blob: 18340c311853887030d8a32c5964227039dfb77c [file] [log] [blame]
/*------------------------------------------------------------------------
* Vulkan Conformance Tests
* ------------------------
*
* Copyright (c) 2020 The Khronos Group Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*//*!
* \file
* \brief Ray Query Builtin tests
*//*--------------------------------------------------------------------*/
#include "vktRayQueryBuiltinTests.hpp"
#include "vkDefs.hpp"
#include "vktTestCase.hpp"
#include "vktCustomInstancesDevices.hpp"
#include "vktTestGroupUtil.hpp"
#include "vkCmdUtil.hpp"
#include "vkObjUtil.hpp"
#include "vkBuilderUtil.hpp"
#include "vkBarrierUtil.hpp"
#include "vkBufferWithMemory.hpp"
#include "vkImageWithMemory.hpp"
#include "vkTypeUtil.hpp"
#include "vkImageUtil.hpp"
#include "deRandom.hpp"
#include "tcuTexture.hpp"
#include "tcuTextureUtil.hpp"
#include "tcuTestLog.hpp"
#include "tcuImageCompare.hpp"
#include "tcuCommandLine.hpp"
#include "vkRayTracingUtil.hpp"
namespace vkt
{
namespace RayQuery
{
namespace
{
using namespace vk;
using namespace vkt;
static const VkFlags ALL_RAY_TRACING_STAGES = VK_SHADER_STAGE_RAYGEN_BIT_KHR
| VK_SHADER_STAGE_ANY_HIT_BIT_KHR
| VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR
| VK_SHADER_STAGE_MISS_BIT_KHR
| VK_SHADER_STAGE_INTERSECTION_BIT_KHR
| VK_SHADER_STAGE_CALLABLE_BIT_KHR;
enum TestType
{
TEST_TYPE_FLOW = 0,
TEST_TYPE_PRIMITIVE_ID,
TEST_TYPE_INSTANCE_ID,
TEST_TYPE_INSTANCE_CUSTOM_INDEX,
TEST_TYPE_INTERSECTION_T_KHR,
TEST_TYPE_OBJECT_RAY_ORIGIN_KHR,
TEST_TYPE_OBJECT_RAY_DIRECTION_KHR,
TEST_TYPE_OBJECT_TO_WORLD_KHR,
TEST_TYPE_WORLD_TO_OBJECT_KHR,
TEST_TYPE_NULL_ACCELERATION_STRUCTURE,
TEST_TYPE_USING_WRAPPER_FUNCTION,
TEST_TYPE_GET_RAY_TMIN,
TEST_TYPE_GET_WORLD_RAY_ORIGIN,
TEST_TYPE_GET_WORLD_RAY_DIRECTION,
TEST_TYPE_GET_INTERSECTION_CANDIDATE_AABB_OPAQUE,
TEST_TYPE_GET_INTERSECTION_FRONT_FACE_CANDIDATE,
TEST_TYPE_GET_INTERSECTION_FRONT_FACE_COMMITTED,
TEST_TYPE_GET_INTERSECTION_GEOMETRY_INDEX_CANDIDATE,
TEST_TYPE_GET_INTERSECTION_GEOMETRY_INDEX_COMMITTED,
TEST_TYPE_GET_INTERSECTION_BARYCENTRICS_CANDIDATE,
TEST_TYPE_GET_INTERSECTION_BARYCENTRICS_COMMITTED,
TEST_TYPE_GET_INTERSECTION_INSTANCE_SHADER_BINDING_TABLE_RECORD_OFFSET_CANDIDATE,
TEST_TYPE_GET_INTERSECTION_INSTANCE_SHADER_BINDING_TABLE_RECORD_OFFSET_COMMITTED,
TEST_TYPE_RAY_QUERY_TERMINATE,
TEST_TYPE_GET_INTERSECTION_TYPE_CANDIDATE,
TEST_TYPE_GET_INTERSECTION_TYPE_COMMITTED,
TEST_TYPE_LAST
};
enum GeomType
{
GEOM_TYPE_TRIANGLES,
GEOM_TYPE_AABBS,
GEOM_TYPE_LAST,
};
const deUint32 TEST_WIDTH = 8;
const deUint32 TEST_HEIGHT = 8;
const deUint32 FIXED_POINT_DIVISOR = 1024 * 1024;
const deUint32 FIXED_POINT_ALLOWED_ERROR = static_cast<deUint32>(float(1e-3f) * FIXED_POINT_DIVISOR);
struct TestParams;
// Similar to a subset of the test context but allows us to plug in a custom device when needed.
// Note TestEnvironment objects do not own the resources they point to.
struct TestEnvironment
{
const InstanceInterface* vki;
VkPhysicalDevice physicalDevice;
const DeviceInterface* vkd;
VkDevice device;
Allocator* allocator;
VkQueue queue;
deUint32 queueFamilyIndex;
BinaryCollection* binaryCollection;
tcu::TestLog* log;
};
typedef void (*CheckSupportFunc)(Context& context, const TestParams& testParams);
typedef void (*InitProgramsFunc)(SourceCollections& programCollection, const TestParams& testParams);
typedef const std::string(*ShaderBodyTextFunc)(const TestParams& testParams);
class PipelineConfiguration
{
public:
PipelineConfiguration() {}
virtual ~PipelineConfiguration() {}
virtual void initConfiguration(const TestEnvironment& env,
TestParams& testParams) = 0;
virtual void fillCommandBuffer(const TestEnvironment& env,
TestParams& testParams,
VkCommandBuffer commandBuffer,
const VkAccelerationStructureKHR* rayQueryTopAccelerationStructurePtr,
const VkDescriptorImageInfo& resultImageInfo) = 0;
};
class TestConfiguration
{
public:
TestConfiguration(Context& context)
: m_bottomAccelerationStructures()
, m_topAccelerationStructure()
, m_expected()
, m_testEnvironment()
{
prepareTestEnvironment(context);
}
virtual ~TestConfiguration()
{
}
const TestEnvironment& getTestEnvironment () const;
virtual const VkAccelerationStructureKHR* initAccelerationStructures (TestParams& testParams, VkCommandBuffer cmdBuffer) = 0;
virtual bool verify (BufferWithMemory* resultBuffer, TestParams& testParams);
protected:
void prepareTestEnvironment (Context& context);
std::vector<de::SharedPtr<BottomLevelAccelerationStructure>> m_bottomAccelerationStructures;
de::SharedPtr<TopLevelAccelerationStructure> m_topAccelerationStructure;
std::vector<deInt32> m_expected;
de::MovePtr<TestEnvironment> m_testEnvironment;
};
class TestConfigurationFloat : public TestConfiguration
{
public:
TestConfigurationFloat(Context& context)
: TestConfiguration(context)
{
}
virtual ~TestConfigurationFloat()
{
}
virtual bool verify(BufferWithMemory* resultBuffer,
TestParams& testParams) override;
};
class TestConfigurationVector : public TestConfiguration
{
public:
TestConfigurationVector(Context& context, bool useStrictComponentMatching = true)
: TestConfiguration(context),
m_useStrictComponentMatching(useStrictComponentMatching)
{
}
virtual ~TestConfigurationVector()
{
}
virtual bool verify(BufferWithMemory* resultBuffer,
TestParams& testParams) override;
private:
bool m_useStrictComponentMatching;
};
class TestConfigurationMatrix : public TestConfiguration
{
public:
TestConfigurationMatrix(Context& context)
: TestConfiguration(context)
{
}
virtual ~TestConfigurationMatrix()
{
}
virtual bool verify(BufferWithMemory* resultBuffer,
TestParams& testParams) override;
};
struct TestParams
{
deUint32 width;
deUint32 height;
deUint32 depth;
TestType testType;
VkShaderStageFlagBits stage;
GeomType geomType;
deUint32 squaresGroupCount;
deUint32 geometriesGroupCount;
deUint32 instancesGroupCount;
VkFormat format;
CheckSupportFunc pipelineCheckSupport;
InitProgramsFunc pipelineInitPrograms;
ShaderBodyTextFunc testConfigShaderBodyText;
bool isSPIRV; // determines if shader body is defined in SPIR-V
CheckSupportFunc testConfigCheckSupport;
};
deUint32 getShaderGroupHandleSize(const InstanceInterface& vki,
const VkPhysicalDevice physicalDevice)
{
de::MovePtr<RayTracingProperties> rayTracingPropertiesKHR;
rayTracingPropertiesKHR = makeRayTracingProperties(vki, physicalDevice);
return rayTracingPropertiesKHR->getShaderGroupHandleSize();
}
deUint32 getShaderGroupBaseAlignment(const InstanceInterface& vki,
const VkPhysicalDevice physicalDevice)
{
de::MovePtr<RayTracingProperties> rayTracingPropertiesKHR;
rayTracingPropertiesKHR = makeRayTracingProperties(vki, physicalDevice);
return rayTracingPropertiesKHR->getShaderGroupBaseAlignment();
}
VkImageCreateInfo makeImageCreateInfo(VkFormat format,
deUint32 width,
deUint32 height,
deUint32 depth,
VkImageType imageType = VK_IMAGE_TYPE_3D,
VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)
{
const VkImageCreateInfo imageCreateInfo =
{
VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
DE_NULL, // const void* pNext;
(VkImageCreateFlags)0u, // VkImageCreateFlags flags;
imageType, // VkImageType imageType;
format, // VkFormat format;
makeExtent3D(width, height, depth), // VkExtent3D extent;
1u, // deUint32 mipLevels;
1u, // deUint32 arrayLayers;
VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
usageFlags, // VkImageUsageFlags usage;
VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
0u, // deUint32 queueFamilyIndexCount;
DE_NULL, // const deUint32* pQueueFamilyIndices;
VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout initialLayout;
};
return imageCreateInfo;
}
Move<VkPipeline> makeComputePipeline(const DeviceInterface& vk,
const VkDevice device,
const VkPipelineLayout pipelineLayout,
const VkShaderModule shaderModule)
{
const VkPipelineShaderStageCreateInfo pipelineShaderStageParams =
{
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
DE_NULL, // const void* pNext;
0u, // VkPipelineShaderStageCreateFlags flags;
VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
shaderModule, // VkShaderModule module;
"main", // const char* pName;
DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
};
const VkComputePipelineCreateInfo pipelineCreateInfo =
{
VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType;
DE_NULL, // const void* pNext;
0u, // VkPipelineCreateFlags flags;
pipelineShaderStageParams, // VkPipelineShaderStageCreateInfo stage;
pipelineLayout, // VkPipelineLayout layout;
DE_NULL, // VkPipeline basePipelineHandle;
0, // deInt32 basePipelineIndex;
};
return createComputePipeline(vk, device, DE_NULL, &pipelineCreateInfo);
}
static const std::string getMissPassthrough(void)
{
const std::string missPassthrough =
"#version 460 core\n"
"#extension GL_EXT_ray_tracing : require\n"
"layout(location = 0) rayPayloadInEXT vec3 hitValue;\n"
"\n"
"void main()\n"
"{\n"
"}\n";
return missPassthrough;
}
static const std::string getHitPassthrough(void)
{
const std::string hitPassthrough =
"#version 460 core\n"
"#extension GL_EXT_ray_tracing : require\n"
"hitAttributeEXT vec3 attribs;\n"
"layout(location = 0) rayPayloadInEXT vec3 hitValue;\n"
"\n"
"void main()\n"
"{\n"
"}\n";
return hitPassthrough;
}
static const std::string getGraphicsPassthrough(void)
{
std::ostringstream src;
src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_460) << "\n"
<< "\n"
<< "void main(void)\n"
<< "{\n"
<< "}\n";
return src.str();
}
static const std::string getVertexPassthrough(void)
{
std::ostringstream src;
src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_460) << "\n"
<< "\n"
<< "layout(location = 0) in vec4 in_position;\n"
<< "\n"
<< "void main(void)\n"
<< "{\n"
<< " gl_Position = in_position;\n"
<< "}\n";
return src.str();
}
class GraphicsConfiguration : public PipelineConfiguration
{
public:
static void checkSupport(Context& context,
const TestParams& testParams);
static void initPrograms(SourceCollections& programCollection,
const TestParams& testParams);
GraphicsConfiguration();
virtual ~GraphicsConfiguration() {}
void initVertexBuffer(const TestEnvironment& env,
TestParams& testParams);
Move<VkPipeline> makeGraphicsPipeline(const TestEnvironment& env,
TestParams& testParams);
virtual void initConfiguration(const TestEnvironment& env,
TestParams& testParams) override;
virtual void fillCommandBuffer(const TestEnvironment& env,
TestParams& testParams,
VkCommandBuffer commandBuffer,
const VkAccelerationStructureKHR* rayQueryTopAccelerationStructurePtr,
const VkDescriptorImageInfo& resultImageInfo) override;
private:
Move<VkDescriptorSetLayout> m_descriptorSetLayout;
Move<VkDescriptorPool> m_descriptorPool;
Move<VkDescriptorSet> m_descriptorSet;
VkFormat m_framebufferFormat;
Move<VkImage> m_framebufferImage;
de::MovePtr<Allocation> m_framebufferImageAlloc;
Move<VkImageView> m_framebufferAttachment;
Move<VkShaderModule> m_vertShaderModule;
Move<VkShaderModule> m_geomShaderModule;
Move<VkShaderModule> m_tescShaderModule;
Move<VkShaderModule> m_teseShaderModule;
Move<VkShaderModule> m_fragShaderModule;
Move<VkRenderPass> m_renderPass;
Move<VkFramebuffer> m_framebuffer;
Move<VkPipelineLayout> m_pipelineLayout;
Move<VkPipeline> m_pipeline;
deUint32 m_vertexCount;
Move<VkBuffer> m_vertexBuffer;
de::MovePtr<Allocation> m_vertexBufferAlloc;
};
GraphicsConfiguration::GraphicsConfiguration()
: PipelineConfiguration()
, m_descriptorSetLayout()
, m_descriptorPool()
, m_descriptorSet()
, m_framebufferFormat(VK_FORMAT_R8G8B8A8_UNORM)
, m_framebufferImage()
, m_framebufferImageAlloc()
, m_framebufferAttachment()
, m_vertShaderModule()
, m_geomShaderModule()
, m_tescShaderModule()
, m_teseShaderModule()
, m_fragShaderModule()
, m_renderPass()
, m_framebuffer()
, m_pipelineLayout()
, m_pipeline()
, m_vertexCount(0)
, m_vertexBuffer()
, m_vertexBufferAlloc()
{
}
void GraphicsConfiguration::checkSupport(Context& context,
const TestParams& testParams)
{
switch (testParams.stage)
{
case VK_SHADER_STAGE_VERTEX_BIT:
case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
case VK_SHADER_STAGE_GEOMETRY_BIT:
context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_VERTEX_PIPELINE_STORES_AND_ATOMICS);
break;
default:
break;
}
switch (testParams.stage)
{
case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_TESSELLATION_SHADER);
break;
case VK_SHADER_STAGE_GEOMETRY_BIT:
context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_GEOMETRY_SHADER);
break;
default:
break;
}
}
void GraphicsConfiguration::initPrograms(SourceCollections& programCollection,
const TestParams& testParams)
{
const vk::ShaderBuildOptions buildOptions(programCollection.usedVulkanVersion, vk::SPIRV_VERSION_1_4, 0u, true);
const std::string testShaderBody = testParams.testConfigShaderBodyText(testParams);
switch (testParams.stage)
{
case VK_SHADER_STAGE_VERTEX_BIT:
{
{
std::ostringstream src;
src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_460) << "\n"
<< "#extension GL_EXT_ray_query : require\n"
<< "#extension GL_EXT_ray_tracing : require\n"
<< "layout(set = 0, binding = 0, r32i) uniform iimage3D result;\n"
<< "layout(set = 0, binding = 1) uniform accelerationStructureEXT rayQueryTopLevelAccelerationStructure;\n"
<< "\n"
<< "void testFunc(ivec3 pos, ivec3 size)\n"
<< "{\n"
<< testShaderBody
<< "}\n"
<< "\n"
<< "void main(void)\n"
<< "{\n"
<< " const int posId = int(gl_VertexIndex / 3);\n"
<< " const int vertId = int(gl_VertexIndex % 3);\n"
<< " const ivec3 size = ivec3(" << testParams.width << ", " << testParams.height << ", 1);\n"
<< " const ivec3 pos = ivec3(posId % size.x, posId / size.x, 0);\n"
<< "\n"
<< " if (vertId == 0)\n"
<< " {\n"
<< " testFunc(pos, size);\n"
<< " }\n"
<< "}\n";
programCollection.glslSources.add("vert") << glu::VertexSource(src.str()) << buildOptions;
}
programCollection.glslSources.add("frag") << glu::FragmentSource(getGraphicsPassthrough()) << buildOptions;
break;
}
case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
{
{
std::ostringstream src;
src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_460) << "\n"
<< "\n"
<< "layout(location = 0) in vec4 in_position;\n"
<< "out gl_PerVertex\n"
<< "{\n"
<< " vec4 gl_Position;\n"
<< "};\n"
<< "\n"
<< "void main(void)\n"
<< "{\n"
<< " gl_Position = in_position;\n"
<< "}\n";
programCollection.glslSources.add("vert") << glu::VertexSource(src.str()) << buildOptions;
}
{
std::ostringstream src;
src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_460) << "\n"
<< "#extension GL_EXT_tessellation_shader : require\n"
<< "#extension GL_EXT_ray_query : require\n"
<< "layout(set = 0, binding = 0, r32i) uniform iimage3D result;\n"
<< "layout(set = 0, binding = 1) uniform accelerationStructureEXT rayQueryTopLevelAccelerationStructure;\n"
<< "in gl_PerVertex\n"
<< "{\n"
<< " vec4 gl_Position;\n"
<< "} gl_in[];\n"
<< "layout(vertices = 4) out;\n"
<< "out gl_PerVertex\n"
<< "{\n"
<< " vec4 gl_Position;\n"
<< "} gl_out[];\n"
<< "\n"
<< "void testFunc(ivec3 pos, ivec3 size)\n"
<< "{\n"
<< testShaderBody
<< "}\n"
<< "\n"
<< "void main(void)\n"
<< "{\n"
<< "\n"
<< " if (gl_InvocationID == 0)\n"
<< " {\n"
<< " const ivec3 size = ivec3(" << testParams.width << ", " << testParams.height << ", 1);\n"
<< " for (int y = 0; y < size.y; y++)\n"
<< " for (int x = 0; x < size.x; x++)\n"
<< " {\n"
<< " const ivec3 pos = ivec3(x, y, 0);\n"
<< " testFunc(pos, size);\n"
<< " }\n"
<< " }\n"
<< "\n"
<< " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
<< " gl_TessLevelInner[0] = 1;\n"
<< " gl_TessLevelInner[1] = 1;\n"
<< " gl_TessLevelOuter[gl_InvocationID] = 1;\n"
<< "}\n";
programCollection.glslSources.add("tesc") << glu::TessellationControlSource(src.str()) << buildOptions;
}
{
std::ostringstream src;
src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_460) << "\n"
<< "#extension GL_EXT_tessellation_shader : require\n"
<< "layout(quads, equal_spacing, ccw) in;\n"
<< "in gl_PerVertex\n"
<< "{\n"
<< " vec4 gl_Position;\n"
<< "} gl_in[];\n"
<< "\n"
<< "void main(void)\n"
<< "{\n"
<< " gl_Position = gl_in[0].gl_Position;\n"
<< "}\n";
programCollection.glslSources.add("tese") << glu::TessellationEvaluationSource(src.str()) << buildOptions;
}
break;
}
case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
{
{
std::ostringstream src;
src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_460) << "\n"
<< "\n"
<< "layout(location = 0) in vec4 in_position;\n"
<< "out gl_PerVertex"
<< "{\n"
<< " vec4 gl_Position;\n"
<< "};\n"
<< "\n"
<< "void main(void)\n"
<< "{\n"
<< " gl_Position = in_position;\n"
<< "}\n";
programCollection.glslSources.add("vert") << glu::VertexSource(src.str()) << buildOptions;
}
{
std::ostringstream src;
src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_460) << "\n"
<< "#extension GL_EXT_tessellation_shader : require\n"
<< "in gl_PerVertex\n"
<< "{\n"
<< " vec4 gl_Position;\n"
<< "} gl_in[];\n"
<< "layout(vertices = 4) out;\n"
<< "out gl_PerVertex\n"
<< "{\n"
<< " vec4 gl_Position;\n"
<< "} gl_out[];\n"
<< "\n"
<< "void main(void)\n"
<< "{\n"
<< " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
<< " gl_TessLevelInner[0] = 1;\n"
<< " gl_TessLevelInner[1] = 1;\n"
<< " gl_TessLevelOuter[gl_InvocationID] = 1;\n"
<< "}\n";
programCollection.glslSources.add("tesc") << glu::TessellationControlSource(src.str()) << buildOptions;
}
{
std::ostringstream src;
src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_460) << "\n"
<< "#extension GL_EXT_tessellation_shader : require\n"
<< "#extension GL_EXT_ray_query : require\n"
<< "layout(set = 0, binding = 0, r32i) uniform iimage3D result;\n"
<< "layout(set = 0, binding = 1) uniform accelerationStructureEXT rayQueryTopLevelAccelerationStructure;\n"
<< "layout(quads, equal_spacing, ccw) in;\n"
<< "in gl_PerVertex\n"
<< "{\n"
<< " vec4 gl_Position;\n"
<< "} gl_in[];\n"
<< "\n"
<< "void testFunc(ivec3 pos, ivec3 size)\n"
<< "{\n"
<< testShaderBody
<< "}\n"
<< "\n"
<< "void main(void)\n"
<< "{\n"
<< " const ivec3 size = ivec3(" << testParams.width << ", " << testParams.height << ", 1);\n"
<< "\n"
<< " if (gl_PrimitiveID == 0)\n"
<< " {\n"
<< " const ivec3 size = ivec3(" << testParams.width << ", " << testParams.height << ", 1);\n"
<< " for (int y = 0; y < size.y; y++)\n"
<< " for (int x = 0; x < size.x; x++)\n"
<< " {\n"
<< " const ivec3 pos = ivec3(x, y, 0);\n"
<< " testFunc(pos, size);\n"
<< " }\n"
<< " }\n"
<< "\n"
<< " gl_Position = gl_in[0].gl_Position;\n"
<< "}\n";
programCollection.glslSources.add("tese") << glu::TessellationEvaluationSource(src.str()) << buildOptions;
}
break;
}
case VK_SHADER_STAGE_GEOMETRY_BIT:
{
programCollection.glslSources.add("vert") << glu::VertexSource(getVertexPassthrough()) << buildOptions;
{
std::ostringstream src;
src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_460) << "\n"
<< "#extension GL_EXT_ray_query : require\n"
<< "layout(triangles) in;\n"
<< "layout(points, max_vertices = 1) out;\n"
<< "layout(set = 0, binding = 0, r32i) uniform iimage3D result;\n"
<< "layout(set = 0, binding = 1) uniform accelerationStructureEXT rayQueryTopLevelAccelerationStructure;\n"
<< "\n"
<< "void testFunc(ivec3 pos, ivec3 size)\n"
<< "{\n"
<< testShaderBody
<< "}\n"
<< "\n"
<< "void main(void)\n"
<< "{\n"
<< " const int posId = int(gl_PrimitiveIDIn);\n"
<< " const ivec3 size = ivec3(" << testParams.width << ", " << testParams.height << ", 1);\n"
<< " const ivec3 pos = ivec3(posId % size.x, posId / size.x, 0);\n"
<< "\n"
<< " testFunc(pos, size);\n"
<< "}\n";
programCollection.glslSources.add("geom") << glu::GeometrySource(src.str()) << buildOptions;
}
break;
}
case VK_SHADER_STAGE_FRAGMENT_BIT:
{
programCollection.glslSources.add("vert") << glu::VertexSource(getVertexPassthrough()) << buildOptions;
{
std::ostringstream src;
src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_460) << "\n"
<< "#extension GL_EXT_ray_query : require\n"
<< "layout(set = 0, binding = 0, r32i) uniform iimage3D result;\n"
<< "layout(set = 0, binding = 1) uniform accelerationStructureEXT rayQueryTopLevelAccelerationStructure;\n"
<< "\n"
<< "void testFunc(ivec3 pos, ivec3 size)\n"
<< "{\n"
<< testShaderBody
<< "}\n"
<< "\n"
<< "void main(void)\n"
<< "{\n"
<< " const ivec3 size = ivec3(" << testParams.width << ", " << testParams.height << ", 1);\n"
<< " const ivec3 pos = ivec3(int(gl_FragCoord.x - 0.5f), int(gl_FragCoord.y - 0.5f), 0);\n"
<< "\n"
<< " testFunc(pos, size);\n"
<< "}\n";
programCollection.glslSources.add("frag") << glu::FragmentSource(src.str()) << buildOptions;
}
break;
}
default:
TCU_THROW(InternalError, "Unknown stage");
}
}
void GraphicsConfiguration::initVertexBuffer(const TestEnvironment& env,
TestParams& testParams)
{
const DeviceInterface& vkd = *env.vkd;
const VkDevice device = env.device;
Allocator& allocator = *env.allocator;
const deUint32 width = testParams.width;
const deUint32 height = testParams.height;
std::vector<tcu::Vec4> vertices;
switch (testParams.stage)
{
case VK_SHADER_STAGE_VERTEX_BIT:
{
const float z = 0.0f;
const float w = 1.0f;
vertices.reserve(3 * height * width);
for (deUint32 y = 0; y < height; ++y)
for (deUint32 x = 0; x < width; ++x)
{
const float x0 = float(x + 0) / float(width);
const float y0 = float(y + 0) / float(height);
const float x1 = float(x + 1) / float(width);
const float y1 = float(y + 1) / float(height);
const float xm = (x0 + x1) / 2.0f;
const float ym = (y0 + y1) / 2.0f;
vertices.push_back(tcu::Vec4(x0, y0, z, w));
vertices.push_back(tcu::Vec4(xm, y1, z, w));
vertices.push_back(tcu::Vec4(x1, ym, z, w));
}
break;
}
case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
{
const float z = 0.0f;
const float w = 1.0f;
const tcu::Vec4 a = tcu::Vec4(-1.0f, -1.0f, z, w);
const tcu::Vec4 b = tcu::Vec4(+1.0f, -1.0f, z, w);
const tcu::Vec4 c = tcu::Vec4(+1.0f, +1.0f, z, w);
const tcu::Vec4 d = tcu::Vec4(-1.0f, +1.0f, z, w);
vertices.push_back(a);
vertices.push_back(b);
vertices.push_back(c);
vertices.push_back(d);
break;
}
case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
{
const float z = 0.0f;
const float w = 1.0f;
const tcu::Vec4 a = tcu::Vec4(-1.0f, -1.0f, z, w);
const tcu::Vec4 b = tcu::Vec4(+1.0f, -1.0f, z, w);
const tcu::Vec4 c = tcu::Vec4(+1.0f, +1.0f, z, w);
const tcu::Vec4 d = tcu::Vec4(-1.0f, +1.0f, z, w);
vertices.push_back(a);
vertices.push_back(b);
vertices.push_back(c);
vertices.push_back(d);
break;
}
case VK_SHADER_STAGE_GEOMETRY_BIT:
{
const float z = 0.0f;
const float w = 1.0f;
vertices.reserve(3 * height * width);
for (deUint32 y = 0; y < height; ++y)
for (deUint32 x = 0; x < width; ++x)
{
const float x0 = float(x + 0) / float(width);
const float y0 = float(y + 0) / float(height);
const float x1 = float(x + 1) / float(width);
const float y1 = float(y + 1) / float(height);
const float xm = (x0 + x1) / 2.0f;
const float ym = (y0 + y1) / 2.0f;
vertices.push_back(tcu::Vec4(x0, y0, z, w));
vertices.push_back(tcu::Vec4(xm, y1, z, w));
vertices.push_back(tcu::Vec4(x1, ym, z, w));
}
break;
}
case VK_SHADER_STAGE_FRAGMENT_BIT:
{
const float z = 1.0f;
const float w = 1.0f;
const tcu::Vec4 a = tcu::Vec4(-1.0f, -1.0f, z, w);
const tcu::Vec4 b = tcu::Vec4(+1.0f, -1.0f, z, w);
const tcu::Vec4 c = tcu::Vec4(-1.0f, +1.0f, z, w);
const tcu::Vec4 d = tcu::Vec4(+1.0f, +1.0f, z, w);
vertices.push_back(a);
vertices.push_back(b);
vertices.push_back(c);
vertices.push_back(b);
vertices.push_back(c);
vertices.push_back(d);
break;
}
default:
TCU_THROW(InternalError, "Unknown stage");
}
// Initialize vertex buffer
{
const VkDeviceSize vertexBufferSize = sizeof(vertices[0][0]) * vertices[0].SIZE * vertices.size();
const VkBufferCreateInfo vertexBufferCreateInfo = makeBufferCreateInfo(vertexBufferSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
m_vertexCount = static_cast<deUint32>(vertices.size());
m_vertexBuffer = createBuffer(vkd, device, &vertexBufferCreateInfo);
m_vertexBufferAlloc = bindBuffer(vkd, device, allocator, *m_vertexBuffer, vk::MemoryRequirement::HostVisible);
deMemcpy(m_vertexBufferAlloc->getHostPtr(), vertices.data(), (size_t)vertexBufferSize);
flushAlloc(vkd, device, *m_vertexBufferAlloc);
}
}
Move<VkPipeline> GraphicsConfiguration::makeGraphicsPipeline(const TestEnvironment& env,
TestParams& testParams)
{
const DeviceInterface& vkd = *env.vkd;
const VkDevice device = env.device;
const bool tessStageTest = (testParams.stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT || testParams.stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);
const VkPrimitiveTopology topology = tessStageTest ? VK_PRIMITIVE_TOPOLOGY_PATCH_LIST : VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
const deUint32 patchControlPoints = tessStageTest ? 4 : 0;
const std::vector<VkViewport> viewports(1, makeViewport(testParams.width, testParams.height));
const std::vector<VkRect2D> scissors(1, makeRect2D(testParams.width, testParams.height));
return vk::makeGraphicsPipeline(vkd,
device,
*m_pipelineLayout,
*m_vertShaderModule,
*m_tescShaderModule,
*m_teseShaderModule,
*m_geomShaderModule,
*m_fragShaderModule,
*m_renderPass,
viewports,
scissors,
topology,
0,
patchControlPoints);
}
void GraphicsConfiguration::initConfiguration(const TestEnvironment& env,
TestParams& testParams)
{
const DeviceInterface& vkd = *env.vkd;
const VkDevice device = env.device;
Allocator& allocator = *env.allocator;
vk::BinaryCollection& collection = *env.binaryCollection;
VkShaderStageFlags shaders = static_cast<VkShaderStageFlags>(0);
deUint32 shaderCount = 0;
if (collection.contains("vert")) shaders |= VK_SHADER_STAGE_VERTEX_BIT;
if (collection.contains("geom")) shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
if (collection.contains("tesc")) shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
if (collection.contains("tese")) shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
if (collection.contains("frag")) shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
for (BinaryCollection::Iterator it = collection.begin(); it != collection.end(); ++it)
shaderCount++;
if (shaderCount != (deUint32)dePop32(shaders))
TCU_THROW(InternalError, "Unused shaders detected in the collection");
if (0 != (shaders & VK_SHADER_STAGE_VERTEX_BIT)) m_vertShaderModule = createShaderModule(vkd, device, collection.get("vert"), 0);
if (0 != (shaders & VK_SHADER_STAGE_GEOMETRY_BIT)) m_geomShaderModule = createShaderModule(vkd, device, collection.get("geom"), 0);
if (0 != (shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT)) m_tescShaderModule = createShaderModule(vkd, device, collection.get("tesc"), 0);
if (0 != (shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) m_teseShaderModule = createShaderModule(vkd, device, collection.get("tese"), 0);
if (0 != (shaders & VK_SHADER_STAGE_FRAGMENT_BIT)) m_fragShaderModule = createShaderModule(vkd, device, collection.get("frag"), 0);
m_descriptorSetLayout = DescriptorSetLayoutBuilder()
.addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_ALL_GRAPHICS)
.addSingleBinding(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, VK_SHADER_STAGE_ALL_GRAPHICS)
.build(vkd, device);
m_descriptorPool = DescriptorPoolBuilder()
.addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE)
.addType(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR)
.build(vkd, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u);
m_descriptorSet = makeDescriptorSet(vkd, device, *m_descriptorPool, *m_descriptorSetLayout);
m_framebufferImage = makeImage(vkd, device, makeImageCreateInfo(m_framebufferFormat, testParams.width, testParams.height, 1u, VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT));
m_framebufferImageAlloc = bindImage(vkd, device, allocator, *m_framebufferImage, MemoryRequirement::Any);
m_framebufferAttachment = makeImageView(vkd, device, *m_framebufferImage, VK_IMAGE_VIEW_TYPE_2D, m_framebufferFormat, makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u));
m_renderPass = makeRenderPass(vkd, device, m_framebufferFormat);
m_framebuffer = makeFramebuffer(vkd, device, *m_renderPass, *m_framebufferAttachment, testParams.width, testParams.height);
m_pipelineLayout = makePipelineLayout(vkd, device, m_descriptorSetLayout.get());
m_pipeline = makeGraphicsPipeline(env, testParams);
initVertexBuffer(env, testParams);
}
void GraphicsConfiguration::fillCommandBuffer(const TestEnvironment& env,
TestParams& testParams,
VkCommandBuffer cmdBuffer,
const VkAccelerationStructureKHR* rayQueryTopAccelerationStructurePtr,
const VkDescriptorImageInfo& resultImageInfo)
{
const DeviceInterface& vkd = *env.vkd;
const VkDevice device = env.device;
const VkDeviceSize vertexBufferOffset = 0;
const VkWriteDescriptorSetAccelerationStructureKHR rayQueryAccelerationStructureWriteDescriptorSet =
{
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR, // VkStructureType sType;
DE_NULL, // const void* pNext;
1u, // deUint32 accelerationStructureCount;
rayQueryTopAccelerationStructurePtr, // const VkAccelerationStructureKHR* pAccelerationStructures;
};
DescriptorSetUpdateBuilder()
.writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &resultImageInfo)
.writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, &rayQueryAccelerationStructureWriteDescriptorSet)
.update(vkd, device);
vkd.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0, 1, &m_descriptorSet.get(), 0, DE_NULL);
vkd.cmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
vkd.cmdBindVertexBuffers(cmdBuffer, 0u, 1u, &m_vertexBuffer.get(), &vertexBufferOffset);
beginRenderPass(vkd, cmdBuffer, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, testParams.width, testParams.height), tcu::UVec4());
vkd.cmdDraw(cmdBuffer, m_vertexCount, 1u, 0u, 0u);
endRenderPass(vkd, cmdBuffer);
}
class ComputeConfiguration : public PipelineConfiguration
{
public:
ComputeConfiguration();
virtual ~ComputeConfiguration() {}
static void checkSupport(Context& context,
const TestParams& testParams);
static void initPrograms(SourceCollections& programCollection,
const TestParams& testParams);
virtual void initConfiguration(const TestEnvironment& env,
TestParams& testParams) override;
virtual void fillCommandBuffer(const TestEnvironment& env,
TestParams& testParams,
VkCommandBuffer commandBuffer,
const VkAccelerationStructureKHR* rayQueryTopAccelerationStructurePtr,
const VkDescriptorImageInfo& resultImageInfo) override;
protected:
Move<VkDescriptorSetLayout> m_descriptorSetLayout;
Move<VkDescriptorPool> m_descriptorPool;
Move<VkDescriptorSet> m_descriptorSet;
Move<VkPipelineLayout> m_pipelineLayout;
Move<VkShaderModule> m_shaderModule;
Move<VkPipeline> m_pipeline;
};
ComputeConfiguration::ComputeConfiguration()
: PipelineConfiguration()
, m_descriptorSetLayout()
, m_descriptorPool()
, m_descriptorSet()
, m_pipelineLayout()
, m_shaderModule()
, m_pipeline()
{
}
void ComputeConfiguration::checkSupport(Context& context,
const TestParams& testParams)
{
DE_UNREF(context);
DE_UNREF(testParams);
}
void ComputeConfiguration::initPrograms(SourceCollections& programCollection,
const TestParams& testParams)
{
DE_ASSERT(testParams.stage == VK_SHADER_STAGE_COMPUTE_BIT);
if (testParams.isSPIRV)
{
const vk::SpirVAsmBuildOptions spvBuildOptions(programCollection.usedVulkanVersion, vk::SPIRV_VERSION_1_4, true);
programCollection.spirvAsmSources.add("comp") << testParams.testConfigShaderBodyText(testParams) << spvBuildOptions;
}
else
{
const vk::ShaderBuildOptions buildOptions(programCollection.usedVulkanVersion, vk::SPIRV_VERSION_1_4, 0u, true);
const std::string testShaderBody = testParams.testConfigShaderBodyText(testParams);
const std::string testBody =
" ivec3 pos = ivec3(gl_WorkGroupID);\n"
" ivec3 size = ivec3(gl_NumWorkGroups);\n"
+ testShaderBody;
std::stringstream css;
css <<
"#version 460 core\n"
"#extension GL_EXT_ray_query : require\n"
"layout(set = 0, binding = 0, r32i) uniform iimage3D result;\n"
"layout(set = 0, binding = 1) uniform accelerationStructureEXT rayQueryTopLevelAccelerationStructure;\n"
"\n"
"void main()\n"
"{\n"
<< testBody <<
"}\n";
programCollection.glslSources.add("comp") << glu::ComputeSource(updateRayTracingGLSL(css.str())) << buildOptions;
}
}
void ComputeConfiguration::initConfiguration(const TestEnvironment& env,
TestParams& testParams)
{
DE_UNREF(testParams);
const DeviceInterface& vkd = *env.vkd;
const VkDevice device = env.device;
vk::BinaryCollection& collection = *env.binaryCollection;
m_descriptorSetLayout = DescriptorSetLayoutBuilder()
.addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_COMPUTE_BIT)
.addSingleBinding(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, VK_SHADER_STAGE_COMPUTE_BIT)
.build(vkd, device);
m_descriptorPool = DescriptorPoolBuilder()
.addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE)
.addType(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR)
.build(vkd, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u);
m_descriptorSet = makeDescriptorSet(vkd, device, *m_descriptorPool, *m_descriptorSetLayout);
m_pipelineLayout = makePipelineLayout(vkd, device, m_descriptorSetLayout.get());
m_shaderModule = createShaderModule(vkd, device, collection.get("comp"), 0);
m_pipeline = makeComputePipeline(vkd, device, *m_pipelineLayout, *m_shaderModule);
}
void ComputeConfiguration::fillCommandBuffer(const TestEnvironment& env,
TestParams& testParams,
VkCommandBuffer cmdBuffer,
const VkAccelerationStructureKHR* rayQueryTopAccelerationStructurePtr,
const VkDescriptorImageInfo& resultImageInfo)
{
const DeviceInterface& vkd = *env.vkd;
const VkDevice device = env.device;
const VkWriteDescriptorSetAccelerationStructureKHR rayQueryAccelerationStructureWriteDescriptorSet =
{
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR, // VkStructureType sType;
DE_NULL, // const void* pNext;
1u, // deUint32 accelerationStructureCount;
rayQueryTopAccelerationStructurePtr, // const VkAccelerationStructureKHR* pAccelerationStructures;
};
DescriptorSetUpdateBuilder()
.writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &resultImageInfo)
.writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, &rayQueryAccelerationStructureWriteDescriptorSet)
.update(vkd, device);
vkd.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *m_pipelineLayout, 0, 1, &m_descriptorSet.get(), 0, DE_NULL);
vkd.cmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, m_pipeline.get());
vkd.cmdDispatch(cmdBuffer, testParams.width, testParams.height, 1);
}
class RayTracingConfiguration : public PipelineConfiguration
{
public:
RayTracingConfiguration();
virtual ~RayTracingConfiguration() {}
static void checkSupport(Context& context,
const TestParams& testParams);
static void initPrograms(SourceCollections& programCollection,
const TestParams& testParams);
virtual void initConfiguration(const TestEnvironment& env,
TestParams& testParams) override;
virtual void fillCommandBuffer(const TestEnvironment& env,
TestParams& testParams,
VkCommandBuffer commandBuffer,
const VkAccelerationStructureKHR* rayQueryTopAccelerationStructurePtr,
const VkDescriptorImageInfo& resultImageInfo) override;
protected:
de::MovePtr<BufferWithMemory> createShaderBindingTable(const InstanceInterface& vki,
const DeviceInterface& vkd,
const VkDevice device,
const VkPhysicalDevice physicalDevice,
const VkPipeline pipeline,
Allocator& allocator,
de::MovePtr<RayTracingPipeline>& rayTracingPipeline,
const deUint32 group);
protected:
deUint32 m_shaders;
deUint32 m_raygenShaderGroup;
deUint32 m_missShaderGroup;
deUint32 m_hitShaderGroup;
deUint32 m_callableShaderGroup;
deUint32 m_shaderGroupCount;
Move<VkDescriptorSetLayout> m_descriptorSetLayout;
Move<VkDescriptorPool> m_descriptorPool;
Move<VkDescriptorSet> m_descriptorSet;
Move<VkPipelineLayout> m_pipelineLayout;
de::MovePtr<RayTracingPipeline> m_rayTracingPipeline;
Move<VkPipeline> m_pipeline;
de::MovePtr<BufferWithMemory> m_raygenShaderBindingTable;
de::MovePtr<BufferWithMemory> m_hitShaderBindingTable;
de::MovePtr<BufferWithMemory> m_missShaderBindingTable;
de::MovePtr<BufferWithMemory> m_callableShaderBindingTable;
VkStridedDeviceAddressRegionKHR m_raygenShaderBindingTableRegion;
VkStridedDeviceAddressRegionKHR m_missShaderBindingTableRegion;
VkStridedDeviceAddressRegionKHR m_hitShaderBindingTableRegion;
VkStridedDeviceAddressRegionKHR m_callableShaderBindingTableRegion;
de::SharedPtr<BottomLevelAccelerationStructure> m_bottomLevelAccelerationStructure;
de::SharedPtr<TopLevelAccelerationStructure> m_topLevelAccelerationStructure;
};
RayTracingConfiguration::RayTracingConfiguration()
: m_shaders(0)
, m_raygenShaderGroup(~0u)
, m_missShaderGroup(~0u)
, m_hitShaderGroup(~0u)
, m_callableShaderGroup(~0u)
, m_shaderGroupCount(0)
, m_descriptorSetLayout()
, m_descriptorPool()
, m_descriptorSet()
, m_pipelineLayout()
, m_rayTracingPipeline()
, m_pipeline()
, m_raygenShaderBindingTable()
, m_hitShaderBindingTable()
, m_missShaderBindingTable()
, m_callableShaderBindingTable()
, m_raygenShaderBindingTableRegion()
, m_missShaderBindingTableRegion()
, m_hitShaderBindingTableRegion()
, m_callableShaderBindingTableRegion()
, m_bottomLevelAccelerationStructure()
, m_topLevelAccelerationStructure()
{
}
void RayTracingConfiguration::checkSupport(Context& context,
const TestParams& testParams)
{
DE_UNREF(testParams);
context.requireDeviceFunctionality("VK_KHR_ray_tracing_pipeline");
const VkPhysicalDeviceRayTracingPipelineFeaturesKHR& rayTracingPipelineFeaturesKHR = context.getRayTracingPipelineFeatures();
if (rayTracingPipelineFeaturesKHR.rayTracingPipeline == DE_FALSE)
TCU_THROW(NotSupportedError, "Requires VkPhysicalDeviceRayTracingPipelineFeaturesKHR.rayTracingPipeline");
}
void RayTracingConfiguration::initPrograms(SourceCollections& programCollection,
const TestParams& testParams)
{
const vk::ShaderBuildOptions buildOptions(programCollection.usedVulkanVersion, vk::SPIRV_VERSION_1_4, 0u, true);
const std::string testShaderBody = testParams.testConfigShaderBodyText(testParams);
const std::string testBody =
" ivec3 pos = ivec3(gl_LaunchIDEXT);\n"
" ivec3 size = ivec3(gl_LaunchSizeEXT);\n"
+ testShaderBody;
switch (testParams.stage)
{
case VK_SHADER_STAGE_RAYGEN_BIT_KHR:
{
std::stringstream css;
css <<
"#version 460 core\n"
"#extension GL_EXT_ray_tracing : require\n"
"#extension GL_EXT_ray_query : require\n"
"layout(set = 0, binding = 0, r32i) uniform iimage3D result;\n"
"layout(set = 0, binding = 2) uniform accelerationStructureEXT rayQueryTopLevelAccelerationStructure;\n"
"\n"
"void main()\n"
"{\n"
<< testBody <<
"}\n";
programCollection.glslSources.add("rgen") << glu::RaygenSource(updateRayTracingGLSL(css.str())) << buildOptions;
break;
}
case VK_SHADER_STAGE_ANY_HIT_BIT_KHR:
{
programCollection.glslSources.add("rgen") << glu::RaygenSource(updateRayTracingGLSL(getCommonRayGenerationShader())) << buildOptions;
{
std::stringstream css;
css <<
"#version 460 core\n"
"#extension GL_EXT_ray_tracing : require\n"
"#extension GL_EXT_ray_query : require\n"
"hitAttributeEXT vec3 attribs;\n"
"layout(location = 0) rayPayloadInEXT vec3 hitValue;\n"
"layout(set = 0, binding = 0, r32i) uniform iimage3D result;\n"
"layout(set = 0, binding = 2) uniform accelerationStructureEXT rayQueryTopLevelAccelerationStructure;\n"
"\n"
"void main()\n"
"{\n"
<< testBody <<
"}\n";
programCollection.glslSources.add("ahit") << glu::AnyHitSource(updateRayTracingGLSL(css.str())) << buildOptions;
}
programCollection.glslSources.add("chit") << glu::ClosestHitSource(updateRayTracingGLSL(getHitPassthrough())) << buildOptions;
programCollection.glslSources.add("miss") << glu::MissSource(updateRayTracingGLSL(getMissPassthrough())) << buildOptions;
break;
}
case VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR:
{
programCollection.glslSources.add("rgen") << glu::RaygenSource(updateRayTracingGLSL(getCommonRayGenerationShader())) << buildOptions;
{
std::stringstream css;
css <<
"#version 460 core\n"
"#extension GL_EXT_ray_tracing : require\n"
"#extension GL_EXT_ray_query : require\n"
"layout(location = 0) rayPayloadInEXT vec3 hitValue;\n"
"hitAttributeEXT vec3 attribs;\n"
"layout(set = 0, binding = 0, r32i) uniform iimage3D result;\n"
"layout(set = 0, binding = 2) uniform accelerationStructureEXT rayQueryTopLevelAccelerationStructure;\n"
"\n"
"void main()\n"
"{\n"
<< testBody <<
"}\n";
programCollection.glslSources.add("chit") << glu::ClosestHitSource(updateRayTracingGLSL(css.str())) << buildOptions;
}
programCollection.glslSources.add("ahit") << glu::AnyHitSource(updateRayTracingGLSL(getHitPassthrough())) << buildOptions;
programCollection.glslSources.add("miss") << glu::MissSource(updateRayTracingGLSL(getMissPassthrough())) << buildOptions;
break;
}
case VK_SHADER_STAGE_INTERSECTION_BIT_KHR:
{
programCollection.glslSources.add("rgen") << glu::RaygenSource(updateRayTracingGLSL(getCommonRayGenerationShader())) << buildOptions;
{
std::stringstream css;
css <<
"#version 460 core\n"
"#extension GL_EXT_ray_tracing : require\n"
"#extension GL_EXT_ray_query : require\n"
"hitAttributeEXT vec3 hitAttribute;\n"
"layout(set = 0, binding = 0, r32i) uniform iimage3D result;\n"
"layout(set = 0, binding = 2) uniform accelerationStructureEXT rayQueryTopLevelAccelerationStructure;\n"
"\n"
"void main()\n"
"{\n"
<< testBody <<
" hitAttribute = vec3(0.0f, 0.0f, 0.0f);\n"
" reportIntersectionEXT(1.0f, 0);\n"
"}\n";
programCollection.glslSources.add("sect") << glu::IntersectionSource(updateRayTracingGLSL(css.str())) << buildOptions;
}
programCollection.glslSources.add("ahit") << glu::AnyHitSource(updateRayTracingGLSL(getHitPassthrough())) << buildOptions;
programCollection.glslSources.add("chit") << glu::ClosestHitSource(updateRayTracingGLSL(getHitPassthrough())) << buildOptions;
programCollection.glslSources.add("miss") << glu::MissSource(updateRayTracingGLSL(getMissPassthrough())) << buildOptions;
break;
}
case VK_SHADER_STAGE_MISS_BIT_KHR:
{
programCollection.glslSources.add("rgen") << glu::RaygenSource(updateRayTracingGLSL(getCommonRayGenerationShader())) << buildOptions;
{
std::stringstream css;
css <<
"#version 460 core\n"
"#extension GL_EXT_ray_tracing : require\n"
"#extension GL_EXT_ray_query : require\n"
"layout(location = 0) rayPayloadInEXT vec3 hitValue;\n"
"layout(set = 0, binding = 0, r32i) uniform iimage3D result;\n"
"layout(set = 0, binding = 2) uniform accelerationStructureEXT rayQueryTopLevelAccelerationStructure;\n"
"\n"
"void main()\n"
"{\n"
<< testBody <<
"}\n";
programCollection.glslSources.add("miss") << glu::MissSource(updateRayTracingGLSL(css.str())) << buildOptions;
}
programCollection.glslSources.add("ahit") << glu::AnyHitSource(updateRayTracingGLSL(getHitPassthrough())) << buildOptions;
programCollection.glslSources.add("chit") << glu::ClosestHitSource(updateRayTracingGLSL(getHitPassthrough())) << buildOptions;
break;
}
case VK_SHADER_STAGE_CALLABLE_BIT_KHR:
{
{
std::stringstream css;
css <<
"#version 460 core\n"
"#extension GL_EXT_ray_tracing : require\n"
"#extension GL_EXT_ray_query : require\n"
"layout(location = 0) callableDataEXT float dummy;"
"layout(set = 0, binding = 1) uniform accelerationStructureEXT topLevelAS;\n"
"\n"
"void main()\n"
"{\n"
" executeCallableEXT(0, 0);\n"
"}\n";
programCollection.glslSources.add("rgen") << glu::RaygenSource(updateRayTracingGLSL(css.str())) << buildOptions;
}
{
std::stringstream css;
css <<
"#version 460 core\n"
"#extension GL_EXT_ray_tracing : require\n"
"#extension GL_EXT_ray_query : require\n"
"layout(location = 0) callableDataInEXT float dummy;"
"layout(set = 0, binding = 0, r32i) uniform iimage3D result;\n"
"layout(set = 0, binding = 2) uniform accelerationStructureEXT rayQueryTopLevelAccelerationStructure;\n"
"\n"
"void main()\n"
"{\n"
<< testBody <<
"}\n";
programCollection.glslSources.add("call") << glu::CallableSource(updateRayTracingGLSL(css.str())) << buildOptions;
}
programCollection.glslSources.add("ahit") << glu::AnyHitSource(updateRayTracingGLSL(getHitPassthrough())) << buildOptions;
programCollection.glslSources.add("chit") << glu::ClosestHitSource(updateRayTracingGLSL(getHitPassthrough())) << buildOptions;
programCollection.glslSources.add("miss") << glu::MissSource(updateRayTracingGLSL(getMissPassthrough())) << buildOptions;
break;
}
default:
TCU_THROW(InternalError, "Unknown stage");
}
}
de::MovePtr<BufferWithMemory> RayTracingConfiguration::createShaderBindingTable(const InstanceInterface& vki,
const DeviceInterface& vkd,
const VkDevice device,
const VkPhysicalDevice physicalDevice,
const VkPipeline pipeline,
Allocator& allocator,
de::MovePtr<RayTracingPipeline>& rayTracingPipeline,
const deUint32 group)
{
de::MovePtr<BufferWithMemory> shaderBindingTable;
if (group < m_shaderGroupCount)
{
const deUint32 shaderGroupHandleSize = getShaderGroupHandleSize(vki, physicalDevice);
const deUint32 shaderGroupBaseAlignment = getShaderGroupBaseAlignment(vki, physicalDevice);
shaderBindingTable = rayTracingPipeline->createShaderBindingTable(vkd, device, pipeline, allocator, shaderGroupHandleSize, shaderGroupBaseAlignment, group, 1u);
}
return shaderBindingTable;
}
void RayTracingConfiguration::initConfiguration(const TestEnvironment& env,
TestParams& testParams)
{
DE_UNREF(testParams);
const InstanceInterface& vki = *env.vki;
const DeviceInterface& vkd = *env.vkd;
const VkDevice device = env.device;
const VkPhysicalDevice physicalDevice = env.physicalDevice;
vk::BinaryCollection& collection = *env.binaryCollection;
Allocator& allocator = *env.allocator;
const deUint32 shaderGroupHandleSize = getShaderGroupHandleSize(vki, physicalDevice);
const VkShaderStageFlags hitStages = VK_SHADER_STAGE_ANY_HIT_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | VK_SHADER_STAGE_INTERSECTION_BIT_KHR;
deUint32 shaderCount = 0;
m_shaderGroupCount = 0;
if (collection.contains("rgen")) m_shaders |= VK_SHADER_STAGE_RAYGEN_BIT_KHR;
if (collection.contains("ahit")) m_shaders |= VK_SHADER_STAGE_ANY_HIT_BIT_KHR;
if (collection.contains("chit")) m_shaders |= VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;
if (collection.contains("miss")) m_shaders |= VK_SHADER_STAGE_MISS_BIT_KHR;
if (collection.contains("sect")) m_shaders |= VK_SHADER_STAGE_INTERSECTION_BIT_KHR;
if (collection.contains("call")) m_shaders |= VK_SHADER_STAGE_CALLABLE_BIT_KHR;
for (BinaryCollection::Iterator it = collection.begin(); it != collection.end(); ++it)
shaderCount++;
if (shaderCount != (deUint32)dePop32(m_shaders))
TCU_THROW(InternalError, "Unused shaders detected in the collection");
if (0 != (m_shaders & VK_SHADER_STAGE_RAYGEN_BIT_KHR))
m_raygenShaderGroup = m_shaderGroupCount++;
if (0 != (m_shaders & VK_SHADER_STAGE_MISS_BIT_KHR))
m_missShaderGroup = m_shaderGroupCount++;
if (0 != (m_shaders & hitStages))
m_hitShaderGroup = m_shaderGroupCount++;
if (0 != (m_shaders & VK_SHADER_STAGE_CALLABLE_BIT_KHR))
m_callableShaderGroup = m_shaderGroupCount++;
m_rayTracingPipeline = de::newMovePtr<RayTracingPipeline>();
m_descriptorSetLayout = DescriptorSetLayoutBuilder()
.addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, ALL_RAY_TRACING_STAGES)
.addSingleBinding(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, ALL_RAY_TRACING_STAGES)
.addSingleBinding(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, ALL_RAY_TRACING_STAGES)
.build(vkd, device);
m_descriptorPool = DescriptorPoolBuilder()
.addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE)
.addType(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR)
.addType(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR)
.build(vkd, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u);
m_descriptorSet = makeDescriptorSet(vkd, device, *m_descriptorPool, *m_descriptorSetLayout);
if (0 != (m_shaders & VK_SHADER_STAGE_RAYGEN_BIT_KHR)) m_rayTracingPipeline->addShader(VK_SHADER_STAGE_RAYGEN_BIT_KHR, createShaderModule(vkd, device, collection.get("rgen"), 0), m_raygenShaderGroup);
if (0 != (m_shaders & VK_SHADER_STAGE_ANY_HIT_BIT_KHR)) m_rayTracingPipeline->addShader(VK_SHADER_STAGE_ANY_HIT_BIT_KHR, createShaderModule(vkd, device, collection.get("ahit"), 0), m_hitShaderGroup);
if (0 != (m_shaders & VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR)) m_rayTracingPipeline->addShader(VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, createShaderModule(vkd, device, collection.get("chit"), 0), m_hitShaderGroup);
if (0 != (m_shaders & VK_SHADER_STAGE_MISS_BIT_KHR)) m_rayTracingPipeline->addShader(VK_SHADER_STAGE_MISS_BIT_KHR, createShaderModule(vkd, device, collection.get("miss"), 0), m_missShaderGroup);
if (0 != (m_shaders & VK_SHADER_STAGE_INTERSECTION_BIT_KHR)) m_rayTracingPipeline->addShader(VK_SHADER_STAGE_INTERSECTION_BIT_KHR, createShaderModule(vkd, device, collection.get("sect"), 0), m_hitShaderGroup);
if (0 != (m_shaders & VK_SHADER_STAGE_CALLABLE_BIT_KHR)) m_rayTracingPipeline->addShader(VK_SHADER_STAGE_CALLABLE_BIT_KHR, createShaderModule(vkd, device, collection.get("call"), 0), m_callableShaderGroup);
m_pipelineLayout = makePipelineLayout(vkd, device, m_descriptorSetLayout.get());
m_pipeline = m_rayTracingPipeline->createPipeline(vkd, device, *m_pipelineLayout);
m_raygenShaderBindingTable = createShaderBindingTable(vki, vkd, device, physicalDevice, *m_pipeline, allocator, m_rayTracingPipeline, m_raygenShaderGroup);
m_missShaderBindingTable = createShaderBindingTable(vki, vkd, device, physicalDevice, *m_pipeline, allocator, m_rayTracingPipeline, m_missShaderGroup);
m_hitShaderBindingTable = createShaderBindingTable(vki, vkd, device, physicalDevice, *m_pipeline, allocator, m_rayTracingPipeline, m_hitShaderGroup);
m_callableShaderBindingTable = createShaderBindingTable(vki, vkd, device, physicalDevice, *m_pipeline, allocator, m_rayTracingPipeline, m_callableShaderGroup);
m_raygenShaderBindingTableRegion = m_raygenShaderBindingTable.get() != NULL ? makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, m_raygenShaderBindingTable->get(), 0), shaderGroupHandleSize, shaderGroupHandleSize) : makeStridedDeviceAddressRegionKHR(DE_NULL, 0, 0);
m_missShaderBindingTableRegion = m_missShaderBindingTable.get() != NULL ? makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, m_missShaderBindingTable->get(), 0), shaderGroupHandleSize, shaderGroupHandleSize) : makeStridedDeviceAddressRegionKHR(DE_NULL, 0, 0);
m_hitShaderBindingTableRegion = m_hitShaderBindingTable.get() != NULL ? makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, m_hitShaderBindingTable->get(), 0), shaderGroupHandleSize, shaderGroupHandleSize) : makeStridedDeviceAddressRegionKHR(DE_NULL, 0, 0);
m_callableShaderBindingTableRegion = m_callableShaderBindingTable.get() != NULL ? makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, m_callableShaderBindingTable->get(), 0), shaderGroupHandleSize, shaderGroupHandleSize) : makeStridedDeviceAddressRegionKHR(DE_NULL, 0, 0);
}
void RayTracingConfiguration::fillCommandBuffer(const TestEnvironment& env,
TestParams& testParams,
VkCommandBuffer commandBuffer,
const VkAccelerationStructureKHR* rayQueryTopAccelerationStructurePtr,
const VkDescriptorImageInfo& resultImageInfo)
{
const DeviceInterface& vkd = *env.vkd;
const VkDevice device = env.device;
Allocator& allocator = *env.allocator;
de::MovePtr<BottomLevelAccelerationStructure> bottomLevelAccelerationStructure = makeBottomLevelAccelerationStructure();
de::MovePtr<TopLevelAccelerationStructure> topLevelAccelerationStructure = makeTopLevelAccelerationStructure();
m_bottomLevelAccelerationStructure = de::SharedPtr<BottomLevelAccelerationStructure>(bottomLevelAccelerationStructure.release());
m_bottomLevelAccelerationStructure->setDefaultGeometryData(testParams.stage);
m_bottomLevelAccelerationStructure->createAndBuild(vkd, device, commandBuffer, allocator);
m_topLevelAccelerationStructure = de::SharedPtr<TopLevelAccelerationStructure>(topLevelAccelerationStructure.release());
m_topLevelAccelerationStructure->setInstanceCount(1);
m_topLevelAccelerationStructure->addInstance(m_bottomLevelAccelerationStructure);
m_topLevelAccelerationStructure->createAndBuild(vkd, device, commandBuffer, allocator);
const TopLevelAccelerationStructure* topLevelAccelerationStructurePtr = m_topLevelAccelerationStructure.get();
const VkWriteDescriptorSetAccelerationStructureKHR accelerationStructureWriteDescriptorSet =
{
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR, // VkStructureType sType;
DE_NULL, // const void* pNext;
1u, // deUint32 accelerationStructureCount;
topLevelAccelerationStructurePtr->getPtr(), // const VkAccelerationStructureKHR* pAccelerationStructures;
};
const VkWriteDescriptorSetAccelerationStructureKHR rayQueryAccelerationStructureWriteDescriptorSet =
{
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR, // VkStructureType sType;
DE_NULL, // const void* pNext;
1u, // deUint32 accelerationStructureCount;
rayQueryTopAccelerationStructurePtr, // const VkAccelerationStructureKHR* pAccelerationStructures;
};
DescriptorSetUpdateBuilder()
.writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &resultImageInfo)
.writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, &accelerationStructureWriteDescriptorSet)
.writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(2u), VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, &rayQueryAccelerationStructureWriteDescriptorSet)
.update(vkd, device);
vkd.cmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, *m_pipelineLayout, 0, 1, &m_descriptorSet.get(), 0, DE_NULL);
vkd.cmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, m_pipeline.get());
cmdTraceRays(vkd,
commandBuffer,
&m_raygenShaderBindingTableRegion,
&m_missShaderBindingTableRegion,
&m_hitShaderBindingTableRegion,
&m_callableShaderBindingTableRegion,
testParams.width, testParams.height, 1);
}
void TestConfiguration::prepareTestEnvironment (Context& context)
{
// By default, all data comes from the context.
m_testEnvironment = de::MovePtr<TestEnvironment>(new TestEnvironment
{
&context.getInstanceInterface(), // const InstanceInterface* vki;
context.getPhysicalDevice(), // VkPhysicalDevice physicalDevice;
&context.getDeviceInterface(), // const DeviceInterface* vkd;
context.getDevice(), // VkDevice device;
&context.getDefaultAllocator(), // Allocator* allocator;
context.getUniversalQueue(), // VkQueue queue;
context.getUniversalQueueFamilyIndex(), // deUint32 queueFamilyIndex;
&context.getBinaryCollection(), // BinaryCollection* binaryCollection;
&context.getTestContext().getLog(), // tcu::TestLog* log;
});
}
const TestEnvironment& TestConfiguration::getTestEnvironment () const
{
return *m_testEnvironment;
}
bool TestConfiguration::verify(BufferWithMemory* resultBuffer, TestParams& testParams)
{
tcu::TestLog& log = *(m_testEnvironment->log);
const deUint32 width = testParams.width;
const deUint32 height = testParams.height;
const deInt32* resultPtr = (deInt32*)resultBuffer->getAllocation().getHostPtr();
const deInt32* expectedPtr = m_expected.data();
deUint32 failures = 0;
deUint32 pos = 0;
for (deUint32 y = 0; y < height; ++y)
for (deUint32 x = 0; x < width; ++x)
{
if (resultPtr[pos] != expectedPtr[pos])
failures++;
pos++;
}
if (failures != 0)
{
const char* names[] = { "Retrieved:", "Expected:" };
for (deUint32 n = 0; n < 2; ++n)
{
std::stringstream css;
pos = 0;
for (deUint32 y = 0; y < height; ++y)
{
for (deUint32 x = 0; x < width; ++x)
{
if (resultPtr[pos] != expectedPtr[pos])
css << std::setw(12) << (n == 0 ? resultPtr[pos] : expectedPtr[pos]) << ",";
else
css << "____________,";
pos++;
}
css << std::endl;
}
log << tcu::TestLog::Message << names[n] << tcu::TestLog::EndMessage;
log << tcu::TestLog::Message << css.str() << tcu::TestLog::EndMessage;
}
}
return (failures == 0);
}
bool TestConfigurationFloat::verify(BufferWithMemory* resultBuffer, TestParams& testParams)
{
tcu::TestLog& log = *(m_testEnvironment->log);
const float eps = float(FIXED_POINT_ALLOWED_ERROR) / float(FIXED_POINT_DIVISOR);
const deUint32 width = testParams.width;
const deUint32 height = testParams.height;
const deInt32* resultPtr = (deInt32*)resultBuffer->getAllocation().getHostPtr();
const deInt32* expectedPtr = m_expected.data();
deUint32 failures = 0;
deUint32 pos = 0;
for (deUint32 y = 0; y < height; ++y)
for (deUint32 x = 0; x < width; ++x)
{
const float retrievedValue = float(resultPtr[pos]) / float(FIXED_POINT_DIVISOR);
const float expectedValue = float(expectedPtr[pos]) / float(FIXED_POINT_DIVISOR);
if (deFloatAbs(retrievedValue - expectedValue) > eps)
failures++;
pos++;
}
if (failures != 0)
{
const char* names[] = { "Retrieved:", "Expected:" };
for (deUint32 n = 0; n < 2; ++n)
{
std::stringstream css;
pos = 0;
for (deUint32 y = 0; y < height; ++y)
{
for (deUint32 x = 0; x < width; ++x)
{
const float retrievedValue = float(resultPtr[pos]) / float(FIXED_POINT_DIVISOR);
const float expectedValue = float(expectedPtr[pos]) / float(FIXED_POINT_DIVISOR);
if (deFloatAbs(retrievedValue - expectedValue) > eps)
css << std::setprecision(8) << std::setw(12) << (n == 0 ? retrievedValue : expectedValue) << ",";
else
css << "____________,";
pos++;
}
css << std::endl;
}
log << tcu::TestLog::Message << names[n] << tcu::TestLog::EndMessage;
log << tcu::TestLog::Message << css.str() << tcu::TestLog::EndMessage;
}
}
return (failures == 0);
}
bool TestConfigurationVector::verify(BufferWithMemory* resultBuffer, TestParams& testParams)
{
tcu::TestLog& log = *(m_testEnvironment->log);
const float eps = float(FIXED_POINT_ALLOWED_ERROR) / float(FIXED_POINT_DIVISOR);
const deUint32 width = testParams.width;
const deUint32 height = testParams.height;
const deUint32 depth = 3u; // vec3
const deInt32* resultPtr = (deInt32*)resultBuffer->getAllocation().getHostPtr();
const deInt32* expectedPtr = m_expected.data();
deUint32 failures = 0;
deUint32 pos = 0;
if (m_useStrictComponentMatching)
{
for (deUint32 z = 0; z < depth; ++z)
{
for (deUint32 y = 0; y < height; ++y)
{
for (deUint32 x = 0; x < width; ++x)
{
const float retrievedValue = float(resultPtr[pos]) / float(FIXED_POINT_DIVISOR);
const float expectedValue = float(expectedPtr[pos]) / float(FIXED_POINT_DIVISOR);
if (deFloatAbs(retrievedValue - expectedValue) > eps)
failures++;
++pos;
}
}
}
}
else
{
// This path is taken for barycentric coords, which can be returned in any order.
//
// We need to ensure that:
// 1. Each component value found in the retrieved value has a match in the expected value vec.
// 2. Only one mapping exists per each component in the expected value vec.
const auto nSquares = width * height;
for (deUint32 y = 0; y < height; ++y)
{
for (deUint32 x = 0; x < width; ++x)
{
bool expectedVectorComponentUsed[3] = { false };
const auto squareNdx = y * width + x;
for (deUint32 retrievedComponentNdx = 0; retrievedComponentNdx < 3 /* vec3 */; ++retrievedComponentNdx)
{
const float retrievedValue = float(resultPtr[nSquares * retrievedComponentNdx + squareNdx]) / float(FIXED_POINT_DIVISOR);
for (deUint32 expectedComponentNdx = 0; expectedComponentNdx < 3 /* vec3 */; ++expectedComponentNdx)
{
const float expectedValue = float(expectedPtr[nSquares * expectedComponentNdx + squareNdx]) / float(FIXED_POINT_DIVISOR);
if (deFloatAbs(retrievedValue - expectedValue) <= eps &&
expectedVectorComponentUsed[expectedComponentNdx] == false)
{
expectedVectorComponentUsed[expectedComponentNdx] = true;
break;
}
++pos;
}
}
if (expectedVectorComponentUsed[0] == false ||
expectedVectorComponentUsed[1] == false ||
expectedVectorComponentUsed[2] == false)
{
++failures;
}
}
}
}
if (failures != 0)
{
const char* names[] = {
"Retrieved",
(m_useStrictComponentMatching) ? "Expected"
: "Expected (component order is irrelevant)"
};
std::stringstream css;
for (deUint32 y = 0; y < height; ++y)
{
for (deUint32 x = 0; x < width; ++x)
{
for (deUint32 n = 0; n < 2; ++n)
{
css << names[n] << " at (" << x << "," << y << ") {";
for (deUint32 z = 0; z < depth; ++z)
{
pos = x + width * (y + height * z);
const float retrievedValue = float(resultPtr[pos]) / float(FIXED_POINT_DIVISOR);
const float expectedValue = float(expectedPtr[pos]) / float(FIXED_POINT_DIVISOR);
if (deFloatAbs(retrievedValue - expectedValue) > eps ||
m_useStrictComponentMatching == false)
{
css << std::setprecision(8) << std::setw(12) << (n == 0 ? retrievedValue : expectedValue) << ",";
}
else
css << "____________,";
}
css << "}" << std::endl;
}
}
}
log << tcu::TestLog::Message << css.str() << tcu::TestLog::EndMessage;
}
return failures == 0;
}
bool TestConfigurationMatrix::verify(BufferWithMemory* resultBuffer, TestParams& testParams)
{
tcu::TestLog& log = *(m_testEnvironment->log);
const float eps = float(FIXED_POINT_ALLOWED_ERROR) / float(FIXED_POINT_DIVISOR);
const deUint32 width = testParams.width;
const deUint32 height = testParams.height;
const deUint32 depth = 12u; // mat3x4 or mat4x3
const deInt32* resultPtr = (deInt32*)resultBuffer->getAllocation().getHostPtr();
const deInt32* expectedPtr = m_expected.data();
deUint32 failures = 0;
deUint32 pos = 0;
for (deUint32 z = 0; z < depth; ++z)
for (deUint32 y = 0; y < height; ++y)
for (deUint32 x = 0; x < width; ++x)
{
const float retrievedValue = float(resultPtr[pos]) / float(FIXED_POINT_DIVISOR);
const float expectedValue = float(expectedPtr[pos]) / float(FIXED_POINT_DIVISOR);
if (deFloatAbs(retrievedValue - expectedValue) > eps)
failures++;
++pos;
}
if (failures != 0)
{
const char* names[] = { "Retrieved", "Expected" };
std::stringstream css;
for (deUint32 y = 0; y < height; ++y)
{
for (deUint32 x = 0; x < width; ++x)
{
css << "At (" << x << "," << y << ")" << std::endl;
for (deUint32 n = 0; n < 2; ++n)
{
css << names[n] << std::endl << "{" << std::endl;
for (deUint32 z = 0; z < depth; ++z)
{
pos = x + width * (y + height * z);
const float retrievedValue = float(resultPtr[pos]) / float(FIXED_POINT_DIVISOR);
const float expectedValue = float(expectedPtr[pos]) / float(FIXED_POINT_DIVISOR);
if (z % 4 == 0)
css << " {";
if (deFloatAbs(retrievedValue - expectedValue) > eps)
css << std::setprecision(5) << std::setw(9) << (n == 0 ? retrievedValue : expectedValue) << ",";
else
css << "_________,";
if (z % 4 == 3)
css << "}" << std::endl;
}
css << "}" << std::endl;
}
}
}
log << tcu::TestLog::Message << css.str() << tcu::TestLog::EndMessage;
}
return failures == 0;
}
class TestConfigurationFlow : public TestConfiguration
{
public:
TestConfigurationFlow (Context& context) : TestConfiguration(context) {}
static const std::string getShaderBodyText(const TestParams& testParams);
virtual const VkAccelerationStructureKHR* initAccelerationStructures(TestParams& testParams,
VkCommandBuffer cmdBuffer) override;
};
const VkAccelerationStructureKHR* TestConfigurationFlow::initAccelerationStructures(TestParams& testParams,
VkCommandBuffer cmdBuffer)
{
const DeviceInterface& vkd = *m_testEnvironment->vkd;
const VkDevice device = m_testEnvironment->device;
Allocator& allocator = *m_testEnvironment->allocator;
const deUint32 width = testParams.width;
const deUint32 height = testParams.height;
const deUint32 instancesGroupCount = testParams.instancesGroupCount;
const deUint32 geometriesGroupCount = testParams.geometriesGroupCount;
const deUint32 squaresGroupCount = testParams.squaresGroupCount;
const bool triangles = (testParams.geomType == GEOM_TYPE_TRIANGLES);
const float z = -1.0f;
tcu::UVec2 startPos = tcu::UVec2(0, 0);
de::MovePtr<TopLevelAccelerationStructure> rayQueryTopLevelAccelerationStructure = makeTopLevelAccelerationStructure();
m_topAccelerationStructure = de::SharedPtr<TopLevelAccelerationStructure>(rayQueryTopLevelAccelerationStructure.release());
m_expected = std::vector<deInt32>(width * height, 1);
m_topAccelerationStructure->setInstanceCount(instancesGroupCount);
for (size_t instanceNdx = 0; instanceNdx < instancesGroupCount; ++instanceNdx)
{
de::MovePtr<BottomLevelAccelerationStructure> rayQueryBottomLevelAccelerationStructure = makeBottomLevelAccelerationStructure();
for (size_t geometryNdx = 0; geometryNdx < geometriesGroupCount; ++geometryNdx)
{
std::vector<tcu::Vec3> geometryData;
geometryData.reserve(squaresGroupCount * (triangles ? 3u : 2u));
for (size_t squareNdx = 0; squareNdx < squaresGroupCount; ++squareNdx)
{
const deUint32 n = width * startPos.y() + startPos.x();
const deUint32 m = n + 1;
const float x0 = float(startPos.x() + 0) / float(width);
const float y0 = float(startPos.y() + 0) / float(height);
const float x1 = float(startPos.x() + 1) / float(width);
const float y1 = float(startPos.y() + 1) / float(height);
if (triangles)
{
const float xm = (x0 + x1) / 2.0f;
const float ym = (y0 + y1) / 2.0f;
geometryData.push_back(tcu::Vec3(x0, y0, z));
geometryData.push_back(tcu::Vec3(xm, y1, z));
geometryData.push_back(tcu::Vec3(x1, ym, z));
}
else
{
geometryData.push_back(tcu::Vec3(x0, y0, z));
geometryData.push_back(tcu::Vec3(x1, y1, z * 0.9f));
}
startPos.y() = m / width;
startPos.x() = m % width;
}
rayQueryBottomLevelAccelerationStructure->addGeometry(geometryData, triangles);
}
rayQueryBottomLevelAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, allocator);
m_bottomAccelerationStructures.push_back(de::SharedPtr<BottomLevelAccelerationStructure>(rayQueryBottomLevelAccelerationStructure.release()));
m_topAccelerationStructure->addInstance(m_bottomAccelerationStructures.back());
}
m_topAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, allocator);
return m_topAccelerationStructure.get()->getPtr();
}
const std::string TestConfigurationFlow::getShaderBodyText(const TestParams& testParams)
{
if (testParams.geomType == GEOM_TYPE_AABBS)
{
const std::string result =
" uint rayFlags = 0;\n"
" uint cullMask = 0xFF;\n"
" float tmin = 0.0;\n"
" float tmax = 9.0;\n"
" vec3 origin = vec3((float(pos.x) + 0.5f) / float(size.x), (float(pos.y) + 0.5f) / float(size.y), 0.0);\n"
" vec3 direct = vec3(0.0, 0.0, -1.0);\n"
" uint value = 4;\n"
" rayQueryEXT rayQuery;\n"
"\n"
" rayQueryInitializeEXT(rayQuery, rayQueryTopLevelAccelerationStructure, rayFlags, cullMask, origin, tmin, direct, tmax);\n"
"\n"
" if (rayQueryProceedEXT(rayQuery))\n"
" {\n"
" value--;\n"
" if (rayQueryGetIntersectionTypeEXT(rayQuery, false) == gl_RayQueryCandidateIntersectionAABBEXT)\n"
" {\n"
" value--;\n"
" rayQueryGenerateIntersectionEXT(rayQuery, 0.5f);\n"
"\n"
" rayQueryProceedEXT(rayQuery);\n"
"\n"
" if (rayQueryGetIntersectionTypeEXT(rayQuery, true) == gl_RayQueryCommittedIntersectionGeneratedEXT)\n"
" value--;\n"
" }\n"
" }\n"
"\n"
" imageStore(result, pos, ivec4(value, 0, 0, 0));\n";
return result;
}
else if (testParams.geomType == GEOM_TYPE_TRIANGLES)
{
const std::string result =
" uint rayFlags = gl_RayFlagsNoOpaqueEXT;\n"
" uint cullMask = 0xFF;\n"
" float tmin = 0.0;\n"
" float tmax = 9.0;\n"
" vec3 origin = vec3((float(pos.x) + 0.5f) / float(size.x), (float(pos.y) + 0.5f) / float(size.y), 0.0);\n"
" vec3 direct = vec3(0.0, 0.0, -1.0);\n"
" uint value = 4;\n"
" rayQueryEXT rayQuery;\n"
"\n"
" rayQueryInitializeEXT(rayQuery, rayQueryTopLevelAccelerationStructure, rayFlags, cullMask, origin, tmin, direct, tmax);\n"
"\n"
" if (rayQueryProceedEXT(rayQuery))\n"
" {\n"
" value--;\n"
" if (rayQueryGetIntersectionTypeEXT(rayQuery, false) == gl_RayQueryCandidateIntersectionTriangleEXT)\n"
" {\n"
" value--;\n"
" rayQueryConfirmIntersectionEXT(rayQuery);\n"
"\n"
" rayQueryProceedEXT(rayQuery);\n"
"\n"
" if (rayQueryGetIntersectionTypeEXT(rayQuery, true) == gl_RayQueryCommittedIntersectionTriangleEXT)\n"
" value--;\n"
" }\n"
" }\n"
"\n"
" imageStore(result, pos, ivec4(value, 0, 0, 0));\n";
return result;
}
else
{
TCU_THROW(InternalError, "Unknown geometry type");
}
}
class TestConfigurationPrimitiveId : public TestConfiguration
{
public:
TestConfigurationPrimitiveId (Context& context) : TestConfiguration(context) {}
static const std::string getShaderBodyText(const TestParams& testParams);
virtual const VkAccelerationStructureKHR* initAccelerationStructures(TestParams& testParams,
VkCommandBuffer cmdBuffer) override;
};
const VkAccelerationStructureKHR* TestConfigurationPrimitiveId::initAccelerationStructures(TestParams& testParams,
VkCommandBuffer cmdBuffer)
{
const DeviceInterface& vkd = *m_testEnvironment->vkd;
const VkDevice device = m_testEnvironment->device;
Allocator& allocator = *m_testEnvironment->allocator;
const deUint32 width = testParams.width;
const deUint32 height = testParams.height;
const deUint32 instancesGroupCount = testParams.instancesGroupCount;
const deUint32 geometriesGroupCount = testParams.geometriesGroupCount;
const deUint32 squaresGroupCount = testParams.squaresGroupCount;
const bool triangles = (testParams.geomType == GEOM_TYPE_TRIANGLES);
const float z = -1.0f;
tcu::UVec2 startPos = tcu::UVec2(0, 0);
de::MovePtr<TopLevelAccelerationStructure> rayQueryTopLevelAccelerationStructure = makeTopLevelAccelerationStructure();
DE_ASSERT(instancesGroupCount * geometriesGroupCount * squaresGroupCount == width * height);
m_topAccelerationStructure = de::SharedPtr<TopLevelAccelerationStructure>(rayQueryTopLevelAccelerationStructure.release());
m_topAccelerationStructure->setInstanceCount(instancesGroupCount);
m_expected.resize(width * height);
for (deUint32 instanceNdx = 0; instanceNdx < instancesGroupCount; ++instanceNdx)
{
de::MovePtr<BottomLevelAccelerationStructure> rayQueryBottomLevelAccelerationStructure = makeBottomLevelAccelerationStructure();
for (deUint32 geometryNdx = 0; geometryNdx < geometriesGroupCount; ++geometryNdx)
{
std::vector<tcu::Vec3> geometryData;
geometryData.reserve(squaresGroupCount * (triangles ? 3u : 2u));
for (deUint32 squareNdx = 0; squareNdx < squaresGroupCount; ++squareNdx)
{
const deUint32 n = width * startPos.y() + startPos.x();
const deUint32 m = (n + 11) % (width * height);
const float x0 = float(startPos.x() + 0) / float(width);
const float y0 = float(startPos.y() + 0) / float(height);
const float x1 = float(startPos.x() + 1) / float(width);
const float y1 = float(startPos.y() + 1) / float(height);
if (triangles)
{
const float xm = (x0 + x1) / 2.0f;
const float ym = (y0 + y1) / 2.0f;
geometryData.push_back(tcu::Vec3(x0, y0, z));
geometryData.push_back(tcu::Vec3(xm, y1, z));
geometryData.push_back(tcu::Vec3(x1, ym, z));
}
else
{
geometryData.push_back(tcu::Vec3(x0, y0, z));
geometryData.push_back(tcu::Vec3(x1, y1, z * 0.9f));
}
m_expected[n] = squareNdx;
startPos.y() = m / width;
startPos.x() = m % width;
}
rayQueryBottomLevelAccelerationStructure->addGeometry(geometryData, triangles);
}
rayQueryBottomLevelAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, allocator);
m_bottomAccelerationStructures.push_back(de::SharedPtr<BottomLevelAccelerationStructure>(rayQueryBottomLevelAccelerationStructure.release()));
m_topAccelerationStructure->addInstance(m_bottomAccelerationStructures.back(), identityMatrix3x4, instanceNdx + 1);
}
m_topAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, allocator);
return m_topAccelerationStructure.get()->getPtr();
}
const std::string TestConfigurationPrimitiveId::getShaderBodyText(const TestParams& testParams)
{
if (testParams.geomType == GEOM_TYPE_AABBS)
{
const std::string result =
" uint rayFlags = 0;\n"
" uint cullMask = 0xFF;\n"
" float tmin = 0.0;\n"
" float tmax = 9.0;\n"
" vec3 origin = vec3((float(pos.x) + 0.5f) / float(size.x), (float(pos.y) + 0.5f) / float(size.y), 0.0);\n"
" vec3 direct = vec3(0.0, 0.0, -1.0);\n"
" uint value = -1;\n"
" rayQueryEXT rayQuery;\n"
"\n"
" rayQueryInitializeEXT(rayQuery, rayQueryTopLevelAccelerationStructure, rayFlags, cullMask, origin, tmin, direct, tmax);\n"
"\n"
" if (rayQueryProceedEXT(rayQuery))\n"
" {\n"
" value--;\n"
" if (rayQueryGetIntersectionTypeEXT(rayQuery, false) == gl_RayQueryCandidateIntersectionAABBEXT)\n"
" {\n"
" value--;\n"
" rayQueryGenerateIntersectionEXT(rayQuery, 0.5f);\n"
"\n"
" rayQueryProceedEXT(rayQuery);\n"
"\n"
" if (rayQueryGetIntersectionTypeEXT(rayQuery, true) == gl_RayQueryCommittedIntersectionGeneratedEXT)\n"
" value = rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true);\n"
" }\n"
" }\n"
"\n"
" imageStore(result, pos, ivec4(value, 0, 0, 0));\n";
return result;
}
else if (testParams.geomType == GEOM_TYPE_TRIANGLES)
{
const std::string result =
" uint rayFlags = gl_RayFlagsNoOpaqueEXT;\n"
" uint cullMask = 0xFF;\n"
" float tmin = 0.0;\n"
" float tmax = 9.0;\n"
" vec3 origin = vec3((float(pos.x) + 0.5f) / float(size.x), (float(pos.y) + 0.5f) / float(size.y), 0.0);\n"
" vec3 direct = vec3(0.0, 0.0, -1.0);\n"
" uint value = -1;\n"
" rayQueryEXT rayQuery;\n"
"\n"
" rayQueryInitializeEXT(rayQuery, rayQueryTopLevelAccelerationStructure, rayFlags, cullMask, origin, tmin, direct, tmax);\n"
"\n"
" if (rayQueryProceedEXT(rayQuery))\n"
" {\n"
" value--;\n"
" if (rayQueryGetIntersectionTypeEXT(rayQuery, false) == gl_RayQueryCandidateIntersectionTriangleEXT)\n"
" {\n"
" value--;\n"
" rayQueryConfirmIntersectionEXT(rayQuery);\n"
"\n"
" rayQueryProceedEXT(rayQuery);\n"
"\n"
" if (rayQueryGetIntersectionTypeEXT(rayQuery, true) == gl_RayQueryCommittedIntersectionTriangleEXT)\n"
" value = rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true);\n"
" }\n"
" }\n"
"\n"
" imageStore(result, pos, ivec4(value, 0, 0, 0));\n";
return result;
}
else
{
TCU_THROW(InternalError, "Unknown geometry type");
}
}
class TestConfigurationGetRayTMin : public TestConfiguration
{
public:
TestConfigurationGetRayTMin (Context& context) : TestConfiguration(context) {}
static const std::string getShaderBodyText(const TestParams& testParams);
virtual const VkAccelerationStructureKHR* initAccelerationStructures(TestParams& testParams,
VkCommandBuffer cmdBuffer) override;
};
const VkAccelerationStructureKHR* TestConfigurationGetRayTMin::initAccelerationStructures(TestParams& testParams, VkCommandBuffer cmdBuffer)
{
const DeviceInterface& vkd = *m_testEnvironment->vkd;
const VkDevice device = m_testEnvironment->device;
Allocator& allocator = *m_testEnvironment->allocator;
const deUint32 width = testParams.width;
const deUint32 height = testParams.height;
const deUint32 instancesGroupCount = testParams.instancesGroupCount;
const deUint32 geometriesGroupCount = testParams.geometriesGroupCount;
const deUint32 squaresGroupCount = testParams.squaresGroupCount;
const bool usesTriangles = (testParams.geomType == GEOM_TYPE_TRIANGLES);
de::MovePtr<TopLevelAccelerationStructure> rayQueryTopLevelAccelerationStructure = makeTopLevelAccelerationStructure();
DE_ASSERT(instancesGroupCount == 1);
DE_ASSERT(geometriesGroupCount == 1);
DE_ASSERT(squaresGroupCount == width * height);
m_topAccelerationStructure = de::SharedPtr<TopLevelAccelerationStructure>(rayQueryTopLevelAccelerationStructure.release());
m_topAccelerationStructure->setInstanceCount(instancesGroupCount);
m_expected.resize(width * height);
for (deUint32 instanceNdx = 0; instanceNdx < instancesGroupCount; ++instanceNdx)
{
de::MovePtr<BottomLevelAccelerationStructure> rayQueryBottomLevelAccelerationStructure = makeBottomLevelAccelerationStructure();
for (deUint32 geometryNdx = 0; geometryNdx < geometriesGroupCount; ++geometryNdx)
{
for (deUint32 squareNdx = 0; squareNdx < squaresGroupCount; ++squareNdx)
{
std::vector<tcu::Vec3> geometryData;
const auto squareX = (squareNdx % width);
const auto squareY = (squareNdx / width);
const float x0 = float(squareX + 0) / float(width);
const float y0 = float(squareY + 0) / float(height);
const float x1 = float(squareX + 1) / float(width);
const float y1 = float(squareY + 1) / float(height);
if (usesTriangles)
{
geometryData.push_back(tcu::Vec3(x0, y0, 0.0));
geometryData.push_back(tcu::Vec3(x0, y1, 0.0));
geometryData.push_back(tcu::Vec3(x1, y1, 0.0));
geometryData.push_back(tcu::Vec3(x1, y1, 0.0));
geometryData.push_back(tcu::Vec3(x1, y0, 0.0));
geometryData.push_back(tcu::Vec3(x0, y0, 0.0));
}
else
{
geometryData.push_back(tcu::Vec3(x0, y0, 0.0));
geometryData.push_back(tcu::Vec3(x1, y1, 0.0));
}
rayQueryBottomLevelAccelerationStructure->addGeometry(geometryData, usesTriangles);
}
}
rayQueryBottomLevelAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, allocator);
m_bottomAccelerationStructures.push_back(de::SharedPtr<BottomLevelAccelerationStructure>(rayQueryBottomLevelAccelerationStructure.release()));
m_topAccelerationStructure->addInstance(m_bottomAccelerationStructures.back(), identityMatrix3x4, instanceNdx + 1);
}
m_topAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, allocator);
for (deUint32 squareNdx = 0; squareNdx < squaresGroupCount; ++squareNdx)
{
const float expected_value = 1.0f + static_cast<float>(squareNdx) / static_cast<float>(squaresGroupCount);
const auto expected_value_i32 = static_cast<deInt32>(expected_value * FIXED_POINT_DIVISOR);
m_expected.at(squareNdx) = expected_value_i32;
}
return m_topAccelerationStructure.get()->getPtr();
}
const std::string TestConfigurationGetRayTMin::getShaderBodyText(const TestParams& testParams)
{
if (testParams.geomType == GEOM_TYPE_AABBS ||
testParams.geomType == GEOM_TYPE_TRIANGLES)
{
const std::string result =
" uint rayFlags = 0;\n"
" uint cullMask = 0xFF;\n"
" float tmin = 1.0 + float(pos.y * size.x + pos.x) / float(size.x * size.y);\n"
" float tmax = 9.0;\n"
" vec3 origin = vec3(0.0, 0.0, -1.0);\n"
" vec3 direct = vec3(0.0, 0.0, 1.0);\n"
" rayQueryEXT rayQuery;\n"
"\n"
" rayQueryInitializeEXT(rayQuery, rayQueryTopLevelAccelerationStructure, rayFlags, cullMask, origin, tmin, direct, tmax);\n"
"\n"
" while (rayQueryProceedEXT(rayQuery))\n"
" {\n"
" if (rayQueryGetIntersectionTypeEXT(rayQuery, false) == gl_RayQueryCandidateIntersectionAABBEXT)\n"
" {\n"
" rayQueryConfirmIntersectionEXT(rayQuery);\n"
" }\n"
" }\n"
"\n"
" float result_fp32 = rayQueryGetRayTMinEXT(rayQuery);\n"
" imageStore(result, pos, ivec4(int(result_fp32 * " + de::toString(FIXED_POINT_DIVISOR) + "), 0, 0, 0));\n";
return result;
}
else
{
TCU_THROW(InternalError, "Unknown geometry type");
}
}
class TestConfigurationGetWorldRayOrigin : public TestConfigurationVector
{
public:
TestConfigurationGetWorldRayOrigin (Context& context) : TestConfigurationVector(context) {}
static const std::string getShaderBodyText(const TestParams& testParams);
virtual const VkAccelerationStructureKHR* initAccelerationStructures(TestParams& testParams,
VkCommandBuffer cmdBuffer) override;
};
const VkAccelerationStructureKHR* TestConfigurationGetWorldRayOrigin::initAccelerationStructures(TestParams& testParams, VkCommandBuffer cmdBuffer)
{
const DeviceInterface& vkd = *m_testEnvironment->vkd;
const VkDevice device = m_testEnvironment->device;
Allocator& allocator = *m_testEnvironment->allocator;
const deUint32 width = testParams.width;
const deUint32 height = testParams.height;
const deUint32 instancesGroupCount = testParams.instancesGroupCount;
const deUint32 geometriesGroupCount = testParams.geometriesGroupCount;
const deUint32 squaresGroupCount = testParams.squaresGroupCount;
const bool usesTriangles = (testParams.geomType == GEOM_TYPE_TRIANGLES);
de::MovePtr<TopLevelAccelerationStructure> rayQueryTopLevelAccelerationStructure = makeTopLevelAccelerationStructure();
DE_ASSERT(instancesGroupCount == 1);
DE_ASSERT(geometriesGroupCount == 1);
DE_ASSERT(squaresGroupCount == width * height);
m_topAccelerationStructure = de::SharedPtr<TopLevelAccelerationStructure>(rayQueryTopLevelAccelerationStructure.release());
m_topAccelerationStructure->setInstanceCount(instancesGroupCount);
m_expected.resize(width * height * 4 /* components */);
for (deUint32 instanceNdx = 0; instanceNdx < instancesGroupCount; ++instanceNdx)
{
de::MovePtr<BottomLevelAccelerationStructure> rayQueryBottomLevelAccelerationStructure = makeBottomLevelAccelerationStructure();
for (deUint32 geometryNdx = 0; geometryNdx < geometriesGroupCount; ++geometryNdx)
{
for (deUint32 squareNdx = 0; squareNdx < squaresGroupCount; ++squareNdx)
{
std::vector<tcu::Vec3> geometryData;
const auto squareX = (squareNdx % width);
const auto squareY = (squareNdx / width);
const float x0 = float(squareX + 0) / float(width);
const float y0 = float(squareY + 0) / float(height);
const float x1 = float(squareX + 1) / float(width);
const float y1 = float(squareY + 1) / float(height);
if (usesTriangles)
{
geometryData.push_back(tcu::Vec3(x0, y0, -0.2f));
geometryData.push_back(tcu::Vec3(x0, y1, -0.2f));
geometryData.push_back(tcu::Vec3(x1, y1, -0.2f));
geometryData.push_back(tcu::Vec3(x1, y1, -0.2f));
geometryData.push_back(tcu::Vec3(x1, y0, -0.2f));
geometryData.push_back(tcu::Vec3(x0, y0, -0.2f));
}
else
{
geometryData.push_back(tcu::Vec3(x0, y0, -0.2f));
geometryData.push_back(tcu::Vec3(x1, y1, -0.2f));
}
rayQueryBottomLevelAccelerationStructure->addGeometry(geometryData, usesTriangles);
}
}
rayQueryBottomLevelAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, allocator);
m_bottomAccelerationStructures.push_back(de::SharedPtr<BottomLevelAccelerationStructure>(rayQueryBottomLevelAccelerationStructure.release()));
m_topAccelerationStructure->addInstance(m_bottomAccelerationStructures.back(), identityMatrix3x4, instanceNdx + 1);
}
m_topAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, allocator);
for (deUint32 squareNdx = 0; squareNdx < squaresGroupCount; ++squareNdx)
{
const auto squareX = squareNdx % width;
const auto squareY = squareNdx / width;
const float expected_values[3] =
{
(float(squareX) + 0.5f) / float(width),
(float(squareY) + 0.5f) / float(height),
float(squareX + squareY) / float(width + height),
};
const deInt32 expected_value_i32vec3[3] =
{
static_cast<deInt32>(expected_values[0] * FIXED_POINT_DIVISOR),
static_cast<deInt32>(expected_values[1] * FIXED_POINT_DIVISOR),
static_cast<deInt32>(expected_values[2] * FIXED_POINT_DIVISOR),
};
/* m_expected data layout is:
*
* XXXXXXXX ..
* YYYYYYYY ..
* ZZZZZZZZ ..
* WWWWWWWW
*/
m_expected.at(0 * squaresGroupCount + squareNdx) = expected_value_i32vec3[0];
m_expected.at(1 * squaresGroupCount + squareNdx) = expected_value_i32vec3[1];
m_expected.at(2 * squaresGroupCount + squareNdx) = expected_value_i32vec3[2];
m_expected.at(3 * squaresGroupCount + squareNdx) = 0;
}
return m_topAccelerationStructure.get()->getPtr();
}
const std::string TestConfigurationGetWorldRayOrigin::getShaderBodyText(const TestParams& testParams)
{
if (testParams.geomType == GEOM_TYPE_AABBS ||
testParams.geomType == GEOM_TYPE_TRIANGLES)
{
const std::string result =
" uint rayFlags = 0;\n"
" uint cullMask = 0xFF;\n"
" float tmin = 0.00001;\n"
" float tmax = 9.0;\n"
" vec3 origin = vec3((float(pos.x) + 0.5)/ float(size.x), float(float(pos.y) + 0.5) / float(size.y), float(pos.x + pos.y) / float(size.x + size.y));\n"
" vec3 direct = vec3(0, 0, -1);\n"
" rayQueryEXT rayQuery;\n"
"\n"
" bool intersection_found = false;\n"
"\n"
" rayQueryInitializeEXT(rayQuery, rayQueryTopLevelAccelerationStructure, rayFlags, cullMask, origin, tmin, direct, tmax);\n"
"\n"
" while (rayQueryProceedEXT(rayQuery))\n"
" {\n"
" intersection_found = true;\n"
"\n"
" rayQueryConfirmIntersectionEXT(rayQuery);\n"
" }\n"
"\n"
" vec3 result_fp32 = (intersection_found) ? rayQueryGetWorldRayOriginEXT(rayQuery)\n"
" : vec3(1234.0, 5678, 9.0);\n"
"\n"
" imageStore(result, ivec3(pos.xy, 0), ivec4(result_fp32.x * " + de::toString(FIXED_POINT_DIVISOR) + ", 0, 0, 0) );\n"
" imageStore(result, ivec3(pos.xy, 1), ivec4(result_fp32.y * " + de::toString(FIXED_POINT_DIVISOR) + ", 0, 0, 0) );\n"
" imageStore(result, ivec3(pos.xy, 2), ivec4(result_fp32.z * " + de::toString(FIXED_POINT_DIVISOR) + ", 0, 0, 0) );\n";
return result;
}
else
{
TCU_THROW(InternalError, "Unknown geometry type");
}
}
class TestConfigurationGetWorldRayDirection : public TestConfigurationVector
{
public:
TestConfigurationGetWorldRayDirection (Context& context) : TestConfigurationVector(context) {}
static const std::string getShaderBodyText(const TestParams& testParams);
virtual const VkAccelerationStructureKHR* initAccelerationStructures(TestParams& testParams,
VkCommandBuffer cmdBuffer) override;
};
const VkAccelerationStructureKHR* TestConfigurationGetWorldRayDirection::initAccelerationStructures(TestParams& testParams, VkCommandBuffer cmdBuffer)
{
const DeviceInterface& vkd = *m_testEnvironment->vkd;
const VkDevice device = m_testEnvironment->device;
Allocator& allocator = *m_testEnvironment->allocator;
const deUint32 width = testParams.width;
const deUint32 height = testParams.height;
const deUint32 instancesGroupCount = testParams.instancesGroupCount;
const deUint32 geometriesGroupCount = testParams.geometriesGroupCount;
const deUint32 squaresGroupCount = testParams.squaresGroupCount;
const bool usesTriangles = (testParams.geomType == GEOM_TYPE_TRIANGLES);
de::MovePtr<TopLevelAccelerationStructure> rayQueryTopLevelAccelerationStructure = makeTopLevelAccelerationStructure();
DE_ASSERT(instancesGroupCount == 1);
DE_ASSERT(geometriesGroupCount == 1);
DE_ASSERT(squaresGroupCount == width * height);
m_topAccelerationStructure = de::SharedPtr<TopLevelAccelerationStructure>(rayQueryTopLevelAccelerationStructure.release());
m_topAccelerationStructure->setInstanceCount(instancesGroupCount);
m_expected.resize(width * height * 3 /* components in vec3 */);
for (deUint32 instanceNdx = 0; instanceNdx < instancesGroupCount; ++instanceNdx)
{
de::MovePtr<BottomLevelAccelerationStructure> rayQueryBottomLevelAccelerationStructure = makeBottomLevelAccelerationStructure();
for (deUint32 geometryNdx = 0; geometryNdx < geometriesGroupCount; ++geometryNdx)
{
for (deUint32 squareNdx = 0; squareNdx < squaresGroupCount; ++squareNdx)
{
std::vector<tcu::Vec3> geometryData;
const auto squareX = (squareNdx % width);
const auto squareY = (squareNdx / width);
const float x0 = float(squareX + 0) / float(width);
const float y0 = float(squareY + 0) / float(height);
const float x1 = float(squareX + 1) / float(width);
const float y1 = float(squareY + 1) / float(height);
if (usesTriangles)
{
geometryData.push_back(tcu::Vec3(x0, y0, 0.0));
geometryData.push_back(tcu::Vec3(x0, y1, 0.0));
geometryData.push_back(tcu::Vec3(x1, y1, 0.0));
geometryData.push_back(tcu::Vec3(x1, y1, 0.0));
geometryData.push_back(tcu::Vec3(x1, y0, 0.0));
geometryData.push_back(tcu::Vec3(x0, y0, 0.0));
}
else
{
geometryData.push_back(tcu::Vec3(x0, y0, 0.0));
geometryData.push_back(tcu::Vec3(x1, y1, 0.0));
}
rayQueryBottomLevelAccelerationStructure->addGeometry(geometryData, usesTriangles);
}
}
rayQueryBottomLevelAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, allocator);
m_bottomAccelerationStructures.push_back(de::SharedPtr<BottomLevelAccelerationStructure>(rayQueryBottomLevelAccelerationStructure.release()));
m_topAccelerationStructure->addInstance(m_bottomAccelerationStructures.back(), identityMatrix3x4, instanceNdx + 1);
}
m_topAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, allocator);
const auto normalize = [](const tcu::Vec3& in_vec3)
{
const auto distance = deFloatSqrt(in_vec3[0] * in_vec3[0] + in_vec3[1] * in_vec3[1] + in_vec3[2] * in_vec3[2]);
return tcu::Vec3(in_vec3[0] / distance, in_vec3[1] / distance, in_vec3[2] / distance);
};
for (deUint32 squareNdx = 0; squareNdx < squaresGroupCount; ++squareNdx)
{
const auto squareX = squareNdx % width;
const auto squareY = squareNdx / width;
const auto origin = tcu::Vec3(0.5f, 0.5f, -1.0f);
const auto target = tcu::Vec3((float(squareX) + 0.5f) / float(width), (float(squareY) + 0.5f) / float(height), 0.0);
const auto dir_vector = target - origin;
const auto dir_vector_normalized = normalize(dir_vector);
const deInt32 expected_value_i32vec3[3] =
{
static_cast<deInt32>(dir_vector_normalized[0] * FIXED_POINT_DIVISOR),
static_cast<deInt32>(dir_vector_normalized[1] * FIXED_POINT_DIVISOR),
static_cast<deInt32>(dir_vector_normalized[2] * FIXED_POINT_DIVISOR),
};
/* Data layout for m_expected is:
*
* XXXX...XX
* YYYY...YY
* ZZZZ...ZZ
* WWWW...WW
*/
m_expected.at(0 * squaresGroupCount + squareNdx) = expected_value_i32vec3[0];
m_expected.at(1 * squaresGroupCount + squareNdx) = expected_value_i32vec3[1];
m_expected.at(2 * squaresGroupCount + squareNdx) = expected_value_i32vec3[2];
}
return m_topAccelerationStructure.get()->getPtr();
}
const std::string TestConfigurationGetWorldRayDirection::getShaderBodyText(const TestParams& testParams)
{
if (testParams.geomType == GEOM_TYPE_AABBS ||
testParams.geomType == GEOM_TYPE_TRIANGLES)
{
const std::string result =
" uint rayFlags = 0;\n"
" uint cullMask = 0xFF;\n"
" float tmin = 0.00001;\n"
" float tmax = 9.0;\n"
" vec3 origin = vec3(0.5, 0.5, -1.0);\n"
" vec3 target = vec3(float(float(pos.x) + 0.5) / float(size.x), float(float(pos.y) + 0.5) / float(size.y), 0.0);\n"
" vec3 direct = normalize(target - origin);\n"
" rayQueryEXT rayQuery;\n"
"\n"
" bool intersection_found = false;\n"
"\n"
" rayQueryInitializeEXT(rayQuery, rayQueryTopLevelAccelerationStructure, rayFlags, cullMask, origin, tmin, direct, tmax);\n"
"\n"
" while (rayQueryProceedEXT(rayQuery))\n"
" {\n"
" rayQueryConfirmIntersectionEXT(rayQuery);\n"
"\n"
" intersection_found = true;\n"
" }\n"
"\n"
" vec3 result_fp32 = (intersection_found) ? rayQueryGetWorldRayDirectionEXT(rayQuery)\n"
" : vec3(1234.0, 5678.0, 9.0);\n"
"\n"
" imageStore(result, ivec3(pos.xy, 0), ivec4(result_fp32.x * " + de::toString(FIXED_POINT_DIVISOR) + ", 0, 0, 0) );\n"
" imageStore(result, ivec3(pos.xy, 1), ivec4(result_fp32.y * " + de::toString(FIXED_POINT_DIVISOR) + ", 0, 0, 0) );\n"
" imageStore(result, ivec3(pos.xy, 2), ivec4(result_fp32.z * " + de::toString(FIXED_POINT_DIVISOR) + ", 0, 0, 0) );\n";
return result;
}
else
{
TCU_THROW(InternalError, "Unknown geometry type");
}
}
class TestConfigurationInstanceId : public TestConfiguration
{
public:
TestConfigurationInstanceId (Context& context) : TestConfiguration(context) {}
static const std::string getShaderBodyText(const TestParams& testParams);
virtual const VkAccelerationStructureKHR* initAccelerationStructures(TestParams& testParams,
VkCommandBuffer cmdBuffer) override;
};
const VkAccelerationStructureKHR* TestConfigurationInstanceId::initAccelerationStructures(TestParams& testParams,
VkCommandBuffer cmdBuffer)
{
const DeviceInterface& vkd = *m_testEnvironment->vkd;
const VkDevice device = m_testEnvironment->device;
Allocator& allocator = *m_testEnvironment->allocator;
const deUint32 width = testParams.width;
const deUint32 height = testParams.height;
const deUint32 instancesGroupCount = testParams.instancesGroupCount;
const deUint32 geometriesGroupCount = testParams.geometriesGroupCount;
const deUint32 squaresGroupCount = testParams.squaresGroupCount;
const bool triangles = (testParams.geomType == GEOM_TYPE_TRIANGLES);
const float z = -1.0f;
tcu::UVec2 startPos = tcu::UVec2(0, 0);
de::MovePtr<TopLevelAccelerationStructure> rayQueryTopLevelAccelerationStructure = makeTopLevelAccelerationStructure();
DE_ASSERT(instancesGroupCount * geometriesGroupCount * squaresGroupCount == width * height);
m_topAccelerationStructure = de::SharedPtr<TopLevelAccelerationStructure>(rayQueryTopLevelAccelerationStructure.release());
m_topAccelerationStructure->setInstanceCount(instancesGroupCount);
m_expected.resize(width * height);
for (deUint32 instanceNdx = 0; instanceNdx < instancesGroupCount; ++instanceNdx)
{
de::MovePtr<BottomLevelAccelerationStructure> rayQueryBottomLevelAccelerationStructure = makeBottomLevelAccelerationStructure();
for (deUint32 geometryNdx = 0; geometryNdx < geometriesGroupCount; ++geometryNdx)
{
std::vector<tcu::Vec3> geometryData;
geometryData.reserve(squaresGroupCount * (triangles ? 3u : 2u));
for (deUint32 squareNdx = 0; squareNdx < squaresGroupCount; ++squareNdx)
{
const deUint32 n = width * startPos.y() + startPos.x();
const deUint32 m = (n + 11) % (width * height);
const float x0 = float(startPos.x() + 0) / float(width);
const float y0 = float(startPos.y() + 0) / float(height);
const float x1 = float(startPos.x() + 1) / float(width);
const float y1 = float(startPos.y() + 1) / float(height);
m_expected[n] = instanceNdx;
if (triangles)
{
const float xm = (x0 + x1) / 2.0f;
const float ym = (y0 + y1) / 2.0f;
geometryData.push_back(tcu::Vec3(x0, y0, z));
geometryData.push_back(tcu::Vec3(xm, y1, z));