Skip to content

Commit 2067d1a

Browse files
authored
Add test case for read-only storage texture passed to helper function (KhronosGroup#2414)
This is based on spv.paramMemory.frag.out which exercises the writeonly storage image case. This appears to need desktop GLSL. The generated SPIR-V fails validation because the image_write function takes a parameter which is pointer to an OpTypeImage with Unknown format. But the parameters passed in are pointer to OpTypeImage with formats Rgba32f and Rgba16f. The validator rejects this, saying the parameter types must match.
1 parent 3ce1486 commit 2067d1a

File tree

3 files changed

+173
-0
lines changed

3 files changed

+173
-0
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
spv.paramMemory.420.frag
2+
Validation failed
3+
// Module Version 10000
4+
// Generated by (magic number): 8000a
5+
// Id's are bound by 69
6+
7+
Capability Shader
8+
Capability StorageImageReadWithoutFormat
9+
Capability StorageImageWriteWithoutFormat
10+
1: ExtInstImport "GLSL.std.450"
11+
MemoryModel Logical GLSL450
12+
EntryPoint Fragment 4 "main" 27 66
13+
ExecutionMode 4 OriginUpperLeft
14+
Source GLSL 420
15+
SourceExtension "GL_EXT_shader_image_load_formatted"
16+
Name 4 "main"
17+
Name 16 "image_load(I21;vi2;"
18+
Name 14 "image"
19+
Name 15 "coords"
20+
Name 23 "image_store(I21;vi2;vf4;"
21+
Name 20 "image"
22+
Name 21 "coords"
23+
Name 22 "data"
24+
Name 27 "in_coords"
25+
Name 35 "read1"
26+
Name 36 "image1"
27+
Name 37 "param"
28+
Name 40 "read2"
29+
Name 41 "image2"
30+
Name 42 "param"
31+
Name 47 "image3"
32+
Name 51 "param"
33+
Name 53 "param"
34+
Name 57 "image4"
35+
Name 61 "param"
36+
Name 63 "param"
37+
Name 66 "out_color"
38+
Decorate 14(image) Coherent
39+
Decorate 14(image) NonWritable
40+
Decorate 20(image) Coherent
41+
Decorate 20(image) NonReadable
42+
Decorate 27(in_coords) Flat
43+
Decorate 27(in_coords) Location 0
44+
Decorate 36(image1) DescriptorSet 0
45+
Decorate 36(image1) Binding 0
46+
Decorate 36(image1) Coherent
47+
Decorate 36(image1) NonWritable
48+
Decorate 41(image2) DescriptorSet 0
49+
Decorate 41(image2) Binding 2
50+
Decorate 41(image2) NonWritable
51+
Decorate 47(image3) DescriptorSet 0
52+
Decorate 47(image3) Binding 1
53+
Decorate 47(image3) Coherent
54+
Decorate 47(image3) NonReadable
55+
Decorate 57(image4) DescriptorSet 0
56+
Decorate 57(image4) Binding 3
57+
Decorate 57(image4) NonReadable
58+
Decorate 66(out_color) Location 0
59+
2: TypeVoid
60+
3: TypeFunction 2
61+
6: TypeFloat 32
62+
7: TypeImage 6(float) 2D nonsampled format:Unknown
63+
8: TypePointer UniformConstant 7
64+
9: TypeInt 32 1
65+
10: TypeVector 9(int) 2
66+
11: TypePointer Function 10(ivec2)
67+
12: TypeVector 6(float) 4
68+
13: TypeFunction 12(fvec4) 8(ptr) 11(ptr)
69+
18: TypePointer Function 12(fvec4)
70+
19: TypeFunction 2 8(ptr) 11(ptr) 18(ptr)
71+
26: TypePointer Input 10(ivec2)
72+
27(in_coords): 26(ptr) Variable Input
73+
36(image1): 8(ptr) Variable UniformConstant
74+
41(image2): 8(ptr) Variable UniformConstant
75+
45: TypeImage 6(float) 2D nonsampled format:Rgba32f
76+
46: TypePointer UniformConstant 45
77+
47(image3): 46(ptr) Variable UniformConstant
78+
49: 6(float) Constant 1056964608
79+
55: TypeImage 6(float) 2D nonsampled format:Rgba16f
80+
56: TypePointer UniformConstant 55
81+
57(image4): 56(ptr) Variable UniformConstant
82+
59: 6(float) Constant 1073741824
83+
65: TypePointer Output 12(fvec4)
84+
66(out_color): 65(ptr) Variable Output
85+
67: 6(float) Constant 0
86+
68: 12(fvec4) ConstantComposite 67 67 67 67
87+
4(main): 2 Function None 3
88+
5: Label
89+
35(read1): 18(ptr) Variable Function
90+
37(param): 11(ptr) Variable Function
91+
40(read2): 18(ptr) Variable Function
92+
42(param): 11(ptr) Variable Function
93+
51(param): 11(ptr) Variable Function
94+
53(param): 18(ptr) Variable Function
95+
61(param): 11(ptr) Variable Function
96+
63(param): 18(ptr) Variable Function
97+
38: 10(ivec2) Load 27(in_coords)
98+
Store 37(param) 38
99+
39: 12(fvec4) FunctionCall 16(image_load(I21;vi2;) 36(image1) 37(param)
100+
Store 35(read1) 39
101+
43: 10(ivec2) Load 27(in_coords)
102+
Store 42(param) 43
103+
44: 12(fvec4) FunctionCall 16(image_load(I21;vi2;) 41(image2) 42(param)
104+
Store 40(read2) 44
105+
48: 12(fvec4) Load 35(read1)
106+
50: 12(fvec4) VectorTimesScalar 48 49
107+
52: 10(ivec2) Load 27(in_coords)
108+
Store 51(param) 52
109+
Store 53(param) 50
110+
54: 2 FunctionCall 23(image_store(I21;vi2;vf4;) 47(image3) 51(param) 53(param)
111+
58: 12(fvec4) Load 40(read2)
112+
60: 12(fvec4) VectorTimesScalar 58 59
113+
62: 10(ivec2) Load 27(in_coords)
114+
Store 61(param) 62
115+
Store 63(param) 60
116+
64: 2 FunctionCall 23(image_store(I21;vi2;vf4;) 57(image4) 61(param) 63(param)
117+
Store 66(out_color) 68
118+
Return
119+
FunctionEnd
120+
16(image_load(I21;vi2;): 12(fvec4) Function None 13
121+
14(image): 8(ptr) FunctionParameter
122+
15(coords): 11(ptr) FunctionParameter
123+
17: Label
124+
25: 7 Load 14(image)
125+
28: 10(ivec2) Load 27(in_coords)
126+
29: 12(fvec4) ImageRead 25 28
127+
ReturnValue 29
128+
FunctionEnd
129+
23(image_store(I21;vi2;vf4;): 2 Function None 19
130+
20(image): 8(ptr) FunctionParameter
131+
21(coords): 11(ptr) FunctionParameter
132+
22(data): 18(ptr) FunctionParameter
133+
24: Label
134+
32: 7 Load 20(image)
135+
33: 10(ivec2) Load 27(in_coords)
136+
34: 12(fvec4) Load 22(data)
137+
ImageWrite 32 33 34
138+
Return
139+
FunctionEnd

Test/spv.paramMemory.420.frag

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#version 420
2+
3+
// Need this extension to permit passing a formatless readonly image to a helper function.
4+
#extension GL_EXT_shader_image_load_formatted : require
5+
6+
readonly coherent uniform layout(set = 0, binding = 0) image2D image1;
7+
readonly uniform layout(set = 0, binding = 2) image2D image2;
8+
writeonly coherent uniform layout(set = 0, binding = 1, rgba32f) image2D image3;
9+
writeonly uniform layout(set = 0, binding = 3, rgba16f) image2D image4;
10+
11+
flat in layout(location = 0) ivec2 in_coords;
12+
out layout(location = 0) vec4 out_color;
13+
14+
vec4 image_load(readonly coherent image2D image, ivec2 coords)
15+
{
16+
return imageLoad(image, in_coords);
17+
}
18+
19+
void image_store(writeonly coherent image2D image, ivec2 coords, vec4 data)
20+
{
21+
imageStore(image, in_coords, data);
22+
}
23+
24+
void main()
25+
{
26+
vec4 read1 = image_load(image1, in_coords);
27+
vec4 read2 = image_load(image2, in_coords);
28+
29+
image_store(image3, in_coords, read1*0.5);
30+
image_store(image4, in_coords, read2*2.0);
31+
32+
out_color = vec4(0.0);
33+
}

gtests/Spv.FromFile.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ INSTANTIATE_TEST_SUITE_P(
376376
"spv.offsets.frag",
377377
"spv.Operations.frag",
378378
"spv.paramMemory.frag",
379+
"spv.paramMemory.420.frag",
379380
"spv.precision.frag",
380381
"spv.precisionArgs.frag",
381382
"spv.precisionNonESSamp.frag",

0 commit comments

Comments
 (0)