st/mesa: simplify update_shader_samplers
authorMarek Olšák <marek.olsak@amd.com>
Sat, 10 Jun 2017 19:59:07 +0000 (21:59 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 21 Jun 2017 23:51:02 +0000 (01:51 +0200)
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/mesa/state_tracker/st_atom_sampler.c

index 5f3f852ab3b3c85beaa4c5a56e152595d1662040..2a7353574e9681da312d9c1e74ef44b635eee289 100644 (file)
@@ -265,38 +265,29 @@ update_shader_samplers(struct st_context *st,
                        enum pipe_shader_type shader_stage,
                        const struct gl_program *prog,
                        struct pipe_sampler_state *samplers,
-                       unsigned *num_samplers)
+                       unsigned *out_num_samplers)
 {
    GLbitfield samplers_used = prog->SamplersUsed;
    GLbitfield free_slots = ~prog->SamplersUsed;
    GLbitfield external_samplers_used = prog->ExternalSamplersUsed;
-   GLuint unit;
-   const GLuint old_max = *num_samplers;
+   unsigned unit, num_samplers;
    const struct pipe_sampler_state *states[PIPE_MAX_SAMPLERS];
 
    if (samplers_used == 0x0)
       return;
 
-   *num_samplers = 0;
+   num_samplers = util_last_bit(samplers_used);
 
    /* loop over sampler units (aka tex image units) */
    for (unit = 0; samplers_used; unit++, samplers_used >>= 1) {
       struct pipe_sampler_state *sampler = samplers + unit;
 
       if (samplers_used & 1) {
-         const GLuint texUnit = prog->SamplerUnits[unit];
-
-         st_convert_sampler_from_unit(st, sampler, texUnit);
+         st_convert_sampler_from_unit(st, sampler, prog->SamplerUnits[unit]);
          states[unit] = sampler;
-         *num_samplers = unit + 1;
-      }
-      else if (samplers_used != 0 || unit < old_max) {
+      } else {
          states[unit] = NULL;
       }
-      else {
-         /* if we've reset all the old samplers and we have no more new ones */
-         break;
-      }
    }
 
    /* For any external samplers with multiplaner YUV, stuff the additional
@@ -331,10 +322,11 @@ update_shader_samplers(struct st_context *st,
          break;
       }
 
-      *num_samplers = MAX2(*num_samplers, extra + 1);
+      num_samplers = MAX2(num_samplers, extra + 1);
    }
 
-   cso_set_samplers(st->cso_context, shader_stage, *num_samplers, states);
+   cso_set_samplers(st->cso_context, shader_stage, num_samplers, states);
+   *out_num_samplers = num_samplers;
 }