mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
naga: Add support for GLSL signed/unsigned samplers (#6513)
This commit is contained in:
parent
4681f4ffba
commit
3018912897
@ -99,6 +99,7 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148]
|
||||
- Fix an issue where `naga` CLI would incorrectly skip the first positional argument when `--stdin-file-path` was specified. By @ErichDonGubler in [#6480](https://github.com/gfx-rs/wgpu/pull/6480).
|
||||
- Fix textureNumLevels in the GLSL backend. By @magcius in [#6483](https://github.com/gfx-rs/wgpu/pull/6483).
|
||||
- Implement `quantizeToF16()` for WGSL frontend, and WGSL, SPIR-V, HLSL, MSL, and GLSL backends. By @jamienicol in [#6519](https://github.com/gfx-rs/wgpu/pull/6519).
|
||||
- Add support for GLSL `usampler*` and `isampler*`. By @DavidPeicho in [#6513](https://github.com/gfx-rs/wgpu/pull/6513).
|
||||
|
||||
#### General
|
||||
|
||||
|
@ -462,37 +462,54 @@ fn inject_standard_builtins(
|
||||
module: &mut Module,
|
||||
name: &str,
|
||||
) {
|
||||
match name {
|
||||
"sampler1D" | "sampler1DArray" | "sampler2D" | "sampler2DArray" | "sampler2DMS"
|
||||
| "sampler2DMSArray" | "sampler3D" | "samplerCube" | "samplerCubeArray" => {
|
||||
declaration.overloads.push(module.add_builtin(
|
||||
vec![
|
||||
TypeInner::Image {
|
||||
dim: match name {
|
||||
"sampler1D" | "sampler1DArray" => Dim::D1,
|
||||
"sampler2D" | "sampler2DArray" | "sampler2DMS" | "sampler2DMSArray" => {
|
||||
Dim::D2
|
||||
}
|
||||
"sampler3D" => Dim::D3,
|
||||
_ => Dim::Cube,
|
||||
// Some samplers (sampler1D, etc...) can be float, int, or uint
|
||||
let anykind_sampler = if name.starts_with("sampler") {
|
||||
Some((name, Sk::Float))
|
||||
} else if name.starts_with("usampler") {
|
||||
Some((&name[1..], Sk::Uint))
|
||||
} else if name.starts_with("isampler") {
|
||||
Some((&name[1..], Sk::Sint))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some((sampler, kind)) = anykind_sampler {
|
||||
match sampler {
|
||||
"sampler1D" | "sampler1DArray" | "sampler2D" | "sampler2DArray" | "sampler2DMS"
|
||||
| "sampler2DMSArray" | "sampler3D" | "samplerCube" | "samplerCubeArray" => {
|
||||
declaration.overloads.push(module.add_builtin(
|
||||
vec![
|
||||
TypeInner::Image {
|
||||
dim: match sampler {
|
||||
"sampler1D" | "sampler1DArray" => Dim::D1,
|
||||
"sampler2D" | "sampler2DArray" | "sampler2DMS"
|
||||
| "sampler2DMSArray" => Dim::D2,
|
||||
"sampler3D" => Dim::D3,
|
||||
_ => Dim::Cube,
|
||||
},
|
||||
arrayed: matches!(
|
||||
sampler,
|
||||
"sampler1DArray"
|
||||
| "sampler2DArray"
|
||||
| "sampler2DMSArray"
|
||||
| "samplerCubeArray"
|
||||
),
|
||||
class: ImageClass::Sampled {
|
||||
kind,
|
||||
multi: matches!(sampler, "sampler2DMS" | "sampler2DMSArray"),
|
||||
},
|
||||
},
|
||||
arrayed: matches!(
|
||||
name,
|
||||
"sampler1DArray"
|
||||
| "sampler2DArray"
|
||||
| "sampler2DMSArray"
|
||||
| "samplerCubeArray"
|
||||
),
|
||||
class: ImageClass::Sampled {
|
||||
kind: Sk::Float,
|
||||
multi: matches!(name, "sampler2DMS" | "sampler2DMSArray"),
|
||||
},
|
||||
},
|
||||
TypeInner::Sampler { comparison: false },
|
||||
],
|
||||
MacroCall::Sampler,
|
||||
))
|
||||
TypeInner::Sampler { comparison: false },
|
||||
],
|
||||
MacroCall::Sampler,
|
||||
));
|
||||
return;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
match name {
|
||||
// Shadow sampler can only be of kind `Sk::Float`
|
||||
"sampler1DShadow"
|
||||
| "sampler1DArrayShadow"
|
||||
| "sampler2DShadow"
|
||||
|
@ -8,7 +8,11 @@ layout(set = 1, binding = 3) uniform texture2DArray tex2DArray;
|
||||
layout(set = 1, binding = 4) uniform textureCube texCube;
|
||||
layout(set = 1, binding = 5) uniform textureCubeArray texCubeArray;
|
||||
layout(set = 1, binding = 6) uniform texture3D tex3D;
|
||||
layout(set = 1, binding = 7) uniform sampler samp;
|
||||
|
||||
layout(set = 1, binding = 7) uniform utexture2D utex2D;
|
||||
layout(set = 1, binding = 8) uniform itexture2D itex2D;
|
||||
|
||||
layout(set = 2, binding = 0) uniform sampler samp;
|
||||
|
||||
// WGSL doesn't have 1D depth samplers.
|
||||
#define HAS_1D_DEPTH_TEXTURES 0
|
||||
@ -129,16 +133,26 @@ void testTex2D(in vec2 coord) {
|
||||
vec4 c;
|
||||
c = texture(sampler2D(tex2D, samp), coord);
|
||||
c = texture(sampler2D(tex2D, samp), coord, 2.0);
|
||||
/* Signed/Unsigned samplers not supported in the WGSL specification with `textureSample()` */
|
||||
|
||||
c = textureGrad(sampler2D(tex2D, samp), coord, vec2(4.0), vec2(4.0));
|
||||
/* Signed/Unsigned samplers not supported in the WGSL specification with `textureSampleGrad()` */
|
||||
|
||||
c = textureGradOffset(sampler2D(tex2D, samp), coord, vec2(4.0), vec2(4.0), ivec2(5));
|
||||
/* Signed/Unsigned samplers not supported in the WGSL specification with `textureSampleGrad()` */
|
||||
|
||||
c = textureLod(sampler2D(tex2D, samp), coord, 3.0);
|
||||
/* Signed/Unsigned samplers not supported in the WGSL specification with `textureSampleLevel()` */
|
||||
|
||||
c = textureLodOffset(sampler2D(tex2D, samp), coord, 3.0, ivec2(5));
|
||||
c = textureOffset(sampler2D(tex2D, samp), coord, ivec2(5));
|
||||
c = textureOffset(sampler2D(tex2D, samp), coord, ivec2(5), 2.0);
|
||||
|
||||
c = textureProj(sampler2D(tex2D, samp), vec3(coord, 6.0));
|
||||
c = textureProj(sampler2D(tex2D, samp), vec4(coord, 0.0, 6.0));
|
||||
c = textureProj(sampler2D(tex2D, samp), vec3(coord, 6.0), 2.0);
|
||||
c = textureProj(sampler2D(tex2D, samp), vec4(coord, 0.0, 6.0), 2.0);
|
||||
|
||||
c = textureProjGrad(sampler2D(tex2D, samp), vec3(coord, 6.0), vec2(4.0), vec2(4.0));
|
||||
c = textureProjGrad(sampler2D(tex2D, samp), vec4(coord, 0.0, 6.0), vec2(4.0), vec2(4.0));
|
||||
c = textureProjGradOffset(sampler2D(tex2D, samp), vec3(coord, 6.0), vec2(4.0), vec2(4.0), ivec2(5));
|
||||
@ -151,8 +165,14 @@ void testTex2D(in vec2 coord) {
|
||||
c = textureProjOffset(sampler2D(tex2D, samp), vec4(coord, 0.0, 6.0), ivec2(5));
|
||||
c = textureProjOffset(sampler2D(tex2D, samp), vec3(coord, 6.0), ivec2(5), 2.0);
|
||||
c = textureProjOffset(sampler2D(tex2D, samp), vec4(coord, 0.0, 6.0), ivec2(5), 2.0);
|
||||
|
||||
c = texelFetch(sampler2D(tex2D, samp), ivec2(coord), 3);
|
||||
c = vec4(texelFetch(usampler2D(utex2D, samp), ivec2(coord), 3));
|
||||
c = vec4(texelFetch(isampler2D(itex2D, samp), ivec2(coord), 3));
|
||||
|
||||
c = texelFetchOffset(sampler2D(tex2D, samp), ivec2(coord), 3, ivec2(5));
|
||||
c = vec4(texelFetchOffset(usampler2D(utex2D, samp), ivec2(coord), 3, ivec2(5)));
|
||||
c = vec4(texelFetchOffset(isampler2D(itex2D, samp), ivec2(coord), 3, ivec2(5)));
|
||||
}
|
||||
|
||||
void testTex2DShadow(vec2 coord) {
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user