Mesa (master): mesa: Check glReadBuffer enums against the ES3 table.

2016-03-24 Thread Kenneth Graunke
Module: Mesa
Branch: master
Commit: 511ce2925baf90c1d93d3e6a389d31e8e7549493
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=511ce2925baf90c1d93d3e6a389d31e8e7549493

Author: Kenneth Graunke 
Date:   Wed Mar 23 22:35:41 2016 -0700

mesa: Check glReadBuffer enums against the ES3 table.

From the ES 3.2 spec, section 16.1.1 (Selecting Buffers for Reading):

   "An INVALID_ENUM error is generated if src is not BACK or one of
the values from table 15.5."

Table 15.5 contains NONE and COLOR_ATTACHMENTi.

Mesa properly returned INVALID_ENUM for unknown enums, but it decided
what was known by using read_buffer_enum_to_index, which handles all
enums in every API.  So enums that were valid in GL were making it
past the "valid enum" check.  Such targets would then be classified
as unsupported, and we'd raise INVALID_OPERATION, but that's technically
the wrong error code.

Fixes dEQP-GLES31's
functional.debug.negative_coverage.get_error.buffer.read_buffer

v2: Only call read_buffer_enuM_to_index when required (Eduardo).

Signed-off-by: Kenneth Graunke 
Reviewed-by: Eduardo Lima Mitev 

---

 src/mesa/main/buffers.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/buffers.c b/src/mesa/main/buffers.c
index 26dafd1..a28c583 100644
--- a/src/mesa/main/buffers.c
+++ b/src/mesa/main/buffers.c
@@ -222,6 +222,12 @@ read_buffer_enum_to_index(GLenum buffer)
}
 }
 
+static bool
+is_legal_es3_readbuffer_enum(GLenum buf)
+{
+   return buf == GL_BACK || buf == GL_NONE ||
+  (buf >= GL_COLOR_ATTACHMENT0 && buf <= GL_COLOR_ATTACHMENT31);
+}
 
 /**
  * Called by glDrawBuffer() and glNamedFramebufferDrawBuffer().
@@ -715,7 +721,11 @@ read_buffer(struct gl_context *ctx, struct gl_framebuffer 
*fb,
}
else {
   /* general case / window-system framebuffer */
-  srcBuffer = read_buffer_enum_to_index(buffer);
+  if (_mesa_is_gles3(ctx) && !is_legal_es3_readbuffer_enum(buffer))
+ srcBuffer = -1;
+  else
+ srcBuffer = read_buffer_enum_to_index(buffer);
+
   if (srcBuffer == -1) {
  _mesa_error(ctx, GL_INVALID_ENUM,
  "%s(invalid buffer %s)", caller,

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


Mesa (master): nir: Add a pass to repair SSA form

2016-03-24 Thread Jason Ekstrand
Module: Mesa
Branch: master
Commit: 364212f1ede4b2ecf4361e27e24e3d84e19aa54d
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=364212f1ede4b2ecf4361e27e24e3d84e19aa54d

Author: Jason Ekstrand 
Date:   Fri Feb 12 21:52:46 2016 -0800

nir: Add a pass to repair SSA form

Reviewed-by: Jordan Justen 

---

 src/compiler/Makefile.sources |   1 +
 src/compiler/nir/Makefile.sources |   1 +
 src/compiler/nir/nir.h|   3 +
 src/compiler/nir/nir_repair_ssa.c | 158 ++
 4 files changed, 163 insertions(+)

diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources
index c38454e..796d004 100644
--- a/src/compiler/Makefile.sources
+++ b/src/compiler/Makefile.sources
@@ -218,6 +218,7 @@ NIR_FILES = \
nir/nir_phi_builder.c \
nir/nir_phi_builder.h \
nir/nir_print.c \
+   nir/nir_repair_ssa.c \
nir/nir_remove_dead_variables.c \
nir/nir_search.c \
nir/nir_search.h \
diff --git a/src/compiler/nir/Makefile.sources 
b/src/compiler/nir/Makefile.sources
index db3eecc..c149355 100644
--- a/src/compiler/nir/Makefile.sources
+++ b/src/compiler/nir/Makefile.sources
@@ -61,6 +61,7 @@ NIR_FILES = \
nir_phi_builder.c \
nir_phi_builder.h \
nir_print.c \
+   nir_repair_ssa.c \
nir_remove_dead_variables.c \
nir_search.c \
nir_search.h \
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 76a511c..a459609 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2235,6 +2235,9 @@ bool nir_ssa_defs_interfere(nir_ssa_def *a, nir_ssa_def 
*b);
 void nir_convert_to_ssa_impl(nir_function_impl *impl);
 void nir_convert_to_ssa(nir_shader *shader);
 
+bool nir_repair_ssa_impl(nir_function_impl *impl);
+bool nir_repair_ssa(nir_shader *shader);
+
 /* If phi_webs_only is true, only convert SSA values involved in phi nodes to
  * registers.  If false, convert all values (even those not involved in a phi
  * node) to registers.
diff --git a/src/compiler/nir/nir_repair_ssa.c 
b/src/compiler/nir/nir_repair_ssa.c
new file mode 100644
index 000..96c791c
--- /dev/null
+++ b/src/compiler/nir/nir_repair_ssa.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "nir.h"
+#include "nir_phi_builder.h"
+
+struct repair_ssa_state {
+   nir_function_impl *impl;
+
+   BITSET_WORD *def_set;
+   struct nir_phi_builder *phi_builder;
+
+   bool progress;
+};
+
+/* Get ready to build a phi and return the builder */
+static struct nir_phi_builder *
+prep_build_phi(struct repair_ssa_state *state)
+{
+   const unsigned num_words = BITSET_WORDS(state->impl->num_blocks);
+
+   /* We create the phi builder on-demand. */
+   if (state->phi_builder == NULL) {
+  state->phi_builder = nir_phi_builder_create(state->impl);
+  state->def_set = ralloc_array(NULL, BITSET_WORD, num_words);
+   }
+
+   /* We're going to build a phi.  That's progress. */
+   state->progress = true;
+
+   /* Set the defs set to empty */
+   memset(state->def_set, 0, num_words * sizeof(*state->def_set));
+
+   return state->phi_builder;
+}
+
+static nir_block *
+get_src_block(nir_src *src)
+{
+   if (src->parent_instr->type == nir_instr_type_phi) {
+  return exec_node_data(nir_phi_src, src, src)->pred;
+   } else {
+  return src->parent_instr->block;
+   }
+}
+
+static bool
+repair_ssa_def(nir_ssa_def *def, void *void_state)
+{
+   struct repair_ssa_state *state = void_state;
+
+   bool is_valid = true;
+   nir_foreach_use(def, src) {
+  if (!nir_block_dominates(def->parent_instr->block, get_src_block(src))) {
+ is_valid = false;
+ break;
+  }
+   }
+
+   if (is_valid)
+  return true;
+
+   struct nir_phi_builder *pb = prep_build_phi(state);
+
+   BITSET_SET(state->def_set, 

Mesa (master): nir/dominance: Handle unreachable blocks

2016-03-24 Thread Jason Ekstrand
Module: Mesa
Branch: master
Commit: 42ddfc611f84297abeadf74be424387b127f7567
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=42ddfc611f84297abeadf74be424387b127f7567

Author: Jason Ekstrand 
Date:   Tue Dec 29 15:25:43 2015 -0800

nir/dominance: Handle unreachable blocks

Previously, nir_dominance.c didn't properly handle unreachable blocks.
This can happen if, for instance, you have something like this:

loop {
   if (...) {
  break;
   } else {
  break;
   }
}

In this case, the block right after the if statement will be unreachable.
This commit makes two changes to handle this.  First, it removes an assert
and allows block->imm_dom to be null if the block is unreachable.  Second,
it properly skips unreachable blocks in calc_dom_frontier_cb.

Reviewed-by: Jordan Justen 
Reviewed-by: Connor Abbott 

---

 src/compiler/nir/nir_dominance.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir_dominance.c b/src/compiler/nir/nir_dominance.c
index b345b85..d95f396 100644
--- a/src/compiler/nir/nir_dominance.c
+++ b/src/compiler/nir/nir_dominance.c
@@ -94,7 +94,6 @@ calc_dominance_cb(nir_block *block, void *_state)
   }
}
 
-   assert(new_idom);
if (block->imm_dom != new_idom) {
   block->imm_dom = new_idom;
   state->progress = true;
@@ -112,6 +111,11 @@ calc_dom_frontier_cb(nir_block *block, void *state)
   struct set_entry *entry;
   set_foreach(block->predecessors, entry) {
  nir_block *runner = (nir_block *) entry->key;
+
+ /* Skip unreachable predecessors */
+ if (runner->imm_dom == NULL)
+continue;
+
  while (runner != block->imm_dom) {
 _mesa_set_add(runner->dom_frontier, block);
 runner = runner->imm_dom;

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


Mesa (master): nir/cf: Handle relinking top-level blocks

2016-03-24 Thread Jason Ekstrand
Module: Mesa
Branch: master
Commit: 124f229ece8ffa7d1f8d530771f183f7803d6cdc
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=124f229ece8ffa7d1f8d530771f183f7803d6cdc

Author: Jason Ekstrand 
Date:   Fri Dec 18 11:27:00 2015 -0800

nir/cf: Handle relinking top-level blocks

This can happen if a function ends in a return instruction and you remove
the return.

Reviewed-by: Jordan Justen 
Reviewed-by: Connor Abbott 

---

 src/compiler/nir/nir_control_flow.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/compiler/nir/nir_control_flow.c 
b/src/compiler/nir/nir_control_flow.c
index 96395a4..ecd9cbd 100644
--- a/src/compiler/nir/nir_control_flow.c
+++ b/src/compiler/nir/nir_control_flow.c
@@ -336,8 +336,7 @@ block_add_normal_succs(nir_block *block)
  nir_block *next_block = nir_cf_node_as_block(next);
 
  link_blocks(block, next_block, NULL);
-  } else {
- assert(parent->type == nir_cf_node_loop);
+  } else if (parent->type == nir_cf_node_loop) {
  nir_loop *loop = nir_cf_node_as_loop(parent);
 
  nir_cf_node *head = nir_loop_first_cf_node(loop);
@@ -346,6 +345,10 @@ block_add_normal_succs(nir_block *block)
 
  link_blocks(block, head_block, NULL);
  insert_phi_undef(head_block, block);
+  } else {
+ assert(parent->type == nir_cf_node_function);
+ nir_function_impl *impl = nir_cf_node_as_function(parent);
+ link_blocks(block, impl->end_block, NULL);
   }
} else {
   nir_cf_node *next = nir_cf_node_next(>cf_node);

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


Mesa (master): nir/builder: Add helpers for easily inserting copy_var intrinsics

2016-03-24 Thread Jason Ekstrand
Module: Mesa
Branch: master
Commit: debf23ec6837506ce372f032751dc683e36d8a98
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=debf23ec6837506ce372f032751dc683e36d8a98

Author: Jason Ekstrand 
Date:   Sat Dec 26 10:48:14 2015 -0800

nir/builder: Add helpers for easily inserting copy_var intrinsics

Reviewed-by: Jordan Justen 

---

 src/compiler/nir/nir_builder.h | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index de5b6ce..b245f48 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -381,6 +381,29 @@ nir_store_var(nir_builder *build, nir_variable *var, 
nir_ssa_def *value,
nir_builder_instr_insert(build, >instr);
 }
 
+static inline void
+nir_copy_deref_var(nir_builder *build, nir_deref_var *dest, nir_deref_var *src)
+{
+   assert(nir_deref_tail(>deref)->type ==
+  nir_deref_tail(>deref)->type);
+
+   nir_intrinsic_instr *copy =
+  nir_intrinsic_instr_create(build->shader, nir_intrinsic_copy_var);
+   copy->variables[0] = nir_deref_as_var(nir_copy_deref(copy, >deref));
+   copy->variables[1] = nir_deref_as_var(nir_copy_deref(copy, >deref));
+   nir_builder_instr_insert(build, >instr);
+}
+
+static inline void
+nir_copy_var(nir_builder *build, nir_variable *dest, nir_variable *src)
+{
+   nir_intrinsic_instr *copy =
+  nir_intrinsic_instr_create(build->shader, nir_intrinsic_copy_var);
+   copy->variables[0] = nir_deref_var_create(copy, dest);
+   copy->variables[1] = nir_deref_var_create(copy, src);
+   nir_builder_instr_insert(build, >instr);
+}
+
 static inline nir_ssa_def *
 nir_load_system_value(nir_builder *build, nir_intrinsic_op op, int index)
 {

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


Mesa (master): nir: Add a phi node placement helper

2016-03-24 Thread Jason Ekstrand
Module: Mesa
Branch: master
Commit: e4dc82cfcffd9c3472b962b6bd7328788926452d
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=e4dc82cfcffd9c3472b962b6bd7328788926452d

Author: Jason Ekstrand 
Date:   Fri Feb 12 21:41:42 2016 -0800

nir: Add a phi node placement helper

Right now, we have phi placement code in two places and there are other
places where it would be nice to be able to do this analysis.  Instead of
repeating it all over the place, this commit adds a helper for placing all
of the needed phi nodes for a value.

v2: Add better documentation

Reviewed-by: Jordan Justen 

---

 src/compiler/Makefile.sources  |   2 +
 src/compiler/nir/Makefile.sources  |   2 +
 src/compiler/nir/nir_phi_builder.c | 295 +
 src/compiler/nir/nir_phi_builder.h | 115 +++
 4 files changed, 414 insertions(+)

diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources
index 6ab0aa7..c38454e 100644
--- a/src/compiler/Makefile.sources
+++ b/src/compiler/Makefile.sources
@@ -215,6 +215,8 @@ NIR_FILES = \
nir/nir_opt_peephole_select.c \
nir/nir_opt_remove_phis.c \
nir/nir_opt_undef.c \
+   nir/nir_phi_builder.c \
+   nir/nir_phi_builder.h \
nir/nir_print.c \
nir/nir_remove_dead_variables.c \
nir/nir_search.c \
diff --git a/src/compiler/nir/Makefile.sources 
b/src/compiler/nir/Makefile.sources
index f31547b..db3eecc 100644
--- a/src/compiler/nir/Makefile.sources
+++ b/src/compiler/nir/Makefile.sources
@@ -58,6 +58,8 @@ NIR_FILES = \
nir_opt_peephole_select.c \
nir_opt_remove_phis.c \
nir_opt_undef.c \
+   nir_phi_builder.c \
+   nir_phi_builder.h \
nir_print.c \
nir_remove_dead_variables.c \
nir_search.c \
diff --git a/src/compiler/nir/nir_phi_builder.c 
b/src/compiler/nir/nir_phi_builder.c
new file mode 100644
index 000..a39e360
--- /dev/null
+++ b/src/compiler/nir/nir_phi_builder.c
@@ -0,0 +1,295 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "nir_phi_builder.h"
+#include "nir/nir_vla.h"
+
+struct nir_phi_builder {
+   nir_shader *shader;
+   nir_function_impl *impl;
+
+   /* Copied from the impl for easy access */
+   unsigned num_blocks;
+
+   /* Array of all blocks indexed by block->index. */
+   nir_block **blocks;
+
+   /* Hold on to the values so we can easily iterate over them. */
+   struct exec_list values;
+
+   /* Worklist for phi adding */
+   unsigned iter_count;
+   unsigned *work;
+   nir_block **W;
+};
+
+#define NEEDS_PHI ((nir_ssa_def *)(intptr_t)-1)
+
+struct nir_phi_builder_value {
+   struct exec_node node;
+
+   struct nir_phi_builder *builder;
+
+   /* Needed so we can create phis and undefs */
+   unsigned num_components;
+   unsigned bit_size;
+
+   /* The list of phi nodes associated with this value.  Phi nodes are not
+* added directly.  Instead, they are created, the instr->block pointer
+* set, and then added to this list.  Later, in phi_builder_finish, we
+* set up their sources and add them to the top of their respective
+* blocks.
+*/
+   struct exec_list phis;
+
+   /* Array of SSA defs, indexed by block.  For each block, this array has has
+* one of three types of values:
+*
+*  - NULL. Indicates that there is no known definition in this block.  If
+*you need to find one, look at the block's immediate dominator.
+*
+*  - NEEDS_PHI. Indicates that the block may need a phi node but none has
+*been created yet.  If a def is requested for a block, a phi will need
+*to be created.
+*
+*  - A regular SSA def.  This will be either the result of a phi node or
+*one of the defs provided by nir_phi_builder_value_set_blocK_def().
+*/
+   nir_ssa_def 

Mesa (master): nir: Add a pass to inline functions

2016-03-24 Thread Jason Ekstrand
Module: Mesa
Branch: master
Commit: 22b343a8ec75a08dae6a6badbb261eab8437475d
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=22b343a8ec75a08dae6a6badbb261eab8437475d

Author: Jason Ekstrand 
Date:   Sat Feb 13 17:31:05 2016 -0800

nir: Add a pass to inline functions

This commit adds a new NIR pass that lowers all function calls away by
inlining the functions.

Reviewed-by: Jordan Justen 

---

 src/compiler/Makefile.sources   |   1 +
 src/compiler/nir/Makefile.sources   |   1 +
 src/compiler/nir/nir.h  |   2 +
 src/compiler/nir/nir_inline_functions.c | 270 
 4 files changed, 274 insertions(+)

diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources
index 74636b1..1f85172 100644
--- a/src/compiler/Makefile.sources
+++ b/src/compiler/Makefile.sources
@@ -177,6 +177,7 @@ NIR_FILES = \
nir/nir_dominance.c \
nir/nir_from_ssa.c \
nir/nir_gs_count_vertices.c \
+   nir/nir_inline_functions.c \
nir/nir_intrinsics.c \
nir/nir_intrinsics.h \
nir/nir_instr_set.c \
diff --git a/src/compiler/nir/Makefile.sources 
b/src/compiler/nir/Makefile.sources
index b9506e8..00576f0 100644
--- a/src/compiler/nir/Makefile.sources
+++ b/src/compiler/nir/Makefile.sources
@@ -20,6 +20,7 @@ NIR_FILES = \
nir_dominance.c \
nir_from_ssa.c \
nir_gs_count_vertices.c \
+   nir_inline_functions.c \
nir_intrinsics.c \
nir_intrinsics.h \
nir_instr_set.c \
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 78bbdc0..37d2907 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2149,6 +2149,8 @@ bool nir_split_var_copies(nir_shader *shader);
 bool nir_lower_returns_impl(nir_function_impl *impl);
 bool nir_lower_returns(nir_shader *shader);
 
+bool nir_inline_functions(nir_shader *shader);
+
 void nir_lower_var_copy_instr(nir_intrinsic_instr *copy, void *mem_ctx);
 void nir_lower_var_copies(nir_shader *shader);
 
diff --git a/src/compiler/nir/nir_inline_functions.c 
b/src/compiler/nir/nir_inline_functions.c
new file mode 100644
index 000..4a08dcc
--- /dev/null
+++ b/src/compiler/nir/nir_inline_functions.c
@@ -0,0 +1,270 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "nir.h"
+#include "nir_builder.h"
+#include "nir_control_flow.h"
+
+struct inline_functions_state {
+   struct set *inlined;
+   nir_builder builder;
+   bool progress;
+};
+
+static bool inline_function_impl(nir_function_impl *impl, struct set *inlined);
+
+static bool
+rewrite_param_derefs_block(nir_block *block, void *void_state)
+{
+   nir_call_instr *call = void_state;
+
+   nir_foreach_instr_safe(block, instr) {
+  if (instr->type != nir_instr_type_intrinsic)
+ continue;
+
+  nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
+
+  for (unsigned i = 0;
+   i < nir_intrinsic_infos[intrin->intrinsic].num_variables; i++) {
+ if (intrin->variables[i]->var->data.mode != nir_var_param)
+continue;
+
+ int param_idx = intrin->variables[i]->var->data.location;
+
+ nir_deref_var *call_deref;
+ if (param_idx >= 0) {
+assert(param_idx < call->callee->num_params);
+call_deref = call->params[param_idx];
+ } else {
+call_deref = call->return_deref;
+ }
+ assert(call_deref);
+
+ nir_deref_var *new_deref = nir_deref_as_var(nir_copy_deref(intrin, 
_deref->deref));
+ nir_deref *new_tail = nir_deref_tail(_deref->deref);
+ new_tail->child = intrin->variables[i]->deref.child;
+ ralloc_steal(new_tail, new_tail->child);
+ intrin->variables[i] = new_deref;
+  }
+   }
+
+   return true;
+}
+
+static void

Mesa (master): nir/vars_to_ssa: Use the new nir_phi_builder helper

2016-03-24 Thread Jason Ekstrand
Module: Mesa
Branch: master
Commit: ea98d415e42b7a97b8c9f37eb2e0e0f6ad98d14e
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=ea98d415e42b7a97b8c9f37eb2e0e0f6ad98d14e

Author: Jason Ekstrand 
Date:   Fri Feb 12 21:48:26 2016 -0800

nir/vars_to_ssa: Use the new nir_phi_builder helper

The efficiency should be approximately the same.  We do a little more work
per phi node because we have to sort the predecessors.  However, we no
longer have to walk the blocks a second time to pop things off the stack.
The bigger advantage, however, is that we can now re-use the phi placement
and per-block SSA value tracking in other passes.

As a side-benifit, the phi builder actually handles unreachable blocks
correctly.  The original vars_to_ssa code, because of the way it iterated
the blocks and added phi sources, didn't add sources corresponding to
predecessors of unreachable blocks.  The new strategy employed by the phi
builder creates a phi source for each predecessor and should correctly
handle unreachable blocks by setting those sources to SSA undefs.

Reviewed-by: Jordan Justen 

---

 src/compiler/nir/nir_lower_vars_to_ssa.c | 493 +--
 1 file changed, 134 insertions(+), 359 deletions(-)

diff --git a/src/compiler/nir/nir_lower_vars_to_ssa.c 
b/src/compiler/nir/nir_lower_vars_to_ssa.c
index 2331791..9f9e454 100644
--- a/src/compiler/nir/nir_lower_vars_to_ssa.c
+++ b/src/compiler/nir/nir_lower_vars_to_ssa.c
@@ -27,6 +27,7 @@
 
 #include "nir.h"
 #include "nir_builder.h"
+#include "nir_phi_builder.h"
 #include "nir_vla.h"
 
 
@@ -47,8 +48,7 @@ struct deref_node {
struct set *stores;
struct set *copies;
 
-   nir_ssa_def **def_stack;
-   nir_ssa_def **def_stack_tail;
+   struct nir_phi_builder_value *pb_value;
 
struct deref_node *wildcard;
struct deref_node *indirect;
@@ -87,8 +87,7 @@ struct lower_variables_state {
 */
bool add_to_direct_deref_nodes;
 
-   /* A hash table mapping phi nodes to deref_state data */
-   struct hash_table *phi_table;
+   struct nir_phi_builder *phi_builder;
 };
 
 static struct deref_node *
@@ -473,114 +472,6 @@ lower_copies_to_load_store(struct deref_node *node,
return true;
 }
 
-/** Pushes an SSA def onto the def stack for the given node
- *
- * Each node is potentially associated with a stack of SSA definitions.
- * This stack is used for determining what SSA definition reaches a given
- * point in the program for variable renaming.  The stack is always kept in
- * dominance-order with at most one SSA def per block.  If the SSA
- * definition on the top of the stack is in the same block as the one being
- * pushed, the top element is replaced.
- */
-static void
-def_stack_push(struct deref_node *node, nir_ssa_def *def,
-   struct lower_variables_state *state)
-{
-   if (node->def_stack == NULL) {
-  node->def_stack = ralloc_array(state->dead_ctx, nir_ssa_def *,
- state->impl->num_blocks);
-  node->def_stack_tail = node->def_stack - 1;
-   }
-
-   if (node->def_stack_tail >= node->def_stack) {
-  nir_ssa_def *top_def = *node->def_stack_tail;
-
-  if (def->parent_instr->block == top_def->parent_instr->block) {
- /* They're in the same block, just replace the top */
- *node->def_stack_tail = def;
- return;
-  }
-   }
-
-   *(++node->def_stack_tail) = def;
-}
-
-/* Pop the top of the def stack if it's in the given block */
-static void
-def_stack_pop_if_in_block(struct deref_node *node, nir_block *block)
-{
-   /* If we're popping, then we have presumably pushed at some time in the
-* past so this should exist.
-*/
-   assert(node->def_stack != NULL);
-
-   /* The stack is already empty.  Do nothing. */
-   if (node->def_stack_tail < node->def_stack)
-  return;
-
-   nir_ssa_def *def = *node->def_stack_tail;
-   if (def->parent_instr->block == block)
-  node->def_stack_tail--;
-}
-
-/** Retrieves the SSA definition on the top of the stack for the given
- * node, if one exists.  If the stack is empty, then we return the constant
- * initializer (if it exists) or an SSA undef.
- */
-static nir_ssa_def *
-get_ssa_def_for_block(struct deref_node *node, nir_block *block,
-  struct lower_variables_state *state)
-{
-   /* If we have something on the stack, go ahead and return it.  We're
-* assuming that the top of the stack dominates the given block.
-*/
-   if (node->def_stack && node->def_stack_tail >= node->def_stack)
-  return *node->def_stack_tail;
-
-   /* If we got here then we don't have a definition that dominates the
-* given block.  This means that we need to add an undef and use that.
-*/
-   nir_ssa_undef_instr *undef =
-  nir_ssa_undef_instr_create(state->shader,
- glsl_get_vector_elements(node->type));
-   nir_instr_insert_before_cf_list(>impl->body, >instr);
-   def_stack_push(node, 

Mesa (master): nir/cf: Make extracting or re-inserting nothing a no-op

2016-03-24 Thread Jason Ekstrand
Module: Mesa
Branch: master
Commit: 97b663481c8c83fda06246860708530cff755a05
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=97b663481c8c83fda06246860708530cff755a05

Author: Jason Ekstrand 
Date:   Wed Dec 23 18:10:08 2015 -0800

nir/cf: Make extracting or re-inserting nothing a no-op

Reviewed-by: Jordan Justen 
Reviewed-by: Connor Abbott 

---

 src/compiler/nir/nir_control_flow.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/src/compiler/nir/nir_control_flow.c 
b/src/compiler/nir/nir_control_flow.c
index ecd9cbd..33b06d0 100644
--- a/src/compiler/nir/nir_control_flow.c
+++ b/src/compiler/nir/nir_control_flow.c
@@ -749,6 +749,12 @@ nir_cf_extract(nir_cf_list *extracted, nir_cursor begin, 
nir_cursor end)
 {
nir_block *block_begin, *block_end, *block_before, *block_after;
 
+   if (nir_cursors_equal(begin, end)) {
+  exec_list_make_empty(>list);
+  extracted->impl = NULL; /* we shouldn't need this */
+  return;
+   }
+
/* In the case where begin points to an instruction in some basic block and
 * end points to the end of the same basic block, we rely on the fact that
 * splitting on an instruction moves earlier instructions into a new basic
@@ -788,6 +794,9 @@ nir_cf_reinsert(nir_cf_list *cf_list, nir_cursor cursor)
 {
nir_block *before, *after;
 
+   if (exec_list_is_empty(_list->list))
+  return;
+
split_block_cursor(cursor, , );
 
foreach_list_typed_safe(nir_cf_node, node, node, _list->list) {

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


Mesa (master): nir: Add return lowering pass

2016-03-24 Thread Jason Ekstrand
Module: Mesa
Branch: master
Commit: 79dec93ead6e3b95b1240a9d843d617a88ee9179
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=79dec93ead6e3b95b1240a9d843d617a88ee9179

Author: Jason Ekstrand 
Date:   Sat Feb 13 17:08:57 2016 -0800

nir: Add return lowering pass

This commit adds a NIR pass for lowering away returns in functions.  If the
return is in a loop, it is lowered to a break.  If it is not in a loop,
it's lowered away by moving/deleting code as needed.

Reviewed-by: Jordan Justen 

---

 src/compiler/Makefile.sources|   1 +
 src/compiler/nir/Makefile.sources|   1 +
 src/compiler/nir/nir.h   |   3 +
 src/compiler/nir/nir_lower_returns.c | 246 +++
 4 files changed, 251 insertions(+)

diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources
index 796d004..74636b1 100644
--- a/src/compiler/Makefile.sources
+++ b/src/compiler/Makefile.sources
@@ -194,6 +194,7 @@ NIR_FILES = \
nir/nir_lower_io.c \
nir/nir_lower_outputs_to_temporaries.c \
nir/nir_lower_phis_to_scalar.c \
+   nir/nir_lower_returns.c \
nir/nir_lower_samplers.c \
nir/nir_lower_system_values.c \
nir/nir_lower_tex.c \
diff --git a/src/compiler/nir/Makefile.sources 
b/src/compiler/nir/Makefile.sources
index c149355..b9506e8 100644
--- a/src/compiler/nir/Makefile.sources
+++ b/src/compiler/nir/Makefile.sources
@@ -37,6 +37,7 @@ NIR_FILES = \
nir_lower_io.c \
nir_lower_outputs_to_temporaries.c \
nir_lower_phis_to_scalar.c \
+   nir_lower_returns.c \
nir_lower_samplers.c \
nir_lower_system_values.c \
nir_lower_tex.c \
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 51d2e79..78bbdc0 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2146,6 +2146,9 @@ int nir_gs_count_vertices(const nir_shader *shader);
 
 bool nir_split_var_copies(nir_shader *shader);
 
+bool nir_lower_returns_impl(nir_function_impl *impl);
+bool nir_lower_returns(nir_shader *shader);
+
 void nir_lower_var_copy_instr(nir_intrinsic_instr *copy, void *mem_ctx);
 void nir_lower_var_copies(nir_shader *shader);
 
diff --git a/src/compiler/nir/nir_lower_returns.c 
b/src/compiler/nir/nir_lower_returns.c
new file mode 100644
index 000..91bb2f7
--- /dev/null
+++ b/src/compiler/nir/nir_lower_returns.c
@@ -0,0 +1,246 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "nir.h"
+#include "nir_builder.h"
+#include "nir_control_flow.h"
+
+struct lower_returns_state {
+   nir_builder builder;
+   struct exec_list *cf_list;
+   nir_loop *loop;
+   nir_variable *return_flag;
+};
+
+static bool lower_returns_in_cf_list(struct exec_list *cf_list,
+ struct lower_returns_state *state);
+
+static void
+predicate_following(nir_cf_node *node, struct lower_returns_state *state)
+{
+   nir_builder *b = >builder;
+   b->cursor = nir_after_cf_node_and_phis(node);
+
+   if (nir_cursors_equal(b->cursor, nir_after_cf_list(state->cf_list)))
+  return; /* Nothing to predicate */
+
+   assert(state->return_flag);
+
+   nir_if *if_stmt = nir_if_create(b->shader);
+   if_stmt->condition = nir_src_for_ssa(nir_load_var(b, state->return_flag));
+   nir_cf_node_insert(b->cursor, _stmt->cf_node);
+
+   if (state->loop) {
+  /* If we're inside of a loop, then all we need to do is insert a
+   * conditional break.
+   */
+  nir_jump_instr *brk =
+ nir_jump_instr_create(state->builder.shader, nir_jump_break);
+  nir_instr_insert(nir_before_cf_list(_stmt->then_list), >instr);
+   } else {
+  /* Otherwise, we need to actually move everything into the else case
+   * of the if statement.
+   */
+  nir_cf_list list;
+  nir_cf_extract(, 

Mesa (master): nir: Add a cursor helper for getting a cursor after any phi nodes

2016-03-24 Thread Jason Ekstrand
Module: Mesa
Branch: master
Commit: 8d61d7252433a0470b441c70085391d3dd4c04bb
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=8d61d7252433a0470b441c70085391d3dd4c04bb

Author: Jason Ekstrand 
Date:   Sun Dec 27 22:50:14 2015 -0800

nir: Add a cursor helper for getting a cursor after any phi nodes

Reviewed-by: Jordan Justen 

---

 src/compiler/nir/nir.h | 16 
 1 file changed, 16 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 718d281..51d2e79 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -1935,6 +1935,22 @@ nir_after_cf_node(nir_cf_node *node)
 }
 
 static inline nir_cursor
+nir_after_cf_node_and_phis(nir_cf_node *node)
+{
+   if (node->type == nir_cf_node_block)
+  return nir_after_block(nir_cf_node_as_block(node));
+
+   nir_block *block = nir_cf_node_as_block(nir_cf_node_next(node));
+   assert(block->cf_node.type == nir_cf_node_block);
+
+   nir_foreach_instr(block, instr) {
+  if (instr->type != nir_instr_type_phi)
+ return nir_before_instr(instr);
+   }
+   return nir_after_block(block);
+}
+
+static inline nir_cursor
 nir_before_cf_list(struct exec_list *cf_list)
 {
nir_cf_node *first_node = exec_node_data(nir_cf_node,

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


Mesa (master): nir: Add a function for comparing cursors

2016-03-24 Thread Jason Ekstrand
Module: Mesa
Branch: master
Commit: 7022a673cd6b9e4bdd4c55fe1d7c76c04d27d4e6
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=7022a673cd6b9e4bdd4c55fe1d7c76c04d27d4e6

Author: Jason Ekstrand 
Date:   Sat Dec 26 10:32:10 2015 -0800

nir: Add a function for comparing cursors

Reviewed-by: Jordan Justen 

---

 src/compiler/nir/nir.c | 56 ++
 src/compiler/nir/nir.h |  2 ++
 2 files changed, 58 insertions(+)

diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 20f1a18..b67916d 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -724,6 +724,62 @@ nir_cf_node_get_function(nir_cf_node *node)
return nir_cf_node_as_function(node);
 }
 
+/* Reduces a cursor by trying to convert everything to after and trying to
+ * go up to block granularity when possible.
+ */
+static nir_cursor
+reduce_cursor(nir_cursor cursor)
+{
+   switch (cursor.option) {
+   case nir_cursor_before_block:
+  assert(nir_cf_node_prev(>cf_node) == NULL ||
+ nir_cf_node_prev(>cf_node)->type != 
nir_cf_node_block);
+  if (exec_list_is_empty(>instr_list)) {
+ /* Empty block.  After is as good as before. */
+ cursor.option = nir_cursor_after_block;
+  }
+  return cursor;
+
+   case nir_cursor_after_block:
+  return cursor;
+
+   case nir_cursor_before_instr: {
+  nir_instr *prev_instr = nir_instr_prev(cursor.instr);
+  if (prev_instr) {
+ /* Before this instruction is after the previous */
+ cursor.instr = prev_instr;
+ cursor.option = nir_cursor_after_instr;
+  } else {
+ /* No previous instruction.  Switch to before block */
+ cursor.block = cursor.instr->block;
+ cursor.option = nir_cursor_before_block;
+  }
+  return reduce_cursor(cursor);
+   }
+
+   case nir_cursor_after_instr:
+  if (nir_instr_next(cursor.instr) == NULL) {
+ /* This is the last instruction, switch to after block */
+ cursor.option = nir_cursor_after_block;
+ cursor.block = cursor.instr->block;
+  }
+  return cursor;
+
+   default:
+  unreachable("Inavlid cursor option");
+   }
+}
+
+bool
+nir_cursors_equal(nir_cursor a, nir_cursor b)
+{
+   /* Reduced cursors should be unique */
+   a = reduce_cursor(a);
+   b = reduce_cursor(b);
+
+   return a.block == b.block && a.option == b.option;
+}
+
 static bool
 add_use_cb(nir_src *src, void *state)
 {
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index a459609..718d281 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -1867,6 +1867,8 @@ typedef struct {
};
 } nir_cursor;
 
+bool nir_cursors_equal(nir_cursor a, nir_cursor b);
+
 static inline nir_cursor
 nir_before_block(nir_block *block)
 {

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


Mesa (master): nir/builder: Add a helper for inserting jump instructions

2016-03-24 Thread Jason Ekstrand
Module: Mesa
Branch: master
Commit: 18b01667493bd61c9c3eafd0848322b23da20efd
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=18b01667493bd61c9c3eafd0848322b23da20efd

Author: Jason Ekstrand 
Date:   Sat Feb 13 17:14:27 2016 -0800

nir/builder: Add a helper for inserting jump instructions

Reviewed-by: Jordan Justen 

---

 src/compiler/nir/nir_builder.h | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index 64d7b43..de5b6ce 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -393,4 +393,11 @@ nir_load_system_value(nir_builder *build, nir_intrinsic_op 
op, int index)
return >dest.ssa;
 }
 
+static inline void
+nir_jump(nir_builder *build, nir_jump_type jump_type)
+{
+   nir_jump_instr *jump = nir_jump_instr_create(build->shader, jump_type);
+   nir_builder_instr_insert(build, >instr);
+}
+
 #endif /* NIR_BUILDER_H */

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


Mesa (master): util/bitset: Allow iterating over const bitsets

2016-03-24 Thread Jason Ekstrand
Module: Mesa
Branch: master
Commit: 9a41d947319f2d2999b4b5442ce20443d7c3cf3a
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=9a41d947319f2d2999b4b5442ce20443d7c3cf3a

Author: Jason Ekstrand 
Date:   Sat Jan 16 16:42:06 2016 -0800

util/bitset: Allow iterating over const bitsets

Reviewed-by: Jordan Justen 

---

 src/util/bitset.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/bitset.h b/src/util/bitset.h
index c452819..2404ce7 100644
--- a/src/util/bitset.h
+++ b/src/util/bitset.h
@@ -98,7 +98,7 @@ __bitset_ffs(const BITSET_WORD *x, int n)
 
 static inline unsigned
 __bitset_next_set(unsigned i, BITSET_WORD *tmp,
-  BITSET_WORD *set, unsigned size)
+  const BITSET_WORD *set, unsigned size)
 {
unsigned bit, word;
 

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


Mesa (vulkan): anv: Sanitize Image extents and offsets

2016-03-24 Thread Nanley Chery
Module: Mesa
Branch: vulkan
Commit: a5dc3c0f02aa523d1d3d123b62b9a187821079fe
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=a5dc3c0f02aa523d1d3d123b62b9a187821079fe

Author: Nanley Chery 
Date:   Tue Mar 22 10:53:37 2016 -0700

anv: Sanitize Image extents and offsets

Prepare Image extents and offsets for internal consumption by assigning
the default values implicitly defned by the spec. Fixes textures on
several Vulkan demos in which the VkImageCopy depth is set to zero when
copying a 2D image.

v2 (Jason Ekstrand):
   Replace "prep" with "sanitize"
   Make function static inline
   Pass structs instead of pointers

Reviewed-by: Jason Ekstrand 
Signed-off-by: Nanley Chery 

---

 src/intel/vulkan/anv_image.c| 24 -
 src/intel/vulkan/anv_meta_copy.c| 53 ++---
 src/intel/vulkan/anv_meta_resolve.c | 41 +---
 src/intel/vulkan/anv_private.h  | 33 +++
 4 files changed, 106 insertions(+), 45 deletions(-)

diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 143a084..b47425b 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -124,30 +124,16 @@ make_surface(const struct anv_device *dev,
 
struct anv_surface *anv_surf = get_surface(image, aspect);
 
-   VkExtent3D extent;
-   switch (vk_info->imageType) {
-   case VK_IMAGE_TYPE_1D:
-  extent = (VkExtent3D) { vk_info->extent.width, 1, 1 };
-  break;
-   case VK_IMAGE_TYPE_2D:
-  extent = (VkExtent3D) { vk_info->extent.width, vk_info->extent.height, 1 
};
-  break;
-   case VK_IMAGE_TYPE_3D:
-  extent = vk_info->extent;
-  break;
-   default:
-  unreachable("invalid image type");
-   }
-
-   image->extent = extent;
+   image->extent = anv_sanitize_image_extent(vk_info->imageType,
+ vk_info->extent);
 
ok = isl_surf_init(>isl_dev, _surf->isl,
   .dim = vk_to_isl_surf_dim[vk_info->imageType],
   .format = anv_get_isl_format(vk_info->format, aspect,
vk_info->tiling, NULL),
-  .width = extent.width,
-  .height = extent.height,
-  .depth = extent.depth,
+  .width = image->extent.width,
+  .height = image->extent.height,
+  .depth = image->extent.depth,
   .levels = vk_info->mipLevels,
   .array_len = vk_info->arrayLayers,
   .samples = vk_info->samples,
diff --git a/src/intel/vulkan/anv_meta_copy.c b/src/intel/vulkan/anv_meta_copy.c
index 1a2bfd6..982fa7e 100644
--- a/src/intel/vulkan/anv_meta_copy.c
+++ b/src/intel/vulkan/anv_meta_copy.c
@@ -28,16 +28,16 @@
  * if Image is uncompressed or compressed, respectively.
  */
 static struct VkExtent3D
-meta_region_extent_el(const VkFormat format,
+meta_region_extent_el(const struct anv_image *image,
   const struct VkExtent3D *extent)
 {
const struct isl_format_layout *isl_layout =
-  anv_format_for_vk_format(format)->isl_layout;
-   return (VkExtent3D) {
+  anv_format_for_vk_format(image->vk_format)->isl_layout;
+   return anv_sanitize_image_extent(image->type, (VkExtent3D) {
   .width  = DIV_ROUND_UP(extent->width , isl_layout->bw),
   .height = DIV_ROUND_UP(extent->height, isl_layout->bh),
   .depth  = DIV_ROUND_UP(extent->depth , isl_layout->bd),
-   };
+   });
 }
 
 /* Returns the user-provided VkBufferImageCopy::imageOffset in units of
@@ -49,11 +49,11 @@ meta_region_offset_el(const struct anv_image *image,
   const struct VkOffset3D *offset)
 {
const struct isl_format_layout *isl_layout = image->format->isl_layout;
-   return (VkOffset3D) {
+   return anv_sanitize_image_offset(image->type, (VkOffset3D) {
   .x = offset->x / isl_layout->bw,
   .y = offset->y / isl_layout->bh,
   .z = offset->z / isl_layout->bd,
-   };
+   });
 }
 
 static struct anv_meta_blit2d_surf
@@ -115,17 +115,28 @@ meta_copy_buffer_to_image(struct anv_cmd_buffer 
*cmd_buffer,
 
for (unsigned r = 0; r < regionCount; r++) {
 
-  /* Start creating blit rect */
+  /**
+   * From the Vulkan 1.0.6 spec: 18.3 Copying Data Between Images
+   *extent is the size in texels of the source image to copy in width,
+   *height and depth. 1D images use only x and width. 2D images use x, 
y,
+   *width and height. 3D images use x, y, z, width, height and depth.
+   *
+   *
+   * Also, convert the offsets and extent from units of texels to units of
+   * blocks - which is the highest resolution accessible in this command.
+   */
   const VkOffset3D img_offset_el =
  meta_region_offset_el(image, [r].imageOffset);
   const VkExtent3D bufferExtent = {
  .width = pRegions[r].bufferRowLength,
  .height = pRegions[r].bufferImageHeight,
   };
+
+  /* Start creating blit rect */
   const 

Mesa (master): ttn: remove stray global from header

2016-03-24 Thread Rob Clark
Module: Mesa
Branch: master
Commit: 61c7d20e4f3c2902582acfcd7212f3357034f33b
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=61c7d20e4f3c2902582acfcd7212f3357034f33b

Author: Rob Clark 
Date:   Thu Mar 24 15:44:35 2016 -0400

ttn: remove stray global from header

Signed-off-by: Rob Clark 

---

 src/gallium/auxiliary/nir/tgsi_to_nir.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.h 
b/src/gallium/auxiliary/nir/tgsi_to_nir.h
index 0651870..f480009 100644
--- a/src/gallium/auxiliary/nir/tgsi_to_nir.h
+++ b/src/gallium/auxiliary/nir/tgsi_to_nir.h
@@ -23,8 +23,6 @@
 
 #include "compiler/nir/nir.h"
 
-struct nir_shader_compiler_options *options;
-
 struct nir_shader *
 tgsi_to_nir(const void *tgsi_tokens,
 const struct nir_shader_compiler_options *options);

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


Mesa (master): mesa: Include null terminator in GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH.

2016-03-24 Thread Kenneth Graunke
Module: Mesa
Branch: master
Commit: 412e686da9e64d5b56b0a9c57c2b95624c56ea05
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=412e686da9e64d5b56b0a9c57c2b95624c56ea05

Author: Kenneth Graunke 
Date:   Wed Mar 23 21:38:42 2016 -0700

mesa: Include null terminator in GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH.

From the KHR_debug spec:
"Applications can query the number of messages currently in the log by
 obtaining the value of DEBUG_LOGGED_MESSAGES, and the string length
 (including its null terminator) of the oldest message in the log
 through the value of DEBUG_NEXT_LOGGED_MESSAGE_LENGTH."

Because we weren't including the null terminator, many dEQP tests
called glGetDebugMessageLog with a bufSize parameter that was 1 too
small, and unable to contain the message, so we skipped returning it,
failing many cases.

Fixes 298 dEQP-GLES31.functional.debug.* tests.

Signed-off-by: Kenneth Graunke 
Reviewed-by: Stephane Marchesin 
Reviewed-by: Eduardo Lima Mitev 

---

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

diff --git a/src/mesa/main/debug_output.c b/src/mesa/main/debug_output.c
index c2b9f05..74be855 100644
--- a/src/mesa/main/debug_output.c
+++ b/src/mesa/main/debug_output.c
@@ -779,7 +779,7 @@ _mesa_get_debug_state_int(struct gl_context *ctx, GLenum 
pname)
   break;
case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
   val = (debug->Log.NumMessages) ?
- debug->Log.Messages[debug->Log.NextMessage].length : 0;
+ debug->Log.Messages[debug->Log.NextMessage].length + 1 : 0;
   break;
case GL_DEBUG_GROUP_STACK_DEPTH:
   val = debug->CurrentGroup + 1;

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


Mesa (master): nv50/ir: silence unhandled TGSI_PROPERTY_NEXT_SHADER info

2016-03-24 Thread Samuel Pitoiset
Module: Mesa
Branch: master
Commit: b9c70fcdadec9a73db13794e89253ababc063574
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=b9c70fcdadec9a73db13794e89253ababc063574

Author: Samuel Pitoiset 
Date:   Wed Mar 23 23:29:20 2016 +0100

nv50/ir: silence unhandled TGSI_PROPERTY_NEXT_SHADER info

radeonsi uses this property to make the best decision about which
shader to compile, but this is not currently used by our codegen.

Signed-off-by: Samuel Pitoiset 
Reviewed-by: Ilia Mirkin 

---

 src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp 
b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
index 12f2551..611d5f9 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_tgsi.cpp
@@ -1039,6 +1039,9 @@ void Source::scanProperty(const struct tgsi_full_property 
*prop)
case TGSI_PROPERTY_NUM_CULLDIST_ENABLED:
   info->io.cullDistances = prop->u[0].Data;
   break;
+   case TGSI_PROPERTY_NEXT_SHADER:
+  /* Do not need to know the next shader stage. */
+  break;
default:
   INFO("unhandled TGSI property %d\n", prop->Property.PropertyName);
   break;

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


Mesa (master): mesa: Handle negative length in glPushDebugGroup().

2016-03-24 Thread Kenneth Graunke
Module: Mesa
Branch: master
Commit: d1bb1df87ed8518693730efc80b3a8b9912bb7bf
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=d1bb1df87ed8518693730efc80b3a8b9912bb7bf

Author: Kenneth Graunke 
Date:   Wed Mar 23 23:46:12 2016 -0700

mesa: Handle negative length in glPushDebugGroup().

The KHR_debug spec doesn't actually say we should handle this, but that
is most likely an oversight - it says to check against strlen and
generate errors if length is negative.  It appears they just forgot to
explicitly spell out that we should then proceed to actually handle it.

Fixes crashes from uncaught std::string exceptions in many
dEQP-GLES31.functional.debug.error_filters.* tests.

Signed-off-by: Kenneth Graunke 
Reviewed-by: Eduardo Lima Mitev 

---

 src/mesa/main/debug_output.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/mesa/main/debug_output.c b/src/mesa/main/debug_output.c
index 001f63e..85f64bd 100644
--- a/src/mesa/main/debug_output.c
+++ b/src/mesa/main/debug_output.c
@@ -1189,6 +1189,9 @@ _mesa_PushDebugGroup(GLenum source, GLuint id, GLsizei 
length,
if (!validate_length(ctx, callerstr, length, message))
   return; /* GL_INVALID_VALUE */
 
+   if (length < 0)
+  length = strlen(message);
+
debug = _mesa_lock_debug_state(ctx);
if (!debug)
   return;

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


Mesa (master): mesa: Make glDebugMessageInsert deal with negative length for all types.

2016-03-24 Thread Kenneth Graunke
Module: Mesa
Branch: master
Commit: 028459a00d6faec85ea75ebbaff75fb6f1d91bff
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=028459a00d6faec85ea75ebbaff75fb6f1d91bff

Author: Kenneth Graunke 
Date:   Wed Mar 23 23:35:40 2016 -0700

mesa: Make glDebugMessageInsert deal with negative length for all types.

From the KHR_debug spec, section 5.5.5 (Externally Generated Messages):

   "If  is negative, it is implied that  contains a null
terminated string. The error INVALID_VALUE will be generated if the
number of characters in , excluding the null terminator when
 is negative, is not less than the value of
MAX_DEBUG_MESSAGE_LENGTH."

This indicates that length should be set to strlen for all types, not
just GL_DEBUG_TYPE_MARKER.  We want it to be after validate_length()
so we still generate appropriate errors.

Fixes crashes from uncaught std::string exceptions in many
dEQP-GLES31.functional.debug.error_filters.* tests.

Signed-off-by: Kenneth Graunke 
Reviewed-by: Eduardo Lima Mitev 

---

 src/mesa/main/debug_output.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/debug_output.c b/src/mesa/main/debug_output.c
index 74be855..001f63e 100644
--- a/src/mesa/main/debug_output.c
+++ b/src/mesa/main/debug_output.c
@@ -1009,15 +1009,16 @@ _mesa_DebugMessageInsert(GLenum source, GLenum type, 
GLuint id,
if (!validate_length(ctx, callerstr, length, buf))
   return; /* GL_INVALID_VALUE */
 
+   /* if length not specified, string will be null terminated: */
+   if (length < 0)
+  length = strlen(buf);
+
_mesa_log_msg(ctx, gl_enum_to_debug_source(source),
  gl_enum_to_debug_type(type), id,
  gl_enum_to_debug_severity(severity),
  length, buf);
 
if (type == GL_DEBUG_TYPE_MARKER && ctx->Driver.EmitStringMarker) {
-  /* if length not specified, string will be null terminated: */
-  if (length < 0)
- length = strlen(buf);
   ctx->Driver.EmitStringMarker(ctx, buf, length);
}
 }

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


Mesa (master): radeonsi: silence a coverity warning

2016-03-24 Thread Nicolai Hähnle
Module: Mesa
Branch: master
Commit: 7880b81d39e56f1d4b062519f087a053c01ee0e4
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=7880b81d39e56f1d4b062519f087a053c01ee0e4

Author: Nicolai Hähnle 
Date:   Wed Mar 23 11:58:28 2016 -0500

radeonsi: silence a coverity warning

The following Coverity warning

5378tmpl.fetch_args = atomic_fetch_args;
5379tmpl.emit = atomic_emit;
>>> CID 1357115:  Uninitialized variables  (UNINIT)
>>> Using uninitialized value "tmpl". Field "tmpl.intr_name" is 
>>> uninitialized.
5380bld_base->op_actions[TGSI_OPCODE_ATOMUADD] = tmpl;
5381bld_base->op_actions[TGSI_OPCODE_ATOMUADD].intr_name = "add";

... is a false positive, but what the hell. This change should "fix" it.

Reviewed-by: Marek Olšák 

---

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

diff --git a/src/gallium/drivers/radeonsi/si_shader.c 
b/src/gallium/drivers/radeonsi/si_shader.c
index 1e4bf82..9eb531f 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -5362,7 +5362,7 @@ static void si_init_shader_ctx(struct si_shader_context 
*ctx,
   LLVMTargetMachineRef tm)
 {
struct lp_build_tgsi_context *bld_base;
-   struct lp_build_tgsi_action tmpl;
+   struct lp_build_tgsi_action tmpl = {};
 
memset(ctx, 0, sizeof(*ctx));
radeon_llvm_context_init(>radeon_bld, "amdgcn--");

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


Mesa (master): st/mesa: use RGBA instead of BGRA for SRGB_ALPHA

2016-03-24 Thread Nicolai Hähnle
Module: Mesa
Branch: master
Commit: 6b763c026de0aa4c18bb698ddcfd25d04c73e56e
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=6b763c026de0aa4c18bb698ddcfd25d04c73e56e

Author: Nicolai Hähnle 
Date:   Wed Mar 23 15:22:16 2016 -0500

st/mesa: use RGBA instead of BGRA for SRGB_ALPHA

This fixes a regression introduced by commit a8eea696 "st/mesa: honour sized
internal formats in st_choose_format (v2)".

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=94657
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=94671
Reviewed-by: Marek Olšák 

---

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

diff --git a/src/mesa/state_tracker/st_format.c 
b/src/mesa/state_tracker/st_format.c
index 4b5f819..9a280fc 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -1309,7 +1309,7 @@ static const struct format_mapping format_map[] = {
},
{
   { GL_SRGB_ALPHA_EXT, GL_SRGB8_ALPHA8_EXT, 0 },
-  { DEFAULT_SRGBA_FORMATS }
+  { PIPE_FORMAT_R8G8B8A8_SRGB, DEFAULT_SRGBA_FORMATS }
},
{
   { GL_COMPRESSED_SRGB_EXT, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 0 },

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


Mesa (master): mesa: replace gl_context-> Multisample._Enabled with _mesa_is_multisample_enabled.

2016-03-24 Thread Brian Paul
Module: Mesa
Branch: master
Commit: f96309753b7f5f4ea5e1942778087b3ace8eda9b
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=f96309753b7f5f4ea5e1942778087b3ace8eda9b

Author: Bas Nieuwenhuizen 
Date:   Thu Mar 24 08:30:09 2016 -0600

mesa: replace gl_context->Multisample._Enabled with 
_mesa_is_multisample_enabled.

This removes any dependency on driver validation of the number of
framebuffer samples.

Signed-off-by: Bas Nieuwenhuizen 
Reviewed-by: Edward O'Callaghan 
Reviewed-by: Marek Olšák 
Tested-by: Brian Paul 

---

 src/mesa/drivers/dri/i965/brw_util.h   |  5 +++--
 src/mesa/drivers/dri/i965/gen6_cc.c|  6 +++---
 src/mesa/drivers/dri/i965/gen6_multisample_state.c |  2 +-
 src/mesa/drivers/dri/i965/gen8_blend_state.c   |  6 +++---
 src/mesa/drivers/dri/i965/gen8_depth_state.c   |  3 ++-
 src/mesa/drivers/dri/i965/gen8_sf_state.c  |  4 ++--
 src/mesa/main/framebuffer.c| 19 +++
 src/mesa/main/framebuffer.h|  3 +++
 src/mesa/main/mtypes.h |  1 -
 src/mesa/main/state.c  | 17 -
 src/mesa/program/prog_statevars.c  |  2 +-
 src/mesa/state_tracker/st_atom_rasterizer.c|  5 +++--
 src/mesa/state_tracker/st_atom_shader.c|  2 +-
 src/mesa/swrast/s_points.c |  4 ++--
 14 files changed, 43 insertions(+), 36 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_util.h 
b/src/mesa/drivers/dri/i965/brw_util.h
index 1f27e98..3e9a6ee 100644
--- a/src/mesa/drivers/dri/i965/brw_util.h
+++ b/src/mesa/drivers/dri/i965/brw_util.h
@@ -34,6 +34,7 @@
 #define BRW_UTIL_H
 
 #include "brw_context.h"
+#include "main/framebuffer.h"
 
 extern GLuint brw_translate_blend_factor( GLenum factor );
 extern GLuint brw_translate_blend_equation( GLenum mode );
@@ -49,13 +50,13 @@ brw_get_line_width(struct brw_context *brw)
 * implementation-dependent maximum non-antialiased line width."
 */
float line_width =
-  CLAMP(!brw->ctx.Multisample._Enabled && !brw->ctx.Line.SmoothFlag
+  CLAMP(!_mesa_is_multisample_enabled(>ctx) && 
!brw->ctx.Line.SmoothFlag
 ? roundf(brw->ctx.Line.Width) : brw->ctx.Line.Width,
 0.0f, brw->ctx.Const.MaxLineWidth);
uint32_t line_width_u3_7 = U_FIXED(line_width, 7);
 
/* Line width of 0 is not allowed when MSAA enabled */
-   if (brw->ctx.Multisample._Enabled) {
+   if (_mesa_is_multisample_enabled(>ctx)) {
   if (line_width_u3_7 == 0)
  line_width_u3_7 = 1;
} else if (brw->ctx.Line.SmoothFlag && line_width < 1.5f) {
diff --git a/src/mesa/drivers/dri/i965/gen6_cc.c 
b/src/mesa/drivers/dri/i965/gen6_cc.c
index cee139b..f5a7d4d 100644
--- a/src/mesa/drivers/dri/i965/gen6_cc.c
+++ b/src/mesa/drivers/dri/i965/gen6_cc.c
@@ -198,14 +198,14 @@ gen6_upload_blend_state(struct brw_context *brw)
   if(!is_buffer_zero_integer_format) {
  /* _NEW_MULTISAMPLE */
  blend[b].blend1.alpha_to_coverage =
-ctx->Multisample._Enabled && 
ctx->Multisample.SampleAlphaToCoverage;
+_mesa_is_multisample_enabled(ctx) && 
ctx->Multisample.SampleAlphaToCoverage;
 
/* From SandyBridge PRM, volume 2 Part 1, section 8.2.3, BLEND_STATE:
 * DWord 1, Bit 30 (AlphaToOne Enable):
 * "If Dual Source Blending is enabled, this bit must be disabled"
 */
  WARN_ONCE(ctx->Color.Blend[b]._UsesDualSrc &&
-   ctx->Multisample._Enabled &&
+   _mesa_is_multisample_enabled(ctx) &&
ctx->Multisample.SampleAlphaToOne,
"HW workaround: disabling alpha to one with dual src "
"blending\n");
@@ -213,7 +213,7 @@ gen6_upload_blend_state(struct brw_context *brw)
 blend[b].blend1.alpha_to_one = false;
 else
blend[b].blend1.alpha_to_one =
-  ctx->Multisample._Enabled && ctx->Multisample.SampleAlphaToOne;
+  _mesa_is_multisample_enabled(ctx) && 
ctx->Multisample.SampleAlphaToOne;
 
  blend[b].blend1.alpha_to_coverage_dither = (brw->gen >= 7);
   }
diff --git a/src/mesa/drivers/dri/i965/gen6_multisample_state.c 
b/src/mesa/drivers/dri/i965/gen6_multisample_state.c
index 8eb620d..fcd313a 100644
--- a/src/mesa/drivers/dri/i965/gen6_multisample_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_multisample_state.c
@@ -171,7 +171,7 @@ gen6_determine_sample_mask(struct brw_context *brw)
/* BRW_NEW_NUM_SAMPLES */
unsigned num_samples = brw->num_samples;
 
-   if (ctx->Multisample._Enabled) {
+   if (_mesa_is_multisample_enabled(ctx)) {
   if (ctx->Multisample.SampleCoverage) {
  coverage = ctx->Multisample.SampleCoverageValue;
  coverage_invert = ctx->Multisample.SampleCoverageInvert;
diff 

Mesa (master): nir: fix dangling ssadef->name ptrs

2016-03-24 Thread Rob Clark
Module: Mesa
Branch: master
Commit: 0bea0e7141a7698118bfd465fdb4adf8e0b21bc8
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=0bea0e7141a7698118bfd465fdb4adf8e0b21bc8

Author: Rob Clark 
Date:   Tue Mar 22 15:02:42 2016 -0400

nir: fix dangling ssadef->name ptrs

In many places, the convention is to pass an existing ssadef name ptr
when construction/initializing a new nir_ssa_def.  But that goes badly
(as noticed by garbage in nir_print output) when the original string
gets freed.

Just use ralloc_strdup() instead, and add ralloc_free() in the two
places that would care (not that the strings wouldn't eventually get
freed anyways).

Also fixup the nir_search code which was directly setting ssadef->name
to use the parent instruction as memctx.

Signed-off-by: Rob Clark 
Reviewed-by: Jason Ekstrand 

---

 src/compiler/nir/nir.c| 4 +++-
 src/compiler/nir/nir_search.c | 6 +++---
 src/compiler/nir/nir_to_ssa.c | 2 ++
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index b114981..20f1a18 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -1317,12 +1317,13 @@ nir_instr_rewrite_dest(nir_instr *instr, nir_dest 
*dest, nir_dest new_dest)
   src_add_all_uses(dest->reg.indirect, instr, NULL);
 }
 
+/* note: does *not* take ownership of 'name' */
 void
 nir_ssa_def_init(nir_instr *instr, nir_ssa_def *def,
  unsigned num_components,
  unsigned bit_size, const char *name)
 {
-   def->name = name;
+   def->name = ralloc_strdup(instr, name);
def->parent_instr = instr;
list_inithead(>uses);
list_inithead(>if_uses);
@@ -1339,6 +1340,7 @@ nir_ssa_def_init(nir_instr *instr, nir_ssa_def *def,
}
 }
 
+/* note: does *not* take ownership of 'name' */
 void
 nir_ssa_dest_init(nir_instr *instr, nir_dest *dest,
  unsigned num_components, unsigned bit_size,
diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c
index 110ab5e..6e63063 100644
--- a/src/compiler/nir/nir_search.c
+++ b/src/compiler/nir/nir_search.c
@@ -469,7 +469,7 @@ construct_value(const nir_search_value *value,
 
   switch (c->type) {
   case nir_type_float:
- load->def.name = ralloc_asprintf(mem_ctx, "%f", c->data.d);
+ load->def.name = ralloc_asprintf(load, "%f", c->data.d);
  switch (bitsize->dest_size) {
  case 32:
 load->value.f32[0] = c->data.d;
@@ -483,7 +483,7 @@ construct_value(const nir_search_value *value,
  break;
 
   case nir_type_int:
- load->def.name = ralloc_asprintf(mem_ctx, "%ld", c->data.i);
+ load->def.name = ralloc_asprintf(load, "%ld", c->data.i);
  switch (bitsize->dest_size) {
  case 32:
 load->value.i32[0] = c->data.i;
@@ -497,7 +497,7 @@ construct_value(const nir_search_value *value,
  break;
 
   case nir_type_uint:
- load->def.name = ralloc_asprintf(mem_ctx, "%lu", c->data.u);
+ load->def.name = ralloc_asprintf(load, "%lu", c->data.u);
  switch (bitsize->dest_size) {
  case 32:
 load->value.u32[0] = c->data.u;
diff --git a/src/compiler/nir/nir_to_ssa.c b/src/compiler/nir/nir_to_ssa.c
index 0640607..d588d7d 100644
--- a/src/compiler/nir/nir_to_ssa.c
+++ b/src/compiler/nir/nir_to_ssa.c
@@ -221,6 +221,7 @@ rewrite_def_forwards(nir_dest *dest, void *_state)
list_del(>reg.def_link);
nir_ssa_dest_init(state->parent_instr, dest, reg->num_components,
  reg->bit_size, name);
+   ralloc_free(name);
 
/* push our SSA destination on the stack */
state->states[index].index++;
@@ -274,6 +275,7 @@ rewrite_alu_instr_forward(nir_alu_instr *instr, 
rewrite_state *state)
   list_del(>dest.dest.reg.def_link);
   nir_ssa_dest_init(>instr, >dest.dest, num_components,
 reg->bit_size, name);
+  ralloc_free(name);
 
   if (nir_op_infos[instr->op].output_size == 0) {
  /*

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