From ac032d800e5f4cb3ab9166187150a93c17a508aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 2 Aug 2016 16:59:41 +0200 Subject: [PATCH] st/mesa: _NEW_TEXTURE & CONSTANTS shouldn't flag states that aren't used MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Tested-by: Edmondo Tommasina Reviewed-by: Nicolai Hähnle --- src/mesa/state_tracker/st_atom.h | 8 ++++++ src/mesa/state_tracker/st_context.c | 54 +++++++++++++++++++++++++++++++------ src/mesa/state_tracker/st_context.h | 6 +++++ 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index c206343..37e382c 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -134,6 +134,14 @@ enum { ST_NEW_FS_IMAGES | \ ST_NEW_CS_IMAGES) +#define ST_ALL_SHADER_RESOURCES (ST_NEW_SAMPLER_VIEWS | \ + ST_NEW_SAMPLERS | \ + ST_NEW_CONSTANTS | \ + ST_NEW_UNIFORM_BUFFER | \ + ST_NEW_ATOMIC_BUFFER | \ + ST_NEW_STORAGE_BUFFER | \ + ST_NEW_IMAGE_UNITS) + /* All state flags within each group: */ #define ST_PIPELINE_RENDER_STATE_MASK (ST_NEW_CS_STATE - 1) #define ST_PIPELINE_COMPUTE_STATE_MASK (0xffllu << ST_NEW_CS_STATE_INDEX) diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 1ff0355..687ca19 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -123,6 +123,41 @@ st_query_memory_info(struct gl_context *ctx, struct gl_memory_info *out) } +uint64_t +st_get_active_states(struct gl_context *ctx) +{ + struct st_vertex_program *vp = + st_vertex_program(ctx->VertexProgram._Current); + struct st_tessctrl_program *tcp = + st_tessctrl_program(ctx->TessCtrlProgram._Current); + struct st_tesseval_program *tep = + st_tesseval_program(ctx->TessEvalProgram._Current); + struct st_geometry_program *gp = + st_geometry_program(ctx->GeometryProgram._Current); + struct st_fragment_program *fp = + st_fragment_program(ctx->FragmentProgram._Current); + struct st_compute_program *cp = + st_compute_program(ctx->ComputeProgram._Current); + uint64_t active_shader_states = 0; + + if (vp) + active_shader_states |= vp->affected_states; + if (tcp) + active_shader_states |= tcp->affected_states; + if (tep) + active_shader_states |= tep->affected_states; + if (gp) + active_shader_states |= gp->affected_states; + if (fp) + active_shader_states |= fp->affected_states; + if (cp) + active_shader_states |= cp->affected_states; + + /* Mark non-shader-resource shader states as "always active". */ + return active_shader_states | ~ST_ALL_SHADER_RESOURCES; +} + + /** * Called via ctx->Driver.UpdateState() */ @@ -204,17 +239,9 @@ void st_invalidate_state(struct gl_context * ctx, GLbitfield new_state) if (new_state & _NEW_PIXEL) st->dirty |= ST_NEW_PIXEL_TRANSFER; - if (new_state & _NEW_TEXTURE) - st->dirty |= ST_NEW_SAMPLER_VIEWS | - ST_NEW_SAMPLERS | - ST_NEW_IMAGE_UNITS; - if (new_state & _NEW_CURRENT_ATTRIB) st->dirty |= ST_NEW_VERTEX_ARRAYS; - if (new_state & _NEW_PROGRAM_CONSTANTS) - st->dirty |= ST_NEW_CONSTANTS; - /* Update the vertex shader if ctx->Light._ClampVertexColor was changed. */ if (st->clamp_vert_color_in_shader && (new_state & _NEW_LIGHT)) st->dirty |= ST_NEW_VS_STATE; @@ -223,8 +250,19 @@ void st_invalidate_state(struct gl_context * ctx, GLbitfield new_state) if (new_state & _NEW_PROGRAM) { st->gfx_shaders_may_be_dirty = true; st->compute_shader_may_be_dirty = true; + /* This will mask out unused shader resources. */ + st->active_states = st_get_active_states(ctx); } + if (new_state & _NEW_TEXTURE) + st->dirty |= st->active_states & + (ST_NEW_SAMPLER_VIEWS | + ST_NEW_SAMPLERS | + ST_NEW_IMAGE_UNITS); + + if (new_state & _NEW_PROGRAM_CONSTANTS) + st->dirty |= st->active_states & ST_NEW_CONSTANTS; + /* This is the only core Mesa module we depend upon. * No longer use swrast, swsetup, tnl. */ diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 556b9c9..f82cf3a 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -140,6 +140,9 @@ struct st_context uint64_t dirty; /**< dirty states */ + /** This masks out unused shader resources. Only valid in draw calls. */ + uint64_t active_states; + /* If true, further analysis of states is required to know if something * has changed. Used mainly for shaders. */ @@ -357,6 +360,9 @@ st_create_context(gl_api api, struct pipe_context *pipe, extern void st_destroy_context(struct st_context *st); +uint64_t +st_get_active_states(struct gl_context *ctx); + #ifdef __cplusplus } -- 2.7.4