@ -2372,9 +2372,9 @@ static void vrend_hw_set_zsurf_texture(struct vrend_context *ctx)
}
}
}
}
static void vrend_hw_set_color_surface ( struct vrend_context * ctx , int index )
static void vrend_hw_set_color_surface ( struct vrend_sub_ context * sub_ ctx, int index )
{
{
struct vrend_surface * surf = ctx - > sub - > surf [ index ] ;
struct vrend_surface * surf = sub_ ctx- > surf [ index ] ;
if ( ! surf ) {
if ( ! surf ) {
GLenum attachment = GL_COLOR_ATTACHMENT0 + index ;
GLenum attachment = GL_COLOR_ATTACHMENT0 + index ;
@ -2382,15 +2382,15 @@ static void vrend_hw_set_color_surface(struct vrend_context *ctx, int index)
glFramebufferTexture2D ( GL_FRAMEBUFFER , attachment ,
glFramebufferTexture2D ( GL_FRAMEBUFFER , attachment ,
GL_TEXTURE_2D , 0 , 0 ) ;
GL_TEXTURE_2D , 0 , 0 ) ;
} else {
} else {
uint32_t first_layer = ctx - > sub - > surf [ index ] - > val1 & 0xffff ;
uint32_t first_layer = sub_ ctx- > surf [ index ] - > val1 & 0xffff ;
uint32_t last_layer = ( ctx - > sub - > surf [ index ] - > val1 > > 16 ) & 0xffff ;
uint32_t last_layer = ( sub_ ctx- > surf [ index ] - > val1 > > 16 ) & 0xffff ;
vrend_fb_bind_texture_id ( surf - > texture , surf - > id , index , surf - > val0 ,
vrend_fb_bind_texture_id ( surf - > texture , surf - > id , index , surf - > val0 ,
first_layer ! = last_layer ? 0xffffffff : first_layer ) ;
first_layer ! = last_layer ? 0xffffffff : first_layer ) ;
}
}
}
}
static void vrend_hw_emit_framebuffer_state ( struct vrend_context * ctx )
static void vrend_hw_emit_framebuffer_state ( struct vrend_sub_ context * sub_ ctx)
{
{
static const GLenum buffers [ 8 ] = {
static const GLenum buffers [ 8 ] = {
GL_COLOR_ATTACHMENT0 ,
GL_COLOR_ATTACHMENT0 ,
@ -2403,19 +2403,19 @@ static void vrend_hw_emit_framebuffer_state(struct vrend_context *ctx)
GL_COLOR_ATTACHMENT7 ,
GL_COLOR_ATTACHMENT7 ,
} ;
} ;
if ( ctx - > sub - > nr_cbufs = = 0 ) {
if ( sub_ ctx- > nr_cbufs = = 0 ) {
glReadBuffer ( GL_NONE ) ;
glReadBuffer ( GL_NONE ) ;
if ( has_feature ( feat_srgb_write_control ) ) {
if ( has_feature ( feat_srgb_write_control ) ) {
glDisable ( GL_FRAMEBUFFER_SRGB_EXT ) ;
glDisable ( GL_FRAMEBUFFER_SRGB_EXT ) ;
ctx - > sub - > framebuffer_srgb_enabled = false ;
sub_ ctx- > framebuffer_srgb_enabled = false ;
}
}
} else if ( has_feature ( feat_srgb_write_control ) ) {
} else if ( has_feature ( feat_srgb_write_control ) ) {
struct vrend_surface * surf = NULL ;
struct vrend_surface * surf = NULL ;
bool use_srgb = false ;
bool use_srgb = false ;
int i ;
int i ;
for ( i = 0 ; i < ctx - > sub - > nr_cbufs ; i + + ) {
for ( i = 0 ; i < sub_ ctx- > nr_cbufs ; i + + ) {
if ( ctx - > sub - > surf [ i ] ) {
if ( sub_ ctx- > surf [ i ] ) {
surf = ctx - > sub - > surf [ i ] ;
surf = sub_ ctx- > surf [ i ] ;
if ( util_format_is_srgb ( surf - > format ) ) {
if ( util_format_is_srgb ( surf - > format ) ) {
use_srgb = true ;
use_srgb = true ;
}
}
@ -2426,25 +2426,25 @@ static void vrend_hw_emit_framebuffer_state(struct vrend_context *ctx)
} else {
} else {
glDisable ( GL_FRAMEBUFFER_SRGB_EXT ) ;
glDisable ( GL_FRAMEBUFFER_SRGB_EXT ) ;
}
}
ctx - > sub - > framebuffer_srgb_enabled = use_srgb ;
sub_ ctx- > framebuffer_srgb_enabled = use_srgb ;
}
}
if ( vrend_state . use_gles & &
if ( vrend_state . use_gles & &
vrend_get_tweak_is_active ( & ctx - > sub - > tweaks , virgl_tweak_gles_brga_apply_dest_swizzle ) ) {
vrend_get_tweak_is_active ( & sub_ ctx- > tweaks , virgl_tweak_gles_brga_apply_dest_swizzle ) ) {
ctx - > sub - > swizzle_output_rgb_to_bgr = 0 ;
sub_ ctx- > swizzle_output_rgb_to_bgr = 0 ;
for ( int i = 0 ; i < ctx - > sub - > nr_cbufs ; i + + ) {
for ( int i = 0 ; i < sub_ ctx- > nr_cbufs ; i + + ) {
if ( ctx - > sub - > surf [ i ] ) {
if ( sub_ ctx- > surf [ i ] ) {
struct vrend_surface * surf = ctx - > sub - > surf [ i ] ;
struct vrend_surface * surf = sub_ ctx- > surf [ i ] ;
if ( surf - > texture - > base . bind & VIRGL_BIND_PREFER_EMULATED_BGRA ) {
if ( surf - > texture - > base . bind & VIRGL_BIND_PREFER_EMULATED_BGRA ) {
VREND_DEBUG ( dbg_tweak , ctx , " Swizzled BGRA output for 0x%x (%s) \n " , i , util_format_name ( surf - > format ) ) ;
VREND_DEBUG ( dbg_tweak , sub_ ctx- > parent , " Swizzled BGRA output for 0x%x (%s) \n " , i , util_format_name ( surf - > format ) ) ;
ctx - > sub - > swizzle_output_rgb_to_bgr | = 1 < < i ;
sub_ ctx- > swizzle_output_rgb_to_bgr | = 1 < < i ;
}
}
}
}
}
}
}
}
glDrawBuffers ( ctx - > sub - > nr_cbufs , buffers ) ;
glDrawBuffers ( sub_ ctx- > nr_cbufs , buffers ) ;
}
}
void vrend_set_framebuffer_state ( struct vrend_context * ctx ,
void vrend_set_framebuffer_state ( struct vrend_context * ctx ,
@ -2458,10 +2458,12 @@ void vrend_set_framebuffer_state(struct vrend_context *ctx,
GLint new_height = - 1 ;
GLint new_height = - 1 ;
bool new_ibf = false ;
bool new_ibf = false ;
glBindFramebuffer ( GL_FRAMEBUFFER , ctx - > sub - > fb_id ) ;
struct vrend_sub_context * sub_ctx = ctx - > sub ;
glBindFramebuffer ( GL_FRAMEBUFFER , sub_ctx - > fb_id ) ;
if ( zsurf_handle ) {
if ( zsurf_handle ) {
zsurf = vrend_object_lookup ( ctx - > sub - > object_hash , zsurf_handle , VIRGL_OBJECT_SURFACE ) ;
zsurf = vrend_object_lookup ( sub_ ctx- > object_hash , zsurf_handle , VIRGL_OBJECT_SURFACE ) ;
if ( ! zsurf ) {
if ( ! zsurf ) {
vrend_report_context_error ( ctx , VIRGL_ERROR_CTX_ILLEGAL_SURFACE , zsurf_handle ) ;
vrend_report_context_error ( ctx , VIRGL_ERROR_CTX_ILLEGAL_SURFACE , zsurf_handle ) ;
return ;
return ;
@ -2469,18 +2471,18 @@ void vrend_set_framebuffer_state(struct vrend_context *ctx,
} else
} else
zsurf = NULL ;
zsurf = NULL ;
if ( ctx - > sub - > zsurf ! = zsurf ) {
if ( sub_ ctx- > zsurf ! = zsurf ) {
vrend_surface_reference ( & ctx - > sub - > zsurf , zsurf ) ;
vrend_surface_reference ( & sub_ ctx- > zsurf , zsurf ) ;
vrend_hw_set_zsurf_texture ( ctx ) ;
vrend_hw_set_zsurf_texture ( ctx ) ;
}
}
old_num = ctx - > sub - > nr_cbufs ;
old_num = sub_ ctx- > nr_cbufs ;
ctx - > sub - > nr_cbufs = nr_cbufs ;
sub_ ctx- > nr_cbufs = nr_cbufs ;
ctx - > sub - > old_nr_cbufs = old_num ;
sub_ ctx- > old_nr_cbufs = old_num ;
for ( i = 0 ; i < ( int ) nr_cbufs ; i + + ) {
for ( i = 0 ; i < ( int ) nr_cbufs ; i + + ) {
if ( surf_handle [ i ] ! = 0 ) {
if ( surf_handle [ i ] ! = 0 ) {
surf = vrend_object_lookup ( ctx - > sub - > object_hash , surf_handle [ i ] , VIRGL_OBJECT_SURFACE ) ;
surf = vrend_object_lookup ( sub_ ctx- > object_hash , surf_handle [ i ] , VIRGL_OBJECT_SURFACE ) ;
if ( ! surf ) {
if ( ! surf ) {
vrend_report_context_error ( ctx , VIRGL_ERROR_CTX_ILLEGAL_SURFACE , surf_handle [ i ] ) ;
vrend_report_context_error ( ctx , VIRGL_ERROR_CTX_ILLEGAL_SURFACE , surf_handle [ i ] ) ;
return ;
return ;
@ -2488,32 +2490,32 @@ void vrend_set_framebuffer_state(struct vrend_context *ctx,
} else
} else
surf = NULL ;
surf = NULL ;
if ( ctx - > sub - > surf [ i ] ! = surf ) {
if ( sub_ ctx- > surf [ i ] ! = surf ) {
vrend_surface_reference ( & ctx - > sub - > surf [ i ] , surf ) ;
vrend_surface_reference ( & sub_ ctx- > surf [ i ] , surf ) ;
vrend_hw_set_color_surface ( ctx , i ) ;
vrend_hw_set_color_surface ( sub_ ctx, i ) ;
}
}
}
}
if ( old_num > ctx - > sub - > nr_cbufs ) {
if ( old_num > sub_ ctx- > nr_cbufs ) {
for ( i = ctx - > sub - > nr_cbufs ; i < old_num ; i + + ) {
for ( i = sub_ ctx- > nr_cbufs ; i < old_num ; i + + ) {
vrend_surface_reference ( & ctx - > sub - > surf [ i ] , NULL ) ;
vrend_surface_reference ( & sub_ ctx- > surf [ i ] , NULL ) ;
vrend_hw_set_color_surface ( ctx , i ) ;
vrend_hw_set_color_surface ( sub_ ctx, i ) ;
}
}
}
}
/* find a buffer to set fb_height from */
/* find a buffer to set fb_height from */
if ( ctx - > sub - > nr_cbufs = = 0 & & ! ctx - > sub - > zsurf ) {
if ( sub_ ctx- > nr_cbufs = = 0 & & ! sub_ ctx- > zsurf ) {
new_height = 0 ;
new_height = 0 ;
new_ibf = false ;
new_ibf = false ;
} else if ( ctx - > sub - > nr_cbufs = = 0 ) {
} else if ( sub_ ctx- > nr_cbufs = = 0 ) {
new_height = u_minify ( ctx - > sub - > zsurf - > texture - > base . height0 , ctx - > sub - > zsurf - > val0 ) ;
new_height = u_minify ( sub_ ctx- > zsurf - > texture - > base . height0 , sub_ ctx- > zsurf - > val0 ) ;
new_ibf = ctx - > sub - > zsurf - > texture - > y_0_top ? true : false ;
new_ibf = sub_ ctx- > zsurf - > texture - > y_0_top ? true : false ;
}
}
else {
else {
surf = NULL ;
surf = NULL ;
for ( i = 0 ; i < ctx - > sub - > nr_cbufs ; i + + ) {
for ( i = 0 ; i < sub_ ctx- > nr_cbufs ; i + + ) {
if ( ctx - > sub - > surf [ i ] ) {
if ( sub_ ctx- > surf [ i ] ) {
surf = ctx - > sub - > surf [ i ] ;
surf = sub_ ctx- > surf [ i ] ;
break ;
break ;
}
}
}
}
@ -2526,23 +2528,23 @@ void vrend_set_framebuffer_state(struct vrend_context *ctx,
}
}
if ( new_height ! = - 1 ) {
if ( new_height ! = - 1 ) {
if ( ctx - > sub - > fb_height ! = ( uint32_t ) new_height | | ctx - > sub - > inverted_fbo_content ! = new_ibf ) {
if ( sub_ ctx- > fb_height ! = ( uint32_t ) new_height | | sub_ ctx- > inverted_fbo_content ! = new_ibf ) {
ctx - > sub - > fb_height = new_height ;
sub_ ctx- > fb_height = new_height ;
ctx - > sub - > inverted_fbo_content = new_ibf ;
sub_ ctx- > inverted_fbo_content = new_ibf ;
ctx - > sub - > viewport_state_dirty = ( 1 < < 0 ) ;
sub_ ctx- > viewport_state_dirty = ( 1 < < 0 ) ;
}
}
}
}
vrend_hw_emit_framebuffer_state ( ctx ) ;
vrend_hw_emit_framebuffer_state ( sub_ ctx) ;
if ( ctx - > sub - > nr_cbufs > 0 | | ctx - > sub - > zsurf ) {
if ( sub_ ctx- > nr_cbufs > 0 | | sub_ ctx- > zsurf ) {
status = glCheckFramebufferStatus ( GL_FRAMEBUFFER ) ;
status = glCheckFramebufferStatus ( GL_FRAMEBUFFER ) ;
if ( status ! = GL_FRAMEBUFFER_COMPLETE )
if ( status ! = GL_FRAMEBUFFER_COMPLETE )
vrend_printf ( " failed to complete framebuffer 0x%x %s \n " , status , ctx - > debug_name ) ;
vrend_printf ( " failed to complete framebuffer 0x%x %s \n " , status , ctx - > debug_name ) ;
}
}
ctx - > sub - > shader_dirty = true ;
sub_ ctx- > shader_dirty = true ;
ctx - > sub - > blend_state_dirty = true ;
sub_ ctx- > blend_state_dirty = true ;
}
}
void vrend_set_framebuffer_state_no_attach ( UNUSED struct vrend_context * ctx ,
void vrend_set_framebuffer_state_no_attach ( UNUSED struct vrend_context * ctx ,