From fc21a2666a151283a3cd60b9be9260e06f0b2ad3 Mon Sep 17 00:00:00 2001 From: Ricardo Garcia Date: Wed, 21 Sep 2022 09:37:49 +0200 Subject: [PATCH] spirv-val: Make it legal to use arrays of ray queries Private arrays of ray queries are legal to use. Several CTS tests check they work properly but were being rejected by spirv-val. --- source/val/validate_ray_query.cpp | 6 ++-- test/val/val_ray_query_test.cpp | 53 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/source/val/validate_ray_query.cpp b/source/val/validate_ray_query.cpp index f92bf016a3..b553449d0b 100644 --- a/source/val/validate_ray_query.cpp +++ b/source/val/validate_ray_query.cpp @@ -28,8 +28,10 @@ spv_result_t ValidateRayQueryPointer(ValidationState_t& _, uint32_t ray_query_index) { const uint32_t ray_query_id = inst->GetOperandAs(ray_query_index); auto variable = _.FindDef(ray_query_id); - if (!variable || (variable->opcode() != SpvOpVariable && - variable->opcode() != SpvOpFunctionParameter)) { + const auto var_opcode = variable->opcode(); + if (!variable || + (var_opcode != SpvOpVariable && var_opcode != SpvOpFunctionParameter && + var_opcode != SpvOpAccessChain)) { return _.diag(SPV_ERROR_INVALID_DATA, inst) << "Ray Query must be a memory object declaration"; } diff --git a/test/val/val_ray_query_test.cpp b/test/val/val_ray_query_test.cpp index e9b9696373..1541c74535 100644 --- a/test/val/val_ray_query_test.cpp +++ b/test/val/val_ray_query_test.cpp @@ -18,6 +18,7 @@ #include #include "gmock/gmock.h" +#include "spirv-tools/libspirv.h" #include "test/val/val_fixtures.h" namespace spvtools { @@ -573,6 +574,58 @@ OpRayQueryGenerateIntersectionKHR %ray_query %u32_0 HasSubstr("Hit T must be a 32-bit float scalar")); } +TEST_F(ValidateRayQuery, RayQueryArraySuccess) { + // This shader is slightly different to the ones above, so it doesn't reuse + // the shader code generator. + const std::string shader = R"( + OpCapability Shader + OpCapability RayQueryKHR + OpExtension "SPV_KHR_ray_query" + OpMemoryModel Logical GLSL450 + OpEntryPoint GLCompute %main "main" + OpExecutionMode %main LocalSize 1 1 1 + OpSource GLSL 460 + OpDecorate %topLevelAS DescriptorSet 0 + OpDecorate %topLevelAS Binding 0 + OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize + %void = OpTypeVoid + %func = OpTypeFunction %void + %ray_query = OpTypeRayQueryKHR + %uint = OpTypeInt 32 0 + %uint_2 = OpConstant %uint 2 + %ray_query_array = OpTypeArray %ray_query %uint_2 +%ptr_ray_query_array = OpTypePointer Private %ray_query_array + %rayQueries = OpVariable %ptr_ray_query_array Private + %int = OpTypeInt 32 1 + %int_0 = OpConstant %int 0 + %ptr_ray_query = OpTypePointer Private %ray_query + %accel_struct = OpTypeAccelerationStructureKHR + %ptr_accel_struct = OpTypePointer UniformConstant %accel_struct + %topLevelAS = OpVariable %ptr_accel_struct UniformConstant + %uint_0 = OpConstant %uint 0 + %uint_255 = OpConstant %uint 255 + %float = OpTypeFloat 32 + %v3float = OpTypeVector %float 3 + %float_0 = OpConstant %float 0 + %vec3_zero = OpConstantComposite %v3float %float_0 %float_0 %float_0 + %float_1 = OpConstant %float 1 + %vec3_xy_0_z_1 = OpConstantComposite %v3float %float_0 %float_0 %float_1 + %float_10 = OpConstant %float 10 + %v3uint = OpTypeVector %uint 3 + %uint_1 = OpConstant %uint 1 + %gl_WorkGroupSize = OpConstantComposite %v3uint %uint_1 %uint_1 %uint_1 + %main = OpFunction %void None %func + %main_label = OpLabel + %first_ray_query = OpAccessChain %ptr_ray_query %rayQueries %int_0 + %topLevelAS_val = OpLoad %accel_struct %topLevelAS + OpRayQueryInitializeKHR %first_ray_query %topLevelAS_val %uint_0 %uint_255 %vec3_zero %float_0 %vec3_xy_0_z_1 %float_10 + OpReturn + OpFunctionEnd +)"; + CompileSuccessfully(shader); + EXPECT_EQ(SPV_SUCCESS, ValidateInstructions()); +} + } // namespace } // namespace val } // namespace spvtools