-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr #125131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
abe7e67
add basic empty root signature
inbelic 671f099
pass down the actual root elements
inbelic d02cb55
introduce a MetadataBuilder to handle the construction of nodes
inbelic 28c6dfa
add support for DescriptorTableClauses
inbelic 9bdf703
add support for associating DescriptorTables with their clauses
inbelic 05e7c0f
self-review: misc clean up
inbelic e96c6d7
review: remove use of CHECK-DAG
inbelic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | FileCheck %s | ||
|
||
// CHECK: !dx.rootsignatures = !{![[#FIRST_ENTRY:]], ![[#SECOND_ENTRY:]]} | ||
|
||
// CHECK: ![[#FIRST_ENTRY]] = !{ptr @FirstEntry, ![[#EMPTY:]]} | ||
// CHECK: ![[#EMPTY]] = !{} | ||
|
||
[shader("compute"), RootSignature("")] | ||
[numthreads(1,1,1)] | ||
void FirstEntry() {} | ||
|
||
// CHECK: ![[#SECOND_ENTRY]] = !{ptr @SecondEntry, ![[#SECOND_RS:]]} | ||
// CHECK: ![[#SECOND_RS]] = !{![[#TABLE:]]} | ||
// CHECK: ![[#TABLE]] = !{!"DescriptorTable", i32 0, ![[#CBV:]], ![[#SRV:]]} | ||
// CHECK: ![[#CBV]] = !{!"CBV", i32 1, i32 0, i32 0, i32 -1, i32 4} | ||
// CHECK: ![[#SRV]] = !{!"SRV", i32 4, i32 42, i32 3, i32 32, i32 0} | ||
joaosaffran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#define SampleDescriptorTable \ | ||
"DescriptorTable( " \ | ||
" CBV(b0), " \ | ||
" SRV(t42, space = 3, offset = 32, numDescriptors = 4, flags = 0) " \ | ||
")" | ||
[shader("compute"), RootSignature(SampleDescriptorTable)] | ||
[numthreads(1,1,1)] | ||
void SecondEntry() {} | ||
|
||
// Sanity test to ensure no root is added for this function as there is only | ||
// two entries in !dx.roosignatures | ||
[shader("compute")] | ||
[numthreads(1,1,1)] | ||
void ThirdEntry() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
//===- HLSLRootSignature.cpp - HLSL Root Signature helper objects | ||
//----------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file This file contains helpers for working with HLSL Root Signatures. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/Frontend/HLSL/HLSLRootSignature.h" | ||
#include "llvm/IR/IRBuilder.h" | ||
#include "llvm/IR/Metadata.h" | ||
#include "llvm/IR/Module.h" | ||
|
||
namespace llvm { | ||
namespace hlsl { | ||
namespace rootsig { | ||
|
||
// Static helper functions | ||
|
||
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); | ||
} | ||
|
||
// Helper struct so that we can use the overloaded notation of std::visit | ||
template <class... Ts> struct OverloadBuilds : Ts... { | ||
using Ts::operator()...; | ||
}; | ||
template <class... Ts> OverloadBuilds(Ts...) -> OverloadBuilds<Ts...>; | ||
|
||
MDNode *MetadataBuilder::BuildRootSignature() { | ||
for (const RootElement &Element : Elements) { | ||
MDNode *ElementMD = | ||
std::visit(OverloadBuilds{ | ||
inbelic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[&](DescriptorTable Table) -> MDNode * { | ||
return BuildDescriptorTable(Table); | ||
}, | ||
[&](DescriptorTableClause Clause) -> MDNode * { | ||
return BuildDescriptorTableClause(Clause); | ||
}, | ||
}, | ||
Element); | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very helpful 👍 |
||
// 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()); | ||
// Then, remove those clauses from the general list of Root Elements | ||
GeneratedMetadata.pop_back_n(Table.NumClauses); | ||
|
||
return MDNode::get(Ctx, TableOperands); | ||
} | ||
|
||
MDNode *MetadataBuilder::BuildDescriptorTableClause( | ||
const DescriptorTableClause &Clause) { | ||
IRBuilder<> B(Ctx); | ||
return MDNode::get( | ||
Ctx, { | ||
ClauseTypeToName(Ctx, Clause.Type), | ||
ConstantAsMetadata::get(B.getInt32(Clause.NumDescriptors)), | ||
ConstantAsMetadata::get(B.getInt32(Clause.Register.Number)), | ||
ConstantAsMetadata::get(B.getInt32(Clause.Space)), | ||
ConstantAsMetadata::get( | ||
inbelic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
B.getInt32(llvm::to_underlying(Clause.Offset))), | ||
ConstantAsMetadata::get( | ||
B.getInt32(llvm::to_underlying(Clause.Flags))), | ||
}); | ||
} | ||
|
||
} // namespace rootsig | ||
} // namespace hlsl | ||
} // namespace llvm |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.