@@ -3934,6 +3934,158 @@ OpMemoryModel Logical GLSL450
3934
3934
HasSubstr (" Initializer type must match the data type" ));
3935
3935
}
3936
3936
3937
+ TEST_F (ValidateMemory, StoreToImage) {
3938
+ const std::string spirv = R"(
3939
+ OpCapability Shader
3940
+ OpMemoryModel Logical GLSL450
3941
+ OpEntryPoint GLCompute %main "main"
3942
+ OpExecutionMode %main LocalSize 1 1 1
3943
+ %void = OpTypeVoid
3944
+ %int = OpTypeInt 32 0
3945
+ %img = OpTypeImage %int 2D 2 0 0 2 R32i
3946
+ %ptr_img = OpTypePointer Function %img
3947
+ %void_fn = OpTypeFunction %void
3948
+ %main = OpFunction %void None %void_fn
3949
+ %entry = OpLabel
3950
+ %var = OpVariable %ptr_img Function
3951
+ %value = OpLoad %img %var
3952
+ OpStore %var %value
3953
+ OpReturn
3954
+ OpFunctionEnd
3955
+ )" ;
3956
+ CompileSuccessfully (spirv, SPV_ENV_VULKAN_1_1);
3957
+ EXPECT_EQ (SPV_ERROR_INVALID_ID, ValidateInstructions (SPV_ENV_VULKAN_1_1));
3958
+ EXPECT_THAT (getDiagnosticString (),
3959
+ AnyVUID (" VUID-StandaloneSpirv-OpTypeImage-06924" ));
3960
+ EXPECT_THAT (
3961
+ getDiagnosticString (),
3962
+ HasSubstr (" Cannot store to OpTypeImage, OpTypeSampler, "
3963
+ " OpTypeSampledImage, or OpTypeAccelerationStructureKHR" ));
3964
+ }
3965
+
3966
+ TEST_F (ValidateMemory, StoreToImageArray) {
3967
+ const std::string spirv = R"(
3968
+ OpCapability Shader
3969
+ OpMemoryModel Logical GLSL450
3970
+ OpEntryPoint GLCompute %main "main"
3971
+ OpExecutionMode %main LocalSize 1 1 1
3972
+ %void = OpTypeVoid
3973
+ %int = OpTypeInt 32 0
3974
+ %img = OpTypeImage %int 2D 2 0 0 2 R32i
3975
+ %arr_size = OpConstant %int 5
3976
+ %i = OpConstant %int 2
3977
+ %arr_img = OpTypeArray %img %arr_size
3978
+ %ptr_img = OpTypePointer Function %img
3979
+ %ptr_arr_img = OpTypePointer Function %arr_img
3980
+ %void_fn = OpTypeFunction %void
3981
+ %main = OpFunction %void None %void_fn
3982
+ %entry = OpLabel
3983
+ %var = OpVariable %ptr_arr_img Function
3984
+ %value = OpLoad %arr_img %var
3985
+ OpStore %var %value
3986
+ OpReturn
3987
+ OpFunctionEnd
3988
+ )" ;
3989
+ CompileSuccessfully (spirv, SPV_ENV_VULKAN_1_1);
3990
+ EXPECT_EQ (SPV_ERROR_INVALID_ID, ValidateInstructions (SPV_ENV_VULKAN_1_1));
3991
+ EXPECT_THAT (getDiagnosticString (),
3992
+ AnyVUID (" VUID-StandaloneSpirv-OpTypeImage-06924" ));
3993
+ EXPECT_THAT (
3994
+ getDiagnosticString (),
3995
+ HasSubstr (" Cannot store to OpTypeImage, OpTypeSampler, "
3996
+ " OpTypeSampledImage, or OpTypeAccelerationStructureKHR" ));
3997
+ }
3998
+
3999
+ TEST_F (ValidateMemory, StoreToSampler) {
4000
+ const std::string spirv = R"(
4001
+ OpCapability Shader
4002
+ OpMemoryModel Logical GLSL450
4003
+ OpEntryPoint GLCompute %main "main"
4004
+ OpExecutionMode %main LocalSize 1 1 1
4005
+ %void = OpTypeVoid
4006
+ %smp = OpTypeSampler
4007
+ %ptr_smp = OpTypePointer Function %smp
4008
+ %void_fn = OpTypeFunction %void
4009
+ %main = OpFunction %void None %void_fn
4010
+ %entry = OpLabel
4011
+ %var = OpVariable %ptr_smp Function
4012
+ %value = OpLoad %smp %var
4013
+ OpStore %var %value
4014
+ OpReturn
4015
+ OpFunctionEnd
4016
+ )" ;
4017
+ CompileSuccessfully (spirv, SPV_ENV_VULKAN_1_1);
4018
+ EXPECT_EQ (SPV_ERROR_INVALID_ID, ValidateInstructions (SPV_ENV_VULKAN_1_1));
4019
+ EXPECT_THAT (getDiagnosticString (),
4020
+ AnyVUID (" VUID-StandaloneSpirv-OpTypeImage-06924" ));
4021
+ EXPECT_THAT (
4022
+ getDiagnosticString (),
4023
+ HasSubstr (" Cannot store to OpTypeImage, OpTypeSampler, "
4024
+ " OpTypeSampledImage, or OpTypeAccelerationStructureKHR" ));
4025
+ }
4026
+
4027
+ TEST_F (ValidateMemory, StoreToSampledImage) {
4028
+ const std::string spirv = R"(
4029
+ OpCapability Shader
4030
+ OpMemoryModel Logical GLSL450
4031
+ OpEntryPoint GLCompute %main "main"
4032
+ OpExecutionMode %main LocalSize 1 1 1
4033
+ %void = OpTypeVoid
4034
+ %int = OpTypeInt 32 0
4035
+ %img = OpTypeImage %int 2D 2 0 0 1 R32i
4036
+ %samp_img = OpTypeSampledImage %img
4037
+ %ptr_samp_img = OpTypePointer Function %samp_img
4038
+ %void_fn = OpTypeFunction %void
4039
+ %main = OpFunction %void None %void_fn
4040
+ %entry = OpLabel
4041
+ %var = OpVariable %ptr_samp_img Function
4042
+ %value = OpLoad %samp_img %var
4043
+ OpStore %var %value
4044
+ OpReturn
4045
+ OpFunctionEnd
4046
+ )" ;
4047
+
4048
+ CompileSuccessfully (spirv, SPV_ENV_VULKAN_1_1);
4049
+ EXPECT_EQ (SPV_ERROR_INVALID_ID, ValidateInstructions (SPV_ENV_VULKAN_1_1));
4050
+ EXPECT_THAT (getDiagnosticString (),
4051
+ AnyVUID (" VUID-StandaloneSpirv-OpTypeImage-06924" ));
4052
+ EXPECT_THAT (
4053
+ getDiagnosticString (),
4054
+ HasSubstr (" Cannot store to OpTypeImage, OpTypeSampler, "
4055
+ " OpTypeSampledImage, or OpTypeAccelerationStructureKHR" ));
4056
+ }
4057
+
4058
+ TEST_F (ValidateMemory, StoreToAccelarationStructureKHR) {
4059
+ const std::string spirv = R"(
4060
+ OpCapability Shader
4061
+ OpCapability RayQueryKHR
4062
+ OpExtension "SPV_KHR_ray_query"
4063
+ OpMemoryModel Logical GLSL450
4064
+ OpEntryPoint GLCompute %main "main"
4065
+ OpExecutionMode %main LocalSize 1 1 1
4066
+ %void = OpTypeVoid
4067
+ %as = OpTypeAccelerationStructureKHR
4068
+ %ptr_as = OpTypePointer Function %as
4069
+ %void_fn = OpTypeFunction %void
4070
+ %main = OpFunction %void None %void_fn
4071
+ %entry = OpLabel
4072
+ %var = OpVariable %ptr_as Function
4073
+ %value = OpLoad %as %var
4074
+ OpStore %var %value
4075
+ OpReturn
4076
+ OpFunctionEnd
4077
+ )" ;
4078
+
4079
+ CompileSuccessfully (spirv, SPV_ENV_VULKAN_1_1);
4080
+ EXPECT_EQ (SPV_ERROR_INVALID_ID, ValidateInstructions (SPV_ENV_VULKAN_1_1));
4081
+ EXPECT_THAT (getDiagnosticString (),
4082
+ AnyVUID (" VUID-StandaloneSpirv-OpTypeImage-06924" ));
4083
+ EXPECT_THAT (
4084
+ getDiagnosticString (),
4085
+ HasSubstr (" Cannot store to OpTypeImage, OpTypeSampler, "
4086
+ " OpTypeSampledImage, or OpTypeAccelerationStructureKHR" ));
4087
+ }
4088
+
3937
4089
TEST_F (ValidateMemory, StoreToUniformBlock) {
3938
4090
const std::string spirv = R"(
3939
4091
OpCapability Shader
0 commit comments