From e8d2b5b86da1463e9364136dbcf7836b2e755c04 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Tue, 5 Dec 2023 12:21:37 +0100 Subject: [PATCH] panfrost: Add a per-gen panfrost_format_from_pipe_format() helper This will allow us to get rid of panfrost_device arguments passed to per-gen helpers that only need it for the format table, which will help the transition to pan_kmod_dev in panvk. Signed-off-by: Boris Brezillon Reviewed-by: Constantine Shablya Reviewed-by: Erik Faye-Lund Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 24 +++++++++++-------- src/panfrost/lib/pan_blitter.c | 3 ++- src/panfrost/lib/pan_format.h | 11 +++++++++ src/panfrost/lib/pan_texture.c | 2 +- src/panfrost/vulkan/panvk_vX_cs.c | 12 ++++++---- src/panfrost/vulkan/panvk_vX_descriptor_set.c | 8 +++---- src/panfrost/vulkan/panvk_vX_image.c | 2 +- src/panfrost/vulkan/panvk_vX_meta_copy.c | 4 +++- 8 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 42ac26907dc..12beb9b5753 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -192,7 +192,8 @@ panfrost_create_sampler_state(struct pipe_context *pctx, * hardware otherwise supports. When packing border colours, we need to * undo this bijection, by swizzling with its inverse. */ - unsigned mali_format = panfrost_pipe_format_v7[cso->border_color_format].hw; + unsigned mali_format = + GENX(panfrost_format_from_pipe_format)(cso->border_color_format)->hw; enum mali_rgb_component_order order = mali_format & BITFIELD_MASK(12); unsigned char inverted_swizzle[4]; @@ -1142,7 +1143,8 @@ panfrost_upload_rt_conversion_sysval(struct panfrost_batch *batch, GENX(pan_blend_get_internal_desc)(dev, format, rt, size, false) >> 32; } else { pan_pack(&uniform->u[0], INTERNAL_CONVERSION, cfg) - cfg.memory_format = dev->formats[PIPE_FORMAT_NONE].hw; + cfg.memory_format = + GENX(panfrost_format_from_pipe_format)(PIPE_FORMAT_NONE)->hw; } } #endif @@ -1708,7 +1710,6 @@ static void emit_image_attribs(struct panfrost_context *ctx, enum pipe_shader_type shader, struct mali_attribute_packed *attribs, unsigned first_buf) { - struct panfrost_device *dev = pan_device(ctx->base.screen); unsigned last_bit = util_last_bit(ctx->image_mask[shader]); for (unsigned i = 0; i < last_bit; ++i) { @@ -1718,7 +1719,7 @@ emit_image_attribs(struct panfrost_context *ctx, enum pipe_shader_type shader, /* Continuation record means 2 buffers per image */ cfg.buffer_index = first_buf + (i * 2); cfg.offset_enable = (PAN_ARCH <= 5); - cfg.format = dev->formats[format].hw; + cfg.format = GENX(panfrost_format_from_pipe_format)(format)->hw; } } } @@ -2252,7 +2253,8 @@ panfrost_emit_varying(const struct panfrost_device *dev, * dEQP-GLES3.functional.shaders.conditionals.if.sequence_statements_vertex */ gl_varying_slot loc = varying.location; - mali_pixel_format format = dev->formats[pipe_format].hw; + mali_pixel_format format = + GENX(panfrost_format_from_pipe_format)(pipe_format)->hw; if (util_varying_is_point_coord(loc, point_sprite_mask)) { pan_emit_vary_special(dev, out, present, PAN_VARY_PNTCOORD); @@ -3181,7 +3183,7 @@ panfrost_pack_attribute(struct panfrost_device *dev, cfg.frequency = (el.instance_divisor > 0) ? MALI_ATTRIBUTE_FREQUENCY_INSTANCE : MALI_ATTRIBUTE_FREQUENCY_VERTEX; - cfg.format = dev->formats[el.src_format].hw; + cfg.format = GENX(panfrost_format_from_pipe_format)(el.src_format)->hw; cfg.offset = el.src_offset; cfg.buffer_index = el.vertex_buffer_index; cfg.stride = el.src_stride; @@ -3214,7 +3216,7 @@ panfrost_create_vertex_elements_state(struct pipe_context *pctx, const struct pipe_vertex_element *elements) { struct panfrost_vertex_state *so = CALLOC_STRUCT(panfrost_vertex_state); - struct panfrost_device *dev = pan_device(pctx->screen); + UNUSED struct panfrost_device *dev = pan_device(pctx->screen); so->num_elements = num_elements; memcpy(so->pipe, elements, sizeof(*elements) * num_elements); @@ -3235,14 +3237,16 @@ panfrost_create_vertex_elements_state(struct pipe_context *pctx, for (int i = 0; i < num_elements; ++i) { enum pipe_format fmt = elements[i].src_format; - so->formats[i] = dev->formats[fmt].hw; + so->formats[i] = GENX(panfrost_format_from_pipe_format)(fmt)->hw; assert(MALI_EXTRACT_INDEX(so->formats[i]) && "format must be supported"); } /* Let's also prepare vertex builtins */ - so->formats[PAN_VERTEX_ID] = dev->formats[PIPE_FORMAT_R32_UINT].hw; - so->formats[PAN_INSTANCE_ID] = dev->formats[PIPE_FORMAT_R32_UINT].hw; + so->formats[PAN_VERTEX_ID] = + GENX(panfrost_format_from_pipe_format)(PIPE_FORMAT_R32_UINT)->hw; + so->formats[PAN_INSTANCE_ID] = + GENX(panfrost_format_from_pipe_format)(PIPE_FORMAT_R32_UINT)->hw; #endif return so; diff --git a/src/panfrost/lib/pan_blitter.c b/src/panfrost/lib/pan_blitter.c index 84bcba6361f..4c56d0b0cd4 100644 --- a/src/panfrost/lib/pan_blitter.c +++ b/src/panfrost/lib/pan_blitter.c @@ -886,7 +886,8 @@ pan_blitter_emit_varying(struct pan_pool *pool) pan_pack(varying.cpu, ATTRIBUTE, cfg) { cfg.buffer_index = 0; cfg.offset_enable = PAN_ARCH <= 5; - cfg.format = pool->dev->formats[PIPE_FORMAT_R32G32B32_FLOAT].hw; + cfg.format = + GENX(panfrost_format_from_pipe_format)(PIPE_FORMAT_R32G32B32_FLOAT)->hw; #if PAN_ARCH >= 9 cfg.attribute_type = MALI_ATTRIBUTE_TYPE_1D; diff --git a/src/panfrost/lib/pan_format.h b/src/panfrost/lib/pan_format.h index 8e90b2e25b2..407be7a6b5f 100644 --- a/src/panfrost/lib/pan_format.h +++ b/src/panfrost/lib/pan_format.h @@ -63,10 +63,13 @@ extern const struct pan_blendable_format panfrost_blendable_formats_v7[PIPE_FORMAT_COUNT]; extern const struct pan_blendable_format panfrost_blendable_formats_v9[PIPE_FORMAT_COUNT]; + +#define panfrost_pipe_format_v4 panfrost_pipe_format_v5 extern const struct panfrost_format panfrost_pipe_format_v5[PIPE_FORMAT_COUNT]; extern const struct panfrost_format panfrost_pipe_format_v6[PIPE_FORMAT_COUNT]; extern const struct panfrost_format panfrost_pipe_format_v7[PIPE_FORMAT_COUNT]; extern const struct panfrost_format panfrost_pipe_format_v9[PIPE_FORMAT_COUNT]; +#define panfrost_pipe_format_v10 panfrost_pipe_format_v9 /* Helpers to construct swizzles */ @@ -148,4 +151,12 @@ struct pan_decomposed_swizzle #endif +#ifdef PAN_ARCH +static inline const struct panfrost_format * +GENX(panfrost_format_from_pipe_format)(enum pipe_format f) +{ + return &GENX(panfrost_pipe_format)[f]; +} +#endif + #endif diff --git a/src/panfrost/lib/pan_texture.c b/src/panfrost/lib/pan_texture.c index bc419fb76e0..836ff7da64a 100644 --- a/src/panfrost/lib/pan_texture.c +++ b/src/panfrost/lib/pan_texture.c @@ -685,7 +685,7 @@ GENX(panfrost_new_texture)(const struct panfrost_device *dev, const struct pan_image *base_image = pan_image_view_get_plane(iview, 0); const struct pan_image_layout *layout = &base_image->layout; enum pipe_format format = iview->format; - uint32_t mali_format = dev->formats[format].hw; + uint32_t mali_format = GENX(panfrost_format_from_pipe_format)(format)->hw; unsigned char swizzle[4]; ASSERTED const struct util_format_description *desc = diff --git a/src/panfrost/vulkan/panvk_vX_cs.c b/src/panfrost/vulkan/panvk_vX_cs.c index c78e4ed701c..addcbacea15 100644 --- a/src/panfrost/vulkan/panvk_vX_cs.c +++ b/src/panfrost/vulkan/panvk_vX_cs.c @@ -77,7 +77,6 @@ panvk_varying_hw_format(const struct panvk_device *dev, const struct panvk_varyings_info *varyings, gl_shader_stage stage, unsigned idx) { - const struct panfrost_device *pdev = &dev->physical_device->pdev; gl_varying_slot loc = varyings->stage[stage].loc[idx]; switch (loc) { @@ -95,8 +94,11 @@ panvk_varying_hw_format(const struct panvk_device *dev, return (MALI_SNAP_4 << 12) | MALI_RGB_COMPONENT_ORDER_RGBA; #endif default: - if (varyings->varying[loc].format != PIPE_FORMAT_NONE) - return pdev->formats[varyings->varying[loc].format].hw; + if (varyings->varying[loc].format != PIPE_FORMAT_NONE) { + enum pipe_format f = varyings->varying[loc].format; + + return GENX(panfrost_format_from_pipe_format)(f)->hw; + } #if PAN_ARCH >= 7 return (MALI_CONSTANT << 12) | MALI_RGB_COMPONENT_ORDER_0000; #else @@ -279,7 +281,7 @@ panvk_emit_attrib(const struct panvk_device *dev, const struct panvk_attrib_buf *bufs, unsigned buf_count, unsigned idx, void *attrib) { - const struct panfrost_device *pdev = &dev->physical_device->pdev; + enum pipe_format f = attribs->attrib[idx].format; unsigned buf_idx = attribs->attrib[idx].buf; const struct panvk_attrib_buf_info *buf_info = &attribs->buf[buf_idx]; @@ -290,7 +292,7 @@ panvk_emit_attrib(const struct panvk_device *dev, if (buf_info->per_instance) cfg.offset += draw->first_instance * buf_info->stride; - cfg.format = pdev->formats[attribs->attrib[idx].format].hw; + cfg.format = GENX(panfrost_format_from_pipe_format)(f)->hw; } } diff --git a/src/panfrost/vulkan/panvk_vX_descriptor_set.c b/src/panfrost/vulkan/panvk_vX_descriptor_set.c index a18d083064d..5e33c0e25ea 100644 --- a/src/panfrost/vulkan/panvk_vX_descriptor_set.c +++ b/src/panfrost/vulkan/panvk_vX_descriptor_set.c @@ -504,14 +504,14 @@ panvk_write_img_desc(struct panvk_device *dev, struct panvk_descriptor_set *set, uint32_t binding, uint32_t elem, const VkDescriptorImageInfo *pImageInfo) { - const struct panfrost_device *pdev = &dev->physical_device->pdev; VK_FROM_HANDLE(panvk_image_view, view, pImageInfo->imageView); unsigned img_idx = panvk_img_idx(set, binding, elem); void *attrib_buf = (uint8_t *)set->img_attrib_bufs + (pan_size(ATTRIBUTE_BUFFER) * 2 * img_idx); - set->img_fmts[img_idx] = pdev->formats[view->pview.format].hw; + set->img_fmts[img_idx] = + GENX(panfrost_format_from_pipe_format)(view->pview.format)->hw; memcpy(attrib_buf, view->descs.img_attrib_buf, pan_size(ATTRIBUTE_BUFFER) * 2); @@ -542,14 +542,14 @@ panvk_write_img_buf_desc(struct panvk_device *dev, struct panvk_descriptor_set *set, uint32_t binding, uint32_t elem, const VkBufferView bufferView) { - const struct panfrost_device *pdev = &dev->physical_device->pdev; VK_FROM_HANDLE(panvk_buffer_view, view, bufferView); unsigned img_idx = panvk_img_idx(set, binding, elem); void *attrib_buf = (uint8_t *)set->img_attrib_bufs + (pan_size(ATTRIBUTE_BUFFER) * 2 * img_idx); - set->img_fmts[img_idx] = pdev->formats[view->fmt].hw; + set->img_fmts[img_idx] = + GENX(panfrost_format_from_pipe_format)(view->fmt)->hw; memcpy(attrib_buf, view->descs.img_attrib_buf, pan_size(ATTRIBUTE_BUFFER) * 2); diff --git a/src/panfrost/vulkan/panvk_vX_image.c b/src/panfrost/vulkan/panvk_vX_image.c index 0e75eb1e6b3..25eec5ee5a3 100644 --- a/src/panfrost/vulkan/panvk_vX_image.c +++ b/src/panfrost/vulkan/panvk_vX_image.c @@ -204,7 +204,7 @@ panvk_per_arch(CreateBufferView)(VkDevice _device, pan_pack(view->descs.tex, TEXTURE, cfg) { cfg.dimension = MALI_TEXTURE_DIMENSION_1D; - cfg.format = pdev->formats[view->fmt].hw; + cfg.format = GENX(panfrost_format_from_pipe_format)(view->fmt)->hw; cfg.width = view->elems; cfg.depth = cfg.height = 1; cfg.swizzle = PAN_V6_SWIZZLE(R, G, B, A); diff --git a/src/panfrost/vulkan/panvk_vX_meta_copy.c b/src/panfrost/vulkan/panvk_vX_meta_copy.c index 6abb644e76c..23f84d6b1fe 100644 --- a/src/panfrost/vulkan/panvk_vX_meta_copy.c +++ b/src/panfrost/vulkan/panvk_vX_meta_copy.c @@ -80,8 +80,10 @@ panvk_meta_copy_emit_varying(struct pan_pool *pool, mali_ptr coordinates, ; pan_pack(varying.cpu, ATTRIBUTE, cfg) { + enum pipe_format f = PIPE_FORMAT_R32G32B32_FLOAT; + cfg.buffer_index = 0; - cfg.format = pool->dev->formats[PIPE_FORMAT_R32G32B32_FLOAT].hw; + cfg.format = GENX(panfrost_format_from_pipe_format)(f)->hw; } *varyings = varying.gpu;