[llvm] [DirectX] Update "dx.TypedBuffer" docs to include a "signed" bit (PR #100695)
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 27 22:41:49 PDT 2024
https://github.com/bogner updated https://github.com/llvm/llvm-project/pull/100695
>From 73e62bff66841afbdad960a5803dde76e18dcda6 Mon Sep 17 00:00:00 2001
From: Justin Bogner <mail at justinbogner.com>
Date: Thu, 25 Jul 2024 22:22:26 -0700
Subject: [PATCH 1/3] [DirectX] Update "dx.TypedBuffer" docs to include a
"signed" bit
To lower these types to dxil we need to know whether ints are signed
or not, but the LLVM type loses that. Add a bit to indicate it's so.
---
llvm/docs/DirectX/DXILResources.rst | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/llvm/docs/DirectX/DXILResources.rst b/llvm/docs/DirectX/DXILResources.rst
index 5bbe902d9d2d7..8f7b11f7255c0 100644
--- a/llvm/docs/DirectX/DXILResources.rst
+++ b/llvm/docs/DirectX/DXILResources.rst
@@ -96,7 +96,7 @@ Buffers
.. code-block:: llvm
- target("dx.TypedBuffer", ElementType, IsWriteable, IsROV)
+ target("dx.TypedBuffer", ElementType, IsWriteable, IsROV, IsSigned)
target("dx.RawBuffer", ElementType, IsWriteable, IsROV)
We need two separate buffer types to account for the differences between the
@@ -106,9 +106,10 @@ used for DXIL's RawBuffers and StructuredBuffers. We call the latter
"RawBuffer" to match the naming of the operations, but it can represent both
the Raw and Structured variants.
-For TypedBuffer, the element type must be an integer or floating point type.
-For RawBuffer the type can be an integer, floating point, or struct type.
-HLSL's ByteAddressBuffer is represented by an `i8` element type.
+For TypedBuffer, the element type must be an scalar integer or floating point
+type, or a vector of at most 4 such types. For RawBuffer the type can be an
+integer, floating point, vecvtor, or struct type. HLSL's ByteAddressBuffer is
+represented as a RawBuffer with an `i8` element type.
These types are generally used by BufferLoad and BufferStore operations, as
well as atomics.
@@ -128,6 +129,8 @@ There are a few fields to describe variants of all of these types:
writeable) and UAVs (writeable).
* - IsROV
- Whether the UAV is a rasterizer ordered view. Always ``0`` for SRVs.
+ * - IsSigned
+ - Whether the element type is signed ("dx.TypedBuffer" only)
.. _bufferLoad: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#bufferload
.. _bufferStore: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#bufferstore
@@ -197,23 +200,23 @@ Examples:
.. code-block:: llvm
; RWBuffer<float4> Buf : register(u5, space3)
- %buf = call target("dx.TypedBuffer", float, 1, 0)
+ %buf = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_f32_1_0(
i32 3, i32 5, i32 1, i32 0, i1 false)
- ; RWBuffer<uint> Buf : register(u7, space2)
- %buf = call target("dx.TypedBuffer", i32, 1, 0)
+ ; RWBuffer<int> Buf : register(u7, space2)
+ %buf = call target("dx.TypedBuffer", i32, 1, 0, 1)
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_1_0t(
i32 2, i32 7, i32 1, i32 0, i1 false)
; Buffer<uint4> Buf[24] : register(t3, space5)
- %buf = call target("dx.TypedBuffer", i32, 0, 0)
+ %buf = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 0)
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_0_0t(
i32 2, i32 7, i32 24, i32 0, i1 false)
; struct S { float4 a; uint4 b; };
; StructuredBuffer<S> Buf : register(t2, space4)
- %buf = call target("dx.RawBuffer", {<4 x f32>, <4 x i32>}, 0, 0)
+ %buf = call target("dx.RawBuffer", {<4 x float>, <4 x i32>}, 0, 0)
@llvm.dx.handle.fromBinding.tdx.RawBuffer_sl_v4f32v4i32s_0_0t(
i32 4, i32 2, i32 1, i32 0, i1 false)
>From 44ae37d45eccc79d8621d0b423efc2531e581fbf Mon Sep 17 00:00:00 2001
From: Justin Bogner <mail at justinbogner.com>
Date: Sat, 27 Jul 2024 22:20:15 -0700
Subject: [PATCH 2/3] Update llvm/docs/DirectX/DXILResources.rst
Co-authored-by: Damyan Pepper <damyanp at microsoft.com>
---
llvm/docs/DirectX/DXILResources.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/docs/DirectX/DXILResources.rst b/llvm/docs/DirectX/DXILResources.rst
index 8f7b11f7255c0..55e413961ed17 100644
--- a/llvm/docs/DirectX/DXILResources.rst
+++ b/llvm/docs/DirectX/DXILResources.rst
@@ -108,7 +108,7 @@ the Raw and Structured variants.
For TypedBuffer, the element type must be an scalar integer or floating point
type, or a vector of at most 4 such types. For RawBuffer the type can be an
-integer, floating point, vecvtor, or struct type. HLSL's ByteAddressBuffer is
+integer, floating point, vector, or struct type. HLSL's ByteAddressBuffer is
represented as a RawBuffer with an `i8` element type.
These types are generally used by BufferLoad and BufferStore operations, as
>From fed71e818bac58dbd6e19b514213f6eac57f6526 Mon Sep 17 00:00:00 2001
From: Justin Bogner <mail at justinbogner.com>
Date: Sat, 27 Jul 2024 22:39:42 -0700
Subject: [PATCH 3/3] fixup: Improve typed buffer signed parameter docs
---
llvm/docs/DirectX/DXILResources.rst | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/llvm/docs/DirectX/DXILResources.rst b/llvm/docs/DirectX/DXILResources.rst
index 55e413961ed17..aef88bc43b224 100644
--- a/llvm/docs/DirectX/DXILResources.rst
+++ b/llvm/docs/DirectX/DXILResources.rst
@@ -106,10 +106,14 @@ used for DXIL's RawBuffers and StructuredBuffers. We call the latter
"RawBuffer" to match the naming of the operations, but it can represent both
the Raw and Structured variants.
-For TypedBuffer, the element type must be an scalar integer or floating point
-type, or a vector of at most 4 such types. For RawBuffer the type can be an
-integer, floating point, vector, or struct type. HLSL's ByteAddressBuffer is
-represented as a RawBuffer with an `i8` element type.
+HLSL's Buffer and RWBuffer are represented as a TypedBuffer with an element
+type that is a scalar integer or floating point type, or a vector of at most 4
+such types. HLSL's ByteAddressBuffer is a RawBuffer with an `i8` element type.
+HLSL's StructuredBuffers are RawBuffer with a struct, vector, or scalar type.
+
+One unfortunate necessity here is that TypedBuffer needs an extra parameter to
+differentiate signed vs unsigned ints. The is because in LLVM IR int types
+don't have a sign, so to keep this information we need a side channel.
These types are generally used by BufferLoad and BufferStore operations, as
well as atomics.
@@ -130,7 +134,7 @@ There are a few fields to describe variants of all of these types:
* - IsROV
- Whether the UAV is a rasterizer ordered view. Always ``0`` for SRVs.
* - IsSigned
- - Whether the element type is signed ("dx.TypedBuffer" only)
+ - Whether an int element type is signed ("dx.TypedBuffer" only)
.. _bufferLoad: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#bufferload
.. _bufferStore: https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#bufferstore
More information about the llvm-commits
mailing list