[SPIR-V] Add descriptor heap -fvk-resource-heap-stride / -fvk-sampler-heap-stride CLI flags - #8519
Conversation
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
1e2a278 to
5e7b928
Compare
|
@microsoft-github-policy-service agree company="NVIDIA" |
9c5badc to
ff7bb88
Compare
d2c47bb to
9f55ccb
Compare
| can be overridden, in increasing order of precedence: | ||
|
|
||
| - ``[[vk::resource_heap_stride_constant_id(id)]]`` and | ||
| ``[[vk::sampler_heap_stride_constant_id(id)]]`` on a ``uint`` global emit the |
There was a problem hiding this comment.
These spec constant attributes are actually in #8520, right? Maybe move them there? This way, this PR just handles the flags.
There was a problem hiding this comment.
Yes, this was a bit clumsy on my part. Will fix the documentation to remove mention of (now dropped feature) stride spec const attributes.
| !handleHeapStride(Args, OPT_fvk_sampler_heap_stride, | ||
| &opts.SpirvOptions.samplerHeapStride, | ||
| "-fvk-sampler-heap-stride", errors)) { | ||
| return 1; |
There was a problem hiding this comment.
If both flags are wrong, this will short-circuit and only give a single error message. Could you make both calls always happen and return the aggregate? Something like this:
bool ok = handleHeapStride(...resource...);
ok &= handleHeapStride(...sampler...);
if (!ok) return 1;
6bc5a9e to
c69d8a0
Compare
Diego Novillo (dnovillo)
left a comment
There was a problem hiding this comment.
Thanks for the fixes. LGTM now.
fcc9b25 to
2feca89
Compare
Building off of microsoft#8281, this commit adds a native lowering via SPV_EXT_descriptor_heap and SPV_KHR_untyped_pointers. ResourceDescriptorHeap and SamplerDescriptorHeap are lowered to untyped variables decorated with ResourceHeapEXT and SamplerHeapEXT. Each heap access emits OpUntypedAccessChainKHR into a runtime array of the appropriate descriptor type. Buffer-like resources (StructuredBuffer, ByteAddressBuffer, ConstantBuffer, TextureBuffer) use OpTypeBufferEXT and OpBufferPointerEXT; image and sampler resources use OpLoad. Interlocked operations on RWTexture use OpUntypedImageTexelPointerEXT. Requires -fspv-target-env=vulkan1.3. Assisted-by: Claude.
2feca89 to
7edda02
Compare
|
Extends the SPV_EXT_descriptor_heap native heap lowering to cover RaytracingAccelerationStructure resources loaded from ResourceDescriptorHeap. Acceleration structure descriptors are accessed via OpUntypedAccessChainKHR into a runtime array of OpTypeAccelerationStructureKHR, consistent with the image and sampler paths added in the previous commit.
7edda02 to
5783deb
Compare
There was a problem hiding this comment.
Pull request overview
Adds configurable resource and sampler descriptor-heap strides while expanding native SPV_EXT_descriptor_heap lowering.
Changes:
- Adds and validates the two stride CLI options.
- Supports literal and computed descriptor-array strides, including acceleration structures.
- Expands documentation and SPIR-V regression coverage.
Reviewed changes
Copilot reviewed 57 out of 57 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
tools/clang/unittests/SPIRV/SpirvContextTest.cpp |
Tests runtime-array uniquing. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.typed-formats.hlsl |
Tests typed image formats. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.texturecube.hlsl |
Tests cube textures. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.texture.hlsl |
Tests buffer textures. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.texture-sampler-assignment.hlsl |
Tests texture/sampler reassignment. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.texture-ms.hlsl |
Tests multisampled textures. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.texture-dims.hlsl |
Tests sampled texture dimensions. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.structured-buffer-atomic.hlsl |
Tests structured-buffer atomics. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.stride-cli.hlsl |
Tests literal CLI strides. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.stride-cli-permute.hlsl |
Tests stride values and validation. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.static-global.hlsl |
Tests static resource aliases. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.sampler-comparison.hlsl |
Tests comparison samplers. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.sample-grad-bias.hlsl |
Tests gradient and bias sampling. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.rwtexture-dims.hlsl |
Tests storage texture dimensions. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.rwtexture-atomics.hlsl |
Tests untyped image atomics. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.rwbyteaddressbuffer.hlsl |
Tests writable byte buffers. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.nonuniform.hlsl |
Tests divergent heap indexing. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.mixed-bound.hlsl |
Tests bound/heap coexistence. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.mixed-alias.error.hlsl |
Tests mixed-alias diagnostics. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.load-offset.hlsl |
Tests texture-load offsets. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.groupshared.hlsl |
Tests groupshared interoperability. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.gather.hlsl |
Tests texture gathers. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.function-params.hlsl |
Tests resource parameters. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.discarded.error.hlsl |
Tests discarded-access diagnostics. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.counter-ops.error.hlsl |
Tests unsupported counter diagnostics. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.constant-texture-buffer.hlsl |
Tests constant/texture buffers. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.constant-buffer-assignment.hlsl |
Tests constant-buffer reassignment. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.buffer.hlsl |
Tests buffer heap lowering. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.array-stride.hlsl |
Tests computed default strides. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.array-stride.accelstruct.hlsl |
Tests acceleration-structure strides. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.append-consume.error.hlsl |
Tests append/consume diagnostics. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.acceleration-structure.stride.error.hlsl |
Tests acceleration-stride errors. |
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.acceleration-structure.hlsl |
Tests acceleration-structure loads. |
tools/clang/test/CodeGenSPIRV/resource-heap-ext-texture.hlsl |
Removes superseded coverage. |
tools/clang/lib/SPIRV/SpirvType.cpp |
Includes stride IDs in type equality. |
tools/clang/lib/SPIRV/SpirvInstruction.cpp |
Implements new SPIR-V instructions. |
tools/clang/lib/SPIRV/SpirvEmitter.h |
Declares descriptor-heap helpers/state. |
tools/clang/lib/SPIRV/SpirvEmitter.cpp |
Implements native heap lowering and strides. |
tools/clang/lib/SPIRV/SpirvContext.cpp |
Uniques extended descriptor types. |
tools/clang/lib/SPIRV/SpirvBuilder.cpp |
Builds computed heap strides. |
tools/clang/lib/SPIRV/LowerTypeVisitor.cpp |
Lowers untyped image pointers. |
tools/clang/lib/SPIRV/EmitVisitor.h |
Declares new emission handlers. |
tools/clang/lib/SPIRV/EmitVisitor.cpp |
Emits new types, constants, and decorations. |
tools/clang/lib/SPIRV/DeclResultIdMapper.h |
Declares function alias support. |
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp |
Implements function aliases. |
tools/clang/lib/SPIRV/CapabilityVisitor.cpp |
Requires Vulkan 1.3 for native heaps. |
tools/clang/lib/SPIRV/AstTypeProbe.cpp |
Detects acceleration structures. |
tools/clang/include/clang/SPIRV/SpirvVisitor.h |
Extends visitor dispatch. |
tools/clang/include/clang/SPIRV/SpirvType.h |
Stores runtime-array stride IDs. |
tools/clang/include/clang/SPIRV/SpirvInstruction.h |
Defines new instruction classes. |
tools/clang/include/clang/SPIRV/SpirvContext.h |
Exposes extended type uniquing. |
tools/clang/include/clang/SPIRV/SpirvBuilder.h |
Exposes stride construction APIs. |
tools/clang/include/clang/SPIRV/AstTypeProbe.h |
Declares acceleration-type detection. |
lib/DxcSupport/HLSLOptions.cpp |
Parses and validates stride options. |
include/dxc/Support/SPIRVOptions.h |
Stores stride overrides. |
include/dxc/Support/HLSLOptions.td |
Defines the CLI flags. |
docs/SPIR-V.rst |
Documents native heaps and strides. |
| if (isRaytracingAccelerationStructure(resourceType) && | ||
| !spvBuilder.resourceHeapStrideIncludesAccelStruct()) { |
| bool strideOk = true; | ||
| strideOk &= handleHeapStride(Args, OPT_fvk_resource_heap_stride, | ||
| &opts.SpirvOptions.resourceHeapStride, | ||
| "-fvk-resource-heap-stride", errors); | ||
| strideOk &= handleHeapStride(Args, OPT_fvk_sampler_heap_stride, | ||
| &opts.SpirvOptions.samplerHeapStride, | ||
| "-fvk-sampler-heap-stride", errors); |
| // [[RS]] = resource-heap stride, [[SS]] = sampler-heap stride (per-RUN via -D). | ||
|
|
||
| // ---- Full 6x6 cross product of {8,16,32,64,128,256} x {8,16,32,64,128,256} ---- | ||
| // RUN: %dxc -T cs_6_6 -E main -Od -fspv-use-descriptor-heap -fspv-target-env=vulkan1.3 -fvk-resource-heap-stride 8 -fvk-sampler-heap-stride 8 -spirv %s | FileCheck %s -DRS=8 -DSS=8 |
| if (!args.hasArg(OPT_spirv)) { | ||
| errors << name << " requires -spirv"; | ||
| return false; |
| def fvk_resource_heap_stride : Separate<["-"], "fvk-resource-heap-stride">, MetaVarName<"<stride>">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>, | ||
| HelpText<"Override the byte ArrayStride of the resource descriptor heap runtime array. Must be a power of 2 in [8, 256].">; | ||
| def fvk_sampler_heap_stride : Separate<["-"], "fvk-sampler-heap-stride">, MetaVarName<"<stride>">, Group<spirv_Group>, Flags<[CoreOption, DriverOption]>, | ||
| HelpText<"Override the byte ArrayStride of the sampler descriptor heap runtime array. Must be a power of 2 in [8, 256].">; |
|
Added an analysis on this series: #8517 (comment) |
Building off of #8518, this PR adds two new command-line flags that override the ArrayStride of the descriptor heap runtime arrays emitted by -fspv-use-descriptor-heap. It is part 3/4 in a series.
-fvk-resource-heap-stride and -fvk-sampler-heap-stride sets the stride for ResourceDescriptorHeap SamplerDescriptorHeap arrays respectively. N and M must be a power of two in [8, 256]. When set, the CLI value takes the highest precedence.
Assisted by an AI agent.
Diego Novillo (@dnovillo)