Re: [Mesa-dev] [PATCH] etnaviv: fix some pm query issues

2019-06-02 Thread Christian Gmeiner
Am Fr., 31. Mai 2019 um 18:05 Uhr schrieb Lucas Stach :
>
> The offsets to read the query results were off-by-one, which causes the
> counters to report bogus increasing values.
>
> Also the counter result is u32, so we need to initialize the query type
> to reflect that.
>
> Signed-off-by: Lucas Stach 

Reviewed-by: Christian Gmeiner 

> ---
> This only fixes the obvious issues. I still believe there are some
> GPU/CPU synchronization issues in this code, that need to be fixed
> separately.

What is your current test for synchronization correctness?

> ---
>  src/gallium/drivers/etnaviv/etnaviv_query_pm.c | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_query_pm.c 
> b/src/gallium/drivers/etnaviv/etnaviv_query_pm.c
> index ade0b9790c28..c63ed8304919 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_query_pm.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_query_pm.c
> @@ -485,9 +485,9 @@ etna_pm_query_get(struct etna_cmd_stream *stream, struct 
> etna_query *q,
> assert(flags);
>
> if (flags == ETNA_PM_PROCESS_PRE)
> -  offset = 2;
> +  offset = 1;
> else
> -  offset = 3;
> +  offset = 2;
>
> struct etna_perf p = {
>.flags = flags,
> @@ -639,6 +639,10 @@ etna_pm_get_driver_query_info(struct pipe_screen 
> *pscreen, unsigned index,
> info->name = query_config[i].name;
> info->query_type = query_config[i].type;
> info->group_id = query_config[i].group_id;
> +   info->type = PIPE_DRIVER_QUERY_TYPE_UINT;
> +   info->result_type = PIPE_DRIVER_QUERY_RESULT_TYPE_AVERAGE;
> +   info->max_value.u32 = 0;
> +   info->flags = 0;
>
> return 1;
>  }
> --
> 2.20.1
>
> _______
> etnaviv mailing list
> etna...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv



-- 
greets
--
Christian Gmeiner, MSc

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

[Mesa-dev] [PATCH] etnaviv: implement set_active_query_state(..) for hw queries

2019-05-28 Thread Christian Gmeiner
Clear w/ quad uses a normal draw which adds up to OQ. st/meta
uses set_active_query_state(..) to tell the driver to pause
queries in such cases.

Fixes spec@arb_occlusion_query@occlusion_query_meta_save piglit.

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_query.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_query.c 
b/src/gallium/drivers/etnaviv/etnaviv_query.c
index b076e87e782..bd75ca90b8a 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_query.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_query.c
@@ -134,8 +134,17 @@ etna_get_driver_query_group_info(struct pipe_screen 
*pscreen, unsigned index,
 }
 
 static void
-etna_set_active_query_state(struct pipe_context *pipe, boolean enable)
+etna_set_active_query_state(struct pipe_context *pctx, boolean enable)
 {
+   struct etna_context *ctx = etna_context(pctx);
+
+   if (enable) {
+  list_for_each_entry(struct etna_hw_query, hq, >active_hw_queries, 
node)
+ etna_hw_query_resume(hq, ctx);
+   } else {
+  list_for_each_entry(struct etna_hw_query, hq, >active_hw_queries, 
node)
+ etna_hw_query_suspend(hq, ctx);
+   }
 }
 
 void
-- 
2.21.0

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

[Mesa-dev] [PATCH] etnaviv: drop a bunch of duplicated gallium PIPE_CAP default code

2019-05-27 Thread Christian Gmeiner
Now that we have the util function for the default values, we can get
rid of the boilerplate.

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_screen.c | 157 ---
 1 file changed, 157 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c 
b/src/gallium/drivers/etnaviv/etnaviv_screen.c
index f245127d2d9..0398a0fb39b 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c
@@ -158,9 +158,6 @@ etna_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
   return 256;
case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
   return 4; /* XXX could easily be supported */
-   case PIPE_CAP_GLSL_FEATURE_LEVEL:
-   case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
-  return 120;
 
case PIPE_CAP_NPOT_TEXTURES:
   return true; /* VIV_FEATURE(priv->dev, chipMinorFeatures1,
@@ -170,148 +167,17 @@ etna_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_PRIMITIVE_RESTART:
   return VIV_FEATURE(screen, chipMinorFeatures1, HALTI0);
 
-   case PIPE_CAP_ENDIANNESS:
-  return PIPE_ENDIAN_LITTLE; /* on most Viv hw this is configurable 
(feature
-ENDIANNESS_CONFIG) */
-
/* Unsupported features. */
-   case PIPE_CAP_SEAMLESS_CUBE_MAP:
-   case PIPE_CAP_COMPUTE: /* XXX supported on gc2000 */
-   case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: /* only one colorbuffer supported, 
so mixing makes no sense */
-   case PIPE_CAP_CONDITIONAL_RENDER: /* no occlusion queries */
-   case PIPE_CAP_TGSI_INSTANCEID: /* no idea, really */
-   case PIPE_CAP_START_INSTANCE: /* instancing not supported AFAIK */
-   case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: /* instancing not supported 
AFAIK */
-   case PIPE_CAP_SHADER_STENCIL_EXPORT: /* Fragment shader cannot export 
stencil value */
-   case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS: /* no dual-source supported */
-   case PIPE_CAP_TEXTURE_MULTISAMPLE: /* no texture multisample */
-   case PIPE_CAP_TEXTURE_MIRROR_CLAMP: /* only mirrored repeat */
-   case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE: /* only mirrored repeat */
-   case PIPE_CAP_INDEP_BLEND_ENABLE:
-   case PIPE_CAP_INDEP_BLEND_FUNC:
-   case PIPE_CAP_DEPTH_CLIP_DISABLE:
-   case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
-   case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
-   case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
-   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
-   case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS: /* Don't skip strict max uniform 
limit check */
-   case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
-   case PIPE_CAP_VERTEX_COLOR_CLAMPED:
-   case PIPE_CAP_USER_VERTEX_BUFFERS:
-   case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
-   case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY:
-   case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES: /* TODO: test me out with piglit */
-   case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
-   case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
-   case PIPE_CAP_TEXTURE_GATHER_SM5:
-   case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
-   case PIPE_CAP_FAKE_SW_MSAA:
-   case PIPE_CAP_TEXTURE_QUERY_LOD:
-   case PIPE_CAP_SAMPLE_SHADING:
-   case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
-   case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
-   case PIPE_CAP_DRAW_INDIRECT:
-   case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
-   case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
-   case PIPE_CAP_SAMPLER_VIEW_TARGET:
-   case PIPE_CAP_CLIP_HALFZ:
-   case PIPE_CAP_VERTEXID_NOBASE:
-   case PIPE_CAP_POLYGON_OFFSET_CLAMP:
-   case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
-   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
-   case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
-   case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
-   case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
-   case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
-   case PIPE_CAP_DEPTH_BOUNDS_TEST:
-   case PIPE_CAP_TGSI_TXQS:
-   case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
-   case PIPE_CAP_SHAREABLE_SHADERS:
-   case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
-   case PIPE_CAP_CLEAR_TEXTURE:
-   case PIPE_CAP_DRAW_PARAMETERS:
-   case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
-   case PIPE_CAP_MULTI_DRAW_INDIRECT:
-   case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
-   case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL:
-   case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
-   case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
-   case PIPE_CAP_INVALIDATE_BUFFER:
-   case PIPE_CAP_GENERATE_MIPMAP:
-   case PIPE_CAP_STRING_MARKER:
-   case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
-   case PIPE_CAP_QUERY_BUFFER_OBJECT:
-   case PIPE_CAP_QUERY_MEMORY_INFO:
-   case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
-   case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
-   case PIPE_CAP_CULL_DISTANCE:
-   case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
-   case PIPE_CAP_TGSI_VOTE:
-   case PIPE_CAP_MAX_WINDOW_RECTANGLES:
-   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
-   case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
-   case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
-   c

[Mesa-dev] [PATCH] etnaviv: rs: choose clear format based on block size

2019-05-26 Thread Christian Gmeiner
Fixes following piglit and does not introduce any regressions.
  spec@ext_packed_depth_stencil@fbo-depth-gl_depth24_stencil8-blit

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_rs.c | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_rs.c 
b/src/gallium/drivers/etnaviv/etnaviv_rs.c
index e64babfdd0a..8c85f329f76 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_rs.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_rs.c
@@ -254,7 +254,19 @@ etna_rs_gen_clear_surface(struct etna_context *ctx, struct 
etna_surface *surf,
   uint32_t clear_value)
 {
struct etna_resource *dst = etna_resource(surf->base.texture);
-   uint32_t format = translate_rs_format(surf->base.format);
+   uint32_t format;
+
+   switch (util_format_get_blocksizebits(surf->base.format)) {
+   case 16:
+  format = RS_FORMAT_A4R4G4B4;
+  break;
+   case 32:
+  format = RS_FORMAT_A8R8G8B8;
+  break;
+   default:
+  format = ETNA_NO_MATCH;
+  break;
+   }
 
if (format == ETNA_NO_MATCH) {
   BUG("etna_rs_gen_clear_surface: Unhandled clear fmt %s", 
util_format_name(surf->base.format));
-- 
2.21.0

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

Re: [Mesa-dev] [PATCH 2/2] etnaviv: blt: s/TRUE/true && s/FALSE/false

2019-05-24 Thread Christian Gmeiner
Hi Fabio,

Am Fr., 24. Mai 2019 um 13:10 Uhr schrieb Fabio Estevam :
>
> Hi Christian,
>
> On Fri, May 24, 2019 at 7:52 AM Christian Gmeiner
>  wrote:
> >
> > Signed-off-by: Christian Gmeiner 
>
> Maybe you could remove the '&& s/FALSE/false' from the Subject since
> you are only replacing the TRUE occurrences in this patch.

I forgot to save the file during FALSE replacement. I have this
version locally now:

8<

--- a/src/gallium/drivers/etnaviv/etnaviv_blt.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_blt.c
@@ -367,7 +367,7 @@ etna_try_blt_blit(struct pipe_context *pctx,
assert(blit_info->dst.level <= dst->base.last_level);

if (!translate_samples_to_xyscale(src->base.nr_samples,
_xscale, _yscale, NULL))
-  return FALSE;
+  return false;

/* The width/height are in pixels; they do not change as a result of
 * multi-sampling. So, when blitting from a 4x multisampled surface
@@ -379,14 +379,14 @@ etna_try_blt_blit(struct pipe_context *pctx,
   DBG("scaling requested: source %dx%d destination %dx%d",
   blit_info->src.box.width, blit_info->src.box.height,
   blit_info->dst.box.width, blit_info->dst.box.height);
-  return FALSE;
+  return false;
}

/* No masks - not sure if BLT can copy individual channels */
unsigned mask = util_format_get_mask(blit_info->dst.format);
if ((blit_info->mask & mask) != mask) {
   DBG("sub-mask requested: 0x%02x vs format mask 0x%02x",
blit_info->mask, mask);
-  return FALSE;
+  return false;
}

/* TODO: 1 byte per pixel formats aren't handled by
etna_compatible_rs_format nor
@@ -402,7 +402,7 @@ etna_try_blt_blit(struct pipe_context *pctx,
blit_info->scissor_enable ||
blit_info->dst.box.depth != blit_info->src.box.depth ||
blit_info->dst.box.depth != 1) {
-  return FALSE;
+  return false;
}

/* Ensure that the Z coordinate is sane */
@@ -419,7 +419,7 @@ etna_try_blt_blit(struct pipe_context *pctx,
   /* Resolve-in-place */
   assert(!memcmp(_info->src, _info->dst,
sizeof(blit_info->src)));
   if (!src_lev->ts_size || !src_lev->ts_valid) /* No TS, no worries */
- return TRUE;
+ return true;
   struct blt_inplace_op op = {};

   op.addr.bo = src->bo;
@@ -516,7 +516,7 @@ etna_try_blt_blit(struct pipe_context *pctx,
    dst->seqno++;
dst_lev->ts_valid = false;

-   return TRUE;
+   return true;
 }

 static void

8<

-- 
greets
--
Christian Gmeiner, MSc

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

[Mesa-dev] [PATCH 1/2] etnaviv: rs: s/TRUE/true && s/FALSE/false

2019-05-24 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_rs.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_rs.c 
b/src/gallium/drivers/etnaviv/etnaviv_rs.c
index a9d3872ad41..e64babfdd0a 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_rs.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_rs.c
@@ -541,7 +541,7 @@ etna_try_rs_blit(struct pipe_context *pctx,
assert(blit_info->dst.level <= dst->base.last_level);
 
if (!translate_samples_to_xyscale(src->base.nr_samples, _xscale, 
_yscale, NULL))
-  return FALSE;
+  return false;
 
/* The width/height are in pixels; they do not change as a result of
 * multi-sampling. So, when blitting from a 4x multisampled surface
@@ -552,14 +552,14 @@ etna_try_rs_blit(struct pipe_context *pctx,
   DBG("scaling requested: source %dx%d destination %dx%d",
   blit_info->src.box.width, blit_info->src.box.height,
   blit_info->dst.box.width, blit_info->dst.box.height);
-  return FALSE;
+  return false;
}
 
/* No masks - RS can't copy specific channels */
unsigned mask = util_format_get_mask(blit_info->dst.format);
if ((blit_info->mask & mask) != mask) {
   DBG("sub-mask requested: 0x%02x vs format mask 0x%02x", blit_info->mask, 
mask);
-  return FALSE;
+  return false;
}
 
unsigned src_format = etna_compatible_rs_format(blit_info->src.format);
@@ -569,18 +569,18 @@ etna_try_rs_blit(struct pipe_context *pctx,
blit_info->scissor_enable ||
blit_info->dst.box.depth != blit_info->src.box.depth ||
blit_info->dst.box.depth != 1) {
-  return FALSE;
+  return false;
}
 
unsigned w_mask, h_mask;
 
etna_get_rs_alignment_mask(ctx, src->layout, _mask, _mask);
if ((blit_info->src.box.x & w_mask) || (blit_info->src.box.y & h_mask))
-  return FALSE;
+  return false;
 
etna_get_rs_alignment_mask(ctx, dst->layout, _mask, _mask);
if ((blit_info->dst.box.x & w_mask) || (blit_info->dst.box.y & h_mask))
-  return FALSE;
+  return false;
 
/* Ensure that the Z coordinate is sane */
if (dst->base.target != PIPE_TEXTURE_CUBE)
@@ -734,7 +734,7 @@ etna_try_rs_blit(struct pipe_context *pctx,
dst->levels[blit_info->dst.level].ts_valid = false;
ctx->dirty |= ETNA_DIRTY_DERIVE_TS;
 
-   return TRUE;
+   return true;
 
 manual:
if (src->layout == ETNA_LAYOUT_TILED && dst->layout == ETNA_LAYOUT_TILED) {
@@ -744,7 +744,7 @@ manual:
   return etna_manual_blit(dst, dst_lev, dst_offset, src, src_lev, 
src_offset, blit_info);
}
 
-   return FALSE;
+   return false;
 }
 
 static void
-- 
2.21.0

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

[Mesa-dev] [PATCH 2/2] etnaviv: blt: s/TRUE/true && s/FALSE/false

2019-05-24 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_blt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_blt.c 
b/src/gallium/drivers/etnaviv/etnaviv_blt.c
index 42190d75d4e..cb6e81999fc 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_blt.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_blt.c
@@ -419,7 +419,7 @@ etna_try_blt_blit(struct pipe_context *pctx,
   /* Resolve-in-place */
   assert(!memcmp(_info->src, _info->dst, 
sizeof(blit_info->src)));
   if (!src_lev->ts_size || !src_lev->ts_valid) /* No TS, no worries */
- return TRUE;
+ return true;
   struct blt_inplace_op op = {};
 
   op.addr.bo = src->bo;
@@ -516,7 +516,7 @@ etna_try_blt_blit(struct pipe_context *pctx,
dst->seqno++;
dst_lev->ts_valid = false;
 
-   return TRUE;
+   return true;
 }
 
 static void
-- 
2.21.0

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

[Mesa-dev] [RFC PATCH 00/17] An other look at nir

2019-05-10 Thread Christian Gmeiner
There has been interest in NIR support for etnaviv for a while, for the
obvious reasons: gaining access to common optimizations, better support
for non-trivial code transformations, better register allocation, and
the promise of OpenCL and SPIR-V support in the future.

This time I give it a try with a completly different architecture compared
to the one pengutronix has choosen.
  - https://patchwork.freedesktop.org/series/44282/

My main goal was to have all the needed tools like assembler, disasm,
linker and ofc the compiler living outside of the gallium driver. This
opens the door for easier testing of the different components and - if
somebody dreams loud - vulkan.

I have choosen to go with an own backend ir called:  *drumroll*  eir
It is a basic block based one with some nice to haves. I have studied
every backend-compiler mesa have and have choosen the (best) parts from
them.

eir provides stuff like:
 - legalization
 - optimizations
 - register allocator
 - unit tests

Why I have not choosen to do it directly in nir?

Not that easy to answer but nir is a really fast moving target and nobody
can tell where the road goes. nir might translate well enought to hw ISA now
but maybe in the situation gets harder with newer GPUs and some core nir
changes. For instance, at the moment on thing that might need worked around
is the fact that nir can't represent (jump_if x CND y).

ISA wise there are some improvements possible like on GC3000 it is possible
to provide immediate values inline for source arguments for other instructions
than control flow instructions.

Oh before I forget it - this RFC is based on top of:
"etnaviv: add low level ISA library"
 - https://gitlab.freedesktop.org/mesa/mesa/merge_requests/848

I am sending out this RFC to get feedback on the design I have choosen. I am not
sure how the future nir based compiler infrastrucutre will look like but I am
hoping for the best.

Keep in mind that the nir compiler does something but most of the time the wrong
thing. I only target GC2000 for the moment as it is still my main dev gpu. Weeks
ago I have started to track deqp and piglit problems and to address them - so 
dont
even try to use it.

The last thing I want to say - lot of you might know that I am working on this 
thing
for a while now and never had any ready-to-send patches, but I have a good 
explanation.

 - nir is moving really fast and it takes time to sync my downstream with 
upstream.
 - I only hack/work on etnaviv one day a week.
 - Cleaning up the git history after a long hack day (with refactorings etc.) 
takes time.
 - It takes time to upstream nir changes if you need to respin it.
 - I spend some of my etnaviv time with other topic like linear texturing 
support,
   etc2 texture patching, some other RE stuff and ofc I try my best to review 
other
   patches in the area of etnaviv.

So it comes down to my limted time and the big architectural changes I have 
done with
unit tests and real shader compiles on the targets.

At the moment I am not sure how to move on form this point.

Thanks

PS: You can find this changes here too
 https://github.com/austriancoder/mesa/commits/eir-v3

Christian Gmeiner (17):
  etnaviv: add basic block based backend ir: eir
  eir: add legalization
  eir: add live ranges pass
  eir: add virtual register classes
  eir: implement actual register allocator
  eir: add nir optimization loop
  eir: add eir_print(..)
  eir: add nir compiler and all its infrastructure
  etnaviv: become independed of the used compiler backend
  etnaviv: hook-up eir into gallium driver
  etnaviv: add eir_compiler
  etnaviv: add debug option to report NIR as supported and preferred
shader IR
  etnaviv: enable nir paths
  eir: add nir alu to scalar lowering pass
  eir: make use of eir_nir_lower_alu_to_scalar(..)
  eir: add optimization 'framework'
  eir: add peephole optimization

 src/etnaviv/compiler/eir.c|  239 
 src/etnaviv/compiler/eir.h|  523 +
 src/etnaviv/compiler/eir_compiler.c   |   61 +
 src/etnaviv/compiler/eir_compiler.h   |   70 ++
 src/etnaviv/compiler/eir_compiler_nir.c   | 1041 +
 src/etnaviv/compiler/eir_legalize.c   |  177 +++
 src/etnaviv/compiler/eir_live_variables.c |  258 
 src/etnaviv/compiler/eir_nir.c|  133 +++
 src/etnaviv/compiler/eir_nir.h|   43 +
 .../compiler/eir_nir_lower_alu_to_scalar.c|  131 +++
 src/etnaviv/compiler/eir_opt_peephole.c   |   63 +
 src/etnaviv/compiler/eir_optimize.c   |   50 +
 src/etnaviv/compiler/eir_optimize.h   |   36 +
 src/etnaviv/compiler/eir_print.c  |  222 
 src/etnaviv/compiler/eir_register_allocate.c  |  353 ++
 src/etnaviv/compiler/eir_shader.c |  312 +
 src/etnaviv/compiler/eir_shader.h |  203 
 src/etnaviv/compiler/eir_uniform.c|  108 ++
 src/etnaviv/compiler/meson.build  

[Mesa-dev] [RFC PATCH 08/17] eir: add nir compiler and all its infrastructure

2019-05-10 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/etnaviv/compiler/eir_compiler.c |   61 ++
 src/etnaviv/compiler/eir_compiler.h |   29 +
 src/etnaviv/compiler/eir_compiler_nir.c | 1035 +++
 src/etnaviv/compiler/eir_shader.c   |  312 +++
 src/etnaviv/compiler/eir_shader.h   |  203 +
 src/etnaviv/compiler/meson.build|4 +
 6 files changed, 1644 insertions(+)
 create mode 100644 src/etnaviv/compiler/eir_compiler.c
 create mode 100644 src/etnaviv/compiler/eir_compiler_nir.c
 create mode 100644 src/etnaviv/compiler/eir_shader.c
 create mode 100644 src/etnaviv/compiler/eir_shader.h

diff --git a/src/etnaviv/compiler/eir_compiler.c 
b/src/etnaviv/compiler/eir_compiler.c
new file mode 100644
index 000..386dcd0b0bc
--- /dev/null
+++ b/src/etnaviv/compiler/eir_compiler.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2018 Etnaviv Project
+ * Copyright (C) 2018 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *    Christian Gmeiner 
+ */
+
+#include "eir.h"
+#include "eir_compiler.h"
+#include "util/ralloc.h"
+#include "util/u_debug.h"
+
+static const struct debug_named_value shader_debug_options[] = {
+   {"disasm",  EIR_DBG_DISASM, "Dump NIR and etnaviv shader disassembly"},
+   {"optmsgs", EIR_DBG_OPTMSGS,"Enable optimizer debug messages"},
+   DEBUG_NAMED_VALUE_END
+};
+
+DEBUG_GET_ONCE_FLAGS_OPTION(eir_compiler_debug, "EIR_COMPILER_DEBUG", 
shader_debug_options, 0)
+
+enum eir_compiler_debug eir_compiler_debug = 0;
+
+struct eir_compiler *
+eir_compiler_create(void)
+{
+   struct eir_compiler *compiler = rzalloc(NULL, struct eir_compiler);
+
+   if (!compiler)
+  return NULL;
+
+   eir_compiler_debug = debug_get_option_eir_compiler_debug();
+   compiler->set = eir_ra_alloc_reg_set(compiler);
+
+   return compiler;
+}
+
+void
+eir_compiler_free(const struct eir_compiler *compiler)
+{
+   ralloc_free((void *)compiler);
+}
diff --git a/src/etnaviv/compiler/eir_compiler.h 
b/src/etnaviv/compiler/eir_compiler.h
index 5c5412e4773..645ee6a0db2 100644
--- a/src/etnaviv/compiler/eir_compiler.h
+++ b/src/etnaviv/compiler/eir_compiler.h
@@ -28,7 +28,21 @@
 #ifndef H_EIR_COMPILER
 #define H_EIR_COMPILER
 
+#include 
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
 struct eir_ra_reg_set;
+struct eir_shader_variant;
+
+enum eir_compiler_debug {
+   EIR_DBG_DISASM   = (1 << 0),
+   EIR_DBG_OPTMSGS  = (1 << 1),
+};
+
+extern enum eir_compiler_debug eir_compiler_debug;
 
 /**
  * Compiler state saved across compiler invocations, for any expensive global
@@ -36,6 +50,21 @@ struct eir_ra_reg_set;
  */
 struct eir_compiler {
struct eir_ra_reg_set *set;
+   uint32_t shader_count;
 };
 
+struct eir_compiler *
+eir_compiler_create(void);
+
+void
+eir_compiler_free(const struct eir_compiler *compiler);
+
+int
+eir_compile_shader_nir(struct eir_compiler *compiler,
+   struct eir_shader_variant *v);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif // H_EIR_COMPILER
diff --git a/src/etnaviv/compiler/eir_compiler_nir.c 
b/src/etnaviv/compiler/eir_compiler_nir.c
new file mode 100644
index 000..862f34390e0
--- /dev/null
+++ b/src/etnaviv/compiler/eir_compiler_nir.c
@@ -0,0 +1,1035 @@
+/*
+ * Copyright (c) 2018 Etnaviv Project
+ * Copyright (C) 2018 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the follo

[Mesa-dev] [RFC PATCH 15/17] eir: make use of eir_nir_lower_alu_to_scalar(..)

2019-05-10 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/etnaviv/compiler/eir_nir.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/etnaviv/compiler/eir_nir.c b/src/etnaviv/compiler/eir_nir.c
index 6e75f2c5fd8..a579037a667 100644
--- a/src/etnaviv/compiler/eir_nir.c
+++ b/src/etnaviv/compiler/eir_nir.c
@@ -102,6 +102,8 @@ eir_optimize_nir(struct nir_shader *s)
OPT_V(s, nir_lower_global_vars_to_local);
OPT_V(s, nir_lower_regs_to_ssa);
 
+   OPT_V(s, eir_nir_lower_alu_to_scalar);
+
OPT_V(s, nir_opt_algebraic);
 
eir_optimize_loop(s);
-- 
2.21.0

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

[Mesa-dev] [RFC PATCH 07/17] eir: add eir_print(..)

2019-05-10 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/etnaviv/compiler/eir.h   |   3 +
 src/etnaviv/compiler/eir_print.c | 222 +++
 src/etnaviv/compiler/meson.build |   1 +
 3 files changed, 226 insertions(+)
 create mode 100644 src/etnaviv/compiler/eir_print.c

diff --git a/src/etnaviv/compiler/eir.h b/src/etnaviv/compiler/eir.h
index bbde10cde08..1b67edab559 100644
--- a/src/etnaviv/compiler/eir.h
+++ b/src/etnaviv/compiler/eir.h
@@ -309,6 +309,9 @@ eir_ra_alloc_reg_set(void *memctx);
 bool
 eir_register_allocate(struct eir *ir, gl_shader_stage type, struct 
eir_compiler *compiler);
 
+void
+eir_print(struct eir *ir);
+
 uint32_t *
 eir_assemble(const struct eir *ir, struct eir_info *info);
 
diff --git a/src/etnaviv/compiler/eir_print.c b/src/etnaviv/compiler/eir_print.c
new file mode 100644
index 000..e4e11d5de19
--- /dev/null
+++ b/src/etnaviv/compiler/eir_print.c
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2018 Etnaviv Project
+ * Copyright (C) 2018 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *    Christian Gmeiner 
+ */
+
+#include 
+
+#include "eir.h"
+#include "etnaviv/gc/gc_disasm.h"
+
+static void
+tab(struct gc_string *string, const unsigned lvl)
+{
+   for (unsigned i = 0; i < lvl; i++)
+  gc_string_append(string, "\t");
+}
+
+static void
+print_a(struct gc_string *string, const struct eir *ir, unsigned ip, bool 
start)
+{
+   const int num = util_dynarray_num_elements(>reg_alloc, unsigned);
+   const int num_components = num * 4;
+   int *data;
+
+   if (start)
+  data = ir->temp_start;
+   else
+  data = ir->temp_end;
+
+   for (int i = 0; i < num_components; i = i + 4) {
+  unsigned comp = 0;
+
+  for (int j = 0; j < 4; j++)
+ if (data[i + j] == ip)
+comp |= 1 << j;
+
+  if (comp == 0)
+ continue;
+
+  if (start)
+ gc_string_append(string, "S%4d", i / 4);
+  else
+ gc_string_append(string, "E%4d", i / 4);
+
+  gc_decode_components(string, comp);
+  gc_string_append(string, " ");
+   }
+
+   gc_string_append(string, "");
+}
+
+static void
+print_live_ranges(struct gc_string *string, const struct eir *ir,
+  unsigned ip)
+{
+   print_a(string, ir, ip, true);
+   print_a(string, ir, ip, false);
+}
+
+static void
+print_register(struct gc_string *string, const struct eir_register *reg)
+{
+   switch (reg->type) {
+   case EIR_REG_TEMP:
+  gc_string_append(string, "t%d", reg->index);
+  break;
+   case EIR_REG_UNIFORM:
+  gc_string_append(string, "u%d", reg->index);
+ break;
+   case EIR_REG_UNDEF:
+  unreachable("undef??");
+  break;
+   default:
+  unreachable("oops");
+  break;
+   }
+}
+
+static void
+print_dst(struct gc_string *string, const struct eir_register *reg)
+{
+   print_register(string, reg);
+   gc_decode_components(string, reg->writemask);
+   gc_string_append(string, " ");
+}
+
+static void
+print_src(struct gc_string *string, const struct eir_register *reg)
+{
+   if (reg->abs)
+  gc_string_append(string, "|");
+
+   print_register(string, reg);
+   gc_decode_swiz(string, reg->swizzle);
+
+   if (reg->abs)
+  gc_string_append(string, "|");
+
+   gc_string_append(string, " ");
+}
+
+static void
+print_alu(struct gc_string *string, struct eir_instruction *inst)
+{
+   for (unsigned i = 0; i < gc_op_num_src(inst->gc.opcode); i++)
+  print_src(string, >src[i]);
+}
+
+static void
+print_branch(struct gc_string *string, struct eir_instruction *inst)
+{
+   print_src(string, >src[0]);
+   print_src(string, >src[1]);
+   gc_string_append(string, &quo

[Mesa-dev] [RFC PATCH 01/17] etnaviv: add basic block based backend ir: eir

2019-05-10 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/etnaviv/compiler/eir.c  | 239 ++
 src/etnaviv/compiler/eir.h  | 499 
 src/etnaviv/compiler/eir_uniform.c  | 108 +
 src/etnaviv/compiler/meson.build|  38 ++
 src/etnaviv/compiler/tests/eir_assemble.cpp | 114 +
 src/etnaviv/compiler/tests/eir_uniform.cpp  | 324 +
 src/etnaviv/compiler/tests/meson.build  |  44 ++
 src/etnaviv/meson.build |   1 +
 8 files changed, 1367 insertions(+)
 create mode 100644 src/etnaviv/compiler/eir.c
 create mode 100644 src/etnaviv/compiler/eir.h
 create mode 100644 src/etnaviv/compiler/eir_uniform.c
 create mode 100644 src/etnaviv/compiler/meson.build
 create mode 100644 src/etnaviv/compiler/tests/eir_assemble.cpp
 create mode 100644 src/etnaviv/compiler/tests/eir_uniform.cpp
 create mode 100644 src/etnaviv/compiler/tests/meson.build

diff --git a/src/etnaviv/compiler/eir.c b/src/etnaviv/compiler/eir.c
new file mode 100644
index 000..398ae7443c5
--- /dev/null
+++ b/src/etnaviv/compiler/eir.c
@@ -0,0 +1,239 @@
+/*
+ * Copyright (c) 2018 Etnaviv Project
+ * Copyright (C) 2018 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *    Christian Gmeiner 
+ */
+
+#include "eir.h"
+#include 
+#include 
+#include "util/ralloc.h"
+
+struct eir *
+eir_create(void)
+{
+   struct eir *ir = rzalloc(NULL, struct eir);
+
+   list_inithead(>block_list);
+   util_dynarray_init(>reg_alloc, ir);
+   util_dynarray_init(>uniform_alloc, ir);
+
+   return ir;
+}
+
+void
+eir_destroy(struct eir *ir)
+{
+   assert(ir);
+   util_dynarray_fini(>reg_alloc);
+   util_dynarray_fini(>uniform_alloc);
+   ralloc_free(ir);
+}
+
+struct eir_block *
+eir_block_create(struct eir *ir)
+{
+   assert(ir);
+   struct eir_block *block = rzalloc(ir, struct eir_block);
+
+   block->ir = ir;
+   block->num = ir->blocks++;
+   list_inithead(>node);
+   list_inithead(>instr_list);
+
+   list_addtail(>node, >block_list);
+
+   return block;
+}
+
+struct eir_instruction *
+eir_instruction_create(struct eir_block *block, enum gc_op opc)
+{
+   assert(block);
+   struct eir_instruction *instr = rzalloc(block, struct eir_instruction);
+
+   instr->block = block;
+   list_addtail(>node, >instr_list);
+
+   instr->gc.opcode = opc;
+
+   return instr;
+}
+
+struct eir_register
+eir_temp_register(struct eir *ir, unsigned num_components)
+{
+   assert(num_components >= 1 && num_components <= 4);
+
+   struct eir_register reg = {
+  .type = EIR_REG_TEMP,
+  .index = util_dynarray_num_elements(>reg_alloc, unsigned),
+   };
+
+   util_dynarray_append(>reg_alloc, unsigned, num_components);
+
+   return reg;
+}
+
+void
+eir_link_blocks(struct eir_block *predecessor, struct eir_block *successor)
+{
+   assert(predecessor);
+   assert(successor);
+
+   if (predecessor->successors[0]) {
+  assert(!predecessor->successors[1]);
+  predecessor->successors[1] = successor;
+   } else {
+  predecessor->successors[0] = successor;
+   }
+}
+
+static void
+convert_sampler(const struct eir_register *eir, struct gc_instr_sampler 
*sampler)
+{
+   assert(eir->type == EIR_REG_SAMPLER);
+
+   sampler->id = eir->index;
+   sampler->swiz = eir->swizzle;
+   sampler->amode = GC_ADDRESSING_MODE_DIRECT;
+}
+
+static void
+convert_src(const struct eir_register *eir, struct gc_instr_src *gc)
+{
+   assert(!gc->use);
+   assert(eir->type != EIR_REG_UNDEF);
+   assert(eir->type != EIR_REG_SAMPLER);
+
+   gc->use = true;
+   gc->reg = eir->index;
+   gc->abs = eir->abs;
+   gc->neg = eir->neg;
+   gc->swiz = eir->swizzle;
+
+   switch (eir->type) {
+   case EIR_REG_TEMP:
+  gc->rgrou

[Mesa-dev] [RFC PATCH 03/17] eir: add live ranges pass

2019-05-10 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/etnaviv/compiler/eir.h|   3 +
 src/etnaviv/compiler/eir_live_variables.c | 258 ++
 src/etnaviv/compiler/meson.build  |   1 +
 .../compiler/tests/eir_live_variables.cpp | 162 +++
 src/etnaviv/compiler/tests/meson.build|  11 +
 5 files changed, 435 insertions(+)
 create mode 100644 src/etnaviv/compiler/eir_live_variables.c
 create mode 100644 src/etnaviv/compiler/tests/eir_live_variables.cpp

diff --git a/src/etnaviv/compiler/eir.h b/src/etnaviv/compiler/eir.h
index a05b12de94b..38c6af4e07e 100644
--- a/src/etnaviv/compiler/eir.h
+++ b/src/etnaviv/compiler/eir.h
@@ -151,6 +151,9 @@ struct eir
/* keep track of number of allocated uniforms */
struct util_dynarray uniform_alloc;
unsigned uniform_offset;
+
+   /* Live ranges of temp registers */
+   int *temp_start, *temp_end;
 };
 
 struct eir_info {
diff --git a/src/etnaviv/compiler/eir_live_variables.c 
b/src/etnaviv/compiler/eir_live_variables.c
new file mode 100644
index 000..fe94e7a2a3d
--- /dev/null
+++ b/src/etnaviv/compiler/eir_live_variables.c
@@ -0,0 +1,258 @@
+/*
+ * Copyright (c) 2018 Etnaviv Project
+ * Copyright (C) 2018 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *    Christian Gmeiner 
+ */
+
+#include "eir.h"
+#include "util/bitset.h"
+#include "util/ralloc.h"
+#include "util/u_math.h"
+
+#define MAX_INSTRUCTION (1 << 30)
+
+struct block_data {
+   BITSET_WORD *def;
+   BITSET_WORD *use;
+   BITSET_WORD *livein;
+   BITSET_WORD *liveout;
+   int start_ip, end_ip;
+};
+
+/* Returns the variable index for the c-th component of register reg. */
+static inline unsigned
+var_from_reg(unsigned reg, unsigned c)
+{
+   assert(c < 4);
+   return (reg * 4) + c;
+}
+
+static void
+setup_use(struct eir_block *block, const struct eir_register *src, int ip)
+{
+   const struct eir *ir = block->ir;
+   struct block_data *bd = block->data;
+
+   if (src->type != EIR_REG_TEMP)
+  return;
+
+   /* The use[] bitset marks when the block makes
+* use of a variable without having completely
+* defined that variable within the block.
+*/
+
+   const unsigned swiz_comp[4] = {
+  /* x */ src->swizzle & 0x3,
+  /* y */ (src->swizzle & 0x0C) >> 2,
+  /* z */ (src->swizzle & 0x30) >> 4,
+  /* w */ (src->swizzle & 0xc0) >> 6,
+   };
+
+   for (unsigned c = 0; c < 4; c++) {
+  const unsigned var = var_from_reg(src->index, swiz_comp[c]);
+
+  ir->temp_start[var] = MIN2(ir->temp_start[var], ip);
+  ir->temp_end[var] = ip;
+
+  if (!BITSET_TEST(bd->def, var))
+ BITSET_SET(bd->use, var);
+   }
+}
+
+static inline void
+setup_def(struct eir_block *block, const struct eir_register *dst, int ip)
+{
+   const struct eir *ir = block->ir;
+   struct block_data *bd = block->data;
+
+   for (unsigned c = 0; c < 4; c++) {
+  if (dst->writemask & (1 << c)) {
+ const unsigned var = var_from_reg(dst->index, c);
+
+ ir->temp_start[var] = MIN2(ir->temp_start[var], ip);
+ ir->temp_end[var] = ip;
+
+ BITSET_SET(bd->def, var);
+  }
+   }
+}
+
+static void
+setup_def_use(struct eir *ir)
+{
+   int ip = 0;
+
+   eir_for_each_block(block, ir) {
+  struct block_data *bd = block->data;
+  bd->start_ip = ip;
+
+  eir_for_each_inst(instr, block) {
+ const struct gc_instr *gc = >gc;
+
+ for (unsigned i = 0; i < gc_op_num_src(gc->opcode); i++)
+setup_use(block, >src[i], ip);
+
+ if (gc_op_has_dst(gc->opcode))
+setup_def(block, >dst, ip);
+
+ ip++;
+  }
+  bd->end_ip = ip;
+   }
+}
+
+

[Mesa-dev] [RFC PATCH 06/17] eir: add nir optimization loop

2019-05-10 Thread Christian Gmeiner
This change adds the eir_optimize_nir(..) function which gets used
to optimize and transform a nir shader for our needs.
Besides this there are some other nir helpers for compiler options
and tgsi handling.

Signed-off-by: Christian Gmeiner 
---
 src/etnaviv/compiler/eir_nir.c   | 131 +++
 src/etnaviv/compiler/eir_nir.h   |  40 ++
 src/etnaviv/compiler/meson.build |   2 +
 3 files changed, 173 insertions(+)
 create mode 100644 src/etnaviv/compiler/eir_nir.c
 create mode 100644 src/etnaviv/compiler/eir_nir.h

diff --git a/src/etnaviv/compiler/eir_nir.c b/src/etnaviv/compiler/eir_nir.c
new file mode 100644
index 000..6e75f2c5fd8
--- /dev/null
+++ b/src/etnaviv/compiler/eir_nir.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2018 Etnaviv Project
+ * Copyright (C) 2018 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *    Christian Gmeiner 
+ */
+
+#include "eir_nir.h"
+#include "compiler/nir/nir.h"
+
+static const nir_shader_compiler_options options = {
+   .lower_all_io_to_temps = true,
+   .fdot_replicates = true,
+   .fuse_ffma = true,
+   .lower_sub = true,
+   .lower_fpow = true,
+   .lower_flrp32 = true,
+   .lower_ftrunc = true,
+   .max_unroll_iterations = 32
+};
+
+const struct nir_shader_compiler_options *
+eir_get_compiler_options(void)
+{
+   return 
+}
+
+#define OPT(nir, pass, ...) ({ \
+   bool this_progress = false; \
+   NIR_PASS(this_progress, nir, pass, ##__VA_ARGS__);  \
+   this_progress;  \
+})
+
+#define OPT_V(nir, pass, ...) NIR_PASS_V(nir, pass, ##__VA_ARGS__)
+
+static void
+eir_optimize_loop(struct nir_shader *s)
+{
+   bool progress;
+   do {
+  progress = false;
+
+  OPT_V(s, nir_lower_vars_to_ssa);
+  progress |= OPT(s, nir_opt_copy_prop_vars);
+  progress |= OPT(s, nir_copy_prop);
+  progress |= OPT(s, nir_opt_dce);
+  progress |= OPT(s, nir_opt_cse);
+  progress |= OPT(s, nir_opt_peephole_select, 16, true, true);
+  progress |= OPT(s, nir_opt_intrinsics);
+  progress |= OPT(s, nir_opt_algebraic);
+  progress |= OPT(s, nir_opt_constant_folding);
+  progress |= OPT(s, nir_opt_dead_cf);
+  if (OPT(s, nir_opt_trivial_continues)) {
+ progress |= true;
+ /* If nir_opt_trivial_continues makes progress, then we need to clean
+  * things up if we want any hope of nir_opt_if or nir_opt_loop_unroll
+  * to make progress.
+  */
+ OPT(s, nir_copy_prop);
+ OPT(s, nir_opt_dce);
+  }
+  progress |= OPT(s, nir_opt_if, false);
+
+  if (s->options->max_unroll_iterations)
+ progress |= OPT(s, nir_opt_loop_unroll, 0);
+
+  progress |= OPT(s, nir_opt_remove_phis);
+  progress |= OPT(s, nir_opt_undef);
+
+   } while (progress);
+}
+
+struct nir_shader *
+eir_optimize_nir(struct nir_shader *s)
+{
+   struct nir_lower_tex_options tex_options = {
+  .lower_txp = ~0,
+  .lower_rect = true,
+   };
+
+   OPT_V(s, nir_lower_tex, _options);
+   OPT_V(s, nir_lower_global_vars_to_local);
+   OPT_V(s, nir_lower_regs_to_ssa);
+
+   OPT_V(s, nir_opt_algebraic);
+
+   eir_optimize_loop(s);
+
+   OPT_V(s, nir_remove_dead_variables, nir_var_function_temp);
+
+   OPT_V(s, nir_opt_algebraic_late);
+
+   OPT_V(s, nir_lower_to_source_mods, nir_lower_all_source_mods);
+   OPT_V(s, nir_copy_prop);
+   OPT_V(s, nir_opt_dce);
+   OPT_V(s, nir_opt_move_comparisons);
+
+   OPT_V(s, nir_lower_bool_to_float);
+   OPT_V(s, nir_lower_int_to_float);
+   OPT_V(s, nir_lower_locals_to_regs);
+   OPT_V(s, nir_convert_from_ssa, true);
+   OPT_V(s, nir_move_vec_src_uses_to_dest);
+   OPT_V(s, nir_lower_vec_to_movs);
+
+   /* TODO: nir_lower_vec_to_movs can generate imov's */
+   OPT_V(s, nir_lower_bool_to_float

[Mesa-dev] [RFC PATCH 11/17] etnaviv: add eir_compiler

2019-05-10 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/eir_cmdline.c | 189 ++
 src/gallium/drivers/etnaviv/meson.build   |  20 +++
 2 files changed, 209 insertions(+)
 create mode 100644 src/gallium/drivers/etnaviv/eir_cmdline.c

diff --git a/src/gallium/drivers/etnaviv/eir_cmdline.c 
b/src/gallium/drivers/etnaviv/eir_cmdline.c
new file mode 100644
index 000..f888a649050
--- /dev/null
+++ b/src/gallium/drivers/etnaviv/eir_cmdline.c
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2017 Etnaviv Project
+ * Copyright (C) 2017 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *    Rob Clark 
+ *    Christian Gmeiner 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "main/mtypes.h"
+
+#include "compiler/eir_compiler.h"
+#include "compiler/eir_nir.h"
+#include "compiler/eir_shader.h"
+#include "compiler/glsl/standalone.h"
+#include "compiler/glsl/glsl_to_nir.h"
+
+#include "etnaviv_eir.h"
+
+#include "tgsi/tgsi_parse.h"
+#include "tgsi/tgsi_text.h"
+
+#include "util/u_debug.h"
+
+int st_glsl_type_size(const struct glsl_type *type);
+
+static nir_shader *
+load_glsl(const char *filename, gl_shader_stage stage)
+{
+   static const struct standalone_options options = {
+  .glsl_version = 120,
+  .do_link = true,
+   };
+   static struct gl_context local_ctx;
+   struct gl_shader_program *prog;
+
+   prog = standalone_compile_shader(, 1, (char * const*), 
_ctx);
+   if (!prog)
+   errx(1, "couldn't parse `%s'", filename);
+
+   nir_shader *nir = glsl_to_nir(_ctx, prog, stage, 
eir_get_compiler_options());
+
+   standalone_compiler_cleanup(prog);
+
+   return nir;
+}
+
+static int
+read_file(const char *filename, void **ptr, size_t *size)
+{
+   int fd, ret;
+   struct stat st;
+
+   *ptr = MAP_FAILED;
+
+   fd = open(filename, O_RDONLY);
+   if (fd == -1) {
+  warnx("couldn't open `%s'", filename);
+  return 1;
+   }
+
+   ret = fstat(fd, );
+   if (ret)
+  errx(1, "couldn't stat `%s'", filename);
+
+   *size = st.st_size;
+   *ptr = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+   if (*ptr == MAP_FAILED)
+  errx(1, "couldn't map `%s'", filename);
+
+   close(fd);
+
+   return 0;
+}
+
+static void
+print_usage(void)
+{
+   printf("Usage: etnaviv_compiler [OPTIONS]... \n");
+   printf("--verbose - verbose compiler/debug messages\n");
+   printf("--frag-rb-swap- swap rb in color output (FRAG)\n");
+   printf("--help- show this message\n");
+}
+
+int main(int argc, char **argv)
+{
+   int ret, n = 1;
+   const char *filename;
+   struct eir_shader_key key = {};
+   void *ptr;
+   size_t size;
+   bool verbose = false;
+
+   while (n < argc) {
+  if (!strcmp(argv[n], "--verbose")) {
+ verbose = true;
+ n++;
+ continue;
+  }
+
+  if (!strcmp(argv[n], "--frag-rb-swap")) {
+ debug_printf(" %s", argv[n]);
+ key.frag_rb_swap = true;
+ n++;
+ continue;
+  }
+
+  if (!strcmp(argv[n], "--help")) {
+ print_usage();
+ return 0;
+  }
+
+  break;
+   }
+
+   filename = argv[n];
+
+   ret = read_file(filename, , );
+   if (ret) {
+  print_usage();
+  return ret;
+   }
+
+   debug_printf("%s\n", (char *)ptr);
+   nir_shader *nir;
+   const char *ext = rindex(filename, '.');
+
+   if (strcmp(ext, ".tgsi") == 0) {
+  struct tgsi_token toks[65536];
+
+  if (!tgsi_text_translate(ptr, toks, ARRAY_SIZE(toks)))
+ errx(1, "could not parse `%s'", filename);
+
+  nir = eir_t

[Mesa-dev] [RFC PATCH 17/17] eir: add peephole optimization

2019-05-10 Thread Christian Gmeiner
Some created shaders can contain instructions like:
  mov t0 t0

This simple pass removes that kind of mov instructions.

Signed-off-by: Christian Gmeiner 
---
 src/etnaviv/compiler/eir_opt_peephole.c | 63 +
 src/etnaviv/compiler/eir_optimize.c |  4 +-
 src/etnaviv/compiler/eir_optimize.h |  5 ++
 src/etnaviv/compiler/meson.build|  1 +
 4 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 src/etnaviv/compiler/eir_opt_peephole.c

diff --git a/src/etnaviv/compiler/eir_opt_peephole.c 
b/src/etnaviv/compiler/eir_opt_peephole.c
new file mode 100644
index 000..a8cf848d652
--- /dev/null
+++ b/src/etnaviv/compiler/eir_opt_peephole.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2019 Etnaviv Project
+ * Copyright (C) 2019 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *    Christian Gmeiner 
+ */
+
+#include "eir.h"
+#include "eir_optimize.h"
+
+static bool
+eir_opt_peephole_impl(struct eir_instruction *instr)
+{
+   /* remove "mov t0 t0" as seen with bin/gl-2.0-vertex-attr-0 */
+
+   if (instr->gc.opcode != GC_MOV)
+  return false;
+
+   if (instr->src[0].index != instr->dst.index)
+  return false;
+
+   if (instr->dst.writemask != (INST_COMPS_X | INST_COMPS_Y | INST_COMPS_Z | 
INST_COMPS_W))
+  return false;
+
+   if (instr->src[0].swizzle != INST_SWIZ_IDENTITY)
+  return false;
+
+   list_del(>node);
+
+   return true;
+}
+
+bool
+eir_opt_peephole(struct eir *ir)
+{
+   bool progress = false;
+
+   eir_for_each_block(block, ir)
+  eir_for_each_inst_safe(inst, block)
+ progress |= eir_opt_peephole_impl(inst);
+
+   return progress;
+}
diff --git a/src/etnaviv/compiler/eir_optimize.c 
b/src/etnaviv/compiler/eir_optimize.c
index 6eae8e9c9ec..695ef76001a 100644
--- a/src/etnaviv/compiler/eir_optimize.c
+++ b/src/etnaviv/compiler/eir_optimize.c
@@ -44,5 +44,7 @@
 void
 eir_optimize(struct eir *ir)
 {
-   const bool print_opt_debug = true;
+   const bool print_opt_debug = false;
+
+   OPTPASS(eir_opt_peephole);
 }
diff --git a/src/etnaviv/compiler/eir_optimize.h 
b/src/etnaviv/compiler/eir_optimize.h
index b840a273c25..ecc9e44713c 100644
--- a/src/etnaviv/compiler/eir_optimize.h
+++ b/src/etnaviv/compiler/eir_optimize.h
@@ -28,4 +28,9 @@
 #ifndef H_EIR_OPTIMIZE
 #define H_EIR_OPTIMIZE
 
+struct eir;
+
+bool
+eir_opt_peephole(struct eir *ir);
+
 #endif // H_EIR_OPTIMIZE
diff --git a/src/etnaviv/compiler/meson.build b/src/etnaviv/compiler/meson.build
index 8343e6b91ad..f43e868208a 100644
--- a/src/etnaviv/compiler/meson.build
+++ b/src/etnaviv/compiler/meson.build
@@ -31,6 +31,7 @@ libetnaviv_compiler_files = files(
   'eir_nir_lower_alu_to_scalar.c',
   'eir_nir.c',
   'eir_nir.h',
+  'eir_opt_peephole.c',
   'eir_optimize.c',
   'eir_print.c',
   'eir_register_allocate.c',
-- 
2.21.0

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

[Mesa-dev] [RFC PATCH 16/17] eir: add optimization 'framework'

2019-05-10 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/etnaviv/compiler/eir.h  |  3 ++
 src/etnaviv/compiler/eir_compiler_nir.c |  6 
 src/etnaviv/compiler/eir_optimize.c | 48 +
 src/etnaviv/compiler/eir_optimize.h | 31 
 src/etnaviv/compiler/meson.build|  1 +
 5 files changed, 89 insertions(+)
 create mode 100644 src/etnaviv/compiler/eir_optimize.c
 create mode 100644 src/etnaviv/compiler/eir_optimize.h

diff --git a/src/etnaviv/compiler/eir.h b/src/etnaviv/compiler/eir.h
index 1b67edab559..f46d12b822a 100644
--- a/src/etnaviv/compiler/eir.h
+++ b/src/etnaviv/compiler/eir.h
@@ -294,6 +294,9 @@ eir_assign_output(struct eir *ir, unsigned idx, unsigned 
slot, unsigned ncomp)
 void
 eir_legalize(struct eir *ir);
 
+void
+eir_optimize(struct eir *ir);
+
 void
 eir_calculate_live_intervals(struct eir *ir);
 
diff --git a/src/etnaviv/compiler/eir_compiler_nir.c 
b/src/etnaviv/compiler/eir_compiler_nir.c
index 862f34390e0..4dbbd5e8f0a 100644
--- a/src/etnaviv/compiler/eir_compiler_nir.c
+++ b/src/etnaviv/compiler/eir_compiler_nir.c
@@ -991,6 +991,12 @@ eir_compile_shader_nir(struct eir_compiler *compiler,
   eir_print(ctx->ir);
}
 
+   eir_optimize(ctx->ir);
+   if (eir_compiler_debug & EIR_DBG_OPTMSGS) {
+  printf("AFTER eir_optimize:\n");
+  eir_print(ctx->ir);
+   }
+
eir_legalize(ctx->ir);
if (eir_compiler_debug & EIR_DBG_OPTMSGS) {
   printf("AFTER legalization:\n");
diff --git a/src/etnaviv/compiler/eir_optimize.c 
b/src/etnaviv/compiler/eir_optimize.c
new file mode 100644
index 000..6eae8e9c9ec
--- /dev/null
+++ b/src/etnaviv/compiler/eir_optimize.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2019 Etnaviv Project
+ * Copyright (C) 2019 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *Christian Gmeiner 
+ */
+
+#include "eir.h"
+#include "eir_optimize.h"
+#include 
+
+#define OPTPASS(func) \
+   do {   \
+ bool stage_progress = func(ir);  \
+ if (stage_progress) {\
+if (print_opt_debug) {\
+   fprintf(stderr,\
+   "EIR opt pass %s progress\n",  \
+   #func);\
+} \
+ }\
+   } while (0)
+
+void
+eir_optimize(struct eir *ir)
+{
+   const bool print_opt_debug = true;
+}
diff --git a/src/etnaviv/compiler/eir_optimize.h 
b/src/etnaviv/compiler/eir_optimize.h
new file mode 100644
index 000..b840a273c25
--- /dev/null
+++ b/src/etnaviv/compiler/eir_optimize.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2019 Etnaviv Project
+ * Copyright (C) 2019 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS 

[Mesa-dev] [RFC PATCH 12/17] etnaviv: add debug option to report NIR as supported and preferred shader IR

2019-05-10 Thread Christian Gmeiner
Add a debug option ETNA_MESA_DEBUG="nir" that will cause the etnaviv
gallium pipe driver to advertise support and preference for NIR shaders.

Signed-off-by: Philipp Zabel 
Signed-off-by: Michael Tretter 
---
 src/gallium/drivers/etnaviv/etnaviv_debug.h  |  3 +++
 src/gallium/drivers/etnaviv/etnaviv_screen.c | 11 +--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_debug.h 
b/src/gallium/drivers/etnaviv/etnaviv_debug.h
index 4051e95dd5f..8dacf6b2433 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_debug.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_debug.h
@@ -54,6 +54,9 @@
 #define ETNA_DBG_SHADERDB0x80 /* dump program compile information 
*/
 #define ETNA_DBG_NO_SINGLEBUF0x100 /* disable single buffer feature */
 
+/* Experimental features */
+#define ETNA_DBG_NIR   0x1000 /* Enable NIR compiler */
+
 extern int etna_mesa_debug; /* set in etna_screen.c from ETNA_DEBUG */
 
 #define DBG_ENABLED(flag) unlikely(etna_mesa_debug & (flag))
diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c 
b/src/gallium/drivers/etnaviv/etnaviv_screen.c
index 641ee80948c..3e151e75159 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c
@@ -69,6 +69,7 @@ static const struct debug_named_value debug_options[] = {
{"cflush_all", ETNA_DBG_CFLUSH_ALL, "Flush every cache before state 
update"},
{"msaa2x", ETNA_DBG_MSAA_2X, "Force 2x msaa"},
{"msaa4x", ETNA_DBG_MSAA_4X, "Force 4x msaa"},
+   {"nir",ETNA_DBG_NIR, "Enable experimental NIR compiler"},
{"flush_all",  ETNA_DBG_FLUSH_ALL, "Flush after every rendered 
primitive"},
{"zero",   ETNA_DBG_ZERO, "Zero all resources after allocation"},
{"draw_stall", ETNA_DBG_DRAW_STALL, "Stall FE/PE after each rendered 
primitive"},
@@ -486,7 +487,10 @@ etna_screen_get_shader_param(struct pipe_screen *pscreen,
 ? screen->specs.fragment_sampler_count
 : screen->specs.vertex_sampler_count;
case PIPE_SHADER_CAP_PREFERRED_IR:
-  return PIPE_SHADER_IR_TGSI;
+  if (etna_mesa_debug & ETNA_DBG_NIR)
+ return PIPE_SHADER_IR_NIR;
+  else
+ return PIPE_SHADER_IR_TGSI;
case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE:
   return 4096;
case PIPE_SHADER_CAP_TGSI_DROUND_SUPPORTED:
@@ -496,7 +500,10 @@ etna_screen_get_shader_param(struct pipe_screen *pscreen,
case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
   return false;
case PIPE_SHADER_CAP_SUPPORTED_IRS:
-  return 0;
+  if (etna_mesa_debug & ETNA_DBG_NIR)
+ return (1 << PIPE_SHADER_IR_TGSI) | (1 << PIPE_SHADER_IR_NIR);
+  else
+ return (1 << PIPE_SHADER_IR_TGSI);
case PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT:
   return 32;
case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
-- 
2.21.0

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

[Mesa-dev] [RFC PATCH 14/17] eir: add nir alu to scalar lowering pass

2019-05-10 Thread Christian Gmeiner
Some operations are scalar and need special treatment. Those
are exp and log2.

  dst := exp2(src2.x)
  dst := log2(src2.x)

The result is broadcasted over all active destination components.

Signed-off-by: Christian Gmeiner 
---
 src/etnaviv/compiler/eir_nir.h|   3 +
 .../compiler/eir_nir_lower_alu_to_scalar.c| 131 ++
 src/etnaviv/compiler/meson.build  |   1 +
 3 files changed, 135 insertions(+)
 create mode 100644 src/etnaviv/compiler/eir_nir_lower_alu_to_scalar.c

diff --git a/src/etnaviv/compiler/eir_nir.h b/src/etnaviv/compiler/eir_nir.h
index 0ba5fa8e6a3..cd21cae38e4 100644
--- a/src/etnaviv/compiler/eir_nir.h
+++ b/src/etnaviv/compiler/eir_nir.h
@@ -37,4 +37,7 @@ eir_get_compiler_options(void);
 struct nir_shader *
 eir_optimize_nir(struct nir_shader *s);
 
+void
+eir_nir_lower_alu_to_scalar(struct nir_shader *shader);
+
 #endif // H_EIR_NIR
diff --git a/src/etnaviv/compiler/eir_nir_lower_alu_to_scalar.c 
b/src/etnaviv/compiler/eir_nir_lower_alu_to_scalar.c
new file mode 100644
index 000..8dc264d083f
--- /dev/null
+++ b/src/etnaviv/compiler/eir_nir_lower_alu_to_scalar.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2019 Etnaviv Project
+ * Copyright (C) 2019 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *    Christian Gmeiner 
+ */
+
+#include "eir_nir.h"
+#include "nir.h"
+#include "nir_builder.h"
+
+/** @file eir_nir_lower_to_scalar.c
+ *
+ * Replaces nir alu operations with individual per-channel operations.
+ */
+
+static void
+nir_alu_ssa_dest_init(nir_alu_instr *instr, unsigned num_components,
+  unsigned bit_size)
+{
+   nir_ssa_dest_init(>instr, >dest.dest, num_components,
+ bit_size, NULL);
+   instr->dest.write_mask = (1 << num_components) - 1;
+}
+
+static nir_ssa_def *
+replace(nir_builder *b, nir_alu_instr *instr)
+{
+   unsigned num_src = nir_op_infos[instr->op].num_inputs;
+   unsigned num_components = instr->dest.dest.ssa.num_components;
+   nir_ssa_def *comps[NIR_MAX_VEC_COMPONENTS] = { NULL };
+   unsigned i, chan;
+
+   for (chan = 0; chan < NIR_MAX_VEC_COMPONENTS; chan++) {
+  if (!(instr->dest.write_mask & (1 << chan)))
+ continue;
+
+  nir_alu_instr *lower = nir_alu_instr_create(b->shader, instr->op);
+  for (i = 0; i < num_src; i++) {
+ /* We only handle same-size-as-dest (input_sizes[] == 0) or scalar
+  * args (input_sizes[] == 1).
+  */
+ assert(nir_op_infos[instr->op].input_sizes[i] < 2);
+ unsigned src_chan = (nir_op_infos[instr->op].input_sizes[i] == 1 ?
+  0 : chan);
+
+ nir_alu_src_copy(>src[i], >src[i], lower);
+ for (int j = 0; j < NIR_MAX_VEC_COMPONENTS; j++)
+lower->src[i].swizzle[j] = instr->src[i].swizzle[src_chan];
+  }
+
+  nir_alu_ssa_dest_init(lower, 1, instr->dest.dest.ssa.bit_size);
+  lower->dest.saturate = instr->dest.saturate;
+  comps[chan] = >dest.dest.ssa;
+  lower->exact = instr->exact;
+
+  nir_builder_instr_insert(b, >instr);
+   }
+
+   return nir_vec(b, comps, num_components);
+}
+
+static void
+lower_alu_to_scalar_impl(nir_function_impl *impl)
+{
+   bool progress = false;
+
+   nir_builder b;
+   nir_builder_init(, impl);
+
+   nir_foreach_block(block, impl) {
+  nir_foreach_instr_safe(instr, block) {
+ if (instr->type != nir_instr_type_alu)
+continue;
+
+ nir_alu_instr *alu_instr = nir_instr_as_alu(instr);
+ nir_ssa_def *vec;
+
+ b.cursor = nir_before_instr(instr);
+
+ switch (alu_instr->op) {
+ case nir_op_fexp2:
+/* fall-through */
+ case nir_op_flog2:
+vec = replace

[Mesa-dev] [RFC PATCH 13/17] etnaviv: enable nir paths

2019-05-10 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_context.c | 23 ++--
 src/gallium/drivers/etnaviv/etnaviv_shader.c  | 55 +--
 2 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.c 
b/src/gallium/drivers/etnaviv/etnaviv_context.c
index d78d8941087..3b764f0111b 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.c
@@ -25,6 +25,8 @@
  *Christian Gmeiner 
  */
 
+#include "etnaviv_eir.h"   /* TODO: fix problems with COMPARE_FUNC_NEVER */
+
 #include "etnaviv_context.h"
 
 #include "etnaviv_blend.h"
@@ -466,12 +468,21 @@ etna_context_create(struct pipe_screen *pscreen, void 
*priv, unsigned flags)
etna_texture_init(pctx);
etna_transfer_init(pctx);
 
-   ctx->uniform_dirty_flags = etna_uniform_dirty_flags;
-   ctx->uniforms_write = etna_uniforms_write;
-   ctx->uniforms_const_count = etna_uniforms_const_count;
-   ctx->create_shader_variant = etna_shader_variant;
-   ctx->shader_link = etna_shader_link;
-   ctx->shader_update_vertex = etna_shader_update_vertex;
+   if (etna_mesa_debug & ETNA_DBG_NIR) {
+  ctx->uniform_dirty_flags = eir_uniform_dirty_flags;
+  ctx->uniforms_write = eir_uniforms_write;
+  ctx->uniforms_const_count = eir_uniforms_const_count;
+  ctx->create_shader_variant = eir_shader_variant;
+  ctx->shader_link = eir_link_shaders;
+  ctx->shader_update_vertex = eir_shader_update_vertex;
+   } else {
+  ctx->uniform_dirty_flags = etna_uniform_dirty_flags;
+  ctx->uniforms_write = etna_uniforms_write;
+  ctx->uniforms_const_count = etna_uniforms_const_count;
+  ctx->create_shader_variant = etna_shader_variant;
+  ctx->shader_link = etna_shader_link;
+  ctx->shader_update_vertex = etna_shader_update_vertex;
+   }
 
ctx->blitter = util_blitter_create(pctx);
if (!ctx->blitter)
diff --git a/src/gallium/drivers/etnaviv/etnaviv_shader.c 
b/src/gallium/drivers/etnaviv/etnaviv_shader.c
index 34c546c3c66..cec27dcb2f8 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_shader.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_shader.c
@@ -24,6 +24,7 @@
  *Wladimir J. van der Laan 
  */
 
+#include "etnaviv_eir.h"
 #include "etnaviv_shader.h"
 
 #include "etnaviv_compiler.h"
@@ -36,6 +37,44 @@
 #include "util/u_math.h"
 #include "util/u_memory.h"
 
+static struct eir_shader *
+create_shader_stateobj(struct pipe_context *pctx, const struct 
pipe_shader_state *cso,
+   gl_shader_stage type)
+{
+   struct etna_context *ctx = etna_context(pctx);
+   struct eir_compiler *compiler = ctx->screen->compiler;
+
+   return eir_shader_create(compiler, cso, type, >debug, pctx->screen);
+}
+
+static void *
+etna_fs_state_create(struct pipe_context *pctx, const struct pipe_shader_state 
*cso)
+{
+   return create_shader_stateobj(pctx, cso, MESA_SHADER_FRAGMENT);
+}
+
+static void
+etna_fs_state_delete(struct pipe_context *pctx, void *hwcso)
+{
+   struct eir_shader *so = hwcso;
+
+   eir_shader_destroy(so);
+}
+
+static void *
+etna_vs_state_create(struct pipe_context *pctx, const struct pipe_shader_state 
*cso)
+{
+   return create_shader_stateobj(pctx, cso, MESA_SHADER_VERTEX);
+}
+
+static void
+etna_vs_state_delete(struct pipe_context *pctx, void *hwcso)
+{
+   struct eir_shader *so = hwcso;
+
+   eir_shader_destroy(so);
+}
+
 /* Upload shader code to bo, if not already done */
 static bool etna_icache_upload_shader(struct etna_context *ctx, struct 
etna_shader_variant *v)
 {
@@ -459,10 +498,18 @@ etna_bind_vs_state(struct pipe_context *pctx, void *hwcso)
 void
 etna_shader_init(struct pipe_context *pctx)
 {
-   pctx->create_fs_state = etna_create_shader_state;
+   if (etna_mesa_debug & ETNA_DBG_NIR) {
+  pctx->create_fs_state = etna_fs_state_create;
+  pctx->delete_fs_state = etna_fs_state_delete;
+  pctx->create_vs_state = etna_vs_state_create;
+  pctx->delete_vs_state = etna_vs_state_delete;
+   } else {
+  pctx->create_fs_state = etna_create_shader_state;
+  pctx->delete_fs_state = etna_delete_shader_state;
+  pctx->create_vs_state = etna_create_shader_state;
+  pctx->delete_vs_state = etna_delete_shader_state;
+   }
+
pctx->bind_fs_state = etna_bind_fs_state;
-   pctx->delete_fs_state = etna_delete_shader_state;
-   pctx->create_vs_state = etna_create_shader_state;
pctx->bind_vs_state = etna_bind_vs_state;
-   pctx->delete_vs_state = etna_delete_shader_state;
 }
-- 
2.21.0

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

[Mesa-dev] [RFC PATCH 09/17] etnaviv: become independed of the used compiler backend

2019-05-10 Thread Christian Gmeiner
This change preps etnaviv to be able to swap the used compiler
backend easily. It takes care of uniform stuff and the actual
creation of shader variants. In the long run - if one backend
won - we can remove this again.

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_context.c | 16 
 src/gallium/drivers/etnaviv/etnaviv_context.h | 18 +-
 src/gallium/drivers/etnaviv/etnaviv_emit.c| 16 
 src/gallium/drivers/etnaviv/etnaviv_shader.c  |  5 +++--
 src/gallium/drivers/etnaviv/etnaviv_shader.h  |  4 ++--
 src/gallium/drivers/etnaviv/etnaviv_state.c   | 16 ++--
 .../drivers/etnaviv/etnaviv_uniforms.c| 19 ++-
 .../drivers/etnaviv/etnaviv_uniforms.h|  8 +++-
 8 files changed, 81 insertions(+), 21 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.c 
b/src/gallium/drivers/etnaviv/etnaviv_context.c
index a59338490b6..d78d8941087 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.c
@@ -44,6 +44,7 @@
 #include "etnaviv_texture.h"
 #include "etnaviv_transfer.h"
 #include "etnaviv_translate.h"
+#include "etnaviv_uniforms.h"
 #include "etnaviv_zsa.h"
 
 #include "pipe/p_context.h"
@@ -119,9 +120,9 @@ etna_update_state_for_draw(struct etna_context *ctx, const 
struct pipe_draw_info
 static bool
 etna_get_vs(struct etna_context *ctx, struct etna_shader_key key)
 {
-   const struct etna_shader_variant *old = ctx->shader.vs;
+   const void *old = ctx->shader.vs;
 
-   ctx->shader.vs = etna_shader_variant(ctx->shader.bind_vs, key, >debug);
+   ctx->shader.vs = ctx->create_shader_variant(ctx->shader.bind_vs, key, 
>debug);
 
if (!ctx->shader.vs)
   return false;
@@ -135,9 +136,9 @@ etna_get_vs(struct etna_context *ctx, struct 
etna_shader_key key)
 static bool
 etna_get_fs(struct etna_context *ctx, struct etna_shader_key key)
 {
-   const struct etna_shader_variant *old = ctx->shader.fs;
+   const void *old = ctx->shader.fs;
 
-   ctx->shader.fs = etna_shader_variant(ctx->shader.bind_fs, key, >debug);
+   ctx->shader.fs = ctx->create_shader_variant(ctx->shader.bind_fs, key, 
>debug);
 
if (!ctx->shader.fs)
   return false;
@@ -465,6 +466,13 @@ etna_context_create(struct pipe_screen *pscreen, void 
*priv, unsigned flags)
etna_texture_init(pctx);
etna_transfer_init(pctx);
 
+   ctx->uniform_dirty_flags = etna_uniform_dirty_flags;
+   ctx->uniforms_write = etna_uniforms_write;
+   ctx->uniforms_const_count = etna_uniforms_const_count;
+   ctx->create_shader_variant = etna_shader_variant;
+   ctx->shader_link = etna_shader_link;
+   ctx->shader_update_vertex = etna_shader_update_vertex;
+
ctx->blitter = util_blitter_create(pctx);
if (!ctx->blitter)
   goto fail;
diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.h 
b/src/gallium/drivers/etnaviv/etnaviv_context.h
index a79d739100d..a20f3d6cf79 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.h
@@ -31,6 +31,7 @@
 #include 
 
 #include "etnaviv_resource.h"
+#include "etnaviv_shader.h"
 #include "etnaviv_tiling.h"
 #include "indices/u_primconvert.h"
 #include "pipe/p_context.h"
@@ -82,7 +83,7 @@ struct etna_vertexbuf_state {
 
 struct etna_shader_state {
void *bind_vs, *bind_fs;
-   struct etna_shader_variant *vs, *fs;
+   void *vs, *fs;
 };
 
 enum etna_immediate_contents {
@@ -191,6 +192,21 @@ struct etna_context {
 
struct etna_bo *dummy_rt;
struct etna_reloc dummy_rt_reloc;
+
+   /* abstraction to support different compilers backends */
+   uint32_t (*uniform_dirty_flags)(const void *sobj);
+   void (*uniforms_write)(const struct etna_context *ctx,
+  const void *sobj,
+  struct pipe_constant_buffer *cb,
+  uint32_t *uniforms,
+  unsigned *size);
+   uint32_t (*uniforms_const_count)(const void *sobj);
+
+   void *(*create_shader_variant)(void *shader,
+  struct etna_shader_key key,
+  struct pipe_debug_callback *debug);
+   bool (*shader_link)(struct etna_context *ctx);
+   bool (*shader_update_vertex)(struct etna_context *ctx);
 };
 
 static inline struct etna_context *
diff --git a/src/gallium/drivers/etnaviv/etnaviv_emit.c 
b/src/gallium/drivers/etnaviv/etnaviv_emit.c
index ed7b7ee3cb8..f6f2d83e607 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_emit.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_emit.c
@@ -105,8 +105,8 @@ required_stream_size(struct etna_context *ctx)
size += ctx->vertex_elements->num_elements + 1;
 
/* uniforms - worst case (2 words per uniform load) */
-   size += ctx->shad

[Mesa-dev] [RFC PATCH 02/17] eir: add legalization

2019-05-10 Thread Christian Gmeiner
- if shader is empty add a NOP instruction
- avoid multiple uniform src for alu ops
- resolve jump target

Signed-off-by: Christian Gmeiner 
---
 src/etnaviv/compiler/eir.h  |   3 +
 src/etnaviv/compiler/eir_legalize.c | 177 
 src/etnaviv/compiler/meson.build|   1 +
 src/etnaviv/compiler/tests/eir_legalize.cpp | 136 +++
 src/etnaviv/compiler/tests/meson.build  |  10 ++
 5 files changed, 327 insertions(+)
 create mode 100644 src/etnaviv/compiler/eir_legalize.c
 create mode 100644 src/etnaviv/compiler/tests/eir_legalize.cpp

diff --git a/src/etnaviv/compiler/eir.h b/src/etnaviv/compiler/eir.h
index e2185b004f1..a05b12de94b 100644
--- a/src/etnaviv/compiler/eir.h
+++ b/src/etnaviv/compiler/eir.h
@@ -282,6 +282,9 @@ eir_assign_output(struct eir *ir, unsigned idx, unsigned 
slot, unsigned ncomp)
ir->num_outputs = MAX2(ir->num_outputs, idx + 1);
 }
 
+void
+eir_legalize(struct eir *ir);
+
 void
 eir_calculate_live_intervals(struct eir *ir);
 
diff --git a/src/etnaviv/compiler/eir_legalize.c 
b/src/etnaviv/compiler/eir_legalize.c
new file mode 100644
index 000..94f5c2bd12b
--- /dev/null
+++ b/src/etnaviv/compiler/eir_legalize.c
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2018 Etnaviv Project
+ * Copyright (C) 2018 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *Christian Gmeiner 
+ */
+
+#include "eir.h"
+#include "etnaviv/gc/gc_instr.h"
+
+static int
+invalid_uniform_usage(const struct eir_instruction *inst)
+{
+   const struct gc_instr *gc = >gc;
+   int invalid = 0;
+   bool first_uniform = true;
+   int index;
+
+   if (gc->type != GC_OP_TYPE_ALU)
+  return 0;
+
+   for (unsigned i = 0; i < gc_op_num_src(gc->opcode); i++) {
+  const struct eir_register *src = >src[i];
+
+  if (src->type != EIR_REG_UNIFORM)
+ continue;
+
+  if (first_uniform) {
+ index = src->index;
+ first_uniform = false;
+ continue;
+  }
+
+  if (src->index == index)
+ continue;
+
+  invalid |= 1 << i;
+   }
+
+   return invalid;
+}
+
+static void
+legalize_uniform_usage(struct eir_block *block, struct eir_instruction *inst)
+{
+   /*
+   * The hardware does not allow two or more different uniform registers to be 
used as
+   * sources in the same ALU instruction. Emit mov instructions to temporary 
registers
+   * for all but one uniform register in this case.
+   */
+   int mask = invalid_uniform_usage(inst);
+
+   while (mask) {
+  const int i = ffs(mask) - 1;
+  struct eir_register *src = >src[i];
+  struct eir_register tmp = eir_temp_register(block->ir, 4);
+
+  tmp.writemask = 0xf; /* TODO */
+
+  eir_MOV(block, , src);
+  src->type = EIR_REG_TEMP;
+  src->index = tmp.index;
+
+  mask &= ~(1 << i);
+   }
+}
+
+static void
+legalize_block(struct eir_block *block)
+{
+   struct list_head instr_list;
+
+   /*
+* Remove all the instructions from the list, we'll be adding
+* them back in as we go
+*/
+   list_replace(>instr_list, _list);
+   list_inithead(>instr_list);
+
+   list_for_each_entry_safe (struct eir_instruction, inst, _list, node) {
+  legalize_uniform_usage(block, inst);
+  list_addtail(>node, >instr_list);
+   }
+}
+
+struct block_data {
+   unsigned start_ip;
+   unsigned end_ip;
+};
+
+static void
+resolve_jumps(struct eir *ir)
+{
+   void *mem_ctx = ralloc_context(NULL);
+   unsigned ip = 0;
+   assert(mem_ctx);
+
+   eir_for_each_block(block, ir) {
+  struct block_data *bd = rzalloc(mem_ctx, struct block_data);
+
+  assert(bd);
+  assert(!block->data);
+  block->data = bd;
+
+  /* determine start and end IP for this block */
+  bd->start_ip = ip;
+  eir_for_each_inst(i

[Mesa-dev] [RFC PATCH 05/17] eir: implement actual register allocator

2019-05-10 Thread Christian Gmeiner
Some unit tests would be great.

Signed-off-by: Christian Gmeiner 
---
 src/etnaviv/compiler/eir.h   |  10 +-
 src/etnaviv/compiler/eir_register_allocate.c | 176 ++-
 2 files changed, 184 insertions(+), 2 deletions(-)

diff --git a/src/etnaviv/compiler/eir.h b/src/etnaviv/compiler/eir.h
index f2652863de6..bbde10cde08 100644
--- a/src/etnaviv/compiler/eir.h
+++ b/src/etnaviv/compiler/eir.h
@@ -29,6 +29,7 @@
 #define H_EIR
 
 #include 
+#include "compiler/shader_enums.h"
 #include "util/list.h"
 #include "util/u_dynarray.h"
 #include "util/u_math.h"
@@ -40,6 +41,7 @@ extern "C"{
 
 struct eir;
 struct eir_block;
+struct eir_compiler;
 struct eir_ra_reg_set;
 
 struct eir_register
@@ -149,10 +151,13 @@ struct eir
 * and the used components per register */
struct util_dynarray reg_alloc;
 
-   /* keep track of number of allocated uniforms */
+   /* keep track of number of allocated uniforms - pre RA */
struct util_dynarray uniform_alloc;
unsigned uniform_offset;
 
+   /* total used temp register - post RA */
+   unsigned num_temps;
+
/* Live ranges of temp registers */
int *temp_start, *temp_end;
 };
@@ -301,6 +306,9 @@ eir_temp_range_end(const struct eir* ir, unsigned n);
 struct eir_ra_reg_set *
 eir_ra_alloc_reg_set(void *memctx);
 
+bool
+eir_register_allocate(struct eir *ir, gl_shader_stage type, struct 
eir_compiler *compiler);
+
 uint32_t *
 eir_assemble(const struct eir *ir, struct eir_info *info);
 
diff --git a/src/etnaviv/compiler/eir_register_allocate.c 
b/src/etnaviv/compiler/eir_register_allocate.c
index 332d686add9..e02fc37a5ef 100644
--- a/src/etnaviv/compiler/eir_register_allocate.c
+++ b/src/etnaviv/compiler/eir_register_allocate.c
@@ -164,7 +164,7 @@ eir_ra_alloc_reg_set(void *memctx)
   }
}
 
-   unsigned int **q_values = ralloc_array(set, unsigned *, 
EIR_NUM_REG_CLASSES);
+   unsigned int **q_values = ralloc_array(set, unsigned *, 
EIR_NUM_REG_CLASSES);
for (int i = 0; i < EIR_NUM_REG_CLASSES; i++) {
   q_values[i] = rzalloc_array(q_values, unsigned, EIR_NUM_REG_CLASSES);
   for (int j = 0; j < EIR_NUM_REG_CLASSES; j++)
@@ -177,3 +177,177 @@ eir_ra_alloc_reg_set(void *memctx)
 
return set;
 }
+
+static bool
+interferes(const struct eir *ir, int a, int b)
+{
+   return !((eir_temp_range_end(ir, a) <= eir_temp_range_start(ir, b)) ||
+(eir_temp_range_end(ir, b) <= eir_temp_range_start(ir, a)));
+}
+
+static inline void
+reswizzle(struct eir_register *reg, int virt_reg)
+{
+   static const unsigned swizzle[EIR_NUM_REG_TYPES] = {
+  INST_SWIZ(0, 1, 2, 3), /* XYZW */
+  INST_SWIZ(0, 1, 2, 2), /* XYZ */
+  INST_SWIZ(0, 1, 3, 3), /* XYW */
+  INST_SWIZ(0, 2, 3, 3), /* XZW */
+  INST_SWIZ(1, 2, 3, 3), /* YZW */
+  INST_SWIZ(0, 1, 1, 1), /* XY */
+  INST_SWIZ(0, 2, 2, 2), /* XZ */
+  INST_SWIZ(0, 3, 3, 3), /* XW */
+  INST_SWIZ(1, 2, 2, 2), /* YZ */
+  INST_SWIZ(1, 3, 3, 3), /* YW */
+  INST_SWIZ(2, 3, 3, 3), /* ZW */
+  INST_SWIZ(0, 0, 0, 0), /* X */
+  INST_SWIZ(1, 1, 1 ,1), /* Y */
+  INST_SWIZ(2, 2, 2, 2), /* Z */
+  INST_SWIZ(3, 3, 3, 3), /* W */
+   };
+
+   const int type = eir_reg_get_type(virt_reg);
+   reg->swizzle = swizzle[type];
+}
+
+static unsigned inline
+result(struct ra_graph *g, unsigned reg)
+{
+   const int virt_reg = ra_get_node_reg(g, reg);
+
+   return etna_reg_get_base(virt_reg);
+}
+
+static void
+assign(struct eir_register *reg, struct ra_graph *g, unsigned *num_temps)
+{
+   if (reg->type != EIR_REG_TEMP)
+  return;
+
+   const int virt_reg = ra_get_node_reg(g, reg->index);
+
+   /*
+* convert virtual register back to hw register
+* and change swizzle if needed
+*/
+   reg->index = etna_reg_get_base(virt_reg);
+
+   if (eir_reg_get_type(virt_reg) != EIR_REG_CLASS_VEC4)
+  reswizzle(reg, virt_reg);
+
+   *num_temps = MAX2(*num_temps, reg->index + 1);
+}
+
+bool
+eir_register_allocate(struct eir *ir, gl_shader_stage type, struct 
eir_compiler *compiler)
+{
+   int num = util_dynarray_num_elements(>reg_alloc, unsigned);
+
+   if (num == 0)
+  return true;
+
+   int frag_varying_pos = -1;
+
+   if (type == MESA_SHADER_FRAGMENT) {
+  for (unsigned i = 0; i < ir->num_inputs; i++) {
+ if (ir->inputs[i].slot == VARYING_SLOT_POS) {
+frag_varying_pos = i;
+break;
+ }
+  }
+
+  /* allocate one extra register for hardwired t0 register */
+  if (frag_varying_pos == -1) {
+ num++;
+ frag_varying_pos = num - 1;
+  }
+   }
+
+   struct ra_graph *g = ra_alloc_interference_graph(compiler->set->regs, num);
+   unsigned num_temps = 0;
+
+   assert(g);
+   assert(ir->temp_start);
+   assert(ir->temp_end);
+
+   unsigned i = 0;
+   util_dynarray_foreach(>reg_alloc, unsigned, num_components) {
+  switch (*num_components) {
+  case

[Mesa-dev] [RFC PATCH 04/17] eir: add virtual register classes

2019-05-10 Thread Christian Gmeiner
Since all threads share a global temporary vec4 register file, it is
important to reduce temporary register use of shaders.
Using source swizzles and destination write mask of ALU operations we
can layer smaller virtual registers on top of the physical base
registers that overlap with their base register and partially with each
other:

 ++-+-+-+
 |VEC4|  VEC3   |VEC2 | SCALAR  |
 ++-+-+-+
 |  X | X X X   | X X X   | X   |
 |  Y | Y Y   Y | Y Y Y   |   Y |
 |  Z | Z   Z Z |   Z   Z   Z | Z   |
 |  W |   W W W | W   W W |   W |
 ++-+-+-+

There are four possible virtual vec3 registers that leave the remaining
component usable as a scalar virtual register, six possible vec2
registers, and four possible scalar registers that only use a single
component.

Signed-off-by: Philipp Zabel 
Signed-off-by: Michael Tretter 
Signed-off-by: Christian Gmeiner 
---
 src/etnaviv/compiler/eir.h   |   4 +
 src/etnaviv/compiler/eir_compiler.h  |  41 +
 src/etnaviv/compiler/eir_register_allocate.c | 179 +++
 src/etnaviv/compiler/meson.build |   2 +
 4 files changed, 226 insertions(+)
 create mode 100644 src/etnaviv/compiler/eir_compiler.h
 create mode 100644 src/etnaviv/compiler/eir_register_allocate.c

diff --git a/src/etnaviv/compiler/eir.h b/src/etnaviv/compiler/eir.h
index 38c6af4e07e..f2652863de6 100644
--- a/src/etnaviv/compiler/eir.h
+++ b/src/etnaviv/compiler/eir.h
@@ -40,6 +40,7 @@ extern "C"{
 
 struct eir;
 struct eir_block;
+struct eir_ra_reg_set;
 
 struct eir_register
 {
@@ -297,6 +298,9 @@ eir_temp_range_start(const struct eir* ir, unsigned n);
 int
 eir_temp_range_end(const struct eir* ir, unsigned n);
 
+struct eir_ra_reg_set *
+eir_ra_alloc_reg_set(void *memctx);
+
 uint32_t *
 eir_assemble(const struct eir *ir, struct eir_info *info);
 
diff --git a/src/etnaviv/compiler/eir_compiler.h 
b/src/etnaviv/compiler/eir_compiler.h
new file mode 100644
index 000..5c5412e4773
--- /dev/null
+++ b/src/etnaviv/compiler/eir_compiler.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2018 Etnaviv Project
+ * Copyright (C) 2018 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *Christian Gmeiner 
+ */
+
+#ifndef H_EIR_COMPILER
+#define H_EIR_COMPILER
+
+struct eir_ra_reg_set;
+
+/**
+ * Compiler state saved across compiler invocations, for any expensive global
+ * setup.
+ */
+struct eir_compiler {
+   struct eir_ra_reg_set *set;
+};
+
+#endif // H_EIR_COMPILER
diff --git a/src/etnaviv/compiler/eir_register_allocate.c 
b/src/etnaviv/compiler/eir_register_allocate.c
new file mode 100644
index 000..332d686add9
--- /dev/null
+++ b/src/etnaviv/compiler/eir_register_allocate.c
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2018 Etnaviv Project
+ * Copyright (C) 2018 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT

[Mesa-dev] [RFC PATCH 10/17] etnaviv: hook-up eir into gallium driver

2019-05-10 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/Makefile.sources |   2 +
 src/gallium/drivers/etnaviv/etnaviv_eir.c| 454 +++
 src/gallium/drivers/etnaviv/etnaviv_eir.h|  71 +++
 src/gallium/drivers/etnaviv/etnaviv_screen.c |  15 +
 src/gallium/drivers/etnaviv/etnaviv_screen.h |   2 +
 src/gallium/drivers/etnaviv/meson.build  |   8 +-
 6 files changed, 549 insertions(+), 3 deletions(-)
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_eir.c
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_eir.h

diff --git a/src/gallium/drivers/etnaviv/Makefile.sources 
b/src/gallium/drivers/etnaviv/Makefile.sources
index 01e7e49a38a..62e65fb6c5e 100644
--- a/src/gallium/drivers/etnaviv/Makefile.sources
+++ b/src/gallium/drivers/etnaviv/Makefile.sources
@@ -23,6 +23,8 @@ C_SOURCES :=  \
etnaviv_debug.h \
etnaviv_disasm.c \
etnaviv_disasm.h \
+   etnaviv_eir.c \
+   etnaviv_eir.h \
etnaviv_emit.c \
etnaviv_emit.h \
etnaviv_etc2.c \
diff --git a/src/gallium/drivers/etnaviv/etnaviv_eir.c 
b/src/gallium/drivers/etnaviv/etnaviv_eir.c
new file mode 100644
index 000..6914f83f5fc
--- /dev/null
+++ b/src/gallium/drivers/etnaviv/etnaviv_eir.c
@@ -0,0 +1,454 @@
+/*
+ * Copyright (c) 2018 Etnaviv Project
+ * Copyright (C) 2018 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *    Christian Gmeiner 
+ */
+
+#include "etnaviv_eir.h"
+
+#include "etnaviv_context.h"
+#include "etnaviv_debug.h"
+#include "etnaviv_util.h"
+#include "nir/tgsi_to_nir.h"
+#include "tgsi/tgsi_dump.h"
+#include "util/u_debug.h"
+#include "util/u_memory.h"
+#include "etnaviv/compiler/eir_compiler.h"
+#include "etnaviv/compiler/eir_nir.h"
+#include "etnaviv/compiler/eir_shader.h"
+#include "pipe/p_state.h"
+
+static void
+dump_shader_info(struct eir_shader_variant *v, struct pipe_debug_callback 
*debug)
+{
+   if (!unlikely(etna_mesa_debug & ETNA_DBG_SHADERDB))
+  return;
+
+   pipe_debug_message(debug, SHADER_INFO, "\n"
+ "SHADER-DB: %s prog %d/%d: %u instructions %u temps\n"
+ "SHADER-DB: %s prog %d/%d: %u immediates %u consts\n"
+ "SHADER-DB: %s prog %d/%d: %u loops\n",
+ gl_shader_stage_name(v->shader->type),
+ v->shader->id, v->id,
+ v->info.sizedwords,
+ v->num_temps,
+ gl_shader_stage_name(v->shader->type),
+ v->shader->id, v->id,
+ util_dynarray_num_elements(>uniforms, struct eir_uniform_data),
+ v->const_size,
+ gl_shader_stage_name(v->shader->type),
+ v->shader->id, v->id,
+ v->num_loops);
+}
+
+struct eir_shader *
+eir_shader_create(struct eir_compiler *compiler,
+  const struct pipe_shader_state *cso,
+  gl_shader_stage type,
+  struct pipe_debug_callback *debug,
+  struct pipe_screen *screen)
+{
+   struct nir_shader *nir;
+
+   assert(compiler);
+
+   if (cso->type == PIPE_SHADER_IR_NIR) {
+  /* we take ownership of the reference */
+  nir = cso->ir.nir;
+   } else {
+  debug_assert(cso->type == PIPE_SHADER_IR_TGSI);
+
+  if (eir_compiler_debug & EIR_DBG_DISASM)
+ tgsi_dump(cso->tokens, 0);
+
+  nir = eir_tgsi_to_nir(cso->tokens, screen);
+   }
+
+   struct eir_shader *shader = eir_shader_from_nir(compiler, nir);
+
+   if (etna_mesa_debug & ETNA_DBG_SHADERDB) {
+  /* if shader-db run, create a standard variant immediately
+   * (as otherwise nothing will trigger the shader to be
+   * actually compiled)
+   */
+  static struct etna

[Mesa-dev] [PATCH] etnaviv: use the correct uniform dirty bits

2019-05-09 Thread Christian Gmeiner
Found during code inspection.

Cc: mesa-sta...@lists.freedesktop.org
Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_emit.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_emit.c 
b/src/gallium/drivers/etnaviv/etnaviv_emit.c
index ed7b7ee3cb8..ee54daabf3e 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_emit.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_emit.c
@@ -577,12 +577,12 @@ etna_emit_state(struct etna_context *ctx)
static const uint32_t uniform_dirty_bits =
   ETNA_DIRTY_SHADER | ETNA_DIRTY_CONSTBUF;
 
-   if (dirty & (uniform_dirty_bits | ctx->shader.fs->uniforms_dirty_bits))
+   if (dirty & (uniform_dirty_bits | ctx->shader.vs->uniforms_dirty_bits))
   etna_uniforms_write(
  ctx, ctx->shader.vs, >constant_buffer[PIPE_SHADER_VERTEX],
  ctx->shader_state.VS_UNIFORMS, >shader_state.vs_uniforms_size);
 
-   if (dirty & (uniform_dirty_bits | ctx->shader.vs->uniforms_dirty_bits))
+   if (dirty & (uniform_dirty_bits | ctx->shader.fs->uniforms_dirty_bits))
   etna_uniforms_write(
  ctx, ctx->shader.fs, >constant_buffer[PIPE_SHADER_FRAGMENT],
  ctx->shader_state.PS_UNIFORMS, >shader_state.ps_uniforms_size);
-- 
2.21.0

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

Re: [Mesa-dev] [PATCH] etnaviv: fill missing offset in etna_resource_get_handle

2019-05-09 Thread Christian Gmeiner
Am Fr., 3. Mai 2019 um 12:05 Uhr schrieb Philipp Zabel :
>
> Without this gbm_bo_get_offset() can return 0 where it shouldn't.

Reviewed-by: Christian Gmeiner 

> ---
>  src/gallium/drivers/etnaviv/etnaviv_resource.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> index 83179d3cd088..ab77a80c72b3 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> @@ -622,6 +622,7 @@ etna_resource_get_handle(struct pipe_screen *pscreen,
>rsc = etna_resource(rsc->external);
>
> handle->stride = rsc->levels[0].stride;
> +   handle->offset = rsc->levels[0].offset;
> handle->modifier = layout_to_modifier(rsc->layout);
>
> if (handle->type == WINSYS_HANDLE_TYPE_SHARED) {
> --
> 2.20.1
>
> ___
> etnaviv mailing list
> etna...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv



-- 
greets
--
Christian Gmeiner, MSc

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

[Mesa-dev] [PATCH] etnaviv: calculate load balancing value at link time

2019-05-09 Thread Christian Gmeiner
Move the calculation out of the compiler.

Signed-off-by: Christian Gmeiner 
---
 .../drivers/etnaviv/etnaviv_compiler.c| 28 
 .../drivers/etnaviv/etnaviv_compiler.h|  1 -
 src/gallium/drivers/etnaviv/etnaviv_shader.c  | 32 +--
 3 files changed, 30 insertions(+), 31 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler.c 
b/src/gallium/drivers/etnaviv/etnaviv_compiler.c
index ceca5b8af99..4bb4f325b7a 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_compiler.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_compiler.c
@@ -2192,33 +2192,6 @@ fill_in_vs_outputs(struct etna_shader_variant *sobj, 
struct etna_compile *c)
 
/* build two-level index for linking */
build_output_index(sobj);
-
-   /* fill in "mystery meat" load balancing value. This value determines how
-* work is scheduled between VS and PS
-* in the unified shader architecture. More precisely, it is determined from
-* the number of VS outputs, as well as chip-specific
-* vertex output buffer size, vertex cache size, and the number of shader
-* cores.
-*
-* XXX this is a conservative estimate, the "optimal" value is only known 
for
-* sure at link time because some
-* outputs may be unused and thus unmapped. Then again, in the general use
-* case with GLSL the vertex and fragment
-* shaders are linked already before submitting to Gallium, thus all outputs
-* are used.
-*/
-   int half_out = (c->file[TGSI_FILE_OUTPUT].reg_size + 1) / 2;
-   assert(half_out);
-
-   uint32_t b = ((20480 / (c->specs->vertex_output_buffer_size -
-   2 * half_out * c->specs->vertex_cache_size)) +
- 9) /
-10;
-   uint32_t a = (b + 256 / (c->specs->shader_core_count * half_out)) / 2;
-   sobj->vs_load_balancing = VIVS_VS_LOAD_BALANCING_A(MIN2(a, 255)) |
- VIVS_VS_LOAD_BALANCING_B(MIN2(b, 255)) |
- VIVS_VS_LOAD_BALANCING_C(0x3f) |
- VIVS_VS_LOAD_BALANCING_D(0x0f);
 }
 
 static bool
@@ -2513,7 +2486,6 @@ etna_dump_shader(const struct etna_shader_variant *shader)
if (shader->processor == PIPE_SHADER_VERTEX) {
   printf("  vs_pos_out_reg=%i\n", shader->vs_pos_out_reg);
   printf("  vs_pointsize_out_reg=%i\n", shader->vs_pointsize_out_reg);
-  printf("  vs_load_balancing=0x%08x\n", shader->vs_load_balancing);
} else {
   printf("  ps_color_out_reg=%i\n", shader->ps_color_out_reg);
   printf("  ps_depth_out_reg=%i\n", shader->ps_depth_out_reg);
diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler.h 
b/src/gallium/drivers/etnaviv/etnaviv_compiler.h
index 48b1b218750..985d8310850 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_compiler.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_compiler.h
@@ -85,7 +85,6 @@ struct etna_shader_variant {
/* special outputs (vs only) */
int vs_pos_out_reg; /* VS position output */
int vs_pointsize_out_reg; /* VS point size output */
-   uint32_t vs_load_balancing;
 
/* special outputs (ps only) */
int ps_color_out_reg; /* color output register */
diff --git a/src/gallium/drivers/etnaviv/etnaviv_shader.c 
b/src/gallium/drivers/etnaviv/etnaviv_shader.c
index d2d736bdee5..03ba94ff5fa 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_shader.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_shader.c
@@ -53,6 +53,31 @@ static bool etna_icache_upload_shader(struct etna_context 
*ctx, struct etna_shad
return true;
 }
 
+static uint32_t
+etna_calculate_load_balance(const struct etna_specs *specs, unsigned num_regs)
+{
+   /* fill in "mystery meat" load balancing value. This value determines how
+* work is scheduled between VS and PS
+* in the unified shader architecture. More precisely, it is determined from
+* the number of VS outputs, as well as chip-specific
+* vertex output buffer size, vertex cache size, and the number of shader
+* cores.
+*/
+   unsigned half_out = (num_regs + 1) / 2;
+   assert(half_out);
+
+   uint32_t b = ((20480 / (specs->vertex_output_buffer_size -
+   2 * half_out * specs->vertex_cache_size)) +
+ 9) /
+10;
+   uint32_t a = (b + 256 / (specs->shader_core_count * half_out)) / 2;
+
+   return VIVS_VS_LOAD_BALANCING_A(MIN2(a, 255)) |
+  VIVS_VS_LOAD_BALANCING_B(MIN2(b, 255)) |
+  VIVS_VS_LOAD_BALANCING_C(0x3f) |
+  VIVS_VS_LOAD_BALANCING_D(0x0f);
+}
+
 /* Link vs and fs together: fill in shader_state from vs and fs
  * as this function is called every time a new fs or vs is bound, the goal is 
to
  * do little processing as possible here, and to precompute as much as 
possible in
@@ -139,9 +164,12 @@ etna_link_shaders(struct etna_context *ctx, struct 
compiled_shader_state *cs,
   

[Mesa-dev] [MR] etnaviv: add low level ISA library

2019-05-09 Thread Christian Gmeiner
This MR adds a low level ISA library containing APIs for asm, diasm
and meta information. One benefit of moving all this stuff out of the
gallium driver is that it opens the door for vulkan. Unit tests are
included and the current etnaviv disasm gets replaced with the new
one.

https://gitlab.freedesktop.org/mesa/mesa/merge_requests/848
-- 
greets
--
Christian Gmeiner, MSc

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

Re: [Mesa-dev] [PATCH 1/8] etnaviv: create optional 2d pipe in screen

2019-05-02 Thread Christian Gmeiner
Hi Lucas,


Am Fr., 12. Apr. 2019 um 19:38 Uhr schrieb Lucas Stach :
>
> The 2D pipe is useful to implement fast planar and interleaved YUV buffer
> imports. Not all systems have a 2D capable core, so this is strictly
> optional.
>

do you have planed to send out a new version of this patch-set?

-- 
greets
--
Christian Gmeiner, MSc

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

Re: [Mesa-dev] [PATCH 5/8] etnaviv: export etna_submit_rs_state

2019-04-26 Thread Christian Gmeiner
Am Fr., 12. Apr. 2019 um 19:38 Uhr schrieb Lucas Stach :
>
> The new 2D YUV blit needs this in some cases, so make it available.
>
> Signed-off-by: Lucas Stach 

Reviewed-by: Christian Gmeiner 

> ---
>  src/gallium/drivers/etnaviv/etnaviv_rs.c | 2 +-
>  src/gallium/drivers/etnaviv/etnaviv_rs.h | 4 
>  2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_rs.c 
> b/src/gallium/drivers/etnaviv/etnaviv_rs.c
> index a9d3872ad41b..fcc2342aedc3 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_rs.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_rs.c
> @@ -171,7 +171,7 @@ etna_modify_rs_clearbits(struct compiled_rs_state *cs, 
> uint32_t clear_bits)
>
>  /* submit RS state, without any processing and no dependence on context
>   * except TS if this is a source-to-destination blit. */
> -static void
> +void
>  etna_submit_rs_state(struct etna_context *ctx,
>   const struct compiled_rs_state *cs)
>  {
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_rs.h 
> b/src/gallium/drivers/etnaviv/etnaviv_rs.h
> index 125a13a9ad34..81ef05955a79 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_rs.h
> +++ b/src/gallium/drivers/etnaviv/etnaviv_rs.h
> @@ -84,6 +84,10 @@ void
>  etna_compile_rs_state(struct etna_context *ctx, struct compiled_rs_state *cs,
>const struct rs_state *rs);
>
> +void
> +etna_submit_rs_state(struct etna_context *ctx,
> + const struct compiled_rs_state *cs);
> +
>  /* Context initialization for RS clear_blit functions. */
>  void
>  etna_clear_blit_rs_init(struct pipe_context *pctx);
> --
> 2.20.1
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev



-- 
greets
--
Christian Gmeiner, MSc

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

Re: [Mesa-dev] [PATCH 0/6] Add support for NV12

2019-04-26 Thread Christian Gmeiner
Hi Lucas

>
> Am Mittwoch, den 24.04.2019, 08:36 +0200 schrieb Christian Gmeiner:
> > This patch series goes a complete different route then the one from
> > Lucas Stach. I am using the integrated YUV tiler instead of using
> > the 2D core for format conversion. I am reusing some patches from
> > Lucas and this series sits on-top of Lucas "st/dri: YUV" patches.
>
> We specifically opted to use the 2D GPU to do a format conversion, as
> this yields a RGB internal representation, which means the texture has
> the same properties as a normal GL texture (e.g. glReadPixels works).
> This way we can expose YUV format imports as non-external textures.
>

Do you know out of head if rs can handle yuv? If that would be the case
the conversion from yuv -> rgb could also be done this way and you have
the same interal RGB representation. But I have the feeling
YUY2_RENDER_TARGET (aka. RS_FORMAT_YUY2) needs to be supported.

Is glReadPixels(..) and friends really an use-case for YUV textures? To be
honest I am not that deep in that topic.

Maybe you can 1-2 sentences about the reasoning for using the 2D core
somewhere in an commit message?

> This provides a number of benefits in texture lifetime handling in the
> upper layers of the stack, which are used to drive those video use-
> cases, like GStreamer. I don't really care what the blob does, but I do
> care about having the highest performing solution, which is to have the
> 2D GPU work in parallel with the 3D GPU and allow efficient texture
> imports with GStreamer.
>

As the branch point is coming I am okay with this. But I have the feeling
that we need to touch this area in near future for our lovely imx8 based gpus.

Btw. do you have some numbers regarding the speed-up you get by using the
2D core in parallel?

> I would really appreciate a review of my patch series.
>
> Regards,
> Lucas
>
> > Christian Gmeiner (3):
> >   etnaviv: direct YUYV/UYVY support
> >   etnaviv: update headers from rnndb
> >   etnaviv: add multi-planar YUV support
> >
> > Lucas Stach (3):
> >   etnaviv: clear out next pointer when allocating resource
> >   etnaviv: remember data offset into BO
> >   etnaviv: improve PIPE_BIND_LINEAR handling
> >
> >  .../drivers/etnaviv/etnaviv_clear_blit.c  |   2 +-
> >  src/gallium/drivers/etnaviv/etnaviv_format.c  |   5 +-
> >  .../drivers/etnaviv/etnaviv_resource.c|  24 +++-
> >  src/gallium/drivers/etnaviv/etnaviv_rs.c  |   5 +
> >  src/gallium/drivers/etnaviv/etnaviv_screen.c  |   4 +
> >  src/gallium/drivers/etnaviv/etnaviv_texture.c |   8 ++
> >  src/gallium/drivers/etnaviv/etnaviv_yuv.c | 123
> > ++
> >  src/gallium/drivers/etnaviv/etnaviv_yuv.h |  44 +++
> >  src/gallium/drivers/etnaviv/hw/common.xml.h   |   2 +-
> >  .../drivers/etnaviv/hw/common_3d.xml.h|   2 +-
> >  src/gallium/drivers/etnaviv/hw/state.xml.h|   4 +-
> >  src/gallium/drivers/etnaviv/hw/state_3d.xml.h |  35 +++--
> >  .../drivers/etnaviv/hw/state_blt.xml.h|   4 +-
> >  .../drivers/etnaviv/hw/texdesc_3d.xml.h   |   2 +-
> >  src/gallium/drivers/etnaviv/meson.build   |   2 +
> >  15 files changed, 240 insertions(+), 26 deletions(-)
> >  create mode 100644 src/gallium/drivers/etnaviv/etnaviv_yuv.c
> >  create mode 100644 src/gallium/drivers/etnaviv/etnaviv_yuv.h
> >



-- 
greets
--
Christian Gmeiner, MSc

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

Re: [Mesa-dev] [PATCH 6/8] etnaviv: use filter blit for 2D YUV import on old GC320

2019-04-26 Thread Christian Gmeiner
m, 1, 0);
> +  etna_set_state(stream, 1, 0);
> +   } else {
> +  etna_set_state_multi(stream, VIVS_DE_FILTER_KERNEL(0), KERNEL_STATE_SZ,
> +   filter_kernel);
> +
> +  etna_set_state(stream, VIVS_DE_VR_CONFIG,
> + VIVS_DE_VR_CONFIG_START_HORIZONTAL_BLIT);
> +   }
>
> etna_set_state(stream, VIVS_GL_FLUSH_CACHE, VIVS_GL_FLUSH_CACHE_PE2D);
>
> @@ -160,5 +278,49 @@ bool etna_try_2d_blit(struct pipe_context *pctx,
>  */
> etna_cmd_stream_flush(ctx->stream2d);
>
> +   if (temp_bo) {
> +  struct etna_resource *dst = etna_resource(res_dst);
> +  struct compiled_rs_state tile_blit;
> +
> +  etna_compile_rs_state(ctx, _blit, &(struct rs_state) {
> +.source_format = RS_FORMAT_X8R8G8B8,
> +.source_tiling = ETNA_LAYOUT_LINEAR,
> +.source = temp_bo,
> +.source_offset = 0,
> +.source_stride = dst->levels[0].stride,
> +.source_padded_width = dst->levels[0].padded_width,
> +.source_padded_height = dst->levels[0].padded_height,
> +.source_ts_valid = 0,
> +.dest_format = RS_FORMAT_X8R8G8B8,
> +.dest_tiling = ETNA_LAYOUT_TILED,
> +.dest = dst->bo,
> +.dest_offset = 0,
> +.dest_stride = dst->levels[0].stride,
> +.dest_padded_height = dst->levels[0].padded_height,
> +.downsample_x = 0,
> +.downsample_y = 0,
> +.swap_rb = 0,
> +.dither = {0x, 0x},
> +.clear_mode = VIVS_RS_CLEAR_CONTROL_MODE_DISABLED,
> +.width = blit_info->dst.box.width,
> +.height = blit_info->dst.box.height,
> + });
> +
> +  /* The combined color/depth cache flush is required to avoid pixels 
> stuck
> +   * in the caches being flushed to the RS target. This seems to be some 
> bug
> +   * found on at least GC2000, with no other known workaround.
> +   */
> +  etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE,
> + VIVS_GL_FLUSH_CACHE_COLOR | VIVS_GL_FLUSH_CACHE_DEPTH);
> +  etna_stall(ctx->stream, SYNC_RECIPIENT_RA, SYNC_RECIPIENT_PE);
> +  etna_set_state(ctx->stream, VIVS_TS_MEM_CONFIG, 0);
> +  ctx->dirty |= ETNA_DIRTY_TS;
> +  etna_submit_rs_state(ctx, _blit);
> +
> +  /* flush now, so we can get rid of the temp BO right here */
> +  etna_cmd_stream_flush(ctx->stream);
> +  etna_bo_del(temp_bo);
> +   }
> +
> return TRUE;
>  }
> --
> 2.20.1
>
> ___
> etnaviv mailing list
> etna...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv



--
greets
--
Christian Gmeiner, MSc

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

[Mesa-dev] [PATCH 0/6] Add support for NV12

2019-04-24 Thread Christian Gmeiner
This patch series goes a complete different route then the one from
Lucas Stach. I am using the integrated YUV tiler instead of using
the 2D core for format conversion. I am reusing some patches from
Lucas and this series sits on-top of Lucas "st/dri: YUV" patches.

Christian Gmeiner (3):
  etnaviv: direct YUYV/UYVY support
  etnaviv: update headers from rnndb
  etnaviv: add multi-planar YUV support

Lucas Stach (3):
  etnaviv: clear out next pointer when allocating resource
  etnaviv: remember data offset into BO
  etnaviv: improve PIPE_BIND_LINEAR handling

 .../drivers/etnaviv/etnaviv_clear_blit.c  |   2 +-
 src/gallium/drivers/etnaviv/etnaviv_format.c  |   5 +-
 .../drivers/etnaviv/etnaviv_resource.c|  24 +++-
 src/gallium/drivers/etnaviv/etnaviv_rs.c  |   5 +
 src/gallium/drivers/etnaviv/etnaviv_screen.c  |   4 +
 src/gallium/drivers/etnaviv/etnaviv_texture.c |   8 ++
 src/gallium/drivers/etnaviv/etnaviv_yuv.c | 123 ++
 src/gallium/drivers/etnaviv/etnaviv_yuv.h |  44 +++
 src/gallium/drivers/etnaviv/hw/common.xml.h   |   2 +-
 .../drivers/etnaviv/hw/common_3d.xml.h|   2 +-
 src/gallium/drivers/etnaviv/hw/state.xml.h|   4 +-
 src/gallium/drivers/etnaviv/hw/state_3d.xml.h |  35 +++--
 .../drivers/etnaviv/hw/state_blt.xml.h|   4 +-
 .../drivers/etnaviv/hw/texdesc_3d.xml.h   |   2 +-
 src/gallium/drivers/etnaviv/meson.build   |   2 +
 15 files changed, 240 insertions(+), 26 deletions(-)
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_yuv.c
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_yuv.h

-- 
2.20.1

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

[Mesa-dev] [PATCH 4/6] etnaviv: direct YUYV/UYVY support

2019-04-24 Thread Christian Gmeiner
The GPU is able to sample from YUYV/UYVY textures directly.

Passes following piglits:
 - ext_image_dma_buf_import-sample_yuv -fmt=YUYV
 - ext_image_dma_buf_import-sample_yuv -fmt=UYVY

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_format.c   |  2 +-
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 14 +-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_format.c 
b/src/gallium/drivers/etnaviv/etnaviv_format.c
index 29e81c4a8b0..7633274e3c2 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_format.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_format.c
@@ -283,7 +283,7 @@ static struct etna_format formats[PIPE_FORMAT_COUNT] = {
 
/* YUV */
_T(YUYV, YUY2, SWIZ(X, Y, Z, W), YUY2, NONE),
-   _T(UYVY, UYVY, SWIZ(X, Y, Z, W), NONE, NONE),
+   _T(UYVY, UYVY, SWIZ(X, Y, Z, W), YUY2, NONE),
 };
 
 uint32_t
diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index 650c8e7eb7f..c6d3ab6e79d 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -560,6 +560,15 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
   
level->padded_height);
level->size = level->layer_stride;
 
+   rsc->pending_ctx = _mesa_set_create(NULL, _mesa_hash_pointer,
+   _mesa_key_pointer_equal);
+   if (!rsc->pending_ctx)
+  goto fail;
+
+   /* The constraint checks below are invalid for YUV formats. */
+   if (util_format_is_yuv(tmpl->format))
+  return prsc;
+
/* The DDX must give us a BO which conforms to our padding size.
 * The stride of the BO must be greater or equal to our padded
 * stride. The size of the BO must accomodate the padded height. */
@@ -576,11 +585,6 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
   goto fail;
}
 
-   rsc->pending_ctx = _mesa_set_create(NULL, _mesa_hash_pointer,
-   _mesa_key_pointer_equal);
-   if (!rsc->pending_ctx)
-  goto fail;
-
if (rsc->layout == ETNA_LAYOUT_LINEAR) {
   /*
* Both sampler and pixel pipes can't handle linear, create a compatible
-- 
2.20.1

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

[Mesa-dev] [PATCH 2/6] etnaviv: remember data offset into BO

2019-04-24 Thread Christian Gmeiner
From: Lucas Stach 

Imported resources might not start at offset 0 into the buffer object.
Make sure to remember the offset that is provided with the handle on
import.

Signed-off-by: Lucas Stach 
Reviewed-by: Philipp Zabel 
Reviewed-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index 77d027ac806..f405b880a6c 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -535,6 +535,7 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
 
level->width = tmpl->width0;
level->height = tmpl->height0;
+   level->offset = handle->offset;
 
/* Determine padding of the imported resource. */
unsigned paddingX = 0, paddingY = 0;
-- 
2.20.1

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

[Mesa-dev] [PATCH 6/6] etnaviv: add multi-planar YUV support

2019-04-24 Thread Christian Gmeiner
This enables support for NV12, which are really useful when
dealing with hardware video decoders. This patch makes use
of the integrated YUV tiler to convert multi-planar to YUYV.
The binary blob uses the same method to deal with multi-planar
YUV formats. Other formarts will be added in a follow-up patch.

Tested with kmscube (nv12-1img).

Signed-off-by: Christian Gmeiner 
---
 .../drivers/etnaviv/etnaviv_clear_blit.c  |   2 +-
 src/gallium/drivers/etnaviv/etnaviv_format.c  |   3 +
 src/gallium/drivers/etnaviv/etnaviv_rs.c  |   5 +
 src/gallium/drivers/etnaviv/etnaviv_screen.c  |   4 +
 src/gallium/drivers/etnaviv/etnaviv_texture.c |   8 ++
 src/gallium/drivers/etnaviv/etnaviv_yuv.c | 123 ++
 src/gallium/drivers/etnaviv/etnaviv_yuv.h |  44 +++
 src/gallium/drivers/etnaviv/meson.build   |   2 +
 8 files changed, 190 insertions(+), 1 deletion(-)
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_yuv.c
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_yuv.h

diff --git a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c 
b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
index 45c30cbf507..5214162d879 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
@@ -159,7 +159,7 @@ etna_copy_resource(struct pipe_context *pctx, struct 
pipe_resource *dst,
struct etna_resource *src_priv = etna_resource(src);
struct etna_resource *dst_priv = etna_resource(dst);
 
-   assert(src->format == dst->format);
+   assert(src->format == dst->format || util_format_is_yuv(src->format));
assert(src->array_size == dst->array_size);
assert(last_level <= dst->last_level && last_level <= src->last_level);
 
diff --git a/src/gallium/drivers/etnaviv/etnaviv_format.c 
b/src/gallium/drivers/etnaviv/etnaviv_format.c
index 7633274e3c2..3b1174e6521 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_format.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_format.c
@@ -284,6 +284,9 @@ static struct etna_format formats[PIPE_FORMAT_COUNT] = {
/* YUV */
_T(YUYV, YUY2, SWIZ(X, Y, Z, W), YUY2, NONE),
_T(UYVY, UYVY, SWIZ(X, Y, Z, W), YUY2, NONE),
+
+   /* multi-planar YUV */
+   _T(NV12, YUY2, SWIZ(X, Y, Z, W), NONE, NONE),
 };
 
 uint32_t
diff --git a/src/gallium/drivers/etnaviv/etnaviv_rs.c 
b/src/gallium/drivers/etnaviv/etnaviv_rs.c
index a9d3872ad41..6e64586ed0b 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_rs.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_rs.c
@@ -36,6 +36,7 @@
 #include "etnaviv_tiling.h"
 #include "etnaviv_translate.h"
 #include "etnaviv_util.h"
+#include "etnaviv_yuv.h"
 
 #include "pipe/p_defines.h"
 #include "pipe/p_state.h"
@@ -775,6 +776,10 @@ etna_blit_rs(struct pipe_context *pctx, const struct 
pipe_blit_info *blit_info)
   return;
}
 
+   if (etna_format_needs_yuv_tiler(blit_info->src.format) &&
+   etna_try_yuv_blit(pctx, blit_info))
+  return;
+
if (etna_try_rs_blit(pctx, blit_info))
   return;
 
diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c 
b/src/gallium/drivers/etnaviv/etnaviv_screen.c
index 62b6f1c80fa..00fa31f8d33 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c
@@ -37,6 +37,7 @@
 #include "etnaviv_query.h"
 #include "etnaviv_resource.h"
 #include "etnaviv_translate.h"
+#include "etnaviv_yuv.h"
 
 #include "util/hash_table.h"
 #include "util/os_time.h"
@@ -529,6 +530,9 @@ gpu_supports_texure_format(struct etna_screen *screen, 
uint32_t fmt,
   supported = screen->specs.tex_astc;
}
 
+   if (etna_format_needs_yuv_tiler(format))
+  supported = VIV_FEATURE(screen, chipFeatures, YUV420_TILER);
+
if (!supported)
   return false;
 
diff --git a/src/gallium/drivers/etnaviv/etnaviv_texture.c 
b/src/gallium/drivers/etnaviv/etnaviv_texture.c
index c4d53324054..99ca1f53f53 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_texture.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_texture.c
@@ -34,6 +34,7 @@
 #include "etnaviv_format.h"
 #include "etnaviv_texture_state.h"
 #include "etnaviv_translate.h"
+#include "etnaviv_yuv.h"
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
 
@@ -164,6 +165,9 @@ etna_update_sampler_source(struct pipe_sampler_view *view, 
int num)
 static bool
 etna_resource_sampler_compatible(struct etna_resource *res)
 {
+   if (etna_format_needs_yuv_tiler(res->base.format))
+  return false;
+
if (util_format_is_compressed(res->base.format))
   return true;
 
@@ -203,6 +207,10 @@ etna_texture_handle_incompatible(struct pipe_context 
*pctx, struct pipe_resource
 
  templat.bind &= ~(PIPE_BIND_DEPTH_STENCIL | PIPE_BIND_RENDER_TARGET |
PIPE_BIND_BLENDABLE);
+
+

[Mesa-dev] [PATCH 1/6] etnaviv: clear out next pointer when allocating resource

2019-04-24 Thread Christian Gmeiner
From: Lucas Stach 

We copy the template resource content into the newly allocated resource.
If the template derived from a planar resource this leads to a non reference
counted copy of the next resource pointer. Make sure to clear this out when
allocating a new resource.

Signed-off-by: Lucas Stach 
Reviewed-by: Philipp Zabel 
Reviewed-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index 83179d3cd08..77d027ac806 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -274,6 +274,7 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned 
layout,
   return NULL;
 
rsc->base = *templat;
+   rsc->base.next = NULL;
rsc->base.screen = pscreen;
rsc->base.nr_samples = nr_samples;
rsc->layout = layout;
-- 
2.20.1

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

[Mesa-dev] [PATCH 3/6] etnaviv: improve PIPE_BIND_LINEAR handling

2019-04-24 Thread Christian Gmeiner
From: Lucas Stach 

We weren't handling this flag at all, which broke some assumptions
made by the users of the resource_create interface. As we can't render
to a linear surface and the usefulness of yet another layout transition
to handle this case seems limited, we only respect the flag when the
resource isn't used for rendering.

Signed-off-by: Lucas Stach 
Reviewed-by: Philipp Zabel 
Reviewed-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index f405b880a6c..650c8e7eb7f 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -369,6 +369,14 @@ etna_resource_create(struct pipe_screen *pscreen,
if (templat->target == PIPE_TEXTURE_3D)
   layout = ETNA_LAYOUT_LINEAR;
 
+   /* The render pipe can't handle linear and there is no code to do yet 
another
+* layout transformation for this case, so we only respect the linear flag
+* if the resource isn't meant to be rendered.
+*/
+   if ((templat->bind & PIPE_BIND_LINEAR) &&
+   !(templat->bind & PIPE_BIND_RENDER_TARGET))
+  layout = ETNA_LAYOUT_LINEAR;
+
/* modifier is only used for scanout surfaces, so safe to use LINEAR here */
return etna_resource_alloc(pscreen, layout, mode, DRM_FORMAT_MOD_LINEAR, 
templat);
 }
-- 
2.20.1

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

[Mesa-dev] [PATCH 5/6] etnaviv: update headers from rnndb

2019-04-24 Thread Christian Gmeiner
Update to etna_viv commit 1ccc35b.

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/hw/common.xml.h   |  2 +-
 .../drivers/etnaviv/hw/common_3d.xml.h|  2 +-
 src/gallium/drivers/etnaviv/hw/state.xml.h|  4 +--
 src/gallium/drivers/etnaviv/hw/state_3d.xml.h | 35 ---
 .../drivers/etnaviv/hw/state_blt.xml.h|  4 +--
 .../drivers/etnaviv/hw/texdesc_3d.xml.h   |  2 +-
 6 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/hw/common.xml.h 
b/src/gallium/drivers/etnaviv/hw/common.xml.h
index 4af7ec3693a..4416ecc872e 100644
--- a/src/gallium/drivers/etnaviv/hw/common.xml.h
+++ b/src/gallium/drivers/etnaviv/hw/common.xml.h
@@ -11,7 +11,7 @@ The rules-ng-ng source files this header was generated from 
are:
 - texdesc_3d.xml (   3183 bytes, from 2018-02-10 13:09:26)
 - copyright.xml  (   1597 bytes, from 2018-02-10 13:09:26)
 - common.xml (  35468 bytes, from 2018-02-10 13:09:26)
-- common_3d.xml  (  14843 bytes, from 2019-01-18 10:13:41)
+- common_3d.xml  (  14843 bytes, from 2019-04-16 07:18:44)
 
 Copyright (C) 2012-2018 by the following authors:
 - Wladimir J. van der Laan 
diff --git a/src/gallium/drivers/etnaviv/hw/common_3d.xml.h 
b/src/gallium/drivers/etnaviv/hw/common_3d.xml.h
index 46a26df79dc..bf5cfe1cf64 100644
--- a/src/gallium/drivers/etnaviv/hw/common_3d.xml.h
+++ b/src/gallium/drivers/etnaviv/hw/common_3d.xml.h
@@ -11,7 +11,7 @@ The rules-ng-ng source files this header was generated from 
are:
 - texdesc_3d.xml (   3183 bytes, from 2018-02-10 13:09:26)
 - copyright.xml  (   1597 bytes, from 2018-02-10 13:09:26)
 - common.xml (  35468 bytes, from 2018-02-10 13:09:26)
-- common_3d.xml  (  14843 bytes, from 2019-01-18 10:13:41)
+- common_3d.xml  (  14843 bytes, from 2019-04-16 07:18:44)
 
 Copyright (C) 2012-2019 by the following authors:
 - Wladimir J. van der Laan 
diff --git a/src/gallium/drivers/etnaviv/hw/state.xml.h 
b/src/gallium/drivers/etnaviv/hw/state.xml.h
index 5b4b8698283..bb770328cdd 100644
--- a/src/gallium/drivers/etnaviv/hw/state.xml.h
+++ b/src/gallium/drivers/etnaviv/hw/state.xml.h
@@ -10,11 +10,11 @@ git clone git://0x04.net/rules-ng-ng
 The rules-ng-ng source files this header was generated from are:
 - state.xml (  26087 bytes, from 2018-02-10 13:09:26)
 - common.xml(  35468 bytes, from 2018-02-10 13:09:26)
-- common_3d.xml (  14843 bytes, from 2019-01-18 10:13:41)
+- common_3d.xml (  14843 bytes, from 2019-04-16 07:18:44)
 - state_hi.xml  (  30232 bytes, from 2018-03-30 07:48:22)
 - copyright.xml (   1597 bytes, from 2018-02-10 13:09:26)
 - state_2d.xml  (  51552 bytes, from 2018-02-10 13:09:26)
-- state_3d.xml  (  79992 bytes, from 2019-01-18 10:10:57)
+- state_3d.xml  (  80352 bytes, from 2019-04-23 18:58:17)
 - state_blt.xml (  13405 bytes, from 2018-02-10 13:09:26)
 - state_vg.xml  (   5975 bytes, from 2018-02-10 13:09:26)
 
diff --git a/src/gallium/drivers/etnaviv/hw/state_3d.xml.h 
b/src/gallium/drivers/etnaviv/hw/state_3d.xml.h
index dacf252feb0..cbd0fa6c6b0 100644
--- a/src/gallium/drivers/etnaviv/hw/state_3d.xml.h
+++ b/src/gallium/drivers/etnaviv/hw/state_3d.xml.h
@@ -10,11 +10,11 @@ git clone git://0x04.net/rules-ng-ng
 The rules-ng-ng source files this header was generated from are:
 - state.xml (  26087 bytes, from 2018-02-10 13:09:26)
 - common.xml(  35468 bytes, from 2018-02-10 13:09:26)
-- common_3d.xml (  14843 bytes, from 2019-01-18 10:13:41)
+- common_3d.xml (  14843 bytes, from 2019-04-16 07:18:44)
 - state_hi.xml  (  30232 bytes, from 2018-03-30 07:48:22)
 - copyright.xml (   1597 bytes, from 2018-02-10 13:09:26)
 - state_2d.xml  (  51552 bytes, from 2018-02-10 13:09:26)
-- state_3d.xml  (  79992 bytes, from 2019-01-18 10:10:57)
+- state_3d.xml  (  80352 bytes, from 2019-04-23 18:58:17)
 - state_blt.xml (  13405 bytes, from 2018-02-10 13:09:26)
 - state_vg.xml  (   5975 bytes, from 2018-02-10 13:09:26)
 
@@ -1351,25 +1351,36 @@ DEALINGS IN THE SOFTWARE.
 
 #define VIVS_YUV   0x
 
-#define VIVS_YUV_UNK01678  0x1678
+#define VIVS_YUV_CONFIG
0x1678
+#define VIVS_YUV_CONFIG_ENABLE 0x0001
+#define VIVS_YUV_CONFIG_SOURCE_FORMAT__MASK0x0030
+#define VIVS_YUV_CONFIG_SOURCE_FORMAT__SHIFT   4
+#define VIVS_YUV_CONFIG_SOURCE_FORMAT(x)   (((x) << 
VIVS_YUV_CONFIG_SOURCE_FORMAT__SHIFT) & VIVS_YUV_CONFIG_SOURCE_FORMAT__MASK)
+#define VIVS_YUV_CONFIG_UV_SWAP
0x0100
 
-#define VIVS_YUV_UNK0167C  0x167c
+#define VIVS_YUV_WINDOW_SIZE   0x167c
+#define VIVS_YUV_WINDOW_SIZE_HEIGHT__MASK  0x
+#define VIVS_YUV_WINDOW_SIZE_HEIGHT__SHIFT 1

Re: [Mesa-dev] [PATCH 3/8] etnaviv: remember data offset into BO

2019-04-23 Thread Christian Gmeiner
Am Fr., 12. Apr. 2019 um 19:38 Uhr schrieb Lucas Stach :
>
> Imported resources might not start at offset 0 into the buffer object.
> Make sure to remember the offset that is provided with the handle on
> import.
>
> Signed-off-by: Lucas Stach 

Reviewed-by: Christian Gmeiner 

> ---
>  src/gallium/drivers/etnaviv/etnaviv_resource.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> index 77d027ac806b..f405b880a6c0 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> @@ -535,6 +535,7 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
>
> level->width = tmpl->width0;
> level->height = tmpl->height0;
> +   level->offset = handle->offset;
>
> /* Determine padding of the imported resource. */
> unsigned paddingX = 0, paddingY = 0;
> --
> 2.20.1
>
> ___
> etnaviv mailing list
> etna...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv



-- 
greets
--
Christian Gmeiner, MSc

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

Re: [Mesa-dev] [PATCH 7/8] etnaviv: improve PIPE_BIND_LINEAR handling

2019-04-23 Thread Christian Gmeiner
Am Fr., 12. Apr. 2019 um 19:38 Uhr schrieb Lucas Stach :
>
> We weren't handling this flag at all, which broke some assumptions
> made by the users of the resource_create interface. As we can't render
> to a linear surface and the usefulness of yet another layout transition
> to handle this case seems limited, we only respect the flag when the
> resource isn't used for rendering.
>
> Signed-off-by: Lucas Stach 

Reviewed-by: Christian Gmeiner 

> ---
>  src/gallium/drivers/etnaviv/etnaviv_resource.c | 8 
>  1 file changed, 8 insertions(+)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> index f405b880a6c0..650c8e7eb7f5 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> @@ -369,6 +369,14 @@ etna_resource_create(struct pipe_screen *pscreen,
> if (templat->target == PIPE_TEXTURE_3D)
>layout = ETNA_LAYOUT_LINEAR;
>
> +   /* The render pipe can't handle linear and there is no code to do yet 
> another
> +* layout transformation for this case, so we only respect the linear flag
> +* if the resource isn't meant to be rendered.
> +*/
> +   if ((templat->bind & PIPE_BIND_LINEAR) &&
> +   !(templat->bind & PIPE_BIND_RENDER_TARGET))
> +  layout = ETNA_LAYOUT_LINEAR;
> +
> /* modifier is only used for scanout surfaces, so safe to use LINEAR here 
> */
> return etna_resource_alloc(pscreen, layout, mode, DRM_FORMAT_MOD_LINEAR, 
> templat);
>  }
> --
> 2.20.1
>
> _______
> etnaviv mailing list
> etna...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv



-- 
greets
--
Christian Gmeiner, MSc

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

Re: [Mesa-dev] [PATCH 2/8] etnaviv: clear out next pointer when allocating resource

2019-04-19 Thread Christian Gmeiner
Am Fr., 12. Apr. 2019 um 19:38 Uhr schrieb Lucas Stach :
>
> We copy the template resource content into the newly allocated resource.
> If the template derived from a planar resource this leads to a non reference
> counted copy of the next resource pointer. Make sure to clear this out when
> allocating a new resource.
>
> Signed-off-by: Lucas Stach 

Reviewed-by: Christian Gmeiner 

> ---
>  src/gallium/drivers/etnaviv/etnaviv_resource.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> index 83179d3cd088..77d027ac806b 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> @@ -274,6 +274,7 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned 
> layout,
>return NULL;
>
> rsc->base = *templat;
> +   rsc->base.next = NULL;
> rsc->base.screen = pscreen;
> rsc->base.nr_samples = nr_samples;
> rsc->layout = layout;
> --
> 2.20.1
>
> ___
> etnaviv mailing list
> etna...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv



-- 
greets
--
Christian Gmeiner, MSc

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

[Mesa-dev] [PATCH] etnaviv: direct YUYV/UYVY support

2019-04-14 Thread Christian Gmeiner
The GPU is able to sample from YUYV/UYVY textures directly.

Passes following piglits:
 - ext_image_dma_buf_import-sample_yuv -fmt=YUYV
 - ext_image_dma_buf_import-sample_yuv -fmt=UYVY

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_format.c   | 2 +-
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 4 
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_format.c 
b/src/gallium/drivers/etnaviv/etnaviv_format.c
index 29e81c4a8b0..7633274e3c2 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_format.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_format.c
@@ -283,7 +283,7 @@ static struct etna_format formats[PIPE_FORMAT_COUNT] = {
 
/* YUV */
_T(YUYV, YUY2, SWIZ(X, Y, Z, W), YUY2, NONE),
-   _T(UYVY, UYVY, SWIZ(X, Y, Z, W), NONE, NONE),
+   _T(UYVY, UYVY, SWIZ(X, Y, Z, W), YUY2, NONE),
 };
 
 uint32_t
diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index 83179d3cd08..f31464aa85a 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -571,6 +571,10 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
if (!rsc->pending_ctx)
   goto fail;
 
+   /* The constraint checks below are invalid for some supported YUV formats. 
*/
+   if (tmpl->format == PIPE_FORMAT_YUYV || tmpl->format == PIPE_FORMAT_UYVY)
+  return prsc;
+
if (rsc->layout == ETNA_LAYOUT_LINEAR) {
   /*
* Both sampler and pixel pipes can't handle linear, create a compatible
-- 
2.20.1

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

Re: [Mesa-dev] [PATCH 1/2] nir: Add nir_lower_viewport_transform

2019-04-14 Thread Christian Gmeiner
rmed writes, still to gl_Position. The
> + * outputted screen space is still written back to VARYING_SLOT_POS,
> + * which is semantically ambiguous but nevertheless a good match for
> + * Gallium/NIR/Mali.
> + *
> + * Implements coordinate transformation as defined in section 12.5
> + * "Coordinate Transformation" of the OpenGL ES 3.2 full specification.
> + *
> + * This pass must run before lower_vars/lower_io such that derefs are
> + * still in place.
> + */
> +
> +#include "nir/nir.h"
> +#include "nir/nir_builder.h"
> +
> +void
> +nir_lower_viewport_transform(nir_shader *shader)
> +{
> +   assert(shader->info.stage == MESA_SHADER_VERTEX);
> +
> +   nir_foreach_function(func, shader) {
> +  nir_foreach_block(block, func->impl) {
> + nir_foreach_instr_safe(instr, block) {
> +if (instr->type != nir_instr_type_intrinsic)
> +   continue;
> +

All other nir lowering passes are easier to read then this one.
Maybe splitting this big function into multiple smaller ones
to help readability?

static bool
lower_frexp_impl(nir_function_impl *impl)
{
   ...
}

bool
lower_viewport_transform_impl(nir_shader *shader)
{
   bool progress = false;

   nir_foreach_function(function, shader) {
  if (function->impl)
 progress |= lower_viewport_transform_impl(function->impl);
   }

   return progress;
}


> +nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
> +if (intr->intrinsic != nir_intrinsic_store_deref)
> +   continue;
> +
> +nir_variable *var = nir_intrinsic_get_var(intr, 0);
> +if (var->data.location != VARYING_SLOT_POS)
> +   continue;
> +
> +nir_builder b;
> +nir_builder_init(, func->impl);
> +b.cursor = nir_before_instr(instr);
> +
> +/* Grab the source and viewport */
> +nir_ssa_def *input_point = nir_ssa_for_src(, intr->src[1], 4);
> +nir_ssa_def *scale = nir_load_viewport_scale();
> +nir_ssa_def *offset = nir_load_viewport_offset();
> +
> +/* World space to normalised device coordinates to screen space 
> */
> +
> +nir_ssa_def *w_recip = nir_frcp(, nir_channel(, input_point, 
> 3));
> +
> +nir_ssa_def *ndc_point = nir_fmul(,
> +  nir_channels(, input_point, 0x7), w_recip);
> +
> +nir_ssa_def *screen = nir_fadd(,
> +  nir_fmul(, ndc_point, scale), offset);
> +
> +/* gl_Position will be written out in screenspace xyz, with w 
> set to
> + * the reciprocal we computed earlier. The transformed w 
> component is
> + * then used for perspective-correct varying interpolation. The
> + * transformed w component must preserve its original sign; this 
> is
> + * used in depth clipping computations
> + */
> +
> +nir_ssa_def *screen_space = nir_vec4(,
> + nir_channel(, screen, 0),
> + nir_channel(, screen, 1),
> +     nir_channel(, screen, 2),
> + w_recip);
> +
> +nir_instr_rewrite_src(instr, >src[1],
> +  nir_src_for_ssa(screen_space));
> + }
> +  }
> +
> +  nir_metadata_preserve(func->impl, nir_metadata_block_index |
> +nir_metadata_dominance);
> +   }
> +}
> --
> 2.20.1
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev



-- 
greets
--
Christian Gmeiner, MSc

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

Re: [Mesa-dev] [PATCH 2/2] etnaviv: flush all pending contexts when accessing a resource with the CPU

2019-03-27 Thread Christian Gmeiner
Am Mi., 27. März 2019 um 12:23 Uhr schrieb Lucas Stach :
>
> When setting up a transfer to a resource, all contexts where the resource
> is pending must be flushed. Otherwise a write transfer might be started
> in the current context before all contexts that access the resource in
> shared (read) mode have been executed.
>
> Fixes: 64813541d575 (etnaviv: fix resource usage tracking across
> different pipe_context's)
> Signed-off-by: Lucas Stach 

Reviewed-by: Christian Gmeiner 

> ---
>  src/gallium/drivers/etnaviv/etnaviv_transfer.c | 10 --
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_transfer.c 
> b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> index 45cd31207f70..d875803bde26 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> @@ -360,8 +360,14 @@ etna_transfer_map(struct pipe_context *pctx, struct 
> pipe_resource *prsc,
>if ((trans->rsc && (etna_resource(trans->rsc)->status & 
> ETNA_PENDING_WRITE)) ||
>(!trans->rsc &&
> (((usage & PIPE_TRANSFER_READ) && (rsc->status & 
> ETNA_PENDING_WRITE)) ||
> -   ((usage & PIPE_TRANSFER_WRITE) && rsc->status
> - pctx->flush(pctx, NULL, 0);
> +   ((usage & PIPE_TRANSFER_WRITE) && rsc->status {
> + set_foreach(rsc->pending_ctx, entry) {
> +struct etna_context *pend_ctx = (struct etna_context 
> *)entry->key;
> +struct pipe_context *pend_pctx = _ctx->base;
> +
> +pend_pctx->flush(pend_pctx, NULL, 0);
> + }
> +  }
>
>mtx_unlock(>lock);
>
> --
> 2.20.1
>


-- 
greets
--
Christian Gmeiner, MSc

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

Re: [Mesa-dev] [PATCH 1/2] etnaviv: don't flush own context when updating resource use

2019-03-27 Thread Christian Gmeiner
Am Mi., 27. März 2019 um 12:23 Uhr schrieb Lucas Stach :
>
> The context is self synchronizing at the GPU side, as commands are
> executed in order. We must not flush our own context when updating the
> resource use, as that leads to excessive flushing on effectively every
> draw call, causing huge CPU overhead.
>
> Fixes: 64813541d575 (etnaviv: fix resource usage tracking across
> different pipe_context's)
> Signed-off-by: Lucas Stach 

Reviewed-by: Christian Gmeiner 

> ---
>  src/gallium/drivers/etnaviv/etnaviv_resource.c | 11 ++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> index ab40414fbe2c..c7eedab74187 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> @@ -666,9 +666,18 @@ etna_resource_used(struct etna_context *ctx, struct 
> pipe_resource *prsc,
>   struct etna_context *extctx = (struct etna_context *)entry->key;
>   struct pipe_context *pctx = >base;
>
> + if (extctx == ctx)
> +continue;
> +
>   pctx->flush(pctx, NULL, 0);
> + /* It's safe to clear the status here. If we need to flush it means
> +  * either another context had the resource in exclusive (write) use,
> +  * or we transition the resource to exclusive use in our context.
> +  * In both cases the new status accurately reflects the resource use
> +  * after the flush.
> +  */
> + rsc->status = 0;
>    }
> -  rsc->status = 0;
> }
>
> rsc->status |= status;
> --
> 2.20.1
>


-- 
greets
--
Christian Gmeiner, MSc

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

Re: [Mesa-dev] [PATCH] etnaviv: only try to construct scanout resource when on KMS winsys

2019-03-27 Thread Christian Gmeiner
Am Mi., 27. März 2019 um 12:25 Uhr schrieb Lucas Stach :
>
> Trying to construct a scanout capable buffer will only ever work when
> when we are on top of a KMS winsys, as the render node isn't capable
> of allocating contiguous buffers.
>
> Tested-by: Marius Vlad 
> Signed-off-by: Lucas Stach 

Reviewed-by: Christian Gmeiner 

> ---
>  src/gallium/drivers/etnaviv/etnaviv_resource.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> index c7eedab74187..83179d3cd088 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> @@ -238,7 +238,7 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned 
> layout,
> if (!screen->specs.use_blt && templat->target != PIPE_BUFFER)
>etna_adjust_rs_align(screen->specs.pixel_pipes, NULL, );
>
> -   if (templat->bind & PIPE_BIND_SCANOUT) {
> +   if (templat->bind & PIPE_BIND_SCANOUT && screen->ro->kms_fd >= 0) {
>struct pipe_resource scanout_templat = *templat;
>struct renderonly_scanout *scanout;
>struct winsys_handle handle;
> --
> 2.20.1
>
> ___
> etnaviv mailing list
> etna...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv



-- 
greets
--
Christian Gmeiner, MSc

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

[Mesa-dev] [PATCH] etnaviv: shrink struct etna_3d_state

2019-03-27 Thread Christian Gmeiner
Drop struct members which are only written to but never read from.

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_emit.c | 17 -
 src/gallium/drivers/etnaviv/etnaviv_internal.h |  6 --
 2 files changed, 23 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_emit.c 
b/src/gallium/drivers/etnaviv/etnaviv_emit.c
index f788896dd8..ed7b7ee3cb 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_emit.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_emit.c
@@ -250,21 +250,6 @@ etna_emit_state(struct etna_context *ctx)
   etna_set_state(stream, VIVS_TS_FLUSH_CACHE, VIVS_TS_FLUSH_CACHE_FLUSH);
}
 
-   /* If MULTI_SAMPLE_CONFIG.MSAA_SAMPLES changed, clobber affected shader
-* state to make sure it is always rewritten. */
-   if (unlikely(dirty & (ETNA_DIRTY_FRAMEBUFFER))) {
-  if ((ctx->gpu3d.GL_MULTI_SAMPLE_CONFIG & 
VIVS_GL_MULTI_SAMPLE_CONFIG_MSAA_SAMPLES__MASK) !=
-  (ctx->framebuffer.GL_MULTI_SAMPLE_CONFIG & 
VIVS_GL_MULTI_SAMPLE_CONFIG_MSAA_SAMPLES__MASK)) {
- /* XXX what does the GPU set these states to on MSAA samples change?
-  * Does it do the right thing?
-  * (increase/decrease as necessary) or something else? Just set some
-  * invalid value until we know for
-  * sure. */
- ctx->gpu3d.PS_INPUT_COUNT = 0x;
- ctx->gpu3d.PS_TEMP_REGISTER_CONTROL = 0x;
-  }
-   }
-
/* Update vertex elements. This is different from any of the other states, 
in that
 * a) the number of vertex elements written matters: so write only active 
ones
 * b) the vertex element states must all be written: do not skip entries 
that stay the same */
@@ -693,8 +678,6 @@ etna_emit_state(struct etna_context *ctx)
   /* Copy uniforms to gpu3d, so that incremental updates to uniforms are
* possible as long as the
* same shader remains bound */
-  ctx->gpu3d.vs_uniforms_size = ctx->shader_state.vs_uniforms_size;
-  ctx->gpu3d.ps_uniforms_size = ctx->shader_state.ps_uniforms_size;
   memcpy(ctx->gpu3d.VS_UNIFORMS, ctx->shader_state.VS_UNIFORMS,
  ctx->shader_state.vs_uniforms_size * 4);
   memcpy(ctx->gpu3d.PS_UNIFORMS, ctx->shader_state.PS_UNIFORMS,
diff --git a/src/gallium/drivers/etnaviv/etnaviv_internal.h 
b/src/gallium/drivers/etnaviv/etnaviv_internal.h
index 77214d9ccb..29566dbd5e 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_internal.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_internal.h
@@ -270,12 +270,6 @@ struct compiled_shader_state {
 
 /* state of some 3d and common registers relevant to etna driver */
 struct etna_3d_state {
-   unsigned vs_uniforms_size;
-   unsigned ps_uniforms_size;
-
-   uint32_t /*01008*/ PS_INPUT_COUNT;
-   uint32_t /*0100C*/ PS_TEMP_REGISTER_CONTROL;
-   uint32_t /*03818*/ GL_MULTI_SAMPLE_CONFIG;
uint32_t /*05000*/ VS_UNIFORMS[VIVS_VS_UNIFORMS__LEN];
uint32_t /*07000*/ PS_UNIFORMS[VIVS_PS_UNIFORMS__LEN];
 };
-- 
2.20.1

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

Re: [Mesa-dev] [PATCH v5] etnaviv: fix resource usage tracking across different pipe_context's

2019-03-17 Thread Christian Gmeiner
Am Sa., 16. März 2019 um 20:55 Uhr schrieb Marek Vasut :
>
> On 2/22/19 10:30 AM, Boris Brezillon wrote:
> > On Thu, 21 Feb 2019 23:29:53 +0100
> > Boris Brezillon  wrote:
> >
> >> Christian, Marek,
> >>
> >> On Wed, 30 Jan 2019 05:28:14 +0100
> >> Marek Vasut  wrote:
> >>
> >>> From: Christian Gmeiner 
> >>>
> >>> A pipe_resource can be shared by all the pipe_context's hanging off the
> >>> same pipe_screen.
> >>
> >> We seem to be impacted by the problem you're fixing here, but, while
> >> this patch definitely make things much better, the problem does not
> >> seem to be entirely fixed (at least in our case).
> >>
> >> A bit more context: we have Qt App using QtWebEngine to render html
> >> content. When we call QtWebEngine::initialize(), which as for effect
> >> to allow shared GL contexts, we sometimes notice that part of the web
> >> page is mis-rendered. That does not happen when we omit the
> >> QtWebEngine::initialize() call.
> >> As said above, this patch make those rendering issues less likely to
> >> happen, but we still have the problem from time to time. So I thought
> >> I'd share my guesses about what could cause these issues before
> >> debugging it further.
> >>
> >> First thing I noticed: I couldn't reproduce the problem with [1]
> >> applied (+ a tiny change forcing CPU-based tiling no matter the size of
> >> the region to tile/untile). So, my guess is that it's related to how we
> >> handle GPU-based tiling/untiling.
> >> Also noticed that we're testing the rsc->status here [2] without the
> >> screen->lock held, and there might be a race with another thread calling
> >> resource_used(). We might also lack a resource_read(ctx, >base)
> >> here [3]. But even after fixing those problems, the rendering issues
> >> are not gone.
> >
> > I tested again with the following diff applied on top of your patch, and
> > the remaining rendering issues we had seem to be gone (don't know what I
> > messed up in my previous tests :-/).
> >
> > --->8---
> > diff --git a/src/gallium/drivers/etnaviv/etnaviv_rs.c 
> > b/src/gallium/drivers/etnaviv/etnaviv_rs.c
> > index fc4f65dbeee1..b8c8b96a6f72 100644
> > --- a/src/gallium/drivers/etnaviv/etnaviv_rs.c
> > +++ b/src/gallium/drivers/etnaviv/etnaviv_rs.c
> > @@ -729,6 +729,7 @@ etna_try_rs_blit(struct pipe_context *pctx,
> >
> > etna_submit_rs_state(ctx, _to_screen);
> > resource_written(ctx, >base);
> > +   resource_read(ctx, >base);
> > dst->seqno++;
> > dst->levels[blit_info->dst.level].ts_valid = false;
> > ctx->dirty |= ETNA_DIRTY_DERIVE_TS;
> While the V6 of this patch [1] is now in mesa upstream, this hunk is
> missing from the V6 . Any special reason for that or is this just an
> omission ?
>

This and an other change was done in separates commits - see:

https://cgit.freedesktop.org/mesa/mesa/commit/?id=7244e768040859126a5b74023f587beaa8bef81c
https://cgit.freedesktop.org/mesa/mesa/commit/?id=c56e73449698c31fe72b99a95b7e4ecdb2985b73

So everything went in.

-- 
greets
--
Christian Gmeiner, MSc

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

Re: [Mesa-dev] [PATCH 1/4] util: Add a drm_find_modifier helper

2019-03-14 Thread Christian Gmeiner
Am Do., 14. März 2019 um 05:19 Uhr schrieb Alyssa Rosenzweig
:
>
> This function is replicated across vc4/v3d/freedreno and is needed in
> Panfrost; let's make this shared code.
>
> Signed-off-by: Alyssa Rosenzweig 
> ---
>  src/util/u_drm.h | 46 ++
>  1 file changed, 46 insertions(+)
>  create mode 100644 src/util/u_drm.h
>
> diff --git a/src/util/u_drm.h b/src/util/u_drm.h
> new file mode 100644
> index 000..d543c9a7543
> --- /dev/null
> +++ b/src/util/u_drm.h
> @@ -0,0 +1,46 @@
> +/*
> + * Copyright © 2014 Broadcom
> + * Copyright (C) 2012 Rob Clark 
> + *
> + * 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.
> + */
> +
> +#ifndef U_DRM_H
> +#define U_DRM_H
> +
> +#include 
> +
> +/* Given a list of `count` DRM modifiers `haystack` and a desired modifier
> + * `needle`, returns whether the modifier is found */
> +
> +static bool
> +drm_find_modifier(uint64_t needle, const uint64_t *haystack, unsigned count)
> +{

static inline bool
drm_find_modifier(..)

> +unsigned i;
> +
> +for (i = 0; i < count; i++) {
> +if (haystack[i] == needle)
> +return true;
> +}
> +
> +return false;
> +}
> +
> +#endif
> --
> 2.20.1


-- 
greets
--
Christian Gmeiner, MSc

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

Re: [Mesa-dev] [PATCH] gallium/u_transfer_helper: do not call resource_create(..) directly

2019-03-08 Thread Christian Gmeiner
Hi Eric

> > Use u_transfer_helper_resource_create(..) instead which uses the
> > resource_create(..) function specified in u_transfer_vtbl.
>
> I would need to run this through the CTS, as the stacking in
> u_transfer_helper is fragile.  What's fixed for you by this patch?

I am playing around with u_transfer_helper stuff for etnaviv and just run over
it. I need that change for my 'lets try to use u_transfer_helper for
tile resolve blits'
but piglit is not happy about it. So if i ever get it working I will
resend this patch
within a patch series. But good to know that u_transfer_helper is fragile :)

-- 
greets
--
Christian Gmeiner, MSc

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

Re: [Mesa-dev] [PATCH] gallium/u_transfer_helper: do not call resource_create(..) directly

2019-03-07 Thread Christian Gmeiner
Am Fr., 1. März 2019 um 16:54 Uhr schrieb Christian Gmeiner
:
>
> Use u_transfer_helper_resource_create(..) instead which uses the
> resource_create(..) function specified in u_transfer_vtbl.
>
> Signed-off-by: Christian Gmeiner 
> ---
>  src/gallium/auxiliary/util/u_transfer_helper.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/gallium/auxiliary/util/u_transfer_helper.c 
> b/src/gallium/auxiliary/util/u_transfer_helper.c
> index 14c4d56392d..a5c3c026e71 100644
> --- a/src/gallium/auxiliary/util/u_transfer_helper.c
> +++ b/src/gallium/auxiliary/util/u_transfer_helper.c
> @@ -182,7 +182,7 @@ transfer_map_msaa(struct pipe_context *pctx,
>   .depth0 = 1,
>   .array_size = 1,
> };
> -   trans->ss = pscreen->resource_create(pscreen, );
> +   trans->ss = u_transfer_helper_resource_create(pscreen, );
> if (!trans->ss) {
>    free(trans);
>return NULL;
> --
> 2.20.1
>

ping

-- 
greets
--
Christian Gmeiner, MSc

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

[Mesa-dev] [PATCH] gallium/u_transfer_helper: do not call resource_create(..) directly

2019-03-01 Thread Christian Gmeiner
Use u_transfer_helper_resource_create(..) instead which uses the
resource_create(..) function specified in u_transfer_vtbl.

Signed-off-by: Christian Gmeiner 
---
 src/gallium/auxiliary/util/u_transfer_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/util/u_transfer_helper.c 
b/src/gallium/auxiliary/util/u_transfer_helper.c
index 14c4d56392d..a5c3c026e71 100644
--- a/src/gallium/auxiliary/util/u_transfer_helper.c
+++ b/src/gallium/auxiliary/util/u_transfer_helper.c
@@ -182,7 +182,7 @@ transfer_map_msaa(struct pipe_context *pctx,
  .depth0 = 1,
  .array_size = 1,
};
-   trans->ss = pscreen->resource_create(pscreen, );
+   trans->ss = u_transfer_helper_resource_create(pscreen, );
if (!trans->ss) {
   free(trans);
   return NULL;
-- 
2.20.1

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

Re: [Mesa-dev] [PATCH] panfrost: List primitive restart enable bit

2019-02-28 Thread Christian Gmeiner
Am Mi., 27. Feb. 2019 um 17:12 Uhr schrieb Alyssa Rosenzweig
:
>
> > super nitpicking: What is the purpose of this change? Should this
> > define be added when it really gets used?
>
> I mean, we don't have explicit documentation on the cmdstream; if I
> don't add the define / enum / struct / whatever in, it will be forgotten
> to time.

Ok, thanks.

-- 
greets
--
Christian Gmeiner, MSc

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

[Mesa-dev] [PATCH v3 0/4] Add ETC2 block patching for HALTI0

2019-02-27 Thread Christian Gmeiner
HALTI0 GPUs have broken ETC2 support (for RGB and RGBA)
formats. The blob driver does per-block patching. The patching
is quite simple: color swaping.

This patch series adds support for the needed block patching
and enabled ETC2 support for HALTI0.

Passes all tested formats of the following piglit:
 spec/!opengl es 3.0/oes_compressed_etc2_texture-miptree_gles3

Christian Gmeiner (4):
  etnaviv: implement ETC2 block patching for HALTI0
  etnaviv: keep track of mapped bo address
  etnaviv: hook-up etc2 patching
  etnaviv: enable ETC2 texture compression support for HALTI0 GPUs

 src/gallium/drivers/etnaviv/Makefile.sources  |   2 +
 src/gallium/drivers/etnaviv/etnaviv_context.h |   1 +
 src/gallium/drivers/etnaviv/etnaviv_etc2.c| 146 ++
 src/gallium/drivers/etnaviv/etnaviv_etc2.h|  51 ++
 .../drivers/etnaviv/etnaviv_resource.c|   3 +
 .../drivers/etnaviv/etnaviv_resource.h|   5 +
 src/gallium/drivers/etnaviv/etnaviv_screen.c  |  12 +-
 .../drivers/etnaviv/etnaviv_transfer.c|  75 +++--
 src/gallium/drivers/etnaviv/meson.build   |   2 +
 9 files changed, 277 insertions(+), 20 deletions(-)
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.c
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.h

-- 
2.20.1

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

[Mesa-dev] [PATCH v3 3/4] etnaviv: hook-up etc2 patching

2019-02-27 Thread Christian Gmeiner
Changes v1 -> v2:
 - Avoid the GPU sampling from the resource that gets mutated by the the
   transfer map by setting DRM_ETNA_PREP_WRITE.

Changes v2 -> v3:
 - make use of likely(..)
 - drop minor optimization regarding rsc->layout == ETNA_LAYOUT_LINEAR
 - better documentation why DRM_ETNA_PREP_WRITE is needed

Signed-off-by: Christian Gmeiner 
---
 .../drivers/etnaviv/etnaviv_resource.c|  3 +
 .../drivers/etnaviv/etnaviv_resource.h|  5 ++
 .../drivers/etnaviv/etnaviv_transfer.c| 56 +++
 3 files changed, 64 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index db5ead4d0ba..45d5f69169e 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -478,6 +478,9 @@ etna_resource_destroy(struct pipe_screen *pscreen, struct 
pipe_resource *prsc)
pipe_resource_reference(>texture, NULL);
pipe_resource_reference(>external, NULL);
 
+   for (unsigned i = 0; i < ETNA_NUM_LOD; i++)
+  FREE(rsc->levels[i].patch_offsets);
+
FREE(rsc);
 }
 
diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.h 
b/src/gallium/drivers/etnaviv/etnaviv_resource.h
index 75aa80b3d7a..c45ff7586d1 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.h
@@ -33,6 +33,7 @@
 #include "util/list.h"
 
 struct pipe_screen;
+struct util_dynarray;
 
 struct etna_resource_level {
unsigned width, padded_width; /* in pixels */
@@ -47,6 +48,10 @@ struct etna_resource_level {
uint32_t ts_size;
uint32_t clear_value; /* clear value of resource level (mainly for TS) */
bool ts_valid;
+
+   /* keep track if we have done some per block patching */
+   bool patched;
+   struct util_dynarray *patch_offsets;
 };
 
 enum etna_resource_addressing_mode {
diff --git a/src/gallium/drivers/etnaviv/etnaviv_transfer.c 
b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
index 01da393d211..3b925a8ef9f 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_transfer.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
@@ -28,6 +28,7 @@
 #include "etnaviv_clear_blit.h"
 #include "etnaviv_context.h"
 #include "etnaviv_debug.h"
+#include "etnaviv_etc2.h"
 #include "etnaviv_screen.h"
 
 #include "pipe/p_defines.h"
@@ -57,6 +58,46 @@ etna_compute_offset(enum pipe_format format, const struct 
pipe_box *box,
  util_format_get_blocksize(format);
 }
 
+static void etna_patch_data(void *buffer, const struct pipe_transfer *ptrans)
+{
+   struct pipe_resource *prsc = ptrans->resource;
+   struct etna_resource *rsc = etna_resource(prsc);
+   struct etna_resource_level *level = >levels[ptrans->level];
+
+   if (likely(!etna_etc2_needs_patching(prsc)))
+  return;
+
+   if (level->patched)
+  return;
+
+   /* do have the offsets of blocks to patch? */
+   if (!level->patch_offsets) {
+  level->patch_offsets = CALLOC_STRUCT(util_dynarray);
+
+  etna_etc2_calculate_blocks(buffer, ptrans->stride,
+ ptrans->box.width, ptrans->box.height,
+ prsc->format, level->patch_offsets);
+   }
+
+   etna_etc2_patch(buffer, level->patch_offsets);
+
+   level->patched = true;
+}
+
+static void etna_unpatch_data(void *buffer, const struct pipe_transfer *ptrans)
+{
+   struct pipe_resource *prsc = ptrans->resource;
+   struct etna_resource *rsc = etna_resource(prsc);
+   struct etna_resource_level *level = >levels[ptrans->level];
+
+   if (!level->patched)
+  return;
+
+   etna_etc2_patch(buffer, level->patch_offsets);
+
+   level->patched = false;
+}
+
 static void
 etna_transfer_unmap(struct pipe_context *pctx, struct pipe_transfer *ptrans)
 {
@@ -119,6 +160,9 @@ etna_transfer_unmap(struct pipe_context *pctx, struct 
pipe_transfer *ptrans)
   }
}
 
+   /* We need to have the patched data ready for the GPU. */
+   etna_patch_data(trans->mapped, ptrans);
+
/*
 * Transfers without a temporary are only pulled into the CPU domain if they
 * are not mapped unsynchronized. If they are, must push them back into GPU
@@ -321,6 +365,14 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
   if (usage & PIPE_TRANSFER_WRITE)
  prep_flags |= DRM_ETNA_PREP_WRITE;
 
+  /*
+   * The ETC2 patching operates in-place on the resource, so the resource 
will
+   * get written even on read-only transfers. This blocks the GPU to sample
+   * from this resource.
+   */
+  if ((usage & PIPE_TRANSFER_READ) && etna_etc2_needs_patching(prsc))
+ prep_flags |= DRM_ETNA_PREP_WRITE;
+
   if (etna_bo_cpu_prep(rsc->bo, prep_flags))
  goto fail_prep;
}
@@ -340,6 +392,10 @@ etna_transfer_map(struct pipe_con

[Mesa-dev] [PATCH v3 2/4] etnaviv: keep track of mapped bo address

2019-02-27 Thread Christian Gmeiner
Saves us from calling etna_bo_map(..) and saves us from doing the
same offset calcs for map() and unmap() operations.

Signed-off-by: Christian Gmeiner 
Reviewed-by: Lucas Stach 
---
 src/gallium/drivers/etnaviv/etnaviv_context.h |  1 +
 .../drivers/etnaviv/etnaviv_transfer.c| 19 ++-
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.h 
b/src/gallium/drivers/etnaviv/etnaviv_context.h
index 6ad9f3431e1..45b3954c7cb 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.h
@@ -70,6 +70,7 @@ struct etna_transfer {
struct pipe_transfer base;
struct pipe_resource *rsc;
void *staging;
+   void *mapped;
 };
 
 struct etna_vertexbuf_state {
diff --git a/src/gallium/drivers/etnaviv/etnaviv_transfer.c 
b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
index 0b7411b47ef..01da393d211 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_transfer.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
@@ -91,16 +91,15 @@ etna_transfer_unmap(struct pipe_context *pctx, struct 
pipe_transfer *ptrans)
   } else if (trans->staging) {
  /* map buffer object */
  struct etna_resource_level *res_level = >levels[ptrans->level];
- void *mapped = etna_bo_map(rsc->bo) + res_level->offset;
 
  if (rsc->layout == ETNA_LAYOUT_TILED) {
 etna_texture_tile(
-   mapped + ptrans->box.z * res_level->layer_stride,
+   trans->mapped + ptrans->box.z * res_level->layer_stride,
trans->staging, ptrans->box.x, ptrans->box.y,
res_level->stride, ptrans->box.width, ptrans->box.height,
ptrans->stride, util_format_get_blocksize(rsc->base.format));
  } else if (rsc->layout == ETNA_LAYOUT_LINEAR) {
-util_copy_box(mapped, rsc->base.format, res_level->stride,
+util_copy_box(trans->mapped, rsc->base.format, res_level->stride,
   res_level->layer_stride, ptrans->box.x,
   ptrans->box.y, ptrans->box.z, ptrans->box.width,
   ptrans->box.height, ptrans->box.depth,
@@ -327,8 +326,8 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
}
 
/* map buffer object */
-   void *mapped = etna_bo_map(rsc->bo);
-   if (!mapped)
+   trans->mapped = etna_bo_map(rsc->bo);
+   if (!trans->mapped)
   goto fail;
 
*out_transfer = ptrans;
@@ -337,9 +336,11 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
   ptrans->stride = res_level->stride;
   ptrans->layer_stride = res_level->layer_stride;
 
-  return mapped + res_level->offset +
+  trans->mapped += res_level->offset +
  etna_compute_offset(prsc->format, box, res_level->stride,
  res_level->layer_stride);
+
+  return trans->mapped;
} else {
   unsigned divSizeX = util_format_get_blockwidth(format);
   unsigned divSizeY = util_format_get_blockheight(format);
@@ -350,7 +351,7 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
   if (usage & PIPE_TRANSFER_MAP_DIRECTLY)
  goto fail;
 
-  mapped += res_level->offset;
+  trans->mapped += res_level->offset;
   ptrans->stride = align(box->width, divSizeX) * 
util_format_get_blocksize(format); /* row stride in bytes */
   ptrans->layer_stride = align(box->height, divSizeY) * ptrans->stride;
   size_t size = ptrans->layer_stride * box->depth;
@@ -362,7 +363,7 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
   if (usage & PIPE_TRANSFER_READ) {
  if (rsc->layout == ETNA_LAYOUT_TILED) {
 etna_texture_untile(trans->staging,
-mapped + ptrans->box.z * 
res_level->layer_stride,
+trans->mapped + ptrans->box.z * 
res_level->layer_stride,
 ptrans->box.x, ptrans->box.y, 
res_level->stride,
 ptrans->box.width, ptrans->box.height, 
ptrans->stride,
 util_format_get_blocksize(rsc->base.format));
@@ -370,7 +371,7 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
 util_copy_box(trans->staging, rsc->base.format, ptrans->stride,
   ptrans->layer_stride, 0, 0, 0, /* dst x,y,z */
   ptrans->box.width, ptrans->box.height,
-  ptrans->box.depth, mapped, res_level->stride,
+  ptrans->box.depth, trans->mapped, res_level->stride,
   res_l

[Mesa-dev] [PATCH v3 1/4] etnaviv: implement ETC2 block patching for HALTI0

2019-02-27 Thread Christian Gmeiner
ETC2 is supported with HALTI0, however that implementation is buggy
in hardware. The blob driver does per-block patching to work around
this. We need to swap colors for t-mode etc2 blocks.

Changes v2 -> v3:
 - Drop redundant format check

Signed-off-by: Christian Gmeiner 
Acked-by: Lucas Stach 
---
 src/gallium/drivers/etnaviv/Makefile.sources |   2 +
 src/gallium/drivers/etnaviv/etnaviv_etc2.c   | 146 +++
 src/gallium/drivers/etnaviv/etnaviv_etc2.h   |  51 +++
 src/gallium/drivers/etnaviv/meson.build  |   2 +
 4 files changed, 201 insertions(+)
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.c
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.h

diff --git a/src/gallium/drivers/etnaviv/Makefile.sources 
b/src/gallium/drivers/etnaviv/Makefile.sources
index 0b208122999..01e7e49a38a 100644
--- a/src/gallium/drivers/etnaviv/Makefile.sources
+++ b/src/gallium/drivers/etnaviv/Makefile.sources
@@ -25,6 +25,8 @@ C_SOURCES :=  \
etnaviv_disasm.h \
etnaviv_emit.c \
etnaviv_emit.h \
+   etnaviv_etc2.c \
+   etnaviv_etc2.h \
etnaviv_fence.c \
etnaviv_fence.h \
etnaviv_format.c \
diff --git a/src/gallium/drivers/etnaviv/etnaviv_etc2.c 
b/src/gallium/drivers/etnaviv/etnaviv_etc2.c
new file mode 100644
index 000..1bb9be12f1c
--- /dev/null
+++ b/src/gallium/drivers/etnaviv/etnaviv_etc2.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2019 Etnaviv Project
+ * Copyright (C) 2019 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *Christian Gmeiner 
+ */
+
+#include "etnaviv_etc2.h"
+#include "etnaviv_resource.h"
+#include "etnaviv_screen.h"
+#include "hw/common.xml.h"
+#include "util/u_format.h"
+
+bool
+etna_etc2_needs_patching(const struct pipe_resource *prsc)
+{
+   const struct etna_screen *screen = etna_screen(prsc->screen);
+
+   if (!util_format_is_etc(prsc->format))
+  return false;
+
+   if (VIV_FEATURE(screen, chipMinorFeatures2, HALTI1))
+  return false;
+
+   switch (prsc->format) {
+   case PIPE_FORMAT_ETC2_RGB8:
+   case PIPE_FORMAT_ETC2_SRGB8:
+   case PIPE_FORMAT_ETC2_RGB8A1:
+   case PIPE_FORMAT_ETC2_SRGB8A1:
+   case PIPE_FORMAT_ETC2_RGBA8:
+   case PIPE_FORMAT_ETC2_SRGBA8:
+  return true;
+  break;
+
+   default:
+  return false;
+   }
+}
+
+static inline bool
+needs_patching(uint8_t *buffer, bool punchthrough_alpha)
+{
+   /* punchthrough_alpha or etc2 individual mode? */
+   if (!punchthrough_alpha && !(buffer[3] & 0x2))
+ return false;
+
+   /* etc2 t-mode? */
+   static const int lookup[8] = { 0, 1, 2, 3, -4, -3, -2, -1 };
+   const int R_plus_dR = (buffer[0] >> 3) + lookup[buffer[0] & 0x7];
+
+   if (R_plus_dR < 0 || R_plus_dR > 31)
+  return true;
+
+   return false;
+}
+
+void
+etna_etc2_calculate_blocks(uint8_t *buffer, unsigned stride,
+   unsigned width, unsigned height,
+   enum pipe_format format,
+   struct util_dynarray *offsets)
+{
+   const unsigned bw = util_format_get_blockwidth(format);
+   const unsigned bh = util_format_get_blockheight(format);
+   const unsigned bs = util_format_get_blocksize(format);
+   bool punchthrough_alpha = false;
+   unsigned offset = 0;
+   const uint8_t *base = buffer;
+
+   if (format == PIPE_FORMAT_ETC2_RGB8A1 ||
+   format == PIPE_FORMAT_ETC2_SRGB8A1)
+  punchthrough_alpha = true;
+
+   if (format == PIPE_FORMAT_ETC2_RGBA8 ||
+   format == PIPE_FORMAT_ETC2_SRGBA8 ||
+   format == PIPE_FORMAT_ETC2_SRGB8A1)
+  offset = 8;
+
+   for (unsigned y = 0; y < height; y += bh) {
+  uint8_t *src = buffer;
+
+  for (unsigned x = 0; x < width; x += bw) {
+ if (needs_patching(src + offset, p

[Mesa-dev] [PATCH v3 4/4] etnaviv: enable ETC2 texture compression support for HALTI0 GPUs

2019-02-27 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
Reviewed-by: Lucas Stach 
---
 src/gallium/drivers/etnaviv/etnaviv_screen.c | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c 
b/src/gallium/drivers/etnaviv/etnaviv_screen.c
index de822fc85ca..ee32a499fb5 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c
@@ -518,19 +518,9 @@ gpu_supports_texure_format(struct etna_screen *screen, 
uint32_t fmt,
if (util_format_is_srgb(format))
   supported = VIV_FEATURE(screen, chipMinorFeatures1, HALTI0);
 
-   if (fmt & EXT_FORMAT) {
+   if (fmt & EXT_FORMAT)
   supported = VIV_FEATURE(screen, chipMinorFeatures1, HALTI0);
 
-  /* ETC1 is checked above, as it has its own feature bit. ETC2 is
-   * supported with HALTI0, however that implementation is buggy in 
hardware.
-   * The blob driver does per-block patching to work around this. As this
-   * is currently not implemented by etnaviv, enable it for HALTI1 (GC3000)
-   * only.
-   */
-  if (util_format_is_etc(format))
- supported = VIV_FEATURE(screen, chipMinorFeatures2, HALTI1);
-   }
-
if (fmt & ASTC_FORMAT) {
   supported = screen->specs.tex_astc;
}
-- 
2.20.1

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

Re: [Mesa-dev] [PATCH v2 1/4] etnaviv: implement ETC2 block patching for HALTI0

2019-02-27 Thread Christian Gmeiner
Hi Lucas

Am Mi., 27. Feb. 2019 um 10:22 Uhr schrieb Lucas Stach :
>
> Am Dienstag, den 26.02.2019, 19:15 +0100 schrieb Christian Gmeiner:
> > ETC2 is supported with HALTI0, however that implementation is buggy
> > in hardware. The blob driver does per-block patching to work around
> > this. We need to swap colors for t-mode etc2 blocks.
> >
> > > Signed-off-by: Christian Gmeiner 
> > ---
> >  src/gallium/drivers/etnaviv/Makefile.sources |   2 +
> >  src/gallium/drivers/etnaviv/etnaviv_etc2.c   | 149 +++
> >  src/gallium/drivers/etnaviv/etnaviv_etc2.h   |  51 +++
> >  src/gallium/drivers/etnaviv/meson.build  |   2 +
> >  4 files changed, 204 insertions(+)
> >  create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.c
> >  create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.h
> >
> > diff --git a/src/gallium/drivers/etnaviv/Makefile.sources 
> > b/src/gallium/drivers/etnaviv/Makefile.sources
> > index 0b208122999..01e7e49a38a 100644
> > --- a/src/gallium/drivers/etnaviv/Makefile.sources
> > +++ b/src/gallium/drivers/etnaviv/Makefile.sources
> > @@ -25,6 +25,8 @@ C_SOURCES :=  \
> > > etnaviv_disasm.h \
> > > etnaviv_emit.c \
> > > etnaviv_emit.h \
> > > +   etnaviv_etc2.c \
> > > +   etnaviv_etc2.h \
> > > etnaviv_fence.c \
> > > etnaviv_fence.h \
> > > etnaviv_format.c \
> > diff --git a/src/gallium/drivers/etnaviv/etnaviv_etc2.c 
> > b/src/gallium/drivers/etnaviv/etnaviv_etc2.c
> > new file mode 100644
> > index 000..64811c3038d
> > --- /dev/null
> > +++ b/src/gallium/drivers/etnaviv/etnaviv_etc2.c
> > @@ -0,0 +1,149 @@
> > +/*
> > + * Copyright (c) 2019 Etnaviv Project
> > + * Copyright (C) 2019 Zodiac Inflight Innovations
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the 
> > "Software"),
> > + * to deal in the Software without restriction, including without 
> > limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sub 
> > license,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice (including the
> > + * next paragraph) shall be included in all copies or substantial portions
> > + * of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
> > OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
> > + * 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:
> > > + *Christian Gmeiner 
> > + */
> > +
> > +#include "etnaviv_etc2.h"
> > +#include "etnaviv_resource.h"
> > +#include "etnaviv_screen.h"
> > +#include "hw/common.xml.h"
> > +#include "util/u_format.h"
> > +
> > +bool
> > +etna_etc2_needs_patching(const struct pipe_resource *prsc)
> > +{
> > +   const struct etna_screen *screen = etna_screen(prsc->screen);
> > +
> > +   if (!util_format_is_etc(prsc->format))
> > +  return false;
> > +
> > +   if (prsc->format == PIPE_FORMAT_ETC1_RGB8)
> > +  return false;
>
> Isn't this format check redundant with the default case of the switch
> below?
>

As util_format_is_etc(..) fires for etc1 and etc2 I thought to be more
explicit here, but
I am fine to remove it.

-- 
greets
--
Christian Gmeiner, MSc

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

Re: [Mesa-dev] [PATCH v2 3/4] etnaviv: hook-up etc2 patching

2019-02-27 Thread Christian Gmeiner
Hi Lucas

Am Mi., 27. Feb. 2019 um 10:19 Uhr schrieb Lucas Stach :
>
> Am Dienstag, den 26.02.2019, 19:15 +0100 schrieb Christian Gmeiner:
> > Changes v1 -> v2:
> >  - Avoid the GPU sampling from the resource that gets mutated by the the
> >transfer map by setting DRM_ETNA_PREP_WRITE.
> >
> > > Signed-off-by: Christian Gmeiner 
> > ---
> >  .../drivers/etnaviv/etnaviv_resource.c|  3 +
> >  .../drivers/etnaviv/etnaviv_resource.h|  5 ++
> >  .../drivers/etnaviv/etnaviv_transfer.c| 55 +++
> >  3 files changed, 63 insertions(+)
> >
> > diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> > b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> > index db5ead4d0ba..45d5f69169e 100644
> > --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> > +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> > @@ -478,6 +478,9 @@ etna_resource_destroy(struct pipe_screen *pscreen, 
> > struct pipe_resource *prsc)
> > pipe_resource_reference(>texture, NULL);
> > pipe_resource_reference(>external, NULL);
> >
> > +   for (unsigned i = 0; i < ETNA_NUM_LOD; i++)
> > +  FREE(rsc->levels[i].patch_offsets);
> > +
> > FREE(rsc);
> >  }
> >
> > diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.h 
> > b/src/gallium/drivers/etnaviv/etnaviv_resource.h
> > index 75aa80b3d7a..c45ff7586d1 100644
> > --- a/src/gallium/drivers/etnaviv/etnaviv_resource.h
> > +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.h
> > @@ -33,6 +33,7 @@
> >  #include "util/list.h"
> >
> >  struct pipe_screen;
> > +struct util_dynarray;
> >
> >  struct etna_resource_level {
> > unsigned width, padded_width; /* in pixels */
> > @@ -47,6 +48,10 @@ struct etna_resource_level {
> > uint32_t ts_size;
> > uint32_t clear_value; /* clear value of resource level (mainly for TS) 
> > */
> > bool ts_valid;
> > +
> > +   /* keep track if we have done some per block patching */
> > +   bool patched;
> > +   struct util_dynarray *patch_offsets;
> >  };
> >
> >  enum etna_resource_addressing_mode {
> > diff --git a/src/gallium/drivers/etnaviv/etnaviv_transfer.c 
> > b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> > index 01da393d211..9a83c481dce 100644
> > --- a/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> > +++ b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> > @@ -28,6 +28,7 @@
> >  #include "etnaviv_clear_blit.h"
> >  #include "etnaviv_context.h"
> >  #include "etnaviv_debug.h"
> > +#include "etnaviv_etc2.h"
> >  #include "etnaviv_screen.h"
> >
> >  #include "pipe/p_defines.h"
> > @@ -57,6 +58,46 @@ etna_compute_offset(enum pipe_format format, const 
> > struct pipe_box *box,
> >   util_format_get_blocksize(format);
> >  }
> >
> > +static void etna_patch_data(void *buffer, const struct pipe_transfer 
> > *ptrans)
> > +{
> > +   struct pipe_resource *prsc = ptrans->resource;
> > +   struct etna_resource *rsc = etna_resource(prsc);
> > +   struct etna_resource_level *level = >levels[ptrans->level];
> > +
> > +   if (!etna_etc2_needs_patching(prsc))
>
> Maybe likely() here?
>

okay.

> > +  return;
> > +
> > +   if (level->patched)
> > +  return;
> > +
> > +   /* do have the offsets of blocks to patch? */
> > +   if (!level->patch_offsets) {
> > +  level->patch_offsets = CALLOC_STRUCT(util_dynarray);
> > +
> > +  etna_etc2_calculate_blocks(buffer, ptrans->stride,
> > + ptrans->box.width, 
> > ptrans->box.height,
> > + prsc->format, 
> > level->patch_offsets);
> > +   }
> > +
> > +   etna_etc2_patch(buffer, level->patch_offsets);
> > +
> > +   level->patched = true;
> > +}
> > +
> > +static void etna_unpatch_data(void *buffer, const struct pipe_transfer 
> > *ptrans)
> > +{
> > +   struct pipe_resource *prsc = ptrans->resource;
> > +   struct etna_resource *rsc = etna_resource(prsc);
> > +   struct etna_resource_level *level = >levels[ptrans->level];
> > +
> > +   if (!level->patched)
> > +  return;
> > +
> > +   etna_etc2_patch(buffer, level->patch_offsets);
> > +
> > +   level->patched = false;
> > +}
> > +
> >  static void
> >  

Re: [Mesa-dev] [PATCH] panfrost: List primitive restart enable bit

2019-02-27 Thread Christian Gmeiner
Am Mi., 27. Feb. 2019 um 05:48 Uhr schrieb Alyssa Rosenzweig
:
>
> Signed-off-by: Alyssa Rosenzweig 
> ---
>  src/gallium/drivers/panfrost/include/panfrost-job.h | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/src/gallium/drivers/panfrost/include/panfrost-job.h 
> b/src/gallium/drivers/panfrost/include/panfrost-job.h
> index 1d738486617..d719325d07b 100644
> --- a/src/gallium/drivers/panfrost/include/panfrost-job.h
> +++ b/src/gallium/drivers/panfrost/include/panfrost-job.h
> @@ -820,10 +820,12 @@ struct mali_uniform_buffer_meta {
>   */
>
>  /* Applies to unknown_draw */
> +
>  #define MALI_DRAW_INDEXED_UINT8  (0x10)
>  #define MALI_DRAW_INDEXED_UINT16 (0x20)
>  #define MALI_DRAW_INDEXED_UINT32 (0x30)
>  #define MALI_DRAW_VARYING_SIZE   (0x100)
> +#define MALI_DRAW_PRIMITIVE_RESTART_FIXED_INDEX (0x1)
>
>  struct mali_vertex_tiler_prefix {
>  /* This is a dynamic bitfield containing the following things in 
> this order:

super nitpicking: What is the purpose of this change? Should this
define be added when it really gets used?

-- 
greets
--
Christian Gmeiner, MSc

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

[Mesa-dev] [PATCH v2 3/4] etnaviv: hook-up etc2 patching

2019-02-26 Thread Christian Gmeiner
Changes v1 -> v2:
 - Avoid the GPU sampling from the resource that gets mutated by the the
   transfer map by setting DRM_ETNA_PREP_WRITE.

Signed-off-by: Christian Gmeiner 
---
 .../drivers/etnaviv/etnaviv_resource.c|  3 +
 .../drivers/etnaviv/etnaviv_resource.h|  5 ++
 .../drivers/etnaviv/etnaviv_transfer.c| 55 +++
 3 files changed, 63 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index db5ead4d0ba..45d5f69169e 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -478,6 +478,9 @@ etna_resource_destroy(struct pipe_screen *pscreen, struct 
pipe_resource *prsc)
pipe_resource_reference(>texture, NULL);
pipe_resource_reference(>external, NULL);
 
+   for (unsigned i = 0; i < ETNA_NUM_LOD; i++)
+  FREE(rsc->levels[i].patch_offsets);
+
FREE(rsc);
 }
 
diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.h 
b/src/gallium/drivers/etnaviv/etnaviv_resource.h
index 75aa80b3d7a..c45ff7586d1 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.h
@@ -33,6 +33,7 @@
 #include "util/list.h"
 
 struct pipe_screen;
+struct util_dynarray;
 
 struct etna_resource_level {
unsigned width, padded_width; /* in pixels */
@@ -47,6 +48,10 @@ struct etna_resource_level {
uint32_t ts_size;
uint32_t clear_value; /* clear value of resource level (mainly for TS) */
bool ts_valid;
+
+   /* keep track if we have done some per block patching */
+   bool patched;
+   struct util_dynarray *patch_offsets;
 };
 
 enum etna_resource_addressing_mode {
diff --git a/src/gallium/drivers/etnaviv/etnaviv_transfer.c 
b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
index 01da393d211..9a83c481dce 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_transfer.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
@@ -28,6 +28,7 @@
 #include "etnaviv_clear_blit.h"
 #include "etnaviv_context.h"
 #include "etnaviv_debug.h"
+#include "etnaviv_etc2.h"
 #include "etnaviv_screen.h"
 
 #include "pipe/p_defines.h"
@@ -57,6 +58,46 @@ etna_compute_offset(enum pipe_format format, const struct 
pipe_box *box,
  util_format_get_blocksize(format);
 }
 
+static void etna_patch_data(void *buffer, const struct pipe_transfer *ptrans)
+{
+   struct pipe_resource *prsc = ptrans->resource;
+   struct etna_resource *rsc = etna_resource(prsc);
+   struct etna_resource_level *level = >levels[ptrans->level];
+
+   if (!etna_etc2_needs_patching(prsc))
+  return;
+
+   if (level->patched)
+  return;
+
+   /* do have the offsets of blocks to patch? */
+   if (!level->patch_offsets) {
+  level->patch_offsets = CALLOC_STRUCT(util_dynarray);
+
+  etna_etc2_calculate_blocks(buffer, ptrans->stride,
+ ptrans->box.width, ptrans->box.height,
+ prsc->format, level->patch_offsets);
+   }
+
+   etna_etc2_patch(buffer, level->patch_offsets);
+
+   level->patched = true;
+}
+
+static void etna_unpatch_data(void *buffer, const struct pipe_transfer *ptrans)
+{
+   struct pipe_resource *prsc = ptrans->resource;
+   struct etna_resource *rsc = etna_resource(prsc);
+   struct etna_resource_level *level = >levels[ptrans->level];
+
+   if (!level->patched)
+  return;
+
+   etna_etc2_patch(buffer, level->patch_offsets);
+
+   level->patched = false;
+}
+
 static void
 etna_transfer_unmap(struct pipe_context *pctx, struct pipe_transfer *ptrans)
 {
@@ -119,6 +160,10 @@ etna_transfer_unmap(struct pipe_context *pctx, struct 
pipe_transfer *ptrans)
   }
}
 
+   /* We need to have the patched data ready for the GPU. */
+   if (rsc->layout == ETNA_LAYOUT_LINEAR)
+  etna_patch_data(trans->mapped, ptrans);
+
/*
 * Transfers without a temporary are only pulled into the CPU domain if they
 * are not mapped unsynchronized. If they are, must push them back into GPU
@@ -321,6 +366,12 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
   if (usage & PIPE_TRANSFER_WRITE)
  prep_flags |= DRM_ETNA_PREP_WRITE;
 
+  /* avoid the GPU sampling from the resource that gets mutated */
+  if (rsc->layout == ETNA_LAYOUT_LINEAR &&
+  (usage & PIPE_TRANSFER_READ) &&
+  etna_etc2_needs_patching(prsc))
+ prep_flags |= DRM_ETNA_PREP_WRITE;
+
   if (etna_bo_cpu_prep(rsc->bo, prep_flags))
  goto fail_prep;
}
@@ -340,6 +391,10 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
  etna_compute_offset(prsc->format, box, res_level->stride,
  res_level->layer_stride);
 
+  /* We need 

[Mesa-dev] [PATCH v2 1/4] etnaviv: implement ETC2 block patching for HALTI0

2019-02-26 Thread Christian Gmeiner
ETC2 is supported with HALTI0, however that implementation is buggy
in hardware. The blob driver does per-block patching to work around
this. We need to swap colors for t-mode etc2 blocks.

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/Makefile.sources |   2 +
 src/gallium/drivers/etnaviv/etnaviv_etc2.c   | 149 +++
 src/gallium/drivers/etnaviv/etnaviv_etc2.h   |  51 +++
 src/gallium/drivers/etnaviv/meson.build  |   2 +
 4 files changed, 204 insertions(+)
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.c
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.h

diff --git a/src/gallium/drivers/etnaviv/Makefile.sources 
b/src/gallium/drivers/etnaviv/Makefile.sources
index 0b208122999..01e7e49a38a 100644
--- a/src/gallium/drivers/etnaviv/Makefile.sources
+++ b/src/gallium/drivers/etnaviv/Makefile.sources
@@ -25,6 +25,8 @@ C_SOURCES :=  \
etnaviv_disasm.h \
etnaviv_emit.c \
etnaviv_emit.h \
+   etnaviv_etc2.c \
+   etnaviv_etc2.h \
etnaviv_fence.c \
etnaviv_fence.h \
etnaviv_format.c \
diff --git a/src/gallium/drivers/etnaviv/etnaviv_etc2.c 
b/src/gallium/drivers/etnaviv/etnaviv_etc2.c
new file mode 100644
index 000..64811c3038d
--- /dev/null
+++ b/src/gallium/drivers/etnaviv/etnaviv_etc2.c
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2019 Etnaviv Project
+ * Copyright (C) 2019 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *    Christian Gmeiner 
+ */
+
+#include "etnaviv_etc2.h"
+#include "etnaviv_resource.h"
+#include "etnaviv_screen.h"
+#include "hw/common.xml.h"
+#include "util/u_format.h"
+
+bool
+etna_etc2_needs_patching(const struct pipe_resource *prsc)
+{
+   const struct etna_screen *screen = etna_screen(prsc->screen);
+
+   if (!util_format_is_etc(prsc->format))
+  return false;
+
+   if (prsc->format == PIPE_FORMAT_ETC1_RGB8)
+  return false;
+
+   if (VIV_FEATURE(screen, chipMinorFeatures2, HALTI1))
+  return false;
+
+   switch (prsc->format) {
+   case PIPE_FORMAT_ETC2_RGB8:
+   case PIPE_FORMAT_ETC2_SRGB8:
+   case PIPE_FORMAT_ETC2_RGB8A1:
+   case PIPE_FORMAT_ETC2_SRGB8A1:
+   case PIPE_FORMAT_ETC2_RGBA8:
+   case PIPE_FORMAT_ETC2_SRGBA8:
+  return true;
+  break;
+
+   default:
+  return false;
+   }
+}
+
+static inline bool
+needs_patching(uint8_t *buffer, bool punchthrough_alpha)
+{
+   /* punchthrough_alpha or etc2 individual mode? */
+   if (!punchthrough_alpha && !(buffer[3] & 0x2))
+ return false;
+
+   /* etc2 t-mode? */
+   static const int lookup[8] = { 0, 1, 2, 3, -4, -3, -2, -1 };
+   const int R_plus_dR = (buffer[0] >> 3) + lookup[buffer[0] & 0x7];
+
+   if (R_plus_dR < 0 || R_plus_dR > 31)
+  return true;
+
+   return false;
+}
+
+void
+etna_etc2_calculate_blocks(uint8_t *buffer, unsigned stride,
+   unsigned width, unsigned height,
+   enum pipe_format format,
+   struct util_dynarray *offsets)
+{
+   const unsigned bw = util_format_get_blockwidth(format);
+   const unsigned bh = util_format_get_blockheight(format);
+   const unsigned bs = util_format_get_blocksize(format);
+   bool punchthrough_alpha = false;
+   unsigned offset = 0;
+   const uint8_t *base = buffer;
+
+   if (format == PIPE_FORMAT_ETC2_RGB8A1 ||
+   format == PIPE_FORMAT_ETC2_SRGB8A1)
+  punchthrough_alpha = true;
+
+   if (format == PIPE_FORMAT_ETC2_RGBA8 ||
+   format == PIPE_FORMAT_ETC2_SRGBA8 ||
+   format == PIPE_FORMAT_ETC2_SRGB8A1)
+  offset = 8;
+
+   for (unsigned y = 0; y < height; y += bh) {
+  uint8_t *src = buffer;
+
+  for (unsigned x = 0; x < width; x+= bw) {
+ if (needs_patching(src + offset, p

[Mesa-dev] [PATCH v2 0/4] Add ETC2 block patching for HALTI0

2019-02-26 Thread Christian Gmeiner
HALTI0 GPUs have broken ETC2 support (for RGB and RGBA)
formats. The blob driver does per-block patching. The patching
is quite simple: color swaping.

This patch series adds support for the needed block patching
and enabled ETC2 support for HALTI0.

Passes all tested formats of the following piglit:
 spec/!opengl es 3.0/oes_compressed_etc2_texture-miptree_gles3

Christian Gmeiner (4):
  etnaviv: implement ETC2 block patching for HALTI0
  etnaviv: keep track of mapped bo address
  etnaviv: hook-up etc2 patching
  etnaviv: enable ETC2 texture compression support for HALTI0 GPUs

 src/gallium/drivers/etnaviv/Makefile.sources  |   2 +
 src/gallium/drivers/etnaviv/etnaviv_context.h |   1 +
 src/gallium/drivers/etnaviv/etnaviv_etc2.c| 149 ++
 src/gallium/drivers/etnaviv/etnaviv_etc2.h|  51 ++
 .../drivers/etnaviv/etnaviv_resource.c|   3 +
 .../drivers/etnaviv/etnaviv_resource.h|   5 +
 src/gallium/drivers/etnaviv/etnaviv_screen.c  |  12 +-
 .../drivers/etnaviv/etnaviv_transfer.c|  74 +++--
 src/gallium/drivers/etnaviv/meson.build   |   2 +
 9 files changed, 279 insertions(+), 20 deletions(-)
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.c
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.h

-- 
2.20.1

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

[Mesa-dev] [PATCH v2 2/4] etnaviv: keep track of mapped bo address

2019-02-26 Thread Christian Gmeiner
Saves us from calling etna_bo_map(..) and saves us from doing the
same offset calcs for map() and unmap() operations.

Signed-off-by: Christian Gmeiner 
Reviewed-by: Lucas Stach 
---
 src/gallium/drivers/etnaviv/etnaviv_context.h |  1 +
 .../drivers/etnaviv/etnaviv_transfer.c| 19 ++-
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.h 
b/src/gallium/drivers/etnaviv/etnaviv_context.h
index 6ad9f3431e1..45b3954c7cb 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.h
@@ -70,6 +70,7 @@ struct etna_transfer {
struct pipe_transfer base;
struct pipe_resource *rsc;
void *staging;
+   void *mapped;
 };
 
 struct etna_vertexbuf_state {
diff --git a/src/gallium/drivers/etnaviv/etnaviv_transfer.c 
b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
index 0b7411b47ef..01da393d211 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_transfer.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
@@ -91,16 +91,15 @@ etna_transfer_unmap(struct pipe_context *pctx, struct 
pipe_transfer *ptrans)
   } else if (trans->staging) {
  /* map buffer object */
  struct etna_resource_level *res_level = >levels[ptrans->level];
- void *mapped = etna_bo_map(rsc->bo) + res_level->offset;
 
  if (rsc->layout == ETNA_LAYOUT_TILED) {
 etna_texture_tile(
-   mapped + ptrans->box.z * res_level->layer_stride,
+   trans->mapped + ptrans->box.z * res_level->layer_stride,
trans->staging, ptrans->box.x, ptrans->box.y,
res_level->stride, ptrans->box.width, ptrans->box.height,
ptrans->stride, util_format_get_blocksize(rsc->base.format));
  } else if (rsc->layout == ETNA_LAYOUT_LINEAR) {
-util_copy_box(mapped, rsc->base.format, res_level->stride,
+util_copy_box(trans->mapped, rsc->base.format, res_level->stride,
   res_level->layer_stride, ptrans->box.x,
   ptrans->box.y, ptrans->box.z, ptrans->box.width,
   ptrans->box.height, ptrans->box.depth,
@@ -327,8 +326,8 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
}
 
/* map buffer object */
-   void *mapped = etna_bo_map(rsc->bo);
-   if (!mapped)
+   trans->mapped = etna_bo_map(rsc->bo);
+   if (!trans->mapped)
   goto fail;
 
*out_transfer = ptrans;
@@ -337,9 +336,11 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
   ptrans->stride = res_level->stride;
   ptrans->layer_stride = res_level->layer_stride;
 
-  return mapped + res_level->offset +
+  trans->mapped += res_level->offset +
  etna_compute_offset(prsc->format, box, res_level->stride,
  res_level->layer_stride);
+
+  return trans->mapped;
} else {
   unsigned divSizeX = util_format_get_blockwidth(format);
   unsigned divSizeY = util_format_get_blockheight(format);
@@ -350,7 +351,7 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
   if (usage & PIPE_TRANSFER_MAP_DIRECTLY)
  goto fail;
 
-  mapped += res_level->offset;
+  trans->mapped += res_level->offset;
   ptrans->stride = align(box->width, divSizeX) * 
util_format_get_blocksize(format); /* row stride in bytes */
   ptrans->layer_stride = align(box->height, divSizeY) * ptrans->stride;
   size_t size = ptrans->layer_stride * box->depth;
@@ -362,7 +363,7 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
   if (usage & PIPE_TRANSFER_READ) {
  if (rsc->layout == ETNA_LAYOUT_TILED) {
 etna_texture_untile(trans->staging,
-mapped + ptrans->box.z * 
res_level->layer_stride,
+trans->mapped + ptrans->box.z * 
res_level->layer_stride,
 ptrans->box.x, ptrans->box.y, 
res_level->stride,
 ptrans->box.width, ptrans->box.height, 
ptrans->stride,
 util_format_get_blocksize(rsc->base.format));
@@ -370,7 +371,7 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
 util_copy_box(trans->staging, rsc->base.format, ptrans->stride,
   ptrans->layer_stride, 0, 0, 0, /* dst x,y,z */
   ptrans->box.width, ptrans->box.height,
-  ptrans->box.depth, mapped, res_level->stride,
+  ptrans->box.depth, trans->mapped, res_level->stride,
   res_l

[Mesa-dev] [PATCH v2 4/4] etnaviv: enable ETC2 texture compression support for HALTI0 GPUs

2019-02-26 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_screen.c | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c 
b/src/gallium/drivers/etnaviv/etnaviv_screen.c
index de822fc85ca..ee32a499fb5 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c
@@ -518,19 +518,9 @@ gpu_supports_texure_format(struct etna_screen *screen, 
uint32_t fmt,
if (util_format_is_srgb(format))
   supported = VIV_FEATURE(screen, chipMinorFeatures1, HALTI0);
 
-   if (fmt & EXT_FORMAT) {
+   if (fmt & EXT_FORMAT)
   supported = VIV_FEATURE(screen, chipMinorFeatures1, HALTI0);
 
-  /* ETC1 is checked above, as it has its own feature bit. ETC2 is
-   * supported with HALTI0, however that implementation is buggy in 
hardware.
-   * The blob driver does per-block patching to work around this. As this
-   * is currently not implemented by etnaviv, enable it for HALTI1 (GC3000)
-   * only.
-   */
-  if (util_format_is_etc(format))
- supported = VIV_FEATURE(screen, chipMinorFeatures2, HALTI1);
-   }
-
if (fmt & ASTC_FORMAT) {
   supported = screen->specs.tex_astc;
}
-- 
2.20.1

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

[Mesa-dev] [PATCH] st/dri: allow direct UYVY import

2019-02-26 Thread Christian Gmeiner
Push this format to the pipe driver unchanged.

Signed-off-by: Christian Gmeiner 
---
 include/GL/internal/dri_interface.h   | 1 +
 src/gallium/state_trackers/dri/dri2.c | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 6d134e3a40f..83aad4100a4 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1290,6 +1290,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FORMAT_XBGR2101010  0x1010
 #define __DRI_IMAGE_FORMAT_ABGR2101010  0x1011
 #define __DRI_IMAGE_FORMAT_SABGR8   0x1012
+#define __DRI_IMAGE_FORMAT_UYVY 0x1013
 
 #define __DRI_IMAGE_USE_SHARE  0x0001
 #define __DRI_IMAGE_USE_SCANOUT0x0002
diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 668d177c371..acdf19e1f5d 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -110,6 +110,8 @@ static const struct dri2_format_mapping dri2_format_table[] 
= {
 __DRI_IMAGE_COMPONENTS_Y_UV,  PIPE_FORMAT_NV12 },
   { __DRI_IMAGE_FOURCC_YUYV,  __DRI_IMAGE_FORMAT_YUYV,
 __DRI_IMAGE_COMPONENTS_Y_XUXV,PIPE_FORMAT_YUYV },
+  { __DRI_IMAGE_FOURCC_UYVY,  __DRI_IMAGE_FORMAT_UYVY,
+__DRI_IMAGE_COMPONENTS_Y_UXVX,PIPE_FORMAT_UYVY },
 };
 
 static const struct dri2_format_mapping *
-- 
2.20.1

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

[Mesa-dev] [PATCH v6] etnaviv: fix resource usage tracking across different pipe_context's

2019-02-23 Thread Christian Gmeiner
A pipe_resource can be shared by all the pipe_context's hanging off the
same pipe_screen.

Changes from v2 -> v3:
 - add locking with mtx_*() to resource and screen (Marek)
Changes from v3 -> v4:
 - drop rsc->lock, just use screen->lock for the entire serialization (Marek)
 - simplify etna_resource_used() flush condition, which also prevents
   potentially flushing resources twice (Marek)
 - don't remove resouces from screen->used_resources in
   etna_cmd_stream_reset_notify(), they may still be used in other
   contexts and may need flushing there later on (Marek)
Changes from v4 -> v5:
 - Fix coding style issues reported by Guido
Changes from v5 -> v6:
 - Add missing locking in etna_transfer_map(..) (Boris)

Signed-off-by: Christian Gmeiner 
Signed-off-by: Marek Vasut 
Signed-off-by: Boris Brezillon 
Tested-by: Marek Vasut 
---
 src/gallium/drivers/etnaviv/etnaviv_context.c | 26 +-
 src/gallium/drivers/etnaviv/etnaviv_context.h |  3 --
 .../drivers/etnaviv/etnaviv_resource.c| 52 +++
 .../drivers/etnaviv/etnaviv_resource.h|  8 +--
 src/gallium/drivers/etnaviv/etnaviv_screen.c  | 12 +
 src/gallium/drivers/etnaviv/etnaviv_screen.h  |  6 +++
 .../drivers/etnaviv/etnaviv_transfer.c|  5 ++
 7 files changed, 83 insertions(+), 29 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.c 
b/src/gallium/drivers/etnaviv/etnaviv_context.c
index 44b50925a4f..83a703f7cc2 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.c
@@ -36,6 +36,7 @@
 #include "etnaviv_query.h"
 #include "etnaviv_query_hw.h"
 #include "etnaviv_rasterizer.h"
+#include "etnaviv_resource.h"
 #include "etnaviv_screen.h"
 #include "etnaviv_shader.h"
 #include "etnaviv_state.h"
@@ -329,7 +330,8 @@ static void
 etna_cmd_stream_reset_notify(struct etna_cmd_stream *stream, void *priv)
 {
struct etna_context *ctx = priv;
-   struct etna_resource *rsc, *rsc_tmp;
+   struct etna_screen *screen = ctx->screen;
+   struct set_entry *entry;
 
etna_set_state(stream, VIVS_GL_API_MODE, VIVS_GL_API_MODE_OPENGL);
etna_set_state(stream, VIVS_GL_VERTEX_ELEMENT_CONFIG, 0x0001);
@@ -384,16 +386,18 @@ etna_cmd_stream_reset_notify(struct etna_cmd_stream 
*stream, void *priv)
ctx->dirty = ~0L;
ctx->dirty_sampler_views = ~0L;
 
-   /* go through all the used resources and clear their status flag */
-   LIST_FOR_EACH_ENTRY_SAFE(rsc, rsc_tmp, >used_resources, list)
-   {
-  debug_assert(rsc->status != 0);
-  rsc->status = 0;
-  rsc->pending_ctx = NULL;
-  list_delinit(>list);
-   }
+   /*
+* Go through all _resources_ associated with this _screen_, pending
+* in this _context_ and mark them as not pending in this _context_
+* anymore, since they were just flushed.
+*/
+   mtx_lock(>lock);
+   set_foreach(screen->used_resources, entry) {
+  struct etna_resource *rsc = (struct etna_resource *)entry->key;
 
-   assert(LIST_IS_EMPTY(>used_resources));
+  _mesa_set_remove_key(rsc->pending_ctx, ctx);
+   }
+   mtx_unlock(>lock);
 }
 
 static void
@@ -437,8 +441,6 @@ etna_context_create(struct pipe_screen *pscreen, void 
*priv, unsigned flags)
/* need some sane default in case state tracker doesn't set some state: */
ctx->sample_mask = 0x;
 
-   list_inithead(>used_resources);
-
/*  Set sensible defaults for state */
etna_cmd_stream_reset_notify(ctx->stream, ctx);
 
diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.h 
b/src/gallium/drivers/etnaviv/etnaviv_context.h
index 6ad9f3431e1..50a2cdf3d07 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.h
@@ -136,9 +136,6 @@ struct etna_context {
uint32_t prim_hwsupport;
struct primconvert_context *primconvert;
 
-   /* list of resources used by currently-unsubmitted renders */
-   struct list_head used_resources;
-
struct slab_child_pool transfer_pool;
struct blitter_context *blitter;
 
diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index db5ead4d0ba..1e8fa714060 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -33,6 +33,7 @@
 #include "etnaviv_screen.h"
 #include "etnaviv_translate.h"
 
+#include "util/hash_table.h"
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
 
@@ -280,7 +281,6 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned 
layout,
rsc->addressing_mode = mode;
 
pipe_reference_init(>base.reference, 1);
-   list_inithead(>list);
 
size = setup_miptree(rsc, paddingX, paddingY, msaa_xscale, msaa_yscale);
 
@@ -301,6 +301,11 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned 
l

[Mesa-dev] [PATCH] etnaviv: blt: mark used src resource as read from

2019-02-22 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_blt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_blt.c 
b/src/gallium/drivers/etnaviv/etnaviv_blt.c
index 52731a9c770..42190d75d4e 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_blt.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_blt.c
@@ -510,7 +510,9 @@ etna_try_blt_blit(struct pipe_context *pctx,
etna_stall(ctx->stream, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT);
etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE, 0x0c23);
 
+   resource_read(ctx, >base);
resource_written(ctx, >base);
+
dst->seqno++;
dst_lev->ts_valid = false;
 
-- 
2.20.1

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

[Mesa-dev] etnaviv: rs: mark used src resource as read from

2019-02-22 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_rs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_rs.c 
b/src/gallium/drivers/etnaviv/etnaviv_rs.c
index fc4f65dbeee..a9d3872ad41 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_rs.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_rs.c
@@ -728,6 +728,7 @@ etna_try_rs_blit(struct pipe_context *pctx,
});
 
etna_submit_rs_state(ctx, _to_screen);
+   resource_read(ctx, >base);
resource_written(ctx, >base);
dst->seqno++;
dst->levels[blit_info->dst.level].ts_valid = false;
-- 
2.20.1

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

Re: [Mesa-dev] [PATCH v5] etnaviv: fix resource usage tracking across different pipe_context's

2019-02-22 Thread Christian Gmeiner
Hi Boris,

Am Fr., 22. Feb. 2019 um 10:30 Uhr schrieb Boris Brezillon
:
>
> On Thu, 21 Feb 2019 23:29:53 +0100
> Boris Brezillon  wrote:
>
> > Christian, Marek,
> >
> > On Wed, 30 Jan 2019 05:28:14 +0100
> > Marek Vasut  wrote:
> >
> > > From: Christian Gmeiner 
> > >
> > > A pipe_resource can be shared by all the pipe_context's hanging off the
> > > same pipe_screen.
> >
> > We seem to be impacted by the problem you're fixing here, but, while
> > this patch definitely make things much better, the problem does not
> > seem to be entirely fixed (at least in our case).
> >

I also got some (private) reports about problems with QtWebEngine but had no
time yet to look more deeply into the issue.

>
> --->8---
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_rs.c 
> b/src/gallium/drivers/etnaviv/etnaviv_rs.c
> index fc4f65dbeee1..b8c8b96a6f72 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_rs.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_rs.c
> @@ -729,6 +729,7 @@ etna_try_rs_blit(struct pipe_context *pctx,
>
> etna_submit_rs_state(ctx, _to_screen);
> resource_written(ctx, >base);
> +   resource_read(ctx, >base);
> dst->seqno++;
> dst->levels[blit_info->dst.level].ts_valid = false;
> ctx->dirty |= ETNA_DIRTY_DERIVE_TS;
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_transfer.c 
> b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> index a3013e624ead..e4b2ac605e63 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> @@ -356,6 +356,7 @@ etna_transfer_map(struct pipe_context *pctx, struct 
> pipe_resource *prsc,
>  * transfers without a temporary resource.
>  */
> if (trans->rsc || !(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
> +  struct etna_screen *screen = ctx->screen;
>uint32_t prep_flags = 0;
>
>/*
> @@ -364,11 +365,13 @@ etna_transfer_map(struct pipe_context *pctx, struct 
> pipe_resource *prsc,
> * current GPU usage (reads must wait for GPU writes, writes must have
> * exclusive access to the buffer).
> */
> +  mtx_lock(>lock);
>if ((trans->rsc && (etna_resource(trans->rsc)->status & 
> ETNA_PENDING_WRITE)) ||
>(!trans->rsc &&
> (((usage & PIPE_TRANSFER_READ) && (rsc->status & 
> ETNA_PENDING_WRITE)) ||
> ((usage & PIPE_TRANSFER_WRITE) && rsc->status
>   pctx->flush(pctx, NULL, 0);
> +  mtx_unlock(>lock);
>
>if (usage & PIPE_TRANSFER_READ)
>   prep_flags |= DRM_ETNA_PREP_READ;
>

Looks good to me - will prepare a v6 of this patch with your changes
incorporated.

Thanks a lot!

-- 
greets
--
Christian Gmeiner, MSc

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

[Mesa-dev] [PATCH 1/4] etnaviv: implement ETC2 block patching for HALTI0

2019-02-22 Thread Christian Gmeiner
ETC2 is supported with HALTI0, however that implementation is buggy
in hardware. The blob driver does per-block patching to work around
this. We need to swap colors for t-mode etc2 blocks.

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/Makefile.sources |   2 +
 src/gallium/drivers/etnaviv/etnaviv_etc2.c   | 149 +++
 src/gallium/drivers/etnaviv/etnaviv_etc2.h   |  51 +++
 src/gallium/drivers/etnaviv/meson.build  |   2 +
 4 files changed, 204 insertions(+)
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.c
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.h

diff --git a/src/gallium/drivers/etnaviv/Makefile.sources 
b/src/gallium/drivers/etnaviv/Makefile.sources
index 0b208122999..01e7e49a38a 100644
--- a/src/gallium/drivers/etnaviv/Makefile.sources
+++ b/src/gallium/drivers/etnaviv/Makefile.sources
@@ -25,6 +25,8 @@ C_SOURCES :=  \
etnaviv_disasm.h \
etnaviv_emit.c \
etnaviv_emit.h \
+   etnaviv_etc2.c \
+   etnaviv_etc2.h \
etnaviv_fence.c \
etnaviv_fence.h \
etnaviv_format.c \
diff --git a/src/gallium/drivers/etnaviv/etnaviv_etc2.c 
b/src/gallium/drivers/etnaviv/etnaviv_etc2.c
new file mode 100644
index 000..64811c3038d
--- /dev/null
+++ b/src/gallium/drivers/etnaviv/etnaviv_etc2.c
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2019 Etnaviv Project
+ * Copyright (C) 2019 Zodiac Inflight Innovations
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * 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:
+ *    Christian Gmeiner 
+ */
+
+#include "etnaviv_etc2.h"
+#include "etnaviv_resource.h"
+#include "etnaviv_screen.h"
+#include "hw/common.xml.h"
+#include "util/u_format.h"
+
+bool
+etna_etc2_needs_patching(const struct pipe_resource *prsc)
+{
+   const struct etna_screen *screen = etna_screen(prsc->screen);
+
+   if (!util_format_is_etc(prsc->format))
+  return false;
+
+   if (prsc->format == PIPE_FORMAT_ETC1_RGB8)
+  return false;
+
+   if (VIV_FEATURE(screen, chipMinorFeatures2, HALTI1))
+  return false;
+
+   switch (prsc->format) {
+   case PIPE_FORMAT_ETC2_RGB8:
+   case PIPE_FORMAT_ETC2_SRGB8:
+   case PIPE_FORMAT_ETC2_RGB8A1:
+   case PIPE_FORMAT_ETC2_SRGB8A1:
+   case PIPE_FORMAT_ETC2_RGBA8:
+   case PIPE_FORMAT_ETC2_SRGBA8:
+  return true;
+  break;
+
+   default:
+  return false;
+   }
+}
+
+static inline bool
+needs_patching(uint8_t *buffer, bool punchthrough_alpha)
+{
+   /* punchthrough_alpha or etc2 individual mode? */
+   if (!punchthrough_alpha && !(buffer[3] & 0x2))
+ return false;
+
+   /* etc2 t-mode? */
+   static const int lookup[8] = { 0, 1, 2, 3, -4, -3, -2, -1 };
+   const int R_plus_dR = (buffer[0] >> 3) + lookup[buffer[0] & 0x7];
+
+   if (R_plus_dR < 0 || R_plus_dR > 31)
+  return true;
+
+   return false;
+}
+
+void
+etna_etc2_calculate_blocks(uint8_t *buffer, unsigned stride,
+   unsigned width, unsigned height,
+   enum pipe_format format,
+   struct util_dynarray *offsets)
+{
+   const unsigned bw = util_format_get_blockwidth(format);
+   const unsigned bh = util_format_get_blockheight(format);
+   const unsigned bs = util_format_get_blocksize(format);
+   bool punchthrough_alpha = false;
+   unsigned offset = 0;
+   const uint8_t *base = buffer;
+
+   if (format == PIPE_FORMAT_ETC2_RGB8A1 ||
+   format == PIPE_FORMAT_ETC2_SRGB8A1)
+  punchthrough_alpha = true;
+
+   if (format == PIPE_FORMAT_ETC2_RGBA8 ||
+   format == PIPE_FORMAT_ETC2_SRGBA8 ||
+   format == PIPE_FORMAT_ETC2_SRGB8A1)
+  offset = 8;
+
+   for (unsigned y = 0; y < height; y += bh) {
+  uint8_t *src = buffer;
+
+  for (unsigned x = 0; x < width; x+= bw) {
+ if (needs_patching(src + offset, p

[Mesa-dev] [PATCH 0/4] Add ETC2 block patching for HALTI0

2019-02-22 Thread Christian Gmeiner
HALTI0 GPUs have broken ETC2 support (for RGB and RGBA)
formats. The blob driver does per-block patching. The patching
is quite simple: color swaping.

This patch series adds support for the needed block patching
and enabled ETC2 support for HALTI0.

Passes all tested formats of the following piglit:
 spec/!opengl es 3.0/oes_compressed_etc2_texture-miptree_gles3

Christian Gmeiner (4):
  etnaviv: implement ETC2 block patching for HALTI0
  etnaviv: keep track of mapped bo address
  etnaviv: hook-up etc2 patching
  etnaviv: enable ETC2 texture compression support for HALTI0 GPUs

 src/gallium/drivers/etnaviv/Makefile.sources  |   2 +
 src/gallium/drivers/etnaviv/etnaviv_context.h |   1 +
 src/gallium/drivers/etnaviv/etnaviv_etc2.c| 149 ++
 src/gallium/drivers/etnaviv/etnaviv_etc2.h|  51 ++
 .../drivers/etnaviv/etnaviv_resource.c|   3 +
 .../drivers/etnaviv/etnaviv_resource.h|   5 +
 src/gallium/drivers/etnaviv/etnaviv_screen.c  |  12 +-
 .../drivers/etnaviv/etnaviv_transfer.c|  68 ++--
 src/gallium/drivers/etnaviv/meson.build   |   2 +
 9 files changed, 273 insertions(+), 20 deletions(-)
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.c
 create mode 100644 src/gallium/drivers/etnaviv/etnaviv_etc2.h

-- 
2.20.1

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

[Mesa-dev] [PATCH 3/4] etnaviv: hook-up etc2 patching

2019-02-22 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 .../drivers/etnaviv/etnaviv_resource.c|  3 ++
 .../drivers/etnaviv/etnaviv_resource.h|  5 ++
 .../drivers/etnaviv/etnaviv_transfer.c| 49 +++
 3 files changed, 57 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index db5ead4d0ba..45d5f69169e 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -478,6 +478,9 @@ etna_resource_destroy(struct pipe_screen *pscreen, struct 
pipe_resource *prsc)
pipe_resource_reference(>texture, NULL);
pipe_resource_reference(>external, NULL);
 
+   for (unsigned i = 0; i < ETNA_NUM_LOD; i++)
+  FREE(rsc->levels[i].patch_offsets);
+
FREE(rsc);
 }
 
diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.h 
b/src/gallium/drivers/etnaviv/etnaviv_resource.h
index 75aa80b3d7a..c45ff7586d1 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.h
@@ -33,6 +33,7 @@
 #include "util/list.h"
 
 struct pipe_screen;
+struct util_dynarray;
 
 struct etna_resource_level {
unsigned width, padded_width; /* in pixels */
@@ -47,6 +48,10 @@ struct etna_resource_level {
uint32_t ts_size;
uint32_t clear_value; /* clear value of resource level (mainly for TS) */
bool ts_valid;
+
+   /* keep track if we have done some per block patching */
+   bool patched;
+   struct util_dynarray *patch_offsets;
 };
 
 enum etna_resource_addressing_mode {
diff --git a/src/gallium/drivers/etnaviv/etnaviv_transfer.c 
b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
index 01da393d211..119820d52b5 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_transfer.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
@@ -28,6 +28,7 @@
 #include "etnaviv_clear_blit.h"
 #include "etnaviv_context.h"
 #include "etnaviv_debug.h"
+#include "etnaviv_etc2.h"
 #include "etnaviv_screen.h"
 
 #include "pipe/p_defines.h"
@@ -57,6 +58,46 @@ etna_compute_offset(enum pipe_format format, const struct 
pipe_box *box,
  util_format_get_blocksize(format);
 }
 
+static void etna_patch_data(void *buffer, const struct pipe_transfer *ptrans)
+{
+   struct pipe_resource *prsc = ptrans->resource;
+   struct etna_resource *rsc = etna_resource(prsc);
+   struct etna_resource_level *level = >levels[ptrans->level];
+
+   if (!etna_etc2_needs_patching(prsc))
+  return;
+
+   if (level->patched)
+  return;
+
+   /* do have the offsets of blocks to patch? */
+   if (!level->patch_offsets) {
+  level->patch_offsets = CALLOC_STRUCT(util_dynarray);
+
+  etna_etc2_calculate_blocks(buffer, ptrans->stride,
+ ptrans->box.width, ptrans->box.height,
+ prsc->format, level->patch_offsets);
+   }
+
+   etna_etc2_patch(buffer, level->patch_offsets);
+
+   level->patched = true;
+}
+
+static void etna_unpatch_data(void *buffer, const struct pipe_transfer *ptrans)
+{
+   struct pipe_resource *prsc = ptrans->resource;
+   struct etna_resource *rsc = etna_resource(prsc);
+   struct etna_resource_level *level = >levels[ptrans->level];
+
+   if (!level->patched)
+  return;
+
+   etna_etc2_patch(buffer, level->patch_offsets);
+
+   level->patched = false;
+}
+
 static void
 etna_transfer_unmap(struct pipe_context *pctx, struct pipe_transfer *ptrans)
 {
@@ -119,6 +160,10 @@ etna_transfer_unmap(struct pipe_context *pctx, struct 
pipe_transfer *ptrans)
   }
}
 
+   /* We need to have the patched data ready for the GPU. */
+   if (rsc->layout == ETNA_LAYOUT_LINEAR)
+  etna_patch_data(trans->mapped, ptrans);
+
/*
 * Transfers without a temporary are only pulled into the CPU domain if they
 * are not mapped unsynchronized. If they are, must push them back into GPU
@@ -340,6 +385,10 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
  etna_compute_offset(prsc->format, box, res_level->stride,
  res_level->layer_stride);
 
+  /* We need to have the unpatched data ready for the gfx stack. */
+  if (usage & PIPE_TRANSFER_READ)
+ etna_unpatch_data(trans->mapped, ptrans);
+
   return trans->mapped;
} else {
   unsigned divSizeX = util_format_get_blockwidth(format);
-- 
2.20.1

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

[Mesa-dev] [PATCH 4/4] etnaviv: enable ETC2 texture compression support for HALTI0 GPUs

2019-02-22 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_screen.c | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c 
b/src/gallium/drivers/etnaviv/etnaviv_screen.c
index de822fc85ca..ee32a499fb5 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c
@@ -518,19 +518,9 @@ gpu_supports_texure_format(struct etna_screen *screen, 
uint32_t fmt,
if (util_format_is_srgb(format))
   supported = VIV_FEATURE(screen, chipMinorFeatures1, HALTI0);
 
-   if (fmt & EXT_FORMAT) {
+   if (fmt & EXT_FORMAT)
   supported = VIV_FEATURE(screen, chipMinorFeatures1, HALTI0);
 
-  /* ETC1 is checked above, as it has its own feature bit. ETC2 is
-   * supported with HALTI0, however that implementation is buggy in 
hardware.
-   * The blob driver does per-block patching to work around this. As this
-   * is currently not implemented by etnaviv, enable it for HALTI1 (GC3000)
-   * only.
-   */
-  if (util_format_is_etc(format))
- supported = VIV_FEATURE(screen, chipMinorFeatures2, HALTI1);
-   }
-
if (fmt & ASTC_FORMAT) {
   supported = screen->specs.tex_astc;
}
-- 
2.20.1

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

[Mesa-dev] [PATCH 2/4] etnaviv: keep track of mapped bo address

2019-02-22 Thread Christian Gmeiner
Saves us from calling etna_bo_map(..) and saves us from doing the
same offset calcs for map() and unmap() operations.

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_context.h |  1 +
 .../drivers/etnaviv/etnaviv_transfer.c| 19 ++-
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.h 
b/src/gallium/drivers/etnaviv/etnaviv_context.h
index 6ad9f3431e1..45b3954c7cb 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.h
@@ -70,6 +70,7 @@ struct etna_transfer {
struct pipe_transfer base;
struct pipe_resource *rsc;
void *staging;
+   void *mapped;
 };
 
 struct etna_vertexbuf_state {
diff --git a/src/gallium/drivers/etnaviv/etnaviv_transfer.c 
b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
index 0b7411b47ef..01da393d211 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_transfer.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
@@ -91,16 +91,15 @@ etna_transfer_unmap(struct pipe_context *pctx, struct 
pipe_transfer *ptrans)
   } else if (trans->staging) {
  /* map buffer object */
  struct etna_resource_level *res_level = >levels[ptrans->level];
- void *mapped = etna_bo_map(rsc->bo) + res_level->offset;
 
  if (rsc->layout == ETNA_LAYOUT_TILED) {
 etna_texture_tile(
-   mapped + ptrans->box.z * res_level->layer_stride,
+   trans->mapped + ptrans->box.z * res_level->layer_stride,
trans->staging, ptrans->box.x, ptrans->box.y,
res_level->stride, ptrans->box.width, ptrans->box.height,
ptrans->stride, util_format_get_blocksize(rsc->base.format));
  } else if (rsc->layout == ETNA_LAYOUT_LINEAR) {
-util_copy_box(mapped, rsc->base.format, res_level->stride,
+util_copy_box(trans->mapped, rsc->base.format, res_level->stride,
   res_level->layer_stride, ptrans->box.x,
   ptrans->box.y, ptrans->box.z, ptrans->box.width,
   ptrans->box.height, ptrans->box.depth,
@@ -327,8 +326,8 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
}
 
/* map buffer object */
-   void *mapped = etna_bo_map(rsc->bo);
-   if (!mapped)
+   trans->mapped = etna_bo_map(rsc->bo);
+   if (!trans->mapped)
   goto fail;
 
*out_transfer = ptrans;
@@ -337,9 +336,11 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
   ptrans->stride = res_level->stride;
   ptrans->layer_stride = res_level->layer_stride;
 
-  return mapped + res_level->offset +
+  trans->mapped += res_level->offset +
  etna_compute_offset(prsc->format, box, res_level->stride,
  res_level->layer_stride);
+
+  return trans->mapped;
} else {
   unsigned divSizeX = util_format_get_blockwidth(format);
   unsigned divSizeY = util_format_get_blockheight(format);
@@ -350,7 +351,7 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
   if (usage & PIPE_TRANSFER_MAP_DIRECTLY)
  goto fail;
 
-  mapped += res_level->offset;
+  trans->mapped += res_level->offset;
   ptrans->stride = align(box->width, divSizeX) * 
util_format_get_blocksize(format); /* row stride in bytes */
   ptrans->layer_stride = align(box->height, divSizeY) * ptrans->stride;
   size_t size = ptrans->layer_stride * box->depth;
@@ -362,7 +363,7 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
   if (usage & PIPE_TRANSFER_READ) {
  if (rsc->layout == ETNA_LAYOUT_TILED) {
 etna_texture_untile(trans->staging,
-mapped + ptrans->box.z * 
res_level->layer_stride,
+trans->mapped + ptrans->box.z * 
res_level->layer_stride,
 ptrans->box.x, ptrans->box.y, 
res_level->stride,
 ptrans->box.width, ptrans->box.height, 
ptrans->stride,
 util_format_get_blocksize(rsc->base.format));
@@ -370,7 +371,7 @@ etna_transfer_map(struct pipe_context *pctx, struct 
pipe_resource *prsc,
 util_copy_box(trans->staging, rsc->base.format, ptrans->stride,
   ptrans->layer_stride, 0, 0, 0, /* dst x,y,z */
   ptrans->box.width, ptrans->box.height,
-  ptrans->box.depth, mapped, res_level->stride,
+  ptrans->box.depth, trans->mapped, res_level->stride,
   res_level->layer_stride, ptrans->box.x,
   ptrans->box.y, ptrans->box.z);
  } else {
-- 
2.20.1

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

Re: [Mesa-dev] [PATCH 4/4] etnaviv: hook up linear texture sampling support

2019-01-28 Thread Christian Gmeiner
Hi Lucas,

Am Fr., 25. Jan. 2019 um 17:02 Uhr schrieb Lucas Stach :
>
> Hi Christian,
>
> Am Montag, den 21.01.2019, 07:50 +0100 schrieb Christian Gmeiner:
> > If the GPU supports linear sampling, linear addressing mode
> > will be used as default.
> >
> > > Signed-off-by: Christian Gmeiner 
> > ---
> >  src/gallium/drivers/etnaviv/etnaviv_resource.c | 10 +++---
> >  src/gallium/drivers/etnaviv/etnaviv_texture.c  |  4 +++-
> >  2 files changed, 10 insertions(+), 4 deletions(-)
> >
> > diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> > b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> > index 9a7ebf3064e..7d24b1f03bd 100644
> > --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> > +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> > @@ -318,9 +318,9 @@ etna_resource_create(struct pipe_screen *pscreen,
> >  {
> > struct etna_screen *screen = etna_screen(pscreen);
> >
> > -   /* Figure out what tiling and address mode to use -- for now, assume 
> > that
> > -* texture cannot be linear. there is a capability 
> > LINEAR_TEXTURE_SUPPORT
> > -* (supported on gc880 and gc2000 at least), but not sure how it works.
> > +   /* Figure out what tiling and address mode to use.
> > +* Textures are TILED or LINEAR. If LINEAR_TEXTURE_SUPPORT capability is
> > +* available LINEAR gets prefered.
> >  * Buffers always have LINEAR layout.
> >  */
> > unsigned layout = ETNA_LAYOUT_LINEAR;
> > @@ -334,6 +334,10 @@ etna_resource_create(struct pipe_screen *pscreen,
> >
> >if (util_format_is_compressed(templat->format))
> >   layout = ETNA_LAYOUT_LINEAR;
> > +  else if (VIV_FEATURE(screen, chipMinorFeatures1, 
> > LINEAR_TEXTURE_SUPPORT)) {
> > + layout = ETNA_LAYOUT_LINEAR;
> > + mode = ETNA_ADDRESSING_MODE_LINEAR;
> > +  }
> > } else if (templat->target != PIPE_BUFFER) {
> >bool want_multitiled = false;
> >bool want_supertiled = screen->specs.can_supertile;
> > diff --git a/src/gallium/drivers/etnaviv/etnaviv_texture.c 
> > b/src/gallium/drivers/etnaviv/etnaviv_texture.c
> > index 3993e31cec1..b06f20531fd 100644
> > --- a/src/gallium/drivers/etnaviv/etnaviv_texture.c
> > +++ b/src/gallium/drivers/etnaviv/etnaviv_texture.c
> > @@ -172,7 +172,9 @@ etna_resource_sampler_compatible(struct etna_resource 
> > *res)
> > if (res->layout == ETNA_LAYOUT_SUPER_TILED && VIV_FEATURE(screen, 
> > chipMinorFeatures2, SUPERTILED_TEXTURE))
> >return true;
> >
> > -   /* TODO: LINEAR_TEXTURE_SUPPORT */
> > +   /* This GPU supports texturing from linear textures? */
> > +   if (res->layout == ETNA_LAYOUT_LINEAR && VIV_FEATURE(screen, 
> > chipMinorFeatures1, LINEAR_TEXTURE_SUPPORT))
> > +  return true;
>
> In order to avoid this sitting on the ML for too long while mostly
> looking good: how would you feel about squashing this last hunk into
> the previous patch and dropping the other parts of this patch for now?
>

Great idea.

> This way we could have most of the stuff in master and do further
> experiments about the performance implications later on. If you want to
> do this, patches 1-3 are:
>
> Reviewed-by: Lucas Stach 
>

Pushed.

-- 
Thanks
--
Christian Gmeiner, MSc

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


Re: [Mesa-dev] [PATCH 4/4] etnaviv: hook up linear texture sampling support

2019-01-23 Thread Christian Gmeiner
Am Mo., 21. Jan. 2019 um 10:10 Uhr schrieb Lucas Stach :
>
> Am Montag, den 21.01.2019, 07:50 +0100 schrieb Christian Gmeiner:
> > If the GPU supports linear sampling, linear addressing mode
> > will be used as default.
> >
> > > Signed-off-by: Christian Gmeiner 
> > ---
> >  src/gallium/drivers/etnaviv/etnaviv_resource.c | 10 +++---
> >  src/gallium/drivers/etnaviv/etnaviv_texture.c  |  4 +++-
> >  2 files changed, 10 insertions(+), 4 deletions(-)
> >
> > diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> > b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> > index 9a7ebf3064e..7d24b1f03bd 100644
> > --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> > +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> > @@ -318,9 +318,9 @@ etna_resource_create(struct pipe_screen *pscreen,
> >  {
> > struct etna_screen *screen = etna_screen(pscreen);
> >
> > -   /* Figure out what tiling and address mode to use -- for now, assume 
> > that
> > -* texture cannot be linear. there is a capability 
> > LINEAR_TEXTURE_SUPPORT
> > -* (supported on gc880 and gc2000 at least), but not sure how it works.
> > +   /* Figure out what tiling and address mode to use.
> > +* Textures are TILED or LINEAR. If LINEAR_TEXTURE_SUPPORT capability is
> > +* available LINEAR gets prefered.
> >  * Buffers always have LINEAR layout.
> >  */
> > unsigned layout = ETNA_LAYOUT_LINEAR;
> > @@ -334,6 +334,10 @@ etna_resource_create(struct pipe_screen *pscreen,
> >
> >if (util_format_is_compressed(templat->format))
> >   layout = ETNA_LAYOUT_LINEAR;
> > +  else if (VIV_FEATURE(screen, chipMinorFeatures1, 
> > LINEAR_TEXTURE_SUPPORT)) {
> > + layout = ETNA_LAYOUT_LINEAR;
> > + mode = ETNA_ADDRESSING_MODE_LINEAR;
> > +  }
>
> Did you do any performance measurements with this change? I don't think
> we generally want to prefer linear textures, as in theory they have
> much worse texture cache hit rates. Also a lot of the async transfer
> stuff currently depends on hitting the RS linear->tiled blit path for
> optimal performance on uploads.
>

I have not done any performance measurements yet - I only tried to get it
render correctly (piglit and amoeba) and get some feedback asap.
But I will keep an eye on perf for v2.

Regarding the async transfer staff I have the feeling that we lose the shadow
resource (etna_transfer->rsc) handling if we are using linear, which saves us
from some RS blits. Or?

> There are 2 cases where I think linear textures are useful:
>
> 1. Imported external buffers, where we might need to update the
> internal tiled copy on each resource update. Getting rid of this blit
> should help performance a good bit.
>

You are taking about etna_resource_from_handle(..). I *think* for this we
need support for linear in the pixel engine too - based on the binding flag
combinations I have seen.

> 2. 8bpp formats that can't be tiled with the RS and would hit the
> software fallback path. The tradeoff software tiling path vs. reduced
> texture cache hit rates might still prefer linear textures.
>

Yes that I something to look into.

-- 
greets
--
Christian Gmeiner, MSc

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


Re: [Mesa-dev] [PATCH 1/4] etnaviv: extend etna_resource with an addressing mode

2019-01-23 Thread Christian Gmeiner
Hi Lucas

Am Mo., 21. Jan. 2019 um 10:03 Uhr schrieb Lucas Stach :
>
> Hi Christian,
>
> first of all, thanks for figuring this out. This is really nice
> to finally know how it works.
>
> Am Montag, den 21.01.2019, 07:49 +0100 schrieb Christian Gmeiner:
> > Defines how sampler (and pixel pipes) needs to access the data
> > represented with a resource. The used default is mode is
> > ETNA_ADDRESSING_MODE_TILED.
>
> Do you see any reason why we need a separate property for this? IMHO
> etna_resource is already a bit too fat and from this set of patches I
> can't see why we can't infer the addressing mode from the layout. Do
> you have something specific in mind, that I don't see right now?
>

We are using ETNA_LAYOUT_LINEAR for compressed textures with an
addressing mode of TILED (register value of 0). That is the root cause why
was forced to add something new to etna_resource as I can not trust that
ETNA_LAYOUT_LINEAR for sampler resources implies an linear addressing
mode.

--
greets
--
Christian Gmeiner, MSc

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


Re: [Mesa-dev] [PATCH 1/2] pl111: Rename the pl111 driver to "kmsro".

2019-01-23 Thread Christian Gmeiner
Hi Eric

Am Do., 25. Okt. 2018 um 18:39 Uhr schrieb Eric Anholt :
>
> The vc4 driver can do prime sharing to many different KMS-only devices,
> such as the various tinydrm drivers for SPI-attached displays.  Rename the
> driver away from "pl111" to represent what it will actually support:
> various sorts of KMS displays with the renderonly layer used to attach a
> GPU.

I like the idea of this patch and it is good starting point torwards a
generic solution
for kms displays with the renderonly framework.

Reviewed-by: Christian Gmeiner 

> ---
>  .travis.yml  |  2 +-
>  Android.mk   |  4 ++--
>  Makefile.am  |  2 +-
>  configure.ac | 16 
>  meson.build  |  8 
>  meson_options.txt|  2 +-
>  src/gallium/Android.mk   |  2 +-
>  src/gallium/Makefile.am  |  4 ++--
>  .../auxiliary/pipe-loader/pipe_loader_drm.c  |  2 +-
>  .../auxiliary/target-helpers/drm_helper.h| 12 ++--
>  .../auxiliary/target-helpers/drm_helper_public.h |  2 +-
>  src/gallium/drivers/{pl111 => kmsro}/Android.mk  |  6 +++---
>  src/gallium/drivers/kmsro/Automake.inc   |  9 +
>  src/gallium/drivers/{pl111 => kmsro}/Makefile.am |  4 ++--
>  .../drivers/{pl111 => kmsro}/Makefile.sources|  0
>  src/gallium/drivers/pl111/Automake.inc   |  9 -
>  src/gallium/meson.build  |  6 +++---
>  src/gallium/targets/dri/Makefile.am  |  2 +-
>  src/gallium/targets/dri/meson.build  |  4 ++--
>  src/gallium/targets/dri/target.c |  2 +-
>  .../winsys/{pl111 => kmsro}/drm/Android.mk   |  2 +-
>  .../winsys/{pl111 => kmsro}/drm/Makefile.am  |  4 ++--
>  src/gallium/winsys/kmsro/drm/Makefile.sources|  3 +++
>  .../drm/kmsro_drm_public.h}  |  8 
>  .../drm/kmsro_drm_winsys.c}  |  6 +++---
>  .../winsys/{pl111 => kmsro}/drm/meson.build  | 12 ++--
>  src/gallium/winsys/pl111/drm/Makefile.sources|  3 ---
>  27 files changed, 68 insertions(+), 68 deletions(-)
>  rename src/gallium/drivers/{pl111 => kmsro}/Android.mk (91%)
>  create mode 100644 src/gallium/drivers/kmsro/Automake.inc
>  rename src/gallium/drivers/{pl111 => kmsro}/Makefile.am (55%)
>  rename src/gallium/drivers/{pl111 => kmsro}/Makefile.sources (100%)
>  delete mode 100644 src/gallium/drivers/pl111/Automake.inc
>  rename src/gallium/winsys/{pl111 => kmsro}/drm/Android.mk (97%)
>  rename src/gallium/winsys/{pl111 => kmsro}/drm/Makefile.am (94%)
>  create mode 100644 src/gallium/winsys/kmsro/drm/Makefile.sources
>  rename src/gallium/winsys/{pl111/drm/pl111_drm_public.h => 
> kmsro/drm/kmsro_drm_public.h} (89%)
>  rename src/gallium/winsys/{pl111/drm/pl111_drm_winsys.c => 
> kmsro/drm/kmsro_drm_winsys.c} (92%)
>  rename src/gallium/winsys/{pl111 => kmsro}/drm/meson.build (87%)
>  delete mode 100644 src/gallium/winsys/pl111/drm/Makefile.sources
>
> diff --git a/.travis.yml b/.travis.yml
> index 78e6d251ae4b..8bcd77143569 100644
> --- a/.travis.yml
> +++ b/.travis.yml
> @@ -165,7 +165,7 @@ matrix:
>  - DRI_LOADERS="--disable-glx --disable-gbm --disable-egl"
>  - DRI_DRIVERS=""
>  - GALLIUM_ST="--enable-dri --disable-opencl --disable-xa 
> --disable-nine --disable-xvmc --disable-vdpau --disable-va 
> --disable-omx-bellagio --disable-gallium-osmesa"
> -- 
> GALLIUM_DRIVERS="i915,nouveau,pl111,r300,r600,freedreno,svga,swrast,v3d,vc4,virgl,etnaviv,imx"
> +- 
> GALLIUM_DRIVERS="i915,nouveau,kmsro,r300,r600,freedreno,svga,swrast,v3d,vc4,virgl,etnaviv,imx"
>  - VULKAN_DRIVERS=""
>  - LIBUNWIND_FLAGS="--enable-libunwind"
>addons:
> diff --git a/Android.mk b/Android.mk
> index 914854c27d63..1a0bdd1736cf 100644
> --- a/Android.mk
> +++ b/Android.mk
> @@ -24,7 +24,7 @@
>  # BOARD_GPU_DRIVERS should be defined.  The valid values are
>  #
>  #   classic drivers: i915 i965
> -#   gallium drivers: swrast freedreno i915g nouveau pl111 r300g r600g 
> radeonsi vc4 virgl vmwgfx etnaviv imx
> +#   gallium drivers: swrast freedreno i915g nouveau kmsro r300g r600g 
> radeonsi vc4 virgl vmwgfx etnaviv imx
>  #
>  # The main target is libGLES_mesa.  For each classic driver enabled, a DRI
>  # module will also be built.  DRI modules will be loaded by libGLES_mesa.
> @@ -52,7 +52,7 @@ gallium_drivers := \
> freedreno

[Mesa-dev] [PATCH 3/4] etnaviv: add linear sampling support

2019-01-20 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 .../drivers/etnaviv/etnaviv_texture_state.c   | 21 +++
 .../drivers/etnaviv/etnaviv_texture_state.h   |  1 +
 2 files changed, 22 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_texture_state.c 
b/src/gallium/drivers/etnaviv/etnaviv_texture_state.c
index 7100865f925..ef2a7bd581c 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_texture_state.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_texture_state.c
@@ -131,6 +131,17 @@ etna_create_sampler_view_state(struct pipe_context *pctx, 
struct pipe_resource *
   return NULL;
}
 
+   if (res->addressing_mode == ETNA_ADDRESSING_MODE_LINEAR) {
+  sv->TE_SAMPLER_CONFIG0 |= 
VIVS_TE_SAMPLER_CONFIG0_ADDRESSING_MODE(TEXTURE_ADDRESSING_MODE_LINEAR);
+
+  for (int lod = 0; lod <= res->base.last_level; ++lod)
+ sv->TE_SAMPLER_LINEAR_STRIDE[lod] = res->levels[lod].stride;
+
+   } else {
+  sv->TE_SAMPLER_CONFIG0 |= 
VIVS_TE_SAMPLER_CONFIG0_ADDRESSING_MODE(TEXTURE_ADDRESSING_MODE_TILED);
+  memset(>TE_SAMPLER_LINEAR_STRIDE, 0, 
sizeof(sv->TE_SAMPLER_LINEAR_STRIDE));
+   }
+
sv->TE_SAMPLER_CONFIG1 = COND(ext, 
VIVS_TE_SAMPLER_CONFIG1_FORMAT_EXT(format)) |
 COND(astc, 
VIVS_TE_SAMPLER_CONFIG1_FORMAT_EXT(TEXTURE_FORMAT_EXT_ASTC)) |
 VIVS_TE_SAMPLER_CONFIG1_HALIGN(res->halign) | swiz;
@@ -294,6 +305,16 @@ etna_emit_texture_state(struct etna_context *ctx)
  }
   }
}
+   if (unlikely(dirty & (ETNA_DIRTY_SAMPLER_VIEWS))) {
+  for (int y = 0; y < VIVS_TE_SAMPLER_LINEAR_STRIDE__LEN; ++y) {
+ for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) {
+if ((1 << x) & active_samplers) {
+   struct etna_sampler_view *sv = 
etna_sampler_view(ctx->sampler_view[x]);
+   /*02C00*/ EMIT_STATE(TE_SAMPLER_LINEAR_STRIDE(x, y), 
sv->TE_SAMPLER_LINEAR_STRIDE[y]);
+}
+ }
+  }
+   }
if (unlikely(ctx->specs.tex_astc && (dirty & (ETNA_DIRTY_SAMPLER_VIEWS {
   for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) {
  if ((1 << x) & active_samplers) {
diff --git a/src/gallium/drivers/etnaviv/etnaviv_texture_state.h 
b/src/gallium/drivers/etnaviv/etnaviv_texture_state.h
index 86bbcb3cf3c..816f42e3730 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_texture_state.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_texture_state.h
@@ -62,6 +62,7 @@ struct etna_sampler_view {
uint32_t TE_SAMPLER_SIZE;
uint32_t TE_SAMPLER_LOG_SIZE;
uint32_t TE_SAMPLER_ASTC0;
+   uint32_t TE_SAMPLER_LINEAR_STRIDE[VIVS_TE_SAMPLER_LINEAR_STRIDE__LEN];
struct etna_reloc TE_SAMPLER_LOD_ADDR[VIVS_TE_SAMPLER_LOD_ADDR__LEN];
unsigned min_lod, max_lod; /* 5.5 fixp */
 
-- 
2.20.1

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


[Mesa-dev] [PATCH 2/4] etnaviv: update headers from rnndb

2019-01-20 Thread Christian Gmeiner
Update to etna_viv commit 4d2f857.

Signed-off-by: Christian Gmeiner 
---
 .../drivers/etnaviv/hw/cmdstream.xml.h|   8 +-
 src/gallium/drivers/etnaviv/hw/common.xml.h   | 171 +-
 .../drivers/etnaviv/hw/common_3d.xml.h|  12 +-
 src/gallium/drivers/etnaviv/hw/isa.xml.h  |   6 +-
 src/gallium/drivers/etnaviv/hw/state.xml.h|  22 +--
 src/gallium/drivers/etnaviv/hw/state_3d.xml.h |  28 +--
 .../drivers/etnaviv/hw/state_blt.xml.h|  22 +--
 .../drivers/etnaviv/hw/texdesc_3d.xml.h   |  13 +-
 8 files changed, 227 insertions(+), 55 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/hw/cmdstream.xml.h 
b/src/gallium/drivers/etnaviv/hw/cmdstream.xml.h
index 63d4e9342eb..77cbebfe365 100644
--- a/src/gallium/drivers/etnaviv/hw/cmdstream.xml.h
+++ b/src/gallium/drivers/etnaviv/hw/cmdstream.xml.h
@@ -8,11 +8,11 @@ http://0x04.net/cgit/index.cgi/rules-ng-ng
 git clone git://0x04.net/rules-ng-ng
 
 The rules-ng-ng source files this header was generated from are:
-- cmdstream.xml (  16929 bytes, from 2017-10-13 12:22:46)
-- copyright.xml (   1597 bytes, from 2016-10-29 07:29:22)
-- common.xml(  26187 bytes, from 2017-10-31 19:05:01)
+- cmdstream.xml (  16930 bytes, from 2019-01-04 11:37:39)
+- copyright.xml (   1597 bytes, from 2018-02-10 13:09:26)
+- common.xml(  35468 bytes, from 2018-02-10 13:09:26)
 
-Copyright (C) 2012-2017 by the following authors:
+Copyright (C) 2012-2019 by the following authors:
 - Wladimir J. van der Laan 
 - Christian Gmeiner 
 - Lucas Stach 
diff --git a/src/gallium/drivers/etnaviv/hw/common.xml.h 
b/src/gallium/drivers/etnaviv/hw/common.xml.h
index 60bde8b96b8..4af7ec3693a 100644
--- a/src/gallium/drivers/etnaviv/hw/common.xml.h
+++ b/src/gallium/drivers/etnaviv/hw/common.xml.h
@@ -8,12 +8,12 @@ http://0x04.net/cgit/index.cgi/rules-ng-ng
 git clone git://0x04.net/rules-ng-ng
 
 The rules-ng-ng source files this header was generated from are:
-- texdesc_3d.xml (   3183 bytes, from 2017-10-31 19:05:01)
-- copyright.xml  (   1597 bytes, from 2016-10-29 07:29:22)
-- common.xml (  26187 bytes, from 2017-10-31 19:05:01)
-- common_3d.xml  (  14615 bytes, from 2017-11-04 14:03:35)
+- texdesc_3d.xml (   3183 bytes, from 2018-02-10 13:09:26)
+- copyright.xml  (   1597 bytes, from 2018-02-10 13:09:26)
+- common.xml (  35468 bytes, from 2018-02-10 13:09:26)
+- common_3d.xml  (  14843 bytes, from 2019-01-18 10:13:41)
 
-Copyright (C) 2012-2017 by the following authors:
+Copyright (C) 2012-2018 by the following authors:
 - Wladimir J. van der Laan 
 - Christian Gmeiner 
 - Lucas Stach 
@@ -320,5 +320,166 @@ DEALINGS IN THE SOFTWARE.
 #define chipMinorFeatures6_DEC 0x0004
 #define chipMinorFeatures6_VS_TILE_NV12
0x0008
 #define chipMinorFeatures6_VS_TILE_NV12_10BIT  0x0010
+#define chipMinorFeatures6_RENDER_TARGET_8 0x0020
+#define chipMinorFeatures6_TEX_LOD_FLOW_CORR   0x0040
+#define chipMinorFeatures6_FACE_LOD0x0080
+#define chipMinorFeatures6_MULTI_CORE_SEMAPHORE_STALL_V2   0x0100
+#define chipMinorFeatures6_VMSAA   0x0200
+#define chipMinorFeatures6_CHIP_ENABLE_LINK0x0400
+#define chipMinorFeatures6_MULTI_SRC_BLT_1_5_ENHANCEMENT   0x0800
+#define chipMinorFeatures6_MULTI_SRC_BLT_BILINEAR_FILTER   0x1000
+#define chipMinorFeatures6_RA_HZEZ_CLOCK_CONTROL   0x2000
+#define chipMinorFeatures6_CACHE128B256BPERLINE
0x4000
+#define chipMinorFeatures6_V4_COMPRESSION  0x8000
+#define chipMinorFeatures6_PE2D_MAJOR_SUPER_TILE   0x0001
+#define chipMinorFeatures6_PE_32BPC_COLORMASK_FIX  0x0002
+#define chipMinorFeatures6_ALPHA_BLENDING_OPT  0x0004
+#define chipMinorFeatures6_NEW_GPIPE   0x0008
+#define chipMinorFeatures6_PIPELINE_32_ATTRIBUTES  0x0010
+#define chipMinorFeatures6_MSAA_SHADING
0x0020
+#define chipMinorFeatures6_NO_ANISTRO_FILTER   0x0040
+#define chipMinorFeatures6_NO_ASTC 0x0080
+#define chipMinorFeatures6_NO_DXT  0x0100
+#define chipMinorFeatures6_HWTFB   0x0200
+#define chipMinorFeatures6_RA_DEPTH_WRITE_MSAA1X_FIX   0x0400
+#define chipMinorFeatures6_EZHZ_CLOCKGATE_FIX  0x0800
+#define chipMinorFeatures6_SH_SNAP2PAGE_FIX0x1000
+#define chipMinorFeatures6_SH_HALFDEPENDENCY_FIX   0x2000
+#define chipMinorFeatures6_USC_MCFILL_FIX  0x4000
+#define chipMinorFeatures6_TPG_TCPERF_FIX  0x8000
+#define chipMinorFeatures7_USC_MDFIFO_OVERFLOW_FIX

[Mesa-dev] [PATCH 4/4] etnaviv: hook up linear texture sampling support

2019-01-20 Thread Christian Gmeiner
If the GPU supports linear sampling, linear addressing mode
will be used as default.

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 10 +++---
 src/gallium/drivers/etnaviv/etnaviv_texture.c  |  4 +++-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index 9a7ebf3064e..7d24b1f03bd 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -318,9 +318,9 @@ etna_resource_create(struct pipe_screen *pscreen,
 {
struct etna_screen *screen = etna_screen(pscreen);
 
-   /* Figure out what tiling and address mode to use -- for now, assume that
-* texture cannot be linear. there is a capability LINEAR_TEXTURE_SUPPORT
-* (supported on gc880 and gc2000 at least), but not sure how it works.
+   /* Figure out what tiling and address mode to use.
+* Textures are TILED or LINEAR. If LINEAR_TEXTURE_SUPPORT capability is
+* available LINEAR gets prefered.
 * Buffers always have LINEAR layout.
 */
unsigned layout = ETNA_LAYOUT_LINEAR;
@@ -334,6 +334,10 @@ etna_resource_create(struct pipe_screen *pscreen,
 
   if (util_format_is_compressed(templat->format))
  layout = ETNA_LAYOUT_LINEAR;
+  else if (VIV_FEATURE(screen, chipMinorFeatures1, 
LINEAR_TEXTURE_SUPPORT)) {
+ layout = ETNA_LAYOUT_LINEAR;
+ mode = ETNA_ADDRESSING_MODE_LINEAR;
+  }
} else if (templat->target != PIPE_BUFFER) {
   bool want_multitiled = false;
   bool want_supertiled = screen->specs.can_supertile;
diff --git a/src/gallium/drivers/etnaviv/etnaviv_texture.c 
b/src/gallium/drivers/etnaviv/etnaviv_texture.c
index 3993e31cec1..b06f20531fd 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_texture.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_texture.c
@@ -172,7 +172,9 @@ etna_resource_sampler_compatible(struct etna_resource *res)
if (res->layout == ETNA_LAYOUT_SUPER_TILED && VIV_FEATURE(screen, 
chipMinorFeatures2, SUPERTILED_TEXTURE))
   return true;
 
-   /* TODO: LINEAR_TEXTURE_SUPPORT */
+   /* This GPU supports texturing from linear textures? */
+   if (res->layout == ETNA_LAYOUT_LINEAR && VIV_FEATURE(screen, 
chipMinorFeatures1, LINEAR_TEXTURE_SUPPORT))
+  return true;
 
/* Otherwise, only support tiled layouts */
if (res->layout != ETNA_LAYOUT_TILED)
-- 
2.20.1

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


[Mesa-dev] [PATCH 1/4] etnaviv: extend etna_resource with an addressing mode

2019-01-20 Thread Christian Gmeiner
Defines how sampler (and pixel pipes) needs to access the data
represented with a resource. The used default is mode is
ETNA_ADDRESSING_MODE_TILED.

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 17 +++--
 src/gallium/drivers/etnaviv/etnaviv_resource.h |  9 -
 src/gallium/drivers/etnaviv/etnaviv_texture.c  |  1 +
 src/gallium/drivers/etnaviv/etnaviv_transfer.c |  3 ++-
 4 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index c0091288030..9a7ebf3064e 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -188,7 +188,8 @@ static bool is_rs_align(struct etna_screen *screen,
 /* Create a new resource object, using the given template info */
 struct pipe_resource *
 etna_resource_alloc(struct pipe_screen *pscreen, unsigned layout,
-uint64_t modifier, const struct pipe_resource *templat)
+enum etna_resource_addressing_mode mode, uint64_t modifier,
+const struct pipe_resource *templat)
 {
struct etna_screen *screen = etna_screen(pscreen);
struct etna_resource *rsc;
@@ -280,6 +281,7 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned 
layout,
rsc->base.nr_samples = nr_samples;
rsc->layout = layout;
rsc->halign = halign;
+   rsc->addressing_mode = mode;
 
pipe_reference_init(>base.reference, 1);
list_inithead(>list);
@@ -316,12 +318,14 @@ etna_resource_create(struct pipe_screen *pscreen,
 {
struct etna_screen *screen = etna_screen(pscreen);
 
-   /* Figure out what tiling to use -- for now, assume that texture cannot be 
linear.
-* there is a capability LINEAR_TEXTURE_SUPPORT (supported on gc880 and
-* gc2000 at least), but not sure how it works.
+   /* Figure out what tiling and address mode to use -- for now, assume that
+* texture cannot be linear. there is a capability LINEAR_TEXTURE_SUPPORT
+* (supported on gc880 and gc2000 at least), but not sure how it works.
 * Buffers always have LINEAR layout.
 */
unsigned layout = ETNA_LAYOUT_LINEAR;
+   enum etna_resource_addressing_mode mode = ETNA_ADDRESSING_MODE_TILED;
+
if (etna_resource_sampler_only(templat)) {
   /* The buffer is only used for texturing, so create something
* directly compatible with the sampler.  Such a buffer can
@@ -364,7 +368,7 @@ etna_resource_create(struct pipe_screen *pscreen,
   layout = ETNA_LAYOUT_LINEAR;
 
/* modifier is only used for scanout surfaces, so safe to use LINEAR here */
-   return etna_resource_alloc(pscreen, layout, DRM_FORMAT_MOD_LINEAR, templat);
+   return etna_resource_alloc(pscreen, layout, mode, DRM_FORMAT_MOD_LINEAR, 
templat);
 }
 
 enum modifier_priority {
@@ -445,7 +449,7 @@ etna_resource_create_modifiers(struct pipe_screen *pscreen,
tmpl.bind |= PIPE_BIND_SCANOUT;
 
return etna_resource_alloc(pscreen, modifier_to_layout(modifier),
-  modifier, );
+  ETNA_ADDRESSING_MODE_TILED, modifier, );
 }
 
 static void
@@ -518,6 +522,7 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
rsc->seqno = 1;
rsc->layout = modifier_to_layout(handle->modifier);
rsc->halign = TEXTURE_HALIGN_FOUR;
+   rsc->addressing_mode = ETNA_ADDRESSING_MODE_TILED;
 
 
level->width = tmpl->width0;
diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.h 
b/src/gallium/drivers/etnaviv/etnaviv_resource.h
index 11ccf8f7bcb..75aa80b3d7a 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.h
@@ -49,6 +49,11 @@ struct etna_resource_level {
bool ts_valid;
 };
 
+enum etna_resource_addressing_mode {
+   ETNA_ADDRESSING_MODE_TILED = 0,
+   ETNA_ADDRESSING_MODE_LINEAR,
+};
+
 /* status of queued up but not flushed reads and write operations.
  * In _transfer_map() we need to know if queued up rendering needs
  * to be flushed to preserve the order of cpu and gpu access. */
@@ -66,6 +71,7 @@ struct etna_resource {
/* only lod 0 used for non-texture buffers */
/* Layout for surface (tiled, multitiled, split tiled, ...) */
enum etna_surface_layout layout;
+   enum etna_resource_addressing_mode addressing_mode;
/* Horizontal alignment for texture unit (TEXTURE_HALIGN_*) */
unsigned halign;
struct etna_bo *bo; /* Surface video memory */
@@ -155,7 +161,8 @@ etna_screen_resource_alloc_ts(struct pipe_screen *pscreen,
 
 struct pipe_resource *
 etna_resource_alloc(struct pipe_screen *pscreen, unsigned layout,
-uint64_t modifier, const struct pipe_resource *templat);
+enum etna_resource_addressing_mode mode, uint64_t modifier,
+const struct pipe_resource *templat);
 
 void
 etna_resource_screen_init(struct pipe_scr

Re: [Mesa-dev] [PATCH] autotools: Deprecate the use of autotools

2019-01-11 Thread Christian Gmeiner
Am So., 16. Dez. 2018 um 12:24 Uhr schrieb Gert Wollny :
>
> Since Meson will eventually be the only build system deprecate autotools
> now. It can still be used by invoking configure with the flag
>   --enable-autotools
>
> Signed-off-by: Gert Wollny 

Reviewed-by: Christian Gmeiner 

> ---
> IMO autotools should be properly deprecated prior it its removal, so here
> is a patch to do just that. I think autotools should be marked as deprecated
> for the 19.0 release and, depending on feedback, it could be removed with 
> 19.1.
> Anyway, in the end it's up to the release team how to handle this.
>
> Best,
> Gert
>
>  configure.ac | 13 +
>  1 file changed, 13 insertions(+)
>
> diff --git a/configure.ac b/configure.ac
> index 9b437a252c..73f5978bb7 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -52,6 +52,19 @@ mingw*)
>  ;;
>  esac
>
> +AC_ARG_ENABLE(autotools,
> +   [AS_HELP_STRING([--enable-autotools],
> +   [Enable the use of this autotools based build 
> configuration])],
> +   [enable_autotools=$enableval], [enable_autotools=no])
> +
> +if test "x$enable_autotools" != "xyes" ; then
> +AC_MSG_ERROR([the autotools build system has been deprecated in favour of
> +meson and will be removed eventually. For instructions on how to use 
> meson
> +see https://www.mesa3d.org/meson.html.
> +If you still want to use the autotools build, then add --enable-autotools
> +to the configure command line.])
> +fi
> +
>  # Support silent build rules, requires at least automake-1.11. Disable
>  # by either passing --disable-silent-rules to configure or passing V=1
>  # to make
> --
> 2.19.2
>
> _______
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev



-- 
greets
--
Christian Gmeiner, MSc

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


Re: [Mesa-dev] [PATCH] etnaviv_screen: Fix typo in cflush_all description

2019-01-07 Thread Christian Gmeiner
Am Mo., 7. Jan. 2019 um 15:00 Uhr schrieb Guido Günther :
>
> Signed-off-by: Guido Günther 

Reviewed-by: Christian Gmeiner 

> ---
>  src/gallium/drivers/etnaviv/etnaviv_screen.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c 
> b/src/gallium/drivers/etnaviv/etnaviv_screen.c
> index fb51aa5f4e8..fd320232528 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_screen.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c
> @@ -63,7 +63,7 @@ static const struct debug_named_value debug_options[] = {
> {"no_autodisable", ETNA_DBG_NO_AUTODISABLE, "Disable autodisable"},
> {"no_supertile",   ETNA_DBG_NO_SUPERTILE, "Disable supertiles"},
> {"no_early_z", ETNA_DBG_NO_EARLY_Z, "Disable early z"},
> -   {"cflush_all", ETNA_DBG_CFLUSH_ALL, "Flush every cash before state 
> update"},
> +   {"cflush_all", ETNA_DBG_CFLUSH_ALL, "Flush every cache before state 
> update"},
> {"msaa2x", ETNA_DBG_MSAA_2X, "Force 2x msaa"},
> {"msaa4x", ETNA_DBG_MSAA_4X, "Force 4x msaa"},
> {"flush_all",  ETNA_DBG_FLUSH_ALL, "Flush after every rendered 
> primitive"},
> --
> 2.19.2
> ___
> etnaviv mailing list
> etna...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv



-- 
greets
--
Christian Gmeiner, MSc

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


[Mesa-dev] [PATCH v2] etnaviv: fix resource usage tracking across different pipe_context's

2019-01-02 Thread Christian Gmeiner
A pipe_resource can be shared by all the pipe_context's hanging off the
same pipe_screen.

Changes from v1 -> v2:
 - to remove the resource from the used_resources set when it is destroyed

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_context.c | 21 
 src/gallium/drivers/etnaviv/etnaviv_context.h |  3 --
 .../drivers/etnaviv/etnaviv_resource.c| 48 ++-
 .../drivers/etnaviv/etnaviv_resource.h|  7 ++-
 src/gallium/drivers/etnaviv/etnaviv_screen.c  |  8 
 src/gallium/drivers/etnaviv/etnaviv_screen.h  |  4 ++
 6 files changed, 61 insertions(+), 30 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.c 
b/src/gallium/drivers/etnaviv/etnaviv_context.c
index 44b50925a4f..8d4956516f1 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.c
@@ -36,6 +36,7 @@
 #include "etnaviv_query.h"
 #include "etnaviv_query_hw.h"
 #include "etnaviv_rasterizer.h"
+#include "etnaviv_resource.h"
 #include "etnaviv_screen.h"
 #include "etnaviv_shader.h"
 #include "etnaviv_state.h"
@@ -329,7 +330,8 @@ static void
 etna_cmd_stream_reset_notify(struct etna_cmd_stream *stream, void *priv)
 {
struct etna_context *ctx = priv;
-   struct etna_resource *rsc, *rsc_tmp;
+   struct etna_screen *screen = ctx->screen;
+   struct set_entry *entry;
 
etna_set_state(stream, VIVS_GL_API_MODE, VIVS_GL_API_MODE_OPENGL);
etna_set_state(stream, VIVS_GL_VERTEX_ELEMENT_CONFIG, 0x0001);
@@ -384,16 +386,13 @@ etna_cmd_stream_reset_notify(struct etna_cmd_stream 
*stream, void *priv)
ctx->dirty = ~0L;
ctx->dirty_sampler_views = ~0L;
 
-   /* go through all the used resources and clear their status flag */
-   LIST_FOR_EACH_ENTRY_SAFE(rsc, rsc_tmp, >used_resources, list)
-   {
-  debug_assert(rsc->status != 0);
-  rsc->status = 0;
-  rsc->pending_ctx = NULL;
-  list_delinit(>list);
-   }
+   /* go through all the used context resources and clear their status flag */
+   set_foreach(screen->used_resources, entry) {
+  struct etna_resource *rsc = (struct etna_resource *)entry->key;
 
-   assert(LIST_IS_EMPTY(>used_resources));
+  _mesa_set_remove_key(rsc->pending_ctx, ctx);
+  _mesa_set_remove(screen->used_resources, entry);
+   }
 }
 
 static void
@@ -437,8 +436,6 @@ etna_context_create(struct pipe_screen *pscreen, void 
*priv, unsigned flags)
/* need some sane default in case state tracker doesn't set some state: */
ctx->sample_mask = 0x;
 
-   list_inithead(>used_resources);
-
/*  Set sensible defaults for state */
etna_cmd_stream_reset_notify(ctx->stream, ctx);
 
diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.h 
b/src/gallium/drivers/etnaviv/etnaviv_context.h
index 6ad9f3431e1..50a2cdf3d07 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.h
@@ -136,9 +136,6 @@ struct etna_context {
uint32_t prim_hwsupport;
struct primconvert_context *primconvert;
 
-   /* list of resources used by currently-unsubmitted renders */
-   struct list_head used_resources;
-
struct slab_child_pool transfer_pool;
struct blitter_context *blitter;
 
diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index c0091288030..00b5f43bf3f 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -33,6 +33,7 @@
 #include "etnaviv_screen.h"
 #include "etnaviv_translate.h"
 
+#include "util/hash_table.h"
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
 
@@ -282,7 +283,6 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned 
layout,
rsc->halign = halign;
 
pipe_reference_init(>base.reference, 1);
-   list_inithead(>list);
 
size = setup_miptree(rsc, paddingX, paddingY, msaa_xscale, msaa_yscale);
 
@@ -303,6 +303,11 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned 
layout,
   memset(map, 0, size);
}
 
+   rsc->pending_ctx = _mesa_set_create(NULL, _mesa_hash_pointer,
+   _mesa_key_pointer_equal);
+   if (!rsc->pending_ctx)
+  goto free_rsc;
+
return >base;
 
 free_rsc:
@@ -462,8 +467,12 @@ etna_resource_changed(struct pipe_screen *pscreen, struct 
pipe_resource *prsc)
 static void
 etna_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *prsc)
 {
+   struct etna_screen *screen = etna_screen(pscreen);
struct etna_resource *rsc = etna_resource(prsc);
 
+   _mesa_set_destroy(rsc->pending_ctx, NULL);
+   _mesa_set_remove_key(screen->used_resources, rsc);
+
if (rsc->bo)
   etna_bo_del(rsc->bo);
 
@@ -471,9 +480,7 @@ etna_resource_destroy(struct pipe_screen *pscreen, struct 
pipe_resource *

Re: [Mesa-dev] [PATCH] etnaviv: implement check_resource_capability

2018-12-28 Thread Christian Gmeiner
Am Di., 18. Dez. 2018 um 19:09 Uhr schrieb Lucas Stach :
>
> We try to avoid sharing all resources with KMS side of renderonly, as this
> adds some overhead that isn't really needed for most resources. If
> someone tries to validate a resource for scanout, this is a good indication
> that the sharing with the KMS side is actually needed.
>
> Signed-off-by: Lucas Stach 
> ---
>  .../drivers/etnaviv/etnaviv_resource.c| 22 +++
>  1 file changed, 22 insertions(+)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> index c00912880309..cd846e3ae36e 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> @@ -624,6 +624,27 @@ etna_resource_get_handle(struct pipe_screen *pscreen,
> }
>  }
>
> +static bool
> +etna_check_resource_capability(struct pipe_screen *pscreen,
> +   struct pipe_resource *prsc,
> +   unsigned bind)
> +{
> +   struct etna_screen *screen = etna_screen(pscreen);
> +   struct etna_resource *rsc = etna_resource(prsc);
> +
> +   if ((bind & PIPE_BIND_LINEAR) && rsc->layout != ETNA_LAYOUT_LINEAR)
> +  return false;
> +
> +   if ((bind & PIPE_BIND_SCANOUT) && !rsc->scanout) {
> +  rsc->scanout = renderonly_create_gpu_import_for_resource(prsc, 
> screen->ro,
> +   NULL);

Can you explain me why the
renderonly_create_gpu_import_for_resource(..) call ends up here? Are
there really any cases where !rsc->scanout? I looked at the relevant
code parts and I have the feeling
the renderonly_create_gpu_import_for_resource(..) call happens much
earlier in the call chain. I could be
wrong as I am running out of coffee right now :)

> +  if (!rsc->scanout)
> + return false;
> +   }
> +
> +   return true;
> +}
> +
>  void
>  etna_resource_used(struct etna_context *ctx, struct pipe_resource *prsc,
> enum etna_resource_status status)
> @@ -667,4 +688,5 @@ etna_resource_screen_init(struct pipe_screen *pscreen)
> pscreen->resource_get_handle = etna_resource_get_handle;
> pscreen->resource_changed = etna_resource_changed;
> pscreen->resource_destroy = etna_resource_destroy;
> +   pscreen->check_resource_capability = etna_check_resource_capability;
>  }
> --
> 2.19.1
>
> ___
> etnaviv mailing list
> etna...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv



-- 
greets
--
Christian Gmeiner, MSc

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


Re: [Mesa-dev] [PATCH v2 2/2] etnaviv: annotate variables only used in debug build

2018-12-28 Thread Christian Gmeiner
Am Mi., 19. Dez. 2018 um 16:27 Uhr schrieb Lucas Stach :
>
> Some of the status variables in the compiler are only used in asserts
> and thus may be unused in release builds. Annotate them accordingly
> to avoid 'unused but set' warnings from the compiler.
>
> Signed-off-by: Lucas Stach 

Reviewed-by: Christian Gmeiner 

> ---
> v2: get rid of superfluous variable initialization
> ---
>  src/gallium/drivers/etnaviv/etnaviv_compiler.c | 11 ---
>  1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler.c 
> b/src/gallium/drivers/etnaviv/etnaviv_compiler.c
> index bbc61a59fc67..ceca5b8af997 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_compiler.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_compiler.c
> @@ -477,8 +477,7 @@ static void
>  etna_compile_parse_declarations(struct etna_compile *c)
>  {
> struct tgsi_parse_context ctx = { };
> -   unsigned status = TGSI_PARSE_OK;
> -   status = tgsi_parse_init(, c->tokens);
> +   MAYBE_UNUSED unsigned status = tgsi_parse_init(, c->tokens);
> assert(status == TGSI_PARSE_OK);
>
> while (!tgsi_parse_end_of_tokens()) {
> @@ -530,8 +529,7 @@ static void
>  etna_compile_pass_check_usage(struct etna_compile *c)
>  {
> struct tgsi_parse_context ctx = { };
> -   unsigned status = TGSI_PARSE_OK;
> -   status = tgsi_parse_init(, c->tokens);
> +   MAYBE_UNUSED unsigned status = tgsi_parse_init(, c->tokens);
> assert(status == TGSI_PARSE_OK);
>
> for (int idx = 0; idx < c->total_decls; ++idx) {
> @@ -662,8 +660,7 @@ etna_compile_pass_optimize_outputs(struct etna_compile *c)
>  {
> struct tgsi_parse_context ctx = { };
> int inst_idx = 0;
> -   unsigned status = TGSI_PARSE_OK;
> -   status = tgsi_parse_init(, c->tokens);
> +   MAYBE_UNUSED unsigned status = tgsi_parse_init(, c->tokens);
> assert(status == TGSI_PARSE_OK);
>
> while (!tgsi_parse_end_of_tokens()) {
> @@ -1812,7 +1809,7 @@ static void
>  etna_compile_pass_generate_code(struct etna_compile *c)
>  {
> struct tgsi_parse_context ctx = { };
> -   unsigned status = tgsi_parse_init(, c->tokens);
> +   MAYBE_UNUSED unsigned status = tgsi_parse_init(, c->tokens);
> assert(status == TGSI_PARSE_OK);
>
> int inst_idx = 0;
> --
> 2.19.1
>
> ___
> etnaviv mailing list
> etna...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv



-- 
greets
--
Christian Gmeiner, MSc

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


Re: [Mesa-dev] [PATCH v2 1/2] etnaviv: enable full overwrite in a few more cases

2018-12-28 Thread Christian Gmeiner
Am Mi., 19. Dez. 2018 um 16:27 Uhr schrieb Lucas Stach :
>
> Take into account the render target format when checking if the color
> mask affects all channels of the RT. This allows to enable full
> override in a few cases where a non-alpha format is used.
>
> Signed-off-by: Lucas Stach 

Reviewed-by: Christian Gmeiner 

> ---
> v2: clarify comment
> ---
>  src/gallium/drivers/etnaviv/etnaviv_blend.c | 11 +++
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_blend.c 
> b/src/gallium/drivers/etnaviv/etnaviv_blend.c
> index 0e2299a50b30..061c9af5247f 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_blend.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_blend.c
> @@ -114,6 +114,7 @@ etna_update_blend(struct etna_context *ctx)
> struct pipe_blend_state *pblend = ctx->blend;
> struct etna_blend_state *blend = etna_blend_state(pblend);
> const struct pipe_rt_blend_state *rt0 = >rt[0];
> +   const struct util_format_description *desc;
> uint32_t colormask;
>
> if (pfb->cbufs[0] &&
> @@ -128,11 +129,13 @@ etna_update_blend(struct etna_context *ctx)
> }
>
> /* If the complete render target is written, set full_overwrite:
> -* - The color mask is 
> -* - No blending is used
> +* - The color mask covers all channels of the render target
> +* - No blending or logicop is used
>  */
> -   bool full_overwrite = ((rt0->colormask == 0xf) && blend->fo_allowed) ||
> - !pfb->cbufs[0];
> +   if (pfb->cbufs[0])
> +  desc = util_format_description(pfb->cbufs[0]->format);
> +   bool full_overwrite = !pfb->cbufs[0] || ((blend->fo_allowed &&
> + util_format_colormask_full(desc, colormask)));
> blend->PE_COLOR_FORMAT =
>  VIVS_PE_COLOR_FORMAT_COMPONENTS(colormask) |
>  COND(full_overwrite, VIVS_PE_COLOR_FORMAT_OVERWRITE);
> --
> 2.19.1
>
> ___
> etnaviv mailing list
> etna...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/etnaviv



-- 
greets
--
Christian Gmeiner, MSc

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


Re: [Mesa-dev] [PATCH 04/16] nir: add nir_lower_bool_to_float

2018-12-19 Thread Christian Gmeiner
 +
> +static bool
> +lower_alu_instr(nir_alu_instr *alu)
> +{
> +   const nir_op_info *op_info = _op_infos[alu->op];
> +
> +   switch (alu->op) {
> +   case nir_op_vec2:
> +   case nir_op_vec3:
> +   case nir_op_vec4:
> +  /* These we expect to have booleans but the opcode doesn't change */
> +  break;
> +
> +   case nir_op_b2f32: alu->op = nir_op_fmov; break;
> +
> +   /* Note: we only expect these 5 opcodes with bools */
> +   case nir_op_imov: alu->op = nir_op_fmov; break;
> +   case nir_op_inot: alu->op = nir_op_fnot; break;
> +   case nir_op_iand: alu->op = nir_op_fand; break;
> +   case nir_op_ior: alu->op = nir_op_for; break;
> +   case nir_op_ixor: alu->op = nir_op_fxor; break;
> +
> +   /* We might want a new opcode (for the (x != 0.0) f2b op)  */
> +   case nir_op_f2b1: alu->op = nir_op_f2b32; break;
> +   case nir_op_i2b1: alu->op = nir_op_f2b32; break;
> +
> +   case nir_op_flt: alu->op = nir_op_slt; break;
> +   case nir_op_fge: alu->op = nir_op_sge; break;
> +   case nir_op_feq: alu->op = nir_op_seq; break;
> +   case nir_op_fne: alu->op = nir_op_sne; break;
> +   case nir_op_ilt: alu->op = nir_op_slt; break;
> +   case nir_op_ige: alu->op = nir_op_sge; break;
> +   case nir_op_ieq: alu->op = nir_op_seq; break;
> +   case nir_op_ine: alu->op = nir_op_sne; break;
> +   case nir_op_ult: alu->op = nir_op_slt; break;
> +   case nir_op_uge: alu->op = nir_op_sge; break;
> +
> +   case nir_op_ball_fequal2:  alu->op = nir_op_fall_equal2; break;
> +   case nir_op_ball_fequal3:  alu->op = nir_op_fall_equal3; break;
> +   case nir_op_ball_fequal4:  alu->op = nir_op_fall_equal4; break;
> +   case nir_op_bany_fnequal2: alu->op = nir_op_fany_nequal2; break;
> +   case nir_op_bany_fnequal3: alu->op = nir_op_fany_nequal3; break;
> +   case nir_op_bany_fnequal4: alu->op = nir_op_fany_nequal4; break;
> +   case nir_op_ball_iequal2:  alu->op = nir_op_fall_equal2; break;
> +   case nir_op_ball_iequal3:  alu->op = nir_op_fall_equal3; break;
> +   case nir_op_ball_iequal4:  alu->op = nir_op_fall_equal4; break;
> +   case nir_op_bany_inequal2: alu->op = nir_op_fany_nequal2; break;
> +   case nir_op_bany_inequal3: alu->op = nir_op_fany_nequal3; break;
> +   case nir_op_bany_inequal4: alu->op = nir_op_fany_nequal4; break;
> +
> +   case nir_op_bcsel: alu->op = nir_op_fcsel; break;
> +
> +   default:
> +  assert(alu->dest.dest.ssa.bit_size > 1);
> +  for (unsigned i = 0; i < op_info->num_inputs; i++)
> + assert(alu->src[i].src.ssa->bit_size > 1);
> +  return false;
> +   }
> +
> +   if (alu->dest.dest.ssa.bit_size == 1)
> +  alu->dest.dest.ssa.bit_size = 32;
> +
> +   return true;
> +}
> +
> +static bool
> +nir_lower_bool_to_float_impl(nir_function_impl *impl)
> +{
> +   bool progress = false;
> +
> +   nir_foreach_block(block, impl) {
> +  nir_foreach_instr_safe(instr, block) {
> + switch (instr->type) {
> + case nir_instr_type_alu:
> +progress |= lower_alu_instr(nir_instr_as_alu(instr));
> +break;
> +
> + case nir_instr_type_load_const: {
> +nir_load_const_instr *load = nir_instr_as_load_const(instr);
> +if (load->def.bit_size == 1) {
> +   nir_const_value value = load->value;
> +   for (unsigned i = 0; i < load->def.num_components; i++)
> +  load->value.f32[i] = value.b[i] ? 1.0f : 0.0f;
> +   load->def.bit_size = 32;
> +   progress = true;
> +}
> +break;
> + }
> +
> + case nir_instr_type_intrinsic:
> + case nir_instr_type_ssa_undef:
> + case nir_instr_type_phi:
> + case nir_instr_type_tex:
> +nir_foreach_ssa_def(instr, rewrite_1bit_ssa_def_to_32bit,
> +);
> +break;
> +
> + default:
> +nir_foreach_ssa_def(instr, assert_ssa_def_is_not_1bit, NULL);
> + }
> +  }
> +   }
> +
> +   if (progress) {
> +  nir_metadata_preserve(impl, nir_metadata_block_index |
> +  nir_metadata_dominance);
> +   }
> +
> +   return progress;
> +}
> +
> +bool
> +nir_lower_bool_to_float(nir_shader *shader)
> +{
> +   bool progress = false;
> +
> +   nir_foreach_function(function, shader) {
> +  if (function->impl && nir_lower_bool_to_float_impl(function->impl))
> + progress = true;
> +   }
> +
> +   return progress;
> +}
> --
> 2.17.1
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev



-- 
greets
--
Christian Gmeiner, MSc

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


Re: [Mesa-dev] [PATCH] etnaviv: Consolidate buffer references from framebuffers

2018-12-17 Thread Christian Gmeiner
Am Mo., 17. Dez. 2018 um 09:56 Uhr schrieb Tomeu Vizoso
:
>
> We were leaking surfaces because the references taken in
> etna_set_framebuffer_state weren't being released on context destroy.
>
> Instead of just directly releasing those references in
> etna_context_destroy, use the util_copy_framebuffer_state helper.
>
> Take the chance to remove the duplicated buffer references in
> compiled_framebuffer_state to avoid confusion.
>
> The leak can be reproduced with a client that continuously creates and
> destroys contexts.
>
> Signed-off-by: Tomeu Vizoso 
> Reported-by: Sjoerd Simons 

Reviewed-by: Christian Gmeiner 

> ---
>  src/gallium/drivers/etnaviv/etnaviv_context.c  | 10 ++
>  src/gallium/drivers/etnaviv/etnaviv_internal.h |  1 -
>  src/gallium/drivers/etnaviv/etnaviv_state.c|  8 +++-
>  3 files changed, 9 insertions(+), 10 deletions(-)
>
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.c 
> b/src/gallium/drivers/etnaviv/etnaviv_context.c
> index 96cf2f3b59a8..2ecbc7449094 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_context.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_context.c
> @@ -60,6 +60,8 @@ etna_context_destroy(struct pipe_context *pctx)
>  {
> struct etna_context *ctx = etna_context(pctx);
>
> +   util_copy_framebuffer_state(>framebuffer_s, NULL);
> +
> if (ctx->primconvert)
>util_primconvert_destroy(ctx->primconvert);
>
> @@ -299,10 +301,10 @@ etna_draw_vbo(struct pipe_context *pctx, const struct 
> pipe_draw_info *info)
> if (DBG_ENABLED(ETNA_DBG_FLUSH_ALL))
>pctx->flush(pctx, NULL, 0);
>
> -   if (ctx->framebuffer.cbuf)
> -  etna_resource(ctx->framebuffer.cbuf->texture)->seqno++;
> -   if (ctx->framebuffer.zsbuf)
> -  etna_resource(ctx->framebuffer.zsbuf->texture)->seqno++;
> +   if (ctx->framebuffer_s.cbufs[0])
> +  etna_resource(ctx->framebuffer_s.cbufs[0]->texture)->seqno++;
> +   if (ctx->framebuffer_s.zsbuf)
> +  etna_resource(ctx->framebuffer_s.zsbuf->texture)->seqno++;
> if (info->index_size && indexbuf != info->index.resource)
>pipe_resource_reference(, NULL);
>  }
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_internal.h 
> b/src/gallium/drivers/etnaviv/etnaviv_internal.h
> index 3424d8a77153..77214d9ccba1 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_internal.h
> +++ b/src/gallium/drivers/etnaviv/etnaviv_internal.h
> @@ -182,7 +182,6 @@ struct compiled_viewport_state {
>
>  /* Compiled pipe_framebuffer_state */
>  struct compiled_framebuffer_state {
> -   struct pipe_surface *cbuf, *zsbuf; /* keep reference to surfaces */
> uint32_t GL_MULTI_SAMPLE_CONFIG;
> uint32_t PE_COLOR_FORMAT;
> uint32_t PE_DEPTH_CONFIG;
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_state.c 
> b/src/gallium/drivers/etnaviv/etnaviv_state.c
> index 87ba10b0dc98..520cc5a775fc 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_state.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_state.c
> @@ -37,6 +37,7 @@
>  #include "etnaviv_surface.h"
>  #include "etnaviv_translate.h"
>  #include "etnaviv_util.h"
> +#include "util/u_framebuffer.h"
>  #include "util/u_helpers.h"
>  #include "util/u_inlines.h"
>  #include "util/u_math.h"
> @@ -130,7 +131,6 @@ etna_set_framebuffer_state(struct pipe_context *pctx,
>assert(res->layout & ETNA_LAYOUT_BIT_TILE); /* Cannot render to linear 
> surfaces */
>etna_update_render_resource(pctx, cbuf->base.texture);
>
> -  pipe_surface_reference(>cbuf, >base);
>cs->PE_COLOR_FORMAT =
>   VIVS_PE_COLOR_FORMAT_FORMAT(translate_rs_format(cbuf->base.format)) 
> |
>   VIVS_PE_COLOR_FORMAT_COMPONENTS__MASK |
> @@ -182,7 +182,6 @@ etna_set_framebuffer_state(struct pipe_context *pctx,
>
>nr_samples_color = cbuf->base.texture->nr_samples;
> } else {
> -  pipe_surface_reference(>cbuf, NULL);
>/* Clearing VIVS_PE_COLOR_FORMAT_COMPONENTS__MASK and
> * VIVS_PE_COLOR_FORMAT_OVERWRITE prevents us from overwriting the
> * color target */
> @@ -201,7 +200,6 @@ etna_set_framebuffer_state(struct pipe_context *pctx,
>
>etna_update_render_resource(pctx, zsbuf->base.texture);
>
> -  pipe_surface_reference(>zsbuf, >base);
>assert(res->layout _LAYOUT_BIT_TILE); /* Cannot render to linear 
> surfaces */
>
>uint32_t depth_format = translate_depth_format(zsbuf->base.format);
> @@ -252,7 +250,6 @@ etna_set_framebuffer_state(struct pipe_context *pctx,
>
>nr_samples_depth = zsbuf-

Re: [Mesa-dev] [PATCH] meson: make it possible to build etnaviv's cmdline compiler

2018-12-15 Thread Christian Gmeiner
Hi Dylan

Am Fr., 14. Dez. 2018 um 20:13 Uhr schrieb Dylan Baker :
>
> Quoting Christian Gmeiner (2018-12-13 12:07:23)
> > Signed-off-by: Christian Gmeiner 
> > ---
> >  meson.build | 2 +-
> >  meson_options.txt   | 2 +-
> >  src/gallium/drivers/etnaviv/meson.build | 3 ++-
> >  3 files changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/meson.build b/meson.build
> > index fe647f682c..f516780115 100644
> > --- a/meson.build
> > +++ b/meson.build
> > @@ -57,7 +57,7 @@ with_osmesa = get_option('osmesa')
> >  with_swr_arches = get_option('swr-arches')
> >  with_tools = get_option('tools')
> >  if with_tools.contains('all')
> > -  with_tools = ['freedreno', 'glsl', 'intel', 'nir', 'nouveau', 'xvmc']
> > +  with_tools = ['etnaviv', 'freedreno', 'glsl', 'intel', 'nir', 'nouveau', 
> > 'xvmc']
> >  endif
> >
> >  dri_drivers_path = get_option('dri-drivers-path')
> > diff --git a/meson_options.txt b/meson_options.txt
> > index a1d5ab0e18..005356b14c 100644
> > --- a/meson_options.txt
> > +++ b/meson_options.txt
> > @@ -301,7 +301,7 @@ option(
> >'tools',
> >type : 'array',
> >value : [],
> > -  choices : ['freedreno', 'glsl', 'intel', 'intel-ui', 'nir', 'nouveau', 
> > 'xvmc', 'all'],
> > +  choices : ['etnaviv', 'freedreno', 'glsl', 'intel', 'intel-ui', 'nir', 
> > 'nouveau', 'xvmc', 'all'],
> >description : 'List of tools to build. (Note: `intel-ui` selects 
> > `intel`)',
> >  )
> >  option(
> > diff --git a/src/gallium/drivers/etnaviv/meson.build 
> > b/src/gallium/drivers/etnaviv/meson.build
> > index 1733024ac9..63553dec51 100644
> > --- a/src/gallium/drivers/etnaviv/meson.build
> > +++ b/src/gallium/drivers/etnaviv/meson.build
> > @@ -101,7 +101,8 @@ etnaviv_compiler = executable(
> >include_directories : [inc_include, inc_src, inc_gallium, 
> > inc_gallium_aux],
> >link_with : [libmesa_util, libgallium, libetnaviv],
> >dependencies : [dep_libdrm_etnaviv],
> > -  build_by_default : false,
> > +  build_by_default : with_tools.contains('etnaviv'),
> > +  install : with_tools.contains('etnaviv'),
> >  )
> >
> >  driver_etnaviv = declare_dependency(
> > --
> > 2.19.2
> >
>
> You technically can build it already, `ninja
> src/gallium/drivers/etnaviv/etnaviv_compiler` should do the trick. This patch 
> is
> obviously simpler and easier to use, and is in line with how other tools in 
> mesa
> work, but can we change the commit message to something like:
>
> meson: add etnaviv to the tools option
>
> Or something similar.
>

Sounds fine to me. Btw thanks for the meson trick - I was not aware of it.

> with that:
> Reviewed-by: Dylan Baker 


-- 
greets
--
Christian Gmeiner, MSc

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


[Mesa-dev] [PATCH] meson: make it possible to build etnaviv's cmdline compiler

2018-12-13 Thread Christian Gmeiner
Signed-off-by: Christian Gmeiner 
---
 meson.build | 2 +-
 meson_options.txt   | 2 +-
 src/gallium/drivers/etnaviv/meson.build | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/meson.build b/meson.build
index fe647f682c..f516780115 100644
--- a/meson.build
+++ b/meson.build
@@ -57,7 +57,7 @@ with_osmesa = get_option('osmesa')
 with_swr_arches = get_option('swr-arches')
 with_tools = get_option('tools')
 if with_tools.contains('all')
-  with_tools = ['freedreno', 'glsl', 'intel', 'nir', 'nouveau', 'xvmc']
+  with_tools = ['etnaviv', 'freedreno', 'glsl', 'intel', 'nir', 'nouveau', 
'xvmc']
 endif
 
 dri_drivers_path = get_option('dri-drivers-path')
diff --git a/meson_options.txt b/meson_options.txt
index a1d5ab0e18..005356b14c 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -301,7 +301,7 @@ option(
   'tools',
   type : 'array',
   value : [],
-  choices : ['freedreno', 'glsl', 'intel', 'intel-ui', 'nir', 'nouveau', 
'xvmc', 'all'],
+  choices : ['etnaviv', 'freedreno', 'glsl', 'intel', 'intel-ui', 'nir', 
'nouveau', 'xvmc', 'all'],
   description : 'List of tools to build. (Note: `intel-ui` selects `intel`)',
 )
 option(
diff --git a/src/gallium/drivers/etnaviv/meson.build 
b/src/gallium/drivers/etnaviv/meson.build
index 1733024ac9..63553dec51 100644
--- a/src/gallium/drivers/etnaviv/meson.build
+++ b/src/gallium/drivers/etnaviv/meson.build
@@ -101,7 +101,8 @@ etnaviv_compiler = executable(
   include_directories : [inc_include, inc_src, inc_gallium, inc_gallium_aux],
   link_with : [libmesa_util, libgallium, libetnaviv],
   dependencies : [dep_libdrm_etnaviv],
-  build_by_default : false,
+  build_by_default : with_tools.contains('etnaviv'),
+  install : with_tools.contains('etnaviv'),
 )
 
 driver_etnaviv = declare_dependency(
-- 
2.19.2

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


[Mesa-dev] [PATCH] etnaviv: drop redundant ctx function parameter

2018-12-12 Thread Christian Gmeiner
There is no need to have an extra ctx paramter as all the other
parameters carry all the needed information.

Signed-off-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_shader.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_shader.c 
b/src/gallium/drivers/etnaviv/etnaviv_shader.c
index 27c735b83b..d2d736bdee 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_shader.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_shader.c
@@ -230,8 +230,7 @@ etna_shader_link(struct etna_context *ctx)
 }
 
 static bool
-etna_shader_update_vs_inputs(struct etna_context *ctx,
- struct compiled_shader_state *cs,
+etna_shader_update_vs_inputs(struct compiled_shader_state *cs,
  const struct etna_shader_variant *vs,
  const struct compiled_vertex_elements_state *ves)
 {
@@ -246,7 +245,7 @@ etna_shader_update_vs_inputs(struct etna_context *ctx,
num_vs_inputs = MAX2(ves->num_elements, vs->infile.num_reg);
if (num_vs_inputs != ves->num_elements) {
   BUG("Number of elements %u does not match the number of VS inputs %zu",
-  ctx->vertex_elements->num_elements, ctx->shader.vs->infile.num_reg);
+  ves->num_elements, vs->infile.num_reg);
   return false;
}
 
@@ -312,7 +311,7 @@ dump_shader_info(struct etna_shader_variant *v, struct 
pipe_debug_callback *debu
 bool
 etna_shader_update_vertex(struct etna_context *ctx)
 {
-   return etna_shader_update_vs_inputs(ctx, >shader_state, ctx->shader.vs,
+   return etna_shader_update_vs_inputs(>shader_state, ctx->shader.vs,
ctx->vertex_elements);
 }
 
-- 
2.19.2

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


Re: [Mesa-dev] [RFC PATCH 0/5] last call for autotools (meson travis fixes)

2018-12-12 Thread Christian Gmeiner
Am Mi., 12. Dez. 2018 um 09:44 Uhr schrieb Samuel Pitoiset
:
>
> What's the point of maintaining Travis? Shouldn't we just drop it in
> favour of Gitlab CI? IIRC, Igalia worked on it.
>

Until Gitlab CI is ready for public use I like the idea that my wip
mesa branches @github run through
Travis CI. I helped me to find missing parts in makefiles etc.

-- 
greets
--
Christian Gmeiner, MSc

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


Re: [Mesa-dev] [PATCH 1/3] nir: add fceil lowering

2018-11-19 Thread Christian Gmeiner
Am Mo., 19. Nov. 2018 um 21:17 Uhr schrieb Jonathan marek :
>
> I don't have push rights, but robclark added this patch to his staging
> branch so I imagine he will push it soon.
>

Great..

> On 11/19/2018 03:15 PM, Christian Gmeiner wrote:
> > Am Mo., 12. Nov. 2018 um 19:17 Uhr schrieb Jonathan Marek 
> > :
> >>
> >> lowers ceil(x) as -floor(-x)
> >>
> >> Signed-off-by: Jonathan Marek 
> >
> > Do you have push rights? As I am interested in this one I would push
> > it for you if needed.
> >



-- 
greets
--
Christian Gmeiner, MSc

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


Re: [Mesa-dev] [PATCH 1/3] nir: add fceil lowering

2018-11-19 Thread Christian Gmeiner
Am Mo., 12. Nov. 2018 um 19:17 Uhr schrieb Jonathan Marek :
>
> lowers ceil(x) as -floor(-x)
>
> Signed-off-by: Jonathan Marek 

Do you have push rights? As I am interested in this one I would push
it for you if needed.

-- 
greets
--
Christian Gmeiner, MSc

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


  1   2   3   4   5   >