From a936013311d41bc8baf7e4b095faa50a74876bc2 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Wed, 30 Apr 2025 15:22:48 +0200 Subject: [PATCH] pan: Draw a clear line between image layout, image and texture helpers This involves moving helpers in separate pan_{layout,image,texture}.{c,h} files, and renaming some of the helper/structs to clarify their purpose. Signed-off-by: Boris Brezillon Reviewed-by: Eric R. Smith Reviewed-by: Mary Guillemard Acked-by: Daniel Stone Reviewed-by: Ryan Mckeever Reviewed-by: Olivia Lee Reviewed-by: Lars-Ivar Hesselberg Simonsen Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 24 +- src/gallium/drivers/panfrost/pan_context.h | 1 - src/gallium/drivers/panfrost/pan_device.c | 1 - src/gallium/drivers/panfrost/pan_fb_preload.c | 14 +- src/gallium/drivers/panfrost/pan_fb_preload.h | 1 - .../drivers/panfrost/pan_mod_conv_cso.h | 1 - src/gallium/drivers/panfrost/pan_resource.c | 16 +- src/gallium/drivers/panfrost/pan_resource.h | 1 - src/gallium/drivers/panfrost/pan_screen.c | 1 - src/gallium/drivers/panfrost/pan_screen.h | 1 - src/panfrost/lib/pan_afbc.h | 20 +- src/panfrost/lib/pan_afrc.h | 34 +- src/panfrost/lib/pan_blend.c | 2 +- src/panfrost/lib/pan_desc.c | 15 +- src/panfrost/lib/pan_desc.h | 3 +- src/panfrost/lib/pan_image.h | 224 +++++++++++++ src/panfrost/lib/pan_layout.c | 130 ++------ src/panfrost/lib/pan_layout.h | 143 ++++++++ src/panfrost/lib/pan_texture.c | 153 ++++----- src/panfrost/lib/pan_texture.h | 308 +----------------- src/panfrost/lib/pan_util.c | 2 +- src/panfrost/lib/tests/test-clear.c | 2 +- src/panfrost/lib/tests/test-layout.cpp | 16 +- src/panfrost/vulkan/panvk_buffer.c | 2 + src/panfrost/vulkan/panvk_image.h | 2 +- src/panfrost/vulkan/panvk_vX_buffer_view.c | 8 +- src/panfrost/vulkan/panvk_vX_cmd_draw.c | 1 + src/panfrost/vulkan/panvk_vX_image_view.c | 22 +- 28 files changed, 592 insertions(+), 556 deletions(-) create mode 100644 src/panfrost/lib/pan_image.h create mode 100644 src/panfrost/lib/pan_layout.h diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index edd9b6aabd5..cb2c499b026 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -1766,20 +1766,20 @@ panfrost_create_sampler_view_bo(struct panfrost_sampler_view *so, #if PAN_ARCH >= 7 /* v7+ doesn't have an _RRRR component order. */ if (util_format_is_depth_or_stencil(format)) - GENX(panfrost_texture_swizzle_replicate_x)(&iview); + GENX(pan_texture_swizzle_replicate_x)(&iview); #endif #if PAN_ARCH == 7 /* v7 requires AFBC reswizzle */ if (!util_format_is_depth_or_stencil(format) && !panfrost_format_is_yuv(format) && pan_format_supports_afbc(PAN_ARCH, format)) - GENX(panfrost_texture_afbc_reswizzle)(&iview); + GENX(pan_texture_afbc_reswizzle)(&iview); #endif panfrost_set_image_view_planes(&iview, texture); unsigned size = (PAN_ARCH <= 5 ? pan_size(TEXTURE) : 0) + - GENX(panfrost_estimate_texture_payload_size)(&iview); + GENX(pan_texture_estimate_payload_size)(&iview); struct panfrost_pool *pool = so->pool ?: &ctx->descs; struct panfrost_ptr payload = pan_pool_alloc_aligned(&pool->base, size, 64); @@ -1817,7 +1817,7 @@ panfrost_create_sampler_view_bo(struct panfrost_sampler_view *so, iview.astc.narrow = true; } - GENX(panfrost_new_texture)(&iview, tex, &payload); + GENX(pan_texture_emit)(&iview, tex, &payload); } static void @@ -2025,11 +2025,12 @@ emit_image_bufs(struct panfrost_batch *batch, enum pipe_shader_type shader, bool is_3d = rsrc->base.target == PIPE_TEXTURE_3D; bool is_buffer = rsrc->base.target == PIPE_BUFFER; - unsigned offset = is_buffer ? image->u.buf.offset - : panfrost_texture_offset( - &rsrc->image.layout, image->u.tex.level, - (is_3d || is_msaa) ? 0 : image->u.tex.first_layer, - (is_3d || is_msaa) ? image->u.tex.first_layer : 0); + unsigned offset = + is_buffer ? image->u.buf.offset + : pan_image_surface_offset( + &rsrc->image.layout, image->u.tex.level, + (is_3d || is_msaa) ? 0 : image->u.tex.first_layer, + (is_3d || is_msaa) ? image->u.tex.first_layer : 0); panfrost_track_image_access(batch, shader, image); @@ -2064,7 +2065,7 @@ emit_image_bufs(struct panfrost_batch *batch, enum pipe_shader_type shader, cfg.row_stride = rsrc->image.layout.slices[level].row_stride; if (cfg.r_dimension > 1) { cfg.slice_stride = - panfrost_get_layer_stride(&rsrc->image.layout, level); + pan_image_surface_stride(&rsrc->image.layout, level); } if (is_msaa) { @@ -2073,7 +2074,8 @@ emit_image_bufs(struct panfrost_batch *batch, enum pipe_shader_type shader, the R dimension */ cfg.r_dimension = samples; cfg.slice_stride = - panfrost_get_layer_stride(&rsrc->image.layout, level) / samples; + pan_image_surface_stride(&rsrc->image.layout, level) / + samples; } else { /* multisampled image arrays are emulated by making the image "samples" times higher than the original image, diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index 64da7d3b41d..1760fef8ea7 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -34,7 +34,6 @@ #include "pan_encoder.h" #include "pan_job.h" #include "pan_resource.h" -#include "pan_texture.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" diff --git a/src/gallium/drivers/panfrost/pan_device.c b/src/gallium/drivers/panfrost/pan_device.c index a2bf204eff1..55402ea8ee5 100644 --- a/src/gallium/drivers/panfrost/pan_device.c +++ b/src/gallium/drivers/panfrost/pan_device.c @@ -35,7 +35,6 @@ #include "pan_device.h" #include "pan_encoder.h" #include "pan_samples.h" -#include "pan_texture.h" #include "pan_util.h" #include "wrap.h" diff --git a/src/gallium/drivers/panfrost/pan_fb_preload.c b/src/gallium/drivers/panfrost/pan_fb_preload.c index f98e2b55f4f..f6a7fdc94d8 100644 --- a/src/gallium/drivers/panfrost/pan_fb_preload.c +++ b/src/gallium/drivers/panfrost/pan_fb_preload.c @@ -875,7 +875,7 @@ pan_preload_emit_textures(struct pan_pool *pool, const struct pan_fb_info *fb, struct pan_image_view *pview = &patched_views[patched_count++]; *pview = *view; /* v7+ doesn't have an _RRRR component order. */ - GENX(panfrost_texture_swizzle_replicate_x)(pview); + GENX(pan_texture_swizzle_replicate_x)(pview); view = pview; #endif views[tex_count++] = view; @@ -902,7 +902,7 @@ pan_preload_emit_textures(struct pan_pool *pool, const struct pan_fb_info *fb, *pview = *view; pview->format = fmt; /* v7+ doesn't have an _RRRR component order. */ - GENX(panfrost_texture_swizzle_replicate_x)(pview); + GENX(pan_texture_swizzle_replicate_x)(pview); view = pview; #else if (fmt != view->format) { @@ -924,7 +924,7 @@ pan_preload_emit_textures(struct pan_pool *pool, const struct pan_fb_info *fb, pan_format_supports_afbc(PAN_ARCH, view->format)) { struct pan_image_view *pview = &patched_views[patched_count++]; *pview = *view; - GENX(panfrost_texture_afbc_reswizzle)(pview); + GENX(pan_texture_afbc_reswizzle)(pview); view = pview; } #endif @@ -945,11 +945,11 @@ pan_preload_emit_textures(struct pan_pool *pool, const struct pan_fb_info *fb, for (unsigned i = 0; i < tex_count; i++) { void *texture = textures.cpu + (pan_size(TEXTURE) * i); size_t payload_size = - GENX(panfrost_estimate_texture_payload_size)(views[i]); + GENX(pan_texture_estimate_payload_size)(views[i]); struct panfrost_ptr surfaces = pan_pool_alloc_aligned(pool, payload_size, 64); - GENX(panfrost_new_texture)(views[i], texture, &surfaces); + GENX(pan_texture_emit)(views[i], texture, &surfaces); } return textures.gpu; @@ -958,7 +958,7 @@ pan_preload_emit_textures(struct pan_pool *pool, const struct pan_fb_info *fb, for (unsigned i = 0; i < tex_count; i++) { size_t sz = pan_size(TEXTURE) + - GENX(panfrost_estimate_texture_payload_size)(views[i]); + GENX(pan_texture_estimate_payload_size)(views[i]); struct panfrost_ptr texture = pan_pool_alloc_aligned(pool, sz, pan_alignment(TEXTURE)); struct panfrost_ptr surfaces = { @@ -966,7 +966,7 @@ pan_preload_emit_textures(struct pan_pool *pool, const struct pan_fb_info *fb, .gpu = texture.gpu + pan_size(TEXTURE), }; - GENX(panfrost_new_texture)(views[i], texture.cpu, &surfaces); + GENX(pan_texture_emit)(views[i], texture.cpu, &surfaces); textures[i] = texture.gpu; } diff --git a/src/gallium/drivers/panfrost/pan_fb_preload.h b/src/gallium/drivers/panfrost/pan_fb_preload.h index 47a6598a30c..1f15ff4c754 100644 --- a/src/gallium/drivers/panfrost/pan_fb_preload.h +++ b/src/gallium/drivers/panfrost/pan_fb_preload.h @@ -28,7 +28,6 @@ #include "util/format/u_format.h" #include "pan_desc.h" #include "pan_pool.h" -#include "pan_texture.h" #include "pan_util.h" struct pan_blend_shader_cache; diff --git a/src/gallium/drivers/panfrost/pan_mod_conv_cso.h b/src/gallium/drivers/panfrost/pan_mod_conv_cso.h index 63eb47175ba..195f0b3f1e2 100644 --- a/src/gallium/drivers/panfrost/pan_mod_conv_cso.h +++ b/src/gallium/drivers/panfrost/pan_mod_conv_cso.h @@ -27,7 +27,6 @@ #include "util/hash_table.h" #include "panfrost/util/pan_ir.h" -#include "pan_texture.h" struct panfrost_context; struct panfrost_resource; diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index c682908db75..8b91335df4a 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -782,8 +782,8 @@ panfrost_resource_create_with_modifier(struct pipe_screen *screen, if (dev->ro && (template->bind & PIPE_BIND_SCANOUT)) { struct winsys_handle handle; - struct pan_block_size blocksize = - panfrost_renderblock_size(modifier, template->format); + struct pan_image_block_size blocksize = + pan_image_renderblock_size(modifier, template->format); /* Block-based texture formats are only used for texture * compression (not framebuffer compression!), which doesn't @@ -1027,7 +1027,7 @@ panfrost_load_tiled_images(struct panfrost_transfer *transfer, return; struct panfrost_bo *bo = rsrc->bo; - unsigned stride = panfrost_get_layer_stride(&rsrc->image.layout, level); + unsigned stride = pan_image_surface_stride(&rsrc->image.layout, level); /* Otherwise, load each layer separately, required to load from 3D and * array textures. @@ -1088,7 +1088,7 @@ dump_block(struct panfrost_resource *rsrc, uint32_t idx) uint32_t *header = (uint32_t *)(ptr + (idx * AFBC_HEADER_BYTES_PER_TILE)); uint32_t body_base_ptr = header[0]; uint32_t *body = (uint32_t *)(ptr + body_base_ptr); - struct pan_block_size block_sz = + struct pan_image_block_size block_sz = pan_afbc_subblock_size(rsrc->image.layout.modifier); unsigned pixel_sz = util_format_get_blocksize(rsrc->base.format); unsigned uncompressed_size = pixel_sz * block_sz.width * block_sz.height; @@ -1180,7 +1180,7 @@ panfrost_store_tiled_images(struct panfrost_transfer *transfer, struct panfrost_bo *bo = rsrc->bo; struct pipe_transfer *ptrans = &transfer->base; unsigned level = ptrans->level; - unsigned stride = panfrost_get_layer_stride(&rsrc->image.layout, level); + unsigned stride = pan_image_surface_stride(&rsrc->image.layout, level); /* Otherwise, store each layer separately, required to store to 3D and * array textures. @@ -1263,7 +1263,7 @@ panfrost_ptr_map(struct pipe_context *pctx, struct pipe_resource *resource, */ transfer->base.stride = staging->image.layout.slices[0].row_stride; transfer->base.layer_stride = - panfrost_get_layer_stride(&staging->image.layout, 0); + pan_image_surface_stride(&staging->image.layout, 0); transfer->staging.rsrc = &staging->base; @@ -1439,7 +1439,7 @@ panfrost_ptr_map(struct pipe_context *pctx, struct pipe_resource *resource, transfer->base.stride = rsrc->image.layout.slices[level].row_stride; transfer->base.layer_stride = - panfrost_get_layer_stride(&rsrc->image.layout, level); + pan_image_surface_stride(&rsrc->image.layout, level); /* By mapping direct-write, we're implicitly already * initialized (maybe), so be conservative */ @@ -1774,7 +1774,7 @@ panfrost_pack_afbc(struct panfrost_context *ctx, } } - total_size = ALIGN_POT(total_size, pan_slice_align(dst_modifier)); + total_size = ALIGN_POT(total_size, pan_image_slice_align(dst_modifier)); { unsigned width = u_minify(prsrc->base.width0, level); unsigned height = u_minify(prsrc->base.height0, level); diff --git a/src/gallium/drivers/panfrost/pan_resource.h b/src/gallium/drivers/panfrost/pan_resource.h index 978e3419a8d..42c481cfa19 100644 --- a/src/gallium/drivers/panfrost/pan_resource.h +++ b/src/gallium/drivers/panfrost/pan_resource.h @@ -29,7 +29,6 @@ #include "util/u_range.h" #include "pan_minmax_cache.h" #include "pan_screen.h" -#include "pan_texture.h" #define LAYOUT_CONVERT_THRESHOLD 8 #define PAN_MAX_BATCHES 32 diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c index 45cf02100e3..e9b5b528b59 100644 --- a/src/gallium/drivers/panfrost/pan_screen.c +++ b/src/gallium/drivers/panfrost/pan_screen.c @@ -54,7 +54,6 @@ #include "pan_resource.h" #include "pan_screen.h" #include "pan_shader.h" -#include "pan_texture.h" #include "pan_util.h" #include "pan_context.h" diff --git a/src/gallium/drivers/panfrost/pan_screen.h b/src/gallium/drivers/panfrost/pan_screen.h index ab76dd631f8..83b7bb39571 100644 --- a/src/gallium/drivers/panfrost/pan_screen.h +++ b/src/gallium/drivers/panfrost/pan_screen.h @@ -41,7 +41,6 @@ #include "pan_device.h" #include "pan_mempool.h" -#include "pan_texture.h" #define PAN_QUERY_DRAW_CALLS (PIPE_QUERY_DRIVER_SPECIFIC + 0) diff --git a/src/panfrost/lib/pan_afbc.h b/src/panfrost/lib/pan_afbc.h index c4763b044a8..73b4593ed95 100644 --- a/src/panfrost/lib/pan_afbc.h +++ b/src/panfrost/lib/pan_afbc.h @@ -14,7 +14,7 @@ #define __PAN_AFBC_H #include "pan_format.h" -#include "pan_texture.h" +#include "pan_layout.h" #include "drm-uapi/drm_fourcc.h" @@ -92,7 +92,7 @@ enum pan_afbc_mode { * superblock sizes on the luma and chroma planes. These formats are unsupported * for now. */ -static inline struct pan_block_size +static inline struct pan_image_block_size pan_afbc_superblock_size(uint64_t modifier) { unsigned index = (modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK); @@ -101,24 +101,24 @@ pan_afbc_superblock_size(uint64_t modifier) switch (index) { case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16: - return (struct pan_block_size){16, 16}; + return (struct pan_image_block_size){16, 16}; case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8: - return (struct pan_block_size){32, 8}; + return (struct pan_image_block_size){32, 8}; case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4: - return (struct pan_block_size){64, 4}; + return (struct pan_image_block_size){64, 4}; default: assert(!"Unsupported AFBC block size"); - return (struct pan_block_size){0, 0}; + return (struct pan_image_block_size){0, 0}; } } /* * Given an AFBC modifier, return the render size. */ -static inline struct pan_block_size +static inline struct pan_image_block_size pan_afbc_renderblock_size(uint64_t modifier) { - struct pan_block_size blk_size = pan_afbc_superblock_size(modifier); + struct pan_image_block_size blk_size = pan_afbc_superblock_size(modifier); /* The GPU needs to render 16x16 tiles. For wide tiles, that means we * have to extend the render region to have a height of 16 pixels. @@ -161,10 +161,10 @@ pan_afbc_is_wide(uint64_t modifier) * superblock). This is always 4x4 for now as we only support one AFBC * superblock layout. */ -static inline struct pan_block_size +static inline struct pan_image_block_size pan_afbc_subblock_size(uint64_t modifier) { - return (struct pan_block_size){4, 4}; + return (struct pan_image_block_size){4, 4}; } /* diff --git a/src/panfrost/lib/pan_afrc.h b/src/panfrost/lib/pan_afrc.h index 0a84670f340..583228547ce 100644 --- a/src/panfrost/lib/pan_afrc.h +++ b/src/panfrost/lib/pan_afrc.h @@ -11,7 +11,7 @@ #define __PAN_AFRC_H #include "pan_format.h" -#include "pan_texture.h" +#include "pan_layout.h" #ifdef __cplusplus extern "C" { @@ -135,23 +135,23 @@ struct pan_afrc_block_size { BLOCK_SIZE(32, 2048), \ } -static inline struct pan_block_size +static inline struct pan_image_block_size pan_afrc_clump_size(enum pipe_format format, bool scan) { struct pan_afrc_format_info finfo = pan_afrc_get_format_info(format); switch (finfo.num_comps) { case 1: - return scan ? (struct pan_block_size){16, 4} - : (struct pan_block_size){8, 8}; + return scan ? (struct pan_image_block_size){16, 4} + : (struct pan_image_block_size){8, 8}; case 2: - return (struct pan_block_size){8, 4}; + return (struct pan_image_block_size){8, 4}; case 3: case 4: - return (struct pan_block_size){4, 4}; + return (struct pan_image_block_size){4, 4}; default: assert(0); - return (struct pan_block_size){0, 0}; + return (struct pan_image_block_size){0, 0}; } } @@ -160,7 +160,7 @@ static inline unsigned pan_afrc_clump_get_nr_components(enum pipe_format format, bool scan) { const struct util_format_description *desc = util_format_description(format); - struct pan_block_size clump_sz = pan_afrc_clump_size(format, scan); + struct pan_image_block_size clump_sz = pan_afrc_clump_size(format, scan); return clump_sz.width * clump_sz.height * desc->nr_channels; } @@ -288,24 +288,24 @@ pan_afrc_get_rate(enum pipe_format format, uint64_t modifier) return block_sz / block_comps; } -static inline struct pan_block_size +static inline struct pan_image_block_size pan_afrc_layout_size(uint64_t modifier) { if (pan_afrc_is_scan(modifier)) - return (struct pan_block_size){16, 4}; + return (struct pan_image_block_size){16, 4}; else - return (struct pan_block_size){8, 8}; + return (struct pan_image_block_size){8, 8}; } -static inline struct pan_block_size +static inline struct pan_image_block_size pan_afrc_tile_size(enum pipe_format format, uint64_t modifier) { bool scan = pan_afrc_is_scan(modifier); - struct pan_block_size clump_sz = pan_afrc_clump_size(format, scan); - struct pan_block_size layout_sz = pan_afrc_layout_size(modifier); + struct pan_image_block_size clump_sz = pan_afrc_clump_size(format, scan); + struct pan_image_block_size layout_sz = pan_afrc_layout_size(modifier); - return (struct pan_block_size){clump_sz.width * layout_sz.width, - clump_sz.height * layout_sz.height}; + return (struct pan_image_block_size){clump_sz.width * layout_sz.width, + clump_sz.height * layout_sz.height}; } static inline unsigned @@ -329,7 +329,7 @@ pan_afrc_buffer_alignment_from_modifier(uint64_t modifier) static inline uint32_t pan_afrc_row_stride(enum pipe_format format, uint64_t modifier, uint32_t width) { - struct pan_block_size tile_size = pan_afrc_tile_size(format, modifier); + struct pan_image_block_size tile_size = pan_afrc_tile_size(format, modifier); unsigned block_size = pan_afrc_block_size_from_modifier(modifier); return (width / tile_size.width) * block_size * AFRC_CLUMPS_PER_TILE; diff --git a/src/panfrost/lib/pan_blend.c b/src/panfrost/lib/pan_blend.c index 69a01238e95..c65532c8b0d 100644 --- a/src/panfrost/lib/pan_blend.c +++ b/src/panfrost/lib/pan_blend.c @@ -27,6 +27,7 @@ #ifdef PAN_ARCH #include "pan_shader.h" +#include "pan_texture.h" #endif #include "compiler/nir/nir.h" @@ -34,7 +35,6 @@ #include "compiler/nir/nir_conversion_builder.h" #include "compiler/nir/nir_lower_blend.h" #include "util/format/u_format.h" -#include "pan_texture.h" #ifndef PAN_ARCH diff --git a/src/panfrost/lib/pan_desc.c b/src/panfrost/lib/pan_desc.c index 84f3cf624dc..e5a0ac049f6 100644 --- a/src/panfrost/lib/pan_desc.c +++ b/src/panfrost/lib/pan_desc.c @@ -35,6 +35,7 @@ #include "pan_encoder.h" #include "pan_props.h" #include "pan_texture.h" +#include "pan_util.h" #define PAN_BIN_LEVEL_COUNT 12 @@ -99,7 +100,7 @@ renderblock_fits_in_single_pass(const struct pan_image_view *view, if (!drm_is_afbc(mod)) return tile_size >= 16 * 16; - struct pan_block_size renderblk_sz = pan_afbc_renderblock_size(mod); + struct pan_image_block_size renderblk_sz = pan_afbc_renderblock_size(mod); return tile_size >= renderblk_sz.width * renderblk_sz.height; } @@ -216,7 +217,7 @@ pan_prepare_s(const struct pan_fb_info *fb, unsigned layer_idx, ext->s_msaa = mali_sampling_mode(s); - struct pan_surface surf; + struct pan_image_surface surf; pan_iview_get_surface(s, 0, layer_idx, 0, &surf); assert(image->layout.modifier == @@ -246,7 +247,7 @@ pan_prepare_zs(const struct pan_fb_info *fb, unsigned layer_idx, ext->zs_msaa = mali_sampling_mode(zs); - struct pan_surface surf; + struct pan_image_surface surf; pan_iview_get_surface(zs, 0, layer_idx, 0, &surf); UNUSED const struct pan_image_slice_layout *slice = &image->layout.slices[level]; @@ -609,7 +610,7 @@ pan_prepare_rt(const struct pan_fb_info *fb, unsigned layer_idx, cfg->writeback_block_format = mod_to_block_fmt(image->layout.modifier); - struct pan_surface surf; + struct pan_image_surface surf; pan_iview_get_surface(rt, 0, layer_idx, 0, &surf); if (drm_is_afbc(image->layout.modifier)) { @@ -789,7 +790,7 @@ pan_force_clean_write_on(const struct pan_image *image, unsigned tile_size) if (!drm_is_afbc(image->layout.modifier)) return false; - struct pan_block_size renderblk_sz = + struct pan_image_block_size renderblk_sz = pan_afbc_renderblock_size(image->layout.modifier); assert(renderblk_sz.width >= 16 && renderblk_sz.height >= 16); @@ -1077,7 +1078,7 @@ GENX(pan_emit_fbd)(const struct pan_fb_info *fb, unsigned layer_idx, } unsigned level = rt->first_level; - struct pan_surface surf; + struct pan_image_surface surf; pan_iview_get_surface(rt, 0, 0, 0, &surf); @@ -1105,7 +1106,7 @@ GENX(pan_emit_fbd)(const struct pan_fb_info *fb, unsigned layer_idx, const struct pan_image_view *zs = fb->zs.view.zs; const struct pan_image *image = pan_image_view_get_zs_plane(zs); unsigned level = zs->first_level; - struct pan_surface surf; + struct pan_image_surface surf; pan_iview_get_surface(zs, 0, 0, 0, &surf); diff --git a/src/panfrost/lib/pan_desc.h b/src/panfrost/lib/pan_desc.h index affdf8f01fa..37bc8f44e48 100644 --- a/src/panfrost/lib/pan_desc.h +++ b/src/panfrost/lib/pan_desc.h @@ -30,7 +30,8 @@ #include "genxml/gen_macros.h" -#include "pan_texture.h" +#include "pan_image.h" +#include "pan_pool.h" struct pan_compute_dim { uint32_t x, y, z; diff --git a/src/panfrost/lib/pan_image.h b/src/panfrost/lib/pan_image.h new file mode 100644 index 00000000000..6dda745be99 --- /dev/null +++ b/src/panfrost/lib/pan_image.h @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2008 VMware, Inc. + * Copyright (C) 2014 Broadcom + * Copyright (C) 2018-2019 Alyssa Rosenzweig + * Copyright (C) 2019-2020 Collabora, Ltd. + * + * SPDX-License-Identifier: MIT + */ + +#ifndef __PAN_IMAGE_H +#define __PAN_IMAGE_H + +#include "genxml/gen_macros.h" + +#include +#include "util/format/u_format.h" +#include "pan_format.h" +#include "pan_layout.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct pan_image_mem { + uint64_t base; + unsigned offset; +}; + +struct pan_image { + struct pan_image_mem data; + struct pan_image_layout layout; +}; + +struct pan_image_surface { + union { + uint64_t data; + struct { + uint64_t header; + uint64_t body; + } afbc; + }; +}; + +struct pan_image_view { + /* Format, dimension and sample count of the view might differ from + * those of the image (2D view of a 3D image surface for instance). + */ + enum pipe_format format; + enum mali_texture_dimension dim; + unsigned first_level, last_level; + unsigned first_layer, last_layer; + unsigned char swizzle[4]; + + /* planes 1 and 2 are NULL for single plane formats */ + const struct pan_image *planes[MAX_IMAGE_PLANES]; + + /* If EXT_multisampled_render_to_texture is used, this may be + * greater than image->layout.nr_samples. */ + unsigned nr_samples; + + /* Only valid if dim == 1D, needed to implement buffer views */ + struct { + unsigned offset; + unsigned size; + } buf; + + struct { + unsigned narrow; + } astc; +}; + +static inline const struct pan_image * +pan_image_view_get_plane(const struct pan_image_view *iview, uint32_t idx) +{ + if (idx >= ARRAY_SIZE(iview->planes)) + return NULL; + + return iview->planes[idx]; +} + +static inline unsigned +pan_image_view_get_plane_mask(const struct pan_image_view *iview) +{ + unsigned mask = 0; + + for (unsigned i = 0; i < ARRAY_SIZE(iview->planes); i++) { + if (iview->planes[i]) + mask |= BITFIELD_BIT(i); + } + + return mask; +} + +static inline unsigned +pan_image_view_get_first_plane_idx(const struct pan_image_view *iview) +{ + unsigned mask = pan_image_view_get_plane_mask(iview); + + assert(mask); + return ffs(mask) - 1; +} + +static inline const struct pan_image * +pan_image_view_get_first_plane(const struct pan_image_view *iview) +{ + unsigned first_plane_idx = pan_image_view_get_first_plane_idx(iview); + return pan_image_view_get_plane(iview, first_plane_idx); +} + +static inline uint32_t +pan_image_view_get_nr_samples(const struct pan_image_view *iview) +{ + const struct pan_image *image = pan_image_view_get_first_plane(iview); + + if (!image) + return 0; + + return image->layout.nr_samples; +} + +static inline const struct pan_image * +pan_image_view_get_color_plane(const struct pan_image_view *iview) +{ + /* We only support rendering to plane 0 */ + assert(pan_image_view_get_plane(iview, 1) == NULL); + return pan_image_view_get_plane(iview, 0); +} + +static inline bool +pan_image_view_has_crc(const struct pan_image_view *iview) +{ + const struct pan_image *image = pan_image_view_get_color_plane(iview); + + if (!image) + return false; + + return image->layout.crc; +} + +static inline const struct pan_image * +pan_image_view_get_s_plane(const struct pan_image_view *iview) +{ + ASSERTED const struct util_format_description *fdesc = + util_format_description(iview->format); + assert(util_format_has_stencil(fdesc)); + + /* In case of multiplanar depth/stencil, the stencil is always on + * plane 1. Combined depth/stencil only has one plane, so depth + * will be on plane 0 in either case. + */ + const struct pan_image *plane = iview->planes[1] ?: iview->planes[0]; + + assert(plane); + fdesc = util_format_description(plane->layout.format); + assert(util_format_has_stencil(fdesc)); + return plane; +} + +static inline const struct pan_image * +pan_image_view_get_zs_plane(const struct pan_image_view *iview) +{ + assert(util_format_is_depth_or_stencil(iview->format)); + + /* Depth or combined depth-stencil is always on plane 0. */ + return pan_image_view_get_plane(iview, 0); +} + +static inline void +pan_iview_get_surface(const struct pan_image_view *iview, unsigned level, + unsigned layer, unsigned sample, + struct pan_image_surface *surf) +{ + const struct util_format_description *fdesc = + util_format_description(iview->format); + + /* In case of multiplanar depth/stencil, the stencil is always on + * plane 1. Combined depth/stencil only has one plane, so depth + * will be on plane 0 in either case. + */ + const struct pan_image *image = util_format_has_stencil(fdesc) + ? pan_image_view_get_s_plane(iview) + : pan_image_view_get_plane(iview, 0); + + level += iview->first_level; + assert(level < image->layout.nr_slices); + + layer += iview->first_layer; + + bool is_3d = image->layout.dim == MALI_TEXTURE_DIMENSION_3D; + const struct pan_image_slice_layout *slice = &image->layout.slices[level]; + uint64_t base = image->data.base + image->data.offset; + + memset(surf, 0, sizeof(*surf)); + + if (drm_is_afbc(image->layout.modifier)) { + assert(!sample); + + if (is_3d) { + ASSERTED unsigned depth = u_minify(image->layout.depth, level); + assert(layer < depth); + surf->afbc.header = + base + slice->offset + (layer * slice->afbc.surface_stride); + surf->afbc.body = base + slice->offset + slice->afbc.header_size + + (slice->surface_stride * layer); + } else { + assert(layer < image->layout.array_size); + surf->afbc.header = + base + pan_image_surface_offset(&image->layout, level, layer, 0); + surf->afbc.body = surf->afbc.header + slice->afbc.header_size; + } + } else { + unsigned array_idx = is_3d ? 0 : layer; + unsigned surface_idx = is_3d ? layer : sample; + + surf->data = base + pan_image_surface_offset(&image->layout, level, + array_idx, surface_idx); + } +} + +#ifdef __cplusplus +} /* extern C */ +#endif + +#endif diff --git a/src/panfrost/lib/pan_layout.c b/src/panfrost/lib/pan_layout.c index 49784fad195..c375e8bb03d 100644 --- a/src/panfrost/lib/pan_layout.c +++ b/src/panfrost/lib/pan_layout.c @@ -28,21 +28,21 @@ #include "util/u_math.h" #include "pan_afbc.h" #include "pan_afrc.h" +#include "pan_layout.h" #include "pan_props.h" -#include "pan_texture.h" /* * Given a format, determine the tile size used for u-interleaving. For formats * that are already block compressed, this is 4x4. For all other formats, this * is 16x16, hence the modifier name. */ -static inline struct pan_block_size -panfrost_u_interleaved_tile_size(enum pipe_format format) +static inline struct pan_image_block_size +pan_u_interleaved_tile_size(enum pipe_format format) { if (util_format_is_compressed(format)) - return (struct pan_block_size){4, 4}; + return (struct pan_image_block_size){4, 4}; else - return (struct pan_block_size){16, 16}; + return (struct pan_image_block_size){16, 16}; } /* @@ -50,41 +50,32 @@ panfrost_u_interleaved_tile_size(enum pipe_format format) * the tile size. For AFBC, this is the superblock size. For AFRC, this is the * paging tile size. For linear textures, this is trivially 1x1. */ -struct pan_block_size -panfrost_block_size(uint64_t modifier, enum pipe_format format) +struct pan_image_block_size +pan_image_block_size(uint64_t modifier, enum pipe_format format) { if (modifier == DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED) - return panfrost_u_interleaved_tile_size(format); + return pan_u_interleaved_tile_size(format); else if (drm_is_afbc(modifier)) return pan_afbc_superblock_size(modifier); else if (drm_is_afrc(modifier)) return pan_afrc_tile_size(format, modifier); else - return (struct pan_block_size){1, 1}; + return (struct pan_image_block_size){1, 1}; } /* For non-AFBC and non-wide AFBC, the render block size matches * the block size, but for wide AFBC, the GPU wants the block height * to be 16 pixels high. */ -struct pan_block_size -panfrost_renderblock_size(uint64_t modifier, enum pipe_format format) +struct pan_image_block_size +pan_image_renderblock_size(uint64_t modifier, enum pipe_format format) { if (!drm_is_afbc(modifier)) - return panfrost_block_size(modifier, format); + return pan_image_block_size(modifier, format); return pan_afbc_renderblock_size(modifier); } -/* - * Determine the required alignment for the slice offset of an image. For - * now, this is always aligned on 64-byte boundaries. */ -uint32_t -pan_slice_align(uint64_t modifier) -{ - return 64; -} - static inline unsigned format_minimum_alignment(unsigned arch, enum pipe_format format, uint64_t mod) { @@ -127,10 +118,9 @@ format_minimum_alignment(unsigned arch, enum pipe_format format, uint64_t mod) #define CHECKSUM_TILE_HEIGHT 16 #define CHECKSUM_BYTES_PER_TILE 8 -unsigned -panfrost_compute_checksum_size(unsigned arch, - struct pan_image_slice_layout *slice, - unsigned width, unsigned height) +static void +init_slice_crc_info(unsigned arch, struct pan_image_slice_layout *slice, + unsigned width, unsigned height, unsigned offset) { unsigned checksum_region_size = panfrost_meta_tile_size(arch); unsigned checksum_x_tile_per_region = @@ -143,13 +133,13 @@ panfrost_compute_checksum_size(unsigned arch, unsigned tile_count_y = checksum_y_tile_per_region * DIV_ROUND_UP(height, checksum_region_size); + slice->crc.offset = offset; slice->crc.stride = tile_count_x * CHECKSUM_BYTES_PER_TILE; - - return slice->crc.stride * tile_count_y; + slice->crc.size = slice->crc.stride * tile_count_y; } unsigned -panfrost_get_layer_stride(const struct pan_image_layout *layout, unsigned level) +pan_image_surface_stride(const struct pan_image_layout *layout, unsigned level) { if (layout->dim != MALI_TEXTURE_DIMENSION_3D) return layout->array_stride; @@ -164,8 +154,8 @@ pan_image_layout_get_wsi_layout(const struct pan_image_layout *layout, unsigned level) { unsigned row_stride = layout->slices[level].row_stride; - struct pan_block_size block_size = - panfrost_renderblock_size(layout->modifier, layout->format); + struct pan_image_block_size block_size = + pan_image_renderblock_size(layout->modifier, layout->format); if (drm_is_afbc(layout->modifier)) { unsigned width = u_minify(layout->width, level); @@ -178,7 +168,7 @@ pan_image_layout_get_wsi_layout(const struct pan_image_layout *layout, .row_pitch_B = width * util_format_get_blocksize(layout->format), }; } else if (drm_is_afrc(layout->modifier)) { - struct pan_block_size tile_size = + struct pan_image_block_size tile_size = pan_afrc_tile_size(layout->format, layout->modifier); return (struct pan_image_wsi_layout){ @@ -197,16 +187,15 @@ static unsigned wsi_row_pitch_to_row_stride(unsigned wsi_row_pitch, enum pipe_format format, uint64_t modifier) { - struct pan_block_size block_size = - panfrost_renderblock_size(modifier, format); + struct pan_image_block_size block_size = + pan_image_renderblock_size(modifier, format); if (drm_is_afbc(modifier)) { unsigned width = wsi_row_pitch / util_format_get_blocksize(format); return pan_afbc_row_stride(modifier, width); } else if (drm_is_afrc(modifier)) { - struct pan_block_size tile_size = - pan_afrc_tile_size(format, modifier); + struct pan_image_block_size tile_size = pan_afrc_tile_size(format, modifier); return wsi_row_pitch * tile_size.height; } else { @@ -214,12 +203,12 @@ wsi_row_pitch_to_row_stride(unsigned wsi_row_pitch, enum pipe_format format, } } -/* Computes the offset into a texture at a particular level/face. Add to +/* Computes the offset of an image surface at a particular level/face. Add to * the base address of a texture to get the address to that level/face */ unsigned -panfrost_texture_offset(const struct pan_image_layout *layout, unsigned level, - unsigned array_idx, unsigned surface_idx) +pan_image_surface_offset(const struct pan_image_layout *layout, unsigned level, + unsigned array_idx, unsigned surface_idx) { return layout->slices[level].offset + (array_idx * layout->array_stride) + (surface_idx * layout->slices[level].surface_stride); @@ -279,10 +268,10 @@ pan_image_layout_init(unsigned arch, struct pan_image_layout *layout, bool linear = layout->modifier == DRM_FORMAT_MOD_LINEAR; bool is_3d = layout->dim == MALI_TEXTURE_DIMENSION_3D; - struct pan_block_size renderblk_size = - panfrost_renderblock_size(layout->modifier, layout->format); - struct pan_block_size block_size = - panfrost_block_size(layout->modifier, layout->format); + struct pan_image_block_size renderblk_size = + pan_image_renderblock_size(layout->modifier, layout->format); + struct pan_image_block_size block_size = + pan_image_block_size(layout->modifier, layout->format); unsigned width = layout->width; unsigned height = layout->height; @@ -309,7 +298,7 @@ pan_image_layout_init(unsigned arch, struct pan_image_layout *layout, /* Align levels to cache-line as a performance improvement for * linear/tiled and as a requirement for AFBC */ - offset = ALIGN_POT(offset, pan_slice_align(layout->modifier)); + offset = ALIGN_POT(offset, pan_image_slice_align(layout->modifier)); slice->offset = offset; @@ -388,10 +377,7 @@ pan_image_layout_init(unsigned arch, struct pan_image_layout *layout, /* Add a checksum region if necessary */ if (layout->crc) { - slice->crc.size = - panfrost_compute_checksum_size(arch, slice, width, height); - - slice->crc.offset = offset; + init_slice_crc_info(arch, slice, width, height, offset); offset += slice->crc.size; slice->size += slice->crc.size; } @@ -411,53 +397,3 @@ pan_image_layout_init(unsigned arch, struct pan_image_layout *layout, return true; } - -void -pan_iview_get_surface(const struct pan_image_view *iview, unsigned level, - unsigned layer, unsigned sample, struct pan_surface *surf) -{ - const struct util_format_description *fdesc = - util_format_description(iview->format); - - - /* In case of multiplanar depth/stencil, the stencil is always on - * plane 1. Combined depth/stencil only has one plane, so depth - * will be on plane 0 in either case. - */ - const struct pan_image *image = util_format_has_stencil(fdesc) - ? pan_image_view_get_s_plane(iview) - : pan_image_view_get_plane(iview, 0); - - level += iview->first_level; - assert(level < image->layout.nr_slices); - - layer += iview->first_layer; - - bool is_3d = image->layout.dim == MALI_TEXTURE_DIMENSION_3D; - const struct pan_image_slice_layout *slice = &image->layout.slices[level]; - uint64_t base = image->data.base + image->data.offset; - - if (drm_is_afbc(image->layout.modifier)) { - assert(!sample); - - if (is_3d) { - ASSERTED unsigned depth = u_minify(image->layout.depth, level); - assert(layer < depth); - surf->afbc.header = - base + slice->offset + (layer * slice->afbc.surface_stride); - surf->afbc.body = base + slice->offset + slice->afbc.header_size + - (slice->surface_stride * layer); - } else { - assert(layer < image->layout.array_size); - surf->afbc.header = - base + panfrost_texture_offset(&image->layout, level, layer, 0); - surf->afbc.body = surf->afbc.header + slice->afbc.header_size; - } - } else { - unsigned array_idx = is_3d ? 0 : layer; - unsigned surface_idx = is_3d ? layer : sample; - - surf->data = base + panfrost_texture_offset(&image->layout, level, - array_idx, surface_idx); - } -} diff --git a/src/panfrost/lib/pan_layout.h b/src/panfrost/lib/pan_layout.h new file mode 100644 index 00000000000..69a96db11bb --- /dev/null +++ b/src/panfrost/lib/pan_layout.h @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2008 VMware, Inc. + * Copyright (C) 2014 Broadcom + * Copyright (C) 2018-2019 Alyssa Rosenzweig + * Copyright (C) 2019-2020 Collabora, Ltd. + * + * SPDX-License-Identifier: MIT + */ + +#ifndef __PAN_LAYOUT_H +#define __PAN_LAYOUT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include "genxml/gen_macros.h" + +#define MAX_MIP_LEVELS 17 +#define MAX_IMAGE_PLANES 3 + +struct pan_image_slice_layout { + unsigned offset; + + /* For AFBC images, the number of bytes between two rows of AFBC + * headers. + * + * For non-AFBC images, the number of bytes between two rows of texels. + * For linear images, this will equal the logical stride. For + * images that are compressed or interleaved, this will be greater than + * the logical stride. + */ + unsigned row_stride; + + unsigned surface_stride; + + struct { + /* Stride in number of superblocks */ + unsigned stride; + + /* Number of superblocks */ + unsigned nr_blocks; + + /* Size of the AFBC header preceding each slice */ + unsigned header_size; + + /* Size of the AFBC body */ + unsigned body_size; + + /* Stride between AFBC headers of two consecutive surfaces. + * For 3D textures, this must be set to header size since + * AFBC headers are allocated together, for 2D arrays this + * should be set to size0, since AFBC headers are placed at + * the beginning of each layer + */ + unsigned surface_stride; + } afbc; + + /* If checksumming is enabled following the slice, what + * is its offset/stride? */ + struct { + unsigned offset; + unsigned stride; + unsigned size; + } crc; + + unsigned size; +}; + +struct pan_image_layout { + uint64_t modifier; + enum pipe_format format; + unsigned width, height, depth; + unsigned nr_samples; + enum mali_texture_dimension dim; + unsigned nr_slices; + unsigned array_size; + bool crc; + + /* The remaining fields may be derived from the above by calling + * pan_image_layout_init + */ + + struct pan_image_slice_layout slices[MAX_MIP_LEVELS]; + + uint64_t data_size; + uint64_t array_stride; +}; + +struct pan_image_wsi_layout { + unsigned offset_B; + unsigned row_pitch_B; +}; + +/* + * Represents the block size of a single plane. For AFBC, this represents the + * superblock size. For u-interleaving, this represents the tile size. + */ +struct pan_image_block_size { + /** Width of block */ + unsigned width; + + /** Height of blocks */ + unsigned height; +}; + +/* + * Determine the required alignment for the slice offset of an image. For + * now, this is always aligned on 64-byte boundaries. */ +static inline uint32_t +pan_image_slice_align(uint64_t modifier) +{ + return 64; +} + +struct pan_image_block_size pan_image_block_size(uint64_t modifier, + enum pipe_format format); + +struct pan_image_block_size pan_image_renderblock_size(uint64_t modifier, + enum pipe_format format); + +unsigned pan_image_surface_stride(const struct pan_image_layout *layout, + unsigned level); + +unsigned pan_image_surface_offset(const struct pan_image_layout *layout, + unsigned level, unsigned array_idx, + unsigned surface_idx); + +bool +pan_image_layout_init(unsigned arch, struct pan_image_layout *layout, + const struct pan_image_wsi_layout *wsi_layout); + +struct pan_image_wsi_layout +pan_image_layout_get_wsi_layout(const struct pan_image_layout *layout, + unsigned level); + +#ifdef __cplusplus +} /* extern C */ +#endif + +#endif diff --git a/src/panfrost/lib/pan_texture.c b/src/panfrost/lib/pan_texture.c index 30ee0106a73..3eac1ff4f40 100644 --- a/src/panfrost/lib/pan_texture.c +++ b/src/panfrost/lib/pan_texture.c @@ -26,11 +26,15 @@ * */ -#include "pan_afbc.h" -#include "pan_afrc.h" #include "pan_texture.h" #include "util/macros.h" #include "util/u_math.h" +#include "pan_afbc.h" +#include "pan_afrc.h" +#include "pan_format.h" +#include "pan_image.h" +#include "pan_pool.h" +#include "pan_util.h" #if PAN_ARCH >= 5 /* @@ -39,7 +43,7 @@ * 6-bit tag on the payload pointer. Map the block size for a single dimension. */ static inline enum mali_astc_2d_dimension -panfrost_astc_dim_2d(unsigned dim) +pan_astc_dim_2d(unsigned dim) { switch (dim) { case 4: @@ -60,7 +64,7 @@ panfrost_astc_dim_2d(unsigned dim) } static inline enum mali_astc_3d_dimension -panfrost_astc_dim_3d(unsigned dim) +pan_astc_dim_3d(unsigned dim) { switch (dim) { case 3: @@ -83,8 +87,8 @@ panfrost_astc_dim_3d(unsigned dim) * For ASTC, this is a "stretch factor" encoding the block size. */ static unsigned -panfrost_compression_tag(const struct util_format_description *desc, - enum mali_texture_dimension dim, uint64_t modifier) +pan_compression_tag(const struct util_format_description *desc, + enum mali_texture_dimension dim, uint64_t modifier) { #if PAN_ARCH >= 5 && PAN_ARCH <= 8 if (drm_is_afbc(modifier)) { @@ -119,12 +123,12 @@ panfrost_compression_tag(const struct util_format_description *desc, return flags; } else if (desc->layout == UTIL_FORMAT_LAYOUT_ASTC) { if (desc->block.depth > 1) { - return (panfrost_astc_dim_3d(desc->block.depth) << 4) | - (panfrost_astc_dim_3d(desc->block.height) << 2) | - panfrost_astc_dim_3d(desc->block.width); + return (pan_astc_dim_3d(desc->block.depth) << 4) | + (pan_astc_dim_3d(desc->block.height) << 2) | + pan_astc_dim_3d(desc->block.width); } else { - return (panfrost_astc_dim_2d(desc->block.height) << 3) | - panfrost_astc_dim_2d(desc->block.width); + return (pan_astc_dim_2d(desc->block.height) << 3) | + pan_astc_dim_2d(desc->block.width); } } #endif @@ -136,7 +140,7 @@ panfrost_compression_tag(const struct util_format_description *desc, /* Following the texture descriptor is a number of descriptors. How many? */ static unsigned -panfrost_texture_num_elements(const struct pan_image_view *iview) +pan_texture_num_elements(const struct pan_image_view *iview) { unsigned levels = 1 + iview->last_level - iview->first_level; unsigned layers = 1 + iview->last_layer - iview->first_layer; @@ -152,7 +156,7 @@ panfrost_texture_num_elements(const struct pan_image_view *iview) * as an allocation amount */ unsigned -GENX(panfrost_estimate_texture_payload_size)(const struct pan_image_view *iview) +GENX(pan_texture_estimate_payload_size)(const struct pan_image_view *iview) { size_t element_size; @@ -172,14 +176,14 @@ GENX(panfrost_estimate_texture_payload_size)(const struct pan_image_view *iview) element_size = pan_size(SURFACE_WITH_STRIDE); #endif - unsigned elements = panfrost_texture_num_elements(iview); + unsigned elements = pan_texture_num_elements(iview); return element_size * elements; } static void -panfrost_get_surface_strides(const struct pan_image_layout *layout, unsigned l, - int32_t *row_stride, int32_t *surf_stride) +pan_get_surface_strides(const struct pan_image_layout *layout, unsigned l, + int32_t *row_stride, int32_t *surf_stride) { const struct pan_image_slice_layout *slice = &layout->slices[l]; @@ -195,18 +199,18 @@ panfrost_get_surface_strides(const struct pan_image_layout *layout, unsigned l, } static uint64_t -panfrost_get_surface_pointer(const struct pan_image_layout *layout, - enum mali_texture_dimension dim, uint64_t base, - unsigned l, unsigned i, unsigned s) +pan_get_surface_pointer(const struct pan_image_layout *layout, + enum mali_texture_dimension dim, uint64_t base, + unsigned l, unsigned i, unsigned s) { unsigned offset; if (layout->dim == MALI_TEXTURE_DIMENSION_3D) { assert(!s); offset = - layout->slices[l].offset + i * panfrost_get_layer_stride(layout, l); + layout->slices[l].offset + i * pan_image_surface_stride(layout, l); } else { - offset = panfrost_texture_offset(layout, l, i, s); + offset = pan_image_surface_offset(layout, l, i, s); } return base + offset; @@ -237,24 +241,24 @@ get_image_section_info(const struct pan_image_view *iview, assert(PAN_ARCH >= 5 || !drm_is_afbc(plane->layout.modifier)); assert(PAN_ARCH >= 5 || desc->layout != UTIL_FORMAT_LAYOUT_ASTC); - /* panfrost_compression_tag() wants the dimension of the resource, not the + /* pan_compression_tag() wants the dimension of the resource, not the * one of the image view (those might differ). */ - unsigned tag = panfrost_compression_tag(desc, plane->layout.dim, - plane->layout.modifier); + unsigned tag = + pan_compression_tag(desc, plane->layout.dim, plane->layout.modifier); - info.pointer = panfrost_get_surface_pointer( - &plane->layout, iview->dim, base | tag, level, index, sample); - panfrost_get_surface_strides(&plane->layout, level, &info.row_stride, - &info.surface_stride); + info.pointer = pan_get_surface_pointer(&plane->layout, iview->dim, + base | tag, level, index, sample); + pan_get_surface_strides(&plane->layout, level, &info.row_stride, + &info.surface_stride); return info; } #if PAN_ARCH <= 7 static void -panfrost_emit_surface_with_stride(const struct pan_image_section_info *section, - void **payload) +pan_emit_surface_with_stride(const struct pan_image_section_info *section, + void **payload) { pan_cast_and_pack(*payload, SURFACE_WITH_STRIDE, cfg) { cfg.pointer = section->pointer; @@ -267,8 +271,8 @@ panfrost_emit_surface_with_stride(const struct pan_image_section_info *section, #if PAN_ARCH == 7 static void -panfrost_emit_multiplanar_surface(const struct pan_image_section_info *sections, - void **payload) +pan_emit_multiplanar_surface(const struct pan_image_section_info *sections, + void **payload) { assert(sections[2].row_stride == 0 || sections[1].row_stride == sections[2].row_stride); @@ -360,7 +364,7 @@ static enum mali_clump_format special_clump_formats[PIPE_FORMAT_COUNT] = { /* clang-format on */ static enum mali_clump_format -panfrost_clump_format(enum pipe_format format) +pan_clump_format(enum pipe_format format) { /* First, try a special clump format. Note that the 0 encoding is for a * raw clump format, which will never be in the special table. @@ -434,15 +438,16 @@ translate_superblock_size(uint64_t modifier) } static void -panfrost_emit_plane(const struct pan_image_view *iview, - const struct pan_image_section_info *sections, - int plane_index, unsigned level, void **payload) +pan_emit_plane(const struct pan_image_view *iview, + const struct pan_image_section_info *sections, int plane_index, + unsigned level, void **payload) { const struct util_format_description *desc = util_format_description(iview->format); - const struct pan_image *plane = util_format_has_stencil(desc) - ? pan_image_view_get_s_plane(iview) - : pan_image_view_get_plane(iview, plane_index); + const struct pan_image *plane = + util_format_has_stencil(desc) + ? pan_image_view_get_s_plane(iview) + : pan_image_view_get_plane(iview, plane_index); const struct pan_image_layout *layout = &plane->layout; int32_t row_stride = sections[plane_index].row_stride; int32_t surface_stride = sections[plane_index].surface_stride; @@ -484,7 +489,7 @@ panfrost_emit_plane(const struct pan_image_view *iview, } else if (!panfrost_format_is_yuv(layout->format)) { cfg.slice_stride = layout->nr_samples > 1 ? surface_stride - : panfrost_get_layer_stride(layout, level); + : pan_image_surface_stride(layout, level); } if (desc->layout == UTIL_FORMAT_LAYOUT_ASTC) { @@ -493,15 +498,13 @@ panfrost_emit_plane(const struct pan_image_view *iview, if (desc->block.depth > 1) { cfg.plane_type = MALI_PLANE_TYPE_ASTC_3D; - cfg.astc._3d.block_width = panfrost_astc_dim_3d(desc->block.width); - cfg.astc._3d.block_height = - panfrost_astc_dim_3d(desc->block.height); - cfg.astc._3d.block_depth = panfrost_astc_dim_3d(desc->block.depth); + cfg.astc._3d.block_width = pan_astc_dim_3d(desc->block.width); + cfg.astc._3d.block_height = pan_astc_dim_3d(desc->block.height); + cfg.astc._3d.block_depth = pan_astc_dim_3d(desc->block.depth); } else { cfg.plane_type = MALI_PLANE_TYPE_ASTC_2D; - cfg.astc._2d.block_width = panfrost_astc_dim_2d(desc->block.width); - cfg.astc._2d.block_height = - panfrost_astc_dim_2d(desc->block.height); + cfg.astc._2d.block_width = pan_astc_dim_2d(desc->block.width); + cfg.astc._2d.block_height = pan_astc_dim_2d(desc->block.height); } bool srgb = (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB); @@ -538,7 +541,7 @@ panfrost_emit_plane(const struct pan_image_view *iview, } else { cfg.plane_type = is_chroma_2p ? MALI_PLANE_TYPE_CHROMA_2P : MALI_PLANE_TYPE_GENERIC; - cfg.clump_format = panfrost_clump_format(iview->format); + cfg.clump_format = pan_clump_format(iview->format); } if (!afbc && !afrc) { @@ -553,8 +556,8 @@ panfrost_emit_plane(const struct pan_image_view *iview, #endif static void -panfrost_emit_surface(const struct pan_image_view *iview, unsigned level, - unsigned index, unsigned sample, void **payload) +pan_emit_surface(const struct pan_image_view *iview, unsigned level, + unsigned index, unsigned sample, void **payload) { #if PAN_ARCH == 7 || PAN_ARCH >= 9 if (panfrost_format_is_yuv(iview->format)) { @@ -575,19 +578,19 @@ panfrost_emit_surface(const struct pan_image_view *iview, unsigned level, #if PAN_ARCH >= 9 /* 3-plane YUV is submitted using two PLANE descriptors, where the * second one is of type CHROMA_2P */ - panfrost_emit_plane(iview, sections, 0, level, payload); + pan_emit_plane(iview, sections, 0, level, payload); if (plane_count > 1) { /* 3-plane YUV requires equal stride for both chroma planes */ assert(plane_count == 2 || sections[1].row_stride == sections[2].row_stride); - panfrost_emit_plane(iview, sections, 1, level, payload); + pan_emit_plane(iview, sections, 1, level, payload); } #else if (plane_count > 1) - panfrost_emit_multiplanar_surface(sections, payload); + pan_emit_multiplanar_surface(sections, payload); else - panfrost_emit_surface_with_stride(sections, payload); + pan_emit_surface_with_stride(sections, payload); #endif return; } @@ -610,14 +613,14 @@ panfrost_emit_surface(const struct pan_image_view *iview, unsigned level, }; #if PAN_ARCH >= 9 - panfrost_emit_plane(iview, section, 0, level, payload); + pan_emit_plane(iview, section, 0, level, payload); #else - panfrost_emit_surface_with_stride(section, payload); + pan_emit_surface_with_stride(section, payload); #endif } static void -panfrost_emit_texture_payload(const struct pan_image_view *iview, void *payload) +pan_emit_texture_payload(const struct pan_image_view *iview, void *payload) { unsigned nr_samples = PAN_ARCH <= 7 ? pan_image_view_get_nr_samples(iview) : 1; @@ -632,8 +635,9 @@ panfrost_emit_texture_payload(const struct pan_image_view *iview, void *payload) /* V7 and later treats faces as extra layers */ for (int layer = iview->first_layer; layer <= iview->last_layer; ++layer) { for (int sample = 0; sample < nr_samples; ++sample) { - for (int level = iview->first_level; level <= iview->last_level; ++level) { - panfrost_emit_surface(iview, level, layer, sample, &payload); + for (int level = iview->first_level; level <= iview->last_level; + ++level) { + pan_emit_surface(iview, level, layer, sample, &payload); } } } @@ -649,14 +653,15 @@ panfrost_emit_texture_payload(const struct pan_image_view *iview, void *payload) /* V6 and earlier has a different memory-layout */ for (int layer = first_layer; layer <= last_layer; ++layer) { - for (int level = iview->first_level; level <= iview->last_level; ++level) { + for (int level = iview->first_level; level <= iview->last_level; + ++level) { /* order of face and sample doesn't matter; we can only have multiple * of one or the other (no support for multisampled cubemaps) */ for (int face = 0; face < face_count; ++face) { for (int sample = 0; sample < nr_samples; ++sample) { - panfrost_emit_surface(iview, level, (face_count * layer) + face, - sample, &payload); + pan_emit_surface(iview, level, (face_count * layer) + face, + sample, &payload); } } } @@ -668,7 +673,7 @@ panfrost_emit_texture_payload(const struct pan_image_view *iview, void *payload) /* Map modifiers to mali_texture_layout for packing in a texture descriptor */ static enum mali_texture_layout -panfrost_modifier_to_layout(uint64_t modifier) +pan_modifier_to_layout(uint64_t modifier) { if (drm_is_afbc(modifier)) return MALI_TEXTURE_LAYOUT_AFBC; @@ -683,7 +688,7 @@ panfrost_modifier_to_layout(uint64_t modifier) #if PAN_ARCH >= 7 void -GENX(panfrost_texture_swizzle_replicate_x)(struct pan_image_view *iview) +GENX(pan_texture_swizzle_replicate_x)(struct pan_image_view *iview) { /* v7+ doesn't have an _RRRR component order, combine the * user swizzle with a .XXXX swizzle to emulate that. */ @@ -702,7 +707,7 @@ GENX(panfrost_texture_swizzle_replicate_x)(struct pan_image_view *iview) #if PAN_ARCH == 7 void -GENX(panfrost_texture_afbc_reswizzle)(struct pan_image_view *iview) +GENX(pan_texture_afbc_reswizzle)(struct pan_image_view *iview) { /* v7 (only) restricts component orders when AFBC is in use. * Rather than restrict AFBC for all non-canonical component orders, we use @@ -793,9 +798,9 @@ panfrost_texture_get_extent(const struct pan_image_view *iview, * consists of a 32-byte header followed by pointers. */ void -GENX(panfrost_new_texture)(const struct pan_image_view *iview, - struct mali_texture_packed *out, - const struct panfrost_ptr *payload) +GENX(pan_texture_emit)(const struct pan_image_view *iview, + struct mali_texture_packed *out, + const struct panfrost_ptr *payload) { const struct util_format_description *desc = util_format_description(iview->format); @@ -809,7 +814,7 @@ GENX(panfrost_new_texture)(const struct pan_image_view *iview, mali_format = MALI_PACK_FMT(RGBA8_UNORM, RGBA, L); } - panfrost_emit_texture_payload(iview, payload->cpu); + pan_emit_texture_payload(iview, payload->cpu); unsigned array_size = panfrost_texture_get_array_size(iview); @@ -830,7 +835,7 @@ GENX(panfrost_new_texture)(const struct pan_image_view *iview, cfg.texel_interleave = (layout->modifier != DRM_FORMAT_MOD_LINEAR) || util_format_is_compressed(iview->format); #else - cfg.texel_ordering = panfrost_modifier_to_layout(layout->modifier); + cfg.texel_ordering = pan_modifier_to_layout(layout->modifier); #endif cfg.levels = iview->last_level - iview->first_level + 1; cfg.array_size = array_size; @@ -849,9 +854,9 @@ GENX(panfrost_new_texture)(const struct pan_image_view *iview, #if PAN_ARCH >= 9 void -GENX(panfrost_new_storage_texture)(const struct pan_image_view *iview, - struct mali_texture_packed *out, - const struct panfrost_ptr *payload) +GENX(pan_storage_texture_emit)(const struct pan_image_view *iview, + struct mali_texture_packed *out, + const struct panfrost_ptr *payload) { const struct util_format_description *desc = util_format_description(iview->format); @@ -869,7 +874,7 @@ GENX(panfrost_new_storage_texture)(const struct pan_image_view *iview, mali_format = MALI_PACK_FMT(RGBA8_UNORM, RGBA, L); } - panfrost_emit_texture_payload(iview, payload->cpu); + pan_emit_texture_payload(iview, payload->cpu); unsigned array_size = panfrost_texture_get_array_size(iview); diff --git a/src/panfrost/lib/pan_texture.h b/src/panfrost/lib/pan_texture.h index 885e0df0b7c..20cf4bc7369 100644 --- a/src/panfrost/lib/pan_texture.h +++ b/src/panfrost/lib/pan_texture.h @@ -28,310 +28,34 @@ #ifndef __PAN_TEXTURE_H #define __PAN_TEXTURE_H -#include "genxml/gen_macros.h" - -#include -#include "compiler/shader_enums.h" -#include "drm-uapi/drm_fourcc.h" -#include "genxml/gen_macros.h" -#include "util/format/u_format.h" -#include "pan_format.h" -#include "pan_pool.h" -#include "pan_props.h" -#include "pan_util.h" - -#ifdef __cplusplus -extern "C" { +#ifndef PAN_ARCH +#error "PAN_ARCH must be defined" #endif -#define MAX_MIP_LEVELS 17 -#define MAX_IMAGE_PLANES 3 +#include "pan_image.h" -struct pan_image_slice_layout { - unsigned offset; - - /* For AFBC images, the number of bytes between two rows of AFBC - * headers. - * - * For non-AFBC images, the number of bytes between two rows of texels. - * For linear images, this will equal the logical stride. For - * images that are compressed or interleaved, this will be greater than - * the logical stride. - */ - unsigned row_stride; - - unsigned surface_stride; - - struct { - /* Stride in number of superblocks */ - unsigned stride; - - /* Number of superblocks */ - unsigned nr_blocks; - - /* Size of the AFBC header preceding each slice */ - unsigned header_size; - - /* Size of the AFBC body */ - unsigned body_size; - - /* Stride between AFBC headers of two consecutive surfaces. - * For 3D textures, this must be set to header size since - * AFBC headers are allocated together, for 2D arrays this - * should be set to size0, since AFBC headers are placed at - * the beginning of each layer - */ - unsigned surface_stride; - } afbc; - - /* If checksumming is enabled following the slice, what - * is its offset/stride? */ - struct { - unsigned offset; - unsigned stride; - unsigned size; - } crc; - - unsigned size; -}; - -struct pan_image_layout { - uint64_t modifier; - enum pipe_format format; - unsigned width, height, depth; - unsigned nr_samples; - enum mali_texture_dimension dim; - unsigned nr_slices; - unsigned array_size; - bool crc; - - /* The remaining fields may be derived from the above by calling - * pan_image_layout_init - */ - - struct pan_image_slice_layout slices[MAX_MIP_LEVELS]; - - uint64_t data_size; - uint64_t array_stride; -}; - -struct pan_image_mem { - uint64_t base; - unsigned offset; -}; - -struct pan_image { - struct pan_image_mem data; - struct pan_image_layout layout; -}; - -struct pan_image_view { - /* Format, dimension and sample count of the view might differ from - * those of the image (2D view of a 3D image surface for instance). - */ - enum pipe_format format; - enum mali_texture_dimension dim; - unsigned first_level, last_level; - unsigned first_layer, last_layer; - unsigned char swizzle[4]; - - /* planes 1 and 2 are NULL for single plane formats */ - const struct pan_image *planes[MAX_IMAGE_PLANES]; - - /* If EXT_multisampled_render_to_texture is used, this may be - * greater than image->layout.nr_samples. */ - unsigned nr_samples; - - /* Only valid if dim == 1D, needed to implement buffer views */ - struct { - unsigned offset; - unsigned size; - } buf; - - struct { - unsigned narrow; - } astc; -}; - -static inline const struct pan_image * -pan_image_view_get_plane(const struct pan_image_view *iview, uint32_t idx) -{ - if (idx >= ARRAY_SIZE(iview->planes)) - return NULL; - - return iview->planes[idx]; -} - -static inline unsigned -pan_image_view_get_plane_mask(const struct pan_image_view *iview) -{ - unsigned mask = 0; - - for (unsigned i = 0; i < ARRAY_SIZE(iview->planes); i++) { - if (iview->planes[i]) - mask |= BITFIELD_BIT(i); - } - - return mask; -} - -static inline unsigned -pan_image_view_get_first_plane_idx(const struct pan_image_view *iview) -{ - unsigned mask = pan_image_view_get_plane_mask(iview); - - assert(mask); - return ffs(mask) - 1; -} - -static inline const struct pan_image * -pan_image_view_get_first_plane(const struct pan_image_view *iview) -{ - unsigned first_plane_idx = pan_image_view_get_first_plane_idx(iview); - return pan_image_view_get_plane(iview, first_plane_idx); -} - -static inline uint32_t -pan_image_view_get_nr_samples(const struct pan_image_view *iview) -{ - const struct pan_image *image = pan_image_view_get_first_plane(iview); - - if (!image) - return 0; - - return image->layout.nr_samples; -} - -static inline const struct pan_image * -pan_image_view_get_color_plane(const struct pan_image_view *iview) -{ - /* We only support rendering to plane 0 */ - assert(pan_image_view_get_plane(iview, 1) == NULL); - return pan_image_view_get_plane(iview, 0); -} - -static inline bool -pan_image_view_has_crc(const struct pan_image_view *iview) -{ - const struct pan_image *image = pan_image_view_get_color_plane(iview); - - if (!image) - return false; - - return image->layout.crc; -} - -static inline const struct pan_image * -pan_image_view_get_s_plane(const struct pan_image_view *iview) -{ - ASSERTED const struct util_format_description *fdesc = - util_format_description(iview->format); - assert(util_format_has_stencil(fdesc)); - - /* In case of multiplanar depth/stencil, the stencil is always on - * plane 1. Combined depth/stencil only has one plane, so depth - * will be on plane 0 in either case. - */ - const struct pan_image *plane = iview->planes[1] ?: iview->planes[0]; - - assert(plane); - fdesc = util_format_description(plane->layout.format); - assert(util_format_has_stencil(fdesc)); - return plane; -} - -static inline const struct pan_image * -pan_image_view_get_zs_plane(const struct pan_image_view *iview) -{ - assert(util_format_is_depth_or_stencil(iview->format)); - - /* Depth or combined depth-stencil is always on plane 0. */ - return pan_image_view_get_plane(iview, 0); -} - -unsigned panfrost_compute_checksum_size(unsigned arch, - struct pan_image_slice_layout *slice, - unsigned width, unsigned height); - -/* - * Represents the block size of a single plane. For AFBC, this represents the - * superblock size. For u-interleaving, this represents the tile size. - */ -struct pan_block_size { - /** Width of block */ - unsigned width; - - /** Height of blocks */ - unsigned height; -}; - -uint32_t pan_slice_align(uint64_t modifier); - -struct pan_block_size panfrost_block_size(uint64_t modifier, - enum pipe_format format); - -struct pan_block_size panfrost_renderblock_size(uint64_t modifier, - enum pipe_format format); - -#ifdef PAN_ARCH -unsigned GENX(panfrost_estimate_texture_payload_size)( - const struct pan_image_view *iview); +struct panfrost_ptr; +struct mali_texture_packed; #if PAN_ARCH >= 7 -void GENX(panfrost_texture_swizzle_replicate_x)(struct pan_image_view *iview); +void GENX(pan_texture_swizzle_replicate_x)(struct pan_image_view *iview); #endif #if PAN_ARCH == 7 -void GENX(panfrost_texture_afbc_reswizzle)(struct pan_image_view *iview); +void GENX(pan_texture_afbc_reswizzle)(struct pan_image_view *iview); #endif -void GENX(panfrost_new_texture)(const struct pan_image_view *iview, - struct mali_texture_packed *out, - const struct panfrost_ptr *payload); +unsigned +GENX(pan_texture_estimate_payload_size)(const struct pan_image_view *iview); + +void GENX(pan_texture_emit)(const struct pan_image_view *iview, + struct mali_texture_packed *out, + const struct panfrost_ptr *payload); #if PAN_ARCH >= 9 -void GENX(panfrost_new_storage_texture)(const struct pan_image_view *iview, - struct mali_texture_packed *out, - const struct panfrost_ptr *payload); -#endif -#endif - -unsigned panfrost_get_layer_stride(const struct pan_image_layout *layout, - unsigned level); - -unsigned panfrost_texture_offset(const struct pan_image_layout *layout, - unsigned level, unsigned array_idx, - unsigned surface_idx); - -struct pan_image_wsi_layout { - unsigned offset_B; - unsigned row_pitch_B; -}; - -bool -pan_image_layout_init(unsigned arch, struct pan_image_layout *layout, - const struct pan_image_wsi_layout *wsi_layout); - -struct pan_image_wsi_layout -pan_image_layout_get_wsi_layout(const struct pan_image_layout *layout, - unsigned level); - -struct pan_surface { - union { - uint64_t data; - struct { - uint64_t header; - uint64_t body; - } afbc; - }; -}; - -void pan_iview_get_surface(const struct pan_image_view *iview, unsigned level, - unsigned layer, unsigned sample, - struct pan_surface *surf); - -#ifdef __cplusplus -} /* extern C */ +void GENX(pan_storage_texture_emit)(const struct pan_image_view *iview, + struct mali_texture_packed *out, + const struct panfrost_ptr *payload); #endif #endif diff --git a/src/panfrost/lib/pan_util.c b/src/panfrost/lib/pan_util.c index 143c54d7f20..feb1211bc78 100644 --- a/src/panfrost/lib/pan_util.c +++ b/src/panfrost/lib/pan_util.c @@ -22,7 +22,7 @@ */ #include -#include "pan_texture.h" +#include "pan_util.h" /* Translate a PIPE swizzle quad to a 12-bit Mali swizzle code. PIPE * swizzles line up with Mali swizzles for the XYZW01, but PIPE swizzles have diff --git a/src/panfrost/lib/tests/test-clear.c b/src/panfrost/lib/tests/test-clear.c index cf864c4c78a..ab2fca12397 100644 --- a/src/panfrost/lib/tests/test-clear.c +++ b/src/panfrost/lib/tests/test-clear.c @@ -21,7 +21,7 @@ * SOFTWARE. */ -#include "pan_texture.h" +#include "pan_image.h" #include "pan_util.h" /* A test consists of a render target format, clear colour, dither state, and diff --git a/src/panfrost/lib/tests/test-layout.cpp b/src/panfrost/lib/tests/test-layout.cpp index d90f18be9e8..d4c187994dd 100644 --- a/src/panfrost/lib/tests/test-layout.cpp +++ b/src/panfrost/lib/tests/test-layout.cpp @@ -22,7 +22,7 @@ */ #include "pan_afbc.h" -#include "pan_texture.h" +#include "pan_image.h" #include @@ -33,8 +33,8 @@ TEST(BlockSize, Linear) PIPE_FORMAT_ASTC_5x5}; for (unsigned i = 0; i < ARRAY_SIZE(format); ++i) { - struct pan_block_size blk = - panfrost_block_size(DRM_FORMAT_MOD_LINEAR, format[i]); + struct pan_image_block_size blk = + pan_image_block_size(DRM_FORMAT_MOD_LINEAR, format[i]); EXPECT_EQ(blk.width, 1); EXPECT_EQ(blk.height, 1); @@ -49,7 +49,7 @@ TEST(BlockSize, UInterleavedRegular) }; for (unsigned i = 0; i < ARRAY_SIZE(format); ++i) { - struct pan_block_size blk = panfrost_block_size( + struct pan_image_block_size blk = pan_image_block_size( DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED, format[i]); EXPECT_EQ(blk.width, 16); @@ -62,7 +62,7 @@ TEST(BlockSize, UInterleavedBlockCompressed) enum pipe_format format[] = {PIPE_FORMAT_ETC2_RGB8, PIPE_FORMAT_ASTC_5x5}; for (unsigned i = 0; i < ARRAY_SIZE(format); ++i) { - struct pan_block_size blk = panfrost_block_size( + struct pan_image_block_size blk = pan_image_block_size( DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED, format[i]); EXPECT_EQ(blk.width, 4); @@ -81,7 +81,8 @@ TEST(BlockSize, AFBCFormatInvariant16x16) AFBC_FORMAT_MOD_SPARSE | AFBC_FORMAT_MOD_YTR); for (unsigned i = 0; i < ARRAY_SIZE(format); ++i) { - struct pan_block_size blk = panfrost_block_size(modifier, format[i]); + struct pan_image_block_size blk = + pan_image_block_size(modifier, format[i]); EXPECT_EQ(blk.width, 16); EXPECT_EQ(blk.height, 16); @@ -99,7 +100,8 @@ TEST(BlockSize, AFBCFormatInvariant32x8) AFBC_FORMAT_MOD_SPARSE | AFBC_FORMAT_MOD_YTR); for (unsigned i = 0; i < ARRAY_SIZE(format); ++i) { - struct pan_block_size blk = panfrost_block_size(modifier, format[i]); + struct pan_image_block_size blk = + pan_image_block_size(modifier, format[i]); EXPECT_EQ(blk.width, 32); EXPECT_EQ(blk.height, 8); diff --git a/src/panfrost/vulkan/panvk_buffer.c b/src/panfrost/vulkan/panvk_buffer.c index 7d279cb47b5..06a01cda9cc 100644 --- a/src/panfrost/vulkan/panvk_buffer.c +++ b/src/panfrost/vulkan/panvk_buffer.c @@ -8,6 +8,8 @@ #include "panvk_device_memory.h" #include "panvk_entrypoints.h" +#include "pan_props.h" + #include "vk_log.h" #define PANVK_MAX_BUFFER_SIZE (1 << 30) diff --git a/src/panfrost/vulkan/panvk_image.h b/src/panfrost/vulkan/panvk_image.h index 27be14d5983..7b8fceb28ab 100644 --- a/src/panfrost/vulkan/panvk_image.h +++ b/src/panfrost/vulkan/panvk_image.h @@ -8,7 +8,7 @@ #include "vk_image.h" -#include "pan_texture.h" +#include "pan_image.h" #define PANVK_MAX_PLANES 3 diff --git a/src/panfrost/vulkan/panvk_vX_buffer_view.c b/src/panfrost/vulkan/panvk_vX_buffer_view.c index a9dbfe18588..feef46a6842 100644 --- a/src/panfrost/vulkan/panvk_vX_buffer_view.c +++ b/src/panfrost/vulkan/panvk_vX_buffer_view.c @@ -18,6 +18,8 @@ #include "panvk_priv_bo.h" #include "pan_afbc.h" +#include "pan_props.h" +#include "pan_texture.h" #include "vk_format.h" #include "vk_log.h" @@ -97,14 +99,14 @@ panvk_per_arch(CreateBufferView)(VkDevice _device, if (!util_format_is_depth_or_stencil(pfmt) && !panfrost_format_is_yuv(pfmt) && pan_format_supports_afbc(PAN_ARCH, pfmt)) - GENX(panfrost_texture_afbc_reswizzle)(&pview); + GENX(pan_texture_afbc_reswizzle)(&pview); #endif pan_image_layout_init(arch, &plane.layout, NULL); struct panvk_pool_alloc_info alloc_info = { .alignment = pan_alignment(TEXTURE), - .size = GENX(panfrost_estimate_texture_payload_size)(&pview), + .size = GENX(pan_texture_estimate_payload_size)(&pview), }; view->mem = panvk_pool_alloc_mem(&device->mempools.rw, alloc_info); @@ -114,7 +116,7 @@ panvk_per_arch(CreateBufferView)(VkDevice _device, .cpu = panvk_priv_mem_host_addr(view->mem), }; - GENX(panfrost_new_texture)(&pview, &view->descs.tex, &ptr); + GENX(pan_texture_emit)(&pview, &view->descs.tex, &ptr); } #if PAN_ARCH <= 7 diff --git a/src/panfrost/vulkan/panvk_vX_cmd_draw.c b/src/panfrost/vulkan/panvk_vX_cmd_draw.c index 57c63546a12..3815ac7df86 100644 --- a/src/panfrost/vulkan/panvk_vX_cmd_draw.c +++ b/src/panfrost/vulkan/panvk_vX_cmd_draw.c @@ -11,6 +11,7 @@ #include "panvk_entrypoints.h" #include "pan_desc.h" +#include "pan_util.h" static void render_state_set_color_attachment(struct panvk_cmd_buffer *cmdbuf, diff --git a/src/panfrost/vulkan/panvk_vX_image_view.c b/src/panfrost/vulkan/panvk_vX_image_view.c index 7c343bd59d2..8480df9bca8 100644 --- a/src/panfrost/vulkan/panvk_vX_image_view.c +++ b/src/panfrost/vulkan/panvk_vX_image_view.c @@ -19,6 +19,7 @@ #include "panvk_priv_bo.h" #include "pan_afbc.h" +#include "pan_texture.h" #include "genxml/gen_macros.h" @@ -106,7 +107,7 @@ prepare_tex_descs(struct panvk_image_view *view) /* v7 requires AFBC reswizzle. */ else if (!panfrost_format_is_yuv(view->pview.format) && pan_format_supports_afbc(PAN_ARCH, view->pview.format)) - GENX(panfrost_texture_afbc_reswizzle)(&pview); + GENX(pan_texture_afbc_reswizzle)(&pview); #endif /* If the view contains both stencil and depth, we need to keep only the @@ -116,8 +117,7 @@ prepare_tex_descs(struct panvk_image_view *view) pview.format = PIPE_FORMAT_Z32_FLOAT; uint32_t plane_count = vk_format_get_plane_count(view->vk.format); - uint32_t tex_payload_size = - GENX(panfrost_estimate_texture_payload_size)(&pview); + uint32_t tex_payload_size = GENX(pan_texture_estimate_payload_size)(&pview); struct panvk_pool_alloc_info alloc_info = { #if PAN_ARCH == 6 @@ -171,10 +171,10 @@ prepare_tex_descs(struct panvk_image_view *view) pview.planes[0] = view->pview.planes[plane]; pview.format = vk_format_to_pipe_format(plane_format); - GENX(panfrost_new_texture)(&pview, &view->descs.tex[plane], &ptr); + GENX(pan_texture_emit)(&pview, &view->descs.tex[plane], &ptr); #if PAN_ARCH >= 9 if (view->vk.usage & VK_IMAGE_USAGE_STORAGE_BIT) { - GENX(panfrost_new_storage_texture)( + GENX(pan_storage_texture_emit)( &pview, &view->descs.storage_tex[plane], &storage_ptr); storage_ptr.cpu += tex_payload_size; storage_ptr.gpu += tex_payload_size; @@ -185,11 +185,11 @@ prepare_tex_descs(struct panvk_image_view *view) ptr.gpu += tex_payload_size; } } else { - GENX(panfrost_new_texture)(&pview, &view->descs.tex[0], &ptr); + GENX(pan_texture_emit)(&pview, &view->descs.tex[0], &ptr); #if PAN_ARCH >= 9 if (view->vk.usage & VK_IMAGE_USAGE_STORAGE_BIT) - GENX(panfrost_new_storage_texture)(&pview, &view->descs.storage_tex[0], - &storage_ptr); + GENX(pan_storage_texture_emit)(&pview, &view->descs.storage_tex[0], + &storage_ptr); #endif } @@ -217,7 +217,7 @@ prepare_tex_descs(struct panvk_image_view *view) ptr.cpu += tex_payload_size; ptr.gpu += tex_payload_size; - GENX(panfrost_new_texture)(&pview, &view->descs.zs.other_aspect_tex, &ptr); + GENX(pan_texture_emit)(&pview, &view->descs.zs.other_aspect_tex, &ptr); return VK_SUCCESS; } @@ -243,7 +243,7 @@ prepare_attr_buf_descs(struct panvk_image_view *view) bool is_3d = image->planes[plane_idx].layout.dim == MALI_TEXTURE_DIMENSION_3D; unsigned offset = image->planes[plane_idx].data.offset; - offset += panfrost_texture_offset( + offset += pan_image_surface_offset( &image->planes[plane_idx].layout, view->pview.first_level, is_3d ? 0 : view->pview.first_layer, is_3d ? view->pview.first_layer : 0); @@ -283,7 +283,7 @@ prepare_attr_buf_descs(struct panvk_image_view *view) cfg.row_stride = image->planes[plane_idx].layout.slices[level].row_stride; if (cfg.r_dimension > 1) { cfg.slice_stride = - panfrost_get_layer_stride(&image->planes[plane_idx].layout, level); + pan_image_surface_stride(&image->planes[plane_idx].layout, level); } } }