[clang] [llvm] [HLSL] Add QuadAll Emulation support (PR #240645)
Deric C. via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 13 14:53:08 PST 2026
================
@@ -1018,11 +1024,28 @@ static void addSPIRVQuadAllExecutionModes(llvm::Module &M) {
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;
+ SmallVector<StringRef, 3> Dimensions;
+ NumThreads.split(Dimensions, ',');
+ assert(Dimensions.size() == 3 && "expected three numthreads dimensions");
+ std::array<uint32_t, 3> Threads;
+ for (auto [Dimension, Thread] : llvm::zip(Dimensions, Threads)) {
+ [[maybe_unused]] bool Invalid = Dimension.getAsInteger(10, Thread);
+ assert(!Invalid && "expected an integer numthreads dimension");
+ }
+ bool IsLinear = Threads[1] == 1 && Threads[2] == 1;
+ if (IsLinear ? (uint64_t(Threads[0]) * Threads[1] * Threads[2]) % 4 != 0
+ : Threads[0] % 2 != 0 || Threads[1] % 2 != 0) {
+ CGM.getDiags().Report(diag::err_hlsl_spirv_quad_all_numthreads)
+ << F->getName() << IsLinear;
+ continue;
+ }
+ SPIRVExecutionMode Mode =
+ IsLinear ? SPIRVExecutionMode::DerivativeGroupLinearKHR
+ : SPIRVExecutionMode::DerivativeGroupQuadsKHR;
----------------
Icohedron wrote:
I think this logic should be separated into its own helper function rather than being specific to `addSPIRVQuadAllExecutionModes`
https://github.com/llvm/llvm-project/pull/240645
More information about the cfe-commits
mailing list