mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-26 05:10:05 +00:00
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
This commit is contained in:
parent
c6099ad242
commit
af7125dfb0
@ -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;
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -33,6 +33,11 @@ using std::stringstream;
|
||||
|
||||
using ValidateData = spvtest::ValidateBase<pair<string, bool>>;
|
||||
|
||||
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());
|
||||
|
Loading…
Reference in New Issue
Block a user