From eea449a1e82ab6a860b68f9b0a23f0432fe9939f Mon Sep 17 00:00:00 2001 From: David Neto Date: Sat, 13 Oct 2018 10:24:05 -0400 Subject: [PATCH] validator: FPRoundingMode can apply to vector conversions Fixes #1972 --- source/val/validate_decorations.cpp | 4 +-- test/val/val_decoration_test.cpp | 42 ++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/source/val/validate_decorations.cpp b/source/val/validate_decorations.cpp index c4c390adf..2026a395b 100644 --- a/source/val/validate_decorations.cpp +++ b/source/val/validate_decorations.cpp @@ -916,12 +916,12 @@ spv_result_t CheckDecorationsOfConversions(ValidationState_t& vstate) { vstate.FindDef(ptr_inst->GetOperandAs(0)); const auto half_float_id = ptr_type->GetOperandAs(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 diff --git a/test/val/val_decoration_test.cpp b/test/val/val_decoration_test.cpp index 21803f9eb..dd4a7f5fc 100644 --- a/test/val/val_decoration_test.cpp +++ b/test/val/val_decoration_test.cpp @@ -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) {