From fbcd709a34ccccf16796b926a3b25d6044fb614b Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Tue, 11 Apr 2017 11:05:22 +1000 Subject: [PATCH] mesa/st: only update samplers for stages that have changed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Might help reduce cpu for some apps that use sso. Reviewed-by: Marek Olšák --- src/mesa/state_tracker/st_atom.h | 6 +- src/mesa/state_tracker/st_atom_list.h | 8 +- src/mesa/state_tracker/st_atom_sampler.c | 94 +++++++++++++++++++----- src/mesa/state_tracker/st_program.c | 14 ++-- 4 files changed, 94 insertions(+), 28 deletions(-) diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index 45c3e487647..0145cefd040 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -83,7 +83,11 @@ enum { #undef ST_STATE /* Combined state flags. */ -#define ST_NEW_SAMPLERS (ST_NEW_RENDER_SAMPLERS | \ +#define ST_NEW_SAMPLERS (ST_NEW_VS_SAMPLERS | \ + ST_NEW_TCS_SAMPLERS | \ + ST_NEW_TES_SAMPLERS | \ + ST_NEW_GS_SAMPLERS | \ + ST_NEW_FS_SAMPLERS | \ ST_NEW_CS_SAMPLERS) #define ST_NEW_FRAMEBUFFER (ST_NEW_FB_STATE | \ diff --git a/src/mesa/state_tracker/st_atom_list.h b/src/mesa/state_tracker/st_atom_list.h index d0d5a05398d..4212dacfa98 100644 --- a/src/mesa/state_tracker/st_atom_list.h +++ b/src/mesa/state_tracker/st_atom_list.h @@ -22,7 +22,11 @@ ST_STATE(ST_NEW_TCS_SAMPLER_VIEWS, st_update_tessctrl_texture) ST_STATE(ST_NEW_TES_SAMPLER_VIEWS, st_update_tesseval_texture) /* Non-compute samplers. */ -ST_STATE(ST_NEW_RENDER_SAMPLERS, st_update_sampler) /* depends on update_*_texture for swizzle */ +ST_STATE(ST_NEW_VS_SAMPLERS, st_update_vertex_sampler) /* depends on update_*_texture for swizzle */ +ST_STATE(ST_NEW_TCS_SAMPLERS, st_update_tessctrl_sampler) /* depends on update_*_texture for swizzle */ +ST_STATE(ST_NEW_TES_SAMPLERS, st_update_tesseval_sampler) /* depends on update_*_texture for swizzle */ +ST_STATE(ST_NEW_GS_SAMPLERS, st_update_geometry_sampler) /* depends on update_*_texture for swizzle */ +ST_STATE(ST_NEW_FS_SAMPLERS, st_update_fragment_sampler) /* depends on update_*_texture for swizzle */ ST_STATE(ST_NEW_VS_IMAGES, st_bind_vs_images) ST_STATE(ST_NEW_TCS_IMAGES, st_bind_tcs_images) @@ -67,7 +71,7 @@ ST_STATE(ST_NEW_VERTEX_ARRAYS, st_update_array) /* Compute states must be last. */ ST_STATE(ST_NEW_CS_STATE, st_update_cp) ST_STATE(ST_NEW_CS_SAMPLER_VIEWS, st_update_compute_texture) -ST_STATE(ST_NEW_CS_SAMPLERS, st_update_sampler) /* depends on update_compute_texture for swizzle */ +ST_STATE(ST_NEW_CS_SAMPLERS, st_update_compute_sampler) /* depends on update_compute_texture for swizzle */ ST_STATE(ST_NEW_CS_CONSTANTS, st_update_cs_constants) ST_STATE(ST_NEW_CS_UBOS, st_bind_cs_ubos) ST_STATE(ST_NEW_CS_ATOMICS, st_bind_cs_atomics) diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index d67b2fcab4f..820a57dd4f5 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -317,32 +317,24 @@ update_shader_samplers(struct st_context *st, static void -update_samplers(struct st_context *st) +update_vertex_samplers(struct st_context *st) { const struct gl_context *ctx = st->ctx; - update_shader_samplers(st, - PIPE_SHADER_FRAGMENT, - ctx->FragmentProgram._Current, - ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits, - st->state.samplers[PIPE_SHADER_FRAGMENT], - &st->state.num_samplers[PIPE_SHADER_FRAGMENT]); - update_shader_samplers(st, PIPE_SHADER_VERTEX, ctx->VertexProgram._Current, ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits, st->state.samplers[PIPE_SHADER_VERTEX], &st->state.num_samplers[PIPE_SHADER_VERTEX]); +} + + +static void +update_tessctrl_samplers(struct st_context *st) +{ + const struct gl_context *ctx = st->ctx; - if (ctx->GeometryProgram._Current) { - update_shader_samplers(st, - PIPE_SHADER_GEOMETRY, - ctx->GeometryProgram._Current, - ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxTextureImageUnits, - st->state.samplers[PIPE_SHADER_GEOMETRY], - &st->state.num_samplers[PIPE_SHADER_GEOMETRY]); - } if (ctx->TessCtrlProgram._Current) { update_shader_samplers(st, PIPE_SHADER_TESS_CTRL, @@ -351,6 +343,14 @@ update_samplers(struct st_context *st) st->state.samplers[PIPE_SHADER_TESS_CTRL], &st->state.num_samplers[PIPE_SHADER_TESS_CTRL]); } +} + + +static void +update_tesseval_samplers(struct st_context *st) +{ + const struct gl_context *ctx = st->ctx; + if (ctx->TessEvalProgram._Current) { update_shader_samplers(st, PIPE_SHADER_TESS_EVAL, @@ -359,6 +359,44 @@ update_samplers(struct st_context *st) st->state.samplers[PIPE_SHADER_TESS_EVAL], &st->state.num_samplers[PIPE_SHADER_TESS_EVAL]); } +} + + +static void +update_geometry_samplers(struct st_context *st) +{ + const struct gl_context *ctx = st->ctx; + + if (ctx->GeometryProgram._Current) { + update_shader_samplers(st, + PIPE_SHADER_GEOMETRY, + ctx->GeometryProgram._Current, + ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxTextureImageUnits, + st->state.samplers[PIPE_SHADER_GEOMETRY], + &st->state.num_samplers[PIPE_SHADER_GEOMETRY]); + } +} + + +static void +update_fragment_samplers(struct st_context *st) +{ + const struct gl_context *ctx = st->ctx; + + update_shader_samplers(st, + PIPE_SHADER_FRAGMENT, + ctx->FragmentProgram._Current, + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits, + st->state.samplers[PIPE_SHADER_FRAGMENT], + &st->state.num_samplers[PIPE_SHADER_FRAGMENT]); +} + + +static void +update_compute_samplers(struct st_context *st) +{ + const struct gl_context *ctx = st->ctx; + if (ctx->ComputeProgram._Current) { update_shader_samplers(st, PIPE_SHADER_COMPUTE, @@ -370,6 +408,26 @@ update_samplers(struct st_context *st) } -const struct st_tracked_state st_update_sampler = { - update_samplers /* update */ +const struct st_tracked_state st_update_vertex_sampler = { + update_vertex_samplers /* update */ +}; + +const struct st_tracked_state st_update_tessctrl_sampler = { + update_tessctrl_samplers /* update */ +}; + +const struct st_tracked_state st_update_tesseval_sampler = { + update_tesseval_samplers /* update */ +}; + +const struct st_tracked_state st_update_geometry_sampler = { + update_geometry_samplers /* update */ +}; + +const struct st_tracked_state st_update_fragment_sampler = { + update_fragment_samplers /* update */ +}; + +const struct st_tracked_state st_update_compute_sampler = { + update_compute_samplers /* update */ }; diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 4d9250b73cc..0dc3b1ea9bd 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -112,7 +112,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog) set_affected_state_flags(states, prog, ST_NEW_VS_CONSTANTS, ST_NEW_VS_SAMPLER_VIEWS, - ST_NEW_RENDER_SAMPLERS, + ST_NEW_VS_SAMPLERS, ST_NEW_VS_IMAGES, ST_NEW_VS_UBOS, ST_NEW_VS_SSBOS, @@ -127,7 +127,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog) set_affected_state_flags(states, prog, ST_NEW_TCS_CONSTANTS, ST_NEW_TCS_SAMPLER_VIEWS, - ST_NEW_RENDER_SAMPLERS, + ST_NEW_TCS_SAMPLERS, ST_NEW_TCS_IMAGES, ST_NEW_TCS_UBOS, ST_NEW_TCS_SSBOS, @@ -143,7 +143,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog) set_affected_state_flags(states, prog, ST_NEW_TES_CONSTANTS, ST_NEW_TES_SAMPLER_VIEWS, - ST_NEW_RENDER_SAMPLERS, + ST_NEW_TES_SAMPLERS, ST_NEW_TES_IMAGES, ST_NEW_TES_UBOS, ST_NEW_TES_SSBOS, @@ -159,7 +159,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog) set_affected_state_flags(states, prog, ST_NEW_GS_CONSTANTS, ST_NEW_GS_SAMPLER_VIEWS, - ST_NEW_RENDER_SAMPLERS, + ST_NEW_GS_SAMPLERS, ST_NEW_GS_IMAGES, ST_NEW_GS_UBOS, ST_NEW_GS_SSBOS, @@ -177,7 +177,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog) set_affected_state_flags(states, prog, ST_NEW_FS_CONSTANTS, ST_NEW_FS_SAMPLER_VIEWS, - ST_NEW_RENDER_SAMPLERS, + ST_NEW_FS_SAMPLERS, ST_NEW_FS_IMAGES, ST_NEW_FS_UBOS, ST_NEW_FS_SSBOS, @@ -754,12 +754,12 @@ st_translate_fragment_program(struct st_context *st, if (stfp->ati_fs) { /* Just set them for ATI_fs unconditionally. */ stfp->affected_states |= ST_NEW_FS_SAMPLER_VIEWS | - ST_NEW_RENDER_SAMPLERS; + ST_NEW_FS_SAMPLERS; } else { /* ARB_fp */ if (stfp->Base.SamplersUsed) stfp->affected_states |= ST_NEW_FS_SAMPLER_VIEWS | - ST_NEW_RENDER_SAMPLERS; + ST_NEW_FS_SAMPLERS; } } -- 2.30.2