Mesa (master): nir/glsl_to_nir: use _mesa_fls() to compute num_textures

Alejandro Pinheiro apinheiro at kemper.freedesktop.org
Mon Nov 16 08:25:45 UTC 2015


Module: Mesa
Branch: master
Commit: 40c2acef5cfe28f4ac371203bd70bfc7a222ba26
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=40c2acef5cfe28f4ac371203bd70bfc7a222ba26

Author: Juan A. Suarez Romero <jasuarez at igalia.com>
Date:   Fri Nov  6 12:23:17 2015 +0000

nir/glsl_to_nir: use _mesa_fls() to compute num_textures

Replace the current loop by a direct call to _mesa_fls() function.

It also fixes an implicit bug in the current code where num_textures
seems to be one value less than it should be when sh->Program->SamplersUsed > 0.

For instance, num_textures is 0 instead of 1 when
sh->Program->SamplersUsed is 1.

Signed-off-by: Juan A. Suarez Romero <jasuarez at igalia.com>
Reviewed-by: Matt Turner <mattst88 at gmail.com>

---

 src/glsl/nir/glsl_to_nir.cpp |    9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
index b10d192..38b8390 100644
--- a/src/glsl/nir/glsl_to_nir.cpp
+++ b/src/glsl/nir/glsl_to_nir.cpp
@@ -31,6 +31,7 @@
 #include "ir_visitor.h"
 #include "ir_hierarchical_visitor.h"
 #include "ir.h"
+#include "main/imports.h"
 
 /*
  * pass to lower GLSL IR to NIR
@@ -145,16 +146,10 @@ glsl_to_nir(const struct gl_shader_program *shader_prog,
 
    nir_lower_outputs_to_temporaries(shader);
 
-   /* TODO: Use _mesa_fls instead */
-   unsigned num_textures = 0;
-   for (unsigned i = 0; i < 8 * sizeof(sh->Program->SamplersUsed); i++)
-      if (sh->Program->SamplersUsed & (1 << i))
-         num_textures = i;
-
    shader->info.name = ralloc_asprintf(shader, "GLSL%d", shader_prog->Name);
    if (shader_prog->Label)
       shader->info.label = ralloc_strdup(shader, shader_prog->Label);
-   shader->info.num_textures = num_textures;
+   shader->info.num_textures = _mesa_fls(sh->Program->SamplersUsed);
    shader->info.num_ubos = sh->NumUniformBlocks;
    shader->info.num_abos = shader_prog->NumAtomicBuffers;
    shader->info.num_ssbos = sh->NumShaderStorageBlocks;




More information about the mesa-commit mailing list