turnip: Use LATE_Z when there might be depth/stencil feedback loop
authorDanylo Piliaiev <dpiliaiev@igalia.com>
Wed, 23 Feb 2022 09:44:23 +0000 (11:44 +0200)
committerMarge Bot <emma+marge@anholt.net>
Wed, 23 Feb 2022 11:31:59 +0000 (11:31 +0000)
Otherwise a shader invocation would read the value which should have
been set AFTER this shader invocation.

Fixes tests:
 dEQP-VK.rasterization.rasterization_order_attachment_access.depth.samples_1.multi_draw_barriers
 dEQP-VK.rasterization.rasterization_order_attachment_access.stencil.samples_1.multi_draw_barriers

Fixes: 71595a189a0c372efd520ad51866ca57aa83298c
("tu: Fix feedback loops in sysmem mode")

Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15106>

src/freedreno/vulkan/tu_cmd_buffer.c
src/freedreno/vulkan/tu_pass.c
src/freedreno/vulkan/tu_pipeline.c
src/freedreno/vulkan/tu_private.h

index 1daa9de..a046a49 100644 (file)
@@ -316,7 +316,7 @@ tu6_emit_mrt(struct tu_cmd_buffer *cmd,
     * setting the SINGLE_PRIM_MODE field to the same value that the blob does
     * for advanced_blend in sysmem mode if a feedback loop is detected.
     */
-   if (subpass->feedback) {
+   if (subpass->feedback_loop_color || subpass->feedback_loop_ds) {
       tu_cond_exec_start(cs, CP_COND_EXEC_0_RENDER_MODE_SYSMEM);
       tu_cs_emit_write_reg(cs, REG_A6XX_GRAS_SC_CNTL,
                            A6XX_GRAS_SC_CNTL_CCUSINGLECACHELINESIZE(2) |
@@ -3879,7 +3879,8 @@ tu6_build_depth_plane_z_mode(struct tu_cmd_buffer *cmd)
    bool depth_write = tu6_writes_depth(cmd, depth_test_enable);
    bool stencil_write = tu6_writes_stencil(cmd);
 
-   if (cmd->state.pipeline->lrz.fs_has_kill &&
+   if ((cmd->state.pipeline->lrz.fs_has_kill ||
+        cmd->state.pipeline->subpass_feedback_loop_ds) &&
        (depth_write || stencil_write)) {
       zmode = cmd->state.lrz.valid ? A6XX_EARLY_LRZ_LATE_Z : A6XX_LATE_Z;
    }
index ee200fd..01c05fa 100644 (file)
@@ -481,7 +481,7 @@ tu_render_pass_check_feedback_loop(struct tu_render_pass *pass)
             continue;
          for (unsigned k = 0; k < subpass->input_count; k++) {
             if (subpass->input_attachments[k].attachment == a) {
-               subpass->feedback = true;
+               subpass->feedback_loop_color = true;
                break;
             }
          }
@@ -491,7 +491,7 @@ tu_render_pass_check_feedback_loop(struct tu_render_pass *pass)
          for (unsigned k = 0; k < subpass->input_count; k++) {
             if (subpass->input_attachments[k].attachment ==
                 subpass->depth_stencil_attachment.attachment) {
-               subpass->feedback = true;
+               subpass->feedback_loop_ds = true;
                break;
             }
          }
index 1a84cb3..78cb64f 100644 (file)
@@ -273,6 +273,8 @@ struct tu_pipeline_builder
    VkFormat depth_attachment_format;
    uint32_t render_components;
    uint32_t multiview_mask;
+
+   bool subpass_feedback_loop_ds;
 };
 
 static bool
@@ -3174,6 +3176,7 @@ tu_pipeline_builder_build(struct tu_pipeline_builder *builder,
       return VK_ERROR_OUT_OF_HOST_MEMORY;
 
    (*pipeline)->layout = builder->layout;
+   (*pipeline)->subpass_feedback_loop_ds = builder->subpass_feedback_loop_ds;
    (*pipeline)->executables_mem_ctx = ralloc_context(NULL);
    util_dynarray_init(&(*pipeline)->executables, (*pipeline)->executables_mem_ctx);
 
@@ -3287,6 +3290,8 @@ tu_pipeline_builder_init_graphics(
    const struct tu_subpass *subpass =
       &pass->subpasses[create_info->subpass];
 
+   builder->subpass_feedback_loop_ds = subpass->feedback_loop_ds;
+
    builder->multiview_mask = subpass->multiview_mask;
 
    builder->rasterizer_discard =
index b5ebc17..288d60e 100644 (file)
@@ -1361,6 +1361,8 @@ struct tu_pipeline
 
    struct tu_lrz_pipeline lrz;
 
+   bool subpass_feedback_loop_ds;
+
    /* Base drawcall cost for sysmem vs gmem autotuner */
    uint8_t drawcall_base_cost;
 
@@ -1695,8 +1697,8 @@ struct tu_subpass
    uint32_t resolve_count;
    bool resolve_depth_stencil;
 
-   /* True if there is any feedback loop at all. */
-   bool feedback;
+   bool feedback_loop_color;
+   bool feedback_loop_ds;
 
    /* True if we must invalidate UCHE thanks to a feedback loop. */
    bool feedback_invalidate;