Skip to content

Commit 9b51d3d

Browse files
authored
SPV_KHR_opacity_micromap (KhronosGroup#6670)
1 parent 62138e5 commit 9b51d3d

7 files changed

Lines changed: 326 additions & 0 deletions

source/val/validate_extensions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,7 @@ spv_result_t ValidateExtension(ValidationState_t& _, const Instruction* inst) {
13451345
if (_.version() < SPV_SPIRV_VERSION_WORD(1, 4)) {
13461346
if (extension ==
13471347
ExtensionToString(kSPV_KHR_workgroup_memory_explicit_layout) ||
1348+
extension == ExtensionToString(kSPV_KHR_opacity_micromap) ||
13481349
extension == ExtensionToString(kSPV_EXT_mesh_shader) ||
13491350
extension == ExtensionToString(kSPV_NV_shader_invocation_reorder) ||
13501351
extension == ExtensionToString(kSPV_EXT_shader_invocation_reorder) ||

source/val/validate_mode_setting.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ spv_result_t ValidateExecutionMode(ValidationState_t& _,
549549
case spv::ExecutionMode::SubgroupsPerWorkgroupId:
550550
case spv::ExecutionMode::LocalSizeHintId:
551551
case spv::ExecutionMode::LocalSizeId:
552+
case spv::ExecutionMode::OpacityMicromapIdKHR:
552553
case spv::ExecutionMode::FPFastMathDefault:
553554
case spv::ExecutionMode::MaximumRegistersIdINTEL:
554555
case spv::ExecutionMode::IsApiEntryAMDX:
@@ -635,6 +636,16 @@ spv_result_t ValidateExecutionMode(ValidationState_t& _,
635636
}
636637
}
637638
break;
639+
case spv::ExecutionMode::OpacityMicromapIdKHR: {
640+
spv::Op operand_opcode = operand_inst->opcode();
641+
if (!spvOpcodeIsConstant(operand_opcode) ||
642+
!_.IsBoolScalarType(operand_inst->type_id())) {
643+
return _.diag(SPV_ERROR_INVALID_DATA, operand_inst)
644+
<< "OpacityMicromapIdKHR's operand must be an <id> "
645+
"of a constant instruction of OpTypeBool.";
646+
}
647+
break;
648+
}
638649
default:
639650
break;
640651
}

source/val/validate_ray_query.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ spv_result_t RayQueryPass(ValidationState_t& _, const Instruction* inst) {
9999
<< "Ray Flags must be a 32-bit int scalar";
100100
}
101101

102+
if (!_.CheckForceOpacityMicromap2StateKHRCapabilityRequirement(inst, 2)) {
103+
return _.diag(SPV_ERROR_INVALID_CAPABILITY, inst)
104+
<< "The ForceOpacityMicromap2StateKHR flag requires the "
105+
"RayTracingOpacityMicromapKHR and RayQueryKHR or "
106+
"RayTracingKHR capabilities";
107+
}
108+
102109
const uint32_t cull_mask = _.GetOperandTypeId(inst, 3);
103110
if (!_.IsIntScalarType(cull_mask, 32)) {
104111
return _.diag(SPV_ERROR_INVALID_DATA, inst)

source/val/validate_ray_tracing.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ spv_result_t ValidateTraceRay(ValidationState_t& _, const Instruction* inst) {
5858
<< "Cull Mask must be a 32-bit int scalar";
5959
}
6060

61+
if (!_.CheckForceOpacityMicromap2StateKHRCapabilityRequirement(inst, 1)) {
62+
return _.diag(SPV_ERROR_INVALID_CAPABILITY, inst)
63+
<< "The ForceOpacityMicromap2StateKHR flag requires the "
64+
"RayTracingOpacityMicromapKHR and RayQueryKHR or "
65+
"RayTracingKHR capabilities";
66+
}
67+
6168
const uint32_t sbt_offset = _.GetOperandTypeId(inst, 3);
6269
if (!_.IsIntScalarType(sbt_offset, 32)) {
6370
return _.diag(SPV_ERROR_INVALID_DATA, inst)

source/val/validation_state.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,23 @@ class ValidationState_t {
932932
return SpvDecorationString(uint32_t(decoration));
933933
}
934934

935+
bool CheckForceOpacityMicromap2StateKHRCapabilityRequirement(
936+
const Instruction* inst, uint32_t flag_operand) {
937+
bool retval = true;
938+
uint64_t flag_val = 0;
939+
if (EvalConstantValUint64(inst->GetOperandAs<uint32_t>(flag_operand),
940+
&flag_val)) {
941+
if ((flag_val & static_cast<uint64_t>(
942+
spv::RayFlagsMask::ForceOpacityMicromap2StateKHR)) !=
943+
0) {
944+
assert(HasCapability(spv::Capability::RayQueryKHR) ||
945+
HasCapability(spv::Capability::RayTracingKHR));
946+
retval = HasCapability(spv::Capability::RayTracingOpacityMicromapKHR);
947+
}
948+
}
949+
return retval;
950+
}
951+
935952
// Returns whether type result_type_id and type m2 are cooperative matrices
936953
// with the same "shape" (matching scope, rows, cols). If any are
937954
// specialization constants, we assume they can match because we can't prove

test/val/val_ray_query_test.cpp

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

test/val/val_ray_tracing_test.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,46 @@ TEST_F(ValidateRayTracing, RayTracingPositionFetchCapability) {
698698
"RayTracingPositionFetchKHR"));
699699
}
700700

701+
TEST_F(ValidateRayTracing, ForceOpacityMicromap2StateKHRCapabilityCheck) {
702+
const std::string shader = R"(
703+
OpCapability Shader
704+
OpCapability RayTracingKHR
705+
OpExtension "SPV_KHR_opacity_micromap"
706+
OpExtension "SPV_KHR_ray_tracing"
707+
OpMemoryModel Logical GLSL450
708+
OpEntryPoint RayGenerationKHR %main "main" %4725 %payload
709+
%void = OpTypeVoid
710+
%3 = OpTypeFunction %void
711+
%uint = OpTypeInt 32 0
712+
%_st_4530 = OpTypeStruct %uint
713+
%_ptr = OpTypePointer RayPayloadKHR %_st_4530
714+
%float = OpTypeFloat 32
715+
%v3float = OpTypeVector %float 3
716+
%4723 = OpTypeAccelerationStructureKHR
717+
%_ptr_UniformConstant_4723 = OpTypePointer UniformConstant %4723
718+
%4725 = OpVariable %_ptr_UniformConstant_4723 UniformConstant
719+
%payload = OpVariable %_ptr RayPayloadKHR
720+
%uint_1 = OpConstant %uint 1
721+
%uint_2 = OpConstant %uint 2
722+
%flag = OpConstant %uint 1024
723+
%float_1 = OpConstant %float 1
724+
%v3float_1 = OpConstantComposite %v3float %float_1 %float_1 %float_1
725+
%main = OpFunction %void None %3
726+
%main_label = OpLabel
727+
%4726 = OpLoad %4723 %4725
728+
OpTraceRayKHR %4726 %flag %uint_1 %uint_2 %uint_1 %uint_2 %v3float_1 %float_1 %v3float_1 %float_1 %payload
729+
OpReturn
730+
OpFunctionEnd
731+
)";
732+
CompileSuccessfully(shader.c_str(), SPV_ENV_UNIVERSAL_1_4);
733+
ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY,
734+
ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
735+
EXPECT_THAT(getDiagnosticString(),
736+
HasSubstr("The ForceOpacityMicromap2StateKHR flag requires the "
737+
"RayTracingOpacityMicromapKHR and RayQueryKHR or "
738+
"RayTracingKHR capabilities"));
739+
}
740+
701741
} // namespace
702742
} // namespace val
703743
} // namespace spvtools

0 commit comments

Comments
 (0)