[Mesa-dev] [PATCH] llvmpipe: We don't use the draw pipeline for offset_point/line.

2013-10-09 Thread jfonseca
From: José Fonseca 

Unless the polygon fill mode is different PIPE_POLYGON_MODE_FILL, so
checking the the polygon mode is sufficient.

Testing done: no regression in polygon-mode-offset
---
 src/gallium/drivers/llvmpipe/lp_state_rasterizer.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c 
b/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c
index 6148337..2149ffc 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c
@@ -78,8 +78,6 @@ llvmpipe_create_rasterizer_state(struct pipe_context *pipe,
 */
need_pipeline = (rast->fill_front != PIPE_POLYGON_MODE_FILL ||
rast->fill_back != PIPE_POLYGON_MODE_FILL ||
-rast->offset_point ||
-rast->offset_line ||
rast->point_smooth ||
rast->line_smooth ||
rast->line_stipple_enable ||
-- 
1.8.1.2

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


[Mesa-dev] [PATCH] util/u_format: take normalized flag in consideration in util_format_is_rgba8_variant

2013-11-04 Thread jfonseca
From: José Fonseca 

Just happened to notice it was missing while looking at it.
---
 src/gallium/auxiliary/util/u_format.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_format.h 
b/src/gallium/auxiliary/util/u_format.h
index dc777c3..31283e5 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -696,6 +696,8 @@ util_format_is_rgba8_variant(const struct 
util_format_description *desc)
   if(desc->channel[chan].type != UTIL_FORMAT_TYPE_UNSIGNED &&
  desc->channel[chan].type != UTIL_FORMAT_TYPE_VOID)
  return FALSE;
+  if(!desc->channel[chan].normalized)
+ return FALSE;
   if(desc->channel[chan].size != 8)
  return FALSE;
}
-- 
1.8.3.2

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


[Mesa-dev] [PATCH] glx: Fix scons build.

2013-11-08 Thread jfonseca
From: José Fonseca 

By disabling DRI3 support for the time being.

I'll add DRI3 support to scons build when the DRI3 dependencies become
more widely available (as now there is no convenient way of testing it
except building dependencies from source).
---
 src/glx/SConscript | 6 ++
 src/glx/glxext.c   | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/src/glx/SConscript b/src/glx/SConscript
index ef372d0..f581c12 100644
--- a/src/glx/SConscript
+++ b/src/glx/SConscript
@@ -40,6 +40,9 @@ if env['HAVE_XF86VIDMODE']:
 if False: # XXX: SHARED_GLAPI
 env.Append(CPPDEFINES = ['GLX_SHARED_GLAPI'])
 
+# XXX: Disable DRI3 for now
+env.Append(CPPDEFINES = ['GLX_NO_DRI3'])
+
 sources = [
 'clientattrib.c',
 'clientinfo.c',
@@ -63,6 +66,7 @@ sources = [
 'indirect_vertex_program.c',
 'pixel.c',
 'pixelstore.c',
+'query_renderer.c',
 'render2.c',
 'renderpix.c',
 'single2.c',
@@ -79,6 +83,8 @@ sources = [
 'dri2_glx.c',
 'dri2.c',
 'dri2_query_renderer.c',
+#'dri3_glx.c',
+#'dri3_common.c',
 'applegl_glx.c',
 ]
 
diff --git a/src/glx/glxext.c b/src/glx/glxext.c
index c6e4d9f..d3c92574 100644
--- a/src/glx/glxext.c
+++ b/src/glx/glxext.c
@@ -865,8 +865,10 @@ __glXInitialize(Display * dpy)
 ** (e.g., those called in AllocAndFetchScreenConfigs).
 */
if (glx_direct && glx_accel) {
+#if !defined(GLX_NO_DRI3)
   if (!getenv("LIBGL_DRI3_DISABLE"))
  dpyPriv->dri3Display = dri3_create_display(dpy);
+#endif
   dpyPriv->dri2Display = dri2CreateDisplay(dpy);
   dpyPriv->driDisplay = driCreateDisplay(dpy);
}
-- 
1.8.3.2

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


[Mesa-dev] [PATCH] gallivm: Compile flag to debug TGSI execution through printfs.

2013-11-13 Thread jfonseca
From: José Fonseca 

It is similar to tgsi_exec.c's DEBUG_EXECUTION compile flag.

I had prototyped this for a while while debugging an issue, but finally
cleaned this up and added a few more bells and whistles.

Here is a sample output.

CONST[0]:
  X: 0.006250 0.006250 0.006250 0.006250
  Y: -0.007143 -0.007143 -0.007143 -0.007143
  Z: -1.00 -1.00 -1.00 -1.00
  W: 1.00 1.00 1.00 1.00
IN[0]:
  X: 143.50 175.50 175.50 143.50
  Y: 123.50 123.50 155.50 155.50
  Z: 0.00 0.00 0.00 0.00
  W: 1.00 1.00 1.00 1.00
>   1: RCP TEMP[0].w, IN[0].
TEMP[0].w =  1 1 1 1
>   2: MAD TEMP[0].xy, IN[0], CONST[0], CONST[0].zwzw
TEMP[0].x =  -0.103124976 0.0968750715 0.0968750715 -0.103124976
TEMP[0].y =  0.117857158 0.117857158 -0.110714316 -0.110714316
>   3: MUL OUT[0].xy, TEMP[0], TEMP[0].
OUT[0].x =  -0.103124976 0.0968750715 0.0968750715 -0.103124976
OUT[0].y =  0.117857158 0.117857158 -0.110714316 -0.110714316
>   4: MUL OUT[0].z, IN[0]., TEMP[0].
OUT[0].z =  0 0 0 0
>   5: MOV OUT[0].w, TEMP[0]
OUT[0].w =  1 1 1 1
---
 src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c | 158 +++-
 src/gallium/auxiliary/tgsi/tgsi_dump.c  |  23 
 src/gallium/auxiliary/tgsi/tgsi_dump.h  |   7 ++
 3 files changed, 159 insertions(+), 29 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c 
b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
index 5f81066..917826d 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
@@ -47,6 +47,7 @@
 #include "tgsi/tgsi_parse.h"
 #include "tgsi/tgsi_util.h"
 #include "tgsi/tgsi_scan.h"
+#include "tgsi/tgsi_strings.h"
 #include "lp_bld_tgsi_action.h"
 #include "lp_bld_type.h"
 #include "lp_bld_const.h"
@@ -67,6 +68,17 @@
 
 #define DUMP_GS_EMITS 0
 
+/*
+ * If non-zero, the generated LLVM IR will print intermediate results on every 
TGSI
+ * instruction.
+ *
+ * TODO:
+ * - take execution masks in consideration
+ * - debug control-flow instructions
+ */
+#define DEBUG_EXECUTION 0
+
+
 static void lp_exec_mask_init(struct lp_exec_mask *mask, struct 
lp_build_context *bld)
 {
LLVMTypeRef int_type = LLVMInt32TypeInContext(bld->gallivm->context);
@@ -664,6 +676,43 @@ static void lp_exec_mask_endsub(struct lp_exec_mask *mask, 
int *pc)
 }
 
 
+static LLVMValueRef
+get_file_ptr(struct lp_build_tgsi_soa_context *bld,
+ unsigned file,
+ unsigned index,
+ unsigned chan)
+{
+   LLVMBuilderRef builder = bld->bld_base.base.gallivm->builder;
+   LLVMValueRef (*array_of_vars)[TGSI_NUM_CHANNELS];
+   LLVMValueRef var_of_array;
+
+   switch (file) {
+   case TGSI_FILE_TEMPORARY:
+  array_of_vars = bld->temps;
+  var_of_array = bld->temps_array;
+  break;
+   case TGSI_FILE_OUTPUT:
+  array_of_vars = bld->outputs;
+  var_of_array = bld->outputs_array;
+  break;
+   default:
+  assert(0);
+  return NULL;
+   }
+
+   assert(chan < 4);
+
+   if (bld->indirect_files & (1 << file)) {
+  LLVMValueRef lindex = lp_build_const_int32(bld->bld_base.base.gallivm, 
index * 4 + chan);
+  return LLVMBuildGEP(builder, var_of_array, &lindex, 1, "");
+   }
+   else {
+  assert(index <= bld->bld_base.info->file_max[file]);
+  return array_of_vars[index][chan];
+   }
+}
+
+
 /**
  * Return pointer to a temporary register channel (src or dest).
  * Note that indirect addressing cannot be handled here.
@@ -675,15 +724,7 @@ lp_get_temp_ptr_soa(struct lp_build_tgsi_soa_context *bld,
  unsigned index,
  unsigned chan)
 {
-   LLVMBuilderRef builder = bld->bld_base.base.gallivm->builder;
-   assert(chan < 4);
-   if (bld->indirect_files & (1 << TGSI_FILE_TEMPORARY)) {
-  LLVMValueRef lindex = lp_build_const_int32(bld->bld_base.base.gallivm, 
index * 4 + chan);
-  return LLVMBuildGEP(builder, bld->temps_array, &lindex, 1, "");
-   }
-   else {
-  return bld->temps[index][chan];
-   }
+   return get_file_ptr(bld, TGSI_FILE_TEMPORARY, index, chan);
 }
 
 /**
@@ -697,16 +738,7 @@ lp_get_output_ptr(struct lp_build_tgsi_soa_context *bld,
unsigned index,
unsigned chan)
 {
-   LLVMBuilderRef builder = bld->bld_base.base.gallivm->builder;
-   assert(chan < 4);
-   if (bld->indirect_files & (1 << TGSI_FILE_OUTPUT)) {
-  LLVMValueRef lindex = lp_build_const_int32(bld->bld_base.base.gallivm,
- index * 4 + chan);
-  return LLVMBuildGEP(builder, bld->outputs_array, &lindex, 1, "");
-   }
-   else {
-  return bld->outputs[index][chan];
-   }
+   return get_file_ptr(bld, TGSI_FILE_OUTPUT, index, chan);
 }
 
 /*
@@ -1415,6 +1447,21 @@ emit_store_chan(
  bld_base->info->file_max[reg->Register.File]);
}
 
+   if (DEBUG_EXECUTION) {
+  /*
+   * Dump the value.
+

[Mesa-dev] [PATCH] u_gen_mipmap: Use untampered cubemap texture coords when generating mipmaps.

2013-11-19 Thread jfonseca
From: José Fonseca 

It's not necessary to scale down cubemap texture coords when generating
mipmaps: we are doing a 2x minification therefore it's guaranteed that
the texture coords will always be at least 1 texel away of the edges.

Scaling down can actually be harmful, as it may cause artefacts when
generating mipmaps with nearest filtering. Sample points will lie
exactly in the middle each 2x2 texels, so the scaling factor was causing
different texels to be take on each quadrant of the cube face.  This is
apparent with a 1x1 checkerboard pattern in the base mipmap level:
instead of next mipmap level receiving a constant color throughout the
face, it will have different colors for each quadrant of the face.

The behaviour for blits is left untouched for now, but the cubemap
texture coord scaling hack should be reconsidered eventually.
---
 src/gallium/auxiliary/util/u_blit.c   |  3 ++-
 src/gallium/auxiliary/util/u_blitter.c|  3 ++-
 src/gallium/auxiliary/util/u_gen_mipmap.c |  3 ++-
 src/gallium/auxiliary/util/u_texture.c| 11 +--
 src/gallium/auxiliary/util/u_texture.h|  5 -
 5 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_blit.c 
b/src/gallium/auxiliary/util/u_blit.c
index 4ba71b9..595287d 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -272,7 +272,8 @@ setup_vertex_data_tex(struct blit_state *ctx,
   const unsigned stride = sizeof ctx->vertices[0] / sizeof 
ctx->vertices[0][0][0];
   util_map_texcoords2d_onto_cubemap(src_face,
 &ctx->vertices[0][1][0], stride,
-&ctx->vertices[0][1][0], stride);
+&ctx->vertices[0][1][0], stride,
+TRUE);
}
 
offset = get_next_slot( ctx );
diff --git a/src/gallium/auxiliary/util/u_blitter.c 
b/src/gallium/auxiliary/util/u_blitter.c
index 096d3bc..b95cbab 100644
--- a/src/gallium/auxiliary/util/u_blitter.c
+++ b/src/gallium/auxiliary/util/u_blitter.c
@@ -659,7 +659,8 @@ static void blitter_set_texcoords(struct 
blitter_context_priv *ctx,
   util_map_texcoords2d_onto_cubemap(layer % 6,
 /* pointer, stride in floats */
 &face_coord[0][0], 2,
-&ctx->vertices[0][1][0], 8);
+&ctx->vertices[0][1][0], 8,
+TRUE);
} else {
   set_texcoords_in_vertices(coord, &ctx->vertices[0][1][0], 8);
}
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c 
b/src/gallium/auxiliary/util/u_gen_mipmap.c
index a885f2b..84bf30f 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.c
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
@@ -1409,7 +1409,8 @@ set_vertex_data(struct gen_mipmap_state *ctx,
   };
 
   util_map_texcoords2d_onto_cubemap(layer, &st[0][0], 2,
-&ctx->vertices[0][1][0], 8);
+&ctx->vertices[0][1][0], 8,
+FALSE);
}
else if (tex_target == PIPE_TEXTURE_1D_ARRAY) {
   /* 1D texture array  */
diff --git a/src/gallium/auxiliary/util/u_texture.c 
b/src/gallium/auxiliary/util/u_texture.c
index d97e57a..e865f8e 100644
--- a/src/gallium/auxiliary/util/u_texture.c
+++ b/src/gallium/auxiliary/util/u_texture.c
@@ -42,7 +42,8 @@
 
 void util_map_texcoords2d_onto_cubemap(unsigned face,
const float *in_st, unsigned in_stride,
-   float *out_str, unsigned out_stride)
+   float *out_str, unsigned out_stride,
+   boolean allow_scale)
 {
int i;
float rx, ry, rz;
@@ -52,8 +53,14 @@ void util_map_texcoords2d_onto_cubemap(unsigned face,
   /* Compute sc = +/-scale and tc = +/-scale.
* Not +/-1 to avoid cube face selection ambiguity near the edges,
* though that can still sometimes happen with this scale factor...
+   *
+   * XXX: Yep, there is no safe scale factor that will prevent sampling
+   * the neighbouring face when stretching out.  A more reliable solution
+   * would be to clamp (sc, tc) against +/- 1.0-1.0/mipsize, in the shader.
+   *
+   * Also, this is not necessary when minifying, or 1:1 blits.
*/
-  const float scale = 0.f;
+  const float scale = allow_scale ? 0.f : 1.0f;
   const float sc = (2 * in_st[0] - 1) * scale;
   const float tc = (2 * in_st[1] - 1) * scale;
 
diff --git a/src/gallium/auxiliary/util/u_texture.h 
b/src/gallium/auxiliary/util/u_texture.h
index 93b2f1e..b1c8c70 100644
--- a/src/gallium/auxiliary/util/u_texture.h
+++ b/src/gallium/auxiliary/util/u_texture.h
@@ -27,6 +27,8 @@
 #ifndef U_TEXTURE_H
 #define 

[Mesa-dev] [PATCH] gallium: Make TGSI_SEMANTIC_FOG register four-component wide.

2013-11-20 Thread jfonseca
From: José Fonseca 

D3D9 Shader Model 2 restricted the fog register to one component,
http://msdn.microsoft.com/en-us/library/windows/desktop/bb172945.aspx ,
but that restriction no longer exists in Shader Model 3, and several
WHCK tests enforce that.

So this change:
- lifts the single-component restriction TGSI_SEMANTIC_FOG
  from Gallium interface
- updates the Mesa state tracker to enforce output fog has (f, 0, 0, 1)
- draw module was updated to leave TGSI_SEMANTIC_FOG output registers
  alone

Several gallium drivers that are going out of their way to clear
TGSI_SEMANTIC_FOG components could be simplified in the future.

Thanks to Si Chen and Michal Krol for identifying the problem.

Testing done: piglit fogcoord-*.vpfp tests
---
 src/gallium/auxiliary/draw/draw_llvm.c |  6 --
 src/gallium/auxiliary/draw/draw_vs_exec.c  |  7 +--
 src/gallium/docs/source/tgsi.rst   | 10 +++---
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  7 +++
 src/mesa/state_tracker/st_mesa_to_tgsi.c   |  7 +++
 5 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_llvm.c 
b/src/gallium/auxiliary/draw/draw_llvm.c
index fe49b86..71cc45f 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -659,12 +659,6 @@ generate_vs(struct draw_llvm_variant *variant,
  LLVMBuildStore(builder, out, outputs[attrib][chan]);
   }
   break;
-   case TGSI_SEMANTIC_FOG:
-  if (chan == 1 || chan == 2)
- LLVMBuildStore(builder, bld.zero, outputs[attrib][chan]);
-  else if (chan == 3)
- LLVMBuildStore(builder, bld.one, outputs[attrib][chan]);
-  break;
}
 }
  }
diff --git a/src/gallium/auxiliary/draw/draw_vs_exec.c 
b/src/gallium/auxiliary/draw/draw_vs_exec.c
index 6100394..83cc5fd 100644
--- a/src/gallium/auxiliary/draw/draw_vs_exec.c
+++ b/src/gallium/auxiliary/draw/draw_vs_exec.c
@@ -167,12 +167,7 @@ vs_exec_run_linear( struct draw_vertex_shader *shader,
output[slot][2] = CLAMP(machine->Outputs[slot].xyzw[2].f[j], 
0.0f, 1.0f);
output[slot][3] = CLAMP(machine->Outputs[slot].xyzw[3].f[j], 
0.0f, 1.0f);
 }
-else if (name == TGSI_SEMANTIC_FOG) {
-   output[slot][0] = machine->Outputs[slot].xyzw[0].f[j];
-   output[slot][1] = 0;
-   output[slot][2] = 0;
-   output[slot][3] = 1;
-   } else
+else
 {
output[slot][0] = machine->Outputs[slot].xyzw[0].f[j];
output[slot][1] = machine->Outputs[slot].xyzw[1].f[j];
diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst
index f80c08d..1070619 100644
--- a/src/gallium/docs/source/tgsi.rst
+++ b/src/gallium/docs/source/tgsi.rst
@@ -2420,13 +2420,9 @@ TGSI_SEMANTIC_FOG
 
 Vertex shader inputs and outputs and fragment shader inputs may be
 labeled with TGSI_SEMANTIC_FOG to indicate that the register contains
-a fog coordinate in the form (F, 0, 0, 1).  Typically, the fragment
-shader will use the fog coordinate to compute a fog blend factor which
-is used to blend the normal fragment color with a constant fog color.
-
-Only the first component matters when writing from the vertex shader;
-the driver will ensure that the coordinate is in this format when used
-as a fragment shader input.
+a fog coordinate.  Typically, the fragment shader will use the fog coordinate
+to compute a fog blend factor which is used to blend the normal fragment color
+with a constant fog color.
 
 
 TGSI_SEMANTIC_PSIZE
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 6319079..74b3e5b 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -4889,6 +4889,13 @@ st_translate_program(
  t->outputs[i] = ureg_DECL_output(ureg,
   outputSemanticName[i],
   outputSemanticIndex[i]);
+ if (outputSemanticName[i] == TGSI_SEMANTIC_FOG) {
+/* force register to contain a fog coordinate in the form (F, 0, 
0, 1). */
+ureg_MOV(ureg,
+ ureg_writemask(t->outputs[i], TGSI_WRITEMASK_XYZW & 
~TGSI_WRITEMASK_X),
+ ureg_imm4f(ureg, 0.0f, 0.0f, 0.0f, 1.0f));
+t->outputs[i] = ureg_writemask(t->outputs[i], TGSI_WRITEMASK_X);
+}
   }
   if (passthrough_edgeflags)
  emit_edgeflags(t);
diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c 
b/src/mesa/state_tracker/st_mesa_to_tgsi.c
index 921b0f9..7d79c62 100644
--- a/src/mesa/state_tracker/st_mesa_to_tgsi.c
+++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c
@@ -1121,6 +1121,13 @@ st_translate_mesa_program(
  t->outputs[i] = ureg

[Mesa-dev] [PATCH] tgsi_exec: Fix mask calculation for emit_kill_if.

2013-11-20 Thread jfonseca
From: José Fonseca 

Same as Si Chen's commit e7a5905d8a3960b0981750f8131e3af9acbfcdb8 for
tgsi_exec module.

Not actually tested, because softpipe is failing the test that caught
this bug due to unrelated issues.
---
 src/gallium/auxiliary/tgsi/tgsi_exec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c 
b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index 6db1238..b614907 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -1610,6 +1610,9 @@ exec_kill_if(struct tgsi_exec_machine *mach,
 kilmask |= 1 << i;
}
 
+   /* restrict to fragments currently executing */
+   kilmask &= mach->ExecMask;
+
mach->Temps[TEMP_KILMASK_I].xyzw[TEMP_KILMASK_C].u[0] |= kilmask;
 }
 
-- 
1.8.3.2

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


[Mesa-dev] [PATCH] docs: Add a section with recommended reading for llvmpipe development.

2013-11-21 Thread jfonseca
From: José Fonseca 

Several links contributed by Keith Whitwell and Roland Scheidegger.
---
 docs/llvmpipe.html | 58 --
 1 file changed, 56 insertions(+), 2 deletions(-)

diff --git a/docs/llvmpipe.html b/docs/llvmpipe.html
index 80f8a01..d695907 100644
--- a/docs/llvmpipe.html
+++ b/docs/llvmpipe.html
@@ -203,11 +203,65 @@ for posterior analysis, e.g.:
   We use LLVM-C bindings for now. They are not documented, but follow the C++
   interfaces very closely, and appear to be complete enough for code
   generation. See 
-  http://npcontemplation.blogspot.com/2008/06/secret-of-llvm-c-bindings.html
-  for a stand-alone example.  See the llvm-c/Core.h file for reference.
+  http://npcontemplation.blogspot.com/2008/06/secret-of-llvm-c-bindings.html";>
+  this stand-alone example.  See the llvm-c/Core.h file for reference.
 
 
 
+Recommended Reading
+
+
+  
+Rasterization
+
+  http://www.cs.unc.edu/~olano/papers/2dh-tri/";>Triangle Scan 
Conversion using 2D Homogeneous Coordinates
+  http://www.drdobbs.com/parallel/rasterization-on-larrabee/217200602";>Rasterization
 on Larrabee (http://devmaster.net/posts/2887/rasterization-on-larrabee";>DevMaster 
copy)
+  http://devmaster.net/posts/6133/rasterization-using-half-space-functions";>Rasterization
 using half-space functions
+  http://devmaster.net/posts/6145/advanced-rasterization";>Advanced 
Rasterization
+  http://fgiesen.wordpress.com/2013/02/17/optimizing-sw-occlusion-culling-index/";>Optimizing
 Software Occlusion Culling
+
+  
+  
+Texture sampling
+
+  http://chrishecker.com/Miscellaneous_Technical_Articles#Perspective_Texture_Mapping";>Perspective
 Texture Mapping
+  http://www.flipcode.com/archives/Texturing_As_In_Unreal.shtml";>Texturing 
As In Unreal
+  http://www.gamasutra.com/view/feature/3301/runtime_mipmap_filtering.php";>Run-Time
 MIP-Map Filtering
+  http://alt.3dcenter.org/artikel/2003/10-26_a_english.php";>Will 
"brilinear" filtering persist?
+  http://ixbtlabs.com/articles2/gffx/nv40-rx800-3.html";>Trilinear 
filtering
+  http://devmaster.net/posts/12785/texture-swizzling";>Texture 
Swizzling
+
+  
+  
+SIMD
+
+  http://www.cdl.uni-saarland.de/projects/wfv/#header4";>Whole-Function 
Vectorization
+
+  
+  
+Optimization
+
+  http://www.drdobbs.com/optimizing-pixomatic-for-modern-x86-proc/184405807";>Optimizing
 Pixomatic For Modern x86 Processors
+  http://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-optimization-manual.html";>Intel
 64 and IA-32 Architectures Optimization Reference Manual
+  http://www.agner.org/optimize/";>Software optimization 
resources
+  http://software.intel.com/en-us/articles/intel-intrinsics-guide";>Intel 
Intrinsics Guide
+
+  
+  
+LLVM
+
+  http://llvm.org/docs/LangRef.html";>LLVM Language Reference 
Manual
+  http://npcontemplation.blogspot.co.uk/2008/06/secret-of-llvm-c-bindings.html";>The
 secret of LLVM C bindings
+
+  
+  
+Misc
+
+  http://msdn.microsoft.com/en-us/library/gg615082.aspx#architecture";>WARP 
Architecture and Performance
+
+  
+
+
 
 
 
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 1/2] tgsi_ureg: Refactor the ureg_* inline so that all variables are pre-declared.

2013-11-21 Thread jfonseca
From: José Fonseca 

Mere syntactical change.
---
 src/gallium/auxiliary/tgsi/tgsi_ureg.h | 200 +
 1 file changed, 104 insertions(+), 96 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h 
b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
index e104cd9..cf0c75e 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
@@ -564,18 +564,19 @@ ureg_fixup_insn_size(struct ureg_program *ureg,
 static INLINE void ureg_##op( struct ureg_program *ureg )   \
 {   \
unsigned opcode = TGSI_OPCODE_##op;  \
-   unsigned insn = ureg_emit_insn(ureg, \
-  opcode,   \
-  FALSE,\
-  FALSE,\
-  FALSE,\
-  TGSI_SWIZZLE_X,   \
-  TGSI_SWIZZLE_Y,   \
-  TGSI_SWIZZLE_Z,   \
-  TGSI_SWIZZLE_W,   \
-  0,\
-  0).insn_token;\
-   ureg_fixup_insn_size( ureg, insn );  \
+   struct ureg_emit_insn_result insn;   \
+   insn = ureg_emit_insn(ureg,  \
+ opcode,\
+ FALSE, \
+ FALSE, \
+ FALSE, \
+ TGSI_SWIZZLE_X,\
+ TGSI_SWIZZLE_Y,\
+ TGSI_SWIZZLE_Z,\
+ TGSI_SWIZZLE_W,\
+ 0, \
+ 0);\
+   ureg_fixup_insn_size( ureg, insn.insn_token );   \
 }
 
 #define OP01( op )  \
@@ -583,19 +584,20 @@ static INLINE void ureg_##op( struct ureg_program *ureg,  
  \
   struct ureg_src src ) \
 {   \
unsigned opcode = TGSI_OPCODE_##op;  \
-   unsigned insn = ureg_emit_insn(ureg, \
-  opcode,   \
-  FALSE,\
-  FALSE,\
-  FALSE,\
-  TGSI_SWIZZLE_X,   \
-  TGSI_SWIZZLE_Y,   \
-  TGSI_SWIZZLE_Z,   \
-  TGSI_SWIZZLE_W,   \
-  0,\
-  1).insn_token;\
+   struct ureg_emit_insn_result insn;   \
+   insn = ureg_emit_insn(ureg,  \
+ opcode,\
+ FALSE, \
+ FALSE, \
+ FALSE, \
+ TGSI_SWIZZLE_X,\
+ TGSI_SWIZZLE_Y,\
+ TGSI_SWIZZLE_Z,\
+ TGSI_SWIZZLE_W,\
+ 0, \
+ 1);\
ureg_emit_src( ureg, src );  \
-   ureg_fixup_insn_size( ureg, insn );  \
+   ureg_fixup_insn_size( ureg, insn.insn_token );   \
 }
 
 #define OP00_LBL( op )  \
@@ -647,19 +649,20 @@ static INLINE void ureg_##op( struct ureg_program *ureg,  
  \
   struct ureg_dst dst ) \
 {   \
unsigned opcode = TGSI_OPCODE_##op;  \
-   unsigned insn = ureg_emit_insn(ureg, \
-  opcode,   \
-   

[Mesa-dev] [PATCH 2/2] tgsi: Prevent emission of instructions with empty writemask.

2013-11-21 Thread jfonseca
From: José Fonseca 

These degenerate instructions can often be emitted by state trackers
when the semantics of instructions don't match precisely.
---
 src/gallium/auxiliary/tgsi/tgsi_ureg.c |  8 
 src/gallium/auxiliary/tgsi/tgsi_ureg.h | 22 ++
 2 files changed, 30 insertions(+)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c 
b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
index 432ed00..f06858e 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
@@ -1113,6 +1113,10 @@ ureg_insn(struct ureg_program *ureg,
boolean negate = FALSE;
unsigned swizzle[4] = { 0 };
 
+   if (nr_dst && ureg_dst_is_empty(dst[0])) {
+  return;
+   }
+
saturate = nr_dst ? dst[0].Saturate : FALSE;
predicate = nr_dst ? dst[0].Predicate : FALSE;
if (predicate) {
@@ -1162,6 +1166,10 @@ ureg_tex_insn(struct ureg_program *ureg,
boolean negate = FALSE;
unsigned swizzle[4] = { 0 };
 
+   if (nr_dst && ureg_dst_is_empty(dst[0])) {
+  return;
+   }
+
saturate = nr_dst ? dst[0].Saturate : FALSE;
predicate = nr_dst ? dst[0].Predicate : FALSE;
if (predicate) {
diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h 
b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
index cf0c75e..d973edb 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
@@ -454,6 +454,16 @@ ureg_imm1i( struct ureg_program *ureg,
return ureg_DECL_immediate_int( ureg, &a, 1 );
 }
 
+/* Where the destination register has a valid file, but an empty
+ * writemask.
+ */
+static INLINE boolean
+ureg_dst_is_empty( struct ureg_dst dst )
+{
+   return dst.File != TGSI_FILE_NULL &&
+  dst.WriteMask == 0;
+}
+
 /***
  * Functions for patching up labels
  */
@@ -650,6 +660,7 @@ static INLINE void ureg_##op( struct ureg_program *ureg,
\
 {   \
unsigned opcode = TGSI_OPCODE_##op;  \
struct ureg_emit_insn_result insn;   \
+   if (ureg_dst_is_empty(dst)) return;  \
insn = ureg_emit_insn(ureg,  \
  opcode,\
  dst.Saturate,  \
@@ -673,6 +684,7 @@ static INLINE void ureg_##op( struct ureg_program *ureg,
\
 {   \
unsigned opcode = TGSI_OPCODE_##op;  \
struct ureg_emit_insn_result insn;   \
+   if (ureg_dst_is_empty(dst)) return;  \
insn = ureg_emit_insn(ureg,  \
  opcode,\
  dst.Saturate,  \
@@ -697,6 +709,7 @@ static INLINE void ureg_##op( struct ureg_program *ureg,
\
 {   \
unsigned opcode = TGSI_OPCODE_##op;  \
struct ureg_emit_insn_result insn;   \
+   if (ureg_dst_is_empty(dst)) return;  \
insn = ureg_emit_insn(ureg,  \
  opcode,\
  dst.Saturate,  \
@@ -723,6 +736,7 @@ static INLINE void ureg_##op( struct ureg_program *ureg,
\
 {   \
unsigned opcode = TGSI_OPCODE_##op;  \
struct ureg_emit_insn_result insn;   \
+   if (ureg_dst_is_empty(dst)) return;  \
insn = ureg_emit_insn(ureg,  \
  opcode,\
  dst.Saturate,  \
@@ -750,6 +764,7 @@ static INLINE void ureg_##op( struct ureg_program *ureg,
\
unsigned opcode = TGSI_OPCODE_##op;  \
unsigned target = TGSI_TEXTURE_UNKNOWN;  \
struct ureg_emit_insn_result insn;   \
+   if (ureg_dst_is_empty(dst)) return;  \
insn = ureg_emit_insn(ureg,  \
  opcode,\
  dst.Saturate,  \
@@ -777,6 +792,7 @@ static INLINE void ureg_##op( struct ureg_prog

[Mesa-dev] [PATCH] mesa/main: Prevent sefgault on glGetIntegerv(GL_ATOMIC_COUNTER_BUFFER_BINDING).

2014-06-06 Thread jfonseca
From: José Fonseca 

A recent ApiTrace change, that tries to dump more buffer state
causes Mesa from my distro (10.1.4) to segfaults here.

I haven't actually confirm this fixes it (I can't repro on master),
but it seems a good idea to be defensive here anyway.

Cc: "10.1 10.2" 
---
 src/mesa/main/get.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 267b5f2..9b56edb 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -1005,7 +1005,11 @@ find_custom_value(struct gl_context *ctx, const struct 
value_desc *d, union valu
   break;
/* GL_ARB_shader_atomic_counters */
case GL_ATOMIC_COUNTER_BUFFER_BINDING:
-  v->value_int = ctx->AtomicBuffer->Name;
+  if (ctx->AtomicBuffer) {
+ v->value_int = ctx->AtomicBuffer->Name;
+  } else {
+ v->value_int = 0;
+  }
   break;
/* GL_ARB_draw_indirect */
case GL_DRAW_INDIRECT_BUFFER_BINDING:
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCH] st/wgl: Clamp wglChoosePixelFormatARB's output nNumFormats to nMaxFormats.

2014-07-24 Thread jfonseca
From: José Fonseca 

While running https://github.com/nvMcJohn/apitest with apitrace I noticed that 
Mesa was producing bogus results:

  wglChoosePixelFormatARB(hdc, piAttribIList = {...}, pfAttribFList = &0, 
nMaxFormats = 1, piFormats = {19, 65576, 37, 198656, 131075, 0, 402653184, 0, 
0, 0, 0, -573575710}, nNumFormats = &12) = TRUE

However https://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt states

 returns the number of matching formats. The returned
value is guaranteed to be no larger than .

Cc: "10.2" 
---
 src/gallium/state_trackers/wgl/stw_ext_pixelformat.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c 
b/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c
index d303b01..91682d1 100644
--- a/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c
+++ b/src/gallium/state_trackers/wgl/stw_ext_pixelformat.c
@@ -448,9 +448,11 @@ wglChoosePixelFormatARB(
 */
for (i = 0; i < count; i++) {
   if (scores[i].points > 0) {
- if (*nNumFormats < nMaxFormats)
-piFormats[*nNumFormats] = scores[i].index + 1;
+piFormats[*nNumFormats] = scores[i].index + 1;
  (*nNumFormats)++;
+if (*nNumFormats >= nMaxFormats) {
+   break;
+}
   }
}
 
-- 
1.9.1

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


[Mesa-dev] [PATCH] glsl/glcpp: Rename ERROR to ERROR_TOKEN.

2014-07-30 Thread jfonseca
From: José Fonseca 

To prevent collision with wingdi.h's ERROR define, using the same _TOKEN
suffix already forsome other tokens due to similar reasons.

PS: Name collisions will be rife with single capitalized words.  And
using _TOKEN suffix for only some of the tokens is not particularly
consistent nor pretty.  So it might be worth using an unique
prefix/suffix for all tokens (even if something short like *_TKN or
TKN_*), to avoid this sort of issue while having consistency.
---
 src/glsl/glcpp/glcpp-lex.l   | 2 +-
 src/glsl/glcpp/glcpp-parse.y | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l
index 4b9ab23..c126850 100644
--- a/src/glsl/glcpp/glcpp-lex.l
+++ b/src/glsl/glcpp/glcpp-lex.l
@@ -350,7 +350,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
 
 error.* {
BEGIN INITIAL;
-   RETURN_STRING_TOKEN (ERROR);
+   RETURN_STRING_TOKEN (ERROR_TOKEN);
 }
 
/* After we see a "#define" we enter the  start state
diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index bc873cd..4ee4110 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -171,11 +171,11 @@ add_builtin_define(glcpp_parser_t *parser, const char 
*name, int value);
/* We use HASH_TOKEN, DEFINE_TOKEN and VERSION_TOKEN (as opposed to
  * HASH, DEFINE, and VERSION) to avoid conflicts with other symbols,
  * (such as the  and  start conditions in the lexer). */
-%token COMMA_FINAL DEFINED ELIF_EXPANDED HASH_TOKEN DEFINE_TOKEN 
FUNC_IDENTIFIER OBJ_IDENTIFIER ELIF ELSE ENDIF ERROR IF IFDEF IFNDEF LINE 
PRAGMA UNDEF VERSION_TOKEN GARBAGE IDENTIFIER IF_EXPANDED INTEGER 
INTEGER_STRING LINE_EXPANDED NEWLINE OTHER PLACEHOLDER SPACE PLUS_PLUS 
MINUS_MINUS
+%token COMMA_FINAL DEFINED ELIF_EXPANDED HASH_TOKEN DEFINE_TOKEN 
FUNC_IDENTIFIER OBJ_IDENTIFIER ELIF ELSE ENDIF ERROR_TOKEN IF IFDEF IFNDEF LINE 
PRAGMA UNDEF VERSION_TOKEN GARBAGE IDENTIFIER IF_EXPANDED INTEGER 
INTEGER_STRING LINE_EXPANDED NEWLINE OTHER PLACEHOLDER SPACE PLUS_PLUS 
MINUS_MINUS
 %token PASTE
 %type  INTEGER operator SPACE integer_constant
 %type  expression
-%type  IDENTIFIER FUNC_IDENTIFIER OBJ_IDENTIFIER INTEGER_STRING OTHER 
ERROR PRAGMA
+%type  IDENTIFIER FUNC_IDENTIFIER OBJ_IDENTIFIER INTEGER_STRING OTHER 
ERROR_TOKEN PRAGMA
 %type  identifier_list
 %type  preprocessing_token conditional_token
 %type  pp_tokens replacement_list text_line conditional_tokens
@@ -421,7 +421,7 @@ control_line_success:
 ;
 
 control_line_error:
-   HASH_TOKEN ERROR NEWLINE {
+   HASH_TOKEN ERROR_TOKEN NEWLINE {
glcpp_error(& @1, parser, "#%s", $2);
}
 |  HASH_TOKEN GARBAGE pp_tokens NEWLINE  {
-- 
1.9.1

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


[Mesa-dev] [PATCH] gallium: Support PIPE_FORMAT_R10G10B10A2_UINT.

2013-08-21 Thread jfonseca
From: José Fonseca 

Same as PIPE_FORMAT_B10G10R10A2_UINT but without the swizzling.
---
 src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c | 1 +
 src/gallium/auxiliary/util/u_format.csv   | 1 +
 src/gallium/include/pipe/p_format.h   | 1 +
 3 files changed, 3 insertions(+)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c 
b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
index 6d12587..f2072ed 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
@@ -1466,6 +1466,7 @@ lp_build_clamp_border_color(struct 
lp_build_sample_context *bld,
   /* mixed plain formats (or different pure size) */
   switch (format_desc->format) {
   case PIPE_FORMAT_B10G10R10A2_UINT:
+  case PIPE_FORMAT_R10G10B10A2_UINT:
   {
  unsigned max10 = (1 << 10) - 1;
  max_clamp = lp_build_const_aos(gallivm, vec4_type, max10, max10,
diff --git a/src/gallium/auxiliary/util/u_format.csv 
b/src/gallium/auxiliary/util/u_format.csv
index f3925bb..8d04b00 100644
--- a/src/gallium/auxiliary/util/u_format.csv
+++ b/src/gallium/auxiliary/util/u_format.csv
@@ -372,3 +372,4 @@ PIPE_FORMAT_R16A16_UINT , plain, 1, 1, up16 , 
up16 , , , x00
 PIPE_FORMAT_R16A16_SINT , plain, 1, 1, sp16 , sp16 , , , 
x00y, rgb
 PIPE_FORMAT_R32A32_UINT , plain, 1, 1, up32 , up32 , , , 
x00y, rgb
 PIPE_FORMAT_R32A32_SINT , plain, 1, 1, sp32 , sp32 , , , 
x00y, rgb
+PIPE_FORMAT_R10G10B10A2_UINT, plain, 1, 1, up10 , up10 , up10, up2 , 
xyzw, rgb
diff --git a/src/gallium/include/pipe/p_format.h 
b/src/gallium/include/pipe/p_format.h
index f181621..b82f08f 100644
--- a/src/gallium/include/pipe/p_format.h
+++ b/src/gallium/include/pipe/p_format.h
@@ -340,6 +340,7 @@ enum pipe_format {
PIPE_FORMAT_R16A16_SINT = 250,
PIPE_FORMAT_R32A32_UINT = 251,
PIPE_FORMAT_R32A32_SINT = 252,
+   PIPE_FORMAT_R10G10B10A2_UINT= 253,
 
PIPE_FORMAT_COUNT
 };
-- 
1.8.1.2

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


[Mesa-dev] [PATCH] llvmpipe: Remove the special path for TGSI_OPCODE_EXP.

2013-09-11 Thread jfonseca
From: José Fonseca 

It was wrong for EXP.y, as we clamped the source before computing the
fractional part, and this opcode should be rarely used, so it's not
worth the hassle.
---
 src/gallium/auxiliary/gallivm/lp_bld_arit.c| 80 --
 src/gallium/auxiliary/gallivm/lp_bld_arit.h|  7 --
 src/gallium/auxiliary/gallivm/lp_bld_tgsi_action.c | 15 
 3 files changed, 30 insertions(+), 72 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c 
b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
index 09107ff..00052ed 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
@@ -3001,12 +3001,9 @@ const double lp_build_exp2_polynomial[] = {
 };
 
 
-void
-lp_build_exp2_approx(struct lp_build_context *bld,
- LLVMValueRef x,
- LLVMValueRef *p_exp2_int_part,
- LLVMValueRef *p_frac_part,
- LLVMValueRef *p_exp2)
+LLVMValueRef
+lp_build_exp2(struct lp_build_context *bld,
+  LLVMValueRef x)
 {
LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
@@ -3019,65 +3016,48 @@ lp_build_exp2_approx(struct lp_build_context *bld,
 
assert(lp_check_value(bld->type, x));
 
-   if(p_exp2_int_part || p_frac_part || p_exp2) {
-  /* TODO: optimize the constant case */
-  if (gallivm_debug & GALLIVM_DEBUG_PERF &&
-  LLVMIsConstant(x)) {
- debug_printf("%s: inefficient/imprecise constant arithmetic\n",
-  __FUNCTION__);
-  }
 
-  assert(type.floating && type.width == 32);
+   /* TODO: optimize the constant case */
+   if (gallivm_debug & GALLIVM_DEBUG_PERF &&
+   LLVMIsConstant(x)) {
+  debug_printf("%s: inefficient/imprecise constant arithmetic\n",
+   __FUNCTION__);
+   }
 
-  /* We want to preserve NaN and make sure than for exp2 if x > 128,
-   * the result is INF  and if it's smaller than -126.9 the result is 0 */
-  x = lp_build_min_ext(bld, lp_build_const_vec(bld->gallivm, type,  
128.0), x,
-   GALLIVM_NAN_RETURN_SECOND);
-  x = lp_build_max_ext(bld, lp_build_const_vec(bld->gallivm, type, 
-126.9), x,
-   GALLIVM_NAN_RETURN_SECOND);
+   assert(type.floating && type.width == 32);
 
-  /* ipart = floor(x) */
-  /* fpart = x - ipart */
-  lp_build_ifloor_fract(bld, x, &ipart, &fpart);
-   }
+   /* We want to preserve NaN and make sure than for exp2 if x > 128,
+* the result is INF  and if it's smaller than -126.9 the result is 0 */
+   x = lp_build_min_ext(bld, lp_build_const_vec(bld->gallivm, type,  128.0), x,
+GALLIVM_NAN_RETURN_SECOND);
+   x = lp_build_max_ext(bld, lp_build_const_vec(bld->gallivm, type, 
-126.9), x,
+GALLIVM_NAN_RETURN_SECOND);
 
-   if(p_exp2_int_part || p_exp2) {
-  /* expipart = (float) (1 << ipart) */
-  expipart = LLVMBuildAdd(builder, ipart,
-  lp_build_const_int_vec(bld->gallivm, type, 127), 
"");
-  expipart = LLVMBuildShl(builder, expipart,
-  lp_build_const_int_vec(bld->gallivm, type, 23), 
"");
-  expipart = LLVMBuildBitCast(builder, expipart, vec_type, "");
-   }
+   /* ipart = floor(x) */
+   /* fpart = x - ipart */
+   lp_build_ifloor_fract(bld, x, &ipart, &fpart);
 
-   if(p_exp2) {
-  expfpart = lp_build_polynomial(bld, fpart, lp_build_exp2_polynomial,
- Elements(lp_build_exp2_polynomial));
 
-  res = LLVMBuildFMul(builder, expipart, expfpart, "");
-   }
 
-   if(p_exp2_int_part)
-  *p_exp2_int_part = expipart;
+   /* expipart = (float) (1 << ipart) */
+   expipart = LLVMBuildAdd(builder, ipart,
+   lp_build_const_int_vec(bld->gallivm, type, 127), 
"");
+   expipart = LLVMBuildShl(builder, expipart,
+   lp_build_const_int_vec(bld->gallivm, type, 23), "");
+   expipart = LLVMBuildBitCast(builder, expipart, vec_type, "");
 
-   if(p_frac_part)
-  *p_frac_part = fpart;
 
-   if(p_exp2)
-  *p_exp2 = res;
-}
+   expfpart = lp_build_polynomial(bld, fpart, lp_build_exp2_polynomial,
+  Elements(lp_build_exp2_polynomial));
+
+   res = LLVMBuildFMul(builder, expipart, expfpart, "");
 
 
-LLVMValueRef
-lp_build_exp2(struct lp_build_context *bld,
-  LLVMValueRef x)
-{
-   LLVMValueRef res;
-   lp_build_exp2_approx(bld, x, NULL, NULL, &res);
return res;
 }
 
 
+
 /**
  * Extract the exponent of a IEEE-754 floating point value.
  *
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.h 
b/src/gallium/auxiliary/gallivm/lp_bld_arit.h
index d98025e..49d4e2c 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_arit.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.h
@@ -326,13 +326,6 @@ lp_build_ilog2(struct lp_build_context *bld,
LLVMValueRef 

[Mesa-dev] [PATCH 3/3] util/u_blit: Implement util_blit_pixels via pipe_context::blit.

2013-09-17 Thread jfonseca
From: José Fonseca 

This removes a lot of code, but not everything, as util_blit_pixels_tex
is still useful when one needs to override pipe_sampler_view::swizzle_?.
---
 src/gallium/auxiliary/util/u_blit.c | 447 +++-
 1 file changed, 37 insertions(+), 410 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_blit.c 
b/src/gallium/auxiliary/util/u_blit.c
index e9bec4a..4ba71b9 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -57,29 +57,20 @@ struct blit_state
struct pipe_context *pipe;
struct cso_context *cso;
 
-   struct pipe_blend_state blend_write_color, blend_keep_color;
+   struct pipe_blend_state blend_write_color;
struct pipe_depth_stencil_alpha_state dsa_keep_depthstencil;
-   struct pipe_depth_stencil_alpha_state dsa_write_depthstencil;
-   struct pipe_depth_stencil_alpha_state dsa_write_depth;
-   struct pipe_depth_stencil_alpha_state dsa_write_stencil;
struct pipe_rasterizer_state rasterizer;
struct pipe_sampler_state sampler;
struct pipe_viewport_state viewport;
struct pipe_vertex_element velem[2];
-   enum pipe_texture_target internal_target;
 
void *vs;
void *fs[PIPE_MAX_TEXTURE_TYPES][TGSI_WRITEMASK_XYZW + 1];
-   void *fs_depthstencil[PIPE_MAX_TEXTURE_TYPES];
-   void *fs_depth[PIPE_MAX_TEXTURE_TYPES];
-   void *fs_stencil[PIPE_MAX_TEXTURE_TYPES];
 
struct pipe_resource *vbuf;  /**< quad vertices */
unsigned vbuf_slot;
 
float vertices[4][2][4];   /**< vertex/texcoords for quad */
-
-   boolean has_stencil_export;
 };
 
 
@@ -103,20 +94,6 @@ util_create_blit(struct pipe_context *pipe, struct 
cso_context *cso)
/* disabled blending/masking */
ctx->blend_write_color.rt[0].colormask = PIPE_MASK_RGBA;
 
-   /* depth stencil states */
-   ctx->dsa_write_depth.depth.enabled = 1;
-   ctx->dsa_write_depth.depth.writemask = 1;
-   ctx->dsa_write_depth.depth.func = PIPE_FUNC_ALWAYS;
-   ctx->dsa_write_stencil.stencil[0].enabled = 1;
-   ctx->dsa_write_stencil.stencil[0].func = PIPE_FUNC_ALWAYS;
-   ctx->dsa_write_stencil.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE;
-   ctx->dsa_write_stencil.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
-   ctx->dsa_write_stencil.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE;
-   ctx->dsa_write_stencil.stencil[0].valuemask = 0xff;
-   ctx->dsa_write_stencil.stencil[0].writemask = 0xff;
-   ctx->dsa_write_depthstencil.depth = ctx->dsa_write_depth.depth;
-   ctx->dsa_write_depthstencil.stencil[0] = ctx->dsa_write_stencil.stencil[0];
-
/* rasterizer */
ctx->rasterizer.cull_face = PIPE_FACE_NONE;
ctx->rasterizer.half_pixel_center = 1;
@@ -147,14 +124,6 @@ util_create_blit(struct pipe_context *pipe, struct 
cso_context *cso)
   ctx->vertices[i][1][3] = 1.0f; /* q */
}
 
-   if(pipe->screen->get_param(pipe->screen, PIPE_CAP_NPOT_TEXTURES))
-  ctx->internal_target = PIPE_TEXTURE_2D;
-   else
-  ctx->internal_target = PIPE_TEXTURE_RECT;
-
-   ctx->has_stencil_export =
-  pipe->screen->get_param(pipe->screen, PIPE_CAP_SHADER_STENCIL_EXPORT);
-
return ctx;
 }
 
@@ -178,18 +147,6 @@ util_destroy_blit(struct blit_state *ctx)
   }
}
 
-   for (i = 0; i < PIPE_MAX_TEXTURE_TYPES; i++) {
-  if (ctx->fs_depthstencil[i]) {
- pipe->delete_fs_state(pipe, ctx->fs_depthstencil[i]);
-  }
-  if (ctx->fs_depth[i]) {
- pipe->delete_fs_state(pipe, ctx->fs_depth[i]);
-  }
-  if (ctx->fs_stencil[i]) {
- pipe->delete_fs_state(pipe, ctx->fs_stencil[i]);
-  }
-   }
-
pipe_resource_reference(&ctx->vbuf, NULL);
 
FREE(ctx);
@@ -217,63 +174,6 @@ set_fragment_shader(struct blit_state *ctx, uint writemask,
 
 
 /**
- * Helper function to set the shader which writes depth and stencil.
- */
-static INLINE void
-set_depthstencil_fragment_shader(struct blit_state *ctx,
- enum pipe_texture_target pipe_tex)
-{
-   if (!ctx->fs_depthstencil[pipe_tex]) {
-  unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex, 0);
-
-  ctx->fs_depthstencil[pipe_tex] =
- util_make_fragment_tex_shader_writedepthstencil(ctx->pipe, tgsi_tex,
-  TGSI_INTERPOLATE_LINEAR);
-   }
-
-   cso_set_fragment_shader_handle(ctx->cso, ctx->fs_depthstencil[pipe_tex]);
-}
-
-
-/**
- * Helper function to set the shader which writes depth.
- */
-static INLINE void
-set_depth_fragment_shader(struct blit_state *ctx,
-  enum pipe_texture_target pipe_tex)
-{
-   if (!ctx->fs_depth[pipe_tex]) {
-  unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex, 0);
-
-  ctx->fs_depth[pipe_tex] =
- util_make_fragment_tex_shader_writedepth(ctx->pipe, tgsi_tex,
-  TGSI_INTERPOLATE_LINEAR);
-   }
-
-   cso_set_fragment_shader_handle(ctx->cso, ctx->fs_depth[pipe_tex]);
-}
-
-
-/**
- * Helper function to set the shader which writes stencil.
- */
-stati

[Mesa-dev] [PATCH 2/3] util/u_blit: Support blits from cubemaps.

2013-09-17 Thread jfonseca
From: José Fonseca 

By calling util_map_texcoords2d_onto_cubemap.

A new parameter for util_blit_pixels_tex is necessary, as
pipe_sampler_view::first_layer is always supposed to point to the first
face when sampling from cubemaps.
---
 src/gallium/auxiliary/util/u_blit.c | 34 +++---
 src/gallium/auxiliary/util/u_blit.h |  1 +
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_blit.c 
b/src/gallium/auxiliary/util/u_blit.c
index 8cc080c..e9bec4a 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -46,6 +46,7 @@
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "util/u_sampler.h"
+#include "util/u_texture.h"
 #include "util/u_simple_shaders.h"
 
 #include "cso_cache/cso_context.h"
@@ -143,7 +144,6 @@ util_create_blit(struct pipe_context *pipe, struct 
cso_context *cso)
/* init vertex data that doesn't change */
for (i = 0; i < 4; i++) {
   ctx->vertices[i][0][3] = 1.0f; /* w */
-  ctx->vertices[i][1][2] = 0.0f; /* r */
   ctx->vertices[i][1][3] = 1.0f; /* q */
}
 
@@ -327,6 +327,8 @@ get_next_slot( struct blit_state *ctx )
  */
 static unsigned
 setup_vertex_data_tex(struct blit_state *ctx,
+  unsigned src_target,
+  unsigned src_face,
   float x0, float y0, float x1, float y1,
   float s0, float t0, float s1, float t1,
   float z)
@@ -338,24 +340,37 @@ setup_vertex_data_tex(struct blit_state *ctx,
ctx->vertices[0][0][2] = z;
ctx->vertices[0][1][0] = s0; /*s*/
ctx->vertices[0][1][1] = t0; /*t*/
+   ctx->vertices[0][1][2] = 0;  /*r*/
 
ctx->vertices[1][0][0] = x1;
ctx->vertices[1][0][1] = y0;
ctx->vertices[1][0][2] = z;
ctx->vertices[1][1][0] = s1; /*s*/
ctx->vertices[1][1][1] = t0; /*t*/
+   ctx->vertices[1][1][2] = 0;  /*r*/
 
ctx->vertices[2][0][0] = x1;
ctx->vertices[2][0][1] = y1;
ctx->vertices[2][0][2] = z;
ctx->vertices[2][1][0] = s1;
ctx->vertices[2][1][1] = t1;
+   ctx->vertices[3][1][2] = 0;
 
ctx->vertices[3][0][0] = x0;
ctx->vertices[3][0][1] = y1;
ctx->vertices[3][0][2] = z;
ctx->vertices[3][1][0] = s0;
ctx->vertices[3][1][1] = t1;
+   ctx->vertices[3][1][2] = 0;
+
+   if (src_target == PIPE_TEXTURE_CUBE ||
+   src_target == PIPE_TEXTURE_CUBE_ARRAY) {
+  /* Map cubemap texture coordinates inplace. */
+  const unsigned stride = sizeof ctx->vertices[0] / sizeof 
ctx->vertices[0][0][0];
+  util_map_texcoords2d_onto_cubemap(src_face,
+&ctx->vertices[0][1][0], stride,
+&ctx->vertices[0][1][0], stride);
+   }
 
offset = get_next_slot( ctx );
 
@@ -770,6 +785,8 @@ util_blit_pixels(struct blit_state *ctx,
 
/* draw quad */
offset = setup_vertex_data_tex(ctx,
+  sampler_view->texture->target,
+  srcZ0 % 6,
   (float) dstX0 / dst_surface->width * 2.0f - 
1.0f,
   (float) dstY0 / dst_surface->height * 2.0f - 
1.0f,
   (float) dstX1 / dst_surface->width * 2.0f - 
1.0f,
@@ -811,16 +828,25 @@ util_blit_pixels(struct blit_state *ctx,
 
 
 /**
- * Copy pixel block from src texture to dst surface.
+ * Copy pixel block from src sampler view to dst surface.
+ *
  * The sampler view's first_level field indicates the source
  * mipmap level to use.
- * XXX need some control over blitting Z and/or stencil.
+ *
+ * The sampler view's first_layer indicate the layer to use, but for
+ * cube maps it must point to the first face.  Face is passed in src_face.
+ *
+ * The main advantage over util_blit_pixels is that it allows to specify 
swizzles in
+ * pipe_sampler_view::swizzle_?.
+ *
+ * But there is no control over blitting Z and/or stencil.
  */
 void
 util_blit_pixels_tex(struct blit_state *ctx,
  struct pipe_sampler_view *src_sampler_view,
  int srcX0, int srcY0,
  int srcX1, int srcY1,
+ unsigned src_face,
  struct pipe_surface *dst,
  int dstX0, int dstY0,
  int dstX1, int dstY1,
@@ -922,6 +948,8 @@ util_blit_pixels_tex(struct blit_state *ctx,
 
/* draw quad */
offset = setup_vertex_data_tex(ctx,
+  src_sampler_view->texture->target,
+  src_face,
   (float) dstX0 / dst->width * 2.0f - 1.0f,
   (float) dstY0 / dst->height * 2.0f - 1.0f,
   (float) dstX1 / dst->width * 2.0f - 1.0f,
diff --git a/src/gallium/auxiliary/util/u_blit.h 
b/src/gallium/auxiliary/util/u_blit.h
index 56ab030..bfcd1bb 100644
--- a/src/gallium/auxiliary/util/u_blit

[Mesa-dev] [PATCH 1/3] vega: Use pipe_context::blit instead of util_blit_pixels_tex.

2013-09-17 Thread jfonseca
From: José Fonseca 

Only compile-tested but it seems straightforward.
---
 src/gallium/state_trackers/vega/vg_context.c | 44 
 src/gallium/state_trackers/vega/vg_context.h |  2 --
 2 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/src/gallium/state_trackers/vega/vg_context.c 
b/src/gallium/state_trackers/vega/vg_context.c
index c636188..46c7d96 100644
--- a/src/gallium/state_trackers/vega/vg_context.c
+++ b/src/gallium/state_trackers/vega/vg_context.c
@@ -41,7 +41,6 @@
 #include "cso_cache/cso_context.h"
 
 #include "util/u_memory.h"
-#include "util/u_blit.h"
 #include "util/u_sampler.h"
 #include "util/u_surface.h"
 #include "util/u_format.h"
@@ -138,8 +137,6 @@ struct vg_context * vg_create_context(struct pipe_context 
*pipe,
ctx->sc = shaders_cache_create(ctx);
ctx->shader = shader_create(ctx);
 
-   ctx->blit = util_create_blit(ctx->pipe, ctx->cso_context);
-
return ctx;
 }
 
@@ -147,7 +144,6 @@ void vg_destroy_context(struct vg_context *ctx)
 {
struct pipe_resource **cbuf = &ctx->mask.cbuf;
 
-   util_destroy_blit(ctx->blit);
renderer_destroy(ctx->renderer);
shaders_cache_destroy(ctx->sc);
shader_destroy(ctx->shader);
@@ -443,23 +439,35 @@ static void vg_prepare_blend_texture(struct vg_context 
*ctx,
  struct pipe_sampler_view *src)
 {
struct st_framebuffer *stfb = ctx->draw_buffer;
-   struct pipe_surface *surf;
-   struct pipe_surface surf_tmpl;
+   struct pipe_context *pipe = ctx->pipe;
+   struct pipe_blit_info info;
 
vg_context_update_blend_texture_view(ctx, stfb->width, stfb->height);
 
-   u_surface_default_template(&surf_tmpl, stfb->blend_texture_view->texture);
-   surf = ctx->pipe->create_surface(ctx->pipe,
-stfb->blend_texture_view->texture,
-&surf_tmpl);
-   if (surf) {
-  util_blit_pixels_tex(ctx->blit,
-   src, 0, 0, stfb->width, stfb->height,
-   surf, 0, 0, stfb->width, stfb->height,
-   0.0, PIPE_TEX_MIPFILTER_NEAREST);
-
-  pipe_surface_reference(&surf, NULL);
-   }
+   memset(&info, 0, sizeof info);
+   info.dst.resource = stfb->blend_texture_view->texture;
+   info.dst.level = 0;
+   info.dst.box.x = 0;
+   info.dst.box.y = 0;
+   info.dst.box.z = 0;
+   info.dst.box.width = stfb->width;
+   info.dst.box.height = stfb->height;
+   info.dst.box.depth = 1;
+   info.dst.format = stfb->blend_texture_view->format;
+   info.src.resource = src->texture;
+   info.src.level = src->u.tex.first_level;
+   info.src.box.x = 0;
+   info.src.box.y = 0;
+   info.src.box.z = src->u.tex.first_layer;
+   info.src.box.width = stfb->width;
+   info.src.box.height = stfb->height;
+   info.src.box.depth = 1;
+   info.src.format = src->format;
+   info.mask = PIPE_MASK_RGBA;
+   info.filter = PIPE_TEX_MIPFILTER_NEAREST;
+   info.scissor_enable = 0;
+
+   pipe->blit(pipe, &info);
 }
 
 struct pipe_sampler_view *vg_prepare_blend_surface(struct vg_context *ctx)
diff --git a/src/gallium/state_trackers/vega/vg_context.h 
b/src/gallium/state_trackers/vega/vg_context.h
index d61c7cf..5a2a322 100644
--- a/src/gallium/state_trackers/vega/vg_context.h
+++ b/src/gallium/state_trackers/vega/vg_context.h
@@ -129,8 +129,6 @@ struct vg_context
struct pipe_sampler_state blend_sampler;
struct vg_paint *default_paint;
 
-   struct blit_state *blit;
-
int32_t draw_stamp;
 };
 
-- 
1.8.1.2

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


[Mesa-dev] [PATCH] llvmpipe: Fix rendering to PIPE_FORMAT_R10G10B10A2_UNORM.

2013-09-20 Thread jfonseca
From: José Fonseca 

We must take rounding in consideration when re-scaling to narrow
normalized channels, such as 2-bit normalized alpha.
---
 src/gallium/drivers/llvmpipe/lp_state_fs.c | 84 +++---
 1 file changed, 78 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c 
b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index 07e6685..875a3cf 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -876,7 +876,22 @@ lp_blend_type_from_format_desc(const struct 
util_format_description *format_desc
 
 
 /**
- * Scale a normalized value from src_bits to dst_bits
+ * Scale a normalized value from src_bits to dst_bits.
+ *
+ * The exact calculation is
+ *
+ *dst = iround(src * dst_mask / src_mask)
+ *
+ *  or with integer rounding
+ *
+ *dst = src * (2*dst_mask + sign(src)*src_mask) / (2*src_mask)
+ *
+ *  where
+ *
+ *src_mask = (1 << src_bits) - 1
+ *dst_mask = (1 << dst_bits) - 1
+ *
+ * but we try to avoid division and multiplication through shifts.
  */
 static INLINE LLVMValueRef
 scale_bits(struct gallivm_state *gallivm,
@@ -889,11 +904,68 @@ scale_bits(struct gallivm_state *gallivm,
LLVMValueRef result = src;
 
if (dst_bits < src_bits) {
-  /* Scale down by LShr */
-  result = LLVMBuildLShr(builder,
- src,
- lp_build_const_int_vec(gallivm, src_type, 
src_bits - dst_bits),
- "");
+  int delta_bits = src_bits - dst_bits;
+
+  if (delta_bits <= dst_bits) {
+ /*
+  * Approximate the rescaling with a single shift.
+  *
+  * This gives the wrong rounding.
+  */
+
+ result = LLVMBuildLShr(builder,
+src,
+lp_build_const_int_vec(gallivm, src_type, 
delta_bits),
+"");
+
+  } else {
+ /*
+  * Try more accurate rescaling.
+  */
+
+ /*
+  * Drop the least significant bits to make space for the 
multiplication.
+  *
+  * XXX: A better approach would be to use a wider integer type as 
intermediate.  But
+  * this is enough to convert alpha from 16bits -> 2 when rendering to
+  * PIPE_FORMAT_R10G10B10A2_UNORM.
+  */
+ result = LLVMBuildLShr(builder,
+src,
+lp_build_const_int_vec(gallivm, src_type, 
dst_bits),
+"");
+
+
+ result = LLVMBuildMul(builder,
+   result,
+   lp_build_const_int_vec(gallivm, src_type, (1LL 
<< dst_bits) - 1),
+   "");
+
+ /*
+  * Add a rounding term before the division.
+  *
+  * TODO: Handle signed integers too.
+  */
+ if (!src_type.sign) {
+result = LLVMBuildAdd(builder,
+  result,
+  lp_build_const_int_vec(gallivm, src_type, 
(1LL << (delta_bits - 1))),
+  "");
+ }
+
+ /*
+  * Approximate the division by src_mask with a src_bits shift.
+  *
+  * Given the src has already been shifted by dst_bits, all we need
+  * to do is to shift by the difference.
+  */
+
+ result = LLVMBuildLShr(builder,
+result,
+lp_build_const_int_vec(gallivm, src_type, 
delta_bits),
+"");
+  }
+
} else if (dst_bits > src_bits) {
   /* Scale up bits */
   int db = dst_bits - src_bits;
-- 
1.8.1.2

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


[Mesa-dev] [PATCH] llvmpipe: Fix rendering into PIPE_FORMAT_X8B8G8R8_UNORM.

2013-02-21 Thread jfonseca
From: José Fonseca 

Weird format, which Mesa state tracker recently started using.

Fixes segfault in

  ./bin/texture-packed-formats -auto

because swizzle[foo] was 0xff for padding channel (X). It still fails though.

I believe the only reason this doesn't BGRX doesn't crash is that we have
special code for when X in in the last channel.
---
 src/gallium/drivers/llvmpipe/lp_state_fs.c |   16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c 
b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index 44a9fcb..9bf9b9c 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -1493,7 +1493,7 @@ generate_unswizzled_blend(struct gallivm_state *gallivm,
vector_width= dst_type.floating ? lp_native_vector_width : 
lp_integer_vector_width;
 
/* Compute correct swizzle and count channels */
-   memset(swizzle, 0xFF, TGSI_NUM_CHANNELS);
+   memset(swizzle, LP_BLD_SWIZZLE_DONTCARE, TGSI_NUM_CHANNELS);
dst_channels = 0;
 
for (i = 0; i < TGSI_NUM_CHANNELS; ++i) {
@@ -1538,7 +1538,12 @@ generate_unswizzled_blend(struct gallivm_state *gallivm,
 
   /* Load each channel */
   for (j = 0; j < dst_channels; ++j) {
- fs_src[i][j] = LLVMBuildLoad(builder, 
fs_out_color[rt][swizzle[j]][i], "");
+ unsigned src_channel = swizzle[j];
+ if (src_channel < 4) {
+fs_src[i][j] = LLVMBuildLoad(builder, 
fs_out_color[rt][src_channel][i], "");
+ } else {
+fs_src[i][j] = lp_build_undef(gallivm, fs_type);
+ }
   }
 
   /* If 3 channels then pad to include alpha for 4 element transpose */
@@ -1568,7 +1573,12 @@ generate_unswizzled_blend(struct gallivm_state *gallivm,
  LLVMValueRef alpha = LLVMBuildLoad(builder, 
fs_out_color[1][alpha_channel][i], "");
 
  for (j = 0; j < dst_channels; ++j) {
-fs_src1[i][j] = LLVMBuildLoad(builder, 
fs_out_color[1][swizzle[j]][i], "");
+unsigned src_channel = swizzle[j];
+if (src_channel < 4) {
+   fs_src1[i][j] = LLVMBuildLoad(builder, 
fs_out_color[1][src_channel][i], "");
+} else {
+   fs_src1[i][j] = lp_build_undef(gallivm, fs_type);
+}
  }
  if (dst_channels == 3 && !has_alpha) {
 fs_src1[i][3] = alpha;
-- 
1.7.10.4

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


[Mesa-dev] [PATCH] tgsi: Improve execution debugging.

2013-02-22 Thread jfonseca
From: José Fonseca 

- zero temps/outputs instead of copying (otherwise we won't be able to see
  the temps/outputs assignements for small shaders where nothing changes
  across big areas

- also show the inputs (as it's often impossible to infer from the rest)
---
 src/gallium/auxiliary/tgsi/tgsi_exec.c |   29 -
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c 
b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index 1099d06..a2b2a81 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -62,6 +62,9 @@
 #include "util/u_math.h"
 
 
+#define DEBUG_EXECUTION 0
+
+
 #define FAST_MATH 0
 
 #define TILE_TOP_LEFT 0
@@ -2456,6 +2459,23 @@ exec_declaration(struct tgsi_exec_machine *mach,
}
 }
  }
+
+ if (DEBUG_EXECUTION) {
+uint i, j;
+for (i = first; i <= last; ++i) {
+   debug_printf("IN[%2u] = ", i);
+   for (j = 0; j < TGSI_NUM_CHANNELS; j++) {
+  if (j > 0) {
+ debug_printf(" ");
+  }
+  debug_printf("(%6f %u, %6f %u, %6f %u, %6f %u)\n",
+   mach->Inputs[i].xyzw[0].f[j], 
mach->Inputs[i].xyzw[0].u[j],
+   mach->Inputs[i].xyzw[1].f[j], 
mach->Inputs[i].xyzw[1].u[j],
+   mach->Inputs[i].xyzw[2].f[j], 
mach->Inputs[i].xyzw[2].u[j],
+   mach->Inputs[i].xyzw[3].f[j], 
mach->Inputs[i].xyzw[3].u[j]);
+   }
+}
+ }
   }
}
 
@@ -4304,9 +4324,6 @@ exec_instruction(
 }
 
 
-#define DEBUG_EXECUTION 0
-
-
 /**
  * Run TGSI interpreter.
  * \return bitmask of "alive" quad components
@@ -4351,8 +4368,10 @@ tgsi_exec_machine_run( struct tgsi_exec_machine *mach )
   struct tgsi_exec_vector outputs[PIPE_MAX_ATTRIBS];
   uint inst = 1;
 
-  memcpy(temps, mach->Temps, sizeof(temps));
-  memcpy(outputs, mach->Outputs, sizeof(outputs));
+  memset(mach->Temps, 0, sizeof(temps));
+  memset(mach->Outputs, 0, sizeof(outputs));
+  memset(temps, 0, sizeof(temps));
+  memset(outputs, 0, sizeof(outputs));
 #endif
 
   /* execute instructions, until pc is set to -1 */
-- 
1.7.9.5

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


[Mesa-dev] [PATCH] util/dump: Use static assertion to detect string table size mismatches.

2013-02-23 Thread jfonseca
From: José Fonseca 

Suggested by Brian Paul.

Could probably be extended to other enums.
---
 src/gallium/auxiliary/util/u_dump_defines.c |   19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/util/u_dump_defines.c 
b/src/gallium/auxiliary/util/u_dump_defines.c
index 2a996b2..cc62687 100644
--- a/src/gallium/auxiliary/util/u_dump_defines.c
+++ b/src/gallium/auxiliary/util/u_dump_defines.c
@@ -73,6 +73,23 @@ util_dump_enum_continuous(unsigned value,
}
 
 
+/**
+ * Same as DEFINE_UTIL_DUMP_CONTINUOUS but with static assertions to detect
+ * failures to update lists.
+ */
+#define DEFINE_UTIL_DUMP_CONTINUOUS_COUNT(_name, _count) \
+   const char * \
+   util_dump_##_name(unsigned value, boolean shortened) \
+   { \
+  STATIC_ASSERT(Elements(util_dump_##_name##_names) == _count); \
+  STATIC_ASSERT(Elements(util_dump_##_name##_short_names) == _count); \
+  if(shortened) \
+ return util_dump_enum_continuous(value, 
Elements(util_dump_##_name##_short_names), util_dump_##_name##_short_names); \
+  else \
+ return util_dump_enum_continuous(value, 
Elements(util_dump_##_name##_names), util_dump_##_name##_names); \
+   }
+
+
 static const char *
 util_dump_blend_factor_names[] = {
UTIL_DUMP_INVALID_NAME, /* 0x0 */
@@ -282,7 +299,7 @@ util_dump_tex_target_short_names[] = {
"cube_array",
 };
 
-DEFINE_UTIL_DUMP_CONTINUOUS(tex_target)
+DEFINE_UTIL_DUMP_CONTINUOUS_COUNT(tex_target, PIPE_MAX_TEXTURE_TYPES)
 
 
 static const char *
-- 
1.7.10.4

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


[Mesa-dev] [PATCH] util/u_blitter: Set pipe_sampler_state::normalized_coords correctly.

2013-02-23 Thread jfonseca
From: José Fonseca 

We might want to revisit the normalized_coords semantics, but this is
the current expected behavior.

Fixes fdo bug 61091.
---
 src/gallium/auxiliary/util/u_blitter.c |   26 ++
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_blitter.c 
b/src/gallium/auxiliary/util/u_blitter.c
index 9522402..e37be4e 100644
--- a/src/gallium/auxiliary/util/u_blitter.c
+++ b/src/gallium/auxiliary/util/u_blitter.c
@@ -103,7 +103,10 @@ struct blitter_context_priv
void *velem_state_readbuf;
 
/* Sampler state. */
-   void *sampler_state, *sampler_state_linear;
+   void *sampler_state;
+   void *sampler_state_linear;
+   void *sampler_state_rect;
+   void *sampler_state_rect_linear;
 
/* Rasterizer state. */
void *rs_state, *rs_state_scissor, *rs_discard_state;
@@ -223,10 +226,15 @@ struct blitter_context *util_blitter_create(struct 
pipe_context *pipe)
sampler_state.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
sampler_state.normalized_coords = 1;
ctx->sampler_state = pipe->create_sampler_state(pipe, &sampler_state);
+   sampler_state.normalized_coords = 0;
+   ctx->sampler_state_rect = pipe->create_sampler_state(pipe, &sampler_state);
 
sampler_state.min_img_filter = PIPE_TEX_FILTER_LINEAR;
sampler_state.mag_img_filter = PIPE_TEX_FILTER_LINEAR;
+   sampler_state.normalized_coords = 1;
ctx->sampler_state_linear = pipe->create_sampler_state(pipe, 
&sampler_state);
+   sampler_state.normalized_coords = 0;
+   ctx->sampler_state_rect_linear = pipe->create_sampler_state(pipe, 
&sampler_state);
 
/* rasterizer state */
memset(&rs_state, 0, sizeof(rs_state));
@@ -365,8 +373,10 @@ void util_blitter_destroy(struct blitter_context *blitter)
  ctx->delete_fs_state(pipe, ctx->fs_col_int[i]);
}
 
-   pipe->delete_sampler_state(pipe, ctx->sampler_state);
+   pipe->delete_sampler_state(pipe, ctx->sampler_state_rect_linear);
+   pipe->delete_sampler_state(pipe, ctx->sampler_state_rect);
pipe->delete_sampler_state(pipe, ctx->sampler_state_linear);
+   pipe->delete_sampler_state(pipe, ctx->sampler_state);
u_upload_destroy(ctx->upload);
FREE(ctx);
 }
@@ -1317,9 +1327,17 @@ void util_blitter_blit_generic(struct blitter_context 
*blitter,
src_samples <= 1 &&
(dstbox->width != abs(srcbox->width) ||
 dstbox->height != abs(srcbox->height))) {
-  sampler_state = ctx->sampler_state_linear;
+  if (src_target == PIPE_TEXTURE_RECT) {
+ sampler_state = ctx->sampler_state_rect_linear;
+  } else {
+ sampler_state = ctx->sampler_state_linear;
+  }
} else {
-  sampler_state = ctx->sampler_state;
+  if (src_target == PIPE_TEXTURE_RECT) {
+ sampler_state = ctx->sampler_state_rect;
+  } else {
+ sampler_state = ctx->sampler_state;
+  }
}
 
/* Set samplers. */
-- 
1.7.10.4

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


[Mesa-dev] [PATCH 1/3] scons: Allows choosing VS 10 or 11.

2013-03-12 Thread jfonseca
From: José Fonseca 

---
 common.py |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common.py b/common.py
index 6ff9608..1d618e6 100644
--- a/common.py
+++ b/common.py
@@ -100,4 +100,4 @@ def AddOptions(opts):
opts.Add(BoolOption('quiet', 'DEPRECATED: profile build', 'yes'))
opts.Add(BoolOption('texture_float', 'enable floating-point textures 
and renderbuffers', 'no'))
if host_platform == 'windows':
-   opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', 
None, allowed_values=('7.1', '8.0', '9.0')))
+   opts.Add(EnumOption('MSVC_VERSION', 'MS Visual C++ version', 
None, allowed_values=('7.1', '8.0', '9.0', '10.0', '11.0')))
-- 
1.7.9.5

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


[Mesa-dev] [PATCH 2/3] One definition of C99 inline/__func__ to rule them all.

2013-03-12 Thread jfonseca
From: José Fonseca 

We were in four already...
---
 include/c99_compat.h  |  105 +
 src/egl/main/eglcompiler.h|   44 ++
 src/gallium/include/pipe/p_compiler.h |   74 ++-
 src/mapi/mapi/u_compiler.h|   26 ++--
 src/mesa/main/compiler.h  |   56 ++
 5 files changed, 125 insertions(+), 180 deletions(-)
 create mode 100644 include/c99_compat.h

diff --git a/include/c99_compat.h b/include/c99_compat.h
new file mode 100644
index 000..39f958f
--- /dev/null
+++ b/include/c99_compat.h
@@ -0,0 +1,105 @@
+/**
+ *
+ * Copyright 2007-2013 VMware, Inc.
+ * 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.
+ *
+ **/
+
+#ifndef _C99_COMPAT_H_
+#define _C99_COMPAT_H_
+
+
+/*
+ * C99 inline keyword
+ */
+#ifndef inline
+#  ifdef __cplusplus
+ /* C++ supports inline keyword */
+#  elif defined(__GNUC__)
+#define inline __inline__
+#  elif defined(_MSC_VER)
+#define inline __inline
+#  elif defined(__ICL)
+#define inline __inline
+#  elif defined(__INTEL_COMPILER)
+ /* Intel compiler supports inline keyword */
+#  elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
+#define inline __inline
+#  elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
+ /* C99 supports inline keyword */
+#  elif (__STDC_VERSION__ >= 199901L)
+ /* C99 supports inline keyword */
+#  else
+#define inline
+#  endif
+#endif
+
+
+/*
+ * C99 restrict keyword
+ *
+ * See also:
+ * - 
http://cellperformance.beyond3d.com/articles/2006/05/demystifying-the-restrict-keyword.html
+ */
+#ifndef restrict
+#  if (__STDC_VERSION__ >= 199901L)
+ /* C99 */
+#  elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
+ /* C99 */
+#  elif defined(__GNUC__)
+#define restrict __restrict__
+#  elif defined(_MSC_VER)
+#define restrict __restrict
+#  else
+#define restrict /* */
+#  endif
+#endif
+
+
+/*
+ * C99 __func__ macro
+ */
+#ifndef __func__
+#  if (__STDC_VERSION__ >= 199901L)
+ /* C99 */
+#  elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
+ /* C99 */
+#  elif defined(__GNUC__)
+#if __GNUC__ >= 2
+#  define __func__ __FUNCTION__
+#else
+#  define __func__ ""
+#endif
+#  elif defined(_MSC_VER)
+#if _MSC_VER >= 1300
+#  define __func__ __FUNCTION__
+#else
+#  define __func__ ""
+#endif
+#  else
+#define __func__ ""
+#  endif
+#endif
+
+
+#endif /* _C99_COMPAT_H_ */
diff --git a/src/egl/main/eglcompiler.h b/src/egl/main/eglcompiler.h
index 9823693..2499172 100644
--- a/src/egl/main/eglcompiler.h
+++ b/src/egl/main/eglcompiler.h
@@ -31,6 +31,9 @@
 #define EGLCOMPILER_INCLUDED
 
 
+#include "c99_compat.h" /* inline, __func__, etc. */
+
+
 /**
  * Get standard integer types
  */
@@ -62,30 +65,7 @@
 #endif
 
 
-/**
- * Function inlining
- */
-#ifndef inline
-#  ifdef __cplusplus
- /* C++ supports inline keyword */
-#  elif defined(__GNUC__)
-#define inline __inline__
-#  elif defined(_MSC_VER)
-#define inline __inline
-#  elif defined(__ICL)
-#define inline __inline
-#  elif defined(__INTEL_COMPILER)
- /* Intel compiler supports inline keyword */
-#  elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
-#define inline __inline
-#  elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
- /* C99 supports inline keyword */
-#  elif (__STDC_VERSION__ >= 199901L)
- /* C99 supports inline keyword */
-#  else
-#define inline
-#  endif
-#endif
+/* XXX: Use standard `inline` keyword instead */
 #ifndef INLINE
 #  define INLINE inline
 #endif
@@ -104,21 +84,9 @@
 #  endif
 #endif
 
-/**
- * The __FUNCTION__ gcc variable is generally only used for debugging.
- * If we're not using gcc, def

[Mesa-dev] [PATCH 3/3] Fix build with VS 2011.

2013-03-12 Thread jfonseca
From: José Fonseca 

---
 include/c99_compat.h |   42 ++
 1 file changed, 42 insertions(+)

diff --git a/include/c99_compat.h b/include/c99_compat.h
index 39f958f..3a9f502 100644
--- a/include/c99_compat.h
+++ b/include/c99_compat.h
@@ -30,6 +30,37 @@
 
 
 /*
+ * MSVC hacks.
+ */
+#if defined(_MSC_VER)
+   /*
+* Visual Studio 2012 will complain if we define the `inline` keyword, but
+* actually it only supports the keyword on C++.
+*
+* We could skip this check by defining _ALLOW_KEYWORD_MACROS, but there is
+* probably value in checking this for other keywords.  So simply include
+* the checking before we define it below.
+*/
+#  if _MSC_VER >= 1700
+#include 
+#  endif
+
+   /*
+* XXX: MSVC has a `__restrict` keyword, but it also has a
+* `__declspec(restrict)` modifier, so it is impossible to define a
+* `restrict` macro without interfering with the latter.  Furthermore the
+* MSVC standard library uses __declspec(restrict) under the _CRTRESTRICT
+* macro.  For now resolve this issue by redefining _CRTRESTRICT, but going
+* forward we should probably should stop using restrict, especially
+* considering that our code does not obbey strict aliasing rules any way.
+*/
+#  include 
+#  undef _CRTRESTRICT
+#  define _CRTRESTRICT
+#endif
+
+
+/*
  * C99 inline keyword
  */
 #ifndef inline
@@ -102,4 +133,15 @@
 #endif
 
 
+/* Simple test case for debugging */
+#if 0
+static inline const char *
+test_c99_compat_h(const void * restrict a,
+  const void * restrict b)
+{
+   return __func__;
+}
+#endif
+
+
 #endif /* _C99_COMPAT_H_ */
-- 
1.7.9.5

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


[Mesa-dev] [PATCH] scons: Define _ALLOW_KEYWORD_MACROS on MSVC builds.

2013-03-14 Thread jfonseca
From: José Fonseca 

scons/llvm.py defines inline globally to workaround issues with LLVM C
binding headers, so the only way to is to avoid
aggravating xkeycheck.h errors is to set _ALLOW_KEYWORD_MACROS.

This fixes MSVC 2012 build with LLVM.
---
 include/c99_compat.h |8 +++-
 scons/gallium.py |1 +
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/c99_compat.h b/include/c99_compat.h
index 3a9f502..429c601 100644
--- a/include/c99_compat.h
+++ b/include/c99_compat.h
@@ -37,12 +37,10 @@
 * Visual Studio 2012 will complain if we define the `inline` keyword, but
 * actually it only supports the keyword on C++.
 *
-* We could skip this check by defining _ALLOW_KEYWORD_MACROS, but there is
-* probably value in checking this for other keywords.  So simply include
-* the checking before we define it below.
+* To avoid this the _ALLOW_KEYWORD_MACROS must be set.
 */
-#  if _MSC_VER >= 1700
-#include 
+#  if (_MSC_VER >= 1700) && !defined(_ALLOW_KEYWORD_MACROS)
+#define _ALLOW_KEYWORD_MACROS
 #  endif
 
/*
diff --git a/scons/gallium.py b/scons/gallium.py
index 4b51b6e..4d3de82 100755
--- a/scons/gallium.py
+++ b/scons/gallium.py
@@ -289,6 +289,7 @@ def generate(env):
 '_CRT_SECURE_NO_DEPRECATE',
 '_SCL_SECURE_NO_WARNINGS',
 '_SCL_SECURE_NO_DEPRECATE',
+'_ALLOW_KEYWORD_MACROS',
 ]
 if env['build'] in ('debug', 'checked'):
 cppdefines += ['_DEBUG']
-- 
1.7.9.5

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


[Mesa-dev] [PATCH] scons: Warn when using MSVS versions prior to 2012.

2013-03-15 Thread jfonseca
From: José Fonseca 

---
 scons/gallium.py |2 ++
 1 file changed, 2 insertions(+)

diff --git a/scons/gallium.py b/scons/gallium.py
index 4d3de82..b28be5d 100755
--- a/scons/gallium.py
+++ b/scons/gallium.py
@@ -402,6 +402,8 @@ def generate(env):
   '/Oi', # enable intrinsic functions
 ]
 else:
+if distutils.version.LooseVersion(env['MSVC_VERSION']) < 
distutils.version.LooseVersion('11.0'):
+print 'scons: warning: Visual Studio versions prior to 2012 
are known to produce incorrect code when optimizations are enabled ( 
https://bugs.freedesktop.org/show_bug.cgi?id=58718 )'
 ccflags += [
 '/O2', # optimize for speed
 ]
-- 
1.7.9.5

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


[Mesa-dev] [PATCH 1/2] gallium: Eliminate TGSI_OPCODE_IFC.

2013-04-14 Thread jfonseca
From: José Fonseca 

Never used or implemented.
---
 src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c |1 -
 src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c  |1 -
 src/gallium/auxiliary/tgsi/tgsi_info.c   |2 +-
 src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h |1 -
 src/gallium/docs/source/tgsi.rst |5 -
 src/gallium/drivers/r300/r300_tgsi_to_rc.c   |1 -
 src/gallium/drivers/r600/r600_shader.c   |9 ++---
 src/gallium/include/pipe/p_shader_tokens.h   |2 +-
 8 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c 
b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c
index a4caf78..3c79abf 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c
@@ -389,7 +389,6 @@ analyse_instruction(struct analysis_context *ctx,
 
switch (inst->Instruction.Opcode) {
case TGSI_OPCODE_IF:
-   case TGSI_OPCODE_IFC:
case TGSI_OPCODE_ELSE:
case TGSI_OPCODE_ENDIF:
case TGSI_OPCODE_BGNLOOP:
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c 
b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
index 853de09..239530d 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
@@ -1732,7 +1732,6 @@ near_end_of_shader(struct lp_build_tgsi_soa_context *bld,
  opcode == TGSI_OPCODE_CAL ||
  opcode == TGSI_OPCODE_CALLNZ ||
  opcode == TGSI_OPCODE_IF ||
- opcode == TGSI_OPCODE_IFC ||
  opcode == TGSI_OPCODE_BGNLOOP ||
  opcode == TGSI_OPCODE_SWITCH)
 return FALSE;
diff --git a/src/gallium/auxiliary/tgsi/tgsi_info.c 
b/src/gallium/auxiliary/tgsi/tgsi_info.c
index 1fadfec..716b16b 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_info.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_info.c
@@ -151,7 +151,7 @@ static const struct tgsi_opcode_info 
opcode_info[TGSI_OPCODE_LAST] =
{ 0, 0, 0, 0, 0, 0, NONE, "", 111 }, /* removed */
{ 1, 1, 0, 0, 0, 0, REPL, "NRM4", TGSI_OPCODE_NRM4 },
{ 0, 1, 0, 0, 0, 0, NONE, "CALLNZ", TGSI_OPCODE_CALLNZ },
-   { 0, 1, 0, 0, 0, 0, NONE, "IFC", TGSI_OPCODE_IFC },
+   { 0, 1, 0, 0, 0, 0, NONE, "", 114 }, /* removed */
{ 0, 1, 0, 0, 0, 0, NONE, "BREAKC", TGSI_OPCODE_BREAKC },
{ 0, 1, 0, 0, 0, 0, NONE, "KIL", TGSI_OPCODE_KIL },
{ 0, 0, 0, 0, 0, 0, NONE, "END", TGSI_OPCODE_END },
diff --git a/src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h 
b/src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h
index fa30352..b8519c6 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h
@@ -154,7 +154,6 @@ OP00(ENDSUB)
 OP00(NOP)
 OP11(NRM4)
 OP01(CALLNZ)
-OP01(IFC)
 OP01(BREAKC)
 OP01(KIL)
 OP00(END)
diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst
index 28308cb..0002626 100644
--- a/src/gallium/docs/source/tgsi.rst
+++ b/src/gallium/docs/source/tgsi.rst
@@ -1198,11 +1198,6 @@ XXX wait what
   TBD
 
 
-.. opcode:: IFC - If
-
-  TBD
-
-
 .. opcode:: BREAKC - Break Conditional
 
   TBD
diff --git a/src/gallium/drivers/r300/r300_tgsi_to_rc.c 
b/src/gallium/drivers/r300/r300_tgsi_to_rc.c
index a0587b4..5e60e6c 100644
--- a/src/gallium/drivers/r300/r300_tgsi_to_rc.c
+++ b/src/gallium/drivers/r300/r300_tgsi_to_rc.c
@@ -135,7 +135,6 @@ static unsigned translate_opcode(unsigned opcode)
 /* gap */
  /* case TGSI_OPCODE_NRM4: return RC_OPCODE_NRM4; */
  /* case TGSI_OPCODE_CALLNZ: return RC_OPCODE_CALLNZ; */
- /* case TGSI_OPCODE_IFC: return RC_OPCODE_IFC; */
  /* case TGSI_OPCODE_BREAKC: return RC_OPCODE_BREAKC; */
 case TGSI_OPCODE_KIL: return RC_OPCODE_KIL;
 }
diff --git a/src/gallium/drivers/r600/r600_shader.c 
b/src/gallium/drivers/r600/r600_shader.c
index 6dbca50..44b5ce5 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -6035,7 +6035,8 @@ static struct r600_shader_tgsi_instruction 
r600_shader_tgsi_instruction[] = {
{111,   0, ALU_OP0_NOP, tgsi_unsupported},
{TGSI_OPCODE_NRM4,  0, ALU_OP0_NOP, tgsi_unsupported},
{TGSI_OPCODE_CALLNZ,0, ALU_OP0_NOP, tgsi_unsupported},
-   {TGSI_OPCODE_IFC,   0, ALU_OP0_NOP, tgsi_unsupported},
+   /* gap */
+   {114,   0, ALU_OP0_NOP, tgsi_unsupported},
{TGSI_OPCODE_BREAKC,0, ALU_OP0_NOP, tgsi_unsupported},
{TGSI_OPCODE_KIL,   0, ALU_OP2_KILLGT, tgsi_kill},  /* conditional 
kill */
{TGSI_OPCODE_END,   0, ALU_OP0_NOP, tgsi_end},  /* aka HALT */
@@ -6228,7 +6229,8 @@ static struct r600_shader_tgsi_instruction 
eg_shader_tgsi_instruction[] = {
{111,   0, ALU_OP0_NOP, tgsi_unsupported},
{TGSI_OPCODE_NRM4,  0, ALU_OP0_NOP, tgsi_unsupported},
{TGSI_OPCODE_CALLNZ,0, ALU_OP0_NOP, tgsi_unsupported},
-   {TGSI_OPCO

[Mesa-dev] [PATCH 2/2] gallium: Desambiguate TGSI_OPCODE_IF.

2013-04-14 Thread jfonseca
From: José Fonseca 

TGSI_OPCODE_IF condition had two possible interpretations:

- src.x != 0.0f

  - Mesa statetracker when PIPE_SHADER_CAP_INTEGERS was false either for
vertex and fragment shaders
  - gallivm/llvmpipe
  - postprocess
  - vl state tracker
  - vega state tracker
  - most old drivers
  - old internal state trackers
  - many graw examples

- src.x != 0U

  - Mesa statetracker when PIPE_SHADER_CAP_INTEGERS was true for both
vertex and fragment shaders
  - tgsi_exec/softpipe
  - r600
  - radeonsi
  - nv50

And drivers that use draw module also were a mess (because Mesa would
emit float IFs, but draw module supports native integers so it would
interpret IF arg as integers...)

This sort of works if the source argument is limited to float +0.0f or
+1.0f, integer 0, but would fail if source is float -0.0f, or integer in
the float NaN range.  It could also fail if source is integer 1, and
hardware flushes denormalized numbers to zero.

But with this change there are now two opcodes, IF and UIF, with clear
meaning.

Drivers that do not support native integers do not need to worry about
UIF.  However, for backwards compatibility with old state trackers and
examples, it is advisable that native integer capable drivers also
support the float IF opcode.

I tried to implement this for r600 and radeonsi based on the surrounding
code.  I couldn't do this for nouveau, so I just shunted IF/UIF
together, which matches the current behavior.
---
 src/gallium/auxiliary/gallivm/lp_bld_tgsi_action.c |1 +
 src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c|1 +
 src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c   |1 +
 src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c|   19 -
 src/gallium/auxiliary/tgsi/tgsi_dump.c |2 +
 src/gallium/auxiliary/tgsi/tgsi_exec.c |   22 +++
 src/gallium/auxiliary/tgsi/tgsi_info.c |2 +-
 src/gallium/auxiliary/tgsi/tgsi_opcode_tmp.h   |1 +
 src/gallium/docs/source/tgsi.rst   |   21 --
 .../drivers/nv50/codegen/nv50_ir_from_tgsi.cpp |6 +++
 src/gallium/drivers/r600/r600_shader.c |   21 +++---
 .../drivers/radeon/radeon_setup_tgsi_llvm.c|   41 
 src/gallium/include/pipe/p_shader_tokens.h |2 +-
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |8 +++-
 src/mesa/state_tracker/st_mesa_to_tgsi.c   |   12 +-
 15 files changed, 137 insertions(+), 23 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_action.c 
b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_action.c
index c71c1f1..e1c362b 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_action.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_action.c
@@ -868,6 +868,7 @@ lp_set_default_actions(struct lp_build_tgsi_context * 
bld_base)
bld_base->op_actions[TGSI_OPCODE_COS].fetch_args = scalar_unary_fetch_args;
bld_base->op_actions[TGSI_OPCODE_EX2].fetch_args = scalar_unary_fetch_args;
bld_base->op_actions[TGSI_OPCODE_IF].fetch_args = scalar_unary_fetch_args;
+   bld_base->op_actions[TGSI_OPCODE_UIF].fetch_args = scalar_unary_fetch_args;
bld_base->op_actions[TGSI_OPCODE_KIL].fetch_args = kil_fetch_args;
bld_base->op_actions[TGSI_OPCODE_KILP].fetch_args = kilp_fetch_args;
bld_base->op_actions[TGSI_OPCODE_RCP].fetch_args = scalar_unary_fetch_args;
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c 
b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
index 98bce0e..223184d 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
@@ -837,6 +837,7 @@ lp_emit_instruction_aos(
   return FALSE;
 
case TGSI_OPCODE_IF:
+   case TGSI_OPCODE_UIF:
   return FALSE;
 
case TGSI_OPCODE_BGNLOOP:
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c 
b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c
index 3c79abf..b00aa09 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_info.c
@@ -389,6 +389,7 @@ analyse_instruction(struct analysis_context *ctx,
 
switch (inst->Instruction.Opcode) {
case TGSI_OPCODE_IF:
+   case TGSI_OPCODE_UIF:
case TGSI_OPCODE_ELSE:
case TGSI_OPCODE_ENDIF:
case TGSI_OPCODE_BGNLOOP:
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c 
b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
index 239530d..362a1de 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
@@ -1732,7 +1732,8 @@ near_end_of_shader(struct lp_build_tgsi_soa_context *bld,
  opcode == TGSI_OPCODE_CAL ||
  opcode == TGSI_OPCODE_CALLNZ ||
  opcode == TGSI_OPCODE_IF ||
- opcode == TGSI_OPCODE_BGNLOOP ||
+  opcode == TGSI_OPCODE_UIF ||
+  opcode == TGSI_OPCODE_BGNLOOP ||
  opcode == TGSI_OPCODE_SWITCH)
 return FALSE;
}
@@ -2395,6 +2396,21 @@ if_emi

[Mesa-dev] [PATCH] gallivm: JIT symbol resolution with linux perf.

2013-04-17 Thread jfonseca
From: José Fonseca 

Details on docs/llvmpipe.html
---
 bin/perf-annotate-jit  |  240 
 configure.ac   |7 -
 docs/llvmpipe.html |   40 ++--
 src/gallium/auxiliary/gallivm/lp_bld_debug.cpp |  117 +---
 src/gallium/auxiliary/gallivm/lp_bld_debug.h   |6 +-
 src/gallium/auxiliary/gallivm/lp_bld_init.c|   11 +-
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp  |   23 ---
 src/gallium/auxiliary/gallivm/lp_bld_misc.h|3 -
 8 files changed, 361 insertions(+), 86 deletions(-)
 create mode 100755 bin/perf-annotate-jit

diff --git a/bin/perf-annotate-jit b/bin/perf-annotate-jit
new file mode 100755
index 000..7ebc965
--- /dev/null
+++ b/bin/perf-annotate-jit
@@ -0,0 +1,240 @@
+#!/usr/bin/env python
+#
+# Copyright 2012 VMware Inc
+# Copyright 2008-2009 Jose Fonseca
+#
+# 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, sublicense, 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 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 NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS 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 sys
+import os.path
+import re
+import optparse
+import subprocess
+
+
+class Parser:
+"""Parser interface."""
+
+def __init__(self):
+pass
+
+def parse(self):
+raise NotImplementedError
+
+
+class LineParser(Parser):
+"""Base class for parsers that read line-based formats."""
+
+def __init__(self, file):
+Parser.__init__(self)
+self._file = file
+self.__line = None
+self.__eof = False
+self.line_no = 0
+
+def readline(self):
+line = self._file.readline()
+if not line:
+self.__line = ''
+self.__eof = True
+else:
+self.line_no += 1
+self.__line = line.rstrip('\r\n')
+
+def lookahead(self):
+assert self.__line is not None
+return self.__line
+
+def consume(self):
+assert self.__line is not None
+line = self.__line
+self.readline()
+return line
+
+def eof(self):
+assert self.__line is not None
+return self.__eof
+
+
+mapFile = None
+
+def lookupMap(filename, matchSymbol):
+global mapFile
+mapFile = filename
+stream = open(filename, 'rt')
+for line in stream:
+start, length, symbol = line.split()
+
+start = int(start, 16)
+length = int(length,16)
+
+if symbol == matchSymbol:
+return start
+
+return None
+
+def lookupAsm(filename, desiredFunction):
+stream = open(filename + '.asm', 'rt')
+while stream.readline() != desiredFunction + ':\n':
+pass
+
+asm = []
+line = stream.readline().strip()
+while line:
+addr, instr = line.split(':', 1)
+addr = int(addr)
+asm.append((addr, instr))
+line = stream.readline().strip()
+
+return asm
+
+
+
+samples = {}
+
+
+class PerfParser(LineParser):
+"""Parser for linux perf callgraph output.
+
+It expects output generated with
+
+perf record -g
+perf script
+"""
+
+def __init__(self, infile, symbol):
+LineParser.__init__(self, infile)
+   self.symbol = symbol
+
+def readline(self):
+# Override LineParser.readline to ignore comment lines
+while True:
+LineParser.readline(self)
+if self.eof() or not self.lookahead().startswith('#'):
+break
+
+def parse(self):
+# read lookahead
+self.readline()
+
+while not self.eof():
+self.parse_event()
+
+asm = lookupAsm(mapFile, self.symbol)
+
+addresses = samples.keys()
+addresses.sort()
+total_samples = 0
+
+   sys.stdout.write('%s:\n' % self.symbol)
+for address, instr in asm:
+try:
+sample = samples.pop(address)
+except KeyError:
+sys.stdout.write(6*' ')
+else:
+sys.stdout.write('%6u' % (sample))
+total_samples += sample
+sys.stdout.write('%6u: %s

[Mesa-dev] [PATCH 1/3] gallivm: Drop pos arg from lp_build_tgsi_soa.

2013-04-18 Thread jfonseca
From: José Fonseca 

Never used.
---
 src/gallium/auxiliary/draw/draw_llvm.c  |2 --
 src/gallium/auxiliary/gallivm/lp_bld_tgsi.h |2 --
 src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c |2 --
 src/gallium/drivers/llvmpipe/lp_state_fs.c  |4 ++--
 4 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_llvm.c 
b/src/gallium/auxiliary/draw/draw_llvm.c
index 8e3ea88..e0c0705 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -593,7 +593,6 @@ generate_vs(struct draw_llvm_variant *variant,
  NULL /*struct lp_build_mask_context *mask*/,
  consts_ptr,
  system_values,
- NULL /*pos*/,
  inputs,
  outputs,
  sampler,
@@ -2023,7 +2022,6 @@ draw_gs_llvm_generate(struct draw_llvm *llvm,
  &mask,
  consts_ptr,
  &system_values,
- NULL /*pos*/,
  NULL,
  outputs,
  sampler,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h 
b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
index 78a1f0e..175b6a9 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
@@ -222,7 +222,6 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm,
   struct lp_build_mask_context *mask,
   LLVMValueRef consts_ptr,
   const struct lp_bld_tgsi_system_values *system_values,
-  const LLVMValueRef *pos,
   const LLVMValueRef (*inputs)[4],
   LLVMValueRef (*outputs)[4],
   struct lp_build_sampler_soa *sampler,
@@ -400,7 +399,6 @@ struct lp_build_tgsi_soa_context
LLVMValueRef max_output_vertices_vec;
 
LLVMValueRef consts_ptr;
-   const LLVMValueRef *pos;
const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS];
LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS];
 
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c 
b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
index ea7dec7..af1b8aa 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
@@ -2742,7 +2742,6 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm,
   struct lp_build_mask_context *mask,
   LLVMValueRef consts_ptr,
   const struct lp_bld_tgsi_system_values *system_values,
-  const LLVMValueRef *pos,
   const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS],
   LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS],
   struct lp_build_sampler_soa *sampler,
@@ -2766,7 +2765,6 @@ lp_build_tgsi_soa(struct gallivm_state *gallivm,
lp_build_context_init(&bld.bld_base.int_bld, gallivm, lp_int_type(type));
lp_build_context_init(&bld.elem_bld, gallivm, lp_elem_type(type));
bld.mask = mask;
-   bld.pos = pos;
bld.inputs = inputs;
bld.outputs = outputs;
bld.consts_ptr = consts_ptr;
diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c 
b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index ea41bd6..cdf246f 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -353,7 +353,7 @@ generate_fs(struct gallivm_state *gallivm,
/* Build the actual shader */
lp_build_tgsi_soa(gallivm, tokens, type, &mask,
  consts_ptr, &system_values,
- interp->pos, interp->inputs,
+ interp->inputs,
  outputs, sampler, &shader->info.base, NULL);
 
/* Alpha test */
@@ -606,7 +606,7 @@ generate_fs_loop(struct gallivm_state *gallivm,
/* Build the actual shader */
lp_build_tgsi_soa(gallivm, tokens, type, &mask,
  consts_ptr, &system_values,
- interp->pos, interp->inputs,
+ interp->inputs,
  outputs, sampler, &shader->info.base, NULL);
 
/* Alpha test */
-- 
1.7.9.5

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


[Mesa-dev] [PATCH 2/3] llvmpipe: Remove the static interpolation.

2013-04-18 Thread jfonseca
From: José Fonseca 

No longer used.

If we ever want the old behavior we can run a loop unroller pass.
---
 src/gallium/drivers/llvmpipe/lp_bld_interp.c |   92 ++--
 src/gallium/drivers/llvmpipe/lp_bld_interp.h |   14 --
 src/gallium/drivers/llvmpipe/lp_state_fs.c   |  297 +-
 3 files changed, 19 insertions(+), 384 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.c 
b/src/gallium/drivers/llvmpipe/lp_bld_interp.c
index 4947f30..083c6da 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_interp.c
+++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.c
@@ -237,7 +237,6 @@ coeffs_init_simple(struct lp_build_interp_soa_context *bld,
 static void
 attribs_update_simple(struct lp_build_interp_soa_context *bld,
   struct gallivm_state *gallivm,
-  int quad_start_index,
   LLVMValueRef loop_iter,
   int start,
   int end)
@@ -249,20 +248,15 @@ attribs_update_simple(struct lp_build_interp_soa_context 
*bld,
unsigned attrib;
LLVMValueRef pixoffx;
LLVMValueRef pixoffy;
+   LLVMValueRef ptr;
 
/* could do this with code-generated passed in pixel offsets too */
-   if (bld->dynamic_offsets) {
-  LLVMValueRef ptr;
 
-  assert(loop_iter);
-  ptr = LLVMBuildGEP(builder, bld->xoffset_store, &loop_iter, 1, "");
-  pixoffx = LLVMBuildLoad(builder, ptr, "");
-  ptr = LLVMBuildGEP(builder, bld->yoffset_store, &loop_iter, 1, "");
-  pixoffy = LLVMBuildLoad(builder, ptr, "");
-   }
-   else {
-  calc_offsets(coeff_bld, quad_start_index, &pixoffx, &pixoffy);
-   }
+   assert(loop_iter);
+   ptr = LLVMBuildGEP(builder, bld->xoffset_store, &loop_iter, 1, "");
+   pixoffx = LLVMBuildLoad(builder, ptr, "");
+   ptr = LLVMBuildGEP(builder, bld->yoffset_store, &loop_iter, 1, "");
+   pixoffy = LLVMBuildLoad(builder, ptr, "");
 
pixoffx = LLVMBuildFAdd(builder, pixoffx,
lp_build_broadcast_scalar(coeff_bld, bld->x), "");
@@ -527,14 +521,9 @@ coeffs_init(struct lp_build_interp_soa_context *bld,
 attrib_name(a, attrib, chan, ".a");
 attrib_name(dadq, attrib, chan, ".dadq");
 
-if (bld->dynamic_offsets) {
-   bld->a[attrib][chan] = lp_build_alloca(gallivm,
-  LLVMTypeOf(a), "");
-   LLVMBuildStore(builder, a, bld->a[attrib][chan]);
-}
-else {
-   bld->a[attrib][chan] = a;
-}
+bld->a[attrib][chan] = lp_build_alloca(gallivm,
+   LLVMTypeOf(a), "");
+LLVMBuildStore(builder, a, bld->a[attrib][chan]);
 bld->dadq[attrib][chan] = dadq;
  }
   }
@@ -549,20 +538,16 @@ coeffs_init(struct lp_build_interp_soa_context *bld,
 static void
 attribs_update(struct lp_build_interp_soa_context *bld,
struct gallivm_state *gallivm,
-   int quad_start_index,
LLVMValueRef loop_iter,
int start,
int end)
 {
LLVMBuilderRef builder = gallivm->builder;
struct lp_build_context *coeff_bld = &bld->coeff_bld;
-   LLVMValueRef shuffle = lp_build_const_int_vec(gallivm, coeff_bld->type, 
quad_start_index);
LLVMValueRef oow = NULL;
unsigned attrib;
unsigned chan;
 
-   assert(quad_start_index < 4);
-
for(attrib = start; attrib < end; ++attrib) {
   const unsigned mask = bld->mask[attrib];
   const unsigned interp = bld->interp[attrib];
@@ -571,10 +556,7 @@ attribs_update(struct lp_build_interp_soa_context *bld,
 LLVMValueRef a;
 if (interp == LP_INTERP_CONSTANT ||
 interp == LP_INTERP_FACING) {
-   a = bld->a[attrib][chan];
-   if (bld->dynamic_offsets) {
-  a = LLVMBuildLoad(builder, a, "");
-   }
+   a = LLVMBuildLoad(builder, bld->a[attrib][chan], "");
 }
 else if (interp == LP_INTERP_POSITION) {
assert(attrib > 0);
@@ -589,7 +571,7 @@ attribs_update(struct lp_build_interp_soa_context *bld,
 * Broadcast the attribute value for this quad into all elements
 */
 
-   if (bld->dynamic_offsets) {
+   {
   /* stored as vector load as float */
   LLVMTypeRef ptr_type = 
LLVMPointerType(LLVMFloatTypeInContext(
 gallivm->context), 
0);
@@ -599,10 +581,6 @@ attribs_update(struct lp_build_interp_soa_context *bld,
   a = LLVMBuildLoad(builder, ptr, "");
   a = lp_build_broadcast_scalar(&bld->coeff_bld, a);
}
-   else {
-  a = LLVMBuildShuffleVector(builder,
- a, coeff_bld->undef, shuffle, "");
-   }

[Mesa-dev] [PATCH 3/3] llvmpipe: Support half integer pixel center fs coord.

2013-04-18 Thread jfonseca
From: José Fonseca 

Tested with graw/fs-fragcoord 2/3, and piglit
glsl-arb-fragment-coord-conventions.
---
 src/gallium/drivers/llvmpipe/lp_bld_interp.c |   25 +++--
 src/gallium/drivers/llvmpipe/lp_bld_interp.h |3 +++
 src/gallium/drivers/llvmpipe/lp_screen.c |2 +-
 src/gallium/drivers/llvmpipe/lp_state_fs.c   |1 +
 4 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.c 
b/src/gallium/drivers/llvmpipe/lp_bld_interp.c
index 083c6da..490a691 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_interp.c
+++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.c
@@ -283,9 +283,15 @@ attribs_update_simple(struct lp_build_interp_soa_context 
*bld,
 case LP_INTERP_LINEAR:
if (attrib == 0 && chan == 0) {
   dadx = coeff_bld->one;
+  if (bld->pos_offset) {
+ a = lp_build_const_vec(gallivm, coeff_bld->type, 
bld->pos_offset);
+  }
}
else if (attrib == 0 && chan == 1) {
   dady = coeff_bld->one;
+  if (bld->pos_offset) {
+ a = lp_build_const_vec(gallivm, coeff_bld->type, 
bld->pos_offset);
+  }
}
else {
   dadx = lp_build_extract_broadcast(gallivm, setup_bld->type,
@@ -454,12 +460,20 @@ coeffs_init(struct lp_build_interp_soa_context *bld,
 LLVMValueRef chan_index = lp_build_const_int32(gallivm, chan);
 
 if (attrib == 0 && chan == 0) {
-   a = lp_build_broadcast_scalar(coeff_bld, bld->x);
+   a = bld->x;
+   if (bld->pos_offset) {
+  a = LLVMBuildFAdd(builder, a, lp_build_const_float(gallivm, 
bld->pos_offset), "");
+   }
+   a = lp_build_broadcast_scalar(coeff_bld, a);
dadx = coeff_bld->one;
dady = coeff_bld->zero;
 }
 else if (attrib == 0 && chan == 1) {
-   a = lp_build_broadcast_scalar(coeff_bld, bld->y);
+   a = bld->y;
+   if (bld->pos_offset) {
+  a = LLVMBuildFAdd(builder, a, lp_build_const_float(gallivm, 
bld->pos_offset), "");
+   }
+   a = lp_build_broadcast_scalar(coeff_bld, a);
dady = coeff_bld->one;
dadx = coeff_bld->zero;
 }
@@ -667,6 +681,7 @@ lp_build_interp_soa_init(struct lp_build_interp_soa_context 
*bld,
  struct gallivm_state *gallivm,
  unsigned num_inputs,
  const struct lp_shader_input *inputs,
+ boolean pixel_center_integer,
  LLVMBuilderRef builder,
  struct lp_type type,
  LLVMValueRef a0_ptr,
@@ -723,6 +738,12 @@ lp_build_interp_soa_init(struct 
lp_build_interp_soa_context *bld,
   }
}
 
+   if (pixel_center_integer) {
+  bld->pos_offset = 0.0;
+   } else {
+  bld->pos_offset = 0.5;
+   }
+
pos_init(bld, x0, y0);
 
if (coeff_type.length > 4) {
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.h 
b/src/gallium/drivers/llvmpipe/lp_bld_interp.h
index 23c9a59..9029d2a 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_interp.h
+++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.h
@@ -86,6 +86,8 @@ struct lp_build_interp_soa_context
enum lp_interp interp[1 + PIPE_MAX_SHADER_INPUTS];
boolean simple_interp;
 
+   double pos_offset;
+
LLVMValueRef x;
LLVMValueRef y;
 
@@ -113,6 +115,7 @@ lp_build_interp_soa_init(struct lp_build_interp_soa_context 
*bld,
  struct gallivm_state *gallivm,
  unsigned num_inputs,
  const struct lp_shader_input *inputs,
+ boolean pixel_center_integer,
  LLVMBuilderRef builder,
  struct lp_type type,
  LLVMValueRef a0_ptr,
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index ebcf680..7152c3e 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -154,9 +154,9 @@ llvmpipe_get_param(struct pipe_screen *screen, enum 
pipe_cap param)
   return 1;
case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
+   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
   return 1;
case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
-   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
   return 0;
case PIPE_CAP_PRIMITIVE_RESTART:
   return 1;
diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c 
b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index 3ec9e0c..8712885 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/

[Mesa-dev] [PATCH] llvmpipe: Take in consideration all current constant buffers when mapping.

2013-04-18 Thread jfonseca
From: José Fonseca 

---
 src/gallium/drivers/llvmpipe/lp_texture.c |   12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c 
b/src/gallium/drivers/llvmpipe/lp_texture.c
index 99bd6d3..0804619 100644
--- a/src/gallium/drivers/llvmpipe/lp_texture.c
+++ b/src/gallium/drivers/llvmpipe/lp_texture.c
@@ -669,9 +669,15 @@ llvmpipe_transfer_map( struct pipe_context *pipe,
 
/* Check if we're mapping the current constant buffer */
if ((usage & PIPE_TRANSFER_WRITE) &&
-   resource == llvmpipe->constants[PIPE_SHADER_FRAGMENT][0].buffer) {
-  /* constants may have changed */
-  llvmpipe->dirty |= LP_NEW_CONSTANTS;
+   (resource->bind & PIPE_BIND_CONSTANT_BUFFER)) {
+  unsigned i;
+  for (i = 0; i < Elements(llvmpipe->constants[PIPE_SHADER_FRAGMENT]); 
++i) {
+ if (resource == llvmpipe->constants[PIPE_SHADER_FRAGMENT][i].buffer) {
+/* constants may have changed */
+llvmpipe->dirty |= LP_NEW_CONSTANTS;
+break;
+ }
+  }
}
 
lpt = CALLOC_STRUCT(llvmpipe_transfer);
-- 
1.7.9.5

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


[Mesa-dev] [PATCH 2/2] trace: Dump PIPE_QUERY_* enums.

2013-11-27 Thread jfonseca
From: José Fonseca 

---
 src/gallium/auxiliary/util/u_dump.h |  3 ++
 src/gallium/auxiliary/util/u_dump_defines.c | 33 
 src/gallium/drivers/trace/tr_context.c  |  3 +-
 src/gallium/drivers/trace/tr_dump_defines.h | 58 +
 src/gallium/drivers/trace/tr_dump_state.c   | 10 +
 src/gallium/drivers/trace/tr_dump_state.h   |  3 --
 src/gallium/drivers/trace/tr_screen.c   |  3 +-
 7 files changed, 98 insertions(+), 15 deletions(-)
 create mode 100644 src/gallium/drivers/trace/tr_dump_defines.h

diff --git a/src/gallium/auxiliary/util/u_dump.h 
b/src/gallium/auxiliary/util/u_dump.h
index 71750a6..58e7dfd 100644
--- a/src/gallium/auxiliary/util/u_dump.h
+++ b/src/gallium/auxiliary/util/u_dump.h
@@ -85,6 +85,9 @@ util_dump_tex_mipfilter(unsigned value, boolean shortened);
 const char *
 util_dump_tex_filter(unsigned value, boolean shortened);
 
+const char *
+util_dump_query_type(unsigned value, boolean shortened);
+
 
 /*
  * p_state.h, through a FILE
diff --git a/src/gallium/auxiliary/util/u_dump_defines.c 
b/src/gallium/auxiliary/util/u_dump_defines.c
index cc62687..03fd15d 100644
--- a/src/gallium/auxiliary/util/u_dump_defines.c
+++ b/src/gallium/auxiliary/util/u_dump_defines.c
@@ -359,3 +359,36 @@ util_dump_tex_filter_short_names[] = {
 };
 
 DEFINE_UTIL_DUMP_CONTINUOUS(tex_filter)
+
+
+static const char *
+util_dump_query_type_names[] = {
+   "PIPE_QUERY_OCCLUSION_COUNTER",
+   "PIPE_QUERY_OCCLUSION_PREDICATE",
+   "PIPE_QUERY_TIMESTAMP",
+   "PIPE_QUERY_TIMESTAMP_DISJOINT",
+   "PIPE_QUERY_TIME_ELAPSED",
+   "PIPE_QUERY_PRIMITIVES_GENERATED",
+   "PIPE_QUERY_PRIMITIVES_EMITTED",
+   "PIPE_QUERY_SO_STATISTICS",
+   "PIPE_QUERY_SO_OVERFLOW_PREDICATE",
+   "PIPE_QUERY_GPU_FINISHED",
+   "PIPE_QUERY_PIPELINE_STATISTICS",
+};
+
+static const char *
+util_dump_query_type_short_names[] = {
+   "occlusion_counter",
+   "occlusion_predicate",
+   "timestamp",
+   "timestamp_disjoint",
+   "time_elapsed",
+   "primitives_generated",
+   "primitives_emitted",
+   "so_statistics",
+   "so_overflow_predicate",
+   "gpu_finished",
+   "pipeline_statistics",
+};
+
+DEFINE_UTIL_DUMP_CONTINUOUS(query_type)
diff --git a/src/gallium/drivers/trace/tr_context.c 
b/src/gallium/drivers/trace/tr_context.c
index d9afb0a..4ac7d9b 100644
--- a/src/gallium/drivers/trace/tr_context.c
+++ b/src/gallium/drivers/trace/tr_context.c
@@ -33,6 +33,7 @@
 #include "pipe/p_screen.h"
 
 #include "tr_dump.h"
+#include "tr_dump_defines.h"
 #include "tr_dump_state.h"
 #include "tr_public.h"
 #include "tr_screen.h"
@@ -135,7 +136,7 @@ trace_context_create_query(struct pipe_context *_pipe,
trace_dump_call_begin("pipe_context", "create_query");
 
trace_dump_arg(ptr, pipe);
-   trace_dump_arg(uint, query_type);
+   trace_dump_arg(query_type, query_type);
 
query = pipe->create_query(pipe, query_type);
 
diff --git a/src/gallium/drivers/trace/tr_dump_defines.h 
b/src/gallium/drivers/trace/tr_dump_defines.h
new file mode 100644
index 000..0c83c2b
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_dump_defines.h
@@ -0,0 +1,58 @@
+/**
+ *
+ * Copyright 2013 VMware, Inc.
+ * 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.
+ *
+ **/
+
+#ifndef TR_DUMP_DEFINES_H_
+#define TR_DUMP_DEFINES_H_
+
+#include "pipe/p_compiler.h"
+#include "util/u_format.h"
+#include "util/u_dump.h"
+#include "tr_dump.h"
+
+
+static INLINE void
+trace_dump_format(enum pipe_format format)
+{
+   if (!trace_dumping_enabled_locked())
+  return;
+
+   trace_dump_enum(util_format_name(format));
+}
+
+
+static INLINE void
+trace_dump_query_type(unsigned value)
+{
+   if (!trace_dumping_enabled_locked())
+  return;
+
+   trace_dump_enum(util_dump_query_type(value, FALSE));
+}
+
+
+
+#end

[Mesa-dev] [PATCH 1/2] trace: Dump query results faithfully.

2013-11-27 Thread jfonseca
From: José Fonseca 

---
 src/gallium/drivers/trace/tr_context.c| 82 +--
 src/gallium/drivers/trace/tr_dump_state.c | 64 
 src/gallium/drivers/trace/tr_dump_state.h |  2 +
 3 files changed, 133 insertions(+), 15 deletions(-)

diff --git a/src/gallium/drivers/trace/tr_context.c 
b/src/gallium/drivers/trace/tr_context.c
index 6a98657..d9afb0a 100644
--- a/src/gallium/drivers/trace/tr_context.c
+++ b/src/gallium/drivers/trace/tr_context.c
@@ -40,7 +40,29 @@
 #include "tr_context.h"
 
 
+struct trace_query
+{
+   unsigned type;
+
+   struct pipe_query *query;
+};
+
+
+static INLINE struct trace_query *
+trace_query(struct pipe_query *query) {
+   return (struct trace_query *)query;
+}
+
 
+static INLINE struct pipe_query *
+trace_query_unwrap(struct pipe_query *query)
+{
+   if (query) {
+  return trace_query(query)->query;
+   } else {
+  return NULL;
+   }
+}
 
 
 static INLINE struct pipe_resource *
@@ -108,29 +130,46 @@ trace_context_create_query(struct pipe_context *_pipe,
 {
struct trace_context *tr_ctx = trace_context(_pipe);
struct pipe_context *pipe = tr_ctx->pipe;
-   struct pipe_query *result;
+   struct pipe_query *query;
 
trace_dump_call_begin("pipe_context", "create_query");
 
trace_dump_arg(ptr, pipe);
trace_dump_arg(uint, query_type);
 
-   result = pipe->create_query(pipe, query_type);
+   query = pipe->create_query(pipe, query_type);
 
-   trace_dump_ret(ptr, result);
+   trace_dump_ret(ptr, query);
 
trace_dump_call_end();
 
-   return result;
+   /* Wrap query object. */
+   if (query) {
+  struct trace_query *tr_query = CALLOC_STRUCT(trace_query);
+  if (tr_query) {
+ tr_query->type = query_type;
+ tr_query->query = query;
+ query = (struct pipe_query *)tr_query;
+  } else {
+ pipe->destroy_query(pipe, query);
+ query = NULL;
+  }
+   }
+
+   return query;
 }
 
 
 static INLINE void
 trace_context_destroy_query(struct pipe_context *_pipe,
-struct pipe_query *query)
+struct pipe_query *_query)
 {
struct trace_context *tr_ctx = trace_context(_pipe);
struct pipe_context *pipe = tr_ctx->pipe;
+   struct trace_query *tr_query = trace_query(_query);
+   struct pipe_query *query = tr_query->query;
+
+   FREE(tr_query);
 
trace_dump_call_begin("pipe_context", "destroy_query");
 
@@ -150,6 +189,8 @@ trace_context_begin_query(struct pipe_context *_pipe,
struct trace_context *tr_ctx = trace_context(_pipe);
struct pipe_context *pipe = tr_ctx->pipe;
 
+   query = trace_query_unwrap(query);
+
trace_dump_call_begin("pipe_context", "begin_query");
 
trace_dump_arg(ptr, pipe);
@@ -168,6 +209,8 @@ trace_context_end_query(struct pipe_context *_pipe,
struct trace_context *tr_ctx = trace_context(_pipe);
struct pipe_context *pipe = tr_ctx->pipe;
 
+   query = trace_query_unwrap(query);
+
trace_dump_call_begin("pipe_context", "end_query");
 
trace_dump_arg(ptr, pipe);
@@ -181,29 +224,36 @@ trace_context_end_query(struct pipe_context *_pipe,
 
 static INLINE boolean
 trace_context_get_query_result(struct pipe_context *_pipe,
-   struct pipe_query *query,
+   struct pipe_query *_query,
boolean wait,
-   union pipe_query_result *presult)
+   union pipe_query_result *result)
 {
struct trace_context *tr_ctx = trace_context(_pipe);
struct pipe_context *pipe = tr_ctx->pipe;
-   uint64_t result;
-   boolean _result;
+   struct trace_query *tr_query = trace_query(_query);
+   struct pipe_query *query = tr_query->query;
+   boolean ret;
 
trace_dump_call_begin("pipe_context", "get_query_result");
 
trace_dump_arg(ptr, pipe);
+   trace_dump_arg(ptr, query);
 
-   _result = pipe->get_query_result(pipe, query, wait, presult);
-   /* XXX this depends on the query type */
-   result = *((uint64_t*)presult);
+   ret = pipe->get_query_result(pipe, query, wait, result);
 
-   trace_dump_arg(uint, result);
-   trace_dump_ret(bool, _result);
+   trace_dump_arg_begin("result");
+   if (ret) {
+  trace_dump_query_result(tr_query->type, result);
+   } else {
+  trace_dump_null();
+   }
+   trace_dump_arg_end();
+
+   trace_dump_ret(bool, ret);
 
trace_dump_call_end();
 
-   return _result;
+   return ret;
 }
 
 
@@ -1408,6 +1458,8 @@ static void trace_context_render_condition(struct 
pipe_context *_context,
struct trace_context *tr_context = trace_context(_context);
struct pipe_context *context = tr_context->pipe;
 
+   query = trace_query_unwrap(query);
+
trace_dump_call_begin("pipe_context", "render_condition");
 
trace_dump_arg(ptr, context);
diff --git a/src/gallium/drivers/trace/tr_dump_state.c 
b/src/gallium/drivers/trace/tr_dump_state.c
index 374e32f..c1e5361 100644
--- a/src/gallium/drivers/trace/tr_du

[Mesa-dev] [PATCH 1/2] demos/pixeltest: Remove Line struct.

2014-01-08 Thread jfonseca
From: José Fonseca 

Not really used/necessary.
---
 src/demos/pixeltest.c | 113 +++---
 1 file changed, 52 insertions(+), 61 deletions(-)

diff --git a/src/demos/pixeltest.c b/src/demos/pixeltest.c
index e9b95b8..0898290 100644
--- a/src/demos/pixeltest.c
+++ b/src/demos/pixeltest.c
@@ -21,24 +21,16 @@ static int WinWidth, WinHeight;
 static int APosX, APosY; /* simple drawpixels */
 static int BPosX, BPosY; /* read/draw pixels */
 int MouseButton, MouseY, MouseX; /* mouse control */
-float x0offset = 0.0f;   /* for line translation */
-float y0offset = 0.0f; 
-float x1offset = 0.0f;
-float y1offset = 0.0f;
+float X0 = 0.0f;   /* for line translation */
+float Y0 = 0.0f; 
+float X1 = 0.0f;
+float Y1 = 0.0f;
 float width = 1.0f;
 
-struct Line{
-   float x0;
-   float y0;
-   float x1;
-   float y1;
-};
-
 #define STEP 16 /* subpixel resolution 1/STEP */
 #define SIZE 128/* of non-zoomed drawing region */
 #define ZOOM 32 /* scale factor for zooming */
 
-struct Line line;
 static GLboolean DrawFront = GL_FALSE;
 GLushort TempImage[SIZE][SIZE]; /* original 128 by 128 pixel image */
 GLushort myImage[SIZE*ZOOM][SIZE*ZOOM]; /* zoom by a factor of 32 */
@@ -177,32 +169,32 @@ drawMagnifiedView(void)
}
   
/* Draws the actual line on zoomed version */
-   drawline(line.x0+x0offset+APosX-MouseX, line.y0+y0offset+APosY-MouseY, 
-line.x1+x1offset+APosX-MouseX, line.y1+y1offset+APosY-MouseY, 0);
+   drawline(X0+APosX-MouseX, Y0+APosY-MouseY, 
+X1+APosX-MouseX, Y1+APosY-MouseY, 0);
   
/* Draws bounding line area */ 
-   if (fabsf(line.x0 + x0offset - line.x1 - x1offset) >= 
-   fabsf(line.y0 + y0offset - line.y1 - y1offset)) {
+   if (fabsf(X0 - X1) >= 
+   fabsf(Y0 - Y1)) {
   /* X-MAJOR line */
-  drawline(line.x0+x0offset+APosX-MouseX, 
line.y0+y0offset+APosY-MouseY+halfwidth, 
-   line.x1+x1offset+APosX-MouseX, 
line.y1+y1offset+APosY-MouseY+halfwidth, 0x);
-  drawline(line.x0+x0offset+APosX-MouseX, 
line.y0+y0offset+APosY-MouseY-halfwidth, 
-   line.x1+x1offset+APosX-MouseX, 
line.y1+y1offset+APosY-MouseY-halfwidth, 0x);
-  drawline(line.x0+x0offset+APosX-MouseX, 
line.y0+y0offset+APosY-MouseY+halfwidth, 
-   line.x0+x0offset+APosX-MouseX, 
line.y0+y0offset+APosY-MouseY-halfwidth, 0x);
-  drawline(line.x1+x1offset+APosX-MouseX, 
line.y1+y1offset+APosY-MouseY+halfwidth, 
-   line.x1+x1offset+APosX-MouseX, 
line.y1+y1offset+APosY-MouseY-halfwidth, 0x);
+  drawline(X0+APosX-MouseX, Y0+APosY-MouseY+halfwidth, 
+   X1+APosX-MouseX, Y1+APosY-MouseY+halfwidth, 0x);
+  drawline(X0+APosX-MouseX, Y0+APosY-MouseY-halfwidth, 
+   X1+APosX-MouseX, Y1+APosY-MouseY-halfwidth, 0x);
+  drawline(X0+APosX-MouseX, Y0+APosY-MouseY+halfwidth, 
+   X0+APosX-MouseX, Y0+APosY-MouseY-halfwidth, 0x);
+  drawline(X1+APosX-MouseX, Y1+APosY-MouseY+halfwidth, 
+   X1+APosX-MouseX, Y1+APosY-MouseY-halfwidth, 0x);
}
else {
   /* Y-MAJOR line */
-  drawline(line.x0+x0offset+APosX-MouseX+halfwidth, 
line.y0+y0offset+APosY-MouseY, 
-   line.x1+x1offset+APosX-MouseX+halfwidth, 
line.y1+y1offset+APosY-MouseY, 0x);
-  drawline(line.x0+x0offset+APosX-MouseX-halfwidth, 
line.y0+y0offset+APosY-MouseY, 
-   line.x1+x1offset+APosX-MouseX-halfwidth, 
line.y1+y1offset+APosY-MouseY, 0x);
-  drawline(line.x0+x0offset+APosX-MouseX+halfwidth, 
line.y0+y0offset+APosY-MouseY, 
-   line.x0+x0offset+APosX-MouseX-halfwidth, 
line.y0+y0offset+APosY-MouseY, 0x);
-  drawline(line.x1+x1offset+APosX-MouseX+halfwidth, 
line.y1+y1offset+APosY-MouseY, 
-   line.x1+x1offset+APosX-MouseX-halfwidth, 
line.y1+y1offset+APosY-MouseY, 0x);
+  drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY, 
+   X1+APosX-MouseX+halfwidth, Y1+APosY-MouseY, 0x);
+  drawline(X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY, 
+   X1+APosX-MouseX-halfwidth, Y1+APosY-MouseY, 0x);
+  drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY, 
+   X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY, 0x);
+  drawline(X1+APosX-MouseX+halfwidth, Y1+APosY-MouseY, 
+   X1+APosX-MouseX-halfwidth, Y1+APosY-MouseY, 0x);
}
 }
 
@@ -211,6 +203,11 @@ Display( void )
 {
float z = 0;
 
+   printf("(%f, %f) - (%f, %f), width = %f\n",
+X0, Y0,
+X1, Y1,
+width);
+
glClearColor(.3, .3, .3, 1);
glClear( GL_COLOR_BUFFER_BIT );

@@ -238,9 +235,9 @@ Display( void )
glLineWidth(width);
glBegin(GL_LINES);
glColor3f(.8,0,0);
-   glVertex3f(line.x0+x0offset, line.y0+y0offset, z);
+   glVertex3f(X0, Y0, z);
glColor3f(0,.9,0); 
-   glVertex3f(line.x1+x1offset, line.y1+y1offset, z);
+  

[Mesa-dev] [PATCH 2/2] demos/pixeltest: Adapt the example for points too.

2014-01-08 Thread jfonseca
From: José Fonseca 

This example is very useful to understand the rasterization of lines.
And with this change, points too.

Adding a key / command-line option to switch modes is left for a future
opportunity though.
---
 src/demos/pixeltest.c | 109 --
 1 file changed, 69 insertions(+), 40 deletions(-)

diff --git a/src/demos/pixeltest.c b/src/demos/pixeltest.c
index 0898290..0b6a580 100644
--- a/src/demos/pixeltest.c
+++ b/src/demos/pixeltest.c
@@ -31,6 +31,10 @@ float width = 1.0f;
 #define SIZE 128/* of non-zoomed drawing region */
 #define ZOOM 32 /* scale factor for zooming */
 
+// TODO: Allow to switch mode via key and/or command-line option.
+//GLenum mode = GL_POINT;
+GLenum mode = GL_LINE;
+
 static GLboolean DrawFront = GL_FALSE;
 GLushort TempImage[SIZE][SIZE]; /* original 128 by 128 pixel image */
 GLushort myImage[SIZE*ZOOM][SIZE*ZOOM]; /* zoom by a factor of 32 */
@@ -168,33 +172,48 @@ drawMagnifiedView(void)
   }
}
   
-   /* Draws the actual line on zoomed version */
-   drawline(X0+APosX-MouseX, Y0+APosY-MouseY, 
-X1+APosX-MouseX, Y1+APosY-MouseY, 0);
-  
-   /* Draws bounding line area */ 
-   if (fabsf(X0 - X1) >= 
-   fabsf(Y0 - Y1)) {
-  /* X-MAJOR line */
-  drawline(X0+APosX-MouseX, Y0+APosY-MouseY+halfwidth, 
-   X1+APosX-MouseX, Y1+APosY-MouseY+halfwidth, 0x);
-  drawline(X0+APosX-MouseX, Y0+APosY-MouseY-halfwidth, 
-   X1+APosX-MouseX, Y1+APosY-MouseY-halfwidth, 0x);
-  drawline(X0+APosX-MouseX, Y0+APosY-MouseY+halfwidth, 
-   X0+APosX-MouseX, Y0+APosY-MouseY-halfwidth, 0x);
-  drawline(X1+APosX-MouseX, Y1+APosY-MouseY+halfwidth, 
-   X1+APosX-MouseX, Y1+APosY-MouseY-halfwidth, 0x);
-   }
-   else {
-  /* Y-MAJOR line */
-  drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY, 
-   X1+APosX-MouseX+halfwidth, Y1+APosY-MouseY, 0x);
-  drawline(X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY, 
-   X1+APosX-MouseX-halfwidth, Y1+APosY-MouseY, 0x);
-  drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY, 
-   X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY, 0x);
-  drawline(X1+APosX-MouseX+halfwidth, Y1+APosY-MouseY, 
-   X1+APosX-MouseX-halfwidth, Y1+APosY-MouseY, 0x);
+   switch (mode) {
+   case GL_POINT:
+  /* Draws bounding point area */ 
+  drawline(X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY-halfwidth, 
+  X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY-halfwidth, 0x);
+  drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY-halfwidth, 
+  X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY+halfwidth, 0x);
+  drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY+halfwidth, 
+  X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY+halfwidth, 0x);
+  drawline(X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY+halfwidth, 
+  X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY-halfwidth, 0x);
+  break;
+   case GL_LINE:
+  /* Draws the actual line on zoomed version */
+  drawline(X0+APosX-MouseX, Y0+APosY-MouseY, 
+  X1+APosX-MouseX, Y1+APosY-MouseY, 0);
+
+  /* Draws bounding line area */ 
+  if (fabsf(X0 - X1) >= 
+ fabsf(Y0 - Y1)) {
+/* X-MAJOR line */
+drawline(X0+APosX-MouseX, Y0+APosY-MouseY+halfwidth, 
+ X1+APosX-MouseX, Y1+APosY-MouseY+halfwidth, 0x);
+drawline(X0+APosX-MouseX, Y0+APosY-MouseY-halfwidth, 
+ X1+APosX-MouseX, Y1+APosY-MouseY-halfwidth, 0x);
+drawline(X0+APosX-MouseX, Y0+APosY-MouseY+halfwidth, 
+ X0+APosX-MouseX, Y0+APosY-MouseY-halfwidth, 0x);
+drawline(X1+APosX-MouseX, Y1+APosY-MouseY+halfwidth, 
+ X1+APosX-MouseX, Y1+APosY-MouseY-halfwidth, 0x);
+  }
+  else {
+/* Y-MAJOR line */
+drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY, 
+ X1+APosX-MouseX+halfwidth, Y1+APosY-MouseY, 0x);
+drawline(X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY, 
+ X1+APosX-MouseX-halfwidth, Y1+APosY-MouseY, 0x);
+drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY, 
+ X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY, 0x);
+drawline(X1+APosX-MouseX+halfwidth, Y1+APosY-MouseY, 
+ X1+APosX-MouseX-halfwidth, Y1+APosY-MouseY, 0x);
+  }
+  break;
}
 }
 
@@ -203,11 +222,6 @@ Display( void )
 {
float z = 0;
 
-   printf("(%f, %f) - (%f, %f), width = %f\n",
-X0, Y0,
-X1, Y1,
-width);
-
glClearColor(.3, .3, .3, 1);
glClear( GL_COLOR_BUFFER_BIT );

@@ -230,16 +244,31 @@ Display( void )
glVertex3f(150, 0, z);
glEnd();
 
-   /* Original line
+   /* Original geometry
 */
-   glLineWidth(width);
-   glBegin(GL_LINES);
-   glColor3f(.8,0,0);
-   glVe

[Mesa-dev] [PATCH] llvmpipe: Honour pipe_rasterizer::point_quad_rasterization.

2014-01-08 Thread jfonseca
From: José Fonseca 

Commit eda21d2a3010d9fc5a68b55a843c5e44b2abf8dd fixed the rasterization
of points for Direct3D but ended up breaking the rasterization of OpenGL
non-sprite points, in particular conform's pntrast.c test.

The only way to get both working is to properly honour
pipe_rasterizer::point_quad_rasterization, and follow the weird OpenGL
rule when it is false.
---
 src/gallium/drivers/llvmpipe/lp_setup_point.c | 64 ++-
 1 file changed, 54 insertions(+), 10 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_setup_point.c 
b/src/gallium/drivers/llvmpipe/lp_setup_point.c
index 988e0c5..e5ce4ee 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup_point.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup_point.c
@@ -338,9 +338,13 @@ try_setup_point( struct lp_setup_context *setup,
int fixed_width = MAX2(FIXED_ONE,
   (subpixel_snap(size) + FIXED_ONE/2 - 1) & 
~(FIXED_ONE-1));
 
-   const int x0 = subpixel_snap(v0[0][0] - setup->pixel_offset) - 
fixed_width/2;
-   const int y0 = subpixel_snap(v0[0][1] - setup->pixel_offset) - 
fixed_width/2;
- 
+   /* Yes this is necessary to accurately calculate bounding boxes
+* with the two fill-conventions we support.  GL (normally) ends
+* up needing a bottom-left fill convention, which requires
+* slightly different rounding.
+*/
+   int adj = (setup->bottom_edge_rule != 0) ? 1 : 0;
+
struct lp_scene *scene = setup->scene;
struct lp_rast_triangle *point;
unsigned bytes;
@@ -363,13 +367,14 @@ try_setup_point( struct lp_setup_context *setup,
   print_point(setup, v0);
 
/* Bounding rectangle (in pixels) */
-   {
-  /* Yes this is necessary to accurately calculate bounding boxes
-   * with the two fill-conventions we support.  GL (normally) ends
-   * up needing a bottom-left fill convention, which requires
-   * slightly different rounding.
+   if (!lp_context->rasterizer ||
+   lp_context->rasterizer->point_quad_rasterization) {
+  /*
+   * Rasterize points as quads.
*/
-  int adj = (setup->bottom_edge_rule != 0) ? 1 : 0;
+
+  const int x0 = subpixel_snap(v0[0][0] - setup->pixel_offset) - 
fixed_width/2;
+  const int y0 = subpixel_snap(v0[0][1] - setup->pixel_offset) - 
fixed_width/2;
 
   bbox.x0 = (x0 + (FIXED_ONE-1)) >> FIXED_ORDER;
   bbox.x1 = (x0 + fixed_width + (FIXED_ONE-1)) >> FIXED_ORDER;
@@ -380,8 +385,47 @@ try_setup_point( struct lp_setup_context *setup,
*/
   bbox.x1--;
   bbox.y1--;
+   } else {
+  /*
+   * OpenGL rasterization rules for non-sprite points.
+   *
+   * Per OpenGL 2.1 spec, section 3.3.1, "Basic Point Rasterization".
+   */
+
+  const int x0 = subpixel_snap(v0[0][0]);
+  const int y0 = subpixel_snap(v0[0][1]) - adj;
+
+  int int_width = fixed_width >> FIXED_ORDER;
+
+  assert(setup->pixel_offset != 0);
+
+  if (int_width == 1) {
+ bbox.x0 = x0 >> FIXED_ORDER;
+ bbox.y0 = y0 >> FIXED_ORDER;
+ bbox.x1 = bbox.x0;
+ bbox.y1 = bbox.y0;
+  } else {
+ if (int_width & 1) {
+/* Odd width */
+bbox.x0 = (x0 >> FIXED_ORDER) - (int_width - 1)/2;
+bbox.y0 = (y0 >> FIXED_ORDER) - (int_width - 1)/2;
+ } else {
+/* Even width */
+bbox.x0 = ((x0 + FIXED_ONE/2) >> FIXED_ORDER) - int_width/2;
+bbox.y0 = ((y0 + FIXED_ONE/2) >> FIXED_ORDER) - int_width/2;
+ }
+
+ bbox.x1 = bbox.x0 + int_width - 1;
+ bbox.y1 = bbox.y0 + int_width - 1;
+  }
}
-   
+
+   if (0) {
+  debug_printf("  bbox: (%i, %i) - (%i, %i)\n",
+   bbox.x0, bbox.y0,
+   bbox.x1, bbox.y1);
+   }
+
if (!u_rect_test_intersection(&setup->draw_regions[viewport_index], &bbox)) 
{
   if (0) debug_printf("offscreen\n");
   LP_COUNT(nr_culled_tris);
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 7/7] c11: Make TIME_UTC a conditional macro.

2014-01-09 Thread jfonseca
From: José Fonseca 

Some system headers already define it, so this prevents conflict.
---
 include/c11/threads.h | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/c11/threads.h b/include/c11/threads.h
index 678774c..4a4079d 100644
--- a/include/c11/threads.h
+++ b/include/c11/threads.h
@@ -10,6 +10,10 @@
 
 #include 
 
+#ifndef TIME_UTC
+#define TIME_UTC 1
+#endif
+
 #include "c99_compat.h" /* for `inline` */
 
 /* types */
@@ -39,8 +43,6 @@ enum {
 thrd_nomem// out of memory
 };
 
-enum { TIME_UTC = 1 };
-
 /*-- functions --*/
 
 #if defined(_WIN32) && !defined(__CYGWIN__)
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 2/7] c11: Import threads.h emulation library.

2014-01-09 Thread jfonseca
From: José Fonseca 

Implementation is based of https://gist.github.com/2223710 with the
following modifications:
- inline implementatation
- retain XP compatability
- add temporary hack for static mutex initializers (as they are not part
  of the stack but still widely used internally).
---
 include/c11/threads.h   |  56 +
 include/c11/threads_posix.h | 346 ++
 include/c11/threads_win32.h | 588 
 3 files changed, 990 insertions(+)
 create mode 100644 include/c11/threads.h
 create mode 100644 include/c11/threads_posix.h
 create mode 100644 include/c11/threads_win32.h

diff --git a/include/c11/threads.h b/include/c11/threads.h
new file mode 100644
index 000..678774c
--- /dev/null
+++ b/include/c11/threads.h
@@ -0,0 +1,56 @@
+/*
+ * C11  emulation library
+ *
+ * (C) Copyright yohhoy 2012.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+#ifndef EMULATED_THREADS_H_INCLUDED_
+#define EMULATED_THREADS_H_INCLUDED_
+
+#include 
+
+#include "c99_compat.h" /* for `inline` */
+
+/* types */
+typedef void (*tss_dtor_t)(void*);
+typedef int (*thrd_start_t)(void*);
+
+struct xtime {
+time_t sec;
+long nsec;
+};
+typedef struct xtime xtime;
+
+
+/* enumeration constants */
+enum {
+mtx_plain = 0,
+mtx_try   = 1,
+mtx_timed = 2,
+mtx_recursive = 4
+};
+
+enum {
+thrd_success = 0, // succeeded
+thrd_timeout, // timeout
+thrd_error,   // failed
+thrd_busy,// resource busy
+thrd_nomem// out of memory
+};
+
+enum { TIME_UTC = 1 };
+
+/*-- functions --*/
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include "threads_win32.h"
+#elif defined(__unix__) || defined(__unix)
+#include "threads_posix.h"
+#else
+#error Not supported on this platform.
+#endif
+
+
+
+#endif /* EMULATED_THREADS_H_INCLUDED_ */
diff --git a/include/c11/threads_posix.h b/include/c11/threads_posix.h
new file mode 100644
index 000..463c93f
--- /dev/null
+++ b/include/c11/threads_posix.h
@@ -0,0 +1,346 @@
+/*
+ * C11  emulation library
+ *
+ * (C) Copyright yohhoy 2012.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include  /* for intptr_t */
+
+/*
+Configuration macro:
+
+  EMULATED_THREADS_USE_NATIVE_TIMEDLOCK
+Use pthread_mutex_timedlock() for `mtx_timedlock()'
+Otherwise use mtx_trylock() + *busy loop* emulation.
+*/
+#if !defined(__CYGWIN__)
+#define EMULATED_THREADS_USE_NATIVE_TIMEDLOCK
+#endif
+
+
+#include 
+
+/* macros */
+#define ONCE_FLAG_INIT PTHREAD_ONCE_INIT
+#ifdef INIT_ONCE_STATIC_INIT
+#define TSS_DTOR_ITERATIONS PTHREAD_DESTRUCTOR_ITERATIONS
+#else
+#define TSS_DTOR_ITERATIONS 1  // assume TSS dtor MAY be called at least once.
+#endif
+
+// FIXME: temporary non-standard hack to ease transition
+#define _MTX_INITIALIZER_NP PTHREAD_MUTEX_INITIALIZER
+
+/* types */
+typedef pthread_cond_t  cnd_t;
+typedef pthread_t   thrd_t;
+typedef pthread_key_t   tss_t;
+typedef pthread_mutex_t mtx_t;
+typedef pthread_once_t  once_flag;
+
+
+/*
+Implementation limits:
+  - Conditionally emulation for "mutex with timeout"
+(see EMULATED_THREADS_USE_NATIVE_TIMEDLOCK macro)
+*/
+struct impl_thrd_param {
+thrd_start_t func;
+void *arg;
+};
+
+static inline void *
+impl_thrd_routine(void *p)
+{
+struct impl_thrd_param pack = *((struct impl_thrd_param *)p);
+free(p);
+return (void*)(intptr_t)pack.func(pack.arg);
+}
+
+
+/*--- 7.25.2 Initialization functions ---*/
+// 7.25.2.1
+static inline void
+call_once(once_flag *flag, void (*func)(void))
+{
+pthread_once(flag, func);
+}
+
+
+/*- 7.25.3 Condition variable functions -*/
+// 7.25.3.1
+static inline int
+cnd_broadcast(cnd_t *cond)
+{
+if (!cond) return thrd_error;
+pthread_cond_broadcast(cond);
+return thrd_success;
+}
+
+// 7.25.3.2
+static inline void
+cnd_destroy(cnd_t *cond)
+{
+assert(cond);
+pthread_cond_destroy(cond);
+}
+
+// 7.25.3.3
+static inline int
+cnd_init(cnd_t *cond)
+{
+if (!cond) return thrd_error;
+pthread_cond_init(cond, NULL);
+return thrd_success;
+}
+
+// 7.25.3.4
+static inline int
+cnd_signal(cnd_t *cond)
+{
+if (!cond) return thrd_error;
+pthread_cond_signal(cond);
+return thrd_success;
+}
+
+// 7.25.3.5
+static inline int
+cnd_timedwait(cnd_t *cond, mtx_t *mtx, const xtime *xt)
+{
+struct timespec abs_time;
+int rt;
+if (!cond || !mtx || !xt) return thrd_error;
+rt = pthread_cond_timedwait(cond, mtx, &abs_time

[Mesa-dev] [PATCH 5/7] egl: Use C11 thread abstractions.

2014-01-09 Thread jfonseca
From: José Fonseca 

---
 src/egl/main/eglmutex.h | 26 +++---
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/src/egl/main/eglmutex.h b/src/egl/main/eglmutex.h
index 1349e9e..2ec965c 100644
--- a/src/egl/main/eglmutex.h
+++ b/src/egl/main/eglmutex.h
@@ -31,46 +31,34 @@
 
 #include "eglcompiler.h"
 
-#ifdef HAVE_PTHREAD
-#include 
+#include "c11/threads.h"
 
-typedef pthread_mutex_t _EGLMutex;
+typedef mtx_t _EGLMutex;
 
 static INLINE void _eglInitMutex(_EGLMutex *m)
 {
-   pthread_mutex_init(m, NULL);
+   mtx_init(m, mtx_plain);
 }
 
 static INLINE void
 _eglDestroyMutex(_EGLMutex *m)
 {
-   pthread_mutex_destroy(m);
+   mtx_destroy(m);
 }
 
 static INLINE void
 _eglLockMutex(_EGLMutex *m)
 {
-   pthread_mutex_lock(m);
+   mtx_lock(m);
 }
 
 static INLINE void
 _eglUnlockMutex(_EGLMutex *m)
 {
-   pthread_mutex_unlock(m);
+   mtx_unlock(m);
 }
 
-#define _EGL_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+#define _EGL_MUTEX_INITIALIZER _MTX_INITIALIZER_NP
 
-#else
-
-typedef int _EGLMutex;
-static INLINE void _eglInitMutex(_EGLMutex *m) { (void) m; }
-static INLINE void _eglDestroyMutex(_EGLMutex *m) { (void) m; }
-static INLINE void _eglLockMutex(_EGLMutex *m) { (void) m; }
-static INLINE void _eglUnlockMutex(_EGLMutex *m) { (void) m; }
-
-#define _EGL_MUTEX_INITIALIZER 0
-
-#endif
 
 #endif /* EGLMUTEX_INCLUDED */
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 4/7] mapi: Use C11 thread abstractions.

2014-01-09 Thread jfonseca
From: José Fonseca 

---
 src/mapi/u_thread.h | 165 +---
 1 file changed, 13 insertions(+), 152 deletions(-)

diff --git a/src/mapi/u_thread.h b/src/mapi/u_thread.h
index 31999c4..75fbec6 100644
--- a/src/mapi/u_thread.h
+++ b/src/mapi/u_thread.h
@@ -46,12 +46,7 @@
 #include 
 #include "u_compiler.h"
 
-#if defined(HAVE_PTHREAD)
-#include  /* POSIX threads headers */
-#endif
-#ifdef _WIN32
-#include 
-#endif
+#include "c11/threads.h"
 
 #if defined(HAVE_PTHREAD) || defined(_WIN32)
 #ifndef THREADS
@@ -79,43 +74,32 @@ extern "C" {
 #endif
 
 
-/*
- * POSIX threads. This should be your choice in the Unix world
- * whenever possible.  When building with POSIX threads, be sure
- * to enable any compiler flags which will cause the MT-safe
- * libc (if one exists) to be used when linking, as well as any
- * header macros for MT-safe errno, etc.  For Solaris, this is the -mt
- * compiler flag.  On Solaris with gcc, use -D_REENTRANT to enable
- * proper compiling for MT-safe libc etc.
- */
-#if defined(HAVE_PTHREAD)
-
 struct u_tsd {
-   pthread_key_t key;
+   tss_t key;
unsigned initMagic;
 };
 
-typedef pthread_mutex_t u_mutex;
+typedef mtx_t u_mutex;
 
 #define u_mutex_declare_static(name) \
-   static u_mutex name = PTHREAD_MUTEX_INITIALIZER
+   static u_mutex name = _MTX_INITIALIZER_NP
 
-#define u_mutex_init(name)pthread_mutex_init(&(name), NULL)
-#define u_mutex_destroy(name) pthread_mutex_destroy(&(name))
-#define u_mutex_lock(name)(void) pthread_mutex_lock(&(name))
-#define u_mutex_unlock(name)  (void) pthread_mutex_unlock(&(name))
+#define u_mutex_init(name)mtx_init(&(name), mtx_plain)
+#define u_mutex_destroy(name) mtx_destroy(&(name))
+#define u_mutex_lock(name)(void) mtx_lock(&(name))
+#define u_mutex_unlock(name)  (void) mtx_unlock(&(name))
 
 static INLINE unsigned long
 u_thread_self(void)
 {
-   return (unsigned long) pthread_self();
+   return (unsigned long) thrd_current();
 }
 
 
 static INLINE void
 u_tsd_init(struct u_tsd *tsd)
 {
-   if (pthread_key_create(&tsd->key, NULL/*free*/) != 0) {
+   if (tss_create(&tsd->key, NULL/*free*/) != 0) {
   perror(INIT_TSD_ERROR);
   exit(-1);
}
@@ -129,7 +113,7 @@ u_tsd_get(struct u_tsd *tsd)
if (tsd->initMagic != INIT_MAGIC) {
   u_tsd_init(tsd);
}
-   return pthread_getspecific(tsd->key);
+   return tss_get(tsd->key);
 }
 
 
@@ -139,56 +123,12 @@ u_tsd_set(struct u_tsd *tsd, void *ptr)
if (tsd->initMagic != INIT_MAGIC) {
   u_tsd_init(tsd);
}
-   if (pthread_setspecific(tsd->key, ptr) != 0) {
+   if (tss_set(tsd->key, ptr) != 0) {
   perror(SET_TSD_ERROR);
   exit(-1);
}
 }
 
-#endif /* HAVE_PTHREAD */
-
-
-/*
- * Windows threads. Should work with Windows NT and 95.
- * IMPORTANT: Link with multithreaded runtime library when THREADS are
- * used!
- */
-#ifdef _WIN32
-
-struct u_tsd {
-   DWORD key;
-   unsigned initMagic;
-};
-
-typedef CRITICAL_SECTION u_mutex;
-
-/* http://locklessinc.com/articles/pthreads_on_windows/ */
-#define u_mutex_declare_static(name) \
-   static u_mutex name = {(PCRITICAL_SECTION_DEBUG)-1, -1, 0, 0, 0, 0}
-
-#define u_mutex_init(name)InitializeCriticalSection(&name)
-#define u_mutex_destroy(name) DeleteCriticalSection(&name)
-#define u_mutex_lock(name)EnterCriticalSection(&name)
-#define u_mutex_unlock(name)  LeaveCriticalSection(&name)
-
-static INLINE unsigned long
-u_thread_self(void)
-{
-   return GetCurrentThreadId();
-}
-
-
-static INLINE void
-u_tsd_init(struct u_tsd *tsd)
-{
-   tsd->key = TlsAlloc();
-   if (tsd->key == TLS_OUT_OF_INDEXES) {
-  perror(INIT_TSD_ERROR);
-  exit(-1);
-   }
-   tsd->initMagic = INIT_MAGIC;
-}
-
 
 static INLINE void
 u_tsd_destroy(struct u_tsd *tsd)
@@ -196,90 +136,11 @@ u_tsd_destroy(struct u_tsd *tsd)
if (tsd->initMagic != INIT_MAGIC) {
   return;
}
-   TlsFree(tsd->key);
+   tss_delete(tsd->key);
tsd->initMagic = 0x0;
 }
 
 
-static INLINE void *
-u_tsd_get(struct u_tsd *tsd)
-{
-   if (tsd->initMagic != INIT_MAGIC) {
-  u_tsd_init(tsd);
-   }
-   return TlsGetValue(tsd->key);
-}
-
-
-static INLINE void
-u_tsd_set(struct u_tsd *tsd, void *ptr)
-{
-   /* the following code assumes that the struct u_tsd has been initialized
-  to zero at creation */
-   if (tsd->initMagic != INIT_MAGIC) {
-  u_tsd_init(tsd);
-   }
-   if (TlsSetValue(tsd->key, ptr) == 0) {
-  perror(SET_TSD_ERROR);
-  exit(-1);
-   }
-}
-
-#endif /* _WIN32 */
-
-
-/*
- * THREADS not defined
- */
-#ifndef THREADS
-
-struct u_tsd {
-   unsigned initMagic;
-};
-
-typedef unsigned u_mutex;
-
-#define u_mutex_declare_static(name)   static u_mutex name = 0
-#define u_mutex_init(name) (void) name
-#define u_mutex_destroy(name)  (void) name
-#define u_mutex_lock(name) (void) name
-#define u_mutex_unlock(name)   (void) name
-
-/*
- * no-op functions
- */
-
-static INLINE unsigned long
-u_thread_self(void)
-{
-   return 0;
-}

[Mesa-dev] [PATCH 1/7] os: Remove pipe_static_condvar.

2014-01-09 Thread jfonseca
From: José Fonseca 

Never used.
---
 src/gallium/auxiliary/os/os_thread.h | 12 
 1 file changed, 12 deletions(-)

diff --git a/src/gallium/auxiliary/os/os_thread.h 
b/src/gallium/auxiliary/os/os_thread.h
index 4528abb..d16f36d 100644
--- a/src/gallium/auxiliary/os/os_thread.h
+++ b/src/gallium/auxiliary/os/os_thread.h
@@ -105,9 +105,6 @@ typedef pthread_mutex_t pipe_mutex;
  */
 typedef pthread_cond_t pipe_condvar;
 
-#define pipe_static_condvar(mutex) \
-   static pipe_condvar mutex = PTHREAD_COND_INITIALIZER
-
 #define pipe_condvar_init(cond)\
pthread_cond_init(&(cond), NULL)
 
@@ -187,9 +184,6 @@ typedef CRITICAL_SECTION pipe_mutex;
  */
 typedef CONDITION_VARIABLE pipe_condvar;
 
-#define pipe_static_condvar(cond) \
-   /*static*/ pipe_condvar cond = CONDITION_VARIABLE_INIT
-
 #define pipe_condvar_init(cond) \
InitializeConditionVariable(&(cond))
 
@@ -213,9 +207,6 @@ typedef CONDITION_VARIABLE pipe_condvar;
  */
 typedef DWORD pipe_condvar;
 
-#define pipe_static_condvar(cond) \
-   /*static*/ pipe_condvar cond = 1
-
 #define pipe_condvar_init(cond) \
(void) (cond = 1)
 
@@ -284,9 +275,6 @@ typedef unsigned pipe_mutex;
 
 typedef int64_t pipe_condvar;
 
-#define pipe_static_condvar(condvar) \
-   static pipe_condvar condvar = 1000
-
 #define pipe_condvar_init(condvar) \
(void) (condvar = 1000)
 
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 6/7] rbug: Update for PIPE_THREAD_ROUTINE returning 0.

2014-01-09 Thread jfonseca
From: José Fonseca 

---
 src/gallium/drivers/rbug/rbug_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gallium/drivers/rbug/rbug_core.c 
b/src/gallium/drivers/rbug/rbug_core.c
index 7cc9f79..c5b26b8 100644
--- a/src/gallium/drivers/rbug/rbug_core.c
+++ b/src/gallium/drivers/rbug/rbug_core.c
@@ -810,7 +810,7 @@ PIPE_THREAD_ROUTINE(rbug_thread, void_tr_rbug)
 
if (s < 0) {
   debug_printf("rbug_rbug - failed to listen\n");
-  return NULL;
+  return 0;
}
 
u_socket_block(s, false);
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 3/7] gallium: Use C11 threads.h.

2014-01-09 Thread jfonseca
From: José Fonseca 

Note that PIPE_ROUTINE now returns an int.
---
 src/gallium/auxiliary/os/os_thread.h  | 262 +++---
 src/gallium/drivers/llvmpipe/lp_rast.c|   2 +-
 src/gallium/drivers/rbug/rbug_core.c  |   2 +-
 src/gallium/tests/unit/pipe_barrier_test.c|   2 +-
 src/gallium/winsys/radeon/drm/radeon_drm_winsys.c |   2 +-
 5 files changed, 36 insertions(+), 234 deletions(-)

diff --git a/src/gallium/auxiliary/os/os_thread.h 
b/src/gallium/auxiliary/os/os_thread.h
index d16f36d..aae40c2 100644
--- a/src/gallium/auxiliary/os/os_thread.h
+++ b/src/gallium/auxiliary/os/os_thread.h
@@ -40,271 +40,97 @@
 #include "pipe/p_compiler.h"
 #include "util/u_debug.h" /* for assert */
 
+#include "c11/threads.h"
 
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) 
|| defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_CYGWIN) 
|| defined(PIPE_OS_HURD)
-
-#include  /* POSIX threads headers */
-#include  /* for perror() */
+#ifdef HAVE_PTHREAD
 #include 
+#endif
 
 
 /* pipe_thread
  */
-typedef pthread_t pipe_thread;
+typedef thrd_t pipe_thread;
 
 #define PIPE_THREAD_ROUTINE( name, param ) \
-   void *name( void *param )
+   int name( void *param )
 
-static INLINE pipe_thread pipe_thread_create( void *(* routine)( void *), void 
*param )
+static INLINE pipe_thread pipe_thread_create( PIPE_THREAD_ROUTINE((*routine), 
), void *param )
 {
pipe_thread thread;
+#ifdef HAVE_PTHREAD
sigset_t saved_set, new_set;
int ret;
 
sigfillset(&new_set);
pthread_sigmask(SIG_SETMASK, &new_set, &saved_set);
-   ret = pthread_create( &thread, NULL, routine, param );
+   ret = thrd_create( &thread, routine, param );
pthread_sigmask(SIG_SETMASK, &saved_set, NULL);
+#else
+   int ret;
+   ret = thrd_create( &thread, routine, param );
+#endif
if (ret)
   return 0;
+
return thread;
 }
 
 static INLINE int pipe_thread_wait( pipe_thread thread )
 {
-   return pthread_join( thread, NULL );
+   return thrd_join( thread, NULL );
 }
 
 static INLINE int pipe_thread_destroy( pipe_thread thread )
 {
-   return pthread_detach( thread );
+   return thrd_detach( thread );
 }
 
 
 /* pipe_mutex
  */
-typedef pthread_mutex_t pipe_mutex;
+typedef mtx_t pipe_mutex;
 
 #define pipe_static_mutex(mutex) \
-   static pipe_mutex mutex = PTHREAD_MUTEX_INITIALIZER
+   static pipe_mutex mutex = _MTX_INITIALIZER_NP
 
 #define pipe_mutex_init(mutex) \
-   (void) pthread_mutex_init(&(mutex), NULL)
+   (void) mtx_init(&(mutex), mtx_plain)
 
 #define pipe_mutex_destroy(mutex) \
-   pthread_mutex_destroy(&(mutex))
+   mtx_destroy(&(mutex))
 
 #define pipe_mutex_lock(mutex) \
-   (void) pthread_mutex_lock(&(mutex))
+   (void) mtx_lock(&(mutex))
 
 #define pipe_mutex_unlock(mutex) \
-   (void) pthread_mutex_unlock(&(mutex))
+   (void) mtx_unlock(&(mutex))
 
 
 /* pipe_condvar
  */
-typedef pthread_cond_t pipe_condvar;
+typedef cnd_t pipe_condvar;
 
 #define pipe_condvar_init(cond)\
-   pthread_cond_init(&(cond), NULL)
-
-#define pipe_condvar_destroy(cond) \
-   pthread_cond_destroy(&(cond))
-
-#define pipe_condvar_wait(cond, mutex) \
-  pthread_cond_wait(&(cond), &(mutex))
-
-#define pipe_condvar_signal(cond) \
-  pthread_cond_signal(&(cond))
-
-#define pipe_condvar_broadcast(cond) \
-  pthread_cond_broadcast(&(cond))
-
-
-
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
-
-#include 
-
-/* pipe_thread
- */
-typedef HANDLE pipe_thread;
-
-#define PIPE_THREAD_ROUTINE( name, param ) \
-   void * WINAPI name( void *param )
-
-static INLINE pipe_thread pipe_thread_create( void *(WINAPI * routine)( void 
*), void *param )
-{
-   DWORD id;
-   return CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) routine, param, 0, 
&id );
-}
-
-static INLINE int pipe_thread_wait( pipe_thread thread )
-{
-   if (WaitForSingleObject( thread, INFINITE ) == WAIT_OBJECT_0)
-  return 0;
-   return -1;
-}
-
-static INLINE int pipe_thread_destroy( pipe_thread thread )
-{
-   if (CloseHandle( thread ))
-  return 0;
-   return -1;
-}
-
-
-/* pipe_mutex
- */
-typedef CRITICAL_SECTION pipe_mutex;
-
-/* http://locklessinc.com/articles/pthreads_on_windows/ */
-#define pipe_static_mutex(mutex) \
-   static pipe_mutex mutex = {(PCRITICAL_SECTION_DEBUG)-1, -1, 0, 0, 0, 0}
-
-#define pipe_mutex_init(mutex) \
-   InitializeCriticalSection(&mutex)
-
-#define pipe_mutex_destroy(mutex) \
-   DeleteCriticalSection(&mutex)
-
-#define pipe_mutex_lock(mutex) \
-   EnterCriticalSection(&mutex)
-
-#define pipe_mutex_unlock(mutex) \
-   LeaveCriticalSection(&mutex)
-
-/* TODO: Need a macro to declare "I don't care about WinXP compatibilty" */
-#if 0 && defined (_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
-/* CONDITION_VARIABLE is only available on newer versions of Windows
- * (Server 2008/Vista or later).
- * http://msdn.microsoft.com/en-us/library/ms682052(VS.85).aspx
- *
- * pipe_condvar
- */
-typedef CONDITION_VARIABLE pipe_condvar;
-
-#define pipe_condvar_init(cond) \

[Mesa-dev] [PATCH 1/2] trace: Re-license trace.xsl under MIT license.

2014-01-17 Thread jfonseca
From: José Fonseca 

I was the sole author, as Tungsten Graphics employee, which was since
then acquired by VMware Inc.
---
 src/gallium/drivers/trace/trace.xsl | 36 ++--
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/gallium/drivers/trace/trace.xsl 
b/src/gallium/drivers/trace/trace.xsl
index 7be95e0..12458ae 100644
--- a/src/gallium/drivers/trace/trace.xsl
+++ b/src/gallium/drivers/trace/trace.xsl
@@ -2,20 +2,28 @@
 
 
 
-- 
1.8.3.2

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


[Mesa-dev] [PATCH] mesa/st: Fix pipe_framebuffer_state::height for PIPE_TEXTURE_1D_ARRAY.

2014-04-03 Thread jfonseca
From: José Fonseca 

This prevents buffer overflow w/ llvmpipe when running piglit

  bin/gl-3.2-layered-rendering-clear-color-all-types 1d_array single_level -fbo 
-auto
---
 src/mesa/state_tracker/st_atom_framebuffer.c | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c 
b/src/mesa/state_tracker/st_atom_framebuffer.c
index 4c4f839..f8eb1f0 100644
--- a/src/mesa/state_tracker/st_atom_framebuffer.c
+++ b/src/mesa/state_tracker/st_atom_framebuffer.c
@@ -52,13 +52,13 @@ update_framebuffer_state( struct st_context *st )
struct pipe_framebuffer_state *framebuffer = &st->state.framebuffer;
struct gl_framebuffer *fb = st->ctx->DrawBuffer;
struct st_renderbuffer *strb;
+   unsigned width = 0;
+   unsigned height = 0;
GLuint i;
 
st_flush_bitmap_cache(st);
 
st->state.fb_orientation = st_fb_orientation(fb);
-   framebuffer->width = fb->Width;
-   framebuffer->height = fb->Height;
 
/*printf("-- fb size %d x %d\n", fb->Width, fb->Height);*/
 
@@ -81,6 +81,8 @@ update_framebuffer_state( struct st_context *st )
 
  if (strb->surface) {
 pipe_surface_reference(&framebuffer->cbufs[i], strb->surface);
+width  = MAX2(width,  strb->surface->width);
+height = MAX2(height, strb->surface->height);
  }
  strb->defined = GL_TRUE; /* we'll be drawing something */
   }
@@ -100,12 +102,18 @@ update_framebuffer_state( struct st_context *st )
  st_update_renderbuffer_surface(st, strb);
   }
   pipe_surface_reference(&framebuffer->zsbuf, strb->surface);
+  if (strb->surface) {
+ width  = MAX2(width,  strb->surface->width);
+ height = MAX2(height, strb->surface->height);
+  }
}
else {
   strb = st_renderbuffer(fb->Attachment[BUFFER_STENCIL].Renderbuffer);
   if (strb) {
  assert(strb->surface);
  pipe_surface_reference(&framebuffer->zsbuf, strb->surface);
+ width  = MAX2(width,  strb->surface->width);
+ height = MAX2(height, strb->surface->height);
   }
   else
  pipe_surface_reference(&framebuffer->zsbuf, NULL);
@@ -122,6 +130,13 @@ update_framebuffer_state( struct st_context *st )
}
 #endif
 
+   /*
+* framebuffer->width should match fb->Weight, but for PIPE_TEXTURE_1D_ARRAY
+* fb->Height has the number of layers as opposed to height.
+*/
+   framebuffer->width  = width;
+   framebuffer->height = height;
+
cso_set_framebuffer(st->cso_context, framebuffer);
 }
 
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 3/3] scons: Add an analyze option.

2014-04-14 Thread jfonseca
From: José Fonseca 

For Clang static code analyzer, the scan-build script will produce more
comprehensive output.  Nevertheless you can invoke it as

  CC=clang CXX=clang++ scons analyze=1

For MSVC this is the best way to use its static code analysis.  Simply
invoke as

  scons analyze=1
---
 common.py|  1 +
 scons/gallium.py | 12 
 2 files changed, 13 insertions(+)

diff --git a/common.py b/common.py
index 22c1725..d6e6215 100644
--- a/common.py
+++ b/common.py
@@ -91,6 +91,7 @@ def AddOptions(opts):
opts.Add(EnumOption('platform', 'target platform', host_platform,

 allowed_values=('cygwin', 'darwin', 'freebsd', 'haiku', 'linux', 
'sunos', 'windows')))
opts.Add(BoolOption('embedded', 'embedded build', 'no'))
+   opts.Add(BoolOption('analyze', 'enable static code analysis where 
available', 'no'))
opts.Add('toolchain', 'compiler toolchain', default_toolchain)
opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support', 
'no'))
opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
diff --git a/scons/gallium.py b/scons/gallium.py
index 42e8f7c..e873c65 100755
--- a/scons/gallium.py
+++ b/scons/gallium.py
@@ -467,6 +467,18 @@ def generate(env):
 env.Append(CCFLAGS = ['/MT'])
 env.Append(SHCCFLAGS = ['/LD'])
 
+# Static code analysis
+if env['analyze']:
+if env['msvc']:
+# http://msdn.microsoft.com/en-us/library/ms173498.aspx
+env.Append(CCFLAGS = [
+'/analyze',
+#'/analyze:log', '${TARGET.base}.xml',
+])
+if env['clang']:
+# scan-build will produce more comprehensive output
+env.Append(CCFLAGS = ['--analyze'])
+
 # Assembler options
 if gcc_compat:
 if env['machine'] == 'x86':
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 1/3] scons: Enable building through Clang Static Analyzer.

2014-04-14 Thread jfonseca
From: José Fonseca 

By accurately detecting gcc/clang through --version option instead
of executable name.

Clang Static Analyzer reports many issues, most false positives, but it
found at least one real and subtle use-after-free issue
in st_texture_get_sampler_view():

  
http://people.freedesktop.org/~jrfonseca/scan-build-2014-04-14-1/report-869047.html#EndPath
---
 scons/gallium.py | 31 +++
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/scons/gallium.py b/scons/gallium.py
index e11d4db..42e8f7c 100755
--- a/scons/gallium.py
+++ b/scons/gallium.py
@@ -104,6 +104,19 @@ def num_jobs():
 return 1
 
 
+def get_cc_version(env):
+# Get the first line of `$CC --version`
+pipe = SCons.Action._subproc(env, [env['CC'], '--version'],
+ stdin = 'devnull',
+ stderr = 'devnull',
+ stdout = subprocess.PIPE)
+if pipe.wait() != 0:
+return ''
+
+line = pipe.stdout.readline()
+return line
+
+
 def generate(env):
 """Common environment generation code"""
 
@@ -119,12 +132,8 @@ def generate(env):
 if os.environ.has_key('CC'):
 env['CC'] = os.environ['CC']
 # Update CCVERSION to match
-pipe = SCons.Action._subproc(env, [env['CC'], '--version'],
- stdin = 'devnull',
- stderr = 'devnull',
- stdout = subprocess.PIPE)
-if pipe.wait() == 0:
-line = pipe.stdout.readline()
+line = get_cc_version(env)
+if line:
 match = re.search(r'[0-9]+(\.[0-9]+)+', line)
 if match:
 env['CCVERSION'] = match.group(0)
@@ -137,10 +146,16 @@ def generate(env):
 if os.environ.has_key('LDFLAGS'):
 env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
 
-env['gcc'] = 'gcc' in os.path.basename(env['CC']).split('-')
+# Detect gcc/clang not by executable name, but through `--version` option,
+# to avoid drawing wrong conclusions when using tools that overrice CC/CXX
+# like scan-build.
+cc_version = get_cc_version(env)
+cc_version_words = cc_version.split()
+
+env['gcc'] = 'gcc' in cc_version_words
 env['msvc'] = env['CC'] == 'cl'
 env['suncc'] = env['platform'] == 'sunos' and os.path.basename(env['CC']) 
== 'cc'
-env['clang'] = env['CC'] == 'clang'
+env['clang'] = 'clang' in cc_version_words
 env['icc'] = 'icc' == os.path.basename(env['CC'])
 
 if env['msvc'] and env['toolchain'] == 'default' and env['machine'] == 
'x86_64':
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 2/3] util/u_debug: Add noreturn attribute to _debug_assert_fail().

2014-04-14 Thread jfonseca
From: José Fonseca 

As recommended by
http://clang-analyzer.llvm.org/annotations.html#attr_noreturn
---
 src/gallium/auxiliary/util/u_debug.h | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/util/u_debug.h 
b/src/gallium/auxiliary/util/u_debug.h
index 9e4eb41..8570597 100644
--- a/src/gallium/auxiliary/util/u_debug.h
+++ b/src/gallium/auxiliary/util/u_debug.h
@@ -154,7 +154,11 @@ debug_get_num_option(const char *name, long dfault);
 void _debug_assert_fail(const char *expr, 
 const char *file, 
 unsigned line, 
-const char *function);
+const char *function)
+#ifdef __GNUC__
+   __attribute__((__noreturn__))
+#endif
+;
 
 
 /** 
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 3/3] util: Add __declspec(noreturn) to _debug_assert_fail().

2014-04-16 Thread jfonseca
From: José Fonseca 

Mostly for consistency; as MSVC's static source code analysis doesn't
seem to rely on assertions, but instead on different kind of source
annotations( http://msdn.microsoft.com/en-us/library/hh916383.aspx ).
---
 src/gallium/auxiliary/util/u_debug.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_debug.h 
b/src/gallium/auxiliary/util/u_debug.h
index 8570597..9c41421 100644
--- a/src/gallium/auxiliary/util/u_debug.h
+++ b/src/gallium/auxiliary/util/u_debug.h
@@ -151,6 +151,9 @@ void debug_print_format(const char *msg, unsigned fmt );
 long
 debug_get_num_option(const char *name, long dfault);
 
+#ifdef _MSC_VER
+__declspec(noreturn)
+#endif
 void _debug_assert_fail(const char *expr, 
 const char *file, 
 unsigned line, 
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 2/3] auxiliary/os,auxiliary/util: Fix the `‘noreturn’ function does return` warning.

2014-04-16 Thread jfonseca
From: José Fonseca 

Now that _debug_assert_fail() has the noreturn attribute, it is better
that execution truly never returns.  Not just for sake of silencing the
warning, but because the code at the return IP address may be invalid or
lead to inconsistent results.

This removes support for the GALLIUM_ABORT_ON_ASSERT debugging
environment variable, but between the usefulness of
GALLIUM_ABORT_ON_ASSERT and better static code analysis I think better
static code analysis wins.
---
 src/gallium/auxiliary/os/os_misc.h   | 2 +-
 src/gallium/auxiliary/util/u_debug.c | 5 +
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/gallium/auxiliary/os/os_misc.h 
b/src/gallium/auxiliary/os/os_misc.h
index 5029ab9..582931f 100644
--- a/src/gallium/auxiliary/os/os_misc.h
+++ b/src/gallium/auxiliary/os/os_misc.h
@@ -67,7 +67,7 @@ extern "C" {
  * Abort the program.
  */
 #if defined(DEBUG)
-#  define os_abort() os_break()
+#  define os_abort() do { os_break(); abort(); } while(0)
 #else
 #  define os_abort() abort()
 #endif
diff --git a/src/gallium/auxiliary/util/u_debug.c 
b/src/gallium/auxiliary/util/u_debug.c
index ae248e0..fe51717 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -274,10 +274,7 @@ void _debug_assert_fail(const char *expr,
 const char *function) 
 {
_debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file, line, function, 
expr);
-   if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", TRUE))
-  os_abort();
-   else
-  _debug_printf("continuing...\n");
+   os_abort();
 }
 
 
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 1/3] scons: Enable building through Clang Static Analyzer.

2014-04-16 Thread jfonseca
From: José Fonseca 

Same intent as commit a45a50a4828e1357e9555474bc127c5585b3a420,
but this the C compiler is detected via C-preprocessor macros,
similar to how autotools do it, as that seems to be the most
reliable method.
---
 scons/gallium.py | 38 +++---
 1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/scons/gallium.py b/scons/gallium.py
index bd71e51..d13d0e6 100755
--- a/scons/gallium.py
+++ b/scons/gallium.py
@@ -36,6 +36,8 @@ import os.path
 import re
 import subprocess
 import platform as _platform
+import sys
+import tempfile
 
 import SCons.Action
 import SCons.Builder
@@ -104,6 +106,28 @@ def num_jobs():
 return 1
 
 
+def check_cc(env, cc, expr, cpp_opt = '-E'):
+# Invoke C-preprocessor to determine whether the specified expression is
+# true or not.
+
+sys.stdout.write('Checking for %s ... ' % cc)
+
+source = tempfile.NamedTemporaryFile(suffix='.c', delete=False)
+source.write('#if !(%s)\n#error\n#endif\n' % expr)
+source.close()
+
+pipe = SCons.Action._subproc(env, [env['CC'], cpp_opt, source.name],
+ stdin = 'devnull',
+ stderr = 'devnull',
+ stdout = 'devnull')
+result = pipe.wait() == 0
+
+os.unlink(source.name)
+
+sys.stdout.write(' %s\n' % ['no', 'yes'][int(bool(result))])
+return result
+
+
 def generate(env):
 """Common environment generation code"""
 
@@ -137,10 +161,18 @@ def generate(env):
 if os.environ.has_key('LDFLAGS'):
 env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
 
-env['gcc'] = 'gcc' in os.path.basename(env['CC']).split('-')
-env['msvc'] = env['CC'] == 'cl'
+# Detect gcc/clang not by executable name, but through pre-defined macros
+# as autoconf does, to avoid drawing wrong conclusions when using tools
+# that overrice CC/CXX like scan-build.
+env['gcc'] = 0
+env['clang'] = 0
+env['msvc'] = 0
+if _platform.system() == 'Windows':
+env['msvc'] = check_cc(env, 'MSVC', 'defined(_MSC_VER)', '/E')
+if not env['msvc']:
+env['gcc'] = check_cc(env, 'GCC', 'defined(__GNUC__) && 
!defined(__clang__)')
+env['clang'] = check_cc(env, 'Clang', '__clang__')
 env['suncc'] = env['platform'] == 'sunos' and os.path.basename(env['CC']) 
== 'cc'
-env['clang'] = env['CC'] == 'clang'
 env['icc'] = 'icc' == os.path.basename(env['CC'])
 
 if env['msvc'] and env['toolchain'] == 'default' and env['machine'] == 
'x86_64':
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 1/2] util/u_debug: Pass correct size to strncat.

2014-04-23 Thread jfonseca
From: José Fonseca 

Courtesy of Clang static analyzer.
---
 src/gallium/auxiliary/util/u_debug.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_debug.c 
b/src/gallium/auxiliary/util/u_debug.c
index fe51717..dc840e8 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -334,10 +334,10 @@ debug_dump_flags(const struct debug_named_value *names,
while(names->name) {
   if((names->value & value) == names->value) {
 if (!first)
-   util_strncat(output, "|", sizeof(output));
+   util_strncat(output, "|", sizeof(output) - strlen(output) - 1);
 else
first = 0;
-util_strncat(output, names->name, sizeof(output) - 1);
+util_strncat(output, names->name, sizeof(output) - strlen(output) - 1);
 output[sizeof(output) - 1] = '\0';
 value &= ~names->value;
   }
@@ -346,12 +346,12 @@ debug_dump_flags(const struct debug_named_value *names,

if (value) {
   if (!first)
-util_strncat(output, "|", sizeof(output));
+util_strncat(output, "|", sizeof(output) - strlen(output) - 1);
   else
 first = 0;
   
   util_snprintf(rest, sizeof(rest), "0x%08lx", value);
-  util_strncat(output, rest, sizeof(output) - 1);
+  util_strncat(output, rest, sizeof(output) - strlen(output) - 1);
   output[sizeof(output) - 1] = '\0';
}

-- 
1.8.3.2

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


[Mesa-dev] [PATCH 2/2] mesa/st: Fix pipe_framebuffer_state::height for PIPE_TEXTURE_1D_ARRAY.

2014-04-23 Thread jfonseca
From: José Fonseca 

This prevents buffer overflow w/ llvmpipe when running piglit

  bin/gl-3.2-layered-rendering-clear-color-all-types 1d_array single_level -fbo 
-auto

v2: Compute the framebuffer size as the minimum size, as pointed out by
Brian;  compacted code;  ran piglit quick test list (with no
regressions.)
---
 src/mesa/state_tracker/st_atom_framebuffer.c | 33 ++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c 
b/src/mesa/state_tracker/st_atom_framebuffer.c
index 4c4f839..f395ec7 100644
--- a/src/mesa/state_tracker/st_atom_framebuffer.c
+++ b/src/mesa/state_tracker/st_atom_framebuffer.c
@@ -31,6 +31,8 @@
   *   Brian Paul
   */
  
+#include 
+
 #include "st_context.h"
 #include "st_atom.h"
 #include "st_cb_bitmap.h"
@@ -44,6 +46,24 @@
 
 
 /**
+ * Update framebuffer size.
+ *
+ * framebuffer->width should match fb->Weight, but for PIPE_TEXTURE_1D_ARRAY
+ * textures fb->Height has the number of layers, and not the surface height.
+ */
+static void
+update_framebuffer_size(struct pipe_framebuffer_state *framebuffer,
+struct pipe_surface *surface)
+{
+   assert(surface);
+   assert(surface->width  < UINT_MAX);
+   assert(surface->height < UINT_MAX);
+   framebuffer->width  = MIN2(framebuffer->width,  surface->width);
+   framebuffer->height = MIN2(framebuffer->height, surface->height);
+}
+
+
+/**
  * Update framebuffer state (color, depth, stencil, etc. buffers)
  */
 static void
@@ -57,11 +77,12 @@ update_framebuffer_state( struct st_context *st )
st_flush_bitmap_cache(st);
 
st->state.fb_orientation = st_fb_orientation(fb);
-   framebuffer->width = fb->Width;
-   framebuffer->height = fb->Height;
 
/*printf("-- fb size %d x %d\n", fb->Width, fb->Height);*/
 
+   framebuffer->width  = UINT_MAX;
+   framebuffer->height = UINT_MAX;
+
/* Examine Mesa's ctx->DrawBuffer->_ColorDrawBuffers state
 * to determine which surfaces to draw to
 */
@@ -81,6 +102,7 @@ update_framebuffer_state( struct st_context *st )
 
  if (strb->surface) {
 pipe_surface_reference(&framebuffer->cbufs[i], strb->surface);
+update_framebuffer_size(framebuffer, strb->surface);
  }
  strb->defined = GL_TRUE; /* we'll be drawing something */
   }
@@ -100,12 +122,14 @@ update_framebuffer_state( struct st_context *st )
  st_update_renderbuffer_surface(st, strb);
   }
   pipe_surface_reference(&framebuffer->zsbuf, strb->surface);
+  update_framebuffer_size(framebuffer, strb->surface);
}
else {
   strb = st_renderbuffer(fb->Attachment[BUFFER_STENCIL].Renderbuffer);
   if (strb) {
  assert(strb->surface);
  pipe_surface_reference(&framebuffer->zsbuf, strb->surface);
+ update_framebuffer_size(framebuffer, strb->surface);
   }
   else
  pipe_surface_reference(&framebuffer->zsbuf, NULL);
@@ -122,6 +146,11 @@ update_framebuffer_state( struct st_context *st )
}
 #endif
 
+   /* _mesa_test_framebuffer_completeness refuses framebuffers with no
+* attachments, so this should never happen. */
+   assert(framebuffer->width  != UINT_MAX);
+   assert(framebuffer->height != UINT_MAX);
+
cso_set_framebuffer(st->cso_context, framebuffer);
 }
 
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 1/2] st/xlib: Honour request of 3.1 contexts through core profile where available.

2014-04-24 Thread jfonseca
From: José Fonseca 

The GLX_ARB_create_context_profile spec says:

"If version 3.1 is requested, the context returned may implement
any of the following versions:

  * Version 3.1. The GL_ARB_compatibility extension may or may not
be implemented, as determined by the implementation.

  * The core profile of version 3.2 or greater."

Mesa does not support GL_ARB_compatibility, and there are no plans to
ever support it, therefore the only chance to honour a 3.1 context is
through core profile, i.e, the 2nd alternative from the spec.

This change does that.  And with it piglit tests that require 3.1
contexts no longer skip.

Assuming there is no objection with this change, src/glx/dri_common.c
and src/gallium/state_trackers/wgl/stw_context.c should also be updated
accordingly, given they have the same logic.
---
 src/gallium/state_trackers/glx/xlib/xm_api.c | 17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c 
b/src/gallium/state_trackers/glx/xlib/xm_api.c
index bb2dd8e..7836c61 100644
--- a/src/gallium/state_trackers/glx/xlib/xm_api.c
+++ b/src/gallium/state_trackers/glx/xlib/xm_api.c
@@ -899,10 +899,23 @@ XMesaContext XMesaCreateContext( XMesaVisual v, 
XMesaContext share_list,
 *
 * "The default value for GLX_CONTEXT_PROFILE_MASK_ARB is
 * GLX_CONTEXT_CORE_PROFILE_BIT_ARB."
+*
+* The spec also says:
+*
+* "If version 3.1 is requested, the context returned may implement
+* any of the following versions:
+*
+*   * Version 3.1. The GL_ARB_compatibility extension may or may not
+* be implemented, as determined by the implementation.
+*   * The core profile of version 3.2 or greater."
+*
+* and because Mesa doesn't support GL_ARB_compatibility, the only chance to
+* honour a 3.1 context is through core profile.
 */
attribs.profile = ST_PROFILE_DEFAULT;
-   if ((major > 3 || (major == 3 && minor >= 2))
-   && ((profileMask & GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB) == 0))
+   if (((major > 3 || (major == 3 && minor >= 2))
+&& ((profileMask & GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB) == 0)) ||
+   (major == 3 && minor == 1))
   attribs.profile = ST_PROFILE_OPENGL_CORE;
 
c->st = stapi->create_context(stapi, xmdpy->smapi, &attribs,
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 2/2] llvmpipe: Advertise GLSL 3.30.

2014-04-24 Thread jfonseca
From: José Fonseca 

According to Roland all TGSI support is there in theory.

In practice there are a few piglit failures and crashes, as this hadn't
been tested before.
---
 src/gallium/drivers/llvmpipe/lp_screen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index 8fbc58f..27073a4 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -200,7 +200,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum 
pipe_cap param)
case PIPE_CAP_VERTEX_COLOR_CLAMPED:
   return 1;
case PIPE_CAP_GLSL_FEATURE_LEVEL:
-  return 140;
+  return 330;
case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
   return 0;
case PIPE_CAP_COMPUTE:
-- 
1.8.3.2

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


[Mesa-dev] [PATCH] st/xlib: Do minimal version checking in glXCreateContextAttribsARB.

2014-04-24 Thread jfonseca
From: José Fonseca 

The current version checking is wrongly refusing to create 3.3 contexts;
unsupported version are checked elsewhere; and the DRI path doesn't do
this sort of checking neither.

This enables piglit glsl 3.30 tests to run without skipping.
---
 src/gallium/state_trackers/glx/xlib/glx_api.c | 20 +---
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/src/gallium/state_trackers/glx/xlib/glx_api.c 
b/src/gallium/state_trackers/glx/xlib/glx_api.c
index 05880dd..d97cbd7 100644
--- a/src/gallium/state_trackers/glx/xlib/glx_api.c
+++ b/src/gallium/state_trackers/glx/xlib/glx_api.c
@@ -2724,26 +2724,8 @@ glXCreateContextAttribsARB(Display *dpy, GLXFBConfig 
config,
}
 
/* check version (generate BadMatch if bad) */
-   switch (majorVersion) {
-   case 1:
-  if (minorVersion < 0 || minorVersion > 5)
- return NULL;
-  break;
-   case 2:
-  if (minorVersion < 0 || minorVersion > 1)
- return NULL;
-  break;
-   case 3:
-  if (minorVersion < 0 || minorVersion > 2)
- return NULL;
-  break;
-   case 4:
-  if (minorVersion < 0 || minorVersion > 0)
- return NULL;
-  break;
-   default:
+   if (majorVersion < 0 || minorVersion < 0)
   return NULL;
-   }
 
if ((contextFlags & GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB) &&
majorVersion < 3)
-- 
1.8.3.2

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


[Mesa-dev] [PATCH 3/9] st/vega: Prevent signed/unsigned comparisons.

2014-05-02 Thread jfonseca
From: José Fonseca 

---
 src/gallium/state_trackers/vega/vg_translate.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/gallium/state_trackers/vega/vg_translate.c 
b/src/gallium/state_trackers/vega/vg_translate.c
index 7b3df27..4aad899 100644
--- a/src/gallium/state_trackers/vega/vg_translate.c
+++ b/src/gallium/state_trackers/vega/vg_translate.c
@@ -34,7 +34,7 @@ void _vega_pack_rgba_span_float(struct vg_context *ctx,
 VGImageFormat dstFormat,
 void *dstAddr)
 {
-   VGint i;
+   VGuint i;
 
switch (dstFormat) {
case VG_sRGBX_: {
@@ -458,7 +458,7 @@ void _vega_unpack_float_span_rgba(struct vg_context *ctx,
   VGImageFormat dataFormat,
   VGfloat rgba[][4])
 {
-   VGint i;
+   VGuint i;
union util_color uc;
 
switch (dataFormat) {
@@ -681,7 +681,7 @@ void _vega_unpack_float_span_rgba(struct vg_context *ctx,
   src += offset;
   for (i = 0; i < n; i += 8) {
  VGfloat clr[4];
- VGint j;
+ VGuint j;
  for (j = 0; j < 8 && j < n ; ++j) {
 VGint shift = j;
 clr[0] = (((*src) & (1<> shift);
@@ -705,7 +705,7 @@ void _vega_unpack_float_span_rgba(struct vg_context *ctx,
   src += offset;
   for (i = 0; i < n; i += 8) {
  VGfloat clr[4];
- VGint j;
+ VGuint j;
  for (j = 0; j < 8 && j < n ; ++j) {
 VGint shift = j;
 clr[0] = 0.f;
@@ -728,7 +728,7 @@ void _vega_unpack_float_span_rgba(struct vg_context *ctx,
   src += offset/2;
   for (i = 0; i < n; i += 2) {
  VGfloat clr[4];
- VGint j;
+ VGuint j;
  for (j = 0; j < n && j < 2; ++j) {
 VGint bitter, shift;
 if (j == 0) {
-- 
1.9.1

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


[Mesa-dev] [PATCH 2/9] scons: Adjust the warnings for VS.

2014-05-02 Thread jfonseca
From: José Fonseca 

Silence insignificant warnings so significant warnings have a chance to
stand out.

The only abundant warning that's not silenced here is "C4018:
signed/unsigned mismatch", as it could hide security issues, so it's better
to actually fix the code.
---
 scons/gallium.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/scons/gallium.py b/scons/gallium.py
index d13d0e6..ca317b0 100755
--- a/scons/gallium.py
+++ b/scons/gallium.py
@@ -455,7 +455,9 @@ def generate(env):
 ]
 ccflags += [
 '/W3', # warning level
-#'/Wp64', # enable 64 bit porting warnings
+'/wd4244', # conversion from 'type1' to 'type2', possible loss of 
data
+'/wd4305', # truncation from 'type1' to 'type2'
+'/wd4800', # forcing value to bool 'true' or 'false' (performance 
warning)
 '/wd4996', # disable deprecated POSIX name warnings
 ]
 if env['machine'] == 'x86':
-- 
1.9.1

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


[Mesa-dev] [PATCH 1/9] util/u_debug_flush: Use util_snprintf.

2014-05-02 Thread jfonseca
From: José Fonseca 

---
 src/gallium/auxiliary/util/u_debug_flush.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_debug_flush.c 
b/src/gallium/auxiliary/util/u_debug_flush.c
index 9cf70db..fdb248c 100644
--- a/src/gallium/auxiliary/util/u_debug_flush.c
+++ b/src/gallium/auxiliary/util/u_debug_flush.c
@@ -46,6 +46,7 @@
 #include "util/u_hash_table.h"
 #include "util/u_double_list.h"
 #include "util/u_inlines.h"
+#include "util/u_string.h"
 #include "os/os_thread.h"
 #include 
 
@@ -320,8 +321,8 @@ debug_flush_might_flush_cb(void *key, void *value, void 
*data)
const char *reason = (const char *) data;
char message[80];
 
-   snprintf(message, sizeof(message),
-"%s referenced mapped buffer detected.", reason);
+   util_snprintf(message, sizeof(message),
+ "%s referenced mapped buffer detected.", reason);
 
pipe_mutex_lock(fbuf->mutex);
if (fbuf->mapped_sync) {
-- 
1.9.1

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


[Mesa-dev] [PATCH 5/9] scons: Don't restrict MSVC_VERSION values.

2014-05-02 Thread jfonseca
From: José Fonseca 

Saves the trouble of continuously needing to update.
---
 common.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common.py b/common.py
index d6e6215..1d2d586 100644
--- a/common.py
+++ b/common.py
@@ -101,4 +101,4 @@ def AddOptions(opts):
opts.Add(BoolOption('quiet', 'DEPRECATED: profile build', 'yes'))
opts.Add(BoolOption('texture_float', 'enable floating-point textures 
and renderbuffers', 'no'))
if host_platform == 'windows':
-   opts.Add(EnumOption('MSVC_VERSION', 'MS Visual C++ version', 
None, allowed_values=('7.1', '8.0', '9.0', '10.0', '11.0', '12.0')))
+   opts.Add('MSVC_VERSION', 'Microsoft Visual C/C++ version')
-- 
1.9.1

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


[Mesa-dev] [PATCH 7/9] egl: Don't attempt to redefine stdint.h types with VS 2013.

2014-05-02 Thread jfonseca
From: José Fonseca 

Just include stdint.h.
---
 src/egl/main/eglcompiler.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/egl/main/eglcompiler.h b/src/egl/main/eglcompiler.h
index 53dab54..5ea83d6 100644
--- a/src/egl/main/eglcompiler.h
+++ b/src/egl/main/eglcompiler.h
@@ -37,7 +37,8 @@
 /**
  * Get standard integer types
  */
-#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
+(defined(_MSC_VER) && _MSC_VER >= 1600)
 #  include 
 #elif defined(_MSC_VER)
typedef __int8 int8_t;
-- 
1.9.1

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


[Mesa-dev] [PATCH 6/9] scons: Don't use bundled C99 headers for VS 2013.

2014-05-02 Thread jfonseca
From: José Fonseca 

Use the ones provided by the compiler instead.

NOTE: External trees should be updated to not include '#include/c99'
directory directly, but rather rely on scons/gallium.py to do the right
thing.
---
 SConstruct   | 6 --
 scons/gallium.py | 6 ++
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/SConstruct b/SConstruct
index 0e10818..ef71ab6 100644
--- a/SConstruct
+++ b/SConstruct
@@ -80,9 +80,6 @@ env.Append(CPPPATH = [
'#/src/gallium/winsys',
 ])
 
-if env['msvc']:
-env.Append(CPPPATH = ['#include/c99'])
-
 # for debugging
 #print env.Dump()
 
@@ -115,9 +112,6 @@ if env['crosscompile'] and not env['embedded']:
 host_env['hostonly'] = True
 assert host_env['crosscompile'] == False
 
-if host_env['msvc']:
-host_env.Append(CPPPATH = ['#include/c99'])
-
 target_env = env
 env = host_env
 Export('env')
diff --git a/scons/gallium.py b/scons/gallium.py
index ca317b0..5109ebf 100755
--- a/scons/gallium.py
+++ b/scons/gallium.py
@@ -433,6 +433,12 @@ def generate(env):
 # See also:
 # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
 # - cl /?
+if 'MSVC_VERSION' not in env or 
distutils.version.LooseVersion(env['MSVC_VERSION']) < 
distutils.version.LooseVersion('12.0'):
+# Use bundled stdbool.h and stdint.h headers for older MSVC
+# versions.  stdint.h was introduced in MSVC 2010, but stdbool.h
+# was only introduced in MSVC 2013.
+top_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 
'..'))
+env.Append(CPPPATH = [os.path.join(top_dir, 'include/c99')])
 if env['build'] == 'debug':
 ccflags += [
   '/Od', # disable optimizations
-- 
1.9.1

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


[Mesa-dev] [PATCH 9/9] util: Don't attempt to redefine INFINITY/NAN on VS 2013.

2014-05-02 Thread jfonseca
From: José Fonseca 

There are now provided by VS.
---
 src/gallium/auxiliary/util/u_math.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_math.h 
b/src/gallium/auxiliary/util/u_math.h
index a60e183..2ade64a 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -138,8 +138,13 @@ roundf(float x)
 }
 #endif
 
+#ifndef INFINITY
 #define INFINITY (DBL_MAX + DBL_MAX)
+#endif
+
+#ifndef NAN
 #define NAN (INFINITY - INFINITY)
+#endif
 
 #endif /* _MSC_VER */
 
-- 
1.9.1

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


[Mesa-dev] [PATCH 4/9] draw: Prevent signed/unsigned comparisons.

2014-05-02 Thread jfonseca
From: José Fonseca 

---
 src/gallium/auxiliary/draw/draw_pt_so_emit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/draw/draw_pt_so_emit.c 
b/src/gallium/auxiliary/draw/draw_pt_so_emit.c
index bd49d0a..91e67c0 100644
--- a/src/gallium/auxiliary/draw/draw_pt_so_emit.c
+++ b/src/gallium/auxiliary/draw/draw_pt_so_emit.c
@@ -162,7 +162,7 @@ static void so_emit_prim(struct pt_so_emit *so,
for (i = 0; i < num_vertices; ++i) {
   const float (*input)[4];
   const float *pre_clip_pos = NULL;
-  int ob;
+  unsigned  ob;
 
   input = (const float (*)[4])(
  (const char *)input_ptr + (indices[i] * input_vertex_stride));
-- 
1.9.1

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


[Mesa-dev] [PATCH 8/9] mesa: VS 2013 does not provide strcasecmp.

2014-05-02 Thread jfonseca
From: José Fonseca 

A define is necessary, like for earlier VS versions.
---
 src/mesa/main/imports.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
index 17a9bd0..af780b2 100644
--- a/src/mesa/main/imports.h
+++ b/src/mesa/main/imports.h
@@ -126,7 +126,8 @@ typedef union { GLfloat f; GLint i; GLuint u; } fi_type;
 #define atanhf(f) ((float) atanh(f))
 #endif
 
-#if defined(_MSC_VER) && (_MSC_VER < 1800)  /* Not req'd on VS2013 and above */
+#if defined(_MSC_VER)
+#if _MSC_VER < 1800  /* Not req'd on VS2013 and above */
 static inline float truncf(float x) { return x < 0.0f ? ceilf(x) : floorf(x); }
 static inline float exp2f(float x) { return powf(2.0f, x); }
 static inline float log2f(float x) { return logf(x) * 1.442695041f; }
@@ -135,6 +136,7 @@ static inline float acoshf(float x) { return logf(x + 
sqrtf(x * x - 1.0f)); }
 static inline float atanhf(float x) { return (logf(1.0f + x) - logf(1.0f - x)) 
/ 2.0f; }
 static inline int isblank(int ch) { return ch == ' ' || ch == '\t'; }
 #define strtoll(p, e, b) _strtoi64(p, e, b)
+#endif /* _MSC_VER < 1800 */
 #define strcasecmp(s1, s2) _stricmp(s1, s2)
 #endif
 /*@}*/
-- 
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] st/wgl: Honour request of 3.1 contexts through core profile where available.

2014-05-07 Thread jfonseca
From: José Fonseca 

Port 5f493eed69f6fb11239c04119d602f1c23a68cbd from GLX.
---
 src/gallium/state_trackers/wgl/stw_context.c | 17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/gallium/state_trackers/wgl/stw_context.c 
b/src/gallium/state_trackers/wgl/stw_context.c
index 3a93091..43186fa 100644
--- a/src/gallium/state_trackers/wgl/stw_context.c
+++ b/src/gallium/state_trackers/wgl/stw_context.c
@@ -205,10 +205,23 @@ stw_create_context_attribs(
 *
 * "The default value for WGL_CONTEXT_PROFILE_MASK_ARB is
 * WGL_CONTEXT_CORE_PROFILE_BIT_ARB."
+*
+* The spec also says:
+*
+* "If version 3.1 is requested, the context returned may implement
+* any of the following versions:
+*
+*   * Version 3.1. The GL_ARB_compatibility extension may or may not
+* be implemented, as determined by the implementation.
+*   * The core profile of version 3.2 or greater."
+*
+* and because Mesa doesn't support GL_ARB_compatibility, the only chance to
+* honour a 3.1 context is through core profile.
 */
attribs.profile = ST_PROFILE_DEFAULT;
-   if ((majorVersion > 3 || (majorVersion == 3 && minorVersion >= 2))
-   && ((profileMask & WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB) == 0))
+   if (((majorVersion > 3 || (majorVersion == 3 && minorVersion >= 2))
+&& ((profileMask & WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB) == 0)) ||
+   (majorVersion == 3 && minorVersion == 1))
   attribs.profile = ST_PROFILE_OPENGL_CORE;
 
ctx->st = stw_dev->stapi->create_context(stw_dev->stapi,
-- 
1.9.1

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


[Mesa-dev] [PATCH 2/2] st/wgl: Advertise WGL_ARB_create_context(_profile).

2014-05-07 Thread jfonseca
From: José Fonseca 

We added wglCreateContextAttribsARB but not the extension strings.

This allows creation of GL 3.x contents.
---
 src/gallium/state_trackers/wgl/stw_ext_extensionsstring.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/gallium/state_trackers/wgl/stw_ext_extensionsstring.c 
b/src/gallium/state_trackers/wgl/stw_ext_extensionsstring.c
index 566f78c..06a152b 100644
--- a/src/gallium/state_trackers/wgl/stw_ext_extensionsstring.c
+++ b/src/gallium/state_trackers/wgl/stw_ext_extensionsstring.c
@@ -35,6 +35,8 @@
 
 
 static const char *stw_extension_string = 
+   "WGL_ARB_create_context "
+   "WGL_ARB_create_context_profile "
"WGL_ARB_extensions_string "
"WGL_ARB_multisample "
"WGL_ARB_pbuffer "
-- 
1.9.1

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


[Mesa-dev] [PATCH] ralloc: Omit detailed license information about talloc.

2014-05-09 Thread jfonseca
From: José Fonseca 

That information misleads source code auditing tools to think that
ralloc itself is released under LGPL v3.

Instead, simply state talloc is not licensed under a permissive license.
---
 src/glsl/ralloc.h | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/glsl/ralloc.h b/src/glsl/ralloc.h
index 4581a7a..70f7d9c 100644
--- a/src/glsl/ralloc.h
+++ b/src/glsl/ralloc.h
@@ -38,10 +38,9 @@
  * Tridgell's talloc, but ralloc is an independent implementation
  * released under the MIT license and tuned for Mesa.
  *
- * The talloc implementation is available under the GNU Lesser
- * General Public License (GNU LGPL), version 3 or later. It is
- * more sophisticated than ralloc in that it includes reference
- * counting and debugging features. See: http://talloc.samba.org/
+ * The talloc implementation is not available under a permissive
+ * license. It is more sophisticated than ralloc in that it includes
+ * reference counting and debugging features. See: http://talloc.samba.org/
  */
 
 #ifndef RALLOC_H
-- 
1.9.1

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


[Mesa-dev] [PATCH 04/12] gallivm: Stop using module providers.

2014-05-13 Thread jfonseca
From: José Fonseca 

Nowadays LLVMModuleProviderRef is just an alias for LLVMModuleRef, so
its use just causes unnecessary confusion.
---
 src/gallium/auxiliary/gallivm/lp_bld_init.c | 33 ++---
 src/gallium/auxiliary/gallivm/lp_bld_init.h |  1 -
 2 files changed, 7 insertions(+), 27 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c 
b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 85faef5..6934a28 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -122,7 +122,7 @@ create_pass_manager(struct gallivm_state *gallivm)
assert(!gallivm->passmgr);
assert(gallivm->target);
 
-   gallivm->passmgr = LLVMCreateFunctionPassManager(gallivm->provider);
+   gallivm->passmgr = LLVMCreateFunctionPassManagerForModule(gallivm->module);
if (!gallivm->passmgr)
   return FALSE;
 
@@ -177,26 +177,16 @@ create_pass_manager(struct gallivm_state *gallivm)
 static void
 free_gallivm_state(struct gallivm_state *gallivm)
 {
-   /* This leads to crashes w/ some versions of LLVM */
-   LLVMModuleRef mod;
-   char *error;
-
-   if (gallivm->engine && gallivm->provider)
-  LLVMRemoveModuleProvider(gallivm->engine, gallivm->provider,
-   &mod, &error);
-
if (gallivm->passmgr) {
   LLVMDisposePassManager(gallivm->passmgr);
}
 
-#if 0
-   /* XXX this seems to crash with all versions of LLVM */
-   if (gallivm->provider)
-  LLVMDisposeModuleProvider(gallivm->provider);
-#endif
-
-   /* This will already destroy any associated module */
-   LLVMDisposeExecutionEngine(gallivm->engine);
+   if (gallivm->engine) {
+  /* This will already destroy any associated module */
+  LLVMDisposeExecutionEngine(gallivm->engine);
+   } else if (gallivm->module) {
+  LLVMDisposeModule(gallivm->module);
+   }
 
 #if !USE_MCJIT
/* Don't free the TargetData, it's owned by the exec engine */
@@ -219,7 +209,6 @@ free_gallivm_state(struct gallivm_state *gallivm)
gallivm->engine = NULL;
gallivm->target = NULL;
gallivm->module = NULL;
-   gallivm->provider = NULL;
gallivm->passmgr = NULL;
gallivm->context = NULL;
gallivm->builder = NULL;
@@ -253,8 +242,6 @@ init_gallivm_engine(struct gallivm_state *gallivm)
   }
}
 
-   LLVMAddModuleProvider(gallivm->engine, gallivm->provider);//new
-
 #if !USE_MCJIT
gallivm->target = LLVMGetExecutionEngineTargetData(gallivm->engine);
if (!gallivm->target)
@@ -311,7 +298,6 @@ init_gallivm_state(struct gallivm_state *gallivm)
 {
assert(!gallivm->context);
assert(!gallivm->module);
-   assert(!gallivm->provider);
 
lp_build_init();
 
@@ -327,11 +313,6 @@ init_gallivm_state(struct gallivm_state *gallivm)
if (!gallivm->module)
   goto fail;
 
-   gallivm->provider =
-  LLVMCreateModuleProviderForExistingModule(gallivm->module);
-   if (!gallivm->provider)
-  goto fail;
-
gallivm->builder = LLVMCreateBuilderInContext(gallivm->context);
if (!gallivm->builder)
   goto fail;
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h 
b/src/gallium/auxiliary/gallivm/lp_bld_init.h
index 7edea61..68f4006 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h
@@ -40,7 +40,6 @@ struct gallivm_state
 {
LLVMModuleRef module;
LLVMExecutionEngineRef engine;
-   LLVMModuleProviderRef provider;
LLVMTargetDataRef target;
LLVMPassManagerRef passmgr;
LLVMContextRef context;
-- 
1.9.1

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


[Mesa-dev] [PATCH 10/12] llvmpipe: Delete unneeded LLVM stuff earlier.

2014-05-13 Thread jfonseca
From: José Fonseca 

Same as Frank's change to draw module but for llvmpipe module.
---
 src/gallium/drivers/llvmpipe/lp_state_fs.c| 13 ++---
 src/gallium/drivers/llvmpipe/lp_state_setup.c | 13 ++---
 src/gallium/drivers/llvmpipe/lp_test_arit.c   |  4 ++--
 src/gallium/drivers/llvmpipe/lp_test_blend.c  |  4 ++--
 src/gallium/drivers/llvmpipe/lp_test_conv.c   |  4 ++--
 src/gallium/drivers/llvmpipe/lp_test_format.c |  8 
 src/gallium/drivers/llvmpipe/lp_test_printf.c |  4 ++--
 7 files changed, 16 insertions(+), 34 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c 
b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index 5e28f0e..a26b981 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -2639,6 +2639,8 @@ generate_variant(struct llvmpipe_context *lp,
   variant->jit_function[RAST_WHOLE] = 
variant->jit_function[RAST_EDGE_TEST];
}
 
+   gallivm_free_ir(variant->gallivm);
+
return variant;
 }
 
@@ -2763,8 +2765,6 @@ void
 llvmpipe_remove_shader_variant(struct llvmpipe_context *lp,
struct lp_fragment_shader_variant *variant)
 {
-   unsigned i;
-
if (gallivm_debug & GALLIVM_DEBUG_IR) {
   debug_printf("llvmpipe: del fs #%u var #%u v created #%u v cached"
" #%u v total cached #%u\n",
@@ -2775,15 +2775,6 @@ llvmpipe_remove_shader_variant(struct llvmpipe_context 
*lp,
lp->nr_fs_variants);
}
 
-   /* free all the variant's JIT'd functions */
-   for (i = 0; i < Elements(variant->function); i++) {
-  if (variant->function[i]) {
- gallivm_free_function(variant->gallivm,
-   variant->function[i],
-   variant->jit_function[i]);
-  }
-   }
-
gallivm_destroy(variant->gallivm);
 
/* remove from shader's list */
diff --git a/src/gallium/drivers/llvmpipe/lp_state_setup.c 
b/src/gallium/drivers/llvmpipe/lp_state_setup.c
index 1d79a4a..10ede56 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_setup.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_setup.c
@@ -800,6 +800,8 @@ generate_setup_variant(struct lp_setup_variant_key *key,
if (!variant->jit_function)
   goto fail;
 
+   gallivm_free_ir(variant->gallivm);
+
/*
 * Update timing information:
 */
@@ -813,11 +815,6 @@ generate_setup_variant(struct lp_setup_variant_key *key,
 
 fail:
if (variant) {
-  if (variant->function) {
- gallivm_free_function(gallivm,
-   variant->function,
-   variant->jit_function);
-  }
   if (variant->gallivm) {
  gallivm_destroy(variant->gallivm);
   }
@@ -893,12 +890,6 @@ remove_setup_variant(struct llvmpipe_context *lp,
   variant->no, lp->nr_setup_variants);
}
 
-   if (variant->function) {
-  gallivm_free_function(variant->gallivm,
-variant->function,
-variant->jit_function);
-   }
-
if (variant->gallivm) {
   gallivm_destroy(variant->gallivm);
}
diff --git a/src/gallium/drivers/llvmpipe/lp_test_arit.c 
b/src/gallium/drivers/llvmpipe/lp_test_arit.c
index 8996411..f8998c1 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_arit.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_arit.c
@@ -362,6 +362,8 @@ test_unary(unsigned verbose, FILE *fp, const struct 
unary_test_t *test)
 
test_func_jit = (unary_func_t) gallivm_jit_function(gallivm, test_func);
 
+   gallivm_free_ir(gallivm);
+
for (j = 0; j < (test->num_values + length - 1) / length; j++) {
   int num_vals = ((j + 1) * length <= test->num_values) ? length :
   test->num_values 
% length;
@@ -401,8 +403,6 @@ test_unary(unsigned verbose, FILE *fp, const struct 
unary_test_t *test)
   }
}
 
-   gallivm_free_function(gallivm, test_func, test_func_jit);
-
gallivm_destroy(gallivm);
 
align_free(in);
diff --git a/src/gallium/drivers/llvmpipe/lp_test_blend.c 
b/src/gallium/drivers/llvmpipe/lp_test_blend.c
index 70f71fa..ec80593 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_blend.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_blend.c
@@ -458,6 +458,8 @@ test_one(unsigned verbose,
 
blend_test_ptr = (blend_test_ptr_t)gallivm_jit_function(gallivm, func);
 
+   gallivm_free_ir(gallivm);
+
success = TRUE;
 
{
@@ -576,8 +578,6 @@ test_one(unsigned verbose,
if(fp)
   write_tsv_row(fp, blend, type, cycles_avg, success);
 
-   gallivm_free_function(gallivm, func, blend_test_ptr);
-
gallivm_destroy(gallivm);
 
return success;
diff --git a/src/gallium/drivers/llvmpipe/lp_test_conv.c 
b/src/gallium/drivers/llvmpipe/lp_test_conv.c
index e2ec6e2..b7d0bfd 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_conv.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_conv.c
@@ -219,6 +219,8 @@ test_one(unsigned verbose,
 
conv_test_ptr = (conv

[Mesa-dev] [PATCH 11/12] gallivm: Remove gallivm_free_function.

2014-05-13 Thread jfonseca
From: José Fonseca 

Unused.  Deprecated by gallivm_free_ir().
---
 src/gallium/auxiliary/gallivm/lp_bld_init.c | 18 --
 src/gallium/auxiliary/gallivm/lp_bld_init.h |  5 -
 2 files changed, 23 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c 
b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 6feec70..36d1bc5 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -610,21 +610,3 @@ gallivm_jit_function(struct gallivm_state *gallivm,
 
return jit_func;
 }
-
-
-/**
- * Free the function (and its machine code).
- */
-void
-gallivm_free_function(struct gallivm_state *gallivm,
-  LLVMValueRef func,
-  const void *code)
-{
-#if !USE_MCJIT
-   if (code) {
-  LLVMFreeMachineCodeForFunction(gallivm->engine, func);
-   }
-
-   LLVMDeleteFunction(func);
-#endif
-}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h 
b/src/gallium/auxiliary/gallivm/lp_bld_init.h
index b11e986..464bb83 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h
@@ -74,11 +74,6 @@ gallivm_jit_function(struct gallivm_state *gallivm,
  LLVMValueRef func);
 
 void
-gallivm_free_function(struct gallivm_state *gallivm,
-  LLVMValueRef func,
-  const void * code);
-
-void
 lp_set_load_alignment(LLVMValueRef Inst,
unsigned Align);
 
-- 
1.9.1

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


[Mesa-dev] [PATCH 08/12] gallivm: Separate freeing LLVM intermediate data from freeing final code.

2014-05-13 Thread jfonseca
From: Frank Henigman 

Split free_gallivm_state() into two steps.  First step is
gallivm_free_ir() which cleans up the LLVM scaffolding used to generate
code while preserving the code itself.  Second step is
gallivm_free_code() to free the memory occupied by the code.

v2: s/gallivm_teardown/gallivm_free_ir/ (Jose)

Signed-off-by: José Fonseca 
---
 src/gallium/auxiliary/gallivm/lp_bld_init.c | 27 ---
 src/gallium/auxiliary/gallivm/lp_bld_init.h |  2 ++
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c 
b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 982d1db..6feec70 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -182,10 +182,11 @@ create_pass_manager(struct gallivm_state *gallivm)
 
 
 /**
- * Free gallivm object's LLVM allocations, but not the gallivm object itself.
+ * Free gallivm object's LLVM allocations, but not any generated code
+ * nor the gallivm object itself.
  */
-static void
-free_gallivm_state(struct gallivm_state *gallivm)
+void
+gallivm_free_ir(struct gallivm_state *gallivm)
 {
if (gallivm->passmgr) {
   LLVMDisposePassManager(gallivm->passmgr);
@@ -212,14 +213,24 @@ free_gallivm_state(struct gallivm_state *gallivm)
if (!USE_GLOBAL_CONTEXT && gallivm->context)
   LLVMContextDispose(gallivm->context);
 
-   lp_free_generated_code(gallivm->code);
-
gallivm->engine = NULL;
gallivm->target = NULL;
gallivm->module = NULL;
gallivm->passmgr = NULL;
gallivm->context = NULL;
gallivm->builder = NULL;
+}
+
+
+/**
+ * Free LLVM-generated code.  Should be done AFTER gallivm_free_ir().
+ */
+static void
+gallivm_free_code(struct gallivm_state *gallivm)
+{
+   assert(!gallivm->module);
+   assert(!gallivm->engine);
+   lp_free_generated_code(gallivm->code);
gallivm->code = NULL;
 }
 
@@ -366,7 +377,8 @@ init_gallivm_state(struct gallivm_state *gallivm)
return TRUE;
 
 fail:
-   free_gallivm_state(gallivm);
+   gallivm_free_ir(gallivm);
+   gallivm_free_code(gallivm);
return FALSE;
 }
 
@@ -497,7 +509,8 @@ gallivm_create(void)
 void
 gallivm_destroy(struct gallivm_state *gallivm)
 {
-   free_gallivm_state(gallivm);
+   gallivm_free_ir(gallivm);
+   gallivm_free_code(gallivm);
FREE(gallivm);
 }
 
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h 
b/src/gallium/auxiliary/gallivm/lp_bld_init.h
index e405b8a..b11e986 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h
@@ -59,6 +59,8 @@ gallivm_create(void);
 void
 gallivm_destroy(struct gallivm_state *gallivm);
 
+void
+gallivm_free_ir(struct gallivm_state *gallivm);
 
 void
 gallivm_verify_function(struct gallivm_state *gallivm,
-- 
1.9.1

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


[Mesa-dev] [PATCH 06/12] gallivm: Run passes per module, not per function.

2014-05-13 Thread jfonseca
From: José Fonseca 

This is how it is meant to be done nowadays.
---
 src/gallium/auxiliary/gallivm/lp_bld_init.c | 47 -
 1 file changed, 19 insertions(+), 28 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c 
b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 2d854e9..a3549c1 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -499,32 +499,6 @@ gallivm_destroy(struct gallivm_state *gallivm)
 
 
 /**
- * Validate and optimze a function.
- */
-static void
-gallivm_optimize_function(struct gallivm_state *gallivm,
-  LLVMValueRef func)
-{
-   if (0) {
-  debug_printf("optimizing %s...\n", LLVMGetValueName(func));
-   }
-
-   assert(gallivm->passmgr);
-
-   /* Apply optimizations to LLVM IR */
-   LLVMRunFunctionPassManager(gallivm->passmgr, func);
-
-   if (0) {
-  if (gallivm_debug & GALLIVM_DEBUG_IR) {
- /* Print the LLVM IR to stderr */
- lp_debug_dump_value(func);
- debug_printf("\n");
-  }
-   }
-}
-
-
-/**
  * Validate a function.
  */
 void
@@ -540,8 +514,6 @@ gallivm_verify_function(struct gallivm_state *gallivm,
}
 #endif
 
-   gallivm_optimize_function(gallivm, func);
-
if (gallivm_debug & GALLIVM_DEBUG_IR) {
   /* Print the LLVM IR to stderr */
   lp_debug_dump_value(func);
@@ -553,8 +525,27 @@ gallivm_verify_function(struct gallivm_state *gallivm,
 void
 gallivm_compile_module(struct gallivm_state *gallivm)
 {
+   LLVMValueRef func;
+
assert(!gallivm->compiled);
 
+   if (gallivm->builder) {
+  LLVMDisposeBuilder(gallivm->builder);
+  gallivm->builder = NULL;
+   }
+
+   /* Run optimization passes */
+   LLVMInitializeFunctionPassManager(gallivm->passmgr);
+   func = LLVMGetFirstFunction(gallivm->module);
+   while (func) {
+  if (0) {
+debug_printf("optimizing %s...\n", LLVMGetValueName(func));
+  }
+  LLVMRunFunctionPassManager(gallivm->passmgr, func);
+  func = LLVMGetNextFunction(func);
+   }
+   LLVMFinalizeFunctionPassManager(gallivm->passmgr);
+
/* Dump byte code to a file */
if (0) {
   LLVMWriteBitcodeToFile(gallivm->module, "llvmpipe.bc");
-- 
1.9.1

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


[Mesa-dev] [PATCH 12/12] gallivm: Remove lp_func_delete_body.

2014-05-13 Thread jfonseca
From: José Fonseca 

Not necessary, now that we will free the whole module (hence all
function bodies) immediately after compiling.
---
 src/gallium/auxiliary/gallivm/lp_bld_init.c   | 3 ---
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 8 
 src/gallium/auxiliary/gallivm/lp_bld_misc.h   | 4 
 3 files changed, 15 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c 
b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 36d1bc5..a39c1a3 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -605,8 +605,5 @@ gallivm_jit_function(struct gallivm_state *gallivm,
lp_profile(func, code);
 #endif
 
-   /* Free the function body to save memory */
-   lp_func_delete_body(func);
-
return jit_func;
 }
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp 
b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index 8825e54..d03680f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -117,14 +117,6 @@ lp_set_target_options(void)
 }
 
 
-extern "C" void
-lp_func_delete_body(LLVMValueRef FF)
-{
-   llvm::Function *func = llvm::unwrap(FF);
-   func->deleteBody();
-}
-
-
 extern "C"
 LLVMValueRef
 lp_build_load_volatile(LLVMBuilderRef B, LLVMValueRef PointerVal,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.h 
b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
index 847894b..64d2a04 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
@@ -46,10 +46,6 @@ extern void
 lp_set_target_options(void);
 
 
-extern void
-lp_func_delete_body(LLVMValueRef func);
-
-
 extern LLVMValueRef
 lp_build_load_volatile(LLVMBuilderRef B, LLVMValueRef PointerVal,
const char *Name);
-- 
1.9.1

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


[Mesa-dev] [PATCH 07/12] gallivm: One code memory pool with deferred free.

2014-05-13 Thread jfonseca
From: Frank Henigman 

Provide a JITMemoryManager derivative which puts all generated code into
one memory pool instead of creating a new one each time code is generated.
This saves significant memory per shader as the pool size is 512K and
a small shader occupies just several K.

This memory manager also defers freeing generated code until you tell
it to do so, making it possible to destroy the LLVM engine while keeping
the code, thus enabling future memory savings.

v2: Fix compilation errors with LLVM 3.4 (Jose)

Signed-off-by: José Fonseca 
---
 src/gallium/auxiliary/gallivm/lp_bld_init.c   |   4 +
 src/gallium/auxiliary/gallivm/lp_bld_init.h   |   1 +
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 273 +-
 src/gallium/auxiliary/gallivm/lp_bld_misc.h   |   6 +
 4 files changed, 283 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c 
b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index a3549c1..982d1db 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -212,12 +212,15 @@ free_gallivm_state(struct gallivm_state *gallivm)
if (!USE_GLOBAL_CONTEXT && gallivm->context)
   LLVMContextDispose(gallivm->context);
 
+   lp_free_generated_code(gallivm->code);
+
gallivm->engine = NULL;
gallivm->target = NULL;
gallivm->module = NULL;
gallivm->passmgr = NULL;
gallivm->context = NULL;
gallivm->builder = NULL;
+   gallivm->code = NULL;
 }
 
 
@@ -237,6 +240,7 @@ init_gallivm_engine(struct gallivm_state *gallivm)
   }
 
   ret = lp_build_create_jit_compiler_for_module(&gallivm->engine,
+&gallivm->code,
 gallivm->module,
 (unsigned) optlevel,
 USE_MCJIT,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h 
b/src/gallium/auxiliary/gallivm/lp_bld_init.h
index 68f4006..e405b8a 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h
@@ -44,6 +44,7 @@ struct gallivm_state
LLVMPassManagerRef passmgr;
LLVMContextRef context;
LLVMBuilderRef builder;
+   struct lp_generated_code *code;
unsigned compiled;
 };
 
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp 
b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index fe45940..8825e54 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -151,6 +151,261 @@ lp_set_store_alignment(LLVMValueRef Inst,
 }
 
 
+/*
+ * Delegating is tedious but the default manager class is hidden in an
+ * anonymous namespace in LLVM, so we cannot just derive from it to change
+ * its behavior.
+ */
+class DelegatingJITMemoryManager : public llvm::JITMemoryManager {
+
+   protected:
+  virtual llvm::JITMemoryManager *mgr() const = 0;
+
+   public:
+  /*
+   * From JITMemoryManager
+   */
+  virtual void setMemoryWritable() {
+ mgr()->setMemoryWritable();
+  }
+  virtual void setMemoryExecutable() {
+ mgr()->setMemoryExecutable();
+  }
+  virtual void setPoisonMemory(bool poison) {
+ mgr()->setPoisonMemory(poison);
+  }
+  virtual void AllocateGOT() {
+ mgr()->AllocateGOT();
+ /*
+  * isManagingGOT() is not virtual in base class so we can't delegate.
+  * Instead we mirror the value of HasGOT in our instance.
+  */
+ HasGOT = mgr()->isManagingGOT();
+  }
+  virtual uint8_t *getGOTBase() const {
+ return mgr()->getGOTBase();
+  }
+  virtual uint8_t *startFunctionBody(const llvm::Function *F,
+ uintptr_t &ActualSize) {
+ return mgr()->startFunctionBody(F, ActualSize);
+  }
+  virtual uint8_t *allocateStub(const llvm::GlobalValue *F,
+unsigned StubSize,
+unsigned Alignment) {
+ return mgr()->allocateStub(F, StubSize, Alignment);
+  }
+  virtual void endFunctionBody(const llvm::Function *F,
+   uint8_t *FunctionStart,
+   uint8_t *FunctionEnd) {
+ mgr()->endFunctionBody(F, FunctionStart, FunctionEnd);
+  }
+  virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) {
+ return mgr()->allocateSpace(Size, Alignment);
+  }
+  virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment) {
+ return mgr()->allocateGlobal(Size, Alignment);
+  }
+  virtual void deallocateFunctionBody(void *Body) {
+ mgr()->deallocateFunctionBody(Body);
+  }
+#if HAVE_LLVM < 0x0304
+  virtual uint8_t *startExceptionTable(const llvm::Function *F,
+   uintptr_t &ActualSize) {
+   

[Mesa-dev] [PATCH 02/12] configure: Require LLVM 3.1.

2014-05-13 Thread jfonseca
From: José Fonseca 

---
 configure.ac | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/configure.ac b/configure.ac
index 99a761a..b4a1606 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1624,6 +1624,12 @@ if test "x$enable_gallium_llvm" = xyes; then
 LLVM_VERSION_INT=`echo $LLVM_VERSION | sed -e 
's/\([[0-9]]\)\.\([[0-9]]\)/\10\2/g'`
 fi
 
+LLVM_REQUIRED_VERSION_MAJOR="3"
+LLVM_REQUIRED_VERSION_MINOR="1"
+if test "$LLVM_VERSION_INT" -lt 
"${LLVM_REQUIRED_VERSION_MAJOR}0${LLVM_REQUIRED_VERSION_MINOR}"; then
+AC_MSG_ERROR([LLVM 
$LLVM_REQUIRED_VERSION_MAJOR.$LLVM_REQUIRED_VERSION_MINOR or newer is required])
+fi
+
 LLVM_COMPONENTS="engine bitwriter"
 if $LLVM_CONFIG --components | grep -qw 'mcjit'; then
 LLVM_COMPONENTS="${LLVM_COMPONENTS} mcjit"
-- 
1.9.1

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


[Mesa-dev] [PATCH 03/12] gallivm, draw, llvmpipe: Remove support for versions of LLVM prior to 3.1.

2014-05-13 Thread jfonseca
From: José Fonseca 

Older versions haven't been tested probably don't work anyway.  But more
importantly, code supporting it is hindering further work.
---
 src/gallium/auxiliary/draw/draw_llvm.c|  48 --
 src/gallium/auxiliary/gallivm/lp_bld.h|   3 +
 src/gallium/auxiliary/gallivm/lp_bld_arit.c   |   2 -
 src/gallium/auxiliary/gallivm/lp_bld_conv.c   |   4 +-
 src/gallium/auxiliary/gallivm/lp_bld_debug.cpp|  75 +
 src/gallium/auxiliary/gallivm/lp_bld_init.c   |  52 +-
 src/gallium/auxiliary/gallivm/lp_bld_logic.c  | 189 --
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp |  96 ---
 src/gallium/auxiliary/gallivm/lp_bld_pack.c   |   8 -
 src/gallium/auxiliary/gallivm/lp_bld_sample.c |   9 --
 src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c |  10 --
 src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c |  18 +--
 src/gallium/auxiliary/gallivm/lp_bld_swizzle.c|  18 +--
 src/gallium/auxiliary/gallivm/lp_bld_type.c   |   8 -
 src/gallium/drivers/llvmpipe/lp_jit.c |  28 
 15 files changed, 20 insertions(+), 548 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_llvm.c 
b/src/gallium/auxiliary/draw/draw_llvm.c
index b9f8bb9..6a3e5b2 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -97,15 +97,6 @@ create_jit_dvbuffer_type(struct gallivm_state *gallivm,
dvbuffer_type = LLVMStructTypeInContext(gallivm->context, elem_types,
Elements(elem_types), 0);
 
-#if HAVE_LLVM < 0x0300
-   LLVMAddTypeName(gallivm->module, struct_name, dvbuffer_type);
-
-   /* Make sure the target's struct layout cache doesn't return
-* stale/invalid data.
-*/
-   LLVMInvalidateStructLayout(gallivm->target, dvbuffer_type);
-#endif
-
LP_CHECK_MEMBER_OFFSET(struct draw_vertex_buffer, map,
   target, dvbuffer_type,
   DRAW_JIT_DVBUFFER_MAP);
@@ -142,15 +133,6 @@ create_jit_texture_type(struct gallivm_state *gallivm, 
const char *struct_name)
texture_type = LLVMStructTypeInContext(gallivm->context, elem_types,
   Elements(elem_types), 0);
 
-#if HAVE_LLVM < 0x0300
-   LLVMAddTypeName(gallivm->module, struct_name, texture_type);
-
-   /* Make sure the target's struct layout cache doesn't return
-* stale/invalid data.
-*/
-   LLVMInvalidateStructLayout(gallivm->target, texture_type);
-#endif
-
LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, width,
   target, texture_type,
   DRAW_JIT_TEXTURE_WIDTH);
@@ -204,15 +186,6 @@ create_jit_sampler_type(struct gallivm_state *gallivm, 
const char *struct_name)
sampler_type = LLVMStructTypeInContext(gallivm->context, elem_types,
   Elements(elem_types), 0);
 
-#if HAVE_LLVM < 0x0300
-   LLVMAddTypeName(gallivm->module, struct_name, sampler_type);
-
-   /* Make sure the target's struct layout cache doesn't return
-* stale/invalid data.
-*/
-   LLVMInvalidateStructLayout(gallivm->target, sampler_type);
-#endif
-
LP_CHECK_MEMBER_OFFSET(struct draw_jit_sampler, min_lod,
   target, sampler_type,
   DRAW_JIT_SAMPLER_MIN_LOD);
@@ -259,12 +232,6 @@ create_jit_context_type(struct gallivm_state *gallivm,
  PIPE_MAX_SAMPLERS); /* samplers */
context_type = LLVMStructTypeInContext(gallivm->context, elem_types,
   Elements(elem_types), 0);
-#if HAVE_LLVM < 0x0300
-   LLVMAddTypeName(gallivm->module, struct_name, context_type);
-
-   LLVMInvalidateStructLayout(gallivm->target, context_type);
-#endif
-
LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, vs_constants,
   target, context_type, DRAW_JIT_CTX_CONSTANTS);
LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, num_vs_constants,
@@ -322,11 +289,6 @@ create_gs_jit_context_type(struct gallivm_state *gallivm,
 
context_type = LLVMStructTypeInContext(gallivm->context, elem_types,
   Elements(elem_types), 0);
-#if HAVE_LLVM < 0x0300
-   LLVMAddTypeName(gallivm->module, struct_name, context_type);
-
-   LLVMInvalidateStructLayout(gallivm->target, context_type);
-#endif
 
LP_CHECK_MEMBER_OFFSET(struct draw_gs_jit_context, constants,
   target, context_type, DRAW_GS_JIT_CTX_CONSTANTS);
@@ -390,11 +352,6 @@ create_jit_vertex_buffer_type(struct gallivm_state 
*gallivm,
 
vb_type = LLVMStructTypeInContext(gallivm->context, elem_types,
  Elements(elem_types), 0);
-#if HAVE_LLVM < 0x0300
-   LLVMAddTypeName(gallivm->module, struct_name, vb_type);
-
-   LLVMInvalidateStructLayout(gallivm->target, vb_type);
-#endif
 
LP_CHECK_MEMBER_OFFSET(struct pipe_vertex_buffer, stride,
  

[Mesa-dev] [PATCH 01/12] scons: Require LLVM 3.1

2014-05-13 Thread jfonseca
From: José Fonseca 

Support for prior versions will be removed in the following change.
---
 scons/llvm.py | 57 +
 1 file changed, 13 insertions(+), 44 deletions(-)

diff --git a/scons/llvm.py b/scons/llvm.py
index 134a072..cdfbe43 100644
--- a/scons/llvm.py
+++ b/scons/llvm.py
@@ -37,6 +37,9 @@ import SCons.Errors
 import SCons.Util
 
 
+required_llvm_version = '3.1'
+
+
 def generate(env):
 env['llvm'] = False
 
@@ -84,6 +87,9 @@ def generate(env):
 if llvm_version is None:
 print 'scons: could not determine the LLVM version from %s' % 
llvm_config
 return
+if llvm_version < 
distutils.version.LooseVersion(required_llvm_version):
+print 'scons: LLVM version %s found, but %s is required' % 
(llvm_version, required_llvm_version)
+return
 
 env.Prepend(CPPPATH = [os.path.join(llvm_dir, 'include')])
 env.AppendUnique(CPPDEFINES = [
@@ -104,8 +110,8 @@ def generate(env):
 'LLVMAnalysis', 'LLVMTarget', 'LLVMMC', 'LLVMCore',
 'LLVMSupport', 'LLVMRuntimeDyld', 'LLVMObject'
 ])
-elif llvm_version >= distutils.version.LooseVersion('3.0'):
-# 3.0
+else:
+# 3.1
 env.Prepend(LIBS = [
 'LLVMBitWriter', 'LLVMX86Disassembler', 'LLVMX86AsmParser',
 'LLVMX86CodeGen', 'LLVMX86Desc', 'LLVMSelectionDAG',
@@ -116,46 +122,6 @@ def generate(env):
 'LLVMAnalysis', 'LLVMTarget', 'LLVMMC', 'LLVMCore',
 'LLVMSupport'
 ])
-elif llvm_version >= distutils.version.LooseVersion('2.9'):
-# 2.9
-env.Prepend(LIBS = [
-'LLVMObject', 'LLVMMCJIT', 'LLVMMCDisassembler',
-'LLVMLinker', 'LLVMipo', 'LLVMInterpreter',
-'LLVMInstrumentation', 'LLVMJIT', 'LLVMExecutionEngine',
-'LLVMBitWriter', 'LLVMX86Disassembler', 'LLVMX86AsmParser',
-'LLVMMCParser', 'LLVMX86AsmPrinter', 'LLVMX86CodeGen',
-'LLVMSelectionDAG', 'LLVMX86Utils', 'LLVMX86Info', 
'LLVMAsmPrinter',
-'LLVMCodeGen', 'LLVMScalarOpts', 'LLVMInstCombine',
-'LLVMTransformUtils', 'LLVMipa', 'LLVMAsmParser',
-'LLVMArchive', 'LLVMBitReader', 'LLVMAnalysis', 'LLVMTarget',
-'LLVMCore', 'LLVMMC', 'LLVMSupport',
-])
-elif llvm_version >= distutils.version.LooseVersion('2.7'):
-# 2.7
-env.Prepend(LIBS = [
-'LLVMLinker', 'LLVMipo', 'LLVMInterpreter',
-'LLVMInstrumentation', 'LLVMJIT', 'LLVMExecutionEngine',
-'LLVMBitWriter', 'LLVMX86Disassembler', 'LLVMX86AsmParser',
-'LLVMMCParser', 'LLVMX86AsmPrinter', 'LLVMX86CodeGen',
-'LLVMSelectionDAG', 'LLVMX86Info', 'LLVMAsmPrinter',
-'LLVMCodeGen', 'LLVMScalarOpts', 'LLVMInstCombine',
-'LLVMTransformUtils', 'LLVMipa', 'LLVMAsmParser',
-'LLVMArchive', 'LLVMBitReader', 'LLVMAnalysis', 'LLVMTarget',
-'LLVMMC', 'LLVMCore', 'LLVMSupport', 'LLVMSystem',
-])
-else:
-# 2.6
-env.Prepend(LIBS = [
-'LLVMX86AsmParser', 'LLVMX86AsmPrinter', 'LLVMX86CodeGen',
-'LLVMX86Info', 'LLVMLinker', 'LLVMipo', 'LLVMInterpreter',
-'LLVMInstrumentation', 'LLVMJIT', 'LLVMExecutionEngine',
-'LLVMDebugger', 'LLVMBitWriter', 'LLVMAsmParser',
-'LLVMArchive', 'LLVMBitReader', 'LLVMSelectionDAG',
-'LLVMAsmPrinter', 'LLVMCodeGen', 'LLVMScalarOpts',
-'LLVMTransformUtils', 'LLVMipa', 'LLVMAnalysis',
-'LLVMTarget', 'LLVMMC', 'LLVMCore', 'LLVMSupport',
-'LLVMSystem',
-])
 env.Append(LIBS = [
 'imagehlp',
 'psapi',
@@ -180,6 +146,10 @@ def generate(env):
 llvm_version = env.backtick('llvm-config --version').rstrip()
 llvm_version = distutils.version.LooseVersion(llvm_version)
 
+if llvm_version < 
distutils.version.LooseVersion(required_llvm_version):
+print 'scons: LLVM version %s found, but %s is required' % 
(llvm_version, required_llvm_version)
+return
+
 try:
 # Treat --cppflags specially to prevent NDEBUG from disabling
 # assertion failures in debug builds.
@@ -197,8 +167,7 @@ def generate(env):
 
 components = ['engine', 'bitwriter', 'x86asmprinter']
 
-if llvm_version >= distutils.version.LooseVersion('3.1'):
-components.append('mcjit')
+components.append('mcjit')
 
 env.ParseConfig('llvm-config --libs ' + ' '.join(components))
 env.ParseConfig('llvm-config --ldflags')
-- 
1.9.1

___
me

[Mesa-dev] [PATCH 09/12] draw: Delete unneeded LLVM stuff earlier.

2014-05-13 Thread jfonseca
From: Frank Henigman 

Free up unneeded LLVM stuff immediately after generating vertex shader
code.  Saves about 500K per shader.

v2: Don't bother calling gallivm_free_function (Jose)

Signed-off-by: José Fonseca 
---
 src/gallium/auxiliary/draw/draw_llvm.c | 19 ---
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_llvm.c 
b/src/gallium/auxiliary/draw/draw_llvm.c
index 6a3e5b2..7ecc340 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -555,6 +555,8 @@ draw_llvm_create_variant(struct draw_llvm *llvm,
variant->jit_func_elts = (draw_jit_vert_func_elts)
  gallivm_jit_function(variant->gallivm, variant->function_elts);
 
+   gallivm_free_ir(variant->gallivm);
+
variant->shader = shader;
variant->list_item_global.base = variant;
variant->list_item_local.base = variant;
@@ -1960,16 +1962,6 @@ draw_llvm_destroy_variant(struct draw_llvm_variant 
*variant)
 {
struct draw_llvm *llvm = variant->llvm;
 
-   if (variant->function_elts) {
-  gallivm_free_function(variant->gallivm,
-variant->function_elts, variant->jit_func_elts);
-   }
-
-   if (variant->function) {
-  gallivm_free_function(variant->gallivm,
-variant->function, variant->jit_func);
-   }
-
gallivm_destroy(variant->gallivm);
 
remove_from_list(&variant->list_item_local);
@@ -2206,6 +2198,8 @@ draw_gs_llvm_create_variant(struct draw_llvm *llvm,
variant->jit_func = (draw_gs_jit_func)
  gallivm_jit_function(variant->gallivm, variant->function);
 
+   gallivm_free_ir(variant->gallivm);
+
variant->list_item_global.base = variant;
variant->list_item_local.base = variant;
/*variant->no = */shader->variants_created++;
@@ -2219,11 +2213,6 @@ draw_gs_llvm_destroy_variant(struct draw_gs_llvm_variant 
*variant)
 {
struct draw_llvm *llvm = variant->llvm;
 
-   if (variant->function) {
-  gallivm_free_function(variant->gallivm,
-variant->function, variant->jit_func);
-   }
-
gallivm_destroy(variant->gallivm);
 
remove_from_list(&variant->list_item_local);
-- 
1.9.1

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


[Mesa-dev] [PATCH 05/12] gallivm: Use LLVM global context.

2014-05-13 Thread jfonseca
From: José Fonseca 

I saw that LLVM internally uses its global context for some things, even
when we use our own.  Given ours is also global, might as well use
LLVM's.

However, sepearate contexts can still be enabled with a simple source
code modification, for when the need/benefit arises.
---
 src/gallium/auxiliary/gallivm/lp_bld_init.c | 40 -
 1 file changed, 17 insertions(+), 23 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c 
b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 6934a28..2d854e9 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -68,6 +68,16 @@
 void LLVMLinkInMCJIT();
 #endif
 
+/*
+ * LLVM has several global caches which pointing/derived from objects
+ * owned by the context, so if we freeing contexts causes
+ * memory leaks and false cache hits when these objects are destroyed.
+ *
+ * TODO: For thread safety on multi-threaded OpenGL we should use one LLVM
+ * context per thread, and put them in a pool when threads are destroyed.
+ */
+#define USE_GLOBAL_CONTEXT 1
+
 
 #ifdef DEBUG
 unsigned gallivm_debug = 0;
@@ -196,16 +206,12 @@ free_gallivm_state(struct gallivm_state *gallivm)
}
 #endif
 
-   /* Never free the LLVM context.
-*/
-#if 0
-   if (gallivm->context)
-  LLVMContextDispose(gallivm->context);
-#endif
-
if (gallivm->builder)
   LLVMDisposeBuilder(gallivm->builder);
 
+   if (!USE_GLOBAL_CONTEXT && gallivm->context)
+  LLVMContextDispose(gallivm->context);
+
gallivm->engine = NULL;
gallivm->target = NULL;
gallivm->module = NULL;
@@ -277,19 +283,6 @@ fail:
 
 
 /**
- * Singleton
- *
- * We must never free LLVM contexts, because LLVM has several global caches
- * which pointing/derived from objects owned by the context, causing false
- * memory leaks and false cache hits when these objects are destroyed.
- *
- * TODO: For thread safety on multi-threaded OpenGL we should use one LLVM
- * context per thread, and put them in a pool when threads are destroyed.
- */
-static LLVMContextRef gallivm_context = NULL;
-
-
-/**
  * Allocate gallivm LLVM objects.
  * \return  TRUE for success, FALSE for failure
  */
@@ -301,10 +294,11 @@ init_gallivm_state(struct gallivm_state *gallivm)
 
lp_build_init();
 
-   if (!gallivm_context) {
-  gallivm_context = LLVMContextCreate();
+   if (USE_GLOBAL_CONTEXT) {
+  gallivm->context = LLVMGetGlobalContext();
+   } else {
+  gallivm->context = LLVMContextCreate();
}
-   gallivm->context = gallivm_context;
if (!gallivm->context)
   goto fail;
 
-- 
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] gallivm: Support MCJIT on Windows.

2014-05-14 Thread jfonseca
From: José Fonseca 

It works fine, though it requires using ELF objects.

With this change there is nothing preventing us to switch exclusively
to MCJIT, everywhere.  It's still off though.
---
 scons/llvm.py | 8 +++-
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 9 +
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/scons/llvm.py b/scons/llvm.py
index cdfbe43..288a080 100644
--- a/scons/llvm.py
+++ b/scons/llvm.py
@@ -104,7 +104,7 @@ def generate(env):
 'LLVMBitWriter', 'LLVMX86Disassembler', 'LLVMX86AsmParser',
 'LLVMX86CodeGen', 'LLVMX86Desc', 'LLVMSelectionDAG',
 'LLVMAsmPrinter', 'LLVMMCParser', 'LLVMX86AsmPrinter',
-'LLVMX86Utils', 'LLVMX86Info', 'LLVMJIT',
+'LLVMX86Utils', 'LLVMX86Info', 'LLVMMCJIT', 'LLVMJIT',
 'LLVMExecutionEngine', 'LLVMCodeGen', 'LLVMScalarOpts',
 'LLVMInstCombine', 'LLVMTransformUtils', 'LLVMipa',
 'LLVMAnalysis', 'LLVMTarget', 'LLVMMC', 'LLVMCore',
@@ -116,7 +116,7 @@ def generate(env):
 'LLVMBitWriter', 'LLVMX86Disassembler', 'LLVMX86AsmParser',
 'LLVMX86CodeGen', 'LLVMX86Desc', 'LLVMSelectionDAG',
 'LLVMAsmPrinter', 'LLVMMCParser', 'LLVMX86AsmPrinter',
-'LLVMX86Utils', 'LLVMX86Info', 'LLVMJIT',
+'LLVMX86Utils', 'LLVMX86Info', 'LLVMMCJIT', 'LLVMJIT',
 'LLVMExecutionEngine', 'LLVMCodeGen', 'LLVMScalarOpts',
 'LLVMInstCombine', 'LLVMTransformUtils', 'LLVMipa',
 'LLVMAnalysis', 'LLVMTarget', 'LLVMMC', 'LLVMCore',
@@ -165,9 +165,7 @@ def generate(env):
 if '-fno-rtti' in cxxflags:
 env.Append(CXXFLAGS = ['-fno-rtti'])
 
-components = ['engine', 'bitwriter', 'x86asmprinter']
-
-components.append('mcjit')
+components = ['engine', 'mcjit', 'bitwriter', 'x86asmprinter']
 
 env.ParseConfig('llvm-config --libs ' + ' '.join(components))
 env.ParseConfig('llvm-config --ldflags')
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp 
b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index d03680f..4d63f9a 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -57,6 +57,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -452,6 +453,14 @@ 
lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
 
if (useMCJIT) {
builder.setUseMCJIT(true);
+#ifdef _WIN32
+   /*
+   * MCJIT works on Windows, but currently only through ELF object format.
+   */
+   std::string targetTriple = llvm::sys::getProcessTriple();
+   targetTriple.append("-elf");
+   unwrap(M)->setTargetTriple(targetTriple);
+#endif
}
 
llvm::SmallVector MAttrs;
-- 
1.9.1

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


[Mesa-dev] [PATCH 2/2] gallivm: Disable workaround for PR12833 on LLVM 3.2+.

2014-05-14 Thread jfonseca
From: José Fonseca 

Fixed upstream.
---
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp 
b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index 4d63f9a..ec54776 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -484,11 +484,11 @@ 
lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
builder.setJITMemoryManager(MM);
 
ExecutionEngine *JIT;
-#if 0
+#if HAVE_LLVM >= 0x0302
JIT = builder.create();
 #else
/*
-* Workaround http://llvm.org/bugs/show_bug.cgi?id=12833
+* Workaround http://llvm.org/PR12833
 */
StringRef MArch = "";
StringRef MCPU = "";
-- 
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] scons: Fix x86_64 build.

2014-05-22 Thread jfonseca
From: José Fonseca 

x86/common_x86.c is required also for x86_64 builds.
---
 src/mesa/SConscript | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/mesa/SConscript b/src/mesa/SConscript
index cd959be..f565786 100644
--- a/src/mesa/SConscript
+++ b/src/mesa/SConscript
@@ -392,6 +392,7 @@ if (env['gcc'] or env['clang']) and \
 'USE_X86_64_ASM',
 ])
 mesa_sources += [
+'x86/common_x86.c',
 'x86-64/x86-64.c',
 'x86-64/xform4.S',
 ]
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCH 2/2] mesa: Rely on USE_X86_64_ASM.

2014-05-22 Thread jfonseca
From: José Fonseca 

This fixes MinGW x64 builds.  We don't use assembly on any of the
Windows builds, to avoid divergence between MSVC and MinGW when testing.
---
 src/mesa/main/cpuinfo.c   | 2 +-
 src/mesa/main/cpuinfo.h   | 2 +-
 src/mesa/x86/common_x86.c | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/mesa/main/cpuinfo.c b/src/mesa/main/cpuinfo.c
index 73e295c..0755d6b 100644
--- a/src/mesa/main/cpuinfo.c
+++ b/src/mesa/main/cpuinfo.c
@@ -34,7 +34,7 @@
 void
 _mesa_get_cpu_features(void)
 {
-#if defined USE_X86_ASM || (defined __x86_64__ && !defined _MSC_VER)
+#if defined USE_X86_ASM || defined USE_X86_64_ASM
_mesa_get_x86_features();
 #endif
 }
diff --git a/src/mesa/main/cpuinfo.h b/src/mesa/main/cpuinfo.h
index fcd611e..57925e8 100644
--- a/src/mesa/main/cpuinfo.h
+++ b/src/mesa/main/cpuinfo.h
@@ -27,7 +27,7 @@
 #define CPUINFO_H
 
 
-#if defined USE_X86_ASM || (defined __x86_64__ && !defined _MSC_VER)
+#if defined USE_X86_ASM || defined USE_X86_64_ASM
 #include "x86/common_x86_asm.h"
 #endif
 
diff --git a/src/mesa/x86/common_x86.c b/src/mesa/x86/common_x86.c
index a55c48e..9c12339 100644
--- a/src/mesa/x86/common_x86.c
+++ b/src/mesa/x86/common_x86.c
@@ -47,7 +47,7 @@
 #include 
 #include 
 #endif
-#if defined(__x86_64__) && !defined(_MSC_VER)
+#if defined(USE_X86_64_ASM)
 #include 
 #endif
 
@@ -336,7 +336,7 @@ _mesa_get_x86_features(void)
}
 #endif
 
-#elif defined(__x86_64__) && !defined(_MSC_VER)
+#elif defined(USE_X86_64_ASM)
unsigned int uninitialized_var(eax), uninitialized_var(ebx),
 uninitialized_var(ecx), uninitialized_var(edx);
 
@@ -347,7 +347,7 @@ _mesa_get_x86_features(void)
 
if (ecx & bit_SSE4_1)
   _mesa_x86_cpu_features |= X86_FEATURE_SSE4_1;
-#endif /* USE_X86_ASM */
+#endif /* USE_X86_64_ASM */
 
(void) detection_debug;
 }
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCH] docs: Document how to replace Windows built-in OpenGL software rasterizer with llvmpipe.

2014-05-29 Thread jfonseca
From: José Fonseca 

Just happened to stumble across this registry key while debugging
something else.

This technique is much neater than trying to override opengl32.dll.

Also a few minors cleanups.
---
 docs/llvmpipe.html | 52 
 1 file changed, 40 insertions(+), 12 deletions(-)

diff --git a/docs/llvmpipe.html b/docs/llvmpipe.html
index 74f0c67..291527b 100644
--- a/docs/llvmpipe.html
+++ b/docs/llvmpipe.html
@@ -43,11 +43,7 @@ It's the fastest software rasterizer for Mesa.

 
 
-   LLVM: version 2.9 recommended; 2.6 or later required.
-   NOTE: LLVM 2.8 and earlier will not work on systems that support 
the
-   Intel AVX extensions (e.g. Sandybridge).  LLVM's code generator will
-   fail when trying to emit AVX instructions.  This was fixed in LLVM 2.9.
-   
+   LLVM: version 3.4 recommended; 3.1 or later required.

For Linux, on a recent Debian based distribution do:

@@ -101,13 +97,15 @@ but the rest of these instructions assume that scons is 
used.
 For Windows the procedure is similar except the target:
 
 
-  scons build=debug libgl-gdi
+  scons platform=windows build=debug libgl-gdi
 
 
 
 Using
 
-On Linux, building will create a drop-in alternative for libGL.so into
+Linux
+
+On Linux, building will create a drop-in alternative for libGL.so into
 
 
   build/foo/gallium/targets/libgl-xlib/libGL.so
@@ -117,15 +115,45 @@ or
   lib/gallium/libGL.so
 
 
-To use it set the LD_LIBRARY_PATH environment variable accordingly.
+To use it set the LD_LIBRARY_PATH environment variable accordingly.
+
+For performance evaluation pass build=release to scons, and use the 
corresponding
+lib directory without the "-debug" suffix.
+
 
-For performance evaluation pass debug=no to scons, and use the corresponding
-lib directory without the "-debug" suffix.
+Windows
 
-On Windows, building will create a drop-in alternative for opengl32.dll. To use
-it put it in the same directory as the application. It can also be used by
+
+On Windows, building will create
+build/windows-x86-debug/gallium/targets/libgl-gdi/opengl32.dll
+which is a drop-in alternative for system's opengl32.dll.  To use
+it put it in the same directory as your application.  It can also be used by
 replacing the native ICD driver, but it's quite an advanced usage, so if you
 need to ask, don't even try it.
+
+
+
+There is however an easy way to replace the OpenGL software renderer that comes
+with Microsoft Windows 7 (or later) with llvmpipe (that is, on systems without
+any OpenGL drivers):
+
+
+
+  copy build/windows-x86-debug/gallium/targets/libgl-gdi/opengl32.dll 
to C:\Windows\SysWOW64\mesadrv.dll
+  load this registry settings:
+  REGEDIT4
+
+; http://technet.microsoft.com/en-us/library/cc749368.aspx
+; 
http://www.msfn.org/board/topic/143241-portable-windows-7-build-from-winpe-30/page-5#entry942596
+[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows 
NT\CurrentVersion\OpenGLDrivers\MSOGL]
+"DLL"="mesadrv.dll"
+"DriverVersion"=dword:0001
+"Flags"=dword:0001
+"Version"=dword:0002
+
+  
+  Ditto for 64 bits drivers if you need them.
+
 
 
 Profiling
-- 
1.9.1

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


[Mesa-dev] [PATCH 2/2] mesa: Make glGetIntegerv(GL_*_ARRAY_SIZE) return GL_BGRA.

2014-06-01 Thread jfonseca
From: José Fonseca 

Same as b026b6bbfe3f15c8a7296ac107dc3d31f74e401e, but
COLOR_ARRAY_SIZE/SECONDARY_COLOR_ARRAY_SIZE.

Ideally we wouldn't munge the incoming state, so that we wouldn't need to
unmunge it back on glGet*.  But the array size state is copied and referred
in many places, many of which .  So just hack around on glGet* time, to
ensure there is no risk of introducing regressions elsewhere.

This bug causes problems to Apitrace, resulting in wrong traces.  See
https://github.com/apitrace/apitrace/issues/261 for details.

Tested with piglit arb_vertex_array_bgra-get, which was created for this
purpose.
---
 src/mesa/main/get.c  | 10 ++
 src/mesa/main/get_hash_params.py |  4 ++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 80a5839..267b5f2 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -847,6 +847,16 @@ find_custom_value(struct gl_context *ctx, const struct 
value_desc *d, union valu
   v->value_int = ctx->Array.VAO->IndexBufferObj->Name;
   break;
 
+   /* ARB_vertex_array_bgra */
+   case GL_COLOR_ARRAY_SIZE:
+  array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0];
+  v->value_int = array->Format == GL_BGRA ? GL_BGRA : array->Size;
+  break;
+   case GL_SECONDARY_COLOR_ARRAY_SIZE:
+  array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1];
+  v->value_int = array->Format == GL_BGRA ? GL_BGRA : array->Size;
+  break;
+
/* ARB_copy_buffer */
case GL_COPY_READ_BUFFER:
   v->value_int = ctx->CopyReadBuffer->Name;
diff --git a/src/mesa/main/get_hash_params.py b/src/mesa/main/get_hash_params.py
index d40fa07..c7a6e02 100644
--- a/src/mesa/main/get_hash_params.py
+++ b/src/mesa/main/get_hash_params.py
@@ -199,7 +199,7 @@ descriptor=[
   [ "NORMAL_ARRAY_TYPE", "ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_NORMAL].Type), 
NO_EXTRA" ],
   [ "NORMAL_ARRAY_STRIDE", 
"ARRAY_INT(VertexAttrib[VERT_ATTRIB_NORMAL].Stride), NO_EXTRA" ],
   [ "COLOR_ARRAY", "ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_COLOR0].Enabled), 
NO_EXTRA" ],
-  [ "COLOR_ARRAY_SIZE", "ARRAY_INT(VertexAttrib[VERT_ATTRIB_COLOR0].Size), 
NO_EXTRA" ],
+  [ "COLOR_ARRAY_SIZE", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
   [ "COLOR_ARRAY_TYPE", "ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_COLOR0].Type), 
NO_EXTRA" ],
   [ "COLOR_ARRAY_STRIDE", "ARRAY_INT(VertexAttrib[VERT_ATTRIB_COLOR0].Stride), 
NO_EXTRA" ],
   [ "TEXTURE_COORD_ARRAY", "LOC_CUSTOM, TYPE_BOOLEAN, offsetof(struct 
gl_client_array, Enabled), NO_EXTRA" ],
@@ -552,7 +552,7 @@ descriptor=[
   [ "SECONDARY_COLOR_ARRAY", 
"ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_COLOR1].Enabled), NO_EXTRA" ],
   [ "SECONDARY_COLOR_ARRAY_TYPE", 
"ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_COLOR1].Type), NO_EXTRA" ],
   [ "SECONDARY_COLOR_ARRAY_STRIDE", 
"ARRAY_INT(VertexAttrib[VERT_ATTRIB_COLOR1].Stride), NO_EXTRA" ],
-  [ "SECONDARY_COLOR_ARRAY_SIZE", 
"ARRAY_INT(VertexAttrib[VERT_ATTRIB_COLOR1].Size), NO_EXTRA" ],
+  [ "SECONDARY_COLOR_ARRAY_SIZE", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
 
 # GL_EXT_fog_coord
   [ "CURRENT_FOG_COORDINATE", 
"CONTEXT_FLOAT(Current.Attrib[VERT_ATTRIB_FOG][0]), extra_flush_current" ],
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCH 1/2] mesa/main: Make get_hash.c values constant.

2014-06-01 Thread jfonseca
From: José Fonseca 

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

diff --git a/src/mesa/main/get_hash_generator.py 
b/src/mesa/main/get_hash_generator.py
index 96bc495..b200d19 100644
--- a/src/mesa/main/get_hash_generator.py
+++ b/src/mesa/main/get_hash_generator.py
@@ -52,7 +52,7 @@ def print_header():
   (prime_factor, prime_step)
 
 def print_params(params):
-   print "static struct value_desc values[] = {"
+   print "static const struct value_desc values[] = {"
for p in params:
   print "{ %s, %s }," % (p[0], p[1])
 
-- 
2.0.0.rc2

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


[Mesa-dev] [PATCH] wgl: Disable CRT message boxes when Windows system error messages boxes are disabled.

2014-06-03 Thread jfonseca
From: José Fonseca 

At least on MSVC we statically link against the CRT, so we must disable
the CRT message boxes if we want to attended testing.

The messages are convenient when running manually, so let them be if the
system error message boxes are not disabled.
---
 src/gallium/auxiliary/util/u_debug.c| 32 +
 src/gallium/auxiliary/util/u_debug.h|  9 
 src/gallium/state_trackers/wgl/stw_device.c |  2 ++
 3 files changed, 43 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_debug.c 
b/src/gallium/auxiliary/util/u_debug.c
index dc840e8..d79f31e 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -46,6 +46,12 @@
 #include  /* CHAR_BIT */
 #include  /* isalnum */
 
+#ifdef _WIN32
+#include 
+#include 
+#endif
+
+
 void _debug_vprintf(const char *format, va_list ap)
 {
static char buf[4096] = {'\0'};
@@ -64,6 +70,32 @@ void _debug_vprintf(const char *format, va_list ap)
 }
 
 
+void
+debug_disable_error_message_boxes(void)
+{
+#ifdef _WIN32
+   /* When Windows' error message boxes are disabled for this process (as is
+* typically the case when running tests in an automated fashion) we disable
+* CRT message boxes too.
+*/
+   UINT uMode = SetErrorMode(0);
+   SetErrorMode(uMode);
+   if (uMode & SEM_FAILCRITICALERRORS) {
+  /* Disable assertion failure message box.
+   * http://msdn.microsoft.com/en-us/library/sas1dkb2.aspx
+   */
+  _set_error_mode(_OUT_TO_STDERR);
+#ifdef _MSC_VER
+  /* Disable abort message box.
+   * http://msdn.microsoft.com/en-us/library/e631wekh.aspx
+   */
+  _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
+#endif
+   }
+#endif /* _WIN32 */
+}
+
+
 #ifdef DEBUG
 void debug_print_blob( const char *name,
const void *blob,
diff --git a/src/gallium/auxiliary/util/u_debug.h 
b/src/gallium/auxiliary/util/u_debug.h
index 9c41421..badd5e2 100644
--- a/src/gallium/auxiliary/util/u_debug.h
+++ b/src/gallium/auxiliary/util/u_debug.h
@@ -139,6 +139,15 @@ void debug_print_format(const char *msg, unsigned fmt );
 
 
 /**
+ * Disable interactive error message boxes.
+ *
+ * Should be called as soon as possible for effectiveness.
+ */
+void
+debug_disable_error_message_boxes(void);
+
+
+/**
  * Hard-coded breakpoint.
  */
 #ifdef DEBUG
diff --git a/src/gallium/state_trackers/wgl/stw_device.c 
b/src/gallium/state_trackers/wgl/stw_device.c
index 8f2cf9c..025dbdc 100644
--- a/src/gallium/state_trackers/wgl/stw_device.c
+++ b/src/gallium/state_trackers/wgl/stw_device.c
@@ -69,6 +69,8 @@ stw_init(const struct stw_winsys *stw_winsys)
static struct stw_device stw_dev_storage;
struct pipe_screen *screen;
 
+   debug_disable_error_message_boxes();
+
debug_printf("%s\n", __FUNCTION__);

assert(!stw_dev);
-- 
1.9.1

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


[Mesa-dev] [PATCH 1/3] gallivm: Emit vector selects.

2013-04-20 Thread jfonseca
From: José Fonseca 

They are supported on LLVM 3.1, at least on x86. (I haven't tested on PPC
though.)

Actually lp_build_linear_mip_levels() already has been emitting them for
some time.

This avoids intrinsics, which tend to be an obstacle for certain
optimization passes.
---
 src/gallium/auxiliary/gallivm/lp_bld_logic.c |   14 ++
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.c 
b/src/gallium/auxiliary/gallivm/lp_bld_logic.c
index f56b61b..cdb7e0a 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_logic.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.c
@@ -458,20 +458,10 @@ lp_build_select(struct lp_build_context *bld,
   mask = LLVMBuildTrunc(builder, mask, LLVMInt1TypeInContext(lc), "");
   res = LLVMBuildSelect(builder, mask, a, b, "");
}
-   else if (0) {
+   else if (HAVE_LLVM >= 0x301) {
   /* Generate a vector select.
*
-   * XXX: Using vector selects would avoid emitting intrinsics, but they 
aren't
-   * properly supported yet.
-   *
-   * LLVM 3.0 includes experimental support provided the -promote-elements
-   * options is passed to LLVM's command line (e.g., via
-   * llvm::cl::ParseCommandLineOptions), but resulting code quality is much
-   * worse, probably because some optimization passes don't know how to
-   * handle vector selects.
-   *
-   * See also:
-   * - http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/043659.html
+   * Only supported on LLVM 3.1 onwards
*/
 
   /* Convert the mask to a vector of booleans.
-- 
1.7.9.5

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


[Mesa-dev] [PATCH 2/3] gallivm: Disable LLVM 2.7 workaround on other versions.

2013-04-20 Thread jfonseca
From: José Fonseca 

2.7 was a particularly trouble ridden released.

Furthermore, the bug no longer can be reproduced ever since the
first_level state was taken in account.
---
 src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c 
b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
index ced2103..beefdae 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
@@ -1149,11 +1149,10 @@ lp_build_sample_common(struct lp_build_sample_context 
*bld,
   /* fall-through */
case PIPE_TEX_MIPFILTER_NONE:
   /* always use mip level 0 */
-  if (target == PIPE_TEXTURE_CUBE) {
+  if (HAVE_LLVM == 0x0207 && target == PIPE_TEXTURE_CUBE) {
  /* XXX this is a work-around for an apparent bug in LLVM 2.7.
   * We should be able to set ilevel0 = const(0) but that causes
   * bad x86 code to be emitted.
-  * XXX should probably disable that on other llvm versions.
   */
  assert(*lod_ipart);
  lp_build_nearest_mip_level(bld, texture_index, *lod_ipart, ilevel0);
-- 
1.7.9.5

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


[Mesa-dev] [PATCH 3/3] llvmpipe: Ignore depth-stencil state if format has no depth/stencil.

2013-04-20 Thread jfonseca
From: José Fonseca 

Prevents assertion failures inside the driver for such state combinations.
---
 src/gallium/drivers/llvmpipe/lp_state_fs.c |   14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c 
b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index 8712885..1a9a194 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -2478,12 +2478,18 @@ make_variant_key(struct llvmpipe_context *lp,
memset(key, 0, shader->variant_key_size);
 
if (lp->framebuffer.zsbuf) {
-  if (lp->depth_stencil->depth.enabled) {
- key->zsbuf_format = lp->framebuffer.zsbuf->format;
+  enum pipe_format zsbuf_format = lp->framebuffer.zsbuf->format;
+  const struct util_format_description *zsbuf_desc =
+ util_format_description(zsbuf_format);
+
+  if (lp->depth_stencil->depth.enabled &&
+  util_format_has_depth(zsbuf_desc)) {
+ key->zsbuf_format = zsbuf_format;
  memcpy(&key->depth, &lp->depth_stencil->depth, sizeof key->depth);
   }
-  if (lp->depth_stencil->stencil[0].enabled) {
- key->zsbuf_format = lp->framebuffer.zsbuf->format;
+  if (lp->depth_stencil->stencil[0].enabled &&
+  util_format_has_stencil(zsbuf_desc)) {
+ key->zsbuf_format = zsbuf_format;
  memcpy(&key->stencil, &lp->depth_stencil->stencil, sizeof 
key->stencil);
   }
}
-- 
1.7.9.5

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


[Mesa-dev] [PATCH] llvmpipe: Don't support Z32_FLOAT_S8X24_UINT texture sampling support either.

2013-04-20 Thread jfonseca
From: José Fonseca 

Because we don't support, and the u_format fallback doesn't work for
zs formats.
---
 src/gallium/drivers/llvmpipe/lp_screen.c |   10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index 5535f85..667ade1 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -361,6 +361,12 @@ llvmpipe_is_format_supported( struct pipe_screen *_screen,
  return FALSE;
}
 
+   /* TODO: Support Z32_FLOAT_S8X24_UINT. See lp_bld_depth.c. */
+   if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS &&
+   format_desc->block.bits > 32) {
+  return FALSE;
+   }
+
if (bind & PIPE_BIND_DEPTH_STENCIL) {
   if (format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
  return FALSE;
@@ -368,10 +374,6 @@ llvmpipe_is_format_supported( struct pipe_screen *_screen,
   if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
  return FALSE;
 
-  /* TODO: Support Z32_FLOAT_S8X24_UINT. See lp_bld_depth.c. */
-  if (format_desc->block.bits > 32)
- return FALSE;
-
   /* TODO: Support stencil-only formats */
   if (format_desc->swizzle[0] == UTIL_FORMAT_SWIZZLE_NONE) {
  return FALSE;
-- 
1.7.9.5

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


[Mesa-dev] [PATCH 1/2] gallium: Add a new clip_halfz rasterizer state.

2013-04-20 Thread jfonseca
From: José Fonseca 

gl_rasterization_rules lumps too many different flags.
---
 src/gallium/auxiliary/draw/draw_context.c  |1 +
 src/gallium/auxiliary/draw/draw_llvm.c |2 +-
 src/gallium/auxiliary/draw/draw_pt.h   |2 +-
 .../auxiliary/draw/draw_pt_fetch_shade_pipeline.c  |9 +++--
 .../draw/draw_pt_fetch_shade_pipeline_llvm.c   |9 +++--
 src/gallium/auxiliary/draw/draw_pt_post_vs.c   |8 
 src/gallium/docs/source/cso/rasterizer.rst |4 
 src/gallium/include/pipe/p_state.h |6 ++
 8 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_context.c 
b/src/gallium/auxiliary/draw/draw_context.c
index 0f98021..5272951 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -712,6 +712,7 @@ draw_get_rasterizer_no_cull( struct draw_context *draw,
   rast.flatshade = flatshade;
   rast.front_ccw = 1;
   rast.gl_rasterization_rules = draw->rasterizer->gl_rasterization_rules;
+  rast.clip_halfz = draw->rasterizer->clip_halfz;
 
   draw->rasterizer_no_cull[scissor][flatshade] =
  pipe->create_rasterizer_state(pipe, &rast);
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c 
b/src/gallium/auxiliary/draw/draw_llvm.c
index e0c0705..e1c08c6 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -1669,7 +1669,7 @@ draw_llvm_make_variant_key(struct draw_llvm *llvm, char 
*store)
key->clip_z = llvm->draw->clip_z;
key->clip_user = llvm->draw->clip_user;
key->bypass_viewport = llvm->draw->identity_viewport;
-   key->clip_halfz = !llvm->draw->rasterizer->gl_rasterization_rules;
+   key->clip_halfz = llvm->draw->rasterizer->clip_halfz;
key->need_edgeflags = (llvm->draw->vs.edgeflag_output ? TRUE : FALSE);
key->ucp_enable = llvm->draw->rasterizer->clip_plane_enable;
key->has_gs = llvm->draw->gs.geometry_shader != NULL;
diff --git a/src/gallium/auxiliary/draw/draw_pt.h 
b/src/gallium/auxiliary/draw/draw_pt.h
index 764d311..dca8368 100644
--- a/src/gallium/auxiliary/draw/draw_pt.h
+++ b/src/gallium/auxiliary/draw/draw_pt.h
@@ -233,7 +233,7 @@ void draw_pt_post_vs_prepare( struct pt_post_vs *pvs,
  boolean clip_user,
   boolean guard_band,
  boolean bypass_viewport,
- boolean opengl,
+  boolean clip_halfz,
  boolean need_edgeflags );
 
 struct pt_post_vs *draw_pt_post_vs_create( struct draw_context *draw );
diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c 
b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
index e17f161..8e48f46 100644
--- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
+++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
@@ -105,17 +105,14 @@ static void fetch_pipeline_prepare( struct 
draw_pt_middle_end *middle,
   vs->info.num_inputs,
   fpme->vertex_size,
   instance_id_index );
-   /* XXX: it's not really gl rasterization rules we care about here,
-* but gl vs dx9 clip spaces.
-*/
draw_pt_post_vs_prepare( fpme->post_vs,
draw->clip_xy,
draw->clip_z,
draw->clip_user,
 draw->guard_band_xy,
-   draw->identity_viewport,
-   (boolean)draw->rasterizer->gl_rasterization_rules,
-   (draw->vs.edgeflag_output ? TRUE : FALSE) );
+draw->identity_viewport,
+draw->rasterizer->clip_halfz,
+(draw->vs.edgeflag_output ? TRUE : FALSE) );
 
draw_pt_so_emit_prepare( fpme->so_emit, FALSE );
 
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 d312dc4..4dff4f8 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
@@ -156,17 +156,14 @@ llvm_middle_end_prepare( struct draw_pt_middle_end 
*middle,
fpme->vertex_size = sizeof(struct vertex_header) + nr * 4 * sizeof(float);
 
 
-   /* XXX: it's not really gl rasterization rules we care about here,
-* but gl vs dx9 clip spaces.
-*/
draw_pt_post_vs_prepare( fpme->post_vs,
draw->clip_xy,
draw->clip_z,
draw->clip_user,
 draw->guard_band_xy,
-   draw->identity_viewport,
-   (boolean)draw->rasterizer->gl_rasterization_rules,
-   (draw->vs.edgeflag_ou

[Mesa-dev] [PATCH 1/2] gallium: Add a new clip_halfz rasterizer state.

2013-04-20 Thread jfonseca
From: José Fonseca 

gl_rasterization_rules lumps too many different flags.
---
 src/gallium/auxiliary/draw/draw_context.c  |1 +
 src/gallium/auxiliary/draw/draw_llvm.c |2 +-
 src/gallium/auxiliary/draw/draw_pt.h   |2 +-
 .../auxiliary/draw/draw_pt_fetch_shade_pipeline.c  |9 +++--
 .../draw/draw_pt_fetch_shade_pipeline_llvm.c   |9 +++--
 src/gallium/auxiliary/draw/draw_pt_post_vs.c   |8 
 src/gallium/docs/source/cso/rasterizer.rst |4 
 src/gallium/include/pipe/p_state.h |6 ++
 8 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_context.c 
b/src/gallium/auxiliary/draw/draw_context.c
index 0f98021..5272951 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -712,6 +712,7 @@ draw_get_rasterizer_no_cull( struct draw_context *draw,
   rast.flatshade = flatshade;
   rast.front_ccw = 1;
   rast.gl_rasterization_rules = draw->rasterizer->gl_rasterization_rules;
+  rast.clip_halfz = draw->rasterizer->clip_halfz;
 
   draw->rasterizer_no_cull[scissor][flatshade] =
  pipe->create_rasterizer_state(pipe, &rast);
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c 
b/src/gallium/auxiliary/draw/draw_llvm.c
index e0c0705..e1c08c6 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -1669,7 +1669,7 @@ draw_llvm_make_variant_key(struct draw_llvm *llvm, char 
*store)
key->clip_z = llvm->draw->clip_z;
key->clip_user = llvm->draw->clip_user;
key->bypass_viewport = llvm->draw->identity_viewport;
-   key->clip_halfz = !llvm->draw->rasterizer->gl_rasterization_rules;
+   key->clip_halfz = llvm->draw->rasterizer->clip_halfz;
key->need_edgeflags = (llvm->draw->vs.edgeflag_output ? TRUE : FALSE);
key->ucp_enable = llvm->draw->rasterizer->clip_plane_enable;
key->has_gs = llvm->draw->gs.geometry_shader != NULL;
diff --git a/src/gallium/auxiliary/draw/draw_pt.h 
b/src/gallium/auxiliary/draw/draw_pt.h
index 764d311..dca8368 100644
--- a/src/gallium/auxiliary/draw/draw_pt.h
+++ b/src/gallium/auxiliary/draw/draw_pt.h
@@ -233,7 +233,7 @@ void draw_pt_post_vs_prepare( struct pt_post_vs *pvs,
  boolean clip_user,
   boolean guard_band,
  boolean bypass_viewport,
- boolean opengl,
+  boolean clip_halfz,
  boolean need_edgeflags );
 
 struct pt_post_vs *draw_pt_post_vs_create( struct draw_context *draw );
diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c 
b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
index e17f161..8e48f46 100644
--- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
+++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
@@ -105,17 +105,14 @@ static void fetch_pipeline_prepare( struct 
draw_pt_middle_end *middle,
   vs->info.num_inputs,
   fpme->vertex_size,
   instance_id_index );
-   /* XXX: it's not really gl rasterization rules we care about here,
-* but gl vs dx9 clip spaces.
-*/
draw_pt_post_vs_prepare( fpme->post_vs,
draw->clip_xy,
draw->clip_z,
draw->clip_user,
 draw->guard_band_xy,
-   draw->identity_viewport,
-   (boolean)draw->rasterizer->gl_rasterization_rules,
-   (draw->vs.edgeflag_output ? TRUE : FALSE) );
+draw->identity_viewport,
+draw->rasterizer->clip_halfz,
+(draw->vs.edgeflag_output ? TRUE : FALSE) );
 
draw_pt_so_emit_prepare( fpme->so_emit, FALSE );
 
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 d312dc4..4dff4f8 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
@@ -156,17 +156,14 @@ llvm_middle_end_prepare( struct draw_pt_middle_end 
*middle,
fpme->vertex_size = sizeof(struct vertex_header) + nr * 4 * sizeof(float);
 
 
-   /* XXX: it's not really gl rasterization rules we care about here,
-* but gl vs dx9 clip spaces.
-*/
draw_pt_post_vs_prepare( fpme->post_vs,
draw->clip_xy,
draw->clip_z,
draw->clip_user,
 draw->guard_band_xy,
-   draw->identity_viewport,
-   (boolean)draw->rasterizer->gl_rasterization_rules,
-   (draw->vs.edgeflag_ou

[Mesa-dev] [PATCH] gallivm: Fix assignment of unsigned values to OUT register.

2013-04-22 Thread jfonseca
From: José Fonseca 

TEMP is not the only register file that accept unsigned. OUT too.

Actually, what determines the appropriate type of the destination value is
not the opcode, but rather the register.

Also cleanup/simplify code.  Add a few more asserts, but also make
code more robust by handling graceful if assert fails.

This fixes segfault / assertion in the included vert-uadd.sh graw shader.
---
 src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c   |  127 -
 src/gallium/tests/graw/vertex-shader/vert-uadd.sh |9 ++
 2 files changed, 59 insertions(+), 77 deletions(-)
 create mode 100755 src/gallium/tests/graw/vertex-shader/vert-uadd.sh

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c 
b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
index c48c6e9..467d395 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
@@ -569,7 +569,7 @@ static void lp_exec_default(struct lp_exec_mask *mask,
 }
 
 
-/* stores val into an address pointed to by dst.
+/* stores val into an address pointed to by dst_ptr.
  * mask->exec_mask is used to figure out which bits of val
  * should be stored into the address
  * (0 means don't store this bit, 1 means do store).
@@ -578,10 +578,14 @@ static void lp_exec_mask_store(struct lp_exec_mask *mask,
struct lp_build_context *bld_store,
LLVMValueRef pred,
LLVMValueRef val,
-   LLVMValueRef dst)
+   LLVMValueRef dst_ptr)
 {
LLVMBuilderRef builder = mask->bld->gallivm->builder;
 
+   assert(lp_check_value(bld_store->type, val));
+   assert(LLVMGetTypeKind(LLVMTypeOf(dst_ptr)) == LLVMPointerTypeKind);
+   assert(LLVMGetElementType(LLVMTypeOf(dst_ptr)) == LLVMTypeOf(val));
+
/* Mix the predicate and execution mask */
if (mask->has_mask) {
   if (pred) {
@@ -592,16 +596,13 @@ static void lp_exec_mask_store(struct lp_exec_mask *mask,
}
 
if (pred) {
-  LLVMValueRef real_val, dst_val;
-
-  dst_val = LLVMBuildLoad(builder, dst, "");
-  real_val = lp_build_select(bld_store,
- pred,
- val, dst_val);
+  LLVMValueRef res, dst;
 
-  LLVMBuildStore(builder, real_val, dst);
+  dst = LLVMBuildLoad(builder, dst_ptr, "");
+  res = lp_build_select(bld_store, pred, val, dst);
+  LLVMBuildStore(builder, res, dst_ptr);
} else
-  LLVMBuildStore(builder, val, dst);
+  LLVMBuildStore(builder, val, dst_ptr);
 }
 
 static void lp_exec_mask_call(struct lp_exec_mask *mask,
@@ -1312,54 +1313,38 @@ emit_store_chan(
LLVMValueRef value)
 {
struct lp_build_tgsi_soa_context * bld = lp_soa_context(bld_base);
-   struct gallivm_state *gallivm = bld->bld_base.base.gallivm;
+   struct gallivm_state *gallivm = bld_base->base.gallivm;
LLVMBuilderRef builder = gallivm->builder;
const struct tgsi_full_dst_register *reg = &inst->Dst[index];
+   struct lp_build_context *float_bld = &bld_base->base;
+   struct lp_build_context *int_bld = &bld_base->int_bld;
struct lp_build_context *uint_bld = &bld_base->uint_bld;
LLVMValueRef indirect_index = NULL;
-   struct lp_build_context *bld_store;
enum tgsi_opcode_type dtype = 
tgsi_opcode_infer_dst_type(inst->Instruction.Opcode);
 
-   switch (dtype) {
-   default:
-   case TGSI_TYPE_FLOAT:
-   case TGSI_TYPE_UNTYPED:
-  bld_store = &bld_base->base;
-  break;
-   case TGSI_TYPE_UNSIGNED:
-  bld_store = &bld_base->uint_bld;
-  break;
-   case TGSI_TYPE_SIGNED:
-  bld_store = &bld_base->int_bld;
-  break;
-   case TGSI_TYPE_DOUBLE:
-   case TGSI_TYPE_VOID:
-  assert(0);
-  bld_store = NULL;
-  break;
-   }
-
-   /* If the destination is untyped then the source can be anything,
-* but LLVM won't like if the types don't match so lets cast
-* to the correct destination type as expected by LLVM. */
-   if (dtype == TGSI_TYPE_UNTYPED &&
-   !lp_check_vec_type(bld_store->type, LLVMTypeOf(value))) {
-  value = LLVMBuildBitCast(builder, value, bld_store->vec_type,
-   "src_casted");
-   }
-
+   /*
+* Apply saturation.
+*
+* It is always assumed to be float.
+*/
switch( inst->Instruction.Saturate ) {
case TGSI_SAT_NONE:
   break;
 
case TGSI_SAT_ZERO_ONE:
-  value = lp_build_max(&bld->bld_base.base, value, 
bld->bld_base.base.zero);
-  value = lp_build_min(&bld->bld_base.base, value, bld->bld_base.base.one);
+  assert(dtype == TGSI_TYPE_FLOAT ||
+ dtype == TGSI_TYPE_UNTYPED);
+  value = LLVMBuildBitCast(builder, value, float_bld->vec_type, "");
+  value = lp_build_max(float_bld, value, float_bld->zero);
+  value = lp_build_min(float_bld, value, float_bld->one);
   break;
 
case TGSI_SAT_MINUS_PLUS_ONE:
-  value = lp_build_max(&bld->bld_base.ba

[Mesa-dev] [PATCH] winsys/sw/xlib: Prevent shared memory segment leakage.

2013-04-24 Thread jfonseca
From: José Fonseca 

Running piglit with was causing all sort of weird stuff happening to my
desktop (Chromium webpages become blank, Qt Creator flickered, etc).  I
tracked this down to shared memory segment leakage when GL is not shutdown
properly. The segments can be seen running `ipcs` and looking for
nattch==0.

This changes fixes this by calling shmctl(IPC_RMID) soon after creation
(which does not remove the segment immediately, but simply marks it for
removal when no more processes are attached).

src/mesa/drivers/x11/xm_buffer.c also does something similar, albeit
slightly later in time -- after XShmCreateImage() call --, but calling
shmctl(IPC_RMID) before XShmCreateImage() seems to work equally well,
with fewer chances of leaking the shared memory segment.

NOTE: This is a candidate for stable branches.
---
 src/gallium/winsys/sw/xlib/xlib_sw_winsys.c |   11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c 
b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
index 3aef8da..584fbee 100644
--- a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
+++ b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
@@ -131,8 +131,13 @@ alloc_shm(struct xlib_displaytarget *buf, unsigned size)
}
 
shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0);
+
+   /* Mark the segment to be destroyed, so that it is automatically destroyed
+* when this process dies.
+*/
+   shmctl(shminfo->shmid, IPC_RMID, 0);
+
if (shminfo->shmaddr == (char *) -1) {
-  shmctl(shminfo->shmid, IPC_RMID, 0);
   return NULL;
}
 
@@ -165,6 +170,8 @@ alloc_shm_ximage(struct xlib_displaytarget *xlib_dt,
   &xlib_dt->shminfo,
   width, height);
if (xlib_dt->tempImage == NULL) {
+
+  debug_printf("XShmCreateImage failed\n");
   xlib_dt->shm = False;
   return;
}
@@ -177,6 +184,7 @@ alloc_shm_ximage(struct xlib_displaytarget *xlib_dt,
XSync(xlib_dt->display, False);
 
if (XErrorFlag) {
+  debug_printf("XErrorFlag set\n");
   /* we are on a remote display, this error is normal, don't print it */
   XFlush(xlib_dt->display);
   XErrorFlag = 0;
@@ -251,7 +259,6 @@ xlib_displaytarget_destroy(struct sw_winsys *ws,
if (xlib_dt->data) {
   if (xlib_dt->shminfo.shmid >= 0) {
  shmdt(xlib_dt->shminfo.shmaddr);
- shmctl(xlib_dt->shminfo.shmid, IPC_RMID, 0);
  
  xlib_dt->shminfo.shmid = -1;
  xlib_dt->shminfo.shmaddr = (char *) -1;
-- 
1.7.10.4

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


  1   2   3   >