vc4: Fix use of a bool as an enum.
[mesa.git] / src / gallium / drivers / vc4 / vc4_resource.c
index b02e2899329aad929b8f8bdff2c9c43c09758872..b8628ec725881bfd9f221ace1ac3253059f38cdd 100644 (file)
 #include "vc4_resource.h"
 #include "vc4_tiling.h"
 
+static bool miptree_debug = false;
+
 static void
 vc4_resource_bo_alloc(struct vc4_resource *rsc)
 {
         struct pipe_resource *prsc = &rsc->base.b;
         struct pipe_screen *pscreen = prsc->screen;
 
+        if (miptree_debug) {
+                fprintf(stderr, "alloc %p: size %d + offset %d -> %d\n",
+                        rsc,
+                        rsc->slices[0].size,
+                        rsc->slices[0].offset,
+                        rsc->slices[0].offset +
+                        rsc->slices[0].size +
+                        rsc->cube_map_stride * (prsc->array_size - 1));
+        }
+
         vc4_bo_unreference(&rsc->bo);
         rsc->bo = vc4_bo_alloc(vc4_screen(pscreen),
                                rsc->slices[0].offset +
@@ -126,7 +138,10 @@ vc4_resource_transfer_map(struct pipe_context *pctx,
          * need to do syncing stuff here yet.
          */
 
-        buf = vc4_bo_map(rsc->bo);
+        if (usage & PIPE_TRANSFER_UNSYNCHRONIZED)
+                buf = vc4_bo_map_unsynchronized(rsc->bo);
+        else
+                buf = vc4_bo_map(rsc->bo);
         if (!buf) {
                 fprintf(stderr, "Failed to map bo\n");
                 goto fail;
@@ -241,7 +256,7 @@ vc4_setup_slices(struct vc4_resource *rsc)
                         level_height = u_minify(pot_height, i);
                 }
 
-                if (rsc->tiled == VC4_TILING_FORMAT_LINEAR) {
+                if (!rsc->tiled) {
                         slice->tiling = VC4_TILING_FORMAT_LINEAR;
                         level_width = align(level_width, 16);
                 } else {
@@ -264,6 +279,22 @@ vc4_setup_slices(struct vc4_resource *rsc)
                 slice->size = level_height * slice->stride;
 
                 offset += slice->size;
+
+                if (miptree_debug) {
+                        static const char tiling_chars[] = {
+                                [VC4_TILING_FORMAT_LINEAR] = 'R',
+                                [VC4_TILING_FORMAT_LT] = 'L',
+                                [VC4_TILING_FORMAT_T] = 'T'
+                        };
+                        fprintf(stderr,
+                                "rsc setup %p (format %d), %dx%d: "
+                                "level %d (%c) -> %dx%d, stride %d@0x%08x\n",
+                                rsc, rsc->vc4_format,
+                                prsc->width0, prsc->height0,
+                                i, tiling_chars[slice->tiling],
+                                level_width, level_height,
+                                slice->stride, slice->offset);
+                }
         }
 
         /* The texture base pointer that has to point to level 0 doesn't have
@@ -342,14 +373,14 @@ vc4_resource_create(struct pipe_screen *pscreen,
                 rsc->tiled = true;
         }
 
+        if (tmpl->target != PIPE_BUFFER)
+                rsc->vc4_format = get_resource_texture_format(prsc);
+
         vc4_setup_slices(rsc);
         vc4_resource_bo_alloc(rsc);
         if (!rsc->bo)
                 goto fail;
 
-        if (tmpl->target != PIPE_BUFFER)
-                rsc->vc4_format = get_resource_texture_format(prsc);
-
         return prsc;
 fail:
         vc4_resource_destroy(pscreen, prsc);
@@ -369,17 +400,28 @@ vc4_resource_from_handle(struct pipe_screen *pscreen,
                 return NULL;
 
         rsc->tiled = false;
-        rsc->bo = vc4_screen_bo_from_handle(pscreen, handle, &slice->stride);
+        rsc->bo = vc4_screen_bo_from_handle(pscreen, handle);
         if (!rsc->bo)
                 goto fail;
 
-#ifdef USE_VC4_SIMULATOR
-        slice->stride = align(prsc->width0 * rsc->cpp, 16);
-#endif
+        if (!using_vc4_simulator)
+                slice->stride = handle->stride;
+        else
+                slice->stride = align(prsc->width0 * rsc->cpp, 16);
+
         slice->tiling = VC4_TILING_FORMAT_LINEAR;
 
         rsc->vc4_format = get_resource_texture_format(prsc);
 
+        if (miptree_debug) {
+                fprintf(stderr,
+                        "rsc import %p (format %d), %dx%d: "
+                        "level 0 (R) -> stride %d@0x%08x\n",
+                        rsc, rsc->vc4_format,
+                        prsc->width0, prsc->height0,
+                        slice->stride, slice->offset);
+        }
+
         return prsc;
 
 fail:
@@ -429,11 +471,11 @@ vc4_surface_destroy(struct pipe_context *pctx, struct pipe_surface *psurf)
 static void
 vc4_flush_resource(struct pipe_context *pctx, struct pipe_resource *resource)
 {
-        struct vc4_context *vc4 = vc4_context(pctx);
-
-        /* XXX: Skip this if we don't have any queued drawing to it. */
-        vc4->base.flush(pctx, NULL, 0);
+        /* All calls to flush_resource are followed by a flush of the context,
+         * so there's nothing to do.
+         */
 }
+
 static bool
 render_blit(struct pipe_context *ctx, struct pipe_blit_info *info)
 {