Skip to content

Conversation

Keenuts
Copy link
Collaborator

@Keenuts Keenuts commented Jun 18, 2025

This is another proposal on how to implement semantic input in Clang, given DXIL & SPIR-V have drasticly different handlings, but some parts could be shared.

The POC for this implementation is in llvm/llvm-project#149363

Another proposal exists: #112 which also suggest a sema change.

HLSLAnnotationAttr *Semantic;

// Info about this field/scalar.
DeclaratorDecl *Decl;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This would be useful to handle the [[vk::location(X)]] attribute. Would be handled later, on top of this.

@Keenuts
Copy link
Collaborator Author

Keenuts commented Jul 2, 2025

Thanks for the review!
I've rewritten the entire proposal to handle both input and outputs, and I also created a branch which implements input & output semantics for HLSL:
https://github.com/Keenuts/llvm-project/tree/hlsl-semantics

@Keenuts Keenuts changed the title Proposal for input semantics Proposal for shader semantics Jul 9, 2025
Copy link
Collaborator

@tex3d tex3d left a comment

Choose a reason for hiding this comment

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

Partial review of comments, thanks for all this work!

@Keenuts
Copy link
Collaborator Author

Keenuts commented Jul 18, 2025

Thanks, rephrased mostly as suggested, reorganized a bit and added more intermediate examples, should be clearer

Copy link
Collaborator

@llvm-beanz llvm-beanz left a comment

Choose a reason for hiding this comment

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

A couple comments, but I think this looks like a good direction to me.

It is also possible to explicitly set the index, using the
`[[vk::location(/* Index */)]]` attribute. \
Mixing implicit and explicit location assignment is **not legal**.
Hence interaction between both mechanism is out of scope.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to have Clang generate the HlslSemanticGOOGLE decorations?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think we need to implement this for now, but we might want to look into reflection helpers like HLSLSemantic or HLSLCounter decorations in the future.

@s-perron s-perron self-requested a review July 30, 2025 14:38
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.

Just one more case to consider for SPIR-V. That can be in a follow up PR. It will not affect the design dramatically, if at all.

Comment on lines 236 to 242
In the example above, there are no system semantics, meaning every
parameter would get a `Location` decorated variable associated.
Each scalar field/parameter is associated with a unique index starting at 0,
from the first parameter's field to the last parameter's field.
Each scalar takes one index, and arrays of size N takes N indices.
The semantic index does not impact the Location assignment.
Indices are independent between `Input` and `Output` semantics.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor issue that we can fix up in a follow up PR.

How will locations be assigned in libraries with multiple shaders? I think we should restart at 0 for each shader, but I'm not sure that DXC does that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From what I see, DXC assigned no Location at all when targeting library, and this causes validation issues.
See https://godbolt.org/z/jbf9zz5sE
I also think this should be thought more once we have a plan for libraries (same with decorations, capabilities, etc, multiple shaders in 1 spir-v module is a bit special)

@Keenuts
Copy link
Collaborator Author

Keenuts commented Jul 31, 2025

Thanks all for the review!

@Keenuts Keenuts changed the title Proposal for shader semantics [0028] Proposal for shader semantics Jul 31, 2025
Keenuts added 8 commits July 31, 2025 13:51
This is another proposal on how to implement semantic input in Clang,
given DXIL & SPIR-V have drasticly different handlings, but some parts
could be shared.

Another proposal exists: llvm#112 which also suggest a sema change.
@Keenuts Keenuts changed the title [0028] Proposal for shader semantics [0031] Proposal for shader semantics Jul 31, 2025
@Keenuts Keenuts merged commit 43410e0 into llvm:main Jul 31, 2025
@Keenuts Keenuts deleted the input-semantics branch July 31, 2025 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants