[Mesa-dev] [PATCH 24/29] mesa: Use bitmask/ffs to iterate SamplersUsed

2016-06-13 Thread Mathias . Froehlich
From: Mathias Fröhlich 

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 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/uniforms.c | 42 +-
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index 35b93d3..d02f92e 100644
--- a/src/mesa/main/uniforms.c
+++ b/src/mesa/main/uniforms.c
@@ -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,26 +78,25 @@ _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)) {
- GLuint unit = shader->SamplerUnits[s];
- GLuint tgt = shader->SamplerTargets[s];
- assert(unit < ARRAY_SIZE(prog->TexturesUsed));
- assert(tgt < NUM_TEXTURE_TARGETS);
-
- /* The types of the samplers associated with a particular texture
-  * unit must be an exact match.  Page 74 (page 89 of the PDF) of the
-  * OpenGL 3.3 core spec says:
-  *
-  * "It is not allowed to have variables of different sampler
-  * types pointing to the same texture image unit within a program
-  * object."
-  */
- if (prog->TexturesUsed[unit] & ~(1 << tgt))
-shProg->SamplersValidated = GL_FALSE;
-
- prog->TexturesUsed[unit] |= (1 << tgt);
-  }
+   while (mask) {
+  const int s = u_bit_scan();
+  GLuint unit = shader->SamplerUnits[s];
+  GLuint tgt = shader->SamplerTargets[s];
+  assert(unit < ARRAY_SIZE(prog->TexturesUsed));
+  assert(tgt < NUM_TEXTURE_TARGETS);
+
+  /* The types of the samplers associated with a particular texture
+   * unit must be an exact match.  Page 74 (page 89 of the PDF) of the
+   * OpenGL 3.3 core spec says:
+   *
+   * "It is not allowed to have variables of different sampler
+   * types pointing to the same texture image unit within a program
+   * object."
+   */
+  if (prog->TexturesUsed[unit] & ~(1 << tgt))
+ shProg->SamplersValidated = GL_FALSE;
+
+  prog->TexturesUsed[unit] |= (1 << tgt);
}
 }
 
-- 
2.5.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 24/29] mesa: Use bitmask/ffs to iterate SamplersUsed

2016-05-24 Thread Mathias . Froehlich
From: Mathias Fröhlich 

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

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/uniforms.c | 42 +-
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index 35b93d3..d60a4b9 100644
--- a/src/mesa/main/uniforms.c
+++ b/src/mesa/main/uniforms.c
@@ -66,7 +66,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,26 +77,26 @@ _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)) {
- GLuint unit = shader->SamplerUnits[s];
- GLuint tgt = shader->SamplerTargets[s];
- assert(unit < ARRAY_SIZE(prog->TexturesUsed));
- assert(tgt < NUM_TEXTURE_TARGETS);
-
- /* The types of the samplers associated with a particular texture
-  * unit must be an exact match.  Page 74 (page 89 of the PDF) of the
-  * OpenGL 3.3 core spec says:
-  *
-  * "It is not allowed to have variables of different sampler
-  * types pointing to the same texture image unit within a program
-  * object."
-  */
- if (prog->TexturesUsed[unit] & ~(1 << tgt))
-shProg->SamplersValidated = GL_FALSE;
-
- prog->TexturesUsed[unit] |= (1 << tgt);
-  }
+   while (mask) {
+  int s = ffs(mask) - 1;
+  GLuint unit = shader->SamplerUnits[s];
+  GLuint tgt = shader->SamplerTargets[s];
+  assert(unit < ARRAY_SIZE(prog->TexturesUsed));
+  assert(tgt < NUM_TEXTURE_TARGETS);
+  mask ^= (1u << s);
+
+  /* The types of the samplers associated with a particular texture
+   * unit must be an exact match.  Page 74 (page 89 of the PDF) of the
+   * OpenGL 3.3 core spec says:
+   *
+   * "It is not allowed to have variables of different sampler
+   * types pointing to the same texture image unit within a program
+   * object."
+   */
+  if (prog->TexturesUsed[unit] & ~(1 << tgt))
+ shProg->SamplersValidated = GL_FALSE;
+
+  prog->TexturesUsed[unit] |= (1 << tgt);
}
 }
 
-- 
2.5.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev