-
Notifications
You must be signed in to change notification settings - Fork 887
[SPIR-V] Honor inline spir-v attributes on functions #8616
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1949,6 +1949,16 @@ void SpirvBuilder::decorateWithLiterals(SpirvInstruction *targetInst, | |
| mod->addDecoration(decor); | ||
| } | ||
|
|
||
| void SpirvBuilder::decorateWithLiterals(SpirvFunction *targetFunc, | ||
| unsigned decorate, | ||
| llvm::ArrayRef<unsigned> literals, | ||
| SourceLocation srcLoc) { | ||
| SpirvDecoration *decor = new (context) SpirvDecoration( | ||
| srcLoc, targetFunc, static_cast<spv::Decoration>(decorate), literals); | ||
| assert(decor != nullptr); | ||
| mod->addDecoration(decor); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The second
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. Fixed, and added a second function in the test to demonstrate. |
||
|
|
||
| void SpirvBuilder::decorateWithIds(SpirvInstruction *targetInst, | ||
| unsigned decorate, | ||
| llvm::ArrayRef<SpirvInstruction *> ids, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // RUN: not %dxc -T cs_6_0 -E main -fcgl %s -spirv 2>&1 | FileCheck %s | ||
|
|
||
| // vk::ext_decorate_id and vk::ext_decorate_string decorate a value-id target | ||
| // and have no OpFunction-target form, so applying either to a function must be | ||
| // diagnosed rather than silently dropped. | ||
|
|
||
| // CHECK: error: vk::ext_decorate_string is not supported on functions | ||
| [[vk::ext_decorate_string(/* UserTypeGOOGLE */ 5636, "myType")]] | ||
| [noinline] uint DecorateString(uint x) { return x; } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a second function that exercises
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I called it |
||
| // CHECK: error: vk::ext_decorate_id is not supported on functions | ||
| [[vk::ext_decorate_id(/* UniformId */ 27, 13)]] | ||
| [noinline] uint DecorateId(uint x) { return x; } | ||
|
|
||
| RWStructuredBuffer<uint> buf; | ||
|
|
||
| [numthreads(1, 1, 1)] | ||
| void main(uint3 tid : SV_DispatchThreadID) { | ||
| buf[0] = DecorateString(tid.x) + DecorateId(tid.x); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // RUN: %dxc -T cs_6_0 -E main -fcgl %s -spirv | FileCheck %s | ||
|
|
||
| // Inline-SPIR-V attributes placed directly on a function must be honored: | ||
| // vk::ext_decorate emits an OpDecorate targeting the OpFunction, and | ||
| // vk::ext_capability / vk::ext_extension add the capability / extension to the | ||
| // module. Known SPIR-V enums are used here so the module still validates; the | ||
| // mechanism is identical for vendor-specific decoration numbers. | ||
|
|
||
| // CHECK-DAG: OpCapability Int8 | ||
| // CHECK-DAG: OpExtension "some_extension" | ||
|
|
||
| [[vk::ext_capability(/* Int8 */ 39)]] | ||
| [[vk::ext_extension("some_extension")]] | ||
| [[vk::ext_decorate(/* RelaxedPrecision */ 0)]] | ||
| [noinline] uint Identity(uint x) { return x; } | ||
|
|
||
| // Decorate a second function to test the hashing in the module's decoration set. | ||
| [[vk::ext_decorate(/* RelaxedPrecision */ 0)]] | ||
| [noinline] uint Increment(uint x) { return x + 1; } | ||
|
|
||
| // CHECK-DAG: OpDecorate %Identity RelaxedPrecision | ||
| // CHECK-DAG: OpDecorate %Increment RelaxedPrecision | ||
|
|
||
| // CHECK-DAG: %Identity = OpFunction %uint DontInline | ||
| // CHECK-DAG: %Increment = OpFunction %uint DontInline | ||
|
|
||
| RWStructuredBuffer<uint> buf; | ||
|
|
||
| [numthreads(1, 1, 1)] | ||
| void main(uint3 tid : SV_DispatchThreadID) { | ||
| buf[0] = Identity(tid.x) + Increment(tid.x); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.