spirv-val: Make it legal to use arrays of ray queries (#4938)

Private arrays of ray queries are legal to use. Several CTS tests check
they work properly but were being rejected by spirv-val.
This commit is contained in:
Ricardo Garcia 2022-09-21 21:27:36 +02:00 коммит произвёл GitHub
Родитель 11d0d16227
Коммит aeb1c64d4a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 57 добавлений и 2 удалений

Просмотреть файл

@ -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";
}

Просмотреть файл

@ -18,6 +18,7 @@
#include <string>
#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