Re: [Mesa-dev] [PATCH] mesa gallium: use compute shaders for vaapi blit

2019-04-03 Thread Marek Olšák
On Wed, Apr 3, 2019 at 9:57 AM Ilia Mirkin  wrote:

> On Wed, Apr 3, 2019 at 9:36 AM Marek Olšák  wrote:
> >
> > On Wed, Apr 3, 2019 at 9:06 AM Ilia Mirkin  wrote:
> >>
> >> On Wed, Apr 3, 2019 at 8:38 AM Marek Olšák  wrote:
> >> >
> >> > On Tue, Apr 2, 2019 at 2:14 PM Eric Anholt  wrote:
> >> >>
> >> >> Ilia Mirkin  writes:
> >> >>
> >> >> > Shouldn't this sort of decision be left up to the driver? If the
> >> >> > driver would like to use CS for blits, fine, but why not let it
> blit
> >> >> > in the most optimal way possible and force it to use a compute
> shader?
> >> >>
> >> >> Yeah, commit messages require an explanation of why a change is being
> >> >> made.
> >> >
> >> >
> >> > We plan to create vaapi contexts with PIPE_CONTEXT_COMPUTE_ONLY for
> better GPU multitasking.
> >> >
> >> > RadeonSI uses async compute queues if PIPE_CONTEXT_COMPUTE_ONLY is
> set, so it can't do any graphics stuff, not even blit. (pipe_context::blit
> is NULL)
> >>
> >> Makes sense. Sounds like one of those would be a better condition than
> >> the mere existence of compute support then?
> >
> >
> > Or we can add PIPE_CAP_PREFER_COMPUTE_BLIT as a performance hint.
>
> When would a driver set that, and when would a state tracker respect it?
>
> As I see it, if the driver prefers compute blits, it can just do that
> in its ->blit impl. If the state tracker created a
> PIPE_CONTEXT_COMPUTE_ONLY context, then it can also decide to not use
> ->blit(). I don't see what the CAP adds, but perhaps I'm missing
> something.
>

util_compute_blit was only validated for vaapi. Using it in the driver is
risky. PIPE_CAP_PREFER_COMPUTE_BLIT would be the hint for vaapi.

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

Re: [Mesa-dev] [PATCH] mesa gallium: use compute shaders for vaapi blit

2019-04-03 Thread Ilia Mirkin
On Wed, Apr 3, 2019 at 9:36 AM Marek Olšák  wrote:
>
> On Wed, Apr 3, 2019 at 9:06 AM Ilia Mirkin  wrote:
>>
>> On Wed, Apr 3, 2019 at 8:38 AM Marek Olšák  wrote:
>> >
>> > On Tue, Apr 2, 2019 at 2:14 PM Eric Anholt  wrote:
>> >>
>> >> Ilia Mirkin  writes:
>> >>
>> >> > Shouldn't this sort of decision be left up to the driver? If the
>> >> > driver would like to use CS for blits, fine, but why not let it blit
>> >> > in the most optimal way possible and force it to use a compute shader?
>> >>
>> >> Yeah, commit messages require an explanation of why a change is being
>> >> made.
>> >
>> >
>> > We plan to create vaapi contexts with PIPE_CONTEXT_COMPUTE_ONLY for better 
>> > GPU multitasking.
>> >
>> > RadeonSI uses async compute queues if PIPE_CONTEXT_COMPUTE_ONLY is set, so 
>> > it can't do any graphics stuff, not even blit. (pipe_context::blit is NULL)
>>
>> Makes sense. Sounds like one of those would be a better condition than
>> the mere existence of compute support then?
>
>
> Or we can add PIPE_CAP_PREFER_COMPUTE_BLIT as a performance hint.

When would a driver set that, and when would a state tracker respect it?

As I see it, if the driver prefers compute blits, it can just do that
in its ->blit impl. If the state tracker created a
PIPE_CONTEXT_COMPUTE_ONLY context, then it can also decide to not use
->blit(). I don't see what the CAP adds, but perhaps I'm missing
something.

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

Re: [Mesa-dev] [PATCH] mesa gallium: use compute shaders for vaapi blit

2019-04-03 Thread Marek Olšák
On Wed, Apr 3, 2019 at 9:06 AM Ilia Mirkin  wrote:

> On Wed, Apr 3, 2019 at 8:38 AM Marek Olšák  wrote:
> >
> > On Tue, Apr 2, 2019 at 2:14 PM Eric Anholt  wrote:
> >>
> >> Ilia Mirkin  writes:
> >>
> >> > Shouldn't this sort of decision be left up to the driver? If the
> >> > driver would like to use CS for blits, fine, but why not let it blit
> >> > in the most optimal way possible and force it to use a compute shader?
> >>
> >> Yeah, commit messages require an explanation of why a change is being
> >> made.
> >
> >
> > We plan to create vaapi contexts with PIPE_CONTEXT_COMPUTE_ONLY for
> better GPU multitasking.
> >
> > RadeonSI uses async compute queues if PIPE_CONTEXT_COMPUTE_ONLY is set,
> so it can't do any graphics stuff, not even blit. (pipe_context::blit is
> NULL)
>
> Makes sense. Sounds like one of those would be a better condition than
> the mere existence of compute support then?
>

Or we can add PIPE_CAP_PREFER_COMPUTE_BLIT as a performance hint.

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

Re: [Mesa-dev] [PATCH] mesa gallium: use compute shaders for vaapi blit

2019-04-03 Thread Ilia Mirkin
On Wed, Apr 3, 2019 at 8:38 AM Marek Olšák  wrote:
>
> On Tue, Apr 2, 2019 at 2:14 PM Eric Anholt  wrote:
>>
>> Ilia Mirkin  writes:
>>
>> > Shouldn't this sort of decision be left up to the driver? If the
>> > driver would like to use CS for blits, fine, but why not let it blit
>> > in the most optimal way possible and force it to use a compute shader?
>>
>> Yeah, commit messages require an explanation of why a change is being
>> made.
>
>
> We plan to create vaapi contexts with PIPE_CONTEXT_COMPUTE_ONLY for better 
> GPU multitasking.
>
> RadeonSI uses async compute queues if PIPE_CONTEXT_COMPUTE_ONLY is set, so it 
> can't do any graphics stuff, not even blit. (pipe_context::blit is NULL)

Makes sense. Sounds like one of those would be a better condition than
the mere existence of compute support then?

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

Re: [Mesa-dev] [PATCH] mesa gallium: use compute shaders for vaapi blit

2019-04-03 Thread Marek Olšák
On Tue, Apr 2, 2019 at 2:14 PM Eric Anholt  wrote:

> Ilia Mirkin  writes:
>
> > Shouldn't this sort of decision be left up to the driver? If the
> > driver would like to use CS for blits, fine, but why not let it blit
> > in the most optimal way possible and force it to use a compute shader?
>
> Yeah, commit messages require an explanation of why a change is being
> made.
>

We plan to create vaapi contexts with PIPE_CONTEXT_COMPUTE_ONLY for better
GPU multitasking.

RadeonSI uses async compute queues if PIPE_CONTEXT_COMPUTE_ONLY is set, so
it can't do any graphics stuff, not even blit. (pipe_context::blit is NULL)

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

Re: [Mesa-dev] [PATCH] mesa gallium: use compute shaders for vaapi blit

2019-04-02 Thread Eric Anholt
Ilia Mirkin  writes:

> Shouldn't this sort of decision be left up to the driver? If the
> driver would like to use CS for blits, fine, but why not let it blit
> in the most optimal way possible and force it to use a compute shader?

Yeah, commit messages require an explanation of why a change is being
made.


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

Re: [Mesa-dev] [PATCH] mesa gallium: use compute shaders for vaapi blit

2019-04-02 Thread Ilia Mirkin
Shouldn't this sort of decision be left up to the driver? If the
driver would like to use CS for blits, fine, but why not let it blit
in the most optimal way possible and force it to use a compute shader?

On Tue, Apr 2, 2019 at 1:44 PM Jiang, Sonny  wrote:
>
> Signed-off-by: Sonny Jiang 
> ---
>  src/gallium/auxiliary/Makefile.sources |   2 +
>  src/gallium/auxiliary/util/u_compute.c | 165 +
>  src/gallium/auxiliary/util/u_compute.h |  44 ++
>  src/gallium/state_trackers/va/context.c|   2 +
>  src/gallium/state_trackers/va/postproc.c   |   6 +-
>  src/gallium/state_trackers/va/va_private.h |   1 +
>  6 files changed, 219 insertions(+), 1 deletion(-)
>  create mode 100644 src/gallium/auxiliary/util/u_compute.c
>  create mode 100644 src/gallium/auxiliary/util/u_compute.h
>
> diff --git a/src/gallium/auxiliary/Makefile.sources 
> b/src/gallium/auxiliary/Makefile.sources
> index 02cc5df70a7..6f5266fe273 100644
> --- a/src/gallium/auxiliary/Makefile.sources
> +++ b/src/gallium/auxiliary/Makefile.sources
> @@ -218,6 +218,8 @@ C_SOURCES := \
> util/u_box.h \
> util/u_cache.c \
> util/u_cache.h \
> +   util/u_compute.c \
> +   util/u_compute.h \
> util/u_debug_gallium.h \
> util/u_debug_gallium.c \
> util/u_debug_describe.c \
> diff --git a/src/gallium/auxiliary/util/u_compute.c 
> b/src/gallium/auxiliary/util/u_compute.c
> new file mode 100644
> index 000..e2e39227206
> --- /dev/null
> +++ b/src/gallium/auxiliary/util/u_compute.c
> @@ -0,0 +1,165 @@
> +/**
> + *
> + * Copyright 2019 Sonny Jiang 
> + * Copyright 2019 Advanced Micro Devices, Inc.
> + * All Rights Reserved.
> + *
> + * 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 VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
> + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> + *
> + **/
> +
> +#include "pipe/p_context.h"
> +#include "pipe/p_state.h"
> +
> +#include "u_bitcast.h"
> +#include "u_format.h"
> +#include "u_sampler.h"
> +#include "tgsi/tgsi_text.h"
> +#include "tgsi/tgsi_ureg.h"
> +#include "u_inlines.h"
> +
> +void *blit_compute_shader(struct pipe_context *ctx)
> +{
> +   static const char text[] =
> +   "COMP\n"
> +   "PROPERTY CS_FIXED_BLOCK_WIDTH 64\n"
> +   "PROPERTY CS_FIXED_BLOCK_HEIGHT 1\n"
> +   "PROPERTY CS_FIXED_BLOCK_DEPTH 1\n"
> +   "DCL SV[0], THREAD_ID\n"
> +   "DCL SV[1], BLOCK_ID\n"
> +   "DCL IMAGE[0], 2D_ARRAY, PIPE_FORMAT_R32G32B32A32_FLOAT, WR\n"
> +   "DCL SAMP[0]\n"
> +   "DCL SVIEW[0], 2D_ARRAY, FLOAT\n"
> +   "DCL CONST[0][0..2]\n" // 0:xyzw 1:xyzw
> +   "DCL TEMP[0..4], LOCAL\n"
> +   "IMM[0] UINT32 {64, 1, 0, 0}\n"
> +
> +   "UMAD TEMP[0].xyz, SV[1].xyzz, IMM[0].xyyy, SV[0].xyzz\n"
> +   "U2F TEMP[1].xyz, TEMP[0]\n"
> +   "MAD TEMP[2].xyz, TEMP[1], CONST[0][1], CONST[0][0]\n"
> +   "TEX_LZ TEMP[3], TEMP[2], SAMP[0], 2D_ARRAY\n"
> +   "UADD TEMP[4].xyz, TEMP[0], CONST[0][2]\n"
> +   "STORE IMAGE[0], TEMP[4], TEMP[3], 2D_ARRAY, 
> PIPE_FORMAT_R32G32B32A32_FLOAT\n"
> +   "END\n";
> +
> +   struct tgsi_token tokens[1024];
> +   struct pipe_compute_state state = {0};
> +
> +   if (!tgsi_text_translate(text, tokens, ARRAY_SIZE(tokens))) {
> +   assert(false);
> +   return NULL;
> +   }
> +
> +   state.ir_type = PIPE_SHADER_IR_TGSI;
> +   state.prog = tokens;
> +
> +   return ctx->create_compute_state(ctx, );
> +}
> +
> +void util_compute_blit(struct pipe_context *ctx, struct pipe_blit_info 
> *blit_info,
> +  void **compute_state)
> +{
> +   if (blit_info->src.box.width == 0 || 

[Mesa-dev] [PATCH] mesa gallium: use compute shaders for vaapi blit

2019-04-02 Thread Jiang, Sonny
Signed-off-by: Sonny Jiang 
---
 src/gallium/auxiliary/Makefile.sources |   2 +
 src/gallium/auxiliary/util/u_compute.c | 165 +
 src/gallium/auxiliary/util/u_compute.h |  44 ++
 src/gallium/state_trackers/va/context.c|   2 +
 src/gallium/state_trackers/va/postproc.c   |   6 +-
 src/gallium/state_trackers/va/va_private.h |   1 +
 6 files changed, 219 insertions(+), 1 deletion(-)
 create mode 100644 src/gallium/auxiliary/util/u_compute.c
 create mode 100644 src/gallium/auxiliary/util/u_compute.h

diff --git a/src/gallium/auxiliary/Makefile.sources 
b/src/gallium/auxiliary/Makefile.sources
index 02cc5df70a7..6f5266fe273 100644
--- a/src/gallium/auxiliary/Makefile.sources
+++ b/src/gallium/auxiliary/Makefile.sources
@@ -218,6 +218,8 @@ C_SOURCES := \
util/u_box.h \
util/u_cache.c \
util/u_cache.h \
+   util/u_compute.c \
+   util/u_compute.h \
util/u_debug_gallium.h \
util/u_debug_gallium.c \
util/u_debug_describe.c \
diff --git a/src/gallium/auxiliary/util/u_compute.c 
b/src/gallium/auxiliary/util/u_compute.c
new file mode 100644
index 000..e2e39227206
--- /dev/null
+++ b/src/gallium/auxiliary/util/u_compute.c
@@ -0,0 +1,165 @@
+/**
+ *
+ * Copyright 2019 Sonny Jiang 
+ * Copyright 2019 Advanced Micro Devices, Inc.
+ * All Rights Reserved.
+ *
+ * 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 VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **/
+
+#include "pipe/p_context.h"
+#include "pipe/p_state.h"
+
+#include "u_bitcast.h"
+#include "u_format.h"
+#include "u_sampler.h"
+#include "tgsi/tgsi_text.h"
+#include "tgsi/tgsi_ureg.h"
+#include "u_inlines.h"
+
+void *blit_compute_shader(struct pipe_context *ctx)
+{
+   static const char text[] =
+   "COMP\n"
+   "PROPERTY CS_FIXED_BLOCK_WIDTH 64\n"
+   "PROPERTY CS_FIXED_BLOCK_HEIGHT 1\n"
+   "PROPERTY CS_FIXED_BLOCK_DEPTH 1\n"
+   "DCL SV[0], THREAD_ID\n"
+   "DCL SV[1], BLOCK_ID\n"
+   "DCL IMAGE[0], 2D_ARRAY, PIPE_FORMAT_R32G32B32A32_FLOAT, WR\n"
+   "DCL SAMP[0]\n"
+   "DCL SVIEW[0], 2D_ARRAY, FLOAT\n"
+   "DCL CONST[0][0..2]\n" // 0:xyzw 1:xyzw
+   "DCL TEMP[0..4], LOCAL\n"
+   "IMM[0] UINT32 {64, 1, 0, 0}\n"
+
+   "UMAD TEMP[0].xyz, SV[1].xyzz, IMM[0].xyyy, SV[0].xyzz\n"
+   "U2F TEMP[1].xyz, TEMP[0]\n"
+   "MAD TEMP[2].xyz, TEMP[1], CONST[0][1], CONST[0][0]\n"
+   "TEX_LZ TEMP[3], TEMP[2], SAMP[0], 2D_ARRAY\n"
+   "UADD TEMP[4].xyz, TEMP[0], CONST[0][2]\n"
+   "STORE IMAGE[0], TEMP[4], TEMP[3], 2D_ARRAY, 
PIPE_FORMAT_R32G32B32A32_FLOAT\n"
+   "END\n";
+
+   struct tgsi_token tokens[1024];
+   struct pipe_compute_state state = {0};
+
+   if (!tgsi_text_translate(text, tokens, ARRAY_SIZE(tokens))) {
+   assert(false);
+   return NULL;
+   }
+
+   state.ir_type = PIPE_SHADER_IR_TGSI;
+   state.prog = tokens;
+
+   return ctx->create_compute_state(ctx, );
+}
+
+void util_compute_blit(struct pipe_context *ctx, struct pipe_blit_info 
*blit_info,
+  void **compute_state)
+{
+   if (blit_info->src.box.width == 0 || blit_info->src.box.height == 0 ||
+   blit_info->dst.box.width == 0 || blit_info->dst.box.height == 0)
+   return;
+
+   struct pipe_resource *src = blit_info->src.resource;
+   struct pipe_resource *dst = blit_info->dst.resource;
+   struct pipe_sampler_view src_templ = {0}, *src_view;
+   void *sampler_state_p;
+   unsigned width = blit_info->dst.box.width;
+   unsigned height = blit_info->dst.box.height;
+   float x_scale =