From 9b75627fab5bf2ea90f27ddd31b60c54895f6de6 Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Wed, 15 Apr 2009 15:53:34 +0200 Subject: gallium: Make sure we flush before some texture / buffer operations. Also implement context member functions to optimize away those flushes whenever possible. Signed-off-by: Thomas Hellstrom --- src/gallium/drivers/cell/ppu/cell_context.c | 25 +++++++++++++++ src/gallium/drivers/failover/fo_context.c | 23 ++++++++++++++ src/gallium/drivers/i915simple/i915_context.c | 26 ++++++++++++++++ src/gallium/drivers/i965simple/brw_context.c | 25 +++++++++++++++ src/gallium/drivers/nv04/nv04_context.c | 27 ++++++++++++++++ src/gallium/drivers/nv10/nv10_context.c | 26 ++++++++++++++++ src/gallium/drivers/nv20/nv20_context.c | 27 ++++++++++++++++ src/gallium/drivers/nv30/nv30_context.c | 26 ++++++++++++++++ src/gallium/drivers/nv40/nv40_context.c | 26 ++++++++++++++++ src/gallium/drivers/nv50/nv50_context.c | 26 ++++++++++++++++ src/gallium/drivers/softpipe/sp_context.c | 18 +++++++++++ src/gallium/drivers/trace/tr_context.c | 44 +++++++++++++++++++++++++++ src/gallium/include/pipe/p_context.h | 29 +++++++++++++++++- src/gallium/include/pipe/p_defines.h | 7 +++++ 14 files changed, 354 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/cell/ppu/cell_context.c b/src/gallium/drivers/cell/ppu/cell_context.c index 808be58..ebb7a7a 100644 --- a/src/gallium/drivers/cell/ppu/cell_context.c +++ b/src/gallium/drivers/cell/ppu/cell_context.c @@ -99,6 +99,28 @@ static const struct debug_named_value cell_debug_flags[] = { {NULL, 0} }; +static unsigned int +cell_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +cell_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} struct pipe_context * cell_create_context(struct pipe_screen *screen, @@ -122,6 +144,9 @@ cell_create_context(struct pipe_screen *screen, cell->pipe.clear = cell_clear; cell->pipe.flush = cell_flush; + cell->pipe.is_texture_referenced = cell_is_texture_referenced; + cell->pipe.is_buffer_referenced = cell_is_buffer_referenced; + #if 0 cell->pipe.begin_query = cell_begin_query; cell->pipe.end_query = cell_end_query; diff --git a/src/gallium/drivers/failover/fo_context.c b/src/gallium/drivers/failover/fo_context.c index fcad717..37184ea 100644 --- a/src/gallium/drivers/failover/fo_context.c +++ b/src/gallium/drivers/failover/fo_context.c @@ -105,7 +105,28 @@ static boolean failover_draw_arrays( struct pipe_context *pipe, return failover_draw_elements(pipe, NULL, 0, prim, start, count); } +static unsigned int +failover_is_texture_referenced( struct pipe_context *_pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + struct failover_context *failover = failover_context( _pipe ); + struct pipe_context *pipe = (failover->mode == FO_HW) ? + failover->hw : failover->sw; + + return pipe->is_texture_referenced(pipe, texture, face, level); +} +static unsigned int +failover_is_buffer_referenced( struct pipe_context *_pipe, + struct pipe_buffer *buf) +{ + struct failover_context *failover = failover_context( _pipe ); + struct pipe_context *pipe = (failover->mode == FO_HW) ? + failover->hw : failover->sw; + + return pipe->is_buffer_referenced(pipe, buf); +} struct pipe_context *failover_create( struct pipe_context *hw, struct pipe_context *sw ) @@ -151,6 +172,8 @@ struct pipe_context *failover_create( struct pipe_context *hw, #endif failover->pipe.flush = hw->flush; + failover->pipe.is_texture_referenced = failover_is_texture_referenced; + failover->pipe.is_buffer_referenced = failover_is_buffer_referenced; failover->dirty = 0; diff --git a/src/gallium/drivers/i915simple/i915_context.c b/src/gallium/drivers/i915simple/i915_context.c index 3e3a596..ccf9bb3 100644 --- a/src/gallium/drivers/i915simple/i915_context.c +++ b/src/gallium/drivers/i915simple/i915_context.c @@ -136,6 +136,29 @@ static boolean i915_draw_arrays( struct pipe_context *pipe, } +static unsigned int +i915_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +i915_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + struct pipe_context *i915_create_context( struct pipe_screen *screen, struct pipe_winsys *pipe_winsys, @@ -160,6 +183,9 @@ struct pipe_context *i915_create_context( struct pipe_screen *screen, i915->pipe.draw_elements = i915_draw_elements; i915->pipe.draw_range_elements = i915_draw_range_elements; + i915->pipe.is_texture_referenced = i915_is_texture_referenced; + i915->pipe.is_buffer_referenced = i915_is_buffer_referenced; + /* * Create drawing context and plug our rendering stage into it. */ diff --git a/src/gallium/drivers/i965simple/brw_context.c b/src/gallium/drivers/i965simple/brw_context.c index c74cbf8..9b33285 100644 --- a/src/gallium/drivers/i965simple/brw_context.c +++ b/src/gallium/drivers/i965simple/brw_context.c @@ -73,6 +73,28 @@ static void brw_clear(struct pipe_context *pipe, struct pipe_surface *ps, pipe->surface_fill(pipe, ps, x, y, w, h, clearValue); } +static unsigned int +brw_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +brw_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} struct pipe_context *brw_create(struct pipe_screen *screen, struct brw_winsys *brw_winsys, @@ -94,6 +116,9 @@ struct pipe_context *brw_create(struct pipe_screen *screen, brw->pipe.destroy = brw_destroy; brw->pipe.clear = brw_clear; + brw->pipe.is_texture_referenced = brw_is_texture_referenced; + brw->pipe.is_buffer_referenced = brw_is_buffer_referenced; + brw_init_surface_functions(brw); brw_init_texture_functions(brw); brw_init_state_functions(brw); diff --git a/src/gallium/drivers/nv04/nv04_context.c b/src/gallium/drivers/nv04/nv04_context.c index d6710cd..17166c9 100644 --- a/src/gallium/drivers/nv04/nv04_context.c +++ b/src/gallium/drivers/nv04/nv04_context.c @@ -64,6 +64,30 @@ nv04_init_hwctx(struct nv04_context *nv04) return TRUE; } +static unsigned int +nv04_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +nv04_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + + struct pipe_context * nv04_create(struct pipe_screen *pscreen, unsigned pctx_id) { @@ -89,6 +113,9 @@ nv04_create(struct pipe_screen *pscreen, unsigned pctx_id) nv04->pipe.clear = nv04_clear; nv04->pipe.flush = nv04_flush; + nv04->pipe.is_texture_referenced = nv04_is_texture_referenced; + nv04->pipe.is_buffer_referenced = nv04_is_buffer_referenced; + nv04_init_surface_functions(nv04); nv04_init_state_functions(nv04); diff --git a/src/gallium/drivers/nv10/nv10_context.c b/src/gallium/drivers/nv10/nv10_context.c index ef2c0c5..3da8d2f 100644 --- a/src/gallium/drivers/nv10/nv10_context.c +++ b/src/gallium/drivers/nv10/nv10_context.c @@ -257,6 +257,29 @@ nv10_set_edgeflags(struct pipe_context *pipe, const unsigned *bitfield) { } +static unsigned int +nv10_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +nv10_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + struct pipe_context * nv10_create(struct pipe_screen *pscreen, unsigned pctx_id) { @@ -282,6 +305,9 @@ nv10_create(struct pipe_screen *pscreen, unsigned pctx_id) nv10->pipe.clear = nv10_clear; nv10->pipe.flush = nv10_flush; + nv10->pipe.is_texture_referenced = nv10_is_texture_referenced; + nv10->pipe.is_buffer_referenced = nv10_is_buffer_referenced; + nv10_init_surface_functions(nv10); nv10_init_state_functions(nv10); diff --git a/src/gallium/drivers/nv20/nv20_context.c b/src/gallium/drivers/nv20/nv20_context.c index 1659aec..cbc4170 100644 --- a/src/gallium/drivers/nv20/nv20_context.c +++ b/src/gallium/drivers/nv20/nv20_context.c @@ -380,6 +380,30 @@ nv20_set_edgeflags(struct pipe_context *pipe, const unsigned *bitfield) { } + +static unsigned int +nv20_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +nv20_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + struct pipe_context * nv20_create(struct pipe_screen *pscreen, unsigned pctx_id) { @@ -405,6 +429,9 @@ nv20_create(struct pipe_screen *pscreen, unsigned pctx_id) nv20->pipe.clear = nv20_clear; nv20->pipe.flush = nv20_flush; + nv20->pipe.is_texture_referenced = nv20_is_texture_referenced; + nv20->pipe.is_buffer_referenced = nv20_is_buffer_referenced; + nv20_init_surface_functions(nv20); nv20_init_state_functions(nv20); diff --git a/src/gallium/drivers/nv30/nv30_context.c b/src/gallium/drivers/nv30/nv30_context.c index 61654f8..f827bdc 100644 --- a/src/gallium/drivers/nv30/nv30_context.c +++ b/src/gallium/drivers/nv30/nv30_context.c @@ -31,6 +31,29 @@ nv30_destroy(struct pipe_context *pipe) FREE(nv30); } +static unsigned int +nv30_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +nv30_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + struct pipe_context * nv30_create(struct pipe_screen *pscreen, unsigned pctx_id) { @@ -55,6 +78,9 @@ nv30_create(struct pipe_screen *pscreen, unsigned pctx_id) nv30->pipe.clear = nv30_clear; nv30->pipe.flush = nv30_flush; + nv30->pipe.is_texture_referenced = nv30_is_texture_referenced; + nv30->pipe.is_buffer_referenced = nv30_is_buffer_referenced; + nv30_init_query_functions(nv30); nv30_init_surface_functions(nv30); nv30_init_state_functions(nv30); diff --git a/src/gallium/drivers/nv40/nv40_context.c b/src/gallium/drivers/nv40/nv40_context.c index 5d325f5..8eba6a4 100644 --- a/src/gallium/drivers/nv40/nv40_context.c +++ b/src/gallium/drivers/nv40/nv40_context.c @@ -31,6 +31,29 @@ nv40_destroy(struct pipe_context *pipe) FREE(nv40); } +static unsigned int +nv40_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +nv40_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + struct pipe_context * nv40_create(struct pipe_screen *pscreen, unsigned pctx_id) { @@ -55,6 +78,9 @@ nv40_create(struct pipe_screen *pscreen, unsigned pctx_id) nv40->pipe.clear = nv40_clear; nv40->pipe.flush = nv40_flush; + nv40->pipe.is_texture_referenced = nv40_is_texture_referenced; + nv40->pipe.is_buffer_referenced = nv40_is_buffer_referenced; + nv40_init_query_functions(nv40); nv40_init_surface_functions(nv40); nv40_init_state_functions(nv40); diff --git a/src/gallium/drivers/nv50/nv50_context.c b/src/gallium/drivers/nv50/nv50_context.c index 565a5da..a511f65 100644 --- a/src/gallium/drivers/nv50/nv50_context.c +++ b/src/gallium/drivers/nv50/nv50_context.c @@ -51,6 +51,29 @@ nv50_set_edgeflags(struct pipe_context *pipe, const unsigned *bitfield) { } +static unsigned int +nv50_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + +static unsigned int +nv50_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + /** + * FIXME: Optimize. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + struct pipe_context * nv50_create(struct pipe_screen *pscreen, unsigned pctx_id) { @@ -76,6 +99,9 @@ nv50_create(struct pipe_screen *pscreen, unsigned pctx_id) nv50->pipe.flush = nv50_flush; + nv50->pipe.is_texture_referenced = nv50_is_texture_referenced; + nv50->pipe.is_buffer_referenced = nv50_is_buffer_referenced; + nv50_init_surface_functions(nv50); nv50_init_state_functions(nv50); nv50_init_query_functions(nv50); diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index 06ace27..6ae4d1a 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -121,6 +121,21 @@ static void softpipe_destroy( struct pipe_context *pipe ) FREE( softpipe ); } +static unsigned int +softpipe_is_texture_referenced( struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level, + unsigned zslice) +{ + return PIPE_UNREFERENCED; +} + +static unsigned int +softpipe_is_buffer_referenced( struct pipe_context *pipe, + struct pipe_buffer *buf) +{ + return PIPE_UNREFERENCED; +} struct pipe_context * softpipe_create( struct pipe_screen *screen, @@ -190,6 +205,9 @@ softpipe_create( struct pipe_screen *screen, softpipe->pipe.clear = softpipe_clear; softpipe->pipe.flush = softpipe_flush; + softpipe->pipe.is_texture_referenced = softpipe_is_texture_referenced; + softpipe->pipe.is_buffer_referenced = softpipe_is_buffer_referenced; + softpipe_init_query_funcs( softpipe ); softpipe_init_texture_funcs( softpipe ); diff --git a/src/gallium/drivers/trace/tr_context.c b/src/gallium/drivers/trace/tr_context.c index d8d5821..556b5e0 100644 --- a/src/gallium/drivers/trace/tr_context.c +++ b/src/gallium/drivers/trace/tr_context.c @@ -1030,6 +1030,48 @@ trace_context_destroy(struct pipe_context *_pipe) FREE(tr_ctx); } +static unsigned int +trace_is_texture_referenced( struct pipe_context *_pipe, + struct pipe_texture *texture, + unsigned face, unsigned level) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + unsigned int referenced; + + trace_dump_call_begin("pipe_context", "is_texture_referenced"); + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, texture); + trace_dump_arg(uint, face); + trace_dump_arg(uint, level); + + referenced = pipe->is_texture_referenced(pipe, texture, face, level); + + trace_dump_ret(uint, referenced); + trace_dump_call_end(); + + return referenced; +} + +static unsigned int +trace_is_buffer_referenced( struct pipe_context *_pipe, + struct pipe_buffer *buf) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct pipe_context *pipe = tr_ctx->pipe; + unsigned int referenced; + + trace_dump_call_begin("pipe_context", "is_buffer_referenced"); + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, buf); + + referenced = pipe->is_buffer_referenced(pipe, buf); + + trace_dump_ret(uint, referenced); + trace_dump_call_end(); + + return referenced; +} struct pipe_context * trace_context_create(struct pipe_screen *_screen, @@ -1096,6 +1138,8 @@ trace_context_create(struct pipe_screen *_screen, tr_ctx->base.surface_fill = trace_context_surface_fill; tr_ctx->base.clear = trace_context_clear; tr_ctx->base.flush = trace_context_flush; + tr_ctx->base.is_texture_referenced = trace_is_texture_referenced; + tr_ctx->base.is_buffer_referenced = trace_is_buffer_referenced; tr_ctx->pipe = pipe; diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index c5c8397..57e966a 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -42,7 +42,6 @@ struct pipe_state_cache; struct pipe_query; struct pipe_winsys; - /** * Gallium rendering context. Basically: * - state setting functions @@ -231,6 +230,34 @@ struct pipe_context { void (*flush)( struct pipe_context *pipe, unsigned flags, struct pipe_fence_handle **fence ); + + /** + * Check whether a texture is referenced by an unflushed hw command. + * The state-tracker uses this function to optimize away unnecessary + * flushes. It is safe (but wasteful) to always return. + * PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE. + * \param pipe The pipe context whose unflushed hw commands will be + * checked. + * \param level mipmap level. + * \param texture texture to check. + * \param face cubemap face. Use 0 for non-cubemap texture. + */ + + unsigned int (*is_texture_referenced) (struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level); + /** + * Check whether a buffer is referenced by an unflushed hw command. + * The state-tracker uses this function to optimize away unnecessary + * flushes. It is safe (but wasteful) to always return + * PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE. + * \param pipe The pipe context whose unflushed hw commands will be + * checked. + * \param buf Buffer to check. + */ + + unsigned int (*is_buffer_referenced) (struct pipe_context *pipe, + struct pipe_buffer *buf); }; diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index 1d2aa10..82e23c4 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -312,6 +312,13 @@ enum pipe_transfer_usage { #define PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS 26 +/** + * Referenced query flags. + */ + +#define PIPE_UNREFERENCED 0 +#define PIPE_REFERENCED_FOR_READ (1 << 0) +#define PIPE_REFERENCED_FOR_WRITE (1 << 1) #ifdef __cplusplus } -- cgit v1.1