1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2019 The Khronos Group 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 Ray Tracing Complex Control Flow tests
22 *//*--------------------------------------------------------------------*/
24 #include "vktRayTracingComplexControlFlowTests.hpp"
28 #include "vktTestCase.hpp"
29 #include "vkCmdUtil.hpp"
30 #include "vkObjUtil.hpp"
31 #include "vkBuilderUtil.hpp"
32 #include "vkBarrierUtil.hpp"
33 #include "vkBufferWithMemory.hpp"
34 #include "vkImageWithMemory.hpp"
35 #include "vkTypeUtil.hpp"
37 #include "vkRayTracingUtil.hpp"
39 #include "tcuTestLog.hpp"
41 #include "deRandom.hpp"
52 static const VkFlags ALL_RAY_TRACING_STAGES = VK_SHADER_STAGE_RAYGEN_BIT_KHR
53 | VK_SHADER_STAGE_ANY_HIT_BIT_KHR
54 | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR
55 | VK_SHADER_STAGE_MISS_BIT_KHR
56 | VK_SHADER_STAGE_INTERSECTION_BIT_KHR
57 | VK_SHADER_STAGE_CALLABLE_BIT_KHR;
60 static const deUint32 PUSH_CONSTANTS_COUNT = 6;
62 static const deUint32 DEFAULT_CLEAR_VALUE = 999999;
69 TEST_TYPE_LOOP_DOUBLE_CALL,
70 TEST_TYPE_LOOP_DOUBLE_CALL_SPARSE,
71 TEST_TYPE_NESTED_LOOP,
72 TEST_TYPE_NESTED_LOOP_BEFORE,
73 TEST_TYPE_NESTED_LOOP_AFTER,
74 TEST_TYPE_FUNCTION_CALL,
75 TEST_TYPE_NESTED_FUNCTION_CALL,
80 TEST_OP_EXECUTE_CALLABLE = 0,
82 TEST_OP_REPORT_INTERSECTION,
88 RAYGEN_GROUP = FIRST_GROUP,
98 VkShaderStageFlagBits stage;
113 deUint32 getShaderGroupSize (const InstanceInterface& vki,
114 const VkPhysicalDevice physicalDevice)
116 de::MovePtr<RayTracingProperties> rayTracingPropertiesKHR;
118 rayTracingPropertiesKHR = makeRayTracingProperties(vki, physicalDevice);
119 return rayTracingPropertiesKHR->getShaderGroupHandleSize();
122 deUint32 getShaderGroupBaseAlignment (const InstanceInterface& vki,
123 const VkPhysicalDevice physicalDevice)
125 de::MovePtr<RayTracingProperties> rayTracingPropertiesKHR;
127 rayTracingPropertiesKHR = makeRayTracingProperties(vki, physicalDevice);
128 return rayTracingPropertiesKHR->getShaderGroupBaseAlignment();
131 VkImageCreateInfo makeImageCreateInfo (deUint32 width, deUint32 height, deUint32 depth, VkFormat format)
133 const VkImageUsageFlags usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
134 const VkImageCreateInfo imageCreateInfo =
136 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
137 DE_NULL, // const void* pNext;
138 (VkImageCreateFlags)0u, // VkImageCreateFlags flags;
139 VK_IMAGE_TYPE_3D, // VkImageType imageType;
140 format, // VkFormat format;
141 makeExtent3D(width, height, depth), // VkExtent3D extent;
142 1u, // deUint32 mipLevels;
143 1u, // deUint32 arrayLayers;
144 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
145 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
146 usage, // VkImageUsageFlags usage;
147 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
148 0u, // deUint32 queueFamilyIndexCount;
149 DE_NULL, // const deUint32* pQueueFamilyIndices;
150 VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout initialLayout;
153 return imageCreateInfo;
156 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
157 const VkDevice device,
158 const VkDescriptorSetLayout descriptorSetLayout,
159 const deUint32 pushConstantsSize)
161 const VkDescriptorSetLayout* descriptorSetLayoutPtr = (descriptorSetLayout == DE_NULL) ? DE_NULL : &descriptorSetLayout;
162 const deUint32 setLayoutCount = (descriptorSetLayout == DE_NULL) ? 0u : 1u;
163 const VkPushConstantRange pushConstantRange =
165 ALL_RAY_TRACING_STAGES, // VkShaderStageFlags stageFlags;
166 0u, // deUint32 offset;
167 pushConstantsSize, // deUint32 size;
169 const VkPushConstantRange* pPushConstantRanges = (pushConstantsSize == 0) ? DE_NULL : &pushConstantRange;
170 const deUint32 pushConstantRangeCount = (pushConstantsSize == 0) ? 0 : 1u;
171 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
173 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
174 DE_NULL, // const void* pNext;
175 0u, // VkPipelineLayoutCreateFlags flags;
176 setLayoutCount, // deUint32 setLayoutCount;
177 descriptorSetLayoutPtr, // const VkDescriptorSetLayout* pSetLayouts;
178 pushConstantRangeCount, // deUint32 pushConstantRangeCount;
179 pPushConstantRanges, // const VkPushConstantRange* pPushConstantRanges;
182 return createPipelineLayout(vk, device, &pipelineLayoutParams);
185 VkBuffer getVkBuffer (const de::MovePtr<BufferWithMemory>& buffer)
187 VkBuffer result = (buffer.get() == DE_NULL) ? DE_NULL : buffer->get();
192 VkStridedDeviceAddressRegionKHR makeStridedDeviceAddressRegion (const DeviceInterface& vkd, const VkDevice device, VkBuffer buffer, deUint32 stride, deUint32 count)
194 if (buffer == DE_NULL)
196 return makeStridedDeviceAddressRegionKHR(0, 0, 0);
200 return makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, buffer, 0), stride, stride * count);
204 // Function replacing all occurrences of substring with string passed in last parameter.
205 static inline std::string replace(const std::string& str, const std::string& from, const std::string& to)
207 std::string result(str);
209 size_t start_pos = 0;
210 while((start_pos = result.find(from, start_pos)) != std::string::npos)
212 result.replace(start_pos, from.length(), to);
213 start_pos += to.length();
220 class RayTracingComplexControlFlowInstance : public TestInstance
223 RayTracingComplexControlFlowInstance (Context& context, const CaseDef& data);
224 ~RayTracingComplexControlFlowInstance (void);
225 tcu::TestStatus iterate (void);
228 void calcShaderGroup (deUint32& shaderGroupCounter,
229 const VkShaderStageFlags shaders1,
230 const VkShaderStageFlags shaders2,
231 const VkShaderStageFlags shaderStageFlags,
232 deUint32& shaderGroup,
233 deUint32& shaderGroupCount) const;
234 void checkSupportInInstance (void) const;
235 PushConstants getPushConstants (void) const;
236 std::vector<deUint32> getExpectedValues (void) const;
237 de::MovePtr<BufferWithMemory> runTest (void);
238 Move<VkPipeline> makePipeline (de::MovePtr<RayTracingPipeline>& rayTracingPipeline,
239 VkPipelineLayout pipelineLayout);
240 de::MovePtr<BufferWithMemory> createShaderBindingTable (const InstanceInterface& vki,
241 const DeviceInterface& vkd,
242 const VkDevice device,
243 const VkPhysicalDevice physicalDevice,
244 const VkPipeline pipeline,
245 Allocator& allocator,
246 de::MovePtr<RayTracingPipeline>& rayTracingPipeline,
247 const deUint32 group,
248 const deUint32 groupCount = 1u);
249 de::MovePtr<TopLevelAccelerationStructure> initTopAccelerationStructure (VkCommandBuffer cmdBuffer,
250 vector<de::SharedPtr<BottomLevelAccelerationStructure> >& bottomLevelAccelerationStructures);
251 vector<de::SharedPtr<BottomLevelAccelerationStructure> > initBottomAccelerationStructures (VkCommandBuffer cmdBuffer);
252 de::MovePtr<BottomLevelAccelerationStructure> initBottomAccelerationStructure (VkCommandBuffer cmdBuffer,
253 tcu::UVec2& startPos);
257 VkShaderStageFlags m_shaders;
258 VkShaderStageFlags m_shaders2;
259 deUint32 m_raygenShaderGroup;
260 deUint32 m_missShaderGroup;
261 deUint32 m_hitShaderGroup;
262 deUint32 m_callableShaderGroup;
263 deUint32 m_raygenShaderGroupCount;
264 deUint32 m_missShaderGroupCount;
265 deUint32 m_hitShaderGroupCount;
266 deUint32 m_callableShaderGroupCount;
267 deUint32 m_shaderGroupCount;
269 PushConstants m_pushConstants;
272 RayTracingComplexControlFlowInstance::RayTracingComplexControlFlowInstance (Context& context, const CaseDef& data)
273 : vkt::TestInstance (context)
277 , m_raygenShaderGroup (~0u)
278 , m_missShaderGroup (~0u)
279 , m_hitShaderGroup (~0u)
280 , m_callableShaderGroup (~0u)
281 , m_raygenShaderGroupCount (0)
282 , m_missShaderGroupCount (0)
283 , m_hitShaderGroupCount (0)
284 , m_callableShaderGroupCount (0)
285 , m_shaderGroupCount (0)
287 , m_pushConstants (getPushConstants())
289 const VkShaderStageFlags hitStages = VK_SHADER_STAGE_ANY_HIT_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | VK_SHADER_STAGE_INTERSECTION_BIT_KHR;
290 BinaryCollection& collection = m_context.getBinaryCollection();
291 deUint32 shaderCount = 0;
293 if (collection.contains("rgen")) m_shaders |= VK_SHADER_STAGE_RAYGEN_BIT_KHR;
294 if (collection.contains("ahit")) m_shaders |= VK_SHADER_STAGE_ANY_HIT_BIT_KHR;
295 if (collection.contains("chit")) m_shaders |= VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;
296 if (collection.contains("miss")) m_shaders |= VK_SHADER_STAGE_MISS_BIT_KHR;
297 if (collection.contains("sect")) m_shaders |= VK_SHADER_STAGE_INTERSECTION_BIT_KHR;
298 if (collection.contains("call")) m_shaders |= VK_SHADER_STAGE_CALLABLE_BIT_KHR;
300 if (collection.contains("ahit2")) m_shaders2 |= VK_SHADER_STAGE_ANY_HIT_BIT_KHR;
301 if (collection.contains("chit2")) m_shaders2 |= VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;
302 if (collection.contains("miss2")) m_shaders2 |= VK_SHADER_STAGE_MISS_BIT_KHR;
303 if (collection.contains("sect2")) m_shaders2 |= VK_SHADER_STAGE_INTERSECTION_BIT_KHR;
305 if (collection.contains("cal0")) m_shaders2 |= VK_SHADER_STAGE_CALLABLE_BIT_KHR;
307 for (BinaryCollection::Iterator it = collection.begin(); it != collection.end(); ++it)
310 if (shaderCount != (deUint32)dePop32(m_shaders) + (deUint32)dePop32(m_shaders2))
311 TCU_THROW(InternalError, "Unused shaders detected in the collection");
313 calcShaderGroup(m_shaderGroupCount, m_shaders, m_shaders2, VK_SHADER_STAGE_RAYGEN_BIT_KHR, m_raygenShaderGroup, m_raygenShaderGroupCount);
314 calcShaderGroup(m_shaderGroupCount, m_shaders, m_shaders2, VK_SHADER_STAGE_MISS_BIT_KHR, m_missShaderGroup, m_missShaderGroupCount);
315 calcShaderGroup(m_shaderGroupCount, m_shaders, m_shaders2, hitStages, m_hitShaderGroup, m_hitShaderGroupCount);
316 calcShaderGroup(m_shaderGroupCount, m_shaders, m_shaders2, VK_SHADER_STAGE_CALLABLE_BIT_KHR, m_callableShaderGroup, m_callableShaderGroupCount);
319 RayTracingComplexControlFlowInstance::~RayTracingComplexControlFlowInstance (void)
323 void RayTracingComplexControlFlowInstance::calcShaderGroup (deUint32& shaderGroupCounter,
324 const VkShaderStageFlags shaders1,
325 const VkShaderStageFlags shaders2,
326 const VkShaderStageFlags shaderStageFlags,
327 deUint32& shaderGroup,
328 deUint32& shaderGroupCount) const
330 const deUint32 shader1Count = ((shaders1 & shaderStageFlags) != 0) ? 1 : 0;
331 const deUint32 shader2Count = ((shaders2 & shaderStageFlags) != 0) ? 1 : 0;
333 shaderGroupCount = shader1Count + shader2Count;
335 if (shaderGroupCount != 0)
337 shaderGroup = shaderGroupCounter;
338 shaderGroupCounter += shaderGroupCount;
342 Move<VkPipeline> RayTracingComplexControlFlowInstance::makePipeline (de::MovePtr<RayTracingPipeline>& rayTracingPipeline,
343 VkPipelineLayout pipelineLayout)
345 const DeviceInterface& vkd = m_context.getDeviceInterface();
346 const VkDevice device = m_context.getDevice();
347 vk::BinaryCollection& collection = m_context.getBinaryCollection();
349 if (0 != (m_shaders & VK_SHADER_STAGE_RAYGEN_BIT_KHR)) rayTracingPipeline->addShader(VK_SHADER_STAGE_RAYGEN_BIT_KHR , createShaderModule(vkd, device, collection.get("rgen"), 0), m_raygenShaderGroup);
350 if (0 != (m_shaders & VK_SHADER_STAGE_ANY_HIT_BIT_KHR)) rayTracingPipeline->addShader(VK_SHADER_STAGE_ANY_HIT_BIT_KHR , createShaderModule(vkd, device, collection.get("ahit"), 0), m_hitShaderGroup);
351 if (0 != (m_shaders & VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR)) rayTracingPipeline->addShader(VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR , createShaderModule(vkd, device, collection.get("chit"), 0), m_hitShaderGroup);
352 if (0 != (m_shaders & VK_SHADER_STAGE_MISS_BIT_KHR)) rayTracingPipeline->addShader(VK_SHADER_STAGE_MISS_BIT_KHR , createShaderModule(vkd, device, collection.get("miss"), 0), m_missShaderGroup);
353 if (0 != (m_shaders & VK_SHADER_STAGE_INTERSECTION_BIT_KHR)) rayTracingPipeline->addShader(VK_SHADER_STAGE_INTERSECTION_BIT_KHR , createShaderModule(vkd, device, collection.get("sect"), 0), m_hitShaderGroup);
354 if (0 != (m_shaders & VK_SHADER_STAGE_CALLABLE_BIT_KHR)) rayTracingPipeline->addShader(VK_SHADER_STAGE_CALLABLE_BIT_KHR , createShaderModule(vkd, device, collection.get("call"), 0), m_callableShaderGroup + 1);
356 if (0 != (m_shaders2 & VK_SHADER_STAGE_CALLABLE_BIT_KHR)) rayTracingPipeline->addShader(VK_SHADER_STAGE_CALLABLE_BIT_KHR , createShaderModule(vkd, device, collection.get("cal0"), 0), m_callableShaderGroup);
357 if (0 != (m_shaders2 & VK_SHADER_STAGE_ANY_HIT_BIT_KHR)) rayTracingPipeline->addShader(VK_SHADER_STAGE_ANY_HIT_BIT_KHR , createShaderModule(vkd, device, collection.get("ahit2"), 0), m_hitShaderGroup + 1);
358 if (0 != (m_shaders2 & VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR)) rayTracingPipeline->addShader(VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR , createShaderModule(vkd, device, collection.get("chit2"), 0), m_hitShaderGroup + 1);
359 if (0 != (m_shaders2 & VK_SHADER_STAGE_MISS_BIT_KHR)) rayTracingPipeline->addShader(VK_SHADER_STAGE_MISS_BIT_KHR , createShaderModule(vkd, device, collection.get("miss2"), 0), m_missShaderGroup + 1);
360 if (0 != (m_shaders2 & VK_SHADER_STAGE_INTERSECTION_BIT_KHR)) rayTracingPipeline->addShader(VK_SHADER_STAGE_INTERSECTION_BIT_KHR , createShaderModule(vkd, device, collection.get("sect2"), 0), m_hitShaderGroup + 1);
362 Move<VkPipeline> pipeline = rayTracingPipeline->createPipeline(vkd, device, pipelineLayout);
367 de::MovePtr<BufferWithMemory> RayTracingComplexControlFlowInstance::createShaderBindingTable (const InstanceInterface& vki,
368 const DeviceInterface& vkd,
369 const VkDevice device,
370 const VkPhysicalDevice physicalDevice,
371 const VkPipeline pipeline,
372 Allocator& allocator,
373 de::MovePtr<RayTracingPipeline>& rayTracingPipeline,
374 const deUint32 group,
375 const deUint32 groupCount)
377 de::MovePtr<BufferWithMemory> shaderBindingTable;
379 if (group < m_shaderGroupCount)
381 const deUint32 shaderGroupHandleSize = getShaderGroupSize(vki, physicalDevice);
382 const deUint32 shaderGroupBaseAlignment = getShaderGroupBaseAlignment(vki, physicalDevice);
384 shaderBindingTable = rayTracingPipeline->createShaderBindingTable(vkd, device, pipeline, allocator, shaderGroupHandleSize, shaderGroupBaseAlignment, group, groupCount);
387 return shaderBindingTable;
391 de::MovePtr<TopLevelAccelerationStructure> RayTracingComplexControlFlowInstance::initTopAccelerationStructure (VkCommandBuffer cmdBuffer,
392 vector<de::SharedPtr<BottomLevelAccelerationStructure> >& bottomLevelAccelerationStructures)
394 const DeviceInterface& vkd = m_context.getDeviceInterface();
395 const VkDevice device = m_context.getDevice();
396 Allocator& allocator = m_context.getDefaultAllocator();
397 de::MovePtr<TopLevelAccelerationStructure> result = makeTopLevelAccelerationStructure();
399 result->setInstanceCount(bottomLevelAccelerationStructures.size());
401 for (size_t structNdx = 0; structNdx < bottomLevelAccelerationStructures.size(); ++structNdx)
402 result->addInstance(bottomLevelAccelerationStructures[structNdx]);
404 result->createAndBuild(vkd, device, cmdBuffer, allocator);
409 de::MovePtr<BottomLevelAccelerationStructure> RayTracingComplexControlFlowInstance::initBottomAccelerationStructure (VkCommandBuffer cmdBuffer,
410 tcu::UVec2& startPos)
412 const DeviceInterface& vkd = m_context.getDeviceInterface();
413 const VkDevice device = m_context.getDevice();
414 Allocator& allocator = m_context.getDefaultAllocator();
415 de::MovePtr<BottomLevelAccelerationStructure> result = makeBottomLevelAccelerationStructure();
416 const float z = (m_data.stage == VK_SHADER_STAGE_MISS_BIT_KHR) ? +1.0f : -1.0f;
417 std::vector<tcu::Vec3> geometryData;
421 result->setGeometryCount(1);
422 geometryData.push_back(tcu::Vec3(0.0f, 0.0f, z));
423 geometryData.push_back(tcu::Vec3(1.0f, 1.0f, z));
424 result->addGeometry(geometryData, false);
425 result->createAndBuild(vkd, device, cmdBuffer, allocator);
430 vector<de::SharedPtr<BottomLevelAccelerationStructure> > RayTracingComplexControlFlowInstance::initBottomAccelerationStructures (VkCommandBuffer cmdBuffer)
433 vector<de::SharedPtr<BottomLevelAccelerationStructure> > result;
434 de::MovePtr<BottomLevelAccelerationStructure> bottomLevelAccelerationStructure = initBottomAccelerationStructure(cmdBuffer, startPos);
436 result.push_back(de::SharedPtr<BottomLevelAccelerationStructure>(bottomLevelAccelerationStructure.release()));
441 PushConstants RayTracingComplexControlFlowInstance::getPushConstants (void) const
443 const deUint32 hitOfs = 1;
444 const deUint32 miss = 1;
445 PushConstants result;
447 switch (m_data.testType)
451 result = { 32 | 8 | 1, 10000, 0x0F, 0xF0, hitOfs, miss };
457 result = { 8, 10000, 0x0F, 100000, hitOfs, miss };
461 case TEST_TYPE_SWITCH:
463 result = { 3, 10000, 0x07, 100000, hitOfs, miss };
467 case TEST_TYPE_LOOP_DOUBLE_CALL:
469 result = { 7, 10000, 0x0F, 0xF0, hitOfs, miss };
473 case TEST_TYPE_LOOP_DOUBLE_CALL_SPARSE:
475 result = { 16, 5, 0x0F, 0xF0, hitOfs, miss };
479 case TEST_TYPE_NESTED_LOOP:
481 result = { 8, 5, 0x0F, 0x09, hitOfs, miss };
485 case TEST_TYPE_NESTED_LOOP_BEFORE:
487 result = { 9, 16, 0x0F, 10, hitOfs, miss };
491 case TEST_TYPE_NESTED_LOOP_AFTER:
493 result = { 9, 16, 0x0F, 10, hitOfs, miss };
497 case TEST_TYPE_FUNCTION_CALL:
499 result = { 0xFFB, 16, 10, 100000, hitOfs, miss };
503 case TEST_TYPE_NESTED_FUNCTION_CALL:
505 result = { 0xFFB, 16, 10, 100000, hitOfs, miss };
511 TCU_THROW(InternalError, "Unknown testType");
517 de::MovePtr<BufferWithMemory> RayTracingComplexControlFlowInstance::runTest (void)
519 const InstanceInterface& vki = m_context.getInstanceInterface();
520 const DeviceInterface& vkd = m_context.getDeviceInterface();
521 const VkDevice device = m_context.getDevice();
522 const VkPhysicalDevice physicalDevice = m_context.getPhysicalDevice();
523 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
524 const VkQueue queue = m_context.getUniversalQueue();
525 Allocator& allocator = m_context.getDefaultAllocator();
526 const VkFormat format = VK_FORMAT_R32_UINT;
527 const deUint32 pushConstants[] = { m_pushConstants.a, m_pushConstants.b, m_pushConstants.c, m_pushConstants.d, m_pushConstants.hitOfs, m_pushConstants.miss };
528 const deUint32 pushConstantsSize = sizeof(pushConstants);
529 const deUint32 pixelCount = m_data.width * m_data.height * m_depth;
530 const deUint32 shaderGroupHandleSize = getShaderGroupSize(vki, physicalDevice);
532 const Move<VkDescriptorSetLayout> descriptorSetLayout = DescriptorSetLayoutBuilder()
533 .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, ALL_RAY_TRACING_STAGES)
534 .addSingleBinding(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, ALL_RAY_TRACING_STAGES)
536 const Move<VkDescriptorPool> descriptorPool = DescriptorPoolBuilder()
537 .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE)
538 .addType(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR)
539 .build(vkd, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u);
540 const Move<VkDescriptorSet> descriptorSet = makeDescriptorSet(vkd, device, *descriptorPool, *descriptorSetLayout);
541 const Move<VkPipelineLayout> pipelineLayout = makePipelineLayout(vkd, device, descriptorSetLayout.get(), pushConstantsSize);
542 const Move<VkCommandPool> cmdPool = createCommandPool(vkd, device, 0, queueFamilyIndex);
543 const Move<VkCommandBuffer> cmdBuffer = allocateCommandBuffer(vkd, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
545 de::MovePtr<RayTracingPipeline> rayTracingPipeline = de::newMovePtr<RayTracingPipeline>();
546 const Move<VkPipeline> pipeline = makePipeline(rayTracingPipeline, *pipelineLayout);
547 const de::MovePtr<BufferWithMemory> raygenShaderBindingTable = createShaderBindingTable(vki, vkd, device, physicalDevice, *pipeline, allocator, rayTracingPipeline, m_raygenShaderGroup, m_raygenShaderGroupCount);
548 const de::MovePtr<BufferWithMemory> missShaderBindingTable = createShaderBindingTable(vki, vkd, device, physicalDevice, *pipeline, allocator, rayTracingPipeline, m_missShaderGroup, m_missShaderGroupCount);
549 const de::MovePtr<BufferWithMemory> hitShaderBindingTable = createShaderBindingTable(vki, vkd, device, physicalDevice, *pipeline, allocator, rayTracingPipeline, m_hitShaderGroup, m_hitShaderGroupCount);
550 const de::MovePtr<BufferWithMemory> callableShaderBindingTable = createShaderBindingTable(vki, vkd, device, physicalDevice, *pipeline, allocator, rayTracingPipeline, m_callableShaderGroup, m_callableShaderGroupCount);
552 const VkStridedDeviceAddressRegionKHR raygenShaderBindingTableRegion = makeStridedDeviceAddressRegion(vkd, device, getVkBuffer(raygenShaderBindingTable), shaderGroupHandleSize, m_raygenShaderGroupCount);
553 const VkStridedDeviceAddressRegionKHR missShaderBindingTableRegion = makeStridedDeviceAddressRegion(vkd, device, getVkBuffer(missShaderBindingTable), shaderGroupHandleSize, m_missShaderGroupCount);
554 const VkStridedDeviceAddressRegionKHR hitShaderBindingTableRegion = makeStridedDeviceAddressRegion(vkd, device, getVkBuffer(hitShaderBindingTable), shaderGroupHandleSize, m_hitShaderGroupCount);
555 const VkStridedDeviceAddressRegionKHR callableShaderBindingTableRegion = makeStridedDeviceAddressRegion(vkd, device, getVkBuffer(callableShaderBindingTable), shaderGroupHandleSize, m_callableShaderGroupCount);
557 const VkImageCreateInfo imageCreateInfo = makeImageCreateInfo(m_data.width, m_data.height, m_depth, format);
558 const VkImageSubresourceRange imageSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0, 1u);
559 const de::MovePtr<ImageWithMemory> image = de::MovePtr<ImageWithMemory>(new ImageWithMemory(vkd, device, allocator, imageCreateInfo, MemoryRequirement::Any));
560 const Move<VkImageView> imageView = makeImageView(vkd, device, **image, VK_IMAGE_VIEW_TYPE_3D, format, imageSubresourceRange);
562 const VkBufferCreateInfo bufferCreateInfo = makeBufferCreateInfo(pixelCount*sizeof(deUint32), VK_BUFFER_USAGE_TRANSFER_DST_BIT);
563 const VkImageSubresourceLayers bufferImageSubresourceLayers = makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u);
564 const VkBufferImageCopy bufferImageRegion = makeBufferImageCopy(makeExtent3D(m_data.width, m_data.height, m_depth), bufferImageSubresourceLayers);
565 de::MovePtr<BufferWithMemory> buffer = de::MovePtr<BufferWithMemory>(new BufferWithMemory(vkd, device, allocator, bufferCreateInfo, MemoryRequirement::HostVisible));
567 const VkDescriptorImageInfo descriptorImageInfo = makeDescriptorImageInfo(DE_NULL, *imageView, VK_IMAGE_LAYOUT_GENERAL);
569 const VkImageMemoryBarrier preImageBarrier = makeImageMemoryBarrier(0u, VK_ACCESS_TRANSFER_WRITE_BIT,
570 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
571 **image, imageSubresourceRange);
572 const VkImageMemoryBarrier postImageBarrier = makeImageMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
573 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
574 **image, imageSubresourceRange);
575 const VkMemoryBarrier preTraceMemoryBarrier = makeMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT);
576 const VkMemoryBarrier postTraceMemoryBarrier = makeMemoryBarrier(VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT);
577 const VkMemoryBarrier postCopyMemoryBarrier = makeMemoryBarrier(VK_ACCESS_TRANSFER_READ_BIT, 0);
578 const VkClearValue clearValue = makeClearValueColorU32(DEFAULT_CLEAR_VALUE, 0u, 0u, 255u);
580 vector<de::SharedPtr<BottomLevelAccelerationStructure> > bottomLevelAccelerationStructures;
581 de::MovePtr<TopLevelAccelerationStructure> topLevelAccelerationStructure;
583 DE_ASSERT(DE_LENGTH_OF_ARRAY(pushConstants) == PUSH_CONSTANTS_COUNT);
585 beginCommandBuffer(vkd, *cmdBuffer, 0u);
587 vkd.cmdPushConstants(*cmdBuffer, *pipelineLayout, ALL_RAY_TRACING_STAGES, 0, pushConstantsSize, &m_pushConstants);
589 cmdPipelineImageMemoryBarrier(vkd, *cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, &preImageBarrier);
590 vkd.cmdClearColorImage(*cmdBuffer, **image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clearValue.color, 1, &imageSubresourceRange);
591 cmdPipelineImageMemoryBarrier(vkd, *cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, ALL_RAY_TRACING_STAGES, &postImageBarrier);
593 bottomLevelAccelerationStructures = initBottomAccelerationStructures(*cmdBuffer);
594 topLevelAccelerationStructure = initTopAccelerationStructure(*cmdBuffer, bottomLevelAccelerationStructures);
596 cmdPipelineMemoryBarrier(vkd, *cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, ALL_RAY_TRACING_STAGES, &preTraceMemoryBarrier);
598 const TopLevelAccelerationStructure* topLevelAccelerationStructurePtr = topLevelAccelerationStructure.get();
599 VkWriteDescriptorSetAccelerationStructureKHR accelerationStructureWriteDescriptorSet =
601 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR, // VkStructureType sType;
602 DE_NULL, // const void* pNext;
603 1u, // deUint32 accelerationStructureCount;
604 topLevelAccelerationStructurePtr->getPtr(), // const VkAccelerationStructureKHR* pAccelerationStructures;
607 DescriptorSetUpdateBuilder()
608 .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorImageInfo)
609 .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, &accelerationStructureWriteDescriptorSet)
610 .update(vkd, device);
612 vkd.cmdBindDescriptorSets(*cmdBuffer, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, *pipelineLayout, 0, 1, &descriptorSet.get(), 0, DE_NULL);
614 vkd.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, *pipeline);
618 &raygenShaderBindingTableRegion,
619 &missShaderBindingTableRegion,
620 &hitShaderBindingTableRegion,
621 &callableShaderBindingTableRegion,
622 m_data.width, m_data.height, 1);
624 cmdPipelineMemoryBarrier(vkd, *cmdBuffer, ALL_RAY_TRACING_STAGES, VK_PIPELINE_STAGE_TRANSFER_BIT, &postTraceMemoryBarrier);
626 vkd.cmdCopyImageToBuffer(*cmdBuffer, **image, VK_IMAGE_LAYOUT_GENERAL, **buffer, 1u, &bufferImageRegion);
628 cmdPipelineMemoryBarrier(vkd, *cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, &postCopyMemoryBarrier);
630 endCommandBuffer(vkd, *cmdBuffer);
632 submitCommandsAndWait(vkd, device, queue, cmdBuffer.get());
634 invalidateMappedMemoryRange(vkd, device, buffer->getAllocation().getMemory(), buffer->getAllocation().getOffset(), pixelCount * sizeof(deUint32));
639 void RayTracingComplexControlFlowInstance::checkSupportInInstance (void) const
643 std::vector<deUint32> RayTracingComplexControlFlowInstance::getExpectedValues (void) const
645 const deUint32 plainSize = m_data.width * m_data.height;
646 const deUint32 plain8Ofs = 8 * plainSize;
647 const struct PushConstants& p = m_pushConstants;
648 const deUint32 pushConstants[] = { 0, m_pushConstants.a, m_pushConstants.b, m_pushConstants.c, m_pushConstants.d, m_pushConstants.hitOfs, m_pushConstants.miss };
649 const deUint32 resultSize = plainSize * m_depth;
650 const bool fixed = m_data.testOp == TEST_OP_REPORT_INTERSECTION;
651 std::vector<deUint32> result (resultSize, DEFAULT_CLEAR_VALUE);
657 switch (m_data.testType)
661 for (deUint32 id = 0; id < plainSize; ++id)
670 result[plain8Ofs + id] = v0;
680 result[plain8Ofs + id] = v1;
684 result[plain8Ofs + id] = v0;
687 result[id] = v0 + v1 + v2 + v3;
694 for (deUint32 id = 0; id < plainSize; ++id)
700 for (deUint32 n = 0; n < p.a; n++)
704 result[((n % 8) + 8) * plainSize + id] = v0;
707 result[id] += v0 + v1 + v3;
713 case TEST_TYPE_SWITCH:
715 for (deUint32 id = 0; id < plainSize; ++id)
719 case 0: { v1 = v2 = v3 = p.b; v0 = p.c & id; break; }
720 case 1: { v0 = v2 = v3 = p.b; v1 = p.c & id; break; }
721 case 2: { v0 = v1 = v3 = p.b; v2 = p.c & id; break; }
722 case 3: { v0 = v1 = v2 = p.b; v3 = p.c & id; break; }
723 default: { v0 = v1 = v2 = v3 = 0; break; }
727 result[plain8Ofs + id] = p.c & id;
729 result[plain8Ofs + id] = v0;
731 result[id] = v0 + v1 + v2 + v3;
733 if (!fixed) result[id]++;
738 case TEST_TYPE_LOOP_DOUBLE_CALL:
740 for (deUint32 id = 0; id < plainSize; ++id)
746 for (deUint32 x = 0; x < p.a; x++)
749 v1 = (p.d & id) + x + 1;
751 result[(((2 * x + 0) % 8) + 8) * plainSize + id] = v0;
756 result[(((2 * x + 1) % 8) + 8) * plainSize + id] = v1;
760 result[id] += v0 + v1 + v3;
766 case TEST_TYPE_LOOP_DOUBLE_CALL_SPARSE:
768 for (deUint32 id = 0; id < plainSize; ++id)
774 for (deUint32 x = 0; x < p.a; x++)
779 v1 = (p.d & id) + x + 1;
781 result[(((2 * x + 0) % 8) + 8) * plainSize + id] = v0;
786 result[(((2 * x + 1) % 8) + 8) * plainSize + id] = v1;
790 result[id] += v0 + v1 + v3;
797 case TEST_TYPE_NESTED_LOOP:
799 for (deUint32 id = 0; id < plainSize; ++id)
805 for (deUint32 y = 0; y < p.a; y++)
806 for (deUint32 x = 0; x < p.a; x++)
808 const deUint32 n = x + y * p.a;
814 result[((n % 8) + 8) * plainSize + id] = v0;
817 result[id] += v0 + v1 + v3;
824 case TEST_TYPE_NESTED_LOOP_BEFORE:
826 for (deUint32 id = 0; id < plainSize; ++id)
830 for (deUint32 y = 0; y < p.d; y++)
831 for (deUint32 x = 0; x < p.d; x++)
833 if (((x + y * p.a) & p.b) != 0)
834 result[id] += (x + y);
839 for (deUint32 x = 0; x < p.b; x++)
845 result[((x % 8) + 8) * plainSize + id] = v0;
848 result[id] += v0 + v1 + v3;
855 case TEST_TYPE_NESTED_LOOP_AFTER:
857 for (deUint32 id = 0; id < plainSize; ++id)
863 for (deUint32 x = 0; x < p.b; x++)
869 result[((x % 8) + 8) * plainSize + id] = v0;
872 result[id] += v0 + v1 + v3;
876 for (deUint32 y = 0; y < p.d; y++)
877 for (deUint32 x = 0; x < p.d; x++)
879 if (((x + y * p.a) & p.b) != 0)
880 result[id] += (x + y);
886 case TEST_TYPE_FUNCTION_CALL:
890 for (deUint32 id = 0; id < plainSize; ++id)
898 for (i = 0; i < DE_LENGTH_OF_ARRAY(a); i++)
901 result[plain8Ofs + id] = v0;
904 for (i = 0; i < DE_LENGTH_OF_ARRAY(a); i++)
907 result[id] = (r + i) + v0 + v1 + v3;
912 case TEST_TYPE_NESTED_FUNCTION_CALL:
917 for (deUint32 id = 0; id < plainSize; ++id)
927 for (j = 0; j < DE_LENGTH_OF_ARRAY(b); j++)
932 for (i = 0; i < DE_LENGTH_OF_ARRAY(a); i++)
935 result[plain8Ofs + id] = v0;
938 for (i = 0; i < DE_LENGTH_OF_ARRAY(a); i++)
941 for (j = 0; j < DE_LENGTH_OF_ARRAY(b); j++)
944 result[id] = (r + i) + (t + j) + v0 + v1 + v3;
951 TCU_THROW(InternalError, "Unknown testType");
955 const deUint32 startOfs = 7 * plainSize;
957 for (deUint32 n = 0; n < plainSize; ++n)
958 result[startOfs + n] = n;
961 for (deUint32 z = 1; z < DE_LENGTH_OF_ARRAY(pushConstants); ++z)
963 const deUint32 startOfs = z * plainSize;
964 const deUint32 pushConstant = pushConstants[z];
966 for (deUint32 n = 0; n < plainSize; ++n)
967 result[startOfs + n] = pushConstant;
973 tcu::TestStatus RayTracingComplexControlFlowInstance::iterate (void)
975 checkSupportInInstance();
977 const de::MovePtr<BufferWithMemory> buffer = runTest();
978 const deUint32* bufferPtr = (deUint32*)buffer->getAllocation().getHostPtr();
979 const vector<deUint32> expected = getExpectedValues();
980 tcu::TestLog& log = m_context.getTestContext().getLog();
981 deUint32 failures = 0;
984 for (deUint32 z = 0; z < m_depth; ++z)
985 for (deUint32 y = 0; y < m_data.height; ++y)
986 for (deUint32 x = 0; x < m_data.width; ++x)
988 if (bufferPtr[pos] != expected[pos])
998 std::stringstream css;
1000 for (deUint32 z = 0; z < m_depth; ++z)
1002 css << "z=" << z << std::endl;
1004 for (deUint32 y = 0; y < m_data.height; ++y)
1006 for (deUint32 x = 0; x < m_data.width; ++x)
1007 css << std::setw(6) << bufferPtr[pos0++] << ' ';
1011 for (deUint32 x = 0; x < m_data.width; ++x)
1012 css << std::setw(6) << expected[pos1++] << ' ';
1020 log << tcu::TestLog::Message << css.str() << tcu::TestLog::EndMessage;
1024 return tcu::TestStatus::pass("Pass");
1026 return tcu::TestStatus::fail("failures=" + de::toString(failures));
1029 class ComplexControlFlowTestCase : public TestCase
1032 ComplexControlFlowTestCase (tcu::TestContext& context, const char* name, const char* desc, const CaseDef data);
1033 ~ComplexControlFlowTestCase (void);
1035 virtual void initPrograms (SourceCollections& programCollection) const;
1036 virtual TestInstance* createInstance (Context& context) const;
1037 virtual void checkSupport (Context& context) const;
1040 static inline const std::string getIntersectionPassthrough (void);
1041 static inline const std::string getMissPassthrough (void);
1042 static inline const std::string getHitPassthrough (void);
1047 ComplexControlFlowTestCase::ComplexControlFlowTestCase (tcu::TestContext& context, const char* name, const char* desc, const CaseDef data)
1048 : vkt::TestCase (context, name, desc)
1053 ComplexControlFlowTestCase::~ComplexControlFlowTestCase (void)
1057 void ComplexControlFlowTestCase::checkSupport (Context& context) const
1059 context.requireDeviceFunctionality("VK_KHR_acceleration_structure");
1060 const VkPhysicalDeviceAccelerationStructureFeaturesKHR& accelerationStructureFeaturesKHR = context.getAccelerationStructureFeatures();
1061 if (accelerationStructureFeaturesKHR.accelerationStructure == DE_FALSE)
1062 TCU_THROW(TestError, "VK_KHR_ray_tracing_pipeline requires VkPhysicalDeviceAccelerationStructureFeaturesKHR.accelerationStructure");
1064 context.requireDeviceFunctionality("VK_KHR_ray_tracing_pipeline");
1065 const VkPhysicalDeviceRayTracingPipelineFeaturesKHR& rayTracingPipelineFeaturesKHR = context.getRayTracingPipelineFeatures();
1066 if (rayTracingPipelineFeaturesKHR.rayTracingPipeline == DE_FALSE)
1067 TCU_THROW(NotSupportedError, "Requires VkPhysicalDeviceRayTracingPipelineFeaturesKHR.rayTracingPipeline");
1072 const std::string ComplexControlFlowTestCase::getIntersectionPassthrough (void)
1074 const std::string intersectionPassthrough =
1075 "#version 460 core\n"
1076 "#extension GL_EXT_nonuniform_qualifier : enable\n"
1077 "#extension GL_EXT_ray_tracing : require\n"
1078 "hitAttributeEXT vec3 hitAttribute;\n"
1082 " reportIntersectionEXT(0.95f, 0u);\n"
1085 return intersectionPassthrough;
1088 const std::string ComplexControlFlowTestCase::getMissPassthrough (void)
1090 const std::string missPassthrough =
1091 "#version 460 core\n"
1092 "#extension GL_EXT_nonuniform_qualifier : enable\n"
1093 "#extension GL_EXT_ray_tracing : require\n"
1094 "layout(location = 0) rayPayloadInEXT vec3 hitValue;\n"
1100 return missPassthrough;
1103 const std::string ComplexControlFlowTestCase::getHitPassthrough (void)
1105 const std::string hitPassthrough =
1106 "#version 460 core\n"
1107 "#extension GL_EXT_nonuniform_qualifier : enable\n"
1108 "#extension GL_EXT_ray_tracing : require\n"
1109 "hitAttributeEXT vec3 attribs;\n"
1110 "layout(location = 0) rayPayloadInEXT vec3 hitValue;\n"
1116 return hitPassthrough;
1119 void ComplexControlFlowTestCase::initPrograms (SourceCollections& programCollection) const
1121 const vk::ShaderBuildOptions buildOptions (programCollection.usedVulkanVersion, vk::SPIRV_VERSION_1_4, 0u, true);
1122 const std::string calleeMainPart =
1123 " uint z = (inValue.x % 8) + 8;\n"
1124 " uint v = inValue.y;\n"
1125 " uint n = gl_LaunchIDEXT.x + gl_LaunchSizeEXT.x * gl_LaunchIDEXT.y;\n"
1126 " imageStore(resultImage, ivec3(gl_LaunchIDEXT.x, gl_LaunchIDEXT.y, z), uvec4(v, 0, 0, 1));\n"
1127 " imageStore(resultImage, ivec3(gl_LaunchIDEXT.x, gl_LaunchIDEXT.y, 7), uvec4(n, 0, 0, 1));\n";
1128 const std::string idTemplate = "$";
1129 const std::string shaderCallInstruction = (m_data.testOp == TEST_OP_EXECUTE_CALLABLE) ? "executeCallableEXT(0, " + idTemplate + ")"
1130 : (m_data.testOp == TEST_OP_TRACE_RAY) ? "traceRayEXT(as, 0, 0xFF, p.hitOfs, 0, p.miss, vec3((gl_LaunchIDEXT.x) + vec3(0.5f)) / vec3(gl_LaunchSizeEXT), 1.0f, vec3(0.0f, 0.0f, 1.0f), 100.0f, " + idTemplate + ")"
1131 : (m_data.testOp == TEST_OP_REPORT_INTERSECTION) ? "reportIntersectionEXT(1.0f, 0u)"
1132 : "TEST_OP_NOT_IMPLEMENTED_FAILURE";
1133 std::string declsPreMain =
1134 "#version 460 core\n"
1135 "#extension GL_EXT_nonuniform_qualifier : enable\n"
1136 "#extension GL_EXT_ray_tracing : require\n"
1138 "layout(set = 0, binding = 0, r32ui) uniform uimage3D resultImage;\n"
1139 "layout(set = 0, binding = 1) uniform accelerationStructureEXT as;\n"
1141 "layout(push_constant) uniform TestParams\n"
1150 std::string declsInMainBeforeOp =
1151 " uint result = 0;\n"
1152 " uint id = uint(gl_LaunchIDEXT.x + gl_LaunchSizeEXT.x * gl_LaunchIDEXT.y);\n";
1153 std::string declsInMainAfterOp =
1154 " imageStore(resultImage, ivec3(gl_LaunchIDEXT.x, gl_LaunchIDEXT.y, 0), uvec4(result, 0, 0, 1));\n"
1155 " imageStore(resultImage, ivec3(gl_LaunchIDEXT.x, gl_LaunchIDEXT.y, 1), uvec4(p.a, 0, 0, 1));\n"
1156 " imageStore(resultImage, ivec3(gl_LaunchIDEXT.x, gl_LaunchIDEXT.y, 2), uvec4(p.b, 0, 0, 1));\n"
1157 " imageStore(resultImage, ivec3(gl_LaunchIDEXT.x, gl_LaunchIDEXT.y, 3), uvec4(p.c, 0, 0, 1));\n"
1158 " imageStore(resultImage, ivec3(gl_LaunchIDEXT.x, gl_LaunchIDEXT.y, 4), uvec4(p.d, 0, 0, 1));\n"
1159 " imageStore(resultImage, ivec3(gl_LaunchIDEXT.x, gl_LaunchIDEXT.y, 5), uvec4(p.hitOfs, 0, 0, 1));\n"
1160 " imageStore(resultImage, ivec3(gl_LaunchIDEXT.x, gl_LaunchIDEXT.y, 6), uvec4(p.miss, 0, 0, 1));\n";
1161 std::string opInMain = "";
1162 std::string opPreMain = "";
1164 DE_ASSERT(!declsPreMain.empty() && PUSH_CONSTANTS_COUNT == 6);
1166 switch (m_data.testType)
1171 " v2 = v3 = uvec2(0, p.b);\n"
1173 " if ((p.a & id) != 0)\n"
1174 " { v0 = uvec2(0, p.c & id); v1 = uvec2(0, (p.d & id) + 1);" + replace(shaderCallInstruction, idTemplate, "0") + "; }\n"
1176 " { v0 = uvec2(0, p.d & id); v1 = uvec2(0, (p.c & id) + 1);" + replace(shaderCallInstruction, idTemplate, "1") + "; }\n"
1178 " result = v0.y + v1.y + v2.y + v3.y;\n";
1182 case TEST_TYPE_LOOP:
1185 " v1 = v3 = uvec2(0, p.b);\n"
1187 " for (uint x = 0; x < p.a; x++)\n"
1189 " v0 = uvec2(x, (p.c & id) + x);\n"
1190 " " + replace(shaderCallInstruction, idTemplate, "0") + ";\n"
1191 " result += v0.y + v1.y + v3.y;\n"
1196 case TEST_TYPE_SWITCH:
1199 " switch (p.a & id)\n"
1201 " case 0: { v1 = v2 = v3 = uvec2(0, p.b); v0 = uvec2(0, p.c & id); " + replace(shaderCallInstruction, idTemplate, "0") + "; break; }\n"
1202 " case 1: { v0 = v2 = v3 = uvec2(0, p.b); v1 = uvec2(0, p.c & id); " + replace(shaderCallInstruction, idTemplate, "1") + "; break; }\n"
1203 " case 2: { v0 = v1 = v3 = uvec2(0, p.b); v2 = uvec2(0, p.c & id); " + replace(shaderCallInstruction, idTemplate, "2") + "; break; }\n"
1204 " case 3: { v0 = v1 = v2 = uvec2(0, p.b); v3 = uvec2(0, p.c & id); " + replace(shaderCallInstruction, idTemplate, "3") + "; break; }\n"
1205 " default: break;\n"
1208 " result = v0.y + v1.y + v2.y + v3.y;\n";
1212 case TEST_TYPE_LOOP_DOUBLE_CALL:
1215 " v3 = uvec2(0, p.b);\n"
1216 " for (uint x = 0; x < p.a; x++)\n"
1218 " v0 = uvec2(2 * x + 0, (p.c & id) + x);\n"
1219 " v1 = uvec2(2 * x + 1, (p.d & id) + x + 1);\n"
1220 " " + replace(shaderCallInstruction, idTemplate, "0") + ";\n"
1221 " " + replace(shaderCallInstruction, idTemplate, "1") + ";\n"
1222 " result += v0.y + v1.y + v3.y;\n"
1227 case TEST_TYPE_LOOP_DOUBLE_CALL_SPARSE:
1230 " v3 = uvec2(0, p.a + p.b);\n"
1231 " for (uint x = 0; x < p.a; x++)\n"
1232 " if ((x & p.b) != 0)\n"
1234 " v0 = uvec2(2 * x + 0, (p.c & id) + x + 0);\n"
1235 " v1 = uvec2(2 * x + 1, (p.d & id) + x + 1);\n"
1236 " " + replace(shaderCallInstruction, idTemplate, "0") + ";\n"
1237 " " + replace(shaderCallInstruction, idTemplate, "1") + ";\n"
1238 " result += v0.y + v1.y + v3.y;\n"
1244 case TEST_TYPE_NESTED_LOOP:
1247 " v1 = v3 = uvec2(0, p.b);\n"
1248 " for (uint y = 0; y < p.a; y++)\n"
1249 " for (uint x = 0; x < p.a; x++)\n"
1251 " uint n = x + y * p.a;\n"
1252 " if ((n & p.d) != 0)\n"
1254 " v0 = uvec2(n, (p.c & id) + (x + y * p.a));\n"
1255 " "+ replace(shaderCallInstruction, idTemplate, "0") + ";\n"
1256 " result += v0.y + v1.y + v3.y;\n"
1263 case TEST_TYPE_NESTED_LOOP_BEFORE:
1266 " for (uint y = 0; y < p.d; y++)\n"
1267 " for (uint x = 0; x < p.d; x++)\n"
1268 " if (((x + y * p.a) & p.b) != 0)\n"
1269 " result += (x + y);\n"
1271 " v1 = v3 = uvec2(0, p.a);\n"
1273 " for (uint x = 0; x < p.b; x++)\n"
1274 " if ((x & p.a) != 0)\n"
1276 " v0 = uvec2(x, p.c & id);\n"
1277 " " + replace(shaderCallInstruction, idTemplate, "0") + ";\n"
1278 " result += v0.y + v1.y + v3.y;\n"
1283 case TEST_TYPE_NESTED_LOOP_AFTER:
1286 " v1 = v3 = uvec2(0, p.a); \n"
1287 " for (uint x = 0; x < p.b; x++)\n"
1288 " if ((x & p.a) != 0)\n"
1290 " v0 = uvec2(x, p.c & id);\n"
1291 " " + replace(shaderCallInstruction, idTemplate, "0") + ";\n"
1292 " result += v0.y + v1.y + v3.y;\n"
1295 " for (uint y = 0; y < p.d; y++)\n"
1296 " for (uint x = 0; x < p.d; x++)\n"
1297 " if (((x + y * p.a) & p.b) != 0)\n"
1298 " result += x + y;\n";
1302 case TEST_TYPE_FUNCTION_CALL:
1310 " for (i = 0; i < a.length(); i++) a[i] = p.c * i;\n"
1312 " " + replace(shaderCallInstruction, idTemplate, "0") + ";\n"
1314 " for (i = 0; i < a.length(); i++) r += a[i];\n"
1319 " v0 = uvec2(0, p.a & id); v1 = v3 = uvec2(0, p.d);\n"
1320 " result = f1() + v0.y + v1.y + v3.y;\n";
1324 case TEST_TYPE_NESTED_FUNCTION_CALL:
1332 " for (i = 0; i < a.length(); i++) a[i] = p.c * i;\n"
1334 " " + replace(shaderCallInstruction, idTemplate, "0") + ";\n"
1336 " for (i = 0; i < a.length(); i++) r += a[i];\n"
1346 " for (j = 0; j < b.length(); j++) b[j] = p.c * j;\n"
1348 " v1 = uvec2(0, p.b);\n"
1352 " for (j = 0; j < b.length(); j++) t += b[j];\n"
1357 " v0 = uvec2(0, p.a & id); v3 = uvec2(0, p.d);\n"
1358 " result = f1() + v0.y + v1.y + v3.y;\n";
1364 TCU_THROW(InternalError, "Unknown testType");
1367 if (m_data.testOp == TEST_OP_EXECUTE_CALLABLE)
1369 const std::string calleeShader =
1370 "#version 460 core\n"
1371 "#extension GL_EXT_nonuniform_qualifier : enable\n"
1372 "#extension GL_EXT_ray_tracing : require\n"
1374 "layout(set = 0, binding = 0, r32ui) uniform uimage3D resultImage;\n"
1375 "layout(location = 0) callableDataInEXT uvec2 inValue;\n"
1384 "layout(location = 0) callableDataEXT uvec2 v0;\n"
1385 "layout(location = 1) callableDataEXT uvec2 v1;\n"
1386 "layout(location = 2) callableDataEXT uvec2 v2;\n"
1387 "layout(location = 3) callableDataEXT uvec2 v3;\n"
1390 switch (m_data.stage)
1392 case VK_SHADER_STAGE_RAYGEN_BIT_KHR:
1394 std::stringstream css;
1400 << declsInMainBeforeOp
1401 << opInMain // executeCallableEXT
1402 << declsInMainAfterOp
1405 programCollection.glslSources.add("rgen") << glu::RaygenSource(css.str()) << buildOptions;
1406 programCollection.glslSources.add("cal0") << glu::CallableSource(calleeShader) << buildOptions;
1411 case VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR:
1413 programCollection.glslSources.add("rgen") << glu::RaygenSource(getCommonRayGenerationShader()) << buildOptions;
1415 std::stringstream css;
1417 << "layout(location = 0) rayPayloadInEXT vec3 hitValue;\n"
1418 << "hitAttributeEXT vec3 attribs;\n"
1424 << declsInMainBeforeOp
1425 << opInMain // executeCallableEXT
1426 << declsInMainAfterOp
1429 programCollection.glslSources.add("chit") << glu::ClosestHitSource(css.str()) << buildOptions;
1430 programCollection.glslSources.add("cal0") << glu::CallableSource(calleeShader) << buildOptions;
1432 programCollection.glslSources.add("ahit") << glu::AnyHitSource(getHitPassthrough()) << buildOptions;
1433 programCollection.glslSources.add("miss") << glu::MissSource(getMissPassthrough()) << buildOptions;
1434 programCollection.glslSources.add("sect") << glu::IntersectionSource(getIntersectionPassthrough()) << buildOptions;
1439 case VK_SHADER_STAGE_MISS_BIT_KHR:
1441 programCollection.glslSources.add("rgen") << glu::RaygenSource(getCommonRayGenerationShader()) << buildOptions;
1443 std::stringstream css;
1449 << declsInMainBeforeOp
1450 << opInMain // executeCallableEXT
1451 << declsInMainAfterOp
1454 programCollection.glslSources.add("miss") << glu::MissSource(css.str()) << buildOptions;
1455 programCollection.glslSources.add("cal0") << glu::CallableSource(calleeShader) << buildOptions;
1457 programCollection.glslSources.add("ahit") << glu::AnyHitSource(getHitPassthrough()) << buildOptions;
1458 programCollection.glslSources.add("chit") << glu::ClosestHitSource(getHitPassthrough()) << buildOptions;
1459 programCollection.glslSources.add("sect") << glu::IntersectionSource(getIntersectionPassthrough()) << buildOptions;
1464 case VK_SHADER_STAGE_CALLABLE_BIT_KHR:
1467 std::stringstream css;
1468 css << "#version 460 core\n"
1469 << "#extension GL_EXT_nonuniform_qualifier : enable\n"
1470 << "#extension GL_EXT_ray_tracing : require\n"
1472 << "layout(location = 4) callableDataEXT float dummy;\n"
1473 << "layout(set = 0, binding = 0, r32ui) uniform uimage3D resultImage;\n"
1477 << " executeCallableEXT(1, 4);\n"
1480 programCollection.glslSources.add("rgen") << glu::RaygenSource(css.str()) << buildOptions;
1484 std::stringstream css;
1486 << "layout(location = 4) callableDataInEXT float dummyIn;\n"
1491 << declsInMainBeforeOp
1492 << opInMain // executeCallableEXT
1493 << declsInMainAfterOp
1496 programCollection.glslSources.add("call") << glu::CallableSource(css.str()) << buildOptions;
1499 programCollection.glslSources.add("cal0") << glu::CallableSource(calleeShader) << buildOptions;
1505 TCU_THROW(InternalError, "Unknown stage");
1508 else if (m_data.testOp == TEST_OP_TRACE_RAY)
1510 const std::string missShader =
1511 "#version 460 core\n"
1512 "#extension GL_EXT_nonuniform_qualifier : enable\n"
1513 "#extension GL_EXT_ray_tracing : require\n"
1515 "layout(set = 0, binding = 0, r32ui) uniform uimage3D resultImage;\n"
1516 "layout(location = 0) rayPayloadInEXT uvec2 inValue;\n"
1525 "layout(location = 0) rayPayloadEXT uvec2 v0;\n"
1526 "layout(location = 1) rayPayloadEXT uvec2 v1;\n"
1527 "layout(location = 2) rayPayloadEXT uvec2 v2;\n"
1528 "layout(location = 3) rayPayloadEXT uvec2 v3;\n";
1530 switch (m_data.stage)
1532 case VK_SHADER_STAGE_RAYGEN_BIT_KHR:
1534 std::stringstream css;
1540 << declsInMainBeforeOp
1541 << opInMain // traceRayEXT
1542 << declsInMainAfterOp
1545 programCollection.glslSources.add("rgen") << glu::RaygenSource(css.str()) << buildOptions;
1547 programCollection.glslSources.add("miss") << glu::MissSource(getMissPassthrough()) << buildOptions;
1548 programCollection.glslSources.add("ahit") << glu::AnyHitSource(getHitPassthrough()) << buildOptions;
1549 programCollection.glslSources.add("chit") << glu::ClosestHitSource(getHitPassthrough()) << buildOptions;
1550 programCollection.glslSources.add("sect") << glu::IntersectionSource(getIntersectionPassthrough()) << buildOptions;
1552 programCollection.glslSources.add("miss2") << glu::MissSource(missShader) << buildOptions;
1553 programCollection.glslSources.add("ahit2") << glu::AnyHitSource(getHitPassthrough()) << buildOptions;
1554 programCollection.glslSources.add("chit2") << glu::ClosestHitSource(getHitPassthrough()) << buildOptions;
1555 programCollection.glslSources.add("sect2") << glu::IntersectionSource(getIntersectionPassthrough()) << buildOptions;
1560 case VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR:
1562 programCollection.glslSources.add("rgen") << glu::RaygenSource(getCommonRayGenerationShader()) << buildOptions;
1564 std::stringstream css;
1570 << declsInMainBeforeOp
1571 << opInMain // traceRayEXT
1572 << declsInMainAfterOp
1575 programCollection.glslSources.add("chit") << glu::ClosestHitSource(css.str()) << buildOptions;
1577 programCollection.glslSources.add("miss") << glu::MissSource(getMissPassthrough()) << buildOptions;
1578 programCollection.glslSources.add("ahit") << glu::AnyHitSource(getHitPassthrough()) << buildOptions;
1579 programCollection.glslSources.add("sect") << glu::IntersectionSource(getIntersectionPassthrough()) << buildOptions;
1581 programCollection.glslSources.add("miss2") << glu::MissSource(missShader) << buildOptions;
1582 programCollection.glslSources.add("ahit2") << glu::AnyHitSource(getHitPassthrough()) << buildOptions;
1583 programCollection.glslSources.add("chit2") << glu::ClosestHitSource(getHitPassthrough()) << buildOptions;
1584 programCollection.glslSources.add("sect2") << glu::IntersectionSource(getIntersectionPassthrough()) << buildOptions;
1589 case VK_SHADER_STAGE_MISS_BIT_KHR:
1591 programCollection.glslSources.add("rgen") << glu::RaygenSource(getCommonRayGenerationShader()) << buildOptions;
1593 std::stringstream css;
1599 << declsInMainBeforeOp
1600 << opInMain // traceRayEXT
1601 << declsInMainAfterOp
1604 programCollection.glslSources.add("miss") << glu::MissSource(css.str()) << buildOptions;
1606 programCollection.glslSources.add("ahit") << glu::AnyHitSource(getHitPassthrough()) << buildOptions;
1607 programCollection.glslSources.add("chit") << glu::ClosestHitSource(getHitPassthrough()) << buildOptions;
1608 programCollection.glslSources.add("sect") << glu::IntersectionSource(getIntersectionPassthrough()) << buildOptions;
1610 programCollection.glslSources.add("miss2") << glu::MissSource(missShader) << buildOptions;
1611 programCollection.glslSources.add("ahit2") << glu::AnyHitSource(getHitPassthrough()) << buildOptions;
1612 programCollection.glslSources.add("chit2") << glu::ClosestHitSource(getHitPassthrough()) << buildOptions;
1613 programCollection.glslSources.add("sect2") << glu::IntersectionSource(getIntersectionPassthrough()) << buildOptions;
1619 TCU_THROW(InternalError, "Unknown stage");
1622 else if (m_data.testOp == TEST_OP_REPORT_INTERSECTION)
1624 const std::string anyHitShader =
1625 "#version 460 core\n"
1626 "#extension GL_EXT_nonuniform_qualifier : enable\n"
1627 "#extension GL_EXT_ray_tracing : require\n"
1629 "layout(set = 0, binding = 0, r32ui) uniform uimage3D resultImage;\n"
1630 "hitAttributeEXT block { uvec2 inValue; };\n"
1638 "hitAttributeEXT block { uvec2 v0; };\n"
1643 switch (m_data.stage)
1645 case VK_SHADER_STAGE_INTERSECTION_BIT_KHR:
1647 programCollection.glslSources.add("rgen") << glu::RaygenSource(getCommonRayGenerationShader()) << buildOptions;
1649 std::stringstream css;
1655 << declsInMainBeforeOp
1656 << opInMain // reportIntersectionEXT
1657 << declsInMainAfterOp
1660 programCollection.glslSources.add("sect") << glu::IntersectionSource(css.str()) << buildOptions;
1661 programCollection.glslSources.add("ahit") << glu::AnyHitSource(anyHitShader) << buildOptions;
1663 programCollection.glslSources.add("chit") << glu::ClosestHitSource(getHitPassthrough()) << buildOptions;
1664 programCollection.glslSources.add("miss") << glu::MissSource(getMissPassthrough()) << buildOptions;
1670 TCU_THROW(InternalError, "Unknown stage");
1675 TCU_THROW(InternalError, "Unknown operation");
1679 TestInstance* ComplexControlFlowTestCase::createInstance (Context& context) const
1681 return new RayTracingComplexControlFlowInstance(context, m_data);
1686 tcu::TestCaseGroup* createComplexControlFlowTests (tcu::TestContext& testCtx)
1691 VkShaderStageFlagBits stage;
1695 { "rgen", VK_SHADER_STAGE_RAYGEN_BIT_KHR },
1696 { "chit", VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR },
1697 { "ahit", VK_SHADER_STAGE_ANY_HIT_BIT_KHR },
1698 { "sect", VK_SHADER_STAGE_INTERSECTION_BIT_KHR },
1699 { "miss", VK_SHADER_STAGE_MISS_BIT_KHR },
1700 { "call", VK_SHADER_STAGE_CALLABLE_BIT_KHR },
1709 { "execute_callable", TEST_OP_EXECUTE_CALLABLE },
1710 { "trace_ray", TEST_OP_TRACE_RAY },
1711 { "report_intersection", TEST_OP_REPORT_INTERSECTION },
1720 { "if", TEST_TYPE_IF },
1721 { "loop", TEST_TYPE_LOOP },
1722 { "switch", TEST_TYPE_SWITCH },
1723 { "loop_double_call", TEST_TYPE_LOOP_DOUBLE_CALL },
1724 { "loop_double_call_sparse", TEST_TYPE_LOOP_DOUBLE_CALL_SPARSE },
1725 { "nested_loop", TEST_TYPE_NESTED_LOOP },
1726 { "nested_loop_loop_before", TEST_TYPE_NESTED_LOOP_BEFORE },
1727 { "nested_loop_loop_after", TEST_TYPE_NESTED_LOOP_AFTER },
1728 { "function_call", TEST_TYPE_FUNCTION_CALL },
1729 { "nested_function_call", TEST_TYPE_NESTED_FUNCTION_CALL },
1732 de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "complexcontrolflow", "Ray tracing complex control flow tests"));
1734 for (size_t testTypeNdx = 0; testTypeNdx < DE_LENGTH_OF_ARRAY(testTypes); ++testTypeNdx)
1736 const TestType testType = testTypes[testTypeNdx].testType;
1737 de::MovePtr<tcu::TestCaseGroup> testTypeGroup (new tcu::TestCaseGroup(testCtx, testTypes[testTypeNdx].name, ""));
1739 for (size_t testOpNdx = 0; testOpNdx < DE_LENGTH_OF_ARRAY(testOps); ++testOpNdx)
1741 const TestOp testOp = testOps[testOpNdx].op;
1742 de::MovePtr<tcu::TestCaseGroup> testOpGroup (new tcu::TestCaseGroup(testCtx, testOps[testOpNdx].name, ""));
1744 for (size_t testStagesNdx = 0; testStagesNdx < DE_LENGTH_OF_ARRAY(testStages); ++testStagesNdx)
1746 const VkShaderStageFlagBits testStage = testStages[testStagesNdx].stage;
1747 const std::string testName = de::toString(testStages[testStagesNdx].name);
1748 const deUint32 width = 4u;
1749 const deUint32 height = 4u;
1750 const CaseDef caseDef =
1752 testType, // TestType testType;
1753 testOp, // TestOp testOp;
1754 testStage, // VkShaderStageFlagBits stage;
1755 width, // deUint32 width;
1756 height, // deUint32 height;
1759 if (testOp == TEST_OP_REPORT_INTERSECTION && testStage != VK_SHADER_STAGE_INTERSECTION_BIT_KHR)
1762 if (testOp == TEST_OP_TRACE_RAY)
1766 case VK_SHADER_STAGE_RAYGEN_BIT_KHR:
1767 case VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR:
1768 case VK_SHADER_STAGE_MISS_BIT_KHR:
1775 if (testOp == TEST_OP_EXECUTE_CALLABLE)
1779 case VK_SHADER_STAGE_RAYGEN_BIT_KHR:
1780 case VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR:
1781 case VK_SHADER_STAGE_MISS_BIT_KHR:
1782 case VK_SHADER_STAGE_CALLABLE_BIT_KHR:
1789 testOpGroup->addChild(new ComplexControlFlowTestCase(testCtx, testName.c_str(), "", caseDef));
1792 testTypeGroup->addChild(testOpGroup.release());
1795 group->addChild(testTypeGroup.release());
1798 return group.release();