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 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).
|
- 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).
|
- 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
|
#### General
|
||||||
|
|
||||||
@ -3481,4 +3482,4 @@ DeviceDescriptor {
|
|||||||
- concept of the storage hub
|
- concept of the storage hub
|
||||||
- basic recording of passes and command buffers
|
- basic recording of passes and command buffers
|
||||||
- submission-based lifetime tracking and command buffer recycling
|
- submission-based lifetime tracking and command buffer recycling
|
||||||
- automatic resource transitions
|
- automatic resource transitions
|
@ -462,37 +462,54 @@ fn inject_standard_builtins(
|
|||||||
module: &mut Module,
|
module: &mut Module,
|
||||||
name: &str,
|
name: &str,
|
||||||
) {
|
) {
|
||||||
match name {
|
// Some samplers (sampler1D, etc...) can be float, int, or uint
|
||||||
"sampler1D" | "sampler1DArray" | "sampler2D" | "sampler2DArray" | "sampler2DMS"
|
let anykind_sampler = if name.starts_with("sampler") {
|
||||||
| "sampler2DMSArray" | "sampler3D" | "samplerCube" | "samplerCubeArray" => {
|
Some((name, Sk::Float))
|
||||||
declaration.overloads.push(module.add_builtin(
|
} else if name.starts_with("usampler") {
|
||||||
vec![
|
Some((&name[1..], Sk::Uint))
|
||||||
TypeInner::Image {
|
} else if name.starts_with("isampler") {
|
||||||
dim: match name {
|
Some((&name[1..], Sk::Sint))
|
||||||
"sampler1D" | "sampler1DArray" => Dim::D1,
|
} else {
|
||||||
"sampler2D" | "sampler2DArray" | "sampler2DMS" | "sampler2DMSArray" => {
|
None
|
||||||
Dim::D2
|
};
|
||||||
}
|
if let Some((sampler, kind)) = anykind_sampler {
|
||||||
"sampler3D" => Dim::D3,
|
match sampler {
|
||||||
_ => Dim::Cube,
|
"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!(
|
TypeInner::Sampler { comparison: false },
|
||||||
name,
|
],
|
||||||
"sampler1DArray"
|
MacroCall::Sampler,
|
||||||
| "sampler2DArray"
|
));
|
||||||
| "sampler2DMSArray"
|
return;
|
||||||
| "samplerCubeArray"
|
}
|
||||||
),
|
_ => (),
|
||||||
class: ImageClass::Sampled {
|
|
||||||
kind: Sk::Float,
|
|
||||||
multi: matches!(name, "sampler2DMS" | "sampler2DMSArray"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
TypeInner::Sampler { comparison: false },
|
|
||||||
],
|
|
||||||
MacroCall::Sampler,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match name {
|
||||||
|
// Shadow sampler can only be of kind `Sk::Float`
|
||||||
"sampler1DShadow"
|
"sampler1DShadow"
|
||||||
| "sampler1DArrayShadow"
|
| "sampler1DArrayShadow"
|
||||||
| "sampler2DShadow"
|
| "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 = 4) uniform textureCube texCube;
|
||||||
layout(set = 1, binding = 5) uniform textureCubeArray texCubeArray;
|
layout(set = 1, binding = 5) uniform textureCubeArray texCubeArray;
|
||||||
layout(set = 1, binding = 6) uniform texture3D tex3D;
|
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.
|
// WGSL doesn't have 1D depth samplers.
|
||||||
#define HAS_1D_DEPTH_TEXTURES 0
|
#define HAS_1D_DEPTH_TEXTURES 0
|
||||||
@ -129,16 +133,26 @@ void testTex2D(in vec2 coord) {
|
|||||||
vec4 c;
|
vec4 c;
|
||||||
c = texture(sampler2D(tex2D, samp), coord);
|
c = texture(sampler2D(tex2D, samp), coord);
|
||||||
c = texture(sampler2D(tex2D, samp), coord, 2.0);
|
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));
|
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));
|
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);
|
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 = 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));
|
||||||
c = textureOffset(sampler2D(tex2D, samp), coord, ivec2(5), 2.0);
|
c = textureOffset(sampler2D(tex2D, samp), coord, ivec2(5), 2.0);
|
||||||
|
|
||||||
c = textureProj(sampler2D(tex2D, samp), vec3(coord, 6.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), vec4(coord, 0.0, 6.0));
|
||||||
c = textureProj(sampler2D(tex2D, samp), vec3(coord, 6.0), 2.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 = 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), 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 = 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));
|
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), 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), vec3(coord, 6.0), ivec2(5), 2.0);
|
||||||
c = textureProjOffset(sampler2D(tex2D, samp), vec4(coord, 0.0, 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 = 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 = 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) {
|
void testTex2DShadow(vec2 coord) {
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user