Mesa (master): glsl_to_tgsi: remove unnecessary dead code elimination pass

2014-05-13 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 4e974a9cf323d774bfcbdd44d5cb1f7bf6391964
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=4e974a9cf323d774bfcbdd44d5cb1f7bf6391964

Author: Bryan Cain bryanca...@gmail.com
Date:   Mon May  5 22:23:38 2014 -0500

glsl_to_tgsi: remove unnecessary dead code elimination pass

With the more advanced dead code elimination pass already being run,
eliminate_dead_code was making no difference in instruction count, and had
an undesirable O(n^2) runtime. So remove it and rename
eliminate_dead_code_advanced to eliminate_dead_code.

Reviewed-by: Marek Olšák marek.olsak at amd.com

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   50 +++-
 1 file changed, 5 insertions(+), 45 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index bdee1f4..f5da5ee 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -459,8 +459,7 @@ public:
int get_last_temp_write(int index);
 
void copy_propagate(void);
-   void eliminate_dead_code(void);
-   int eliminate_dead_code_advanced(void);
+   int eliminate_dead_code(void);
void merge_registers(void);
void renumber_registers(void);
 
@@ -3672,7 +3671,8 @@ glsl_to_tgsi_visitor::copy_propagate(void)
 }
 
 /*
- * Tracks available PROGRAM_TEMPORARY registers for dead code elimination.
+ * On a basic block basis, tracks available PROGRAM_TEMPORARY registers for 
dead
+ * code elimination.
  *
  * The glsl_to_tgsi_visitor lazily produces code assuming that this pass
  * will occur.  As an example, a TXP production after copy propagation but 
@@ -3685,48 +3685,9 @@ glsl_to_tgsi_visitor::copy_propagate(void)
  * and after this pass:
  *
  * 0: TXP TEMP[2], INPUT[4].xyyw, texture[0], 2D;
- * 
- * FIXME: assumes that all functions are inlined (no support for BGNSUB/ENDSUB)
- * FIXME: doesn't eliminate all dead code inside of loops; it steps around them
- */
-void
-glsl_to_tgsi_visitor::eliminate_dead_code(void)
-{
-   int i;
-   
-   for (i=0; i  this-next_temp; i++) {
-  int last_read = get_last_temp_read(i);
-  int j = 0;
-  
-  foreach_list_safe(node, this-instructions) {
- glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *) node;
-
- if (inst-dst.file == PROGRAM_TEMPORARY  inst-dst.index == i 
- j  last_read)
- {
-inst-remove();
-delete inst;
- }
- 
- j++;
-  }
-   }
-}
-
-/*
- * On a basic block basis, tracks available PROGRAM_TEMPORARY registers for 
dead
- * code elimination.  This is less primitive than eliminate_dead_code(), as it
- * is per-channel and can detect consecutive writes without a read between them
- * as dead code.  However, there is some dead code that can be eliminated by 
- * eliminate_dead_code() but not this function - for example, this function 
- * cannot eliminate an instruction writing to a register that is never read and
- * is the only instruction writing to that register.
- *
- * The glsl_to_tgsi_visitor lazily produces code assuming that this pass
- * will occur.
  */
 int
-glsl_to_tgsi_visitor::eliminate_dead_code_advanced(void)
+glsl_to_tgsi_visitor::eliminate_dead_code(void)
 {
glsl_to_tgsi_instruction **writes = rzalloc_array(mem_ctx,
  glsl_to_tgsi_instruction 
*,
@@ -5270,9 +5231,8 @@ get_mesa_program(struct gl_context *ctx,
/* Perform optimizations on the instructions in the glsl_to_tgsi_visitor. */
v-simplify_cmp();
v-copy_propagate();
-   while (v-eliminate_dead_code_advanced());
+   while (v-eliminate_dead_code());
 
-   v-eliminate_dead_code();
v-merge_registers();
v-renumber_registers();


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


Mesa (master): nv50: initialize kick_notify callback in nv50_create

2013-05-07 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 14a0bb81fef164949aeb2ec2bcfe14fee4627eeb
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=14a0bb81fef164949aeb2ec2bcfe14fee4627eeb

Author: Bryan Cain bryanca...@gmail.com
Date:   Tue May  7 16:57:17 2013 -0500

nv50: initialize kick_notify callback in nv50_create

Fixes infinite loop on startup in Portal and Left 4 Dead 2.

NOTE: This is a candidate for the 9.0 and 9.1 branches.

---

 src/gallium/drivers/nv50/nv50_context.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/src/gallium/drivers/nv50/nv50_context.c 
b/src/gallium/drivers/nv50/nv50_context.c
index 16697a0..5781c4b 100644
--- a/src/gallium/drivers/nv50/nv50_context.c
+++ b/src/gallium/drivers/nv50/nv50_context.c
@@ -242,6 +242,7 @@ nv50_create(struct pipe_screen *pscreen, void *priv)
   screen-cur_ctx = nv50;
   nouveau_pushbuf_bufctx(screen-base.pushbuf, nv50-bufctx);
}
+   nv50-base.pushbuf-kick_notify = nv50_default_kick_notify;
 
nv50_init_query_functions(nv50);
nv50_init_surface_functions(nv50);

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


Mesa (master): glsl_to_tgsi: remove bad assertion

2012-01-07 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: c4529d10bed098b8d3d694f2a333f9afabbabbf9
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c4529d10bed098b8d3d694f2a333f9afabbabbf9

Author: Bryan Cain bryanca...@gmail.com
Date:   Sat Jan  7 14:54:49 2012 -0600

glsl_to_tgsi: remove bad assertion

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 73d956e..ddd5366 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1402,8 +1402,7 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
   }
   break;
case ir_unop_neg:
-  assert(result_dst.type == GLSL_TYPE_FLOAT || result_dst.type == 
GLSL_TYPE_INT);
-  if (result_dst.type == GLSL_TYPE_INT)
+  if (result_dst.type == GLSL_TYPE_INT || result_dst.type == 
GLSL_TYPE_UINT)
  emit(ir, TGSI_OPCODE_INEG, result_dst, op[0]);
   else {
  op[0].negate = ~op[0].negate;

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


Mesa (master): glsl_to_tgsi: fix emission of boolean constants

2012-01-07 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 673535f6071e512b18ac6da622e15bdc45ebf0a0
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=673535f6071e512b18ac6da622e15bdc45ebf0a0

Author: Bryan Cain bryanca...@gmail.com
Date:   Sat Jan  7 15:28:27 2012 -0600

glsl_to_tgsi: fix emission of boolean constants

We use 0x for true, but visit(ir_constant *) was emitting 1.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index ddd5366..5397011 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -2374,7 +2374,7 @@ glsl_to_tgsi_visitor::visit(ir_constant *ir)
   gl_type = native_integers ? GL_BOOL : GL_FLOAT;
   for (i = 0; i  ir-type-vector_elements; i++) {
  if (native_integers)
-values[i].b = ir-value.b[i];
+values[i].u = ir-value.b[i] ? ~0 : 0;
  else
 values[i].f = ir-value.b[i];
   }

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


Mesa (master): gallium: add an IABS opcode to TGSI

2012-01-07 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 4c0f1fb5ec6117f07c9c911d7f74ff0d18c51d98
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=4c0f1fb5ec6117f07c9c911d7f74ff0d18c51d98

Author: Bryan Cain bryanca...@gmail.com
Date:   Sat Jan  7 10:43:04 2012 -0600

gallium: add an IABS opcode to TGSI

This is a necessary operation that is missing from TGSI.

Reviewed-by: Brian Paul bri...@vmware.com

---

 src/gallium/auxiliary/tgsi/tgsi_exec.c |4 
 src/gallium/auxiliary/tgsi/tgsi_info.c |1 +
 src/gallium/docs/source/tgsi.rst   |   13 +
 src/gallium/include/pipe/p_shader_tokens.h |3 ++-
 4 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c 
b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index 7ea8511..3e2b899 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -4193,6 +4193,10 @@ exec_instruction(
   exec_vector_trinary(mach, inst, micro_ucmp, TGSI_EXEC_DATA_UINT, 
TGSI_EXEC_DATA_UINT);
   break;
 
+   case TGSI_OPCODE_IABS:
+  exec_vector_unary(mach, inst, micro_iabs, TGSI_EXEC_DATA_INT, 
TGSI_EXEC_DATA_INT);
+  break;
+
default:
   assert( 0 );
}
diff --git a/src/gallium/auxiliary/tgsi/tgsi_info.c 
b/src/gallium/auxiliary/tgsi/tgsi_info.c
index 6cd580a..c9acdb9 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_info.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_info.c
@@ -192,6 +192,7 @@ static const struct tgsi_opcode_info 
opcode_info[TGSI_OPCODE_LAST] =

{ 1, 1, 0, 0, 0, 0, UARL, TGSI_OPCODE_UARL },
{ 1, 3, 0, 0, 0, 0, UCMP, TGSI_OPCODE_UCMP },
+   { 1, 1, 0, 0, 0, 0, IABS, TGSI_OPCODE_IABS },
 };
 
 const struct tgsi_opcode_info *
diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst
index 45af528..7e7010f 100644
--- a/src/gallium/docs/source/tgsi.rst
+++ b/src/gallium/docs/source/tgsi.rst
@@ -1043,6 +1043,19 @@ XXX so let's discuss it, yeah?
   destination register, which is assumed to be an address (ADDR) register.
 
 
+.. opcode:: IABS - Integer Absolute Value
+
+.. math::
+
+  dst.x = |src.x|
+
+  dst.y = |src.y|
+
+  dst.z = |src.z|
+
+  dst.w = |src.w|
+
+
 .. opcode:: SAD - Sum Of Absolute Differences
 
 .. math::
diff --git a/src/gallium/include/pipe/p_shader_tokens.h 
b/src/gallium/include/pipe/p_shader_tokens.h
index b24b64c..75e17a1 100644
--- a/src/gallium/include/pipe/p_shader_tokens.h
+++ b/src/gallium/include/pipe/p_shader_tokens.h
@@ -376,8 +376,9 @@ struct tgsi_property_data {
 
 #define TGSI_OPCODE_UARL157
 #define TGSI_OPCODE_UCMP158
+#define TGSI_OPCODE_IABS159
 
-#define TGSI_OPCODE_LAST159
+#define TGSI_OPCODE_LAST160
 
 #define TGSI_SAT_NONE0  /* do not saturate */
 #define TGSI_SAT_ZERO_ONE1  /* clamp to [0,1] */

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


Mesa (master): glsl_to_tgsi: emit IABS for absolute value of integers

2012-01-07 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 73b26e4d12e5fa07bb96b4a30f41bd3b583776aa
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=73b26e4d12e5fa07bb96b4a30f41bd3b583776aa

Author: Bryan Cain bryanca...@gmail.com
Date:   Sat Jan  7 16:19:39 2012 -0600

glsl_to_tgsi: emit IABS for absolute value of integers

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 5397011..3b8e2fe 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1410,8 +1410,10 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
   }
   break;
case ir_unop_abs:
-  assert(result_dst.type == GLSL_TYPE_FLOAT);
-  emit(ir, TGSI_OPCODE_ABS, result_dst, op[0]);
+  if (result_dst.type == GLSL_TYPE_INT || result_dst.type == 
GLSL_TYPE_UINT)
+ emit(ir, TGSI_OPCODE_IABS, result_dst, op[0]);
+  else
+ emit(ir, TGSI_OPCODE_ABS, result_dst, op[0]);
   break;
case ir_unop_sign:
   emit(ir, TGSI_OPCODE_SSG, result_dst, op[0]);

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


Mesa (master): gallium: add support for clip distances

2012-01-05 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 6951870e5790a4b563bfa3b943ed338f9c5922ac
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=6951870e5790a4b563bfa3b943ed338f9c5922ac

Author: Bryan Cain bryanca...@gmail.com
Date:   Mon Jan  2 14:48:47 2012 -0600

gallium: add support for clip distances

---

 src/gallium/auxiliary/tgsi/tgsi_strings.c  |3 +-
 src/gallium/auxiliary/tgsi/tgsi_ureg.c |   38 +--
 src/gallium/auxiliary/tgsi/tgsi_ureg.h |6 
 src/gallium/include/pipe/p_shader_tokens.h |3 +-
 4 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_strings.c 
b/src/gallium/auxiliary/tgsi/tgsi_strings.c
index ee4ce08..9516095 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_strings.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_strings.c
@@ -70,7 +70,8 @@ const char *tgsi_semantic_names[TGSI_SEMANTIC_COUNT] =
PRIM_ID,
INSTANCEID,
VERTEXID,
-   STENCIL
+   STENCIL,
+   CLIPDIST
 };
 
 const char *tgsi_texture_names[TGSI_TEXTURE_COUNT] =
diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c 
b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
index 17f9ce2..0f9aa3a 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
@@ -122,6 +122,7 @@ struct ureg_program
struct {
   unsigned semantic_name;
   unsigned semantic_index;
+  unsigned usage_mask; /* = TGSI_WRITEMASK_* */
} output[UREG_MAX_OUTPUT];
unsigned nr_outputs;
 
@@ -396,21 +397,27 @@ ureg_DECL_system_value(struct ureg_program *ureg,
 
 
 struct ureg_dst 
-ureg_DECL_output( struct ureg_program *ureg,
-  unsigned name,
-  unsigned index )
+ureg_DECL_output_masked( struct ureg_program *ureg,
+ unsigned name,
+ unsigned index,
+ unsigned usage_mask )
 {
unsigned i;
 
+   assert(usage_mask != 0);
+
for (i = 0; i  ureg-nr_outputs; i++) {
   if (ureg-output[i].semantic_name == name 
-  ureg-output[i].semantic_index == index) 
+  ureg-output[i].semantic_index == index) { 
+ ureg-output[i].usage_mask |= usage_mask;
  goto out;
+  }
}
 
if (ureg-nr_outputs  UREG_MAX_OUTPUT) {
   ureg-output[i].semantic_name = name;
   ureg-output[i].semantic_index = index;
+  ureg-output[i].usage_mask = usage_mask;
   ureg-nr_outputs++;
}
else {
@@ -422,6 +429,15 @@ out:
 }
 
 
+struct ureg_dst 
+ureg_DECL_output( struct ureg_program *ureg,
+  unsigned name,
+  unsigned index )
+{
+   return ureg_DECL_output_masked(ureg, name, index, TGSI_WRITEMASK_XYZW);
+}
+
+
 /* Returns a new constant register.  Keep track of which have been
  * referred to so that we can emit decls later.
  *
@@ -1181,7 +1197,8 @@ emit_decl_semantic(struct ureg_program *ureg,
unsigned file,
unsigned index,
unsigned semantic_name,
-   unsigned semantic_index)
+   unsigned semantic_index,
+   unsigned usage_mask)
 {
union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 3);
 
@@ -1189,7 +1206,7 @@ emit_decl_semantic(struct ureg_program *ureg,
out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
out[0].decl.NrTokens = 3;
out[0].decl.File = file;
-   out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; /* FIXME! */
+   out[0].decl.UsageMask = usage_mask;
out[0].decl.Semantic = 1;
 
out[1].value = 0;
@@ -1427,7 +1444,8 @@ static void emit_decls( struct ureg_program *ureg )
 TGSI_FILE_INPUT,
 ureg-gs_input[i].index,
 ureg-gs_input[i].semantic_name,
-ureg-gs_input[i].semantic_index);
+ureg-gs_input[i].semantic_index,
+TGSI_WRITEMASK_XYZW);
   }
}
 
@@ -1436,7 +1454,8 @@ static void emit_decls( struct ureg_program *ureg )
  TGSI_FILE_SYSTEM_VALUE,
  ureg-system_value[i].index,
  ureg-system_value[i].semantic_name,
- ureg-system_value[i].semantic_index);
+ ureg-system_value[i].semantic_index,
+ TGSI_WRITEMASK_XYZW);
}
 
for (i = 0; i  ureg-nr_outputs; i++) {
@@ -1444,7 +1463,8 @@ static void emit_decls( struct ureg_program *ureg )
  TGSI_FILE_OUTPUT,
  i,
  ureg-output[i].semantic_name,
- ureg-output[i].semantic_index);
+ ureg-output[i].semantic_index,
+ ureg-output[i].usage_mask);
}
 
for (i = 0; i  ureg-nr_samplers; i++) {
diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h 
b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
index bf55d54..07ab8cb 100644
--- a/src/gallium/auxiliary

Mesa (master): st/mesa: add support for gl_ClipDistance

2012-01-05 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 59be691638200797583bce39a83f641d30d97492
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=59be691638200797583bce39a83f641d30d97492

Author: Bryan Cain bryanca...@gmail.com
Date:   Mon Jan  2 14:49:46 2012 -0600

st/mesa: add support for gl_ClipDistance

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   48 +---
 src/mesa/state_tracker/st_program.c|   18 ++
 2 files changed, 61 insertions(+), 5 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index cecceca..500e662 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -304,6 +304,7 @@ public:
int samplers_used;
bool indirect_addr_temps;
bool indirect_addr_consts;
+   int num_clip_distances;

int glsl_version;
bool native_integers;
@@ -4641,9 +4642,17 @@ st_translate_program(
   }
 
   for (i = 0; i  numOutputs; i++) {
- t-outputs[i] = ureg_DECL_output(ureg,
-  outputSemanticName[i],
-  outputSemanticIndex[i]);
+ if (outputSemanticName[i] == TGSI_SEMANTIC_CLIPDIST) {
+int mask = ((1  (program-num_clip_distances - 
4*outputSemanticIndex[i])) - 1)  TGSI_WRITEMASK_XYZW;
+t-outputs[i] = ureg_DECL_output_masked(ureg,
+outputSemanticName[i],
+outputSemanticIndex[i],
+mask);
+ } else {
+t-outputs[i] = ureg_DECL_output(ureg,
+ outputSemanticName[i],
+ outputSemanticIndex[i]);
+ }
  if ((outputSemanticName[i] == TGSI_SEMANTIC_PSIZE)  proginfo-Id) {
 /* Writing to the point size result register requires special
  * handling to implement clamping.
@@ -4834,7 +4843,8 @@ out:
 static struct gl_program *
 get_mesa_program(struct gl_context *ctx,
  struct gl_shader_program *shader_program,
-struct gl_shader *shader)
+ struct gl_shader *shader,
+ int num_clip_distances)
 {
glsl_to_tgsi_visitor* v = new glsl_to_tgsi_visitor();
struct gl_program *prog;
@@ -4879,6 +4889,7 @@ get_mesa_program(struct gl_context *ctx,
v-options = options;
v-glsl_version = ctx-Const.GLSLVersion;
v-native_integers = ctx-Const.NativeIntegers;
+   v-num_clip_distances = num_clip_distances;
 
_mesa_generate_parameters_list_for_uniforms(shader_program, shader,
   prog-Parameters);
@@ -5008,6 +5019,25 @@ get_mesa_program(struct gl_context *ctx,
return prog;
 }
 
+/**
+ * Searches through the IR for a declaration of gl_ClipDistance and returns the
+ * declared size of the gl_ClipDistance array.  Returns 0 if gl_ClipDistance is
+ * not declared in the IR.
+ */
+int get_clip_distance_size(exec_list *ir)
+{
+   foreach_iter (exec_list_iterator, iter, *ir) {
+  ir_instruction *inst = (ir_instruction *)iter.get();
+  ir_variable *var = inst-as_variable();
+  if (var == NULL) continue;
+  if (!strcmp(var-name, gl_ClipDistance)) {
+ return var-type-length;
+  }
+   }
+   
+   return 0;
+}
+
 extern C {
 
 struct gl_shader *
@@ -5046,6 +5076,7 @@ st_new_shader_program(struct gl_context *ctx, GLuint name)
 GLboolean
 st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
 {
+   int num_clip_distances[MESA_SHADER_TYPES];
assert(prog-LinkStatus);
 
for (unsigned i = 0; i  MESA_SHADER_TYPES; i++) {
@@ -5057,6 +5088,11 @@ st_link_shader(struct gl_context *ctx, struct 
gl_shader_program *prog)
   const struct gl_shader_compiler_options *options =
 
ctx-ShaderCompilerOptions[_mesa_shader_type_to_index(prog-_LinkedShaders[i]-Type)];
 
+  /* We have to determine the length of the gl_ClipDistance array before
+   * the array is lowered to two vec4s by lower_clip_distance().
+   */
+  num_clip_distances[i] = get_clip_distance_size(ir);
+
   do {
  progress = false;
 
@@ -5073,6 +5109,7 @@ st_link_shader(struct gl_context *ctx, struct 
gl_shader_program *prog)
   || progress;
 
  progress = lower_quadop_vector(ir, false) || progress;
+ progress = lower_clip_distance(ir) || progress;
 
  if (options-MaxIfDepth == 0)
 progress = lower_discard(ir) || progress;
@@ -5107,7 +5144,8 @@ st_link_shader(struct gl_context *ctx, struct 
gl_shader_program *prog)
   if (prog-_LinkedShaders[i] == NULL)
  continue;
 
-  linked_prog = get_mesa_program(ctx, prog, prog-_LinkedShaders[i]);
+  linked_prog = get_mesa_program(ctx, prog, prog-_LinkedShaders[i

Mesa (master): glsl_to_tgsi: fix handling of CONT and BRK in eliminate_dead_code_advanced()

2012-01-02 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 09497e020a11cc893d06691751faf57c1e762839
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=09497e020a11cc893d06691751faf57c1e762839

Author: Bryan Cain bryanca...@gmail.com
Date:   Mon Jan  2 14:07:38 2012 -0600

glsl_to_tgsi: fix handling of CONT and BRK in eliminate_dead_code_advanced()

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |9 +++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 77aa0d1..1515fc1 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -3505,10 +3505,15 @@ glsl_to_tgsi_visitor::eliminate_dead_code_advanced(void)
   switch (inst-op) {
   case TGSI_OPCODE_BGNLOOP:
   case TGSI_OPCODE_ENDLOOP:
+  case TGSI_OPCODE_CONT:
+  case TGSI_OPCODE_BRK:
  /* End of a basic block, clear the write array entirely.
-  * FIXME: This keeps us from killing dead code when the writes are
+  *
+  * This keeps us from killing dead code when the writes are
   * on either side of a loop, even when the register isn't touched
-  * inside the loop.
+  * inside the loop.  However, glsl_to_tgsi_visitor doesn't seem to 
emit
+  * dead code of this type, so it shouldn't make a difference as long 
as
+  * the dead code elimination pass in the GLSL compiler does its job.
   */
  memset(writes, 0, sizeof(*writes) * this-next_temp * 4);
  break;

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


Mesa (master): glsl_to_tgsi: emit both operands of shift and bitwise operations

2011-12-13 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: d24b44c37d51051ff153b4f04e529f2bea6630db
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=d24b44c37d51051ff153b4f04e529f2bea6630db

Author: Bryan Cain bryanca...@gmail.com
Date:   Tue Dec 13 10:30:59 2011 -0600

glsl_to_tgsi: emit both operands of shift and bitwise operations

Fixes these operations when native integers are enabled.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   10 +-
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 6cc655d..9042cdb 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1807,27 +1807,27 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
   }
case ir_binop_lshift:
   if (native_integers) {
- emit(ir, TGSI_OPCODE_SHL, result_dst, op[0]);
+ emit(ir, TGSI_OPCODE_SHL, result_dst, op[0], op[1]);
  break;
   }
case ir_binop_rshift:
   if (native_integers) {
- emit(ir, TGSI_OPCODE_ISHR, result_dst, op[0]);
+ emit(ir, TGSI_OPCODE_ISHR, result_dst, op[0], op[1]);
  break;
   }
case ir_binop_bit_and:
   if (native_integers) {
- emit(ir, TGSI_OPCODE_AND, result_dst, op[0]);
+ emit(ir, TGSI_OPCODE_AND, result_dst, op[0], op[1]);
  break;
   }
case ir_binop_bit_xor:
   if (native_integers) {
- emit(ir, TGSI_OPCODE_XOR, result_dst, op[0]);
+ emit(ir, TGSI_OPCODE_XOR, result_dst, op[0], op[1]);
  break;
   }
case ir_binop_bit_or:
   if (native_integers) {
- emit(ir, TGSI_OPCODE_OR, result_dst, op[0]);
+ emit(ir, TGSI_OPCODE_OR, result_dst, op[0], op[1]);
  break;
   }
case ir_unop_round_even:

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


Mesa (master): glsl_to_tgsi: fix typo in comment

2011-12-13 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 3b15f5046c36fb2d32a4c5f36e77b74efcb539b2
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=3b15f5046c36fb2d32a4c5f36e77b74efcb539b2

Author: Bryan Cain bryanca...@gmail.com
Date:   Tue Dec 13 10:33:44 2011 -0600

glsl_to_tgsi: fix typo in comment

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 9042cdb..9ef65c8 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -3515,8 +3515,8 @@ glsl_to_tgsi_visitor::eliminate_dead_code_advanced(void)
 
   case TGSI_OPCODE_ENDIF:
   case TGSI_OPCODE_ELSE:
- /* Promote the recorded level all channels written inside the 
preceding
-  * if or else block to the level above the if/else block.
+ /* Promote the recorded level of all channels written inside the
+  * preceding if or else block to the level above the if/else block.
   */
  for (int r = 0; r  this-next_temp; r++) {
 for (int c = 0; c  4; c++) {

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


Mesa (master): glsl_to_tgsi: fix a bug in eliminate_dead_code_advanced()

2011-12-08 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 20b0daf82de91fd57b7e8d825786789149f6358d
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=20b0daf82de91fd57b7e8d825786789149f6358d

Author: Bryan Cain bryanca...@gmail.com
Date:   Thu Dec  8 13:48:27 2011 -0600

glsl_to_tgsi: fix a bug in eliminate_dead_code_advanced()

The bug, reported to me by Vadim Girlin on IRC, was causing overzealous
elimination of code in parallel if statements such as the following:

if (x) {
r = false;
}
if (y) {
r = true;
}

Before this commit, the assignment inside the first if block would be
misdetected as dead code and removed.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   18 --
 1 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 59b5ffd..6cc655d 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -3514,25 +3514,23 @@ glsl_to_tgsi_visitor::eliminate_dead_code_advanced(void)
  break;
 
   case TGSI_OPCODE_ENDIF:
- --level;
- break;
-
   case TGSI_OPCODE_ELSE:
- /* Clear all channels written inside the preceding if block from the
-  * write array, but leave those that were not touched.
-  *
-  * FIXME: This destroys opportunities to remove dead code inside of
-  * IF blocks that are followed by an ELSE block.
+ /* Promote the recorded level all channels written inside the 
preceding
+  * if or else block to the level above the if/else block.
   */
  for (int r = 0; r  this-next_temp; r++) {
 for (int c = 0; c  4; c++) {
if (!writes[4 * r + c])
 continue;
 
-   if (write_level[4 * r + c] = level)
-writes[4 * r + c] = NULL;
+   if (write_level[4 * r + c] == level)
+write_level[4 * r + c] = level-1;
 }
  }
+
+ if(inst-op == TGSI_OPCODE_ENDIF)
+--level;
+ 
  break;
 
   case TGSI_OPCODE_IF:

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


Mesa (master): glsl_to_tgsi: implement ir_binop_all_equal and ir_binop_any_nequal for native integers

2011-09-20 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 6da8c21124152c68fb968b196895f2c881a24280
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=6da8c21124152c68fb968b196895f2c881a24280

Author: Bryan Cain bryanca...@gmail.com
Date:   Mon Sep 19 16:46:44 2011 -0500

glsl_to_tgsi: implement ir_binop_all_equal and ir_binop_any_nequal for native 
integers

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  119 
 1 files changed, 85 insertions(+), 34 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 8921698..f68270d 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1528,15 +1528,45 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
  st_src_reg temp = get_temp(native_integers ?
glsl_type::get_instance(ir-operands[0]-type-base_type, 4, 1) 
:
glsl_type::vec4_type);
- assert(ir-operands[0]-type-base_type == GLSL_TYPE_FLOAT);
- emit(ir, TGSI_OPCODE_SNE, st_dst_reg(temp), op[0], op[1]);
- 
- /* After the dot-product, the value will be an integer on the
-  * range [0,4].  Zero becomes 1.0, and positive values become zero.
-  */
- emit_dp(ir, result_dst, temp, temp, vector_elements);
  
- if (result_dst.type == GLSL_TYPE_FLOAT) {
+ if (native_integers) {
+st_dst_reg temp_dst = st_dst_reg(temp);
+st_src_reg temp1 = st_src_reg(temp), temp2 = st_src_reg(temp);
+
+emit(ir, TGSI_OPCODE_SEQ, st_dst_reg(temp), op[0], op[1]);
+
+/* Emit 1-3 AND operations to combine the SEQ results. */
+switch (ir-operands[0]-type-vector_elements) {
+case 2:
+   break;
+case 3:
+   temp_dst.writemask = WRITEMASK_Y;
+   temp1.swizzle = SWIZZLE_;
+   temp2.swizzle = SWIZZLE_;
+   emit(ir, TGSI_OPCODE_AND, temp_dst, temp1, temp2);
+   break;
+case 4:
+   temp_dst.writemask = WRITEMASK_X;
+   temp1.swizzle = SWIZZLE_;
+   temp2.swizzle = SWIZZLE_;
+   emit(ir, TGSI_OPCODE_AND, temp_dst, temp1, temp2);
+   temp_dst.writemask = WRITEMASK_Y;
+   temp1.swizzle = SWIZZLE_;
+   temp2.swizzle = SWIZZLE_;
+   emit(ir, TGSI_OPCODE_AND, temp_dst, temp1, temp2);
+}
+
+temp1.swizzle = SWIZZLE_;
+temp2.swizzle = SWIZZLE_;
+emit(ir, TGSI_OPCODE_AND, result_dst, temp1, temp2);
+ } else {
+emit(ir, TGSI_OPCODE_SNE, st_dst_reg(temp), op[0], op[1]);
+
+/* After the dot-product, the value will be an integer on the
+ * range [0,4].  Zero becomes 1.0, and positive values become zero.
+ */
+emit_dp(ir, result_dst, temp, temp, vector_elements);
+
 /* Negating the result of the dot-product gives values on the range
  * [-4, 0].  Zero becomes 1.0, and negative values become zero.
  * This is achieved using SGE.
@@ -1544,11 +1574,6 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
 st_src_reg sge_src = result_src;
 sge_src.negate = ~sge_src.negate;
 emit(ir, TGSI_OPCODE_SGE, result_dst, sge_src, 
st_src_reg_for_float(0.0));
- } else {
-/* The TGSI negate flag doesn't work for integers, so use SEQ 0
- * instead.
- */
-emit(ir, TGSI_OPCODE_SEQ, result_dst, result_src, 
st_src_reg_for_int(0));
  }
   } else {
  emit(ir, TGSI_OPCODE_SEQ, result_dst, op[0], op[1]);
@@ -1561,30 +1586,56 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
  st_src_reg temp = get_temp(native_integers ?
glsl_type::get_instance(ir-operands[0]-type-base_type, 4, 1) 
:
glsl_type::vec4_type);
- assert(ir-operands[0]-type-base_type == GLSL_TYPE_FLOAT);
  emit(ir, TGSI_OPCODE_SNE, st_dst_reg(temp), op[0], op[1]);
 
- /* After the dot-product, the value will be an integer on the
-  * range [0,4].  Zero stays zero, and positive values become 1.0.
-  */
- glsl_to_tgsi_instruction *const dp =
-   emit_dp(ir, result_dst, temp, temp, vector_elements);
- if (this-prog-Target == GL_FRAGMENT_PROGRAM_ARB 
- result_dst.type == GLSL_TYPE_FLOAT) {
-/* The clamping to [0,1] can be done for free in the fragment
- * shader with a saturate.
- */
-dp-saturate = true;
- } else if (result_dst.type == GLSL_TYPE_FLOAT) {
-/* Negating the result of the dot-product gives values on the range
- * [-4, 0].  Zero stays zero, and negative values become 1.0

Mesa (master): gallium: add TGSI opcodes UARL and UCMP

2011-09-10 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 324ac982d8e7c2693035342de2d24baff3042911
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=324ac982d8e7c2693035342de2d24baff3042911

Author: Bryan Cain bryanca...@gmail.com
Date:   Sat Sep 10 12:31:54 2011 -0500

gallium: add TGSI opcodes UARL and UCMP

They are needed by glsl_to_tgsi for an efficient implementation using native
integers.

Reviewed-by: Brian Paul bri...@vmware.com

---

 src/gallium/auxiliary/tgsi/tgsi_exec.c |   30 
 src/gallium/auxiliary/tgsi/tgsi_info.c |3 ++
 src/gallium/docs/source/tgsi.rst   |   19 +
 src/gallium/include/pipe/p_shader_tokens.h |5 +++-
 4 files changed, 56 insertions(+), 1 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c 
b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index d9de41b..ce6399c 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -3367,6 +3367,28 @@ micro_usne(union tgsi_exec_channel *dst,
 }
 
 static void
+micro_uarl(union tgsi_exec_channel *dst,
+   const union tgsi_exec_channel *src)
+{
+   dst-i[0] = src-u[0];
+   dst-i[1] = src-u[1];
+   dst-i[2] = src-u[2];
+   dst-i[3] = src-u[3];
+}
+
+static void
+micro_ucmp(union tgsi_exec_channel *dst,
+   const union tgsi_exec_channel *src0,
+   const union tgsi_exec_channel *src1,
+   const union tgsi_exec_channel *src2)
+{
+   dst-u[0] = src0-u[0] ? src1-u[0] : src2-u[0];
+   dst-u[1] = src0-u[1] ? src1-u[1] : src2-u[1];
+   dst-u[2] = src0-u[2] ? src1-u[2] : src2-u[2];
+   dst-u[3] = src0-u[3] ? src1-u[3] : src2-u[3];
+}
+
+static void
 exec_instruction(
struct tgsi_exec_machine *mach,
const struct tgsi_full_instruction *inst,
@@ -4126,6 +4148,14 @@ exec_instruction(
   assert(0);
   break;
 
+   case TGSI_OPCODE_UARL:
+  exec_vector_unary(mach, inst, micro_uarl, TGSI_EXEC_DATA_INT, 
TGSI_EXEC_DATA_UINT);
+  break;
+
+   case TGSI_OPCODE_UCMP:
+  exec_vector_trinary(mach, inst, micro_ucmp, TGSI_EXEC_DATA_FLOAT, 
TGSI_EXEC_DATA_UINT);
+  break;
+
default:
   assert( 0 );
}
diff --git a/src/gallium/auxiliary/tgsi/tgsi_info.c 
b/src/gallium/auxiliary/tgsi/tgsi_info.c
index 14ed56a..6cd580a 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_info.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_info.c
@@ -189,6 +189,9 @@ static const struct tgsi_opcode_info 
opcode_info[TGSI_OPCODE_LAST] =
{ 1, 2, 0, 0, 0, 0, RESINFO, TGSI_OPCODE_RESINFO },
{ 1, 2, 0, 0, 0, 0, SAMPLE_POS,  TGSI_OPCODE_SAMPLE_POS },
{ 1, 2, 0, 0, 0, 0, SAMPLE_INFO, TGSI_OPCODE_SAMPLE_INFO },
+   
+   { 1, 1, 0, 0, 0, 0, UARL, TGSI_OPCODE_UARL },
+   { 1, 3, 0, 0, 0, 0, UCMP, TGSI_OPCODE_UCMP },
 };
 
 const struct tgsi_opcode_info *
diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst
index 5cf0875..d7f50b1 100644
--- a/src/gallium/docs/source/tgsi.rst
+++ b/src/gallium/docs/source/tgsi.rst
@@ -1013,6 +1013,25 @@ XXX so let's discuss it, yeah?
   dst.w = src0.w \oplus src1.w
 
 
+.. opcode:: UCMP - Integer Conditional Move
+
+.. math::
+
+  dst.x = src0.x ? src1.x : src2.x
+
+  dst.y = src0.y ? src1.y : src2.y
+
+  dst.z = src0.z ? src1.z : src2.z
+
+  dst.w = src0.w ? src1.w : src2.w
+
+
+.. opcode:: UARL - Integer Address Register Load
+
+  Moves the contents of the source register, assumed to be an integer, into the
+  destination register, which is assumed to be an address (ADDR) register.
+
+
 .. opcode:: SAD - Sum Of Absolute Differences
 
 .. math::
diff --git a/src/gallium/include/pipe/p_shader_tokens.h 
b/src/gallium/include/pipe/p_shader_tokens.h
index b9e3dcf..7236c92 100644
--- a/src/gallium/include/pipe/p_shader_tokens.h
+++ b/src/gallium/include/pipe/p_shader_tokens.h
@@ -363,7 +363,10 @@ struct tgsi_property_data {
 #define TGSI_OPCODE_SAMPLE_POS  155
 #define TGSI_OPCODE_SAMPLE_INFO 156
 
-#define TGSI_OPCODE_LAST157
+#define TGSI_OPCODE_UARL157
+#define TGSI_OPCODE_UCMP158
+
+#define TGSI_OPCODE_LAST159
 
 #define TGSI_SAT_NONE0  /* do not saturate */
 #define TGSI_SAT_ZERO_ONE1  /* clamp to [0,1] */

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


Mesa (master): glsl_to_tgsi: use UARL instead of I2F and ARL

2011-09-10 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 10dbd029279dda1689410d8ef2bc5aba64dd5958
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=10dbd029279dda1689410d8ef2bc5aba64dd5958

Author: Bryan Cain bryanca...@gmail.com
Date:   Fri Sep  2 00:10:50 2011 -0500

glsl_to_tgsi: use UARL instead of I2F and ARL

Since TGSI now has a UARL opcode that takes an integer as the source, it is
no longer necessary to hack around the lack of an integer ARL opcode using I2F.
UARL is only emitted when native integers are enabled; ARL is still used
otherwise.

Reviewed-by: Brian Paul bri...@vmware.com

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   18 +++---
 1 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 4a5f6a2..8921698 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -519,7 +519,7 @@ glsl_to_tgsi_visitor::emit(ir_instruction *ir, unsigned op,
 
inst-function = NULL;

-   if (op == TGSI_OPCODE_ARL)
+   if (op == TGSI_OPCODE_ARL || op == TGSI_OPCODE_UARL)
   this-num_address_regs = 1;

/* Update indirect addressing status used by TGSI */
@@ -746,16 +746,12 @@ void
 glsl_to_tgsi_visitor::emit_arl(ir_instruction *ir,
st_dst_reg dst, st_src_reg src0)
 {
-   st_src_reg tmp = get_temp(glsl_type::float_type);
+   int op = TGSI_OPCODE_ARL;
 
-   if (src0.type == GLSL_TYPE_INT)
-  emit(NULL, TGSI_OPCODE_I2F, st_dst_reg(tmp), src0);
-   else if (src0.type == GLSL_TYPE_UINT)
-  emit(NULL, TGSI_OPCODE_U2F, st_dst_reg(tmp), src0);
-   else
-  tmp = src0;
-   
-   emit(NULL, TGSI_OPCODE_ARL, dst, tmp);
+   if (src0.type == GLSL_TYPE_INT || src0.type == GLSL_TYPE_UINT)
+  op = TGSI_OPCODE_UARL;
+
+   emit(NULL, op, dst, src0);
 }
 
 /**

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


Mesa (master): tgsi: fix typo in commit 324ac982d8e7

2011-09-10 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: f0bfc0daa87578ce8b11383afb99dbf2d2630e23
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=f0bfc0daa87578ce8b11383afb99dbf2d2630e23

Author: Emil Velikov emil.l.veli...@gmail.com
Date:   Sat Sep 10 14:07:07 2011 -0500

tgsi: fix typo in commit 324ac982d8e7

Reviewed-by: Bryan Cain bryanca...@gmail.com

---

 src/gallium/auxiliary/tgsi/tgsi_exec.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c 
b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index ce6399c..b4eea54 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -4153,7 +4153,7 @@ exec_instruction(
   break;
 
case TGSI_OPCODE_UCMP:
-  exec_vector_trinary(mach, inst, micro_ucmp, TGSI_EXEC_DATA_FLOAT, 
TGSI_EXEC_DATA_UINT);
+  exec_vector_trinary(mach, inst, micro_ucmp, TGSI_EXEC_DATA_UINT, 
TGSI_EXEC_DATA_UINT);
   break;
 
default:

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


Mesa (master): mesa: add a UniformBooleanTrue option

2011-09-05 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 4e64cfbb4ec92877803e70257af8b97c484c00c0
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=4e64cfbb4ec92877803e70257af8b97c484c00c0

Author: Bryan Cain bryanca...@gmail.com
Date:   Mon Sep  5 14:54:37 2011 -0500

mesa: add a UniformBooleanTrue option

Drivers supporting native integers set UniformBooleanTrue to the integer value
that should be used for true when uploading uniform booleans.  This is ~0 for
Gallium and 1 for i965.

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

---

 src/mesa/drivers/dri/i965/brw_context.c |4 +++-
 src/mesa/main/mtypes.h  |6 ++
 src/mesa/main/uniforms.c|5 -
 src/mesa/state_tracker/st_extensions.c  |1 +
 4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index 6ef0fcb..5ea7385 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -253,8 +253,10 @@ GLboolean brwCreateContext( int api,
/* If we're using the new shader backend, we require integer uniforms
 * stored as actual integers.
 */
-   if (brw-new_vs_backend)
+   if (brw-new_vs_backend) {
   ctx-Const.NativeIntegers = true;
+  ctx-Const.UniformBooleanTrue = 1;
+   }
 
return GL_TRUE;
 }
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 44ebf0a..ad59797 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2722,6 +2722,12 @@ struct gl_constants
 */
GLboolean NativeIntegers;
 
+   /**
+* If the driver supports real 32-bit integers, what integer value should be
+* used for boolean true in uniform uploads?  (Usually 1 or ~0.)
+*/
+   GLuint UniformBooleanTrue;
+
/** Which texture units support GL_ATI_envmap_bumpmap as targets */
GLbitfield SupportedBumpUnits;
 
diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index fe1ce6d..b0f9c33 100644
--- a/src/mesa/main/uniforms.c
+++ b/src/mesa/main/uniforms.c
@@ -802,7 +802,10 @@ set_program_uniform(struct gl_context *ctx, struct 
gl_program *program,
else
   uniformVal[i].b = uniformVal[i].u ? 1 : 0;

-   if (!ctx-Const.NativeIntegers)
+   if (ctx-Const.NativeIntegers)
+  uniformVal[i].u =
+uniformVal[i].b ? ctx-Const.UniformBooleanTrue : 0;
+   else
   uniformVal[i].f = uniformVal[i].b ? 1.0f : 0.0f;
 }
  }
diff --git a/src/mesa/state_tracker/st_extensions.c 
b/src/mesa/state_tracker/st_extensions.c
index aa7f3b5..76e84eb 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -207,6 +207,7 @@ void st_init_limits(struct st_context *st)
   c-MaxProgramTexelOffset = screen-get_param(screen, 
PIPE_CAP_MAX_TEXEL_OFFSET);
 
   c-GLSLVersion = 120;
+  c-UniformBooleanTrue = ~0;
}
 }
 

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


Mesa (master): glsl_to_tgsi: fixes for native integers and integer booleans

2011-09-04 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 0dc575c6f6157867accf749a06ec745617ea64ac
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=0dc575c6f6157867accf749a06ec745617ea64ac

Author: Bryan Cain bryanca...@gmail.com
Date:   Sun Sep  4 14:31:16 2011 -0500

glsl_to_tgsi: fixes for native integers and integer booleans

This fixes all but one of the piglit regressions from enabling native integers
in softpipe.  The change to fix the last regression is still being discussed.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  170 +++-
 1 files changed, 118 insertions(+), 52 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 66fc00f..9394bea 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -390,6 +390,8 @@ public:
void emit_scalar(ir_instruction *ir, unsigned op,
st_dst_reg dst, st_src_reg src0, st_src_reg src1);
 
+   void try_emit_float_set(ir_instruction *ir, unsigned op, st_dst_reg dst);
+
void emit_arl(ir_instruction *ir, st_dst_reg dst, st_src_reg src0);
 
void emit_scs(ir_instruction *ir, unsigned op,
@@ -567,7 +569,10 @@ glsl_to_tgsi_visitor::emit(ir_instruction *ir, unsigned op,
}
 
this-instructions.push_tail(inst);
-   
+
+   if (native_integers)
+  try_emit_float_set(ir, op, dst);
+
return inst;
 }
 
@@ -593,11 +598,28 @@ glsl_to_tgsi_visitor::emit(ir_instruction *ir, unsigned 
op)
return emit(ir, op, undef_dst, undef_src, undef_src, undef_src);
 }
 
+ /**
+ * Emits the code to convert the result of float SET instructions to integers.
+ */
+void
+glsl_to_tgsi_visitor::try_emit_float_set(ir_instruction *ir, unsigned op,
+st_dst_reg dst)
+{
+   if ((op == TGSI_OPCODE_SEQ ||
+op == TGSI_OPCODE_SNE ||
+op == TGSI_OPCODE_SGE ||
+op == TGSI_OPCODE_SLT))
+   {
+  st_src_reg src = st_src_reg(dst);
+  src.negate = ~src.negate;
+  dst.type = GLSL_TYPE_FLOAT;
+  emit(ir, TGSI_OPCODE_F2I, dst, src);
+   }
+}
+
 /**
  * Determines whether to use an integer, unsigned integer, or float opcode 
  * based on the operands and input opcode, then emits the result.
- * 
- * TODO: type checking for remaining TGSI opcodes
  */
 unsigned
 glsl_to_tgsi_visitor::get_opcode(ir_instruction *ir, unsigned op,
@@ -609,7 +631,7 @@ glsl_to_tgsi_visitor::get_opcode(ir_instruction *ir, 
unsigned op,
if (src0.type == GLSL_TYPE_FLOAT || src1.type == GLSL_TYPE_FLOAT)
   type = GLSL_TYPE_FLOAT;
else if (native_integers)
-  type = src0.type;
+  type = src0.type == GLSL_TYPE_BOOL ? GLSL_TYPE_INT : src0.type;
 
 #define case4(c, f, i, u) \
case TGSI_OPCODE_##c: \
@@ -635,12 +657,7 @@ glsl_to_tgsi_visitor::get_opcode(ir_instruction *ir, 
unsigned op,
   case3(SGE, ISGE, USGE);
   case3(SLT, ISLT, USLT);
   
-  case2iu(SHL, SHL);
   case2iu(ISHR, USHR);
-  case2iu(NOT, NOT);
-  case2iu(AND, AND);
-  case2iu(OR, OR);
-  case2iu(XOR, XOR);
   
   default: break;
}
@@ -1394,7 +1411,7 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
switch (ir-operation) {
case ir_unop_logic_not:
   if (result_dst.type != GLSL_TYPE_FLOAT)
- emit(ir, TGSI_OPCODE_SEQ, result_dst, op[0], 
st_src_reg_for_type(result_dst.type, 0));
+ emit(ir, TGSI_OPCODE_NOT, result_dst, op[0]);
   else {
  /* Previously 'SEQ dst, src, 0.0' was used for this.  However, many
   * older GPUs implement SEQ using multiple instructions (i915 uses two
@@ -1494,10 +1511,10 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
   emit(ir, TGSI_OPCODE_SLT, result_dst, op[0], op[1]);
   break;
case ir_binop_greater:
-  emit(ir, TGSI_OPCODE_SGT, result_dst, op[0], op[1]);
+  emit(ir, TGSI_OPCODE_SLT, result_dst, op[1], op[0]);
   break;
case ir_binop_lequal:
-  emit(ir, TGSI_OPCODE_SLE, result_dst, op[0], op[1]);
+  emit(ir, TGSI_OPCODE_SGE, result_dst, op[1], op[0]);
   break;
case ir_binop_gequal:
   emit(ir, TGSI_OPCODE_SGE, result_dst, op[0], op[1]);
@@ -1610,41 +1627,52 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
}
 
case ir_binop_logic_xor:
-  emit(ir, TGSI_OPCODE_SNE, result_dst, op[0], op[1]);
+  if (native_integers)
+ emit(ir, TGSI_OPCODE_XOR, result_dst, op[0], op[1]);
+  else
+ emit(ir, TGSI_OPCODE_SNE, result_dst, op[0], op[1]);
   break;
 
case ir_binop_logic_or: {
-  /* After the addition, the value will be an integer on the
-   * range [0,2].  Zero stays zero, and positive values become 1.0.
-   */
-  glsl_to_tgsi_instruction *add =
- emit(ir, TGSI_OPCODE_ADD, result_dst, op[0], op[1]);
-  if (this-prog-Target == GL_FRAGMENT_PROGRAM_ARB 
-  result_dst.type == GLSL_TYPE_FLOAT) {
- /* The clamping to [0,1] can be done for free in the fragment
-  * shader

Mesa (master): mesa: Replace the EmitNoIfs compiler flag with a MaxIfDepth flag.

2011-08-31 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 488fe51cf823ccd137c667f1e92dd86f8323b723
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=488fe51cf823ccd137c667f1e92dd86f8323b723

Author: Bryan Cain bryanca...@gmail.com
Date:   Wed Aug 31 17:28:53 2011 -0500

mesa: Replace the EmitNoIfs compiler flag with a MaxIfDepth flag.

This is a better, more fine-grained way of lowering if statements.  Fixes the
game And Yet It Moves on nv50.

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

---

 src/mesa/drivers/dri/i915/i915_context.c   |2 +-
 src/mesa/main/mtypes.h |6 +-
 src/mesa/program/ir_to_mesa.cpp|8 
 src/mesa/state_tracker/st_extensions.c |2 +-
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |6 +++---
 5 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/src/mesa/drivers/dri/i915/i915_context.c 
b/src/mesa/drivers/dri/i915/i915_context.c
index 11bee14..e807281 100644
--- a/src/mesa/drivers/dri/i915/i915_context.c
+++ b/src/mesa/drivers/dri/i915/i915_context.c
@@ -189,7 +189,7 @@ i915CreateContext(int api,
 
struct gl_shader_compiler_options *const fs_options =
ctx-ShaderCompilerOptions[MESA_SHADER_FRAGMENT];
-   fs_options-EmitNoIfs = GL_TRUE;
+   fs_options-MaxIfDepth = 0;
fs_options-EmitNoNoise = GL_TRUE;
fs_options-EmitNoPow = GL_TRUE;
fs_options-EmitNoMainReturn = GL_TRUE;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index f2eb889..44ebf0a 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2266,11 +2266,6 @@ struct gl_shader_compiler_options
/** Driver-selectable options: */
GLboolean EmitCondCodes; /** Use condition codes? */
GLboolean EmitNVTempInitialization;  /** 0-fill NV temp registers */
-   /**
-* Attempts to flatten all ir_if (OPCODE_IF) for GPUs that can't
-* support control flow.
-*/
-   GLboolean EmitNoIfs;
GLboolean EmitNoLoops;
GLboolean EmitNoFunctions;
GLboolean EmitNoCont;  /** Emit CONT opcode? */
@@ -2288,6 +2283,7 @@ struct gl_shader_compiler_options
GLboolean EmitNoIndirectUniform; /** No indirect addressing of constants */
/*@}*/
 
+   GLuint MaxIfDepth;   /** Maximum nested IF blocks */
GLuint MaxUnrollIterations;
 
struct gl_sl_pragmas DefaultPragmas; /** Default #pragma settings */
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index dd154db..9813c4a 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -3119,7 +3119,7 @@ get_mesa_program(struct gl_context *ctx,
 
   switch (mesa_inst-Opcode) {
   case OPCODE_IF:
-if (options-EmitNoIfs) {
+if (options-MaxIfDepth == 0) {
linker_warning(shader_program,
   Couldn't flatten if-statement.  
   This will likely result in software 
@@ -3241,10 +3241,10 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct 
gl_shader_program *prog)
 
 progress = lower_quadop_vector(ir, true) || progress;
 
-if (options-EmitNoIfs) {
+if (options-MaxIfDepth == 0)
progress = lower_discard(ir) || progress;
-   progress = lower_if_to_cond_assign(ir) || progress;
-}
+
+progress = lower_if_to_cond_assign(ir, options-MaxIfDepth) || 
progress;
 
 if (options-EmitNoNoise)
progress = lower_noise(ir) || progress;
diff --git a/src/mesa/state_tracker/st_extensions.c 
b/src/mesa/state_tracker/st_extensions.c
index 8e90093..322dbbf 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -173,7 +173,7 @@ void st_init_limits(struct st_context *st)
   options-EmitNoNoise = TRUE;
 
   /* TODO: make these more fine-grained if anyone needs it */
-  options-EmitNoIfs = !screen-get_shader_param(screen, sh, 
PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
+  options-MaxIfDepth = screen-get_shader_param(screen, sh, 
PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
   options-EmitNoLoops = !screen-get_shader_param(screen, sh, 
PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
   options-EmitNoFunctions = !screen-get_shader_param(screen, sh, 
PIPE_SHADER_CAP_SUBROUTINES);
   options-EmitNoMainReturn = !screen-get_shader_param(screen, sh, 
PIPE_SHADER_CAP_SUBROUTINES);
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 98bea69..e2857ed 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -4991,10 +4991,10 @@ st_link_shader(struct gl_context *ctx, struct 
gl_shader_program *prog)
 
  progress = lower_quadop_vector(ir, false) || progress;
 
- if (options-EmitNoIfs) {
+ if (options-MaxIfDepth == 0)
 progress = lower_discard(ir) || progress;
-progress = lower_if_to_cond_assign(ir) || progress;
- }
+
+ progress

Mesa (master): glsl_to_tgsi: remove unused code

2011-08-27 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: c8fed01c732fa20e1ae035ed5f7b6156a5d6ffe9
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c8fed01c732fa20e1ae035ed5f7b6156a5d6ffe9

Author: Marek Olšák mar...@gmail.com
Date:   Wed Aug 24 23:58:43 2011 +0200

glsl_to_tgsi: remove unused code

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   79 
 src/mesa/state_tracker/st_glsl_to_tgsi.h   |1 -
 2 files changed, 0 insertions(+), 80 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 9cac309..2266083 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -2963,36 +2963,6 @@ set_uniform_initializer(struct gl_context *ctx, void 
*mem_ctx,
}
 }
 
-static void
-set_uniform_initializers(struct gl_context *ctx,
-struct gl_shader_program *shader_program)
-{
-   void *mem_ctx = NULL;
-
-   for (unsigned int i = 0; i  MESA_SHADER_TYPES; i++) {
-  struct gl_shader *shader = shader_program-_LinkedShaders[i];
-
-  if (shader == NULL)
- continue;
-
-  foreach_iter(exec_list_iterator, iter, *shader-ir) {
- ir_instruction *ir = (ir_instruction *)iter.get();
- ir_variable *var = ir-as_variable();
-
- if (!var || var-mode != ir_var_uniform || !var-constant_value)
-continue;
-
- if (!mem_ctx)
-mem_ctx = ralloc_context(NULL);
-
- set_uniform_initializer(ctx, mem_ctx, shader_program, var-name,
-var-type, var-constant_value);
-  }
-   }
-
-   ralloc_free(mem_ctx);
-}
-
 /*
  * Scan/rewrite program to remove reads of custom (output) registers.
  * The passed type has to be either PROGRAM_OUTPUT or PROGRAM_VARYING
@@ -5090,53 +5060,4 @@ st_link_shader(struct gl_context *ctx, struct 
gl_shader_program *prog)
return GL_TRUE;
 }
 
-
-/**
- * Link a GLSL shader program.  Called via glLinkProgram().
- */
-void
-st_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
-{
-   unsigned int i;
-
-   _mesa_clear_shader_program_data(ctx, prog);
-
-   prog-LinkStatus = GL_TRUE;
-
-   for (i = 0; i  prog-NumShaders; i++) {
-  if (!prog-Shaders[i]-CompileStatus) {
- fail_link(prog, linking with uncompiled shader);
- prog-LinkStatus = GL_FALSE;
-  }
-   }
-
-   prog-Varying = _mesa_new_parameter_list();
-   _mesa_reference_vertprog(ctx, prog-VertexProgram, NULL);
-   _mesa_reference_fragprog(ctx, prog-FragmentProgram, NULL);
-   _mesa_reference_geomprog(ctx, prog-GeometryProgram, NULL);
-
-   if (prog-LinkStatus) {
-  link_shaders(ctx, prog);
-   }
-
-   if (prog-LinkStatus) {
-  if (!ctx-Driver.LinkShader(ctx, prog)) {
- prog-LinkStatus = GL_FALSE;
-  }
-   }
-
-   set_uniform_initializers(ctx, prog);
-
-   if (ctx-Shader.Flags  GLSL_DUMP) {
-  if (!prog-LinkStatus) {
- printf(GLSL shader program %d failed to link\n, prog-Name);
-  }
-
-  if (prog-InfoLog  prog-InfoLog[0] != 0) {
- printf(GLSL shader program %d info log:\n, prog-Name);
- printf(%s\n, prog-InfoLog);
-  }
-   }
-}
-
 } /* extern C */
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.h 
b/src/mesa/state_tracker/st_glsl_to_tgsi.h
index d877471..fafe52e 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.h
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.h
@@ -64,7 +64,6 @@ struct gl_shader *st_new_shader(struct gl_context *ctx, 
GLuint name, GLuint type
 struct gl_shader_program *
 st_new_shader_program(struct gl_context *ctx, GLuint name);
 
-void st_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program 
*prog);
 GLboolean st_link_shader(struct gl_context *ctx, struct gl_shader_program 
*prog);
 
 #ifdef __cplusplus

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


Mesa (master): glsl_to_tgsi: implement ir_unop_logic_not using 1-x

2011-08-20 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 8c31bc704826d46cad65c4d65b4b70de7144205a
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=8c31bc704826d46cad65c4d65b4b70de7144205a

Author: Bryan Cain bryanca...@gmail.com
Date:   Wed Aug 17 10:01:30 2011 -0500

glsl_to_tgsi: implement ir_unop_logic_not using 1-x

Since our logic values are 0.0 (false) and 1.0 (true), 1.0 - x accurately
implements logical not.

This is a port of commit 6ad08989d7c1 to glsl_to_tgsi.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   12 +++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 886a177..73a647e 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1336,7 +1336,17 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
 
switch (ir-operation) {
case ir_unop_logic_not:
-  emit(ir, TGSI_OPCODE_SEQ, result_dst, op[0], 
st_src_reg_for_type(result_dst.type, 0));
+  if (result_dst.type != GLSL_TYPE_FLOAT)
+ emit(ir, TGSI_OPCODE_SEQ, result_dst, op[0], 
st_src_reg_for_type(result_dst.type, 0));
+  else {
+ /* Previously 'SEQ dst, src, 0.0' was used for this.  However, many
+  * older GPUs implement SEQ using multiple instructions (i915 uses two
+  * SGE instructions and a MUL instruction).  Since our logic values 
are
+  * 0.0 and 1.0, 1-x also implements !x.
+  */
+ op[0].negate = ~op[0].negate;
+ emit(ir, TGSI_OPCODE_ADD, result_dst, op[0], 
st_src_reg_for_float(1.0));
+  }
   break;
case ir_unop_neg:
   assert(result_dst.type == GLSL_TYPE_FLOAT || result_dst.type == 
GLSL_TYPE_INT);

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


Mesa (master): glsl_to_tgsi: implement ir_binop_logic_or using an add w/ saturate or add w/SLT

2011-08-20 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 691cc0e3a8716a2cdb7271765cd7d4c7465066eb
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=691cc0e3a8716a2cdb7271765cd7d4c7465066eb

Author: Bryan Cain bryanca...@gmail.com
Date:   Wed Aug 17 14:35:35 2011 -0500

glsl_to_tgsi: implement ir_binop_logic_or using an add w/saturate or add w/SLT

Logical-or is implemented using addition (followed by clamping to [0,1]) on
values of 0.0 and 1.0. Replacing the logical-or operators with addition gives
a + b which has a result on the range [0, 2].

Previously a SNE instruction was used to clamp the resulting logic value to
[0,1]. In a fragment shader, using a saturate on the add has the same effect.
Adding the saturate to the add is free, so (at least) one instruction is
saved. In a vertex shader, using an SLT on the negation of the add result has
the same effect. Many older shader architectures do not support the SNE
instruction. It must be emulated using two SLT instructions and an ADD. On
these architectures, the single SLT saves two instructions.

Note that SNE is still used when integers are used for boolean values, since
there is no such thing as an integer saturate, and older shader architectures
without SNE don't support integers.

This is a port of commit 41f8ffe5e07c to glsl_to_tgsi with integer support
added.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   31 ---
 1 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 73a647e..5f4aef1 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1493,11 +1493,34 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
   emit(ir, TGSI_OPCODE_SNE, result_dst, op[0], op[1]);
   break;
 
-   case ir_binop_logic_or:
-  /* This could be a saturated add and skip the SNE. */
-  emit(ir, TGSI_OPCODE_ADD, result_dst, op[0], op[1]);
-  emit(ir, TGSI_OPCODE_SNE, result_dst, result_src, 
st_src_reg_for_float(0.0));
+   case ir_binop_logic_or: {
+  /* After the addition, the value will be an integer on the
+   * range [0,2].  Zero stays zero, and positive values become 1.0.
+   */
+  glsl_to_tgsi_instruction *add =
+ emit(ir, TGSI_OPCODE_ADD, result_dst, op[0], op[1]);
+  if (this-prog-Target == GL_FRAGMENT_PROGRAM_ARB 
+  result_dst.type == GLSL_TYPE_FLOAT) {
+ /* The clamping to [0,1] can be done for free in the fragment
+  * shader with a saturate if floats are being used as boolean values.
+  */
+ add-saturate = true;
+  } else if (result_dst.type == GLSL_TYPE_FLOAT) {
+ /* Negating the result of the addition gives values on the range
+  * [-2, 0].  Zero stays zero, and negative values become 1.0.  This
+  * is achieved using SLT.
+  */
+ st_src_reg slt_src = result_src;
+ slt_src.negate = ~slt_src.negate;
+ emit(ir, TGSI_OPCODE_SLT, result_dst, slt_src, 
st_src_reg_for_float(0.0));
+  } else {
+ /* Use an SNE on the result of the addition.  Zero stays zero,
+  * 1 stays 1, and 2 becomes 1.
+  */
+ emit(ir, TGSI_OPCODE_SNE, result_dst, result_src, 
st_src_reg_for_int(0));
+  }
   break;
+   }
 
case ir_binop_logic_and:
   /* the bool args are stored as float 0.0 or 1.0, so mul gives us 
and. */

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


Mesa (master): glsl_to_tgsi: implement ir_unop_any using DP4 w/ saturate or DP4 w/SLT

2011-08-20 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: a43f68810a347f3e952a0bc401be6edb91e1baea
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=a43f68810a347f3e952a0bc401be6edb91e1baea

Author: Bryan Cain bryanca...@gmail.com
Date:   Sat Aug 20 13:26:12 2011 -0500

glsl_to_tgsi: implement ir_unop_any using DP4 w/saturate or DP4 w/SLT

This is a port of commit 92ca560d68e8 to glsl_to_tgsi, with integer support
added.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   32 ---
 1 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 62127af..f7d79e9 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1482,12 +1482,36 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
   }
   break;
 
-   case ir_unop_any:
+   case ir_unop_any: {
   assert(ir-operands[0]-type-is_vector());
-  emit_dp(ir, result_dst, op[0], op[0],
-  ir-operands[0]-type-vector_elements);
-  emit(ir, TGSI_OPCODE_SNE, result_dst, result_src, 
st_src_reg_for_float(0.0));
+
+  /* After the dot-product, the value will be an integer on the
+   * range [0,4].  Zero stays zero, and positive values become 1.0.
+   */
+  glsl_to_tgsi_instruction *const dp =
+ emit_dp(ir, result_dst, op[0], op[0],
+ ir-operands[0]-type-vector_elements);
+  if (this-prog-Target == GL_FRAGMENT_PROGRAM_ARB 
+  result_dst.type == GLSL_TYPE_FLOAT) {
+ /* The clamping to [0,1] can be done for free in the fragment
+  * shader with a saturate.
+  */
+ dp-saturate = true;
+  } else if (result_dst.type == GLSL_TYPE_FLOAT) {
+ /* Negating the result of the dot-product gives values on the 
range
+  * [-4, 0].  Zero stays zero, and negative values become 1.0.  
This
+  * is achieved using SLT.
+  */
+ st_src_reg slt_src = result_src;
+ slt_src.negate = ~slt_src.negate;
+ emit(ir, TGSI_OPCODE_SLT, result_dst, slt_src, 
st_src_reg_for_float(0.0));
+  }
+  else {
+ /* Use SNE 0 if integers are being used as boolean values. */
+ emit(ir, TGSI_OPCODE_SNE, result_dst, result_src, 
st_src_reg_for_int(0));
+  }
   break;
+   }
 
case ir_binop_logic_xor:
   emit(ir, TGSI_OPCODE_SNE, result_dst, op[0], op[1]);

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


Mesa (master): glsl_to_tgsi: make glsl_to_tgsi_visitor:: emit_dp return the instruction

2011-08-20 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: c15eb5569bf76c5dc41327017b92a5d960207b97
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c15eb5569bf76c5dc41327017b92a5d960207b97

Author: Bryan Cain bryanca...@gmail.com
Date:   Wed Aug 17 20:34:19 2011 -0500

glsl_to_tgsi: make glsl_to_tgsi_visitor::emit_dp return the instruction

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   14 +++---
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 5f4aef1..62127af 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -373,11 +373,11 @@ public:
/**
 * Emit the correct dot-product instruction for the type of arguments
 */
-   void emit_dp(ir_instruction *ir,
-st_dst_reg dst,
-st_src_reg src0,
-st_src_reg src1,
-unsigned elements);
+   glsl_to_tgsi_instruction *emit_dp(ir_instruction *ir,
+ st_dst_reg dst,
+ st_src_reg src0,
+ st_src_reg src1,
+ unsigned elements);
 
void emit_scalar(ir_instruction *ir, unsigned op,
st_dst_reg dst, st_src_reg src0);
@@ -642,7 +642,7 @@ glsl_to_tgsi_visitor::get_opcode(ir_instruction *ir, 
unsigned op,
return op;
 }
 
-void
+glsl_to_tgsi_instruction *
 glsl_to_tgsi_visitor::emit_dp(ir_instruction *ir,
st_dst_reg dst, st_src_reg src0, st_src_reg src1,
unsigned elements)
@@ -651,7 +651,7 @@ glsl_to_tgsi_visitor::emit_dp(ir_instruction *ir,
   TGSI_OPCODE_DP2, TGSI_OPCODE_DP3, TGSI_OPCODE_DP4
};
 
-   emit(ir, dot_opcodes[elements - 2], dst, src0, src1);
+   return emit(ir, dot_opcodes[elements - 2], dst, src0, src1);
 }
 
 /**

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


Mesa (master): glsl_to_tgsi: implement ir_binop_any_nequal using DP4 w/ saturate or DP4 w/SLT

2011-08-20 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: f3dce133f0422c42ca61f07f488237107efc30e6
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=f3dce133f0422c42ca61f07f488237107efc30e6

Author: Bryan Cain bryanca...@gmail.com
Date:   Sat Aug 20 13:56:06 2011 -0500

glsl_to_tgsi: implement ir_binop_any_nequal using DP4 w/saturate or DP4 w/SLT

Implement the any() part of the operation the same way regular ir_unop_any
is implemented.

This is a port of commit e7bf096e8b04 to glsl_to_tgsi, with added integer
support.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   25 +++--
 1 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index f7d79e9..b238c26 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1475,8 +1475,29 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
glsl_type::vec4_type);
  assert(ir-operands[0]-type-base_type == GLSL_TYPE_FLOAT);
  emit(ir, TGSI_OPCODE_SNE, st_dst_reg(temp), op[0], op[1]);
- emit_dp(ir, result_dst, temp, temp, vector_elements);
- emit(ir, TGSI_OPCODE_SNE, result_dst, result_src, 
st_src_reg_for_float(0.0));
+
+ /* After the dot-product, the value will be an integer on the
+  * range [0,4].  Zero stays zero, and positive values become 1.0.
+  */
+ glsl_to_tgsi_instruction *const dp =
+   emit_dp(ir, result_dst, temp, temp, vector_elements);
+ if (this-prog-Target == GL_FRAGMENT_PROGRAM_ARB 
+ result_dst.type == GLSL_TYPE_FLOAT) {
+/* The clamping to [0,1] can be done for free in the fragment
+ * shader with a saturate.
+ */
+dp-saturate = true;
+ } else if (result_dst.type == GLSL_TYPE_FLOAT) {
+/* Negating the result of the dot-product gives values on the range
+ * [-4, 0].  Zero stays zero, and negative values become 1.0.  This
+ * achieved using SLT.
+ */
+st_src_reg slt_src = result_src;
+slt_src.negate = ~slt_src.negate;
+emit(ir, TGSI_OPCODE_SLT, result_dst, slt_src, 
st_src_reg_for_float(0.0));
+ } else {
+emit(ir, TGSI_OPCODE_SNE, result_dst, result_src, 
st_src_reg_for_float(0.0));
+ }
   } else {
  emit(ir, TGSI_OPCODE_SNE, result_dst, op[0], op[1]);
   }

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


Mesa (master): glsl_to_tgsi: implement ir_binop_all_equal using DP4 w/SGE

2011-08-20 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 9098953ee6e0699e13e35183c817ecf40363d538
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=9098953ee6e0699e13e35183c817ecf40363d538

Author: Bryan Cain bryanca...@gmail.com
Date:   Sat Aug 20 14:15:03 2011 -0500

glsl_to_tgsi: implement ir_binop_all_equal using DP4 w/SGE

This is a port of commit ba01df11c4d0 to glsl_to_tgsi with integer support
added.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   20 +++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index b238c26..b211fc6 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1460,8 +1460,26 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
glsl_type::vec4_type);
  assert(ir-operands[0]-type-base_type == GLSL_TYPE_FLOAT);
  emit(ir, TGSI_OPCODE_SNE, st_dst_reg(temp), op[0], op[1]);
+ 
+ /* After the dot-product, the value will be an integer on the
+  * range [0,4].  Zero becomes 1.0, and positive values become zero.
+  */
  emit_dp(ir, result_dst, temp, temp, vector_elements);
- emit(ir, TGSI_OPCODE_SEQ, result_dst, result_src, 
st_src_reg_for_float(0.0));
+ 
+ if (result_dst.type == GLSL_TYPE_FLOAT) {
+/* Negating the result of the dot-product gives values on the range
+ * [-4, 0].  Zero becomes 1.0, and negative values become zero.
+ * This is achieved using SGE.
+ */
+st_src_reg sge_src = result_src;
+sge_src.negate = ~sge_src.negate;
+emit(ir, TGSI_OPCODE_SGE, result_dst, sge_src, 
st_src_reg_for_float(0.0));
+ } else {
+/* The TGSI negate flag doesn't work for integers, so use SEQ 0
+ * instead.
+ */
+emit(ir, TGSI_OPCODE_SEQ, result_dst, result_src, 
st_src_reg_for_int(0));
+ }
   } else {
  emit(ir, TGSI_OPCODE_SEQ, result_dst, op[0], op[1]);
   }

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


Mesa (master): glsl_to_tgsi: fix typo

2011-08-20 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: c721d7b7bc70503d2ebb6c742be96371b68bd152
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c721d7b7bc70503d2ebb6c742be96371b68bd152

Author: Bryan Cain bryanca...@gmail.com
Date:   Sat Aug 20 14:17:52 2011 -0500

glsl_to_tgsi: fix typo

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index b211fc6..2885630 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1514,7 +1514,7 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
 slt_src.negate = ~slt_src.negate;
 emit(ir, TGSI_OPCODE_SLT, result_dst, slt_src, 
st_src_reg_for_float(0.0));
  } else {
-emit(ir, TGSI_OPCODE_SNE, result_dst, result_src, 
st_src_reg_for_float(0.0));
+emit(ir, TGSI_OPCODE_SNE, result_dst, result_src, 
st_src_reg_for_int(0));
  }
   } else {
  emit(ir, TGSI_OPCODE_SNE, result_dst, op[0], op[1]);

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


Mesa (master): glsl_to_tgsi: emit a MAD(b, -a, b) for !a b

2011-08-20 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 5379a70d3fabd9cf92a615647f81289d33ae9468
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=5379a70d3fabd9cf92a615647f81289d33ae9468

Author: Bryan Cain bryanca...@gmail.com
Date:   Sat Aug 20 14:43:25 2011 -0500

glsl_to_tgsi: emit a MAD(b, -a, b) for !a  b

This is a port of commit ff2cfb8989cd to glsl_to_tgsi.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   52 
 1 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 2885630..a1f56d3 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -392,6 +392,8 @@ public:
 
GLboolean try_emit_mad(ir_expression *ir,
  int mul_operand);
+   bool try_emit_mad_for_and_not(ir_expression *ir,
+  int mul_operand);
GLboolean try_emit_sat(ir_expression *ir);
 
void emit_swz(ir_expression *ir);
@@ -1210,6 +1212,46 @@ glsl_to_tgsi_visitor::try_emit_mad(ir_expression *ir, 
int mul_operand)
return true;
 }
 
+/**
+ * Emit MAD(a, -b, a) instead of AND(a, NOT(b))
+ *
+ * The logic values are 1.0 for true and 0.0 for false.  Logical-and is
+ * implemented using multiplication, and logical-or is implemented using
+ * addition.  Logical-not can be implemented as (true - x), or (1.0 - x).
+ * As result, the logical expression (a  !b) can be rewritten as:
+ *
+ * - a * !b
+ * - a * (1 - b)
+ * - (a * 1) - (a * b)
+ * - a + -(a * b)
+ * - a + (a * -b)
+ *
+ * This final expression can be implemented as a single MAD(a, -b, a)
+ * instruction.
+ */
+bool
+glsl_to_tgsi_visitor::try_emit_mad_for_and_not(ir_expression *ir, int 
try_operand)
+{
+   const int other_operand = 1 - try_operand;
+   st_src_reg a, b;
+
+   ir_expression *expr = ir-operands[try_operand]-as_expression();
+   if (!expr || expr-operation != ir_unop_logic_not)
+  return false;
+
+   ir-operands[other_operand]-accept(this);
+   a = this-result;
+   expr-operands[0]-accept(this);
+   b = this-result;
+
+   b.negate = ~b.negate;
+
+   this-result = get_temp(ir-type);
+   emit(ir, TGSI_OPCODE_MAD, st_dst_reg(this-result), a, b, a);
+
+   return true;
+}
+
 GLboolean
 glsl_to_tgsi_visitor::try_emit_sat(ir_expression *ir)
 {
@@ -1291,6 +1333,16 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
   if (try_emit_mad(ir, 0))
  return;
}
+
+   /* Quick peephole: Emit OPCODE_MAD(-a, -b, a) instead of AND(a, NOT(b))
+*/
+   if (ir-operation == ir_binop_logic_and) {
+  if (try_emit_mad_for_and_not(ir, 1))
+return;
+  if (try_emit_mad_for_and_not(ir, 0))
+return;
+   }
+
if (try_emit_sat(ir))
   return;
 

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


Mesa (master): glsl_to_tgsi: improve assignment hack

2011-08-09 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: e6c64800cc8833fb4083a556c839b51e8ac84a8b
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=e6c64800cc8833fb4083a556c839b51e8ac84a8b

Author: Henri Verbeet hverb...@gmail.com
Date:   Tue Aug  9 12:23:47 2011 -0500

glsl_to_tgsi: improve assignment hack

Fixes StarCraft 2 and Fallout 3 in Wine.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index d7a1ba8..aef23e7 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1994,15 +1994,17 @@ glsl_to_tgsi_visitor::visit(ir_assignment *ir)
} else if (ir-rhs-as_expression() 
   this-instructions.get_tail() 
   ir-rhs == ((glsl_to_tgsi_instruction 
*)this-instructions.get_tail())-ir 
-  type_size(ir-lhs-type) == 1) {
+  type_size(ir-lhs-type) == 1 
+  l.writemask == ((glsl_to_tgsi_instruction 
*)this-instructions.get_tail())-dst.writemask) {
   /* To avoid emitting an extra MOV when assigning an expression to a 
* variable, emit the last instruction of the expression again, but
* replace the destination register with the target of the assignment.
* Dead code elimination will remove the original instruction.
*/
-  glsl_to_tgsi_instruction *inst;
+  glsl_to_tgsi_instruction *inst, *new_inst;
   inst = (glsl_to_tgsi_instruction *)this-instructions.get_tail();
-  emit(ir, inst-op, l, inst-src[0], inst-src[1], inst-src[2]);
+  new_inst = emit(ir, inst-op, l, inst-src[0], inst-src[1], 
inst-src[2]);
+  new_inst-saturate = inst-saturate;
} else {
   for (i = 0; i  type_size(ir-lhs-type); i++) {
  emit(ir, TGSI_OPCODE_MOV, l, r);

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


Mesa (master): st/mesa: inline st_prepare_fragment_program in st_translate_fragment_program

2011-08-08 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: ffb7d02154186402f64e0b628998485309774bb8
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=ffb7d02154186402f64e0b628998485309774bb8

Author: Bryan Cain bryanca...@gmail.com
Date:   Sun Aug  7 14:15:35 2011 -0500

st/mesa: inline st_prepare_fragment_program in st_translate_fragment_program

This reverts an unnecessary part of commit 4683529048ee and fixes misrendering
and an assertion failure in Cogs.

Fixes freedesktop.org bug 39888.

Reviewed-by: Brian Paul bri...@vmware.com

---

 src/mesa/state_tracker/st_program.c |  326 +--
 src/mesa/state_tracker/st_program.h |   15 --
 2 files changed, 162 insertions(+), 179 deletions(-)

diff --git a/src/mesa/state_tracker/st_program.c 
b/src/mesa/state_tracker/st_program.c
index ca01d2e..a4f47ed 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -416,151 +416,6 @@ st_get_vp_variant(struct st_context *st,
return vpv;
 }
 
-/**
- * Translate Mesa fragment shader attributes to TGSI attributes.
- * \return GL_TRUE if color output should be written to all render targets, 
- * GL_FALSE if not
- */
-GLboolean
-st_prepare_fragment_program(struct gl_context *ctx,
-struct st_fragment_program *stfp)
-{
-   GLuint attr;
-   const GLbitfield inputsRead = stfp-Base.Base.InputsRead;
-   GLboolean write_all = GL_FALSE;
-
-   /*
-* Convert Mesa program inputs to TGSI input register semantics.
-*/
-   for (attr = 0; attr  FRAG_ATTRIB_MAX; attr++) {
-  if (inputsRead  (1  attr)) {
- const GLuint slot = stfp-num_inputs++;
-
- stfp-input_to_index[attr] = slot;
-
- switch (attr) {
- case FRAG_ATTRIB_WPOS:
-stfp-input_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
-stfp-input_semantic_index[slot] = 0;
-stfp-interp_mode[slot] = TGSI_INTERPOLATE_LINEAR;
-break;
- case FRAG_ATTRIB_COL0:
-stfp-input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
-stfp-input_semantic_index[slot] = 0;
-stfp-interp_mode[slot] = TGSI_INTERPOLATE_LINEAR;
-break;
- case FRAG_ATTRIB_COL1:
-stfp-input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
-stfp-input_semantic_index[slot] = 1;
-stfp-interp_mode[slot] = TGSI_INTERPOLATE_LINEAR;
-break;
- case FRAG_ATTRIB_FOGC:
-stfp-input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
-stfp-input_semantic_index[slot] = 0;
-stfp-interp_mode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
-break;
- case FRAG_ATTRIB_FACE:
-stfp-input_semantic_name[slot] = TGSI_SEMANTIC_FACE;
-stfp-input_semantic_index[slot] = 0;
-stfp-interp_mode[slot] = TGSI_INTERPOLATE_CONSTANT;
-break;
-/* In most cases, there is nothing special about these
- * inputs, so adopt a convention to use the generic
- * semantic name and the mesa FRAG_ATTRIB_ number as the
- * index. 
- * 
- * All that is required is that the vertex shader labels
- * its own outputs similarly, and that the vertex shader
- * generates at least every output required by the
- * fragment shader plus fixed-function hardware (such as
- * BFC).
- * 
- * There is no requirement that semantic indexes start at
- * zero or be restricted to a particular range -- nobody
- * should be building tables based on semantic index.
- */
- case FRAG_ATTRIB_PNTC:
- case FRAG_ATTRIB_TEX0:
- case FRAG_ATTRIB_TEX1:
- case FRAG_ATTRIB_TEX2:
- case FRAG_ATTRIB_TEX3:
- case FRAG_ATTRIB_TEX4:
- case FRAG_ATTRIB_TEX5:
- case FRAG_ATTRIB_TEX6:
- case FRAG_ATTRIB_TEX7:
- case FRAG_ATTRIB_VAR0:
- default:
-/* Actually, let's try and zero-base this just for
- * readability of the generated TGSI.
- */
-assert(attr = FRAG_ATTRIB_TEX0);
-stfp-input_semantic_index[slot] = (attr - FRAG_ATTRIB_TEX0);
-stfp-input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
-if (attr == FRAG_ATTRIB_PNTC)
-   stfp-interp_mode[slot] = TGSI_INTERPOLATE_LINEAR;
-else
-   stfp-interp_mode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
-break;
- }
-  }
-  else {
- stfp-input_to_index[attr] = -1;
-  }
-   }
-
-   /*
-* Semantics and mapping for outputs
-*/
-   {
-  uint numColors = 0;
-  GLbitfield64 outputsWritten = stfp-Base.Base.OutputsWritten;
-
-  /* if z is written, emit that first */
-  if (outputsWritten  BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
- stfp-output_semantic_name[stfp-num_outputs

Mesa (master): glsl_to_tgsi: try to avoid emitting a MOV_SAT to saturate an expression tree

2011-08-05 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: b44648c9186d403abaeeeb3190d6759f951a49e4
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=b44648c9186d403abaeeeb3190d6759f951a49e4

Author: Bryan Cain bryanca...@gmail.com
Date:   Fri Aug  5 14:09:37 2011 -0500

glsl_to_tgsi: try to avoid emitting a MOV_SAT to saturate an expression tree

This is a port of commit 62722d9 to glsl_to_tgsi, with minor aesthetic
changes (moved the declaration and assignment of new_inst inside the if block).

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   32 ++-
 1 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 460bafb..e10243a 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1232,12 +1232,32 @@ glsl_to_tgsi_visitor::try_emit_sat(ir_expression *ir)
sat_src-accept(this);
st_src_reg src = this-result;
 
-   this-result = get_temp(ir-type);
-   st_dst_reg result_dst = st_dst_reg(this-result);
-   result_dst.writemask = (1  ir-type-vector_elements) - 1;
-   glsl_to_tgsi_instruction *inst;
-   inst = emit(ir, TGSI_OPCODE_MOV, result_dst, src);
-   inst-saturate = true;
+   /* If we generated an expression instruction into a temporary in
+* processing the saturate's operand, apply the saturate to that
+* instruction.  Otherwise, generate a MOV to do the saturate.
+*
+* Note that we have to be careful to only do this optimization if
+* the instruction in question was what generated src-result.  For
+* example, ir_dereference_array might generate a MUL instruction
+* to create the reladdr, and return us a src reg using that
+* reladdr.  That MUL result is not the value we're trying to
+* saturate.
+*/
+   ir_expression *sat_src_expr = sat_src-as_expression();
+   if (sat_src_expr  (sat_src_expr-operation == ir_binop_mul ||
+   sat_src_expr-operation == ir_binop_add ||
+   sat_src_expr-operation == ir_binop_dot)) {
+  glsl_to_tgsi_instruction *new_inst;
+  new_inst = (glsl_to_tgsi_instruction *)this-instructions.get_tail();
+  new_inst-saturate = true;
+   } else {
+  this-result = get_temp(ir-type);
+  st_dst_reg result_dst = st_dst_reg(this-result);
+  result_dst.writemask = (1  ir-type-vector_elements) - 1;
+  glsl_to_tgsi_instruction *inst;
+  inst = emit(ir, TGSI_OPCODE_MOV, result_dst, src);
+  inst-saturate = true;
+   }
 
return true;
 }

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


Mesa (master): glsl_to_tgsi: replace open-coded swizzle_for_size()

2011-08-05 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 5164244df02f33d6ad9e0a286f4b6d6af2dfbc75
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=5164244df02f33d6ad9e0a286f4b6d6af2dfbc75

Author: Bryan Cain bryanca...@gmail.com
Date:   Fri Aug  5 14:37:33 2011 -0500

glsl_to_tgsi: replace open-coded swizzle_for_size()

This is a port of commit 4c7e215c7bb to glsl_to_tgsi.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |9 +
 1 files changed, 1 insertions(+), 8 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index e10243a..d7a1ba8 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -949,8 +949,6 @@ st_src_reg
 glsl_to_tgsi_visitor::get_temp(const glsl_type *type)
 {
st_src_reg src;
-   int swizzle[4];
-   int i;
 
src.type = glsl_version = 130 ? type-base_type : GLSL_TYPE_FLOAT;
src.file = PROGRAM_TEMPORARY;
@@ -961,12 +959,7 @@ glsl_to_tgsi_visitor::get_temp(const glsl_type *type)
if (type-is_array() || type-is_record()) {
   src.swizzle = SWIZZLE_NOOP;
} else {
-  for (i = 0; i  type-vector_elements; i++)
- swizzle[i] = i;
-  for (; i  4; i++)
- swizzle[i] = type-vector_elements - 1;
-  src.swizzle = MAKE_SWIZZLE4(swizzle[0], swizzle[1],
- swizzle[2], swizzle[3]);
+  src.swizzle = swizzle_for_size(type-vector_elements);
}
src.negate = 0;
 

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


Mesa (glsl-to-tgsi): st/mesa: replace duplicated create_color_map_texture() function with shared function

2011-08-04 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 95208751c0228f0a82347563c3b5f638c1096ec3
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=95208751c0228f0a82347563c3b5f638c1096ec3

Author: Bryan Cain bryanca...@gmail.com
Date:   Thu Aug  4 10:15:54 2011 -0500

st/mesa: replace duplicated create_color_map_texture() function with shared 
function

---

 src/mesa/state_tracker/st_atom_pixeltransfer.c |   22 +-
 src/mesa/state_tracker/st_cb_drawpixels.c  |   23 +--
 src/mesa/state_tracker/st_texture.c|   20 
 src/mesa/state_tracker/st_texture.h|4 
 4 files changed, 26 insertions(+), 43 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c 
b/src/mesa/state_tracker/st_atom_pixeltransfer.c
index 95b706c..12b5bc5 100644
--- a/src/mesa/state_tracker/st_atom_pixeltransfer.c
+++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c
@@ -84,26 +84,6 @@ make_state_key(struct gl_context *ctx,  struct state_key 
*key)
 }
 
 
-static struct pipe_resource *
-create_color_map_texture(struct gl_context *ctx)
-{
-   struct st_context *st = st_context(ctx);
-   struct pipe_context *pipe = st-pipe;
-   struct pipe_resource *pt;
-   enum pipe_format format;
-   const uint texSize = 256; /* simple, and usually perfect */
-
-   /* find an RGBA texture format */
-   format = st_choose_format(pipe-screen, GL_RGBA,
- PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW);
-
-   /* create texture for color map/table */
-   pt = st_texture_create(st, PIPE_TEXTURE_2D, format, 0,
-  texSize, texSize, 1, 1, PIPE_BIND_SAMPLER_VIEW);
-   return pt;
-}
-
-
 /**
  * Update the pixelmap texture with the contents of the R/G/B/A pixel maps.
  */
@@ -219,7 +199,7 @@ get_pixel_transfer_program(struct gl_context *ctx, const 
struct state_key *key)
 
   /* create the colormap/texture now if not already done */
   if (!st-pixel_xfer.pixelmap_texture) {
- st-pixel_xfer.pixelmap_texture = create_color_map_texture(ctx);
+ st-pixel_xfer.pixelmap_texture = st_create_color_map_texture(ctx);
  st-pixel_xfer.pixelmap_sampler_view =
 st_create_texture_sampler_view(st-pipe,
st-pixel_xfer.pixelmap_texture);
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c 
b/src/mesa/state_tracker/st_cb_drawpixels.c
index f4dd2a4..0c4dc23 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -94,27 +94,6 @@ is_passthrough_program(const struct gl_fragment_program 
*prog)
 }
 
 
-/* XXX copied verbatim from st_atom_pixeltransfer.c */
-static struct pipe_resource *
-create_color_map_texture(struct gl_context *ctx)
-{
-   struct st_context *st = st_context(ctx);
-   struct pipe_context *pipe = st-pipe;
-   struct pipe_resource *pt;
-   enum pipe_format format;
-   const uint texSize = 256; /* simple, and usually perfect */
-
-   /* find an RGBA texture format */
-   format = st_choose_format(pipe-screen, GL_RGBA,
- PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW);
-
-   /* create texture for color map/table */
-   pt = st_texture_create(st, PIPE_TEXTURE_2D, format, 0,
-  texSize, texSize, 1, 1, PIPE_BIND_SAMPLER_VIEW);
-   return pt;
-}
-
-
 /**
  * Returns a fragment program which implements the current pixel transfer ops.
  */
@@ -142,7 +121,7 @@ get_glsl_pixel_transfer_program(struct st_context *st,
if (pixelMaps) {
   /* create the colormap/texture now if not already done */
   if (!st-pixel_xfer.pixelmap_texture) {
- st-pixel_xfer.pixelmap_texture = create_color_map_texture(ctx);
+ st-pixel_xfer.pixelmap_texture = st_create_color_map_texture(ctx);
  st-pixel_xfer.pixelmap_sampler_view =
 st_create_texture_sampler_view(st-pipe,
st-pixel_xfer.pixelmap_texture);
diff --git a/src/mesa/state_tracker/st_texture.c 
b/src/mesa/state_tracker/st_texture.c
index ffe7e25..d8ba3ac 100644
--- a/src/mesa/state_tracker/st_texture.c
+++ b/src/mesa/state_tracker/st_texture.c
@@ -396,3 +396,23 @@ st_texture_image_copy(struct pipe_context *pipe,
}
 }
 
+
+struct pipe_resource *
+st_create_color_map_texture(struct gl_context *ctx)
+{
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st-pipe;
+   struct pipe_resource *pt;
+   enum pipe_format format;
+   const uint texSize = 256; /* simple, and usually perfect */
+
+   /* find an RGBA texture format */
+   format = st_choose_format(pipe-screen, GL_RGBA,
+ PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW);
+
+   /* create texture for color map/table */
+   pt = st_texture_create(st, PIPE_TEXTURE_2D, format, 0,
+  texSize, texSize, 1, 1, PIPE_BIND_SAMPLER_VIEW);
+   return pt;
+}
+
diff --git a/src/mesa/state_tracker/st_texture.h 
b/src/mesa

Mesa (master): 46 new commits

2011-08-04 Thread Bryan Cain
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=4683529048ee133481b2d8f1cae1685aa1736f9a
Merge: 50073563b2bfe3716b3dc8b1ed2f91381ba24305 
9adcab9cd464d659288e31e6767efb5dee3894ff
Author: Bryan Cain bryanca...@gmail.com
Date:   Thu Aug 4 15:43:34 2011 -0500

Merge branch 'glsl-to-tgsi'

Conflicts:
src/mesa/state_tracker/st_atom_pixeltransfer.c
src/mesa/state_tracker/st_program.c

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=9adcab9cd464d659288e31e6767efb5dee3894ff
Author: Bryan Cain bryanca...@gmail.com
Date:   Thu Aug 4 10:15:54 2011 -0500

st/mesa: replace duplicated create_color_map_texture() function with shared 
function

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=b7e89115310628310bf458a33f2df2bf23384cf3
Author: Bryan Cain bryanca...@gmail.com
Date:   Tue Aug 2 11:36:44 2011 -0500

glsl_to_tgsi: remove debugging printf

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=189e9f12c7d3a82d7dd28695935a83e4319bb267
Author: Bryan Cain bryanca...@gmail.com
Date:   Wed Jul 27 16:39:40 2011 -0500

glsl_to_tgsi: copy reladdr in st_src_reg(st_dst_reg) constructor

This is a glsl_to_tgsi port of commit f7cd9a858c04.

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=3e7fce9773ec332665326a785b6ed1fcf5bd578e
Author: Bryan Cain bryanca...@gmail.com
Date:   Wed Jul 27 16:36:10 2011 -0500

glsl_to_tgsi: add each relative address to the previous

This is a glsl_to_tgsi port of commit d6e1a8f71437.

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=10d31cb307f90a08fafed5c67945ffe53d279940
Author: Bryan Cain bryanca...@gmail.com
Date:   Wed Jul 27 15:45:16 2011 -0500

glsl_to_tgsi: lower all ir_quadop_vector expressions

Unlike Mesa IR, TGSI doesn't have a SWZ opcode.

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=3354a5b56398f90fc36ab14b6444aae27b50e859
Author: Bryan Cain bryanca...@gmail.com
Date:   Wed Jul 27 15:20:19 2011 -0500

glsl_to_tgsi: rework immediate tracking to not use gl_program_parameter_list

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=f751730ad003bb19ce85bc4d0abddaf40edde6c1
Author: Bryan Cain bryanca...@gmail.com
Date:   Fri Jul 22 13:24:42 2011 -0500

glsl_to_tgsi: update comments

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=a2c3b9f38d81f363bd62abc87dc3abef2beeba95
Author: Bryan Cain bryanca...@gmail.com
Date:   Fri Jul 22 13:23:26 2011 -0500

glsl_to_tgsi: make coding style more consistent

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=0da994a9f15b461d16cf88ce16dc07e98dfada6f
Author: Bryan Cain bryanca...@gmail.com
Date:   Thu Jul 21 16:29:56 2011 -0500

glsl_to_tgsi: make assignment hack safer

Fixes an assertion failure in piglit test glsl-texcoord-array.

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=7732822c833ee22e259af3f8bd2bfb57c986612e
Author: Bryan Cain bryanca...@gmail.com
Date:   Thu Jul 21 15:49:26 2011 -0500

glsl_to_tgsi: separate immediates from array constants during IR translation

Before, if any uniform or constant array was accessed with indirect
addressing, st_translate_program() would emit uniform constants in the place
of immediates.  This behavior was unavoidable with ir_to_mesa/mesa_to_tgsi, 
but
glsl_to_tgsi can work around it since the GLSL IR backend and the TGSI
emission are both inside the state tracker.

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=87f8d8547db9b947ae847c509a464e06d0ac6c64
Author: Bryan Cain bryanca...@gmail.com
Date:   Sun Jul 10 17:36:04 2011 -0500

glsl_to_tgsi: fix mistakes in get_pixel_transfer_visitor()

I noticed these issues while working on get_bitmap_visitor().

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=5f0b4b0e9d376f9ec1cb5ae08c36052f4f51ac37
Author: Bryan Cain bryanca...@gmail.com
Date:   Sun Jul 10 17:17:38 2011 -0500

st/mesa, glsl_to_tgsi: support glBitmap with a GLSL fragment shader active

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c0dcab2882a4731dccd363a40c3ebcabc88b9c5d
Author: Bryan Cain bryanca...@gmail.com
Date:   Fri Jul 8 21:12:08 2011 -0500

st/mesa, glsl_to_tgsi: support glDrawPixels/glCopyPixels with a GLSL 
fragment shader active

Since this was previously implemented using Mesa IR and 
_mesa_combine_programs,
this commit adds a new code path that works with glsl_to_tgsi.

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=33e0c47b05c8fbae9d7af57ba65b612825b5db60
Author: Bryan Cain bryanca...@gmail.com
Date:   Mon Jul 4 08:44:12 2011 -0500

glsl_to_tgsi: replace MAX_PROGRAM_TEMPS (256) with MAX_TEMPS (4096)

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=54db6e618e43abbd69b59e0a03e2b6ec83d3120f
Author: Bryan Cain bryanca...@gmail.com
Date:   Thu Jun 30 13:42:37 2011 -0500

r200, r600c, i965: fix build

URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id

Mesa (glsl-to-tgsi): glsl_to_tgsi: remove debugging printf

2011-08-02 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: a4e35eacebdd6501406dd7f787e79602141e4af0
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=a4e35eacebdd6501406dd7f787e79602141e4af0

Author: Bryan Cain bryanca...@gmail.com
Date:   Tue Aug  2 11:36:44 2011 -0500

glsl_to_tgsi: remove debugging printf

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index ba4074e..b5f4253 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -840,7 +840,6 @@ glsl_to_tgsi_visitor::add_constant(gl_register_file file,
   int index = 0;
   immediate_storage *entry;
   assert(file == PROGRAM_IMMEDIATE);
-  fprintf(stderr, adding immediate\n);
 
   /* Search immediate storage to see if we already have an identical
* immediate that we can use instead of adding a duplicate entry.

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


Mesa (glsl-to-tgsi): glsl_to_tgsi: make coding style more consistent

2011-07-27 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 0acd60883ab2e679cc943ab3581c7b9a68286f80
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=0acd60883ab2e679cc943ab3581c7b9a68286f80

Author: Bryan Cain bryanca...@gmail.com
Date:   Fri Jul 22 13:23:26 2011 -0500

glsl_to_tgsi: make coding style more consistent

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  263 +---
 1 files changed, 126 insertions(+), 137 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 6e01a44..952900a 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -3778,15 +3778,14 @@ static unsigned 
mesa_sysval_to_semantic[SYSTEM_VALUE_MAX] = {
  * of labels built here and patch the TGSI code with the actual
  * location of each label.
  */
-static unsigned *get_label( struct st_translate *t,
-unsigned branch_target )
+static unsigned *get_label(struct st_translate *t, unsigned branch_target)
 {
unsigned i;
 
if (t-labels_count + 1 = t-labels_size) {
   t-labels_size = 1  (util_logbase2(t-labels_size) + 1);
   t-labels = (struct label *)realloc(t-labels, 
-  t-labels_size * sizeof 
t-labels[0]);
+  t-labels_size * sizeof(struct 
label));
   if (t-labels == NULL) {
  static unsigned dummy;
  t-error = TRUE;
@@ -3805,12 +3804,11 @@ static unsigned *get_label( struct st_translate *t,
  * Update the insn[] array so the next Mesa instruction points to
  * the next TGSI instruction.
  */
-static void set_insn_start( struct st_translate *t,
-unsigned start )
+static void set_insn_start(struct st_translate *t, unsigned start)
 {
if (t-insn_count + 1 = t-insn_size) {
   t-insn_size = 1  (util_logbase2(t-insn_size) + 1);
-  t-insn = (unsigned *)realloc(t-insn, t-insn_size * sizeof t-insn[0]);
+  t-insn = (unsigned *)realloc(t-insn, t-insn_size * 
sizeof(t-insn[0]));
   if (t-insn == NULL) {
  t-error = TRUE;
  return;
@@ -3824,9 +3822,9 @@ static void set_insn_start( struct st_translate *t,
  * Map a glsl_to_tgsi constant/immediate to a TGSI immediate.
  */
 static struct ureg_src
-emit_immediate( struct st_translate *t,
-struct gl_program_parameter_list *params,
-int index)
+emit_immediate(struct st_translate *t,
+   struct gl_program_parameter_list *params,
+   int index)
 {
struct ureg_program *ureg = t-ureg;
 
@@ -3861,17 +3859,17 @@ emit_immediate( struct st_translate *t,
  * Map a Mesa dst register to a TGSI ureg_dst register.
  */
 static struct ureg_dst
-dst_register( struct st_translate *t,
-  gl_register_file file,
-  GLuint index )
+dst_register(struct st_translate *t,
+ gl_register_file file,
+ GLuint index)
 {
-   switch( file ) {
+   switch(file) {
case PROGRAM_UNDEFINED:
   return ureg_dst_undef();
 
case PROGRAM_TEMPORARY:
   if (ureg_dst_is_undef(t-temps[index]))
- t-temps[index] = ureg_DECL_temporary( t-ureg );
+ t-temps[index] = ureg_DECL_temporary(t-ureg);
 
   return t-temps[index];
 
@@ -3894,7 +3892,7 @@ dst_register( struct st_translate *t,
   return t-address[index];
 
default:
-  debug_assert( 0 );
+  assert(!unknown dst register file);
   return ureg_dst_undef();
}
 }
@@ -3903,11 +3901,11 @@ dst_register( struct st_translate *t,
  * Map a Mesa src register to a TGSI ureg_src register.
  */
 static struct ureg_src
-src_register( struct st_translate *t,
-  gl_register_file file,
-  GLuint index )
+src_register(struct st_translate *t,
+ gl_register_file file,
+ GLuint index)
 {
-   switch( file ) {
+   switch(file) {
case PROGRAM_UNDEFINED:
   return ureg_src_undef();
 
@@ -3915,7 +3913,7 @@ src_register( struct st_translate *t,
   assert(index = 0);
   assert(index  Elements(t-temps));
   if (ureg_dst_is_undef(t-temps[index]))
- t-temps[index] = ureg_DECL_temporary( t-ureg );
+ t-temps[index] = ureg_DECL_temporary(t-ureg);
   return ureg_src(t-temps[index]);
 
case PROGRAM_NAMED_PARAM:
@@ -3927,7 +3925,7 @@ src_register( struct st_translate *t,
case PROGRAM_STATE_VAR:
case PROGRAM_CONSTANT:   /* ie, immediate */
   if (index  0)
- return ureg_DECL_constant( t-ureg, 0 );
+ return ureg_DECL_constant(t-ureg, 0);
   else
  return t-constants[index];
 
@@ -3950,7 +3948,7 @@ src_register( struct st_translate *t,
   return t-systemValues[index];
 
default:
-  debug_assert( 0 );
+  assert(!unknown src register file);
   return ureg_src_undef();
}
 }
@@ -3959,22 +3957,21 @@ src_register( struct st_translate *t,
  * Create a TGSI ureg_dst register from

Mesa (glsl-to-tgsi): glsl_to_tgsi: update comments

2011-07-27 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: ff6383c12a1f8f4e66bccadbab59191b3c9213cd
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=ff6383c12a1f8f4e66bccadbab59191b3c9213cd

Author: Bryan Cain bryanca...@gmail.com
Date:   Fri Jul 22 13:24:42 2011 -0500

glsl_to_tgsi: update comments

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   23 +++
 1 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 952900a..3a69a43 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -236,7 +236,7 @@ public:
/**
 * identifier of this function signature used by the program.
 *
-* At the point that Mesa instructions for function calls are
+* At the point that TGSI instructions for function calls are
 * generated, we don't know the address of the first instruction of
 * the function body.  So we make the BranchTarget that is called a
 * small integer and rewrite them during set_branchtargets().
@@ -251,10 +251,9 @@ public:
glsl_to_tgsi_instruction *bgn_inst;
 
/**
-* Index of the first instruction of the function body in actual
-* Mesa IR.
+* Index of the first instruction of the function body in actual TGSI.
 *
-* Set after convertion from glsl_to_tgsi_instruction to prog_instruction.
+* Set after conversion from glsl_to_tgsi_instruction to TGSI.
 */
int inst;
 
@@ -1672,7 +1671,7 @@ glsl_to_tgsi_visitor::visit(ir_dereference_array *ir)
} else {
   st_src_reg array_base = this-result;
   /* Variable index array dereference.  It eats the vec4 of the
-   * base of the array and an index that offsets the Mesa register
+   * base of the array and an index that offsets the TGSI register
* index.
*/
   ir-array_index-accept(this);
@@ -1879,7 +1878,7 @@ glsl_to_tgsi_visitor::visit(ir_assignment *ir)
   /* Swizzle a small RHS vector into the channels being written.
*
* glsl ir treats write_mask as dictating how many channels are
-   * present on the RHS while Mesa IR treats write_mask as just
+   * present on the RHS while TGSI treats write_mask as just
* showing which channels of the vec4 RHS get written.
*/
   for (int i = 0; i  4; i++) {
@@ -2202,8 +2201,8 @@ glsl_to_tgsi_visitor::visit(ir_texture *ir)
 
/* Put our coords in a temp.  We'll need to modify them for shadow,
 * projection, or LOD, so the only case we'd use it as is is if
-* we're doing plain old texturing.  Mesa IR optimization should
-* handle cleaning up our mess in that case.
+* we're doing plain old texturing.  The optimization passes on
+* glsl_to_tgsi_visitor should handle cleaning up our mess in that case.
 */
coord = get_temp(glsl_type::vec4_type);
coord_dst = st_dst_reg(coord);
@@ -3799,9 +3798,9 @@ static unsigned *get_label(struct st_translate *t, 
unsigned branch_target)
 }
 
 /**
- * Called prior to emitting the TGSI code for each Mesa instruction.
+ * Called prior to emitting the TGSI code for each instruction.
  * Allocate additional space for instructions if needed.
- * Update the insn[] array so the next Mesa instruction points to
+ * Update the insn[] array so the next glsl_to_tgsi_instruction points to
  * the next TGSI instruction.
  */
 static void set_insn_start(struct st_translate *t, unsigned start)
@@ -3856,7 +3855,7 @@ emit_immediate(struct st_translate *t,
 }
 
 /**
- * Map a Mesa dst register to a TGSI ureg_dst register.
+ * Map a glsl_to_tgsi dst register to a TGSI ureg_dst register.
  */
 static struct ureg_dst
 dst_register(struct st_translate *t,
@@ -3898,7 +3897,7 @@ dst_register(struct st_translate *t,
 }
 
 /**
- * Map a Mesa src register to a TGSI ureg_src register.
+ * Map a glsl_to_tgsi src register to a TGSI ureg_src register.
  */
 static struct ureg_src
 src_register(struct st_translate *t,

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


Mesa (glsl-to-tgsi): glsl_to_tgsi: lower all ir_quadop_vector expressions

2011-07-27 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: c236d3997d1a6d8f4d602c80639cdf331a294c36
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c236d3997d1a6d8f4d602c80639cdf331a294c36

Author: Bryan Cain bryanca...@gmail.com
Date:   Wed Jul 27 15:45:16 2011 -0500

glsl_to_tgsi: lower all ir_quadop_vector expressions

Unlike Mesa IR, TGSI doesn't have a SWZ opcode.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 6039488..0cbfc94 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -4825,7 +4825,7 @@ st_link_shader(struct gl_context *ctx, struct 
gl_shader_program *prog)
 
  progress = do_common_optimization(ir, true, 
options-MaxUnrollIterations) || progress;
 
- progress = lower_quadop_vector(ir, true) || progress;
+ progress = lower_quadop_vector(ir, false) || progress;
 
  if (options-EmitNoIfs) {
 progress = lower_discard(ir) || progress;

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


Mesa (glsl-to-tgsi): glsl_to_tgsi: add each relative address to the previous

2011-07-27 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 36e90af8f88a92cafaac62f57c92aa03c61ce9f3
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=36e90af8f88a92cafaac62f57c92aa03c61ce9f3

Author: Bryan Cain bryanca...@gmail.com
Date:   Wed Jul 27 16:36:10 2011 -0500

glsl_to_tgsi: add each relative address to the previous

This is a glsl_to_tgsi port of commit d6e1a8f71437.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   12 
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 0cbfc94..f66e240 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1741,6 +1741,18 @@ glsl_to_tgsi_visitor::visit(ir_dereference_array *ir)
   this-result, st_src_reg_for_float(element_size));
   }
 
+  /* If there was already a relative address register involved, add the
+   * new and the old together to get the new offset.
+   */
+  if (src.reladdr != NULL) {
+ st_src_reg accum_reg = get_temp(glsl_type::float_type);
+
+ emit(ir, TGSI_OPCODE_ADD, st_dst_reg(accum_reg),
+  index_reg, *src.reladdr);
+
+ index_reg = accum_reg;
+  }
+
   src.reladdr = ralloc(mem_ctx, st_src_reg);
   memcpy(src.reladdr, index_reg, sizeof(index_reg));
}

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


Mesa (master): st/mesa: respect force_s3tc_enable environment variable

2011-07-26 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 95739f19ccc8d3915c437238ca057ddbecd193c6
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=95739f19ccc8d3915c437238ca057ddbecd193c6

Author: Bryan Cain bryanca...@gmail.com
Date:   Mon Jul 25 13:30:17 2011 -0500

st/mesa: respect force_s3tc_enable environment variable

NOTE: This is a candidate for the 7.10 and 7.11 branches.

---

 src/mesa/state_tracker/st_extensions.c |   11 ++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/src/mesa/state_tracker/st_extensions.c 
b/src/mesa/state_tracker/st_extensions.c
index 99b231d..b5f6d35 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -208,6 +208,15 @@ void st_init_limits(struct st_context *st)
 }
 
 
+static GLboolean st_get_s3tc_override(void)
+{
+   const char *override = _mesa_getenv(force_s3tc_enable);
+   if (override  !strcmp(override, true))
+  return GL_TRUE;
+   return GL_FALSE;
+}
+
+
 /**
  * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
  * which GL extensions are supported.
@@ -426,7 +435,7 @@ void st_init_extensions(struct st_context *st)
if (screen-is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA,
PIPE_TEXTURE_2D, 0,
PIPE_BIND_SAMPLER_VIEW) 
-   ctx-Mesa_DXTn) {
+   (ctx-Mesa_DXTn || st_get_s3tc_override())) {
   ctx-Extensions.EXT_texture_compression_s3tc = GL_TRUE;
   ctx-Extensions.S3_s3tc = GL_TRUE;
}

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


Mesa (master): util: enable S3TC support when the force_s3tc_enable env var is set to true

2011-07-26 Thread Bryan Cain
Module: Mesa
Branch: master
Commit: 860c51d82711936d343b55aafb46befc8c032fe6
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=860c51d82711936d343b55aafb46befc8c032fe6

Author: Bryan Cain bryanca...@gmail.com
Date:   Wed Jul 20 17:35:22 2011 -0500

util: enable S3TC support when the force_s3tc_enable env var is set to true

NOTE: This is a candidate for the 7.10 and 7.11 branches.

---

 src/gallium/auxiliary/util/u_format_s3tc.c |   11 +--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_format_s3tc.c 
b/src/gallium/auxiliary/util/u_format_s3tc.c
index bb989c2..d8a7c0d 100644
--- a/src/gallium/auxiliary/util/u_format_s3tc.c
+++ b/src/gallium/auxiliary/util/u_format_s3tc.c
@@ -119,8 +119,15 @@ util_format_s3tc_init(void)
 
library = util_dl_open(DXTN_LIBNAME);
if (!library) {
-  debug_printf(couldn't open  DXTN_LIBNAME , software DXTn 
- compression/decompression unavailable\n);
+  if (getenv(force_s3tc_enable) 
+  !strcmp(getenv(force_s3tc_enable), true)) {
+ debug_printf(couldn't open  DXTN_LIBNAME , enabling DXTn due to 
+force_s3tc_enable=true environment variable\n);
+ util_format_s3tc_enabled = TRUE;
+  } else {
+ debug_printf(couldn't open  DXTN_LIBNAME , software DXTn 
+compression/decompression unavailable\n);
+  }
   return;
}
 

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


Mesa (7.11): st/mesa: respect force_s3tc_enable environment variable

2011-07-26 Thread Bryan Cain
Module: Mesa
Branch: 7.11
Commit: 208bae4251984d9fde02bc7f54022c02daeb3d6a
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=208bae4251984d9fde02bc7f54022c02daeb3d6a

Author: Bryan Cain bryanca...@gmail.com
Date:   Mon Jul 25 13:30:17 2011 -0500

st/mesa: respect force_s3tc_enable environment variable

NOTE: This is a candidate for the 7.10 and 7.11 branches.

---

 src/mesa/state_tracker/st_extensions.c |   11 ++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/src/mesa/state_tracker/st_extensions.c 
b/src/mesa/state_tracker/st_extensions.c
index d3aebe5..5a71e43 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -208,6 +208,15 @@ void st_init_limits(struct st_context *st)
 }
 
 
+static GLboolean st_get_s3tc_override(void)
+{
+   const char *override = _mesa_getenv(force_s3tc_enable);
+   if (override  !strcmp(override, true))
+  return GL_TRUE;
+   return GL_FALSE;
+}
+
+
 /**
  * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
  * which GL extensions are supported.
@@ -426,7 +435,7 @@ void st_init_extensions(struct st_context *st)
if (screen-is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA,
PIPE_TEXTURE_2D, 0,
PIPE_BIND_SAMPLER_VIEW) 
-   ctx-Mesa_DXTn) {
+   (ctx-Mesa_DXTn || st_get_s3tc_override())) {
   ctx-Extensions.EXT_texture_compression_s3tc = GL_TRUE;
   ctx-Extensions.S3_s3tc = GL_TRUE;
}

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


Mesa (7.11): util: enable S3TC support when the force_s3tc_enable env var is set to true

2011-07-26 Thread Bryan Cain
Module: Mesa
Branch: 7.11
Commit: fd461c5888565a3f4b444b2ac76964b28a05160a
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=fd461c5888565a3f4b444b2ac76964b28a05160a

Author: Bryan Cain bryanca...@gmail.com
Date:   Wed Jul 20 17:35:22 2011 -0500

util: enable S3TC support when the force_s3tc_enable env var is set to true

NOTE: This is a candidate for the 7.10 and 7.11 branches.

---

 src/gallium/auxiliary/util/u_format_s3tc.c |   11 +--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_format_s3tc.c 
b/src/gallium/auxiliary/util/u_format_s3tc.c
index bb989c2..d8a7c0d 100644
--- a/src/gallium/auxiliary/util/u_format_s3tc.c
+++ b/src/gallium/auxiliary/util/u_format_s3tc.c
@@ -119,8 +119,15 @@ util_format_s3tc_init(void)
 
library = util_dl_open(DXTN_LIBNAME);
if (!library) {
-  debug_printf(couldn't open  DXTN_LIBNAME , software DXTn 
- compression/decompression unavailable\n);
+  if (getenv(force_s3tc_enable) 
+  !strcmp(getenv(force_s3tc_enable), true)) {
+ debug_printf(couldn't open  DXTN_LIBNAME , enabling DXTn due to 
+force_s3tc_enable=true environment variable\n);
+ util_format_s3tc_enabled = TRUE;
+  } else {
+ debug_printf(couldn't open  DXTN_LIBNAME , software DXTn 
+compression/decompression unavailable\n);
+  }
   return;
}
 

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


Mesa (glsl-to-tgsi): glsl_to_tgsi: separate immediates from array constants during IR translation

2011-07-21 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 08ca791719183330ebff33230836607813fad569
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=08ca791719183330ebff33230836607813fad569

Author: Bryan Cain bryanca...@gmail.com
Date:   Thu Jul 21 15:49:26 2011 -0500

glsl_to_tgsi: separate immediates from array constants during IR translation

Before, if any uniform or constant array was accessed with indirect
addressing, st_translate_program() would emit uniform constants in the place
of immediates.  This behavior was unavoidable with ir_to_mesa/mesa_to_tgsi, but
glsl_to_tgsi can work around it since the GLSL IR backend and the TGSI
emission are both inside the state tracker.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  143 ++-
 1 files changed, 95 insertions(+), 48 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 3df22ea..389e5d8 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -70,6 +70,7 @@ extern C {
 #include st_mesa_to_tgsi.h
 }
 
+#define PROGRAM_IMMEDIATE PROGRAM_FILE_MAX
 #define PROGRAM_ANY_CONST ((1  PROGRAM_LOCAL_PARAM) |  \
(1  PROGRAM_ENV_PARAM) |\
(1  PROGRAM_STATE_VAR) |\
@@ -272,6 +273,7 @@ public:
struct gl_program *prog;
struct gl_shader_program *shader_program;
struct gl_shader_compiler_options *options;
+   struct gl_program_parameter_list *immediates;
 
int next_temp;
 
@@ -505,6 +507,9 @@ glsl_to_tgsi_visitor::emit(ir_instruction *ir, unsigned op,
   case PROGRAM_UNIFORM:
  this-indirect_addr_consts = true;
  break;
+  case PROGRAM_IMMEDIATE:
+ assert(!immediates should not have indirect addressing);
+ break;
   default:
  break;
   }
@@ -524,6 +529,9 @@ glsl_to_tgsi_visitor::emit(ir_instruction *ir, unsigned op,
 case PROGRAM_UNIFORM:
this-indirect_addr_consts = true;
break;
+case PROGRAM_IMMEDIATE:
+   assert(!immediates should not have indirect addressing);
+   break;
 default:
break;
 }
@@ -804,12 +812,12 @@ glsl_to_tgsi_visitor::emit_scs(ir_instruction *ir, 
unsigned op,
 struct st_src_reg
 glsl_to_tgsi_visitor::st_src_reg_for_float(float val)
 {
-   st_src_reg src(PROGRAM_CONSTANT, -1, GLSL_TYPE_FLOAT);
+   st_src_reg src(PROGRAM_IMMEDIATE, -1, GLSL_TYPE_FLOAT);
union gl_constant_value uval;
 
uval.f = val;
-   src.index = _mesa_add_typed_unnamed_constant(this-prog-Parameters,
- uval, 1, GL_FLOAT, src.swizzle);
+   src.index = _mesa_add_typed_unnamed_constant(this-immediates, uval, 1,
+GL_FLOAT, src.swizzle);
 
return src;
 }
@@ -817,14 +825,14 @@ glsl_to_tgsi_visitor::st_src_reg_for_float(float val)
 struct st_src_reg
 glsl_to_tgsi_visitor::st_src_reg_for_int(int val)
 {
-   st_src_reg src(PROGRAM_CONSTANT, -1, GLSL_TYPE_INT);
+   st_src_reg src(PROGRAM_IMMEDIATE, -1, GLSL_TYPE_INT);
union gl_constant_value uval;

assert(glsl_version = 130);
 
uval.i = val;
-   src.index = _mesa_add_typed_unnamed_constant(this-prog-Parameters,
- uval, 1, GL_INT, src.swizzle);
+   src.index = _mesa_add_typed_unnamed_constant(this-immediates, uval, 1,
+GL_INT, src.swizzle);
 
return src;
 }
@@ -1933,9 +1941,15 @@ glsl_to_tgsi_visitor::visit(ir_constant *ir)
gl_constant_value *values = (gl_constant_value *) stack_vals;
GLenum gl_type = GL_NONE;
unsigned int i;
+   gl_register_file file;
+   gl_program_parameter_list *param_list;
+   static int in_array = 0;
+
+   file = in_array ? PROGRAM_CONSTANT : PROGRAM_IMMEDIATE;
+   param_list = in_array ? this-prog-Parameters : this-immediates;
 
/* Unfortunately, 4 floats is all we can get into
-* _mesa_add_unnamed_constant.  So, make a temp to store an
+* _mesa_add_typed_unnamed_constant.  So, make a temp to store an
 * aggregate constant and move each constant value into it.  If we
 * get lucky, copy propagation will eliminate the extra moves.
 */
@@ -1969,6 +1983,7 @@ glsl_to_tgsi_visitor::visit(ir_constant *ir)
   int size = type_size(ir-type-fields.array);
 
   assert(size  0);
+  in_array++;
 
   for (i = 0; i  ir-type-length; i++) {
  ir-array_elements[i]-accept(this);
@@ -1981,6 +1996,7 @@ glsl_to_tgsi_visitor::visit(ir_constant *ir)
  }
   }
   this-result = temp_base;
+  in_array--;
   return;
}
 
@@ -1992,8 +2008,8 @@ glsl_to_tgsi_visitor::visit(ir_constant *ir)
  assert(ir-type-base_type == GLSL_TYPE_FLOAT);
  values = (gl_constant_value *) ir-value.f[i * 
ir-type-vector_elements];
 
- src = st_src_reg(PROGRAM_CONSTANT

Mesa (glsl-to-tgsi): glsl_to_tgsi: make assignment hack safer

2011-07-21 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 4d3dc452eb2f23f85da17f2908af244f62ba9c24
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=4d3dc452eb2f23f85da17f2908af244f62ba9c24

Author: Bryan Cain bryanca...@gmail.com
Date:   Thu Jul 21 16:29:56 2011 -0500

glsl_to_tgsi: make assignment hack safer

Fixes an assertion failure in piglit test glsl-texcoord-array.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 389e5d8..6e01a44 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1917,12 +1917,13 @@ glsl_to_tgsi_visitor::visit(ir_assignment *ir)
   ir-rhs == ((glsl_to_tgsi_instruction 
*)this-instructions.get_tail())-ir 
   type_size(ir-lhs-type) == 1) {
   /* To avoid emitting an extra MOV when assigning an expression to a 
-   * variable, change the destination register of the last instruction 
-   * emitted as part of the expression to the assignment variable.
+   * variable, emit the last instruction of the expression again, but
+   * replace the destination register with the target of the assignment.
+   * Dead code elimination will remove the original instruction.
*/
   glsl_to_tgsi_instruction *inst;
   inst = (glsl_to_tgsi_instruction *)this-instructions.get_tail();
-  inst-dst = l;
+  emit(ir, inst-op, l, inst-src[0], inst-src[1], inst-src[2]);
} else {
   for (i = 0; i  type_size(ir-lhs-type); i++) {
  emit(ir, TGSI_OPCODE_MOV, l, r);

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


Mesa (glsl-to-tgsi): st/mesa, glsl_to_tgsi: support glBitmap with a GLSL fragment shader active

2011-07-10 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 8991085e9d04e7a2dc8c17918c1d65779a40f622
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=8991085e9d04e7a2dc8c17918c1d65779a40f622

Author: Bryan Cain bryanca...@gmail.com
Date:   Sun Jul 10 17:17:38 2011 -0500

st/mesa, glsl_to_tgsi: support glBitmap with a GLSL fragment shader active

---

 src/mesa/state_tracker/st_cb_bitmap.c  |   37 +++---
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   73 
 src/mesa/state_tracker/st_glsl_to_tgsi.h   |3 +
 3 files changed, 106 insertions(+), 7 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_bitmap.c 
b/src/mesa/state_tracker/st_cb_bitmap.c
index 49b1960..f0750b5 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -172,6 +172,23 @@ make_bitmap_fragment_program(struct gl_context *ctx, 
GLuint samplerIndex)
 }
 
 
+static struct gl_program *
+make_bitmap_fragment_program_glsl(struct st_context *st,
+  struct st_fragment_program *orig,
+  GLuint samplerIndex)
+{
+   struct gl_context *ctx = st-ctx;
+   struct st_fragment_program *fp = (struct st_fragment_program *)
+  ctx-Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
+
+   if (!fp)
+  return NULL;
+   
+   get_bitmap_visitor(fp, orig-glsl_to_tgsi, samplerIndex);
+   return fp-Base.Base;
+}
+
+
 static int
 find_free_bit(uint bitfield)
 {
@@ -199,6 +216,7 @@ st_make_bitmap_fragment_program(struct st_context *st,
 GLuint *bitmap_sampler)
 {
struct st_fragment_program *bitmap_prog;
+   struct st_fragment_program *stfpIn = (struct st_fragment_program *) fpIn;
struct gl_program *newProg;
uint sampler;
 
@@ -207,13 +225,18 @@ st_make_bitmap_fragment_program(struct st_context *st,
 * with the bitmap sampler/kill instructions.
 */
sampler = find_free_bit(fpIn-Base.SamplersUsed);
-   bitmap_prog = make_bitmap_fragment_program(st-ctx, sampler);
+   
+   if (stfpIn-glsl_to_tgsi)
+  newProg = make_bitmap_fragment_program_glsl(st, stfpIn, sampler);
+   else {
+  bitmap_prog = make_bitmap_fragment_program(st-ctx, sampler);
 
-   newProg = _mesa_combine_programs(st-ctx,
-bitmap_prog-Base.Base,
-fpIn-Base);
-   /* done with this after combining */
-   st_reference_fragprog(st, bitmap_prog, NULL);
+  newProg = _mesa_combine_programs(st-ctx,
+   bitmap_prog-Base.Base,
+   fpIn-Base);
+  /* done with this after combining */
+  st_reference_fragprog(st, bitmap_prog, NULL);
+   }
 
 #if 0
{
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index ae0c92f..74f1508 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -3620,6 +3620,79 @@ get_pixel_transfer_visitor(struct st_fragment_program 
*fp,
fp-glsl_to_tgsi = v;
 }
 
+/**
+ * Make fragment program for glBitmap:
+ *   Sample the texture and kill the fragment if the bit is 0.
+ * This program will be combined with the user's fragment program.
+ *
+ * Based on make_bitmap_fragment_program in st_cb_bitmap.c.
+ */
+extern C void
+get_bitmap_visitor(struct st_fragment_program *fp,
+   glsl_to_tgsi_visitor *original, int samplerIndex)
+{
+   glsl_to_tgsi_visitor *v = new glsl_to_tgsi_visitor();
+   struct st_context *st = st_context(original-ctx);
+   struct gl_program *prog = fp-Base.Base;
+   st_src_reg coord, src0;
+   st_dst_reg dst0;
+   glsl_to_tgsi_instruction *inst;
+
+   /* Copy attributes of the glsl_to_tgsi_visitor in the original shader. */
+   v-ctx = original-ctx;
+   v-prog = prog;
+   v-glsl_version = original-glsl_version;
+   v-options = original-options;
+   v-next_temp = original-next_temp;
+   v-num_address_regs = original-num_address_regs;
+   v-samplers_used = prog-SamplersUsed = original-samplers_used;
+   v-indirect_addr_temps = original-indirect_addr_temps;
+   v-indirect_addr_consts = original-indirect_addr_consts;
+
+   /* TEX tmp0, fragment.texcoord[0], texture[0], 2D; */
+   coord = st_src_reg(PROGRAM_INPUT, FRAG_ATTRIB_TEX0, glsl_type::vec2_type);
+   src0 = v-get_temp(glsl_type::vec4_type);
+   dst0 = st_dst_reg(src0);
+   inst = v-emit(NULL, TGSI_OPCODE_TEX, dst0, coord);
+   inst-sampler = samplerIndex;
+   inst-tex_target = TEXTURE_2D_INDEX;
+
+   prog-InputsRead |= (1  FRAG_ATTRIB_TEX0);
+   prog-SamplersUsed |= (1  samplerIndex); /* mark sampler as used */
+   v-samplers_used |= (1  samplerIndex);
+
+   /* KIL if -tmp0  0 # texel=0 - keep / texel=0 - discard */
+   src0.negate = NEGATE_XYZW;
+   if (st-bitmap.tex_format == PIPE_FORMAT_L8_UNORM)
+  src0.swizzle = SWIZZLE_;
+   inst = v-emit(NULL, TGSI_OPCODE_KIL, undef_dst, src0);
+
+   /* Now copy the instructions from the original

Mesa (glsl-to-tgsi): glsl_to_tgsi: fix mistakes in get_pixel_transfer_visitor()

2011-07-10 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 8df3510b28f9fe9850ef5e056e1cc8374032979d
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=8df3510b28f9fe9850ef5e056e1cc8374032979d

Author: Bryan Cain bryanca...@gmail.com
Date:   Sun Jul 10 17:36:04 2011 -0500

glsl_to_tgsi: fix mistakes in get_pixel_transfer_visitor()

I noticed these issues while working on get_bitmap_visitor().

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 74f1508..3df22ea 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -3534,7 +3534,6 @@ get_pixel_transfer_visitor(struct st_fragment_program *fp,
inst-tex_target = TEXTURE_2D_INDEX;
 
prog-InputsRead |= (1  FRAG_ATTRIB_TEX0);
-   prog-OutputsWritten |= BITFIELD64_BIT(FRAG_RESULT_COLOR);
prog-SamplersUsed |= (1  0); /* mark sampler 0 as used */
v-samplers_used |= (1  0);
 
@@ -3593,6 +3592,9 @@ get_pixel_transfer_visitor(struct st_fragment_program *fp,
   glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *)iter.get();
   st_src_reg src_regs[3];
 
+  if (inst-dst.file == PROGRAM_OUTPUT)
+ prog-OutputsWritten |= BITFIELD64_BIT(inst-dst.index);
+
   for (int i=0; i3; i++) {
  src_regs[i] = inst-src[i];
  if (src_regs[i].file == PROGRAM_INPUT 
@@ -3603,8 +3605,6 @@ get_pixel_transfer_visitor(struct st_fragment_program *fp,
  }
  else if (src_regs[i].file == PROGRAM_INPUT)
 prog-InputsRead |= (1  src_regs[i].index);
- else if (src_regs[i].file == PROGRAM_OUTPUT)
-prog-OutputsWritten |= BITFIELD64_BIT(src_regs[i].index);
   }
 
   v-emit(NULL, inst-op, inst-dst, src_regs[0], src_regs[1], 
src_regs[2]);

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


Mesa (glsl-to-tgsi): st/mesa, glsl_to_tgsi: support glDrawPixels/ glCopyPixels with a GLSL fragment shader

2011-07-08 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 45893d7c24d5a0057b2a0441398e7337a9541be5
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=45893d7c24d5a0057b2a0441398e7337a9541be5

Author: Bryan Cain bryanca...@gmail.com
Date:   Fri Jul  8 21:12:08 2011 -0500

st/mesa, glsl_to_tgsi: support glDrawPixels/glCopyPixels with a GLSL fragment 
shader

Since this was previously implemented using Mesa IR and _mesa_combine_programs,
this commit adds a new code path that works with glsl_to_tgsi.

---

 src/mesa/state_tracker/st_cb_drawpixels.c  |   65 ++
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  126 
 src/mesa/state_tracker/st_glsl_to_tgsi.h   |3 +
 3 files changed, 194 insertions(+), 0 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c 
b/src/mesa/state_tracker/st_cb_drawpixels.c
index 965fbcd..f4dd2a4 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -94,6 +94,67 @@ is_passthrough_program(const struct gl_fragment_program 
*prog)
 }
 
 
+/* XXX copied verbatim from st_atom_pixeltransfer.c */
+static struct pipe_resource *
+create_color_map_texture(struct gl_context *ctx)
+{
+   struct st_context *st = st_context(ctx);
+   struct pipe_context *pipe = st-pipe;
+   struct pipe_resource *pt;
+   enum pipe_format format;
+   const uint texSize = 256; /* simple, and usually perfect */
+
+   /* find an RGBA texture format */
+   format = st_choose_format(pipe-screen, GL_RGBA,
+ PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW);
+
+   /* create texture for color map/table */
+   pt = st_texture_create(st, PIPE_TEXTURE_2D, format, 0,
+  texSize, texSize, 1, 1, PIPE_BIND_SAMPLER_VIEW);
+   return pt;
+}
+
+
+/**
+ * Returns a fragment program which implements the current pixel transfer ops.
+ */
+static struct gl_fragment_program *
+get_glsl_pixel_transfer_program(struct st_context *st,
+struct st_fragment_program *orig)
+{
+   int pixelMaps = 0, scaleAndBias = 0;
+   struct gl_context *ctx = st-ctx;
+   struct st_fragment_program *fp = (struct st_fragment_program *)
+  ctx-Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
+
+   if (!fp)
+  return NULL;
+
+   if (ctx-Pixel.RedBias != 0.0 || ctx-Pixel.RedScale != 1.0 ||
+   ctx-Pixel.GreenBias != 0.0 || ctx-Pixel.GreenScale != 1.0 ||
+   ctx-Pixel.BlueBias != 0.0 || ctx-Pixel.BlueScale != 1.0 ||
+   ctx-Pixel.AlphaBias != 0.0 || ctx-Pixel.AlphaScale != 1.0) {
+  scaleAndBias = 1;
+   }
+
+   pixelMaps = ctx-Pixel.MapColorFlag;
+
+   if (pixelMaps) {
+  /* create the colormap/texture now if not already done */
+  if (!st-pixel_xfer.pixelmap_texture) {
+ st-pixel_xfer.pixelmap_texture = create_color_map_texture(ctx);
+ st-pixel_xfer.pixelmap_sampler_view =
+st_create_texture_sampler_view(st-pipe,
+   st-pixel_xfer.pixelmap_texture);
+  }
+   }
+
+   get_pixel_transfer_visitor(fp, orig-glsl_to_tgsi,
+  scaleAndBias, pixelMaps);
+
+   return fp-Base;
+}
+
 
 /**
  * Make fragment shader for glDraw/CopyPixels.  This shader is made
@@ -107,11 +168,15 @@ st_make_drawpix_fragment_program(struct st_context *st,
  struct gl_fragment_program **fpOut)
 {
struct gl_program *newProg;
+   struct st_fragment_program *stfp = (struct st_fragment_program *) fpIn;
 
if (is_passthrough_program(fpIn)) {
   newProg = (struct gl_program *) _mesa_clone_fragment_program(st-ctx,
  st-pixel_xfer.program-Base);
}
+   else if (stfp-glsl_to_tgsi != NULL) {
+  newProg = (struct gl_program *) get_glsl_pixel_transfer_program(st, 
stfp);
+   }
else {
 #if 0
   /* debug */
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index d7afc22..ae0c92f 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -3494,6 +3494,132 @@ glsl_to_tgsi_visitor::renumber_registers(void)
this-next_temp = new_index;
 }
 
+/**
+ * Returns a fragment program which implements the current pixel transfer ops.
+ * Based on get_pixel_transfer_program in st_atom_pixeltransfer.c.
+ */
+extern C void
+get_pixel_transfer_visitor(struct st_fragment_program *fp,
+   glsl_to_tgsi_visitor *original,
+   int scale_and_bias, int pixel_maps)
+{
+   glsl_to_tgsi_visitor *v = new glsl_to_tgsi_visitor();
+   struct st_context *st = st_context(original-ctx);
+   struct gl_program *prog = fp-Base.Base;
+   struct gl_program_parameter_list *params = _mesa_new_parameter_list();
+   st_src_reg coord, src0;
+   st_dst_reg dst0;
+   glsl_to_tgsi_instruction *inst;
+
+   /* Copy attributes of the glsl_to_tgsi_visitor in the original shader. */
+   v-ctx = original-ctx;
+   v

Mesa (glsl-to-tgsi): glsl_to_tgsi: replace MAX_PROGRAM_TEMPS (256) with MAX_TEMPS (4096)

2011-07-04 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 1c90c522a0a2d8bf36dfc49e86606864db03958a
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=1c90c522a0a2d8bf36dfc49e86606864db03958a

Author: Bryan Cain bryanca...@gmail.com
Date:   Mon Jul  4 08:44:12 2011 -0500

glsl_to_tgsi: replace MAX_PROGRAM_TEMPS (256) with MAX_TEMPS (4096)

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   14 --
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index e7d0af8..d7afc22 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -77,6 +77,8 @@ extern C {
(1  PROGRAM_CONSTANT) | \
(1  PROGRAM_UNIFORM))
 
+#define MAX_TEMPS 4096
+
 class st_src_reg;
 class st_dst_reg;
 
@@ -2751,11 +2753,11 @@ 
glsl_to_tgsi_visitor::remove_output_reads(gl_register_file type)
GLint outputMap[VERT_RESULT_MAX];
GLint outputTypes[VERT_RESULT_MAX];
GLuint numVaryingReads = 0;
-   GLboolean usedTemps[MAX_PROGRAM_TEMPS];
+   GLboolean usedTemps[MAX_TEMPS];
GLuint firstTemp = 0;
 
_mesa_find_used_registers(prog, PROGRAM_TEMPORARY,
- usedTemps, MAX_PROGRAM_TEMPS);
+ usedTemps, MAX_TEMPS);
 
assert(type == PROGRAM_VARYING || type == PROGRAM_OUTPUT);
assert(prog-Target == GL_VERTEX_PROGRAM_ARB || type != PROGRAM_VARYING);
@@ -2775,7 +2777,7 @@ 
glsl_to_tgsi_visitor::remove_output_reads(gl_register_file type)
 if (outputMap[var] == -1) {
numVaryingReads++;
outputMap[var] = _mesa_find_free_register(usedTemps,
- MAX_PROGRAM_TEMPS,
+ MAX_TEMPS,
  firstTemp);
outputTypes[var] = inst-src[j].type;
firstTemp = outputMap[var] + 1;
@@ -2857,7 +2859,7 @@ get_src_arg_mask(st_dst_reg dst, st_src_reg src)
 void
 glsl_to_tgsi_visitor::simplify_cmp(void)
 {
-   unsigned tempWrites[MAX_PROGRAM_TEMPS];
+   unsigned tempWrites[MAX_TEMPS];
unsigned outputWrites[MAX_PROGRAM_OUTPUTS];
 
memset(tempWrites, 0, sizeof(tempWrites));
@@ -2883,7 +2885,7 @@ glsl_to_tgsi_visitor::simplify_cmp(void)
  prevWriteMask = outputWrites[inst-dst.index];
  outputWrites[inst-dst.index] |= inst-dst.writemask;
   } else if (inst-dst.file == PROGRAM_TEMPORARY) {
- assert(inst-dst.index  MAX_PROGRAM_TEMPS);
+ assert(inst-dst.index  MAX_TEMPS);
  prevWriteMask = tempWrites[inst-dst.index];
  tempWrites[inst-dst.index] |= inst-dst.writemask;
   }
@@ -3504,7 +3506,7 @@ struct label {
 struct st_translate {
struct ureg_program *ureg;
 
-   struct ureg_dst temps[MAX_PROGRAM_TEMPS];
+   struct ureg_dst temps[MAX_TEMPS];
struct ureg_src *constants;
struct ureg_dst outputs[PIPE_MAX_SHADER_OUTPUTS];
struct ureg_src inputs[PIPE_MAX_SHADER_INPUTS];

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


Mesa (glsl-to-tgsi): r200,r600c,i965: fix build

2011-06-30 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 4d0203a49dcb4c2e06d0ce911b9896bd9d3f72a2
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=4d0203a49dcb4c2e06d0ce911b9896bd9d3f72a2

Author: Bryan Cain bryanca...@gmail.com
Date:   Thu Jun 30 13:42:37 2011 -0500

r200,r600c,i965: fix build

---

 src/mesa/drivers/dri/i965/brw_fs.cpp   |2 +-
 src/mesa/drivers/dri/i965/brw_vs_emit.c|2 +-
 src/mesa/drivers/dri/r200/r200_vertprog.c  |8 
 src/mesa/drivers/dri/r600/evergreen_fragprog.c |8 
 src/mesa/drivers/dri/r600/evergreen_vertprog.c |   16 
 src/mesa/drivers/dri/r600/r700_fragprog.c  |8 
 src/mesa/drivers/dri/r600/r700_vertprog.c  |   16 
 7 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp 
b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 7c73a8f..31f76f8 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -605,7 +605,7 @@ fs_visitor::setup_paramvalues_refs()
/* Set up the pointers to ParamValues now that that array is finalized. */
for (unsigned int i = 0; i  c-prog_data.nr_params; i++) {
   c-prog_data.param[i] =
-fp-Base.Parameters-ParameterValues[this-param_index[i]] +
+(const float 
*)fp-Base.Parameters-ParameterValues[this-param_index[i]] +
 this-param_offset[i];
}
 }
diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c 
b/src/mesa/drivers/dri/i965/brw_vs_emit.c
index b6c9e5a..2fa04a1 100644
--- a/src/mesa/drivers/dri/i965/brw_vs_emit.c
+++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c
@@ -1359,7 +1359,7 @@ get_src_reg( struct brw_vs_compile *c,
 
 if (component = 0) {
params = c-vp-program.Base.Parameters;
-   f = params-ParameterValues[src-Index][component];
+   f = params-ParameterValues[src-Index][component].f;
 
if (src-Abs)
   f = fabs(f);
diff --git a/src/mesa/drivers/dri/r200/r200_vertprog.c 
b/src/mesa/drivers/dri/r200/r200_vertprog.c
index 63e03b0..cf44d7f 100644
--- a/src/mesa/drivers/dri/r200/r200_vertprog.c
+++ b/src/mesa/drivers/dri/r200/r200_vertprog.c
@@ -126,10 +126,10 @@ static GLboolean r200VertexProgUpdateParams(struct 
gl_context *ctx, struct r200_
   case PROGRAM_NAMED_PARAM:
   //fprintf(stderr, %s, vp-Parameters-Parameters[pi].Name);
   case PROGRAM_CONSTANT:
-*fcmd++ = paramList-ParameterValues[pi][0];
-*fcmd++ = paramList-ParameterValues[pi][1];
-*fcmd++ = paramList-ParameterValues[pi][2];
-*fcmd++ = paramList-ParameterValues[pi][3];
+*fcmd++ = paramList-ParameterValues[pi][0].f;
+*fcmd++ = paramList-ParameterValues[pi][1].f;
+*fcmd++ = paramList-ParameterValues[pi][2].f;
+*fcmd++ = paramList-ParameterValues[pi][3].f;
 break;
   default:
 _mesa_problem(NULL, Bad param type in %s, __FUNCTION__);
diff --git a/src/mesa/drivers/dri/r600/evergreen_fragprog.c 
b/src/mesa/drivers/dri/r600/evergreen_fragprog.c
index e527c37..cc584ca 100644
--- a/src/mesa/drivers/dri/r600/evergreen_fragprog.c
+++ b/src/mesa/drivers/dri/r600/evergreen_fragprog.c
@@ -752,10 +752,10 @@ GLboolean evergreenSetupFPconstants(struct gl_context * 
ctx)
unNumParamData = paramList-NumParameters;
 
for(ui=0; uiunNumParamData; ui++) {
-   evergreen-ps.consts[ui][0].f32All = 
paramList-ParameterValues[ui][0];
-   evergreen-ps.consts[ui][1].f32All = 
paramList-ParameterValues[ui][1];
-   evergreen-ps.consts[ui][2].f32All = 
paramList-ParameterValues[ui][2];
-   evergreen-ps.consts[ui][3].f32All = 
paramList-ParameterValues[ui][3];
+   evergreen-ps.consts[ui][0].f32All = 
paramList-ParameterValues[ui][0].f;
+   evergreen-ps.consts[ui][1].f32All = 
paramList-ParameterValues[ui][1].f;
+   evergreen-ps.consts[ui][2].f32All = 
paramList-ParameterValues[ui][2].f;
+   evergreen-ps.consts[ui][3].f32All = 
paramList-ParameterValues[ui][3].f;
}
 
/* alloc multiple of 16 constants */
diff --git a/src/mesa/drivers/dri/r600/evergreen_vertprog.c 
b/src/mesa/drivers/dri/r600/evergreen_vertprog.c
index 018869b..117916a 100644
--- a/src/mesa/drivers/dri/r600/evergreen_vertprog.c
+++ b/src/mesa/drivers/dri/r600/evergreen_vertprog.c
@@ -684,17 +684,17 @@ GLboolean evergreenSetupVPconstants(struct gl_context * 
ctx)
for(ui=0; uiunNumParamData; ui++) {
 if(paramList-Parameters[ui].Type == PROGRAM_UNIFORM) 
 {
-evergreen-vs.consts[ui][0].f32All = 
paramListOrginal-ParameterValues[ui][0];
-   evergreen-vs.consts[ui][1].f32All = 
paramListOrginal-ParameterValues[ui][1];
-   evergreen-vs.consts[ui][2].f32All = 
paramListOrginal-ParameterValues[ui][2

Mesa (glsl-to-tgsi): glsl_to_tgsi: fix mistake in new dead code elimination pass

2011-06-27 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: dc66cfd63feacb7e1343ed699fb372c4e5fc7b90
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=dc66cfd63feacb7e1343ed699fb372c4e5fc7b90

Author: Bryan Cain bryanca...@gmail.com
Date:   Mon Jun 27 17:25:50 2011 -0500

glsl_to_tgsi: fix mistake in new dead code elimination pass

The conditions of IF opcodes were not being counted as reads, which sometimes
led to the condition register being wrong or undefined.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index e38617a..f87c64f 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -3315,10 +3315,6 @@ glsl_to_tgsi_visitor::eliminate_dead_code_advanced(void)
  memset(writes, 0, sizeof(*writes) * this-next_temp * 4);
  break;
 
-  case TGSI_OPCODE_IF:
- ++level;
- break;
-
   case TGSI_OPCODE_ENDIF:
  --level;
  break;
@@ -3341,6 +3337,10 @@ glsl_to_tgsi_visitor::eliminate_dead_code_advanced(void)
  }
  break;
 
+  case TGSI_OPCODE_IF:
+ ++level;
+ /* fallthrough to default case to mark the condition as read */
+  
   default:
  /* Continuing the block, clear any channels from the write array that
   * are read by this instruction.

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


Mesa (glsl-to-tgsi): glsl_to_tgsi: always run copy_propagate() and eliminate_dead_code_advanced()

2011-06-27 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 49f4336ab96df0c907f1ff86a35aaba40ed451d9
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=49f4336ab96df0c907f1ff86a35aaba40ed451d9

Author: Bryan Cain bryanca...@gmail.com
Date:   Mon Jun 27 17:40:10 2011 -0500

glsl_to_tgsi: always run copy_propagate() and eliminate_dead_code_advanced()

These two passes are written to handle indirect addressing properly.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |9 -
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index f87c64f..e7d0af8 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -4422,18 +4422,17 @@ get_mesa_program(struct gl_context *ctx,
if (target == GL_VERTEX_PROGRAM_ARB)
   v-remove_output_reads(PROGRAM_VARYING);

-   /* Perform the simplify_cmp optimization, which is required by r300g. */
+   /* Perform optimizations on the instructions in the glsl_to_tgsi_visitor. */
v-simplify_cmp();
+   v-copy_propagate();
+   while (v-eliminate_dead_code_advanced());
 
-   /* Perform optimizations on the instructions in the glsl_to_tgsi_visitor.
-* FIXME: These passes to optimize temporary registers don't work when there
+   /* FIXME: These passes to optimize temporary registers don't work when there
 * is indirect addressing of the temporary register space.  We need proper 
 * array support so that we don't have to give up these passes in every 
 * shader that uses arrays.
 */
if (!v-indirect_addr_temps) {
-  v-copy_propagate();
-  while (v-eliminate_dead_code_advanced());
   v-eliminate_dead_code();
   v-merge_registers();
   v-renumber_registers();

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


Mesa (glsl-to-tgsi): glsl_to_tgsi: improve eliminate_dead_code_advanced()

2011-06-25 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 1e4933b9a18ac6294b34860cfc4cc09974fbe643
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=1e4933b9a18ac6294b34860cfc4cc09974fbe643

Author: Bryan Cain bryanca...@gmail.com
Date:   Fri Jun 24 23:17:30 2011 -0500

glsl_to_tgsi: improve eliminate_dead_code_advanced()

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |9 +
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 13573fc..15a1a3c 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -3379,6 +3379,15 @@ glsl_to_tgsi_visitor::eliminate_dead_code_advanced(void)
   }
}
 
+   /* Anything still in the write array at this point is dead code. */
+   for (int r = 0; r  this-next_temp; r++) {
+  for (int c = 0; c  4; c++) {
+ glsl_to_tgsi_instruction *inst = writes[4 * r + c];
+ if (inst)
+inst-dead_mask |= (1  c);
+  }
+   }
+
/* Now actually remove the instructions that are completely dead and update
 * the writemask of other instructions with dead channels.
 */

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


Mesa (glsl-to-tgsi): glsl_to_tgsi: remove handling of XPD opcode in compile_tgsi_instruction()

2011-06-24 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 857f3973b457f41078af803e1c562cec3d4a6dce
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=857f3973b457f41078af803e1c562cec3d4a6dce

Author: Bryan Cain bryanca...@gmail.com
Date:   Thu Jun 23 19:53:37 2011 -0500

glsl_to_tgsi: remove handling of XPD opcode in compile_tgsi_instruction()

The opcode is never emitted by the glsl_to_tgsi_visitor, so its special case in
compile_tgsi_instruction() was dead code.

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |8 
 1 files changed, 0 insertions(+), 8 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 6d76686..721ba28 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -3653,14 +3653,6 @@ compile_tgsi_instruction(struct st_translate *t,
  src, num_src );
   break;
 
-   case TGSI_OPCODE_XPD:
-  dst[0] = ureg_writemask(dst[0], TGSI_WRITEMASK_XYZ );
-  ureg_insn( ureg, 
- inst-op, 
- dst, num_dst, 
- src, num_src );
-  break;
-
default:
   ureg_insn( ureg, 
  inst-op, 

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


Mesa (glsl-to-tgsi): glsl_to_tgsi: add a better, more advanced dead code elimination pass

2011-06-24 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: de3a9fbd852b86a9a7818abf9ad7ca2e32e26ba2
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=de3a9fbd852b86a9a7818abf9ad7ca2e32e26ba2

Author: Bryan Cain bryanca...@gmail.com
Date:   Fri Jun 24 18:45:04 2011 -0500

glsl_to_tgsi: add a better, more advanced dead code elimination pass

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  140 
 1 files changed, 140 insertions(+), 0 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 721ba28..d47364f 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -208,6 +208,7 @@ public:
int sampler; /** sampler index */
int tex_target; /** One of TEXTURE_*_INDEX */
GLboolean tex_shadow;
+   int dead_mask; /** Used in dead code elimination */
 
class function_entry *function; /* Set on TGSI_OPCODE_CAL or 
TGSI_OPCODE_BGNSUB */
 };
@@ -384,6 +385,7 @@ public:
 
void copy_propagate(void);
void eliminate_dead_code(void);
+   int eliminate_dead_code_advanced(void);
void merge_registers(void);
void renumber_registers(void);
 
@@ -480,6 +482,7 @@ glsl_to_tgsi_visitor::emit(ir_instruction *ir, unsigned op,
inst-src[1] = src1;
inst-src[2] = src2;
inst-ir = ir;
+   inst-dead_mask = 0;
 
inst-function = NULL;

@@ -3257,6 +3260,142 @@ glsl_to_tgsi_visitor::eliminate_dead_code(void)
}
 }
 
+/*
+ * On a basic block basis, tracks available PROGRAM_TEMPORARY registers for 
dead
+ * code elimination.  This is less primitive than eliminate_dead_code(), as it
+ * is per-channel and can detect consecutive writes without a read between them
+ * as dead code.  However, there is some dead code that can be eliminated by 
+ * eliminate_dead_code() but not this function - for example, this function 
+ * cannot eliminate an instruction writing to a register that is never read and
+ * is the only instruction writing to that register.
+ *
+ * The glsl_to_tgsi_visitor lazily produces code assuming that this pass
+ * will occur.
+ */
+int
+glsl_to_tgsi_visitor::eliminate_dead_code_advanced(void)
+{
+   glsl_to_tgsi_instruction **writes = rzalloc_array(mem_ctx,
+ glsl_to_tgsi_instruction 
*,
+ this-next_temp * 4);
+   int *write_level = rzalloc_array(mem_ctx, int, this-next_temp * 4);
+   int level = 0;
+   int removed = 0;
+
+   foreach_iter(exec_list_iterator, iter, this-instructions) {
+  glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *)iter.get();
+
+  assert(inst-dst.file != PROGRAM_TEMPORARY
+ || inst-dst.index  this-next_temp);
+  
+  switch (inst-op) {
+  case TGSI_OPCODE_BGNLOOP:
+  case TGSI_OPCODE_ENDLOOP:
+ /* End of a basic block, clear the write array entirely.
+  * FIXME: This keeps us from killing dead code when the writes are
+  * on either side of a loop, even when the register isn't touched
+  * inside the loop.
+  */
+ memset(writes, 0, sizeof(*writes) * this-next_temp * 4);
+ break;
+
+  case TGSI_OPCODE_IF:
+ ++level;
+ break;
+
+  case TGSI_OPCODE_ENDIF:
+ --level;
+ break;
+
+  case TGSI_OPCODE_ELSE:
+ /* Clear all channels written inside the preceding if block from the
+  * write array, but leave those that were not touched.
+  *
+  * FIXME: This destroys opportunities to remove dead code inside of
+  * IF blocks that are followed by an ELSE block.
+  */
+ for (int r = 0; r  this-next_temp; r++) {
+for (int c = 0; c  4; c++) {
+   if (!writes[4 * r + c])
+continue;
+
+   if (write_level[4 * r + c] = level)
+writes[4 * r + c] = NULL;
+}
+ }
+ break;
+
+  default:
+ /* Continuing the block, clear any channels from the write array that
+  * are read by this instruction.
+  */
+ for (int i = 0; i  4; i++) {
+if (inst-src[i].file == PROGRAM_TEMPORARY  
inst-src[i].reladdr){
+   /* Any temporary might be read, so no dead code elimination 
+* across this instruction.
+*/
+   memset(writes, 0, sizeof(*writes) * this-next_temp * 4);
+} else if (inst-src[i].file == PROGRAM_TEMPORARY) {
+   /* Clear where it's used as src. */
+   int src_chans = 1  GET_SWZ(inst-src[i].swizzle, 0);
+   src_chans |= 1  GET_SWZ(inst-src[i].swizzle, 1);
+   src_chans |= 1  GET_SWZ(inst-src[i].swizzle, 2);
+   src_chans |= 1  GET_SWZ(inst-src[i].swizzle, 3);
+   
+   for (int c = 0; c  4; c++) {
+  if (src_chans  (1  c

Mesa (glsl-to-tgsi): glsl_to_tgsi: use the correct writemask in try_emit_mad() and try_emit_sat()

2011-06-24 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: bdc3e8fc7089fe66c95be84de75fce9ae8e76560
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=bdc3e8fc7089fe66c95be84de75fce9ae8e76560

Author: Bryan Cain bryanca...@gmail.com
Date:   Fri Jun 24 22:32:26 2011 -0500

glsl_to_tgsi: use the correct writemask in try_emit_mad() and try_emit_sat()

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |9 +++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 5f22f70..13573fc 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1133,6 +1133,7 @@ glsl_to_tgsi_visitor::try_emit_mad(ir_expression *ir, int 
mul_operand)
 {
int nonmul_operand = 1 - mul_operand;
st_src_reg a, b, c;
+   st_dst_reg result_dst;
 
ir_expression *expr = ir-operands[mul_operand]-as_expression();
if (!expr || expr-operation != ir_binop_mul)
@@ -1146,7 +1147,9 @@ glsl_to_tgsi_visitor::try_emit_mad(ir_expression *ir, int 
mul_operand)
c = this-result;
 
this-result = get_temp(ir-type);
-   emit(ir, TGSI_OPCODE_MAD, st_dst_reg(this-result), a, b, c);
+   result_dst = st_dst_reg(this-result);
+   result_dst.writemask = (1  ir-type-vector_elements) - 1;
+   emit(ir, TGSI_OPCODE_MAD, result_dst, a, b, c);
 
return true;
 }
@@ -1168,8 +1171,10 @@ glsl_to_tgsi_visitor::try_emit_sat(ir_expression *ir)
st_src_reg src = this-result;
 
this-result = get_temp(ir-type);
+   st_dst_reg result_dst = st_dst_reg(this-result);
+   result_dst.writemask = (1  ir-type-vector_elements) - 1;
glsl_to_tgsi_instruction *inst;
-   inst = emit(ir, TGSI_OPCODE_MOV, st_dst_reg(this-result), src);
+   inst = emit(ir, TGSI_OPCODE_MOV, result_dst, src);
inst-saturate = true;
 
return true;

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


Mesa (glsl-to-tgsi): st/mesa: implement simplify_cmp pass needed by r300g

2011-06-22 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: 95b86e40fbac83918139d1cdcadb8f6471233d82
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=95b86e40fbac83918139d1cdcadb8f6471233d82

Author: Bryan Cain bryanca...@gmail.com
Date:   Thu Jun 16 18:36:16 2011 -0500

st/mesa: implement simplify_cmp pass needed by r300g

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   95 
 1 files changed, 95 insertions(+), 0 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 6c92441..322bfbb 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -374,6 +374,7 @@ public:
bool process_move_condition(ir_rvalue *ir);
 
void remove_output_reads(gl_register_file type);
+   void simplify_cmp(void);
 
void rename_temp_register(int index, int new_index);
int get_first_temp_read(int index);
@@ -2788,6 +2789,97 @@ 
glsl_to_tgsi_visitor::remove_output_reads(gl_register_file type)
}
 }
 
+/**
+ * Returns the mask of channels (bitmask of WRITEMASK_X,Y,Z,W) which
+ * are read from the given src in this instruction
+ */
+static int
+get_src_arg_mask(st_dst_reg dst, st_src_reg src)
+{
+   int read_mask = 0, comp;
+
+   /* Now, given the src swizzle and the written channels, find which
+* components are actually read
+*/
+   for (comp = 0; comp  4; ++comp) {
+  const unsigned coord = GET_SWZ(src.swizzle, comp);
+  ASSERT(coord  4);
+  if (dst.writemask  (1  comp)  coord = SWIZZLE_W)
+ read_mask |= 1  coord;
+   }
+
+   return read_mask;
+}
+
+/**
+ * This pass replaces CMP T0, T1 T2 T0 with MOV T0, T2 when the CMP
+ * instruction is the first instruction to write to register T0.  There are
+ * several lowering passes done in GLSL IR (e.g. branches and
+ * relative addressing) that create a large number of conditional assignments
+ * that ir_to_mesa converts to CMP instructions like the one mentioned above.
+ *
+ * Here is why this conversion is safe:
+ * CMP T0, T1 T2 T0 can be expanded to:
+ * if (T1  0.0)
+ * MOV T0, T2;
+ * else
+ * MOV T0, T0;
+ *
+ * If (T1  0.0) evaluates to true then our replacement MOV T0, T2 is the same
+ * as the original program.  If (T1  0.0) evaluates to false, executing
+ * MOV T0, T0 will store a garbage value in T0 since T0 is uninitialized.
+ * Therefore, it doesn't matter that we are replacing MOV T0, T0 with MOV T0, 
T2
+ * because any instruction that was going to read from T0 after this was going
+ * to read a garbage value anyway.
+ */
+void
+glsl_to_tgsi_visitor::simplify_cmp(void)
+{
+   unsigned tempWrites[MAX_PROGRAM_TEMPS];
+   unsigned outputWrites[MAX_PROGRAM_OUTPUTS];
+
+   memset(tempWrites, 0, sizeof(tempWrites));
+   memset(outputWrites, 0, sizeof(outputWrites));
+
+   foreach_iter(exec_list_iterator, iter, this-instructions) {
+  glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *)iter.get();
+  unsigned prevWriteMask = 0;
+
+  /* Give up if we encounter relative addressing or flow control. */
+  if (inst-dst.reladdr ||
+  tgsi_get_opcode_info(inst-op)-is_branch ||
+  inst-op == TGSI_OPCODE_BGNSUB ||
+  inst-op == TGSI_OPCODE_CONT ||
+  inst-op == TGSI_OPCODE_END ||
+  inst-op == TGSI_OPCODE_ENDSUB ||
+  inst-op == TGSI_OPCODE_RET) {
+ return;
+  }
+
+  if (inst-dst.file == PROGRAM_OUTPUT) {
+ assert(inst-dst.index  MAX_PROGRAM_OUTPUTS);
+ prevWriteMask = outputWrites[inst-dst.index];
+ outputWrites[inst-dst.index] |= inst-dst.writemask;
+  } else if (inst-dst.file == PROGRAM_TEMPORARY) {
+ assert(inst-dst.index  MAX_PROGRAM_TEMPS);
+ prevWriteMask = tempWrites[inst-dst.index];
+ tempWrites[inst-dst.index] |= inst-dst.writemask;
+  }
+
+  /* For a CMP to be considered a conditional write, the destination
+   * register and source register two must be the same. */
+  if (inst-op == TGSI_OPCODE_CMP
+   !(inst-dst.writemask  prevWriteMask)
+   inst-src[2].file == inst-dst.file
+   inst-src[2].index == inst-dst.index
+   inst-dst.writemask == get_src_arg_mask(inst-dst, inst-src[2])) 
{
+
+ inst-op = TGSI_OPCODE_MOV;
+ inst-src[0] = inst-src[1];
+  }
+   }
+}
+
 /* Replaces all references to a temporary register index with another index. */
 void
 glsl_to_tgsi_visitor::rename_temp_register(int index, int new_index)
@@ -4170,6 +4262,9 @@ get_mesa_program(struct gl_context *ctx,
v-remove_output_reads(PROGRAM_OUTPUT);
if (target == GL_VERTEX_PROGRAM_ARB)
   v-remove_output_reads(PROGRAM_VARYING);
+   
+   /* Perform the simplify_cmp optimization, which is required by r300g. */
+   v-simplify_cmp();
 
/* Perform optimizations on the instructions in the glsl_to_tgsi_visitor.
 * FIXME: These passes to optimize temporary registers don't work when

Mesa (glsl-to-tgsi): glsl_to_tgsi: execute merge_registers() after eliminate_dead_code()

2011-06-22 Thread Bryan Cain
Module: Mesa
Branch: glsl-to-tgsi
Commit: fd29c7207fff1965225657eaed4f5f0ee1f1f4f5
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=fd29c7207fff1965225657eaed4f5f0ee1f1f4f5

Author: Emil Velikov emil.l.veli...@gmail.com
Date:   Tue Jun 21 21:52:19 2011 +0100

glsl_to_tgsi: execute merge_registers() after eliminate_dead_code()

Fixes a regression unintentionally introduced by commit 343e75d9 (st/mesa: fix 
shaders with indirect addressing of temps) that caused missing leaves in 
3dmark01 test 4 (Nature) and missing/displaced textures on human models in 
Counter-Strike: Source.

[Bryan: This regression also caused a performance regression in many shaders 
since it made the dead code elimination pass ineffective.]

Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
Signed-off-by: Bryan Cain bryanca...@gmail.com

---

 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 322bfbb..abeb44a 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -4274,8 +4274,8 @@ get_mesa_program(struct gl_context *ctx,
 */
if (!v-indirect_addr_temps) {
   v-copy_propagate();
-  v-merge_registers();
   v-eliminate_dead_code();
+  v-merge_registers();
   v-renumber_registers();
}


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