@@ -870,6 +870,249 @@ TEST_F(ValidateRayQuery,
870870 " point vector as Result Type" ));
871871}
872872
873+ TEST_F (ValidateRayQuery, RayQueryOpacityMicromapSpvVersionCheck) {
874+ const std::string shader = R"(
875+ OpCapability Shader
876+ OpCapability RayQueryKHR
877+ OpCapability RayTracingOpacityMicromapExecutionModeKHR
878+ OpExtension "SPV_KHR_ray_query"
879+ OpExtension "SPV_KHR_opacity_micromap"
880+ OpMemoryModel Logical GLSL450
881+ OpEntryPoint GLCompute %main "main"
882+ OpExecutionMode %main LocalSize 1 1 1
883+ OpExecutionModeId %main OpacityMicromapIdKHR %enable
884+ OpDecorate %enable SpecId 4
885+ %void = OpTypeVoid
886+ %3 = OpTypeFunction %void
887+ %bool = OpTypeBool
888+ %enable = OpSpecConstantFalse %bool
889+ %main = OpFunction %void None %3
890+ %main_label = OpLabel
891+ OpReturn
892+ OpFunctionEnd
893+ )" ;
894+ CompileSuccessfully (shader.c_str (), SPV_ENV_UNIVERSAL_1_3 );
895+ ASSERT_EQ (SPV_ERROR_WRONG_VERSION ,
896+ ValidateInstructions (SPV_ENV_UNIVERSAL_1_3 ));
897+ EXPECT_THAT (getDiagnosticString (),
898+ HasSubstr (" SPV_KHR_opacity_micromap extension requires SPIR-V "
899+ " version 1.4 or later." ));
900+ }
901+
902+ TEST_F (ValidateRayQuery, OpacityMicromapExtensionStringIsMissing) {
903+ const std::string shader = R"(
904+ OpCapability Shader
905+ OpCapability RayQueryKHR
906+ OpCapability RayTracingOpacityMicromapExecutionModeKHR
907+ OpExtension "SPV_KHR_ray_query"
908+ OpMemoryModel Logical GLSL450
909+ OpEntryPoint GLCompute %main "main"
910+ OpExecutionMode %main LocalSize 1 1 1
911+ OpExecutionModeId %main OpacityMicromapIdKHR %enable
912+ OpDecorate %enable SpecId 4
913+ %void = OpTypeVoid
914+ %3 = OpTypeFunction %void
915+ %bool = OpTypeBool
916+ %enable = OpSpecConstantFalse %bool
917+ %main = OpFunction %void None %3
918+ %main_label = OpLabel
919+ OpReturn
920+ OpFunctionEnd
921+ )" ;
922+ CompileSuccessfully (shader.c_str (), SPV_ENV_UNIVERSAL_1_4 );
923+ ASSERT_EQ (SPV_ERROR_MISSING_EXTENSION ,
924+ ValidateInstructions (SPV_ENV_UNIVERSAL_1_4 ));
925+ EXPECT_THAT (
926+ getDiagnosticString (),
927+ HasSubstr (" requires one of these extensions: SPV_KHR_opacity_micromap" ));
928+ }
929+
930+ TEST_F (ValidateRayQuery,
931+ OpacityMicromapExecutionModeRejectsEXTExtensionString) {
932+ const std::string shader = R"(
933+ OpCapability Shader
934+ OpCapability RayQueryKHR
935+ OpCapability RayTracingOpacityMicromapExecutionModeKHR
936+ OpExtension "SPV_KHR_ray_query"
937+ OpExtension "SPV_EXT_opacity_micromap"
938+ OpMemoryModel Logical GLSL450
939+ OpEntryPoint GLCompute %main "main"
940+ OpExecutionMode %main LocalSize 1 1 1
941+ OpExecutionModeId %main OpacityMicromapIdKHR %enable
942+ OpDecorate %enable SpecId 4
943+ %void = OpTypeVoid
944+ %3 = OpTypeFunction %void
945+ %bool = OpTypeBool
946+ %enable = OpSpecConstantFalse %bool
947+ %main = OpFunction %void None %3
948+ %main_label = OpLabel
949+ OpReturn
950+ OpFunctionEnd
951+ )" ;
952+ CompileSuccessfully (shader.c_str (), SPV_ENV_UNIVERSAL_1_4 );
953+ ASSERT_EQ (SPV_ERROR_MISSING_EXTENSION ,
954+ ValidateInstructions (SPV_ENV_UNIVERSAL_1_4 ));
955+ EXPECT_THAT (
956+ getDiagnosticString (),
957+ HasSubstr (" requires one of these extensions: SPV_KHR_opacity_micromap" ));
958+ }
959+
960+ TEST_F (ValidateRayQuery, RayQueryOpacityMicromapId_1) {
961+ const std::string shader = R"(
962+ OpCapability Shader
963+ OpCapability RayQueryKHR
964+ OpCapability RayTracingOpacityMicromapExecutionModeKHR
965+ OpExtension "SPV_KHR_opacity_micromap"
966+ OpExtension "SPV_KHR_ray_query"
967+ OpMemoryModel Logical GLSL450
968+ OpEntryPoint GLCompute %main "main"
969+ OpExecutionMode %main LocalSize 1 1 1
970+ OpExecutionModeId %main OpacityMicromapIdKHR %omm
971+ %void = OpTypeVoid
972+ %3 = OpTypeFunction %void
973+ %i32 = OpTypeInt 32 0
974+ %omm = OpConstant %i32 9
975+ %main = OpFunction %void None %3
976+ %main_label = OpLabel
977+ OpReturn
978+ OpFunctionEnd
979+ )" ;
980+ CompileSuccessfully (shader.c_str (), SPV_ENV_UNIVERSAL_1_4 );
981+ ASSERT_EQ (SPV_ERROR_INVALID_DATA ,
982+ ValidateInstructions (SPV_ENV_UNIVERSAL_1_4 ));
983+ EXPECT_THAT (getDiagnosticString (),
984+ HasSubstr (" OpacityMicromapIdKHR's operand must be an <id> of a "
985+ " constant instruction of OpTypeBool" ));
986+ }
987+
988+ TEST_F (ValidateRayQuery, RayQueryOpacityMicromapId_2) {
989+ const std::string shader = R"(
990+ OpCapability Shader
991+ OpCapability RayQueryKHR
992+ OpCapability RayTracingOpacityMicromapExecutionModeKHR
993+ OpExtension "SPV_KHR_opacity_micromap"
994+ OpExtension "SPV_KHR_ray_query"
995+ OpMemoryModel Logical GLSL450
996+ OpEntryPoint GLCompute %main "main"
997+ OpExecutionMode %main LocalSize 1 1 1
998+ OpExecutionModeId %main OpacityMicromapIdKHR %omm
999+ OpDecorate %omm SpecId 4
1000+ %void = OpTypeVoid
1001+ %3 = OpTypeFunction %void
1002+ %i32 = OpTypeInt 32 0
1003+ %omm = OpSpecConstant %i32 9
1004+ %main = OpFunction %void None %3
1005+ %main_label = OpLabel
1006+ OpReturn
1007+ OpFunctionEnd
1008+ )" ;
1009+ CompileSuccessfully (shader.c_str (), SPV_ENV_UNIVERSAL_1_4 );
1010+ ASSERT_EQ (SPV_ERROR_INVALID_DATA ,
1011+ ValidateInstructions (SPV_ENV_UNIVERSAL_1_4 ));
1012+ EXPECT_THAT (getDiagnosticString (),
1013+ HasSubstr (" OpacityMicromapIdKHR's operand must be an <id> of a "
1014+ " constant instruction of OpTypeBool" ));
1015+ }
1016+
1017+ TEST_F (ValidateRayQuery, RayQueryOpacityMicromapId_4) {
1018+ const std::string shader = R"(
1019+ OpCapability Shader
1020+ OpCapability RayQueryKHR
1021+ OpCapability RayTracingOpacityMicromapKHR
1022+ OpExtension "SPV_KHR_opacity_micromap"
1023+ OpExtension "SPV_KHR_ray_query"
1024+ OpMemoryModel Logical GLSL450
1025+ OpEntryPoint GLCompute %main "main"
1026+ OpExecutionMode %main LocalSize 1 1 1
1027+ OpExecutionModeId %main OpacityMicromapIdKHR %omm
1028+ OpDecorate %omm SpecId 4
1029+ %void = OpTypeVoid
1030+ %3 = OpTypeFunction %void
1031+ %bool = OpTypeBool
1032+ %omm = OpSpecConstantFalse %bool
1033+ %main = OpFunction %void None %3
1034+ %main_label = OpLabel
1035+ OpReturn
1036+ OpFunctionEnd
1037+ )" ;
1038+ CompileSuccessfully (shader.c_str (), SPV_ENV_UNIVERSAL_1_4 );
1039+ ASSERT_EQ (SPV_ERROR_INVALID_CAPABILITY ,
1040+ ValidateInstructions (SPV_ENV_UNIVERSAL_1_4 ));
1041+ EXPECT_THAT (
1042+ getDiagnosticString (),
1043+ HasSubstr (" Operand 2 of ExecutionModeId requires one of these "
1044+ " capabilities: RayTracingOpacityMicromapExecutionModeKHR" ));
1045+ }
1046+
1047+ TEST_F (ValidateRayQuery,
1048+ RayQueryInitializeForceOpacityMicromap2StateKHRCapabilityCheck) {
1049+ const std::string shader = R"(
1050+ OpCapability Shader
1051+ OpCapability RayQueryKHR
1052+ OpExtension "SPV_KHR_opacity_micromap"
1053+ OpExtension "SPV_KHR_ray_query"
1054+ OpMemoryModel Logical GLSL450
1055+ OpEntryPoint GLCompute %main "main" %4725
1056+ %void = OpTypeVoid
1057+ %3 = OpTypeFunction %void
1058+ %uint = OpTypeInt 32 0
1059+ %_st_4530 = OpTypeStruct %uint
1060+ %float = OpTypeFloat 32
1061+ %v3float = OpTypeVector %float 3
1062+ %type_rq = OpTypeRayQueryKHR
1063+ %4723 = OpTypeAccelerationStructureKHR
1064+ %_ptr_UniformConstant_4723 = OpTypePointer UniformConstant %4723
1065+ %rq_ptr = OpTypePointer Private %type_rq
1066+ %4725 = OpVariable %_ptr_UniformConstant_4723 UniformConstant
1067+ %uint_1 = OpConstant %uint 1
1068+ %uint_2 = OpConstant %uint 2
1069+ %flag = OpConstant %uint 1024
1070+ %float_1 = OpConstant %float 1
1071+ %v3float_1 = OpConstantComposite %v3float %float_1 %float_1 %float_1
1072+ %ptr_rq = OpTypePointer Function %type_rq
1073+ %main = OpFunction %void None %3
1074+ %main_label = OpLabel
1075+ %ray_query = OpVariable %ptr_rq Function
1076+ %4726 = OpLoad %4723 %4725
1077+ OpRayQueryInitializeKHR %ray_query %4726 %flag %uint_1 %v3float_1 %float_1 %v3float_1 %float_1
1078+ OpReturn
1079+ OpFunctionEnd
1080+ )" ;
1081+ CompileSuccessfully (shader.c_str (), SPV_ENV_UNIVERSAL_1_4 );
1082+ ASSERT_EQ (SPV_ERROR_INVALID_CAPABILITY ,
1083+ ValidateInstructions (SPV_ENV_UNIVERSAL_1_4 ));
1084+ EXPECT_THAT (getDiagnosticString (),
1085+ HasSubstr (" The ForceOpacityMicromap2StateKHR flag requires the "
1086+ " RayTracingOpacityMicromapKHR and RayQueryKHR or "
1087+ " RayTracingKHR capabilities" ));
1088+ }
1089+
1090+ TEST_F (ValidateRayQuery, RayQueryOpacityMicromapGood) {
1091+ const std::string shader = R"(
1092+ OpCapability Shader
1093+ OpCapability RayQueryKHR
1094+ OpCapability RayTracingOpacityMicromapKHR
1095+ OpCapability RayTracingOpacityMicromapExecutionModeKHR
1096+ OpExtension "SPV_KHR_opacity_micromap"
1097+ OpExtension "SPV_KHR_ray_query"
1098+ OpMemoryModel Logical GLSL450
1099+ OpEntryPoint GLCompute %main "main"
1100+ OpExecutionMode %main LocalSize 1 1 1
1101+ OpExecutionModeId %main OpacityMicromapIdKHR %omm
1102+ OpDecorate %omm SpecId 4
1103+ %void = OpTypeVoid
1104+ %3 = OpTypeFunction %void
1105+ %bool = OpTypeBool
1106+ %omm = OpSpecConstantFalse %bool
1107+ %main = OpFunction %void None %3
1108+ %main_label = OpLabel
1109+ OpReturn
1110+ OpFunctionEnd
1111+ )" ;
1112+ CompileSuccessfully (shader.c_str (), SPV_ENV_UNIVERSAL_1_4 );
1113+ ASSERT_EQ (SPV_SUCCESS , ValidateInstructions (SPV_ENV_UNIVERSAL_1_4 ));
1114+ }
1115+
8731116} // namespace
8741117} // namespace val
8751118} // namespace spvtools
0 commit comments