vc4: Fix segfaults when rendering with no color render target.
authorEric Anholt <eric@anholt.net>
Sun, 7 Sep 2014 19:29:41 +0000 (12:29 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 9 Sep 2014 14:29:16 +0000 (07:29 -0700)
src/gallium/drivers/vc4/vc4_context.c
src/gallium/drivers/vc4/vc4_simulator.c

index d14da676334610a0efb2e08b127bc264a08a9bef..6ecc2cab2aba85eb831bd0c7551b2c86d74681e5 100644 (file)
@@ -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));
index 416a201b40f1e2bea2a542b2bb5b21ff6ea8df68..e122c0a8668433e9b4a29375095022272036ad6d 100644 (file)
@@ -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,