//===----------------------------------------------------------------------===//
#include "DXILMetadata.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
}
bool ValidatorVersionMD::isEmpty() { return Entry->getNumOperands() == 0; }
+
+static StringRef getShortShaderStage(Triple::EnvironmentType Env) {
+ switch (Env) {
+ case Triple::Pixel:
+ return "ps";
+ case Triple::Vertex:
+ return "vs";
+ case Triple::Geometry:
+ return "gs";
+ case Triple::Hull:
+ return "hs";
+ case Triple::Domain:
+ return "ds";
+ case Triple::Compute:
+ return "cs";
+ case Triple::Library:
+ return "lib";
+ case Triple::Mesh:
+ return "ms";
+ case Triple::Amplification:
+ return "as";
+ default:
+ break;
+ }
+ llvm_unreachable("Unsupported environment for DXIL generation.");
+ return "";
+}
+
+void dxil::createShaderModelMD(Module &M) {
+ NamedMDNode *Entry = M.getOrInsertNamedMetadata("dx.shaderModel");
+ Triple TT(M.getTargetTriple());
+ VersionTuple Ver = TT.getOSVersion();
+ LLVMContext &Ctx = M.getContext();
+ IRBuilder<> B(Ctx);
+
+ Metadata *Vals[3];
+ Vals[0] = MDString::get(Ctx, getShortShaderStage(TT.getEnvironment()));
+ Vals[1] = ConstantAsMetadata::get(B.getInt32(Ver.getMajor()));
+ Vals[2] = ConstantAsMetadata::get(B.getInt32(Ver.getMinor().value_or(0)));
+ Entry->addOperand(MDNode::get(Ctx, Vals));
+}
bool isEmpty();
};
+void createShaderModelMD(Module &M);
+
} // namespace dxil
} // namespace llvm
dxil::ValidatorVersionMD ValVerMD(M);
if (ValVerMD.isEmpty())
ValVerMD.update(VersionTuple(1, 0));
+ dxil::createShaderModelMD(M);
return false;
}
--- /dev/null
+; RUN: opt -S -dxil-metadata-emit %s | FileCheck %s
+target triple = "dxil-pc-shadermodel6-amplification"
+
+; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
+; CHECK: ![[SM]] = !{!"as", i32 6, i32 0}
--- /dev/null
+; RUN: opt -S -dxil-metadata-emit %s | FileCheck %s
+target triple = "dxil-pc-shadermodel6.6-compute"
+
+; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
+; CHECK: ![[SM]] = !{!"cs", i32 6, i32 6}
--- /dev/null
+; RUN: opt -S -dxil-metadata-emit %s | FileCheck %s
+target triple = "dxil-pc-shadermodel6.6-geometry"
+
+; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
+; CHECK: ![[SM]] = !{!"gs", i32 6, i32 6}
--- /dev/null
+; RUN: opt -S -dxil-metadata-emit %s | FileCheck %s
+target triple = "dxil-pc-shadermodel6.6-hull"
+
+; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
+; CHECK: ![[SM]] = !{!"hs", i32 6, i32 6}
--- /dev/null
+; RUN: opt -S -dxil-metadata-emit %s | FileCheck %s
+target triple = "dxil-pc-shadermodel6.3-library"
+
+; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
+; CHECK: ![[SM]] = !{!"lib", i32 6, i32 3}
--- /dev/null
+; RUN: opt -S -dxil-metadata-emit %s | FileCheck %s
+target triple = "dxil-pc-shadermodel6.6-mesh"
+
+; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
+; CHECK: ![[SM]] = !{!"ms", i32 6, i32 6}
--- /dev/null
+; RUN: opt -S -dxil-metadata-emit %s | FileCheck %s
+target triple = "dxil-pc-shadermodel5.0-pixel"
+
+; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
+; CHECK: ![[SM]] = !{!"ps", i32 5, i32 0}
--- /dev/null
+; RUN: opt -S -dxil-metadata-emit %s | FileCheck %s
+target triple = "dxil-pc-shadermodel-vertex"
+
+; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
+; CHECK: ![[SM]] = !{!"vs", i32 0, i32 0}