@@ -23,15 +23,18 @@ void CapabilityVisitor::addExtension(Extension ext, llvm::StringRef target,
23
23
spvBuilder.requireExtension (featureManager.getExtensionName (ext), loc);
24
24
}
25
25
26
- void CapabilityVisitor::addExtensionAndCapabilitiesIfEnabled (
26
+ bool CapabilityVisitor::addExtensionAndCapabilitiesIfEnabled (
27
27
Extension ext, llvm::ArrayRef<spv::Capability> capabilities) {
28
- if (featureManager.isExtensionEnabled (ext)) {
29
- addExtension (ext, " " , {});
28
+ if (!featureManager.isExtensionEnabled (ext)) {
29
+ return false ;
30
+ }
30
31
31
- for (auto cap : capabilities) {
32
- addCapability (cap);
33
- }
32
+ addExtension (ext, " " , {});
33
+
34
+ for (auto cap : capabilities) {
35
+ addCapability (cap);
34
36
}
37
+ return true ;
35
38
}
36
39
37
40
void CapabilityVisitor::addCapability (spv::Capability cap, SourceLocation loc) {
@@ -225,18 +228,6 @@ void CapabilityVisitor::addCapabilityForType(const SpirvType *type,
225
228
for (auto field : structType->getFields ())
226
229
addCapabilityForType (field.type , loc, sc);
227
230
}
228
- // AccelerationStructureTypeNV and RayQueryTypeKHR type
229
- // Note: Because AccelerationStructureType can be provided by both
230
- // SPV_KHR_ray_query and SPV_{NV,KHR}_ray_tracing extensions, this logic will
231
- // result in SPV_KHR_ray_query being unnecessarily required in some cases. If
232
- // this is an issue in future (more devices are identified that support
233
- // ray_tracing but not ray_query), then we should consider addressing this
234
- // interaction with a spirv-opt pass instead.
235
- else if (isa<AccelerationStructureTypeNV>(type) ||
236
- isa<RayQueryTypeKHR>(type)) {
237
- addCapability (spv::Capability::RayQueryKHR);
238
- addExtension (Extension::KHR_ray_query, " SPV_KHR_ray_query" , {});
239
- }
240
231
}
241
232
242
233
bool CapabilityVisitor::visit (SpirvDecoration *decor) {
@@ -888,6 +879,18 @@ bool CapabilityVisitor::visit(SpirvModule *, Visitor::Phase phase) {
888
879
spv::Capability::FragmentShaderPixelInterlockEXT,
889
880
spv::Capability::FragmentShaderShadingRateInterlockEXT,
890
881
});
882
+
883
+ // AccelerationStructureType or RayQueryType can be provided by both
884
+ // ray_tracing and ray_query extension. By default, we select ray_query to
885
+ // provide it. This is an arbitrary decision. If the user wants avoid one
886
+ // extension (lack of support by ex), if can be done by providing the list
887
+ // of enabled extensions.
888
+ if (!addExtensionAndCapabilitiesIfEnabled (Extension::KHR_ray_query,
889
+ {spv::Capability::RayQueryKHR})) {
890
+ addExtensionAndCapabilitiesIfEnabled (Extension::KHR_ray_tracing,
891
+ {spv::Capability::RayTracingKHR});
892
+ }
893
+
891
894
return true ;
892
895
}
893
896
0 commit comments