freedreno/a3xx/compiler: refactor trans_samp()
[mesa.git] / src / gallium / drivers / freedreno / freedreno_resource.c
index fd975cb388d5961d37e66debd7770f9ffe0a1e16..289f3653e12eb10939ba402498411558db630de9 100644 (file)
@@ -36,6 +36,7 @@
 #include "freedreno_screen.h"
 #include "freedreno_surface.h"
 #include "freedreno_context.h"
+#include "freedreno_query_hw.h"
 #include "freedreno_util.h"
 
 #include <errno.h>
@@ -123,8 +124,8 @@ fd_resource_transfer_map(struct pipe_context *pctx,
                op |= DRM_FREEDRENO_PREP_NOSYNC;
 
        /* some state trackers (at least XA) don't do this.. */
-//     if (!(usage & PIPE_TRANSFER_FLUSH_EXPLICIT))
-//             fd_resource_transfer_flush_region(pctx, ptrans, box);
+       if (!(usage & (PIPE_TRANSFER_FLUSH_EXPLICIT | PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE)))
+               fd_resource_transfer_flush_region(pctx, ptrans, box);
 
        if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
                ret = fd_bo_cpu_prep(rsc->bo, ctx->screen->pipe, op);
@@ -157,7 +158,8 @@ fd_resource_destroy(struct pipe_screen *pscreen,
                struct pipe_resource *prsc)
 {
        struct fd_resource *rsc = fd_resource(prsc);
-       fd_bo_del(rsc->bo);
+       if (rsc->bo)
+               fd_bo_del(rsc->bo);
        FREE(rsc);
 }
 
@@ -243,8 +245,13 @@ fd_resource_create(struct pipe_screen *pscreen,
        size = setup_slices(rsc);
 
        realloc_bo(rsc, size);
+       if (!rsc->bo)
+               goto fail;
 
        return prsc;
+fail:
+       fd_resource_destroy(pscreen, prsc);
+       return NULL;
 }
 
 /**
@@ -277,6 +284,8 @@ fd_resource_from_handle(struct pipe_screen *pscreen,
        prsc->screen = pscreen;
 
        rsc->bo = fd_screen_bo_from_handle(pscreen, handle, &slice->pitch);
+       if (!rsc->bo)
+               goto fail;
 
        rsc->base.vtbl = &fd_resource_vtbl;
        rsc->cpp = util_format_get_blocksize(tmpl->format);
@@ -285,6 +294,10 @@ fd_resource_from_handle(struct pipe_screen *pscreen,
        assert(rsc->cpp);
 
        return prsc;
+
+fail:
+       fd_resource_destroy(pscreen, prsc);
+       return NULL;
 }
 
 static bool render_blit(struct pipe_context *pctx, struct pipe_blit_info *info);
@@ -389,11 +402,18 @@ render_blit(struct pipe_context *pctx, struct pipe_blit_info *info)
        util_blitter_save_fragment_sampler_views(ctx->blitter,
                        ctx->fragtex.num_textures, ctx->fragtex.textures);
 
+       fd_hw_query_set_stage(ctx, ctx->ring, FD_STAGE_BLIT);
        util_blitter_blit(ctx->blitter, info);
+       fd_hw_query_set_stage(ctx, ctx->ring, FD_STAGE_NULL);
 
        return true;
 }
 
+static void
+fd_flush_resource(struct pipe_context *ctx, struct pipe_resource *resource)
+{
+}
+
 void
 fd_resource_screen_init(struct pipe_screen *pscreen)
 {
@@ -414,4 +434,5 @@ fd_resource_context_init(struct pipe_context *pctx)
        pctx->surface_destroy = fd_surface_destroy;
        pctx->resource_copy_region = fd_resource_copy_region;
        pctx->blit = fd_blit;
+       pctx->flush_resource = fd_flush_resource;
 }