@@ -336,6 +336,8 @@ Supported extensions
336336* SPV_KHR_float_controls
337337* SPV_NV_shader_subgroup_partitioned
338338* SPV_KHR_quad_control
339+ * SPV_KHR_untyped_pointers
340+ * SPV_EXT_descriptor_heap
339341
340342Vulkan specific attributes
341343--------------------------
@@ -1993,10 +1995,14 @@ responsibility to provide proper numbers and avoid binding overlaps.
19931995ResourceDescriptorHeaps & SamplerDescriptorHeaps
19941996------------------------------------------------
19951997
1996- The SPIR-V backend supported SM6.6 resource heaps, using 2 extensions:
1998+ By default, the SPIR-V backend supports SM6.6 resource heaps by emulating the
1999+ heaps with descriptor-indexing runtime arrays, using 2 extensions:
2000+
19972001- `SPV_EXT_descriptor_indexing `
19982002- `VK_EXT_mutable_descriptor_type `
19992003
2004+ This is also the behavior selected by ``-fspv-use-emulated-heap ``.
2005+
20002006Each type loaded from a heap is considered to be an unbounded RuntimeArray
20012007bound to the descriptor set 0.
20022008
@@ -2074,6 +2080,85 @@ Bindings & sets associated with each heap can be explicitly set using:
20742080- `-fvk-bind-counter-heap <binding> <set> `: Specify Vulkan binding number
20752081 and set number for the counter heap.
20762082
2083+ Native descriptor heap extension lowering
2084+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2085+
2086+ When ``-fspv-use-descriptor-heap `` is specified, DXC lowers
2087+ ``ResourceDescriptorHeap `` and ``SamplerDescriptorHeap `` through
2088+ ``SPV_EXT_descriptor_heap `` instead of the default emulated heap path. This
2089+ also requires ``SPV_KHR_untyped_pointers `` and ``-fspv-target-env=vulkan1.3 ``
2090+ (targeting a lower environment is an error), and a SPIRV-Headers / SPIRV-Tools
2091+ build that defines these extensions. The emitted module declares the heap
2092+ objects as untyped variables in ``UniformConstant `` storage class:
2093+
2094+ .. code :: spirv
2095+
2096+ %uptr_uc = OpTypeUntypedPointerKHR UniformConstant
2097+ %resource_heap = OpUntypedVariableKHR %uptr_uc UniformConstant
2098+ %sampler_heap = OpUntypedVariableKHR %uptr_uc UniformConstant
2099+ OpDecorate %resource_heap BuiltIn ResourceHeapEXT
2100+ OpDecorate %sampler_heap BuiltIn SamplerHeapEXT
2101+
2102+ The concrete descriptor type is selected at each heap access. For image,
2103+ sampler, and texel buffer resources, DXC forms a runtime array of that
2104+ descriptor type and decorates the array with a byte ``ArrayStride ``, then uses
2105+ ``OpUntypedAccessChainKHR `` followed by ``OpLoad ``:
2106+
2107+ .. code :: spirv
2108+
2109+ %image_type = OpTypeImage %float 2D 2 0 0 1 Unknown
2110+ %image_array = OpTypeRuntimeArray %image_type
2111+ OpDecorate %image_array ArrayStride 64
2112+ %descriptor = OpUntypedAccessChainKHR %uptr_uc %image_array %resource_heap %index
2113+ %image = OpLoad %image_type %descriptor
2114+
2115+ For buffer-like resources, DXC uses ``OpTypeBufferEXT `` as the descriptor type
2116+ and ``OpBufferPointerEXT `` to recover the pointer to the buffer data. The
2117+ descriptor storage class matches the recovered buffer pointer storage class; for
2118+ example, ``ConstantBuffer<T> `` uses ``Uniform `` and ``TextureBuffer<T> `` uses
2119+ ``StorageBuffer ``:
2120+
2121+ .. code :: spirv
2122+
2123+ %buffer_type = OpTypeBufferEXT Uniform
2124+ %buffer_array = OpTypeRuntimeArray %buffer_type
2125+ OpDecorate %buffer_array ArrayStride 64
2126+ %descriptor = OpUntypedAccessChainKHR %uptr_uc %buffer_array %resource_heap %index
2127+ %buffer_ptr = OpBufferPointerEXT %_ptr_Uniform_type_BufferData %descriptor
2128+
2129+ For ``RWTexture `` resources loaded from ``ResourceDescriptorHeap ``, interlocked
2130+ operations that need a texel pointer use ``OpUntypedImageTexelPointerEXT ``.
2131+ The image descriptor pointer produced by ``OpUntypedAccessChainKHR `` is passed
2132+ directly to the texel-pointer instruction instead of first storing the image
2133+ handle into a function-scope image variable:
2134+
2135+ .. code :: spirv
2136+
2137+ %image_type = OpTypeImage %uint 2D 2 0 0 2 R32ui
2138+ %image_array = OpTypeRuntimeArray %image_type
2139+ %descriptor = OpUntypedAccessChainKHR %uptr_uc %image_array %resource_heap %index
2140+ %uptr_image = OpTypeUntypedPointerKHR Image
2141+ %texel_ptr = OpUntypedImageTexelPointerEXT %uptr_image %image_type %descriptor %coord %sample
2142+ %old = OpAtomicIAdd %uint %texel_ptr %scope %semantics %value
2143+
2144+ This path supports texture, RWTexture, sampler, Buffer/RWBuffer,
2145+ StructuredBuffer/RWStructuredBuffer without associated counter operations,
2146+ ByteAddressBuffer/RWByteAddressBuffer, ConstantBuffer, and TextureBuffer heap
2147+ loads, including direct field and array-element accesses for
2148+ ``ConstantBuffer<T> `` and ``TextureBuffer<T> ``. ``NonUniformResourceIndex `` is
2149+ accepted but the ``NonUniform `` decoration is not emitted on
2150+ ``OpUntypedAccessChainKHR `` or the loaded value; ``SPV_EXT_descriptor_heap ``
2151+ deprecates the ``NonUniform `` decoration for heap accesses.
2152+
2153+ Append/consume structured buffers and UAV counter heap lowering are not
2154+ supported by the native descriptor heap path yet. Those forms should continue
2155+ to use the default emulated heap lowering, or DXC will emit a diagnostic for
2156+ unsupported append/consume structured-buffer heap loads. Heap-loaded
2157+ ``RWStructuredBuffer `` resources are supported for ordinary data access, but
2158+ associated counter operations such as ``IncrementCounter `` and
2159+ ``DecrementCounter `` emit a diagnostic because the native descriptor heap path
2160+ does not recover an associated counter descriptor.
2161+
20772162HLSL Expressions
20782163================
20792164
0 commit comments