mesa/st: Add and use st_texture_image_insert_transfer

Split out the transfer array reallocation and insertion functionality from
st_texture_image_map.

Acked-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18257>
This commit is contained in:
Nanley Chery
2022-08-22 09:08:13 -07:00
committed by Marge Bot
parent 9fe525e37b
commit 5f1967e92b
2 changed files with 30 additions and 14 deletions

View File

@@ -238,6 +238,26 @@ st_texture_match_image(struct st_context *st,
return GL_TRUE;
}
void
st_texture_image_insert_transfer(struct gl_texture_image *stImage,
unsigned index,
struct pipe_transfer *transfer)
{
/* Enlarge the transfer array if it's not large enough. */
if (index >= stImage->num_transfers) {
unsigned new_size = index + 1;
stImage->transfer = realloc(stImage->transfer,
new_size * sizeof(struct st_texture_image_transfer));
memset(&stImage->transfer[stImage->num_transfers], 0,
(new_size - stImage->num_transfers) *
sizeof(struct st_texture_image_transfer));
stImage->num_transfers = new_size;
}
assert(!stImage->transfer[index].transfer);
stImage->transfer[index].transfer = transfer;
}
/**
* Map a texture image and return the address for a particular 2D face/slice/
@@ -279,22 +299,10 @@ st_texture_image_map(struct st_context *st, struct gl_texture_image *stImage,
map = pipe_texture_map_3d(st->pipe, stImage->pt, level, usage,
x, y, z, w, h, d, transfer);
if (map) {
/* Enlarge the transfer array if it's not large enough. */
if (z >= stImage->num_transfers) {
unsigned new_size = z + 1;
stImage->transfer = realloc(stImage->transfer,
new_size * sizeof(struct st_texture_image_transfer));
memset(&stImage->transfer[stImage->num_transfers], 0,
(new_size - stImage->num_transfers) *
sizeof(struct st_texture_image_transfer));
stImage->num_transfers = new_size;
}
if (map)
st_texture_image_insert_transfer(stImage, z, *transfer);
assert(!stImage->transfer[z].transfer);
stImage->transfer[z].transfer = *transfer;
}
return map;
}

View File

@@ -178,6 +178,14 @@ st_texture_match_image(struct st_context *st,
const struct pipe_resource *pt,
const struct gl_texture_image *image);
/* Insert a transfer pointer into the image's transfer array at the specified
* index. The array is reallocated if necessary.
*/
void
st_texture_image_insert_transfer(struct gl_texture_image *stImage,
unsigned index,
struct pipe_transfer *transfer);
/* Return a pointer to an image within a texture. Return image stride as
* well.
*/