Validation of type decls for SPV_KHR_16bit_storage
authorDavid Neto <dneto@google.com>
Wed, 22 Feb 2017 23:10:05 +0000 (18:10 -0500)
committerDavid Neto <dneto@google.com>
Mon, 27 Feb 2017 18:12:59 +0000 (13:12 -0500)
Allow declaration of 16bit int or 16bit float in
the presence of capabilities from SPV_KHR_16bit_storage

source/val/validation_state.cpp
source/validate_datarules.cpp
test/val/val_data_test.cpp

index 5b01b15..78ac704 100644 (file)
@@ -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;
   }
index 3927ab5..5a11e68 100644 (file)
@@ -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)) {
index d1be941..3c4ffed 100644 (file)
@@ -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());