From 968b6896d5e48944de454cba456c55a49b23128e Mon Sep 17 00:00:00 2001 From: "Eric R. Smith" Date: Tue, 24 Mar 2026 09:48:11 -0300 Subject: [PATCH] panvk: store number of samples in unused bits in the attribute descriptor We reduce the number of bits used for pixel stride from 10 to 7. This gives us space to store the log2 of the number of samples, which we will need later. Reviewed-by: Lars-Ivar Hesselberg Simonsen Reviewed-by: Erik Faye-Lund Part-of: --- .../vulkan/bifrost/panvk_vX_meta_desc_copy.c | 4 ++-- src/panfrost/vulkan/panvk_vX_image_view.c | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/panfrost/vulkan/bifrost/panvk_vX_meta_desc_copy.c b/src/panfrost/vulkan/bifrost/panvk_vX_meta_desc_copy.c index 3eb471a72e3..d0f0c153e45 100644 --- a/src/panfrost/vulkan/bifrost/panvk_vX_meta_desc_copy.c +++ b/src/panfrost/vulkan/bifrost/panvk_vX_meta_desc_copy.c @@ -176,7 +176,7 @@ set_to_table_img_copy(nir_builder *b, nir_def *set_ptr, nir_def *set_desc_count, nir_def *attrib_buf_desc = nir_vec8( b, nir_channel(b, src_desc, 0), nir_channel(b, src_desc, 1), - nir_iand_imm(b, nir_channel(b, src_desc, 2), BITFIELD_MASK(10)), + nir_iand_imm(b, nir_channel(b, src_desc, 2), BITFIELD_MASK(7)), nir_channel(b, src_desc, 3), nir_channel(b, null_desc, 0), nir_channel(b, null_desc, 1), nir_channel(b, null_desc, 2), nir_channel(b, null_desc, 3)); @@ -208,7 +208,7 @@ set_to_table_img_copy(nir_builder *b, nir_def *set_ptr, nir_def *set_desc_count, nir_def *attrib_buf_desc = nir_vec8( b, nir_channel(b, src_desc, 0), nir_channel(b, src_desc, 1), - nir_iand_imm(b, nir_channel(b, src_desc, 2), BITFIELD_MASK(10)), + nir_iand_imm(b, nir_channel(b, src_desc, 2), BITFIELD_MASK(7)), nir_channel(b, src_desc, 3), nir_channel(b, src_desc, 4), nir_channel(b, src_desc, 5), nir_channel(b, src_desc, 6), nir_channel(b, src_desc, 7)); diff --git a/src/panfrost/vulkan/panvk_vX_image_view.c b/src/panfrost/vulkan/panvk_vX_image_view.c index 873f58a40be..d4f46c47dfb 100644 --- a/src/panfrost/vulkan/panvk_vX_image_view.c +++ b/src/panfrost/vulkan/panvk_vX_image_view.c @@ -220,25 +220,32 @@ prepare_attr_buf_descs(struct panvk_image_view *view) (is_3d ? slayout->tiled_or_linear.surface_stride_B : plane_layout->array_stride_B)); + unsigned nr_samples = image->planes[plane_idx].image.props.nr_samples; + nr_samples = (nr_samples > 0) ? nr_samples : 1; + unsigned log2_nr_samples = util_logbase2(nr_samples); + pan_pack(&view->descs.img_attrib_buf[0], ATTRIBUTE_BUFFER, cfg) { /* The format is the only thing we lack to emit attribute descriptors * when copying from the set to the attribute tables. Instead of * making the descriptor size to store an extra format, we pack * the 22-bit format with the texel stride, which is expected to be - * fit in remaining 10 bits. + * fit in 7 bits, followed by 3 bits for log2(nr_samples), which we + * need in order to reconstruct the number of layers in multisampled + * arrays. */ uint32_t fmt_blksize = util_format_get_blocksize(view->pview.format); uint32_t hw_fmt = GENX(pan_format_from_pipe_format)(view->pview.format)->hw; - assert(fmt_blksize < BITFIELD_MASK(10)); - assert(hw_fmt < BITFIELD_MASK(22)); + assert(fmt_blksize <= BITFIELD_MASK(7)); + assert(log2_nr_samples <= BITFIELD_MASK(3)); + assert(hw_fmt <= BITFIELD_MASK(22)); cfg.type = image->vk.drm_format_mod == DRM_FORMAT_MOD_LINEAR ? MALI_ATTRIBUTE_TYPE_3D_LINEAR : MALI_ATTRIBUTE_TYPE_3D_INTERLEAVED; cfg.pointer = image->planes[plane_idx].plane.base + offset; - cfg.stride = fmt_blksize | (hw_fmt << 10); + cfg.stride = fmt_blksize | (log2_nr_samples << 7) | (hw_fmt << 10); cfg.size = pan_image_mip_level_size(&image->planes[plane_idx].image, 0, view->pview.first_level); }