llvmpipe: make sample position a global array.
authorDave Airlie <airlied@redhat.com>
Thu, 7 May 2020 00:04:16 +0000 (10:04 +1000)
committerMarge Bot <eric+marge@anholt.net>
Thu, 7 May 2020 18:38:51 +0000 (18:38 +0000)
I messed this up and LLVM asserts on it.

Use the gallivm struct wrappers to make it clearer.

Closes: https://gitlab.freedesktop.org/mesa/mesa/issues/2913

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Tested-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4933>

src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c
src/gallium/drivers/llvmpipe/lp_bld_interp.c
src/gallium/drivers/llvmpipe/lp_state_fs.c

index 3ae3323..0196b34 100644 (file)
@@ -1382,8 +1382,8 @@ static void emit_sysval_intrin(struct lp_build_nir_context *bld_base,
       for (unsigned i = 0; i < 2; i++) {
          LLVMValueRef idx = LLVMBuildMul(gallivm->builder, bld->system_values.sample_id, lp_build_const_int32(gallivm, 2), "");
          idx = LLVMBuildAdd(gallivm->builder, idx, lp_build_const_int32(gallivm, i), "");
-         LLVMValueRef val = LLVMBuildGEP(gallivm->builder, bld->system_values.sample_pos, &idx, 1, "");
-         result[i] = lp_build_broadcast_scalar(&bld_base->base, LLVMBuildLoad(gallivm->builder, val, ""));
+         LLVMValueRef val = lp_build_array_get(gallivm, bld->system_values.sample_pos, idx);
+         result[i] = lp_build_broadcast_scalar(&bld_base->base, val);
       }
       break;
    }
index bd6bce7..6f40d85 100644 (file)
@@ -317,10 +317,10 @@ attribs_update_simple(struct lp_build_interp_soa_context *bld,
                         LLVMValueRef x_val_idx = LLVMBuildMul(gallivm->builder, sample_id, lp_build_const_int32(gallivm, 2), "");
                         LLVMValueRef y_val_idx = LLVMBuildAdd(gallivm->builder, x_val_idx, lp_build_const_int32(gallivm, 1), "");
 
-                        x_val_idx = LLVMBuildGEP(builder, bld->sample_pos_array, &x_val_idx, 1, "");
-                        y_val_idx = LLVMBuildGEP(builder, bld->sample_pos_array, &y_val_idx, 1, "");
-                        xoffset = lp_build_broadcast_scalar(coeff_bld, LLVMBuildLoad(builder, x_val_idx, ""));
-                        yoffset = lp_build_broadcast_scalar(coeff_bld, LLVMBuildLoad(builder, y_val_idx, ""));
+                        x_val_idx = lp_build_array_get(gallivm, bld->sample_pos_array, x_val_idx);
+                        y_val_idx = lp_build_array_get(gallivm, bld->sample_pos_array, y_val_idx);
+                        xoffset = lp_build_broadcast_scalar(coeff_bld, x_val_idx);
+                        yoffset = lp_build_broadcast_scalar(coeff_bld, y_val_idx);
                      } else if (loc == TGSI_INTERPOLATE_LOC_CENTROID) {
                         LLVMValueRef centroid_x_offset = lp_build_const_vec(gallivm, coeff_bld->type, bld->pos_offset);
                         LLVMValueRef centroid_y_offset = lp_build_const_vec(gallivm, coeff_bld->type, bld->pos_offset);
@@ -342,10 +342,11 @@ attribs_update_simple(struct lp_build_interp_soa_context *bld,
                            LLVMValueRef x_val_idx = lp_build_const_int32(gallivm, s * 2);
                            LLVMValueRef y_val_idx = lp_build_const_int32(gallivm, s * 2 + 1);
 
-                           x_val_idx = LLVMBuildGEP(builder, bld->sample_pos_array, &x_val_idx, 1, "");
-                           y_val_idx = LLVMBuildGEP(builder, bld->sample_pos_array, &y_val_idx, 1, "");
-                           x_val_idx = lp_build_broadcast_scalar(coeff_bld, LLVMBuildLoad(builder, x_val_idx, ""));
-                           y_val_idx = lp_build_broadcast_scalar(coeff_bld, LLVMBuildLoad(builder, y_val_idx, ""));
+                           x_val_idx = lp_build_array_get(gallivm, bld->sample_pos_array, x_val_idx);
+                           y_val_idx = lp_build_array_get(gallivm, bld->sample_pos_array, y_val_idx);
+
+                           x_val_idx = lp_build_broadcast_scalar(coeff_bld, x_val_idx);
+                           y_val_idx = lp_build_broadcast_scalar(coeff_bld, y_val_idx);
                            centroid_x_offset = lp_build_select(coeff_bld, sample_cov, x_val_idx, centroid_x_offset);
                            centroid_y_offset = lp_build_select(coeff_bld, sample_cov, y_val_idx, centroid_y_offset);
                         }
index f4959fb..c60faec 100644 (file)
@@ -2889,7 +2889,7 @@ generate_fragment(struct llvmpipe_context *lp,
                                                       num_loop_samp, "mask_store");
 
       LLVMTypeRef flt_type = LLVMFloatTypeInContext(gallivm->context);
-      LLVMValueRef glob_sample_pos = LLVMAddGlobal(gallivm->module, flt_type, "");
+      LLVMValueRef glob_sample_pos = LLVMAddGlobal(gallivm->module, LLVMArrayType(flt_type, key->coverage_samples * 2), "");
       LLVMValueRef sample_pos_array;
 
       if (key->multisample && key->coverage_samples == 4) {