[Mesa-dev] [PATCH 14/29] radeon/r200: Use bitmask/ffs to iterate enabled lights

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

Replaces a loop that iterates all lights and test
which of them is enabled by a loop only iterating over
the bits set in the enabled 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/drivers/dri/r200/r200_state.c | 40 ++--
 src/mesa/drivers/dri/radeon/radeon_state.c | 42 +++---
 2 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/src/mesa/drivers/dri/r200/r200_state.c 
b/src/mesa/drivers/dri/r200/r200_state.c
index f0693ba..0e38afc 100644
--- a/src/mesa/drivers/dri/r200/r200_state.c
+++ b/src/mesa/drivers/dri/r200/r200_state.c
@@ -49,6 +49,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
 #include "tnl/t_pipeline.h"
 #include "swrast_setup/swrast_setup.h"
 #include "drivers/common/meta.h"
+#include "util/bitscan.h"
 
 #include "radeon_common.h"
 #include "radeon_mipmap_tree.h"
@@ -1112,27 +1113,26 @@ static void update_light( struct gl_context *ctx )
 
 
if (ctx->Light.Enabled) {
-  GLint p;
-  for (p = 0 ; p < MAX_LIGHTS; p++) {
-if (ctx->Light.Light[p].Enabled) {
-   struct gl_light *l = >Light.Light[p];
-   GLfloat *fcmd = (GLfloat *)R200_DB_STATE( lit[p] );
-
-   if (l->EyePosition[3] == 0.0) {
-  COPY_3FV( [LIT_POSITION_X], l->_VP_inf_norm );
-  COPY_3FV( [LIT_DIRECTION_X], l->_h_inf_norm );
-  fcmd[LIT_POSITION_W] = 0;
-  fcmd[LIT_DIRECTION_W] = 0;
-   } else {
-  COPY_4V( [LIT_POSITION_X], l->_Position );
-  fcmd[LIT_DIRECTION_X] = -l->_NormSpotDirection[0];
-  fcmd[LIT_DIRECTION_Y] = -l->_NormSpotDirection[1];
-  fcmd[LIT_DIRECTION_Z] = -l->_NormSpotDirection[2];
-  fcmd[LIT_DIRECTION_W] = 0;
-   }
+  GLbitfield mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int p = u_bit_scan();
+ struct gl_light *l = >Light.Light[p];
+ GLfloat *fcmd = (GLfloat *)R200_DB_STATE( lit[p] );
+
+ if (l->EyePosition[3] == 0.0) {
+COPY_3FV( [LIT_POSITION_X], l->_VP_inf_norm );
+COPY_3FV( [LIT_DIRECTION_X], l->_h_inf_norm );
+fcmd[LIT_POSITION_W] = 0;
+fcmd[LIT_DIRECTION_W] = 0;
+ } else {
+COPY_4V( [LIT_POSITION_X], l->_Position );
+fcmd[LIT_DIRECTION_X] = -l->_NormSpotDirection[0];
+fcmd[LIT_DIRECTION_Y] = -l->_NormSpotDirection[1];
+fcmd[LIT_DIRECTION_Z] = -l->_NormSpotDirection[2];
+fcmd[LIT_DIRECTION_W] = 0;
+ }
 
-   R200_DB_STATECHANGE( rmesa, >hw.lit[p] );
-}
+ R200_DB_STATECHANGE( rmesa, >hw.lit[p] );
   }
}
 }
diff --git a/src/mesa/drivers/dri/radeon/radeon_state.c 
b/src/mesa/drivers/dri/radeon/radeon_state.c
index 8a1b81d..93bc0f9 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state.c
@@ -51,6 +51,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
 #include "tnl/t_pipeline.h"
 #include "swrast_setup/swrast_setup.h"
 #include "drivers/common/meta.h"
+#include "util/bitscan.h"
 
 #include "radeon_context.h"
 #include "radeon_mipmap_tree.h"
@@ -892,27 +893,26 @@ static void update_light( struct gl_context *ctx )
 
 
if (ctx->Light.Enabled) {
-  GLint p;
-  for (p = 0 ; p < MAX_LIGHTS; p++) {
-if (ctx->Light.Light[p].Enabled) {
-   struct gl_light *l = >Light.Light[p];
-   GLfloat *fcmd = (GLfloat *)RADEON_DB_STATE( lit[p] );
-
-   if (l->EyePosition[3] == 0.0) {
-  COPY_3FV( [LIT_POSITION_X], l->_VP_inf_norm );
-  COPY_3FV( [LIT_DIRECTION_X], l->_h_inf_norm );
-  fcmd[LIT_POSITION_W] = 0;
-  fcmd[LIT_DIRECTION_W] = 0;
-   } else {
-  COPY_4V( [LIT_POSITION_X], l->_Position );
-  fcmd[LIT_DIRECTION_X] = -l->_NormSpotDirection[0];
-  fcmd[LIT_DIRECTION_Y] = -l->_NormSpotDirection[1];
-  fcmd[LIT_DIRECTION_Z] = -l->_NormSpotDirection[2];
-  fcmd[LIT_DIRECTION_W] = 0;
-   }
-
-   RADEON_DB_STATECHANGE( rmesa, >hw.lit[p] );
-}
+  GLbitfield mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int p = u_bit_scan();
+ struct gl_light *l = >Light.Light[p];
+ GLfloat *fcmd = (GLfloat *)RADEON_DB_STATE( lit[p] );
+
+ if (l->EyePosition[3] == 0.0) {
+COPY_3FV( [LIT_POSITION_X], l->_VP_inf_norm );
+COPY_3FV( [LIT_DIRECTION_X], l->_h_inf_norm );
+fcmd[LIT_POSITION_W] = 0;
+fcmd[LIT_DIRECTION_W] = 0;
+ } else {
+COPY_4V( [LIT_POSITION_X], l->_Position );
+

[Mesa-dev] [PATCH 14/29] radeon/r200: Use bitmask/ffs to iterate enabled lights

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

Replaces a loop that iterates all lights and test
which of them is enabled by a loop only iterating over
the bits set in the enabled bitmask.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/dri/r200/r200_state.c | 40 ++--
 src/mesa/drivers/dri/radeon/radeon_state.c | 42 +++---
 2 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/src/mesa/drivers/dri/r200/r200_state.c 
b/src/mesa/drivers/dri/r200/r200_state.c
index 017930f..86144e0 100644
--- a/src/mesa/drivers/dri/r200/r200_state.c
+++ b/src/mesa/drivers/dri/r200/r200_state.c
@@ -1112,27 +1112,27 @@ static void update_light( struct gl_context *ctx )
 
 
if (ctx->Light.Enabled) {
-  GLint p;
-  for (p = 0 ; p < MAX_LIGHTS; p++) {
-if (ctx->Light.Light[p].Enabled) {
-   struct gl_light *l = >Light.Light[p];
-   GLfloat *fcmd = (GLfloat *)R200_DB_STATE( lit[p] );
-
-   if (l->EyePosition[3] == 0.0) {
-  COPY_3FV( [LIT_POSITION_X], l->_VP_inf_norm );
-  COPY_3FV( [LIT_DIRECTION_X], l->_h_inf_norm );
-  fcmd[LIT_POSITION_W] = 0;
-  fcmd[LIT_DIRECTION_W] = 0;
-   } else {
-  COPY_4V( [LIT_POSITION_X], l->_Position );
-  fcmd[LIT_DIRECTION_X] = -l->_NormSpotDirection[0];
-  fcmd[LIT_DIRECTION_Y] = -l->_NormSpotDirection[1];
-  fcmd[LIT_DIRECTION_Z] = -l->_NormSpotDirection[2];
-  fcmd[LIT_DIRECTION_W] = 0;
-   }
+  GLbitfield mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int p = ffs(mask) - 1;
+ struct gl_light *l = >Light.Light[p];
+ GLfloat *fcmd = (GLfloat *)R200_DB_STATE( lit[p] );
+ mask ^= (1u << p);
+
+ if (l->EyePosition[3] == 0.0) {
+COPY_3FV( [LIT_POSITION_X], l->_VP_inf_norm );
+COPY_3FV( [LIT_DIRECTION_X], l->_h_inf_norm );
+fcmd[LIT_POSITION_W] = 0;
+fcmd[LIT_DIRECTION_W] = 0;
+ } else {
+COPY_4V( [LIT_POSITION_X], l->_Position );
+fcmd[LIT_DIRECTION_X] = -l->_NormSpotDirection[0];
+fcmd[LIT_DIRECTION_Y] = -l->_NormSpotDirection[1];
+fcmd[LIT_DIRECTION_Z] = -l->_NormSpotDirection[2];
+fcmd[LIT_DIRECTION_W] = 0;
+ }
 
-   R200_DB_STATECHANGE( rmesa, >hw.lit[p] );
-}
+ R200_DB_STATECHANGE( rmesa, >hw.lit[p] );
   }
}
 }
diff --git a/src/mesa/drivers/dri/radeon/radeon_state.c 
b/src/mesa/drivers/dri/radeon/radeon_state.c
index 8a1b81d..5f52b39 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state.c
@@ -892,27 +892,27 @@ static void update_light( struct gl_context *ctx )
 
 
if (ctx->Light.Enabled) {
-  GLint p;
-  for (p = 0 ; p < MAX_LIGHTS; p++) {
-if (ctx->Light.Light[p].Enabled) {
-   struct gl_light *l = >Light.Light[p];
-   GLfloat *fcmd = (GLfloat *)RADEON_DB_STATE( lit[p] );
-
-   if (l->EyePosition[3] == 0.0) {
-  COPY_3FV( [LIT_POSITION_X], l->_VP_inf_norm );
-  COPY_3FV( [LIT_DIRECTION_X], l->_h_inf_norm );
-  fcmd[LIT_POSITION_W] = 0;
-  fcmd[LIT_DIRECTION_W] = 0;
-   } else {
-  COPY_4V( [LIT_POSITION_X], l->_Position );
-  fcmd[LIT_DIRECTION_X] = -l->_NormSpotDirection[0];
-  fcmd[LIT_DIRECTION_Y] = -l->_NormSpotDirection[1];
-  fcmd[LIT_DIRECTION_Z] = -l->_NormSpotDirection[2];
-  fcmd[LIT_DIRECTION_W] = 0;
-   }
-
-   RADEON_DB_STATECHANGE( rmesa, >hw.lit[p] );
-}
+  GLbitfield mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int p = ffs(mask) - 1;
+ struct gl_light *l = >Light.Light[p];
+ GLfloat *fcmd = (GLfloat *)RADEON_DB_STATE( lit[p] );
+ mask ^= (1u << p);
+
+ if (l->EyePosition[3] == 0.0) {
+COPY_3FV( [LIT_POSITION_X], l->_VP_inf_norm );
+COPY_3FV( [LIT_DIRECTION_X], l->_h_inf_norm );
+fcmd[LIT_POSITION_W] = 0;
+fcmd[LIT_DIRECTION_W] = 0;
+ } else {
+COPY_4V( [LIT_POSITION_X], l->_Position );
+fcmd[LIT_DIRECTION_X] = -l->_NormSpotDirection[0];
+fcmd[LIT_DIRECTION_Y] = -l->_NormSpotDirection[1];
+fcmd[LIT_DIRECTION_Z] = -l->_NormSpotDirection[2];
+fcmd[LIT_DIRECTION_W] = 0;
+ }
+
+ RADEON_DB_STATECHANGE( rmesa, >hw.lit[p] );
   }
}
 }
-- 
2.5.5

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