mesa: Use bitmask/ffs to iterate SamplersUsed

Replaces an iterate and test bit in a bitmask loop by a
loop only iterating over the bits set in the bitmask.

v2: Use _mesa_bit_scan{,64} instead of open coding.
v3: Use u_bit_scan{,64} instead of _mesa_bit_scan{,64}.

Reviewed-by: Brian Paul <brianp@vmware.com>
Signed-off-by: Mathias Fröhlich <Mathias.Froehlich@web.de>
This commit is contained in:
Mathias Fröhlich
2016-05-22 14:10:19 +02:00
parent 53691b7cb1
commit c14ec9aafa

View File

@@ -46,6 +46,7 @@
#include "compiler/glsl/ir_uniform.h"
#include "compiler/glsl_types.h"
#include "program/program.h"
#include "util/bitscan.h"
/**
* Update the vertex/fragment program's TexturesUsed array.
@@ -66,7 +67,7 @@ void
_mesa_update_shader_textures_used(struct gl_shader_program *shProg,
struct gl_program *prog)
{
GLuint s;
GLbitfield mask = prog->SamplersUsed;
struct gl_shader *shader =
shProg->_LinkedShaders[_mesa_program_enum_to_shader_stage(prog->Target)];
@@ -77,8 +78,8 @@ _mesa_update_shader_textures_used(struct gl_shader_program *shProg,
shProg->SamplersValidated = GL_TRUE;
for (s = 0; s < MAX_SAMPLERS; s++) {
if (prog->SamplersUsed & (1u << s)) {
while (mask) {
const int s = u_bit_scan(&mask);
GLuint unit = shader->SamplerUnits[s];
GLuint tgt = shader->SamplerTargets[s];
assert(unit < ARRAY_SIZE(prog->TexturesUsed));
@@ -98,7 +99,6 @@ _mesa_update_shader_textures_used(struct gl_shader_program *shProg,
prog->TexturesUsed[unit] |= (1 << tgt);
}
}
}
/**
* Connect a piece of driver storage with a part of a uniform