[Mesa-dev] [PATCH] gallium/swr: Cleaned up some context-resource management
Cherniak, Bruce
bruce.cherniak at intel.com
Thu Mar 17 03:05:47 UTC 2016
Reviewed-by: Bruce Cherniak <bruce.cherniak at intel.com>
On 3/14/16, 5:40 PM, "mesa-dev on behalf of George Kyriazis" <mesa-dev-bounces at lists.freedesktop.org on behalf of george.kyriazis at intel.com> wrote:
>Removed bound_to_context. We now pick up the context from the screen
>instead of the resource itself. The resource could be out-of-date
>and point to a pipe that is already freed.
>
>Fixes manywin mesa xdemo.
>---
> src/gallium/drivers/swr/swr_context.cpp | 16 +++++++++++-----
> src/gallium/drivers/swr/swr_resource.h | 18 ++++++------------
> src/gallium/drivers/swr/swr_screen.cpp | 8 ++++----
> src/gallium/drivers/swr/swr_screen.h | 1 +
> src/gallium/drivers/swr/swr_state.cpp | 10 +++++-----
> 5 files changed, 27 insertions(+), 26 deletions(-)
>
>diff --git a/src/gallium/drivers/swr/swr_context.cpp b/src/gallium/drivers/swr/swr_context.cpp
>index c8cb145..78b8fdf 100644
>--- a/src/gallium/drivers/swr/swr_context.cpp
>+++ b/src/gallium/drivers/swr/swr_context.cpp
>@@ -129,7 +129,7 @@ swr_transfer_map(struct pipe_context *pipe,
> swr_fence_submit(swr_context(pipe), screen->flush_fence);
>
> swr_fence_finish(pipe->screen, screen->flush_fence, 0);
>- swr_resource_unused(pipe, spr);
>+ swr_resource_unused(resource);
> }
> }
> }
>@@ -206,8 +206,8 @@ swr_resource_copy(struct pipe_context *pipe,
> swr_store_dirty_resource(pipe, dst, SWR_TILE_RESOLVED);
>
> swr_fence_finish(pipe->screen, screen->flush_fence, 0);
>- swr_resource_unused(pipe, swr_resource(src));
>- swr_resource_unused(pipe, swr_resource(dst));
>+ swr_resource_unused(src);
>+ swr_resource_unused(dst);
>
> if ((dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER)
> || (dst->target != PIPE_BUFFER && src->target != PIPE_BUFFER)) {
>@@ -293,6 +293,7 @@ static void
> swr_destroy(struct pipe_context *pipe)
> {
> struct swr_context *ctx = swr_context(pipe);
>+ struct swr_screen *screen = swr_screen(pipe->screen);
>
> if (ctx->blitter)
> util_blitter_destroy(ctx->blitter);
>@@ -306,6 +307,9 @@ swr_destroy(struct pipe_context *pipe)
>
> swr_destroy_scratch_buffers(ctx);
>
>+ assert(screen);
>+ screen->pipe = NULL;
>+
> FREE(ctx);
> }
>
>@@ -324,9 +328,10 @@ swr_render_condition(struct pipe_context *pipe,
> }
>
> struct pipe_context *
>-swr_create_context(struct pipe_screen *screen, void *priv, unsigned flags)
>+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<BLEND_COMPILE_STATE, PFN_BLEND_JIT_FUNC>;
>
>@@ -347,7 +352,8 @@ swr_create_context(struct pipe_screen *screen, void *priv, unsigned flags)
> if (ctx->swrContext == NULL)
> goto fail;
>
>- ctx->pipe.screen = screen;
>+ screen->pipe = &ctx->pipe;
>+ ctx->pipe.screen = p_screen;
> ctx->pipe.destroy = swr_destroy;
> ctx->pipe.priv = priv;
> ctx->pipe.create_surface = swr_create_surface;
>diff --git a/src/gallium/drivers/swr/swr_resource.h b/src/gallium/drivers/swr/swr_resource.h
>index 2fdc768..59cf028 100644
>--- a/src/gallium/drivers/swr/swr_resource.h
>+++ b/src/gallium/drivers/swr/swr_resource.h
>@@ -54,9 +54,6 @@ struct swr_resource {
> unsigned mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
>
> enum swr_resource_status status;
>-
>- /* pipe_context to which resource is currently bound. */
>- struct pipe_context *bound_to_context;
> };
>
>
>@@ -120,24 +117,21 @@ swr_resource_status & operator|=(enum swr_resource_status & a,
> }
>
> static INLINE void
>-swr_resource_read(struct pipe_context *pipe, struct swr_resource *resource)
>+swr_resource_read(struct pipe_resource *resource)
> {
>- resource->status |= SWR_RESOURCE_READ;
>- resource->bound_to_context = pipe;
>+ swr_resource(resource)->status |= SWR_RESOURCE_READ;
> }
>
> static INLINE void
>-swr_resource_write(struct pipe_context *pipe, struct swr_resource *resource)
>+swr_resource_write(struct pipe_resource *resource)
> {
>- resource->status |= SWR_RESOURCE_WRITE;
>- resource->bound_to_context = pipe;
>+ swr_resource(resource)->status |= SWR_RESOURCE_WRITE;
> }
>
> static INLINE void
>-swr_resource_unused(struct pipe_context *pipe, struct swr_resource *resource)
>+swr_resource_unused(struct pipe_resource *resource)
> {
>- resource->status = SWR_RESOURCE_UNUSED;
>- resource->bound_to_context = nullptr;
>+ swr_resource(resource)->status = SWR_RESOURCE_UNUSED;
> }
>
> #endif
>diff --git a/src/gallium/drivers/swr/swr_screen.cpp b/src/gallium/drivers/swr/swr_screen.cpp
>index e46df47..f9e52be 100644
>--- a/src/gallium/drivers/swr/swr_screen.cpp
>+++ b/src/gallium/drivers/swr/swr_screen.cpp
>@@ -620,7 +620,7 @@ swr_resource_destroy(struct pipe_screen *p_screen, struct pipe_resource *pt)
> {
> struct swr_screen *screen = swr_screen(p_screen);
> struct swr_resource *spr = swr_resource(pt);
>- struct pipe_context *pipe = spr->bound_to_context;
>+ struct pipe_context *pipe = screen->pipe;
>
> /* Only wait on fence if the resource is being used */
> if (pipe && spr->status) {
>@@ -630,7 +630,7 @@ swr_resource_destroy(struct pipe_screen *p_screen, struct pipe_resource *pt)
> swr_fence_submit(swr_context(pipe), screen->flush_fence);
>
> swr_fence_finish(p_screen, screen->flush_fence, 0);
>- swr_resource_unused(pipe, spr);
>+ swr_resource_unused(pt);
> }
>
> /*
>@@ -661,11 +661,11 @@ swr_flush_frontbuffer(struct pipe_screen *p_screen,
> struct swr_screen *screen = swr_screen(p_screen);
> struct sw_winsys *winsys = screen->winsys;
> struct swr_resource *spr = swr_resource(resource);
>- struct pipe_context *pipe = spr->bound_to_context;
>+ struct pipe_context *pipe = screen->pipe;
>
> if (pipe) {
> swr_fence_finish(p_screen, screen->flush_fence, 0);
>- swr_resource_unused(pipe, spr);
>+ swr_resource_unused(resource);
> SwrEndFrame(swr_context(pipe)->swrContext);
> }
>
>diff --git a/src/gallium/drivers/swr/swr_screen.h b/src/gallium/drivers/swr/swr_screen.h
>index a96dc44..0c82a2e 100644
>--- a/src/gallium/drivers/swr/swr_screen.h
>+++ b/src/gallium/drivers/swr/swr_screen.h
>@@ -32,6 +32,7 @@ struct sw_winsys;
>
> struct swr_screen {
> struct pipe_screen base;
>+ struct pipe_context *pipe;
>
> struct pipe_fence_handle *flush_fence;
>
>diff --git a/src/gallium/drivers/swr/swr_state.cpp b/src/gallium/drivers/swr/swr_state.cpp
>index 47ee3cb..e7bf361 100644
>--- a/src/gallium/drivers/swr/swr_state.cpp
>+++ b/src/gallium/drivers/swr/swr_state.cpp
>@@ -646,24 +646,24 @@ swr_update_resource_status(struct pipe_context *pipe,
> if (fb->nr_cbufs)
> for (uint32_t i = 0; i < fb->nr_cbufs; ++i)
> if (fb->cbufs[i])
>- swr_resource_write(pipe, swr_resource(fb->cbufs[i]->texture));
>+ swr_resource_write(fb->cbufs[i]->texture);
>
> /* depth/stencil target */
> if (fb->zsbuf)
>- swr_resource_write(pipe, swr_resource(fb->zsbuf->texture));
>+ swr_resource_write(fb->zsbuf->texture);
>
> /* VBO vertex buffers */
> for (uint32_t i = 0; i < ctx->num_vertex_buffers; i++) {
> struct pipe_vertex_buffer *vb = &ctx->vertex_buffer[i];
> if (!vb->user_buffer)
>- swr_resource_read(pipe, swr_resource(vb->buffer));
>+ swr_resource_read(vb->buffer);
> }
>
> /* VBO index buffer */
> if (p_draw_info && p_draw_info->indexed) {
> struct pipe_index_buffer *ib = &ctx->index_buffer;
> if (!ib->user_buffer)
>- swr_resource_read(pipe, swr_resource(ib->buffer));
>+ swr_resource_read(ib->buffer);
> }
>
> /* texture sampler views */
>@@ -671,7 +671,7 @@ swr_update_resource_status(struct pipe_context *pipe,
> struct pipe_sampler_view *view =
> ctx->sampler_views[PIPE_SHADER_FRAGMENT][i];
> if (view)
>- swr_resource_read(pipe, swr_resource(view->texture));
>+ swr_resource_read(view->texture);
> }
> }
>
>--
>2.5.0
>
>_______________________________________________
>mesa-dev mailing list
>mesa-dev at lists.freedesktop.org
>https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list