On 02/08/2012 07:28 AM, Dave Airlie wrote:
From: Dave Airlie<airl...@redhat.com>
If we have no more enabled samplers and we've reset all the previously
used ones, no need to keep going around this loop.
Signed-off-by: Dave Airlie<airl...@redhat.com>
---
src/mesa/state_tracker/st_atom_sampler.c | 12 ++++++++----
src/mesa/state_tracker/st_atom_texture.c | 12 +++++++++---
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/src/mesa/state_tracker/st_atom_sampler.c
b/src/mesa/state_tracker/st_atom_sampler.c
index 8845fed..6524949 100644
--- a/src/mesa/state_tracker/st_atom_sampler.c
+++ b/src/mesa/state_tracker/st_atom_sampler.c
@@ -233,15 +233,16 @@ update_fragment_samplers(struct st_context *st)
const struct gl_context *ctx = st->ctx;
struct gl_fragment_program *fprog = ctx->FragmentProgram._Current;
GLuint su;
+ GLuint samplers_used = fprog->Base.SamplersUsed;
+ GLuint old_max = st->state.num_samplers;
st->state.num_samplers = 0;
/* loop over sampler units (aka tex image units) */
- for (su = 0; su< ctx->Const.MaxTextureImageUnits; su++) {
+ for (su = 0; su< ctx->Const.MaxTextureImageUnits; su++, samplers_used>>=
1) {
struct pipe_sampler_state *sampler = st->state.samplers + su;
-
- if (fprog->Base.SamplersUsed& (1<< su)) {
+ if (samplers_used& 1) {
GLuint texUnit;
texUnit = fprog->Base.SamplerUnits[su];
@@ -253,7 +254,10 @@ update_fragment_samplers(struct st_context *st)
/*printf("%s su=%u non-null\n", __FUNCTION__, su);*/
cso_single_sampler(st->cso_context, su, sampler);
}
- else {
+ else if (samplers_used == 0&& su>= old_max) {
+ /* if we've reset all the old views and we have no more new ones */
+ break;
+ } else {
/*printf("%s su=%u null\n", __FUNCTION__, su);*/
cso_single_sampler(st->cso_context, su, NULL);
}
diff --git a/src/mesa/state_tracker/st_atom_texture.c
b/src/mesa/state_tracker/st_atom_texture.c
index d241527..9e98d7f 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -300,13 +300,16 @@ update_fragment_textures(struct st_context *st)
const struct gl_context *ctx = st->ctx;
struct gl_fragment_program *fprog = ctx->FragmentProgram._Current;
GLuint su;
+ int old_max = st->state.num_textures;
+ GLbitfield samplers_used = fprog->Base.SamplersUsed;
st->state.num_textures = 0;
/* loop over sampler units (aka tex image units) */
- for (su = 0; su< ctx->Const.MaxTextureImageUnits; su++) {
+ for (su = 0; su< ctx->Const.MaxTextureImageUnits; su++, samplers_used>>=
1) {
struct pipe_sampler_view *sampler_view = NULL;
- if (fprog->Base.SamplersUsed& (1<< su)) {
+
+ if (samplers_used& 1) {
GLboolean retval;
GLuint texUnit;
@@ -317,7 +320,10 @@ update_fragment_textures(struct st_context *st)
continue;
st->state.num_textures = su + 1;
- }
+ } else if (samplers_used == 0&& su>= old_max)
+ /* if we've reset all the old views and we have no more new ones */
+ break;
+
Just a minor nit: would you mind putting braces there?
pipe_sampler_view_reference(&st->state.sampler_views[su], sampler_view);
}
Reviewed-by: Brian Paul <bri...@vmware.com>
BTW, if you're looking for something else to optimize in the state
validation code, look at the calls to st_finalize_texture().
We're calling it both from the update_single_texture() function used
for vert/frag tex validation AND from finalize_textures(). The later
was added to deal with an OOM condition, IIRC. I think the results of
finalize_textures() could be saved to avoid calling
st_finalize_texture() in the vert/frag validation code.
In any case, st_finalize_texture() should be smarter too. I think we
could have some sort of per-texture dirty flag to avoid redundant
validation.
-Brian
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev