[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-01-30 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/125131

- Define and implement `MetadataBuilder` in `HLSLRootSignature`
- Integrate and invoke the builder in `CGHLSLRuntime.cpp` to generate the Root 
Signature for any associated entry functions
- Add tests to demonstrate functionality in `RootSignature.hlsl`

First part of resolving #119014 

>From 96a959b5c1dd4d46b72344902d697a40100d8046 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 29 Jan 2025 19:40:08 +
Subject: [PATCH 1/5] add basic empty root signature

---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 21 +
 clang/test/CodeGenHLSL/RootSignature.hlsl | 19 +++
 2 files changed, 40 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/RootSignature.hlsl

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index c354e58e15f4bb..ff608323e9ac3a 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -119,6 +119,20 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) {
   return CBGV;
 }
 
+void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
+  auto &Ctx = M.getContext();
+  IRBuilder<> B(M.getContext());
+
+  MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
+
+  MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
+ ExampleRootSignature});
+
+  StringRef RootSignatureValKey = "dx.rootsignatures";
+  auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey);
+  RootSignatureValMD->addOperand(ExamplePairing);
+}
+
 } // namespace
 
 llvm::Type *CGHLSLRuntime::convertHLSLSpecificType(const Type *T) {
@@ -453,6 +467,13 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   // FIXME: Handle codegen for return type semantics.
   // See: https://github.com/llvm/llvm-project/issues/57875
   B.CreateRetVoid();
+
+  // Add and identify root signature to function, if applicable
+  const AttrVec &Attrs = FD->getAttrs();
+  for (const Attr *Attr : Attrs) {
+if (isa(Attr))
+  addRootSignature(EntryFn, M);
+  }
 }
 
 void CGHLSLRuntime::setHLSLFunctionAttributes(const FunctionDecl *FD,
diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl 
b/clang/test/CodeGenHLSL/RootSignature.hlsl
new file mode 100644
index 00..1ea9ab7aaa2c35
--- /dev/null
+++ b/clang/test/CodeGenHLSL/RootSignature.hlsl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | 
FileCheck %s
+
+// CHECK: !dx.rootsignatures = !{![[#FIRST_ENTRY:]], ![[#SECOND_ENTRY:]]}
+// CHECK-DAG: ![[#FIRST_ENTRY]] = !{ptr @FirstEntry, ![[#RS:]]}
+// CHECK-DAG: ![[#SECOND_ENTRY]] = !{ptr @SecondEntry, ![[#RS:]]}
+// CHECK-DAG: ![[#RS]] = !{}
+
+[shader("compute"), RootSignature("")]
+[numthreads(1,1,1)]
+void FirstEntry() {}
+
+[shader("compute"), RootSignature("DescriptorTable()")]
+[numthreads(1,1,1)]
+void SecondEntry() {}
+
+// Sanity test to ensure to root is added for this function
+[shader("compute")]
+[numthreads(1,1,1)]
+void ThirdEntry() {}

>From 3f292a141ea90674301a3c23d02d2677fc3b8b23 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 29 Jan 2025 19:57:48 +
Subject: [PATCH 2/5] pass down the actual root elements

- test that we have the correct number of elements
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 17 -
 clang/test/CodeGenHLSL/RootSignature.hlsl |  9 +
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index ff608323e9ac3a..4c9adcd8a90536 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -119,11 +119,18 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) 
{
   return CBGV;
 }
 
-void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
+void addRootSignature(
+ArrayRef Elements,
+llvm::Function *Fn, llvm::Module &M) {
   auto &Ctx = M.getContext();
-  IRBuilder<> B(M.getContext());
 
-  MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
+  SmallVector GeneratedMetadata;
+  for (auto Element : Elements) {
+MDNode *ExampleRootElement = MDNode::get(Ctx, {});
+GeneratedMetadata.push_back(ExampleRootElement);
+  }
+
+  MDNode *ExampleRootSignature = MDNode::get(Ctx, GeneratedMetadata);
 
   MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
  ExampleRootSignature});
@@ -471,8 +478,8 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   // Add and identify root signature to function, if applicable
   const AttrVec &Attrs = FD->getAttrs();
   for (const Attr *Attr : Attrs) {
-if (isa(Attr))
-  addRootSignature(EntryFn, M);
+if (const auto *RSAttr = dyn_cast(Attr))
+  addRootSignature(RSAttr->getElements(), EntryFn, M);
   }
 }
 
diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl 
b/clang/tes

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-01-30 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/125131

>From 96a959b5c1dd4d46b72344902d697a40100d8046 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 29 Jan 2025 19:40:08 +
Subject: [PATCH 1/7] add basic empty root signature

---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 21 +
 clang/test/CodeGenHLSL/RootSignature.hlsl | 19 +++
 2 files changed, 40 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/RootSignature.hlsl

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index c354e58e15f4bb..ff608323e9ac3a 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -119,6 +119,20 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) {
   return CBGV;
 }
 
+void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
+  auto &Ctx = M.getContext();
+  IRBuilder<> B(M.getContext());
+
+  MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
+
+  MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
+ ExampleRootSignature});
+
+  StringRef RootSignatureValKey = "dx.rootsignatures";
+  auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey);
+  RootSignatureValMD->addOperand(ExamplePairing);
+}
+
 } // namespace
 
 llvm::Type *CGHLSLRuntime::convertHLSLSpecificType(const Type *T) {
@@ -453,6 +467,13 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   // FIXME: Handle codegen for return type semantics.
   // See: https://github.com/llvm/llvm-project/issues/57875
   B.CreateRetVoid();
+
+  // Add and identify root signature to function, if applicable
+  const AttrVec &Attrs = FD->getAttrs();
+  for (const Attr *Attr : Attrs) {
+if (isa(Attr))
+  addRootSignature(EntryFn, M);
+  }
 }
 
 void CGHLSLRuntime::setHLSLFunctionAttributes(const FunctionDecl *FD,
diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl 
b/clang/test/CodeGenHLSL/RootSignature.hlsl
new file mode 100644
index 00..1ea9ab7aaa2c35
--- /dev/null
+++ b/clang/test/CodeGenHLSL/RootSignature.hlsl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | 
FileCheck %s
+
+// CHECK: !dx.rootsignatures = !{![[#FIRST_ENTRY:]], ![[#SECOND_ENTRY:]]}
+// CHECK-DAG: ![[#FIRST_ENTRY]] = !{ptr @FirstEntry, ![[#RS:]]}
+// CHECK-DAG: ![[#SECOND_ENTRY]] = !{ptr @SecondEntry, ![[#RS:]]}
+// CHECK-DAG: ![[#RS]] = !{}
+
+[shader("compute"), RootSignature("")]
+[numthreads(1,1,1)]
+void FirstEntry() {}
+
+[shader("compute"), RootSignature("DescriptorTable()")]
+[numthreads(1,1,1)]
+void SecondEntry() {}
+
+// Sanity test to ensure to root is added for this function
+[shader("compute")]
+[numthreads(1,1,1)]
+void ThirdEntry() {}

>From 3f292a141ea90674301a3c23d02d2677fc3b8b23 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 29 Jan 2025 19:57:48 +
Subject: [PATCH 2/7] pass down the actual root elements

- test that we have the correct number of elements
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 17 -
 clang/test/CodeGenHLSL/RootSignature.hlsl |  9 +
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index ff608323e9ac3a..4c9adcd8a90536 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -119,11 +119,18 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) 
{
   return CBGV;
 }
 
-void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
+void addRootSignature(
+ArrayRef Elements,
+llvm::Function *Fn, llvm::Module &M) {
   auto &Ctx = M.getContext();
-  IRBuilder<> B(M.getContext());
 
-  MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
+  SmallVector GeneratedMetadata;
+  for (auto Element : Elements) {
+MDNode *ExampleRootElement = MDNode::get(Ctx, {});
+GeneratedMetadata.push_back(ExampleRootElement);
+  }
+
+  MDNode *ExampleRootSignature = MDNode::get(Ctx, GeneratedMetadata);
 
   MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
  ExampleRootSignature});
@@ -471,8 +478,8 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   // Add and identify root signature to function, if applicable
   const AttrVec &Attrs = FD->getAttrs();
   for (const Attr *Attr : Attrs) {
-if (isa(Attr))
-  addRootSignature(EntryFn, M);
+if (const auto *RSAttr = dyn_cast(Attr))
+  addRootSignature(RSAttr->getElements(), EntryFn, M);
   }
 }
 
diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl 
b/clang/test/CodeGenHLSL/RootSignature.hlsl
index 1ea9ab7aaa2c35..63c0505e224f0a 100644
--- a/clang/test/CodeGenHLSL/RootSignature.hlsl
+++ b/clang/test/CodeGenHLSL/RootSignature.hlsl
@@ -1,9 +1,10 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | 
FileCheck %s
 
-//

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-30 Thread Finn Plummer via llvm-branch-commits


@@ -169,5 +220,399 @@ bool RootSignatureLexer::LexToken(RootSignatureToken 
&Result) {
   return false;
 }
 
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(
+SmallVector &Elements,
+const SmallVector &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) {

inbelic wrote:

This pr only adds support for `DescriptorTable` as a root element. So there is 
no added support for a root descriptor range at the moment. A future pr that 
will handle the `RootCBV, etc` would be added to this switch statement and then 
dispatched onto its own method.

https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-02-04 Thread Finn Plummer via llvm-branch-commits




inbelic wrote:

Okay, sounds good. In that case then we can remove the code that handles got 
multiple

https://github.com/llvm/llvm-project/pull/123147
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-02-05 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/122982

>From 5ed5fcfebb395cdfe45dc41094e07716d2003d66 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Tue, 28 Jan 2025 17:49:21 +
Subject: [PATCH 01/18] [HLSL][RootSignature] Handle an empty root signature

- Define the Parser struct
- Model RootElements as a variant of the different types
- Create a basic test case for unit testing
---
 .../clang/Parse/ParseHLSLRootSignature.h  | 26 
 clang/lib/Parse/ParseHLSLRootSignature.cpp| 19 
 .../Parse/ParseHLSLRootSignatureTest.cpp  | 26 
 .../llvm/Frontend/HLSL/HLSLRootSignature.h| 30 +++
 4 files changed, 101 insertions(+)
 create mode 100644 llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index 899608bd1527ea..2e01f86f832f76 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -22,9 +22,13 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
+
 namespace clang {
 namespace hlsl {
 
+namespace rs = llvm::hlsl::root_signature;
+
 struct RootSignatureToken {
   enum Kind {
 #define TOK(X) X,
@@ -80,6 +84,28 @@ class RootSignatureLexer {
   }
 };
 
+class RootSignatureParser {
+public:
+  RootSignatureParser(SmallVector &Elements,
+  const SmallVector &Tokens,
+  DiagnosticsEngine &Diags);
+
+  // Iterates over the provided tokens and constructs the in-memory
+  // representations of the RootElements.
+  //
+  // The return value denotes if there was a failure and the method will
+  // return on the first encountered failure, or, return false if it
+  // can sucessfully reach the end of the tokens.
+  bool Parse();
+
+private:
+  SmallVector &Elements;
+  SmallVector::const_iterator CurTok;
+  SmallVector::const_iterator LastTok;
+
+  DiagnosticsEngine &Diags;
+};
+
 } // namespace hlsl
 } // namespace clang
 
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp 
b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index 7ceb85a47a088e..2ba756f3bd09f2 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -1,5 +1,7 @@
 #include "clang/Parse/ParseHLSLRootSignature.h"
 
+using namespace llvm::hlsl::root_signature;
+
 namespace clang {
 namespace hlsl {
 
@@ -169,5 +171,22 @@ bool RootSignatureLexer::LexToken(RootSignatureToken 
&Result) {
   return false;
 }
 
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(
+SmallVector &Elements,
+const SmallVector &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;
+
+  return true;
+}
 } // namespace hlsl
 } // namespace clang
diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp 
b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
index 57b61e43746a0b..87bceeeb3283ef 100644
--- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
+++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
@@ -24,6 +24,7 @@
 #include "gtest/gtest.h"
 
 using namespace clang;
+using namespace llvm::hlsl::root_signature;
 
 namespace {
 
@@ -279,4 +280,29 @@ TEST_F(ParseHLSLRootSignatureTest, 
InvalidLexIdentifierTest) {
   ASSERT_TRUE(Consumer->IsSatisfied());
 }
 
+// Valid Parser Tests
+
+TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
+  const llvm::StringLiteral Source = R"cc()cc";
+
+  TrivialModuleLoader ModLoader;
+  auto PP = CreatePP(Source, ModLoader);
+  auto TokLoc = SourceLocation();
+
+  // Test no diagnostics produced
+  Consumer->SetNoDiag();
+  hlsl::RootSignatureLexer Lexer(Source, TokLoc, *PP);
+
+  SmallVector Tokens;
+  ASSERT_FALSE(Lexer.Lex(Tokens));
+
+  SmallVector Elements;
+  hlsl::RootSignatureParser Parser(Elements, Tokens, Diags);
+
+  ASSERT_FALSE(Parser.Parse());
+  ASSERT_EQ((int)Elements.size(), 0);
+
+  ASSERT_TRUE(Consumer->IsSatisfied());
+}
+
 } // anonymous namespace
diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h 
b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
new file mode 100644
index 00..4c196d29a01bbb
--- /dev/null
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
@@ -0,0 +1,30 @@
+//===- HLSLRootSignature.h - 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 helpe

[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-02-07 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/123985

>From 05c9523adaf9cc3e1585c02bed036ad83667b722 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 22 Jan 2025 17:53:59 +
Subject: [PATCH 1/6] [HLSL] Define the HLSLRootSignature Attr

- Defines HLSLRootSignature Attr in `Attr.td`
- Define and implement handleHLSLRootSignature in `SemaHLSL`
- Adds sample test case to show AST Node is generated in
`RootSignatures-AST.hlsl`

This commit will "hook-up" the seperately defined RootSignature parser
and invoke it to create the RootElements, then store them on the
ASTContext and finally store the reference to the Elements in
RootSignatureAttr
---
 clang/include/clang/AST/Attr.h  |  1 +
 clang/include/clang/Basic/Attr.td   | 20 
 clang/include/clang/Basic/AttrDocs.td   |  4 +++
 clang/include/clang/Sema/SemaHLSL.h |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp |  3 ++
 clang/lib/Sema/SemaHLSL.cpp | 36 +
 clang/test/AST/HLSL/RootSignatures-AST.hlsl | 28 
 7 files changed, 93 insertions(+)
 create mode 100644 clang/test/AST/HLSL/RootSignatures-AST.hlsl

diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 3365ebe4d9012be..d45b8891cf1a72a 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -26,6 +26,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Support/Compiler.h"
 #include "llvm/Frontend/HLSL/HLSLResource.h"
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/VersionTuple.h"
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52ad72eb608c319..36ae98730db031c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,6 +4643,26 @@ def Error : InheritableAttr {
   let Documentation = [ErrorAttrDocs];
 }
 
+/// HLSL Root Signature Attribute
+def HLSLRootSignature : Attr {
+  /// [RootSignature(Signature)]
+  let Spellings = [Microsoft<"RootSignature">];
+  let Args = [StringArgument<"Signature">];
+  let Subjects = SubjectList<[Function],
+ ErrorDiag, "'function'">;
+  let LangOpts = [HLSL];
+  let Documentation = [HLSLRootSignatureDocs];
+  let AdditionalMembers = [{
+private:
+  ArrayRef RootElements;
+public:
+  void setElements(ArrayRef Elements) 
{
+RootElements = Elements;
+  }
+  auto getElements() const { return RootElements; }
+}];
+}
+
 def HLSLNumThreads: InheritableAttr {
   let Spellings = [Microsoft<"numthreads">];
   let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fdad4c9a3ea1910..bb0934a11f9f3f0 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7783,6 +7783,10 @@ and 
https://microsoft.github.io/hlsl-specs/proposals/0013-wave-size-range.html
   }];
 }
 
+def HLSLRootSignatureDocs : Documentation {
+  let Category = DocCatUndocumented;
+}
+
 def NumThreadsDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index f4cd11f423a84a0..df4a5c8d88ba9e2 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -116,6 +116,7 @@ class SemaHLSL : public SemaBase {
bool IsCompAssign);
   void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc);
 
+  void handleRootSignatureAttr(Decl *D, const ParsedAttr &AL);
   void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
   void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8d..c594d6e54ddbcd2 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7149,6 +7149,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
 break;
 
   // HLSL attributes:
+  case ParsedAttr::AT_HLSLRootSignature:
+S.HLSL().handleRootSignatureAttr(D, AL);
+break;
   case ParsedAttr::AT_HLSLNumThreads:
 S.HLSL().handleNumThreadsAttr(D, AL);
 break;
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 600c800029fd05a..ab8aa6f5a351be6 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -24,6 +24,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/Parse/ParseHLSLRootSignature.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/ParsedAttr.h"
 #include "clang/Sema/Sema.h"
@@ -647,6 +648,41 @@ void SemaHLSL::emitLogicalOperatorFi

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-02-10 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-02-11 Thread Finn Plummer via llvm-branch-commits

inbelic wrote:

Rebasing onto the lexer pr api changes of using `ConsumeToken`/`PeekNextToken` 
instead of pre-allocating the tokens

https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-02-10 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/125131
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-01-30 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/123985

>From 8ecb03776b24247e7c68e12d2d9aea8f26e2e0cc Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 22 Jan 2025 17:53:59 +
Subject: [PATCH 1/4] [HLSL] Define the HLSLRootSignature Attr

- Defines HLSLRootSignature Attr in `Attr.td`
- Define and implement handleHLSLRootSignature in `SemaHLSL`
- Adds sample test case to show AST Node is generated in
`RootSignatures-AST.hlsl`

This commit will "hook-up" the seperately defined RootSignature parser
and invoke it to create the RootElements, then store them on the
ASTContext and finally store the reference to the Elements in
RootSignatureAttr
---
 clang/include/clang/AST/Attr.h  |  1 +
 clang/include/clang/Basic/Attr.td   | 20 
 clang/include/clang/Basic/AttrDocs.td   |  4 +++
 clang/include/clang/Sema/SemaHLSL.h |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp |  3 ++
 clang/lib/Sema/SemaHLSL.cpp | 36 +
 clang/test/AST/HLSL/RootSignatures-AST.hlsl | 28 
 7 files changed, 93 insertions(+)
 create mode 100644 clang/test/AST/HLSL/RootSignatures-AST.hlsl

diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 3365ebe4d9012b..d45b8891cf1a72 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -26,6 +26,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Support/Compiler.h"
 #include "llvm/Frontend/HLSL/HLSLResource.h"
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/VersionTuple.h"
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52ad72eb608c31..36ae98730db031 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,6 +4643,26 @@ def Error : InheritableAttr {
   let Documentation = [ErrorAttrDocs];
 }
 
+/// HLSL Root Signature Attribute
+def HLSLRootSignature : Attr {
+  /// [RootSignature(Signature)]
+  let Spellings = [Microsoft<"RootSignature">];
+  let Args = [StringArgument<"Signature">];
+  let Subjects = SubjectList<[Function],
+ ErrorDiag, "'function'">;
+  let LangOpts = [HLSL];
+  let Documentation = [HLSLRootSignatureDocs];
+  let AdditionalMembers = [{
+private:
+  ArrayRef RootElements;
+public:
+  void setElements(ArrayRef Elements) 
{
+RootElements = Elements;
+  }
+  auto getElements() const { return RootElements; }
+}];
+}
+
 def HLSLNumThreads: InheritableAttr {
   let Spellings = [Microsoft<"numthreads">];
   let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fdad4c9a3ea191..bb0934a11f9f3f 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7783,6 +7783,10 @@ and 
https://microsoft.github.io/hlsl-specs/proposals/0013-wave-size-range.html
   }];
 }
 
+def HLSLRootSignatureDocs : Documentation {
+  let Category = DocCatUndocumented;
+}
+
 def NumThreadsDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index f4cd11f423a84a..df4a5c8d88ba9e 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -116,6 +116,7 @@ class SemaHLSL : public SemaBase {
bool IsCompAssign);
   void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc);
 
+  void handleRootSignatureAttr(Decl *D, const ParsedAttr &AL);
   void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
   void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..c594d6e54ddbcd 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7149,6 +7149,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
 break;
 
   // HLSL attributes:
+  case ParsedAttr::AT_HLSLRootSignature:
+S.HLSL().handleRootSignatureAttr(D, AL);
+break;
   case ParsedAttr::AT_HLSLNumThreads:
 S.HLSL().handleNumThreadsAttr(D, AL);
 break;
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 600c800029fd05..ab8aa6f5a351be 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -24,6 +24,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/Parse/ParseHLSLRootSignature.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/ParsedAttr.h"
 #include "clang/Sema/Sema.h"
@@ -647,6 +648,41 @@ void SemaHLSL::emitLogicalOperatorFixIt(Expr *LH

[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-31 Thread Finn Plummer via llvm-branch-commits


@@ -10,13 +10,13 @@ Header:
   PartOffsets: [ 60 ]
 Parts:
   - Name:RTS0
-Size:8
+Size:4

inbelic wrote:

Why should this change?

https://github.com/llvm/llvm-project/pull/123147
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-31 Thread Finn Plummer via llvm-branch-commits


@@ -0,0 +1,74 @@
+//===- DXILRootSignature.h - DXIL 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 helper objects and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/Pass.h"
+#include 
+
+namespace llvm {
+namespace dxil {
+
+enum class RootSignatureElementKind {
+  None = 0,
+  RootFlags = 1,
+  RootConstants = 2,
+  RootDescriptor = 3,
+  DescriptorTable = 4,
+  StaticSampler = 5
+};
+
+struct ModuleRootSignature {
+  uint32_t Flags = 0;
+
+  ModuleRootSignature() = default;
+
+  bool parse(NamedMDNode *Root);

inbelic wrote:

This should be a private method right? Just expose the `analyzeModule`. We 
could also move those `static` functions into private methods as well?

https://github.com/llvm/llvm-project/pull/123147
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-31 Thread Finn Plummer via llvm-branch-commits


@@ -0,0 +1,157 @@
+//===- DXILRootSignature.cpp - DXIL 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 helper objects and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+#include "DXILRootSignature.h"
+#include "DirectX.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Module.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::dxil;
+
+static bool reportError(Twine Message) {
+  report_fatal_error(Message, false);
+  return true;
+}
+
+static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
+
+  if (RootFlagNode->getNumOperands() != 2)
+return reportError("Invalid format for RootFlag Element");
+
+  auto *Flag = mdconst::extract(RootFlagNode->getOperand(1));
+  uint32_t Value = Flag->getZExtValue();
+
+  // Root Element validation, as specified:
+  // 
https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation

inbelic wrote:

I wonder if it is beneficial to decouple the parsing and validation logic?

On one hand it means that the generated structures might be in an invalid 
state. But then we would have an isolated pass to verify the `MRS` struct. If 
there is a case that we will generate the `MRS` another way then we could 
re-use the validation.

https://github.com/llvm/llvm-project/pull/123147
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-31 Thread Finn Plummer via llvm-branch-commits


@@ -0,0 +1,158 @@
+//===- DXILRootSignature.cpp - DXIL 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 helper objects and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+#include "DXILRootSignature.h"
+#include "DirectX.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Module.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::dxil;
+
+static bool reportError(Twine Message) {
+  report_fatal_error(Message, false);
+  return true;
+}
+
+static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
+
+  if (RootFlagNode->getNumOperands() != 2)
+return reportError("Invalid format for RootFlag Element");
+
+  auto *Flag = mdconst::extract(RootFlagNode->getOperand(1));
+  uint32_t Value = Flag->getZExtValue();
+
+  // Root Element validation, as specified:
+  // 
https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
+  if ((Value & ~0x8fff) != 0)
+return reportError("Invalid flag value for RootFlag");
+
+  MRS->Flags = Value;
+  return false;
+}
+
+static bool parseRootSignatureElement(ModuleRootSignature *MRS,
+  MDNode *Element) {
+  MDString *ElementText = cast(Element->getOperand(0));
+  if (ElementText == nullptr)
+return reportError("Invalid format for Root Element");
+
+  RootSignatureElementKind ElementKind =
+  StringSwitch(ElementText->getString())
+  .Case("RootFlags", RootSignatureElementKind::RootFlags)
+  .Case("RootConstants", RootSignatureElementKind::RootConstants)
+  .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
+  .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
+  .Case("Sampler", RootSignatureElementKind::RootDescriptor)
+  .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+  .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
+  .Default(RootSignatureElementKind::None);
+
+  switch (ElementKind) {
+
+  case RootSignatureElementKind::RootFlags: {
+return parseRootFlags(MRS, Element);
+break;
+  }
+
+  case RootSignatureElementKind::RootConstants:
+  case RootSignatureElementKind::RootDescriptor:
+  case RootSignatureElementKind::DescriptorTable:
+  case RootSignatureElementKind::StaticSampler:
+  case RootSignatureElementKind::None:
+return reportError("Invalid Root Element: " + ElementText->getString());
+break;
+  }
+
+  return true;
+}
+
+bool ModuleRootSignature::parse(NamedMDNode *Root) {
+  bool HasError = false;
+
+  /** Root Signature are specified as following in the metadata:
+
+  !dx.rootsignatures = !{!2} ; list of function/root signature pairs
+  !2 = !{ ptr @main, !3 } ; function, root signature
+  !3 = !{ !4, !5, !6, !7 } ; list of root signature elements
+
+  So for each MDNode inside dx.rootsignatures NamedMDNode
+  (the Root parameter of this function), the parsing process needs
+  to loop through each of it's operand and process the pairs function
+  signature pair.
+   */
+
+  for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
+MDNode *Node = dyn_cast(Root->getOperand(Sid));
+
+if (Node == nullptr || Node->getNumOperands() != 2)
+  return reportError("Invalid format for Root Signature Definition. Pairs "
+ "of function, root signature expected.");
+
+// Get the Root Signature Description from the function signature pair.
+MDNode *RS = dyn_cast(Node->getOperand(1).get());
+
+if (RS == nullptr)
+  return reportError("Missing Root Signature Metadata node.");
+
+// Loop through the Root Elements of the root signature.
+for (unsigned int Eid = 0; Eid < RS->getNumOperands(); Eid++) {
+
+  MDNode *Element = dyn_cast(RS->getOperand(Eid));
+  if (Element == nullptr)
+return reportError("Missing Root Element Metadata Node.");
+
+  HasError = HasError || parseRootSignatureElement(this, Element);
+}
+  }
+  return HasError;
+}
+
+ModuleRootSignature ModuleRootSignature::analyzeModule(Module &M) {
+  ModuleRootSignature MRS;
+
+  NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
+  if (RootSignatureNode) {
+if (MRS.parse(RootSignatureNode))
+  llvm_unreachable("Invalid Root Signature Metadata.");

inbelic wrote:

Shouldn't we just `return MRS` then?

https://github.com/llvm/l

[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-31 Thread Finn Plummer via llvm-branch-commits


@@ -0,0 +1,157 @@
+//===- DXILRootSignature.cpp - DXIL 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 helper objects and APIs for working with DXIL
+///   Root Signatures.
+///
+//===--===//
+#include "DXILRootSignature.h"
+#include "DirectX.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Module.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::dxil;
+
+static bool reportError(Twine Message) {
+  report_fatal_error(Message, false);

inbelic wrote:

Note: I am curious if this type of error reporting will result in similar 
HWAddress buildbot failure as reported 
[here](https://github.com/llvm/llvm-project/issues/124045), when trying to test 
it later

https://github.com/llvm/llvm-project/pull/123147
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-31 Thread Finn Plummer via llvm-branch-commits




inbelic wrote:

If you think it makes more sense to have the separate, then I think we should 
have at least 1 test-case that demonstrates multiple root-signatures

https://github.com/llvm/llvm-project/pull/123147
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-31 Thread Finn Plummer via llvm-branch-commits




inbelic wrote:

Are you able to merge all these testcases into one file? You should be able to 
define multiple root signatures on different entry functions right?

https://github.com/llvm/llvm-project/pull/123147
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-31 Thread Finn Plummer via llvm-branch-commits




inbelic wrote:

I guess we can't merge all these error tests because we error out on the first 
one? We should have at least one test that iterates on multiple root signatures 
though.

https://github.com/llvm/llvm-project/pull/123147
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)

2025-01-31 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic deleted 
https://github.com/llvm/llvm-project/pull/123147
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-01-22 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/123985

>From 42932906dc811f2f6953d0902143419daa030be7 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 22 Jan 2025 17:53:59 +
Subject: [PATCH 1/2] [HLSL] Define the HLSLRootSignature Attr

- Defines HLSLRootSignature Attr in `Attr.td`
- Define and implement handleHLSLRootSignature in `SemaHLSL`
- Adds sample test case to show AST Node is generated in
`RootSignatures-AST.hlsl`

This commit will "hook-up" the seperately defined RootSignature parser
and invoke it to create the RootElements, then store them on the
ASTContext and finally store the reference to the Elements in
RootSignatureAttr
---
 clang/include/clang/AST/Attr.h  |  1 +
 clang/include/clang/Basic/Attr.td   | 20 ++
 clang/include/clang/Basic/AttrDocs.td   |  4 +++
 clang/include/clang/Sema/SemaHLSL.h |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp |  3 +++
 clang/lib/Sema/SemaHLSL.cpp | 30 +
 clang/test/AST/HLSL/RootSignatures-AST.hlsl | 28 +++
 7 files changed, 87 insertions(+)
 create mode 100644 clang/test/AST/HLSL/RootSignatures-AST.hlsl

diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 3365ebe4d9012b..d45b8891cf1a72 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -26,6 +26,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Support/Compiler.h"
 #include "llvm/Frontend/HLSL/HLSLResource.h"
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/VersionTuple.h"
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52ad72eb608c31..36ae98730db031 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,6 +4643,26 @@ def Error : InheritableAttr {
   let Documentation = [ErrorAttrDocs];
 }
 
+/// HLSL Root Signature Attribute
+def HLSLRootSignature : Attr {
+  /// [RootSignature(Signature)]
+  let Spellings = [Microsoft<"RootSignature">];
+  let Args = [StringArgument<"Signature">];
+  let Subjects = SubjectList<[Function],
+ ErrorDiag, "'function'">;
+  let LangOpts = [HLSL];
+  let Documentation = [HLSLRootSignatureDocs];
+  let AdditionalMembers = [{
+private:
+  ArrayRef RootElements;
+public:
+  void setElements(ArrayRef Elements) 
{
+RootElements = Elements;
+  }
+  auto getElements() const { return RootElements; }
+}];
+}
+
 def HLSLNumThreads: InheritableAttr {
   let Spellings = [Microsoft<"numthreads">];
   let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fdad4c9a3ea191..bb0934a11f9f3f 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7783,6 +7783,10 @@ and 
https://microsoft.github.io/hlsl-specs/proposals/0013-wave-size-range.html
   }];
 }
 
+def HLSLRootSignatureDocs : Documentation {
+  let Category = DocCatUndocumented;
+}
+
 def NumThreadsDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index f4cd11f423a84a..df4a5c8d88ba9e 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -116,6 +116,7 @@ class SemaHLSL : public SemaBase {
bool IsCompAssign);
   void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc);
 
+  void handleRootSignatureAttr(Decl *D, const ParsedAttr &AL);
   void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
   void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..c594d6e54ddbcd 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7149,6 +7149,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
 break;
 
   // HLSL attributes:
+  case ParsedAttr::AT_HLSLRootSignature:
+S.HLSL().handleRootSignatureAttr(D, AL);
+break;
   case ParsedAttr::AT_HLSLNumThreads:
 S.HLSL().handleNumThreadsAttr(D, AL);
 break;
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 600c800029fd05..5dd1e872a2b6f7 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -24,6 +24,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/Parse/ParseHLSLRootSignature.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/ParsedAttr.h"
 #include "clang/Sema/Sema.h"
@@ -647,6 +648,35 @@ void SemaHLSL::emitLogicalOperatorFixIt(Ex

[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-01-22 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/123985
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-01-22 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/123985

- Defines HLSLRootSignature Attr in `Attr.td`
- Define and implement handleHLSLRootSignature in `SemaHLSL`
- Adds sample test case to show AST Node is generated in 
`RootSignatures-AST.hlsl`

This commit will "hook-up" the seperately defined RootSignature parser and 
invoke it to create the RootElements, then store them on the ASTContext and 
finally store the reference to the Elements in RootSignatureAttr.

This pr essentially resolves #119011, however we will keep it open until we can 
resolve the FIXME when floating-point is supported in the parser/lexer. This 
will be done when we add support for StaticSampler's.

>From 42932906dc811f2f6953d0902143419daa030be7 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 22 Jan 2025 17:53:59 +
Subject: [PATCH] [HLSL] Define the HLSLRootSignature Attr

- Defines HLSLRootSignature Attr in `Attr.td`
- Define and implement handleHLSLRootSignature in `SemaHLSL`
- Adds sample test case to show AST Node is generated in
`RootSignatures-AST.hlsl`

This commit will "hook-up" the seperately defined RootSignature parser
and invoke it to create the RootElements, then store them on the
ASTContext and finally store the reference to the Elements in
RootSignatureAttr
---
 clang/include/clang/AST/Attr.h  |  1 +
 clang/include/clang/Basic/Attr.td   | 20 ++
 clang/include/clang/Basic/AttrDocs.td   |  4 +++
 clang/include/clang/Sema/SemaHLSL.h |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp |  3 +++
 clang/lib/Sema/SemaHLSL.cpp | 30 +
 clang/test/AST/HLSL/RootSignatures-AST.hlsl | 28 +++
 7 files changed, 87 insertions(+)
 create mode 100644 clang/test/AST/HLSL/RootSignatures-AST.hlsl

diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 3365ebe4d9012b..d45b8891cf1a72 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -26,6 +26,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Support/Compiler.h"
 #include "llvm/Frontend/HLSL/HLSLResource.h"
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/VersionTuple.h"
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52ad72eb608c31..36ae98730db031 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,6 +4643,26 @@ def Error : InheritableAttr {
   let Documentation = [ErrorAttrDocs];
 }
 
+/// HLSL Root Signature Attribute
+def HLSLRootSignature : Attr {
+  /// [RootSignature(Signature)]
+  let Spellings = [Microsoft<"RootSignature">];
+  let Args = [StringArgument<"Signature">];
+  let Subjects = SubjectList<[Function],
+ ErrorDiag, "'function'">;
+  let LangOpts = [HLSL];
+  let Documentation = [HLSLRootSignatureDocs];
+  let AdditionalMembers = [{
+private:
+  ArrayRef RootElements;
+public:
+  void setElements(ArrayRef Elements) 
{
+RootElements = Elements;
+  }
+  auto getElements() const { return RootElements; }
+}];
+}
+
 def HLSLNumThreads: InheritableAttr {
   let Spellings = [Microsoft<"numthreads">];
   let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fdad4c9a3ea191..bb0934a11f9f3f 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7783,6 +7783,10 @@ and 
https://microsoft.github.io/hlsl-specs/proposals/0013-wave-size-range.html
   }];
 }
 
+def HLSLRootSignatureDocs : Documentation {
+  let Category = DocCatUndocumented;
+}
+
 def NumThreadsDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index f4cd11f423a84a..df4a5c8d88ba9e 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -116,6 +116,7 @@ class SemaHLSL : public SemaBase {
bool IsCompAssign);
   void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc);
 
+  void handleRootSignatureAttr(Decl *D, const ParsedAttr &AL);
   void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
   void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..c594d6e54ddbcd 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7149,6 +7149,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
 break;
 
   // HLSL attributes:
+  case ParsedAttr::AT_HLSLRootSignature:
+S.HLSL().handleRootSignatureAttr(D, AL);
+break;

[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-01-22 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/123985

>From 42932906dc811f2f6953d0902143419daa030be7 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 22 Jan 2025 17:53:59 +
Subject: [PATCH 1/3] [HLSL] Define the HLSLRootSignature Attr

- Defines HLSLRootSignature Attr in `Attr.td`
- Define and implement handleHLSLRootSignature in `SemaHLSL`
- Adds sample test case to show AST Node is generated in
`RootSignatures-AST.hlsl`

This commit will "hook-up" the seperately defined RootSignature parser
and invoke it to create the RootElements, then store them on the
ASTContext and finally store the reference to the Elements in
RootSignatureAttr
---
 clang/include/clang/AST/Attr.h  |  1 +
 clang/include/clang/Basic/Attr.td   | 20 ++
 clang/include/clang/Basic/AttrDocs.td   |  4 +++
 clang/include/clang/Sema/SemaHLSL.h |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp |  3 +++
 clang/lib/Sema/SemaHLSL.cpp | 30 +
 clang/test/AST/HLSL/RootSignatures-AST.hlsl | 28 +++
 7 files changed, 87 insertions(+)
 create mode 100644 clang/test/AST/HLSL/RootSignatures-AST.hlsl

diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 3365ebe4d9012b..d45b8891cf1a72 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -26,6 +26,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Support/Compiler.h"
 #include "llvm/Frontend/HLSL/HLSLResource.h"
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/VersionTuple.h"
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52ad72eb608c31..36ae98730db031 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,6 +4643,26 @@ def Error : InheritableAttr {
   let Documentation = [ErrorAttrDocs];
 }
 
+/// HLSL Root Signature Attribute
+def HLSLRootSignature : Attr {
+  /// [RootSignature(Signature)]
+  let Spellings = [Microsoft<"RootSignature">];
+  let Args = [StringArgument<"Signature">];
+  let Subjects = SubjectList<[Function],
+ ErrorDiag, "'function'">;
+  let LangOpts = [HLSL];
+  let Documentation = [HLSLRootSignatureDocs];
+  let AdditionalMembers = [{
+private:
+  ArrayRef RootElements;
+public:
+  void setElements(ArrayRef Elements) 
{
+RootElements = Elements;
+  }
+  auto getElements() const { return RootElements; }
+}];
+}
+
 def HLSLNumThreads: InheritableAttr {
   let Spellings = [Microsoft<"numthreads">];
   let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fdad4c9a3ea191..bb0934a11f9f3f 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7783,6 +7783,10 @@ and 
https://microsoft.github.io/hlsl-specs/proposals/0013-wave-size-range.html
   }];
 }
 
+def HLSLRootSignatureDocs : Documentation {
+  let Category = DocCatUndocumented;
+}
+
 def NumThreadsDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index f4cd11f423a84a..df4a5c8d88ba9e 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -116,6 +116,7 @@ class SemaHLSL : public SemaBase {
bool IsCompAssign);
   void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc);
 
+  void handleRootSignatureAttr(Decl *D, const ParsedAttr &AL);
   void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
   void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..c594d6e54ddbcd 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7149,6 +7149,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
 break;
 
   // HLSL attributes:
+  case ParsedAttr::AT_HLSLRootSignature:
+S.HLSL().handleRootSignatureAttr(D, AL);
+break;
   case ParsedAttr::AT_HLSLNumThreads:
 S.HLSL().handleNumThreadsAttr(D, AL);
 break;
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 600c800029fd05..5dd1e872a2b6f7 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -24,6 +24,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/Parse/ParseHLSLRootSignature.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/ParsedAttr.h"
 #include "clang/Sema/Sema.h"
@@ -647,6 +648,35 @@ void SemaHLSL::emitLogicalOperatorFixIt(Ex

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-22 Thread Finn Plummer via llvm-branch-commits


@@ -148,6 +148,333 @@ bool RootSignatureLexer::LexToken(RootSignatureToken 
&Result) {
   return false;
 }
 
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(
+SmallVector &Elements,
+const SmallVector &Tokens)
+: Elements(Elements) {
+  CurTok = Tokens.begin();
+  LastTok = Tokens.end();
+}
+
+bool RootSignatureParser::ReportError() { return true; }
+
+bool RootSignatureParser::Parse() {
+  CurTok--; // Decrement once here so we can use the ...ExpectedToken api
+
+  // Iterate as many RootElements as possible
+  bool HasComma = true;
+  while (HasComma &&
+ !TryConsumeExpectedToken(ArrayRef{TokenKind::kw_DescriptorTable})) {
+if (ParseRootElement())
+  return true;
+HasComma = !TryConsumeExpectedToken(TokenKind::pu_comma);
+  }
+  if (HasComma)
+return ReportError(); // report 'comma' denotes a required extra item
+
+  // Ensure that we are at the end of the tokens
+  CurTok++;
+  if (CurTok != LastTok)
+return ReportError(); // report expected end of input but got more
+  return false;
+}
+
+bool RootSignatureParser::ParseRootElement() {
+  // Dispatch onto the correct parse method
+  switch (CurTok->Kind) {
+  case TokenKind::kw_DescriptorTable:
+return ParseDescriptorTable();
+  default:
+llvm_unreachable("Switch for an expected token was not provided");
+return true;
+  }
+}
+
+bool RootSignatureParser::ParseDescriptorTable() {
+  DescriptorTable Table;
+
+  if (ConsumeExpectedToken(TokenKind::pu_l_paren))
+return true;
+
+  // Iterate as many DescriptorTableClaues as possible
+  bool HasComma = true;
+  while (!TryConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV,
+   TokenKind::kw_UAV, TokenKind::kw_Sampler})) 
{
+if (ParseDescriptorTableClause())
+  return true;
+Table.NumClauses++;
+HasComma = !TryConsumeExpectedToken(TokenKind::pu_comma);
+  }
+
+  // Consume optional 'visibility' paramater
+  if (HasComma && !TryConsumeExpectedToken(TokenKind::kw_visibility)) {
+if (ConsumeExpectedToken(TokenKind::pu_equal))
+  return true;
+
+if (ParseShaderVisibility(Table.Visibility))
+  return true;
+
+HasComma = !TryConsumeExpectedToken(TokenKind::pu_comma);
+  }
+
+  if (HasComma && Table.NumClauses != 0)
+return ReportError(); // report 'comma' denotes a required extra item
+
+  if (ConsumeExpectedToken(TokenKind::pu_r_paren))
+return true;
+
+  Elements.push_back(RootElement(Table));
+  return false;
+}
+
+bool RootSignatureParser::ParseDescriptorTableClause() {
+  // Determine the type of Clause first so we can initialize the struct with
+  // the correct default flags
+  ClauseType CT;
+  switch (CurTok->Kind) {
+  case TokenKind::kw_CBV:
+CT = ClauseType::CBV;
+break;
+  case TokenKind::kw_SRV:
+CT = ClauseType::SRV;
+break;
+  case TokenKind::kw_UAV:
+CT = ClauseType::UAV;
+break;
+  case TokenKind::kw_Sampler:
+CT = ClauseType::Sampler;
+break;
+  default:
+llvm_unreachable("Switch for an expected token was not provided");
+return true;
+  }
+  DescriptorTableClause Clause(CT);
+
+  if (ConsumeExpectedToken(TokenKind::pu_l_paren))
+return true;
+
+  // Consume mandatory Register paramater
+  if (ConsumeExpectedToken(
+  {TokenKind::bReg, TokenKind::tReg, TokenKind::uReg, 
TokenKind::sReg}))
+return true;
+  if (ParseRegister(Clause.Register))
+return true;
+
+  // Start parsing the optional parameters

inbelic wrote:

My understanding of the grammar specified 
[here](https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#root-signature-grammar)
 was that they need to be in the given order. Although looking at DXC's 
implementation it seems they can be specified in any order.

https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-01-22 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic ready_for_review 
https://github.com/llvm/llvm-project/pull/123985
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-23 Thread Finn Plummer via llvm-branch-commits


@@ -148,6 +148,333 @@ bool RootSignatureLexer::LexToken(RootSignatureToken 
&Result) {
   return false;
 }
 
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(
+SmallVector &Elements,
+const SmallVector &Tokens)
+: Elements(Elements) {
+  CurTok = Tokens.begin();
+  LastTok = Tokens.end();
+}
+
+bool RootSignatureParser::ReportError() { return true; }
+
+bool RootSignatureParser::Parse() {
+  CurTok--; // Decrement once here so we can use the ...ExpectedToken api
+
+  // Iterate as many RootElements as possible
+  bool HasComma = true;
+  while (HasComma &&
+ !TryConsumeExpectedToken(ArrayRef{TokenKind::kw_DescriptorTable})) {
+if (ParseRootElement())
+  return true;
+HasComma = !TryConsumeExpectedToken(TokenKind::pu_comma);
+  }
+  if (HasComma)
+return ReportError(); // report 'comma' denotes a required extra item
+
+  // Ensure that we are at the end of the tokens
+  CurTok++;
+  if (CurTok != LastTok)
+return ReportError(); // report expected end of input but got more
+  return false;
+}
+
+bool RootSignatureParser::ParseRootElement() {
+  // Dispatch onto the correct parse method
+  switch (CurTok->Kind) {
+  case TokenKind::kw_DescriptorTable:
+return ParseDescriptorTable();
+  default:
+llvm_unreachable("Switch for an expected token was not provided");
+return true;
+  }
+}
+
+bool RootSignatureParser::ParseDescriptorTable() {
+  DescriptorTable Table;
+
+  if (ConsumeExpectedToken(TokenKind::pu_l_paren))
+return true;
+
+  // Iterate as many DescriptorTableClaues as possible
+  bool HasComma = true;
+  while (!TryConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV,
+   TokenKind::kw_UAV, TokenKind::kw_Sampler})) 
{
+if (ParseDescriptorTableClause())
+  return true;
+Table.NumClauses++;
+HasComma = !TryConsumeExpectedToken(TokenKind::pu_comma);
+  }
+
+  // Consume optional 'visibility' paramater
+  if (HasComma && !TryConsumeExpectedToken(TokenKind::kw_visibility)) {
+if (ConsumeExpectedToken(TokenKind::pu_equal))
+  return true;
+
+if (ParseShaderVisibility(Table.Visibility))
+  return true;
+
+HasComma = !TryConsumeExpectedToken(TokenKind::pu_comma);
+  }
+
+  if (HasComma && Table.NumClauses != 0)
+return ReportError(); // report 'comma' denotes a required extra item
+
+  if (ConsumeExpectedToken(TokenKind::pu_r_paren))
+return true;
+
+  Elements.push_back(RootElement(Table));
+  return false;
+}
+
+bool RootSignatureParser::ParseDescriptorTableClause() {
+  // Determine the type of Clause first so we can initialize the struct with
+  // the correct default flags
+  ClauseType CT;
+  switch (CurTok->Kind) {
+  case TokenKind::kw_CBV:
+CT = ClauseType::CBV;
+break;
+  case TokenKind::kw_SRV:
+CT = ClauseType::SRV;
+break;
+  case TokenKind::kw_UAV:
+CT = ClauseType::UAV;
+break;
+  case TokenKind::kw_Sampler:
+CT = ClauseType::Sampler;
+break;
+  default:
+llvm_unreachable("Switch for an expected token was not provided");
+return true;
+  }
+  DescriptorTableClause Clause(CT);
+
+  if (ConsumeExpectedToken(TokenKind::pu_l_paren))
+return true;
+
+  // Consume mandatory Register paramater
+  if (ConsumeExpectedToken(
+  {TokenKind::bReg, TokenKind::tReg, TokenKind::uReg, 
TokenKind::sReg}))
+return true;
+  if (ParseRegister(Clause.Register))
+return true;
+
+  // Start parsing the optional parameters

inbelic wrote:

Confirmed that we should accept the parameters in any order. So will need to 
refactor this.

https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-23 Thread Finn Plummer via llvm-branch-commits

inbelic wrote:

Sounds good, and I appreciate the feedback. I will restructure the changes to 
be of smaller granularity, which will be better self-contained and directly 
include their diagnostics testing.

https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-23 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic converted_to_draft 
https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-17 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-17 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/122982

>From 58ef8ad2d3d9bfa008745b35f1514222c13b773a Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Tue, 14 Jan 2025 22:23:22 +
Subject: [PATCH 1/3] [HLSL][RootSignature] Implement Parsing of Descriptor
 Tables

- Defines the in-memory data layout for the Descriptor Table Clauses,
its dependent flags/enums and parent RootElement in HLSLRootSignature.h
- Implements a Parser and its required Parsing methods in
ParseHLSLRootSignature
---
 .../clang/Parse/ParseHLSLRootSignature.h  |  68 
 clang/lib/Parse/ParseHLSLRootSignature.cpp| 327 ++
 .../Parse/ParseHLSLRootSignatureTest.cpp  |  85 +
 .../llvm/Frontend/HLSL/HLSLRootSignature.h| 140 
 4 files changed, 620 insertions(+)
 create mode 100644 llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index 6c534411e754a0..9464bd8f2f9e0f 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -21,6 +21,8 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
+
 namespace llvm {
 namespace hlsl {
 namespace root_signature {
@@ -89,6 +91,72 @@ class RootSignatureLexer {
   }
 };
 
+class RootSignatureParser {
+public:
+  RootSignatureParser(SmallVector &Elements,
+  const SmallVector &Tokens);
+
+  // Iterates over the provided tokens and constructs the in-memory
+  // representations of the RootElements.
+  //
+  // The return value denotes if there was a failure and the method will
+  // return on the first encountered failure, or, return false if it
+  // can sucessfully reach the end of the tokens.
+  bool Parse();
+
+private:
+  bool ReportError(); // TODO: Implement this to report error through Diags
+
+  // Root Element helpers
+  bool ParseRootElement();
+  bool ParseDescriptorTable();
+  bool ParseDescriptorTableClause();
+
+  // Common parsing helpers
+  bool ParseRegister(Register &Register);
+
+  // Various flags/enum parsing helpers
+  bool ParseDescriptorRangeFlags(DescriptorRangeFlags &Flags);
+  bool ParseShaderVisibility(ShaderVisibility &Flag);
+
+  // Increment the token iterator if we have not reached the end.
+  // Return value denotes if we were already at the last token.
+  bool ConsumeNextToken();
+
+  // Attempt to retrieve the next token, if TokenKind is invalid then there was
+  // no next token.
+  RootSignatureToken PeekNextToken();
+
+  // Peek if the next token is of the expected kind.
+  //
+  // Return value denotes if it failed to match the expected kind, either it is
+  // the end of the stream or it didn't match any of the expected kinds.
+  bool PeekExpectedToken(TokenKind Expected);
+  bool PeekExpectedToken(ArrayRef AnyExpected);
+
+  // Consume the next token and report an error if it is not of the expected
+  // kind.
+  //
+  // Return value denotes if it failed to match the expected kind, either it is
+  // the end of the stream or it didn't match any of the expected kinds.
+  bool ConsumeExpectedToken(TokenKind Expected);
+  bool ConsumeExpectedToken(ArrayRef AnyExpected);
+
+  // Peek if the next token is of the expected kind and if it is then consume
+  // it.
+  //
+  // Return value denotes if it failed to match the expected kind, either it is
+  // the end of the stream or it didn't match any of the expected kinds. It 
will
+  // not report an error if there isn't a match.
+  bool TryConsumeExpectedToken(TokenKind Expected);
+  bool TryConsumeExpectedToken(ArrayRef Expected);
+
+private:
+  SmallVector &Elements;
+  SmallVector::const_iterator CurTok;
+  SmallVector::const_iterator LastTok;
+};
+
 } // namespace root_signature
 } // namespace hlsl
 } // namespace llvm
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp 
b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index fac4a92f1920be..c5e6dd112c6fae 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -148,6 +148,333 @@ bool RootSignatureLexer::LexToken(RootSignatureToken 
&Result) {
   return false;
 }
 
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(
+SmallVector &Elements,
+const SmallVector &Tokens)
+: Elements(Elements) {
+  CurTok = Tokens.begin();
+  LastTok = Tokens.end();
+}
+
+bool RootSignatureParser::ReportError() { return true; }
+
+bool RootSignatureParser::Parse() {
+  CurTok--; // Decrement once here so we can use the ...ExpectedToken api
+
+  // Iterate as many RootElements as possible
+  bool HasComma = true;
+  while (HasComma &&
+ !TryConsumeExpectedToken(ArrayRef{TokenKind::kw_DescriptorTable})) {
+if (ParseRootElement())
+  return true;
+HasComma = !TryConsumeExpectedToken(TokenKind::pu_comma);
+  }
+  if (HasComma)
+return Report

[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-01-27 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/123985
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-01-27 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/123985
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-28 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/122982

>From 5ed5fcfebb395cdfe45dc41094e07716d2003d66 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Tue, 28 Jan 2025 17:49:21 +
Subject: [PATCH 01/13] [HLSL][RootSignature] Handle an empty root signature

- Define the Parser struct
- Model RootElements as a variant of the different types
- Create a basic test case for unit testing
---
 .../clang/Parse/ParseHLSLRootSignature.h  | 26 
 clang/lib/Parse/ParseHLSLRootSignature.cpp| 19 
 .../Parse/ParseHLSLRootSignatureTest.cpp  | 26 
 .../llvm/Frontend/HLSL/HLSLRootSignature.h| 30 +++
 4 files changed, 101 insertions(+)
 create mode 100644 llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index 899608bd1527ea..2e01f86f832f76 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -22,9 +22,13 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
+
 namespace clang {
 namespace hlsl {
 
+namespace rs = llvm::hlsl::root_signature;
+
 struct RootSignatureToken {
   enum Kind {
 #define TOK(X) X,
@@ -80,6 +84,28 @@ class RootSignatureLexer {
   }
 };
 
+class RootSignatureParser {
+public:
+  RootSignatureParser(SmallVector &Elements,
+  const SmallVector &Tokens,
+  DiagnosticsEngine &Diags);
+
+  // Iterates over the provided tokens and constructs the in-memory
+  // representations of the RootElements.
+  //
+  // The return value denotes if there was a failure and the method will
+  // return on the first encountered failure, or, return false if it
+  // can sucessfully reach the end of the tokens.
+  bool Parse();
+
+private:
+  SmallVector &Elements;
+  SmallVector::const_iterator CurTok;
+  SmallVector::const_iterator LastTok;
+
+  DiagnosticsEngine &Diags;
+};
+
 } // namespace hlsl
 } // namespace clang
 
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp 
b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index 7ceb85a47a088e..2ba756f3bd09f2 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -1,5 +1,7 @@
 #include "clang/Parse/ParseHLSLRootSignature.h"
 
+using namespace llvm::hlsl::root_signature;
+
 namespace clang {
 namespace hlsl {
 
@@ -169,5 +171,22 @@ bool RootSignatureLexer::LexToken(RootSignatureToken 
&Result) {
   return false;
 }
 
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(
+SmallVector &Elements,
+const SmallVector &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;
+
+  return true;
+}
 } // namespace hlsl
 } // namespace clang
diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp 
b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
index 57b61e43746a0b..87bceeeb3283ef 100644
--- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
+++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
@@ -24,6 +24,7 @@
 #include "gtest/gtest.h"
 
 using namespace clang;
+using namespace llvm::hlsl::root_signature;
 
 namespace {
 
@@ -279,4 +280,29 @@ TEST_F(ParseHLSLRootSignatureTest, 
InvalidLexIdentifierTest) {
   ASSERT_TRUE(Consumer->IsSatisfied());
 }
 
+// Valid Parser Tests
+
+TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
+  const llvm::StringLiteral Source = R"cc()cc";
+
+  TrivialModuleLoader ModLoader;
+  auto PP = CreatePP(Source, ModLoader);
+  auto TokLoc = SourceLocation();
+
+  // Test no diagnostics produced
+  Consumer->SetNoDiag();
+  hlsl::RootSignatureLexer Lexer(Source, TokLoc, *PP);
+
+  SmallVector Tokens;
+  ASSERT_FALSE(Lexer.Lex(Tokens));
+
+  SmallVector Elements;
+  hlsl::RootSignatureParser Parser(Elements, Tokens, Diags);
+
+  ASSERT_FALSE(Parser.Parse());
+  ASSERT_EQ((int)Elements.size(), 0);
+
+  ASSERT_TRUE(Consumer->IsSatisfied());
+}
+
 } // anonymous namespace
diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h 
b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
new file mode 100644
index 00..4c196d29a01bbb
--- /dev/null
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
@@ -0,0 +1,30 @@
+//===- HLSLRootSignature.h - 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 helpe

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-28 Thread Finn Plummer via llvm-branch-commits

inbelic wrote:

Updated to include diagnostics output and the relevant testing.

I have rebased to split the pr into smaller incremental changes, to help with 
review. And I have taken care to address all previous comments. Unfortunately 
the rebase causes these comments to get lost :/

I have implemented the suggestion to use `std::variant` to model the 
`RootElement` data-type, re-used the `dxil::ResourceClass` for `ClauseType`.

Notably though, there was some bigger changes introduced to handle that the 
optional parameters can be specified in any order.

https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-28 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic ready_for_review 
https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-01-28 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/123985

>From 9efdfc1ca3d6c02e441715061ed04b52504bc179 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 22 Jan 2025 17:53:59 +
Subject: [PATCH 1/3] [HLSL] Define the HLSLRootSignature Attr

- Defines HLSLRootSignature Attr in `Attr.td`
- Define and implement handleHLSLRootSignature in `SemaHLSL`
- Adds sample test case to show AST Node is generated in
`RootSignatures-AST.hlsl`

This commit will "hook-up" the seperately defined RootSignature parser
and invoke it to create the RootElements, then store them on the
ASTContext and finally store the reference to the Elements in
RootSignatureAttr
---
 clang/include/clang/AST/Attr.h  |  1 +
 clang/include/clang/Basic/Attr.td   | 20 ++
 clang/include/clang/Basic/AttrDocs.td   |  4 +++
 clang/include/clang/Sema/SemaHLSL.h |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp |  3 +++
 clang/lib/Sema/SemaHLSL.cpp | 30 +
 clang/test/AST/HLSL/RootSignatures-AST.hlsl | 28 +++
 7 files changed, 87 insertions(+)
 create mode 100644 clang/test/AST/HLSL/RootSignatures-AST.hlsl

diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 3365ebe4d9012b..d45b8891cf1a72 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -26,6 +26,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Support/Compiler.h"
 #include "llvm/Frontend/HLSL/HLSLResource.h"
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/VersionTuple.h"
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52ad72eb608c31..36ae98730db031 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,6 +4643,26 @@ def Error : InheritableAttr {
   let Documentation = [ErrorAttrDocs];
 }
 
+/// HLSL Root Signature Attribute
+def HLSLRootSignature : Attr {
+  /// [RootSignature(Signature)]
+  let Spellings = [Microsoft<"RootSignature">];
+  let Args = [StringArgument<"Signature">];
+  let Subjects = SubjectList<[Function],
+ ErrorDiag, "'function'">;
+  let LangOpts = [HLSL];
+  let Documentation = [HLSLRootSignatureDocs];
+  let AdditionalMembers = [{
+private:
+  ArrayRef RootElements;
+public:
+  void setElements(ArrayRef Elements) 
{
+RootElements = Elements;
+  }
+  auto getElements() const { return RootElements; }
+}];
+}
+
 def HLSLNumThreads: InheritableAttr {
   let Spellings = [Microsoft<"numthreads">];
   let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fdad4c9a3ea191..bb0934a11f9f3f 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7783,6 +7783,10 @@ and 
https://microsoft.github.io/hlsl-specs/proposals/0013-wave-size-range.html
   }];
 }
 
+def HLSLRootSignatureDocs : Documentation {
+  let Category = DocCatUndocumented;
+}
+
 def NumThreadsDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index f4cd11f423a84a..df4a5c8d88ba9e 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -116,6 +116,7 @@ class SemaHLSL : public SemaBase {
bool IsCompAssign);
   void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc);
 
+  void handleRootSignatureAttr(Decl *D, const ParsedAttr &AL);
   void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
   void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..c594d6e54ddbcd 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7149,6 +7149,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
 break;
 
   // HLSL attributes:
+  case ParsedAttr::AT_HLSLRootSignature:
+S.HLSL().handleRootSignatureAttr(D, AL);
+break;
   case ParsedAttr::AT_HLSLNumThreads:
 S.HLSL().handleNumThreadsAttr(D, AL);
 break;
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 600c800029fd05..5dd1e872a2b6f7 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -24,6 +24,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/Parse/ParseHLSLRootSignature.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/ParsedAttr.h"
 #include "clang/Sema/Sema.h"
@@ -647,6 +648,35 @@ void SemaHLSL::emitLogicalOperatorFixIt(Ex

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-28 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/122982

>From 44d3086a5a8b53a734bbabe32d7c34195def2d65 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Fri, 24 Jan 2025 22:28:05 +
Subject: [PATCH 01/17] [HLSL][RootSignature] Add lexing of integer literals

- Integrate the use of the `NumericLiteralParser` to lex integer
literals
- Add additional hlsl specific diagnostics messages
---
 .../include/clang/Basic/DiagnosticLexKinds.td |  4 ++
 .../Parse/HLSLRootSignatureTokenKinds.def |  1 +
 .../clang/Parse/ParseHLSLRootSignature.h  |  6 ++
 clang/lib/Parse/ParseHLSLRootSignature.cpp| 59 
 .../Parse/ParseHLSLRootSignatureTest.cpp  | 69 +++
 5 files changed, 139 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 7755c05bc8969b..81d314c838cede 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -1020,6 +1020,10 @@ Error<"expected 'begin' or 'end'">;
 
 // HLSL Root Signature Lexing Errors
 let CategoryName = "Root Signature Lexical Issue" in {
+  def err_hlsl_invalid_number_literal:
+Error<"expected number literal is not a supported number literal of 
unsigned integer or integer">;
+  def err_hlsl_number_literal_overflow :
+Error<"provided %select{unsigned integer|signed integer}0 literal '%1' 
that overflows the maximum of 32 bits">;
   def err_hlsl_invalid_token: Error<"unable to lex a valid Root Signature 
token">;
 }
 
diff --git a/clang/include/clang/Parse/HLSLRootSignatureTokenKinds.def 
b/clang/include/clang/Parse/HLSLRootSignatureTokenKinds.def
index 9625f6a5bd76d9..64c5fd14a2017f 100644
--- a/clang/include/clang/Parse/HLSLRootSignatureTokenKinds.def
+++ b/clang/include/clang/Parse/HLSLRootSignatureTokenKinds.def
@@ -23,6 +23,7 @@
 
 // General Tokens:
 TOK(invalid)
+TOK(int_literal)
 
 // Punctuators:
 PUNCTUATOR(l_paren, '(')
diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index 39069e7cc39988..3b2c61781b1da3 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -13,7 +13,9 @@
 #ifndef LLVM_CLANG_PARSE_PARSEHLSLROOTSIGNATURE_H
 #define LLVM_CLANG_PARSE_PARSEHLSLROOTSIGNATURE_H
 
+#include "clang/AST/APValue.h"
 #include "clang/Basic/DiagnosticLex.h"
+#include "clang/Lex/LiteralSupport.h"
 #include "clang/Lex/Preprocessor.h"
 
 #include "llvm/ADT/SmallVector.h"
@@ -33,6 +35,8 @@ struct RootSignatureToken {
   // Retain the SouceLocation of the token for diagnostics
   clang::SourceLocation TokLoc;
 
+  APValue NumLiteral = APValue();
+
   // Constructors
   RootSignatureToken(clang::SourceLocation TokLoc) : TokLoc(TokLoc) {}
 };
@@ -60,6 +64,8 @@ class RootSignatureLexer {
   clang::SourceLocation SourceLoc;
   clang::Preprocessor &PP;
 
+  bool LexNumber(RootSignatureToken &Result);
+
   // Consumes the internal buffer for a single token.
   //
   // The return value denotes if there was a failure.
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp 
b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index a9a9d209085c91..1cc75998ca07da 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -5,6 +5,61 @@ namespace hlsl {
 
 // Lexer Definitions
 
+static bool IsNumberChar(char C) {
+  // TODO(#120472): extend for float support exponents
+  return isdigit(C); // integer support
+}
+
+bool RootSignatureLexer::LexNumber(RootSignatureToken &Result) {
+  // NumericLiteralParser does not handle the sign so we will manually apply it
+  bool Negative = Buffer.front() == '-';
+  bool Signed = Negative || Buffer.front() == '+';
+  if (Signed)
+AdvanceBuffer();
+
+  // Retrieve the possible number
+  StringRef NumSpelling = Buffer.take_while(IsNumberChar);
+
+  // Catch this now as the Literal Parser will accept it as valid
+  if (NumSpelling.empty()) {
+PP.getDiagnostics().Report(Result.TokLoc,
+   diag::err_hlsl_invalid_number_literal);
+return true;
+  }
+
+  // Parse the numeric value and do semantic checks on its specification
+  clang::NumericLiteralParser Literal(NumSpelling, SourceLoc,
+  PP.getSourceManager(), PP.getLangOpts(),
+  PP.getTargetInfo(), PP.getDiagnostics());
+  if (Literal.hadError)
+return true; // Error has already been reported so just return
+
+  if (!Literal.isIntegerLiteral()) {
+// Note: if IsNumberChar allows for hexidecimal we will need to turn this
+// into a diagnostics for potential fixed-point literals
+llvm_unreachable("IsNumberChar will only support digits");
+return true;
+  }
+
+  // Retrieve the number value to store into the token
+  Result.Kind = TokenKind::int_literal;
+
+  llvm::APSInt X = llvm::APSInt(32, !Signed);

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-28 Thread Finn Plummer via llvm-branch-commits


@@ -0,0 +1,140 @@
+//===- HLSLRootSignature.h - 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 helper objects for working with HLSL Root
+/// Signatures.
+///
+//===--===//
+
+#ifndef LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
+#define LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
+
+#include 
+
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Endian.h"
+
+namespace llvm {
+namespace hlsl {
+namespace root_signature {
+
+// This is a copy from DebugInfo/CodeView/CodeView.h
+#define RS_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(Class)
\
+  inline Class operator|(Class a, Class b) {   
\
+return static_cast(llvm::to_underlying(a) | 
\
+  llvm::to_underlying(b)); 
\
+  }
\
+  inline Class operator&(Class a, Class b) {   
\
+return static_cast(llvm::to_underlying(a) & 
\
+  llvm::to_underlying(b)); 
\
+  }
\
+  inline Class operator~(Class a) {
\
+return static_cast(~llvm::to_underlying(a));
\
+  }
\
+  inline Class &operator|=(Class &a, Class b) {
\
+a = a | b; 
\
+return a;  
\
+  }
\
+  inline Class &operator&=(Class &a, Class b) {
\
+a = a & b; 
\
+return a;  
\
+  }
+
+// Definition of the various enumerations and flags
+enum class DescriptorRangeFlags : unsigned {
+  None = 0,
+  DescriptorsVolatile = 0x1,
+  DataVolatile = 0x2,
+  DataStaticWhileSetAtExecute = 0x4,
+  DataStatic = 0x8,
+  DescriptorsStaticKeepingBufferBoundsChecks = 0x1,
+  ValidFlags = 0x1000f,
+  ValidSamplerFlags = DescriptorsVolatile,
+};
+RS_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(DescriptorRangeFlags)
+
+enum class ShaderVisibility {
+  All = 0,
+  Vertex = 1,
+  Hull = 2,
+  Domain = 3,
+  Geometry = 4,
+  Pixel = 5,
+  Amplification = 6,
+  Mesh = 7,
+};
+
+// Definitions of the in-memory data layout structures
+
+// Models the different registers: bReg | tReg | uReg | sReg
+enum class RegisterType { BReg, TReg, UReg, SReg };
+struct Register {
+  RegisterType ViewType;
+  uint32_t Number;
+};
+
+static const uint32_t DescriptorTableOffsetAppend = 0x;
+// Models DTClause : CBV | SRV | UAV | Sampler by collecting like parameters
+enum class ClauseType { CBV, SRV, UAV, Sampler };
+struct DescriptorTableClause {
+  ClauseType Type;
+  Register Register;
+  uint32_t NumDescriptors = 1;
+  uint32_t Space = 0;
+  uint32_t Offset = DescriptorTableOffsetAppend;
+  DescriptorRangeFlags Flags;
+
+  DescriptorTableClause(ClauseType Type) : Type(Type) {
+switch (Type) {
+case ClauseType::CBV:
+  Flags = DescriptorRangeFlags::DataStaticWhileSetAtExecute;
+  break;
+case ClauseType::SRV:
+  Flags = DescriptorRangeFlags::DataStaticWhileSetAtExecute;
+  break;
+case ClauseType::UAV:
+  Flags = DescriptorRangeFlags::DataVolatile;
+  break;
+case ClauseType::Sampler:
+  Flags = DescriptorRangeFlags::None;
+  break;
+}
+  }
+};
+
+// Models the end of a descriptor table and stores its visibility
+struct DescriptorTable {
+  ShaderVisibility Visibility = ShaderVisibility::All;
+  uint32_t NumClauses = 0; // The number of clauses in the table
+};
+
+// Models RootElement : DescriptorTable | DescriptorTableClause
+struct RootElement {

inbelic wrote:

Nope, good idea! Switched

https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-28 Thread Finn Plummer via llvm-branch-commits


@@ -148,6 +148,347 @@ bool RootSignatureLexer::LexToken(RootSignatureToken 
&Result) {
   return false;
 }
 
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(
+SmallVector &Elements,
+const SmallVector &Tokens)
+: Elements(Elements) {
+  CurTok = Tokens.begin();
+  LastTok = Tokens.end();
+}
+
+bool RootSignatureParser::ReportError() { return true; }
+
+bool RootSignatureParser::Parse() {
+  // Handle edge-case of empty RootSignature()
+  if (CurTok == LastTok)
+return false;
+
+  // Iterate as many RootElements as possible
+  bool HasComma = true;
+  while (HasComma &&
+ IsCurExpectedToken(ArrayRef{TokenKind::kw_DescriptorTable})) {
+if (ParseRootElement())
+  return true;
+HasComma = !TryConsumeExpectedToken(TokenKind::pu_comma);
+if (HasComma)
+  ConsumeNextToken();
+  }
+
+  if (HasComma)
+return ReportError(); // report 'comma' denotes a required extra item
+
+  // Ensure that we are at the end of the tokens
+  CurTok++;
+  if (CurTok != LastTok)
+return ReportError(); // report expected end of input but got more
+  return false;
+}
+
+bool RootSignatureParser::ParseRootElement() {
+  // Dispatch onto the correct parse method
+  switch (CurTok->Kind) {
+  case TokenKind::kw_DescriptorTable:
+return ParseDescriptorTable();
+  default:
+llvm_unreachable("Switch for an expected token was not provided");
+return true;

inbelic wrote:

Return `true` denotes that we occurred an error, so after hitting the 
unreachable state, this will just let the parser error out.

https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-28 Thread Finn Plummer via llvm-branch-commits


@@ -0,0 +1,140 @@
+//===- HLSLRootSignature.h - 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 helper objects for working with HLSL Root
+/// Signatures.
+///
+//===--===//
+
+#ifndef LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
+#define LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
+
+#include 
+
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Endian.h"
+
+namespace llvm {
+namespace hlsl {
+namespace root_signature {
+
+// This is a copy from DebugInfo/CodeView/CodeView.h
+#define RS_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(Class)
\
+  inline Class operator|(Class a, Class b) {   
\
+return static_cast(llvm::to_underlying(a) | 
\
+  llvm::to_underlying(b)); 
\
+  }
\
+  inline Class operator&(Class a, Class b) {   
\
+return static_cast(llvm::to_underlying(a) & 
\
+  llvm::to_underlying(b)); 
\
+  }
\
+  inline Class operator~(Class a) {
\
+return static_cast(~llvm::to_underlying(a));
\
+  }
\
+  inline Class &operator|=(Class &a, Class b) {
\
+a = a | b; 
\
+return a;  
\
+  }
\
+  inline Class &operator&=(Class &a, Class b) {
\
+a = a & b; 
\
+return a;  
\
+  }
+
+// Definition of the various enumerations and flags
+enum class DescriptorRangeFlags : unsigned {
+  None = 0,
+  DescriptorsVolatile = 0x1,
+  DataVolatile = 0x2,
+  DataStaticWhileSetAtExecute = 0x4,
+  DataStatic = 0x8,
+  DescriptorsStaticKeepingBufferBoundsChecks = 0x1,
+  ValidFlags = 0x1000f,
+  ValidSamplerFlags = DescriptorsVolatile,
+};
+RS_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(DescriptorRangeFlags)
+
+enum class ShaderVisibility {
+  All = 0,
+  Vertex = 1,
+  Hull = 2,
+  Domain = 3,
+  Geometry = 4,
+  Pixel = 5,
+  Amplification = 6,
+  Mesh = 7,
+};
+
+// Definitions of the in-memory data layout structures
+
+// Models the different registers: bReg | tReg | uReg | sReg
+enum class RegisterType { BReg, TReg, UReg, SReg };
+struct Register {
+  RegisterType ViewType;
+  uint32_t Number;
+};
+
+static const uint32_t DescriptorTableOffsetAppend = 0x;
+// Models DTClause : CBV | SRV | UAV | Sampler by collecting like parameters
+enum class ClauseType { CBV, SRV, UAV, Sampler };
+struct DescriptorTableClause {
+  ClauseType Type;
+  Register Register;

inbelic wrote:

Switched to use a non-constructor function to avoid implying that the register 
would be initialized.

https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-01-29 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-02-14 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/122982

error: too big or took too long to generate
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-02-14 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-02-14 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic deleted 
https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-02-14 Thread Finn Plummer via llvm-branch-commits


@@ -306,4 +307,254 @@ TEST_F(ParseHLSLRootSignatureTest, 
InvalidLexRegNumberTest) {
   ASSERT_FALSE(Consumer->IsSatisfied());
 }
 
+// Valid Parser Tests
+
+TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
+  const llvm::StringLiteral Source = R"cc()cc";
+
+  TrivialModuleLoader ModLoader;
+  auto PP = CreatePP(Source, ModLoader);
+  auto TokLoc = SourceLocation();
+
+  hlsl::RootSignatureLexer Lexer(Source, TokLoc, *PP);
+  SmallVector Elements;
+  hlsl::RootSignatureParser Parser(Elements, Lexer, Diags);
+
+  // Test no diagnostics produced
+  Consumer->SetNoDiag();
+
+  ASSERT_FALSE(Parser.Parse());
+  ASSERT_EQ((int)Elements.size(), 0);

inbelic wrote:

Updated this and other casting to use the `u` notation.

https://github.com/llvm/llvm-project/pull/122982
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add infastructure to parse parameters (PR #133800)

2025-03-31 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/133800

- defines `ParamType` as a way to represent a reference to some
parameter in a root signature

- defines `ParseParam` and `ParseParams` as an infastructure to define
how the parameters of a given struct should be parsed in an orderless
manner

- implements parsing of two param types: `UInt32` and `Register` to
demonstrate the parsing implementation and allow for unit testing

Part two of implementing: https://github.com/llvm/llvm-project/issues/126569

>From 71ae66142abb2e6e43a60ce521dc638ec702399f Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Mon, 31 Mar 2025 18:29:26 +
Subject: [PATCH 1/3] [HLSL][RootSignature] Add infastructure to parse
 parameters

- defines `ParamType` as a way to represent a reference to some
parameter in a root signature

- defines `ParseParam` and `ParseParams` as an infastructure to define
how the parameters of a given struct should be parsed in an orderless
manner
---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 +-
 .../clang/Parse/ParseHLSLRootSignature.h  | 32 
 clang/lib/Parse/ParseHLSLRootSignature.cpp| 51 +++
 .../llvm/Frontend/HLSL/HLSLRootSignature.h|  6 +++
 4 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 2582e1e5ef0f6..f25c9c930cc61 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1830,8 +1830,10 @@ def err_hlsl_virtual_function
 def err_hlsl_virtual_inheritance
 : Error<"virtual inheritance is unsupported in HLSL">;
 
-// HLSL Root Siganture diagnostic messages
+// HLSL Root Signature Parser Diagnostics
 def err_hlsl_unexpected_end_of_params
 : Error<"expected %0 to denote end of parameters, or, another valid 
parameter of %1">;
+def err_hlsl_rootsig_repeat_param : Error<"specified the same parameter '%0' 
multiple times">;
+def err_hlsl_rootsig_missing_param : Error<"did not specify mandatory 
parameter '%0'">;
 
 } // end of Parser diagnostics
diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index 43b41315b88b5..b39267dbaaa28 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -69,6 +69,38 @@ class RootSignatureParser {
   bool parseDescriptorTable();
   bool parseDescriptorTableClause();
 
+  /// Each unique ParamType will have a custom parse method defined that we can
+  /// use to invoke the parameters.
+  ///
+  /// This function will switch on the ParamType using std::visit and dispatch
+  /// onto the corresponding parse method
+  bool parseParam(llvm::hlsl::rootsig::ParamType Ref);
+
+  /// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
+  /// order, exactly once, and only a subset are mandatory. This function acts
+  /// as the infastructure to do so in a declarative way.
+  ///
+  /// For the example:
+  ///  SmallDenseMap Params = {
+  ///TokenKind::bReg, &Clause.Register,
+  ///TokenKind::kw_space, &Clause.Space
+  ///  };
+  ///  SmallDenseSet Mandatory = {
+  ///TokenKind::kw_numDescriptors
+  ///  };
+  ///
+  /// We can read it is as:
+  ///
+  /// when 'b0' is encountered, invoke the parse method for the type
+  ///   of &Clause.Register (Register *) and update the parameter
+  /// when 'space' is encountered, invoke a parse method for the type
+  ///   of &Clause.Space (uint32_t *) and update the parameter
+  ///
+  /// and 'bReg' must be specified
+  bool parseParams(
+  llvm::SmallDenseMap &Params,
+  llvm::SmallDenseSet &Mandatory);
+
   /// Invoke the Lexer to consume a token and update CurToken with the result
   void consumeNextToken() { CurToken = Lexer.ConsumeToken(); }
 
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp 
b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index 33caca5fa1c82..8bb78def243fe 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -118,6 +118,57 @@ bool RootSignatureParser::parseDescriptorTableClause() {
   return false;
 }
 
+// Helper struct so that we can use the overloaded notation of std::visit
+template  struct ParseMethods : Ts... { using Ts::operator()...; 
};
+template  ParseMethods(Ts...) -> ParseMethods;
+
+bool RootSignatureParser::parseParam(ParamType Ref) {
+  bool Error = true;
+  std::visit(ParseMethods{}, Ref);
+
+  return Error;
+}
+
+bool RootSignatureParser::parseParams(
+llvm::SmallDenseMap &Params,
+llvm::SmallDenseSet &Mandatory) {
+
+  // Initialize a vector of possible keywords
+  SmallVector Keywords;
+  for (auto Pair : Params)
+Keywords.push_back(Pair.first);
+
+  // Keep track of which keywords have been seen to report duplicates
+  llvm::SmallDenseSet Seen;
+
+  while (tryConsumeExpectedToken(Keyw

[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-03-31 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic closed 
https://github.com/llvm/llvm-project/pull/123985
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [HLSL] Adding support for Root Constants in LLVM Metadata (PR #135085)

2025-04-16 Thread Finn Plummer via llvm-branch-commits


@@ -0,0 +1,18 @@
+; RUN: not opt -passes='print' %s -S -o - 2>&1 | 
FileCheck %s
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for Num32BitValues
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+  ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }

inbelic wrote:

nit: are these attributes needed?

https://github.com/llvm/llvm-project/pull/135085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [NFC][RootSignatures] Conform to new std::optional calling conventions (PR #136747)

2025-04-22 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/136747

- It was determined to define the parsing methods much more inline with a 
recursive descent parser to follow the EBNF notation better
- As part of this change, we decided to go with a calling convention to the 
parse.* methods of returning an optional rather than a bool and a reference to 
the parsed struct

This is a clean-up task from https://github.com/llvm/llvm-project/pull/133800

>From cb85ab7411d726de31553c1e26c49be49f6f64e7 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Thu, 17 Apr 2025 19:27:02 +
Subject: [PATCH] [NFC][RootSignatures] Conform to new std::optional calling
 conventions

- It was determined to define the parsing methods much more inline with
a recursive descent parser to follow the EBNF notation better
- As part of this change, we decided to go with a calling convention to
the parse.* methods of returning an optional rather than a bool and a
reference to the parsed struct
---
 .../clang/Parse/ParseHLSLRootSignature.h  |  5 +-
 clang/lib/Parse/ParseHLSLRootSignature.cpp| 67 ---
 2 files changed, 32 insertions(+), 40 deletions(-)

diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index 3eb3f8ea8422d..d9f121030c1fc 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -71,8 +71,9 @@ class RootSignatureParser {
   // expected, or, there is a lexing error
 
   /// Root Element parse methods:
-  bool parseDescriptorTable();
-  bool parseDescriptorTableClause();
+  std::optional parseDescriptorTable();
+  std::optional
+  parseDescriptorTableClause();
 
   /// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
   /// order and only exactly once. `ParsedClauseParams` denotes the current
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp 
b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index 4f8bfccfa2243..1bf33b8e8329c 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -26,22 +26,14 @@ 
RootSignatureParser::RootSignatureParser(SmallVector &Elements,
 
 bool RootSignatureParser::parse() {
   // Iterate as many RootElements as possible
-  while (tryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) {
-// Dispatch onto parser method.
-// We guard against the unreachable here as we just ensured that CurToken
-// will be one of the kinds in the while condition
-switch (CurToken.TokKind) {
-case TokenKind::kw_DescriptorTable:
-  if (parseDescriptorTable())
+  do {
+if (tryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) {
+  auto Table = parseDescriptorTable();
+  if (!Table.has_value())
 return true;
-  break;
-default:
-  llvm_unreachable("Switch for consumed token was not provided");
+  Elements.push_back(*Table);
 }
-
-if (!tryConsumeExpectedToken(TokenKind::pu_comma))
-  break;
-  }
+  } while (tryConsumeExpectedToken(TokenKind::pu_comma));
 
   if (consumeExpectedToken(TokenKind::end_of_stream,
diag::err_hlsl_unexpected_end_of_params,
@@ -51,38 +43,38 @@ bool RootSignatureParser::parse() {
   return false;
 }
 
-bool RootSignatureParser::parseDescriptorTable() {
+std::optional RootSignatureParser::parseDescriptorTable() {
   assert(CurToken.TokKind == TokenKind::kw_DescriptorTable &&
  "Expects to only be invoked starting at given keyword");
 
-  DescriptorTable Table;
-
   if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after,
CurToken.TokKind))
-return true;
-
-  // Iterate as many Clauses as possible
-  while (tryConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV,
-  TokenKind::kw_UAV, TokenKind::kw_Sampler})) {
-if (parseDescriptorTableClause())
-  return true;
+return std::nullopt;
 
-Table.NumClauses++;
+  DescriptorTable Table;
 
-if (!tryConsumeExpectedToken(TokenKind::pu_comma))
-  break;
-  }
+  // Iterate as many Clauses as possible
+  do {
+if (tryConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV,
+ TokenKind::kw_UAV, TokenKind::kw_Sampler})) {
+  auto Clause = parseDescriptorTableClause();
+  if (!Clause.has_value())
+return std::nullopt;
+  Elements.push_back(*Clause);
+  Table.NumClauses++;
+}
+  } while (tryConsumeExpectedToken(TokenKind::pu_comma));
 
   if (consumeExpectedToken(TokenKind::pu_r_paren,
diag::err_hlsl_unexpected_end_of_params,
/*param of=*/TokenKind::kw_DescriptorTable))
-return true;
+return std::nullopt;
 
-  Elements.push_back(Table);
-  return false;
+  return Table;
 }
 
-bool RootSignatureParser::parseDescriptorTableClause() {
+std::optional
+RootSignatureParser::p

[llvm-branch-commits] [llvm] [DirectX] Adding support for Root Descriptor in Obj2yaml/Yaml2Obj (PR #136732)

2025-04-23 Thread Finn Plummer via llvm-branch-commits


@@ -594,6 +599,25 @@ struct RootConstants {
 sys::swapByteOrder(Num32BitValues);
   }
 };
+struct RootDescriptor_V1_0 {

inbelic wrote:

Having poked a bit more in `DXContainer.h`, maybe it would be best to follow 
how it is done for `RuntimeInfo`? Defining a new namespace for each version and 
then having all later version inheret from the previous version. So something 
like:
```
namespace v0 {
struct RootDescriptor {
  uint32_t ShaderRegister;
  uint32_t RegisterSpace;
  
  void swapbytes() {...}
};
}

namespace v1 {
struct RootDescriptor : public v0::RootDescriptor {
  uint32_t Flags;
  void swapbytes() {...}
};
}
```

https://github.com/llvm/llvm-project/pull/136732
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Adding support for Root Descriptor in Obj2yaml/Yaml2Obj (PR #136732)

2025-04-23 Thread Finn Plummer via llvm-branch-commits


@@ -73,24 +75,50 @@ struct ShaderHash {
   std::vector Digest;
 };
 
-#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false;
-
 struct RootConstantsYaml {
   uint32_t ShaderRegister;
   uint32_t RegisterSpace;
   uint32_t Num32BitValues;
 };
 
+#define ROOT_DESCRIPTOR_FLAG(Num, Val) bool Val = false;
+struct RootDescriptorYaml {
+  RootDescriptorYaml() = default;
+
+  uint32_t ShaderRegister;
+  uint32_t RegisterSpace;
+
+  uint32_t getEncodedFlags();
+
+#include "llvm/BinaryFormat/DXContainerConstants.def"
+};
+
 struct RootParameterYamlDesc {
   uint32_t Type;
   uint32_t Visibility;
   uint32_t Offset;
+  RootParameterYamlDesc(){};
+  RootParameterYamlDesc(uint32_t T) : Type(T) {

inbelic wrote:

Is the old constructor still used? If so, when would we use that instead of 
this one?

https://github.com/llvm/llvm-project/pull/136732
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Adding support for Root Descriptor in Obj2yaml/Yaml2Obj (PR #136732)

2025-04-23 Thread Finn Plummer via llvm-branch-commits


@@ -89,6 +111,15 @@ DXContainerYAML::RootSignatureYamlDesc::create(
   return RootSigDesc;
 }
 
+uint32_t DXContainerYAML::RootDescriptorYaml::getEncodedFlags() const {
+  uint64_t Flag = 0;
+#define ROOT_DESCRIPTOR_FLAG(Num, Val) 
\
+  if (Val) 
\

inbelic wrote:

Note: `Val` is a member of the struct which is why this works

https://github.com/llvm/llvm-project/pull/136732
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Adding support for Root Descriptor in Obj2yaml/Yaml2Obj (PR #136732)

2025-04-23 Thread Finn Plummer via llvm-branch-commits


@@ -594,6 +599,25 @@ struct RootConstants {
 sys::swapByteOrder(Num32BitValues);
   }
 };
+struct RootDescriptor_V1_0 {

inbelic wrote:

IIUC, this is how the structs were defined and planned to be extended in DXC. 
And I believe it was also documented there that each new version of a must 
guarantee it will only append data members.

What were the reasons for keeping separate structures?

>From glancing, it seems like we would just need to update the `readParameter` 
>function to determine the size of the struct based on the version. Maybe that 
>is more extensible? It seems like the logic elsewhere would be nicer:

Currently it is like:
```
  if (Version == 1) {
Param1 = Param1;
Param2 = Param2;
  }
  if (Version == 2) {
Param1 = Param1;
Param2 = Param2;
ExtraParam1 = ExtraParam1;
  }
  if (Version == 3) {
...
  }
```
And it could be like
```
Param1 = Param1;
Param2 = Param2;
if (Version >= 2) {
  ExtraParam1 = ExtraParam2;
}
if (Version >= 3) {
  ExtraParam2 = ExtraParam2;
}
```
And similar for the `sys::write` functionality, etc.

Happy to just be told no, but wanted to make sure we haved reconsidered the 
format.

https://github.com/llvm/llvm-project/pull/136732
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Adding support for Root Descriptor in Obj2yaml/Yaml2Obj (PR #136732)

2025-04-23 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/136732
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add mandatory parameters for RootConstants (PR #138002)

2025-04-30 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/138002

- defines the `parseRootConstantParams` function and adds handling for the 
mandatory arguments of `num32BitConstants` and `bReg`

- adds corresponding unit tests

Part two of implementing #126576 

>From 15857bf8e1303e2325b48e417e7abd26aa77910e Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 30 Apr 2025 17:53:11 +
Subject: [PATCH] [HLSL][RootSignature] Add mandatory parameters for
 RootConstants

- defines the `parseRootConstantParams` function and adds handling for
the mandatory arguments of `num32BitConstants` and `bReg`

- adds corresponding unit tests

Part two of implementing
---
 .../clang/Parse/ParseHLSLRootSignature.h  | 10 ++-
 clang/lib/Parse/ParseHLSLRootSignature.cpp| 68 ++-
 .../Parse/ParseHLSLRootSignatureTest.cpp  | 14 +++-
 .../llvm/Frontend/HLSL/HLSLRootSignature.h|  5 +-
 4 files changed, 89 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index efa735ea03d94..0f05b05ed4df6 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -77,8 +77,14 @@ class RootSignatureParser {
   parseDescriptorTableClause();
 
   /// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
-  /// order and only exactly once. `ParsedClauseParams` denotes the current
-  /// state of parsed params
+  /// order and only exactly once. The following methods define a
+  /// `Parsed.*Params` struct to denote the current state of parsed params
+  struct ParsedConstantParams {
+std::optional Reg;
+std::optional Num32BitConstants;
+  };
+  std::optional parseRootConstantParams();
+
   struct ParsedClauseParams {
 std::optional Reg;
 std::optional NumDescriptors;
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp 
b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index 48d3e38b0519d..2ce8e6e5cca98 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -57,6 +57,27 @@ std::optional 
RootSignatureParser::parseRootConstants() {
 
   RootConstants Constants;
 
+  auto Params = parseRootConstantParams();
+  if (!Params.has_value())
+return std::nullopt;
+
+  // Check mandatory parameters were provided
+  if (!Params->Num32BitConstants.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param)
+<< TokenKind::kw_num32BitConstants;
+return std::nullopt;
+  }
+
+  Constants.Num32BitConstants = Params->Num32BitConstants.value();
+
+  if (!Params->Reg.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param)
+<< TokenKind::bReg;
+return std::nullopt;
+  }
+
+  Constants.Reg = Params->Reg.value();
+
   if (consumeExpectedToken(TokenKind::pu_r_paren,
diag::err_hlsl_unexpected_end_of_params,
/*param of=*/TokenKind::kw_RootConstants))
@@ -187,14 +208,55 @@ RootSignatureParser::parseDescriptorTableClause() {
   return Clause;
 }
 
+// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
+// order and only exactly once. The following methods will parse through as
+// many arguments as possible reporting an error if a duplicate is seen.
+std::optional
+RootSignatureParser::parseRootConstantParams() {
+  assert(CurToken.TokKind == TokenKind::pu_l_paren &&
+ "Expects to only be invoked starting at given token");
+
+  ParsedConstantParams Params;
+  do {
+// `num32BitConstants` `=` POS_INT
+if (tryConsumeExpectedToken(TokenKind::kw_num32BitConstants)) {
+  if (Params.Num32BitConstants.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
+<< CurToken.TokKind;
+return std::nullopt;
+  }
+
+  if (consumeExpectedToken(TokenKind::pu_equal))
+return std::nullopt;
+
+  auto Num32BitConstants = parseUIntParam();
+  if (!Num32BitConstants.has_value())
+return std::nullopt;
+  Params.Num32BitConstants = Num32BitConstants;
+}
+
+// `b` POS_INT
+if (tryConsumeExpectedToken(TokenKind::bReg)) {
+  if (Params.Reg.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
+<< CurToken.TokKind;
+return std::nullopt;
+  }
+  auto Reg = parseRegister();
+  if (!Reg.has_value())
+return std::nullopt;
+  Params.Reg = Reg;
+}
+  } while (tryConsumeExpectedToken(TokenKind::pu_comma));
+
+  return Params;
+}
+
 std::optional
 RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
   assert(CurToken.TokKind == TokenKind::pu_l_paren &&
  "Expects to only be invoked starting at given token");
 
-  // Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
-  // order

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add mandatory parameters for RootConstants (PR #138002)

2025-04-30 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/138002

>From 15857bf8e1303e2325b48e417e7abd26aa77910e Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 30 Apr 2025 17:53:11 +
Subject: [PATCH] [HLSL][RootSignature] Add mandatory parameters for
 RootConstants

- defines the `parseRootConstantParams` function and adds handling for
the mandatory arguments of `num32BitConstants` and `bReg`

- adds corresponding unit tests

Part two of implementing
---
 .../clang/Parse/ParseHLSLRootSignature.h  | 10 ++-
 clang/lib/Parse/ParseHLSLRootSignature.cpp| 68 ++-
 .../Parse/ParseHLSLRootSignatureTest.cpp  | 14 +++-
 .../llvm/Frontend/HLSL/HLSLRootSignature.h|  5 +-
 4 files changed, 89 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index efa735ea03d94..0f05b05ed4df6 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -77,8 +77,14 @@ class RootSignatureParser {
   parseDescriptorTableClause();
 
   /// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
-  /// order and only exactly once. `ParsedClauseParams` denotes the current
-  /// state of parsed params
+  /// order and only exactly once. The following methods define a
+  /// `Parsed.*Params` struct to denote the current state of parsed params
+  struct ParsedConstantParams {
+std::optional Reg;
+std::optional Num32BitConstants;
+  };
+  std::optional parseRootConstantParams();
+
   struct ParsedClauseParams {
 std::optional Reg;
 std::optional NumDescriptors;
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp 
b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index 48d3e38b0519d..2ce8e6e5cca98 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -57,6 +57,27 @@ std::optional 
RootSignatureParser::parseRootConstants() {
 
   RootConstants Constants;
 
+  auto Params = parseRootConstantParams();
+  if (!Params.has_value())
+return std::nullopt;
+
+  // Check mandatory parameters were provided
+  if (!Params->Num32BitConstants.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param)
+<< TokenKind::kw_num32BitConstants;
+return std::nullopt;
+  }
+
+  Constants.Num32BitConstants = Params->Num32BitConstants.value();
+
+  if (!Params->Reg.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param)
+<< TokenKind::bReg;
+return std::nullopt;
+  }
+
+  Constants.Reg = Params->Reg.value();
+
   if (consumeExpectedToken(TokenKind::pu_r_paren,
diag::err_hlsl_unexpected_end_of_params,
/*param of=*/TokenKind::kw_RootConstants))
@@ -187,14 +208,55 @@ RootSignatureParser::parseDescriptorTableClause() {
   return Clause;
 }
 
+// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
+// order and only exactly once. The following methods will parse through as
+// many arguments as possible reporting an error if a duplicate is seen.
+std::optional
+RootSignatureParser::parseRootConstantParams() {
+  assert(CurToken.TokKind == TokenKind::pu_l_paren &&
+ "Expects to only be invoked starting at given token");
+
+  ParsedConstantParams Params;
+  do {
+// `num32BitConstants` `=` POS_INT
+if (tryConsumeExpectedToken(TokenKind::kw_num32BitConstants)) {
+  if (Params.Num32BitConstants.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
+<< CurToken.TokKind;
+return std::nullopt;
+  }
+
+  if (consumeExpectedToken(TokenKind::pu_equal))
+return std::nullopt;
+
+  auto Num32BitConstants = parseUIntParam();
+  if (!Num32BitConstants.has_value())
+return std::nullopt;
+  Params.Num32BitConstants = Num32BitConstants;
+}
+
+// `b` POS_INT
+if (tryConsumeExpectedToken(TokenKind::bReg)) {
+  if (Params.Reg.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
+<< CurToken.TokKind;
+return std::nullopt;
+  }
+  auto Reg = parseRegister();
+  if (!Reg.has_value())
+return std::nullopt;
+  Params.Reg = Reg;
+}
+  } while (tryConsumeExpectedToken(TokenKind::pu_comma));
+
+  return Params;
+}
+
 std::optional
 RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
   assert(CurToken.TokKind == TokenKind::pu_l_paren &&
  "Expects to only be invoked starting at given token");
 
-  // Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
-  // order and only exactly once. Parse through as many arguments as possible
-  // reporting an error if a duplicate is seen.
   ParsedClauseParams Params;
   do {
 // ( `b` | `t` | `u` | `s`) POS_INT
dif

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add optional parameter for RootConstants (PR #138007)

2025-04-30 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/138007

- extends `parseRootConstantParams` and the struct to include the optional 
parameters of a RootConstant

- adds corresponding unit tests

Part three of and resolves https://github.com/llvm/llvm-project/issues/126576

>From f8011807d233d1d0d1f9d4ce08bad0c559cde74a Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 30 Apr 2025 18:08:31 +
Subject: [PATCH] [HLSL][RootSignature] Add optional parameter for
 RootConstants

- extends `parseRootConstantParams` and the struct to include the
optional parameters of a RootConstant

- adds corresponding unit tests
---
 .../clang/Parse/ParseHLSLRootSignature.h  |  2 +
 clang/lib/Parse/ParseHLSLRootSignature.cpp| 41 +++
 .../Parse/ParseHLSLRootSignatureTest.cpp  |  8 +++-
 .../llvm/Frontend/HLSL/HLSLRootSignature.h|  2 +
 4 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index 0f05b05ed4df6..2ac2083983741 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -82,6 +82,8 @@ class RootSignatureParser {
   struct ParsedConstantParams {
 std::optional Reg;
 std::optional Num32BitConstants;
+std::optional Space;
+std::optional Visibility;
   };
   std::optional parseRootConstantParams();
 
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp 
b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index 2ce8e6e5cca98..a5006b77a6e44 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -78,6 +78,13 @@ std::optional 
RootSignatureParser::parseRootConstants() {
 
   Constants.Reg = Params->Reg.value();
 
+  // Fill in optional parameters
+  if (Params->Visibility.has_value())
+Constants.Visibility = Params->Visibility.value();
+
+  if (Params->Space.has_value())
+Constants.Space = Params->Space.value();
+
   if (consumeExpectedToken(TokenKind::pu_r_paren,
diag::err_hlsl_unexpected_end_of_params,
/*param of=*/TokenKind::kw_RootConstants))
@@ -247,6 +254,40 @@ RootSignatureParser::parseRootConstantParams() {
 return std::nullopt;
   Params.Reg = Reg;
 }
+
+// `space` `=` POS_INT
+if (tryConsumeExpectedToken(TokenKind::kw_space)) {
+  if (Params.Space.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
+<< CurToken.TokKind;
+return std::nullopt;
+  }
+
+  if (consumeExpectedToken(TokenKind::pu_equal))
+return std::nullopt;
+
+  auto Space = parseUIntParam();
+  if (!Space.has_value())
+return std::nullopt;
+  Params.Space = Space;
+}
+
+// `visibility` `=` SHADER_VISIBILITY
+if (tryConsumeExpectedToken(TokenKind::kw_visibility)) {
+  if (Params.Visibility.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
+<< CurToken.TokKind;
+return std::nullopt;
+  }
+
+  if (consumeExpectedToken(TokenKind::pu_equal))
+return std::nullopt;
+
+  auto Visibility = parseShaderVisibility();
+  if (!Visibility.has_value())
+return std::nullopt;
+  Params.Visibility = Visibility;
+}
   } while (tryConsumeExpectedToken(TokenKind::pu_comma));
 
   return Params;
diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp 
b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
index 336868b579866..150eb3e6e54ef 100644
--- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
+++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
@@ -255,7 +255,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) {
 TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) {
   const llvm::StringLiteral Source = R"cc(
 RootConstants(num32BitConstants = 1, b0),
-RootConstants(b42, num32BitConstants = 4294967295)
+RootConstants(b42, space = 3, num32BitConstants = 4294967295,
+  visibility = SHADER_VISIBILITY_HULL
+)
   )cc";
 
   TrivialModuleLoader ModLoader;
@@ -278,12 +280,16 @@ TEST_F(ParseHLSLRootSignatureTest, 
ValidParseRootConsantsTest) {
   ASSERT_EQ(std::get(Elem).Num32BitConstants, 1u);
   ASSERT_EQ(std::get(Elem).Reg.ViewType, RegisterType::BReg);
   ASSERT_EQ(std::get(Elem).Reg.Number, 0u);
+  ASSERT_EQ(std::get(Elem).Space, 0u);
+  ASSERT_EQ(std::get(Elem).Visibility, ShaderVisibility::All);
 
   Elem = Elements[1];
   ASSERT_TRUE(std::holds_alternative(Elem));
   ASSERT_EQ(std::get(Elem).Num32BitConstants, 4294967295u);
   ASSERT_EQ(std::get(Elem).Reg.ViewType, RegisterType::BReg);
   ASSERT_EQ(std::get(Elem).Reg.Number, 42u);
+  ASSERT_EQ(std::get(Elem).Space, 3u);
+  ASSERT_EQ(std::get(Elem).Visibility, ShaderVisibility::Hull);
 
   ASSERT_TRUE(Consumer->isSatisfied());
 }
diff --git 

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add optional parameters for RootConstants (PR #138007)

2025-04-30 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/138007
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add mandatory parameters for RootConstants (PR #138002)

2025-04-30 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/138002

>From 15857bf8e1303e2325b48e417e7abd26aa77910e Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 30 Apr 2025 17:53:11 +
Subject: [PATCH 1/2] [HLSL][RootSignature] Add mandatory parameters for
 RootConstants

- defines the `parseRootConstantParams` function and adds handling for
the mandatory arguments of `num32BitConstants` and `bReg`

- adds corresponding unit tests

Part two of implementing
---
 .../clang/Parse/ParseHLSLRootSignature.h  | 10 ++-
 clang/lib/Parse/ParseHLSLRootSignature.cpp| 68 ++-
 .../Parse/ParseHLSLRootSignatureTest.cpp  | 14 +++-
 .../llvm/Frontend/HLSL/HLSLRootSignature.h|  5 +-
 4 files changed, 89 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index efa735ea03d94..0f05b05ed4df6 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -77,8 +77,14 @@ class RootSignatureParser {
   parseDescriptorTableClause();
 
   /// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
-  /// order and only exactly once. `ParsedClauseParams` denotes the current
-  /// state of parsed params
+  /// order and only exactly once. The following methods define a
+  /// `Parsed.*Params` struct to denote the current state of parsed params
+  struct ParsedConstantParams {
+std::optional Reg;
+std::optional Num32BitConstants;
+  };
+  std::optional parseRootConstantParams();
+
   struct ParsedClauseParams {
 std::optional Reg;
 std::optional NumDescriptors;
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp 
b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index 48d3e38b0519d..2ce8e6e5cca98 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -57,6 +57,27 @@ std::optional 
RootSignatureParser::parseRootConstants() {
 
   RootConstants Constants;
 
+  auto Params = parseRootConstantParams();
+  if (!Params.has_value())
+return std::nullopt;
+
+  // Check mandatory parameters were provided
+  if (!Params->Num32BitConstants.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param)
+<< TokenKind::kw_num32BitConstants;
+return std::nullopt;
+  }
+
+  Constants.Num32BitConstants = Params->Num32BitConstants.value();
+
+  if (!Params->Reg.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param)
+<< TokenKind::bReg;
+return std::nullopt;
+  }
+
+  Constants.Reg = Params->Reg.value();
+
   if (consumeExpectedToken(TokenKind::pu_r_paren,
diag::err_hlsl_unexpected_end_of_params,
/*param of=*/TokenKind::kw_RootConstants))
@@ -187,14 +208,55 @@ RootSignatureParser::parseDescriptorTableClause() {
   return Clause;
 }
 
+// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
+// order and only exactly once. The following methods will parse through as
+// many arguments as possible reporting an error if a duplicate is seen.
+std::optional
+RootSignatureParser::parseRootConstantParams() {
+  assert(CurToken.TokKind == TokenKind::pu_l_paren &&
+ "Expects to only be invoked starting at given token");
+
+  ParsedConstantParams Params;
+  do {
+// `num32BitConstants` `=` POS_INT
+if (tryConsumeExpectedToken(TokenKind::kw_num32BitConstants)) {
+  if (Params.Num32BitConstants.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
+<< CurToken.TokKind;
+return std::nullopt;
+  }
+
+  if (consumeExpectedToken(TokenKind::pu_equal))
+return std::nullopt;
+
+  auto Num32BitConstants = parseUIntParam();
+  if (!Num32BitConstants.has_value())
+return std::nullopt;
+  Params.Num32BitConstants = Num32BitConstants;
+}
+
+// `b` POS_INT
+if (tryConsumeExpectedToken(TokenKind::bReg)) {
+  if (Params.Reg.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
+<< CurToken.TokKind;
+return std::nullopt;
+  }
+  auto Reg = parseRegister();
+  if (!Reg.has_value())
+return std::nullopt;
+  Params.Reg = Reg;
+}
+  } while (tryConsumeExpectedToken(TokenKind::pu_comma));
+
+  return Params;
+}
+
 std::optional
 RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
   assert(CurToken.TokKind == TokenKind::pu_l_paren &&
  "Expects to only be invoked starting at given token");
 
-  // Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
-  // order and only exactly once. Parse through as many arguments as possible
-  // reporting an error if a duplicate is seen.
   ParsedClauseParams Params;
   do {
 // ( `b` | `t` | `u` | `s`) POS_INT

[llvm-branch-commits] [llvm] [HLSL] Adding support for Root Constants in LLVM Metadata (PR #135085)

2025-04-14 Thread Finn Plummer via llvm-branch-commits


@@ -94,10 +144,56 @@ static bool parse(LLVMContext *Ctx, 
mcdxbc::RootSignatureDesc &RSD,
 
 static bool verifyRootFlag(uint32_t Flags) { return (Flags & ~0xfff) == 0; }
 
+static bool verifyShaderVisibility(dxbc::ShaderVisibility Flags) {
+  switch (Flags) {
+
+  case dxbc::ShaderVisibility::All:
+  case dxbc::ShaderVisibility::Vertex:
+  case dxbc::ShaderVisibility::Hull:
+  case dxbc::ShaderVisibility::Domain:
+  case dxbc::ShaderVisibility::Geometry:
+  case dxbc::ShaderVisibility::Pixel:
+  case dxbc::ShaderVisibility::Amplification:
+  case dxbc::ShaderVisibility::Mesh:
+return true;
+  }
+
+  return false;
+}
+
+static bool verifyParameterType(dxbc::RootParameterType Flags) {
+  switch (Flags) {
+  case dxbc::RootParameterType::Constants32Bit:
+return true;
+  }
+
+  return false;
+}
+
+static bool verifyVersion(uint32_t Version) {
+  return (Version == 1 || Version == 2);
+}
+
 static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
+
+  if (!verifyVersion(RSD.Header.Version)) {
+return reportValueError(Ctx, "Version", RSD.Header.Version);
+  }
+
   if (!verifyRootFlag(RSD.Header.Flags)) {
-return reportError(Ctx, "Invalid Root Signature flag value");
+return reportValueError(Ctx, "RootFlags", RSD.Header.Flags);
+  }
+
+  for (const auto &P : RSD.Parameters) {
+if (!verifyShaderVisibility(P.Header.ShaderVisibility))
+  return reportValueError(Ctx, "ShaderVisibility",
+  (uint32_t)P.Header.ShaderVisibility);
+
+if (!verifyParameterType(P.Header.ParameterType))
+  return reportValueError(Ctx, "ParameterType",

inbelic wrote:

There isn't a test case demonstrating this

https://github.com/llvm/llvm-project/pull/135085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [HLSL] Adding support for Root Constants in LLVM Metadata (PR #135085)

2025-04-14 Thread Finn Plummer via llvm-branch-commits




inbelic wrote:

I think we should change the name of the file to be more descriptive

https://github.com/llvm/llvm-project/pull/135085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [HLSL] Adding support for Root Constants in LLVM Metadata (PR #135085)

2025-04-14 Thread Finn Plummer via llvm-branch-commits




inbelic wrote:

The test name implies that we are only testing root constants. Can we either 
change the name or remove root flags

https://github.com/llvm/llvm-project/pull/135085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [HLSL] Adding support for Root Constants in LLVM Metadata (PR #135085)

2025-04-14 Thread Finn Plummer via llvm-branch-commits


@@ -52,6 +59,45 @@ static bool parseRootFlags(LLVMContext *Ctx, 
mcdxbc::RootSignatureDesc &RSD,
   return false;
 }
 
+static bool extractMdValue(uint32_t &Value, MDNode *Node, unsigned int OpId) {

inbelic wrote:

We could use this for `parseRootFlags` as well to make it consistent.

https://github.com/llvm/llvm-project/pull/135085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [HLSL] Adding support for Root Constants in LLVM Metadata (PR #135085)

2025-04-14 Thread Finn Plummer via llvm-branch-commits


@@ -0,0 +1,34 @@
+; RUN: opt %s -dxil-embed -dxil-globals -S -o - | FileCheck %s
+; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: @dx.rts0 = private constant [48 x i8]  c"{{.*}}", section "RTS0", 
align 4
+
+define void @main() #0 {
+entry:
+  ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !4, !5 } ; list of root signature elements
+!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
+!5 = !{ !"RootConstants", i32 0, i32 1, i32 2, i32 3 }
+
+; DXC:  - Name:RTS0
+; DXC-NEXT:Size:48
+; DXC-NEXT:RootSignature:
+; DXC-NEXT:  Version: 2
+; DXC-NEXT:  NumStaticSamplers: 0
+; DXC-NEXT:  StaticSamplersOffset: 0

inbelic wrote:

This has a different value from the test above (0 vs 48). Presumably they 
should be the same?

https://github.com/llvm/llvm-project/pull/135085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [HLSL] Adding support for Root Constants in LLVM Metadata (PR #135085)

2025-04-14 Thread Finn Plummer via llvm-branch-commits


@@ -94,10 +144,56 @@ static bool parse(LLVMContext *Ctx, 
mcdxbc::RootSignatureDesc &RSD,
 
 static bool verifyRootFlag(uint32_t Flags) { return (Flags & ~0xfff) == 0; }
 
+static bool verifyShaderVisibility(dxbc::ShaderVisibility Flags) {
+  switch (Flags) {
+
+  case dxbc::ShaderVisibility::All:
+  case dxbc::ShaderVisibility::Vertex:
+  case dxbc::ShaderVisibility::Hull:
+  case dxbc::ShaderVisibility::Domain:
+  case dxbc::ShaderVisibility::Geometry:
+  case dxbc::ShaderVisibility::Pixel:
+  case dxbc::ShaderVisibility::Amplification:
+  case dxbc::ShaderVisibility::Mesh:
+return true;
+  }
+
+  return false;
+}
+
+static bool verifyParameterType(dxbc::RootParameterType Flags) {
+  switch (Flags) {
+  case dxbc::RootParameterType::Constants32Bit:

inbelic wrote:

Shouldn't root flags also be here?

https://github.com/llvm/llvm-project/pull/135085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [HLSL] Adding support for Root Constants in LLVM Metadata (PR #135085)

2025-04-14 Thread Finn Plummer via llvm-branch-commits




inbelic wrote:

I think you meant this to be a new test file and not to edit the root flags 
validation.

Can we also remove the "RootFlags" member to reduce noise.

https://github.com/llvm/llvm-project/pull/135085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [HLSL] Adding support for Root Constants in LLVM Metadata (PR #135085)

2025-04-14 Thread Finn Plummer via llvm-branch-commits


@@ -52,6 +59,45 @@ static bool parseRootFlags(LLVMContext *Ctx, 
mcdxbc::RootSignatureDesc &RSD,
   return false;
 }
 
+static bool extractMdValue(uint32_t &Value, MDNode *Node, unsigned int OpId) {

inbelic wrote:

Maybe we could rename this to `extractMdIntValue` or the like? We will 
eventually have `float` args

https://github.com/llvm/llvm-project/pull/135085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [HLSL] Adding support for Root Constants in LLVM Metadata (PR #135085)

2025-04-16 Thread Finn Plummer via llvm-branch-commits


@@ -94,10 +144,56 @@ static bool parse(LLVMContext *Ctx, 
mcdxbc::RootSignatureDesc &RSD,
 
 static bool verifyRootFlag(uint32_t Flags) { return (Flags & ~0xfff) == 0; }
 
+static bool verifyShaderVisibility(dxbc::ShaderVisibility Flags) {
+  switch (Flags) {
+
+  case dxbc::ShaderVisibility::All:
+  case dxbc::ShaderVisibility::Vertex:
+  case dxbc::ShaderVisibility::Hull:
+  case dxbc::ShaderVisibility::Domain:
+  case dxbc::ShaderVisibility::Geometry:
+  case dxbc::ShaderVisibility::Pixel:
+  case dxbc::ShaderVisibility::Amplification:
+  case dxbc::ShaderVisibility::Mesh:
+return true;
+  }
+
+  return false;
+}
+
+static bool verifyParameterType(dxbc::RootParameterType Flags) {
+  switch (Flags) {
+  case dxbc::RootParameterType::Constants32Bit:

inbelic wrote:

I see. What was the reason to change the input parameter to `uint32_t`? Do we 
want the printed output to be the literal metadata values? It seemed more 
explicit with the enums

https://github.com/llvm/llvm-project/pull/135085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add parsing for RootFlags (PR #138055)

2025-04-30 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/138055

- defines the `RootFlags` in-memory enum
- defines `parseRootFlags` to parse the various flag enums into a single 
`uint32_t`
- adds corresponding unit tests

- improves the diagnostic message for when we provide a non-zero integer value 
to the flags

Resolves https://github.com/llvm/llvm-project/issues/126575



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Define and integrate rootsig clang attr and decl (PR #137690)

2025-05-02 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/137690

>From 0ccff5b9be4f876969e4db439e67edbc7af6cb29 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Mon, 28 Apr 2025 18:42:10 +
Subject: [PATCH 01/13] [HLSL][RootSignature] Define and integrate rootsig
 clang attr and decl

- Defines a new declaration node `HLSLRootSignature` in `DeclNodes.td`
that will hold a reference to an in-memory construction of the root
signature, namely an array of `hlsl::rootsig::RootElement`s

- Defines a new clang attr `RootSignature` which simply holds an
identifier to a corresponding root signature declration as above

It was previously proposed that we could have the root elements
reference be stored directly as an additional member of the attribute
and to not have a seperate root signature decl. In contrast, by defining
them seperately as this change proposes, we will allow a unique root
signature to have its own declaration in the AST tree. This allows us
to only construct a single root signature for all duplicate rootsignature
attributes. Having it located directly as a declaration might also prove
advantageous when we consider root signature libraries.
---
 clang/include/clang/AST/Decl.h| 24 +
 clang/include/clang/AST/RecursiveASTVisitor.h |  2 +
 clang/include/clang/AST/TextNodeDumper.h  |  1 +
 clang/include/clang/Basic/Attr.td | 11 +++
 clang/include/clang/Basic/AttrDocs.td | 11 +++
 clang/include/clang/Basic/DeclNodes.td|  1 +
 clang/include/clang/Parse/Parser.h|  1 +
 clang/include/clang/Sema/SemaHLSL.h   |  1 +
 clang/lib/AST/Decl.cpp| 25 ++
 clang/lib/AST/DeclBase.cpp|  1 +
 clang/lib/AST/TextNodeDumper.cpp  |  4 +
 clang/lib/CodeGen/CGDecl.cpp  |  1 +
 clang/lib/Parse/ParseDeclCXX.cpp  | 90 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  3 +
 clang/lib/Sema/SemaHLSL.cpp   | 18 
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  5 ++
 clang/lib/Serialization/ASTCommon.cpp |  1 +
 clang/test/AST/HLSL/RootSignatures-AST.hlsl   | 58 
 clang/test/SemaHLSL/RootSignature-err.hlsl| 11 +++
 clang/tools/libclang/CIndex.cpp   |  1 +
 20 files changed, 270 insertions(+)
 create mode 100644 clang/test/AST/HLSL/RootSignatures-AST.hlsl
 create mode 100644 clang/test/SemaHLSL/RootSignature-err.hlsl

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 3faf63e395a08..8e45c19061b1d 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -41,6 +41,7 @@
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator_range.h"
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/TrailingObjects.h"
@@ -5178,6 +5179,29 @@ class HLSLBufferDecl final : public NamedDecl, public 
DeclContext {
   friend class ASTDeclWriter;
 };
 
+class HLSLRootSignatureDecl final : public NamedDecl {
+  ArrayRef RootElements;
+
+  HLSLRootSignatureDecl(
+  DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
+  ArrayRef RootElements);
+
+public:
+  static HLSLRootSignatureDecl *
+  Create(ASTContext &C, DeclContext *DC, SourceLocation Loc, IdentifierInfo 
*ID,
+ ArrayRef RootElements);
+  static HLSLRootSignatureDecl *CreateDeserialized(ASTContext &C,
+   GlobalDeclID ID);
+
+  ArrayRef &getRootElements() {
+return RootElements;
+  }
+
+  // Implement isa/cast/dyncast/etc.
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+  static bool classofKind(Kind K) { return K == HLSLRootSignature; }
+};
+
 /// Insertion operator for diagnostics.  This allows sending NamedDecl's
 /// into a diagnostic with <<.
 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 3edc8684d0a19..23a8c4f1f7380 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -1599,6 +1599,8 @@ DEF_TRAVERSE_DECL(EmptyDecl, {})
 
 DEF_TRAVERSE_DECL(HLSLBufferDecl, {})
 
+DEF_TRAVERSE_DECL(HLSLRootSignatureDecl, {})
+
 DEF_TRAVERSE_DECL(LifetimeExtendedTemporaryDecl, {
   TRY_TO(TraverseStmt(D->getTemporaryExpr()));
 })
diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index ea3a0f058a8ed..1917a8ac29f05 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -408,6 +408,7 @@ class TextNodeDumper
   void
   VisitLifetimeExtendedTemporaryDecl(const LifetimeExtendedTemporaryDecl *D);
   void VisitHLSLBufferDecl(const HLSLBufferDecl *D);
+  void VisitHLSLRootSignatureDe

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Define and integrate rootsig clang attr and decl (PR #137690)

2025-05-02 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/137690

>From 0ccff5b9be4f876969e4db439e67edbc7af6cb29 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Mon, 28 Apr 2025 18:42:10 +
Subject: [PATCH 01/14] [HLSL][RootSignature] Define and integrate rootsig
 clang attr and decl

- Defines a new declaration node `HLSLRootSignature` in `DeclNodes.td`
that will hold a reference to an in-memory construction of the root
signature, namely an array of `hlsl::rootsig::RootElement`s

- Defines a new clang attr `RootSignature` which simply holds an
identifier to a corresponding root signature declration as above

It was previously proposed that we could have the root elements
reference be stored directly as an additional member of the attribute
and to not have a seperate root signature decl. In contrast, by defining
them seperately as this change proposes, we will allow a unique root
signature to have its own declaration in the AST tree. This allows us
to only construct a single root signature for all duplicate rootsignature
attributes. Having it located directly as a declaration might also prove
advantageous when we consider root signature libraries.
---
 clang/include/clang/AST/Decl.h| 24 +
 clang/include/clang/AST/RecursiveASTVisitor.h |  2 +
 clang/include/clang/AST/TextNodeDumper.h  |  1 +
 clang/include/clang/Basic/Attr.td | 11 +++
 clang/include/clang/Basic/AttrDocs.td | 11 +++
 clang/include/clang/Basic/DeclNodes.td|  1 +
 clang/include/clang/Parse/Parser.h|  1 +
 clang/include/clang/Sema/SemaHLSL.h   |  1 +
 clang/lib/AST/Decl.cpp| 25 ++
 clang/lib/AST/DeclBase.cpp|  1 +
 clang/lib/AST/TextNodeDumper.cpp  |  4 +
 clang/lib/CodeGen/CGDecl.cpp  |  1 +
 clang/lib/Parse/ParseDeclCXX.cpp  | 90 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  3 +
 clang/lib/Sema/SemaHLSL.cpp   | 18 
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  5 ++
 clang/lib/Serialization/ASTCommon.cpp |  1 +
 clang/test/AST/HLSL/RootSignatures-AST.hlsl   | 58 
 clang/test/SemaHLSL/RootSignature-err.hlsl| 11 +++
 clang/tools/libclang/CIndex.cpp   |  1 +
 20 files changed, 270 insertions(+)
 create mode 100644 clang/test/AST/HLSL/RootSignatures-AST.hlsl
 create mode 100644 clang/test/SemaHLSL/RootSignature-err.hlsl

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 3faf63e395a08..8e45c19061b1d 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -41,6 +41,7 @@
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator_range.h"
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/TrailingObjects.h"
@@ -5178,6 +5179,29 @@ class HLSLBufferDecl final : public NamedDecl, public 
DeclContext {
   friend class ASTDeclWriter;
 };
 
+class HLSLRootSignatureDecl final : public NamedDecl {
+  ArrayRef RootElements;
+
+  HLSLRootSignatureDecl(
+  DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
+  ArrayRef RootElements);
+
+public:
+  static HLSLRootSignatureDecl *
+  Create(ASTContext &C, DeclContext *DC, SourceLocation Loc, IdentifierInfo 
*ID,
+ ArrayRef RootElements);
+  static HLSLRootSignatureDecl *CreateDeserialized(ASTContext &C,
+   GlobalDeclID ID);
+
+  ArrayRef &getRootElements() {
+return RootElements;
+  }
+
+  // Implement isa/cast/dyncast/etc.
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+  static bool classofKind(Kind K) { return K == HLSLRootSignature; }
+};
+
 /// Insertion operator for diagnostics.  This allows sending NamedDecl's
 /// into a diagnostic with <<.
 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 3edc8684d0a19..23a8c4f1f7380 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -1599,6 +1599,8 @@ DEF_TRAVERSE_DECL(EmptyDecl, {})
 
 DEF_TRAVERSE_DECL(HLSLBufferDecl, {})
 
+DEF_TRAVERSE_DECL(HLSLRootSignatureDecl, {})
+
 DEF_TRAVERSE_DECL(LifetimeExtendedTemporaryDecl, {
   TRY_TO(TraverseStmt(D->getTemporaryExpr()));
 })
diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index ea3a0f058a8ed..1917a8ac29f05 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -408,6 +408,7 @@ class TextNodeDumper
   void
   VisitLifetimeExtendedTemporaryDecl(const LifetimeExtendedTemporaryDecl *D);
   void VisitHLSLBufferDecl(const HLSLBufferDecl *D);
+  void VisitHLSLRootSignatureDe

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Define and integrate rootsig clang attr and decl (PR #137690)

2025-05-02 Thread Finn Plummer via llvm-branch-commits

inbelic wrote:

This is rebased onto: https://github.com/llvm/llvm-project/pull/138326 which 
defines a serialization of the in-memory structures.

As such, the test-case in RootSignatures-AST.hlsl is updated to show that the 
values are correctly stored in the decl node.

https://github.com/llvm/llvm-project/pull/137690
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [HLSL][RootSignature] Define and integrate rootsig clang attr and decl (PR #137690)

2025-05-02 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/137690
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Adding support for Root Descriptor in Obj2yaml/Yaml2Obj (PR #136732)

2025-04-23 Thread Finn Plummer via llvm-branch-commits




inbelic wrote:

Maybe this was covered in the first pr. But are there tests that cover both big 
and little endian?

https://github.com/llvm/llvm-project/pull/136732
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add parsing of remaining Descriptor Table params (PR #137038)

2025-04-23 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/137038

- defines the special values for `DESCRIPTOR_RANGE_OFFSET_APPEND` and
`unbounded` for the `offset` and `numDescriptors` parameters
respectively

- adds these parmaters to the `DescriptorClause` struct and the params
struct

- plugs in parsing of `numDescriptors` and `offset` into
`parseDescriptorTableClauseParams`

- adds corresponding unit tests

Part 5 of #126569 

>From 4513515dab8dca5c16ae80fd576ef12a3b51b21e Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 23 Apr 2025 18:37:55 +
Subject: [PATCH 1/2] pre-req: Add `unbounded` keyword to lexer

---
 clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def | 7 +++
 clang/unittests/Lex/LexHLSLRootSignatureTest.cpp| 1 +
 2 files changed, 8 insertions(+)

diff --git a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def 
b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
index c514d3456146a..d94be66b420c7 100644
--- a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
+++ b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
@@ -27,6 +27,9 @@
 #endif
 
 // Defines the various types of enum
+#ifndef UNBOUNDED_ENUM
+#define UNBOUNDED_ENUM(NAME, LIT) ENUM(NAME, LIT)
+#endif
 #ifndef DESCRIPTOR_RANGE_OFFSET_ENUM
 #define DESCRIPTOR_RANGE_OFFSET_ENUM(NAME, LIT) ENUM(NAME, LIT)
 #endif
@@ -87,6 +90,9 @@ KEYWORD(flags)
 KEYWORD(numDescriptors)
 KEYWORD(offset)
 
+// Unbounded Enum:
+UNBOUNDED_ENUM(unbounded, "unbounded")
+
 // Descriptor Range Offset Enum:
 DESCRIPTOR_RANGE_OFFSET_ENUM(DescriptorRangeOffsetAppend, 
"DESCRIPTOR_RANGE_OFFSET_APPEND")
 
@@ -118,6 +124,7 @@ SHADER_VISIBILITY_ENUM(Mesh, "SHADER_VISIBILITY_MESH")
 #undef DESCRIPTOR_RANGE_FLAG_ENUM_ON
 #undef ROOT_DESCRIPTOR_FLAG_ENUM
 #undef DESCRIPTOR_RANGE_OFFSET_ENUM
+#undef UNBOUNDED_ENUM
 #undef ENUM
 #undef KEYWORD
 #undef PUNCTUATOR
diff --git a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp 
b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
index 46f00450adb62..2024ff3a7dba9 100644
--- a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
+++ b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
@@ -93,6 +93,7 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) {
 space visibility flags
 numDescriptors offset
 
+unbounded
 DESCRIPTOR_RANGE_OFFSET_APPEND
 
 DATA_VOLATILE

>From 06e8bf23b389e7968931abaf4256e321d32b0493 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 23 Apr 2025 18:41:54 +
Subject: [PATCH 2/2] [HLSL][RootSignature] Add parsing of remaining Descriptor
 Table params

- defines the special values for `DESCRIPTOR_RANGE_OFFSET_APPEND` and
`unbounded` for the `offset` and `numDescriptors` parameters
respectively

- adds these parmaters to the `DescriptorClause` struct and the params
struct

- plugs in parsing of `numDescriptors` and `offset` into
`parseDescriptorTableClauseParams`

- adds corresponding unit tests
---
 .../clang/Parse/ParseHLSLRootSignature.h  |  2 +
 clang/lib/Parse/ParseHLSLRootSignature.cpp| 52 +++
 .../Parse/ParseHLSLRootSignatureTest.cpp  | 18 +--
 .../llvm/Frontend/HLSL/HLSLRootSignature.h|  4 ++
 4 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index d2e8f4dbcfc0c..91640e8bf0354 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -80,7 +80,9 @@ class RootSignatureParser {
   /// state of parsed params
   struct ParsedClauseParams {
 std::optional Reg;
+std::optional NumDescriptors;
 std::optional Space;
+std::optional Offset;
 std::optional Flags;
   };
   std::optional
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp 
b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index 3b9e96017c88d..042aedbf1af52 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -145,9 +145,15 @@ RootSignatureParser::parseDescriptorTableClause() {
   Clause.Reg = Params->Reg.value();
 
   // Fill in optional values
+  if (Params->NumDescriptors.has_value())
+Clause.NumDescriptors = Params->NumDescriptors.value();
+
   if (Params->Space.has_value())
 Clause.Space = Params->Space.value();
 
+  if (Params->Offset.has_value())
+Clause.Offset = Params->Offset.value();
+
   if (Params->Flags.has_value())
 Clause.Flags = Params->Flags.value();
 
@@ -182,6 +188,29 @@ 
RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
   Params.Reg = Reg;
 }
 
+// `numDescriptors` `=` POS_INT | unbounded
+if (tryConsumeExpectedToken(TokenKind::kw_numDescriptors)) {
+  if (Params.NumDescriptors.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
+<< CurToken.TokKind;
+return std::nullopt;
+  }
+
+  if (consumeExpectedToken(Tok

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add parsing of remaining Descriptor Table params (PR #137038)

2025-04-23 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/137038
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [NFC][HLSL][RootSignature] Move `HLSLRootSignatureParser` into clangSema (PR #137381)

2025-04-25 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/137381

Noting:
- Currently, `HLSLRootSignatureParser` is defined in `clangParse`, as it would 
naturally seem an appropriate place to place.

- Surprisingly, `clangParse` has a dependency on `clangSema`. So we can't 
introduce a dependency of `clangSema` onto `clangParse`.

- Given the users of `HLSLRootSignatureParser` will be `SemaHLSL` when parsing 
from source and `clangFrontend` when we are parsing as a command line argument.

- Therefore, we are required to move this out of `clangParse` so that 
`clangSema` can reference it.

This commit moves `HLSLRootSignatureParser` into `clangSema` so it can be 
linked to all its dependencies (`clangFrontend` already depends on `clangSema`)

>From 92d1d83b3fbb43523819b5be338922ab614d2054 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Fri, 25 Apr 2025 18:21:36 +
Subject: [PATCH] [NFC][HLSL][RootSignature] Move `HLSLRootSignatureParser`
 into clangSema

Noting:
- Currently, `HLSLRootSignatureParser` is defined in `clangParse`, as it
would naturally seem an appropriate place to place.

- Surprisingly, `clangParse` has a dependency on `clangSema`. So we can't
introduce a dependency of `clangSema` onto `clangParse`.

- Given the users of `HLSLRootSignatureParser` will be `SemaHLSL` when
parsing from source and `clangFrontend` when we are parsing as a
command line argument.

- Therefore, we are required to move this out of `clangParse` so that
`clangSema` can reference it.

This commit moves `HLSLRootSignatureParser` into `clangSema` so it can
be linked to all its dependencies (`clangFrontend` already depends on
`clangSema`)
---
 .../{Parse => Sema}/ParseHLSLRootSignature.h  |  0
 clang/lib/Parse/CMakeLists.txt|  1 -
 clang/lib/Sema/CMakeLists.txt |  1 +
 .../ParseHLSLRootSignature.cpp|  2 +-
 clang/unittests/CMakeLists.txt|  1 -
 clang/unittests/Parse/CMakeLists.txt  | 20 ---
 clang/unittests/Sema/CMakeLists.txt   |  2 ++
 .../ParseHLSLRootSignatureTest.cpp|  2 +-
 8 files changed, 5 insertions(+), 24 deletions(-)
 rename clang/include/clang/{Parse => Sema}/ParseHLSLRootSignature.h (100%)
 rename clang/lib/{Parse => Sema}/ParseHLSLRootSignature.cpp (99%)
 delete mode 100644 clang/unittests/Parse/CMakeLists.txt
 rename clang/unittests/{Parse => Sema}/ParseHLSLRootSignatureTest.cpp (99%)

diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Sema/ParseHLSLRootSignature.h
similarity index 100%
rename from clang/include/clang/Parse/ParseHLSLRootSignature.h
rename to clang/include/clang/Sema/ParseHLSLRootSignature.h
diff --git a/clang/lib/Parse/CMakeLists.txt b/clang/lib/Parse/CMakeLists.txt
index 00fde537bb9c6..22e902f7e1bc5 100644
--- a/clang/lib/Parse/CMakeLists.txt
+++ b/clang/lib/Parse/CMakeLists.txt
@@ -14,7 +14,6 @@ add_clang_library(clangParse
   ParseExpr.cpp
   ParseExprCXX.cpp
   ParseHLSL.cpp
-  ParseHLSLRootSignature.cpp
   ParseInit.cpp
   ParseObjc.cpp
   ParseOpenMP.cpp
diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 4b87004e4b8ea..9ca4b8e6ab96b 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangSema
   JumpDiagnostics.cpp
   MultiplexExternalSemaSource.cpp
   ParsedAttr.cpp
+  ParseHLSLRootSignature.cpp
   Scope.cpp
   ScopeInfo.cpp
   Sema.cpp
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp 
b/clang/lib/Sema/ParseHLSLRootSignature.cpp
similarity index 99%
rename from clang/lib/Parse/ParseHLSLRootSignature.cpp
rename to clang/lib/Sema/ParseHLSLRootSignature.cpp
index 042aedbf1af52..87b5022cb0abe 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Sema/ParseHLSLRootSignature.cpp
@@ -6,7 +6,7 @@
 //
 
//===--===//
 
-#include "clang/Parse/ParseHLSLRootSignature.h"
+#include "clang/Sema/ParseHLSLRootSignature.h"
 
 #include "clang/Lex/LiteralSupport.h"
 
diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index f3823ba309420..580533a97d700 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -49,7 +49,6 @@ endfunction()
 
 add_subdirectory(Basic)
 add_subdirectory(Lex)
-add_subdirectory(Parse)
 add_subdirectory(Driver)
 if(CLANG_ENABLE_STATIC_ANALYZER)
   add_subdirectory(Analysis)
diff --git a/clang/unittests/Parse/CMakeLists.txt 
b/clang/unittests/Parse/CMakeLists.txt
deleted file mode 100644
index 2a31be625042e..0
--- a/clang/unittests/Parse/CMakeLists.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  )
-add_clang_unittest(ParseTests
-  ParseHLSLRootSignatureTest.cpp
-  )
-clang_target_link_libraries(ParseTests
-  PRIVATE
-  clangAST
-  clangBasic
-  clangLex
-  clangParse
-  clangSema
-  )
-target_link_libraries(ParseTests
-  PRIVATE
-  LLVMTest

[llvm-branch-commits] [clang] [NFC][HLSL][RootSignature] Move `HLSLRootSignatureParser` into `clangSema` (PR #137381)

2025-04-25 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/137381
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [NFC][HLSL][RootSignature] Move `HLSLRootSignatureParser` into `clangSema` (PR #137381)

2025-04-25 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic closed 
https://github.com/llvm/llvm-project/pull/137381
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [HLSL] Adding support for Root Constants in LLVM Metadata (PR #135085)

2025-04-15 Thread Finn Plummer via llvm-branch-commits


@@ -24,7 +24,11 @@
 namespace llvm {
 namespace dxil {
 
-enum class RootSignatureElementKind { Error = 0, RootFlags = 1 };
+enum class RootSignatureElementKind {

inbelic wrote:

What is the reason to define this instead of just using 
`dxbc::RootParameterType`. They seem to map to the same value and we are 
already using it in `DXILRootSignature.cpp`

https://github.com/llvm/llvm-project/pull/135085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [HLSL] Adding support for Root Constants in LLVM Metadata (PR #135085)

2025-04-15 Thread Finn Plummer via llvm-branch-commits


@@ -52,6 +59,45 @@ static bool parseRootFlags(LLVMContext *Ctx, 
mcdxbc::RootSignatureDesc &RSD,
   return false;
 }
 
+static bool extractMdValue(uint32_t &Value, MDNode *Node, unsigned int OpId) {
+
+  auto *CI = mdconst::extract(Node->getOperand(OpId));
+  if (CI == nullptr)
+return true;
+
+  Value = CI->getZExtValue();
+  return false;
+}
+
+static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc 
&RSD,
+   MDNode *RootFlagNode) {
+
+  if (RootFlagNode->getNumOperands() != 5)
+return reportError(Ctx, "Invalid format for RootConstants Element");
+
+  mcdxbc::RootParameter NewParameter;
+  NewParameter.Header.ParameterType = dxbc::RootParameterType::Constants32Bit;
+
+  uint32_t SV;
+  if (extractMdValue(SV, RootFlagNode, 1))
+return reportError(Ctx, "Invalid value for ShaderVisibility");
+
+  NewParameter.Header.ShaderVisibility = (dxbc::ShaderVisibility)SV;
+
+  if (extractMdValue(NewParameter.Constants.ShaderRegister, RootFlagNode, 2))
+return reportError(Ctx, "Invalid value for ShaderRegister");
+
+  if (extractMdValue(NewParameter.Constants.RegisterSpace, RootFlagNode, 3))
+return reportError(Ctx, "Invalid value for RegisterSpace");
+
+  if (extractMdValue(NewParameter.Constants.Num32BitValues, RootFlagNode, 4))
+return reportError(Ctx, "Invalid value for Num32BitValues");

inbelic wrote:

Only the "Invalid value for ShaderVisibility" has a test demonstrating its 
functionality. Maybe it is too verbose to include a test case for each diag 
type, or, they are all reporting the same error (expected an i32) and we could 
move that logic into `extractMdValue`?

https://github.com/llvm/llvm-project/pull/135085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add optional parameters for RootConstants (PR #138007)

2025-05-01 Thread Finn Plummer via llvm-branch-commits


@@ -255,7 +255,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) {
 TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) {

inbelic wrote:

Sure, I can add more. Just wasn't sure what the right balance is, as many of 
the error reports are already tested. I guess more tests never hurt tho. Will 
update.

https://github.com/llvm/llvm-project/pull/138007
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add optional parameters for RootConstants (PR #138007)

2025-05-01 Thread Finn Plummer via llvm-branch-commits


@@ -82,6 +82,8 @@ class RootSignatureParser {
   struct ParsedConstantParams {
 std::optional Reg;
 std::optional Num32BitConstants;
+std::optional Space;

inbelic wrote:

I think having it separate maps closer and clearer to the metadata and 
parameter specification

https://github.com/llvm/llvm-project/pull/138007
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-03-07 Thread Finn Plummer via llvm-branch-commits


@@ -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:]]}

inbelic wrote:

https://github.com/llvm/llvm-project/issues/126557 tracks this work

https://github.com/llvm/llvm-project/pull/125131
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-03-07 Thread Finn Plummer via llvm-branch-commits


@@ -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  struct OverloadBuilds : Ts... {
+  using Ts::operator()...;
+};
+template  OverloadBuilds(Ts...) -> OverloadBuilds;
+
+MDNode *MetadataBuilder::BuildRootSignature() {
+  for (const RootElement &Element : Elements) {
+MDNode *ElementMD =
+std::visit(OverloadBuilds{
+   [&](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 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
+  // 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 wrote:

Good catch. I think the specification is wrong then? Based on 
https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_descriptor_range?redirectedfrom=MSDN
 we should need to pass that down.

I will raise this

https://github.com/llvm/llvm-project/pull/125131
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Updating DXContainer documentation to add Root Descriptors (PR #129759)

2025-03-10 Thread Finn Plummer via llvm-branch-commits


@@ -497,3 +497,49 @@ signature and passed to the shader without requiring a 
constant buffer resource:
 #. **Num32BitValues**: The number of 32-bit values included in this constant 
buffer.
 
 Root constants provide a fast way to pass small amounts of data directly to 
the shader without the overhead of creating and binding a constant buffer 
resource.
+
+Root Descriptor
+~~~
+
+Root descriptors provide a direct mechanism for binding individual resources 
to shader stages in the Direct3D 12 
+rendering pipeline. They represent a critical interface for efficient resource 
management, allowing applications 
+to specify how shader stages access specific GPU resources.
+
+.. code-block:: cpp
+
+   enum RootDescriptorFlags {
+  None = 0,
+  DataVolatile = 0x2,
+  DataStaticWhileSetAtExecute = 0x4,
+  DataStatic = 0x8,
+   }
+
+   // Version 1.0 Root Descriptor
+   struct RootDescriptor_V1_0 {
+  uint32_t ShaderRegister;
+  uint32_t RegisterSpace;
+   };
+   
+   // Version 1.1 Root Descriptor
+   struct RootDescriptor_V1_1 {
+  uint32_t ShaderRegister;
+  uint32_t RegisterSpace;  
+  // Bitfield of flags from the Flags enum
+  uint32_t Flags;
+   };
+
+Version 1.1 of Root Descriptors has introduced some flags that can hint the 
drivers into
+performing further code optimizations. For details about it, check `Direct X 
documentation 
`_.

inbelic wrote:

```suggestion
performing further code optimizations. For details, check
`Direct X documentation 
`_.
```

https://github.com/llvm/llvm-project/pull/129759
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Updating DXContainer documentation to add Root Descriptors (PR #129759)

2025-03-10 Thread Finn Plummer via llvm-branch-commits


@@ -497,3 +497,49 @@ signature and passed to the shader without requiring a 
constant buffer resource:
 #. **Num32BitValues**: The number of 32-bit values included in this constant 
buffer.
 
 Root constants provide a fast way to pass small amounts of data directly to 
the shader without the overhead of creating and binding a constant buffer 
resource.
+
+Root Descriptor
+~~~
+
+Root descriptors provide a direct mechanism for binding individual resources 
to shader stages in the Direct3D 12 
+rendering pipeline. They represent a critical interface for efficient resource 
management, allowing applications 
+to specify how shader stages access specific GPU resources.

inbelic wrote:

Imo, this strays away from the `what and how` tone throughout this document and 
into `why`. I think the previous pr did a good job of keeping that tone, which 
I presume is what we would like. 

https://github.com/llvm/llvm-project/pull/129759
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Updating Root Signature documentation with Descriptor table description (PR #129797)

2025-03-11 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/129797
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Updating Root Signature documentation with Descriptor table description (PR #129797)

2025-03-11 Thread Finn Plummer via llvm-branch-commits


@@ -544,3 +544,73 @@ Version 1.1 Root Descriptor
 The Version 1.1 RootDescriptor_V1_1 extends the base structure with the 
following additional fields:
 
 #. **Flags**: Provides additional metadata about the descriptor's usage 
pattern.
+
+Root Descriptor Table
+~
+
+Descriptor tables provide a flexible mechanism for grouping and managing 
multiple resource descriptors within 
+a single root signature parameter. They enable efficient binding of complex 
shader resource sets while minimizing 
+root signature space consumption.

inbelic wrote:

I think https://github.com/llvm/llvm-project/pull/129759#discussion_r1987797852 
applies here as well

https://github.com/llvm/llvm-project/pull/129797
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Updating Root Signature documentation with Descriptor table description (PR #129797)

2025-03-11 Thread Finn Plummer via llvm-branch-commits


@@ -544,3 +544,73 @@ Version 1.1 Root Descriptor
 The Version 1.1 RootDescriptor_V1_1 extends the base structure with the 
following additional fields:
 
 #. **Flags**: Provides additional metadata about the descriptor's usage 
pattern.
+
+Root Descriptor Table
+~
+
+Descriptor tables provide a flexible mechanism for grouping and managing 
multiple resource descriptors within 
+a single root signature parameter. They enable efficient binding of complex 
shader resource sets while minimizing 
+root signature space consumption.
+
+.. code-block:: cpp
+
+   struct DescriptorRange_V1_0 {
+  dxbc::DescriptorRangeType RangeType;
+  uint32_t NumDescriptors;
+  uint32_t BaseShaderRegister;
+  uint32_t RegisterSpace;
+  uint32_t OffsetInDescriptorsFromTableStart;
+   };
+
+   struct DescriptorRange_V1_1 {
+  dxbc::DescriptorRangeType RangeType;
+  uint32_t NumDescriptors;
+  uint32_t BaseShaderRegister;
+  uint32_t RegisterSpace;
+  uint32_t OffsetInDescriptorsFromTableStart;
+  // New flags for Version 1.1
+  enum Flags {
+None= 0x0,
+// Descriptors are static and known at root signature creation
+DESCRIPTORS_STATIC  = 0x1,
+// Descriptors remain constant during command list execution
+DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS = 0x2,
+// Descriptors may change frequently
+DESCRIPTORS_VOLATILE= 0x4
+  };
+  
+  // Bitfield of flags from the Flags enum
+  uint32_t Flags;
+   };
+
+   struct RootDescriptorTable {
+  uint32_t NumDescriptorRanges;  
+  uint32_t DescriptorRangesOffset;  
+   };
+
+
+Descriptor Range Version 1.0
+
+
+The Version 1.0 ``DescriptorRange_V1_0`` provides basic descriptor range 
definition:
+
+#. **RangeType**: Type of descriptors (CBV, SRV, UAV, or Sampler)
+#. **NumDescriptors**: Number of descriptors in the range
+#. **BaseShaderRegister**: First shader register in the range
+#. **RegisterSpace**: Register space for the range
+#. **OffsetInDescriptorsFromTableStart**: Offset from the descriptor heap start
+
+Descriptor Range Version 1.1
+
+The Version 1.1 DescriptorRange_V1_1 extends the base structure with 
performance optimization flags.
+
+#. **Flags**: Provide additional information about the descriptors and enable 
further driver optimizations.

inbelic wrote:

Is there an easy link we can have to descriptions of the flags?

https://github.com/llvm/llvm-project/pull/129797
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-03-05 Thread Finn Plummer via llvm-branch-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | 
FileCheck %s
+
+// CHECK-DAG: ![[#EMPTY:]] = !{}
+[shader("compute"), RootSignature("")]
+[numthreads(1,1,1)]
+void FirstEntry() {}
+
+// CHECK-DAG: ![[#CBV:]] = !{!"CBV", i32 1, i32 0, i32 0, i32 -1, i32 4}

inbelic wrote:

These are in a deterministic order, I had only used DAG to help with 
readability of the testcase. But I can see that affects correctness. Updated to 
remove use of CHECK-DAG

https://github.com/llvm/llvm-project/pull/125131
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-03-05 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/125131
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-03-05 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic edited 
https://github.com/llvm/llvm-project/pull/125131
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-03-05 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/125131

>From abe7e6703a008608e19ce3f9bdcbd1b613fab60d Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 29 Jan 2025 19:40:08 +
Subject: [PATCH 1/7] add basic empty root signature

---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 21 +
 clang/test/CodeGenHLSL/RootSignature.hlsl | 19 +++
 2 files changed, 40 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/RootSignature.hlsl

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index c354e58e15f4b..ff608323e9ac3 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -119,6 +119,20 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) {
   return CBGV;
 }
 
+void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
+  auto &Ctx = M.getContext();
+  IRBuilder<> B(M.getContext());
+
+  MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
+
+  MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
+ ExampleRootSignature});
+
+  StringRef RootSignatureValKey = "dx.rootsignatures";
+  auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey);
+  RootSignatureValMD->addOperand(ExamplePairing);
+}
+
 } // namespace
 
 llvm::Type *CGHLSLRuntime::convertHLSLSpecificType(const Type *T) {
@@ -453,6 +467,13 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   // FIXME: Handle codegen for return type semantics.
   // See: https://github.com/llvm/llvm-project/issues/57875
   B.CreateRetVoid();
+
+  // Add and identify root signature to function, if applicable
+  const AttrVec &Attrs = FD->getAttrs();
+  for (const Attr *Attr : Attrs) {
+if (isa(Attr))
+  addRootSignature(EntryFn, M);
+  }
 }
 
 void CGHLSLRuntime::setHLSLFunctionAttributes(const FunctionDecl *FD,
diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl 
b/clang/test/CodeGenHLSL/RootSignature.hlsl
new file mode 100644
index 0..1ea9ab7aaa2c3
--- /dev/null
+++ b/clang/test/CodeGenHLSL/RootSignature.hlsl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | 
FileCheck %s
+
+// CHECK: !dx.rootsignatures = !{![[#FIRST_ENTRY:]], ![[#SECOND_ENTRY:]]}
+// CHECK-DAG: ![[#FIRST_ENTRY]] = !{ptr @FirstEntry, ![[#RS:]]}
+// CHECK-DAG: ![[#SECOND_ENTRY]] = !{ptr @SecondEntry, ![[#RS:]]}
+// CHECK-DAG: ![[#RS]] = !{}
+
+[shader("compute"), RootSignature("")]
+[numthreads(1,1,1)]
+void FirstEntry() {}
+
+[shader("compute"), RootSignature("DescriptorTable()")]
+[numthreads(1,1,1)]
+void SecondEntry() {}
+
+// Sanity test to ensure to root is added for this function
+[shader("compute")]
+[numthreads(1,1,1)]
+void ThirdEntry() {}

>From 671f099d3d58995677c47b4226481b72295e525d Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 29 Jan 2025 19:57:48 +
Subject: [PATCH 2/7] pass down the actual root elements

- test that we have the correct number of elements
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 17 -
 clang/test/CodeGenHLSL/RootSignature.hlsl |  9 +
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index ff608323e9ac3..4c9adcd8a9053 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -119,11 +119,18 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) 
{
   return CBGV;
 }
 
-void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
+void addRootSignature(
+ArrayRef Elements,
+llvm::Function *Fn, llvm::Module &M) {
   auto &Ctx = M.getContext();
-  IRBuilder<> B(M.getContext());
 
-  MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
+  SmallVector GeneratedMetadata;
+  for (auto Element : Elements) {
+MDNode *ExampleRootElement = MDNode::get(Ctx, {});
+GeneratedMetadata.push_back(ExampleRootElement);
+  }
+
+  MDNode *ExampleRootSignature = MDNode::get(Ctx, GeneratedMetadata);
 
   MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
  ExampleRootSignature});
@@ -471,8 +478,8 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   // Add and identify root signature to function, if applicable
   const AttrVec &Attrs = FD->getAttrs();
   for (const Attr *Attr : Attrs) {
-if (isa(Attr))
-  addRootSignature(EntryFn, M);
+if (const auto *RSAttr = dyn_cast(Attr))
+  addRootSignature(RSAttr->getElements(), EntryFn, M);
   }
 }
 
diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl 
b/clang/test/CodeGenHLSL/RootSignature.hlsl
index 1ea9ab7aaa2c3..63c0505e224f0 100644
--- a/clang/test/CodeGenHLSL/RootSignature.hlsl
+++ b/clang/test/CodeGenHLSL/RootSignature.hlsl
@@ -1,9 +1,10 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | 
FileCheck %s
 
-// CHECK: 

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-02-12 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/125131

>From abe7e6703a008608e19ce3f9bdcbd1b613fab60d Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 29 Jan 2025 19:40:08 +
Subject: [PATCH 1/6] add basic empty root signature

---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 21 +
 clang/test/CodeGenHLSL/RootSignature.hlsl | 19 +++
 2 files changed, 40 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/RootSignature.hlsl

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index c354e58e15f4b..ff608323e9ac3 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -119,6 +119,20 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) {
   return CBGV;
 }
 
+void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
+  auto &Ctx = M.getContext();
+  IRBuilder<> B(M.getContext());
+
+  MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
+
+  MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
+ ExampleRootSignature});
+
+  StringRef RootSignatureValKey = "dx.rootsignatures";
+  auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey);
+  RootSignatureValMD->addOperand(ExamplePairing);
+}
+
 } // namespace
 
 llvm::Type *CGHLSLRuntime::convertHLSLSpecificType(const Type *T) {
@@ -453,6 +467,13 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   // FIXME: Handle codegen for return type semantics.
   // See: https://github.com/llvm/llvm-project/issues/57875
   B.CreateRetVoid();
+
+  // Add and identify root signature to function, if applicable
+  const AttrVec &Attrs = FD->getAttrs();
+  for (const Attr *Attr : Attrs) {
+if (isa(Attr))
+  addRootSignature(EntryFn, M);
+  }
 }
 
 void CGHLSLRuntime::setHLSLFunctionAttributes(const FunctionDecl *FD,
diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl 
b/clang/test/CodeGenHLSL/RootSignature.hlsl
new file mode 100644
index 0..1ea9ab7aaa2c3
--- /dev/null
+++ b/clang/test/CodeGenHLSL/RootSignature.hlsl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | 
FileCheck %s
+
+// CHECK: !dx.rootsignatures = !{![[#FIRST_ENTRY:]], ![[#SECOND_ENTRY:]]}
+// CHECK-DAG: ![[#FIRST_ENTRY]] = !{ptr @FirstEntry, ![[#RS:]]}
+// CHECK-DAG: ![[#SECOND_ENTRY]] = !{ptr @SecondEntry, ![[#RS:]]}
+// CHECK-DAG: ![[#RS]] = !{}
+
+[shader("compute"), RootSignature("")]
+[numthreads(1,1,1)]
+void FirstEntry() {}
+
+[shader("compute"), RootSignature("DescriptorTable()")]
+[numthreads(1,1,1)]
+void SecondEntry() {}
+
+// Sanity test to ensure to root is added for this function
+[shader("compute")]
+[numthreads(1,1,1)]
+void ThirdEntry() {}

>From 671f099d3d58995677c47b4226481b72295e525d Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 29 Jan 2025 19:57:48 +
Subject: [PATCH 2/6] pass down the actual root elements

- test that we have the correct number of elements
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   | 17 -
 clang/test/CodeGenHLSL/RootSignature.hlsl |  9 +
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index ff608323e9ac3..4c9adcd8a9053 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -119,11 +119,18 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) 
{
   return CBGV;
 }
 
-void addRootSignature(llvm::Function *Fn, llvm::Module &M) {
+void addRootSignature(
+ArrayRef Elements,
+llvm::Function *Fn, llvm::Module &M) {
   auto &Ctx = M.getContext();
-  IRBuilder<> B(M.getContext());
 
-  MDNode *ExampleRootSignature = MDNode::get(Ctx, {});
+  SmallVector GeneratedMetadata;
+  for (auto Element : Elements) {
+MDNode *ExampleRootElement = MDNode::get(Ctx, {});
+GeneratedMetadata.push_back(ExampleRootElement);
+  }
+
+  MDNode *ExampleRootSignature = MDNode::get(Ctx, GeneratedMetadata);
 
   MDNode *ExamplePairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
  ExampleRootSignature});
@@ -471,8 +478,8 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
   // Add and identify root signature to function, if applicable
   const AttrVec &Attrs = FD->getAttrs();
   for (const Attr *Attr : Attrs) {
-if (isa(Attr))
-  addRootSignature(EntryFn, M);
+if (const auto *RSAttr = dyn_cast(Attr))
+  addRootSignature(RSAttr->getElements(), EntryFn, M);
   }
 }
 
diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl 
b/clang/test/CodeGenHLSL/RootSignature.hlsl
index 1ea9ab7aaa2c3..63c0505e224f0 100644
--- a/clang/test/CodeGenHLSL/RootSignature.hlsl
+++ b/clang/test/CodeGenHLSL/RootSignature.hlsl
@@ -1,9 +1,10 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | 
FileCheck %s
 
-// CHECK: 

[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-02-12 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic ready_for_review 
https://github.com/llvm/llvm-project/pull/125131
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-02-12 Thread Finn Plummer via llvm-branch-commits


@@ -647,6 +648,40 @@ void SemaHLSL::emitLogicalOperatorFixIt(Expr *LHS, Expr 
*RHS,
   << NewFnName << FixItHint::CreateReplacement(FullRange, OS.str());
 }
 
+void SemaHLSL::handleRootSignatureAttr(Decl *D, const ParsedAttr &AL) {
+  if (AL.getNumArgs() != 1)
+return;
+
+  StringRef Signature;
+  if (!SemaRef.checkStringLiteralArgumentAttr(AL, 0, Signature))
+return;
+
+  SourceLocation Loc = AL.getArgAsExpr(0)->getExprLoc();
+  // FIXME: pass down below to lexer when fp is supported
+  // llvm::RoundingMode RM = SemaRef.CurFPFeatures.getRoundingMode();
+  SmallVector Tokens;
+  hlsl::RootSignatureLexer Lexer(Signature, Loc, SemaRef.getPreprocessor());
+  if (Lexer.Lex(Tokens))

inbelic wrote:

Correct. We will have already produced the required error messages here.

https://github.com/llvm/llvm-project/pull/123985
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-02-12 Thread Finn Plummer via llvm-branch-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/123985

>From d9b0d8ee0f8420c56a6c2c5e0c2234fbc2a22d7e Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 22 Jan 2025 17:53:59 +
Subject: [PATCH 1/9] [HLSL] Define the HLSLRootSignature Attr

- Defines HLSLRootSignature Attr in `Attr.td`
- Define and implement handleHLSLRootSignature in `SemaHLSL`
- Adds sample test case to show AST Node is generated in
`RootSignatures-AST.hlsl`

This commit will "hook-up" the seperately defined RootSignature parser
and invoke it to create the RootElements, then store them on the
ASTContext and finally store the reference to the Elements in
RootSignatureAttr
---
 clang/include/clang/AST/Attr.h  |  1 +
 clang/include/clang/Basic/Attr.td   | 20 
 clang/include/clang/Basic/AttrDocs.td   |  4 +++
 clang/include/clang/Sema/SemaHLSL.h |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp |  3 ++
 clang/lib/Sema/SemaHLSL.cpp | 36 +
 clang/test/AST/HLSL/RootSignatures-AST.hlsl | 28 
 7 files changed, 93 insertions(+)
 create mode 100644 clang/test/AST/HLSL/RootSignatures-AST.hlsl

diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 3365ebe4d9012..d45b8891cf1a7 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -26,6 +26,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Support/Compiler.h"
 #include "llvm/Frontend/HLSL/HLSLResource.h"
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/VersionTuple.h"
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52ad72eb608c3..36ae98730db03 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4643,6 +4643,26 @@ def Error : InheritableAttr {
   let Documentation = [ErrorAttrDocs];
 }
 
+/// HLSL Root Signature Attribute
+def HLSLRootSignature : Attr {
+  /// [RootSignature(Signature)]
+  let Spellings = [Microsoft<"RootSignature">];
+  let Args = [StringArgument<"Signature">];
+  let Subjects = SubjectList<[Function],
+ ErrorDiag, "'function'">;
+  let LangOpts = [HLSL];
+  let Documentation = [HLSLRootSignatureDocs];
+  let AdditionalMembers = [{
+private:
+  ArrayRef RootElements;
+public:
+  void setElements(ArrayRef Elements) 
{
+RootElements = Elements;
+  }
+  auto getElements() const { return RootElements; }
+}];
+}
+
 def HLSLNumThreads: InheritableAttr {
   let Spellings = [Microsoft<"numthreads">];
   let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fdad4c9a3ea19..bb0934a11f9f3 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7783,6 +7783,10 @@ and 
https://microsoft.github.io/hlsl-specs/proposals/0013-wave-size-range.html
   }];
 }
 
+def HLSLRootSignatureDocs : Documentation {
+  let Category = DocCatUndocumented;
+}
+
 def NumThreadsDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index f4cd11f423a84..df4a5c8d88ba9 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -116,6 +116,7 @@ class SemaHLSL : public SemaBase {
bool IsCompAssign);
   void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc);
 
+  void handleRootSignatureAttr(Decl *D, const ParsedAttr &AL);
   void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
   void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b..c594d6e54ddbc 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7149,6 +7149,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
 break;
 
   // HLSL attributes:
+  case ParsedAttr::AT_HLSLRootSignature:
+S.HLSL().handleRootSignatureAttr(D, AL);
+break;
   case ParsedAttr::AT_HLSLNumThreads:
 S.HLSL().handleNumThreadsAttr(D, AL);
 break;
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 600c800029fd0..ab8aa6f5a351b 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -24,6 +24,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/Parse/ParseHLSLRootSignature.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/ParsedAttr.h"
 #include "clang/Sema/Sema.h"
@@ -647,6 +648,41 @@ void SemaHLSL::emitLogicalOperatorFixIt(Expr *LHS, Expr 
*RH

[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-02-12 Thread Finn Plummer via llvm-branch-commits

inbelic wrote:

> I was expectng a change in `CGHLSLRuntime.cpp` that did something with the 
> root signature attribute. Is there a reason why we aren't? That seems to be 
> the pattern for other prs like this for `WaveSizeAttr` and 
> `HLSLNumThreadsAttr`.

Yep, we will be using that to emit the metadata, which is addressed 
[here](https://github.com/llvm/llvm-project/pull/125131). I will get a 
reviewable version of that pr up soon.

This change just handles the construction of the attribute.

https://github.com/llvm/llvm-project/pull/123985
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [HLSL] Define the HLSLRootSignature Attr (PR #123985)

2025-02-12 Thread Finn Plummer via llvm-branch-commits


@@ -647,6 +648,40 @@ void SemaHLSL::emitLogicalOperatorFixIt(Expr *LHS, Expr 
*RHS,
   << NewFnName << FixItHint::CreateReplacement(FullRange, OS.str());
 }
 
+void SemaHLSL::handleRootSignatureAttr(Decl *D, const ParsedAttr &AL) {
+  if (AL.getNumArgs() != 1)
+return;
+
+  StringRef Signature;
+  if (!SemaRef.checkStringLiteralArgumentAttr(AL, 0, Signature))
+return;
+
+  SourceLocation Loc = AL.getArgAsExpr(0)->getExprLoc();
+  // FIXME: pass down below to lexer when fp is supported

inbelic wrote:

Yep, updated the comment to connect that.

https://github.com/llvm/llvm-project/pull/123985
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


  1   2   3   >