Re: [Mesa-dev] [PATCH] glsl/linker: add check for compute shared memory size

2017-10-06 Thread Timothy Arceri

Reviewed-by: Timothy Arceri 

On 07/10/17 07:17, Nicolai Hähnle wrote:

From: Nicolai Hähnle 

Unlike uniforms, the limit on shared memory size is not called out
explicitly in the list of things that cause linker errors, but presumably
that's just an oversight in the spec.

Fixes 
dEQP-GLES31.functional.debug.negative_coverage.{callbacks,get_error,log}.compute.exceed_shared_memory_size_limit
---
  src/compiler/glsl/ir_optimization.h  |  5 +++--
  src/compiler/glsl/linker.cpp |  3 +--
  src/compiler/glsl/lower_shared_reference.cpp | 21 +++--
  3 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/compiler/glsl/ir_optimization.h 
b/src/compiler/glsl/ir_optimization.h
index 38fb54990ea..eb3ec3b0c7d 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -136,22 +136,23 @@ bool lower_instructions(exec_list *instructions, unsigned 
what_to_lower);
  bool lower_noise(exec_list *instructions);
  bool lower_variable_index_to_cond_assign(gl_shader_stage stage,
  exec_list *instructions, bool lower_input, bool lower_output,
  bool lower_temp, bool lower_uniform);
  bool lower_quadop_vector(exec_list *instructions, bool dont_lower_swz);
  bool lower_const_arrays_to_uniforms(exec_list *instructions, unsigned stage);
  bool lower_clip_cull_distance(struct gl_shader_program *prog,
gl_linked_shader *shader);
  void lower_output_reads(unsigned stage, exec_list *instructions);
  bool lower_packing_builtins(exec_list *instructions, int op_mask);
-void lower_shared_reference(struct gl_linked_shader *shader,
-unsigned *shared_size);
+void lower_shared_reference(struct gl_context *ctx,
+struct gl_shader_program *prog,
+struct gl_linked_shader *shader);
  void lower_ubo_reference(struct gl_linked_shader *shader,
   bool clamp_block_indices, bool 
use_std430_as_default);
  void lower_packed_varyings(void *mem_ctx,
 unsigned locations_used,
 const uint8_t *components,
 ir_variable_mode mode,
 unsigned gs_input_vertices,
 gl_linked_shader *shader,
 bool disable_varying_packing, bool xfb_enabled);
  bool lower_vector_insert(exec_list *instructions, bool 
lower_nonconstant_index);
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index f352c5385ca..03eb05bf637 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -4650,22 +4650,21 @@ link_varyings_and_uniforms(unsigned first, unsigned 
last,
  
const struct gl_shader_compiler_options *options =

   >Const.ShaderCompilerOptions[i];
  
if (options->LowerBufferInterfaceBlocks)

   lower_ubo_reference(prog->_LinkedShaders[i],
   options->ClampBlockIndicesToArrayBounds,
   ctx->Const.UseSTD430AsDefaultPacking);
  
if (i == MESA_SHADER_COMPUTE)

- lower_shared_reference(prog->_LinkedShaders[i],
->Comp.SharedSize);
+ lower_shared_reference(ctx, prog, prog->_LinkedShaders[i]);
  
lower_vector_derefs(prog->_LinkedShaders[i]);

do_vec_index_to_swizzle(prog->_LinkedShaders[i]->ir);
 }
  
 return true;

  }
  
  static void

  linker_optimisation_loop(struct gl_context *ctx, exec_list *ir,
diff --git a/src/compiler/glsl/lower_shared_reference.cpp 
b/src/compiler/glsl/lower_shared_reference.cpp
index b9098913af8..a1b3f7df47e 100644
--- a/src/compiler/glsl/lower_shared_reference.cpp
+++ b/src/compiler/glsl/lower_shared_reference.cpp
@@ -26,20 +26,21 @@
   *
   * IR lower pass to replace dereferences of compute shader shared variables
   * with intrinsic function calls.
   *
   * This relieves drivers of the responsibility of allocating space for the
   * shared variables in the shared memory region.
   */
  
  #include "lower_buffer_access.h"

  #include "ir_builder.h"
+#include "linker.h"
  #include "main/macros.h"
  #include "util/list.h"
  #include "glsl_parser_extras.h"
  
  using namespace ir_builder;
  
  namespace {
  
  struct var_offset {

 struct list_head node;
@@ -471,29 +472,45 @@ lower_shared_reference_visitor::visit_enter(ir_call *ir)
base_ir->replace_with(new_ir);
return visit_continue_with_parent;
 }
  
 return rvalue_visit(ir);

  }
  
  } /* unnamed namespace */
  
  void

-lower_shared_reference(struct gl_linked_shader *shader, unsigned *shared_size)
+lower_shared_reference(struct gl_context *ctx,
+   struct gl_shader_program *prog,
+   struct gl_linked_shader *shader)
  {
 if (shader->Stage != MESA_SHADER_COMPUTE)
return;
  
 

Re: [Mesa-dev] [PATCH v2] i965: Disable auxiliary buffers when there are self-dependencies.

2017-10-06 Thread Kenneth Graunke
On Friday, October 6, 2017 8:09:33 PM PDT Jason Ekstrand wrote:
> On October 6, 2017 8:00:04 PM Kenneth Graunke  wrote:
> > diff --git a/src/mesa/drivers/dri/i965/brw_draw.c 
> > b/src/mesa/drivers/dri/i965/brw_draw.c
> > index c7ed7284501..fcb194dbe86 100644
> > --- a/src/mesa/drivers/dri/i965/brw_draw.c
> > +++ b/src/mesa/drivers/dri/i965/brw_draw.c
> > @@ -336,21 +336,39 @@ brw_merge_inputs(struct brw_context *brw,
> > }
> >  }
> >
> > +/* Disable auxiliary buffers if a renderbuffer is also bound as a texture
> > + * or shader image.  This causes a self-dependency, where both rendering
> > + * and sampling may concurrently read or write the CCS buffer, causing
> > + * incorrect pixels.
> > + *
> > + * We don't support sampling from CCS_D, so this only matters for CCS_E.
> > + */
> >  static bool
> > -intel_disable_rb_aux_buffer(struct brw_context *brw, const struct brw_bo 
> > *bo)
> > +intel_disable_rb_aux_buffer(struct brw_context *brw,
> > +struct intel_mipmap_tree *tex_mt,
> > +const char *usage)
> >  {
> > const struct gl_framebuffer *fb = brw->ctx.DrawBuffer;
> > bool found = false;
> >
> > +   /* Nothing to disable, don't bother looking */
> > +   if (tex_mt->aux_usage != ISL_AUX_USAGE_CCS_E)
> > +  return false;
> 
> As I mentioned in the office today, I'm not convinced this is actually 
> needed.  When it isn't CCS_E, we'll resolve anyway so passing disable_aux = 
> true won't hurt anything.

Yeah, that's true - but I figured we could avoid the overhead of the
loop in other cases, since it doesn't really matter either way.

Make sense?  Should we leave it?  Or would you rather drop it?

> > +
> > for (unsigned i = 0; i < fb->_NumColorDrawBuffers; i++) {
> >const struct intel_renderbuffer *irb =
> >   intel_renderbuffer(fb->_ColorDrawBuffers[i]);
> >
> > -  if (irb && irb->mt->bo == bo) {
> > +  if (irb && irb->mt->bo == tex_mt->bo) {
> >   found = brw->draw_aux_buffer_disabled[i] = true;
> >}
> > }
> >
> > +   if (found) {
> > +  perf_debug("Disabling CCS because a renderbuffer is also bound 
> > %s.\n",
> > + usage);
> > +   }
> > +
> > return found;
> >  }
> > diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
> > b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> > index 670a92c1168..48392e7494a 100644
> > --- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> > +++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> > @@ -2678,7 +2676,7 @@ intel_miptree_prepare_fb_fetch(struct brw_context 
> > *brw,
> > uint32_t start_layer, uint32_t num_layers)
> >  {
> > intel_miptree_prepare_texture_slices(brw, mt, mt->surf.format, level, 1,
> > -start_layer, num_layers, NULL);
> > +start_layer, num_layers, false);
> 
> I think we probably want true here.  It is for fb_fetch after all.  :-)  
> Also, we probably want to do disable_rb_aux_buffer for framebuffer fetch as 
> well.

Sure, I can do that.  It won't actually do anything, however, as this is
the code for non-coherent framebuffer fetch...and on Gen9+, we always do
a coherent fetch using the Render Target Read messages (even if the app
says that a non-coherent fetch would be fine).  And, Gen9+ is the only
platform where CCS_E exists.  So, the only platforms where this matters
don't use this code :)

Still, I think your suggestion would make the code clearer, and would
future-proof it in case we ever decide that non-coherent fetches are
useful on modern hardware (say, if they're cheaper someday).


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


Re: [Mesa-dev] [PATCH v2] i965: Disable auxiliary buffers when there are self-dependencies.

2017-10-06 Thread Jason Ekstrand

On October 6, 2017 8:00:04 PM Kenneth Graunke  wrote:


Jason and I investigated several OpenGL CTS failures where the tests
bind the same texture for rendering and texturing, at the same time.
This has defined results as long as the reads happen before writes,
or the regions are non-overlapping.  Normally, this just works out.

However, CCS can cause problems.  If the shader is reading one set of
pixels, and writing to different pixels that are adjacent, they may end
up being covered by the same CCS block.  So rendering may be writing a
CCS block, while the sampler is trying to read it.  Corruption ensues.

Disabling CCS is unfortunate, but safe.

Fixes several KHR-GL45.texture_barrier.* subtests.

Cc: nanleych...@gmail.com
Cc: ja...@jlekstrand.net
---
 src/mesa/drivers/dri/i965/brw_draw.c  | 44 ---
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 12 +++-
 src/mesa/drivers/dri/i965/intel_mipmap_tree.h |  2 +-
 3 files changed, 33 insertions(+), 25 deletions(-)

Only one patch this time around.  This is a lot nicer.

diff --git a/src/mesa/drivers/dri/i965/brw_draw.c 
b/src/mesa/drivers/dri/i965/brw_draw.c

index c7ed7284501..fcb194dbe86 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -336,21 +336,39 @@ brw_merge_inputs(struct brw_context *brw,
}
 }

+/* Disable auxiliary buffers if a renderbuffer is also bound as a texture
+ * or shader image.  This causes a self-dependency, where both rendering
+ * and sampling may concurrently read or write the CCS buffer, causing
+ * incorrect pixels.
+ *
+ * We don't support sampling from CCS_D, so this only matters for CCS_E.
+ */
 static bool
-intel_disable_rb_aux_buffer(struct brw_context *brw, const struct brw_bo *bo)
+intel_disable_rb_aux_buffer(struct brw_context *brw,
+struct intel_mipmap_tree *tex_mt,
+const char *usage)
 {
const struct gl_framebuffer *fb = brw->ctx.DrawBuffer;
bool found = false;

+   /* Nothing to disable, don't bother looking */
+   if (tex_mt->aux_usage != ISL_AUX_USAGE_CCS_E)
+  return false;


As I mentioned in the office today, I'm not convinced this is actually 
needed.  When it isn't CCS_E, we'll resolve anyway so passing disable_aux = 
true won't hurt anything.



+
for (unsigned i = 0; i < fb->_NumColorDrawBuffers; i++) {
   const struct intel_renderbuffer *irb =
  intel_renderbuffer(fb->_ColorDrawBuffers[i]);

-  if (irb && irb->mt->bo == bo) {
+  if (irb && irb->mt->bo == tex_mt->bo) {
  found = brw->draw_aux_buffer_disabled[i] = true;
   }
}

+   if (found) {
+  perf_debug("Disabling CCS because a renderbuffer is also bound %s.\n",
+ usage);
+   }
+
return found;
 }

@@ -363,7 +381,6 @@ intel_disable_rb_aux_buffer(struct brw_context *brw, 
const struct brw_bo *bo)

 void
 brw_predraw_resolve_inputs(struct brw_context *brw)
 {
-   const struct gen_device_info *devinfo = >screen->devinfo;
struct gl_context *ctx = >ctx;
struct intel_texture_object *tex_obj;

@@ -383,15 +400,11 @@ brw_predraw_resolve_inputs(struct brw_context *brw)
   enum isl_format view_format =
  translate_tex_format(brw, tex_obj->_Format, sampler->sRGBDecode);

-  bool aux_supported;
-  intel_miptree_prepare_texture(brw, tex_obj->mt, view_format,
-_supported);
+  const bool disable_aux =
+ intel_disable_rb_aux_buffer(brw, tex_obj->mt, "for sampling");

-  if (!aux_supported && devinfo->gen >= 9 &&
-  intel_disable_rb_aux_buffer(brw, tex_obj->mt->bo)) {
- perf_debug("Sampling renderbuffer with non-compressible format - "
-"turning off compression\n");
-  }
+  intel_miptree_prepare_texture(brw, tex_obj->mt, view_format,
+disable_aux);

   brw_render_cache_set_check_flush(brw, tex_obj->mt->bo);

@@ -412,13 +425,10 @@ brw_predraw_resolve_inputs(struct brw_context *brw)
 tex_obj = intel_texture_object(u->TexObj);

 if (tex_obj && tex_obj->mt) {
-   intel_miptree_prepare_image(brw, tex_obj->mt);
+   intel_disable_rb_aux_buffer(brw, tex_obj->mt,
+   "as a shader image");

-   if (tex_obj->mt->aux_usage == ISL_AUX_USAGE_CCS_E &&
-   intel_disable_rb_aux_buffer(brw, tex_obj->mt->bo)) {
-  perf_debug("Using renderbuffer as shader image - turning "
- "off lossless compression\n");
-   }
+   intel_miptree_prepare_image(brw, tex_obj->mt);

brw_render_cache_set_check_flush(brw, tex_obj->mt->bo);
 }
diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c

index 670a92c1168..48392e7494a 100644
--- 

[Mesa-dev] [PATCH v2] i965: Disable auxiliary buffers when there are self-dependencies.

2017-10-06 Thread Kenneth Graunke
Jason and I investigated several OpenGL CTS failures where the tests
bind the same texture for rendering and texturing, at the same time.
This has defined results as long as the reads happen before writes,
or the regions are non-overlapping.  Normally, this just works out.

However, CCS can cause problems.  If the shader is reading one set of
pixels, and writing to different pixels that are adjacent, they may end
up being covered by the same CCS block.  So rendering may be writing a
CCS block, while the sampler is trying to read it.  Corruption ensues.

Disabling CCS is unfortunate, but safe.

Fixes several KHR-GL45.texture_barrier.* subtests.

Cc: nanleych...@gmail.com
Cc: ja...@jlekstrand.net
---
 src/mesa/drivers/dri/i965/brw_draw.c  | 44 ---
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 12 +++-
 src/mesa/drivers/dri/i965/intel_mipmap_tree.h |  2 +-
 3 files changed, 33 insertions(+), 25 deletions(-)

Only one patch this time around.  This is a lot nicer.

diff --git a/src/mesa/drivers/dri/i965/brw_draw.c 
b/src/mesa/drivers/dri/i965/brw_draw.c
index c7ed7284501..fcb194dbe86 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -336,21 +336,39 @@ brw_merge_inputs(struct brw_context *brw,
}
 }
 
+/* Disable auxiliary buffers if a renderbuffer is also bound as a texture
+ * or shader image.  This causes a self-dependency, where both rendering
+ * and sampling may concurrently read or write the CCS buffer, causing
+ * incorrect pixels.
+ *
+ * We don't support sampling from CCS_D, so this only matters for CCS_E.
+ */
 static bool
-intel_disable_rb_aux_buffer(struct brw_context *brw, const struct brw_bo *bo)
+intel_disable_rb_aux_buffer(struct brw_context *brw,
+struct intel_mipmap_tree *tex_mt,
+const char *usage)
 {
const struct gl_framebuffer *fb = brw->ctx.DrawBuffer;
bool found = false;
 
+   /* Nothing to disable, don't bother looking */
+   if (tex_mt->aux_usage != ISL_AUX_USAGE_CCS_E)
+  return false;
+
for (unsigned i = 0; i < fb->_NumColorDrawBuffers; i++) {
   const struct intel_renderbuffer *irb =
  intel_renderbuffer(fb->_ColorDrawBuffers[i]);
 
-  if (irb && irb->mt->bo == bo) {
+  if (irb && irb->mt->bo == tex_mt->bo) {
  found = brw->draw_aux_buffer_disabled[i] = true;
   }
}
 
+   if (found) {
+  perf_debug("Disabling CCS because a renderbuffer is also bound %s.\n",
+ usage);
+   }
+
return found;
 }
 
@@ -363,7 +381,6 @@ intel_disable_rb_aux_buffer(struct brw_context *brw, const 
struct brw_bo *bo)
 void
 brw_predraw_resolve_inputs(struct brw_context *brw)
 {
-   const struct gen_device_info *devinfo = >screen->devinfo;
struct gl_context *ctx = >ctx;
struct intel_texture_object *tex_obj;
 
@@ -383,15 +400,11 @@ brw_predraw_resolve_inputs(struct brw_context *brw)
   enum isl_format view_format =
  translate_tex_format(brw, tex_obj->_Format, sampler->sRGBDecode);
 
-  bool aux_supported;
-  intel_miptree_prepare_texture(brw, tex_obj->mt, view_format,
-_supported);
+  const bool disable_aux =
+ intel_disable_rb_aux_buffer(brw, tex_obj->mt, "for sampling");
 
-  if (!aux_supported && devinfo->gen >= 9 &&
-  intel_disable_rb_aux_buffer(brw, tex_obj->mt->bo)) {
- perf_debug("Sampling renderbuffer with non-compressible format - "
-"turning off compression\n");
-  }
+  intel_miptree_prepare_texture(brw, tex_obj->mt, view_format,
+disable_aux);
 
   brw_render_cache_set_check_flush(brw, tex_obj->mt->bo);
 
@@ -412,13 +425,10 @@ brw_predraw_resolve_inputs(struct brw_context *brw)
 tex_obj = intel_texture_object(u->TexObj);
 
 if (tex_obj && tex_obj->mt) {
-   intel_miptree_prepare_image(brw, tex_obj->mt);
+   intel_disable_rb_aux_buffer(brw, tex_obj->mt,
+   "as a shader image");
 
-   if (tex_obj->mt->aux_usage == ISL_AUX_USAGE_CCS_E &&
-   intel_disable_rb_aux_buffer(brw, tex_obj->mt->bo)) {
-  perf_debug("Using renderbuffer as shader image - turning "
- "off lossless compression\n");
-   }
+   intel_miptree_prepare_image(brw, tex_obj->mt);
 
brw_render_cache_set_check_flush(brw, tex_obj->mt->bo);
 }
diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 670a92c1168..48392e7494a 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -2630,9 +2630,9 @@ intel_miptree_prepare_texture_slices(struct brw_context 
*brw,
  enum isl_format view_format,
 

Re: [Mesa-dev] [PATCH 1/2] st/glsl_to_tgsi: ignore GL_TEXTURE_SRGB_DECODE_EXT for samplers used with texelFetch*()

2017-10-06 Thread Kenneth Graunke
On Friday, October 6, 2017 1:39:50 PM PDT Nicolai Hähnle wrote:
> From: Nicolai Hähnle 
> 
> See the comment for the relevant spec quote.
> 
> Fixes 
> dEQP-GLES31.functional.srgb_texture_decode.skip_decode.srgba8.texel_fetch
> --
> Note that this is on top of the texture locking series which I have
> sent out a minute ago.
> ---
>  src/mesa/main/mtypes.h |  1 +
>  src/mesa/state_tracker/st_atom_texture.c   | 39 
> +++---
>  src/mesa/state_tracker/st_cb_texture.c |  8 +-
>  src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  4 +++
>  src/mesa/state_tracker/st_sampler_view.c   | 19 +--
>  src/mesa/state_tracker/st_sampler_view.h   |  3 ++-
>  src/mesa/state_tracker/st_texture.c|  7 +-
>  src/mesa/state_tracker/st_texture.h|  7 +++---
>  8 files changed, 71 insertions(+), 17 deletions(-)

Heh.  I was going to send out patches for i965 shortly.  I did this
by adding a new shader_info field instead, and populating it from
nir_shader_gather_info().  I obviously won't be able to reuse your
code in st_glsl_to_tgsi, but maybe I can reuse the field at least.

This looks good at any rate, no need to wait for me...

Reviewed-by: Kenneth Graunke 


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


Re: [Mesa-dev] [PATCH 2/2] st/mesa: don't assign prog->ShadowSamplers

2017-10-06 Thread Kenneth Graunke
On Friday, October 6, 2017 1:39:51 PM PDT Nicolai Hähnle wrote:
> From: Nicolai Hähnle 
> 
> It's not used, and the assignment for the TGSI case was incorrect
> for sampler arrays.
> ---
>  src/mesa/state_tracker/st_glsl_to_nir.cpp  | 1 -
>  src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 4 
>  2 files changed, 5 deletions(-)

Hmm, you're right...it looked like r300g used it, but it actually
just creates a similar bitfield in its compiler backend.

Reviewed-by: Kenneth Graunke 


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


Re: [Mesa-dev] [PATCH 3/3] st/mesa: whitespace fix

2017-10-06 Thread Marek Olšák
For the series:

Reviewed-by: Marek Olšák 

Marek

On Fri, Oct 6, 2017 at 10:19 PM, Nicolai Hähnle  wrote:
> From: Nicolai Hähnle 
>
> ---
>  src/mesa/state_tracker/st_texture.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/mesa/state_tracker/st_texture.h 
> b/src/mesa/state_tracker/st_texture.h
> index 0cde0c1f409..ea459bf6e24 100644
> --- a/src/mesa/state_tracker/st_texture.h
> +++ b/src/mesa/state_tracker/st_texture.h
> @@ -63,21 +63,21 @@ struct st_texture_image
> /* List of transfers, allocated on demand.
>  * transfer[layer] is a mapping for that layer.
>  */
> struct st_texture_image_transfer *transfer;
> unsigned num_transfers;
>
> /* For ETC images, keep track of the original data. This is necessary for
>  * mapping/unmapping, as well as image copies.
>  */
> GLubyte *etc_data;
> - };
> +};
>
>
>  /**
>   * Subclass of gl_texure_object.
>   */
>  struct st_texture_object
>  {
> struct gl_texture_object base;   /* The "parent" object */
>
> /* The texture must include at levels [0..lastLevel] once validated:
> --
> 2.11.0
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 3/3] radeonsi: add support for PIPE_FORMAT_A1R5G5B5_UNORM

2017-10-06 Thread Marek Olšák
Reviewed-by: Marek Olšák 

Instead of patches 1-2, I prefer Eric's version which also adds
X1B5G5R5. You have my Rb for any leftover bits not present in Eric's
patch.

Marek



On Fri, Oct 6, 2017 at 10:41 PM, Nicolai Hähnle  wrote:
> From: Nicolai Hähnle 
>
> Fixes dEQP-EGL.functional.image.modify.tex_rgb5_a1_tex_subimage_rgba8
> ---
>  src/gallium/drivers/radeonsi/si_state.c | 8 
>  1 file changed, 8 insertions(+)
>
> diff --git a/src/gallium/drivers/radeonsi/si_state.c 
> b/src/gallium/drivers/radeonsi/si_state.c
> index 99c3ca36886..a86a3a83217 100644
> --- a/src/gallium/drivers/radeonsi/si_state.c
> +++ b/src/gallium/drivers/radeonsi/si_state.c
> @@ -1499,20 +1499,22 @@ static uint32_t si_translate_colorformat(enum 
> pipe_format format)
> return V_028C70_COLOR_4_4_4_4;
> case 8:
> return V_028C70_COLOR_8_8_8_8;
> case 16:
> return V_028C70_COLOR_16_16_16_16;
> case 32:
> return V_028C70_COLOR_32_32_32_32;
> }
> } else if (HAS_SIZE(5,5,5,1)) {
> return V_028C70_COLOR_1_5_5_5;
> +   } else if (HAS_SIZE(1,5,5,5)) {
> +   return V_028C70_COLOR_5_5_5_1;
> } else if (HAS_SIZE(10,10,10,2)) {
> return V_028C70_COLOR_2_10_10_10;
> }
> break;
> }
> return V_028C70_COLOR_INVALID;
>  }
>
>  static uint32_t si_colorformat_endian_swap(uint32_t colorformat)
>  {
> @@ -1757,20 +1759,26 @@ static uint32_t si_translate_texformat(struct 
> pipe_screen *screen,
> return V_008F14_IMG_DATA_FORMAT_5_6_5;
> }
> goto out_unknown;
> case 4:
> if (desc->channel[0].size == 5 &&
> desc->channel[1].size == 5 &&
> desc->channel[2].size == 5 &&
> desc->channel[3].size == 1) {
> return V_008F14_IMG_DATA_FORMAT_1_5_5_5;
> }
> +   if (desc->channel[0].size == 1 &&
> +   desc->channel[1].size == 5 &&
> +   desc->channel[2].size == 5 &&
> +   desc->channel[3].size == 5) {
> +   return V_008F14_IMG_DATA_FORMAT_5_5_5_1;
> +   }
> if (desc->channel[0].size == 10 &&
> desc->channel[1].size == 10 &&
> desc->channel[2].size == 10 &&
> desc->channel[3].size == 2) {
> return V_008F14_IMG_DATA_FORMAT_2_10_10_10;
> }
> goto out_unknown;
> }
> goto out_unknown;
> }
> --
> 2.11.0
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 2/6] gallium: Add support for 5551 with the 1-bit field in the low bit.

2017-10-06 Thread Marek Olšák
Reviewed-by: Marek Olšák 

Marek

On Thu, Aug 17, 2017 at 6:10 PM, Eric Anholt  wrote:
> This is how VC4 stores 5551 textures, which we need to support for
> GL_OES_required_internalformat.
>
> v2: Extend commit message, fix svga driver build, add BE ordering from
> Roland.
> ---
>  src/gallium/auxiliary/util/u_format.csv |  2 ++
>  src/gallium/drivers/svga/svga_format.c  |  2 ++
>  src/gallium/include/pipe/p_format.h |  3 +++
>  src/mesa/state_tracker/st_format.c  | 16 +---
>  4 files changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/src/gallium/auxiliary/util/u_format.csv 
> b/src/gallium/auxiliary/util/u_format.csv
> index cef530aae7c3..966b34bd722e 100644
> --- a/src/gallium/auxiliary/util/u_format.csv
> +++ b/src/gallium/auxiliary/util/u_format.csv
> @@ -74,6 +74,8 @@ PIPE_FORMAT_X8B8G8R8_UNORM, plain, 1, 1, x8  , un8 
> , un8 , un8 , wzy1, r
>  PIPE_FORMAT_R8G8B8X8_UNORM, plain, 1, 1, un8 , un8 , un8 , x8  , 
> xyz1, rgb
>  PIPE_FORMAT_B5G5R5X1_UNORM, plain, 1, 1, un5 , un5 , un5 , x1  , 
> zyx1, rgb, x1  , un5 , un5 , un5 , yzw1
>  PIPE_FORMAT_B5G5R5A1_UNORM, plain, 1, 1, un5 , un5 , un5 , un1 , 
> zyxw, rgb, un1 , un5 , un5 , un5 , yzwx
> +PIPE_FORMAT_X1B5G5R5_UNORM, plain, 1, 1, x1  , un5 , un5 , un5 , 
> wzy1, rgb, un5 , un5 , un5 ,  x1 , xyz1
> +PIPE_FORMAT_A1B5G5R5_UNORM, plain, 1, 1, un1 , un5 , un5 , un5 , 
> wzyx, rgb, un5 , un5 , un5 , un1 , xyzw
>  PIPE_FORMAT_B4G4R4A4_UNORM, plain, 1, 1, un4 , un4 , un4 , un4 , 
> zyxw, rgb, un4 , un4 , un4 , un4 , yzwx
>  PIPE_FORMAT_B4G4R4X4_UNORM, plain, 1, 1, un4 , un4 , un4 , x4  , 
> zyx1, rgb, x4  , un4 , un4 , un4 , yzw1
>  PIPE_FORMAT_B5G6R5_UNORM  , plain, 1, 1, un5 , un6 , un5 , , 
> zyx1, rgb, un5 , un6 , un5 , , xyz1
> diff --git a/src/gallium/drivers/svga/svga_format.c 
> b/src/gallium/drivers/svga/svga_format.c
> index 95dd04d8abd8..5b844b570e24 100644
> --- a/src/gallium/drivers/svga/svga_format.c
> +++ b/src/gallium/drivers/svga/svga_format.c
> @@ -58,6 +58,7 @@ static const struct vgpu10_format_entry 
> format_conversion_table[] =
> { PIPE_FORMAT_A8R8G8B8_UNORM,SVGA3D_FORMAT_INVALID,  
> SVGA3D_FORMAT_INVALID,   0 },
> { PIPE_FORMAT_X8R8G8B8_UNORM,SVGA3D_FORMAT_INVALID,  
> SVGA3D_FORMAT_INVALID,   0 },
> { PIPE_FORMAT_B5G5R5A1_UNORM,SVGA3D_FORMAT_INVALID,  
> SVGA3D_B5G5R5A1_UNORM,   TF_GEN_MIPS },
> +   { PIPE_FORMAT_A1B5G5R5_UNORM,SVGA3D_FORMAT_INVALID,  
> SVGA3D_FORMAT_INVALID,   0 },
> { PIPE_FORMAT_B4G4R4A4_UNORM,SVGA3D_FORMAT_INVALID,  
> SVGA3D_FORMAT_INVALID,   0 },
> { PIPE_FORMAT_B5G6R5_UNORM,  SVGA3D_FORMAT_INVALID,  
> SVGA3D_B5G6R5_UNORM, TF_GEN_MIPS },
> { PIPE_FORMAT_R10G10B10A2_UNORM, SVGA3D_R10G10B10A2_UNORM,   
> SVGA3D_R10G10B10A2_UNORM,TF_GEN_MIPS },
> @@ -175,6 +176,7 @@ static const struct vgpu10_format_entry 
> format_conversion_table[] =
> { PIPE_FORMAT_R5SG5SB6U_NORM,SVGA3D_FORMAT_INVALID,  
> SVGA3D_FORMAT_INVALID,   0 },
> { PIPE_FORMAT_A8B8G8R8_UNORM,SVGA3D_FORMAT_INVALID,  
> SVGA3D_FORMAT_INVALID,   0 },
> { PIPE_FORMAT_B5G5R5X1_UNORM,SVGA3D_FORMAT_INVALID,  
> SVGA3D_FORMAT_INVALID,   0 },
> +   { PIPE_FORMAT_X1B5G5R5_UNORM,SVGA3D_FORMAT_INVALID,  
> SVGA3D_FORMAT_INVALID,   0 },
> { PIPE_FORMAT_R10G10B10A2_USCALED,   SVGA3D_R10G10B10A2_UNORM,   
> SVGA3D_FORMAT_INVALID,   VF_PUINT_TO_USCALED },
> { PIPE_FORMAT_R11G11B10_FLOAT,   SVGA3D_FORMAT_INVALID,  
> SVGA3D_R11G11B10_FLOAT,  TF_GEN_MIPS },
> { PIPE_FORMAT_R9G9B9E5_FLOAT,SVGA3D_FORMAT_INVALID,  
> SVGA3D_R9G9B9E5_SHAREDEXP,   0 },
> diff --git a/src/gallium/include/pipe/p_format.h 
> b/src/gallium/include/pipe/p_format.h
> index e4e09d8b4353..515ce62e2973 100644
> --- a/src/gallium/include/pipe/p_format.h
> +++ b/src/gallium/include/pipe/p_format.h
> @@ -391,6 +391,9 @@ enum pipe_format {
>
> PIPE_FORMAT_P016= 307,
>
> +   PIPE_FORMAT_A1B5G5R5_UNORM  = 308,
> +   PIPE_FORMAT_X1B5G5R5_UNORM  = 309,
> +
> PIPE_FORMAT_COUNT
>  };
>
> diff --git a/src/mesa/state_tracker/st_format.c 
> b/src/mesa/state_tracker/st_format.c
> index 348853affd82..0ce785575ba8 100644
> --- a/src/mesa/state_tracker/st_format.c
> +++ b/src/mesa/state_tracker/st_format.c
> @@ -79,6 +79,8 @@ st_mesa_format_to_pipe_format(const struct st_context *st, 
> mesa_format mesaForma
>return PIPE_FORMAT_XRGB_UNORM;
> case MESA_FORMAT_B5G5R5A1_UNORM:
>return PIPE_FORMAT_B5G5R5A1_UNORM;
> +   case MESA_FORMAT_A1B5G5R5_UNORM:
> +  return PIPE_FORMAT_A1B5G5R5_UNORM;
> case MESA_FORMAT_B4G4R4A4_UNORM:
>return PIPE_FORMAT_B4G4R4A4_UNORM;
> case MESA_FORMAT_B5G6R5_UNORM:
> @@ -407,6 +409,8 @@ 

Re: [Mesa-dev] [PATCH 1/3] gallium: add PIPE_FORMAT_A1B5G5R5_UNORM format

2017-10-06 Thread Eric Anholt
Nicolai Hähnle  writes:

> From: Nicolai Hähnle 
>
> This matches the GL_UNSIGNED_SHORT_5_5_5_1 type.

Sigh, I've sent a patch for this 3 times already and not been able to
get review.

https://lists.freedesktop.org/archives/mesa-dev/2017-August/166569.html

I found that I also needed X1B5G5R5, or GL_RGB5 would give me failures.


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


[Mesa-dev] [Bug 87925] SIGSEGV libX11 src/ImUtil.c:733

2017-10-06 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=87925

Vinson Lee  changed:

   What|Removed |Added

Version|unspecified |10.2

--- Comment #3 from Vinson Lee  ---
mesa: 52b73caaf40e79c90a105ec6d349abb3398e3c6b (master 17.3.0-devel)

glx-tfp still crashes on swrast.

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


[Mesa-dev] [PATCH V2 1/4] i965/gen10: Implement WaSampleOffsetIZ workaround

2017-10-06 Thread Anuj Phogat
There are few other (duplicate) workarounds which have similar recommendations:
WaFlushHangWhenNonPipelineStateAndMarkerStalled
WaCSStallBefore3DSamplePattern
WaPipeControlBefore3DStateSamplePattern

WaPipeControlBefore3DStateSamplePattern has some extra recommendations if
driver is using mid batch context restore. Ignoring it for now because We're
not doing mid-batch context restore in Mesa.

Cc: mesa-sta...@lists.freedesktop.org
Cc: Jason Ekstrand 
Cc: Rafael Antognolli 
Signed-off-by: Anuj Phogat 
---
 src/mesa/drivers/dri/i965/brw_context.h|  2 +
 src/mesa/drivers/dri/i965/brw_defines.h|  1 +
 src/mesa/drivers/dri/i965/brw_pipe_control.c   | 50 ++
 src/mesa/drivers/dri/i965/gen8_multisample_state.c |  8 
 4 files changed, 61 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h 
b/src/mesa/drivers/dri/i965/brw_context.h
index 92fc16de13..f0e8d562e9 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1647,6 +1647,8 @@ void brw_emit_post_sync_nonzero_flush(struct brw_context 
*brw);
 void brw_emit_depth_stall_flushes(struct brw_context *brw);
 void gen7_emit_vs_workaround_flush(struct brw_context *brw);
 void gen7_emit_cs_stall_flush(struct brw_context *brw);
+void gen10_emit_wa_cs_stall_flush(struct brw_context *brw);
+void gen10_emit_wa_lri_to_cache_mode_zero(struct brw_context *brw);
 
 /* brw_queryformat.c */
 void brw_query_internal_format(struct gl_context *ctx, GLenum target,
diff --git a/src/mesa/drivers/dri/i965/brw_defines.h 
b/src/mesa/drivers/dri/i965/brw_defines.h
index 4abb790612..270cdf29db 100644
--- a/src/mesa/drivers/dri/i965/brw_defines.h
+++ b/src/mesa/drivers/dri/i965/brw_defines.h
@@ -1609,6 +1609,7 @@ enum brw_pixel_shader_coverage_mask_mode {
 #define GEN7_GPGPU_DISPATCHDIMY 0x2504
 #define GEN7_GPGPU_DISPATCHDIMZ 0x2508
 
+#define GEN7_CACHE_MODE_0   0x7000
 #define GEN7_CACHE_MODE_1   0x7004
 # define GEN9_FLOAT_BLEND_OPTIMIZATION_ENABLE (1 << 4)
 # define GEN8_HIZ_NP_PMA_FIX_ENABLE(1 << 11)
diff --git a/src/mesa/drivers/dri/i965/brw_pipe_control.c 
b/src/mesa/drivers/dri/i965/brw_pipe_control.c
index 460b8f73b6..156f5c25ec 100644
--- a/src/mesa/drivers/dri/i965/brw_pipe_control.c
+++ b/src/mesa/drivers/dri/i965/brw_pipe_control.c
@@ -278,6 +278,56 @@ gen7_emit_cs_stall_flush(struct brw_context *brw)
brw->workaround_bo, 0, 0);
 }
 
+static void
+brw_flush_gpu_caches(struct brw_context *brw) {
+   brw_emit_pipe_control_flush(brw,
+   PIPE_CONTROL_CACHE_FLUSH_BITS |
+   PIPE_CONTROL_CACHE_INVALIDATE_BITS);
+}
+
+/**
+ * From Gen10 Workarounds page in h/w specs:
+ * WaSampleOffsetIZ:
+ * Prior to the 3DSTATE_SAMPLE_PATTERN driver must ensure there are no
+ * markers in the pipeline by programming a PIPE_CONTROL with stall.
+ */
+void
+gen10_emit_wa_cs_stall_flush(struct brw_context *brw)
+{
+   const struct gen_device_info *devinfo = >screen->devinfo;
+   assert(devinfo->gen == 10);
+   brw_emit_pipe_control_flush(brw,
+   PIPE_CONTROL_CS_STALL |
+   PIPE_CONTROL_STALL_AT_SCOREBOARD);
+}
+
+/**
+ * From Gen10 Workarounds page in h/w specs:
+ * WaSampleOffsetIZ:
+ * When 3DSTATE_SAMPLE_PATTERN is programmed, driver must then issue an
+ * MI_LOAD_REGISTER_IMM command to an offset between 0x7000 and 0x7FFF(SVL)
+ * after the command to ensure the state has been delivered prior to any
+ * command causing a marker in the pipeline.
+ */
+void
+gen10_emit_wa_lri_to_cache_mode_zero(struct brw_context *brw)
+{
+   const struct gen_device_info *devinfo = >screen->devinfo;
+   assert(devinfo->gen == 10);
+
+   /* Before changing the value of CACHE_MODE_0 register, GFX pipeline must
+* be idle; i.e., full flush is required.
+*/
+   brw_flush_gpu_caches(brw);
+
+   /* Write to CACHE_MODE_0 (0x7000) */
+   BEGIN_BATCH(3);
+   OUT_BATCH(MI_LOAD_REGISTER_IMM | (3 - 2));
+   OUT_BATCH(GEN7_CACHE_MODE_0);
+   OUT_BATCH(0);
+   ADVANCE_BATCH();
+}
+
 /**
  * Emits a PIPE_CONTROL with a non-zero post-sync operation, for
  * implementing two workarounds on gen6.  From section 1.4.7.1
diff --git a/src/mesa/drivers/dri/i965/gen8_multisample_state.c 
b/src/mesa/drivers/dri/i965/gen8_multisample_state.c
index 7a31a5df4a..14043025b6 100644
--- a/src/mesa/drivers/dri/i965/gen8_multisample_state.c
+++ b/src/mesa/drivers/dri/i965/gen8_multisample_state.c
@@ -49,6 +49,11 @@ gen8_emit_3dstate_multisample(struct brw_context *brw, 
unsigned num_samples)
 void
 gen8_emit_3dstate_sample_pattern(struct brw_context *brw)
 {
+   const struct gen_device_info *devinfo = >screen->devinfo;
+
+   if (devinfo->gen == 10)
+  gen10_emit_wa_cs_stall_flush(brw);
+
BEGIN_BATCH(9);
OUT_BATCH(_3DSTATE_SAMPLE_PATTERN << 16 | (9 - 2));
 

Re: [Mesa-dev] [PATCH 0/6] st/mesa: add locking around lazy texture/sampler updates

2017-10-06 Thread Roland Scheidegger
Am 07.10.2017 um 01:01 schrieb Nicolai Hähnle:
> On 07.10.2017 00:36, Roland Scheidegger wrote:
>> I can't help but think that there'd be none of those problems if those
>> views were actually used as specced by gallium initially: all sampler
>> views (and surfaces) are per context, and they simply cannot be used in
>> another context.
> 
> That is actually the case today, with the exception that when a texture
> object is destroyed, all of sampler views are destroyed as well, from
> within whatever happens to be the current context. (This can be solved
> with some kind of "orphaned" list, but I'd rather not do that in st/mesa.)
> 
> The problem is that when we need a sampler view for a texture, we have
> (a) the context pointer and (b) the texture object pointer, and we need
> to map those to a sampler view. This happens via a mutable per-texture
> object structure, access to which must be protected somehow.

Ah I see I didn't look close enough.
This is all just about protecting st_texture_object, which is global (as
per gl rules of texture objects). So yes locking I guess locking is
indeed unavoidable.

Roland


> Cheers,
> Nicolai
> 
> 
>>
>> Roland
>>
>> Am 06.10.2017 um 22:38 schrieb Nicolai Hähnle:
>>> Hi all,
>>>
>>> This series is a first result of debugging some random crashes in dEQP's
>>> multi-threaded EGL tests.
>>>
>>> The OpenGL spec is pretty clear that application must not modify a
>>> texture
>>> in one context while simultaneously using it for texturing (or even
>>> modifying) it in another context. Texturing simultaneously in multiple
>>> contexts is fine, though.
>>>
>>> This can lead to races when st_finalize_texture is called simultaneously
>>> for two contexts, or if two contexts simultaneously attempt to access
>>> the
>>> sampler view array of a texture.
>>>
>>> This series should fix most (all?) issues where our internal data
>>> structures could become corrupted. I am aware of one remaining corner
>>> case that could lead to rendering corruption. It appears rather
>>> non-trivial
>>> to fix, and it is documented in a comment of patch #5.
>>>
>>> Please review!
>>> Thanks,
>>> Nicolai
>>> -- 
>>>   src/gallium/auxiliary/util/u_inlines.h   |  16 ++-
>>>   src/gallium/include/pipe/p_context.h |  10 ++
>>>   src/mesa/state_tracker/st_atom_sampler.c |  12 +-
>>>   src/mesa/state_tracker/st_atom_texture.c |  12 --
>>>   src/mesa/state_tracker/st_cb_texture.c   |  59 +++--
>>>   src/mesa/state_tracker/st_manager.c  |   3 +
>>>   src/mesa/state_tracker/st_sampler_view.c | 137 +
>>>   src/mesa/state_tracker/st_sampler_view.h |   7 ++
>>>   src/mesa/state_tracker/st_texture.h  |  23 +++-
>>>   9 files changed, 205 insertions(+), 74 deletions(-)
>>>
>>> ___
>>> mesa-dev mailing list
>>> mesa-dev@lists.freedesktop.org
>>> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.freedesktop.org_mailman_listinfo_mesa-2Ddev=DwIGaQ=uilaK90D4TOVoH58JNXRgQ=_QIjpv-UJ77xEQY8fIYoQtr5qv8wKrPJc7v7_-CYAb0=aJQCyBglFPt5-boeH0TmdwZPCq7mlewl6Obk3Gs6ckY=uJEnKpDKTfDfspSkPSUNxyVCXwiiizKYJ4xWFybULew=
>>>
>>>
>>
> 
> 

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


[Mesa-dev] [Bug 87926] [softpipe] SIGSEGV draw/draw_pt_fetch_shade_pipeline.c:161

2017-10-06 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=87926

Vinson Lee  changed:

   What|Removed |Added

Version|git |10.5

--- Comment #2 from Vinson Lee  ---
mesa: 52b73caaf40e79c90a105ec6d349abb3398e3c6b (master 17.3.0-devel)

gl-3.1-vao-broken-attrib still crashes on softpipe.

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


Re: [Mesa-dev] [PATCH 0/6] st/mesa: add locking around lazy texture/sampler updates

2017-10-06 Thread Nicolai Hähnle

On 07.10.2017 00:36, Roland Scheidegger wrote:

I can't help but think that there'd be none of those problems if those
views were actually used as specced by gallium initially: all sampler
views (and surfaces) are per context, and they simply cannot be used in
another context.


That is actually the case today, with the exception that when a texture 
object is destroyed, all of sampler views are destroyed as well, from 
within whatever happens to be the current context. (This can be solved 
with some kind of "orphaned" list, but I'd rather not do that in st/mesa.)


The problem is that when we need a sampler view for a texture, we have 
(a) the context pointer and (b) the texture object pointer, and we need 
to map those to a sampler view. This happens via a mutable per-texture 
object structure, access to which must be protected somehow.


Cheers,
Nicolai




Roland

Am 06.10.2017 um 22:38 schrieb Nicolai Hähnle:

Hi all,

This series is a first result of debugging some random crashes in dEQP's
multi-threaded EGL tests.

The OpenGL spec is pretty clear that application must not modify a texture
in one context while simultaneously using it for texturing (or even
modifying) it in another context. Texturing simultaneously in multiple
contexts is fine, though.

This can lead to races when st_finalize_texture is called simultaneously
for two contexts, or if two contexts simultaneously attempt to access the
sampler view array of a texture.

This series should fix most (all?) issues where our internal data
structures could become corrupted. I am aware of one remaining corner
case that could lead to rendering corruption. It appears rather non-trivial
to fix, and it is documented in a comment of patch #5.

Please review!
Thanks,
Nicolai
--
  src/gallium/auxiliary/util/u_inlines.h   |  16 ++-
  src/gallium/include/pipe/p_context.h |  10 ++
  src/mesa/state_tracker/st_atom_sampler.c |  12 +-
  src/mesa/state_tracker/st_atom_texture.c |  12 --
  src/mesa/state_tracker/st_cb_texture.c   |  59 +++--
  src/mesa/state_tracker/st_manager.c  |   3 +
  src/mesa/state_tracker/st_sampler_view.c | 137 +
  src/mesa/state_tracker/st_sampler_view.h |   7 ++
  src/mesa/state_tracker/st_texture.h  |  23 +++-
  9 files changed, 205 insertions(+), 74 deletions(-)

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.freedesktop.org_mailman_listinfo_mesa-2Ddev=DwIGaQ=uilaK90D4TOVoH58JNXRgQ=_QIjpv-UJ77xEQY8fIYoQtr5qv8wKrPJc7v7_-CYAb0=aJQCyBglFPt5-boeH0TmdwZPCq7mlewl6Obk3Gs6ckY=uJEnKpDKTfDfspSkPSUNxyVCXwiiizKYJ4xWFybULew=






--
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [Bug 103031] [llvmpipe] piglit fs-discard-exit-2 fails with llvm-6.0

2017-10-06 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=103031

Roland Scheidegger  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|NEW |RESOLVED

--- Comment #3 from Roland Scheidegger  ---
> Yes, this patch fixes the llvm.x86.avx2.pabs.d error.

Thanks for testing, fixed with 52b73caaf40e79c90a105ec6d349abb3398e3c6b.

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


Re: [Mesa-dev] [PATCH 0/6] st/mesa: add locking around lazy texture/sampler updates

2017-10-06 Thread Roland Scheidegger
I can't help but think that there'd be none of those problems if those
views were actually used as specced by gallium initially: all sampler
views (and surfaces) are per context, and they simply cannot be used in
another context.

Roland

Am 06.10.2017 um 22:38 schrieb Nicolai Hähnle:
> Hi all,
> 
> This series is a first result of debugging some random crashes in dEQP's
> multi-threaded EGL tests.
> 
> The OpenGL spec is pretty clear that application must not modify a texture
> in one context while simultaneously using it for texturing (or even
> modifying) it in another context. Texturing simultaneously in multiple
> contexts is fine, though.
> 
> This can lead to races when st_finalize_texture is called simultaneously
> for two contexts, or if two contexts simultaneously attempt to access the
> sampler view array of a texture.
> 
> This series should fix most (all?) issues where our internal data
> structures could become corrupted. I am aware of one remaining corner
> case that could lead to rendering corruption. It appears rather non-trivial
> to fix, and it is documented in a comment of patch #5.
> 
> Please review!
> Thanks,
> Nicolai
> --
>  src/gallium/auxiliary/util/u_inlines.h   |  16 ++-
>  src/gallium/include/pipe/p_context.h |  10 ++
>  src/mesa/state_tracker/st_atom_sampler.c |  12 +-
>  src/mesa/state_tracker/st_atom_texture.c |  12 --
>  src/mesa/state_tracker/st_cb_texture.c   |  59 +++--
>  src/mesa/state_tracker/st_manager.c  |   3 +
>  src/mesa/state_tracker/st_sampler_view.c | 137 +
>  src/mesa/state_tracker/st_sampler_view.h |   7 ++
>  src/mesa/state_tracker/st_texture.h  |  23 +++-
>  9 files changed, 205 insertions(+), 74 deletions(-)
> 
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.freedesktop.org_mailman_listinfo_mesa-2Ddev=DwIGaQ=uilaK90D4TOVoH58JNXRgQ=_QIjpv-UJ77xEQY8fIYoQtr5qv8wKrPJc7v7_-CYAb0=aJQCyBglFPt5-boeH0TmdwZPCq7mlewl6Obk3Gs6ckY=uJEnKpDKTfDfspSkPSUNxyVCXwiiizKYJ4xWFybULew=
>  
> 

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


Re: [Mesa-dev] [PATCH 2/2] disk_cache: remove unnecessary NULL-pointer guards

2017-10-06 Thread Marek Olšák
Reviewed-by: Marek Olšák 

Marek

On Fri, Oct 6, 2017 at 10:21 PM, Nicolai Hähnle  wrote:
> From: Nicolai Hähnle 
>
> ---
>  src/util/disk_cache.c | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
> index 63fd8e1f93a..e38cacb259b 100644
> --- a/src/util/disk_cache.c
> +++ b/src/util/disk_cache.c
> @@ -980,24 +980,22 @@ cache_put(void *job, int thread_index)
> p_atomic_add(dc_job->cache->size, sb.st_blocks * 512);
>
>   done:
> if (fd_final != -1)
>close(fd_final);
> /* This close finally releases the flock, (now that the final file
>  * has been renamed into place and the size has been added).
>  */
> if (fd != -1)
>close(fd);
> -   if (filename_tmp)
> -  free(filename_tmp);
> -   if (filename)
> -  free(filename);
> +   free(filename_tmp);
> +   free(filename);
>  }
>
>  void
>  disk_cache_put(struct disk_cache *cache, const cache_key key,
> const void *data, size_t size,
> struct cache_item_metadata *cache_item_metadata)
>  {
> struct disk_cache_put_job *dc_job =
>create_put_job(cache, key, data, size, cache_item_metadata);
>
> --
> 2.11.0
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 1/2] disk_cache: fix a memory leak

2017-10-06 Thread Marek Olšák
Reviewed-by: Marek Olšák 

Marek

On Fri, Oct 6, 2017 at 10:21 PM, Nicolai Hähnle  wrote:
> From: Nicolai Hähnle 
>
> ---
>  src/util/disk_cache.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
> index 17913a913bd..63fd8e1f93a 100644
> --- a/src/util/disk_cache.c
> +++ b/src/util/disk_cache.c
> @@ -1138,20 +1138,21 @@ disk_cache_get(struct disk_cache *cache, const 
> cache_key key, size_t *size)
> cf_data.uncompressed_size))
>goto fail;
>
> /* Check the data for corruption */
> if (cf_data.crc32 != util_hash_crc32(uncompressed_data,
>  cf_data.uncompressed_size))
>goto fail;
>
> free(data);
> free(filename);
> +   free(file_header);
> close(fd);
>
> if (size)
>*size = cf_data.uncompressed_size;
>
> return uncompressed_data;
>
>   fail:
> if (data)
>free(data);
> --
> 2.11.0
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] u_threaded_context: fix a memory leak

2017-10-06 Thread Marek Olšák
Reviewed-by: Marek Olšák 

Marek

On Fri, Oct 6, 2017 at 10:20 PM, Nicolai Hähnle  wrote:
> From: Nicolai Hähnle 
>
> The uploaders can own transfers which need to be unmapped. Destroy them
> before the final sync (they're not used from the driver thread anyway)
> so that the transfer_unmap call is processed by the driver.
> ---
>  src/gallium/auxiliary/util/u_threaded_context.c | 15 ---
>  1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/src/gallium/auxiliary/util/u_threaded_context.c 
> b/src/gallium/auxiliary/util/u_threaded_context.c
> index 043d4e67df1..7e28b87a7ff 100644
> --- a/src/gallium/auxiliary/util/u_threaded_context.c
> +++ b/src/gallium/auxiliary/util/u_threaded_context.c
> @@ -2226,37 +2226,38 @@ tc_resource_commit(struct pipe_context *_pipe, struct 
> pipe_resource *res,
>  /
>   * create & destroy
>   */
>
>  static void
>  tc_destroy(struct pipe_context *_pipe)
>  {
> struct threaded_context *tc = threaded_context(_pipe);
> struct pipe_context *pipe = tc->pipe;
>
> +   if (tc->base.const_uploader &&
> +   tc->base.stream_uploader != tc->base.const_uploader)
> +  u_upload_destroy(tc->base.const_uploader);
> +
> +   if (tc->base.stream_uploader)
> +  u_upload_destroy(tc->base.stream_uploader);
> +
> tc_sync(tc);
>
> if (util_queue_is_initialized(>queue)) {
>util_queue_destroy(>queue);
>
>for (unsigned i = 0; i < TC_MAX_BATCHES; i++)
>   util_queue_fence_destroy(>batch_slots[i].fence);
> }
>
> -   if (tc->base.const_uploader &&
> -   tc->base.stream_uploader != tc->base.const_uploader)
> -  u_upload_destroy(tc->base.const_uploader);
> -
> -   if (tc->base.stream_uploader)
> -  u_upload_destroy(tc->base.stream_uploader);
> -
> slab_destroy_child(>pool_transfers);
> +   assert(tc->batch_slots[tc->next].num_total_call_slots == 0);
> pipe->destroy(pipe);
> os_free_aligned(tc);
>  }
>
>  static const tc_execute execute_func[TC_NUM_CALLS] = {
>  #define CALL(name) tc_call_##name,
>  #include "u_threaded_context_calls.h"
>  #undef CALL
>  };
>
> --
> 2.11.0
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [Mesa-stable] [PATCH] st/mesa: don't clobber glGetInternalformat* buffer for GL_NUM_SAMPLE_COUNTS

2017-10-06 Thread Marek Olšák
Reviewed-by: Marek Olšák 

Marek

On Fri, Oct 6, 2017 at 10:13 PM, Nicolai Hähnle  wrote:
> From: Nicolai Hähnle 
>
> Applications might pass in a buffer that is sized too large and rely
> on the extra space of the buffer not being overwritten.
>
> Fixes 
> dEQP-GLES31.functional.state_query.internal_format.partial_query.num_sample_counts
>
> Cc: mesa-sta...@lists.freedesktop.org
> ---
>  src/mesa/state_tracker/st_format.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/src/mesa/state_tracker/st_format.c 
> b/src/mesa/state_tracker/st_format.c
> index 5e38fe56890..65be09cbde2 100644
> --- a/src/mesa/state_tracker/st_format.c
> +++ b/src/mesa/state_tracker/st_format.c
> @@ -2371,23 +2371,24 @@ st_QueryInternalFormat(struct gl_context *ctx, GLenum 
> target,
>  * and guaranteed to have at least 16 elements.
>  */
> assert(params != NULL);
>
> switch (pname) {
> case GL_SAMPLES:
>st_QuerySamplesForFormat(ctx, target, internalFormat, params);
>break;
>
> case GL_NUM_SAMPLE_COUNTS: {
> +  int samples[16];
>size_t num_samples;
>num_samples = st_QuerySamplesForFormat(ctx, target, internalFormat,
> - params);
> + samples);
>params[0] = (GLint) num_samples;
>break;
> }
> case GL_INTERNALFORMAT_PREFERRED: {
>params[0] = GL_NONE;
>
>/* We need to resolve an internal format that is compatible with
> * the passed internal format, and optimal to the driver. By now,
> * we just validate that the passed internal format is supported by
> * the driver, and if so return the same internal format, otherwise
> --
> 2.11.0
>
> ___
> mesa-stable mailing list
> mesa-sta...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-stable
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v4 01/10] egl: add a treatment of tizen platform on egl display (v2)

2017-10-06 Thread Gwan-gyeong Mun
It adds a _EGL_PLATFORM_TIZEN enum value to _EGLPlatformType for tizen platform.

It adds a detecting routine of tizen platform to 
_eglNativePlatformDetectNativeDisplay()
and _eglGetNativePlatform().

  - As tizen platform internally distinguishes native displays of tbm, drm/gbm
and wayland client, when EGL_PLATFORM_WAYLAND_EXT or EGL_PLATFORM_GBM_MESA
come from eglGetPlatformDisplayEXT(), it have call _eglGetTizenDisplay().

Tizen supports various display protocols (tbm / gbm / wayland-egl) and each
implementation is different from mesa's. Because of tizen specific 
scanout-buffer
management for hardware overlay compositing and optimization. And also tizen
has its own gbm implementation for tizen specific implementation.
(gbm_create_device function pointer is differ from mesa's implementation.)

Therefore tizen provides libtpl-egl(Tizen Porting Layer for EGL) which is
an abstraction layer for the surface and buffer management on Tizen platform
aimed to implement the EGL porting layer of the OpenGLES driver over the
various display protocols.
As the libtpl-egl detects native display, if mesa send native display to
the libtpl-egl then it  distinguishes tbm/gbm/wayland-egl native display
and loads appropriate backend.

  - If tizen platform is enabled at the configuration, _eglGetNativePlatform()
always detects _EGL_PLATFORM_TIZEN as a detected_platform.

v2:
 - Fixes from Emil's review:
   a) Add commit messages in detail for a needing of a separated tizen backend.
   b) Remove unneeded ifndef blocks.
   c) Add comments in detail.
   d) Remove an wrong detection routine on _eglGetNativePlatform()

 - Add a detection routine of Tizen platform on _eglGetNativePlatformFromEnv()

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/main/eglapi.c | 13 +
 src/egl/main/egldisplay.c | 46 ++
 src/egl/main/egldisplay.h |  7 +++
 3 files changed, 66 insertions(+)

diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 4a9b3fe392..f3257eef4b 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -402,6 +402,19 @@ _eglGetPlatformDisplayCommon(EGLenum platform, void 
*native_display,
case EGL_PLATFORM_SURFACELESS_MESA:
   dpy = _eglGetSurfacelessDisplay(native_display, attrib_list);
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+/* Tizen supports various display protocols (tbm / gbm / wayland-egl) and
+ * each implementation is different from mesa's.
+ * (Tizen has its own gbm implementation for tizen specific implementation.)
+ *  Therefore, when Tizen platform is enabled, it has call 
_eglGetTizenDisplay().
+ */
+case EGL_PLATFORM_GBM_MESA:
+   dpy = _eglGetTizenDisplay(native_display, attrib_list);
+   break;
+case EGL_PLATFORM_WAYLAND_EXT:
+   dpy = _eglGetTizenDisplay(native_display, attrib_list);
+   break;
 #endif
default:
   RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 690728d2f7..43e2d73e73 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -70,6 +70,7 @@ static const struct {
{ _EGL_PLATFORM_ANDROID, "android" },
{ _EGL_PLATFORM_HAIKU, "haiku" },
{ _EGL_PLATFORM_SURFACELESS, "surfaceless" },
+   { _EGL_PLATFORM_TIZEN, "tizen" },
 };
 
 
@@ -92,7 +93,20 @@ _eglGetNativePlatformFromEnv(void)
 
for (i = 0; i < _EGL_NUM_PLATFORMS; i++) {
   if (strcmp(egl_platforms[i].name, plat_name) == 0) {
+#ifdef HAVE_TIZEN_PLATFORM
+ /* Some widget library (ex. efl) can set EGL_DISPLAY environment
+  * variable as wayland or drm. But when TIZEN platform is enabled,
+  * we should ignore this variable in mesa. Becasue libtpl-egl detects
+  * this enviromnet variable and loads appropriate backend for that.
+  */
+ if ((egl_platforms[i].platform == _EGL_PLATFORM_WAYLAND) ||
+ (egl_platforms[i].platform == _EGL_PLATFORM_DRM))
+plat = _EGL_PLATFORM_TIZEN;
+ else
+plat = egl_platforms[i].platform;
+#else
  plat = egl_platforms[i].platform;
+#endif
  break;
   }
}
@@ -115,6 +129,23 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay)
 
   (void) first_pointer; /* silence unused var warning */
 
+#ifdef HAVE_TIZEN_PLATFORM
+  /* Tizen supports various display protocols (tbm / gbm / wayland-egl)
+   * and each implementation is different from mesa's. Because of tizen
+   * specific scanout-buffer management for hardware overlay compositing
+   * and optimization. And also tizen has its own gbm implementation for
+   * tizen specific implementation. (gbm_create_device function pointer
+   * is differ from mesa's implementation.)
+   * Therefore tizen provides libtpl-egl(Tizen Porting Layer for EGL) which
+   * is an abstraction layer for the surface and buffer 

[Mesa-dev] [PATCH v4 05/10] egl/tizen: add support of dri2_loader (v3)

2017-10-06 Thread Gwan-gyeong Mun
It adds support of dri2_loader to egl dri2 tizen backend.
  - referenced a basic buffer flow and management implementation from android.

And it implements a query buffer age extesion for tizen and turn on
swap_buffers_with_damage extension.
  - it add color buffer related member variables to dri_egl_surface for a
management of color buffers.

v2: Fixes from Emil's review:
   a) Remove a temporary variable and return directly on get_format_bpp()
   b) Remove unneeded compiler pragma
   c) Follow coding style
   d) Rename get_pitch() to get_stride() for using of consistent naming
   e) Remove mis-referencing from android implementation on treatment of buffer
  age.
  reference: 
https://lists.freedesktop.org/archives/mesa-dev/2017-June/158409.html
   f) Use dri2_egl_surface_free_outdated_buffers_and_update_size() helper
   g) Use dri2_egl_surface_record_buffers_and_update_back_buffer() helper
   h) Use add dri2_egl_surface_update_buffer_age() helper
   i) Use env_var_as_boolean for hw_accel variable on dri2_initialize_tizen()
   j) Remove getting of the device name and opening of the device node on 
dri2_initialize_tizen()
  And add duplicating of tbm_bufmgr_fd. As tbm_bufmgr_fd is managed by 
tbm_bufmgr,
  if mesa use this fd then we should duplicate it.
   k) Add comments why we can not drop the dri2 codepath on 
dri2_initialize_tizen()
  As some kernels ported for tizen don't support render node feature yet,
  currently we cannot drop the dri2 codepath.

v3: Fixes from Rob and Emil's review:
   - Use refactored color_buffers structure

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.h   |   2 +
 src/egl/drivers/dri2/platform_tizen.c | 257 --
 2 files changed, 245 insertions(+), 14 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 4e1fead46b..12c46759d3 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -78,6 +78,8 @@ struct zwp_linux_dmabuf_v1;
 #else
/* Usually Android uses at most triple buffers in ANativeWindow
 * so hardcode the number of color_buffers to 3.
+* And usually Tizen uses at most triple buffers in tpl_surface
+* (tbm_surface_queue) so hardcode the number of color_buffers to 3.
 */
 #define COLOR_BUFFERS_SIZE 3
 #endif
diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 7cee03f784..72cef25364 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -46,6 +46,43 @@
 #include "egl_dri2.h"
 #include "egl_dri2_fallbacks.h"
 #include "loader.h"
+#include "util/debug.h"
+
+static int get_format_bpp(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_BGRA:
+   case TBM_FORMAT_RGBA:
+   case TBM_FORMAT_RGBX:
+   case TBM_FORMAT_ARGB:
+   case TBM_FORMAT_XRGB:
+  return 4;
+   case TBM_FORMAT_RGB565:
+  return 2;
+   default:
+  return 0;
+   }
+}
+
+static int get_stride(tbm_surface_h tbm_surface)
+{
+   tbm_surface_info_s surf_info;
+
+   if (tbm_surface_get_info(tbm_surface, _info) != TBM_SURFACE_ERROR_NONE)
+  return 0;
+
+   return surf_info.planes[0].stride;
+}
+
+static int
+get_native_buffer_name(tbm_surface_h tbm_surface)
+{
+   uint32_t bo_name;
+
+   bo_name = tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0));
+
+   return (bo_name != 0 ) ? (int)bo_name : -1;
+}
 
 static EGLBoolean
 tizen_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
@@ -60,10 +97,14 @@ tizen_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
tbm_surface_internal_ref(dri2_surf->tbm_surface);
 
tpl_surface_get_size(dri2_surf->tpl_surface, , );
-   if (dri2_surf->base.Width != width || dri2_surf->base.Height != height) {
-  dri2_surf->base.Width = width;
-  dri2_surf->base.Height = height;
-   }
+
+   dri2_egl_surface_free_outdated_buffers_and_update_size(dri2_surf, width, 
height);
+
+   /* Record all the buffers created by tpl_surface (tbm_surface_queue)
+* and update back buffer for updating buffer's age in swap_buffers.
+*/
+   dri2_egl_surface_record_buffers_and_update_back_buffer(dri2_surf,
+  
(void*)dri2_surf->tbm_surface);
 
return EGL_TRUE;
 }
@@ -101,6 +142,7 @@ tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
 
tbm_surface_internal_unref(dri2_surf->tbm_surface);
dri2_surf->tbm_surface = NULL;
+   dri2_surf->back = NULL;
 
mtx_lock(>Mutex);
 
@@ -208,7 +250,10 @@ tizen_create_surface(_EGLDriver *drv, _EGLDisplay *disp, 
EGLint type,
if (!dri2_surf->tpl_surface)
   goto cleanup_surface;
 
-   createNewDrawable = dri2_dpy->swrast->createNewDrawable;
+   if (dri2_dpy->dri2)
+  createNewDrawable = dri2_dpy->dri2->createNewDrawable;
+   else
+  createNewDrawable = dri2_dpy->swrast->createNewDrawable;
 

[Mesa-dev] [PATCH v4 04/10] configure.ac: Add tizen to supported platforms (v2)

2017-10-06 Thread Gwan-gyeong Mun
It checks tpl-egl/libtbm/libtdm packages and defines HAVE_PLATFORM_TIZEN.
This feature is enabled by the config option '--with-platforms=tizen'

v2: Fixes from Emil's review:
  - Add require_libdrm to tizen platform

Signed-off-by: Mun Gwan-gyeong 
---
 configure.ac | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 903a3979d4..f350d3caa9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1695,7 +1695,7 @@ dnl
 AC_ARG_WITH([platforms],
 [AS_HELP_STRING([--with-platforms@<:@=DIRS...@:>@],
 [comma delimited native platforms libEGL/Vulkan/other supports, e.g.
-"x11,drm,wayland,surfaceless..." @<:@default=auto@:>@])],
+"x11,drm,wayland,surfaceless,tizen..." @<:@default=auto@:>@])],
 [with_platforms="$withval"],
 [with_platforms=auto])
 
@@ -1755,13 +1755,18 @@ for plat in $platforms; do
 DEFINES="$DEFINES -DHAVE_ANDROID_PLATFORM"
 ;;
 
+tizen)
+PKG_CHECK_MODULES([TIZEN], [tpl-egl libtbm libtdm])
+DEFINES="$DEFINES -DHAVE_TIZEN_PLATFORM"
+;;
+
 *)
 AC_MSG_ERROR([platform '$plat' does not exist])
 ;;
 esac
 
 case "$plat" in
-wayland|drm|surfaceless)
+wayland|drm|surfaceless|tizen)
 require_libdrm "Platform $plat"
 ;;
 esac
@@ -1785,6 +1790,7 @@ AM_CONDITIONAL(HAVE_PLATFORM_WAYLAND, echo "$platforms" | 
grep -q 'wayland')
 AM_CONDITIONAL(HAVE_PLATFORM_DRM, echo "$platforms" | grep -q 'drm')
 AM_CONDITIONAL(HAVE_PLATFORM_SURFACELESS, echo "$platforms" | grep -q 
'surfaceless')
 AM_CONDITIONAL(HAVE_PLATFORM_ANDROID, echo "$platforms" | grep -q 'android')
+AM_CONDITIONAL(HAVE_PLATFORM_TIZEN, echo "$platforms" | grep -q 'tizen')
 
 dnl
 dnl More DRI setup
-- 
2.14.2

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


[Mesa-dev] [PATCH v4 10/10] docs: add a high level info about Tizen / Tizen Porting Layer (TPL) for EGL / Tizen Buffer Manager (TBM) / etc (v2)

2017-10-06 Thread Gwan-gyeong Mun
It gives a quick overview and references of developing OpenGLES / EGL
Driver for Tizen.

v2:
 - Fixes from Eric's review:
   Change links of Setup build environment for Tizen (Raspberry Pi 3) and
   Tizen Binary Download Instructions for Raspberry Pi 3 to `tizen-` prefixed
   pages.

 - Add Setup Raspberry Pi 3 for Tizen Instruction link

Signed-off-by: Mun Gwan-gyeong 
---
 docs/systems.html |   1 +
 docs/tizen.html   | 251 ++
 2 files changed, 252 insertions(+)
 create mode 100644 docs/tizen.html

diff --git a/docs/systems.html b/docs/systems.html
index b97e1f0a79..ab6c9c3f74 100644
--- a/docs/systems.html
+++ b/docs/systems.html
@@ -63,6 +63,7 @@ drivers for the X Window System
 and Unix-like operating systems
 Microsoft Windows
 VMware guest OS driver
+Tizen
 
 
 
diff --git a/docs/tizen.html b/docs/tizen.html
new file mode 100644
index 00..06656c8f44
--- /dev/null
+++ b/docs/tizen.html
@@ -0,0 +1,251 @@
+http://www.w3.org/TR/html4/loose.dtd;>
+
+
+  
+  Tizen
+  
+
+
+
+
+  The Mesa 3D Graphics Library
+
+
+
+
+
+Introduction
+
+
+This document describes the essential elements of Tizen's platform-level
+graphics architecture related to OpenGL ES and EGL,
+and how it is used by the application framework and the display server.
+The focus is on how graphical data buffers move through the system.
+
+
+
+Tizen platform requires the OpenGL ES driver for the acceleration of
+the Wayland display server and wayland-eglclient.
+This platform demands OpenGL ES and EGL driver which is implemented by
+the Tizen EGL Porting Layer.
+
+
+
+Tizen OpenGL ES and EGL Architecture
+
+
+The following figure illustrates the Tizen OpenGL ES and EGL architecture.
+
+
+
+  https://wiki.tizen.org/images/d/d6/OPENGLES_STACK.png;
+  width="800" height="582" />
+
+
+
+CoreGL
+
+An injection layer of OpenGL ES that provides the following 
capabilities:
+
+
+   Support for driver-independent optimization (FastPath)
+   EGL/OpenGL ES debugging
+   Performance logging
+
+
+
+Tizen Porting Layer (TPL) for EGL
+
+
+TPL-EGL is an abstraction layer for surface and buffer management on Tizen
+platform. It is used for implementation of the EGL platform functions.
+
+
+
+  https://wiki.tizen.org/images/0/0e/Tpl_architecture.png;
+  width="800" height="204" />
+
+
+
+
+  
+  The background for the Tizen EGL Porting Layer for EGL is in various window
+  system protocols in Tizen. There was a need for separating common layer and
+  backend.
+  
+  
+  Tizen uses the Tizen Porting Layer for EGL, as the TPL-EGL APIs prevents
+  burdens of the EGL porting on various window system protocols.
+  The GPU GL Driver’s Window System Porting Layer can be implemented by
+  TPL-EGL APIs which are the corresponding window system APIs.
+  The TBM, Wayland, and GBM backends are supported.
+  
+
+
+
+Tizen Porting Layer for EGL Object Model
+
+
+TPL-EGL provides interfaces based of object driven model.
+Every TPL-EGL object can be represented as a generic tpl_object_t,
+which is reference-counted and provides common functions.
+Currently, display and surface types of TPL-EGL objects are provided.
+Display, like normal display, represents a display system which is usually
+used for connection to the server. Surface corresponds to a native surface
+like wl_surface. A surface might be configured to use N-buffers,
+but is usually double-buffered or triple-buffered.
+Buffer is actually something to render on, usually a set of pixels
+or a block of memory. For these 2 objects, the Wayland, GBM, TBM backend are
+defined, and they are corresponding to their own window systems.
+This means that you do not need to care about the window systems.
+
+
+
+TPL-EGL Core Object
+
+
+  TPL-EGL Object
+  
+Base class for all TPL-EGL objects
+  
+
+  TPL-EGL Display
+  
+
+Encapsulates the native display object (Display *, wl_display) Like a
+normal display, represents a display system which is usually used for
+connection to the server, scope for other objects.
+  
+  
+
+  TPL-EGL Surface
+  
+
+Encapsulates the native drawable object (Window, Pixmap, wl_surface)
+The surface corresponds to a native surface, such as tbm_surface_queue
+or wl_surface. A surface can be configured to use N-buffers,
+but they are usually double-buffered or triple-buffered.
+
+  
+
+
+
+TPL-EGL Objects and Corresponding EGL Objects
+
+Both TPL-EGL and vendor GLES/EGL driver handles the tbm_surface as
+TPL surface's corresponding buffer. It is represented by the TBM_Surface
+part in the following figure.
+
+
+
+  https://wiki.tizen.org/images/e/e6/Relationship_TPL_EGL_Gray.png;
+  width="800" height="403" />
+
+
+
+The following figure illustrates the GLES drawing API flow.
+
+
+  https://wiki.tizen.org/images/4/41/GLES_API_FLOW_GRAY.png;
+  width="800" height="480" />
+
+
+
+Tizen Buffer Manager (TBM)
+
+
+Tizen Buffer Manager (TBM) provides the abstraction interface for the 

[Mesa-dev] [PATCH v4 09/10] egl/tizen: add support of dri_image_loader (v3)

2017-10-06 Thread Gwan-gyeong Mun
It adds support of dri_image_loader to egl dri2 tizen backend.
   - referenced a basic buffer flow and management  implementation from 
android's.

It adds dri_image_back/dri_image_back member variables to dri_egl_surface for
a management of back/front buffers.

v2:
 - Fixes from Emil's review:
   a) Use dri2_egl_surface_destroy_image_back() helper
   b) Use dri2_egl_surface_destroy_image_front() helper
   c) Use dri2_egl_surface_get_image_front() helper

 - Use get_stride helper on get_back_bo()

v3:
 - Use dri2_egl_surface's default dri_image_back and dri_image_front

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 143 +-
 1 file changed, 140 insertions(+), 3 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 091ae4dcef..87c7e1e6a2 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -225,6 +225,8 @@ tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
 
mtx_lock(>Mutex);
 
+   dri2_egl_surface_destroy_image_back(dri2_surf);
+
return EGL_TRUE;
 
 cleanup:
@@ -329,7 +331,9 @@ tizen_create_surface(_EGLDriver *drv, _EGLDisplay *disp, 
EGLint type,
if (!dri2_surf->tpl_surface)
   goto cleanup_surface;
 
-   if (dri2_dpy->dri2)
+   if (dri2_dpy->image_driver)
+  createNewDrawable = dri2_dpy->image_driver->createNewDrawable;
+   else if (dri2_dpy->dri2)
   createNewDrawable = dri2_dpy->dri2->createNewDrawable;
else
   createNewDrawable = dri2_dpy->swrast->createNewDrawable;
@@ -380,6 +384,9 @@ tizen_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->tbm_surface)
   tizen_window_cancel_buffer(disp, dri2_surf);
 
+   dri2_egl_surface_destroy_image_back(dri2_surf);
+   dri2_egl_surface_destroy_image_front(dri2_surf);
+
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
tpl_object_unreference((tpl_object_t *)dri2_surf->tpl_surface);
@@ -404,6 +411,119 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
return 0;
 }
 
+static int
+get_back_bo(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+   int fourcc, pitch;
+   int offset = 0, fd;
+   tbm_surface_info_s surf_info;
+
+   if (dri2_surf->dri_image_back)
+  return 0;
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+  if (!dri2_surf->tbm_surface) {
+ _eglLog(_EGL_WARNING, "Could not get native buffer");
+ return -1;
+  }
+
+  fd = get_native_buffer_fd(dri2_surf->tbm_surface);
+  if (fd < 0) {
+ _eglLog(_EGL_WARNING, "Could not get native buffer FD");
+ return -1;
+  }
+
+  pitch = get_stride(dri2_surf->tbm_surface);
+  fourcc = get_fourcc(dri2_surf->tbm_format);
+
+  if (fourcc == -1 || pitch == 0) {
+ _eglLog(_EGL_WARNING, "Invalid buffer fourcc(%x) or pitch(%d)",
+ fourcc, pitch);
+ return -1;
+  }
+
+  dri2_surf->base.Width = surf_info.width;
+  dri2_surf->base.Height = surf_info.height;
+
+  dri2_surf->dri_image_back =
+ dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen,
+ dri2_surf->base.Width,
+ dri2_surf->base.Height,
+ fourcc,
+ ,
+ 1,
+ ,
+ ,
+ dri2_surf);
+
+  if (!dri2_surf->dri_image_back) {
+ _eglLog(_EGL_WARNING, "failed to create DRI image from FD");
+ return -1;
+  }
+   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
+  /* The EGL 1.5 spec states that pbuffers are single-buffered. 
Specifically,
+   * the spec states that they have a back buffer but no front buffer, in
+   * contrast to pixmaps, which have a front buffer but no back buffer.
+   *
+   * Single-buffered surfaces with no front buffer confuse Mesa; so we 
deviate
+   * from the spec, following the precedent of Mesa's EGL X11 platform. The
+   * X11 platform correctly assigns pbuffers to single-buffered configs, 
but
+   * assigns the pbuffer a front buffer instead of a back buffer.
+   *
+   * Pbuffers in the X11 platform mostly work today, so let's just copy its
+   * behavior instead of trying to fix (and hence potentially breaking) the
+   * world.
+   */
+  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported back buffer for 
pbuffer surface");
+   }
+
+   return 0;
+}
+
+/* Some drivers will pass multiple bits in buffer_mask.
+ * For such case, will go through all the bits, and
+ * will not return 

[Mesa-dev] [PATCH v4 00/10] Mesa for Tizen serises

2017-10-06 Thread Gwan-gyeong Mun
Hi,

Patch series split out refactors and "mesa for tizen".

Thease series only have mesa for tizen feature.

these depend on splited out refactors.
https://patchwork.freedesktop.org/patch/181055/
https://patchwork.freedesktop.org/patch/181056/
https://patchwork.freedesktop.org/patch/181060/
https://patchwork.freedesktop.org/patch/181057/
https://patchwork.freedesktop.org/patch/181058/
https://patchwork.freedesktop.org/patch/181061/
https://patchwork.freedesktop.org/patch/181062/


Gwan-gyeong Mun (10):
  egl: add a treatment of tizen platform on egl display (v2)
  egl/dri2: Add some member variables for tizen platform on
dri2_egl_display and dri2_egl_surface (v2)
  egl/tizen: add support of the swrast related features for tizen
platform (v2)
  configure.ac: Add tizen to supported platforms (v2)
  egl/tizen: add support of dri2_loader (v3)
  egl/tizen: add tizen specific implementations for
BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL
(v2)
  egl/tizen: add tizen specific implementation for EGL_WAYLAND_BUFFER_WL
target of eglCreateImageKHR() (v2)
  egl/tizen: add EGL_NATIVE_SURFACE_TIZEN target of eglCreateImageKHR()
  egl/tizen: add support of dri_image_loader (v3)
  docs: add a high level info about Tizen / Tizen Porting Layer (TPL)
for EGL / Tizen Buffer Manager (TBM) / etc (v2)

 configure.ac  |   10 +-
 docs/systems.html |1 +
 docs/tizen.html   |  251 ++
 src/egl/Makefile.am   |6 +
 src/egl/drivers/dri2/egl_dri2.c   |   11 +
 src/egl/drivers/dri2/egl_dri2.h   |   24 +
 src/egl/drivers/dri2/platform_tizen.c | 1419 +
 src/egl/main/eglapi.c |   15 +
 src/egl/main/egldisplay.c |   46 ++
 src/egl/main/egldisplay.h |9 +
 10 files changed, 1790 insertions(+), 2 deletions(-)
 create mode 100644 docs/tizen.html
 create mode 100644 src/egl/drivers/dri2/platform_tizen.c

-- 
2.14.2

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


[Mesa-dev] [PATCH v4 07/10] egl/tizen: add tizen specific implementation for EGL_WAYLAND_BUFFER_WL target of eglCreateImageKHR() (v2)

2017-10-06 Thread Gwan-gyeong Mun
In the tizen platform, a wl_buffer wraps a tbm_surface. The tbm_surface contains
gem name or prime fd. For creating dri_image, we need to extract the tbm_surface
from the wl_buffer and we use tpl_display_get_buffer_from_native_pixmap() api
for that.

v2:
   a) Add switch's default case to return on get_fourcc(), get_fourcc_yuv()
  and get_format()
   b) Use get_stride helper on tizen_create_image_from_name() and 
tizen_create_image_from_prime_fd()

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 299 +-
 1 file changed, 298 insertions(+), 1 deletion(-)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 6d872f9d3e..777b9ba9b3 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -48,6 +48,60 @@
 #include "loader.h"
 #include "util/debug.h"
 
+/* createImageFromFds requires fourcc format */
+static int get_fourcc(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_RGB565:   return __DRI_IMAGE_FOURCC_RGB565;
+   case TBM_FORMAT_BGRA: return __DRI_IMAGE_FOURCC_ARGB;
+   case TBM_FORMAT_RGBA: return __DRI_IMAGE_FOURCC_ABGR;
+   case TBM_FORMAT_ARGB: return __DRI_IMAGE_FOURCC_ARGB;
+   case TBM_FORMAT_ABGR: return __DRI_IMAGE_FOURCC_ABGR;
+   case TBM_FORMAT_RGBX: return __DRI_IMAGE_FOURCC_XBGR;
+   case TBM_FORMAT_XRGB: return __DRI_IMAGE_FOURCC_XRGB;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
+  return -1;
+   }
+}
+
+static int get_fourcc_yuv(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_NV12:   return __DRI_IMAGE_FOURCC_NV12;
+   case TBM_FORMAT_NV21:   return __DRI_IMAGE_FOURCC_NV12;
+   case TBM_FORMAT_YUV420: return __DRI_IMAGE_FOURCC_YUV420;
+   case TBM_FORMAT_YVU420: return __DRI_IMAGE_FOURCC_YVU420;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native yuv buffer format 0x%x", 
format);
+  return -1;
+   }
+}
+
+static bool is_yuv_format(tbm_format format)
+{
+   if (get_fourcc_yuv(format) == -1)
+  return false;
+   else
+  return true;
+}
+
+static int get_format(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_RGB565:   return __DRI_IMAGE_FORMAT_RGB565;
+   case TBM_FORMAT_BGRA: return __DRI_IMAGE_FORMAT_ARGB;
+   case TBM_FORMAT_RGBA: return __DRI_IMAGE_FORMAT_ABGR;
+   case TBM_FORMAT_ARGB: return __DRI_IMAGE_FORMAT_ARGB;
+   case TBM_FORMAT_ABGR: return __DRI_IMAGE_FORMAT_ABGR;
+   case TBM_FORMAT_RGBX: return __DRI_IMAGE_FORMAT_XBGR;
+   case TBM_FORMAT_XRGB: return __DRI_IMAGE_FORMAT_XRGB;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
+  return -1;
+   }
+}
+
 static int get_format_bpp(tbm_format format)
 {
switch (format) {
@@ -89,6 +143,16 @@ static int get_stride(tbm_surface_h tbm_surface)
return surf_info.planes[0].stride;
 }
 
+static int
+get_native_buffer_fd(tbm_surface_h tbm_surface)
+{
+   tbm_bo_handle bo_handle;
+   bo_handle = tbm_bo_get_handle(tbm_surface_internal_get_bo(tbm_surface, 0),
+ TBM_DEVICE_3D);
+
+   return (bo_handle.ptr != NULL) ? (int)bo_handle.u32 : -1;
+}
+
 static int
 get_native_buffer_name(tbm_surface_h tbm_surface)
 {
@@ -385,6 +449,205 @@ tizen_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *draw)
return tizen_swap_buffers_with_damage (drv, disp, draw, NULL, 0);
 }
 
+static _EGLImage *
+tizen_create_image_from_prime_fd_yuv(_EGLDisplay *disp, _EGLContext *ctx,
+ tbm_surface_h tbm_surface)
+
+{
+   tbm_surface_info_s surf_info;
+   tbm_fd bo_fd[TBM_SURF_PLANE_MAX];
+   tbm_bo bo[TBM_SURF_PLANE_MAX];
+   int num_planes;
+   int i;
+   int fourcc;
+   size_t offsets[3] = {0, 0, 0};
+   size_t pitches[3] = {0, 0, 0};
+   int fds[3] = {-1, -1, -1};
+
+   if (tbm_surface_get_info(tbm_surface, _info) != 
TBM_SURFACE_ERROR_NONE) {
+  _eglLog(_EGL_WARNING, "Could not get tbm_surface_info");
+  return NULL;
+   }
+
+   num_planes = surf_info.num_planes;
+   for (i = 0; i < num_planes; i++) {
+  tbm_bo_handle bo_handle;
+  int bo_idx = tbm_surface_internal_get_plane_bo_idx(tbm_surface, i);
+  bo[i] = tbm_surface_internal_get_bo (tbm_surface, bo_idx);
+  if (bo[i] == NULL) {
+ _eglLog(_EGL_WARNING, "Could not get tbm_surface_internal_bo");
+ return NULL;
+  }
+  bo_handle = tbm_bo_get_handle(bo[i], TBM_DEVICE_3D);
+  bo_fd[i] = bo_handle.u32;
+   }
+
+   fourcc = get_fourcc_yuv(tbm_surface_get_format(tbm_surface));
+   if (fourcc == -1) {
+  _eglLog(_EGL_WARNING, "Unsupported native yuv format");
+  return NULL;
+   }
+
+   switch (fourcc) {
+   case __DRI_IMAGE_FOURCC_NV12:
+  fds[0] = bo_fd[0];
+  fds[1] = bo_fd[1];
+  offsets[0] = surf_info.planes[0].offset;
+  

[Mesa-dev] [PATCH v4 06/10] egl/tizen: add tizen specific implementations for BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL (v2)

2017-10-06 Thread Gwan-gyeong Mun
Tizen platform (actually WL_TBM protocol) internally processes similiar actions
such as mesa's BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL.
So the platform_tizen.c needs to implemment BindWaylandDisplayWL,
UnbindWaylandDisplayWL and QueryWaylandBufferWL apart from mesa's.

  - tizen's enlightenment wayland display server calls wayland_tbm_server_init()
which processes described tasks.

  - section TPL-EGL and Wayland Server and Client
from https://wiki.tizen.org/3.0_Porting_Guide/Graphics_and_UI/OpenGL

"Tizen uses the wl_tbm protocol instead of wl_drm. The wl_tbm protocol is
 born for sharing the buffer(tbm_surface) between the wayland_client and
 wayland_server. Although the wayland_tbm_server_init and 
wayland_tbm_client_init
 pair is a role for the eglBindWaylandDisplayWL, the EGL driver is required
 to implement the entrypoints for the eglBindWaylandDisplayWL and
 eglUnbindWaylandDisplayWL as dummy."

v2: Fixes from Emil's review:
   a) Remove unneeded compiler pragma
   b) Add and use get_texture_format() helper
   c) Add switch's default case on tizen_query_wayland_buffer_wl()

referenced materials:
[1] https://wiki.tizen.org/3.0_Porting_Guide/Graphics_and_UI/OpenGL
[2] repository: git://git.tizen.org/platform/core/uifw/wayland-tbm (branch: 
tizen)

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 92 +++
 1 file changed, 92 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 72cef25364..6d872f9d3e 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -64,6 +64,21 @@ static int get_format_bpp(tbm_format format)
}
 }
 
+static EGLBoolean get_texture_format(tbm_format format, EGLint *value)
+{
+   switch (format) {
+   case TBM_FORMAT_ARGB:
+  *value = EGL_TEXTURE_RGBA;
+  return EGL_TRUE;
+   case TBM_FORMAT_XRGB:
+   case TBM_FORMAT_RGB565:
+  *value = EGL_TEXTURE_RGB;
+  return EGL_TRUE;
+   default:
+  return EGL_FALSE;
+   }
+}
+
 static int get_stride(tbm_surface_h tbm_surface)
 {
tbm_surface_info_s surf_info;
@@ -735,6 +750,78 @@ static const __DRIextension 
*tizen_swrast_loader_extensions[] = {
NULL,
 };
 
+static EGLBoolean
+tizen_bind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp,
+  struct wl_display *wl_dpy)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   (void) drv;
+   (void) wl_dpy;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_unbind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp,
+struct wl_display *wl_dpy)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   (void) drv;
+   (void) wl_dpy;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_query_wayland_buffer_wl(_EGLDriver *drv, _EGLDisplay *disp,
+  struct wl_resource *buffer_resource,
+  EGLint attribute, EGLint *value)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   tbm_format tbm_format = 0;
+   int width = 0, height = 0;
+   tpl_result_t res;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   res = tpl_display_get_native_pixmap_info(dri2_dpy->tpl_display,
+(tpl_handle_t)buffer_resource,
+, , _format);
+   if (res != TPL_ERROR_NONE)
+  return EGL_FALSE;
+
+   switch (attribute) {
+   case EGL_TEXTURE_FORMAT:
+  return get_texture_format(tbm_format, value);
+   case EGL_WIDTH:
+  *value = width;
+  return EGL_TRUE;
+   case EGL_HEIGHT:
+  *value = height;
+  return EGL_TRUE;
+   default:
+  return EGL_FALSE;
+   }
+}
+
 EGLBoolean
 dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 {
@@ -865,6 +952,11 @@ dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 
dpy->Extensions.EXT_buffer_age = EGL_TRUE;
dpy->Extensions.EXT_swap_buffers_with_damage = EGL_TRUE;
+   dpy->Extensions.WL_bind_wayland_display = EGL_TRUE;
+
+   drv->API.BindWaylandDisplayWL = tizen_bind_wayland_display_wl;
+   drv->API.UnbindWaylandDisplayWL = tizen_unbind_wayland_display_wl;
+   drv->API.QueryWaylandBufferWL = tizen_query_wayland_buffer_wl;
 
return EGL_TRUE;
 
-- 
2.14.2

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


[Mesa-dev] [PATCH v4 03/10] egl/tizen: add support of the swrast related features for tizen platform (v2)

2017-10-06 Thread Gwan-gyeong Mun
It implements the egl swrast related features for tizen platform on 
platform_tizen.c

It works with libtpl-egl (Tizen Porting Layer for egl) and libtbm (Tizen Buffer 
Manager)
where back buffers of windows are backed by GEM objects. In Tizen a native 
window
has a queue (tbm_surface_queue) of back buffers allocated by the WL_TBM
(wayland client case, WL_TBM is abbreviation of wayland-tbm protocol) or gbm
(tizen has implements gbm with tbm) or tbm through tbm_backend.

For each frame, EGL needs to

  dequeue the next back buffer - tizen_window_dequeue_buffer()
  render to the buffer
  enqueue the buffer - tizen_window_enqueue_buffer()

After enqueuing, the buffer is no longer valid to EGL.

v2:
 - Fixes from Emil's review:
   a) Add a treating of fail case on tizen_window_enqueue_buffer_with_damage()
   b) Follow coding style
   c) Remove unneeded compiler pragma
   d) Use a stride helper for tizen_swrast_get_image()
   e) Fix tizen_swrast_get_image() as drm platform's implementation
  referenced commit: fe2a6281b3b28fe7399e7dbcc2077d773824
   f) Fix tizen_swrast_put_image2() as drm platform's implementation
  referenced commit: 3a5e3aa5a53cff55a5e31766d713a41ffa5a93d7
   g) Add tizen_add_configs_for_surface_type() helper function which removes
  roundtrips.
   h) Refactor for tizen_add_configs()

 - Add image_image_lookup extension to tizen_swrast_loader_extensions

Referenced documents:
[1] 
https://www.x.org/wiki/Events/XDC2016/Program/XDC2016_Tizen_Window_System_EGL_Vulkan.pdf
[2] https://wiki.tizen.org/wiki/3.0_Porting_Guide/Graphics_and_UI/libtpl-egl
[3] https://wiki.tizen.org/wiki/TBM

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/Makefile.am   |   6 +
 src/egl/drivers/dri2/platform_tizen.c | 646 ++
 2 files changed, 652 insertions(+)
 create mode 100644 src/egl/drivers/dri2/platform_tizen.c

diff --git a/src/egl/Makefile.am b/src/egl/Makefile.am
index eeb745f973..648672998e 100644
--- a/src/egl/Makefile.am
+++ b/src/egl/Makefile.am
@@ -108,6 +108,12 @@ libEGL_common_la_LIBADD += $(ANDROID_LIBS)
 dri2_backend_FILES += drivers/dri2/platform_android.c
 endif
 
+if HAVE_PLATFORM_TIZEN
+AM_CFLAGS += $(TIZEN_CFLAGS)
+libEGL_common_la_LIBADD += $(TIZEN_LIBS)
+dri2_backend_FILES += drivers/dri2/platform_tizen.c
+endif
+
 AM_CFLAGS += \
-I$(top_srcdir)/src/loader \
-I$(top_builddir)/src/egl/drivers/dri2 \
diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
new file mode 100644
index 00..7cee03f784
--- /dev/null
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -0,0 +1,646 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 2017 Samsung Electronics co., Ltd. All Rights Reserved
+ *
+ * Based on platform_android, which has
+ *
+ * Copyright (C) 2010-2011 Chia-I Wu 
+ * Copyright (C) 2010-2011 LunarG Inc.
+ * Copyright © 2011 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.
+ *
+ * Authors:
+ *Gwan-gyeong Mun 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "egl_dri2.h"
+#include "egl_dri2_fallbacks.h"
+#include "loader.h"
+
+static EGLBoolean
+tizen_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
+{
+   int width, height;
+
+   dri2_surf->tbm_surface = tpl_surface_dequeue_buffer(dri2_surf->tpl_surface);
+
+   if (!dri2_surf->tbm_surface)
+  return EGL_FALSE;
+
+   tbm_surface_internal_ref(dri2_surf->tbm_surface);
+
+   tpl_surface_get_size(dri2_surf->tpl_surface, , );
+   if (dri2_surf->base.Width != width || dri2_surf->base.Height != height) {
+  dri2_surf->base.Width = width;
+  dri2_surf->base.Height = height;
+   }
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
+   

[Mesa-dev] [PATCH v4 08/10] egl/tizen: add EGL_NATIVE_SURFACE_TIZEN target of eglCreateImageKHR()

2017-10-06 Thread Gwan-gyeong Mun
It adds TIZEN_image_native_surface extension string to _EGLExtensions.
And it adds a routine of creating an EGLImage from a tbm_surface.

  - section overview
from 
https://www.khronos.org/registry/EGL/extensions/TIZEN/EGL_TIZEN_image_native_surface.txt

"Tizen Buffer Manager (TBM) is a user space, generic memory management
 framework to create and share memory buffers between different system
 components. This extension enables using a Tizen Buffer Manager (TBM)
 surface object (struct tbm_surface_h) as an EGLImage source."

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 18 ++
 src/egl/main/eglapi.c |  2 ++
 src/egl/main/egldisplay.h |  2 ++
 3 files changed, 22 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 777b9ba9b3..091ae4dcef 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -678,6 +678,20 @@ tizen_query_surface(_EGLDriver *drv, _EGLDisplay *dpy, 
_EGLSurface *surf,
return _eglQuerySurface(drv, dpy, surf, attribute, value);
 }
 
+static _EGLImage *
+dri2_create_image_tizen_native_buffer(_EGLDisplay *disp,
+  _EGLContext *ctx,
+  tbm_surface_h tbm_surface)
+{
+   int fd;
+
+   fd = get_native_buffer_fd(tbm_surface);
+   if (fd >= 0)
+  return tizen_create_image_from_prime_fd(disp, ctx, tbm_surface, fd);
+
+   return tizen_create_image_from_name(disp, ctx, tbm_surface);
+}
+
 static _EGLImage *
 dri2_create_image_tizen_wl_buffer(_EGLDisplay *disp,
   _EGLContext *ctx,
@@ -705,6 +719,9 @@ tizen_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
EGLClientBuffer buffer, const EGLint *attr_list)
 {
switch (target) {
+   case EGL_NATIVE_SURFACE_TIZEN:
+  return dri2_create_image_tizen_native_buffer(disp, ctx,
+   (tbm_surface_h)buffer);
case EGL_WAYLAND_BUFFER_WL:
   return dri2_create_image_tizen_wl_buffer(disp, ctx, 
(tpl_handle_t)buffer);
default:
@@ -1249,6 +1266,7 @@ dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 
dpy->Extensions.EXT_buffer_age = EGL_TRUE;
dpy->Extensions.EXT_swap_buffers_with_damage = EGL_TRUE;
+   dpy->Extensions.TIZEN_image_native_surface = EGL_TRUE;
dpy->Extensions.WL_bind_wayland_display = EGL_TRUE;
 
drv->API.BindWaylandDisplayWL = tizen_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index f3257eef4b..099ab18f15 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -536,6 +536,8 @@ _eglCreateExtensionsString(_EGLDisplay *dpy)
 
_EGL_CHECK_EXTENSION(NV_post_sub_buffer);
 
+   _EGL_CHECK_EXTENSION(TIZEN_image_native_surface);
+
_EGL_CHECK_EXTENSION(WL_bind_wayland_display);
_EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
 
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index c009462b82..1ff7b5a2d5 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -133,6 +133,8 @@ struct _egl_extensions
 
EGLBoolean NV_post_sub_buffer;
 
+   EGLBoolean TIZEN_image_native_surface;
+
EGLBoolean WL_bind_wayland_display;
EGLBoolean WL_create_wayland_buffer_from_image;
 };
-- 
2.14.2

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


[Mesa-dev] [PATCH v4 02/10] egl/dri2: Add some member variables for tizen platform on dri2_egl_display and dri2_egl_surface (v2)

2017-10-06 Thread Gwan-gyeong Mun
It adds some member variables for tizen platform on dri2_egl_display and 
dri2_egl_surface.
  - tpl_display stores a object which encapsulates native disply (wl_display,
gbm_device, tbm_bufmgr) for tizen platfom.
  - native_win stores native window (wl_surface, gbm_surface, 
tbm_surface_queue_h
  - tpl_surface stores a object which encapsulates native drawable object
(wl_surface, gbm_surface, tbm_surface_queue_h) for tizen platfom.
  - tbm_surface stores a native platform buffer.
tpl-egl exposes the native platform buffer as a tbm_surface.

And it adds routines of initialize and finalize for tizen platform.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 11 +++
 src/egl/drivers/dri2/egl_dri2.h | 22 ++
 2 files changed, 33 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index fd55dba7de..36b12ea2d5 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -910,6 +910,11 @@ dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp)
case _EGL_PLATFORM_ANDROID:
   ret = dri2_initialize_android(drv, disp);
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+   case _EGL_PLATFORM_TIZEN:
+  ret = dri2_initialize_tizen(drv, disp);
+  break;
 #endif
default:
   _eglLog(_EGL_WARNING, "No EGL platform enabled.");
@@ -1004,6 +1009,12 @@ dri2_display_destroy(_EGLDisplay *disp)
  wl_display_disconnect(dri2_dpy->wl_dpy);
   }
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+   case _EGL_PLATFORM_TIZEN:
+  if (dri2_dpy->tpl_display)
+ tpl_object_unreference((tpl_object_t *)(dri2_dpy->tpl_display));
+  break;
 #endif
default:
   break;
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 0f4ef763bd..4e1fead46b 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -65,6 +65,14 @@ struct zwp_linux_dmabuf_v1;
 
 #endif /* HAVE_ANDROID_PLATFORM */
 
+#ifdef HAVE_TIZEN_PLATFORM
+#include 
+#include 
+#include 
+#include 
+#include 
+#endif /* HAVE_TIZEN_PLATFORM */
+
 #if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
 #define COLOR_BUFFERS_SIZE 4
 #else
@@ -241,6 +249,10 @@ struct dri2_egl_display
const gralloc_module_t *gralloc;
 #endif
 
+#ifdef HAVE_TIZEN_PLATFORM
+   tpl_display_t*tpl_display;
+#endif
+
bool  is_render_node;
bool  is_different_gpu;
 };
@@ -320,6 +332,13 @@ struct dri2_egl_surface
struct ANativeWindowBuffer *buffer;
 #endif
 
+#ifdef HAVE_TIZEN_PLATFORM
+   void  *native_win;
+   tpl_surface_t *tpl_surface;
+   tbm_surface_h  tbm_surface;
+   tbm_format tbm_format;
+#endif
+
 #if defined(HAVE_SURFACELESS_PLATFORM)
   __DRIimage   *front;
   unsigned int visual;
@@ -417,6 +436,9 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
 EGLBoolean
 dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
 
+EGLBoolean
+dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *disp);
+
 EGLBoolean
 dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp);
 
-- 
2.14.2

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


[Mesa-dev] [PATCH v2 7/8] egl: add dri2_egl_surface_get_image_front() helper (v2)

2017-10-06 Thread Gwan-gyeong Mun
To share common get and create dri_image_front code.

In preparation to adding of new platform which uses this helper.

v2:
 - Remove unneeded ifdef magic
 - Fixes from Eric's review:
   a) Split out series of refactor for helpers to a separate series.
   b) Add the new helper function and use them to replace the old code in the
  same patch.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 34 
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 src/egl/drivers/dri2/platform_android.c | 35 +
 3 files changed, 38 insertions(+), 34 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 67ae33cdc9..fd55dba7de 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1139,6 +1139,40 @@ dri2_egl_surface_destroy_image_front(struct 
dri2_egl_surface *dri2_surf)
}
 }
 
+int
+dri2_egl_surface_get_image_front(struct dri2_egl_surface *dri2_surf,
+ unsigned int format)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (dri2_surf->dri_image_front)
+  return 0;
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+  /* According current EGL spec, front buffer rendering
+   * for window surface is not supported now.
+   * and mesa doesn't have the implementation of this case.
+   * Add warning message, but not treat it as error.
+   */
+  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for 
window surface");
+   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
+  dri2_surf->dri_image_front =
+ dri2_dpy->image->createImage(dri2_dpy->dri_screen,
+  dri2_surf->base.Width,
+  dri2_surf->base.Height,
+  format,
+  0,
+  dri2_surf);
+  if (!dri2_surf->dri_image_front) {
+ _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
+ return -1;
+  }
+   }
+
+   return 0;
+}
+
 /**
  * Called via eglTerminate(), drv->API.Terminate().
  *
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 83b9e368b2..0f4ef763bd 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -478,6 +478,9 @@ dri2_egl_surface_destroy_image_back(struct dri2_egl_surface 
*dri2_surf);
 void
 dri2_egl_surface_destroy_image_front(struct dri2_egl_surface *dri2_surf);
 
+int
+dri2_egl_surface_get_image_front(struct dri2_egl_surface *dri2_surf,
+ unsigned int format);
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
 _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean 
enable_out_fence);
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index c98802774c..ef55a6d085 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -388,39 +388,6 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
return 0;
 }
 
-static int
-get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)
-{
-   struct dri2_egl_display *dri2_dpy =
-  dri2_egl_display(dri2_surf->base.Resource.Display);
-
-   if (dri2_surf->dri_image_front)
-  return 0;
-
-   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
-  /* According current EGL spec, front buffer rendering
-   * for window surface is not supported now.
-   * and mesa doesn't have the implementation of this case.
-   * Add warning message, but not treat it as error.
-   */
-  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for 
window surface");
-   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
-  dri2_surf->dri_image_front =
-  dri2_dpy->image->createImage(dri2_dpy->dri_screen,
-  dri2_surf->base.Width,
-  dri2_surf->base.Height,
-  format,
-  0,
-  dri2_surf);
-  if (!dri2_surf->dri_image_front) {
- _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
- return -1;
-  }
-   }
-
-   return 0;
-}
-
 static int
 get_back_bo(struct dri2_egl_surface *dri2_surf)
 {
@@ -512,7 +479,7 @@ droid_image_get_buffers(__DRIdrawable *driDrawable,
   return 0;
 
if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) {
-  if (get_front_bo(dri2_surf, format) < 0)
+  if (dri2_egl_surface_get_image_front(dri2_surf, format) < 0)
  return 0;
 
   if (dri2_surf->dri_image_front) {
-- 
2.14.2

___

[Mesa-dev] [PATCH v2 6/8] egl: add dri2_egl_surface_destroy_image_front() helper (v2)

2017-10-06 Thread Gwan-gyeong Mun
To share common destroy dri_image_front code.

In preparation to adding of new platform which uses this helper.

v2:
 - Move dri_image_front to outside of android ifdef block for removing of
   ifdef magic on dri2_egl_surface_destroy_image_front().
 - Fixes from Eric's review:
   a) Split out series of refactor for helpers to a separate series.
   b) Add the new helper function and use them to replace the old code in the
  same patch.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 12 
 src/egl/drivers/dri2/egl_dri2.h |  5 -
 src/egl/drivers/dri2/platform_android.c |  7 +--
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index bb4944358d..67ae33cdc9 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1127,6 +1127,18 @@ dri2_egl_surface_destroy_image_back(struct 
dri2_egl_surface *dri2_surf)
}
 }
 
+void
+dri2_egl_surface_destroy_image_front(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (dri2_surf->dri_image_front) {
+  dri2_dpy->image->destroyImage(dri2_surf->dri_image_front);
+  dri2_surf->dri_image_front = NULL;
+   }
+}
+
 /**
  * Called via eglTerminate(), drv->API.Terminate().
  *
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 165749ebb1..83b9e368b2 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -313,11 +313,11 @@ struct dri2_egl_surface
} color_buffers[COLOR_BUFFERS_SIZE], *back, *current;
 
__DRIimage *dri_image_back;
+   __DRIimage *dri_image_front;
 
 #ifdef HAVE_ANDROID_PLATFORM
struct ANativeWindow *window;
struct ANativeWindowBuffer *buffer;
-   __DRIimage *dri_image_front;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
@@ -475,6 +475,9 @@ dri2_egl_surface_update_buffer_age(struct dri2_egl_surface 
*dri2_surf);
 void
 dri2_egl_surface_destroy_image_back(struct dri2_egl_surface *dri2_surf);
 
+void
+dri2_egl_surface_destroy_image_front(struct dri2_egl_surface *dri2_surf);
+
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
 _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean 
enable_out_fence);
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index 421395b5d7..c98802774c 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -354,12 +354,7 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
}
 
dri2_egl_surface_destroy_image_back(dri2_surf);
-
-   if (dri2_surf->dri_image_front) {
-  _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, 
__LINE__);
-  dri2_dpy->image->destroyImage(dri2_surf->dri_image_front);
-  dri2_surf->dri_image_front = NULL;
-   }
+   dri2_egl_surface_destroy_image_front(dri2_surf);
 
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
-- 
2.14.2

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


[Mesa-dev] [PATCH v2 8/8] egl/wayland: add dri2_wl_free_buffers() helper

2017-10-06 Thread Gwan-gyeong Mun
This deduplicates free routines of color_buffers array.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_wayland.c | 60 +
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index 1518a24b7c..cfe474cf58 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -253,6 +253,35 @@ dri2_wl_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay 
*disp,
return NULL;
 }
 
+static void
+dri2_wl_free_buffers(struct dri2_egl_surface *dri2_surf, bool check_lock)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  if (dri2_surf->color_buffers[i].native_buffer) {
+ if (check_lock && !dri2_surf->color_buffers[i].locked)
+wl_buffer_destroy((struct wl_buffer 
*)dri2_surf->color_buffers[i].native_buffer);
+ else
+wl_buffer_destroy((struct wl_buffer 
*)dri2_surf->color_buffers[i].native_buffer);
+  }
+  if (dri2_surf->color_buffers[i].dri_image)
+ dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].dri_image);
+  if (dri2_surf->color_buffers[i].linear_copy)
+ 
dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].linear_copy);
+  if (dri2_surf->color_buffers[i].data)
+ munmap(dri2_surf->color_buffers[i].data,
+dri2_surf->color_buffers[i].data_size);
+
+  dri2_surf->color_buffers[i].native_buffer = NULL;
+  dri2_surf->color_buffers[i].dri_image = NULL;
+  dri2_surf->color_buffers[i].linear_copy = NULL;
+  dri2_surf->color_buffers[i].data = NULL;
+  dri2_surf->color_buffers[i].locked = false;
+   }
+}
+
 /**
  * Called via eglDestroySurface(), drv->API.DestroySurface().
  */
@@ -266,17 +295,7 @@ dri2_wl_destroy_surface(_EGLDriver *drv, _EGLDisplay 
*disp, _EGLSurface *surf)
 
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (dri2_surf->color_buffers[i].native_buffer)
- wl_buffer_destroy((struct wl_buffer 
*)dri2_surf->color_buffers[i].native_buffer);
-  if (dri2_surf->color_buffers[i].dri_image)
- dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].dri_image);
-  if (dri2_surf->color_buffers[i].linear_copy)
- 
dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].linear_copy);
-  if (dri2_surf->color_buffers[i].data)
- munmap(dri2_surf->color_buffers[i].data,
-dri2_surf->color_buffers[i].data_size);
-   }
+   dri2_wl_free_buffers(dri2_surf, false);
 
if (dri2_dpy->dri2)
   dri2_egl_surface_free_local_buffers(dri2_surf);
@@ -308,24 +327,7 @@ dri2_wl_release_buffers(struct dri2_egl_surface *dri2_surf)
struct dri2_egl_display *dri2_dpy =
   dri2_egl_display(dri2_surf->base.Resource.Display);
 
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (dri2_surf->color_buffers[i].native_buffer &&
-  !dri2_surf->color_buffers[i].locked)
- wl_buffer_destroy((struct wl_buffer 
*)dri2_surf->color_buffers[i].native_buffer);
-  if (dri2_surf->color_buffers[i].dri_image)
- dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].dri_image);
-  if (dri2_surf->color_buffers[i].linear_copy)
- 
dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].linear_copy);
-  if (dri2_surf->color_buffers[i].data)
- munmap(dri2_surf->color_buffers[i].data,
-dri2_surf->color_buffers[i].data_size);
-
-  dri2_surf->color_buffers[i].native_buffer = NULL;
-  dri2_surf->color_buffers[i].dri_image = NULL;
-  dri2_surf->color_buffers[i].linear_copy = NULL;
-  dri2_surf->color_buffers[i].data = NULL;
-  dri2_surf->color_buffers[i].locked = false;
-   }
+   dri2_wl_free_buffers(dri2_surf, true);
 
if (dri2_dpy->dri2)
   dri2_egl_surface_free_local_buffers(dri2_surf);
-- 
2.14.2

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


[Mesa-dev] [PATCH v2 5/8] egl: add dri2_egl_surface_destroy_image_back() helper (v2)

2017-10-06 Thread Gwan-gyeong Mun
To share common destroy dri_image_back code.

In preparation to adding of new platform which uses this helper.

v2:
 - Move dri_image_back to outside of android ifdef block for removing of
   ifdef magic on dri2_egl_surface_destroy_image_back().
 - Fixes from Eric's review:
   a) Split out series of refactor for helpers to a separate series.
   b) Add the new helper function and use them to replace the old code in the
  same patch.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 12 
 src/egl/drivers/dri2/egl_dri2.h |  6 +-
 src/egl/drivers/dri2/platform_android.c | 11 ++-
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index a0f58ca8e4..bb4944358d 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1115,6 +1115,18 @@ dri2_egl_surface_update_buffer_age(struct 
dri2_egl_surface *dri2_surf)
   dri2_surf->back->age = 1;
 }
 
+void
+dri2_egl_surface_destroy_image_back(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (dri2_surf->dri_image_back) {
+  dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
+  dri2_surf->dri_image_back = NULL;
+   }
+}
+
 /**
  * Called via eglTerminate(), drv->API.Terminate().
  *
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index fe3880ef89..165749ebb1 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -312,10 +312,11 @@ struct dri2_egl_surface
   int age;
} color_buffers[COLOR_BUFFERS_SIZE], *back, *current;
 
+   __DRIimage *dri_image_back;
+
 #ifdef HAVE_ANDROID_PLATFORM
struct ANativeWindow *window;
struct ANativeWindowBuffer *buffer;
-   __DRIimage *dri_image_back;
__DRIimage *dri_image_front;
 #endif
 
@@ -471,6 +472,9 @@ 
dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface *
 void
 dri2_egl_surface_update_buffer_age(struct dri2_egl_surface *dri2_surf);
 
+void
+dri2_egl_surface_destroy_image_back(struct dri2_egl_surface *dri2_surf);
+
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
 _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean 
enable_out_fence);
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index 29ee12b140..421395b5d7 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -229,10 +229,7 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct 
dri2_egl_surface *dri2_sur
 
mtx_lock(>Mutex);
 
-   if (dri2_surf->dri_image_back) {
-  dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
-  dri2_surf->dri_image_back = NULL;
-   }
+   dri2_egl_surface_destroy_image_back(dri2_surf);
 
return EGL_TRUE;
 }
@@ -356,11 +353,7 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
   dri2_surf->window->common.decRef(_surf->window->common);
}
 
-   if (dri2_surf->dri_image_back) {
-  _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_back", __func__, 
__LINE__);
-  dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
-  dri2_surf->dri_image_back = NULL;
-   }
+   dri2_egl_surface_destroy_image_back(dri2_surf);
 
if (dri2_surf->dri_image_front) {
   _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, 
__LINE__);
-- 
2.14.2

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


[Mesa-dev] [PATCH v2 2/8] egl: refactor color_buffers structure for deduplicating

2017-10-06 Thread Gwan-gyeong Mun
This is added for preventing adding of new color buffers structure and back*
when new platform backend is added.
This refactoring separates out the common and platform specific bits.
This makes odd casting in the platform_foo.c but it prevents adding of new
ifdef magic.
Because of color_buffers array size is different on android and wayland /drm,
it adds COLOR_BUFFERS_SIZE macro.
 - android's color buffers array size is 3.
   drm & wayland's color buffers array size is 4.

Fixes from Rob's review:
 - refactor to separate out the common and platform specific bits.

Fixes from Emil's review:
 - use suggested color buffers structure shape.
   it makes a buffer pointer of each platform to void pointer type.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.h | 30 +-
 src/egl/drivers/dri2/platform_android.c | 10 +++---
 src/egl/drivers/dri2/platform_drm.c | 55 +
 src/egl/drivers/dri2/platform_wayland.c | 46 +--
 4 files changed, 71 insertions(+), 70 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 017895f0d9..08ccf24410 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -65,6 +65,15 @@ struct zwp_linux_dmabuf_v1;
 
 #endif /* HAVE_ANDROID_PLATFORM */
 
+#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
+#define COLOR_BUFFERS_SIZE 4
+#else
+   /* Usually Android uses at most triple buffers in ANativeWindow
+* so hardcode the number of color_buffers to 3.
+*/
+#define COLOR_BUFFERS_SIZE 3
+#endif
+
 #include "eglconfig.h"
 #include "eglcontext.h"
 #include "egldisplay.h"
@@ -286,39 +295,28 @@ struct dri2_egl_surface
/* EGL-owned buffers */
__DRIbuffer   *local_buffers[__DRI_BUFFER_COUNT];
 
-#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
+   /* Used to record all the buffers created by each platform's native window
+* and their ages.
+*/
struct {
+  void *native_buffer; // aka wl_buffer/gbm_bo/ANativeWindowBuffer
 #ifdef HAVE_WAYLAND_PLATFORM
-  struct wl_buffer   *wl_buffer;
   __DRIimage *dri_image;
   /* for is_different_gpu case. NULL else */
   __DRIimage *linear_copy;
   /* for swrast */
   void *data;
   int data_size;
-#endif
-#ifdef HAVE_DRM_PLATFORM
-  struct gbm_bo   *bo;
 #endif
   boollocked;
   int age;
-   } color_buffers[4], *back, *current;
-#endif
+   } color_buffers[COLOR_BUFFERS_SIZE], *back, *current;
 
 #ifdef HAVE_ANDROID_PLATFORM
struct ANativeWindow *window;
struct ANativeWindowBuffer *buffer;
__DRIimage *dri_image_back;
__DRIimage *dri_image_front;
-
-   /* Used to record all the buffers created by ANativeWindow and their ages.
-* Usually Android uses at most triple buffers in ANativeWindow
-* so hardcode the number of color_buffers to 3.
-*/
-   struct {
-  struct ANativeWindowBuffer *buffer;
-  int age;
-   } color_buffers[3], *back;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index 0acbb38bd8..67e739c1fc 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -193,10 +193,10 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
 */
EGLBoolean updated = EGL_FALSE;
for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (!dri2_surf->color_buffers[i].buffer) {
- dri2_surf->color_buffers[i].buffer = dri2_surf->buffer;
+  if (!dri2_surf->color_buffers[i].native_buffer) {
+ dri2_surf->color_buffers[i].native_buffer = (void *)dri2_surf->buffer;
   }
-  if (dri2_surf->color_buffers[i].buffer == dri2_surf->buffer) {
+  if (dri2_surf->color_buffers[i].native_buffer == (void 
*)dri2_surf->buffer) {
  dri2_surf->back = _surf->color_buffers[i];
  updated = EGL_TRUE;
  break;
@@ -208,10 +208,10 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
* the color_buffers
*/
   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
- dri2_surf->color_buffers[i].buffer = NULL;
+ dri2_surf->color_buffers[i].native_buffer = NULL;
  dri2_surf->color_buffers[i].age = 0;
   }
-  dri2_surf->color_buffers[0].buffer = dri2_surf->buffer;
+  dri2_surf->color_buffers[0].native_buffer = (void *)dri2_surf->buffer;
   dri2_surf->back = _surf->color_buffers[0];
}
 
diff --git a/src/egl/drivers/dri2/platform_drm.c 
b/src/egl/drivers/dri2/platform_drm.c
index 9005f5dd9e..3527352bab 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -53,7 +53,7 @@ lock_front_buffer(struct gbm_surface *_surf)
   return NULL;
}
 
-   bo = 

[Mesa-dev] [PATCH v2 4/8] egl: add dri2_egl_surface_update_buffer_age() helper (v2)

2017-10-06 Thread Gwan-gyeong Mun
To share common update buffer age code.
This updates old buffer's age and sets current back buffer's age to 1.

In preparation to adding of new platform which uses this helper.

v2:
 - Fixes from Eric's review:
   a) Split out series of refactor for helpers to a separate series.
   b) Add the new helper function and use them to replace the old code in the
  same patch.
 - Fixes from Rob's review:
   Remove unneeded ifdef block

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 15 +++
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 src/egl/drivers/dri2/platform_android.c | 11 +--
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 3622d18a24..a0f58ca8e4 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1100,6 +1100,21 @@ 
dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface *
}
 }
 
+void
+dri2_egl_surface_update_buffer_age(struct dri2_egl_surface *dri2_surf)
+{
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  if (dri2_surf->color_buffers[i].age > 0)
+ dri2_surf->color_buffers[i].age++;
+   }
+
+   /* "XXX: we don't use get_back_bo() since it causes regressions in
+* several dEQP tests.
+*/
+   if (dri2_surf->back)
+  dri2_surf->back->age = 1;
+}
+
 /**
  * Called via eglTerminate(), drv->API.Terminate().
  *
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 67d7b7f863..fe3880ef89 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -468,6 +468,9 @@ void
 dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface 
*dri2_surf,
void *buffer);
 
+void
+dri2_egl_surface_update_buffer_age(struct dri2_egl_surface *dri2_surf);
+
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
 _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean 
enable_out_fence);
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index 202db9a883..29ee12b140 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -569,16 +569,7 @@ droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *draw)
if (dri2_surf->base.Type != EGL_WINDOW_BIT)
   return EGL_TRUE;
 
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (dri2_surf->color_buffers[i].age > 0)
- dri2_surf->color_buffers[i].age++;
-   }
-
-   /* "XXX: we don't use get_back_bo() since it causes regressions in
-* several dEQP tests.
-*/
-   if (dri2_surf->back)
-  dri2_surf->back->age = 1;
+   dri2_egl_surface_update_buffer_age(dri2_surf);
 
dri2_flush_drawable_for_swapbuffers(disp, draw);
 
-- 
2.14.2

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


[Mesa-dev] [PATCH v2 3/8] egl: add dri2_egl_surface_record_buffers_and_update_back_buffer() helper (v2)

2017-10-06 Thread Gwan-gyeong Mun
To share common record buffers and update back buffer code.
This records all the buffers created by each platform's native window and
update back buffer for updating buffer's age in swap_buffers.

In preparation to adding of new platform which uses this helper.

v2:
 - Remove unnedded ifdef magic
 - Fixes from Eric's review:
   a) Split out series of refactor for helpers to a separate series.
   b) Add the new helper function and use them to replace the old code in the
  same patch.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 32 
 src/egl/drivers/dri2/egl_dri2.h |  5 +
 src/egl/drivers/dri2/platform_android.c | 25 ++---
 3 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 3c4e525040..3622d18a24 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1068,6 +1068,38 @@ 
dri2_egl_surface_free_outdated_buffers_and_update_size(struct dri2_egl_surface *
}
 }
 
+void
+dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface 
*dri2_surf,
+   void *buffer)
+{
+   /* Record all the buffers created by each platform's native window and
+* update back buffer for updating buffer's age in swap_buffers.
+*/
+   EGLBoolean updated = EGL_FALSE;
+
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  if (!dri2_surf->color_buffers[i].native_buffer) {
+ dri2_surf->color_buffers[i].native_buffer = buffer;
+ dri2_surf->color_buffers[i].age = 0;
+  }
+  if (dri2_surf->color_buffers[i].native_buffer == buffer) {
+ dri2_surf->back = _surf->color_buffers[i];
+ updated = EGL_TRUE;
+ break;
+  }
+   }
+
+   if (!updated) {
+  /* In case of all the buffers were recreated, reset the color_buffers */
+  for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+ dri2_surf->color_buffers[i].native_buffer = NULL;
+ dri2_surf->color_buffers[i].age = 0;
+  }
+  dri2_surf->color_buffers[0].native_buffer = buffer;
+  dri2_surf->back = _surf->color_buffers[0];
+   }
+}
+
 /**
  * Called via eglTerminate(), drv->API.Terminate().
  *
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 08ccf24410..67d7b7f863 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -463,6 +463,11 @@ dri2_egl_surface_free_local_buffers(struct 
dri2_egl_surface *dri2_surf);
 void
 dri2_egl_surface_free_outdated_buffers_and_update_size(struct dri2_egl_surface 
*dri2_surf,
int width, int height);
+
+void
+dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface 
*dri2_surf,
+   void *buffer);
+
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
 _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean 
enable_out_fence);
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index 67e739c1fc..202db9a883 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -191,29 +191,8 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
/* Record all the buffers created by ANativeWindow and update back buffer
 * for updating buffer's age in swap_buffers.
 */
-   EGLBoolean updated = EGL_FALSE;
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (!dri2_surf->color_buffers[i].native_buffer) {
- dri2_surf->color_buffers[i].native_buffer = (void *)dri2_surf->buffer;
-  }
-  if (dri2_surf->color_buffers[i].native_buffer == (void 
*)dri2_surf->buffer) {
- dri2_surf->back = _surf->color_buffers[i];
- updated = EGL_TRUE;
- break;
-  }
-   }
-
-   if (!updated) {
-  /* In case of all the buffers were recreated by ANativeWindow, reset
-   * the color_buffers
-   */
-  for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
- dri2_surf->color_buffers[i].native_buffer = NULL;
- dri2_surf->color_buffers[i].age = 0;
-  }
-  dri2_surf->color_buffers[0].native_buffer = (void *)dri2_surf->buffer;
-  dri2_surf->back = _surf->color_buffers[0];
-   }
+   dri2_egl_surface_record_buffers_and_update_back_buffer(dri2_surf,
+  (void 
*)dri2_surf->buffer);
 
return EGL_TRUE;
 }
-- 
2.14.2

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


[Mesa-dev] [PATCH v2 1/8] egl: add dri2_egl_surface_free_outdated_buffers_and_update_size() helper (v2)

2017-10-06 Thread Gwan-gyeong Mun
To share common free outdated buffers and update size code.
This compares width and height arguments with current egl surface dimension,
if the compared surface dimension is differ, then it free local buffers and
updates dimension.

In preparation to adding of new platform which uses this helper.

v2: Fixes from Eric's review:
   a) Split out series of refactor for helpers to a separate series.
   b) Add the new helper function and use them to replace the old code in the
  same patch.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 12 
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 src/egl/drivers/dri2/platform_android.c |  9 +++--
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 0db80a091f..3c4e525040 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1056,6 +1056,18 @@ dri2_egl_surface_free_local_buffers(struct 
dri2_egl_surface *dri2_surf)
}
 }
 
+void
+dri2_egl_surface_free_outdated_buffers_and_update_size(struct dri2_egl_surface 
*dri2_surf,
+   int width, int height)
+{
+   /* free outdated buffers and update the surface size */
+   if (dri2_surf->base.Width != width || dri2_surf->base.Height != height) {
+  dri2_egl_surface_free_local_buffers(dri2_surf);
+  dri2_surf->base.Width = width;
+  dri2_surf->base.Height = height;
+   }
+}
+
 /**
  * Called via eglTerminate(), drv->API.Terminate().
  *
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index e3bdbb55f5..017895f0d9 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -462,6 +462,9 @@ dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface 
*dri2_surf,
 void
 dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf);
 
+void
+dri2_egl_surface_free_outdated_buffers_and_update_size(struct dri2_egl_surface 
*dri2_surf,
+   int width, int height);
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
 _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean 
enable_out_fence);
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index e390365b8b..0acbb38bd8 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -414,12 +414,9 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
}
 
/* free outdated buffers and update the surface size */
-   if (dri2_surf->base.Width != dri2_surf->buffer->width ||
-   dri2_surf->base.Height != dri2_surf->buffer->height) {
-  dri2_egl_surface_free_local_buffers(dri2_surf);
-  dri2_surf->base.Width = dri2_surf->buffer->width;
-  dri2_surf->base.Height = dri2_surf->buffer->height;
-   }
+   dri2_egl_surface_free_outdated_buffers_and_update_size(dri2_surf,
+  
dri2_surf->buffer->width,
+  
dri2_surf->buffer->height);
 
return 0;
 }
-- 
2.14.2

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


Re: [Mesa-dev] [PATCH 1/6] gallium: clarify the constraints on sampler_view_destroy

2017-10-06 Thread Nicolai Hähnle
FWIW, the drivers that really are affected currently are SVGA and 
possibly virgl, because they pass Gallium calls on to a supervisor. 
Since we guarantee that the creation context is still alive, those 
drivers could fix any issues by adding samplers that are destroyed from 
a different context to an "orphan" list which is regularly cleaned up by 
the creating context.


Cheers,
Nicolai

On 06.10.2017 22:38, Nicolai Hähnle wrote:

From: Nicolai Hähnle 

r600 expects the context that created the sampler view to still be alive
(there is a per-context list of sampler views).

svga currently bails when the context of destruction is not the same as
creation.

The GL state tracker, which is the only one that runs into the
multi-context subtleties (due to share groups), already guarantees that
sampler views are destroyed before their context of creation is destroyed.

Most drivers are context-agnostic, so the warning message in
pipe_sampler_view_release doesn't really make sense.
---
  src/gallium/auxiliary/util/u_inlines.h   | 16 ++--
  src/gallium/include/pipe/p_context.h | 10 ++
  src/mesa/state_tracker/st_sampler_view.c |  1 -
  3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_inlines.h 
b/src/gallium/auxiliary/util/u_inlines.h
index 79f62c32266..790352d7800 100644
--- a/src/gallium/auxiliary/util/u_inlines.h
+++ b/src/gallium/auxiliary/util/u_inlines.h
@@ -142,45 +142,49 @@ pipe_resource_reference(struct pipe_resource **ptr, 
struct pipe_resource *tex)
   struct pipe_resource *next = old_tex->next;
  
   old_tex->screen->resource_destroy(old_tex->screen, old_tex);

   old_tex = next;
} while (pipe_reference_described(_tex->reference, NULL,
  
(debug_reference_descriptor)debug_describe_resource));
 }
 *ptr = tex;
  }
  
+/**

+ * Set *ptr to \p view with proper reference counting.
+ *
+ * The caller must guarantee that \p view and *ptr must have been created in
+ * the same context (if they exist), and that this must be the current context.
+ */
  static inline void
  pipe_sampler_view_reference(struct pipe_sampler_view **ptr, struct 
pipe_sampler_view *view)
  {
 struct pipe_sampler_view *old_view = *ptr;
  
 if (pipe_reference_described(&(*ptr)->reference, >reference,

  
(debug_reference_descriptor)debug_describe_sampler_view))
old_view->context->sampler_view_destroy(old_view->context, old_view);
 *ptr = view;
  }
  
  /**

   * Similar to pipe_sampler_view_reference() but always set the pointer to
- * NULL and pass in an explicit context.  Passing an explicit context is a
- * work-around for fixing a dangling context pointer problem when textures
- * are shared by multiple contexts.  XXX fix this someday.
+ * NULL and pass in the current context explicitly.
+ *
+ * If *ptr is non-NULL, it may refer to a view that was created in a different
+ * context (however, that context must still be alive).
   */
  static inline void
  pipe_sampler_view_release(struct pipe_context *ctx,
struct pipe_sampler_view **ptr)
  {
 struct pipe_sampler_view *old_view = *ptr;
-   if (*ptr && (*ptr)->context != ctx) {
-  debug_printf_once(("context mis-match in 
pipe_sampler_view_release()\n"));
-   }
 if (pipe_reference_described(&(*ptr)->reference, NULL,
  (debug_reference_descriptor)debug_describe_sampler_view)) 
{
ctx->sampler_view_destroy(ctx, old_view);
 }
 *ptr = NULL;
  }
  
  static inline void

  pipe_so_target_reference(struct pipe_stream_output_target **ptr,
   struct pipe_stream_output_target *target)
diff --git a/src/gallium/include/pipe/p_context.h 
b/src/gallium/include/pipe/p_context.h
index 4609d4dbf23..087836d1c0c 100644
--- a/src/gallium/include/pipe/p_context.h
+++ b/src/gallium/include/pipe/p_context.h
@@ -501,20 +501,30 @@ struct pipe_context {
 void (*fence_server_sync)(struct pipe_context *pipe,
   struct pipe_fence_handle *fence);
  
 /**

  * Create a view on a texture to be used by a shader stage.
  */
 struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx,
   struct pipe_resource 
*texture,
   const struct 
pipe_sampler_view *templat);
  
+   /**

+* Destroy a view on a texture.
+*
+* \param ctx the current context
+* \param view the view to be destroyed
+*
+* \note The current context may not be the context in which the view was
+*   created (view->context). However, the caller must guarantee that
+*   the context which created the view is still alive.
+*/
 void (*sampler_view_destroy)(struct pipe_context *ctx,
  struct 

[Mesa-dev] [PATCH 2/3] st/mesa: use PIPE_FORMAT_A1B5G5R5_UNORM when requested

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

This affects dEQP-EGL.functional.image.modify.tex_rgb5_a1_tex_subimage_rgba8,
which implicitly tests that GLES really creates a 5551 texture when
GL_UNSIGNED_SHORT_5_5_5_1 is passed as type parameter to glTexImage*()
functions.
---
 src/mesa/state_tracker/st_format.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/mesa/state_tracker/st_format.c 
b/src/mesa/state_tracker/st_format.c
index 5e38fe56890..08a2908b1f0 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -402,20 +402,22 @@ st_mesa_format_to_pipe_format(const struct st_context 
*st, mesa_format mesaForma
   return PIPE_FORMAT_R11G11B10_FLOAT;
case MESA_FORMAT_B10G10R10A2_UINT:
   return PIPE_FORMAT_B10G10R10A2_UINT;
case MESA_FORMAT_R10G10B10A2_UINT:
   return PIPE_FORMAT_R10G10B10A2_UINT;
 
case MESA_FORMAT_B4G4R4X4_UNORM:
   return PIPE_FORMAT_B4G4R4X4_UNORM;
case MESA_FORMAT_B5G5R5X1_UNORM:
   return PIPE_FORMAT_B5G5R5X1_UNORM;
+   case MESA_FORMAT_A1B5G5R5_UNORM:
+  return PIPE_FORMAT_A1B5G5R5_UNORM;
case MESA_FORMAT_R8G8B8X8_SNORM:
   return PIPE_FORMAT_RGBX_SNORM;
case MESA_FORMAT_X8B8G8R8_SNORM:
   return PIPE_FORMAT_XBGR_SNORM;
case MESA_FORMAT_R8G8B8X8_SRGB:
   return PIPE_FORMAT_RGBX_SRGB;
case MESA_FORMAT_X8B8G8R8_SRGB:
   return PIPE_FORMAT_XBGR_SRGB;
case MESA_FORMAT_RGBX_UINT8:
   return PIPE_FORMAT_R8G8B8X8_UINT;
@@ -883,20 +885,22 @@ st_pipe_format_to_mesa_format(enum pipe_format format)
 
case PIPE_FORMAT_B10G10R10A2_UINT:
   return MESA_FORMAT_B10G10R10A2_UINT;
case PIPE_FORMAT_R10G10B10A2_UINT:
   return MESA_FORMAT_R10G10B10A2_UINT;
 
case PIPE_FORMAT_B4G4R4X4_UNORM:
   return MESA_FORMAT_B4G4R4X4_UNORM;
case PIPE_FORMAT_B5G5R5X1_UNORM:
   return MESA_FORMAT_B5G5R5X1_UNORM;
+   case PIPE_FORMAT_A1B5G5R5_UNORM:
+  return MESA_FORMAT_A1B5G5R5_UNORM;
case PIPE_FORMAT_RGBX_SNORM:
   return MESA_FORMAT_R8G8B8X8_SNORM;
case PIPE_FORMAT_XBGR_SNORM:
   return MESA_FORMAT_X8B8G8R8_SNORM;
case PIPE_FORMAT_RGBX_SRGB:
   return MESA_FORMAT_R8G8B8X8_SRGB;
case PIPE_FORMAT_XBGR_SRGB:
   return MESA_FORMAT_X8B8G8R8_SRGB;
case PIPE_FORMAT_R8G8B8X8_UINT:
   return MESA_FORMAT_RGBX_UINT8;
-- 
2.11.0

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


[Mesa-dev] [PATCH 1/3] gallium: add PIPE_FORMAT_A1B5G5R5_UNORM format

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

This matches the GL_UNSIGNED_SHORT_5_5_5_1 type.
---
 src/gallium/auxiliary/util/u_format.csv | 1 +
 src/gallium/auxiliary/util/u_format_tests.c | 7 +++
 src/gallium/drivers/svga/svga_format.c  | 1 +
 src/gallium/include/pipe/p_format.h | 1 +
 4 files changed, 10 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_format.csv 
b/src/gallium/auxiliary/util/u_format.csv
index be86acca9bd..252e8b21578 100644
--- a/src/gallium/auxiliary/util/u_format.csv
+++ b/src/gallium/auxiliary/util/u_format.csv
@@ -67,20 +67,21 @@ PIPE_FORMAT_NONE  , plain, 1, 1, u8  , 
, , , x001, r
 PIPE_FORMAT_B8G8R8A8_UNORM, plain, 1, 1, un8 , un8 , un8 , un8 , zyxw, 
rgb
 PIPE_FORMAT_B8G8R8X8_UNORM, plain, 1, 1, un8 , un8 , un8 , x8  , zyx1, 
rgb
 PIPE_FORMAT_A8R8G8B8_UNORM, plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, 
rgb
 PIPE_FORMAT_X8R8G8B8_UNORM, plain, 1, 1, x8  , un8 , un8 , un8 , yzw1, 
rgb
 PIPE_FORMAT_A8B8G8R8_UNORM, plain, 1, 1, un8 , un8 , un8 , un8 , wzyx, 
rgb
 PIPE_FORMAT_X8B8G8R8_UNORM, plain, 1, 1, x8  , un8 , un8 , un8 , wzy1, 
rgb
 # PIPE_FORMAT_R8G8B8A8_UNORM is below
 PIPE_FORMAT_R8G8B8X8_UNORM, plain, 1, 1, un8 , un8 , un8 , x8  , xyz1, 
rgb
 PIPE_FORMAT_B5G5R5X1_UNORM, plain, 1, 1, un5 , un5 , un5 , x1  , zyx1, 
rgb, x1  , un5 , un5 , un5 , yzw1
 PIPE_FORMAT_B5G5R5A1_UNORM, plain, 1, 1, un5 , un5 , un5 , un1 , zyxw, 
rgb, un1 , un5 , un5 , un5 , yzwx
+PIPE_FORMAT_A1B5G5R5_UNORM, plain, 1, 1, un1 , un5 , un5 , un5 , wzyx, 
rgb, un5 , un5 , un5 , un1 , xyzw
 PIPE_FORMAT_B4G4R4A4_UNORM, plain, 1, 1, un4 , un4 , un4 , un4 , zyxw, 
rgb, un4 , un4 , un4 , un4 , yzwx
 PIPE_FORMAT_B4G4R4X4_UNORM, plain, 1, 1, un4 , un4 , un4 , x4  , zyx1, 
rgb, x4  , un4 , un4 , un4 , yzw1
 PIPE_FORMAT_B5G6R5_UNORM  , plain, 1, 1, un5 , un6 , un5 , , zyx1, 
rgb, un5 , un6 , un5 , , xyz1
 PIPE_FORMAT_R10G10B10A2_UNORM , plain, 1, 1, un10, un10, un10, un2 , xyzw, 
rgb, un2 , un10, un10, un10, wzyx
 PIPE_FORMAT_R10G10B10X2_UNORM , plain, 1, 1, un10, un10, un10, x2,   xyz1, 
rgb, x2  , un10, un10, un10, wzy1
 PIPE_FORMAT_B10G10R10A2_UNORM , plain, 1, 1, un10, un10, un10, un2 , zyxw, 
rgb, un2 , un10, un10, un10, yzwx
 PIPE_FORMAT_B2G3R3_UNORM  , plain, 1, 1, un2 , un3 , un3 , , zyx1, 
rgb, un3 , un3 , un2 , , xyz1
 
 # Luminance/Intensity/Alpha formats
 PIPE_FORMAT_L8_UNORM  , plain, 1, 1, un8 , , , , xxx1, 
rgb
diff --git a/src/gallium/auxiliary/util/u_format_tests.c 
b/src/gallium/auxiliary/util/u_format_tests.c
index dbf072a01e3..b4c562cac45 100644
--- a/src/gallium/auxiliary/util/u_format_tests.c
+++ b/src/gallium/auxiliary/util/u_format_tests.c
@@ -163,20 +163,27 @@ util_format_test_cases[] =
{PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x7c00), 
UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)},
{PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x7fff), 
UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)},
 
{PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0x), PACKED_1x16(0x), 
UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)},
{PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0x), PACKED_1x16(0x001f), 
UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)},
{PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0x), PACKED_1x16(0x03e0), 
UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)},
{PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0x), PACKED_1x16(0x7c00), 
UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)},
{PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0x), PACKED_1x16(0x8000), 
UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)},
{PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0x), PACKED_1x16(0x), 
UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)},
 
+   {PIPE_FORMAT_A1B5G5R5_UNORM, PACKED_1x16(0x), PACKED_1x16(0x), 
UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)},
+   {PIPE_FORMAT_A1B5G5R5_UNORM, PACKED_1x16(0x), PACKED_1x16(0x003e), 
UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)},
+   {PIPE_FORMAT_A1B5G5R5_UNORM, PACKED_1x16(0x), PACKED_1x16(0x07c0), 
UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)},
+   {PIPE_FORMAT_A1B5G5R5_UNORM, PACKED_1x16(0x), PACKED_1x16(0xf800), 
UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)},
+   {PIPE_FORMAT_A1B5G5R5_UNORM, PACKED_1x16(0x), PACKED_1x16(0x0001), 
UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)},
+   {PIPE_FORMAT_A1B5G5R5_UNORM, PACKED_1x16(0x), PACKED_1x16(0x), 
UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)},
+
{PIPE_FORMAT_B4G4R4X4_UNORM, PACKED_1x16(0x0fff), PACKED_1x16(0x), 
UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)},
{PIPE_FORMAT_B4G4R4X4_UNORM, PACKED_1x16(0x0fff), PACKED_1x16(0x000f), 
UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)},
{PIPE_FORMAT_B4G4R4X4_UNORM, PACKED_1x16(0x0fff), PACKED_1x16(0x00f0), 
UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)},
{PIPE_FORMAT_B4G4R4X4_UNORM, PACKED_1x16(0x0fff), PACKED_1x16(0x0f00), 
UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)},
{PIPE_FORMAT_B4G4R4X4_UNORM, PACKED_1x16(0x0fff), PACKED_1x16(0x0fff), 
UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)},
 

[Mesa-dev] [PATCH 3/3] radeonsi: add support for PIPE_FORMAT_A1R5G5B5_UNORM

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

Fixes dEQP-EGL.functional.image.modify.tex_rgb5_a1_tex_subimage_rgba8
---
 src/gallium/drivers/radeonsi/si_state.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/src/gallium/drivers/radeonsi/si_state.c 
b/src/gallium/drivers/radeonsi/si_state.c
index 99c3ca36886..a86a3a83217 100644
--- a/src/gallium/drivers/radeonsi/si_state.c
+++ b/src/gallium/drivers/radeonsi/si_state.c
@@ -1499,20 +1499,22 @@ static uint32_t si_translate_colorformat(enum 
pipe_format format)
return V_028C70_COLOR_4_4_4_4;
case 8:
return V_028C70_COLOR_8_8_8_8;
case 16:
return V_028C70_COLOR_16_16_16_16;
case 32:
return V_028C70_COLOR_32_32_32_32;
}
} else if (HAS_SIZE(5,5,5,1)) {
return V_028C70_COLOR_1_5_5_5;
+   } else if (HAS_SIZE(1,5,5,5)) {
+   return V_028C70_COLOR_5_5_5_1;
} else if (HAS_SIZE(10,10,10,2)) {
return V_028C70_COLOR_2_10_10_10;
}
break;
}
return V_028C70_COLOR_INVALID;
 }
 
 static uint32_t si_colorformat_endian_swap(uint32_t colorformat)
 {
@@ -1757,20 +1759,26 @@ static uint32_t si_translate_texformat(struct 
pipe_screen *screen,
return V_008F14_IMG_DATA_FORMAT_5_6_5;
}
goto out_unknown;
case 4:
if (desc->channel[0].size == 5 &&
desc->channel[1].size == 5 &&
desc->channel[2].size == 5 &&
desc->channel[3].size == 1) {
return V_008F14_IMG_DATA_FORMAT_1_5_5_5;
}
+   if (desc->channel[0].size == 1 &&
+   desc->channel[1].size == 5 &&
+   desc->channel[2].size == 5 &&
+   desc->channel[3].size == 5) {
+   return V_008F14_IMG_DATA_FORMAT_5_5_5_1;
+   }
if (desc->channel[0].size == 10 &&
desc->channel[1].size == 10 &&
desc->channel[2].size == 10 &&
desc->channel[3].size == 2) {
return V_008F14_IMG_DATA_FORMAT_2_10_10_10;
}
goto out_unknown;
}
goto out_unknown;
}
-- 
2.11.0

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


[Mesa-dev] [PATCH 1/2] st/glsl_to_tgsi: ignore GL_TEXTURE_SRGB_DECODE_EXT for samplers used with texelFetch*()

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

See the comment for the relevant spec quote.

Fixes dEQP-GLES31.functional.srgb_texture_decode.skip_decode.srgba8.texel_fetch
--
Note that this is on top of the texture locking series which I have
sent out a minute ago.
---
 src/mesa/main/mtypes.h |  1 +
 src/mesa/state_tracker/st_atom_texture.c   | 39 +++---
 src/mesa/state_tracker/st_cb_texture.c |  8 +-
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  4 +++
 src/mesa/state_tracker/st_sampler_view.c   | 19 +--
 src/mesa/state_tracker/st_sampler_view.h   |  3 ++-
 src/mesa/state_tracker/st_texture.c|  7 +-
 src/mesa/state_tracker/st_texture.h|  7 +++---
 8 files changed, 71 insertions(+), 17 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index abda1a36e46..a45409ed2d9 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2081,20 +2081,21 @@ struct gl_program
 
bool is_arb_asm; /** Is this an ARB assembly-style program */
 
/** Is this program written to on disk shader cache */
bool program_written_to_cache;
 
GLbitfield64 SecondaryOutputsWritten; /**< Subset of OutputsWritten outputs 
written with non-zero index. */
GLbitfield TexturesUsed[MAX_COMBINED_TEXTURE_IMAGE_UNITS];  /**< 
TEXTURE_x_BIT bitmask */
GLbitfield SamplersUsed;   /**< Bitfield of which samplers are used */
GLbitfield ShadowSamplers; /**< Texture units used for shadow sampling. */
+   GLbitfield TexelFetchSamplers; /**< Texture units used for texelFetch*(). */
GLbitfield ExternalSamplersUsed; /**< Texture units used for 
samplerExternalOES */
 
/* Fragement shader only fields */
GLboolean OriginUpperLeft;
GLboolean PixelCenterInteger;
 
/** Named parameters, constants, etc. from program text */
struct gl_program_parameter_list *Parameters;
 
/** Map from sampler unit to texture unit (set by glUniform1i()) */
diff --git a/src/mesa/state_tracker/st_atom_texture.c 
b/src/mesa/state_tracker/st_atom_texture.c
index 90828bb4cf9..c350a098097 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -51,21 +51,22 @@
 #include "util/u_inlines.h"
 #include "cso_cache/cso_context.h"
 
 
 /**
  * Get a pipe_sampler_view object from a texture unit.
  */
 void
 st_update_single_texture(struct st_context *st,
  struct pipe_sampler_view **sampler_view,
- GLuint texUnit, bool glsl130_or_later)
+ GLuint texUnit, bool glsl130_or_later,
+ bool ignore_srgb_decode)
 {
struct gl_context *ctx = st->ctx;
const struct gl_sampler_object *samp;
struct gl_texture_object *texObj;
struct st_texture_object *stObj;
 
samp = _mesa_get_samplerobj(ctx, texUnit);
 
texObj = ctx->Texture.Unit[texUnit]._Current;
assert(texObj);
@@ -83,55 +84,85 @@ st_update_single_texture(struct st_context *st,
   *sampler_view = NULL;
   return;
}
 
if (texObj->TargetIndex == TEXTURE_EXTERNAL_INDEX &&
stObj->pt->screen->resource_changed)
  stObj->pt->screen->resource_changed(stObj->pt->screen, stObj->pt);
 
*sampler_view =
   st_get_texture_sampler_view_from_stobj(st, stObj, samp,
- glsl130_or_later);
+ glsl130_or_later,
+ ignore_srgb_decode);
 }
 
 
 
 static void
 update_textures(struct st_context *st,
 enum pipe_shader_type shader_stage,
 const struct gl_program *prog,
 struct pipe_sampler_view **sampler_views,
 unsigned *out_num_textures)
 {
const GLuint old_max = *out_num_textures;
GLbitfield samplers_used = prog->SamplersUsed;
+   GLbitfield texel_fetch_samplers = prog->TexelFetchSamplers;
GLbitfield free_slots = ~prog->SamplersUsed;
GLbitfield external_samplers_used = prog->ExternalSamplersUsed;
GLuint unit;
 
if (samplers_used == 0x0 && old_max == 0)
   return;
 
unsigned num_textures = 0;
 
/* prog->sh.data is NULL if it's ARB_fragment_program */
bool glsl130 = (prog->sh.data ? prog->sh.data->Version : 0) >= 130;
 
/* loop over sampler units (aka tex image units) */
for (unit = 0; samplers_used || unit < old_max;
-unit++, samplers_used >>= 1) {
+unit++, samplers_used >>= 1, texel_fetch_samplers >>= 1) {
   struct pipe_sampler_view *sampler_view = NULL;
 
   if (samplers_used & 1) {
  const GLuint texUnit = prog->SamplerUnits[unit];
 
- st_update_single_texture(st, _view, texUnit, glsl130);
+ /* The EXT_texture_sRGB_decode extension says:
+  *
+  *"The conversion of sRGB color space components to linear color
+  * space is always performed if the texel lookup function is one
+ 

[Mesa-dev] [PATCH 2/2] st/mesa: don't assign prog->ShadowSamplers

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

It's not used, and the assignment for the TGSI case was incorrect
for sampler arrays.
---
 src/mesa/state_tracker/st_glsl_to_nir.cpp  | 1 -
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 4 
 2 files changed, 5 deletions(-)

diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp 
b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index 06a8ee8c612..5a439aaf92a 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -428,21 +428,20 @@ st_nir_get_mesa_program(struct gl_context *ctx,
 
if (ctx->_Shader->Flags & GLSL_DUMP) {
   _mesa_log("\n");
   _mesa_log("GLSL IR for linked %s program %d:\n",
  _mesa_shader_stage_to_string(shader->Stage),
  shader_program->Name);
   _mesa_print_ir(_mesa_get_log_file(), shader->ir, NULL);
   _mesa_log("\n\n");
}
 
-   prog->ShadowSamplers = shader->shadow_samplers;
prog->ExternalSamplersUsed = gl_external_samplers(prog);
_mesa_update_shader_textures_used(shader_program, prog);
 
/* Avoid reallocation of the program parameter list, because the uniform
 * storage is only associated with the original parameter list.
 * This should be enough for Bitmap and DrawPixels constants.
 */
_mesa_reserve_parameter_storage(prog->Parameters, 8);
 
/* This has to be done last.  Any operation the can cause
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 4b365c84817..1cfc9d963dc 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -4468,24 +4468,20 @@ count_resources(glsl_to_tgsi_visitor *v, gl_program 
*prog)
   if (inst->info->is_tex) {
  for (int i = 0; i < inst->sampler_array_size; i++) {
 unsigned idx = inst->sampler_base + i;
 v->samplers_used |= 1u << idx;
 
 debug_assert(idx < (int)ARRAY_SIZE(v->sampler_types));
 v->sampler_types[idx] = inst->tex_type;
 v->sampler_targets[idx] =
st_translate_texture_target(inst->tex_target, inst->tex_shadow);
 
-if (inst->tex_shadow) {
-   prog->ShadowSamplers |= 1 << (inst->resource.index + i);
-}
-
 if (inst->op == TGSI_OPCODE_TXF || inst->op == TGSI_OPCODE_TXF_LZ) 
{
prog->TexelFetchSamplers |= 1u << idx;
 }
  }
   }
 
   if (inst->tex_target == TEXTURE_EXTERNAL_INDEX)
  prog->ExternalSamplersUsed |= 1 << inst->resource.index;
 
   if (inst->resource.file != PROGRAM_UNDEFINED && (
-- 
2.11.0

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


[Mesa-dev] [PATCH 4/6] st/mesa: re-arrange st_finalize_texture

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

Move the early-out for surface-based textures earlier. This narrows the
scope of the locking added in a follow-up commit.

Fix one remaining case of initializing a surface-based texture
without properly finalizing it.
---
 src/mesa/state_tracker/st_cb_texture.c | 16 
 src/mesa/state_tracker/st_manager.c|  3 +++
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_texture.c 
b/src/mesa/state_tracker/st_cb_texture.c
index bac2a0289f5..6d9e40baa95 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -2465,50 +2465,50 @@ st_finalize_texture(struct gl_context *ctx,
* incomplete.  In that case, we'll have set stObj->lastLevel before
* we get here.
*/
   if (stObj->base.Sampler.MinFilter == GL_LINEAR ||
   stObj->base.Sampler.MinFilter == GL_NEAREST)
  stObj->lastLevel = stObj->base.BaseLevel;
   else
  stObj->lastLevel = stObj->base._MaxLevel;
}
 
-   firstImage = 
st_texture_image_const(stObj->base.Image[cubeMapFace][stObj->base.BaseLevel]);
-   assert(firstImage);
-
/* Skip the loop over images in the common case of no images having
 * changed.  But if the GL_BASE_LEVEL or GL_MAX_LEVEL change to something we
 * haven't looked at, then we do need to look at those new images.
 */
if (!stObj->needs_validation &&
stObj->base.BaseLevel >= stObj->validated_first_level &&
stObj->lastLevel <= stObj->validated_last_level) {
   return GL_TRUE;
}
 
+   /* If this texture comes from a window system, there is nothing else to do. 
*/
+   if (stObj->surface_based) {
+  return GL_TRUE;
+   }
+
+   firstImage = 
st_texture_image_const(stObj->base.Image[cubeMapFace][stObj->base.BaseLevel]);
+   assert(firstImage);
+
/* If both firstImage and stObj point to a texture which can contain
 * all active images, favour firstImage.  Note that because of the
 * completeness requirement, we know that the image dimensions
 * will match.
 */
if (firstImage->pt &&
firstImage->pt != stObj->pt &&
(!stObj->pt || firstImage->pt->last_level >= stObj->pt->last_level)) {
   pipe_resource_reference(>pt, firstImage->pt);
   st_texture_release_all_sampler_views(st, stObj);
}
 
-   /* If this texture comes from a window system, there is nothing else to do. 
*/
-   if (stObj->surface_based) {
-  return GL_TRUE;
-   }
-
/* Find gallium format for the Mesa texture */
firstImageFormat =
   st_mesa_format_to_pipe_format(st, firstImage->base.TexFormat);
 
/* Find size of level=0 Gallium mipmap image, plus number of texture layers 
*/
{
   unsigned width;
   uint16_t height, depth;
 
   st_gl_texture_dims_to_pipe_dims(stObj->base.Target,
diff --git a/src/mesa/state_tracker/st_manager.c 
b/src/mesa/state_tracker/st_manager.c
index 50bc3c33c62..c0baa4f06c2 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -41,20 +41,21 @@
 #include "util/hash_table.h"
 #include "st_texture.h"
 
 #include "st_context.h"
 #include "st_debug.h"
 #include "st_extensions.h"
 #include "st_format.h"
 #include "st_cb_fbo.h"
 #include "st_cb_flush.h"
 #include "st_manager.h"
+#include "st_sampler_view.h"
 
 #include "state_tracker/st_gl_api.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_screen.h"
 #include "util/u_format.h"
 #include "util/u_pointer.h"
 #include "util/u_inlines.h"
 #include "util/u_atomic.h"
 #include "util/u_surface.h"
@@ -725,20 +726,22 @@ st_context_teximage(struct st_context_iface *stctxi,
  if (depth != 1)
 depth <<= 1;
  level--;
   }
}
else {
   _mesa_clear_texture_image(ctx, texImage);
   width = height = depth = 0;
}
 
+   pipe_resource_reference(>pt, tex);
+   st_texture_release_all_sampler_views(st, stObj);
pipe_resource_reference(>pt, tex);
stObj->surface_format = pipe_format;
 
stObj->needs_validation = true;
 
_mesa_dirty_texobj(ctx, texObj);
_mesa_unlock_texture(ctx, texObj);
 
return TRUE;
 }
-- 
2.11.0

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


[Mesa-dev] [PATCH 0/6] st/mesa: add locking around lazy texture/sampler updates

2017-10-06 Thread Nicolai Hähnle
Hi all,

This series is a first result of debugging some random crashes in dEQP's
multi-threaded EGL tests.

The OpenGL spec is pretty clear that application must not modify a texture
in one context while simultaneously using it for texturing (or even
modifying) it in another context. Texturing simultaneously in multiple
contexts is fine, though.

This can lead to races when st_finalize_texture is called simultaneously
for two contexts, or if two contexts simultaneously attempt to access the
sampler view array of a texture.

This series should fix most (all?) issues where our internal data
structures could become corrupted. I am aware of one remaining corner
case that could lead to rendering corruption. It appears rather non-trivial
to fix, and it is documented in a comment of patch #5.

Please review!
Thanks,
Nicolai
--
 src/gallium/auxiliary/util/u_inlines.h   |  16 ++-
 src/gallium/include/pipe/p_context.h |  10 ++
 src/mesa/state_tracker/st_atom_sampler.c |  12 +-
 src/mesa/state_tracker/st_atom_texture.c |  12 --
 src/mesa/state_tracker/st_cb_texture.c   |  59 +++--
 src/mesa/state_tracker/st_manager.c  |   3 +
 src/mesa/state_tracker/st_sampler_view.c | 137 +
 src/mesa/state_tracker/st_sampler_view.h |   7 ++
 src/mesa/state_tracker/st_texture.h  |  23 +++-
 9 files changed, 205 insertions(+), 74 deletions(-)

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


[Mesa-dev] [PATCH 3/6] st/mesa: store state that affects sampler views per context

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

This fixes sequences like:

1. Context 1 samples from texture with sRGB decode enabled
2. Context 2 samples from texture with sRGB decode disabled
3. Context 1 samples from texture with sRGB decode disabled

Previously, step 3 would see the prev_sRGBDecode value from context 2
and would incorrectly use the old sampler view with sRGB decode enabled.
---
 src/mesa/state_tracker/st_atom_texture.c | 12 
 src/mesa/state_tracker/st_sampler_view.c | 47 ++--
 src/mesa/state_tracker/st_texture.h  | 20 ++
 3 files changed, 40 insertions(+), 39 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_texture.c 
b/src/mesa/state_tracker/st_atom_texture.c
index 81bf62908f1..90828bb4cf9 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -77,32 +77,20 @@ st_update_single_texture(struct st_context *st,
   return;
}
 
if (!st_finalize_texture(ctx, st->pipe, texObj, 0) ||
!stObj->pt) {
   /* out of mem */
   *sampler_view = NULL;
   return;
}
 
-   /* Check a few pieces of state outside the texture object to see if we
-* need to force revalidation.
-*/
-   if (stObj->prev_glsl130_or_later != glsl130_or_later ||
-   stObj->prev_sRGBDecode != samp->sRGBDecode) {
-
-  st_texture_release_all_sampler_views(st, stObj);
-
-  stObj->prev_glsl130_or_later = glsl130_or_later;
-  stObj->prev_sRGBDecode = samp->sRGBDecode;
-   }
-
if (texObj->TargetIndex == TEXTURE_EXTERNAL_INDEX &&
stObj->pt->screen->resource_changed)
  stObj->pt->screen->resource_changed(stObj->pt->screen, stObj->pt);
 
*sampler_view =
   st_get_texture_sampler_view_from_stobj(st, stObj, samp,
  glsl130_or_later);
 }
 
 
diff --git a/src/mesa/state_tracker/st_sampler_view.c 
b/src/mesa/state_tracker/st_sampler_view.c
index f46e759dc24..a06b6e64aaf 100644
--- a/src/mesa/state_tracker/st_sampler_view.c
+++ b/src/mesa/state_tracker/st_sampler_view.c
@@ -42,53 +42,53 @@
 #include "st_cb_texture.h"
 
 
 /**
  * Try to find a matching sampler view for the given context.
  * If none is found an empty slot is initialized with a
  * template and returned instead.
  *
  * Must be called with the validate_mutex locked.
  */
-static struct pipe_sampler_view **
+static struct st_sampler_view *
 st_texture_get_sampler_view(struct st_context *st,
 struct st_texture_object *stObj)
 {
-   struct pipe_sampler_view **free = NULL;
+   struct st_sampler_view *free = NULL;
GLuint i;
 
for (i = 0; i < stObj->num_sampler_views; ++i) {
-  struct pipe_sampler_view **sv = >sampler_views[i];
+  struct st_sampler_view *sv = >sampler_views[i];
   /* Is the array entry used ? */
-  if (*sv) {
+  if (sv->view) {
  /* check if the context matches */
- if ((*sv)->context == st->pipe) {
+ if (sv->view->context == st->pipe) {
 return sv;
  }
   } else {
  /* Found a free slot, remember that */
  free = sv;
   }
}
 
/* Couldn't find a slot for our context, create a new one */
 
if (!free) {
   /* Haven't even found a free one, resize the array */
   unsigned new_size = (stObj->num_sampler_views + 1) *
- sizeof(struct pipe_sampler_view *);
+ sizeof(struct st_sampler_view);
   stObj->sampler_views = realloc(stObj->sampler_views, new_size);
   free = >sampler_views[stObj->num_sampler_views++];
-  *free = NULL;
+  free->view = NULL;
}
 
-   assert(*free == NULL);
+   assert(free->view == NULL);
 
return free;
 }
 
 
 /**
  * Return the most-recently validated sampler view for the texture \p stObj
  * in the given context, if any.
  *
  * Performs no additional validation.
@@ -122,21 +122,21 @@ void
 st_texture_release_sampler_view(struct st_context *st,
 struct st_texture_object *stObj)
 {
GLuint i;
 
/* This function is called during context destruction, which can race with
 * operations on the texture in another context in a well-formed GL program.
 */
mtx_lock(>validate_mutex);
for (i = 0; i < stObj->num_sampler_views; ++i) {
-  struct pipe_sampler_view **sv = >sampler_views[i];
+  struct pipe_sampler_view **sv = >sampler_views[i].view;
 
   if (*sv && (*sv)->context == st->pipe) {
  pipe_sampler_view_reference(sv, NULL);
  break;
   }
}
mtx_unlock(>validate_mutex);
 }
 
 
@@ -149,21 +149,21 @@ st_texture_release_all_sampler_views(struct st_context 
*st,
  struct st_texture_object *stObj)
 {
GLuint i;
 
/* This function is called from code paths that do not correspond to a
 * modification of the texture, so it may race with other accesses of the
 * sampler views array in a well-formed GL program.
 

[Mesa-dev] [PATCH 5/6] st/mesa: guard st_finalize_texture by the texture validation mutex

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

Since finalization of textures is done lazily, a well-formed GL program
might enter the main part of st_finalize_texture simultaneously in two
threads.

The mutex guards against corruption of our internal data structures.
However, finalization may also involve image copies (for copying image
data into a single mip-tree). We still lack proper synchronization of
these copy operations in a multi-context situation like:

 Context 1   Context 2
 -   -
 glTexImage*() operations
 glFinish()
 render using texture
 (implied image copy operations)
 render using texture
 glFlush()
 glFlush()

Since glFinish() was called after setting up the texture, the GL spec
guarantees that the rendering operations in both contexts will use the
expected texel data. However, we run the main part of st_finalize_texture
during context 1's rendering operations, and if that involves texture
image copies, then those may still be queued up and un-flushed when
context 2 is explicitly flushed.
---
 src/mesa/state_tracker/st_cb_texture.c   | 41 
 src/mesa/state_tracker/st_sampler_view.c | 22 +
 src/mesa/state_tracker/st_sampler_view.h |  4 
 3 files changed, 58 insertions(+), 9 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_texture.c 
b/src/mesa/state_tracker/st_cb_texture.c
index 6d9e40baa95..44e0dd11dcd 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -2480,33 +2480,60 @@ st_finalize_texture(struct gl_context *ctx,
stObj->base.BaseLevel >= stObj->validated_first_level &&
stObj->lastLevel <= stObj->validated_last_level) {
   return GL_TRUE;
}
 
/* If this texture comes from a window system, there is nothing else to do. 
*/
if (stObj->surface_based) {
   return GL_TRUE;
}
 
+   /* The mutex guards against corruption of our internal data structures.
+*
+* TODO: Finalization may also involve image copies (for copying image
+* data into a single mip-tree). We still lack proper synchronization of
+* these copy operations in a multi-context situation like:
+*
+*  Context 1Context 2
+*  --
+*  glTexImage*() operations
+*  glFinish() or other sync
+*
+*  render using texture
+*  (triggers image copy operations)
+*   render using texture
+*   glFlush()
+*  glFlush()
+*
+* Since glFinish() was called after setting up the texture, the GL spec
+* guarantees that the rendering operations in both contexts will use the
+* expected texel data. However, we run the main part of st_finalize_texture
+* during context 1's rendering operations, and if that involves texture
+* image copies, then those may still be queued up and un-flushed when
+* context 2 is explicitly flushed.
+*/
+   bool ok = false;
+   mtx_lock(>validate_mutex);
+
firstImage = 
st_texture_image_const(stObj->base.Image[cubeMapFace][stObj->base.BaseLevel]);
assert(firstImage);
 
/* If both firstImage and stObj point to a texture which can contain
 * all active images, favour firstImage.  Note that because of the
 * completeness requirement, we know that the image dimensions
 * will match.
 */
if (firstImage->pt &&
firstImage->pt != stObj->pt &&
(!stObj->pt || firstImage->pt->last_level >= stObj->pt->last_level)) {
   pipe_resource_reference(>pt, firstImage->pt);
-  st_texture_release_all_sampler_views(st, stObj);
+  st_texture_release_all_sampler_views_locked(st, stObj);
}
 
/* Find gallium format for the Mesa texture */
firstImageFormat =
   st_mesa_format_to_pipe_format(st, firstImage->base.TexFormat);
 
/* Find size of level=0 Gallium mipmap image, plus number of texture layers 
*/
{
   unsigned width;
   uint16_t height, depth;
@@ -2548,21 +2575,22 @@ st_finalize_texture(struct gl_context *ctx,
  }
 
  /* At this point, the texture may be incomplete (mismatched cube
   * face sizes, for example).  If that's the case, give up, but
   * don't return GL_FALSE as that would raise an incorrect
   * GL_OUT_OF_MEMORY error.  See Piglit fbo-incomplete-texture-03 test.
   */
  if (!stObj->base._BaseComplete) {
 _mesa_test_texobj_completeness(ctx, >base);
 if (!stObj->base._BaseComplete) {
-   return TRUE;
+   ok = true;
+   goto out;
 }
  }
   }
 
   ptNumSamples = firstImage->base.NumSamples;
}
 
/* If we already have a gallium texture, check that it matches the texture
 * object's format, target, size, 

[Mesa-dev] [PATCH 6/6] st/mesa: handle out-of-memory when resizing sampler views array

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

---
 src/mesa/state_tracker/st_sampler_view.c | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/mesa/state_tracker/st_sampler_view.c 
b/src/mesa/state_tracker/st_sampler_view.c
index 638fac671b2..de104355c04 100644
--- a/src/mesa/state_tracker/st_sampler_view.c
+++ b/src/mesa/state_tracker/st_sampler_view.c
@@ -69,21 +69,27 @@ st_texture_get_sampler_view(struct st_context *st,
  free = sv;
   }
}
 
/* Couldn't find a slot for our context, create a new one */
 
if (!free) {
   /* Haven't even found a free one, resize the array */
   unsigned new_size = (stObj->num_sampler_views + 1) *
  sizeof(struct st_sampler_view);
-  stObj->sampler_views = realloc(stObj->sampler_views, new_size);
+  struct st_sampler_view *new_sampler_views = 
realloc(stObj->sampler_views, new_size);
+  if (!new_sampler_views) {
+ _mesa_error(st->ctx, GL_OUT_OF_MEMORY, "sampler views array");
+ return NULL;
+  }
+
+  stObj->sampler_views = new_sampler_views;
   free = >sampler_views[stObj->num_sampler_views++];
   free->view = NULL;
}
 
assert(free->view == NULL);
 
return free;
 }
 
 
@@ -457,20 +463,25 @@ struct pipe_sampler_view *
 st_get_texture_sampler_view_from_stobj(struct st_context *st,
struct st_texture_object *stObj,
const struct gl_sampler_object *samp,
bool glsl130_or_later)
 {
struct st_sampler_view *sv;
struct pipe_sampler_view *view;
 
mtx_lock(>validate_mutex);
sv = st_texture_get_sampler_view(st, stObj);
+   if (!sv) {
+  mtx_unlock(>validate_mutex);
+  return NULL;
+   }
+
view = sv->view;
 
if (view &&
sv->glsl130_or_later == glsl130_or_later &&
sv->sRGBDecode == samp->sRGBDecode) {
   /* Debug check: make sure that the sampler view's parameters are
* what they're supposed to be.
*/
   MAYBE_UNUSED struct pipe_sampler_view *view = sv->view;
   assert(stObj->pt == view->texture);
@@ -510,20 +521,24 @@ st_get_buffer_sampler_view_from_stobj(struct st_context 
*st,
 {
struct st_sampler_view *sv;
struct st_buffer_object *stBuf =
   st_buffer_object(stObj->base.BufferObject);
 
if (!stBuf || !stBuf->buffer)
   return NULL;
 
mtx_lock(>validate_mutex);
sv = st_texture_get_sampler_view(st, stObj);
+   if (!sv) {
+  mtx_unlock(>validate_mutex);
+  return NULL;
+   }
 
struct pipe_resource *buf = stBuf->buffer;
struct pipe_sampler_view *view = sv->view;
 
if (view && view->texture == buf) {
   /* Debug check: make sure that the sampler view's parameters are
* what they're supposed to be.
*/
   assert(st_mesa_format_to_pipe_format(st, stObj->base._BufferObjectFormat)
  == view->format);
-- 
2.11.0

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


[Mesa-dev] [PATCH 1/6] gallium: clarify the constraints on sampler_view_destroy

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

r600 expects the context that created the sampler view to still be alive
(there is a per-context list of sampler views).

svga currently bails when the context of destruction is not the same as
creation.

The GL state tracker, which is the only one that runs into the
multi-context subtleties (due to share groups), already guarantees that
sampler views are destroyed before their context of creation is destroyed.

Most drivers are context-agnostic, so the warning message in
pipe_sampler_view_release doesn't really make sense.
---
 src/gallium/auxiliary/util/u_inlines.h   | 16 ++--
 src/gallium/include/pipe/p_context.h | 10 ++
 src/mesa/state_tracker/st_sampler_view.c |  1 -
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_inlines.h 
b/src/gallium/auxiliary/util/u_inlines.h
index 79f62c32266..790352d7800 100644
--- a/src/gallium/auxiliary/util/u_inlines.h
+++ b/src/gallium/auxiliary/util/u_inlines.h
@@ -142,45 +142,49 @@ pipe_resource_reference(struct pipe_resource **ptr, 
struct pipe_resource *tex)
  struct pipe_resource *next = old_tex->next;
 
  old_tex->screen->resource_destroy(old_tex->screen, old_tex);
  old_tex = next;
   } while (pipe_reference_described(_tex->reference, NULL,
 
(debug_reference_descriptor)debug_describe_resource));
}
*ptr = tex;
 }
 
+/**
+ * Set *ptr to \p view with proper reference counting.
+ *
+ * The caller must guarantee that \p view and *ptr must have been created in
+ * the same context (if they exist), and that this must be the current context.
+ */
 static inline void
 pipe_sampler_view_reference(struct pipe_sampler_view **ptr, struct 
pipe_sampler_view *view)
 {
struct pipe_sampler_view *old_view = *ptr;
 
if (pipe_reference_described(&(*ptr)->reference, >reference,
 
(debug_reference_descriptor)debug_describe_sampler_view))
   old_view->context->sampler_view_destroy(old_view->context, old_view);
*ptr = view;
 }
 
 /**
  * Similar to pipe_sampler_view_reference() but always set the pointer to
- * NULL and pass in an explicit context.  Passing an explicit context is a
- * work-around for fixing a dangling context pointer problem when textures
- * are shared by multiple contexts.  XXX fix this someday.
+ * NULL and pass in the current context explicitly.
+ *
+ * If *ptr is non-NULL, it may refer to a view that was created in a different
+ * context (however, that context must still be alive).
  */
 static inline void
 pipe_sampler_view_release(struct pipe_context *ctx,
   struct pipe_sampler_view **ptr)
 {
struct pipe_sampler_view *old_view = *ptr;
-   if (*ptr && (*ptr)->context != ctx) {
-  debug_printf_once(("context mis-match in 
pipe_sampler_view_release()\n"));
-   }
if (pipe_reference_described(&(*ptr)->reference, NULL,
 (debug_reference_descriptor)debug_describe_sampler_view)) {
   ctx->sampler_view_destroy(ctx, old_view);
}
*ptr = NULL;
 }
 
 static inline void
 pipe_so_target_reference(struct pipe_stream_output_target **ptr,
  struct pipe_stream_output_target *target)
diff --git a/src/gallium/include/pipe/p_context.h 
b/src/gallium/include/pipe/p_context.h
index 4609d4dbf23..087836d1c0c 100644
--- a/src/gallium/include/pipe/p_context.h
+++ b/src/gallium/include/pipe/p_context.h
@@ -501,20 +501,30 @@ struct pipe_context {
void (*fence_server_sync)(struct pipe_context *pipe,
  struct pipe_fence_handle *fence);
 
/**
 * Create a view on a texture to be used by a shader stage.
 */
struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx,
  struct pipe_resource 
*texture,
  const struct 
pipe_sampler_view *templat);
 
+   /**
+* Destroy a view on a texture.
+*
+* \param ctx the current context
+* \param view the view to be destroyed
+*
+* \note The current context may not be the context in which the view was
+*   created (view->context). However, the caller must guarantee that
+*   the context which created the view is still alive.
+*/
void (*sampler_view_destroy)(struct pipe_context *ctx,
 struct pipe_sampler_view *view);
 
 
/**
 * Get a surface which is a "view" into a resource, used by
 * render target / depth stencil stages.
 */
struct pipe_surface *(*create_surface)(struct pipe_context *ctx,
   struct pipe_resource *resource,
diff --git a/src/mesa/state_tracker/st_sampler_view.c 
b/src/mesa/state_tracker/st_sampler_view.c
index fbf0aaeb03a..d1715a888d9 100644
--- a/src/mesa/state_tracker/st_sampler_view.c
+++ 

[Mesa-dev] [PATCH 2/6] st/mesa: guard sampler views changes with a mutex

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

Locking is unfortunately required, because well-formed GL programs can
have multiple threads racing to access the same texture, e.g.: two
threads/contexts rendering from the same texture, or one thread destroying
a context while the other is rendering from or modifying a texture.
---
 src/mesa/state_tracker/st_atom_sampler.c | 12 ++-
 src/mesa/state_tracker/st_cb_texture.c   |  2 ++
 src/mesa/state_tracker/st_sampler_view.c | 58 +---
 src/mesa/state_tracker/st_sampler_view.h |  3 ++
 src/mesa/state_tracker/st_texture.h  |  3 ++
 5 files changed, 64 insertions(+), 14 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_sampler.c 
b/src/mesa/state_tracker/st_atom_sampler.c
index d9e8de3c9e0..34a0c18b0a5 100644
--- a/src/mesa/state_tracker/st_atom_sampler.c
+++ b/src/mesa/state_tracker/st_atom_sampler.c
@@ -36,20 +36,21 @@
 #include "main/mtypes.h"
 #include "main/glformats.h"
 #include "main/samplerobj.h"
 #include "main/teximage.h"
 #include "main/texobj.h"
 
 #include "st_context.h"
 #include "st_cb_texture.h"
 #include "st_format.h"
 #include "st_atom.h"
+#include "st_sampler_view.h"
 #include "st_texture.h"
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 
 #include "cso_cache/cso_context.h"
 
 #include "util/u_format.h"
 
 
 /**
@@ -157,31 +158,22 @@ st_convert_sampler(const struct st_context *st,
(sampler->wrap_s | sampler->wrap_t | sampler->wrap_r) & 0x1 &&
(msamp->BorderColor.ui[0] ||
 msamp->BorderColor.ui[1] ||
 msamp->BorderColor.ui[2] ||
 msamp->BorderColor.ui[3])) {
   const GLboolean is_integer = texobj->_IsIntegerFormat;
   GLenum texBaseFormat = _mesa_base_tex_image(texobj)->_BaseFormat;
 
   if (st->apply_texture_swizzle_to_border_color) {
  const struct st_texture_object *stobj = 
st_texture_object_const(texobj);
- const struct pipe_sampler_view *sv = NULL;
-
- /* Just search for the first used view. We can do this because the
-swizzle is per-texture, not per context. */
  /* XXX: clean that up to not use the sampler view at all */
- for (unsigned i = 0; i < stobj->num_sampler_views; ++i) {
-if (stobj->sampler_views[i]) {
-   sv = stobj->sampler_views[i];
-   break;
-}
- }
+ const struct pipe_sampler_view *sv = 
st_texture_get_current_sampler_view(st, stobj);
 
  if (sv) {
 union pipe_color_union tmp;
 const unsigned char swz[4] =
 {
sv->swizzle_r,
sv->swizzle_g,
sv->swizzle_b,
sv->swizzle_a,
 };
diff --git a/src/mesa/state_tracker/st_cb_texture.c 
b/src/mesa/state_tracker/st_cb_texture.c
index b5006b05a7b..bac2a0289f5 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -148,36 +148,38 @@ st_DeleteTextureImage(struct gl_context * ctx, struct 
gl_texture_image *img)
 
 /** called via ctx->Driver.NewTextureObject() */
 static struct gl_texture_object *
 st_NewTextureObject(struct gl_context * ctx, GLuint name, GLenum target)
 {
struct st_texture_object *obj = ST_CALLOC_STRUCT(st_texture_object);
 
DBG("%s\n", __func__);
_mesa_initialize_texture_object(ctx, >base, name, target);
 
+   mtx_init(>validate_mutex, mtx_plain);
obj->needs_validation = true;
 
return >base;
 }
 
 /** called via ctx->Driver.DeleteTextureObject() */
 static void 
 st_DeleteTextureObject(struct gl_context *ctx,
struct gl_texture_object *texObj)
 {
struct st_context *st = st_context(ctx);
struct st_texture_object *stObj = st_texture_object(texObj);
 
pipe_resource_reference(>pt, NULL);
st_texture_release_all_sampler_views(st, stObj);
st_texture_free_sampler_views(stObj);
+   mtx_destroy(>validate_mutex);
_mesa_delete_texture_object(ctx, texObj);
 }
 
 
 /** called via ctx->Driver.FreeTextureImageBuffer() */
 static void
 st_FreeTextureImageBuffer(struct gl_context *ctx,
   struct gl_texture_image *texImage)
 {
struct st_context *st = st_context(ctx);
diff --git a/src/mesa/state_tracker/st_sampler_view.c 
b/src/mesa/state_tracker/st_sampler_view.c
index d1715a888d9..f46e759dc24 100644
--- a/src/mesa/state_tracker/st_sampler_view.c
+++ b/src/mesa/state_tracker/st_sampler_view.c
@@ -39,20 +39,22 @@
 #include "st_texture.h"
 #include "st_format.h"
 #include "st_cb_bufferobjects.h"
 #include "st_cb_texture.h"
 
 
 /**
  * Try to find a matching sampler view for the given context.
  * If none is found an empty slot is initialized with a
  * template and returned instead.
+ *
+ * Must be called with the validate_mutex locked.
  */
 static struct pipe_sampler_view **
 st_texture_get_sampler_view(struct st_context *st,
 struct st_texture_object *stObj)
 {
struct 

[Mesa-dev] [PATCH 1/2] disk_cache: fix a memory leak

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

---
 src/util/disk_cache.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 17913a913bd..63fd8e1f93a 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -1138,20 +1138,21 @@ disk_cache_get(struct disk_cache *cache, const 
cache_key key, size_t *size)
cf_data.uncompressed_size))
   goto fail;
 
/* Check the data for corruption */
if (cf_data.crc32 != util_hash_crc32(uncompressed_data,
 cf_data.uncompressed_size))
   goto fail;
 
free(data);
free(filename);
+   free(file_header);
close(fd);
 
if (size)
   *size = cf_data.uncompressed_size;
 
return uncompressed_data;
 
  fail:
if (data)
   free(data);
-- 
2.11.0

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


[Mesa-dev] [PATCH 2/2] disk_cache: remove unnecessary NULL-pointer guards

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

---
 src/util/disk_cache.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 63fd8e1f93a..e38cacb259b 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -980,24 +980,22 @@ cache_put(void *job, int thread_index)
p_atomic_add(dc_job->cache->size, sb.st_blocks * 512);
 
  done:
if (fd_final != -1)
   close(fd_final);
/* This close finally releases the flock, (now that the final file
 * has been renamed into place and the size has been added).
 */
if (fd != -1)
   close(fd);
-   if (filename_tmp)
-  free(filename_tmp);
-   if (filename)
-  free(filename);
+   free(filename_tmp);
+   free(filename);
 }
 
 void
 disk_cache_put(struct disk_cache *cache, const cache_key key,
const void *data, size_t size,
struct cache_item_metadata *cache_item_metadata)
 {
struct disk_cache_put_job *dc_job =
   create_put_job(cache, key, data, size, cache_item_metadata);
 
-- 
2.11.0

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


[Mesa-dev] [PATCH] u_threaded_context: fix a memory leak

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

The uploaders can own transfers which need to be unmapped. Destroy them
before the final sync (they're not used from the driver thread anyway)
so that the transfer_unmap call is processed by the driver.
---
 src/gallium/auxiliary/util/u_threaded_context.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_threaded_context.c 
b/src/gallium/auxiliary/util/u_threaded_context.c
index 043d4e67df1..7e28b87a7ff 100644
--- a/src/gallium/auxiliary/util/u_threaded_context.c
+++ b/src/gallium/auxiliary/util/u_threaded_context.c
@@ -2226,37 +2226,38 @@ tc_resource_commit(struct pipe_context *_pipe, struct 
pipe_resource *res,
 /
  * create & destroy
  */
 
 static void
 tc_destroy(struct pipe_context *_pipe)
 {
struct threaded_context *tc = threaded_context(_pipe);
struct pipe_context *pipe = tc->pipe;
 
+   if (tc->base.const_uploader &&
+   tc->base.stream_uploader != tc->base.const_uploader)
+  u_upload_destroy(tc->base.const_uploader);
+
+   if (tc->base.stream_uploader)
+  u_upload_destroy(tc->base.stream_uploader);
+
tc_sync(tc);
 
if (util_queue_is_initialized(>queue)) {
   util_queue_destroy(>queue);
 
   for (unsigned i = 0; i < TC_MAX_BATCHES; i++)
  util_queue_fence_destroy(>batch_slots[i].fence);
}
 
-   if (tc->base.const_uploader &&
-   tc->base.stream_uploader != tc->base.const_uploader)
-  u_upload_destroy(tc->base.const_uploader);
-
-   if (tc->base.stream_uploader)
-  u_upload_destroy(tc->base.stream_uploader);
-
slab_destroy_child(>pool_transfers);
+   assert(tc->batch_slots[tc->next].num_total_call_slots == 0);
pipe->destroy(pipe);
os_free_aligned(tc);
 }
 
 static const tc_execute execute_func[TC_NUM_CALLS] = {
 #define CALL(name) tc_call_##name,
 #include "u_threaded_context_calls.h"
 #undef CALL
 };
 
-- 
2.11.0

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


[Mesa-dev] [PATCH 1/3] st/mesa: fix switching from surface-based to non-surface-based textures

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

This can happen with surface-based texture objects derived from EGL
images, since those aren't immutable.

Fixes tests in 
dEQP-EGL.functional.sharing.gles2.multithread.random.images.teximage2d.* and 
others
---
 src/mesa/main/texobj.c  | 11 +++
 src/mesa/main/texobj.h  |  3 ++-
 src/mesa/state_tracker/st_cb_eglimage.c |  2 +-
 src/mesa/state_tracker/st_cb_texture.c  |  3 ++-
 src/mesa/state_tracker/st_manager.c |  2 +-
 src/mesa/state_tracker/st_vdpau.c   |  2 +-
 6 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index b703da01bef..1978898b8b9 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -464,40 +464,43 @@ _mesa_copy_texture_object( struct gl_texture_object *dest,
COPY_4V(dest->Swizzle, src->Swizzle);
dest->_Swizzle = src->_Swizzle;
dest->_IsHalfFloat = src->_IsHalfFloat;
dest->_IsFloat = src->_IsFloat;
 
dest->RequiredTextureImageUnits = src->RequiredTextureImageUnits;
 }
 
 
 /**
- * Free all texture images of the given texture object.
+ * Free all texture images of the given texture objectm, except for
+ * \p retainTexImage.
  *
  * \param ctx GL context.
- * \param t texture object.
+ * \param texObj texture object.
+ * \param retainTexImage a texture image that will \em not be freed.
  *
  * \sa _mesa_clear_texture_image().
  */
 void
 _mesa_clear_texture_object(struct gl_context *ctx,
-   struct gl_texture_object *texObj)
+   struct gl_texture_object *texObj,
+   struct gl_texture_image *retainTexImage)
 {
GLuint i, j;
 
if (texObj->Target == 0)
   return;
 
for (i = 0; i < MAX_FACES; i++) {
   for (j = 0; j < MAX_TEXTURE_LEVELS; j++) {
  struct gl_texture_image *texImage = texObj->Image[i][j];
- if (texImage)
+ if (texImage && texImage != retainTexImage)
 _mesa_clear_texture_image(ctx, texImage);
   }
}
 }
 
 
 /**
  * Check if the given texture object is valid by examining its Target field.
  * For debugging only.
  */
diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h
index 71cc8ffba2e..e67ce3ff9df 100644
--- a/src/mesa/main/texobj.h
+++ b/src/mesa/main/texobj.h
@@ -74,21 +74,22 @@ _mesa_tex_target_to_index(const struct gl_context *ctx, 
GLenum target);
 extern void
 _mesa_delete_texture_object( struct gl_context *ctx,
  struct gl_texture_object *obj );
 
 extern void
 _mesa_copy_texture_object( struct gl_texture_object *dest,
const struct gl_texture_object *src );
 
 extern void
 _mesa_clear_texture_object(struct gl_context *ctx,
-   struct gl_texture_object *obj);
+   struct gl_texture_object *obj,
+   struct gl_texture_image *retainTexImage);
 
 extern void
 _mesa_reference_texobj_(struct gl_texture_object **ptr,
 struct gl_texture_object *tex);
 
 static inline void
 _mesa_reference_texobj(struct gl_texture_object **ptr,
struct gl_texture_object *tex)
 {
if (*ptr != tex)
diff --git a/src/mesa/state_tracker/st_cb_eglimage.c 
b/src/mesa/state_tracker/st_cb_eglimage.c
index cca2c026097..e15b32ff199 100644
--- a/src/mesa/state_tracker/st_cb_eglimage.c
+++ b/src/mesa/state_tracker/st_cb_eglimage.c
@@ -191,21 +191,21 @@ st_bind_egl_image(struct gl_context *ctx,
   UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
   internalFormat = GL_RGBA;
else
   internalFormat = GL_RGB;
 
stObj = st_texture_object(texObj);
stImage = st_texture_image(texImage);
 
/* switch to surface based */
if (!stObj->surface_based) {
-  _mesa_clear_texture_object(ctx, texObj);
+  _mesa_clear_texture_object(ctx, texObj, NULL);
   stObj->surface_based = GL_TRUE;
}
 
texFormat = st_pipe_format_to_mesa_format(stimg->format);
 
/* TODO RequiredTextureImageUnits should probably be reset back
 * to 1 somewhere if different texture is bound??
 */
if (texFormat == MESA_FORMAT_NONE) {
   switch (stimg->format) {
diff --git a/src/mesa/state_tracker/st_cb_texture.c 
b/src/mesa/state_tracker/st_cb_texture.c
index b5006b05a7b..b0a95ecbc79 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -686,21 +686,22 @@ prep_teximage(struct gl_context *ctx, struct 
gl_texture_image *texImage,
 {
struct gl_texture_object *texObj = texImage->TexObject;
struct st_texture_object *stObj = st_texture_object(texObj);
 
/* switch to "normal" */
if (stObj->surface_based) {
   const GLenum target = texObj->Target;
   const GLuint level = texImage->Level;
   mesa_format texFormat;
 
-  _mesa_clear_texture_object(ctx, texObj);
+  assert(!st_texture_image(texImage)->pt);
+   

[Mesa-dev] [PATCH 3/3] st/mesa: whitespace fix

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

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

diff --git a/src/mesa/state_tracker/st_texture.h 
b/src/mesa/state_tracker/st_texture.h
index 0cde0c1f409..ea459bf6e24 100644
--- a/src/mesa/state_tracker/st_texture.h
+++ b/src/mesa/state_tracker/st_texture.h
@@ -63,21 +63,21 @@ struct st_texture_image
/* List of transfers, allocated on demand.
 * transfer[layer] is a mapping for that layer.
 */
struct st_texture_image_transfer *transfer;
unsigned num_transfers;
 
/* For ETC images, keep track of the original data. This is necessary for
 * mapping/unmapping, as well as image copies.
 */
GLubyte *etc_data;
- };
+};
 
 
 /**
  * Subclass of gl_texure_object.
  */
 struct st_texture_object
 {
struct gl_texture_object base;   /* The "parent" object */
 
/* The texture must include at levels [0..lastLevel] once validated:
-- 
2.11.0

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


[Mesa-dev] [PATCH 2/3] st/mesa: fix import of EGL images with non-zero level or layer

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

In GL state, textures created from EGL images look like plain 2D textures
with a single level, so we use the existing layer_override facility and
add an analogous level_override one.

Fixes 
dEQP-EGL.functional.image.create.gles2_cubemap_{positive,negative}_{x,y,z}_rgba_texture
---
 src/mesa/state_tracker/st_cb_eglimage.c  |  3 ++-
 src/mesa/state_tracker/st_cb_texture.c   |  2 ++
 src/mesa/state_tracker/st_sampler_view.c | 16 ++--
 src/mesa/state_tracker/st_texture.h  | 15 ---
 src/mesa/state_tracker/st_vdpau.c|  2 ++
 5 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_eglimage.c 
b/src/mesa/state_tracker/st_cb_eglimage.c
index e15b32ff199..bb092a2f6ef 100644
--- a/src/mesa/state_tracker/st_cb_eglimage.c
+++ b/src/mesa/state_tracker/st_cb_eglimage.c
@@ -219,26 +219,27 @@ st_bind_egl_image(struct gl_context *ctx,
  break;
   default:
  unreachable("bad YUV format!");
   }
}
 
_mesa_init_teximage_fields(ctx, texImage,
   stimg->texture->width0, stimg->texture->height0,
   1, 0, internalFormat, texFormat);
 
-   /* FIXME create a non-default sampler view from the stimg? */
pipe_resource_reference(>pt, stimg->texture);
st_texture_release_all_sampler_views(st, stObj);
pipe_resource_reference(>pt, stObj->pt);
 
stObj->surface_format = stimg->format;
+   stObj->level_override = stimg->level;
+   stObj->layer_override = stimg->layer;
 
_mesa_dirty_texobj(ctx, texObj);
 }
 
 static void
 st_egl_image_target_texture_2d(struct gl_context *ctx, GLenum target,
   struct gl_texture_object *texObj,
   struct gl_texture_image *texImage,
   GLeglImageOES image_handle)
 {
diff --git a/src/mesa/state_tracker/st_cb_texture.c 
b/src/mesa/state_tracker/st_cb_texture.c
index b0a95ecbc79..25ea52924d2 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -688,20 +688,22 @@ prep_teximage(struct gl_context *ctx, struct 
gl_texture_image *texImage,
struct st_texture_object *stObj = st_texture_object(texObj);
 
/* switch to "normal" */
if (stObj->surface_based) {
   const GLenum target = texObj->Target;
   const GLuint level = texImage->Level;
   mesa_format texFormat;
 
   assert(!st_texture_image(texImage)->pt);
   _mesa_clear_texture_object(ctx, texObj, texImage);
+  stObj->layer_override = 0;
+  stObj->level_override = 0;
   pipe_resource_reference(>pt, NULL);
 
   /* oops, need to init this image again */
   texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
   texImage->InternalFormat, format,
   type);
 
   _mesa_init_teximage_fields(ctx, texImage,
  texImage->Width, texImage->Height,
  texImage->Depth, texImage->Border,
diff --git a/src/mesa/state_tracker/st_sampler_view.c 
b/src/mesa/state_tracker/st_sampler_view.c
index fbf0aaeb03a..014b4d26784 100644
--- a/src/mesa/state_tracker/st_sampler_view.c
+++ b/src/mesa/state_tracker/st_sampler_view.c
@@ -372,30 +372,34 @@ st_create_texture_sampler_view_from_stobj(struct 
st_context *st,
  struct st_texture_object *stObj,
  enum pipe_format format,
   bool glsl130_or_later)
 {
/* There is no need to clear this structure (consider CPU overhead). */
struct pipe_sampler_view templ;
unsigned swizzle = get_texture_format_swizzle(st, stObj, glsl130_or_later);
 
templ.format = format;
 
-   templ.u.tex.first_level = stObj->base.MinLevel + stObj->base.BaseLevel;
-   templ.u.tex.last_level = last_level(stObj);
-   assert(templ.u.tex.first_level <= templ.u.tex.last_level);
+   if (stObj->level_override) {
+  templ.u.tex.first_level = templ.u.tex.last_level = stObj->level_override;
+   } else {
+  templ.u.tex.first_level = stObj->base.MinLevel + stObj->base.BaseLevel;
+  templ.u.tex.last_level = last_level(stObj);
+   }
if (stObj->layer_override) {
   templ.u.tex.first_layer = templ.u.tex.last_layer = stObj->layer_override;
} else {
   templ.u.tex.first_layer = stObj->base.MinLayer;
   templ.u.tex.last_layer = last_layer(stObj);
}
assert(templ.u.tex.first_layer <= templ.u.tex.last_layer);
+   assert(templ.u.tex.first_level <= templ.u.tex.last_level);
templ.target = gl_target_to_pipe(stObj->base.Target);
 
templ.swizzle_r = GET_SWZ(swizzle, 0);
templ.swizzle_g = GET_SWZ(swizzle, 1);
templ.swizzle_b = GET_SWZ(swizzle, 2);
templ.swizzle_a = GET_SWZ(swizzle, 3);
 
return st->pipe->create_sampler_view(st->pipe, 

[Mesa-dev] [PATCH] glsl/linker: add check for compute shared memory size

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

Unlike uniforms, the limit on shared memory size is not called out
explicitly in the list of things that cause linker errors, but presumably
that's just an oversight in the spec.

Fixes 
dEQP-GLES31.functional.debug.negative_coverage.{callbacks,get_error,log}.compute.exceed_shared_memory_size_limit
---
 src/compiler/glsl/ir_optimization.h  |  5 +++--
 src/compiler/glsl/linker.cpp |  3 +--
 src/compiler/glsl/lower_shared_reference.cpp | 21 +++--
 3 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/compiler/glsl/ir_optimization.h 
b/src/compiler/glsl/ir_optimization.h
index 38fb54990ea..eb3ec3b0c7d 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -136,22 +136,23 @@ bool lower_instructions(exec_list *instructions, unsigned 
what_to_lower);
 bool lower_noise(exec_list *instructions);
 bool lower_variable_index_to_cond_assign(gl_shader_stage stage,
 exec_list *instructions, bool lower_input, bool lower_output,
 bool lower_temp, bool lower_uniform);
 bool lower_quadop_vector(exec_list *instructions, bool dont_lower_swz);
 bool lower_const_arrays_to_uniforms(exec_list *instructions, unsigned stage);
 bool lower_clip_cull_distance(struct gl_shader_program *prog,
   gl_linked_shader *shader);
 void lower_output_reads(unsigned stage, exec_list *instructions);
 bool lower_packing_builtins(exec_list *instructions, int op_mask);
-void lower_shared_reference(struct gl_linked_shader *shader,
-unsigned *shared_size);
+void lower_shared_reference(struct gl_context *ctx,
+struct gl_shader_program *prog,
+struct gl_linked_shader *shader);
 void lower_ubo_reference(struct gl_linked_shader *shader,
  bool clamp_block_indices, bool use_std430_as_default);
 void lower_packed_varyings(void *mem_ctx,
unsigned locations_used,
const uint8_t *components,
ir_variable_mode mode,
unsigned gs_input_vertices,
gl_linked_shader *shader,
bool disable_varying_packing, bool xfb_enabled);
 bool lower_vector_insert(exec_list *instructions, bool 
lower_nonconstant_index);
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index f352c5385ca..03eb05bf637 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -4650,22 +4650,21 @@ link_varyings_and_uniforms(unsigned first, unsigned 
last,
 
   const struct gl_shader_compiler_options *options =
  >Const.ShaderCompilerOptions[i];
 
   if (options->LowerBufferInterfaceBlocks)
  lower_ubo_reference(prog->_LinkedShaders[i],
  options->ClampBlockIndicesToArrayBounds,
  ctx->Const.UseSTD430AsDefaultPacking);
 
   if (i == MESA_SHADER_COMPUTE)
- lower_shared_reference(prog->_LinkedShaders[i],
->Comp.SharedSize);
+ lower_shared_reference(ctx, prog, prog->_LinkedShaders[i]);
 
   lower_vector_derefs(prog->_LinkedShaders[i]);
   do_vec_index_to_swizzle(prog->_LinkedShaders[i]->ir);
}
 
return true;
 }
 
 static void
 linker_optimisation_loop(struct gl_context *ctx, exec_list *ir,
diff --git a/src/compiler/glsl/lower_shared_reference.cpp 
b/src/compiler/glsl/lower_shared_reference.cpp
index b9098913af8..a1b3f7df47e 100644
--- a/src/compiler/glsl/lower_shared_reference.cpp
+++ b/src/compiler/glsl/lower_shared_reference.cpp
@@ -26,20 +26,21 @@
  *
  * IR lower pass to replace dereferences of compute shader shared variables
  * with intrinsic function calls.
  *
  * This relieves drivers of the responsibility of allocating space for the
  * shared variables in the shared memory region.
  */
 
 #include "lower_buffer_access.h"
 #include "ir_builder.h"
+#include "linker.h"
 #include "main/macros.h"
 #include "util/list.h"
 #include "glsl_parser_extras.h"
 
 using namespace ir_builder;
 
 namespace {
 
 struct var_offset {
struct list_head node;
@@ -471,29 +472,45 @@ lower_shared_reference_visitor::visit_enter(ir_call *ir)
   base_ir->replace_with(new_ir);
   return visit_continue_with_parent;
}
 
return rvalue_visit(ir);
 }
 
 } /* unnamed namespace */
 
 void
-lower_shared_reference(struct gl_linked_shader *shader, unsigned *shared_size)
+lower_shared_reference(struct gl_context *ctx,
+   struct gl_shader_program *prog,
+   struct gl_linked_shader *shader)
 {
if (shader->Stage != MESA_SHADER_COMPUTE)
   return;
 
lower_shared_reference_visitor v(shader);
 
/* Loop over the instructions lowering references, because we take a deref
 * of an shared variable array using a shared variable 

[Mesa-dev] [PATCH 3/6] egl/dri: use createImageFromRenderbuffer2 when available

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

---
 src/egl/drivers/dri2/egl_dri2.c | 23 ---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 1407c96352e..171858bbcd9 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1883,23 +1883,40 @@ dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, 
_EGLContext *ctx,
if (renderbuffer == 0) {
   _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr");
   return EGL_NO_IMAGE_KHR;
}
 
if (!disp->Extensions.KHR_gl_renderbuffer_image) {
   _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr");
   return EGL_NO_IMAGE_KHR;
}
 
-   dri_image =
-  dri2_dpy->image->createImageFromRenderbuffer(dri2_ctx->dri_context,
-   renderbuffer, NULL);
+   if (dri2_dpy->image->base.version >= 17) {
+  unsigned error = ~0;
+
+  dri_image = dri2_dpy->image->createImageFromRenderbuffer2(
+   dri2_ctx->dri_context, renderbuffer, NULL, );
+
+  assert(!!dri_image == (error == __DRI_IMAGE_ERROR_SUCCESS));
+
+  if (!dri_image) {
+ _eglError(egl_error_from_dri_image_error(error), 
"dri2_create_image_khr");
+ return EGL_NO_IMAGE_KHR;
+  }
+   } else {
+  dri_image = dri2_dpy->image->createImageFromRenderbuffer(
+   dri2_ctx->dri_context, renderbuffer, NULL);
+  if (!dri_image) {
+ _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr");
+ return EGL_NO_IMAGE_KHR;
+  }
+   }
 
return dri2_create_image_from_dri(disp, dri_image);
 }
 
 #ifdef HAVE_WAYLAND_PLATFORM
 
 /* This structure describes how a wl_buffer maps to one or more
  * __DRIimages.  A wl_drm_buffer stores the wl_drm format code and the
  * offsets and strides of the planes in the buffer.  This table maps a
  * wl_drm format code to a description of the planes in the buffer
-- 
2.11.0

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


[Mesa-dev] [PATCH 6/6] st/dri: implement createImageFromRenderbuffer(2)

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

Tested with dEQP-EGL tests.
---
 src/gallium/state_trackers/dri/dri2.c|  8 +++-
 src/gallium/state_trackers/dri/dri_helpers.c | 65 +---
 src/gallium/state_trackers/dri/dri_helpers.h |  5 +++
 src/mesa/state_tracker/st_cb_fbo.h   |  5 +++
 4 files changed, 76 insertions(+), 7 deletions(-)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 86721747878..324e357c358 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1554,38 +1554,44 @@ dri2_unmap_image(__DRIcontext *context, __DRIimage 
*image, void *data)
 static int
 dri2_get_capabilities(__DRIscreen *_screen)
 {
struct dri_screen *screen = dri_screen(_screen);
 
return (screen->can_share_buffer ? __DRI_IMAGE_CAP_GLOBAL_NAMES : 0);
 }
 
 /* The extension is modified during runtime if DRI_PRIME is detected */
 static __DRIimageExtension dri2ImageExtension = {
-.base = { __DRI_IMAGE, 15 },
+.base = { __DRI_IMAGE, 17 },
 
 .createImageFromName  = dri2_create_image_from_name,
 .createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
 .destroyImage = dri2_destroy_image,
 .createImage  = dri2_create_image,
 .queryImage   = dri2_query_image,
 .dupImage = dri2_dup_image,
 .validateUsage= dri2_validate_usage,
 .createImageFromNames = dri2_from_names,
 .fromPlanar   = dri2_from_planar,
 .createImageFromTexture   = dri2_create_from_texture,
 .createImageFromFds   = NULL,
 .createImageFromDmaBufs   = NULL,
 .blitImage= dri2_blit_image,
 .getCapabilities  = dri2_get_capabilities,
 .mapImage = dri2_map_image,
 .unmapImage   = dri2_unmap_image,
+.createImageWithModifiers = NULL,
+.createImageFromDmaBufs2  = NULL,
+.queryDmaBufFormats   = NULL,
+.queryDmaBufModifiers = NULL,
+.queryDmaBufFormatModifierAttribs = NULL,
+.createImageFromRenderbuffer2 = dri2_create_image_from_renderbuffer2,
 };
 
 static const __DRIrobustnessExtension dri2Robustness = {
.base = { __DRI2_ROBUSTNESS, 1 }
 };
 
 static int
 dri2_interop_query_device_info(__DRIcontext *_ctx,
struct mesa_glinterop_device_info *out)
 {
diff --git a/src/gallium/state_trackers/dri/dri_helpers.c 
b/src/gallium/state_trackers/dri/dri_helpers.c
index 07c4086310d..06309d8f0ce 100644
--- a/src/gallium/state_trackers/dri/dri_helpers.c
+++ b/src/gallium/state_trackers/dri/dri_helpers.c
@@ -18,20 +18,21 @@
  * 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 
 #include "util/u_memory.h"
 #include "pipe/p_screen.h"
 #include "state_tracker/st_texture.h"
 #include "state_tracker/st_context.h"
+#include "state_tracker/st_cb_fbo.h"
 #include "main/texobj.h"
 
 #include "dri_helpers.h"
 
 static bool
 dri2_is_opencl_interop_loaded_locked(struct dri_screen *screen)
 {
return screen->opencl_dri_event_add_ref &&
   screen->opencl_dri_event_release &&
   screen->opencl_dri_event_wait &&
@@ -239,30 +240,82 @@ dri2_lookup_egl_image(struct dri_screen *screen, void 
*handle)
if (!loader->lookupEGLImage)
   return NULL;
 
img = loader->lookupEGLImage(screen->sPriv,
handle, screen->sPriv->loaderPrivate);
 
return img;
 }
 
 __DRIimage *
-dri2_create_image_from_renderbuffer(__DRIcontext *context,
-   int renderbuffer, void *loaderPrivate)
+dri2_create_image_from_renderbuffer2(__DRIcontext *context,
+int renderbuffer, void *loaderPrivate,
+ unsigned *error)
 {
-   struct dri_context *ctx = dri_context(context);
+   struct gl_context *ctx = ((struct st_context 
*)dri_context(context)->st)->ctx;
+   struct gl_renderbuffer *rb;
+   struct pipe_resource *tex;
+   __DRIimage *img;
+
+   /* Section 3.9 (EGLImage Specification and Management) of the EGL 1.5
+* specification says:
+*
+*   "If target is EGL_GL_RENDERBUFFER and buffer is not the name of a
+*renderbuffer object, or if buffer is the name of a multisampled
+*renderbuffer object, the error EGL_BAD_PARAMETER is generated."
+*
+*   "If target is EGL_GL_TEXTURE_2D , EGL_GL_TEXTURE_CUBE_MAP_*,
+*EGL_GL_RENDERBUFFER or EGL_GL_TEXTURE_3D and buffer refers to the
+*default GL texture object (0) for the corresponding GL target, the
+*error EGL_BAD_PARAMETER is generated."
+*   (rely on _mesa_lookup_renderbuffer returning NULL in this case)
+*/
+   rb = 

[Mesa-dev] [PATCH 4/6] egl/dri: remove old left-overs

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

---
 src/egl/drivers/dri2/platform_x11_dri3.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_x11_dri3.c 
b/src/egl/drivers/dri2/platform_x11_dri3.c
index 45bb56ca17e..eadd37141e0 100644
--- a/src/egl/drivers/dri2/platform_x11_dri3.c
+++ b/src/egl/drivers/dri2/platform_x11_dri3.c
@@ -297,22 +297,20 @@ dri3_create_image_khr_pixmap(_EGLDisplay *disp, 
_EGLContext *ctx,
free(bp_reply);
 
return _img->base;
 }
 
 static _EGLImage *
 dri3_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
   _EGLContext *ctx, EGLenum target,
   EGLClientBuffer buffer, const EGLint *attr_list)
 {
-   (void) drv;
-
switch (target) {
case EGL_NATIVE_PIXMAP_KHR:
   return dri3_create_image_khr_pixmap(disp, ctx, buffer, attr_list);
default:
   return dri2_create_image_khr(drv, disp, ctx, target, buffer, attr_list);
}
 }
 
 /**
  * Called by the driver when it needs to update the real front buffer with the
-- 
2.11.0

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


[Mesa-dev] [PATCH 5/6] st_api: remove unused get_resource_for_egl_image

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

---
 src/gallium/include/state_tracker/st_api.h | 37 --
 1 file changed, 37 deletions(-)

diff --git a/src/gallium/include/state_tracker/st_api.h 
b/src/gallium/include/state_tracker/st_api.h
index 4d27dad5c55..2232c3efa18 100644
--- a/src/gallium/include/state_tracker/st_api.h
+++ b/src/gallium/include/state_tracker/st_api.h
@@ -134,36 +134,20 @@ enum st_attachment_type {
 /* for buffer_mask in st_visual */
 #define ST_ATTACHMENT_FRONT_LEFT_MASK (1 << ST_ATTACHMENT_FRONT_LEFT)
 #define ST_ATTACHMENT_BACK_LEFT_MASK  (1 << ST_ATTACHMENT_BACK_LEFT)
 #define ST_ATTACHMENT_FRONT_RIGHT_MASK(1 << ST_ATTACHMENT_FRONT_RIGHT)
 #define ST_ATTACHMENT_BACK_RIGHT_MASK (1 << ST_ATTACHMENT_BACK_RIGHT)
 #define ST_ATTACHMENT_DEPTH_STENCIL_MASK  (1 << ST_ATTACHMENT_DEPTH_STENCIL)
 #define ST_ATTACHMENT_ACCUM_MASK  (1 << ST_ATTACHMENT_ACCUM)
 #define ST_ATTACHMENT_SAMPLE_MASK (1 << ST_ATTACHMENT_SAMPLE)
 
 /**
- * Enumerations of state tracker context resources.
- */
-enum st_context_resource_type {
-   ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_2D,
-   ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_3D,
-   ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_POSITIVE_X,
-   ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_NEGATIVE_X,
-   ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_POSITIVE_Y,
-   ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
-   ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_POSITIVE_Z,
-   ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
-   ST_CONTEXT_RESOURCE_OPENGL_RENDERBUFFER,
-   ST_CONTEXT_RESOURCE_OPENVG_PARENT_IMAGE
-};
-
-/**
  * Flush flags.
  */
 #define ST_FLUSH_FRONT(1 << 0)
 #define ST_FLUSH_END_OF_FRAME (1 << 1)
 #define ST_FLUSH_WAIT (1 << 2)
 
 /**
  * Value to st_manager->get_param function.
  */
 enum st_manager_param {
@@ -176,33 +160,20 @@ enum st_manager_param {
 */
ST_MANAGER_BROKEN_INVALIDATE
 };
 
 struct pipe_context;
 struct pipe_resource;
 struct pipe_fence_handle;
 struct util_queue_monitoring;
 
 /**
- * Used in st_context_iface->get_resource_for_egl_image.
- */
-struct st_context_resource
-{
-   /* these fields are filled in by the caller */
-   enum st_context_resource_type type;
-   void *resource;
-
-   /* this is owned by the caller */
-   struct pipe_resource *texture;
-};
-
-/**
  * Used in st_manager_iface->get_egl_image.
  */
 struct st_egl_image
 {
/* this is owned by the caller */
struct pipe_resource *texture;
 
/* format only differs from texture->format for multi-planar (YUV): */
enum pipe_format format;
 
@@ -425,28 +396,20 @@ struct st_context_iface
void (*copy)(struct st_context_iface *stctxi,
 struct st_context_iface *stsrci, unsigned mask);
 
/**
 * Used to implement wglShareLists.
 */
boolean (*share)(struct st_context_iface *stctxi,
 struct st_context_iface *stsrci);
 
/**
-* Look up and return the info of a resource for EGLImage.
-*
-* This function is optional.
-*/
-   boolean (*get_resource_for_egl_image)(struct st_context_iface *stctxi,
- struct st_context_resource *stres);
-
-   /**
 * Start the thread if the API has a worker thread.
 * Called after the context has been created and fully initialized on both
 * sides (e.g. st/mesa and st/dri).
 */
void (*start_thread)(struct st_context_iface *stctxi);
 
/**
 * If the API is multithreaded, wait for all queued commands to complete.
 * Called from the main thread.
 */
-- 
2.11.0

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


[Mesa-dev] [PATCH 2/6] egl/dri: factor out egl_error_from_dri_image_error

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

---
 src/egl/drivers/dri2/egl_dri2.c | 54 -
 1 file changed, 26 insertions(+), 28 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 0db80a091f8..1407c96352e 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1840,20 +1840,43 @@ dri2_create_image_from_dri(_EGLDisplay *disp, 
__DRIimage *dri_image)
   return NULL;
}
 
_eglInitImage(_img->base, disp);
 
dri2_img->dri_image = dri_image;
 
return _img->base;
 }
 
+/**
+ * Translate a DRI Image extension error code into an EGL error code.
+ */
+static EGLint
+egl_error_from_dri_image_error(int dri_error)
+{
+   switch (dri_error) {
+   case __DRI_IMAGE_ERROR_SUCCESS:
+  return EGL_SUCCESS;
+   case __DRI_IMAGE_ERROR_BAD_ALLOC:
+  return EGL_BAD_ALLOC;
+   case __DRI_IMAGE_ERROR_BAD_MATCH:
+  return EGL_BAD_MATCH;
+   case __DRI_IMAGE_ERROR_BAD_PARAMETER:
+  return EGL_BAD_PARAMETER;
+   case __DRI_IMAGE_ERROR_BAD_ACCESS:
+  return EGL_BAD_ACCESS;
+   default:
+  assert(0);
+  return EGL_BAD_ALLOC;
+   }
+}
+
 static _EGLImage *
 dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx,
EGLClientBuffer buffer,
const EGLint *attr_list)
 {
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
GLuint renderbuffer = (GLuint) (uintptr_t) buffer;
__DRIimage *dri_image;
 
@@ -1942,49 +1965,24 @@ dri2_get_sync_values_chromium(_EGLDisplay *dpy, 
_EGLSurface *surf,
return dri2_dpy->vtbl->get_sync_values(dpy, surf, ust, msc, sbc);
 }
 
 /**
  * Set the error code after a call to
  * dri2_egl_image::dri_image::createImageFromTexture.
  */
 static void
 dri2_create_image_khr_texture_error(int dri_error)
 {
-   EGLint egl_error;
-
-   switch (dri_error) {
-   case __DRI_IMAGE_ERROR_SUCCESS:
-  return;
-
-   case __DRI_IMAGE_ERROR_BAD_ALLOC:
-  egl_error = EGL_BAD_ALLOC;
-  break;
-
-   case __DRI_IMAGE_ERROR_BAD_MATCH:
-  egl_error = EGL_BAD_MATCH;
-  break;
-
-   case __DRI_IMAGE_ERROR_BAD_PARAMETER:
-  egl_error = EGL_BAD_PARAMETER;
-  break;
-
-   case __DRI_IMAGE_ERROR_BAD_ACCESS:
-  egl_error = EGL_BAD_ACCESS;
-  break;
-
-   default:
-  assert(0);
-  egl_error = EGL_BAD_MATCH;
-  break;
-   }
+   EGLint egl_error = egl_error_from_dri_image_error(dri_error);
 
-   _eglError(egl_error, "dri2_create_image_khr_texture");
+   if (egl_error != EGL_SUCCESS)
+  _eglError(egl_error, "dri2_create_image_khr_texture");
 }
 
 static _EGLImage *
 dri2_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx,
EGLenum target,
EGLClientBuffer buffer,
const EGLint *attr_list)
 {
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
-- 
2.11.0

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


[Mesa-dev] [PATCH 1/6] dri_interface: add an error-returning version of createImageFromRenderbuffer

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

We ought to be able to distinguish between allocation errors and bad
parameters (non-existent renderbuffer object).

Bumps the version of the DRI Image extension to 17.
---
 include/GL/internal/dri_interface.h | 19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 783ff1c70d5..aefba92c024 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1173,21 +1173,21 @@ struct __DRIdri2ExtensionRec {
 */
__DRIcreateNewScreen2FunccreateNewScreen2;
 };
 
 
 /**
  * This extension provides functionality to enable various EGLImage
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 16
+#define __DRI_IMAGE_VERSION 17
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
  * tokens, except in the native endian of the CPU.  For example, on
  * little endian __DRI_IMAGE_FORMAT_XRGB corresponds to
  * MESA_FORMAT_XRGB, but MESA_FORMAT_XRGB_REV on big endian.
  *
  * __DRI_IMAGE_FORMAT_NONE is for images that aren't directly usable
  * by the driver (YUV planar formats) but serve as a base image for
  * creating sub-images for the different planes within the image.
@@ -1370,20 +1370,21 @@ enum __DRIChromaSiting {
 typedef struct __DRIimageRec  __DRIimage;
 typedef struct __DRIimageExtensionRec __DRIimageExtension;
 struct __DRIimageExtensionRec {
 __DRIextension base;
 
 __DRIimage *(*createImageFromName)(__DRIscreen *screen,
   int width, int height, int format,
   int name, int pitch,
   void *loaderPrivate);
 
+/* Deprecated since version 17; see createImageFromRenderbuffer2 */
 __DRIimage *(*createImageFromRenderbuffer)(__DRIcontext *context,
   int renderbuffer,
   void *loaderPrivate);
 
 void (*destroyImage)(__DRIimage *image);
 
 __DRIimage *(*createImage)(__DRIscreen *screen,
   int width, int height, int format,
   unsigned int use,
   void *loaderPrivate);
@@ -1618,20 +1619,36 @@ struct __DRIimageExtensionRec {
 * \param attribThe __DRI_IMAGE_FORMAT_MODIFIER_ATTRIB to query.
 * \param value A pointer to where to store the result of the query.
 *
 * Returns true upon success.
 *
 * \since 16
 */
GLboolean (*queryDmaBufFormatModifierAttribs)(__DRIscreen *screen,
  uint32_t fourcc, uint64_t 
modifier,
  int attrib, uint64_t *value);
+
+   /**
+* Create a DRI image from the given renderbuffer.
+*
+* \param context   the current DRI context
+* \param renderbuffer  the GL name of the renderbuffer
+* \param loaderPrivate for callbacks into the loader related to the image
+* \param error will be set to one of __DRI_IMAGE_ERROR_xxx
+* \return the newly created image on success, or NULL otherwise
+*
+* \since 17
+*/
+__DRIimage *(*createImageFromRenderbuffer2)(__DRIcontext *context,
+int renderbuffer,
+void *loaderPrivate,
+unsigned *error);
 };
 
 
 /**
  * This extension must be implemented by the loader and passed to the
  * driver at screen creation time.  The EGLImage entry points in the
  * various client APIs take opaque EGLImage handles and use this
  * extension to map them to a __DRIimage.  At version 1, this
  * extensions allows mapping EGLImage pointers to __DRIimage pointers,
  * but future versions could support other EGLImage-like, opaque types
-- 
2.11.0

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


[Mesa-dev] [PATCH 0/6] egl/st/dri: implement createImageFromRenderbuffer and add proper error handling

2017-10-06 Thread Nicolai Hähnle
Hi all,

It turns out that creating an EGLImage from GL_RENDERBUFFER was never
implement in st/dri, so do that.

While at it, extend the DRIImage extension so that we can return the
correct error code when e.g. a non-existing renderbuffer handle is
passed in by the application.

Please review!
Thanks,
Nicolai
--
 include/GL/internal/dri_interface.h  | 19 -
 src/egl/drivers/dri2/egl_dri2.c  | 77 +++---
 src/egl/drivers/dri2/platform_x11_dri3.c |  2 -
 src/gallium/include/state_tracker/st_api.h   | 37 -
 src/gallium/state_trackers/dri/dri2.c|  8 +-
 src/gallium/state_trackers/dri/dri_helpers.c | 65 +--
 src/gallium/state_trackers/dri/dri_helpers.h |  5 ++
 src/mesa/state_tracker/st_cb_fbo.h   |  5 ++
 8 files changed, 140 insertions(+), 78 deletions(-)

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


[Mesa-dev] [PATCH] st/mesa: don't clobber glGetInternalformat* buffer for GL_NUM_SAMPLE_COUNTS

2017-10-06 Thread Nicolai Hähnle
From: Nicolai Hähnle 

Applications might pass in a buffer that is sized too large and rely
on the extra space of the buffer not being overwritten.

Fixes 
dEQP-GLES31.functional.state_query.internal_format.partial_query.num_sample_counts

Cc: mesa-sta...@lists.freedesktop.org
---
 src/mesa/state_tracker/st_format.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/mesa/state_tracker/st_format.c 
b/src/mesa/state_tracker/st_format.c
index 5e38fe56890..65be09cbde2 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -2371,23 +2371,24 @@ st_QueryInternalFormat(struct gl_context *ctx, GLenum 
target,
 * and guaranteed to have at least 16 elements.
 */
assert(params != NULL);
 
switch (pname) {
case GL_SAMPLES:
   st_QuerySamplesForFormat(ctx, target, internalFormat, params);
   break;
 
case GL_NUM_SAMPLE_COUNTS: {
+  int samples[16];
   size_t num_samples;
   num_samples = st_QuerySamplesForFormat(ctx, target, internalFormat,
- params);
+ samples);
   params[0] = (GLint) num_samples;
   break;
}
case GL_INTERNALFORMAT_PREFERRED: {
   params[0] = GL_NONE;
 
   /* We need to resolve an internal format that is compatible with
* the passed internal format, and optimal to the driver. By now,
* we just validate that the passed internal format is supported by
* the driver, and if so return the same internal format, otherwise
-- 
2.11.0

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


Re: [Mesa-dev] [PATCH 1/2] i965: Change intel_disable_rb_aux_buffer into get_drawbuffer_index().

2017-10-06 Thread Kenneth Graunke
On Friday, October 6, 2017 10:57:57 AM PDT Nanley Chery wrote:
> On Thu, Oct 05, 2017 at 10:02:39PM -0700, Kenneth Graunke wrote:
> > The bulk of the work in intel_disable_rb_aux_buffer() is finding the
> > drawbuffer index for the given BO.  After that, disabling the auxiliary
> > buffers is an easy one liner.
> > 
> > This lets us ask whether a texture is also bound as a renderbuffer
> > before making any decisions.  We'll use this in the next patch.
> > 
> > Cc: nanleych...@gmail.com
> > Cc: ja...@jlekstrand.net
> > ---
> >  src/mesa/drivers/dri/i965/brw_draw.c | 18 ++
> >  1 file changed, 10 insertions(+), 8 deletions(-)
> > 
> > diff --git a/src/mesa/drivers/dri/i965/brw_draw.c 
> > b/src/mesa/drivers/dri/i965/brw_draw.c
> > index c7ed7284501..cab3758d7b5 100644
> > --- a/src/mesa/drivers/dri/i965/brw_draw.c
> > +++ b/src/mesa/drivers/dri/i965/brw_draw.c
> > @@ -336,22 +336,21 @@ brw_merge_inputs(struct brw_context *brw,
> > }
> >  }
> >  
> > -static bool
> > -intel_disable_rb_aux_buffer(struct brw_context *brw, const struct brw_bo 
> > *bo)
> > +static int
> > +get_drawbuffer_index(struct brw_context *brw, const struct brw_bo *bo)
> 
> We can now make brw point to a const struct.
> 
> >  {
> > const struct gl_framebuffer *fb = brw->ctx.DrawBuffer;
> > -   bool found = false;
> >  
> > for (unsigned i = 0; i < fb->_NumColorDrawBuffers; i++) {
> >const struct intel_renderbuffer *irb =
> >   intel_renderbuffer(fb->_ColorDrawBuffers[i]);
> >  
> >if (irb && irb->mt->bo == bo) {
> > - found = brw->draw_aux_buffer_disabled[i] = true;
> > + return i;
> >}
> > }
> >  
> > -   return found;
> > +   return -1;
> >  }
> >  
> >  /**
> > @@ -382,13 +381,14 @@ brw_predraw_resolve_inputs(struct brw_context *brw)
> >struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, i);
> >enum isl_format view_format =
> >   translate_tex_format(brw, tex_obj->_Format, sampler->sRGBDecode);
> > +  int drawbuf_idx = get_drawbuffer_index(brw, tex_obj->mt->bo);
> >  
> >bool aux_supported;
> >intel_miptree_prepare_texture(brw, tex_obj->mt, view_format,
> >  _supported);
> >  
> > -  if (!aux_supported && devinfo->gen >= 9 &&
> > -  intel_disable_rb_aux_buffer(brw, tex_obj->mt->bo)) {
> > +  if (!aux_supported && devinfo->gen >= 9 && drawbuf_idx != -1) {
> > + brw->draw_aux_buffer_disabled[i] = true;
> 
> Don't we want to index this array with drawbuf_idx? Maybe I don't
> understand how the texunit and drawbuffer arrays are related.. I'll do
> some reading.

No no...that's just a bug.  Thanks for catching this!

> >   perf_debug("Sampling renderbuffer with non-compressible format - "
> >  "turning off compression\n");
> >}
> > @@ -413,9 +413,11 @@ brw_predraw_resolve_inputs(struct brw_context *brw)
> >  
> >  if (tex_obj && tex_obj->mt) {
> > intel_miptree_prepare_image(brw, tex_obj->mt);
> > +   int drawbuf_idx = get_drawbuffer_index(brw, 
> > tex_obj->mt->bo);
> >  
> > if (tex_obj->mt->aux_usage == ISL_AUX_USAGE_CCS_E &&
> > -   intel_disable_rb_aux_buffer(brw, tex_obj->mt->bo)) {
> > +   drawbuf_idx != -1) {
> > +  brw->draw_aux_buffer_disabled[i] = true;
> 
> You're using the index of the shader stage here.

Even more bogus!  I'll fix this and resend.

--Ken


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


[Mesa-dev] [Bug 103128] [softpipe] piglit fs-ldexp regression

2017-10-06 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=103128

Bug ID: 103128
   Summary: [softpipe] piglit fs-ldexp regression
   Product: Mesa
   Version: git
  Hardware: x86-64 (AMD64)
OS: Linux (All)
Status: NEW
  Keywords: bisected, regression
  Severity: normal
  Priority: medium
 Component: Mesa core
  Assignee: mesa-dev@lists.freedesktop.org
  Reporter: v...@freedesktop.org
QA Contact: mesa-dev@lists.freedesktop.org
CC: die...@nuetzel-hh.de, mar...@gmail.com,
nhaeh...@gmail.com

mesa: bbe2082e7d38568433a5944a3f3fc7af4f079564 (master 17.3.0-devel)

$ ./bin/shader_runner
tests/spec/mesa_shader_integer_functions/execution/built-in-functions/fs-ldexp.shader_test
-auto
Probe color at (0,0)
  Expected: 0 255 0 255
  Observed: 255 255 0 255
Test failure on line 38
Probe color at (0,0)
  Expected: 0 255 0 255
  Observed: 255 255 0 255
Test failure on line 52
Probe color at (0,0)
  Expected: 0 255 0 255
  Observed: 255 255 0 255
Test failure on line 59
Probe color at (0,0)
  Expected: 0 255 0 255
  Observed: 255 255 0 255
Test failure on line 66
Probe color at (0,0)
  Expected: 0 255 0 255
  Observed: 255 255 0 255
Test failure on line 73
PIGLIT: {"result": "fail" }


6de5147d2024a282f064d3bcf6103240d283da72 is the first bad commit
commit 6de5147d2024a282f064d3bcf6103240d283da72
Author: Nicolai Hähnle 
Date:   Fri Sep 15 16:52:23 2017 +0200

st/glsl_to_tgsi: use LDEXP when available

Reviewed-by: Marek Olšák 
Tested-by: Dieter Nützel 

:04 04 bc78e5e07de9bab1751cfb3a24b78e5aa24af441
669a548343b85d800902f005853c05871a525d19 M  src
bisect run success

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


Re: [Mesa-dev] [PATCH 2/2] i965: Disable auxiliary buffers when there are self-dependencies.

2017-10-06 Thread Jason Ekstrand
On Fri, Oct 6, 2017 at 11:13 AM, Nanley Chery  wrote:

> On Thu, Oct 05, 2017 at 10:02:40PM -0700, Kenneth Graunke wrote:
> > Jason and I investigated several OpenGL CTS failures where the tests
> > bind the same texture for rendering and texturing, at the same time.
> > This has defined results as long as the reads happen before writes,
> > or the regions are non-overlapping.  Normally, this just works out.
> >
> > However, CCS can cause problems.  If the shader is reading one set of
> > pixels, and writing to different pixels that are adjacent, they may end
> > up being covered by the same CCS block.  So rendering may be writing a
> > CCS block, while the sampler is trying to read it.  Corruption ensues.
> >
> > Disabling CCS is unfortunate, but safe.
> >
> > Fixes several KHR-GL45.texture_barrier.* subtests.
> >
> > Cc: nanleych...@gmail.com
> > Cc: ja...@jlekstrand.net
> > ---
> >  src/mesa/drivers/dri/i965/brw_draw.c  |  8 +++-
> >  src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 13 +++--
> >  src/mesa/drivers/dri/i965/intel_mipmap_tree.h |  2 +-
> >  3 files changed, 15 insertions(+), 8 deletions(-)
> >
> > diff --git a/src/mesa/drivers/dri/i965/brw_draw.c
> b/src/mesa/drivers/dri/i965/brw_draw.c
> > index cab3758d7b5..c13fa8c367a 100644
> > --- a/src/mesa/drivers/dri/i965/brw_draw.c
> > +++ b/src/mesa/drivers/dri/i965/brw_draw.c
> > @@ -383,7 +383,13 @@ brw_predraw_resolve_inputs(struct brw_context *brw)
> >   translate_tex_format(brw, tex_obj->_Format,
> sampler->sRGBDecode);
> >int drawbuf_idx = get_drawbuffer_index(brw, tex_obj->mt->bo);
> >
> > -  bool aux_supported;
> > +  /* Disable auxiliary buffers if there's a self-dependency, where
> > +   * we're both texturing from and rendering to the same buffer.
> > +   * It's not necessarily safe - concurrent reads and writes to the
> > +   * CCS buffer can result in incorrect pixels.
> > +   */
> > +  bool aux_supported = drawbuf_idx == -1;
> > +
> >intel_miptree_prepare_texture(brw, tex_obj->mt, view_format,
> >  _supported);
> >
> > diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> > index 5b7cde82f65..29b93dd656c 100644
> > --- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> > +++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> > @@ -2651,9 +2651,10 @@ intel_miptree_prepare_texture_slices(struct
> brw_context *brw,
> >   enum isl_format view_format,
> >   uint32_t start_level, uint32_t
> num_levels,
> >   uint32_t start_layer, uint32_t
> num_layers,
> > - bool *aux_supported_out)
> > + bool *aux_supported)
>
> I find the name of this new parameter a little misleading. It suggests
> that the caller can determine that the aux surface is usable during the
> texture operation, when in fact it is the
> intel_miptree_texture_aux_usage function in the callee which does this
> determination. Since the caller can determine that the aux surface
> cannot be used, perhaps something like disable_aux would be a better
> fit?
>

I was thinking the same thing.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 2/2] i965: Disable auxiliary buffers when there are self-dependencies.

2017-10-06 Thread Nanley Chery
On Thu, Oct 05, 2017 at 10:02:40PM -0700, Kenneth Graunke wrote:
> Jason and I investigated several OpenGL CTS failures where the tests
> bind the same texture for rendering and texturing, at the same time.
> This has defined results as long as the reads happen before writes,
> or the regions are non-overlapping.  Normally, this just works out.
> 
> However, CCS can cause problems.  If the shader is reading one set of
> pixels, and writing to different pixels that are adjacent, they may end
> up being covered by the same CCS block.  So rendering may be writing a
> CCS block, while the sampler is trying to read it.  Corruption ensues.
> 
> Disabling CCS is unfortunate, but safe.
> 
> Fixes several KHR-GL45.texture_barrier.* subtests.
> 
> Cc: nanleych...@gmail.com
> Cc: ja...@jlekstrand.net
> ---
>  src/mesa/drivers/dri/i965/brw_draw.c  |  8 +++-
>  src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 13 +++--
>  src/mesa/drivers/dri/i965/intel_mipmap_tree.h |  2 +-
>  3 files changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_draw.c 
> b/src/mesa/drivers/dri/i965/brw_draw.c
> index cab3758d7b5..c13fa8c367a 100644
> --- a/src/mesa/drivers/dri/i965/brw_draw.c
> +++ b/src/mesa/drivers/dri/i965/brw_draw.c
> @@ -383,7 +383,13 @@ brw_predraw_resolve_inputs(struct brw_context *brw)
>   translate_tex_format(brw, tex_obj->_Format, sampler->sRGBDecode);
>int drawbuf_idx = get_drawbuffer_index(brw, tex_obj->mt->bo);
>  
> -  bool aux_supported;
> +  /* Disable auxiliary buffers if there's a self-dependency, where
> +   * we're both texturing from and rendering to the same buffer.
> +   * It's not necessarily safe - concurrent reads and writes to the
> +   * CCS buffer can result in incorrect pixels.
> +   */
> +  bool aux_supported = drawbuf_idx == -1;
> +
>intel_miptree_prepare_texture(brw, tex_obj->mt, view_format,
>  _supported);
>  
> diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
> b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> index 5b7cde82f65..29b93dd656c 100644
> --- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> +++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> @@ -2651,9 +2651,10 @@ intel_miptree_prepare_texture_slices(struct 
> brw_context *brw,
>   enum isl_format view_format,
>   uint32_t start_level, uint32_t 
> num_levels,
>   uint32_t start_layer, uint32_t 
> num_layers,
> - bool *aux_supported_out)
> + bool *aux_supported)

I find the name of this new parameter a little misleading. It suggests
that the caller can determine that the aux surface is usable during the
texture operation, when in fact it is the
intel_miptree_texture_aux_usage function in the callee which does this
determination. Since the caller can determine that the aux surface
cannot be used, perhaps something like disable_aux would be a better
fit?

>  {
> -   enum isl_aux_usage aux_usage =
> +   enum isl_aux_usage aux_usage = aux_supported && !*aux_supported ?
> +  ISL_AUX_USAGE_NONE :
>intel_miptree_texture_aux_usage(brw, mt, view_format);
> bool clear_supported = aux_usage != ISL_AUX_USAGE_NONE;
>  
> @@ -2667,20 +2668,20 @@ intel_miptree_prepare_texture_slices(struct 
> brw_context *brw,
> intel_miptree_prepare_access(brw, mt, start_level, num_levels,
>  start_layer, num_layers,
>  aux_usage, clear_supported);
> -   if (aux_supported_out)
> -  *aux_supported_out = aux_usage != ISL_AUX_USAGE_NONE;
> +   if (aux_supported)
> +  *aux_supported = aux_usage != ISL_AUX_USAGE_NONE;
>  }
>  
>  void
>  intel_miptree_prepare_texture(struct brw_context *brw,
>struct intel_mipmap_tree *mt,
>enum isl_format view_format,
> -  bool *aux_supported_out)
> +  bool *aux_supported)
>  {
> intel_miptree_prepare_texture_slices(brw, mt, view_format,
>  0, INTEL_REMAINING_LEVELS,
>  0, INTEL_REMAINING_LAYERS,
> -aux_supported_out);
> +aux_supported);
>  }
>  
>  void
> diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.h 
> b/src/mesa/drivers/dri/i965/intel_mipmap_tree.h
> index 2fce28c524b..0da7fafe601 100644
> --- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.h
> +++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.h
> @@ -640,7 +640,7 @@ void
>  intel_miptree_prepare_texture(struct brw_context *brw,
>struct intel_mipmap_tree *mt,
>enum isl_format view_format,
> -   

Re: [Mesa-dev] [PATCH 1/2] i965: Change intel_disable_rb_aux_buffer into get_drawbuffer_index().

2017-10-06 Thread Jason Ekstrand
On Fri, Oct 6, 2017 at 10:57 AM, Nanley Chery  wrote:

> On Thu, Oct 05, 2017 at 10:02:39PM -0700, Kenneth Graunke wrote:
> > The bulk of the work in intel_disable_rb_aux_buffer() is finding the
> > drawbuffer index for the given BO.  After that, disabling the auxiliary
> > buffers is an easy one liner.
> >
> > This lets us ask whether a texture is also bound as a renderbuffer
> > before making any decisions.  We'll use this in the next patch.
> >
> > Cc: nanleych...@gmail.com
> > Cc: ja...@jlekstrand.net
> > ---
> >  src/mesa/drivers/dri/i965/brw_draw.c | 18 ++
> >  1 file changed, 10 insertions(+), 8 deletions(-)
> >
> > diff --git a/src/mesa/drivers/dri/i965/brw_draw.c
> b/src/mesa/drivers/dri/i965/brw_draw.c
> > index c7ed7284501..cab3758d7b5 100644
> > --- a/src/mesa/drivers/dri/i965/brw_draw.c
> > +++ b/src/mesa/drivers/dri/i965/brw_draw.c
> > @@ -336,22 +336,21 @@ brw_merge_inputs(struct brw_context *brw,
> > }
> >  }
> >
> > -static bool
> > -intel_disable_rb_aux_buffer(struct brw_context *brw, const struct
> brw_bo *bo)
> > +static int
> > +get_drawbuffer_index(struct brw_context *brw, const struct brw_bo *bo)
>
> We can now make brw point to a const struct.
>
> >  {
> > const struct gl_framebuffer *fb = brw->ctx.DrawBuffer;
> > -   bool found = false;
> >
> > for (unsigned i = 0; i < fb->_NumColorDrawBuffers; i++) {
> >const struct intel_renderbuffer *irb =
> >   intel_renderbuffer(fb->_ColorDrawBuffers[i]);
> >
> >if (irb && irb->mt->bo == bo) {
> > - found = brw->draw_aux_buffer_disabled[i] = true;
> > + return i;
> >}
> > }
> >
> > -   return found;
> > +   return -1;
> >  }
> >
> >  /**
> > @@ -382,13 +381,14 @@ brw_predraw_resolve_inputs(struct brw_context
> *brw)
> >struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, i);
> >enum isl_format view_format =
> >   translate_tex_format(brw, tex_obj->_Format,
> sampler->sRGBDecode);
> > +  int drawbuf_idx = get_drawbuffer_index(brw, tex_obj->mt->bo);
> >
> >bool aux_supported;
> >intel_miptree_prepare_texture(brw, tex_obj->mt, view_format,
> >  _supported);
> >
> > -  if (!aux_supported && devinfo->gen >= 9 &&
> > -  intel_disable_rb_aux_buffer(brw, tex_obj->mt->bo)) {
> > +  if (!aux_supported && devinfo->gen >= 9 && drawbuf_idx != -1) {
> > + brw->draw_aux_buffer_disabled[i] = true;
>
> Don't we want to index this array with drawbuf_idx? Maybe I don't
> understand how the texunit and drawbuffer arrays are related.. I'll do
> some reading.
>

Good catch.  You are 100% right.


> >   perf_debug("Sampling renderbuffer with non-compressible format
> - "
> >  "turning off compression\n");
> >}
> > @@ -413,9 +413,11 @@ brw_predraw_resolve_inputs(struct brw_context *brw)
> >
> >  if (tex_obj && tex_obj->mt) {
> > intel_miptree_prepare_image(brw, tex_obj->mt);
> > +   int drawbuf_idx = get_drawbuffer_index(brw,
> tex_obj->mt->bo);
> >
> > if (tex_obj->mt->aux_usage == ISL_AUX_USAGE_CCS_E &&
> > -   intel_disable_rb_aux_buffer(brw, tex_obj->mt->bo)) {
> > +   drawbuf_idx != -1) {
> > +  brw->draw_aux_buffer_disabled[i] = true;
>
> You're using the index of the shader stage here.
>
> >perf_debug("Using renderbuffer as shader image -
> turning "
> >   "off lossless compression\n");
> > }
> > --
> > 2.14.2
> >
>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 1/2] i965: Change intel_disable_rb_aux_buffer into get_drawbuffer_index().

2017-10-06 Thread Nanley Chery
On Thu, Oct 05, 2017 at 10:02:39PM -0700, Kenneth Graunke wrote:
> The bulk of the work in intel_disable_rb_aux_buffer() is finding the
> drawbuffer index for the given BO.  After that, disabling the auxiliary
> buffers is an easy one liner.
> 
> This lets us ask whether a texture is also bound as a renderbuffer
> before making any decisions.  We'll use this in the next patch.
> 
> Cc: nanleych...@gmail.com
> Cc: ja...@jlekstrand.net
> ---
>  src/mesa/drivers/dri/i965/brw_draw.c | 18 ++
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_draw.c 
> b/src/mesa/drivers/dri/i965/brw_draw.c
> index c7ed7284501..cab3758d7b5 100644
> --- a/src/mesa/drivers/dri/i965/brw_draw.c
> +++ b/src/mesa/drivers/dri/i965/brw_draw.c
> @@ -336,22 +336,21 @@ brw_merge_inputs(struct brw_context *brw,
> }
>  }
>  
> -static bool
> -intel_disable_rb_aux_buffer(struct brw_context *brw, const struct brw_bo *bo)
> +static int
> +get_drawbuffer_index(struct brw_context *brw, const struct brw_bo *bo)

We can now make brw point to a const struct.

>  {
> const struct gl_framebuffer *fb = brw->ctx.DrawBuffer;
> -   bool found = false;
>  
> for (unsigned i = 0; i < fb->_NumColorDrawBuffers; i++) {
>const struct intel_renderbuffer *irb =
>   intel_renderbuffer(fb->_ColorDrawBuffers[i]);
>  
>if (irb && irb->mt->bo == bo) {
> - found = brw->draw_aux_buffer_disabled[i] = true;
> + return i;
>}
> }
>  
> -   return found;
> +   return -1;
>  }
>  
>  /**
> @@ -382,13 +381,14 @@ brw_predraw_resolve_inputs(struct brw_context *brw)
>struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, i);
>enum isl_format view_format =
>   translate_tex_format(brw, tex_obj->_Format, sampler->sRGBDecode);
> +  int drawbuf_idx = get_drawbuffer_index(brw, tex_obj->mt->bo);
>  
>bool aux_supported;
>intel_miptree_prepare_texture(brw, tex_obj->mt, view_format,
>  _supported);
>  
> -  if (!aux_supported && devinfo->gen >= 9 &&
> -  intel_disable_rb_aux_buffer(brw, tex_obj->mt->bo)) {
> +  if (!aux_supported && devinfo->gen >= 9 && drawbuf_idx != -1) {
> + brw->draw_aux_buffer_disabled[i] = true;

Don't we want to index this array with drawbuf_idx? Maybe I don't
understand how the texunit and drawbuffer arrays are related.. I'll do
some reading.

>   perf_debug("Sampling renderbuffer with non-compressible format - "
>  "turning off compression\n");
>}
> @@ -413,9 +413,11 @@ brw_predraw_resolve_inputs(struct brw_context *brw)
>  
>  if (tex_obj && tex_obj->mt) {
> intel_miptree_prepare_image(brw, tex_obj->mt);
> +   int drawbuf_idx = get_drawbuffer_index(brw, tex_obj->mt->bo);
>  
> if (tex_obj->mt->aux_usage == ISL_AUX_USAGE_CCS_E &&
> -   intel_disable_rb_aux_buffer(brw, tex_obj->mt->bo)) {
> +   drawbuf_idx != -1) {
> +  brw->draw_aux_buffer_disabled[i] = true;

You're using the index of the shader stage here.

>perf_debug("Using renderbuffer as shader image - turning "
>   "off lossless compression\n");
> }
> -- 
> 2.14.2
> 
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] intel/compiler: Make brw_nir_lower_intrinsics compute-specific

2017-10-06 Thread Jordan Justen
Reviewed-by: Jordan Justen 

On 2017-10-06 10:20:28, Jason Ekstrand wrote:
> It's already only ever called from brw_compile_cs and only handles
> compute intrinsics.  Let's just make it CS-specific.  We can always
> make it handle other stages again later if we want.
> 
> Cc: Jordan Justen 
> 
> ---
>  src/intel/Makefile.sources |  2 +-
>  src/intel/compiler/brw_fs.cpp  |  2 +-
>  src/intel/compiler/brw_nir.h   |  4 ++--
>  ..._intrinsics.c => brw_nir_lower_cs_intrinsics.c} | 22 
> --
>  4 files changed, 12 insertions(+), 18 deletions(-)
>  rename src/intel/compiler/{brw_nir_intrinsics.c => 
> brw_nir_lower_cs_intrinsics.c} (89%)
> 
> diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources
> index 9672dcc..b835533 100644
> --- a/src/intel/Makefile.sources
> +++ b/src/intel/Makefile.sources
> @@ -75,7 +75,7 @@ COMPILER_FILES = \
> compiler/brw_nir_analyze_boolean_resolves.c \
> compiler/brw_nir_analyze_ubo_ranges.c \
> compiler/brw_nir_attribute_workarounds.c \
> -   compiler/brw_nir_intrinsics.c \
> +   compiler/brw_nir_lower_cs_intrinsics.c \
> compiler/brw_nir_opt_peephole_ffma.c \
> compiler/brw_nir_tcs_workarounds.c \
> compiler/brw_packed_float.c \
> diff --git a/src/intel/compiler/brw_fs.cpp b/src/intel/compiler/brw_fs.cpp
> index 6f5f21d..371df71 100644
> --- a/src/intel/compiler/brw_fs.cpp
> +++ b/src/intel/compiler/brw_fs.cpp
> @@ -6766,7 +6766,7 @@ brw_compile_cs(const struct brw_compiler *compiler, 
> void *log_data,
>MAX2(shader->num_uniforms,
> (unsigned)4 * (prog_data->thread_local_id_index + 1));
>  
> -   brw_nir_lower_intrinsics(shader, _data->base);
> +   brw_nir_lower_cs_intrinsics(shader, prog_data);
> shader = brw_postprocess_nir(shader, compiler, true);
>  
> prog_data->local_size[0] = shader->info.cs.local_size[0];
> diff --git a/src/intel/compiler/brw_nir.h b/src/intel/compiler/brw_nir.h
> index f4b13b1..6f64a73 100644
> --- a/src/intel/compiler/brw_nir.h
> +++ b/src/intel/compiler/brw_nir.h
> @@ -95,8 +95,8 @@ void brw_nir_analyze_boolean_resolves(nir_shader *nir);
>  nir_shader *brw_preprocess_nir(const struct brw_compiler *compiler,
> nir_shader *nir);
>  
> -bool brw_nir_lower_intrinsics(nir_shader *nir,
> -  struct brw_stage_prog_data *prog_data);
> +bool brw_nir_lower_cs_intrinsics(nir_shader *nir,
> + struct brw_cs_prog_data *prog_data);
>  void brw_nir_lower_vs_inputs(nir_shader *nir,
>   bool use_legacy_snorm_formula,
>   const uint8_t *vs_attrib_wa_flags);
> diff --git a/src/intel/compiler/brw_nir_intrinsics.c 
> b/src/intel/compiler/brw_nir_lower_cs_intrinsics.c
> similarity index 89%
> rename from src/intel/compiler/brw_nir_intrinsics.c
> rename to src/intel/compiler/brw_nir_lower_cs_intrinsics.c
> index abbbc6f..602ef2e 100644
> --- a/src/intel/compiler/brw_nir_intrinsics.c
> +++ b/src/intel/compiler/brw_nir_lower_cs_intrinsics.c
> @@ -26,10 +26,7 @@
>  
>  struct lower_intrinsics_state {
> nir_shader *nir;
> -   union {
> -  struct brw_stage_prog_data *prog_data;
> -  struct brw_cs_prog_data *cs_prog_data;
> -   };
> +   struct brw_cs_prog_data *prog_data;
> nir_function_impl *impl;
> bool progress;
> nir_builder builder;
> @@ -50,9 +47,9 @@ read_thread_local_id(struct lower_intrinsics_state *state)
> if (group_size <= 8)
>return nir_imm_int(b, 0);
>  
> -   assert(state->cs_prog_data->thread_local_id_index >= 0);
> +   assert(state->prog_data->thread_local_id_index >= 0);
> state->cs_thread_id_used = true;
> -   const int id_index = state->cs_prog_data->thread_local_id_index;
> +   const int id_index = state->prog_data->thread_local_id_index;
>  
> nir_intrinsic_instr *load =
>nir_intrinsic_instr_create(nir, nir_intrinsic_load_uniform);
> @@ -84,7 +81,6 @@ lower_cs_intrinsics_convert_block(struct 
> lower_intrinsics_state *state,
>nir_ssa_def *sysval;
>switch (intrinsic->intrinsic) {
>case nir_intrinsic_load_local_invocation_index: {
> - assert(nir->stage == MESA_SHADER_COMPUTE);
>   /* We construct the local invocation index from:
>*
>*gl_LocalInvocationIndex =
> @@ -97,7 +93,6 @@ lower_cs_intrinsics_convert_block(struct 
> lower_intrinsics_state *state,
>}
>  
>case nir_intrinsic_load_local_invocation_id: {
> - assert(nir->stage == MESA_SHADER_COMPUTE);
>   /* We lower gl_LocalInvocationID from gl_LocalInvocationIndex based
>* on this formula:
>*
> @@ -156,11 +151,10 @@ lower_cs_intrinsics_convert_impl(struct 
> lower_intrinsics_state *state)
>  }
>  
>  bool
> -brw_nir_lower_intrinsics(nir_shader *nir, struct 

Re: [Mesa-dev] [PATCH 00/21] intel/compiler: Rework the world of push/pull params

2017-10-06 Thread Jordan Justen
Series Reviewed-by: Jordan Justen 

Although, I think you said you might rewrite patch 13 (the
thread_local_id_index patch). If you just add the small stage check I
mentioned then you can add my r-b for it.

-Jordan

On 2017-09-29 14:25:00, Jason Ekstrand wrote:
> This little series reworks basically the entire world of push/pull params.
> This refactor has been on my ToDo list ever since I hooked up push
> constants in Vulkan over two years ago.  Recently, thanks to some
> up-and-coming Vulkan features, the pain of the old system increased enough
> to finally push me over the edge to make the changes.
> 
> Historically, we have had two arrays in brw_stage_prog_data: param and
> pull_param which are arrays of pointers to a gl_constant_value union.  In
> state setup, we would walk the arrays, dereference each pointer, and copy
> the value into our push or pull constant storage.  These pointers may point
> to uniform storage, ARB program parameter storage, or random bits of API
> state that we've gathered up.  This model has never really matched what we
> want in Vulkan because we don't have a dedicated CPU memory location where
> the push constant values are stored that we can know at compile time.
> Instead, in Vulkan, we just store offsets into a struct anv_push_constants
> in the pointers and trust that the back-end compiler will re-arrange the
> array without ever dereferencing any of the pointers.
> 
> This primary purpose of this series is to move us over to a model where the
> param and pull_param arrays are just arrays of uint32_t handles which have
> a meaning which is defined by the driver.  This makes the contract between
> compiler and driver a bit more clear and we stop passing random pointers to
> API state into the back-end compiler.
> 
> The secondary purpose of this series is to add support for "builtin"
> params.  These params have a well-defined meaning as per their builtin enum
> name and will get filled out by the driver during state upload.  Having a
> well-defined meaning means that they can be added by either the front-end
> or back-end compilers without having to do a lot of juggling in order to
> make them work in two drivers.  One example of this is the last patch which
> moves the thread local id from being this weird special-cased thing to
> being a normal builtin param.  We still have to do a bit of special-case
> work because it needs to be part of the per-thread push constants but other
> than that, it now works more-or-less like any other param.
> 
> Thirdly, I did a bunch of refactoring to try and get us to the point where
> the param and pull_param arrays are, as far as practical, out parameters of
> the compilation process rather than in-out parameters.  In particular, we
> stop trying to estimate in the driver how much space we need to allocate
> for params and just allocate what we need on-demand in the various places
> that set them up.
> 
> This series can be found here:
> 
> https://cgit.freedesktop.org/~jekstrand/mesa/log/?h=wip/i965-push-enums
> 
> Jason Ekstrand (21):
>   i965: Move brw_upload_pull_constants to gen6_constant_state.c
>   i965: Add a helper for populating constant buffers
>   i965: Get rid of gen7_cs_state.c
>   intel: Rewrite the world of push/pull params
>   i965: Use prog->info.num_images for needs_dc computation
>   i965: Store image_param in brw_context instead of prog_data
>   anv/pipeline: Add a mem_ctx parameter to anv_pipeline_compile
>   anv/pipeline: Ralloc prog_data::param of the compile mem_ctx
>   intel/compiler: Add a flag for pull constant support
>   i965: Only add the wpos state reference if we lowered something
>   intel/compiler: Stop adding params for texture sizes
>   intel/compiler: Add a helper for growing the prog_data::param array
>   intel/cs: Grow prog_data::param on-demand for thread_local_id_index
>   intel/vs: Grow the param array for clip planes
>   anv/pipeline: Whack nir->num_uniforms to MAX_PUSH_CONSTANT_SIZE
>   anv/pipeline: Grow the param array for images
>   anv/pipeline: Refactor setup of the prog_data::param array
>   ralloc: Allow reparenting to a NULL context
>   intel: Allocate prog_data::[pull_]param deeper inside the compiler
>   intel/compiler: Allocate pull_param in assign_constant_locations
>   intel/cs: Make thread_local_id a regular builtin param
> 
>  src/intel/blorp/blorp.c  |   2 +-
>  src/intel/compiler/brw_compiler.h|  98 --
>  src/intel/compiler/brw_fs.cpp|  78 
>  src/intel/compiler/brw_fs.h  |   6 +-
>  src/intel/compiler/brw_fs_visitor.cpp|  15 +-
>  src/intel/compiler/brw_nir.h |   5 +-
>  src/intel/compiler/brw_nir_intrinsics.c  |  18 +-
>  src/intel/compiler/brw_vec4.cpp  |  18 +-
>  src/intel/compiler/brw_vec4_visitor.cpp  |   7 +-
>  src/intel/compiler/brw_vec4_vs.h |   3 -
>  

Re: [Mesa-dev] [PATCH 10/21] i965: Only add the wpos state reference if we lowered something

2017-10-06 Thread Jason Ekstrand
On Wed, Oct 4, 2017 at 7:31 PM, Jordan Justen 
wrote:

> On 2017-09-29 14:25:10, Jason Ekstrand wrote:
> > Otherwise, in the ARB program case _mesa_add_state_reference may grow
> > the parameter array which will cause brw_nir_setup_arb_uniforms to write
> > past the end of the param array because it only looks at the parameter
> > list length but the parma array is allocated based on nir->num_uniforms.
> > The only reason this hasn't caused us problems is because we are padding
> > out the param array for fragment programs unnecessarily.
> > ---
> >  src/mesa/drivers/dri/i965/brw_program.c | 9 +
> >  1 file changed, 5 insertions(+), 4 deletions(-)
> >
> > diff --git a/src/mesa/drivers/dri/i965/brw_program.c
> b/src/mesa/drivers/dri/i965/brw_program.c
> > index ee464fc..7eec6f7 100644
> > --- a/src/mesa/drivers/dri/i965/brw_program.c
> > +++ b/src/mesa/drivers/dri/i965/brw_program.c
> > @@ -88,8 +88,6 @@ brw_create_nir(struct brw_context *brw,
> > }
> > nir_validate_shader(nir);
> >
> > -   (void)progress;
> > -
> > nir = brw_preprocess_nir(brw->screen->compiler, nir);
> >
> > if (stage == MESA_SHADER_FRAGMENT) {
> > @@ -98,10 +96,13 @@ brw_create_nir(struct brw_context *brw,
> >   .fs_coord_pixel_center_integer = 1,
> >   .fs_coord_origin_upper_left = 1,
> >};
> > -  _mesa_add_state_reference(prog->Parameters,
> > -(gl_state_index *)
> wpos_options.state_tokens);
> >
> > +  progress = false;
>
> Should we move the `progress` declaration here?
>
> >NIR_PASS(progress, nir, nir_lower_wpos_ytransform, _options);
> > +  if (progress) {
> > + _mesa_add_state_reference(prog->Parameters,
> > +   (gl_state_index *)
> wpos_options.state_tokens);
> > +  }
> > }
> >
> > NIR_PASS(progress, nir, nir_lower_system_values);
>
> And convert this to NIR_PASS_V?
>

Sure.  I thought about that but didn't.  Done.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] intel/compiler: Make brw_nir_lower_intrinsics compute-specific

2017-10-06 Thread Jason Ekstrand
It's already only ever called from brw_compile_cs and only handles
compute intrinsics.  Let's just make it CS-specific.  We can always
make it handle other stages again later if we want.

Cc: Jordan Justen 

---
 src/intel/Makefile.sources |  2 +-
 src/intel/compiler/brw_fs.cpp  |  2 +-
 src/intel/compiler/brw_nir.h   |  4 ++--
 ..._intrinsics.c => brw_nir_lower_cs_intrinsics.c} | 22 --
 4 files changed, 12 insertions(+), 18 deletions(-)
 rename src/intel/compiler/{brw_nir_intrinsics.c => 
brw_nir_lower_cs_intrinsics.c} (89%)

diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources
index 9672dcc..b835533 100644
--- a/src/intel/Makefile.sources
+++ b/src/intel/Makefile.sources
@@ -75,7 +75,7 @@ COMPILER_FILES = \
compiler/brw_nir_analyze_boolean_resolves.c \
compiler/brw_nir_analyze_ubo_ranges.c \
compiler/brw_nir_attribute_workarounds.c \
-   compiler/brw_nir_intrinsics.c \
+   compiler/brw_nir_lower_cs_intrinsics.c \
compiler/brw_nir_opt_peephole_ffma.c \
compiler/brw_nir_tcs_workarounds.c \
compiler/brw_packed_float.c \
diff --git a/src/intel/compiler/brw_fs.cpp b/src/intel/compiler/brw_fs.cpp
index 6f5f21d..371df71 100644
--- a/src/intel/compiler/brw_fs.cpp
+++ b/src/intel/compiler/brw_fs.cpp
@@ -6766,7 +6766,7 @@ brw_compile_cs(const struct brw_compiler *compiler, void 
*log_data,
   MAX2(shader->num_uniforms,
(unsigned)4 * (prog_data->thread_local_id_index + 1));
 
-   brw_nir_lower_intrinsics(shader, _data->base);
+   brw_nir_lower_cs_intrinsics(shader, prog_data);
shader = brw_postprocess_nir(shader, compiler, true);
 
prog_data->local_size[0] = shader->info.cs.local_size[0];
diff --git a/src/intel/compiler/brw_nir.h b/src/intel/compiler/brw_nir.h
index f4b13b1..6f64a73 100644
--- a/src/intel/compiler/brw_nir.h
+++ b/src/intel/compiler/brw_nir.h
@@ -95,8 +95,8 @@ void brw_nir_analyze_boolean_resolves(nir_shader *nir);
 nir_shader *brw_preprocess_nir(const struct brw_compiler *compiler,
nir_shader *nir);
 
-bool brw_nir_lower_intrinsics(nir_shader *nir,
-  struct brw_stage_prog_data *prog_data);
+bool brw_nir_lower_cs_intrinsics(nir_shader *nir,
+ struct brw_cs_prog_data *prog_data);
 void brw_nir_lower_vs_inputs(nir_shader *nir,
  bool use_legacy_snorm_formula,
  const uint8_t *vs_attrib_wa_flags);
diff --git a/src/intel/compiler/brw_nir_intrinsics.c 
b/src/intel/compiler/brw_nir_lower_cs_intrinsics.c
similarity index 89%
rename from src/intel/compiler/brw_nir_intrinsics.c
rename to src/intel/compiler/brw_nir_lower_cs_intrinsics.c
index abbbc6f..602ef2e 100644
--- a/src/intel/compiler/brw_nir_intrinsics.c
+++ b/src/intel/compiler/brw_nir_lower_cs_intrinsics.c
@@ -26,10 +26,7 @@
 
 struct lower_intrinsics_state {
nir_shader *nir;
-   union {
-  struct brw_stage_prog_data *prog_data;
-  struct brw_cs_prog_data *cs_prog_data;
-   };
+   struct brw_cs_prog_data *prog_data;
nir_function_impl *impl;
bool progress;
nir_builder builder;
@@ -50,9 +47,9 @@ read_thread_local_id(struct lower_intrinsics_state *state)
if (group_size <= 8)
   return nir_imm_int(b, 0);
 
-   assert(state->cs_prog_data->thread_local_id_index >= 0);
+   assert(state->prog_data->thread_local_id_index >= 0);
state->cs_thread_id_used = true;
-   const int id_index = state->cs_prog_data->thread_local_id_index;
+   const int id_index = state->prog_data->thread_local_id_index;
 
nir_intrinsic_instr *load =
   nir_intrinsic_instr_create(nir, nir_intrinsic_load_uniform);
@@ -84,7 +81,6 @@ lower_cs_intrinsics_convert_block(struct 
lower_intrinsics_state *state,
   nir_ssa_def *sysval;
   switch (intrinsic->intrinsic) {
   case nir_intrinsic_load_local_invocation_index: {
- assert(nir->stage == MESA_SHADER_COMPUTE);
  /* We construct the local invocation index from:
   *
   *gl_LocalInvocationIndex =
@@ -97,7 +93,6 @@ lower_cs_intrinsics_convert_block(struct 
lower_intrinsics_state *state,
   }
 
   case nir_intrinsic_load_local_invocation_id: {
- assert(nir->stage == MESA_SHADER_COMPUTE);
  /* We lower gl_LocalInvocationID from gl_LocalInvocationIndex based
   * on this formula:
   *
@@ -156,11 +151,10 @@ lower_cs_intrinsics_convert_impl(struct 
lower_intrinsics_state *state)
 }
 
 bool
-brw_nir_lower_intrinsics(nir_shader *nir, struct brw_stage_prog_data 
*prog_data)
+brw_nir_lower_cs_intrinsics(nir_shader *nir,
+struct brw_cs_prog_data *prog_data)
 {
-   /* Currently we only lower intrinsics for compute shaders */
-   if (nir->stage != MESA_SHADER_COMPUTE)
-  return false;
+   assert(nir->stage == MESA_SHADER_COMPUTE);
 
bool 

Re: [Mesa-dev] [PATCH 20/21] intel/compiler: Allocate pull_param in assign_constant_locations

2017-10-06 Thread Jason Ekstrand
On Fri, Oct 6, 2017 at 9:40 AM, Jordan Justen 
wrote:

> On 2017-09-29 14:25:20, Jason Ekstrand wrote:
> > diff --git a/src/intel/compiler/brw_vec4_visitor.cpp
> b/src/intel/compiler/brw_vec4_visitor.cpp
> > index ff5cd2d..ae51619 100644
> > --- a/src/intel/compiler/brw_vec4_visitor.cpp
> > +++ b/src/intel/compiler/brw_vec4_visitor.cpp
> > @@ -1782,6 +1782,11 @@ vec4_visitor::move_uniform_array_access_to_pull_
> constants()
> >return;
> > }
> >
> > +   /* Allocate the pull_params array */
> > +   assert(stage_prog_data->nr_pull_params == 0);
> > +   stage_prog_data->pull_param = ralloc_array(mem_ctx, uint32_t,
> > +  this->uniforms * 4);
>
> Why allocate this based on this->uniforms if nr_pull_params is 0?
>

At this point in the function nr_pull_params is always 0.  It gets assigned
later on in the function but we know that it will be <= uniforms * 4.

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


[Mesa-dev] [Bug 103126] glthread doesn't offload anything in Witcher 2

2017-10-06 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=103126

--- Comment #1 from Alexander Tsoy  ---
My GPU:
01:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc.
[AMD/ATI] Tonga PRO [Radeon R9 285/380] [1002:6939] (rev f1) (prog-if 00 [VGA
controller])

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


[Mesa-dev] [Bug 103126] glthread doesn't offload anything in Witcher 2

2017-10-06 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=103126

Bug ID: 103126
   Summary: glthread doesn't offload anything in Witcher 2
   Product: Mesa
   Version: 17.2
  Hardware: Other
OS: All
Status: NEW
  Severity: normal
  Priority: medium
 Component: Mesa core
  Assignee: mesa-dev@lists.freedesktop.org
  Reporter: alexan...@tsoy.me
QA Contact: mesa-dev@lists.freedesktop.org

Created attachment 134710
  --> https://bugs.freedesktop.org/attachment.cgi?id=134710=edit
witcher2_glthread.png

Even though there were reports that glthread improves performance in Witcher 2,
and it was enabled via drirc in recent mesa versions, it never worked for me.
"API-thread-offloaded-slots" always stays at zero, see attached screenshot.

In other games like Civilization 5 glthread works on my system as expected.


My current package versions:

linux-4.13.5
mesa-17.2.2
llvm-5.0.0
libdrm-2.4.82
xf86-video-amdgpu-1.4.0

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


Re: [Mesa-dev] [PATCH 20/21] intel/compiler: Allocate pull_param in assign_constant_locations

2017-10-06 Thread Jordan Justen
On 2017-09-29 14:25:20, Jason Ekstrand wrote:
> diff --git a/src/intel/compiler/brw_vec4_visitor.cpp 
> b/src/intel/compiler/brw_vec4_visitor.cpp
> index ff5cd2d..ae51619 100644
> --- a/src/intel/compiler/brw_vec4_visitor.cpp
> +++ b/src/intel/compiler/brw_vec4_visitor.cpp
> @@ -1782,6 +1782,11 @@ 
> vec4_visitor::move_uniform_array_access_to_pull_constants()
>return;
> }
>  
> +   /* Allocate the pull_params array */
> +   assert(stage_prog_data->nr_pull_params == 0);
> +   stage_prog_data->pull_param = ralloc_array(mem_ctx, uint32_t,
> +  this->uniforms * 4);

Why allocate this based on this->uniforms if nr_pull_params is 0?

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


Re: [Mesa-dev] [PATCH] Replace byte-swapping code with builtins in pack.c

2017-10-06 Thread Dylan Baker
Quoting Erik Faye-Lund (2017-10-06 00:31:20)
> On Thu, Oct 5, 2017 at 8:59 PM, Jochen Rollwagen  
> wrote:
> > Am 04.10.2017 um 05:59 schrieb Matt Turner:
> >>
> >> On Tue, Oct 3, 2017 at 11:01 AM, Jochen Rollwagen 
> >> wrote:
> >>>
> >>>  From 4cebe50a9bade6717923e104c954f3fad75f71bb Mon Sep 17 00:00:00 2001
> >>> From: Jochen Rollwagen 
> >>> Date: Tue, 3 Oct 2017 19:54:10 +0200
> >>> Subject: [PATCH] Replace byte-swapping code with builtins in pack.c
> >>>
> >>> This patch replaces some code for byte-swapping in pack.c with the
> >>> builtin
> >>> functions allowing the compiler to do its optimization magic
> >>> ---
> >>>   src/mesa/main/pack.c |   22 ++
> >>>   1 file changed, 2 insertions(+), 20 deletions(-)
> >>>
> >>> diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
> >>> index 94a6d28..9bfde39 100644
> >>> --- a/src/mesa/main/pack.c
> >>> +++ b/src/mesa/main/pack.c
> >>> @@ -230,26 +230,8 @@ _mesa_pack_bitmap( GLint width, GLint height, const
> >>> GLubyte
> >>>   *source,
> >>>  }
> >>>   }
> >>>
> >>> -
> >>> -#define SWAP2BYTE(VALUE)\
> >>> -   {\
> >>> -  GLubyte *bytes = (GLubyte *) &(VALUE);\
> >>> -  GLubyte tmp = bytes[0];\
> >>> -  bytes[0] = bytes[1];\
> >>> -  bytes[1] = tmp;\
> >>> -   }
> >>> -
> >>> -#define SWAP4BYTE(VALUE)\
> >>> -   {\
> >>> -  GLubyte *bytes = (GLubyte *) &(VALUE);\
> >>> -  GLubyte tmp = bytes[0];\
> >>> -  bytes[0] = bytes[3];\
> >>> -  bytes[3] = tmp;\
> >>> -  tmp = bytes[1];\
> >>> -  bytes[1] = bytes[2];\
> >>> -  bytes[2] = tmp;\
> >>> -   }
> >>> -
> >>> +#define SWAP2BYTE(VALUE) __builtin_bswap16(VALUE)
> >>> +#define SWAP4BYTE(VALUE) __builtin_bswap32(VALUE)
> >>
> >> In my experience it's much simpler to just write these as
> >>
> >> return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
> >>
> >> and
> >>
> >> return  ((x & 0xff) << 24) |
> >> ((x & 0xff00) << 8) |
> >> ((x & 0xff) >> 8) |
> >> ((x >> 24) & 0xff);
> >>
> >> and not have to deal with compiler intrinsics. Compilers will
> >> recognize these patterns and use the appropriate instructions (rol for
> >> 2-bytes and bswap for 4-bytes).
> >>
> >> You should be able to count the numbers of those instructions before
> >> and after such a patch to confirm it's working as expected.
> >
> > Fair enough. I've attached a new patch that optimizes the code on linux
> > systems only where there is byteswap.h containing (hopefully optimal)
> > functions. The other systems may be dealt with by a followup patch if
> > desired.
> >
> > From 327012410f75f77010b658ce9643a229c45bc308 Mon Sep 17 00:00:00 2001
> > From: Jochen Rollwagen 
> > Date: Thu, 5 Oct 2017 20:48:46 +0200
> > Subject: [PATCH] Simplify byte swapping code in pack.c on Linux systems
> >
> > This patch replaces the code for byte swapping in pack.c with the function
> > from
> > byteswap.h on Linux systems
> > ---
> >  src/mesa/main/pack.c |8 +++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
> > index 94a6d28..d8ab267 100644
> > --- a/src/mesa/main/pack.c
> > +++ b/src/mesa/main/pack.c
> > @@ -230,6 +230,12 @@ _mesa_pack_bitmap( GLint width, GLint height, const
> > GLubyte
> >  *source,
> > }
> >  }
> >
> > +#ifdef __linux__
> > +#include 
> > +
> > +#define SWAP2BYTE(VALUE) bswap_16(VALUE)
> > +#define SWAP4BYTE(VALUE) bswap_32(VALUE)
> > +#else
> 
> Another alternative would be to use:
> 
> AX_GCC_BUILTIN / HAVE___BUILTIN_BSWAP{16,32}
> 
> ...to check explicitly for the builtins, like we do for other
> builtins. We already do this for __builtin_bswap32 and
> __builtin_bswap64, so it would seem like a pretty straight-forward
> extension of that pattern.

Not withstanding Matt and Nicolai's points:

We already check for bswap builtins in configure (and meson), and would be the
right way to guard this since this isn't really linux specific, it's gcc/clang
specific, and I *think* the BSD's would benefit as well.

Dylan


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


Re: [Mesa-dev] [PATCH] ac/nir: use llvm fma intrinsic if nir instruction is exact.

2017-10-06 Thread Marek Olšák
On Fri, Oct 6, 2017 at 4:39 AM, Dave Airlie  wrote:
> On 6 October 2017 at 12:31, Marek Olšák  wrote:
>> On Fri, Oct 6, 2017 at 4:10 AM, Connor Abbott  wrote:
>>> On Thu, Oct 5, 2017 at 10:08 PM, Marek Olšák  wrote:
 On Fri, Oct 6, 2017 at 3:50 AM, Connor Abbott  wrote:
> Why? While it might technically be legal, always generating an unfused
> mul+add when the user explicitly requested fma() seems harsh...

 It's slow on some chips. It doesn't need any other reason.

 Marek
>>>
>>> Presumably, if the developer asked for fma, then they don't care how
>>> fast or slow it is...
>>
>> Feral asked for fma. They care. This debate is pointless. We just
>> won't use fma by default. Period.
>
> They didn't ask for it with precise precision. I'm assuming if someone wants
> fma with precise precision we should give it to them. Like at least
> the fma manpage states.
>
> https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/fma.xhtml

Oh please Dave, the page says the exact opposite of what you are
saying. The only thing the manpage says is: If fma and mul+add have
different precision, fma can't be split and mul+add can't be combined.
It doesn't say anything about precision of the result of fma itself.
Search for the word "can". It's not the same as "must".

That said, RADV can use as many slow opcodes as you want if you
insist. I'm only saying that the opcode selection of radeonsi is
non-negotiable on my side, and nir_to_llvm might get radeonsi-specific
opcode selection.

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


Re: [Mesa-dev] [PATCH v2 09/12] meson: build gbm

2017-10-06 Thread Dylan Baker
Quoting Daniel Stone (2017-10-06 03:28:48)
> Hi,
> 
> On 5 October 2017 at 22:22, Dylan Baker  wrote:
> > Quoting Eric Anholt (2017-10-05 12:43:47)
> >> Dylan Baker  writes:
> >> > +install_headers('main/gbm.h')
> >> > +
> >> > +pkg.generate(
> >> > +  name : 'gbm',
> >> > +  filebase : 'gbm',
> >> > +  description : 'Mesa gbm library',
> >> > +  version : meson.project_version(),
> >> > +  libraries : libgbm,
> >> > +  #libraries_private : [dep_dl],  # FIXME: autotools lists this a 
> >> > incomplete
> >>
> >> Is there a reason this is commented out?
> >
> > Just that it doesn't accept libraries, only strings. I'll add the string 
> > until
> > we can get the issue resolved upstream.
> 
> Would it not be easier, at least for now, to just use configure_file()
> to build the pkg-config files from the .pc.in we use for autotools? It
> would help avoid desynchronisation between the two systems, and means
> we don't have to route around Meson's pkg-config module being ... not
> quite the best.
> 
> Cheers,
> Daniel

I don't know that it really is going to change much, the information that is
duplicated between them is unlikely to change (the name and description are the
only things hardcoded). And the rest would require the same information in
string form (Requires.private, Libs.private). I don't have a strong opinion at
the moment one way or the other (although I started writing patches last night
to make the pkgconfig interface better), but I think the work in the end is
equal whichever path we take.

Dylan


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


Re: [Mesa-dev] [PATCH v2 06/12] meson: Build i965 and dri stack

2017-10-06 Thread Dylan Baker
Quoting Daniel Stone (2017-10-06 03:25:15)
> Hi,
> 
> On 5 October 2017 at 18:12, Dylan Baker  wrote:
> > This gets pretty much the entire classic tree building, as well as
> > i965, including the various glapis. There are some workarounds for bugs
> > that are fixed in meson 0.43.0, which is due out on October 8th.
> 
> I'm not really sure what prompt you typed the wrong thing into, but
> somehow this patch is declared to have a charset of 'true', rather
> than UTF-8.
> 
> Cheers,
> Daniel

Wow, I'm not sure what I did either. Strange.

Dylan


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


Re: [Mesa-dev] [PATCH v2 05/12] meson: de-tabularize meson_options.txt

2017-10-06 Thread Dylan Baker
Quoting Eero Tamminen (2017-10-06 03:22:56)
> Hi,
> 
> On 05.10.2017 20:12, Dylan Baker wrote:
> > This ends up being unworkable as more options get added, and with
> > description wrapped onto a new line it doesn't improve readability
> > anyway.
> > 
> > Signed-off-by: Dylan Baker 
> > ---
> >   meson_options.txt | 12 ++--
> >   1 file changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/meson_options.txt b/meson_options.txt
> > index eccd5c10d59..6ca19db3497 100644
> > --- a/meson_options.txt
> > +++ b/meson_options.txt
> > @@ -18,15 +18,15 @@
> >   # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
> > IN THE
> >   # SOFTWARE.
> >   
> > -option('platforms',  type : 'string',  value : 'x11,wayland',
> > +option('platforms', type : 'string', value : 'x11,wayland',
> >  description : 'comma separated list of window systems to support. 
> > wayland, x11, surfaceless, drm, etc.')
> > -option('vulkan-drivers', type : 'string',  value : 'intel,amd',
> > +option('vulkan-drivers', type : 'string', value : 'intel,amd',
> >  description : 'comma separated list of vulkan drivers to build.')
> 
> Would this work visually better like this:
> 
> option('platforms',
> type  : 'string',
> value : 'x11,wayland',
> description : 'comma separated list of window systems to 
> support. wayland, x11, surfaceless, drm, etc.'
> )
> 
> option('vulkan-drivers',
> type  : 'string',
> value : 'intel,amd',
> description : 'comma separated list of vulkan drivers to build.'
> )
> 
> ?
> 
> - Eero

It probably would, at this point though if possible I'd rather do that as a
follow up, it creates a lot of rebasing to alter this file this early in the
series.

Dylan

> 
> > -option('shader-cache',type : 'boolean', value : true,
> > +option('shader-cache', type : 'boolean', value : true,
> >  description : 'Build with on-disk shader cache support')
> > -option('vulkan-icd-dir', type : 'string',  value : '',
> > +option('vulkan-icd-dir', type : 'string', value : '',
> >  description : 'Location relative to prefix to put vulkan icds on 
> > install. Default: $datadir/vulkan/icd.d')
> > -option('valgrind',   type : 'boolean', value : true,
> > +option('valgrind', type : 'boolean', value : true,
> >  description : 'Build with valgrind support if possible')
> > -option('build-tests',type : 'boolean', value : false,
> > +option('build-tests', type : 'boolean', value : false,
> >  description : 'Build unit tests. Currently this will build *all* 
> > unit tests, which may build more than expected.')
> > 
> 
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


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


[Mesa-dev] [PATCH 15/15] egl/wayland: Add Wayland shm swrast support for RGB10 winsys buffers.

2017-10-06 Thread Mario Kleiner
Signed-off-by: Mario Kleiner 
---
 src/egl/drivers/dri2/platform_wayland.c | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index 08b7084..20e31aa 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -163,10 +163,14 @@ dri2_wl_create_window_surface(_EGLDriver *drv, 
_EGLDisplay *disp,
   assert(dri2_dpy->wl_shm);
   if (conf->RedSize == 5)
  dri2_surf->format = WL_SHM_FORMAT_RGB565;
-  else if (conf->AlphaSize == 0)
+  else if (conf->RedSize == 8 && conf->AlphaSize == 0)
  dri2_surf->format = WL_SHM_FORMAT_XRGB;
-  else
+  else if (conf->RedSize == 8)
  dri2_surf->format = WL_SHM_FORMAT_ARGB;
+  else if (conf->RedSize == 10 && conf->AlphaSize == 0)
+ dri2_surf->format = WL_SHM_FORMAT_XRGB2101010;
+  else if (conf->RedSize == 10)
+ dri2_surf->format = WL_SHM_FORMAT_ARGB2101010;
}
 
dri2_surf->wl_queue = wl_display_create_queue(dri2_dpy->wl_dpy);
@@ -1442,7 +1446,7 @@ dri2_wl_swrast_get_stride_for_format(int format, int w)
 {
if (format == WL_SHM_FORMAT_RGB565)
   return 2 * w;
-   else /* ARGB || XRGB */
+   else /* ARGB || XRGB || ARGB2101010 || XRGB2101010 */
   return 4 * w;
 }
 
@@ -1867,6 +1871,12 @@ shm_handle_format(void *data, struct wl_shm *shm, 
uint32_t format)
struct dri2_egl_display *dri2_dpy = data;
 
switch (format) {
+   case WL_SHM_FORMAT_ARGB2101010:
+  dri2_dpy->formats |= HAS_ARGB2101010;
+  break;
+   case WL_SHM_FORMAT_XRGB2101010:
+  dri2_dpy->formats |= HAS_XRGB2101010;
+  break;
case WL_SHM_FORMAT_ARGB:
   dri2_dpy->formats |= HAS_ARGB;
   break;
-- 
2.7.4

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


[Mesa-dev] [PATCH 13/15] egl/wayland: Add Wayland drm support for RGB10 winsys buffers.

2017-10-06 Thread Mario Kleiner
Successfully tested under Weston 3.0.
Photometer confirms 10 rgb bits from rendering to display.

Signed-off-by: Mario Kleiner 
---
 src/egl/drivers/dri2/platform_wayland.c   | 37 ---
 src/egl/wayland/wayland-drm/wayland-drm.c |  6 +
 2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index 14db55c..d3df141 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -62,6 +62,8 @@ enum wl_drm_format_flags {
HAS_ARGB = 1,
HAS_XRGB = 2,
HAS_RGB565 = 4,
+   HAS_ARGB2101010 = 8,
+   HAS_XRGB2101010 = 16,
 };
 
 static int
@@ -149,10 +151,14 @@ dri2_wl_create_window_surface(_EGLDriver *drv, 
_EGLDisplay *disp,
if (dri2_dpy->wl_dmabuf || dri2_dpy->wl_drm) {
   if (conf->RedSize == 5)
  dri2_surf->format = WL_DRM_FORMAT_RGB565;
-  else if (conf->AlphaSize == 0)
+  else if (conf->RedSize == 8 && conf->AlphaSize == 0)
  dri2_surf->format = WL_DRM_FORMAT_XRGB;
-  else
+  else if (conf->RedSize == 8)
  dri2_surf->format = WL_DRM_FORMAT_ARGB;
+  else if (conf->RedSize == 10 && conf->AlphaSize == 0)
+ dri2_surf->format = WL_DRM_FORMAT_XRGB2101010;
+  else if (conf->RedSize == 10)
+ dri2_surf->format = WL_DRM_FORMAT_ARGB2101010;
} else {
   assert(dri2_dpy->wl_shm);
   if (conf->RedSize == 5)
@@ -341,11 +347,18 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
uint64_t *modifiers;
int num_modifiers;
 
-   /* currently supports three WL DRM formats,
+   /* currently supports five WL DRM formats,
+* WL_DRM_FORMAT_ARGB2101010, WL_DRM_FORMAT_XRGB2101010,
 * WL_DRM_FORMAT_ARGB, WL_DRM_FORMAT_XRGB,
 * and WL_DRM_FORMAT_RGB565
 */
switch (dri2_surf->format) {
+   case WL_DRM_FORMAT_ARGB2101010:
+  dri_image_format = __DRI_IMAGE_FORMAT_ARGB2101010;
+  break;
+   case WL_DRM_FORMAT_XRGB2101010:
+  dri_image_format = __DRI_IMAGE_FORMAT_XRGB2101010;
+  break;
case WL_DRM_FORMAT_ARGB:
   dri_image_format = __DRI_IMAGE_FORMAT_ARGB;
   modifiers = u_vector_tail(_dpy->wl_modifiers.argb);
@@ -582,6 +595,8 @@ dri2_wl_get_buffers(__DRIdrawable * driDrawable,
unsigned int bpp;
 
switch (dri2_surf->format) {
+   case WL_DRM_FORMAT_ARGB2101010:
+   case WL_DRM_FORMAT_XRGB2101010:
case WL_DRM_FORMAT_ARGB:
case WL_DRM_FORMAT_XRGB:
   bpp = 32;
@@ -945,6 +960,14 @@ dri2_wl_create_wayland_buffer_from_image(_EGLDriver *drv,
 
dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, );
switch (format) {
+   case __DRI_IMAGE_FORMAT_ARGB2101010:
+  if (!(dri2_dpy->formats & HAS_ARGB2101010))
+ goto bad_format;
+  break;
+   case __DRI_IMAGE_FORMAT_XRGB2101010:
+  if (!(dri2_dpy->formats & HAS_XRGB2101010))
+ goto bad_format;
+  break;
case __DRI_IMAGE_FORMAT_ARGB:
   if (!(dri2_dpy->formats & HAS_ARGB))
  goto bad_format;
@@ -1032,6 +1055,12 @@ drm_handle_format(void *data, struct wl_drm *drm, 
uint32_t format)
struct dri2_egl_display *dri2_dpy = data;
 
switch (format) {
+   case WL_DRM_FORMAT_ARGB2101010:
+  dri2_dpy->formats |= HAS_ARGB2101010;
+  break;
+   case WL_DRM_FORMAT_XRGB2101010:
+  dri2_dpy->formats |= HAS_XRGB2101010;
+  break;
case WL_DRM_FORMAT_ARGB:
   dri2_dpy->formats |= HAS_ARGB;
   break;
@@ -1200,6 +1229,8 @@ dri2_wl_add_configs_for_visuals(_EGLDriver *drv, 
_EGLDisplay *disp)
   int has_format;
   unsigned int rgba_masks[4];
} visuals[] = {
+  { "XRGB2101010", HAS_XRGB2101010, { 0x3ff0, 0xffc00, 0x3ff, 0 } },
+  { "ARGB2101010", HAS_ARGB2101010, { 0x3ff0, 0xffc00, 0x3ff, 
0xc000 } },
   { "XRGB", HAS_XRGB, { 0xff, 0xff00, 0x00ff, 0xff00 } },
   { "ARGB", HAS_ARGB, { 0xff, 0xff00, 0x00ff, 0 } },
   { "RGB565",   HAS_RGB565,   { 0x00f800, 0x07e0, 0x001f, 0 } },
diff --git a/src/egl/wayland/wayland-drm/wayland-drm.c 
b/src/egl/wayland/wayland-drm/wayland-drm.c
index 2e256ae..c9af487 100644
--- a/src/egl/wayland/wayland-drm/wayland-drm.c
+++ b/src/egl/wayland/wayland-drm/wayland-drm.c
@@ -124,6 +124,8 @@ drm_create_buffer(struct wl_client *client, struct 
wl_resource *resource,
  uint32_t stride, uint32_t format)
 {
 switch (format) {
+case WL_DRM_FORMAT_ARGB2101010:
+case WL_DRM_FORMAT_XRGB2101010:
 case WL_DRM_FORMAT_ARGB:
 case WL_DRM_FORMAT_XRGB:
 case WL_DRM_FORMAT_YUYV:
@@ -222,6 +224,10 @@ bind_drm(struct wl_client *client, void *data, uint32_t 
version, uint32_t id)
 
wl_resource_post_event(resource, WL_DRM_DEVICE, drm->device_name);
wl_resource_post_event(resource, WL_DRM_FORMAT,
+  WL_DRM_FORMAT_ARGB2101010);
+  

[Mesa-dev] [PATCH 02/15] i965/screen: Add basic support for rendering 10 bpc/depth 30 framebuffers. (v2)

2017-10-06 Thread Mario Kleiner
Expose formats which are supported at least back to Gen 5 Ironlake,
possibly further. Allow creation of 10 bpc winsys buffers for drawables.

glxinfo now lists new RGBA 10 10 10 2/0 formats.
Works correctly under DRI2 without compositing.

v2: Move the BGRA/BGRX1010102 formats before the RGBA/RGBX
32 bit formats, as the code comments require. Thanks Emil!
Update num_formats from 3 to 5, to keep the special Android
handling intact.

Signed-off-by: Mario Kleiner 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 712cd40..9c0539d 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -1567,7 +1567,13 @@ intelCreateBuffer(__DRIscreen *dri_screen,
   fb->Visual.samples = num_samples;
}
 
-   if (mesaVis->redBits == 5) {
+   if (mesaVis->redBits == 10 && mesaVis->alphaBits > 0) {
+  rgbFormat = mesaVis->redMask == 0x3ff0 ? 
MESA_FORMAT_B10G10R10A2_UNORM
+ : 
MESA_FORMAT_R10G10B10A2_UNORM;
+   } else if (mesaVis->redBits == 10) {
+  rgbFormat = mesaVis->redMask == 0x3ff0 ? 
MESA_FORMAT_B10G10R10X2_UNORM
+ : 
MESA_FORMAT_R10G10B10X2_UNORM;
+   } else if (mesaVis->redBits == 5) {
   rgbFormat = mesaVis->redMask == 0x1f ? MESA_FORMAT_R5G6B5_UNORM
: MESA_FORMAT_B5G6R5_UNORM;
} else if (mesaVis->sRGBCapable) {
@@ -1949,6 +1955,10 @@ intel_screen_make_configs(__DRIscreen *dri_screen)
   MESA_FORMAT_B8G8R8A8_UNORM,
   MESA_FORMAT_B8G8R8X8_UNORM,
 
+  /* For 10 bpc, 30 bit depth framebuffers. */
+  MESA_FORMAT_B10G10R10A2_UNORM,
+  MESA_FORMAT_B10G10R10X2_UNORM,
+
   /* The 32-bit RGBA format must not precede the 32-bit BGRA format.
* Likewise for RGBX and BGRX.  Otherwise, the GLX client and the GLX
* server may disagree on which format the GLXFBConfig represents,
@@ -1988,7 +1998,7 @@ intel_screen_make_configs(__DRIscreen *dri_screen)
if (intel_loader_get_cap(dri_screen, DRI_LOADER_CAP_RGBA_ORDERING))
   num_formats = ARRAY_SIZE(formats);
else
-  num_formats = 3;
+  num_formats = 5;
 
/* Generate singlesample configs without accumulation buffer. */
for (unsigned i = 0; i < num_formats; i++) {
-- 
2.7.4

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


[Mesa-dev] [PATCH 05/15] loader/dri3: Add XRGB2101010 and ARGB2101010 support.

2017-10-06 Thread Mario Kleiner
To allow DRI3/Present buffer sharing for 10 bpc buffers.

Signed-off-by: Mario Kleiner 
Reviewed-by: Tapani Pälli 
---
 src/loader/loader_dri3_helper.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/loader/loader_dri3_helper.c b/src/loader/loader_dri3_helper.c
index 19ab581..1904af7 100644
--- a/src/loader/loader_dri3_helper.c
+++ b/src/loader/loader_dri3_helper.c
@@ -982,6 +982,8 @@ image_format_to_fourcc(int format)
case __DRI_IMAGE_FORMAT_ARGB: return __DRI_IMAGE_FOURCC_ARGB;
case __DRI_IMAGE_FORMAT_ABGR: return __DRI_IMAGE_FOURCC_ABGR;
case __DRI_IMAGE_FORMAT_XBGR: return __DRI_IMAGE_FOURCC_XBGR;
+   case __DRI_IMAGE_FORMAT_XRGB2101010: return __DRI_IMAGE_FOURCC_XRGB2101010;
+   case __DRI_IMAGE_FORMAT_ARGB2101010: return __DRI_IMAGE_FOURCC_ARGB2101010;
}
return 0;
 }
-- 
2.7.4

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


[Mesa-dev] [PATCH 06/15] i965/screen: Add XRGB2101010 and ARGB2101010 support for DRI3.

2017-10-06 Thread Mario Kleiner
Allow DRI3/Present buffer sharing for 10 bpc buffers.
Otherwise composited desktops under DRI3 will only display
black client areas for redirected windows.

Signed-off-by: Mario Kleiner 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 9c0539d..98cdb81 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -181,6 +181,12 @@ static const struct __DRI2flushExtensionRec 
intelFlushExtension = {
 };
 
 static const struct intel_image_format intel_image_formats[] = {
+   { __DRI_IMAGE_FOURCC_ARGB2101010, __DRI_IMAGE_COMPONENTS_RGBA, 1,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB2101010, 4 } } },
+
+   { __DRI_IMAGE_FOURCC_XRGB2101010, __DRI_IMAGE_COMPONENTS_RGB, 1,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB2101010, 4 } } },
+
{ __DRI_IMAGE_FOURCC_ARGB, __DRI_IMAGE_COMPONENTS_RGBA, 1,
  { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB, 4 } } },
 
-- 
2.7.4

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


[Mesa-dev] [PATCH 12/15] egl/x11: Handle depth 30 drawables for EGL_KHR_image_pixmap.

2017-10-06 Thread Mario Kleiner
Enables eglCreateImageKHR() with target set to
EGL_NATIVE_PIXMAP_KHR to handle color depth 30
X11 drawables.

Note that in theory the drawable depth 32 case in the
current implementation is ambiguous: A depth 32 drawable
could be of format ARGB or ARGB2101010, therefore an
assignment of __DRI_IMAGE_FORMAT_ARGB for a pixmap of
ARGB2101010 format would be wrong. In practice however, the
X-Server (as of v1.19) does not provide any depth 32 visuals
for ARGB2101010 EGL/GLX configs. Those are associated with
depth 30 visuals without an alpha channel instead. Therefore
the switch-case depth 32 branch is only executed for ARGB
pixmaps and we get away with this.

Tested with KDE Plasma 5 under X11, DRI2 and DRI3/Present,
selecting EGL + OpenGL compositing and different fbconfigs
with/without 2 bit alpha channel. glxinfo confirms use of
depth 30 visuals for ARGB2101010 only.

Suggested-by: Eric Engestrom 
Signed-off-by: Mario Kleiner 
---
 src/egl/drivers/dri2/platform_x11.c  | 3 +++
 src/egl/drivers/dri2/platform_x11_dri3.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_x11.c 
b/src/egl/drivers/dri2/platform_x11.c
index 289351a..5aed4d7 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -1050,6 +1050,9 @@ dri2_create_image_khr_pixmap(_EGLDisplay *disp, 
_EGLContext *ctx,
case 24:
   format = __DRI_IMAGE_FORMAT_XRGB;
   break;
+   case 30:
+  format = __DRI_IMAGE_FORMAT_XRGB2101010;
+  break;
case 32:
   format = __DRI_IMAGE_FORMAT_ARGB;
   break;
diff --git a/src/egl/drivers/dri2/platform_x11_dri3.c 
b/src/egl/drivers/dri2/platform_x11_dri3.c
index 45bb56c..bb5172c 100644
--- a/src/egl/drivers/dri2/platform_x11_dri3.c
+++ b/src/egl/drivers/dri2/platform_x11_dri3.c
@@ -269,6 +269,9 @@ dri3_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext 
*ctx,
case 24:
   format = __DRI_IMAGE_FORMAT_XRGB;
   break;
+   case 30:
+  format = __DRI_IMAGE_FORMAT_XRGB2101010;
+  break;
case 32:
   format = __DRI_IMAGE_FORMAT_ARGB;
   break;
-- 
2.7.4

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


[Mesa-dev] [PATCH 11/15] egl/x11: Handle depth 30 drawables under software rasterizer.

2017-10-06 Thread Mario Kleiner
For fixing eglCreateWindowSurface() under swrast, as tested
with LIBGL_ALWAYS_SOFTWARE=1.

Suggested-by: Eric Engestrom 
Signed-off-by: Mario Kleiner 
---
 src/egl/drivers/dri2/platform_x11.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/egl/drivers/dri2/platform_x11.c 
b/src/egl/drivers/dri2/platform_x11.c
index 070e15c..289351a 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -75,6 +75,7 @@ swrastCreateDrawable(struct dri2_egl_display * dri2_dpy,
xcb_create_gc(dri2_dpy->conn, dri2_surf->swapgc, dri2_surf->drawable, mask, 
valgc);
switch (dri2_surf->depth) {
   case 32:
+  case 30:
   case 24:
  dri2_surf->bytes_per_pixel = 4;
  break;
-- 
2.7.4

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


[Mesa-dev] [PATCH 04/15] dri: Add 10 bpc formats as available formats. (v2)

2017-10-06 Thread Mario Kleiner
Used to support ARGB2101010 and XRGB2101010
winsys framebuffers / drawables, but added
other 10 bpc fourcc's as well for consistency
with definitions in wayland_drm.h, gbm.h, and
drm_fourcc.h.

v2: Align new defines with tabs instead of spaces, for
consistency with remainder of that block of definitions,
as suggested by Tapani.

Signed-off-by: Mario Kleiner 
Reviewed-by: Tapani Pälli 
---
 include/GL/internal/dri_interface.h | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 783ff1c..70ea0d4 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1245,7 +1245,15 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FOURCC_XRGB0x34325258
 #define __DRI_IMAGE_FOURCC_ABGR0x34324241
 #define __DRI_IMAGE_FOURCC_XBGR0x34324258
-#define __DRI_IMAGE_FOURCC_SARGB0x83324258
+#define __DRI_IMAGE_FOURCC_SARGB   0x83324258
+#define __DRI_IMAGE_FOURCC_ARGB2101010 0x30335241
+#define __DRI_IMAGE_FOURCC_XRGB2101010 0x30335258
+#define __DRI_IMAGE_FOURCC_ABGR2101010 0x30334241
+#define __DRI_IMAGE_FOURCC_XBGR2101010 0x30334258
+#define __DRI_IMAGE_FOURCC_RGBA1010102 0x30334152
+#define __DRI_IMAGE_FOURCC_RGBX1010102 0x30335852
+#define __DRI_IMAGE_FOURCC_BGRA1010102 0x30334142
+#define __DRI_IMAGE_FOURCC_BGRX1010102 0x30335842
 #define __DRI_IMAGE_FOURCC_YUV410  0x39565559
 #define __DRI_IMAGE_FOURCC_YUV411  0x31315559
 #define __DRI_IMAGE_FOURCC_YUV420  0x32315559
-- 
2.7.4

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


[Mesa-dev] [PATCH 03/15] i965: Support accelerated blit for depth 30 formats. (v2)

2017-10-06 Thread Mario Kleiner
Extend intel_miptree_blit() to handle at least
ARGB2101010 -> XRGB2101010, ARGB2101010 -> ARGB2101010,
and XRGB2101010 -> XRGB2101010 via the BLT engine,
but not XRGB2101010 -> ARGB2101010 yet.

This works as tested under Compiz, KDE-5, Gnome-Shell.

v2: Restrict BLT fast path to exclude XRGB2101010 -> ARGB2101010,
as intel_miptree_set_alpha_to_one() isn't ready to set 2 bit
alpha channels to 1.0 yet. However, couldn't find a test case
where this specific blit would be needed, so maybe not much
of a point to improve here.

Signed-off-by: Mario Kleiner 
---
 src/mesa/drivers/dri/i965/intel_blit.c | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/intel_blit.c 
b/src/mesa/drivers/dri/i965/intel_blit.c
index 819a3da..f953483 100644
--- a/src/mesa/drivers/dri/i965/intel_blit.c
+++ b/src/mesa/drivers/dri/i965/intel_blit.c
@@ -161,6 +161,19 @@ intel_miptree_blit_compatible_formats(mesa_format src, 
mesa_format dst)
   return (dst == MESA_FORMAT_R8G8B8A8_UNORM ||
   dst == MESA_FORMAT_R8G8B8X8_UNORM);
 
+   /* We can also discard alpha when going from A2->X2 for 2 bit alpha,
+* however we can't fill the alpha channel with two 1 bits when going
+* from X2->A2, because intel_miptree_set_alpha_to_one() is not yet
+* ready for this / can only handle 8 bit alpha.
+*/
+   if (src == MESA_FORMAT_B10G10R10A2_UNORM)
+  return (dst == MESA_FORMAT_B10G10R10A2_UNORM ||
+  dst == MESA_FORMAT_B10G10R10X2_UNORM);
+
+   if (src == MESA_FORMAT_R10G10B10A2_UNORM)
+  return (dst == MESA_FORMAT_R10G10B10A2_UNORM ||
+  dst == MESA_FORMAT_R10G10B10X2_UNORM);
+
return false;
 }
 
@@ -313,7 +326,8 @@ intel_miptree_blit(struct brw_context *brw,
/* The blitter doesn't support doing any format conversions.  We do also
 * support blitting ARGB to XRGB (trivial, the values dropped into
 * the X channel don't matter), and XRGB to ARGB by setting the A
-* channel to 1.0 at the end.
+* channel to 1.0 at the end. Also trivially ARGB2101010 to XRGB2101010,
+* but not XRGB2101010 to ARGB2101010 yet.
 */
if (!intel_miptree_blit_compatible_formats(src_format, dst_format)) {
   perf_debug("%s: Can't use hardware blitter from %s to %s, "
@@ -780,6 +794,10 @@ intel_miptree_set_alpha_to_one(struct brw_context *brw,
DBG("%s dst:buf(%p)/%d %d,%d sz:%dx%d\n",
__func__, mt->bo, pitch, x, y, width, height);
 
+   /* Note: Currently only handles 8 bit alpha channel. Extension to < 8 Bit
+* alpha channel would be likely possible via ROP code 0xfa instead of 0xf0
+* and writing a suitable bit-mask instead of 0x.
+*/
BR13 = br13_for_cpp(cpp) | 0xf0 << 16;
CMD = XY_COLOR_BLT_CMD;
CMD |= XY_BLT_WRITE_ALPHA;
-- 
2.7.4

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


[Mesa-dev] [PATCH 10/15] egl/x11: Match depth 30 RGB visuals to 32-bit RGBA EGLConfigs.

2017-10-06 Thread Mario Kleiner
Similar to the matching of 24 bit RGB visuals to 32-bit
RGBA EGLConfigs, so X11 compositors won't alpha-blend any
config with a destination alpha buffer during compositing.

Additionally this fixes failure to select ARGB2101010
configs via eglChooseConfig() with EGL_ALPHA_BITS 2 on
a depth 30 X-Screen. The X-Server doesn't provide any
visuals of depth 32 for ARGB2101010 configs, it only
provides depth 30 visuals. Therefore if we'd only match
ARGB2101010 configs to depth 32 RGBA visuals, we would
not ever get a visual for such a config.

This was apparent in piglit tests for egl configs, which
are fixed by this commit.

Signed-off-by: Mario Kleiner 
---
 src/egl/drivers/dri2/platform_x11.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/egl/drivers/dri2/platform_x11.c 
b/src/egl/drivers/dri2/platform_x11.c
index 9c20ea8..070e15c 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -783,13 +783,14 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display 
*dri2_dpy,
   config_count++;
 
 /* Allow a 24-bit RGB visual to match a 32-bit RGBA EGLConfig.
+ * Ditto for 30-bit RGB visuals to match a 32-bit RGBA EGLConfig.
  * Otherwise it will only match a 32-bit RGBA visual.  On a
  * composited window manager on X11, this will make all of the
  * EGLConfigs with destination alpha get blended by the
  * compositor.  This is probably not what the application
  * wants... especially on drivers that only have 32-bit RGBA
  * EGLConfigs! */
-if (d.data->depth == 24) {
+if (d.data->depth == 24 || d.data->depth == 30) {
rgba_masks[3] =
   ~(rgba_masks[0] | rgba_masks[1] | rgba_masks[2]);
dri2_conf = dri2_add_config(disp, config, config_count + 1,
-- 
2.7.4

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


[Mesa-dev] [PATCH 09/15] mesa: Add GL_RGBA + GL_UNSIGNED_INT_2_10_10_10_REV for OES read type.

2017-10-06 Thread Mario Kleiner
This format + type combo is good for BGRA1010102 framebuffers
for use with glReadPixels() under GLES, so add it for the
GL_IMPLEMENTATION_COLOR_READ_TYPE_OES query.

Allows successful testing of 10 bpc / depth 30 rendering with dEQP test
case dEQP-EGL.functional.wide_color.window_1010102_colorspace_default.

Signed-off-by: Mario Kleiner 
---
 src/mesa/main/framebuffer.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c
index 039762a..a3b617d 100644
--- a/src/mesa/main/framebuffer.c
+++ b/src/mesa/main/framebuffer.c
@@ -889,6 +889,9 @@ _mesa_get_color_read_type(struct gl_context *ctx,
   if (format == MESA_FORMAT_B5G6R5_UNORM)
  return GL_UNSIGNED_SHORT_5_6_5;
 
+  if (format == MESA_FORMAT_B10G10R10A2_UNORM)
+ return GL_UNSIGNED_INT_2_10_10_10_REV;
+
   switch (data_type) {
   case GL_SIGNED_NORMALIZED:
  return GL_BYTE;
-- 
2.7.4

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


[Mesa-dev] [PATCH 14/15] egl/wayland: Add Wayland dmabuf support for RGB10 winsys buffers.

2017-10-06 Thread Mario Kleiner
Successfully tested under Weston 3.0.
Photometer confirms 10 rgb bits from rendering to display.

Signed-off-by: Mario Kleiner 
---
 src/egl/drivers/dri2/egl_dri2.c |  3 +++
 src/egl/drivers/dri2/egl_dri2.h |  2 ++
 src/egl/drivers/dri2/platform_wayland.c | 16 +++-
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 0db80a0..edbb9f7 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -997,6 +997,9 @@ dri2_display_destroy(_EGLDisplay *disp)
  wl_event_queue_destroy(dri2_dpy->wl_queue);
   if (dri2_dpy->wl_dpy_wrapper)
  wl_proxy_wrapper_destroy(dri2_dpy->wl_dpy_wrapper);
+
+  u_vector_finish(_dpy->wl_modifiers.argb2101010);
+  u_vector_finish(_dpy->wl_modifiers.xrgb2101010);
   u_vector_finish(_dpy->wl_modifiers.argb);
   u_vector_finish(_dpy->wl_modifiers.xrgb);
   u_vector_finish(_dpy->wl_modifiers.rgb565);
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index e3bdbb5..330d457 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -218,6 +218,8 @@ struct dri2_egl_display
struct wl_event_queue*wl_queue;
struct zwp_linux_dmabuf_v1 *wl_dmabuf;
struct {
+  struct u_vectorxrgb2101010;
+  struct u_vectorargb2101010;
   struct u_vectorxrgb;
   struct u_vectorargb;
   struct u_vectorrgb565;
diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index d3df141..08b7084 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -355,9 +355,13 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
switch (dri2_surf->format) {
case WL_DRM_FORMAT_ARGB2101010:
   dri_image_format = __DRI_IMAGE_FORMAT_ARGB2101010;
+  modifiers = u_vector_tail(_dpy->wl_modifiers.argb2101010);
+  num_modifiers = u_vector_length(_dpy->wl_modifiers.argb2101010);
   break;
case WL_DRM_FORMAT_XRGB2101010:
   dri_image_format = __DRI_IMAGE_FORMAT_XRGB2101010;
+  modifiers = u_vector_tail(_dpy->wl_modifiers.xrgb2101010);
+  num_modifiers = u_vector_length(_dpy->wl_modifiers.xrgb2101010);
   break;
case WL_DRM_FORMAT_ARGB:
   dri_image_format = __DRI_IMAGE_FORMAT_ARGB;
@@ -1116,6 +1120,14 @@ dmabuf_handle_modifier(void *data, struct 
zwp_linux_dmabuf_v1 *dmabuf,
   return;
 
switch (format) {
+   case WL_DRM_FORMAT_ARGB2101010:
+  mod = u_vector_add(_dpy->wl_modifiers.argb2101010);
+  dri2_dpy->formats |= HAS_ARGB2101010;
+  break;
+   case WL_DRM_FORMAT_XRGB2101010:
+  mod = u_vector_add(_dpy->wl_modifiers.xrgb2101010);
+  dri2_dpy->formats |= HAS_XRGB2101010;
+  break;
case WL_DRM_FORMAT_ARGB:
   mod = u_vector_add(_dpy->wl_modifiers.argb);
   dri2_dpy->formats |= HAS_ARGB;
@@ -1287,7 +1299,9 @@ dri2_initialize_wayland_drm(_EGLDriver *drv, _EGLDisplay 
*disp)
   dri2_dpy->wl_dpy = disp->PlatformDisplay;
}
 
-   if (!u_vector_init(_dpy->wl_modifiers.xrgb, sizeof(uint64_t), 32) 
||
+   if (!u_vector_init(_dpy->wl_modifiers.xrgb2101010, sizeof(uint64_t), 
32) ||
+   !u_vector_init(_dpy->wl_modifiers.argb2101010, sizeof(uint64_t), 
32) ||
+   !u_vector_init(_dpy->wl_modifiers.xrgb, sizeof(uint64_t), 32) 
||
!u_vector_init(_dpy->wl_modifiers.argb, sizeof(uint64_t), 32) 
||
!u_vector_init(_dpy->wl_modifiers.rgb565, sizeof(uint64_t), 32)) {
   goto cleanup;
-- 
2.7.4

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


[Mesa-dev] [PATCH 08/15] i965/screen: Honor 'allow_rgb10_configs' option. (v2)

2017-10-06 Thread Mario Kleiner
Allows to prevent exposing RGB10 configs and visuals to
clients.

v2: Rename expose_rgb10_configs to allow_rgb10_configs,
as suggested by Emil.

Signed-off-by: Mario Kleiner 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 98cdb81..919de86 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -2006,11 +2006,20 @@ intel_screen_make_configs(__DRIscreen *dri_screen)
else
   num_formats = 5;
 
+   /* Shall we expose 10 bpc formats? */
+   bool allow_rgb10_configs = driQueryOptionb(_screen->optionCache,
+  "allow_rgb10_configs");
+
/* Generate singlesample configs without accumulation buffer. */
for (unsigned i = 0; i < num_formats; i++) {
   __DRIconfig **new_configs;
   int num_depth_stencil_bits = 2;
 
+  if (!allow_rgb10_configs &&
+  (formats[i] == MESA_FORMAT_B10G10R10A2_UNORM ||
+   formats[i] == MESA_FORMAT_B10G10R10X2_UNORM))
+ continue;
+
   /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
* buffer that has a different number of bits per pixel than the color
* buffer, gen >= 6 supports this.
@@ -2047,6 +2056,11 @@ intel_screen_make_configs(__DRIscreen *dri_screen)
for (unsigned i = 0; i < num_formats; i++) {
   __DRIconfig **new_configs;
 
+  if (!allow_rgb10_configs &&
+  (formats[i] == MESA_FORMAT_B10G10R10A2_UNORM ||
+  formats[i] == MESA_FORMAT_B10G10R10X2_UNORM))
+ continue;
+
   if (formats[i] == MESA_FORMAT_B5G6R5_UNORM) {
  depth_bits[0] = 16;
  stencil_bits[0] = 0;
@@ -2080,6 +2094,11 @@ intel_screen_make_configs(__DRIscreen *dri_screen)
   if (devinfo->gen < 6)
  break;
 
+  if (!allow_rgb10_configs &&
+  (formats[i] == MESA_FORMAT_B10G10R10A2_UNORM ||
+  formats[i] == MESA_FORMAT_B10G10R10X2_UNORM))
+ continue;
+
   __DRIconfig **new_configs;
   const int num_depth_stencil_bits = 2;
   int num_msaa_modes = 0;
-- 
2.7.4

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


  1   2   >