Repository navigation
[SPIRV] Add -fspv-flatten-resource-array-bindings-only #8705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Youssef Abusamra (l3rp)
wants to merge
6
commits into
microsoft:main
Choose a base branch
from
l3rp:spv-array-flatten-binding-only
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+164
−5
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
10ee56e
[SPIRV] Add -fspv-flatten-resource-array-bindings-only
YoussefAbusamra af1f1aa
Add to release notes
YoussefAbusamra 295306f
Apply suggestions from code review
l3rp d3c470b
[SPIRV] Rename to -fspv-reserve-resource-array-bindings, handle unbou…
YoussefAbusamra 5df1169
[SPIRV] Count typedef'd resource arrays; tighten binding reservation …
YoussefAbusamra e4b477f
[SPIRV] Fall back to one binding for non-resource globals
YoussefAbusamra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
tools/clang/test/CodeGenSPIRV/vk.binding.cl.reserve-array-bindings.example1-optimized.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // RUN: %dxc -T ps_6_0 -E main -fspv-reserve-resource-array-bindings -O3 %s -spirv | FileCheck %s | ||
|
|
||
| // The array is NOT split into individual variables (unlike | ||
| // -fspv-flatten-resource-arrays): MyTextures/MySamplers stay as single | ||
| // array variables, each with a single Binding decoration, but the binding | ||
| // numbers reserved for them still account for the full array size. | ||
| // CHECK-NOT: MyTextures_0_ | ||
| // CHECK-NOT: MySamplers_0_ | ||
| // CHECK: OpDecorate %MyTextures Binding 0 | ||
| // CHECK: OpDecorate %AnotherTexture Binding 5 | ||
| // CHECK: OpDecorate %NextTexture Binding 6 | ||
| // CHECK: OpDecorate %MySamplers Binding 7 | ||
| // CHECK: OpDecorate %LastTexture Binding 9 | ||
| Texture2D MyTextures[5] : register(t0); | ||
| Texture2D NextTexture; // This is supposed to be t6. | ||
| Texture2D AnotherTexture : register(t5); | ||
| SamplerState MySamplers[2]; | ||
| Texture2D LastTexture; // Right after MySamplers[2], so this is supposed to be t9. | ||
|
|
||
| float4 main(float2 TexCoord : TexCoord) : SV_Target0 | ||
| { | ||
| float4 result = 0; | ||
| [unroll] | ||
| for (uint i = 0; i < 5; ++i) | ||
| result += MyTextures[i].Sample(MySamplers[i < 3 ? 0 : 1], TexCoord); | ||
| result += AnotherTexture.Sample(MySamplers[1], TexCoord); | ||
| result += NextTexture.Sample(MySamplers[1], TexCoord); | ||
| result += LastTexture.Sample(MySamplers[1], TexCoord); | ||
| return result; | ||
| } |
26 changes: 26 additions & 0 deletions
26
tools/clang/test/CodeGenSPIRV/vk.binding.cl.reserve-array-bindings.example1.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // RUN: %dxc -T ps_6_0 -E main -fspv-reserve-resource-array-bindings -fcgl %s -spirv | FileCheck %s | ||
|
|
||
| // CHECK: OpDecorate %MyTextures Binding 0 | ||
| // CHECK: OpDecorate %AnotherTexture Binding 5 | ||
| // CHECK: OpDecorate %NextTexture Binding 6 | ||
| // CHECK: OpDecorate %MySamplers Binding 7 | ||
| // CHECK: OpDecorate %LastTexture Binding 9 | ||
| Texture2D MyTextures[5] : register(t0); | ||
| Texture2D NextTexture; // This is supposed to be t6. | ||
| Texture2D AnotherTexture : register(t5); | ||
| SamplerState MySamplers[2]; | ||
| Texture2D LastTexture; // Right after MySamplers[2], so this is supposed to be t9. | ||
|
|
||
| float4 main(float2 TexCoord : TexCoord) : SV_Target0 | ||
| { | ||
| float4 result = | ||
| MyTextures[0].Sample(MySamplers[0], TexCoord) + | ||
| MyTextures[1].Sample(MySamplers[0], TexCoord) + | ||
| MyTextures[2].Sample(MySamplers[0], TexCoord) + | ||
| MyTextures[3].Sample(MySamplers[1], TexCoord) + | ||
| MyTextures[4].Sample(MySamplers[1], TexCoord) + | ||
| AnotherTexture.Sample(MySamplers[1], TexCoord) + | ||
| NextTexture.Sample(MySamplers[1], TexCoord) + | ||
| LastTexture.Sample(MySamplers[1], TexCoord); | ||
| return result; | ||
| } |
17 changes: 17 additions & 0 deletions
17
tools/clang/test/CodeGenSPIRV/vk.binding.cl.reserve-array-bindings.non-resource.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // RUN: %dxc -T ps_6_0 -E main -fspv-reserve-resource-array-bindings -Vd -fcgl %s -spirv | FileCheck %s | ||
|
|
||
| // Regression test: globals that are not resources (here, one with an inline | ||
| // SPIR-V storage class) are also visited when reserving bindings. They must | ||
| // fall back to a single binding instead of tripping the resource-only | ||
| // assertion in getNumBindingsUsedByResourceType. | ||
|
|
||
| [[vk::ext_extension("SPV_KHR_ray_tracing")]] | ||
| [[vk::ext_capability(/* RayTracingKHR */ 4479)]] | ||
| [[vk::ext_storage_class(/*RayPayloadKHR*/5338)]] | ||
| float4 payload; | ||
| // CHECK-DAG: [[ptr_payload_v4:%[a-zA-Z0-9_]+]] = OpTypePointer RayPayloadKHR %v4float | ||
| // CHECK-DAG: %payload = OpVariable [[ptr_payload_v4]] RayPayloadKHR | ||
|
|
||
| float4 main() : SV_Target0 { | ||
| return payload; | ||
| } |
25 changes: 25 additions & 0 deletions
25
tools/clang/test/CodeGenSPIRV/vk.binding.cl.reserve-array-bindings.typedef.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // RUN: %dxc -T ps_6_0 -E main -fspv-reserve-resource-array-bindings -fcgl %s -spirv | FileCheck %s | ||
|
|
||
| // Regression test: arrays declared through a typedef must reserve one binding | ||
| // per element, just like arrays spelled out directly. Both the explicitly and | ||
| // the implicitly bound typedef'd arrays have to be counted in full, otherwise | ||
| // the resources declared after them overlap. | ||
| // CHECK: OpDecorate %ExplicitTextures Binding 0 | ||
| // CHECK: OpDecorate %ImplicitTextures Binding 3 | ||
| // CHECK: OpDecorate %NextTexture Binding 6 | ||
| typedef Texture2D Textures[3]; | ||
| Textures ExplicitTextures : register(t0); | ||
| Textures ImplicitTextures; | ||
| Texture2D NextTexture; | ||
| SamplerState MySampler; | ||
|
|
||
| float4 main(float2 TexCoord : TexCoord) : SV_Target0 | ||
| { | ||
| float4 result = | ||
| ExplicitTextures[0].Sample(MySampler, TexCoord) + | ||
| ExplicitTextures[2].Sample(MySampler, TexCoord) + | ||
| ImplicitTextures[0].Sample(MySampler, TexCoord) + | ||
| ImplicitTextures[2].Sample(MySampler, TexCoord) + | ||
| NextTexture.Sample(MySampler, TexCoord); | ||
| return result; | ||
| } |
21 changes: 21 additions & 0 deletions
21
tools/clang/test/CodeGenSPIRV/vk.binding.cl.reserve-array-bindings.unbounded.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // RUN: %dxc -T ps_6_0 -E main -fspv-reserve-resource-array-bindings -fcgl %s -spirv | FileCheck %s | ||
|
|
||
| // Regression test: an explicitly-bound unbounded (runtime-sized) resource | ||
| // array used to crash getNumBindingsUsedByResourceType, since its AST type | ||
| // (IncompleteArrayType) isn't a ConstantArrayType and isn't a resource type | ||
| // either, so the function fell through to its "unknown resource type" | ||
| // unreachable. An unbounded array must be the last resource declared in its | ||
| // register space, so nothing can collide with it regardless of how many | ||
| // slots are reserved for it -- it only reserves its own single binding | ||
| // number, same as without this flag. NextTexture (auto-assigned, no | ||
| // explicit register) is unaffected by MyTextures's position and lands on | ||
| // the first free slot, binding 0. | ||
| // CHECK: OpDecorate %MyTextures Binding 5 | ||
| // CHECK: OpDecorate %NextTexture Binding 0 | ||
| Texture2D MyTextures[] : register(t5); | ||
| Texture2D NextTexture; | ||
|
|
||
| float4 main(float2 TexCoord : TexCoord, uint index : Index) : SV_Target0 | ||
| { | ||
| return MyTextures[index].Load(int3(0, 0, 0)) + NextTexture.Load(int3(0, 0, 0)); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-fspv-flatten-resource-arraysis for when non uniform resource accesses are unsupported AFAIK, anOpSwitchwith an array element per case is generated when a non compile time constant is used.I think
-fspv-dx-resource-array-bindingwould be less "obvious" though?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about something that more explicitly describes what this does?
-fspv-reserve-resource-array-bindings?