Skip to content

Allows Vulkan spec constants as attribute arguments. #7439

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
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

danbrown-amd
Copy link
Contributor

@danbrown-amd danbrown-amd commented May 8, 2025

Fixes #3092

Copy link
Contributor

github-actions bot commented May 8, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@danbrown-amd danbrown-amd force-pushed the attr-arg-consts branch 3 times, most recently from 9db3b6c to 243acbc Compare May 13, 2025 22:08
Copy link
Collaborator

@s-perron s-perron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind this change generally. It will be good for SPIR-V.

I don't know if this is complete yet (it is still a draft). I pointed out one issue with using LocalSize. You might also need to look at SpirvEmitter::addDerivativeGroupExecutionMode(). That function determines which derivative group execution mode to add based on the number of threas in the group. However, if you have a spec constant for the number of threads, we cannot do that.

@danbrown-amd danbrown-amd force-pushed the attr-arg-consts branch 2 times, most recently from 58352af to 357813d Compare June 12, 2025 02:30
@danbrown-amd
Copy link
Contributor Author

danbrown-amd commented Jun 17, 2025

Why was SpirvEmitter::addDerivativeGroupExecutionMode() written that way? It seems to me that it wouldn't be that difficult to provide enough context to find the original attribute in the AST so the method wouldn't need to scan the previously emitted instructions.

Of course, since there's no access to specializations at compile time, there's no way to ensure the best choice of execution mode with spec constants anyway. However, in some cases partial information would be sufficient to rule out one of them. If both are possible, maybe pick one and issue a warning?

@danbrown-amd danbrown-amd marked this pull request as ready for review June 19, 2025 18:27
@danbrown-amd danbrown-amd changed the title Allows defined constants as attribute arguments. Allows Vulkan spec constants as attribute arguments. Jun 26, 2025
@s-perron
Copy link
Collaborator

s-perron commented Jul 7, 2025

Why was SpirvEmitter::addDerivativeGroupExecutionMode() written that way?

It was implemented that way because that was the HLSL spec implemented for DXIL. See Thread Groups and Quads. I don't mind if we diverge from it when there are specialization constants. We just need to document it.

If both are possible, maybe pick one and issue a warning?

That is a reasonable idea. Longer term, we could try to add explicit attribute that apply to the entry point that would override the guess.

Copy link
Collaborator

@s-perron s-perron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but requires some tests.

Also restores file inadvertently committed source file changed for debugging.
Comment on lines +4 to +5
// Note: validation disabled until NodePayloadAMDX pointers are allowed
// as function arguments
Copy link
Collaborator

@s-perron s-perron Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these comments be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that's still the case.

Comment on lines +7 to +10
// CHECK-LINEAR: OpCapability ComputeDerivativeGroupLinearKHR
// CHECK-LINEAR: OpExecutionMode %{{[^ ]*}} DerivativeGroupLinearKHR
// CHECK-QUADS: OpCapability ComputeDerivativeGroupQuadsKHR
// CHECK-QUADS: OpExecutionMode %{{[^ ]*}} DerivativeGroupQuadsKHR
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we are making a guess based on the default values of the spec constants. That seems reasonable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I don't see a better way. I should probably add a warning that the determination may not be optimal if there are spec constants for NumThreads.

@s-perron s-perron requested a review from llvm-beanz July 11, 2025 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

[SPIR-V] Allow thread group size to be specified with specialization constants
2 participants