Skip to content

Commit

Permalink
naga: Fix textureNumLevels in the GLSL backend
Browse files Browse the repository at this point in the history
... and reactivate the GLSL test for it.

Fixes issue #6435.
  • Loading branch information
magcius authored and teoxoy committed Nov 4, 2024
1 parent 6a75a73 commit 9ccea81
Show file tree
Hide file tree
Showing 14 changed files with 414 additions and 396 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Bottom level categories:

- Parse `diagnostic(…)` directives, but don't implement any triggering rules yet. By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456).
- 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).

#### General

Expand Down
2 changes: 1 addition & 1 deletion naga/src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,7 @@ impl<'a, W: Write> Writer<'a, W> {
self.write_expr(image, ctx)?;
// All textureSize calls requires an lod argument
// except for multisampled samplers
if class.is_multisampled() {
if !class.is_multisampled() {
write!(self.out, ", 0")?;
}
write!(self.out, ")")?;
Expand Down
8 changes: 7 additions & 1 deletion naga/tests/in/image.param.ron
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
version: (1, 1),
debug: true,
),
glsl_exclude_list: ["depth_load", "depth_no_comparison", "levels_queries"]
glsl: (
version: Desktop(430),
writer_flags: (""),
binding_map: {},
zero_initialize_workgroup_memory: true,
),
glsl_exclude_list: ["depth_load", "depth_no_comparison"]
)
3 changes: 2 additions & 1 deletion naga/tests/in/image.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ fn queries() -> @builtin(position) vec4<f32> {
@vertex
fn levels_queries() -> @builtin(position) vec4<f32> {
let num_levels_2d = textureNumLevels(image_2d);
let num_levels_2d_array = textureNumLevels(image_2d_array);
let num_layers_2d = textureNumLayers(image_2d_array);
let num_levels_2d_array = textureNumLevels(image_2d_array);
let num_layers_2d_array = textureNumLayers(image_2d_array);
let num_levels_cube = textureNumLevels(image_cube);
let num_levels_cube_array = textureNumLevels(image_cube_array);
let num_layers_cube = textureNumLayers(image_cube_array);
Expand Down
15 changes: 5 additions & 10 deletions naga/tests/out/glsl/image.gather.Fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
#version 310 es
#extension GL_EXT_texture_cube_map_array : require
#version 430 core
uniform sampler2D _group_0_binding_1_fs;

precision highp float;
precision highp int;
uniform usampler2D _group_0_binding_2_fs;

uniform highp sampler2D _group_0_binding_1_fs;
uniform isampler2D _group_0_binding_3_fs;

uniform highp usampler2D _group_0_binding_2_fs;

uniform highp isampler2D _group_0_binding_3_fs;

uniform highp sampler2DShadow _group_1_binding_2_fs;
uniform sampler2DShadow _group_1_binding_2_fs;

layout(location = 0) out vec4 _fs2p_location0;

Expand Down
30 changes: 30 additions & 0 deletions naga/tests/out/glsl/image.levels_queries.Vertex.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#version 430 core
#extension GL_ARB_shader_texture_image_samples : require
uniform sampler2D _group_0_binding_1_vs;

uniform sampler2DArray _group_0_binding_4_vs;

uniform samplerCube _group_0_binding_5_vs;

uniform samplerCubeArray _group_0_binding_6_vs;

uniform sampler3D _group_0_binding_7_vs;

uniform sampler2DMS _group_0_binding_8_vs;


void main() {
uint num_levels_2d = uint(textureQueryLevels(_group_0_binding_1_vs));
uint num_layers_2d = uint(textureSize(_group_0_binding_4_vs, 0).z);
uint num_levels_2d_array = uint(textureQueryLevels(_group_0_binding_4_vs));
uint num_layers_2d_array = uint(textureSize(_group_0_binding_4_vs, 0).z);
uint num_levels_cube = uint(textureQueryLevels(_group_0_binding_5_vs));
uint num_levels_cube_array = uint(textureQueryLevels(_group_0_binding_6_vs));
uint num_layers_cube = uint(textureSize(_group_0_binding_6_vs, 0).z);
uint num_levels_3d = uint(textureQueryLevels(_group_0_binding_7_vs));
uint num_samples_aa = uint(textureSamples(_group_0_binding_8_vs));
uint sum = (((((((num_layers_2d + num_layers_cube) + num_samples_aa) + num_levels_2d) + num_levels_2d_array) + num_levels_3d) + num_levels_cube) + num_levels_cube_array);
gl_Position = vec4(float(sum));
return;
}

28 changes: 12 additions & 16 deletions naga/tests/out/glsl/image.main.Compute.glsl
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
#version 310 es
#extension GL_EXT_texture_cube_map_array : require

precision highp float;
precision highp int;

#version 430 core
#extension GL_ARB_compute_shader : require
layout(local_size_x = 16, local_size_y = 1, local_size_z = 1) in;

uniform highp usampler2D _group_0_binding_0_cs;
uniform usampler2D _group_0_binding_0_cs;

uniform highp usampler2DMS _group_0_binding_3_cs;
uniform usampler2DMS _group_0_binding_3_cs;

layout(rgba8ui) readonly uniform highp uimage2D _group_0_binding_1_cs;
layout(rgba8ui) readonly uniform uimage2D _group_0_binding_1_cs;

uniform highp usampler2DArray _group_0_binding_5_cs;
uniform usampler2DArray _group_0_binding_5_cs;

uniform highp usampler2D _group_0_binding_7_cs;
uniform usampler1D _group_0_binding_7_cs;

layout(r32ui) writeonly uniform highp uimage2D _group_0_binding_2_cs;
layout(r32ui) writeonly uniform uimage1D _group_0_binding_2_cs;


void main() {
Expand All @@ -28,15 +24,15 @@ void main() {
uvec4 value4_ = imageLoad(_group_0_binding_1_cs, itc);
uvec4 value5_ = texelFetch(_group_0_binding_5_cs, ivec3(itc, local_id.z), (int(local_id.z) + 1));
uvec4 value6_ = texelFetch(_group_0_binding_5_cs, ivec3(itc, int(local_id.z)), (int(local_id.z) + 1));
uvec4 value7_ = texelFetch(_group_0_binding_7_cs, ivec2(int(local_id.x), 0), int(local_id.z));
uvec4 value7_ = texelFetch(_group_0_binding_7_cs, int(local_id.x), int(local_id.z));
uvec4 value1u = texelFetch(_group_0_binding_0_cs, ivec2(uvec2(itc)), int(local_id.z));
uvec4 value2u = texelFetch(_group_0_binding_3_cs, ivec2(uvec2(itc)), int(local_id.z));
uvec4 value4u = imageLoad(_group_0_binding_1_cs, ivec2(uvec2(itc)));
uvec4 value5u = texelFetch(_group_0_binding_5_cs, ivec3(uvec2(itc), local_id.z), (int(local_id.z) + 1));
uvec4 value6u = texelFetch(_group_0_binding_5_cs, ivec3(uvec2(itc), int(local_id.z)), (int(local_id.z) + 1));
uvec4 value7u = texelFetch(_group_0_binding_7_cs, ivec2(uint(local_id.x), 0), int(local_id.z));
imageStore(_group_0_binding_2_cs, ivec2(itc.x, 0), ((((value1_ + value2_) + value4_) + value5_) + value6_));
imageStore(_group_0_binding_2_cs, ivec2(uint(itc.x), 0), ((((value1u + value2u) + value4u) + value5u) + value6u));
uvec4 value7u = texelFetch(_group_0_binding_7_cs, int(uint(local_id.x)), int(local_id.z));
imageStore(_group_0_binding_2_cs, itc.x, ((((value1_ + value2_) + value4_) + value5_) + value6_));
imageStore(_group_0_binding_2_cs, int(uint(itc.x)), ((((value1u + value2u) + value4u) + value5u) + value6u));
return;
}

26 changes: 10 additions & 16 deletions naga/tests/out/glsl/image.queries.Vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
#version 310 es
#extension GL_EXT_texture_cube_map_array : require
#version 430 core
uniform sampler1D _group_0_binding_0_vs;

precision highp float;
precision highp int;
uniform sampler2D _group_0_binding_1_vs;

uniform highp sampler2D _group_0_binding_0_vs;
uniform sampler2DArray _group_0_binding_4_vs;

uniform highp sampler2D _group_0_binding_1_vs;
uniform samplerCube _group_0_binding_5_vs;

uniform highp sampler2DArray _group_0_binding_4_vs;
uniform samplerCubeArray _group_0_binding_6_vs;

uniform highp samplerCube _group_0_binding_5_vs;
uniform sampler3D _group_0_binding_7_vs;

uniform highp samplerCubeArray _group_0_binding_6_vs;

uniform highp sampler3D _group_0_binding_7_vs;

uniform highp sampler2DMS _group_0_binding_8_vs;
uniform sampler2DMS _group_0_binding_8_vs;


void main() {
uint dim_1d = uint(textureSize(_group_0_binding_0_vs, 0).x);
uint dim_1d_lod = uint(textureSize(_group_0_binding_0_vs, int(dim_1d)).x);
uint dim_1d = uint(textureSize(_group_0_binding_0_vs, 0));
uint dim_1d_lod = uint(textureSize(_group_0_binding_0_vs, int(dim_1d)));
uvec2 dim_2d = uvec2(textureSize(_group_0_binding_1_vs, 0).xy);
uvec2 dim_2d_lod = uvec2(textureSize(_group_0_binding_1_vs, 1).xy);
uvec2 dim_2d_array = uvec2(textureSize(_group_0_binding_4_vs, 0).xy);
Expand All @@ -35,7 +30,6 @@ void main() {
uvec2 dim_2s_ms = uvec2(textureSize(_group_0_binding_8_vs).xy);
uint sum = ((((((((((dim_1d + dim_2d.y) + dim_2d_lod.y) + dim_2d_array.y) + dim_2d_array_lod.y) + dim_cube.y) + dim_cube_lod.y) + dim_cube_array.y) + dim_cube_array_lod.y) + dim_3d.z) + dim_3d_lod.z);
gl_Position = vec4(float(sum));
gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);
return;
}

17 changes: 6 additions & 11 deletions naga/tests/out/glsl/image.texture_sample.Fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
#version 310 es
#extension GL_EXT_texture_cube_map_array : require
#version 430 core
uniform sampler1D _group_0_binding_0_fs;

precision highp float;
precision highp int;
uniform sampler2D _group_0_binding_1_fs;

uniform highp sampler2D _group_0_binding_0_fs;
uniform sampler2DArray _group_0_binding_4_fs;

uniform highp sampler2D _group_0_binding_1_fs;

uniform highp sampler2DArray _group_0_binding_4_fs;

uniform highp samplerCubeArray _group_0_binding_6_fs;
uniform samplerCubeArray _group_0_binding_6_fs;

layout(location = 0) out vec4 _fs2p_location0;

void main() {
vec4 a = vec4(0.0);
vec2 tc = vec2(0.5);
vec3 tc3_ = vec3(0.5);
vec4 _e9 = texture(_group_0_binding_0_fs, vec2(tc.x, 0.0));
vec4 _e9 = texture(_group_0_binding_0_fs, tc.x);
vec4 _e10 = a;
a = (_e10 + _e9);
vec4 _e14 = texture(_group_0_binding_1_fs, vec2(tc));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#version 310 es
#extension GL_EXT_texture_cube_map_array : require
#version 430 core
uniform sampler2DShadow _group_1_binding_2_fs;

precision highp float;
precision highp int;
uniform sampler2DArrayShadow _group_1_binding_3_fs;

uniform highp sampler2DShadow _group_1_binding_2_fs;

uniform highp sampler2DArrayShadow _group_1_binding_3_fs;

uniform highp samplerCubeShadow _group_1_binding_4_fs;
uniform samplerCubeShadow _group_1_binding_4_fs;

layout(location = 0) out float _fs2p_location0;

Expand Down
7 changes: 4 additions & 3 deletions naga/tests/out/hlsl/image.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ uint NagaNumLevels2D(Texture2D<float4> tex)
return ret.z;
}

uint NagaNumLevels2DArray(Texture2DArray<float4> tex)
uint NagaNumLayers2DArray(Texture2DArray<float4> tex)
{
uint4 ret;
tex.GetDimensions(0, ret.x, ret.y, ret.z, ret.w);
return ret.w;
}

uint NagaNumLayers2DArray(Texture2DArray<float4> tex)
uint NagaNumLevels2DArray(Texture2DArray<float4> tex)
{
uint4 ret;
tex.GetDimensions(0, ret.x, ret.y, ret.z, ret.w);
Expand Down Expand Up @@ -229,8 +229,9 @@ uint NagaMSNumSamples2D(Texture2DMS<float4> tex)
float4 levels_queries() : SV_Position
{
uint num_levels_2d = NagaNumLevels2D(image_2d);
uint num_levels_2d_array = NagaNumLevels2DArray(image_2d_array);
uint num_layers_2d = NagaNumLayers2DArray(image_2d_array);
uint num_levels_2d_array = NagaNumLevels2DArray(image_2d_array);
uint num_layers_2d_array = NagaNumLayers2DArray(image_2d_array);
uint num_levels_cube = NagaNumLevelsCube(image_cube);
uint num_levels_cube_array = NagaNumLevelsCubeArray(image_cube_array);
uint num_layers_cube = NagaNumLayersCubeArray(image_cube_array);
Expand Down
3 changes: 2 additions & 1 deletion naga/tests/out/msl/image.msl
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ vertex levels_queriesOutput levels_queries(
, metal::texture2d_ms<float, metal::access::read> image_aa [[user(fake0)]]
) {
uint num_levels_2d = image_2d.get_num_mip_levels();
uint num_levels_2d_array = image_2d_array.get_num_mip_levels();
uint num_layers_2d = image_2d_array.get_array_size();
uint num_levels_2d_array = image_2d_array.get_num_mip_levels();
uint num_layers_2d_array = image_2d_array.get_array_size();
uint num_levels_cube = image_cube.get_num_mip_levels();
uint num_levels_cube_array = image_cube_array.get_num_mip_levels();
uint num_layers_cube = image_cube_array.get_array_size();
Expand Down
Loading

0 comments on commit 9ccea81

Please sign in to comment.