llvmpipe: interpolate Z at sample points for early depth test.
authorDave Airlie <airlied@redhat.com>
Wed, 25 Mar 2020 02:47:53 +0000 (12:47 +1000)
committerMarge Bot <eric+marge@anholt.net>
Wed, 6 May 2020 06:20:37 +0000 (06:20 +0000)
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4122>

src/gallium/drivers/llvmpipe/lp_bld_interp.c
src/gallium/drivers/llvmpipe/lp_bld_interp.h
src/gallium/drivers/llvmpipe/lp_state_fs.c

index 745a6ca7c3bfba9cc5cb6031b4ef568272a1d0fe..bd6bce7be2dd42d84d36a9d007a788a3f5a7b3bb 100644 (file)
@@ -313,7 +313,7 @@ attribs_update_simple(struct lp_build_interp_soa_context *bld,
                   if (bld->coverage_samples > 1) {
                      LLVMValueRef xoffset = lp_build_const_vec(gallivm, coeff_bld->type, bld->pos_offset);
                      LLVMValueRef yoffset = lp_build_const_vec(gallivm, coeff_bld->type, bld->pos_offset);
-                     if (loc == TGSI_INTERPOLATE_LOC_SAMPLE) {
+                     if (loc == TGSI_INTERPOLATE_LOC_SAMPLE || (attrib == 0 && chan == 2 && sample_id)) {
                         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), "");
 
@@ -882,10 +882,11 @@ lp_build_interp_soa_update_inputs_dyn(struct lp_build_interp_soa_context *bld,
 void
 lp_build_interp_soa_update_pos_dyn(struct lp_build_interp_soa_context *bld,
                                    struct gallivm_state *gallivm,
-                                   LLVMValueRef quad_start_index)
+                                   LLVMValueRef quad_start_index,
+                                   LLVMValueRef sample_id)
 {
    if (bld->simple_interp) {
-      attribs_update_simple(bld, gallivm, quad_start_index, NULL, NULL, 0, 1);
+      attribs_update_simple(bld, gallivm, quad_start_index, NULL, sample_id, 0, 1);
    }
    else {
       attribs_update(bld, gallivm, quad_start_index, 0, 1);
index 11445ebfb4f726a80e72df2a9c167d257f22b977..e679a17118f3751da25e608c1ca1298b0b1dd6eb 100644 (file)
@@ -144,6 +144,7 @@ lp_build_interp_soa_update_inputs_dyn(struct lp_build_interp_soa_context *bld,
 void
 lp_build_interp_soa_update_pos_dyn(struct lp_build_interp_soa_context *bld,
                                    struct gallivm_state *gallivm,
-                                   LLVMValueRef quad_start_index);
+                                   LLVMValueRef quad_start_index,
+                                   LLVMValueRef sample_id);
 
 #endif /* LP_BLD_INTERP_H */
index c89693ce3c5237b32be5b1a758bd32730a5aed4f..d32bdeb301daf800ef0d3f0b644ffdb91b365e69 100644 (file)
@@ -464,9 +464,6 @@ generate_fs_loop(struct gallivm_state *gallivm,
    if (!(depth_mode & EARLY_DEPTH_TEST) && !simple_shader)
       lp_build_mask_check(&mask);
 
-   lp_build_interp_soa_update_pos_dyn(interp, gallivm, loop_state.counter);
-   z = interp->pos[2];
-
    /* Create storage for recombining sample masks after early Z pass. */
    LLVMValueRef s_mask_or = lp_build_alloca(gallivm, lp_build_int_vec_type(gallivm, type), "cov_mask_early_depth");
    LLVMBuildStore(builder, LLVMConstNull(lp_build_int_vec_type(gallivm, type)), s_mask_or);
@@ -512,6 +509,11 @@ generate_fs_loop(struct gallivm_state *gallivm,
       s_mask = LLVMBuildAnd(builder, s_mask, mask_val, "");
    }
 
+
+   /* for multisample Z needs to be interpolated at sample points for testing. */
+   lp_build_interp_soa_update_pos_dyn(interp, gallivm, loop_state.counter, key->multisample ? sample_loop_state.counter : NULL);
+   z = interp->pos[2];
+
    depth_ptr = depth_base_ptr;
    if (key->multisample) {
       LLVMValueRef sample_offset = LLVMBuildMul(builder, sample_loop_state.counter, depth_sample_stride, "");
@@ -585,6 +587,9 @@ generate_fs_loop(struct gallivm_state *gallivm,
       /* recombined all the coverage masks in the shader exec mask. */
       tmp_s_mask_or = LLVMBuildLoad(builder, s_mask_or, "");
       lp_build_mask_update(&mask, tmp_s_mask_or);
+
+      /* for multisample Z needs to be re interpolated at pixel center */
+      lp_build_interp_soa_update_pos_dyn(interp, gallivm, loop_state.counter, NULL);
    }
 
    lp_build_interp_soa_update_inputs_dyn(interp, gallivm, loop_state.counter, NULL, NULL);