Skip to content

Commit e1ecc29

Browse files
committed
Sampled images should have the correct data type
1 parent 1e7751c commit e1ecc29

1 file changed

Lines changed: 61 additions & 6 deletions

File tree

inox2d-wgpu/build.rs

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use shaderc;
22
use spirv_reflect;
33
use spirv_reflect::types::{
4-
ReflectBlockVariable, ReflectDescriptorType, ReflectEntryPoint, ReflectFormat, ReflectTypeDescription,
5-
ReflectTypeFlags,
4+
ReflectBlockVariable, ReflectDescriptorType, ReflectEntryPoint, ReflectFormat, ReflectImageFormat,
5+
ReflectTypeDescription, ReflectTypeFlags,
66
};
77

88
use std::borrow::Cow;
@@ -233,10 +233,65 @@ fn gen_shader_new(
233233
out,
234234
" view_dimension: wgpu::TextureViewDimension::D2,"
235235
)?; //TODO: Support 1D/3D textures
236-
writeln!(
237-
out,
238-
" sample_type: wgpu::TextureSampleType::Float {{ filterable: true }},"
239-
)?;
236+
match binding.image.image_format {
237+
ReflectImageFormat::RGBA32_FLOAT |
238+
ReflectImageFormat::RGBA16_FLOAT |
239+
ReflectImageFormat::R32_FLOAT |
240+
ReflectImageFormat::RG32_FLOAT |
241+
ReflectImageFormat::RG16_FLOAT |
242+
ReflectImageFormat::R11G11B10_FLOAT |
243+
ReflectImageFormat::R16_FLOAT => {
244+
// TODO: filtering on float textures is actually not permitted by WebGPU
245+
// so we need a mode to ask the generated shader code to turn this off
246+
writeln!(
247+
out,
248+
" sample_type: wgpu::TextureSampleType::Float {{ filterable: true }},"
249+
)?;
250+
}
251+
ReflectImageFormat::RGBA8 | //TODO: Any documentation as to what this does?
252+
ReflectImageFormat::RGBA16 | //I asked Al and he said this is UNORM, but Al
253+
ReflectImageFormat::RGB10A2 | //likes to make things up a lot.
254+
ReflectImageFormat::RG16 |
255+
ReflectImageFormat::RG8 |
256+
ReflectImageFormat::R16 |
257+
ReflectImageFormat::R8 |
258+
ReflectImageFormat::RGBA32_UINT |
259+
ReflectImageFormat::RGBA16_UINT |
260+
ReflectImageFormat::RGBA8_UINT |
261+
ReflectImageFormat::R32_UINT |
262+
ReflectImageFormat::RGB10A2_UINT |
263+
ReflectImageFormat::RG32_UINT |
264+
ReflectImageFormat::RG16_UINT |
265+
ReflectImageFormat::RG8_UINT |
266+
ReflectImageFormat::R16_UINT |
267+
ReflectImageFormat::R8_UINT => {
268+
writeln!(
269+
out,
270+
" sample_type: wgpu::TextureSampleType::Uint,"
271+
)?;
272+
}
273+
ReflectImageFormat::Undefined | //NOTE: To be clear, "Undefined" makes no sense.
274+
ReflectImageFormat::RGBA8_SNORM |
275+
ReflectImageFormat::RGBA16_SNORM |
276+
ReflectImageFormat::RG16_SNORM |
277+
ReflectImageFormat::RG8_SNORM |
278+
ReflectImageFormat::R16_SNORM |
279+
ReflectImageFormat::R8_SNORM |
280+
ReflectImageFormat::RGBA32_INT |
281+
ReflectImageFormat::RGBA16_INT |
282+
ReflectImageFormat::RGBA8_INT |
283+
ReflectImageFormat::R32_INT |
284+
ReflectImageFormat::RG32_INT |
285+
ReflectImageFormat::RG16_INT |
286+
ReflectImageFormat::RG8_INT |
287+
ReflectImageFormat::R16_INT |
288+
ReflectImageFormat::R8_INT => {
289+
writeln!(
290+
out,
291+
" sample_type: wgpu::TextureSampleType::Sint,"
292+
)?;
293+
}
294+
}
240295
writeln!(out, " }},")?;
241296
}
242297

0 commit comments

Comments
 (0)