-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPIR-V] Implement vk::ext_builtin_input and vk::ext_builtin_output (#…
…6027) I definitely think it would look better if we allowed these attributes on variables, ie microsoft/hlsl-specs#76. I haven't fully investigated how involved it would be to implement, but my intuition is that it wouldn't take that much more work. Fixes #4217.
- Loading branch information
1 parent
a743e97
commit 9dacbe3
Showing
13 changed files
with
256 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
9 changes: 9 additions & 0 deletions
9
tools/clang/test/CodeGenSPIRV/spv.inline.builtin.both.error.hlsl
This file contains 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,9 @@ | ||
// RUN: not %dxc -T ps_6_0 -E main -fcgl %s -spirv 2>&1 | FileCheck %s | ||
|
||
// CHECK: error: vk::ext_builtin_input cannot be used together with vk::ext_builtin_output | ||
[[vk::ext_builtin_input(/* NumWorkgroups */ 24)]] | ||
[[vk::ext_builtin_output(/* NumWorkgroups */ 24)]] | ||
static uint3 invalid; | ||
|
||
void main() { | ||
} |
15 changes: 15 additions & 0 deletions
15
tools/clang/test/CodeGenSPIRV/spv.inline.builtin.input.flat.hlsl
This file contains 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: %dxc -T ps_6_0 -E main -fcgl %s -spirv | FileCheck %s | ||
|
||
// CHECK: OpEntryPoint Fragment %main "main" %gl_SampleID | ||
// CHECK: OpDecorate %gl_SampleID BuiltIn SampleId | ||
// CHECK: OpDecorate %gl_SampleID Flat | ||
|
||
// CHECK: %gl_SampleID = OpVariable %_ptr_Input_int Input | ||
|
||
[[vk::ext_builtin_input(/* SampleID */ 18)]] | ||
static const int gl_SampleID; | ||
|
||
void main() { | ||
// CHECK: {{%[0-9]+}} = OpLoad %int %gl_SampleID | ||
int sID = gl_SampleID; | ||
} |
23 changes: 23 additions & 0 deletions
23
tools/clang/test/CodeGenSPIRV/spv.inline.builtin.input.hlsl
This file contains 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,23 @@ | ||
// RUN: %dxc -T cs_6_0 -E main -fcgl %s -spirv | FileCheck %s | ||
|
||
// CHECK: OpEntryPoint GLCompute %main "main" %gl_NumWorkGroups | ||
// CHECK: OpDecorate %gl_NumWorkGroups BuiltIn NumWorkgroups | ||
|
||
// CHECK: %gl_NumWorkGroups = OpVariable %_ptr_Input_v3uint Input | ||
|
||
[[vk::ext_builtin_input(/* NumWorkgroups */ 24)]] | ||
static const uint3 gl_NumWorkGroups; | ||
|
||
uint square_x(uint3 v) { | ||
return v.x * v.x; | ||
} | ||
|
||
[numthreads(32,1,1)] | ||
void main() { | ||
// CHECK: {{%[0-9]+}} = OpLoad %v3uint %gl_NumWorkGroups | ||
uint3 numWorkgroups = gl_NumWorkGroups; | ||
// CHECK: [[nwg:%[0-9]+]] = OpLoad %v3uint %gl_NumWorkGroups | ||
// CHECK: OpStore %param_var_v [[nwg]] | ||
// CHECK: OpFunctionCall %uint %square_x %param_var_v | ||
square_x(gl_NumWorkGroups); | ||
} |
8 changes: 8 additions & 0 deletions
8
tools/clang/test/CodeGenSPIRV/spv.inline.builtin.input.nonconst.hlsl
This file contains 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,8 @@ | ||
// RUN: not %dxc -T ps_6_0 -E main -fcgl %s -spirv 2>&1 | FileCheck %s | ||
|
||
// CHECK: error: vk::ext_builtin_input can only be applied to a const-qualified variable | ||
[[vk::ext_builtin_input(/* NumWorkgroups */ 24)]] | ||
static uint3 invalid; | ||
|
||
void main() { | ||
} |
8 changes: 8 additions & 0 deletions
8
tools/clang/test/CodeGenSPIRV/spv.inline.builtin.input.nonstatic.error.hlsl
This file contains 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,8 @@ | ||
// RUN: not %dxc -T ps_6_0 -E main -fcgl %s -spirv 2>&1 | FileCheck %s | ||
|
||
// CHECK: error: vk::ext_builtin_input and vk::ext_builtin_output can only be applied to a static variable | ||
[[vk::ext_builtin_input(/* NumWorkgroups */ 24)]] | ||
uint3 invalid; | ||
|
||
void main() { | ||
} |
22 changes: 22 additions & 0 deletions
22
tools/clang/test/CodeGenSPIRV/spv.inline.builtin.output.hlsl
This file contains 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,22 @@ | ||
// RUN: %dxc -T ps_6_0 -E main -fcgl %s -spirv | FileCheck %s | ||
|
||
// CHECK: OpEntryPoint Fragment %main "main" [[fragStencilVar:%[0-9]+]] | ||
// CHECK: OpDecorate [[fragStencilVar]] BuiltIn FragStencilRefEXT | ||
|
||
// CHECK: [[fragStencilVar]] = OpVariable %_ptr_Output_int Output | ||
|
||
[[vk::ext_extension("SPV_EXT_shader_stencil_export")]] | ||
[[vk::ext_builtin_output(/* FragStencilRefEXT */ 5014)]] | ||
static int gl_FragStencilRefARB; | ||
|
||
void assign(out int val) { | ||
val = 123; | ||
} | ||
|
||
void main() { | ||
// CHECK: OpStore [[fragStencilVar]] %int_10 | ||
gl_FragStencilRefARB = 10; | ||
|
||
// CHECK: OpFunctionCall %void %assign [[fragStencilVar]] | ||
assign(gl_FragStencilRefARB); | ||
} |
8 changes: 8 additions & 0 deletions
8
tools/clang/test/CodeGenSPIRV/spv.inline.builtin.output.nonstatic.error.hlsl
This file contains 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,8 @@ | ||
// RUN: not %dxc -T ps_6_0 -E main -fcgl %s -spirv 2>&1 | FileCheck %s | ||
|
||
// CHECK: error: vk::ext_builtin_input and vk::ext_builtin_output can only be applied to a static variable | ||
[[vk::ext_builtin_output(/* NumWorkgroups */ 24)]] | ||
uint3 invalid; | ||
|
||
void main() { | ||
} |
12 changes: 12 additions & 0 deletions
12
tools/clang/test/CodeGenSPIRV/spv.inline.builtin.redefine.error.hlsl
This file contains 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,12 @@ | ||
// RUN: not %dxc -T ps_6_0 -E main -fcgl %s -spirv 2>&1 | FileCheck %s | ||
|
||
[[vk::ext_builtin_input(/* NumWorkgroups */ 24)]] | ||
static const uint3 gl_NumWorkGroups; | ||
|
||
// CHECK: error: cannot redefine builtin 24 as an output | ||
// CHECK: warning: previous definition is here | ||
[[vk::ext_builtin_output(/* NumWorkgroups */ 24)]] | ||
static uint3 invalid; | ||
|
||
void main() { | ||
} |