[clang] [llvm] [HLSL][RootSignature] Add metadata generation for descriptor tables (PR #139633)
Finn Plummer via cfe-commits
cfe-commits at lists.llvm.org
Thu May 15 10:25:26 PDT 2025
================
@@ -160,6 +163,75 @@ void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements) {
OS << "}";
}
+static MDString *ClauseTypeToName(LLVMContext &Ctx, ClauseType Type) {
+ StringRef Name;
+ switch (Type) {
+ case ClauseType::CBuffer:
+ Name = "CBV";
+ break;
+ case ClauseType::SRV:
+ Name = "SRV";
+ break;
+ case ClauseType::UAV:
+ Name = "UAV";
+ break;
+ case ClauseType::Sampler:
+ Name = "Sampler";
+ break;
+ }
+ return MDString::get(Ctx, Name);
+}
+
+MDNode *MetadataBuilder::BuildRootSignature() {
+ for (const RootElement &Element : Elements) {
+ MDNode *ElementMD = nullptr;
+ if (const auto &Clause = std::get_if<DescriptorTableClause>(&Element))
+ ElementMD = BuildDescriptorTableClause(*Clause);
+ if (const auto &Table = std::get_if<DescriptorTable>(&Element))
+ ElementMD = BuildDescriptorTable(*Table);
+ GeneratedMetadata.push_back(ElementMD);
+ }
+
+ return MDNode::get(Ctx, GeneratedMetadata);
+}
+
+MDNode *MetadataBuilder::BuildDescriptorTable(const DescriptorTable &Table) {
+ IRBuilder<> B(Ctx);
+ SmallVector<Metadata *> TableOperands;
+ // Set the mandatory arguments
+ TableOperands.push_back(MDString::get(Ctx, "DescriptorTable"));
+ TableOperands.push_back(ConstantAsMetadata::get(
+ B.getInt32(llvm::to_underlying(Table.Visibility))));
+
+ // Remaining operands are references to the table's clauses. The in-memory
+ // representation of the Root Elements created from parsing will ensure that
+ // the previous N elements are the clauses for this table.
+ assert(Table.NumClauses <= GeneratedMetadata.size() &&
+ "Table expected all owned clauses to be generated already");
+ // So, add a refence to each clause to our operands
+ TableOperands.append(GeneratedMetadata.end() - Table.NumClauses,
+ GeneratedMetadata.end());
----------------
inbelic wrote:
Correct, I added a comment to documentation the in-memory representation better
https://github.com/llvm/llvm-project/pull/139633
More information about the cfe-commits
mailing list