From 696e2064bd7a00d271bbaa1f70e4f36076834fac Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 11 Mar 2024 09:27:22 -0500 Subject: [PATCH] nil: Move Z slice offset calculations to a helper Part-of: --- src/nouveau/nil/nil_image.c | 28 ++++++++++++++++++++++++++++ src/nouveau/nil/nil_image.h | 3 +++ src/nouveau/nil/nil_image_tic.c | 25 +++---------------------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/nouveau/nil/nil_image.c b/src/nouveau/nil/nil_image.c index f6476c72827..8aaa3c51218 100644 --- a/src/nouveau/nil/nil_image.c +++ b/src/nouveau/nil/nil_image.c @@ -702,6 +702,34 @@ nil_image_init(struct nv_device_info *dev, return true; } +/** Offset of the given Z slice within the level */ +uint64_t +nil_image_level_z_offset_B(const struct nil_image *image, + uint32_t level, uint32_t z) +{ + assert(level < image->num_levels); + const struct nil_extent4d lvl_extent_px = + nil_image_level_extent_px(image, level); + assert(z < lvl_extent_px.d); + + const struct nil_tiling *lvl_tiling = &image->levels[level].tiling; + + const uint32_t z_tl = z >> lvl_tiling->z_log2; + const uint32_t z_GOB = z & BITFIELD_MASK(lvl_tiling->z_log2); + + const struct nil_extent4d lvl_extent_tl = + nil_extent4d_px_to_tl(lvl_extent_px, *lvl_tiling, + image->format, image->sample_layout); + uint64_t offset_B = lvl_extent_tl.w * lvl_extent_tl.h * (uint64_t)z_tl * + nil_tiling_size_B(*lvl_tiling); + + const struct nil_extent4d tiling_extent_B = + nil_tiling_extent_B(*lvl_tiling); + offset_B += tiling_extent_B.w * tiling_extent_B.h * z_GOB; + + return offset_B; +} + uint64_t nil_image_level_depth_stride_B(const struct nil_image *image, uint32_t level) { diff --git a/src/nouveau/nil/nil_image.h b/src/nouveau/nil/nil_image.h index 81ebe5aeeaf..ecc4fffdc60 100644 --- a/src/nouveau/nil/nil_image.h +++ b/src/nouveau/nil/nil_image.h @@ -220,6 +220,9 @@ nil_image_level_layer_offset_B(const struct nil_image *image, return image->levels[level].offset_B + (layer * image->array_stride_B); } +uint64_t nil_image_level_z_offset_B(const struct nil_image *image, + uint32_t level, uint32_t z); + static inline uint32_t nil_image_mip_tail_offset_B(const struct nil_image *image) { diff --git a/src/nouveau/nil/nil_image_tic.c b/src/nouveau/nil/nil_image_tic.c index 00247382a29..36c808fbed6 100644 --- a/src/nouveau/nil/nil_image_tic.c +++ b/src/nouveau/nil/nil_image_tic.c @@ -415,29 +415,10 @@ nvb097_nil_image_fill_tic(const struct nil_image *image, /* There's no base layer field in the texture header */ uint64_t layer_address = base_address; if (view->type == NIL_VIEW_TYPE_3D_SLICED) { - assert(view->num_levels == 1); + assert(image->num_levels == 1); assert(view->base_array_layer + view->array_len <= image->extent_px.d); - - /* For sliced 3D images, computing the offset is a bit more complicated. - * We first have to compute the offset to the tile then, within that - * tile, the offset to the GOB. - * - * TODO: If we ever enable 3D gobs, we'll also have to compute the - * offset within the gob. - */ - const uint32_t z_tl = view->base_array_layer >> tiling->z_log2; - const uint32_t z_GOB = - view->base_array_layer & BITFIELD_MASK(tiling->z_log2); - - const struct nil_extent4d extent_tl = - nil_extent4d_px_to_tl(image->extent_px, *tiling, - image->format, image->sample_layout); - layer_address += extent_tl.w * extent_tl.h * z_tl * - nil_tiling_size_B(*tiling); - - const struct nil_extent4d tiling_extent_B = - nil_tiling_extent_B(*tiling); - layer_address += tiling_extent_B.w * tiling_extent_B.h * z_GOB; + layer_address += nil_image_level_z_offset_B(image, view->base_level, + view->base_array_layer); } else { assert(view->base_array_layer + view->array_len <= image->extent_px.a); layer_address += view->base_array_layer * image->array_stride_B;