panfrost: Re-init the VT payloads at draw/launch_grid() time
authorBoris Brezillon <boris.brezillon@collabora.com>
Fri, 6 Mar 2020 10:31:06 +0000 (11:31 +0100)
committerBoris Brezillon <boris.brezillon@collabora.com>
Tue, 10 Mar 2020 11:47:34 +0000 (12:47 +0100)
Doing that should help us avoiding state leaks between draw/launch_grid
calls.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4083>

src/gallium/drivers/panfrost/pan_cmdstream.c
src/gallium/drivers/panfrost/pan_cmdstream.h
src/gallium/drivers/panfrost/pan_compute.c
src/gallium/drivers/panfrost/pan_context.c

index 02d3cfde068ecb34b50e1382556d648a572a9b76..0070c18fabadc5b5fd488641c3d607556f497243 100644 (file)
@@ -101,6 +101,25 @@ panfrost_vt_update_occlusion_query(struct panfrost_context *ctx,
                 tp->postfix.occlusion_counter = 0;
 }
 
+void
+panfrost_vt_init(struct panfrost_context *ctx,
+                 enum pipe_shader_type stage,
+                 struct midgard_payload_vertex_tiler *vtp)
+{
+        if (!ctx->shader[stage])
+                return;
+
+        memset(vtp, 0, sizeof(*vtp));
+        vtp->gl_enables = 0x6;
+        panfrost_vt_attach_framebuffer(ctx, vtp);
+
+        if (stage == PIPE_SHADER_FRAGMENT) {
+                panfrost_vt_update_occlusion_query(ctx, vtp);
+                panfrost_vt_update_rasterizer(ctx, vtp);
+        }
+}
+
+
 static unsigned
 panfrost_translate_index_size(unsigned size)
 {
index 655110243cde881a9f07f0ac1fc04f3bb1f1347f..9ace7802ba2c49da69707490c17625e767b44137 100644 (file)
 void panfrost_sampler_desc_init(const struct pipe_sampler_state *cso,
                                 struct mali_sampler_descriptor *hw);
 
+void
+panfrost_vt_init(struct panfrost_context *ctx,
+                 enum pipe_shader_type stage,
+                 struct midgard_payload_vertex_tiler *vtp);
+
 void
 panfrost_vt_attach_framebuffer(struct panfrost_context *ctx,
                                struct midgard_payload_vertex_tiler *vt);
index d67e87f590b5e6f1b5142fafb42f4dafe75b518e..09ab09fb63ee74bc0ebdc8cf141d5d215e53dc9b 100644 (file)
@@ -117,6 +117,8 @@ panfrost_launch_grid(struct pipe_context *pipe,
         if (info->input)
                 pipe->set_constant_buffer(pipe, PIPE_SHADER_COMPUTE, 0, &ubuf);
 
+        panfrost_vt_init(ctx, PIPE_SHADER_COMPUTE, payload);
+
         panfrost_emit_shader_meta(batch, PIPE_SHADER_COMPUTE, payload);
         panfrost_emit_const_buf(batch, PIPE_SHADER_COMPUTE, payload);
         panfrost_emit_shared_memory(batch, info, payload);
index db9f96a0185409b17ef8aaea1e4907c2c85beb4e..999823263f984197ad657f8acace1f0219dc778a 100644 (file)
@@ -148,32 +148,10 @@ panfrost_clear(
 void
 panfrost_invalidate_frame(struct panfrost_context *ctx)
 {
-        for (unsigned i = 0; i < PIPE_SHADER_TYPES; ++i)
-                ctx->payloads[i].postfix.shared_memory = 0;
-
         /* TODO: When does this need to be handled? */
         ctx->active_queries = true;
 }
 
-/* In practice, every field of these payloads should be configurable
- * arbitrarily, which means these functions are basically catch-all's for
- * as-of-yet unwavering unknowns */
-
-static void
-panfrost_emit_vertex_payload(struct panfrost_context *ctx)
-{
-        /* 0x2 bit clear on 32-bit T6XX */
-
-        struct midgard_payload_vertex_tiler payload = {
-                .gl_enables = 0x4 | 0x2,
-        };
-
-        /* Vertex and compute are closely coupled, so share a payload */
-
-        memcpy(&ctx->payloads[PIPE_SHADER_VERTEX], &payload, sizeof(payload));
-        memcpy(&ctx->payloads[PIPE_SHADER_COMPUTE], &payload, sizeof(payload));
-}
-
 bool
 panfrost_writes_point_size(struct panfrost_context *ctx)
 {
@@ -422,17 +400,14 @@ panfrost_draw_vbo(
 
         unsigned vertex_count;
 
+        for (int i = 0; i <= PIPE_SHADER_FRAGMENT; ++i)
+                panfrost_vt_init(ctx, i, &ctx->payloads[i]);
+
         panfrost_vt_set_draw_info(ctx, info, g2m_draw_mode(mode),
                                   &ctx->payloads[PIPE_SHADER_VERTEX],
                                   &ctx->payloads[PIPE_SHADER_FRAGMENT],
                                   &vertex_count, &ctx->padded_count);
 
-        for (int i = 0; i <= PIPE_SHADER_FRAGMENT; ++i)
-                panfrost_vt_attach_framebuffer(ctx, &ctx->payloads[i]);
-
-        panfrost_vt_update_rasterizer(ctx, &ctx->payloads[PIPE_SHADER_FRAGMENT]);
-        panfrost_vt_update_occlusion_query(ctx, &ctx->payloads[PIPE_SHADER_FRAGMENT]);
-
         panfrost_statistics_record(ctx, info);
 
         /* Dispatch "compute jobs" for the vertex/tiler pair as (1,
@@ -1455,7 +1430,6 @@ panfrost_create_context(struct pipe_screen *screen, void *priv, unsigned flags)
         /* Prepare for render! */
 
         panfrost_batch_init(ctx);
-        panfrost_emit_vertex_payload(ctx);
         panfrost_invalidate_frame(ctx);
 
         return gallium;