naga: Add support for textureQueryLevels to GLSL parser (#6415)

This commit is contained in:
Jasper St. Pierre 2024-10-18 01:07:58 -07:00 committed by GitHub
parent a8214b67f6
commit 1b2ef8612d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 566 additions and 480 deletions

View File

@ -116,6 +116,7 @@ By @bradwerth [#6216](https://github.com/gfx-rs/wgpu/pull/6216).
- Fix handling of phony statements, so they are actually emitted. By @sagudev in [#6328](https://github.com/gfx-rs/wgpu/pull/6328).
- Added `gl_DrawID` to glsl and `DrawIndex` to spv. By @ChosenName in [#6325](https://github.com/gfx-rs/wgpu/pull/6325).
- Matrices can now be indexed by value (#4337), and indexing arrays by value no longer causes excessive spilling (#6358). By @jimblandy in [#6390](https://github.com/gfx-rs/wgpu/pull/6390).
- Add support for `textureQueryLevels` to the GLSL parser. By @magcius in [#6325](https://github.com/gfx-rs/wgpu/pull/6415).
#### General

View File

@ -292,6 +292,26 @@ pub fn inject_builtin(
f,
)
}
"textureQueryLevels" => {
let f = |kind, dim, arrayed, multi, shadow| {
let class = match shadow {
true => ImageClass::Depth { multi },
false => ImageClass::Sampled { kind, multi },
};
let image = TypeInner::Image {
dim,
arrayed,
class,
};
declaration
.overloads
.push(module.add_builtin(vec![image], MacroCall::TextureQueryLevels))
};
texture_args_generator(TextureArgsOptions::SHADOW | variations.into(), f)
}
"texelFetch" | "texelFetchOffset" => {
let offset = "texelFetchOffset" == name;
let f = |kind, dim, arrayed, multi, _shadow| {
@ -1515,6 +1535,7 @@ pub enum MacroCall {
TextureSize {
arrayed: bool,
},
TextureQueryLevels,
ImageLoad {
multi: bool,
},
@ -1747,6 +1768,24 @@ impl MacroCall {
Span::default(),
)?
}
MacroCall::TextureQueryLevels => {
let expr = ctx.add_expression(
Expression::ImageQuery {
image: args[0],
query: ImageQuery::NumLevels,
},
Span::default(),
)?;
ctx.add_expression(
Expression::As {
expr,
kind: Sk::Sint,
convert: Some(4),
},
Span::default(),
)?
}
MacroCall::ImageLoad { multi } => {
let comps = frontend.coordinate_components(ctx, args[0], args[1], None, meta)?;
let (sample, level) = match (multi, args.get(2)) {

View File

@ -38,6 +38,7 @@ layout(binding = 19) uniform texture2DMSArray tex2DMSArray;
void testTex1D(in float coord) {
int size1D = textureSize(sampler1D(tex1D, samp), 0);
int levels = textureQueryLevels(sampler1D(tex1D, samp));
vec4 c;
c = texture(sampler1D(tex1D, samp), coord);
c = texture(sampler1D(tex1D, samp), coord, 2.0);
@ -70,6 +71,7 @@ void testTex1D(in float coord) {
#if HAS_1D_DEPTH_TEXTURES
void testTex1DShadow(float coord) {
int size1DShadow = textureSize(sampler1DShadow(tex1DShadow, sampShadow), 0);
int levels = textureQueryLevels(sampler1DShadow(tex1DShadow, sampShadow));
float d;
d = texture(sampler1DShadow(tex1DShadow, sampShadow), vec3(coord, 1.0, 1.0));
// d = texture(sampler1DShadow(tex1DShadow, sampShadow), vec3(coord, 1.0, 1.0), 2.0);
@ -92,6 +94,7 @@ void testTex1DShadow(float coord) {
void testTex1DArray(in vec2 coord) {
ivec2 size1DArray = textureSize(sampler1DArray(tex1DArray, samp), 0);
int levels = textureQueryLevels(sampler1DArray(tex1DArray, samp));
vec4 c;
c = texture(sampler1DArray(tex1DArray, samp), coord);
c = texture(sampler1DArray(tex1DArray, samp), coord, 2.0);
@ -108,6 +111,7 @@ void testTex1DArray(in vec2 coord) {
#if HAS_1D_DEPTH_TEXTURES
void testTex1DArrayShadow(in vec2 coord) {
ivec2 size1DArrayShadow = textureSize(sampler1DArrayShadow(tex1DArrayShadow, sampShadow), 0);
int levels = textureQueryLevels(sampler1DArrayShadow(tex1DArrayShadow, sampShadow));
float d;
d = texture(sampler1DArrayShadow(tex1DArrayShadow, sampShadow), vec3(coord, 1.0));
d = textureGrad(sampler1DArrayShadow(tex1DArrayShadow, sampShadow), vec3(coord, 1.0), 4.0, 4.0);
@ -121,6 +125,7 @@ void testTex1DArrayShadow(in vec2 coord) {
void testTex2D(in vec2 coord) {
ivec2 size2D = textureSize(sampler2D(tex2D, samp), 0);
int levels = textureQueryLevels(sampler2D(tex2D, samp));
vec4 c;
c = texture(sampler2D(tex2D, samp), coord);
c = texture(sampler2D(tex2D, samp), coord, 2.0);
@ -152,6 +157,7 @@ void testTex2D(in vec2 coord) {
void testTex2DShadow(vec2 coord) {
ivec2 size2DShadow = textureSize(sampler2DShadow(tex2DShadow, sampShadow), 0);
int levels = textureQueryLevels(sampler2DShadow(tex2DShadow, sampShadow));
float d;
d = texture(sampler2DShadow(tex2DShadow, sampShadow), vec3(coord, 1.0));
// d = texture(sampler2DShadow(tex2DShadow, sampShadow), vec3(coord, 1.0), 2.0);
@ -173,6 +179,7 @@ void testTex2DShadow(vec2 coord) {
void testTex2DArray(in vec3 coord) {
ivec3 size2DArray = textureSize(sampler2DArray(tex2DArray, samp), 0);
int levels = textureQueryLevels(sampler2DArray(tex2DArray, samp));
vec4 c;
c = texture(sampler2DArray(tex2DArray, samp), coord);
c = texture(sampler2DArray(tex2DArray, samp), coord, 2.0);
@ -188,6 +195,7 @@ void testTex2DArray(in vec3 coord) {
void testTex2DArrayShadow(in vec3 coord) {
ivec3 size2DArrayShadow = textureSize(sampler2DArrayShadow(tex2DArrayShadow, sampShadow), 0);
int levels = textureQueryLevels(sampler2DArrayShadow(tex2DArrayShadow, sampShadow));
float d;
d = texture(sampler2DArrayShadow(tex2DArrayShadow, sampShadow), vec4(coord, 1.0));
d = textureGrad(sampler2DArrayShadow(tex2DArrayShadow, sampShadow), vec4(coord, 1.0), vec2(4.0), vec2(4.0));
@ -197,6 +205,7 @@ void testTex2DArrayShadow(in vec3 coord) {
void testTexCube(in vec3 coord) {
ivec2 sizeCube = textureSize(samplerCube(texCube, samp), 0);
int levels = textureQueryLevels(samplerCube(texCube, samp));
vec4 c;
c = texture(samplerCube(texCube, samp), coord);
c = texture(samplerCube(texCube, samp), coord, 2.0);
@ -206,6 +215,7 @@ void testTexCube(in vec3 coord) {
void testTexCubeShadow(in vec3 coord) {
ivec2 sizeCubeShadow = textureSize(samplerCubeShadow(texCubeShadow, sampShadow), 0);
int levels = textureQueryLevels(samplerCubeShadow(texCubeShadow, sampShadow));
float d;
d = texture(samplerCubeShadow(texCubeShadow, sampShadow), vec4(coord, 1.0));
d = textureGrad(samplerCubeShadow(texCubeShadow, sampShadow), vec4(coord, 1.0), vec3(4.0), vec3(4.0));
@ -213,6 +223,7 @@ void testTexCubeShadow(in vec3 coord) {
void testTexCubeArray(in vec4 coord) {
ivec3 sizeCubeArray = textureSize(samplerCubeArray(texCubeArray, samp), 0);
int levels = textureQueryLevels(samplerCubeArray(texCubeArray, samp));
vec4 c;
c = texture(samplerCubeArray(texCubeArray, samp), coord);
c = texture(samplerCubeArray(texCubeArray, samp), coord, 2.0);
@ -222,6 +233,7 @@ void testTexCubeArray(in vec4 coord) {
void testTexCubeArrayShadow(in vec4 coord) {
ivec3 sizeCubeArrayShadow = textureSize(samplerCubeArrayShadow(texCubeArrayShadow, sampShadow), 0);
int levels = textureQueryLevels(samplerCubeArrayShadow(texCubeArrayShadow, sampShadow));
float d;
d = texture(samplerCubeArrayShadow(texCubeArrayShadow, sampShadow), coord, 1.0);
// The rest of the variants aren't defined by GLSL.
@ -229,6 +241,7 @@ void testTexCubeArrayShadow(in vec4 coord) {
void testTex3D(in vec3 coord) {
ivec3 size3D = textureSize(sampler3D(tex3D, samp), 0);
int levels = textureQueryLevels(sampler3D(tex3D, samp));
vec4 c;
c = texture(sampler3D(tex3D, samp), coord);
c = texture(sampler3D(tex3D, samp), coord, 2.0);

File diff suppressed because it is too large Load Diff