llvmpipe: add per-sample depth/stencil test
authorDave Airlie <airlied@redhat.com>
Thu, 19 Mar 2020 05:54:08 +0000 (15:54 +1000)
committerMarge Bot <eric+marge@anholt.net>
Wed, 6 May 2020 06:20:37 +0000 (06:20 +0000)
The current depth stencil test code has some optimisations using
the mask when there is only one depth value, multisample requires
per-sample zstencil testing, and for that case just pass in the
mask that needs updating.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4122>

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

index 5efbb3945a7823407130039891863952aac06dec..ed28d212df3024e49c476d82109792ed4bc333f3 100644 (file)
@@ -810,6 +810,7 @@ lp_build_depth_stencil_write_swizzled(struct gallivm_state *gallivm,
  * \param type  the data type of the fragment depth/stencil values
  * \param format_desc  description of the depth/stencil surface
  * \param mask  the alive/dead pixel mask for the quad (vector)
+ * \param cov_mask coverage mask
  * \param stencil_refs  the front/back stencil ref values (scalar)
  * \param z_src  the incoming depth/stencil values (n 2x2 quad values, float32)
  * \param zs_dst  the depth/stencil values in framebuffer
@@ -822,6 +823,7 @@ lp_build_depth_stencil_test(struct gallivm_state *gallivm,
                             struct lp_type z_src_type,
                             const struct util_format_description *format_desc,
                             struct lp_build_mask_context *mask,
+                            LLVMValueRef *cov_mask,
                             LLVMValueRef stencil_refs[2],
                             LLVMValueRef z_src,
                             LLVMValueRef z_fb,
@@ -841,7 +843,7 @@ lp_build_depth_stencil_test(struct gallivm_state *gallivm,
    LLVMValueRef stencil_vals = NULL;
    LLVMValueRef z_bitmask = NULL, stencil_shift = NULL;
    LLVMValueRef z_pass = NULL, s_pass_mask = NULL;
-   LLVMValueRef current_mask = lp_build_mask_value(mask);
+   LLVMValueRef current_mask = mask ? lp_build_mask_value(mask) : *cov_mask;
    LLVMValueRef front_facing = NULL;
    boolean have_z, have_s;
 
@@ -1070,7 +1072,7 @@ lp_build_depth_stencil_test(struct gallivm_state *gallivm,
          current_mask = LLVMBuildAnd(builder, current_mask, s_pass_mask, "");
       }
 
-      if (!stencil[0].enabled) {
+      if (!stencil[0].enabled && mask) {
          /* We can potentially skip all remaining operations here, but only
           * if stencil is disabled because we still need to update the stencil
           * buffer values.  Don't need to update Z buffer values.
@@ -1145,10 +1147,21 @@ lp_build_depth_stencil_test(struct gallivm_state *gallivm,
       *s_value = stencil_vals;
    }
 
-   if (s_pass_mask)
-      lp_build_mask_update(mask, s_pass_mask);
+   if (mask) {
+      if (s_pass_mask)
+         lp_build_mask_update(mask, s_pass_mask);
 
-   if (depth->enabled && stencil[0].enabled)
-      lp_build_mask_update(mask, z_pass);
+      if (depth->enabled && stencil[0].enabled)
+         lp_build_mask_update(mask, z_pass);
+   } else {
+      LLVMValueRef tmp_mask = *cov_mask;
+      if (s_pass_mask)
+         tmp_mask = LLVMBuildAnd(builder, tmp_mask, s_pass_mask, "");
+
+      /* for multisample we don't do the stencil optimisation so update always */
+      if (depth->enabled)
+         tmp_mask = LLVMBuildAnd(builder, tmp_mask, z_pass, "");
+      *cov_mask = tmp_mask;
+   }
 }
 
index f0115daacc11553dbd003483b05fb340f7244337..2ced0bab90776083ba71abe565202ca04303f2fd 100644 (file)
@@ -61,6 +61,7 @@ lp_build_depth_stencil_test(struct gallivm_state *gallivm,
                             struct lp_type z_src_type,
                             const struct util_format_description *format_desc,
                             struct lp_build_mask_context *mask,
+                            LLVMValueRef *cov_mask,
                             LLVMValueRef stencil_refs[2],
                             LLVMValueRef z_src,
                             LLVMValueRef z_fb,
index fc56468332f881ace14c85f1c8fb13c5a3184c87..b2525334acf66c6ca106950fbed8d7ad90519871 100644 (file)
@@ -470,6 +470,7 @@ generate_fs_loop(struct gallivm_state *gallivm,
                                   type,
                                   zs_format_desc,
                                   &mask,
+                                  NULL,
                                   stencil_refs,
                                   z, z_fb, s_fb,
                                   facing,
@@ -614,6 +615,7 @@ generate_fs_loop(struct gallivm_state *gallivm,
                                   type,
                                   zs_format_desc,
                                   &mask,
+                                  NULL,
                                   stencil_refs,
                                   z, z_fb, s_fb,
                                   facing,