Skip to content

Commit 611ef1f

Browse files
committed
clean up
1 parent 016f380 commit 611ef1f

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,9 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
471471

472472
// Add and identify root signature to function, if applicable
473473
const AttrVec &Attrs = FD->getAttrs();
474-
for (const Attr *Attr : Attrs) {
474+
for (const Attr *Attr : Attrs)
475475
if (const auto *RSAttr = dyn_cast<HLSLRootSignatureAttr>(Attr))
476476
addRootSignature(RSAttr->getElements(), EntryFn, M);
477-
}
478477
}
479478

480479
void CGHLSLRuntime::setHLSLFunctionAttributes(const FunctionDecl *FD,

clang/test/CodeGenHLSL/RootSignature.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void FirstEntry() {}
1919
[numthreads(1,1,1)]
2020
void SecondEntry() {}
2121

22-
// Sanity test to ensure to root is added for this function
22+
// Sanity test to ensure no root is added for this function
2323
[shader("compute")]
2424
[numthreads(1,1,1)]
2525
void ThirdEntry() {}

llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ class MetadataBuilder {
133133
MetadataBuilder(llvm::LLVMContext &Ctx, ArrayRef<RootElement> Elements)
134134
: Ctx(Ctx), Elements(Elements) {}
135135

136-
// Iterates through the elements and builds the respective nodes
136+
// Iterates through the elements and dispatches onto the correct Build method
137+
//
138+
// Accumulates the root signature and returns the Metadata node that is just
139+
// a list of all the elements
137140
MDNode *BuildRootSignature();
138141

139142
private:

llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace llvm {
1919
namespace hlsl {
2020
namespace root_signature {
2121

22+
// Static helper functions
23+
2224
static MDString *ClauseTypeToName(LLVMContext &Ctx, ClauseType Type) {
2325
StringRef Name;
2426
switch (Type) {
@@ -66,11 +68,17 @@ MDNode *MetadataBuilder::BuildRootSignature() {
6668
MDNode *MetadataBuilder::BuildDescriptorTable(const DescriptorTable &Table) {
6769
IRBuilder<> B(Ctx);
6870
SmallVector<Metadata *> TableOperands;
71+
// Set the mandatory arguments
6972
TableOperands.push_back(MDString::get(Ctx, "DescriptorTable"));
7073
TableOperands.push_back(ConstantAsMetadata::get(B.getInt32(llvm::to_underlying(Table.Visibility))));
7174

75+
// Remaining operands are references to the table's clauses. The in-memory
76+
// representation of the Root Elements created from parsing will ensure that
77+
// the previous N elements are the clauses for this table.
7278
assert(Table.NumClauses <= GeneratedMetadata.size() && "Table expected all owned clauses to be generated already");
79+
// So, add a refence to each clause to our operands
7380
TableOperands.append(GeneratedMetadata.end() - Table.NumClauses, GeneratedMetadata.end());
81+
// Then, remove those clauses from the general list of Root Elements
7482
GeneratedMetadata.pop_back_n(Table.NumClauses);
7583

7684
return MDNode::get(Ctx, TableOperands);

0 commit comments

Comments
 (0)