================
@@ -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");
----------------
joaosaffran wrote:

Not sure how complex/useful this is, we could check how many 
`DescriptorTableClause` are in `TableOperands` preceding the table. I think 
this could be done like:

```C++
uint Count = 0;
// I think this should be the Element parameter, from BuildRootSignature
auto It = Element;
while (std::holds_alternative<DescriptorTableClause>(*It)){
    Count ++;
    Element --;
}

assert(Table.NumClauses == Count);
```

Not sure this code is correct/useful, but that is the idea.

https://github.com/llvm/llvm-project/pull/139633
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to