-
Notifications
You must be signed in to change notification settings - Fork 25
[VULKAN] Add support for specialization constants #499
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
s-perron
wants to merge
6
commits into
llvm:main
Choose a base branch
from
s-perron:spec_const
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
6 commits
Select commit
Hold shift + click to select a range
754ca1f
[VULKAN] Add support for specialization constants
s-perron daae43b
Add error for invalid strings
s-perron 1d12749
Add test for multiple spec constants in the HLSL.
s-perron ed1f8ed
Add error if the same spec id is defined twice.
s-perron 3809f85
Merge branch 'main' into spec_const
s-perron 880ae6a
XFAIL tests with short and double.
s-perron 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
87 changes: 87 additions & 0 deletions
87
test/Feature/SpecializationConstant/spec_const_32_bits.test
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,87 @@ | ||
| #--- simple.hlsl | ||
s-perron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // bool | ||
| [[vk::constant_id(0)]] | ||
| const bool spec_bool = false; | ||
| RWBuffer<uint> OutBool : register(u0, space0); | ||
|
|
||
| // int | ||
| [[vk::constant_id(1)]] | ||
| const int spec_int = 0; | ||
| RWBuffer<int> OutInt : register(u1, space0); | ||
|
|
||
| // unsigned int | ||
| [[vk::constant_id(2)]] | ||
| const uint spec_uint = 0; | ||
| RWBuffer<uint> OutUInt : register(u2, space0); | ||
|
|
||
| // float | ||
| [[vk::constant_id(3)]] | ||
| const float spec_float = 0.0; | ||
| RWBuffer<float> OutFloat : register(u3, space0); | ||
|
|
||
| // int with default value | ||
| [[vk::constant_id(4)]] | ||
| const int spec_int_default = 1234; | ||
| RWBuffer<int> OutIntDefault : register(u4, space0); | ||
|
|
||
| [numthreads(1,1,1)] | ||
| void main(uint GI : SV_GroupIndex) { | ||
| OutBool[GI] = (uint)spec_bool; | ||
| OutInt[GI] = spec_int; | ||
| OutUInt[GI] = spec_uint; | ||
| OutFloat[GI] = spec_float; | ||
| OutIntDefault[GI] = spec_int_default; | ||
| } | ||
| #--- simple.yaml | ||
| --- | ||
| Shaders: | ||
| - Stage: Compute | ||
| Entry: main | ||
| DispatchSize: [1, 1, 1] | ||
| SpecializationConstants: | ||
| - { ConstantID: 0, Value: 1, Type: Bool } | ||
| - { ConstantID: 1, Value: 42, Type: Int32 } | ||
| - { ConstantID: 2, Value: 0xDEADBEEF, Type: UInt32 } | ||
| - { ConstantID: 3, Value: 3.14, Type: Float32 } | ||
| Buffers: | ||
| - { Name: OutBool, Format: Int32, FillSize: 4 } | ||
| - { Name: OutInt, Format: Int32, FillSize: 4 } | ||
| - { Name: OutUInt, Format: UInt32, FillSize: 4 } | ||
| - { Name: OutFloat, Format: Float32, FillSize: 4 } | ||
| - { Name: OutIntDefault, Format: Int32, FillSize: 4 } | ||
| DescriptorSets: | ||
| - Resources: | ||
| - Name: OutBool | ||
| Kind: RWBuffer | ||
| DirectXBinding: { Register: 0, Space: 0 } | ||
| VulkanBinding: { Binding: 0 } | ||
| - Name: OutInt | ||
| Kind: RWBuffer | ||
| DirectXBinding: { Register: 1, Space: 0 } | ||
| VulkanBinding: { Binding: 1 } | ||
| - Name: OutUInt | ||
| Kind: RWBuffer | ||
| DirectXBinding: { Register: 2, Space: 0 } | ||
| VulkanBinding: { Binding: 2 } | ||
| - Name: OutFloat | ||
| Kind: RWBuffer | ||
| DirectXBinding: { Register: 3, Space: 0 } | ||
| VulkanBinding: { Binding: 3 } | ||
| - Name: OutIntDefault | ||
| Kind: RWBuffer | ||
| DirectXBinding: { Register: 4, Space: 0 } | ||
| VulkanBinding: { Binding: 4 } | ||
| ... | ||
| #--- end | ||
|
|
||
| # REQUIRES: Vulkan | ||
|
|
||
| # RUN: split-file %s %t | ||
| # RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/simple.hlsl | ||
| # RUN: %offloader %t/simple.yaml %t.o | FileCheck %s | ||
|
|
||
| # CHECK: Data: [ 1 ] | ||
| # CHECK: Data: [ 42 ] | ||
| # CHECK: Data: [ 3735928559 ] | ||
| # CHECK: Data: [ {{3.14.*}} ] | ||
| # CHECK: Data: [ 1234 ] | ||
64 changes: 64 additions & 0 deletions
64
test/Feature/SpecializationConstant/spec_const_other_sizes.test
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,64 @@ | ||
| #--- simple_64bit.hlsl | ||
| // double | ||
| [[vk::constant_id(0)]] | ||
| const double spec_double = 0.0; | ||
| RWStructuredBuffer<double> OutDouble : register(u0, space0); | ||
|
|
||
| // short | ||
| [[vk::constant_id(1)]] | ||
| const int16_t spec_short = 0; | ||
| RWStructuredBuffer<int16_t> OutShort : register(u1, space0); | ||
|
|
||
| // ushort | ||
| [[vk::constant_id(2)]] | ||
| const uint16_t spec_ushort = 0; | ||
| RWStructuredBuffer<uint16_t> OutUShort : register(u2, space0); | ||
|
|
||
| [numthreads(1,1,1)] | ||
| void main(uint GI : SV_GroupIndex) { | ||
| OutDouble[GI] = spec_double; | ||
| OutShort[GI] = spec_short; | ||
| OutUShort[GI] = spec_ushort; | ||
| } | ||
| #--- simple_64bit.yaml | ||
| --- | ||
| Shaders: | ||
| - Stage: Compute | ||
| Entry: main | ||
| DispatchSize: [1, 1, 1] | ||
| SpecializationConstants: | ||
| - { ConstantID: 0, Value: 2.718, Type: Float64 } | ||
| - { ConstantID: 1, Value: 123, Type: Int16 } | ||
| - { ConstantID: 2, Value: 456, Type: UInt16 } | ||
| Buffers: | ||
| - { Name: OutDouble, Format: Float64, Stride: 8, FillSize: 8 } | ||
| - { Name: OutShort, Format: Int16, Stride: 2, FillSize: 2 } | ||
| - { Name: OutUShort, Format: UInt16, Stride: 2, FillSize: 2 } | ||
| DescriptorSets: | ||
| - Resources: | ||
| - Name: OutDouble | ||
| Kind: RWStructuredBuffer | ||
| DirectXBinding: { Register: 0, Space: 0 } | ||
| VulkanBinding: { Binding: 0 } | ||
| - Name: OutShort | ||
| Kind: RWStructuredBuffer | ||
| DirectXBinding: { Register: 1, Space: 0 } | ||
| VulkanBinding: { Binding: 1 } | ||
| - Name: OutUShort | ||
| Kind: RWStructuredBuffer | ||
| DirectXBinding: { Register: 2, Space: 0 } | ||
| VulkanBinding: { Binding: 2 } | ||
| ... | ||
| #--- end | ||
|
|
||
| # REQUIRES: Vulkan | ||
|
|
||
| # XFAIL: DXC | ||
|
|
||
| # RUN: split-file %s %t | ||
| # RUN: %dxc_target -T cs_6_2 -enable-16bit-types -Fo %t.o %t/simple_64bit.hlsl | ||
| # RUN: %offloader %t/simple_64bit.yaml %t.o | FileCheck %s | ||
|
|
||
| # CHECK: Data: [ {{2.718}} ] | ||
| # CHECK: Data: [ 123 ] | ||
| # CHECK: Data: [ 456 ] |
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.
Uh oh!
There was an error while loading. Please reload this page.