-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[HLSL][RootSignature] Add parsing for RootFlags #138055
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e1b21cc
pre-req: define missing lexer tokens for flags
inbelic adc2168
[HLSL][RootSignature] Add parsing for empty RootFlags
inbelic b3752fb
implement parsing of the flags
inbelic ddfbed4
nfc: improve error message for non-zero flag diagnostic
inbelic 9963bdf
clang-format
inbelic 08f42a9
review: touch-up diag message
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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -27,6 +27,13 @@ RootSignatureParser::RootSignatureParser(SmallVector<RootElement> &Elements, | |||||
bool RootSignatureParser::parse() { | ||||||
// Iterate as many RootElements as possible | ||||||
do { | ||||||
if (tryConsumeExpectedToken(TokenKind::kw_RootFlags)) { | ||||||
auto Flags = parseRootFlags(); | ||||||
if (!Flags.has_value()) | ||||||
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. nit:
Suggested change
|
||||||
return true; | ||||||
Elements.push_back(*Flags); | ||||||
} | ||||||
|
||||||
if (tryConsumeExpectedToken(TokenKind::kw_RootConstants)) { | ||||||
auto Constants = parseRootConstants(); | ||||||
if (!Constants.has_value()) | ||||||
|
@@ -47,6 +54,61 @@ bool RootSignatureParser::parse() { | |||||
/*param of=*/TokenKind::kw_RootSignature); | ||||||
} | ||||||
|
||||||
template <typename FlagType> | ||||||
static FlagType maybeOrFlag(std::optional<FlagType> Flags, FlagType Flag) { | ||||||
if (!Flags.has_value()) | ||||||
return Flag; | ||||||
|
||||||
return static_cast<FlagType>(llvm::to_underlying(Flags.value()) | | ||||||
llvm::to_underlying(Flag)); | ||||||
} | ||||||
|
||||||
std::optional<RootFlags> RootSignatureParser::parseRootFlags() { | ||||||
assert(CurToken.TokKind == TokenKind::kw_RootFlags && | ||||||
"Expects to only be invoked starting at given keyword"); | ||||||
|
||||||
if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after, | ||||||
CurToken.TokKind)) | ||||||
return std::nullopt; | ||||||
|
||||||
std::optional<RootFlags> Flags = RootFlags::None; | ||||||
|
||||||
// Handle the edge-case of '0' to specify no flags set | ||||||
if (tryConsumeExpectedToken(TokenKind::int_literal)) { | ||||||
if (!verifyZeroFlag()) { | ||||||
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_non_zero_flag); | ||||||
return std::nullopt; | ||||||
} | ||||||
} else { | ||||||
// Otherwise, parse as many flags as possible | ||||||
TokenKind Expected[] = { | ||||||
#define ROOT_FLAG_ENUM(NAME, LIT) TokenKind::en_##NAME, | ||||||
#include "clang/Lex/HLSLRootSignatureTokenKinds.def" | ||||||
}; | ||||||
|
||||||
do { | ||||||
if (tryConsumeExpectedToken(Expected)) { | ||||||
switch (CurToken.TokKind) { | ||||||
#define ROOT_FLAG_ENUM(NAME, LIT) \ | ||||||
case TokenKind::en_##NAME: \ | ||||||
Flags = maybeOrFlag<RootFlags>(Flags, RootFlags::NAME); \ | ||||||
break; | ||||||
#include "clang/Lex/HLSLRootSignatureTokenKinds.def" | ||||||
default: | ||||||
llvm_unreachable("Switch for consumed enum token was not provided"); | ||||||
} | ||||||
} | ||||||
} while (tryConsumeExpectedToken(TokenKind::pu_or)); | ||||||
} | ||||||
|
||||||
if (consumeExpectedToken(TokenKind::pu_r_paren, | ||||||
diag::err_hlsl_unexpected_end_of_params, | ||||||
/*param of=*/TokenKind::kw_RootFlags)) | ||||||
return std::nullopt; | ||||||
|
||||||
return Flags; | ||||||
} | ||||||
|
||||||
std::optional<RootConstants> RootSignatureParser::parseRootConstants() { | ||||||
assert(CurToken.TokKind == TokenKind::kw_RootConstants && | ||||||
"Expects to only be invoked starting at given keyword"); | ||||||
|
@@ -467,15 +529,6 @@ RootSignatureParser::parseShaderVisibility() { | |||||
return std::nullopt; | ||||||
} | ||||||
|
||||||
template <typename FlagType> | ||||||
static FlagType maybeOrFlag(std::optional<FlagType> Flags, FlagType Flag) { | ||||||
if (!Flags.has_value()) | ||||||
return Flag; | ||||||
|
||||||
return static_cast<FlagType>(llvm::to_underlying(Flags.value()) | | ||||||
llvm::to_underlying(Flag)); | ||||||
} | ||||||
|
||||||
std::optional<llvm::hlsl::rootsig::DescriptorRangeFlags> | ||||||
RootSignatureParser::parseDescriptorRangeFlags() { | ||||||
assert(CurToken.TokKind == TokenKind::pu_equal && | ||||||
|
@@ -484,7 +537,7 @@ RootSignatureParser::parseDescriptorRangeFlags() { | |||||
// Handle the edge-case of '0' to specify no flags set | ||||||
if (tryConsumeExpectedToken(TokenKind::int_literal)) { | ||||||
if (!verifyZeroFlag()) { | ||||||
getDiags().Report(CurToken.TokLoc, diag::err_expected) << "'0'"; | ||||||
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_non_zero_flag); | ||||||
return std::nullopt; | ||||||
} | ||||||
return DescriptorRangeFlags::None; | ||||||
|
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
Oops, something went wrong.
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.