Skip to content

[HLSL][RootSignature] Update setDefaultFlags to account for Root Signature Version #145828

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

Open
wants to merge 7 commits into
base: users/inbelic/pr-145986
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang/include/clang/Parse/ParseHLSLRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ namespace hlsl {

class RootSignatureParser {
public:
RootSignatureParser(SmallVector<llvm::hlsl::rootsig::RootElement> &Elements,
RootSignatureParser(llvm::dxbc::RootSignatureVersion Version,
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements,
RootSignatureLexer &Lexer, clang::Preprocessor &PP);

/// Consumes tokens from the Lexer and constructs the in-memory
Expand Down Expand Up @@ -187,6 +188,7 @@ class RootSignatureParser {
bool tryConsumeExpectedToken(ArrayRef<RootSignatureToken::Kind> Expected);

private:
llvm::dxbc::RootSignatureVersion Version;
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements;
RootSignatureLexer &Lexer;

Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Parse/ParseDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4957,7 +4957,8 @@ void Parser::ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs) {
// Invoke the root signature parser to construct the in-memory constructs
hlsl::RootSignatureLexer Lexer(Signature, SignatureLoc);
SmallVector<llvm::hlsl::rootsig::RootElement> RootElements;
hlsl::RootSignatureParser Parser(RootElements, Lexer, PP);
hlsl::RootSignatureParser Parser(getLangOpts().HLSLRootSigVer, RootElements,
Lexer, PP);
if (Parser.parse()) {
T.consumeClose();
return;
Expand Down
14 changes: 8 additions & 6 deletions clang/lib/Parse/ParseHLSLRootSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ namespace hlsl {

using TokenKind = RootSignatureToken::Kind;

RootSignatureParser::RootSignatureParser(SmallVector<RootElement> &Elements,
RootSignatureLexer &Lexer,
Preprocessor &PP)
: Elements(Elements), Lexer(Lexer), PP(PP), CurToken(SourceLocation()) {}
RootSignatureParser::RootSignatureParser(
llvm::dxbc::RootSignatureVersion Version,
SmallVector<RootElement> &Elements, RootSignatureLexer &Lexer,
Preprocessor &PP)
: Version(Version), Elements(Elements), Lexer(Lexer), PP(PP),
CurToken(SourceLocation()) {}

bool RootSignatureParser::parse() {
// Iterate as many RootElements as possible
Expand Down Expand Up @@ -199,7 +201,7 @@ std::optional<RootDescriptor> RootSignatureParser::parseRootDescriptor() {
ExpectedReg = TokenKind::uReg;
break;
}
Descriptor.setDefaultFlags();
Descriptor.setDefaultFlags(Version);

auto Params = parseRootDescriptorParams(ExpectedReg);
if (!Params.has_value())
Expand Down Expand Up @@ -318,7 +320,7 @@ RootSignatureParser::parseDescriptorTableClause() {
ExpectedReg = TokenKind::sReg;
break;
}
Clause.setDefaultFlags();
Clause.setDefaultFlags(Version);

auto Params = parseDescriptorTableClauseParams(ExpectedReg);
if (!Params.has_value())
Expand Down
12 changes: 9 additions & 3 deletions clang/test/AST/HLSL/RootSignatures-AST.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@
// CHECK-SAME: space = 1, visibility = All, flags = DataStatic
// CHECK-SAME: ),
// CHECK-SAME: RootSRV(t0,
// CHECK-SAME: space = 0, visibility = All, flags = DataStaticWhileSetAtExecute
// CHECK-SAME: space = 0, visibility = All,
// CHECK-V1_0-SAME: flags = DataVolatile
// CHECK-V1_1-SAME: flags = DataStaticWhileSetAtExecute
// CHECK-SAME: ),
// CHECK-SAME: RootUAV(
// CHECK-SAME: u0, space = 0, visibility = All, flags = DataVolatile
// CHECK-SAME: ),
// CHECK-SAME: CBV(
// CHECK-SAME: b1, numDescriptors = 1, space = 0, offset = DescriptorTableOffsetAppend, flags = DataStaticWhileSetAtExecute
// CHECK-SAME: b1, numDescriptors = 1, space = 0, offset = DescriptorTableOffsetAppend,
// CHECK-V1_0-SAME: flags = DescriptorsVolatile | DataVolatile
// CHECK-V1_1-SAME: flags = DataStaticWhileSetAtExecute
// CHECK-SAME: ),
// CHECK-SAME: SRV(
// CHECK-SAME: t1, numDescriptors = 8, space = 0, offset = DescriptorTableOffsetAppend, flags = DescriptorsVolatile
Expand All @@ -55,7 +59,9 @@
// CHECK-SAME: numClauses = 3, visibility = All
// CHECK-SAME: ),
// CHECK-SAME: Sampler(
// CHECK-SAME: s0, numDescriptors = 4, space = 1, offset = DescriptorTableOffsetAppend, flags = None
// CHECK-SAME: s0, numDescriptors = 4, space = 1, offset = DescriptorTableOffsetAppend,
// CHECK-V1_1-SAME: flags = DescriptorsVolatile
// CHECK-V1_1-SAME: flags = None
// CHECK-SAME: ),
// CHECK-SAME: DescriptorTable(
// CHECK-SAME: numClauses = 1, visibility = All
Expand Down
Loading