[Mesa-dev] [PATCH 2/3] mesa: Introduce enabled bitfield helper functions.

2011-12-29 Thread Mathias Froehlich
Depending on the installed shader type, different arrays are used
from gl_array_object. Provide helper functions that compute
the bitmask of these arrays that are finally enabled for a given
shader type. The will be used in a followup change.

Signed-off-by: Mathias Fröhlich mathias.froehl...@web.de
---
 src/mesa/main/arrayobj.h |   38 ++
 src/mesa/main/mtypes.h   |4 
 2 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/arrayobj.h b/src/mesa/main/arrayobj.h
index 0b5a013..938fa1e 100644
--- a/src/mesa/main/arrayobj.h
+++ b/src/mesa/main/arrayobj.h
@@ -29,6 +29,7 @@
 #define ARRAYOBJ_H
 
 #include glheader.h
+#include mtypes.h
 
 struct gl_context;
 
@@ -64,6 +65,43 @@ extern void
 _mesa_update_array_object_max_element(struct gl_context *ctx,
   struct gl_array_object *arrayObj);
 
+/** Returns the bitmask of all enabled arrays in fixed function mode.
+ *
+ *  In fixed function mode only the traditional fixed function arrays
+ *  are available.
+ */
+static inline GLbitfield64
+_mesa_array_object_get_enabled_ff(const struct gl_array_object *arrayObj)
+{
+   return arrayObj-_Enabled  VERT_BIT_FF_ALL;
+}
+
+/** Returns the bitmask of all enabled arrays in nv shader mode.
+ *
+ *  In nv shader mode any the generic nv arrays superseed the traditional
+ *  fixed function arrays. The nv generic arrays take precedence
+ *  over the legacy arrays.
+ */
+static inline GLbitfield64
+_mesa_array_object_get_enabled_nv(const struct gl_array_object *arrayObj)
+{
+   GLbitfield64 enabled = arrayObj-_Enabled;
+   return enabled  ~(VERT_BIT_FF_NVALIAS  (enabled  
VERT_ATTRIB_GENERIC0));
+}
+
+/** Returns the bitmask of all enabled arrays in arb/glsl shader mode.
+ *
+ *  In arb/glsl shader mode all the fixed function and the arg/glsl generic
+ *  arrays are available. Here only the first generic array takes
+ *  precedence over the legacy position array.
+ */
+static inline GLbitfield64
+_mesa_array_object_get_enabled_arb(const struct gl_array_object *arrayObj)
+{
+   GLbitfield64 enabled = arrayObj-_Enabled;
+   return enabled  ~(VERT_BIT_POS  (enabled  VERT_ATTRIB_GENERIC0));
+}
+
 
 /*
  * API functions
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 451d442..3bef71d 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -206,9 +206,13 @@ typedef enum
 #define VERT_BIT_TEX(i)  VERT_BIT(VERT_ATTRIB_TEX(i))
 #define VERT_BIT_TEX_ALL \
BITFIELD64_RANGE(VERT_ATTRIB_TEX(0), VERT_ATTRIB_TEX_MAX)
+#define VERT_BIT_FF_NVALIAS  \
+   BITFIELD64_RANGE(VERT_ATTRIB_POS, VERT_ATTRIB_GENERIC_NV_MAX)
+
 #define VERT_BIT_GENERIC_NV(i)   VERT_BIT(VERT_ATTRIB_GENERIC_NV(i))
 #define VERT_BIT_GENERIC_NV_ALL  \
BITFIELD64_RANGE(VERT_ATTRIB_GENERIC_NV(0), VERT_ATTRIB_GENERIC_NV_MAX)
+
 #define VERT_BIT_GENERIC(i)  VERT_BIT(VERT_ATTRIB_GENERIC(i))
 #define VERT_BIT_GENERIC_ALL \
BITFIELD64_RANGE(VERT_ATTRIB_GENERIC(0), VERT_ATTRIB_GENERIC_MAX)
-- 
1.7.4.4

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


[Mesa-dev] [PATCH 2/3] mesa: Introduce enabled bitfield helper functions.

2012-01-11 Thread Mathias Froehlich
Depending on the installed shader type, different arrays are used
from gl_array_object. Provide helper functions that compute
the bitmask of these arrays that are finally enabled for a given
shader type. The will be used in a followup change.

Signed-off-by: Mathias Fröhlich mathias.froehl...@web.de
---
 src/mesa/main/arrayobj.h |   37 +
 src/mesa/main/mtypes.h   |4 
 2 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/arrayobj.h b/src/mesa/main/arrayobj.h
index 0b5a013..717c791 100644
--- a/src/mesa/main/arrayobj.h
+++ b/src/mesa/main/arrayobj.h
@@ -29,6 +29,7 @@
 #define ARRAYOBJ_H
 
 #include glheader.h
+#include mtypes.h
 
 struct gl_context;
 
@@ -64,6 +65,42 @@ extern void
 _mesa_update_array_object_max_element(struct gl_context *ctx,
   struct gl_array_object *arrayObj);
 
+/** Returns the bitmask of all enabled arrays in fixed function mode.
+ *
+ *  In fixed function mode only the traditional fixed function arrays
+ *  are available.
+ */
+static inline GLbitfield64
+_mesa_array_object_get_enabled_ff(const struct gl_array_object *arrayObj)
+{
+   return arrayObj-_Enabled  VERT_BIT_FF_ALL;
+}
+
+/** Returns the bitmask of all enabled arrays in nv shader mode.
+ *
+ *  In nv shader mode, the nv generic arrays take precedence over
+ *  the legacy arrays.
+ */
+static inline GLbitfield64
+_mesa_array_object_get_enabled_nv(const struct gl_array_object *arrayObj)
+{
+   GLbitfield64 enabled = arrayObj-_Enabled;
+   return enabled  ~(VERT_BIT_FF_NVALIAS  (enabled  
VERT_ATTRIB_GENERIC0));
+}
+
+/** Returns the bitmask of all enabled arrays in arb/glsl shader mode.
+ *
+ *  In arb/glsl shader mode all the fixed function and the arb/glsl generic
+ *  arrays are available. Only the first generic array takes
+ *  precedence over the legacy position array.
+ */
+static inline GLbitfield64
+_mesa_array_object_get_enabled_arb(const struct gl_array_object *arrayObj)
+{
+   GLbitfield64 enabled = arrayObj-_Enabled;
+   return enabled  ~(VERT_BIT_POS  (enabled  VERT_ATTRIB_GENERIC0));
+}
+
 
 /*
  * API functions
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index b381ad2..f8ef01d 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -206,9 +206,13 @@ typedef enum
 #define VERT_BIT_TEX(i)  VERT_BIT(VERT_ATTRIB_TEX(i))
 #define VERT_BIT_TEX_ALL \
BITFIELD64_RANGE(VERT_ATTRIB_TEX(0), VERT_ATTRIB_TEX_MAX)
+#define VERT_BIT_FF_NVALIAS  \
+   BITFIELD64_RANGE(VERT_ATTRIB_POS, VERT_ATTRIB_TEX(VERT_ATTRIB_TEX_MAX))
+
 #define VERT_BIT_GENERIC_NV(i)   VERT_BIT(VERT_ATTRIB_GENERIC_NV(i))
 #define VERT_BIT_GENERIC_NV_ALL  \
BITFIELD64_RANGE(VERT_ATTRIB_GENERIC_NV(0), VERT_ATTRIB_GENERIC_NV_MAX)
+
 #define VERT_BIT_GENERIC(i)  VERT_BIT(VERT_ATTRIB_GENERIC(i))
 #define VERT_BIT_GENERIC_ALL \
BITFIELD64_RANGE(VERT_ATTRIB_GENERIC(0), VERT_ATTRIB_GENERIC_MAX)
-- 
1.7.7.5

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


[Mesa-dev] [PATCH 0/2] Make a llvmpipe context basically thread safe v2.

2014-08-31 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

Hi Jose,

This makes llvmpipe thread safe as mandated by the OpenGL standard.
The changes replace the use of two global data structures with
non global ones.
The changes pass piglit as of today without regressions.
The patchset now sticks to your initial suggestion and the review notes to
the first patch version.

Please review!
Mathias

Mathias Fröhlich (2):
  llvmpipe: Use two LLVMContexts per OpenGL context instead of a global
one.
  llvmpipe: Make a llvmpipe OpenGL context thread safe.

 src/gallium/auxiliary/draw/draw_llvm.c| 15 +--
 src/gallium/auxiliary/draw/draw_llvm.h|  2 ++
 src/gallium/auxiliary/gallivm/lp_bld_init.c   | 35 ++--
 src/gallium/auxiliary/gallivm/lp_bld_init.h   |  3 ++-
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 38 +--
 src/gallium/auxiliary/gallivm/lp_bld_misc.h   |  3 +++
 src/gallium/drivers/llvmpipe/lp_context.c |  7 +
 src/gallium/drivers/llvmpipe/lp_context.h |  3 +++
 src/gallium/drivers/llvmpipe/lp_state_fs.c|  2 +-
 src/gallium/drivers/llvmpipe/lp_state_setup.c |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_arit.c   |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_blend.c  |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_conv.c   |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_format.c |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_printf.c |  2 +-
 15 files changed, 70 insertions(+), 50 deletions(-)

-- 
1.9.3

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


[Mesa-dev] [PATCH 1/2] llvmpipe: Use two LLVMContexts per OpenGL context instead of a global one.

2014-08-31 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

This is one step to make llvmpipe thread safe as mandated by the OpenGL
standard. Using the global LLVMContext is obviously a problem for
that kind of use pattern. The patch introduces two LLVMContext
instances that are private to an OpenGL context and used for all
compiles. One is put into struct draw_llvm and the other
one into struct llvmpipe_context.

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 src/gallium/auxiliary/draw/draw_llvm.c| 15 --
 src/gallium/auxiliary/draw/draw_llvm.h|  2 ++
 src/gallium/auxiliary/gallivm/lp_bld_init.c   | 28 +++
 src/gallium/auxiliary/gallivm/lp_bld_init.h   |  2 +-
 src/gallium/drivers/llvmpipe/lp_context.c |  7 +++
 src/gallium/drivers/llvmpipe/lp_context.h |  3 +++
 src/gallium/drivers/llvmpipe/lp_state_fs.c|  2 +-
 src/gallium/drivers/llvmpipe/lp_state_setup.c |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_arit.c   |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_blend.c  |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_conv.c   |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_format.c |  2 +-
 src/gallium/drivers/llvmpipe/lp_test_printf.c |  2 +-
 13 files changed, 40 insertions(+), 31 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_llvm.c 
b/src/gallium/auxiliary/draw/draw_llvm.c
index e8e837a..ae14fed 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -492,6 +492,10 @@ draw_llvm_create(struct draw_context *draw)
 
llvm-draw = draw;
 
+   llvm-context = LLVMContextCreate();
+   if (!llvm-context)
+  goto fail;
+
llvm-nr_variants = 0;
make_empty_list(llvm-vs_variants_list);
 
@@ -499,6 +503,10 @@ draw_llvm_create(struct draw_context *draw)
make_empty_list(llvm-gs_variants_list);
 
return llvm;
+
+fail:
+   draw_llvm_destroy(llvm);
+   return NULL;
 }
 
 
@@ -508,6 +516,9 @@ draw_llvm_create(struct draw_context *draw)
 void
 draw_llvm_destroy(struct draw_llvm *llvm)
 {
+   LLVMContextDispose(llvm-context);
+   llvm-context = NULL;
+
/* XXX free other draw_llvm data? */
FREE(llvm);
 }
@@ -539,7 +550,7 @@ draw_llvm_create_variant(struct draw_llvm *llvm,
util_snprintf(module_name, sizeof(module_name), draw_llvm_vs_variant%u,
  variant-shader-variants_cached);
 
-   variant-gallivm = gallivm_create(module_name);
+   variant-gallivm = gallivm_create(module_name, llvm-context);
 
create_jit_types(variant);
 
@@ -2194,7 +2205,7 @@ draw_gs_llvm_create_variant(struct draw_llvm *llvm,
util_snprintf(module_name, sizeof(module_name), draw_llvm_gs_variant%u,
  variant-shader-variants_cached);
 
-   variant-gallivm = gallivm_create(module_name);
+   variant-gallivm = gallivm_create(module_name, llvm-context);
 
create_gs_jit_types(variant);
 
diff --git a/src/gallium/auxiliary/draw/draw_llvm.h 
b/src/gallium/auxiliary/draw/draw_llvm.h
index ed97cf7..a4bd1ed 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.h
+++ b/src/gallium/auxiliary/draw/draw_llvm.h
@@ -461,6 +461,8 @@ struct llvm_geometry_shader {
 struct draw_llvm {
struct draw_context *draw;
 
+   LLVMContextRef context;
+
struct draw_jit_context jit_context;
struct draw_gs_jit_context gs_jit_context;
 
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c 
b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 8b8686d..dfc28b4 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -69,17 +69,6 @@
 void LLVMLinkInMCJIT();
 #endif
 
-/*
- * LLVM has several global caches which pointing/derived from objects
- * owned by the context, so if we freeing contexts causes
- * memory leaks and false cache hits when these objects are destroyed.
- *
- * TODO: For thread safety on multi-threaded OpenGL we should use one LLVM
- * context per thread, and put them in a pool when threads are destroyed.
- */
-#define USE_GLOBAL_CONTEXT 1
-
-
 #ifdef DEBUG
 unsigned gallivm_debug = 0;
 
@@ -193,8 +182,7 @@ gallivm_free_ir(struct gallivm_state *gallivm)
if (gallivm-builder)
   LLVMDisposeBuilder(gallivm-builder);
 
-   if (!USE_GLOBAL_CONTEXT  gallivm-context)
-  LLVMContextDispose(gallivm-context);
+   /* The LLVMContext should be owned by the parent of gallivm. */
 
gallivm-engine = NULL;
gallivm-target = NULL;
@@ -285,18 +273,16 @@ fail:
  * \return  TRUE for success, FALSE for failure
  */
 static boolean
-init_gallivm_state(struct gallivm_state *gallivm, const char *name)
+init_gallivm_state(struct gallivm_state *gallivm, const char *name,
+   LLVMContextRef context)
 {
assert(!gallivm-context);
assert(!gallivm-module);
 
lp_build_init();
 
-   if (USE_GLOBAL_CONTEXT) {
-  gallivm-context = LLVMGetGlobalContext();
-   } else {
-  gallivm-context = LLVMContextCreate();
-   }
+   gallivm-context = context;
+
if (!gallivm-context)
   goto fail

[Mesa-dev] [PATCH 2/2] llvmpipe: Make a llvmpipe OpenGL context thread safe.

2014-08-31 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

This fixes the remaining problem with the recently introduced
global jit memory manager. This change again uses a memory manager
that is local to gallivm_state. This implementation still frees
the majority of the memory immediately after compilation.
Only the generated code is deferred until this code is no longer used.

This change and the previous one using private LLVMContext instances
I can now safely run several independent OpenGL contexts driven
by llvmpipe from different threads.

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 src/gallium/auxiliary/gallivm/lp_bld_init.c   |  7 +
 src/gallium/auxiliary/gallivm/lp_bld_init.h   |  1 +
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 38 +--
 src/gallium/auxiliary/gallivm/lp_bld_misc.h   |  3 +++
 4 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c 
b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index dfc28b4..a38979f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -203,6 +203,8 @@ gallivm_free_code(struct gallivm_state *gallivm)
assert(!gallivm-engine);
lp_free_generated_code(gallivm-code);
gallivm-code = NULL;
+   LLVMDisposeMCJITMemoryManager(gallivm-memorymgr);
+   gallivm-memorymgr = NULL;
 }
 
 
@@ -224,6 +226,7 @@ init_gallivm_engine(struct gallivm_state *gallivm)
   ret = lp_build_create_jit_compiler_for_module(gallivm-engine,
 gallivm-code,
 gallivm-module,
+gallivm-memorymgr,
 (unsigned) optlevel,
 USE_MCJIT,
 error);
@@ -295,6 +298,10 @@ init_gallivm_state(struct gallivm_state *gallivm, const 
char *name,
if (!gallivm-builder)
   goto fail;
 
+   gallivm-memorymgr = lp_get_default_memory_manager();
+   if (!gallivm-memorymgr)
+  goto fail;
+
/* FIXME: MC-JIT only allows compiling one module at a time, and it must be
 * complete when MC-JIT is created. So defer the MC-JIT engine creation for
 * now.
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h 
b/src/gallium/auxiliary/gallivm/lp_bld_init.h
index 8f20158..cb78210 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h
@@ -44,6 +44,7 @@ struct gallivm_state
LLVMPassManagerRef passmgr;
LLVMContextRef context;
LLVMBuilderRef builder;
+   LLVMMCJITMemoryManagerRef memorymgr;
struct lp_generated_code *code;
unsigned compiled;
 };
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp 
b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index 55aa8b9..dc7206f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -319,15 +319,15 @@ class DelegatingJITMemoryManager : public 
llvm::JITMemoryManager {
  */
 class ShaderMemoryManager : public DelegatingJITMemoryManager {
 
-   static llvm::JITMemoryManager *TheMM;
-   static unsigned NumUsers;
+   llvm::JITMemoryManager *TheMM;
 
struct GeneratedCode {
   typedef std::vectorvoid * Vec;
   Vec FunctionBody, ExceptionTable;
+  llvm::JITMemoryManager *TheMM;
 
-  GeneratedCode() {
- ++NumUsers;
+  GeneratedCode(llvm::JITMemoryManager *MM) {
+ TheMM = MM;
   }
 
   ~GeneratedCode() {
@@ -344,27 +344,20 @@ class ShaderMemoryManager : public 
DelegatingJITMemoryManager {
 for ( i = ExceptionTable.begin(); i != ExceptionTable.end(); ++i )
TheMM-deallocateExceptionTable(*i);
 #endif
- --NumUsers;
- if (NumUsers == 0) {
-delete TheMM;
-TheMM = 0;
- }
   }
};
 
GeneratedCode *code;
 
llvm::JITMemoryManager *mgr() const {
-  if (!TheMM) {
- TheMM = CreateDefaultMemManager();
-  }
   return TheMM;
}
 
public:
 
-  ShaderMemoryManager() {
- code = new GeneratedCode;
+  ShaderMemoryManager(llvm::JITMemoryManager* MM) {
+ TheMM = MM;
+ code = new GeneratedCode(MM);
   }
 
   virtual ~ShaderMemoryManager() {
@@ -395,10 +388,6 @@ class ShaderMemoryManager : public 
DelegatingJITMemoryManager {
   }
 };
 
-llvm::JITMemoryManager *ShaderMemoryManager::TheMM = 0;
-unsigned ShaderMemoryManager::NumUsers = 0;
-
-
 /**
  * Same as LLVMCreateJITCompilerForModule, but:
  * - allows using MCJIT and enabling AVX feature where available.
@@ -414,6 +403,7 @@ LLVMBool
 lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
 lp_generated_code **OutCode,
 LLVMModuleRef M

[Mesa-dev] [PATCH] Add support for NV_depth_buffer_float.

2014-09-06 Thread Mathias Froehlich

Hi,

Please review:

Add support for the unclamped versions of glDepthRange
and relatives. Also starting with OpenGL 4.2 the traditional
functions for this should no longer clamp the values to [0, 1].

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 docs/GL3.txt |  1 +
 src/mapi/glapi/gen/NV_depth_buffer_float.xml | 24 
 src/mapi/glapi/gen/gl_API.xml|  2 +
 src/mesa/drivers/common/meta.c   |  3 +-
 src/mesa/main/attrib.c   |  6 +-
 src/mesa/main/depth.c| 82 +++-
 src/mesa/main/depth.h|  6 ++
 src/mesa/main/dlist.c| 67 +++
 src/mesa/main/extensions.c   |  1 +
 src/mesa/main/viewport.c | 77 +-
 src/mesa/main/viewport.h |  9 ++-
 11 files changed, 223 insertions(+), 55 deletions(-)
 create mode 100644 src/mapi/glapi/gen/NV_depth_buffer_float.xml

diff --git a/docs/GL3.txt b/docs/GL3.txt
index f5d5e72..a869beb 100644
--- a/docs/GL3.txt
+++ b/docs/GL3.txt
@@ -144,6 +144,7 @@ GL 4.2, GLSL 4.20:
   GL_ARB_shading_language_420pack  DONE (all drivers that 
support GLSL 1.30)
   GL_ARB_internalformat_query  DONE (i965, nv50, nvc0, 
r300, r600, radeonsi, llvmpipe, softpipe)
   GL_ARB_map_buffer_alignment  DONE (all drivers)
+  Unclamped glDepthRange and GL_NV_depth_buffer_float  DONE (all drivers)
 
 
 GL 4.3, GLSL 4.30:
diff --git a/src/mapi/glapi/gen/NV_depth_buffer_float.xml 
b/src/mapi/glapi/gen/NV_depth_buffer_float.xml
new file mode 100644
index 000..17ee268
--- /dev/null
+++ b/src/mapi/glapi/gen/NV_depth_buffer_float.xml
@@ -0,0 +1,24 @@
+?xml version=1.0?
+!DOCTYPE OpenGLAPI SYSTEM gl_API.dtd
+
+!-- Note: no GLX protocol info yet. --
+
+OpenGLAPI
+
+category name=GL_NV_depth_buffer_float number=417
+
+function name=DepthRangedNV offset=assign
+param name=n type=GLdouble/
+param name=f type=GLdouble/
+/function
+function name=ClearDepthdNV offset=assign
+param name=d type=GLdouble/
+/function
+function name=DepthBoundsdNV offset=assign
+param name=zmin type=GLdouble/
+param name=zmax type=GLdouble/
+/function
+
+/category
+
+/OpenGLAPI
diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
index 73f2f75..d504faf 100644
--- a/src/mapi/glapi/gen/gl_API.xml
+++ b/src/mapi/glapi/gen/gl_API.xml
@@ -13027,6 +13027,8 @@
 
 xi:include href=NV_vdpau_interop.xml 
xmlns:xi=http://www.w3.org/2001/XInclude/
 
+xi:include href=NV_depth_buffer_float.xml 
xmlns:xi=http://www.w3.org/2001/XInclude/
+
 xi:include href=GL4x.xml xmlns:xi=http://www.w3.org/2001/XInclude/
 
 /OpenGLAPI
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 7a8e627..d165f12 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -1112,7 +1112,8 @@ _mesa_meta_end(struct gl_context *ctx)
  _mesa_set_viewport(ctx, 0, save-ViewportX, save-ViewportY,
 save-ViewportW, save-ViewportH);
   }
-  _mesa_DepthRange(save-DepthNear, save-DepthFar);
+  /* Need to call ...NV since this is guaranteed not to clamp to [0,1] */
+  _mesa_DepthRangedNV(save-DepthNear, save-DepthFar);
}
 
if (state  MESA_META_CLAMP_FRAGMENT_COLOR 
diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index 2e289b6..7368ee1 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -1072,7 +1072,9 @@ _mesa_PopAttrib(void)
const struct gl_depthbuffer_attrib *depth;
depth = (const struct gl_depthbuffer_attrib *) attr-data;
_mesa_DepthFunc(depth-Func);
-   _mesa_ClearDepth(depth-Clear);
+   /* The ...NV variant is guaranteed not to clamp */
+   /* what was not clamped before. */
+   _mesa_ClearDepthdNV(depth-Clear);
_mesa_set_enable(ctx, GL_DEPTH_TEST, depth-Test);
_mesa_DepthMask(depth-Mask);
 }
@@ -1364,7 +1366,7 @@ _mesa_PopAttrib(void)
for (i = 0; i  ctx-Const.MaxViewports; i++) {
   _mesa_set_viewport(ctx, i, vp[i].X, vp[i].Y, vp[i].Width,
  vp[i].Height);
-  _mesa_set_depth_range(ctx, i, vp[i].Near, vp[i].Far);
+  _mesa_set_depth_range(ctx, i, vp[i].Near, vp[i].Far, 
GL_FALSE);
}
 }
 break;
diff --git a/src/mesa/main/depth.c b/src/mesa/main/depth.c
index 29851ec..9ef10bf 100644
--- a/src/mesa/main/depth.c
+++ b/src/mesa/main/depth.c
@@ -32,30 +32,69 @@
 #include mtypes.h
 
 
+static void
+set_clear_depth( struct gl_context *ctx, const char* fcn,
+ GLdouble depth, GLboolean clamp )
+{
+   if (MESA_VERBOSE  VERBOSE_API

[Mesa-dev] [PATCH 1/4] mesa: Rework depth range setting in preparation for NV_depth_buffer_float.

2014-09-14 Thread Mathias . Froehlich
From: Mathias Froehlich mathias.froehl...@web.de

Factor out some functions that will get additional callers
with the implementation of NV_depth_buffer_float.

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 src/mesa/main/attrib.c   |  2 +-
 src/mesa/main/depth.c| 66 ++--
 src/mesa/main/viewport.c | 64 +++---
 src/mesa/main/viewport.h |  2 +-
 4 files changed, 82 insertions(+), 52 deletions(-)

diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index 2e289b6..97115a1 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -1364,7 +1364,7 @@ _mesa_PopAttrib(void)
for (i = 0; i  ctx-Const.MaxViewports; i++) {
   _mesa_set_viewport(ctx, i, vp[i].X, vp[i].Y, vp[i].Width,
  vp[i].Height);
-  _mesa_set_depth_range(ctx, i, vp[i].Near, vp[i].Far);
+  _mesa_set_depth_range(ctx, i, vp[i].Near, vp[i].Far, false);
}
 }
 break;
diff --git a/src/mesa/main/depth.c b/src/mesa/main/depth.c
index 29851ec..8ae3cb6 100644
--- a/src/mesa/main/depth.c
+++ b/src/mesa/main/depth.c
@@ -32,6 +32,44 @@
 #include mtypes.h
 
 
+static void
+set_clear_depth( struct gl_context *ctx, const char* fcn,
+ GLdouble depth, bool clamp )
+{
+   if (MESA_VERBOSE  VERBOSE_API)
+  _mesa_debug(ctx, %s(%f)\n, fcn, depth);
+
+   if (clamp)
+  depth = CLAMP( depth, 0.0, 1.0 );
+
+   ctx-Depth.Clear = depth;
+}
+
+static void
+set_depth_bounds( struct gl_context *ctx, const char* fcn,
+  GLdouble zmin, GLdouble zmax, bool clamp )
+{
+   if (MESA_VERBOSE  VERBOSE_API)
+  _mesa_debug(ctx, %s(%f, %f)\n, fcn, zmin, zmax);
+
+   if (zmin  zmax) {
+  _mesa_error(ctx, GL_INVALID_VALUE, %s(zmin  zmax), fcn);
+  return;
+   }
+
+   if (clamp) {
+  zmin = CLAMP(zmin, 0.0, 1.0);
+  zmax = CLAMP(zmax, 0.0, 1.0);
+   }
+
+   if (ctx-Depth.BoundsMin == zmin  ctx-Depth.BoundsMax == zmax)
+  return;
+
+   FLUSH_VERTICES(ctx, _NEW_DEPTH);
+   ctx-Depth.BoundsMin = (GLfloat) zmin;
+   ctx-Depth.BoundsMax = (GLfloat) zmax;
+}
+
 /**/
 /*  API Functions */
 /**/
@@ -42,18 +80,15 @@ void GLAPIENTRY
 _mesa_ClearDepth( GLclampd depth )
 {
GET_CURRENT_CONTEXT(ctx);
-
-   if (MESA_VERBOSE  VERBOSE_API)
-  _mesa_debug(ctx, glClearDepth(%f)\n, depth);
-
-   ctx-Depth.Clear = CLAMP( depth, 0.0, 1.0 );
+   set_clear_depth(ctx, glClearDepth, depth, true);
 }
 
 
 void GLAPIENTRY
 _mesa_ClearDepthf( GLclampf depth )
 {
-   _mesa_ClearDepth(depth);
+   GET_CURRENT_CONTEXT(ctx);
+   set_clear_depth(ctx, glClearDepthf, depth, true);
 }
 
 
@@ -123,24 +158,7 @@ void GLAPIENTRY
 _mesa_DepthBoundsEXT( GLclampd zmin, GLclampd zmax )
 {
GET_CURRENT_CONTEXT(ctx);
-
-   if (MESA_VERBOSE  VERBOSE_API)
-  _mesa_debug(ctx, glDepthBounds(%f, %f)\n, zmin, zmax);
-
-   if (zmin  zmax) {
-  _mesa_error(ctx, GL_INVALID_VALUE, glDepthBoundsEXT(zmin  zmax));
-  return;
-   }
-
-   zmin = CLAMP(zmin, 0.0, 1.0);
-   zmax = CLAMP(zmax, 0.0, 1.0);
-
-   if (ctx-Depth.BoundsMin == zmin  ctx-Depth.BoundsMax == zmax)
-  return;
-
-   FLUSH_VERTICES(ctx, _NEW_DEPTH);
-   ctx-Depth.BoundsMin = (GLfloat) zmin;
-   ctx-Depth.BoundsMax = (GLfloat) zmax;
+   set_depth_bounds(ctx, glDepthBoundsEXT, zmin, zmax, true);
 }
 
 
diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c
index 6545bf6..e86a77c 100644
--- a/src/mesa/main/viewport.c
+++ b/src/mesa/main/viewport.c
@@ -240,14 +240,19 @@ _mesa_ViewportIndexedfv(GLuint index, const GLfloat *v)
 
 static void
 set_depth_range_no_notify(struct gl_context *ctx, unsigned idx,
-  GLclampd nearval, GLclampd farval)
+  GLdouble nearval, GLdouble farval, bool clamp)
 {
+   if (clamp) {
+  nearval = CLAMP(nearval, 0.0, 1.0);
+  farval = CLAMP(farval, 0.0, 1.0);
+   }
+
if (ctx-ViewportArray[idx].Near == nearval 
ctx-ViewportArray[idx].Far == farval)
   return;
 
-   ctx-ViewportArray[idx].Near = CLAMP(nearval, 0.0, 1.0);
-   ctx-ViewportArray[idx].Far = CLAMP(farval, 0.0, 1.0);
+   ctx-ViewportArray[idx].Near = nearval;
+   ctx-ViewportArray[idx].Far = farval;
ctx-NewState |= _NEW_VIEWPORT;
 
 #if 1
@@ -268,32 +273,19 @@ set_depth_range_no_notify(struct gl_context *ctx, 
unsigned idx,
 
 void
 _mesa_set_depth_range(struct gl_context *ctx, unsigned idx,
-  GLclampd nearval, GLclampd farval)
+  GLdouble nearval, GLdouble farval, bool clamp)
 {
-   set_depth_range_no_notify(ctx, idx, nearval, farval);
+   set_depth_range_no_notify(ctx, idx, nearval, farval, clamp);
 
if (ctx-Driver.DepthRange)
   ctx

[Mesa-dev] [PATCH 0/4] Add support for NV_depth_buffer_float v3.

2014-09-14 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

This adds support for NV_depth_buffer_float.

Mostly the unclamped depth buffer handling which can be exploited
to get logarithmic depth buffer like behavior in a simple way.

v2
  Readd clamping to the traditional gl entry points.

v3
  Split the patch into preparational changes and an extension implementation.
  Fix 'make check'.
  Add handling for the introduced enums which are not overlapping with core gl.
  Make NV_depth_buffer_float a seperate extension not enabled by default.
  Minor changes in the implementation like requested.

Please review.

Mathias Fröhlich (4):
  mesa: Rework depth range setting in preparation for NV_depth_buffer_float.
  mesa: Add helper function to see if we have a float depth format.
  gallium: introduce PIPE_CAP_UNCLAMPED_DEPTH_VALUES.
  mesa: Add support for NV_depth_buffer_float.

 docs/relnotes/10.3.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/NV_depth_buffer_float.xml | 32 ++
 src/mapi/glapi/gen/gl_API.xml|  2 +
 src/mesa/drivers/common/meta.c   |  3 +-
 src/mesa/main/attrib.c   |  6 +-
 src/mesa/main/depth.c| 80 +---
 src/mesa/main/depth.h|  6 ++
 src/mesa/main/dlist.c| 67 
 src/mesa/main/extensions.c   |  1 +
 src/mesa/main/fbobject.c |  5 ++
 src/mesa/main/get.c  | 15 +
 src/mesa/main/get_hash_params.py |  3 +
 src/mesa/main/glformats.c| 27 +++-
 src/mesa/main/glformats.h|  3 +
 src/mesa/main/mtypes.h   |  1 +
 src/mesa/main/tests/dispatch_sanity.cpp  |  5 ++
 src/mesa/main/texformat.c|  2 +
 src/mesa/main/teximage.c |  2 +
 src/mesa/main/viewport.c | 77 +++
 src/mesa/main/viewport.h |  5 +-
 src/mesa/state_tracker/st_extensions.c   |  1 +
 src/mesa/state_tracker/st_format.c   |  8 +++
 37 files changed, 316 insertions(+), 55 deletions(-)
 create mode 100644 src/mapi/glapi/gen/NV_depth_buffer_float.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/4] mesa: Add support for NV_depth_buffer_float.

2014-09-14 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

This is mostly support for the unclamped versions of
glDepthRangedNV, glClearDepthdNV and glDepthBoundsdNV.
Note that OpenGL 4.2 introduced that the traditonal
glDepthRange functions may no longer clamp to [0, 1],
but OpenGL 4.3 already revoked this behavior to clamp
the arguments.

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 docs/relnotes/10.3.html  |  1 +
 src/mapi/glapi/gen/NV_depth_buffer_float.xml | 32 +
 src/mapi/glapi/gen/gl_API.xml|  2 +
 src/mesa/drivers/common/meta.c   |  3 +-
 src/mesa/main/attrib.c   |  4 +-
 src/mesa/main/depth.c| 16 +++
 src/mesa/main/depth.h|  6 +++
 src/mesa/main/dlist.c| 67 
 src/mesa/main/extensions.c   |  1 +
 src/mesa/main/fbobject.c |  5 +++
 src/mesa/main/get.c  | 15 +++
 src/mesa/main/get_hash_params.py |  3 ++
 src/mesa/main/glformats.c|  9 +++-
 src/mesa/main/mtypes.h   |  1 +
 src/mesa/main/tests/dispatch_sanity.cpp  |  5 +++
 src/mesa/main/texformat.c|  2 +
 src/mesa/main/teximage.c |  2 +
 src/mesa/main/viewport.c | 13 ++
 src/mesa/main/viewport.h |  3 ++
 src/mesa/state_tracker/st_extensions.c   |  1 +
 src/mesa/state_tracker/st_format.c   |  8 
 21 files changed, 195 insertions(+), 4 deletions(-)
 create mode 100644 src/mapi/glapi/gen/NV_depth_buffer_float.xml

diff --git a/docs/relnotes/10.3.html b/docs/relnotes/10.3.html
index fa4ea23..702f4b6 100644
--- a/docs/relnotes/10.3.html
+++ b/docs/relnotes/10.3.html
@@ -65,6 +65,7 @@ Note: some of the new features are only available with 
certain drivers.
 liGL_ARB_texture_query_lod on r600, radeonsi/li
 liGL_ARB_viewport_array on nvc0/li
 liGL_AMD_vertex_shader_viewport_index on i965/gen7+, r600/li
+liGL_NV_depth_buffer_float on softpipe, llvmpipe/li
 liGL_OES_compressed_ETC1_RGB8_texture on nv30, nv50, nvc0, r300, r600, 
radeonsi, softpipe, llvmpipe/li
 liGLX_MESA_query_renderer on nv30, nv50, nvc0, r300, r600, radeonsi, 
softpipe, llvmpipe/li
 liA new software rasterizer driver (kms_swrast_dri.so) that works with
diff --git a/src/mapi/glapi/gen/NV_depth_buffer_float.xml 
b/src/mapi/glapi/gen/NV_depth_buffer_float.xml
new file mode 100644
index 000..289538cf
--- /dev/null
+++ b/src/mapi/glapi/gen/NV_depth_buffer_float.xml
@@ -0,0 +1,32 @@
+?xml version=1.0?
+!DOCTYPE OpenGLAPI SYSTEM gl_API.dtd
+
+!-- Note: no GLX protocol info yet. --
+
+OpenGLAPI
+
+category name=GL_NV_depth_buffer_float number=334
+
+enum name=DEPTH_COMPONENT32F_NVvalue = 0x8DAB/
+enum name=DEPTH32F_STENCIL8_NV value = 0x8DAC/
+
+!-- Is the same than FLOAT_32_UNSIGNED_INT_24_8_REV. --
+enum name=FLOAT_32_UNSIGNED_INT_24_8_REV_NV value = 0x8DAD/
+
+enum name=DEPTH_BUFFER_FLOAT_MODE_NV value = 0x8DAF/
+
+function name=DepthRangedNV offset=assign
+param name=n type=GLdouble/
+param name=f type=GLdouble/
+/function
+function name=ClearDepthdNV offset=assign
+param name=d type=GLdouble/
+/function
+function name=DepthBoundsdNV offset=assign
+param name=zmin type=GLdouble/
+param name=zmax type=GLdouble/
+/function
+
+/category
+
+/OpenGLAPI
diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
index 73f2f75..d504faf 100644
--- a/src/mapi/glapi/gen/gl_API.xml
+++ b/src/mapi/glapi/gen/gl_API.xml
@@ -13027,6 +13027,8 @@
 
 xi:include href=NV_vdpau_interop.xml 
xmlns:xi=http://www.w3.org/2001/XInclude/
 
+xi:include href=NV_depth_buffer_float.xml 
xmlns:xi=http://www.w3.org/2001/XInclude/
+
 xi:include href=GL4x.xml xmlns:xi=http://www.w3.org/2001/XInclude/
 
 /OpenGLAPI
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 7a8e627..d165f12 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -1112,7 +1112,8 @@ _mesa_meta_end(struct gl_context *ctx)
  _mesa_set_viewport(ctx, 0, save-ViewportX, save-ViewportY,
 save-ViewportW, save-ViewportH);
   }
-  _mesa_DepthRange(save-DepthNear, save-DepthFar);
+  /* Need to call ...NV since this is guaranteed not to clamp to [0,1] */
+  _mesa_DepthRangedNV(save-DepthNear, save-DepthFar);
}
 
if (state  MESA_META_CLAMP_FRAGMENT_COLOR 
diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index 97115a1..4930afd 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -1072,7 +1072,9 @@ _mesa_PopAttrib(void)
const struct gl_depthbuffer_attrib *depth;
depth = (const struct gl_depthbuffer_attrib *) attr-data;
_mesa_DepthFunc(depth-Func

[Mesa-dev] [PATCH 3/4] gallium: introduce PIPE_CAP_UNCLAMPED_DEPTH_VALUES.

2014-09-14 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

In preparation of NV_depth_buffer_float. Let the
driver decide if it could support writing depth values
beyond the [0, 1] range.

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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 +
 15 files changed, 19 insertions(+)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index c83be12..82f7c72 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -230,6 +230,9 @@ The integer capabilities:
   different than the underlying resource's, as permitted by
   ARB_texture_view. For example a 2d array texture may be reinterpreted as a
   cube (array) texture and vice-versa.
+* ``PIPE_CAP_UNCLAMPED_DEPTH_VALUES``: If depth value clamping to [0,1] can be
+  switched off when writing into the depth buffer. This controls whether
+  NV_depth_buffer_float is provided.
 
 
 .. _pipe_capf:
diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c 
b/src/gallium/drivers/freedreno/freedreno_screen.c
index 6db75ad..d868014 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.c
+++ b/src/gallium/drivers/freedreno/freedreno_screen.c
@@ -221,6 +221,7 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
case PIPE_CAP_SAMPLER_VIEW_TARGET:
+   case PIPE_CAP_UNCLAMPED_DEPTH_VALUES:
return 0;
 
/* Stream output. */
diff --git a/src/gallium/drivers/i915/i915_screen.c 
b/src/gallium/drivers/i915/i915_screen.c
index 9006734..1414ffd 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -223,6 +223,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap 
cap)
case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
+   case PIPE_CAP_UNCLAMPED_DEPTH_VALUES:
   return 0;
 
case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
diff --git a/src/gallium/drivers/ilo/ilo_screen.c 
b/src/gallium/drivers/ilo/ilo_screen.c
index 82fda2c..fc0f3eb 100644
--- a/src/gallium/drivers/ilo/ilo_screen.c
+++ b/src/gallium/drivers/ilo/ilo_screen.c
@@ -439,6 +439,7 @@ ilo_get_param(struct pipe_screen *screen, enum pipe_cap 
param)
case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
case PIPE_CAP_SAMPLER_VIEW_TARGET:
+   case PIPE_CAP_UNCLAMPED_DEPTH_VALUES:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index e6597e9..47a411c 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -277,6 +277,8 @@ llvmpipe_get_param(struct pipe_screen *screen, enum 
pipe_cap param)
}
case PIPE_CAP_UMA:
   return 0;
+   case PIPE_CAP_UNCLAMPED_DEPTH_VALUES:
+  return 1;
}
/* should only get here on unhandled cases */
debug_printf(Unexpected PIPE_CAP %d query\n, param);
diff --git a/src/gallium/drivers/nouveau/nv30/nv30_screen.c 
b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
index a1373fd..caf70be 100644
--- a/src/gallium/drivers/nouveau/nv30/nv30_screen.c
+++ b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
@@ -156,6 +156,7 @@ nv30_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
case PIPE_CAP_SAMPLER_VIEW_TARGET:
+   case PIPE_CAP_UNCLAMPED_DEPTH_VALUES:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index 3a46e72..618abf8 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -204,6 +204,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_COMPUTE:
case PIPE_CAP_DRAW_INDIRECT:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
+   case PIPE_CAP_UNCLAMPED_DEPTH_VALUES:
   return 0

[Mesa-dev] [PATCH 2/4] mesa: Add helper function to see if we have a float depth format.

2014-09-14 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

Will be used in the implementation of NV_depth_buffer_float.

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 src/mesa/main/glformats.c | 18 ++
 src/mesa/main/glformats.h |  3 +++
 2 files changed, 21 insertions(+)

diff --git a/src/mesa/main/glformats.c b/src/mesa/main/glformats.c
index 00478f9..16f7d6b 100644
--- a/src/mesa/main/glformats.c
+++ b/src/mesa/main/glformats.c
@@ -983,6 +983,24 @@ _mesa_is_depth_or_stencil_format(GLenum format)
 
 
 /**
+ * Test if the given image format is a float depth format.
+ */
+GLboolean
+_mesa_is_float_depth_format(GLenum format)
+{
+   switch (format) {
+  case GL_DEPTH_COMPONENT32F:
+  case GL_DEPTH_COMPONENT32F_NV:
+  case GL_DEPTH32F_STENCIL8:
+  case GL_DEPTH32F_STENCIL8_NV:
+ return GL_TRUE;
+  default:
+ return GL_FALSE;
+   }
+}
+
+
+/**
  * Test if an image format is a supported compressed format.
  * \param format the internal format token provided by the user.
  * \return GL_TRUE if compressed, GL_FALSE if uncompressed
diff --git a/src/mesa/main/glformats.h b/src/mesa/main/glformats.h
index 7b03215..a960786 100644
--- a/src/mesa/main/glformats.h
+++ b/src/mesa/main/glformats.h
@@ -93,6 +93,9 @@ extern GLboolean
 _mesa_is_depth_or_stencil_format(GLenum format);
 
 extern GLboolean
+_mesa_is_float_depth_format(GLenum format);
+
+extern GLboolean
 _mesa_is_compressed_format(struct gl_context *ctx, GLenum format);
 
 extern GLenum
-- 
1.9.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://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 mathias.froehl...@gmx.net

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

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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 mathias.froehl...@gmx.net

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 mathias.froehl...@gmx.net

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

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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 @@
+?xml version=1.0?
+!DOCTYPE OpenGLAPI SYSTEM gl_API.dtd
+
+OpenGLAPI
+
+category name=GL_ARB_clip_control number=160
+
+enum name=LOWER_LEFT value = 0x8CA1/
+enum name=UPPER_LEFT value = 0x8CA2/
+
+enum name=NEGATIVE_ONE_TO_ONE value = 0x935E/
+enum name=ZERO_TO_ONE value = 0x935F/
+
+enum name=CLIP_ORIGIN value = 0x935C/
+enum name=CLIP_DEPTH_MODE value = 0x935D/
+
+function name=ClipControl offset=assign
+param name=origin type=GLenum/
+param name=depth type=GLenum/
+glx rop=1340/
+/function
+
+/category
+
+/OpenGLAPI
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 @@
 
 xi:include href=ARB_multi_bind.xml 
xmlns:xi=http://www.w3.org/2001/XInclude/
 
-!-- ARB extensions 148 - 160 --
+!-- ARB extensions 148 - 159 --
+
+xi:include href=ARB_clip_control.xml 
xmlns:xi=http://www.w3.org/2001/XInclude/
 
 category name=GL_ARB_conditional_render_inverted number=161
 enum name=QUERY_WAIT_INVERTED  value=0x8E17/
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

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

2014-10-21 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

This is for preparation of ARB_clip_control.

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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_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;
@@ -261,14 +260,9 @@ set_depth_range_no_notify

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

2014-10-21 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

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

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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.
 ul
 liGL_ARB_sample_shading on r600/li
 liGL_ARB_texture_view on nv50, nvc0/li
+liGL_ARB_clip_control on gallium drivers/li
 /ul
 
 
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 mathias.froehl...@gmx.net

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 mathias.froehl...@web.de
---
 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.
 ul
 liGL_ARB_sample_shading on r600/li
 liGL_ARB_texture_view on nv50, nvc0/li
+liGL_ARB_clip_control on llvmpipe, softpipe/li
 /ul
 
 
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 mathias.froehl...@gmx.net

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

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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 @@
+?xml version=1.0?
+!DOCTYPE OpenGLAPI SYSTEM gl_API.dtd
+
+OpenGLAPI
+
+category name=GL_ARB_clip_control number=160
+
+enum name=LOWER_LEFT value = 0x8CA1/
+enum name=UPPER_LEFT value = 0x8CA2/
+
+enum name=NEGATIVE_ONE_TO_ONE value = 0x935E/
+enum name=ZERO_TO_ONE value = 0x935F/
+
+enum name=CLIP_ORIGIN value = 0x935C/
+enum name=CLIP_DEPTH_MODE value = 0x935D/
+
+function name=ClipControl offset=assign
+param name=origin type=GLenum/
+param name=depth type=GLenum/
+glx rop=1340/
+/function
+
+/category
+
+/OpenGLAPI
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 @@
 
 xi:include href=ARB_multi_bind.xml 
xmlns:xi=http://www.w3.org/2001/XInclude/
 
-!-- ARB extensions 148 - 160 --
+!-- ARB extensions 148 - 159 --
+
+xi:include href=ARB_clip_control.xml 
xmlns:xi=http://www.w3.org/2001/XInclude/
 
 category name=GL_ARB_conditional_render_inverted number=161
 enum name=QUERY_WAIT_INVERTED  value=0x8E17/
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

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

2014-10-22 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

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 mathias.froehl...@web.de
---
 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 +
 15 files changed, 19 insertions(+)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index 88d7e49..e711ad4 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -230,6 +230,9 @@ The integer capabilities:
   different than the underlying resource's, as permitted by
   ARB_texture_view. For example a 2d array texture may be reinterpreted as a
   cube (array) texture and vice-versa.
+* ``PIPE_CAP_CLIP_HALFZ``: Whether the driver supports the
+  pipe_rasterizer_state::clip_halfz being set to true. This is required
+  for enabling ARB_clip_control.
 
 
 .. _pipe_capf:
diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c 
b/src/gallium/drivers/freedreno/freedreno_screen.c
index 90156b4..7a3cd95 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.c
+++ b/src/gallium/drivers/freedreno/freedreno_screen.c
@@ -226,6 +226,7 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
case PIPE_CAP_SAMPLER_VIEW_TARGET:
+   case PIPE_CAP_CLIP_HALFZ:
return 0;
 
case PIPE_CAP_MAX_VIEWPORTS:
diff --git a/src/gallium/drivers/i915/i915_screen.c 
b/src/gallium/drivers/i915/i915_screen.c
index 2a6e751..062f1a6 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -225,6 +225,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap 
cap)
case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
+   case PIPE_CAP_CLIP_HALFZ:
   return 0;
 
case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
diff --git a/src/gallium/drivers/ilo/ilo_screen.c 
b/src/gallium/drivers/ilo/ilo_screen.c
index 48c3dea..4e931fb 100644
--- a/src/gallium/drivers/ilo/ilo_screen.c
+++ b/src/gallium/drivers/ilo/ilo_screen.c
@@ -446,6 +446,7 @@ ilo_get_param(struct pipe_screen *screen, enum pipe_cap 
param)
case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
case PIPE_CAP_SAMPLER_VIEW_TARGET:
+   case PIPE_CAP_CLIP_HALFZ:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index a264f99..df47e53 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -277,6 +277,8 @@ llvmpipe_get_param(struct pipe_screen *screen, enum 
pipe_cap param)
}
case PIPE_CAP_UMA:
   return 0;
+   case PIPE_CAP_CLIP_HALFZ:
+  return 1;
}
/* should only get here on unhandled cases */
debug_printf(Unexpected PIPE_CAP %d query\n, param);
diff --git a/src/gallium/drivers/nouveau/nv30/nv30_screen.c 
b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
index 700b9bb..2b65f8c 100644
--- a/src/gallium/drivers/nouveau/nv30/nv30_screen.c
+++ b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
@@ -156,6 +156,7 @@ nv30_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
case PIPE_CAP_SAMPLER_VIEW_TARGET:
+   case PIPE_CAP_CLIP_HALFZ:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index d26a438..4ee5980 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -204,6 +204,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_COMPUTE:
case PIPE_CAP_DRAW_INDIRECT:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
+   case PIPE_CAP_CLIP_HALFZ:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c 
b

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

2014-10-22 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

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

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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 mathias.froehl...@gmx.net

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 mathias.froehl...@gmx.net

This is for preparation of ARB_clip_control.

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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_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;
@@ -261,14 +260,9 @@ set_depth_range_no_notify

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

2014-10-24 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

This is for preparation of ARB_clip_control.

v3:
Add comments.

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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_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;
@@ -261,14 +260,9

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

2014-10-24 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

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 mathias.froehl...@web.de
---
 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.
 ul
 liGL_ARB_sample_shading on r600/li
 liGL_ARB_texture_view on nv50, nvc0/li
+liGL_ARB_clip_control on llvmpipe, softpipe, r300, r600, radeonsi/li
 /ul
 
 
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 mathias.froehl...@gmx.net

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 mathias.froehl...@gmx.net

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 mathias.froehl...@web.de
---
 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 +
 15 files changed, 20 insertions(+)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index 88d7e49..e711ad4 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -230,6 +230,9 @@ The integer capabilities:
   different than the underlying resource's, as permitted by
   ARB_texture_view. For example a 2d array texture may be reinterpreted as a
   cube (array) texture and vice-versa.
+* ``PIPE_CAP_CLIP_HALFZ``: Whether the driver supports the
+  pipe_rasterizer_state::clip_halfz being set to true. This is required
+  for enabling ARB_clip_control.
 
 
 .. _pipe_capf:
diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c 
b/src/gallium/drivers/freedreno/freedreno_screen.c
index 90156b4..7a3cd95 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.c
+++ b/src/gallium/drivers/freedreno/freedreno_screen.c
@@ -226,6 +226,7 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
case PIPE_CAP_SAMPLER_VIEW_TARGET:
+   case PIPE_CAP_CLIP_HALFZ:
return 0;
 
case PIPE_CAP_MAX_VIEWPORTS:
diff --git a/src/gallium/drivers/i915/i915_screen.c 
b/src/gallium/drivers/i915/i915_screen.c
index 2a6e751..062f1a6 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -225,6 +225,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap 
cap)
case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
+   case PIPE_CAP_CLIP_HALFZ:
   return 0;
 
case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
diff --git a/src/gallium/drivers/ilo/ilo_screen.c 
b/src/gallium/drivers/ilo/ilo_screen.c
index 48c3dea..da6cf76 100644
--- a/src/gallium/drivers/ilo/ilo_screen.c
+++ b/src/gallium/drivers/ilo/ilo_screen.c
@@ -469,6 +469,8 @@ ilo_get_param(struct pipe_screen *screen, enum pipe_cap 
param)
}
case PIPE_CAP_UMA:
   return true;
+   case PIPE_CAP_CLIP_HALFZ:
+  return true;
 
default:
   return 0;
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index ad716b7..cec0fcb 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -277,6 +277,8 @@ llvmpipe_get_param(struct pipe_screen *screen, enum 
pipe_cap param)
}
case PIPE_CAP_UMA:
   return 0;
+   case PIPE_CAP_CLIP_HALFZ:
+  return 1;
}
/* should only get here on unhandled cases */
debug_printf(Unexpected PIPE_CAP %d query\n, param);
diff --git a/src/gallium/drivers/nouveau/nv30/nv30_screen.c 
b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
index 700b9bb..2b65f8c 100644
--- a/src/gallium/drivers/nouveau/nv30/nv30_screen.c
+++ b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
@@ -156,6 +156,7 @@ nv30_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
case PIPE_CAP_SAMPLER_VIEW_TARGET:
+   case PIPE_CAP_CLIP_HALFZ:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index d26a438..4ee5980 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -204,6 +204,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_COMPUTE:
case PIPE_CAP_DRAW_INDIRECT:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
+   case PIPE_CAP_CLIP_HALFZ:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c 
b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c

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

2014-10-24 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

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 mathias.froehl...@web.de
---
 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 @@
+?xml version=1.0?
+!DOCTYPE OpenGLAPI SYSTEM gl_API.dtd
+
+OpenGLAPI
+
+category name=GL_ARB_clip_control number=160
+
+enum name=LOWER_LEFT value = 0x8CA1/
+enum name=UPPER_LEFT value = 0x8CA2/
+
+enum name=NEGATIVE_ONE_TO_ONE value = 0x935E/
+enum name=ZERO_TO_ONE value = 0x935F/
+
+enum name=CLIP_ORIGIN value = 0x935C/
+enum name=CLIP_DEPTH_MODE value = 0x935D/
+
+function name=ClipControl offset=assign
+param name=origin type=GLenum/
+param name=depth type=GLenum/
+glx rop=1340/
+/function
+
+/category
+
+/OpenGLAPI
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 @@
 
 xi:include href=ARB_multi_bind.xml 
xmlns:xi=http://www.w3.org/2001/XInclude/
 
-!-- ARB extensions 148 - 160 --
+!-- ARB extensions 148 - 159 --
+
+xi:include href=ARB_clip_control.xml 
xmlns:xi=http://www.w3.org/2001/XInclude/
 
 category name=GL_ARB_conditional_render_inverted number=161
 enum name=QUERY_WAIT_INVERTED  value=0x8E17/
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

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

2014-10-24 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

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 mathias.froehl...@web.de
---
 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-25 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

Fixes the link failures with make check.

Ok to commit?

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
CC: Ian Romanick ian.d.roman...@intel.com
---
 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 mathias.froehl...@gmx.net

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 mathias.froehl...@web.de
---
 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 mathias.froehl...@gmx.net

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 mar...@gmail.com.

CC: Marek Olšák mar...@gmail.com
Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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-31 Thread Mathias . Froehlich
From: Mathias Fröhlich mathias.froehl...@gmx.net

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 mathias.froehl...@web.de
---
 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.
 liGL_ARB_instanced_arrays on freedreno/li
 liGL_ARB_pipeline_statistics_query on i965, nv50, nvc0, r600, radeonsi, 
softpipe/li
 liGL_ARB_draw_indirect, GL_ARB_multi_draw_indirect on r600/li
+liGL_ARB_clip_control on i965/li
 /ul
 
 h2Bug fixes/h2
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().
*/
-  key.frontface_ccw = (ctx

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

2015-03-31 Thread Mathias . Froehlich
From: Mathias Froehlich mathias.froehl...@gmx.net

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 mathias.froehl...@web.de
---
 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-Current.RasterPos[1] = (ndc[1] * scale[1] + translate[1]);
+  ctx-Current.RasterPos[2] = (ndc[2] * scale[2] + translate[2]);
   ctx-Current.RasterPos[3] = clip[3];
 
   if (ctx-Transform.DepthClamp) {
-- 
2.1.0

___
mesa

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

2015-03-31 Thread Mathias . Froehlich
From: Mathias Froehlich mathias.froehl...@gmx.net

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 mathias.froehl...@web.de
---
 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-DrawBuffer);
struct gen7_sf_clip_viewport *vp;
@@ -52,7 +52,8 @@ gen7_upload_sf_clip_viewport(struct brw_context *brw)
}
 
for (unsigned i = 0; i  ctx-Const.MaxViewports; i++) {
-  const GLfloat *const v = ctx-ViewportArray[i]._WindowMap.m;
+  double scale[3], translate[3];
+  _mesa_get_viewport_xform(ctx, i, scale

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

2015-03-31 Thread Mathias . Froehlich
From: Mathias Froehlich mathias.froehl...@gmx.net

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 mathias.froehl...@web.de
---
 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 4/4] mesa: Remove the _WindowMap from gl_viewport_attrib.

2015-03-31 Thread Mathias . Froehlich
From: Mathias Froehlich mathias.froehl...@gmx.net

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

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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-ViewportArray[idx].Near = CLAMP(nearval, 0.0, 1.0);
ctx-ViewportArray[idx].Far = CLAMP(farval, 0.0, 1.0);
ctx-NewState |= _NEW_VIEWPORT;
-
-#if 1

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

2015-03-31 Thread Mathias . Froehlich
From: Mathias Froehlich mathias.froehl...@gmx.net

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] i965: Flush batchbuffer containing the query on glQueryCounter.

2015-04-12 Thread Mathias . Froehlich
From: Mathias Froehlich mathias.froehl...@gmx.net

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 mathias.froehl...@web.de
---
 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] mesa: Remove unused variables left over from 107ae27e57d.

2015-04-05 Thread Mathias . Froehlich
From: Mathias Froehlich mathias.froehl...@gmx.net

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

Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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 2/4] radeon: Make use of _mesa_get_viewport_xform v2.

2015-04-02 Thread Mathias . Froehlich
From: Mathias Froehlich mathias.froehl...@web.de

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 bri...@vmware.com
Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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 mathias.froehl...@web.de

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 bri...@vmware.com
Signed-off-by: Mathias Froehlich mathias.froehl...@web.de
---
 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_viewport_xform(ctx, 0, scale, translate);
+  ctx-Current.RasterPos[0] = ndc[0] * scale[0] + translate[0];
+  ctx-Current.RasterPos[1] = ndc[1] * scale[1] + translate[1];
+  ctx-Current.RasterPos[2

[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 +-
 

[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();
+  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();
+  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<Transform.ClipPlanesEnabled;
+  while (mask) {
+ const int j = _mesa_bit_scan();
+ buf[offset + i * 4 + 0].f = clip_planes[j][0];
+ buf[offset + i * 4 + 1].f = clip_planes[j][1];
+ buf[offset + i * 4 + 2].f = clip_planes[j][2];
+ buf[offset + i * 4 + 3].f = clip_planes[j][3];
+ i++;
   }
}
 
-- 
2.5.5

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


[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();
+  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();
+ _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();
+ _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();
+
+  _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();
+  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 

[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 = >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(>_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 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(>Light.EnabledList,
-   >Light.Light[cap-GL_LIGHT0]);
  }
  else {
 ctx->Light._EnabledLights &= ~(1u << (cap - GL_LIGHT0));
-remove_from_list(>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( >Light.Light[i], i );
}
-   make_empty_list( >Light.EnabledList );
 
init_lightmodel( >Light.Model );
init_material( >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(>Light.EnabledList,
>Light.Light[cap-GL_LIGHT0]);
  }
  else {
+ctx->Light._EnabledLights &= ~(1u << (cap - GL_LIGHT0));
 remove_from_list(>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( >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 

[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();
   const struct gl_texture_unit *texUnit = >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 = >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();
+ struct gl_light *light = >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();
+ struct gl_light *light = >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();
+ struct gl_light *light = >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();
+ struct gl_light *light = >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();
+ struct gl_light *light = >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();
+ struct gl_light *light = >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, >Light.EnabledList) {
+   GLbitfield mask = ctx->Light._EnabledLights;
+   while (mask) {
+  const int i = _mesa_bit_scan();
+  struct gl_light *light = >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, >Light.EnabledList) {
+   GLbitfield mask = ctx->Light._EnabledLights;
+   while (mask) {
+  const int i = _mesa_bit_scan();
+  struct gl_light *light = >Light.Light[i];
 
   if (ctx->_NeedEyeCoords) {
  /* _Position is in eye coordinate space */
diff --git a/src/mesa/main/rastpos.c b/src/mesa/main/rastpos.c
index b468219..819a9a9 100644
--- a/src/mesa/main/rastpos.c
+++ b/src/mesa/main/rastpos.c
@@ -37,7 +37,6 @@
 #include "state.h"
 #include "main/dispatch.h"
 #include "main/viewport.h"
-#include "util/simple_list.h"
 
 

[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, >Light.EnabledList) {
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int l = _mesa_bit_scan();
+ struct gl_light *light = >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, >Light.EnabledList) {
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int l = _mesa_bit_scan();
+ struct gl_light *light = >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 =
+  >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, >Light.EnabledList) {
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int l = _mesa_bit_scan();
+ const struct gl_light *light = >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 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();
+   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, >Light.EnabledList) {
-   const int i = l - ctx->Light.Light;
+   mask = ctx->Light._EnabledLights;
+   while (mask) {
+   const int i = _mesa_bit_scan();
+   struct gl_light *l = >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, >Light.EnabledList) {
-   const int i = l - ctx->Light.Light;
+   mask = ctx->Light._EnabledLights;
+   while (mask) {
+   const int i = _mesa_bit_scan();
+   struct gl_light *l = >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, >Light.EnabledList) {
-   const int i = l - ctx->Light.Light;
+   mask = ctx->Light._EnabledLights;
+   while (mask) {
+   const int i = _mesa_bit_scan();
+   struct gl_light *l = >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)

[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 )
  

[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 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();
+
   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 = >VertexAttrib[attrib];
   buffer_binding = >VertexBinding[attrib_array->VertexBinding];
   client_array = >_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();
  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();
+ *   ... 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 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 = >Light.Light[i];
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int i = _mesa_bit_scan();
+ struct gl_light *light = >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();
   struct gl_texture_unit *texUnit = >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 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();
+
+  /* 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
+  

[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();
+   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 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 = >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 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 = >Light.Light[p];
-   GLfloat *fcmd = (GLfloat *)R200_DB_STATE( lit[p] );
-
-   if (l->EyePosition[3] == 0.0) {
-  COPY_3FV( [LIT_POSITION_X], l->_VP_inf_norm );
-  COPY_3FV( [LIT_DIRECTION_X], l->_h_inf_norm );
-  fcmd[LIT_POSITION_W] = 0;
-  fcmd[LIT_DIRECTION_W] = 0;
-   } else {
-  COPY_4V( [LIT_POSITION_X], l->_Position );
-  fcmd[LIT_DIRECTION_X] = -l->_NormSpotDirection[0];
-  fcmd[LIT_DIRECTION_Y] = -l->_NormSpotDirection[1];
-  fcmd[LIT_DIRECTION_Z] = -l->_NormSpotDirection[2];
-  fcmd[LIT_DIRECTION_W] = 0;
-   }
+  GLbitfield mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int p = _mesa_bit_scan();
+ struct gl_light *l = >Light.Light[p];
+ GLfloat *fcmd = (GLfloat *)R200_DB_STATE( lit[p] );
+
+ if (l->EyePosition[3] == 0.0) {
+COPY_3FV( [LIT_POSITION_X], l->_VP_inf_norm );
+COPY_3FV( [LIT_DIRECTION_X], l->_h_inf_norm );
+fcmd[LIT_POSITION_W] = 0;
+fcmd[LIT_DIRECTION_W] = 0;
+ } else {
+COPY_4V( [LIT_POSITION_X], l->_Position );
+fcmd[LIT_DIRECTION_X] = -l->_NormSpotDirection[0];
+fcmd[LIT_DIRECTION_Y] = -l->_NormSpotDirection[1];
+fcmd[LIT_DIRECTION_Z] = -l->_NormSpotDirection[2];
+fcmd[LIT_DIRECTION_W] = 0;
+ }
 
-   R200_DB_STATECHANGE( rmesa, >hw.lit[p] );
-}
+ R200_DB_STATECHANGE( rmesa, >hw.lit[p] );
   }
}
 }
diff --git a/src/mesa/drivers/dri/radeon/radeon_state.c 
b/src/mesa/drivers/dri/radeon/radeon_state.c
index 8a1b81d..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 = >Light.Light[p];
-   GLfloat *fcmd = (GLfloat *)RADEON_DB_STATE( lit[p] );
-
-   if (l->EyePosition[3] == 0.0) {
-  COPY_3FV( [LIT_POSITION_X], l->_VP_inf_norm );
-  COPY_3FV( [LIT_DIRECTION_X], l->_h_inf_norm );
-  fcmd[LIT_POSITION_W] = 0;
-  fcmd[LIT_DIRECTION_W] = 0;
-   } else {
-  COPY_4V( [LIT_POSITION_X], l->_Position );
-  fcmd[LIT_DIRECTION_X] = -l->_NormSpotDirection[0];
-  fcmd[LIT_DIRECTION_Y] = -l->_NormSpotDirection[1];
-  fcmd[LIT_DIRECTION_Z] = -l->_NormSpotDirection[2];
-  fcmd[LIT_DIRECTION_W] = 0;
-   }
-
-   RADEON_DB_STATECHANGE( rmesa, >hw.lit[p] );
-}
+  GLbitfield mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int p = _mesa_bit_scan();
+ struct gl_light *l = >Light.Light[p];
+ GLfloat *fcmd = (GLfloat *)RADEON_DB_STATE( lit[p] );
+
+ if (l->EyePosition[3] == 0.0) {
+COPY_3FV( [LIT_POSITION_X], l->_VP_inf_norm );
+COPY_3FV( [LIT_DIRECTION_X], l->_h_inf_norm );
+fcmd[LIT_POSITION_W] = 0;
+fcmd[LIT_DIRECTION_W] = 0;
+ } else {
+COPY_4V( [LIT_POSITION_X], l->_Position );
+fcmd[LIT_DIRECTION_X] = -l->_NormSpotDirection[0];
+fcmd[LIT_DIRECTION_Y] = -l->_NormSpotDirection[1];
+fcmd[LIT_DIRECTION_Z] = -l->_NormSpotDirection[2];
+fcmd[LIT_DIRECTION_W] = 0;
+ }
+
+ RADEON_DB_STATECHANGE( rmesa, >hw.lit[p] );
   }
}
 }
-- 
2.5.5

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


[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 = _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();
+  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 = _context(ctx)->save;
-   GLint i;
+   GLbitfield64 enabled = save->enabled & (~BITFIELD64_BIT(VBO_ATTRIB_POS));
+
+   while (enabled) {
+  const int i = _mesa_bit_scan64();
 
-   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();
+

[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 = >Light.Material;
-   int i;
 
-   for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) 
-  if (bitmask & (1<Attrib[i], color );
+   while (bitmask) {
+  const int i = _mesa_bit_scan();
+
+  COPY_4FV( mat->Attrib[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 & (1<AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] = 
VB->AttribPtr[_TNL_ATTRIB_COLOR0];
+  GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
+  while (bitmask) {
+ const int i = _mesa_bit_scan();
+ 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 = >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();
+
  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 = >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 : >Sampler;
-
-if (!_mesa_is_texture_complete(texObj, sampler)) {
-   _mesa_test_texobj_completeness(ctx, texObj);
-}
-if (_mesa_is_texture_complete(texObj, sampler)) {
-   _mesa_reference_texobj(>_Current, texObj);
-   complete = true;
-   break;
-}
+  mask = texUnit->Enabled;
+  while (mask) {
+ const int texIndex = _mesa_bit_scan();
+ struct gl_texture_object *texObj = texUnit->CurrentTex[texIndex];
+ struct gl_sampler_object *sampler = texUnit->Sampler ?
+texUnit->Sampler : >Sampler;
+
+ if (!_mesa_is_texture_complete(texObj, sampler)) {
+_mesa_test_texobj_completeness(ctx, texObj);
+ }
+ if (_mesa_is_texture_complete(texObj, sampler)) {
+_mesa_reference_texobj(>_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] 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(, 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();
- *   ... 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(, , );
- *
- *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) {
- 

[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, >Light.EnabledList) {
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int l = u_bit_scan();
+ struct gl_light *light = >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, >Light.EnabledList) {
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int l = u_bit_scan();
+ struct gl_light *light = >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 =
+  >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, >Light.EnabledList) {
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int l = u_bit_scan();
+ const struct gl_light *light = >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 = >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();
+ struct gl_light *light = >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();
+ struct gl_light *light = >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();
+ struct gl_light *light = >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();
+ struct gl_light *light = >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();
+ struct gl_light *light = >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();
+ struct gl_light *light = >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, >Light.EnabledList) {
+   GLbitfield mask = ctx->Light._EnabledLights;
+   while (mask) {
+  const int i = u_bit_scan();
+  struct gl_light *light = >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, >Light.EnabledList) {
+   GLbitfield mask = ctx->Light._EnabledLights;
+   while (mask) {
+  const int i = u_bit_scan();
+  struct gl_light *light = >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 100644
--- 

[Mesa-dev] [PATCH 02/29] swrast: Convert swrast to use CoordsReplaceBits.

2016-06-13 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 06/29] i965: Convert i965 to use CoordsReplaceBits.

2016-06-13 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 d929f9b..fb52990 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -299,7 +299,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));
 
@@ -330,10 +329,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 07/29] mesa: Remove the now unused CoordsReplace array.

2016-06-13 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 4abe55b..2da8f3f 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 26/29] mesa: Use bitmask/ffs to iterate the enabled textures.

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

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

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

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

diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 3543369..94caf2a 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -38,6 +38,7 @@
 #include "teximage.h"
 #include "texstate.h"
 #include "mtypes.h"
+#include "util/bitscan.h"
 #include "util/bitset.h"
 
 
@@ -611,7 +612,7 @@ update_ff_texture_state(struct gl_context *ctx,
 
for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
   struct gl_texture_unit *texUnit = >Texture.Unit[unit];
-  GLuint texIndex;
+  GLbitfield mask;
   bool complete;
 
   if (texUnit->Enabled == 0x0)
@@ -651,20 +652,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 : >Sampler;
-
-if (!_mesa_is_texture_complete(texObj, sampler)) {
-   _mesa_test_texobj_completeness(ctx, texObj);
-}
-if (_mesa_is_texture_complete(texObj, sampler)) {
-   _mesa_reference_texobj(>_Current, texObj);
-   complete = true;
-   break;
-}
+  mask = texUnit->Enabled;
+  while (mask) {
+ const int texIndex = u_bit_scan();
+ struct gl_texture_object *texObj = texUnit->CurrentTex[texIndex];
+ struct gl_sampler_object *sampler = texUnit->Sampler ?
+texUnit->Sampler : >Sampler;
+
+ if (!_mesa_is_texture_complete(texObj, sampler)) {
+_mesa_test_texobj_completeness(ctx, texObj);
+ }
+ if (_mesa_is_texture_complete(texObj, sampler)) {
+_mesa_reference_texobj(>_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 04/29] r200: convert r200 to use CoordsReplaceBits.

2016-06-13 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 15/29] mesa: Switch to bitmask based enabled lights in gen_matypes.c

2016-06-13 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 18/29] mesa: Use bitmask/ffs to build ff fragment shader keys.

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

Replaces an iterate and test bit in a bitmask loop by a
loop only iterating over the bits set in the bitmask.
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.
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/ff_fragment_shader.cpp | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/ff_fragment_shader.cpp 
b/src/mesa/main/ff_fragment_shader.cpp
index 26bf162..9e18e30 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -49,6 +49,7 @@
 #include "program/prog_parameter.h"
 #include "program/prog_print.h"
 #include "program/prog_statevars.h"
+#include "util/bitscan.h"
 
 using namespace ir_builder;
 
@@ -398,22 +399,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 = u_bit_scan();
   const struct gl_texture_unit *texUnit = >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 14/29] radeon/r200: Use bitmask/ffs to iterate enabled lights

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

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

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

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

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

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

2016-06-13 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 85cd779..c30031e 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"
@@ -1413,16 +1412,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(>Light.EnabledList,
-   >Light.Light[cap-GL_LIGHT0]);
  }
  else {
 ctx->Light._EnabledLights &= ~(1u << (cap - GL_LIGHT0));
-remove_from_list(>Light.Light[cap-GL_LIGHT0]);
  }
  break;
   case GL_LIGHTING:
diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
index c9e2fc2..ad9cef1 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"
 #include "util/bitscan.h"
@@ -1122,8 +1121,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 );
@@ -1197,7 +1194,6 @@ _mesa_init_lighting( struct gl_context *ctx )
for (i = 0; i < MAX_LIGHTS; i++) {
   init_light( >Light.Light[i], i );
}
-   make_empty_list( >Light.EnabledList );
 
init_lightmodel( >Light.Model );
init_material( >Light.Material );
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index a0b1a86..af0aac9 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 20/29] mesa: Use bitmask/ffs to iterate enabled clip planes.

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

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

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

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/common/meta.c | 22 +++---
 src/mesa/main/matrix.c | 19 ++--
 src/mesa/main/rastpos.c| 21 +++---
 src/mesa/tnl/t_vb_cliptmp.h| 51 -
 src/mesa/tnl/t_vb_program.c| 65 +-
 src/mesa/tnl/t_vb_render.c |  1 +
 src/mesa/tnl/t_vb_vertex.c | 59 +++---
 7 files changed, 117 insertions(+), 121 deletions(-)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 6dcbc8b..1a4191f 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -85,6 +85,7 @@
 #include "drivers/common/meta.h"
 #include "main/enums.h"
 #include "main/glformats.h"
+#include "util/bitscan.h"
 #include "util/ralloc.h"
 
 /** Return offset in bytes of the field within a vertex struct */
@@ -682,12 +683,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 = u_bit_scan();
+ _mesa_set_enable(ctx, GL_CLIP_PLANE0 + i, GL_FALSE);
   }
}
 
@@ -1090,13 +1091,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 = u_bit_scan();
+ _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..293d50c 100644
--- a/src/mesa/main/matrix.c
+++ b/src/mesa/main/matrix.c
@@ -43,6 +43,7 @@
 #include "matrix.h"
 #include "mtypes.h"
 #include "math/m_matrix.h"
+#include "util/bitscan.h"
 
 
 /**
@@ -554,20 +555,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 = u_bit_scan();
+
+  _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 8f971f5..4fddad1 100644
--- a/src/mesa/main/rastpos.c
+++ b/src/mesa/main/rastpos.c
@@ -91,17 +91,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 = u_bit_scan();
+  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..c654666 100644
--- 

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

2016-06-13 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 = >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(>_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 22/29] i965: Use bitmask/ffs to iterate enabled clip planes.

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

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

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

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/dri/i965/brw_curbe.c | 21 +++--
 1 file changed, 11 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..02c4e38 100644
--- a/src/mesa/drivers/dri/i965/brw_curbe.c
+++ b/src/mesa/drivers/dri/i965/brw_curbe.c
@@ -56,6 +56,7 @@
 #include "program/prog_parameter.h"
 #include "program/prog_print.h"
 #include "program/prog_statevars.h"
+#include "util/bitscan.h"
 #include "intel_batchbuffer.h"
 #include "intel_buffer_objects.h"
 #include "brw_context.h"
@@ -84,7 +85,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 +227,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 +242,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<Transform.ClipPlanesEnabled;
+  while (mask) {
+ const int j = u_bit_scan();
+ buf[offset + i * 4 + 0].f = clip_planes[j][0];
+ buf[offset + i * 4 + 1].f = clip_planes[j][1];
+ buf[offset + i * 4 + 2].f = clip_planes[j][2];
+ buf[offset + i * 4 + 3].f = clip_planes[j][3];
+ i++;
   }
}
 
-- 
2.5.5

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


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

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

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

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

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/dri/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 ---
 3 files changed, 38 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..6189997 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_state.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_state.c
@@ -31,6 +31,7 @@
 
 #include "swrast/swrast.h"
 #include "tnl/tnl.h"
+#include "util/bitscan.h"
 
 static void
 nouveau_alpha_func(struct gl_context *ctx, GLenum func, GLfloat ref)
@@ -122,7 +123,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 +188,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 = u_bit_scan();
+   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..9f80e41 100644
--- a/src/mesa/drivers/dri/nouveau/nv10_state_tnl.c
+++ b/src/mesa/drivers/dri/nouveau/nv10_state_tnl.c
@@ -30,8 +30,7 @@
 #include "nouveau_util.h"
 #include "nv10_3d.xml.h"
 #include "nv10_driver.h"
-
-#include "util/simple_list.h"
+#include "util/bitscan.h"
 
 void
 nv10_emit_clip_plane(struct gl_context *ctx, int emit)
@@ -323,7 +322,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 +346,10 @@ nv10_emit_material_ambient(struct gl_context *ctx, int 
emit)
PUSH_DATAp(push, c_factor, 3);
}
 
-   foreach(l, >Light.EnabledList) {
-   const int i = l - ctx->Light.Light;
+   mask = ctx->Light._EnabledLights;
+   while (mask) {
+   const int i = u_bit_scan();
+   struct gl_light *l = >Light.Light[i];
float *c_light = (USE_COLOR_MATERIAL(AMBIENT) ?
  l->Ambient :
  l->_MatAmbient[0]);
@@ -363,13 +364,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, >Light.EnabledList) {
-   const int i = l - ctx->Light.Light;
+   mask = ctx->Light._EnabledLights;
+   while (mask) {
+   const int i = u_bit_scan();
+   struct gl_light *l = >Light.Light[i];
float *c_light = (USE_COLOR_MATERIAL(DIFFUSE) ?
  l->Diffuse :
  l->_MatDiffuse[0]);
@@ -383,10 +386,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, >Light.EnabledList) {
-   const int i = l - ctx->Light.Light;
+   mask = ctx->Light._EnabledLights;
+   while (mask) {
+   const int i = u_bit_scan();
+   struct gl_light *l = >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 

[Mesa-dev] [PATCH 05/29] i915: Convert i915 to use CoordsReplaceBits.

2016-06-13 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 03/29] gallium: Convert the state_tracker to use CoordsReplaceBits.

2016-06-13 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 = >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 17/29] mesa: Use bitmask/ffs to build ff vertex shader keys.

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

Replaces an iterate and test bit in a bitmask loop by a
loop only iterating over the bits set in the bitmask.
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.
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/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 ca72554..f4ae690 100644
--- a/src/mesa/main/ffvertex_prog.c
+++ b/src/mesa/main/ffvertex_prog.c
@@ -150,7 +150,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;
@@ -238,7 +237,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 = u_bit_scan();
   struct gl_texture_unit *texUnit = >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 19/29] mesa: Use bitmask/ffs to iterate color material attributes.

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

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

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

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/main/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 ad9cef1..87a06db 100644
--- a/src/mesa/main/light.c
+++ b/src/mesa/main/light.c
@@ -706,13 +706,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 = >Light.Material;
-   int i;
 
-   for (i = 0 ; i < MAT_ATTRIB_MAX ; i++) 
-  if (bitmask & (1<Attrib[i], color );
+   while (bitmask) {
+  const int i = u_bit_scan();
+
+  COPY_4FV( mat->Attrib[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 4342b6e..8d13712 100644
--- a/src/mesa/tnl/t_vb_light.c
+++ b/src/mesa/tnl/t_vb_light.c
@@ -233,10 +233,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 & (1<AttribPtr[_TNL_ATTRIB_MAT_FRONT_AMBIENT + i] = 
VB->AttribPtr[_TNL_ATTRIB_COLOR0];
+  GLbitfield bitmask = ctx->Light._ColorMaterialBitmask;
+  while (bitmask) {
+ const int i = u_bit_scan();
+ 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 23/29] i965: Use bitmask/ffs to iterate used vertex attributes.

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

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

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

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/drivers/dri/i965/brw_draw.c | 10 +-
 1 file changed, 5 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..d7a1ba3 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -38,6 +38,7 @@
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
 #include "drivers/common/meta.h"
+#include "util/bitscan.h"
 
 #include "brw_blorp.h"
 #include "brw_draw.h"
@@ -301,16 +302,15 @@ brw_merge_inputs(struct brw_context *brw,
}
 
if (brw->gen < 8 && !brw->is_haswell) {
-  struct gl_program *vp = >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 = u_bit_scan64();
+
  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 21/29] radeon/r200: Use bitmask/ffs to iterate enabled clip planes.

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

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

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

Reviewed-by: Brian Paul 
Signed-off-by: Mathias Fröhlich 
---
 src/mesa/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 0e38afc..3671231 100644
--- a/src/mesa/drivers/dri/r200/r200_state.c
+++ b/src/mesa/drivers/dri/r200/r200_state.c
@@ -1360,18 +1360,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 = u_bit_scan();
+  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 93bc0f9..c6b1f38 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state.c
@@ -1134,18 +1134,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 = u_bit_scan();
+  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 11/29] mesa: Use bitmask/ffs to iterate enabled lights for ff shader keys.

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

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

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

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

diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c
index ecdd018..ca72554 100644
--- a/src/mesa/main/ffvertex_prog.c
+++ b/src/mesa/main/ffvertex_prog.c
@@ -44,6 +44,7 @@
 #include "program/prog_parameter.h"
 #include "program/prog_print.h"
 #include "program/prog_statevars.h"
+#include "util/bitscan.h"
 
 
 /** Max of number of lights and texture coord units */
@@ -148,6 +149,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 +185,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 = >Light.Light[i];
+  mask = ctx->Light._EnabledLights;
+  while (mask) {
+ const int i = u_bit_scan();
+ struct gl_light *light = >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 28/29] vbo: Use a bitmask to track the active arrays in vbo_exec*.

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

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

diff --git a/src/mesa/vbo/vbo_exec.h b/src/mesa/vbo/vbo_exec.h
index 27bff4a..5e20cf6 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..e02bb90 100644
--- a/src/mesa/vbo/vbo_exec_api.c
+++ b/src/mesa/vbo/vbo_exec_api.c
@@ -42,6 +42,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "main/api_arrayelt.h"
 #include "main/api_validate.h"
 #include "main/dispatch.h"
+#include "util/bitscan.h"
 
 #include "vbo_context.h"
 #include "vbo_noop.h"
@@ -167,54 +168,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 = u_bit_scan64();
+
+  /* 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 <= 

[Mesa-dev] [PATCH 08/29] mesa: Rename CoordReplaceBits back to CoordReplace.

2016-06-13 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 fb52990..e9a1b6d 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -329,7 +329,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 )
  

[Mesa-dev] [PATCH 01/29] mesa: Add gl_point_attrib::CoordReplaceBits bitfield.

2016-06-13 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 471d41d..4abe55b 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 

  1   2   3   4   5   >