From c8fccdbbf51eedb7b390b48da6aeb7763ca16343 Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Wed, 7 May 2025 11:26:56 -0400 Subject: [PATCH 1/2] [0018] Update cbuffer representation CBuffer will use the `spirv.Layout` type. We leave open how to handle substructures in the cbuffer. Contributes to https://github.com/llvm/llvm-project/issues/138276. --- .../0018-spirv-resource-representation.md | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/proposals/0018-spirv-resource-representation.md b/proposals/0018-spirv-resource-representation.md index c6e85ad..c89d730 100644 --- a/proposals/0018-spirv-resource-representation.md +++ b/proposals/0018-spirv-resource-representation.md @@ -66,7 +66,7 @@ type. For now, the counter variable will not be handled. We will create a target type `spirv.VulkanBuffer` to represent a storage or uniform buffer: ``` -target("spirv.VulkanBuffer", ElementType, StorageClass, IsWriteable, IsROV) +target("spirv.VulkanBuffer", ElementType, StorageClass, IsWriteable) ``` `ElementType` is the type for the storage buffer array, and `StorageClass` is @@ -149,13 +149,13 @@ it is used. The handle for structured buffers will be -| HLSL Resource Type | Handle Type | -|--------------------------------------|----------------------------------------------------| -| StructuredBuffer | spirv.VulkanBuffer(T, StorageBuffer, false, false) | -| RWStructuredBuffer | spirv.VulkanBuffer(T, StorageBuffer, true, false) | -| RasterizerOrderedStructuredBuffer | spirv.VulkanBuffer(T, StorageBuffer, true, true) | -| AppendStructuredBuffer | spirv.VulkanBuffer(T, StorageBuffer, true, false) | -| ConsumeStructuredBuffer | spirv.VulkanBuffer(T, StorageBuffer, true, false) | +| HLSL Resource Type | Handle Type | +|--------------------------------------|---------------------------------------------| +| StructuredBuffer | spirv.VulkanBuffer(T, StorageBuffer, false) | +| RWStructuredBuffer | spirv.VulkanBuffer(T, StorageBuffer, true) | +| RasterizerOrderedStructuredBuffer | TODO | +| AppendStructuredBuffer | spirv.VulkanBuffer(T, StorageBuffer, true) | +| ConsumeStructuredBuffer | spirv.VulkanBuffer(T, StorageBuffer, true) | ### Texture buffers @@ -164,17 +164,28 @@ perspective, this makes it the same as a `StructureBuffer`, and will be represented the same way: ``` -spirv.VulkanBuffer(T, StorageBuffer, false, false) +spirv.VulkanBuffer(T, StorageBuffer, false) ``` ### Constant buffers -In SPIR-V, constant buffers are implemented as uniform buffers. The only -difference between a uniform buffer and storage buffer is the storage class. -Uniform buffers use the `Uniform` storage class. The handle type will be: +Our design for constant buffers will be in line with +proposal [0016 constant buffers](0016-constant-buffers.md). +As in that proposal, we will use `spirv.LayoutType` for the struct in the +buffer. We use the layout type +because we cannot reorder or add new members to the layout type in allow the +standard offset calculations for structs to work. That will break the `hlsl.cbs` +metadata. + +TODO: Still unclear how to lay out the members of `T` that are structs. + +The `spirv.Layout` will then be wrapped in a `spirv.VulkanBuffer` type to +represent a uniform buffer: + +The handle type will be: ``` -spirv.VulkanBuffer(T, Uniform, false, false) +spirv.VulkanBuffer(spirv.LayoutType(T, sizeof(T), Offsets...), Uniform, false) ``` ### Samplers From fc0f4deaa8c87dbd11c4aae26af5c39108d57ce3 Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Wed, 28 May 2025 15:47:13 -0400 Subject: [PATCH 2/2] Fix typo --- proposals/0018-spirv-resource-representation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/0018-spirv-resource-representation.md b/proposals/0018-spirv-resource-representation.md index c89d730..937858f 100644 --- a/proposals/0018-spirv-resource-representation.md +++ b/proposals/0018-spirv-resource-representation.md @@ -173,7 +173,7 @@ Our design for constant buffers will be in line with proposal [0016 constant buffers](0016-constant-buffers.md). As in that proposal, we will use `spirv.LayoutType` for the struct in the buffer. We use the layout type -because we cannot reorder or add new members to the layout type in allow the +because we cannot reorder or add new members to the layout type to allow the standard offset calculations for structs to work. That will break the `hlsl.cbs` metadata.