-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[HLSL][SPIR-V] Implement vk::location for inputs #169479
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
Keenuts
wants to merge
7
commits into
llvm:main
Choose a base branch
from
Keenuts:vk-location
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.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8305fe2
[HLSL][SPIR-V] Add support for SV_Target semantic
Keenuts 2ebbc27
pr-feedback
Keenuts 9c4c26f
change language
Keenuts 24b9a4e
[HLSL][SPIR-V] Implement vk::location for inputs
Keenuts d0cfafe
pr-feedback
Keenuts 97d25e5
move state to struct
Keenuts ddf2c21
fix shader kind in CG
Keenuts 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
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
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
37 changes: 37 additions & 0 deletions
37
clang/test/CodeGenHLSL/semantics/semantic.explicit-location-output-struct.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,37 @@ | ||
| // RUN: %clang_cc1 -triple spirv-pc-vulkan1.3-pixel -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV | ||
| // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-pixel -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-DXIL | ||
|
|
||
| // CHECK-SPIRV: @SV_Position = external hidden thread_local addrspace(7) externally_initialized constant <4 x float>, !spirv.Decorations ![[#MD_0:]] | ||
| // CHECK-SPIRV: @SV_Target0 = external hidden thread_local addrspace(8) global <4 x float>, !spirv.Decorations ![[#MD_2:]] | ||
|
|
||
| struct Output { | ||
| [[vk::location(2)]] float4 field : SV_Target; | ||
| }; | ||
|
|
||
| // CHECK: define void @main() {{.*}} { | ||
| Output main(float4 p : SV_Position) { | ||
| // CHECK: %[[#OUT:]] = alloca %struct.Output, align 16 | ||
|
|
||
| // CHECK-SPIRV: %[[#IN:]] = load <4 x float>, ptr addrspace(7) @SV_Position, align 16 | ||
| // CHECK-SPIRV: call spir_func void @_Z4mainDv4_f(ptr %[[#OUT]], <4 x float> %[[#IN]]) | ||
|
|
||
| // CHECK-DXIL: call void @_Z4mainDv4_f(ptr %[[#OUT]], <4 x float> %SV_Position0) | ||
|
|
||
| // CHECK: %[[#TMP:]] = load %struct.Output, ptr %[[#OUT]], align 16 | ||
| // CHECK: %[[#FIELD:]] = extractvalue %struct.Output %[[#TMP]], 0 | ||
|
|
||
| // CHECK-SPIRV: store <4 x float> %[[#FIELD]], ptr addrspace(8) @SV_Target0, align 16 | ||
| // CHECK-DXIL: call void @llvm.dx.store.output.v4f32(i32 4, i32 0, i32 0, i8 0, i32 poison, <4 x float> %[[#FIELD]]) | ||
| Output o; | ||
| o.field = p; | ||
| return o; | ||
| } | ||
|
|
||
| // CHECK-SPIRV-DAG: ![[#MD_0]] = !{![[#MD_1:]]} | ||
| // CHECK-SPIRV-DAG: ![[#MD_1]] = !{i32 11, i32 15} | ||
| // | `-> BuiltIn 'FragCoord' | ||
| // `-> SPIR-V decoration 'BuiltIn' | ||
| // CHECK-SPIRV-DAG: ![[#MD_2]] = !{![[#MD_3:]]} | ||
| // CHECK-SPIRV-DAG: ![[#MD_3]] = !{i32 30, i32 2} | ||
| // | `-> Location index | ||
| // `-> SPIR-V decoration 'Location' |
19 changes: 19 additions & 0 deletions
19
clang/test/CodeGenHLSL/semantics/semantic.explicit-location.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,19 @@ | ||
| // RUN: %clang_cc1 -triple spirv-pc-vulkan1.3-pixel -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CHECK-SPIRV | ||
| // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-pixel -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CHECK-DXIL | ||
|
|
||
| // CHECK-SPIRV: @SV_Target0 = external hidden thread_local addrspace(8) global <4 x float>, !spirv.Decorations ![[#MD_2:]] | ||
|
|
||
| // CHECK: define void @main() {{.*}} { | ||
| [[vk::location(2)]] float4 main(float4 p : SV_Position) : SV_Target { | ||
| // CHECK-SPIRV: %[[#R:]] = call spir_func <4 x float> @_Z4mainDv4_f(<4 x float> %[[#]]) | ||
| // CHECK-SPIRV: store <4 x float> %[[#R]], ptr addrspace(8) @SV_Target0, align 16 | ||
|
|
||
| // CHECK-DXIL: %[[#TMP:]] = call <4 x float> @_Z4mainDv4_f(<4 x float> %SV_Position0) | ||
| // CHECK-DXIL: call void @llvm.dx.store.output.v4f32(i32 4, i32 0, i32 0, i8 0, i32 poison, <4 x float> %[[#TMP]]) | ||
| return p; | ||
| } | ||
|
|
||
| // CHECK-SPIRV-DAG: ![[#MD_2]] = !{![[#MD_3:]]} | ||
| // CHECK-SPIRV-DAG: ![[#MD_3]] = !{i32 30, i32 2} | ||
| // | `-> Location index | ||
| // `-> SPIR-V decoration 'Location' |
39 changes: 39 additions & 0 deletions
39
clang/test/CodeGenHLSL/semantics/semantic.explicit-mix-builtin.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,39 @@ | ||
| // RUN: %clang_cc1 -triple spirv-linux-vulkan-pixel -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV | ||
|
|
||
| // The following code is allowed because the `SV_Position` semantic is here | ||
| // translated into a SPIR-V builtin. Meaning there is no implicit `Location` | ||
| // assignment. | ||
|
|
||
| struct S2 { | ||
| float4 a; | ||
| float4 b; | ||
| }; | ||
|
|
||
| struct S1 { | ||
| float4 position : SV_Position; | ||
| [[vk::location(3)]] float4 color0 : COLOR0; | ||
| }; | ||
|
|
||
| // CHECK-SPIRV: @SV_Position = external hidden thread_local addrspace(7) externally_initialized constant <4 x float>, !spirv.Decorations ![[#MD_0:]] | ||
| // CHECK-SPIRV: @COLOR0 = external hidden thread_local addrspace(7) externally_initialized constant <4 x float>, !spirv.Decorations ![[#MD_2:]] | ||
| // CHECK-SPIRV: @SV_Target0 = external hidden thread_local addrspace(8) global <4 x float>, !spirv.Decorations ![[#MD_4:]] | ||
|
|
||
| [shader("pixel")] | ||
| float4 main(S1 p) : SV_Target { | ||
| return p.position + p.color0; | ||
| } | ||
| // CHECK-SPIRV: %[[#SV_POS:]] = load <4 x float>, ptr addrspace(7) @SV_Position, align 16 | ||
| // CHECK: %[[#TMP1:]] = insertvalue %struct.S1 poison, <4 x float> %[[#SV_POS]], 0 | ||
| // CHECK-SPIRV: %[[#A0:]] = load <4 x float>, ptr addrspace(7) @COLOR0, align 16 | ||
| // CHECK: %[[#TMP2:]] = insertvalue %struct.S1 %[[#TMP1]], <4 x float> %[[#A0]], 1 | ||
| // CHECK: %[[#P:]] = alloca %struct.S1, align 16 | ||
| // CHECK: store %struct.S1 %[[#TMP2]], ptr %[[#P]], align 16 | ||
| // CHECK-SPIRV: %[[#R:]] = call spir_func <4 x float> @_Z4main2S1(ptr %[[#P]]) | ||
| // CHECK-SPIRV: store <4 x float> %[[#R]], ptr addrspace(8) @SV_Target0, align 16 | ||
|
|
||
| // CHECK-SPIRV: ![[#MD_0]] = !{![[#MD_1:]]} | ||
| // CHECK-SPIRV: ![[#MD_1]] = !{i32 11, i32 15} | ||
| // CHECK-SPIRV: ![[#MD_2]] = !{![[#MD_3:]]} | ||
| // CHECK-SPIRV: ![[#MD_3]] = !{i32 30, i32 3} | ||
| // CHECK-SPIRV: ![[#MD_4]] = !{![[#MD_5:]]} | ||
| // CHECK-SPIRV: ![[#MD_5]] = !{i32 30, i32 0} |
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
16 changes: 16 additions & 0 deletions
16
clang/test/SemaHLSL/Semantics/semantic.explicit-mix-builtin-vs.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,16 @@ | ||
| // RUN: %clang_cc1 -triple spirv-linux-vulkan-vertex -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s -verify -verify-ignore-unexpected=note | ||
|
|
||
| // This is almost the same as semantic.explicit-mix-builtin.hlsl, except this | ||
| // time we build a vertex shader. This means the SV_Position semantic is not | ||
| // a BuiltIn anymore, but a Location decorated variable. This means we mix | ||
| // implicit and explicit location assignment. | ||
| struct S1 { | ||
| float4 position : SV_Position; | ||
| [[vk::location(3)]] float4 color : A; | ||
| // expected-error@-1 {{partial explicit stage input location assignment via vk::location(X) unsupported}} | ||
| }; | ||
|
|
||
| [shader("vertex")] | ||
| float4 main1(S1 p) : A { | ||
| return p.position + p.color; | ||
| } |
15 changes: 15 additions & 0 deletions
15
clang/test/SemaHLSL/Semantics/semantic.explicit-mix-location-2.hlsl
Keenuts marked this conversation as resolved.
Show resolved
Hide resolved
|
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,15 @@ | ||
| // RUN: %clang --driver-mode=dxc %s -T ps_6_8 -E main1 -O3 -spirv -Xclang -verify -Xclang -verify-ignore-unexpected=note | ||
|
|
||
| // The following code is not legal: both semantics A and B will be lowered | ||
| // into a Location decoration. And mixing implicit and explicit Location | ||
| // assignment is not supported. | ||
| struct S1 { | ||
| [[vk::location(3)]] float4 color : B; | ||
| float4 position : A; | ||
| // expected-error@-1 {{partial explicit stage input location assignment via vk::location(X) unsupported}} | ||
| }; | ||
|
|
||
| [shader("pixel")] | ||
| float4 main1(S1 p) : SV_Target { | ||
| return p.position + p.color; | ||
| } |
15 changes: 15 additions & 0 deletions
15
clang/test/SemaHLSL/Semantics/semantic.explicit-mix-location.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,15 @@ | ||
| // RUN: %clang --driver-mode=dxc %s -T ps_6_8 -E main1 -O3 -spirv -Xclang -verify -Xclang -verify-ignore-unexpected=note | ||
|
|
||
| // The following code is not legal: both semantics A and B will be lowered | ||
| // into a Location decoration. And mixing implicit and explicit Location | ||
| // assignment is not supported. | ||
| struct S1 { | ||
| float4 position : A; | ||
| [[vk::location(3)]] float4 color : B; | ||
| // expected-error@-1 {{partial explicit stage input location assignment via vk::location(X) unsupported}} | ||
| }; | ||
|
|
||
| [shader("pixel")] | ||
| float4 main1(S1 p) : SV_Target { | ||
| return p.position + p.color; | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.