From d0401d09ce19e47e01a3f1c86c10894515de26ad Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 9 Jul 2013 15:09:05 -0700 Subject: [PATCH] i965: Make sampler counts available for the entire drawing operation. Previously, we computed sampler counts when generating the SAMPLER_STATE table. By computing it earlier, we should be able to shorten a bunch of loops. Signed-off-by: Kenneth Graunke Reviewed-by: Paul Berry --- src/mesa/drivers/dri/i965/brw_context.h | 2 +- src/mesa/drivers/dri/i965/brw_draw.c | 7 +++++++ .../drivers/dri/i965/brw_wm_sampler_state.c | 19 +++++++------------ .../drivers/dri/i965/gen7_sampler_state.c | 12 +++++------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h index fbe00b12fb8..d7de0bf79b2 100644 --- a/src/mesa/drivers/dri/i965/brw_context.h +++ b/src/mesa/drivers/dri/i965/brw_context.h @@ -818,7 +818,7 @@ struct brw_context /** Upload a SAMPLER_STATE table. */ void (*upload_sampler_state_table)(struct brw_context *brw, struct gl_program *prog, - uint32_t *sampler_count, + uint32_t sampler_count, uint32_t *sst_offset, uint32_t *sdc_offset); diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c index 6170d0728e1..424d39fb8c2 100644 --- a/src/mesa/drivers/dri/i965/brw_draw.c +++ b/src/mesa/drivers/dri/i965/brw_draw.c @@ -371,6 +371,13 @@ static bool brw_try_draw_prims( struct gl_context *ctx, if (ctx->NewState) _mesa_update_state( ctx ); + /* Find the highest sampler unit used by each shader program. A bit-count + * won't work since ARB programs use the texture unit number as the sampler + * index. + */ + brw->wm.sampler_count = _mesa_fls(ctx->FragmentProgram._Current->Base.SamplersUsed); + brw->vs.sampler_count = _mesa_fls(ctx->VertexProgram._Current->Base.SamplersUsed); + /* We have to validate the textures *before* checking for fallbacks; * otherwise, the software fallback won't be able to rely on the * texture state, the firstLevel and lastLevel fields won't be diff --git a/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c b/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c index a03953f17cd..f2117a48e1a 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c +++ b/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c @@ -369,7 +369,7 @@ static void brw_update_sampler_state(struct brw_context *brw, static void brw_upload_sampler_state_table(struct brw_context *brw, struct gl_program *prog, - uint32_t *sampler_count, + uint32_t sampler_count, uint32_t *sst_offset, uint32_t *sdc_offset) { @@ -378,20 +378,15 @@ brw_upload_sampler_state_table(struct brw_context *brw, GLbitfield SamplersUsed = prog->SamplersUsed; - /* ARB programs use the texture unit number as the sampler index, so we - * need to find the highest unit used. A bit-count will not work. - */ - *sampler_count = _mesa_fls(SamplersUsed); - - if (*sampler_count == 0) + if (sampler_count == 0) return; samplers = brw_state_batch(brw, AUB_TRACE_SAMPLER_STATE, - *sampler_count * sizeof(*samplers), + sampler_count * sizeof(*samplers), 32, sst_offset); - memset(samplers, 0, *sampler_count * sizeof(*samplers)); + memset(samplers, 0, sampler_count * sizeof(*samplers)); - for (unsigned s = 0; s < *sampler_count; s++) { + for (unsigned s = 0; s < sampler_count; s++) { if (SamplersUsed & (1 << s)) { const unsigned unit = prog->SamplerUnits[s]; if (ctx->Texture.Unit[unit]._ReallyEnabled) @@ -409,7 +404,7 @@ brw_upload_fs_samplers(struct brw_context *brw) /* BRW_NEW_FRAGMENT_PROGRAM */ struct gl_program *fs = (struct gl_program *) brw->fragment_program; brw->vtbl.upload_sampler_state_table(brw, fs, - &brw->wm.sampler_count, + brw->wm.sampler_count, &brw->wm.sampler_offset, brw->wm.sdc_offset); } @@ -430,7 +425,7 @@ brw_upload_vs_samplers(struct brw_context *brw) /* BRW_NEW_VERTEX_PROGRAM */ struct gl_program *vs = (struct gl_program *) brw->vertex_program; brw->vtbl.upload_sampler_state_table(brw, vs, - &brw->vs.sampler_count, + brw->vs.sampler_count, &brw->vs.sampler_offset, brw->vs.sdc_offset); } diff --git a/src/mesa/drivers/dri/i965/gen7_sampler_state.c b/src/mesa/drivers/dri/i965/gen7_sampler_state.c index 5701f4d8f04..193b5b12752 100644 --- a/src/mesa/drivers/dri/i965/gen7_sampler_state.c +++ b/src/mesa/drivers/dri/i965/gen7_sampler_state.c @@ -187,7 +187,7 @@ gen7_update_sampler_state(struct brw_context *brw, int unit, int ss_index, static void gen7_upload_sampler_state_table(struct brw_context *brw, struct gl_program *prog, - uint32_t *sampler_count, + uint32_t sampler_count, uint32_t *sst_offset, uint32_t *sdc_offset) { @@ -196,17 +196,15 @@ gen7_upload_sampler_state_table(struct brw_context *brw, GLbitfield SamplersUsed = prog->SamplersUsed; - *sampler_count = _mesa_fls(SamplersUsed); - - if (*sampler_count == 0) + if (sampler_count == 0) return; samplers = brw_state_batch(brw, AUB_TRACE_SAMPLER_STATE, - *sampler_count * sizeof(*samplers), + sampler_count * sizeof(*samplers), 32, sst_offset); - memset(samplers, 0, *sampler_count * sizeof(*samplers)); + memset(samplers, 0, sampler_count * sizeof(*samplers)); - for (unsigned s = 0; s < *sampler_count; s++) { + for (unsigned s = 0; s < sampler_count; s++) { if (SamplersUsed & (1 << s)) { const unsigned unit = prog->SamplerUnits[s]; if (ctx->Texture.Unit[unit]._ReallyEnabled) -- 2.30.2