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 1/4] etnaviv: implement ETC2 block patching for HALTI0

2019-02-27 Thread 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?

Other than that:

Acked-by: Lucas Stach 

Regards,
Lucas


> +   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 

[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, punchthrough_alpha))
+util_dynarray_append(offsets, unsigned, src + offset - base);
+
+ src += bs;
+  }
+
+