[llvm-branch-commits] [clang] [llvm] [HLSL] Generate semantic signature metadata (PR #212892)
Justin Bogner via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Aug 5 11:52:53 PDT 2026
================
@@ -1226,13 +1257,64 @@ static SemanticShape getSemanticShape(ASTContext &Ctx, QualType Ty) {
return {Rows, Cols, Ty};
}
+static llvm::dxil::ElementType getSignatureComponentType(CodeGenModule &CGM,
+ QualType Ty) {
+ if (const auto *VT = Ty->getAs<clang::VectorType>())
+ Ty = VT->getElementType();
+ else if (const auto *MT = Ty->getAs<clang::ConstantMatrixType>())
+ Ty = MT->getElementType();
+
+ llvm::Type *IRTy = CGM.getTypes().ConvertTypeForMem(Ty);
+ bool IsSigned = Ty->isSignedIntegerOrEnumerationType();
+ return llvm::dxil::toDXILElementType(IRTy, IsSigned);
+}
+
+static llvm::dxbc::PSV::SemanticKind
+getSignatureSemanticKind(StringRef SemanticName) {
+ if (!SemanticName.consume_front_insensitive("SV_"))
+ return llvm::dxbc::PSV::SemanticKind::Arbitrary;
+
+ for (const auto &Kind : llvm::dxbc::PSV::getSemanticKinds())
+ if (SemanticName.equals_insensitive(Kind.name()))
+ return Kind.value();
+
+ return llvm::dxbc::PSV::SemanticKind::Invalid;
+}
+
+static llvm::hlsl::SemanticSignatureElement createSemanticSignatureElement(
+ CodeGenModule &CGM, uint32_t SigId, HLSLAppliedSemanticAttr *Semantic,
+ std::optional<unsigned> Index, const SemanticShape &Shape) {
+ llvm::hlsl::SemanticSignatureElement Element{};
+ Element.SigId = SigId;
+ Element.SemanticName = Semantic->getAttrName()->getName();
+ Element.CompType = getSignatureComponentType(CGM, Shape.RowType);
+ Element.SemanticKind = getSignatureSemanticKind(Element.SemanticName);
+ Element.Rows = Shape.Rows;
+ Element.Cols = static_cast<uint8_t>(Shape.Cols);
+ // All members with a default value will be filled at a later stage, either
+ // during packing or analysis of usage
----------------
bogner wrote:
Can we add a constructor to `SemanticSignatureElement` that initializes all of the fields that don't have defaults? This pattern of initialization feels error-prone. I guess we'd still need a constructor that leaves everything uninitialized for the `fromMetadata` case, but I think it's fine to have both.
https://github.com/llvm/llvm-project/pull/212892
More information about the llvm-branch-commits
mailing list