From: Rémi Bernon <rbernon@codeweavers.com> Buffer names on the unix side are now valid across contexts. --- dlls/opengl32/unix_wgl.c | 56 ++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/dlls/opengl32/unix_wgl.c b/dlls/opengl32/unix_wgl.c index c1a21c58245..2abeda46196 100644 --- a/dlls/opengl32/unix_wgl.c +++ b/dlls/opengl32/unix_wgl.c @@ -187,6 +187,7 @@ struct vk_device static ULONG_PTR zero_bits; +static struct buffers *buffers; static const struct vulkan_funcs *vk_funcs; static VkInstance vk_instance; static PFN_vkDestroyInstance p_vkDestroyInstance; @@ -409,7 +410,7 @@ void free_buffer( const struct opengl_funcs *funcs, struct buffer *buffer ) free( buffer ); } -static void release_buffers( const struct opengl_funcs *funcs, struct buffers *buffers ) +static void release_buffers( const struct opengl_funcs *funcs ) { struct buffer *buffer, *next; @@ -418,6 +419,18 @@ static void release_buffers( const struct opengl_funcs *funcs, struct buffers *b RB_FOR_EACH_ENTRY_DESTRUCTOR( buffer, next, &buffers->map, struct buffer, entry ) free_buffer( funcs, buffer ); free( buffers ); + buffers = NULL; +} + +static struct buffers *acquire_buffers(void) +{ + if (buffers) buffers->ref++; + else if ((buffers = malloc( sizeof(*buffers )))) + { + buffers->ref = 1; + rb_init( &buffers->map, compare_buffer_name ); + } + return buffers; } static struct context *context_from_client_context( HGLRC client_context ) @@ -433,23 +446,15 @@ static struct context *update_context( TEB *teb, HGLRC client_context, struct co { struct opengl_client_context *client = opengl_client_context_from_client( client_context ); const struct opengl_funcs *funcs = get_context_funcs( client_context ); - struct context *share; if (client->current_tid) return ctx; /* currently in use */ if (ctx->share == (HGLRC)-1) return ctx; /* not re-shared */ - share = ctx->share ? get_updated_context( teb, ctx->share ) : NULL; if (!funcs->p_context_reset( &ctx->base, ctx->attribs )) { WARN( "Failed to re-create context for wglShareLists\n" ); return ctx; } - if (share && share->buffers) - { - release_buffers( funcs, ctx->buffers ); - ctx->buffers = share->buffers; - ctx->buffers->ref++; - } ctx->share = (HGLRC)-1; /* initial shared context */ copy_context_attributes( teb, client_context, ctx, client_context, ctx, ctx->used ); return ctx; @@ -869,7 +874,7 @@ static BOOL initialize_vk_device( TEB *teb, struct context *ctx ) static PFN_vkGetPhysicalDeviceMemoryProperties p_vkGetPhysicalDeviceMemoryProperties; static PFN_vkGetPhysicalDeviceProperties2KHR p_vkGetPhysicalDeviceProperties2KHR; - if (ctx->buffers->vk_device) return TRUE; /* already initialized */ + if (buffers->vk_device) return TRUE; /* already initialized */ if (!client->extensions[GL_EXT_memory_object_win32] ) { TRACE( "GL_EXT_memory_object_win32 is not supported\n" ); @@ -930,7 +935,7 @@ static BOOL initialize_vk_device( TEB *teb, struct context *ctx ) vk_device = RB_ENTRY_VALUE( entry, struct vk_device, entry ); if (!vk_device->vk_device) continue; /* known incompatible device */ TRACE( "Found existing device %p for uuid %s\n", vk_device, debugstr_guid(&vk_device->uuid) ); - ctx->buffers->vk_device = vk_device; + buffers->vk_device = vk_device; free( vk_physical_devices ); return TRUE; } @@ -1140,8 +1145,9 @@ static void make_context_current( TEB *teb, const struct opengl_funcs *funcs, HD ctx->pixel_mode.read_buffer = ctx->base.draw->doublebuffer ? GL_BACK : GL_FRONT; } -static void free_context( struct context *ctx ) +static void free_context( const struct opengl_funcs *funcs, struct context *ctx ) { + if (ctx->buffers) release_buffers( funcs ); free( ctx->wow64_version ); free( ctx->extensions ); free( ctx->attribs ); @@ -1153,7 +1159,7 @@ BOOL wrap_wglDeleteContext( TEB *teb, HGLRC client_context ) const struct opengl_funcs *funcs = get_context_funcs( client_context ); struct context *ctx = context_from_client_context( client_context ); funcs->p_context_destroy( &ctx->base ); - free_context( ctx ); + free_context( funcs, ctx ); return TRUE; } @@ -1318,7 +1324,7 @@ BOOL wrap_wglShareLists( TEB *teb, HGLRC client_src, HGLRC client_dst ) HGLRC wrap_wglCreateContextAttribsARB( TEB *teb, HDC hdc, HGLRC client_shared, const int *attribs, HGLRC client_context ) { const struct opengl_funcs *funcs = get_dc_funcs( hdc ); - struct context *context, *shared = get_updated_context( teb, client_shared ); + struct context *context; if (!funcs->p_context_create) return 0; if (!(context = calloc( 1, sizeof(*context) ))) @@ -1330,29 +1336,11 @@ HGLRC wrap_wglCreateContextAttribsARB( TEB *teb, HDC hdc, HGLRC client_shared, c context->share = (HGLRC)-1; /* initial shared context */ context->attribs = memdup_attribs( attribs ); - if (is_win64 && is_wow64()) - { - if (shared) - { - context->buffers = shared->buffers; - context->buffers->ref++; - } - else if (!(context->buffers = malloc( sizeof(*context->buffers )))) - { - free_context( context ); - return 0; - } - else - { - context->buffers->ref = 1; - context->buffers->vk_device = NULL; - rb_init( &context->buffers->map, compare_buffer_name ); - } - } + if (is_win64 && is_wow64()) context->buffers = acquire_buffers(); if (!(funcs->p_context_create( &context->base, hdc, attribs ))) { - free_context( context ); + free_context( funcs, context ); return 0; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11161