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 <boris.brezillon@collabora.com>
Reviewed-by: Constantine Shablya <constantine.shablya@collabora.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26698>
This commit is contained in:
Boris Brezillon
2023-12-05 12:21:37 +01:00
committed by Marge Bot
parent fe9d541d9d
commit e8d2b5b86d
8 changed files with 43 additions and 23 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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 =

View File

@@ -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;
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;