ilo: minor cleanups for transfers
Rename some functions and reorder some code.
This commit is contained in:
parent
ca349e0217
commit
46bb33bc21
|
@ -59,7 +59,7 @@ ilo_transfer(struct pipe_transfer *transfer)
|
||||||
* the bo is busy.
|
* the bo is busy.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
transfer_choose_method(struct ilo_context *ilo, struct ilo_transfer *xfer)
|
choose_transfer_method(struct ilo_context *ilo, struct ilo_transfer *xfer)
|
||||||
{
|
{
|
||||||
struct pipe_resource *res = xfer->base.resource;
|
struct pipe_resource *res = xfer->base.resource;
|
||||||
struct ilo_texture *tex;
|
struct ilo_texture *tex;
|
||||||
|
@ -79,12 +79,12 @@ transfer_choose_method(struct ilo_context *ilo, struct ilo_transfer *xfer)
|
||||||
tex = ilo_texture(res);
|
tex = ilo_texture(res);
|
||||||
bo = tex->bo;
|
bo = tex->bo;
|
||||||
|
|
||||||
/* need to convert on-the-fly */
|
if (!(xfer->base.usage & PIPE_TRANSFER_MAP_DIRECTLY)) {
|
||||||
if (tex->bo_format != tex->base.format &&
|
/* need to convert on-the-fly */
|
||||||
!(xfer->base.usage & PIPE_TRANSFER_MAP_DIRECTLY)) {
|
if (tex->bo_format != tex->base.format) {
|
||||||
xfer->method = ILO_TRANSFER_MAP_STAGING_SYS;
|
xfer->method = ILO_TRANSFER_MAP_STAGING_SYS;
|
||||||
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,12 +151,12 @@ transfer_choose_method(struct ilo_context *ilo, struct ilo_transfer *xfer)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tex_unmap_sys_convert(enum pipe_format dst_fmt,
|
tex_staging_sys_convert_write(enum pipe_format dst_fmt,
|
||||||
const struct pipe_transfer *dst_xfer,
|
const struct pipe_transfer *dst_xfer,
|
||||||
void *dst,
|
void *dst,
|
||||||
enum pipe_format src_fmt,
|
enum pipe_format src_fmt,
|
||||||
const struct pipe_transfer *src_xfer,
|
const struct pipe_transfer *src_xfer,
|
||||||
const void *src)
|
const void *src)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -180,9 +180,9 @@ tex_unmap_sys_convert(enum pipe_format dst_fmt,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tex_unmap_sys(struct ilo_context *ilo,
|
tex_staging_sys_unmap(struct ilo_context *ilo,
|
||||||
struct ilo_texture *tex,
|
struct ilo_texture *tex,
|
||||||
struct ilo_transfer *xfer)
|
struct ilo_transfer *xfer)
|
||||||
{
|
{
|
||||||
const void *src = xfer->ptr;
|
const void *src = xfer->ptr;
|
||||||
struct pipe_transfer *dst_xfer;
|
struct pipe_transfer *dst_xfer;
|
||||||
|
@ -201,7 +201,7 @@ tex_unmap_sys(struct ilo_context *ilo,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (likely(tex->bo_format != tex->base.format)) {
|
if (likely(tex->bo_format != tex->base.format)) {
|
||||||
tex_unmap_sys_convert(tex->bo_format, dst_xfer, dst,
|
tex_staging_sys_convert_write(tex->bo_format, dst_xfer, dst,
|
||||||
tex->base.format, &xfer->base, src);
|
tex->base.format, &xfer->base, src);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -216,9 +216,9 @@ tex_unmap_sys(struct ilo_context *ilo,
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
tex_map_sys(struct ilo_context *ilo,
|
tex_staging_sys_map(struct ilo_context *ilo,
|
||||||
struct ilo_texture *tex,
|
struct ilo_texture *tex,
|
||||||
struct ilo_transfer *xfer)
|
struct ilo_transfer *xfer)
|
||||||
{
|
{
|
||||||
const struct pipe_box *box = &xfer->base.box;
|
const struct pipe_box *box = &xfer->base.box;
|
||||||
const size_t stride = util_format_get_stride(tex->base.format, box->width);
|
const size_t stride = util_format_get_stride(tex->base.format, box->width);
|
||||||
|
@ -226,6 +226,15 @@ tex_map_sys(struct ilo_context *ilo,
|
||||||
util_format_get_2d_size(tex->base.format, stride, box->height);
|
util_format_get_2d_size(tex->base.format, stride, box->height);
|
||||||
bool read_back = false;
|
bool read_back = false;
|
||||||
|
|
||||||
|
xfer->staging_sys = MALLOC(size * box->depth);
|
||||||
|
if (!xfer->staging_sys)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
xfer->base.stride = stride;
|
||||||
|
xfer->base.layer_stride = size;
|
||||||
|
xfer->ptr = xfer->staging_sys;
|
||||||
|
|
||||||
|
/* see if we need to read the resource back */
|
||||||
if (xfer->base.usage & PIPE_TRANSFER_READ) {
|
if (xfer->base.usage & PIPE_TRANSFER_READ) {
|
||||||
read_back = true;
|
read_back = true;
|
||||||
}
|
}
|
||||||
|
@ -237,23 +246,15 @@ tex_map_sys(struct ilo_context *ilo,
|
||||||
read_back = true;
|
read_back = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!read_back)
|
||||||
|
return true;
|
||||||
|
|
||||||
/* TODO */
|
/* TODO */
|
||||||
if (read_back)
|
return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
xfer->staging_sys = MALLOC(size * box->depth);
|
|
||||||
if (!xfer->staging_sys)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
xfer->base.stride = stride;
|
|
||||||
xfer->base.layer_stride = size;
|
|
||||||
xfer->ptr = xfer->staging_sys;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tex_unmap_direct(struct ilo_context *ilo,
|
tex_direct_unmap(struct ilo_context *ilo,
|
||||||
struct ilo_texture *tex,
|
struct ilo_texture *tex,
|
||||||
struct ilo_transfer *xfer)
|
struct ilo_transfer *xfer)
|
||||||
{
|
{
|
||||||
|
@ -261,7 +262,7 @@ tex_unmap_direct(struct ilo_context *ilo,
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
tex_map_direct(struct ilo_context *ilo,
|
tex_direct_map(struct ilo_context *ilo,
|
||||||
struct ilo_texture *tex,
|
struct ilo_texture *tex,
|
||||||
struct ilo_transfer *xfer)
|
struct ilo_transfer *xfer)
|
||||||
{
|
{
|
||||||
|
@ -321,16 +322,15 @@ tex_map(struct ilo_context *ilo, struct ilo_transfer *xfer)
|
||||||
struct ilo_texture *tex = ilo_texture(xfer->base.resource);
|
struct ilo_texture *tex = ilo_texture(xfer->base.resource);
|
||||||
bool success;
|
bool success;
|
||||||
|
|
||||||
success = transfer_choose_method(ilo, xfer);
|
if (!choose_transfer_method(ilo, xfer))
|
||||||
if (!success)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (xfer->method) {
|
switch (xfer->method) {
|
||||||
case ILO_TRANSFER_MAP_DIRECT:
|
case ILO_TRANSFER_MAP_DIRECT:
|
||||||
success = tex_map_direct(ilo, tex, xfer);
|
success = tex_direct_map(ilo, tex, xfer);
|
||||||
break;
|
break;
|
||||||
case ILO_TRANSFER_MAP_STAGING_SYS:
|
case ILO_TRANSFER_MAP_STAGING_SYS:
|
||||||
success = tex_map_sys(ilo, tex, xfer);
|
success = tex_staging_sys_map(ilo, tex, xfer);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(!"unknown mapping method");
|
assert(!"unknown mapping method");
|
||||||
|
@ -348,10 +348,10 @@ tex_unmap(struct ilo_context *ilo, struct ilo_transfer *xfer)
|
||||||
|
|
||||||
switch (xfer->method) {
|
switch (xfer->method) {
|
||||||
case ILO_TRANSFER_MAP_DIRECT:
|
case ILO_TRANSFER_MAP_DIRECT:
|
||||||
tex_unmap_direct(ilo, tex, xfer);
|
tex_direct_unmap(ilo, tex, xfer);
|
||||||
break;
|
break;
|
||||||
case ILO_TRANSFER_MAP_STAGING_SYS:
|
case ILO_TRANSFER_MAP_STAGING_SYS:
|
||||||
tex_unmap_sys(ilo, tex, xfer);
|
tex_staging_sys_unmap(ilo, tex, xfer);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(!"unknown mapping method");
|
assert(!"unknown mapping method");
|
||||||
|
@ -365,7 +365,7 @@ buf_map(struct ilo_context *ilo, struct ilo_transfer *xfer)
|
||||||
struct ilo_buffer *buf = ilo_buffer(xfer->base.resource);
|
struct ilo_buffer *buf = ilo_buffer(xfer->base.resource);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!transfer_choose_method(ilo, xfer))
|
if (!choose_transfer_method(ilo, xfer))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
assert(xfer->method == ILO_TRANSFER_MAP_DIRECT);
|
assert(xfer->method == ILO_TRANSFER_MAP_DIRECT);
|
||||||
|
|
Loading…
Reference in New Issue