iris: rework Wa_14017076903 to only apply with occlusion queries
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Tue, 2 May 2023 21:06:32 +0000 (00:06 +0300)
committerMarge Bot <emma+marge@anholt.net>
Thu, 25 May 2023 09:10:33 +0000 (09:10 +0000)
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Fixes: 415b824bc6 ("iris: implement occlusion query related Wa_14017076903")
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22807>

src/gallium/drivers/iris/iris_context.h
src/gallium/drivers/iris/iris_query.c
src/gallium/drivers/iris/iris_state.c

index 2a2726a..9471081 100644 (file)
@@ -850,6 +850,9 @@ struct iris_context {
       /** Is a PIPE_QUERY_PRIMITIVES_GENERATED query active? */
       bool prims_generated_query_active;
 
+      /** Is a PIPE_QUERY_OCCLUSION_COUNTER query active? */
+      bool occlusion_query_active;
+
       /** 3DSTATE_STREAMOUT and 3DSTATE_SO_DECL_LIST packets */
       uint32_t *streamout;
 
index ac7df8f..a5c4c94 100644 (file)
@@ -540,6 +540,11 @@ iris_begin_query(struct pipe_context *ctx, struct pipe_query *query)
       ice->state.dirty |= IRIS_DIRTY_STREAMOUT | IRIS_DIRTY_CLIP;
    }
 
+   if (q->type == PIPE_QUERY_OCCLUSION_COUNTER && q->index == 0) {
+      ice->state.occlusion_query_active = true;
+      ice->state.dirty |= IRIS_DIRTY_STREAMOUT;
+   }
+
    if (q->type == PIPE_QUERY_SO_OVERFLOW_PREDICATE ||
        q->type == PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE)
       write_overflow_values(ice, q, false);
@@ -579,6 +584,11 @@ iris_end_query(struct pipe_context *ctx, struct pipe_query *query)
       ice->state.dirty |= IRIS_DIRTY_STREAMOUT | IRIS_DIRTY_CLIP;
    }
 
+   if (q->type == PIPE_QUERY_OCCLUSION_COUNTER && q->index == 0) {
+      ice->state.occlusion_query_active = false;
+      ice->state.dirty |= IRIS_DIRTY_STREAMOUT;
+   }
+
    if (q->type == PIPE_QUERY_SO_OVERFLOW_PREDICATE ||
        q->type == PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE)
       write_overflow_values(ice, q, true);
index 502617e..96736c9 100644 (file)
@@ -4316,17 +4316,6 @@ iris_create_so_decl_list(const struct pipe_stream_output_info *info,
       sol.Buffer1SurfacePitch = 4 * info->stride[1];
       sol.Buffer2SurfacePitch = 4 * info->stride[2];
       sol.Buffer3SurfacePitch = 4 * info->stride[3];
-
-#if INTEL_NEEDS_WA_14017076903
-      /* Wa_14017076903 : SOL should be programmed to force the
-       * rendering to be enabled.
-       *
-       * This fixes a rare case where SOL must render to get correct
-       * occlusion query results even when no PS and depth buffers are
-       * bound.
-       */
-      sol.ForceRendering = Force_on;
-#endif
    }
 
    iris_pack_command(GENX(3DSTATE_SO_DECL_LIST), so_decl_map, list) {
@@ -6746,6 +6735,41 @@ iris_upload_dirty_render_state(struct iris_context *ice,
             sol.RenderingDisable = cso_rast->rasterizer_discard &&
                                    !ice->state.prims_generated_query_active;
             sol.ReorderMode = cso_rast->flatshade_first ? LEADING : TRAILING;
+
+
+#if INTEL_NEEDS_WA_14017076903
+            /* Wa_14017076903 :
+             *
+             * SKL PRMs, Volume 7: 3D-Media-GPGPU, Stream Output Logic (SOL) Stage:
+             *
+             * SOL_INT::Render_Enable =
+             *   (3DSTATE_STREAMOUT::Force_Rending == Force_On) ||
+             *   (
+             *     (3DSTATE_STREAMOUT::Force_Rending != Force_Off) &&
+             *     !(3DSTATE_GS::Enable && 3DSTATE_GS::Output Vertex Size == 0) &&
+             *     !3DSTATE_STREAMOUT::API_Render_Disable &&
+             *     (
+             *       3DSTATE_DEPTH_STENCIL_STATE::Stencil_TestEnable ||
+             *       3DSTATE_DEPTH_STENCIL_STATE::Depth_TestEnable ||
+             *       3DSTATE_DEPTH_STENCIL_STATE::Depth_WriteEnable ||
+             *       3DSTATE_PS_EXTRA::PS_Valid ||
+             *       3DSTATE_WM::Legacy Depth_Buffer_Clear ||
+             *       3DSTATE_WM::Legacy Depth_Buffer_Resolve_Enable ||
+             *       3DSTATE_WM::Legacy Hierarchical_Depth_Buffer_Resolve_Enable
+             *     )
+             *   )
+             *
+             * If SOL_INT::Render_Enable is false, the SO stage will not forward any
+             * topologies down the pipeline. Which is not what we want for occlusion
+             * queries.
+             *
+             * Here we force rendering to get SOL_INT::Render_Enable when occlusion
+             * queries are active.
+             */
+            const struct iris_rasterizer_state *cso_rast = ice->state.cso_rast;
+            if (!cso_rast->rasterizer_discard && ice->state.occlusion_query_active)
+               sol.ForceRendering = Force_on;
+#endif
          }
 
          assert(ice->state.streamout);