panfrost: Simplify how image_layout_init is called
Rather than using it as a catch-all initialize, use it to fill in derived from fields from a partially initialized image_layout. This is easier to understand and, more importantly, easier to unit test. Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15991>
This commit is contained in:

committed by
Marge Bot

parent
c45ed7e576
commit
52f8f7d6c9
@@ -89,12 +89,20 @@ panfrost_resource_from_handle(struct pipe_screen *pscreen,
|
||||
.line_stride = whandle->stride,
|
||||
};
|
||||
|
||||
bool valid = pan_image_layout_init(&rsc->image.layout, mod,
|
||||
templat->format, dim,
|
||||
prsc->width0, prsc->height0,
|
||||
prsc->depth0, prsc->array_size,
|
||||
MAX2(prsc->nr_samples, 1), 1,
|
||||
crc_mode, &explicit_layout);
|
||||
rsc->image.layout = (struct pan_image_layout) {
|
||||
.modifier = mod,
|
||||
.format = templat->format,
|
||||
.dim = dim,
|
||||
.width = prsc->width0,
|
||||
.height = prsc->height0,
|
||||
.depth = prsc->depth0,
|
||||
.array_size = prsc->array_size,
|
||||
.nr_samples = MAX2(prsc->nr_samples, 1),
|
||||
.nr_slices = 1,
|
||||
.crc_mode = crc_mode
|
||||
};
|
||||
|
||||
bool valid = pan_image_layout_init(&rsc->image.layout, &explicit_layout);
|
||||
|
||||
if (!valid) {
|
||||
FREE(rsc);
|
||||
@@ -501,16 +509,20 @@ panfrost_resource_setup(struct panfrost_device *dev,
|
||||
if (fmt == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT)
|
||||
fmt = PIPE_FORMAT_Z32_FLOAT;
|
||||
|
||||
ASSERTED bool valid =
|
||||
pan_image_layout_init(&pres->image.layout,
|
||||
chosen_mod, fmt, dim,
|
||||
pres->base.width0,
|
||||
pres->base.height0,
|
||||
pres->base.depth0,
|
||||
pres->base.array_size,
|
||||
MAX2(pres->base.nr_samples, 1),
|
||||
pres->base.last_level + 1,
|
||||
crc_mode, NULL);
|
||||
pres->image.layout = (struct pan_image_layout) {
|
||||
.modifier = chosen_mod,
|
||||
.format = fmt,
|
||||
.dim = dim,
|
||||
.width = pres->base.width0,
|
||||
.height = pres->base.height0,
|
||||
.depth = pres->base.depth0,
|
||||
.array_size = pres->base.array_size,
|
||||
.nr_samples = MAX2(pres->base.nr_samples, 1),
|
||||
.nr_slices = pres->base.last_level + 1,
|
||||
.crc_mode = crc_mode
|
||||
};
|
||||
|
||||
ASSERTED bool valid = pan_image_layout_init(&pres->image.layout, NULL);
|
||||
assert(valid);
|
||||
}
|
||||
|
||||
|
@@ -179,44 +179,27 @@ panfrost_texture_offset(const struct pan_image_layout *layout,
|
||||
|
||||
bool
|
||||
pan_image_layout_init(struct pan_image_layout *layout,
|
||||
uint64_t modifier,
|
||||
enum pipe_format format,
|
||||
enum mali_texture_dimension dim,
|
||||
unsigned width, unsigned height, unsigned depth,
|
||||
unsigned array_size, unsigned nr_samples,
|
||||
unsigned nr_slices, enum pan_image_crc_mode crc_mode,
|
||||
const struct pan_image_explicit_layout *explicit_layout)
|
||||
{
|
||||
/* Explicit stride only work with non-mipmap, non-array; single-sample
|
||||
* 2D image, and in-band CRC can't be used.
|
||||
*/
|
||||
if (explicit_layout &&
|
||||
(depth > 1 || nr_samples > 1 || array_size > 1 ||
|
||||
dim != MALI_TEXTURE_DIMENSION_2D || nr_slices > 1 ||
|
||||
crc_mode == PAN_IMAGE_CRC_INBAND))
|
||||
(layout->depth > 1 || layout->nr_samples > 1 ||
|
||||
layout->array_size > 1 || layout->dim != MALI_TEXTURE_DIMENSION_2D ||
|
||||
layout->nr_slices > 1 || layout->crc_mode == PAN_IMAGE_CRC_INBAND))
|
||||
return false;
|
||||
|
||||
/* Mandate 64 byte alignement */
|
||||
if (explicit_layout && (explicit_layout->offset & 63))
|
||||
return false;
|
||||
|
||||
layout->crc_mode = crc_mode;
|
||||
layout->modifier = modifier;
|
||||
layout->format = format;
|
||||
layout->dim = dim;
|
||||
layout->width = width;
|
||||
layout->height = height;
|
||||
layout->depth = depth;
|
||||
layout->array_size = array_size;
|
||||
layout->nr_samples = nr_samples;
|
||||
layout->nr_slices = nr_slices;
|
||||
|
||||
unsigned bytes_per_pixel = util_format_get_blocksize(format);
|
||||
unsigned bytes_per_pixel = util_format_get_blocksize(layout->format);
|
||||
|
||||
/* MSAA is implemented as a 3D texture with z corresponding to the
|
||||
* sample #, horrifyingly enough */
|
||||
|
||||
assert(depth == 1 || nr_samples == 1);
|
||||
assert(layout->depth == 1 || layout->nr_samples == 1);
|
||||
|
||||
bool afbc = drm_is_afbc(layout->modifier);
|
||||
bool linear = layout->modifier == DRM_FORMAT_MOD_LINEAR;
|
||||
@@ -225,13 +208,17 @@ pan_image_layout_init(struct pan_image_layout *layout,
|
||||
unsigned oob_crc_offset = 0;
|
||||
unsigned offset = explicit_layout ? explicit_layout->offset : 0;
|
||||
struct pan_block_size block_size =
|
||||
panfrost_block_size(layout->modifier, format);
|
||||
panfrost_block_size(layout->modifier, layout->format);
|
||||
|
||||
for (unsigned l = 0; l < nr_slices; ++l) {
|
||||
unsigned width = layout->width;
|
||||
unsigned height = layout->height;
|
||||
unsigned depth = layout->depth;
|
||||
|
||||
for (unsigned l = 0; l < layout->nr_slices; ++l) {
|
||||
struct pan_image_slice_layout *slice = &layout->slices[l];
|
||||
|
||||
unsigned effective_width = ALIGN_POT(util_format_get_nblocksx(format, width), block_size.width);
|
||||
unsigned effective_height = ALIGN_POT(util_format_get_nblocksy(format, height), block_size.height);
|
||||
unsigned effective_width = ALIGN_POT(util_format_get_nblocksx(layout->format, width), block_size.width);
|
||||
unsigned effective_height = ALIGN_POT(util_format_get_nblocksy(layout->format, height), block_size.height);
|
||||
|
||||
/* Align levels to cache-line as a performance improvement for
|
||||
* linear/tiled and as a requirement for AFBC */
|
||||
@@ -289,7 +276,7 @@ pan_image_layout_init(struct pan_image_layout *layout,
|
||||
}
|
||||
|
||||
unsigned slice_full_size =
|
||||
slice_one_size * depth * nr_samples;
|
||||
slice_one_size * depth * layout->nr_samples;
|
||||
|
||||
slice->surface_stride = slice_one_size;
|
||||
|
||||
@@ -299,11 +286,11 @@ pan_image_layout_init(struct pan_image_layout *layout,
|
||||
slice->size = slice_full_size;
|
||||
|
||||
/* Add a checksum region if necessary */
|
||||
if (crc_mode != PAN_IMAGE_CRC_NONE) {
|
||||
if (layout->crc_mode != PAN_IMAGE_CRC_NONE) {
|
||||
slice->crc.size =
|
||||
panfrost_compute_checksum_size(slice, width, height);
|
||||
|
||||
if (crc_mode == PAN_IMAGE_CRC_INBAND) {
|
||||
if (layout->crc_mode == PAN_IMAGE_CRC_INBAND) {
|
||||
slice->crc.offset = offset;
|
||||
offset += slice->crc.size;
|
||||
slice->size += slice->crc.size;
|
||||
@@ -323,7 +310,7 @@ pan_image_layout_init(struct pan_image_layout *layout,
|
||||
if (explicit_layout)
|
||||
layout->data_size = offset;
|
||||
else
|
||||
layout->data_size = ALIGN_POT(layout->array_stride * array_size, 4096);
|
||||
layout->data_size = ALIGN_POT(layout->array_stride * layout->array_size, 4096);
|
||||
layout->crc_size = oob_crc_offset;
|
||||
|
||||
return true;
|
||||
|
@@ -96,15 +96,20 @@ struct pan_image_layout {
|
||||
unsigned nr_samples;
|
||||
enum mali_texture_dimension dim;
|
||||
unsigned nr_slices;
|
||||
struct pan_image_slice_layout slices[MAX_MIP_LEVELS];
|
||||
unsigned array_size;
|
||||
unsigned array_stride;
|
||||
unsigned data_size;
|
||||
|
||||
enum pan_image_crc_mode crc_mode;
|
||||
|
||||
/* The remaining fields may be derived from the above by calling
|
||||
* pan_image_layout_init
|
||||
*/
|
||||
|
||||
struct pan_image_slice_layout slices[MAX_MIP_LEVELS];
|
||||
|
||||
/* crc_size != 0 only if crc_mode == OOB otherwise CRC words are
|
||||
* counted in data_size */
|
||||
unsigned crc_size;
|
||||
unsigned data_size;
|
||||
unsigned array_stride;
|
||||
};
|
||||
|
||||
struct pan_image_mem {
|
||||
@@ -222,13 +227,6 @@ struct pan_image_explicit_layout {
|
||||
|
||||
bool
|
||||
pan_image_layout_init(struct pan_image_layout *layout,
|
||||
uint64_t modifier,
|
||||
enum pipe_format format,
|
||||
enum mali_texture_dimension dim,
|
||||
unsigned width, unsigned height, unsigned depth,
|
||||
unsigned array_size, unsigned nr_samples,
|
||||
unsigned nr_slices,
|
||||
enum pan_image_crc_mode crc_mode,
|
||||
const struct pan_image_explicit_layout *explicit_layout);
|
||||
|
||||
struct pan_surface {
|
||||
|
@@ -75,13 +75,20 @@ panvk_image_create(VkDevice _device,
|
||||
if (!image)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
pan_image_layout_init(&image->pimage.layout, modifier,
|
||||
vk_format_to_pipe_format(image->vk.format),
|
||||
panvk_image_type_to_mali_tex_dim(image->vk.image_type),
|
||||
image->vk.extent.width, image->vk.extent.height,
|
||||
image->vk.extent.depth, image->vk.array_layers,
|
||||
image->vk.samples, image->vk.mip_levels,
|
||||
PAN_IMAGE_CRC_NONE, NULL);
|
||||
image->pimage.layout = (struct pan_image_layout) {
|
||||
.modifier = modifier,
|
||||
.format = vk_format_to_pipe_format(image->vk.format),
|
||||
.dim = panvk_image_type_to_mali_tex_dim(image->vk.image_type),
|
||||
.width = image->vk.extent.width,
|
||||
.height = image->vk.extent.height,
|
||||
.depth = image->vk.extent.depth,
|
||||
.array_size = image->vk.array_layers,
|
||||
.nr_samples = image->vk.samples,
|
||||
.nr_slices = image->vk.mip_levels,
|
||||
.crc_mode = PAN_IMAGE_CRC_NONE
|
||||
};
|
||||
|
||||
pan_image_layout_init(&image->pimage.layout, NULL);
|
||||
|
||||
*pImage = panvk_image_to_handle(image);
|
||||
return VK_SUCCESS;
|
||||
|
Reference in New Issue
Block a user