Skip to content

Commit bf3ad6e

Browse files
authored
spirv-val: Make it legal to use OpInBoundsAccessChain with ray queries (KhronosGroup#6710)
We had allowed OpAccessChain in the past but missed the OpInBoundsAccessChain case. This will be needed for some upcoming CTS tests.
1 parent 2e40a11 commit bf3ad6e

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

source/val/validate_ray_query.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ spv_result_t ValidateRayQueryPointer(ValidationState_t& _,
4242
const auto var_opcode = variable->opcode();
4343
if (!variable || (var_opcode != spv::Op::OpVariable &&
4444
var_opcode != spv::Op::OpFunctionParameter &&
45-
var_opcode != spv::Op::OpAccessChain)) {
45+
var_opcode != spv::Op::OpAccessChain &&
46+
var_opcode != spv::Op::OpInBoundsAccessChain)) {
4647
return _.diag(SPV_ERROR_INVALID_DATA, inst)
4748
<< "Ray Query must be a memory object declaration";
4849
}

test/val/val_ray_query_test.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,58 @@ TEST_F(ValidateRayQuery, RayQueryArraySuccess) {
633633
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
634634
}
635635

636+
TEST_F(ValidateRayQuery, RayQueryArraySuccessInBounds) {
637+
// This shader is slightly different to the ones above, so it doesn't reuse
638+
// the shader code generator.
639+
const std::string shader = R"(
640+
OpCapability Shader
641+
OpCapability RayQueryKHR
642+
OpExtension "SPV_KHR_ray_query"
643+
OpMemoryModel Logical GLSL450
644+
OpEntryPoint GLCompute %main "main"
645+
OpExecutionMode %main LocalSize 1 1 1
646+
OpSource GLSL 460
647+
OpDecorate %topLevelAS DescriptorSet 0
648+
OpDecorate %topLevelAS Binding 0
649+
OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize
650+
%void = OpTypeVoid
651+
%func = OpTypeFunction %void
652+
%ray_query = OpTypeRayQueryKHR
653+
%uint = OpTypeInt 32 0
654+
%uint_2 = OpConstant %uint 2
655+
%ray_query_array = OpTypeArray %ray_query %uint_2
656+
%ptr_ray_query_array = OpTypePointer Private %ray_query_array
657+
%rayQueries = OpVariable %ptr_ray_query_array Private
658+
%int = OpTypeInt 32 1
659+
%int_0 = OpConstant %int 0
660+
%ptr_ray_query = OpTypePointer Private %ray_query
661+
%accel_struct = OpTypeAccelerationStructureKHR
662+
%ptr_accel_struct = OpTypePointer UniformConstant %accel_struct
663+
%topLevelAS = OpVariable %ptr_accel_struct UniformConstant
664+
%uint_0 = OpConstant %uint 0
665+
%uint_255 = OpConstant %uint 255
666+
%float = OpTypeFloat 32
667+
%v3float = OpTypeVector %float 3
668+
%float_0 = OpConstant %float 0
669+
%vec3_zero = OpConstantComposite %v3float %float_0 %float_0 %float_0
670+
%float_1 = OpConstant %float 1
671+
%vec3_xy_0_z_1 = OpConstantComposite %v3float %float_0 %float_0 %float_1
672+
%float_10 = OpConstant %float 10
673+
%v3uint = OpTypeVector %uint 3
674+
%uint_1 = OpConstant %uint 1
675+
%gl_WorkGroupSize = OpConstantComposite %v3uint %uint_1 %uint_1 %uint_1
676+
%main = OpFunction %void None %func
677+
%main_label = OpLabel
678+
%first_ray_query = OpInBoundsAccessChain %ptr_ray_query %rayQueries %int_0
679+
%topLevelAS_val = OpLoad %accel_struct %topLevelAS
680+
OpRayQueryInitializeKHR %first_ray_query %topLevelAS_val %uint_0 %uint_255 %vec3_zero %float_0 %vec3_xy_0_z_1 %float_10
681+
OpReturn
682+
OpFunctionEnd
683+
)";
684+
CompileSuccessfully(shader);
685+
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
686+
}
687+
636688
TEST_F(ValidateRayQuery, ClusterASNV) {
637689
const std::string cap = R"(
638690
OpCapability RayTracingClusterAccelerationStructureNV

0 commit comments

Comments
 (0)