lavapipe: move copy_depth_box to lvp_image.c

no functional changes

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37589>
This commit is contained in:
Mike Blumenkrantz
2025-07-29 13:07:42 -04:00
committed by Marge Bot
parent 141a225ca1
commit daa276b605
3 changed files with 132 additions and 120 deletions
+3 -120
View File
@@ -42,7 +42,6 @@
#include "util/u_memory.h"
#include "util/u_prim.h"
#include "util/u_prim_restart.h"
#include "util/format/u_format_zs.h"
#include "util/ptralloc.h"
#include "tgsi/tgsi_from_mesa.h"
@@ -2069,122 +2068,6 @@ static void handle_set_stencil_reference(struct vk_cmd_queue_entry *cmd,
state->stencil_ref_dirty = true;
}
static void
copy_depth_rect(uint8_t * dst,
enum pipe_format dst_format,
unsigned dst_stride,
unsigned dst_x,
unsigned dst_y,
unsigned width,
unsigned height,
const uint8_t * src,
enum pipe_format src_format,
int src_stride,
unsigned src_x,
unsigned src_y)
{
int src_stride_pos = src_stride < 0 ? -src_stride : src_stride;
int src_blocksize = util_format_get_blocksize(src_format);
int src_blockwidth = util_format_get_blockwidth(src_format);
int src_blockheight = util_format_get_blockheight(src_format);
int dst_blocksize = util_format_get_blocksize(dst_format);
int dst_blockwidth = util_format_get_blockwidth(dst_format);
int dst_blockheight = util_format_get_blockheight(dst_format);
assert(src_blocksize > 0);
assert(src_blockwidth > 0);
assert(src_blockheight > 0);
dst_x /= dst_blockwidth;
dst_y /= dst_blockheight;
width = (width + src_blockwidth - 1)/src_blockwidth;
height = (height + src_blockheight - 1)/src_blockheight;
src_x /= src_blockwidth;
src_y /= src_blockheight;
dst += dst_x * dst_blocksize;
src += src_x * src_blocksize;
dst += dst_y * dst_stride;
src += src_y * src_stride_pos;
if (dst_format == PIPE_FORMAT_S8_UINT) {
if (src_format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
util_format_z32_float_s8x24_uint_unpack_s_8uint(dst, dst_stride,
src, src_stride,
width, height);
} else if (src_format == PIPE_FORMAT_Z24_UNORM_S8_UINT) {
util_format_z24_unorm_s8_uint_unpack_s_8uint(dst, dst_stride,
src, src_stride,
width, height);
} else {
abort();
}
} else if (dst_format == PIPE_FORMAT_Z24X8_UNORM) {
util_format_z24_unorm_s8_uint_unpack_z24(dst, dst_stride,
src, src_stride,
width, height);
} else if (dst_format == PIPE_FORMAT_Z32_FLOAT) {
if (src_format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
util_format_z32_float_s8x24_uint_unpack_z_float((float *)dst, dst_stride,
src, src_stride,
width, height);
} else {
abort();
}
} else if (dst_format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
if (src_format == PIPE_FORMAT_Z32_FLOAT)
util_format_z32_float_s8x24_uint_pack_z_float(dst, dst_stride,
(float *)src, src_stride,
width, height);
else if (src_format == PIPE_FORMAT_S8_UINT)
util_format_z32_float_s8x24_uint_pack_s_8uint(dst, dst_stride,
src, src_stride,
width, height);
else
abort();
} else if (dst_format == PIPE_FORMAT_Z24_UNORM_S8_UINT) {
if (src_format == PIPE_FORMAT_S8_UINT)
util_format_z24_unorm_s8_uint_pack_s_8uint(dst, dst_stride,
src, src_stride,
width, height);
else if (src_format == PIPE_FORMAT_Z24X8_UNORM)
util_format_z24_unorm_s8_uint_pack_z24(dst, dst_stride,
src, src_stride,
width, height);
else
abort();
}
}
static void
copy_depth_box(uint8_t *dst,
enum pipe_format dst_format,
unsigned dst_stride, uint64_t dst_slice_stride,
unsigned dst_x, unsigned dst_y, unsigned dst_z,
unsigned width, unsigned height, unsigned depth,
const uint8_t * src,
enum pipe_format src_format,
int src_stride, uint64_t src_slice_stride,
unsigned src_x, unsigned src_y, unsigned src_z)
{
dst += dst_z * dst_slice_stride;
src += src_z * src_slice_stride;
for (unsigned z = 0; z < depth; ++z) {
copy_depth_rect(dst,
dst_format,
dst_stride,
dst_x, dst_y,
width, height,
src,
src_format,
src_stride,
src_x, src_y);
dst += dst_slice_stride;
src += src_slice_stride;
}
}
static unsigned
subresource_layercount(const struct lvp_image *image, const VkImageSubresourceLayers *sub)
{
@@ -2247,7 +2130,7 @@ static void handle_copy_image_to_buffer2(struct vk_cmd_queue_entry *cmd,
const struct vk_image_buffer_layout buffer_layout =
vk_image_buffer_copy_layout(&src_image->vk, &copycmd->pRegions[i]);
if (src_format != dst_format) {
copy_depth_box(dst_data, dst_format,
lvp_image_copy_depth_box(dst_data, dst_format,
buffer_layout.row_stride_B,
buffer_layout.image_stride_B,
0, 0, 0,
@@ -2325,7 +2208,7 @@ static void handle_copy_buffer_to_image(struct vk_cmd_queue_entry *cmd,
const struct vk_image_buffer_layout buffer_layout =
vk_image_buffer_copy_layout(&dst_image->vk, &copycmd->pRegions[i]);
if (src_format != dst_format) {
copy_depth_box(dst_data, dst_format,
lvp_image_copy_depth_box(dst_data, dst_format,
dst_t->stride, dst_t->layer_stride,
0, 0, 0,
region->imageExtent.width,
@@ -2441,7 +2324,7 @@ static void handle_copy_image(struct vk_cmd_queue_entry *cmd,
PIPE_MAP_WRITE,
&dst_box,
&dst_t);
copy_depth_box(dst_data, dst_format,
lvp_image_copy_depth_box(dst_data, dst_format,
dst_t->stride, dst_t->layer_stride,
0, 0, 0,
region->extent.width,
+118
View File
@@ -26,6 +26,7 @@
#include "util/u_inlines.h"
#include "util/u_surface.h"
#include "pipe/p_state.h"
#include "util/format/u_format_zs.h"
#include "frontend/winsys_handle.h"
#include "vk_android.h"
@@ -1022,3 +1023,120 @@ lvp_image_bind_sparse(struct lvp_device *device,
return VK_SUCCESS;
}
static void
copy_depth_rect(uint8_t * dst,
enum pipe_format dst_format,
unsigned dst_stride,
unsigned dst_x,
unsigned dst_y,
unsigned width,
unsigned height,
const uint8_t * src,
enum pipe_format src_format,
int src_stride,
unsigned src_x,
unsigned src_y)
{
int src_stride_pos = src_stride < 0 ? -src_stride : src_stride;
int src_blocksize = util_format_get_blocksize(src_format);
int src_blockwidth = util_format_get_blockwidth(src_format);
int src_blockheight = util_format_get_blockheight(src_format);
int dst_blocksize = util_format_get_blocksize(dst_format);
int dst_blockwidth = util_format_get_blockwidth(dst_format);
int dst_blockheight = util_format_get_blockheight(dst_format);
assert(src_blocksize > 0);
assert(src_blockwidth > 0);
assert(src_blockheight > 0);
dst_x /= dst_blockwidth;
dst_y /= dst_blockheight;
width = (width + src_blockwidth - 1)/src_blockwidth;
height = (height + src_blockheight - 1)/src_blockheight;
src_x /= src_blockwidth;
src_y /= src_blockheight;
dst += dst_x * dst_blocksize;
src += src_x * src_blocksize;
dst += dst_y * dst_stride;
src += src_y * src_stride_pos;
if (dst_format == PIPE_FORMAT_S8_UINT) {
if (src_format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
util_format_z32_float_s8x24_uint_unpack_s_8uint(dst, dst_stride,
src, src_stride,
width, height);
} else if (src_format == PIPE_FORMAT_Z24_UNORM_S8_UINT) {
util_format_z24_unorm_s8_uint_unpack_s_8uint(dst, dst_stride,
src, src_stride,
width, height);
} else {
abort();
}
} else if (dst_format == PIPE_FORMAT_Z24X8_UNORM) {
util_format_z24_unorm_s8_uint_unpack_z24(dst, dst_stride,
src, src_stride,
width, height);
} else if (dst_format == PIPE_FORMAT_Z32_FLOAT) {
if (src_format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
util_format_z32_float_s8x24_uint_unpack_z_float((float *)dst, dst_stride,
src, src_stride,
width, height);
} else {
abort();
}
} else if (dst_format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
if (src_format == PIPE_FORMAT_Z32_FLOAT)
util_format_z32_float_s8x24_uint_pack_z_float(dst, dst_stride,
(float *)src, src_stride,
width, height);
else if (src_format == PIPE_FORMAT_S8_UINT)
util_format_z32_float_s8x24_uint_pack_s_8uint(dst, dst_stride,
src, src_stride,
width, height);
else
abort();
} else if (dst_format == PIPE_FORMAT_Z24_UNORM_S8_UINT) {
if (src_format == PIPE_FORMAT_S8_UINT)
util_format_z24_unorm_s8_uint_pack_s_8uint(dst, dst_stride,
src, src_stride,
width, height);
else if (src_format == PIPE_FORMAT_Z24X8_UNORM)
util_format_z24_unorm_s8_uint_pack_z24(dst, dst_stride,
src, src_stride,
width, height);
else
abort();
}
}
void
lvp_image_copy_depth_box(uint8_t *dst,
enum pipe_format dst_format,
unsigned dst_stride, uint64_t dst_slice_stride,
unsigned dst_x, unsigned dst_y, unsigned dst_z,
unsigned width, unsigned height, unsigned depth,
const uint8_t * src,
enum pipe_format src_format,
int src_stride, uint64_t src_slice_stride,
unsigned src_x, unsigned src_y, unsigned src_z)
{
dst += dst_z * dst_slice_stride;
src += src_z * src_slice_stride;
for (unsigned z = 0; z < depth; ++z) {
copy_depth_rect(dst,
dst_format,
dst_stride,
dst_x, dst_y,
width, height,
src,
src_format,
src_stride,
src_x, src_y);
dst += dst_slice_stride;
src += src_slice_stride;
}
}
@@ -848,6 +848,17 @@ enum {
#define LVP_CMD_SAVE_STATE ((enum vk_cmd_type)LVP_CMD_SAVE_STATE)
#define LVP_CMD_RESTORE_STATE ((enum vk_cmd_type)LVP_CMD_RESTORE_STATE)
void
lvp_image_copy_depth_box(uint8_t *dst,
enum pipe_format dst_format,
unsigned dst_stride, uint64_t dst_slice_stride,
unsigned dst_x, unsigned dst_y, unsigned dst_z,
unsigned width, unsigned height, unsigned depth,
const uint8_t * src,
enum pipe_format src_format,
int src_stride, uint64_t src_slice_stride,
unsigned src_x, unsigned src_y, unsigned src_z);
#ifdef __cplusplus
}
#endif