From: Vasily Khoruzhick Date: Thu, 19 Mar 2020 02:21:57 +0000 (-0700) Subject: lima: split pixel and texel format tables X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e763c6778ced36ba5f513391fc26952aab05d8af;p=mesa.git lima: split pixel and texel format tables This is preparation for the next commit where we may need different swap_r_b flags for pixel and texel formats. Reviewed-by: Erico Nunes Signed-off-by: Vasily Khoruzhick Part-of: --- diff --git a/src/gallium/drivers/lima/lima_format.c b/src/gallium/drivers/lima/lima_format.c index 524d12773e8..fad0f8976ef 100644 --- a/src/gallium/drivers/lima/lima_format.c +++ b/src/gallium/drivers/lima/lima_format.c @@ -47,7 +47,6 @@ #define LIMA_TEXEL_FORMAT_Z24X8 0x2c /* This format is only used for depth/stencil reload */ #define LIMA_TEXEL_FORMAT_Z24S8_RLD 0x32 -#define LIMA_TEXEL_FORMAT_NONE -1 #define LIMA_PIXEL_FORMAT_B5G6R5 0x00 #define LIMA_PIXEL_FORMAT_B5G5R5A1 0x01 @@ -55,82 +54,108 @@ #define LIMA_PIXEL_FORMAT_B8G8R8A8 0x03 #define LIMA_PIXEL_FORMAT_Z16 0x0e #define LIMA_PIXEL_FORMAT_Z24S8 0x0f -#define LIMA_PIXEL_FORMAT_NONE -1 struct lima_format { bool present; - int texel; - int pixel; + int format; bool swap_r_b; uint32_t channel_layout; }; -#define LIMA_FORMAT(pipe, tex, pix, swap, ch_layout) \ - [PIPE_FORMAT_##pipe] = { \ - .present = true, .texel = LIMA_TEXEL_FORMAT_##tex, \ - .pixel = LIMA_PIXEL_FORMAT_##pix, .swap_r_b = swap, \ - .channel_layout = ch_layout, \ +#define LIMA_TEXEL_FORMAT(pipe, tex, swap) \ + [PIPE_FORMAT_##pipe] = { \ + .present = true, .format = LIMA_TEXEL_FORMAT_##tex, \ + .swap_r_b = swap \ } -static const struct lima_format lima_format_table[] = { - LIMA_FORMAT(R8G8B8A8_UNORM, RGBA_8888, B8G8R8A8, true, 0x8888), - LIMA_FORMAT(B8G8R8A8_UNORM, RGBA_8888, B8G8R8A8, false, 0x8888), - LIMA_FORMAT(R8G8B8A8_SRGB, RGBA_8888, B8G8R8A8, true, 0x8888), - LIMA_FORMAT(B8G8R8A8_SRGB, RGBA_8888, B8G8R8A8, false, 0x8888), - LIMA_FORMAT(R8G8B8X8_UNORM, RGBX_8888, B8G8R8A8, true, 0x8888), - LIMA_FORMAT(B8G8R8X8_UNORM, RGBX_8888, B8G8R8A8, false, 0x8888), - LIMA_FORMAT(B5G6R5_UNORM, BGR_565, B5G6R5, false, 0x8565), - /* BGRA_5551 seems to need channel layout 0x8565, it's not a typo */ - LIMA_FORMAT(B5G5R5A1_UNORM, BGRA_5551, B5G5R5A1, false, 0x8565), - LIMA_FORMAT(B4G4R4A4_UNORM, BGRA_4444, B4G4R4A4, false, 0x8444), - LIMA_FORMAT(Z24_UNORM_S8_UINT, Z24X8, Z24S8, false, 0x0000), - LIMA_FORMAT(Z24X8_UNORM, Z24X8, Z24S8, false, 0x0000), - LIMA_FORMAT(L16_UNORM, L16, NONE, false, 0x0000), - LIMA_FORMAT(L8_UNORM, L8, NONE, false, 0x0000), - LIMA_FORMAT(A16_UNORM, A16, NONE, false, 0x0000), - LIMA_FORMAT(A8_UNORM, A8, NONE, false, 0x0000), - LIMA_FORMAT(I16_UNORM, I16, NONE, false, 0x0000), - LIMA_FORMAT(I8_UNORM, I8, NONE, false, 0x0000), - LIMA_FORMAT(L8A8_UNORM, L8A8, NONE, false, 0x0000), - LIMA_FORMAT(ETC1_RGB8, ETC1_RGB8, NONE, false, 0x8888), +#define LIMA_PIXEL_FORMAT(pipe, pix, swap, ch_layout) \ + [PIPE_FORMAT_##pipe] = { \ + .present = true, .format = LIMA_PIXEL_FORMAT_##pix, \ + .swap_r_b = swap, .channel_layout = ch_layout \ + } + +static const struct lima_format lima_texel_formats[] = { + LIMA_TEXEL_FORMAT(R8G8B8A8_UNORM, RGBA_8888, true), + LIMA_TEXEL_FORMAT(B8G8R8A8_UNORM, RGBA_8888, false), + LIMA_TEXEL_FORMAT(R8G8B8A8_SRGB, RGBA_8888, true), + LIMA_TEXEL_FORMAT(B8G8R8A8_SRGB, RGBA_8888, false), + LIMA_TEXEL_FORMAT(R8G8B8X8_UNORM, RGBX_8888, true), + LIMA_TEXEL_FORMAT(B8G8R8X8_UNORM, RGBX_8888, false), + LIMA_TEXEL_FORMAT(B5G6R5_UNORM, BGR_565, false), + LIMA_TEXEL_FORMAT(B5G5R5A1_UNORM, BGRA_5551, false), + LIMA_TEXEL_FORMAT(B4G4R4A4_UNORM, BGRA_4444, false), + LIMA_TEXEL_FORMAT(Z24_UNORM_S8_UINT, Z24X8, false), + LIMA_TEXEL_FORMAT(Z24X8_UNORM, Z24X8, false), + LIMA_TEXEL_FORMAT(L16_UNORM, L16, false), + LIMA_TEXEL_FORMAT(L8_UNORM, L8, false), + LIMA_TEXEL_FORMAT(A16_UNORM, A16, false), + LIMA_TEXEL_FORMAT(A8_UNORM, A8, false), + LIMA_TEXEL_FORMAT(I16_UNORM, I16, false), + LIMA_TEXEL_FORMAT(I8_UNORM, I8, false), + LIMA_TEXEL_FORMAT(L8A8_UNORM, L8A8, false), + LIMA_TEXEL_FORMAT(ETC1_RGB8, ETC1_RGB8, false), +}; + +static const struct lima_format lima_pixel_formats[] = { + LIMA_PIXEL_FORMAT(R8G8B8A8_UNORM, B8G8R8A8, true, 0x8888), + LIMA_PIXEL_FORMAT(B8G8R8A8_UNORM, B8G8R8A8, false, 0x8888), + LIMA_PIXEL_FORMAT(R8G8B8A8_SRGB, B8G8R8A8, true, 0x8888), + LIMA_PIXEL_FORMAT(B8G8R8A8_SRGB, B8G8R8A8, false, 0x8888), + LIMA_PIXEL_FORMAT(R8G8B8X8_UNORM, B8G8R8A8, true, 0x8888), + LIMA_PIXEL_FORMAT(B8G8R8X8_UNORM, B8G8R8A8, false, 0x8888), + LIMA_PIXEL_FORMAT(B5G6R5_UNORM, B5G6R5, false, 0x8565), + LIMA_PIXEL_FORMAT(B5G5R5A1_UNORM, B5G5R5A1, false, 0x8565), + LIMA_PIXEL_FORMAT(B4G4R4A4_UNORM, B4G4R4A4, false, 0x8444), + LIMA_PIXEL_FORMAT(Z24_UNORM_S8_UINT, Z24S8, false, 0x0000), + LIMA_PIXEL_FORMAT(Z24X8_UNORM, Z24S8, false, 0x0000), }; static const struct lima_format * -get_format(enum pipe_format f) +get_texel_format(enum pipe_format f) +{ + if (f >= ARRAY_SIZE(lima_texel_formats) || + !lima_texel_formats[f].present) + return NULL; + + return lima_texel_formats + f; +} + +static const struct lima_format * +get_pixel_format(enum pipe_format f) { - if (f >= ARRAY_SIZE(lima_format_table) || - !lima_format_table[f].present) + if (f >= ARRAY_SIZE(lima_pixel_formats) || + !lima_pixel_formats[f].present) return NULL; - return lima_format_table + f; + return lima_pixel_formats + f; } bool lima_format_texel_supported(enum pipe_format f) { - const struct lima_format *lf = get_format(f); + const struct lima_format *lf = get_texel_format(f); if (!lf) return false; - return lf->texel != LIMA_TEXEL_FORMAT_NONE; + return true; } bool lima_format_pixel_supported(enum pipe_format f) { - const struct lima_format *lf = get_format(f); + const struct lima_format *lf = get_pixel_format(f); if (!lf) return false; - return lf->pixel != LIMA_PIXEL_FORMAT_NONE; + return true; } int lima_format_get_texel(enum pipe_format f) { - return lima_format_table[f].texel; + return lima_texel_formats[f].format; } int @@ -148,17 +173,23 @@ lima_format_get_texel_reload(enum pipe_format f) int lima_format_get_pixel(enum pipe_format f) { - return lima_format_table[f].pixel; + return lima_pixel_formats[f].format; +} + +bool +lima_format_get_texel_swap_rb(enum pipe_format f) +{ + return lima_texel_formats[f].swap_r_b; } bool -lima_format_get_swap_rb(enum pipe_format f) +lima_format_get_pixel_swap_rb(enum pipe_format f) { - return lima_format_table[f].swap_r_b; + return lima_pixel_formats[f].swap_r_b; } uint32_t lima_format_get_channel_layout(enum pipe_format f) { - return lima_format_table[f].channel_layout; + return lima_pixel_formats[f].channel_layout; } diff --git a/src/gallium/drivers/lima/lima_format.h b/src/gallium/drivers/lima/lima_format.h index 29faaac3a7b..856f8ba5acb 100644 --- a/src/gallium/drivers/lima/lima_format.h +++ b/src/gallium/drivers/lima/lima_format.h @@ -33,7 +33,8 @@ bool lima_format_pixel_supported(enum pipe_format f); int lima_format_get_texel(enum pipe_format f); int lima_format_get_pixel(enum pipe_format f); int lima_format_get_texel_reload(enum pipe_format f); -bool lima_format_get_swap_rb(enum pipe_format f); +bool lima_format_get_texel_swap_rb(enum pipe_format f); +bool lima_format_get_pixel_swap_rb(enum pipe_format f); uint32_t lima_format_get_channel_layout(enum pipe_format f); #endif diff --git a/src/gallium/drivers/lima/lima_job.c b/src/gallium/drivers/lima/lima_job.c index c628ff0a4e6..58dba520429 100644 --- a/src/gallium/drivers/lima/lima_job.c +++ b/src/gallium/drivers/lima/lima_job.c @@ -804,7 +804,7 @@ lima_pack_wb_cbuf_reg(struct lima_job *job, uint32_t *frame_reg, int level = cbuf->u.tex.level; unsigned layer = cbuf->u.tex.first_layer; uint32_t format = lima_format_get_pixel(cbuf->format); - bool swap_channels = lima_format_get_swap_rb(cbuf->format); + bool swap_channels = lima_format_get_pixel_swap_rb(cbuf->format); struct lima_pp_frame_reg *frame = (void *)frame_reg; frame->channel_layout = lima_format_get_channel_layout(cbuf->format); diff --git a/src/gallium/drivers/lima/lima_texture.c b/src/gallium/drivers/lima/lima_texture.c index a6cbb97d635..0258aa23ec9 100644 --- a/src/gallium/drivers/lima/lima_texture.c +++ b/src/gallium/drivers/lima/lima_texture.c @@ -83,7 +83,7 @@ lima_texture_desc_set_res(struct lima_context *ctx, lima_tex_desc *desc, } desc->format = lima_format_get_texel(prsc->format); - desc->swap_r_b = lima_format_get_swap_rb(prsc->format); + desc->swap_r_b = lima_format_get_texel_swap_rb(prsc->format); desc->width = width; desc->height = height; desc->unknown_3_1 = 1;