From 5a747306ce6dd3021c15cfabc83465ec3fb4bb1c Mon Sep 17 00:00:00 2001 From: Kevin Strasser Date: Thu, 24 Jan 2019 16:11:11 -0800 Subject: [PATCH] dri: Add config attributes for color channel shift MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The existing mask attributes can only support up to 32 bpp. Introduce per-channel SHIFT attributes that indicate how many bits, from lsb towards msb, the bit field is offset. A shift of -1 will indicate that there is no bit field set for the channel. As old loaders will still be looking for masks, we set the masks to 0 for any formats wider than 32 bpp. Signed-off-by: Kevin Strasser Reviewed-by: Adam Jackson Reviewed-by: Marek Olšák Reviewed-by: Emil Velikov --- include/GL/internal/dri_interface.h | 6 ++- src/mesa/drivers/dri/common/utils.c | 68 +++++++++++++++++++++-------- src/mesa/main/context.c | 9 ++-- src/mesa/main/mtypes.h | 1 + 4 files changed, 61 insertions(+), 23 deletions(-) diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h index 9f5bc7c569e..c5d22389969 100644 --- a/include/GL/internal/dri_interface.h +++ b/include/GL/internal/dri_interface.h @@ -809,7 +809,11 @@ struct __DRIuseInvalidateExtensionRec { #define __DRI_ATTRIB_YINVERTED 47 #define __DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE 48 #define __DRI_ATTRIB_MUTABLE_RENDER_BUFFER 49 /* EGL_MUTABLE_RENDER_BUFFER_BIT_KHR */ -#define __DRI_ATTRIB_MAX 50 +#define __DRI_ATTRIB_RED_SHIFT 50 +#define __DRI_ATTRIB_GREEN_SHIFT 51 +#define __DRI_ATTRIB_BLUE_SHIFT 52 +#define __DRI_ATTRIB_ALPHA_SHIFT 53 +#define __DRI_ATTRIB_MAX 54 /* __DRI_ATTRIB_RENDER_TYPE */ #define __DRI_ATTRIB_RGBA_BIT 0x01 diff --git a/src/mesa/drivers/dri/common/utils.c b/src/mesa/drivers/dri/common/utils.c index 30ff237d00e..fb991e4e483 100644 --- a/src/mesa/drivers/dri/common/utils.c +++ b/src/mesa/drivers/dri/common/utils.c @@ -181,28 +181,41 @@ driCreateConfigs(mesa_format format, GLboolean enable_accum, GLboolean color_depth_match, GLboolean mutable_render_buffer) { - static const uint32_t masks_table[][4] = { + static const struct { + uint32_t masks[4]; + int shifts[4]; + } format_table[] = { /* MESA_FORMAT_B5G6R5_UNORM */ - { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, + {{ 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, + { 11, 5, 0, -1 }}, /* MESA_FORMAT_B8G8R8X8_UNORM */ - { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, + {{ 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, + { 16, 8, 0, -1 }}, /* MESA_FORMAT_B8G8R8A8_UNORM */ - { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, + {{ 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, + { 16, 8, 0, 24 }}, /* MESA_FORMAT_B10G10R10X2_UNORM */ - { 0x3FF00000, 0x000FFC00, 0x000003FF, 0x00000000 }, + {{ 0x3FF00000, 0x000FFC00, 0x000003FF, 0x00000000 }, + { 20, 10, 0, -1 }}, /* MESA_FORMAT_B10G10R10A2_UNORM */ - { 0x3FF00000, 0x000FFC00, 0x000003FF, 0xC0000000 }, + {{ 0x3FF00000, 0x000FFC00, 0x000003FF, 0xC0000000 }, + { 20, 10, 0, 30 }}, /* MESA_FORMAT_R8G8B8A8_UNORM */ - { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, + {{ 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, + { 0, 8, 16, 24 }}, /* MESA_FORMAT_R8G8B8X8_UNORM */ - { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 }, + {{ 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 }, + { 0, 8, 16, -1 }}, /* MESA_FORMAT_R10G10B10X2_UNORM */ - { 0x000003FF, 0x000FFC00, 0x3FF00000, 0x00000000 }, + {{ 0x000003FF, 0x000FFC00, 0x3FF00000, 0x00000000 }, + { 0, 10, 20, -1 }}, /* MESA_FORMAT_R10G10B10A2_UNORM */ - { 0x000003FF, 0x000FFC00, 0x3FF00000, 0xC0000000 }, + {{ 0x000003FF, 0x000FFC00, 0x3FF00000, 0xC0000000 }, + { 0, 10, 20, 30 }}, }; const uint32_t * masks; + const int * shifts; __DRIconfig **configs, **c; struct gl_config *modes; unsigned i, j, k, h; @@ -216,34 +229,43 @@ driCreateConfigs(mesa_format format, switch (format) { case MESA_FORMAT_B5G6R5_UNORM: - masks = masks_table[0]; + masks = format_table[0].masks; + shifts = format_table[0].shifts; break; case MESA_FORMAT_B8G8R8X8_UNORM: case MESA_FORMAT_B8G8R8X8_SRGB: - masks = masks_table[1]; + masks = format_table[1].masks; + shifts = format_table[1].shifts; break; case MESA_FORMAT_B8G8R8A8_UNORM: case MESA_FORMAT_B8G8R8A8_SRGB: - masks = masks_table[2]; + masks = format_table[2].masks; + shifts = format_table[2].shifts; break; case MESA_FORMAT_R8G8B8A8_UNORM: case MESA_FORMAT_R8G8B8A8_SRGB: - masks = masks_table[5]; + masks = format_table[5].masks; + shifts = format_table[5].shifts; break; case MESA_FORMAT_R8G8B8X8_UNORM: - masks = masks_table[6]; + masks = format_table[6].masks; + shifts = format_table[6].shifts; break; case MESA_FORMAT_B10G10R10X2_UNORM: - masks = masks_table[3]; + masks = format_table[3].masks; + shifts = format_table[3].shifts; break; case MESA_FORMAT_B10G10R10A2_UNORM: - masks = masks_table[4]; + masks = format_table[4].masks; + shifts = format_table[4].shifts; break; case MESA_FORMAT_R10G10B10X2_UNORM: - masks = masks_table[7]; + masks = format_table[7].masks; + shifts = format_table[7].shifts; break; case MESA_FORMAT_R10G10B10A2_UNORM: - masks = masks_table[8]; + masks = format_table[8].masks; + shifts = format_table[8].shifts; break; default: fprintf(stderr, "[%s:%u] Unknown framebuffer type %s (%d).\n", @@ -294,6 +316,10 @@ driCreateConfigs(mesa_format format, modes->greenMask = masks[1]; modes->blueMask = masks[2]; modes->alphaMask = masks[3]; + modes->redShift = shifts[0]; + modes->greenShift = shifts[1]; + modes->blueShift = shifts[2]; + modes->alphaShift = shifts[3]; modes->rgbBits = modes->redBits + modes->greenBits + modes->blueBits + modes->alphaBits; @@ -414,9 +440,13 @@ static const struct { unsigned int attrib, offset; } attribMap[] = { __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue), __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha), __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask), + __ATTRIB(__DRI_ATTRIB_RED_SHIFT, redShift), __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask), + __ATTRIB(__DRI_ATTRIB_GREEN_SHIFT, greenShift), __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask), + __ATTRIB(__DRI_ATTRIB_BLUE_SHIFT, blueShift), __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask), + __ATTRIB(__DRI_ATTRIB_ALPHA_SHIFT, alphaShift), __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth), __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight), __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels), diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 0128fe12d86..c68be8d01e5 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1564,9 +1564,12 @@ check_compatible(const struct gl_context *ctx, ctxvis->foo != bufvis->foo) \ return GL_FALSE - check_component(redMask); - check_component(greenMask); - check_component(blueMask); + check_component(redShift); + check_component(greenShift); + check_component(blueShift); + check_component(redBits); + check_component(greenBits); + check_component(blueBits); check_component(depthBits); check_component(stencilBits); diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index b38d0a29009..b740671559b 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -170,6 +170,7 @@ struct gl_config GLint redBits, greenBits, blueBits, alphaBits; /* bits per comp */ GLuint redMask, greenMask, blueMask, alphaMask; + GLint redShift, greenShift, blueShift, alphaShift; GLint rgbBits; /* total bits for rgb */ GLint indexBits; /* total bits for colorindex */ -- 2.30.2