Module: Mesa
Branch: main
Commit: f33399aa9e9cd284b0810c5eefd0f9f45330ed43
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=f33399aa9e9cd284b0810c5eefd0f9f45330ed43

Author: Mike Blumenkrantz <[email protected]>
Date:   Fri Mar 11 11:10:56 2022 -0500

llvmpipe: fix gl_NumSubgroups

this is (x * y * z) / subgroup_size, not num_x_loops

Reviewed-by: Dave Airlie <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15354>

---

 src/gallium/drivers/llvmpipe/lp_state_cs.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.c 
b/src/gallium/drivers/llvmpipe/lp_state_cs.c
index 5109d15a257..61213175f67 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_cs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_cs.c
@@ -373,8 +373,12 @@ generate_compute(struct llvmpipe_context *lp,
       system_values.work_dim = work_dim_arg;
 
       system_values.subgroup_id = coro_idx;
-      system_values.num_subgroups = LLVMBuildMul(builder, num_x_loop,
-                                                 LLVMBuildMul(builder, 
block_y_size_arg, block_z_size_arg, ""), "");
+      LLVMValueRef num_subgroups = LLVMBuildUDiv(builder,
+                                                 LLVMBuildMul(builder, 
block_x_size_arg,
+                                                              
LLVMBuildMul(builder, block_y_size_arg, block_z_size_arg, ""), ""),
+                                                 vec_length, "");
+      LLVMValueRef subgroup_cmp = LLVMBuildICmp(gallivm->builder, LLVMIntEQ, 
num_subgroups, lp_build_const_int32(gallivm, 0), "");
+      system_values.num_subgroups = LLVMBuildSelect(builder, subgroup_cmp, 
lp_build_const_int32(gallivm, 1), num_subgroups, "");
 
       LLVMValueRef bsize[3] = { block_x_size_arg, block_y_size_arg, 
block_z_size_arg };
       system_values.block_size = LLVMGetUndef(LLVMVectorType(int32_type, 3));

Reply via email to