summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/svga
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/svga
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/svga')
-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
4 files changed, 32 insertions, 74 deletions
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 */