summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/freedreno/freedreno_resource.c
diff options
context:
space:
mode:
authorRob Clark <robclark@freedesktop.org>2013-05-26 17:13:27 -0400
committerRob Clark <robclark@freedesktop.org>2013-06-08 13:15:51 -0400
commit18c317b21ddc2ec4538544f9dd69dc568dcf821f (patch)
tree224e3c0464dcedabbf5784e5c3def952473fd8f8 /src/gallium/drivers/freedreno/freedreno_resource.c
parent213c207b3ac40ae769afe01b8578f566b5e7840d (diff)
downloadexternal_mesa3d-18c317b21ddc2ec4538544f9dd69dc568dcf821f.zip
external_mesa3d-18c317b21ddc2ec4538544f9dd69dc568dcf821f.tar.gz
external_mesa3d-18c317b21ddc2ec4538544f9dd69dc568dcf821f.tar.bz2
freedreno: prepare for a3xx
Split the parts that are specific to adreno a2xx series GPUs from the parts that will be in common with a3xx, so that a3xx support can be added more cleanly. Signed-off-by: Rob Clark <robclark@freedesktop.org>
Diffstat (limited to 'src/gallium/drivers/freedreno/freedreno_resource.c')
-rw-r--r--src/gallium/drivers/freedreno/freedreno_resource.c73
1 files changed, 45 insertions, 28 deletions
diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c
index ba81453..1b1eaa5 100644
--- a/src/gallium/drivers/freedreno/freedreno_resource.c
+++ b/src/gallium/drivers/freedreno/freedreno_resource.c
@@ -38,6 +38,31 @@
#include "freedreno_context.h"
#include "freedreno_util.h"
+static void fd_resource_transfer_flush_region(struct pipe_context *pctx,
+ struct pipe_transfer *ptrans,
+ const struct pipe_box *box)
+{
+ struct fd_context *ctx = fd_context(pctx);
+ struct fd_resource *rsc = fd_resource(ptrans->resource);
+
+ if (rsc->dirty)
+ fd_context_render(pctx);
+
+ if (rsc->timestamp) {
+ fd_pipe_wait(ctx->screen->pipe, rsc->timestamp);
+ rsc->timestamp = 0;
+ }
+}
+
+static void
+fd_resource_transfer_unmap(struct pipe_context *pctx,
+ struct pipe_transfer *ptrans)
+{
+ struct fd_context *ctx = fd_context(pctx);
+ pipe_resource_reference(&ptrans->resource, NULL);
+ util_slab_free(&ctx->transfer_pool, ptrans);
+}
+
static void *
fd_resource_transfer_map(struct pipe_context *pctx,
struct pipe_resource *prsc,
@@ -54,14 +79,24 @@ fd_resource_transfer_map(struct pipe_context *pctx,
if (!ptrans)
return NULL;
- ptrans->resource = prsc;
+ /* util_slap_alloc() doesn't zero: */
+ memset(ptrans, 0, sizeof(*ptrans));
+
+ pipe_resource_reference(&ptrans->resource, prsc);
ptrans->level = level;
ptrans->usage = usage;
ptrans->box = *box;
ptrans->stride = rsc->pitch * rsc->cpp;
ptrans->layer_stride = ptrans->stride;
+ /* some state trackers (at least XA) don't do this.. */
+ fd_resource_transfer_flush_region(pctx, ptrans, box);
+
buf = fd_bo_map(rsc->bo);
+ if (!buf) {
+ fd_resource_transfer_unmap(pctx, ptrans);
+ return NULL;
+ }
*pptrans = ptrans;
@@ -70,30 +105,6 @@ fd_resource_transfer_map(struct pipe_context *pctx,
box->x / util_format_get_blockwidth(format) * rsc->cpp;
}
-static void fd_resource_transfer_flush_region(struct pipe_context *pctx,
- struct pipe_transfer *ptrans,
- const struct pipe_box *box)
-{
- struct fd_context *ctx = fd_context(pctx);
- struct fd_resource *rsc = fd_resource(ptrans->resource);
-
- if (rsc->dirty)
- fd_context_render(pctx);
-
- if (rsc->timestamp) {
- fd_pipe_wait(ctx->screen->pipe, rsc->timestamp);
- rsc->timestamp = 0;
- }
-}
-
-static void
-fd_resource_transfer_unmap(struct pipe_context *pctx,
- struct pipe_transfer *ptrans)
-{
- struct fd_context *ctx = fd_context(pctx);
- util_slab_free(&ctx->transfer_pool, ptrans);
-}
-
static void
fd_resource_destroy(struct pipe_screen *pscreen,
struct pipe_resource *prsc)
@@ -110,11 +121,12 @@ fd_resource_get_handle(struct pipe_screen *pscreen,
{
struct fd_resource *rsc = fd_resource(prsc);
- return fd_screen_bo_get_handle(pscreen, rsc->bo, rsc->pitch, handle);
+ return fd_screen_bo_get_handle(pscreen, rsc->bo,
+ rsc->pitch * rsc->cpp, handle);
}
-const struct u_resource_vtbl fd_resource_vtbl = {
+static const struct u_resource_vtbl fd_resource_vtbl = {
.resource_get_handle = fd_resource_get_handle,
.resource_destroy = fd_resource_destroy,
.transfer_map = fd_resource_transfer_map,
@@ -154,6 +166,8 @@ fd_resource_create(struct pipe_screen *pscreen,
rsc->pitch = align(tmpl->width0, 32);
rsc->cpp = util_format_get_blocksize(tmpl->format);
+ assert(rsc->cpp);
+
size = rsc->pitch * tmpl->height0 * rsc->cpp;
flags = DRM_FREEDRENO_GEM_CACHE_WCOMBINE |
DRM_FREEDRENO_GEM_TYPE_KMEM; /* TODO */
@@ -194,7 +208,10 @@ fd_resource_from_handle(struct pipe_screen *pscreen,
rsc->bo = fd_screen_bo_from_handle(pscreen, handle, &rsc->pitch);
rsc->base.vtbl = &fd_resource_vtbl;
- rsc->pitch = align(tmpl->width0, 32);
+ rsc->cpp = util_format_get_blocksize(tmpl->format);
+ rsc->pitch /= rsc->cpp;
+
+ assert(rsc->cpp);
return prsc;
}