[llvm] [clang] [DirectX] Move ROV info into HLSL metadata. NFC (PR #74896)

2023-12-09 Thread Justin Bogner via cfe-commits

https://github.com/bogner closed https://github.com/llvm/llvm-project/pull/74896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [DirectX] Move ROV info into HLSL metadata. NFC (PR #74896)

2023-12-08 Thread David Peixotto via cfe-commits

https://github.com/dmpots edited https://github.com/llvm/llvm-project/pull/74896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [DirectX] Move ROV info into HLSL metadata. NFC (PR #74896)

2023-12-08 Thread Justin Bogner via cfe-commits


@@ -219,7 +221,7 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
  "ResourceMD must have been set by the switch above.");
 
   llvm::hlsl::FrontendResource Res(
-  GV, TyName, RK, Binding.Reg.value_or(UINT_MAX), Binding.Space);
+  GV, TyName, RK, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);

bogner wrote:

I considered flags (and a few other ways of trying to represent this), but I'm 
reasonably confident that we're not going to be adding a lot of flags here and 
that the bool is clearer if that's the case. Append and Consume buffers don't 
need any extra information passed along to the middle/backend, because they 
only differ from StructuredBuffer in what methods are legal. I'm picturing this 
going in a direction sort of like this:

https://github.com/bogner/llvm-project/commit/45c49457c38ad4b89e6e308100fa8266e4ceff6f

Note that I haven't really dealt with Textures yet, so some things may need to 
change, but I think this design makes sense to make incremental progress on.

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


[llvm] [clang] [DirectX] Move ROV info into HLSL metadata. NFC (PR #74896)

2023-12-08 Thread David Peixotto via cfe-commits


@@ -219,7 +221,7 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
  "ResourceMD must have been set by the switch above.");
 
   llvm::hlsl::FrontendResource Res(
-  GV, TyName, RK, Binding.Reg.value_or(UINT_MAX), Binding.Space);
+  GV, TyName, RK, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);

dmpots wrote:

Instead of a single `bool` here it might make sense to have some kind of 
`flags` field that we can extend as needed. I'm wondering what is special about 
ROV that we specifically need to flag them and if that is going to happen to 
other "weird" resource types (like Append/Consume buffers).

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


[llvm] [clang] [DirectX] Move ROV info into HLSL metadata. NFC (PR #74896)

2023-12-08 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 18f0da26b292341f84f91d4ce731b046315cd0a1 
133bdc09eed41545794a369d3fa4d2afb720815e -- clang/lib/CodeGen/CGHLSLRuntime.cpp 
clang/lib/CodeGen/CGHLSLRuntime.h 
llvm/include/llvm/Frontend/HLSL/HLSLResource.h 
llvm/lib/Frontend/HLSL/HLSLResource.cpp llvm/lib/Target/DirectX/DXILResource.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 0979a0c5eb..bb500cb5c9 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -92,8 +92,7 @@ private:
   void addBufferResourceAnnotation(llvm::GlobalVariable *GV,
llvm::StringRef TyName,
llvm::hlsl::ResourceClass RC,
-   llvm::hlsl::ResourceKind RK,
-   bool IsROV,
+   llvm::hlsl::ResourceKind RK, bool IsROV,
BufferResBinding );
   void addConstant(VarDecl *D, Buffer );
   void addBufferDecls(const DeclContext *DC, Buffer );

``




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


[llvm] [clang] [DirectX] Move ROV info into HLSL metadata. NFC (PR #74896)

2023-12-08 Thread Justin Bogner via cfe-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/74896

None

>From 133bdc09eed41545794a369d3fa4d2afb720815e Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Fri, 8 Dec 2023 15:41:14 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp   |  9 ++---
 clang/lib/CodeGen/CGHLSLRuntime.h |  1 +
 .../builtins/RWBuffer-annotations.hlsl| 12 +--
 clang/test/CodeGenHLSL/cbuf.hlsl  |  4 ++--
 .../include/llvm/Frontend/HLSL/HLSLResource.h |  5 +++--
 llvm/lib/Frontend/HLSL/HLSLResource.cpp   | 14 +
 llvm/lib/Target/DirectX/DXILResource.cpp  |  4 +---
 llvm/test/CodeGen/DirectX/UAVMetadata.ll  | 20 +--
 llvm/test/CodeGen/DirectX/cbuf.ll |  2 +-
 .../CodeGen/DirectX/legacy_cb_layout_0.ll |  2 +-
 .../CodeGen/DirectX/legacy_cb_layout_1.ll |  2 +-
 .../CodeGen/DirectX/legacy_cb_layout_2.ll |  4 ++--
 .../CodeGen/DirectX/legacy_cb_layout_3.ll |  2 +-
 13 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index c239bc17ef267..3e8a40e7540be 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -184,7 +184,8 @@ void CGHLSLRuntime::finishCodeGen() {
   : llvm::hlsl::ResourceKind::TBuffer;
 std::string TyName =
 Buf.Name.str() + (Buf.IsCBuffer ? ".cb." : ".tb.") + "ty";
-addBufferResourceAnnotation(GV, TyName, RC, RK, Buf.Binding);
+addBufferResourceAnnotation(GV, TyName, RC, RK, /*IsROV=*/false,
+Buf.Binding);
   }
 }
 
@@ -196,6 +197,7 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
 llvm::StringRef TyName,
 llvm::hlsl::ResourceClass RC,
 llvm::hlsl::ResourceKind RK,
+bool IsROV,
 BufferResBinding ) {
   llvm::Module  = CGM.getModule();
 
@@ -219,7 +221,7 @@ void 
CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
  "ResourceMD must have been set by the switch above.");
 
   llvm::hlsl::FrontendResource Res(
-  GV, TyName, RK, Binding.Reg.value_or(UINT_MAX), Binding.Space);
+  GV, TyName, RK, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);
   ResourceMD->addOperand(Res.getMetadata());
 }
 
@@ -236,10 +238,11 @@ void CGHLSLRuntime::annotateHLSLResource(const VarDecl 
*D, GlobalVariable *GV) {
 
   llvm::hlsl::ResourceClass RC = Attr->getResourceClass();
   llvm::hlsl::ResourceKind RK = Attr->getResourceKind();
+  bool IsROV = Attr->getIsROV();
 
   QualType QT(Ty, 0);
   BufferResBinding Binding(D->getAttr());
-  addBufferResourceAnnotation(GV, QT.getAsString(), RC, RK, Binding);
+  addBufferResourceAnnotation(GV, QT.getAsString(), RC, RK, IsROV, Binding);
 }
 
 CGHLSLRuntime::BufferResBinding::BufferResBinding(
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 67413fbd4a78e..0979a0c5eb9ad 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -93,6 +93,7 @@ class CGHLSLRuntime {
llvm::StringRef TyName,
llvm::hlsl::ResourceClass RC,
llvm::hlsl::ResourceKind RK,
+   bool IsROV,
BufferResBinding );
   void addConstant(VarDecl *D, Buffer );
   void addBufferDecls(const DeclContext *DC, Buffer );
diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
index 77091f8390a15..a70e224b81e4b 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
@@ -16,9 +16,9 @@ void main() {
 }
 
 // CHECK: !hlsl.uavs = !{![[Single:[0-9]+]], ![[Array:[0-9]+]], 
![[SingleAllocated:[0-9]+]], ![[ArrayAllocated:[0-9]+]], 
![[SingleSpace:[0-9]+]], ![[ArraySpace:[0-9]+]]}
-// CHECK-DAG: ![[Single]] = !{ptr @"?Buffer1@@3V?$RWBuffer@M@hlsl@@A", 
!"RWBuffer", i32 10, i32 -1, i32 0}
-// CHECK-DAG: ![[Array]] = !{ptr 
@"?BufferArray@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", 
!"RWBuffer >", i32 10, i32 -1, i32 0}
-// CHECK-DAG: ![[SingleAllocated]] = !{ptr 
@"?Buffer2@@3V?$RWBuffer@M@hlsl@@A", !"RWBuffer", i32 10, i32 3, i32 0}
-// CHECK-DAG: ![[ArrayAllocated]] = !{ptr 
@"?BufferArray2@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", 
!"RWBuffer >", i32 10, i32 4, i32 0}
-//