From a29a9947ac96d811b310f481b24e293f67fedf32 Mon Sep 17 00:00:00 2001 From: David Neto Date: Wed, 14 Nov 2018 21:50:09 -0500 Subject: [PATCH] UniformConstant variables can have RuntimeArray, TypeAccelerationStructureNV --- source/val/validate_memory.cpp | 10 +++++++--- test/val/val_memory_test.cpp | 28 ++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/source/val/validate_memory.cpp b/source/val/validate_memory.cpp index 9a1e831b2..438cc88b8 100644 --- a/source/val/validate_memory.cpp +++ b/source/val/validate_memory.cpp @@ -332,8 +332,10 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) { auto variable_type = _.FindDef(result_type->GetOperandAs(2)); auto variable_type_opcode = variable_type->opcode(); - // If the variable is actually an array extract the element type. - if (variable_type_opcode == SpvOpTypeArray) { + // If the variable is actually an array or runtime-array, extract the + // element type. + if (variable_type_opcode == SpvOpTypeArray || + variable_type_opcode == SpvOpTypeRuntimeArray) { variable_type = _.FindDef(variable_type->GetOperandAs(1)); variable_type_opcode = variable_type->opcode(); } @@ -342,6 +344,7 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) { case SpvOpTypeImage: case SpvOpTypeSampler: case SpvOpTypeSampledImage: + case SpvOpTypeAccelerationStructureNV: break; default: return _.diag(SPV_ERROR_INVALID_ID, inst) @@ -349,7 +352,8 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) { << "Variables identified with the UniformConstant storage class " << "are used only as handles to refer to opaque resources. Such " << "variables must be typed as OpTypeImage, OpTypeSampler, " - << "OpTypeSampledImage, or an array of one of these types."; + << "OpTypeSampledImage, OpTypeAccelerationStructureNV, " + << "or an array of one of these types."; } } diff --git a/test/val/val_memory_test.cpp b/test/val/val_memory_test.cpp index 00ef057ee..3666c93ea 100644 --- a/test/val/val_memory_test.cpp +++ b/test/val/val_memory_test.cpp @@ -54,7 +54,8 @@ OpFunctionEnd "Variables identified with the UniformConstant storage class " "are used only as handles to refer to opaque resources. Such " "variables must be typed as OpTypeImage, OpTypeSampler, " - "OpTypeSampledImage, or an array of one of these types.")); + "OpTypeSampledImage, OpTypeAccelerationStructureNV, or an " + "array of one of these types.")); } TEST_F(ValidateMemory, VulkanUniformConstantOnOpaqueResourceGood) { @@ -104,7 +105,8 @@ OpFunctionEnd "Variables identified with the UniformConstant storage class " "are used only as handles to refer to opaque resources. Such " "variables must be typed as OpTypeImage, OpTypeSampler, " - "OpTypeSampledImage, or an array of one of these types.")); + "OpTypeSampledImage, OpTypeAccelerationStructureNV, or an " + "array of one of these types.")); } TEST_F(ValidateMemory, VulkanUniformConstantOnOpaqueResourceArrayGood) { @@ -130,6 +132,28 @@ OpFunctionEnd EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_1)); } +TEST_F(ValidateMemory, VulkanUniformConstantOnOpaqueResourceRuntimeArrayGood) { + std::string spirv = R"( +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %func "func" +OpExecutionMode %func OriginUpperLeft +%sampler = OpTypeSampler +%uint = OpTypeInt 32 0 +%array = OpTypeRuntimeArray %sampler +%array_ptr = OpTypePointer UniformConstant %array +%2 = OpVariable %array_ptr UniformConstant +%void = OpTypeVoid +%functy = OpTypeFunction %void +%func = OpFunction %void None %functy +%1 = OpLabel +OpReturn +OpFunctionEnd +)"; + CompileSuccessfully(spirv.c_str(), SPV_ENV_VULKAN_1_1); + EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_1)); +} + } // namespace } // namespace val } // namespace spvtools