diff options
author | Marek Olšák <[email protected]> | 2012-10-08 04:06:42 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2012-10-11 21:12:16 +0200 |
commit | 369e46888904c6d379b8b477d9242cff1608e30e (patch) | |
tree | 528b10f900f23af3acd22a0edcf50fde0eeee86e /src/mesa/state_tracker | |
parent | ec4c74a9dc10039d97ad24c4f16bd2400517991d (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/mesa/state_tracker')
-rw-r--r-- | src/mesa/state_tracker/st_atom_pixeltransfer.c | 8 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_bitmap.c | 26 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_bufferobjects.c | 3 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_drawpixels.c | 60 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_fbo.c | 15 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_texture.c | 50 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_texture.c | 18 |
7 files changed, 80 insertions, 100 deletions
diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 8d2317ea152..b612f784630 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -101,10 +101,9 @@ load_color_map_texture(struct gl_context *ctx, struct pipe_resource *pt) uint *dest; uint i, j; - transfer = pipe_get_transfer(pipe, - pt, 0, 0, PIPE_TRANSFER_WRITE, - 0, 0, texSize, texSize); - dest = (uint *) pipe_transfer_map(pipe, transfer); + dest = (uint *) pipe_transfer_map(pipe, + pt, 0, 0, PIPE_TRANSFER_WRITE, + 0, 0, texSize, texSize, &transfer); /* Pack four 1D maps into a 2D texture: * R map is placed horizontally, indexed by S, in channel 0 @@ -127,7 +126,6 @@ load_color_map_texture(struct gl_context *ctx, struct pipe_resource *pt) } pipe_transfer_unmap(pipe, transfer); - pipe->transfer_destroy(pipe, transfer); } diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index e4d6c4a85bf..b024ef0db32 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -306,11 +306,9 @@ make_bitmap_texture(struct gl_context *ctx, GLsizei width, GLsizei height, return NULL; } - transfer = pipe_get_transfer(st->pipe, pt, 0, 0, - PIPE_TRANSFER_WRITE, - 0, 0, width, height); - - dest = pipe_transfer_map(pipe, transfer); + dest = pipe_transfer_map(st->pipe, pt, 0, 0, + PIPE_TRANSFER_WRITE, + 0, 0, width, height, &transfer); /* Put image into texture transfer */ memset(dest, 0xff, height * transfer->stride); @@ -321,8 +319,6 @@ make_bitmap_texture(struct gl_context *ctx, GLsizei width, GLsizei height, /* Release transfer */ pipe_transfer_unmap(pipe, transfer); - pipe->transfer_destroy(pipe, transfer); - return pt; } @@ -611,11 +607,10 @@ create_cache_trans(struct st_context *st) /* Map the texture transfer. * Subsequent glBitmap calls will write into the texture image. */ - cache->trans = pipe_get_transfer(st->pipe, cache->texture, 0, 0, - PIPE_TRANSFER_WRITE, 0, 0, - BITMAP_CACHE_WIDTH, - BITMAP_CACHE_HEIGHT); - cache->buffer = pipe_transfer_map(pipe, cache->trans); + cache->buffer = pipe_transfer_map(pipe, cache->texture, 0, 0, + PIPE_TRANSFER_WRITE, 0, 0, + BITMAP_CACHE_WIDTH, + BITMAP_CACHE_HEIGHT, &cache->trans); /* init image to all 0xff */ memset(cache->buffer, 0xff, cache->trans->stride * BITMAP_CACHE_HEIGHT); @@ -645,13 +640,11 @@ st_flush_bitmap_cache(struct st_context *st) /* The texture transfer has been mapped until now. * So unmap and release the texture transfer before drawing. */ - if (cache->trans) { + if (cache->trans && cache->buffer) { if (0) print_cache(cache); pipe_transfer_unmap(pipe, cache->trans); cache->buffer = NULL; - - pipe->transfer_destroy(pipe, cache->trans); cache->trans = NULL; } @@ -867,9 +860,8 @@ st_destroy_bitmap(struct st_context *st) } if (cache) { - if (cache->trans) { + if (cache->trans && cache->buffer) { pipe_transfer_unmap(pipe, cache->trans); - pipe->transfer_destroy(pipe, cache->trans); } pipe_resource_reference(&st->bitmap.cache->texture, NULL); free(st->bitmap.cache); diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index b47a2d87f74..ac38128dfd9 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -298,6 +298,9 @@ st_bufferobj_map_range(struct gl_context *ctx, obj->Length = length; obj->AccessFlags = access; } + else { + st_obj->transfer = NULL; + } return obj->Pointer; } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index a8a01db969d..121496a41cd 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -514,12 +514,10 @@ make_texture(struct st_context *st, /* we'll do pixel transfer in a fragment shader */ ctx->_ImageTransferState = 0x0; - transfer = pipe_get_transfer(st->pipe, pt, 0, 0, - PIPE_TRANSFER_WRITE, 0, 0, - width, height); - /* map texture transfer */ - dest = pipe_transfer_map(pipe, transfer); + dest = pipe_transfer_map(pipe, pt, 0, 0, + PIPE_TRANSFER_WRITE, 0, 0, + width, height, &transfer); /* Put image into texture transfer. @@ -538,7 +536,6 @@ make_texture(struct st_context *st, /* unmap */ pipe_transfer_unmap(pipe, transfer); - pipe->transfer_destroy(pipe, transfer); assert(success); @@ -863,12 +860,10 @@ draw_stencil_pixels(struct gl_context *ctx, GLint x, GLint y, usage = PIPE_TRANSFER_WRITE; } - pt = pipe_get_transfer(pipe, strb->texture, - strb->rtt_level, strb->rtt_face + strb->rtt_slice, - usage, x, y, - width, height); - - stmap = pipe_transfer_map(pipe, pt); + stmap = pipe_transfer_map(pipe, strb->texture, + strb->rtt_level, strb->rtt_face + strb->rtt_slice, + usage, x, y, + width, height, &pt); pixels = _mesa_map_pbo_source(ctx, &clippedUnpack, pixels); assert(pixels); @@ -996,7 +991,6 @@ draw_stencil_pixels(struct gl_context *ctx, GLint x, GLint y, /* unmap the stencil buffer */ pipe_transfer_unmap(pipe, pt); - pipe->transfer_destroy(pipe, pt); } @@ -1247,18 +1241,16 @@ copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy, dsty = rbDraw->Base.Height - dsty - height; } - ptDraw = pipe_get_transfer(pipe, - rbDraw->texture, - rbDraw->rtt_level, - rbDraw->rtt_face + rbDraw->rtt_slice, - usage, dstx, dsty, - width, height); - assert(util_format_get_blockwidth(ptDraw->resource->format) == 1); assert(util_format_get_blockheight(ptDraw->resource->format) == 1); /* map the stencil buffer */ - drawMap = pipe_transfer_map(pipe, ptDraw); + drawMap = pipe_transfer_map(pipe, + rbDraw->texture, + rbDraw->rtt_level, + rbDraw->rtt_face + rbDraw->rtt_slice, + usage, dstx, dsty, + width, height, &ptDraw); /* draw */ /* XXX PixelZoom not handled yet */ @@ -1283,7 +1275,6 @@ copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy, /* unmap the stencil buffer */ pipe_transfer_unmap(pipe, ptDraw); - pipe->transfer_destroy(pipe, ptDraw); } @@ -1573,13 +1564,15 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy, } else { /* CPU-based fallback/conversion */ - struct pipe_transfer *ptRead = - pipe_get_transfer(st->pipe, rbRead->texture, + struct pipe_transfer *ptRead; + void *mapRead = + pipe_transfer_map(st->pipe, rbRead->texture, rbRead->rtt_level, rbRead->rtt_face + rbRead->rtt_slice, PIPE_TRANSFER_READ, - readX, readY, readW, readH); + readX, readY, readW, readH, &ptRead); struct pipe_transfer *ptTex; + void *mapTex; enum pipe_transfer_usage transfer_usage; if (ST_DEBUG & DEBUG_FALLBACK) @@ -1590,8 +1583,8 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy, else transfer_usage = PIPE_TRANSFER_WRITE; - ptTex = pipe_get_transfer(st->pipe, pt, 0, 0, transfer_usage, - 0, 0, width, height); + mapTex = pipe_transfer_map(st->pipe, pt, 0, 0, transfer_usage, + 0, 0, width, height, &ptTex); /* copy image from ptRead surface to ptTex surface */ if (type == GL_COLOR) { @@ -1600,23 +1593,24 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy, enum pipe_format readFormat, drawFormat; readFormat = util_format_linear(rbRead->texture->format); drawFormat = util_format_linear(pt->format); - pipe_get_tile_rgba_format(pipe, ptRead, 0, 0, readW, readH, + pipe_get_tile_rgba_format(ptRead, mapRead, 0, 0, readW, readH, readFormat, buf); - pipe_put_tile_rgba_format(pipe, ptTex, pack.SkipPixels, pack.SkipRows, + pipe_put_tile_rgba_format(ptTex, mapTex, pack.SkipPixels, + pack.SkipRows, readW, readH, drawFormat, buf); free(buf); } else { /* GL_DEPTH */ GLuint *buf = malloc(width * height * sizeof(GLuint)); - pipe_get_tile_z(pipe, ptRead, 0, 0, readW, readH, buf); - pipe_put_tile_z(pipe, ptTex, pack.SkipPixels, pack.SkipRows, + pipe_get_tile_z(ptRead, mapRead, 0, 0, readW, readH, buf); + pipe_put_tile_z(ptTex, mapTex, pack.SkipPixels, pack.SkipRows, readW, readH, buf); free(buf); } - pipe->transfer_destroy(pipe, ptRead); - pipe->transfer_destroy(pipe, ptTex); + pipe->transfer_unmap(pipe, ptRead); + pipe->transfer_unmap(pipe, ptTex); } /* OK, the texture 'pt' contains the src image/pixels. Now draw a diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index c523795b91f..882fb372b05 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -708,6 +708,7 @@ st_MapRenderbuffer(struct gl_context *ctx, const GLboolean invert = rb->Name == 0; unsigned usage; GLuint y2; + GLubyte *map; if (strb->software) { /* software-allocated renderbuffer (probably an accum buffer) */ @@ -742,13 +743,12 @@ st_MapRenderbuffer(struct gl_context *ctx, else y2 = y; - strb->transfer = pipe_get_transfer(pipe, - strb->texture, - strb->rtt_level, - strb->rtt_face + strb->rtt_slice, - usage, x, y2, w, h); - if (strb->transfer) { - GLubyte *map = pipe_transfer_map(pipe, strb->transfer); + map = pipe_transfer_map(pipe, + strb->texture, + strb->rtt_level, + strb->rtt_face + strb->rtt_slice, + usage, x, y2, w, h, &strb->transfer); + if (map) { if (invert) { *rowStrideOut = -strb->transfer->stride; map += (h - 1) * strb->transfer->stride; @@ -782,7 +782,6 @@ st_UnmapRenderbuffer(struct gl_context *ctx, } pipe_transfer_unmap(pipe, strb->transfer); - pipe->transfer_destroy(pipe, strb->transfer); strb->transfer = NULL; } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index a5d997efca4..5bf3dc699b7 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -578,9 +578,10 @@ decompress_with_blit(struct gl_context * ctx, const GLuint width = texImage->Width; const GLuint height = texImage->Height; struct pipe_resource *dst_texture; - struct pipe_transfer *tex_xfer; struct pipe_blit_info blit; unsigned bind = (PIPE_BIND_RENDER_TARGET | PIPE_BIND_TRANSFER_READ); + struct pipe_transfer *tex_xfer; + ubyte *map; /* create temp / dest surface */ if (!util_create_rgba_texture(pipe, width, height, bind, @@ -610,21 +611,22 @@ decompress_with_blit(struct gl_context * ctx, /* blit/render/decompress */ st->pipe->blit(st->pipe, &blit); - /* map the dst_surface so we can read from it */ - tex_xfer = pipe_get_transfer(pipe, - dst_texture, 0, 0, - PIPE_TRANSFER_READ, - 0, 0, width, height); - pixels = _mesa_map_pbo_dest(ctx, &ctx->Pack, pixels); + map = pipe_transfer_map(pipe, dst_texture, 0, 0, + PIPE_TRANSFER_READ, + 0, 0, width, height, &tex_xfer); + if (!map) { + goto end; + } + /* copy/pack data into user buffer */ if (_mesa_format_matches_format_and_type(stImage->base.TexFormat, format, type, ctx->Pack.SwapBytes)) { /* memcpy */ const uint bytesPerRow = width * util_format_get_blocksize(stImage->pt->format); - ubyte *map = pipe_transfer_map(pipe, tex_xfer); + /* map the dst_surface so we can read from it */ GLuint row; for (row = 0; row < height; row++) { GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width, @@ -655,7 +657,7 @@ decompress_with_blit(struct gl_context * ctx, debug_printf("%s: fallback format translation\n", __FUNCTION__); /* get float[4] rgba row from surface */ - pipe_get_tile_rgba_format(pipe, tex_xfer, 0, row, width, 1, + pipe_get_tile_rgba_format(tex_xfer, map, 0, row, width, 1, pformat, rgba); _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format, @@ -666,10 +668,10 @@ decompress_with_blit(struct gl_context * ctx, } end: - _mesa_unmap_pbo_dest(ctx, &ctx->Pack); - - pipe->transfer_destroy(pipe, tex_xfer); + if (map) + pipe_transfer_unmap(pipe, tex_xfer); + _mesa_unmap_pbo_dest(ctx, &ctx->Pack); pipe_resource_reference(&dst_texture, NULL); } @@ -720,6 +722,7 @@ fallback_copy_texsubimage(struct gl_context *ctx, struct pipe_transfer *src_trans; GLvoid *texDest; enum pipe_transfer_usage transfer_usage; + void *map; if (ST_DEBUG & DEBUG_FALLBACK) debug_printf("%s: fallback processing\n", __FUNCTION__); @@ -728,13 +731,13 @@ fallback_copy_texsubimage(struct gl_context *ctx, srcY = strb->Base.Height - srcY - height; } - src_trans = pipe_get_transfer(pipe, - strb->texture, - strb->rtt_level, - strb->rtt_face + strb->rtt_slice, - PIPE_TRANSFER_READ, - srcX, srcY, - width, height); + map = pipe_transfer_map(pipe, + strb->texture, + strb->rtt_level, + strb->rtt_face + strb->rtt_slice, + PIPE_TRANSFER_READ, + srcX, srcY, + width, height, &src_trans); if ((baseFormat == GL_DEPTH_COMPONENT || baseFormat == GL_DEPTH_STENCIL) && @@ -769,11 +772,12 @@ fallback_copy_texsubimage(struct gl_context *ctx, if (data) { /* To avoid a large temp memory allocation, do copy row by row */ for (row = 0; row < height; row++, srcY += yStep) { - pipe_get_tile_z(pipe, src_trans, 0, srcY, width, 1, data); + pipe_get_tile_z(src_trans, map, 0, srcY, width, 1, data); if (scaleOrBias) { _mesa_scale_and_bias_depth_uint(ctx, width, data); } - pipe_put_tile_z(pipe, stImage->transfer, 0, row, width, 1, data); + pipe_put_tile_z(stImage->transfer, texDest, 0, row, width, 1, + data); } } else { @@ -801,7 +805,7 @@ fallback_copy_texsubimage(struct gl_context *ctx, /* XXX this usually involves a lot of int/float conversion. * try to avoid that someday. */ - pipe_get_tile_rgba_format(pipe, src_trans, 0, 0, width, height, + pipe_get_tile_rgba_format(src_trans, map, 0, 0, width, height, util_format_linear(strb->texture->format), tempSrc); @@ -828,7 +832,7 @@ fallback_copy_texsubimage(struct gl_context *ctx, } st_texture_image_unmap(st, stImage); - pipe->transfer_destroy(pipe, src_trans); + pipe->transfer_unmap(pipe, src_trans); } diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index 8984dc5f96c..d6dbf8d6cf6 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -230,7 +230,6 @@ st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, { struct st_texture_object *stObj = st_texture_object(stImage->base.TexObject); - struct pipe_context *pipe = st->pipe; GLuint level; DBG("%s \n", __FUNCTION__); @@ -243,14 +242,9 @@ st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, else level = stImage->base.Level; - stImage->transfer = pipe_get_transfer(st->pipe, stImage->pt, level, - stImage->base.Face + zoffset, - usage, x, y, w, h); - - if (stImage->transfer) - return pipe_transfer_map(pipe, stImage->transfer); - else - return NULL; + return pipe_transfer_map(st->pipe, stImage->pt, level, + stImage->base.Face + zoffset, + usage, x, y, w, h, &stImage->transfer); } @@ -263,8 +257,6 @@ st_texture_image_unmap(struct st_context *st, DBG("%s\n", __FUNCTION__); pipe_transfer_unmap(pipe, stImage->transfer); - - pipe->transfer_destroy(pipe, stImage->transfer); stImage->transfer = NULL; } @@ -324,13 +316,11 @@ print_center_pixel(struct pipe_context *pipe, struct pipe_resource *src) region.height = 1; region.depth = 1; - xfer = pipe->get_transfer(pipe, src, 0, PIPE_TRANSFER_READ, ®ion); - map = pipe->transfer_map(pipe, xfer); + map = pipe->transfer_map(pipe, src, 0, PIPE_TRANSFER_READ, ®ion, &xfer); printf("center pixel: %d %d %d %d\n", map[0], map[1], map[2], map[3]); pipe->transfer_unmap(pipe, xfer); - pipe->transfer_destroy(pipe, xfer); } |