[clang] [llvm] [HLSL] Add support for user semantics (PR #153424)
Nathan Gauër via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 30 03:10:45 PDT 2025
================
@@ -818,6 +821,33 @@ bool SemaHLSL::determineActiveSemanticOnScalar(FunctionDecl *FD,
checkSemanticAnnotation(FD, D, A);
FD->addAttr(A);
+
+ unsigned Location = ActiveSemantic.Index.value_or(0);
+
+ const ConstantArrayType *AT = dyn_cast<ConstantArrayType>(D->getType());
+ unsigned ElementCount = AT ? AT->getZExtSize() : 1;
+ ActiveSemantic.Index = Location + ElementCount;
+
+ Twine BaseName = Twine(ActiveSemantic.Semantic->getAttrName()->getName());
+ for (unsigned I = 0; I < ElementCount; ++I) {
+ Twine VariableName = BaseName.concat(Twine(Location + I));
+
+ auto It = ActiveInputSemantics.find(FD);
+ if (It == ActiveInputSemantics.end()) {
+ llvm::StringSet<> Set({VariableName.str()});
+ auto Item = std::make_pair(FD, std::move(Set));
+ ActiveInputSemantics.insert(std::move(Item));
+ continue;
+ }
+
+ auto [_, Inserted] = ActiveInputSemantics[FD].insert(VariableName.str());
----------------
Keenuts wrote:
For arrays, one variable is inserted by element (not pretty, but functional)
```
uint a[3] : A0
uint b : A1
```
The array will contain `A0, A1, A2`, thus inserting `A1` later will fail.
This means if we have a large array, we insert of lot of names, but I think that's OK since we have a limited signature space on the DXIL side.
Btw, DXC doesn't handle this correctly:
DXC would assign Location 0 to `a`, and Location 3 to `b`, ignoring the semantic index.
https://github.com/llvm/llvm-project/pull/153424
More information about the llvm-commits
mailing list