From: David Neto Date: Wed, 22 Feb 2017 23:10:05 +0000 (-0500) Subject: Validation of type decls for SPV_KHR_16bit_storage X-Git-Tag: upstream/2018.6~958 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af7125dfb0493fcf8825609025ab6d83f32ecefc;p=platform%2Fupstream%2FSPIRV-Tools.git Validation of type decls for SPV_KHR_16bit_storage Allow declaration of 16bit int or 16bit float in the presence of capabilities from SPV_KHR_16bit_storage --- diff --git a/source/val/validation_state.cpp b/source/val/validation_state.cpp index 5b01b15..78ac704 100644 --- a/source/val/validation_state.cpp +++ b/source/val/validation_state.cpp @@ -341,6 +341,12 @@ void ValidationState_t::RegisterCapability(SpvCapability cap) { case SpvCapabilityFloat16Buffer: features_.declare_float16_type = true; break; + case SpvCapabilityStorageUniformBufferBlock16: + case SpvCapabilityStorageUniform16: + case SpvCapabilityStoragePushConstant16: + case SpvCapabilityStorageInputOutput16: + features_.declare_int16_type = true; + features_.declare_float16_type = true; default: break; } diff --git a/source/validate_datarules.cpp b/source/validate_datarules.cpp index 3927ab5..5a11e68 100644 --- a/source/validate_datarules.cpp +++ b/source/validate_datarules.cpp @@ -74,7 +74,8 @@ spv_result_t ValidateFloatSize(ValidationState_t& _, } return _.diag(SPV_ERROR_INVALID_DATA) << "Using a 16-bit floating point " - << "type requires the Float16 or Float16Buffer capability."; + << "type requires the Float16 or Float16Buffer capability," + " or an extension that explicitly enables 16-bit floating point."; } if (num_bits == 64) { if (_.HasCapability(SpvCapabilityFloat64)) { @@ -111,7 +112,8 @@ spv_result_t ValidateIntSize(ValidationState_t& _, return SPV_SUCCESS; } return _.diag(SPV_ERROR_INVALID_DATA) - << "Using a 16-bit integer type requires the Int16 capability."; + << "Using a 16-bit integer type requires the Int16 capability," + " or an extension that explicitly enables 16-bit integers."; } if (num_bits == 64) { if (_.HasCapability(SpvCapabilityInt64)) { diff --git a/test/val/val_data_test.cpp b/test/val/val_data_test.cpp index d1be941..3c4ffed 100644 --- a/test/val/val_data_test.cpp +++ b/test/val/val_data_test.cpp @@ -33,6 +33,11 @@ using std::stringstream; using ValidateData = spvtest::ValidateBase>; +string HeaderWith(std::string cap) { + return std::string("OpCapability Shader OpCapability Linkage OpCapability ") + + cap + " OpMemoryModel Logical GLSL450 "; +} + string header = R"( OpCapability Shader OpCapability Linkage @@ -92,10 +97,13 @@ string header_with_float64 = R"( string invalid_comp_error = "Illegal number of components"; string missing_cap_error = "requires the Vector16 capability"; string missing_int8_cap_error = "requires the Int8 capability"; -string missing_int16_cap_error = "requires the Int16 capability"; +string missing_int16_cap_error = + "requires the Int16 capability," + " or an extension that explicitly enables 16-bit integers."; string missing_int64_cap_error = "requires the Int64 capability"; string missing_float16_cap_error = - "requires the Float16 or Float16Buffer capability."; + "requires the Float16 or Float16Buffer capability," + " or an extension that explicitly enables 16-bit floating point."; string missing_float64_cap_error = "requires the Float64 capability"; string invalid_num_bits_error = "Invalid number of bits"; @@ -190,6 +198,34 @@ TEST_F(ValidateData, int16_good) { ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); } +TEST_F(ValidateData, storage_uniform_buffer_block_16_good) { + string str = + HeaderWith("StorageUniformBufferBlock16") + "%2 = OpTypeInt 16 1 %3 = OpTypeFloat 16"; + CompileSuccessfully(str.c_str()); + ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); +} + +TEST_F(ValidateData, storage_uniform_16_good) { + string str = HeaderWith("StorageUniform16") + + "%2 = OpTypeInt 16 1 %3 = OpTypeFloat 16"; + CompileSuccessfully(str.c_str()); + ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); +} + +TEST_F(ValidateData, storage_push_constant_16_good) { + string str = HeaderWith("StoragePushConstant16") + + "%2 = OpTypeInt 16 1 %3 = OpTypeFloat 16"; + CompileSuccessfully(str.c_str()); + ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); +} + +TEST_F(ValidateData, storage_input_output_16_good) { + string str = HeaderWith("StorageInputOutput16") + + "%2 = OpTypeInt 16 1 %3 = OpTypeFloat 16"; + CompileSuccessfully(str.c_str()); + ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); +} + TEST_F(ValidateData, int16_bad) { string str = header + "%2 = OpTypeInt 16 1"; CompileSuccessfully(str.c_str());