1# UBO test using an array of ubos, with complex content.
2
3[require]
4SPIRV YES
5GL >= 3.3
6GLSL >= 4.50
7GL_ARB_gl_spirv
8
9[vertex shader passthrough]
10
11[fragment shader spirv]
12; Automatically generated from the GLSL by shader_test_spirv.py. DO NOT EDIT
13; SPIR-V
14; Version: 1.0
15; Generator: Khronos Glslang Reference Front End; 7
16; Bound: 159
17; Schema: 0
18               OpCapability Shader
19          %1 = OpExtInstImport "GLSL.std.450"
20               OpMemoryModel Logical GLSL450
21               OpEntryPoint Fragment %main "main" %color
22               OpExecutionMode %main OriginLowerLeft
23               OpSource GLSL 450
24               OpDecorate %color Location 0
25               OpDecorate %_arr_v3float_uint_3 ArrayStride 16
26               OpDecorate %_arr_mat2v2float_uint_3 ArrayStride 32
27               OpMemberDecorate %S 0 Offset 0
28               OpMemberDecorate %S 1 Offset 48
29               OpMemberDecorate %S 2 RowMajor
30               OpMemberDecorate %S 2 Offset 64
31               OpMemberDecorate %S 2 MatrixStride 16
32               OpDecorate %_arr_S_uint_3 ArrayStride 160
33               OpMemberDecorate %ComponentsBlock 0 Offset 0
34               OpMemberDecorate %ComponentsBlock 1 Offset 8
35               OpMemberDecorate %ComponentsBlock 2 Offset 16
36               OpDecorate %ComponentsBlock Block
37               OpDecorate %components DescriptorSet 0
38               OpDecorate %components Binding 5
39               OpDecorate %struct_array Location 6
40               OpDecorate %struct_array DescriptorSet 0
41               OpDecorate %struct_array Binding 0
42       %void = OpTypeVoid
43          %3 = OpTypeFunction %void
44      %float = OpTypeFloat 32
45    %v4float = OpTypeVector %float 4
46%_ptr_Function_v4float = OpTypePointer Function %v4float
47    %float_1 = OpConstant %float 1
48    %float_0 = OpConstant %float 0
49         %12 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
50%_ptr_Output_v4float = OpTypePointer Output %v4float
51      %color = OpVariable %_ptr_Output_v4float Output
52         %15 = OpConstantComposite %v4float %float_0 %float_1 %float_0 %float_1
53    %v2float = OpTypeVector %float 2
54    %v3float = OpTypeVector %float 3
55       %uint = OpTypeInt 32 0
56     %uint_3 = OpConstant %uint 3
57%_arr_v3float_uint_3 = OpTypeArray %v3float %uint_3
58%mat2v2float = OpTypeMatrix %v2float 2
59%_arr_mat2v2float_uint_3 = OpTypeArray %mat2v2float %uint_3
60          %S = OpTypeStruct %_arr_v3float_uint_3 %v4float %_arr_mat2v2float_uint_3
61%_arr_S_uint_3 = OpTypeArray %S %uint_3
62%ComponentsBlock = OpTypeStruct %float %v2float %_arr_S_uint_3
63     %uint_2 = OpConstant %uint 2
64%_arr_ComponentsBlock_uint_2 = OpTypeArray %ComponentsBlock %uint_2
65%_ptr_Uniform__arr_ComponentsBlock_uint_2 = OpTypePointer Uniform %_arr_ComponentsBlock_uint_2
66 %components = OpVariable %_ptr_Uniform__arr_ComponentsBlock_uint_2 Uniform
67        %int = OpTypeInt 32 1
68      %int_0 = OpConstant %int 0
69%_ptr_Uniform_float = OpTypePointer Uniform %float
70%float_5720_54443 = OpConstant %float 5720.54443
71       %bool = OpTypeBool
72      %int_1 = OpConstant %int 1
73%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
74%float_n21857_1582 = OpConstant %float -21857.1582
75%float_n711_078674 = OpConstant %float -711.078674
76         %47 = OpConstantComposite %v2float %float_n21857_1582 %float_n711_078674
77     %v2bool = OpTypeVector %bool 2
78      %int_2 = OpConstant %int 2
79%_ptr_Uniform_v3float = OpTypePointer Uniform %v3float
80%float_8904_7334 = OpConstant %float 8904.7334
81%float_3164_0835 = OpConstant %float 3164.0835
82%float_20808_1934 = OpConstant %float 20808.1934
83         %61 = OpConstantComposite %v3float %float_8904_7334 %float_3164_0835 %float_20808_1934
84     %v3bool = OpTypeVector %bool 3
85%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
86%float_n6150_84961 = OpConstant %float -6150.84961
87%float_n10267_4893 = OpConstant %float -10267.4893
88%float_26495_5859 = OpConstant %float 26495.5859
89%float_n12496_1973 = OpConstant %float -12496.1973
90         %75 = OpConstantComposite %v4float %float_n6150_84961 %float_n10267_4893 %float_26495_5859 %float_n12496_1973
91     %v4bool = OpTypeVector %bool 4
92%float_n3839_13696 = OpConstant %float -3839.13696
93%float_19438_668 = OpConstant %float 19438.668
94         %86 = OpConstantComposite %v2float %float_n3839_13696 %float_19438_668
95%float_1848_25549 = OpConstant %float 1848.25549
96%float_n2268_96582 = OpConstant %float -2268.96582
97%float_n1441_44067 = OpConstant %float -1441.44067
98        %103 = OpConstantComposite %v2float %float_n2268_96582 %float_n1441_44067
99%float_12916_126 = OpConstant %float 12916.126
100%float_23087_1719 = OpConstant %float 23087.1719
101%float_n21303_748 = OpConstant %float -21303.748
102        %114 = OpConstantComposite %v3float %float_12916_126 %float_23087_1719 %float_n21303_748
103%float_n10231_1807 = OpConstant %float -10231.1807
104%float_11729_6475 = OpConstant %float 11729.6475
105%float_n2747_33765 = OpConstant %float -2747.33765
106%float_n30325_041 = OpConstant %float -30325.041
107        %126 = OpConstantComposite %v4float %float_n10231_1807 %float_11729_6475 %float_n2747_33765 %float_n30325_041
108%float_19382_7812 = OpConstant %float 19382.7812
109%float_28998_5918 = OpConstant %float 28998.5918
110        %136 = OpConstantComposite %v2float %float_19382_7812 %float_28998_5918
111        %S_0 = OpTypeStruct %_arr_v3float_uint_3 %v4float %_arr_mat2v2float_uint_3
112%_arr_S_0_uint_2 = OpTypeArray %S_0 %uint_2
113%_ptr_UniformConstant__arr_S_0_uint_2 = OpTypePointer UniformConstant %_arr_S_0_uint_2
114%struct_array = OpVariable %_ptr_UniformConstant__arr_S_0_uint_2 UniformConstant
115%_ptr_UniformConstant_v4float = OpTypePointer UniformConstant %v4float
116%float_16690_9727 = OpConstant %float 16690.9727
117%float_n30557_1582 = OpConstant %float -30557.1582
118%float_n16199_5928 = OpConstant %float -16199.5928
119%float_2088_69482 = OpConstant %float 2088.69482
120        %153 = OpConstantComposite %v4float %float_16690_9727 %float_n30557_1582 %float_n16199_5928 %float_2088_69482
121       %main = OpFunction %void None %3
122          %5 = OpLabel
123 %fail_color = OpVariable %_ptr_Function_v4float Function
124               OpStore %fail_color %12
125               OpStore %color %15
126         %33 = OpAccessChain %_ptr_Uniform_float %components %int_0 %int_0
127         %34 = OpLoad %float %33
128         %37 = OpFOrdNotEqual %bool %34 %float_5720_54443
129               OpSelectionMerge %39 None
130               OpBranchConditional %37 %38 %39
131         %38 = OpLabel
132         %40 = OpLoad %v4float %fail_color
133               OpStore %color %40
134               OpBranch %39
135         %39 = OpLabel
136         %43 = OpAccessChain %_ptr_Uniform_v2float %components %int_0 %int_1
137         %44 = OpLoad %v2float %43
138         %49 = OpFOrdNotEqual %v2bool %44 %47
139         %50 = OpAny %bool %49
140               OpSelectionMerge %52 None
141               OpBranchConditional %50 %51 %52
142         %51 = OpLabel
143         %53 = OpLoad %v4float %fail_color
144               OpStore %color %53
145               OpBranch %52
146         %52 = OpLabel
147         %56 = OpAccessChain %_ptr_Uniform_v3float %components %int_0 %int_2 %int_0 %int_0 %int_1
148         %57 = OpLoad %v3float %56
149         %63 = OpFOrdNotEqual %v3bool %57 %61
150         %64 = OpAny %bool %63
151               OpSelectionMerge %66 None
152               OpBranchConditional %64 %65 %66
153         %65 = OpLabel
154         %67 = OpLoad %v4float %fail_color
155               OpStore %color %67
156               OpBranch %66
157         %66 = OpLabel
158         %69 = OpAccessChain %_ptr_Uniform_v4float %components %int_0 %int_2 %int_1 %int_1
159         %70 = OpLoad %v4float %69
160         %77 = OpFOrdNotEqual %v4bool %70 %75
161         %78 = OpAny %bool %77
162               OpSelectionMerge %80 None
163               OpBranchConditional %78 %79 %80
164         %79 = OpLabel
165         %81 = OpLoad %v4float %fail_color
166               OpStore %color %81
167               OpBranch %80
168         %80 = OpLabel
169         %82 = OpAccessChain %_ptr_Uniform_v2float %components %int_0 %int_2 %int_2 %int_2 %int_0 %int_0
170         %83 = OpLoad %v2float %82
171         %87 = OpFOrdNotEqual %v2bool %83 %86
172         %88 = OpAny %bool %87
173               OpSelectionMerge %90 None
174               OpBranchConditional %88 %89 %90
175         %89 = OpLabel
176         %91 = OpLoad %v4float %fail_color
177               OpStore %color %91
178               OpBranch %90
179         %90 = OpLabel
180         %92 = OpAccessChain %_ptr_Uniform_float %components %int_1 %int_0
181         %93 = OpLoad %float %92
182         %95 = OpFOrdNotEqual %bool %93 %float_1848_25549
183               OpSelectionMerge %97 None
184               OpBranchConditional %95 %96 %97
185         %96 = OpLabel
186         %98 = OpLoad %v4float %fail_color
187               OpStore %color %98
188               OpBranch %97
189         %97 = OpLabel
190         %99 = OpAccessChain %_ptr_Uniform_v2float %components %int_1 %int_1
191        %100 = OpLoad %v2float %99
192        %104 = OpFOrdNotEqual %v2bool %100 %103
193        %105 = OpAny %bool %104
194               OpSelectionMerge %107 None
195               OpBranchConditional %105 %106 %107
196        %106 = OpLabel
197        %108 = OpLoad %v4float %fail_color
198               OpStore %color %108
199               OpBranch %107
200        %107 = OpLabel
201        %109 = OpAccessChain %_ptr_Uniform_v3float %components %int_1 %int_2 %int_0 %int_0 %int_1
202        %110 = OpLoad %v3float %109
203        %115 = OpFOrdNotEqual %v3bool %110 %114
204        %116 = OpAny %bool %115
205               OpSelectionMerge %118 None
206               OpBranchConditional %116 %117 %118
207        %117 = OpLabel
208        %119 = OpLoad %v4float %fail_color
209               OpStore %color %119
210               OpBranch %118
211        %118 = OpLabel
212        %120 = OpAccessChain %_ptr_Uniform_v4float %components %int_1 %int_2 %int_1 %int_1
213        %121 = OpLoad %v4float %120
214        %127 = OpFOrdNotEqual %v4bool %121 %126
215        %128 = OpAny %bool %127
216               OpSelectionMerge %130 None
217               OpBranchConditional %128 %129 %130
218        %129 = OpLabel
219        %131 = OpLoad %v4float %fail_color
220               OpStore %color %131
221               OpBranch %130
222        %130 = OpLabel
223        %132 = OpAccessChain %_ptr_Uniform_v2float %components %int_1 %int_2 %int_2 %int_2 %int_0 %int_0
224        %133 = OpLoad %v2float %132
225        %137 = OpFOrdNotEqual %v2bool %133 %136
226        %138 = OpAny %bool %137
227               OpSelectionMerge %140 None
228               OpBranchConditional %138 %139 %140
229        %139 = OpLabel
230        %141 = OpLoad %v4float %fail_color
231               OpStore %color %141
232               OpBranch %140
233        %140 = OpLabel
234        %147 = OpAccessChain %_ptr_UniformConstant_v4float %struct_array %int_1 %int_1
235        %148 = OpLoad %v4float %147
236        %154 = OpFOrdNotEqual %v4bool %148 %153
237        %155 = OpAny %bool %154
238               OpSelectionMerge %157 None
239               OpBranchConditional %155 %156 %157
240        %156 = OpLabel
241        %158 = OpLoad %v4float %fail_color
242               OpStore %color %158
243               OpBranch %157
244        %157 = OpLabel
245               OpReturn
246               OpFunctionEnd
247
248[fragment shader]
249
250#version 450
251
252struct S {
253  vec3 c3[3];
254  vec4 c4;
255  mat2x2 m22[3];
256};
257
258layout (location = 0) out vec4 color;
259layout (std140, binding = 5, row_major) uniform ComponentsBlock
260 {
261    float c1;
262    vec2 c2;
263    S s[3];
264 } components[2];
265
266/* The main reason to have an array of type S is to test that in this
267 * case, it is generated as many uniforms as array_length *
268 * struct_size (recursively), in opposite an ubo array, where they are
269 * added as many uniforms as struct_size (recursively). That
270 * difference needs to be handled on the driver
271 */
272layout (location = 6) uniform S struct_array[2];
273
274void main()
275{
276	vec4 fail_color = vec4(1.0, 0.0, 0.0, 1.0);
277	color = vec4(0.0, 1.0, 0.0, 1.0);
278
279	if (components[0].c1 != 5720.54428931)
280	   color = fail_color;
281
282	if (components[0].c2 != vec2(-21857.1581292, -711.078644999))
283	   color = fail_color;
284
285	if (components[0].s[0].c3[1] != vec3(8904.73374533, 3164.08349737, 20808.1933471))
286	   color = fail_color;
287
288	if (components[0].s[1].c4 != vec4(-6150.84975967, -10267.4895552, 26495.5859007, -12496.1967803))
289	   color = fail_color;
290
291	if (components[0].s[2].m22[0][0] != vec2(-3839.13702602, 19438.6676432))
292	   color = fail_color;
293
294	if (components[1].c1 != 1848.25552758)
295	   color = fail_color;
296
297	if (components[1].c2 != vec2(-2268.96586557, -1441.44065003))
298	   color = fail_color;
299
300	if (components[1].s[0].c3[1] != vec3(12916.12607, 23087.1716182, -21303.7489128))
301	   color = fail_color;
302
303	if (components[1].s[1].c4 != vec4(-10231.1810483, 11729.6478218, -2747.33765164, -30325.0400702))
304	   color = fail_color;
305
306	if (components[1].s[2].m22[0][0] != vec2(19382.7803769, 28998.5927672))
307	   color = fail_color;
308
309	if (struct_array[1].c4 != vec4(16690.9719539, -30557.1591211, -16199.592401, 2088.69494163))
310	   color = fail_color;
311}
312
313[test]
314clear color 1.0 0.0 0.0 0.0
315clear
316
317block binding 5
318
319block array index 0
320block offset 0
321uniform float ComponentsBlock.c1        5720.54428931
322block offset 8
323uniform vec2  ComponentsBlock.c2        -21857.1581292 -711.078644999
324block offset 32
325uniform vec3  ComponentsBlock.s[0].c3[1]   8904.73374533 3164.08349737 20808.1933471
326block offset 224
327uniform vec4  ComponentsBlock.s[1].c4     -6150.84975967 -10267.4895552 26495.5859007 -12496.1967803
328block row major 1
329block matrix stride 16
330block offset 400
331uniform mat2  ComponentsBlock.s[2].m22[0]   -3839.13702602 19438.6676432
332
333block array index 1
334block offset 0
335uniform float ComponentsBlock.c1        1848.25552758
336block offset 8
337uniform vec2  ComponentsBlock.c2        -2268.96586557 -1441.44065003
338block offset 32
339uniform vec3  ComponentsBlock.s[0].c3[1]   12916.12607 23087.1716182 -21303.7489128
340block offset 224
341uniform vec4  ComponentsBlock.s[1].c4     -10231.1810483 11729.6478218 -2747.33765164 -30325.0400702
342block offset 400
343uniform mat2  ComponentsBlock.s[2].m22[0]  19382.7803769 28998.5927672
344
345#struct_array[1].c4
346uniform vec4 16 16690.9719539 -30557.1591211 -16199.592401 2088.69494163
347
348block binding 5
349verify program_interface_query GL_UNIFORM_BLOCK ComponentsBlock[0] GL_NUM_ACTIVE_VARIABLES 11
350verify program_interface_query GL_UNIFORM_BLOCK ComponentsBlock[0] GL_BUFFER_DATA_SIZE 496
351
352block binding 6
353verify program_interface_query GL_UNIFORM_BLOCK ComponentsBlock[1] GL_NUM_ACTIVE_VARIABLES 11
354verify program_interface_query GL_UNIFORM_BLOCK ComponentsBlock[1] GL_BUFFER_DATA_SIZE 496
355
356verify program_query GL_ACTIVE_UNIFORM_BLOCKS 2
357verify program_query GL_ACTIVE_UNIFORMS 17
358
359draw rect -1 -1 2 2
360probe all rgba 0.0 1.0 0.0 1.0
361