1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2018 Google Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief SPIR-V Assembly Tests for indexing with different bit sizes.
22 *//*--------------------------------------------------------------------*/
24 #include "vktSpvAsmIndexingTests.hpp"
25 #include "vktSpvAsmComputeShaderCase.hpp"
26 #include "vktSpvAsmComputeShaderTestUtil.hpp"
27 #include "vktSpvAsmGraphicsShaderTestUtil.hpp"
29 #include "tcuStringTemplate.hpp"
33 namespace SpirVAssembly
46 using tcu::StringTemplate;
53 CHAIN_OP_ACCESS_CHAIN = 0,
54 CHAIN_OP_IN_BOUNDS_ACCESS_CHAIN,
55 CHAIN_OP_PTR_ACCESS_CHAIN,
59 static const int idxSizes[] = { 16, 32, 64 };
60 static const ComputeTestFeatures computeTestFeatures[] = { COMPUTE_TEST_USES_INT16, COMPUTE_TEST_USES_NONE, COMPUTE_TEST_USES_INT64 };
61 static const string chainOpTestNames[] = { "opaccesschain", "opinboundsaccesschain", "opptraccesschain" };
68 void addComputeIndexingStructTests (tcu::TestCaseGroup* group)
70 tcu::TestContext& testCtx = group->getTestContext();
71 de::MovePtr<tcu::TestCaseGroup> structGroup (new tcu::TestCaseGroup(testCtx, "struct", "Tests for indexing input struct."));
72 de::Random rnd (deStringHash(group->getName()));
73 const int numItems = 128;
74 const int numStructs = 2;
75 const int numInputFloats = (int)sizeof(InputData) / 4 * numStructs;
76 vector<float> inputData;
77 vector<UVec4> indexSelectorData;
79 inputData.reserve(numInputFloats);
80 for (deUint32 numIdx = 0; numIdx < numInputFloats; ++numIdx)
81 inputData.push_back(rnd.getFloat());
83 indexSelectorData.reserve(numItems);
84 for (deUint32 numIdx = 0; numIdx < numItems; ++numIdx)
85 indexSelectorData.push_back(UVec4(rnd.getUint32() % 32, rnd.getUint32() % 32, rnd.getUint32() % 4, rnd.getUint32() % 4));
87 for (int chainOpIdx = 0; chainOpIdx < CHAIN_OP_LAST; ++chainOpIdx)
89 for (int idxSizeIdx = 0; idxSizeIdx < DE_LENGTH_OF_ARRAY(idxSizes); ++idxSizeIdx)
91 for (int sign = 0; sign < 2; ++sign)
93 const int idxSize = idxSizes[idxSizeIdx];
94 const string testName = chainOpTestNames[chainOpIdx] + string(sign == 0 ? "_u" : "_s") + de::toString(idxSize);
95 VulkanFeatures vulkanFeatures;
96 map<string, string> specs;
97 vector<float> outputData;
98 ComputeShaderSpec spec;
99 const ComputeTestFeatures features = computeTestFeatures[idxSizeIdx];
102 // Index an input buffer containing 2D array of 4x4 matrices. The indices are read from another
103 // input and converted to the desired bit size and sign.
104 const StringTemplate shaderSource(
105 " OpCapability Shader\n"
107 " ${variablepointercaps:opt}\n"
108 " ${extensions:opt}\n"
109 " %1 = OpExtInstImport \"GLSL.std.450\"\n"
110 " OpMemoryModel Logical GLSL450\n"
111 " OpEntryPoint GLCompute %main \"main\" %gl_GlobalInvocationID\n"
112 " OpExecutionMode %main LocalSize 1 1 1\n"
113 " OpSource GLSL 430\n"
114 " OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId\n"
115 " OpDecorate %_arr_float_uint_128 ArrayStride 4\n"
116 " OpMemberDecorate %Output 0 Offset 0\n"
117 " OpDecorate %Output BufferBlock\n"
118 " OpDecorate %dataOutput DescriptorSet 0\n"
119 " OpDecorate %dataOutput Binding 2\n"
120 " OpDecorate %_arr_mat4v4float_uint_32 ArrayStride 64\n"
121 " OpDecorate %_arr__arr_mat4v4float_uint_32_uint_32 ArrayStride 2048\n"
122 " OpMemberDecorate %InputStruct 0 ColMajor\n"
123 " OpMemberDecorate %InputStruct 0 Offset 0\n"
124 " OpMemberDecorate %InputStruct 0 MatrixStride 16\n"
125 " OpDecorate %InputStructArr ArrayStride 65536\n"
126 " OpDecorate %Input ${inputdecoration}\n"
127 " OpMemberDecorate %Input 0 Offset 0\n"
128 " OpDecorate %dataInput DescriptorSet 0\n"
129 " OpDecorate %dataInput Binding 0\n"
130 " OpDecorate %_ptr_buffer_InputStruct ArrayStride 65536\n"
131 " OpDecorate %_arr_v4uint_uint_128 ArrayStride 16\n"
132 " OpMemberDecorate %DataSelector 0 Offset 0\n"
133 " OpDecorate %DataSelector BufferBlock\n"
134 " OpDecorate %selector DescriptorSet 0\n"
135 " OpDecorate %selector Binding 1\n"
136 " %void = OpTypeVoid\n"
137 " %3 = OpTypeFunction %void\n"
138 " %u32 = OpTypeInt 32 0\n"
139 " %i32 = OpTypeInt 32 1\n"
141 " %idx_0 = OpConstant ${idx_int} 0\n"
142 " %idx_1 = OpConstant ${idx_int} 1\n"
143 " %idx_2 = OpConstant ${idx_int} 2\n"
144 " %idx_3 = OpConstant ${idx_int} 3\n"
145 " %_ptr_Function_uint32 = OpTypePointer Function %u32\n"
146 " %v3uint32 = OpTypeVector %u32 3\n"
147 " %_ptr_Input_v3uint32 = OpTypePointer Input %v3uint32\n"
148 " %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint32 Input\n"
149 " %_ptr_Input_uint32 = OpTypePointer Input %u32\n"
150 " %float = OpTypeFloat 32\n"
151 " %uint_128 = OpConstant %u32 128\n"
152 " %uint_32 = OpConstant %u32 32\n"
153 " %uint_2 = OpConstant %u32 2\n"
154 " %_arr_float_uint_128 = OpTypeArray %float %uint_128\n"
155 " %Output = OpTypeStruct %_arr_float_uint_128\n"
156 " %_ptr_Uniform_Output = OpTypePointer Uniform %Output\n"
157 " %dataOutput = OpVariable %_ptr_Uniform_Output Uniform\n"
158 " %v4float = OpTypeVector %float 4\n"
159 " %mat4v4float = OpTypeMatrix %v4float 4\n"
160 " %_arr_mat4v4float_uint_32 = OpTypeArray %mat4v4float %uint_32\n"
161 " %_arr__arr_mat4v4float_uint_32_uint_32 = OpTypeArray %_arr_mat4v4float_uint_32 %uint_32\n"
162 " %InputStruct = OpTypeStruct %_arr__arr_mat4v4float_uint_32_uint_32\n"
163 " %InputStructArr = OpTypeArray %InputStruct %uint_2\n"
164 " %Input = OpTypeStruct %InputStructArr\n"
165 " %_ptr_buffer_Input = OpTypePointer ${inputstorageclass} %Input\n"
166 " %dataInput = OpVariable %_ptr_buffer_Input ${inputstorageclass}\n"
167 " %_ptr_buffer_InputStruct = OpTypePointer ${inputstorageclass} %InputStruct\n"
168 " %v4uint32 = OpTypeVector %u32 4\n"
169 " %_arr_v4uint_uint_128 = OpTypeArray %v4uint32 %uint_128\n"
170 " %DataSelector = OpTypeStruct %_arr_v4uint_uint_128\n"
171 "%_ptr_Uniform_DataSelector = OpTypePointer Uniform %DataSelector\n"
172 " %selector = OpVariable %_ptr_Uniform_DataSelector Uniform\n"
173 " %_ptr_Uniform_uint32 = OpTypePointer Uniform %u32\n"
174 " %_ptr_Uniform_float = OpTypePointer Uniform %float\n"
175 " ${ptr_buffer_float:opt}\n"
177 " %main = OpFunction %void None %3\n"
179 " %i = OpVariable %_ptr_Function_uint32 Function\n"
180 " %14 = OpAccessChain %_ptr_Input_uint32 %gl_GlobalInvocationID %idx_0\n"
181 " %15 = OpLoad %u32 %14\n"
183 " %uint_i = OpLoad %u32 %i\n"
184 " %39 = OpAccessChain %_ptr_Uniform_uint32 %selector %idx_0 %uint_i %idx_0\n"
185 " %40 = OpLoad %u32 %39\n"
186 " %43 = OpAccessChain %_ptr_Uniform_uint32 %selector %idx_0 %uint_i %idx_1\n"
187 " %44 = OpLoad %u32 %43\n"
188 " %47 = OpAccessChain %_ptr_Uniform_uint32 %selector %idx_0 %uint_i %idx_2\n"
189 " %48 = OpLoad %u32 %47\n"
190 " %51 = OpAccessChain %_ptr_Uniform_uint32 %selector %idx_0 %uint_i %idx_3\n"
191 " %52 = OpLoad %u32 %51\n"
192 " %i0 = ${convert} ${idx_int} %40\n"
193 " %i1 = ${convert} ${idx_int} %44\n"
194 " %i2 = ${convert} ${idx_int} %48\n"
195 " %i3 = ${convert} ${idx_int} %52\n"
196 " %inputFirstElement = OpAccessChain %_ptr_buffer_InputStruct %dataInput %idx_0 %idx_0\n"
197 " %54 = ${accesschain}\n"
198 " %55 = OpLoad %float %54\n"
199 " %56 = OpAccessChain %_ptr_Uniform_float %dataOutput %idx_0 %uint_i\n"
207 case CHAIN_OP_ACCESS_CHAIN:
208 specs["accesschain"] = "OpAccessChain %_ptr_Uniform_float %inputFirstElement %idx_0 %i0 %i1 %i2 %i3\n";
209 specs["inputdecoration"] = "BufferBlock";
210 specs["inputstorageclass"] = "Uniform";
212 case CHAIN_OP_IN_BOUNDS_ACCESS_CHAIN:
213 specs["accesschain"] = "OpInBoundsAccessChain %_ptr_Uniform_float %inputFirstElement %idx_0 %i0 %i1 %i2 %i3\n";
214 specs["inputdecoration"] = "BufferBlock";
215 specs["inputstorageclass"] = "Uniform";
218 DE_ASSERT(chainOpIdx == CHAIN_OP_PTR_ACCESS_CHAIN);
219 specs["accesschain"] = "OpPtrAccessChain %_ptr_StorageBuffer_float %inputFirstElement %idx_1 %idx_0 %i0 %i1 %i2 %i3\n";
220 specs["inputdecoration"] = "Block";
221 specs["inputstorageclass"] = "StorageBuffer";
222 specs["variablepointercaps"] = "OpCapability VariablePointersStorageBuffer";
223 specs["ptr_buffer_float"] = "%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float";
224 specs["extensions"] = "OpExtension \"SPV_KHR_variable_pointers\"\n "
225 "OpExtension \"SPV_KHR_storage_buffer_storage_class\"";
227 vulkanFeatures.extVariablePointers = EXTVARIABLEPOINTERSFEATURES_VARIABLE_POINTERS_STORAGEBUFFER;
228 spec.extensions.push_back("VK_KHR_variable_pointers");
232 spec.inputs.push_back(BufferSp(new Float32Buffer(inputData)));
233 spec.inputs.push_back(BufferSp(new Buffer<UVec4>(indexSelectorData)));
235 outputData.reserve(numItems);
236 for (deUint32 numIdx = 0; numIdx < numItems; ++numIdx)
238 // Determine the selected output float for the selected indices.
239 const UVec4 vec = indexSelectorData[numIdx];
240 outputData.push_back(inputData[element * sizeof(InputData) / 4 + vec.x() * (32 * 4 * 4) + vec.y() * 4 * 4 + vec.z() * 4 + vec.w()]);
245 specs["intcaps"] = "OpCapability Int16";
246 specs["convert"] = "OpSConvert";
247 specs["intdecl"] = " %u16 = OpTypeInt 16 0\n"
248 " %i16 = OpTypeInt 16 1\n";
250 else if (idxSize == 64)
252 specs["intcaps"] = "OpCapability Int64";
253 specs["convert"] = "OpSConvert";
254 specs["intdecl"] = " %u64 = OpTypeInt 64 0\n"
255 " %i64 = OpTypeInt 64 1\n";
257 specs["convert"] = "OpBitcast";
260 specs["idx_uint"] = "%u" + de::toString(idxSize);
261 specs["idx_int"] = (sign ? "%i" : "%u") + de::toString(idxSize);
263 spec.assembly = shaderSource.specialize(specs);
264 spec.numWorkGroups = IVec3(numItems, 1, 1);
265 spec.requestedVulkanFeatures = vulkanFeatures;
266 spec.inputs[0].setDescriptorType(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
267 spec.inputs[1].setDescriptorType(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
269 spec.outputs.push_back(BufferSp(new Float32Buffer(outputData)));
271 structGroup->addChild(new SpvAsmComputeShaderCase(testCtx, testName.c_str(), testName.c_str(), spec, features));
275 group->addChild(structGroup.release());
278 void addGraphicsIndexingStructTests (tcu::TestCaseGroup* group)
280 tcu::TestContext& testCtx = group->getTestContext();
281 de::MovePtr<tcu::TestCaseGroup> structGroup (new tcu::TestCaseGroup(testCtx, "struct", "Tests for indexing input struct."));
282 de::Random rnd (deStringHash(group->getName()));
283 const int numItems = 128;
284 const int numStructs = 2;
285 const int numInputFloats = (int)sizeof(InputData) / 4 * numStructs;
286 RGBA defaultColors[4];
287 vector<float> inputData;
288 vector<UVec4> indexSelectorData;
290 inputData.reserve(numInputFloats);
291 for (deUint32 numIdx = 0; numIdx < numInputFloats; ++numIdx)
292 inputData.push_back(rnd.getFloat());
294 indexSelectorData.reserve(numItems);
295 for (deUint32 numIdx = 0; numIdx < numItems; ++numIdx)
296 indexSelectorData.push_back(UVec4(rnd.getUint32() % 32, rnd.getUint32() % 32, rnd.getUint32() % 4, rnd.getUint32() % 4));
298 getDefaultColors(defaultColors);
300 for (int chainOpIdx = 0; chainOpIdx < CHAIN_OP_LAST; ++chainOpIdx)
302 for (int idxSizeIdx = 0; idxSizeIdx < DE_LENGTH_OF_ARRAY(idxSizes); ++idxSizeIdx)
304 for (int sign = 0; sign < 2; sign++)
306 const int idxSize = idxSizes[idxSizeIdx];
307 const string testName = chainOpTestNames[chainOpIdx] + string(sign == 0 ? "_u" : "_s") + de::toString(idxSize);
308 VulkanFeatures vulkanFeatures;
309 vector<string> extensions;
310 vector<string> features;
311 SpecConstants noSpecConstants;
312 PushConstants noPushConstants;
313 GraphicsInterfaces noInterfaces;
314 map<string, string> specs;
315 map<string, string> fragments;
316 vector<float> outputData;
317 ComputeShaderSpec spec;
319 GraphicsResources resources;
321 const StringTemplate preMain(
323 " %c_i32_128 = OpConstant %i32 128\n"
324 " %uint_0 = OpConstant ${idx_uint} 0\n"
325 " %uint_128 = OpConstant %u32 128\n"
326 " %uint_32 = OpConstant %u32 32\n"
327 " %uint_1 = OpConstant ${idx_uint} 1\n"
328 " %uint_2 = OpConstant ${idx_uint} 2\n"
329 " %uint_3 = OpConstant ${idx_uint} 3\n"
330 " %_arr_float_uint_128 = OpTypeArray %f32 %uint_128\n"
331 " %Output = OpTypeStruct %_arr_float_uint_128\n"
332 " %_ptr_Uniform_Output = OpTypePointer Uniform %Output\n"
333 " %dataOutput = OpVariable %_ptr_Uniform_Output Uniform\n"
334 " %int_0 = OpConstant ${idx_int} 0\n"
335 " %mat4v4float = OpTypeMatrix %v4f32 4\n"
336 " %_arr_mat4v4float_uint_32 = OpTypeArray %mat4v4float %uint_32\n"
337 " %_arr__arr_mat4v4float_uint_32_uint_32 = OpTypeArray %_arr_mat4v4float_uint_32 %uint_32\n"
338 " %InputStruct = OpTypeStruct %_arr__arr_mat4v4float_uint_32_uint_32\n"
339 " %InputStructArr = OpTypeArray %InputStruct %uint_2\n"
340 " %Input = OpTypeStruct %InputStructArr\n"
341 " %_ptr_buffer_Input = OpTypePointer ${inputstorageclass} %Input\n"
342 " %dataInput = OpVariable %_ptr_buffer_Input ${inputstorageclass}\n"
343 " %_ptr_buffer_InputStruct = OpTypePointer ${inputstorageclass} %InputStruct\n"
344 " %_arr_v4uint_uint_128 = OpTypeArray %v4u32 %uint_128\n"
345 " %DataSelector = OpTypeStruct %_arr_v4uint_uint_128\n"
346 "%_ptr_Uniform_DataSelector = OpTypePointer Uniform %DataSelector\n"
347 " %selector = OpVariable %_ptr_Uniform_DataSelector Uniform\n"
348 " %_ptr_Uniform_uint32 = OpTypePointer Uniform %u32\n"
349 " %_ptr_Uniform_float = OpTypePointer Uniform %f32\n"
350 " ${ptr_buffer_float:opt}\n");
353 const StringTemplate decoration(
354 "OpDecorate %_arr_float_uint_128 ArrayStride 4\n"
355 "OpMemberDecorate %Output 0 Offset 0\n"
356 "OpDecorate %Output BufferBlock\n"
357 "OpDecorate %dataOutput DescriptorSet 0\n"
358 "OpDecorate %dataOutput Binding 2\n"
359 "OpDecorate %_arr_mat4v4float_uint_32 ArrayStride 64\n"
360 "OpDecorate %_arr__arr_mat4v4float_uint_32_uint_32 ArrayStride 2048\n"
361 "OpMemberDecorate %InputStruct 0 ColMajor\n"
362 "OpMemberDecorate %InputStruct 0 Offset 0\n"
363 "OpMemberDecorate %InputStruct 0 MatrixStride 16\n"
364 "OpDecorate %InputStructArr ArrayStride 65536\n"
365 "OpDecorate %Input ${inputdecoration}\n"
366 "OpMemberDecorate %Input 0 Offset 0\n"
367 "OpDecorate %dataInput DescriptorSet 0\n"
368 "OpDecorate %dataInput Binding 0\n"
369 "OpDecorate %_ptr_buffer_InputStruct ArrayStride 65536\n"
370 "OpDecorate %_arr_v4uint_uint_128 ArrayStride 16\n"
371 "OpMemberDecorate %DataSelector 0 Offset 0\n"
372 "OpDecorate %DataSelector BufferBlock\n"
373 "OpDecorate %selector DescriptorSet 0\n"
374 "OpDecorate %selector Binding 1\n");
376 // Index an input buffer containing 2D array of 4x4 matrices. The indices are read from another
377 // input and converted to the desired bit size and sign.
378 const StringTemplate testFun(
379 " %test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n"
380 " %param = OpFunctionParameter %v4f32\n"
382 " %entry = OpLabel\n"
383 " %i = OpVariable %fp_i32 Function\n"
384 " OpStore %i %c_i32_0\n"
388 " %15 = OpLoad %i32 %i\n"
389 " %lt = OpSLessThan %bool %15 %c_i32_128\n"
390 " OpLoopMerge %merge %inc None\n"
391 " OpBranchConditional %lt %write %merge\n"
393 " %write = OpLabel\n"
394 " %int_i = OpLoad %i32 %i\n"
395 " %39 = OpAccessChain %_ptr_Uniform_uint32 %selector %int_0 %int_i %uint_0\n"
396 " %40 = OpLoad %u32 %39\n"
397 " %43 = OpAccessChain %_ptr_Uniform_uint32 %selector %int_0 %int_i %uint_1\n"
398 " %44 = OpLoad %u32 %43\n"
399 " %47 = OpAccessChain %_ptr_Uniform_uint32 %selector %int_0 %int_i %uint_2\n"
400 " %48 = OpLoad %u32 %47\n"
401 " %51 = OpAccessChain %_ptr_Uniform_uint32 %selector %int_0 %int_i %uint_3\n"
402 " %52 = OpLoad %u32 %51\n"
403 " %i0 = ${convert} ${idx_uint} %40\n"
404 " %i1 = ${convert} ${idx_uint} %44\n"
405 " %i2 = ${convert} ${idx_uint} %48\n"
406 " %i3 = ${convert} ${idx_uint} %52\n"
407 "%inputFirstElement = OpAccessChain %_ptr_buffer_InputStruct %dataInput %uint_0 %uint_0\n"
408 " %54 = ${accesschain}\n"
409 " %55 = OpLoad %f32 %54\n"
410 " %56 = OpAccessChain %_ptr_Uniform_float %dataOutput %int_0 %int_i\n"
415 " %67 = OpLoad %i32 %i\n"
416 " %69 = OpIAdd %i32 %67 %c_i32_1\n"
420 " %merge = OpLabel\n"
421 " OpReturnValue %param\n"
425 resources.inputs.push_back(Resource(BufferSp(new Float32Buffer(inputData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
426 resources.inputs.push_back(Resource(BufferSp(new Buffer<UVec4>(indexSelectorData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
430 fragments["capability"] = "OpCapability Int16\n";
431 features.push_back("shaderInt16");
432 specs["convert"] = "OpUConvert";
433 specs["intdecl"] = " %u16 = OpTypeInt 16 0\n"
434 " %i16 = OpTypeInt 16 1\n";
436 else if (idxSize == 64)
438 fragments["capability"] = "OpCapability Int64\n";
439 features.push_back("shaderInt64");
440 specs["convert"] = "OpUConvert";
441 specs["intdecl"] = " %u64 = OpTypeInt 64 0\n"
442 " %i64 = OpTypeInt 64 1\n";
444 specs["convert"] = "OpCopyObject";
447 specs["idx_uint"] = "%u" + de::toString(idxSize);
448 specs["idx_int"] = (sign ? "%i" : "%u") + de::toString(idxSize);
452 case CHAIN_OP_ACCESS_CHAIN:
453 specs["accesschain"] = "OpAccessChain %_ptr_Uniform_float %inputFirstElement %int_0 %i0 %i1 %i2 %i3\n";
454 specs["inputdecoration"] = "BufferBlock";
455 specs["inputstorageclass"] = "Uniform";
457 case CHAIN_OP_IN_BOUNDS_ACCESS_CHAIN:
458 specs["accesschain"] = "OpInBoundsAccessChain %_ptr_Uniform_float %inputFirstElement %int_0 %i0 %i1 %i2 %i3\n";
459 specs["inputdecoration"] = "BufferBlock";
460 specs["inputstorageclass"] = "Uniform";
463 DE_ASSERT(chainOpIdx == CHAIN_OP_PTR_ACCESS_CHAIN);
464 specs["accesschain"] = "OpPtrAccessChain %_ptr_StorageBuffer_float %inputFirstElement %uint_1 %int_0 %i0 %i1 %i2 %i3\n";
465 specs["inputdecoration"] = "Block";
466 specs["inputstorageclass"] = "StorageBuffer";
467 specs["ptr_buffer_float"] = "%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %f32";
468 fragments["capability"] += "OpCapability VariablePointersStorageBuffer";
469 fragments["extension"] = "OpExtension \"SPV_KHR_variable_pointers\"\nOpExtension \"SPV_KHR_storage_buffer_storage_class\"";
470 extensions.push_back ("VK_KHR_variable_pointers");
471 vulkanFeatures.extVariablePointers = EXTVARIABLEPOINTERSFEATURES_VARIABLE_POINTERS_STORAGEBUFFER;
476 outputData.reserve(numItems);
477 for (deUint32 numIdx = 0; numIdx < numItems; ++numIdx)
479 // Determine the selected output float for the selected indices.
480 const UVec4 vec = indexSelectorData[numIdx];
481 outputData.push_back(inputData[element * sizeof(InputData) / 4 + vec.x() * (32 * 4 * 4) + vec.y() * 4 * 4 + vec.z() * 4 + vec.w()]);
484 resources.outputs.push_back(Resource(BufferSp(new Float32Buffer(outputData)), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER));
486 fragments["pre_main"] = preMain.specialize(specs);
487 fragments["decoration"] = decoration.specialize(specs);
488 fragments["testfun"] = testFun.specialize(specs);
490 createTestsForAllStages(
491 testName.c_str(), defaultColors, defaultColors, fragments, noSpecConstants,
492 noPushConstants, resources, noInterfaces, extensions, features, vulkanFeatures, structGroup.get());
496 group->addChild(structGroup.release());
499 void addGraphicsOutputComponentIndexingTests (tcu::TestCaseGroup* testGroup)
501 RGBA defaultColors[4];
502 vector<string> noExtensions;
503 map<string, string> fragments = passthruFragments();
504 const deUint32 numItems = 4;
505 vector<deInt32> inputData;
506 vector<float> outputData;
507 const deInt32 pattern[] = { 2, 0, 1, 3 };
509 for (deUint32 itemIdx = 0; itemIdx < numItems; ++itemIdx)
512 output[pattern[itemIdx]] = 1.0f;
513 outputData.push_back(output.x());
514 outputData.push_back(output.y());
515 outputData.push_back(output.z());
516 outputData.push_back(output.w());
517 inputData.push_back(pattern[itemIdx]);
520 getDefaultColors(defaultColors);
522 fragments["pre_main"] =
523 " %a3u32 = OpTypeArray %u32 %c_i32_3\n"
524 " %ip_a3u32 = OpTypePointer Input %a3u32\n"
525 "%v4f32_u32_function = OpTypeFunction %v4f32 %u32\n";
527 fragments["interface_op_func"] =
528 "%interface_op_func = OpFunction %v4f32 None %v4f32_u32_function\n"
529 " %io_param1 = OpFunctionParameter %u32\n"
530 " %entry = OpLabel\n"
531 " %ret = OpCompositeConstruct %v4f32 %c_f32_0 %c_f32_0 %c_f32_0 %c_f32_0\n"
532 " OpReturnValue %ret\n"
535 fragments["post_interface_op_vert"] = fragments["post_interface_op_frag"] =
536 "%cpntPtr = OpAccessChain %op_f32 %IF_output %IF_input_val\n"
537 " OpStore %cpntPtr %c_f32_1\n";
539 fragments["post_interface_op_tessc"] =
540 "%cpntPtr0 = OpAccessChain %op_f32 %IF_output %c_i32_0 %IF_input_val0\n"
541 " OpStore %cpntPtr0 %c_f32_1\n"
542 "%cpntPtr1 = OpAccessChain %op_f32 %IF_output %c_i32_1 %IF_input_val1\n"
543 " OpStore %cpntPtr1 %c_f32_1\n"
544 "%cpntPtr2 = OpAccessChain %op_f32 %IF_output %c_i32_2 %IF_input_val2\n"
545 " OpStore %cpntPtr2 %c_f32_1\n";
547 fragments["post_interface_op_tesse"] = fragments["post_interface_op_geom"] =
548 "%cpntPtr = OpAccessChain %op_f32 %IF_output %IF_input_val0\n"
549 " OpStore %cpntPtr %c_f32_1\n";
551 fragments["input_type"] = "u32";
552 fragments["output_type"] = "v4f32";
554 GraphicsInterfaces interfaces;
556 interfaces.setInputOutput(std::make_pair(IFDataType(1, NUMBERTYPE_UINT32), BufferSp(new Int32Buffer(inputData))),
557 std::make_pair(IFDataType(4, NUMBERTYPE_FLOAT32), BufferSp(new Float32Buffer(outputData))));
559 createTestsForAllStages("component", defaultColors, defaultColors, fragments, interfaces, noExtensions, testGroup);
564 tcu::TestCaseGroup* createIndexingComputeGroup (tcu::TestContext& testCtx)
566 de::MovePtr<tcu::TestCaseGroup> indexingGroup (new tcu::TestCaseGroup(testCtx, "indexing", "Compute tests for data indexing."));
567 de::MovePtr<tcu::TestCaseGroup> inputGroup (new tcu::TestCaseGroup(testCtx, "input", "Tests for indexing input data."));
569 addComputeIndexingStructTests(inputGroup.get());
571 indexingGroup->addChild(inputGroup.release());
573 return indexingGroup.release();
576 tcu::TestCaseGroup* createIndexingGraphicsGroup (tcu::TestContext& testCtx)
578 de::MovePtr<tcu::TestCaseGroup> indexingGroup (new tcu::TestCaseGroup(testCtx, "indexing", "Graphics tests for data indexing."));
579 de::MovePtr<tcu::TestCaseGroup> inputGroup (new tcu::TestCaseGroup(testCtx, "input", "Tests for indexing input data."));
580 de::MovePtr<tcu::TestCaseGroup> outputGroup (new tcu::TestCaseGroup(testCtx, "output", "Tests for indexing output data."));
582 addGraphicsIndexingStructTests(inputGroup.get());
583 addGraphicsOutputComponentIndexingTests(outputGroup.get());
585 indexingGroup->addChild(inputGroup.release());
586 indexingGroup->addChild(outputGroup.release());
588 return indexingGroup.release();