[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jan 29 15:53:59 PST 2025
================
@@ -169,5 +220,399 @@ bool RootSignatureLexer::LexToken(RootSignatureToken &Result) {
return false;
}
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(
+ SmallVector<RootElement> &Elements,
+ const SmallVector<RootSignatureToken> &Tokens, DiagnosticsEngine &Diags)
+ : Elements(Elements), Diags(Diags) {
+ CurTok = Tokens.begin();
+ LastTok = Tokens.end();
+}
+
+bool RootSignatureParser::Parse() {
+ // Handle edge-case of empty RootSignature()
+ if (CurTok == LastTok)
+ return false;
+
+ bool First = true;
+ // Iterate as many RootElements as possible
+ while (!ParseRootElement(First)) {
+ First = false;
+ // Avoid use of ConsumeNextToken here to skip incorrect end of tokens error
+ CurTok++;
+ if (CurTok == LastTok)
+ return false;
+ if (EnsureExpectedToken(TokenKind::pu_comma))
+ return true;
+ }
+
+ return true;
+}
+
+bool RootSignatureParser::ParseRootElement(bool First) {
+ if (First && EnsureExpectedToken(TokenKind::kw_DescriptorTable))
+ return true;
+ if (!First && ConsumeExpectedToken(TokenKind::kw_DescriptorTable))
+ return true;
+
+ // Dispatch onto the correct parse method
+ switch (CurTok->Kind) {
----------------
joaosaffran wrote:
I was expecting this switch to happen earlier in this method. What is the reason to ensure that descriptor tables are the first element of Root Signatures? For example, this is valid `SRV(t0), DescriptorTable(CBV(b0, numDescriptors=5))` and doesn't start with a `DescriptorTable`.
https://github.com/llvm/llvm-project/pull/122982
More information about the llvm-branch-commits
mailing list