dri: Support 1555/4444 formats

Add support for 1555 and 4444 formats, both in RGB/BGR ordering, with
and without alpha.

These are already supported by Gallium and drivers, but not yet for
winsys surfaces. Adding these is enough to make them renderable when
using Weston on iris.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24331>
This commit is contained in:
Daniel Stone 2023-07-26 12:18:10 +01:00
parent 0a07431e9a
commit 00aa095d53
7 changed files with 167 additions and 3 deletions

View File

@ -1275,6 +1275,13 @@ struct __DRIdri2ExtensionRec {
#define __DRI_IMAGE_FORMAT_SXRGB8 0x1016
#define __DRI_IMAGE_FORMAT_ABGR16161616 0x1017
#define __DRI_IMAGE_FORMAT_XBGR16161616 0x1018
#define __DRI_IMAGE_FORMAT_ARGB4444 0x1019
#define __DRI_IMAGE_FORMAT_XRGB4444 0x101a
#define __DRI_IMAGE_FORMAT_ABGR4444 0x101b
#define __DRI_IMAGE_FORMAT_XBGR4444 0x101c
#define __DRI_IMAGE_FORMAT_XRGB1555 0x101d
#define __DRI_IMAGE_FORMAT_ABGR1555 0x101e
#define __DRI_IMAGE_FORMAT_XBGR1555 0x101f
#define __DRI_IMAGE_USE_SHARE 0x0001
#define __DRI_IMAGE_USE_SCANOUT 0x0002

View File

@ -186,6 +186,46 @@ static const struct dri2_wl_visual {
{11, 5, 0, -1},
{5, 6, 5, 0},
},
{
"ARGB1555",
WL_DRM_FORMAT_ARGB1555,
WL_SHM_FORMAT_ARGB1555,
__DRI_IMAGE_FORMAT_ARGB1555,
__DRI_IMAGE_FORMAT_ABGR1555,
16,
{10, 5, 0, 15},
{5, 5, 5, 1},
},
{
"XRGB1555",
WL_DRM_FORMAT_XRGB1555,
WL_SHM_FORMAT_XRGB1555,
__DRI_IMAGE_FORMAT_XRGB1555,
__DRI_IMAGE_FORMAT_XBGR1555,
16,
{10, 5, 0, -1},
{5, 5, 5, 0},
},
{
"ARGB4444",
WL_DRM_FORMAT_ARGB4444,
WL_SHM_FORMAT_ARGB4444,
__DRI_IMAGE_FORMAT_ARGB4444,
__DRI_IMAGE_FORMAT_XBGR4444,
16,
{8, 4, 0, 12},
{4, 4, 4, 4},
},
{
"XRGB4444",
WL_DRM_FORMAT_XRGB4444,
WL_SHM_FORMAT_XRGB4444,
__DRI_IMAGE_FORMAT_XRGB4444,
__DRI_IMAGE_FORMAT_XBGR4444,
16,
{8, 4, 0, -1},
{4, 4, 4, 0},
},
};
static int

View File

@ -292,6 +292,15 @@ dri_image_drawable_get_buffers(struct dri_drawable *drawable,
case PIPE_FORMAT_R10G10B10A2_UNORM:
image_format = __DRI_IMAGE_FORMAT_ABGR2101010;
break;
case PIPE_FORMAT_R5G5B5A1_UNORM:
image_format = __DRI_IMAGE_FORMAT_ABGR1555;
break;
case PIPE_FORMAT_B4G4R4A4_UNORM:
image_format = __DRI_IMAGE_FORMAT_ARGB4444;
break;
case PIPE_FORMAT_R4G4B4A4_UNORM:
image_format = __DRI_IMAGE_FORMAT_ABGR4444;
break;
default:
image_format = __DRI_IMAGE_FORMAT_NONE;
break;

View File

@ -505,6 +505,15 @@ static const struct dri2_format_mapping dri2_format_table[] = {
{ DRM_FORMAT_ARGB1555, __DRI_IMAGE_FORMAT_ARGB1555,
__DRI_IMAGE_COMPONENTS_RGBA, PIPE_FORMAT_B5G5R5A1_UNORM, 1,
{ { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB1555 } } },
{ DRM_FORMAT_ABGR1555, __DRI_IMAGE_FORMAT_ABGR1555,
__DRI_IMAGE_COMPONENTS_RGBA, PIPE_FORMAT_R5G5B5A1_UNORM, 1,
{ { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR1555 } } },
{ DRM_FORMAT_ARGB4444, __DRI_IMAGE_FORMAT_ARGB4444,
__DRI_IMAGE_COMPONENTS_RGBA, PIPE_FORMAT_B4G4R4A4_UNORM, 1,
{ { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB4444 } } },
{ DRM_FORMAT_ABGR4444, __DRI_IMAGE_FORMAT_ABGR4444,
__DRI_IMAGE_COMPONENTS_RGBA, PIPE_FORMAT_R4G4B4A4_UNORM, 1,
{ { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR4444 } } },
{ DRM_FORMAT_RGB565, __DRI_IMAGE_FORMAT_RGB565,
__DRI_IMAGE_COMPONENTS_RGB, PIPE_FORMAT_B5G6R5_UNORM, 1,
{ { 0, 0, 0, __DRI_IMAGE_FORMAT_RGB565 } } },

View File

@ -190,6 +190,18 @@ driCreateConfigs(mesa_format format,
/* MESA_FORMAT_RGBA_FLOAT16 */
{{ 0, 0, 0, 0},
{ 0, 16, 32, 48 }},
/* MESA_FORMAT_B5G5R5A1_UNORM */
{{ 0x00007C00, 0x000003E0, 0x0000001F, 0x00008000 },
{ 10, 5, 0, 15 }},
/* MESA_FORMAT_R5G5B5A1_UNORM */
{{ 0x0000001F, 0x000003E0, 0x00007C00, 0x00008000 },
{ 0, 5, 10, 15 }},
/* MESA_FORMAT_B4G4R4A4_UNORM */
{{ 0x00000F00, 0x000000F0, 0x0000000F, 0x0000F000 },
{ 8, 4, 0, 12 }},
/* MESA_FORMAT_R4G4B4A4_UNORM */
{{ 0x0000000F, 0x000000F0, 0x00000F00, 0x0000F000 },
{ 0, 4, 8, 12 }},
};
const uint32_t * masks;
@ -255,6 +267,22 @@ driCreateConfigs(mesa_format format,
masks = format_table[8].masks;
shifts = format_table[8].shifts;
break;
case MESA_FORMAT_B5G5R5A1_UNORM:
masks = format_table[11].masks;
shifts = format_table[11].shifts;
break;
case MESA_FORMAT_R5G5B5A1_UNORM:
masks = format_table[12].masks;
shifts = format_table[12].shifts;
break;
case MESA_FORMAT_B4G4R4A4_UNORM:
masks = format_table[13].masks;
shifts = format_table[13].shifts;
break;
case MESA_FORMAT_R4G4B4A4_UNORM:
masks = format_table[14].masks;
shifts = format_table[14].shifts;
break;
default:
fprintf(stderr, "[%s:%u] Unknown framebuffer type %s (%d).\n",
__func__, __LINE__,
@ -417,6 +445,11 @@ dri_fill_in_modes(struct dri_screen *screen)
/* Required by Android, for HAL_PIXEL_FORMAT_RGBX_8888. */
MESA_FORMAT_R8G8B8X8_SRGB,
MESA_FORMAT_B5G5R5A1_UNORM,
MESA_FORMAT_R5G5B5A1_UNORM,
MESA_FORMAT_B4G4R4A4_UNORM,
MESA_FORMAT_R4G4B4A4_UNORM,
};
static const enum pipe_format pipe_formats[] = {
PIPE_FORMAT_B10G10R10A2_UNORM,
@ -434,6 +467,10 @@ dri_fill_in_modes(struct dri_screen *screen)
PIPE_FORMAT_RGBX8888_UNORM,
PIPE_FORMAT_RGBA8888_SRGB,
PIPE_FORMAT_RGBX8888_SRGB,
PIPE_FORMAT_B5G5R5A1_UNORM,
PIPE_FORMAT_R5G5B5A1_UNORM,
PIPE_FORMAT_B4G4R4A4_UNORM,
PIPE_FORMAT_R4G4B4A4_UNORM,
};
__DRIconfig **configs = NULL;
uint8_t depth_bits_array[5];
@ -520,7 +557,9 @@ dri_fill_in_modes(struct dri_screen *screen)
(mesa_formats[format] == MESA_FORMAT_R8G8B8A8_UNORM ||
mesa_formats[format] == MESA_FORMAT_R8G8B8X8_UNORM ||
mesa_formats[format] == MESA_FORMAT_R8G8B8A8_SRGB ||
mesa_formats[format] == MESA_FORMAT_R8G8B8X8_SRGB))
mesa_formats[format] == MESA_FORMAT_R8G8B8X8_SRGB ||
mesa_formats[format] == MESA_FORMAT_R5G5B5A1_UNORM ||
mesa_formats[format] == MESA_FORMAT_R4G4B4A4_UNORM))
continue;
if (!allow_rgb10 &&
@ -656,6 +695,38 @@ dri_fill_st_visual(struct st_visual *stvis,
stvis->color_format = PIPE_FORMAT_B5G6R5_UNORM;
break;
case 0x00007C00:
assert(!mode->sRGBCapable);
if (mode->alphaMask)
stvis->color_format = PIPE_FORMAT_B5G5R5A1_UNORM;
else
stvis->color_format = PIPE_FORMAT_B5G5R5X1_UNORM;
break;
case 0x0000001F:
assert(!mode->sRGBCapable);
if (mode->alphaMask)
stvis->color_format = PIPE_FORMAT_R5G5B5A1_UNORM;
else
stvis->color_format = PIPE_FORMAT_R5G5B5X1_UNORM;
break;
case 0x00000F00:
assert(!mode->sRGBCapable);
if (mode->alphaMask)
stvis->color_format = PIPE_FORMAT_B4G4R4A4_UNORM;
else
stvis->color_format = PIPE_FORMAT_B4G4R4X4_UNORM;
break;
case 0x0000000F:
assert(!mode->sRGBCapable);
if (mode->alphaMask)
stvis->color_format = PIPE_FORMAT_R4G4B4A4_UNORM;
else
stvis->color_format = PIPE_FORMAT_R4G4B4X4_UNORM;
break;
default:
assert(!"unsupported visual: invalid red mask");
return;

View File

@ -943,6 +943,11 @@ static const struct {
.mesa_format = MESA_FORMAT_B5G5R5A1_UNORM,
.internal_format = GL_RGB5_A1,
},
{
.image_format = __DRI_IMAGE_FORMAT_ABGR1555,
.mesa_format = MESA_FORMAT_R5G5B5A1_UNORM,
.internal_format = GL_RGB5_A1,
},
{
.image_format = __DRI_IMAGE_FORMAT_XRGB8888,
.mesa_format = MESA_FORMAT_B8G8R8X8_UNORM,
@ -1062,6 +1067,16 @@ static const struct {
.internal_format = GL_RG16,
},
#endif
{
.image_format = __DRI_IMAGE_FORMAT_ARGB4444,
.mesa_format = MESA_FORMAT_B4G4R4A4_UNORM,
.internal_format = GL_RGBA4,
},
{
.image_format = __DRI_IMAGE_FORMAT_ABGR4444,
.mesa_format = MESA_FORMAT_R4G4B4A4_UNORM,
.internal_format = GL_RGBA4,
},
};
uint32_t

View File

@ -191,11 +191,20 @@ get_dri_format(enum pipe_format pf)
case PIPE_FORMAT_R16G16B16X16_FLOAT:
image_format = __DRI_IMAGE_FORMAT_XBGR16161616F;
break;
case PIPE_FORMAT_B5G6R5_UNORM:
image_format = __DRI_IMAGE_FORMAT_RGB565;
break;
case PIPE_FORMAT_B5G5R5A1_UNORM:
image_format = __DRI_IMAGE_FORMAT_ARGB1555;
break;
case PIPE_FORMAT_B5G6R5_UNORM:
image_format = __DRI_IMAGE_FORMAT_RGB565;
case PIPE_FORMAT_R5G5B5A1_UNORM:
image_format = __DRI_IMAGE_FORMAT_ABGR1555;
break;
case PIPE_FORMAT_B4G4R4A4_UNORM:
image_format = __DRI_IMAGE_FORMAT_ARGB4444;
break;
case PIPE_FORMAT_R4G4B4A4_UNORM:
image_format = __DRI_IMAGE_FORMAT_ABGR4444;
break;
case PIPE_FORMAT_BGRX8888_UNORM:
image_format = __DRI_IMAGE_FORMAT_XRGB8888;
@ -253,6 +262,10 @@ image_format_to_fourcc(int format)
case __DRI_IMAGE_FORMAT_ABGR2101010: return DRM_FORMAT_ABGR2101010;
case __DRI_IMAGE_FORMAT_XBGR16161616F: return DRM_FORMAT_XBGR16161616F;
case __DRI_IMAGE_FORMAT_ABGR16161616F: return DRM_FORMAT_ABGR16161616F;
case __DRI_IMAGE_FORMAT_ARGB1555: return DRM_FORMAT_ARGB1555;
case __DRI_IMAGE_FORMAT_ABGR1555: return DRM_FORMAT_ABGR1555;
case __DRI_IMAGE_FORMAT_ARGB4444: return DRM_FORMAT_ARGB4444;
case __DRI_IMAGE_FORMAT_ABGR4444: return DRM_FORMAT_ABGR4444;
}
return 0;
}