validator: FPRoundingMode can apply to vector conversions

Fixes #1972
This commit is contained in:
David Neto 2018-10-13 10:24:05 -04:00
parent 339d23275d
commit eea449a1e8
2 changed files with 40 additions and 6 deletions

View File

@ -916,12 +916,12 @@ spv_result_t CheckDecorationsOfConversions(ValidationState_t& vstate) {
vstate.FindDef(ptr_inst->GetOperandAs<uint32_t>(0));
const auto half_float_id = ptr_type->GetOperandAs<uint32_t>(2);
if (!vstate.IsFloatScalarType(half_float_id) ||
if (!vstate.IsFloatScalarOrVectorType(half_float_id) ||
vstate.GetBitWidth(half_float_id) != 16) {
return vstate.diag(SPV_ERROR_INVALID_ID, inst)
<< "FPRoundingMode decoration can be applied only to the "
"Object operand of an OpStore storing through a pointer to "
"a 16-bit floating-point object.";
"a 16-bit floating-point scalar or vector object.";
}
// Validates storage class of the pointer to the OpStore

View File

@ -3176,6 +3176,39 @@ OpFunctionEnd
EXPECT_EQ(SPV_SUCCESS, ValidateAndRetrieveValidationState());
}
TEST_F(ValidateDecorations, FPRoundingModeVectorGood) {
std::string spirv = R"(
OpCapability Shader
OpCapability Linkage
OpCapability StorageBuffer16BitAccess
OpExtension "SPV_KHR_storage_buffer_storage_class"
OpExtension "SPV_KHR_variable_pointers"
OpExtension "SPV_KHR_16bit_storage"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpDecorate %_ FPRoundingMode RTE
%half = OpTypeFloat 16
%float = OpTypeFloat 32
%v2half = OpTypeVector %half 2
%v2float = OpTypeVector %float 2
%float_1_25 = OpConstant %float 1.25
%floats = OpConstantComposite %v2float %float_1_25 %float_1_25
%halfs_ptr = OpTypePointer StorageBuffer %v2half
%halfs_ptr_var = OpVariable %halfs_ptr StorageBuffer
%void = OpTypeVoid
%func = OpTypeFunction %void
%main = OpFunction %void None %func
%main_entry = OpLabel
%_ = OpFConvert %v2half %floats
OpStore %halfs_ptr_var %_
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(spirv);
EXPECT_EQ(SPV_SUCCESS, ValidateAndRetrieveValidationState());
}
TEST_F(ValidateDecorations, FPRoundingModeNotOpFConvert) {
std::string spirv = R"(
OpCapability Shader
@ -3299,10 +3332,11 @@ OpFunctionEnd
CompileSuccessfully(spirv);
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateAndRetrieveValidationState());
EXPECT_THAT(getDiagnosticString(),
HasSubstr("FPRoundingMode decoration can be applied only to the "
"Object operand of an OpStore storing through a "
"pointer to a 16-bit floating-point object."));
EXPECT_THAT(
getDiagnosticString(),
HasSubstr("FPRoundingMode decoration can be applied only to the "
"Object operand of an OpStore storing through a "
"pointer to a 16-bit floating-point scalar or vector object."));
}
TEST_F(ValidateDecorations, FPRoundingModeBadStorageClass) {