[Mesa-dev] [PATCH] util: Use win32 intrinsics for util_last_bit if present.

2016-08-09 Thread Mathias . Froehlich
From: Mathias Fröhlich 

v2: Split into two patches.
v3: Fix off by one problem.

Signed-off-by: Mathias Fröhlich 
---
 src/util/bitscan.h | 12 
 1 file changed, 12 insertions(+)

diff --git a/src/util/bitscan.h b/src/util/bitscan.h
index 0743fe7..8afef81 100644
--- a/src/util/bitscan.h
+++ b/src/util/bitscan.h
@@ -157,6 +157,12 @@ util_last_bit(unsigned u)
 {
 #if defined(HAVE___BUILTIN_CLZ)
return u == 0 ? 0 : 32 - __builtin_clz(u);
+#elif defined(_MSC_VER) && (_M_IX86 || _M_ARM || _M_AMD64 || _M_IA64)
+   unsigned long index;
+   if (_BitScanReverse(&index, u))
+  return index + 1;
+   else
+  return 0;
 #else
unsigned r = 0;
while (u) {
@@ -177,6 +183,12 @@ util_last_bit64(uint64_t u)
 {
 #if defined(HAVE___BUILTIN_CLZLL)
return u == 0 ? 0 : 64 - __builtin_clzll(u);
+#elif defined(_MSC_VER) && (_M_AMD64 || _M_ARM || _M_IA64)
+   unsigned long index;
+   if (_BitScanReverse64(&index, u))
+  return index + 1;
+   else
+  return 0;
 #else
unsigned r = 0;
while (u) {
-- 
2.7.4

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


[Mesa-dev] [PATCH 0/5] Move check for mapped buffers into api_validate.

2016-08-14 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi all,

This series moves the call to check for mapped vertex
buffer objects on draw from the vbo code into api_validate.c.
There we already check for various conditions to validate the
current draw call. Some cleanups in that area are included.

Please review!
Thanks

Mathias



Mathias Fröhlich (5):
  vbo: Array draw must not care about glBegin/glEnd vbo mapping.
  mesa: Move _mesa_all_buffers_are_unmapped to arrayobj.c.
  mesa: Move check for vbo mapping into api_validate.c.
  vbo: Remove allways true return from vbo_bind_arrays.
  mesa: Remove duplicate include.

 src/mesa/main/api_validate.c  |  8 +++-
 src/mesa/main/arrayobj.c  | 28 +
 src/mesa/main/arrayobj.h  |  4 ++
 src/mesa/vbo/vbo.h|  2 +-
 src/mesa/vbo/vbo_exec_array.c | 92 ++-
 5 files changed, 51 insertions(+), 83 deletions(-)

-- 
2.7.4

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


[Mesa-dev] [PATCH 1/5] vbo: Array draw must not care about glBegin/glEnd vbo mapping.

2016-08-14 Thread Mathias . Froehlich
From: Mathias Fröhlich 

In array draw do not check if the vertex buffer object that
is used to implement immediate mode glBegin/glEnd is mapped.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/vbo/vbo_exec_array.c | 18 +-
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c
index f371890..8789837 100644
--- a/src/mesa/vbo/vbo_exec_array.c
+++ b/src/mesa/vbo/vbo_exec_array.c
@@ -77,22 +77,6 @@ check_input_buffers_are_unmapped(const struct 
gl_vertex_array_object *vao)
 
 
 /**
- * A debug function that may be called from other parts of Mesa as
- * needed during debugging.
- */
-static bool
-check_buffers_are_unmapped(struct gl_context *ctx)
-{
-   struct vbo_context *vbo = vbo_context(ctx);
-   struct vbo_exec_context *exec = &vbo->exec;
-
-   /* check the current vertex arrays */
-   return !_mesa_check_disallowed_mapping(exec->vtx.bufferobj) &&
-  check_input_buffers_are_unmapped(ctx->Array.VAO);
-}
-
-
-/**
  * Check that element 'j' of the array has reasonable data.
  * Map VBO if needed.
  * For debugging purposes; not normally used.
@@ -446,7 +430,7 @@ vbo_bind_arrays(struct gl_context *ctx)
   }
}
 
-   if (!check_buffers_are_unmapped(ctx)) {
+   if (!check_input_buffers_are_unmapped(ctx->Array.VAO)) {
   _mesa_error(ctx, GL_INVALID_OPERATION,
   "draw call (vertex buffers are mapped)");
   return false;
-- 
2.7.4

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


[Mesa-dev] [PATCH 4/5] vbo: Remove allways true return from vbo_bind_arrays.

2016-08-14 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/vbo/vbo.h|  2 +-
 src/mesa/vbo/vbo_exec_array.c | 36 +++-
 2 files changed, 12 insertions(+), 26 deletions(-)

diff --git a/src/mesa/vbo/vbo.h b/src/mesa/vbo/vbo.h
index 939a3a6..73478e6 100644
--- a/src/mesa/vbo/vbo.h
+++ b/src/mesa/vbo/vbo.h
@@ -197,7 +197,7 @@ void vbo_set_draw_func(struct gl_context *ctx, 
vbo_draw_func func);
 void vbo_set_indirect_draw_func(struct gl_context *ctx,
 vbo_indirect_draw_func func);
 
-bool vbo_bind_arrays(struct gl_context *ctx);
+void vbo_bind_arrays(struct gl_context *ctx);
 
 size_t
 vbo_count_tessellated_primitives(GLenum mode, GLuint count,
diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c
index bfa9cd6..2fee50b 100644
--- a/src/mesa/vbo/vbo_exec_array.c
+++ b/src/mesa/vbo/vbo_exec_array.c
@@ -369,7 +369,7 @@ recalculate_input_bindings(struct gl_context *ctx)
  * Note that this might set the _NEW_VARYING_VP_INPUTS dirty flag so state
  * validation must be done after this call.
  */
-bool
+void
 vbo_bind_arrays(struct gl_context *ctx)
 {
struct vbo_context *vbo = vbo_context(ctx);
@@ -395,8 +395,6 @@ vbo_bind_arrays(struct gl_context *ctx)
  exec->validating = GL_FALSE;
   }
}
-
-   return true;
 }
 
 /**
@@ -412,8 +410,7 @@ vbo_draw_arrays(struct gl_context *ctx, GLenum mode, GLint 
start,
struct vbo_context *vbo = vbo_context(ctx);
struct _mesa_prim prim[2];
 
-   if (!vbo_bind_arrays(ctx))
-  return;
+   vbo_bind_arrays(ctx);
 
/* init most fields to zero */
memset(prim, 0, sizeof(prim));
@@ -762,8 +759,7 @@ vbo_validated_drawrangeelements(struct gl_context *ctx, 
GLenum mode,
struct _mesa_index_buffer ib;
struct _mesa_prim prim[1];
 
-   if (!vbo_bind_arrays(ctx))
-  return;
+   vbo_bind_arrays(ctx);
 
ib.count = count;
ib.type = type;
@@ -1106,10 +1102,7 @@ vbo_validated_multidrawelements(struct gl_context *ctx, 
GLenum mode,
   return;
}
 
-   if (!vbo_bind_arrays(ctx)) {
-  free(prim);
-  return;
-   }
+   vbo_bind_arrays(ctx);
 
min_index_ptr = (uintptr_t)indices[0];
max_index_ptr = 0;
@@ -1273,8 +1266,7 @@ vbo_draw_transform_feedback(struct gl_context *ctx, 
GLenum mode,
   return;
}
 
-   if (!vbo_bind_arrays(ctx))
-  return;
+   vbo_bind_arrays(ctx);
 
/* init most fields to zero */
memset(prim, 0, sizeof(prim));
@@ -1370,8 +1362,7 @@ vbo_validated_drawarraysindirect(struct gl_context *ctx,
 {
struct vbo_context *vbo = vbo_context(ctx);
 
-   if (!vbo_bind_arrays(ctx))
-  return;
+   vbo_bind_arrays(ctx);
 
vbo->draw_indirect_prims(ctx, mode,
 ctx->DrawIndirectBuffer, (GLsizeiptr)indirect,
@@ -1394,8 +1385,7 @@ vbo_validated_multidrawarraysindirect(struct gl_context 
*ctx,
if (primcount == 0)
   return;
 
-   if (!vbo_bind_arrays(ctx))
-  return;
+   vbo_bind_arrays(ctx);
 
vbo->draw_indirect_prims(ctx, mode,
 ctx->DrawIndirectBuffer, offset,
@@ -1414,8 +1404,7 @@ vbo_validated_drawelementsindirect(struct gl_context *ctx,
struct vbo_context *vbo = vbo_context(ctx);
struct _mesa_index_buffer ib;
 
-   if (!vbo_bind_arrays(ctx))
-  return;
+   vbo_bind_arrays(ctx);
 
ib.count = 0; /* unknown */
ib.type = type;
@@ -1445,8 +1434,7 @@ vbo_validated_multidrawelementsindirect(struct gl_context 
*ctx,
if (primcount == 0)
   return;
 
-   if (!vbo_bind_arrays(ctx))
-  return;
+   vbo_bind_arrays(ctx);
 
/* NOTE: IndexBufferObj is guaranteed to be a VBO. */
 
@@ -1566,8 +1554,7 @@ vbo_validated_multidrawarraysindirectcount(struct 
gl_context *ctx,
if (maxdrawcount == 0)
   return;
 
-   if (!vbo_bind_arrays(ctx))
-  return;
+   vbo_bind_arrays(ctx);
 
vbo->draw_indirect_prims(ctx, mode,
 ctx->DrawIndirectBuffer, offset,
@@ -1594,8 +1581,7 @@ vbo_validated_multidrawelementsindirectcount(struct 
gl_context *ctx,
if (maxdrawcount == 0)
   return;
 
-   if (!vbo_bind_arrays(ctx))
-  return;
+   vbo_bind_arrays(ctx);
 
/* NOTE: IndexBufferObj is guaranteed to be a VBO. */
 
-- 
2.7.4

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


[Mesa-dev] [PATCH 3/5] mesa: Move check for vbo mapping into api_validate.c.

2016-08-14 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Instead of checking for mapped buffers in vbo_bind_arrays
do this check in api_validate.c. This additionally
enables printing the draw calls name into the error
string.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/api_validate.c  | 7 +++
 src/mesa/vbo/vbo_exec_array.c | 8 +---
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c
index ec3cc1b..ae3e118 100644
--- a/src/mesa/main/api_validate.c
+++ b/src/mesa/main/api_validate.c
@@ -25,6 +25,7 @@
 #include 
 #include "glheader.h"
 #include "api_validate.h"
+#include "arrayobj.h"
 #include "bufferobj.h"
 #include "context.h"
 #include "imports.h"
@@ -119,6 +120,12 @@ check_valid_to_render(struct gl_context *ctx, const char 
*function)
   unreachable("Invalid API value in check_valid_to_render()");
}
 
+   if (!_mesa_all_buffers_are_unmapped(ctx->Array.VAO)) {
+  _mesa_error(ctx, GL_INVALID_OPERATION,
+  "%s(vertex buffers are mapped)", function);
+  return false;
+   }
+
return true;
 }
 
diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c
index e1aa3ac..bfa9cd6 100644
--- a/src/mesa/vbo/vbo_exec_array.c
+++ b/src/mesa/vbo/vbo_exec_array.c
@@ -396,13 +396,7 @@ vbo_bind_arrays(struct gl_context *ctx)
   }
}
 
-   if (!_mesa_all_buffers_are_unmapped(ctx->Array.VAO)) {
-  _mesa_error(ctx, GL_INVALID_OPERATION,
-  "draw call (vertex buffers are mapped)");
-  return false;
-   } else {
-  return true;
-   }
+   return true;
 }
 
 /**
-- 
2.7.4

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


[Mesa-dev] [PATCH 5/5] mesa: Remove duplicate include.

2016-08-14 Thread Mathias . Froehlich
From: Mathias Fröhlich 

In api_validate.c stdbool.h was included twice.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/api_validate.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c
index ae3e118..384a8858 100644
--- a/src/mesa/main/api_validate.c
+++ b/src/mesa/main/api_validate.c
@@ -33,7 +33,6 @@
 #include "enums.h"
 #include "vbo/vbo.h"
 #include "transformfeedback.h"
-#include 
 
 
 /**
-- 
2.7.4

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


[Mesa-dev] [PATCH 2/5] mesa: Move _mesa_all_buffers_are_unmapped to arrayobj.c.

2016-08-14 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Move the function to check if all vao buffers are
unmapped into the vao implementation file.
Rename the function to _mesa_all_buffers_are_unmapped.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/arrayobj.c  | 28 
 src/mesa/main/arrayobj.h  |  4 
 src/mesa/vbo/vbo_exec_array.c | 36 +---
 3 files changed, 33 insertions(+), 35 deletions(-)

diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index becf32f..13f2dd7 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -393,6 +393,34 @@ _mesa_all_varyings_in_vbos(const struct 
gl_vertex_array_object *vao)
return true;
 }
 
+bool
+_mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao)
+{
+   /* Walk the enabled arrays that have a vbo attached */
+   GLbitfield64 mask = vao->_Enabled & vao->VertexAttribBufferMask;
+
+   while (mask) {
+  const int i = ffsll(mask) - 1;
+  const struct gl_vertex_attrib_array *attrib_array =
+ &vao->VertexAttrib[i];
+  const struct gl_vertex_buffer_binding *buffer_binding =
+ &vao->VertexBinding[attrib_array->VertexBinding];
+
+  /* Only enabled arrays shall appear in the _Enabled bitmask */
+  assert(attrib_array->Enabled);
+  /* We have already masked with vao->VertexAttribBufferMask  */
+  assert(_mesa_is_bufferobj(buffer_binding->BufferObj));
+
+  /* Bail out once we find the first disallowed mapping */
+  if (_mesa_check_disallowed_mapping(buffer_binding->BufferObj))
+ return false;
+
+  /* We have handled everything that is bound to this buffer_binding. */
+  mask &= ~buffer_binding->_BoundArrays;
+   }
+
+   return true;
+}
 
 /**/
 /* API Functions  */
diff --git a/src/mesa/main/arrayobj.h b/src/mesa/main/arrayobj.h
index d30c85c..830502e 100644
--- a/src/mesa/main/arrayobj.h
+++ b/src/mesa/main/arrayobj.h
@@ -85,6 +85,10 @@ _mesa_update_vao_client_arrays(struct gl_context *ctx,
 extern bool
 _mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao);
 
+/* Returns true if all vbos are unmapped */
+extern bool
+_mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao);
+
 /*
  * API functions
  */
diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c
index 8789837..e1aa3ac 100644
--- a/src/mesa/vbo/vbo_exec_array.c
+++ b/src/mesa/vbo/vbo_exec_array.c
@@ -43,40 +43,6 @@
 
 
 /**
- * All vertex buffers should be in an unmapped state when we're about
- * to draw.
- */
-static bool
-check_input_buffers_are_unmapped(const struct gl_vertex_array_object *vao)
-{
-   /* Walk the enabled arrays that have a vbo attached */
-   GLbitfield64 mask = vao->_Enabled & vao->VertexAttribBufferMask;
-
-   while (mask) {
-  int i = ffsll(mask) - 1;
-  const struct gl_vertex_attrib_array *attrib_array =
- &vao->VertexAttrib[i];
-  const struct gl_vertex_buffer_binding *buffer_binding =
- &vao->VertexBinding[attrib_array->VertexBinding];
-
-  /* Only enabled arrays shall appear in the _Enabled bitmask */
-  assert(attrib_array->Enabled);
-  /* We have already masked with vao->VertexAttribBufferMask  */
-  assert(_mesa_is_bufferobj(buffer_binding->BufferObj));
-
-  /* Bail out once we find the first disallowed mapping */
-  if (_mesa_check_disallowed_mapping(buffer_binding->BufferObj))
- return false;
-
-  /* We have handled everything that is bound to this buffer_binding. */
-  mask &= ~buffer_binding->_BoundArrays;
-   }
-
-   return true;
-}
-
-
-/**
  * Check that element 'j' of the array has reasonable data.
  * Map VBO if needed.
  * For debugging purposes; not normally used.
@@ -430,7 +396,7 @@ vbo_bind_arrays(struct gl_context *ctx)
   }
}
 
-   if (!check_input_buffers_are_unmapped(ctx->Array.VAO)) {
+   if (!_mesa_all_buffers_are_unmapped(ctx->Array.VAO)) {
   _mesa_error(ctx, GL_INVALID_OPERATION,
   "draw call (vertex buffers are mapped)");
   return false;
-- 
2.7.4

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


[Mesa-dev] [PATCH] vbo: Correctly handle attribute offsets in dlist draw.

2016-08-18 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi,

I found the below while fixing a similar problem lately in
the immediate mode glBegin/glEnd code path.

Please review
Thanks

Mathias



When executing a display list draw with a shader program
using the generic0 attribute the offset computation
may get out of sync. To fix precompute the offsets
on the full attribute list and store the offsets in
the display list node.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/vbo/vbo_save.h  |  1 +
 src/mesa/vbo/vbo_save_api.c  |  6 ++
 src/mesa/vbo/vbo_save_draw.c | 35 +--
 3 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/src/mesa/vbo/vbo_save.h b/src/mesa/vbo/vbo_save.h
index 2843b3c..a61973f 100644
--- a/src/mesa/vbo/vbo_save.h
+++ b/src/mesa/vbo/vbo_save.h
@@ -64,6 +64,7 @@ struct vbo_save_vertex_list {
GLbitfield64 enabled; /**< mask of enabled vbo arrays. */
GLubyte attrsz[VBO_ATTRIB_MAX];
GLenum attrtype[VBO_ATTRIB_MAX];
+   GLushort offsets[VBO_ATTRIB_MAX];
GLuint vertex_size;  /**< size in GLfloats */
 
/* Copy of the final vertex from node->vertex_store->bufferobj.
diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index f648ccc..4473fef 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -436,6 +436,12 @@ _save_compile_vertex_list(struct gl_context *ctx)
node->vertex_size = save->vertex_size;
node->buffer_offset =
   (save->buffer - save->vertex_store->buffer) * sizeof(GLfloat);
+   GLushort offset = 0;
+   int i;
+   for (i = 0; i < VBO_ATTRIB_MAX; ++i) {
+  node->offsets[i] = offset;
+  offset += node->attrsz[i] * sizeof(GLfloat);
+   }
node->count = save->vert_count;
node->wrap_count = save->copied.nr;
node->dangling_attr_ref = save->dangling_attr_ref;
diff --git a/src/mesa/vbo/vbo_save_draw.c b/src/mesa/vbo/vbo_save_draw.c
index 507ab82..e69c108 100644
--- a/src/mesa/vbo/vbo_save_draw.c
+++ b/src/mesa/vbo/vbo_save_draw.c
@@ -26,6 +26,7 @@
  *Keith Whitwell 
  */
 
+#include 
 #include "main/glheader.h"
 #include "main/bufferobj.h"
 #include "main/context.h"
@@ -136,15 +137,10 @@ static void vbo_bind_vertex_list(struct gl_context *ctx,
struct vbo_context *vbo = vbo_context(ctx);
struct vbo_save_context *save = &vbo->save;
struct gl_client_array *arrays = save->arrays;
-   GLuint buffer_offset = node->buffer_offset;
const GLuint *map;
GLuint attr;
-   GLubyte node_attrsz[VBO_ATTRIB_MAX];  /* copy of node->attrsz[] */
-   GLenum node_attrtype[VBO_ATTRIB_MAX];  /* copy of node->attrtype[] */
GLbitfield64 varying_inputs = 0x0;
-
-   memcpy(node_attrsz, node->attrsz, sizeof(node->attrsz));
-   memcpy(node_attrtype, node->attrtype, sizeof(node->attrtype));
+   bool generic_from_pos = false;
 
/* Install the default (ie Current) attributes first, then overlay
 * all active ones.
@@ -176,10 +172,7 @@ static void vbo_bind_vertex_list(struct gl_context *ctx,
*/
   if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 &&
   (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) {
- save->inputs[VERT_ATTRIB_GENERIC0] = save->inputs[0];
- node_attrsz[VERT_ATTRIB_GENERIC0] = node_attrsz[0];
- node_attrtype[VERT_ATTRIB_GENERIC0] = node_attrtype[0];
- node_attrsz[0] = 0;
+ generic_from_pos = true;
   }
   break;
default:
@@ -188,30 +181,36 @@ static void vbo_bind_vertex_list(struct gl_context *ctx,
 
for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
   const GLuint src = map[attr];
+  const GLubyte size = node->attrsz[src];
 
-  if (node_attrsz[src]) {
+  if (size) {
  /* override the default array set above */
  save->inputs[attr] = &arrays[attr];
 
-arrays[attr].Ptr = (const GLubyte *) NULL + buffer_offset;
-arrays[attr].Size = node_attrsz[src];
+ const uintptr_t buffer_offset = node->buffer_offset;
+ arrays[attr].Ptr = ADD_POINTERS(buffer_offset, node->offsets[src]);
+ arrays[attr].Size = size;
 arrays[attr].StrideB = node->vertex_size * sizeof(GLfloat);
- arrays[attr].Type = node_attrtype[src];
- arrays[attr].Integer =
-   vbo_attrtype_to_integer_flag(node_attrtype[src]);
+ const GLenum type = node->attrtype[src];
+ arrays[attr].Type = type;
+ arrays[attr].Integer = vbo_attrtype_to_integer_flag(type);
  arrays[attr].Format = GL_RGBA;
- arrays[attr]._ElementSize = arrays[attr].Size * sizeof(GLfloat);
+ arrays[attr]._ElementSize = size * sizeof(GLfloat);
  _mesa_reference_buffer_object(ctx,
&arrays[attr].BufferObj,
node->vertex_store->bufferobj);
 
 assert(arrays[attr].BufferObj->Name);
 
-buffer_offset += node_attrsz[src] * sizeof(GLfloat);
  varying_inputs |= VERT_BIT(attr);

[Mesa-dev] [PATCH] vbo: Correctly handle attribute offsets in dlist draw.

2016-08-23 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi all,

kind of a ping with a rephrased commit message
and the style change.
Please review.

Thanks!

Mathias


When executing a display list draw, for the offset
list to be correct, the offset computation needs to
accumulate all attribute size values in order.
Specifically, if we are shuffling around the position
and generic0 attributes, we may violate the order or
if we do not walk the generic vbo attributes we may
skip some of the attributes.
Even if this is an unlikely usecase we can fix this
by precomputing the offsets on the full attribute list
and store the full offset list in the display list node.

v2: Formatting fix

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/vbo/vbo_save.h  |  1 +
 src/mesa/vbo/vbo_save_api.c  |  5 +
 src/mesa/vbo/vbo_save_draw.c | 35 +--
 3 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/src/mesa/vbo/vbo_save.h b/src/mesa/vbo/vbo_save.h
index 2843b3c..a61973f 100644
--- a/src/mesa/vbo/vbo_save.h
+++ b/src/mesa/vbo/vbo_save.h
@@ -64,6 +64,7 @@ struct vbo_save_vertex_list {
GLbitfield64 enabled; /**< mask of enabled vbo arrays. */
GLubyte attrsz[VBO_ATTRIB_MAX];
GLenum attrtype[VBO_ATTRIB_MAX];
+   GLushort offsets[VBO_ATTRIB_MAX];
GLuint vertex_size;  /**< size in GLfloats */
 
/* Copy of the final vertex from node->vertex_store->bufferobj.
diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index f648ccc..36af426 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -415,6 +415,7 @@ _save_compile_vertex_list(struct gl_context *ctx)
 {
struct vbo_save_context *save = &vbo_context(ctx)->save;
struct vbo_save_vertex_list *node;
+   GLushort offset = 0;
 
/* Allocate space for this structure in the display list currently
 * being compiled.
@@ -436,6 +437,10 @@ _save_compile_vertex_list(struct gl_context *ctx)
node->vertex_size = save->vertex_size;
node->buffer_offset =
   (save->buffer - save->vertex_store->buffer) * sizeof(GLfloat);
+   for (unsigned i = 0; i < VBO_ATTRIB_MAX; ++i) {
+  node->offsets[i] = offset;
+  offset += node->attrsz[i] * sizeof(GLfloat);
+   }
node->count = save->vert_count;
node->wrap_count = save->copied.nr;
node->dangling_attr_ref = save->dangling_attr_ref;
diff --git a/src/mesa/vbo/vbo_save_draw.c b/src/mesa/vbo/vbo_save_draw.c
index 507ab82..e69c108 100644
--- a/src/mesa/vbo/vbo_save_draw.c
+++ b/src/mesa/vbo/vbo_save_draw.c
@@ -26,6 +26,7 @@
  *Keith Whitwell 
  */
 
+#include 
 #include "main/glheader.h"
 #include "main/bufferobj.h"
 #include "main/context.h"
@@ -136,15 +137,10 @@ static void vbo_bind_vertex_list(struct gl_context *ctx,
struct vbo_context *vbo = vbo_context(ctx);
struct vbo_save_context *save = &vbo->save;
struct gl_client_array *arrays = save->arrays;
-   GLuint buffer_offset = node->buffer_offset;
const GLuint *map;
GLuint attr;
-   GLubyte node_attrsz[VBO_ATTRIB_MAX];  /* copy of node->attrsz[] */
-   GLenum node_attrtype[VBO_ATTRIB_MAX];  /* copy of node->attrtype[] */
GLbitfield64 varying_inputs = 0x0;
-
-   memcpy(node_attrsz, node->attrsz, sizeof(node->attrsz));
-   memcpy(node_attrtype, node->attrtype, sizeof(node->attrtype));
+   bool generic_from_pos = false;
 
/* Install the default (ie Current) attributes first, then overlay
 * all active ones.
@@ -176,10 +172,7 @@ static void vbo_bind_vertex_list(struct gl_context *ctx,
*/
   if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 &&
   (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) {
- save->inputs[VERT_ATTRIB_GENERIC0] = save->inputs[0];
- node_attrsz[VERT_ATTRIB_GENERIC0] = node_attrsz[0];
- node_attrtype[VERT_ATTRIB_GENERIC0] = node_attrtype[0];
- node_attrsz[0] = 0;
+ generic_from_pos = true;
   }
   break;
default:
@@ -188,30 +181,36 @@ static void vbo_bind_vertex_list(struct gl_context *ctx,
 
for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
   const GLuint src = map[attr];
+  const GLubyte size = node->attrsz[src];
 
-  if (node_attrsz[src]) {
+  if (size) {
  /* override the default array set above */
  save->inputs[attr] = &arrays[attr];
 
-arrays[attr].Ptr = (const GLubyte *) NULL + buffer_offset;
-arrays[attr].Size = node_attrsz[src];
+ const uintptr_t buffer_offset = node->buffer_offset;
+ arrays[attr].Ptr = ADD_POINTERS(buffer_offset, node->offsets[src]);
+ arrays[attr].Size = size;
 arrays[attr].StrideB = node->vertex_size * sizeof(GLfloat);
- arrays[attr].Type = node_attrtype[src];
- arrays[attr].Integer =
-   vbo_attrtype_to_integer_flag(node_attrtype[src]);
+ const GLenum type = node->attrtype[src];
+ arrays[attr].Type = type;
+ arrays[attr].Integer = vbo_attrtype_to_integer_flag(type);

[Mesa-dev] [PATCH] osmesa: Export OSMesaCreateContextAttribs.

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

Hi,

Since the function is exported like any other
public api fucnntion and put in the header
as if you could link against it export it also
from shared objects.

Please review!
Thanks!

Mathias

---
 src/gallium/targets/osmesa/osmesa.def   | 1 +
 src/gallium/targets/osmesa/osmesa.mingw.def | 1 +
 src/gallium/targets/osmesa/osmesa.sym   | 1 +
 src/mesa/drivers/osmesa/osmesa.def  | 1 +
 4 files changed, 4 insertions(+)

diff --git a/src/gallium/targets/osmesa/osmesa.def 
b/src/gallium/targets/osmesa/osmesa.def
index e347463..f6d09b8 100644
--- a/src/gallium/targets/osmesa/osmesa.def
+++ b/src/gallium/targets/osmesa/osmesa.def
@@ -3,6 +3,7 @@ VERSION 4.1
 
 EXPORTS
OSMesaCreateContext
+   OSMesaCreateContextAttribs
OSMesaCreateContextExt
OSMesaDestroyContext
OSMesaMakeCurrent
diff --git a/src/gallium/targets/osmesa/osmesa.mingw.def 
b/src/gallium/targets/osmesa/osmesa.mingw.def
index 945201c..b77af60 100644
--- a/src/gallium/targets/osmesa/osmesa.mingw.def
+++ b/src/gallium/targets/osmesa/osmesa.mingw.def
@@ -1,5 +1,6 @@
 EXPORTS
OSMesaCreateContext = OSMesaCreateContext@8
+   OSMesaCreateContextAttribs = OSMesaCreateContextAttribs@8
OSMesaCreateContextExt = OSMesaCreateContextExt@20
OSMesaDestroyContext = OSMesaDestroyContext@4
OSMesaMakeCurrent = OSMesaMakeCurrent@20
diff --git a/src/gallium/targets/osmesa/osmesa.sym 
b/src/gallium/targets/osmesa/osmesa.sym
index d4b963d..59beab3 100644
--- a/src/gallium/targets/osmesa/osmesa.sym
+++ b/src/gallium/targets/osmesa/osmesa.sym
@@ -2,6 +2,7 @@
global:
OSMesaColorClamp;
OSMesaCreateContext;
+   OSMesaCreateContextAttribs;
OSMesaCreateContextExt;
OSMesaDestroyContext;
OSMesaGetColorBuffer;
diff --git a/src/mesa/drivers/osmesa/osmesa.def 
b/src/mesa/drivers/osmesa/osmesa.def
index 06afab7..f7dcd59 100644
--- a/src/mesa/drivers/osmesa/osmesa.def
+++ b/src/mesa/drivers/osmesa/osmesa.def
@@ -4,6 +4,7 @@ VERSION 4.1
 EXPORTS
OSMesaColorClamp
OSMesaCreateContext
+   OSMesaCreateContextAttribs
OSMesaCreateContextExt
OSMesaDestroyContext
OSMesaMakeCurrent
-- 
2.5.5

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


[Mesa-dev] [PATCH 03/11] mesa: Implement _mesa_all_varyings_in_vbos.

2016-07-26 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Implement the equivalent of vbo_all_varyings_in_vbos for
vertex array objects.

v2: Update comment.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/arrayobj.c | 35 +++
 src/mesa/main/arrayobj.h |  4 
 2 files changed, 39 insertions(+)

diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index 9c3451e..becf32f 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -359,6 +359,41 @@ _mesa_update_vao_client_arrays(struct gl_context *ctx,
 }
 
 
+bool
+_mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao)
+{
+   /* Walk those enabled arrays that have the default vbo attached */
+   GLbitfield64 mask = vao->_Enabled & ~vao->VertexAttribBufferMask;
+
+   while (mask) {
+  /* Do not use u_bit_scan64 as we can walk multiple
+   * attrib arrays at once
+   */
+  const int i = ffsll(mask) - 1;
+  const struct gl_vertex_attrib_array *attrib_array =
+ &vao->VertexAttrib[i];
+  const struct gl_vertex_buffer_binding *buffer_binding =
+ &vao->VertexBinding[attrib_array->VertexBinding];
+
+  /* Only enabled arrays shall appear in the _Enabled bitmask */
+  assert(attrib_array->Enabled);
+  /* We have already masked out vao->VertexAttribBufferMask  */
+  assert(!_mesa_is_bufferobj(buffer_binding->BufferObj));
+
+  /* Bail out once we find the first non vbo with a non zero stride */
+  if (buffer_binding->Stride != 0)
+ return false;
+
+  /* Note that we cannot use the xor variant since the _BoundArray mask
+   * may contain array attributes that are bound but not enabled.
+   */
+  mask &= ~buffer_binding->_BoundArrays;
+   }
+
+   return true;
+}
+
+
 /**/
 /* API Functions  */
 /**/
diff --git a/src/mesa/main/arrayobj.h b/src/mesa/main/arrayobj.h
index 6a4247f..d30c85c 100644
--- a/src/mesa/main/arrayobj.h
+++ b/src/mesa/main/arrayobj.h
@@ -81,6 +81,10 @@ extern void
 _mesa_update_vao_client_arrays(struct gl_context *ctx,
struct gl_vertex_array_object *vao);
 
+/* Returns true if all varying arrays reside in vbos */
+extern bool
+_mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao);
+
 /*
  * API functions
  */
-- 
2.5.5

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


[Mesa-dev] [PATCH] mesa: Copy bitmask of VBOs in the VAO on gl{Push, Pop}Attrib.

2016-08-04 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi all,

The below was found by inspection.
Please review.

Thanks

Mathias



On gl{Push,Pop}Attrib(GL_CLIENT_VERTEX_ARRAY_BIT) take
care that gl_vertex_array_object::VertexAttribBufferMask
matches the bound buffer object in the
gl_vertex_array_object::VertexBinding array.

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

diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index f859191..ff5f0f1 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -1489,6 +1489,8 @@ copy_array_object(struct gl_context *ctx,
 
/* _Enabled must be the same than on push */
dest->_Enabled = src->_Enabled;
+   /* The bitmask of bound VBOs needs to match the VertexBinding array */
+   dest->VertexAttribBufferMask = src->VertexAttribBufferMask;
dest->NewArrays = src->NewArrays;
 }
 
-- 
2.5.5

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


[Mesa-dev] [PATCH] util: Move _mesa_fsl/util_last_bit into util/bitscan.h

2016-08-04 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi Brian,

As requested with the initial creation of util/bitscan.h
now move other bitscan related functions into util.
Make use of win32 intrinsics for util_last_bit/fls if present.

Signed-off-by: Mathias Fröhlich 


Any testing especially on win32 is apprechiated.

Please review

Mathias


---
 src/compiler/glsl/glsl_to_nir.cpp |  2 +-
 src/gallium/auxiliary/util/u_math.h   | 64 --
 src/mesa/drivers/dri/i965/brw_cs.c|  2 +-
 src/mesa/drivers/dri/i965/brw_draw.c  | 10 +--
 src/mesa/drivers/dri/i965/brw_fs_nir.cpp  |  6 +-
 src/mesa/drivers/dri/i965/brw_program.c   |  2 +-
 src/mesa/drivers/dri/i965/brw_shader.cpp  |  2 +-
 src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp |  2 +-
 src/mesa/drivers/dri/i965/brw_wm_surface_state.c  |  2 +-
 src/mesa/main/imports.h   | 45 -
 src/mesa/program/prog_to_nir.c|  6 +-
 src/util/bitscan.h| 80 +++
 12 files changed, 97 insertions(+), 126 deletions(-)

diff --git a/src/compiler/glsl/glsl_to_nir.cpp 
b/src/compiler/glsl/glsl_to_nir.cpp
index 20302e3..d3cc5b4 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -146,7 +146,7 @@ glsl_to_nir(const struct gl_shader_program *shader_prog,
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 = _mesa_fls(sh->Program->SamplersUsed);
+   shader->info.num_textures = util_last_bit(sh->Program->SamplersUsed);
shader->info.num_ubos = sh->NumUniformBlocks;
shader->info.num_abos = shader_prog->NumAtomicBuffers;
shader->info.num_ssbos = sh->NumShaderStorageBlocks;
diff --git a/src/gallium/auxiliary/util/u_math.h 
b/src/gallium/auxiliary/util/u_math.h
index 1661e63..a923271 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -347,70 +347,6 @@ util_half_inf_sign(int16_t x)
 
 
 /**
- * Find last bit set in a word.  The least significant bit is 1.
- * Return 0 if no bits are set.
- */
-static inline unsigned
-util_last_bit(unsigned u)
-{
-#if defined(HAVE___BUILTIN_CLZ)
-   return u == 0 ? 0 : 32 - __builtin_clz(u);
-#else
-   unsigned r = 0;
-   while (u) {
-   r++;
-   u >>= 1;
-   }
-   return r;
-#endif
-}
-
-/**
- * Find last bit set in a word.  The least significant bit is 1.
- * Return 0 if no bits are set.
- */
-static inline unsigned
-util_last_bit64(uint64_t u)
-{
-#if defined(HAVE___BUILTIN_CLZLL)
-   return u == 0 ? 0 : 64 - __builtin_clzll(u);
-#else
-   unsigned r = 0;
-   while (u) {
-   r++;
-   u >>= 1;
-   }
-   return r;
-#endif
-}
-
-/**
- * Find last bit in a word that does not match the sign bit. The least
- * significant bit is 1.
- * Return 0 if no bits are set.
- */
-static inline unsigned
-util_last_bit_signed(int i)
-{
-   if (i >= 0)
-  return util_last_bit(i);
-   else
-  return util_last_bit(~(unsigned)i);
-}
-
-/* Returns a bitfield in which the first count bits starting at start are
- * set.
- */
-static inline unsigned
-u_bit_consecutive(unsigned start, unsigned count)
-{
-   assert(start + count <= 32);
-   if (count == 32)
-  return ~0;
-   return ((1u << count) - 1) << start;
-}
-
-/**
  * Return float bits.
  */
 static inline unsigned
diff --git a/src/mesa/drivers/dri/i965/brw_cs.c 
b/src/mesa/drivers/dri/i965/brw_cs.c
index 655adc1..6685acd 100644
--- a/src/mesa/drivers/dri/i965/brw_cs.c
+++ b/src/mesa/drivers/dri/i965/brw_cs.c
@@ -220,7 +220,7 @@ brw_upload_cs_prog(struct brw_context *brw)
   return;
 
brw->cs.base.sampler_count =
-  _mesa_fls(ctx->ComputeProgram._Current->Base.SamplersUsed);
+  util_last_bit(ctx->ComputeProgram._Current->Base.SamplersUsed);
 
brw_cs_populate_key(brw, &key);
 
diff --git a/src/mesa/drivers/dri/i965/brw_draw.c 
b/src/mesa/drivers/dri/i965/brw_draw.c
index d7a1ba3..9b1e18c 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -452,15 +452,15 @@ brw_try_draw_prims(struct gl_context *ctx,
 * index.
 */
brw->wm.base.sampler_count =
-  _mesa_fls(ctx->FragmentProgram._Current->Base.SamplersUsed);
+  util_last_bit(ctx->FragmentProgram._Current->Base.SamplersUsed);
brw->gs.base.sampler_count = ctx->GeometryProgram._Current ?
-  _mesa_fls(ctx->GeometryProgram._Current->Base.SamplersUsed) : 0;
+  util_last_bit(ctx->GeometryProgram._Current->Base.SamplersUsed) : 0;
brw->tes.base.sampler_count = ctx->TessEvalProgram._Current ?
-  _mesa_fls(ctx->TessEvalProgram._Current->Base.SamplersUsed) : 0;
+  util_last_bit(ctx->TessEvalProgram._Current->Base.SamplersUsed) : 0;
brw->tcs.base.sampler_count = ctx->TessCtrlProgram._Current ?
-  _mesa_fls(ctx->TessCtrlProgram._Current->Base

[Mesa-dev] [PATCH 1/3] util: Move _mesa_fsl/util_last_bit into util/bitscan.h v2

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

Following the split up patch as a series and on top
the include fix to u_bitscan.h.

Please review!
Thanks!

Mathias




As requested with the initial creation of util/bitscan.h
now move other bitscan related functions into util.

v2: Split into two patches.

Signed-off-by: Mathias Fröhlich 
---
 src/compiler/glsl/glsl_to_nir.cpp |  2 +-
 src/gallium/auxiliary/util/u_math.h   | 64 -
 src/mesa/drivers/dri/i965/brw_cs.c|  2 +-
 src/mesa/drivers/dri/i965/brw_draw.c  | 10 ++--
 src/mesa/drivers/dri/i965/brw_fs_nir.cpp  |  6 +-
 src/mesa/drivers/dri/i965/brw_program.c   |  2 +-
 src/mesa/drivers/dri/i965/brw_shader.cpp  |  2 +-
 src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp |  2 +-
 src/mesa/drivers/dri/i965/brw_wm_surface_state.c  |  2 +-
 src/mesa/main/imports.h   | 45 ---
 src/mesa/program/prog_to_nir.c|  6 +-
 src/util/bitscan.h| 68 +++
 12 files changed, 85 insertions(+), 126 deletions(-)

diff --git a/src/compiler/glsl/glsl_to_nir.cpp 
b/src/compiler/glsl/glsl_to_nir.cpp
index 20302e3..d3cc5b4 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -146,7 +146,7 @@ glsl_to_nir(const struct gl_shader_program *shader_prog,
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 = _mesa_fls(sh->Program->SamplersUsed);
+   shader->info.num_textures = util_last_bit(sh->Program->SamplersUsed);
shader->info.num_ubos = sh->NumUniformBlocks;
shader->info.num_abos = shader_prog->NumAtomicBuffers;
shader->info.num_ssbos = sh->NumShaderStorageBlocks;
diff --git a/src/gallium/auxiliary/util/u_math.h 
b/src/gallium/auxiliary/util/u_math.h
index 1661e63..a923271 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -347,70 +347,6 @@ util_half_inf_sign(int16_t x)
 
 
 /**
- * Find last bit set in a word.  The least significant bit is 1.
- * Return 0 if no bits are set.
- */
-static inline unsigned
-util_last_bit(unsigned u)
-{
-#if defined(HAVE___BUILTIN_CLZ)
-   return u == 0 ? 0 : 32 - __builtin_clz(u);
-#else
-   unsigned r = 0;
-   while (u) {
-   r++;
-   u >>= 1;
-   }
-   return r;
-#endif
-}
-
-/**
- * Find last bit set in a word.  The least significant bit is 1.
- * Return 0 if no bits are set.
- */
-static inline unsigned
-util_last_bit64(uint64_t u)
-{
-#if defined(HAVE___BUILTIN_CLZLL)
-   return u == 0 ? 0 : 64 - __builtin_clzll(u);
-#else
-   unsigned r = 0;
-   while (u) {
-   r++;
-   u >>= 1;
-   }
-   return r;
-#endif
-}
-
-/**
- * Find last bit in a word that does not match the sign bit. The least
- * significant bit is 1.
- * Return 0 if no bits are set.
- */
-static inline unsigned
-util_last_bit_signed(int i)
-{
-   if (i >= 0)
-  return util_last_bit(i);
-   else
-  return util_last_bit(~(unsigned)i);
-}
-
-/* Returns a bitfield in which the first count bits starting at start are
- * set.
- */
-static inline unsigned
-u_bit_consecutive(unsigned start, unsigned count)
-{
-   assert(start + count <= 32);
-   if (count == 32)
-  return ~0;
-   return ((1u << count) - 1) << start;
-}
-
-/**
  * Return float bits.
  */
 static inline unsigned
diff --git a/src/mesa/drivers/dri/i965/brw_cs.c 
b/src/mesa/drivers/dri/i965/brw_cs.c
index 655adc1..6685acd 100644
--- a/src/mesa/drivers/dri/i965/brw_cs.c
+++ b/src/mesa/drivers/dri/i965/brw_cs.c
@@ -220,7 +220,7 @@ brw_upload_cs_prog(struct brw_context *brw)
   return;
 
brw->cs.base.sampler_count =
-  _mesa_fls(ctx->ComputeProgram._Current->Base.SamplersUsed);
+  util_last_bit(ctx->ComputeProgram._Current->Base.SamplersUsed);
 
brw_cs_populate_key(brw, &key);
 
diff --git a/src/mesa/drivers/dri/i965/brw_draw.c 
b/src/mesa/drivers/dri/i965/brw_draw.c
index d7a1ba3..9b1e18c 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -452,15 +452,15 @@ brw_try_draw_prims(struct gl_context *ctx,
 * index.
 */
brw->wm.base.sampler_count =
-  _mesa_fls(ctx->FragmentProgram._Current->Base.SamplersUsed);
+  util_last_bit(ctx->FragmentProgram._Current->Base.SamplersUsed);
brw->gs.base.sampler_count = ctx->GeometryProgram._Current ?
-  _mesa_fls(ctx->GeometryProgram._Current->Base.SamplersUsed) : 0;
+  util_last_bit(ctx->GeometryProgram._Current->Base.SamplersUsed) : 0;
brw->tes.base.sampler_count = ctx->TessEvalProgram._Current ?
-  _mesa_fls(ctx->TessEvalProgram._Current->Base.SamplersUsed) : 0;
+  util_last_bit(ctx->TessEvalProgram._Current->Base.SamplersUsed) : 0;
brw->tcs.base.sampler_count = ctx->TessCtrlProgram._Current ?
-  _mesa_fls(ctx->TessCtrlProgram._Current-

[Mesa-dev] [PATCH 2/3] util: Use win32 intrinsics for util_last_bit if present.

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

v2: Split into two patches.

Signed-off-by: Mathias Fröhlich 
---
 src/util/bitscan.h | 12 
 1 file changed, 12 insertions(+)

diff --git a/src/util/bitscan.h b/src/util/bitscan.h
index 0743fe7..a5bb34e 100644
--- a/src/util/bitscan.h
+++ b/src/util/bitscan.h
@@ -157,6 +157,12 @@ util_last_bit(unsigned u)
 {
 #if defined(HAVE___BUILTIN_CLZ)
return u == 0 ? 0 : 32 - __builtin_clz(u);
+#elif defined(_MSC_VER) && (_M_IX86 || _M_ARM || _M_AMD64 || _M_IA64)
+   unsigned long index;
+   if (_BitScanReverse(&index, u))
+  return index;
+   else
+  return 0;
 #else
unsigned r = 0;
while (u) {
@@ -177,6 +183,12 @@ util_last_bit64(uint64_t u)
 {
 #if defined(HAVE___BUILTIN_CLZLL)
return u == 0 ? 0 : 64 - __builtin_clzll(u);
+#elif defined(_MSC_VER) && (_M_AMD64 || _M_ARM || _M_IA64)
+   unsigned long index;
+   if (_BitScanReverse64(&index, u))
+  return index;
+   else
+  return 0;
 #else
unsigned r = 0;
while (u) {
-- 
2.5.5

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


[Mesa-dev] [PATCH 3/3] gallium: Add c99_compat.h to u_bitcast.h

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

We need this for 'inline'.

Signed-off-by: Mathias Fröhlich 
---
 src/gallium/auxiliary/util/u_bitcast.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_bitcast.h 
b/src/gallium/auxiliary/util/u_bitcast.h
index b1f9938..e8fb0fe 100644
--- a/src/gallium/auxiliary/util/u_bitcast.h
+++ b/src/gallium/auxiliary/util/u_bitcast.h
@@ -30,6 +30,8 @@
 
 #include 
 
+#include "c99_compat.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
-- 
2.5.5

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


[Mesa-dev] [PATCH] st/mesa: Reduce array updates due to current changes.

2019-02-23 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi Brian,

Following a small optimization in the gallium state tracker to
avoid flagging ST_NEW_VERTEX_ARRAYS a bit more often:

please review!

best

Mathias




Since using bitmasks we can easily check if we have any
current value that is potentially uploaded on array setup.
So check for any potential vertex program input that is not
already a vao enabled array. Only flag array update if there is
a potential overlap.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/state_tracker/st_context.c | 2 +-
 src/mesa/state_tracker/st_context.h | 9 +
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/mesa/state_tracker/st_context.c 
b/src/mesa/state_tracker/st_context.c
index 0a0bd8ba1ca..45451531df9 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -224,7 +224,7 @@ st_invalidate_state(struct gl_context *ctx)
if (new_state & _NEW_PIXEL)
   st->dirty |= ST_NEW_PIXEL_TRANSFER;
 
-   if (new_state & _NEW_CURRENT_ATTRIB)
+   if (new_state & _NEW_CURRENT_ATTRIB && st_vp_uses_current_values(ctx))
   st->dirty |= ST_NEW_VERTEX_ARRAYS;
 
/* Update the vertex shader if ctx->Light._ClampVertexColor was changed. */
diff --git a/src/mesa/state_tracker/st_context.h 
b/src/mesa/state_tracker/st_context.h
index ed69e3d4873..324a7f24178 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -28,6 +28,7 @@
 #ifndef ST_CONTEXT_H
 #define ST_CONTEXT_H
 
+#include "main/arrayobj.h"
 #include "main/mtypes.h"
 #include "state_tracker/st_api.h"
 #include "main/fbobject.h"
@@ -398,6 +399,14 @@ st_user_clip_planes_enabled(struct gl_context *ctx)
   ctx->Transform.ClipPlanesEnabled;
 }
 
+
+static inline bool
+st_vp_uses_current_values(const struct gl_context *ctx)
+{
+   const uint64_t inputs = ctx->VertexProgram._Current->info.inputs_read;
+   return _mesa_draw_current_bits(ctx) & inputs;
+}
+
 /** clear-alloc a struct-sized object, with casting */
 #define ST_CALLOC_STRUCT(T)   (struct T *) calloc(1, sizeof(struct T))
 
-- 
2.20.1

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

[Mesa-dev] [PATCH 2/2] st/mesa: Invalidate the gallium array atom only if needed.

2019-02-28 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Now that the buffer object usage history tracks if it is
being used as vertex buffer object, we can restrict setting
the ST_NEW_VERTEX_ARRAYS bit to dirty on glBufferData calls to
buffers that are potentially used as vertex buffer object.
Also put a note that the same could be done for index arrays
used in indexed draws.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/state_tracker/st_cb_bufferobjects.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c 
b/src/mesa/state_tracker/st_cb_bufferobjects.c
index 5ebe94f4545..b05f2516980 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -357,8 +357,10 @@ bufferobj_data(struct gl_context *ctx,
/* The current buffer may be bound, so we have to revalidate all atoms that
 * might be using it.
 */
-   /* TODO: Add arrays to usage history */
-   ctx->NewDriverState |= ST_NEW_VERTEX_ARRAYS;
+   if (st_obj->Base.UsageHistory & USAGE_ARRAY_BUFFER)
+  ctx->NewDriverState |= ST_NEW_VERTEX_ARRAYS;
+   /* if (st_obj->Base.UsageHistory & USAGE_ELEMENT_ARRAY_BUFFER) */
+   /*ctx->NewDriverState |= TODO: Handle indices as gallium state; */
if (st_obj->Base.UsageHistory & USAGE_UNIFORM_BUFFER)
   ctx->NewDriverState |= ST_NEW_UNIFORM_BUFFER;
if (st_obj->Base.UsageHistory & USAGE_SHADER_STORAGE_BUFFER)
-- 
2.20.1

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

[Mesa-dev] [PATCH 1/2] mesa: Track buffer object use also for VAO usage.

2019-02-28 Thread Mathias . Froehlich
From: Mathias Fröhlich 

We already track the usage history for buffer objects
in a lot of aspects. Add GL_ARRAY_BUFFER and
GL_ELEMENT_ARRAY_BUFFER to gl_buffer_object::UsageHistory.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/arrayobj.c  | 4 +++-
 src/mesa/main/bufferobj.c | 5 +
 src/mesa/main/mtypes.h| 4 +++-
 src/mesa/main/varray.c| 6 --
 4 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index bfd6fce6798..68d30aa9b1f 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -1213,8 +1213,10 @@ vertex_array_element_buffer(struct gl_context *ctx, 
GLuint vaobj, GLuint buffer,
   bufObj = ctx->Shared->NullBufferObj;
}
 
-   if (bufObj)
+   if (bufObj) {
+  bufObj->UsageHistory |= USAGE_ELEMENT_ARRAY_BUFFER;
   _mesa_reference_buffer_object(ctx, &vao->IndexBufferObj, bufObj);
+   }
 }
 
 
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index f9e52942d47..3caf363b37f 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -113,8 +113,13 @@ get_buffer_target(struct gl_context *ctx, GLenum target)
 
switch (target) {
case GL_ARRAY_BUFFER_ARB:
+  if (ctx->Array.ArrayBufferObj)
+ ctx->Array.ArrayBufferObj->UsageHistory |= USAGE_ARRAY_BUFFER;
   return &ctx->Array.ArrayBufferObj;
case GL_ELEMENT_ARRAY_BUFFER_ARB:
+  if (ctx->Array.VAO->IndexBufferObj)
+ ctx->Array.VAO->IndexBufferObj->UsageHistory
+|= USAGE_ELEMENT_ARRAY_BUFFER;
   return &ctx->Array.VAO->IndexBufferObj;
case GL_PIXEL_PACK_BUFFER_EXT:
   return &ctx->Pack.BufferObj;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 9bca5c153ad..96f30d4a4d5 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1339,7 +1339,9 @@ typedef enum
USAGE_SHADER_STORAGE_BUFFER = 0x8,
USAGE_TRANSFORM_FEEDBACK_BUFFER = 0x10,
USAGE_PIXEL_PACK_BUFFER = 0x20,
-   USAGE_DISABLE_MINMAX_CACHE = 0x40,
+   USAGE_ARRAY_BUFFER = 0x40,
+   USAGE_ELEMENT_ARRAY_BUFFER = 0x80,
+   USAGE_DISABLE_MINMAX_CACHE = 0x100,
 } gl_buffer_usage;
 
 
diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c
index 5af5a7f773f..e6057c7f881 100644
--- a/src/mesa/main/varray.c
+++ b/src/mesa/main/varray.c
@@ -209,10 +209,12 @@ _mesa_bind_vertex_buffer(struct gl_context *ctx,
   binding->Offset = offset;
   binding->Stride = stride;
 
-  if (!_mesa_is_bufferobj(vbo))
+  if (!_mesa_is_bufferobj(vbo)) {
  vao->VertexAttribBufferMask &= ~binding->_BoundArrays;
-  else
+  } else {
  vao->VertexAttribBufferMask |= binding->_BoundArrays;
+ vbo->UsageHistory |= USAGE_ARRAY_BUFFER;
+  }
 
   vao->NewArrays |= vao->Enabled & binding->_BoundArrays;
   if (vao == ctx->Array.VAO)
-- 
2.20.1

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

[Mesa-dev] [PATCH 0/2] Track vertex buffer usage for buffer objects.

2019-02-28 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi Brian,

I have an other VAO optimization aspect for review.
Currently gallium just invalidates the array state on every
glBufferData type call. The change adds buffer object
usage tracking for vertex buffer objects and avoids invalidating
array state on for example uniform buffer object data uploads.

The change does not introduce piglit regressions on radeonsi.

Please review

thanks
Mathias


Mathias Fröhlich (2):
  mesa: Track buffer object use also for VAO usage.
  st/mesa: Invalidate the gallium array atom only if needed.

 src/mesa/main/arrayobj.c | 4 +++-
 src/mesa/main/bufferobj.c| 5 +
 src/mesa/main/mtypes.h   | 4 +++-
 src/mesa/main/varray.c   | 6 --
 src/mesa/state_tracker/st_cb_bufferobjects.c | 6 --
 5 files changed, 19 insertions(+), 6 deletions(-)

-- 
2.20.1

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

[Mesa-dev] [PATCH 3/8] mesa: Use _mesa_array_element in dlist save.

2019-03-05 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Make use of the newly factored out _mesa_array_element function
in display list compilation. For now that duplicates out the
primitive restart logic. But that turns out to need a fix in
display list handling anyhow.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/vbo/vbo_save_api.c | 23 +++
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index fb8d68d5560..6122727bae9 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -1330,7 +1330,7 @@ _save_OBE_DrawArrays(GLenum mode, GLint start, GLsizei 
count)
vbo_save_NotifyBegin(ctx, mode, true);
 
for (i = 0; i < count; i++)
-  CALL_ArrayElement(GET_DISPATCH(), (start + i));
+  _mesa_array_element(ctx, GET_DISPATCH(), start + i);
CALL_End(GET_DISPATCH(), ());
 
_ae_unmap_vbos(ctx);
@@ -1371,6 +1371,21 @@ _save_OBE_MultiDrawArrays(GLenum mode, const GLint 
*first,
 }
 
 
+static void
+array_element(struct gl_context *ctx, struct _glapi_table *disp, GLuint elt)
+{
+   /* If PrimitiveRestart is enabled and the index is the RestartIndex
+* then we call PrimitiveRestartNV and return.
+*/
+   if (ctx->Array.PrimitiveRestart && elt == ctx->Array.RestartIndex) {
+  CALL_PrimitiveRestartNV(disp, ());
+  return;
+   }
+
+   _mesa_array_element(ctx, disp, elt);
+}
+
+
 /* Could do better by copying the arrays and element list intact and
  * then emitting an indexed prim at runtime.
  */
@@ -1415,15 +1430,15 @@ _save_OBE_DrawElementsBaseVertex(GLenum mode, GLsizei 
count, GLenum type,
switch (type) {
case GL_UNSIGNED_BYTE:
   for (i = 0; i < count; i++)
- CALL_ArrayElement(GET_DISPATCH(), (basevertex + ((GLubyte *) 
indices)[i]));
+ array_element(ctx, GET_DISPATCH(), (basevertex + ((GLubyte *) 
indices)[i]));
   break;
case GL_UNSIGNED_SHORT:
   for (i = 0; i < count; i++)
- CALL_ArrayElement(GET_DISPATCH(), (basevertex + ((GLushort *) 
indices)[i]));
+ array_element(ctx, GET_DISPATCH(), (basevertex + ((GLushort *) 
indices)[i]));
   break;
case GL_UNSIGNED_INT:
   for (i = 0; i < count; i++)
- CALL_ArrayElement(GET_DISPATCH(), (basevertex + ((GLuint *) 
indices)[i]));
+ array_element(ctx, GET_DISPATCH(), (basevertex + ((GLuint *) 
indices)[i]));
   break;
default:
   _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)");
-- 
2.20.1

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

[Mesa-dev] [PATCH 8/8] vbo: Fix GL_PRIMITIVE_RESTART_FIXED_INDEX in display list compiles.

2019-03-05 Thread Mathias . Froehlich
From: Mathias Fröhlich 

The maximum value primitive restart index is different for each index data
type. Use the appropriate fixed restart index value.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/vbo/vbo_save_api.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index 7f8c06b630c..de0be4e3324 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -1374,7 +1374,7 @@ _save_OBE_MultiDrawArrays(GLenum mode, const GLint *first,
 
 static void
 array_element(struct gl_context *ctx, struct _glapi_table *disp,
-  GLint basevertex, GLuint elt)
+  GLint basevertex, GLuint elt, unsigned index_size)
 {
/* Section 10.3.5 Primitive Restart:
 * [...]
@@ -1385,7 +1385,8 @@ array_element(struct gl_context *ctx, struct _glapi_table 
*disp,
/* If PrimitiveRestart is enabled and the index is the RestartIndex
 * then we call PrimitiveRestartNV and return.
 */
-   if (ctx->Array.PrimitiveRestart && elt == ctx->Array.RestartIndex) {
+   if (ctx->Array._PrimitiveRestart &&
+   elt == _mesa_primitive_restart_index(ctx, index_size)) {
   CALL_PrimitiveRestartNV(disp, ());
   return;
}
@@ -1439,15 +1440,18 @@ _save_OBE_DrawElementsBaseVertex(GLenum mode, GLsizei 
count, GLenum type,
switch (type) {
case GL_UNSIGNED_BYTE:
   for (i = 0; i < count; i++)
- array_element(ctx, GET_DISPATCH(), basevertex, ((GLubyte *) 
indices)[i]);
+ array_element(ctx, GET_DISPATCH(), basevertex,
+   ((GLubyte *) indices)[i], 1);
   break;
case GL_UNSIGNED_SHORT:
   for (i = 0; i < count; i++)
- array_element(ctx, GET_DISPATCH(), basevertex, ((GLushort *) 
indices)[i]);
+ array_element(ctx, GET_DISPATCH(), basevertex,
+   ((GLushort *) indices)[i], 2);
   break;
case GL_UNSIGNED_INT:
   for (i = 0; i < count; i++)
- array_element(ctx, GET_DISPATCH(), basevertex, ((GLuint *) 
indices)[i]);
+ array_element(ctx, GET_DISPATCH(), basevertex,
+   ((GLuint *) indices)[i], 4);
   break;
default:
   _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)");
-- 
2.20.1

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

[Mesa-dev] [PATCH 4/8] mesa: Replace _ae_{, un}map_vbos with _mesa_vao_{, un}map_arrays

2019-03-05 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Due to the use of bitmaps, the _mesa_vao_{,un}map_arrays functions
should provide comparable runtime efficienty to the currently used
_ae_{,un}map_vbos functions. So use this functions and enable
further cleanup.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/api_arrayelt.c | 12 
 src/mesa/vbo/vbo_save_api.c  | 12 +++-
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/mesa/main/api_arrayelt.c b/src/mesa/main/api_arrayelt.c
index cb0d2a28a6c..ea91fbcabf5 100644
--- a/src/mesa/main/api_arrayelt.c
+++ b/src/mesa/main/api_arrayelt.c
@@ -1792,7 +1792,7 @@ _ae_ArrayElement(GLint elt)
GET_CURRENT_CONTEXT(ctx);
const AEcontext *actx = AE_CONTEXT(ctx);
const struct _glapi_table * const disp = GET_DISPATCH();
-   GLboolean do_map;
+   struct gl_vertex_array_object *vao;
 
/* If PrimitiveRestart is enabled and the index is the RestartIndex
 * then we call PrimitiveRestartNV and return.
@@ -1807,16 +1807,12 @@ _ae_ArrayElement(GLint elt)
   _ae_update_state(ctx);
}
 
-   /* Determine if we need to map/unmap VBOs */
-   do_map = actx->nr_vbos && !actx->mapped_vbos;
-
-   if (do_map)
-  _ae_map_vbos(ctx);
+   vao = ctx->Array.VAO;
+   _mesa_vao_map_arrays(ctx, vao, GL_MAP_READ_BIT);
 
_mesa_array_element(ctx, (struct _glapi_table *)disp, elt);
 
-   if (do_map)
-  _ae_unmap_vbos(ctx);
+   _mesa_vao_unmap_arrays(ctx, vao);
 }
 
 
diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index 6122727bae9..bb578694e00 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -1307,6 +1307,7 @@ static void GLAPIENTRY
 _save_OBE_DrawArrays(GLenum mode, GLint start, GLsizei count)
 {
GET_CURRENT_CONTEXT(ctx);
+   struct gl_vertex_array_object *vao = ctx->Array.VAO;
struct vbo_save_context *save = &vbo_context(ctx)->save;
GLint i;
 
@@ -1325,7 +1326,7 @@ _save_OBE_DrawArrays(GLenum mode, GLint start, GLsizei 
count)
/* Make sure to process any VBO binding changes */
_mesa_update_state(ctx);
 
-   _ae_map_vbos(ctx);
+   _mesa_vao_map_arrays(ctx, vao, GL_MAP_READ_BIT);
 
vbo_save_NotifyBegin(ctx, mode, true);
 
@@ -1333,7 +1334,7 @@ _save_OBE_DrawArrays(GLenum mode, GLint start, GLsizei 
count)
   _mesa_array_element(ctx, GET_DISPATCH(), start + i);
CALL_End(GET_DISPATCH(), ());
 
-   _ae_unmap_vbos(ctx);
+   _mesa_vao_unmap_arrays(ctx, vao);
 }
 
 
@@ -1395,7 +1396,8 @@ _save_OBE_DrawElementsBaseVertex(GLenum mode, GLsizei 
count, GLenum type,
 {
GET_CURRENT_CONTEXT(ctx);
struct vbo_save_context *save = &vbo_context(ctx)->save;
-   struct gl_buffer_object *indexbuf = ctx->Array.VAO->IndexBufferObj;
+   struct gl_vertex_array_object *vao = ctx->Array.VAO;
+   struct gl_buffer_object *indexbuf = vao->IndexBufferObj;
GLint i;
 
if (!_mesa_is_valid_prim_mode(ctx, mode)) {
@@ -1419,7 +1421,7 @@ _save_OBE_DrawElementsBaseVertex(GLenum mode, GLsizei 
count, GLenum type,
/* Make sure to process any VBO binding changes */
_mesa_update_state(ctx);
 
-   _ae_map_vbos(ctx);
+   _mesa_vao_map(ctx, vao, GL_MAP_READ_BIT);
 
if (_mesa_is_bufferobj(indexbuf))
   indices =
@@ -1447,7 +1449,7 @@ _save_OBE_DrawElementsBaseVertex(GLenum mode, GLsizei 
count, GLenum type,
 
CALL_End(GET_DISPATCH(), ());
 
-   _ae_unmap_vbos(ctx);
+   _mesa_vao_unmap(ctx, vao);
 }
 
 static void GLAPIENTRY
-- 
2.20.1

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

[Mesa-dev] [PATCH 2/8] mesa: Factor out _mesa_array_element.

2019-03-05 Thread Mathias . Froehlich
From: Mathias Fröhlich 

The factored out function handles emitting the vertex attributes
at the given index. The now public accessible function gets used
in the following patches.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/api_arrayelt.c | 49 ++--
 src/mesa/main/api_arrayelt.h |  2 ++
 2 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/src/mesa/main/api_arrayelt.c b/src/mesa/main/api_arrayelt.c
index 2b59c478d9e..cb0d2a28a6c 100644
--- a/src/mesa/main/api_arrayelt.c
+++ b/src/mesa/main/api_arrayelt.c
@@ -1751,6 +1751,35 @@ _ae_unmap_vbos(struct gl_context *ctx)
 }
 
 
+void
+_mesa_array_element(struct gl_context *ctx,
+struct _glapi_table *disp, GLint elt)
+{
+   const AEcontext *actx = AE_CONTEXT(ctx);
+
+   if (actx->dirty_state)
+  _ae_update_state(ctx);
+
+   /* emit generic attribute elements */
+   for (const AEattrib *at = actx->attribs; at->func; at++) {
+  const GLubyte *src
+ = ADD_POINTERS(at->binding->BufferObj->Mappings[MAP_INTERNAL].Pointer,
+_mesa_vertex_attrib_address(at->array, at->binding))
+ + elt * at->binding->Stride;
+  at->func(at->index, src);
+   }
+
+   /* emit conventional arrays elements */
+   for (const AEarray *aa = actx->arrays; aa->offset != -1 ; aa++) {
+  const GLubyte *src
+ = ADD_POINTERS(aa->binding->BufferObj->Mappings[MAP_INTERNAL].Pointer,
+_mesa_vertex_attrib_address(aa->array, aa->binding))
+ + elt * aa->binding->Stride;
+  CALL_by_offset(disp, (array_func), aa->offset, ((const void *) src));
+   }
+}
+
+
 /**
  * Called via glArrayElement() and glDrawArrays().
  * Issue the glNormal, glVertex, glColor, glVertexAttrib, etc functions
@@ -1762,8 +1791,6 @@ _ae_ArrayElement(GLint elt)
 {
GET_CURRENT_CONTEXT(ctx);
const AEcontext *actx = AE_CONTEXT(ctx);
-   const AEarray *aa;
-   const AEattrib *at;
const struct _glapi_table * const disp = GET_DISPATCH();
GLboolean do_map;
 
@@ -1786,23 +1813,7 @@ _ae_ArrayElement(GLint elt)
if (do_map)
   _ae_map_vbos(ctx);
 
-   /* emit generic attribute elements */
-   for (at = actx->attribs; at->func; at++) {
-  const GLubyte *src
- = ADD_POINTERS(at->binding->BufferObj->Mappings[MAP_INTERNAL].Pointer,
-_mesa_vertex_attrib_address(at->array, at->binding))
- + elt * at->binding->Stride;
-  at->func(at->index, src);
-   }
-
-   /* emit conventional arrays elements */
-   for (aa = actx->arrays; aa->offset != -1 ; aa++) {
-  const GLubyte *src
- = ADD_POINTERS(aa->binding->BufferObj->Mappings[MAP_INTERNAL].Pointer,
-_mesa_vertex_attrib_address(aa->array, aa->binding))
- + elt * aa->binding->Stride;
-  CALL_by_offset(disp, (array_func), aa->offset, ((const void *) src));
-   }
+   _mesa_array_element(ctx, (struct _glapi_table *)disp, elt);
 
if (do_map)
   _ae_unmap_vbos(ctx);
diff --git a/src/mesa/main/api_arrayelt.h b/src/mesa/main/api_arrayelt.h
index 6543a58f724..d0412806153 100644
--- a/src/mesa/main/api_arrayelt.h
+++ b/src/mesa/main/api_arrayelt.h
@@ -36,6 +36,8 @@ extern GLboolean _ae_create_context( struct gl_context *ctx );
 extern void _ae_destroy_context( struct gl_context *ctx );
 extern void _ae_invalidate_state(struct gl_context *ctx);
 extern bool _ae_is_state_dirty(struct gl_context *ctx);
+extern void _mesa_array_element(struct gl_context *ctx,
+struct _glapi_table *disp, GLint elt);
 extern void GLAPIENTRY _ae_ArrayElement( GLint elt );
 
 /* May optionally be called before a batch of element calls:
-- 
2.20.1

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

[Mesa-dev] [PATCH 6/8] mesa: Use mapping tools in debug prints.

2019-03-05 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/draw.c | 57 ++--
 1 file changed, 12 insertions(+), 45 deletions(-)

diff --git a/src/mesa/main/draw.c b/src/mesa/main/draw.c
index bfc4b9c9373..fa70463eaee 100644
--- a/src/mesa/main/draw.c
+++ b/src/mesa/main/draw.c
@@ -73,12 +73,6 @@ check_array_data(struct gl_context *ctx, struct 
gl_vertex_array_object *vao,
   struct gl_buffer_object *bo = binding->BufferObj;
   const void *data = array->Ptr;
   if (_mesa_is_bufferobj(bo)) {
- if (!bo->Mappings[MAP_INTERNAL].Pointer) {
-/* need to map now */
-bo->Mappings[MAP_INTERNAL].Pointer =
-   ctx->Driver.MapBufferRange(ctx, 0, bo->Size,
-  GL_MAP_READ_BIT, bo, MAP_INTERNAL);
- }
  data = ADD_POINTERS(_mesa_vertex_attrib_address(array, binding),
  bo->Mappings[MAP_INTERNAL].Pointer);
   }
@@ -110,25 +104,6 @@ check_array_data(struct gl_context *ctx, struct 
gl_vertex_array_object *vao,
 }
 
 
-/**
- * Unmap the buffer object referenced by given array, if mapped.
- */
-static void
-unmap_array_buffer(struct gl_context *ctx, struct gl_vertex_array_object *vao,
-   GLuint attrib)
-{
-   const struct gl_array_attributes *array = &vao->VertexAttrib[attrib];
-   if (vao->Enabled & VERT_BIT(attrib)) {
-  const struct gl_vertex_buffer_binding *binding =
- &vao->BufferBinding[array->BufferBindingIndex];
-  struct gl_buffer_object *bo = binding->BufferObj;
-  if (_mesa_is_bufferobj(bo) && _mesa_bufferobj_mapped(bo, MAP_INTERNAL)) {
- ctx->Driver.UnmapBuffer(ctx, bo, MAP_INTERNAL);
-  }
-   }
-}
-
-
 static inline int
 sizeof_ib_type(GLenum type)
 {
@@ -156,17 +131,14 @@ check_draw_elements_data(struct gl_context *ctx, GLsizei 
count,
  GLint basevertex)
 {
struct gl_vertex_array_object *vao = ctx->Array.VAO;
-   const void *elemMap;
GLint i;
GLuint k;
 
-   if (_mesa_is_bufferobj(vao->IndexBufferObj)) {
-  elemMap = ctx->Driver.MapBufferRange(ctx, 0,
-   vao->IndexBufferObj->Size,
-   GL_MAP_READ_BIT,
-   vao->IndexBufferObj, MAP_INTERNAL);
-  elements = ADD_POINTERS(elements, elemMap);
-   }
+   _mesa_vao_map(ctx, vao, GL_MAP_READ_BIT);
+
+   if (_mesa_is_bufferobj(vao->IndexBufferObj))
+   elements =
+  ADD_POINTERS(vao->IndexBufferObj->Mappings[MAP_INTERNAL].Pointer, 
elements);
 
for (i = 0; i < count; i++) {
   GLuint j;
@@ -192,13 +164,7 @@ check_draw_elements_data(struct gl_context *ctx, GLsizei 
count,
   }
}
 
-   if (_mesa_is_bufferobj(vao->IndexBufferObj)) {
-  ctx->Driver.UnmapBuffer(ctx, vao->IndexBufferObj, MAP_INTERNAL);
-   }
-
-   for (k = 0; k < VERT_ATTRIB_MAX; k++) {
-  unmap_array_buffer(ctx, vao, k);
-   }
+   _mesa_vao_unmap(ctx, vao);
 }
 
 
@@ -272,11 +238,13 @@ static void
 print_draw_arrays(struct gl_context *ctx,
   GLenum mode, GLint start, GLsizei count)
 {
-   const struct gl_vertex_array_object *vao = ctx->Array.VAO;
+   struct gl_vertex_array_object *vao = ctx->Array.VAO;
 
printf("_mesa_DrawArrays(mode 0x%x, start %d, count %d):\n",
   mode, start, count);
 
+   _mesa_vao_map_arrays(ctx, vao, GL_MAP_READ_BIT);
+
GLbitfield mask = vao->Enabled;
while (mask) {
   const gl_vert_attrib i = u_bit_scan(&mask);
@@ -293,9 +261,7 @@ print_draw_arrays(struct gl_context *ctx,
  array->Ptr, bufObj->Name);
 
   if (_mesa_is_bufferobj(bufObj)) {
- GLubyte *p = ctx->Driver.MapBufferRange(ctx, 0, bufObj->Size,
- GL_MAP_READ_BIT, bufObj,
- MAP_INTERNAL);
+ GLubyte *p = bufObj->Mappings[MAP_INTERNAL].Pointer;
  int offset = (int) (GLintptr)
 _mesa_vertex_attrib_address(array, binding);
 
@@ -326,9 +292,10 @@ print_draw_arrays(struct gl_context *ctx,
printf("float[%d] = 0x%08x %f\n", i, k[i], f[i]);
 i++;
  } while (i < n);
- ctx->Driver.UnmapBuffer(ctx, bufObj, MAP_INTERNAL);
   }
}
+
+   _mesa_vao_unmap_arrays(ctx, vao);
 }
 
 
-- 
2.20.1

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

[Mesa-dev] [PATCH 1/8] mesa: Implement helper functions to map and unmap a VAO.

2019-03-05 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Provide a set of functions that maps or unmaps all VBOs held
in a VAO. The functions will be used in the following patches.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/arrayobj.c | 84 
 src/mesa/main/arrayobj.h | 18 +
 2 files changed, 102 insertions(+)

diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index 68d30aa9b1f..1f6c6904739 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -913,6 +913,90 @@ _mesa_all_buffers_are_unmapped(const struct 
gl_vertex_array_object *vao)
return true;
 }
 
+
+/**
+ * Map buffer objects used in attribute arrays.
+ */
+void
+_mesa_vao_map_arrays(struct gl_context *ctx, struct gl_vertex_array_object 
*vao,
+ GLbitfield access)
+{
+   GLbitfield mask = vao->Enabled & vao->VertexAttribBufferMask;
+   while (mask) {
+  /* Do not use u_bit_scan as we can walk multiple attrib arrays at once */
+  const gl_vert_attrib attr = ffs(mask) - 1;
+  const GLubyte bindex = vao->VertexAttrib[attr].BufferBindingIndex;
+  struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[bindex];
+  mask &= ~binding->_BoundArrays;
+
+  struct gl_buffer_object *bo = binding->BufferObj;
+  assert(_mesa_is_bufferobj(bo));
+  if (_mesa_bufferobj_mapped(bo, MAP_INTERNAL))
+ continue;
+
+  ctx->Driver.MapBufferRange(ctx, 0, bo->Size, access, bo, MAP_INTERNAL);
+   }
+}
+
+
+/**
+ * Map buffer objects used in the vao,
+ * attribute arrays and index buffer.
+ */
+void
+_mesa_vao_map(struct gl_context *ctx, struct gl_vertex_array_object *vao,
+  GLbitfield access)
+{
+   struct gl_buffer_object *bo = vao->IndexBufferObj;
+
+   if (_mesa_is_bufferobj(bo) && !_mesa_bufferobj_mapped(bo, MAP_INTERNAL))
+  ctx->Driver.MapBufferRange(ctx, 0, bo->Size, access, bo, MAP_INTERNAL);
+
+   _mesa_vao_map_arrays(ctx, vao, access);
+}
+
+
+/**
+ * Unmap buffer objects used in attribute arrays.
+ */
+void
+_mesa_vao_unmap_arrays(struct gl_context *ctx,
+   struct gl_vertex_array_object *vao)
+{
+   GLbitfield mask = vao->Enabled & vao->VertexAttribBufferMask;
+   while (mask) {
+  /* Do not use u_bit_scan as we can walk multiple attrib arrays at once */
+  const gl_vert_attrib attr = ffs(mask) - 1;
+  const GLubyte bindex = vao->VertexAttrib[attr].BufferBindingIndex;
+  struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[bindex];
+  mask &= ~binding->_BoundArrays;
+
+  struct gl_buffer_object *bo = binding->BufferObj;
+  assert(_mesa_is_bufferobj(bo));
+  if (!_mesa_bufferobj_mapped(bo, MAP_INTERNAL))
+ continue;
+
+  ctx->Driver.UnmapBuffer(ctx, bo, MAP_INTERNAL);
+   }
+}
+
+
+/**
+ * Unmap buffer objects used in the vao,
+ * attribute arrays and index buffer.
+ */
+void
+_mesa_vao_unmap(struct gl_context *ctx, struct gl_vertex_array_object *vao)
+{
+   struct gl_buffer_object *bo = vao->IndexBufferObj;
+
+   if (_mesa_is_bufferobj(bo) && _mesa_bufferobj_mapped(bo, MAP_INTERNAL))
+  ctx->Driver.UnmapBuffer(ctx, bo, MAP_INTERNAL);
+
+   _mesa_vao_unmap_arrays(ctx, vao);
+}
+
+
 /**/
 /* API Functions  */
 /**/
diff --git a/src/mesa/main/arrayobj.h b/src/mesa/main/arrayobj.h
index ee87b4b6ba5..7516bae9e39 100644
--- a/src/mesa/main/arrayobj.h
+++ b/src/mesa/main/arrayobj.h
@@ -100,6 +100,24 @@ extern bool
 _mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao);
 
 
+extern void
+_mesa_vao_map_arrays(struct gl_context *ctx, struct gl_vertex_array_object 
*vao,
+ GLbitfield access);
+
+extern void
+_mesa_vao_map(struct gl_context *ctx, struct gl_vertex_array_object *vao,
+  GLbitfield access);
+
+
+extern void
+_mesa_vao_unmap_arrays(struct gl_context *ctx,
+   struct gl_vertex_array_object *vao);
+
+extern void
+_mesa_vao_unmap(struct gl_context *ctx,
+struct gl_vertex_array_object *vao);
+
+
 /**
  * Array to apply the position/generic0 aliasing map to
  * an attribute value used in vertex processing inputs to an attribute
-- 
2.20.1

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

[Mesa-dev] [PATCH 5/8] mesa: Remove _ae_{, un}map_vbos and dependencies.

2019-03-05 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Since mapping and unmapping the buffer objects in a VAO is handled
directly from the VAO, this part of the _NEW_ARRAY state is no longer
used. So remove this part of array element state.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/api_arrayelt.c | 95 
 src/mesa/main/api_arrayelt.h |  5 --
 2 files changed, 100 deletions(-)

diff --git a/src/mesa/main/api_arrayelt.c b/src/mesa/main/api_arrayelt.c
index ea91fbcabf5..1c086bbcda4 100644
--- a/src/mesa/main/api_arrayelt.c
+++ b/src/mesa/main/api_arrayelt.c
@@ -66,11 +66,6 @@ typedef struct {
AEarray arrays[32];
AEattrib attribs[VERT_ATTRIB_MAX + 1];
 
-   /* List of VBOs we need to map before executing ArrayElements */
-   struct gl_buffer_object *vbo[VERT_ATTRIB_MAX];
-   GLuint nr_vbos;
-   GLboolean mapped_vbos;  /**< Any currently mapped VBOs? */
-
bool dirty_state;
 } AEcontext;
 
@@ -1534,26 +1529,6 @@ _ae_destroy_context(struct gl_context *ctx)
 }
 
 
-/**
- * Check if the given vertex buffer object exists and is not mapped.
- * If so, add it to the list of buffers we must map before executing
- * an glArrayElement call.
- */
-static void
-check_vbo(AEcontext *actx, struct gl_buffer_object *vbo)
-{
-   if (_mesa_is_bufferobj(vbo) &&
-   !_mesa_bufferobj_mapped(vbo, MAP_INTERNAL)) {
-  GLuint i;
-  for (i = 0; i < actx->nr_vbos; i++)
- if (actx->vbo[i] == vbo)
-return;  /* already in the list, we're done */
-  assert(actx->nr_vbos < VERT_ATTRIB_MAX);
-  actx->vbo[actx->nr_vbos++] = vbo;
-   }
-}
-
-
 /**
  * Make a list of per-vertex functions to call for each glArrayElement call.
  * These functions access the array data (i.e. glVertex, glColor, glNormal,
@@ -1569,14 +1544,11 @@ _ae_update_state(struct gl_context *ctx)
GLuint i;
struct gl_vertex_array_object *vao = ctx->Array.VAO;
 
-   actx->nr_vbos = 0;
-
/* conventional vertex arrays */
if (vao->Enabled & VERT_BIT_COLOR_INDEX) {
   aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX];
   aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
   aa->offset = IndexFuncs[TYPE_IDX(aa->array->Format.Type)];
-  check_vbo(actx, aa->binding->BufferObj);
   aa++;
}
 
@@ -1584,7 +1556,6 @@ _ae_update_state(struct gl_context *ctx)
   aa->array = &vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG];
   aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
   aa->offset = _gloffset_EdgeFlagv;
-  check_vbo(actx, aa->binding->BufferObj);
   aa++;
}
 
@@ -1592,7 +1563,6 @@ _ae_update_state(struct gl_context *ctx)
   aa->array = &vao->VertexAttrib[VERT_ATTRIB_NORMAL];
   aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
   aa->offset = NormalFuncs[TYPE_IDX(aa->array->Format.Type)];
-  check_vbo(actx, aa->binding->BufferObj);
   aa++;
}
 
@@ -1600,7 +1570,6 @@ _ae_update_state(struct gl_context *ctx)
   aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR0];
   aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
   aa->offset = 
ColorFuncs[aa->array->Format.Size-3][TYPE_IDX(aa->array->Format.Type)];
-  check_vbo(actx, aa->binding->BufferObj);
   aa++;
}
 
@@ -1608,7 +1577,6 @@ _ae_update_state(struct gl_context *ctx)
   aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR1];
   aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
   aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Format.Type)];
-  check_vbo(actx, aa->binding->BufferObj);
   aa++;
}
 
@@ -1616,7 +1584,6 @@ _ae_update_state(struct gl_context *ctx)
   aa->array = &vao->VertexAttrib[VERT_ATTRIB_FOG];
   aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
   aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Format.Type)];
-  check_vbo(actx, aa->binding->BufferObj);
   aa++;
}
 
@@ -1634,7 +1601,6 @@ _ae_update_state(struct gl_context *ctx)
  [at->array->Format.Size-1]
  [TYPE_IDX(at->array->Format.Type)];
  at->index = VERT_ATTRIB_TEX0 + i;
-check_vbo(actx, at->binding->BufferObj);
  at++;
   }
}
@@ -1666,7 +1632,6 @@ _ae_update_state(struct gl_context *ctx)
 [TYPE_IDX(at->array->Format.Type)];
 
  at->index = i;
-check_vbo(actx, at->binding->BufferObj);
  at++;
   }
}
@@ -1680,19 +1645,15 @@ _ae_update_state(struct gl_context *ctx)
   aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
   assert(aa->array->Format.Size >= 2); /* XXX fix someday? */
   aa->offset = 
VertexFuncs[aa->array->Format.Size-2][TYPE_IDX(aa->array->Format.Type)];
-  check_vbo(actx, aa->binding->BufferObj);
   aa++;
}
else if (vao->Enabled & VERT_BIT_POS) {
   aa->array = &vao->VertexAttrib[VERT_ATTRIB_POS];
   aa->binding = &vao->BufferBinding[aa->array->Bu

[Mesa-dev] [PATCH 7/8] vbo: Fix basevertex handling in display list compiles.

2019-03-05 Thread Mathias . Froehlich
From: Mathias Fröhlich 

The standard requires that the primitive restart comparison happens before
the basevertex value is added. Do this now, drop a reference to the standard
why this happens at this place.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/vbo/vbo_save_api.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index bb578694e00..7f8c06b630c 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -1373,8 +1373,15 @@ _save_OBE_MultiDrawArrays(GLenum mode, const GLint 
*first,
 
 
 static void
-array_element(struct gl_context *ctx, struct _glapi_table *disp, GLuint elt)
+array_element(struct gl_context *ctx, struct _glapi_table *disp,
+  GLint basevertex, GLuint elt)
 {
+   /* Section 10.3.5 Primitive Restart:
+* [...]
+*When one of the *BaseVertex drawing commands specified in section 10.5
+* is used, the primitive restart comparison occurs before the basevertex
+* offset is added to the array index.
+*/
/* If PrimitiveRestart is enabled and the index is the RestartIndex
 * then we call PrimitiveRestartNV and return.
 */
@@ -1383,7 +1390,7 @@ array_element(struct gl_context *ctx, struct _glapi_table 
*disp, GLuint elt)
   return;
}
 
-   _mesa_array_element(ctx, disp, elt);
+   _mesa_array_element(ctx, disp, basevertex + elt);
 }
 
 
@@ -1432,15 +1439,15 @@ _save_OBE_DrawElementsBaseVertex(GLenum mode, GLsizei 
count, GLenum type,
switch (type) {
case GL_UNSIGNED_BYTE:
   for (i = 0; i < count; i++)
- array_element(ctx, GET_DISPATCH(), (basevertex + ((GLubyte *) 
indices)[i]));
+ array_element(ctx, GET_DISPATCH(), basevertex, ((GLubyte *) 
indices)[i]);
   break;
case GL_UNSIGNED_SHORT:
   for (i = 0; i < count; i++)
- array_element(ctx, GET_DISPATCH(), (basevertex + ((GLushort *) 
indices)[i]));
+ array_element(ctx, GET_DISPATCH(), basevertex, ((GLushort *) 
indices)[i]);
   break;
case GL_UNSIGNED_INT:
   for (i = 0; i < count; i++)
- array_element(ctx, GET_DISPATCH(), (basevertex + ((GLuint *) 
indices)[i]));
+ array_element(ctx, GET_DISPATCH(), basevertex, ((GLuint *) 
indices)[i]);
   break;
default:
   _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)");
-- 
2.20.1

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

[Mesa-dev] [PATCH 0/8] Half way to remove _NEW_ARRAY.

2019-03-05 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi all,

The following series introduces functions to map and unmap all
vbos stored in a vao. Make use of those functions where possible.
On that way cleanup and fix what comes up along the way.
The series also already removes half of the state that is tracked
using the _NEW_ARRAY bit. The rest of the _NEW_ARRAY state will
be removed past some more optimization in the vbo module.

The series is tested without regressions on radeonsi using piglit and deqp.

please review!
Thanks!

Mathias

Mathias Fröhlich (8):
  mesa: Implement helper functions to map and unmap a VAO.
  mesa: Factor out _mesa_array_element.
  mesa: Use _mesa_array_element in dlist save.
  mesa: Replace _ae_{,un}map_vbos with _mesa_vao_{,un}map_arrays
  mesa: Remove _ae_{,un}map_vbos and dependencies.
  mesa: Use mapping tools in debug prints.
  vbo: Fix basevertex handling in display list compiles.
  vbo: Fix GL_PRIMITIVE_RESTART_FIXED_INDEX in display list compiles.

 src/mesa/main/api_arrayelt.c | 136 +++
 src/mesa/main/api_arrayelt.h |   7 +-
 src/mesa/main/arrayobj.c |  84 ++
 src/mesa/main/arrayobj.h |  18 +
 src/mesa/main/draw.c |  57 ---
 src/mesa/vbo/vbo_save_api.c  |  46 +---
 6 files changed, 177 insertions(+), 171 deletions(-)

-- 
2.20.1

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

[Mesa-dev] [PATCH 1/9] mesa: Implement helper functions to map and unmap a VAO.

2019-03-14 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Brian,

For reference the v2 with the updated comments.

Thanks and best

Mathias

Provide a set of functions that maps or unmaps all VBOs held
in a VAO. The functions will be used in the following patches.

v2: Update comments.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/arrayobj.c | 84 
 src/mesa/main/arrayobj.h | 18 +
 2 files changed, 102 insertions(+)

diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index 68d30aa9b1f..63138096da6 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -913,6 +913,90 @@ _mesa_all_buffers_are_unmapped(const struct 
gl_vertex_array_object *vao)
return true;
 }
 
+
+/**
+ * Map buffer objects used in attribute arrays.
+ */
+void
+_mesa_vao_map_arrays(struct gl_context *ctx, struct gl_vertex_array_object 
*vao,
+ GLbitfield access)
+{
+   GLbitfield mask = vao->Enabled & vao->VertexAttribBufferMask;
+   while (mask) {
+  /* Do not use u_bit_scan as we can walk multiple attrib arrays at once */
+  const gl_vert_attrib attr = ffs(mask) - 1;
+  const GLubyte bindex = vao->VertexAttrib[attr].BufferBindingIndex;
+  struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[bindex];
+  mask &= ~binding->_BoundArrays;
+
+  struct gl_buffer_object *bo = binding->BufferObj;
+  assert(_mesa_is_bufferobj(bo));
+  if (_mesa_bufferobj_mapped(bo, MAP_INTERNAL))
+ continue;
+
+  ctx->Driver.MapBufferRange(ctx, 0, bo->Size, access, bo, MAP_INTERNAL);
+   }
+}
+
+
+/**
+ * Map buffer objects used in the vao, attribute arrays and index buffer.
+ */
+void
+_mesa_vao_map(struct gl_context *ctx, struct gl_vertex_array_object *vao,
+  GLbitfield access)
+{
+   struct gl_buffer_object *bo = vao->IndexBufferObj;
+
+   /* map the index buffer, if there is one, and not already mapped */
+   if (_mesa_is_bufferobj(bo) && !_mesa_bufferobj_mapped(bo, MAP_INTERNAL))
+  ctx->Driver.MapBufferRange(ctx, 0, bo->Size, access, bo, MAP_INTERNAL);
+
+   _mesa_vao_map_arrays(ctx, vao, access);
+}
+
+
+/**
+ * Unmap buffer objects used in attribute arrays.
+ */
+void
+_mesa_vao_unmap_arrays(struct gl_context *ctx,
+   struct gl_vertex_array_object *vao)
+{
+   GLbitfield mask = vao->Enabled & vao->VertexAttribBufferMask;
+   while (mask) {
+  /* Do not use u_bit_scan as we can walk multiple attrib arrays at once */
+  const gl_vert_attrib attr = ffs(mask) - 1;
+  const GLubyte bindex = vao->VertexAttrib[attr].BufferBindingIndex;
+  struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[bindex];
+  mask &= ~binding->_BoundArrays;
+
+  struct gl_buffer_object *bo = binding->BufferObj;
+  assert(_mesa_is_bufferobj(bo));
+  if (!_mesa_bufferobj_mapped(bo, MAP_INTERNAL))
+ continue;
+
+  ctx->Driver.UnmapBuffer(ctx, bo, MAP_INTERNAL);
+   }
+}
+
+
+/**
+ * Unmap buffer objects used in the vao, attribute arrays and index buffer.
+ */
+void
+_mesa_vao_unmap(struct gl_context *ctx, struct gl_vertex_array_object *vao)
+{
+   struct gl_buffer_object *bo = vao->IndexBufferObj;
+
+   /* unmap the index buffer, if there is one, and still mapped */
+   if (_mesa_is_bufferobj(bo) && _mesa_bufferobj_mapped(bo, MAP_INTERNAL))
+  ctx->Driver.UnmapBuffer(ctx, bo, MAP_INTERNAL);
+
+   _mesa_vao_unmap_arrays(ctx, vao);
+}
+
+
 /**/
 /* API Functions  */
 /**/
diff --git a/src/mesa/main/arrayobj.h b/src/mesa/main/arrayobj.h
index ee87b4b6ba5..7516bae9e39 100644
--- a/src/mesa/main/arrayobj.h
+++ b/src/mesa/main/arrayobj.h
@@ -100,6 +100,24 @@ extern bool
 _mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao);
 
 
+extern void
+_mesa_vao_map_arrays(struct gl_context *ctx, struct gl_vertex_array_object 
*vao,
+ GLbitfield access);
+
+extern void
+_mesa_vao_map(struct gl_context *ctx, struct gl_vertex_array_object *vao,
+  GLbitfield access);
+
+
+extern void
+_mesa_vao_unmap_arrays(struct gl_context *ctx,
+   struct gl_vertex_array_object *vao);
+
+extern void
+_mesa_vao_unmap(struct gl_context *ctx,
+struct gl_vertex_array_object *vao);
+
+
 /**
  * Array to apply the position/generic0 aliasing map to
  * an attribute value used in vertex processing inputs to an attribute
-- 
2.20.1

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

[Mesa-dev] [PATCH 9/9] mesa: Add assert to _mesa_primitive_restart_index.

2019-03-14 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi Brian,

You mean an assert like this?
This patch also made it together with the rest of the series through intels CI.

best

Mathias





Make sure the inde_size parameter is meant to be in bytes.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/varray.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/mesa/main/varray.h b/src/mesa/main/varray.h
index 0be57971bd7..2831720edfc 100644
--- a/src/mesa/main/varray.h
+++ b/src/mesa/main/varray.h
@@ -316,6 +316,9 @@ static inline unsigned
 _mesa_primitive_restart_index(const struct gl_context *ctx,
   unsigned index_size)
 {
+   /* The index_size parameter is menat to be in bytes. */
+   assert(index_size == 1 || index_size == 2 || index_size == 4);
+
/* From the OpenGL 4.3 core specification, page 302:
 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
 *  enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
-- 
2.20.1

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

[Mesa-dev] [PATCH 3/4] mesa: Handle clip control in meta operations.

2014-10-21 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Restore clip control to the default state if MESA_META_VIEWPORT
or MESA_META_DEPTH_TEST is requested.

Signed-off-by: Mathias Froehlich 
---
 src/mesa/drivers/common/meta.c | 13 +
 src/mesa/drivers/common/meta.h |  4 
 2 files changed, 17 insertions(+)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 7a8e627..119f327 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -494,6 +494,13 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
   _mesa_set_enable(ctx, GL_DITHER, GL_TRUE);
}
 
+   if (state & MESA_META_CLIP_CONTROL) {
+  save->ClipControl = ctx->ClipControl;
+  if (ctx->ClipControl.Origin != GL_LOWER_LEFT ||
+  ctx->ClipControl.Depth != GL_NEGATIVE_ONE_TO_ONE)
+ _mesa_ClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
+   }
+
if (state & MESA_META_COLOR_MASK) {
   memcpy(save->ColorMask, ctx->Color.ColorMask,
  sizeof(ctx->Color.ColorMask));
@@ -856,6 +863,12 @@ _mesa_meta_end(struct gl_context *ctx)
if (state & MESA_META_DITHER)
   _mesa_set_enable(ctx, GL_DITHER, save->DitherFlag);
 
+   if (state & MESA_META_CLIP_CONTROL) {
+  if (ctx->ClipControl.Origin != save->ClipControl.Origin ||
+  ctx->ClipControl.Depth != save->ClipControl.Depth)
+ _mesa_ClipControl(save->ClipControl.Origin, save->ClipControl.Depth);
+   }
+
if (state & MESA_META_COLOR_MASK) {
   GLuint i;
   for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h
index 2c9517b..08514ad 100644
--- a/src/mesa/drivers/common/meta.h
+++ b/src/mesa/drivers/common/meta.h
@@ -60,6 +60,7 @@
 #define MESA_META_OCCLUSION_QUERY  0x40
 #define MESA_META_DRAW_BUFFERS 0x80
 #define MESA_META_DITHER  0x100
+#define MESA_META_CLIP_CONTROL(MESA_META_VIEWPORT|MESA_META_DEPTH_TEST)
 /**\}*/
 
 /**
@@ -88,6 +89,9 @@ struct save_state
/** MESA_META_DITHER */
GLboolean DitherFlag;
 
+   /** MESA_META_CLIP_CONTROL */
+   struct gl_clip_control ClipControl;
+
/** MESA_META_COLOR_MASK */
GLubyte ColorMask[MAX_DRAW_BUFFERS][4];
 
-- 
1.9.3

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


[Mesa-dev] [PATCH 0/4] Implement clip control

2014-10-21 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi,

The next approach to bring decent depth buffer precision to mesa.

The patch series implements ARB_clip_control in mesa and enables the
extension for the gallium drivers.

Please review.

Greetings
Mathias


Mathias Fröhlich (4):
  mesa: Refactor viewport transform computation.
  mesa: Implement ARB_clip_control.
  mesa: Handle clip control in meta operations.
  gallium: Enable ARB_clip_control for gallium drivers.

 docs/GL3.txt|   2 +-
 docs/relnotes/10.4.html |   1 +
 src/mapi/glapi/gen/ARB_clip_control.xml |  26 ++
 src/mapi/glapi/gen/gl_API.xml   |   4 +-
 src/mesa/drivers/common/meta.c  |  13 +++
 src/mesa/drivers/common/meta.h  |   4 +
 src/mesa/drivers/dri/i915/i915_state.c  |  26 +++---
 src/mesa/main/dlist.c   |  26 ++
 src/mesa/main/extensions.c  |   1 +
 src/mesa/main/get_hash_params.py|   2 +
 src/mesa/main/mtypes.h  |  12 +++
 src/mesa/main/polygon.c |   5 +-
 src/mesa/main/state.c   |   9 ++-
 src/mesa/main/tests/dispatch_sanity.cpp |   3 +
 src/mesa/main/viewport.c| 118 
 src/mesa/main/viewport.h|   6 ++
 src/mesa/math/m_matrix.c|  17 ++--
 src/mesa/math/m_matrix.h|   4 +-
 src/mesa/state_tracker/st_atom_rasterizer.c |  14 +++-
 src/mesa/state_tracker/st_atom_viewport.c   |  23 +++---
 src/mesa/state_tracker/st_extensions.c  |   1 +
 21 files changed, 252 insertions(+), 65 deletions(-)
 create mode 100644 src/mapi/glapi/gen/ARB_clip_control.xml

-- 
1.9.3

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


[Mesa-dev] [PATCH 2/4] mesa: Implement ARB_clip_control.

2014-10-21 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Implement the mesa parts of ARB_clip_control.
So far no driver enables this.

Signed-off-by: Mathias Froehlich 
---
 src/mapi/glapi/gen/ARB_clip_control.xml | 25 +++
 src/mapi/glapi/gen/gl_API.xml   |  4 +-
 src/mesa/main/dlist.c   | 26 +++
 src/mesa/main/extensions.c  |  1 +
 src/mesa/main/get_hash_params.py|  2 +
 src/mesa/main/mtypes.h  | 12 +
 src/mesa/main/polygon.c |  5 ++-
 src/mesa/main/tests/dispatch_sanity.cpp |  3 ++
 src/mesa/main/viewport.c| 79 +++--
 src/mesa/main/viewport.h|  3 ++
 10 files changed, 154 insertions(+), 6 deletions(-)
 create mode 100644 src/mapi/glapi/gen/ARB_clip_control.xml

diff --git a/src/mapi/glapi/gen/ARB_clip_control.xml 
b/src/mapi/glapi/gen/ARB_clip_control.xml
new file mode 100644
index 000..2973a31
--- /dev/null
+++ b/src/mapi/glapi/gen/ARB_clip_control.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
index 73f2f75..534e6a0 100644
--- a/src/mapi/glapi/gen/gl_API.xml
+++ b/src/mapi/glapi/gen/gl_API.xml
@@ -8364,7 +8364,9 @@
 
 http://www.w3.org/2001/XInclude"/>
 
-
+
+
+http://www.w3.org/2001/XInclude"/>
 
 
 
diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c
index 5c7160d..4b7b060 100644
--- a/src/mesa/main/dlist.c
+++ b/src/mesa/main/dlist.c
@@ -398,6 +398,9 @@ typedef enum
OPCODE_PROGRAM_UNIFORM_MATRIX34F,
OPCODE_PROGRAM_UNIFORM_MATRIX43F,
 
+   /* GL_ARB_clip_control */
+   OPCODE_CLIP_CONTROL,
+
/* GL_ARB_color_buffer_float */
OPCODE_CLAMP_COLOR,
 
@@ -7208,6 +7211,22 @@ save_ProgramUniformMatrix4fv(GLuint program, GLint 
location, GLsizei count,
 }
 
 static void GLAPIENTRY
+save_ClipControl(GLenum origin, GLenum depth)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   Node *n;
+   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+   n = alloc_instruction(ctx, OPCODE_CLIP_CONTROL, 2);
+   if (n) {
+  n[1].e = origin;
+  n[2].e = depth;
+   }
+   if (ctx->ExecuteFlag) {
+  CALL_ClipControl(ctx->Exec, (origin, depth));
+   }
+}
+
+static void GLAPIENTRY
 save_ClampColorARB(GLenum target, GLenum clamp)
 {
GET_CURRENT_CONTEXT(ctx);
@@ -8617,6 +8636,10 @@ execute_list(struct gl_context *ctx, GLuint list)
   get_pointer(&n[5])));
 break;
 
+ case OPCODE_CLIP_CONTROL:
+CALL_ClipControl(ctx->Exec, (n[1].e, n[2].e));
+break;
+
  case OPCODE_CLAMP_COLOR:
 CALL_ClampColor(ctx->Exec, (n[1].e, n[2].e));
 break;
@@ -9551,6 +9574,9 @@ _mesa_initialize_save_table(const struct gl_context *ctx)
SET_TexParameterIiv(table, save_TexParameterIiv);
SET_TexParameterIuiv(table, save_TexParameterIuiv);
 
+   /* GL_ARB_clip_control */
+   SET_ClipControl(table, save_ClipControl);
+
/* GL_ARB_color_buffer_float */
SET_ClampColor(table, save_ClampColorARB);
 
diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
index f0e2f89..15d66a7 100644
--- a/src/mesa/main/extensions.c
+++ b/src/mesa/main/extensions.c
@@ -91,6 +91,7 @@ static const struct extension extension_table[] = {
{ "GL_ARB_buffer_storage",  o(ARB_buffer_storage),  
GL, 2013 },
{ "GL_ARB_clear_buffer_object", o(dummy_true),  
GL, 2012 },
{ "GL_ARB_clear_texture",   o(ARB_clear_texture),   
GL, 2013 },
+   { "GL_ARB_clip_control",o(ARB_clip_control),
GL, 2014 },
{ "GL_ARB_color_buffer_float",  o(ARB_color_buffer_float),  
GL, 2004 },
{ "GL_ARB_compressed_texture_pixel_storage",o(dummy_true),  
GL, 2011 },
{ "GL_ARB_compute_shader",  o(ARB_compute_shader),  
GL, 2012 },
diff --git a/src/mesa/main/get_hash_params.py b/src/mesa/main/get_hash_params.py
index da35684..ed1f390 100644
--- a/src/mesa/main/get_hash_params.py
+++ b/src/mesa/main/get_hash_params.py
@@ -414,6 +414,8 @@ descriptor=[
   [ "AUX_BUFFERS", "BUFFER_INT(Visual.numAuxBuffers), NO_EXTRA" ],
   [ "BLUE_BIAS", "CONTEXT_FLOAT(Pixel.BlueBias), NO_EXTRA" ],
   [ "BLUE_SCALE", "CONTEXT_FLOAT(Pixel.BlueScale), NO_EXTRA" ],
+  [ "CLIP_DEPTH_MODE", "CONTEXT_ENUM(ClipControl.Depth), NO_EXTRA" ],
+  [ "CLIP_ORIGIN", "CONTEXT_ENUM(ClipControl.Origin), NO_EXTRA" ],
   [ "

[Mesa-dev] [PATCH 1/4] mesa: Refactor viewport transform computation.

2014-10-21 Thread Mathias . Froehlich
From: Mathias Fröhlich 

This is for preparation of ARB_clip_control.

Signed-off-by: Mathias Froehlich 
---
 src/mesa/drivers/dri/i915/i915_state.c| 26 ++---
 src/mesa/main/state.c |  9 +++---
 src/mesa/main/viewport.c  | 47 ---
 src/mesa/main/viewport.h  |  3 ++
 src/mesa/math/m_matrix.c  | 17 ++-
 src/mesa/math/m_matrix.h  |  4 +--
 src/mesa/state_tracker/st_atom_viewport.c | 23 +++
 7 files changed, 68 insertions(+), 61 deletions(-)

diff --git a/src/mesa/drivers/dri/i915/i915_state.c 
b/src/mesa/drivers/dri/i915/i915_state.c
index f31b271..f9aecba 100644
--- a/src/mesa/drivers/dri/i915/i915_state.c
+++ b/src/mesa/drivers/dri/i915/i915_state.c
@@ -34,6 +34,7 @@
 #include "main/dd.h"
 #include "main/state.h"
 #include "main/stencil.h"
+#include "main/viewport.h"
 #include "tnl/tnl.h"
 #include "tnl/t_context.h"
 
@@ -401,26 +402,17 @@ void
 intelCalcViewport(struct gl_context * ctx)
 {
struct intel_context *intel = intel_context(ctx);
+   double scale[3], translate[3];
+
+   _mesa_get_viewport_xform(ctx, 0, scale, translate);
 
if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
-  _math_matrix_viewport(&intel->ViewportMatrix,
-   ctx->ViewportArray[0].X,
-   ctx->DrawBuffer->Height - ctx->ViewportArray[0].Y,
-   ctx->ViewportArray[0].Width,
-   -ctx->ViewportArray[0].Height,
-   ctx->ViewportArray[0].Near,
-   ctx->ViewportArray[0].Far,
-   1.0);
-   } else {
-  _math_matrix_viewport(&intel->ViewportMatrix,
-   ctx->ViewportArray[0].X,
-   ctx->ViewportArray[0].Y,
-   ctx->ViewportArray[0].Width,
-   ctx->ViewportArray[0].Height,
-   ctx->ViewportArray[0].Near,
-   ctx->ViewportArray[0].Far,
-   1.0);
+  scale[1] = -scale[1];
+  translate[1] = ctx->DrawBuffer->Height - translate[1];
}
+
+   _math_matrix_viewport(&intel->ViewportMatrix,
+ scale, translate, 1.0);
 }
 
 
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index 80287c4..3dbbfaa 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -51,6 +51,7 @@
 #include "texobj.h"
 #include "texstate.h"
 #include "varray.h"
+#include "viewport.h"
 #include "blend.h"
 
 
@@ -281,11 +282,11 @@ update_viewport_matrix(struct gl_context *ctx)
 * NOTE: RasterPos uses this.
 */
for (i = 0; i < ctx->Const.MaxViewports; i++) {
+  double scale[3], translate[3];
+
+  _mesa_get_viewport_xform(ctx, i, scale, translate);
   _math_matrix_viewport(&ctx->ViewportArray[i]._WindowMap,
-ctx->ViewportArray[i].X, ctx->ViewportArray[i].Y,
-ctx->ViewportArray[i].Width, 
ctx->ViewportArray[i].Height,
-ctx->ViewportArray[i].Near, 
ctx->ViewportArray[i].Far,
-depthMax);
+scale, translate, depthMax);
}
 }
 
diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c
index 222ae30..89766cf 100644
--- a/src/mesa/main/viewport.c
+++ b/src/mesa/main/viewport.c
@@ -39,6 +39,8 @@ set_viewport_no_notify(struct gl_context *ctx, unsigned idx,
GLfloat x, GLfloat y,
GLfloat width, GLfloat height)
 {
+   double scale[3], translate[3];
+
/* clamp width and height to the implementation dependent range */
width  = MIN2(width, (GLfloat) ctx->Const.MaxViewportWidth);
height = MIN2(height, (GLfloat) ctx->Const.MaxViewportHeight);
@@ -75,14 +77,9 @@ set_viewport_no_notify(struct gl_context *ctx, unsigned idx,
 * the WindowMap matrix being up to date in the driver's Viewport
 * and DepthRange functions.
 */
+   _mesa_get_viewport_xform(ctx, idx, scale, translate);
_math_matrix_viewport(&ctx->ViewportArray[idx]._WindowMap,
- ctx->ViewportArray[idx].X,
- ctx->ViewportArray[idx].Y,
- ctx->ViewportArray[idx].Width,
- ctx->ViewportArray[idx].Height,
- ctx->ViewportArray[idx].Near,
- ctx->ViewportArray[idx].Far,
- ctx->DrawBuffer->_DepthMaxF);
+ scale, translate, ctx->DrawBuffer->_DepthMaxF);
 #endif
 }
 
@@ -248,6 +245,8 @@ static void
 set_depth_range_no_notify(struct gl

[Mesa-dev] [PATCH 4/4] gallium: Enable ARB_clip_control for gallium drivers.

2014-10-21 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Gallium should be prepared fine for ARB_clip_control.
So enable this and mention it in the release notes.

Signed-off-by: Mathias Froehlich 
---
 docs/GL3.txt|  2 +-
 docs/relnotes/10.4.html |  1 +
 src/mesa/state_tracker/st_atom_rasterizer.c | 14 +-
 src/mesa/state_tracker/st_extensions.c  |  1 +
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/docs/GL3.txt b/docs/GL3.txt
index 07d1d2c..2fe0da1 100644
--- a/docs/GL3.txt
+++ b/docs/GL3.txt
@@ -187,7 +187,7 @@ GL 4.4, GLSL 4.40:
 GL 4.5, GLSL 4.50:
 
   GL_ARB_ES3_1_compatibility   not started
-  GL_ARB_clip_control  not started
+  GL_ARB_clip_control  DONE (gallium drivers)
   GL_ARB_conditional_render_inverted   DONE (i965, nvc0, 
llvmpipe, softpipe)
   GL_ARB_cull_distance not started
   GL_ARB_derivative_controlDONE (i965, nv50, nvc0, 
r600)
diff --git a/docs/relnotes/10.4.html b/docs/relnotes/10.4.html
index 64cbfae..462eeb5 100644
--- a/docs/relnotes/10.4.html
+++ b/docs/relnotes/10.4.html
@@ -46,6 +46,7 @@ Note: some of the new features are only available with 
certain drivers.
 
 GL_ARB_sample_shading on r600
 GL_ARB_texture_view on nv50, nvc0
+GL_ARB_clip_control on gallium drivers
 
 
 
diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c 
b/src/mesa/state_tracker/st_atom_rasterizer.c
index a228538..050160d 100644
--- a/src/mesa/state_tracker/st_atom_rasterizer.c
+++ b/src/mesa/state_tracker/st_atom_rasterizer.c
@@ -71,6 +71,11 @@ static void update_raster_state( struct st_context *st )
{
   raster->front_ccw = (ctx->Polygon.FrontFace == GL_CCW);
 
+  /* _NEW_VIEWPORT */
+  if (ctx->ClipControl.Origin == GL_UPPER_LEFT) {
+ raster->front_ccw ^= 1;
+  }
+
   /*
* Gallium's surfaces are Y=0=TOP orientation.  OpenGL is the
* opposite.  Window system surfaces are Y=0=TOP.  Mesa's FBOs
@@ -234,6 +239,12 @@ static void update_raster_state( struct st_context *st )
raster->half_pixel_center = 1;
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP)
   raster->bottom_edge_rule = 1;
+   /* _NEW_VIEWPORT */
+   if (ctx->ClipControl.Origin == GL_UPPER_LEFT)
+  raster->bottom_edge_rule ^= 1;
+
+   /* _NEW_VIEWPORT */
+   raster->clip_halfz = (ctx->ClipControl.Depth == GL_ZERO_TO_ONE);
 
/* ST_NEW_RASTERIZER */
raster->rasterizer_discard = ctx->RasterDiscard;
@@ -265,7 +276,8 @@ const struct st_tracked_state st_update_rasterizer = {
_NEW_PROGRAM |
_NEW_SCISSOR |
_NEW_FRAG_CLAMP |
-   _NEW_TRANSFORM),  /* mesa state dependencies*/
+   _NEW_TRANSFORM |
+   _NEW_VIEWPORT),  /* mesa state dependencies*/
   (ST_NEW_VERTEX_PROGRAM |
ST_NEW_RASTERIZER),  /* state tracker dependencies */
},
diff --git a/src/mesa/state_tracker/st_extensions.c 
b/src/mesa/state_tracker/st_extensions.c
index 5dd8278..e22347b 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -585,6 +585,7 @@ void st_init_extensions(struct pipe_screen *screen,
 * Extensions that are supported by all Gallium drivers:
 */
extensions->ARB_ES2_compatibility = GL_TRUE;
+   extensions->ARB_clip_control = GL_TRUE;
extensions->ARB_draw_elements_base_vertex = GL_TRUE;
extensions->ARB_explicit_attrib_location = GL_TRUE;
extensions->ARB_explicit_uniform_location = GL_TRUE;
-- 
1.9.3

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


[Mesa-dev] [PATCH 5/5] gallium: Enable ARB_clip_control for gallium drivers.

2014-10-22 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Gallium should be prepared fine for ARB_clip_control.
So enable this and mention it in the release notes.

v2:
Only enable for drivers announcing the freshly introduced
PIPE_CAP_CLIP_HALFZ capability.

Signed-off-by: Mathias Froehlich 
---
 docs/GL3.txt|  2 +-
 docs/relnotes/10.4.html |  1 +
 src/mesa/state_tracker/st_atom_rasterizer.c | 14 +-
 src/mesa/state_tracker/st_extensions.c  |  5 +
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/docs/GL3.txt b/docs/GL3.txt
index 07d1d2c..35b7678 100644
--- a/docs/GL3.txt
+++ b/docs/GL3.txt
@@ -187,7 +187,7 @@ GL 4.4, GLSL 4.40:
 GL 4.5, GLSL 4.50:
 
   GL_ARB_ES3_1_compatibility   not started
-  GL_ARB_clip_control  not started
+  GL_ARB_clip_control  DONE (llvmpipe, 
softpipe)
   GL_ARB_conditional_render_inverted   DONE (i965, nvc0, 
llvmpipe, softpipe)
   GL_ARB_cull_distance not started
   GL_ARB_derivative_controlDONE (i965, nv50, nvc0, 
r600)
diff --git a/docs/relnotes/10.4.html b/docs/relnotes/10.4.html
index 64cbfae..4c7af47 100644
--- a/docs/relnotes/10.4.html
+++ b/docs/relnotes/10.4.html
@@ -46,6 +46,7 @@ Note: some of the new features are only available with 
certain drivers.
 
 GL_ARB_sample_shading on r600
 GL_ARB_texture_view on nv50, nvc0
+GL_ARB_clip_control on llvmpipe, softpipe
 
 
 
diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c 
b/src/mesa/state_tracker/st_atom_rasterizer.c
index dfa728b..31d7776 100644
--- a/src/mesa/state_tracker/st_atom_rasterizer.c
+++ b/src/mesa/state_tracker/st_atom_rasterizer.c
@@ -72,6 +72,11 @@ static void update_raster_state( struct st_context *st )
{
   raster->front_ccw = (ctx->Polygon.FrontFace == GL_CCW);
 
+  /* _NEW_VIEWPORT */
+  if (ctx->ClipControl.Origin == GL_UPPER_LEFT) {
+ raster->front_ccw ^= 1;
+  }
+
   /*
* Gallium's surfaces are Y=0=TOP orientation.  OpenGL is the
* opposite.  Window system surfaces are Y=0=TOP.  Mesa's FBOs
@@ -241,6 +246,12 @@ static void update_raster_state( struct st_context *st )
raster->half_pixel_center = 1;
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP)
   raster->bottom_edge_rule = 1;
+   /* _NEW_VIEWPORT */
+   if (ctx->ClipControl.Origin == GL_UPPER_LEFT)
+  raster->bottom_edge_rule ^= 1;
+
+   /* _NEW_VIEWPORT */
+   raster->clip_halfz = (ctx->ClipControl.Depth == GL_ZERO_TO_ONE);
 
/* ST_NEW_RASTERIZER */
raster->rasterizer_discard = ctx->RasterDiscard;
@@ -272,7 +283,8 @@ const struct st_tracked_state st_update_rasterizer = {
_NEW_PROGRAM |
_NEW_SCISSOR |
_NEW_FRAG_CLAMP |
-   _NEW_TRANSFORM),  /* mesa state dependencies*/
+   _NEW_TRANSFORM |
+   _NEW_VIEWPORT),  /* mesa state dependencies*/
   (ST_NEW_VERTEX_PROGRAM |
ST_NEW_RASTERIZER),  /* state tracker dependencies */
},
diff --git a/src/mesa/state_tracker/st_extensions.c 
b/src/mesa/state_tracker/st_extensions.c
index 78bfe30..4a3f055 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -889,4 +889,9 @@ void st_init_extensions(struct pipe_screen *screen,
PIPE_VIDEO_CAP_SUPPORTS_INTERLACED)) {
   extensions->NV_vdpau_interop = GL_TRUE;
}
+
+   /* ARB_clip_control */
+   if (screen->get_param(screen, PIPE_CAP_CLIP_HALFZ)) {
+  extensions->ARB_clip_control = GL_TRUE;
+   }
 }
-- 
1.9.3

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


[Mesa-dev] [PATCH 2/5] mesa: Implement ARB_clip_control.

2014-10-22 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Implement the mesa parts of ARB_clip_control.
So far no driver enables this.

Signed-off-by: Mathias Froehlich 
---
 src/mapi/glapi/gen/ARB_clip_control.xml | 25 +++
 src/mapi/glapi/gen/gl_API.xml   |  4 +-
 src/mesa/main/dlist.c   | 26 +++
 src/mesa/main/extensions.c  |  1 +
 src/mesa/main/get_hash_params.py|  2 +
 src/mesa/main/mtypes.h  | 12 +
 src/mesa/main/polygon.c |  5 ++-
 src/mesa/main/tests/dispatch_sanity.cpp |  3 ++
 src/mesa/main/viewport.c| 79 +++--
 src/mesa/main/viewport.h|  3 ++
 10 files changed, 154 insertions(+), 6 deletions(-)
 create mode 100644 src/mapi/glapi/gen/ARB_clip_control.xml

diff --git a/src/mapi/glapi/gen/ARB_clip_control.xml 
b/src/mapi/glapi/gen/ARB_clip_control.xml
new file mode 100644
index 000..2973a31
--- /dev/null
+++ b/src/mapi/glapi/gen/ARB_clip_control.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
index 73f2f75..534e6a0 100644
--- a/src/mapi/glapi/gen/gl_API.xml
+++ b/src/mapi/glapi/gen/gl_API.xml
@@ -8364,7 +8364,9 @@
 
 http://www.w3.org/2001/XInclude"/>
 
-
+
+
+http://www.w3.org/2001/XInclude"/>
 
 
 
diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c
index 5c7160d..4b7b060 100644
--- a/src/mesa/main/dlist.c
+++ b/src/mesa/main/dlist.c
@@ -398,6 +398,9 @@ typedef enum
OPCODE_PROGRAM_UNIFORM_MATRIX34F,
OPCODE_PROGRAM_UNIFORM_MATRIX43F,
 
+   /* GL_ARB_clip_control */
+   OPCODE_CLIP_CONTROL,
+
/* GL_ARB_color_buffer_float */
OPCODE_CLAMP_COLOR,
 
@@ -7208,6 +7211,22 @@ save_ProgramUniformMatrix4fv(GLuint program, GLint 
location, GLsizei count,
 }
 
 static void GLAPIENTRY
+save_ClipControl(GLenum origin, GLenum depth)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   Node *n;
+   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+   n = alloc_instruction(ctx, OPCODE_CLIP_CONTROL, 2);
+   if (n) {
+  n[1].e = origin;
+  n[2].e = depth;
+   }
+   if (ctx->ExecuteFlag) {
+  CALL_ClipControl(ctx->Exec, (origin, depth));
+   }
+}
+
+static void GLAPIENTRY
 save_ClampColorARB(GLenum target, GLenum clamp)
 {
GET_CURRENT_CONTEXT(ctx);
@@ -8617,6 +8636,10 @@ execute_list(struct gl_context *ctx, GLuint list)
   get_pointer(&n[5])));
 break;
 
+ case OPCODE_CLIP_CONTROL:
+CALL_ClipControl(ctx->Exec, (n[1].e, n[2].e));
+break;
+
  case OPCODE_CLAMP_COLOR:
 CALL_ClampColor(ctx->Exec, (n[1].e, n[2].e));
 break;
@@ -9551,6 +9574,9 @@ _mesa_initialize_save_table(const struct gl_context *ctx)
SET_TexParameterIiv(table, save_TexParameterIiv);
SET_TexParameterIuiv(table, save_TexParameterIuiv);
 
+   /* GL_ARB_clip_control */
+   SET_ClipControl(table, save_ClipControl);
+
/* GL_ARB_color_buffer_float */
SET_ClampColor(table, save_ClampColorARB);
 
diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
index f0e2f89..15d66a7 100644
--- a/src/mesa/main/extensions.c
+++ b/src/mesa/main/extensions.c
@@ -91,6 +91,7 @@ static const struct extension extension_table[] = {
{ "GL_ARB_buffer_storage",  o(ARB_buffer_storage),  
GL, 2013 },
{ "GL_ARB_clear_buffer_object", o(dummy_true),  
GL, 2012 },
{ "GL_ARB_clear_texture",   o(ARB_clear_texture),   
GL, 2013 },
+   { "GL_ARB_clip_control",o(ARB_clip_control),
GL, 2014 },
{ "GL_ARB_color_buffer_float",  o(ARB_color_buffer_float),  
GL, 2004 },
{ "GL_ARB_compressed_texture_pixel_storage",o(dummy_true),  
GL, 2011 },
{ "GL_ARB_compute_shader",  o(ARB_compute_shader),  
GL, 2012 },
diff --git a/src/mesa/main/get_hash_params.py b/src/mesa/main/get_hash_params.py
index da35684..ed1f390 100644
--- a/src/mesa/main/get_hash_params.py
+++ b/src/mesa/main/get_hash_params.py
@@ -414,6 +414,8 @@ descriptor=[
   [ "AUX_BUFFERS", "BUFFER_INT(Visual.numAuxBuffers), NO_EXTRA" ],
   [ "BLUE_BIAS", "CONTEXT_FLOAT(Pixel.BlueBias), NO_EXTRA" ],
   [ "BLUE_SCALE", "CONTEXT_FLOAT(Pixel.BlueScale), NO_EXTRA" ],
+  [ "CLIP_DEPTH_MODE", "CONTEXT_ENUM(ClipControl.Depth), NO_EXTRA" ],
+  [ "CLIP_ORIGIN", "CONTEXT_ENUM(ClipControl.Origin), NO_EXTRA" ],
   [ "

[Mesa-dev] [PATCH 4/5] gallium: introduce PIPE_CAP_CLIP_HALFZ.

2014-10-22 Thread Mathias . Froehlich
From: Mathias Fröhlich 

In preparation of ARB_clip_control. Let the driver decide if
it supports pipe_rasterizer_state::clip_halfz being set to true.

Signed-off-by: Mathias Froehlich http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 3/5] mesa: Handle clip control in meta operations.

2014-10-22 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Restore clip control to the default state if MESA_META_VIEWPORT
or MESA_META_DEPTH_TEST is requested.

Signed-off-by: Mathias Froehlich 
---
 src/mesa/drivers/common/meta.c | 13 +
 src/mesa/drivers/common/meta.h |  4 
 2 files changed, 17 insertions(+)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 7a8e627..119f327 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -494,6 +494,13 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
   _mesa_set_enable(ctx, GL_DITHER, GL_TRUE);
}
 
+   if (state & MESA_META_CLIP_CONTROL) {
+  save->ClipControl = ctx->ClipControl;
+  if (ctx->ClipControl.Origin != GL_LOWER_LEFT ||
+  ctx->ClipControl.Depth != GL_NEGATIVE_ONE_TO_ONE)
+ _mesa_ClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
+   }
+
if (state & MESA_META_COLOR_MASK) {
   memcpy(save->ColorMask, ctx->Color.ColorMask,
  sizeof(ctx->Color.ColorMask));
@@ -856,6 +863,12 @@ _mesa_meta_end(struct gl_context *ctx)
if (state & MESA_META_DITHER)
   _mesa_set_enable(ctx, GL_DITHER, save->DitherFlag);
 
+   if (state & MESA_META_CLIP_CONTROL) {
+  if (ctx->ClipControl.Origin != save->ClipControl.Origin ||
+  ctx->ClipControl.Depth != save->ClipControl.Depth)
+ _mesa_ClipControl(save->ClipControl.Origin, save->ClipControl.Depth);
+   }
+
if (state & MESA_META_COLOR_MASK) {
   GLuint i;
   for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h
index 2c9517b..08514ad 100644
--- a/src/mesa/drivers/common/meta.h
+++ b/src/mesa/drivers/common/meta.h
@@ -60,6 +60,7 @@
 #define MESA_META_OCCLUSION_QUERY  0x40
 #define MESA_META_DRAW_BUFFERS 0x80
 #define MESA_META_DITHER  0x100
+#define MESA_META_CLIP_CONTROL(MESA_META_VIEWPORT|MESA_META_DEPTH_TEST)
 /**\}*/
 
 /**
@@ -88,6 +89,9 @@ struct save_state
/** MESA_META_DITHER */
GLboolean DitherFlag;
 
+   /** MESA_META_CLIP_CONTROL */
+   struct gl_clip_control ClipControl;
+
/** MESA_META_COLOR_MASK */
GLubyte ColorMask[MAX_DRAW_BUFFERS][4];
 
-- 
1.9.3

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


[Mesa-dev] [PATCH 0/5] Implement clip control v2

2014-10-22 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi,

The next approach to bring decent depth buffer precision to mesa.

The patch series implements ARB_clip_control in mesa and enables the
extension for the gallium drivers.

v2:
Only enable on those gallium drivers that already support clip_halfz.

Please review.

Greetings
Mathias


Mathias Fröhlich (5):
  mesa: Refactor viewport transform computation.
  mesa: Implement ARB_clip_control.
  mesa: Handle clip control in meta operations.
  gallium: introduce PIPE_CAP_CLIP_HALFZ.
  gallium: Enable ARB_clip_control for gallium drivers.

 docs/GL3.txt |   2 +-
 docs/relnotes/10.4.html  |   1 +
 src/gallium/docs/source/screen.rst   |   3 +
 src/gallium/drivers/freedreno/freedreno_screen.c |   1 +
 src/gallium/drivers/i915/i915_screen.c   |   1 +
 src/gallium/drivers/ilo/ilo_screen.c |   1 +
 src/gallium/drivers/llvmpipe/lp_screen.c |   2 +
 src/gallium/drivers/nouveau/nv30/nv30_screen.c   |   1 +
 src/gallium/drivers/nouveau/nv50/nv50_screen.c   |   1 +
 src/gallium/drivers/nouveau/nvc0/nvc0_screen.c   |   1 +
 src/gallium/drivers/r300/r300_screen.c   |   1 +
 src/gallium/drivers/r600/r600_pipe.c |   1 +
 src/gallium/drivers/radeonsi/si_pipe.c   |   1 +
 src/gallium/drivers/softpipe/sp_screen.c |   2 +
 src/gallium/drivers/svga/svga_screen.c   |   1 +
 src/gallium/drivers/vc4/vc4_screen.c |   1 +
 src/gallium/include/pipe/p_defines.h |   1 +
 src/mapi/glapi/gen/ARB_clip_control.xml  |  25 +
 src/mapi/glapi/gen/gl_API.xml|   4 +-
 src/mesa/drivers/common/meta.c   |  13 +++
 src/mesa/drivers/common/meta.h   |   4 +
 src/mesa/drivers/dri/i915/i915_state.c   |  26 ++---
 src/mesa/main/dlist.c|  26 +
 src/mesa/main/extensions.c   |   1 +
 src/mesa/main/get_hash_params.py |   2 +
 src/mesa/main/mtypes.h   |  12 +++
 src/mesa/main/polygon.c  |   5 +-
 src/mesa/main/state.c|   9 +-
 src/mesa/main/tests/dispatch_sanity.cpp  |   3 +
 src/mesa/main/viewport.c | 118 ---
 src/mesa/main/viewport.h |   6 ++
 src/mesa/math/m_matrix.c |  17 ++--
 src/mesa/math/m_matrix.h |   4 +-
 src/mesa/state_tracker/st_atom_rasterizer.c  |  14 ++-
 src/mesa/state_tracker/st_atom_viewport.c|  23 ++---
 src/mesa/state_tracker/st_extensions.c   |   5 +
 36 files changed, 274 insertions(+), 65 deletions(-)
 create mode 100644 src/mapi/glapi/gen/ARB_clip_control.xml

-- 
1.9.3

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


[Mesa-dev] [PATCH 1/5] mesa: Refactor viewport transform computation.

2014-10-22 Thread Mathias . Froehlich
From: Mathias Fröhlich 

This is for preparation of ARB_clip_control.

Signed-off-by: Mathias Froehlich 
---
 src/mesa/drivers/dri/i915/i915_state.c| 26 ++---
 src/mesa/main/state.c |  9 +++---
 src/mesa/main/viewport.c  | 47 ---
 src/mesa/main/viewport.h  |  3 ++
 src/mesa/math/m_matrix.c  | 17 ++-
 src/mesa/math/m_matrix.h  |  4 +--
 src/mesa/state_tracker/st_atom_viewport.c | 23 +++
 7 files changed, 68 insertions(+), 61 deletions(-)

diff --git a/src/mesa/drivers/dri/i915/i915_state.c 
b/src/mesa/drivers/dri/i915/i915_state.c
index f31b271..f9aecba 100644
--- a/src/mesa/drivers/dri/i915/i915_state.c
+++ b/src/mesa/drivers/dri/i915/i915_state.c
@@ -34,6 +34,7 @@
 #include "main/dd.h"
 #include "main/state.h"
 #include "main/stencil.h"
+#include "main/viewport.h"
 #include "tnl/tnl.h"
 #include "tnl/t_context.h"
 
@@ -401,26 +402,17 @@ void
 intelCalcViewport(struct gl_context * ctx)
 {
struct intel_context *intel = intel_context(ctx);
+   double scale[3], translate[3];
+
+   _mesa_get_viewport_xform(ctx, 0, scale, translate);
 
if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
-  _math_matrix_viewport(&intel->ViewportMatrix,
-   ctx->ViewportArray[0].X,
-   ctx->DrawBuffer->Height - ctx->ViewportArray[0].Y,
-   ctx->ViewportArray[0].Width,
-   -ctx->ViewportArray[0].Height,
-   ctx->ViewportArray[0].Near,
-   ctx->ViewportArray[0].Far,
-   1.0);
-   } else {
-  _math_matrix_viewport(&intel->ViewportMatrix,
-   ctx->ViewportArray[0].X,
-   ctx->ViewportArray[0].Y,
-   ctx->ViewportArray[0].Width,
-   ctx->ViewportArray[0].Height,
-   ctx->ViewportArray[0].Near,
-   ctx->ViewportArray[0].Far,
-   1.0);
+  scale[1] = -scale[1];
+  translate[1] = ctx->DrawBuffer->Height - translate[1];
}
+
+   _math_matrix_viewport(&intel->ViewportMatrix,
+ scale, translate, 1.0);
 }
 
 
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index 80287c4..3dbbfaa 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -51,6 +51,7 @@
 #include "texobj.h"
 #include "texstate.h"
 #include "varray.h"
+#include "viewport.h"
 #include "blend.h"
 
 
@@ -281,11 +282,11 @@ update_viewport_matrix(struct gl_context *ctx)
 * NOTE: RasterPos uses this.
 */
for (i = 0; i < ctx->Const.MaxViewports; i++) {
+  double scale[3], translate[3];
+
+  _mesa_get_viewport_xform(ctx, i, scale, translate);
   _math_matrix_viewport(&ctx->ViewportArray[i]._WindowMap,
-ctx->ViewportArray[i].X, ctx->ViewportArray[i].Y,
-ctx->ViewportArray[i].Width, 
ctx->ViewportArray[i].Height,
-ctx->ViewportArray[i].Near, 
ctx->ViewportArray[i].Far,
-depthMax);
+scale, translate, depthMax);
}
 }
 
diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c
index 222ae30..89766cf 100644
--- a/src/mesa/main/viewport.c
+++ b/src/mesa/main/viewport.c
@@ -39,6 +39,8 @@ set_viewport_no_notify(struct gl_context *ctx, unsigned idx,
GLfloat x, GLfloat y,
GLfloat width, GLfloat height)
 {
+   double scale[3], translate[3];
+
/* clamp width and height to the implementation dependent range */
width  = MIN2(width, (GLfloat) ctx->Const.MaxViewportWidth);
height = MIN2(height, (GLfloat) ctx->Const.MaxViewportHeight);
@@ -75,14 +77,9 @@ set_viewport_no_notify(struct gl_context *ctx, unsigned idx,
 * the WindowMap matrix being up to date in the driver's Viewport
 * and DepthRange functions.
 */
+   _mesa_get_viewport_xform(ctx, idx, scale, translate);
_math_matrix_viewport(&ctx->ViewportArray[idx]._WindowMap,
- ctx->ViewportArray[idx].X,
- ctx->ViewportArray[idx].Y,
- ctx->ViewportArray[idx].Width,
- ctx->ViewportArray[idx].Height,
- ctx->ViewportArray[idx].Near,
- ctx->ViewportArray[idx].Far,
- ctx->DrawBuffer->_DepthMaxF);
+ scale, translate, ctx->DrawBuffer->_DepthMaxF);
 #endif
 }
 
@@ -248,6 +245,8 @@ static void
 set_depth_range_no_notify(struct gl

[Mesa-dev] [PATCH 1/5] mesa: Refactor viewport transform computation.

2014-10-24 Thread Mathias . Froehlich
From: Mathias Fröhlich 

This is for preparation of ARB_clip_control.

v3:
Add comments.

Signed-off-by: Mathias Froehlich 
---
 src/mesa/drivers/dri/i915/i915_state.c| 26 ++--
 src/mesa/main/state.c |  9 +++---
 src/mesa/main/viewport.c  | 52 +--
 src/mesa/main/viewport.h  |  3 ++
 src/mesa/math/m_matrix.c  | 17 +-
 src/mesa/math/m_matrix.h  |  4 +--
 src/mesa/state_tracker/st_atom_viewport.c | 23 ++
 7 files changed, 73 insertions(+), 61 deletions(-)

diff --git a/src/mesa/drivers/dri/i915/i915_state.c 
b/src/mesa/drivers/dri/i915/i915_state.c
index f31b271..f9aecba 100644
--- a/src/mesa/drivers/dri/i915/i915_state.c
+++ b/src/mesa/drivers/dri/i915/i915_state.c
@@ -34,6 +34,7 @@
 #include "main/dd.h"
 #include "main/state.h"
 #include "main/stencil.h"
+#include "main/viewport.h"
 #include "tnl/tnl.h"
 #include "tnl/t_context.h"
 
@@ -401,26 +402,17 @@ void
 intelCalcViewport(struct gl_context * ctx)
 {
struct intel_context *intel = intel_context(ctx);
+   double scale[3], translate[3];
+
+   _mesa_get_viewport_xform(ctx, 0, scale, translate);
 
if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
-  _math_matrix_viewport(&intel->ViewportMatrix,
-   ctx->ViewportArray[0].X,
-   ctx->DrawBuffer->Height - ctx->ViewportArray[0].Y,
-   ctx->ViewportArray[0].Width,
-   -ctx->ViewportArray[0].Height,
-   ctx->ViewportArray[0].Near,
-   ctx->ViewportArray[0].Far,
-   1.0);
-   } else {
-  _math_matrix_viewport(&intel->ViewportMatrix,
-   ctx->ViewportArray[0].X,
-   ctx->ViewportArray[0].Y,
-   ctx->ViewportArray[0].Width,
-   ctx->ViewportArray[0].Height,
-   ctx->ViewportArray[0].Near,
-   ctx->ViewportArray[0].Far,
-   1.0);
+  scale[1] = -scale[1];
+  translate[1] = ctx->DrawBuffer->Height - translate[1];
}
+
+   _math_matrix_viewport(&intel->ViewportMatrix,
+ scale, translate, 1.0);
 }
 
 
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index 80287c4..3dbbfaa 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -51,6 +51,7 @@
 #include "texobj.h"
 #include "texstate.h"
 #include "varray.h"
+#include "viewport.h"
 #include "blend.h"
 
 
@@ -281,11 +282,11 @@ update_viewport_matrix(struct gl_context *ctx)
 * NOTE: RasterPos uses this.
 */
for (i = 0; i < ctx->Const.MaxViewports; i++) {
+  double scale[3], translate[3];
+
+  _mesa_get_viewport_xform(ctx, i, scale, translate);
   _math_matrix_viewport(&ctx->ViewportArray[i]._WindowMap,
-ctx->ViewportArray[i].X, ctx->ViewportArray[i].Y,
-ctx->ViewportArray[i].Width, 
ctx->ViewportArray[i].Height,
-ctx->ViewportArray[i].Near, 
ctx->ViewportArray[i].Far,
-depthMax);
+scale, translate, depthMax);
}
 }
 
diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c
index 222ae30..afc813d 100644
--- a/src/mesa/main/viewport.c
+++ b/src/mesa/main/viewport.c
@@ -39,6 +39,8 @@ set_viewport_no_notify(struct gl_context *ctx, unsigned idx,
GLfloat x, GLfloat y,
GLfloat width, GLfloat height)
 {
+   double scale[3], translate[3];
+
/* clamp width and height to the implementation dependent range */
width  = MIN2(width, (GLfloat) ctx->Const.MaxViewportWidth);
height = MIN2(height, (GLfloat) ctx->Const.MaxViewportHeight);
@@ -75,14 +77,9 @@ set_viewport_no_notify(struct gl_context *ctx, unsigned idx,
 * the WindowMap matrix being up to date in the driver's Viewport
 * and DepthRange functions.
 */
+   _mesa_get_viewport_xform(ctx, idx, scale, translate);
_math_matrix_viewport(&ctx->ViewportArray[idx]._WindowMap,
- ctx->ViewportArray[idx].X,
- ctx->ViewportArray[idx].Y,
- ctx->ViewportArray[idx].Width,
- ctx->ViewportArray[idx].Height,
- ctx->ViewportArray[idx].Near,
- ctx->ViewportArray[idx].Far,
- ctx->DrawBuffer->_DepthMaxF);
+ scale, translate, ctx->DrawBuffer->_DepthMaxF);
 #endif
 }
 
@@ -248,6 +245,8 @@ static void
 set_depth_range_

[Mesa-dev] [PATCH 5/5] gallium: Enable ARB_clip_control for gallium drivers.

2014-10-24 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Gallium should be prepared fine for ARB_clip_control.
So enable this and mention it in the release notes.

v2:
Only enable for drivers announcing the freshly introduced
PIPE_CAP_CLIP_HALFZ capability.

v3:
Use extension enable infrastructure to connect PIPE_CAP_CLIP_HALFZ
with ARB_clip_control.

Signed-off-by: Mathias Froehlich 
---
 docs/GL3.txt|  2 +-
 docs/relnotes/10.4.html |  1 +
 src/mesa/state_tracker/st_atom_rasterizer.c | 14 +-
 src/mesa/state_tracker/st_extensions.c  |  1 +
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/docs/GL3.txt b/docs/GL3.txt
index 07d1d2c..6a988d5 100644
--- a/docs/GL3.txt
+++ b/docs/GL3.txt
@@ -187,7 +187,7 @@ GL 4.4, GLSL 4.40:
 GL 4.5, GLSL 4.50:
 
   GL_ARB_ES3_1_compatibility   not started
-  GL_ARB_clip_control  not started
+  GL_ARB_clip_control  DONE (llvmpipe, 
softpipe, r300, r600, radeonsi)
   GL_ARB_conditional_render_inverted   DONE (i965, nvc0, 
llvmpipe, softpipe)
   GL_ARB_cull_distance not started
   GL_ARB_derivative_controlDONE (i965, nv50, nvc0, 
r600)
diff --git a/docs/relnotes/10.4.html b/docs/relnotes/10.4.html
index 64cbfae..67c3087 100644
--- a/docs/relnotes/10.4.html
+++ b/docs/relnotes/10.4.html
@@ -46,6 +46,7 @@ Note: some of the new features are only available with 
certain drivers.
 
 GL_ARB_sample_shading on r600
 GL_ARB_texture_view on nv50, nvc0
+GL_ARB_clip_control on llvmpipe, softpipe, r300, r600, radeonsi
 
 
 
diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c 
b/src/mesa/state_tracker/st_atom_rasterizer.c
index dfa728b..2f0886e 100644
--- a/src/mesa/state_tracker/st_atom_rasterizer.c
+++ b/src/mesa/state_tracker/st_atom_rasterizer.c
@@ -72,6 +72,11 @@ static void update_raster_state( struct st_context *st )
{
   raster->front_ccw = (ctx->Polygon.FrontFace == GL_CCW);
 
+  /* _NEW_VIEWPORT */
+  if (ctx->Transform.Origin == GL_UPPER_LEFT) {
+ raster->front_ccw ^= 1;
+  }
+
   /*
* Gallium's surfaces are Y=0=TOP orientation.  OpenGL is the
* opposite.  Window system surfaces are Y=0=TOP.  Mesa's FBOs
@@ -241,6 +246,12 @@ static void update_raster_state( struct st_context *st )
raster->half_pixel_center = 1;
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP)
   raster->bottom_edge_rule = 1;
+   /* _NEW_VIEWPORT */
+   if (ctx->Transform.Origin == GL_UPPER_LEFT)
+  raster->bottom_edge_rule ^= 1;
+
+   /* _NEW_VIEWPORT */
+   raster->clip_halfz = (ctx->Transform.Depth == GL_ZERO_TO_ONE);
 
/* ST_NEW_RASTERIZER */
raster->rasterizer_discard = ctx->RasterDiscard;
@@ -272,7 +283,8 @@ const struct st_tracked_state st_update_rasterizer = {
_NEW_PROGRAM |
_NEW_SCISSOR |
_NEW_FRAG_CLAMP |
-   _NEW_TRANSFORM),  /* mesa state dependencies*/
+   _NEW_TRANSFORM |
+   _NEW_VIEWPORT),  /* mesa state dependencies*/
   (ST_NEW_VERTEX_PROGRAM |
ST_NEW_RASTERIZER),  /* state tracker dependencies */
},
diff --git a/src/mesa/state_tracker/st_extensions.c 
b/src/mesa/state_tracker/st_extensions.c
index 78bfe30..aff3dde 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -463,6 +463,7 @@ void st_init_extensions(struct pipe_screen *screen,
   { o(ARB_derivative_control),   PIPE_CAP_TGSI_FS_FINE_DERIVATIVE  
},
   { o(ARB_conditional_render_inverted),  
PIPE_CAP_CONDITIONAL_RENDER_INVERTED  },
   { o(ARB_texture_view), PIPE_CAP_SAMPLER_VIEW_TARGET  
},
+  { o(ARB_clip_control), PIPE_CAP_CLIP_HALFZ   
},
};
 
/* Required: render target and sampler support */
-- 
1.9.3

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


[Mesa-dev] [PATCH 0/5] Implement clip control v3

2014-10-24 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi,

The next approach to bring decent depth buffer precision to mesa.

The patch series implements ARB_clip_control in mesa and enables the
extension for the gallium drivers.

v2:
Only enable on those gallium drivers that already support clip_halfz.

v3:
Add more comments.
Restrict getting clip control state to the availability
of ARB_clip_control.
Move to transformation state.
Handle clip control state with the GL_TRANSFORM_BIT.
Move _FrontBit update into state.c.
Handle clip control state with MESA_META_TRANSFORM.
Initially enable on ilo.
Use extension enable infrastructure to connect PIPE_CAP_CLIP_HALFZ
with ARB_clip_control.

Please review.

Greetings
Mathias

Mathias Fröhlich (5):
  mesa: Refactor viewport transform computation.
  mesa: Implement ARB_clip_control.
  mesa: Handle clip control in meta operations.
  gallium: introduce PIPE_CAP_CLIP_HALFZ.
  gallium: Enable ARB_clip_control for gallium drivers.

 docs/GL3.txt |   2 +-
 docs/relnotes/10.4.html  |   1 +
 src/gallium/docs/source/screen.rst   |   3 +
 src/gallium/drivers/freedreno/freedreno_screen.c |   1 +
 src/gallium/drivers/i915/i915_screen.c   |   1 +
 src/gallium/drivers/ilo/ilo_screen.c |   2 +
 src/gallium/drivers/llvmpipe/lp_screen.c |   2 +
 src/gallium/drivers/nouveau/nv30/nv30_screen.c   |   1 +
 src/gallium/drivers/nouveau/nv50/nv50_screen.c   |   1 +
 src/gallium/drivers/nouveau/nvc0/nvc0_screen.c   |   1 +
 src/gallium/drivers/r300/r300_screen.c   |   1 +
 src/gallium/drivers/r600/r600_pipe.c |   1 +
 src/gallium/drivers/radeonsi/si_pipe.c   |   1 +
 src/gallium/drivers/softpipe/sp_screen.c |   2 +
 src/gallium/drivers/svga/svga_screen.c   |   1 +
 src/gallium/drivers/vc4/vc4_screen.c |   1 +
 src/gallium/include/pipe/p_defines.h |   1 +
 src/mapi/glapi/gen/ARB_clip_control.xml  |  25 +
 src/mapi/glapi/gen/gl_API.xml|   4 +-
 src/mesa/drivers/common/meta.c   |   6 ++
 src/mesa/drivers/common/meta.h   |   2 +
 src/mesa/drivers/dri/i915/i915_state.c   |  26 ++---
 src/mesa/main/attrib.c   |   1 +
 src/mesa/main/dlist.c|  26 +
 src/mesa/main/extensions.c   |   1 +
 src/mesa/main/get.c  |   1 +
 src/mesa/main/get_hash_params.py |   2 +
 src/mesa/main/mtypes.h   |   3 +
 src/mesa/main/polygon.c  |   2 -
 src/mesa/main/state.c|  25 -
 src/mesa/main/tests/dispatch_sanity.cpp  |   3 +
 src/mesa/main/viewport.c | 122 ---
 src/mesa/main/viewport.h |   6 ++
 src/mesa/math/m_matrix.c |  17 ++--
 src/mesa/math/m_matrix.h |   4 +-
 src/mesa/state_tracker/st_atom_rasterizer.c  |  14 ++-
 src/mesa/state_tracker/st_atom_viewport.c|  23 ++---
 src/mesa/state_tracker/st_extensions.c   |   1 +
 38 files changed, 271 insertions(+), 66 deletions(-)
 create mode 100644 src/mapi/glapi/gen/ARB_clip_control.xml

-- 
1.9.3

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


[Mesa-dev] [PATCH 4/5] gallium: introduce PIPE_CAP_CLIP_HALFZ.

2014-10-24 Thread Mathias . Froehlich
From: Mathias Fröhlich 

In preparation of ARB_clip_control. Let the driver decide if
it supports pipe_rasterizer_state::clip_halfz being set to true.

v3:
Initially enable on ilo.

Signed-off-by: Mathias Froehlich http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/5] mesa: Implement ARB_clip_control.

2014-10-24 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Implement the mesa parts of ARB_clip_control.
So far no driver enables this.

v3:
Restrict getting clip control state to the availability
of ARB_clip_control.
Move to transformation state.
Handle clip control state with the GL_TRANSFORM_BIT.
Move _FrontBit update into state.c.

Signed-off-by: Mathias Froehlich 
---
 src/mapi/glapi/gen/ARB_clip_control.xml | 25 +++
 src/mapi/glapi/gen/gl_API.xml   |  4 +-
 src/mesa/main/attrib.c  |  1 +
 src/mesa/main/dlist.c   | 26 +++
 src/mesa/main/extensions.c  |  1 +
 src/mesa/main/get.c |  1 +
 src/mesa/main/get_hash_params.py|  2 +
 src/mesa/main/mtypes.h  |  3 ++
 src/mesa/main/polygon.c |  2 -
 src/mesa/main/state.c   | 16 +++
 src/mesa/main/tests/dispatch_sanity.cpp |  3 ++
 src/mesa/main/viewport.c| 78 +++--
 src/mesa/main/viewport.h|  3 ++
 13 files changed, 158 insertions(+), 7 deletions(-)
 create mode 100644 src/mapi/glapi/gen/ARB_clip_control.xml

diff --git a/src/mapi/glapi/gen/ARB_clip_control.xml 
b/src/mapi/glapi/gen/ARB_clip_control.xml
new file mode 100644
index 000..2973a31
--- /dev/null
+++ b/src/mapi/glapi/gen/ARB_clip_control.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
index 73f2f75..534e6a0 100644
--- a/src/mapi/glapi/gen/gl_API.xml
+++ b/src/mapi/glapi/gen/gl_API.xml
@@ -8364,7 +8364,9 @@
 
 http://www.w3.org/2001/XInclude"/>
 
-
+
+
+http://www.w3.org/2001/XInclude"/>
 
 
 
diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index d90e662..55ce462 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -1345,6 +1345,7 @@ _mesa_PopAttrib(void)
if (xform->DepthClamp != ctx->Transform.DepthClamp)
   _mesa_set_enable(ctx, GL_DEPTH_CLAMP,
ctx->Transform.DepthClamp);
+   _mesa_ClipControl(xform->Origin, xform->Depth);
 }
 break;
  case GL_TEXTURE_BIT:
diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c
index 5c7160d..4b7b060 100644
--- a/src/mesa/main/dlist.c
+++ b/src/mesa/main/dlist.c
@@ -398,6 +398,9 @@ typedef enum
OPCODE_PROGRAM_UNIFORM_MATRIX34F,
OPCODE_PROGRAM_UNIFORM_MATRIX43F,
 
+   /* GL_ARB_clip_control */
+   OPCODE_CLIP_CONTROL,
+
/* GL_ARB_color_buffer_float */
OPCODE_CLAMP_COLOR,
 
@@ -7208,6 +7211,22 @@ save_ProgramUniformMatrix4fv(GLuint program, GLint 
location, GLsizei count,
 }
 
 static void GLAPIENTRY
+save_ClipControl(GLenum origin, GLenum depth)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   Node *n;
+   ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
+   n = alloc_instruction(ctx, OPCODE_CLIP_CONTROL, 2);
+   if (n) {
+  n[1].e = origin;
+  n[2].e = depth;
+   }
+   if (ctx->ExecuteFlag) {
+  CALL_ClipControl(ctx->Exec, (origin, depth));
+   }
+}
+
+static void GLAPIENTRY
 save_ClampColorARB(GLenum target, GLenum clamp)
 {
GET_CURRENT_CONTEXT(ctx);
@@ -8617,6 +8636,10 @@ execute_list(struct gl_context *ctx, GLuint list)
   get_pointer(&n[5])));
 break;
 
+ case OPCODE_CLIP_CONTROL:
+CALL_ClipControl(ctx->Exec, (n[1].e, n[2].e));
+break;
+
  case OPCODE_CLAMP_COLOR:
 CALL_ClampColor(ctx->Exec, (n[1].e, n[2].e));
 break;
@@ -9551,6 +9574,9 @@ _mesa_initialize_save_table(const struct gl_context *ctx)
SET_TexParameterIiv(table, save_TexParameterIiv);
SET_TexParameterIuiv(table, save_TexParameterIuiv);
 
+   /* GL_ARB_clip_control */
+   SET_ClipControl(table, save_ClipControl);
+
/* GL_ARB_color_buffer_float */
SET_ClampColor(table, save_ClampColorARB);
 
diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
index f0e2f89..15d66a7 100644
--- a/src/mesa/main/extensions.c
+++ b/src/mesa/main/extensions.c
@@ -91,6 +91,7 @@ static const struct extension extension_table[] = {
{ "GL_ARB_buffer_storage",  o(ARB_buffer_storage),  
GL, 2013 },
{ "GL_ARB_clear_buffer_object", o(dummy_true),  
GL, 2012 },
{ "GL_ARB_clear_texture",   o(ARB_clear_texture),   
GL, 2013 },
+   { "GL_ARB_clip_control",o(ARB_clip_control),
GL, 2014 },
{ "GL_ARB_color_buffer_float",  o(ARB_color_buffer_float),  
GL, 2004 },
{ "GL_ARB_compressed_texture_pixel_storage",o(dummy_true), 

[Mesa-dev] [PATCH 3/5] mesa: Handle clip control in meta operations.

2014-10-24 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Restore clip control to the default state if MESA_META_VIEWPORT
or MESA_META_DEPTH_TEST is requested.

v3:
Handle clip control state with MESA_META_TRANSFORM.

Signed-off-by: Mathias Froehlich 
---
 src/mesa/drivers/common/meta.c | 6 ++
 src/mesa/drivers/common/meta.h | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 7a8e627..ebb6f5c 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -680,6 +680,10 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
  _mesa_Ortho(0.0, ctx->DrawBuffer->Width,
  0.0, ctx->DrawBuffer->Height,
  -1.0, 1.0);
+
+  save->ClipControlOrigin = ctx->Transform.Origin;
+  save->ClipControlDepth = ctx->Transform.Depth;
+  _mesa_ClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
}
 
if (state & MESA_META_CLIP) {
@@ -1081,6 +1085,8 @@ _mesa_meta_end(struct gl_context *ctx)
   _mesa_LoadMatrixf(save->ProjectionMatrix);
 
   _mesa_MatrixMode(save->MatrixMode);
+
+  _mesa_ClipControl(save->ClipControlOrigin, save->ClipControlDepth);
}
 
if (state & MESA_META_CLIP) {
diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h
index 2c9517b..596a0d9 100644
--- a/src/mesa/drivers/common/meta.h
+++ b/src/mesa/drivers/common/meta.h
@@ -136,6 +136,8 @@ struct save_state
GLfloat ModelviewMatrix[16];
GLfloat ProjectionMatrix[16];
GLfloat TextureMatrix[16];
+   GLenum ClipControlOrigin;
+   GLenum ClipControlDepth;
 
/** MESA_META_CLIP */
GLbitfield ClipPlanesEnabled;
-- 
1.9.3

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


[Mesa-dev] [PATCH] glx: Fix make check.

2014-10-24 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Fixes the link failures with make check.

Ok to commit?

Signed-off-by: Mathias Froehlich 
CC: Ian Romanick 
---
 src/glx/tests/indirect_api.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/glx/tests/indirect_api.cpp b/src/glx/tests/indirect_api.cpp
index 52469a7..cf33764 100644
--- a/src/glx/tests/indirect_api.cpp
+++ b/src/glx/tests/indirect_api.cpp
@@ -704,6 +704,7 @@ void __indirect_glIsRenderbuffer(void) { }
 void __indirect_glRenderbufferStorage(void) { }
 void __indirect_glBlitFramebuffer(void) { }
 void __indirect_glFramebufferTextureLayer(void) { }
+void __indirect_glClipControl(void) { }
 }
 /*@}*/
 
-- 
1.9.3

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


[Mesa-dev] [PATCH] mesa: Add ARB_clip_control.xml to automake.

2014-10-25 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi,

Adding this makes 'make check' catch failures introduced from
within ARB_clip_control.xml earlier.

Ok to commit?
Mathias

Signed-off-by: Mathias Froehlich 
---
 src/mapi/glapi/gen/Makefile.am | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/mapi/glapi/gen/Makefile.am b/src/mapi/glapi/gen/Makefile.am
index 2fbc598..72e5095 100644
--- a/src/mapi/glapi/gen/Makefile.am
+++ b/src/mapi/glapi/gen/Makefile.am
@@ -113,6 +113,7 @@ API_XML = \
ARB_blend_func_extended.xml \
ARB_clear_buffer_object.xml \
ARB_clear_texture.xml \
+   ARB_clip_control.xml \
ARB_color_buffer_float.xml \
ARB_compressed_texture_pixel_storage.xml \
ARB_compute_shader.xml \
-- 
1.9.3

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


[Mesa-dev] [PATCH] mesa/gallium: Signal _NEW_TRANSFORM from glClipControl.

2014-10-25 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi Marek,

Did you have something like below in mind?

Mathias


This removes the need for the gallium rasterizer state
to listen to viewport changes.
Thanks to Marek Olšák .

CC: Marek Olšák 
Signed-off-by: Mathias Froehlich 
---
 src/mesa/main/viewport.c|  8 ++--
 src/mesa/state_tracker/st_atom_rasterizer.c | 11 ---
 2 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c
index d6a9e29..0adce9c 100644
--- a/src/mesa/main/viewport.c
+++ b/src/mesa/main/viewport.c
@@ -459,15 +459,14 @@ _mesa_ClipControl(GLenum origin, GLenum depth)
ctx->Transform.ClipDepthMode == depth)
   return;
 
-   FLUSH_VERTICES(ctx, 0);
+   /* Affects transform state and the viewport transform */
+   FLUSH_VERTICES(ctx, _NEW_TRANSFORM | _NEW_VIEWPORT);
 
if (ctx->Transform.ClipOrigin != origin) {
   ctx->Transform.ClipOrigin = origin;
 
   /* Affects the winding order of the front face. */
   ctx->NewState |= _NEW_POLYGON;
-  /* Affects the y component of the viewport transform. */
-  ctx->NewState |= _NEW_VIEWPORT;
 
   if (ctx->Driver.FrontFace)
  ctx->Driver.FrontFace(ctx, ctx->Polygon.FrontFace);
@@ -476,9 +475,6 @@ _mesa_ClipControl(GLenum origin, GLenum depth)
if (ctx->Transform.ClipDepthMode != depth) {
   ctx->Transform.ClipDepthMode = depth;
 
-  /* Affects the z part of the viewpoint transform. */
-  ctx->NewState |= _NEW_VIEWPORT;
-
   if (ctx->Driver.DepthRange)
  ctx->Driver.DepthRange(ctx);
}
diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c 
b/src/mesa/state_tracker/st_atom_rasterizer.c
index 5020978..606f19a 100644
--- a/src/mesa/state_tracker/st_atom_rasterizer.c
+++ b/src/mesa/state_tracker/st_atom_rasterizer.c
@@ -72,7 +72,7 @@ static void update_raster_state( struct st_context *st )
{
   raster->front_ccw = (ctx->Polygon.FrontFace == GL_CCW);
 
-  /* _NEW_VIEWPORT */
+  /* _NEW_TRANSFORM */
   if (ctx->Transform.ClipOrigin == GL_UPPER_LEFT) {
  raster->front_ccw ^= 1;
   }
@@ -246,13 +246,10 @@ static void update_raster_state( struct st_context *st )
raster->half_pixel_center = 1;
if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP)
   raster->bottom_edge_rule = 1;
-   /* _NEW_VIEWPORT */
+   /* _NEW_TRANSFORM */
if (ctx->Transform.ClipOrigin == GL_UPPER_LEFT)
   raster->bottom_edge_rule ^= 1;
 
-   /* _NEW_VIEWPORT */
-   raster->clip_halfz = (ctx->Transform.ClipDepthMode == GL_ZERO_TO_ONE);
-
/* ST_NEW_RASTERIZER */
raster->rasterizer_discard = ctx->RasterDiscard;
 
@@ -267,6 +264,7 @@ static void update_raster_state( struct st_context *st )
/* _NEW_TRANSFORM */
raster->depth_clip = !ctx->Transform.DepthClamp;
raster->clip_plane_enable = ctx->Transform.ClipPlanesEnabled;
+   raster->clip_halfz = (ctx->Transform.ClipDepthMode == GL_ZERO_TO_ONE);
 
cso_set_rasterizer(st->cso_context, raster);
 }
@@ -283,8 +281,7 @@ const struct st_tracked_state st_update_rasterizer = {
_NEW_PROGRAM |
_NEW_SCISSOR |
_NEW_FRAG_CLAMP |
-   _NEW_TRANSFORM |
-   _NEW_VIEWPORT),  /* mesa state dependencies*/
+   _NEW_TRANSFORM), /* mesa state dependencies*/
   (ST_NEW_VERTEX_PROGRAM |
ST_NEW_RASTERIZER),  /* state tracker dependencies */
},
-- 
1.9.3

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


[Mesa-dev] [PATCH] i965: Implement support for ARB_clip_control.

2015-03-30 Thread Mathias . Froehlich
From: Mathias Fröhlich 

Hi,

The patch aims to implement ARB_clip_control on intel chips.
I hope to have found all places to cover all supported chipsets.
I have done some limited testing on an Ivybridge Mobile and
a GM45 Express chipset.
Please review.

Thanks

Mathias

Switch between the two clip space definitions already available
in hardware. Update winding order dependent state according
to the clip control state.
This change did not introduce new piglit quick.test regressions on
an Ivybridge Mobile and a GM45 Express chipset.
Also it enables and passes the clip-control and clip-control-depth-precision
tests on these two chipsets.

Signed-off-by: Mathias Froehlich 
---
 docs/GL3.txt | 2 +-
 docs/relnotes/10.6.0.html| 1 +
 src/mesa/drivers/dri/i965/brw_clip.c | 7 ++-
 src/mesa/drivers/dri/i965/brw_clip_state.c   | 5 -
 src/mesa/drivers/dri/i965/brw_sf.c   | 2 +-
 src/mesa/drivers/dri/i965/brw_sf_state.c | 6 +++---
 src/mesa/drivers/dri/i965/gen6_clip_state.c  | 7 +--
 src/mesa/drivers/dri/i965/gen6_sf_state.c| 2 +-
 src/mesa/drivers/dri/i965/gen7_sf_state.c| 2 +-
 src/mesa/drivers/dri/i965/gen8_sf_state.c| 2 +-
 src/mesa/drivers/dri/i965/intel_extensions.c | 1 +
 11 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/docs/GL3.txt b/docs/GL3.txt
index 3614260..6cc0087 100644
--- a/docs/GL3.txt
+++ b/docs/GL3.txt
@@ -188,7 +188,7 @@ GL 4.4, GLSL 4.40:
 GL 4.5, GLSL 4.50:
 
   GL_ARB_ES3_1_compatibility   not started
-  GL_ARB_clip_control  DONE (nv50, nvc0, r600, 
radeonsi, llvmpipe, softpipe)
+  GL_ARB_clip_control  DONE (i965, nv50, nvc0, 
r600, radeonsi, llvmpipe, softpipe)
   GL_ARB_conditional_render_inverted   DONE (i965, nv50, nvc0, 
llvmpipe, softpipe)
   GL_ARB_cull_distance not started
   GL_ARB_derivative_controlDONE (i965, nv50, nvc0, 
r600)
diff --git a/docs/relnotes/10.6.0.html b/docs/relnotes/10.6.0.html
index 005..c62d0d8 100644
--- a/docs/relnotes/10.6.0.html
+++ b/docs/relnotes/10.6.0.html
@@ -50,6 +50,7 @@ Note: some of the new features are only available with 
certain drivers.
 GL_ARB_instanced_arrays on freedreno
 GL_ARB_pipeline_statistics_query on i965, nv50, nvc0, r600, radeonsi, 
softpipe
 GL_ARB_draw_indirect, GL_ARB_multi_draw_indirect on r600
+GL_ARB_clip_control on i965
 
 
 Bug fixes
diff --git a/src/mesa/drivers/dri/i965/brw_clip.c 
b/src/mesa/drivers/dri/i965/brw_clip.c
index 3fef38c..de78f46 100644
--- a/src/mesa/drivers/dri/i965/brw_clip.c
+++ b/src/mesa/drivers/dri/i965/brw_clip.c
@@ -224,8 +224,7 @@ brw_upload_clip_prog(struct brw_context *brw)
   key.offset_factor = ctx->Polygon.OffsetFactor * 
ctx->DrawBuffer->_MRD;
}
 
-   switch (ctx->Polygon.FrontFace) {
-   case GL_CCW:
+   if (!ctx->Polygon._FrontBit) {
   key.fill_ccw = fill_front;
   key.fill_cw = fill_back;
   key.offset_ccw = offset_front;
@@ -233,8 +232,7 @@ brw_upload_clip_prog(struct brw_context *brw)
   if (ctx->Light.Model.TwoSide &&
   key.fill_cw != CLIP_CULL)
  key.copy_bfc_cw = 1;
-  break;
-   case GL_CW:
+   } else {
   key.fill_cw = fill_front;
   key.fill_ccw = fill_back;
   key.offset_cw = offset_front;
@@ -242,7 +240,6 @@ brw_upload_clip_prog(struct brw_context *brw)
   if (ctx->Light.Model.TwoSide &&
   key.fill_ccw != CLIP_CULL)
  key.copy_bfc_ccw = 1;
-  break;
}
 }
   }
diff --git a/src/mesa/drivers/dri/i965/brw_clip_state.c 
b/src/mesa/drivers/dri/i965/brw_clip_state.c
index 09a2523..385b8a4 100644
--- a/src/mesa/drivers/dri/i965/brw_clip_state.c
+++ b/src/mesa/drivers/dri/i965/brw_clip_state.c
@@ -147,7 +147,10 @@ brw_upload_clip_unit(struct brw_context *brw)
   clip->clip5.viewport_z_clip_enable = 1;
clip->clip5.viewport_xy_clip_enable = 1;
clip->clip5.vertex_position_space = BRW_CLIP_NDCSPACE;
-   clip->clip5.api_mode = BRW_CLIP_API_OGL;
+   if (ctx->Transform.ClipDepthMode == GL_ZERO_TO_ONE)
+  clip->clip5.api_mode = BRW_CLIP_API_DX;
+   else
+  clip->clip5.api_mode = BRW_CLIP_API_OGL;
clip->clip5.clip_mode = brw->clip.prog_data->clip_mode;
 
if (brw->is_g4x)
diff --git a/src/mesa/drivers/dri/i965/brw_sf.c 
b/src/mesa/drivers/dri/i965/brw_sf.c
index a41a4ad..d5395de 100644
--- a/src/mesa/drivers/dri/i965/brw_sf.c
+++ b/src/mesa/drivers/dri/i965/brw_sf.c
@@ -204,7 +204,7 @@ brw_upload_sf_prog(struct brw_context *brw)
* face orientation, just as we invert the viewport in
* sf_unit_create_from_key().
*/
-  k

[Mesa-dev] [PATCH 4/4] mesa: Remove the _WindowMap from gl_viewport_attrib.

2015-03-30 Thread Mathias . Froehlich
From: Mathias Froehlich 

The _WindowMap can be dropped from gl_viewport_attrib now.
Simplify gl_viewport_attrib handling where possible.

Signed-off-by: Mathias Froehlich 
---
 src/mesa/main/context.c  | 12 ++--
 src/mesa/main/mtypes.h   |  1 -
 src/mesa/main/state.c| 25 -
 src/mesa/main/viewport.c | 44 ++--
 src/mesa/main/viewport.h |  3 ---
 5 files changed, 4 insertions(+), 81 deletions(-)

diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index c1acda9..adf6497 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1288,7 +1288,6 @@ _mesa_free_context_data( struct gl_context *ctx )
_mesa_free_eval_data( ctx );
_mesa_free_texture_data( ctx );
_mesa_free_matrix_data( ctx );
-   _mesa_free_viewport_data( ctx );
_mesa_free_pipeline_data(ctx);
_mesa_free_program_data(ctx);
_mesa_free_shader_state(ctx);
@@ -1449,17 +1448,10 @@ _mesa_copy_context( const struct gl_context *src, 
struct gl_context *dst,
   dst->Transform = src->Transform;
}
if (mask & GL_VIEWPORT_BIT) {
-  /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
   unsigned i;
   for (i = 0; i < src->Const.MaxViewports; i++) {
- dst->ViewportArray[i].X = src->ViewportArray[i].X;
- dst->ViewportArray[i].Y = src->ViewportArray[i].Y;
- dst->ViewportArray[i].Width = src->ViewportArray[i].Width;
- dst->ViewportArray[i].Height = src->ViewportArray[i].Height;
- dst->ViewportArray[i].Near = src->ViewportArray[i].Near;
- dst->ViewportArray[i].Far = src->ViewportArray[i].Far;
- _math_matrix_copy(&dst->ViewportArray[i]._WindowMap,
-   &src->ViewportArray[i]._WindowMap);
+ /* OK to memcpy */
+ dst->ViewportArray[i] = src->ViewportArray[i];
   }
}
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 8e1dba6..6444ac9 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1456,7 +1456,6 @@ struct gl_viewport_attrib
GLfloat X, Y;   /**< position */
GLfloat Width, Height;  /**< size */
GLdouble Near, Far; /**< Depth buffer range */
-   GLmatrix _WindowMap;/**< Mapping transformation as a 
matrix. */
 };
 
 
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index dadfb3c..6dc14b2 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -269,28 +269,6 @@ update_program_constants(struct gl_context *ctx)
 
 
 
-static void
-update_viewport_matrix(struct gl_context *ctx)
-{
-   const GLfloat depthMax = ctx->DrawBuffer->_DepthMaxF;
-   unsigned i;
-
-   assert(depthMax > 0);
-
-   /* Compute scale and bias values. This is really driver-specific
-* and should be maintained elsewhere if at all.
-* NOTE: RasterPos uses this.
-*/
-   for (i = 0; i < ctx->Const.MaxViewports; i++) {
-  double scale[3], translate[3];
-
-  _mesa_get_viewport_xform(ctx, i, scale, translate);
-  _math_matrix_viewport(&ctx->ViewportArray[i]._WindowMap,
-scale, translate, depthMax);
-   }
-}
-
-
 /**
  * Update the ctx->Polygon._FrontBit flag.
  */
@@ -407,9 +385,6 @@ _mesa_update_state_locked( struct gl_context *ctx )
if (new_state & _NEW_PIXEL)
   _mesa_update_pixel( ctx, new_state );
 
-   if (new_state & (_NEW_BUFFERS | _NEW_VIEWPORT))
-  update_viewport_matrix(ctx);
-
if (new_state & (_NEW_MULTISAMPLE | _NEW_BUFFERS))
   update_multisample( ctx );
 
diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c
index 0adce9c..3f5ca79 100644
--- a/src/mesa/main/viewport.c
+++ b/src/mesa/main/viewport.c
@@ -72,16 +72,6 @@ set_viewport_no_notify(struct gl_context *ctx, unsigned idx,
ctx->ViewportArray[idx].Y = y;
ctx->ViewportArray[idx].Height = height;
ctx->NewState |= _NEW_VIEWPORT;
-
-#if 1
-   /* XXX remove this someday.  Currently the DRI drivers rely on
-* the WindowMap matrix being up to date in the driver's Viewport
-* and DepthRange functions.
-*/
-   _mesa_get_viewport_xform(ctx, idx, scale, translate);
-   _math_matrix_viewport(&ctx->ViewportArray[idx]._WindowMap,
- scale, translate, ctx->DrawBuffer->_DepthMaxF);
-#endif
 }
 
 struct gl_viewport_inputs {
@@ -140,8 +130,8 @@ _mesa_Viewport(GLint x, GLint y, GLsizei width, GLsizei 
height)
 
 
 /**
- * Set new viewport parameters and update derived state (the _WindowMap
- * matrix).  Usually called from _mesa_Viewport().
+ * Set new viewport parameters and update derived state.
+ * Usually called from _mesa_Viewport().
  * 
  * \param ctx GL context.
  * \param idxIndex of the viewport to be updated.
@@ -255,16 +245,6 @@ set_depth_range_no_notify(struct gl_context *ctx, unsigned 
idx,
ctx->View

[Mesa-dev] [PATCH 3/4] tnl: Maintain the _WindowMap matrix in TNLcontext.

2015-03-30 Thread Mathias . Froehlich
From: Mathias Froehlich 

This is the only real user of _WindowMap which has the depth
buffer scaling multiplied in. Maintain the _WindowMap of the
one and only viewport inside TNLcontext.

Signed-off-by: Mathias Froehlich 
---
 src/mesa/swrast_setup/ss_context.c |  5 +++--
 src/mesa/tnl/t_context.c   | 12 
 src/mesa/tnl/t_context.h   |  1 +
 src/mesa/tnl/t_rasterpos.c | 13 ++---
 4 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/mesa/swrast_setup/ss_context.c 
b/src/mesa/swrast_setup/ss_context.c
index 0b3b9e4..0b648b3 100644
--- a/src/mesa/swrast_setup/ss_context.c
+++ b/src/mesa/swrast_setup/ss_context.c
@@ -167,7 +167,7 @@ setup_vertex_format(struct gl_context *ctx)
  EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, pointSize );
 
   _tnl_install_attrs( ctx, map, e,
-  ctx->ViewportArray[0]._WindowMap.m,
+  tnl->_WindowMap.m,
   sizeof(SWvertex) );
 
   swsetup->last_index_bitset = index_bitset;
@@ -265,7 +265,8 @@ _swsetup_Wakeup( struct gl_context *ctx )
 void 
 _swsetup_Translate( struct gl_context *ctx, const void *vertex, SWvertex *dest 
)
 {
-   const GLfloat *m = ctx->ViewportArray[0]._WindowMap.m;
+   TNLcontext *tnl = TNL_CONTEXT(ctx);
+   const GLfloat *m = tnl->_WindowMap.m;
GLfloat tmp[4];
GLuint i;
 
diff --git a/src/mesa/tnl/t_context.c b/src/mesa/tnl/t_context.c
index bc705d7..5b9dd54 100644
--- a/src/mesa/tnl/t_context.c
+++ b/src/mesa/tnl/t_context.c
@@ -35,6 +35,7 @@
 #include "math/m_translate.h"
 #include "math/m_xform.h"
 #include "main/state.h"
+#include "main/viewport.h"
 
 #include "tnl.h"
 #include "t_context.h"
@@ -69,6 +70,8 @@ _tnl_CreateContext( struct gl_context *ctx )
   _tnl_install_pipeline( ctx, _tnl_default_pipeline );
}
 
+   _math_matrix_ctr(&tnl->_WindowMap);
+
tnl->NeedNdcCoords = GL_TRUE;
tnl->AllowVertexFog = GL_TRUE;
tnl->AllowPixelFog = GL_TRUE;
@@ -108,6 +111,8 @@ _tnl_DestroyContext( struct gl_context *ctx )
struct tnl_shine_tab *s, *tmps;
TNLcontext *tnl = TNL_CONTEXT(ctx);
 
+   _math_matrix_dtr(&tnl->_WindowMap);
+
/* Free lighting shininess exponentiation table */
foreach_s( s, tmps, tnl->_ShineTabList ) {
   free( s );
@@ -182,6 +187,13 @@ _tnl_InvalidateState( struct gl_context *ctx, GLuint 
new_state )
  }
   }
}
+
+   if (new_state & (_NEW_VIEWPORT | _NEW_BUFFERS)) {
+  double scale[3], translate[3];
+  _mesa_get_viewport_xform(ctx, 0, scale, translate);
+  _math_matrix_viewport(&tnl->_WindowMap, scale, translate,
+ctx->DrawBuffer->_DepthMaxF);
+   }
 }
 
 
diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h
index e89a7f8..e7adb5f 100644
--- a/src/mesa/tnl/t_context.h
+++ b/src/mesa/tnl/t_context.h
@@ -514,6 +514,7 @@ typedef struct
/* Clipspace/ndc/window vertex managment:
 */
struct tnl_clipspace clipspace;
+   GLmatrix _WindowMap;
 
/* Probably need a better configuration mechanism:
 */
diff --git a/src/mesa/tnl/t_rasterpos.c b/src/mesa/tnl/t_rasterpos.c
index 9ecf947..9bdaee8 100644
--- a/src/mesa/tnl/t_rasterpos.c
+++ b/src/mesa/tnl/t_rasterpos.c
@@ -31,6 +31,7 @@
 #include "main/macros.h"
 #include "util/simple_list.h"
 #include "main/mtypes.h"
+#include "main/viewport.h"
 
 #include "math/m_matrix.h"
 #include "tnl/tnl.h"
@@ -378,6 +379,7 @@ _tnl_RasterPos(struct gl_context *ctx, const GLfloat 
vObj[4])
   GLfloat eye[4], clip[4], ndc[3], d;
   GLfloat *norm, eyenorm[3];
   GLfloat *objnorm = ctx->Current.Attrib[VERT_ATTRIB_NORMAL];
+  double scale[3], translate[3];
 
   /* apply modelview matrix:  eye = MV * obj */
   TRANSFORM_POINT( eye, ctx->ModelviewMatrixStack.Top->m, vObj );
@@ -410,13 +412,10 @@ _tnl_RasterPos(struct gl_context *ctx, const GLfloat 
vObj[4])
   ndc[1] = clip[1] * d;
   ndc[2] = clip[2] * d;
   /* wincoord = viewport_mapping(ndc) */
-  ctx->Current.RasterPos[0] = (ndc[0] * 
ctx->ViewportArray[0]._WindowMap.m[MAT_SX]
-   + 
ctx->ViewportArray[0]._WindowMap.m[MAT_TX]);
-  ctx->Current.RasterPos[1] = (ndc[1] * 
ctx->ViewportArray[0]._WindowMap.m[MAT_SY]
-   + 
ctx->ViewportArray[0]._WindowMap.m[MAT_TY]);
-  ctx->Current.RasterPos[2] = (ndc[2] * 
ctx->ViewportArray[0]._WindowMap.m[MAT_SZ]
-   + 
ctx->ViewportArray[0]._WindowMap.m[MAT_TZ])
-  / ctx->DrawBuffer->_DepthMaxF;
+  _mesa_get_viewport_xform(ctx, 0, scale, translate);
+  ctx->Current.RasterPos[0] = (ndc[0] * scale[0] + translate[0]);
+  ctx->

[Mesa-dev] [PATCH 1/4] i965: Make use of _mesa_get_viewport_xform.

2015-03-30 Thread Mathias . Froehlich
From: Mathias Froehlich 

Instead of _WindowMap just use the translation and scale
of the viewport transform directly. Thereby avoid dividing by
_DepthMaxF again.

Signed-off-by: Mathias Froehlich 
---
 src/mesa/drivers/dri/i965/brw_sf_state.c| 17 +
 src/mesa/drivers/dri/i965/gen6_viewport_state.c | 17 +
 src/mesa/drivers/dri/i965/gen7_viewport_state.c | 17 +
 src/mesa/drivers/dri/i965/gen8_viewport_state.c | 17 +
 4 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_sf_state.c 
b/src/mesa/drivers/dri/i965/brw_sf_state.c
index 75d6451..7cd3e73 100644
--- a/src/mesa/drivers/dri/i965/brw_sf_state.c
+++ b/src/mesa/drivers/dri/i965/brw_sf_state.c
@@ -34,6 +34,7 @@
 #include "main/mtypes.h"
 #include "main/macros.h"
 #include "main/fbobject.h"
+#include "main/viewport.h"
 #include "brw_context.h"
 #include "brw_state.h"
 #include "brw_defines.h"
@@ -42,11 +43,10 @@
 static void upload_sf_vp(struct brw_context *brw)
 {
struct gl_context *ctx = &brw->ctx;
-   const GLfloat depth_scale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
struct brw_sf_viewport *sfv;
GLfloat y_scale, y_bias;
+   double scale[3], translate[3];
const bool render_to_fbo = _mesa_is_user_fbo(ctx->DrawBuffer);
-   const GLfloat *v = ctx->ViewportArray[0]._WindowMap.m;
 
sfv = brw_state_batch(brw, AUB_TRACE_SF_VP_STATE,
 sizeof(*sfv), 32, &brw->sf.vp_offset);
@@ -63,12 +63,13 @@ static void upload_sf_vp(struct brw_context *brw)
 
/* _NEW_VIEWPORT */
 
-   sfv->viewport.m00 = v[MAT_SX];
-   sfv->viewport.m11 = v[MAT_SY] * y_scale;
-   sfv->viewport.m22 = v[MAT_SZ] * depth_scale;
-   sfv->viewport.m30 = v[MAT_TX];
-   sfv->viewport.m31 = v[MAT_TY] * y_scale + y_bias;
-   sfv->viewport.m32 = v[MAT_TZ] * depth_scale;
+   _mesa_get_viewport_xform(ctx, 0, scale, translate);
+   sfv->viewport.m00 = scale[0];
+   sfv->viewport.m11 = scale[1] * y_scale;
+   sfv->viewport.m22 = scale[2];
+   sfv->viewport.m30 = translate[0];
+   sfv->viewport.m31 = translate[1] * y_scale + y_bias;
+   sfv->viewport.m32 = translate[2];
 
/* _NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT
 * for DrawBuffer->_[XY]{min,max}
diff --git a/src/mesa/drivers/dri/i965/gen6_viewport_state.c 
b/src/mesa/drivers/dri/i965/gen6_viewport_state.c
index 81546e4..aec2a9b 100644
--- a/src/mesa/drivers/dri/i965/gen6_viewport_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_viewport_state.c
@@ -30,6 +30,7 @@
 #include "brw_defines.h"
 #include "intel_batchbuffer.h"
 #include "main/fbobject.h"
+#include "main/viewport.h"
 
 /* The clip VP defines the guardband region where expensive clipping is skipped
  * and fragments are allowed to be generated and clipped out cheaply by the SF.
@@ -78,11 +79,10 @@ static void
 gen6_upload_sf_vp(struct brw_context *brw)
 {
struct gl_context *ctx = &brw->ctx;
-   const GLfloat depth_scale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
struct brw_sf_viewport *sfv;
GLfloat y_scale, y_bias;
+   double scale[3], translate[3];
const bool render_to_fbo = _mesa_is_user_fbo(ctx->DrawBuffer);
-   const GLfloat *v = ctx->ViewportArray[0]._WindowMap.m;
 
sfv = brw_state_batch(brw, AUB_TRACE_SF_VP_STATE,
 sizeof(*sfv), 32, &brw->sf.vp_offset);
@@ -98,12 +98,13 @@ gen6_upload_sf_vp(struct brw_context *brw)
}
 
/* _NEW_VIEWPORT */
-   sfv->viewport.m00 = v[MAT_SX];
-   sfv->viewport.m11 = v[MAT_SY] * y_scale;
-   sfv->viewport.m22 = v[MAT_SZ] * depth_scale;
-   sfv->viewport.m30 = v[MAT_TX];
-   sfv->viewport.m31 = v[MAT_TY] * y_scale + y_bias;
-   sfv->viewport.m32 = v[MAT_TZ] * depth_scale;
+   _mesa_get_viewport_xform(ctx, 0, scale, translate);
+   sfv->viewport.m00 = scale[0];
+   sfv->viewport.m11 = scale[1] * y_scale;
+   sfv->viewport.m22 = scale[2];
+   sfv->viewport.m30 = translate[0];
+   sfv->viewport.m31 = translate[1] * y_scale + y_bias;
+   sfv->viewport.m32 = translate[2];
 
brw->state.dirty.brw |= BRW_NEW_SF_VP;
 }
diff --git a/src/mesa/drivers/dri/i965/gen7_viewport_state.c 
b/src/mesa/drivers/dri/i965/gen7_viewport_state.c
index bd11c3a..eb59684 100644
--- a/src/mesa/drivers/dri/i965/gen7_viewport_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_viewport_state.c
@@ -26,12 +26,12 @@
 #include "brw_defines.h"
 #include "intel_batchbuffer.h"
 #include "main/fbobject.h"
+#include "main/viewport.h"
 
 static void
 gen7_upload_sf_clip_viewport(struct brw_context *brw)
 {
struct gl_context *ctx = &brw->ctx;
-   const GLfloat depth_scale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
GLfloat y_scale, y_bias;
const bool render_to_fbo = _mesa_is_user_fbo(ctx->

[Mesa-dev] [PATCH 2/4] radeon: Make use of _mesa_get_viewport_xform.

2015-03-30 Thread Mathias . Froehlich
From: Mathias Froehlich 

Instead of _WindowMap just use the translation and scale
of the viewport transform directly. Thereby avoid dividing by
_DepthMaxF again.

Signed-off-by: Mathias Froehlich 
---
 src/mesa/drivers/dri/r200/r200_state.c | 17 +
 src/mesa/drivers/dri/radeon/radeon_state.c | 17 +
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/src/mesa/drivers/dri/r200/r200_state.c 
b/src/mesa/drivers/dri/r200/r200_state.c
index 8327187..358f100 100644
--- a/src/mesa/drivers/dri/r200/r200_state.c
+++ b/src/mesa/drivers/dri/r200/r200_state.c
@@ -42,6 +42,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
 #include "main/framebuffer.h"
 #include "main/fbobject.h"
 #include "main/stencil.h"
+#include "main/viewport.h"
 
 #include "swrast/swrast.h"
 #include "vbo/vbo.h"
@@ -1544,9 +1545,8 @@ void r200UpdateWindow( struct gl_context *ctx )
__DRIdrawable *dPriv = radeon_get_drawable(&rmesa->radeon);
GLfloat xoffset = 0;
GLfloat yoffset = dPriv ? (GLfloat) dPriv->h : 0;
-   const GLfloat *v = ctx->ViewportArray[0]._WindowMap.m;
const GLboolean render_to_fbo = (ctx->DrawBuffer ? 
_mesa_is_user_fbo(ctx->DrawBuffer) : 0);
-   const GLfloat depthScale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
+   double scale[3], translate[3];
GLfloat y_scale, y_bias;
 
if (render_to_fbo) {
@@ -1557,12 +1557,13 @@ void r200UpdateWindow( struct gl_context *ctx )
   y_bias = yoffset;
}
 
-   float_ui32_type sx = { v[MAT_SX] };
-   float_ui32_type tx = { v[MAT_TX] + xoffset };
-   float_ui32_type sy = { v[MAT_SY] * y_scale };
-   float_ui32_type ty = { (v[MAT_TY] * y_scale) + y_bias };
-   float_ui32_type sz = { v[MAT_SZ] * depthScale };
-   float_ui32_type tz = { v[MAT_TZ] * depthScale };
+   _mesa_get_viewport_xform(ctx, 0, scale, translate);
+   float_ui32_type sx = { scale[0] };
+   float_ui32_type tx = { translate[0] + xoffset };
+   float_ui32_type sy = { scale[1] * y_scale };
+   float_ui32_type ty = { (translate[1] * y_scale) + y_bias };
+   float_ui32_type sz = { scale[2] };
+   float_ui32_type tz = { translate[2] };
 
R200_STATECHANGE( rmesa, vpt );
 
diff --git a/src/mesa/drivers/dri/radeon/radeon_state.c 
b/src/mesa/drivers/dri/radeon/radeon_state.c
index e83a34d..fb21fd1 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state.c
@@ -44,6 +44,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
 #include "main/state.h"
 #include "main/core.h"
 #include "main/stencil.h"
+#include "main/viewport.h"
 
 #include "vbo/vbo.h"
 #include "tnl/tnl.h"
@@ -1352,9 +1353,8 @@ void radeonUpdateWindow( struct gl_context *ctx )
__DRIdrawable *dPriv = radeon_get_drawable(&rmesa->radeon);
GLfloat xoffset = 0.0;
GLfloat yoffset = dPriv ? (GLfloat) dPriv->h : 0;
-   const GLfloat *v = ctx->ViewportArray[0]._WindowMap.m;
const GLboolean render_to_fbo = (ctx->DrawBuffer ? 
_mesa_is_user_fbo(ctx->DrawBuffer) : 0);
-   const GLfloat depthScale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
+   double scale[3], translate[3];
GLfloat y_scale, y_bias;
 
if (render_to_fbo) {
@@ -1365,12 +1365,13 @@ void radeonUpdateWindow( struct gl_context *ctx )
   y_bias = yoffset;
}
 
-   float_ui32_type sx = { v[MAT_SX] };
-   float_ui32_type tx = { v[MAT_TX] + xoffset + SUBPIXEL_X };
-   float_ui32_type sy = { v[MAT_SY] * y_scale };
-   float_ui32_type ty = { (v[MAT_TY] * y_scale) + y_bias + SUBPIXEL_Y };
-   float_ui32_type sz = { v[MAT_SZ] * depthScale };
-   float_ui32_type tz = { v[MAT_TZ] * depthScale };
+   _mesa_get_viewport_xform(ctx, 0, scale, translate);
+   float_ui32_type sx = { scale[0] };
+   float_ui32_type tx = { translate[0] + xoffset + SUBPIXEL_X };
+   float_ui32_type sy = { scale[1] * y_scale };
+   float_ui32_type ty = { (translate[1] * y_scale) + y_bias + SUBPIXEL_Y };
+   float_ui32_type sz = { scale[2] };
+   float_ui32_type tz = { translate[2] };
 
RADEON_STATECHANGE( rmesa, vpt );
 
-- 
2.1.0

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


[Mesa-dev] [PATCH 0/4] Cleanup viewport handling past clip control.

2015-03-30 Thread Mathias . Froehlich
From: Mathias Froehlich 

Hi,

The series cleans up viewport handling a bit. Make use of the utility
functions provided with the clip control implementation in the drivers.
Move the _WindowMap matrix into the TNL state which is the only
remaining user of that matrix and simplify gl_viewport_attrib handling.

I did not see any regression with piglit quick.test on i965 and on swrast.
I cannot test the radeon code that I touched since I do not have such
hardware available.
Please review!

Thanks

Mathias


Mathias Froehlich (4):
  i965: Make use of _mesa_get_viewport_xform.
  radeon: Make use of _mesa_get_viewport_xform.
  tnl: Maintain the _WindowMap matrix in TNLcontext.
  mesa: Remove the _WindowMap from gl_viewport_attrib.

 src/mesa/drivers/dri/i965/brw_sf_state.c| 17 +-
 src/mesa/drivers/dri/i965/gen6_viewport_state.c | 17 +-
 src/mesa/drivers/dri/i965/gen7_viewport_state.c | 17 +-
 src/mesa/drivers/dri/i965/gen8_viewport_state.c | 17 +-
 src/mesa/drivers/dri/r200/r200_state.c  | 17 +-
 src/mesa/drivers/dri/radeon/radeon_state.c  | 17 +-
 src/mesa/main/context.c | 12 ++-
 src/mesa/main/mtypes.h  |  1 -
 src/mesa/main/state.c   | 25 --
 src/mesa/main/viewport.c| 44 ++---
 src/mesa/main/viewport.h|  3 --
 src/mesa/swrast_setup/ss_context.c  |  5 +--
 src/mesa/tnl/t_context.c| 12 +++
 src/mesa/tnl/t_context.h|  1 +
 src/mesa/tnl/t_rasterpos.c  | 13 
 15 files changed, 80 insertions(+), 138 deletions(-)

-- 
2.1.0

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


[Mesa-dev] [PATCH 2/4] radeon: Make use of _mesa_get_viewport_xform v2.

2015-04-02 Thread Mathias . Froehlich
From: Mathias Froehlich 

Hi Michael,

You mean like this?
I did initially preserve the original ordering present in the
radeon implementation because I thought it is easier to review then.
If it's the other way round, here you are ...
Ok, to commit?

Thanks

Mathias


Instead of _WindowMap just use the translation and scale
of the viewport transform directly. Thereby avoid dividing by
_DepthMaxF again.

v2:
Change order of assignments.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Froehlich 
---
 src/mesa/drivers/dri/r200/r200_state.c | 17 +
 src/mesa/drivers/dri/radeon/radeon_state.c | 17 +
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/src/mesa/drivers/dri/r200/r200_state.c 
b/src/mesa/drivers/dri/r200/r200_state.c
index 8327187..e4f07b3 100644
--- a/src/mesa/drivers/dri/r200/r200_state.c
+++ b/src/mesa/drivers/dri/r200/r200_state.c
@@ -42,6 +42,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
 #include "main/framebuffer.h"
 #include "main/fbobject.h"
 #include "main/stencil.h"
+#include "main/viewport.h"
 
 #include "swrast/swrast.h"
 #include "vbo/vbo.h"
@@ -1544,9 +1545,8 @@ void r200UpdateWindow( struct gl_context *ctx )
__DRIdrawable *dPriv = radeon_get_drawable(&rmesa->radeon);
GLfloat xoffset = 0;
GLfloat yoffset = dPriv ? (GLfloat) dPriv->h : 0;
-   const GLfloat *v = ctx->ViewportArray[0]._WindowMap.m;
const GLboolean render_to_fbo = (ctx->DrawBuffer ? 
_mesa_is_user_fbo(ctx->DrawBuffer) : 0);
-   const GLfloat depthScale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
+   double scale[3], translate[3];
GLfloat y_scale, y_bias;
 
if (render_to_fbo) {
@@ -1557,12 +1557,13 @@ void r200UpdateWindow( struct gl_context *ctx )
   y_bias = yoffset;
}
 
-   float_ui32_type sx = { v[MAT_SX] };
-   float_ui32_type tx = { v[MAT_TX] + xoffset };
-   float_ui32_type sy = { v[MAT_SY] * y_scale };
-   float_ui32_type ty = { (v[MAT_TY] * y_scale) + y_bias };
-   float_ui32_type sz = { v[MAT_SZ] * depthScale };
-   float_ui32_type tz = { v[MAT_TZ] * depthScale };
+   _mesa_get_viewport_xform(ctx, 0, scale, translate);
+   float_ui32_type sx = { scale[0] };
+   float_ui32_type sy = { scale[1] * y_scale };
+   float_ui32_type sz = { scale[2] };
+   float_ui32_type tx = { translate[0] + xoffset };
+   float_ui32_type ty = { (translate[1] * y_scale) + y_bias };
+   float_ui32_type tz = { translate[2] };
 
R200_STATECHANGE( rmesa, vpt );
 
diff --git a/src/mesa/drivers/dri/radeon/radeon_state.c 
b/src/mesa/drivers/dri/radeon/radeon_state.c
index e83a34d..66a50a9 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state.c
@@ -44,6 +44,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
 #include "main/state.h"
 #include "main/core.h"
 #include "main/stencil.h"
+#include "main/viewport.h"
 
 #include "vbo/vbo.h"
 #include "tnl/tnl.h"
@@ -1352,9 +1353,8 @@ void radeonUpdateWindow( struct gl_context *ctx )
__DRIdrawable *dPriv = radeon_get_drawable(&rmesa->radeon);
GLfloat xoffset = 0.0;
GLfloat yoffset = dPriv ? (GLfloat) dPriv->h : 0;
-   const GLfloat *v = ctx->ViewportArray[0]._WindowMap.m;
const GLboolean render_to_fbo = (ctx->DrawBuffer ? 
_mesa_is_user_fbo(ctx->DrawBuffer) : 0);
-   const GLfloat depthScale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
+   double scale[3], translate[3];
GLfloat y_scale, y_bias;
 
if (render_to_fbo) {
@@ -1365,12 +1365,13 @@ void radeonUpdateWindow( struct gl_context *ctx )
   y_bias = yoffset;
}
 
-   float_ui32_type sx = { v[MAT_SX] };
-   float_ui32_type tx = { v[MAT_TX] + xoffset + SUBPIXEL_X };
-   float_ui32_type sy = { v[MAT_SY] * y_scale };
-   float_ui32_type ty = { (v[MAT_TY] * y_scale) + y_bias + SUBPIXEL_Y };
-   float_ui32_type sz = { v[MAT_SZ] * depthScale };
-   float_ui32_type tz = { v[MAT_TZ] * depthScale };
+   _mesa_get_viewport_xform(ctx, 0, scale, translate);
+   float_ui32_type sx = { scale[0] };
+   float_ui32_type sy = { scale[1] * y_scale };
+   float_ui32_type sz = { scale[2] };
+   float_ui32_type tx = { translate[0] + xoffset + SUBPIXEL_X };
+   float_ui32_type ty = { (translate[1] * y_scale) + y_bias + SUBPIXEL_Y };
+   float_ui32_type tz = { translate[2] };
 
RADEON_STATECHANGE( rmesa, vpt );
 
-- 
2.1.0

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


[Mesa-dev] [PATCH 3/4] tnl: Maintain the _WindowMap matrix in TNLcontext v2.

2015-04-02 Thread Mathias . Froehlich
From: Mathias Froehlich 

Hi Brian,

Thanks for the review!
The Patch with unneeded parentheses removed.
Ok, to push?

Greetings

Mathias


This is the only real user of _WindowMap which has the depth
buffer scaling multiplied in. Maintain the _WindowMap of the
one and only viewport inside TNLcontext.

v2:
Remove unneeded parentheses.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Froehlich 
---
 src/mesa/swrast_setup/ss_context.c |  5 +++--
 src/mesa/tnl/t_context.c   | 12 
 src/mesa/tnl/t_context.h   |  1 +
 src/mesa/tnl/t_rasterpos.c | 13 ++---
 4 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/mesa/swrast_setup/ss_context.c 
b/src/mesa/swrast_setup/ss_context.c
index 4fc90c3..74b1da3 100644
--- a/src/mesa/swrast_setup/ss_context.c
+++ b/src/mesa/swrast_setup/ss_context.c
@@ -167,7 +167,7 @@ setup_vertex_format(struct gl_context *ctx)
  EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, pointSize );
 
   _tnl_install_attrs( ctx, map, e,
-  ctx->ViewportArray[0]._WindowMap.m,
+  tnl->_WindowMap.m,
   sizeof(SWvertex) );
 
   swsetup->last_index_bitset = index_bitset;
@@ -265,7 +265,8 @@ _swsetup_Wakeup( struct gl_context *ctx )
 void 
 _swsetup_Translate( struct gl_context *ctx, const void *vertex, SWvertex *dest 
)
 {
-   const GLfloat *m = ctx->ViewportArray[0]._WindowMap.m;
+   TNLcontext *tnl = TNL_CONTEXT(ctx);
+   const GLfloat *m = tnl->_WindowMap.m;
GLfloat tmp[4];
GLuint i;
 
diff --git a/src/mesa/tnl/t_context.c b/src/mesa/tnl/t_context.c
index bc705d7..5b9dd54 100644
--- a/src/mesa/tnl/t_context.c
+++ b/src/mesa/tnl/t_context.c
@@ -35,6 +35,7 @@
 #include "math/m_translate.h"
 #include "math/m_xform.h"
 #include "main/state.h"
+#include "main/viewport.h"
 
 #include "tnl.h"
 #include "t_context.h"
@@ -69,6 +70,8 @@ _tnl_CreateContext( struct gl_context *ctx )
   _tnl_install_pipeline( ctx, _tnl_default_pipeline );
}
 
+   _math_matrix_ctr(&tnl->_WindowMap);
+
tnl->NeedNdcCoords = GL_TRUE;
tnl->AllowVertexFog = GL_TRUE;
tnl->AllowPixelFog = GL_TRUE;
@@ -108,6 +111,8 @@ _tnl_DestroyContext( struct gl_context *ctx )
struct tnl_shine_tab *s, *tmps;
TNLcontext *tnl = TNL_CONTEXT(ctx);
 
+   _math_matrix_dtr(&tnl->_WindowMap);
+
/* Free lighting shininess exponentiation table */
foreach_s( s, tmps, tnl->_ShineTabList ) {
   free( s );
@@ -182,6 +187,13 @@ _tnl_InvalidateState( struct gl_context *ctx, GLuint 
new_state )
  }
   }
}
+
+   if (new_state & (_NEW_VIEWPORT | _NEW_BUFFERS)) {
+  double scale[3], translate[3];
+  _mesa_get_viewport_xform(ctx, 0, scale, translate);
+  _math_matrix_viewport(&tnl->_WindowMap, scale, translate,
+ctx->DrawBuffer->_DepthMaxF);
+   }
 }
 
 
diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h
index e89a7f8..e7adb5f 100644
--- a/src/mesa/tnl/t_context.h
+++ b/src/mesa/tnl/t_context.h
@@ -514,6 +514,7 @@ typedef struct
/* Clipspace/ndc/window vertex managment:
 */
struct tnl_clipspace clipspace;
+   GLmatrix _WindowMap;
 
/* Probably need a better configuration mechanism:
 */
diff --git a/src/mesa/tnl/t_rasterpos.c b/src/mesa/tnl/t_rasterpos.c
index 1cd3981..d4b45ba 100644
--- a/src/mesa/tnl/t_rasterpos.c
+++ b/src/mesa/tnl/t_rasterpos.c
@@ -30,6 +30,7 @@
 #include "main/macros.h"
 #include "util/simple_list.h"
 #include "main/mtypes.h"
+#include "main/viewport.h"
 
 #include "math/m_matrix.h"
 #include "tnl/tnl.h"
@@ -377,6 +378,7 @@ _tnl_RasterPos(struct gl_context *ctx, const GLfloat 
vObj[4])
   GLfloat eye[4], clip[4], ndc[3], d;
   GLfloat *norm, eyenorm[3];
   GLfloat *objnorm = ctx->Current.Attrib[VERT_ATTRIB_NORMAL];
+  double scale[3], translate[3];
 
   /* apply modelview matrix:  eye = MV * obj */
   TRANSFORM_POINT( eye, ctx->ModelviewMatrixStack.Top->m, vObj );
@@ -409,13 +411,10 @@ _tnl_RasterPos(struct gl_context *ctx, const GLfloat 
vObj[4])
   ndc[1] = clip[1] * d;
   ndc[2] = clip[2] * d;
   /* wincoord = viewport_mapping(ndc) */
-  ctx->Current.RasterPos[0] = (ndc[0] * 
ctx->ViewportArray[0]._WindowMap.m[MAT_SX]
-   + 
ctx->ViewportArray[0]._WindowMap.m[MAT_TX]);
-  ctx->Current.RasterPos[1] = (ndc[1] * 
ctx->ViewportArray[0]._WindowMap.m[MAT_SY]
-   + 
ctx->ViewportArray[0]._WindowMap.m[MAT_TY]);
-  ctx->Current.RasterPos[2] = (ndc[2] * 
ctx->ViewportArray[0]._WindowMap.m[MAT_SZ]
-   + 
ctx->ViewportArray[0]._WindowMap.m[MAT_TZ])
-  / ctx->DrawBuffer->_DepthMaxF;
+  _mesa_get_

[Mesa-dev] [PATCH] mesa: Remove unused variables left over from 107ae27e57d.

2015-04-05 Thread Mathias . Froehlich
From: Mathias Froehlich 

David,
You mean the below.
Ok to push?
Greetings and Thanks!
Mathias

Signed-off-by: Mathias Froehlich 
---
 src/mesa/main/viewport.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c
index 3f5ca79..b270630 100644
--- a/src/mesa/main/viewport.c
+++ b/src/mesa/main/viewport.c
@@ -40,8 +40,6 @@ set_viewport_no_notify(struct gl_context *ctx, unsigned idx,
GLfloat x, GLfloat y,
GLfloat width, GLfloat height)
 {
-   double scale[3], translate[3];
-
/* clamp width and height to the implementation dependent range */
width  = MIN2(width, (GLfloat) ctx->Const.MaxViewportWidth);
height = MIN2(height, (GLfloat) ctx->Const.MaxViewportHeight);
@@ -236,8 +234,6 @@ static void
 set_depth_range_no_notify(struct gl_context *ctx, unsigned idx,
   GLclampd nearval, GLclampd farval)
 {
-   double scale[3], translate[3];
-
if (ctx->ViewportArray[idx].Near == nearval &&
ctx->ViewportArray[idx].Far == farval)
   return;
-- 
2.1.0

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


[Mesa-dev] [PATCH] i965: Flush batchbuffer containing the query on glQueryCounter.

2015-04-12 Thread Mathias . Froehlich
From: Mathias Froehlich 

Hi all,

the attached patch fixes timer queries as noticed with osgviewer.
Please review!

Greetings and thanks

  Mathias



This change fixes a regression with timer queries introduced with
commit 3eb6258. There the pending batchbuffer is flushed
only if glEndQuery is executed. This present change adds such
a flush to glQueryCounter which also schedules a value query
just like glEndQuery does. The patch fixes GPU timer queries
going mad from within osgviewer.

Signed-off-by: Mathias Froehlich 
---
 src/mesa/drivers/dri/i965/brw_queryobj.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_queryobj.c 
b/src/mesa/drivers/dri/i965/brw_queryobj.c
index 917a24f..667c900 100644
--- a/src/mesa/drivers/dri/i965/brw_queryobj.c
+++ b/src/mesa/drivers/dri/i965/brw_queryobj.c
@@ -472,6 +472,8 @@ brw_query_counter(struct gl_context *ctx, struct 
gl_query_object *q)
drm_intel_bo_unreference(query->bo);
query->bo = drm_intel_bo_alloc(brw->bufmgr, "timestamp query", 4096, 4096);
brw_write_timestamp(brw, query->bo, 0);
+
+   query->flushed = false;
 }
 
 /**
-- 
2.1.0

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


[Mesa-dev] [PATCH 00/31] Make more use of bitmasks v2

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

Hi all,

following a series with performance improvements
for cpu/draw bound applications. This part makes
more use of the bitmask/ffs technique for iterating
a set of enabled items. The gains are not huge
but they are noticable for some of my favourite
workloads.

Changes in v2:

Past the suggestion from Brian Paul and the
discussion about maintainability I
switched to gallium/u_bit_scan{,64} style
functions for the series of changes.
Providing them and using them in some places
in core mesa make up the two new patches upfront.

Appart from that the problem spotted
by Roland Scheidegger is fixed and the changes
requested all around are incorporated.

Please review!

Thanks

Mathias


Mathias Fröhlich (31):
  mesa: Provide _mesa_bit_scan{,64} similar to gallium.
  mesa: Make use of _mesa_bit_scan{,64}.
  mesa: Add gl_point_attrib::CoordReplaceBits bitfield.
  swrast: Convert swrast to use CoordsReplaceBits.
  gallium: Convert the state_tracker to use CoordsReplaceBits.
  r200: convert r200 to use CoordsReplaceBits.
  i915: Convert i915 to use CoordsReplaceBits.
  i965: Convert i965 to use CoordsReplaceBits.
  mesa: Remove the now unused CoordsReplace array.
  mesa: Rename CoordReplaceBits back to CoordReplace.
  mesa: Track enabled lights in a bitmask
  mesa: Use bitmask/ffs to iterate enabled lights
  mesa: Use bitmask/ffs to iterate enabled lights for ff shader keys.
  tnl: Use bitmask/ffs to iterate enabled lights
  nouveau: Use bitmask/ffs to iterate enabled lights
  radeon/r200: Use bitmask/ffs to iterate enabled lights
  mesa: Switch to bitmask based enabled lights in gen_matypes.c
  mesa: Remove the linked list of enabled lights
  mesa: Use bitmask/ffs to build ff vertex shader keys.
  mesa: Use bitmask/ffs to build ff fragment shader keys.
  mesa: Use bitmask/ffs to iterate color material attributes.
  mesa: Use bitmask/ffs to iterate enabled clip planes.
  radeon/r200: Use bitmask/ffs to iterate enabled clip planes.
  i965: Use bitmask/ffs to iterate enabled clip planes.
  i965: Use bitmask/ffs to iterate used vertex attributes.
  mesa: Use bitmask/ffs to iterate SamplersUsed
  mesa: Use designated bool value to check texture unit completeness.
  mesa: Use bitmask/ffs to iterate the enabled textures.
  mesa: Use bitmask/ffs to iterate the active_samplers bitmask.
  vbo: Use a bitmask to track the active arrays in vbo_exec*.
  vbo: Use a bitmask to track the active arrays in vbo_save*.

 src/mesa/drivers/common/meta.c|  21 ++--
 src/mesa/drivers/dri/i915/i915_state.c|  17 ++-
 src/mesa/drivers/dri/i965/brw_curbe.c |  20 ++--
 src/mesa/drivers/dri/i965/brw_draw.c  |   9 +-
 src/mesa/drivers/dri/i965/brw_sf.c|   7 +-
 src/mesa/drivers/dri/i965/brw_vs.c|   6 +-
 src/mesa/drivers/dri/i965/gen6_sf_state.c |   2 +-
 src/mesa/drivers/dri/nouveau/nouveau_state.c  |   9 +-
 src/mesa/drivers/dri/nouveau/nv10_state_tnl.c |  26 +++--
 src/mesa/drivers/dri/nouveau/nv20_state_tnl.c |  26 +++--
 src/mesa/drivers/dri/r200/r200_state.c|  65 ++--
 src/mesa/drivers/dri/radeon/radeon_state.c|  60 ++-
 src/mesa/main/arrayobj.c  |   5 +-
 src/mesa/main/attrib.c|   2 +-
 src/mesa/main/buffers.c   |   3 +-
 src/mesa/main/context.c   |  11 +-
 src/mesa/main/enable.c|   6 +-
 src/mesa/main/ff_fragment_shader.cpp  |   9 +-
 src/mesa/main/ffvertex_prog.c |  35 ---
 src/mesa/main/imports.h   |  24 +
 src/mesa/main/light.c |  59 +++
 src/mesa/main/matrix.c|  18 ++--
 src/mesa/main/mtypes.h|   8 +-
 src/mesa/main/points.c|   6 +-
 src/mesa/main/rastpos.c   |  27 ++---
 src/mesa/main/texenv.c|  32 +++---
 src/mesa/main/texstate.c  |  33 +++---
 src/mesa/main/uniform_query.cpp   |   7 +-
 src/mesa/main/uniforms.c  |  41 
 src/mesa/state_tracker/st_atom_rasterizer.c   |   8 +-
 src/mesa/swrast/s_points.c|   4 +-
 src/mesa/tnl/t_vb_cliptmp.h   |  51 +
 src/mesa/tnl/t_vb_light.c |  13 ++-
 src/mesa/tnl/t_vb_lighttmp.h  |  24 +++--
 src/mesa/tnl/t_vb_program.c   |  64 ++--
 src/mesa/tnl/t_vb_vertex.c|  57 +-
 src/mesa/vbo/vbo_exec.h   |   1 +
 src/mesa/vbo/vbo_exec_api.c   | 145 +-
 src/mesa/vbo/vbo_exec_draw.c  |   2 +
 src/mesa/vbo/vbo_save.h   |   2 +
 src/mesa/vbo/vbo_save_api.c   |  66 ++--
 src/mesa/vbo/vbo_save_draw.c  |  54 +-
 src/mesa/x86/gen_matypes.c|  

[Mesa-dev] [PATCH 02/31] mesa: Make use of _mesa_bit_scan{,64}.

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

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/arrayobj.c | 5 ++---
 src/mesa/main/buffers.c  | 3 +--
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index 897dac6..fb3c752 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -342,13 +342,12 @@ _mesa_update_vao_client_arrays(struct gl_context *ctx,
GLbitfield64 arrays = vao->NewArrays;
 
while (arrays) {
+  const int attrib = _mesa_bit_scan64(&arrays);
+
   struct gl_client_array *client_array;
   struct gl_vertex_attrib_array *attrib_array;
   struct gl_vertex_buffer_binding *buffer_binding;
 
-  GLint attrib = ffsll(arrays) - 1;
-  arrays ^= BITFIELD64_BIT(attrib);
-
   attrib_array = &vao->VertexAttrib[attrib];
   buffer_binding = &vao->VertexBinding[attrib_array->VertexBinding];
   client_array = &vao->_VertexAttrib[attrib];
diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c
index a28c583..c93be3b 100644
--- a/src/mesa/main/buffers.c
+++ b/src/mesa/main/buffers.c
@@ -595,13 +595,12 @@ _mesa_drawbuffers(struct gl_context *ctx, struct 
gl_framebuffer *fb,
if (n > 0 && _mesa_bitcount(destMask[0]) > 1) {
   GLuint count = 0, destMask0 = destMask[0];
   while (destMask0) {
- GLint bufIndex = ffs(destMask0) - 1;
+ const int bufIndex = _mesa_bit_scan(&destMask0);
  if (fb->_ColorDrawBufferIndexes[count] != bufIndex) {
 updated_drawbuffers(ctx, fb);
 fb->_ColorDrawBufferIndexes[count] = bufIndex;
  }
  count++;
- destMask0 &= ~(1 << bufIndex);
   }
   fb->ColorDrawBuffer[0] = buffers[0];
   fb->_NumColorDrawBuffers = count;
-- 
2.5.5

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


[Mesa-dev] [PATCH 01/31] mesa: Provide _mesa_bit_scan{, 64} similar to gallium.

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

The function is yet unused but will be used with the
next changes.

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/imports.h | 24 
 1 file changed, 24 insertions(+)

diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
index d96d666..3ccfb80 100644
--- a/src/mesa/main/imports.h
+++ b/src/mesa/main/imports.h
@@ -400,6 +400,30 @@ _mesa_flsll(uint64_t n)
 #endif
 }
 
+/* Destructively loop over all of the bits in a mask as in:
+ *
+ * while (mymask) {
+ *   int i = _mesa_bit_scan(&mymask);
+ *   ... process element i
+ * }
+ *
+ */
+static inline int
+_mesa_bit_scan(unsigned *mask)
+{
+   const int i = ffs(*mask) - 1;
+   *mask ^= (1u << i);
+   return i;
+}
+
+static inline int
+_mesa_bit_scan64(uint64_t *mask)
+{
+   const int i = ffsll(*mask) - 1;
+   *mask ^= (1llu << i);
+   return i;
+}
+
 static inline bool
 _mesa_half_is_negative(GLhalfARB h)
 {
-- 
2.5.5

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


[Mesa-dev] [PATCH 07/31] i915: Convert i915 to use CoordsReplaceBits.

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

Switch over to use the CoordsReplaceBits bitmask.

Reviewed-by: Brian Paul 
Reviewed-by: Ian Romanick 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/dri/i915/i915_state.c | 17 +++--
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/src/mesa/drivers/dri/i915/i915_state.c 
b/src/mesa/drivers/dri/i915/i915_state.c
index 4c83073..4c4bb09 100644
--- a/src/mesa/drivers/dri/i915/i915_state.c
+++ b/src/mesa/drivers/dri/i915/i915_state.c
@@ -653,17 +653,14 @@ i915_update_sprite_point_enable(struct gl_context *ctx)
const GLbitfield64 inputsRead = p->FragProg.Base.InputsRead;
struct i915_context *i915 = i915_context(ctx);
GLuint s4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_VFMT_MASK;
-   int i;
GLuint coord_replace_bits = 0x0;
-   GLuint tex_coord_unit_bits = 0x0;
-
-   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
-  /* _NEW_POINT */
-  if (ctx->Point.CoordReplace[i] && ctx->Point.PointSprite)
- coord_replace_bits |= (1 << i);
-  if (inputsRead & VARYING_BIT_TEX(i))
- tex_coord_unit_bits |= (1 << i);
-   }
+
+   /* _NEW_POINT */
+   if (ctx->Point.PointSprite)
+  coord_replace_bits = ctx->Point.CoordReplaceBits;
+
+   GLuint tex_coord_unit_bits =
+  (GLuint)((inputsRead & VARYING_BITS_TEX_ANY) >> VARYING_SLOT_TEX0);
 
/*
 * Here we can't enable the SPRITE_POINT_ENABLE bit when the mis-match
-- 
2.5.5

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


[Mesa-dev] [PATCH 15/31] nouveau: Use bitmask/ffs to iterate enabled lights

2016-06-06 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.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/dri/nouveau/nouveau_state.c  |  9 +
 src/mesa/drivers/dri/nouveau/nv10_state_tnl.c | 26 +++---
 src/mesa/drivers/dri/nouveau/nv20_state_tnl.c | 26 +++---
 3 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/src/mesa/drivers/dri/nouveau/nouveau_state.c 
b/src/mesa/drivers/dri/nouveau/nouveau_state.c
index 3aad10e..26d0910 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_state.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_state.c
@@ -122,7 +122,7 @@ nouveau_draw_buffers(struct gl_context *ctx, GLsizei n, 
const GLenum *buffers)
 static void
 nouveau_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
 {
-   int i;
+   GLbitfield mask;
 
switch (cap) {
case GL_ALPHA_TEST:
@@ -187,9 +187,10 @@ nouveau_enable(struct gl_context *ctx, GLenum cap, 
GLboolean state)
context_dirty(ctx, LIGHT_MODEL);
context_dirty(ctx, LIGHT_ENABLE);
 
-   for (i = 0; i < MAX_LIGHTS; i++) {
-   if (ctx->Light.Light[i].Enabled)
-   context_dirty_i(ctx, LIGHT_SOURCE, i);
+   mask = ctx->Light._EnabledLights;
+   while (mask) {
+   const int i = _mesa_bit_scan(&mask);
+   context_dirty_i(ctx, LIGHT_SOURCE, i);
}
 
context_dirty(ctx, MATERIAL_FRONT_AMBIENT);
diff --git a/src/mesa/drivers/dri/nouveau/nv10_state_tnl.c 
b/src/mesa/drivers/dri/nouveau/nv10_state_tnl.c
index 1398385..e9e5e94 100644
--- a/src/mesa/drivers/dri/nouveau/nv10_state_tnl.c
+++ b/src/mesa/drivers/dri/nouveau/nv10_state_tnl.c
@@ -31,8 +31,6 @@
 #include "nv10_3d.xml.h"
 #include "nv10_driver.h"
 
-#include "util/simple_list.h"
-
 void
 nv10_emit_clip_plane(struct gl_context *ctx, int emit)
 {
@@ -323,7 +321,7 @@ nv10_emit_material_ambient(struct gl_context *ctx, int emit)
struct nouveau_pushbuf *push = context_push(ctx);
float (*mat)[4] = ctx->Light.Material.Attrib;
float c_scene[3], c_factor[3];
-   struct gl_light *l;
+   GLbitfield mask;
 
if (USE_COLOR_MATERIAL(AMBIENT)) {
COPY_3V(c_scene, ctx->Light.Model.Ambient);
@@ -347,8 +345,10 @@ nv10_emit_material_ambient(struct gl_context *ctx, int 
emit)
PUSH_DATAp(push, c_factor, 3);
}
 
-   foreach(l, &ctx->Light.EnabledList) {
-   const int i = l - ctx->Light.Light;
+   mask = ctx->Light._EnabledLights;
+   while (mask) {
+   const int i = _mesa_bit_scan(&mask);
+   struct gl_light *l = &ctx->Light.Light[i];
float *c_light = (USE_COLOR_MATERIAL(AMBIENT) ?
  l->Ambient :
  l->_MatAmbient[0]);
@@ -363,13 +363,15 @@ nv10_emit_material_diffuse(struct gl_context *ctx, int 
emit)
 {
struct nouveau_pushbuf *push = context_push(ctx);
GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
-   struct gl_light *l;
+   GLbitfield mask;
 
BEGIN_NV04(push, NV10_3D(MATERIAL_FACTOR_A), 1);
PUSH_DATAf(push, mat[MAT_ATTRIB_FRONT_DIFFUSE][3]);
 
-   foreach(l, &ctx->Light.EnabledList) {
-   const int i = l - ctx->Light.Light;
+   mask = ctx->Light._EnabledLights;
+   while (mask) {
+   const int i = _mesa_bit_scan(&mask);
+   struct gl_light *l = &ctx->Light.Light[i];
float *c_light = (USE_COLOR_MATERIAL(DIFFUSE) ?
  l->Diffuse :
  l->_MatDiffuse[0]);
@@ -383,10 +385,12 @@ void
 nv10_emit_material_specular(struct gl_context *ctx, int emit)
 {
struct nouveau_pushbuf *push = context_push(ctx);
-   struct gl_light *l;
+   GLbitfield mask;
 
-   foreach(l, &ctx->Light.EnabledList) {
-   const int i = l - ctx->Light.Light;
+   mask = ctx->Light._EnabledLights;
+   while (mask) {
+   const int i = _mesa_bit_scan(&mask);
+   struct gl_light *l = &ctx->Light.Light[i];
float *c_light = (USE_COLOR_MATERIAL(SPECULAR) ?
  l->Specular :
  l->_MatSpecular[0]);
diff --git a/src/mesa/drivers/dri/nouveau/nv20_state_tnl.c 
b/src/mesa/drivers/dri/nouveau/nv20_state_tnl.c
index 4139551..3cdba4a 100644
--- a/src/mesa/drivers/dri/nouveau/nv20_state_tnl.c
+++ b/src/mesa/drivers/dri/nouveau/nv20_state_tnl.c
@@ -32,8 +32,6 @@
 #include "nv10_driver.h"
 #include "nv20_driver.h"
 
-#include "util/simple_list.h"
-
 #define LIGHT_MODEL_AMBIENT_R(side)\
((side) ? N

[Mesa-dev] [PATCH 10/31] mesa: Rename CoordReplaceBits back to CoordReplace.

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

It used to be called like that and fits better with 80 columns.

Reviewed-by: Brian Paul 
Reviewed-by: Ian Romanick 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/dri/i915/i915_state.c  |  2 +-
 src/mesa/drivers/dri/i965/brw_sf.c  |  2 +-
 src/mesa/drivers/dri/i965/brw_vs.c  |  2 +-
 src/mesa/drivers/dri/i965/gen6_sf_state.c   |  2 +-
 src/mesa/drivers/dri/r200/r200_state.c  |  2 +-
 src/mesa/main/attrib.c  |  2 +-
 src/mesa/main/ffvertex_prog.c   |  2 +-
 src/mesa/main/mtypes.h  |  2 +-
 src/mesa/main/points.c  |  2 +-
 src/mesa/main/texenv.c  | 12 ++--
 src/mesa/state_tracker/st_atom_rasterizer.c |  2 +-
 src/mesa/swrast/s_points.c  |  2 +-
 12 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/mesa/drivers/dri/i915/i915_state.c 
b/src/mesa/drivers/dri/i915/i915_state.c
index 4c4bb09..39abe1b 100644
--- a/src/mesa/drivers/dri/i915/i915_state.c
+++ b/src/mesa/drivers/dri/i915/i915_state.c
@@ -657,7 +657,7 @@ i915_update_sprite_point_enable(struct gl_context *ctx)
 
/* _NEW_POINT */
if (ctx->Point.PointSprite)
-  coord_replace_bits = ctx->Point.CoordReplaceBits;
+  coord_replace_bits = ctx->Point.CoordReplace;
 
GLuint tex_coord_unit_bits =
   (GLuint)((inputsRead & VARYING_BITS_TEX_ANY) >> VARYING_SLOT_TEX0);
diff --git a/src/mesa/drivers/dri/i965/brw_sf.c 
b/src/mesa/drivers/dri/i965/brw_sf.c
index bbfa2c6..dff3461 100644
--- a/src/mesa/drivers/dri/i965/brw_sf.c
+++ b/src/mesa/drivers/dri/i965/brw_sf.c
@@ -190,7 +190,7 @@ brw_upload_sf_prog(struct brw_context *brw)
/* _NEW_POINT */
key.do_point_sprite = ctx->Point.PointSprite;
if (key.do_point_sprite) {
-  key.point_sprite_coord_replace = ctx->Point.CoordReplaceBits & 0xff;
+  key.point_sprite_coord_replace = ctx->Point.CoordReplace & 0xff;
}
if (brw->fragment_program->Base.InputsRead & 
BITFIELD64_BIT(VARYING_SLOT_PNTC))
   key.do_point_coord = 1;
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c 
b/src/mesa/drivers/dri/i965/brw_vs.c
index e5796b3..13e8949 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -331,7 +331,7 @@ brw_vs_populate_key(struct brw_context *brw,
 
/* _NEW_POINT */
if (brw->gen < 6 && ctx->Point.PointSprite) {
-  key->point_coord_replace = ctx->Point.CoordReplaceBits & 0xff;
+  key->point_coord_replace = ctx->Point.CoordReplace & 0xff;
}
 
/* _NEW_TEXTURE */
diff --git a/src/mesa/drivers/dri/i965/gen6_sf_state.c 
b/src/mesa/drivers/dri/i965/gen6_sf_state.c
index 309464f..32dd8c4 100644
--- a/src/mesa/drivers/dri/i965/gen6_sf_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_sf_state.c
@@ -214,7 +214,7 @@ calculate_attr_overrides(const struct brw_context *brw,
   if (drawing_points) {
  if (brw->ctx.Point.PointSprite &&
  (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7) &&
- (brw->ctx.Point.CoordReplaceBits & (1u << (attr - 
VARYING_SLOT_TEX0 {
+ (brw->ctx.Point.CoordReplace & (1u << (attr - 
VARYING_SLOT_TEX0 {
 point_sprite = true;
  }
 
diff --git a/src/mesa/drivers/dri/r200/r200_state.c 
b/src/mesa/drivers/dri/r200/r200_state.c
index e2a56d5..f0693ba 100644
--- a/src/mesa/drivers/dri/r200/r200_state.c
+++ b/src/mesa/drivers/dri/r200/r200_state.c
@@ -1852,7 +1852,7 @@ static void r200Enable( struct gl_context *ctx, GLenum 
cap, GLboolean state )
   R200_STATECHANGE( rmesa, spr );
   if ( state ) {
 rmesa->hw.spr.cmd[SPR_POINT_SPRITE_CNTL] |= R200_PS_GEN_TEX_MASK &
-(ctx->Point.CoordReplaceBits << R200_PS_GEN_TEX_0_SHIFT);
+(ctx->Point.CoordReplace << R200_PS_GEN_TEX_0_SHIFT);
   } else {
 rmesa->hw.spr.cmd[SPR_POINT_SPRITE_CNTL] &= ~R200_PS_GEN_TEX_MASK;
   }
diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index 6f39cb0..52a8ba6 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -1247,7 +1247,7 @@ _mesa_PopAttrib(void)
   GLuint u;
   for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
  _mesa_TexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV,
-   !!(point->CoordReplaceBits & (1u << u)));
+   !!(point->CoordReplace & (1u << u)));
   }
   _mesa_set_enable(ctx, GL_POINT_SPRITE_NV,point->PointSprite);
   if (ctx->Extensions.NV_point_sprite)
diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c
index adf71dc..ecdd018 100644
--- a/src/mesa/main/ffvertex_prog.c
+++ b/src/mesa/main/ffvertex_prog.c
@@ -243,7 +243,7 @@ static void make_state_key( struct gl_context *ctx, struct 
state_key *key )
 key->unit[i].texunit_really_enabled = 1;
 
   if (ctx->Point.PointSprite)
-if (ctx

[Mesa-dev] [PATCH 04/31] swrast: Convert swrast to use CoordsReplaceBits.

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

Switch over to use the CoordsReplaceBits bitmask.

Reviewed-by: Brian Paul 
Reviewed-by: Ian Romanick 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/swrast/s_points.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/mesa/swrast/s_points.c b/src/mesa/swrast/s_points.c
index 3163b04..8212850 100644
--- a/src/mesa/swrast/s_points.c
+++ b/src/mesa/swrast/s_points.c
@@ -139,8 +139,8 @@ sprite_point(struct gl_context *ctx, const SWvertex *vert)
  if (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7) {
 /* a texcoord attribute */
 const GLuint u = attr - VARYING_SLOT_TEX0;
-assert(u < ARRAY_SIZE(ctx->Point.CoordReplace));
-if (ctx->Point.CoordReplace[u]) {
+assert(u < MAX_TEXTURE_COORD_UNITS);
+if (ctx->Point.CoordReplaceBits & (1u << u)) {
tCoords[numTcoords++] = attr;
 
if (ctx->Point.SpriteRMode == GL_ZERO)
-- 
2.5.5

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


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

2016-06-06 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.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/dri/r200/r200_state.c | 39 ++--
 src/mesa/drivers/dri/radeon/radeon_state.c | 41 +++---
 2 files changed, 39 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..12efe18 100644
--- a/src/mesa/drivers/dri/r200/r200_state.c
+++ b/src/mesa/drivers/dri/r200/r200_state.c
@@ -1112,27 +1112,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 = &ctx->Light.Light[p];
-   GLfloat *fcmd = (GLfloat *)R200_DB_STATE( lit[p] );
-
-   if (l->EyePosition[3] == 0.0) {
-  COPY_3FV( &fcmd[LIT_POSITION_X], l->_VP_inf_norm );
-  COPY_3FV( &fcmd[LIT_DIRECTION_X], l->_h_inf_norm );
-  fcmd[LIT_POSITION_W] = 0;
-  fcmd[LIT_DIRECTION_W] = 0;
-   } else {
-  COPY_4V( &fcmd[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 = _mesa_bit_scan(&mask);
+ struct gl_light *l = &ctx->Light.Light[p];
+ GLfloat *fcmd = (GLfloat *)R200_DB_STATE( lit[p] );
+
+ if (l->EyePosition[3] == 0.0) {
+COPY_3FV( &fcmd[LIT_POSITION_X], l->_VP_inf_norm );
+COPY_3FV( &fcmd[LIT_DIRECTION_X], l->_h_inf_norm );
+fcmd[LIT_POSITION_W] = 0;
+fcmd[LIT_DIRECTION_W] = 0;
+ } else {
+COPY_4V( &fcmd[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, &rmesa->hw.lit[p] );
-}
+ R200_DB_STATECHANGE( rmesa, &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..41a4d04 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state.c
@@ -892,27 +892,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 = &ctx->Light.Light[p];
-   GLfloat *fcmd = (GLfloat *)RADEON_DB_STATE( lit[p] );
-
-   if (l->EyePosition[3] == 0.0) {
-  COPY_3FV( &fcmd[LIT_POSITION_X], l->_VP_inf_norm );
-  COPY_3FV( &fcmd[LIT_DIRECTION_X], l->_h_inf_norm );
-  fcmd[LIT_POSITION_W] = 0;
-  fcmd[LIT_DIRECTION_W] = 0;
-   } else {
-  COPY_4V( &fcmd[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, &rmesa->hw.lit[p] );
-}
+  GLbitfield mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int p = _mesa_bit_scan(&mask);
+ struct gl_light *l = &ctx->Light.Light[p];
+ GLfloat *fcmd = (GLfloat *)RADEON_DB_STATE( lit[p] );
+
+ if (l->EyePosition[3] == 0.0) {
+COPY_3FV( &fcmd[LIT_POSITION_X], l->_VP_inf_norm );
+COPY_3FV( &fcmd[LIT_DIRECTION_X], l->_h_inf_norm );
+fcmd[LIT_POSITION_W] = 0;
+fcmd[LIT_DIRECTION_W] = 0;
+ } else {
+COPY_4V( &fcmd[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, &rmesa->hw.lit[p] );
   }
}
 }
-- 
2.5.5

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


[Mesa-dev] [PATCH 18/31] mesa: Remove the linked list of enabled lights

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

Clean up after conversion to bitmasks.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/context.c | 11 +--
 src/mesa/main/enable.c  |  4 
 src/mesa/main/light.c   |  4 
 src/mesa/main/mtypes.h  |  4 
 4 files changed, 1 insertion(+), 22 deletions(-)

diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 172c854..a99a54e 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -120,7 +120,6 @@
 #include "shared.h"
 #include "shaderobj.h"
 #include "shaderimage.h"
-#include "util/simple_list.h"
 #include "util/strtod.h"
 #include "state.h"
 #include "stencil.h"
@@ -1453,16 +1452,8 @@ _mesa_copy_context( const struct gl_context *src, struct 
gl_context *dst,
   dst->Hint = src->Hint;
}
if (mask & GL_LIGHTING_BIT) {
-  GLuint i;
-  /* begin with memcpy */
+  /* OK to memcpy */
   dst->Light = src->Light;
-  /* fixup linked lists to prevent pointer insanity */
-  make_empty_list( &(dst->Light.EnabledList) );
-  for (i = 0; i < MAX_LIGHTS; i++) {
- if (dst->Light.Light[i].Enabled) {
-insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i]));
- }
-  }
}
if (mask & GL_LINE_BIT) {
   /* OK to memcpy */
diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
index bc59280..1468a45 100644
--- a/src/mesa/main/enable.c
+++ b/src/mesa/main/enable.c
@@ -35,7 +35,6 @@
 #include "enable.h"
 #include "errors.h"
 #include "light.h"
-#include "util/simple_list.h"
 #include "mtypes.h"
 #include "enums.h"
 #include "api_arrayelt.h"
@@ -403,12 +402,9 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, 
GLboolean state)
  ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
  if (state) {
 ctx->Light._EnabledLights |= 1u << (cap - GL_LIGHT0);
-insert_at_tail(&ctx->Light.EnabledList,
-   &ctx->Light.Light[cap-GL_LIGHT0]);
  }
  else {
 ctx->Light._EnabledLights &= ~(1u << (cap - GL_LIGHT0));
-remove_from_list(&ctx->Light.Light[cap-GL_LIGHT0]);
  }
  break;
   case GL_LIGHTING:
diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
index 49e99ce..ae723e8 100644
--- a/src/mesa/main/light.c
+++ b/src/mesa/main/light.c
@@ -31,7 +31,6 @@
 #include "enums.h"
 #include "light.h"
 #include "macros.h"
-#include "util/simple_list.h"
 #include "mtypes.h"
 #include "math/m_matrix.h"
 
@@ -1121,8 +1120,6 @@ _mesa_allow_light_in_model( struct gl_context *ctx, 
GLboolean flag )
 static void
 init_light( struct gl_light *l, GLuint n )
 {
-   make_empty_list( l );
-
ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
if (n==0) {
   ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
@@ -1196,7 +1193,6 @@ _mesa_init_lighting( struct gl_context *ctx )
for (i = 0; i < MAX_LIGHTS; i++) {
   init_light( &ctx->Light.Light[i], i );
}
-   make_empty_list( &ctx->Light.EnabledList );
 
init_lightmodel( &ctx->Light.Model );
init_material( &ctx->Light.Material );
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index f0128cd..dcc471a 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -333,9 +333,6 @@ struct gl_material
  */
 struct gl_light
 {
-   struct gl_light *next;  /**< double linked list with sentinel */
-   struct gl_light *prev;
-
GLfloat Ambient[4]; /**< ambient color */
GLfloat Diffuse[4]; /**< diffuse color */
GLfloat Specular[4];/**< specular color */
@@ -634,7 +631,6 @@ struct gl_light_attrib
 
GLboolean _NeedEyeCoords;   
GLboolean _NeedVertices;/**< Use fast shader? */
-   struct gl_light EnabledList; /**< List sentinel */
 
GLfloat _BaseColor[2][3];
/*@}*/
-- 
2.5.5

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


[Mesa-dev] [PATCH 11/31] mesa: Track enabled lights in a bitmask

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

This enables some optimizations afterwards.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/enable.c | 2 ++
 src/mesa/main/light.c  | 1 +
 src/mesa/main/mtypes.h | 2 ++
 3 files changed, 5 insertions(+)

diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
index 1d674bf..bc59280 100644
--- a/src/mesa/main/enable.c
+++ b/src/mesa/main/enable.c
@@ -402,10 +402,12 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, 
GLboolean state)
  FLUSH_VERTICES(ctx, _NEW_LIGHT);
  ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
  if (state) {
+ctx->Light._EnabledLights |= 1u << (cap - GL_LIGHT0);
 insert_at_tail(&ctx->Light.EnabledList,
&ctx->Light.Light[cap-GL_LIGHT0]);
  }
  else {
+ctx->Light._EnabledLights &= ~(1u << (cap - GL_LIGHT0));
 remove_from_list(&ctx->Light.Light[cap-GL_LIGHT0]);
  }
  break;
diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
index 4a8dee3..a52efdb 100644
--- a/src/mesa/main/light.c
+++ b/src/mesa/main/light.c
@@ -1171,6 +1171,7 @@ _mesa_init_lighting( struct gl_context *ctx )
GLuint i;
 
/* Lighting group */
+   ctx->Light._EnabledLights = 0;
for (i = 0; i < MAX_LIGHTS; i++) {
   init_light( &ctx->Light.Light[i], i );
}
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index d7dd6ec..f0128cd 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -630,6 +630,8 @@ struct gl_light_attrib
 * Derived state for optimizations: 
 */
/*@{*/
+   GLbitfield _EnabledLights;  /**< bitmask containing enabled lights */
+
GLboolean _NeedEyeCoords;   
GLboolean _NeedVertices;/**< Use fast shader? */
struct gl_light EnabledList; /**< List sentinel */
-- 
2.5.5

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


[Mesa-dev] [PATCH 03/31] mesa: Add gl_point_attrib::CoordReplaceBits bitfield.

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

The aim is to replace the CoordReplace array by
a bitfield. Until all drivers are converted,
establish the bitfield in parallel to the
CoordReplace array.

v2: Fix bitmask logic.

Reviewed-by: Brian Paul 
Reviewed-by: Ian Romanick 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/attrib.c|  2 +-
 src/mesa/main/ffvertex_prog.c |  2 +-
 src/mesa/main/mtypes.h|  1 +
 src/mesa/main/points.c|  1 +
 src/mesa/main/texenv.c| 34 ++
 5 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index 61f7036..6f39cb0 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -1247,7 +1247,7 @@ _mesa_PopAttrib(void)
   GLuint u;
   for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
  _mesa_TexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV,
-   (GLint) point->CoordReplace[u]);
+   !!(point->CoordReplaceBits & (1u << u)));
   }
   _mesa_set_enable(ctx, GL_POINT_SPRITE_NV,point->PointSprite);
   if (ctx->Extensions.NV_point_sprite)
diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c
index d72bc71..adf71dc 100644
--- a/src/mesa/main/ffvertex_prog.c
+++ b/src/mesa/main/ffvertex_prog.c
@@ -243,7 +243,7 @@ static void make_state_key( struct gl_context *ctx, struct 
state_key *key )
 key->unit[i].texunit_really_enabled = 1;
 
   if (ctx->Point.PointSprite)
-if (ctx->Point.CoordReplace[i])
+if (ctx->Point.CoordReplaceBits & (1u << i))
key->unit[i].coord_replace = 1;
 
   if (ctx->Texture._TexMatEnabled & ENABLE_TEXMAT(i))
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 0f9b01d..5fb094f 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -757,6 +757,7 @@ struct gl_point_attrib
GLboolean _Attenuated;  /**< True if Params != [1, 0, 0] */
GLboolean PointSprite;  /**< GL_NV/ARB_point_sprite */
GLboolean CoordReplace[MAX_TEXTURE_COORD_UNITS]; /**< GL_ARB_point_sprite*/
+   GLbitfield CoordReplaceBits; /**< GL_ARB_point_sprite*/
GLenum SpriteRMode; /**< GL_NV_point_sprite (only!) */
GLenum SpriteOrigin;/**< GL_ARB_point_sprite */
 };
diff --git a/src/mesa/main/points.c b/src/mesa/main/points.c
index c2f2b63..3fbd5d3 100644
--- a/src/mesa/main/points.c
+++ b/src/mesa/main/points.c
@@ -256,4 +256,5 @@ _mesa_init_point(struct gl_context *ctx)
for (i = 0; i < ARRAY_SIZE(ctx->Point.CoordReplace); i++) {
   ctx->Point.CoordReplace[i] = GL_FALSE; /* GL_ARB/NV_point_sprite */
}
+   ctx->Point.CoordReplaceBits = 0; /* GL_ARB/NV_point_sprite */
 }
diff --git a/src/mesa/main/texenv.c b/src/mesa/main/texenv.c
index 93c6806..2cf322d 100644
--- a/src/mesa/main/texenv.c
+++ b/src/mesa/main/texenv.c
@@ -460,20 +460,24 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const 
GLfloat *param )
 return;
   }
   if (pname == GL_COORD_REPLACE_NV) {
- if (iparam0 == GL_TRUE || iparam0 == GL_FALSE) {
-/* It's kind of weird to set point state via glTexEnv,
- * but that's what the spec calls for.
- */
-const GLboolean state = (GLboolean) iparam0;
-if (ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] == state)
+ /* It's kind of weird to set point state via glTexEnv,
+  * but that's what the spec calls for.
+  */
+ if (iparam0 == GL_TRUE) {
+if (ctx->Point.CoordReplaceBits & (1u << ctx->Texture.CurrentUnit))
return;
-FLUSH_VERTICES(ctx, _NEW_POINT);
-ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] = state;
- }
- else {
+ctx->Point.CoordReplaceBits |= (1u << ctx->Texture.CurrentUnit);
+ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] = GL_TRUE;
+ } else if (iparam0 == GL_FALSE) {
+if (~(ctx->Point.CoordReplaceBits) & (1u << 
ctx->Texture.CurrentUnit))
+   return;
+ctx->Point.CoordReplaceBits &= ~(1u << ctx->Texture.CurrentUnit);
+ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] = GL_FALSE;
+ } else {
 _mesa_error( ctx, GL_INVALID_VALUE, "glTexEnv(param=0x%x)", 
iparam0);
 return;
  }
+ FLUSH_VERTICES(ctx, _NEW_POINT);
   }
   else {
  _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname=0x%x)", pname );
@@ -675,7 +679,10 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat 
*params )
  return;
   }
   if (pname == GL_COORD_REPLACE_NV) {
- *params = (GLfloat) ctx->Point.CoordReplace[ctx->Texture.CurrentUnit];
+ if (ctx->Point.CoordReplaceBits & (1u << ctx->Texture.CurrentUnit))
+*params = 1.0f;
+ else
+ 

[Mesa-dev] [PATCH 20/31] mesa: Use bitmask/ffs to build ff fragment shader keys.

2016-06-06 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.
The bitmask used here for iteration is a combination
of different enabled masks present for texture units.

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

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/ff_fragment_shader.cpp | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/ff_fragment_shader.cpp 
b/src/mesa/main/ff_fragment_shader.cpp
index 26bf162..f2f4514 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -398,22 +398,25 @@ static GLbitfield get_fp_input_mask( struct gl_context 
*ctx )
  */
 static GLuint make_state_key( struct gl_context *ctx,  struct state_key *key )
 {
-   GLuint i, j;
+   GLuint j;
GLbitfield inputs_referenced = VARYING_BIT_COL0;
const GLbitfield inputs_available = get_fp_input_mask( ctx );
+   GLbitfield mask;
GLuint keySize;
 
memset(key, 0, sizeof(*key));
 
/* _NEW_TEXTURE */
-   for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
+   mask = ctx->Texture._EnabledCoordUnits;
+   while (mask) {
+  const int i = _mesa_bit_scan(&mask);
   const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
   const struct gl_texture_object *texObj = texUnit->_Current;
   const struct gl_tex_env_combine_state *comb = texUnit->_CurrentCombine;
   const struct gl_sampler_object *samp;
   GLenum format;
 
-  if (!texUnit->_Current || !texUnit->Enabled)
+  if (!texObj)
  continue;
 
   samp = _mesa_get_samplerobj(ctx, i);
-- 
2.5.5

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


[Mesa-dev] [PATCH 12/31] mesa: Use bitmask/ffs to iterate enabled lights

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

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 
Signed-off-by: Mathias Fröhlich 
---
 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 "

[Mesa-dev] [PATCH 14/31] tnl: Use bitmask/ffs to iterate enabled lights

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

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 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/tnl/t_vb_light.c|  3 ++-
 src/mesa/tnl/t_vb_lighttmp.h | 24 +---
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/mesa/tnl/t_vb_light.c b/src/mesa/tnl/t_vb_light.c
index 029265a..67daddd 100644
--- a/src/mesa/tnl/t_vb_light.c
+++ b/src/mesa/tnl/t_vb_light.c
@@ -394,7 +394,8 @@ static void validate_lighting( struct gl_context *ctx,
 tab = _tnl_light_tab;
}
else {
-  if (ctx->Light.EnabledList.next == ctx->Light.EnabledList.prev)
+  /* Power of two means only a single active light. */
+  if (_mesa_is_pow_two(ctx->Light._EnabledLights))
 tab = _tnl_light_fast_single_tab;
   else
 tab = _tnl_light_fast_tab;
diff --git a/src/mesa/tnl/t_vb_lighttmp.h b/src/mesa/tnl/t_vb_lighttmp.h
index 3aebcd4..994afd2 100644
--- a/src/mesa/tnl/t_vb_lighttmp.h
+++ b/src/mesa/tnl/t_vb_lighttmp.h
@@ -87,7 +87,7 @@ static void TAG(light_rgba_spec)( struct gl_context *ctx,
 
for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) {
   GLfloat sum[2][3], spec[2][3];
-  struct gl_light *light;
+  GLbitfield mask;
 
 #if IDX & LIGHT_MATERIAL
   update_materials( ctx, store );
@@ -106,7 +106,10 @@ static void TAG(light_rgba_spec)( struct gl_context *ctx,
 #endif
 
   /* Add contribution from each enabled light source */
-  foreach (light, &ctx->Light.EnabledList) {
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int l = _mesa_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[l];
 GLfloat n_dot_h;
 GLfloat correction;
 GLint side;
@@ -265,7 +268,7 @@ static void TAG(light_rgba)( struct gl_context *ctx,
 
for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) {
   GLfloat sum[2][3];
-  struct gl_light *light;
+  GLbitfield mask;
 
 #if IDX & LIGHT_MATERIAL
   update_materials( ctx, store );
@@ -282,7 +285,10 @@ static void TAG(light_rgba)( struct gl_context *ctx,
 #endif
 
   /* Add contribution from each enabled light source */
-  foreach (light, &ctx->Light.EnabledList) {
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int l = _mesa_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[l];
 GLfloat n_dot_h;
 GLfloat correction;
 GLint side;
@@ -417,7 +423,8 @@ static void TAG(light_fast_rgba_single)( struct gl_context 
*ctx,
 #if IDX & LIGHT_TWOSIDE
GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data;
 #endif
-   const struct gl_light *light = ctx->Light.EnabledList.next;
+   const struct gl_light *light =
+  &ctx->Light.Light[ffs(ctx->Light._EnabledLights) - 1];
GLuint j = 0;
GLfloat base[2][4];
 #if IDX & LIGHT_MATERIAL
@@ -528,7 +535,6 @@ static void TAG(light_fast_rgba)( struct gl_context *ctx,
 #else
const GLuint nr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->count;
 #endif
-   const struct gl_light *light;
 
 #ifdef TRACE
fprintf(stderr, "%s %d\n", __func__, nr );
@@ -556,6 +562,7 @@ static void TAG(light_fast_rgba)( struct gl_context *ctx,
for (j = 0; j < nr; j++, STRIDE_F(normal,nstride)) {
 
   GLfloat sum[2][3];
+  GLbitfield mask;
 
 #if IDX & LIGHT_MATERIAL
   update_materials( ctx, store );
@@ -572,7 +579,10 @@ static void TAG(light_fast_rgba)( struct gl_context *ctx,
   COPY_3V(sum[1], ctx->Light._BaseColor[1]);
 #endif
 
-  foreach (light, &ctx->Light.EnabledList) {
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int l = _mesa_bit_scan(&mask);
+ const struct gl_light *light = &ctx->Light.Light[l];
 GLfloat n_dot_h, n_dot_VP, spec;
 
 ACC_3V(sum[0], light->_MatAmbient[0]);
-- 
2.5.5

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


[Mesa-dev] [PATCH 13/31] mesa: Use bitmask/ffs to iterate enabled lights for ff shader keys.

2016-06-06 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.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/ffvertex_prog.c | 27 ++-
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c
index ecdd018..b3c5d8c 100644
--- a/src/mesa/main/ffvertex_prog.c
+++ b/src/mesa/main/ffvertex_prog.c
@@ -148,6 +148,7 @@ static GLboolean check_active_shininess( struct gl_context 
*ctx,
 static void make_state_key( struct gl_context *ctx, struct state_key *key )
 {
const struct gl_fragment_program *fp;
+   GLbitfield mask;
GLuint i;
 
memset(key, 0, sizeof(struct state_key));
@@ -183,23 +184,23 @@ static void make_state_key( struct gl_context *ctx, 
struct state_key *key )
 key->light_color_material_mask = ctx->Light._ColorMaterialBitmask;
   }
 
-  for (i = 0; i < MAX_LIGHTS; i++) {
-struct gl_light *light = &ctx->Light.Light[i];
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int i = _mesa_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[i];
 
-if (light->Enabled) {
-   key->unit[i].light_enabled = 1;
+ key->unit[i].light_enabled = 1;
 
-   if (light->EyePosition[3] == 0.0F)
-  key->unit[i].light_eyepos3_is_zero = 1;
+ if (light->EyePosition[3] == 0.0F)
+key->unit[i].light_eyepos3_is_zero = 1;
 
-   if (light->SpotCutoff == 180.0F)
-  key->unit[i].light_spotcutoff_is_180 = 1;
+ if (light->SpotCutoff == 180.0F)
+key->unit[i].light_spotcutoff_is_180 = 1;
 
-   if (light->ConstantAttenuation != 1.0F ||
-   light->LinearAttenuation != 0.0F ||
-   light->QuadraticAttenuation != 0.0F)
-  key->unit[i].light_attenuated = 1;
-}
+ if (light->ConstantAttenuation != 1.0F ||
+ light->LinearAttenuation != 0.0F ||
+ light->QuadraticAttenuation != 0.0F)
+key->unit[i].light_attenuated = 1;
   }
 
   if (check_active_shininess(ctx, key, 0)) {
-- 
2.5.5

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


[Mesa-dev] [PATCH 17/31] mesa: Switch to bitmask based enabled lights in gen_matypes.c

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

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/x86/gen_matypes.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/mesa/x86/gen_matypes.c b/src/mesa/x86/gen_matypes.c
index 18ffb72..fc06dc7 100644
--- a/src/mesa/x86/gen_matypes.c
+++ b/src/mesa/x86/gen_matypes.c
@@ -125,7 +125,7 @@ int main( int argc, char **argv )
OFFSET( "CTX_LIGHT_COLOR_MAT_MODE", struct gl_context, 
Light.ColorMaterialMode );
OFFSET( "CTX_LIGHT_COLOR_MAT_MASK", struct gl_context, 
Light._ColorMaterialBitmask );
OFFSET( "CTX_LIGHT_COLOR_MAT_ENABLED ", struct gl_context, 
Light.ColorMaterialEnabled );
-   OFFSET( "CTX_LIGHT_ENABLED_LIST  ", struct gl_context, 
Light.EnabledList );
+   OFFSET( "CTX_LIGHT_ENABLED_LIGHTS", struct gl_context, 
Light._EnabledLights );
OFFSET( "CTX_LIGHT_NEED_VERTS", struct gl_context, 
Light._NeedVertices );
OFFSET( "CTX_LIGHT_BASE_COLOR", struct gl_context, Light._BaseColor 
);
 
@@ -208,8 +208,6 @@ int main( int argc, char **argv )
 */
OFFSET_HEADER( "struct gl_light" );
 
-   OFFSET( "LIGHT_NEXT  ", struct gl_light, next );
-   OFFSET( "LIGHT_PREV  ", struct gl_light, prev );
printf( "\n" );
OFFSET( "LIGHT_AMBIENT   ", struct gl_light, Ambient );
OFFSET( "LIGHT_DIFFUSE   ", struct gl_light, Diffuse );
-- 
2.5.5

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


[Mesa-dev] [PATCH 06/31] r200: convert r200 to use CoordsReplaceBits.

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

Switch over to use the CoordsReplaceBits bitmask.

Reviewed-by: Brian Paul 
Reviewed-by: Ian Romanick 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/dri/r200/r200_state.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/mesa/drivers/dri/r200/r200_state.c 
b/src/mesa/drivers/dri/r200/r200_state.c
index b4acf98..e2a56d5 100644
--- a/src/mesa/drivers/dri/r200/r200_state.c
+++ b/src/mesa/drivers/dri/r200/r200_state.c
@@ -1851,11 +1851,8 @@ static void r200Enable( struct gl_context *ctx, GLenum 
cap, GLboolean state )
case GL_POINT_SPRITE_ARB:
   R200_STATECHANGE( rmesa, spr );
   if ( state ) {
-int i;
-for (i = 0; i < 6; i++) {
-   rmesa->hw.spr.cmd[SPR_POINT_SPRITE_CNTL] |=
-   ctx->Point.CoordReplace[i] << (R200_PS_GEN_TEX_0_SHIFT + i);
-}
+rmesa->hw.spr.cmd[SPR_POINT_SPRITE_CNTL] |= R200_PS_GEN_TEX_MASK &
+(ctx->Point.CoordReplaceBits << R200_PS_GEN_TEX_0_SHIFT);
   } else {
 rmesa->hw.spr.cmd[SPR_POINT_SPRITE_CNTL] &= ~R200_PS_GEN_TEX_MASK;
   }
-- 
2.5.5

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


[Mesa-dev] [PATCH 08/31] i965: Convert i965 to use CoordsReplaceBits.

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

Switch over to use the CoordsReplaceBits bitmask.

Reviewed-by: Brian Paul 
Reviewed-by: Ian Romanick 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/dri/i965/brw_sf.c| 7 +--
 src/mesa/drivers/dri/i965/brw_vs.c| 6 +-
 src/mesa/drivers/dri/i965/gen6_sf_state.c | 2 +-
 3 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_sf.c 
b/src/mesa/drivers/dri/i965/brw_sf.c
index c85d8bc..bbfa2c6 100644
--- a/src/mesa/drivers/dri/i965/brw_sf.c
+++ b/src/mesa/drivers/dri/i965/brw_sf.c
@@ -190,12 +190,7 @@ brw_upload_sf_prog(struct brw_context *brw)
/* _NEW_POINT */
key.do_point_sprite = ctx->Point.PointSprite;
if (key.do_point_sprite) {
-  int i;
-
-  for (i = 0; i < 8; i++) {
-if (ctx->Point.CoordReplace[i])
-   key.point_sprite_coord_replace |= (1 << i);
-  }
+  key.point_sprite_coord_replace = ctx->Point.CoordReplaceBits & 0xff;
}
if (brw->fragment_program->Base.InputsRead & 
BITFIELD64_BIT(VARYING_SLOT_PNTC))
   key.do_point_coord = 1;
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c 
b/src/mesa/drivers/dri/i965/brw_vs.c
index abf03b1..e5796b3 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -301,7 +301,6 @@ brw_vs_populate_key(struct brw_context *brw,
struct brw_vertex_program *vp =
   (struct brw_vertex_program *)brw->vertex_program;
struct gl_program *prog = (struct gl_program *) brw->vertex_program;
-   int i;
 
memset(key, 0, sizeof(*key));
 
@@ -332,10 +331,7 @@ brw_vs_populate_key(struct brw_context *brw,
 
/* _NEW_POINT */
if (brw->gen < 6 && ctx->Point.PointSprite) {
-  for (i = 0; i < 8; i++) {
-if (ctx->Point.CoordReplace[i])
-key->point_coord_replace |= (1 << i);
-  }
+  key->point_coord_replace = ctx->Point.CoordReplaceBits & 0xff;
}
 
/* _NEW_TEXTURE */
diff --git a/src/mesa/drivers/dri/i965/gen6_sf_state.c 
b/src/mesa/drivers/dri/i965/gen6_sf_state.c
index 0538ab7..309464f 100644
--- a/src/mesa/drivers/dri/i965/gen6_sf_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_sf_state.c
@@ -214,7 +214,7 @@ calculate_attr_overrides(const struct brw_context *brw,
   if (drawing_points) {
  if (brw->ctx.Point.PointSprite &&
  (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7) &&
- brw->ctx.Point.CoordReplace[attr - VARYING_SLOT_TEX0]) {
+ (brw->ctx.Point.CoordReplaceBits & (1u << (attr - 
VARYING_SLOT_TEX0 {
 point_sprite = true;
  }
 
-- 
2.5.5

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


[Mesa-dev] [PATCH 19/31] mesa: Use bitmask/ffs to build ff vertex shader keys.

2016-06-06 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.
The bitmask used here for iteration is a combination
of different enabled masks present for texture units.

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

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/ffvertex_prog.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c
index b3c5d8c..242a136 100644
--- a/src/mesa/main/ffvertex_prog.c
+++ b/src/mesa/main/ffvertex_prog.c
@@ -149,7 +149,6 @@ static void make_state_key( struct gl_context *ctx, struct 
state_key *key )
 {
const struct gl_fragment_program *fp;
GLbitfield mask;
-   GLuint i;
 
memset(key, 0, sizeof(struct state_key));
fp = ctx->FragmentProgram._Current;
@@ -237,7 +236,10 @@ static void make_state_key( struct gl_context *ctx, struct 
state_key *key )
ctx->Texture._MaxEnabledTexImageUnit != -1)
   key->texture_enabled_global = 1;
 
-   for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) {
+   mask = ctx->Texture._EnabledCoordUnits | ctx->Texture._TexGenEnabled
+  | ctx->Texture._TexMatEnabled | ctx->Point.CoordReplace;
+   while (mask) {
+  const int i = _mesa_bit_scan(&mask);
   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
 
   if (texUnit->_Current)
-- 
2.5.5

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


[Mesa-dev] [PATCH 09/31] mesa: Remove the now unused CoordsReplace array.

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

Now that all users are converted, remove the array.

Reviewed-by: Brian Paul 
Reviewed-by: Ian Romanick 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/mtypes.h | 1 -
 src/mesa/main/points.c | 5 -
 src/mesa/main/texenv.c | 2 --
 3 files changed, 8 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 5fb094f..1827991 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -756,7 +756,6 @@ struct gl_point_attrib
GLboolean SmoothFlag;   /**< True if GL_POINT_SMOOTH is enabled */
GLboolean _Attenuated;  /**< True if Params != [1, 0, 0] */
GLboolean PointSprite;  /**< GL_NV/ARB_point_sprite */
-   GLboolean CoordReplace[MAX_TEXTURE_COORD_UNITS]; /**< GL_ARB_point_sprite*/
GLbitfield CoordReplaceBits; /**< GL_ARB_point_sprite*/
GLenum SpriteRMode; /**< GL_NV_point_sprite (only!) */
GLenum SpriteOrigin;/**< GL_ARB_point_sprite */
diff --git a/src/mesa/main/points.c b/src/mesa/main/points.c
index 3fbd5d3..6bb1ce6 100644
--- a/src/mesa/main/points.c
+++ b/src/mesa/main/points.c
@@ -225,8 +225,6 @@ _mesa_PointParameterfv( GLenum pname, const GLfloat *params)
 void
 _mesa_init_point(struct gl_context *ctx)
 {
-   GLuint i;
-
ctx->Point.SmoothFlag = GL_FALSE;
ctx->Point.Size = 1.0;
ctx->Point.Params[0] = 1.0;
@@ -253,8 +251,5 @@ _mesa_init_point(struct gl_context *ctx)
 
ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite (only!) */
ctx->Point.SpriteOrigin = GL_UPPER_LEFT; /* GL_ARB_point_sprite */
-   for (i = 0; i < ARRAY_SIZE(ctx->Point.CoordReplace); i++) {
-  ctx->Point.CoordReplace[i] = GL_FALSE; /* GL_ARB/NV_point_sprite */
-   }
ctx->Point.CoordReplaceBits = 0; /* GL_ARB/NV_point_sprite */
 }
diff --git a/src/mesa/main/texenv.c b/src/mesa/main/texenv.c
index 2cf322d..1aa0d6c 100644
--- a/src/mesa/main/texenv.c
+++ b/src/mesa/main/texenv.c
@@ -467,12 +467,10 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const 
GLfloat *param )
 if (ctx->Point.CoordReplaceBits & (1u << ctx->Texture.CurrentUnit))
return;
 ctx->Point.CoordReplaceBits |= (1u << ctx->Texture.CurrentUnit);
-ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] = GL_TRUE;
  } else if (iparam0 == GL_FALSE) {
 if (~(ctx->Point.CoordReplaceBits) & (1u << 
ctx->Texture.CurrentUnit))
return;
 ctx->Point.CoordReplaceBits &= ~(1u << ctx->Texture.CurrentUnit);
-ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] = GL_FALSE;
  } else {
 _mesa_error( ctx, GL_INVALID_VALUE, "glTexEnv(param=0x%x)", 
iparam0);
 return;
-- 
2.5.5

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


[Mesa-dev] [PATCH 05/31] gallium: Convert the state_tracker to use CoordsReplaceBits.

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

Switch over to use the CoordsReplaceBits bitmask.

Reviewed-by: Brian Paul 
Reviewed-by: Ian Romanick 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/state_tracker/st_atom_rasterizer.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c 
b/src/mesa/state_tracker/st_atom_rasterizer.c
index ab5fa8f..37a3598 100644
--- a/src/mesa/state_tracker/st_atom_rasterizer.c
+++ b/src/mesa/state_tracker/st_atom_rasterizer.c
@@ -64,7 +64,6 @@ static void update_raster_state( struct st_context *st )
struct pipe_rasterizer_state *raster = &st->state.rasterizer;
const struct gl_vertex_program *vertProg = ctx->VertexProgram._Current;
const struct gl_fragment_program *fragProg = ctx->FragmentProgram._Current;
-   uint i;
 
memset(raster, 0, sizeof(*raster));
 
@@ -181,11 +180,8 @@ static void update_raster_state( struct st_context *st )
* that we need to replace GENERIC[k] attrib with an automatically
* computed texture coord.
*/
-  for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) {
- if (ctx->Point.CoordReplace[i]) {
-raster->sprite_coord_enable |= 1 << i;
- }
-  }
+  raster->sprite_coord_enable = ctx->Point.CoordReplaceBits &
+ ((1u << MAX_TEXTURE_COORD_UNITS) - 1);
   if (!st->needs_texcoord_semantic &&
   fragProg->Base.InputsRead & VARYING_BIT_PNTC) {
  raster->sprite_coord_enable |=
-- 
2.5.5

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


[Mesa-dev] [PATCH 30/31] vbo: Use a bitmask to track the active arrays in vbo_exec*.

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

The use of a bitmask makes functions iterating only active
attributes less visible in profiles.

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

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/vbo/vbo_exec.h  |   1 +
 src/mesa/vbo/vbo_exec_api.c  | 145 ++-
 src/mesa/vbo/vbo_exec_draw.c |   2 +
 3 files changed, 78 insertions(+), 70 deletions(-)

diff --git a/src/mesa/vbo/vbo_exec.h b/src/mesa/vbo/vbo_exec.h
index 27bff4a..9748ef2 100644
--- a/src/mesa/vbo/vbo_exec.h
+++ b/src/mesa/vbo/vbo_exec.h
@@ -101,6 +101,7 @@ struct vbo_exec_context
   GLuint max_vert; /**< Max number of vertices allowed in buffer */
   struct vbo_exec_copied_vtx copied;
 
+  GLbitfield64 enabled;/**< mask of enabled vbo arrays. */
   GLubyte attrsz[VBO_ATTRIB_MAX];   /**< nr. of attrib components (1..4) */
   GLenum attrtype[VBO_ATTRIB_MAX];  /**< GL_FLOAT, GL_DOUBLE, GL_INT, etc 
*/
   GLubyte active_sz[VBO_ATTRIB_MAX];  /**< attrib size (nr. 32-bit words) 
*/
diff --git a/src/mesa/vbo/vbo_exec_api.c b/src/mesa/vbo/vbo_exec_api.c
index 7534599..abf3c63 100644
--- a/src/mesa/vbo/vbo_exec_api.c
+++ b/src/mesa/vbo/vbo_exec_api.c
@@ -167,54 +167,56 @@ static void vbo_exec_copy_to_current( struct 
vbo_exec_context *exec )
 {
struct gl_context *ctx = exec->ctx;
struct vbo_context *vbo = vbo_context(ctx);
-   GLuint i;
+   GLbitfield64 enabled = exec->vtx.enabled & 
(~BITFIELD64_BIT(VBO_ATTRIB_POS));
 
-   for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) {
-  if (exec->vtx.attrsz[i]) {
- /* Note: the exec->vtx.current[i] pointers point into the
-  * ctx->Current.Attrib and ctx->Light.Material.Attrib arrays.
-  */
-GLfloat *current = (GLfloat *)vbo->currval[i].Ptr;
- fi_type tmp[8]; /* space for doubles */
- int dmul = exec->vtx.attrtype[i] == GL_DOUBLE ? 2 : 1;
-
- if (exec->vtx.attrtype[i] == GL_DOUBLE) {
-memset(tmp, 0, sizeof(tmp));
-memcpy(tmp, exec->vtx.attrptr[i], exec->vtx.attrsz[i] * 
sizeof(GLfloat));
- } else {
-COPY_CLEAN_4V_TYPE_AS_UNION(tmp,
-exec->vtx.attrsz[i],
-exec->vtx.attrptr[i],
-exec->vtx.attrtype[i]);
- }
+   while (enabled) {
+  const int i = _mesa_bit_scan64(&enabled);
+
+  /* Note: the exec->vtx.current[i] pointers point into the
+   * ctx->Current.Attrib and ctx->Light.Material.Attrib arrays.
+   */
+  GLfloat *current = (GLfloat *)vbo->currval[i].Ptr;
+  fi_type tmp[8]; /* space for doubles */
+  int dmul = exec->vtx.attrtype[i] == GL_DOUBLE ? 2 : 1;
+
+  assert(exec->vtx.attrsz[i]);
+
+  if (exec->vtx.attrtype[i] == GL_DOUBLE) {
+ memset(tmp, 0, sizeof(tmp));
+ memcpy(tmp, exec->vtx.attrptr[i], exec->vtx.attrsz[i] * 
sizeof(GLfloat));
+  } else {
+ COPY_CLEAN_4V_TYPE_AS_UNION(tmp,
+ exec->vtx.attrsz[i],
+ exec->vtx.attrptr[i],
+ exec->vtx.attrtype[i]);
+  }
 
- if (exec->vtx.attrtype[i] != vbo->currval[i].Type ||
- memcmp(current, tmp, 4 * sizeof(GLfloat) * dmul) != 0) {
-memcpy(current, tmp, 4 * sizeof(GLfloat) * dmul);
+  if (exec->vtx.attrtype[i] != vbo->currval[i].Type ||
+  memcmp(current, tmp, 4 * sizeof(GLfloat) * dmul) != 0) {
+ memcpy(current, tmp, 4 * sizeof(GLfloat) * dmul);
 
-/* Given that we explicitly state size here, there is no need
- * for the COPY_CLEAN above, could just copy 16 bytes and be
- * done.  The only problem is when Mesa accesses ctx->Current
- * directly.
- */
-/* Size here is in components - not bytes */
-vbo->currval[i].Size = exec->vtx.attrsz[i] / dmul;
-vbo->currval[i]._ElementSize = vbo->currval[i].Size * 
sizeof(GLfloat) * dmul;
-vbo->currval[i].Type = exec->vtx.attrtype[i];
-vbo->currval[i].Integer =
-  vbo_attrtype_to_integer_flag(exec->vtx.attrtype[i]);
-vbo->currval[i].Doubles =
-  vbo_attrtype_to_double_flag(exec->vtx.attrtype[i]);
-
-/* This triggers rather too much recalculation of Mesa state
- * that doesn't get used (eg light positions).
- */
-if (i >= VBO_ATTRIB_MAT_FRONT_AMBIENT &&
-i <= VBO_ATTRIB_MAT_BACK_INDEXES)
-   ctx->NewState |= _NEW_LIGHT;
-
-ctx->NewState |= _NEW_CURRENT_ATTRIB;
- }
+ /* Given that we explicitly state size here, there is no need
+  * for the COPY_CLEAN above, could just copy 16 bytes and be
+  * done.  The only problem is when Mesa accesses ctx->Curren

[Mesa-dev] [PATCH 29/31] mesa: Use bitmask/ffs to iterate the active_samplers bitmask.

2016-06-06 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.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/uniform_query.cpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index 997b0cb..461ebba 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -843,9 +843,10 @@ _mesa_uniform(struct gl_context *ctx, struct 
gl_shader_program *shProg,
  * been modified.
  */
 bool changed = false;
-for (unsigned j = 0; j < ARRAY_SIZE(prog->SamplerUnits); j++) {
-   if ((sh->active_samplers & (1U << j)) != 0
-   && (prog->SamplerUnits[j] != sh->SamplerUnits[j])) {
+GLbitfield mask = sh->active_samplers;
+while (mask) {
+   const int j = _mesa_bit_scan(&mask);
+   if (prog->SamplerUnits[j] != sh->SamplerUnits[j]) {
   changed = true;
   break;
}
-- 
2.5.5

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


[Mesa-dev] [PATCH 23/31] radeon/r200: Use bitmask/ffs to iterate enabled clip planes.

2016-06-06 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.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/dri/r200/r200_state.c | 19 +--
 src/mesa/drivers/dri/radeon/radeon_state.c | 19 +--
 2 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/mesa/drivers/dri/r200/r200_state.c 
b/src/mesa/drivers/dri/r200/r200_state.c
index 12efe18..61e3585 100644
--- a/src/mesa/drivers/dri/r200/r200_state.c
+++ b/src/mesa/drivers/dri/r200/r200_state.c
@@ -1359,18 +1359,17 @@ static void r200ClipPlane( struct gl_context *ctx, 
GLenum plane, const GLfloat *
 static void r200UpdateClipPlanes( struct gl_context *ctx )
 {
r200ContextPtr rmesa = R200_CONTEXT(ctx);
-   GLuint p;
+   GLbitfield mask = ctx->Transform.ClipPlanesEnabled;
 
-   for (p = 0; p < ctx->Const.MaxClipPlanes; p++) {
-  if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
-GLint *ip = (GLint *)ctx->Transform._ClipUserPlane[p];
+   while (mask) {
+  const int p = _mesa_bit_scan(&mask);
+  GLint *ip = (GLint *)ctx->Transform._ClipUserPlane[p];
 
-R200_STATECHANGE( rmesa, ucp[p] );
-rmesa->hw.ucp[p].cmd[UCP_X] = ip[0];
-rmesa->hw.ucp[p].cmd[UCP_Y] = ip[1];
-rmesa->hw.ucp[p].cmd[UCP_Z] = ip[2];
-rmesa->hw.ucp[p].cmd[UCP_W] = ip[3];
-  }
+  R200_STATECHANGE( rmesa, ucp[p] );
+  rmesa->hw.ucp[p].cmd[UCP_X] = ip[0];
+  rmesa->hw.ucp[p].cmd[UCP_Y] = ip[1];
+  rmesa->hw.ucp[p].cmd[UCP_Z] = ip[2];
+  rmesa->hw.ucp[p].cmd[UCP_W] = ip[3];
}
 }
 
diff --git a/src/mesa/drivers/dri/radeon/radeon_state.c 
b/src/mesa/drivers/dri/radeon/radeon_state.c
index 41a4d04..3a4bb4a 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state.c
@@ -1133,18 +1133,17 @@ static void radeonClipPlane( struct gl_context *ctx, 
GLenum plane, const GLfloat
 static void radeonUpdateClipPlanes( struct gl_context *ctx )
 {
r100ContextPtr rmesa = R100_CONTEXT(ctx);
-   GLuint p;
+   GLbitfield mask = ctx->Transform.ClipPlanesEnabled;
 
-   for (p = 0; p < ctx->Const.MaxClipPlanes; p++) {
-  if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
-GLint *ip = (GLint *)ctx->Transform._ClipUserPlane[p];
+   while (mask) {
+  const int p = _mesa_bit_scan(&mask);
+  GLint *ip = (GLint *)ctx->Transform._ClipUserPlane[p];
 
-RADEON_STATECHANGE( rmesa, ucp[p] );
-rmesa->hw.ucp[p].cmd[UCP_X] = ip[0];
-rmesa->hw.ucp[p].cmd[UCP_Y] = ip[1];
-rmesa->hw.ucp[p].cmd[UCP_Z] = ip[2];
-rmesa->hw.ucp[p].cmd[UCP_W] = ip[3];
-  }
+  RADEON_STATECHANGE( rmesa, ucp[p] );
+  rmesa->hw.ucp[p].cmd[UCP_X] = ip[0];
+  rmesa->hw.ucp[p].cmd[UCP_Y] = ip[1];
+  rmesa->hw.ucp[p].cmd[UCP_Z] = ip[2];
+  rmesa->hw.ucp[p].cmd[UCP_W] = ip[3];
}
 }
 
-- 
2.5.5

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


[Mesa-dev] [PATCH 24/31] i965: Use bitmask/ffs to iterate enabled clip planes.

2016-06-06 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.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/dri/i965/brw_curbe.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_curbe.c 
b/src/mesa/drivers/dri/i965/brw_curbe.c
index dfb90b1..cf6dabd 100644
--- a/src/mesa/drivers/dri/i965/brw_curbe.c
+++ b/src/mesa/drivers/dri/i965/brw_curbe.c
@@ -84,7 +84,7 @@ static void calculate_curbe_offsets( struct brw_context *brw )
 
/* _NEW_TRANSFORM */
if (ctx->Transform.ClipPlanesEnabled) {
-  GLuint nr_planes = 6 + 
_mesa_bitcount_64(ctx->Transform.ClipPlanesEnabled);
+  GLuint nr_planes = 6 + _mesa_bitcount(ctx->Transform.ClipPlanesEnabled);
   nr_clip_regs = (nr_planes * 4 + 15) / 16;
}
 
@@ -226,7 +226,7 @@ brw_upload_constant_buffer(struct brw_context *brw)
/* clipper constants */
if (brw->curbe.clip_size) {
   GLuint offset = brw->curbe.clip_start * 16;
-  GLuint j;
+  GLbitfield mask;
 
   /* If any planes are going this way, send them all this way:
*/
@@ -241,14 +241,14 @@ brw_upload_constant_buffer(struct brw_context *brw)
* clip-space:
*/
   clip_planes = brw_select_clip_planes(ctx);
-  for (j = 0; j < MAX_CLIP_PLANES; j++) {
-if (ctx->Transform.ClipPlanesEnabled & (1

[Mesa-dev] [PATCH 26/31] mesa: Use bitmask/ffs to iterate SamplersUsed

2016-06-06 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.

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

diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index 35b93d3..5669faf 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,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 = _mesa_bit_scan(&mask);
+  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 22/31] mesa: Use bitmask/ffs to iterate enabled clip planes.

2016-06-06 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.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/common/meta.c | 21 ++
 src/mesa/main/matrix.c | 18 ++--
 src/mesa/main/rastpos.c| 21 +++---
 src/mesa/tnl/t_vb_cliptmp.h| 51 -
 src/mesa/tnl/t_vb_program.c| 64 --
 src/mesa/tnl/t_vb_vertex.c | 57 ++---
 6 files changed, 111 insertions(+), 121 deletions(-)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 6dcbc8b..c0f9a92 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -682,12 +682,12 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
}
 
if (state & MESA_META_CLIP) {
+  GLbitfield mask;
   save->ClipPlanesEnabled = ctx->Transform.ClipPlanesEnabled;
-  if (ctx->Transform.ClipPlanesEnabled) {
- GLuint i;
- for (i = 0; i < ctx->Const.MaxClipPlanes; i++) {
-_mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_FALSE);
- }
+  mask = ctx->Transform.ClipPlanesEnabled;
+  while (mask) {
+ const int i = _mesa_bit_scan(&mask);
+ _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_FALSE);
   }
}
 
@@ -1090,13 +1090,10 @@ _mesa_meta_end(struct gl_context *ctx)
}
 
if (state & MESA_META_CLIP) {
-  if (save->ClipPlanesEnabled) {
- GLuint i;
- for (i = 0; i < ctx->Const.MaxClipPlanes; i++) {
-if (save->ClipPlanesEnabled & (1 << i)) {
-   _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_TRUE);
-}
- }
+  GLbitfield mask = save->ClipPlanesEnabled;
+  while (mask) {
+ const int i = _mesa_bit_scan(&mask);
+ _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_TRUE);
   }
}
 
diff --git a/src/mesa/main/matrix.c b/src/mesa/main/matrix.c
index 5ff5ac5..1954acd 100644
--- a/src/mesa/main/matrix.c
+++ b/src/mesa/main/matrix.c
@@ -554,20 +554,20 @@ _mesa_MultTransposeMatrixd( const GLdouble *m )
 static void
 update_projection( struct gl_context *ctx )
 {
+   GLbitfield mask;
+
_math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
 
/* Recompute clip plane positions in clipspace.  This is also done
 * in _mesa_ClipPlane().
 */
-   if (ctx->Transform.ClipPlanesEnabled) {
-  GLuint p;
-  for (p = 0; p < ctx->Const.MaxClipPlanes; p++) {
-if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
-   _mesa_transform_vector( ctx->Transform._ClipUserPlane[p],
-ctx->Transform.EyeUserPlane[p],
-ctx->ProjectionMatrixStack.Top->inv );
-}
-  }
+   mask = ctx->Transform.ClipPlanesEnabled;
+   while (mask) {
+  const int p = _mesa_bit_scan(&mask);
+
+  _mesa_transform_vector( ctx->Transform._ClipUserPlane[p],
+  ctx->Transform.EyeUserPlane[p],
+  ctx->ProjectionMatrixStack.Top->inv );
}
 }
 
diff --git a/src/mesa/main/rastpos.c b/src/mesa/main/rastpos.c
index 819a9a9..847dfde 100644
--- a/src/mesa/main/rastpos.c
+++ b/src/mesa/main/rastpos.c
@@ -90,17 +90,16 @@ viewclip_point_z( const GLfloat v[] )
 static GLuint
 userclip_point( struct gl_context *ctx, const GLfloat v[] )
 {
-   GLuint p;
-
-   for (p = 0; p < ctx->Const.MaxClipPlanes; p++) {
-  if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
-GLfloat dot = v[0] * ctx->Transform._ClipUserPlane[p][0]
-+ v[1] * ctx->Transform._ClipUserPlane[p][1]
-+ v[2] * ctx->Transform._ClipUserPlane[p][2]
-+ v[3] * ctx->Transform._ClipUserPlane[p][3];
- if (dot < 0.0F) {
-return 0;
- }
+   GLbitfield mask = ctx->Transform.ClipPlanesEnabled;
+   while (mask) {
+  const int p = _mesa_bit_scan(&mask);
+  GLfloat dot = v[0] * ctx->Transform._ClipUserPlane[p][0]
+ + v[1] * ctx->Transform._ClipUserPlane[p][1]
+ + v[2] * ctx->Transform._ClipUserPlane[p][2]
+ + v[3] * ctx->Transform._ClipUserPlane[p][3];
+
+  if (dot < 0.0F) {
+ return 0;
   }
}
 
diff --git a/src/mesa/tnl/t_vb_cliptmp.h b/src/mesa/tnl/t_vb_cliptmp.h
index 12181f0..7e6942d 100644
--- a/src/mesa/tnl/t_vb_cliptmp.h
+++ b/src/mesa/tnl/t_vb_cliptmp.h
@@ -124,7 +124,6 @@ TAG(clip_line)( struct gl_context *ctx, GLuint v0, GLuint 
v1, GLubyte mask )
GLuint newvert = VB->Count;
GLfloat t0 = 0;
GLfloat t1 = 0;
-   GLuint p;
const GLuint v0_orig = v0;
 
if (mask & CLIP_FRUSTUM_BITS) {
@@ -137,14 +136,14 @@ TAG(clip_line)( struct gl_context *ctx, GLuint v0, GLuint 
v1, GLubyte mask )
}
 
if (mask & CLIP_USER_BIT) {
-  for (p = 0; p < ctx->Con

[Mesa-dev] [PATCH 27/31] mesa: Use designated bool value to check texture unit completeness.

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

The change helps to use the bitmask/ffs in the next change.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/texstate.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 9ee5c69..3543369 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -612,6 +612,7 @@ update_ff_texture_state(struct gl_context *ctx,
for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
   GLuint texIndex;
+  bool complete;
 
   if (texUnit->Enabled == 0x0)
  continue;
@@ -649,6 +650,7 @@ update_ff_texture_state(struct gl_context *ctx,
*  another unit, then the results of texture blending are
*  undefined."
*/
+  complete = false;
   for (texIndex = 0; texIndex < NUM_TEXTURE_TARGETS; texIndex++) {
  if (texUnit->Enabled & (1 << texIndex)) {
 struct gl_texture_object *texObj = texUnit->CurrentTex[texIndex];
@@ -660,12 +662,13 @@ update_ff_texture_state(struct gl_context *ctx,
 }
 if (_mesa_is_texture_complete(texObj, sampler)) {
_mesa_reference_texobj(&texUnit->_Current, texObj);
+   complete = true;
break;
 }
  }
   }
 
-  if (texIndex == NUM_TEXTURE_TARGETS)
+  if (!complete)
  continue;
 
   /* if we get here, we know this texture unit is enabled */
-- 
2.5.5

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


[Mesa-dev] [PATCH 31/31] vbo: Use a bitmask to track the active arrays in vbo_save*.

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

The use of a bitmask makes functions iterating only active
attributes less visible in profiles.

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

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/vbo/vbo_save.h  |  2 ++
 src/mesa/vbo/vbo_save_api.c  | 66 +---
 src/mesa/vbo/vbo_save_draw.c | 54 +++-
 3 files changed, 67 insertions(+), 55 deletions(-)

diff --git a/src/mesa/vbo/vbo_save.h b/src/mesa/vbo/vbo_save.h
index 8032db8..e3b86bc 100644
--- a/src/mesa/vbo/vbo_save.h
+++ b/src/mesa/vbo/vbo_save.h
@@ -61,6 +61,7 @@ struct vbo_save_copied_vtx {
  * compiled using the fallback opcode mechanism provided by dlist.c.
  */
 struct vbo_save_vertex_list {
+   GLbitfield64 enabled;/**< mask of enabled vbo arrays. */
GLubyte attrsz[VBO_ATTRIB_MAX];
GLenum attrtype[VBO_ATTRIB_MAX];
GLuint vertex_size;  /**< size in GLfloats */
@@ -126,6 +127,7 @@ struct vbo_save_context {
struct gl_client_array arrays[VBO_ATTRIB_MAX];
const struct gl_client_array *inputs[VBO_ATTRIB_MAX];
 
+   GLbitfield64 enabled;/**< mask of enabled vbo arrays. */
GLubyte attrsz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
GLenum attrtype[VBO_ATTRIB_MAX];  /**< GL_FLOAT, GL_INT, etc */
GLubyte active_sz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index 97a1dfd..f1d8cf5 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -429,6 +429,7 @@ _save_compile_vertex_list(struct gl_context *ctx)
 
/* Duplicate our template, increment refcounts to the storage structs:
 */
+   node->enabled = save->enabled;
memcpy(node->attrsz, save->attrsz, sizeof(node->attrsz));
memcpy(node->attrtype, save->attrtype, sizeof(node->attrtype));
node->vertex_size = save->vertex_size;
@@ -624,14 +625,15 @@ static void
 _save_copy_to_current(struct gl_context *ctx)
 {
struct vbo_save_context *save = &vbo_context(ctx)->save;
-   GLuint i;
+   GLbitfield64 enabled = save->enabled & (~BITFIELD64_BIT(VBO_ATTRIB_POS));
 
-   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
-  if (save->attrsz[i]) {
- save->currentsz[i][0] = save->attrsz[i];
- COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
- save->attrptr[i], save->attrtype[i]);
-  }
+   while (enabled) {
+  const int i = _mesa_bit_scan64(&enabled);
+  assert(save->attrsz[i]);
+
+  save->currentsz[i][0] = save->attrsz[i];
+  COPY_CLEAN_4V_TYPE_AS_UNION(save->current[i], save->attrsz[i],
+  save->attrptr[i], save->attrtype[i]);
}
 }
 
@@ -640,9 +642,11 @@ static void
 _save_copy_from_current(struct gl_context *ctx)
 {
struct vbo_save_context *save = &vbo_context(ctx)->save;
-   GLint i;
+   GLbitfield64 enabled = save->enabled & (~BITFIELD64_BIT(VBO_ATTRIB_POS));
+
+   while (enabled) {
+  const int i = _mesa_bit_scan64(&enabled);
 
-   for (i = VBO_ATTRIB_POS + 1; i < VBO_ATTRIB_MAX; i++) {
   switch (save->attrsz[i]) {
   case 4:
  save->attrptr[i][3] = save->current[i][3];
@@ -652,7 +656,9 @@ _save_copy_from_current(struct gl_context *ctx)
  save->attrptr[i][1] = save->current[i][1];
   case 1:
  save->attrptr[i][0] = save->current[i][0];
+ break;
   case 0:
+ assert(0);
  break;
   }
}
@@ -691,6 +697,7 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, 
GLuint newsz)
 */
oldsz = save->attrsz[attr];
save->attrsz[attr] = newsz;
+   save->enabled |= BITFIELD64_BIT(attr);
 
save->vertex_size += newsz - oldsz;
save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) /
@@ -723,7 +730,6 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, 
GLuint newsz)
if (save->copied.nr) {
   const fi_type *data = save->copied.buffer;
   fi_type *dest = save->buffer;
-  GLuint j;
 
   /* Need to note this and fix up at runtime (or loopback):
*/
@@ -733,27 +739,28 @@ _save_upgrade_vertex(struct gl_context *ctx, GLuint attr, 
GLuint newsz)
   }
 
   for (i = 0; i < save->copied.nr; i++) {
- for (j = 0; j < VBO_ATTRIB_MAX; j++) {
-if (save->attrsz[j]) {
-   if (j == attr) {
-  if (oldsz) {
- COPY_CLEAN_4V_TYPE_AS_UNION(dest, oldsz, data,
- save->attrtype[j]);
- data += oldsz;
- dest += newsz;
-  }
-  else {
- COPY_SZ_4V(dest, newsz, save->current[attr]);
- dest += newsz;
-  }
+ GLbitfield64 enabled = save->enabled;
+ while (enabled) {
+const int j = _mesa_bit_scan64(&enabled);
+assert(save->attrsz[j]);
+if

[Mesa-dev] [PATCH 21/31] mesa: Use bitmask/ffs to iterate color material attributes.

2016-06-06 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.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/light.c | 11 ++-
 src/mesa/tnl/t_vb_light.c | 10 ++
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
index ae723e8..004449b 100644
--- a/src/mesa/main/light.c
+++ b/src/mesa/main/light.c
@@ -705,13 +705,14 @@ _mesa_update_material( struct gl_context *ctx, GLuint 
bitmask )
 void
 _mesa_update_color_material( struct gl_context *ctx, const GLfloat color[4] )
 {
-   const GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
+   GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
struct gl_material *mat = &ctx->Light.Material;
-   int i;
 
-   for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) 
-  if (bitmask & (1Attrib[i], color );
+   }
 
_mesa_update_material( ctx, bitmask );
 }
diff --git a/src/mesa/tnl/t_vb_light.c b/src/mesa/tnl/t_vb_light.c
index 67daddd..55f2f6d 100644
--- a/src/mesa/tnl/t_vb_light.c
+++ b/src/mesa/tnl/t_vb_light.c
@@ -231,10 +231,12 @@ prepare_materials(struct gl_context *ctx,
 * with the color pointer for each one.
 */
if (ctx->Light.ColorMaterialEnabled) {
-  const GLuint bitmask = ctx->Light._ColorMaterialBitmask;
-  for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
-if (bitmask & (1AttribPtr[_TNL_ATTRIB_COLOR0];
+  GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
+  while (bitmask) {
+ const int i = _mesa_bit_scan(&bitmask);
+ VB->AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] =
+VB->AttribPtr[_TNL_ATTRIB_COLOR0];
+  }
}
 
/* Now, for each material attribute that's tracking vertex color, save
-- 
2.5.5

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


[Mesa-dev] [PATCH 25/31] i965: Use bitmask/ffs to iterate used vertex attributes.

2016-06-06 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.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/dri/i965/brw_draw.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_draw.c 
b/src/mesa/drivers/dri/i965/brw_draw.c
index fa3ff5f..32beb1c 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -301,16 +301,15 @@ brw_merge_inputs(struct brw_context *brw,
}
 
if (brw->gen < 8 && !brw->is_haswell) {
-  struct gl_program *vp = &ctx->VertexProgram._Current->Base;
+  GLbitfield64 mask = ctx->VertexProgram._Current->Base.InputsRead;
   /* Prior to Haswell, the hardware can't natively support GL_FIXED or
* 2_10_10_10_REV vertex formats.  Set appropriate workaround flags.
*/
-  for (i = 0; i < VERT_ATTRIB_MAX; i++) {
- if (!(vp->InputsRead & BITFIELD64_BIT(i)))
-continue;
-
+  while (mask) {
  uint8_t wa_flags = 0;
 
+ i = _mesa_bit_scan64(&mask);
+
  switch (brw->vb.inputs[i].glarray->Type) {
 
  case GL_FIXED:
-- 
2.5.5

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


[Mesa-dev] [PATCH 28/31] mesa: Use bitmask/ffs to iterate the enabled textures.

2016-06-06 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.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/texstate.c | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 3543369..5d28aee 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -611,7 +611,7 @@ update_ff_texture_state(struct gl_context *ctx,
 
for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
-  GLuint texIndex;
+  GLbitfield mask;
   bool complete;
 
   if (texUnit->Enabled == 0x0)
@@ -651,20 +651,20 @@ update_ff_texture_state(struct gl_context *ctx,
*  undefined."
*/
   complete = false;
-  for (texIndex = 0; texIndex < NUM_TEXTURE_TARGETS; texIndex++) {
- if (texUnit->Enabled & (1 << texIndex)) {
-struct gl_texture_object *texObj = texUnit->CurrentTex[texIndex];
-struct gl_sampler_object *sampler = texUnit->Sampler ?
-   texUnit->Sampler : &texObj->Sampler;
-
-if (!_mesa_is_texture_complete(texObj, sampler)) {
-   _mesa_test_texobj_completeness(ctx, texObj);
-}
-if (_mesa_is_texture_complete(texObj, sampler)) {
-   _mesa_reference_texobj(&texUnit->_Current, texObj);
-   complete = true;
-   break;
-}
+  mask = texUnit->Enabled;
+  while (mask) {
+ const int texIndex = _mesa_bit_scan(&mask);
+ struct gl_texture_object *texObj = texUnit->CurrentTex[texIndex];
+ struct gl_sampler_object *sampler = texUnit->Sampler ?
+texUnit->Sampler : &texObj->Sampler;
+
+ if (!_mesa_is_texture_complete(texObj, sampler)) {
+_mesa_test_texobj_completeness(ctx, texObj);
+ }
+ if (_mesa_is_texture_complete(texObj, sampler)) {
+_mesa_reference_texobj(&texUnit->_Current, texObj);
+complete = true;
+break;
  }
   }
 
-- 
2.5.5

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


[Mesa-dev] [PATCH 1/2] mesa/gallium: Move u_bit_scan{, 64} from gallium to mesa.

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

The functions are also useful for mesa.
Introduce src/util/bitscan.{h,c}. Move ffs function
implementations from src/mesa/main/imports.{h,c}.
Move bit scan related functions from
src/gallium/auxiliary/util/u_math.h. Merge platform
handling with what is available from within mesa.

Signed-off-by: Mathias Fröhlich 
---
 src/gallium/auxiliary/util/u_math.h | 149 +--
 src/mesa/main/imports.c |  58 --
 src/mesa/main/imports.h |  16 
 src/util/Makefile.sources   |   2 +
 src/util/bitscan.c  |  80 +++
 src/util/bitscan.h  | 151 
 6 files changed, 234 insertions(+), 222 deletions(-)
 create mode 100644 src/util/bitscan.c
 create mode 100644 src/util/bitscan.h

diff --git a/src/gallium/auxiliary/util/u_math.h 
b/src/gallium/auxiliary/util/u_math.h
index ecb1d63..c94967e 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -46,14 +46,7 @@
 #include 
 #include 
 
-#ifdef PIPE_OS_UNIX
-#include  /* for ffs */
-#endif
-
-#if defined(_MSC_VER)
-#include 
-#endif
-
+#include "util/bitscan.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -354,80 +347,6 @@ util_half_inf_sign(int16_t x)
 
 
 /**
- * Find first bit set in word.  Least significant bit is 1.
- * Return 0 if no bits set.
- */
-#ifndef FFS_DEFINED
-#define FFS_DEFINED 1
-
-#if defined(_MSC_VER) && (_M_IX86 || _M_AMD64 || _M_IA64)
-static inline
-unsigned long ffs( unsigned long u )
-{
-   unsigned long i;
-   if (_BitScanForward(&i, u))
-  return i + 1;
-   else
-  return 0;
-}
-#elif defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)
-static inline
-unsigned ffs( unsigned u )
-{
-   unsigned i;
-
-   if (u == 0) {
-  return 0;
-   }
-
-   __asm bsf eax, [u]
-   __asm inc eax
-   __asm mov [i], eax
-
-   return i;
-}
-#elif defined(__MINGW32__) || defined(PIPE_OS_ANDROID) || \
-defined(HAVE___BUILTIN_FFS)
-#define ffs __builtin_ffs
-#endif
-
-#ifdef HAVE___BUILTIN_FFSLL
-#define ffsll __builtin_ffsll
-#else
-static inline int
-ffsll(long long int val)
-{
-   int bit;
-
-   bit = ffs((unsigned) (val & 0x));
-   if (bit != 0)
-  return bit;
-
-   bit = ffs((unsigned) (val >> 32));
-   if (bit != 0)
-  return 32 + bit;
-
-   return 0;
-}
-#endif
-
-#endif /* FFS_DEFINED */
-
-/**
- * Find first bit set in long long.  Least significant bit is 1.
- * Return 0 if no bits set.
- */
-#ifndef FFSLL_DEFINED
-#define FFSLL_DEFINED 1
-
-#if defined(__MINGW32__) || defined(PIPE_OS_ANDROID) || \
-defined(HAVE___BUILTIN_FFSLL)
-#define ffsll __builtin_ffsll
-#endif
-
-#endif /* FFSLL_DEFINED */
-
-/**
  * Find last bit set in a word.  The least significant bit is 1.
  * Return 0 if no bits are set.
  */
@@ -479,72 +398,6 @@ util_last_bit_signed(int i)
   return util_last_bit(~(unsigned)i);
 }
 
-/* Destructively loop over all of the bits in a mask as in:
- *
- * while (mymask) {
- *   int i = u_bit_scan(&mymask);
- *   ... process element i
- * }
- *
- */
-static inline int
-u_bit_scan(unsigned *mask)
-{
-   int i = ffs(*mask) - 1;
-   *mask &= ~(1u << i);
-   return i;
-}
-
-#ifndef _MSC_VER
-static inline int
-u_bit_scan64(uint64_t *mask)
-{
-   int i = ffsll(*mask) - 1;
-   *mask &= ~(1llu << i);
-   return i;
-}
-#endif
-
-/* For looping over a bitmask when you want to loop over consecutive bits
- * manually, for example:
- *
- * while (mask) {
- *int start, count, i;
- *
- *u_bit_scan_consecutive_range(&mask, &start, &count);
- *
- *for (i = 0; i < count; i++)
- *   ... process element (start+i)
- * }
- */
-static inline void
-u_bit_scan_consecutive_range(unsigned *mask, int *start, int *count)
-{
-   if (*mask == 0x) {
-  *start = 0;
-  *count = 32;
-  *mask = 0;
-  return;
-   }
-   *start = ffs(*mask) - 1;
-   *count = ffs(~(*mask >> *start)) - 1;
-   *mask &= ~(((1u << *count) - 1) << *start);
-}
-
-static inline void
-u_bit_scan_consecutive_range64(uint64_t *mask, int *start, int *count)
-{
-   if (*mask == ~0llu) {
-  *start = 0;
-  *count = 64;
-  *mask = 0;
-  return;
-   }
-   *start = ffsll(*mask) - 1;
-   *count = ffsll(~(*mask >> *start)) - 1;
-   *mask &= ~(((1llu << *count) - 1) << *start);
-}
-
 /* Returns a bitfield in which the first count bits starting at start are
  * set.
  */
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index fe54109..808b8f6 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -219,64 +219,6 @@ _mesa_align_realloc(void *oldBuffer, size_t oldSize, 
size_t newSize,
 /*@{*/
 
 
-#ifndef HAVE___BUILTIN_FFS
-/**
- * Find the first bit set in a word.
- */
-int
-ffs(int i)
-{
-   register int bit = 0;
-   if (i != 0) {
-  if ((i & 0x) == 0) {
- bit += 16;
- i >>= 16;
-  }
-  if ((i & 0xff) == 0) {
- bit += 8;
- i >>= 8;
-  }
-  if ((i & 0xf)

[Mesa-dev] [PATCH 0/2] Move u_bit_scan from gallium to util.

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

Hi all,

I just put the two leading patches to move u_bit_scan
from gallium to util. The architecture handling of
ffs{,ll} is merged with what is available in the
mesa/util directory. It compiles and works here and
we should get slightly better intrinsic coverage on win32.
At least according to what is documented at msdn. But
the chance to break one of our other builds or
architectures is high with this kind of change.
So any hints or testing according that are
even more appreciated.

The rest of the series posted earlier gets posted
again when this part arrived.

Please review.

Thanks

Mathias

Mathias Fröhlich (2):
  mesa/gallium: Move u_bit_scan{,64} from gallium to mesa.
  mesa: Make use of u_bit_scan{,64}.

 src/gallium/auxiliary/util/u_math.h | 149 +--
 src/mesa/main/arrayobj.c|   6 +-
 src/mesa/main/buffers.c |   4 +-
 src/mesa/main/imports.c |  58 --
 src/mesa/main/imports.h |  16 
 src/util/Makefile.sources   |   2 +
 src/util/bitscan.c  |  80 +++
 src/util/bitscan.h  | 151 
 8 files changed, 239 insertions(+), 227 deletions(-)
 create mode 100644 src/util/bitscan.c
 create mode 100644 src/util/bitscan.h

-- 
2.5.5

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


[Mesa-dev] [PATCH 2/2] mesa: Make use of u_bit_scan{,64}.

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

Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/arrayobj.c | 6 +++---
 src/mesa/main/buffers.c  | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index 897dac6..9c3451e 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -52,6 +52,7 @@
 #include "mtypes.h"
 #include "varray.h"
 #include "main/dispatch.h"
+#include "util/bitscan.h"
 
 
 /**
@@ -342,13 +343,12 @@ _mesa_update_vao_client_arrays(struct gl_context *ctx,
GLbitfield64 arrays = vao->NewArrays;
 
while (arrays) {
+  const int attrib = u_bit_scan64(&arrays);
+
   struct gl_client_array *client_array;
   struct gl_vertex_attrib_array *attrib_array;
   struct gl_vertex_buffer_binding *buffer_binding;
 
-  GLint attrib = ffsll(arrays) - 1;
-  arrays ^= BITFIELD64_BIT(attrib);
-
   attrib_array = &vao->VertexAttrib[attrib];
   buffer_binding = &vao->VertexBinding[attrib_array->VertexBinding];
   client_array = &vao->_VertexAttrib[attrib];
diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c
index a28c583..e8aedde 100644
--- a/src/mesa/main/buffers.c
+++ b/src/mesa/main/buffers.c
@@ -36,6 +36,7 @@
 #include "enums.h"
 #include "fbobject.h"
 #include "mtypes.h"
+#include "util/bitscan.h"
 
 
 #define BAD_MASK ~0u
@@ -595,13 +596,12 @@ _mesa_drawbuffers(struct gl_context *ctx, struct 
gl_framebuffer *fb,
if (n > 0 && _mesa_bitcount(destMask[0]) > 1) {
   GLuint count = 0, destMask0 = destMask[0];
   while (destMask0) {
- GLint bufIndex = ffs(destMask0) - 1;
+ const int bufIndex = u_bit_scan(&destMask0);
  if (fb->_ColorDrawBufferIndexes[count] != bufIndex) {
 updated_drawbuffers(ctx, fb);
 fb->_ColorDrawBufferIndexes[count] = bufIndex;
  }
  count++;
- destMask0 &= ~(1 << bufIndex);
   }
   fb->ColorDrawBuffer[0] = buffers[0];
   fb->_NumColorDrawBuffers = count;
-- 
2.5.5

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


[Mesa-dev] [PATCH] mesa/gallium: Move u_bit_scan{, 64} from gallium to util.

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

The functions are also useful for mesa.
Introduce src/util/bitscan.{h,c}. Move ffs function
implementations from src/mesa/main/imports.{h,c}.
Move bit scan related functions from
src/gallium/auxiliary/util/u_math.h. Merge platform
handling with what is available from within mesa.

v2: Try to fix MSVC compile.

Signed-off-by: Mathias Fröhlich 
---
 src/gallium/auxiliary/util/u_math.h | 149 +--
 src/mesa/main/imports.c |  58 --
 src/mesa/main/imports.h |  17 +---
 src/util/Makefile.sources   |   2 +
 src/util/bitscan.c  |  80 +++
 src/util/bitscan.h  | 153 
 6 files changed, 237 insertions(+), 222 deletions(-)
 create mode 100644 src/util/bitscan.c
 create mode 100644 src/util/bitscan.h

diff --git a/src/gallium/auxiliary/util/u_math.h 
b/src/gallium/auxiliary/util/u_math.h
index ecb1d63..c94967e 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -46,14 +46,7 @@
 #include 
 #include 
 
-#ifdef PIPE_OS_UNIX
-#include  /* for ffs */
-#endif
-
-#if defined(_MSC_VER)
-#include 
-#endif
-
+#include "util/bitscan.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -354,80 +347,6 @@ util_half_inf_sign(int16_t x)
 
 
 /**
- * Find first bit set in word.  Least significant bit is 1.
- * Return 0 if no bits set.
- */
-#ifndef FFS_DEFINED
-#define FFS_DEFINED 1
-
-#if defined(_MSC_VER) && (_M_IX86 || _M_AMD64 || _M_IA64)
-static inline
-unsigned long ffs( unsigned long u )
-{
-   unsigned long i;
-   if (_BitScanForward(&i, u))
-  return i + 1;
-   else
-  return 0;
-}
-#elif defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)
-static inline
-unsigned ffs( unsigned u )
-{
-   unsigned i;
-
-   if (u == 0) {
-  return 0;
-   }
-
-   __asm bsf eax, [u]
-   __asm inc eax
-   __asm mov [i], eax
-
-   return i;
-}
-#elif defined(__MINGW32__) || defined(PIPE_OS_ANDROID) || \
-defined(HAVE___BUILTIN_FFS)
-#define ffs __builtin_ffs
-#endif
-
-#ifdef HAVE___BUILTIN_FFSLL
-#define ffsll __builtin_ffsll
-#else
-static inline int
-ffsll(long long int val)
-{
-   int bit;
-
-   bit = ffs((unsigned) (val & 0x));
-   if (bit != 0)
-  return bit;
-
-   bit = ffs((unsigned) (val >> 32));
-   if (bit != 0)
-  return 32 + bit;
-
-   return 0;
-}
-#endif
-
-#endif /* FFS_DEFINED */
-
-/**
- * Find first bit set in long long.  Least significant bit is 1.
- * Return 0 if no bits set.
- */
-#ifndef FFSLL_DEFINED
-#define FFSLL_DEFINED 1
-
-#if defined(__MINGW32__) || defined(PIPE_OS_ANDROID) || \
-defined(HAVE___BUILTIN_FFSLL)
-#define ffsll __builtin_ffsll
-#endif
-
-#endif /* FFSLL_DEFINED */
-
-/**
  * Find last bit set in a word.  The least significant bit is 1.
  * Return 0 if no bits are set.
  */
@@ -479,72 +398,6 @@ util_last_bit_signed(int i)
   return util_last_bit(~(unsigned)i);
 }
 
-/* Destructively loop over all of the bits in a mask as in:
- *
- * while (mymask) {
- *   int i = u_bit_scan(&mymask);
- *   ... process element i
- * }
- *
- */
-static inline int
-u_bit_scan(unsigned *mask)
-{
-   int i = ffs(*mask) - 1;
-   *mask &= ~(1u << i);
-   return i;
-}
-
-#ifndef _MSC_VER
-static inline int
-u_bit_scan64(uint64_t *mask)
-{
-   int i = ffsll(*mask) - 1;
-   *mask &= ~(1llu << i);
-   return i;
-}
-#endif
-
-/* For looping over a bitmask when you want to loop over consecutive bits
- * manually, for example:
- *
- * while (mask) {
- *int start, count, i;
- *
- *u_bit_scan_consecutive_range(&mask, &start, &count);
- *
- *for (i = 0; i < count; i++)
- *   ... process element (start+i)
- * }
- */
-static inline void
-u_bit_scan_consecutive_range(unsigned *mask, int *start, int *count)
-{
-   if (*mask == 0x) {
-  *start = 0;
-  *count = 32;
-  *mask = 0;
-  return;
-   }
-   *start = ffs(*mask) - 1;
-   *count = ffs(~(*mask >> *start)) - 1;
-   *mask &= ~(((1u << *count) - 1) << *start);
-}
-
-static inline void
-u_bit_scan_consecutive_range64(uint64_t *mask, int *start, int *count)
-{
-   if (*mask == ~0llu) {
-  *start = 0;
-  *count = 64;
-  *mask = 0;
-  return;
-   }
-   *start = ffsll(*mask) - 1;
-   *count = ffsll(~(*mask >> *start)) - 1;
-   *mask &= ~(((1llu << *count) - 1) << *start);
-}
-
 /* Returns a bitfield in which the first count bits starting at start are
  * set.
  */
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index fe54109..808b8f6 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -219,64 +219,6 @@ _mesa_align_realloc(void *oldBuffer, size_t oldSize, 
size_t newSize,
 /*@{*/
 
 
-#ifndef HAVE___BUILTIN_FFS
-/**
- * Find the first bit set in a word.
- */
-int
-ffs(int i)
-{
-   register int bit = 0;
-   if (i != 0) {
-  if ((i & 0x) == 0) {
- bit += 16;
- i >>= 16;
-  }
-  if ((i & 0xff) == 0) {
- bit += 8;
- i >>= 8;

[Mesa-dev] [PATCH 00/29] Make more use of bitmasks v3

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


Hi all,

following a series with performance improvements
for cpu/draw bound applications. This part makes
more use of the bitmask/ffs technique for iterating
a set of enabled items. The gains are not huge
but they are noticable for some of my favourite
workloads.

Changes in v2:

Past the suggestion from Brian Paul and the
discussion about maintainability I
switched to gallium/u_bit_scan{,64} style
functions for the series of changes.
Providing them and using them in some places
in core mesa make up the two new patches upfront.

Appart from that the problem spotted
by Roland Scheidegger is fixed and the changes
requested all around are incorporated.

Changes in v3:

Rename _mesa_bit_scan* to u_bit_scan*.
Comment formating changes.
Rebase to master.

Ok to push?

Thanks

Mathias


Mathias Fröhlich (29):
  mesa: Add gl_point_attrib::CoordReplaceBits bitfield.
  swrast: Convert swrast to use CoordsReplaceBits.
  gallium: Convert the state_tracker to use CoordsReplaceBits.
  r200: convert r200 to use CoordsReplaceBits.
  i915: Convert i915 to use CoordsReplaceBits.
  i965: Convert i965 to use CoordsReplaceBits.
  mesa: Remove the now unused CoordsReplace array.
  mesa: Rename CoordReplaceBits back to CoordReplace.
  mesa: Track enabled lights in a bitmask
  mesa: Use bitmask/ffs to iterate enabled lights
  mesa: Use bitmask/ffs to iterate enabled lights for ff shader keys.
  tnl: Use bitmask/ffs to iterate enabled lights
  nouveau: Use bitmask/ffs to iterate enabled lights
  radeon/r200: Use bitmask/ffs to iterate enabled lights
  mesa: Switch to bitmask based enabled lights in gen_matypes.c
  mesa: Remove the linked list of enabled lights
  mesa: Use bitmask/ffs to build ff vertex shader keys.
  mesa: Use bitmask/ffs to build ff fragment shader keys.
  mesa: Use bitmask/ffs to iterate color material attributes.
  mesa: Use bitmask/ffs to iterate enabled clip planes.
  radeon/r200: Use bitmask/ffs to iterate enabled clip planes.
  i965: Use bitmask/ffs to iterate enabled clip planes.
  i965: Use bitmask/ffs to iterate used vertex attributes.
  mesa: Use bitmask/ffs to iterate SamplersUsed
  mesa: Use designated bool value to check texture unit completeness.
  mesa: Use bitmask/ffs to iterate the enabled textures.
  mesa: Use bitmask/ffs to iterate the active_samplers bitmask.
  vbo: Use a bitmask to track the active arrays in vbo_exec*.
  vbo: Use a bitmask to track the active arrays in vbo_save*.

 src/mesa/drivers/common/meta.c|  22 ++--
 src/mesa/drivers/dri/i915/i915_state.c|  17 ++-
 src/mesa/drivers/dri/i965/brw_curbe.c |  21 ++--
 src/mesa/drivers/dri/i965/brw_draw.c  |  10 +-
 src/mesa/drivers/dri/i965/brw_sf.c|   7 +-
 src/mesa/drivers/dri/i965/brw_vs.c|   6 +-
 src/mesa/drivers/dri/i965/gen6_sf_state.c |   2 +-
 src/mesa/drivers/dri/nouveau/nouveau_state.c  |  10 +-
 src/mesa/drivers/dri/nouveau/nv10_state_tnl.c |  27 +++--
 src/mesa/drivers/dri/nouveau/nv20_state_tnl.c |  27 +++--
 src/mesa/drivers/dri/r200/r200_state.c|  66 ++--
 src/mesa/drivers/dri/radeon/radeon_state.c|  61 ++-
 src/mesa/main/attrib.c|   2 +-
 src/mesa/main/context.c   |  11 +-
 src/mesa/main/enable.c|   6 +-
 src/mesa/main/ff_fragment_shader.cpp  |  10 +-
 src/mesa/main/ffvertex_prog.c |  36 ---
 src/mesa/main/light.c |  60 +++
 src/mesa/main/matrix.c|  19 ++--
 src/mesa/main/mtypes.h|   8 +-
 src/mesa/main/points.c|   6 +-
 src/mesa/main/rastpos.c   |  28 ++---
 src/mesa/main/texenv.c|  32 +++---
 src/mesa/main/texstate.c  |  34 +++---
 src/mesa/main/uniform_query.cpp   |   8 +-
 src/mesa/main/uniforms.c  |  42 
 src/mesa/state_tracker/st_atom_rasterizer.c   |   8 +-
 src/mesa/swrast/s_points.c|   4 +-
 src/mesa/tnl/t_vb_cliptmp.h   |  51 +
 src/mesa/tnl/t_vb_light.c |  15 ++-
 src/mesa/tnl/t_vb_lighttmp.h  |  24 +++--
 src/mesa/tnl/t_vb_program.c   |  65 ++--
 src/mesa/tnl/t_vb_render.c|   1 +
 src/mesa/tnl/t_vb_vertex.c|  59 ++-
 src/mesa/vbo/vbo_exec.h   |   1 +
 src/mesa/vbo/vbo_exec_api.c   | 146 ++
 src/mesa/vbo/vbo_exec_draw.c  |   2 +
 src/mesa/vbo/vbo_save.h   |   2 +
 src/mesa/vbo/vbo_save_api.c   |  67 +++-
 src/mesa/vbo/vbo_save_draw.c  |  55 +-
 src/mesa/x86/gen_matypes.c|   4 +-
 41 files changed, 567 insertions(+), 515 deletions(-)

-- 
2.5.5


[Mesa-dev] [PATCH 12/29] tnl: Use bitmask/ffs to iterate enabled lights

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

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.
v3: Use u_bit_scan{,64} instead of _mesa_bit_scan{,64}.

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/tnl/t_vb_light.c|  5 -
 src/mesa/tnl/t_vb_lighttmp.h | 24 +---
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/mesa/tnl/t_vb_light.c b/src/mesa/tnl/t_vb_light.c
index 029265a..4342b6e 100644
--- a/src/mesa/tnl/t_vb_light.c
+++ b/src/mesa/tnl/t_vb_light.c
@@ -33,6 +33,8 @@
 
 #include "math/m_translate.h"
 
+#include "util/bitscan.h"
+
 #include "t_context.h"
 #include "t_pipeline.h"
 #include "tnl.h"
@@ -394,7 +396,8 @@ static void validate_lighting( struct gl_context *ctx,
 tab = _tnl_light_tab;
}
else {
-  if (ctx->Light.EnabledList.next == ctx->Light.EnabledList.prev)
+  /* Power of two means only a single active light. */
+  if (_mesa_is_pow_two(ctx->Light._EnabledLights))
 tab = _tnl_light_fast_single_tab;
   else
 tab = _tnl_light_fast_tab;
diff --git a/src/mesa/tnl/t_vb_lighttmp.h b/src/mesa/tnl/t_vb_lighttmp.h
index 3aebcd4..ac88095 100644
--- a/src/mesa/tnl/t_vb_lighttmp.h
+++ b/src/mesa/tnl/t_vb_lighttmp.h
@@ -87,7 +87,7 @@ static void TAG(light_rgba_spec)( struct gl_context *ctx,
 
for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) {
   GLfloat sum[2][3], spec[2][3];
-  struct gl_light *light;
+  GLbitfield mask;
 
 #if IDX & LIGHT_MATERIAL
   update_materials( ctx, store );
@@ -106,7 +106,10 @@ static void TAG(light_rgba_spec)( struct gl_context *ctx,
 #endif
 
   /* Add contribution from each enabled light source */
-  foreach (light, &ctx->Light.EnabledList) {
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int l = u_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[l];
 GLfloat n_dot_h;
 GLfloat correction;
 GLint side;
@@ -265,7 +268,7 @@ static void TAG(light_rgba)( struct gl_context *ctx,
 
for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) {
   GLfloat sum[2][3];
-  struct gl_light *light;
+  GLbitfield mask;
 
 #if IDX & LIGHT_MATERIAL
   update_materials( ctx, store );
@@ -282,7 +285,10 @@ static void TAG(light_rgba)( struct gl_context *ctx,
 #endif
 
   /* Add contribution from each enabled light source */
-  foreach (light, &ctx->Light.EnabledList) {
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int l = u_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[l];
 GLfloat n_dot_h;
 GLfloat correction;
 GLint side;
@@ -417,7 +423,8 @@ static void TAG(light_fast_rgba_single)( struct gl_context 
*ctx,
 #if IDX & LIGHT_TWOSIDE
GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data;
 #endif
-   const struct gl_light *light = ctx->Light.EnabledList.next;
+   const struct gl_light *light =
+  &ctx->Light.Light[ffs(ctx->Light._EnabledLights) - 1];
GLuint j = 0;
GLfloat base[2][4];
 #if IDX & LIGHT_MATERIAL
@@ -528,7 +535,6 @@ static void TAG(light_fast_rgba)( struct gl_context *ctx,
 #else
const GLuint nr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->count;
 #endif
-   const struct gl_light *light;
 
 #ifdef TRACE
fprintf(stderr, "%s %d\n", __func__, nr );
@@ -556,6 +562,7 @@ static void TAG(light_fast_rgba)( struct gl_context *ctx,
for (j = 0; j < nr; j++, STRIDE_F(normal,nstride)) {
 
   GLfloat sum[2][3];
+  GLbitfield mask;
 
 #if IDX & LIGHT_MATERIAL
   update_materials( ctx, store );
@@ -572,7 +579,10 @@ static void TAG(light_fast_rgba)( struct gl_context *ctx,
   COPY_3V(sum[1], ctx->Light._BaseColor[1]);
 #endif
 
-  foreach (light, &ctx->Light.EnabledList) {
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int l = u_bit_scan(&mask);
+ const struct gl_light *light = &ctx->Light.Light[l];
 GLfloat n_dot_h, n_dot_VP, spec;
 
 ACC_3V(sum[0], light->_MatAmbient[0]);
-- 
2.5.5

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


[Mesa-dev] [PATCH 10/29] mesa: Use bitmask/ffs to iterate enabled lights

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

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.
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/light.c   | 44 +---
 src/mesa/main/rastpos.c |  9 ++---
 2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
index a52efdb..c9e2fc2 100644
--- a/src/mesa/main/light.c
+++ b/src/mesa/main/light.c
@@ -34,6 +34,7 @@
 #include "util/simple_list.h"
 #include "mtypes.h"
 #include "math/m_matrix.h"
+#include "util/bitscan.h"
 
 
 void GLAPIENTRY
@@ -612,7 +613,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 +623,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 = u_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 = u_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 +657,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 = u_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 = u_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 +678,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 = u_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 = u_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 +882,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 = u_bit_scan(&mask);
+  struct gl_light *light = &ctx->Light.Light[i];
   flags |= light->_Flags;
}
 
@@ -926,7 +946,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 +958,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 = u_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..8f971f5 

  1   2   3   4   5   >