-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[SPIR-V] Support nonuniformindex
intrsinsic in SPIRV CodeGen.
#162540
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
Merged
Merged
Changes from all commits
Commits
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
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
26 changes: 26 additions & 0 deletions
26
llvm/test/CodeGen/SPIRV/hlsl-resources/NonUniformIdx/RWStructuredBufferNonUniformIdx.ll
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: llc -O0 -mtriple=spirv1.6-unknown-vulkan1.3-compute %s -o - | FileCheck %s --match-full-lines | ||
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv1.6-unknown-vulkan1.3-compute %s -o - -filetype=obj | spirv-val %} | ||
|
||
; CHECK-DAG: OpCapability Shader | ||
; CHECK-DAG: OpCapability ShaderNonUniformEXT | ||
; CHECK-DAG: OpDecorate {{%[0-9]+}} NonUniformEXT | ||
; CHECK-DAG: OpDecorate {{%[0-9]+}} NonUniformEXT | ||
; CHECK-DAG: OpDecorate {{%[0-9]+}} NonUniformEXT | ||
; CHECK-DAG: OpDecorate {{%[0-9]+}} NonUniformEXT | ||
; CHECK-DAG: OpDecorate %[[#access1:]] NonUniformEXT | ||
@ReadWriteStructuredBuf.str = private unnamed_addr constant [23 x i8] c"ReadWriteStructuredBuf\00", align 1 | ||
|
||
define void @main() local_unnamed_addr #0 { | ||
entry: | ||
%0 = tail call i32 @llvm.spv.thread.id.in.group.i32(i32 0) | ||
%add.i = add i32 %0, 1 | ||
%1 = tail call noundef i32 @llvm.spv.resource.nonuniformindex(i32 %add.i) | ||
%2 = tail call target("spirv.VulkanBuffer", [0 x <4 x i32>], 12, 1) @llvm.spv.resource.handlefromimplicitbinding.tspirv.VulkanBuffer_a0v4i32_12_1t(i32 0, i32 0, i32 64, i32 %1, ptr nonnull @ReadWriteStructuredBuf.str) | ||
%3 = tail call noundef align 16 dereferenceable(16) ptr addrspace(11) @llvm.spv.resource.getpointer.p11.tspirv.VulkanBuffer_a0v4i32_12_1t(target("spirv.VulkanBuffer", [0 x <4 x i32>], 12, 1) %2, i32 98) | ||
%4 = load <4 x i32>, ptr addrspace(11) %3, align 16 | ||
%vecins.i = insertelement <4 x i32> %4, i32 99, i64 0 | ||
; CHECK: %[[#access1]] = OpAccessChain {{.*}} | ||
; CHECK: OpStore %[[#access1]] {{%[0-9]+}} Aligned 16 | ||
store <4 x i32> %vecins.i, ptr addrspace(11) %3, align 16 | ||
ret void | ||
} |
24 changes: 24 additions & 0 deletions
24
llvm/test/CodeGen/SPIRV/hlsl-resources/NonUniformIdx/StructuredBufferNonUniformIdx.ll
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,24 @@ | ||
; RUN: llc -O0 -mtriple=spirv1.6-unknown-vulkan1.3-compute %s -o - | FileCheck %s --match-full-lines | ||
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv1.6-unknown-vulkan1.3-compute %s -o - -filetype=obj | spirv-val %} | ||
|
||
; CHECK-DAG: OpCapability Shader | ||
; CHECK-DAG: OpCapability ShaderNonUniformEXT | ||
; CHECK-DAG: OpCapability StorageTexelBufferArrayNonUniformIndexingEXT | ||
; CHECK-DAG: OpDecorate {{%[0-9]+}} NonUniformEXT | ||
; CHECK-DAG: OpDecorate %[[#access:]] NonUniformEXT | ||
; CHECK-DAG: OpDecorate %[[#load:]] NonUniformEXT | ||
@ReadWriteBuf.str = private unnamed_addr constant [13 x i8] c"ReadWriteBuf\00", align 1 | ||
|
||
define void @main() local_unnamed_addr #0 { | ||
entry: | ||
%0 = tail call i32 @llvm.spv.thread.id.in.group.i32(i32 0) | ||
%1 = tail call noundef i32 @llvm.spv.resource.nonuniformindex(i32 %0) | ||
%2 = tail call target("spirv.Image", i32, 5, 2, 0, 0, 2, 33) @llvm.spv.resource.handlefromimplicitbinding.tspirv.Image_i32_5_2_0_0_2_33t(i32 0, i32 0, i32 64, i32 %1, ptr nonnull @ReadWriteBuf.str) | ||
%3 = tail call noundef align 4 dereferenceable(4) ptr addrspace(11) @llvm.spv.resource.getpointer.p11.tspirv.Image_i32_5_2_0_0_2_33t(target("spirv.Image", i32, 5, 2, 0, 0, 2, 33) %2, i32 96) | ||
; CHECK: {{%[0-9]+}} = OpCompositeExtract {{.*}} | ||
; CHECK: %[[#access]] = OpAccessChain {{.*}} | ||
; CHECK: %[[#load]] = OpLoad {{%[0-9]+}} %[[#access]] | ||
; CHECK: OpImageWrite %[[#load]] {{%[0-9]+}} {{%[0-9]+}} | ||
store i32 95, ptr addrspace(11) %3, align 4 | ||
ret void | ||
} |
56 changes: 0 additions & 56 deletions
56
llvm/test/CodeGen/SPIRV/hlsl-resources/StorageImageNonUniformIdx.ll
This file was deleted.
Oops, something went wrong.
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.
You changed this test from a non uniform index into an array of storage images (RWBuffer) into an array of storage buffer (RWStructuredBuffers). Can you look at the full set of tests that we will need? See #122355.
You cannot generate all of these from HLSL yet. For now add that can be generated from HLSL. Look at the tables in https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#textures and https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#constanttexturestructuredbyte-buffers to see the links between HLSL type and the Vulkan type.
Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks for pointing out!
Based on our discussion
RWStructuredBuffer
andRWBuffer
.RWStructuredBuffer
should haveStorageBufferArrayNonUniformIndexing
extension added (both in dxc and llvm)Buffer
doesn't pass spirv-val, we need to replaceOpTypeImageRead
withOpTypeImageFetch
.