panfrost: Pass a batch to functions emitting FB descs
authorBoris Brezillon <boris.brezillon@collabora.com>
Sun, 1 Sep 2019 08:30:39 +0000 (10:30 +0200)
committerBoris Brezillon <boris.brezillon@collabora.com>
Fri, 13 Sep 2019 14:25:06 +0000 (16:25 +0200)
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>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_context.h
src/gallium/drivers/panfrost/pan_drm.c
src/gallium/drivers/panfrost/pan_fragment.c
src/gallium/drivers/panfrost/pan_mfbd.c
src/gallium/drivers/panfrost/pan_sfbd.c

index 3f036ce..f3950b0 100644 (file)
 /* 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);
@@ -104,10 +102,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),
@@ -116,18 +115,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 */
@@ -138,14 +137,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;
@@ -168,7 +166,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;
 }
@@ -177,7 +175,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;
 }
index 02552ed..8400b75 100644 (file)
@@ -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(
index e7dcd2e..81f922a 100644 (file)
@@ -286,7 +286,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);
         }
index dc89bce..2b6ffd8 100644 (file)
@@ -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]);
index da1827a..fcddec2 100644 (file)
@@ -345,8 +345,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,
@@ -364,7 +363,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);
 
@@ -393,18 +391,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;
@@ -417,7 +412,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);
@@ -443,8 +438,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
@@ -473,8 +468,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;
 
@@ -489,5 +484,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);
 }
index 843e563..bf49ddf 100644 (file)
@@ -130,19 +130,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;