Repository navigation
[SPIRV] Add -fspv-flatten-resource-array-bindings-only - #8705
Youssef Abusamra (l3rp) wants to merge 6 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
@microsoft-github-policy-service agree |
Gregory Roth (pow2clk)
left a comment
There was a problem hiding this comment.
My main confusion here is how the previous -fspv-flatten-resource-arrays flag was useful. The way the commit message for #2397 reads, it sounds like it's trying to solve this exact problem, but I don't see why flattening the arrays was necessary. Perhaps the concern was without individual variables, they might be consolidated to fill in the gaps? Is there anywhere that might happen?
The only way this is relevant to your change is if the actual solution is to remove the old behavior and replace it with this.
| array size) instead of splitting it into one variable per element. Use this | ||
| when you want later-declared resources to avoid overlapping the numbers an | ||
| array would need under DX, without requiring the array itself to be | ||
| split up or unrolled. |
There was a problem hiding this comment.
I hate to bikeshed over naming, but I don't think what this does can be described as flattening even though it shares some behavior with the flag that does.
Perhaps something like spv-dx-resource-array-binding? I'm open to other suggestions.
There was a problem hiding this comment.
-fspv-flatten-resource-arrays is for when non uniform resource accesses are unsupported AFAIK, an OpSwitch with an array element per case is generated when a non compile time constant is used.
I think -fspv-dx-resource-array-binding would be less "obvious" though?
There was a problem hiding this comment.
What about something that more explicitly describes what this does? -fspv-reserve-resource-array-bindings?
|
There was a problem hiding this comment.
Pull request overview
Adds a SPIR-V option that reserves binding slots for resource-array elements without splitting arrays into separate variables.
Changes:
- Adds and parses the new compiler option.
- Extends SPIR-V binding allocation.
- Adds documentation, release notes, and optimized/unoptimized tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
include/dxc/Support/HLSLOptions.td |
Defines the command-line option. |
include/dxc/Support/SPIRVOptions.h |
Stores the option state. |
lib/DxcSupport/HLSLOptions.cpp |
Parses and validates option availability. |
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp |
Reserves array-sized binding ranges. |
tools/clang/test/CodeGenSPIRV/vk.binding.cl.flatten-array-bindings-only.example1.hlsl |
Tests unoptimized binding allocation. |
tools/clang/test/CodeGenSPIRV/vk.binding.cl.flatten-array-bindings-only.example1-optimized.hlsl |
Tests optimized output without array splitting. |
docs/SPIR-V.rst |
Documents behavior and usage. |
docs/ReleaseNotes.md |
Announces the option. |
Suppressed comments (1)
tools/clang/test/CodeGenSPIRV/vk.binding.cl.flatten-array-bindings-only.example1-optimized.hlsl:18
[unroll]is attached to themaindeclaration here, but this attribute only applies to loop statements, so the compiler diagnoses/ignores it and the loop is not explicitly unrolled. Move it immediately before theforstatement.
[unroll]
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Suppressed comments (1)
tools/clang/test/CodeGenSPIRV/vk.binding.cl.flatten-array-bindings-only.example1-optimized.hlsl:22
[unroll]is attached tomainhere, not to the loop, so it is ignored and produces an attribute warning instead of marking the loop. Move it immediately before theforstatement.
[unroll]
| // CHECK: OpDecorate %NextTexture Binding 6 | ||
| // CHECK: OpDecorate %MySamplers Binding 7 | ||
| // CHECK-NOT: MyTextures_0_ | ||
| // CHECK-NOT: MySamplers_0_ |
There was a problem hiding this comment.
These CHECK-NOTs will not trigger here. Moving them before the CHECKs is probably the easiest way to handle them.
- Reserves 1 binding slot per array element for resource arrays matching -fspv-flatten-resource-arrays but without emitting separate SPIRV variables/bindings. - Adds CodeGenSPIRV tests covering the non optimized and -O3 cases.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…nded arrays - Rename -fspv-flatten-resource-array-bindings-only to -fspv-reserve-resource-array-bindings, since the option does not flatten anything; it only reserves one binding per array element. - Return a single binding for unbounded (IncompleteArrayType) resource arrays in getNumBindingsUsedByResourceType instead of asserting, and add a regression test. - Fix the optimized test: attach [unroll] to the loop instead of main and move the CHECK-NOTs ahead of the CHECKs so they actually apply. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2e81951 to
d3c470b
Compare
…tests - Canonicalize the type in getNumBindingsUsedByResourceType so arrays declared through a typedef reserve one binding per element instead of being treated as a single resource. - Add a typedef regression test covering explicitly and implicitly bound typedef'd arrays. - Add a trailing implicitly bound texture to the example tests so under-reservation in the implicit-binding path is caught. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
createExternVar registers every extern global in resourceVars, including non-resources such as variables with [[vk::ext_storage_class]]. With -fspv-reserve-resource-array-bindings these reached getNumBindingsUsedByResourceType and tripped its resource-only assertion. Return a single binding for such types instead, and add a regression test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
| if (type->isIncompleteArrayType()) | ||
| return arrayFactor; |


-fspv-flatten-resource-arraysbut without emitting separate SPIRV variables/bindings.