Skip to content

Commit

Permalink
spirv-val: Make it legal to use arrays of ray queries
Browse files Browse the repository at this point in the history
Private arrays of ray queries are legal to use. Several CTS tests check
they work properly but were being rejected by spirv-val.
  • Loading branch information
rg3igalia committed Sep 21, 2022
1 parent 11d0d16 commit fc21a26
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
6 changes: 4 additions & 2 deletions source/val/validate_ray_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ spv_result_t ValidateRayQueryPointer(ValidationState_t& _,
uint32_t ray_query_index) {
const uint32_t ray_query_id = inst->GetOperandAs<uint32_t>(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";
}
Expand Down
53 changes: 53 additions & 0 deletions test/val/val_ray_query_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <string>

#include "gmock/gmock.h"
#include "spirv-tools/libspirv.h"
#include "test/val/val_fixtures.h"

namespace spvtools {
Expand Down Expand Up @@ -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

0 comments on commit fc21a26

Please sign in to comment.