[Mesa-dev] [PATCH 12/31] mesa: Use bitmask/ffs to iterate enabled lights
Mathias.Froehlich at gmx.net
Mathias.Froehlich at gmx.net
Tue Jun 7 05:30:27 UTC 2016
From: Mathias Fröhlich <mathias.froehlich at web.de>
Replaces loops that iterate 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.
Reviewed-by: Brian Paul <brianp at vmware.com>
Signed-off-by: Mathias Fröhlich <Mathias.Froehlich at web.de>
---
src/mesa/main/light.c | 43 ++++++++++++++++++++++++++++++++-----------
src/mesa/main/rastpos.c | 8 +++++---
2 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
index a52efdb..49e99ce 100644
--- a/src/mesa/main/light.c
+++ b/src/mesa/main/light.c
@@ -612,7 +612,6 @@ _mesa_material_bitmask( struct gl_context *ctx, GLenum face, GLenum pname,
void
_mesa_update_material( struct gl_context *ctx, GLuint bitmask )
{
- struct gl_light *light, *list = &ctx->Light.EnabledList;
GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
if (MESA_VERBOSE & VERBOSE_MATERIAL)
@@ -623,14 +622,20 @@ _mesa_update_material( struct gl_context *ctx, GLuint bitmask )
/* update material ambience */
if (bitmask & MAT_BIT_FRONT_AMBIENT) {
- foreach (light, list) {
+ GLbitfield mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int i = _mesa_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[i];
SCALE_3V( light->_MatAmbient[0], light->Ambient,
mat[MAT_ATTRIB_FRONT_AMBIENT]);
}
}
if (bitmask & MAT_BIT_BACK_AMBIENT) {
- foreach (light, list) {
+ GLbitfield mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int i = _mesa_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[i];
SCALE_3V( light->_MatAmbient[1], light->Ambient,
mat[MAT_ATTRIB_BACK_AMBIENT]);
}
@@ -651,14 +656,20 @@ _mesa_update_material( struct gl_context *ctx, GLuint bitmask )
/* update material diffuse values */
if (bitmask & MAT_BIT_FRONT_DIFFUSE) {
- foreach (light, list) {
+ GLbitfield mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int i = _mesa_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[i];
SCALE_3V( light->_MatDiffuse[0], light->Diffuse,
mat[MAT_ATTRIB_FRONT_DIFFUSE] );
}
}
if (bitmask & MAT_BIT_BACK_DIFFUSE) {
- foreach (light, list) {
+ GLbitfield mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int i = _mesa_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[i];
SCALE_3V( light->_MatDiffuse[1], light->Diffuse,
mat[MAT_ATTRIB_BACK_DIFFUSE] );
}
@@ -666,14 +677,20 @@ _mesa_update_material( struct gl_context *ctx, GLuint bitmask )
/* update material specular values */
if (bitmask & MAT_BIT_FRONT_SPECULAR) {
- foreach (light, list) {
+ GLbitfield mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int i = _mesa_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[i];
SCALE_3V( light->_MatSpecular[0], light->Specular,
mat[MAT_ATTRIB_FRONT_SPECULAR]);
}
}
if (bitmask & MAT_BIT_BACK_SPECULAR) {
- foreach (light, list) {
+ GLbitfield mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int i = _mesa_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[i];
SCALE_3V( light->_MatSpecular[1], light->Specular,
mat[MAT_ATTRIB_BACK_SPECULAR]);
}
@@ -864,13 +881,15 @@ void
_mesa_update_lighting( struct gl_context *ctx )
{
GLbitfield flags = 0;
- struct gl_light *light;
ctx->Light._NeedEyeCoords = GL_FALSE;
if (!ctx->Light.Enabled)
return;
- foreach(light, &ctx->Light.EnabledList) {
+ GLbitfield mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int i = _mesa_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[i];
flags |= light->_Flags;
}
@@ -926,7 +945,6 @@ _mesa_update_lighting( struct gl_context *ctx )
static void
compute_light_positions( struct gl_context *ctx )
{
- struct gl_light *light;
static const GLfloat eye_z[3] = { 0, 0, 1 };
if (!ctx->Light.Enabled)
@@ -939,7 +957,10 @@ compute_light_positions( struct gl_context *ctx )
TRANSFORM_NORMAL( ctx->_EyeZDir, eye_z, ctx->ModelviewMatrixStack.Top->m );
}
- foreach (light, &ctx->Light.EnabledList) {
+ GLbitfield mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int i = _mesa_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[i];
if (ctx->_NeedEyeCoords) {
/* _Position is in eye coordinate space */
diff --git a/src/mesa/main/rastpos.c b/src/mesa/main/rastpos.c
index b468219..819a9a9 100644
--- a/src/mesa/main/rastpos.c
+++ b/src/mesa/main/rastpos.c
@@ -37,7 +37,6 @@
#include "state.h"
#include "main/dispatch.h"
#include "main/viewport.h"
-#include "util/simple_list.h"
@@ -125,7 +124,7 @@ shade_rastpos(struct gl_context *ctx,
GLfloat Rspec[4])
{
/*const*/ GLfloat (*base)[3] = ctx->Light._BaseColor;
- const struct gl_light *light;
+ GLbitfield mask;
GLfloat diffuseColor[4], specularColor[4]; /* for RGB mode only */
COPY_3V(diffuseColor, base[0]);
@@ -133,7 +132,10 @@ shade_rastpos(struct gl_context *ctx,
ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3], 0.0F, 1.0F );
ASSIGN_4V(specularColor, 0.0, 0.0, 0.0, 1.0);
- foreach (light, &ctx->Light.EnabledList) {
+ mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int i = _mesa_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[i];
GLfloat attenuation = 1.0;
GLfloat VP[3]; /* vector from vertex to light pos */
GLfloat n_dot_VP;
--
2.5.5
More information about the mesa-dev
mailing list