Re: [Mesa-dev] [PATCH] egl: Emit correct error when robust context creation fails

2016-12-26 Thread Tapani Pälli

Reviewed-by: Tapani Pälli 

On 12/23/2016 03:29 AM, Chad Versace wrote:

Fixes dEQP-EGL.functional.create_context_ext.robust_*
on Intel with GBM.

If the user sets the EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR in
EGL_CONTEXT_FLAGS_KHR when creating an OpenGL ES context, then
EGL_KHR_create_context spec requires that we unconditionally emit
EGL_BAD_ATTRIBUTE because that flag does not exist for OpenGL ES. When
creating an OpenGL context, the spec requires that we emit EGL_BAD_MATCH
if we can't support the request; that error is generated in the egl_dri2
layer where the driver capability is actually checked.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=99188
Cc: mesa-sta...@lists.freedesktop.org
---
 src/egl/main/eglcontext.c | 38 ++
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c
index 60625f6470..5313e1dabc 100644
--- a/src/egl/main/eglcontext.c
+++ b/src/egl/main/eglcontext.c
@@ -184,19 +184,33 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay 
*dpy,
 break;
  }

- /* The EGL_KHR_create_context_spec says:
-  *
-  * "If the EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR bit is set in
-  * EGL_CONTEXT_FLAGS_KHR, then a context supporting  will be created. Robust buffer access is defined in the
-  * GL_ARB_robustness extension specification, and the resulting
-  * context must also support either the GL_ARB_robustness
-  * extension, or a version of OpenGL incorporating equivalent
-  * functionality. This bit is supported for OpenGL contexts.
-  */
  if ((val & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) &&
- (api != EGL_OPENGL_API ||
-  !dpy->Extensions.EXT_create_context_robustness)) {
+ api != EGL_OPENGL_API) {
+/* The EGL_KHR_create_context spec says:
+ *
+ *   10) Which error should be generated if robust buffer access
+ *   or reset notifications are requested under OpenGL ES?
+ *
+ *   As per Issue 6, this extension does not support creating
+ *   robust contexts for OpenGL ES. This is only supported via
+ *   the EGL_EXT_create_context_robustness extension.
+ *
+ *   Attempting to use this extension to create robust OpenGL
+ *   ES context will generate an EGL_BAD_ATTRIBUTE error. This
+ *   specific error is generated because this extension does
+ *   not define the EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR
+ *   and EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR
+ *   bits for OpenGL ES contexts. Thus, use of these bits fall
+ *   under condition described by: "If an attribute is
+ *   specified that is not meaningful for the client API
+ *   type.." in the above specification.
+ *
+ * The spec requires that we emit the error even if the display
+ * supports EGL_EXT_create_context_robustness. To create a robust
+ * GLES context, the *attribute*
+ * EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT must be used, not the
+ * *flag* EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR.
+ */
 err = EGL_BAD_ATTRIBUTE;
 break;
  }


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


Re: [Mesa-dev] [PATCH 1/8] nir: Make nir_copy_deref follow the "clone" pattern

2016-12-26 Thread Jordan Justen
On 2016-12-26 09:13:28, Jason Ekstrand wrote:
> We rename it to nir_deref_clone, re-order the sources to match the other
> clone functions, and expose nir_deref_var_clone.  This past part, in
> particular, lets us get rid of quite a few lines since we no longer have
> to call nir_copy_deref and wrap it in deref_to_var.

deref_to_var => deref_as_var

Reviewed-by: Jordan Justen 

> ---
>  src/compiler/glsl/glsl_to_nir.cpp  |  3 +--
>  src/compiler/nir/nir.c | 22 
> +++---
>  src/compiler/nir/nir.h |  4 ++--
>  src/compiler/nir/nir_builder.h |  6 +++---
>  src/compiler/nir/nir_inline_functions.c|  2 +-
>  src/compiler/nir/nir_lower_indirect_derefs.c   |  6 ++
>  src/compiler/nir/nir_lower_tex.c   | 18 ++
>  src/compiler/nir/nir_lower_var_copies.c|  4 ++--
>  src/compiler/nir/nir_split_var_copies.c| 17 +++--
>  src/compiler/spirv/spirv_to_nir.c  | 22 
> ++
>  src/compiler/spirv/vtn_glsl450.c   |  3 +--
>  src/compiler/spirv/vtn_variables.c |  3 +--
>  src/intel/vulkan/anv_nir_lower_input_attachments.c |  3 +--
>  13 files changed, 48 insertions(+), 65 deletions(-)
> 
> diff --git a/src/compiler/glsl/glsl_to_nir.cpp 
> b/src/compiler/glsl/glsl_to_nir.cpp
> index fcaca9f..8efd030 100644
> --- a/src/compiler/glsl/glsl_to_nir.cpp
> +++ b/src/compiler/glsl/glsl_to_nir.cpp
> @@ -1179,8 +1179,7 @@ nir_visitor::visit(ir_assignment *ir)
>nir_intrinsic_instr_create(this->shader, nir_intrinsic_store_var);
> store->num_components = ir->lhs->type->vector_elements;
> nir_intrinsic_set_write_mask(store, ir->write_mask);
> -   nir_deref *store_deref = nir_copy_deref(store, _deref->deref);
> -   store->variables[0] = nir_deref_as_var(store_deref);
> +   store->variables[0] = nir_deref_var_clone(lhs_deref, store);
> store->src[0] = nir_src_for_ssa(src);
>  
> if (ir->condition) {
> diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
> index 885616e..6057143 100644
> --- a/src/compiler/nir/nir.c
> +++ b/src/compiler/nir/nir.c
> @@ -624,18 +624,18 @@ nir_deref_struct_create(void *mem_ctx, unsigned 
> field_index)
> return deref;
>  }
>  
> -static nir_deref_var *
> -copy_deref_var(void *mem_ctx, nir_deref_var *deref)
> +nir_deref_var *
> +nir_deref_var_clone(const nir_deref_var *deref, void *mem_ctx)
>  {
> nir_deref_var *ret = nir_deref_var_create(mem_ctx, deref->var);
> ret->deref.type = deref->deref.type;
> if (deref->deref.child)
> -  ret->deref.child = nir_copy_deref(ret, deref->deref.child);
> +  ret->deref.child = nir_deref_clone(deref->deref.child, ret);
> return ret;
>  }
>  
>  static nir_deref_array *
> -copy_deref_array(void *mem_ctx, nir_deref_array *deref)
> +deref_array_clone(const nir_deref_array *deref, void *mem_ctx)
>  {
> nir_deref_array *ret = nir_deref_array_create(mem_ctx);
> ret->base_offset = deref->base_offset;
> @@ -645,33 +645,33 @@ copy_deref_array(void *mem_ctx, nir_deref_array *deref)
> }
> ret->deref.type = deref->deref.type;
> if (deref->deref.child)
> -  ret->deref.child = nir_copy_deref(ret, deref->deref.child);
> +  ret->deref.child = nir_deref_clone(deref->deref.child, ret);
> return ret;
>  }
>  
>  static nir_deref_struct *
> -copy_deref_struct(void *mem_ctx, nir_deref_struct *deref)
> +deref_struct_clone(const nir_deref_struct *deref, void *mem_ctx)
>  {
> nir_deref_struct *ret = nir_deref_struct_create(mem_ctx, deref->index);
> ret->deref.type = deref->deref.type;
> if (deref->deref.child)
> -  ret->deref.child = nir_copy_deref(ret, deref->deref.child);
> +  ret->deref.child = nir_deref_clone(deref->deref.child, ret);
> return ret;
>  }
>  
>  nir_deref *
> -nir_copy_deref(void *mem_ctx, nir_deref *deref)
> +nir_deref_clone(const nir_deref *deref, void *mem_ctx)
>  {
> if (deref == NULL)
>return NULL;
>  
> switch (deref->deref_type) {
> case nir_deref_type_var:
> -  return _deref_var(mem_ctx, nir_deref_as_var(deref))->deref;
> +  return _deref_var_clone(nir_deref_as_var(deref), mem_ctx)->deref;
> case nir_deref_type_array:
> -  return _deref_array(mem_ctx, nir_deref_as_array(deref))->deref;
> +  return _array_clone(nir_deref_as_array(deref), mem_ctx)->deref;
> case nir_deref_type_struct:
> -  return _deref_struct(mem_ctx, nir_deref_as_struct(deref))->deref;
> +  return _struct_clone(nir_deref_as_struct(deref), mem_ctx)->deref;
> default:
>unreachable("Invalid dereference type");
> }
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index 6557631..d896679 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -1927,8 +1927,6 @@ nir_deref_var *nir_deref_var_create(void *mem_ctx, 
> 

[Mesa-dev] [PATCH 3/8] nir/lower_io: Use the builder instead of carrying a mem_ctx

2016-12-26 Thread Jason Ekstrand
---
 src/compiler/nir/nir_lower_io.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c
index 6628947..7dff26b 100644
--- a/src/compiler/nir/nir_lower_io.c
+++ b/src/compiler/nir/nir_lower_io.c
@@ -36,7 +36,6 @@
 
 struct lower_io_state {
nir_builder builder;
-   void *mem_ctx;
int (*type_size)(const struct glsl_type *type);
nir_variable_mode modes;
nir_lower_io_options options;
@@ -204,7 +203,8 @@ lower_load(nir_intrinsic_instr *intrin, struct 
lower_io_state *state,
   unreachable("Unknown variable mode");
}
 
-   nir_intrinsic_instr *load = nir_intrinsic_instr_create(state->mem_ctx, op);
+   nir_intrinsic_instr *load =
+  nir_intrinsic_instr_create(state->builder.shader, op);
load->num_components = intrin->num_components;
 
nir_intrinsic_set_base(load, var->data.driver_location);
@@ -244,7 +244,8 @@ lower_store(nir_intrinsic_instr *intrin, struct 
lower_io_state *state,
   nir_intrinsic_store_output;
}
 
-   nir_intrinsic_instr *store = nir_intrinsic_instr_create(state->mem_ctx, op);
+   nir_intrinsic_instr *store =
+  nir_intrinsic_instr_create(state->builder.shader, op);
store->num_components = intrin->num_components;
 
nir_src_copy(>src[0], >src[0], store);
@@ -291,7 +292,7 @@ lower_atomic(nir_intrinsic_instr *intrin, struct 
lower_io_state *state,
}
 
nir_intrinsic_instr *atomic =
-  nir_intrinsic_instr_create(state->mem_ctx, op);
+  nir_intrinsic_instr_create(state->builder.shader, op);
 
nir_intrinsic_set_base(atomic, var->data.driver_location);
 
@@ -333,7 +334,7 @@ lower_interpolate_at(nir_intrinsic_instr *intrin, struct 
lower_io_state *state,
}
 
nir_intrinsic_instr *bary_setup =
-  nir_intrinsic_instr_create(state->mem_ctx, bary_op);
+  nir_intrinsic_instr_create(state->builder.shader, bary_op);
 
nir_ssa_dest_init(_setup->instr, _setup->dest, 2, 32, NULL);
nir_intrinsic_set_interp_mode(bary_setup, var->data.interpolation);
@@ -344,7 +345,7 @@ lower_interpolate_at(nir_intrinsic_instr *intrin, struct 
lower_io_state *state,
nir_builder_instr_insert(>builder, _setup->instr);
 
nir_intrinsic_instr *load =
-  nir_intrinsic_instr_create(state->mem_ctx,
+  nir_intrinsic_instr_create(state->builder.shader,
  nir_intrinsic_load_interpolated_input);
load->num_components = intrin->num_components;
 
@@ -467,7 +468,7 @@ nir_lower_io_block(nir_block *block,
 nir_ssa_def_rewrite_uses(>dest.ssa,
  nir_src_for_ssa(>dest.ssa));
  } else {
-nir_dest_copy(>dest, >dest, state->mem_ctx);
+nir_dest_copy(>dest, >dest, >instr);
  }
   }
 
@@ -487,7 +488,6 @@ nir_lower_io_impl(nir_function_impl *impl,
struct lower_io_state state;
 
nir_builder_init(, impl);
-   state.mem_ctx = ralloc_parent(impl);
state.modes = modes;
state.type_size = type_size;
state.options = options;
-- 
2.5.0.400.gff86faf

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


[Mesa-dev] [PATCH 2/8] nir/from_ssa: Use nir_builder for emit_copy

2016-12-26 Thread Jason Ekstrand
This lets us get rid of the void *mem_ctx parameter and make things a
bit more type safe.
---
 src/compiler/nir/nir_from_ssa.c | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/compiler/nir/nir_from_ssa.c b/src/compiler/nir/nir_from_ssa.c
index 603d1a5..2d8eed5 100644
--- a/src/compiler/nir/nir_from_ssa.c
+++ b/src/compiler/nir/nir_from_ssa.c
@@ -26,6 +26,7 @@
  */
 
 #include "nir.h"
+#include "nir_builder.h"
 #include "nir_vla.h"
 
 /*
@@ -35,12 +36,11 @@
  */
 
 struct from_ssa_state {
-   void *mem_ctx;
+   nir_builder builder;
void *dead_ctx;
bool phi_webs_only;
struct hash_table *merge_node_table;
nir_instr *instr;
-   nir_function_impl *impl;
 };
 
 /* Returns true if a dominates b */
@@ -477,7 +477,7 @@ rewrite_ssa_def(nir_ssa_def *def, void *void_state)
* matter which node's definition we use.
*/
   if (node->set->reg == NULL)
- node->set->reg = create_reg_for_ssa_def(def, state->impl);
+ node->set->reg = create_reg_for_ssa_def(def, state->builder.impl);
 
   reg = node->set->reg;
} else {
@@ -490,7 +490,7 @@ rewrite_ssa_def(nir_ssa_def *def, void *void_state)
   if (def->parent_instr->type == nir_instr_type_load_const)
  return true;
 
-  reg = create_reg_for_ssa_def(def, state->impl);
+  reg = create_reg_for_ssa_def(def, state->builder.impl);
}
 
nir_ssa_def_rewrite_uses(def, nir_src_for_reg(reg));
@@ -539,8 +539,7 @@ resolve_registers_block(nir_block *block, struct 
from_ssa_state *state)
 }
 
 static void
-emit_copy(nir_parallel_copy_instr *pcopy, nir_src src, nir_src dest_src,
-  void *mem_ctx)
+emit_copy(nir_builder *b, nir_src src, nir_src dest_src)
 {
assert(!dest_src.is_ssa &&
   dest_src.reg.indirect == NULL &&
@@ -551,12 +550,12 @@ emit_copy(nir_parallel_copy_instr *pcopy, nir_src src, 
nir_src dest_src,
else
   assert(src.reg.reg->num_components >= dest_src.reg.reg->num_components);
 
-   nir_alu_instr *mov = nir_alu_instr_create(mem_ctx, nir_op_imov);
+   nir_alu_instr *mov = nir_alu_instr_create(b->shader, nir_op_imov);
nir_src_copy(>src[0].src, , mov);
mov->dest.dest = nir_dest_for_reg(dest_src.reg.reg);
mov->dest.write_mask = (1 << dest_src.reg.reg->num_components) - 1;
 
-   nir_instr_insert_before(>instr, >instr);
+   nir_builder_instr_insert(b, >instr);
 }
 
 /* Resolves a single parallel copy operation into a sequence of mov's
@@ -613,6 +612,8 @@ resolve_parallel_copy(nir_parallel_copy_instr *pcopy,
NIR_VLA(int, to_do, num_copies * 2);
int to_do_idx = -1;
 
+   state->builder.cursor = nir_before_instr(>instr);
+
/* Now we set everything up:
 *  - All values get assigned a temporary index
 *  - Current locations are set from sources
@@ -676,7 +677,7 @@ resolve_parallel_copy(nir_parallel_copy_instr *pcopy,
   while (ready_idx >= 0) {
  int b = ready[ready_idx--];
  int a = pred[b];
- emit_copy(pcopy, values[loc[a]], values[b], state->mem_ctx);
+ emit_copy(>builder, values[loc[a]], values[b]);
 
  /* If any other copies want a they can find it at b */
  loc[a] = b;
@@ -702,7 +703,7 @@ resolve_parallel_copy(nir_parallel_copy_instr *pcopy,
* backend can coalesce the (possibly multiple) temporaries.
*/
   assert(num_vals < num_copies * 2);
-  nir_register *reg = nir_local_reg_create(state->impl);
+  nir_register *reg = nir_local_reg_create(state->builder.impl);
   reg->name = "copy_temp";
   reg->num_array_elems = 0;
   if (values[b].is_ssa)
@@ -712,7 +713,7 @@ resolve_parallel_copy(nir_parallel_copy_instr *pcopy,
   values[num_vals].is_ssa = false;
   values[num_vals].reg.reg = reg;
 
-  emit_copy(pcopy, values[b], values[num_vals], state->mem_ctx);
+  emit_copy(>builder, values[b], values[num_vals]);
   loc[b] = num_vals;
   ready[++ready_idx] = b;
   num_vals++;
@@ -760,9 +761,8 @@ nir_convert_from_ssa_impl(nir_function_impl *impl, bool 
phi_webs_only)
 {
struct from_ssa_state state;
 
-   state.mem_ctx = ralloc_parent(impl);
+   nir_builder_init(, impl);
state.dead_ctx = ralloc_context(NULL);
-   state.impl = impl;
state.phi_webs_only = phi_webs_only;
state.merge_node_table = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
 _mesa_key_pointer_equal);
-- 
2.5.0.400.gff86faf

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


[Mesa-dev] [PATCH 7/8] nir/split_var_copies: Use a nir_shader rather than a void *mem_ctx

2016-12-26 Thread Jason Ekstrand
---
 src/compiler/nir/nir_split_var_copies.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir_split_var_copies.c 
b/src/compiler/nir/nir_split_var_copies.c
index cfebb0b..94a45ee 100644
--- a/src/compiler/nir/nir_split_var_copies.c
+++ b/src/compiler/nir/nir_split_var_copies.c
@@ -62,7 +62,7 @@
  */
 
 struct split_var_copies_state {
-   void *mem_ctx;
+   nir_shader *shader;
void *dead_ctx;
bool progress;
 };
@@ -176,7 +176,7 @@ split_var_copy_instr(nir_intrinsic_instr *old_copy,
   * actually add the new copy instruction.
   */
  nir_intrinsic_instr *new_copy =
-nir_intrinsic_instr_create(state->mem_ctx, nir_intrinsic_copy_var);
+nir_intrinsic_instr_create(state->shader, nir_intrinsic_copy_var);
 
  /* We need to make copies because a) this deref chain actually
   * belongs to the copy instruction and b) the deref chains may
@@ -254,7 +254,7 @@ split_var_copies_impl(nir_function_impl *impl)
 {
struct split_var_copies_state state;
 
-   state.mem_ctx = ralloc_parent(impl);
+   state.shader = impl->function->shader;
state.dead_ctx = ralloc_context(NULL);
state.progress = false;
 
-- 
2.5.0.400.gff86faf

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


[Mesa-dev] [PATCH 5/8] nir/conditional_if: Properly use the builder

2016-12-26 Thread Jason Ekstrand
We were passing around a void *mem_ctx and using that to initialize the
builder which was wrong since that pointed to ralloc_parent(impl) which
is the shader but the builder is supposed to be initialized with the
nir_function_impl.
---
 src/compiler/nir/nir_opt_conditional_discard.c | 21 ++---
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/compiler/nir/nir_opt_conditional_discard.c 
b/src/compiler/nir/nir_opt_conditional_discard.c
index 2fde179..3605eaf 100644
--- a/src/compiler/nir/nir_opt_conditional_discard.c
+++ b/src/compiler/nir/nir_opt_conditional_discard.c
@@ -30,10 +30,8 @@
  */
 
 static bool
-nir_opt_conditional_discard_block(nir_block *block, void *mem_ctx)
+nir_opt_conditional_discard_block(nir_builder *b, nir_block *block)
 {
-   nir_builder bld;
-
if (nir_cf_node_is_first(>cf_node))
   return false;
 
@@ -88,17 +86,16 @@ nir_opt_conditional_discard_block(nir_block *block, void 
*mem_ctx)
 
nir_src cond;
 
-   nir_builder_init(, mem_ctx);
-   bld.cursor = nir_before_cf_node(prev_node);
+   b->cursor = nir_before_cf_node(prev_node);
if (intrin->intrinsic == nir_intrinsic_discard)
   cond = if_stmt->condition;
else
-  cond = nir_src_for_ssa(nir_iand(,
-  nir_ssa_for_src(, 
if_stmt->condition, 1),
-  nir_ssa_for_src(, intrin->src[0], 
1)));
+  cond = nir_src_for_ssa(nir_iand(b,
+  nir_ssa_for_src(b, if_stmt->condition, 
1),
+  nir_ssa_for_src(b, intrin->src[0], 1)));
 
nir_intrinsic_instr *discard_if =
-  nir_intrinsic_instr_create(mem_ctx, nir_intrinsic_discard_if);
+  nir_intrinsic_instr_create(b->shader, nir_intrinsic_discard_if);
nir_src_copy(_if->src[0], , discard_if);
 
nir_instr_insert_before_cf(prev_node, _if->instr);
@@ -113,11 +110,13 @@ nir_opt_conditional_discard(nir_shader *shader)
 {
bool progress = false;
 
+   nir_builder builder;
+
nir_foreach_function(function, shader) {
   if (function->impl) {
- void *mem_ctx = ralloc_parent(function->impl);
+ nir_builder_init(, function->impl);
  nir_foreach_block_safe(block, function->impl) {
-progress |= nir_opt_conditional_discard_block(block, mem_ctx);
+progress |= nir_opt_conditional_discard_block(, block);
  }
   }
}
-- 
2.5.0.400.gff86faf

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


[Mesa-dev] [PATCH 8/8] i965/peephole_ffma: Use nir_builder

2016-12-26 Thread Jason Ekstrand
---
 .../drivers/dri/i965/brw_nir_opt_peephole_ffma.c   | 43 +++---
 1 file changed, 14 insertions(+), 29 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_nir_opt_peephole_ffma.c 
b/src/mesa/drivers/dri/i965/brw_nir_opt_peephole_ffma.c
index 14a9a0f..cc225e1 100644
--- a/src/mesa/drivers/dri/i965/brw_nir_opt_peephole_ffma.c
+++ b/src/mesa/drivers/dri/i965/brw_nir_opt_peephole_ffma.c
@@ -26,18 +26,13 @@
  */
 
 #include "brw_nir.h"
+#include "compiler/nir/nir_builder.h"
 
 /*
  * Implements a small peephole optimization that looks for a multiply that
  * is only ever used in an add and replaces both with an fma.
  */
 
-struct peephole_ffma_state {
-   void *mem_ctx;
-   nir_function_impl *impl;
-   bool progress;
-};
-
 static inline bool
 are_all_uses_fadd(nir_ssa_def *def)
 {
@@ -167,7 +162,7 @@ any_alu_src_is_a_constant(nir_alu_src srcs[])
 }
 
 static bool
-brw_nir_opt_peephole_ffma_block(nir_block *block, void *mem_ctx)
+brw_nir_opt_peephole_ffma_block(nir_builder *b, nir_block *block)
 {
bool progress = false;
 
@@ -229,29 +224,17 @@ brw_nir_opt_peephole_ffma_block(nir_block *block, void 
*mem_ctx)
  continue;
   }
 
+  b->cursor = nir_before_instr(>instr);
+
   if (abs) {
- for (unsigned i = 0; i < 2; i++) {
-nir_alu_instr *abs = nir_alu_instr_create(mem_ctx, nir_op_fabs);
-abs->src[0].src = nir_src_for_ssa(mul_src[i]);
-nir_ssa_dest_init(>instr, >dest.dest,
-  mul_src[i]->num_components, bit_size, NULL);
-abs->dest.write_mask = (1 << mul_src[i]->num_components) - 1;
-nir_instr_insert_before(>instr, >instr);
-mul_src[i] = >dest.dest.ssa;
- }
+ for (unsigned i = 0; i < 2; i++)
+mul_src[i] = nir_fabs(b, mul_src[i]);
   }
 
-  if (negate) {
- nir_alu_instr *neg = nir_alu_instr_create(mem_ctx, nir_op_fneg);
- neg->src[0].src = nir_src_for_ssa(mul_src[0]);
- nir_ssa_dest_init(>instr, >dest.dest,
-   mul_src[0]->num_components, bit_size, NULL);
- neg->dest.write_mask = (1 << mul_src[0]->num_components) - 1;
- nir_instr_insert_before(>instr, >instr);
- mul_src[0] = >dest.dest.ssa;
-  }
+  if (negate)
+ mul_src[0] = nir_fneg(b, mul_src[0]);
 
-  nir_alu_instr *ffma = nir_alu_instr_create(mem_ctx, nir_op_ffma);
+  nir_alu_instr *ffma = nir_alu_instr_create(b->shader, nir_op_ffma);
   ffma->dest.saturate = add->dest.saturate;
   ffma->dest.write_mask = add->dest.write_mask;
 
@@ -271,7 +254,7 @@ brw_nir_opt_peephole_ffma_block(nir_block *block, void 
*mem_ctx)
   nir_ssa_def_rewrite_uses(>dest.dest.ssa,
nir_src_for_ssa(>dest.dest.ssa));
 
-  nir_instr_insert_before(>instr, >instr);
+  nir_builder_instr_insert(b, >instr);
   assert(list_empty(>dest.dest.ssa.uses));
   nir_instr_remove(>instr);
 
@@ -285,10 +268,12 @@ static bool
 brw_nir_opt_peephole_ffma_impl(nir_function_impl *impl)
 {
bool progress = false;
-   void *mem_ctx = ralloc_parent(impl);
+
+   nir_builder builder;
+   nir_builder_init(, impl);
 
nir_foreach_block(block, impl) {
-  progress |= brw_nir_opt_peephole_ffma_block(block, mem_ctx);
+  progress |= brw_nir_opt_peephole_ffma_block(, block);
}
 
if (progress)
-- 
2.5.0.400.gff86faf

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


[Mesa-dev] [PATCH 6/8] nir/opt_peephole_select: Pass around the actual nir_shader

2016-12-26 Thread Jason Ekstrand
---
 src/compiler/nir/nir_opt_peephole_select.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/compiler/nir/nir_opt_peephole_select.c 
b/src/compiler/nir/nir_opt_peephole_select.c
index 9c85c17..87a8ee0 100644
--- a/src/compiler/nir/nir_opt_peephole_select.c
+++ b/src/compiler/nir/nir_opt_peephole_select.c
@@ -147,7 +147,8 @@ block_check_for_allowed_instrs(nir_block *block, unsigned 
*count, bool alu_ok)
 }
 
 static bool
-nir_opt_peephole_select_block(nir_block *block, void *mem_ctx, unsigned limit)
+nir_opt_peephole_select_block(nir_block *block, nir_shader *shader,
+  unsigned limit)
 {
if (nir_cf_node_is_first(>cf_node))
   return false;
@@ -203,7 +204,7 @@ nir_opt_peephole_select_block(nir_block *block, void 
*mem_ctx, unsigned limit)
  break;
 
   nir_phi_instr *phi = nir_instr_as_phi(instr);
-  nir_alu_instr *sel = nir_alu_instr_create(mem_ctx, nir_op_bcsel);
+  nir_alu_instr *sel = nir_alu_instr_create(shader, nir_op_bcsel);
   nir_src_copy(>src[0].src, _stmt->condition, sel);
   /* Splat the condition to all channels */
   memset(sel->src[0].swizzle, 0, sizeof sel->src[0].swizzle);
@@ -236,11 +237,11 @@ nir_opt_peephole_select_block(nir_block *block, void 
*mem_ctx, unsigned limit)
 static bool
 nir_opt_peephole_select_impl(nir_function_impl *impl, unsigned limit)
 {
-   void *mem_ctx = ralloc_parent(impl);
+   nir_shader *shader = impl->function->shader;
bool progress = false;
 
nir_foreach_block_safe(block, impl) {
-  progress |= nir_opt_peephole_select_block(block, mem_ctx, limit);
+  progress |= nir_opt_peephole_select_block(block, shader, limit);
}
 
if (progress)
-- 
2.5.0.400.gff86faf

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


[Mesa-dev] [PATCH 1/8] nir: Make nir_copy_deref follow the "clone" pattern

2016-12-26 Thread Jason Ekstrand
We rename it to nir_deref_clone, re-order the sources to match the other
clone functions, and expose nir_deref_var_clone.  This past part, in
particular, lets us get rid of quite a few lines since we no longer have
to call nir_copy_deref and wrap it in deref_to_var.
---
 src/compiler/glsl/glsl_to_nir.cpp  |  3 +--
 src/compiler/nir/nir.c | 22 +++---
 src/compiler/nir/nir.h |  4 ++--
 src/compiler/nir/nir_builder.h |  6 +++---
 src/compiler/nir/nir_inline_functions.c|  2 +-
 src/compiler/nir/nir_lower_indirect_derefs.c   |  6 ++
 src/compiler/nir/nir_lower_tex.c   | 18 ++
 src/compiler/nir/nir_lower_var_copies.c|  4 ++--
 src/compiler/nir/nir_split_var_copies.c| 17 +++--
 src/compiler/spirv/spirv_to_nir.c  | 22 ++
 src/compiler/spirv/vtn_glsl450.c   |  3 +--
 src/compiler/spirv/vtn_variables.c |  3 +--
 src/intel/vulkan/anv_nir_lower_input_attachments.c |  3 +--
 13 files changed, 48 insertions(+), 65 deletions(-)

diff --git a/src/compiler/glsl/glsl_to_nir.cpp 
b/src/compiler/glsl/glsl_to_nir.cpp
index fcaca9f..8efd030 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -1179,8 +1179,7 @@ nir_visitor::visit(ir_assignment *ir)
   nir_intrinsic_instr_create(this->shader, nir_intrinsic_store_var);
store->num_components = ir->lhs->type->vector_elements;
nir_intrinsic_set_write_mask(store, ir->write_mask);
-   nir_deref *store_deref = nir_copy_deref(store, _deref->deref);
-   store->variables[0] = nir_deref_as_var(store_deref);
+   store->variables[0] = nir_deref_var_clone(lhs_deref, store);
store->src[0] = nir_src_for_ssa(src);
 
if (ir->condition) {
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 885616e..6057143 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -624,18 +624,18 @@ nir_deref_struct_create(void *mem_ctx, unsigned 
field_index)
return deref;
 }
 
-static nir_deref_var *
-copy_deref_var(void *mem_ctx, nir_deref_var *deref)
+nir_deref_var *
+nir_deref_var_clone(const nir_deref_var *deref, void *mem_ctx)
 {
nir_deref_var *ret = nir_deref_var_create(mem_ctx, deref->var);
ret->deref.type = deref->deref.type;
if (deref->deref.child)
-  ret->deref.child = nir_copy_deref(ret, deref->deref.child);
+  ret->deref.child = nir_deref_clone(deref->deref.child, ret);
return ret;
 }
 
 static nir_deref_array *
-copy_deref_array(void *mem_ctx, nir_deref_array *deref)
+deref_array_clone(const nir_deref_array *deref, void *mem_ctx)
 {
nir_deref_array *ret = nir_deref_array_create(mem_ctx);
ret->base_offset = deref->base_offset;
@@ -645,33 +645,33 @@ copy_deref_array(void *mem_ctx, nir_deref_array *deref)
}
ret->deref.type = deref->deref.type;
if (deref->deref.child)
-  ret->deref.child = nir_copy_deref(ret, deref->deref.child);
+  ret->deref.child = nir_deref_clone(deref->deref.child, ret);
return ret;
 }
 
 static nir_deref_struct *
-copy_deref_struct(void *mem_ctx, nir_deref_struct *deref)
+deref_struct_clone(const nir_deref_struct *deref, void *mem_ctx)
 {
nir_deref_struct *ret = nir_deref_struct_create(mem_ctx, deref->index);
ret->deref.type = deref->deref.type;
if (deref->deref.child)
-  ret->deref.child = nir_copy_deref(ret, deref->deref.child);
+  ret->deref.child = nir_deref_clone(deref->deref.child, ret);
return ret;
 }
 
 nir_deref *
-nir_copy_deref(void *mem_ctx, nir_deref *deref)
+nir_deref_clone(const nir_deref *deref, void *mem_ctx)
 {
if (deref == NULL)
   return NULL;
 
switch (deref->deref_type) {
case nir_deref_type_var:
-  return _deref_var(mem_ctx, nir_deref_as_var(deref))->deref;
+  return _deref_var_clone(nir_deref_as_var(deref), mem_ctx)->deref;
case nir_deref_type_array:
-  return _deref_array(mem_ctx, nir_deref_as_array(deref))->deref;
+  return _array_clone(nir_deref_as_array(deref), mem_ctx)->deref;
case nir_deref_type_struct:
-  return _deref_struct(mem_ctx, nir_deref_as_struct(deref))->deref;
+  return _struct_clone(nir_deref_as_struct(deref), mem_ctx)->deref;
default:
   unreachable("Invalid dereference type");
}
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 6557631..d896679 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -1927,8 +1927,6 @@ nir_deref_var *nir_deref_var_create(void *mem_ctx, 
nir_variable *var);
 nir_deref_array *nir_deref_array_create(void *mem_ctx);
 nir_deref_struct *nir_deref_struct_create(void *mem_ctx, unsigned field_index);
 
-nir_deref *nir_copy_deref(void *mem_ctx, nir_deref *deref);
-
 typedef bool (*nir_deref_foreach_leaf_cb)(nir_deref_var *deref, void *state);
 bool nir_deref_foreach_leaf(nir_deref_var *deref,
  

[Mesa-dev] [PATCH 0/8] nir: A few allocation cleanups

2016-12-26 Thread Jason Ekstrand
The first patch in this series is a change I've been meaning to make for
some time.  I've been running into name collisions with nir_copy_deref and
the nir_builder nir_copy_deref_var helper.  Also, now that we have lots of
other "clone" stuff, it makes sense to make things make them all match.

The other 7 patches are fixes that update some passes a bit and make us
handle ralloc memory contexts better.

Jason Ekstrand (8):
  nir: Make nir_copy_deref follow the "clone" pattern
  nir/from_ssa: Use nir_builder for emit_copy
  nir/lower_io: Use the builder instead of carrying a mem_ctx
  nir/lower_var_copies: Use a shader rather than a void *mem_ctx
  nir/conditional_if: Properly use the builder
  nir/opt_peephole_select: Pass around the actual nir_shader
  nir/split_var_copies: Use a nir_shader rather than a void *mem_ctx
  i965/peephole_ffma: Use nir_builder

 src/compiler/glsl/glsl_to_nir.cpp  |  3 +-
 src/compiler/nir/nir.c | 22 +--
 src/compiler/nir/nir.h |  6 +--
 src/compiler/nir/nir_builder.h |  6 +--
 src/compiler/nir/nir_from_ssa.c| 26 ++---
 src/compiler/nir/nir_inline_functions.c|  2 +-
 src/compiler/nir/nir_lower_indirect_derefs.c   |  6 +--
 src/compiler/nir/nir_lower_io.c| 16 
 src/compiler/nir/nir_lower_tex.c   | 18 +++--
 src/compiler/nir/nir_lower_var_copies.c| 21 ++-
 src/compiler/nir/nir_opt_conditional_discard.c | 21 +--
 src/compiler/nir/nir_opt_peephole_select.c |  9 +++--
 src/compiler/nir/nir_split_var_copies.c| 23 +---
 src/compiler/spirv/spirv_to_nir.c  | 22 +--
 src/compiler/spirv/vtn_glsl450.c   |  3 +-
 src/compiler/spirv/vtn_variables.c |  3 +-
 src/intel/vulkan/anv_nir_lower_input_attachments.c |  3 +-
 .../drivers/dri/i965/brw_nir_opt_peephole_ffma.c   | 43 +++---
 18 files changed, 111 insertions(+), 142 deletions(-)

-- 
2.5.0.400.gff86faf

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


Re: [Mesa-dev] [PATCH 11/27] gbm: Get modifiers from DRI

2016-12-26 Thread Ben Widawsky

On 16-12-02 09:43:07, Daniel Stone wrote:

Hi Ben,

On 1 December 2016 at 22:09, Ben Widawsky  wrote:

@@ -678,6 +679,28 @@ gbm_dri_bo_get_offset(struct gbm_bo *_bo, int plane)
return (uint32_t)offset;
 }

+static uint64_t
+gbm_dri_bo_get_modifier(struct gbm_bo *_bo)
+{
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+
+   if (!dri->image || dri->image->base.version < 14) {
+  errno = ENOSYS;
+  return 0;
+   }


Sticking this here prevents my cursor crash:
+   /* Dumb buffers have no modifiers */
+   if (!bo->image)
+  return 0;

Cheers,
Daniel


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