From 6b0ac95c2862b4d464079b2edd9b59b5ef906da3 Mon Sep 17 00:00:00 2001 From: Bruce Cherniak Date: Fri, 17 Jun 2016 12:14:54 -0500 Subject: [PATCH] swr: Update screen->context pointer with multiple contexts. A pipe pointer in the screen allows for access to current device context in flush_frontbuffer and resource_destroy. This wasn't tracking current context in multi-context situations. v2: More caffeine. Corrected compare, removed unnecessary set of screen-pipe in create_context, and added a few comments. --- src/gallium/drivers/swr/swr_context.cpp | 6 +++--- src/gallium/drivers/swr/swr_state.cpp | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/swr/swr_context.cpp b/src/gallium/drivers/swr/swr_context.cpp index 3a5d9e07ab3..1f3a14cb9c8 100644 --- a/src/gallium/drivers/swr/swr_context.cpp +++ b/src/gallium/drivers/swr/swr_context.cpp @@ -322,8 +322,10 @@ swr_destroy(struct pipe_context *pipe) swr_destroy_scratch_buffers(ctx); + /* Only update screen->pipe if current context is being destroyed */ assert(screen); - screen->pipe = NULL; + if (screen->pipe == pipe) + screen->pipe = NULL; FREE(ctx); } @@ -346,7 +348,6 @@ struct pipe_context * swr_create_context(struct pipe_screen *p_screen, void *priv, unsigned flags) { struct swr_context *ctx = CALLOC_STRUCT(swr_context); - struct swr_screen *screen = swr_screen(p_screen); ctx->blendJIT = new std::unordered_map; @@ -366,7 +367,6 @@ swr_create_context(struct pipe_screen *p_screen, void *priv, unsigned flags) if (ctx->swrContext == NULL) goto fail; - screen->pipe = &ctx->pipe; ctx->pipe.screen = p_screen; ctx->pipe.destroy = swr_destroy; ctx->pipe.priv = priv; diff --git a/src/gallium/drivers/swr/swr_state.cpp b/src/gallium/drivers/swr/swr_state.cpp index 3eeb98d0261..1f34365d30e 100644 --- a/src/gallium/drivers/swr/swr_state.cpp +++ b/src/gallium/drivers/swr/swr_state.cpp @@ -776,6 +776,10 @@ swr_update_derived(struct pipe_context *pipe, struct swr_context *ctx = swr_context(pipe); struct swr_screen *screen = swr_screen(ctx->pipe.screen); + /* Update screen->pipe to current pipe context. */ + if (screen->pipe != pipe) + screen->pipe = pipe; + /* Any state that requires dirty flags to be re-triggered sets this mask */ /* For example, user_buffer vertex and index buffers. */ unsigned post_update_dirty_flags = 0;