gl-renderer: Replace channel ordering with texture swizzles

The channel ordering system currently proposes to swizzle components
in the fragment shader for a few combinations. This commit replaces
this system with texture swizzling parameters in order to support all
the possible combinations in a more efficient way.

This will allow to easily add a lot more formats and as a nice side
effect to force components to 0 or 1, which is useful for opaque
formats.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
This commit is contained in:
Loïc Molinari 2024-11-11 11:42:41 +01:00 committed by Daniel Stone
parent 891736793a
commit 815ccaff92
6 changed files with 70 additions and 100 deletions

View file

@ -51,29 +51,41 @@
#include <GLES2/gl2ext.h> #include <GLES2/gl2ext.h>
#include <GLES3/gl3.h> #include <GLES3/gl3.h>
#define GL_FORMAT_INFO(internal_, external_, type_) \ #define SWIZZLES_ABG1 { GL_ALPHA, GL_BLUE, GL_GREEN, GL_ONE }
#define SWIZZLES_ABGR { GL_ALPHA, GL_BLUE, GL_GREEN, GL_RED }
#define SWIZZLES_B1RG { GL_BLUE, GL_ONE, GL_RED, GL_GREEN }
#define SWIZZLES_BARG { GL_BLUE, GL_ALPHA, GL_RED, GL_GREEN }
#define SWIZZLES_BGR1 { GL_BLUE, GL_GREEN, GL_RED, GL_ONE }
#define SWIZZLES_BGRA { GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA }
#define SWIZZLES_GBA1 { GL_GREEN, GL_BLUE, GL_ALPHA, GL_ONE }
#define SWIZZLES_GBAR { GL_GREEN, GL_BLUE, GL_ALPHA, GL_RED }
#define SWIZZLES_R001 { GL_RED, GL_ZERO, GL_ZERO, GL_ONE }
#define SWIZZLES_RG01 { GL_RED, GL_GREEN, GL_ZERO, GL_ONE }
#define SWIZZLES_RGB1 { GL_RED, GL_GREEN, GL_BLUE, GL_ONE }
#define SWIZZLES_RGBA { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA }
#define GL_FORMAT_INFO(internal_, external_, type_, swizzles_) \
.gl = { \ .gl = { \
.internal = internal_, \ .internal = internal_, \
.external = external_, \ .external = external_, \
.type = type_, \ .type = type_, \
.swizzles.array = SWIZZLES_ ## swizzles_, \
} }
#define GL_INTERNALFORMAT(fmt) .gl_internalformat = (fmt) #define GL_INTERNALFORMAT(fmt) .gl_internalformat = (fmt)
#define GL_FORMAT(fmt) .gl_format = (fmt) #define GL_FORMAT(fmt) .gl_format = (fmt)
#define GL_TYPE(type) .gl_type = (type) #define GL_TYPE(type) .gl_type = (type)
#define GL_CHANNEL_ORDER(order) \
.gl_channel_order = (SHADER_CHANNEL_ORDER_ ## order)
#define SAMPLER_TYPE(type) .sampler_type = (type) #define SAMPLER_TYPE(type) .sampler_type = (type)
#else #else
#define GL_FORMAT_INFO(internal_, external_, type_) \ #define GL_FORMAT_INFO(internal_, external_, type_, swizzles_) \
.gl = { \ .gl = { \
.internal = 0, \ .internal = 0, \
.external = 0, \ .external = 0, \
.type = 0, \ .type = 0, \
.swizzles.array = { 0, 0, 0, 0 }, \
} }
#define GL_INTERNALFORMAT(fmt) .gl_internalformat = 0 #define GL_INTERNALFORMAT(fmt) .gl_internalformat = 0
#define GL_FORMAT(fmt) .gl_format = 0 #define GL_FORMAT(fmt) .gl_format = 0
#define GL_TYPE(type) .gl_type = 0 #define GL_TYPE(type) .gl_type = 0
#define GL_CHANNEL_ORDER(order) .gl_channel_order = 0
#define SAMPLER_TYPE(type) .sampler_type = 0 #define SAMPLER_TYPE(type) .sampler_type = 0
#endif #endif
@ -106,7 +118,7 @@ static const struct pixel_format_info pixel_format_table[] = {
BITS_RGBA_FIXED(8, 0, 0, 0), BITS_RGBA_FIXED(8, 0, 0, 0),
.bpp = 8, .bpp = 8,
.hide_from_clients = true, .hide_from_clients = true,
GL_FORMAT_INFO(GL_R8, GL_RED, GL_UNSIGNED_BYTE), GL_FORMAT_INFO(GL_R8, GL_RED, GL_UNSIGNED_BYTE, R001),
GL_FORMAT(GL_R8_EXT), GL_FORMAT(GL_R8_EXT),
GL_TYPE(GL_UNSIGNED_BYTE), GL_TYPE(GL_UNSIGNED_BYTE),
}, },
@ -115,7 +127,7 @@ static const struct pixel_format_info pixel_format_table[] = {
BITS_RGBA_FIXED(8, 8, 0, 0), BITS_RGBA_FIXED(8, 8, 0, 0),
.bpp = 16, .bpp = 16,
.hide_from_clients = true, .hide_from_clients = true,
GL_FORMAT_INFO(GL_RG8, GL_RG, GL_UNSIGNED_BYTE), GL_FORMAT_INFO(GL_RG8, GL_RG, GL_UNSIGNED_BYTE, RG01),
GL_FORMAT(GL_RG8_EXT), GL_FORMAT(GL_RG8_EXT),
GL_TYPE(GL_UNSIGNED_BYTE), GL_TYPE(GL_UNSIGNED_BYTE),
}, },
@ -146,9 +158,11 @@ static const struct pixel_format_info pixel_format_table[] = {
BITS_RGBA_FIXED(4, 4, 4, 0), BITS_RGBA_FIXED(4, 4, 4, 0),
.bpp = 16, .bpp = 16,
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
GL_FORMAT_INFO(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4), GL_FORMAT_INFO(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, RGB1),
GL_FORMAT(GL_RGBA), GL_FORMAT(GL_RGBA),
GL_TYPE(GL_UNSIGNED_SHORT_4_4_4_4), GL_TYPE(GL_UNSIGNED_SHORT_4_4_4_4),
#else
GL_FORMAT_INFO(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, B1RG),
#endif #endif
}, },
{ {
@ -157,9 +171,11 @@ static const struct pixel_format_info pixel_format_table[] = {
.bpp = 16, .bpp = 16,
.opaque_substitute = DRM_FORMAT_RGBX4444, .opaque_substitute = DRM_FORMAT_RGBX4444,
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
GL_FORMAT_INFO(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4), GL_FORMAT_INFO(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, RGBA),
GL_FORMAT(GL_RGBA), GL_FORMAT(GL_RGBA),
GL_TYPE(GL_UNSIGNED_SHORT_4_4_4_4), GL_TYPE(GL_UNSIGNED_SHORT_4_4_4_4),
#else
GL_FORMAT_INFO(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, BARG),
#endif #endif
}, },
{ {
@ -201,7 +217,7 @@ static const struct pixel_format_info pixel_format_table[] = {
BITS_RGBA_FIXED(5, 5, 5, 0), BITS_RGBA_FIXED(5, 5, 5, 0),
.bpp = 16, .bpp = 16,
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
GL_FORMAT_INFO(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1), GL_FORMAT_INFO(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, RGB1),
GL_FORMAT(GL_RGBA), GL_FORMAT(GL_RGBA),
GL_TYPE(GL_UNSIGNED_SHORT_5_5_5_1), GL_TYPE(GL_UNSIGNED_SHORT_5_5_5_1),
#endif #endif
@ -212,7 +228,7 @@ static const struct pixel_format_info pixel_format_table[] = {
.bpp = 16, .bpp = 16,
.opaque_substitute = DRM_FORMAT_RGBX5551, .opaque_substitute = DRM_FORMAT_RGBX5551,
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
GL_FORMAT_INFO(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1), GL_FORMAT_INFO(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, RGBA),
GL_FORMAT(GL_RGBA), GL_FORMAT(GL_RGBA),
GL_TYPE(GL_UNSIGNED_SHORT_5_5_5_1), GL_TYPE(GL_UNSIGNED_SHORT_5_5_5_1),
#endif #endif
@ -234,7 +250,7 @@ static const struct pixel_format_info pixel_format_table[] = {
.addfb_legacy_depth = 16, .addfb_legacy_depth = 16,
.bpp = 16, .bpp = 16,
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
GL_FORMAT_INFO(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5), GL_FORMAT_INFO(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, RGB1),
GL_FORMAT(GL_RGB), GL_FORMAT(GL_RGB),
GL_TYPE(GL_UNSIGNED_SHORT_5_6_5), GL_TYPE(GL_UNSIGNED_SHORT_5_6_5),
PIXMAN_FMT(r5g6b5), PIXMAN_FMT(r5g6b5),
@ -249,16 +265,15 @@ static const struct pixel_format_info pixel_format_table[] = {
DRM_FORMAT(RGB888), DRM_FORMAT(RGB888),
BITS_RGBA_FIXED(8, 8, 8, 0), BITS_RGBA_FIXED(8, 8, 8, 0),
.bpp = 24, .bpp = 24,
GL_FORMAT_INFO(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE), GL_FORMAT_INFO(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, RGB1),
GL_FORMAT(GL_RGB), GL_FORMAT(GL_RGB),
GL_TYPE(GL_UNSIGNED_BYTE), GL_TYPE(GL_UNSIGNED_BYTE),
GL_CHANNEL_ORDER(BGRA),
}, },
{ {
DRM_FORMAT(BGR888), DRM_FORMAT(BGR888),
BITS_RGBA_FIXED(8, 8, 8, 0), BITS_RGBA_FIXED(8, 8, 8, 0),
.bpp = 24, .bpp = 24,
GL_FORMAT_INFO(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE), GL_FORMAT_INFO(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, BGR1),
GL_FORMAT(GL_RGB), GL_FORMAT(GL_RGB),
GL_TYPE(GL_UNSIGNED_BYTE), GL_TYPE(GL_UNSIGNED_BYTE),
}, },
@ -267,7 +282,7 @@ static const struct pixel_format_info pixel_format_table[] = {
BITS_RGBA_FIXED(8, 8, 8, 0), BITS_RGBA_FIXED(8, 8, 8, 0),
.addfb_legacy_depth = 24, .addfb_legacy_depth = 24,
.bpp = 32, .bpp = 32,
GL_FORMAT_INFO(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE), GL_FORMAT_INFO(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE, RGB1),
GL_INTERNALFORMAT(GL_RGB8), GL_INTERNALFORMAT(GL_RGB8),
GL_FORMAT(GL_BGRA_EXT), GL_FORMAT(GL_BGRA_EXT),
GL_TYPE(GL_UNSIGNED_BYTE), GL_TYPE(GL_UNSIGNED_BYTE),
@ -283,7 +298,7 @@ static const struct pixel_format_info pixel_format_table[] = {
.opaque_substitute = DRM_FORMAT_XRGB8888, .opaque_substitute = DRM_FORMAT_XRGB8888,
.addfb_legacy_depth = 32, .addfb_legacy_depth = 32,
.bpp = 32, .bpp = 32,
GL_FORMAT_INFO(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE), GL_FORMAT_INFO(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE, RGBA),
GL_INTERNALFORMAT(GL_RGBA8), GL_INTERNALFORMAT(GL_RGBA8),
GL_FORMAT(GL_BGRA_EXT), GL_FORMAT(GL_BGRA_EXT),
GL_TYPE(GL_UNSIGNED_BYTE), GL_TYPE(GL_UNSIGNED_BYTE),
@ -297,7 +312,7 @@ static const struct pixel_format_info pixel_format_table[] = {
DRM_FORMAT(XBGR8888), DRM_FORMAT(XBGR8888),
BITS_RGBA_FIXED(8, 8, 8, 0), BITS_RGBA_FIXED(8, 8, 8, 0),
.bpp = 32, .bpp = 32,
GL_FORMAT_INFO(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE), GL_FORMAT_INFO(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, RGB1),
GL_FORMAT(GL_RGBA), GL_FORMAT(GL_RGBA),
GL_TYPE(GL_UNSIGNED_BYTE), GL_TYPE(GL_UNSIGNED_BYTE),
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
@ -311,7 +326,7 @@ static const struct pixel_format_info pixel_format_table[] = {
BITS_RGBA_FIXED(8, 8, 8, 8), BITS_RGBA_FIXED(8, 8, 8, 8),
.bpp = 32, .bpp = 32,
.opaque_substitute = DRM_FORMAT_XBGR8888, .opaque_substitute = DRM_FORMAT_XBGR8888,
GL_FORMAT_INFO(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE), GL_FORMAT_INFO(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, RGBA),
GL_FORMAT(GL_RGBA), GL_FORMAT(GL_RGBA),
GL_TYPE(GL_UNSIGNED_BYTE), GL_TYPE(GL_UNSIGNED_BYTE),
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
@ -324,10 +339,9 @@ static const struct pixel_format_info pixel_format_table[] = {
DRM_FORMAT(RGBX8888), DRM_FORMAT(RGBX8888),
BITS_RGBA_FIXED(8, 8, 8, 0), BITS_RGBA_FIXED(8, 8, 8, 0),
.bpp = 32, .bpp = 32,
GL_FORMAT_INFO(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE), GL_FORMAT_INFO(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ABG1),
GL_FORMAT(GL_RGBA), GL_FORMAT(GL_RGBA),
GL_TYPE(GL_UNSIGNED_BYTE), GL_TYPE(GL_UNSIGNED_BYTE),
GL_CHANNEL_ORDER(ABGR),
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
PIXMAN_FMT(r8g8b8x8), PIXMAN_FMT(r8g8b8x8),
#else #else
@ -339,10 +353,9 @@ static const struct pixel_format_info pixel_format_table[] = {
BITS_RGBA_FIXED(8, 8, 8, 8), BITS_RGBA_FIXED(8, 8, 8, 8),
.bpp = 32, .bpp = 32,
.opaque_substitute = DRM_FORMAT_RGBX8888, .opaque_substitute = DRM_FORMAT_RGBX8888,
GL_FORMAT_INFO(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE), GL_FORMAT_INFO(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ABGR),
GL_FORMAT(GL_RGBA), GL_FORMAT(GL_RGBA),
GL_TYPE(GL_UNSIGNED_BYTE), GL_TYPE(GL_UNSIGNED_BYTE),
GL_CHANNEL_ORDER(ABGR),
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
PIXMAN_FMT(r8g8b8a8), PIXMAN_FMT(r8g8b8a8),
#else #else
@ -353,10 +366,9 @@ static const struct pixel_format_info pixel_format_table[] = {
DRM_FORMAT(BGRX8888), DRM_FORMAT(BGRX8888),
BITS_RGBA_FIXED(8, 8, 8, 0), BITS_RGBA_FIXED(8, 8, 8, 0),
.bpp = 32, .bpp = 32,
GL_FORMAT_INFO(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE), GL_FORMAT_INFO(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, GBA1),
GL_FORMAT(GL_RGBA), GL_FORMAT(GL_RGBA),
GL_TYPE(GL_UNSIGNED_BYTE), GL_TYPE(GL_UNSIGNED_BYTE),
GL_CHANNEL_ORDER(ARGB),
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
PIXMAN_FMT(b8g8r8x8), PIXMAN_FMT(b8g8r8x8),
#else #else
@ -368,10 +380,9 @@ static const struct pixel_format_info pixel_format_table[] = {
BITS_RGBA_FIXED(8, 8, 8, 8), BITS_RGBA_FIXED(8, 8, 8, 8),
.bpp = 32, .bpp = 32,
.opaque_substitute = DRM_FORMAT_BGRX8888, .opaque_substitute = DRM_FORMAT_BGRX8888,
GL_FORMAT_INFO(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE), GL_FORMAT_INFO(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, GBAR),
GL_FORMAT(GL_RGBA), GL_FORMAT(GL_RGBA),
GL_TYPE(GL_UNSIGNED_BYTE), GL_TYPE(GL_UNSIGNED_BYTE),
GL_CHANNEL_ORDER(ARGB),
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
PIXMAN_FMT(b8g8r8a8), PIXMAN_FMT(b8g8r8a8),
#else #else
@ -385,6 +396,7 @@ static const struct pixel_format_info pixel_format_table[] = {
.bpp = 32, .bpp = 32,
GL_INTERNALFORMAT(GL_RGB10_A2), GL_INTERNALFORMAT(GL_RGB10_A2),
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
GL_FORMAT_INFO(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, BGR1),
PIXMAN_FMT(x2r10g10b10), PIXMAN_FMT(x2r10g10b10),
#endif #endif
}, },
@ -395,6 +407,7 @@ static const struct pixel_format_info pixel_format_table[] = {
.opaque_substitute = DRM_FORMAT_XRGB2101010, .opaque_substitute = DRM_FORMAT_XRGB2101010,
GL_INTERNALFORMAT(GL_RGB10_A2), GL_INTERNALFORMAT(GL_RGB10_A2),
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
GL_FORMAT_INFO(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, BGRA),
PIXMAN_FMT(a2r10g10b10), PIXMAN_FMT(a2r10g10b10),
#endif #endif
}, },
@ -403,7 +416,7 @@ static const struct pixel_format_info pixel_format_table[] = {
BITS_RGBA_FIXED(10, 10, 10, 0), BITS_RGBA_FIXED(10, 10, 10, 0),
.bpp = 32, .bpp = 32,
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
GL_FORMAT_INFO(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV), GL_FORMAT_INFO(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, RGB1),
GL_FORMAT(GL_RGBA), GL_FORMAT(GL_RGBA),
GL_TYPE(GL_UNSIGNED_INT_2_10_10_10_REV_EXT), GL_TYPE(GL_UNSIGNED_INT_2_10_10_10_REV_EXT),
PIXMAN_FMT(x2b10g10r10), PIXMAN_FMT(x2b10g10r10),
@ -415,7 +428,7 @@ static const struct pixel_format_info pixel_format_table[] = {
.bpp = 32, .bpp = 32,
.opaque_substitute = DRM_FORMAT_XBGR2101010, .opaque_substitute = DRM_FORMAT_XBGR2101010,
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
GL_FORMAT_INFO(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV), GL_FORMAT_INFO(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, RGBA),
GL_FORMAT(GL_RGBA), GL_FORMAT(GL_RGBA),
GL_TYPE(GL_UNSIGNED_INT_2_10_10_10_REV_EXT), GL_TYPE(GL_UNSIGNED_INT_2_10_10_10_REV_EXT),
PIXMAN_FMT(a2b10g10r10), PIXMAN_FMT(a2b10g10r10),
@ -447,7 +460,7 @@ static const struct pixel_format_info pixel_format_table[] = {
DRM_FORMAT(XBGR16161616), DRM_FORMAT(XBGR16161616),
BITS_RGBA_FIXED(16, 16, 16, 0), BITS_RGBA_FIXED(16, 16, 16, 0),
.bpp = 64, .bpp = 64,
GL_FORMAT_INFO(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT), GL_FORMAT_INFO(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT, RGB1),
#if __BYTE_ORDER__ == __LITTLE_ENDIAN #if __BYTE_ORDER__ == __LITTLE_ENDIAN
GL_FORMAT(GL_RGBA16_EXT), GL_FORMAT(GL_RGBA16_EXT),
GL_TYPE(GL_UNSIGNED_SHORT), GL_TYPE(GL_UNSIGNED_SHORT),
@ -458,7 +471,7 @@ static const struct pixel_format_info pixel_format_table[] = {
BITS_RGBA_FIXED(16, 16, 16, 16), BITS_RGBA_FIXED(16, 16, 16, 16),
.bpp = 64, .bpp = 64,
.opaque_substitute = DRM_FORMAT_XBGR16161616, .opaque_substitute = DRM_FORMAT_XBGR16161616,
GL_FORMAT_INFO(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT), GL_FORMAT_INFO(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT, RGBA),
#if __BYTE_ORDER__ == __LITTLE_ENDIAN #if __BYTE_ORDER__ == __LITTLE_ENDIAN
GL_FORMAT(GL_RGBA16_EXT), GL_FORMAT(GL_RGBA16_EXT),
GL_TYPE(GL_UNSIGNED_SHORT), GL_TYPE(GL_UNSIGNED_SHORT),
@ -468,7 +481,7 @@ static const struct pixel_format_info pixel_format_table[] = {
DRM_FORMAT(XBGR16161616F), DRM_FORMAT(XBGR16161616F),
BITS_RGBA_FLOAT(16, 16, 16, 0), BITS_RGBA_FLOAT(16, 16, 16, 0),
.bpp = 64, .bpp = 64,
GL_FORMAT_INFO(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT), GL_FORMAT_INFO(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, RGB1),
#if __BYTE_ORDER__ == __LITTLE_ENDIAN #if __BYTE_ORDER__ == __LITTLE_ENDIAN
GL_FORMAT(GL_RGBA16F), GL_FORMAT(GL_RGBA16F),
GL_TYPE(GL_HALF_FLOAT), GL_TYPE(GL_HALF_FLOAT),
@ -479,7 +492,7 @@ static const struct pixel_format_info pixel_format_table[] = {
BITS_RGBA_FLOAT(16, 16, 16, 16), BITS_RGBA_FLOAT(16, 16, 16, 16),
.bpp = 64, .bpp = 64,
.opaque_substitute = DRM_FORMAT_XBGR16161616F, .opaque_substitute = DRM_FORMAT_XBGR16161616F,
GL_FORMAT_INFO(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT), GL_FORMAT_INFO(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, RGBA),
#if __BYTE_ORDER__ == __LITTLE_ENDIAN #if __BYTE_ORDER__ == __LITTLE_ENDIAN
GL_FORMAT(GL_RGBA16F), GL_FORMAT(GL_RGBA16F),
GL_TYPE(GL_HALF_FLOAT), GL_TYPE(GL_HALF_FLOAT),

View file

@ -28,14 +28,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <pixman.h> #include <pixman.h>
/* Keep the following in sync with fragment.glsl. */
enum gl_channel_order {
SHADER_CHANNEL_ORDER_RGBA = 0,
SHADER_CHANNEL_ORDER_BGRA,
SHADER_CHANNEL_ORDER_ARGB,
SHADER_CHANNEL_ORDER_ABGR,
};
/** /**
* GL format information to create and manage texture and renderbuffer objects. * GL format information to create and manage texture and renderbuffer objects.
*/ */
@ -55,9 +47,20 @@ struct gl_format_info {
* DRM_FORMAT_RGBA8888 maps to GL_RGBA / GL_UNSIGNED_BYTE). However, GL * DRM_FORMAT_RGBA8888 maps to GL_RGBA / GL_UNSIGNED_BYTE). However, GL
* depends on CPU endianness for special types packing all components * depends on CPU endianness for special types packing all components
* in a single type (e.g. DRM_FORMAT_RGBA4444 maps to GL_RGBA / * in a single type (e.g. DRM_FORMAT_RGBA4444 maps to GL_RGBA /
* GL_UNSIGNED_SHORT_4_4_4_4). */ * GL_UNSIGNED_SHORT_4_4_4_4). Different swizzles (see below) must be
* provided in that case in order to support the format on both
* little-endian and big-endian CPUs (e.g. RGBA on little-endian CPUs
* and BARG on big-endian CPUs for DRM_FORMAT_RGBA4444).*/
unsigned int external; unsigned int external;
unsigned int type; unsigned int type;
/** Swizzles to reorder color components of texture samples. Supported
* values are: GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_ZERO and
* GL_ONE. */
union {
struct { int r, g, b, a; };
int array[4];
} swizzles;
}; };
/** /**
@ -113,11 +116,6 @@ struct pixel_format_info {
/** GL data type, if data can be natively/directly uploaded. */ /** GL data type, if data can be natively/directly uploaded. */
int gl_type; int gl_type;
/** This enumeration tells the resulting order of the color channels
* when the DRM formatted pixel data is read with the given gl_format
* and gl_type. */
enum gl_channel_order gl_channel_order;
/** Pixman data type, if it agrees exactly with the wl_shm format */ /** Pixman data type, if it agrees exactly with the wl_shm format */
pixman_format_code_t pixman_format; pixman_format_code_t pixman_format;

View file

@ -54,12 +54,6 @@
#define SHADER_COLOR_MAPPING_3DLUT 1 #define SHADER_COLOR_MAPPING_3DLUT 1
#define SHADER_COLOR_MAPPING_MATRIX 2 #define SHADER_COLOR_MAPPING_MATRIX 2
/* enum gl_channel_order */
#define SHADER_CHANNEL_ORDER_RGBA 0
#define SHADER_CHANNEL_ORDER_BGRA 1
#define SHADER_CHANNEL_ORDER_ARGB 2
#define SHADER_CHANNEL_ORDER_ABGR 3
#if DEF_VARIANT == SHADER_VARIANT_EXTERNAL #if DEF_VARIANT == SHADER_VARIANT_EXTERNAL
#extension GL_OES_EGL_image_external : require #extension GL_OES_EGL_image_external : require
#endif #endif
@ -84,7 +78,6 @@ compile_const int c_variant = DEF_VARIANT;
compile_const int c_color_pre_curve = DEF_COLOR_PRE_CURVE; compile_const int c_color_pre_curve = DEF_COLOR_PRE_CURVE;
compile_const int c_color_mapping = DEF_COLOR_MAPPING; compile_const int c_color_mapping = DEF_COLOR_MAPPING;
compile_const int c_color_post_curve = DEF_COLOR_POST_CURVE; compile_const int c_color_post_curve = DEF_COLOR_POST_CURVE;
compile_const int c_color_channel_order = DEF_COLOR_CHANNEL_ORDER;
compile_const bool c_input_is_premult = DEF_INPUT_IS_PREMULT; compile_const bool c_input_is_premult = DEF_INPUT_IS_PREMULT;
compile_const bool c_tint = DEF_TINT; compile_const bool c_tint = DEF_TINT;
@ -173,16 +166,7 @@ sample_input_texture()
if (c_variant == SHADER_VARIANT_RGBA || if (c_variant == SHADER_VARIANT_RGBA ||
c_variant == SHADER_VARIANT_RGBX) { c_variant == SHADER_VARIANT_RGBX) {
vec4 color; vec4 color = texture2D(tex, v_texcoord);
if (c_color_channel_order == SHADER_CHANNEL_ORDER_BGRA)
color = texture2D(tex, v_texcoord).bgra;
else if (c_color_channel_order == SHADER_CHANNEL_ORDER_ARGB)
color = texture2D(tex, v_texcoord).gbar;
else if (c_color_channel_order == SHADER_CHANNEL_ORDER_ABGR)
color = texture2D(tex, v_texcoord).abgr;
else
color = texture2D(tex, v_texcoord);
if (c_variant == SHADER_VARIANT_RGBX) if (c_variant == SHADER_VARIANT_RGBX)
color.a = 1.0; color.a = 1.0;

View file

@ -287,13 +287,12 @@ struct gl_shader_requirements
unsigned color_pre_curve:2; /* enum gl_shader_color_curve */ unsigned color_pre_curve:2; /* enum gl_shader_color_curve */
unsigned color_mapping:2; /* enum gl_shader_color_mapping */ unsigned color_mapping:2; /* enum gl_shader_color_mapping */
unsigned color_post_curve:2; /* enum gl_shader_color_curve */ unsigned color_post_curve:2; /* enum gl_shader_color_curve */
unsigned color_channel_order:2; /* enum gl_channel_order */
/* /*
* The total size of all bitfields plus pad_bits_ must fill up exactly * The total size of all bitfields plus pad_bits_ must fill up exactly
* how many bytes the compiler allocates for them together. * how many bytes the compiler allocates for them together.
*/ */
unsigned pad_bits_:16; unsigned pad_bits_:18;
}; };
static_assert(sizeof(struct gl_shader_requirements) == static_assert(sizeof(struct gl_shader_requirements) ==
4 /* total bitfield size in bytes */, 4 /* total bitfield size in bytes */,

View file

@ -237,7 +237,6 @@ struct gl_buffer_state {
/* Only needed between attach() and flush_damage() */ /* Only needed between attach() and flush_damage() */
int pitch; /* plane 0 pitch in pixels */ int pitch; /* plane 0 pitch in pixels */
enum gl_channel_order gl_channel_order;
int offset[3]; /* per-plane pitch in bytes */ int offset[3]; /* per-plane pitch in bytes */
EGLImageKHR images[3]; EGLImageKHR images[3];
@ -1347,7 +1346,6 @@ gl_shader_config_set_input_textures(struct gl_shader_config *sconf,
struct gl_buffer_state *gb) struct gl_buffer_state *gb)
{ {
sconf->req.variant = gb->shader_variant; sconf->req.variant = gb->shader_variant;
sconf->req.color_channel_order = gb->gl_channel_order;
sconf->req.input_is_premult = sconf->req.input_is_premult =
gl_shader_texture_variant_can_be_premult(gb->shader_variant); gl_shader_texture_variant_can_be_premult(gb->shader_variant);
@ -2861,7 +2859,6 @@ gl_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer)
gb->pitch = pitch; gb->pitch = pitch;
gb->shader_variant = shader_variant; gb->shader_variant = shader_variant;
ARRAY_COPY(gb->offset, offset); ARRAY_COPY(gb->offset, offset);
gb->gl_channel_order = buffer->pixel_format->gl_channel_order;
ARRAY_COPY(gb->texture_format, texture_format); ARRAY_COPY(gb->texture_format, texture_format);
gb->needs_full_upload = true; gb->needs_full_upload = true;
gb->num_textures = num_planes; gb->num_textures = num_planes;
@ -2876,7 +2873,8 @@ gl_renderer_attach_shm(struct weston_surface *es, struct weston_buffer *buffer)
buffer->width / hsub, buffer->height / vsub, buffer->width / hsub, buffer->height / vsub,
&gb->textures[i]); &gb->textures[i]);
gl_texture_parameters_init(gr, &gb->parameters[i], gl_texture_parameters_init(gr, &gb->parameters[i],
GL_TEXTURE_2D, NULL, NULL, NULL, GL_TEXTURE_2D, NULL, NULL,
texture_format[i].swizzles.array,
false); false);
} }
} }

View file

@ -155,21 +155,6 @@ gl_shader_color_mapping_to_string(enum gl_shader_color_mapping kind)
return "!?!?"; /* never reached */ return "!?!?"; /* never reached */
} }
static const char *
gl_shader_color_order_to_string(enum gl_channel_order kind)
{
switch (kind) {
#define CASERET(x) case x: return #x;
CASERET(SHADER_CHANNEL_ORDER_RGBA)
CASERET(SHADER_CHANNEL_ORDER_BGRA)
CASERET(SHADER_CHANNEL_ORDER_ARGB)
CASERET(SHADER_CHANNEL_ORDER_ABGR)
#undef CASERET
}
return "!?!?"; /* never reached */
}
static void static void
dump_program_with_line_numbers(int count, const char **sources) dump_program_with_line_numbers(int count, const char **sources)
{ {
@ -235,13 +220,12 @@ create_shader_description_string(const struct gl_shader_requirements *req)
int size; int size;
char *str; char *str;
size = asprintf(&str, "%s %s %s %s %s %s %cinput_is_premult %ctint", size = asprintf(&str, "%s %s %s %s %s %cinput_is_premult %ctint",
gl_shader_texcoord_input_to_string(req->texcoord_input), gl_shader_texcoord_input_to_string(req->texcoord_input),
gl_shader_texture_variant_to_string(req->variant), gl_shader_texture_variant_to_string(req->variant),
gl_shader_color_curve_to_string(req->color_pre_curve), gl_shader_color_curve_to_string(req->color_pre_curve),
gl_shader_color_mapping_to_string(req->color_mapping), gl_shader_color_mapping_to_string(req->color_mapping),
gl_shader_color_curve_to_string(req->color_post_curve), gl_shader_color_curve_to_string(req->color_post_curve),
gl_shader_color_order_to_string(req->color_channel_order),
req->input_is_premult ? '+' : '-', req->input_is_premult ? '+' : '-',
req->tint ? '+' : '-'); req->tint ? '+' : '-');
if (size < 0) if (size < 0)
@ -272,10 +256,6 @@ create_fragment_shader_config_string(const struct gl_shader_requirements *req)
int size; int size;
char *str; char *str;
/* EXTERNAL can only be used with identity swizzle */
assert(req->variant != SHADER_VARIANT_EXTERNAL ||
req->color_channel_order == SHADER_CHANNEL_ORDER_RGBA);
size = asprintf(&str, size = asprintf(&str,
"#define DEF_TINT %s\n" "#define DEF_TINT %s\n"
"#define DEF_INPUT_IS_PREMULT %s\n" "#define DEF_INPUT_IS_PREMULT %s\n"
@ -283,7 +263,6 @@ create_fragment_shader_config_string(const struct gl_shader_requirements *req)
"#define DEF_COLOR_PRE_CURVE %s\n" "#define DEF_COLOR_PRE_CURVE %s\n"
"#define DEF_COLOR_MAPPING %s\n" "#define DEF_COLOR_MAPPING %s\n"
"#define DEF_COLOR_POST_CURVE %s\n" "#define DEF_COLOR_POST_CURVE %s\n"
"#define DEF_COLOR_CHANNEL_ORDER %s\n"
"#define DEF_VARIANT %s\n", "#define DEF_VARIANT %s\n",
req->tint ? "true" : "false", req->tint ? "true" : "false",
req->input_is_premult ? "true" : "false", req->input_is_premult ? "true" : "false",
@ -291,7 +270,6 @@ create_fragment_shader_config_string(const struct gl_shader_requirements *req)
gl_shader_color_curve_to_string(req->color_pre_curve), gl_shader_color_curve_to_string(req->color_pre_curve),
gl_shader_color_mapping_to_string(req->color_mapping), gl_shader_color_mapping_to_string(req->color_mapping),
gl_shader_color_curve_to_string(req->color_post_curve), gl_shader_color_curve_to_string(req->color_post_curve),
gl_shader_color_order_to_string(req->color_channel_order),
gl_shader_texture_variant_to_string(req->variant)); gl_shader_texture_variant_to_string(req->variant));
if (size < 0) if (size < 0)
return NULL; return NULL;