Commit eb74f977 authored by Marek Olšák's avatar Marek Olšák Committed by Marge Bot
Browse files

gallium: split transfer_(un)map into buffer_(un)map and texture_(un)map



The u_resource_vtbl indirection is going to be removed.

Reviewed-By: Mike Blumenkrantz's avatarMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Acked-by: Pierre-Eric Pelloux-Prayer's avatarPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <!10659>
parent 9effc495
......@@ -1599,10 +1599,10 @@ dd_context_clear_texture(struct pipe_context *_pipe,
*/
static void *
dd_context_transfer_map(struct pipe_context *_pipe,
struct pipe_resource *resource, unsigned level,
unsigned usage, const struct pipe_box *box,
struct pipe_transfer **transfer)
dd_context_buffer_map(struct pipe_context *_pipe,
struct pipe_resource *resource, unsigned level,
unsigned usage, const struct pipe_box *box,
struct pipe_transfer **transfer)
{
struct dd_context *dctx = dd_context(_pipe);
struct pipe_context *pipe = dctx->pipe;
......@@ -1614,7 +1614,41 @@ dd_context_transfer_map(struct pipe_context *_pipe,
dd_before_draw(dctx, record);
}
void *ptr = pipe->transfer_map(pipe, resource, level, usage, box, transfer);
void *ptr = pipe->buffer_map(pipe, resource, level, usage, box, transfer);
if (record) {
record->call.info.transfer_map.transfer_ptr = *transfer;
record->call.info.transfer_map.ptr = ptr;
if (*transfer) {
record->call.info.transfer_map.transfer = **transfer;
record->call.info.transfer_map.transfer.resource = NULL;
pipe_resource_reference(&record->call.info.transfer_map.transfer.resource,
(*transfer)->resource);
} else {
memset(&record->call.info.transfer_map.transfer, 0, sizeof(struct pipe_transfer));
}
dd_after_draw(dctx, record);
}
return ptr;
}
static void *
dd_context_texture_map(struct pipe_context *_pipe,
struct pipe_resource *resource, unsigned level,
unsigned usage, const struct pipe_box *box,
struct pipe_transfer **transfer)
{
struct dd_context *dctx = dd_context(_pipe);
struct pipe_context *pipe = dctx->pipe;
struct dd_draw_record *record =
dd_screen(dctx->base.screen)->transfers ? dd_create_record(dctx) : NULL;
if (record) {
record->call.type = CALL_TRANSFER_MAP;
dd_before_draw(dctx, record);
}
void *ptr = pipe->texture_map(pipe, resource, level, usage, box, transfer);
if (record) {
record->call.info.transfer_map.transfer_ptr = *transfer;
record->call.info.transfer_map.ptr = ptr;
......@@ -1660,7 +1694,32 @@ dd_context_transfer_flush_region(struct pipe_context *_pipe,
}
static void
dd_context_transfer_unmap(struct pipe_context *_pipe,
dd_context_buffer_unmap(struct pipe_context *_pipe,
struct pipe_transfer *transfer)
{
struct dd_context *dctx = dd_context(_pipe);
struct pipe_context *pipe = dctx->pipe;
struct dd_draw_record *record =
dd_screen(dctx->base.screen)->transfers ? dd_create_record(dctx) : NULL;
if (record) {
record->call.type = CALL_TRANSFER_UNMAP;
record->call.info.transfer_unmap.transfer_ptr = transfer;
record->call.info.transfer_unmap.transfer = *transfer;
record->call.info.transfer_unmap.transfer.resource = NULL;
pipe_resource_reference(
&record->call.info.transfer_unmap.transfer.resource,
transfer->resource);
dd_before_draw(dctx, record);
}
pipe->buffer_unmap(pipe, transfer);
if (record)
dd_after_draw(dctx, record);
}
static void
dd_context_texture_unmap(struct pipe_context *_pipe,
struct pipe_transfer *transfer)
{
struct dd_context *dctx = dd_context(_pipe);
......@@ -1679,7 +1738,7 @@ dd_context_transfer_unmap(struct pipe_context *_pipe,
dd_before_draw(dctx, record);
}
pipe->transfer_unmap(pipe, transfer);
pipe->texture_unmap(pipe, transfer);
if (record)
dd_after_draw(dctx, record);
}
......@@ -1759,9 +1818,11 @@ dd_init_draw_functions(struct dd_context *dctx)
CTX_INIT(flush_resource);
CTX_INIT(generate_mipmap);
CTX_INIT(get_query_result_resource);
CTX_INIT(transfer_map);
CTX_INIT(buffer_map);
CTX_INIT(texture_map);
CTX_INIT(transfer_flush_region);
CTX_INIT(transfer_unmap);
CTX_INIT(buffer_unmap);
CTX_INIT(texture_unmap);
CTX_INIT(buffer_subdata);
CTX_INIT(texture_subdata);
}
......@@ -381,9 +381,11 @@ static struct pipe_context *noop_create_context(struct pipe_screen *screen,
ctx->end_query = noop_end_query;
ctx->get_query_result = noop_get_query_result;
ctx->set_active_query_state = noop_set_active_query_state;
ctx->transfer_map = noop_transfer_map;
ctx->buffer_map = noop_transfer_map;
ctx->texture_map = noop_transfer_map;
ctx->transfer_flush_region = noop_transfer_flush_region;
ctx->transfer_unmap = noop_transfer_unmap;
ctx->buffer_unmap = noop_transfer_unmap;
ctx->texture_unmap = noop_transfer_unmap;
ctx->buffer_subdata = noop_buffer_subdata;
ctx->texture_subdata = noop_texture_subdata;
ctx->invalidate_resource = noop_invalidate_resource;
......
......@@ -1107,7 +1107,7 @@ rbug_context_surface_destroy(struct pipe_context *_pipe,
static void *
rbug_context_transfer_map(struct pipe_context *_context,
rbug_context_buffer_map(struct pipe_context *_context,
struct pipe_resource *_resource,
unsigned level,
unsigned usage,
......@@ -1122,7 +1122,34 @@ rbug_context_transfer_map(struct pipe_context *_context,
void *map;
mtx_lock(&rb_pipe->call_mutex);
map = context->transfer_map(context,
map = context->buffer_map(context,
resource,
level,
usage,
box, &result);
mtx_unlock(&rb_pipe->call_mutex);
*transfer = rbug_transfer_create(rb_pipe, rb_resource, result);
return *transfer ? map : NULL;
}
static void *
rbug_context_texture_map(struct pipe_context *_context,
struct pipe_resource *_resource,
unsigned level,
unsigned usage,
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;
mtx_lock(&rb_pipe->call_mutex);
map = context->texture_map(context,
resource,
level,
usage,
......@@ -1152,7 +1179,24 @@ rbug_context_transfer_flush_region(struct pipe_context *_context,
static void
rbug_context_transfer_unmap(struct pipe_context *_context,
rbug_context_buffer_unmap(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;
mtx_lock(&rb_pipe->call_mutex);
context->buffer_unmap(context,
transfer);
rbug_transfer_destroy(rb_pipe,
rb_transfer);
mtx_unlock(&rb_pipe->call_mutex);
}
static void
rbug_context_texture_unmap(struct pipe_context *_context,
struct pipe_transfer *_transfer)
{
struct rbug_context *rb_pipe = rbug_context(_context);
......@@ -1161,7 +1205,7 @@ rbug_context_transfer_unmap(struct pipe_context *_context,
struct pipe_transfer *transfer = rb_transfer->transfer;
mtx_lock(&rb_pipe->call_mutex);
context->transfer_unmap(context,
context->texture_unmap(context,
transfer);
rbug_transfer_destroy(rb_pipe,
rb_transfer);
......@@ -1308,8 +1352,10 @@ 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.transfer_map = rbug_context_transfer_map;
rb_pipe->base.transfer_unmap = rbug_context_transfer_unmap;
rb_pipe->base.buffer_map = rbug_context_buffer_map;
rb_pipe->base.buffer_unmap = rbug_context_buffer_unmap;
rb_pipe->base.texture_map = rbug_context_texture_map;
rb_pipe->base.texture_unmap = rbug_context_texture_unmap;
rb_pipe->base.transfer_flush_region = rbug_context_transfer_flush_region;
rb_pipe->base.buffer_subdata = rbug_context_buffer_subdata;
rb_pipe->base.texture_subdata = rbug_context_texture_subdata;
......
......@@ -267,7 +267,7 @@ rbug_texture_read(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_
}
tex = tr_tex->resource;
map = pipe_transfer_map(context, tex,
map = pipe_texture_map(context, tex,
gptr->level, gptr->face + gptr->zslice,
PIPE_MAP_READ,
gptr->x, gptr->y, gptr->w, gptr->h, &t);
......@@ -283,7 +283,7 @@ rbug_texture_read(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_
t->stride,
NULL);
context->transfer_unmap(context, t);
context->texture_unmap(context, t);
mtx_unlock(&rb_screen->list_mutex);
......
......@@ -186,7 +186,10 @@ rbug_transfer_create(struct rbug_context *rb_context,
return &rb_transfer->base;
error:
rb_context->pipe->transfer_unmap(rb_context->pipe, transfer);
if (rb_resource->base.target == PIPE_BUFFER)
rb_context->pipe->buffer_unmap(rb_context->pipe, transfer);
else
rb_context->pipe->texture_unmap(rb_context->pipe, transfer);
return NULL;
}
......
......@@ -1572,7 +1572,10 @@ trace_context_transfer_map(struct pipe_context *_context,
* to texture/buffer_subdata and ignore read transfers.
*/
map = context->transfer_map(context, resource, level, usage, box, &result);
if (resource->target == PIPE_BUFFER)
map = context->buffer_map(context, resource, level, usage, box, &result);
else
map = context->texture_map(context, resource, level, usage, box, &result);
if (!map)
return NULL;
......@@ -1672,7 +1675,10 @@ trace_context_transfer_unmap(struct pipe_context *_context,
tr_trans->map = NULL;
}
context->transfer_unmap(context, transfer);
if (transfer->resource->target == PIPE_BUFFER)
context->buffer_unmap(context, transfer);
else
context->texture_unmap(context, transfer);
trace_transfer_destroy(tr_ctx, tr_trans);
}
......@@ -2160,8 +2166,8 @@ trace_context_create(struct trace_screen *tr_scr,
TR_CTX_INIT(delete_image_handle);
TR_CTX_INIT(make_image_handle_resident);
TR_CTX_INIT(transfer_map);
TR_CTX_INIT(transfer_unmap);
tr_ctx->base.buffer_map = tr_ctx->base.texture_map = trace_context_transfer_map;
tr_ctx->base.buffer_unmap = tr_ctx->base.texture_unmap = trace_context_transfer_unmap;
TR_CTX_INIT(transfer_flush_region);
TR_CTX_INIT(buffer_subdata);
TR_CTX_INIT(texture_subdata);
......
......@@ -101,7 +101,10 @@ trace_transfer_create(struct trace_context *tr_ctx,
return &tr_trans->base.b;
error:
tr_ctx->pipe->transfer_unmap(tr_ctx->pipe, transfer);
if (res->target == PIPE_BUFFER)
tr_ctx->pipe->buffer_unmap(tr_ctx->pipe, transfer);
else
tr_ctx->pipe->texture_unmap(tr_ctx->pipe, transfer);
return NULL;
}
......
......@@ -417,8 +417,8 @@ util_font_create_fixed_8x13(struct pipe_context *pipe,
return FALSE;
}
map = pipe_transfer_map(pipe, tex, 0, 0, PIPE_MAP_WRITE, 0, 0,
tex->width0, tex->height0, &transfer);
map = pipe_texture_map(pipe, tex, 0, 0, PIPE_MAP_WRITE, 0, 0,
tex->width0, tex->height0, &transfer);
if (!map) {
pipe_resource_reference(&tex, NULL);
return FALSE;
......@@ -432,7 +432,7 @@ util_font_create_fixed_8x13(struct pipe_context *pipe,
transfer->stride, i);
}
pipe_transfer_unmap(pipe, transfer);
pipe_texture_unmap(pipe, transfer);
pipe_resource_reference(&out_font->texture, NULL);
out_font->texture = tex;
......
......@@ -113,10 +113,10 @@ debug_dump_surface(struct pipe_context *pipe,
*/
texture = surface->texture;
data = pipe_transfer_map(pipe, texture, surface->u.tex.level,
surface->u.tex.first_layer,
PIPE_MAP_READ,
0, 0, surface->width, surface->height, &transfer);
data = pipe_texture_map(pipe, texture, surface->u.tex.level,
surface->u.tex.first_layer,
PIPE_MAP_READ,
0, 0, surface->width, surface->height, &transfer);
if (!data)
return;
......@@ -128,7 +128,7 @@ debug_dump_surface(struct pipe_context *pipe,
transfer->stride,
data);
pipe->transfer_unmap(pipe, transfer);
pipe->texture_unmap(pipe, transfer);
}
......@@ -192,13 +192,13 @@ debug_dump_surface_bmp(struct pipe_context *pipe,
struct pipe_resource *texture = surface->texture;
void *ptr;
ptr = pipe_transfer_map(pipe, texture, surface->u.tex.level,
surface->u.tex.first_layer, PIPE_MAP_READ,
0, 0, surface->width, surface->height, &transfer);
ptr = pipe_texture_map(pipe, texture, surface->u.tex.level,
surface->u.tex.first_layer, PIPE_MAP_READ,
0, 0, surface->width, surface->height, &transfer);
debug_dump_transfer_bmp(pipe, filename, transfer, ptr);
pipe->transfer_unmap(pipe, transfer);
pipe->texture_unmap(pipe, transfer);
}
void
......
......@@ -355,7 +355,7 @@ pipe_buffer_map_range(struct pipe_context *pipe,
u_box_1d(offset, length, &box);
map = pipe->transfer_map(pipe, buffer, 0, access, &box, transfer);
map = pipe->buffer_map(pipe, buffer, 0, access, &box, transfer);
if (!map) {
return NULL;
}
......@@ -384,7 +384,7 @@ static inline void
pipe_buffer_unmap(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
pipe->transfer_unmap(pipe, transfer);
pipe->buffer_unmap(pipe, transfer);
}
static inline void
......@@ -504,21 +504,18 @@ pipe_buffer_read(struct pipe_context *pipe,
* \param access bitmask of PIPE_MAP_x flags
*/
static inline void *
pipe_transfer_map(struct pipe_context *context,
struct pipe_resource *resource,
unsigned level, unsigned layer,
unsigned access,
unsigned x, unsigned y,
unsigned w, unsigned h,
struct pipe_transfer **transfer)
pipe_texture_map(struct pipe_context *context,
struct pipe_resource *resource,
unsigned level, unsigned layer,
unsigned access,
unsigned x, unsigned y,
unsigned w, unsigned h,
struct pipe_transfer **transfer)
{
struct pipe_box box;
u_box_2d_zslice(x, y, layer, w, h, &box);
return context->transfer_map(context,
resource,
level,
access,
&box, transfer);
return context->texture_map(context, resource, level, access,
&box, transfer);
}
......@@ -527,28 +524,25 @@ pipe_transfer_map(struct pipe_context *context,
* \param access bitmask of PIPE_MAP_x flags
*/
static inline void *
pipe_transfer_map_3d(struct pipe_context *context,
struct pipe_resource *resource,
unsigned level,
unsigned access,
unsigned x, unsigned y, unsigned z,
unsigned w, unsigned h, unsigned d,
struct pipe_transfer **transfer)
pipe_texture_map_3d(struct pipe_context *context,
struct pipe_resource *resource,
unsigned level,
unsigned access,
unsigned x, unsigned y, unsigned z,
unsigned w, unsigned h, unsigned d,
struct pipe_transfer **transfer)
{
struct pipe_box box;
u_box_3d(x, y, z, w, h, d, &box);
return context->transfer_map(context,
resource,
level,
access,
&box, transfer);
return context->texture_map(context, resource, level, access,
&box, transfer);
}
static inline void
pipe_transfer_unmap(struct pipe_context *context,
struct pipe_transfer *transfer)
pipe_texture_unmap(struct pipe_context *context,
struct pipe_transfer *transfer)
{
context->transfer_unmap(context, transfer);
context->texture_unmap(context, transfer);
}
static inline void
......
......@@ -69,7 +69,7 @@ util_pstipple_update_stipple_texture(struct pipe_context *pipe,
int i, j;
/* map texture memory */
data = pipe_transfer_map(pipe, tex, 0, 0,
data = pipe_texture_map(pipe, tex, 0, 0,
PIPE_MAP_WRITE, 0, 0, 32, 32, &transfer);
/*
......@@ -92,7 +92,7 @@ util_pstipple_update_stipple_texture(struct pipe_context *pipe,
}
/* unmap */
pipe->transfer_unmap(pipe, transfer);
pipe->texture_unmap(pipe, transfer);
}
......
......@@ -288,32 +288,59 @@ util_resource_copy_region(struct pipe_context *pipe,
assert((src_box.width / src_bw) * (src_box.height / src_bh) * src_bs ==
(dst_box.width / dst_bw) * (dst_box.height / dst_bh) * dst_bs);
src_map = pipe->transfer_map(pipe,
src,
src_level,
PIPE_MAP_READ,
&src_box, &src_trans);
assert(src_map);
if (!src_map) {
goto no_src_map;
}
if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) {
src_map = pipe->buffer_map(pipe,
src,
src_level,
PIPE_MAP_READ,
&src_box, &src_trans);
assert(src_map);
if (!src_map) {
goto no_src_map_buf;
}
dst_map = pipe->transfer_map(pipe,
dst,
dst_level,
PIPE_MAP_WRITE |
PIPE_MAP_DISCARD_RANGE, &dst_box,
&dst_trans);
assert(dst_map);
if (!dst_map) {
goto no_dst_map;
}
dst_map = pipe->buffer_map(pipe,
dst,
dst_level,
PIPE_MAP_WRITE |
PIPE_MAP_DISCARD_RANGE, &dst_box,
&dst_trans);
assert(dst_map);
if (!dst_map) {
goto no_dst_map_buf;
}
if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) {
assert(src_box.height == 1);
assert(src_box.depth == 1);
memcpy(dst_map, src_map, src_box.width);
pipe->buffer_unmap(pipe, dst_trans);
no_dst_map_buf:
pipe->buffer_unmap(pipe, src_trans);
no_src_map_buf:
;
} else {
src_map = pipe->texture_map(pipe,
src,
src_level,
PIPE_MAP_READ,
&src_box, &src_trans);
assert(src_map);
if (!src_map) {
goto no_src_map;
}
dst_map = pipe->texture_map(pipe,
dst,
dst_level,
PIPE_MAP_WRITE |
PIPE_MAP_DISCARD_RANGE, &dst_box,
&dst_trans);
assert(dst_map);
if (!dst_map) {
goto no_dst_map;
}
util_copy_box(dst_map,
src_format,
dst_trans->stride, dst_trans->layer_stride,
......@@ -322,13 +349,13 @@ util_resource_copy_region(struct pipe_context *pipe,
src_map,
src_trans->stride, src_trans->layer_stride,
0, 0, 0);
}
pipe->transfer_unmap(pipe, dst_trans);
no_dst_map:
pipe->transfer_unmap(pipe, src_trans);
no_src_map:
;
pipe->texture_unmap(pipe, dst_trans);
no_dst_map:
pipe->texture_unmap(pipe, src_trans);
no_src_map:
;
}
}
static void
......@@ -361,7 +388,7 @@ util_clear_color_texture(struct pipe_context *pipe,
struct pipe_transfer *dst_trans;
ubyte *dst_map;
dst_map = pipe_transfer_map_3d(pipe,
dst_map = pipe_texture_map_3d(pipe,
texture,
level,
PIPE_MAP_WRITE,
......@@ -375,7 +402,7 @@ util_clear_color_texture(struct pipe_context *pipe,
util_clear_color_texture_helper(dst_trans, dst_map, format, color,
width, height, depth);
}
pipe->transfer_unmap(pipe, dst_trans);
pipe->texture_unmap(pipe, dst_trans);
}
......@@ -413,7 +440,7 @@ util_clear_render_target(struct pipe_context *pipe,
unsigned pixstride = util_format_get_blocksize(dst->format);
dx = (dst->u.buf.first_element + dstx) * pixstride;
w = width * pixstride;
dst_map = pipe_transfer_map(pipe,
dst_map = pipe_texture_map(pipe,