@ -32,6 +32,9 @@
# define RRR1_SWIZZLE { PIPE_SWIZZLE_RED, PIPE_SWIZZLE_RED, PIPE_SWIZZLE_RED, PIPE_SWIZZLE_ONE }
# define RRR1_SWIZZLE { PIPE_SWIZZLE_RED, PIPE_SWIZZLE_RED, PIPE_SWIZZLE_RED, PIPE_SWIZZLE_ONE }
# define RGB1_SWIZZLE { PIPE_SWIZZLE_RED, PIPE_SWIZZLE_GREEN, PIPE_SWIZZLE_BLUE, PIPE_SWIZZLE_ONE }
# define RGB1_SWIZZLE { PIPE_SWIZZLE_RED, PIPE_SWIZZLE_GREEN, PIPE_SWIZZLE_BLUE, PIPE_SWIZZLE_ONE }
# define BGR1_SWIZZLE { PIPE_SWIZZLE_BLUE, PIPE_SWIZZLE_GREEN, PIPE_SWIZZLE_RED, PIPE_SWIZZLE_ONE }
# define BGRA_SWIZZLE { PIPE_SWIZZLE_BLUE, PIPE_SWIZZLE_GREEN, PIPE_SWIZZLE_RED, PIPE_SWIZZLE_ALPHA }
# ifdef __GNUC__
# ifdef __GNUC__
/* The warning missing-field-initializers is misleading: If at least one field
/* The warning missing-field-initializers is misleading: If at least one field
* is initialized , then the un - initialized fields will be filled with zero .
* is initialized , then the un - initialized fields will be filled with zero .
@ -50,9 +53,6 @@
/* fill the format table */
/* fill the format table */
static struct vrend_format_table base_rgba_formats [ ] =
static struct vrend_format_table base_rgba_formats [ ] =
{
{
{ VIRGL_FORMAT_B8G8R8X8_UNORM , GL_RGBA8 , GL_BGRA , GL_UNSIGNED_BYTE , RGB1_SWIZZLE } ,
{ VIRGL_FORMAT_B8G8R8A8_UNORM , GL_RGBA8 , GL_BGRA , GL_UNSIGNED_BYTE , NO_SWIZZLE } ,
{ VIRGL_FORMAT_R8G8B8X8_UNORM , GL_RGBA8 , GL_RGBA , GL_UNSIGNED_BYTE , RGB1_SWIZZLE } ,
{ VIRGL_FORMAT_R8G8B8X8_UNORM , GL_RGBA8 , GL_RGBA , GL_UNSIGNED_BYTE , RGB1_SWIZZLE } ,
{ VIRGL_FORMAT_R8G8B8A8_UNORM , GL_RGBA8 , GL_RGBA , GL_UNSIGNED_BYTE , NO_SWIZZLE } ,
{ VIRGL_FORMAT_R8G8B8A8_UNORM , GL_RGBA8 , GL_RGBA , GL_UNSIGNED_BYTE , NO_SWIZZLE } ,
@ -280,11 +280,25 @@ static struct vrend_format_table bptc_formats[] = {
{ VIRGL_FORMAT_BPTC_RGB_UFLOAT , GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT , GL_RGB , GL_UNSIGNED_BYTE , NO_SWIZZLE } ,
{ VIRGL_FORMAT_BPTC_RGB_UFLOAT , GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT , GL_RGB , GL_UNSIGNED_BYTE , NO_SWIZZLE } ,
} ;
} ;
static struct vrend_format_table gl_bgra_formats [ ] = {
{ VIRGL_FORMAT_B8G8R8X8_UNORM , GL_RGBA8 , GL_BGRA , GL_UNSIGNED_BYTE , RGB1_SWIZZLE } ,
{ VIRGL_FORMAT_B8G8R8A8_UNORM , GL_RGBA8 , GL_BGRA , GL_UNSIGNED_BYTE , NO_SWIZZLE } ,
} ;
static struct vrend_format_table gles_bgra_formats [ ] = {
static struct vrend_format_table gles_bgra_formats [ ] = {
{ VIRGL_FORMAT_B8G8R8X8_UNORM , GL_BGRA_EXT , GL_BGRA_EXT , GL_UNSIGNED_BYTE , RGB1_SWIZZLE } ,
{ VIRGL_FORMAT_B8G8R8X8_UNORM , GL_BGRA_EXT , GL_BGRA_EXT , GL_UNSIGNED_BYTE , RGB1_SWIZZLE } ,
{ VIRGL_FORMAT_B8G8R8A8_UNORM , GL_BGRA_EXT , GL_BGRA_EXT , GL_UNSIGNED_BYTE , NO_SWIZZLE } ,
{ VIRGL_FORMAT_B8G8R8A8_UNORM , GL_BGRA_EXT , GL_BGRA_EXT , GL_UNSIGNED_BYTE , NO_SWIZZLE } ,
} ;
} ;
static struct vrend_format_table gles_bgra_formats_emulation [ ] = {
{ VIRGL_FORMAT_B8G8R8X8_UNORM_EMULATED , GL_RGBA8 , GL_RGBA , GL_UNSIGNED_BYTE , BGR1_SWIZZLE } ,
{ VIRGL_FORMAT_B8G8R8A8_UNORM_EMULATED , GL_RGBA8 , GL_RGBA , GL_UNSIGNED_BYTE , BGRA_SWIZZLE } ,
{ VIRGL_FORMAT_B8G8R8X8_SRGB , GL_SRGB8_ALPHA8 , GL_RGBA , GL_UNSIGNED_BYTE , BGR1_SWIZZLE } ,
{ VIRGL_FORMAT_B8G8R8A8_SRGB , GL_SRGB8_ALPHA8 , GL_RGBA , GL_UNSIGNED_BYTE , BGRA_SWIZZLE } ,
} ;
static struct vrend_format_table gles_z32_format [ ] = {
static struct vrend_format_table gles_z32_format [ ] = {
{ VIRGL_FORMAT_Z32_UNORM , GL_DEPTH_COMPONENT24 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT , NO_SWIZZLE } ,
{ VIRGL_FORMAT_Z32_UNORM , GL_DEPTH_COMPONENT24 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT , NO_SWIZZLE } ,
} ;
} ;
@ -378,6 +392,7 @@ static void vrend_add_formats(struct vrend_format_table *table, int num_entries)
/* we can't probe compressed formats, as we'd need valid payloads to
/* we can't probe compressed formats, as we'd need valid payloads to
* glCompressedTexImage2D . Let ' s just check for extensions instead .
* glCompressedTexImage2D . Let ' s just check for extensions instead .
*/
*/
if ( table [ i ] . format < VIRGL_FORMAT_MAX ) {
const struct util_format_description * desc = util_format_description ( table [ i ] . format ) ;
const struct util_format_description * desc = util_format_description ( table [ i ] . format ) ;
switch ( desc - > layout ) {
switch ( desc - > layout ) {
case UTIL_FORMAT_LAYOUT_S3TC :
case UTIL_FORMAT_LAYOUT_S3TC :
@ -406,6 +421,7 @@ static void vrend_add_formats(struct vrend_format_table *table, int num_entries)
default :
default :
; /* do logic below */
; /* do logic below */
}
}
}
/* The error state should be clear here */
/* The error state should be clear here */
status = glGetError ( ) ;
status = glGetError ( ) ;
@ -441,7 +457,7 @@ static void vrend_add_formats(struct vrend_format_table *table, int num_entries)
continue ;
continue ;
}
}
if ( util_format_is_depth_or_stencil ( table [ i ] . format ) ) {
if ( table [ i ] . format < VIRGL_FORMAT_MAX & & util_format_is_depth_or_stencil ( table [ i ] . format ) ) {
GLenum attachment ;
GLenum attachment ;
if ( table [ i ] . format = = VIRGL_FORMAT_Z24X8_UNORM | | table [ i ] . format = = VIRGL_FORMAT_Z32_UNORM | | table [ i ] . format = = VIRGL_FORMAT_Z16_UNORM | | table [ i ] . format = = VIRGL_FORMAT_Z32_FLOAT )
if ( table [ i ] . format = = VIRGL_FORMAT_Z24X8_UNORM | | table [ i ] . format = = VIRGL_FORMAT_Z32_UNORM | | table [ i ] . format = = VIRGL_FORMAT_Z16_UNORM | | table [ i ] . format = = VIRGL_FORMAT_Z32_FLOAT )
@ -472,6 +488,14 @@ static void vrend_add_formats(struct vrend_format_table *table, int num_entries)
flags | = VIRGL_TEXTURE_CAN_READBACK ;
flags | = VIRGL_TEXTURE_CAN_READBACK ;
}
}
if ( i = = VIRGL_FORMAT_B8G8R8A8_UNORM_EMULATED ) {
table [ VIRGL_FORMAT_B8G8R8A8_UNORM ] . flags | = VIRGL_TEXTURE_CAN_READBACK ;
binding | = VIRGL_BIND_PREFER_EMULATED_BGRA ;
} else if ( i = = VIRGL_FORMAT_B8G8R8X8_UNORM_EMULATED ) {
table [ VIRGL_FORMAT_B8G8R8X8_UNORM ] . flags | = VIRGL_TEXTURE_CAN_READBACK ;
binding | = VIRGL_BIND_PREFER_EMULATED_BGRA ;
}
glDeleteTextures ( 1 , & tex_id ) ;
glDeleteTextures ( 1 , & tex_id ) ;
glDeleteFramebuffers ( 1 , & fb_id ) ;
glDeleteFramebuffers ( 1 , & fb_id ) ;
@ -533,6 +557,7 @@ void vrend_build_format_list_gl(void)
* transfer operations . So we only register support for it in GL .
* transfer operations . So we only register support for it in GL .
*/
*/
add_formats ( gl_base_rgba_formats ) ;
add_formats ( gl_base_rgba_formats ) ;
add_formats ( gl_bgra_formats ) ;
add_formats ( gl_srgb_formats ) ;
add_formats ( gl_srgb_formats ) ;
}
}
@ -553,6 +578,11 @@ void vrend_build_format_list_gles(void)
add_formats ( gles_bit10_formats ) ;
add_formats ( gles_bit10_formats ) ;
}
}
void vrend_build_emulated_format_list_gles ( void )
{
add_formats ( gles_bgra_formats_emulation ) ;
}
/* glTexStorage may not support all that is supported by glTexImage,
/* glTexStorage may not support all that is supported by glTexImage,
* so add a flag to indicate when it can be used .
* so add a flag to indicate when it can be used .
*/
*/
@ -560,9 +590,10 @@ void vrend_check_texture_storage(struct vrend_format_table *table)
{
{
int i ;
int i ;
GLuint tex_id ;
GLuint tex_id ;
for ( i = 0 ; i < VIRGL_FORMAT_MAX ; i + + ) {
for ( i = 0 ; i < VIRGL_FORMAT_MAX_EXTENDED ; i + + ) {
if ( table [ i ] . internalformat ! = 0 ) {
if ( table [ i ] . internalformat ! = 0 & &
! ( table [ i ] . flags & VIRGL_TEXTURE_CAN_TEXTURE_STORAGE ) ) {
glGenTextures ( 1 , & tex_id ) ;
glGenTextures ( 1 , & tex_id ) ;
glBindTexture ( GL_TEXTURE_2D , tex_id ) ;
glBindTexture ( GL_TEXTURE_2D , tex_id ) ;
glTexStorage2D ( GL_TEXTURE_2D , 1 , table [ i ] . internalformat , 32 , 32 ) ;
glTexStorage2D ( GL_TEXTURE_2D , 1 , table [ i ] . internalformat , 32 , 32 ) ;