[v3,17/25] panfrost: Pass a batch to functions emitting FB descs

Submitted by Boris Brezillon on Sept. 5, 2019, 7:41 p.m.

Details

Message ID 20190905194150.17608-18-boris.brezillon@collabora.com
State Accepted
Commit aa851a62b964c1c73d699739ce07d6ba773605d7
Headers show
Series "panfrost: Rework the batch pipelining logic" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Boris Brezillon Sept. 5, 2019, 7:41 p.m.
So we can emit such jobs to a batch that's not currently bound to the
context.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
 src/gallium/drivers/panfrost/pan_context.c  | 36 ++++++++++-----------
 src/gallium/drivers/panfrost/pan_context.h  | 10 +++---
 src/gallium/drivers/panfrost/pan_drm.c      |  2 +-
 src/gallium/drivers/panfrost/pan_fragment.c | 11 +++----
 src/gallium/drivers/panfrost/pan_mfbd.c     | 25 ++++++--------
 src/gallium/drivers/panfrost/pan_sfbd.c     | 13 ++++----
 6 files changed, 44 insertions(+), 53 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index a1b112c08919..c56f404cd9e9 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -55,14 +55,12 @@ 
 /* Framebuffer descriptor */
 
 static struct midgard_tiler_descriptor
-panfrost_emit_midg_tiler(
-        struct panfrost_context *ctx,
-        unsigned width,
-        unsigned height,
-        unsigned vertex_count)
+panfrost_emit_midg_tiler(struct panfrost_batch *batch, unsigned vertex_count)
 {
+        struct panfrost_context *ctx = batch->ctx;
         struct midgard_tiler_descriptor t = {};
-        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
+        unsigned height = batch->key.height;
+        unsigned width = batch->key.width;
 
         t.hierarchy_mask =
                 panfrost_choose_hierarchy_mask(width, height, vertex_count);
@@ -105,10 +103,11 @@  panfrost_emit_midg_tiler(
 }
 
 struct mali_single_framebuffer
-panfrost_emit_sfbd(struct panfrost_context *ctx, unsigned vertex_count)
+panfrost_emit_sfbd(struct panfrost_batch *batch, unsigned vertex_count)
 {
-        unsigned width = ctx->pipe_framebuffer.width;
-        unsigned height = ctx->pipe_framebuffer.height;
+        struct panfrost_context *ctx = batch->ctx;
+        unsigned width = batch->key.width;
+        unsigned height = batch->key.height;
 
         struct mali_single_framebuffer framebuffer = {
                 .width = MALI_POSITIVE(width),
@@ -117,18 +116,18 @@  panfrost_emit_sfbd(struct panfrost_context *ctx, unsigned vertex_count)
                 .format = 0x30000000,
                 .clear_flags = 0x1000,
                 .unknown_address_0 = ctx->scratchpad->gpu,
-                .tiler = panfrost_emit_midg_tiler(ctx,
-                                                  width, height, vertex_count),
+                .tiler = panfrost_emit_midg_tiler(batch, vertex_count),
         };
 
         return framebuffer;
 }
 
 struct bifrost_framebuffer
-panfrost_emit_mfbd(struct panfrost_context *ctx, unsigned vertex_count)
+panfrost_emit_mfbd(struct panfrost_batch *batch, unsigned vertex_count)
 {
-        unsigned width = ctx->pipe_framebuffer.width;
-        unsigned height = ctx->pipe_framebuffer.height;
+        struct panfrost_context *ctx = batch->ctx;
+        unsigned width = batch->key.width;
+        unsigned height = batch->key.height;
 
         struct bifrost_framebuffer framebuffer = {
                 .unk0 = 0x1e5, /* 1e4 if no spill */
@@ -139,14 +138,13 @@  panfrost_emit_mfbd(struct panfrost_context *ctx, unsigned vertex_count)
 
                 .unk1 = 0x1080,
 
-                .rt_count_1 = MALI_POSITIVE(ctx->pipe_framebuffer.nr_cbufs),
+                .rt_count_1 = MALI_POSITIVE(batch->key.nr_cbufs),
                 .rt_count_2 = 4,
 
                 .unknown2 = 0x1f,
 
                 .scratchpad = ctx->scratchpad->gpu,
-                .tiler = panfrost_emit_midg_tiler(ctx,
-                                                  width, height, vertex_count)
+                .tiler = panfrost_emit_midg_tiler(batch, vertex_count)
         };
 
         return framebuffer;
@@ -169,7 +167,7 @@  static mali_ptr
 panfrost_attach_vt_mfbd(struct panfrost_context *ctx)
 {
         struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
-        struct bifrost_framebuffer mfbd = panfrost_emit_mfbd(ctx, ~0);
+        struct bifrost_framebuffer mfbd = panfrost_emit_mfbd(batch, ~0);
 
         return panfrost_upload_transient(batch, &mfbd, sizeof(mfbd)) | MALI_MFBD;
 }
@@ -178,7 +176,7 @@  static mali_ptr
 panfrost_attach_vt_sfbd(struct panfrost_context *ctx)
 {
         struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
-        struct mali_single_framebuffer sfbd = panfrost_emit_sfbd(ctx, ~0);
+        struct mali_single_framebuffer sfbd = panfrost_emit_sfbd(batch, ~0);
 
         return panfrost_upload_transient(batch, &sfbd, sizeof(sfbd)) | MALI_SFBD;
 }
diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h
index f5e54f862cca..f0578d6808d2 100644
--- a/src/gallium/drivers/panfrost/pan_context.h
+++ b/src/gallium/drivers/panfrost/pan_context.h
@@ -315,17 +315,17 @@  panfrost_flush(
         struct pipe_fence_handle **fence,
         unsigned flags);
 
-mali_ptr panfrost_sfbd_fragment(struct panfrost_context *ctx, bool has_draws);
-mali_ptr panfrost_mfbd_fragment(struct panfrost_context *ctx, bool has_draws);
+mali_ptr panfrost_sfbd_fragment(struct panfrost_batch *batch, bool has_draws);
+mali_ptr panfrost_mfbd_fragment(struct panfrost_batch *batch, bool has_draws);
 
 struct bifrost_framebuffer
-panfrost_emit_mfbd(struct panfrost_context *ctx, unsigned vertex_count);
+panfrost_emit_mfbd(struct panfrost_batch *batch, unsigned vertex_count);
 
 struct mali_single_framebuffer
-panfrost_emit_sfbd(struct panfrost_context *ctx, unsigned vertex_count);
+panfrost_emit_sfbd(struct panfrost_batch *batch, unsigned vertex_count);
 
 mali_ptr
-panfrost_fragment_job(struct panfrost_context *ctx, bool has_draws);
+panfrost_fragment_job(struct panfrost_batch *batch, bool has_draws);
 
 void
 panfrost_shader_compile(
diff --git a/src/gallium/drivers/panfrost/pan_drm.c b/src/gallium/drivers/panfrost/pan_drm.c
index 87551bb26b3a..f76c097345f1 100644
--- a/src/gallium/drivers/panfrost/pan_drm.c
+++ b/src/gallium/drivers/panfrost/pan_drm.c
@@ -101,7 +101,7 @@  panfrost_drm_submit_vs_fs_batch(struct panfrost_batch *batch, bool has_draws)
 
         if (batch->first_tiler.gpu || batch->clear) {
                 ret = panfrost_drm_submit_batch(batch,
-                                                panfrost_fragment_job(ctx, has_draws),
+                                                panfrost_fragment_job(batch, has_draws),
                                                 PANFROST_JD_REQ_FS);
                 assert(!ret);
         }
diff --git a/src/gallium/drivers/panfrost/pan_fragment.c b/src/gallium/drivers/panfrost/pan_fragment.c
index dc89bce1b76b..2b6ffd841fe9 100644
--- a/src/gallium/drivers/panfrost/pan_fragment.c
+++ b/src/gallium/drivers/panfrost/pan_fragment.c
@@ -51,19 +51,18 @@  panfrost_initialize_surface(
  * presentations, this is supposed to correspond to eglSwapBuffers) */
 
 mali_ptr
-panfrost_fragment_job(struct panfrost_context *ctx, bool has_draws)
+panfrost_fragment_job(struct panfrost_batch *batch, bool has_draws)
 {
-        struct panfrost_screen *screen = pan_screen(ctx->base.screen);
+        struct panfrost_screen *screen = pan_screen(batch->ctx->base.screen);
 
         mali_ptr framebuffer = screen->require_sfbd ?
-                               panfrost_sfbd_fragment(ctx, has_draws) :
-                               panfrost_mfbd_fragment(ctx, has_draws);
+                               panfrost_sfbd_fragment(batch, has_draws) :
+                               panfrost_mfbd_fragment(batch, has_draws);
 
         /* Mark the affected buffers as initialized, since we're writing to it.
          * Also, add the surfaces we're writing to to the batch */
 
-        struct pipe_framebuffer_state *fb = &ctx->pipe_framebuffer;
-        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
+        struct pipe_framebuffer_state *fb = &batch->key;
 
         for (unsigned i = 0; i < fb->nr_cbufs; ++i) {
                 panfrost_initialize_surface(batch, fb->cbufs[i]);
diff --git a/src/gallium/drivers/panfrost/pan_mfbd.c b/src/gallium/drivers/panfrost/pan_mfbd.c
index 46a28ff6c94c..b01f8289bf9c 100644
--- a/src/gallium/drivers/panfrost/pan_mfbd.c
+++ b/src/gallium/drivers/panfrost/pan_mfbd.c
@@ -346,8 +346,7 @@  panfrost_mfbd_set_zsbuf(
 }
 
 static mali_ptr
-panfrost_mfbd_upload(
-        struct panfrost_context *ctx,
+panfrost_mfbd_upload(struct panfrost_batch *batch,
         struct bifrost_framebuffer *fb,
         struct bifrost_fb_extra *fbx,
         struct bifrost_render_target *rts,
@@ -365,7 +364,6 @@  panfrost_mfbd_upload(
                 (has_extra ? sizeof(struct bifrost_fb_extra) : 0) +
                 sizeof(struct bifrost_render_target) * 4;
 
-        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
         struct panfrost_transfer m_f_trans =
                 panfrost_allocate_transient(batch, total_sz);
 
@@ -394,18 +392,15 @@  panfrost_mfbd_upload(
 /* Creates an MFBD for the FRAGMENT section of the bound framebuffer */
 
 mali_ptr
-panfrost_mfbd_fragment(struct panfrost_context *ctx, bool has_draws)
+panfrost_mfbd_fragment(struct panfrost_batch *batch, bool has_draws)
 {
-        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
-
-        struct bifrost_framebuffer fb = panfrost_emit_mfbd(ctx, has_draws);
+        struct bifrost_framebuffer fb = panfrost_emit_mfbd(batch, has_draws);
         struct bifrost_fb_extra fbx = {};
         struct bifrost_render_target rts[4] = {};
 
         /* We always upload at least one dummy GL_NONE render target */
 
-        unsigned rt_descriptors =
-                MAX2(ctx->pipe_framebuffer.nr_cbufs, 1);
+        unsigned rt_descriptors = MAX2(batch->key.nr_cbufs, 1);
 
         fb.rt_count_1 = MALI_POSITIVE(rt_descriptors);
         fb.rt_count_2 = rt_descriptors;
@@ -418,7 +413,7 @@  panfrost_mfbd_fragment(struct panfrost_context *ctx, bool has_draws)
         /* Upload either the render target or a dummy GL_NONE target */
 
         for (int cb = 0; cb < rt_descriptors; ++cb) {
-                struct pipe_surface *surf = ctx->pipe_framebuffer.cbufs[cb];
+                struct pipe_surface *surf = batch->key.cbufs[cb];
 
                 if (surf) {
                         panfrost_mfbd_set_cbuf(&rts[cb], surf);
@@ -444,8 +439,8 @@  panfrost_mfbd_fragment(struct panfrost_context *ctx, bool has_draws)
                 rts[cb].format.unk1 |= (cb * 0x400);
         }
 
-        if (ctx->pipe_framebuffer.zsbuf) {
-                panfrost_mfbd_set_zsbuf(&fb, &fbx, ctx->pipe_framebuffer.zsbuf);
+        if (batch->key.zsbuf) {
+                panfrost_mfbd_set_zsbuf(&fb, &fbx, batch->key.zsbuf);
         }
 
         /* When scanning out, the depth buffer is immediately invalidated, so
@@ -474,8 +469,8 @@  panfrost_mfbd_fragment(struct panfrost_context *ctx, bool has_draws)
 
         /* Checksumming only works with a single render target */
 
-        if (ctx->pipe_framebuffer.nr_cbufs == 1) {
-                struct pipe_surface *surf = ctx->pipe_framebuffer.cbufs[0];
+        if (batch->key.nr_cbufs == 1) {
+                struct pipe_surface *surf = batch->key.cbufs[0];
                 struct panfrost_resource *rsrc = pan_resource(surf->texture);
                 struct panfrost_bo *bo = rsrc->bo;
 
@@ -490,5 +485,5 @@  panfrost_mfbd_fragment(struct panfrost_context *ctx, bool has_draws)
                 }
         }
 
-        return panfrost_mfbd_upload(ctx, &fb, &fbx, rts, rt_descriptors);
+        return panfrost_mfbd_upload(batch, &fb, &fbx, rts, rt_descriptors);
 }
diff --git a/src/gallium/drivers/panfrost/pan_sfbd.c b/src/gallium/drivers/panfrost/pan_sfbd.c
index 835c7dbbf95e..b5e18f07045e 100644
--- a/src/gallium/drivers/panfrost/pan_sfbd.c
+++ b/src/gallium/drivers/panfrost/pan_sfbd.c
@@ -131,19 +131,18 @@  panfrost_sfbd_set_zsbuf(
 /* Creates an SFBD for the FRAGMENT section of the bound framebuffer */
 
 mali_ptr
-panfrost_sfbd_fragment(struct panfrost_context *ctx, bool has_draws)
+panfrost_sfbd_fragment(struct panfrost_batch *batch, bool has_draws)
 {
-        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
-        struct mali_single_framebuffer fb = panfrost_emit_sfbd(ctx, has_draws);
+        struct mali_single_framebuffer fb = panfrost_emit_sfbd(batch, has_draws);
 
         panfrost_sfbd_clear(batch, &fb);
 
         /* SFBD does not support MRT natively; sanity check */
-        assert(ctx->pipe_framebuffer.nr_cbufs == 1);
-        panfrost_sfbd_set_cbuf(&fb, ctx->pipe_framebuffer.cbufs[0]);
+        assert(batch->key.nr_cbufs == 1);
+        panfrost_sfbd_set_cbuf(&fb, batch->key.cbufs[0]);
 
-        if (ctx->pipe_framebuffer.zsbuf)
-                panfrost_sfbd_set_zsbuf(&fb, ctx->pipe_framebuffer.zsbuf);
+        if (batch->key.zsbuf)
+                panfrost_sfbd_set_zsbuf(&fb, batch->key.zsbuf);
 
         if (batch->requirements & PAN_REQ_MSAA)
                 fb.format |= MALI_FRAMEBUFFER_MSAA_A | MALI_FRAMEBUFFER_MSAA_B;

Comments

Very happily R-b, this is a good cleanup :)