diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/drivers/lima/Android.mk | 4 | ||||
-rw-r--r-- | src/gallium/drivers/lima/lima_draw.c | 33 | ||||
-rw-r--r-- | src/gallium/drivers/lima/lima_format.c | 135 | ||||
-rw-r--r-- | src/gallium/drivers/lima/lima_format.h | 37 | ||||
-rw-r--r-- | src/gallium/drivers/lima/lima_screen.c | 21 | ||||
-rw-r--r-- | src/gallium/drivers/lima/lima_texture.c | 60 | ||||
-rw-r--r-- | src/gallium/drivers/lima/lima_texture.h | 1 | ||||
-rw-r--r-- | src/gallium/drivers/lima/meson.build | 2 |
8 files changed, 190 insertions, 103 deletions
diff --git a/src/gallium/drivers/lima/Android.mk b/src/gallium/drivers/lima/Android.mk index 10aba8dd3e2..c09789ec022 100644 --- a/src/gallium/drivers/lima/Android.mk +++ b/src/gallium/drivers/lima/Android.mk @@ -68,7 +68,9 @@ LOCAL_SRC_FILES := \ lima_texture.c \ lima_texture.h \ lima_util.c \ - lima_util.h + lima_util.h \ + lima_format.c \ + lima_format.h LOCAL_MODULE := libmesa_pipe_lima diff --git a/src/gallium/drivers/lima/lima_draw.c b/src/gallium/drivers/lima/lima_draw.c index 87eeb0e795b..33b01212f43 100644 --- a/src/gallium/drivers/lima/lima_draw.c +++ b/src/gallium/drivers/lima/lima_draw.c @@ -44,6 +44,7 @@ #include "lima_texture.h" #include "lima_util.h" #include "lima_fence.h" +#include "lima_format.h" #include <drm-uapi/lima_drm.h> @@ -116,9 +117,6 @@ struct lima_render_state { uint32_t varyings_address; }; -#define LIMA_PIXEL_FORMAT_B8G8R8A8 0x03 -#define LIMA_PIXEL_FORMAT_Z16 0x0e -#define LIMA_PIXEL_FORMAT_Z24S8 0x0f /* plbu commands */ #define PLBU_CMD_BEGIN(max) { \ @@ -1444,20 +1442,7 @@ lima_pack_wb_zsbuf_reg(struct lima_context *ctx, uint32_t *wb_reg, int wb_idx) struct lima_context_framebuffer *fb = &ctx->framebuffer; struct lima_resource *res = lima_resource(fb->base.zsbuf->texture); int level = fb->base.zsbuf->u.tex.level; - - uint32_t format; - - switch (fb->base.zsbuf->format) { - case PIPE_FORMAT_Z16_UNORM: - format = LIMA_PIXEL_FORMAT_Z16; - break; - case PIPE_FORMAT_Z24_UNORM_S8_UINT: - case PIPE_FORMAT_Z24X8_UNORM: - default: - /* Assume Z24S8 */ - format = LIMA_PIXEL_FORMAT_Z24S8; - break; - } + uint32_t format = lima_format_get_pixel(fb->base.zsbuf->format); struct lima_pp_wb_reg *wb = (void *)wb_reg; wb[wb_idx].type = 0x01; /* 1 for depth, stencil */ @@ -1479,21 +1464,13 @@ lima_pack_wb_cbuf_reg(struct lima_context *ctx, uint32_t *wb_reg, int wb_idx) struct lima_context_framebuffer *fb = &ctx->framebuffer; struct lima_resource *res = lima_resource(fb->base.cbufs[0]->texture); int level = fb->base.cbufs[0]->u.tex.level; - - bool swap_channels = false; - switch (fb->base.cbufs[0]->format) { - case PIPE_FORMAT_R8G8B8A8_UNORM: - case PIPE_FORMAT_R8G8B8X8_UNORM: - swap_channels = true; - break; - default: - break; - } + uint32_t format = lima_format_get_pixel(fb->base.cbufs[0]->format); + bool swap_channels = lima_format_get_swap_rb(fb->base.cbufs[0]->format); struct lima_pp_wb_reg *wb = (void *)wb_reg; wb[wb_idx].type = 0x02; /* 2 for color buffer */ wb[wb_idx].address = res->bo->va + res->levels[level].offset; - wb[wb_idx].pixel_format = LIMA_PIXEL_FORMAT_B8G8R8A8; + wb[wb_idx].pixel_format = format; if (res->tiled) { wb[wb_idx].pixel_layout = 0x2; wb[wb_idx].pitch = fb->tiled_w; diff --git a/src/gallium/drivers/lima/lima_format.c b/src/gallium/drivers/lima/lima_format.c new file mode 100644 index 00000000000..a599ee67eec --- /dev/null +++ b/src/gallium/drivers/lima/lima_format.c @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2011-2013 Luc Verhaegen <[email protected]> + * Copyright (c) 2018-2019 Lima Project + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sub license, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + +#include <stdlib.h> + +#include <util/macros.h> + +#include "lima_format.h" + +#define LIMA_TEXEL_FORMAT_L8 0x09 +#define LIMA_TEXEL_FORMAT_A8 0x0a +#define LIMA_TEXEL_FORMAT_I8 0x0b +#define LIMA_TEXEL_FORMAT_BGR_565 0x0e +#define LIMA_TEXEL_FORMAT_L8A8 0x11 +#define LIMA_TEXEL_FORMAT_L16 0x12 +#define LIMA_TEXEL_FORMAT_A16 0x13 +#define LIMA_TEXEL_FORMAT_I16 0x14 +#define LIMA_TEXEL_FORMAT_RGB_888 0x15 +#define LIMA_TEXEL_FORMAT_RGBA_8888 0x16 +#define LIMA_TEXEL_FORMAT_RGBX_8888 0x17 +#define LIMA_TEXEL_FORMAT_Z24S8 0x2c +#define LIMA_TEXEL_FORMAT_NONE -1 + +#define LIMA_PIXEL_FORMAT_B5G6R5 0x00 +#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; + bool swap_r_b; +}; + +#define LIMA_FORMAT(pipe, tex, pix, swap) \ + [PIPE_FORMAT_##pipe] = { \ + .present = true, .texel = LIMA_TEXEL_FORMAT_##tex, \ + .pixel = LIMA_PIXEL_FORMAT_##pix, .swap_r_b = swap, \ + } + +static const struct lima_format lima_format_table[] = { + LIMA_FORMAT(R8G8B8A8_UNORM, RGBA_8888, B8G8R8A8, true), + LIMA_FORMAT(B8G8R8A8_UNORM, RGBA_8888, B8G8R8A8, false), + LIMA_FORMAT(R8G8B8A8_SRGB, RGBA_8888, B8G8R8A8, true), + LIMA_FORMAT(B8G8R8A8_SRGB, RGBA_8888, B8G8R8A8, false), + LIMA_FORMAT(R8G8B8X8_UNORM, RGBX_8888, B8G8R8A8, true), + LIMA_FORMAT(B8G8R8X8_UNORM, RGBX_8888, B8G8R8A8, false), + LIMA_FORMAT(R8G8B8_UNORM, RGB_888, NONE, true), + LIMA_FORMAT(B5G6R5_UNORM, BGR_565, B5G6R5, false), + LIMA_FORMAT(Z24_UNORM_S8_UINT, Z24S8, Z24S8, false), + LIMA_FORMAT(Z24X8_UNORM, Z24S8, Z24S8, false), + /* Blob uses L16 for Z16 */ + LIMA_FORMAT(Z16_UNORM, L16, Z16, false), + LIMA_FORMAT(L16_UNORM, L16, NONE, false), + LIMA_FORMAT(L8_UNORM, L8, NONE, false), + LIMA_FORMAT(A16_UNORM, A16, NONE, false), + LIMA_FORMAT(A8_UNORM, A8, NONE, false), + LIMA_FORMAT(I16_UNORM, I16, NONE, false), + LIMA_FORMAT(I8_UNORM, I8, NONE, false), + LIMA_FORMAT(L8A8_UNORM, L8A8, NONE, false), +}; + +static const struct lima_format * +get_format(enum pipe_format f) +{ + if (f >= ARRAY_SIZE(lima_format_table) || + !lima_format_table[f].present) + return NULL; + + return lima_format_table + f; +} + +bool +lima_format_texel_supported(enum pipe_format f) +{ + const struct lima_format *lf = get_format(f); + + if (!lf) + return false; + + return lf->texel != LIMA_TEXEL_FORMAT_NONE; +} + +bool +lima_format_pixel_supported(enum pipe_format f) +{ + const struct lima_format *lf = get_format(f); + + if (!lf) + return false; + + return lf->pixel != LIMA_PIXEL_FORMAT_NONE; +} + +int +lima_format_get_texel(enum pipe_format f) +{ + return lima_format_table[f].texel; +} + +int +lima_format_get_pixel(enum pipe_format f) +{ + return lima_format_table[f].pixel; +} + +bool +lima_format_get_swap_rb(enum pipe_format f) +{ + return lima_format_table[f].swap_r_b; +} diff --git a/src/gallium/drivers/lima/lima_format.h b/src/gallium/drivers/lima/lima_format.h new file mode 100644 index 00000000000..3caa0994573 --- /dev/null +++ b/src/gallium/drivers/lima/lima_format.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018-2019 Lima Project + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sub license, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +#ifndef H_LIMA_FORMAT +#define H_LIMA_FORMAT + +#include <stdbool.h> + +#include <pipe/p_format.h> + +bool lima_format_texel_supported(enum pipe_format f); +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); +bool lima_format_get_swap_rb(enum pipe_format f); + +#endif diff --git a/src/gallium/drivers/lima/lima_screen.c b/src/gallium/drivers/lima/lima_screen.c index 13b5599c1a8..5e6ac1ffb08 100644 --- a/src/gallium/drivers/lima/lima_screen.c +++ b/src/gallium/drivers/lima/lima_screen.c @@ -38,7 +38,7 @@ #include "lima_program.h" #include "lima_bo.h" #include "lima_fence.h" -#include "lima_texture.h" +#include "lima_format.h" #include "ir/lima_ir.h" #include "xf86drm.h" @@ -275,20 +275,9 @@ lima_screen_is_format_supported(struct pipe_screen *pscreen, if (sample_count > 1 && sample_count != 4) return false; - if (usage & PIPE_BIND_RENDER_TARGET) { - switch (format) { - case PIPE_FORMAT_B8G8R8A8_UNORM: - case PIPE_FORMAT_B8G8R8X8_UNORM: - case PIPE_FORMAT_R8G8B8A8_UNORM: - case PIPE_FORMAT_R8G8B8X8_UNORM: - case PIPE_FORMAT_Z16_UNORM: - case PIPE_FORMAT_Z24_UNORM_S8_UINT: - case PIPE_FORMAT_Z24X8_UNORM: - break; - default: - return false; - } - } + if (usage & PIPE_BIND_RENDER_TARGET && + !lima_format_pixel_supported(format)) + return false; if (usage & PIPE_BIND_DEPTH_STENCIL) { switch (format) { @@ -322,7 +311,7 @@ lima_screen_is_format_supported(struct pipe_screen *pscreen, } if (usage & PIPE_BIND_SAMPLER_VIEW) - return lima_texel_format_supported(format); + return lima_format_texel_supported(format); return true; } diff --git a/src/gallium/drivers/lima/lima_texture.c b/src/gallium/drivers/lima/lima_texture.c index 9fb6313cf53..379bf387330 100644 --- a/src/gallium/drivers/lima/lima_texture.c +++ b/src/gallium/drivers/lima/lima_texture.c @@ -36,66 +36,15 @@ #include "lima_resource.h" #include "lima_submit.h" #include "lima_util.h" +#include "lima_format.h" #include <drm-uapi/lima_drm.h> -#define LIMA_TEXEL_FORMAT_L8 0x09 -#define LIMA_TEXEL_FORMAT_A8 0x0a -#define LIMA_TEXEL_FORMAT_I8 0x0b -#define LIMA_TEXEL_FORMAT_BGR_565 0x0e -#define LIMA_TEXEL_FORMAT_L8A8 0x11 -#define LIMA_TEXEL_FORMAT_L16 0x12 -#define LIMA_TEXEL_FORMAT_A16 0x13 -#define LIMA_TEXEL_FORMAT_I16 0x14 -#define LIMA_TEXEL_FORMAT_RGB_888 0x15 -#define LIMA_TEXEL_FORMAT_RGBA_8888 0x16 -#define LIMA_TEXEL_FORMAT_RGBX_8888 0x17 -#define LIMA_TEXEL_FORMAT_Z24S8 0x2c #define lima_tex_list_size 64 -typedef struct { - bool present; - uint32_t lima_format; - bool swap_r_b; -} lima_format; - -#define LIMA_FORMAT(pipe, lima, swap) \ - [PIPE_FORMAT_##pipe] = { .present = true, .lima_format = lima, \ - .swap_r_b = swap } - -static const lima_format lima_format_table[] = { - LIMA_FORMAT(R8G8B8A8_UNORM, LIMA_TEXEL_FORMAT_RGBA_8888, true), - LIMA_FORMAT(B8G8R8A8_UNORM, LIMA_TEXEL_FORMAT_RGBA_8888, false), - LIMA_FORMAT(R8G8B8A8_SRGB, LIMA_TEXEL_FORMAT_RGBA_8888, true), - LIMA_FORMAT(B8G8R8A8_SRGB, LIMA_TEXEL_FORMAT_RGBA_8888, false), - LIMA_FORMAT(R8G8B8X8_UNORM, LIMA_TEXEL_FORMAT_RGBX_8888, true), - LIMA_FORMAT(B8G8R8X8_UNORM, LIMA_TEXEL_FORMAT_RGBX_8888, false), - LIMA_FORMAT(R8G8B8_UNORM, LIMA_TEXEL_FORMAT_RGB_888, true), - LIMA_FORMAT(B5G6R5_UNORM, LIMA_TEXEL_FORMAT_BGR_565, false), - LIMA_FORMAT(Z24_UNORM_S8_UINT, LIMA_TEXEL_FORMAT_Z24S8, false), - LIMA_FORMAT(Z24X8_UNORM, LIMA_TEXEL_FORMAT_Z24S8, false), - /* Blob uses L16 for Z16 */ - LIMA_FORMAT(Z16_UNORM, LIMA_TEXEL_FORMAT_L16, false), - LIMA_FORMAT(L16_UNORM, LIMA_TEXEL_FORMAT_L16, false), - LIMA_FORMAT(L8_UNORM, LIMA_TEXEL_FORMAT_L8, false), - LIMA_FORMAT(A16_UNORM, LIMA_TEXEL_FORMAT_A16, false), - LIMA_FORMAT(A8_UNORM, LIMA_TEXEL_FORMAT_A8, false), - LIMA_FORMAT(I16_UNORM, LIMA_TEXEL_FORMAT_I16, false), - LIMA_FORMAT(I8_UNORM, LIMA_TEXEL_FORMAT_I8, false), - LIMA_FORMAT(L8A8_UNORM, LIMA_TEXEL_FORMAT_L8A8, false), -}; - static_assert(offsetof(lima_tex_desc, va) == 24, "lima_tex_desc->va offset isn't 24"); -bool -lima_texel_format_supported(enum pipe_format pformat) -{ - if (pformat >= ARRAY_SIZE(lima_format_table)) - return false; - - return lima_format_table[pformat].present; -} static void lima_texture_desc_set_va(lima_tex_desc *desc, @@ -129,11 +78,8 @@ lima_texture_desc_set_res(struct lima_context *ctx, lima_tex_desc *desc, height = u_minify(height, first_level); } - assert(prsc->format < ARRAY_SIZE(lima_format_table)); - assert(lima_format_table[prsc->format].present); - - desc->format = lima_format_table[prsc->format].lima_format; - desc->swap_r_b = lima_format_table[prsc->format].swap_r_b; + desc->format = lima_format_get_texel(prsc->format); + desc->swap_r_b = lima_format_get_swap_rb(prsc->format); desc->width = width; desc->height = height; desc->unknown_3_1 = 1; diff --git a/src/gallium/drivers/lima/lima_texture.h b/src/gallium/drivers/lima/lima_texture.h index d91c8bb00c8..c1bc34f8740 100644 --- a/src/gallium/drivers/lima/lima_texture.h +++ b/src/gallium/drivers/lima/lima_texture.h @@ -92,6 +92,5 @@ void lima_texture_desc_set_res(struct lima_context *ctx, lima_tex_desc *desc, struct pipe_resource *prsc, unsigned first_level, unsigned last_level); void lima_update_textures(struct lima_context *ctx); -bool lima_texel_format_supported(enum pipe_format pformat); #endif diff --git a/src/gallium/drivers/lima/meson.build b/src/gallium/drivers/lima/meson.build index 0d8f2f87c29..9f5edb0ebfb 100644 --- a/src/gallium/drivers/lima/meson.build +++ b/src/gallium/drivers/lima/meson.build @@ -69,6 +69,8 @@ files_lima = files( 'lima_texture.h', 'lima_fence.c', 'lima_fence.h', + 'lima_format.h', + 'lima_format.c', ) lima_nir_algebraic_c = custom_target( |