================
@@ -468,12 +469,44 @@ void CGHLSLRuntime::addHLSLBufferLayoutType(const
RecordType *StructType,
LayoutTypes[StructType] = LayoutTy;
}
+class VkExtExtensionVisitor
+ : public RecursiveASTVisitor<VkExtExtensionVisitor> {
+ llvm::StringSet<> &Extensions;
+
+public:
+ VkExtExtensionVisitor(llvm::StringSet<> &Exts) : Extensions(Exts) {}
+ bool VisitDecl(Decl *D) {
+ for (const auto *ExtAttr : D->specific_attrs<HLSLVkExtExtensionAttr>()) {
+ Extensions.insert(ExtAttr->getExtensionName());
+ }
+ return true;
+ }
+};
+
void CGHLSLRuntime::finishCodeGen() {
auto &TargetOpts = CGM.getTarget().getTargetOpts();
auto &CodeGenOpts = CGM.getCodeGenOpts();
auto &LangOpts = CGM.getLangOpts();
llvm::Module &M = CGM.getModule();
Triple T(M.getTargetTriple());
+
+ if (T.isSPIRV()) {
+ llvm::StringSet<> SPIRVExtensions;
+ VkExtExtensionVisitor Visitor(SPIRVExtensions);
+ Visitor.TraverseDecl(CGM.getContext().getTranslationUnitDecl());
+
+ if (!SPIRVExtensions.empty()) {
+ llvm::LLVMContext &Ctx = CGM.getLLVMContext();
+ llvm::NamedMDNode *SpirvExtMD =
+ CGM.getModule().getOrInsertNamedMetadata("spirv.ext");
+
+ for (const auto &Ext : SPIRVExtensions) {
+ auto *MStr = llvm::MDString::get(Ctx, Ext.getKey());
+ SpirvExtMD->addOperand(llvm::MDNode::get(Ctx, MStr));
+ }
+ }
+ }
----------------
Keenuts wrote:
We may need to keep the decl<>extension association.
In DXC, we had issues because of caps/extensions being requested even when the
shader was not using the feature
(https://github.com/microsoft/DirectXShaderCompiler/issues/4795 )
This is a problem for ubershaders or similar: if a utility function uses
anything relates to SPV_KHR_some_extention, even if it's dead-code, the
extension will be required.
I think we should keep the requested<>ext link in the IR. Maybe this could be
an instruction/global attribute? This way, we can let LLVM optimize our IR, and
we only get the used extensions/capabilities at the end.
https://github.com/llvm/llvm-project/pull/187632
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits