nil: Move Z slice offset calculations to a helper

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28103>
This commit is contained in:
Faith Ekstrand
2024-03-11 09:27:22 -05:00
committed by Marge Bot
parent 813f37a8ed
commit 696e2064bd
3 changed files with 34 additions and 22 deletions
+28
View File
@@ -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)
{
+3
View File
@@ -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)
{
+3 -22
View File
@@ -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;