[Mesa-dev] [PATCH 2/2] i965: Handle nested uniform array indexing

2014-11-18 Thread Chris Forbes
When converting a uniform array reference to a pull constant load, the
`reladdr` expression itself may have its own `reladdr`, arbitrarily
deeply. This arises from expressions like:

   a[b[x]] where a, b are uniform arrays (or lowered const arrays),
   and x is not a constant.

Just iterate the lowering to pull constants until we stop seeing these
nested. For most shaders, there will be only one pass through this loop.

Fixes the piglit test:
tests/spec/glsl-1.20/linker/double-indirect-1.shader_test

Signed-off-by: Chris Forbes chr...@ijw.co.nz
Cc: 10.3 10.4 mesa-sta...@lists.freedesktop.org
---
 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp | 66 +++---
 1 file changed, 37 insertions(+), 29 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp 
b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index af7ca0c..22a6fb9 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -3354,6 +3354,7 @@ 
vec4_visitor::move_uniform_array_access_to_pull_constants()
 {
int pull_constant_loc[this-uniforms];
memset(pull_constant_loc, -1, sizeof(pull_constant_loc));
+   bool nested_reladdr;
 
/* Walk through and find array access of uniforms.  Put a copy of that
 * uniform in the pull constant buffer.
@@ -3361,44 +3362,51 @@ 
vec4_visitor::move_uniform_array_access_to_pull_constants()
 * Note that we don't move constant-indexed accesses to arrays.  No
 * testing has been done of the performance impact of this choice.
 */
-   foreach_block_and_inst_safe(block, vec4_instruction, inst, cfg) {
-  for (int i = 0 ; i  3; i++) {
-if (inst-src[i].file != UNIFORM || !inst-src[i].reladdr)
-   continue;
+   do {
+  nested_reladdr = false;
 
-int uniform = inst-src[i].reg;
+  foreach_block_and_inst_safe(block, vec4_instruction, inst, cfg) {
+ for (int i = 0 ; i  3; i++) {
+if (inst-src[i].file != UNIFORM || !inst-src[i].reladdr)
+   continue;
 
-/* If this array isn't already present in the pull constant buffer,
- * add it.
- */
-if (pull_constant_loc[uniform] == -1) {
-   const gl_constant_value **values =
-   stage_prog_data-param[uniform * 4];
+int uniform = inst-src[i].reg;
 
-   pull_constant_loc[uniform] = stage_prog_data-nr_pull_params / 4;
+if (inst-src[i].reladdr-reladdr)
+   nested_reladdr = true;  /* will need another pass */
 
-   assert(uniform  uniform_array_size);
-   for (int j = 0; j  uniform_size[uniform] * 4; j++) {
-  stage_prog_data-pull_param[stage_prog_data-nr_pull_params++]
-  = values[j];
-   }
-}
+/* If this array isn't already present in the pull constant buffer,
+ * add it.
+ */
+if (pull_constant_loc[uniform] == -1) {
+   const gl_constant_value **values =
+  stage_prog_data-param[uniform * 4];
 
-/* Set up the annotation tracking for new generated instructions. */
-base_ir = inst-ir;
-current_annotation = inst-annotation;
+   pull_constant_loc[uniform] = stage_prog_data-nr_pull_params / 
4;
 
-dst_reg temp = dst_reg(this, glsl_type::vec4_type);
+   assert(uniform  uniform_array_size);
+   for (int j = 0; j  uniform_size[uniform] * 4; j++) {
+  
stage_prog_data-pull_param[stage_prog_data-nr_pull_params++]
+ = values[j];
+   }
+}
 
-emit_pull_constant_load(block, inst, temp, inst-src[i],
-pull_constant_loc[uniform]);
+/* Set up the annotation tracking for new generated instructions. 
*/
+base_ir = inst-ir;
+current_annotation = inst-annotation;
 
-inst-src[i].file = temp.file;
-inst-src[i].reg = temp.reg;
-inst-src[i].reg_offset = temp.reg_offset;
-inst-src[i].reladdr = NULL;
+dst_reg temp = dst_reg(this, glsl_type::vec4_type);
+
+emit_pull_constant_load(block, inst, temp, inst-src[i],
+pull_constant_loc[uniform]);
+
+inst-src[i].file = temp.file;
+inst-src[i].reg = temp.reg;
+inst-src[i].reg_offset = temp.reg_offset;
+inst-src[i].reladdr = NULL;
+ }
   }
-   }
+   } while (nested_reladdr);
 
/* Now there are no accesses of the UNIFORM file with a reladdr, so
 * no need to track them as larger-than-vec4 objects.  This will be
-- 
2.1.3

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


[Mesa-dev] [PATCH 1/2] glsl: Generate unique names for each const array lowered to uniforms

2014-11-18 Thread Chris Forbes
Uniform names (even for hidden uniforms) are required to be unique; some
parts of the compiler assume they can be looked up by name.

Fixes the piglit test: tests/spec/glsl-1.20/linker/array-initializers-1

Signed-off-by: Chris Forbes chr...@ijw.co.nz
Cc: 10.4 mesa-sta...@lists.freedesktop.org
---
 src/glsl/lower_const_arrays_to_uniforms.cpp | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/glsl/lower_const_arrays_to_uniforms.cpp 
b/src/glsl/lower_const_arrays_to_uniforms.cpp
index b3c0ee2..700e903 100644
--- a/src/glsl/lower_const_arrays_to_uniforms.cpp
+++ b/src/glsl/lower_const_arrays_to_uniforms.cpp
@@ -49,6 +49,7 @@ public:
{
   instructions = insts;
   progress = false;
+  index = 0;
}
 
bool run()
@@ -62,6 +63,7 @@ public:
 private:
exec_list *instructions;
bool progress;
+   unsigned index;
 };
 
 void
@@ -76,8 +78,10 @@ lower_const_array_visitor::handle_rvalue(ir_rvalue **rvalue)
 
void *mem_ctx = ralloc_parent(con);
 
+   char *uniform_name = ralloc_asprintf(mem_ctx, constarray__%d, index++);
+
ir_variable *uni =
-  new(mem_ctx) ir_variable(con-type, constarray, ir_var_uniform);
+  new(mem_ctx) ir_variable(con-type, uniform_name, ir_var_uniform);
uni-constant_initializer = con;
uni-constant_value = con;
uni-data.has_initializer = true;
-- 
2.1.3

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


[Mesa-dev] [PATCH 09/20] mesa: Add a concept of an array format

2014-11-18 Thread Iago Toral Quiroga
From: Jason Ekstrand jason.ekstr...@intel.com

An array format is a 32-bit integer format identifier that can represent
any format that can be represented as an array of standard GL datatypes.
While the MESA_FORMAT enums provide several of these, they don't account
for all of them.

v2 by Iago Toral Quiroga ito...@igalia.com:
- Set pad to 0 and array_format_bit to 1 for all mesa array formats.
- Fix array_format_flip_channels, since it was not doing what was expected.
---
 src/mesa/main/format_info.py | 41 
 src/mesa/main/formats.c  | 56 +++-
 src/mesa/main/formats.h  | 55 +++
 3 files changed, 151 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/format_info.py b/src/mesa/main/format_info.py
index 7424fe0..315767d 100644
--- a/src/mesa/main/format_info.py
+++ b/src/mesa/main/format_info.py
@@ -98,6 +98,32 @@ def get_gl_data_type(fmat):
else:
   assert False
 
+def get_array_format_datatype(chan):
+   if chan.type == parser.FLOAT:
+  if chan.size == 16:
+ return 'MESA_ARRAY_FORMAT_TYPE_HALF'
+  elif chan.size == 32:
+ return 'MESA_ARRAY_FORMAT_TYPE_FLOAT'
+  else:
+ assert False
+   elif chan.type in (parser.SIGNED, parser.UNSIGNED):
+  datatype = 'MESA_ARRAY_FORMAT_TYPE_'
+  if chan.type == parser.UNSIGNED:
+ datatype += 'U'
+
+  if chan.size == 8:
+ datatype += 'BYTE'
+  elif chan.size == 16:
+ datatype += 'SHORT'
+  elif chan.size == 32:
+ datatype += 'INT'
+  else:
+ print chan.size
+ assert False
+  return datatype
+   else:
+  assert False
+
 def get_mesa_layout(fmat):
if fmat.layout == 'array':
   return 'MESA_FORMAT_LAYOUT_ARRAY'
@@ -192,6 +218,21 @@ for fmat in formats:
int(fmat.block_size() / 8))
 
print '  {{ {0} }},'.format(', '.join(map(str, fmat.swizzle)))
+   if fmat.is_array() and fmat.colorspace in ('rgb', 'srgb'):
+  chan = fmat.array_element()
+  print '   {0} ,'.format(', '.join([
+ get_array_format_datatype(chan),
+ str(int(chan.norm)),
+ str(len(fmat.channels)),
+ str(fmat.swizzle[0]),
+ str(fmat.swizzle[1]),
+ str(fmat.swizzle[2]),
+ str(fmat.swizzle[3]),
+ str(int(0)),
+ str(int(1))
+  ]))
+   else:
+  print '  {{ MESA_ARRAY_FORMAT_TYPE_UBYTE, 0, 0, 0, 0, 0, 0, 0, 0 }},'
print '   },'
 
 print '};'
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 7ec0507..f86925e 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -71,6 +71,7 @@ struct gl_format_info
GLubyte BytesPerBlock;
 
uint8_t Swizzle[4];
+   mesa_array_format ArrayFormat;
 };
 
 #include format_info.c
@@ -269,6 +270,60 @@ _mesa_get_format_swizzle(mesa_format format, uint8_t 
swizzle_out[4])
memcpy(swizzle_out, info-Swizzle, sizeof(info-Swizzle));
 }
 
+static mesa_array_format
+array_format_flip_channels(mesa_array_format format)
+{
+   if (format.num_channels == 1)
+  return format;
+
+   if (format.num_channels == 2) {
+  int tmp = format.swizzle_x;
+  format.swizzle_x = format.swizzle_y;
+  format.swizzle_y = tmp;
+  return format;
+   }
+
+   if (format.num_channels == 4) {
+  int tmp = format.swizzle_x;
+  format.swizzle_x = format.swizzle_w;
+  format.swizzle_w = tmp;
+  tmp = format.swizzle_y;
+  format.swizzle_y = format.swizzle_z;
+  format.swizzle_z = tmp;
+  return format;
+   }
+
+   assert(!Invalid array format);
+}
+
+uint32_t
+_mesa_format_to_array_format(mesa_format format)
+{
+   const struct gl_format_info *info = _mesa_get_format_info(format);
+   if (_mesa_little_endian())
+  return info-ArrayFormat.as_uint;
+   else
+  return array_format_flip_channels(info-ArrayFormat).as_uint;
+}
+
+mesa_format
+_mesa_format_from_array_format(uint32_t array_format)
+{
+   mesa_array_format af;
+   unsigned f;
+
+   af.as_uint = array_format;
+   af.pad = 0;
+   if (!_mesa_little_endian())
+  af = array_format_flip_channels(af);
+
+   assert(af.array_format_bit);
+   for (f = 1; f  MESA_FORMAT_COUNT; ++f)
+  if (_mesa_get_format_info(f)-ArrayFormat.as_uint == af.as_uint)
+ return f;
+
+   return MESA_FORMAT_NONE;
+}
 
 /** Is the given format a compressed format? */
 GLboolean
@@ -278,7 +333,6 @@ _mesa_is_format_compressed(mesa_format format)
return info-BlockWidth  1 || info-BlockHeight  1;
 }
 
-
 /**
  * Determine if the given format represents a packed depth/stencil buffer.
  */
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index 213ab56..7642875 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -81,6 +81,55 @@ enum {
MESA_FORMAT_SWIZZLE_NONE = 6,
 };
 
+enum  mesa_array_format_datatype {
+   MESA_ARRAY_FORMAT_TYPE_UBYTE = 0x0,
+   

[Mesa-dev] [PATCH 10/20] mesa: Add a _mesa_is_format_color_format helper

2014-11-18 Thread Iago Toral Quiroga
From: Jason Ekstrand jason.ekstr...@intel.com

---
 src/mesa/main/formats.c | 19 +++
 src/mesa/main/formats.h |  3 +++
 2 files changed, 22 insertions(+)

diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index f86925e..f14250b 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -399,6 +399,25 @@ _mesa_is_format_integer(mesa_format format)
return (info-DataType == GL_INT || info-DataType == GL_UNSIGNED_INT);
 }
 
+
+/**
+ * Return true if the given format is a color format.
+ */
+GLenum
+_mesa_is_format_color_format(mesa_format format)
+{
+   const struct gl_format_info *info = _mesa_get_format_info(format);
+   switch (info-BaseFormat) {
+   case GL_DEPTH_COMPONENT:
+   case GL_STENCIL_INDEX:
+   case GL_DEPTH_STENCIL:
+  return false;
+   default:
+  return true;
+   }
+}
+
+
 /**
  * Return color encoding for given format.
  * \return GL_LINEAR or GL_SRGB
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index 7642875..7ddf4ee 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -545,6 +545,9 @@ _mesa_is_format_integer(mesa_format format);
 extern bool
 _mesa_is_format_etc2(mesa_format format);
 
+GLenum
+_mesa_is_format_color_format(mesa_format format);
+
 extern GLenum
 _mesa_get_format_color_encoding(mesa_format format);
 
-- 
1.9.1

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


[Mesa-dev] [PATCH 20/20] mesa/pack: refactor _mesa_pack_rgba_span_float()

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

Use autogenerated format pack functions and take advantage of some
macros to reduce source code, facilitating its maintenance.

Unfortunately, dstType == GL_UNSIGNED_SHORT cannot simplified like
the others, so keep it as it is.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
---
 src/mesa/main/pack.c | 1318 ++
 src/mesa/main/pack_tmp.h |1 +
 2 files changed, 153 insertions(+), 1166 deletions(-)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 067a0f5..06993d4 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -531,22 +531,22 @@ _mesa_pack_rgba_span_from_uints(struct gl_context *ctx, 
GLuint n, GLuint rgba[][
 {
switch(dstType) {
case GL_UNSIGNED_INT:
-  pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
+  pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
   break;
case GL_INT:
-  pack_int_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
+  pack_int_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
   break;
case GL_UNSIGNED_SHORT:
-  pack_ushort_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
+  pack_ushort_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
   break;
case GL_SHORT:
-  pack_short_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
+  pack_short_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
   break;
case GL_UNSIGNED_BYTE:
-  pack_ubyte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
+  pack_ubyte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
   break;
case GL_BYTE:
-  pack_byte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
+  pack_byte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
   break;
case GL_UNSIGNED_BYTE_3_3_2:
   if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER))
@@ -722,23 +722,23 @@ _mesa_pack_rgba_span_from_ints(struct gl_context *ctx, 
GLuint n, GLint rgba[][4]
 {
switch(dstType) {
case GL_UNSIGNED_INT:
-  pack_uint_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n);
+  pack_uint_from_int_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
   break;
case GL_INT:
   /* No conversion necessary. */
-  pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, (GLuint (*)[4]) rgba, 
n);
+  pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, (GLuint (*)[4]) rgba, 
NULL, n);
   break;
case GL_UNSIGNED_SHORT:
-  pack_ushort_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n);
+  pack_ushort_from_int_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
   break;
case GL_SHORT:
-  pack_short_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n);
+  pack_short_from_int_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
   break;
case GL_UNSIGNED_BYTE:
-  pack_ubyte_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n);
+  pack_ubyte_from_int_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
   break;
case GL_BYTE:
-  pack_byte_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n);
+  pack_byte_from_int_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
   break;
case GL_UNSIGNED_BYTE_3_3_2:
   if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER))
@@ -850,6 +850,80 @@ _mesa_pack_rgba_span_from_ints(struct gl_context *ctx, 
GLuint n, GLint rgba[][4]
}
 }
 
+/* Customization of float packing.
+ */
+#define SRC_TYPE GLfloat
+
+#define DST_TYPE GLuint
+#define FLOAT_SRC_CONVERT(x) FLOAT_TO_UINT(x)
+#define SRC_CONVERT(x) (GLuint) x
+#define FN_NAME pack_uint_from_float_rgba
+#include pack_tmp.h
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FLOAT_SRC_CONVERT
+#undef FN_NAME
+
+#define DST_TYPE GLint
+#define FLOAT_SRC_CONVERT(x) FLOAT_TO_INT(x)
+#define SRC_CONVERT(x) (GLint) x
+#define FN_NAME pack_int_from_float_rgba
+#include pack_tmp.h
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FLOAT_SRC_CONVERT
+#undef FN_NAME
+
+#define DST_TYPE GLshort
+#define FLOAT_SRC_CONVERT(x) FLOAT_TO_SHORT_TEX(x)
+#define SRC_CONVERT(x) (GLshort) x
+#define FN_NAME pack_short_from_float_rgba
+#include pack_tmp.h
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FLOAT_SRC_CONVERT
+#undef FN_NAME
+
+#define DST_TYPE GLubyte
+#define FLOAT_SRC_CONVERT(x) FLOAT_TO_UBYTE(x)
+#define SRC_CONVERT(x) (GLubyte) x
+#define FN_NAME pack_ubyte_from_float_rgba
+#include pack_tmp.h
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FLOAT_SRC_CONVERT
+#undef FN_NAME
+
+#define DST_TYPE GLbyte
+#define FLOAT_SRC_CONVERT(x) FLOAT_TO_BYTE_TEX(x)
+#define SRC_CONVERT(x) (GLbyte) x
+#define FN_NAME pack_byte_from_float_rgba
+#include pack_tmp.h
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FLOAT_SRC_CONVERT
+#undef FN_NAME
+
+#define DST_TYPE GLfloat
+#define FLOAT_SRC_CONVERT(x) x
+#define SRC_CONVERT(x) x
+#define FN_NAME pack_float_from_float_rgba
+#include pack_tmp.h
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FLOAT_SRC_CONVERT
+#undef FN_NAME
+

[Mesa-dev] [PATCH 01/20] mesa/format_utils: Fix a bug in one of the format helper functions

2014-11-18 Thread Iago Toral Quiroga
From: Jason Ekstrand jason.ekstr...@intel.com

---
 src/mesa/main/format_utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index 93a0cea..b6d0fbc 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -152,7 +152,7 @@ unorm_to_float(unsigned x, unsigned src_bits)
 static inline float
 snorm_to_float(int x, unsigned src_bits)
 {
-   if (x == -MAX_INT(src_bits))
+   if (x  -MAX_INT(src_bits))
   return -1.0f;
else
   return x * (1.0f / (float)MAX_INT(src_bits));
-- 
1.9.1

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


[Mesa-dev] [PATCH 00/20] Auto-generate pack/unpack functions

2014-11-18 Thread Iago Toral Quiroga
This is the fist of two series of patches to address:
https://bugs.freedesktop.org/show_bug.cgi?id=84566

The idea is that we have a lot of format conversion code scattered through
different files in the repository, a lot of that is redundant / duplicated,
so this intends to address that issue.

The goal of this first series is to address auto-generation of our pack/unpack
functions (format_pack.c and format_unpack.c). Currently, we  have a ton of
hand-coded pack/unpack functions for lots of formats, but we can auto-generate
most of that code instead, so this series handles this.

This is based on initial work by Jason Ekstrand.

Tested on i965, classic swrast and gallium (radeon, nouveau, llvmpipe) without
regressions.

For software drivers we worked with a trimmed set of piglit tests (related to
format conversion), ~5700 tests selected with the following filter:

-t format -t color -t tex -t image -t swizzle -t clamp -t rgb -t lum -t pix
-t fbo -t frame

Summary of the patches:
 * Patches 1-7 are general fixes to the current code that were found while
   working on this.
 * Patches 8-16 implement auto-generation of pack/unpack functions.
 * Patches 17-20 make use of the auto-generated pack/unpack functions in
   various places to simplify the current code.

Notice that some of the fixes in patches 1-7 will become obsolete as soon as
we auto-generate the pack/unpack functions, but we thought it would make sense
to keep them in the patch set anyway since we started from that base and they
should be correct fixes to the currently existing code.

Iago Toral Quiroga (1):
  swrast: Remove unused variable.

Jason Ekstrand (9):
  mesa/format_utils: Fix a bug in one of the format helper functions
  mesa: Fix packing/unpacking of MESA_FORMAT_R5G6B5_UNORM
  mesa/colormac: Remove an unused macro
  mesa: Fix A1R5G5B5 packing/unpacking
  mesa/format_utils: Prefix and expose the conversion helper functions
  mesa: Add a concept of an array format
  mesa: Add a _mesa_is_format_color_format helper
  mesa: Autogenerate most of format_pack.c
  mesa: Autogenerate format_unpack.c

Samuel Iglesias Gonsalvez (10):
  mesa: Fix get_texbuffer_format().
  mesa: Fix _mesa_swizzle_and_convert integer conversions to clamp
properly
  mesa: Add _mesa_pack_uint_rgba_row() format conversion function
  mesa: Add non-normalized formats support for ubyte packing functions
  mesa/format_pack: Add _mesa_pack_int_rgba_row()
  mesa/formats: add new mesa formats and their pack/unpack functions.
  mesa: use format conversion functions in swrast
  mesa/pack: use autogenerated format_pack functions
  mesa/main/pack_tmp.h: Add float conversion support
  mesa/pack: refactor _mesa_pack_rgba_span_float()

 src/mesa/Makefile.am   |   18 +
 src/mesa/Makefile.sources  |4 +-
 src/mesa/main/colormac.h   |3 -
 src/mesa/main/format_convert.py|   71 +
 src/mesa/main/format_info.py   |   41 +
 src/mesa/main/format_pack.c| 2994 
 src/mesa/main/format_pack.c.mako   | 1147 ++
 src/mesa/main/format_pack.h|6 +
 src/mesa/main/format_unpack.c  | 4400 
 src/mesa/main/format_unpack.c.mako |  914 
 src/mesa/main/format_utils.c   |  248 +-
 src/mesa/main/format_utils.h   |  105 +
 src/mesa/main/formats.c|  193 +-
 src/mesa/main/formats.csv  |   13 +
 src/mesa/main/formats.h|   73 +
 src/mesa/main/pack.c   | 2111 +++--
 src/mesa/main/pack_tmp.h   |   76 +-
 src/mesa/main/run_mako.py  |7 +
 src/mesa/main/teximage.c   |4 +-
 src/mesa/main/texstore.c   |2 +-
 src/mesa/swrast/s_drawpix.c|3 -
 src/mesa/swrast/s_texfetch.c   |   13 +
 src/mesa/swrast/s_texfetch_tmp.h   | 1359 +--
 23 files changed, 3222 insertions(+), 10583 deletions(-)
 create mode 100644 src/mesa/main/format_convert.py
 delete mode 100644 src/mesa/main/format_pack.c
 create mode 100644 src/mesa/main/format_pack.c.mako
 delete mode 100644 src/mesa/main/format_unpack.c
 create mode 100644 src/mesa/main/format_unpack.c.mako
 create mode 100644 src/mesa/main/run_mako.py

-- 
1.9.1

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


[Mesa-dev] [PATCH 19/20] mesa/main/pack_tmp.h: Add float conversion support

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

We will use this in a later patch to refactor _mesa_pack_rgba_span_float.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
---
 src/mesa/main/pack_tmp.h | 75 +++-
 1 file changed, 74 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/pack_tmp.h b/src/mesa/main/pack_tmp.h
index 0d4eb38..c6882db 100644
--- a/src/mesa/main/pack_tmp.h
+++ b/src/mesa/main/pack_tmp.h
@@ -31,6 +31,79 @@ FN_NAME(struct gl_context *ctx,
int i;
 
switch (dstFormat) {
+#ifdef FLOAT_SRC_CONVERT
+   case GL_RED:
+  for (i=0;in;i++)
+ dst[i] = FLOAT_SRC_CONVERT(rgba[i][RCOMP]);
+  break;
+   case GL_GREEN:
+  for (i=0;in;i++)
+ dst[i] = FLOAT_SRC_CONVERT(rgba[i][GCOMP]);
+  break;
+   case GL_BLUE:
+  for (i=0;in;i++)
+ dst[i] = FLOAT_SRC_CONVERT(rgba[i][BCOMP]);
+  break;
+   case GL_ALPHA:
+  for (i=0;in;i++)
+ dst[i] = FLOAT_SRC_CONVERT(rgba[i][ACOMP]);
+  break;
+   case GL_LUMINANCE:
+  for (i=0;in;i++)
+ dst[i] = FLOAT_SRC_CONVERT(luminance[i]);
+  break;
+   case GL_LUMINANCE_ALPHA:
+  for (i=0;in;i++) {
+ dst[i*2+0] = FLOAT_SRC_CONVERT(luminance[i]);
+ dst[i*2+1] = FLOAT_SRC_CONVERT(rgba[i][ACOMP]);
+  }
+  break;
+   case GL_RG:
+  for (i=0;in;i++) {
+ dst[i*2+0] = FLOAT_SRC_CONVERT(rgba[i][RCOMP]);
+ dst[i*2+1] = FLOAT_SRC_CONVERT(rgba[i][GCOMP]);
+  }
+  break;
+   case GL_RGB:
+  for (i=0;in;i++) {
+ dst[i*3+0] = FLOAT_SRC_CONVERT(rgba[i][RCOMP]);
+ dst[i*3+1] = FLOAT_SRC_CONVERT(rgba[i][GCOMP]);
+ dst[i*3+2] = FLOAT_SRC_CONVERT(rgba[i][BCOMP]);
+  }
+  break;
+   case GL_RGBA:
+  for (i=0;in;i++) {
+ dst[i*4+0] = FLOAT_SRC_CONVERT(rgba[i][RCOMP]);
+ dst[i*4+1] = FLOAT_SRC_CONVERT(rgba[i][GCOMP]);
+ dst[i*4+2] = FLOAT_SRC_CONVERT(rgba[i][BCOMP]);
+ dst[i*4+3] = FLOAT_SRC_CONVERT(rgba[i][ACOMP]);
+  }
+  break;
+   case GL_BGR:
+  for (i=0;in;i++) {
+ dst[i*3+0] = FLOAT_SRC_CONVERT(rgba[i][BCOMP]);
+ dst[i*3+1] = FLOAT_SRC_CONVERT(rgba[i][GCOMP]);
+ dst[i*3+2] = FLOAT_SRC_CONVERT(rgba[i][RCOMP]);
+  }
+  break;
+   case GL_BGRA:
+  for (i=0;in;i++) {
+ dst[i*4+0] = FLOAT_SRC_CONVERT(rgba[i][BCOMP]);
+ dst[i*4+1] = FLOAT_SRC_CONVERT(rgba[i][GCOMP]);
+ dst[i*4+2] = FLOAT_SRC_CONVERT(rgba[i][RCOMP]);
+ dst[i*4+3] = FLOAT_SRC_CONVERT(rgba[i][ACOMP]);
+  }
+  break;
+   case GL_ABGR_EXT:
+  for (i=0;in;i++) {
+ dst[i*4+0] = FLOAT_SRC_CONVERT(rgba[i][ACOMP]);
+ dst[i*4+1] = FLOAT_SRC_CONVERT(rgba[i][BCOMP]);
+ dst[i*4+2] = FLOAT_SRC_CONVERT(rgba[i][GCOMP]);
+ dst[i*4+3] = FLOAT_SRC_CONVERT(rgba[i][RCOMP]);
+  }
+  break;
+#endif
+#ifdef SRC_CONVERT
case GL_RED_INTEGER_EXT:
   for (i=0;in;i++) {
 dst[i] = SRC_CONVERT(rgba[i][RCOMP]);
@@ -112,7 +185,7 @@ FN_NAME(struct gl_context *ctx,
 dst[i*2+1] = SRC_CONVERT(rgba[i][ACOMP]);
   }
   break;
-
+#endif
default:
   _mesa_problem(ctx,
  Unsupported format (%s),
-- 
1.9.1

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


[Mesa-dev] [PATCH 06/20] mesa: Fix _mesa_swizzle_and_convert integer conversions to clamp properly

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

Fix various conversion paths that involved integer data types of different
sizes (uint16_t to uint8_t, int16_t to uint8_t, etc) that were not
being clamped properly.

Also, one of the paths was incorrectly assigning the value 12, instead of 1,
to the constant one.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
---
 src/mesa/main/format_utils.c | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index b6d0fbc..8040173 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -24,6 +24,7 @@
 
 #include format_utils.h
 #include glformats.h
+#include macros.h
 
 static const uint8_t map_identity[7] = { 0, 1, 2, 3, 4, 5, 6 };
 static const uint8_t map_3210[7] = { 3, 2, 1, 0, 4, 5, 6 };
@@ -593,28 +594,28 @@ convert_ubyte(void *void_dst, int num_dst_channels,
   if (normalized) {
  SWIZZLE_CONVERT(uint8_t, uint16_t, unorm_to_unorm(src, 16, 8));
   } else {
- SWIZZLE_CONVERT(uint8_t, uint16_t, src);
+ SWIZZLE_CONVERT(uint8_t, uint16_t, MIN2(src, 0xff));
   }
   break;
case GL_SHORT:
   if (normalized) {
  SWIZZLE_CONVERT(uint8_t, int16_t, snorm_to_unorm(src, 16, 8));
   } else {
- SWIZZLE_CONVERT(uint8_t, int16_t, (src  0) ? 0 : src);
+ SWIZZLE_CONVERT(uint8_t, int16_t, CLAMP(src, 0, 0xff));
   }
   break;
case GL_UNSIGNED_INT:
   if (normalized) {
  SWIZZLE_CONVERT(uint8_t, uint32_t, unorm_to_unorm(src, 32, 8));
   } else {
- SWIZZLE_CONVERT(uint8_t, uint32_t, src);
+ SWIZZLE_CONVERT(uint8_t, uint32_t, MIN2(src, 0xff));
   }
   break;
case GL_INT:
   if (normalized) {
  SWIZZLE_CONVERT(uint8_t, int32_t, snorm_to_unorm(src, 32, 8));
   } else {
- SWIZZLE_CONVERT(uint8_t, int32_t, (src  0) ? 0 : src);
+ SWIZZLE_CONVERT(uint8_t, int32_t, CLAMP(src, 0, 0xff));
   }
   break;
default:
@@ -649,7 +650,7 @@ convert_byte(void *void_dst, int num_dst_channels,
   if (normalized) {
  SWIZZLE_CONVERT(int8_t, uint8_t, unorm_to_snorm(src, 8, 8));
   } else {
- SWIZZLE_CONVERT(int8_t, uint8_t, src);
+ SWIZZLE_CONVERT(int8_t, uint8_t, MIN2(src, 0x7f));
   }
   break;
case GL_BYTE:
@@ -659,28 +660,28 @@ convert_byte(void *void_dst, int num_dst_channels,
   if (normalized) {
  SWIZZLE_CONVERT(int8_t, uint16_t, unorm_to_snorm(src, 16, 8));
   } else {
- SWIZZLE_CONVERT(int8_t, uint16_t, src);
+ SWIZZLE_CONVERT(int8_t, uint16_t, MIN2(src, 0x7f));
   }
   break;
case GL_SHORT:
   if (normalized) {
  SWIZZLE_CONVERT(int8_t, int16_t, snorm_to_snorm(src, 16, 8));
   } else {
- SWIZZLE_CONVERT(int8_t, int16_t, src);
+ SWIZZLE_CONVERT(int8_t, int16_t, CLAMP(src, -0x80, 0x7f));
   }
   break;
case GL_UNSIGNED_INT:
   if (normalized) {
  SWIZZLE_CONVERT(int8_t, uint32_t, unorm_to_snorm(src, 32, 8));
   } else {
- SWIZZLE_CONVERT(int8_t, uint32_t, src);
+ SWIZZLE_CONVERT(int8_t, uint32_t, MIN2(src, 0x7f));
   }
   break;
case GL_INT:
   if (normalized) {
  SWIZZLE_CONVERT(int8_t, int32_t, snorm_to_snorm(src, 32, 8));
   } else {
- SWIZZLE_CONVERT(int8_t, int32_t, src);
+ SWIZZLE_CONVERT(int8_t, int32_t, CLAMP(src, -0x80, 0x7f));
   }
   break;
default:
@@ -739,14 +740,14 @@ convert_ushort(void *void_dst, int num_dst_channels,
   if (normalized) {
  SWIZZLE_CONVERT(uint16_t, uint32_t, unorm_to_unorm(src, 32, 16));
   } else {
- SWIZZLE_CONVERT(uint16_t, uint32_t, src);
+ SWIZZLE_CONVERT(uint16_t, uint32_t, MIN2(src, 0x));
   }
   break;
case GL_INT:
   if (normalized) {
  SWIZZLE_CONVERT(uint16_t, int32_t, snorm_to_unorm(src, 32, 16));
   } else {
- SWIZZLE_CONVERT(uint16_t, int32_t, (src  0) ? 0 : src);
+ SWIZZLE_CONVERT(uint16_t, int32_t,  CLAMP(src, 0, 0x));
   }
   break;
default:
@@ -795,7 +796,7 @@ convert_short(void *void_dst, int num_dst_channels,
   if (normalized) {
  SWIZZLE_CONVERT(int16_t, uint16_t, unorm_to_snorm(src, 16, 16));
   } else {
- SWIZZLE_CONVERT(int16_t, uint16_t, src);
+ SWIZZLE_CONVERT(int16_t, uint16_t, (src  0) ? 0 : src);
   }
   break;
case GL_SHORT:
@@ -805,14 +806,14 @@ convert_short(void *void_dst, int num_dst_channels,
   if (normalized) {
  SWIZZLE_CONVERT(int16_t, uint32_t, unorm_to_snorm(src, 32, 16));
   } else {
- SWIZZLE_CONVERT(int16_t, uint32_t, src);
+ SWIZZLE_CONVERT(int16_t, uint32_t, MIN2(src, 0x7fff));
   }
   break;
case GL_INT:
   if (normalized) {
  SWIZZLE_CONVERT(int16_t, int32_t, snorm_to_snorm(src, 32, 

[Mesa-dev] [PATCH 05/20] mesa: Fix get_texbuffer_format().

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

We were returning incorrect mesa formats for GL_LUMINANCE_ALPHA16I_EXT
and GL_LUMINANCE_ALPHA32I_EXT.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
---
 src/mesa/main/teximage.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 4f4bb11..e238863 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -4461,9 +4461,9 @@ get_texbuffer_format(const struct gl_context *ctx, GLenum 
internalFormat)
   case GL_LUMINANCE_ALPHA8I_EXT:
  return MESA_FORMAT_LA_SINT8;
   case GL_LUMINANCE_ALPHA16I_EXT:
- return MESA_FORMAT_LA_SINT8;
-  case GL_LUMINANCE_ALPHA32I_EXT:
  return MESA_FORMAT_LA_SINT16;
+  case GL_LUMINANCE_ALPHA32I_EXT:
+ return MESA_FORMAT_LA_SINT32;
   case GL_LUMINANCE_ALPHA8UI_EXT:
  return MESA_FORMAT_LA_UINT8;
   case GL_LUMINANCE_ALPHA16UI_EXT:
-- 
1.9.1

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


[Mesa-dev] [PATCH 18/20] mesa/pack: use autogenerated format_pack functions

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

Take advantage of new mesa formats and new format_pack functions to
reduce source code in _mesa_pack_rgba_span_from_ints() and
_mesa_pack_rgba_span_from_uints().

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
---
 src/mesa/main/pack.c | 663 +++
 1 file changed, 138 insertions(+), 525 deletions(-)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 649a74c..067a0f5 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -55,6 +55,8 @@
 #include glformats.h
 #include ../../gallium/auxiliary/util/u_format_rgb9e5.h
 #include ../../gallium/auxiliary/util/u_format_r11g11b10f.h
+#include format_utils.h
+#include format_pack.h
 
 
 /**
@@ -527,8 +529,6 @@ _mesa_pack_rgba_span_from_uints(struct gl_context *ctx, 
GLuint n, GLuint rgba[][
 GLenum dstFormat, GLenum dstType,
 GLvoid *dstAddr)
 {
-   GLuint i;
-
switch(dstType) {
case GL_UNSIGNED_INT:
   pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
@@ -549,300 +549,108 @@ _mesa_pack_rgba_span_from_uints(struct gl_context *ctx, 
GLuint n, GLuint rgba[][
   pack_byte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
   break;
case GL_UNSIGNED_BYTE_3_3_2:
-  if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER)) {
- GLubyte *dst = (GLubyte *) dstAddr;
- for (i=0;in;i++) {
-dst[i] = (MIN2(rgba[i][RCOMP], 7)  5)
-   | (MIN2(rgba[i][GCOMP], 7)  2)
-   | (MIN2(rgba[i][BCOMP], 3) );
- }
-  } else {
+  if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER))
+ _mesa_pack_uint_rgba_row(MESA_FORMAT_B2G3R3_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
+  else
  _pack_rgba_span_from_uints_problem(ctx, dstFormat, dstType);
-  }
   break;
case GL_UNSIGNED_BYTE_2_3_3_REV:
-  if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER)) {
- GLubyte *dst = (GLubyte *) dstAddr;
- for (i=0;in;i++) {
-dst[i] = (MIN2(rgba[i][RCOMP], 7) )
-   | (MIN2(rgba[i][GCOMP], 7)  3)
-   | (MIN2(rgba[i][BCOMP], 3)  6);
- }
-  } else {
+  if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER))
+ _mesa_pack_uint_rgba_row(MESA_FORMAT_R3G3B2_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
+  else
  _pack_rgba_span_from_uints_problem(ctx, dstFormat, dstType);
-  }
   break;
case GL_UNSIGNED_SHORT_5_6_5:
-  if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER)) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;in;i++) {
-dst[i] = (MIN2(rgba[i][RCOMP], 31)  11)
-   | (MIN2(rgba[i][GCOMP], 63)   5)
-   | (MIN2(rgba[i][BCOMP], 31)  );
- }
-  } else {
+  if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER))
+ _mesa_pack_uint_rgba_row(MESA_FORMAT_B5G6R5_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
+  else
  _pack_rgba_span_from_uints_problem(ctx, dstFormat, dstType);
-  }
   break;
case GL_UNSIGNED_SHORT_5_6_5_REV:
-  if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER)) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;in;i++) {
-dst[i] = (MIN2(rgba[i][RCOMP], 31)  )
-   | (MIN2(rgba[i][GCOMP], 63)   5)
-   | (MIN2(rgba[i][BCOMP], 31)  11);
- }
-  } else {
+  if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER))
+ _mesa_pack_uint_rgba_row(MESA_FORMAT_R5G6B5_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
+  else
  _pack_rgba_span_from_uints_problem(ctx, dstFormat, dstType);
-  }
   break;
case GL_UNSIGNED_SHORT_4_4_4_4:
-  if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT)) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;in;i++) {
-dst[i] = (MIN2(rgba[i][RCOMP], 15)  12)
-   | (MIN2(rgba[i][GCOMP], 15)   8)
-   | (MIN2(rgba[i][BCOMP], 15)   4)
-   | (MIN2(rgba[i][ACOMP], 15)  );
- }
-  }
-  else if ((dstFormat == GL_BGRA) || (dstFormat == GL_BGRA_INTEGER)) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;in;i++) {
-dst[i] = (MIN2(rgba[i][BCOMP], 15)  12)
-   | (MIN2(rgba[i][GCOMP], 15)   8)
-   | (MIN2(rgba[i][RCOMP], 15)   4)
-   | (MIN2(rgba[i][ACOMP], 15)  );
- }
-  }
-  else if (dstFormat == GL_ABGR_EXT) {
- GLushort *dst = (GLushort *) dstAddr;
- for (i=0;in;i++) {
-dst[i] = (MIN2(rgba[i][ACOMP], 15)  12)
-   | (MIN2(rgba[i][BCOMP], 15)   8)
-   | (MIN2(rgba[i][GCOMP], 15)   4)
-   | 

[Mesa-dev] [PATCH 02/20] mesa: Fix packing/unpacking of MESA_FORMAT_R5G6B5_UNORM

2014-11-18 Thread Iago Toral Quiroga
From: Jason Ekstrand jason.ekstr...@intel.com

Aparently, the packing/unpacking functions for these formats have differed
from the format description in formats.h.  Instead of fixing this, people
simply left a comment saying it was broken.  Let's actually fix it for
real.

Signed-off-by: Jason Ekstrand jason.ekstr...@intel.com
---
 src/mesa/main/format_pack.c  | 10 ++
 src/mesa/main/format_unpack.c| 10 ++
 src/mesa/main/formats.c  | 12 ++--
 src/mesa/main/texstore.c |  2 +-
 src/mesa/swrast/s_texfetch_tmp.h |  8 
 5 files changed, 15 insertions(+), 27 deletions(-)

diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c
index 31c9f77..20d2b1a 100644
--- a/src/mesa/main/format_pack.c
+++ b/src/mesa/main/format_pack.c
@@ -458,17 +458,11 @@ pack_row_float_B5G6R5_UNORM(GLuint n, const GLfloat 
src[][4], void *dst)
 }
 
 
-/*
- * MESA_FORMAT_R5G6B5_UNORM
- * Warning: these functions do not match the current Mesa definition
- * of MESA_FORMAT_R5G6B5_UNORM.
- */
-
 static void
 pack_ubyte_R5G6B5_UNORM(const GLubyte src[4], void *dst)
 {
GLushort *d = ((GLushort *) dst);
-   *d = PACK_COLOR_565_REV(src[RCOMP], src[GCOMP], src[BCOMP]);
+   *d = PACK_COLOR_565(src[BCOMP], src[GCOMP], src[RCOMP]);
 }
 
 static void
@@ -479,7 +473,7 @@ pack_float_R5G6B5_UNORM(const GLfloat src[4], void *dst)
UNCLAMPED_FLOAT_TO_UBYTE(r, src[RCOMP]);
UNCLAMPED_FLOAT_TO_UBYTE(g, src[GCOMP]);
UNCLAMPED_FLOAT_TO_UBYTE(b, src[BCOMP]);
-   *d = PACK_COLOR_565_REV(r, g, b);
+   *d = PACK_COLOR_565(b, g, r);
 }
 
 static void
diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
index d5628a9..f5ab966 100644
--- a/src/mesa/main/format_unpack.c
+++ b/src/mesa/main/format_unpack.c
@@ -207,9 +207,6 @@ unpack_B5G6R5_UNORM(const void *src, GLfloat dst[][4], 
GLuint n)
 static void
 unpack_R5G6B5_UNORM(const void *src, GLfloat dst[][4], GLuint n)
 {
-   /* Warning: this function does not match the current Mesa definition
-* of MESA_FORMAT_R5G6B5_UNORM.
-*/
const GLushort *s = ((const GLushort *) src);
GLuint i;
for (i = 0; i  n; i++) {
@@ -2764,16 +2761,13 @@ unpack_ubyte_B5G6R5_UNORM(const void *src, GLubyte 
dst[][4], GLuint n)
 static void
 unpack_ubyte_R5G6B5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
 {
-   /* Warning: this function does not match the current Mesa definition
-* of MESA_FORMAT_R5G6B5_UNORM.
-*/
const GLushort *s = ((const GLushort *) src);
GLuint i;
for (i = 0; i  n; i++) {
   GLuint t = (s[i]  8) | (s[i]  8); /* byte swap */
-  dst[i][RCOMP] = EXPAND_5_8((t  11)  0x1f);
+  dst[i][RCOMP] = EXPAND_5_8( t 0x1f);
   dst[i][GCOMP] = EXPAND_6_8((t  5 )  0x3f);
-  dst[i][BCOMP] = EXPAND_5_8( t 0x1f);
+  dst[i][BCOMP] = EXPAND_5_8((t  11)  0x1f);
   dst[i][ACOMP] = 0xff;
}
 }
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 58c32e2..1315d36 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -1462,14 +1462,14 @@ _mesa_format_matches_format_and_type(mesa_format 
mesa_format,
   return format == GL_RGB  type == GL_UNSIGNED_BYTE  littleEndian;
 
case MESA_FORMAT_B5G6R5_UNORM:
-  return format == GL_RGB  type == GL_UNSIGNED_SHORT_5_6_5  !swapBytes;
+  return ((format == GL_RGB  type == GL_UNSIGNED_SHORT_5_6_5) ||
+  (format == GL_BGR  type == GL_UNSIGNED_SHORT_5_6_5_REV)) 
+  !swapBytes;
 
case MESA_FORMAT_R5G6B5_UNORM:
-  /* Some of the 16-bit MESA_FORMATs that would seem to correspond to
-   * GL_UNSIGNED_SHORT_* are byte-swapped instead of channel-reversed,
-   * according to formats.h, so they can't be matched.
-   */
-  return GL_FALSE;
+  return ((format == GL_BGR  type == GL_UNSIGNED_SHORT_5_6_5) ||
+  (format == GL_RGB  type == GL_UNSIGNED_SHORT_5_6_5_REV)) 
+  !swapBytes;
 
case MESA_FORMAT_B4G4R4A4_UNORM:
   return format == GL_BGRA  type == GL_UNSIGNED_SHORT_4_4_4_4_REV 
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index f913e42..31ca03c 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -923,7 +923,7 @@ _mesa_texstore_rgb565(TEXSTORE_PARAMS)
  }
  else {
 for (col = 0; col  srcWidth; col++) {
-   dstUS[col] = PACK_COLOR_565_REV( srcUB[0], srcUB[1], srcUB[2] );
+   dstUS[col] = PACK_COLOR_565( srcUB[2], srcUB[1], srcUB[0] );
srcUB += 3;
 }
  }
diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h
index 7ff30f6..23db48d 100644
--- a/src/mesa/swrast/s_texfetch_tmp.h
+++ b/src/mesa/swrast/s_texfetch_tmp.h
@@ -417,10 +417,10 @@ FETCH(R5G6B5_UNORM)(const struct swrast_texture_image 
*texImage,
 GLint i, GLint j, GLint k, GLfloat *texel)
 {
const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   const 

[Mesa-dev] [PATCH 04/20] mesa: Fix A1R5G5B5 packing/unpacking

2014-11-18 Thread Iago Toral Quiroga
From: Jason Ekstrand jason.ekstr...@intel.com

As with B5G6R5, these have been left broken with comments saying they are.

Signed-off-by: Jason Ekstrand jason.ekstr...@intel.com
---
 src/mesa/main/format_pack.c  |  8 +---
 src/mesa/main/format_unpack.c| 11 ---
 src/mesa/main/formats.c  |  2 ++
 src/mesa/swrast/s_texfetch_tmp.h |  8 
 4 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c
index 20d2b1a..3d191c1 100644
--- a/src/mesa/main/format_pack.c
+++ b/src/mesa/main/format_pack.c
@@ -584,17 +584,11 @@ pack_float_B5G5R5A1_UNORM(const GLfloat src[4], void *dst)
pack_ubyte_B5G5R5A1_UNORM(v, dst);
 }
 
-
-/* MESA_FORMAT_A1R5G5B5_UNORM
- * Warning: these functions do not match the current Mesa definition
- * of MESA_FORMAT_A1R5G5B5_UNORM.
- */
-
 static void
 pack_ubyte_A1R5G5B5_UNORM(const GLubyte src[4], void *dst)
 {
GLushort *d = ((GLushort *) dst), tmp;
-   tmp = PACK_COLOR_1555(src[ACOMP], src[RCOMP], src[GCOMP], src[BCOMP]);
+   tmp = PACK_COLOR_5551(src[BCOMP], src[GCOMP], src[RCOMP], src[ACOMP]);
*d = (tmp  8) | (tmp  8);
 }
 
diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
index f5ab966..8a95fad 100644
--- a/src/mesa/main/format_unpack.c
+++ b/src/mesa/main/format_unpack.c
@@ -2827,17 +2827,14 @@ unpack_ubyte_B5G5R5A1_UNORM(const void *src, GLubyte 
dst[][4], GLuint n)
 static void
 unpack_ubyte_A1R5G5B5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
 {
-   /* Warning: this function does not match the current Mesa definition
-* of MESA_FORMAT_A1R5G5B5_UNORM.
-*/
const GLushort *s = ((const GLushort *) src);
GLuint i;
for (i = 0; i  n; i++) {
   GLushort tmp = (s[i]  8) | (s[i]  8); /* byteswap */
-  dst[i][RCOMP] = EXPAND_5_8((tmp  10)  0x1f);
-  dst[i][GCOMP] = EXPAND_5_8((tmp   5)  0x1f);
-  dst[i][BCOMP] = EXPAND_5_8((tmp   0)  0x1f);
-  dst[i][ACOMP] = EXPAND_1_8((tmp  15)  0x01);
+  dst[i][RCOMP] = EXPAND_5_8((tmp   1)  0x1f);
+  dst[i][GCOMP] = EXPAND_5_8((tmp   6)  0x1f);
+  dst[i][BCOMP] = EXPAND_5_8((tmp  11)  0x1f);
+  dst[i][ACOMP] = EXPAND_1_8((tmp  )  0x01);
}
 }
 
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 1315d36..7ec0507 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -1487,6 +1487,8 @@ _mesa_format_matches_format_and_type(mesa_format 
mesa_format,
  !swapBytes;
 
case MESA_FORMAT_A1R5G5B5_UNORM:
+  return format == GL_BGRA  type == GL_UNSIGNED_SHORT_5_5_5_1 
+ !swapBytes;
   return GL_FALSE;
 
case MESA_FORMAT_L4A4_UNORM:
diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h
index 23db48d..e3a3cfe 100644
--- a/src/mesa/swrast/s_texfetch_tmp.h
+++ b/src/mesa/swrast/s_texfetch_tmp.h
@@ -482,10 +482,10 @@ FETCH(A1R5G5B5_UNORM)(const struct swrast_texture_image 
*texImage,
 {
const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
const GLushort s = (*src  8) | (*src  8); /* byteswap */
-   texel[RCOMP] = UBYTE_TO_FLOAT( ((s   7)  0xf8) | ((s  12)  0x7) );
-   texel[GCOMP] = UBYTE_TO_FLOAT( ((s   2)  0xf8) | ((s   7)  0x7) );
-   texel[BCOMP] = UBYTE_TO_FLOAT( ((s   3)  0xf8) | ((s   2)  0x7) );
-   texel[ACOMP] = UBYTE_TO_FLOAT( ((s  15)  0x01) * 255 );
+   texel[RCOMP] = ((s   1)  0x1f) * (1.0F / 31.0F);
+   texel[GCOMP] = ((s   6)  0x1f) * (1.0F / 31.0F);
+   texel[BCOMP] = ((s  11)  0x1f) * (1.0F / 31.0F);
+   texel[ACOMP] = ((s  )  0x01) * 1.0F;
 }
 
 
-- 
1.9.1

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


[Mesa-dev] [PATCH 16/20] mesa/formats: add new mesa formats and their pack/unpack functions.

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

This  will be used to refactor code in pack.c and support conversion
to/from these types in a master convert function that will be added
later.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
---
 src/mesa/main/format_pack.c.mako   |  36 -
 src/mesa/main/format_unpack.c.mako |  35 -
 src/mesa/main/formats.c| 104 +
 src/mesa/main/formats.csv  |  13 +
 src/mesa/main/formats.h|  15 ++
 src/mesa/swrast/s_texfetch.c   |  13 +
 6 files changed, 212 insertions(+), 4 deletions(-)

diff --git a/src/mesa/main/format_pack.c.mako b/src/mesa/main/format_pack.c.mako
index b846702..c5ad623 100644
--- a/src/mesa/main/format_pack.c.mako
+++ b/src/mesa/main/format_pack.c.mako
@@ -68,7 +68,7 @@ for f in formats:
 /* ubyte packing functions */
 
 %for f in rgb_formats:
-   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
+   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT', 
'MESA_FORMAT_A2R10G10B10_UNORM'):
   % continue %
%elif f.is_compressed():
   % continue %
@@ -137,6 +137,22 @@ pack_ubyte_${f.short_name()}(const GLubyte src[4], void 
*dst)
 %endfor
 
 static inline void
+pack_ubyte_a2r10g10b10_unorm(const GLubyte src[4], void *dst)
+{
+uint8_t  a = _mesa_unorm_to_unorm(src[3], 8, 2);
+uint16_t r = _mesa_unorm_to_unorm(src[0], 8, 10);
+uint16_t g = _mesa_unorm_to_unorm(src[1], 8, 10);
+uint16_t b = _mesa_unorm_to_unorm(src[2], 8, 10);
+
+uint32_t d = 0;
+d |= PACK(a, 0, 2);
+d |= PACK(r, 2, 10);
+d |= PACK(g, 12, 10);
+d |= PACK(b, 22, 10);
+(*(uint32_t *) dst) = d;
+}
+
+static inline void
 pack_ubyte_r9g9b9e5_float(const GLubyte src[4], void *dst)
 {
GLuint *d = (GLuint *) dst;
@@ -311,7 +327,7 @@ pack_int_r11g11b10_float(const GLint src[4], void *dst)
 /* float packing functions */
 
 %for f in rgb_formats:
-   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
+   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT', 
'MESA_FORMAT_A2R10G10B10_UNORM'):
   % continue %
%elif f.is_compressed():
   % continue %
@@ -373,6 +389,22 @@ pack_float_${f.short_name()}(const GLfloat src[4], void 
*dst)
 %endfor
 
 static inline void
+pack_float_a2r10g10b10_unorm(const GLfloat src[4], void *dst)
+{
+uint8_t  a = _mesa_float_to_unorm(src[3], 2);
+uint16_t r = _mesa_float_to_unorm(src[0], 10);
+uint16_t g = _mesa_float_to_unorm(src[1], 10);
+uint16_t b = _mesa_float_to_unorm(src[2], 10);
+
+uint32_t d = 0;
+d |= PACK(a, 0, 2);
+d |= PACK(r, 2, 10);
+d |= PACK(g, 12, 10);
+d |= PACK(b, 22, 10);
+(*(uint32_t *) dst) = d;
+}
+
+static inline void
 pack_float_r9g9b9e5_float(const GLfloat src[4], void *dst)
 {
GLuint *d = (GLuint *) dst;
diff --git a/src/mesa/main/format_unpack.c.mako 
b/src/mesa/main/format_unpack.c.mako
index 8fd3cdd..510aed2 100644
--- a/src/mesa/main/format_unpack.c.mako
+++ b/src/mesa/main/format_unpack.c.mako
@@ -67,7 +67,7 @@ for f in formats:
 /* float unpacking functions */
 
 %for f in rgb_formats:
-   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
+   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT', 
'MESA_FORMAT_A2R10G10B10_UNORM'):
   % continue %
%elif f.is_compressed():
   % continue %
@@ -128,6 +128,21 @@ unpack_float_${f.short_name()}(const void *void_src, 
GLfloat dst[4])
 }
 %endfor
 
+static inline void
+unpack_float_a2r10g10b10_unorm(const void *void_src, GLfloat dst[4])
+{
+uint32_t *src = (uint32_t *) void_src;
+uint8_t a = UNPACK(*src, 0, 2);
+uint16_t r = UNPACK(*src, 2, 10);
+uint16_t g = UNPACK(*src, 12, 10);
+uint16_t b = UNPACK(*src, 22, 10);
+
+dst[0] = _mesa_unorm_to_float(r, 10);
+dst[1] = _mesa_unorm_to_float(g, 10);
+dst[2] = _mesa_unorm_to_float(b, 10);
+dst[3] = _mesa_unorm_to_float(a, 2);
+}
+
 static void
 unpack_float_r9g9b9e5_float(const void *src, GLfloat dst[4])
 {
@@ -195,7 +210,9 @@ unpack_float_ycbcr_rev(const void *src, GLfloat dst[][4], 
GLuint n)
 /* ubyte packing functions */
 
 %for f in rgb_formats:
-   %if not f.is_normalized():
+   %if f.name in ('MESA_FORMAT_A2R10G10B10_UNORM'):
+  % continue %
+   %elif not f.is_normalized():
   % continue %
%endif
 
@@ -254,6 +271,20 @@ unpack_ubyte_${f.short_name()}(const void *void_src, 
GLubyte dst[4])
 }
 %endfor
 
+static inline void
+unpack_ubyte_a2r10g10b10_unorm(const void *void_src, GLubyte dst[4])
+{
+uint32_t *src = (uint32_t *) void_src;
+uint8_t a = UNPACK(*src, 0, 2);
+uint16_t r = UNPACK(*src, 2, 10);
+uint16_t g = UNPACK(*src, 12, 10);
+uint16_t b = UNPACK(*src, 22, 10);
+
+dst[0] = _mesa_unorm_to_unorm(r, 10, 8);
+dst[1] = _mesa_unorm_to_unorm(g, 10, 8);
+dst[2] = 

[Mesa-dev] [PATCH 03/20] mesa/colormac: Remove an unused macro

2014-11-18 Thread Iago Toral Quiroga
From: Jason Ekstrand jason.ekstr...@intel.com

The PACK_565_REV macro is no longer used.  It was also extremely confusing
because it's actually a byteswapped 565 not reversed 565.

Signed-off-by: Jason Ekstrand jason.ekstr...@intel.com
---
 src/mesa/main/colormac.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/mesa/main/colormac.h b/src/mesa/main/colormac.h
index c8adca6..bc69f46 100644
--- a/src/mesa/main/colormac.h
+++ b/src/mesa/main/colormac.h
@@ -69,9 +69,6 @@ _mesa_unclamped_float_rgba_to_ubyte(GLubyte dst[4], const 
GLfloat src[4])
 #define PACK_COLOR_565( X, Y, Z )  \
X)  0xf8)  8) | (((Y)  0xfc)  3) | (((Z)  0xf8)  3))
 
-#define PACK_COLOR_565_REV( X, Y, Z ) \
-   (((X)  0xf8) | ((Y)  0xe0)  5 | (((Y)  0x1c)  11) | (((Z)  0xf8)  
5))
-
 #define PACK_COLOR_5551( R, G, B, A )  \
R)  0xf8)  8) | (((G)  0xf8)  3) | (((B)  0xf8)  2) |  \
 ((A)  7))
-- 
1.9.1

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


[Mesa-dev] [PATCH 07/20] swrast: Remove unused variable.

2014-11-18 Thread Iago Toral Quiroga
---
 src/mesa/swrast/s_drawpix.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
index f7926e4..227faa2 100644
--- a/src/mesa/swrast/s_drawpix.c
+++ b/src/mesa/swrast/s_drawpix.c
@@ -414,7 +414,6 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
 {
const GLint imgX = x, imgY = y;
const GLboolean zoom = ctx-Pixel.ZoomX!=1.0 || ctx-Pixel.ZoomY!=1.0;
-   GLfloat *convImage = NULL;
GLbitfield transferOps = ctx-_ImageTransferState;
SWspan span;
 
@@ -493,8 +492,6 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
   span.array-ChanType = CHAN_TYPE;
}
 
-   free(convImage);
-
swrast_render_finish(ctx);
 }
 
-- 
1.9.1

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


[Mesa-dev] [PATCH 13/20] mesa: Add _mesa_pack_uint_rgba_row() format conversion function

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

We will use this later on to handle uint conversion scenarios in a master
convert function.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
---
 src/mesa/main/format_pack.c.mako | 88 
 src/mesa/main/format_pack.h  |  3 ++
 2 files changed, 91 insertions(+)

diff --git a/src/mesa/main/format_pack.c.mako b/src/mesa/main/format_pack.c.mako
index 13a20c1..b9f4656 100644
--- a/src/mesa/main/format_pack.c.mako
+++ b/src/mesa/main/format_pack.c.mako
@@ -150,6 +150,62 @@ pack_ubyte_r11g11b10_float(const GLubyte src[4], void *dst)
*d = float3_to_r11g11b10f(rgb);
 }
 
+/* uint packing functions */
+
+%for f in rgb_formats:
+   %if not f.is_int():
+  % continue %
+   %elif f.is_normalized():
+  % continue %
+   %elif f.is_compressed():
+  % continue %
+   %endif
+
+static inline void
+pack_uint_${f.short_name()}(const GLuint src[4], void *dst)
+{
+   %for (i, c) in enumerate(f.channels):
+  % i = f.swizzle.inverse()[i] %
+  %if c.type == 'x':
+ % continue %
+  %endif
+
+  ${channel_datatype(c)} ${c.name} =
+  %if not f.is_normalized():
+ %if c.type == parser.FLOAT and c.size == 32:
+UINT_TO_FLOAT(src[${i}]);
+ %elif c.type == parser.FLOAT and c.size == 16:
+_mesa_float_to_half(UINT_TO_FLOAT(src[${i}]));
+ %else:
+(${channel_datatype(c)}) src[${i}];
+ %endif
+  %else:
+ % assert False %
+  %endif
+   %endfor
+
+   %if f.layout == parser.ARRAY:
+  ${format_datatype(f)} *d = (${format_datatype(f)} *)dst;
+  %for (i, c) in enumerate(f.channels):
+ %if c.type == 'x':
+% continue %
+ %endif
+ d[${i}] = ${c.name};
+  %endfor
+   %elif f.layout == parser.PACKED:
+  ${format_datatype(f)} d = 0;
+  %for (i, c) in enumerate(f.channels):
+ %if c.type == 'x':
+% continue %
+ %endif
+ d |= PACK(${c.name}, ${c.shift}, ${c.size});
+  %endfor
+  (*(${format_datatype(f)} *)dst) = d;
+   %else:
+  % assert False %
+   %endif
+}
+%endfor
 
 /* float packing functions */
 
@@ -298,6 +354,38 @@ _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n,
 }
 
 /**
+ * Pack a row of GLuint rgba[4] values to the destination.
+ */
+void
+_mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
+  const GLuint src[][4], void *dst)
+{
+   GLuint i;
+   GLubyte *d = dst;
+
+   switch (format) {
+%for f in rgb_formats:
+   %if not f.is_int():
+  % continue %
+   %elif f.is_normalized():
+  % continue %
+   %elif f.is_compressed():
+  % continue %
+   %endif
+
+   case ${f.name}:
+  for (i = 0; i  n; ++i) {
+ pack_uint_${f.short_name()}(src[i], d);
+ d += ${f.block_size() / 8};
+  }
+  break;
+%endfor
+   default:
+  assert(!Invalid format);
+   }
+}
+
+/**
  * Pack a row of GLfloat rgba[4] values to the destination.
  */
 void
diff --git a/src/mesa/main/format_pack.h b/src/mesa/main/format_pack.h
index 2577def..1582ad1 100644
--- a/src/mesa/main/format_pack.h
+++ b/src/mesa/main/format_pack.h
@@ -77,6 +77,9 @@ extern void
 _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n,
   const GLubyte src[][4], void *dst);
 
+extern void
+_mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
+ const GLuint src[][4], void *dst);
 
 extern void
 _mesa_pack_ubyte_rgba_rect(mesa_format format, GLuint width, GLuint height,
-- 
1.9.1

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


[Mesa-dev] [PATCH 15/20] mesa/format_pack: Add _mesa_pack_int_rgba_row()

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

This will be used to unify code in pack.c.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
---
 src/mesa/main/format_pack.c.mako | 121 +++
 src/mesa/main/format_pack.h  |   3 +
 2 files changed, 124 insertions(+)

diff --git a/src/mesa/main/format_pack.c.mako b/src/mesa/main/format_pack.c.mako
index 97adf6e..b846702 100644
--- a/src/mesa/main/format_pack.c.mako
+++ b/src/mesa/main/format_pack.c.mako
@@ -215,6 +215,99 @@ pack_uint_${f.short_name()}(const GLuint src[4], void *dst)
 }
 %endfor
 
+/* int packing functions */
+
+%for f in rgb_formats:
+   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
+  % continue %
+   %elif f.is_compressed():
+  % continue %
+   %endif
+
+static inline void
+pack_int_${f.short_name()}(const GLint src[4], void *dst)
+{
+   %for (i, c) in enumerate(f.channels):
+  % i = f.swizzle.inverse()[i] %
+  %if c.type == 'x':
+ % continue %
+  %endif
+
+  ${channel_datatype(c)} ${c.name} =
+  %if not f.is_normalized():
+ %if c.type == parser.FLOAT and c.size == 32:
+INT_TO_FLOAT(src[${i}]);
+ %elif c.type == parser.FLOAT and c.size == 16:
+_mesa_float_to_half(INT_TO_FLOAT(src[${i}]));
+ %else:
+(${channel_datatype(c)}) src[${i}];
+ %endif
+  %elif c.type == parser.UNSIGNED:
+ %if f.colorspace == 'srgb' and c.name in 'rgb':
+util_format_linear_to_srgb_8unorm(src[${i}]);
+ %else:
+CLAMP(src[${i}], 0, MAX_UINT(${c.size}));
+ %endif
+  %elif c.type == parser.SIGNED:
+ CLAMP(src[${i}], 0,  MAX_UINT(${c.size}));
+  %elif c.type == parser.FLOAT:
+ %if c.size == 32:
+_mesa_snorm_to_float(src[${i}], 8);
+ %elif c.size == 16:
+_mesa_snorm_to_half(src[${i}], 8);
+ %else:
+% assert False %
+ %endif
+  %else:
+ % assert False %
+  %endif
+   %endfor
+
+   %if f.layout == parser.ARRAY:
+  ${format_datatype(f)} *d = (${format_datatype(f)} *)dst;
+  %for (i, c) in enumerate(f.channels):
+ %if c.type == 'x':
+% continue %
+ %endif
+ d[${i}] = ${c.name};
+  %endfor
+   %elif f.layout == parser.PACKED:
+  ${format_datatype(f)} d = 0;
+  %for (i, c) in enumerate(f.channels):
+ %if c.type == 'x':
+% continue %
+ %endif
+ d |= PACK(${c.name}, ${c.shift}, ${c.size});
+  %endfor
+  (*(${format_datatype(f)} *)dst) = d;
+   %else:
+  % assert False %
+   %endif
+}
+%endfor
+
+static inline void
+pack_int_r9g9b9e5_float(const GLint src[4], void *dst)
+{
+   GLuint *d = (GLuint *) dst;
+   GLfloat rgb[3];
+   rgb[0] = _mesa_snorm_to_float(src[RCOMP], 8);
+   rgb[1] = _mesa_snorm_to_float(src[GCOMP], 8);
+   rgb[2] = _mesa_snorm_to_float(src[BCOMP], 8);
+   *d = float3_to_rgb9e5(rgb);
+}
+
+static inline void
+pack_int_r11g11b10_float(const GLint src[4], void *dst)
+{
+   GLuint *d = (GLuint *) dst;
+   GLfloat rgb[3];
+   rgb[0] = _mesa_snorm_to_float(src[RCOMP], 8);
+   rgb[1] = _mesa_snorm_to_float(src[GCOMP], 8);
+   rgb[2] = _mesa_snorm_to_float(src[BCOMP], 8);
+   *d = float3_to_r11g11b10f(rgb);
+}
+
 /* float packing functions */
 
 %for f in rgb_formats:
@@ -394,6 +487,34 @@ _mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
 }
 
 /**
+ * Pack a row of GLint rgba[4] values to the destination.
+ */
+void
+_mesa_pack_int_rgba_row(mesa_format format, GLuint n,
+  const GLint src[][4], void *dst)
+{
+   GLuint i;
+   GLubyte *d = dst;
+
+   switch (format) {
+%for f in rgb_formats:
+   %if f.is_compressed():
+  % continue %
+   %endif
+
+   case ${f.name}:
+  for (i = 0; i  n; ++i) {
+ pack_int_${f.short_name()}(src[i], d);
+ d += ${f.block_size() / 8};
+  }
+  break;
+%endfor
+   default:
+  assert(!Invalid format);
+   }
+}
+
+/**
  * Pack a row of GLfloat rgba[4] values to the destination.
  */
 void
diff --git a/src/mesa/main/format_pack.h b/src/mesa/main/format_pack.h
index 1582ad1..6087fc3 100644
--- a/src/mesa/main/format_pack.h
+++ b/src/mesa/main/format_pack.h
@@ -68,6 +68,9 @@ extern gl_pack_ubyte_stencil_func
 _mesa_get_pack_ubyte_stencil_func(mesa_format format);
 
 
+extern void
+_mesa_pack_int_rgba_row(mesa_format format, GLuint n,
+  const GLint src[][4], void *dst);
 
 extern void
 _mesa_pack_float_rgba_row(mesa_format format, GLuint n,
-- 
1.9.1

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


[Mesa-dev] [PATCH 08/20] mesa/format_utils: Prefix and expose the conversion helper functions

2014-11-18 Thread Iago Toral Quiroga
From: Jason Ekstrand jason.ekstr...@intel.com

Signed-off-by: Jason Ekstrand jason.ekstr...@intel.com

v2 by Samuel Iglesias sigles...@igalia.com:
- Fix compilation errors

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
---
 src/mesa/main/format_utils.c | 215 +++
 src/mesa/main/format_utils.h | 105 +
 2 files changed, 159 insertions(+), 161 deletions(-)

diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index 8040173..fcbbba4 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -133,113 +133,6 @@ _mesa_format_to_array(mesa_format format, GLenum *type, 
int *num_components,
}
 }
 
-/* A bunch of format conversion macros and helper functions used below */
-
-/* Only guaranteed to work for BITS = 32 */
-#define MAX_UINT(BITS) ((BITS) == 32 ? UINT32_MAX : ((1u  (BITS)) - 1))
-#define MAX_INT(BITS) ((int)MAX_UINT((BITS) - 1))
-
-/* Extends an integer of size SRC_BITS to one of size DST_BITS linearly */
-#define EXTEND_NORMALIZED_INT(X, SRC_BITS, DST_BITS) \
-  (((X) * (int)(MAX_UINT(DST_BITS) / MAX_UINT(SRC_BITS))) + \
-   ((DST_BITS % SRC_BITS) ? ((X)  (SRC_BITS - DST_BITS % SRC_BITS)) : 0))
-
-static inline float
-unorm_to_float(unsigned x, unsigned src_bits)
-{
-   return x * (1.0f / (float)MAX_UINT(src_bits));
-}
-
-static inline float
-snorm_to_float(int x, unsigned src_bits)
-{
-   if (x  -MAX_INT(src_bits))
-  return -1.0f;
-   else
-  return x * (1.0f / (float)MAX_INT(src_bits));
-}
-
-static inline uint16_t
-unorm_to_half(unsigned x, unsigned src_bits)
-{
-   return _mesa_float_to_half(unorm_to_float(x, src_bits));
-}
-
-static inline uint16_t
-snorm_to_half(int x, unsigned src_bits)
-{
-   return _mesa_float_to_half(snorm_to_float(x, src_bits));
-}
-
-static inline unsigned
-float_to_unorm(float x, unsigned dst_bits)
-{
-   if (x  0.0f)
-  return 0;
-   else if (x  1.0f)
-  return MAX_UINT(dst_bits);
-   else
-  return F_TO_I(x * MAX_UINT(dst_bits));
-}
-
-static inline unsigned
-half_to_unorm(uint16_t x, unsigned dst_bits)
-{
-   return float_to_unorm(_mesa_half_to_float(x), dst_bits);
-}
-
-static inline unsigned
-unorm_to_unorm(unsigned x, unsigned src_bits, unsigned dst_bits)
-{
-   if (src_bits  dst_bits)
-  return EXTEND_NORMALIZED_INT(x, src_bits, dst_bits);
-   else
-  return x  (src_bits - dst_bits);
-}
-
-static inline unsigned
-snorm_to_unorm(int x, unsigned src_bits, unsigned dst_bits)
-{
-   if (x  0)
-  return 0;
-   else
-  return unorm_to_unorm(x, src_bits - 1, dst_bits);
-}
-
-static inline int
-float_to_snorm(float x, unsigned dst_bits)
-{
-   if (x  -1.0f)
-  return -MAX_INT(dst_bits);
-   else if (x  1.0f)
-  return MAX_INT(dst_bits);
-   else
-  return F_TO_I(x * MAX_INT(dst_bits));
-}
-
-static inline int
-half_to_snorm(uint16_t x, unsigned dst_bits)
-{
-   return float_to_snorm(_mesa_half_to_float(x), dst_bits);
-}
-
-static inline int
-unorm_to_snorm(unsigned x, unsigned src_bits, unsigned dst_bits)
-{
-   return unorm_to_unorm(x, src_bits, dst_bits - 1);
-}
-
-static inline int
-snorm_to_snorm(int x, unsigned src_bits, unsigned dst_bits)
-{
-   if (x  -MAX_INT(src_bits))
-  return -MAX_INT(dst_bits);
-   else if (src_bits  dst_bits)
-  return EXTEND_NORMALIZED_INT(x, src_bits - 1, dst_bits - 1);
-   else
-  return x  (src_bits - dst_bits);
-}
-
 static inline unsigned
 float_to_uint(float x)
 {
@@ -450,42 +343,42 @@ convert_float(void *void_dst, int num_dst_channels,
   break;
case GL_UNSIGNED_BYTE:
   if (normalized) {
- SWIZZLE_CONVERT(float, uint8_t, unorm_to_float(src, 8));
+ SWIZZLE_CONVERT(float, uint8_t, _mesa_unorm_to_float(src, 8));
   } else {
  SWIZZLE_CONVERT(float, uint8_t, src);
   }
   break;
case GL_BYTE:
   if (normalized) {
- SWIZZLE_CONVERT(float, int8_t, snorm_to_float(src, 8));
+ SWIZZLE_CONVERT(float, int8_t, _mesa_snorm_to_float(src, 8));
   } else {
  SWIZZLE_CONVERT(float, int8_t, src);
   }
   break;
case GL_UNSIGNED_SHORT:
   if (normalized) {
- SWIZZLE_CONVERT(float, uint16_t, unorm_to_float(src, 16));
+ SWIZZLE_CONVERT(float, uint16_t, _mesa_unorm_to_float(src, 16));
   } else {
  SWIZZLE_CONVERT(float, uint16_t, src);
   }
   break;
case GL_SHORT:
   if (normalized) {
- SWIZZLE_CONVERT(float, int16_t, snorm_to_float(src, 16));
+ SWIZZLE_CONVERT(float, int16_t, _mesa_snorm_to_float(src, 16));
   } else {
  SWIZZLE_CONVERT(float, int16_t, src);
   }
   break;
case GL_UNSIGNED_INT:
   if (normalized) {
- SWIZZLE_CONVERT(float, uint32_t, unorm_to_float(src, 32));
+ SWIZZLE_CONVERT(float, uint32_t, _mesa_unorm_to_float(src, 32));
   } else {
  SWIZZLE_CONVERT(float, uint32_t, src);
   }
   break;
case GL_INT:
   if (normalized) {

[Mesa-dev] [PATCH 14/20] mesa: Add non-normalized formats support for ubyte packing functions

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
---
 src/mesa/main/format_pack.c.mako | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/format_pack.c.mako b/src/mesa/main/format_pack.c.mako
index b9f4656..97adf6e 100644
--- a/src/mesa/main/format_pack.c.mako
+++ b/src/mesa/main/format_pack.c.mako
@@ -84,7 +84,15 @@ pack_ubyte_${f.short_name()}(const GLubyte src[4], void *dst)
   %endif
 
   ${channel_datatype(c)} ${c.name} =
-  %if c.type == parser.UNSIGNED:
+  %if not f.is_normalized():
+ %if c.type == parser.FLOAT and c.size == 32:
+UBYTE_TO_FLOAT(src[${i}]);
+ %elif c.type == parser.FLOAT and c.size == 16:
+_mesa_float_to_half(UBYTE_TO_FLOAT(src[${i}]));
+ %else:
+(${channel_datatype(c)}) src[${i}];
+ %endif
+  %elif c.type == parser.UNSIGNED:
  %if f.colorspace == 'srgb' and c.name in 'rgb':
 util_format_linear_to_srgb_8unorm(src[${i}]);
  %else:
-- 
1.9.1

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


[Mesa-dev] [PATCH 17/20] mesa: use format conversion functions in swrast

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

This commit adds a macro to facilitate the task of using
format conversions functions but keeps the same API.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
---
 src/mesa/swrast/s_texfetch_tmp.h | 1359 --
 1 file changed, 122 insertions(+), 1237 deletions(-)

diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h
index e3a3cfe..45bd839 100644
--- a/src/mesa/swrast/s_texfetch_tmp.h
+++ b/src/mesa/swrast/s_texfetch_tmp.h
@@ -39,6 +39,7 @@
  * \author Brian Paul
  */
 
+#include format_unpack.h
 
 #if DIM == 1
 
@@ -68,1244 +69,128 @@
 #error illegal number of texture dimensions
 #endif
 
-
-static void
-FETCH(Z_UNORM32)(const struct swrast_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   texel[0] = src[0] * (1.0F / 0x);
-}
-
-
-static void
-FETCH(Z_UNORM16)(const struct swrast_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   texel[0] = src[0] * (1.0F / 65535.0F);
-}
-
-
-static void
-FETCH(RGBA_FLOAT32)(const struct swrast_texture_image *texImage,
-GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
-   texel[RCOMP] = src[0];
-   texel[GCOMP] = src[1];
-   texel[BCOMP] = src[2];
-   texel[ACOMP] = src[3];
-}
-
-
-static void
-FETCH(RGBA_FLOAT16)(const struct swrast_texture_image *texImage,
-GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
-   texel[RCOMP] = _mesa_half_to_float(src[0]);
-   texel[GCOMP] = _mesa_half_to_float(src[1]);
-   texel[BCOMP] = _mesa_half_to_float(src[2]);
-   texel[ACOMP] = _mesa_half_to_float(src[3]);
-}
-
-
-static void
-FETCH(RGB_FLOAT32)(const struct swrast_texture_image *texImage,
-   GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
-   texel[RCOMP] = src[0];
-   texel[GCOMP] = src[1];
-   texel[BCOMP] = src[2];
-   texel[ACOMP] = 1.0F;
-}
-
-
-static void
-FETCH(RGB_FLOAT16)(const struct swrast_texture_image *texImage,
-   GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
-   texel[RCOMP] = _mesa_half_to_float(src[0]);
-   texel[GCOMP] = _mesa_half_to_float(src[1]);
-   texel[BCOMP] = _mesa_half_to_float(src[2]);
-   texel[ACOMP] = 1.0F;
-}
-
-
-static void
-FETCH(A_FLOAT32)(const struct swrast_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
-   texel[RCOMP] =
-   texel[GCOMP] =
-   texel[BCOMP] = 0.0F;
-   texel[ACOMP] = src[0];
-}
-
-
-static void
-FETCH(A_FLOAT16)(const struct swrast_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
-   texel[RCOMP] =
-   texel[GCOMP] =
-   texel[BCOMP] = 0.0F;
-   texel[ACOMP] = _mesa_half_to_float(src[0]);
-}
-
-
-static void
-FETCH(L_FLOAT32)(const struct swrast_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
-   texel[RCOMP] =
-   texel[GCOMP] =
-   texel[BCOMP] = src[0];
-   texel[ACOMP] = 1.0F;
-}
-
-
-static void
-FETCH(L_FLOAT16)(const struct swrast_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
-   texel[RCOMP] =
-   texel[GCOMP] =
-   texel[BCOMP] = _mesa_half_to_float(src[0]);
-   texel[ACOMP] = 1.0F;
-}
-
-
-static void
-FETCH(LA_FLOAT32)(const struct swrast_texture_image *texImage,
-  GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
-   texel[RCOMP] =
-   texel[GCOMP] =
-   texel[BCOMP] = src[0];
-   texel[ACOMP] = src[1];
-}
-
-
-static void
-FETCH(LA_FLOAT16)(const struct swrast_texture_image *texImage,
-  GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
-   texel[RCOMP] =
-   texel[GCOMP] =
-   texel[BCOMP] = _mesa_half_to_float(src[0]);
-   texel[ACOMP] = _mesa_half_to_float(src[1]);
-}
-
-
-static void
-FETCH(I_FLOAT32)(const struct swrast_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
-   texel[RCOMP] =
-   texel[GCOMP] =
-   texel[BCOMP] =
-   texel[ACOMP] = src[0];
-}
-
-
-static void
-FETCH(I_FLOAT16)(const struct 

Re: [Mesa-dev] [PATCH 1/2] glsl: Generate unique names for each const array lowered to uniforms

2014-11-18 Thread Kenneth Graunke
On Tuesday, November 18, 2014 09:15:05 PM Chris Forbes wrote:
 Uniform names (even for hidden uniforms) are required to be unique; some
 parts of the compiler assume they can be looked up by name.
 
 Fixes the piglit test: tests/spec/glsl-1.20/linker/array-initializers-1
 
 Signed-off-by: Chris Forbes chr...@ijw.co.nz
 Cc: 10.4 mesa-sta...@lists.freedesktop.org
 ---
  src/glsl/lower_const_arrays_to_uniforms.cpp | 6 +-
  1 file changed, 5 insertions(+), 1 deletion(-)
 
 diff --git a/src/glsl/lower_const_arrays_to_uniforms.cpp 
 b/src/glsl/lower_const_arrays_to_uniforms.cpp
 index b3c0ee2..700e903 100644
 --- a/src/glsl/lower_const_arrays_to_uniforms.cpp
 +++ b/src/glsl/lower_const_arrays_to_uniforms.cpp
 @@ -49,6 +49,7 @@ public:
 {
instructions = insts;
progress = false;
 +  index = 0;
 }
  
 bool run()
 @@ -62,6 +63,7 @@ public:
  private:
 exec_list *instructions;
 bool progress;
 +   unsigned index;
  };
  
  void
 @@ -76,8 +78,10 @@ lower_const_array_visitor::handle_rvalue(ir_rvalue 
 **rvalue)
  
 void *mem_ctx = ralloc_parent(con);
  
 +   char *uniform_name = ralloc_asprintf(mem_ctx, constarray__%d, index++);

Yeah, I think this should work...we don't need locking on the counter because
it's not global...and we don't need to worry about getting the same name
twice because we only run the pass once (and I don't see a need to ever run it
more than once).

I had thought about doing this instead:

char *uniform_name = ralloc_asprintf(mem_ctx, constarray@%p, con);

which conveniently avoids the need for a counter.  The only bad thing is it
makes shader debug output different each invocation of the program, which
makes diffing output hard.  So, what you have is probably better.

Reviewed-by: Kenneth Graunke kenn...@whitecape.org

 +
 ir_variable *uni =
 -  new(mem_ctx) ir_variable(con-type, constarray, ir_var_uniform);
 +  new(mem_ctx) ir_variable(con-type, uniform_name, ir_var_uniform);
 uni-constant_initializer = con;
 uni-constant_value = con;
 uni-data.has_initializer = true;

signature.asc
Description: This is a digitally signed message part.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] i965/blorp: Fix hiz ops on MSAA surfaces

2014-11-18 Thread Chris Forbes
Two things were broken here:
- The depth/stencil surface dimensions were broken for MSAA.
- Sample count was programmed incorrectly.

Result was the depth resolve didn't work correctly on MSAA surfaces, and
so sampling the surface later produced garbage.

Fixes the new piglit test arb_texture_multisample-sample-depth, and
various artifacts in 'tesseract' with msaa=4 glineardepth=0.

Not observed any piglit regressions on Haswell.

v2: Just set brw_hiz_op_params::dst.num_samples rather than adding a
helper function (Ken).

Signed-off-by: Chris Forbes chr...@ijw.co.nz
---
 src/mesa/drivers/dri/i965/brw_blorp.cpp  |  1 +
 src/mesa/drivers/dri/i965/gen7_blorp.cpp | 11 +++
 2 files changed, 12 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_blorp.cpp 
b/src/mesa/drivers/dri/i965/brw_blorp.cpp
index 20ce7b7..0ecf330 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp.cpp
+++ b/src/mesa/drivers/dri/i965/brw_blorp.cpp
@@ -323,6 +323,7 @@ brw_hiz_op_params::brw_hiz_op_params(struct 
intel_mipmap_tree *mt,
 */
depth.width = ALIGN(depth.width, 8);
depth.height = ALIGN(depth.height, 4);
+   dst.num_samples = mt-num_samples;
 
x1 = depth.width;
y1 = depth.height;
diff --git a/src/mesa/drivers/dri/i965/gen7_blorp.cpp 
b/src/mesa/drivers/dri/i965/gen7_blorp.cpp
index 206a6ff..03fc9c8 100644
--- a/src/mesa/drivers/dri/i965/gen7_blorp.cpp
+++ b/src/mesa/drivers/dri/i965/gen7_blorp.cpp
@@ -663,6 +663,17 @@ gen7_blorp_emit_depth_stencil_config(struct brw_context 
*brw,
*/
   surfwidth = params-depth.width;
   surfheight = params-depth.height;
+
+  if (params-dst.num_samples  1) {
+ /* If this is an MSAA + HIZ op, we need to program the
+  * aligned logical size of the depth surface.
+  */
+ surfwidth = ALIGN(params-depth.mt-logical_width0, 8);
+ surfheight = ALIGN(params-depth.mt-logical_height0, 4);
+  } else {
+ surfwidth = params-depth.width;
+ surfheight = params-depth.height;
+  }
} else {
   surfwidth = params-depth.mt-logical_width0;
   surfheight = params-depth.mt-logical_height0;
-- 
2.1.3

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


Re: [Mesa-dev] [PATCH 2/2] i965: Handle nested uniform array indexing

2014-11-18 Thread Kenneth Graunke
On Tuesday, November 18, 2014 09:15:06 PM Chris Forbes wrote:
 When converting a uniform array reference to a pull constant load, the
 `reladdr` expression itself may have its own `reladdr`, arbitrarily
 deeply. This arises from expressions like:
 
a[b[x]] where a, b are uniform arrays (or lowered const arrays),
and x is not a constant.
 
 Just iterate the lowering to pull constants until we stop seeing these
 nested. For most shaders, there will be only one pass through this loop.
 
 Fixes the piglit test:
 tests/spec/glsl-1.20/linker/double-indirect-1.shader_test
 
 Signed-off-by: Chris Forbes chr...@ijw.co.nz
 Cc: 10.3 10.4 mesa-sta...@lists.freedesktop.org
 ---
  src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp | 66 
+++---
  1 file changed, 37 insertions(+), 29 deletions(-)
 
 diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp 
b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
 index af7ca0c..22a6fb9 100644
 --- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
 +++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
 @@ -3354,6 +3354,7 @@ 
vec4_visitor::move_uniform_array_access_to_pull_constants()
  {
 int pull_constant_loc[this-uniforms];
 memset(pull_constant_loc, -1, sizeof(pull_constant_loc));
 +   bool nested_reladdr;
  
 /* Walk through and find array access of uniforms.  Put a copy of that
  * uniform in the pull constant buffer.
 @@ -3361,44 +3362,51 @@ 
vec4_visitor::move_uniform_array_access_to_pull_constants()
  * Note that we don't move constant-indexed accesses to arrays.  No
  * testing has been done of the performance impact of this choice.
  */
 -   foreach_block_and_inst_safe(block, vec4_instruction, inst, cfg) {
 -  for (int i = 0 ; i  3; i++) {
 -  if (inst-src[i].file != UNIFORM || !inst-src[i].reladdr)
 - continue;
 +   do {
 +  nested_reladdr = false;

Yikes.  Good find on the bug.

Wrapping it in a loop like this is definitely nice and simple, which is great 
for stable branches.  It might be worth adding a TODO comment for doing it 
more efficiently someday:

/* TODO: We could refactor this and avoid doing N passes over the instruction
 * stream (where N is the reladdr nesting depth).
 */

I think this is fine, though, since the reladdr depth is probably 0 or 1...and 
we just found our first case of 2 today...

I think you need an equivalent patch for the FS.

As is,
Reviewed-by: Kenneth Graunke kenn...@whitecape.org

signature.asc
Description: This is a digitally signed message part.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] i965/blorp: Fix hiz ops on MSAA surfaces

2014-11-18 Thread Kenneth Graunke
On Tuesday, November 18, 2014 09:49:53 PM Chris Forbes wrote:
 Two things were broken here:
 - The depth/stencil surface dimensions were broken for MSAA.
 - Sample count was programmed incorrectly.
 
 Result was the depth resolve didn't work correctly on MSAA surfaces, and
 so sampling the surface later produced garbage.
 
 Fixes the new piglit test arb_texture_multisample-sample-depth, and
 various artifacts in 'tesseract' with msaa=4 glineardepth=0.
 
 Not observed any piglit regressions on Haswell.
 
 v2: Just set brw_hiz_op_params::dst.num_samples rather than adding a
 helper function (Ken).
 
 Signed-off-by: Chris Forbes chr...@ijw.co.nz
 ---
  src/mesa/drivers/dri/i965/brw_blorp.cpp  |  1 +
  src/mesa/drivers/dri/i965/gen7_blorp.cpp | 11 +++
  2 files changed, 12 insertions(+)
 
 diff --git a/src/mesa/drivers/dri/i965/brw_blorp.cpp 
b/src/mesa/drivers/dri/i965/brw_blorp.cpp
 index 20ce7b7..0ecf330 100644
 --- a/src/mesa/drivers/dri/i965/brw_blorp.cpp
 +++ b/src/mesa/drivers/dri/i965/brw_blorp.cpp
 @@ -323,6 +323,7 @@ brw_hiz_op_params::brw_hiz_op_params(struct 
intel_mipmap_tree *mt,
  */
 depth.width = ALIGN(depth.width, 8);
 depth.height = ALIGN(depth.height, 4);
 +   dst.num_samples = mt-num_samples;
  
 x1 = depth.width;
 y1 = depth.height;
 diff --git a/src/mesa/drivers/dri/i965/gen7_blorp.cpp 
b/src/mesa/drivers/dri/i965/gen7_blorp.cpp
 index 206a6ff..03fc9c8 100644
 --- a/src/mesa/drivers/dri/i965/gen7_blorp.cpp
 +++ b/src/mesa/drivers/dri/i965/gen7_blorp.cpp
 @@ -663,6 +663,17 @@ gen7_blorp_emit_depth_stencil_config(struct brw_context 
*brw,
 */
surfwidth = params-depth.width;
surfheight = params-depth.height;
 +
 +  if (params-dst.num_samples  1) {
 + /* If this is an MSAA + HIZ op, we need to program the
 +  * aligned logical size of the depth surface.
 +  */
 + surfwidth = ALIGN(params-depth.mt-logical_width0, 8);
 + surfheight = ALIGN(params-depth.mt-logical_height0, 4);
 +  } else {
 + surfwidth = params-depth.width;
 + surfheight = params-depth.height;
 +  }
 } else {
surfwidth = params-depth.mt-logical_width0;
surfheight = params-depth.mt-logical_height0;
 

Jordan, Chad...could one of you take a look at this?  It looks reasonable, but 
I always get confused by when/where we do rounding in BLORP.

Chris - we might want to Cc this to stable too.

--Ken

signature.asc
Description: This is a digitally signed message part.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 14/29] mesa: use _mesa_format_convert to implement glReadPixels.

2014-11-18 Thread Iago Toral Quiroga
---
 src/mesa/main/readpix.c | 354 +---
 1 file changed, 214 insertions(+), 140 deletions(-)

diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index b09cf54..8f4894e 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -39,6 +39,8 @@
 #include state.h
 #include glformats.h
 #include fbobject.h
+#include format_utils.h
+#include pixeltransfer.h
 
 
 /**
@@ -405,174 +407,246 @@ read_stencil_pixels( struct gl_context *ctx,
ctx-Driver.UnmapRenderbuffer(ctx, rb);
 }
 
-
-/**
- * Try to do glReadPixels of RGBA data using swizzle.
- * \return GL_TRUE if successful, GL_FALSE otherwise (use the slow path)
+/*
+ * Read R, G, B, A, RGB, L, or LA pixels.
  */
-static GLboolean
-read_rgba_pixels_swizzle(struct gl_context *ctx,
- GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- GLvoid *pixels,
- const struct gl_pixelstore_attrib *packing)
+static void
+read_rgba_pixels( struct gl_context *ctx,
+  GLint x, GLint y,
+  GLsizei width, GLsizei height,
+  GLenum format, GLenum type, GLvoid *pixels,
+  const struct gl_pixelstore_attrib *packing )
 {
-   struct gl_renderbuffer *rb = ctx-ReadBuffer-_ColorReadBuffer;
-   GLubyte *dst, *map;
-   int dstStride, stride, j;
-   GLboolean swizzle_rb = GL_FALSE, copy_xrgb = GL_FALSE;
-
-   /* XXX we could check for other swizzle/special cases here as needed */
-   if (rb-Format == MESA_FORMAT_R8G8B8A8_UNORM 
-   format == GL_BGRA 
-   type == GL_UNSIGNED_INT_8_8_8_8_REV 
-   !ctx-Pack.SwapBytes) {
-  swizzle_rb = GL_TRUE;
-   }
-   else if (rb-Format == MESA_FORMAT_B8G8R8X8_UNORM 
-   format == GL_BGRA 
-   type == GL_UNSIGNED_INT_8_8_8_8_REV 
-   !ctx-Pack.SwapBytes) {
-  copy_xrgb = GL_TRUE;
-   }
-   else {
-  return GL_FALSE;
-   }
+   GLbitfield transferOps;
+   struct gl_framebuffer *fb = ctx-ReadBuffer;
+   struct gl_renderbuffer *rb = fb-_ColorReadBuffer;
 
-   dstStride = _mesa_image_row_stride(packing, width, format, type);
-   dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
-  format, type, 0, 0);
+   if (!rb)
+  return;
 
+   transferOps = get_readpixels_transfer_ops(ctx, rb-Format, format, type,
+ GL_FALSE);
+   /* Describe the dst format */
+   GLboolean dst_is_integer = _mesa_is_enum_format_integer(format);
+   int dst_stride = _mesa_image_row_stride(packing, width, format, type);
+   uint32_t dst_format = _mesa_format_from_format_and_type(format, type);
+   mesa_format dst_mesa_format;
+   if (dst_format  MESA_ARRAY_FORMAT_BIT)
+  dst_mesa_format = _mesa_format_from_array_format(dst_format);
+   else
+  dst_mesa_format = dst_format;
+   GLenum dst_base_format = _mesa_get_format_base_format(dst_mesa_format);
+   GLubyte *dst = (GLubyte *)
+  _mesa_image_address2d(packing, pixels, width, height,
+format, type, 0, 0);
+
+   /* Map the source render buffer */
+   GLubyte *map;
+   int rb_stride;
ctx-Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
-  map, stride);
+   map, rb_stride);
if (!map) {
   _mesa_error(ctx, GL_OUT_OF_MEMORY, glReadPixels);
-  return GL_TRUE;  /* don't bother trying the slow path */
+  return;
}
+   const mesa_format rb_format = _mesa_get_srgb_format_linear(rb-Format);
+   GLenum rb_base_format = _mesa_get_format_base_format(rb_format);
 
-   if (swizzle_rb) {
-  /* swap R/B */
-  for (j = 0; j  height; j++) {
- int i;
- for (i = 0; i  width; i++) {
-GLuint *dst4 = (GLuint *) dst, *map4 = (GLuint *) map;
-GLuint pixel = map4[i];
-dst4[i] = (pixel  0xff00ff00)
-   | ((pixel  0x00ff)  16)
-   | ((pixel  0x00ff)  16);
+   /* Since _mesa_format_convert does not handle transferOps we need to handle
+* them before we call the function. This requires to convert to RGBA float
+* first so we can call _mesa_apply_rgba_transfer_ops. If the dst format is
+* integer we can ignore transferOps.
+*
+* Depending on the base formats involved in the conversion we might need to
+* rebase some values and for that we need to convert to RGBA first too.
+*/
+   assert(!transferOps || (transferOps  !dst_is_integer));
+   GLenum rebase_format = GL_NONE;
+   if (rb-_BaseFormat == GL_LUMINANCE ||
+   rb-_BaseFormat == GL_INTENSITY ||
+   rb-_BaseFormat == GL_LUMINANCE_ALPHA) {
+  /* If luminance (or intensity) is read back as RGB(A), the returned value
+   * should be (L,0,0,1), not (L,L,L,1), so we need to rebase.
+   */
+  rebase_format = 

[Mesa-dev] [PATCH 07/29] mesa: Add helper to convert a GL format and type to a mesa (array) format.

2014-11-18 Thread Iago Toral Quiroga
---
 src/mesa/main/formats.c | 285 
 src/mesa/main/formats.h |   3 +
 2 files changed, 288 insertions(+)

diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 06e8973..7464d89 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -325,6 +325,291 @@ _mesa_format_from_array_format(uint32_t array_format)
return MESA_FORMAT_NONE;
 }
 
+static void
+_mesa_array_format_set_swizzle(mesa_array_format *array_format,
+   int x, int y, int z, int w)
+{
+   array_format-swizzle_x = x;
+   array_format-swizzle_y = y;
+   array_format-swizzle_z = z;
+   array_format-swizzle_w = w;
+}
+
+static bool
+_mesa_array_format_set_swizzle_from_format(mesa_array_format *array_format,
+   GLenum format)
+{
+   switch (format) {
+   case GL_RGBA:
+   case GL_RGBA_INTEGER_EXT:
+  _mesa_array_format_set_swizzle(array_format, 0, 1, 2, 3);
+  return true;
+   case GL_BGRA:
+   case GL_BGRA_INTEGER_EXT:
+  _mesa_array_format_set_swizzle(array_format, 2, 1, 0, 3);
+  return true;
+   case GL_ABGR_EXT:
+  _mesa_array_format_set_swizzle(array_format, 3, 2, 1, 0);
+  return true;
+   case GL_RGB:
+   case GL_RGB_INTEGER_EXT:
+  _mesa_array_format_set_swizzle(array_format, 0, 1, 2, 5);
+  return true;
+   case GL_BGR:
+   case GL_BGR_INTEGER_EXT:
+  _mesa_array_format_set_swizzle(array_format, 2, 1, 0, 5);
+  return true;
+   case GL_LUMINANCE_ALPHA:
+   case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+  _mesa_array_format_set_swizzle(array_format, 0, 0, 0, 1);
+  return true;
+   case GL_RG:
+   case GL_RG_INTEGER:
+  _mesa_array_format_set_swizzle(array_format, 0, 1, 4, 5);
+  return true;
+   case GL_RED:
+   case GL_RED_INTEGER_EXT:
+  _mesa_array_format_set_swizzle(array_format, 0, 4, 4, 5);
+  return true;
+   case GL_GREEN:
+   case GL_GREEN_INTEGER_EXT:
+  _mesa_array_format_set_swizzle(array_format, 4, 0, 4, 5);
+  return true;
+   case GL_BLUE:
+   case GL_BLUE_INTEGER_EXT:
+  _mesa_array_format_set_swizzle(array_format, 4, 4, 0, 5);
+  return true;
+   case GL_ALPHA:
+   case GL_ALPHA_INTEGER_EXT:
+  _mesa_array_format_set_swizzle(array_format, 4, 4, 4, 0);
+  return true;
+   case GL_LUMINANCE:
+   case GL_LUMINANCE_INTEGER_EXT:
+  _mesa_array_format_set_swizzle(array_format, 0, 0, 0, 5);
+  return true;
+   case GL_INTENSITY:
+  _mesa_array_format_set_swizzle(array_format, 0, 0, 0, 0);
+  return true;
+   default:
+  return false;
+   }
+}
+
+/**
+* Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
+* GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
+* otherwise (for non-array formats).
+*
+* This function will typically be used to compute a mesa format from a GL type
+* so we can then call _mesa_format_convert. This function does
+* not consider byte swapping, so it returns types assuming that no byte
+* swapping is involved. If byte swapping is involved then clients are supposed
+* to handle that on their side before calling _mesa_format_convert.
+*
+* This function returns an uint32_t that can pack a mesa_format or a
+* mesa_array_format. Clients must check the mesa array format bit
+* (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
+* format is a mesa_array_format or a mesa_format.
+*/
+uint32_t
+_mesa_format_from_format_and_type(GLenum format, GLenum type)
+{
+   mesa_array_format array_format;
+
+   bool is_array_format = true;
+
+   /* Map the OpenGL data type to an array format data type */
+   switch (type) {
+   case GL_UNSIGNED_BYTE:
+  array_format.type = MESA_ARRAY_FORMAT_TYPE_UBYTE;
+  break;
+   case GL_BYTE:
+  array_format.type = MESA_ARRAY_FORMAT_TYPE_BYTE;
+  break;
+   case GL_UNSIGNED_SHORT:
+  array_format.type = MESA_ARRAY_FORMAT_TYPE_USHORT;
+  break;
+   case GL_SHORT:
+  array_format.type = MESA_ARRAY_FORMAT_TYPE_SHORT;
+  break;
+   case GL_UNSIGNED_INT:
+  array_format.type = MESA_ARRAY_FORMAT_TYPE_UINT;
+  break;
+   case GL_INT:
+  array_format.type = MESA_ARRAY_FORMAT_TYPE_INT;
+  break;
+   case GL_HALF_FLOAT:
+  array_format.type = MESA_ARRAY_FORMAT_TYPE_HALF;
+  break;
+   case GL_FLOAT:
+  array_format.type = MESA_ARRAY_FORMAT_TYPE_FLOAT;
+  break;
+   case GL_UNSIGNED_INT_8_8_8_8:
+   case GL_UNSIGNED_INT_8_8_8_8_REV:
+  array_format.type = MESA_ARRAY_FORMAT_TYPE_UBYTE;
+  break;
+   default:
+  is_array_format = false;
+  break;
+   }
+
+   /* Next we extract array swizzle information from the OpenGL format */
+   if (is_array_format) {
+  is_array_format =
+ _mesa_array_format_set_swizzle_from_format(array_format, format);
+   }
+
+   /* If this is an array format type after checking data type and format,
+* fill in the remaining data
+*/
+   if (is_array_format) {
+  

[Mesa-dev] [PATCH 05/29] mesa: Consider internal base format in _mesa_format_convert

2014-11-18 Thread Iago Toral Quiroga
Add a dst_internal_format parameter to _mesa_format_convert, that represents
the base internal format for texture/pixel uploads, so we can do the right
thing when the driver has selected a different internal format for the target
dst format.
---
 src/mesa/main/format_utils.c | 65 +++-
 src/mesa/main/format_utils.h |  2 +-
 2 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index fc59e86..5964689 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -303,7 +303,7 @@ _mesa_compute_component_mapping(GLenum inFormat, GLenum 
outFormat, GLubyte *map)
 void
 _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
  void *void_src, uint32_t src_format, size_t src_stride,
- size_t width, size_t height)
+ size_t width, size_t height, GLenum dst_internal_format)
 {
uint8_t *dst = (uint8_t *)void_dst;
uint8_t *src = (uint8_t *)void_src;
@@ -422,6 +422,36 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, 
size_t dst_stride,
if (src_array_format.as_uint  dst_array_format.as_uint) {
   assert(src_array_format.normalized == dst_array_format.normalized);
 
+  /* If the base format of our dst is not the same as the provided base
+   * format it means that we are converting to a different format
+   * than the one originally requested by the client. This can happen when
+   * the internal base format requested is not supported by the driver.
+   * In this case we need to consider the requested internal base format to
+   * compute the correct swizzle operation from src to dst. We will do this
+   * by computing the swizzle transform src-rgba-base-rgba-dst instead
+   * of src-rgba-dst.
+   */
+  mesa_format dst_mesa_format;
+  if (dst_format  MESA_ARRAY_FORMAT_BIT)
+ dst_mesa_format = _mesa_format_from_array_format(dst_format);
+  else
+ dst_mesa_format = dst_format;
+  if (dst_internal_format != 
_mesa_get_format_base_format(dst_mesa_format)) {
+ /* Compute src2rgba as src-rgba-base-rgba */
+ uint8_t rgba2base[4], base2rgba[4], swizzle[4];
+ _mesa_compute_component_mapping(GL_RGBA, dst_internal_format, 
rgba2base);
+ _mesa_compute_component_mapping(dst_internal_format, GL_RGBA, 
base2rgba);
+
+ for (i = 0; i  4; i++) {
+if (base2rgba[i]  MESA_FORMAT_SWIZZLE_W)
+   swizzle[i] = base2rgba[i];
+else
+   swizzle[i] = src2rgba[rgba2base[base2rgba[i]]];
+ }
+ memcpy(src2rgba, swizzle, sizeof(src2rgba));
+  }
+
+  /* Compute src2dst from src2rgba */
   for (i = 0; i  4; i++) {
  if (rgba2dst[i]  MESA_FORMAT_SWIZZLE_W) {
 src2dst[i] = rgba2dst[i];
@@ -539,9 +569,42 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, 
size_t dst_stride,
 src += src_stride;
  }
   } else {
+ /* For some conversions, doing src-rgba-dst is not enough and we
+  * need to consider the base internal format. In these cases a
+  * swizzle operation is required to match the semantics of the base
+  * internal format requested: src-rgba-swizzle-rgba-dst.
+  *
+  * We can detect these cases by checking if the swizzle transform
+  * for base-rgba-base is 0123. If it is not, then we need
+  * to do the swizzle operation (need_convert = true).
+  */
+ GLubyte rgba2base[4], base2rgba[4], map[4];
+ bool need_convert = false;
+ mesa_format dst_mesa_format;
+ if (dst_format  MESA_ARRAY_FORMAT_BIT)
+dst_mesa_format = _mesa_format_from_array_format(dst_format);
+ else
+dst_mesa_format = dst_format;
+ if (dst_internal_format !=
+ _mesa_get_format_base_format(dst_mesa_format)) {
+_mesa_compute_component_mapping(GL_RGBA, dst_internal_format,
+base2rgba);
+_mesa_compute_component_mapping(dst_internal_format, GL_RGBA,
+rgba2base);
+for (i = 0; i  4; ++i) {
+   map[i] = base2rgba[rgba2base[i]];
+   if (map[i] != i)
+  need_convert = true;
+}
+ }
+
  for (row = 0; row  height; ++row) {
 _mesa_unpack_rgba_row(src_format, width,
   src, tmp_float + row * width);
+if (need_convert)
+   _mesa_swizzle_and_convert(tmp_float + row * width, GL_FLOAT, 4,
+ tmp_float + row * width, GL_FLOAT, 4,
+ map, false, width);
 src += src_stride;
  }
   }
diff --git a/src/mesa/main/format_utils.h 

[Mesa-dev] [PATCH 26/29] mesa: Replace _mesa_pack_rgba_span_float with _mesa_format_convert

2014-11-18 Thread Iago Toral Quiroga
This replaces all remaining uses of this function, which will be
removed in another commit.
---
 src/mesa/main/texgetimage.c| 23 +++
 src/mesa/state_tracker/st_cb_texture.c | 14 ++
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index 13e5ae6..6bf1681 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -247,8 +247,8 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint 
dimensions,
const GLuint width = texImage-Width;
const GLuint height = texImage-Height;
const GLuint depth = texImage-Depth;
-   GLfloat *tempImage, *tempSlice, *srcRow;
-   GLuint row, slice;
+   GLfloat *tempImage, *tempSlice;
+   GLuint slice;
 
/* Decompress into temp float buffer, then pack into user buffer */
tempImage = malloc(width * height * depth
@@ -310,18 +310,17 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint 
dimensions,
   rebaseFormat);
}
 
+   int srcStride = 4 * width * sizeof(GLfloat);
+   int dstStride = _mesa_image_row_stride(ctx-Pack, width, format, type);
+   uint32_t dstFormat = _mesa_format_from_format_and_type(format, type);
tempSlice = tempImage;
for (slice = 0; slice  depth; slice++) {
-  srcRow = tempSlice;
-  for (row = 0; row  height; row++) {
- void *dest = _mesa_image_address(dimensions, ctx-Pack, pixels,
-  width, height, format, type,
-  slice, row, 0);
-
- _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) srcRow,
-format, type, dest, ctx-Pack, 
transferOps);
- srcRow += 4 * width;
-  }
+  void *dest = _mesa_image_address(dimensions, ctx-Pack, pixels,
+   width, height, format, type,
+   slice, 0, 0);
+  _mesa_format_convert(dest, dstFormat, dstStride,
+   tempSlice, RGBA_FLOAT.as_uint, srcStride,
+   width, height, destBaseFormat);
   tempSlice += 4 * width * height;
}
 
diff --git a/src/mesa/state_tracker/st_cb_texture.c 
b/src/mesa/state_tracker/st_cb_texture.c
index a8dbb78..b93d8c1 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -29,6 +29,7 @@
 #include main/enums.h
 #include main/fbobject.h
 #include main/formats.h
+#include main/format_utils.h
 #include main/image.h
 #include main/imports.h
 #include main/macros.h
@@ -1149,6 +1150,9 @@ st_GetTexImage(struct gl_context * ctx,
   if (ST_DEBUG  DEBUG_FALLBACK)
  debug_printf(%s: fallback format translation\n, __FUNCTION__);
 
+  uint32_t dstMesaFormat = _mesa_format_from_format_and_type(format, type);
+  int dstStride = _mesa_image_row_stride(ctx-Pack, width, format, type);
+  int srcStride = 4 * width * sizeof(GLfloat);
   for (slice = 0; slice  depth; slice++) {
  if (gl_target == GL_TEXTURE_1D_ARRAY) {
 /* 1D array textures.
@@ -1162,8 +1166,9 @@ st_GetTexImage(struct gl_context * ctx,
 pipe_get_tile_rgba_format(tex_xfer, map, 0, 0, width, 1,
   dst_format, rgba);
 
-_mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, 
format,
-   type, dest, ctx-Pack, 0);
+_mesa_format_convert(dest, dstMesaFormat, dstStride,
+ rgba, RGBA_FLOAT.as_uint, srcStride,
+ width, 1, GL_RGBA);
  }
  else {
 for (row = 0; row  height; row++) {
@@ -1175,8 +1180,9 @@ st_GetTexImage(struct gl_context * ctx,
pipe_get_tile_rgba_format(tex_xfer, map, 0, row, width, 1,
  dst_format, rgba);
 
-   _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, 
format,
-  type, dest, ctx-Pack, 0);
+   _mesa_format_convert(dest, dstMesaFormat, dstStride,
+rgba, RGBA_FLOAT.as_uint, srcStride,
+width, 1, GL_RGBA);
 }
  }
  map += tex_xfer-layer_stride;
-- 
1.9.1

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


[Mesa-dev] [PATCH 28/29] mesa: Remove _mesa_(un)pack_index_span

2014-11-18 Thread Iago Toral Quiroga
These are not used anywhere.
---
 src/mesa/main/pack.c | 219 ---
 src/mesa/main/pack.h |  15 
 2 files changed, 234 deletions(-)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 49b2998..a804a58 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -481,225 +481,6 @@ clamp_half_to_uint(GLhalfARB h)
 
 
 /*
- * Unpack a row of color index data from a client buffer according to
- * the pixel unpacking parameters.
- * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
- *
- * Args:  ctx - the context
- *n - number of pixels
- *dstType - destination data type
- *dest - destination array
- *srcType - source pixel type
- *source - source data pointer
- *srcPacking - pixel unpacking parameters
- *transferOps - the pixel transfer operations to apply
- */
-void
-_mesa_unpack_index_span( struct gl_context *ctx, GLuint n,
- GLenum dstType, GLvoid *dest,
- GLenum srcType, const GLvoid *source,
- const struct gl_pixelstore_attrib *srcPacking,
- GLbitfield transferOps )
-{
-   ASSERT(srcType == GL_BITMAP ||
-  srcType == GL_UNSIGNED_BYTE ||
-  srcType == GL_BYTE ||
-  srcType == GL_UNSIGNED_SHORT ||
-  srcType == GL_SHORT ||
-  srcType == GL_UNSIGNED_INT ||
-  srcType == GL_INT ||
-  srcType == GL_HALF_FLOAT_ARB ||
-  srcType == GL_FLOAT);
-
-   ASSERT(dstType == GL_UNSIGNED_BYTE ||
-  dstType == GL_UNSIGNED_SHORT ||
-  dstType == GL_UNSIGNED_INT);
-
-
-   transferOps = (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT);
-
-   /*
-* Try simple cases first
-*/
-   if (transferOps == 0  srcType == GL_UNSIGNED_BYTE
-dstType == GL_UNSIGNED_BYTE) {
-  memcpy(dest, source, n * sizeof(GLubyte));
-   }
-   else if (transferOps == 0  srcType == GL_UNSIGNED_INT
- dstType == GL_UNSIGNED_INT  !srcPacking-SwapBytes) {
-  memcpy(dest, source, n * sizeof(GLuint));
-   }
-   else {
-  /*
-   * general solution
-   */
-  GLuint *indexes = malloc(n * sizeof(GLuint));
-
-  if (!indexes) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, pixel unpacking);
- return;
-  }
-
-  extract_uint_indexes(n, indexes, GL_COLOR_INDEX, srcType, source,
-   srcPacking);
-
-  if (transferOps)
- _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
-
-  /* convert to dest type */
-  switch (dstType) {
- case GL_UNSIGNED_BYTE:
-{
-   GLubyte *dst = (GLubyte *) dest;
-   GLuint i;
-   for (i = 0; i  n; i++) {
-  dst[i] = (GLubyte) (indexes[i]  0xff);
-   }
-}
-break;
- case GL_UNSIGNED_SHORT:
-{
-   GLuint *dst = (GLuint *) dest;
-   GLuint i;
-   for (i = 0; i  n; i++) {
-  dst[i] = (GLushort) (indexes[i]  0x);
-   }
-}
-break;
- case GL_UNSIGNED_INT:
-memcpy(dest, indexes, n * sizeof(GLuint));
-break;
- default:
-_mesa_problem(ctx, bad dstType in _mesa_unpack_index_span);
-  }
-
-  free(indexes);
-   }
-}
-
-
-void
-_mesa_pack_index_span( struct gl_context *ctx, GLuint n,
-   GLenum dstType, GLvoid *dest, const GLuint *source,
-   const struct gl_pixelstore_attrib *dstPacking,
-   GLbitfield transferOps )
-{
-   GLuint *indexes = malloc(n * sizeof(GLuint));
-
-   if (!indexes) {
-  _mesa_error(ctx, GL_OUT_OF_MEMORY, pixel packing);
-  return;
-   }
-
-   transferOps = (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT);
-
-   if (transferOps  (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT)) {
-  /* make a copy of input */
-  memcpy(indexes, source, n * sizeof(GLuint));
-  _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
-  source = indexes;
-   }
-
-   switch (dstType) {
-   case GL_UNSIGNED_BYTE:
-  {
- GLubyte *dst = (GLubyte *) dest;
- GLuint i;
- for (i = 0; i  n; i++) {
-*dst++ = (GLubyte) source[i];
- }
-  }
-  break;
-   case GL_BYTE:
-  {
- GLbyte *dst = (GLbyte *) dest;
- GLuint i;
- for (i = 0; i  n; i++) {
-dst[i] = (GLbyte) source[i];
- }
-  }
-  break;
-   case GL_UNSIGNED_SHORT:
-  {
- GLushort *dst = (GLushort *) dest;
- GLuint i;
- for (i = 0; i  n; i++) {
-dst[i] = (GLushort) source[i];
- }
- if (dstPacking-SwapBytes) {
-_mesa_swap2( (GLushort *) dst, n );
- }
-  }
-  break;
-   case GL_SHORT:
-  {
- GLshort *dst = (GLshort *) dest;
- 

[Mesa-dev] [PATCH 00/29] Use a master format convert function

2014-11-18 Thread Iago Toral Quiroga
This is the second of two series of patches to address:
https://bugs.freedesktop.org/show_bug.cgi?id=84566

This series is based on the previous series we sent for review: Auto-generate
pack/unpack functions. To ease review and testing, the combined series are
available here:

https://github.com/Igalia/mesa/tree/itoral-format-convert-review

The goal of this second series is to provide a master convert function
(_mesa_format_convert) that can handle almost all kinds of color format
conversions. To achieve this, this master convert function will operate using
the auto-generated pack/unpack functions as well as _mesa_swizzle_and_convert
(for array types).

This is based on initial work by Jason Ekstrand.

Tested on i965, classic swrast and gallium (llvmpipe, nouveau, radeon) without
regressions. We also get the following new piglit passes:

spec/!OpenGL 1.1/teximage-colors GL_RGB16_SNORM/Exact upload-download of 
GL_RGB16_SNORM
spec/!OpenGL 1.1/teximage-colors GL_RGB8_SNORM/Exact upload-download of 
GL_RGB8_SNORM
spec/ARB_copy_image/arb_copy_image-formats/Source: GL_RGB16_SNORM/Destination: 
GL_RGB16_SNORM
spec/ARB_copy_image/arb_copy_image-formats/Source: GL_ALPHA12/Destination: 
GL_ALPHA12
spec/ARB_copy_image/arb_copy_image-formats/Source: GL_RGB8I/Destination: 
GL_RGB8_SNORM
spec/ARB_copy_image/arb_copy_image-formats/Source: GL_RGB16UI/Destination: 
GL_RGB16_SNORM
spec/ARB_copy_image/arb_copy_image-formats/Source: GL_RGB8_SNORM/Destination: 
GL_RGB8_SNORM
spec/ARB_copy_image/arb_copy_image-formats/Source: GL_RGB8UI/Destination: 
GL_RGB8_SNORM
spec/ARB_copy_image/arb_copy_image-formats/Source: GL_RGB16/Destination: 
GL_RGB16_SNORM
spec/ARB_copy_image/arb_copy_image-formats/Source: GL_RGB8/Destination: 
GL_RGB8_SNORM
spec/ARB_copy_image/arb_copy_image-formats/Source: GL_INTENSITY12/Destination: 
GL_INTENSITY12
spec/ARB_copy_image/arb_copy_image-formats/Source: GL_LUMINANCE12/Destination: 
GL_LUMINANCE12
spec/ARB_copy_image/arb_copy_image-formats/Source: 
GL_LUMINANCE12_ALPHA12/Destination: GL_LUMINANCE12_ALPHA12
spec/ARB_copy_image/arb_copy_image-formats/Source: GL_RGB16I/Destination: 
GL_RGB16_SNORM

Just like in the previous series, for software drivers we worked with a
significant subset of piglit tests selected with this filter:
-t format -t color -t tex -t image -t swizzle -t clamp -t rgb -t lum -t pix
-t fbo -t frame

This series removes 3000 SLOC and together with the autogen pack/unpack series
it removes 1 SLOC (although we would be auto-generating a good chunk of
those).

Although there are no piglit regressions and we even get some new passes,
there are thousands of format conversion combinations and piglit does not cover
every single one, so there is room for some regressions but hopefully not 
major ones. One thing we could not test is big-endian, so that's something that
should be reviewed with extra care.

Patch summary:
  * Patches 1-6, 12 implement the master convert function (_mesa_format_convert)
  * Patches 7-11 mostly add helpers that will be used by callers of
_mesa_format_convert
  * Patches 13-17 use _mesa_format_convert in the implementation of
glTex(Sub)Image, glDrawPixels, glGetTex(Sub)Image and glReadPixels.
  * Patches 18-29 remove a bunch of code that becomes obsolete after
introducing _mesa_format_convert

Eduardo Lima Mitev (1):
  mesa: Replace _mesa_unpack_bitmap with _mesa_unpack_image()

Iago Toral Quiroga (24):
  mesa: Set normalized=true for float array formats.
  mesa: Do not assert on integer-non-integer direct pack/unpack fast
paths
  mesa: Expose compute_component_mapping as
_mesa_compute_component_mapping
  mesa: Consider internal base format in _mesa_format_convert
  mesa: Avoid pack/unpack fast paths if base internal format != base
format
  mesa: Add helper to convert a GL format and type to a mesa (array)
format.
  mesa: Add _mesa_swap2_copy and _mesa_swap4_copy
  mesa: Add RGBA to Luminance conversion helpers
  mesa: Add helpers to extract GL_COLOR_INDEX to RGBA float/ubyte
  mesa: Fix RGBA_UINT direct unpack path in _mesa_format_convert.
  mesa: Use _mesa_format_convert to implement texstore_rgba.
  mesa: use _mesa_format_convert to implement glReadPixels.
  mesa: Let _mesa_get_format_base_format also handle mesa_array_format
  mesa: Unify rebase logic for glReadPixels and glGetTexImage.
  mesa: Remove _mesa_unpack_color_span_uint
  mesa: Remove _mesa_make_temp_ubyte_image
  mesa: Remove _mesa_make_temp_float_image
  mesa: Remove _mesa_unpack_color_span_ubyte
  mesa: Remove (signed) integer pack and span functions.
  swrast: Replace _mesa_unpack_color_span_float with
_mesa_format_convert
  mesa: Remove _mesa_unpack_color_span_float
  mesa: Replace _mesa_pack_rgba_span_float with _mesa_format_convert
  mesa: Remove _mesa_pack_rgba_span_float and tmp_pack.h
  mesa: Remove _mesa_(un)pack_index_span

Jason Ekstrand (1):
  mesa: Add an implementation of a master convert function.

Samuel Iglesias Gonsalvez (3):
  mesa/pack: 

[Mesa-dev] [PATCH 03/29] mesa: Do not assert on integer-non-integer direct pack/unpack fast paths

2014-11-18 Thread Iago Toral Quiroga
We can have conversions from non-integer types to integer types, so remove
the assertions for these in the pack/unpack fast paths. It could be that
we do not have all the necessary pack/unpack functions in these cases though,
so protect these paths with conditionals and let _mesa_format_convert use
other paths to resolve these kind of conversions if necessary.
---
 src/mesa/main/format_utils.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index 1d65f2b..56a3b8d 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -143,8 +143,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, 
size_t dst_stride,
 dst += dst_stride;
  }
  return;
-  } else if (dst_array_format.as_uint == RGBA_UBYTE.as_uint) {
- assert(!_mesa_is_format_integer_color(src_format));
+  } else if (dst_array_format.as_uint == RGBA_UBYTE.as_uint 
+ !_mesa_is_format_integer_color(src_format)) {
  for (row = 0; row  height; ++row) {
 _mesa_unpack_ubyte_rgba_row(src_format, width,
 src, (uint8_t (*)[4])dst);
@@ -152,8 +152,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, 
size_t dst_stride,
 dst += dst_stride;
  }
  return;
-  } else if (dst_array_format.as_uint == RGBA_UINT.as_uint) {
- assert(_mesa_is_format_integer_color(src_format));
+  } else if (dst_array_format.as_uint == RGBA_UINT.as_uint 
+ _mesa_is_format_integer_color(src_format)) {
  for (row = 0; row  height; ++row) {
 _mesa_unpack_uint_rgba_row(src_format, width,
src, (uint32_t (*)[4])dst);
@@ -174,8 +174,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, 
size_t dst_stride,
 dst += dst_stride;
  }
  return;
-  } else if (src_array_format.as_uint == RGBA_UBYTE.as_uint) {
- assert(!_mesa_is_format_integer_color(dst_format));
+  } else if (src_array_format.as_uint == RGBA_UBYTE.as_uint 
+ !_mesa_is_format_integer_color(dst_format)) {
  for (row = 0; row  height; ++row) {
 _mesa_pack_ubyte_rgba_row(dst_format, width,
   (const uint8_t (*)[4])src, dst);
@@ -183,8 +183,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, 
size_t dst_stride,
 dst += dst_stride;
  }
  return;
-  } else if (src_array_format.as_uint == RGBA_UINT.as_uint) {
- assert(_mesa_is_format_integer_color(dst_format));
+  } else if (src_array_format.as_uint == RGBA_UINT.as_uint 
+ _mesa_is_format_integer_color(dst_format)) {
  for (row = 0; row  height; ++row) {
 _mesa_pack_uint_rgba_row(dst_format, width,
  (const uint32_t (*)[4])src, dst);
-- 
1.9.1

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


[Mesa-dev] [PATCH 08/29] mesa/pack: use _mesa_format_from_format_and_type in _mesa_pack_rgba_span_from_*

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

We had previously added the needed mesa formats, so we can simplify
the code further.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
---
 src/mesa/main/pack.c | 282 +--
 1 file changed, 26 insertions(+), 256 deletions(-)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 06993d4..de6ab27 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -529,6 +529,8 @@ _mesa_pack_rgba_span_from_uints(struct gl_context *ctx, 
GLuint n, GLuint rgba[][
 GLenum dstFormat, GLenum dstType,
 GLvoid *dstAddr)
 {
+   uint32_t dstMesaFormat;
+
switch(dstType) {
case GL_UNSIGNED_INT:
   pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
@@ -549,109 +551,24 @@ _mesa_pack_rgba_span_from_uints(struct gl_context *ctx, 
GLuint n, GLuint rgba[][
   pack_byte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
   break;
case GL_UNSIGNED_BYTE_3_3_2:
-  if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER))
- _mesa_pack_uint_rgba_row(MESA_FORMAT_B2G3R3_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else
- _pack_rgba_span_from_uints_problem(ctx, dstFormat, dstType);
-  break;
case GL_UNSIGNED_BYTE_2_3_3_REV:
-  if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER))
- _mesa_pack_uint_rgba_row(MESA_FORMAT_R3G3B2_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else
- _pack_rgba_span_from_uints_problem(ctx, dstFormat, dstType);
-  break;
case GL_UNSIGNED_SHORT_5_6_5:
-  if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER))
- _mesa_pack_uint_rgba_row(MESA_FORMAT_B5G6R5_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else
- _pack_rgba_span_from_uints_problem(ctx, dstFormat, dstType);
-  break;
case GL_UNSIGNED_SHORT_5_6_5_REV:
-  if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER))
- _mesa_pack_uint_rgba_row(MESA_FORMAT_R5G6B5_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else
- _pack_rgba_span_from_uints_problem(ctx, dstFormat, dstType);
-  break;
case GL_UNSIGNED_SHORT_4_4_4_4:
-  if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT))
- _mesa_pack_uint_rgba_row(MESA_FORMAT_A4B4G4R4_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else if ((dstFormat == GL_BGRA) || (dstFormat == GL_BGRA_INTEGER))
- _mesa_pack_uint_rgba_row(MESA_FORMAT_A4R4G4B4_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else if (dstFormat == GL_ABGR_EXT)
- _mesa_pack_uint_rgba_row(MESA_FORMAT_R4G4B4A4_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else
- _pack_rgba_span_from_uints_problem(ctx, dstFormat, dstType);
-  break;
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
-  if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT))
- _mesa_pack_uint_rgba_row(MESA_FORMAT_R4G4B4A4_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else if ((dstFormat == GL_BGRA) || (dstFormat == GL_BGRA_INTEGER))
- _mesa_pack_uint_rgba_row(MESA_FORMAT_B4G4R4A4_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else if (dstFormat == GL_ABGR_EXT)
- _mesa_pack_uint_rgba_row(MESA_FORMAT_A4B4G4R4_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else
- _pack_rgba_span_from_uints_problem(ctx, dstFormat, dstType);
-  break;
case GL_UNSIGNED_SHORT_5_5_5_1:
-  if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT))
-  _mesa_pack_uint_rgba_row(MESA_FORMAT_A1B5G5R5_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else if ((dstFormat == GL_BGRA) || (dstFormat == GL_BGRA_INTEGER))
- _mesa_pack_uint_rgba_row(MESA_FORMAT_A1R5G5B5_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else if (dstFormat == GL_ABGR_EXT)
- _mesa_pack_uint_rgba_row(MESA_FORMAT_R1G5B5A5_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else
- _pack_rgba_span_from_uints_problem(ctx, dstFormat, dstType);
-  break;
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
-  if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT))
- _mesa_pack_uint_rgba_row(MESA_FORMAT_R5G5B5A1_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else if ((dstFormat == GL_BGRA) || (dstFormat == GL_BGRA_INTEGER))
- _mesa_pack_uint_rgba_row(MESA_FORMAT_B5G5R5A1_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else if (dstFormat == GL_ABGR_EXT)
- _mesa_pack_uint_rgba_row(MESA_FORMAT_A5B5G5R1_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else
- _pack_rgba_span_from_uints_problem(ctx, dstFormat, dstType);
-  break;
case GL_UNSIGNED_INT_8_8_8_8:
-  if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT))
- _mesa_pack_uint_rgba_row(MESA_FORMAT_A8B8G8R8_UNORM, n, (void 
*)rgba[0], (void *)dstAddr);
-  else if 

[Mesa-dev] [PATCH 10/29] mesa: Add RGBA to Luminance conversion helpers

2014-11-18 Thread Iago Toral Quiroga
For glReadPixels with a Luminance destination format we compute luminance
values from RGBA as L=R+G+B. This, however, requires ad-hoc implementation,
since pack/unpack functions or _mesa_swizzle_and_convert won't do this
(and thus, neither will _mesa_format_convert). This patch adds helpers
to do this computation so they can be used to support conversion to luminance
formats.

The current implementation of glReadPixels does this computation as part
of the span functions in pack.c (see _mesa_pack_rgba_span_float), that do
this together with other things like type conversion, etc. We do not want
to use these functions but use _mesa_format_convert instead (later patches
will remove the color span functions), so we need to extract this functionality
as helpers.
---
 src/mesa/main/pack.c | 63 
 src/mesa/main/pack.h |  9 
 2 files changed, 72 insertions(+)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index de6ab27..fa4046c 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -4334,4 +4334,67 @@ _mesa_rebase_rgba_uint(GLuint n, GLuint rgba[][4], 
GLenum baseFormat)
}
 }
 
+void
+_mesa_pack_luminance_from_rgba_float(GLuint n, GLfloat rgba[][4],
+ GLvoid *dstAddr, GLenum dst_format,
+ GLbitfield transferOps)
+{
+   int i;
+   GLfloat *dst = (GLfloat *) dstAddr;
+
+   switch (dst_format) {
+   case GL_LUMINANCE:
+  if (transferOps  IMAGE_CLAMP_BIT) {
+ for (i = 0; i  n; i++) {
+GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
+dst[i] = CLAMP(sum, 0.0F, 1.0F);
+ }
+  } else {
+ for (i = 0; i  n; i++) {
+dst[i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
+ }
+  }
+  return;
+   case GL_LUMINANCE_ALPHA:
+  if (transferOps  IMAGE_CLAMP_BIT) {
+ for (i = 0; i  n; i++) {
+GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
+dst[2*i] = CLAMP(sum, 0.0F, 1.0F);
+dst[2*i+1] = rgba[i][ACOMP];
+ }
+  } else {
+ for (i = 0; i  n; i++) {
+dst[2*i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
+dst[2*i+1] = rgba[i][ACOMP];
+ }
+  }
+  return;
+   default:
+  assert(!Unsupported format);
+   }
+}
+
+void
+_mesa_pack_luminance_from_rgba_integer(GLuint n, GLuint rgba[][4],
+   GLvoid *dstAddr, GLenum dst_format)
+{
+   int i;
+   GLuint *dst = (GLuint *) dstAddr;
+
+   switch (dst_format) {
+   case GL_LUMINANCE:
+  for (i = 0; i  n; i++) {
+ dst[i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
+  }
+  return;
+   case GL_LUMINANCE_ALPHA:
+  for (i = 0; i  n; i++) {
+ dst[2*i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
+ dst[2*i+1] = rgba[i][ACOMP];
+  }
+  return;
+   default:
+  assert(!Unsupported format);
+   }
+}
 
diff --git a/src/mesa/main/pack.h b/src/mesa/main/pack.h
index 2173b65..2783f23 100644
--- a/src/mesa/main/pack.h
+++ b/src/mesa/main/pack.h
@@ -155,4 +155,13 @@ _mesa_rebase_rgba_float(GLuint n, GLfloat rgba[][4], 
GLenum baseFormat);
 extern void
 _mesa_rebase_rgba_uint(GLuint n, GLuint rgba[][4], GLenum baseFormat);
 
+extern void
+_mesa_pack_luminance_from_rgba_float(GLuint n, GLfloat rgba[][4],
+ GLvoid *dstAddr, GLenum dst_format,
+ GLbitfield transferOps);
+
+extern void
+_mesa_pack_luminance_from_rgba_integer(GLuint n, GLuint rgba[][4],
+   GLvoid *dstAddr, GLenum dst_format);
+
 #endif
-- 
1.9.1

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


[Mesa-dev] [PATCH 02/29] mesa: Set normalized=true for float array formats.

2014-11-18 Thread Iago Toral Quiroga
In order to check if a format is normalized Mesa does something like this:
normalized = !_mesa_is_enum_format_integer(srcFormat);

So all float types will set normalized to true. Since our mesa_array_format
includes a normalized flag for each type we want to make it consistent with
this.
---
 src/mesa/main/format_info.py | 3 ++-
 src/mesa/main/format_utils.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/format_info.py b/src/mesa/main/format_info.py
index 315767d..d4bc276 100644
--- a/src/mesa/main/format_info.py
+++ b/src/mesa/main/format_info.py
@@ -220,9 +220,10 @@ for fmat in formats:
print '  {{ {0} }},'.format(', '.join(map(str, fmat.swizzle)))
if fmat.is_array() and fmat.colorspace in ('rgb', 'srgb'):
   chan = fmat.array_element()
+  norm = chan.norm or chan.type == parser.FLOAT
   print '   {0} ,'.format(', '.join([
  get_array_format_datatype(chan),
- str(int(chan.norm)),
+ str(int(norm)),
  str(len(fmat.channels)),
  str(fmat.swizzle[0]),
  str(fmat.swizzle[1]),
diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index c3815cb..1d65f2b 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -30,7 +30,7 @@
 
 mesa_array_format RGBA_FLOAT = {{
MESA_ARRAY_FORMAT_TYPE_FLOAT,
-   0,
+   1,
4,
0, 1, 2, 3,
0, 1
-- 
1.9.1

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


[Mesa-dev] [PATCH 11/29] mesa: Add helpers to extract GL_COLOR_INDEX to RGBA float/ubyte

2014-11-18 Thread Iago Toral Quiroga
We only use _mesa_make_temp_ubyte_image in texstore.c to convert
GL_COLOR_INDEX to RGBA, but this helper does more stuff than this.
All uses of this helper can be replaced with calls to
_mesa_format_convert except for this GL_COLOR_INDEX conversion.

This patch extracts the GL_COLOR_INDEX to RGBA logic to a separate
helper so we can use that instead from texstore.c.

In future patches we will replace all remaining calls to
_mesa_make_temp_ubyte_image in the repository (related to compressed
formats) with calls to _mesa_format_convert so we can remove
_mesa_make_temp_ubyte_image and related functions.
---
 src/mesa/main/pack.c | 78 
 src/mesa/main/pack.h | 14 ++
 2 files changed, 92 insertions(+)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index fa4046c..aabe6a9 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -4398,3 +4398,81 @@ _mesa_pack_luminance_from_rgba_integer(GLuint n, GLuint 
rgba[][4],
}
 }
 
+GLfloat *
+_mesa_unpack_color_index_to_rgba_float(struct gl_context *ctx, GLuint dims,
+   const void *src, GLenum srcFormat, 
GLenum srcType,
+   int srcWidth, int srcHeight, int 
srcDepth,
+   const struct gl_pixelstore_attrib 
*srcPacking,
+   GLbitfield transferOps)
+{
+   int count = srcWidth * srcHeight;
+   GLuint *indexes = malloc(count * sizeof(GLuint));
+   if (!indexes) {
+  _mesa_error(ctx, GL_OUT_OF_MEMORY, pixel unpacking);
+  return NULL;
+   }
+
+   GLfloat *rgba = malloc(4 * count * srcDepth * sizeof(GLfloat));
+   if (!rgba) {
+  free(indexes);
+  _mesa_error(ctx, GL_OUT_OF_MEMORY, pixel unpacking);
+  return NULL;
+   }
+
+   /* Convert indexes to RGBA float */
+   GLfloat *dstPtr = rgba;
+   for (int img = 0; img  srcDepth; img++) {
+  const GLubyte *srcPtr =
+ (const GLubyte *) _mesa_image_address(dims, srcPacking, src,
+   srcWidth, srcHeight,
+   srcFormat, srcType,
+   img, 0, 0);
+
+  extract_uint_indexes(count, indexes, srcFormat, srcType, srcPtr, 
srcPacking);
+
+  if (transferOps  IMAGE_SHIFT_OFFSET_BIT)
+ _mesa_shift_and_offset_ci(ctx, count, indexes);
+
+  _mesa_map_ci_to_rgba(ctx, count, indexes, (float (*)[4])dstPtr);
+
+  /* Don't do RGBA scale/bias or RGBA-RGBA mapping if starting
+   * with color indexes.
+   */
+  transferOps = ~(IMAGE_SCALE_BIAS_BIT | IMAGE_MAP_COLOR_BIT);
+  _mesa_apply_rgba_transfer_ops(ctx, transferOps, count, (float 
(*)[4])dstPtr);
+
+  dstPtr += srcHeight * srcWidth * 4;
+   }
+
+   free(indexes);
+
+   return rgba;
+}
+
+GLubyte *
+_mesa_unpack_color_index_to_rgba_ubyte(struct gl_context *ctx, GLuint dims,
+   const void *src, GLenum srcFormat, 
GLenum srcType,
+   int srcWidth, int srcHeight, int 
srcDepth,
+   const struct gl_pixelstore_attrib 
*srcPacking,
+   GLbitfield transferOps)
+{
+   transferOps |= IMAGE_CLAMP_BIT;
+   GLfloat *rgba =
+  _mesa_unpack_color_index_to_rgba_float(ctx, dims,
+ src, srcFormat, srcType,
+ srcWidth, srcHeight, srcDepth,
+ srcPacking, transferOps);
+
+   int count = srcWidth * srcHeight * srcDepth;
+   GLubyte *dst = malloc(count * 4 * sizeof(GLubyte));
+   for (int i = 0; i  count; i++) {
+  CLAMPED_FLOAT_TO_UBYTE(dst[i * 4 + 0], rgba[i * 4 + 0]);
+  CLAMPED_FLOAT_TO_UBYTE(dst[i * 4 + 1], rgba[i * 4 + 1]);
+  CLAMPED_FLOAT_TO_UBYTE(dst[i * 4 + 2], rgba[i * 4 + 2]);
+  CLAMPED_FLOAT_TO_UBYTE(dst[i * 4 + 3], rgba[i * 4 + 3]);
+   }
+
+   free(rgba);
+
+   return dst;
+}
diff --git a/src/mesa/main/pack.h b/src/mesa/main/pack.h
index 2783f23..5a532e0 100644
--- a/src/mesa/main/pack.h
+++ b/src/mesa/main/pack.h
@@ -164,4 +164,18 @@ extern void
 _mesa_pack_luminance_from_rgba_integer(GLuint n, GLuint rgba[][4],
GLvoid *dstAddr, GLenum dst_format);
 
+extern GLfloat *
+_mesa_unpack_color_index_to_rgba_float(struct gl_context *ctx, GLuint dims,
+   const void *src, GLenum srcFormat, 
GLenum srcType,
+   int srcWidth, int srcHeight, int 
srcDepth,
+   const struct gl_pixelstore_attrib 
*srcPacking,
+   GLbitfield transferOps);
+
+extern GLubyte *
+_mesa_unpack_color_index_to_rgba_ubyte(struct gl_context *ctx, GLuint dims,
+   const void *src, GLenum srcFormat, 
GLenum srcType,

[Mesa-dev] [PATCH 15/29] mesa: Let _mesa_get_format_base_format also handle mesa_array_format

2014-11-18 Thread Iago Toral Quiroga
When we needed the base format for a mesa_array_format we had to find
the matching mesa_format first. This is expensive because it requires
to loop through all existing mesa formats until we find the right match.

We can resolve the base format of an array format directly by looking
at its swizzle information. Also, we can have _mesa_get_format_base_format
accept an uint32_t which can pack either a mesa_format or a mesa_array_format
and resolve the base format for either type. This way clients do not need to
check if they have a mesa_format or a mesa_array_format and call different
functions depending on the case.

Another reason to resolve the base format for array formats directly is that
we don't have matching mesa_format enums for every possible array format, so
for some GL format/type combinations we will produce array formats that don't
have a corresponding mesa format, in which case we would not be able to
find the base format. Example format=GL_RGB, type=GL_UNSIGNED_SHORT. This type
would map to something like MESA_FORMAT_RGB_UNORM16, but we don't have that.
---
 src/mesa/main/format_utils.c | 12 ++--
 src/mesa/main/formats.c  | 69 ++--
 src/mesa/main/formats.h  |  2 +-
 src/mesa/main/readpix.c  |  7 +
 4 files changed, 71 insertions(+), 19 deletions(-)

diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index 97c125c..6648876 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -341,12 +341,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, 
size_t dst_stride,
 * this path in these scenarios but in the future we may want to enable
 * it for specific combinations that are known to work.
 */
-   mesa_format dst_mesa_format;
-   if (dst_format  MESA_ARRAY_FORMAT_BIT)
-  dst_mesa_format = _mesa_format_from_array_format(dst_format);
-   else
-  dst_mesa_format = dst_format;
-   if (_mesa_get_format_base_format(dst_mesa_format) == dst_internal_format) {
+   if (_mesa_get_format_base_format(dst_format) == dst_internal_format) {
   /* Handle the cases where we can directly unpack */
   if (!(src_format  MESA_ARRAY_FORMAT_BIT)) {
  if (dst_array_format.as_uint == RGBA_FLOAT.as_uint) {
@@ -449,7 +444,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, 
size_t dst_stride,
* by computing the swizzle transform src-rgba-base-rgba-dst instead
* of src-rgba-dst.
*/
-  if (dst_internal_format != 
_mesa_get_format_base_format(dst_mesa_format)) {
+  if (dst_internal_format != _mesa_get_format_base_format(dst_format)) {
  /* Compute src2rgba as src-rgba-base-rgba */
  uint8_t rgba2base[4], base2rgba[4], swizzle[4];
  _mesa_compute_component_mapping(GL_RGBA, dst_internal_format, 
rgba2base);
@@ -593,8 +588,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, 
size_t dst_stride,
   */
  GLubyte rgba2base[4], base2rgba[4], map[4];
  bool need_convert = false;
- if (dst_internal_format !=
- _mesa_get_format_base_format(dst_mesa_format)) {
+ if (dst_internal_format != _mesa_get_format_base_format(dst_format)) {
 _mesa_compute_component_mapping(GL_RGBA, dst_internal_format,
 base2rgba);
 _mesa_compute_component_mapping(dst_internal_format, GL_RGBA,
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 7464d89..8917f6d 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -214,17 +214,80 @@ _mesa_get_format_datatype(mesa_format format)
return info-DataType;
 }
 
+static GLenum
+get_base_format_for_array_format(mesa_array_format format)
+{
+   switch (format.num_channels) {
+   case 4:
+  /* FIXME: RGBX formats have 4 channels, but their base format is GL_RGB.
+   * This is not really a problem for now because we only create array
+   * formats from GL format/type combinations, and these cannot specify
+   * RGBX formats.
+   */
+  return GL_RGBA;
+   case 3:
+  return GL_RGB;
+   case 2:
+  if (format.swizzle_x == 0 
+  format.swizzle_y == 0 
+  format.swizzle_z == 0 
+  format.swizzle_w == 1)
+ return GL_LUMINANCE_ALPHA;
+  if (format.swizzle_x == 1 
+  format.swizzle_y == 1 
+  format.swizzle_z == 1 
+  format.swizzle_w == 0)
+ return GL_LUMINANCE_ALPHA;
+  if (format.swizzle_x == 0 
+  format.swizzle_y == 1 
+  format.swizzle_z == 4 
+  format.swizzle_w == 5)
+ return GL_RG;
+  if (format.swizzle_x == 1 
+  format.swizzle_y == 0 
+  format.swizzle_z == 4 
+  format.swizzle_w == 5)
+ return GL_RG;
+  break;
+   case 1:
+  if (format.swizzle_x == 0 
+  format.swizzle_y == 0 
+  format.swizzle_z == 0 
+  format.swizzle_w == 5)
+ 

[Mesa-dev] [PATCH 29/29] mesa: Remove _mesa_pack_int_rgba_row() and auxiliary functions

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

These are no longer used.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
---
 src/mesa/main/format_pack.c.mako | 121 ---
 src/mesa/main/format_pack.h  |   4 --
 2 files changed, 125 deletions(-)

diff --git a/src/mesa/main/format_pack.c.mako b/src/mesa/main/format_pack.c.mako
index c5ad623..7433bcd 100644
--- a/src/mesa/main/format_pack.c.mako
+++ b/src/mesa/main/format_pack.c.mako
@@ -231,99 +231,6 @@ pack_uint_${f.short_name()}(const GLuint src[4], void *dst)
 }
 %endfor
 
-/* int packing functions */
-
-%for f in rgb_formats:
-   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
-  % continue %
-   %elif f.is_compressed():
-  % continue %
-   %endif
-
-static inline void
-pack_int_${f.short_name()}(const GLint src[4], void *dst)
-{
-   %for (i, c) in enumerate(f.channels):
-  % i = f.swizzle.inverse()[i] %
-  %if c.type == 'x':
- % continue %
-  %endif
-
-  ${channel_datatype(c)} ${c.name} =
-  %if not f.is_normalized():
- %if c.type == parser.FLOAT and c.size == 32:
-INT_TO_FLOAT(src[${i}]);
- %elif c.type == parser.FLOAT and c.size == 16:
-_mesa_float_to_half(INT_TO_FLOAT(src[${i}]));
- %else:
-(${channel_datatype(c)}) src[${i}];
- %endif
-  %elif c.type == parser.UNSIGNED:
- %if f.colorspace == 'srgb' and c.name in 'rgb':
-util_format_linear_to_srgb_8unorm(src[${i}]);
- %else:
-CLAMP(src[${i}], 0, MAX_UINT(${c.size}));
- %endif
-  %elif c.type == parser.SIGNED:
- CLAMP(src[${i}], 0,  MAX_UINT(${c.size}));
-  %elif c.type == parser.FLOAT:
- %if c.size == 32:
-_mesa_snorm_to_float(src[${i}], 8);
- %elif c.size == 16:
-_mesa_snorm_to_half(src[${i}], 8);
- %else:
-% assert False %
- %endif
-  %else:
- % assert False %
-  %endif
-   %endfor
-
-   %if f.layout == parser.ARRAY:
-  ${format_datatype(f)} *d = (${format_datatype(f)} *)dst;
-  %for (i, c) in enumerate(f.channels):
- %if c.type == 'x':
-% continue %
- %endif
- d[${i}] = ${c.name};
-  %endfor
-   %elif f.layout == parser.PACKED:
-  ${format_datatype(f)} d = 0;
-  %for (i, c) in enumerate(f.channels):
- %if c.type == 'x':
-% continue %
- %endif
- d |= PACK(${c.name}, ${c.shift}, ${c.size});
-  %endfor
-  (*(${format_datatype(f)} *)dst) = d;
-   %else:
-  % assert False %
-   %endif
-}
-%endfor
-
-static inline void
-pack_int_r9g9b9e5_float(const GLint src[4], void *dst)
-{
-   GLuint *d = (GLuint *) dst;
-   GLfloat rgb[3];
-   rgb[0] = _mesa_snorm_to_float(src[RCOMP], 8);
-   rgb[1] = _mesa_snorm_to_float(src[GCOMP], 8);
-   rgb[2] = _mesa_snorm_to_float(src[BCOMP], 8);
-   *d = float3_to_rgb9e5(rgb);
-}
-
-static inline void
-pack_int_r11g11b10_float(const GLint src[4], void *dst)
-{
-   GLuint *d = (GLuint *) dst;
-   GLfloat rgb[3];
-   rgb[0] = _mesa_snorm_to_float(src[RCOMP], 8);
-   rgb[1] = _mesa_snorm_to_float(src[GCOMP], 8);
-   rgb[2] = _mesa_snorm_to_float(src[BCOMP], 8);
-   *d = float3_to_r11g11b10f(rgb);
-}
-
 /* float packing functions */
 
 %for f in rgb_formats:
@@ -519,34 +426,6 @@ _mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
 }
 
 /**
- * Pack a row of GLint rgba[4] values to the destination.
- */
-void
-_mesa_pack_int_rgba_row(mesa_format format, GLuint n,
-  const GLint src[][4], void *dst)
-{
-   GLuint i;
-   GLubyte *d = dst;
-
-   switch (format) {
-%for f in rgb_formats:
-   %if f.is_compressed():
-  % continue %
-   %endif
-
-   case ${f.name}:
-  for (i = 0; i  n; ++i) {
- pack_int_${f.short_name()}(src[i], d);
- d += ${f.block_size() / 8};
-  }
-  break;
-%endfor
-   default:
-  assert(!Invalid format);
-   }
-}
-
-/**
  * Pack a row of GLfloat rgba[4] values to the destination.
  */
 void
diff --git a/src/mesa/main/format_pack.h b/src/mesa/main/format_pack.h
index 6087fc3..aa7113e 100644
--- a/src/mesa/main/format_pack.h
+++ b/src/mesa/main/format_pack.h
@@ -69,10 +69,6 @@ _mesa_get_pack_ubyte_stencil_func(mesa_format format);
 
 
 extern void
-_mesa_pack_int_rgba_row(mesa_format format, GLuint n,
-  const GLint src[][4], void *dst);
-
-extern void
 _mesa_pack_float_rgba_row(mesa_format format, GLuint n,
   const GLfloat src[][4], void *dst);
 
-- 
1.9.1

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


[Mesa-dev] [PATCH 27/29] mesa: Remove _mesa_pack_rgba_span_float and tmp_pack.h

2014-11-18 Thread Iago Toral Quiroga
_mesa_pack_rgba_span_float was the last of the color span functions
and we have replaced all calls to it with calls to _mesa_format_convert,
so we can remove it together with tmp_pack.h which was used to
generate the pack functions for multiple types that were used from
the various color span functions that have been removed.
---
 src/mesa/main/pack.c | 403 ---
 src/mesa/main/pack.h |   8 -
 src/mesa/main/pack_tmp.h | 196 ---
 3 files changed, 607 deletions(-)
 delete mode 100644 src/mesa/main/pack_tmp.h

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index e45bfb1..49b2998 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -232,409 +232,6 @@ _mesa_pack_bitmap( GLint width, GLint height, const 
GLubyte *source,
 }
 
 
-/**
- * For small integer types, return the min and max possible values.
- * Used for clamping floats to unscaled integer types.
- * \return GL_TRUE if type is handled, GL_FALSE otherwise.
- */
-static GLboolean
-get_type_min_max(GLenum type, GLfloat *min, GLfloat *max)
-{
-   switch (type) {
-   case GL_BYTE:
-  *min = -128.0;
-  *max = 127.0;
-  return GL_TRUE;
-   case GL_UNSIGNED_BYTE:
-  *min = 0.0;
-  *max = 255.0;
-  return GL_TRUE;
-   case GL_SHORT:
-  *min = -32768.0;
-  *max = 32767.0;
-  return GL_TRUE;
-   case GL_UNSIGNED_SHORT:
-  *min = 0.0;
-  *max = 65535.0;
-  return GL_TRUE;
-   default:
-  return GL_FALSE;
-   }
-}
-
-/* Customization of float packing.
- */
-#define SRC_TYPE GLfloat
-
-#define DST_TYPE GLuint
-#define FLOAT_SRC_CONVERT(x) FLOAT_TO_UINT(x)
-#define SRC_CONVERT(x) (GLuint) x
-#define FN_NAME pack_uint_from_float_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLint
-#define FLOAT_SRC_CONVERT(x) FLOAT_TO_INT(x)
-#define SRC_CONVERT(x) (GLint) x
-#define FN_NAME pack_int_from_float_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLshort
-#define FLOAT_SRC_CONVERT(x) FLOAT_TO_SHORT_TEX(x)
-#define SRC_CONVERT(x) (GLshort) x
-#define FN_NAME pack_short_from_float_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLubyte
-#define FLOAT_SRC_CONVERT(x) FLOAT_TO_UBYTE(x)
-#define SRC_CONVERT(x) (GLubyte) x
-#define FN_NAME pack_ubyte_from_float_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLbyte
-#define FLOAT_SRC_CONVERT(x) FLOAT_TO_BYTE_TEX(x)
-#define SRC_CONVERT(x) (GLbyte) x
-#define FN_NAME pack_byte_from_float_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLfloat
-#define FLOAT_SRC_CONVERT(x) x
-#define SRC_CONVERT(x) x
-#define FN_NAME pack_float_from_float_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLhalfARB
-#define FLOAT_SRC_CONVERT(x) _mesa_float_to_half(x)
-#define FN_NAME pack_half_float_from_float_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#undef SRC_TYPE
-
-/**
- * Used to pack an array [][4] of RGBA float colors as specified
- * by the dstFormat, dstType and dstPacking.  Used by glReadPixels.
- * Historically, the RGBA values were in [0,1] and rescaled to fit
- * into GLubytes, etc.  But with new integer formats, the RGBA values
- * may have any value and we don't always rescale when converting to
- * integers.
- *
- * Note: the rgba values will be modified by this function when any pixel
- * transfer ops are enabled.
- */
-void
-_mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4],
-   GLenum dstFormat, GLenum dstType,
-   GLvoid *dstAddr,
-   const struct gl_pixelstore_attrib *dstPacking,
-   GLbitfield transferOps)
-{
-   GLfloat *luminance;
-   const GLint comps = _mesa_components_in_format(dstFormat);
-   const GLboolean intDstFormat = _mesa_is_enum_format_integer(dstFormat);
-   GLuint i;
-   uint32_t dstMesaFormat;
-
-   if (dstFormat == GL_LUMINANCE ||
-   dstFormat == GL_LUMINANCE_ALPHA ||
-   dstFormat == GL_LUMINANCE_INTEGER_EXT ||
-   dstFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT) {
-  luminance = malloc(n * sizeof(GLfloat));
-  if (!luminance) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, pixel packing);
- return;
-  }
-   }
-   else {
-  luminance = NULL;
-   }
-
-   /* EXT_texture_integer specifies no transfer ops on integer
-* types in the resolved issues section. Just set them to 0
-* for integer surfaces.
-*/
-   if (intDstFormat)
-  transferOps = 0;
-
-   if (transferOps) {
-  

[Mesa-dev] [PATCH 12/29] mesa: Fix RGBA8888_UINT direct unpack path in _mesa_format_convert.

2014-11-18 Thread Iago Toral Quiroga
A direct unpack to this format from a signed format won't clamp so we should
not resolve converts of this kind via the unpack fast path. These scenarios
will be handled properly by mesa_swizzle_and_convert path.
---
 src/mesa/main/format_utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index 34c90d9..97c125c 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -367,7 +367,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, 
size_t dst_stride,
 }
 return;
  } else if (dst_array_format.as_uint == RGBA_UINT.as_uint 
-_mesa_is_format_integer_color(src_format)) {
+_mesa_is_format_integer_color(src_format) 
+_mesa_is_format_unsigned(src_format)) {
 for (row = 0; row  height; ++row) {
_mesa_unpack_uint_rgba_row(src_format, width,
   src, (uint32_t (*)[4])dst);
-- 
1.9.1

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


[Mesa-dev] [PATCH 25/29] mesa: Remove _mesa_unpack_color_span_float

2014-11-18 Thread Iago Toral Quiroga
And various helper functions that went unused after removing it.
---
 src/mesa/main/pack.c | 1033 --
 src/mesa/main/pack.h |9 -
 2 files changed, 1042 deletions(-)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 0d77c4e..e45bfb1 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -53,8 +53,6 @@
 #include pixeltransfer.h
 #include imports.h
 #include glformats.h
-#include ../../gallium/auxiliary/util/u_format_rgb9e5.h
-#include ../../gallium/auxiliary/util/u_format_r11g11b10f.h
 #include format_utils.h
 #include format_pack.h
 
@@ -235,100 +233,6 @@ _mesa_pack_bitmap( GLint width, GLint height, const 
GLubyte *source,
 
 
 /**
- * Get indexes of color components for a basic color format, such as
- * GL_RGBA, GL_RED, GL_LUMINANCE_ALPHA, etc.  Return -1 for indexes
- * that do not apply.
- */
-static void
-get_component_indexes(GLenum format,
-  GLint *redIndex,
-  GLint *greenIndex,
-  GLint *blueIndex,
-  GLint *alphaIndex,
-  GLint *luminanceIndex,
-  GLint *intensityIndex)
-{
-   *redIndex = -1;
-   *greenIndex = -1;
-   *blueIndex = -1;
-   *alphaIndex = -1;
-   *luminanceIndex = -1;
-   *intensityIndex = -1;
-
-   switch (format) {
-   case GL_LUMINANCE:
-   case GL_LUMINANCE_INTEGER_EXT:
-  *luminanceIndex = 0;
-  break;
-   case GL_LUMINANCE_ALPHA:
-   case GL_LUMINANCE_ALPHA_INTEGER_EXT:
-  *luminanceIndex = 0;
-  *alphaIndex = 1;
-  break;
-   case GL_INTENSITY:
-  *intensityIndex = 0;
-  break;
-   case GL_RED:
-   case GL_RED_INTEGER_EXT:
-  *redIndex = 0;
-  break;
-   case GL_GREEN:
-   case GL_GREEN_INTEGER_EXT:
-  *greenIndex = 0;
-  break;
-   case GL_BLUE:
-   case GL_BLUE_INTEGER_EXT:
-  *blueIndex = 0;
-  break;
-   case GL_ALPHA:
-   case GL_ALPHA_INTEGER_EXT:
-  *alphaIndex = 0;
-  break;
-   case GL_RG:
-   case GL_RG_INTEGER:
-  *redIndex = 0;
-  *greenIndex = 1;
-  break;
-   case GL_RGB:
-   case GL_RGB_INTEGER_EXT:
-  *redIndex = 0;
-  *greenIndex = 1;
-  *blueIndex = 2;
-  break;
-   case GL_BGR:
-   case GL_BGR_INTEGER_EXT:
-  *blueIndex = 0;
-  *greenIndex = 1;
-  *redIndex = 2;
-  break;
-   case GL_RGBA:
-   case GL_RGBA_INTEGER_EXT:
-  *redIndex = 0;
-  *greenIndex = 1;
-  *blueIndex = 2;
-  *alphaIndex = 3;
-  break;
-   case GL_BGRA:
-   case GL_BGRA_INTEGER:
-  *redIndex = 2;
-  *greenIndex = 1;
-  *blueIndex = 0;
-  *alphaIndex = 3;
-  break;
-   case GL_ABGR_EXT:
-  *redIndex = 3;
-  *greenIndex = 2;
-  *blueIndex = 1;
-  *alphaIndex = 0;
-  break;
-   default:
-  assert(0  bad format in get_component_indexes());
-   }
-}
-
-
-
-/**
  * For small integer types, return the min and max possible values.
  * Used for clamping floats to unscaled integer types.
  * \return GL_TRUE if type is handled, GL_FALSE otherwise.
@@ -964,743 +868,6 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
 }
 
 
-/**
- * Return source/dest RGBA indexes for unpacking pixels.
- */
-static void
-get_component_mapping(GLenum format,
-  GLint *rSrc,
-  GLint *gSrc,
-  GLint *bSrc,
-  GLint *aSrc,
-  GLint *rDst,
-  GLint *gDst,
-  GLint *bDst,
-  GLint *aDst)
-{
-   switch (format) {
-   case GL_RED:
-   case GL_RED_INTEGER_EXT:
-  *rSrc = 0;
-  *gSrc = *bSrc = *aSrc = -1;
-  break;
-   case GL_GREEN:
-   case GL_GREEN_INTEGER_EXT:
-  *gSrc = 0;
-  *rSrc = *bSrc = *aSrc = -1;
-  break;
-   case GL_BLUE:
-   case GL_BLUE_INTEGER_EXT:
-  *bSrc = 0;
-  *rSrc = *gSrc = *aSrc = -1;
-  break;
-   case GL_ALPHA:
-   case GL_ALPHA_INTEGER_EXT:
-  *rSrc = *gSrc = *bSrc = -1;
-  *aSrc = 0;
-  break;
-   case GL_LUMINANCE:
-   case GL_LUMINANCE_INTEGER_EXT:
-  *rSrc = *gSrc = *bSrc = 0;
-  *aSrc = -1;
-  break;
-   case GL_LUMINANCE_ALPHA:
-   case GL_LUMINANCE_ALPHA_INTEGER_EXT:
-  *rSrc = *gSrc = *bSrc = 0;
-  *aSrc = 1;
-  break;
-   case GL_INTENSITY:
-  *rSrc = *gSrc = *bSrc = *aSrc = 0;
-  break;
-   case GL_RG:
-   case GL_RG_INTEGER:
-  *rSrc = 0;
-  *gSrc = 1;
-  *bSrc = -1;
-  *aSrc = -1;
-  *rDst = 0;
-  *gDst = 1;
-  *bDst = 2;
-  *aDst = 3;
-  break;
-   case GL_RGB:
-   case GL_RGB_INTEGER:
-  *rSrc = 0;
-  *gSrc = 1;
-  *bSrc = 2;
-  *aSrc = -1;
-  *rDst = 0;
-  *gDst = 1;
-  *bDst = 2;
-  *aDst = 3;
-  break;
-   case GL_BGR:
-   case GL_BGR_INTEGER:
-  *rSrc = 2;
-  *gSrc = 1;
-  *bSrc = 0;
-  *aSrc = -1;
-  *rDst = 2;
-  *gDst = 1;
-  *bDst = 0;
-  *aDst = 3;
-  break;
-   case GL_RGBA:
- 

[Mesa-dev] [PATCH 16/29] mesa: use master conversion function to implement get_tex_rgba_uncompressed()

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

This covers glGetTexImage for uncompressed color formats.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
Signed-off-by: Eduardo Lima Mitev el...@igalia.com
---
 src/mesa/main/texgetimage.c | 170 ++--
 1 file changed, 117 insertions(+), 53 deletions(-)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index cb5f793..84cd53e 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -45,7 +45,8 @@
 #include texgetimage.h
 #include teximage.h
 #include texstore.h
-
+#include format_utils.h
+#include pixeltransfer.h
 
 
 /**
@@ -380,20 +381,10 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
GLenum rebaseFormat = GL_NONE;
GLuint height = texImage-Height;
GLuint depth = texImage-Depth;
-   GLuint img, row;
-   GLfloat (*rgba)[4];
-   GLuint (*rgba_uint)[4];
-   GLboolean tex_is_integer = 
_mesa_is_format_integer_color(texImage-TexFormat);
-   GLboolean tex_is_uint = _mesa_is_format_unsigned(texImage-TexFormat);
+   GLuint img;
GLenum texBaseFormat = _mesa_get_format_base_format(texImage-TexFormat);
 
-   /* Allocate buffer for one row of texels */
-   rgba = malloc(4 * width * sizeof(GLfloat));
-   rgba_uint = (GLuint (*)[4]) rgba;
-   if (!rgba) {
-  _mesa_error(ctx, GL_OUT_OF_MEMORY, glGetTexImage());
-  return;
-   }
+   assert (depth = 1 || dimensions  2);
 
if (texImage-TexObject-Target == GL_TEXTURE_1D_ARRAY) {
   depth = height;
@@ -413,9 +404,7 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
  texImage-_BaseFormat == GL_RGB ||
  texImage-_BaseFormat == GL_RG) 
 (destBaseFormat == GL_LUMINANCE ||
- destBaseFormat == GL_LUMINANCE_ALPHA ||
- destBaseFormat == GL_LUMINANCE_INTEGER_EXT ||
- destBaseFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT)) {
+ destBaseFormat == GL_LUMINANCE_ALPHA)) {
   /* If we're reading back an RGB(A) texture as luminance then we need
* to return L=tex(R).  Note, that's different from glReadPixels which
* returns L=R+G+B.
@@ -467,6 +456,22 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
   }
}
 
+   /* Describe the dst format */
+   GLboolean dst_is_integer = _mesa_is_enum_format_integer(format);
+   uint32_t dst_format = _mesa_format_from_format_and_type(format, type);
+   int dst_stride = _mesa_image_row_stride(ctx-Pack, width, format, type);
+
+   /* Since _mesa_format_convert does not handle transferOps we need to handle
+* them before we call the function. This requires to convert to RGBA float
+* first so we can call _mesa_apply_rgba_transfer_ops. If the dst format is
+* integer we can ignore transferOps.
+*
+* Some source formats (Luminance) will also require to be rebased to obtain
+* the expected results and this also requires to convert to RGBA first.
+*/
+   assert(!transferOps || (transferOps  !dst_is_integer));
+   bool needs_rgba = (transferOps || rebaseFormat != GL_NONE);
+
for (img = 0; img  depth; img++) {
   GLubyte *srcMap;
   GLint rowstride;
@@ -475,46 +480,105 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
   ctx-Driver.MapTextureImage(ctx, texImage, img,
   0, 0, width, height, GL_MAP_READ_BIT,
   srcMap, rowstride);
-  if (srcMap) {
- for (row = 0; row  height; row++) {
-const GLubyte *src = srcMap + row * rowstride;
-void *dest = _mesa_image_address(dimensions, ctx-Pack, pixels,
- width, height, format, type,
- img, row, 0);
-
-   if (tex_is_integer) {
-  _mesa_unpack_uint_rgba_row(texFormat, width, src, rgba_uint);
-   if (rebaseFormat)
-  _mesa_rebase_rgba_uint(width, rgba_uint, rebaseFormat);
-   if (tex_is_uint) {
-  _mesa_pack_rgba_span_from_uints(ctx, width,
-  (GLuint (*)[4]) rgba_uint,
-  format, type, dest);
-   } else {
-  _mesa_pack_rgba_span_from_ints(ctx, width,
- (GLint (*)[4]) rgba_uint,
- format, type, dest);
-   }
-   } else {
-  _mesa_unpack_rgba_row(texFormat, width, src, rgba);
-   if (rebaseFormat)
-  _mesa_rebase_rgba_float(width, rgba, rebaseFormat);
-  _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
- format, type, dest,
- ctx-Pack, transferOps);
-   }
-}

[Mesa-dev] [PATCH 23/29] mesa: Remove (signed) integer pack and span functions.

2014-11-18 Thread Iago Toral Quiroga
These are no longer used now that we moved to _mesa_format_convert.
---
 src/mesa/main/pack.c | 225 ---
 src/mesa/main/pack.h |  12 ---
 2 files changed, 237 deletions(-)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index d89fc7b..0d77c4e 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -358,231 +358,6 @@ get_type_min_max(GLenum type, GLfloat *min, GLfloat *max)
}
 }
 
-/* Customization of unsigned integer packing.
- */
-#define SRC_TYPE GLuint
-
-#define DST_TYPE GLuint
-#define SRC_CONVERT(x) (x)
-#define FN_NAME pack_uint_from_uint_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLint
-#define SRC_CONVERT(x) MIN2(x, 0x7fff)
-#define FN_NAME pack_int_from_uint_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLushort
-#define SRC_CONVERT(x) MIN2(x, 0x)
-#define FN_NAME pack_ushort_from_uint_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLshort
-#define SRC_CONVERT(x) CLAMP((int)x, -32768, 32767)
-#define FN_NAME pack_short_from_uint_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLubyte
-#define SRC_CONVERT(x) MIN2(x, 0xff)
-#define FN_NAME pack_ubyte_from_uint_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLbyte
-#define SRC_CONVERT(x) CLAMP((int)x, -128, 127)
-#define FN_NAME pack_byte_from_uint_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FN_NAME
-
-#undef SRC_TYPE
-
-static void
-_pack_rgba_span_from_uints_problem(struct gl_context *ctx,
-   GLenum dstFormat, GLenum dstType)
-{
-   _mesa_problem(ctx,
- Unsupported type (%s) / format (%s) 
- in _mesa_pack_rgba_span_from_uints,
- _mesa_lookup_enum_by_nr(dstType),
- _mesa_lookup_enum_by_nr(dstFormat));
-}
-
-void
-_mesa_pack_rgba_span_from_uints(struct gl_context *ctx, GLuint n, GLuint 
rgba[][4],
-GLenum dstFormat, GLenum dstType,
-GLvoid *dstAddr)
-{
-   uint32_t dstMesaFormat;
-
-   switch(dstType) {
-   case GL_UNSIGNED_INT:
-  pack_uint_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
-  break;
-   case GL_INT:
-  pack_int_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
-  break;
-   case GL_UNSIGNED_SHORT:
-  pack_ushort_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
-  break;
-   case GL_SHORT:
-  pack_short_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
-  break;
-   case GL_UNSIGNED_BYTE:
-  pack_ubyte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
-  break;
-   case GL_BYTE:
-  pack_byte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, NULL, n);
-  break;
-   case GL_UNSIGNED_BYTE_3_3_2:
-   case GL_UNSIGNED_BYTE_2_3_3_REV:
-   case GL_UNSIGNED_SHORT_5_6_5:
-   case GL_UNSIGNED_SHORT_5_6_5_REV:
-   case GL_UNSIGNED_SHORT_4_4_4_4:
-   case GL_UNSIGNED_SHORT_4_4_4_4_REV:
-   case GL_UNSIGNED_SHORT_5_5_5_1:
-   case GL_UNSIGNED_SHORT_1_5_5_5_REV:
-   case GL_UNSIGNED_INT_8_8_8_8:
-   case GL_UNSIGNED_INT_8_8_8_8_REV:
-   case GL_UNSIGNED_INT_10_10_10_2:
-   case GL_UNSIGNED_INT_2_10_10_10_REV:
-  dstMesaFormat = _mesa_format_from_format_and_type(dstFormat, dstType);
-  if (!(dstMesaFormat  MESA_ARRAY_FORMAT_BIT)) {
- _mesa_pack_uint_rgba_row(dstMesaFormat, n, (void *)rgba[0], (void 
*)dstAddr);
- break;
-  } else {
- /* Fall through */
-  }
-   default:
-  _pack_rgba_span_from_uints_problem(ctx, dstFormat, dstType);
-  return;
-   }
-}
-
-/* Customization of signed integer packing.
- */
-#define SRC_TYPE GLint
-
-#define DST_TYPE GLuint
-#define SRC_CONVERT(x) MAX2(x, 0)
-#define FN_NAME pack_uint_from_int_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLushort
-#define SRC_CONVERT(x) MAX2(x, 0)
-#define FN_NAME pack_ushort_from_int_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLshort
-#define SRC_CONVERT(x) CLAMP(x, -0x8000, 0x7fff)
-#define FN_NAME pack_short_from_int_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLubyte
-#define SRC_CONVERT(x) MAX2(x, 0)
-#define FN_NAME pack_ubyte_from_int_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLbyte
-#define SRC_CONVERT(x) CLAMP(x, -0x80, 0x7f)
-#define FN_NAME pack_byte_from_int_rgba
-#include pack_tmp.h
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FN_NAME
-
-#undef SRC_TYPE
-
-static void
-_pack_rgba_span_from_ints_problem(struct gl_context *ctx,
-   GLenum dstFormat, GLenum dstType)
-{
-   

[Mesa-dev] [PATCH 09/29] mesa: Add _mesa_swap2_copy and _mesa_swap4_copy

2014-11-18 Thread Iago Toral Quiroga
We have _mesa_swap{2,4} but these do in-place byte-swapping only. The new
functions receive an extra parameter so we can swap bytes on a source
input array and store the results in a (possibly different) destination
array.

This is useful to implement byte-swapping in pixel uploads, since in this
case we need to swap bytes on the src data which is owned by the
application so we can't do an in-place byte swap.
---
 src/mesa/main/image.c | 25 +
 src/mesa/main/image.h | 10 --
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index 4ea5f04..9ad97c5 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -41,36 +41,45 @@
 
 
 /**
- * Flip the order of the 2 bytes in each word in the given array.
+ * Flip the order of the 2 bytes in each word in the given array (src) and
+ * store the result in another array (dst). For in-place byte-swapping this
+ * function can be called with the same array for src and dst.
  *
- * \param p array.
+ * \param dst the array where byte-swapped data will be stored.
+ * \param src the array with the source data we want to byte-swap.
  * \param n number of words.
  */
 void
-_mesa_swap2( GLushort *p, GLuint n )
+_mesa_swap2_copy( GLushort *dst, GLushort *src, GLuint n )
 {
GLuint i;
for (i = 0; i  n; i++) {
-  p[i] = (p[i]  8) | ((p[i]  8)  0xff00);
+  dst[i] = (src[i]  8) | ((src[i]  8)  0xff00);
}
 }
 
 
 
 /*
- * Flip the order of the 4 bytes in each word in the given array.
+ * Flip the order of the 4 bytes in each word in the given array (src) and
+ * store the result in another array (dst). For in-place byte-swapping this
+ * function can be called with the same array for src and dst.
+ *
+ * \param dst the array where byte-swapped data will be stored.
+ * \param src the array with the source data we want to byte-swap.
+ * \param n number of words.
  */
 void
-_mesa_swap4( GLuint *p, GLuint n )
+_mesa_swap4_copy( GLuint *dst, GLuint *src, GLuint n )
 {
GLuint i, a, b;
for (i = 0; i  n; i++) {
-  b = p[i];
+  b = src[i];
   a =  (b  24)
| ((b  8)  0xff00)
| ((b  8)  0xff)
| ((b  24)  0xff00);
-  p[i] = a;
+  dst[i] = a;
}
 }
 
diff --git a/src/mesa/main/image.h b/src/mesa/main/image.h
index abd84bf..79c6e68 100644
--- a/src/mesa/main/image.h
+++ b/src/mesa/main/image.h
@@ -33,10 +33,16 @@ struct gl_context;
 struct gl_pixelstore_attrib;
 
 extern void
-_mesa_swap2( GLushort *p, GLuint n );
+_mesa_swap2_copy( GLushort *dst, GLushort *src, GLuint n );
 
 extern void
-_mesa_swap4( GLuint *p, GLuint n );
+_mesa_swap4_copy( GLuint *dst, GLuint *src, GLuint n );
+
+static inline void
+_mesa_swap2( GLushort *p, GLuint n ) { _mesa_swap2_copy(p, p, n); }
+
+static inline void
+_mesa_swap4( GLuint *p, GLuint n ) { _mesa_swap4_copy(p, p, n); }
 
 extern GLintptr
 _mesa_image_offset( GLuint dimensions,
-- 
1.9.1

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


[Mesa-dev] [PATCH 04/29] mesa: Expose compute_component_mapping as _mesa_compute_component_mapping

2014-11-18 Thread Iago Toral Quiroga
This is necessary to handle conversions between array types where
the driver does not support the dst format requested by the client and
chooses a different format instead.

We will need this in _mesa_format_convert, so move it to format_utils.c,
prefix it with '_mesa_' and make it available to other files.
---
 src/mesa/main/format_utils.c | 198 +++
 src/mesa/main/format_utils.h |   3 +
 src/mesa/main/texstore.c | 216 ++-
 3 files changed, 210 insertions(+), 207 deletions(-)

diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index 56a3b8d..fc59e86 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -27,6 +27,7 @@
 #include macros.h
 #include format_pack.h
 #include format_unpack.h
+#include enums.h
 
 mesa_array_format RGBA_FLOAT = {{
MESA_ARRAY_FORMAT_TYPE_FLOAT,
@@ -102,6 +103,203 @@ gl_type_for_array_format_datatype(enum 
mesa_array_format_datatype type)
}
 }
 
+enum {
+   ZERO = 4,
+   ONE = 5
+};
+
+enum {
+   IDX_LUMINANCE = 0,
+   IDX_ALPHA,
+   IDX_INTENSITY,
+   IDX_LUMINANCE_ALPHA,
+   IDX_RGB,
+   IDX_RGBA,
+   IDX_RED,
+   IDX_GREEN,
+   IDX_BLUE,
+   IDX_BGR,
+   IDX_BGRA,
+   IDX_ABGR,
+   IDX_RG,
+   MAX_IDX
+};
+
+#define MAP1(x)   MAP4(x, ZERO, ZERO, ZERO)
+#define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
+#define MAP3(x,y,z)   MAP4(x, y, z, ZERO)
+#define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
+
+static const struct {
+   GLubyte format_idx;
+   GLubyte to_rgba[6];
+   GLubyte from_rgba[6];
+} mappings[MAX_IDX] =
+{
+   {
+  IDX_LUMINANCE,
+  MAP4(0,0,0,ONE),
+  MAP1(0)
+   },
+
+   {
+  IDX_ALPHA,
+  MAP4(ZERO, ZERO, ZERO, 0),
+  MAP1(3)
+   },
+
+   {
+  IDX_INTENSITY,
+  MAP4(0, 0, 0, 0),
+  MAP1(0),
+   },
+
+   {
+  IDX_LUMINANCE_ALPHA,
+  MAP4(0,0,0,1),
+  MAP2(0,3)
+   },
+
+   {
+  IDX_RGB,
+  MAP4(0,1,2,ONE),
+  MAP3(0,1,2)
+   },
+
+   {
+  IDX_RGBA,
+  MAP4(0,1,2,3),
+  MAP4(0,1,2,3),
+   },
+
+   {
+  IDX_RED,
+  MAP4(0, ZERO, ZERO, ONE),
+  MAP1(0),
+   },
+
+   {
+  IDX_GREEN,
+  MAP4(ZERO, 0, ZERO, ONE),
+  MAP1(1),
+   },
+
+   {
+  IDX_BLUE,
+  MAP4(ZERO, ZERO, 0, ONE),
+  MAP1(2),
+   },
+
+   {
+  IDX_BGR,
+  MAP4(2,1,0,ONE),
+  MAP3(2,1,0)
+   },
+
+   {
+  IDX_BGRA,
+  MAP4(2,1,0,3),
+  MAP4(2,1,0,3)
+   },
+
+   {
+  IDX_ABGR,
+  MAP4(3,2,1,0),
+  MAP4(3,2,1,0)
+   },
+
+   {
+  IDX_RG,
+  MAP4(0, 1, ZERO, ONE),
+  MAP2(0, 1)
+   },
+};
+
+/**
+ * Convert a GL image format enum to an IDX_* value (see above).
+ */
+static int
+get_map_idx(GLenum value)
+{
+   switch (value) {
+   case GL_LUMINANCE:
+   case GL_LUMINANCE_INTEGER_EXT:
+  return IDX_LUMINANCE;
+   case GL_ALPHA:
+   case GL_ALPHA_INTEGER:
+  return IDX_ALPHA;
+   case GL_INTENSITY:
+  return IDX_INTENSITY;
+   case GL_LUMINANCE_ALPHA:
+   case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+  return IDX_LUMINANCE_ALPHA;
+   case GL_RGB:
+   case GL_RGB_INTEGER:
+  return IDX_RGB;
+   case GL_RGBA:
+   case GL_RGBA_INTEGER:
+  return IDX_RGBA;
+   case GL_RED:
+   case GL_RED_INTEGER:
+  return IDX_RED;
+   case GL_GREEN:
+  return IDX_GREEN;
+   case GL_BLUE:
+  return IDX_BLUE;
+   case GL_BGR:
+   case GL_BGR_INTEGER:
+  return IDX_BGR;
+   case GL_BGRA:
+   case GL_BGRA_INTEGER:
+  return IDX_BGRA;
+   case GL_ABGR_EXT:
+  return IDX_ABGR;
+   case GL_RG:
+   case GL_RG_INTEGER:
+  return IDX_RG;
+   default:
+  _mesa_problem(NULL, Unexpected inFormat %s,
+_mesa_lookup_enum_by_nr(value));
+  return 0;
+   }
+}
+
+/**
+ * When promoting texture formats (see below) we need to compute the
+ * mapping of dest components back to source components.
+ * This function does that.
+ * \param inFormat  the incoming format of the texture
+ * \param outFormat  the final texture format
+ * \return map[6]  a full 6-component map
+ */
+void
+_mesa_compute_component_mapping(GLenum inFormat, GLenum outFormat, GLubyte 
*map)
+{
+   const int inFmt = get_map_idx(inFormat);
+   const int outFmt = get_map_idx(outFormat);
+   const GLubyte *in2rgba = mappings[inFmt].to_rgba;
+   const GLubyte *rgba2out = mappings[outFmt].from_rgba;
+   int i;
+
+   for (i = 0; i  4; i++)
+  map[i] = in2rgba[rgba2out[i]];
+
+   map[ZERO] = ZERO;
+   map[ONE] = ONE;
+
+#if 0
+   printf(from %x/%s to %x/%s map %d %d %d %d %d %d\n,
+ inFormat, _mesa_lookup_enum_by_nr(inFormat),
+ outFormat, _mesa_lookup_enum_by_nr(outFormat),
+ map[0],
+ map[1],
+ map[2],
+ map[3],
+ map[4],
+ map[5]);
+#endif
+}
+
 void
 _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
  void *void_src, uint32_t src_format, size_t src_stride,
diff --git a/src/mesa/main/format_utils.h 

[Mesa-dev] [PATCH 13/29] mesa: Use _mesa_format_convert to implement texstore_rgba.

2014-11-18 Thread Iago Toral Quiroga
Notice that _mesa_format_convert does not handle byte-swapping scenarios,
GL_COLOR_INDEX or MESA_FORMAT_YCBCR(_REV), so these must be handled
separately.

Also, remove all the code that goes unused after using _mesa_format_convert.
---
 src/mesa/main/texstore.c | 676 +--
 1 file changed, 61 insertions(+), 615 deletions(-)

diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 02e2b4c..f6d53d4 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -221,116 +221,6 @@ _mesa_make_temp_float_image(struct gl_context *ctx, 
GLuint dims,
 
 
 /**
- * Make temporary image with uint pixel values.  Used for unsigned
- * integer-valued textures.
- */
-static GLuint *
-make_temp_uint_image(struct gl_context *ctx, GLuint dims,
- GLenum logicalBaseFormat,
- GLenum textureBaseFormat,
- GLint srcWidth, GLint srcHeight, GLint srcDepth,
- GLenum srcFormat, GLenum srcType,
- const GLvoid *srcAddr,
- const struct gl_pixelstore_attrib *srcPacking)
-{
-   GLuint *tempImage;
-   const GLint components = _mesa_components_in_format(logicalBaseFormat);
-   const GLint srcStride =
-  _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
-   GLuint *dst;
-   GLint img, row;
-
-   ASSERT(dims = 1  dims = 3);
-
-   ASSERT(logicalBaseFormat == GL_RGBA ||
-  logicalBaseFormat == GL_RGB ||
-  logicalBaseFormat == GL_RG ||
-  logicalBaseFormat == GL_RED ||
-  logicalBaseFormat == GL_LUMINANCE_ALPHA ||
-  logicalBaseFormat == GL_LUMINANCE ||
-  logicalBaseFormat == GL_INTENSITY ||
-  logicalBaseFormat == GL_ALPHA);
-
-   ASSERT(textureBaseFormat == GL_RGBA ||
-  textureBaseFormat == GL_RGB ||
-  textureBaseFormat == GL_RG ||
-  textureBaseFormat == GL_RED ||
-  textureBaseFormat == GL_LUMINANCE_ALPHA ||
-  textureBaseFormat == GL_LUMINANCE ||
-  textureBaseFormat == GL_INTENSITY ||
-  textureBaseFormat == GL_ALPHA);
-
-   tempImage = malloc(srcWidth * srcHeight * srcDepth
- * components * sizeof(GLuint));
-   if (!tempImage)
-  return NULL;
-
-   dst = tempImage;
-   for (img = 0; img  srcDepth; img++) {
-  const GLubyte *src
-= (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
-srcWidth, srcHeight,
-srcFormat, srcType,
-img, 0, 0);
-  for (row = 0; row  srcHeight; row++) {
-_mesa_unpack_color_span_uint(ctx, srcWidth, logicalBaseFormat,
-  dst, srcFormat, srcType, src,
-  srcPacking);
-dst += srcWidth * components;
-src += srcStride;
-  }
-   }
-
-   if (logicalBaseFormat != textureBaseFormat) {
-  /* more work */
-  GLint texComponents = _mesa_components_in_format(textureBaseFormat);
-  GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
-  GLuint *newImage;
-  GLint i, n;
-  GLubyte map[6];
-
-  /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
-  ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||
- textureBaseFormat == GL_LUMINANCE_ALPHA);
-
-  /* The actual texture format should have at least as many components
-   * as the logical texture format.
-   */
-  ASSERT(texComponents = logComponents);
-
-  newImage = malloc(srcWidth * srcHeight * srcDepth
-   * texComponents * sizeof(GLuint));
-  if (!newImage) {
- free(tempImage);
- return NULL;
-  }
-
-  _mesa_compute_component_mapping(logicalBaseFormat, textureBaseFormat, 
map);
-
-  n = srcWidth * srcHeight * srcDepth;
-  for (i = 0; i  n; i++) {
- GLint k;
- for (k = 0; k  texComponents; k++) {
-GLint j = map[k];
-if (j == ZERO)
-   newImage[i * texComponents + k] = 0;
-else if (j == ONE)
-   newImage[i * texComponents + k] = 1;
-else
-   newImage[i * texComponents + k] = tempImage[i * logComponents + 
j];
- }
-  }
-
-  free(tempImage);
-  tempImage = newImage;
-   }
-
-   return tempImage;
-}
-
-
-
-/**
  * Make a temporary (color) texture image with GLubyte components.
  * Apply all needed pixel unpacking and pixel transfer operations.
  * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
@@ -518,46 +408,6 @@ memcpy_texture(struct gl_context *ctx,
 
 
 /**
- * General-case function for storing a color texture images with
- * components that can be represented with ubytes.  Example destination
- * texture formats are 

[Mesa-dev] [PATCH 19/29] mesa: Remove _mesa_unpack_color_span_uint

2014-11-18 Thread Iago Toral Quiroga
This is no longer used.
---
 src/mesa/main/pack.c | 646 ---
 src/mesa/main/pack.h |   6 -
 2 files changed, 652 deletions(-)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index afc168c..46b103e 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -1941,493 +1941,6 @@ clamp_half_to_uint(GLhalfARB h)
 }
 
 
-/**
- * \sa extract_float_rgba()
- */
-static void
-extract_uint_rgba(GLuint n, GLuint rgba[][4],
-  GLenum srcFormat, GLenum srcType, const GLvoid *src,
-  GLboolean swapBytes)
-{
-   GLint rSrc, gSrc, bSrc, aSrc;
-   GLint stride;
-   GLint rDst, bDst, gDst, aDst;
-
-   ASSERT(srcFormat == GL_RED ||
-  srcFormat == GL_GREEN ||
-  srcFormat == GL_BLUE ||
-  srcFormat == GL_ALPHA ||
-  srcFormat == GL_LUMINANCE ||
-  srcFormat == GL_LUMINANCE_ALPHA ||
-  srcFormat == GL_INTENSITY ||
-  srcFormat == GL_RG ||
-  srcFormat == GL_RGB ||
-  srcFormat == GL_BGR ||
-  srcFormat == GL_RGBA ||
-  srcFormat == GL_BGRA ||
-  srcFormat == GL_ABGR_EXT ||
-  srcFormat == GL_RED_INTEGER_EXT ||
-  srcFormat == GL_RG_INTEGER ||
-  srcFormat == GL_GREEN_INTEGER_EXT ||
-  srcFormat == GL_BLUE_INTEGER_EXT ||
-  srcFormat == GL_ALPHA_INTEGER_EXT ||
-  srcFormat == GL_RGB_INTEGER_EXT ||
-  srcFormat == GL_RGBA_INTEGER_EXT ||
-  srcFormat == GL_BGR_INTEGER_EXT ||
-  srcFormat == GL_BGRA_INTEGER_EXT ||
-  srcFormat == GL_LUMINANCE_INTEGER_EXT ||
-  srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT);
-
-   ASSERT(srcType == GL_UNSIGNED_BYTE ||
-  srcType == GL_BYTE ||
-  srcType == GL_UNSIGNED_SHORT ||
-  srcType == GL_SHORT ||
-  srcType == GL_UNSIGNED_INT ||
-  srcType == GL_INT ||
-  srcType == GL_HALF_FLOAT_ARB ||
-  srcType == GL_FLOAT ||
-  srcType == GL_UNSIGNED_BYTE_3_3_2 ||
-  srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
-  srcType == GL_UNSIGNED_SHORT_5_6_5 ||
-  srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
-  srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
-  srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
-  srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
-  srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
-  srcType == GL_UNSIGNED_INT_8_8_8_8 ||
-  srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
-  srcType == GL_UNSIGNED_INT_10_10_10_2 ||
-  srcType == GL_UNSIGNED_INT_2_10_10_10_REV ||
-  srcType == GL_UNSIGNED_INT_5_9_9_9_REV ||
-  srcType == GL_UNSIGNED_INT_10F_11F_11F_REV);
-
-   get_component_mapping(srcFormat,
- rSrc, gSrc, bSrc, aSrc,
- rDst, gDst, bDst, aDst);
-
-   stride = _mesa_components_in_format(srcFormat);
-
-#define PROCESS(SRC_INDEX, DST_INDEX, DEFAULT, TYPE, CONVERSION)   \
-   if ((SRC_INDEX)  0) {  \
-  GLuint i;
\
-  for (i = 0; i  n; i++) {
\
- rgba[i][DST_INDEX] = DEFAULT; \
-  }
\
-   }   \
-   else if (swapBytes) {   \
-  const TYPE *s = (const TYPE *) src;  \
-  GLuint i;
\
-  for (i = 0; i  n; i++) {
\
- TYPE value = s[SRC_INDEX];\
- if (sizeof(TYPE) == 2) {  \
-SWAP2BYTE(value);  \
- } \
- else if (sizeof(TYPE) == 4) { \
-SWAP4BYTE(value);  \
- } \
- rgba[i][DST_INDEX] = CONVERSION(value);\
- s += stride;  \
-  }
\
-   }   \
-   else {  \
-  const TYPE *s = (const TYPE *) src;  \
-  GLuint i;
\
-  for (i = 0; i  n; i++) {
\
- rgba[i][DST_INDEX] = CONVERSION(s[SRC_INDEX]);
\
-   

[Mesa-dev] [PATCH 24/29] swrast: Replace _mesa_unpack_color_span_float with _mesa_format_convert

2014-11-18 Thread Iago Toral Quiroga
This is the only place that uses _mesa_unpack_color_span_float so after
this we will be able to remove it.
---
 src/mesa/swrast/s_drawpix.c | 39 +++
 1 file changed, 35 insertions(+), 4 deletions(-)

diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
index 227faa2..c5813bc 100644
--- a/src/mesa/swrast/s_drawpix.c
+++ b/src/mesa/swrast/s_drawpix.c
@@ -29,6 +29,8 @@
 #include main/condrender.h
 #include main/context.h
 #include main/format_pack.h
+#include main/format_utils.h
+#include main/glformats.h
 #include main/image.h
 #include main/imports.h
 #include main/macros.h
@@ -452,6 +454,28 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
   /* use span array for temp color storage */
   GLfloat *rgba = (GLfloat *) span.array-attribs[VARYING_SLOT_COL0];
 
+  void *tempImage = NULL;
+  if (unpack-SwapBytes) {
+ /* We have to handle byte-swapping scenarios before calling
+  * _mesa_format_convert
+  */
+ GLint swapSize = _mesa_sizeof_packed_type(type);
+ if (swapSize == 2 || swapSize == 4) {
+int components = _mesa_components_in_format(format);
+int elementCount = width * height * components;
+tempImage = malloc(elementCount * swapSize);
+if (!tempImage) {
+   _mesa_error(ctx, GL_OUT_OF_MEMORY, glDrawPixels);
+   return;
+}
+if (swapSize == 2)
+   _mesa_swap2_copy(tempImage, (GLushort *) pixels, elementCount);
+else
+   _mesa_swap4_copy(tempImage, (GLuint *) pixels, elementCount);
+pixels = tempImage;
+ }
+  }
+
   /* if the span is wider than SWRAST_MAX_WIDTH we have to do it in chunks 
*/
   while (skipPixels  width) {
  const GLint spanWidth = MIN2(width - skipPixels, SWRAST_MAX_WIDTH);
@@ -461,11 +485,15 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint 
y,
   type, 0, skipPixels);
  GLint row;
 
+ /* get image row as float/RGBA */
+ uint32_t srcMesaFormat = _mesa_format_from_format_and_type(format, 
type);
  for (row = 0; row  height; row++) {
-/* get image row as float/RGBA */
-_mesa_unpack_color_span_float(ctx, spanWidth, GL_RGBA, rgba,
- format, type, source, unpack,
- transferOps);
+int dstRowStride = 4 * width * sizeof(float);
+_mesa_format_convert(rgba, RGBA_FLOAT.as_uint, dstRowStride,
+ (void*)source, srcMesaFormat, srcStride,
+ spanWidth, 1, GL_RGBA);
+if (transferOps)
+   _mesa_apply_rgba_transfer_ops(ctx, transferOps, spanWidth, 
(GLfloat (*)[4])rgba);
/* Set these for each row since the _swrast_write_* functions
 * may change them while clipping/rendering.
 */
@@ -490,6 +518,9 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
 
   /* XXX this is ugly/temporary, to undo above change */
   span.array-ChanType = CHAN_TYPE;
+
+  if (tempImage)
+ free(tempImage);
}
 
swrast_render_finish(ctx);
-- 
1.9.1

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


[Mesa-dev] [PATCH 20/29] mesa: Remove _mesa_make_temp_ubyte_image

2014-11-18 Thread Iago Toral Quiroga
Now that we have _mesa_format_convert we don't need this.

texstore_rgba will use the GL_COLOR_INDEX to RGBA conversion
helpers instead and compressed formats that used
_mesa_make_temp_ubyte_image to create an ubyte RGBA temporary
image can call _mesa_texstore with a RGBA/ubyte dst to
achieve the same goal.
---
 src/mesa/main/texcompress_bptc.c |  19 +++---
 src/mesa/main/texcompress_fxt1.c |  34 ++
 src/mesa/main/texcompress_rgtc.c |  40 +++
 src/mesa/main/texcompress_s3tc.c |  68 ---
 src/mesa/main/texstore.c | 141 ++-
 src/mesa/main/texstore.h |   9 ---
 6 files changed, 111 insertions(+), 200 deletions(-)

diff --git a/src/mesa/main/texcompress_bptc.c b/src/mesa/main/texcompress_bptc.c
index 9204f12..f7c8cac 100644
--- a/src/mesa/main/texcompress_bptc.c
+++ b/src/mesa/main/texcompress_bptc.c
@@ -1276,7 +1276,6 @@ _mesa_texstore_bptc_rgba_unorm(TEXSTORE_PARAMS)
 {
const GLubyte *pixels;
const GLubyte *tempImage = NULL;
-   GLenum baseFormat;
int rowstride;
 
if (srcFormat != GL_RGBA ||
@@ -1284,15 +1283,19 @@ _mesa_texstore_bptc_rgba_unorm(TEXSTORE_PARAMS)
ctx-_ImageTransferState ||
srcPacking-SwapBytes) {
   /* convert image to RGBA/ubyte */
-  baseFormat = _mesa_get_format_base_format(dstFormat);
-  tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
-  baseInternalFormat,
-  baseFormat,
-  srcWidth, srcHeight, srcDepth,
-  srcFormat, srcType, srcAddr,
-  srcPacking);
+  int rgbaRowStride = 4 * srcWidth * sizeof(GLubyte);
+  tempImage = malloc(srcWidth * srcHeight * 4 * sizeof(GLubyte));
   if (!tempImage)
  return GL_FALSE; /* out of memory */
+  GLubyte *tempImageSlices[1];
+  tempImageSlices[0] = (GLubyte *) tempImage;
+  _mesa_texstore(ctx, dims,
+ baseInternalFormat,
+ MESA_FORMAT_R8G8B8A8_UNORM,
+ rgbaRowStride, tempImageSlices,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
 
   pixels = tempImage;
   rowstride = srcWidth * 4;
diff --git a/src/mesa/main/texcompress_fxt1.c b/src/mesa/main/texcompress_fxt1.c
index 61b01c6..b194c27 100644
--- a/src/mesa/main/texcompress_fxt1.c
+++ b/src/mesa/main/texcompress_fxt1.c
@@ -69,14 +69,19 @@ _mesa_texstore_rgb_fxt1(TEXSTORE_PARAMS)
srcPacking-RowLength != srcWidth ||
srcPacking-SwapBytes) {
   /* convert image to RGB/GLubyte */
-  tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
- baseInternalFormat,
- 
_mesa_get_format_base_format(dstFormat),
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
+  int rgbRowStride = 3 * srcWidth * sizeof(GLubyte);
+  tempImage = malloc(srcWidth * srcHeight * 3 * sizeof(GLubyte));
   if (!tempImage)
  return GL_FALSE; /* out of memory */
+  GLubyte *tempImageSlices[1];
+  tempImageSlices[0] = (GLubyte *) tempImage;
+  _mesa_texstore(ctx, dims,
+ baseInternalFormat,
+ MESA_FORMAT_RGB_UNORM8,
+ rgbRowStride, tempImageSlices,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
   pixels = tempImage;
   srcRowStride = 3 * srcWidth;
   srcFormat = GL_RGB;
@@ -118,14 +123,19 @@ _mesa_texstore_rgba_fxt1(TEXSTORE_PARAMS)
ctx-_ImageTransferState ||
srcPacking-SwapBytes) {
   /* convert image to RGBA/GLubyte */
-  tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
- baseInternalFormat,
- 
_mesa_get_format_base_format(dstFormat),
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
+  int rgbaRowStride = 4 * srcWidth * sizeof(GLubyte);
+  tempImage = malloc(srcWidth * srcHeight * 4 * sizeof(GLubyte));
   if (!tempImage)
  return GL_FALSE; /* out of memory */
+  GLubyte *tempImageSlices[1];
+  tempImageSlices[0] = (GLubyte *) tempImage;
+  _mesa_texstore(ctx, dims,
+ baseInternalFormat,
+ MESA_FORMAT_R8G8B8A8_UNORM,
+ rgbaRowStride, tempImageSlices,
+ srcWidth, srcHeight, 

[Mesa-dev] [PATCH 21/29] mesa: Remove _mesa_make_temp_float_image

2014-11-18 Thread Iago Toral Quiroga
Now that we have _mesa_format_convert we don't need this.

This was only used to create temporary RGBA float images in the process
of storing some compressed formats. These can call _mesa_texstore
with a RGBA/float dst to achieve the same goal.
---
 src/mesa/main/texcompress_bptc.c |  20 +++---
 src/mesa/main/texcompress_rgtc.c |  40 
 src/mesa/main/texstore.c | 134 ---
 src/mesa/main/texstore.h |  10 ---
 4 files changed, 39 insertions(+), 165 deletions(-)

diff --git a/src/mesa/main/texcompress_bptc.c b/src/mesa/main/texcompress_bptc.c
index f7c8cac..9c8b47a 100644
--- a/src/mesa/main/texcompress_bptc.c
+++ b/src/mesa/main/texcompress_bptc.c
@@ -1587,7 +1587,6 @@ texstore_bptc_rgb_float(TEXSTORE_PARAMS,
 {
const float *pixels;
const float *tempImage = NULL;
-   GLenum baseFormat;
int rowstride;
 
if (srcFormat != GL_RGB ||
@@ -1595,16 +1594,19 @@ texstore_bptc_rgb_float(TEXSTORE_PARAMS,
ctx-_ImageTransferState ||
srcPacking-SwapBytes) {
   /* convert image to RGB/float */
-  baseFormat = _mesa_get_format_base_format(dstFormat);
-  tempImage = _mesa_make_temp_float_image(ctx, dims,
-  baseInternalFormat,
-  baseFormat,
-  srcWidth, srcHeight, srcDepth,
-  srcFormat, srcType, srcAddr,
-  srcPacking,
-  ctx-_ImageTransferState);
+  int rgbRowStride = 3 * srcWidth * sizeof(GLfloat);
+  tempImage = malloc(srcWidth * srcHeight * 3 * sizeof(GLfloat));
   if (!tempImage)
  return GL_FALSE; /* out of memory */
+  GLfloat *tempImageSlices[1];
+  tempImageSlices[0] = (GLfloat *) tempImage;
+  _mesa_texstore(ctx, dims,
+ baseInternalFormat,
+ MESA_FORMAT_RGB_FLOAT32,
+ rgbRowStride, (GLubyte **)tempImageSlices,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
 
   pixels = tempImage;
   rowstride = srcWidth * sizeof(float) * 3;
diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c
index 72c6062..1144d37 100644
--- a/src/mesa/main/texcompress_rgtc.c
+++ b/src/mesa/main/texcompress_rgtc.c
@@ -139,14 +139,19 @@ _mesa_texstore_signed_red_rgtc1(TEXSTORE_PARAMS)
ASSERT(dstFormat == MESA_FORMAT_R_RGTC1_SNORM ||
   dstFormat == MESA_FORMAT_L_LATC1_SNORM);
 
-   tempImage = _mesa_make_temp_float_image(ctx, dims,
-  baseInternalFormat,
-  
_mesa_get_format_base_format(dstFormat),
-  srcWidth, srcHeight, srcDepth,
-  srcFormat, srcType, srcAddr,
-  srcPacking, 0x0);
+   int redRowStride = 1 * srcWidth * sizeof(GLfloat);
+   tempImage = malloc(srcWidth * srcHeight * 1 * sizeof(GLfloat));
if (!tempImage)
   return GL_FALSE; /* out of memory */
+   GLfloat *tempImageSlices[1];
+   tempImageSlices[0] = (GLfloat *) tempImage;
+   _mesa_texstore(ctx, dims,
+  baseInternalFormat,
+  MESA_FORMAT_R_FLOAT32,
+  redRowStride, (GLubyte **)tempImageSlices,
+  srcWidth, srcHeight, srcDepth,
+  srcFormat, srcType, srcAddr,
+  srcPacking);
 
dst = (GLbyte *) dstSlices[0];
 
@@ -252,14 +257,25 @@ _mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS)
ASSERT(dstFormat == MESA_FORMAT_RG_RGTC2_SNORM ||
   dstFormat == MESA_FORMAT_LA_LATC2_SNORM);
 
-   tempImage = _mesa_make_temp_float_image(ctx, dims,
-  baseInternalFormat,
-  
_mesa_get_format_base_format(dstFormat),
-  srcWidth, srcHeight, srcDepth,
-  srcFormat, srcType, srcAddr,
-  srcPacking, 0x0);
+   mesa_format tempFormat;
+   if (baseInternalFormat == GL_RG)
+  tempFormat = MESA_FORMAT_RG_FLOAT32;
+   else
+  tempFormat = MESA_FORMAT_LA_FLOAT32;
+
+   int rgRowStride = 2 * srcWidth * sizeof(GLfloat);
+   tempImage = malloc(srcWidth * srcHeight * 2 * sizeof(GLfloat));
if (!tempImage)
   return GL_FALSE; /* out of memory */
+   GLfloat *tempImageSlices[1];
+   tempImageSlices[0] = (GLfloat *) tempImage;
+   _mesa_texstore(ctx, dims,
+  baseInternalFormat,
+  tempFormat,
+  rgRowStride, (GLubyte **)tempImageSlices,
+  srcWidth, srcHeight, srcDepth,
+  srcFormat, srcType, srcAddr,
+  

[Mesa-dev] [PATCH 17/29] mesa: Unify rebase logic for glReadPixels and glGetTexImage.

2014-11-18 Thread Iago Toral Quiroga
Both glReadPixels and glGetTexImage have RGBA rebasing logic that is almost
the same, so move that logic to a separate helper function
_mesa_get_rebase_format_for_color_read_back and call this from
both implementations.
---
 src/mesa/main/pack.c| 69 +++
 src/mesa/main/pack.h|  5 
 src/mesa/main/readpix.c | 71 +++--
 src/mesa/main/texgetimage.c | 68 +++
 4 files changed, 95 insertions(+), 118 deletions(-)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index aabe6a9..8e7afc2 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -4334,6 +4334,75 @@ _mesa_rebase_rgba_uint(GLuint n, GLuint rgba[][4], 
GLenum baseFormat)
}
 }
 
+GLenum
+_mesa_get_rebase_format_for_color_read_back(GLenum src_internal_base_format,
+GLenum src_base_format,
+GLenum dst_base_format)
+{
+   if (src_internal_base_format == GL_LUMINANCE ||
+   src_internal_base_format == GL_INTENSITY ||
+   src_internal_base_format == GL_LUMINANCE_ALPHA) {
+  /* If luminance (or intensity) is read back as RGB(A), the returned value
+   * should be (L,0,0,1), not (L,L,L,1), so we need to rebase.
+   */
+  return src_internal_base_format;
+   } else if ((src_internal_base_format == GL_RGB ||
+   src_internal_base_format == GL_RG) 
+  (dst_base_format == GL_LUMINANCE ||
+   dst_base_format == GL_LUMINANCE_ALPHA)) {
+  /* If RG(B) is read as luminance we want to have (R,G,B,1) or (R,G,0,1),
+   * RGBA values, so we need a rebase.
+   */
+  return src_internal_base_format;
+   } else if (src_internal_base_format != src_base_format) {
+  /* If the internal format and the real format differ we can't rely
+   * on the convert functions setting the correct constant values
+   * (e.g. reading back GL_RGB8 which is actually RGBA won't set alpha=1),
+   * so we will have to rebase in certain cases.
+   */
+  switch (src_internal_base_format) {
+  case GL_RED:
+ if ((src_base_format == GL_RGBA ||
+  src_base_format == GL_RGB ||
+  src_base_format == GL_RG) 
+ (dst_base_format == GL_RGBA ||
+  dst_base_format == GL_RGB ||
+  dst_base_format == GL_RG ||
+  dst_base_format == GL_GREEN)) {
+return src_internal_base_format;
+break;
+ }
+ /* fall through */
+  case GL_RG:
+ if ((src_base_format == GL_RGBA ||
+  src_base_format == GL_RGB) 
+ (dst_base_format == GL_RGBA ||
+  dst_base_format == GL_RGB ||
+  dst_base_format == GL_BLUE)) {
+return src_internal_base_format;
+break;
+ }
+ /* fall through */
+  case GL_RGB:
+ if (src_base_format == GL_RGBA 
+ (dst_base_format == GL_RGBA ||
+  dst_base_format == GL_ALPHA ||
+  dst_base_format == GL_LUMINANCE_ALPHA)) {
+ return src_internal_base_format;
+ }
+ break;
+  case GL_ALPHA:
+ if (dst_base_format != GL_ALPHA) {
+return src_internal_base_format;
+ }
+ break;
+  }
+   }
+
+   /* No rebase needed */
+   return GL_NONE;
+}
+
 void
 _mesa_pack_luminance_from_rgba_float(GLuint n, GLfloat rgba[][4],
  GLvoid *dstAddr, GLenum dst_format,
diff --git a/src/mesa/main/pack.h b/src/mesa/main/pack.h
index 5a532e0..6765a7f 100644
--- a/src/mesa/main/pack.h
+++ b/src/mesa/main/pack.h
@@ -155,6 +155,11 @@ _mesa_rebase_rgba_float(GLuint n, GLfloat rgba[][4], 
GLenum baseFormat);
 extern void
 _mesa_rebase_rgba_uint(GLuint n, GLuint rgba[][4], GLenum baseFormat);
 
+extern GLenum
+_mesa_get_rebase_format_for_color_read_back(GLenum src_internal_base_format,
+GLenum src_base_format,
+GLenum dst_base_format);
+
 extern void
 _mesa_pack_luminance_from_rgba_float(GLuint n, GLfloat rgba[][4],
  GLvoid *dstAddr, GLenum dst_format,
diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index b779a5b..f08fead 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -431,6 +431,8 @@ read_rgba_pixels( struct gl_context *ctx,
int dst_stride = _mesa_image_row_stride(packing, width, format, type);
uint32_t dst_format = _mesa_format_from_format_and_type(format, type);
GLenum dst_base_format = _mesa_get_format_base_format(dst_format);
+   bool dst_is_luminance = format == GL_LUMINANCE ||
+   format == GL_LUMINANCE_ALPHA;
GLubyte *dst = (GLubyte *)
   _mesa_image_address2d(packing, pixels, width, height,
 format, type, 

[Mesa-dev] [PATCH 01/29] mesa: Add an implementation of a master convert function.

2014-11-18 Thread Iago Toral Quiroga
From: Jason Ekstrand jason.ekstr...@intel.com

v2 by Iago Toral ito...@igalia.com:

- When testing if we can directly pack we should use the src format to check
  if we are packing from an RGBA format. The original code used the dst format
  for the ubyte case by mistake.
- Fixed incorrect number of bits for dst, it was computed using the src format
  instead of the dst format.
- If the dst format is an array format, check if it is signed. We were only
  checking this for the case where it was not an array format, but we need
  to know this in both scenarios.
- Fixed incorrect swizzle transform for the cases where we convert between
  array formats.
- Compute is_signed and bits only once and for the dst format. We were
  computing these for the src format too but they were overwritten by the
  dst values immediately after.
- Be more careful when selecting the integer path. Specifically, check that
  both src and dst are integer types. Checking only one of them should suffice
  since OpenGL does not allow conversions between normalized and integer types,
  but putting extra care here makes sense and also makes the actual requirements
  for this path more clear.
- The format argument for pack functions is the destination format we are
  packing to, not the source format (which has to be RGBA).
- Expose RGBA_* to other files. These will come in handy when in need to
  test if a given array format is RGBA or in need to pass RGBA formats to
  mesa_format_convert.

v3 by Samuel Iglesias sigles...@igalia.com:

- Add an RGBA_INT definition.
---
 src/mesa/main/format_utils.c | 378 +++
 src/mesa/main/format_utils.h |  10 ++
 src/mesa/main/formats.h  |  15 +-
 3 files changed, 399 insertions(+), 4 deletions(-)

diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index fcbbba4..c3815cb 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -25,6 +25,384 @@
 #include format_utils.h
 #include glformats.h
 #include macros.h
+#include format_pack.h
+#include format_unpack.h
+
+mesa_array_format RGBA_FLOAT = {{
+   MESA_ARRAY_FORMAT_TYPE_FLOAT,
+   0,
+   4,
+   0, 1, 2, 3,
+   0, 1
+}};
+
+mesa_array_format RGBA_UBYTE = {{
+   MESA_ARRAY_FORMAT_TYPE_UBYTE,
+   1,
+   4,
+   0, 1, 2, 3,
+   0, 1
+}};
+
+mesa_array_format RGBA_UINT = {{
+   MESA_ARRAY_FORMAT_TYPE_UINT,
+   0,
+   4,
+   0, 1, 2, 3,
+   0, 1
+}};
+
+mesa_array_format RGBA_INT = {{
+   MESA_ARRAY_FORMAT_TYPE_INT,
+   0,
+   4,
+   0, 1, 2, 3,
+   0, 1
+}};
+
+static void
+invert_swizzle(uint8_t dst[4], const uint8_t src[4])
+{
+   int i, j;
+
+   dst[0] = MESA_FORMAT_SWIZZLE_NONE;
+   dst[1] = MESA_FORMAT_SWIZZLE_NONE;
+   dst[2] = MESA_FORMAT_SWIZZLE_NONE;
+   dst[3] = MESA_FORMAT_SWIZZLE_NONE;
+
+   for (i = 0; i  4; ++i)
+  for (j = 0; j  4; ++j)
+ if (src[j] == i  dst[i] == MESA_FORMAT_SWIZZLE_NONE)
+dst[i] = j;
+}
+
+static GLenum
+gl_type_for_array_format_datatype(enum mesa_array_format_datatype type)
+{
+   switch (type) {
+   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
+  return GL_UNSIGNED_BYTE;
+   case MESA_ARRAY_FORMAT_TYPE_USHORT:
+  return GL_UNSIGNED_SHORT;
+   case MESA_ARRAY_FORMAT_TYPE_UINT:
+  return GL_UNSIGNED_INT;
+   case MESA_ARRAY_FORMAT_TYPE_BYTE:
+  return GL_BYTE;
+   case MESA_ARRAY_FORMAT_TYPE_SHORT:
+  return GL_SHORT;
+   case MESA_ARRAY_FORMAT_TYPE_INT:
+  return GL_INT;
+   case MESA_ARRAY_FORMAT_TYPE_HALF:
+  return GL_HALF_FLOAT;
+   case MESA_ARRAY_FORMAT_TYPE_FLOAT:
+  return GL_FLOAT;
+   default:
+  assert(!Invalid datatype);
+  return GL_NONE;
+   }
+}
+
+void
+_mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
+ void *void_src, uint32_t src_format, size_t src_stride,
+ size_t width, size_t height)
+{
+   uint8_t *dst = (uint8_t *)void_dst;
+   uint8_t *src = (uint8_t *)void_src;
+   mesa_array_format src_array_format, dst_array_format;
+   uint8_t src2dst[4], src2rgba[4], rgba2dst[4], dst2rgba[4];
+   GLenum src_gl_type, dst_gl_type, common_gl_type;
+   bool normalized, dst_integer, src_integer, is_signed;
+   uint8_t (*tmp_ubyte)[4];
+   float (*tmp_float)[4];
+   uint32_t (*tmp_uint)[4];
+   int i, bits;
+   size_t row;
+
+   if (src_format  MESA_ARRAY_FORMAT_BIT) {
+  src_array_format.as_uint = src_format;
+   } else {
+  assert(_mesa_is_format_color_format(src_format));
+  src_array_format.as_uint = _mesa_format_to_array_format(src_format);
+   }
+
+   if (dst_format  MESA_ARRAY_FORMAT_BIT) {
+  dst_array_format.as_uint = dst_format;
+   } else {
+  assert(_mesa_is_format_color_format(dst_format));
+  dst_array_format.as_uint = _mesa_format_to_array_format(dst_format);
+   }
+
+   /* Handle the cases where we can directly unpack */
+   if (!(src_format  MESA_ARRAY_FORMAT_BIT)) {
+  if (dst_array_format.as_uint == RGBA_FLOAT.as_uint) {
+ for 

[Mesa-dev] [PATCH 18/29] mesa: Replace _mesa_unpack_bitmap with _mesa_unpack_image()

2014-11-18 Thread Iago Toral Quiroga
From: Eduardo Lima Mitev el...@igalia.com

_mesa_unpack_bitmap() was introduced by commit 02b801c to handle the case
when data is stored in PBO by display lists, in the context of this bug:

Incorrect pixels read back if draw bitmap texture through Display list
https://bugs.freedesktop.org/show_bug.cgi?id=10370

Since _mesa_unpack_image() already handles the case of GL_BITMAP, this patch
removes _mesa_unpack_bitmap() and makes affected calls go through
_mesa_unapck_image() instead.

The sample test attached to the original bug report passes with this change
and there are no piglit regressions.

Signed-off-by: Eduardo Lima Mitev el...@igalia.com
---
 src/mesa/main/dlist.c |  14 ++-
 src/mesa/main/pack.c  | 105 +-
 src/mesa/main/pack.h  |   4 --
 3 files changed, 6 insertions(+), 117 deletions(-)

diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c
index 4b7b060..4a5d819 100644
--- a/src/mesa/main/dlist.c
+++ b/src/mesa/main/dlist.c
@@ -957,11 +957,8 @@ unpack_image(struct gl_context *ctx, GLuint dimensions,
   /* no PBO */
   GLvoid *image;
 
-  if (type == GL_BITMAP)
- image = _mesa_unpack_bitmap(width, height, pixels, unpack);
-  else
- image = _mesa_unpack_image(dimensions, width, height, depth,
-format, type, pixels, unpack);
+  image = _mesa_unpack_image(dimensions, width, height, depth,
+ format, type, pixels, unpack);
   if (pixels  !image) {
  _mesa_error(ctx, GL_OUT_OF_MEMORY, display list construction);
   }
@@ -983,11 +980,8 @@ unpack_image(struct gl_context *ctx, GLuint dimensions,
   }
 
   src = ADD_POINTERS(map, pixels);
-  if (type == GL_BITMAP)
- image = _mesa_unpack_bitmap(width, height, src, unpack);
-  else
- image = _mesa_unpack_image(dimensions, width, height, depth,
-format, type, src, unpack);
+  image = _mesa_unpack_image(dimensions, width, height, depth,
+ format, type, src, unpack);
 
   ctx-Driver.UnmapBuffer(ctx, unpack-BufferObj, MAP_INTERNAL);
 
diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 8e7afc2..afc168c 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -100,7 +100,8 @@ void
 _mesa_unpack_polygon_stipple( const GLubyte *pattern, GLuint dest[32],
   const struct gl_pixelstore_attrib *unpacking )
 {
-   GLubyte *ptrn = (GLubyte *) _mesa_unpack_bitmap(32, 32, pattern, unpacking);
+   GLubyte *ptrn = (GLubyte *) _mesa_unpack_image(2, 32, 32, 1, GL_COLOR_INDEX,
+  GL_BITMAP, pattern, 
unpacking);
if (ptrn) {
   /* Convert pattern from GLubytes to GLuints and handle big/little
* endian differences
@@ -144,108 +145,6 @@ _mesa_pack_polygon_stipple( const GLuint pattern[32], 
GLubyte *dest,
 
 
 /*
- * Unpack bitmap data.  Resulting data will be in most-significant-bit-first
- * order with row alignment = 1 byte.
- */
-GLvoid *
-_mesa_unpack_bitmap( GLint width, GLint height, const GLubyte *pixels,
- const struct gl_pixelstore_attrib *packing )
-{
-   GLint bytes, row, width_in_bytes;
-   GLubyte *buffer, *dst;
-
-   if (!pixels)
-  return NULL;
-
-   /* Alloc dest storage */
-   bytes = ((width + 7) / 8 * height);
-   buffer = malloc( bytes );
-   if (!buffer)
-  return NULL;
-
-   width_in_bytes = CEILING( width, 8 );
-   dst = buffer;
-   for (row = 0; row  height; row++) {
-  const GLubyte *src = (const GLubyte *)
- _mesa_image_address2d(packing, pixels, width, height,
-   GL_COLOR_INDEX, GL_BITMAP, row, 0);
-  if (!src) {
- free(buffer);
- return NULL;
-  }
-
-  if ((packing-SkipPixels  7) == 0) {
- memcpy( dst, src, width_in_bytes );
- if (packing-LsbFirst) {
-flip_bytes( dst, width_in_bytes );
- }
-  }
-  else {
- /* handling SkipPixels is a bit tricky (no pun intended!) */
- GLint i;
- if (packing-LsbFirst) {
-GLubyte srcMask = 1  (packing-SkipPixels  0x7);
-GLubyte dstMask = 128;
-const GLubyte *s = src;
-GLubyte *d = dst;
-*d = 0;
-for (i = 0; i  width; i++) {
-   if (*s  srcMask) {
-  *d |= dstMask;
-   }
-   if (srcMask == 128) {
-  srcMask = 1;
-  s++;
-   }
-   else {
-  srcMask = srcMask  1;
-   }
-   if (dstMask == 1) {
-  dstMask = 128;
-  d++;
-  *d = 0;
-   }
-   else {
-  dstMask = dstMask  1;
-   }
-}
- }
- else {
-GLubyte srcMask = 128  

Re: [Mesa-dev] [PATCH 00/20] Auto-generate pack/unpack functions

2014-11-18 Thread Iago Toral
I forgot to say that the series is available for testing here:
https://github.com/Igalia/mesa/tree/itoral-autogen-packing-review

Also, one of the patches was held for review by the list owner due to
its size (patch 12, which handles auto-generation of format_unpack.c),
so reviewers can fetch it from that link too if it does not reach the
list in the end.

Iago

On Tue, 2014-11-18 at 09:43 +0100, Iago Toral Quiroga wrote:
 This is the fist of two series of patches to address:
 https://bugs.freedesktop.org/show_bug.cgi?id=84566
 
 The idea is that we have a lot of format conversion code scattered through
 different files in the repository, a lot of that is redundant / duplicated,
 so this intends to address that issue.
 
 The goal of this first series is to address auto-generation of our pack/unpack
 functions (format_pack.c and format_unpack.c). Currently, we  have a ton of
 hand-coded pack/unpack functions for lots of formats, but we can auto-generate
 most of that code instead, so this series handles this.
 
 This is based on initial work by Jason Ekstrand.
 
 Tested on i965, classic swrast and gallium (radeon, nouveau, llvmpipe) without
 regressions.
 
 For software drivers we worked with a trimmed set of piglit tests (related to
 format conversion), ~5700 tests selected with the following filter:
 
 -t format -t color -t tex -t image -t swizzle -t clamp -t rgb -t lum -t pix
 -t fbo -t frame
 
 Summary of the patches:
  * Patches 1-7 are general fixes to the current code that were found while
working on this.
  * Patches 8-16 implement auto-generation of pack/unpack functions.
  * Patches 17-20 make use of the auto-generated pack/unpack functions in
various places to simplify the current code.
 
 Notice that some of the fixes in patches 1-7 will become obsolete as soon as
 we auto-generate the pack/unpack functions, but we thought it would make sense
 to keep them in the patch set anyway since we started from that base and they
 should be correct fixes to the currently existing code.
 
 Iago Toral Quiroga (1):
   swrast: Remove unused variable.
 
 Jason Ekstrand (9):
   mesa/format_utils: Fix a bug in one of the format helper functions
   mesa: Fix packing/unpacking of MESA_FORMAT_R5G6B5_UNORM
   mesa/colormac: Remove an unused macro
   mesa: Fix A1R5G5B5 packing/unpacking
   mesa/format_utils: Prefix and expose the conversion helper functions
   mesa: Add a concept of an array format
   mesa: Add a _mesa_is_format_color_format helper
   mesa: Autogenerate most of format_pack.c
   mesa: Autogenerate format_unpack.c
 
 Samuel Iglesias Gonsalvez (10):
   mesa: Fix get_texbuffer_format().
   mesa: Fix _mesa_swizzle_and_convert integer conversions to clamp
 properly
   mesa: Add _mesa_pack_uint_rgba_row() format conversion function
   mesa: Add non-normalized formats support for ubyte packing functions
   mesa/format_pack: Add _mesa_pack_int_rgba_row()
   mesa/formats: add new mesa formats and their pack/unpack functions.
   mesa: use format conversion functions in swrast
   mesa/pack: use autogenerated format_pack functions
   mesa/main/pack_tmp.h: Add float conversion support
   mesa/pack: refactor _mesa_pack_rgba_span_float()
 
  src/mesa/Makefile.am   |   18 +
  src/mesa/Makefile.sources  |4 +-
  src/mesa/main/colormac.h   |3 -
  src/mesa/main/format_convert.py|   71 +
  src/mesa/main/format_info.py   |   41 +
  src/mesa/main/format_pack.c| 2994 
  src/mesa/main/format_pack.c.mako   | 1147 ++
  src/mesa/main/format_pack.h|6 +
  src/mesa/main/format_unpack.c  | 4400 
 
  src/mesa/main/format_unpack.c.mako |  914 
  src/mesa/main/format_utils.c   |  248 +-
  src/mesa/main/format_utils.h   |  105 +
  src/mesa/main/formats.c|  193 +-
  src/mesa/main/formats.csv  |   13 +
  src/mesa/main/formats.h|   73 +
  src/mesa/main/pack.c   | 2111 +++--
  src/mesa/main/pack_tmp.h   |   76 +-
  src/mesa/main/run_mako.py  |7 +
  src/mesa/main/teximage.c   |4 +-
  src/mesa/main/texstore.c   |2 +-
  src/mesa/swrast/s_drawpix.c|3 -
  src/mesa/swrast/s_texfetch.c   |   13 +
  src/mesa/swrast/s_texfetch_tmp.h   | 1359 +--
  23 files changed, 3222 insertions(+), 10583 deletions(-)
  create mode 100644 src/mesa/main/format_convert.py
  delete mode 100644 src/mesa/main/format_pack.c
  create mode 100644 src/mesa/main/format_pack.c.mako
  delete mode 100644 src/mesa/main/format_unpack.c
  create mode 100644 src/mesa/main/format_unpack.c.mako
  create mode 100644 src/mesa/main/run_mako.py
 


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


Re: [Mesa-dev] [PATCH 00/20] Auto-generate pack/unpack functions

2014-11-18 Thread Jose Fonseca
 The idea is that we have a lot of format conversion code scattered 
through
 different files in the repository, a lot of that is redundant / 
duplicated,

 so this intends to address that issue.

First, I think this is a great goal.  And while I haven't reviewed them 
in detail, just from skimming through them, these patch series seem to 
be a great cleanup and a lot of work went into it.  I certainly don't 
object to any of this.




But I have to say I find a bit unfortunate that so much effort is being 
put on implementing something specific to Mesa formats instead of taking 
this opportunity to devise a solution that would work both for gallium 
and Mesa formats.



Furthermore I see there is some interest speeding mesa using SSE2 
intrinsics, and of course format conversion is precisely one of the code 
paths that can great benefit from SIMD, but I have no doubt: the most 
efficient and sane way of leveraging SIMD with all these formats 
conversion is to JIT compile format conversion code tailored to the CPU 
in runtime.  There are just too many CPU variations to statically 
generate C code for every one of them.  And lot of the code to do this 
already exists in src/gallium/auxiliary/gallivm.  We should consider 
using it from src/mesa/*.



This gallium helper code was written outside mesa to avoid the GL 
dependency (there was one point some of this stuff had to run in XP 
kernel mode! thankfully not anymore), and because when gallium was 
written the idea was that all Mesa drivers would eventually migrate into 
it.  Alas, that didn't happen, and might never happen.  That's OK.  But 
in that case, I do believe we should find a way of sharing more of the 
stuff in src/gallium/auxiliary with all Mesa drivers, non-gallium 
classic drivers included.



In particular, we really should have a format conversion module that is 
capable of handling a superset of all Mesa and Gallium formats somwhere 
in src/util/  .  One might even leverage the auto-generated pack/unpack 
functions in src/gallium/auxiliary/u_format* though I wouldn't care if 
not, as long as the functionality is the same.



In short, we can't change the past, but I wish we could have more 
synergy in the future.



Jose




On 18/11/14 08:43, Iago Toral Quiroga wrote:

This is the fist of two series of patches to address:
https://urldefense.proofpoint.com/v2/url?u=https-3A__bugs.freedesktop.org_show-5Fbug.cgi-3Fid-3D84566d=AAIGaQc=Sqcl0Ez6M0X8aeM67LKIiDJAXVeAw-YihVMNtXt-uEsr=zfmBZnnVGHeYde45pMKNnVyzeaZbdIqVLprmZCM2zzEm=9H2UxyGUngIpuFNlQEzL9VtIOmYVKVs2o4nyL_We6o0s=xYhgcKEBxp3-d_ddjpFiNGRkqLo2BMUedLQ67ck2ce8e=

The idea is that we have a lot of format conversion code scattered through
different files in the repository, a lot of that is redundant / duplicated,
so this intends to address that issue.

The goal of this first series is to address auto-generation of our pack/unpack
functions (format_pack.c and format_unpack.c). Currently, we  have a ton of
hand-coded pack/unpack functions for lots of formats, but we can auto-generate
most of that code instead, so this series handles this.

This is based on initial work by Jason Ekstrand.

Tested on i965, classic swrast and gallium (radeon, nouveau, llvmpipe) without
regressions.

For software drivers we worked with a trimmed set of piglit tests (related to
format conversion), ~5700 tests selected with the following filter:

-t format -t color -t tex -t image -t swizzle -t clamp -t rgb -t lum -t pix
-t fbo -t frame

Summary of the patches:
  * Patches 1-7 are general fixes to the current code that were found while
working on this.
  * Patches 8-16 implement auto-generation of pack/unpack functions.
  * Patches 17-20 make use of the auto-generated pack/unpack functions in
various places to simplify the current code.

Notice that some of the fixes in patches 1-7 will become obsolete as soon as
we auto-generate the pack/unpack functions, but we thought it would make sense
to keep them in the patch set anyway since we started from that base and they
should be correct fixes to the currently existing code.

Iago Toral Quiroga (1):
   swrast: Remove unused variable.

Jason Ekstrand (9):
   mesa/format_utils: Fix a bug in one of the format helper functions
   mesa: Fix packing/unpacking of MESA_FORMAT_R5G6B5_UNORM
   mesa/colormac: Remove an unused macro
   mesa: Fix A1R5G5B5 packing/unpacking
   mesa/format_utils: Prefix and expose the conversion helper functions
   mesa: Add a concept of an array format
   mesa: Add a _mesa_is_format_color_format helper
   mesa: Autogenerate most of format_pack.c
   mesa: Autogenerate format_unpack.c

Samuel Iglesias Gonsalvez (10):
   mesa: Fix get_texbuffer_format().
   mesa: Fix _mesa_swizzle_and_convert integer conversions to clamp
 properly
   mesa: Add _mesa_pack_uint_rgba_row() format conversion function
   mesa: Add non-normalized formats support for ubyte packing functions
   mesa/format_pack: Add _mesa_pack_int_rgba_row()
   mesa/formats: add new 

[Mesa-dev] [PATCH] util: update hash type comments

2014-11-18 Thread Timothy Arceri
Signed-off-by: Timothy Arceri t_arc...@yahoo.com.au
---
 src/util/hash_table.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/util/hash_table.c b/src/util/hash_table.c
index 1b6726c..920bdfd 100644
--- a/src/util/hash_table.c
+++ b/src/util/hash_table.c
@@ -385,12 +385,12 @@ _mesa_hash_table_random_entry(struct hash_table *ht,
 
 
 /**
- * Quick FNV-1 hash implementation based on:
+ * Quick FNV-1a hash implementation based on:
  * http://www.isthe.com/chongo/tech/comp/fnv/
  *
- * FNV-1 is not be the best hash out there -- Jenkins's lookup3 is supposed to
- * be quite good, and it probably beats FNV.  But FNV has the advantage that
- * it involves almost no code.  For an improvement on both, see Paul
+ * FNV-1a is not be the best hash out there -- Jenkins's lookup3 is supposed
+ * to be quite good, and it probably beats FNV.  But FNV has the advantage
+ * that it involves almost no code.  For an improvement on both, see Paul
  * Hsieh's http://www.azillionmonkeys.com/qed/hash.html
  */
 uint32_t
@@ -408,7 +408,7 @@ _mesa_hash_data(const void *data, size_t size)
return hash;
 }
 
-/** FNV-1 string hash implementation */
+/** FNV-1a string hash implementation */
 uint32_t
 _mesa_hash_string(const char *key)
 {
-- 
1.9.3

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


Re: [Mesa-dev] [PATCH] glsl_compiler: Add binding hash tables to avoid SIGSEVs on linking stage

2014-11-18 Thread Andres Gomez
On Mon, 2014-11-17 at 09:25 -0700, Brian Paul wrote:
 Please split up this patch into:
 
 1. gallium comment fixes
 2. linker string fixes
 3. hash table code changes

Sure. I thought it was not worth given the small changes but I suppose
it is always better to have different topics in different patches.

Coming soon ...

Thanks for checking! :)

-- 
Br,

Andres

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


[Mesa-dev] [PATCH 3/3] glsl_compiler: Add binding hash tables to avoid SIGSEVs on linking stage

2014-11-18 Thread Andres Gomez
When using the stand alone compiler, if we try to
link a shader with vertex attributes it will
segfault on linking as the binding hash tables are
not included in the shader program. Obviously, we
cannot make the linking stage succeed without the
bound attributes but we can prevent the crash and
just let the linker spit its own error.
---
 src/glsl/main.cpp | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index 9b36a1f..91e457a 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -35,6 +35,7 @@
 #include glsl_parser_extras.h
 #include ir_optimization.h
 #include program.h
+#include program/hash_table.h
 #include loop_analysis.h
 #include standalone_scaffolding.h
 
@@ -357,6 +358,11 @@ main(int argc, char **argv)
assert(whole_program != NULL);
whole_program-InfoLog = ralloc_strdup(whole_program, );
 
+   /* Created just to avoid segmentation faults */
+   whole_program-AttributeBindings = new string_to_uint_map;
+   whole_program-FragDataBindings = new string_to_uint_map;
+   whole_program-FragDataIndexBindings = new string_to_uint_map;
+
for (/* empty */; argc  optind; optind++) {
   whole_program-Shaders =
 reralloc(whole_program, whole_program-Shaders,
@@ -415,6 +421,10 @@ main(int argc, char **argv)
for (unsigned i = 0; i  MESA_SHADER_STAGES; i++)
   ralloc_free(whole_program-_LinkedShaders[i]);
 
+   delete whole_program-AttributeBindings;
+   delete whole_program-FragDataBindings;
+   delete whole_program-FragDataIndexBindings;
+
ralloc_free(whole_program);
_mesa_glsl_release_types();
_mesa_glsl_release_builtin_functions();
-- 
1.9.1

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


Re: [Mesa-dev] [PATCH] nv50/ir: saturate FRC result to avoid completely bogus values

2014-11-18 Thread Roland Scheidegger
Am 18.11.2014 um 05:03 schrieb Ilia Mirkin:
 For values above integer accuracy in floats, val - floor(val) might
 actually produce a value greater than 1. For such large floats, it's
 reasonable to be imprecise, but it's unreasonable for FRC to return a
 value that is not between 0 and 1.
 
 Signed-off-by: Ilia Mirkin imir...@alum.mit.edu
 ---
  src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
 
 diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp 
 b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
 index 41b91e8..e5b767f 100644
 --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
 +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
 @@ -2512,7 +2512,8 @@ Converter::handleInstruction(const struct 
 tgsi_full_instruction *insn)
   src0 = fetchSrc(0, c);
   val0 = getScratch();
   mkOp1(OP_FLOOR, TYPE_F32, val0, src0);
 - mkOp2(OP_SUB, TYPE_F32, dst0[c], src0, val0);
 + mkOp2(OP_SUB, TYPE_F32, val0, src0, val0);
 + mkOp1(OP_SAT, TYPE_F32, dst0[c], val0);
}
break;
 case TGSI_OPCODE_ROUND:
 

I don't understand the math behind this. For any such large number, as
far as I can tell floor(val) == val and hence the end result ought to be
zero. Or doesn't your floor work like that?

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


Re: [Mesa-dev] [PATCH] nv50/ir: saturate FRC result to avoid completely bogus values

2014-11-18 Thread Ilia Mirkin
On Tue, Nov 18, 2014 at 8:54 AM, Roland Scheidegger srol...@vmware.com wrote:
 Am 18.11.2014 um 05:03 schrieb Ilia Mirkin:
 For values above integer accuracy in floats, val - floor(val) might
 actually produce a value greater than 1. For such large floats, it's
 reasonable to be imprecise, but it's unreasonable for FRC to return a
 value that is not between 0 and 1.

 Signed-off-by: Ilia Mirkin imir...@alum.mit.edu
 ---
  src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

 diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp 
 b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
 index 41b91e8..e5b767f 100644
 --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
 +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
 @@ -2512,7 +2512,8 @@ Converter::handleInstruction(const struct 
 tgsi_full_instruction *insn)
   src0 = fetchSrc(0, c);
   val0 = getScratch();
   mkOp1(OP_FLOOR, TYPE_F32, val0, src0);
 - mkOp2(OP_SUB, TYPE_F32, dst0[c], src0, val0);
 + mkOp2(OP_SUB, TYPE_F32, val0, src0, val0);
 + mkOp1(OP_SAT, TYPE_F32, dst0[c], val0);
}
break;
 case TGSI_OPCODE_ROUND:


 I don't understand the math behind this. For any such large number, as
 far as I can tell floor(val) == val and hence the end result ought to be
 zero. Or doesn't your floor work like that?

I could be thinking about this backwards, but let's say that floats
lose integer precision at 10.0. And I do floor(12.5)... normally this
would be 12.0, but since that's not exactly representable, it might
actually be 11.0. (Or would it be 11.9987? I didn't consider that
possibility...) And then 12.5 - 11 = 1.5. Or am I thinking about this
backwards? I guess ideally I'd do something along the lines of y = x -
floor(x); return y - floor(y). That seems like it might be more
accurate... not sure.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] nv50/ir: saturate FRC result to avoid completely bogus values

2014-11-18 Thread Roland Scheidegger
Am 18.11.2014 um 15:05 schrieb Ilia Mirkin:
 On Tue, Nov 18, 2014 at 8:54 AM, Roland Scheidegger srol...@vmware.com 
 wrote:
 Am 18.11.2014 um 05:03 schrieb Ilia Mirkin:
 For values above integer accuracy in floats, val - floor(val) might
 actually produce a value greater than 1. For such large floats, it's
 reasonable to be imprecise, but it's unreasonable for FRC to return a
 value that is not between 0 and 1.

 Signed-off-by: Ilia Mirkin imir...@alum.mit.edu
 ---
  src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

 diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp 
 b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
 index 41b91e8..e5b767f 100644
 --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
 +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
 @@ -2512,7 +2512,8 @@ Converter::handleInstruction(const struct 
 tgsi_full_instruction *insn)
   src0 = fetchSrc(0, c);
   val0 = getScratch();
   mkOp1(OP_FLOOR, TYPE_F32, val0, src0);
 - mkOp2(OP_SUB, TYPE_F32, dst0[c], src0, val0);
 + mkOp2(OP_SUB, TYPE_F32, val0, src0, val0);
 + mkOp1(OP_SAT, TYPE_F32, dst0[c], val0);
}
break;
 case TGSI_OPCODE_ROUND:


 I don't understand the math behind this. For any such large number, as
 far as I can tell floor(val) == val and hence the end result ought to be
 zero. Or doesn't your floor work like that?
 
 I could be thinking about this backwards, but let's say that floats
 lose integer precision at 10.0. And I do floor(12.5)... normally this
 would be 12.0, but since that's not exactly representable, it might
 actually be 11.0. (Or would it be 11.9987? I didn't consider that
 possibility...) And then 12.5 - 11 = 1.5. Or am I thinking about this
 backwards? I guess ideally I'd do something along the lines of y = x -
 floor(x); return y - floor(y). That seems like it might be more
 accurate... not sure.
 
If your float is large enough that the next closest float is more than
1.0 away, then that float would have been an exact integer, thus floor()
doing nothing.

Roland

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


Re: [Mesa-dev] [PATCH] nv50/ir: saturate FRC result to avoid completely bogus values

2014-11-18 Thread Jose Fonseca

On 18/11/14 14:34, Roland Scheidegger wrote:

Am 18.11.2014 um 15:05 schrieb Ilia Mirkin:

On Tue, Nov 18, 2014 at 8:54 AM, Roland Scheidegger srol...@vmware.com wrote:

Am 18.11.2014 um 05:03 schrieb Ilia Mirkin:

For values above integer accuracy in floats, val - floor(val) might
actually produce a value greater than 1. For such large floats, it's
reasonable to be imprecise, but it's unreasonable for FRC to return a
value that is not between 0 and 1.

Signed-off-by: Ilia Mirkin imir...@alum.mit.edu
---
  src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp 
b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
index 41b91e8..e5b767f 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
@@ -2512,7 +2512,8 @@ Converter::handleInstruction(const struct 
tgsi_full_instruction *insn)
   src0 = fetchSrc(0, c);
   val0 = getScratch();
   mkOp1(OP_FLOOR, TYPE_F32, val0, src0);
- mkOp2(OP_SUB, TYPE_F32, dst0[c], src0, val0);
+ mkOp2(OP_SUB, TYPE_F32, val0, src0, val0);
+ mkOp1(OP_SAT, TYPE_F32, dst0[c], val0);
}
break;
 case TGSI_OPCODE_ROUND:



I don't understand the math behind this. For any such large number, as
far as I can tell floor(val) == val and hence the end result ought to be
zero. Or doesn't your floor work like that?


I could be thinking about this backwards, but let's say that floats
lose integer precision at 10.0. And I do floor(12.5)... normally this
would be 12.0, but since that's not exactly representable, it might
actually be 11.0. (Or would it be 11.9987? I didn't consider that
possibility...) And then 12.5 - 11 = 1.5. Or am I thinking about this
backwards? I guess ideally I'd do something along the lines of y = x -
floor(x); return y - floor(y). That seems like it might be more
accurate... not sure.


If your float is large enough that the next closest float is more than
1.0 away, then that float would have been an exact integer, thus floor()
doing nothing.

Roland


Roland's right -- it takes less mantissa bits to represent an integer x, 
than a fractional number between x and x + 1


The only case where `frac(x) = x - floor(x)` fails is when x is a 
negative denormal. It might give 1.0f instead of 0.0f, if the hardware 
is not setup to flush denormals to zero properly.


Jose

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


Re: [Mesa-dev] [PATCH 16/29] mesa: use master conversion function to implement get_tex_rgba_uncompressed()

2014-11-18 Thread Brian Paul

On 11/18/2014 02:23 AM, Iago Toral Quiroga wrote:

From: Samuel Iglesias Gonsalvez sigles...@igalia.com

This covers glGetTexImage for uncompressed color formats.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
Signed-off-by: Eduardo Lima Mitev el...@igalia.com
---
  src/mesa/main/texgetimage.c | 170 ++--
  1 file changed, 117 insertions(+), 53 deletions(-)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index cb5f793..84cd53e 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -45,7 +45,8 @@
  #include texgetimage.h
  #include teximage.h
  #include texstore.h
-
+#include format_utils.h
+#include pixeltransfer.h


  /**
@@ -380,20 +381,10 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
 GLenum rebaseFormat = GL_NONE;
 GLuint height = texImage-Height;
 GLuint depth = texImage-Depth;
-   GLuint img, row;
-   GLfloat (*rgba)[4];
-   GLuint (*rgba_uint)[4];
-   GLboolean tex_is_integer = 
_mesa_is_format_integer_color(texImage-TexFormat);
-   GLboolean tex_is_uint = _mesa_is_format_unsigned(texImage-TexFormat);
+   GLuint img;
 GLenum texBaseFormat = _mesa_get_format_base_format(texImage-TexFormat);

-   /* Allocate buffer for one row of texels */
-   rgba = malloc(4 * width * sizeof(GLfloat));
-   rgba_uint = (GLuint (*)[4]) rgba;
-   if (!rgba) {
-  _mesa_error(ctx, GL_OUT_OF_MEMORY, glGetTexImage());
-  return;
-   }
+   assert (depth = 1 || dimensions  2);

 if (texImage-TexObject-Target == GL_TEXTURE_1D_ARRAY) {
depth = height;
@@ -413,9 +404,7 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
   texImage-_BaseFormat == GL_RGB ||
   texImage-_BaseFormat == GL_RG) 
  (destBaseFormat == GL_LUMINANCE ||
- destBaseFormat == GL_LUMINANCE_ALPHA ||
- destBaseFormat == GL_LUMINANCE_INTEGER_EXT ||
- destBaseFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT)) {
+ destBaseFormat == GL_LUMINANCE_ALPHA)) {
/* If we're reading back an RGB(A) texture as luminance then we need
 * to return L=tex(R).  Note, that's different from glReadPixels which
 * returns L=R+G+B.
@@ -467,6 +456,22 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
}
 }

+   /* Describe the dst format */
+   GLboolean dst_is_integer = _mesa_is_enum_format_integer(format);
+   uint32_t dst_format = _mesa_format_from_format_and_type(format, type);
+   int dst_stride = _mesa_image_row_stride(ctx-Pack, width, format, type);


This won't build with MSVC.  Declarations cannot follow code.




+
+   /* Since _mesa_format_convert does not handle transferOps we need to handle
+* them before we call the function. This requires to convert to RGBA float
+* first so we can call _mesa_apply_rgba_transfer_ops. If the dst format is
+* integer we can ignore transferOps.
+*
+* Some source formats (Luminance) will also require to be rebased to obtain
+* the expected results and this also requires to convert to RGBA first.
+*/
+   assert(!transferOps || (transferOps  !dst_is_integer));
+   bool needs_rgba = (transferOps || rebaseFormat != GL_NONE);
+
 for (img = 0; img  depth; img++) {
GLubyte *srcMap;
GLint rowstride;
@@ -475,46 +480,105 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
ctx-Driver.MapTextureImage(ctx, texImage, img,
0, 0, width, height, GL_MAP_READ_BIT,
srcMap, rowstride);
-  if (srcMap) {
- for (row = 0; row  height; row++) {
-const GLubyte *src = srcMap + row * rowstride;
-void *dest = _mesa_image_address(dimensions, ctx-Pack, pixels,
- width, height, format, type,
- img, row, 0);
-
-   if (tex_is_integer) {
-  _mesa_unpack_uint_rgba_row(texFormat, width, src, rgba_uint);
-   if (rebaseFormat)
-  _mesa_rebase_rgba_uint(width, rgba_uint, rebaseFormat);
-   if (tex_is_uint) {
-  _mesa_pack_rgba_span_from_uints(ctx, width,
-  (GLuint (*)[4]) rgba_uint,
-  format, type, dest);
-   } else {
-  _mesa_pack_rgba_span_from_ints(ctx, width,
- (GLint (*)[4]) rgba_uint,
- format, type, dest);
-   }
-   } else {
-  _mesa_unpack_rgba_row(texFormat, width, src, rgba);
-   if (rebaseFormat)
-  _mesa_rebase_rgba_float(width, rgba, rebaseFormat);
-  _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
-   

Re: [Mesa-dev] [PATCH] nv50/ir: saturate FRC result to avoid completely bogus values

2014-11-18 Thread Ilia Mirkin
On Tue, Nov 18, 2014 at 9:53 AM, Jose Fonseca jfons...@vmware.com wrote:
 On 18/11/14 14:34, Roland Scheidegger wrote:

 Am 18.11.2014 um 15:05 schrieb Ilia Mirkin:

 On Tue, Nov 18, 2014 at 8:54 AM, Roland Scheidegger srol...@vmware.com
 wrote:

 Am 18.11.2014 um 05:03 schrieb Ilia Mirkin:

 For values above integer accuracy in floats, val - floor(val) might
 actually produce a value greater than 1. For such large floats, it's
 reasonable to be imprecise, but it's unreasonable for FRC to return a
 value that is not between 0 and 1.

 Signed-off-by: Ilia Mirkin imir...@alum.mit.edu
 ---
   src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp | 3 ++-
   1 file changed, 2 insertions(+), 1 deletion(-)

 diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
 b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
 index 41b91e8..e5b767f 100644
 --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
 +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
 @@ -2512,7 +2512,8 @@ Converter::handleInstruction(const struct
 tgsi_full_instruction *insn)
src0 = fetchSrc(0, c);
val0 = getScratch();
mkOp1(OP_FLOOR, TYPE_F32, val0, src0);
 - mkOp2(OP_SUB, TYPE_F32, dst0[c], src0, val0);
 + mkOp2(OP_SUB, TYPE_F32, val0, src0, val0);
 + mkOp1(OP_SAT, TYPE_F32, dst0[c], val0);
 }
 break;
  case TGSI_OPCODE_ROUND:


 I don't understand the math behind this. For any such large number, as
 far as I can tell floor(val) == val and hence the end result ought to be
 zero. Or doesn't your floor work like that?


 I could be thinking about this backwards, but let's say that floats
 lose integer precision at 10.0. And I do floor(12.5)... normally this
 would be 12.0, but since that's not exactly representable, it might
 actually be 11.0. (Or would it be 11.9987? I didn't consider that
 possibility...) And then 12.5 - 11 = 1.5. Or am I thinking about this
 backwards? I guess ideally I'd do something along the lines of y = x -
 floor(x); return y - floor(y). That seems like it might be more
 accurate... not sure.

 If your float is large enough that the next closest float is more than
 1.0 away, then that float would have been an exact integer, thus floor()
 doing nothing.

 Roland


 Roland's right -- it takes less mantissa bits to represent an integer x,
 than a fractional number between x and x + 1

 The only case where `frac(x) = x - floor(x)` fails is when x is a negative
 denormal. It might give 1.0f instead of 0.0f, if the hardware is not setup
 to flush denormals to zero properly.

Very cool. This patch wasn't in response to an actual issue but rather
a theoretical one. Sounds like I got the theory a little wrong... time
to think more about floats :)

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


Re: [Mesa-dev] [PATCH 3/3] glsl_compiler: Add binding hash tables to avoid SIGSEVs on linking stage

2014-11-18 Thread Brian Paul
Thanks for splitting up the patch.  Your commit message below line wraps 
a bit short (~70 chars is about right).  I'll fix that before pushing.


-Brian


On 11/18/2014 06:49 AM, Andres Gomez wrote:

When using the stand alone compiler, if we try to
link a shader with vertex attributes it will
segfault on linking as the binding hash tables are
not included in the shader program. Obviously, we
cannot make the linking stage succeed without the
bound attributes but we can prevent the crash and
just let the linker spit its own error.
---
  src/glsl/main.cpp | 10 ++
  1 file changed, 10 insertions(+)

diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index 9b36a1f..91e457a 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -35,6 +35,7 @@
  #include glsl_parser_extras.h
  #include ir_optimization.h
  #include program.h
+#include program/hash_table.h
  #include loop_analysis.h
  #include standalone_scaffolding.h

@@ -357,6 +358,11 @@ main(int argc, char **argv)
 assert(whole_program != NULL);
 whole_program-InfoLog = ralloc_strdup(whole_program, );

+   /* Created just to avoid segmentation faults */
+   whole_program-AttributeBindings = new string_to_uint_map;
+   whole_program-FragDataBindings = new string_to_uint_map;
+   whole_program-FragDataIndexBindings = new string_to_uint_map;
+
 for (/* empty */; argc  optind; optind++) {
whole_program-Shaders =
 reralloc(whole_program, whole_program-Shaders,
@@ -415,6 +421,10 @@ main(int argc, char **argv)
 for (unsigned i = 0; i  MESA_SHADER_STAGES; i++)
ralloc_free(whole_program-_LinkedShaders[i]);

+   delete whole_program-AttributeBindings;
+   delete whole_program-FragDataBindings;
+   delete whole_program-FragDataIndexBindings;
+
 ralloc_free(whole_program);
 _mesa_glsl_release_types();
 _mesa_glsl_release_builtin_functions();



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


Re: [Mesa-dev] [PATCH 1/1] r600: upload implicit arguments even if there are no explicit args

2014-11-18 Thread Jan Vesely
ping

On Mon, 2014-11-03 at 20:29 -0500, Jan Vesely wrote:
 Signed-off-by: Jan Vesely jan.ves...@rutgers.edu
 ---
 
 moreover, the condition is never true now that clover appends dim info
 
  src/gallium/drivers/r600/evergreen_compute.c | 4 
  1 file changed, 4 deletions(-)
 
 diff --git a/src/gallium/drivers/r600/evergreen_compute.c 
 b/src/gallium/drivers/r600/evergreen_compute.c
 index 90fdd79..41dc93e 100644
 --- a/src/gallium/drivers/r600/evergreen_compute.c
 +++ b/src/gallium/drivers/r600/evergreen_compute.c
 @@ -295,10 +295,6 @@ void evergreen_compute_upload_input(
   struct pipe_box box;
   struct pipe_transfer *transfer = NULL;
  
 - if (shader-input_size == 0) {
 - return;
 - }
 -
   if (!shader-kernel_param) {
   /* Add space for the grid dimensions */
   shader-kernel_param = (struct r600_resource *)

-- 
Jan Vesely jan.ves...@rutgers.edu


signature.asc
Description: This is a digitally signed message part
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 00/20] Auto-generate pack/unpack functions

2014-11-18 Thread Jason Ekstrand
Jose,
I haven't had time to fully review Iago and Samuel's code, so I can't 100%
comment on it right now.  However, let me make a few comments on the
overarching plan as it were.

On Tue, Nov 18, 2014 at 2:36 AM, Jose Fonseca jfons...@vmware.com wrote:

  The idea is that we have a lot of format conversion code scattered
 through
  different files in the repository, a lot of that is redundant /
 duplicated,
  so this intends to address that issue.

 First, I think this is a great goal.  And while I haven't reviewed them in
 detail, just from skimming through them, these patch series seem to be a
 great cleanup and a lot of work went into it.  I certainly don't object to
 any of this.



 But I have to say I find a bit unfortunate that so much effort is being
 put on implementing something specific to Mesa formats instead of taking
 this opportunity to devise a solution that would work both for gallium and
 Mesa formats.


That is the end goal.  Unfortunately, getting there requires a lot of
work.  Probably more work on the mesa side than on the gallium side.  A big
part of the problem was that there was a lot of code for format conversion
and it was scattered all over mesa/main directory.  A lot of stuff needs to
be cleaned up an unified inside mesa/main before things can be unified with
gallium.  Much of that work is now done.

One of the things that I would like to see happen after this stuff lands is
to convert the mesa pack/unpack functions to take a width, height, and
stride.  Then they would have exactly the same function signature as the
gallium conversion functions and merging will be much easier.  Then we can
work on moving the format handling code into a helper library which, for
the moment, I'll call libmesaformat.  Then both gallium and mesa classic
can pull from libmesaformat and we can kill all of the redundant code.
Whose autogenerator framework we end up keeping is kind of immaterial,
they're not that hard to write.

One of the decisions that has to be made there (probably a topic for
another thread) is how we would want to structure the format metadata.
Mesa and gallium both have completely different ways of structuring it and
we need to unify that if we're going to unify the conversion code.
Personally, I think gallium's is cleaner and more expressive, but it lacks
the GL information that core mesa needs.  But, like I said, that's a topic
for another thread.


 Furthermore I see there is some interest speeding mesa using SSE2
 intrinsics, and of course format conversion is precisely one of the code
 paths that can great benefit from SIMD, but I have no doubt: the most
 efficient and sane way of leveraging SIMD with all these formats conversion
 is to JIT compile format conversion code tailored to the CPU in runtime.
 There are just too many CPU variations to statically generate C code for
 every one of them.  And lot of the code to do this already exists in
 src/gallium/auxiliary/gallivm.  We should consider using it from src/mesa/*.


Yes, there were some patches.  However, given my experiments in the past,
I'm skeptical as to how much of a real benefit it would be to
SSE-accelerate all the format conversion.  When I did my first major rework
a couple of months ago, I experimented with using the SSSE3 shuffle
operation for doing swizzling of the C implementation.  The net result of
that experiment is that using SSSE3 had a very marginal benefit over a good
C implementation such as the one we now have.  The real problem we had was
that the current format conversion stuff was doing the pessimal thing in a
lot of cases;  a lot of that stupid is now gone.  So, if someone wants to
work on that, I'm curious to see their results, but I'm not holding out for
it.

As far as doing a JIT compile, I've thought of it.  Daniel Stone recently
mentioned the idea of using ORC for doing things like this and it might be
a good fit.  However, be fore we can do that, we need a framework for these
things (which we now have, thanks to this series).  How is that done in
gallivm?  Is it done using LLVM?  If so, it might be a non-starter.  I
don't want to rekindle any debates, but you're going to have trouble
convincing some people that format conversion is a good enough reason for a
hard dependency on LLVM.

Another idea that has been put forward would be to, whenever possible, push
the unconverted data to the GPU as a linear texture and use the GPU to do
the format conversion.  This would quite possibly be better than either a
straight CPU path or an optimized JIT'ed path.

This gallium helper code was written outside mesa to avoid the GL
 dependency (there was one point some of this stuff had to run in XP kernel
 mode! thankfully not anymore), and because when gallium was written the
 idea was that all Mesa drivers would eventually migrate into it.  Alas,
 that didn't happen, and might never happen.  That's OK.  But in that case,
 I do believe we should find a way of sharing more of the stuff in
 

Re: [Mesa-dev] Move mesa version scheme to a more common style ?

2014-11-18 Thread Ian Romanick
On 11/14/2014 07:07 AM, Erik Faye-Lund wrote:
 On Fri, Nov 14, 2014 at 3:39 PM, Emil Velikov emil.l.veli...@gmail.com 
 wrote:
 Hello all,

 This is an old question that I had laying around - why doesn't mesa use
 a more conventional numbering for the development/rc releases ?

 Eg.
 mesa 10.4.0-rc1 - 10.3.99.901
 mesa 10.4.0-rc2 - 10.3.99.902
 ...
 mesa 10.4.0 - 10.4.0
 mesa 10.4.1-rc1 - 10.4.0.901
 ... you get the idea.

 Afaics most freedesktop project use it plus a big hunk of gnome.
 
 Does this really make it a more conventional numbering scheme? I've
 personally seen the 10.4.1-rc1-scheme way more often than the
 10.4.0.901-scheme. In fact, I think this is the first time I've seen
 the latter used. But I haven't exactly gone out of my way looking for
 versioning schemes.
 
 Are there any objections if I move to the above format starting with
 mesa 10.4-rc1 ? I would appreciate any feedback over the next 2-3 days,
 and based on it I'll tag the first RC.
 
 Shouldn't it be the other way around? IMO we should have strong
 arguments for *changing* it, rather than keep going as-is... Any
 change can break something, so only changes that have clear benefits
 should be done, no?

I agree with this.  Packagers have already figured out how to deal with
Mesa's scheme.  Changing it will just create more work for them.  At the
very least, I'd like to get buy-in from a couple distro maintainers
before making such a change.

 AFAICT, the current scheme conveys more relevant, obvious information
 than the proposed one, namely that it's a release *candidate* for
 v10.4.1. If no blocking issues are found, it'll become the *actual*
 release...
 ___
 mesa-dev mailing list
 mesa-dev@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/mesa-dev
 

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


Re: [Mesa-dev] [PATCH 1/2] radeonsi: support per-sample gl_FragCoord

2014-11-18 Thread Ian Romanick
On 11/17/2014 01:42 PM, Marek Olšák wrote:
 From: Marek Olšák marek.ol...@amd.com
 
 Cc: 10.4 mesa-sta...@lists.freedesktop.org
 ---
  src/gallium/drivers/radeonsi/si_state_draw.c | 25 +
  1 file changed, 13 insertions(+), 12 deletions(-)
 
 diff --git a/src/gallium/drivers/radeonsi/si_state_draw.c 
 b/src/gallium/drivers/radeonsi/si_state_draw.c
 index d5b27e7..f108282 100644
 --- a/src/gallium/drivers/radeonsi/si_state_draw.c
 +++ b/src/gallium/drivers/radeonsi/si_state_draw.c
 @@ -248,20 +248,21 @@ static void si_shader_ps(struct si_shader *shader)
   for (i = 0; i  info-num_inputs; i++) {
   switch (info-input_semantic_name[i]) {
   case TGSI_SEMANTIC_POSITION:

So... now this is a switch-statement with just one case?  That seems a
little weird...

 - if (info-input_interpolate_loc[i] ==
 - TGSI_INTERPOLATE_LOC_CENTROID) {
 - /* SPI_BARYC_CNTL.POS_FLOAT_LOCATION
 -  * Possible vaules:
 -  * 0 - Position = pixel center (default)
 -  * 1 - Position = pixel centroid
 -  * 2 - Position = iterated sample number XXX:
 -  *What does this mean?
 -  */
 + /* SPI_BARYC_CNTL.POS_FLOAT_LOCATION
 +  * Possible vaules:
 +  * 0 - Position = pixel center (default)
 +  * 1 - Position = pixel centroid
 +  * 2 - Position = at sample position
 +  */
 + switch (info-input_interpolate_loc[i]) {
 + case TGSI_INTERPOLATE_LOC_CENTROID:
   spi_baryc_cntl |= 
 S_0286E0_POS_FLOAT_LOCATION(1);
 + break;
 + case TGSI_INTERPOLATE_LOC_SAMPLE:
 + spi_baryc_cntl |= 
 S_0286E0_POS_FLOAT_LOCATION(2);
 + break;
   }
 - /* Fall through */
 - case TGSI_SEMANTIC_FACE:
 - continue;
 + break;
   }
   }
  
 

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


Re: [Mesa-dev] [PATCH 06/20] mesa: Fix _mesa_swizzle_and_convert integer conversions to clamp properly

2014-11-18 Thread Jason Ekstrand
In general, I like this patch.  However, if we are going to claim to follow
the GL rule of Colors are clampped to their representable range, then
there still seem to be quite a few cases missing.  For instance, when going
from signed to unsigned 8-bit formats, we should should take a min with 0
and when converting from unsigned to signed, we should take a max with
0x7f.  Maybe we need to add integer helper functions like we have for the
normalized ones and use those just to make sure we don't miss anything.
--Jason


On Tue, Nov 18, 2014 at 12:43 AM, Iago Toral Quiroga ito...@igalia.com
wrote:

 From: Samuel Iglesias Gonsalvez sigles...@igalia.com

 Fix various conversion paths that involved integer data types of different
 sizes (uint16_t to uint8_t, int16_t to uint8_t, etc) that were not
 being clamped properly.

 Also, one of the paths was incorrectly assigning the value 12, instead of
 1,
 to the constant one.

 Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
 ---
  src/mesa/main/format_utils.c | 33 +
  1 file changed, 17 insertions(+), 16 deletions(-)

 diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
 index b6d0fbc..8040173 100644
 --- a/src/mesa/main/format_utils.c
 +++ b/src/mesa/main/format_utils.c
 @@ -24,6 +24,7 @@

  #include format_utils.h
  #include glformats.h
 +#include macros.h

  static const uint8_t map_identity[7] = { 0, 1, 2, 3, 4, 5, 6 };
  static const uint8_t map_3210[7] = { 3, 2, 1, 0, 4, 5, 6 };
 @@ -593,28 +594,28 @@ convert_ubyte(void *void_dst, int num_dst_channels,
if (normalized) {
   SWIZZLE_CONVERT(uint8_t, uint16_t, unorm_to_unorm(src, 16, 8));
} else {
 - SWIZZLE_CONVERT(uint8_t, uint16_t, src);
 + SWIZZLE_CONVERT(uint8_t, uint16_t, MIN2(src, 0xff));
}
break;
 case GL_SHORT:
if (normalized) {
   SWIZZLE_CONVERT(uint8_t, int16_t, snorm_to_unorm(src, 16, 8));
} else {
 - SWIZZLE_CONVERT(uint8_t, int16_t, (src  0) ? 0 : src);
 + SWIZZLE_CONVERT(uint8_t, int16_t, CLAMP(src, 0, 0xff));
}
break;
 case GL_UNSIGNED_INT:
if (normalized) {
   SWIZZLE_CONVERT(uint8_t, uint32_t, unorm_to_unorm(src, 32, 8));
} else {
 - SWIZZLE_CONVERT(uint8_t, uint32_t, src);
 + SWIZZLE_CONVERT(uint8_t, uint32_t, MIN2(src, 0xff));
}
break;
 case GL_INT:
if (normalized) {
   SWIZZLE_CONVERT(uint8_t, int32_t, snorm_to_unorm(src, 32, 8));
} else {
 - SWIZZLE_CONVERT(uint8_t, int32_t, (src  0) ? 0 : src);
 + SWIZZLE_CONVERT(uint8_t, int32_t, CLAMP(src, 0, 0xff));
}
break;
 default:
 @@ -649,7 +650,7 @@ convert_byte(void *void_dst, int num_dst_channels,
if (normalized) {
   SWIZZLE_CONVERT(int8_t, uint8_t, unorm_to_snorm(src, 8, 8));
} else {
 - SWIZZLE_CONVERT(int8_t, uint8_t, src);
 + SWIZZLE_CONVERT(int8_t, uint8_t, MIN2(src, 0x7f));
}
break;
 case GL_BYTE:
 @@ -659,28 +660,28 @@ convert_byte(void *void_dst, int num_dst_channels,
if (normalized) {
   SWIZZLE_CONVERT(int8_t, uint16_t, unorm_to_snorm(src, 16, 8));
} else {
 - SWIZZLE_CONVERT(int8_t, uint16_t, src);
 + SWIZZLE_CONVERT(int8_t, uint16_t, MIN2(src, 0x7f));
}
break;
 case GL_SHORT:
if (normalized) {
   SWIZZLE_CONVERT(int8_t, int16_t, snorm_to_snorm(src, 16, 8));
} else {
 - SWIZZLE_CONVERT(int8_t, int16_t, src);
 + SWIZZLE_CONVERT(int8_t, int16_t, CLAMP(src, -0x80, 0x7f));
}
break;
 case GL_UNSIGNED_INT:
if (normalized) {
   SWIZZLE_CONVERT(int8_t, uint32_t, unorm_to_snorm(src, 32, 8));
} else {
 - SWIZZLE_CONVERT(int8_t, uint32_t, src);
 + SWIZZLE_CONVERT(int8_t, uint32_t, MIN2(src, 0x7f));
}
break;
 case GL_INT:
if (normalized) {
   SWIZZLE_CONVERT(int8_t, int32_t, snorm_to_snorm(src, 32, 8));
} else {
 - SWIZZLE_CONVERT(int8_t, int32_t, src);
 + SWIZZLE_CONVERT(int8_t, int32_t, CLAMP(src, -0x80, 0x7f));
}
break;
 default:
 @@ -739,14 +740,14 @@ convert_ushort(void *void_dst, int num_dst_channels,
if (normalized) {
   SWIZZLE_CONVERT(uint16_t, uint32_t, unorm_to_unorm(src, 32, 16));
} else {
 - SWIZZLE_CONVERT(uint16_t, uint32_t, src);
 + SWIZZLE_CONVERT(uint16_t, uint32_t, MIN2(src, 0x));
}
break;
 case GL_INT:
if (normalized) {
   SWIZZLE_CONVERT(uint16_t, int32_t, snorm_to_unorm(src, 32, 16));
} else {
 - SWIZZLE_CONVERT(uint16_t, int32_t, (src  0) ? 0 : src);
 + SWIZZLE_CONVERT(uint16_t, int32_t,  CLAMP(src, 0, 0x));
}
break;
 default:
 @@ -795,7 +796,7 @@ convert_short(void *void_dst, int num_dst_channels,

Re: [Mesa-dev] [PATCH v3 0/9] Gallium Nine

2014-11-18 Thread Henri Verbeet
On 17 November 2014 21:05, Emil Velikov emil.l.veli...@gmail.com wrote:
  - GL extensions
 I feel that it's a bit too much to shoot the project down, because it
 does not introduce GL extensions that will be useful.
To clarify, that's not what I said. It's mostly just that I'd like to
see some actual evidence for the (implicit) claim that the performance
difference is largely due to inherent OpenGL API overhead.

 Considering the interface note able, would you say that any new
 implementation towards handling D3D9 in wine is acceptable ?
If anything, it would have to be an interface approximately on the
level of the DDI, like Jose mentioned.

 Can we work together so that both project benefit from this effort ?
I like to think we've always had good relations with Mesa, even if we
don't always agree on everything. In this specific case, I'm afraid we
just have a pretty fundamental difference of opinion with the st/nine
developers on what the right approach is. Feel free to send me an
e-mail if you have Wine related questions / requests in any case
though.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 09/20] mesa: Add a concept of an array format

2014-11-18 Thread Jason Ekstrand
On Tue, Nov 18, 2014 at 12:43 AM, Iago Toral Quiroga ito...@igalia.com
wrote:

 From: Jason Ekstrand jason.ekstr...@intel.com

 An array format is a 32-bit integer format identifier that can represent
 any format that can be represented as an array of standard GL datatypes.
 While the MESA_FORMAT enums provide several of these, they don't account
 for all of them.

 v2 by Iago Toral Quiroga ito...@igalia.com:
 - Set pad to 0 and array_format_bit to 1 for all mesa array formats.
 - Fix array_format_flip_channels, since it was not doing what was expected.


I'm not terribly surprised, I never got a chance to test that function
before I handed it off to you.  I'm curious how you found it though, given
that it's only run on big endian architectures.  Maybe it was just
obviously wrong.  (silly me).  In any case, the new version looks good to
me.
--Jason


 ---
  src/mesa/main/format_info.py | 41 
  src/mesa/main/formats.c  | 56
 +++-
  src/mesa/main/formats.h  | 55
 +++
  3 files changed, 151 insertions(+), 1 deletion(-)

 diff --git a/src/mesa/main/format_info.py b/src/mesa/main/format_info.py
 index 7424fe0..315767d 100644
 --- a/src/mesa/main/format_info.py
 +++ b/src/mesa/main/format_info.py
 @@ -98,6 +98,32 @@ def get_gl_data_type(fmat):
 else:
assert False

 +def get_array_format_datatype(chan):
 +   if chan.type == parser.FLOAT:
 +  if chan.size == 16:
 + return 'MESA_ARRAY_FORMAT_TYPE_HALF'
 +  elif chan.size == 32:
 + return 'MESA_ARRAY_FORMAT_TYPE_FLOAT'
 +  else:
 + assert False
 +   elif chan.type in (parser.SIGNED, parser.UNSIGNED):
 +  datatype = 'MESA_ARRAY_FORMAT_TYPE_'
 +  if chan.type == parser.UNSIGNED:
 + datatype += 'U'
 +
 +  if chan.size == 8:
 + datatype += 'BYTE'
 +  elif chan.size == 16:
 + datatype += 'SHORT'
 +  elif chan.size == 32:
 + datatype += 'INT'
 +  else:
 + print chan.size
 + assert False
 +  return datatype
 +   else:
 +  assert False
 +
  def get_mesa_layout(fmat):
 if fmat.layout == 'array':
return 'MESA_FORMAT_LAYOUT_ARRAY'
 @@ -192,6 +218,21 @@ for fmat in formats:
 int(fmat.block_size() / 8))

 print '  {{ {0} }},'.format(', '.join(map(str, fmat.swizzle)))
 +   if fmat.is_array() and fmat.colorspace in ('rgb', 'srgb'):
 +  chan = fmat.array_element()
 +  print '   {0} ,'.format(', '.join([
 + get_array_format_datatype(chan),
 + str(int(chan.norm)),
 + str(len(fmat.channels)),
 + str(fmat.swizzle[0]),
 + str(fmat.swizzle[1]),
 + str(fmat.swizzle[2]),
 + str(fmat.swizzle[3]),
 + str(int(0)),
 + str(int(1))
 +  ]))
 +   else:
 +  print '  {{ MESA_ARRAY_FORMAT_TYPE_UBYTE, 0, 0, 0, 0, 0, 0, 0,
 0 }},'
 print '   },'

  print '};'
 diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
 index 7ec0507..f86925e 100644
 --- a/src/mesa/main/formats.c
 +++ b/src/mesa/main/formats.c
 @@ -71,6 +71,7 @@ struct gl_format_info
 GLubyte BytesPerBlock;

 uint8_t Swizzle[4];
 +   mesa_array_format ArrayFormat;
  };

  #include format_info.c
 @@ -269,6 +270,60 @@ _mesa_get_format_swizzle(mesa_format format, uint8_t
 swizzle_out[4])
 memcpy(swizzle_out, info-Swizzle, sizeof(info-Swizzle));
  }

 +static mesa_array_format
 +array_format_flip_channels(mesa_array_format format)
 +{
 +   if (format.num_channels == 1)
 +  return format;
 +
 +   if (format.num_channels == 2) {
 +  int tmp = format.swizzle_x;
 +  format.swizzle_x = format.swizzle_y;
 +  format.swizzle_y = tmp;
 +  return format;
 +   }
 +
 +   if (format.num_channels == 4) {
 +  int tmp = format.swizzle_x;
 +  format.swizzle_x = format.swizzle_w;
 +  format.swizzle_w = tmp;
 +  tmp = format.swizzle_y;
 +  format.swizzle_y = format.swizzle_z;
 +  format.swizzle_z = tmp;
 +  return format;
 +   }
 +
 +   assert(!Invalid array format);
 +}
 +
 +uint32_t
 +_mesa_format_to_array_format(mesa_format format)
 +{
 +   const struct gl_format_info *info = _mesa_get_format_info(format);
 +   if (_mesa_little_endian())
 +  return info-ArrayFormat.as_uint;
 +   else
 +  return array_format_flip_channels(info-ArrayFormat).as_uint;
 +}
 +
 +mesa_format
 +_mesa_format_from_array_format(uint32_t array_format)
 +{
 +   mesa_array_format af;
 +   unsigned f;
 +
 +   af.as_uint = array_format;
 +   af.pad = 0;
 +   if (!_mesa_little_endian())
 +  af = array_format_flip_channels(af);
 +
 +   assert(af.array_format_bit);
 +   for (f = 1; f  MESA_FORMAT_COUNT; ++f)
 +  if (_mesa_get_format_info(f)-ArrayFormat.as_uint == af.as_uint)
 + return f;
 +
 +   return MESA_FORMAT_NONE;
 +}

  /** Is the given format a compressed format? */
  GLboolean
 @@ -278,7 

Re: [Mesa-dev] The ARB_shader_subroutine extension

2014-11-18 Thread Ian Romanick
On 11/16/2014 08:31 AM, Gustaw Smolarczyk wrote:
 Hello once again,
 
 This time, I would like to ask about the shader subroutine extension.
 I believe this extension is not very popular, but is still needed for
 GL4 compliance.
 
 What is the reason for its unpopularity?
 Is it because one needs to reset subroutine uniform values after any glUse*?
 Or it just didn't provide enough value?
 Wouldn't it be good to implement uber-shaders (especially using
 subroutine uniform array)?

It has a very strong negative affect on register allocation.  Basically,
the compiler has to, at the very least, allocate registers for the
worst subroutine.  This means that subroutines that use fewer
registers will often perform worse (on some GPUs much, much worse) than
they should.  On Intel GPUs this means that you might just get SIMD8 for
a shader that could have had SIMD16.  I've been told that on AMD GPUs it
means you have much fewer vertices or pixels executing in parallel
leading to dramatic performance hits.

 Is anybody actively working on it? I guess, there are changes needed
 in the GLSL compiler. It could be easily lowered to a
 switch-on-uniform-int thing, or something like that, if only
 compliance to the GL4 matters and not the performance.
 
 Regards,
 Gustaw
 ___
 mesa-dev mailing list
 mesa-dev@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/mesa-dev

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


Re: [Mesa-dev] [PATCH 11/20] mesa: Autogenerate most of format_pack.c

2014-11-18 Thread Jason Ekstrand
On Tue, Nov 18, 2014 at 12:43 AM, Iago Toral Quiroga ito...@igalia.com
wrote:

 From: Jason Ekstrand jason.ekstr...@intel.com

 We were auto-generating it before.  The problem was that the autogeneration
 tool we were using was called copy, paste, and edit.  Let's use a more
 sensible solution.

 Signed-off-by: Jason Ekstrand jason.ekstr...@intel.com

 v2 by Samuel Iglesias sigles...@igalia.com
 - Remove format_pack.c as it is now autogenerated
 - Add usage of INDENT_FLAGS in Makefile.am
 - Remove trailing blank line

 Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
 ---
  src/mesa/Makefile.am |9 +
  src/mesa/Makefile.sources|2 +-
  src/mesa/main/format_convert.py  |   71 +
  src/mesa/main/format_pack.c  | 2982
 --
  src/mesa/main/format_pack.c.mako |  898 
  src/mesa/main/run_mako.py|7 +
  6 files changed, 986 insertions(+), 2983 deletions(-)
  create mode 100644 src/mesa/main/format_convert.py
  delete mode 100644 src/mesa/main/format_pack.c
  create mode 100644 src/mesa/main/format_pack.c.mako
  create mode 100644 src/mesa/main/run_mako.py

 diff --git a/src/mesa/Makefile.am b/src/mesa/Makefile.am
 index e71bccb..76cac4a 100644
 --- a/src/mesa/Makefile.am
 +++ b/src/mesa/Makefile.am
 @@ -66,6 +66,7 @@ BUILT_SOURCES = \
 main/get_hash.h \
  main/format_info.c \
 $(BUILDDIR)main/git_sha1.h \
 +   $(BUILDDIR)main/format_pack.c \
 $(BUILDDIR)program/program_parse.tab.c \
 $(BUILDDIR)program/lex.yy.c
  CLEANFILES = \
 @@ -89,6 +90,14 @@ main/format_info.c: main/formats.csv
 \
 $  $@.tmp; \
 mv $@.tmp $@;

 +$(BUILDDIR)main/format_pack.c: main/format_pack.c.mako main/formats.csv \
 +   main/run_mako.py main/format_parser.py
 +   $(AM_V_GEN)set -e;  \
 +   $(PYTHON2) $(PYTHON_FLAGS) $(srcdir)/main/run_mako.py   \
 +   $ $(srcdir)/main/formats.csv  $@.tmp;  \
 +   cat $@.tmp | $(INDENT) $(INDENT_FLAGS)  $@;\
 +rm $@.tmp;
 +
  main/formats.c: main/format_info.c

  noinst_LTLIBRARIES = $(ARCH_LIBS)
 diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
 index 4755018..99fc497 100644
 --- a/src/mesa/Makefile.sources
 +++ b/src/mesa/Makefile.sources
 @@ -50,7 +50,7 @@ MAIN_FILES = \
 $(SRCDIR)main/fog.c \
 $(SRCDIR)main/formatquery.c \
 $(SRCDIR)main/formats.c \
 -   $(SRCDIR)main/format_pack.c \
 +   $(BUILDDIR)main/format_pack.c \
 $(SRCDIR)main/format_unpack.c \
 $(SRCDIR)main/format_utils.c \
 $(SRCDIR)main/framebuffer.c \
 diff --git a/src/mesa/main/format_convert.py
 b/src/mesa/main/format_convert.py
 new file mode 100644
 index 000..0423427
 --- /dev/null
 +++ b/src/mesa/main/format_convert.py
 @@ -0,0 +1,71 @@
 +#!/usr/bin/env python
 +#
 +# Copyright 2014 Intel Corporation
 +# All Rights Reserved.
 +#
 +# Permission is hereby granted, free of charge, to any person obtaining a
 +# copy of this software and associated documentation files (the
 +# Software), to deal in the Software without restriction, including
 +# without limitation the rights to use, copy, modify, merge, publish,
 +# distribute, sub license, and/or sell copies of the Software, and to
 +# permit persons to whom the Software is furnished to do so, subject to
 +# the following conditions:
 +#
 +# The above copyright notice and this permission notice (including the
 +# next paragraph) shall be included in all copies or substantial portions
 +# of the Software.
 +#
 +# THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS
 +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 +# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
 +# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 +
 +import format_parser as parser
 +
 +def __get_datatype(_type, size):
 +   if _type == parser.FLOAT:
 +  if size == 32:
 + return 'float'
 +  elif size == 16:
 + return 'uint16_t'
 +  else:
 + assert False
 +   elif _type == parser.UNSIGNED:
 +  if size = 8:
 + return 'uint8_t'
 +  elif size = 16:
 + return 'uint16_t'
 +  elif size = 32:
 + return 'uint32_t'
 +  else:
 + assert False
 +   elif _type == parser.SIGNED:
 +  if size = 8:
 + return 'int8_t'
 +  elif size = 16:
 + return 'int16_t'
 +  elif size = 32:
 + return 'int32_t'
 +  else:
 + assert False
 +   else:
 +  assert False
 +
 +def channel_datatype(c):
 +   return 

Re: [Mesa-dev] [PATCH 3/3] glsl_compiler: Add binding hash tables to avoid SIGSEVs on linking stage

2014-11-18 Thread Ian Romanick
On 11/18/2014 07:40 AM, Brian Paul wrote:
 Thanks for splitting up the patch.  Your commit message below line wraps
 a bit short (~70 chars is about right).  I'll fix that before pushing.

You can add

Reviewed-by: Ian Romanick ian.d.roman...@intel.com

to patches 2 and 3 too.

 -Brian
 
 
 On 11/18/2014 06:49 AM, Andres Gomez wrote:
 When using the stand alone compiler, if we try to
 link a shader with vertex attributes it will
 segfault on linking as the binding hash tables are
 not included in the shader program. Obviously, we
 cannot make the linking stage succeed without the
 bound attributes but we can prevent the crash and
 just let the linker spit its own error.
 ---
   src/glsl/main.cpp | 10 ++
   1 file changed, 10 insertions(+)

 diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
 index 9b36a1f..91e457a 100644
 --- a/src/glsl/main.cpp
 +++ b/src/glsl/main.cpp
 @@ -35,6 +35,7 @@
   #include glsl_parser_extras.h
   #include ir_optimization.h
   #include program.h
 +#include program/hash_table.h
   #include loop_analysis.h
   #include standalone_scaffolding.h

 @@ -357,6 +358,11 @@ main(int argc, char **argv)
  assert(whole_program != NULL);
  whole_program-InfoLog = ralloc_strdup(whole_program, );

 +   /* Created just to avoid segmentation faults */
 +   whole_program-AttributeBindings = new string_to_uint_map;
 +   whole_program-FragDataBindings = new string_to_uint_map;
 +   whole_program-FragDataIndexBindings = new string_to_uint_map;
 +
  for (/* empty */; argc  optind; optind++) {
 whole_program-Shaders =
reralloc(whole_program, whole_program-Shaders,
 @@ -415,6 +421,10 @@ main(int argc, char **argv)
  for (unsigned i = 0; i  MESA_SHADER_STAGES; i++)
 ralloc_free(whole_program-_LinkedShaders[i]);

 +   delete whole_program-AttributeBindings;
 +   delete whole_program-FragDataBindings;
 +   delete whole_program-FragDataIndexBindings;
 +
  ralloc_free(whole_program);
  _mesa_glsl_release_types();
  _mesa_glsl_release_builtin_functions();

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

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


Re: [Mesa-dev] [PATCH 13/20] mesa: Add _mesa_pack_uint_rgba_row() format conversion function

2014-11-18 Thread Jason Ekstrand
On Tue, Nov 18, 2014 at 12:44 AM, Iago Toral Quiroga ito...@igalia.com
wrote:

 From: Samuel Iglesias Gonsalvez sigles...@igalia.com

 We will use this later on to handle uint conversion scenarios in a master
 convert function.

 Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
 ---
  src/mesa/main/format_pack.c.mako | 88
 
  src/mesa/main/format_pack.h  |  3 ++
  2 files changed, 91 insertions(+)

 diff --git a/src/mesa/main/format_pack.c.mako
 b/src/mesa/main/format_pack.c.mako
 index 13a20c1..b9f4656 100644
 --- a/src/mesa/main/format_pack.c.mako
 +++ b/src/mesa/main/format_pack.c.mako
 @@ -150,6 +150,62 @@ pack_ubyte_r11g11b10_float(const GLubyte src[4], void
 *dst)
 *d = float3_to_r11g11b10f(rgb);
  }

 +/* uint packing functions */
 +
 +%for f in rgb_formats:
 +   %if not f.is_int():
 +  % continue %
 +   %elif f.is_normalized():
 +  % continue %
 +   %elif f.is_compressed():
 +  % continue %
 +   %endif
 +
 +static inline void
 +pack_uint_${f.short_name()}(const GLuint src[4], void *dst)
 +{
 +   %for (i, c) in enumerate(f.channels):
 +  % i = f.swizzle.inverse()[i] %
 +  %if c.type == 'x':
 + % continue %
 +  %endif
 +
 +  ${channel_datatype(c)} ${c.name} =
 +  %if not f.is_normalized():


This if isn't needed.  If you want the assertion, an assert not
f.is_normalized would be ok, but I don't see the need given the continues
above.


 + %if c.type == parser.FLOAT and c.size == 32:
 +UINT_TO_FLOAT(src[${i}]);


Why are we doing UINT_TO_FLOAT here?  If these are for non-normalied
functions, shouldn't we just be clampping the floating-point value to the
maximum range for the integer?


 + %elif c.type == parser.FLOAT and c.size == 16:
 +_mesa_float_to_half(UINT_TO_FLOAT(src[${i}]));
 + %else:
 +(${channel_datatype(c)}) src[${i}];
 + %endif
 +  %else:
 + % assert False %
 +  %endif
 +   %endfor
 +
 +   %if f.layout == parser.ARRAY:
 +  ${format_datatype(f)} *d = (${format_datatype(f)} *)dst;
 +  %for (i, c) in enumerate(f.channels):
 + %if c.type == 'x':
 +% continue %
 + %endif
 + d[${i}] = ${c.name};
 +  %endfor
 +   %elif f.layout == parser.PACKED:
 +  ${format_datatype(f)} d = 0;
 +  %for (i, c) in enumerate(f.channels):
 + %if c.type == 'x':
 +% continue %
 + %endif
 + d |= PACK(${c.name}, ${c.shift}, ${c.size});
 +  %endfor
 +  (*(${format_datatype(f)} *)dst) = d;
 +   %else:
 +  % assert False %
 +   %endif
 +}
 +%endfor

  /* float packing functions */

 @@ -298,6 +354,38 @@ _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint
 n,
  }

  /**
 + * Pack a row of GLuint rgba[4] values to the destination.
 + */
 +void
 +_mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
 +  const GLuint src[][4], void *dst)
 +{
 +   GLuint i;
 +   GLubyte *d = dst;
 +
 +   switch (format) {
 +%for f in rgb_formats:
 +   %if not f.is_int():
 +  % continue %
 +   %elif f.is_normalized():
 +  % continue %
 +   %elif f.is_compressed():
 +  % continue %
 +   %endif
 +
 +   case ${f.name}:
 +  for (i = 0; i  n; ++i) {
 + pack_uint_${f.short_name()}(src[i], d);
 + d += ${f.block_size() / 8};
 +  }
 +  break;
 +%endfor
 +   default:
 +  assert(!Invalid format);
 +   }
 +}
 +
 +/**
   * Pack a row of GLfloat rgba[4] values to the destination.
   */
  void
 diff --git a/src/mesa/main/format_pack.h b/src/mesa/main/format_pack.h
 index 2577def..1582ad1 100644
 --- a/src/mesa/main/format_pack.h
 +++ b/src/mesa/main/format_pack.h
 @@ -77,6 +77,9 @@ extern void
  _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n,
const GLubyte src[][4], void *dst);

 +extern void
 +_mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
 + const GLuint src[][4], void *dst);

  extern void
  _mesa_pack_ubyte_rgba_rect(mesa_format format, GLuint width, GLuint
 height,
 --
 1.9.1

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

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


Re: [Mesa-dev] [PATCH 13/13] mesa: Drop unused NV_fragment_program opcodes.

2014-11-18 Thread Ian Romanick
Patches 12 and 13 are

Reviewed-by: Ian Roamnick ian.d.roman...@intel.com

The other require_NV_fp opcodes can also be removed from
program_lexer.l.  ir_to_mesa can generate those opcodes, but we can't
get them from an assembly source shader.

On 11/12/2014 05:18 PM, Eric Anholt wrote:
 The extension itself was deleted 2 years ago.  There are still some
 prog_instruction opcodes from NV_fp that exist because they're used by
 ir_to_mesa.cpp, though.
 ---
  src/mesa/program/prog_execute.c | 144 
 
  src/mesa/program/prog_instruction.c |  10 ---
  src/mesa/program/prog_instruction.h |  10 ---
  src/mesa/program/program_lexer.l|  13 
  4 files changed, 177 deletions(-)
 
 diff --git a/src/mesa/program/prog_execute.c b/src/mesa/program/prog_execute.c
 index e59ae70..650c40f 100644
 --- a/src/mesa/program/prog_execute.c
 +++ b/src/mesa/program/prog_execute.c
 @@ -1119,77 +1119,6 @@ _mesa_execute_program(struct gl_context * ctx,
   break;
case OPCODE_NOP:
   break;
 -  case OPCODE_PK2H:/* pack two 16-bit floats in one 32-bit float 
 */
 - {
 -GLfloat a[4];
 -GLuint result[4];
 -GLhalfNV hx, hy;
 -fetch_vector4(inst-SrcReg[0], machine, a);
 -hx = _mesa_float_to_half(a[0]);
 -hy = _mesa_float_to_half(a[1]);
 -result[0] =
 -result[1] =
 -result[2] =
 -result[3] = hx | (hy  16);
 -store_vector4ui(inst, machine, result);
 - }
 - break;
 -  case OPCODE_PK2US:   /* pack two GLushorts into one 32-bit float */
 - {
 -GLfloat a[4];
 -GLuint result[4], usx, usy;
 -fetch_vector4(inst-SrcReg[0], machine, a);
 -a[0] = CLAMP(a[0], 0.0F, 1.0F);
 -a[1] = CLAMP(a[1], 0.0F, 1.0F);
 -usx = F_TO_I(a[0] * 65535.0F);
 -usy = F_TO_I(a[1] * 65535.0F);
 -result[0] =
 -result[1] =
 -result[2] =
 -result[3] = usx | (usy  16);
 -store_vector4ui(inst, machine, result);
 - }
 - break;
 -  case OPCODE_PK4B:/* pack four GLbytes into one 32-bit float */
 - {
 -GLfloat a[4];
 -GLuint result[4], ubx, uby, ubz, ubw;
 -fetch_vector4(inst-SrcReg[0], machine, a);
 -a[0] = CLAMP(a[0], -128.0F / 127.0F, 1.0F);
 -a[1] = CLAMP(a[1], -128.0F / 127.0F, 1.0F);
 -a[2] = CLAMP(a[2], -128.0F / 127.0F, 1.0F);
 -a[3] = CLAMP(a[3], -128.0F / 127.0F, 1.0F);
 -ubx = F_TO_I(127.0F * a[0] + 128.0F);
 -uby = F_TO_I(127.0F * a[1] + 128.0F);
 -ubz = F_TO_I(127.0F * a[2] + 128.0F);
 -ubw = F_TO_I(127.0F * a[3] + 128.0F);
 -result[0] =
 -result[1] =
 -result[2] =
 -result[3] = ubx | (uby  8) | (ubz  16) | (ubw  24);
 -store_vector4ui(inst, machine, result);
 - }
 - break;
 -  case OPCODE_PK4UB:   /* pack four GLubytes into one 32-bit float */
 - {
 -GLfloat a[4];
 -GLuint result[4], ubx, uby, ubz, ubw;
 -fetch_vector4(inst-SrcReg[0], machine, a);
 -a[0] = CLAMP(a[0], 0.0F, 1.0F);
 -a[1] = CLAMP(a[1], 0.0F, 1.0F);
 -a[2] = CLAMP(a[2], 0.0F, 1.0F);
 -a[3] = CLAMP(a[3], 0.0F, 1.0F);
 -ubx = F_TO_I(255.0F * a[0]);
 -uby = F_TO_I(255.0F * a[1]);
 -ubz = F_TO_I(255.0F * a[2]);
 -ubw = F_TO_I(255.0F * a[3]);
 -result[0] =
 -result[1] =
 -result[2] =
 -result[3] = ubx | (uby  8) | (ubz  16) | (ubw  24);
 -store_vector4ui(inst, machine, result);
 - }
 - break;
case OPCODE_POW:
   {
  GLfloat a[4], b[4], result[4];
 @@ -1224,20 +1153,6 @@ _mesa_execute_program(struct gl_context * ctx,
  pc = machine-CallStack[--machine-StackDepth] - 1;
   }
   break;
 -  case OPCODE_RFL: /* reflection vector */
 - {
 -GLfloat axis[4], dir[4], result[4], tmpX, tmpW;
 -fetch_vector4(inst-SrcReg[0], machine, axis);
 -fetch_vector4(inst-SrcReg[1], machine, dir);
 -tmpW = DOT3(axis, axis);
 -tmpX = (2.0F * DOT3(axis, dir)) / tmpW;
 -result[0] = tmpX * axis[0] - dir[0];
 -result[1] = tmpX * axis[1] - dir[1];
 -result[2] = tmpX * axis[2] - dir[2];
 -/* result[3] is never written! XXX enforce in parser! */
 -store_vector4(inst, machine, result);
 - }
 - break;
case OPCODE_RSQ: /* 1 / sqrt() */
   {
  GLfloat a[4], result[4];
 @@ -1562,52 +1477,6 @@ _mesa_execute_program(struct gl_context * ctx,
  

Re: [Mesa-dev] [PATCH 14/20] mesa: Add non-normalized formats support for ubyte packing functions

2014-11-18 Thread Jason Ekstrand
On Tue, Nov 18, 2014 at 12:44 AM, Iago Toral Quiroga ito...@igalia.com
wrote:

 From: Samuel Iglesias Gonsalvez sigles...@igalia.com

 Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
 ---
  src/mesa/main/format_pack.c.mako | 10 +-
  1 file changed, 9 insertions(+), 1 deletion(-)

 diff --git a/src/mesa/main/format_pack.c.mako
 b/src/mesa/main/format_pack.c.mako
 index b9f4656..97adf6e 100644
 --- a/src/mesa/main/format_pack.c.mako
 +++ b/src/mesa/main/format_pack.c.mako
 @@ -84,7 +84,15 @@ pack_ubyte_${f.short_name()}(const GLubyte src[4], void
 *dst)
%endif

${channel_datatype(c)} ${c.name} =
 -  %if c.type == parser.UNSIGNED:
 +  %if not f.is_normalized():
 + %if c.type == parser.FLOAT and c.size == 32:
 +UBYTE_TO_FLOAT(src[${i}]);
 + %elif c.type == parser.FLOAT and c.size == 16:
 +_mesa_float_to_half(UBYTE_TO_FLOAT(src[${i}]));


Same question here as in the previous patch.  Why are we using
UBYTE_TO_FLOAT?


 + %else:
 +(${channel_datatype(c)}) src[${i}];
 + %endif
 +  %elif c.type == parser.UNSIGNED:
   %if f.colorspace == 'srgb' and c.name in 'rgb':
  util_format_linear_to_srgb_8unorm(src[${i}]);
   %else:
 --
 1.9.1

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

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


Re: [Mesa-dev] The ARB_shader_subroutine extension

2014-11-18 Thread Gustaw Smolarczyk
Yeah, I understand this concern. But this could be said about any
uber-shader approach. For cases when one cannot afford to change
shader program in between draw calls (using features like multi draw
indirect), it should be better to use shader subroutine arrays instead
of a switch. If the difference in register pressure between the
simplest and the most complex subroutine is not that large, the
problem you described wouldn't exist. One can always batch draw calls
with very simple subroutines separately.

It would be great if there was a possibility to change *the whole*
program for a given draw, so that renderings with simple shaders
wouldn't be penalized by the artificial register pressure caused by
the dynamically unused paths. But I guess, the hardware is unable to
implement such a feature.

2014-11-18 19:51 GMT+01:00 Ian Romanick i...@freedesktop.org:
 On 11/16/2014 08:31 AM, Gustaw Smolarczyk wrote:
 Hello once again,

 This time, I would like to ask about the shader subroutine extension.
 I believe this extension is not very popular, but is still needed for
 GL4 compliance.

 What is the reason for its unpopularity?
 Is it because one needs to reset subroutine uniform values after any glUse*?
 Or it just didn't provide enough value?
 Wouldn't it be good to implement uber-shaders (especially using
 subroutine uniform array)?

 It has a very strong negative affect on register allocation.  Basically,
 the compiler has to, at the very least, allocate registers for the
 worst subroutine.  This means that subroutines that use fewer
 registers will often perform worse (on some GPUs much, much worse) than
 they should.  On Intel GPUs this means that you might just get SIMD8 for
 a shader that could have had SIMD16.  I've been told that on AMD GPUs it
 means you have much fewer vertices or pixels executing in parallel
 leading to dramatic performance hits.

 Is anybody actively working on it? I guess, there are changes needed
 in the GLSL compiler. It could be easily lowered to a
 switch-on-uniform-int thing, or something like that, if only
 compliance to the GL4 matters and not the performance.

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

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


Re: [Mesa-dev] [PATCH] i965/blorp: Fix hiz ops on MSAA surfaces

2014-11-18 Thread Jordan Justen
On 2014-11-18 00:56:02, Kenneth Graunke wrote:
 On Tuesday, November 18, 2014 09:49:53 PM Chris Forbes wrote:
  Two things were broken here:
  - The depth/stencil surface dimensions were broken for MSAA.
  - Sample count was programmed incorrectly.
  
  Result was the depth resolve didn't work correctly on MSAA surfaces, and
  so sampling the surface later produced garbage.
  
  Fixes the new piglit test arb_texture_multisample-sample-depth, and
  various artifacts in 'tesseract' with msaa=4 glineardepth=0.
  
  Not observed any piglit regressions on Haswell.
  
  v2: Just set brw_hiz_op_params::dst.num_samples rather than adding a
  helper function (Ken).
  
  Signed-off-by: Chris Forbes chr...@ijw.co.nz
  ---
   src/mesa/drivers/dri/i965/brw_blorp.cpp  |  1 +
   src/mesa/drivers/dri/i965/gen7_blorp.cpp | 11 +++
   2 files changed, 12 insertions(+)
  
  diff --git a/src/mesa/drivers/dri/i965/brw_blorp.cpp 
 b/src/mesa/drivers/dri/i965/brw_blorp.cpp
  index 20ce7b7..0ecf330 100644
  --- a/src/mesa/drivers/dri/i965/brw_blorp.cpp
  +++ b/src/mesa/drivers/dri/i965/brw_blorp.cpp
  @@ -323,6 +323,7 @@ brw_hiz_op_params::brw_hiz_op_params(struct 
 intel_mipmap_tree *mt,
   */
  depth.width = ALIGN(depth.width, 8);
  depth.height = ALIGN(depth.height, 4);
  +   dst.num_samples = mt-num_samples;
   
  x1 = depth.width;
  y1 = depth.height;
  diff --git a/src/mesa/drivers/dri/i965/gen7_blorp.cpp 
 b/src/mesa/drivers/dri/i965/gen7_blorp.cpp
  index 206a6ff..03fc9c8 100644
  --- a/src/mesa/drivers/dri/i965/gen7_blorp.cpp
  +++ b/src/mesa/drivers/dri/i965/gen7_blorp.cpp
  @@ -663,6 +663,17 @@ gen7_blorp_emit_depth_stencil_config(struct 
  brw_context 
 *brw,
  */
 surfwidth = params-depth.width;
 surfheight = params-depth.height;
  +
  +  if (params-dst.num_samples  1) {
  + /* If this is an MSAA + HIZ op, we need to program the
  +  * aligned logical size of the depth surface.
  +  */
  + surfwidth = ALIGN(params-depth.mt-logical_width0, 8);
  + surfheight = ALIGN(params-depth.mt-logical_height0, 4);

Would something like this cover all cases?

   surfwidth = params-depth.mt-logical_width0;
   surfheight = params-depth.mt-logical_height0;

   if (params-hiz_op != GEN6_HIZ_OP_NONE  lod == 0) {
   surfwidth = ALIGN(surfwidth, 8);
   surfheight = ALIGN(surfheight, 4);
   }

  +  } else {
  + surfwidth = params-depth.width;
  + surfheight = params-depth.height;

Duplicate of the code just above.

-Jordan

  +  }
  } else {
 surfwidth = params-depth.mt-logical_width0;
 surfheight = params-depth.mt-logical_height0;
  
 
 Jordan, Chad...could one of you take a look at this?  It looks reasonable, 
 but 
 I always get confused by when/where we do rounding in BLORP.
 
 Chris - we might want to Cc this to stable too.
 
 --Ken
 
 ___
 mesa-dev mailing list
 mesa-dev@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 16/20] mesa/formats: add new mesa formats and their pack/unpack functions.

2014-11-18 Thread Jason Ekstrand
On Tue, Nov 18, 2014 at 12:44 AM, Iago Toral Quiroga ito...@igalia.com
wrote:

 From: Samuel Iglesias Gonsalvez sigles...@igalia.com

 This  will be used to refactor code in pack.c and support conversion
 to/from these types in a master convert function that will be added
 later.

 Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
 ---
  src/mesa/main/format_pack.c.mako   |  36 -
  src/mesa/main/format_unpack.c.mako |  35 -
  src/mesa/main/formats.c| 104
 +
  src/mesa/main/formats.csv  |  13 +
  src/mesa/main/formats.h|  15 ++
  src/mesa/swrast/s_texfetch.c   |  13 +
  6 files changed, 212 insertions(+), 4 deletions(-)

 diff --git a/src/mesa/main/format_pack.c.mako
 b/src/mesa/main/format_pack.c.mako
 index b846702..c5ad623 100644
 --- a/src/mesa/main/format_pack.c.mako
 +++ b/src/mesa/main/format_pack.c.mako
 @@ -68,7 +68,7 @@ for f in formats:
  /* ubyte packing functions */

  %for f in rgb_formats:
 -   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT',
 'MESA_FORMAT_R11G11B10_FLOAT'):
 +   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT',
 'MESA_FORMAT_R11G11B10_FLOAT', 'MESA_FORMAT_A2R10G10B10_UNORM'):
% continue %
 %elif f.is_compressed():
% continue %
 @@ -137,6 +137,22 @@ pack_ubyte_${f.short_name()}(const GLubyte src[4],
 void *dst)
  %endfor

  static inline void
 +pack_ubyte_a2r10g10b10_unorm(const GLubyte src[4], void *dst)
 +{
 +uint8_t  a = _mesa_unorm_to_unorm(src[3], 8, 2);
 +uint16_t r = _mesa_unorm_to_unorm(src[0], 8, 10);
 +uint16_t g = _mesa_unorm_to_unorm(src[1], 8, 10);
 +uint16_t b = _mesa_unorm_to_unorm(src[2], 8, 10);
 +
 +uint32_t d = 0;
 +d |= PACK(a, 0, 2);
 +d |= PACK(r, 2, 10);
 +d |= PACK(g, 12, 10);
 +d |= PACK(b, 22, 10);
 +(*(uint32_t *) dst) = d;
 +}


The autogen code should be able to handle this.  There's no reason for
special-casing it.  The only reason those other two are a special case is
that they involve strange floating-bit computations.


 +
 +static inline void
  pack_ubyte_r9g9b9e5_float(const GLubyte src[4], void *dst)
  {
 GLuint *d = (GLuint *) dst;
 @@ -311,7 +327,7 @@ pack_int_r11g11b10_float(const GLint src[4], void *dst)
  /* float packing functions */

  %for f in rgb_formats:
 -   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT',
 'MESA_FORMAT_R11G11B10_FLOAT'):
 +   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT',
 'MESA_FORMAT_R11G11B10_FLOAT', 'MESA_FORMAT_A2R10G10B10_UNORM'):
% continue %
 %elif f.is_compressed():
% continue %
 @@ -373,6 +389,22 @@ pack_float_${f.short_name()}(const GLfloat src[4],
 void *dst)
  %endfor

  static inline void
 +pack_float_a2r10g10b10_unorm(const GLfloat src[4], void *dst)
 +{
 +uint8_t  a = _mesa_float_to_unorm(src[3], 2);
 +uint16_t r = _mesa_float_to_unorm(src[0], 10);
 +uint16_t g = _mesa_float_to_unorm(src[1], 10);
 +uint16_t b = _mesa_float_to_unorm(src[2], 10);
 +
 +uint32_t d = 0;
 +d |= PACK(a, 0, 2);
 +d |= PACK(r, 2, 10);
 +d |= PACK(g, 12, 10);
 +d |= PACK(b, 22, 10);
 +(*(uint32_t *) dst) = d;
 +}
 +
 +static inline void
  pack_float_r9g9b9e5_float(const GLfloat src[4], void *dst)
  {
 GLuint *d = (GLuint *) dst;
 diff --git a/src/mesa/main/format_unpack.c.mako
 b/src/mesa/main/format_unpack.c.mako
 index 8fd3cdd..510aed2 100644
 --- a/src/mesa/main/format_unpack.c.mako
 +++ b/src/mesa/main/format_unpack.c.mako
 @@ -67,7 +67,7 @@ for f in formats:
  /* float unpacking functions */

  %for f in rgb_formats:
 -   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT',
 'MESA_FORMAT_R11G11B10_FLOAT'):
 +   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT',
 'MESA_FORMAT_R11G11B10_FLOAT', 'MESA_FORMAT_A2R10G10B10_UNORM'):
% continue %
 %elif f.is_compressed():
% continue %
 @@ -128,6 +128,21 @@ unpack_float_${f.short_name()}(const void *void_src,
 GLfloat dst[4])
  }
  %endfor

 +static inline void
 +unpack_float_a2r10g10b10_unorm(const void *void_src, GLfloat dst[4])
 +{
 +uint32_t *src = (uint32_t *) void_src;
 +uint8_t a = UNPACK(*src, 0, 2);
 +uint16_t r = UNPACK(*src, 2, 10);
 +uint16_t g = UNPACK(*src, 12, 10);
 +uint16_t b = UNPACK(*src, 22, 10);
 +
 +dst[0] = _mesa_unorm_to_float(r, 10);
 +dst[1] = _mesa_unorm_to_float(g, 10);
 +dst[2] = _mesa_unorm_to_float(b, 10);
 +dst[3] = _mesa_unorm_to_float(a, 2);
 +}
 +
  static void
  unpack_float_r9g9b9e5_float(const void *src, GLfloat dst[4])
  {
 @@ -195,7 +210,9 @@ unpack_float_ycbcr_rev(const void *src, GLfloat
 dst[][4], GLuint n)
  /* ubyte packing functions */

  %for f in rgb_formats:
 -   %if not f.is_normalized():
 +   %if f.name in ('MESA_FORMAT_A2R10G10B10_UNORM'):
 +  % continue %
 +   %elif not f.is_normalized():
% continue %
 %endif

 @@ -254,6 +271,20 @@ unpack_ubyte_${f.short_name()}(const void *void_src,
 GLubyte dst[4])
  }
  %endfor

 +static inline void
 

Re: [Mesa-dev] [PATCH 10/10] mesa: Uniform logging is very, very unlikely

2014-11-18 Thread Anuj Phogat
On Mon, Nov 3, 2014 at 4:23 PM, Ian Romanick i...@freedesktop.org wrote:
 From: Ian Romanick ian.d.roman...@intel.com

 Signed-off-by: Ian Romanick ian.d.roman...@intel.com
 ---
  src/mesa/main/uniform_query.cpp | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

 diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
 index f971ba1..32870d0 100644
 --- a/src/mesa/main/uniform_query.cpp
 +++ b/src/mesa/main/uniform_query.cpp
 @@ -634,7 +634,7 @@ _mesa_uniform(struct gl_context *ctx, struct 
 gl_shader_program *shProg,
return;
 }

 -   if (ctx-_Shader-Flags  GLSL_UNIFORMS) {
 +   if (unlikely(ctx-_Shader-Flags  GLSL_UNIFORMS)) {
log_uniform(values, basicType, components, 1, count,
   false, shProg, location, uni);
 }
 @@ -846,7 +846,7 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct 
 gl_shader_program *shProg,
}
 }

 -   if (ctx-_Shader-Flags  GLSL_UNIFORMS) {
 +   if (unlikely(ctx-_Shader-Flags  GLSL_UNIFORMS)) {
log_uniform(values, GLSL_TYPE_FLOAT, components, vectors, count,
   bool(transpose), shProg, location, uni);
 }
 --
 1.8.1.4

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

Series is Reviewed-by: Anuj Phogat anuj.pho...@gmail.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] i965/disasm: Properly decode branch_ctrl (gen8+)

2014-11-18 Thread Ben Widawsky
Add support for decoding the new branch control bit. I saw two things wrong with
the existing code.

1. It didn't bother trying to decode the bit.
-  While we do not *intentionally* emit this bit today, I think it's interesting
   to see if we somehow ended up with the bit set. It may also be useful in the
   future.

2. It seemed to be the wrong bit.
-  The docs are pretty poor wrt which bit this actually occupies. To me, it
   /looks/ like it should be bit 28. I am not sure where Ken got 30 from. I
   verified it should be 28 by looking at the simulator code.

I also added the most basic support for GOTO simply so we don't need to remember
to change the function in the future.

Cc: Kenneth Graunke kenn...@whitecape.org
Signed-off-by: Ben Widawsky b...@bwidawsk.net
---
 src/mesa/drivers/dri/i965/brw_defines.h |  1 +
 src/mesa/drivers/dri/i965/brw_disasm.c  | 29 ++---
 src/mesa/drivers/dri/i965/brw_inst.h|  2 +-
 3 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_defines.h 
b/src/mesa/drivers/dri/i965/brw_defines.h
index 53cd75e..ed94bcc 100644
--- a/src/mesa/drivers/dri/i965/brw_defines.h
+++ b/src/mesa/drivers/dri/i965/brw_defines.h
@@ -820,6 +820,7 @@ enum opcode {
BRW_OPCODE_MSAVE =  44,  /** Pre-Gen6 */
BRW_OPCODE_MRESTORE = 45, /** Pre-Gen6 */
BRW_OPCODE_PUSH =   46,  /** Pre-Gen6 */
+   BRW_OPCODE_GOTO =   46,  /** Gen8+*/
BRW_OPCODE_POP =47,  /** Pre-Gen6 */
BRW_OPCODE_WAIT =   48,
BRW_OPCODE_SEND =   49,
diff --git a/src/mesa/drivers/dri/i965/brw_disasm.c 
b/src/mesa/drivers/dri/i965/brw_disasm.c
index 53ec767..013058e 100644
--- a/src/mesa/drivers/dri/i965/brw_disasm.c
+++ b/src/mesa/drivers/dri/i965/brw_disasm.c
@@ -131,6 +131,18 @@ has_uip(struct brw_context *brw, enum opcode opcode)
 }
 
 static bool
+has_branch_ctrl(struct brw_context *brw, enum opcode opcode)
+{
+   if (brw-gen  8)
+  return false;
+
+   return opcode == BRW_OPCODE_IF ||
+  opcode == BRW_OPCODE_ELSE ||
+  opcode == BRW_OPCODE_GOTO ||
+  opcode == BRW_OPCODE_ENDIF;
+}
+
+static bool
 is_logic_instruction(unsigned opcode)
 {
return opcode == BRW_OPCODE_AND ||
@@ -217,6 +229,11 @@ static const char *const accwr[2] = {
[1] = AccWrEnable
 };
 
+static const char *const branch_ctrl[2] = {
+   [0] = ,
+   [1] = BranchCtrl
+};
+
 static const char *const wectrl[2] = {
[0] = ,
[1] = WE_all
@@ -1544,9 +1561,15 @@ brw_disassemble_inst(FILE *file, struct brw_context 
*brw, brw_inst *inst,
   err |= control(file, compaction, cmpt_ctrl, is_compacted, space);
   err |= control(file, thread control, thread_ctrl,
  brw_inst_thread_control(brw, inst), space);
-  if (brw-gen = 6)
- err |= control(file, acc write control, accwr,
-brw_inst_acc_wr_control(brw, inst), space);
+  if (brw-gen = 6) {
+ if (has_branch_ctrl(brw, opcode)) {
+err |= control(file, branch ctrl, branch_ctrl,
+   brw_inst_branch_control(brw, inst), space);
+ } else {
+err |= control(file, acc write control, accwr,
+   brw_inst_acc_wr_control(brw, inst), space);
+ }
+  }
   if (opcode == BRW_OPCODE_SEND || opcode == BRW_OPCODE_SENDC)
  err |= control(file, end of thread, end_of_thread,
 brw_inst_eot(brw, inst), space);
diff --git a/src/mesa/drivers/dri/i965/brw_inst.h 
b/src/mesa/drivers/dri/i965/brw_inst.h
index c1ff10d..372aa2b 100644
--- a/src/mesa/drivers/dri/i965/brw_inst.h
+++ b/src/mesa/drivers/dri/i965/brw_inst.h
@@ -169,9 +169,9 @@ FF(flag_reg_nr,
/* 8: */ 33, 33)
 F8(flag_subreg_nr, /* 4+ */  89, 89, /* 8+ */ 32, 32)
 F(saturate, 31,  31)
-FC(branch_control,  30,  30, brw-gen = 8)
 F(debug_control,30,  30)
 F(cmpt_control, 29,  29)
+FC(branch_control,  28,  28, brw-gen = 8)
 F(acc_wr_control,   28,  28)
 F(cond_modifier,27,  24)
 FC(math_function,   27,  24, brw-gen = 6)
-- 
2.1.3

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


Re: [Mesa-dev] [PATCH v3 0/9] Gallium Nine

2014-11-18 Thread Stefan Dösinger
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Am 2014-11-18 19:36, schrieb Henri Verbeet:
 To clarify, that's not what I said. It's mostly just that I'd like
 to see some actual evidence for the (implicit) claim that the
 performance difference is largely due to inherent OpenGL API
 overhead.
I have some microbenchmarks to measure API overhead of d3d and GL here:


https://stefandoesinger.ddns.net/~git/perftest/
(self-signed cert)
Binaries are here:
https://stefandoesinger.ddns.net/~stefan/pts/

I had a chat with mannerov (I guess he's Axel Davy, according to
/whois) on IRC, and he ran the drawprim and clear tests with gallium
nine, wined3d and GL. His results show pretty much the same result in
gallium nine and wined3d, and the GL result handily beats both of them.

Mannerov says his system doesn't show a big difference in real games
between wined3d and nine, so it would be nice to have more test
results from other people who see a big difference in real-world games.

Those benchmarks would be a first step in pointing out overhead
differences between nine and wined3d and give some hints where they
are. The GL result should show if the difference is due to overhead
inside wined3d or the Mesa GL frontend.

Obviously more tests are needed. The tests so far just cover plain
draws, stream source changes, clears and vertex buffer uploads. I
suspect that a major source of overhead are shader changes and / or
shader constant / uniform changes. And so far all of those tests only
cover CPU-side performance problems.

-BEGIN PGP SIGNATURE-
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJUa7hjAAoJEN0/YqbEcdMwdoAP/1F9PL1VFbQcRnhBcv6sb1tp
6+R0Yx63U1f3OVfDmQ2qtgIq0Tj27G4KyfDRrNeHYygYxMGiWJm4ksHmb1E25WND
7TXLvcOdb5ZyFX9I1JPLR/fmA112DB/OzxYdvfCeLn2dS7zk7pvZ73Bz/NfugI6/
+k4GpP3/X9oGvcdy6JAMZ5SX7/7i3aFom0Ak2C+4vhKtdN/gslxitweH6DbkIT6g
ogKTakj+sHV+dYHXwzpCMa3w1ZRK3A4VDRrVbJ/dXUOr+li774dlQaMQE3t7tjDK
3ax2sH7VcF4kCQnc3eocHDKAH8tjAffRWxLxW5F94AlPb14p9BAUCkvYGkb+KEfR
DH4JIX5aJXSvNPLHLjQwDhvhbC2cEr8iMTCerHJllVJjROeXEbvsukj0rkMPAgjP
aicp0fMQyS84GTKj0mwJ2fWZ/ja/UeZwOQv+4rj5adpv7X+pDm9C89dL0mOPWRn/
o73ObJkiAVR0XMqnUfAK5CEziLA985Hg8Fen1hGC221GVpwj+QMQp4dMRJkrLR17
BZgjv18TR40yQLPKGeNv+JbJVdbvZ4XzE0tAWuFpaefBOp2txt26P0KCz2iS58+H
zOa6FxYDC5nMRIWqI4zCF4sKDz5JD0ymn8aYIgWubFEevwyzt7Ql2EACq62S4aYD
N4Xb+Rjk0fu3ihPJiTuz
=qxzo
-END PGP SIGNATURE-
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 00/20] Auto-generate pack/unpack functions

2014-11-18 Thread Jason Ekstrand
Iago,
Most of this looks pretty good to me.  The one primary concern I have is in
the handling of integer formats.  I made the comment in a couple of
patches, but I'll make it in general here.  In a lot of the code, when you
convert from integer formats to float, you treat them as if they are
normalized.  Can you explain why you are doing this?  It seems very wrong
to me.

One other issue is that I couldn't actually get it to compile.  This is
probably due to the fact that I always build out-of-tree, so sourcedir and
builddir are not the same.  Not really sure what's going on there.

Other than that, It's looking pretty good.  I'll try and get to reviewing
your second patch series tomorrow.  Since my R-B obviously doesn't mean
much on the code I wrote I'll try and dig up a second reviewer as well.
--Jason

On Tue, Nov 18, 2014 at 12:43 AM, Iago Toral Quiroga ito...@igalia.com
wrote:

 This is the fist of two series of patches to address:
 https://bugs.freedesktop.org/show_bug.cgi?id=84566

 The idea is that we have a lot of format conversion code scattered through
 different files in the repository, a lot of that is redundant / duplicated,
 so this intends to address that issue.

 The goal of this first series is to address auto-generation of our
 pack/unpack
 functions (format_pack.c and format_unpack.c). Currently, we  have a ton of
 hand-coded pack/unpack functions for lots of formats, but we can
 auto-generate
 most of that code instead, so this series handles this.

 This is based on initial work by Jason Ekstrand.

 Tested on i965, classic swrast and gallium (radeon, nouveau, llvmpipe)
 without
 regressions.

 For software drivers we worked with a trimmed set of piglit tests (related
 to
 format conversion), ~5700 tests selected with the following filter:

 -t format -t color -t tex -t image -t swizzle -t clamp -t rgb -t lum -t pix
 -t fbo -t frame

 Summary of the patches:
  * Patches 1-7 are general fixes to the current code that were found while
working on this.
  * Patches 8-16 implement auto-generation of pack/unpack functions.
  * Patches 17-20 make use of the auto-generated pack/unpack functions in
various places to simplify the current code.

 Notice that some of the fixes in patches 1-7 will become obsolete as soon
 as
 we auto-generate the pack/unpack functions, but we thought it would make
 sense
 to keep them in the patch set anyway since we started from that base and
 they
 should be correct fixes to the currently existing code.

 Iago Toral Quiroga (1):
   swrast: Remove unused variable.

 Jason Ekstrand (9):
   mesa/format_utils: Fix a bug in one of the format helper functions
   mesa: Fix packing/unpacking of MESA_FORMAT_R5G6B5_UNORM
   mesa/colormac: Remove an unused macro
   mesa: Fix A1R5G5B5 packing/unpacking
   mesa/format_utils: Prefix and expose the conversion helper functions
   mesa: Add a concept of an array format
   mesa: Add a _mesa_is_format_color_format helper
   mesa: Autogenerate most of format_pack.c
   mesa: Autogenerate format_unpack.c

 Samuel Iglesias Gonsalvez (10):
   mesa: Fix get_texbuffer_format().
   mesa: Fix _mesa_swizzle_and_convert integer conversions to clamp
 properly
   mesa: Add _mesa_pack_uint_rgba_row() format conversion function
   mesa: Add non-normalized formats support for ubyte packing functions
   mesa/format_pack: Add _mesa_pack_int_rgba_row()
   mesa/formats: add new mesa formats and their pack/unpack functions.
   mesa: use format conversion functions in swrast
   mesa/pack: use autogenerated format_pack functions
   mesa/main/pack_tmp.h: Add float conversion support
   mesa/pack: refactor _mesa_pack_rgba_span_float()

  src/mesa/Makefile.am   |   18 +
  src/mesa/Makefile.sources  |4 +-
  src/mesa/main/colormac.h   |3 -
  src/mesa/main/format_convert.py|   71 +
  src/mesa/main/format_info.py   |   41 +
  src/mesa/main/format_pack.c| 2994 
  src/mesa/main/format_pack.c.mako   | 1147 ++
  src/mesa/main/format_pack.h|6 +
  src/mesa/main/format_unpack.c  | 4400
 
  src/mesa/main/format_unpack.c.mako |  914 
  src/mesa/main/format_utils.c   |  248 +-
  src/mesa/main/format_utils.h   |  105 +
  src/mesa/main/formats.c|  193 +-
  src/mesa/main/formats.csv  |   13 +
  src/mesa/main/formats.h|   73 +
  src/mesa/main/pack.c   | 2111 +++--
  src/mesa/main/pack_tmp.h   |   76 +-
  src/mesa/main/run_mako.py  |7 +
  src/mesa/main/teximage.c   |4 +-
  src/mesa/main/texstore.c   |2 +-
  src/mesa/swrast/s_drawpix.c|3 -
  src/mesa/swrast/s_texfetch.c   |   13 +
  src/mesa/swrast/s_texfetch_tmp.h   | 1359 +--
  23 files changed, 3222 insertions(+), 10583 deletions(-)
  create mode 100644 src/mesa/main/format_convert.py
  delete mode 100644 src/mesa/main/format_pack.c
  

Re: [Mesa-dev] [PATCH 00/20] Auto-generate pack/unpack functions

2014-11-18 Thread Jose Fonseca

On 18/11/14 17:10, Jason Ekstrand wrote:

Jose,
I haven't had time to fully review Iago and Samuel's code, so I can't
100% comment on it right now.  However, let me make a few comments on
the overarching plan as it were.

On Tue, Nov 18, 2014 at 2:36 AM, Jose Fonseca jfons...@vmware.com
mailto:jfons...@vmware.com wrote:

 The idea is that we have a lot of format conversion code scattered through
 different files in the repository, a lot of that is redundant / 
duplicated,
 so this intends to address that issue.

First, I think this is a great goal.  And while I haven't reviewed
them in detail, just from skimming through them, these patch series
seem to be a great cleanup and a lot of work went into it.  I
certainly don't object to any of this.



But I have to say I find a bit unfortunate that so much effort is
being put on implementing something specific to Mesa formats instead
of taking this opportunity to devise a solution that would work both
for gallium and Mesa formats.


That is the end goal.  Unfortunately, getting there requires a lot of
work.  Probably more work on the mesa side than on the gallium side.  A
big part of the problem was that there was a lot of code for format
conversion and it was scattered all over mesa/main directory.  A lot of
stuff needs to be cleaned up an unified inside mesa/main before things
can be unified with gallium.  Much of that work is now done.



One of the things that I would like to see happen after this stuff lands
is to convert the mesa pack/unpack functions to take a width, height,
and stride.  Then they would have exactly the same function signature as
the gallium conversion functions and merging will be much easier.  Then
we can work on moving the format handling code into a helper library
which, for the moment, I'll call libmesaformat.  Then both gallium and
mesa classic can pull from libmesaformat and we can kill all of the
redundant code.  Whose autogenerator framework we end up keeping is kind
of immaterial, they're not that hard to write.


Oh, got it now. Sounds great then.


One of the decisions that has to be made there (probably a topic for
another thread) is how we would want to structure the format metadata.
Mesa and gallium both have completely different ways of structuring it
and we need to unify that if we're going to unify the conversion code.
Personally, I think gallium's is cleaner and more expressive, but it
lacks the GL information that core mesa needs.  But, like I said, that's
a topic for another thread.

Furthermore I see there is some interest speeding mesa using SSE2
intrinsics, and of course format conversion is precisely one of the
code paths that can great benefit from SIMD, but I have no doubt:
the most efficient and sane way of leveraging SIMD with all these
formats conversion is to JIT compile format conversion code tailored
to the CPU in runtime.  There are just too many CPU variations to
statically generate C code for every one of them.  And lot of the
code to do this already exists in src/gallium/auxiliary/gallivm.  We
should consider using it from src/mesa/*.


Yes, there were some patches.  However, given my experiments in the
past, I'm skeptical as to how much of a real benefit it would be to
SSE-accelerate all the format conversion.  When I did my first major
rework a couple of months ago, I experimented with using the SSSE3
shuffle operation for doing swizzling of the C implementation.  The net
result of that experiment is that using SSSE3 had a very marginal
benefit over a good C implementation such as the one we now have.  The
real problem we had was that the current format conversion stuff was
doing the pessimal thing in a lot of cases;  a lot of that stupid is now
gone.  So, if someone wants to work on that, I'm curious to see their
results, but I'm not holding out for it.

As far as doing a JIT compile, I've thought of it.  Daniel Stone
recently mentioned the idea of using ORC for doing things like this and
it might be a good fit.


I never heard of ORC, and I didn't get any relevant hits from google. 
What is it?



However, be fore we can do that, we need a
framework for these things (which we now have, thanks to this series).
How is that done in gallivm?  Is it done using LLVM?  If so, it might be
a non-starter.  I don't want to rekindle any debates, but you're going
to have trouble convincing some people that format conversion is a good
enough reason for a hard dependency on LLVM.


Yes, it's done with LLVM.

But note that when using LLVM as a JIT for CPU the we practically only 
use the LLVM C API, whose ABI is stable across any LLVM version.  (We 
use a bit of C++ in gallivm/llvmpipe just for a few minor omissions of 
the LLVM C API but that's something we can and should fix.  Just a 
matter of upstreaming that functionality.)


In other words, I'm not aware of any technical/logistic argument against 
using LLVM C API as a CPU 

[Mesa-dev] [PATCH 2/2] llvmpipe: enable PIPE_CAP_TGSI_VS_LAYER_VIEWPORT

2014-11-18 Thread sroland
From: Roland Scheidegger srol...@vmware.com

No changes required in the driver itself, all handled by draw.

piglit results in a quick run:
skip-pass 7
skip-fail 2
(The new failures in the ARB_fragment_layer_viewport group are expected,
we fail the same if gs doesn't write these outputs regardless of the vs.)
---
 src/gallium/drivers/llvmpipe/lp_screen.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index cec0fcb..e10e83e 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -245,6 +245,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum 
pipe_cap param)
case PIPE_CAP_ENDIANNESS:
   return PIPE_ENDIAN_NATIVE;
case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
+  return 1;
case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
case PIPE_CAP_TEXTURE_GATHER_SM5:
case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
-- 
1.9.1

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


[Mesa-dev] [PATCH 1/2] draw: fixes for vertex shaders outputting layer or viewport index

2014-11-18 Thread sroland
From: Roland Scheidegger srol...@vmware.com

Mostly add a couple cases so we don't just check gs for this.
There's only one gotcha, the built-in vp transform in the llvm vs can't
handle it (this would be fixable though non-trivial due to vp index being
non-constant for the SoA outputs, but we don't use it if there's a gs
neither - the whole clip/vp transform integration there is suboptimal).
---
 src/gallium/auxiliary/draw/draw_context.c |  4 ++--
 src/gallium/auxiliary/draw/draw_llvm.c|  6 +-
 .../auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c|  6 +++---
 src/gallium/auxiliary/draw/draw_pt_post_vs.c  |  2 +-
 src/gallium/auxiliary/draw/draw_vs.c  |  4 +++-
 src/gallium/auxiliary/draw/draw_vs.h  |  1 +
 src/gallium/auxiliary/tgsi/tgsi_scan.c| 15 ++-
 7 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_context.c 
b/src/gallium/auxiliary/draw/draw_context.c
index bb8c03c..f46f8b4 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -806,7 +806,7 @@ draw_current_shader_viewport_index_output(const struct 
draw_context *draw)
 {
if (draw-gs.geometry_shader)
   return draw-gs.geometry_shader-viewport_index_output;
-   return 0;
+   return draw-vs.vertex_shader-viewport_index_output;
 }
 
 /**
@@ -818,7 +818,7 @@ draw_current_shader_uses_viewport_index(const struct 
draw_context *draw)
 {
if (draw-gs.geometry_shader)
   return draw-gs.geometry_shader-info.writes_viewport_index;
-   return FALSE;
+   return draw-vs.vertex_shader-info.writes_viewport_index;
 }
 
 
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c 
b/src/gallium/auxiliary/draw/draw_llvm.c
index b6a9713..43d11f7 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -1522,8 +1522,12 @@ draw_llvm_generate(struct draw_llvm *llvm, struct 
draw_llvm_variant *variant,
/* If geometry shader is present we need to skip both the viewport
 * transformation and clipping otherwise the inputs to the geometry
 * shader will be incorrect.
+* The code can't handle vp transform when vs writes vp index neither
+* (though this would be fixable here, but couldn't just broadcast
+* the values).
 */
-   const boolean bypass_viewport = key-has_gs || key-bypass_viewport;
+   const boolean bypass_viewport = key-has_gs || key-bypass_viewport ||
+   
llvm-draw-vs.vertex_shader-info.writes_viewport_index;
const boolean enable_cliptest = !key-has_gs  (key-clip_xy ||
 key-clip_z  ||
 key-clip_user);
diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c 
b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
index 49341ff..cc83736 100644
--- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
@@ -169,8 +169,7 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
draw_pt_so_emit_prepare( fpme-so_emit, gs == NULL );
 
if (!(opt  PT_PIPELINE)) {
-  draw_pt_emit_prepare( fpme-emit,
-   out_prim,
+  draw_pt_emit_prepare( fpme-emit, out_prim,
 max_vertices );
 
   *max_vertices = MAX2( *max_vertices, 4096 );
@@ -442,7 +441,8 @@ llvm_pipeline_generic(struct draw_pt_middle_end *middle,
 * will try to access non-existent position output.
 */
if (draw_current_shader_position_output(draw) != -1) {
-  if ((opt  PT_SHADE)  gshader) {
+  if ((opt  PT_SHADE)  (gshader ||
+   
draw-vs.vertex_shader-info.writes_viewport_index)) {
  clipped = draw_pt_post_vs_run( fpme-post_vs, vert_info, prim_info );
   }
   if (clipped) {
diff --git a/src/gallium/auxiliary/draw/draw_pt_post_vs.c 
b/src/gallium/auxiliary/draw/draw_pt_post_vs.c
index 9279cd1..71a7d39 100644
--- a/src/gallium/auxiliary/draw/draw_pt_post_vs.c
+++ b/src/gallium/auxiliary/draw/draw_pt_post_vs.c
@@ -117,7 +117,7 @@ dot4(const float *a, const float *b)
 
 
 boolean draw_pt_post_vs_run( struct pt_post_vs *pvs,
-struct draw_vertex_info *info,
+ struct draw_vertex_info *info,
  const struct draw_prim_info *prim_info )
 {
return pvs-run( pvs, info, prim_info );
diff --git a/src/gallium/auxiliary/draw/draw_vs.c 
b/src/gallium/auxiliary/draw/draw_vs.c
index dc50870..f24354e 100644
--- a/src/gallium/auxiliary/draw/draw_vs.c
+++ b/src/gallium/auxiliary/draw/draw_vs.c
@@ -85,7 +85,9 @@ draw_create_vertex_shader(struct draw_context *draw,
   vs-info.output_semantic_index[i] == 0) {
 found_clipvertex = TRUE;
 

Re: [Mesa-dev] [PATCH 2/2] llvmpipe: enable PIPE_CAP_TGSI_VS_LAYER_VIEWPORT

2014-11-18 Thread Jose Fonseca

Series LGTM.

Jose

On 18/11/14 22:05, srol...@vmware.com wrote:

From: Roland Scheidegger srol...@vmware.com

No changes required in the driver itself, all handled by draw.

piglit results in a quick run:
skip-pass 7
skip-fail 2
(The new failures in the ARB_fragment_layer_viewport group are expected,
we fail the same if gs doesn't write these outputs regardless of the vs.)
---
  src/gallium/drivers/llvmpipe/lp_screen.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index cec0fcb..e10e83e 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -245,6 +245,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum 
pipe_cap param)
 case PIPE_CAP_ENDIANNESS:
return PIPE_ENDIAN_NATIVE;
 case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
+  return 1;
 case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
 case PIPE_CAP_TEXTURE_GATHER_SM5:
 case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:



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


Re: [Mesa-dev] [PATCH] r600g: geom shaders: always load texture src regs from inputs

2014-11-18 Thread Glenn Kennard

On Tue, 18 Nov 2014 05:09:05 +0100, Dave Airlie airl...@gmail.com wrote:


From: Dave Airlie airl...@redhat.com

Otherwise we seem to lose the split_gs_inputs and try and
pull from an uninitialised register.

fixes 9 texelFetch geom shader tests.

Signed-off-by: Dave Airlie airl...@redhat.com
---
 src/gallium/drivers/r600/r600_shader.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/r600/r600_shader.c  
b/src/gallium/drivers/r600/r600_shader.c

index 709fcd7..ab2a838 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -4919,7 +4919,8 @@ static inline boolean  
tgsi_tex_src_requires_loading(struct r600_shader_ctx *ctx,

return  (inst-Src[index].Register.File != TGSI_FILE_TEMPORARY 
inst-Src[index].Register.File != TGSI_FILE_INPUT 
inst-Src[index].Register.File != TGSI_FILE_OUTPUT) ||
-   ctx-src[index].neg || ctx-src[index].abs;
+   ctx-src[index].neg || ctx-src[index].abs ||
+		(inst-Src[index].Register.File == TGSI_FILE_INPUT  ctx-type ==  
TGSI_PROCESSOR_GEOMETRY);

 }
static inline unsigned tgsi_tex_get_src_gpr(struct r600_shader_ctx *ctx,


Confirmed fixes the same set of tests on a Turks.

Reviewed-by: Glenn Kennard glenn.kenn...@gmail.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] r600g: limit texture offset application to specific types (v2)

2014-11-18 Thread Glenn Kennard

On Tue, 18 Nov 2014 07:59:23 +0100, Dave Airlie airl...@gmail.com wrote:


From: Dave Airlie airl...@redhat.com

For 1D and 2D arrays we don't want the other coordinates being
offset and affecting where we sample. I wrote this patch 6 months
ago but lost it.

Fixes:
./bin/tex-miplevel-selection textureLodOffset 1DArray
./bin/tex-miplevel-selection textureLodOffset 2DArray
./bin/tex-miplevel-selection textureOffset 1DArray
./bin/tex-miplevel-selection textureOffset 1DArrayShadow
./bin/tex-miplevel-selection textureOffset 2DArray
./bin/tex-miplevel-selection textureOffset(bias) 1DArray
./bin/tex-miplevel-selection textureOffset(bias) 2DArray

v2: rewrite to handle more cases and be consistent with code
above.

Signed-off-by: Dave Airlie airl...@redhat.com
---
 src/gallium/drivers/r600/r600_shader.c | 21 ++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/r600/r600_shader.c  
b/src/gallium/drivers/r600/r600_shader.c

index ab2a838..76daf2c 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -5535,9 +5535,24 @@ static int tgsi_tex(struct r600_shader_ctx *ctx)
/* texture offsets do not apply to other 
texture targets */
}
} else {
-			offset_x = ctx-literals[4 * inst-TexOffsets[0].Index +  
inst-TexOffsets[0].SwizzleX]  1;
-			offset_y = ctx-literals[4 * inst-TexOffsets[0].Index +  
inst-TexOffsets[0].SwizzleY]  1;
-			offset_z = ctx-literals[4 * inst-TexOffsets[0].Index +  
inst-TexOffsets[0].SwizzleZ]  1;

+   switch (inst-Texture.Texture) {
+   case TGSI_TEXTURE_3D:
+offset_z = ctx-literals[4 * inst-TexOffsets[0].Index +  
inst-TexOffsets[0].SwizzleZ]  1;

+   /* fallthrough */
+   case TGSI_TEXTURE_2D:
+   case TGSI_TEXTURE_SHADOW2D:
+   case TGSI_TEXTURE_RECT:
+   case TGSI_TEXTURE_SHADOWRECT:
+   case TGSI_TEXTURE_2D_ARRAY:
+   case TGSI_TEXTURE_SHADOW2D_ARRAY:
+offset_y = ctx-literals[4 * inst-TexOffsets[0].Index +  
inst-TexOffsets[0].SwizzleY]  1;

+   /* fallthrough */
+   case TGSI_TEXTURE_1D:
+   case TGSI_TEXTURE_SHADOW1D:
+   case TGSI_TEXTURE_1D_ARRAY:
+   case TGSI_TEXTURE_SHADOW1D_ARRAY:
+offset_x = ctx-literals[4 * inst-TexOffsets[0].Index +  
inst-TexOffsets[0].SwizzleX]  1;

+   }
}
}



Confirmed fixes the same set of tests on a Turks.

Reviewed-by: Glenn Kennard glenn.kenn...@gmail.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH v3 0/9] Gallium Nine

2014-11-18 Thread Emil Velikov
Hi Stefan,

On 18/11/14 21:21, Stefan Dösinger wrote:
 Am 2014-11-18 19:36, schrieb Henri Verbeet:
 To clarify, that's not what I said. It's mostly just that I'd like
 to see some actual evidence for the (implicit) claim that the
 performance difference is largely due to inherent OpenGL API
 overhead.
 I have some microbenchmarks to measure API overhead of d3d and GL here:
 
 
 https://stefandoesinger.ddns.net/~git/perftest/
 (self-signed cert)
 Binaries are here:
 https://stefandoesinger.ddns.net/~stefan/pts/
 
Hmm the binaries do not seem to match the source. Am I missing something ?

 I had a chat with mannerov (I guess he's Axel Davy, according to
 /whois) on IRC, and he ran the drawprim and clear tests with gallium
 nine, wined3d and GL. His results show pretty much the same result in
 gallium nine and wined3d, and the GL result handily beats both of them.
 
 Mannerov says his system doesn't show a big difference in real games
 between wined3d and nine, so it would be nice to have more test
 results from other people who see a big difference in real-world games.
 
Thanks for listing these test publicly. Now more people can give them a
spin thus find some correlation. Or perhaps it's a case that the tests
do not affect code paths that are faster with nine :\

 Those benchmarks would be a first step in pointing out overhead
 differences between nine and wined3d and give some hints where they
 are. The GL result should show if the difference is due to overhead
 inside wined3d or the Mesa GL frontend.
 
 Obviously more tests are needed. The tests so far just cover plain
 draws, stream source changes, clears and vertex buffer uploads. I
 suspect that a major source of overhead are shader changes and / or
 shader constant / uniform changes. And so far all of those tests only
 cover CPU-side performance problems.
 
On of the points in my earlier rant was - if wine is interested solely
on improvements of the current code, and there is no interest/intensive
to include an alternative solution it makes no sense to keep on
pestering you guys.

Thank you for the input.
Emil
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] r600: fix texture gradients instruction emission

2014-11-18 Thread Dave Airlie
From: Dave Airlie airl...@redhat.com

The piglit tests were failing, and it appeared to be SB
optimising out things, but Glenn pointed out the gradients
are meant to be clause local, so we should emit the texture
instructions in the same clause. This moves things around
to always copy to a temp and then emit the texture clauses
for H/V.

Fixes at least:
./bin/tex-miplevel-selection textureGrad 2D

Signed-off-by: Dave Airlie airl...@redhat.com
---
 src/gallium/drivers/r600/r600_shader.c | 55 +-
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/src/gallium/drivers/r600/r600_shader.c 
b/src/gallium/drivers/r600/r600_shader.c
index 76daf2c..5e597df 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -5110,12 +5110,34 @@ static int tgsi_tex(struct r600_shader_ctx *ctx)
}
 
if (inst-Instruction.Opcode == TGSI_OPCODE_TXD) {
+   int temp_h, temp_v;
/* TGSI moves the sampler to src reg 3 for TXD */
sampler_src_reg = 3;
 
sampler_index_mode = inst-Src[sampler_src_reg].Indirect.Index 
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
 
for (i = 1; i  3; i++) {
+   int treg = r600_get_temp(ctx);
+   if (i == 1)
+   temp_h = treg;
+   else
+   temp_v = treg;
+
+   for (j = 0; j  4; j++) {
+   memset(alu, 0, sizeof(struct 
r600_bytecode_alu));
+   alu.op = ALU_OP1_MOV;
+r600_bytecode_src(alu.src[0], ctx-src[i], 
j);
+alu.dst.sel = treg;
+alu.dst.chan = j;
+if (j == 3)
+   alu.last = 1;
+alu.dst.write = 1;
+r = r600_bytecode_add_alu(ctx-bc, alu);
+if (r)
+return r;
+   }
+   }
+   for (i = 1; i  3; i++) {
/* set gradients h/v */
memset(tex, 0, sizeof(struct r600_bytecode_tex));
tex.op = (i == 1) ? FETCH_OP_SET_GRADIENTS_H :
@@ -5125,35 +5147,12 @@ static int tgsi_tex(struct r600_shader_ctx *ctx)
tex.resource_id = tex.sampler_id + 
R600_MAX_CONST_BUFFERS;
tex.resource_index_mode = sampler_index_mode;
 
-   if (tgsi_tex_src_requires_loading(ctx, i)) {
-   tex.src_gpr = r600_get_temp(ctx);
-   tex.src_sel_x = 0;
-   tex.src_sel_y = 1;
-   tex.src_sel_z = 2;
-   tex.src_sel_w = 3;
-
-   for (j = 0; j  4; j++) {
-   memset(alu, 0, sizeof(struct 
r600_bytecode_alu));
-   alu.op = ALU_OP1_MOV;
-r600_bytecode_src(alu.src[0], 
ctx-src[i], j);
-alu.dst.sel = tex.src_gpr;
-alu.dst.chan = j;
-if (j == 3)
-alu.last = 1;
-alu.dst.write = 1;
-r = r600_bytecode_add_alu(ctx-bc, 
alu);
-if (r)
-return r;
-   }
+   tex.src_gpr = (i == 1) ? temp_h : temp_v;
+   tex.src_sel_x = 0;
+   tex.src_sel_y = 1;
+   tex.src_sel_z = 2;
+   tex.src_sel_w = 3;
 
-   } else {
-   tex.src_gpr = tgsi_tex_get_src_gpr(ctx, i);
-   tex.src_sel_x = ctx-src[i].swizzle[0];
-   tex.src_sel_y = ctx-src[i].swizzle[1];
-   tex.src_sel_z = ctx-src[i].swizzle[2];
-   tex.src_sel_w = ctx-src[i].swizzle[3];
-   tex.src_rel = ctx-src[i].rel;
-   }
tex.dst_gpr = ctx-temp_reg; /* just to avoid confusing 
the asm scheduler */
tex.dst_sel_x = tex.dst_sel_y = tex.dst_sel_z = 
tex.dst_sel_w = 7;
if (inst-Texture.Texture != TGSI_TEXTURE_RECT) {
-- 
1.9.3

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


Re: [Mesa-dev] [PATCH 00/20] Auto-generate pack/unpack functions

2014-11-18 Thread Jason Ekstrand
On Tue, Nov 18, 2014 at 1:42 PM, Jose Fonseca jfons...@vmware.com wrote:

 On 18/11/14 17:10, Jason Ekstrand wrote:

 Jose,
 I haven't had time to fully review Iago and Samuel's code, so I can't
 100% comment on it right now.  However, let me make a few comments on
 the overarching plan as it were.

 On Tue, Nov 18, 2014 at 2:36 AM, Jose Fonseca jfons...@vmware.com
 mailto:jfons...@vmware.com wrote:

  The idea is that we have a lot of format conversion code scattered
 through
  different files in the repository, a lot of that is redundant /
 duplicated,
  so this intends to address that issue.

 First, I think this is a great goal.  And while I haven't reviewed
 them in detail, just from skimming through them, these patch series
 seem to be a great cleanup and a lot of work went into it.  I
 certainly don't object to any of this.



 But I have to say I find a bit unfortunate that so much effort is
 being put on implementing something specific to Mesa formats instead
 of taking this opportunity to devise a solution that would work both
 for gallium and Mesa formats.


 That is the end goal.  Unfortunately, getting there requires a lot of
 work.  Probably more work on the mesa side than on the gallium side.  A
 big part of the problem was that there was a lot of code for format
 conversion and it was scattered all over mesa/main directory.  A lot of
 stuff needs to be cleaned up an unified inside mesa/main before things
 can be unified with gallium.  Much of that work is now done.

 

 One of the things that I would like to see happen after this stuff lands
 is to convert the mesa pack/unpack functions to take a width, height,
 and stride.  Then they would have exactly the same function signature as
 the gallium conversion functions and merging will be much easier.  Then
 we can work on moving the format handling code into a helper library
 which, for the moment, I'll call libmesaformat.  Then both gallium and
 mesa classic can pull from libmesaformat and we can kill all of the
 redundant code.  Whose autogenerator framework we end up keeping is kind
 of immaterial, they're not that hard to write.


 Oh, got it now. Sounds great then.


  One of the decisions that has to be made there (probably a topic for
 another thread) is how we would want to structure the format metadata.
 Mesa and gallium both have completely different ways of structuring it
 and we need to unify that if we're going to unify the conversion code.
 Personally, I think gallium's is cleaner and more expressive, but it
 lacks the GL information that core mesa needs.  But, like I said, that's
 a topic for another thread.

 Furthermore I see there is some interest speeding mesa using SSE2
 intrinsics, and of course format conversion is precisely one of the
 code paths that can great benefit from SIMD, but I have no doubt:
 the most efficient and sane way of leveraging SIMD with all these
 formats conversion is to JIT compile format conversion code tailored
 to the CPU in runtime.  There are just too many CPU variations to
 statically generate C code for every one of them.  And lot of the
 code to do this already exists in src/gallium/auxiliary/gallivm.  We
 should consider using it from src/mesa/*.


 Yes, there were some patches.  However, given my experiments in the
 past, I'm skeptical as to how much of a real benefit it would be to
 SSE-accelerate all the format conversion.  When I did my first major
 rework a couple of months ago, I experimented with using the SSSE3
 shuffle operation for doing swizzling of the C implementation.  The net
 result of that experiment is that using SSSE3 had a very marginal
 benefit over a good C implementation such as the one we now have.  The
 real problem we had was that the current format conversion stuff was
 doing the pessimal thing in a lot of cases;  a lot of that stupid is now
 gone.  So, if someone wants to work on that, I'm curious to see their
 results, but I'm not holding out for it.

 As far as doing a JIT compile, I've thought of it.  Daniel Stone
 recently mentioned the idea of using ORC for doing things like this and
 it might be a good fit.


 I never heard of ORC, and I didn't get any relevant hits from google. What
 is it?


It stands for oil runtime compiler.  The homepage, which seems to be down
at the moment, can be found here:  http://code.entropywave.com/orc/ ORC is
a JIT designed for producing highly optimized streaming code that takes
full advantage of CPU features such as SSE.  It's designed for fairly small
kernels that need to be run fast on arrays of data.  I haven't taken more
than a very cursory look at it, so I can't say much more.  Aparently, the
gstreamer people use it for all of their software filters and video
transformations.


  However, be fore we can do that, we need a
 framework for these things (which we now have, thanks to this series).
 How is that done in gallivm?  Is it done 

[Mesa-dev] [PATCH] r600: fix texture gradients instruction emission (v2)

2014-11-18 Thread Dave Airlie
From: Dave Airlie airl...@redhat.com

The piglit tests were failing, and it appeared to be SB
optimising out things, but Glenn pointed out the gradients
are meant to be clause local, so we should emit the texture
instructions in the same clause. This moves things around
to always copy to a temp and then emit the texture clauses
for H/V.

v2: Glenn pointed out we could get another ALU fetch in
the wrong place, so load the src gpr earlier as well.

Fixes at least:
./bin/tex-miplevel-selection textureGrad 2D

Signed-off-by: Dave Airlie airl...@redhat.com
---
 src/gallium/drivers/r600/r600_shader.c | 59 ++
 1 file changed, 31 insertions(+), 28 deletions(-)

diff --git a/src/gallium/drivers/r600/r600_shader.c 
b/src/gallium/drivers/r600/r600_shader.c
index 76daf2c..41caac3 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -5110,11 +5110,37 @@ static int tgsi_tex(struct r600_shader_ctx *ctx)
}
 
if (inst-Instruction.Opcode == TGSI_OPCODE_TXD) {
+   int temp_h, temp_v;
/* TGSI moves the sampler to src reg 3 for TXD */
sampler_src_reg = 3;
 
sampler_index_mode = inst-Src[sampler_src_reg].Indirect.Index 
== 2 ? 2 : 0; // CF_INDEX_1 : CF_INDEX_NONE
 
+   src_loaded = TRUE;
+   for (i = 0; i  3; i++) {
+   int treg = r600_get_temp(ctx);
+
+   if (i == 0)
+   src_gpr = treg;
+   else if (i == 1)
+   temp_h = treg;
+   else
+   temp_v = treg;
+
+   for (j = 0; j  4; j++) {
+   memset(alu, 0, sizeof(struct 
r600_bytecode_alu));
+   alu.op = ALU_OP1_MOV;
+r600_bytecode_src(alu.src[0], ctx-src[i], 
j);
+alu.dst.sel = treg;
+alu.dst.chan = j;
+if (j == 3)
+   alu.last = 1;
+alu.dst.write = 1;
+r = r600_bytecode_add_alu(ctx-bc, alu);
+if (r)
+return r;
+   }
+   }
for (i = 1; i  3; i++) {
/* set gradients h/v */
memset(tex, 0, sizeof(struct r600_bytecode_tex));
@@ -5125,35 +5151,12 @@ static int tgsi_tex(struct r600_shader_ctx *ctx)
tex.resource_id = tex.sampler_id + 
R600_MAX_CONST_BUFFERS;
tex.resource_index_mode = sampler_index_mode;
 
-   if (tgsi_tex_src_requires_loading(ctx, i)) {
-   tex.src_gpr = r600_get_temp(ctx);
-   tex.src_sel_x = 0;
-   tex.src_sel_y = 1;
-   tex.src_sel_z = 2;
-   tex.src_sel_w = 3;
+   tex.src_gpr = (i == 1) ? temp_h : temp_v;
+   tex.src_sel_x = 0;
+   tex.src_sel_y = 1;
+   tex.src_sel_z = 2;
+   tex.src_sel_w = 3;
 
-   for (j = 0; j  4; j++) {
-   memset(alu, 0, sizeof(struct 
r600_bytecode_alu));
-   alu.op = ALU_OP1_MOV;
-r600_bytecode_src(alu.src[0], 
ctx-src[i], j);
-alu.dst.sel = tex.src_gpr;
-alu.dst.chan = j;
-if (j == 3)
-alu.last = 1;
-alu.dst.write = 1;
-r = r600_bytecode_add_alu(ctx-bc, 
alu);
-if (r)
-return r;
-   }
-
-   } else {
-   tex.src_gpr = tgsi_tex_get_src_gpr(ctx, i);
-   tex.src_sel_x = ctx-src[i].swizzle[0];
-   tex.src_sel_y = ctx-src[i].swizzle[1];
-   tex.src_sel_z = ctx-src[i].swizzle[2];
-   tex.src_sel_w = ctx-src[i].swizzle[3];
-   tex.src_rel = ctx-src[i].rel;
-   }
tex.dst_gpr = ctx-temp_reg; /* just to avoid confusing 
the asm scheduler */
tex.dst_sel_x = tex.dst_sel_y = tex.dst_sel_z = 
tex.dst_sel_w = 7;
if (inst-Texture.Texture != TGSI_TEXTURE_RECT) {
-- 
1.9.3


Re: [Mesa-dev] [PATCH] i965/blorp: Fix hiz ops on MSAA surfaces

2014-11-18 Thread Chad Versace

On Tue 18 Nov 2014, Chris Forbes wrote:

Two things were broken here:
- The depth/stencil surface dimensions were broken for MSAA.
- Sample count was programmed incorrectly.

Result was the depth resolve didn't work correctly on MSAA surfaces, and
so sampling the surface later produced garbage.

Fixes the new piglit test arb_texture_multisample-sample-depth, and
various artifacts in 'tesseract' with msaa=4 glineardepth=0.

Not observed any piglit regressions on Haswell.

v2: Just set brw_hiz_op_params::dst.num_samples rather than adding a
   helper function (Ken).

Signed-off-by: Chris Forbes chr...@ijw.co.nz
---
src/mesa/drivers/dri/i965/brw_blorp.cpp  |  1 +
src/mesa/drivers/dri/i965/gen7_blorp.cpp | 11 +++
2 files changed, 12 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_blorp.cpp 
b/src/mesa/drivers/dri/i965/brw_blorp.cpp
index 20ce7b7..0ecf330 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp.cpp
+++ b/src/mesa/drivers/dri/i965/brw_blorp.cpp
@@ -323,6 +323,7 @@ brw_hiz_op_params::brw_hiz_op_params(struct 
intel_mipmap_tree *mt,
*/
   depth.width = ALIGN(depth.width, 8);
   depth.height = ALIGN(depth.height, 4);
+   dst.num_samples = mt-num_samples;

   x1 = depth.width;
   y1 = depth.height;
diff --git a/src/mesa/drivers/dri/i965/gen7_blorp.cpp 
b/src/mesa/drivers/dri/i965/gen7_blorp.cpp
index 206a6ff..03fc9c8 100644
--- a/src/mesa/drivers/dri/i965/gen7_blorp.cpp
+++ b/src/mesa/drivers/dri/i965/gen7_blorp.cpp
@@ -663,6 +663,17 @@ gen7_blorp_emit_depth_stencil_config(struct brw_context 
*brw,
   */
  surfwidth = params-depth.width;
  surfheight = params-depth.height;
+
+  if (params-dst.num_samples  1) {
+ /* If this is an MSAA + HIZ op, we need to program the
+  * aligned logical size of the depth surface.
+  */
+ surfwidth = ALIGN(params-depth.mt-logical_width0, 8);
+ surfheight = ALIGN(params-depth.mt-logical_height0, 4);
+  } else {
+ surfwidth = params-depth.width;
+ surfheight = params-depth.height;
+  }


I think the code that aligns up to 8x4 should go into hunk above that 
touches brw_hiz_op_params::brw_hiz_op_params(), because:


   1. That function already does the 8x4 alignment for the non-MSAA
  case. It doesn't make sense to do the 8x4 alignment for MSAA as
  a special case in a different file.
   2. The lengthy comment that explains how alignment works and why 
  it's needed is in that function. This is tricky delicate stuff, 
  so let's put the special cases near the documentation.



   } else {
  surfwidth = params-depth.mt-logical_width0;
  surfheight = params-depth.mt-logical_height0;
--
2.1.3


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


[Mesa-dev] [Bug 54080] glXQueryDrawable fails with GLXBadDrawable for a Window in direct context

2014-11-18 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=54080

Kaveh kaveh.na...@intel.com changed:

   What|Removed |Added

   Assignee|mesa-dev@lists.freedesktop. |n...@linux.intel.com
   |org |

-- 
You are receiving this mail because:
You are the assignee for the bug.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] mesa/main: Fix tmp_row memory leak in texstore_rgba_integer.

2014-11-18 Thread Jason Ekstrand
Pushed.  Thanks!
--Jason

On Sat, Nov 15, 2014 at 7:07 PM, Siavash Eliasi siavashser...@gmail.com
wrote:

  Please push it, I don't have write access.

 Best regards,
 Siavash Eliasi.


 On 11/15/2014 11:06 PM, Jason Ekstrand wrote:

  Good catch!

  Reviewed-by: Jason Ekstrand jason.ekstr...@intel.com

  Can you push or do you need me to?

 On Sat, Nov 15, 2014 at 11:02 AM, Siavash Eliasi siavashser...@gmail.com
 wrote:

 ---
  src/mesa/main/texstore.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

 diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
 index f913e42..f858cef 100644
 --- a/src/mesa/main/texstore.c
 +++ b/src/mesa/main/texstore.c
 @@ -1667,8 +1667,10 @@ texstore_rgba_integer(TEXSTORE_PARAMS)

 assert(is_array  !normalized);

 -   if (!is_array)
 +   if (!is_array) {
 +  free(tmp_row);
return GL_FALSE;
 +   }

 invert_swizzle(dst2rgba, rgba2dst);
 compute_component_mapping(GL_RGBA, baseInternalFormat, base2rgba);
 --
 2.1.3

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




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


Re: [Mesa-dev] [PATCH v3 0/9] Gallium Nine

2014-11-18 Thread Emil Velikov
On 18/11/14 18:36, Henri Verbeet wrote:
 On 17 November 2014 21:05, Emil Velikov emil.l.veli...@gmail.com wrote:
  - GL extensions
 I feel that it's a bit too much to shoot the project down, because it
 does not introduce GL extensions that will be useful.
 To clarify, that's not what I said. It's mostly just that I'd like to
 see some actual evidence for the (implicit) claim that the performance
 difference is largely due to inherent OpenGL API overhead.
 
An earlier link shows quite a few games that have noticeable perf
impact. Feel free to grab anyone and do some analysis that you'd
consider most appropriate. I fear I won't be able to help you out there :(

 Considering the interface note able, would you say that any new
 implementation towards handling D3D9 in wine is acceptable ?
 If anything, it would have to be an interface approximately on the
 level of the DDI, like Jose mentioned.
 
This is a very nice first step. Thank you.

From a quick look at MSDN it seems to me that going the DDI (like) route
would require substantial rework on the wine side. How much contribution
from wine can we expect ? Would you have the chance to help with
design/coding, or would you be (no disrespect here) limited to answering
questions ?

 Can we work together so that both project benefit from this effort ?
 I like to think we've always had good relations with Mesa, even if we
 don't always agree on everything.

I'm sure that not everything in mesa is perfect yet I've not seen (m)any
bug reports from you guys. If/when you guys spot something
broken/extremely slow please bugzilla it or send an email to the ML.

Good relations are based on mutual feedback :)

Speaking of feedback, please consider using GLX_MESA_query_renderer. It
should help you (at least a bit) with the massive
vendor/device/video_memory tables that you currently have.


Thanks
Emil

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


[Mesa-dev] [PATCH] i965: Fix segfault in WebGL Conformance on Ivybridge (v2)

2014-11-18 Thread Chad Versace
Fixes regression of WebGL Conformance test texture-size-limit [1] on
Ivybridge Mobile GT2 0x0166 with Google Chrome R38.

Regression introduced by

commit 6c044231535b93c5d16404528946cad618d96bd9
Author: Kenneth Graunke kenn...@whitecape.org
Date:   Sun Feb 2 02:58:42 2014 -0800

i965: Bump GL_MAX_CUBE_MAP_TEXTURE_SIZE to 8192.

The test regressed because the pointer offset arithmetic in
intel_miptree_map_gtt() overflows for large textures. The pointer
arithmetic is not 64-bit safe.

[1] 
https://github.com/KhronosGroup/WebGL/blob/52f0dc240f04dce31b1b8e2b8107fe2b8332dc90/sdk/tests/conformance/textures/texture-size-limit.html

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=78770
Fixes: Intel CHRMOS-1377
Reported-by: Lu Hua huax...@intel.com
Signed-off-by: Chad Versace chad.vers...@linux.intel.com
---

v2:
- Simplify diff. Change types of x,y to intptr_t instead of casting
intermediate arithmetic expressions to intptr_t.
- Remove big TODO comment, because my original TODO comment might be the
wrong thing to do :/

 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 8fda25d..7081f1d 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -1745,8 +1745,8 @@ intel_miptree_map_gtt(struct brw_context *brw,
unsigned int bw, bh;
void *base;
unsigned int image_x, image_y;
-   int x = map-x;
-   int y = map-y;
+   intptr_t x = map-x;
+   intptr_t y = map-y;
 
/* For compressed formats, the stride is the number of bytes per
 * row of blocks.  intel_miptree_get_image_offset() already does
@@ -1772,7 +1772,8 @@ intel_miptree_map_gtt(struct brw_context *brw,
   map-ptr = base + y * map-stride + x * mt-cpp;
}
 
-   DBG(%s: %d,%d %dx%d from mt %p (%s) %d,%d = %p/%d\n, __FUNCTION__,
+   DBG(%s: %d,%d %dx%d from mt %p (%s) 
+   %PRIiPTR,%PRIiPTR = %p/%d\n, __FUNCTION__,
map-x, map-y, map-w, map-h,
mt, _mesa_get_format_name(mt-format),
x, y, map-ptr, map-stride);
-- 
2.1.0-rc0

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


  1   2   >