UniformConstant variables can have RuntimeArray, TypeAccelerationStructureNV

This commit is contained in:
David Neto 2018-11-14 21:50:09 -05:00
parent d4a10590b7
commit a29a9947ac
2 changed files with 33 additions and 5 deletions

View File

@ -332,8 +332,10 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) {
auto variable_type = _.FindDef(result_type->GetOperandAs<uint32_t>(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<uint32_t>(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.";
}
}

View File

@ -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