[Mesa-dev] [PATCH 6/8] st/mesa: _NEW_TEXTURE & CONSTANTS shouldn't flag states that aren't used
Marek Olšák
maraeo at gmail.com
Sun Aug 7 01:12:22 UTC 2016
From: Marek Olšák <marek.olsak at amd.com>
---
src/mesa/state_tracker/st_context.c | 64 ++++++++++++++++++++++++++++++++-----
src/mesa/state_tracker/st_context.h | 6 ++++
2 files changed, 62 insertions(+), 8 deletions(-)
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 1ff0355..b9fc9e7 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -116,20 +116,65 @@ st_query_memory_info(struct gl_context *ctx, struct gl_memory_info *out)
out->total_device_memory = info.total_device_memory;
out->avail_device_memory = info.avail_device_memory;
out->total_staging_memory = info.total_staging_memory;
out->avail_staging_memory = info.avail_staging_memory;
out->device_memory_evicted = info.device_memory_evicted;
out->nr_device_memory_evictions = info.nr_device_memory_evictions;
}
+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;
+ uint64_t all_shader_resources;
+
+ 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;
+
+ 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;
+
+ /* Mark non-shader-resource shader states as "always active". */
+ return active_shader_states | ~all_shader_resources;
+}
+
+
/**
* Called via ctx->Driver.UpdateState()
*/
void st_invalidate_state(struct gl_context * ctx, GLbitfield new_state)
{
struct st_context *st = st_context(ctx);
if (new_state & _NEW_BUFFERS) {
st->dirty |= ST_NEW_DSA |
ST_NEW_FB_STATE |
@@ -197,41 +242,44 @@ void st_invalidate_state(struct gl_context * ctx, GLbitfield new_state)
st_user_clip_planes_enabled(ctx))
st->dirty |= ST_NEW_CLIP_STATE;
if (new_state & _NEW_COLOR)
st->dirty |= ST_NEW_BLEND |
ST_NEW_DSA;
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;
/* Which shaders are dirty will be determined manually. */
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.
*/
_vbo_InvalidateState(ctx, new_state);
}
static void
st_destroy_context_priv(struct st_context *st)
{
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
@@ -133,20 +133,23 @@ struct st_context
GLuint poly_stipple[32]; /**< In OpenGL's bottom-to-top order */
GLuint fb_orientation;
} state;
char vendor[100];
char renderer[100];
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.
*/
bool gfx_shaders_may_be_dirty;
bool compute_shader_may_be_dirty;
GLboolean vertdata_edgeflags;
GLboolean edgeflag_culls_prims;
/** Mapping from VARYING_SLOT_x to post-transformed vertex slot */
@@ -350,16 +353,19 @@ st_user_clip_planes_enabled(struct gl_context *ctx)
extern struct st_context *
st_create_context(gl_api api, struct pipe_context *pipe,
const struct gl_config *visual,
struct st_context *share,
const struct st_config_options *options);
extern void
st_destroy_context(struct st_context *st);
+uint64_t
+st_get_active_states(struct gl_context *ctx);
+
#ifdef __cplusplus
}
#endif
#endif
--
2.7.4
More information about the mesa-dev
mailing list