Mesa (master): vc4: Fix segfaults when rendering with no color render target.

Eric Anholt anholt at kemper.freedesktop.org
Tue Sep 9 14:30:30 UTC 2014


Module: Mesa
Branch: master
Commit: 2220692330ab2ac2879cfa392435784f5d5c8ca2
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2220692330ab2ac2879cfa392435784f5d5c8ca2

Author: Eric Anholt <eric at anholt.net>
Date:   Sun Sep  7 12:29:41 2014 -0700

vc4: Fix segfaults when rendering with no color render target.

---

 src/gallium/drivers/vc4/vc4_context.c   |   16 +++++++++++++---
 src/gallium/drivers/vc4/vc4_simulator.c |   10 +++++-----
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/vc4/vc4_context.c b/src/gallium/drivers/vc4/vc4_context.c
index d14da67..6ecc2ca 100644
--- a/src/gallium/drivers/vc4/vc4_context.c
+++ b/src/gallium/drivers/vc4/vc4_context.c
@@ -61,14 +61,24 @@ vc4_setup_rcl(struct vc4_context *vc4)
         cl_u32(&vc4->rcl, vc4->clear_depth);
         cl_u8(&vc4->rcl, vc4->clear_stencil);
 
+        /* The rendering mode config determines the pointer that's used for
+         * VC4_PACKET_STORE_MS_TILE_BUFFER address computations.  The kernel
+         * could handle a no-relocation rendering mode config and deny those
+         * packets, but instead we just tell the kernel we're doing our color
+         * rendering to the Z buffer, and just don't emit any of those
+         * packets.
+         */
+        struct vc4_surface *render_surf = csurf ? csurf : zsurf;
+        struct vc4_resource *render_tex = vc4_resource(render_surf->base.texture);
+
         cl_start_reloc(&vc4->rcl, 1);
         cl_u8(&vc4->rcl, VC4_PACKET_TILE_RENDERING_MODE_CONFIG);
-        cl_reloc(vc4, &vc4->rcl, ctex->bo, csurf->offset);
+        cl_reloc(vc4, &vc4->rcl, render_tex->bo, render_surf->offset);
         cl_u16(&vc4->rcl, width);
         cl_u16(&vc4->rcl, height);
-        cl_u16(&vc4->rcl, ((csurf->tiling <<
+        cl_u16(&vc4->rcl, ((render_surf->tiling <<
                             VC4_RENDER_CONFIG_MEMORY_FORMAT_SHIFT) |
-                           (vc4_rt_format_is_565(csurf->base.format) ?
+                           (vc4_rt_format_is_565(render_surf->base.format) ?
                             VC4_RENDER_CONFIG_FORMAT_BGR565 :
                             VC4_RENDER_CONFIG_FORMAT_RGBA8888) |
                            VC4_RENDER_CONFIG_EARLY_Z_COVERAGE_DISABLE));
diff --git a/src/gallium/drivers/vc4/vc4_simulator.c b/src/gallium/drivers/vc4/vc4_simulator.c
index 416a201..e122c0a 100644
--- a/src/gallium/drivers/vc4/vc4_simulator.c
+++ b/src/gallium/drivers/vc4/vc4_simulator.c
@@ -227,9 +227,9 @@ int
 vc4_simulator_flush(struct vc4_context *vc4, struct drm_vc4_submit_cl *args)
 {
         struct vc4_surface *csurf = vc4_surface(vc4->framebuffer.cbufs[0]);
-        struct vc4_resource *ctex = vc4_resource(csurf->base.texture);
-        uint32_t winsys_stride = ctex->bo->simulator_winsys_stride;
-        uint32_t sim_stride = ctex->slices[0].stride;
+        struct vc4_resource *ctex = csurf ? vc4_resource(csurf->base.texture) : NULL;
+        uint32_t winsys_stride = ctex ? ctex->bo->simulator_winsys_stride : 0;
+        uint32_t sim_stride = ctex ? ctex->slices[0].stride : 0;
         uint32_t row_len = MIN2(sim_stride, winsys_stride);
         struct exec_info exec;
         struct drm_device local_dev = {
@@ -241,7 +241,7 @@ vc4_simulator_flush(struct vc4_context *vc4, struct drm_vc4_submit_cl *args)
 
         memset(&exec, 0, sizeof(exec));
 
-        if (ctex->bo->simulator_winsys_map) {
+        if (ctex && ctex->bo->simulator_winsys_map) {
 #if 0
                 fprintf(stderr, "%dx%d %d %d %d\n",
                         ctex->base.b.width0, ctex->base.b.height0,
@@ -276,7 +276,7 @@ vc4_simulator_flush(struct vc4_context *vc4, struct drm_vc4_submit_cl *args)
 
         free(exec.exec_bo);
 
-        if (ctex->bo->simulator_winsys_map) {
+        if (ctex && ctex->bo->simulator_winsys_map) {
                 for (int y = 0; y < ctex->base.b.height0; y++) {
                         memcpy(ctex->bo->simulator_winsys_map + y * winsys_stride,
                                ctex->bo->map + y * sim_stride,




More information about the mesa-commit mailing list