gallium: refactor a channel loop in draw_llvm.c
authorMihai Preda <mhpreda@gmail.com>
Wed, 20 Apr 2022 11:30:30 +0000 (14:30 +0300)
committerMihai Preda <42345-preda@users.noreply.gitlab.freedesktop.org>
Wed, 4 May 2022 20:00:33 +0000 (20:00 +0000)
Acked-by: Marek Olšák <marek.olsak@amd.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893>

src/gallium/auxiliary/draw/draw_llvm.c

index 1f68170..ee4ff81 100644 (file)
@@ -1651,29 +1651,19 @@ generate_clipmask(struct draw_llvm *llvm,
             indices[0] = lp_build_const_int32(gallivm, 0);
             indices[1] = lp_build_const_int32(gallivm, plane_idx);
 
-            indices[2] = lp_build_const_int32(gallivm, 0);
-            plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, "");
-            plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr, "plane_x");
-            planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1);
-            sum = LLVMBuildFMul(builder, planes, cv_x, "");
-
-            indices[2] = lp_build_const_int32(gallivm, 1);
-            plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, "");
-            plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr, "plane_y");
-            planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1);
-            sum = lp_build_fmuladd(builder, planes, cv_y, sum);
-
-            indices[2] = lp_build_const_int32(gallivm, 2);
-            plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, "");
-            plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr, "plane_z");
-            planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1);
-            sum = lp_build_fmuladd(builder, planes, cv_z, sum);
-
-            indices[2] = lp_build_const_int32(gallivm, 3);
-            plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, "");
-            plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr, "plane_w");
-            planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1);
-            sum = lp_build_fmuladd(builder, planes, cv_w, sum);
+            for (int i = 0; i < 4; ++i) {
+               indices[2] = lp_build_const_int32(gallivm, i);
+               plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, "");
+               plane1 = LLVMBuildLoad2(builder, vs_elem_type, plane_ptr,
+                                       (const char *[]){"plane_x", "plane_y", "plane_z", "plane_w"}[i]);
+               planes = lp_build_broadcast(gallivm, vs_type_llvm, plane1);
+               if (i == 0) {
+                  sum = LLVMBuildFMul(builder, planes, cv_x, "");
+               } else {
+                  sum = lp_build_fmuladd(builder, planes,
+                                         (LLVMValueRef[]){cv_x, cv_y, cv_z, cv_w}[i], sum);
+               }
+            }
 
             test = lp_build_compare(gallivm, f32_type, PIPE_FUNC_GREATER, zero, sum);
             temp = lp_build_const_int_vec(gallivm, i32_type, 1LL << plane_idx);