panfrost: Check for NULL surface in places
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Thu, 18 Jul 2019 17:59:59 +0000 (10:59 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Thu, 18 Jul 2019 22:25:40 +0000 (15:25 -0700)
Fixes a bunch of NULL dereferences, although it does cause GPU faults of
course.

This is caused by color buffers masked out in MRT, which we'll
eventually have to solve the right way... one thing at a time.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/pan_blend_cso.c
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_fragment.c
src/gallium/drivers/panfrost/pan_mfbd.c
src/gallium/drivers/panfrost/pan_resource.c

index 5055d2d854e840ff8a18c799099d16884e1b8122..a96e7b02cd4a2a04504e3a930ec6823534318c56 100644 (file)
@@ -212,7 +212,7 @@ panfrost_get_blend_for_context(struct panfrost_context *ctx, unsigned rti)
         struct pipe_framebuffer_state *fb = &ctx->pipe_framebuffer;
         enum pipe_format fmt = PIPE_FORMAT_R8G8B8A8_UNORM;
 
-        if (fb->nr_cbufs > rti)
+        if ((fb->nr_cbufs > rti) && fb->cbufs[rti])
                 fmt = fb->cbufs[rti]->format;
 
         /* Grab the blend state */
index d01503e43a96a6fe9d27b07ab63bb51e377d59e8..06943c22b449acd0910eb43022bb2915aa5e1a4c 100644 (file)
@@ -1213,11 +1213,10 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data)
 
                         struct midgard_blend_rt rts[4];
 
-                        /* TODO: MRT */
-
-                        for (unsigned i = 0; i < 1; ++i) {
+                        for (unsigned i = 0; i < ctx->pipe_framebuffer.nr_cbufs; ++i) {
                                 bool is_srgb =
                                         (ctx->pipe_framebuffer.nr_cbufs > i) &&
+                                        (ctx->pipe_framebuffer.cbufs[i]) &&
                                         util_format_is_srgb(ctx->pipe_framebuffer.cbufs[i]->format);
 
                                 rts[i].flags = blend_count;
index 7ffb9db0a055ee5604e48d615aa669e691d40a0a..023569ef204de1a027b482bb4c91f22ae916e57a 100644 (file)
@@ -35,6 +35,9 @@ panfrost_initialize_surface(
                 struct panfrost_job *batch,
                 struct pipe_surface *surf)
 {
+        if (!surf)
+                return;
+
         unsigned level = surf->u.tex.level;
         struct panfrost_resource *rsrc = pan_resource(surf->texture);
 
index e3595af4cf1de1f0d4ba6a0e1be648279093d165..c9f3dc315a0fb8f139f572554befa630f60870ca 100644 (file)
@@ -403,6 +403,10 @@ panfrost_mfbd_fragment(struct panfrost_context *ctx, bool has_draws)
 
         for (int cb = 0; cb < ctx->pipe_framebuffer.nr_cbufs; ++cb) {
                 struct pipe_surface *surf = ctx->pipe_framebuffer.cbufs[cb];
+
+                if (!surf)
+                        continue;
+
                 unsigned bpp = util_format_get_blocksize(surf->format);
 
                 panfrost_mfbd_set_cbuf(&rts[cb], surf);
index d3cbfe70c77a26cbbb149b2f9d65bba4207928c6..3f8d50cad73c768e339aa2b8954576da7289f529 100644 (file)
@@ -507,7 +507,10 @@ panfrost_transfer_map(struct pipe_context *pctx,
         bool is_bound = false;
 
         for (unsigned c = 0; c < fb->nr_cbufs; ++c) {
-                is_bound |= fb->cbufs[c]->texture == resource;
+                /* If cbufs is NULL, we're definitely not bound here */
+
+                if (fb->cbufs[c])
+                        is_bound |= fb->cbufs[c]->texture == resource;
         }
 
         if (is_bound && (usage & PIPE_TRANSFER_READ)) {