summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2012-10-08 04:06:42 +0200
committerMarek Olšák <[email protected]>2012-10-11 21:12:16 +0200
commit369e46888904c6d379b8b477d9242cff1608e30e (patch)
tree528b10f900f23af3acd22a0edcf50fde0eeee86e /src/gallium/drivers
parentec4c74a9dc10039d97ad24c4f16bd2400517991d (diff)
gallium: unify transfer functions
"get_transfer + transfer_map" becomes "transfer_map". "transfer_unmap + transfer_destroy" becomes "transfer_unmap". transfer_map must create and return the transfer object and transfer_unmap must destroy it. transfer_map is successful if the returned buffer pointer is not NULL. If transfer_map fails, the pointer to the transfer object remains unchanged (i.e. doesn't have to be NULL). Acked-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r--src/gallium/drivers/galahad/glhd_context.c65
-rw-r--r--src/gallium/drivers/galahad/glhd_objects.c4
-rw-r--r--src/gallium/drivers/i915/i915_resource.c2
-rw-r--r--src/gallium/drivers/i915/i915_resource_buffer.c37
-rw-r--r--src/gallium/drivers/i915/i915_resource_texture.c92
-rw-r--r--src/gallium/drivers/identity/id_context.c52
-rw-r--r--src/gallium/drivers/identity/id_objects.c10
-rw-r--r--src/gallium/drivers/identity/id_objects.h2
-rw-r--r--src/gallium/drivers/llvmpipe/lp_texture.c104
-rw-r--r--src/gallium/drivers/noop/noop_pipe.c53
-rw-r--r--src/gallium/drivers/nouveau/nouveau_buffer.c102
-rw-r--r--src/gallium/drivers/nv30/nv30_miptree.c59
-rw-r--r--src/gallium/drivers/nv30/nv30_resource.c2
-rw-r--r--src/gallium/drivers/nv50/nv50_miptree.c2
-rw-r--r--src/gallium/drivers/nv50/nv50_resource.c2
-rw-r--r--src/gallium/drivers/nv50/nv50_resource.h15
-rw-r--r--src/gallium/drivers/nv50/nv50_transfer.c63
-rw-r--r--src/gallium/drivers/nvc0/nvc0_miptree.c2
-rw-r--r--src/gallium/drivers/nvc0/nvc0_resource.c2
-rw-r--r--src/gallium/drivers/nvc0/nvc0_resource.h15
-rw-r--r--src/gallium/drivers/nvc0/nvc0_transfer.c63
-rw-r--r--src/gallium/drivers/r300/r300_resource.c2
-rw-r--r--src/gallium/drivers/r300/r300_screen_buffer.c80
-rw-r--r--src/gallium/drivers/r300/r300_texture.c2
-rw-r--r--src/gallium/drivers/r300/r300_transfer.c105
-rw-r--r--src/gallium/drivers/r300/r300_transfer.h15
-rw-r--r--src/gallium/drivers/r600/compute_memory_pool.c17
-rw-r--r--src/gallium/drivers/r600/evergreen_compute.c94
-rw-r--r--src/gallium/drivers/r600/evergreen_compute.h11
-rw-r--r--src/gallium/drivers/r600/r600_buffer.c113
-rw-r--r--src/gallium/drivers/r600/r600_resource.c2
-rw-r--r--src/gallium/drivers/r600/r600_resource.h13
-rw-r--r--src/gallium/drivers/r600/r600_texture.c138
-rw-r--r--src/gallium/drivers/radeonsi/r600_buffer.c53
-rw-r--r--src/gallium/drivers/radeonsi/r600_resource.c2
-rw-r--r--src/gallium/drivers/radeonsi/r600_texture.c99
-rw-r--r--src/gallium/drivers/rbug/rbug_context.c60
-rw-r--r--src/gallium/drivers/rbug/rbug_core.c11
-rw-r--r--src/gallium/drivers/rbug/rbug_objects.c4
-rw-r--r--src/gallium/drivers/softpipe/sp_context.c32
-rw-r--r--src/gallium/drivers/softpipe/sp_draw_arrays.c2
-rw-r--r--src/gallium/drivers/softpipe/sp_flush.c8
-rw-r--r--src/gallium/drivers/softpipe/sp_state.h6
-rw-r--r--src/gallium/drivers/softpipe/sp_tex_tile_cache.c41
-rw-r--r--src/gallium/drivers/softpipe/sp_texture.c88
-rw-r--r--src/gallium/drivers/softpipe/sp_tile_cache.c74
-rw-r--r--src/gallium/drivers/softpipe/sp_tile_cache.h6
-rw-r--r--src/gallium/drivers/svga/svga_resource.c2
-rw-r--r--src/gallium/drivers/svga/svga_resource_buffer.c36
-rw-r--r--src/gallium/drivers/svga/svga_resource_texture.c64
-rw-r--r--src/gallium/drivers/svga/svga_swtnl_backend.c4
-rw-r--r--src/gallium/drivers/trace/tr_context.c54
-rw-r--r--src/gallium/drivers/trace/tr_texture.c6
53 files changed, 746 insertions, 1246 deletions
diff --git a/src/gallium/drivers/galahad/glhd_context.c b/src/gallium/drivers/galahad/glhd_context.c
index 354f20a3ad7..92ca4a63da9 100644
--- a/src/gallium/drivers/galahad/glhd_context.c
+++ b/src/gallium/drivers/galahad/glhd_context.c
@@ -877,58 +877,35 @@ galahad_context_surface_destroy(struct pipe_context *_pipe,
}
-
-static struct pipe_transfer *
-galahad_context_get_transfer(struct pipe_context *_context,
- struct pipe_resource *_resource,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box)
+static void *
+galahad_context_transfer_map(struct pipe_context *_context,
+ struct pipe_resource *_resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **transfer)
{
struct galahad_context *glhd_context = galahad_context(_context);
struct galahad_resource *glhd_resource = galahad_resource(_resource);
struct pipe_context *context = glhd_context->pipe;
struct pipe_resource *resource = glhd_resource->resource;
struct pipe_transfer *result;
-
- result = context->get_transfer(context,
- resource,
- level,
- usage,
- box);
-
- if (result)
- return galahad_transfer_create(glhd_context, glhd_resource, result);
- return NULL;
-}
-
-static void
-galahad_context_transfer_destroy(struct pipe_context *_pipe,
- struct pipe_transfer *_transfer)
-{
- galahad_transfer_destroy(galahad_context(_pipe),
- galahad_transfer(_transfer));
-}
-
-static void *
-galahad_context_transfer_map(struct pipe_context *_context,
- struct pipe_transfer *_transfer)
-{
- struct galahad_context *glhd_context = galahad_context(_context);
- struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer);
- struct pipe_context *context = glhd_context->pipe;
- struct pipe_transfer *transfer = glhd_transfer->transfer;
-
- struct galahad_resource *glhd_resource = galahad_resource(_transfer->resource);
+ void *map;
+
+ map = context->transfer_map(context,
+ resource,
+ level,
+ usage,
+ box, &result);
+ if (!map)
+ return NULL;
glhd_resource->map_count++;
- return context->transfer_map(context,
- transfer);
+ *transfer = galahad_transfer_create(glhd_context, glhd_resource, result);
+ return *transfer ? map : NULL;
}
-
-
static void
galahad_context_transfer_flush_region(struct pipe_context *_context,
struct pipe_transfer *_transfer,
@@ -944,7 +921,6 @@ galahad_context_transfer_flush_region(struct pipe_context *_context,
box);
}
-
static void
galahad_context_transfer_unmap(struct pipe_context *_context,
struct pipe_transfer *_transfer)
@@ -964,6 +940,9 @@ galahad_context_transfer_unmap(struct pipe_context *_context,
context->transfer_unmap(context,
transfer);
+
+ galahad_transfer_destroy(galahad_context(_context),
+ galahad_transfer(_transfer));
}
@@ -1088,8 +1067,6 @@ galahad_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
GLHD_PIPE_INIT(sampler_view_destroy);
GLHD_PIPE_INIT(create_surface);
GLHD_PIPE_INIT(surface_destroy);
- GLHD_PIPE_INIT(get_transfer);
- GLHD_PIPE_INIT(transfer_destroy);
GLHD_PIPE_INIT(transfer_map);
GLHD_PIPE_INIT(transfer_flush_region);
GLHD_PIPE_INIT(transfer_unmap);
diff --git a/src/gallium/drivers/galahad/glhd_objects.c b/src/gallium/drivers/galahad/glhd_objects.c
index b44adff20c7..e4a8f28f352 100644
--- a/src/gallium/drivers/galahad/glhd_objects.c
+++ b/src/gallium/drivers/galahad/glhd_objects.c
@@ -173,7 +173,7 @@ galahad_transfer_create(struct galahad_context *glhd_context,
return &glhd_transfer->base;
error:
- glhd_context->pipe->transfer_destroy(glhd_context->pipe, transfer);
+ glhd_context->pipe->transfer_unmap(glhd_context->pipe, transfer);
return NULL;
}
@@ -182,7 +182,5 @@ galahad_transfer_destroy(struct galahad_context *glhd_context,
struct galahad_transfer *glhd_transfer)
{
pipe_resource_reference(&glhd_transfer->base.resource, NULL);
- glhd_context->pipe->transfer_destroy(glhd_context->pipe,
- glhd_transfer->transfer);
FREE(glhd_transfer);
}
diff --git a/src/gallium/drivers/i915/i915_resource.c b/src/gallium/drivers/i915/i915_resource.c
index 253c7d06233..314ebe9551e 100644
--- a/src/gallium/drivers/i915/i915_resource.c
+++ b/src/gallium/drivers/i915/i915_resource.c
@@ -31,11 +31,9 @@ i915_resource_from_handle(struct pipe_screen * screen,
void
i915_init_resource_functions(struct i915_context *i915 )
{
- i915->base.get_transfer = u_get_transfer_vtbl;
i915->base.transfer_map = u_transfer_map_vtbl;
i915->base.transfer_flush_region = u_transfer_flush_region_vtbl;
i915->base.transfer_unmap = u_transfer_unmap_vtbl;
- i915->base.transfer_destroy = u_transfer_destroy_vtbl;
i915->base.transfer_inline_write = u_transfer_inline_write_vtbl;
}
diff --git a/src/gallium/drivers/i915/i915_resource_buffer.c b/src/gallium/drivers/i915/i915_resource_buffer.c
index 77c03450b3a..80ec43a41eb 100644
--- a/src/gallium/drivers/i915/i915_resource_buffer.c
+++ b/src/gallium/drivers/i915/i915_resource_buffer.c
@@ -60,14 +60,16 @@ i915_buffer_destroy(struct pipe_screen *screen,
}
-static struct pipe_transfer *
-i915_get_transfer(struct pipe_context *pipe,
- struct pipe_resource *resource,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box)
+static void *
+i915_buffer_transfer_map(struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
struct i915_context *i915 = i915_context(pipe);
+ struct i915_buffer *buffer = i915_buffer(resource);
struct pipe_transfer *transfer = util_slab_alloc(&i915->transfer_pool);
if (transfer == NULL)
@@ -77,30 +79,19 @@ i915_get_transfer(struct pipe_context *pipe,
transfer->level = level;
transfer->usage = usage;
transfer->box = *box;
+ *ptransfer = transfer;
- /* Note strides are zero, this is ok for buffers, but not for
- * textures 2d & higher at least.
- */
- return transfer;
+ return buffer->data + transfer->box.x;
}
static void
-i915_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
+i915_buffer_transfer_unmap(struct pipe_context *pipe,
+ struct pipe_transfer *transfer)
{
struct i915_context *i915 = i915_context(pipe);
util_slab_free(&i915->transfer_pool, transfer);
}
-static void *
-i915_buffer_transfer_map( struct pipe_context *pipe,
- struct pipe_transfer *transfer )
-{
- struct i915_buffer *buffer = i915_buffer(transfer->resource);
- return buffer->data + transfer->box.x;
-}
-
-
static void
i915_buffer_transfer_inline_write( struct pipe_context *rm_ctx,
struct pipe_resource *resource,
@@ -123,11 +114,9 @@ struct u_resource_vtbl i915_buffer_vtbl =
{
i915_buffer_get_handle, /* get_handle */
i915_buffer_destroy, /* resource_destroy */
- i915_get_transfer, /* get_transfer */
- i915_transfer_destroy, /* transfer_destroy */
i915_buffer_transfer_map, /* transfer_map */
u_default_transfer_flush_region, /* transfer_flush_region */
- u_default_transfer_unmap, /* transfer_unmap */
+ i915_buffer_transfer_unmap, /* transfer_unmap */
i915_buffer_transfer_inline_write /* transfer_inline_write */
};
diff --git a/src/gallium/drivers/i915/i915_resource_texture.c b/src/gallium/drivers/i915/i915_resource_texture.c
index 83437af371a..52ef776b3ce 100644
--- a/src/gallium/drivers/i915/i915_resource_texture.c
+++ b/src/gallium/drivers/i915/i915_resource_texture.c
@@ -705,17 +705,22 @@ i915_texture_destroy(struct pipe_screen *screen,
FREE(tex);
}
-static struct pipe_transfer *
-i915_texture_get_transfer(struct pipe_context *pipe,
+static void *
+i915_texture_transfer_map(struct pipe_context *pipe,
struct pipe_resource *resource,
unsigned level,
unsigned usage,
- const struct pipe_box *box)
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
struct i915_context *i915 = i915_context(pipe);
struct i915_texture *tex = i915_texture(resource);
struct i915_transfer *transfer = util_slab_alloc(&i915->texture_transfer_pool);
boolean use_staging_texture = FALSE;
+ struct i915_winsys *iws = i915_screen(pipe->screen)->iws;
+ enum pipe_format format = resource->format;
+ unsigned offset;
+ char *map;
if (transfer == NULL)
return NULL;
@@ -749,67 +754,32 @@ i915_texture_get_transfer(struct pipe_context *pipe,
transfer->staging_texture = i915_texture_create(pipe->screen, resource, TRUE);
}
- return (struct pipe_transfer*)transfer;
-}
-
-static void
-i915_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct i915_context *i915 = i915_context(pipe);
- struct i915_transfer *itransfer = (struct i915_transfer*)transfer;
-
- if ((itransfer->staging_texture) &&
- (transfer->usage & PIPE_TRANSFER_WRITE)) {
- struct pipe_box sbox;
-
- u_box_origin_2d(itransfer->b.box.width, itransfer->b.box.height, &sbox);
- pipe->resource_copy_region(pipe, itransfer->b.resource, itransfer->b.level,
- itransfer->b.box.x, itransfer->b.box.y, itransfer->b.box.z,
- itransfer->staging_texture,
- 0, &sbox);
- pipe->flush(pipe, NULL);
- pipe_resource_reference(&itransfer->staging_texture, NULL);
- }
-
- util_slab_free(&i915->texture_transfer_pool, itransfer);
-}
-
-static void *
-i915_texture_transfer_map(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct i915_transfer *itransfer = (struct i915_transfer*)transfer;
- struct pipe_resource *resource = itransfer->b.resource;
- struct i915_texture *tex = NULL;
- struct i915_winsys *iws = i915_screen(pipe->screen)->iws;
- struct pipe_box *box = &itransfer->b.box;
- enum pipe_format format = resource->format;
- unsigned offset;
- char *map;
-
if (resource->target != PIPE_TEXTURE_3D &&
resource->target != PIPE_TEXTURE_CUBE)
assert(box->z == 0);
- if (itransfer->staging_texture) {
- tex = i915_texture(itransfer->staging_texture);
+ if (transfer->staging_texture) {
+ tex = i915_texture(transfer->staging_texture);
} else {
/* TODO this is a sledgehammer */
tex = i915_texture(resource);
pipe->flush(pipe, NULL);
}
- offset = i915_texture_offset(tex, itransfer->b.level, box->z);
+ offset = i915_texture_offset(tex, transfer->b.level, box->z);
map = iws->buffer_map(iws, tex->buffer,
- (itransfer->b.usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE);
+ (transfer->b.usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE);
if (map == NULL) {
+ pipe_resource_reference(&transfer->staging_texture, NULL);
+ FREE(transfer);
return NULL;
}
+ *ptransfer = &transfer->b;
+
return map + offset +
- box->y / util_format_get_blockheight(format) * itransfer->b.stride +
+ box->y / util_format_get_blockheight(format) * transfer->b.stride +
box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
}
@@ -817,6 +787,7 @@ static void
i915_texture_transfer_unmap(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
+ struct i915_context *i915 = i915_context(pipe);
struct i915_transfer *itransfer = (struct i915_transfer*)transfer;
struct i915_texture *tex = i915_texture(itransfer->b.resource);
struct i915_winsys *iws = i915_screen(tex->b.b.screen)->iws;
@@ -825,8 +796,24 @@ i915_texture_transfer_unmap(struct pipe_context *pipe,
tex = i915_texture(itransfer->staging_texture);
iws->buffer_unmap(iws, tex->buffer);
+
+ if ((itransfer->staging_texture) &&
+ (transfer->usage & PIPE_TRANSFER_WRITE)) {
+ struct pipe_box sbox;
+
+ u_box_origin_2d(itransfer->b.box.width, itransfer->b.box.height, &sbox);
+ pipe->resource_copy_region(pipe, itransfer->b.resource, itransfer->b.level,
+ itransfer->b.box.x, itransfer->b.box.y, itransfer->b.box.z,
+ itransfer->staging_texture,
+ 0, &sbox);
+ pipe->flush(pipe, NULL);
+ pipe_resource_reference(&itransfer->staging_texture, NULL);
+ }
+
+ util_slab_free(&i915->texture_transfer_pool, itransfer);
}
+#if 0
static void i915_transfer_inline_write( struct pipe_context *pipe,
struct pipe_resource *resource,
unsigned level,
@@ -841,7 +828,7 @@ static void i915_transfer_inline_write( struct pipe_context *pipe,
const uint8_t *src_data = data;
unsigned i;
- transfer = pipe->get_transfer(pipe,
+ transfer = pipe->transfer_get(pipe,
resource,
level,
usage,
@@ -913,24 +900,19 @@ out:
if (itransfer)
pipe_transfer_destroy(pipe, &itransfer->b);
}
-
-
+#endif
struct u_resource_vtbl i915_texture_vtbl =
{
i915_texture_get_handle, /* get_handle */
i915_texture_destroy, /* resource_destroy */
- i915_texture_get_transfer, /* get_transfer */
- i915_transfer_destroy, /* transfer_destroy */
i915_texture_transfer_map, /* transfer_map */
u_default_transfer_flush_region, /* transfer_flush_region */
i915_texture_transfer_unmap, /* transfer_unmap */
- i915_transfer_inline_write /* transfer_inline_write */
+ u_default_transfer_inline_write /* transfer_inline_write */
};
-
-
struct pipe_resource *
i915_texture_create(struct pipe_screen *screen,
const struct pipe_resource *template,
diff --git a/src/gallium/drivers/identity/id_context.c b/src/gallium/drivers/identity/id_context.c
index cf0a3f9aa40..fb2f78764a4 100644
--- a/src/gallium/drivers/identity/id_context.c
+++ b/src/gallium/drivers/identity/id_context.c
@@ -776,53 +776,34 @@ identity_context_surface_destroy(struct pipe_context *_pipe,
identity_surface(_surf));
}
-static struct pipe_transfer *
-identity_context_get_transfer(struct pipe_context *_context,
+static void *
+identity_context_transfer_map(struct pipe_context *_context,
struct pipe_resource *_resource,
unsigned level,
unsigned usage,
- const struct pipe_box *box)
+ const struct pipe_box *box,
+ struct pipe_transfer **transfer)
{
struct identity_context *id_context = identity_context(_context);
struct identity_resource *id_resource = identity_resource(_resource);
struct pipe_context *context = id_context->pipe;
struct pipe_resource *resource = id_resource->resource;
struct pipe_transfer *result;
+ void *map;
- result = context->get_transfer(context,
- resource,
- level,
- usage,
- box);
-
- if (result)
- return identity_transfer_create(id_context, id_resource, result);
- return NULL;
-}
+ map = context->transfer_map(context,
+ resource,
+ level,
+ usage,
+ box, &result);
-static void
-identity_context_transfer_destroy(struct pipe_context *_pipe,
- struct pipe_transfer *_transfer)
-{
- identity_transfer_destroy(identity_context(_pipe),
- identity_transfer(_transfer));
-}
-
-static void *
-identity_context_transfer_map(struct pipe_context *_context,
- struct pipe_transfer *_transfer)
-{
- struct identity_context *id_context = identity_context(_context);
- struct identity_transfer *id_transfer = identity_transfer(_transfer);
- struct pipe_context *context = id_context->pipe;
- struct pipe_transfer *transfer = id_transfer->transfer;
+ if (!map)
+ return NULL;
- return context->transfer_map(context,
- transfer);
+ *transfer = identity_transfer_map(id_context, id_resource, result);
+ return *transfer ? map : NULL;
}
-
-
static void
identity_context_transfer_flush_region(struct pipe_context *_context,
struct pipe_transfer *_transfer,
@@ -850,6 +831,9 @@ identity_context_transfer_unmap(struct pipe_context *_context,
context->transfer_unmap(context,
transfer);
+
+ identity_transfer_destroy(identity_context(_context),
+ identity_transfer(_transfer));
}
@@ -945,8 +929,6 @@ identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
id_pipe->base.surface_destroy = identity_context_surface_destroy;
id_pipe->base.create_sampler_view = identity_context_create_sampler_view;
id_pipe->base.sampler_view_destroy = identity_context_sampler_view_destroy;
- id_pipe->base.get_transfer = identity_context_get_transfer;
- id_pipe->base.transfer_destroy = identity_context_transfer_destroy;
id_pipe->base.transfer_map = identity_context_transfer_map;
id_pipe->base.transfer_unmap = identity_context_transfer_unmap;
id_pipe->base.transfer_flush_region = identity_context_transfer_flush_region;
diff --git a/src/gallium/drivers/identity/id_objects.c b/src/gallium/drivers/identity/id_objects.c
index 63454410525..a26d9874870 100644
--- a/src/gallium/drivers/identity/id_objects.c
+++ b/src/gallium/drivers/identity/id_objects.c
@@ -149,9 +149,9 @@ identity_sampler_view_destroy(struct identity_context *id_context,
struct pipe_transfer *
-identity_transfer_create(struct identity_context *id_context,
- struct identity_resource *id_resource,
- struct pipe_transfer *transfer)
+identity_transfer_map(struct identity_context *id_context,
+ struct identity_resource *id_resource,
+ struct pipe_transfer *transfer)
{
struct identity_transfer *id_transfer;
@@ -175,7 +175,7 @@ identity_transfer_create(struct identity_context *id_context,
return &id_transfer->base;
error:
- id_context->pipe->transfer_destroy(id_context->pipe, transfer);
+ id_context->pipe->transfer_unmap(id_context->pipe, transfer);
return NULL;
}
@@ -184,8 +184,6 @@ identity_transfer_destroy(struct identity_context *id_context,
struct identity_transfer *id_transfer)
{
pipe_resource_reference(&id_transfer->base.resource, NULL);
- id_context->pipe->transfer_destroy(id_context->pipe,
- id_transfer->transfer);
FREE(id_transfer);
}
diff --git a/src/gallium/drivers/identity/id_objects.h b/src/gallium/drivers/identity/id_objects.h
index 181f2d6623e..67049436247 100644
--- a/src/gallium/drivers/identity/id_objects.h
+++ b/src/gallium/drivers/identity/id_objects.h
@@ -165,7 +165,7 @@ identity_sampler_view_destroy(struct identity_context *id_context,
struct identity_sampler_view *id_sampler_view);
struct pipe_transfer *
-identity_transfer_create(struct identity_context *id_context,
+identity_transfer_map(struct identity_context *id_context,
struct identity_resource *id_resource,
struct pipe_transfer *transfer);
diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c
index 841df004d14..b4ea94ca1ae 100644
--- a/src/gallium/drivers/llvmpipe/lp_texture.c
+++ b/src/gallium/drivers/llvmpipe/lp_texture.c
@@ -622,16 +622,23 @@ llvmpipe_surface_destroy(struct pipe_context *pipe,
}
-static struct pipe_transfer *
-llvmpipe_get_transfer(struct pipe_context *pipe,
- struct pipe_resource *resource,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box)
+static void *
+llvmpipe_transfer_map( struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **transfer )
{
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
- struct llvmpipe_resource *lprex = llvmpipe_resource(resource);
- struct llvmpipe_transfer *lpr;
+ struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen);
+ struct llvmpipe_resource *lpr = llvmpipe_resource(resource);
+ struct llvmpipe_transfer *lpt;
+ struct pipe_transfer *pt;
+ ubyte *map;
+ enum pipe_format format;
+ enum lp_texture_usage tex_usage;
+ const char *mode;
assert(resource);
assert(level <= resource->last_level);
@@ -661,48 +668,19 @@ llvmpipe_get_transfer(struct pipe_context *pipe,
if (resource == llvmpipe->constants[PIPE_SHADER_FRAGMENT][0])
llvmpipe->dirty |= LP_NEW_CONSTANTS;
- lpr = CALLOC_STRUCT(llvmpipe_transfer);
- if (lpr) {
- struct pipe_transfer *pt = &lpr->base;
- pipe_resource_reference(&pt->resource, resource);
- pt->box = *box;
- pt->level = level;
- pt->stride = lprex->row_stride[level];
- pt->layer_stride = lprex->img_stride[level];
- pt->usage = usage;
-
- return pt;
- }
- return NULL;
-}
-
-
-static void
-llvmpipe_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- /* Effectively do the texture_update work here - if texture images
- * needed post-processing to put them into hardware layout, this is
- * where it would happen. For llvmpipe, nothing to do.
- */
- assert (transfer->resource);
- pipe_resource_reference(&transfer->resource, NULL);
- FREE(transfer);
-}
-
-
-static void *
-llvmpipe_transfer_map( struct pipe_context *pipe,
- struct pipe_transfer *transfer )
-{
- struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen);
- ubyte *map;
- struct llvmpipe_resource *lpr;
- enum pipe_format format;
- enum lp_texture_usage tex_usage;
- const char *mode;
+ lpt = CALLOC_STRUCT(llvmpipe_transfer);
+ if (!lpt)
+ return NULL;
+ pt = &lpt->base;
+ pipe_resource_reference(&pt->resource, resource);
+ pt->box = *box;
+ pt->level = level;
+ pt->stride = lpr->row_stride[level];
+ pt->layer_stride = lpr->img_stride[level];
+ pt->usage = usage;
+ *transfer = pt;
- assert(transfer->level < LP_MAX_TEXTURE_LEVELS);
+ assert(level < LP_MAX_TEXTURE_LEVELS);
/*
printf("tex_transfer_map(%d, %d %d x %d of %d x %d, usage %d )\n",
@@ -712,7 +690,7 @@ llvmpipe_transfer_map( struct pipe_context *pipe,
transfer->usage);
*/
- if (transfer->usage == PIPE_TRANSFER_READ) {
+ if (usage == PIPE_TRANSFER_READ) {
tex_usage = LP_TEX_USAGE_READ;
mode = "read";
}
@@ -722,33 +700,29 @@ llvmpipe_transfer_map( struct pipe_context *pipe,
}
if (0) {
- struct llvmpipe_resource *lpr = llvmpipe_resource(transfer->resource);
printf("transfer map tex %u mode %s\n", lpr->id, mode);
}
-
- assert(transfer->resource);
- lpr = llvmpipe_resource(transfer->resource);
format = lpr->base.format;
- map = llvmpipe_resource_map(transfer->resource,
- transfer->level,
- transfer->box.z,
+ map = llvmpipe_resource_map(resource,
+ level,
+ box->z,
tex_usage, LP_TEX_LAYOUT_LINEAR);
/* May want to do different things here depending on read/write nature
* of the map:
*/
- if (transfer->usage & PIPE_TRANSFER_WRITE) {
+ if (usage & PIPE_TRANSFER_WRITE) {
/* Do something to notify sharing contexts of a texture change.
*/
screen->timestamp++;
}
map +=
- transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
- transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
+ box->y / util_format_get_blockheight(format) * pt->stride +
+ box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
return map;
}
@@ -763,6 +737,14 @@ llvmpipe_transfer_unmap(struct pipe_context *pipe,
llvmpipe_resource_unmap(transfer->resource,
transfer->level,
transfer->box.z);
+
+ /* Effectively do the texture_update work here - if texture images
+ * needed post-processing to put them into hardware layout, this is
+ * where it would happen. For llvmpipe, nothing to do.
+ */
+ assert (transfer->resource);
+ pipe_resource_reference(&transfer->resource, NULL);
+ FREE(transfer);
}
unsigned int
@@ -1474,8 +1456,6 @@ llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen)
void
llvmpipe_init_context_resource_funcs(struct pipe_context *pipe)
{
- pipe->get_transfer = llvmpipe_get_transfer;
- pipe->transfer_destroy = llvmpipe_transfer_destroy;
pipe->transfer_map = llvmpipe_transfer_map;
pipe->transfer_unmap = llvmpipe_transfer_unmap;
diff --git a/src/gallium/drivers/noop/noop_pipe.c b/src/gallium/drivers/noop/noop_pipe.c
index 6411418c3fe..b7c73cf084d 100644
--- a/src/gallium/drivers/noop/noop_pipe.c
+++ b/src/gallium/drivers/noop/noop_pipe.c
@@ -146,32 +146,28 @@ static void noop_resource_destroy(struct pipe_screen *screen,
/*
* transfer
*/
-static struct pipe_transfer *noop_get_transfer(struct pipe_context *context,
- struct pipe_resource *resource,
- unsigned level,
- enum pipe_transfer_usage usage,
- const struct pipe_box *box)
-{
- struct pipe_transfer *transfer;
-
- transfer = CALLOC_STRUCT(pipe_transfer);
- if (transfer == NULL)
- return NULL;
- pipe_resource_reference(&transfer->resource, resource);
- transfer->level = level;
- transfer->usage = usage;
- transfer->box = *box;
- transfer->stride = 1;
- transfer->layer_stride = 1;
- return transfer;
-}
-
static void *noop_transfer_map(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
+ struct pipe_resource *resource,
+ unsigned level,
+ enum pipe_transfer_usage usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
- struct noop_resource *nresource = (struct noop_resource *)transfer->resource;
+ struct pipe_transfer *transfer;
+ struct noop_resource *nresource = (struct noop_resource *)resource;
+
+ transfer = CALLOC_STRUCT(pipe_transfer);
+ if (transfer == NULL)
+ return NULL;
+ pipe_resource_reference(&transfer->resource, resource);
+ transfer->level = level;
+ transfer->usage = usage;
+ transfer->box = *box;
+ transfer->stride = 1;
+ transfer->layer_stride = 1;
+ *ptransfer = transfer;
- return nresource->data;
+ return nresource->data;
}
static void noop_transfer_flush_region(struct pipe_context *pipe,
@@ -183,13 +179,8 @@ static void noop_transfer_flush_region(struct pipe_context *pipe,
static void noop_transfer_unmap(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
-}
-
-static void noop_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- pipe_resource_reference(&transfer->resource, NULL);
- FREE(transfer);
+ pipe_resource_reference(&transfer->resource, NULL);
+ FREE(transfer);
}
static void noop_transfer_inline_write(struct pipe_context *pipe,
@@ -280,11 +271,9 @@ static struct pipe_context *noop_create_context(struct pipe_screen *screen, void
ctx->begin_query = noop_begin_query;
ctx->end_query = noop_end_query;
ctx->get_query_result = noop_get_query_result;
- ctx->get_transfer = noop_get_transfer;
ctx->transfer_map = noop_transfer_map;
ctx->transfer_flush_region = noop_transfer_flush_region;
ctx->transfer_unmap = noop_transfer_unmap;
- ctx->transfer_destroy = noop_transfer_destroy;
ctx->transfer_inline_write = noop_transfer_inline_write;
noop_init_state_functions(ctx);
diff --git a/src/gallium/drivers/nouveau/nouveau_buffer.c b/src/gallium/drivers/nouveau/nouveau_buffer.c
index e83aae0bba5..f16345d540e 100644
--- a/src/gallium/drivers/nouveau/nouveau_buffer.c
+++ b/src/gallium/drivers/nouveau/nouveau_buffer.c
@@ -167,54 +167,6 @@ nouveau_buffer_upload(struct nouveau_context *nv, struct nv04_resource *buf,
return TRUE;
}
-static struct pipe_transfer *
-nouveau_buffer_transfer_get(struct pipe_context *pipe,
- struct pipe_resource *resource,
- unsigned level, unsigned usage,
- const struct pipe_box *box)
-{
- struct nv04_resource *buf = nv04_resource(resource);
- struct nouveau_context *nv = nouveau_context(pipe);
- struct nouveau_transfer *xfr = CALLOC_STRUCT(nouveau_transfer);
- if (!xfr)
- return NULL;
-
- xfr->base.resource = resource;
- xfr->base.box.x = box->x;
- xfr->base.box.width = box->width;
- xfr->base.usage = usage;
-
- if (buf->domain == NOUVEAU_BO_VRAM) {
- if (usage & PIPE_TRANSFER_READ) {
- if (buf->status & NOUVEAU_BUFFER_STATUS_GPU_WRITING)
- nouveau_buffer_download(nv, buf, 0, buf->base.width0);
- }
- }
-
- return &xfr->base;
-}
-
-static void
-nouveau_buffer_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct nv04_resource *buf = nv04_resource(transfer->resource);
- struct nouveau_transfer *xfr = nouveau_transfer(transfer);
- struct nouveau_context *nv = nouveau_context(pipe);
-
- if (xfr->base.usage & PIPE_TRANSFER_WRITE) {
- if (buf->domain == NOUVEAU_BO_VRAM) {
- nouveau_buffer_upload(nv, buf, transfer->box.x, transfer->box.width);
- }
-
- if (buf->domain != 0 && (buf->base.bind & (PIPE_BIND_VERTEX_BUFFER |
- PIPE_BIND_INDEX_BUFFER)))
- nouveau_context(pipe)->vbo_dirty = TRUE;
- }
-
- FREE(xfr);
-}
-
static INLINE boolean
nouveau_buffer_sync(struct nv04_resource *buf, unsigned rw)
{
@@ -247,19 +199,39 @@ nouveau_buffer_busy(struct nv04_resource *buf, unsigned rw)
static void *
nouveau_buffer_transfer_map(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
+ struct pipe_resource *resource,
+ unsigned level, unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
+ struct nv04_resource *buf = nv04_resource(resource);
struct nouveau_context *nv = nouveau_context(pipe);
- struct nouveau_transfer *xfr = nouveau_transfer(transfer);
- struct nv04_resource *buf = nv04_resource(transfer->resource);
+ struct nouveau_transfer *xfr = CALLOC_STRUCT(nouveau_transfer);
struct nouveau_bo *bo = buf->bo;
uint8_t *map;
int ret;
uint32_t offset = xfr->base.box.x;
uint32_t flags = 0;
- if (buf->domain != NOUVEAU_BO_GART)
+ if (!xfr)
+ return NULL;
+
+ xfr->base.resource = resource;
+ xfr->base.box.x = box->x;
+ xfr->base.box.width = box->width;
+ xfr->base.usage = usage;
+
+ if (buf->domain == NOUVEAU_BO_VRAM) {
+ if (usage & PIPE_TRANSFER_READ) {
+ if (buf->status & NOUVEAU_BUFFER_STATUS_GPU_WRITING)
+ nouveau_buffer_download(nv, buf, 0, buf->base.width0);
+ }
+ }
+
+ if (buf->domain != NOUVEAU_BO_GART) {
+ *ptransfer = &xfr->base;
return buf->data + offset;
+ }
if (!buf->mm)
flags = nouveau_screen_transfer_flags(xfr->base.usage);
@@ -267,19 +239,24 @@ nouveau_buffer_transfer_map(struct pipe_context *pipe,
offset += buf->offset;
ret = nouveau_bo_map(buf->bo, flags, nv->screen->client);
- if (ret)
+ if (ret) {
+ FREE(xfr);
return NULL;
+ }
map = (uint8_t *)bo->map + offset;
if (buf->mm) {
if (xfr->base.usage & PIPE_TRANSFER_DONTBLOCK) {
- if (nouveau_buffer_busy(buf, xfr->base.usage & PIPE_TRANSFER_READ_WRITE))
+ if (nouveau_buffer_busy(buf, xfr->base.usage & PIPE_TRANSFER_READ_WRITE)) {
+ FREE(xfr);
return NULL;
+ }
} else
if (!(xfr->base.usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
nouveau_buffer_sync(buf, xfr->base.usage & PIPE_TRANSFER_READ_WRITE);
}
}
+ *ptransfer = &xfr->base;
return map;
}
@@ -307,6 +284,21 @@ static void
nouveau_buffer_transfer_unmap(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
+ struct nv04_resource *buf = nv04_resource(transfer->resource);
+ struct nouveau_transfer *xfr = nouveau_transfer(transfer);
+ struct nouveau_context *nv = nouveau_context(pipe);
+
+ if (xfr->base.usage & PIPE_TRANSFER_WRITE) {
+ if (buf->domain == NOUVEAU_BO_VRAM) {
+ nouveau_buffer_upload(nv, buf, transfer->box.x, transfer->box.width);
+ }
+
+ if (buf->domain != 0 && (buf->base.bind & (PIPE_BIND_VERTEX_BUFFER |
+ PIPE_BIND_INDEX_BUFFER)))
+ nouveau_context(pipe)->vbo_dirty = TRUE;
+ }
+
+ FREE(xfr);
}
@@ -341,8 +333,6 @@ const struct u_resource_vtbl nouveau_buffer_vtbl =
{
u_default_resource_get_handle, /* get_handle */
nouveau_buffer_destroy, /* resource_destroy */
- nouveau_buffer_transfer_get, /* get_transfer */
- nouveau_buffer_transfer_destroy, /* transfer_destroy */
nouveau_buffer_transfer_map, /* transfer_map */
nouveau_buffer_transfer_flush_region, /* transfer_flush_region */
nouveau_buffer_transfer_unmap, /* transfer_unmap */
diff --git a/src/gallium/drivers/nv30/nv30_miptree.c b/src/gallium/drivers/nv30/nv30_miptree.c
index 9700fa8cb4b..e89725feb2f 100644
--- a/src/gallium/drivers/nv30/nv30_miptree.c
+++ b/src/gallium/drivers/nv30/nv30_miptree.c
@@ -218,14 +218,16 @@ nv30_blit(struct pipe_context *pipe,
util_blitter_blit(nv30->blitter, &info);
}
-static struct pipe_transfer *
-nv30_miptree_transfer_new(struct pipe_context *pipe, struct pipe_resource *pt,
+static void *
+nv30_miptree_transfer_map(struct pipe_context *pipe, struct pipe_resource *pt,
unsigned level, unsigned usage,
- const struct pipe_box *box)
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
struct nv30_context *nv30 = nv30_context(pipe);
struct nouveau_device *dev = nv30->screen->base.device;
struct nv30_transfer *tx;
+ unsigned access = 0;
int ret;
tx = CALLOC_STRUCT(nv30_transfer);
@@ -270,42 +272,24 @@ nv30_miptree_transfer_new(struct pipe_context *pipe, struct pipe_resource *pt,
if (usage & PIPE_TRANSFER_READ)
nv30_transfer_rect(nv30, NEAREST, &tx->img, &tx->tmp);
- return &tx->base;
-}
-
-static void
-nv30_miptree_transfer_del(struct pipe_context *pipe, struct pipe_transfer *ptx)
-{
- struct nv30_context *nv30 = nv30_context(pipe);
- struct nv30_transfer *tx = nv30_transfer(ptx);
-
- if (ptx->usage & PIPE_TRANSFER_WRITE)
- nv30_transfer_rect(nv30, NEAREST, &tx->tmp, &tx->img);
-
- nouveau_bo_ref(NULL, &tx->tmp.bo);
- pipe_resource_reference(&ptx->resource, NULL);
- FREE(tx);
-}
-
-static void *
-nv30_miptree_transfer_map(struct pipe_context *pipe, struct pipe_transfer *ptx)
-{
- struct nv30_context *nv30 = nv30_context(pipe);
- struct nv30_transfer *tx = nv30_transfer(ptx);
- unsigned access = 0;
- int ret;
-
- if (tx->tmp.bo->map)
+ if (tx->tmp.bo->map) {
+ *ptransfer = &tx->base;
return tx->tmp.bo->map;
+ }
- if (ptx->usage & PIPE_TRANSFER_READ)
+ if (usage & PIPE_TRANSFER_READ)
access |= NOUVEAU_BO_RD;
- if (ptx->usage & PIPE_TRANSFER_WRITE)
+ if (usage & PIPE_TRANSFER_WRITE)
access |= NOUVEAU_BO_WR;
ret = nouveau_bo_map(tx->tmp.bo, access, nv30->base.client);
- if (ret)
+ if (ret) {
+ pipe_resource_reference(&tx->base.resource, NULL);
+ FREE(tx);
return NULL;
+ }
+
+ *ptransfer = &tx->base;
return tx->tmp.bo->map;
}
@@ -313,13 +297,20 @@ static void
nv30_miptree_transfer_unmap(struct pipe_context *pipe,
struct pipe_transfer *ptx)
{
+ struct nv30_context *nv30 = nv30_context(pipe);
+ struct nv30_transfer *tx = nv30_transfer(ptx);
+
+ if (ptx->usage & PIPE_TRANSFER_WRITE)
+ nv30_transfer_rect(nv30, NEAREST, &tx->tmp, &tx->img);
+
+ nouveau_bo_ref(NULL, &tx->tmp.bo);
+ pipe_resource_reference(&ptx->resource, NULL);
+ FREE(tx);
}
const struct u_resource_vtbl nv30_miptree_vtbl = {
nv30_miptree_get_handle,
nv30_miptree_destroy,
- nv30_miptree_transfer_new,
- nv30_miptree_transfer_del,
nv30_miptree_transfer_map,
u_default_transfer_flush_region,
nv30_miptree_transfer_unmap,
diff --git a/src/gallium/drivers/nv30/nv30_resource.c b/src/gallium/drivers/nv30/nv30_resource.c
index 4d2a2284a75..f3bc8f1ee1b 100644
--- a/src/gallium/drivers/nv30/nv30_resource.c
+++ b/src/gallium/drivers/nv30/nv30_resource.c
@@ -66,11 +66,9 @@ nv30_resource_screen_init(struct pipe_screen *pscreen)
void
nv30_resource_init(struct pipe_context *pipe)
{
- pipe->get_transfer = u_get_transfer_vtbl;
pipe->transfer_map = u_transfer_map_vtbl;
pipe->transfer_flush_region = u_transfer_flush_region_vtbl;
pipe->transfer_unmap = u_transfer_unmap_vtbl;
- pipe->transfer_destroy = u_transfer_destroy_vtbl;
pipe->transfer_inline_write = u_transfer_inline_write_vtbl;
pipe->create_surface = nv30_miptree_surface_new;
pipe->surface_destroy = nv30_miptree_surface_del;
diff --git a/src/gallium/drivers/nv50/nv50_miptree.c b/src/gallium/drivers/nv50/nv50_miptree.c
index 70e8c7788ea..568526c5933 100644
--- a/src/gallium/drivers/nv50/nv50_miptree.c
+++ b/src/gallium/drivers/nv50/nv50_miptree.c
@@ -145,8 +145,6 @@ const struct u_resource_vtbl nv50_miptree_vtbl =
{
nv50_miptree_get_handle, /* get_handle */
nv50_miptree_destroy, /* resource_destroy */
- nv50_miptree_transfer_new, /* get_transfer */
- nv50_miptree_transfer_del, /* transfer_destroy */
nv50_miptree_transfer_map, /* transfer_map */
u_default_transfer_flush_region, /* transfer_flush_region */
nv50_miptree_transfer_unmap, /* transfer_unmap */
diff --git a/src/gallium/drivers/nv50/nv50_resource.c b/src/gallium/drivers/nv50/nv50_resource.c
index 9fe18a6d09d..42fefa61efc 100644
--- a/src/gallium/drivers/nv50/nv50_resource.c
+++ b/src/gallium/drivers/nv50/nv50_resource.c
@@ -86,11 +86,9 @@ nv50_surface_destroy(struct pipe_context *pipe, struct pipe_surface *ps)
void
nv50_init_resource_functions(struct pipe_context *pcontext)
{
- pcontext->get_transfer = u_get_transfer_vtbl;
pcontext->transfer_map = u_transfer_map_vtbl;
pcontext->transfer_flush_region = u_transfer_flush_region_vtbl;
pcontext->transfer_unmap = u_transfer_unmap_vtbl;
- pcontext->transfer_destroy = u_transfer_destroy_vtbl;
pcontext->transfer_inline_write = u_transfer_inline_write_vtbl;
pcontext->create_surface = nv50_surface_create;
pcontext->surface_destroy = nv50_surface_destroy;
diff --git a/src/gallium/drivers/nv50/nv50_resource.h b/src/gallium/drivers/nv50/nv50_resource.h
index c1b159e1244..48089557082 100644
--- a/src/gallium/drivers/nv50/nv50_resource.h
+++ b/src/gallium/drivers/nv50/nv50_resource.h
@@ -123,18 +123,13 @@ nv50_miptree_surface_new(struct pipe_context *,
struct pipe_resource *,
const struct pipe_surface *templ);
-struct pipe_transfer *
-nv50_miptree_transfer_new(struct pipe_context *pcontext,
- struct pipe_resource *pt,
+void *
+nv50_miptree_transfer_map(struct pipe_context *pctx,
+ struct pipe_resource *res,
unsigned level,
unsigned usage,
- const struct pipe_box *box);
-void
-nv50_miptree_transfer_del(struct pipe_context *pcontext,
- struct pipe_transfer *ptx);
-void *
-nv50_miptree_transfer_map(struct pipe_context *pcontext,
- struct pipe_transfer *ptx);
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer);
void
nv50_miptree_transfer_unmap(struct pipe_context *pcontext,
struct pipe_transfer *ptx);
diff --git a/src/gallium/drivers/nv50/nv50_transfer.c b/src/gallium/drivers/nv50/nv50_transfer.c
index b960dc0d191..25319d785e4 100644
--- a/src/gallium/drivers/nv50/nv50_transfer.c
+++ b/src/gallium/drivers/nv50/nv50_transfer.c
@@ -246,19 +246,22 @@ nv50_m2mf_copy_linear(struct nouveau_context *nv,
nouveau_bufctx_reset(bctx, 0);
}
-struct pipe_transfer *
-nv50_miptree_transfer_new(struct pipe_context *pctx,
+void *
+nv50_miptree_transfer_map(struct pipe_context *pctx,
struct pipe_resource *res,
unsigned level,
unsigned usage,
- const struct pipe_box *box)
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
+ struct nv50_screen *screen = nv50_screen(pctx->screen);
struct nv50_context *nv50 = nv50_context(pctx);
struct nouveau_device *dev = nv50->screen->base.device;
const struct nv50_miptree *mt = nv50_miptree(res);
struct nv50_transfer *tx;
uint32_t size;
int ret;
+ unsigned flags = 0;
if (usage & PIPE_TRANSFER_MAP_DIRECTLY)
return NULL;
@@ -320,12 +323,30 @@ nv50_miptree_transfer_new(struct pipe_context *pctx,
tx->rect[1].base = 0;
}
- return &tx->base;
+ if (tx->rect[1].bo->map) {
+ *ptransfer = &tx->base;
+ return tx->rect[1].bo->map;
+ }
+
+ if (usage & PIPE_TRANSFER_READ)
+ flags = NOUVEAU_BO_RD;
+ if (usage & PIPE_TRANSFER_WRITE)
+ flags |= NOUVEAU_BO_WR;
+
+ ret = nouveau_bo_map(tx->rect[1].bo, flags, screen->base.client);
+ if (ret) {
+ nouveau_bo_ref(NULL, &tx->rect[1].bo);
+ FREE(tx);
+ return NULL;
+ }
+
+ *ptransfer = &tx->base;
+ return tx->rect[1].bo->map;
}
void
-nv50_miptree_transfer_del(struct pipe_context *pctx,
- struct pipe_transfer *transfer)
+nv50_miptree_transfer_unmap(struct pipe_context *pctx,
+ struct pipe_transfer *transfer)
{
struct nv50_context *nv50 = nv50_context(pctx);
struct nv50_transfer *tx = (struct nv50_transfer *)transfer;
@@ -350,36 +371,6 @@ nv50_miptree_transfer_del(struct pipe_context *pctx,
FREE(tx);
}
-void *
-nv50_miptree_transfer_map(struct pipe_context *pctx,
- struct pipe_transfer *transfer)
-{
- struct nv50_screen *screen = nv50_screen(pctx->screen);
- struct nv50_transfer *tx = (struct nv50_transfer *)transfer;
- int ret;
- unsigned flags = 0;
-
- if (tx->rect[1].bo->map)
- return tx->rect[1].bo->map;
-
- if (transfer->usage & PIPE_TRANSFER_READ)
- flags = NOUVEAU_BO_RD;
- if (transfer->usage & PIPE_TRANSFER_WRITE)
- flags |= NOUVEAU_BO_WR;
-
- ret = nouveau_bo_map(tx->rect[1].bo, flags, screen->base.client);
- if (ret)
- return NULL;
- return tx->rect[1].bo->map;
-}
-
-void
-nv50_miptree_transfer_unmap(struct pipe_context *pctx,
- struct pipe_transfer *transfer)
-{
- /* nothing to do */
-}
-
void
nv50_cb_push(struct nouveau_context *nv,
struct nouveau_bo *bo, unsigned domain,
diff --git a/src/gallium/drivers/nvc0/nvc0_miptree.c b/src/gallium/drivers/nvc0/nvc0_miptree.c
index 591ac4402db..b63f196eecd 100644
--- a/src/gallium/drivers/nvc0/nvc0_miptree.c
+++ b/src/gallium/drivers/nvc0/nvc0_miptree.c
@@ -259,8 +259,6 @@ const struct u_resource_vtbl nvc0_miptree_vtbl =
{
nv50_miptree_get_handle, /* get_handle */
nv50_miptree_destroy, /* resource_destroy */
- nvc0_miptree_transfer_new, /* get_transfer */
- nvc0_miptree_transfer_del, /* transfer_destroy */
nvc0_miptree_transfer_map, /* transfer_map */
u_default_transfer_flush_region, /* transfer_flush_region */
nvc0_miptree_transfer_unmap, /* transfer_unmap */
diff --git a/src/gallium/drivers/nvc0/nvc0_resource.c b/src/gallium/drivers/nvc0/nvc0_resource.c
index daf5c907a05..162399f2e48 100644
--- a/src/gallium/drivers/nvc0/nvc0_resource.c
+++ b/src/gallium/drivers/nvc0/nvc0_resource.c
@@ -44,11 +44,9 @@ nvc0_surface_create(struct pipe_context *pipe,
void
nvc0_init_resource_functions(struct pipe_context *pcontext)
{
- pcontext->get_transfer = u_get_transfer_vtbl;
pcontext->transfer_map = u_transfer_map_vtbl;
pcontext->transfer_flush_region = u_transfer_flush_region_vtbl;
pcontext->transfer_unmap = u_transfer_unmap_vtbl;
- pcontext->transfer_destroy = u_transfer_destroy_vtbl;
pcontext->transfer_inline_write = u_transfer_inline_write_vtbl;
pcontext->create_surface = nvc0_surface_create;
pcontext->surface_destroy = nv50_surface_destroy;
diff --git a/src/gallium/drivers/nvc0/nvc0_resource.h b/src/gallium/drivers/nvc0/nvc0_resource.h
index 41b1667b2e4..0d5f026d6e1 100644
--- a/src/gallium/drivers/nvc0/nvc0_resource.h
+++ b/src/gallium/drivers/nvc0/nvc0_resource.h
@@ -44,18 +44,13 @@ nvc0_miptree_surface_new(struct pipe_context *,
unsigned
nvc0_mt_zslice_offset(const struct nv50_miptree *, unsigned l, unsigned z);
-struct pipe_transfer *
-nvc0_miptree_transfer_new(struct pipe_context *pcontext,
- struct pipe_resource *pt,
+void *
+nvc0_miptree_transfer_map(struct pipe_context *pctx,
+ struct pipe_resource *res,
unsigned level,
unsigned usage,
- const struct pipe_box *box);
-void
-nvc0_miptree_transfer_del(struct pipe_context *pcontext,
- struct pipe_transfer *ptx);
-void *
-nvc0_miptree_transfer_map(struct pipe_context *pcontext,
- struct pipe_transfer *ptx);
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer);
void
nvc0_miptree_transfer_unmap(struct pipe_context *pcontext,
struct pipe_transfer *ptx);
diff --git a/src/gallium/drivers/nvc0/nvc0_transfer.c b/src/gallium/drivers/nvc0/nvc0_transfer.c
index 58dcd862c99..66753c9135b 100644
--- a/src/gallium/drivers/nvc0/nvc0_transfer.c
+++ b/src/gallium/drivers/nvc0/nvc0_transfer.c
@@ -326,12 +326,13 @@ nve4_m2mf_copy_linear(struct nouveau_context *nv,
nouveau_bufctx_reset(bctx, 0);
}
-struct pipe_transfer *
-nvc0_miptree_transfer_new(struct pipe_context *pctx,
+void *
+nvc0_miptree_transfer_map(struct pipe_context *pctx,
struct pipe_resource *res,
unsigned level,
unsigned usage,
- const struct pipe_box *box)
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
struct nvc0_context *nvc0 = nvc0_context(pctx);
struct nouveau_device *dev = nvc0->screen->base.device;
@@ -339,6 +340,7 @@ nvc0_miptree_transfer_new(struct pipe_context *pctx,
struct nvc0_transfer *tx;
uint32_t size;
int ret;
+ unsigned flags = 0;
if (usage & PIPE_TRANSFER_MAP_DIRECTLY)
return NULL;
@@ -372,6 +374,7 @@ nvc0_miptree_transfer_new(struct pipe_context *pctx,
ret = nouveau_bo_new(dev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0,
size * tx->nlayers, NULL, &tx->rect[1].bo);
if (ret) {
+ pipe_resource_reference(&tx->base.resource, NULL);
FREE(tx);
return NULL;
}
@@ -401,12 +404,31 @@ nvc0_miptree_transfer_new(struct pipe_context *pctx,
tx->rect[1].base = 0;
}
- return &tx->base;
+ if (tx->rect[1].bo->map) {
+ *ptransfer = &tx->base;
+ return tx->rect[1].bo->map;
+ }
+
+ if (usage & PIPE_TRANSFER_READ)
+ flags = NOUVEAU_BO_RD;
+ if (usage & PIPE_TRANSFER_WRITE)
+ flags |= NOUVEAU_BO_WR;
+
+ ret = nouveau_bo_map(tx->rect[1].bo, flags, nvc0->screen->base.client);
+ if (ret) {
+ pipe_resource_reference(&tx->base.resource, NULL);
+ nouveau_bo_ref(NULL, &tx->rect[1].bo);
+ FREE(tx);
+ return NULL;
+ }
+
+ *ptransfer = &tx->base;
+ return tx->rect[1].bo->map;
}
void
-nvc0_miptree_transfer_del(struct pipe_context *pctx,
- struct pipe_transfer *transfer)
+nvc0_miptree_transfer_unmap(struct pipe_context *pctx,
+ struct pipe_transfer *transfer)
{
struct nvc0_context *nvc0 = nvc0_context(pctx);
struct nvc0_transfer *tx = (struct nvc0_transfer *)transfer;
@@ -431,35 +453,6 @@ nvc0_miptree_transfer_del(struct pipe_context *pctx,
FREE(tx);
}
-void *
-nvc0_miptree_transfer_map(struct pipe_context *pctx,
- struct pipe_transfer *transfer)
-{
- struct nvc0_context *nvc0 = nvc0_context(pctx);
- struct nvc0_transfer *tx = (struct nvc0_transfer *)transfer;
- int ret;
- unsigned flags = 0;
-
- if (tx->rect[1].bo->map)
- return tx->rect[1].bo->map;
-
- if (transfer->usage & PIPE_TRANSFER_READ)
- flags = NOUVEAU_BO_RD;
- if (transfer->usage & PIPE_TRANSFER_WRITE)
- flags |= NOUVEAU_BO_WR;
-
- ret = nouveau_bo_map(tx->rect[1].bo, flags, nvc0->screen->base.client);
- if (ret)
- return NULL;
- return tx->rect[1].bo->map;
-}
-
-void
-nvc0_miptree_transfer_unmap(struct pipe_context *pctx,
- struct pipe_transfer *transfer)
-{
-}
-
void
nvc0_cb_push(struct nouveau_context *nv,
struct nouveau_bo *bo, unsigned domain,
diff --git a/src/gallium/drivers/r300/r300_resource.c b/src/gallium/drivers/r300/r300_resource.c
index 46399fb2397..701fd249d30 100644
--- a/src/gallium/drivers/r300/r300_resource.c
+++ b/src/gallium/drivers/r300/r300_resource.c
@@ -40,11 +40,9 @@ r300_resource_create(struct pipe_screen *screen,
void r300_init_resource_functions(struct r300_context *r300)
{
- r300->context.get_transfer = u_get_transfer_vtbl;
r300->context.transfer_map = u_transfer_map_vtbl;
r300->context.transfer_flush_region = u_default_transfer_flush_region;
r300->context.transfer_unmap = u_transfer_unmap_vtbl;
- r300->context.transfer_destroy = u_transfer_destroy_vtbl;
r300->context.transfer_inline_write = u_default_transfer_inline_write;
r300->context.create_surface = r300_create_surface;
r300->context.surface_destroy = r300_surface_destroy;
diff --git a/src/gallium/drivers/r300/r300_screen_buffer.c b/src/gallium/drivers/r300/r300_screen_buffer.c
index f652bf72b0c..37a7c77010a 100644
--- a/src/gallium/drivers/r300/r300_screen_buffer.c
+++ b/src/gallium/drivers/r300/r300_screen_buffer.c
@@ -63,79 +63,63 @@ static void r300_buffer_destroy(struct pipe_screen *screen,
FREE(rbuf);
}
-static struct pipe_transfer*
-r300_buffer_get_transfer(struct pipe_context *context,
- struct pipe_resource *resource,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box)
-{
- struct r300_context *r300 = r300_context(context);
- struct pipe_transfer *transfer =
- util_slab_alloc(&r300->pool_transfers);
-
- transfer->resource = resource;
- transfer->level = level;
- transfer->usage = usage;
- transfer->box = *box;
- transfer->stride = 0;
- transfer->layer_stride = 0;
- transfer->data = NULL;
-
- /* Note strides are zero, this is ok for buffers, but not for
- * textures 2d & higher at least.
- */
- return transfer;
-}
-
-static void r300_buffer_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct r300_context *r300 = r300_context(pipe);
- util_slab_free(&r300->pool_transfers, transfer);
-}
-
static void *
-r300_buffer_transfer_map( struct pipe_context *pipe,
- struct pipe_transfer *transfer )
+r300_buffer_transfer_map( struct pipe_context *context,
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer )
{
- struct r300_context *r300 = r300_context(pipe);
- struct r300_screen *r300screen = r300_screen(pipe->screen);
- struct radeon_winsys *rws = r300screen->rws;
- struct r300_resource *rbuf = r300_resource(transfer->resource);
+ struct r300_context *r300 = r300_context(context);
+ struct radeon_winsys *rws = r300->screen->rws;
+ struct r300_resource *rbuf = r300_resource(resource);
+ struct pipe_transfer *transfer;
uint8_t *map;
- enum pipe_transfer_usage usage;
- if (rbuf->malloced_buffer)
- return (uint8_t *) rbuf->malloced_buffer + transfer->box.x;
+ transfer = util_slab_alloc(&r300->pool_transfers);
+ transfer->resource = resource;
+ transfer->level = level;
+ transfer->usage = usage;
+ transfer->box = *box;
+ transfer->stride = 0;
+ transfer->layer_stride = 0;
+ transfer->data = NULL;
+
+ if (rbuf->malloced_buffer) {
+ *ptransfer = transfer;
+ return (uint8_t *) rbuf->malloced_buffer + box->x;
+ }
/* Buffers are never used for write, therefore mapping for read can be
* unsynchronized. */
- usage = transfer->usage;
if (!(usage & PIPE_TRANSFER_WRITE)) {
usage |= PIPE_TRANSFER_UNSYNCHRONIZED;
}
map = rws->buffer_map(rbuf->cs_buf, r300->cs, usage);
- if (map == NULL)
+ if (map == NULL) {
+ util_slab_free(&r300->pool_transfers, transfer);
return NULL;
+ }
- return map + transfer->box.x;
+ *ptransfer = transfer;
+ return map + box->x;
}
static void r300_buffer_transfer_unmap( struct pipe_context *pipe,
- struct pipe_transfer *transfer )
+ struct pipe_transfer *transfer )
{
- /* no-op */
+ struct r300_context *r300 = r300_context(pipe);
+
+ util_slab_free(&r300->pool_transfers, transfer);
}
static const struct u_resource_vtbl r300_buffer_vtbl =
{
NULL, /* get_handle */
r300_buffer_destroy, /* resource_destroy */
- r300_buffer_get_transfer, /* get_transfer */
- r300_buffer_transfer_destroy, /* transfer_destroy */
r300_buffer_transfer_map, /* transfer_map */
NULL, /* transfer_flush_region */
r300_buffer_transfer_unmap, /* transfer_unmap */
diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c
index 39cca78ebce..7f74538deea 100644
--- a/src/gallium/drivers/r300/r300_texture.c
+++ b/src/gallium/drivers/r300/r300_texture.c
@@ -937,8 +937,6 @@ static const struct u_resource_vtbl r300_texture_vtbl =
{
NULL, /* get_handle */
r300_texture_destroy, /* resource_destroy */
- r300_texture_get_transfer, /* get_transfer */
- r300_texture_transfer_destroy, /* transfer_destroy */
r300_texture_transfer_map, /* transfer_map */
NULL, /* transfer_flush_region */
r300_texture_transfer_unmap, /* transfer_unmap */
diff --git a/src/gallium/drivers/r300/r300_transfer.c b/src/gallium/drivers/r300/r300_transfer.c
index 9140bb191cf..fbae2df52b9 100644
--- a/src/gallium/drivers/r300/r300_transfer.c
+++ b/src/gallium/drivers/r300/r300_transfer.c
@@ -76,18 +76,21 @@ static void r300_copy_into_tiled_texture(struct pipe_context *ctx,
r300_flush(ctx, 0, NULL);
}
-struct pipe_transfer*
-r300_texture_get_transfer(struct pipe_context *ctx,
+void *
+r300_texture_transfer_map(struct pipe_context *ctx,
struct pipe_resource *texture,
unsigned level,
unsigned usage,
- const struct pipe_box *box)
+ const struct pipe_box *box,
+ struct pipe_transfer **transfer)
{
struct r300_context *r300 = r300_context(ctx);
struct r300_resource *tex = r300_resource(texture);
struct r300_transfer *trans;
struct pipe_resource base;
boolean referenced_cs, referenced_hw;
+ enum pipe_format format = tex->b.b.format;
+ char *map;
referenced_cs =
r300->rws->cs_is_buffer_referenced(r300->cs, tex->cs_buf, RADEON_USAGE_READWRITE);
@@ -101,7 +104,7 @@ r300_texture_get_transfer(struct pipe_context *ctx,
trans = CALLOC_STRUCT(r300_transfer);
if (trans) {
/* Initialize the transfer object. */
- pipe_resource_reference(&trans->transfer.resource, texture);
+ trans->transfer.resource = texture;
trans->transfer.level = level;
trans->transfer.usage = usage;
trans->transfer.box = *box;
@@ -161,15 +164,8 @@ r300_texture_get_transfer(struct pipe_context *ctx,
&base));
if (!trans->linear_texture) {
- /* For linear textures, it's safe to fallback to
- * an unpipelined transfer. */
- if (!tex->tex.microtile && !tex->tex.macrotile[level]) {
- goto unpipelined;
- }
-
- /* Otherwise, go to hell. */
fprintf(stderr,
- "r300: Failed to create a transfer object, praise.\n");
+ "r300: Failed to create a transfer object.\n");
FREE(trans);
return NULL;
}
@@ -190,64 +186,43 @@ r300_texture_get_transfer(struct pipe_context *ctx,
/* Always referenced in the blit. */
r300_flush(ctx, 0, NULL);
}
- return &trans->transfer;
- }
-
- unpipelined:
- /* Unpipelined transfer. */
- trans->transfer.stride = tex->tex.stride_in_bytes[level];
- trans->offset = r300_texture_get_offset(tex, level, box->z);
-
- if (referenced_cs &&
- !(usage & PIPE_TRANSFER_UNSYNCHRONIZED))
- r300_flush(ctx, 0, NULL);
- return &trans->transfer;
- }
- return NULL;
-}
+ } else {
+ /* Unpipelined transfer. */
+ trans->transfer.stride = tex->tex.stride_in_bytes[level];
+ trans->offset = r300_texture_get_offset(tex, level, box->z);
-void r300_texture_transfer_destroy(struct pipe_context *ctx,
- struct pipe_transfer *trans)
-{
- struct r300_transfer *r300transfer = r300_transfer(trans);
-
- if (r300transfer->linear_texture) {
- if (trans->usage & PIPE_TRANSFER_WRITE) {
- r300_copy_into_tiled_texture(ctx, r300transfer);
+ if (referenced_cs &&
+ !(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
+ r300_flush(ctx, 0, NULL);
+ }
}
-
- pipe_resource_reference(
- (struct pipe_resource**)&r300transfer->linear_texture, NULL);
}
- pipe_resource_reference(&trans->resource, NULL);
- FREE(trans);
-}
-void* r300_texture_transfer_map(struct pipe_context *ctx,
- struct pipe_transfer *transfer)
-{
- struct r300_context *r300 = r300_context(ctx);
- struct r300_transfer *r300transfer = r300_transfer(transfer);
- struct r300_resource *tex = r300_resource(transfer->resource);
- char *map;
- enum pipe_format format = tex->b.b.format;
-
- if (r300transfer->linear_texture) {
+ if (trans->linear_texture) {
/* The detiled texture is of the same size as the region being mapped
* (no offset needed). */
- return r300->rws->buffer_map(r300transfer->linear_texture->cs_buf,
- r300->cs, transfer->usage);
+ map = r300->rws->buffer_map(trans->linear_texture->cs_buf,
+ r300->cs, usage);
+ if (!map) {
+ pipe_resource_reference(
+ (struct pipe_resource**)&trans->linear_texture, NULL);
+ FREE(trans);
+ return NULL;
+ }
+ *transfer = &trans->transfer;
+ return map;
} else {
/* Tiling is disabled. */
- map = r300->rws->buffer_map(tex->cs_buf, r300->cs, transfer->usage);
-
+ map = r300->rws->buffer_map(tex->cs_buf, r300->cs, usage);
if (!map) {
+ FREE(trans);
return NULL;
}
- return map + r300_transfer(transfer)->offset +
- transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
- transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
+ *transfer = &trans->transfer;
+ return map + trans->offset +
+ box->y / util_format_get_blockheight(format) * trans->transfer.stride +
+ box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
}
}
@@ -255,12 +230,20 @@ void r300_texture_transfer_unmap(struct pipe_context *ctx,
struct pipe_transfer *transfer)
{
struct radeon_winsys *rws = r300_context(ctx)->rws;
- struct r300_transfer *r300transfer = r300_transfer(transfer);
+ struct r300_transfer *trans = r300_transfer(transfer);
struct r300_resource *tex = r300_resource(transfer->resource);
- if (r300transfer->linear_texture) {
- rws->buffer_unmap(r300transfer->linear_texture->cs_buf);
+ if (trans->linear_texture) {
+ rws->buffer_unmap(trans->linear_texture->cs_buf);
+
+ if (transfer->usage & PIPE_TRANSFER_WRITE) {
+ r300_copy_into_tiled_texture(ctx, trans);
+ }
+
+ pipe_resource_reference(
+ (struct pipe_resource**)&trans->linear_texture, NULL);
} else {
rws->buffer_unmap(tex->cs_buf);
}
+ FREE(transfer);
}
diff --git a/src/gallium/drivers/r300/r300_transfer.h b/src/gallium/drivers/r300/r300_transfer.h
index 7977ef516f2..45477ae6d0d 100644
--- a/src/gallium/drivers/r300/r300_transfer.h
+++ b/src/gallium/drivers/r300/r300_transfer.h
@@ -28,20 +28,13 @@
struct r300_context;
-struct pipe_transfer*
-r300_texture_get_transfer(struct pipe_context *ctx,
+void *
+r300_texture_transfer_map(struct pipe_context *ctx,
struct pipe_resource *texture,
unsigned level,
unsigned usage,
- const struct pipe_box *box);
-
-void
-r300_texture_transfer_destroy(struct pipe_context *ctx,
- struct pipe_transfer *trans);
-
-void*
-r300_texture_transfer_map(struct pipe_context *ctx,
- struct pipe_transfer *transfer);
+ const struct pipe_box *box,
+ struct pipe_transfer **transfer);
void
r300_texture_transfer_unmap(struct pipe_context *ctx,
diff --git a/src/gallium/drivers/r600/compute_memory_pool.c b/src/gallium/drivers/r600/compute_memory_pool.c
index 19fbe0cddc4..46bff3221d9 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -453,27 +453,22 @@ void compute_memory_transfer(
"offset_in_chunk = %d, size = %d\n", device_to_host,
offset_in_chunk, size);
- if (device_to_host)
- {
- xfer = pipe->get_transfer(pipe, gart, 0, PIPE_TRANSFER_READ,
+ if (device_to_host) {
+ map = pipe->transfer_map(pipe, gart, 0, PIPE_TRANSFER_READ,
&(struct pipe_box) { .width = aligned_size,
- .height = 1, .depth = 1 });
- assert(xfer);
- map = pipe->transfer_map(pipe, xfer);
+ .height = 1, .depth = 1 }, &xfer);
+ assert(xfer);
assert(map);
memcpy(data, map + internal_offset, size);
pipe->transfer_unmap(pipe, xfer);
- pipe->transfer_destroy(pipe, xfer);
} else {
- xfer = pipe->get_transfer(pipe, gart, 0, PIPE_TRANSFER_WRITE,
+ map = pipe->transfer_map(pipe, gart, 0, PIPE_TRANSFER_WRITE,
&(struct pipe_box) { .width = aligned_size,
- .height = 1, .depth = 1 });
+ .height = 1, .depth = 1 }, &xfer);
assert(xfer);
- map = pipe->transfer_map(pipe, xfer);
assert(map);
memcpy(map + internal_offset, data, size);
pipe->transfer_unmap(pipe, xfer);
- pipe->transfer_destroy(pipe, xfer);
}
}
diff --git a/src/gallium/drivers/r600/evergreen_compute.c b/src/gallium/drivers/r600/evergreen_compute.c
index 8f055bd5f38..655cf756186 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -104,12 +104,10 @@ static void evergreen_cs_set_vertex_buffer(
state->atom.dirty = true;
}
-const struct u_resource_vtbl r600_global_buffer_vtbl =
+static const struct u_resource_vtbl r600_global_buffer_vtbl =
{
u_default_resource_get_handle, /* get_handle */
r600_compute_global_buffer_destroy, /* resource_destroy */
- r600_compute_global_get_transfer, /* get_transfer */
- r600_compute_global_transfer_destroy, /* transfer_destroy */
r600_compute_global_transfer_map, /* transfer_map */
r600_compute_global_transfer_flush_region,/* transfer_flush_region */
r600_compute_global_transfer_unmap, /* transfer_unmap */
@@ -841,30 +839,57 @@ void r600_compute_global_buffer_destroy(
free(res);
}
-void* r600_compute_global_transfer_map(
+void *r600_compute_global_transfer_map(
struct pipe_context *ctx_,
- struct pipe_transfer* transfer)
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
+ struct r600_context *rctx = (struct r600_context*)ctx_;
+ struct compute_memory_pool *pool = rctx->screen->global_pool;
+ struct pipe_transfer *transfer = util_slab_alloc(&rctx->pool_transfers);
+ struct r600_resource_global* buffer =
+ (struct r600_resource_global*)transfer->resource;
+ uint32_t* map;
+
+ compute_memory_finalize_pending(pool, ctx_);
+
+ assert(resource->target == PIPE_BUFFER);
+
+ COMPUTE_DBG("* r600_compute_global_get_transfer()\n"
+ "level = %u, usage = %u, box(x = %u, y = %u, z = %u "
+ "width = %u, height = %u, depth = %u)\n", level, usage,
+ box->x, box->y, box->z, box->width, box->height,
+ box->depth);
+
+ transfer->resource = resource;
+ transfer->level = level;
+ transfer->usage = usage;
+ transfer->box = *box;
+ transfer->stride = 0;
+ transfer->layer_stride = 0;
+ transfer->data = NULL;
+
assert(transfer->resource->target == PIPE_BUFFER);
assert(transfer->resource->bind & PIPE_BIND_GLOBAL);
assert(transfer->box.x >= 0);
assert(transfer->box.y == 0);
assert(transfer->box.z == 0);
- struct r600_context *ctx = (struct r600_context *)ctx_;
- struct r600_resource_global* buffer =
- (struct r600_resource_global*)transfer->resource;
-
- uint32_t* map;
///TODO: do it better, mapping is not possible if the pool is too big
COMPUTE_DBG("* r600_compute_global_transfer_map()\n");
- if (!(map = ctx->ws->buffer_map(buffer->chunk->pool->bo->cs_buf,
- ctx->cs, transfer->usage))) {
+ if (!(map = rctx->ws->buffer_map(buffer->chunk->pool->bo->cs_buf,
+ rctx->cs, transfer->usage))) {
+ util_slab_free(&rctx->pool_transfers, transfer);
return NULL;
}
+ *ptransfer = transfer;
+
COMPUTE_DBG("Buffer: %p + %u (buffer offset in global memory) "
"+ %u (box.x)\n", map, buffer->chunk->start_in_dw, transfer->box.x);
return ((char*)(map + buffer->chunk->start_in_dw)) + transfer->box.x;
@@ -884,50 +909,7 @@ void r600_compute_global_transfer_unmap(
COMPUTE_DBG("* r600_compute_global_transfer_unmap()\n");
ctx->ws->buffer_unmap(buffer->chunk->pool->bo->cs_buf);
-}
-
-struct pipe_transfer * r600_compute_global_get_transfer(
- struct pipe_context *ctx_,
- struct pipe_resource *resource,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box)
-{
- struct r600_context *ctx = (struct r600_context *)ctx_;
- struct compute_memory_pool *pool = ctx->screen->global_pool;
-
- compute_memory_finalize_pending(pool, ctx_);
-
- assert(resource->target == PIPE_BUFFER);
- struct r600_context *rctx = (struct r600_context*)ctx_;
- struct pipe_transfer *transfer = util_slab_alloc(&rctx->pool_transfers);
-
- COMPUTE_DBG("* r600_compute_global_get_transfer()\n"
- "level = %u, usage = %u, box(x = %u, y = %u, z = %u "
- "width = %u, height = %u, depth = %u)\n", level, usage,
- box->x, box->y, box->z, box->width, box->height,
- box->depth);
-
- transfer->resource = resource;
- transfer->level = level;
- transfer->usage = usage;
- transfer->box = *box;
- transfer->stride = 0;
- transfer->layer_stride = 0;
- transfer->data = NULL;
-
- /* Note strides are zero, this is ok for buffers, but not for
- * textures 2d & higher at least.
- */
- return transfer;
-}
-
-void r600_compute_global_transfer_destroy(
- struct pipe_context *ctx_,
- struct pipe_transfer *transfer)
-{
- struct r600_context *rctx = (struct r600_context*)ctx_;
- util_slab_free(&rctx->pool_transfers, transfer);
+ util_slab_free(&ctx->pool_transfers, transfer);
}
void r600_compute_global_transfer_flush_region(
diff --git a/src/gallium/drivers/r600/evergreen_compute.h b/src/gallium/drivers/r600/evergreen_compute.h
index f29d91b9349..e68ebd8585e 100644
--- a/src/gallium/drivers/r600/evergreen_compute.h
+++ b/src/gallium/drivers/r600/evergreen_compute.h
@@ -41,11 +41,14 @@ void evergreen_emit_cs_shader(struct r600_context *rctx, struct r600_atom * atom
struct pipe_resource *r600_compute_global_buffer_create(struct pipe_screen *screen, const struct pipe_resource *templ);
void r600_compute_global_buffer_destroy(struct pipe_screen *screen, struct pipe_resource *res);
-void* r600_compute_global_transfer_map(struct pipe_context *ctx, struct pipe_transfer* transfer);
+void *r600_compute_global_transfer_map(
+ struct pipe_context *ctx_,
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer);
void r600_compute_global_transfer_unmap(struct pipe_context *ctx, struct pipe_transfer* transfer);
-struct pipe_transfer * r600_compute_global_get_transfer(struct pipe_context *, struct pipe_resource *, unsigned level,
- unsigned usage, const struct pipe_box *);
-void r600_compute_global_transfer_destroy(struct pipe_context *, struct pipe_transfer *);
void r600_compute_global_transfer_flush_region( struct pipe_context *, struct pipe_transfer *, const struct pipe_box *);
void r600_compute_global_transfer_inline_write( struct pipe_context *, struct pipe_resource *, unsigned level,
unsigned usage, const struct pipe_box *, const void *data, unsigned stride, unsigned layer_stride);
diff --git a/src/gallium/drivers/r600/r600_buffer.c b/src/gallium/drivers/r600/r600_buffer.c
index 0b0ac3460e1..90ab2475d75 100644
--- a/src/gallium/drivers/r600/r600_buffer.c
+++ b/src/gallium/drivers/r600/r600_buffer.c
@@ -37,33 +37,6 @@ static void r600_buffer_destroy(struct pipe_screen *screen,
FREE(rbuffer);
}
-static struct pipe_transfer *r600_get_transfer(struct pipe_context *ctx,
- struct pipe_resource *resource,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box)
-{
- struct r600_context *rctx = (struct r600_context*)ctx;
- struct r600_transfer *transfer = util_slab_alloc(&rctx->pool_transfers);
-
- assert(box->x + box->width <= resource->width0);
-
- transfer->transfer.resource = resource;
- transfer->transfer.level = level;
- transfer->transfer.usage = usage;
- transfer->transfer.box = *box;
- transfer->transfer.stride = 0;
- transfer->transfer.layer_stride = 0;
- transfer->transfer.data = NULL;
- transfer->staging = NULL;
- transfer->offset = 0;
-
- /* Note strides are zero, this is ok for buffers, but not for
- * textures 2d & higher at least.
- */
- return &transfer->transfer;
-}
-
static void r600_set_constants_dirty_if_bound(struct r600_context *rctx,
struct r600_resource *rbuffer)
{
@@ -87,16 +60,47 @@ static void r600_set_constants_dirty_if_bound(struct r600_context *rctx,
}
}
-static void *r600_buffer_transfer_map(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
+static void *r600_buffer_get_transfer(struct pipe_context *ctx,
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer,
+ void *data, struct r600_resource *staging)
{
- struct r600_resource *rbuffer = r600_resource(transfer->resource);
- struct r600_context *rctx = (struct r600_context*)pipe;
+ struct r600_context *rctx = (struct r600_context*)ctx;
+ struct r600_transfer *transfer = util_slab_alloc(&rctx->pool_transfers);
+
+ transfer->transfer.resource = resource;
+ transfer->transfer.level = level;
+ transfer->transfer.usage = usage;
+ transfer->transfer.box = *box;
+ transfer->transfer.stride = 0;
+ transfer->transfer.layer_stride = 0;
+ transfer->transfer.data = NULL;
+ transfer->staging = NULL;
+ transfer->offset = 0;
+ transfer->staging = staging;
+ *ptransfer = &transfer->transfer;
+ return data;
+}
+
+static void *r600_buffer_transfer_map(struct pipe_context *ctx,
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
+{
+ struct r600_context *rctx = (struct r600_context*)ctx;
+ struct r600_resource *rbuffer = r600_resource(resource);
uint8_t *data;
- if (transfer->usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE &&
- !(transfer->usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
- assert(transfer->usage & PIPE_TRANSFER_WRITE);
+ assert(box->x + box->width <= resource->width0);
+
+ if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE &&
+ !(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
+ assert(usage & PIPE_TRANSFER_WRITE);
/* Check if mapping this buffer would cause waiting for the GPU. */
if (rctx->ws->cs_is_buffer_referenced(rctx->cs, rbuffer->cs_buf, RADEON_USAGE_READWRITE) ||
@@ -134,37 +138,44 @@ static void *r600_buffer_transfer_map(struct pipe_context *pipe,
}
}
#if 0 /* this is broken (see Bug 53130) */
- else if ((transfer->usage & PIPE_TRANSFER_DISCARD_RANGE) &&
- !(transfer->usage & PIPE_TRANSFER_UNSYNCHRONIZED) &&
+ else if ((usage & PIPE_TRANSFER_DISCARD_RANGE) &&
+ !(usage & PIPE_TRANSFER_UNSYNCHRONIZED) &&
rctx->screen->has_streamout &&
/* The buffer range must be aligned to 4. */
- transfer->box.x % 4 == 0 && transfer->box.width % 4 == 0) {
- assert(transfer->usage & PIPE_TRANSFER_WRITE);
+ box->x % 4 == 0 && box->width % 4 == 0) {
+ assert(usage & PIPE_TRANSFER_WRITE);
/* Check if mapping this buffer would cause waiting for the GPU. */
if (rctx->ws->cs_is_buffer_referenced(rctx->cs, rbuffer->cs_buf, RADEON_USAGE_READWRITE) ||
rctx->ws->buffer_is_busy(rbuffer->buf, RADEON_USAGE_READWRITE)) {
/* Do a wait-free write-only transfer using a temporary buffer. */
- struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
-
- rtransfer->staging = (struct r600_resource*)
- pipe_buffer_create(pipe->screen, PIPE_BIND_VERTEX_BUFFER,
- PIPE_USAGE_STAGING, transfer->box.width);
- return rctx->ws->buffer_map(rtransfer->staging->cs_buf, rctx->cs, PIPE_TRANSFER_WRITE);
+ struct r600_resource *staging = (struct r600_resource*)
+ pipe_buffer_create(ctx->screen, PIPE_BIND_VERTEX_BUFFER,
+ PIPE_USAGE_STAGING, box->width);
+ data = rctx->ws->buffer_map(staging->cs_buf, rctx->cs, PIPE_TRANSFER_WRITE);
+
+ if (!data)
+ return NULL;
+ return r600_buffer_get_transfer(ctx, resource, level, usage, box,
+ ptransfer, data, staging);
}
}
#endif
- data = rctx->ws->buffer_map(rbuffer->cs_buf, rctx->cs, transfer->usage);
- if (!data)
+ data = rctx->ws->buffer_map(rbuffer->cs_buf, rctx->cs, usage);
+ if (!data) {
return NULL;
+ }
+ data += box->x;
- return (uint8_t*)data + transfer->box.x;
+ return r600_buffer_get_transfer(ctx, resource, level, usage, box,
+ ptransfer, data, NULL);
}
static void r600_buffer_transfer_unmap(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
+ struct r600_context *rctx = (struct r600_context*)pipe;
struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
if (rtransfer->staging) {
@@ -176,12 +187,6 @@ static void r600_buffer_transfer_unmap(struct pipe_context *pipe,
&rtransfer->staging->b.b, &box);
pipe_resource_reference((struct pipe_resource**)&rtransfer->staging, NULL);
}
-}
-
-static void r600_transfer_destroy(struct pipe_context *ctx,
- struct pipe_transfer *transfer)
-{
- struct r600_context *rctx = (struct r600_context*)ctx;
util_slab_free(&rctx->pool_transfers, transfer);
}
@@ -189,8 +194,6 @@ static const struct u_resource_vtbl r600_buffer_vtbl =
{
u_default_resource_get_handle, /* get_handle */
r600_buffer_destroy, /* resource_destroy */
- r600_get_transfer, /* get_transfer */
- r600_transfer_destroy, /* transfer_destroy */
r600_buffer_transfer_map, /* transfer_map */
NULL, /* transfer_flush_region */
r600_buffer_transfer_unmap, /* transfer_unmap */
diff --git a/src/gallium/drivers/r600/r600_resource.c b/src/gallium/drivers/r600/r600_resource.c
index 1a91d5d5755..5e637f64a4a 100644
--- a/src/gallium/drivers/r600/r600_resource.c
+++ b/src/gallium/drivers/r600/r600_resource.c
@@ -68,10 +68,8 @@ void r600_init_screen_resource_functions(struct pipe_screen *screen)
void r600_init_context_resource_functions(struct r600_context *r600)
{
- r600->context.get_transfer = u_get_transfer_vtbl;
r600->context.transfer_map = u_transfer_map_vtbl;
r600->context.transfer_flush_region = u_default_transfer_flush_region;
r600->context.transfer_unmap = u_transfer_unmap_vtbl;
- r600->context.transfer_destroy = u_transfer_destroy_vtbl;
r600->context.transfer_inline_write = u_default_transfer_inline_write;
}
diff --git a/src/gallium/drivers/r600/r600_resource.h b/src/gallium/drivers/r600/r600_resource.h
index bf7fffa44c5..7ebf59e23a5 100644
--- a/src/gallium/drivers/r600/r600_resource.h
+++ b/src/gallium/drivers/r600/r600_resource.h
@@ -141,17 +141,4 @@ bool r600_init_flushed_depth_texture(struct pipe_context *ctx,
struct pipe_resource *texture,
struct r600_texture **staging);
-/* r600_texture.c texture transfer functions. */
-struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx,
- struct pipe_resource *texture,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box);
-void r600_texture_transfer_destroy(struct pipe_context *ctx,
- struct pipe_transfer *trans);
-void* r600_texture_transfer_map(struct pipe_context *ctx,
- struct pipe_transfer* transfer);
-void r600_texture_transfer_unmap(struct pipe_context *ctx,
- struct pipe_transfer* transfer);
-
#endif
diff --git a/src/gallium/drivers/r600/r600_texture.c b/src/gallium/drivers/r600/r600_texture.c
index 4fb10ca031d..785eeffcab5 100644
--- a/src/gallium/drivers/r600/r600_texture.c
+++ b/src/gallium/drivers/r600/r600_texture.c
@@ -240,17 +240,7 @@ static void r600_texture_destroy(struct pipe_screen *screen,
FREE(rtex);
}
-static const struct u_resource_vtbl r600_texture_vtbl =
-{
- r600_texture_get_handle, /* get_handle */
- r600_texture_destroy, /* resource_destroy */
- r600_texture_get_transfer, /* get_transfer */
- r600_texture_transfer_destroy, /* transfer_destroy */
- r600_texture_transfer_map, /* transfer_map */
- NULL, /* transfer_flush_region */
- r600_texture_transfer_unmap, /* transfer_unmap */
- NULL /* transfer_inline_write */
-};
+static const struct u_resource_vtbl r600_texture_vtbl;
/* The number of samples can be specified independently of the texture. */
void r600_texture_get_fmask_info(struct r600_screen *rscreen,
@@ -603,17 +593,26 @@ bool r600_init_flushed_depth_texture(struct pipe_context *ctx,
return true;
}
-struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx,
- struct pipe_resource *texture,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box)
+static void *r600_texture_transfer_map(struct pipe_context *ctx,
+ struct pipe_resource *texture,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
struct r600_context *rctx = (struct r600_context*)ctx;
struct r600_texture *rtex = (struct r600_texture*)texture;
struct pipe_resource resource;
struct r600_transfer *trans;
boolean use_staging_texture = FALSE;
+ enum pipe_format format = texture->format;
+ struct radeon_winsys_cs_handle *buf;
+ unsigned offset = 0;
+ char *map;
+
+ if ((texture->bind & PIPE_BIND_GLOBAL) && texture->target == PIPE_BUFFER) {
+ return r600_compute_global_transfer_map(ctx, texture, level, usage, box, ptransfer);
+ }
/* We cannot map a tiled texture directly because the data is
* in a different order, therefore we do detiling using a blit.
@@ -644,7 +643,7 @@ struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx,
trans = CALLOC_STRUCT(r600_transfer);
if (trans == NULL)
return NULL;
- pipe_resource_reference(&trans->transfer.resource, texture);
+ trans->transfer.resource = texture;
trans->transfer.level = level;
trans->transfer.usage = usage;
trans->transfer.box = *box;
@@ -657,7 +656,6 @@ struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx,
if (!r600_init_flushed_depth_texture(ctx, texture, &staging_depth)) {
R600_ERR("failed to create temporary texture to hold untiled copy\n");
- pipe_resource_reference(&trans->transfer.resource, NULL);
FREE(trans);
return NULL;
}
@@ -670,7 +668,6 @@ struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx,
trans->transfer.stride = staging_depth->surface.level[level].pitch_bytes;
trans->offset = r600_texture_get_offset(staging_depth, level, box->z);
trans->staging = (struct r600_resource*)staging_depth;
- return &trans->transfer;
} else if (use_staging_texture) {
resource.target = PIPE_TEXTURE_2D;
resource.format = texture->format;
@@ -697,7 +694,6 @@ struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx,
trans->staging = (struct r600_resource*)ctx->screen->resource_create(ctx->screen, &resource);
if (trans->staging == NULL) {
R600_ERR("failed to create temporary texture to hold untiled copy\n");
- pipe_resource_reference(&trans->transfer.resource, NULL);
FREE(trans);
return NULL;
}
@@ -709,79 +705,41 @@ struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx,
/* Always referenced in the blit. */
r600_flush(ctx, NULL, 0);
}
- return &trans->transfer;
- }
- trans->transfer.stride = rtex->surface.level[level].pitch_bytes;
- trans->transfer.layer_stride = rtex->surface.level[level].slice_size;
- trans->offset = r600_texture_get_offset(rtex, level, box->z);
- return &trans->transfer;
-}
-
-void r600_texture_transfer_destroy(struct pipe_context *ctx,
- struct pipe_transfer *transfer)
-{
- struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
- struct pipe_resource *texture = transfer->resource;
- struct r600_texture *rtex = (struct r600_texture*)texture;
-
- if ((transfer->usage & PIPE_TRANSFER_WRITE) && rtransfer->staging) {
- if (rtex->is_depth) {
- ctx->resource_copy_region(ctx, texture, transfer->level,
- transfer->box.x, transfer->box.y, transfer->box.z,
- &rtransfer->staging->b.b, transfer->level,
- &transfer->box);
- } else {
- r600_copy_from_staging_texture(ctx, rtransfer);
- }
- }
-
- if (rtransfer->staging)
- pipe_resource_reference((struct pipe_resource**)&rtransfer->staging, NULL);
-
- pipe_resource_reference(&transfer->resource, NULL);
- FREE(transfer);
-}
-
-void* r600_texture_transfer_map(struct pipe_context *ctx,
- struct pipe_transfer* transfer)
-{
- struct r600_context *rctx = (struct r600_context *)ctx;
- struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
- struct radeon_winsys_cs_handle *buf;
- struct r600_texture *rtex =
- (struct r600_texture*)transfer->resource;
- enum pipe_format format = transfer->resource->format;
- unsigned offset = 0;
- char *map;
-
- if ((transfer->resource->bind & PIPE_BIND_GLOBAL) && transfer->resource->target == PIPE_BUFFER) {
- return r600_compute_global_transfer_map(ctx, transfer);
+ } else {
+ trans->transfer.stride = rtex->surface.level[level].pitch_bytes;
+ trans->transfer.layer_stride = rtex->surface.level[level].slice_size;
+ trans->offset = r600_texture_get_offset(rtex, level, box->z);
}
- if (rtransfer->staging) {
- buf = ((struct r600_resource *)rtransfer->staging)->cs_buf;
+ if (trans->staging) {
+ buf = ((struct r600_resource *)trans->staging)->cs_buf;
} else {
- buf = ((struct r600_resource *)transfer->resource)->cs_buf;
+ buf = ((struct r600_resource *)texture)->cs_buf;
}
- if (rtex->is_depth || !rtransfer->staging)
- offset = rtransfer->offset +
- transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
- transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
+ if (rtex->is_depth || !trans->staging)
+ offset = trans->offset +
+ box->y / util_format_get_blockheight(format) * trans->transfer.stride +
+ box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
- if (!(map = rctx->ws->buffer_map(buf, rctx->cs, transfer->usage))) {
+ if (!(map = rctx->ws->buffer_map(buf, rctx->cs, usage))) {
+ pipe_resource_reference((struct pipe_resource**)&trans->staging, NULL);
+ FREE(trans);
return NULL;
}
+ *ptransfer = &trans->transfer;
return map + offset;
}
-void r600_texture_transfer_unmap(struct pipe_context *ctx,
- struct pipe_transfer* transfer)
+static void r600_texture_transfer_unmap(struct pipe_context *ctx,
+ struct pipe_transfer* transfer)
{
struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
struct r600_context *rctx = (struct r600_context*)ctx;
struct radeon_winsys_cs_handle *buf;
+ struct pipe_resource *texture = transfer->resource;
+ struct r600_texture *rtex = (struct r600_texture*)texture;
if ((transfer->resource->bind & PIPE_BIND_GLOBAL) && transfer->resource->target == PIPE_BUFFER) {
return r600_compute_global_transfer_unmap(ctx, transfer);
@@ -793,6 +751,22 @@ void r600_texture_transfer_unmap(struct pipe_context *ctx,
buf = ((struct r600_resource *)transfer->resource)->cs_buf;
}
rctx->ws->buffer_unmap(buf);
+
+ if ((transfer->usage & PIPE_TRANSFER_WRITE) && rtransfer->staging) {
+ if (rtex->is_depth) {
+ ctx->resource_copy_region(ctx, texture, transfer->level,
+ transfer->box.x, transfer->box.y, transfer->box.z,
+ &rtransfer->staging->b.b, transfer->level,
+ &transfer->box);
+ } else {
+ r600_copy_from_staging_texture(ctx, rtransfer);
+ }
+ }
+
+ if (rtransfer->staging)
+ pipe_resource_reference((struct pipe_resource**)&rtransfer->staging, NULL);
+
+ FREE(transfer);
}
void r600_init_surface_functions(struct r600_context *r600)
@@ -1178,3 +1152,13 @@ out_unknown:
/* R600_ERR("Unable to handle texformat %d %s\n", format, util_format_name(format)); */
return ~0;
}
+
+static const struct u_resource_vtbl r600_texture_vtbl =
+{
+ r600_texture_get_handle, /* get_handle */
+ r600_texture_destroy, /* resource_destroy */
+ r600_texture_transfer_map, /* transfer_map */
+ NULL, /* transfer_flush_region */
+ r600_texture_transfer_unmap, /* transfer_unmap */
+ NULL /* transfer_inline_write */
+};
diff --git a/src/gallium/drivers/radeonsi/r600_buffer.c b/src/gallium/drivers/radeonsi/r600_buffer.c
index ec9d87e4866..7fae048d1f5 100644
--- a/src/gallium/drivers/radeonsi/r600_buffer.c
+++ b/src/gallium/drivers/radeonsi/r600_buffer.c
@@ -46,15 +46,24 @@ static void r600_buffer_destroy(struct pipe_screen *screen,
FREE(rbuffer);
}
-static struct pipe_transfer *r600_get_transfer(struct pipe_context *ctx,
- struct pipe_resource *resource,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box)
+static void *r600_buffer_transfer_map(struct pipe_context *ctx,
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
struct r600_context *rctx = (struct r600_context*)ctx;
- struct pipe_transfer *transfer = util_slab_alloc(&rctx->pool_transfers);
+ struct pipe_transfer *transfer;
+ struct si_resource *rbuffer = si_resource(resource);
+ uint8_t *data;
+ data = rctx->ws->buffer_map(rbuffer->cs_buf, rctx->cs, usage);
+ if (!data) {
+ return NULL;
+ }
+
+ transfer = util_slab_alloc(&rctx->pool_transfers);
transfer->resource = resource;
transfer->level = level;
transfer->usage = usage;
@@ -62,31 +71,16 @@ static struct pipe_transfer *r600_get_transfer(struct pipe_context *ctx,
transfer->stride = 0;
transfer->layer_stride = 0;
transfer->data = NULL;
-
- /* Note strides are zero, this is ok for buffers, but not for
- * textures 2d & higher at least.
- */
- return transfer;
-}
-
-static void *r600_buffer_transfer_map(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct si_resource *rbuffer = si_resource(transfer->resource);
- struct r600_context *rctx = (struct r600_context*)pipe;
- uint8_t *data;
-
- data = rctx->ws->buffer_map(rbuffer->cs_buf, rctx->cs, transfer->usage);
- if (!data)
- return NULL;
+ *ptransfer = transfer;
return (uint8_t*)data + transfer->box.x;
}
-static void r600_buffer_transfer_unmap(struct pipe_context *pipe,
+static void r600_buffer_transfer_unmap(struct pipe_context *ctx,
struct pipe_transfer *transfer)
{
- /* no-op */
+ struct r600_context *rctx = (struct r600_context*)ctx;
+ util_slab_free(&rctx->pool_transfers, transfer);
}
static void r600_buffer_transfer_flush_region(struct pipe_context *pipe,
@@ -95,19 +89,10 @@ static void r600_buffer_transfer_flush_region(struct pipe_context *pipe,
{
}
-static void r600_transfer_destroy(struct pipe_context *ctx,
- struct pipe_transfer *transfer)
-{
- struct r600_context *rctx = (struct r600_context*)ctx;
- util_slab_free(&rctx->pool_transfers, transfer);
-}
-
static const struct u_resource_vtbl r600_buffer_vtbl =
{
u_default_resource_get_handle, /* get_handle */
r600_buffer_destroy, /* resource_destroy */
- r600_get_transfer, /* get_transfer */
- r600_transfer_destroy, /* transfer_destroy */
r600_buffer_transfer_map, /* transfer_map */
r600_buffer_transfer_flush_region, /* transfer_flush_region */
r600_buffer_transfer_unmap, /* transfer_unmap */
diff --git a/src/gallium/drivers/radeonsi/r600_resource.c b/src/gallium/drivers/radeonsi/r600_resource.c
index a4888a703b4..33ccd003090 100644
--- a/src/gallium/drivers/radeonsi/r600_resource.c
+++ b/src/gallium/drivers/radeonsi/r600_resource.c
@@ -54,10 +54,8 @@ void r600_init_screen_resource_functions(struct pipe_screen *screen)
void r600_init_context_resource_functions(struct r600_context *r600)
{
- r600->context.get_transfer = u_get_transfer_vtbl;
r600->context.transfer_map = u_transfer_map_vtbl;
r600->context.transfer_flush_region = u_transfer_flush_region_vtbl;
r600->context.transfer_unmap = u_transfer_unmap_vtbl;
- r600->context.transfer_destroy = u_transfer_destroy_vtbl;
r600->context.transfer_inline_write = u_default_transfer_inline_write;
}
diff --git a/src/gallium/drivers/radeonsi/r600_texture.c b/src/gallium/drivers/radeonsi/r600_texture.c
index e6f72c88b05..8fae79200b6 100644
--- a/src/gallium/drivers/radeonsi/r600_texture.c
+++ b/src/gallium/drivers/radeonsi/r600_texture.c
@@ -254,17 +254,23 @@ static void r600_texture_destroy(struct pipe_screen *screen,
FREE(rtex);
}
-static struct pipe_transfer* si_texture_get_transfer(struct pipe_context *ctx,
- struct pipe_resource *texture,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box)
+static void *si_texture_transfer_map(struct pipe_context *ctx,
+ struct pipe_resource *texture,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
+ struct r600_context *rctx = (struct r600_context *)ctx;
struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture;
struct pipe_resource resource;
struct r600_transfer *trans;
int r;
boolean use_staging_texture = FALSE;
+ struct radeon_winsys_cs_handle *buf;
+ enum pipe_format format = texture->format;
+ unsigned offset = 0;
+ char *map;
/* We cannot map a tiled texture directly because the data is
* in a different order, therefore we do detiling using a blit.
@@ -316,7 +322,6 @@ static struct pipe_transfer* si_texture_get_transfer(struct pipe_context *ctx,
}
trans->transfer.stride = rtex->flushed_depth_texture->surface.level[level].pitch_bytes;
trans->offset = r600_texture_get_offset(rtex->flushed_depth_texture, level, box->z);
- return &trans->transfer;
} else if (use_staging_texture) {
resource.target = PIPE_TEXTURE_2D;
resource.format = texture->format;
@@ -355,66 +360,35 @@ static struct pipe_transfer* si_texture_get_transfer(struct pipe_context *ctx,
/* Always referenced in the blit. */
radeonsi_flush(ctx, NULL, 0);
}
- return &trans->transfer;
- }
- trans->transfer.stride = rtex->surface.level[level].pitch_bytes;
- trans->transfer.layer_stride = rtex->surface.level[level].slice_size;
- trans->offset = r600_texture_get_offset(rtex, level, box->z);
- return &trans->transfer;
-}
-
-static void si_texture_transfer_destroy(struct pipe_context *ctx,
- struct pipe_transfer *transfer)
-{
- struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
- struct pipe_resource *texture = transfer->resource;
- struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture;
-
- if (rtransfer->staging_texture) {
- if (transfer->usage & PIPE_TRANSFER_WRITE) {
- r600_copy_from_staging_texture(ctx, rtransfer);
- }
- pipe_resource_reference(&rtransfer->staging_texture, NULL);
- }
-
- if (rtex->depth && !rtex->is_flushing_texture) {
- if ((transfer->usage & PIPE_TRANSFER_WRITE) && rtex->flushed_depth_texture)
- r600_blit_push_depth(ctx, rtex);
+ } else {
+ trans->transfer.stride = rtex->surface.level[level].pitch_bytes;
+ trans->transfer.layer_stride = rtex->surface.level[level].slice_size;
+ trans->offset = r600_texture_get_offset(rtex, level, box->z);
}
- pipe_resource_reference(&transfer->resource, NULL);
- FREE(transfer);
-}
-
-static void* si_texture_transfer_map(struct pipe_context *ctx,
- struct pipe_transfer* transfer)
-{
- struct r600_context *rctx = (struct r600_context *)ctx;
- struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
- struct radeon_winsys_cs_handle *buf;
- enum pipe_format format = transfer->resource->format;
- unsigned offset = 0;
- char *map;
-
- if (rtransfer->staging_texture) {
- buf = si_resource(rtransfer->staging_texture)->cs_buf;
+ if (trans->staging_texture) {
+ buf = si_resource(trans->staging_texture)->cs_buf;
} else {
- struct r600_resource_texture *rtex = (struct r600_resource_texture*)transfer->resource;
+ struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture;
if (rtex->flushed_depth_texture)
buf = rtex->flushed_depth_texture->resource.cs_buf;
else
- buf = si_resource(transfer->resource)->cs_buf;
+ buf = si_resource(texture)->cs_buf;
- offset = rtransfer->offset +
- transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
- transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
+ offset = trans->offset +
+ box->y / util_format_get_blockheight(format) * trans->transfer.stride +
+ box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
}
- if (!(map = rctx->ws->buffer_map(buf, rctx->cs, transfer->usage))) {
+ if (!(map = rctx->ws->buffer_map(buf, rctx->cs, usage))) {
+ pipe_resource_reference(&trans->staging_texture, NULL);
+ pipe_resource_reference(&trans->transfer.resource, NULL);
+ FREE(trans);
return NULL;
}
+ *ptransfer = &trans->transfer;
return map + offset;
}
@@ -424,6 +398,8 @@ static void si_texture_transfer_unmap(struct pipe_context *ctx,
struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
struct r600_context *rctx = (struct r600_context*)ctx;
struct radeon_winsys_cs_handle *buf;
+ struct pipe_resource *texture = transfer->resource;
+ struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture;
if (rtransfer->staging_texture) {
buf = si_resource(rtransfer->staging_texture)->cs_buf;
@@ -437,14 +413,27 @@ static void si_texture_transfer_unmap(struct pipe_context *ctx,
}
}
rctx->ws->buffer_unmap(buf);
+
+ if (rtransfer->staging_texture) {
+ if (transfer->usage & PIPE_TRANSFER_WRITE) {
+ r600_copy_from_staging_texture(ctx, rtransfer);
+ }
+ pipe_resource_reference(&rtransfer->staging_texture, NULL);
+ }
+
+ if (rtex->depth && !rtex->is_flushing_texture) {
+ if ((transfer->usage & PIPE_TRANSFER_WRITE) && rtex->flushed_depth_texture)
+ r600_blit_push_depth(ctx, rtex);
+ }
+
+ pipe_resource_reference(&transfer->resource, NULL);
+ FREE(transfer);
}
static const struct u_resource_vtbl r600_texture_vtbl =
{
r600_texture_get_handle, /* get_handle */
r600_texture_destroy, /* resource_destroy */
- si_texture_get_transfer, /* get_transfer */
- si_texture_transfer_destroy, /* transfer_destroy */
si_texture_transfer_map, /* transfer_map */
u_default_transfer_flush_region,/* transfer_flush_region */
si_texture_transfer_unmap, /* transfer_unmap */
diff --git a/src/gallium/drivers/rbug/rbug_context.c b/src/gallium/drivers/rbug/rbug_context.c
index 59d5af9590a..0b59a0121c2 100644
--- a/src/gallium/drivers/rbug/rbug_context.c
+++ b/src/gallium/drivers/rbug/rbug_context.c
@@ -1019,66 +1019,34 @@ rbug_context_surface_destroy(struct pipe_context *_pipe,
-static struct pipe_transfer *
-rbug_context_get_transfer(struct pipe_context *_context,
+static void *
+rbug_context_transfer_map(struct pipe_context *_context,
struct pipe_resource *_resource,
unsigned level,
unsigned usage,
- const struct pipe_box *box)
+ const struct pipe_box *box,
+ struct pipe_transfer **transfer)
{
struct rbug_context *rb_pipe = rbug_context(_context);
struct rbug_resource *rb_resource = rbug_resource(_resource);
struct pipe_context *context = rb_pipe->pipe;
struct pipe_resource *resource = rb_resource->resource;
struct pipe_transfer *result;
+ void *map;
pipe_mutex_lock(rb_pipe->call_mutex);
- result = context->get_transfer(context,
- resource,
- level,
- usage,
- box);
+ map = context->transfer_map(context,
+ resource,
+ level,
+ usage,
+ box, &result);
pipe_mutex_unlock(rb_pipe->call_mutex);
- if (result)
- return rbug_transfer_create(rb_pipe, rb_resource, result);
- return NULL;
+ *transfer = rbug_transfer_create(rb_pipe, rb_resource, result);
+ return *transfer ? map : NULL;
}
static void
-rbug_context_transfer_destroy(struct pipe_context *_pipe,
- struct pipe_transfer *_transfer)
-{
- struct rbug_context *rb_pipe = rbug_context(_pipe);
- struct rbug_transfer *rb_transfer =rbug_transfer(_transfer);
-
- pipe_mutex_lock(rb_pipe->call_mutex);
- rbug_transfer_destroy(rb_pipe,
- rb_transfer);
- pipe_mutex_unlock(rb_pipe->call_mutex);
-}
-
-static void *
-rbug_context_transfer_map(struct pipe_context *_context,
- struct pipe_transfer *_transfer)
-{
- struct rbug_context *rb_pipe = rbug_context(_context);
- struct rbug_transfer *rb_transfer = rbug_transfer(_transfer);
- struct pipe_context *context = rb_pipe->pipe;
- struct pipe_transfer *transfer = rb_transfer->transfer;
- void *ret;
-
- pipe_mutex_lock(rb_pipe->call_mutex);
- ret = context->transfer_map(context,
- transfer);
- pipe_mutex_unlock(rb_pipe->call_mutex);
-
- return ret;
-}
-
-
-
-static void
rbug_context_transfer_flush_region(struct pipe_context *_context,
struct pipe_transfer *_transfer,
const struct pipe_box *box)
@@ -1108,6 +1076,8 @@ rbug_context_transfer_unmap(struct pipe_context *_context,
pipe_mutex_lock(rb_pipe->call_mutex);
context->transfer_unmap(context,
transfer);
+ rbug_transfer_destroy(rb_pipe,
+ rb_transfer);
pipe_mutex_unlock(rb_pipe->call_mutex);
}
@@ -1217,8 +1187,6 @@ rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
rb_pipe->base.sampler_view_destroy = rbug_context_sampler_view_destroy;
rb_pipe->base.create_surface = rbug_context_create_surface;
rb_pipe->base.surface_destroy = rbug_context_surface_destroy;
- rb_pipe->base.get_transfer = rbug_context_get_transfer;
- rb_pipe->base.transfer_destroy = rbug_context_transfer_destroy;
rb_pipe->base.transfer_map = rbug_context_transfer_map;
rb_pipe->base.transfer_unmap = rbug_context_transfer_unmap;
rb_pipe->base.transfer_flush_region = rbug_context_transfer_flush_region;
diff --git a/src/gallium/drivers/rbug/rbug_core.c b/src/gallium/drivers/rbug/rbug_core.c
index 4608b884181..9cbc0e02f4a 100644
--- a/src/gallium/drivers/rbug/rbug_core.c
+++ b/src/gallium/drivers/rbug/rbug_core.c
@@ -266,12 +266,10 @@ rbug_texture_read(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_
}
tex = tr_tex->resource;
- t = pipe_get_transfer(context, tex,
- gptr->level, gptr->face + gptr->zslice,
- PIPE_TRANSFER_READ,
- gptr->x, gptr->y, gptr->w, gptr->h);
-
- map = context->transfer_map(context, t);
+ map = pipe_transfer_map(context, tex,
+ gptr->level, gptr->face + gptr->zslice,
+ PIPE_TRANSFER_READ,
+ gptr->x, gptr->y, gptr->w, gptr->h, &t);
rbug_send_texture_read_reply(tr_rbug->con, serial,
t->resource->format,
@@ -285,7 +283,6 @@ rbug_texture_read(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_
NULL);
context->transfer_unmap(context, t);
- context->transfer_destroy(context, t);
pipe_mutex_unlock(rb_screen->list_mutex);
diff --git a/src/gallium/drivers/rbug/rbug_objects.c b/src/gallium/drivers/rbug/rbug_objects.c
index 15f5db40093..c64b14c1832 100644
--- a/src/gallium/drivers/rbug/rbug_objects.c
+++ b/src/gallium/drivers/rbug/rbug_objects.c
@@ -184,7 +184,7 @@ rbug_transfer_create(struct rbug_context *rb_context,
return &rb_transfer->base;
error:
- rb_context->pipe->transfer_destroy(rb_context->pipe, transfer);
+ rb_context->pipe->transfer_unmap(rb_context->pipe, transfer);
return NULL;
}
@@ -193,8 +193,6 @@ rbug_transfer_destroy(struct rbug_context *rb_context,
struct rbug_transfer *rb_transfer)
{
pipe_resource_reference(&rb_transfer->base.resource, NULL);
- rb_transfer->pipe->transfer_destroy(rb_context->pipe,
- rb_transfer->transfer);
FREE(rb_transfer);
}
diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c
index 891bb261d8a..e2cc1e17dae 100644
--- a/src/gallium/drivers/softpipe/sp_context.c
+++ b/src/gallium/drivers/softpipe/sp_context.c
@@ -53,38 +53,6 @@
#include "sp_screen.h"
-/**
- * Map any drawing surfaces which aren't already mapped
- */
-void
-softpipe_map_transfers(struct softpipe_context *sp)
-{
- unsigned i;
-
- for (i = 0; i < sp->framebuffer.nr_cbufs; i++) {
- sp_tile_cache_map_transfers(sp->cbuf_cache[i]);
- }
-
- sp_tile_cache_map_transfers(sp->zsbuf_cache);
-}
-
-
-/**
- * Unmap any mapped drawing surfaces
- */
-void
-softpipe_unmap_transfers(struct softpipe_context *sp)
-{
- uint i;
-
- for (i = 0; i < sp->framebuffer.nr_cbufs; i++) {
- sp_tile_cache_unmap_transfers(sp->cbuf_cache[i]);
- }
-
- sp_tile_cache_unmap_transfers(sp->zsbuf_cache);
-}
-
-
static void
softpipe_destroy( struct pipe_context *pipe )
{
diff --git a/src/gallium/drivers/softpipe/sp_draw_arrays.c b/src/gallium/drivers/softpipe/sp_draw_arrays.c
index f9fc923a184..59226fb9c15 100644
--- a/src/gallium/drivers/softpipe/sp_draw_arrays.c
+++ b/src/gallium/drivers/softpipe/sp_draw_arrays.c
@@ -73,8 +73,6 @@ softpipe_draw_vbo(struct pipe_context *pipe,
softpipe_update_derived(sp, sp->reduced_api_prim);
}
- softpipe_map_transfers(sp);
-
/* Map vertex buffers */
for (i = 0; i < sp->num_vertex_buffers; i++) {
const void *buf = sp->vertex_buffer[i].user_buffer;
diff --git a/src/gallium/drivers/softpipe/sp_flush.c b/src/gallium/drivers/softpipe/sp_flush.c
index 28660850d29..e28236afc50 100644
--- a/src/gallium/drivers/softpipe/sp_flush.c
+++ b/src/gallium/drivers/softpipe/sp_flush.c
@@ -75,14 +75,6 @@ softpipe_flush( struct pipe_context *pipe,
softpipe->dirty_render_cache = FALSE;
- /* Need this call for hardware buffers before swapbuffers.
- *
- * there should probably be another/different flush-type function
- * that's called before swapbuffers because we don't always want
- * to unmap surfaces when flushing.
- */
- softpipe_unmap_transfers(softpipe);
-
/* Enable to dump BMPs of the color/depth buffers each frame */
#if 0
if(flags & PIPE_FLUSH_FRAME) {
diff --git a/src/gallium/drivers/softpipe/sp_state.h b/src/gallium/drivers/softpipe/sp_state.h
index 6df40c66394..eb85b0689ea 100644
--- a/src/gallium/drivers/softpipe/sp_state.h
+++ b/src/gallium/drivers/softpipe/sp_state.h
@@ -159,12 +159,6 @@ softpipe_draw_vbo(struct pipe_context *pipe,
const struct pipe_draw_info *info);
void
-softpipe_map_transfers(struct softpipe_context *sp);
-
-void
-softpipe_unmap_transfers(struct softpipe_context *sp);
-
-void
softpipe_map_texture_surfaces(struct softpipe_context *sp);
void
diff --git a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c
index 7e1ac6c88fd..b6a848bc5a7 100644
--- a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c
+++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c
@@ -74,10 +74,10 @@ sp_destroy_tex_tile_cache(struct softpipe_tex_tile_cache *tc)
/*assert(tc->entries[pos].x < 0);*/
}
if (tc->transfer) {
- tc->pipe->transfer_destroy(tc->pipe, tc->transfer);
+ tc->pipe->transfer_unmap(tc->pipe, tc->transfer);
}
if (tc->tex_trans) {
- tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans);
+ tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans);
}
FREE( tc );
@@ -131,14 +131,10 @@ sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache *tc,
if (!sp_tex_tile_is_compat_view(tc, view)) {
pipe_resource_reference(&tc->texture, texture);
- if (tc->tex_trans) {
- if (tc->tex_trans_map) {
- tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans);
- tc->tex_trans_map = NULL;
- }
-
- tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans);
+ if (tc->tex_trans_map) {
+ tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans);
tc->tex_trans = NULL;
+ tc->tex_trans_map = NULL;
}
if (view) {
@@ -236,14 +232,10 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc,
/* get new transfer (view into texture) */
unsigned width, height, layer;
- if (tc->tex_trans) {
- if (tc->tex_trans_map) {
- tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans);
- tc->tex_trans_map = NULL;
- }
-
- tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans);
+ if (tc->tex_trans_map) {
+ tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans);
tc->tex_trans = NULL;
+ tc->tex_trans_map = NULL;
}
width = u_minify(tc->texture->width0, addr.bits.level);
@@ -256,14 +248,12 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc,
layer = addr.bits.face + addr.bits.z;
}
- tc->tex_trans =
- pipe_get_transfer(tc->pipe, tc->texture,
+ tc->tex_trans_map =
+ pipe_transfer_map(tc->pipe, tc->texture,
addr.bits.level,
layer,
PIPE_TRANSFER_READ | PIPE_TRANSFER_UNSYNCHRONIZED,
- 0, 0, width, height);
-
- tc->tex_trans_map = tc->pipe->transfer_map(tc->pipe, tc->tex_trans);
+ 0, 0, width, height, &tc->tex_trans);
tc->tex_face = addr.bits.face;
tc->tex_level = addr.bits.level;
@@ -274,8 +264,7 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc,
* the image format.
*/
if (!zs && util_format_is_pure_uint(tc->format)) {
- pipe_get_tile_ui_format(tc->pipe,
- tc->tex_trans,
+ pipe_get_tile_ui_format(tc->tex_trans, tc->tex_trans_map,
addr.bits.x * TILE_SIZE,
addr.bits.y * TILE_SIZE,
TILE_SIZE,
@@ -283,8 +272,7 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc,
tc->format,
(unsigned *) tile->data.colorui);
} else if (!zs && util_format_is_pure_sint(tc->format)) {
- pipe_get_tile_i_format(tc->pipe,
- tc->tex_trans,
+ pipe_get_tile_i_format(tc->tex_trans, tc->tex_trans_map,
addr.bits.x * TILE_SIZE,
addr.bits.y * TILE_SIZE,
TILE_SIZE,
@@ -292,8 +280,7 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc,
tc->format,
(int *) tile->data.colori);
} else {
- pipe_get_tile_rgba_format(tc->pipe,
- tc->tex_trans,
+ pipe_get_tile_rgba_format(tc->tex_trans, tc->tex_trans_map,
addr.bits.x * TILE_SIZE,
addr.bits.y * TILE_SIZE,
TILE_SIZE,
diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c
index 50137fe6227..b4bca076bda 100644
--- a/src/gallium/drivers/softpipe/sp_texture.c
+++ b/src/gallium/drivers/softpipe/sp_texture.c
@@ -331,15 +331,22 @@ softpipe_surface_destroy(struct pipe_context *pipe,
* \param usage bitmask of PIPE_TRANSFER_x flags
* \param box the 1D/2D/3D region of interest
*/
-static struct pipe_transfer *
-softpipe_get_transfer(struct pipe_context *pipe,
+static void *
+softpipe_transfer_map(struct pipe_context *pipe,
struct pipe_resource *resource,
unsigned level,
unsigned usage,
- const struct pipe_box *box)
+ const struct pipe_box *box,
+ struct pipe_transfer **transfer)
{
+ struct sw_winsys *winsys = softpipe_screen(pipe->screen)->winsys;
struct softpipe_resource *spr = softpipe_resource(resource);
struct softpipe_transfer *spt;
+ struct pipe_transfer *pt;
+ enum pipe_format format = resource->format;
+ const unsigned hgt = u_minify(spr->base.height0, level);
+ const unsigned nblocksy = util_format_get_nblocksy(format, hgt);
+ uint8_t *map;
assert(resource);
assert(level <= resource->last_level);
@@ -384,69 +391,41 @@ softpipe_get_transfer(struct pipe_context *pipe,
}
spt = CALLOC_STRUCT(softpipe_transfer);
- if (spt) {
- struct pipe_transfer *pt = &spt->base;
- enum pipe_format format = resource->format;
- const unsigned hgt = u_minify(spr->base.height0, level);
- const unsigned nblocksy = util_format_get_nblocksy(format, hgt);
-
- pipe_resource_reference(&pt->resource, resource);
- pt->level = level;
- pt->usage = usage;
- pt->box = *box;
- pt->stride = spr->stride[level];
- pt->layer_stride = pt->stride * nblocksy;
-
- spt->offset = sp_get_tex_image_offset(spr, level, box->z);
-
- spt->offset +=
- box->y / util_format_get_blockheight(format) * spt->base.stride +
- box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
+ if (!spt)
+ return NULL;
- return pt;
- }
- return NULL;
-}
+ pt = &spt->base;
+ pipe_resource_reference(&pt->resource, resource);
+ pt->level = level;
+ pt->usage = usage;
+ pt->box = *box;
+ pt->stride = spr->stride[level];
+ pt->layer_stride = pt->stride * nblocksy;
-/**
- * Free a pipe_transfer object which was created with
- * softpipe_get_transfer().
- */
-static void
-softpipe_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- pipe_resource_reference(&transfer->resource, NULL);
- FREE(transfer);
-}
+ spt->offset = sp_get_tex_image_offset(spr, level, box->z);
+ spt->offset +=
+ box->y / util_format_get_blockheight(format) * spt->base.stride +
+ box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
-/**
- * Create memory mapping for given pipe_transfer object.
- */
-static void *
-softpipe_transfer_map(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct softpipe_transfer *spt = softpipe_transfer(transfer);
- struct softpipe_resource *spr = softpipe_resource(transfer->resource);
- struct sw_winsys *winsys = softpipe_screen(pipe->screen)->winsys;
- uint8_t *map;
-
/* resources backed by display target treated specially:
*/
if (spr->dt) {
- map = winsys->displaytarget_map(winsys, spr->dt, transfer->usage);
+ map = winsys->displaytarget_map(winsys, spr->dt, usage);
}
else {
map = spr->data;
}
- if (map == NULL)
+ if (map == NULL) {
+ pipe_resource_reference(&pt->resource, NULL);
+ FREE(spt);
return NULL;
- else
- return map + spt->offset;
+ }
+
+ *transfer = pt;
+ return map + spt->offset;
}
@@ -472,6 +451,9 @@ softpipe_transfer_unmap(struct pipe_context *pipe,
/* Mark the texture as dirty to expire the tile caches. */
spr->timestamp++;
}
+
+ pipe_resource_reference(&transfer->resource, NULL);
+ FREE(transfer);
}
/**
@@ -509,8 +491,6 @@ softpipe_user_buffer_create(struct pipe_screen *screen,
void
softpipe_init_texture_funcs(struct pipe_context *pipe)
{
- pipe->get_transfer = softpipe_get_transfer;
- pipe->transfer_destroy = softpipe_transfer_destroy;
pipe->transfer_map = softpipe_transfer_map;
pipe->transfer_unmap = softpipe_transfer_unmap;
diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.c b/src/gallium/drivers/softpipe/sp_tile_cache.c
index 659ac58e5b0..8d581112fcd 100644
--- a/src/gallium/drivers/softpipe/sp_tile_cache.c
+++ b/src/gallium/drivers/softpipe/sp_tile_cache.c
@@ -141,7 +141,7 @@ sp_destroy_tile_cache(struct softpipe_tile_cache *tc)
FREE( tc->tile );
if (tc->transfer) {
- tc->pipe->transfer_destroy(tc->pipe, tc->transfer);
+ tc->pipe->transfer_unmap(tc->pipe, tc->transfer);
}
FREE( tc );
@@ -158,27 +158,24 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc,
{
struct pipe_context *pipe = tc->pipe;
- if (tc->transfer) {
+ if (tc->transfer_map) {
if (ps == tc->surface)
return;
- if (tc->transfer_map) {
- pipe->transfer_unmap(pipe, tc->transfer);
- tc->transfer_map = NULL;
- }
-
- pipe->transfer_destroy(pipe, tc->transfer);
+ pipe->transfer_unmap(pipe, tc->transfer);
tc->transfer = NULL;
+ tc->transfer_map = NULL;
}
tc->surface = ps;
if (ps) {
- tc->transfer = pipe_get_transfer(pipe, ps->texture,
- ps->u.tex.level, ps->u.tex.first_layer,
- PIPE_TRANSFER_READ_WRITE |
- PIPE_TRANSFER_UNSYNCHRONIZED,
- 0, 0, ps->width, ps->height);
+ tc->transfer_map = pipe_transfer_map(pipe, ps->texture,
+ ps->u.tex.level, ps->u.tex.first_layer,
+ PIPE_TRANSFER_READ_WRITE |
+ PIPE_TRANSFER_UNSYNCHRONIZED,
+ 0, 0, ps->width, ps->height,
+ &tc->transfer);
tc->depth_stencil = util_format_is_depth_or_stencil(ps->format);
}
@@ -195,24 +192,6 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc)
}
-void
-sp_tile_cache_map_transfers(struct softpipe_tile_cache *tc)
-{
- if (tc->transfer && !tc->transfer_map)
- tc->transfer_map = tc->pipe->transfer_map(tc->pipe, tc->transfer);
-}
-
-
-void
-sp_tile_cache_unmap_transfers(struct softpipe_tile_cache *tc)
-{
- if (tc->transfer_map) {
- tc->pipe->transfer_unmap(tc->pipe, tc->transfer);
- tc->transfer_map = NULL;
- }
-}
-
-
/**
* Set pixels in a tile to the given clear color/value, float.
*/
@@ -349,24 +328,23 @@ sp_tile_cache_flush_clear(struct softpipe_tile_cache *tc)
if (is_clear_flag_set(tc->clear_flags, addr)) {
/* write the scratch tile to the surface */
if (tc->depth_stencil) {
- pipe_put_tile_raw(tc->pipe,
- pt,
+ pipe_put_tile_raw(pt, tc->transfer_map,
x, y, TILE_SIZE, TILE_SIZE,
tc->tile->data.any, 0/*STRIDE*/);
}
else {
if (util_format_is_pure_uint(tc->surface->format)) {
- pipe_put_tile_ui_format(tc->pipe, pt,
+ pipe_put_tile_ui_format(pt, tc->transfer_map,
x, y, TILE_SIZE, TILE_SIZE,
pt->resource->format,
(unsigned *) tc->tile->data.colorui128);
} else if (util_format_is_pure_sint(tc->surface->format)) {
- pipe_put_tile_i_format(tc->pipe, pt,
+ pipe_put_tile_i_format(pt, tc->transfer_map,
x, y, TILE_SIZE, TILE_SIZE,
pt->resource->format,
(int *) tc->tile->data.colori128);
} else {
- pipe_put_tile_rgba(tc->pipe, pt,
+ pipe_put_tile_rgba(pt, tc->transfer_map,
x, y, TILE_SIZE, TILE_SIZE,
(float *) tc->tile->data.color);
}
@@ -389,7 +367,7 @@ sp_flush_tile(struct softpipe_tile_cache* tc, unsigned pos)
{
if (!tc->tile_addrs[pos].bits.invalid) {
if (tc->depth_stencil) {
- pipe_put_tile_raw(tc->pipe, tc->transfer,
+ pipe_put_tile_raw(tc->transfer, tc->transfer_map,
tc->tile_addrs[pos].bits.x * TILE_SIZE,
tc->tile_addrs[pos].bits.y * TILE_SIZE,
TILE_SIZE, TILE_SIZE,
@@ -397,21 +375,21 @@ sp_flush_tile(struct softpipe_tile_cache* tc, unsigned pos)
}
else {
if (util_format_is_pure_uint(tc->surface->format)) {
- pipe_put_tile_ui_format(tc->pipe, tc->transfer,
+ pipe_put_tile_ui_format(tc->transfer, tc->transfer_map,
tc->tile_addrs[pos].bits.x * TILE_SIZE,
tc->tile_addrs[pos].bits.y * TILE_SIZE,
TILE_SIZE, TILE_SIZE,
tc->surface->format,
(unsigned *) tc->entries[pos]->data.colorui128);
} else if (util_format_is_pure_sint(tc->surface->format)) {
- pipe_put_tile_i_format(tc->pipe, tc->transfer,
+ pipe_put_tile_i_format(tc->transfer, tc->transfer_map,
tc->tile_addrs[pos].bits.x * TILE_SIZE,
tc->tile_addrs[pos].bits.y * TILE_SIZE,
TILE_SIZE, TILE_SIZE,
tc->surface->format,
(int *) tc->entries[pos]->data.colori128);
} else {
- pipe_put_tile_rgba_format(tc->pipe, tc->transfer,
+ pipe_put_tile_rgba_format(tc->transfer, tc->transfer_map,
tc->tile_addrs[pos].bits.x * TILE_SIZE,
tc->tile_addrs[pos].bits.y * TILE_SIZE,
TILE_SIZE, TILE_SIZE,
@@ -516,7 +494,7 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
if (tc->tile_addrs[pos].bits.invalid == 0) {
/* put dirty tile back in framebuffer */
if (tc->depth_stencil) {
- pipe_put_tile_raw(tc->pipe, pt,
+ pipe_put_tile_raw(pt, tc->transfer_map,
tc->tile_addrs[pos].bits.x * TILE_SIZE,
tc->tile_addrs[pos].bits.y * TILE_SIZE,
TILE_SIZE, TILE_SIZE,
@@ -524,21 +502,21 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
}
else {
if (util_format_is_pure_uint(tc->surface->format)) {
- pipe_put_tile_ui_format(tc->pipe, pt,
+ pipe_put_tile_ui_format(pt, tc->transfer_map,
tc->tile_addrs[pos].bits.x * TILE_SIZE,
tc->tile_addrs[pos].bits.y * TILE_SIZE,
TILE_SIZE, TILE_SIZE,
tc->surface->format,
(unsigned *) tile->data.colorui128);
} else if (util_format_is_pure_sint(tc->surface->format)) {
- pipe_put_tile_i_format(tc->pipe, pt,
+ pipe_put_tile_i_format(pt, tc->transfer_map,
tc->tile_addrs[pos].bits.x * TILE_SIZE,
tc->tile_addrs[pos].bits.y * TILE_SIZE,
TILE_SIZE, TILE_SIZE,
tc->surface->format,
(int *) tile->data.colori128);
} else {
- pipe_put_tile_rgba_format(tc->pipe, pt,
+ pipe_put_tile_rgba_format(pt, tc->transfer_map,
tc->tile_addrs[pos].bits.x * TILE_SIZE,
tc->tile_addrs[pos].bits.y * TILE_SIZE,
TILE_SIZE, TILE_SIZE,
@@ -563,7 +541,7 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
else {
/* get new tile data from transfer */
if (tc->depth_stencil) {
- pipe_get_tile_raw(tc->pipe, pt,
+ pipe_get_tile_raw(pt, tc->transfer_map,
tc->tile_addrs[pos].bits.x * TILE_SIZE,
tc->tile_addrs[pos].bits.y * TILE_SIZE,
TILE_SIZE, TILE_SIZE,
@@ -571,21 +549,21 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
}
else {
if (util_format_is_pure_uint(tc->surface->format)) {
- pipe_get_tile_ui_format(tc->pipe, pt,
+ pipe_get_tile_ui_format(pt, tc->transfer_map,
tc->tile_addrs[pos].bits.x * TILE_SIZE,
tc->tile_addrs[pos].bits.y * TILE_SIZE,
TILE_SIZE, TILE_SIZE,
tc->surface->format,
(unsigned *) tile->data.colorui128);
} else if (util_format_is_pure_sint(tc->surface->format)) {
- pipe_get_tile_i_format(tc->pipe, pt,
+ pipe_get_tile_i_format(pt, tc->transfer_map,
tc->tile_addrs[pos].bits.x * TILE_SIZE,
tc->tile_addrs[pos].bits.y * TILE_SIZE,
TILE_SIZE, TILE_SIZE,
tc->surface->format,
(int *) tile->data.colori128);
} else {
- pipe_get_tile_rgba_format(tc->pipe, pt,
+ pipe_get_tile_rgba_format(pt, tc->transfer_map,
tc->tile_addrs[pos].bits.x * TILE_SIZE,
tc->tile_addrs[pos].bits.y * TILE_SIZE,
TILE_SIZE, TILE_SIZE,
diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.h b/src/gallium/drivers/softpipe/sp_tile_cache.h
index 775676b4bf5..8d0466b8191 100644
--- a/src/gallium/drivers/softpipe/sp_tile_cache.h
+++ b/src/gallium/drivers/softpipe/sp_tile_cache.h
@@ -113,12 +113,6 @@ extern struct pipe_surface *
sp_tile_cache_get_surface(struct softpipe_tile_cache *tc);
extern void
-sp_tile_cache_map_transfers(struct softpipe_tile_cache *tc);
-
-extern void
-sp_tile_cache_unmap_transfers(struct softpipe_tile_cache *tc);
-
-extern void
sp_flush_tile_cache(struct softpipe_tile_cache *tc);
extern void
diff --git a/src/gallium/drivers/svga/svga_resource.c b/src/gallium/drivers/svga/svga_resource.c
index 890c953a3c2..79951b34db5 100644
--- a/src/gallium/drivers/svga/svga_resource.c
+++ b/src/gallium/drivers/svga/svga_resource.c
@@ -58,11 +58,9 @@ svga_resource_from_handle(struct pipe_screen * screen,
void
svga_init_resource_functions(struct svga_context *svga)
{
- svga->pipe.get_transfer = u_get_transfer_vtbl;
svga->pipe.transfer_map = u_transfer_map_vtbl;
svga->pipe.transfer_flush_region = u_transfer_flush_region_vtbl;
svga->pipe.transfer_unmap = u_transfer_unmap_vtbl;
- svga->pipe.transfer_destroy = u_transfer_destroy_vtbl;
svga->pipe.transfer_inline_write = u_transfer_inline_write_vtbl;
}
diff --git a/src/gallium/drivers/svga/svga_resource_buffer.c b/src/gallium/drivers/svga/svga_resource_buffer.c
index fa713ee88ad..87a4a9b7a82 100644
--- a/src/gallium/drivers/svga/svga_resource_buffer.c
+++ b/src/gallium/drivers/svga/svga_resource_buffer.c
@@ -62,17 +62,19 @@ svga_buffer_needs_hw_storage(unsigned usage)
* the end result is exactly the same as if one DMA was used for every mapped
* range.
*/
-static struct pipe_transfer *
-svga_buffer_get_transfer(struct pipe_context *pipe,
+static void *
+svga_buffer_transfer_map(struct pipe_context *pipe,
struct pipe_resource *resource,
unsigned level,
unsigned usage,
- const struct pipe_box *box)
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
struct svga_context *svga = svga_context(pipe);
struct svga_screen *ss = svga_screen(pipe->screen);
struct svga_buffer *sbuf = svga_buffer(resource);
struct pipe_transfer *transfer;
+ uint8_t *map;
transfer = CALLOC_STRUCT(pipe_transfer);
if (transfer == NULL) {
@@ -186,21 +188,6 @@ svga_buffer_get_transfer(struct pipe_context *pipe,
}
}
- return transfer;
-}
-
-
-/**
- * Map a range of a buffer.
- */
-static void *
-svga_buffer_transfer_map( struct pipe_context *pipe,
- struct pipe_transfer *transfer )
-{
- struct svga_buffer *sbuf = svga_buffer(transfer->resource);
-
- uint8_t *map;
-
if (sbuf->swbuf) {
/* User/malloc buffer */
map = sbuf->swbuf;
@@ -218,6 +205,7 @@ svga_buffer_transfer_map( struct pipe_context *pipe,
if (map) {
++sbuf->map.count;
map += transfer->box.x;
+ *ptransfer = transfer;
}
return map;
@@ -280,16 +268,6 @@ svga_buffer_transfer_unmap( struct pipe_context *pipe,
}
pipe_mutex_unlock(ss->swc_mutex);
-}
-
-
-/**
- * Destroy transfer
- */
-static void
-svga_buffer_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
FREE(transfer);
}
@@ -325,8 +303,6 @@ struct u_resource_vtbl svga_buffer_vtbl =
{
u_default_resource_get_handle, /* get_handle */
svga_buffer_destroy, /* resource_destroy */
- svga_buffer_get_transfer, /* get_transfer */
- svga_buffer_transfer_destroy, /* transfer_destroy */
svga_buffer_transfer_map, /* transfer_map */
svga_buffer_transfer_flush_region, /* transfer_flush_region */
svga_buffer_transfer_unmap, /* transfer_unmap */
diff --git a/src/gallium/drivers/svga/svga_resource_texture.c b/src/gallium/drivers/svga/svga_resource_texture.c
index 97ec7eeea7e..1d796cb6a9b 100644
--- a/src/gallium/drivers/svga/svga_resource_texture.c
+++ b/src/gallium/drivers/svga/svga_resource_texture.c
@@ -236,12 +236,13 @@ svga_texture_destroy(struct pipe_screen *screen,
/* XXX: Still implementing this as if it was a screen function, but
* can now modify it to queue transfers on the context.
*/
-static struct pipe_transfer *
-svga_texture_get_transfer(struct pipe_context *pipe,
+static void *
+svga_texture_transfer_map(struct pipe_context *pipe,
struct pipe_resource *texture,
unsigned level,
unsigned usage,
- const struct pipe_box *box)
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
struct svga_context *svga = svga_context(pipe);
struct svga_screen *ss = svga_screen(pipe->screen);
@@ -259,7 +260,7 @@ svga_texture_get_transfer(struct pipe_context *pipe,
if (!st)
return NULL;
- pipe_resource_reference(&st->base.resource, texture);
+ st->base.resource = texture;
st->base.level = level;
st->base.usage = usage;
st->base.box = *box;
@@ -305,8 +306,22 @@ svga_texture_get_transfer(struct pipe_context *pipe,
svga_transfer_dma(svga, st, SVGA3D_READ_HOST_VRAM, flags);
}
- return &st->base;
+ if (st->swbuf) {
+ *ptransfer = &st->base;
+ return st->swbuf;
+ } else {
+ /* The wait for read transfers already happened when svga_transfer_dma
+ * was called. */
+ void *map = sws->buffer_map(sws, st->hwbuf, usage);
+ if (!map)
+ goto fail;
+
+ *ptransfer = &st->base;
+ return map;
+ }
+fail:
+ FREE(st->swbuf);
no_swbuf:
sws->buffer_destroy(sws, st->hwbuf);
no_hwbuf:
@@ -318,48 +333,18 @@ no_hwbuf:
/* XXX: Still implementing this as if it was a screen function, but
* can now modify it to queue transfers on the context.
*/
-static void *
-svga_texture_transfer_map( struct pipe_context *pipe,
- struct pipe_transfer *transfer )
-{
- struct svga_screen *ss = svga_screen(pipe->screen);
- struct svga_winsys_screen *sws = ss->sws;
- struct svga_transfer *st = svga_transfer(transfer);
-
- if(st->swbuf)
- return st->swbuf;
- else
- /* The wait for read transfers already happened when svga_transfer_dma
- * was called. */
- return sws->buffer_map(sws, st->hwbuf, transfer->usage);
-}
-
-
-/* XXX: Still implementing this as if it was a screen function, but
- * can now modify it to queue transfers on the context.
- */
static void
svga_texture_transfer_unmap(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
+ struct svga_context *svga = svga_context(pipe);
struct svga_screen *ss = svga_screen(pipe->screen);
struct svga_winsys_screen *sws = ss->sws;
struct svga_transfer *st = svga_transfer(transfer);
-
+ struct svga_texture *tex = svga_texture(transfer->resource);
+
if(!st->swbuf)
sws->buffer_unmap(sws, st->hwbuf);
-}
-
-
-static void
-svga_texture_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct svga_context *svga = svga_context(pipe);
- struct svga_texture *tex = svga_texture(transfer->resource);
- struct svga_screen *ss = svga_screen(pipe->screen);
- struct svga_winsys_screen *sws = ss->sws;
- struct svga_transfer *st = svga_transfer(transfer);
if (st->base.usage & PIPE_TRANSFER_WRITE) {
SVGA3dSurfaceDMAFlags flags;
@@ -381,7 +366,6 @@ svga_texture_transfer_destroy(struct pipe_context *pipe,
tex->defined[0][transfer->level] = TRUE;
}
- pipe_resource_reference(&st->base.resource, NULL);
FREE(st->swbuf);
sws->buffer_destroy(sws, st->hwbuf);
FREE(st);
@@ -392,8 +376,6 @@ struct u_resource_vtbl svga_texture_vtbl =
{
svga_texture_get_handle, /* get_handle */
svga_texture_destroy, /* resource_destroy */
- svga_texture_get_transfer, /* get_transfer */
- svga_texture_transfer_destroy, /* transfer_destroy */
svga_texture_transfer_map, /* transfer_map */
u_default_transfer_flush_region, /* transfer_flush_region */
svga_texture_transfer_unmap, /* transfer_unmap */
diff --git a/src/gallium/drivers/svga/svga_swtnl_backend.c b/src/gallium/drivers/svga/svga_swtnl_backend.c
index 33557aa937a..8900cdde18d 100644
--- a/src/gallium/drivers/svga/svga_swtnl_backend.c
+++ b/src/gallium/drivers/svga/svga_swtnl_backend.c
@@ -131,8 +131,10 @@ svga_vbuf_render_map_vertices( struct vbuf_render *render )
&svga_render->vbuf_transfer);
if (ptr)
return ptr + svga_render->vbuf_offset;
- else
+ else {
+ svga_render->vbuf_transfer = NULL;
return NULL;
+ }
}
else {
/* we probably ran out of memory when allocating the vertex buffer */
diff --git a/src/gallium/drivers/trace/tr_context.c b/src/gallium/drivers/trace/tr_context.c
index affdfca228f..dd1b5a00de7 100644
--- a/src/gallium/drivers/trace/tr_context.c
+++ b/src/gallium/drivers/trace/tr_context.c
@@ -1377,18 +1377,20 @@ trace_context_destroy(struct pipe_context *_pipe)
*/
-static struct pipe_transfer *
-trace_context_get_transfer(struct pipe_context *_context,
+static void *
+trace_context_transfer_map(struct pipe_context *_context,
struct pipe_resource *_resource,
unsigned level,
unsigned usage,
- const struct pipe_box *box)
+ const struct pipe_box *box,
+ struct pipe_transfer **transfer)
{
struct trace_context *tr_context = trace_context(_context);
struct trace_resource *tr_res = trace_resource(_resource);
struct pipe_context *context = tr_context->pipe;
struct pipe_resource *texture = tr_res->resource;
struct pipe_transfer *result = NULL;
+ void *map;
assert(texture->screen == context->screen);
@@ -1397,48 +1399,21 @@ trace_context_get_transfer(struct pipe_context *_context,
* to transfer_inline_write and ignore read transfers.
*/
- result = context->get_transfer(context, texture, level, usage, box);
-
- if (result)
- result = trace_transfer_create(tr_context, tr_res, result);
-
- return result;
-}
-
-
-static void
-trace_context_transfer_destroy(struct pipe_context *_context,
- struct pipe_transfer *_transfer)
-{
- struct trace_context *tr_context = trace_context(_context);
- struct trace_transfer *tr_trans = trace_transfer(_transfer);
-
- trace_transfer_destroy(tr_context, tr_trans);
-}
+ map = context->transfer_map(context, texture, level, usage, box, &result);
+ if (!map)
+ return NULL;
+ *transfer = trace_transfer_create(tr_context, tr_res, result);
-static void *
-trace_context_transfer_map(struct pipe_context *_context,
- struct pipe_transfer *_transfer)
-{
- struct trace_context *tr_context = trace_context(_context);
- struct trace_transfer *tr_trans = trace_transfer(_transfer);
- struct pipe_context *context = tr_context->pipe;
- struct pipe_transfer *transfer = tr_trans->transfer;
- void *map;
-
- map = context->transfer_map(context, transfer);
- if(map) {
- if(transfer->usage & PIPE_TRANSFER_WRITE) {
- assert(!tr_trans->map);
- tr_trans->map = map;
+ if (map) {
+ if(usage & PIPE_TRANSFER_WRITE) {
+ trace_transfer(*transfer)->map = map;
}
}
- return map;
+ return *transfer ? map : NULL;
}
-
static void
trace_context_transfer_flush_region( struct pipe_context *_context,
struct pipe_transfer *_transfer,
@@ -1500,6 +1475,7 @@ trace_context_transfer_unmap(struct pipe_context *_context,
}
context->transfer_unmap(context, transfer);
+ trace_transfer_destroy(tr_ctx, tr_trans);
}
@@ -1667,8 +1643,6 @@ trace_context_create(struct trace_screen *tr_scr,
TR_CTX_INIT(render_condition);
TR_CTX_INIT(texture_barrier);
- TR_CTX_INIT(get_transfer);
- TR_CTX_INIT(transfer_destroy);
TR_CTX_INIT(transfer_map);
TR_CTX_INIT(transfer_unmap);
TR_CTX_INIT(transfer_flush_region);
diff --git a/src/gallium/drivers/trace/tr_texture.c b/src/gallium/drivers/trace/tr_texture.c
index 648b7a4f1cc..81ebc9ee770 100644
--- a/src/gallium/drivers/trace/tr_texture.c
+++ b/src/gallium/drivers/trace/tr_texture.c
@@ -139,7 +139,7 @@ trace_transfer_create(struct trace_context *tr_ctx,
return &tr_trans->base;
error:
- tr_ctx->pipe->transfer_destroy(tr_ctx->pipe, transfer);
+ tr_ctx->pipe->transfer_unmap(tr_ctx->pipe, transfer);
return NULL;
}
@@ -148,11 +148,7 @@ void
trace_transfer_destroy(struct trace_context *tr_context,
struct trace_transfer *tr_trans)
{
- struct pipe_context *context = tr_context->pipe;
- struct pipe_transfer *transfer = tr_trans->transfer;
-
pipe_resource_reference(&tr_trans->base.resource, NULL);
- context->transfer_destroy(context, transfer);
FREE(tr_trans);
}