Skip to content

Commit bf4e62b

Browse files
JMS55teoxoy
andauthored
Fix textureGather on texture_2d<u32/i32> (gfx-rs#2138)
* Fix textureGather on texture_2d<u32/i32> * Add textureGather u32/i32 tests * Update src/valid/expression.rs Co-authored-by: Teodor Tanasoaia <[email protected]> * Fix formatting * undo analyzer change Co-authored-by: Teodor Tanasoaia <[email protected]>
1 parent d1c2953 commit bf4e62b

File tree

8 files changed

+452
-392
lines changed

8 files changed

+452
-392
lines changed

src/valid/expression.rs

+4
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ impl super::Validator {
384384
kind: crate::ScalarKind::Float,
385385
multi: false,
386386
} => false,
387+
crate::ImageClass::Sampled {
388+
kind: crate::ScalarKind::Uint | crate::ScalarKind::Sint,
389+
multi: false,
390+
} if gather.is_some() => false,
387391
crate::ImageClass::Depth { multi: false } => true,
388392
_ => return Err(ExpressionError::InvalidImageClass(class)),
389393
};

tests/in/image.wgsl

+15-6
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@ var image_1d: texture_1d<f32>;
4545
@group(0) @binding(1)
4646
var image_2d: texture_2d<f32>;
4747
@group(0) @binding(2)
48-
var image_2d_array: texture_2d_array<f32>;
48+
var image_2d_u32: texture_2d<u32>;
4949
@group(0) @binding(3)
50-
var image_cube: texture_cube<f32>;
50+
var image_2d_i32: texture_2d<i32>;
5151
@group(0) @binding(4)
52-
var image_cube_array: texture_cube_array<f32>;
52+
var image_2d_array: texture_2d_array<f32>;
5353
@group(0) @binding(5)
54-
var image_3d: texture_3d<f32>;
54+
var image_cube: texture_cube<f32>;
5555
@group(0) @binding(6)
56+
var image_cube_array: texture_cube_array<f32>;
57+
@group(0) @binding(7)
58+
var image_3d: texture_3d<f32>;
59+
@group(0) @binding(8)
5660
var image_aa: texture_multisampled_2d<f32>;
5761

5862
@vertex
@@ -71,7 +75,7 @@ fn queries() -> @builtin(position) vec4<f32> {
7175
let dim_3d_lod = textureDimensions(image_3d, 1);
7276
let dim_2s_ms = textureDimensions(image_aa);
7377

74-
let sum = dim_1d + dim_2d.y + dim_2d_lod.y + dim_2d_array.y + dim_2d_array_lod.y +
78+
let sum = dim_1d + dim_2d.y + dim_2d_lod.y + dim_2d_array.y + dim_2d_array_lod.y +
7579
dim_cube.y + dim_cube_lod.y + dim_cube_array.y + dim_cube_array_lod.y +
7680
dim_3d.z + dim_3d_lod.z;
7781
return vec4<f32>(f32(sum));
@@ -134,7 +138,12 @@ fn gather() -> @location(0) vec4<f32> {
134138
let s2d_offset = textureGather(3, image_2d, sampler_reg, tc, vec2<i32>(3, 1));
135139
let s2d_depth = textureGatherCompare(image_2d_depth, sampler_cmp, tc, dref);
136140
let s2d_depth_offset = textureGatherCompare(image_2d_depth, sampler_cmp, tc, dref, vec2<i32>(3, 1));
137-
return s2d + s2d_offset + s2d_depth + s2d_depth_offset;
141+
142+
let u = textureGather(0, image_2d_u32, sampler_reg, tc);
143+
let i = textureGather(0, image_2d_i32, sampler_reg, tc);
144+
let f = vec4<f32>(u) + vec4<f32>(i);
145+
146+
return s2d + s2d_offset + s2d_depth + s2d_depth_offset + f;
138147
}
139148

140149
@fragment

tests/out/glsl/image.gather.Fragment.glsl

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ precision highp int;
66

77
uniform highp sampler2D _group_0_binding_1_fs;
88

9+
uniform highp usampler2D _group_0_binding_2_fs;
10+
11+
uniform highp isampler2D _group_0_binding_3_fs;
12+
913
uniform highp sampler2DShadow _group_1_binding_2_fs;
1014

1115
layout(location = 0) out vec4 _fs2p_location0;
@@ -16,7 +20,10 @@ void main() {
1620
vec4 s2d_offset = textureGatherOffset(_group_0_binding_1_fs, vec2(tc), ivec2(3, 1), 3);
1721
vec4 s2d_depth = textureGather(_group_1_binding_2_fs, vec2(tc), 0.5);
1822
vec4 s2d_depth_offset = textureGatherOffset(_group_1_binding_2_fs, vec2(tc), 0.5, ivec2(3, 1));
19-
_fs2p_location0 = (((s2d + s2d_offset) + s2d_depth) + s2d_depth_offset);
23+
uvec4 u = textureGather(_group_0_binding_2_fs, vec2(tc), 0);
24+
ivec4 i = textureGather(_group_0_binding_3_fs, vec2(tc), 0);
25+
vec4 f = (vec4(u) + vec4(i));
26+
_fs2p_location0 = ((((s2d + s2d_offset) + s2d_depth) + s2d_depth_offset) + f);
2027
return;
2128
}
2229

tests/out/glsl/image.queries.Vertex.glsl

+14-14
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@ uniform highp sampler2D _group_0_binding_0_vs;
88

99
uniform highp sampler2D _group_0_binding_1_vs;
1010

11-
uniform highp sampler2DArray _group_0_binding_2_vs;
11+
uniform highp sampler2DArray _group_0_binding_4_vs;
1212

13-
uniform highp samplerCube _group_0_binding_3_vs;
13+
uniform highp samplerCube _group_0_binding_5_vs;
1414

15-
uniform highp samplerCubeArray _group_0_binding_4_vs;
15+
uniform highp samplerCubeArray _group_0_binding_6_vs;
1616

17-
uniform highp sampler3D _group_0_binding_5_vs;
17+
uniform highp sampler3D _group_0_binding_7_vs;
1818

19-
uniform highp sampler2DMS _group_0_binding_6_vs;
19+
uniform highp sampler2DMS _group_0_binding_8_vs;
2020

2121

2222
void main() {
2323
int dim_1d = textureSize(_group_0_binding_0_vs, 0).x;
2424
int dim_1d_lod = textureSize(_group_0_binding_0_vs, int(dim_1d)).x;
2525
ivec2 dim_2d = textureSize(_group_0_binding_1_vs, 0).xy;
2626
ivec2 dim_2d_lod = textureSize(_group_0_binding_1_vs, 1).xy;
27-
ivec2 dim_2d_array = textureSize(_group_0_binding_2_vs, 0).xy;
28-
ivec2 dim_2d_array_lod = textureSize(_group_0_binding_2_vs, 1).xy;
29-
ivec2 dim_cube = textureSize(_group_0_binding_3_vs, 0).xy;
30-
ivec2 dim_cube_lod = textureSize(_group_0_binding_3_vs, 1).xy;
31-
ivec2 dim_cube_array = textureSize(_group_0_binding_4_vs, 0).xy;
32-
ivec2 dim_cube_array_lod = textureSize(_group_0_binding_4_vs, 1).xy;
33-
ivec3 dim_3d = textureSize(_group_0_binding_5_vs, 0).xyz;
34-
ivec3 dim_3d_lod = textureSize(_group_0_binding_5_vs, 1).xyz;
35-
ivec2 dim_2s_ms = textureSize(_group_0_binding_6_vs).xy;
27+
ivec2 dim_2d_array = textureSize(_group_0_binding_4_vs, 0).xy;
28+
ivec2 dim_2d_array_lod = textureSize(_group_0_binding_4_vs, 1).xy;
29+
ivec2 dim_cube = textureSize(_group_0_binding_5_vs, 0).xy;
30+
ivec2 dim_cube_lod = textureSize(_group_0_binding_5_vs, 1).xy;
31+
ivec2 dim_cube_array = textureSize(_group_0_binding_6_vs, 0).xy;
32+
ivec2 dim_cube_array_lod = textureSize(_group_0_binding_6_vs, 1).xy;
33+
ivec3 dim_3d = textureSize(_group_0_binding_7_vs, 0).xyz;
34+
ivec3 dim_3d_lod = textureSize(_group_0_binding_7_vs, 1).xyz;
35+
ivec2 dim_2s_ms = textureSize(_group_0_binding_8_vs).xy;
3636
int 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);
3737
gl_Position = vec4(float(sum));
3838
gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);

tests/out/hlsl/image.hlsl

+11-6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ Texture1D<uint4> image_1d_src : register(t7);
99
RWTexture1D<uint4> image_dst : register(u2);
1010
Texture1D<float4> image_1d : register(t0);
1111
Texture2D<float4> image_2d : register(t1);
12-
Texture2DArray<float4> image_2d_array : register(t2);
13-
TextureCube<float4> image_cube : register(t3);
14-
TextureCubeArray<float4> image_cube_array : register(t4);
15-
Texture3D<float4> image_3d : register(t5);
16-
Texture2DMS<float4> image_aa : register(t6);
12+
Texture2D<uint4> image_2d_u32_ : register(t2);
13+
Texture2D<int4> image_2d_i32_ : register(t3);
14+
Texture2DArray<float4> image_2d_array : register(t4);
15+
TextureCube<float4> image_cube : register(t5);
16+
TextureCubeArray<float4> image_cube_array : register(t6);
17+
Texture3D<float4> image_3d : register(t7);
18+
Texture2DMS<float4> image_aa : register(t8);
1719
SamplerState sampler_reg : register(s0, space1);
1820
SamplerComparisonState sampler_cmp : register(s1, space1);
1921
Texture2D<float> image_2d_depth : register(t2, space1);
@@ -258,7 +260,10 @@ float4 gather() : SV_Target0
258260
float4 s2d_offset_1 = image_2d.GatherAlpha(sampler_reg, tc_2, int2(3, 1));
259261
float4 s2d_depth_1 = image_2d_depth.GatherCmp(sampler_cmp, tc_2, 0.5);
260262
float4 s2d_depth_offset = image_2d_depth.GatherCmp(sampler_cmp, tc_2, 0.5, int2(3, 1));
261-
return (((s2d_1 + s2d_offset_1) + s2d_depth_1) + s2d_depth_offset);
263+
uint4 u = image_2d_u32_.Gather(sampler_reg, tc_2);
264+
int4 i = image_2d_i32_.Gather(sampler_reg, tc_2);
265+
float4 f = (float4(u) + float4(i));
266+
return ((((s2d_1 + s2d_offset_1) + s2d_depth_1) + s2d_depth_offset) + f);
262267
}
263268

264269
float4 depth_no_comparison() : SV_Target0

tests/out/msl/image.msl

+6-1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ struct gatherOutput {
139139
};
140140
fragment gatherOutput gather(
141141
metal::texture2d<float, metal::access::sample> image_2d [[user(fake0)]]
142+
, metal::texture2d<uint, metal::access::sample> image_2d_u32_ [[user(fake0)]]
143+
, metal::texture2d<int, metal::access::sample> image_2d_i32_ [[user(fake0)]]
142144
, metal::sampler sampler_reg [[user(fake0)]]
143145
, metal::sampler sampler_cmp [[user(fake0)]]
144146
, metal::depth2d<float, metal::access::sample> image_2d_depth [[user(fake0)]]
@@ -148,7 +150,10 @@ fragment gatherOutput gather(
148150
metal::float4 s2d_offset_1 = image_2d.gather(sampler_reg, tc_2, const_type_9_, metal::component::w);
149151
metal::float4 s2d_depth_1 = image_2d_depth.gather_compare(sampler_cmp, tc_2, 0.5);
150152
metal::float4 s2d_depth_offset = image_2d_depth.gather_compare(sampler_cmp, tc_2, 0.5, const_type_9_);
151-
return gatherOutput { ((s2d_1 + s2d_offset_1) + s2d_depth_1) + s2d_depth_offset };
153+
metal::uint4 u = image_2d_u32_.gather(sampler_reg, tc_2);
154+
metal::int4 i = image_2d_i32_.gather(sampler_reg, tc_2);
155+
metal::float4 f = static_cast<metal::float4>(u) + static_cast<metal::float4>(i);
156+
return gatherOutput { (((s2d_1 + s2d_offset_1) + s2d_depth_1) + s2d_depth_offset) + f };
152157
}
153158

154159

0 commit comments

Comments
 (0)