Re: [Mesa-dev] [PATCH 1/2] swr: switch to using SwrGetInterface api table
Reviewed-by: Bruce Cherniak > On Jul 7, 2017, at 4:25 PM, Tim Rowley wrote: > > Use the SWR rasterizer API through the table returned from > SwrGetInterface rather than referencing the functions directly. > This will allow us to move to a model of having the driver dynamically > load the appropriate swr architecture library. > --- > src/gallium/drivers/swr/swr_clear.cpp | 6 ++--- > src/gallium/drivers/swr/swr_context.cpp | 19 -- > src/gallium/drivers/swr/swr_context.h | 5 +++- > src/gallium/drivers/swr/swr_draw.cpp| 46 - > src/gallium/drivers/swr/swr_fence.cpp | 2 +- > src/gallium/drivers/swr/swr_memory.h| 6 ++--- > src/gallium/drivers/swr/swr_query.cpp | 8 +++--- > src/gallium/drivers/swr/swr_scratch.cpp | 2 +- > src/gallium/drivers/swr/swr_screen.cpp | 3 ++- > src/gallium/drivers/swr/swr_state.cpp | 40 ++-- > 10 files changed, 72 insertions(+), 65 deletions(-) > > diff --git a/src/gallium/drivers/swr/swr_clear.cpp > b/src/gallium/drivers/swr/swr_clear.cpp > index 3a35805..233432e 100644 > --- a/src/gallium/drivers/swr/swr_clear.cpp > +++ b/src/gallium/drivers/swr/swr_clear.cpp > @@ -78,9 +78,9 @@ swr_clear(struct pipe_context *pipe, > >for (unsigned i = 0; i < layers; ++i) { > swr_update_draw_context(ctx); > - SwrClearRenderTarget(ctx->swrContext, clearMask, i, > - color->f, depth, stencil, > - clear_rect); > + ctx->api.pfnSwrClearRenderTarget(ctx->swrContext, clearMask, i, > + color->f, depth, stencil, > + clear_rect); > > // Mask out the attachments that are out of layers. > if (fb->zsbuf && > diff --git a/src/gallium/drivers/swr/swr_context.cpp > b/src/gallium/drivers/swr/swr_context.cpp > index f2d971a..9648278 100644 > --- a/src/gallium/drivers/swr/swr_context.cpp > +++ b/src/gallium/drivers/swr/swr_context.cpp > @@ -311,8 +311,8 @@ swr_blit(struct pipe_context *pipe, const struct > pipe_blit_info *blit_info) >} > >if (ctx->active_queries) { > - SwrEnableStatsFE(ctx->swrContext, FALSE); > - SwrEnableStatsBE(ctx->swrContext, FALSE); > + ctx->api.pfnSwrEnableStatsFE(ctx->swrContext, FALSE); > + ctx->api.pfnSwrEnableStatsBE(ctx->swrContext, FALSE); >} > >util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vertex_buffer); > @@ -349,8 +349,8 @@ swr_blit(struct pipe_context *pipe, const struct > pipe_blit_info *blit_info) >util_blitter_blit(ctx->blitter, &info); > >if (ctx->active_queries) { > - SwrEnableStatsFE(ctx->swrContext, TRUE); > - SwrEnableStatsBE(ctx->swrContext, TRUE); > + ctx->api.pfnSwrEnableStatsFE(ctx->swrContext, TRUE); > + ctx->api.pfnSwrEnableStatsBE(ctx->swrContext, TRUE); >} > } > > @@ -383,10 +383,10 @@ swr_destroy(struct pipe_context *pipe) > >/* Idle core after destroying buffer resources, but before deleting > * context. Destroying resources has potentially called StoreTiles.*/ > - SwrWaitForIdle(ctx->swrContext); > + ctx->api.pfnSwrWaitForIdle(ctx->swrContext); > >if (ctx->swrContext) > - SwrDestroyContext(ctx->swrContext); > + ctx->api.pfnSwrDestroyContext(ctx->swrContext); > >delete ctx->blendJIT; > > @@ -467,6 +467,9 @@ swr_create_context(struct pipe_screen *p_screen, void > *priv, unsigned flags) > AlignedMalloc(sizeof(struct swr_context), KNOB_SIMD_BYTES); >memset(ctx, 0, sizeof(struct swr_context)); > > + SwrGetInterface(ctx->api); > + ctx->swrDC.pAPI = &ctx->api; > + >ctx->blendJIT = > new std::unordered_map; > > @@ -478,9 +481,9 @@ swr_create_context(struct pipe_screen *p_screen, void > *priv, unsigned flags) >createInfo.pfnClearTile = swr_StoreHotTileClear; >createInfo.pfnUpdateStats = swr_UpdateStats; >createInfo.pfnUpdateStatsFE = swr_UpdateStatsFE; > - ctx->swrContext = SwrCreateContext(&createInfo); > + ctx->swrContext = ctx->api.pfnSwrCreateContext(&createInfo); > > - SwrInit(); > + ctx->api.pfnSwrInit(); > >if (ctx->swrContext == NULL) > goto fail; > diff --git a/src/gallium/drivers/swr/swr_context.h > b/src/gallium/drivers/swr/swr_context.h > index 3ff4bf3..753cbf3 100644 > --- a/src/gallium/drivers/swr/swr_context.h > +++ b/src/gallium/drivers/swr/swr_context.h > @@ -102,6 +102,7 @@ struct swr_draw_context { > >SWR_SURFACE_STATE renderTargets[SWR_NUM_ATTACHMENTS]; >struct swr_query_result *pStats; // @llvm_struct > + SWR_INTERFACE *pAPI; // @llvm_struct - Needed for the swr_memory callbacks > }; > > /* gen_llvm_types FINI */ > @@ -169,6 +170,8 @@ struct swr_context { >struct swr_draw_context swrDC; > >unsigned dirty; /**< Mask of SWR_NEW_x flags */ > + > + SWR_INTERFACE api; > }; > > static INLINE struct swr_context * > @@ -182,7 +185,7 @@ swr_update_draw_context(struct swr_context *ctx, > struct swr_quer
[Mesa-dev] [PATCH 1/2] swr: switch to using SwrGetInterface api table
Use the SWR rasterizer API through the table returned from SwrGetInterface rather than referencing the functions directly. This will allow us to move to a model of having the driver dynamically load the appropriate swr architecture library. --- src/gallium/drivers/swr/swr_clear.cpp | 6 ++--- src/gallium/drivers/swr/swr_context.cpp | 19 -- src/gallium/drivers/swr/swr_context.h | 5 +++- src/gallium/drivers/swr/swr_draw.cpp| 46 - src/gallium/drivers/swr/swr_fence.cpp | 2 +- src/gallium/drivers/swr/swr_memory.h| 6 ++--- src/gallium/drivers/swr/swr_query.cpp | 8 +++--- src/gallium/drivers/swr/swr_scratch.cpp | 2 +- src/gallium/drivers/swr/swr_screen.cpp | 3 ++- src/gallium/drivers/swr/swr_state.cpp | 40 ++-- 10 files changed, 72 insertions(+), 65 deletions(-) diff --git a/src/gallium/drivers/swr/swr_clear.cpp b/src/gallium/drivers/swr/swr_clear.cpp index 3a35805..233432e 100644 --- a/src/gallium/drivers/swr/swr_clear.cpp +++ b/src/gallium/drivers/swr/swr_clear.cpp @@ -78,9 +78,9 @@ swr_clear(struct pipe_context *pipe, for (unsigned i = 0; i < layers; ++i) { swr_update_draw_context(ctx); - SwrClearRenderTarget(ctx->swrContext, clearMask, i, - color->f, depth, stencil, - clear_rect); + ctx->api.pfnSwrClearRenderTarget(ctx->swrContext, clearMask, i, + color->f, depth, stencil, + clear_rect); // Mask out the attachments that are out of layers. if (fb->zsbuf && diff --git a/src/gallium/drivers/swr/swr_context.cpp b/src/gallium/drivers/swr/swr_context.cpp index f2d971a..9648278 100644 --- a/src/gallium/drivers/swr/swr_context.cpp +++ b/src/gallium/drivers/swr/swr_context.cpp @@ -311,8 +311,8 @@ swr_blit(struct pipe_context *pipe, const struct pipe_blit_info *blit_info) } if (ctx->active_queries) { - SwrEnableStatsFE(ctx->swrContext, FALSE); - SwrEnableStatsBE(ctx->swrContext, FALSE); + ctx->api.pfnSwrEnableStatsFE(ctx->swrContext, FALSE); + ctx->api.pfnSwrEnableStatsBE(ctx->swrContext, FALSE); } util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vertex_buffer); @@ -349,8 +349,8 @@ swr_blit(struct pipe_context *pipe, const struct pipe_blit_info *blit_info) util_blitter_blit(ctx->blitter, &info); if (ctx->active_queries) { - SwrEnableStatsFE(ctx->swrContext, TRUE); - SwrEnableStatsBE(ctx->swrContext, TRUE); + ctx->api.pfnSwrEnableStatsFE(ctx->swrContext, TRUE); + ctx->api.pfnSwrEnableStatsBE(ctx->swrContext, TRUE); } } @@ -383,10 +383,10 @@ swr_destroy(struct pipe_context *pipe) /* Idle core after destroying buffer resources, but before deleting * context. Destroying resources has potentially called StoreTiles.*/ - SwrWaitForIdle(ctx->swrContext); + ctx->api.pfnSwrWaitForIdle(ctx->swrContext); if (ctx->swrContext) - SwrDestroyContext(ctx->swrContext); + ctx->api.pfnSwrDestroyContext(ctx->swrContext); delete ctx->blendJIT; @@ -467,6 +467,9 @@ swr_create_context(struct pipe_screen *p_screen, void *priv, unsigned flags) AlignedMalloc(sizeof(struct swr_context), KNOB_SIMD_BYTES); memset(ctx, 0, sizeof(struct swr_context)); + SwrGetInterface(ctx->api); + ctx->swrDC.pAPI = &ctx->api; + ctx->blendJIT = new std::unordered_map; @@ -478,9 +481,9 @@ swr_create_context(struct pipe_screen *p_screen, void *priv, unsigned flags) createInfo.pfnClearTile = swr_StoreHotTileClear; createInfo.pfnUpdateStats = swr_UpdateStats; createInfo.pfnUpdateStatsFE = swr_UpdateStatsFE; - ctx->swrContext = SwrCreateContext(&createInfo); + ctx->swrContext = ctx->api.pfnSwrCreateContext(&createInfo); - SwrInit(); + ctx->api.pfnSwrInit(); if (ctx->swrContext == NULL) goto fail; diff --git a/src/gallium/drivers/swr/swr_context.h b/src/gallium/drivers/swr/swr_context.h index 3ff4bf3..753cbf3 100644 --- a/src/gallium/drivers/swr/swr_context.h +++ b/src/gallium/drivers/swr/swr_context.h @@ -102,6 +102,7 @@ struct swr_draw_context { SWR_SURFACE_STATE renderTargets[SWR_NUM_ATTACHMENTS]; struct swr_query_result *pStats; // @llvm_struct + SWR_INTERFACE *pAPI; // @llvm_struct - Needed for the swr_memory callbacks }; /* gen_llvm_types FINI */ @@ -169,6 +170,8 @@ struct swr_context { struct swr_draw_context swrDC; unsigned dirty; /**< Mask of SWR_NEW_x flags */ + + SWR_INTERFACE api; }; static INLINE struct swr_context * @@ -182,7 +185,7 @@ swr_update_draw_context(struct swr_context *ctx, struct swr_query_result *pqr = nullptr) { swr_draw_context *pDC = - (swr_draw_context *)SwrGetPrivateContextState(ctx->swrContext); + (swr_draw_context *)ctx->api.pfnSwrGetPrivateContextState(ctx->swrContext); if (pqr) ctx->swrDC.pStats = pqr; memcpy(pDC