aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsfricke-samsung <46493288+sfricke-samsung@users.noreply.github.com>2021-02-01 07:39:44 -0800
committerGitHub <noreply@github.com>2021-02-01 10:39:44 -0500
commitd61a7d110d93c244222364d67099bd3bbba1c307 (patch)
treedc78c372dcd1eb9506f2f049fe72f968a397f760
parent297723d75af4244d1cdad1178da0689dec8fd9a0 (diff)
downloadspirv-tools-d61a7d110d93c244222364d67099bd3bbba1c307.tar.gz
spirv-val: Add Vulkan PSB64 convert VUID (#4122)
-rw-r--r--source/val/validate_conversion.cpp38
-rw-r--r--source/val/validation_state.cpp2
-rw-r--r--test/val/val_conversion_test.cpp91
3 files changed, 109 insertions, 22 deletions
diff --git a/source/val/validate_conversion.cpp b/source/val/validate_conversion.cpp
index 0060d0b7..b4e39cfe 100644
--- a/source/val/validate_conversion.cpp
+++ b/source/val/validate_conversion.cpp
@@ -14,12 +14,12 @@
// Validates correctness of conversion instructions.
-#include "source/val/validate.h"
-
#include "source/diagnostic.h"
#include "source/opcode.h"
#include "source/spirv_constant.h"
+#include "source/spirv_target_env.h"
#include "source/val/instruction.h"
+#include "source/val/validate.h"
#include "source/val/validation_state.h"
namespace spvtools {
@@ -263,16 +263,25 @@ spv_result_t ConversionPass(ValidationState_t& _, const Instruction* inst) {
<< "Logical addressing not supported: "
<< spvOpcodeString(opcode);
- if (_.addressing_model() ==
- SpvAddressingModelPhysicalStorageBuffer64EXT) {
+ if (_.addressing_model() == SpvAddressingModelPhysicalStorageBuffer64) {
uint32_t input_storage_class = 0;
uint32_t input_data_type = 0;
_.GetPointerTypeInfo(input_type, &input_data_type,
&input_storage_class);
- if (input_storage_class != SpvStorageClassPhysicalStorageBufferEXT)
+ if (input_storage_class != SpvStorageClassPhysicalStorageBuffer)
return _.diag(SPV_ERROR_INVALID_DATA, inst)
- << "Pointer storage class must be PhysicalStorageBufferEXT: "
+ << "Pointer storage class must be PhysicalStorageBuffer: "
<< spvOpcodeString(opcode);
+
+ if (spvIsVulkanEnv(_.context()->target_env)) {
+ if (_.GetBitWidth(result_type) != 64) {
+ return _.diag(SPV_ERROR_INVALID_DATA, inst)
+ << _.VkErrorID(4710)
+ << "PhysicalStorageBuffer64 addressing mode requires the "
+ "result integer type to have a 64-bit width for Vulkan "
+ "environment.";
+ }
+ }
}
break;
}
@@ -314,16 +323,25 @@ spv_result_t ConversionPass(ValidationState_t& _, const Instruction* inst) {
<< "Logical addressing not supported: "
<< spvOpcodeString(opcode);
- if (_.addressing_model() ==
- SpvAddressingModelPhysicalStorageBuffer64EXT) {
+ if (_.addressing_model() == SpvAddressingModelPhysicalStorageBuffer64) {
uint32_t result_storage_class = 0;
uint32_t result_data_type = 0;
_.GetPointerTypeInfo(result_type, &result_data_type,
&result_storage_class);
- if (result_storage_class != SpvStorageClassPhysicalStorageBufferEXT)
+ if (result_storage_class != SpvStorageClassPhysicalStorageBuffer)
return _.diag(SPV_ERROR_INVALID_DATA, inst)
- << "Pointer storage class must be PhysicalStorageBufferEXT: "
+ << "Pointer storage class must be PhysicalStorageBuffer: "
<< spvOpcodeString(opcode);
+
+ if (spvIsVulkanEnv(_.context()->target_env)) {
+ if (_.GetBitWidth(input_type) != 64) {
+ return _.diag(SPV_ERROR_INVALID_DATA, inst)
+ << _.VkErrorID(4710)
+ << "PhysicalStorageBuffer64 addressing mode requires the "
+ "input integer to have a 64-bit width for Vulkan "
+ "environment.";
+ }
+ }
}
break;
}
diff --git a/source/val/validation_state.cpp b/source/val/validation_state.cpp
index 3268e424..746efd05 100644
--- a/source/val/validation_state.cpp
+++ b/source/val/validation_state.cpp
@@ -1714,6 +1714,8 @@ std::string ValidationState_t::VkErrorID(uint32_t id,
return VUID_WRAP(VUID-StandaloneSpirv-OpGroupNonUniformBallotBitCount-04685);
case 4686:
return VUID_WRAP(VUID-StandaloneSpirv-None-04686);
+ case 4710:
+ return VUID_WRAP(VUID-StandaloneSpirv-PhysicalStorageBuffer64-04710);
case 4711:
return VUID_WRAP(VUID-StandaloneSpirv-OpTypeForwardPointer-04711);
case 4730:
diff --git a/test/val/val_conversion_test.cpp b/test/val/val_conversion_test.cpp
index 47e67938..b9802ece 100644
--- a/test/val/val_conversion_test.cpp
+++ b/test/val/val_conversion_test.cpp
@@ -1464,16 +1464,16 @@ OpFunctionEnd
TEST_F(ValidateConversion, ConvertUToPtrPSBSuccess) {
const std::string body = R"(
-OpCapability PhysicalStorageBufferAddressesEXT
+OpCapability PhysicalStorageBufferAddresses
OpCapability Int64
OpCapability Shader
OpExtension "SPV_EXT_physical_storage_buffer"
-OpMemoryModel PhysicalStorageBuffer64EXT GLSL450
+OpMemoryModel PhysicalStorageBuffer64 GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
%uint64 = OpTypeInt 64 0
%u64_1 = OpConstant %uint64 1
-%ptr = OpTypePointer PhysicalStorageBufferEXT %uint64
+%ptr = OpTypePointer PhysicalStorageBuffer %uint64
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
%main = OpFunction %void None %voidfn
@@ -1489,11 +1489,11 @@ OpFunctionEnd
TEST_F(ValidateConversion, ConvertUToPtrPSBStorageClass) {
const std::string body = R"(
-OpCapability PhysicalStorageBufferAddressesEXT
+OpCapability PhysicalStorageBufferAddresses
OpCapability Int64
OpCapability Shader
OpExtension "SPV_EXT_physical_storage_buffer"
-OpMemoryModel PhysicalStorageBuffer64EXT GLSL450
+OpMemoryModel PhysicalStorageBuffer64 GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
%uint64 = OpTypeInt 64 0
@@ -1513,22 +1513,54 @@ OpFunctionEnd
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Pointer storage class must be "
- "PhysicalStorageBufferEXT: ConvertUToPtr"));
+ "PhysicalStorageBuffer: ConvertUToPtr"));
+}
+
+TEST_F(ValidateConversion, ConvertUToPtrVulkanWrongWidth) {
+ const std::string body = R"(
+OpCapability PhysicalStorageBufferAddresses
+OpCapability Int64
+OpCapability Shader
+OpExtension "SPV_EXT_physical_storage_buffer"
+OpMemoryModel PhysicalStorageBuffer64 GLSL450
+OpEntryPoint Fragment %main "main"
+OpExecutionMode %main OriginUpperLeft
+%uint32 = OpTypeInt 32 0
+%uint64 = OpTypeInt 64 0
+%u32_1 = OpConstant %uint32 1
+%ptr = OpTypePointer PhysicalStorageBuffer %uint64
+%void = OpTypeVoid
+%voidfn = OpTypeFunction %void
+%main = OpFunction %void None %voidfn
+%entry = OpLabel
+%val1 = OpConvertUToPtr %ptr %u32_1
+OpReturn
+OpFunctionEnd
+)";
+
+ CompileSuccessfully(body.c_str());
+ ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
+ EXPECT_THAT(getDiagnosticString(),
+ AnyVUID("VUID-StandaloneSpirv-PhysicalStorageBuffer64-04710"));
+ EXPECT_THAT(
+ getDiagnosticString(),
+ HasSubstr("PhysicalStorageBuffer64 addressing mode requires the input "
+ "integer to have a 64-bit width for Vulkan environment."));
}
TEST_F(ValidateConversion, ConvertPtrToUPSBSuccess) {
const std::string body = R"(
-OpCapability PhysicalStorageBufferAddressesEXT
+OpCapability PhysicalStorageBufferAddresses
OpCapability Int64
OpCapability Shader
OpExtension "SPV_EXT_physical_storage_buffer"
-OpMemoryModel PhysicalStorageBuffer64EXT GLSL450
+OpMemoryModel PhysicalStorageBuffer64 GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
OpDecorate %val1 RestrictPointerEXT
%uint64 = OpTypeInt 64 0
%u64_1 = OpConstant %uint64 1
-%ptr = OpTypePointer PhysicalStorageBufferEXT %uint64
+%ptr = OpTypePointer PhysicalStorageBuffer %uint64
%pptr_f = OpTypePointer Function %ptr
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
@@ -1547,11 +1579,11 @@ OpFunctionEnd
TEST_F(ValidateConversion, ConvertPtrToUPSBStorageClass) {
const std::string body = R"(
-OpCapability PhysicalStorageBufferAddressesEXT
+OpCapability PhysicalStorageBufferAddresses
OpCapability Int64
OpCapability Shader
OpExtension "SPV_EXT_physical_storage_buffer"
-OpMemoryModel PhysicalStorageBuffer64EXT GLSL450
+OpMemoryModel PhysicalStorageBuffer64 GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
%uint64 = OpTypeInt 64 0
@@ -1571,7 +1603,42 @@ OpFunctionEnd
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Pointer storage class must be "
- "PhysicalStorageBufferEXT: ConvertPtrToU"));
+ "PhysicalStorageBuffer: ConvertPtrToU"));
+}
+
+TEST_F(ValidateConversion, ConvertPtrToUVulkanWrongWidth) {
+ const std::string body = R"(
+OpCapability PhysicalStorageBufferAddresses
+OpCapability Int64
+OpCapability Shader
+OpExtension "SPV_EXT_physical_storage_buffer"
+OpMemoryModel PhysicalStorageBuffer64 GLSL450
+OpEntryPoint Fragment %main "main"
+OpExecutionMode %main OriginUpperLeft
+OpDecorate %val1 RestrictPointerEXT
+%uint32 = OpTypeInt 32 0
+%uint64 = OpTypeInt 64 0
+%ptr = OpTypePointer PhysicalStorageBuffer %uint64
+%pptr_f = OpTypePointer Function %ptr
+%void = OpTypeVoid
+%voidfn = OpTypeFunction %void
+%main = OpFunction %void None %voidfn
+%entry = OpLabel
+%val1 = OpVariable %pptr_f Function
+%val2 = OpLoad %ptr %val1
+%val3 = OpConvertPtrToU %uint32 %val2
+OpReturn
+OpFunctionEnd
+)";
+
+ CompileSuccessfully(body.c_str());
+ ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
+ EXPECT_THAT(getDiagnosticString(),
+ AnyVUID("VUID-StandaloneSpirv-PhysicalStorageBuffer64-04710"));
+ EXPECT_THAT(
+ getDiagnosticString(),
+ HasSubstr("PhysicalStorageBuffer64 addressing mode requires the result "
+ "integer type to have a 64-bit width for Vulkan environment."));
}
using ValidateSmallConversions = spvtest::ValidateBase<std::string>;