[clang] [llvm] [HLSL] Add QuadAll Emulation support (PR #240645)
Helena Kotas via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 13 00:18:59 PST 2026
================
@@ -1000,6 +1001,37 @@ void CGHLSLRuntime::addHLSLBufferLayoutType(const RecordType *StructType,
LayoutTypes[StructType] = LayoutTy;
}
+static void addSPIRVQuadAllExecutionModes(llvm::Module &M) {
+ Function *QuadAll =
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::spv_quad_all);
+ if (!QuadAll)
+ return;
+
+ SmallVector<Function *, 8> Worklist{QuadAll};
+ SmallPtrSet<Function *, 16> Visited;
+ IRBuilder<> B(M);
+ while (!Worklist.empty()) {
+ Function *F = Worklist.pop_back_val();
+ if (!Visited.insert(F).second)
+ continue;
+
+ if (F->hasFnAttribute("hlsl.numthreads")) {
+ StringRef NumThreads =
+ F->getFnAttribute("hlsl.numthreads").getValueAsString();
+ // DerivativeGroupLinearKHR is 5290; DerivativeGroupQuadsKHR is 5289.
+ unsigned Mode = NumThreads.ends_with(",1,1") ? 5290 : 5289;
----------------
hekota wrote:
The `numthreads` values need more validation - `DerivativeGroupQuadsKHR` requires both X and Y to be even. So a shader with `[numthreads(1,4,1)]` should be rejected.
https://docs.vulkan.org/spec/latest/appendices/spirvenv.html#VUID-StandaloneSpirv-DerivativeGroupQuadsKHR-10151
https://github.com/llvm/llvm-project/pull/240645
More information about the cfe-commits
mailing list