Re: [Mesa-dev] [PATCH v7 4/5] st/dri2: Implement DRI2bufferDamageExtension

2019-08-12 Thread Qiang Yu
Looks good for me, patch is:
Reviewed-by: Qiang Yu 

Regards,
Qiang

On Mon, Aug 12, 2019 at 6:07 PM Boris Brezillon
 wrote:
>
> From: Daniel Stone 
>
> Add a pipe_screen->set_damage_region() hook to propagate
> set-damage-region requests to the driver, it's then up to the driver to
> decide what to do with this piece of information.
>
> If the hook is left unassigned, the buffer-damage extension is
> considered unsupported.
>
> Signed-off-by: Daniel Stone 
> Signed-off-by: Boris Brezillon 
> Reviewed-by: Alyssa Rosenzweig 
> ---
> Changes in v7:
> * Add a missing FREE() in dri2_set_damage_region() (Reported by Qiang)
>
> Changes in v6:
> * Pass pipe_box objects instead ints
> * Document the set_damage_region() hook
>
> Changes in v5:
> * Add Alyssa's R-b
> ---
>  src/gallium/include/pipe/p_screen.h   | 17 +
>  src/gallium/state_trackers/dri/dri2.c | 35 +++
>  2 files changed, 52 insertions(+)
>
> diff --git a/src/gallium/include/pipe/p_screen.h 
> b/src/gallium/include/pipe/p_screen.h
> index 9bd247722993..cf8e30634838 100644
> --- a/src/gallium/include/pipe/p_screen.h
> +++ b/src/gallium/include/pipe/p_screen.h
> @@ -464,6 +464,23 @@ struct pipe_screen {
> bool (*is_parallel_shader_compilation_finished)(struct pipe_screen 
> *screen,
> void *shader,
> unsigned shader_type);
> +
> +   /**
> +* Set the damage region (called when KHR_partial_update() is invoked).
> +* This function is passed an array of rectangles encoding the damage 
> area.
> +* rects are using the bottom-left origin convention.
> +* nrects = 0 means 'reset the damage region'. What 'reset' implies is HW
> +* specific. For tile-based renderers, the damage extent is typically set
> +* to cover the whole resource with no damage rect (or a 0-size damage
> +* rect). This way, the existing resource content is reloaded into the
> +* local tile buffer for every tile thus making partial tile update
> +* possible. For HW operating in immediate mode, this reset operation is
> +* likely to be a NOOP.
> +*/
> +   void (*set_damage_region)(struct pipe_screen *screen,
> + struct pipe_resource *resource,
> + unsigned int nrects,
> + const struct pipe_box *rects);
>  };
>
>
> diff --git a/src/gallium/state_trackers/dri/dri2.c 
> b/src/gallium/state_trackers/dri/dri2.c
> index 1ead99ed01b1..22cf4caca8d0 100644
> --- a/src/gallium/state_trackers/dri/dri2.c
> +++ b/src/gallium/state_trackers/dri/dri2.c
> @@ -1680,6 +1680,36 @@ static const __DRI2interopExtension 
> dri2InteropExtension = {
> .export_object = dri2_interop_export_object
>  };
>
> +/**
> + * \brief the DRI2bufferDamageExtension set_damage_region method
> + */
> +static void
> +dri2_set_damage_region(__DRIdrawable *dPriv, unsigned int nrects, int *rects)
> +{
> +   struct dri_drawable *drawable = dri_drawable(dPriv);
> +   struct pipe_resource *resource = 
> drawable->textures[ST_ATTACHMENT_BACK_LEFT];
> +   struct pipe_screen *screen = resource->screen;
> +   struct pipe_box *boxes = NULL;
> +
> +   if (nrects) {
> +  boxes = CALLOC(nrects, sizeof(*boxes));
> +  assert(boxes);
> +
> +  for (unsigned int i = 0; i < nrects; i++) {
> + int *rect = [i * 4];
> +
> + u_box_2d(rect[0], rect[1], rect[2], rect[3], [i]);
> +  }
> +   }
> +
> +   screen->set_damage_region(screen, resource, nrects, boxes);
> +   FREE(boxes);
> +}
> +
> +static __DRI2bufferDamageExtension dri2BufferDamageExtension = {
> +   .base = { __DRI2_BUFFER_DAMAGE, 1 },
> +};
> +
>  /**
>   * \brief the DRI2ConfigQueryExtension configQueryb method
>   */
> @@ -1781,6 +1811,7 @@ static const __DRIextension *dri_screen_extensions[] = {
> ,
> ,
> ,
> +   ,
> ,
> ,
> ,
> @@ -1796,6 +1827,7 @@ static const __DRIextension 
> *dri_robust_screen_extensions[] = {
> ,
> ,
> ,
> +   ,
> ,
> ,
> ,
> @@ -1856,6 +1888,9 @@ dri2_init_screen(__DRIscreen * sPriv)
>}
> }
>
> +   if (pscreen->set_damage_region)
> +  dri2BufferDamageExtension.set_damage_region = dri2_set_damage_region;
> +
> if (pscreen->get_param(pscreen, PIPE_CAP_DEVICE_RESET_STATUS_QUERY)) {
>sPriv->extensions = dri_robust_screen_extensions;
>screen->has_reset_status_query = true;
> --
> 2.21.0
>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH v6 4/5] st/dri2: Implement DRI2bufferDamageExtension

2019-08-06 Thread Qiang Yu
On Thu, Aug 1, 2019 at 8:15 PM Boris Brezillon
 wrote:
>
> +Marek (looks like I forgot to Cc you on this v6 :-/).
>
> On Mon, 22 Jul 2019 09:49:31 +0200
> Boris Brezillon  wrote:
>
> > Hi Qiang,
> >
> > On Sun, 21 Jul 2019 17:02:54 +0800
> > Qiang Yu  wrote:
> >
> > > On Mon, Jul 15, 2019 at 8:50 PM Boris Brezillon
> > >  wrote:
> > > >
> > > > From: Daniel Stone 
> > > >
> > > > Add a pipe_screen->set_damage_region() hook to propagate
> > > > set-damage-region requests to the driver, it's then up to the driver to
> > > > decide what to do with this piece of information.
> > > >
> > > > If the hook is left unassigned, the buffer-damage extension is
> > > > considered unsupported.
> > > >
> > > > Signed-off-by: Daniel Stone 
> > > > Signed-off-by: Boris Brezillon 
> > > > Reviewed-by: Alyssa Rosenzweig 
> > > > ---
> > > > Hello Qiang,
> > > >
> > > > I intentionally dropped your R-b/T-b on this patch since the
> > > > ->set_damage_region() prototype has changed. Feel free to add it back.
> > > >
> > > > Regards,
> > > >
> > > > Boris
> > > >
> > > > Changes in v6:
> > > > * Pass pipe_box objects instead ints
> > > > * Document the set_damage_region() hook
> > > >
> > > > Changes in v5:
> > > > * Add Alyssa's R-b
> > > > ---
> > > >  src/gallium/include/pipe/p_screen.h   | 17 ++
> > > >  src/gallium/state_trackers/dri/dri2.c | 34 +++
> > > >  2 files changed, 51 insertions(+)
> > > >
> > > > diff --git a/src/gallium/include/pipe/p_screen.h 
> > > > b/src/gallium/include/pipe/p_screen.h
> > > > index 3f9bad470950..11a6aa939124 100644
> > > > --- a/src/gallium/include/pipe/p_screen.h
> > > > +++ b/src/gallium/include/pipe/p_screen.h
> > > > @@ -464,6 +464,23 @@ struct pipe_screen {
> > > > bool (*is_parallel_shader_compilation_finished)(struct pipe_screen 
> > > > *screen,
> > > > void *shader,
> > > > unsigned 
> > > > shader_type);
> > > > +
> > > > +   /**
> > > > +* Set the damage region (called when KHR_partial_update() is 
> > > > invoked).
> > > > +* This function is passed an array of rectangles encoding the 
> > > > damage area.
> > > > +* rects are using the bottom-left origin convention.
> > > > +* nrects = 0 means 'reset the damage region'. What 'reset' implies 
> > > > is HW
> > > > +* specific. For tile-based renderers, the damage extent is 
> > > > typically set
> > > > +* to cover the whole resource with no damage rect (or a 0-size 
> > > > damage
> > > > +* rect). This way, the existing resource content is reloaded into 
> > > > the
> > > > +* local tile buffer for every tile thus making partial tile update
> > > > +* possible. For HW operating in immediate mode, this reset 
> > > > operation is
> > > > +* likely to be a NOOP.
> > > > +*/
> > > > +   void (*set_damage_region)(struct pipe_screen *screen,
> > > > + struct pipe_resource *resource,
> > > > + unsigned int nrects,
> > > > + const struct pipe_box *rects);
> > > >  };
> > > >
> > > >
> > > > diff --git a/src/gallium/state_trackers/dri/dri2.c 
> > > > b/src/gallium/state_trackers/dri/dri2.c
> > > > index 5a7ec878bab0..5273b95cd5fb 100644
> > > > --- a/src/gallium/state_trackers/dri/dri2.c
> > > > +++ b/src/gallium/state_trackers/dri/dri2.c
> > > > @@ -1807,6 +1807,35 @@ static const __DRI2interopExtension 
> > > > dri2InteropExtension = {
> > > > .export_object = dri2_interop_export_object
> > > >  };
> > > >
> > > > +/**
> > > > + * \brief the DRI2bufferDamageExtension set_damage_region method
> > > > + */
> > > > +static void
> > > > +dri2_set_damage_region(__DRIdrawable *dPriv, unsigned int nrects, int 
> > > > *rects)
> > > > +{
> >

Re: [Mesa-dev] [PATCH v6 4/5] st/dri2: Implement DRI2bufferDamageExtension

2019-07-21 Thread Qiang Yu
On Mon, Jul 15, 2019 at 8:50 PM Boris Brezillon
 wrote:
>
> From: Daniel Stone 
>
> Add a pipe_screen->set_damage_region() hook to propagate
> set-damage-region requests to the driver, it's then up to the driver to
> decide what to do with this piece of information.
>
> If the hook is left unassigned, the buffer-damage extension is
> considered unsupported.
>
> Signed-off-by: Daniel Stone 
> Signed-off-by: Boris Brezillon 
> Reviewed-by: Alyssa Rosenzweig 
> ---
> Hello Qiang,
>
> I intentionally dropped your R-b/T-b on this patch since the
> ->set_damage_region() prototype has changed. Feel free to add it back.
>
> Regards,
>
> Boris
>
> Changes in v6:
> * Pass pipe_box objects instead ints
> * Document the set_damage_region() hook
>
> Changes in v5:
> * Add Alyssa's R-b
> ---
>  src/gallium/include/pipe/p_screen.h   | 17 ++
>  src/gallium/state_trackers/dri/dri2.c | 34 +++
>  2 files changed, 51 insertions(+)
>
> diff --git a/src/gallium/include/pipe/p_screen.h 
> b/src/gallium/include/pipe/p_screen.h
> index 3f9bad470950..11a6aa939124 100644
> --- a/src/gallium/include/pipe/p_screen.h
> +++ b/src/gallium/include/pipe/p_screen.h
> @@ -464,6 +464,23 @@ struct pipe_screen {
> bool (*is_parallel_shader_compilation_finished)(struct pipe_screen 
> *screen,
> void *shader,
> unsigned shader_type);
> +
> +   /**
> +* Set the damage region (called when KHR_partial_update() is invoked).
> +* This function is passed an array of rectangles encoding the damage 
> area.
> +* rects are using the bottom-left origin convention.
> +* nrects = 0 means 'reset the damage region'. What 'reset' implies is HW
> +* specific. For tile-based renderers, the damage extent is typically set
> +* to cover the whole resource with no damage rect (or a 0-size damage
> +* rect). This way, the existing resource content is reloaded into the
> +* local tile buffer for every tile thus making partial tile update
> +* possible. For HW operating in immediate mode, this reset operation is
> +* likely to be a NOOP.
> +*/
> +   void (*set_damage_region)(struct pipe_screen *screen,
> + struct pipe_resource *resource,
> + unsigned int nrects,
> + const struct pipe_box *rects);
>  };
>
>
> diff --git a/src/gallium/state_trackers/dri/dri2.c 
> b/src/gallium/state_trackers/dri/dri2.c
> index 5a7ec878bab0..5273b95cd5fb 100644
> --- a/src/gallium/state_trackers/dri/dri2.c
> +++ b/src/gallium/state_trackers/dri/dri2.c
> @@ -1807,6 +1807,35 @@ static const __DRI2interopExtension 
> dri2InteropExtension = {
> .export_object = dri2_interop_export_object
>  };
>
> +/**
> + * \brief the DRI2bufferDamageExtension set_damage_region method
> + */
> +static void
> +dri2_set_damage_region(__DRIdrawable *dPriv, unsigned int nrects, int *rects)
> +{
> +   struct dri_drawable *drawable = dri_drawable(dPriv);
> +   struct pipe_resource *resource = 
> drawable->textures[ST_ATTACHMENT_BACK_LEFT];
> +   struct pipe_screen *screen = resource->screen;
> +   struct pipe_box *boxes = NULL;
> +
> +   if (nrects) {
> +  boxes = CALLOC(nrects, sizeof(*boxes));
> +  assert(boxes);

Where does this boxes array get freed? I can't find in your patch 6 either.
In fact I prefer the v5 way which just uses `int *rects` to avoid unnecessary
conversion.

Regards,
Qiang

> +
> +  for (unsigned int i = 0; i < nrects; i++) {
> + int *rect = [i * 4];
> +
> + u_box_2d(rect[0], rect[1], rect[2], rect[3], [i]);
> +  }
> +   }
> +
> +   screen->set_damage_region(screen, resource, nrects, boxes);
> +}
> +
> +static __DRI2bufferDamageExtension dri2BufferDamageExtension = {
> +   .base = { __DRI2_BUFFER_DAMAGE, 1 },
> +};
> +
>  /**
>   * \brief the DRI2ConfigQueryExtension configQueryb method
>   */
> @@ -1908,6 +1937,7 @@ static const __DRIextension *dri_screen_extensions[] = {
> ,
> ,
> ,
> +   ,
> ,
> ,
> ,
> @@ -1923,6 +1953,7 @@ static const __DRIextension 
> *dri_robust_screen_extensions[] = {
> ,
> ,
> ,
> +   ,
> ,
> ,
> ,
> @@ -1983,6 +2014,9 @@ dri2_init_screen(__DRIscreen * sPriv)
>}
> }
>
> +   if (pscreen->set_damage_region)
> +  dri2BufferDamageExtension.set_damage_region = dri2_set_damage_region;
> +
> if (pscreen->get_param(pscreen, PIPE_CAP_DEVICE_RESET_STATUS_QUERY)) {
>sPriv->extensions = dri_robust_screen_extensions;
>screen->has_reset_status_query = true;
> --
> 2.21.0
>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH v4 0/5] EGL_KHR_partial_update support

2019-06-30 Thread Qiang Yu
Patch 1~4 are:
Reviewed-and-tested-by: Qiang Yu 

I've tested on lima platform with weston master branch including
Daniel's change, works fine for me now.

I'll send out the lima change after this series gets merged.

Thanks,
Qiang

On Wed, Jun 26, 2019 at 12:37 AM Boris Brezillon
 wrote:
>
> This is an attempt at resurrecting Daniel's MR [1] which was already
> resurrecting Harish's EGL_KHR_partial_update series [2]. This version
> implements Marek's suggestion to pass the set_damage_region() directly
> to the gallium driver and let it decide how to handle the request. Some
> drivers might just calculate the damage extent (as done in Daniel's
> initial proposal and in the panfrost implementation), others might do
> extra optimizations like trying to reduce the area we're supposed to
> reload (only valid for tile-based rendering) even further.
>
> This patch series has been tested with weston (see Daniel's MR[3]) on
> panfrost. Note that the panfrost implementation is rather simple (just
> limits the rendering area to the damage extent and picks the biggest
> damage rect as the only damage region) but we can improve it if we feel
> the need.
>
> Any feedback and suggestions on how to do it better are welcome.
>
> Regards,
>
> Boris
>
> [1]https://gitlab.freedesktop.org/mesa/mesa/merge_requests/227
> [2]https://patchwork.freedesktop.org/series/45915/#rev2
> [3]https://gitlab.freedesktop.org/wayland/weston/merge_requests/106
>
> Boris Brezillon (1):
>   panfrost: Add support for KHR_partial_update()
>
> Daniel Stone (2):
>   dri_interface: add DRI2_BufferDamage interface
>   st/dri2: Implement DRI2bufferDamageExtension
>
> Harish Krupo (2):
>   egl/android: Delete set_damage_region from egl dri vtbl
>   egl/dri: Use __DRI2_DAMAGE extension for KHR_partial_update
>
>  include/GL/internal/dri_interface.h | 43 +++
>  src/egl/drivers/dri2/egl_dri2.c | 54 +--
>  src/egl/drivers/dri2/egl_dri2.h |  5 +-
>  src/egl/drivers/dri2/egl_dri2_fallbacks.h   |  9 
>  src/egl/drivers/dri2/platform_android.c | 45 
>  src/egl/drivers/dri2/platform_device.c  |  1 -
>  src/egl/drivers/dri2/platform_drm.c |  1 -
>  src/egl/drivers/dri2/platform_surfaceless.c |  1 -
>  src/egl/drivers/dri2/platform_wayland.c |  1 -
>  src/egl/drivers/dri2/platform_x11.c |  2 -
>  src/egl/drivers/dri2/platform_x11_dri3.c|  1 -
>  src/gallium/drivers/panfrost/pan_blit.c | 14 ++---
>  src/gallium/drivers/panfrost/pan_context.c  | 49 -
>  src/gallium/drivers/panfrost/pan_job.c  | 11 
>  src/gallium/drivers/panfrost/pan_job.h  |  5 ++
>  src/gallium/drivers/panfrost/pan_resource.c | 58 +
>  src/gallium/drivers/panfrost/pan_resource.h | 12 -
>  src/gallium/drivers/panfrost/pan_screen.c   |  1 +
>  src/gallium/include/pipe/p_screen.h |  7 +++
>  src/gallium/state_trackers/dri/dri2.c   | 22 
>  20 files changed, 263 insertions(+), 79 deletions(-)
>
> --
> 2.20.1
>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

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

2019-04-12 Thread Qiang Yu
Patch series are:
Reviewed-by: Qiang Yu 

Regards,
Qiang


On Sat, Apr 13, 2019 at 7:46 AM Alyssa Rosenzweig  wrote:
>
> On Mali hardware (supported by Panfrost and Lima), the fixed-function
> transformation from world-space to screen-space coordinates is done in
> the vertex shader prior to writing out the gl_Position varying, rather
> than in dedicated hardware. This commit adds a shared NIR pass for
> implementing coordinate transformation and lowering gl_Position writes
> into screen-space gl_Position writes.
>
> v2: Run directly on derefs before io/vars are lowered to cleanup the
> code substantially. Thank you to Qiang for this suggestion!
>
> v3: Bikeshed continues.
>
> Signed-off-by: Alyssa Rosenzweig 
> Suggested-by: Qiang Yu 
> Cc: Jason Ekstrand 
> Cc: Eric Anholt 
> ---
>  src/compiler/nir/meson.build  |   1 +
>  src/compiler/nir/nir.h|   1 +
>  .../nir/nir_lower_viewport_transform.c| 101 ++
>  3 files changed, 103 insertions(+)
>  create mode 100644 src/compiler/nir/nir_lower_viewport_transform.c
>
> diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build
> index c65f2ff62ff..c274361bdc4 100644
> --- a/src/compiler/nir/meson.build
> +++ b/src/compiler/nir/meson.build
> @@ -151,6 +151,7 @@ files_libnir = files(
>'nir_lower_vars_to_ssa.c',
>'nir_lower_var_copies.c',
>'nir_lower_vec_to_movs.c',
> +  'nir_lower_viewport_transform.c',
>'nir_lower_wpos_center.c',
>'nir_lower_wpos_ytransform.c',
>'nir_lower_bit_size.c',
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index bc72d8f83f5..0f6ed734efa 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -3124,6 +3124,7 @@ void nir_lower_io_to_scalar(nir_shader *shader, 
> nir_variable_mode mask);
>  void nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode 
> mask);
>  bool nir_lower_io_to_vector(nir_shader *shader, nir_variable_mode mask);
>
> +void nir_lower_viewport_transform(nir_shader *shader);
>  bool nir_lower_uniforms_to_ubo(nir_shader *shader, int multiplier);
>
>  typedef struct nir_lower_subgroups_options {
> diff --git a/src/compiler/nir/nir_lower_viewport_transform.c 
> b/src/compiler/nir/nir_lower_viewport_transform.c
> new file mode 100644
> index 000..66085b8da5a
> --- /dev/null
> +++ b/src/compiler/nir/nir_lower_viewport_transform.c
> @@ -0,0 +1,101 @@
> +/*
> + * Copyright (C) 2019 Alyssa Rosenzweig
> + *
> + * 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.
> + */
> +
> +/* On some hardware (particularly, all current versions of Mali GPUs),
> + * vertex shaders do not output gl_Position in world-space. Instead, they
> + * output gl_Position in transformed screen space via the "pseudo"
> + * position varying. Thus, this pass finds writes to gl_Position and
> + * changes them to transformed 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.s

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

2019-04-08 Thread Qiang Yu
On Mon, Apr 8, 2019 at 12:30 PM Alyssa Rosenzweig  wrote:
>
> On Mali hardware (supported by Panfrost and Lima), the fixed-function
> transformation from world-space to screen-space coordinates is done in
> the vertex shader prior to writing out the gl_Position varying, rather
> than in dedicated hardware. This commit adds a shared NIR pass for
> implementing coordinate transformation and lowering gl_Position writes
> into screen-space gl_Position writes.
>
> v2: Run directly on derefs before io/vars are lowered to cleanup the
> code substantially. Thank you to Qiang for this suggestion!
>
> Signed-off-by: Alyssa Rosenzweig 
> Suggested-by: Qiang Yu 
> Cc: Jason Ekstrand 
> Cc: Eric Anholt 
> ---
>  src/compiler/nir/meson.build  |  1 +
>  src/compiler/nir/nir.h|  1 +
>  .../nir/nir_lower_viewport_transform.c| 98 +++
>  3 files changed, 100 insertions(+)
>  create mode 100644 src/compiler/nir/nir_lower_viewport_transform.c
>
> diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build
> index c65f2ff62ff..c274361bdc4 100644
> --- a/src/compiler/nir/meson.build
> +++ b/src/compiler/nir/meson.build
> @@ -151,6 +151,7 @@ files_libnir = files(
>'nir_lower_vars_to_ssa.c',
>'nir_lower_var_copies.c',
>'nir_lower_vec_to_movs.c',
> +  'nir_lower_viewport_transform.c',
>'nir_lower_wpos_center.c',
>'nir_lower_wpos_ytransform.c',
>'nir_lower_bit_size.c',
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index bc72d8f83f5..0f6ed734efa 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -3124,6 +3124,7 @@ void nir_lower_io_to_scalar(nir_shader *shader, 
> nir_variable_mode mask);
>  void nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode 
> mask);
>  bool nir_lower_io_to_vector(nir_shader *shader, nir_variable_mode mask);
>
> +void nir_lower_viewport_transform(nir_shader *shader);
>  bool nir_lower_uniforms_to_ubo(nir_shader *shader, int multiplier);
>
>  typedef struct nir_lower_subgroups_options {
> diff --git a/src/compiler/nir/nir_lower_viewport_transform.c 
> b/src/compiler/nir/nir_lower_viewport_transform.c
> new file mode 100644
> index 000..9646b72c053
> --- /dev/null
> +++ b/src/compiler/nir/nir_lower_viewport_transform.c
> @@ -0,0 +1,98 @@
> +/*
> + * Copyright (C) 2019 Alyssa Rosenzweig
> + *
> + * 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.
> + */
> +
> +/* On some hardware (particularly, all current versions of Mali GPUs),
> + * vertex shaders do not output gl_Position in world-space. Instead, they
> + * output gl_Position in transformed screen space via the "pseudo"
> + * position varying. Thus, this pass finds writes to gl_Position and
> + * changes them to transformed 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

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

2019-04-07 Thread Qiang Yu
On Mon, Apr 8, 2019 at 12:41 AM Alyssa Rosenzweig  wrote:
>
> On Mali hardware (supported by Panfrost and Lima), the fixed-function
> transformation from world-space to screen-space coordinates is done in
> the vertex shader prior to writing out the gl_Position varying, rather
> than in dedicated hardware. This commit adds a shared NIR pass for
> implementing coordinate transformation and lowering gl_Position writes
> into screen-space gl_Position writes.
>
> Signed-off-by: Alyssa Rosenzweig 
> Suggested-by: Qiang Yu 
> Cc: Jason Ekstrand 
> Cc: Eric Anholt 
> ---
>  src/compiler/nir/meson.build  |   1 +
>  src/compiler/nir/nir.h|   1 +
>  .../nir/nir_lower_viewport_transform.c| 126 ++
>  3 files changed, 128 insertions(+)
>  create mode 100644 src/compiler/nir/nir_lower_viewport_transform.c
>
> diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build
> index c65f2ff62ff..c274361bdc4 100644
> --- a/src/compiler/nir/meson.build
> +++ b/src/compiler/nir/meson.build
> @@ -151,6 +151,7 @@ files_libnir = files(
>'nir_lower_vars_to_ssa.c',
>'nir_lower_var_copies.c',
>'nir_lower_vec_to_movs.c',
> +  'nir_lower_viewport_transform.c',
>'nir_lower_wpos_center.c',
>'nir_lower_wpos_ytransform.c',
>'nir_lower_bit_size.c',
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index bc72d8f83f5..0f6ed734efa 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -3124,6 +3124,7 @@ void nir_lower_io_to_scalar(nir_shader *shader, 
> nir_variable_mode mask);
>  void nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode 
> mask);
>  bool nir_lower_io_to_vector(nir_shader *shader, nir_variable_mode mask);
>
> +void nir_lower_viewport_transform(nir_shader *shader);
>  bool nir_lower_uniforms_to_ubo(nir_shader *shader, int multiplier);
>
>  typedef struct nir_lower_subgroups_options {
> diff --git a/src/compiler/nir/nir_lower_viewport_transform.c 
> b/src/compiler/nir/nir_lower_viewport_transform.c
> new file mode 100644
> index 000..34a248d5871
> --- /dev/null
> +++ b/src/compiler/nir/nir_lower_viewport_transform.c
> @@ -0,0 +1,126 @@
> +/*
> + * Copyright (C) 2019 Alyssa Rosenzweig
> + *
> + * 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.
> + */
> +
> +/* On some hardware (particularly, all current versions of Mali GPUs),
> + * vertex shaders do not output gl_Position in world-space. Instead, they
> + * output gl_Position in transformed screen space via the "pseudo"
> + * position varying. Thus, this pass finds writes to gl_Position and
> + * changes them to transformed 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.
> + */
> +
> +#include "nir/nir.h"
> +#include "nir/nir_builder.h"
> +
> +static void write_transformed_position(nir_builder *b, nir_src
> +  input_point_src)
> +{
> +   nir_ssa_def *input_point = nir_ssa_for_src(b, input_point_src, 4);
> +   nir_ssa_def *scale = nir_load_viewport_scale(b);
> +   nir_ssa_def *offset = nir_load_viewport_offset(b);
> +
> +   /* World space to normalised device coordinates to screen space */
> +
> +   nir_ssa_def *w_recip = nir_frcp(b, nir_channel(b, input_point, 3));
> +   n

Re: [Mesa-dev] [PATCH 0/2] Implement (viewport) system values

2019-04-05 Thread Qiang Yu
On Sat, Apr 6, 2019 at 10:18 AM Alyssa Rosenzweig  wrote:
>
> Hi,
>
> NIR system values are the preferred method of transferring state like
> this around; the shared transformation pass should be agnostic to the
> underlying uniforms / state tracker / etc. Is there any reason we can't
> share the transform as I implement it here? (Which makes no assumptions
> about uniform layout)

I think there're two parts of this stuff
1. sysval uniform update
2. nir transform insert

If we use the sysval, at least 1 is driver spec, 2 can be shared. So could you
move 2 into the nir dir for sharing with lima?

Thanks,
Qiang

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

Re: [Mesa-dev] [PATCH 0/2] Implement (viewport) system values

2019-04-05 Thread Qiang Yu
So you prefer to use the nir sysval method and implement a per driver version
of viewport transform? As I sended out a patch series for a shared version of
this transform, any feedback on it?
https://patchwork.freedesktop.org/series/58618/

Regards,
Qiang

On Wed, Apr 3, 2019 at 9:50 AM Alyssa Rosenzweig  wrote:
>
> This patch set implements the infrastructure for piping system values
> through Panfrost, replacing the prior brittle system of magic uniform
> offsets. This infrastructure is used to implement the vertex shader
> viewport transformation, which will soon be shared with lima.
>
> Alyssa Rosenzweig (2):
>   nir: Add "viewport vector" system values
>   panfrost: Implement system values
>
>  src/compiler/nir/nir_intrinsics.py|   5 +
>  src/gallium/drivers/panfrost/meson.build  |   1 +
>  .../drivers/panfrost/midgard/helpers.h|   4 -
>  .../panfrost/midgard/midgard_compile.c| 272 +-
>  .../panfrost/midgard/midgard_compile.h|  27 +-
>  src/gallium/drivers/panfrost/pan_assemble.c   |   5 +
>  src/gallium/drivers/panfrost/pan_context.c| 103 +++
>  src/gallium/drivers/panfrost/pan_context.h|   5 +
>  8 files changed, 234 insertions(+), 188 deletions(-)
>
> --
> 2.20.1
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH v2 6/8] gallium: add lima driver

2019-03-27 Thread Qiang Yu
V3 driver could be reviewed at:
https://gitlab.freedesktop.org/mesa/mesa/merge_requests/465

Regards,
Qiang

On Tue, Mar 26, 2019 at 2:38 PM Qiang Yu  wrote:
>
> On Tue, Mar 26, 2019 at 11:33 AM Alyssa Rosenzweig  
> wrote:
> >
> > > +   [PPIR_INSTR_SLOT_ALU_VEC_MUL] = ppir_codegen_encode_vec_mul,
> > > +   [PPIR_INSTR_SLOT_ALU_SCL_MUL] = ppir_codegen_encode_scl_mul,
> > > +   [PPIR_INSTR_SLOT_ALU_VEC_ADD] = ppir_codegen_encode_vec_add,
> > > +   [PPIR_INSTR_SLOT_ALU_SCL_ADD] = ppir_codegen_encode_scl_add,
> >
> > vmul/smul/vadd/sadd are the (official?) names for this on Midgard, fwiw.
> >
> > > +static const int ppir_codegen_field_size[] = {
> > > +   34, 62, 41, 43, 30, 44, 31, 30, 41, 73
> > > +};
> >
> > What is this?
> PP instruction field (i.e. vadd part length) length in bit.
>
> >
> > > +static inline int align_to_word(int size)
> > > +{
> > > +   return ((size + 0x1f) >> 5);
> > > +}
> >
> > Maybe use the align() macro (it's in mesa/src/util/) for clarity?
> >
> > > +   ppir_codegen_combine_scalar_op_atan  = 8, /* Arc Tangent Part 1 */
> > > +   ppir_codegen_combine_scalar_op_atan2 = 9, /* Arc Tangent 2 Part 1 */
> >
> > Any plan to use these ops? Midgard has them too, but inverse trig gets
> > lowered away anyway...
> >
> Not yet.
>
> > > +if (node->op == ppir_op_neg)
> > > +   src->negate = !src->negate;
> > > +else if (node->op == ppir_op_abs)
> > > +   src->absolute = true;
> >
> > I'm confused. NIR has neg/abs modifiers natively. You can get all
> > fneg/fabs instructions lowered in NIR to these modifiers via
> > the lower_source_mods pass. If you don't want them, you'll never have
> > neg/abs ops at all; they'll all be modifiers. Why duplicate this in
> > ppir?
>
> Didn't know this pass, I can use it, thanks.
>
> >
> > > +   uint32_t va;
> >
> > I don't know the Utgard MMU, but will this work on 64-bit?
> >
> It's fine as Utgard MMU only support 32bit address.
>
> >
> > > +   uint32_t dubya;
> >
> > ???
> Don't know for me either, just copy from lima-ng.
>
> >
> > > +   uint32_t mrt_bits;
> > > +   uint32_t mrt_pitch;
> >
> > Utgard supports MRT?!
> >
> Utgard can render to 3 FB (WB0~2) in one pass.
>
> >
> > > +   uint32_t width = fui(fb->width);
> > > +   uint32_t height = fui(fb->height);
> > > +   uint32_t reload_gl_pos[] = {
> > > +  width,  0x, 0x, 0x3f80, /* 0x */
> > > +  0x, 0x, 0x, 0x3f80, /* 0x0010 */
> > > +  0x, height, 0x, 0x3f80, /* 0x0020 */
> > > +   };
> > > +   memcpy(cpu + lima_reload_gl_pos_offset, reload_gl_pos,
> > > +  sizeof(reload_gl_pos));
> > > +
> > > +   uint32_t reload_varying[] = {
> > > +  width,  0x, 0x, 0x, /* 0x */
> > > +  0x, height, 0x, 0x, /* 0x0010 */
> > > +   };
> > > +   memcpy(cpu + lima_reload_varying_offset, reload_varying,
> > > +  sizeof(reload_varying));
> > > +
> >
> > Why not actual float arrays?
> >
> Right.
>
> >
> > > +   uint32_t clear_shader[] = {
> > > +  0x00021025, 0x000c,
> > > +  (ctx->clear.color_16pc << 12) | 0x07cf,
> > > +  ctx->clear.color_16pc >> 12,
> > > +  ctx->clear.color_16pc >> 44,
> > > +   };
> >
> > Please don't include shader blobs. This should maybe be generated
> > from NIR, but at minimum, please include the corresponding annotated
> > assembly.
> >
> I think no need to compile this kind of util shader, will add some
> comments about it.
>
> > > +  clear->color_16pc =
> > > + ((uint64_t)float_to_ushort(color->f[3]) << 48) |
> > > + ((uint64_t)float_to_ushort(color->f[2]) << 32) |
> > > + ((uint64_t)float_to_ushort(color->f[1]) << 16) |
> > > + float_to_ubyte(color->f[0]);
> >
> > Should that last line be float_to_ushort?
> >
> Right, will fix it.
>
> >
> > > +enum lima_attrib_type {
> > > +   LIMA_ATTRIB_FLOAT = 0x000,
> > > +   /* todo: find out what lives here. */
> >
> > LIMA_ATTRIB_FP16 maybe.
> > LIMA_ATTRIB_

[Mesa-dev] [PATCH 4/4] mesa/st: do nir_lower_viewport_transform

2019-03-26 Thread Qiang Yu
Do nir_lower_viewport_transform when driver set
PIPE_CAP_NIR_VS_LOWER_VIEWPORT_TRANSFORM in vertex
shader.

Signed-off-by: Qiang Yu 
---
 src/gallium/auxiliary/util/u_screen.c |  3 +++
 src/gallium/include/pipe/p_defines.h  |  1 +
 src/mesa/state_tracker/st_glsl_to_nir.cpp | 23 +++
 src/mesa/state_tracker/st_nir.h   |  4 
 src/mesa/state_tracker/st_program.c   |  1 +
 5 files changed, 32 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_screen.c 
b/src/gallium/auxiliary/util/u_screen.c
index b902c083ad4..c3b8252197f 100644
--- a/src/gallium/auxiliary/util/u_screen.c
+++ b/src/gallium/auxiliary/util/u_screen.c
@@ -344,6 +344,9 @@ u_pipe_screen_get_param_defaults(struct pipe_screen 
*pscreen,
case PIPE_CAP_COMPUTE_GRID_INFO_LAST_BLOCK:
   return 0;
 
+   case PIPE_CAP_NIR_VS_LOWER_VIEWPORT_TRANSFORM:
+  return 0;
+
default:
   unreachable("bad PIPE_CAP_*");
}
diff --git a/src/gallium/include/pipe/p_defines.h 
b/src/gallium/include/pipe/p_defines.h
index ebc44d7a75e..1d6b69453e8 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -864,6 +864,7 @@ enum pipe_cap
PIPE_CAP_NIR_COMPACT_ARRAYS,
PIPE_CAP_MAX_VARYINGS,
PIPE_CAP_COMPUTE_GRID_INFO_LAST_BLOCK,
+   PIPE_CAP_NIR_VS_LOWER_VIEWPORT_TRANSFORM,
 };
 
 /**
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp 
b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index e5d5fe21e27..87e457dccbf 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -738,6 +738,26 @@ st_nir_lower_wpos_ytransform(struct nir_shader *nir,
}
 }
 
+void
+st_nir_lower_viewport_transform(struct nir_shader *nir,
+struct gl_program *prog,
+struct pipe_screen *pscreen)
+{
+   if (nir->info.stage != MESA_SHADER_VERTEX ||
+   !pscreen->get_param(pscreen, PIPE_CAP_NIR_VS_LOWER_VIEWPORT_TRANSFORM))
+  return;
+
+   static const nir_lower_viewport_transform_options viewport_options = {
+  .scale = { STATE_INTERNAL, STATE_VIEWPORT_SCALE },
+  .translate = { STATE_INTERNAL, STATE_VIEWPORT_TRANSLATE },
+   };
+
+   NIR_PASS_V(nir, nir_lower_viewport_transform, _options);
+
+   _mesa_add_state_reference(prog->Parameters, viewport_options.scale);
+   _mesa_add_state_reference(prog->Parameters, viewport_options.translate);
+}
+
 bool
 st_link_nir(struct gl_context *ctx,
 struct gl_shader_program *shader_program)
@@ -793,6 +813,9 @@ st_link_nir(struct gl_context *ctx,
   NIR_PASS_V(nir, st_nir_lower_wpos_ytransform, shader->Program,
  st->pipe->screen);
 
+  NIR_PASS_V(nir, st_nir_lower_viewport_transform, shader->Program,
+ st->pipe->screen);
+
   NIR_PASS_V(nir, nir_lower_system_values);
   NIR_PASS_V(nir, nir_lower_clip_cull_distance_arrays);
 
diff --git a/src/mesa/state_tracker/st_nir.h b/src/mesa/state_tracker/st_nir.h
index 94eae84402e..100ab0f7125 100644
--- a/src/mesa/state_tracker/st_nir.h
+++ b/src/mesa/state_tracker/st_nir.h
@@ -41,6 +41,10 @@ void st_nir_lower_wpos_ytransform(struct nir_shader *nir,
   struct gl_program *prog,
   struct pipe_screen *pscreen);
 
+void st_nir_lower_viewport_transform(struct nir_shader *nir,
+ struct gl_program *prog,
+ struct pipe_screen *pscreen);
+
 void st_finalize_nir(struct st_context *st, struct gl_program *prog,
  struct gl_shader_program *shader_program,
  struct nir_shader *nir);
diff --git a/src/mesa/state_tracker/st_program.c 
b/src/mesa/state_tracker/st_program.c
index 9f6e492d6fb..cf1ae6e65a8 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -442,6 +442,7 @@ st_translate_prog_to_nir(struct st_context *st, struct 
gl_program *prog,
nir_validate_shader(nir, "after st/ptn lower_regs_to_ssa");
 
NIR_PASS_V(nir, st_nir_lower_wpos_ytransform, prog, st->pipe->screen);
+   NIR_PASS_V(nir, st_nir_lower_viewport_transform, prog, st->pipe->screen);
NIR_PASS_V(nir, nir_lower_system_values);
 
/* Optimise NIR */
-- 
2.17.1

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

[Mesa-dev] [PATCH 3/4] nir: add nir_lower_viewport_transform

2019-03-26 Thread Qiang Yu
Signed-off-by: Qiang Yu 
---
 src/compiler/Makefile.sources |   1 +
 src/compiler/nir/meson.build  |   1 +
 src/compiler/nir/nir.h|   8 +
 .../nir/nir_lower_viewport_transform.c| 142 ++
 4 files changed, 152 insertions(+)
 create mode 100644 src/compiler/nir/nir_lower_viewport_transform.c

diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources
index 722cfbb25a8..589a4f92602 100644
--- a/src/compiler/Makefile.sources
+++ b/src/compiler/Makefile.sources
@@ -269,6 +269,7 @@ NIR_FILES = \
nir/nir_lower_vars_to_ssa.c \
nir/nir_lower_var_copies.c \
nir/nir_lower_vec_to_movs.c \
+   nir/nir_lower_viewport_transform.c \
nir/nir_lower_wpos_center.c \
nir/nir_lower_wpos_ytransform.c \
nir/nir_metadata.c \
diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build
index 4f1efb5c6d3..fd6678beb4d 100644
--- a/src/compiler/nir/meson.build
+++ b/src/compiler/nir/meson.build
@@ -149,6 +149,7 @@ files_libnir = files(
   'nir_lower_vars_to_ssa.c',
   'nir_lower_var_copies.c',
   'nir_lower_vec_to_movs.c',
+  'nir_lower_viewport_transform.c',
   'nir_lower_wpos_center.c',
   'nir_lower_wpos_ytransform.c',
   'nir_lower_bit_size.c',
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 1da9874060b..688d006b646 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -3273,6 +3273,14 @@ bool nir_lower_wpos_ytransform(nir_shader *shader,
const nir_lower_wpos_ytransform_options 
*options);
 bool nir_lower_wpos_center(nir_shader *shader, const bool for_sample_shading);
 
+typedef struct nir_lower_viewport_transform_options {
+   gl_state_index16 scale[STATE_LENGTH];
+   gl_state_index16 translate[STATE_LENGTH];
+} nir_lower_viewport_transform_options;
+
+void nir_lower_viewport_transform(nir_shader *shader,
+  const nir_lower_viewport_transform_options 
*options);
+
 typedef struct nir_lower_drawpixels_options {
gl_state_index16 texcoord_state_tokens[STATE_LENGTH];
gl_state_index16 scale_state_tokens[STATE_LENGTH];
diff --git a/src/compiler/nir/nir_lower_viewport_transform.c 
b/src/compiler/nir/nir_lower_viewport_transform.c
new file mode 100644
index 000..4a8102be1e0
--- /dev/null
+++ b/src/compiler/nir/nir_lower_viewport_transform.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2017-2019 Qiang Yu 
+ *
+ * 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.
+ *
+ */
+
+#include "program/prog_statevars.h"
+#include "nir_builder.h"
+
+/* lower viewport transform into vertex shader
+ *
+ * This is needed for GPU like Mali Utgard and Midgard which has no viewport
+ * transform hw. Declare viewport transform parameters in uniform and use them
+ * to apply on the gl_Position varying output.
+ */
+
+typedef struct {
+   const nir_lower_viewport_transform_options *options;
+   nir_shader   *shader;
+   nir_builder   b;
+   nir_variable *scale, *translate;
+} lower_viewport_transform_state;
+
+static nir_variable *
+create_uniform(nir_shader *shader, const char *name, const gl_state_index16 
*tokens)
+{
+   nir_variable *var = nir_variable_create(
+  shader, nir_var_uniform, glsl_vec_type(3), name);
+
+   var->num_state_slots = 1;
+   var->state_slots = ralloc_array(var, nir_state_slot, 1);
+   memcpy(var->state_slots[0].tokens, tokens,
+  sizeof(var->state_slots[0].tokens));
+   return var;
+}
+
+static nir_ssa_def *
+get_scale(lower_viewport_transform_state *state)
+{
+   if (!state->scale)
+  state->scale = create_uniform(state->shader, "gl_viewportScale",
+state->options->scale);
+
+   return nir_load_var(>b, state->scale);
+}
+
+static nir_ssa_def *
+get_translate(lower_viewport_transform_s

[Mesa-dev] [PATCH 2/4] mesa: add STATE_VIEWPORT_SCALE/TRANSLATE

2019-03-26 Thread Qiang Yu
Signed-off-by: Qiang Yu 
---
 src/mesa/program/prog_statevars.c | 35 +++
 src/mesa/program/prog_statevars.h |  2 ++
 2 files changed, 37 insertions(+)

diff --git a/src/mesa/program/prog_statevars.c 
b/src/mesa/program/prog_statevars.c
index 3bbe451399f..ce74dbe317d 100644
--- a/src/mesa/program/prog_statevars.c
+++ b/src/mesa/program/prog_statevars.c
@@ -41,6 +41,7 @@
 #include "prog_parameter.h"
 #include "main/samplerobj.h"
 #include "main/framebuffer.h"
+#include "main/viewport.h"
 
 
 #define ONE_DIV_SQRT_LN2 (1.201122408786449815)
@@ -602,6 +603,30 @@ _mesa_fetch_state(struct gl_context *ctx, const 
gl_state_index16 state[],
   ctx->Color.BlendEnabled, ctx->Color._AdvancedBlendMode);
  return;
 
+  case STATE_VIEWPORT_SCALE:
+ {
+float scale[3];
+_mesa_get_viewport_xform(ctx, 0, scale, NULL);
+if (_mesa_is_winsys_fbo(ctx->DrawBuffer))
+   scale[1] = -scale[1];
+value[0] = scale[0];
+value[1] = scale[1];
+value[2] = scale[2];
+return;
+ }
+
+  case STATE_VIEWPORT_TRANSLATE:
+ {
+float translate[3];
+_mesa_get_viewport_xform(ctx, 0, NULL, translate);
+if (_mesa_is_winsys_fbo(ctx->DrawBuffer))
+   translate[1] = (GLfloat)ctx->DrawBuffer->Height - translate[1];
+value[0] = translate[0];
+value[1] = translate[1];
+value[2] = translate[2];
+return;
+ }
+
   /* XXX: make sure new tokens added here are also handled in the 
* _mesa_program_state_flags() switch, below.
*/
@@ -713,6 +738,10 @@ _mesa_program_state_flags(const gl_state_index16 
state[STATE_LENGTH])
   case STATE_ADVANCED_BLENDING_MODE:
  return _NEW_COLOR;
 
+  case STATE_VIEWPORT_SCALE:
+  case STATE_VIEWPORT_TRANSLATE:
+ return _NEW_BUFFERS | _NEW_VIEWPORT | _NEW_TRANSFORM;
+
   default:
  /* unknown state indexes are silently ignored and
  *  no flag set, since it is handled by the driver.
@@ -919,6 +948,12 @@ append_token(char *dst, gl_state_index k)
case STATE_ADVANCED_BLENDING_MODE:
   append(dst, "AdvancedBlendingMode");
   break;
+   case STATE_VIEWPORT_SCALE:
+  append(dst, "viewportScale");
+  break;
+   case STATE_VIEWPORT_TRANSLATE:
+  append(dst, "viewportTranslate");
+  break;
default:
   /* probably STATE_INTERNAL_DRIVER+i (driver private state) */
   append(dst, "driverState");
diff --git a/src/mesa/program/prog_statevars.h 
b/src/mesa/program/prog_statevars.h
index f28d2bb4a37..0d7a255b8ee 100644
--- a/src/mesa/program/prog_statevars.h
+++ b/src/mesa/program/prog_statevars.h
@@ -129,6 +129,8 @@ typedef enum gl_state_index_ {
 * currently active advanced blending equation, or zero if disabled.
 */
STATE_ADVANCED_BLENDING_MODE,
+   STATE_VIEWPORT_SCALE,
+   STATE_VIEWPORT_TRANSLATE,
STATE_INTERNAL_DRIVER   /* first available state index for drivers 
(must be last) */
 } gl_state_index;
 
-- 
2.17.1

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

[Mesa-dev] [PATCH 1/4] mesa: seperate scale and translate in viewport calculation

2019-03-26 Thread Qiang Yu
This is needed in _mesa_fetch_state where scale and translate
are get one by one.

Signed-off-by: Qiang Yu 
---
 src/mesa/main/viewport.c | 26 --
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/src/mesa/main/viewport.c b/src/mesa/main/viewport.c
index 97d328541b2..c9b1c27f120 100644
--- a/src/mesa/main/viewport.c
+++ b/src/mesa/main/viewport.c
@@ -585,21 +585,19 @@ _mesa_get_viewport_xform(struct gl_context *ctx, unsigned 
i,
double n = ctx->ViewportArray[i].Near;
double f = ctx->ViewportArray[i].Far;
 
-   scale[0] = half_width;
-   translate[0] = half_width + x;
-   if (ctx->Transform.ClipOrigin == GL_UPPER_LEFT) {
-  scale[1] = -half_height;
-   } else {
-  scale[1] = half_height;
+   if (scale) {
+  scale[0] = half_width;
+  scale[1] = ctx->Transform.ClipOrigin == GL_UPPER_LEFT ?
+ -half_height : half_height;
+  scale[2] = ctx->Transform.ClipDepthMode == GL_NEGATIVE_ONE_TO_ONE ?
+ 0.5 * (f - n) : f - n;
}
-   translate[1] = half_height + y;
-
-   if (ctx->Transform.ClipDepthMode == GL_NEGATIVE_ONE_TO_ONE) {
-  scale[2] = 0.5 * (f - n);
-  translate[2] = 0.5 * (n + f);
-   } else {
-  scale[2] = f - n;
-  translate[2] = n;
+
+   if (translate) {
+  translate[0] = half_width + x;
+  translate[1] = half_height + y;
+  translate[2] = ctx->Transform.ClipDepthMode == GL_NEGATIVE_ONE_TO_ONE ?
+ 0.5 * (n + f) : n;
}
 }
 
-- 
2.17.1

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

[Mesa-dev] [PATCH 0/4] Add nir_lower_viewport_transform

2019-03-26 Thread Qiang Yu
This is needed by Mali Utgard/Midgard GPU which don't have viewport
transform HW, and Lima/Panfrost driver can share same implementation
in a common place.

I send out this patch series seperatly because Lima is under review in
https://gitlab.freedesktop.org/mesa/mesa/merge_requests/465
and Panfrost driver need additinal changes in special uniform handling
which I'm not familiar with.

I expect Panfrost guys will send out patch to use this and Lima will be
another user of it when upstreamed.

Qiang Yu (4):
  mesa: seperate scale and translate in viewport calculation
  mesa: add STATE_VIEWPORT_SCALE/TRANSLATE
  nir: add nir_lower_viewport_transform
  mesa/st: do nir_lower_viewport_transform

 src/compiler/Makefile.sources |   1 +
 src/compiler/nir/meson.build  |   1 +
 src/compiler/nir/nir.h|   8 +
 .../nir/nir_lower_viewport_transform.c| 142 ++
 src/gallium/auxiliary/util/u_screen.c |   3 +
 src/gallium/include/pipe/p_defines.h  |   1 +
 src/mesa/main/viewport.c  |  26 ++--
 src/mesa/program/prog_statevars.c |  35 +
 src/mesa/program/prog_statevars.h |   2 +
 src/mesa/state_tracker/st_glsl_to_nir.cpp |  23 +++
 src/mesa/state_tracker/st_nir.h   |   4 +
 src/mesa/state_tracker/st_program.c   |   1 +
 12 files changed, 233 insertions(+), 14 deletions(-)
 create mode 100644 src/compiler/nir/nir_lower_viewport_transform.c

-- 
2.17.1

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

Re: [Mesa-dev] [PATCH v2 6/8] gallium: add lima driver

2019-03-26 Thread Qiang Yu
On Tue, Mar 26, 2019 at 11:33 AM Alyssa Rosenzweig  wrote:
>
> > +   [PPIR_INSTR_SLOT_ALU_VEC_MUL] = ppir_codegen_encode_vec_mul,
> > +   [PPIR_INSTR_SLOT_ALU_SCL_MUL] = ppir_codegen_encode_scl_mul,
> > +   [PPIR_INSTR_SLOT_ALU_VEC_ADD] = ppir_codegen_encode_vec_add,
> > +   [PPIR_INSTR_SLOT_ALU_SCL_ADD] = ppir_codegen_encode_scl_add,
>
> vmul/smul/vadd/sadd are the (official?) names for this on Midgard, fwiw.
>
> > +static const int ppir_codegen_field_size[] = {
> > +   34, 62, 41, 43, 30, 44, 31, 30, 41, 73
> > +};
>
> What is this?
PP instruction field (i.e. vadd part length) length in bit.

>
> > +static inline int align_to_word(int size)
> > +{
> > +   return ((size + 0x1f) >> 5);
> > +}
>
> Maybe use the align() macro (it's in mesa/src/util/) for clarity?
>
> > +   ppir_codegen_combine_scalar_op_atan  = 8, /* Arc Tangent Part 1 */
> > +   ppir_codegen_combine_scalar_op_atan2 = 9, /* Arc Tangent 2 Part 1 */
>
> Any plan to use these ops? Midgard has them too, but inverse trig gets
> lowered away anyway...
>
Not yet.

> > +if (node->op == ppir_op_neg)
> > +   src->negate = !src->negate;
> > +else if (node->op == ppir_op_abs)
> > +   src->absolute = true;
>
> I'm confused. NIR has neg/abs modifiers natively. You can get all
> fneg/fabs instructions lowered in NIR to these modifiers via
> the lower_source_mods pass. If you don't want them, you'll never have
> neg/abs ops at all; they'll all be modifiers. Why duplicate this in
> ppir?

Didn't know this pass, I can use it, thanks.

>
> > +   uint32_t va;
>
> I don't know the Utgard MMU, but will this work on 64-bit?
>
It's fine as Utgard MMU only support 32bit address.

>
> > +   uint32_t dubya;
>
> ???
Don't know for me either, just copy from lima-ng.

>
> > +   uint32_t mrt_bits;
> > +   uint32_t mrt_pitch;
>
> Utgard supports MRT?!
>
Utgard can render to 3 FB (WB0~2) in one pass.

>
> > +   uint32_t width = fui(fb->width);
> > +   uint32_t height = fui(fb->height);
> > +   uint32_t reload_gl_pos[] = {
> > +  width,  0x, 0x, 0x3f80, /* 0x */
> > +  0x, 0x, 0x, 0x3f80, /* 0x0010 */
> > +  0x, height, 0x, 0x3f80, /* 0x0020 */
> > +   };
> > +   memcpy(cpu + lima_reload_gl_pos_offset, reload_gl_pos,
> > +  sizeof(reload_gl_pos));
> > +
> > +   uint32_t reload_varying[] = {
> > +  width,  0x, 0x, 0x, /* 0x */
> > +  0x, height, 0x, 0x, /* 0x0010 */
> > +   };
> > +   memcpy(cpu + lima_reload_varying_offset, reload_varying,
> > +  sizeof(reload_varying));
> > +
>
> Why not actual float arrays?
>
Right.

>
> > +   uint32_t clear_shader[] = {
> > +  0x00021025, 0x000c,
> > +  (ctx->clear.color_16pc << 12) | 0x07cf,
> > +  ctx->clear.color_16pc >> 12,
> > +  ctx->clear.color_16pc >> 44,
> > +   };
>
> Please don't include shader blobs. This should maybe be generated
> from NIR, but at minimum, please include the corresponding annotated
> assembly.
>
I think no need to compile this kind of util shader, will add some
comments about it.

> > +  clear->color_16pc =
> > + ((uint64_t)float_to_ushort(color->f[3]) << 48) |
> > + ((uint64_t)float_to_ushort(color->f[2]) << 32) |
> > + ((uint64_t)float_to_ushort(color->f[1]) << 16) |
> > + float_to_ubyte(color->f[0]);
>
> Should that last line be float_to_ushort?
>
Right, will fix it.

>
> > +enum lima_attrib_type {
> > +   LIMA_ATTRIB_FLOAT = 0x000,
> > +   /* todo: find out what lives here. */
>
> LIMA_ATTRIB_FP16 maybe.
> LIMA_ATTRIB_I32/LIMA_ATTRIB_U32?.
>
>
> > +static bool
> > +is_modifier_ok(const uint64_t *modifiers, int count, uint64_t mod)
>
> drm_find_modifier in util/u_drm.h
>
> > +   /* fs program for clear buffer? */
> > +   static const uint32_t pp_clear_program[] = {
> > +  0x00020425, 0x000c, 0x01e007cf, 0xb000, /* 0x */
> > +  0x05f5, 0x, 0x, 0x, /* 0x0010 */
> > +   };
> > +   memcpy(lima_bo_map(screen->pp_buffer) + pp_clear_program_offset,
> > +  pp_clear_program, sizeof(pp_clear_program));
> > +
> > +   /* copy texture to framebuffer, used to reload gpu tile buffer */
> > +   static const uint32_t pp_reload_program[] = {
> > +  0x05e6, 0xf1003c20, 0x, 0x39001000, /* 0x */
> > +  0x0e4e, 0x07cf, 0x, 0x, /* 0x0010 */
> > +   };
> > +   memcpy(lima_bo_map(screen->pp_buffer) + pp_reload_program_offset,
> > +  pp_reload_program, sizeof(pp_reload_program));
> > +
> > +   /* 0/1/2 vertex index for reload/clear draw */
> > +   static const uint32_t pp_shared_index[] = {
> > +  0x00020100, 0x, 0x, 0x, /* 0x */
> > +   };
> > +   memcpy(lima_bo_map(screen->pp_buffer) + pp_shared_index_offset,
> > +  pp_shared_index, sizeof(pp_shared_index));
> 

Re: [Mesa-dev] [Lima] [PATCH v2 6/8] gallium: add lima driver

2019-03-26 Thread Qiang Yu
On Tue, Mar 26, 2019 at 11:00 AM Alyssa Rosenzweig  wrote:
>
> > Seems Panfrost implementation does not take depth uniforms?
>
> That's a /* to-do */ for me; it should definitely be implemented before
> adding to common code.
>
> > we both use the viewport scale/transform vector as the uniform
> > in this lower pass.
>
> I think that's reasonable. I don't like wasting a half-uniform (2vec3 =
> 1.5vec4), but that can't be helped I guess.
>
> > But due to lima pad special uniforms instead of prefix like
> > panfrost, we need to add a uniform location parameter to the API function.
>
> What do you mean by "pad vs prefix"?
Lima pad special uniform after system uniform, but Panfrost put special
uniform before the system uniform.

> A location parameter is a good idea
> regardless. Better yet, we could use an intrinsic system value load (I
> forget the exact) name to handle this, which I think is the most generic
> way for common NIR routines.
I mean a driver spec (passed in) uniform location.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH v2 6/8] gallium: add lima driver

2019-03-25 Thread Qiang Yu
On Fri, Mar 22, 2019 at 11:25 PM Alyssa Rosenzweig  wrote:
>
> > +
> > +static bool gpir_lower_viewport_transform(gpir_compiler *comp)
> > +{
> > +   gpir_node *rcpw = NULL;
> > +
> > +   /* rcpw = 1 / w */
> > +   list_for_each_entry(gpir_block, block, >block_list, list) {
> > +  list_for_each_entry(gpir_node, node, >node_list, list) {
> > + if (node->op == gpir_op_store_varying) {
> > +gpir_store_node *store = gpir_node_to_store(node);
> > +if (store->index == 0 && store->component == 3) {
> > +   gpir_node *w = store->child;
> > +
> > +   rcpw = gpir_node_create(block, gpir_op_rcp);
> > +   if (!rcpw)
> > +  return false;
> > +   list_addtail(>list, >list);
> > +
> > +   gpir_alu_node *alu = gpir_node_to_alu(rcpw);
> > +   alu->children[0] = w;
> > +   alu->num_child = 1;
> > +   store->child = rcpw;
> > +
> > +   gpir_node_insert_child(node, w, rcpw);
> > +   goto found;
> > +}
> > + }
> > +  }
> > +   }
> > +
> > +found:
> > +   assert(rcpw);
> > +
> > +   /* xyz = xyz * rcpw * scale + transition */
> > +   list_for_each_entry(gpir_block, block, >block_list, list) {
> > +  list_for_each_entry(gpir_node, node, >node_list, list) {
> > + if (node->op == gpir_op_store_varying) {
> > +gpir_store_node *store = gpir_node_to_store(node);
> > +if (store->index == 0 && store->component < 3) {
> > +   gpir_node *xyz = store->child;
> > +
> > +   gpir_node *mul1 =
> > +  gpir_lower_create_insert_node(node, xyz, rcpw, 
> > gpir_op_mul);
> > +   if (!mul1)
> > +  return false;
> > +
> > +   gpir_load_node *scale = gpir_node_create(block, 
> > gpir_op_load_uniform);
> > +   if (!scale)
> > +  return false;
> > +   scale->index = comp->constant_base;
> > +   scale->component = store->component;
> > +   list_addtail(>node.list, >list);
> > +
> > +   gpir_node *mul2 =
> > +  gpir_lower_create_insert_node(node, mul1, >node, 
> > gpir_op_mul);
> > +   if (!mul2)
> > +  return false;
> > +
> > +   gpir_load_node *translate = gpir_node_create(block, 
> > gpir_op_load_uniform);
> > +   if (!translate)
> > +  return false;
> > +   translate->index = comp->constant_base + 1;
> > +   translate->component = store->component;
> > +   list_addtail(>node.list, >list);
> > +
> > +   gpir_node *add =
> > +  gpir_lower_create_insert_node(node, mul2, 
> > >node, gpir_op_add);
> > +   if (!add)
> > +  return false;
> > +
> > +   store->child = add;
> > +}
> > + }
> > +  }
> > +   }
> > +
> > +   comp->constant_base += 2;
> > +   return true;
> > +}
>
> I have this routine implemented in Panfrost at the NIR level, rather
> than the ISA level. Do we want to move this to common NIR code?
>
Seems Panfrost implementation does not take depth uniforms? I think we can
move it to nir if we both use the viewport scale/transform vector as the uniform
in this lower pass. But due to lima pad special uniforms instead of prefix like
panfrost, we need to add a uniform location parameter to the API function.

> > +static int gpir_get_max_start(gpir_node *node)
>
> Read until here (note to self, gotta go, will read more later).
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

[Mesa-dev] [PATCH v2 8/8] kmsro: Add platform support for exynos and sun4i

2019-03-22 Thread Qiang Yu
From: Rob Herring 

Signed-off-by: Rob Herring 
Signed-off-by: Qiang Yu 
---
 src/gallium/targets/dri/meson.build | 2 ++
 src/gallium/targets/dri/target.c| 2 ++
 2 files changed, 4 insertions(+)

diff --git a/src/gallium/targets/dri/meson.build 
b/src/gallium/targets/dri/meson.build
index ff3455592ca..ae417d8ad5b 100644
--- a/src/gallium/targets/dri/meson.build
+++ b/src/gallium/targets/dri/meson.build
@@ -63,6 +63,7 @@ libgallium_dri = shared_library(
 )
 
 foreach d : [[with_gallium_kmsro, [
+   'exynos_dri.so',
'hx8357d_dri.so',
'ili9225_dri.so',
'ili9341_dri.so',
@@ -74,6 +75,7 @@ foreach d : [[with_gallium_kmsro, [
'rockchip_dri.so',
'st7586.so',
'st7735r.so',
+  'sun4i-drm_dri.so',
  ]],
  [with_gallium_radeonsi, 'radeonsi_dri.so'],
  [with_gallium_nouveau, 'nouveau_dri.so'],
diff --git a/src/gallium/targets/dri/target.c b/src/gallium/targets/dri/target.c
index c702058b0c9..ec657de277d 100644
--- a/src/gallium/targets/dri/target.c
+++ b/src/gallium/targets/dri/target.c
@@ -93,6 +93,7 @@ DEFINE_LOADER_DRM_ENTRYPOINT(tegra);
 #endif
 
 #if defined(GALLIUM_KMSRO)
+DEFINE_LOADER_DRM_ENTRYPOINT(exynos)
 DEFINE_LOADER_DRM_ENTRYPOINT(hx8357d)
 DEFINE_LOADER_DRM_ENTRYPOINT(ili9225)
 DEFINE_LOADER_DRM_ENTRYPOINT(ili9341)
@@ -103,6 +104,7 @@ DEFINE_LOADER_DRM_ENTRYPOINT(repaper)
 DEFINE_LOADER_DRM_ENTRYPOINT(rockchip)
 DEFINE_LOADER_DRM_ENTRYPOINT(st7586)
 DEFINE_LOADER_DRM_ENTRYPOINT(st7735r)
+DEFINE_LOADER_DRM_ENTRYPOINT(sun4i_drm)
 #endif
 
 #if defined(GALLIUM_LIMA)
-- 
2.17.1

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

[Mesa-dev] [PATCH v2 7/8] kmsro: Add lima renderonly support

2019-03-22 Thread Qiang Yu
From: Rob Herring 

Enable using lima for KMS renderonly. This still needs KMS driver
name mapping to kmsro to be used automatically.

Signed-off-by: Rob Herring 
Signed-off-by: Qiang Yu 
---
 meson.build |  4 ++--
 src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c | 11 +++
 src/gallium/winsys/kmsro/drm/meson.build|  3 +++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/meson.build b/meson.build
index 8def7444a45..851891f7e57 100644
--- a/meson.build
+++ b/meson.build
@@ -217,8 +217,8 @@ endif
 if with_dri_i915 and with_gallium_i915
   error('Only one i915 provider can be built')
 endif
-if with_gallium_kmsro and not (with_gallium_vc4 or with_gallium_etnaviv or 
with_gallium_freedreno or with_gallium_panfrost)
-  error('kmsro driver requires one or more renderonly drivers (vc4, etnaviv, 
freedreno, panfrost)')
+if with_gallium_kmsro and not (with_gallium_vc4 or with_gallium_etnaviv or 
with_gallium_freedreno or with_gallium_panfrost or with_gallium_lima)
+  error('kmsro driver requires one or more renderonly drivers (vc4, etnaviv, 
freedreno, panfrost, lima)')
 endif
 if with_gallium_tegra and not with_gallium_nouveau
   error('tegra driver requires nouveau driver')
diff --git a/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c 
b/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c
index 7752474f8aa..0bb8d437cd6 100644
--- a/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c
+++ b/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c
@@ -30,6 +30,7 @@
 #include "etnaviv/drm/etnaviv_drm_public.h"
 #include "freedreno/drm/freedreno_drm_public.h"
 #include "panfrost/drm/panfrost_drm_public.h"
+#include "lima/drm/lima_drm_public.h"
 #include "xf86drm.h"
 
 #include "pipe/p_screen.h"
@@ -105,7 +106,17 @@ struct pipe_screen *kmsro_drm_screen_create(int fd)
}
 #endif
 
+#if defined(GALLIUM_LIMA)
+   ro.gpu_fd = drmOpenWithType("lima", NULL, DRM_NODE_RENDER);
+   if (ro.gpu_fd >= 0) {
+  ro.create_for_resource = renderonly_create_kms_dumb_buffer_for_resource,
+  screen = lima_drm_screen_create_renderonly();
+  if (!screen)
+ close(ro.gpu_fd);
 
+  return screen;
+   }
+#endif
 
return screen;
 }
diff --git a/src/gallium/winsys/kmsro/drm/meson.build 
b/src/gallium/winsys/kmsro/drm/meson.build
index 51246b68e34..02064025b4d 100644
--- a/src/gallium/winsys/kmsro/drm/meson.build
+++ b/src/gallium/winsys/kmsro/drm/meson.build
@@ -22,6 +22,9 @@ kmsro_c_args = []
 if with_gallium_etnaviv
   kmsro_c_args += '-DGALLIUM_ETNAVIV'
 endif
+if with_gallium_lima
+  kmsro_c_args += '-DGALLIUM_LIMA'
+endif
 if with_gallium_vc4
   kmsro_c_args += '-DGALLIUM_VC4'
 endif
-- 
2.17.1

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

[Mesa-dev] [PATCH v2 5/8] drm-uapi: add lima_drm.h

2019-03-22 Thread Qiang Yu
Signed-of-by: Qiang Yu 
---
 include/drm-uapi/lima_drm.h | 169 
 1 file changed, 169 insertions(+)
 create mode 100644 include/drm-uapi/lima_drm.h

diff --git a/include/drm-uapi/lima_drm.h b/include/drm-uapi/lima_drm.h
new file mode 100644
index 000..95a00fb867e
--- /dev/null
+++ b/include/drm-uapi/lima_drm.h
@@ -0,0 +1,169 @@
+/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */
+/* Copyright 2017-2018 Qiang Yu  */
+
+#ifndef __LIMA_DRM_H__
+#define __LIMA_DRM_H__
+
+#include "drm.h"
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+enum drm_lima_param_gpu_id {
+   DRM_LIMA_PARAM_GPU_ID_UNKNOWN,
+   DRM_LIMA_PARAM_GPU_ID_MALI400,
+   DRM_LIMA_PARAM_GPU_ID_MALI450,
+};
+
+enum drm_lima_param {
+   DRM_LIMA_PARAM_GPU_ID,
+   DRM_LIMA_PARAM_NUM_PP,
+   DRM_LIMA_PARAM_GP_VERSION,
+   DRM_LIMA_PARAM_PP_VERSION,
+};
+
+/**
+ * get various information of the GPU
+ */
+struct drm_lima_get_param {
+   __u32 param; /* in, value in enum drm_lima_param */
+   __u32 pad;   /* pad, must be zero */
+   __u64 value; /* out, parameter value */
+};
+
+/**
+ * create a buffer for used by GPU
+ */
+struct drm_lima_gem_create {
+   __u32 size;/* in, buffer size */
+   __u32 flags;   /* in, currently no flags, must be zero */
+   __u32 handle;  /* out, GEM buffer handle */
+   __u32 pad; /* pad, must be zero */
+};
+
+/**
+ * get information of a buffer
+ */
+struct drm_lima_gem_info {
+   __u32 handle;  /* in, GEM buffer handle */
+   __u32 va;  /* out, virtual address mapped into GPU MMU */
+   __u64 offset;  /* out, used to mmap this buffer to CPU */
+};
+
+#define LIMA_SUBMIT_BO_READ   0x01
+#define LIMA_SUBMIT_BO_WRITE  0x02
+
+/* buffer information used by one task */
+struct drm_lima_gem_submit_bo {
+   __u32 handle;  /* in, GEM buffer handle */
+   __u32 flags;   /* in, buffer read/write by GPU */
+};
+
+#define LIMA_GP_FRAME_REG_NUM 6
+
+/* frame used to setup GP for each task */
+struct drm_lima_gp_frame {
+   __u32 frame[LIMA_GP_FRAME_REG_NUM];
+};
+
+#define LIMA_PP_FRAME_REG_NUM 23
+#define LIMA_PP_WB_REG_NUM 12
+
+/* frame used to setup mali400 GPU PP for each task */
+struct drm_lima_m400_pp_frame {
+   __u32 frame[LIMA_PP_FRAME_REG_NUM];
+   __u32 num_pp;
+   __u32 wb[3 * LIMA_PP_WB_REG_NUM];
+   __u32 plbu_array_address[4];
+   __u32 fragment_stack_address[4];
+};
+
+/* frame used to setup mali450 GPU PP for each task */
+struct drm_lima_m450_pp_frame {
+   __u32 frame[LIMA_PP_FRAME_REG_NUM];
+   __u32 num_pp;
+   __u32 wb[3 * LIMA_PP_WB_REG_NUM];
+   __u32 use_dlbu;
+   __u32 _pad;
+   union {
+   __u32 plbu_array_address[8];
+   __u32 dlbu_regs[4];
+   };
+   __u32 fragment_stack_address[8];
+};
+
+#define LIMA_PIPE_GP  0x00
+#define LIMA_PIPE_PP  0x01
+
+#define LIMA_SUBMIT_FLAG_EXPLICIT_FENCE (1 << 0)
+
+/**
+ * submit a task to GPU
+ *
+ * User can always merge multi sync_file and drm_syncobj
+ * into one drm_syncobj as in_sync[0], but we reserve
+ * in_sync[1] for another task's out_sync to avoid the
+ * export/import/merge pass when explicit sync.
+ */
+struct drm_lima_gem_submit {
+   __u32 ctx; /* in, context handle task is submitted to */
+   __u32 pipe;/* in, which pipe to use, GP/PP */
+   __u32 nr_bos;  /* in, array length of bos field */
+   __u32 frame_size;  /* in, size of frame field */
+   __u64 bos; /* in, array of drm_lima_gem_submit_bo */
+   __u64 frame;   /* in, GP/PP frame */
+   __u32 flags;   /* in, submit flags */
+   __u32 out_sync;/* in, drm_syncobj handle used to wait task finish 
after submission */
+   __u32 in_sync[2];  /* in, drm_syncobj handle used to wait before start 
this task */
+};
+
+#define LIMA_GEM_WAIT_READ   0x01
+#define LIMA_GEM_WAIT_WRITE  0x02
+
+/**
+ * wait pending GPU task finish of a buffer
+ */
+struct drm_lima_gem_wait {
+   __u32 handle;  /* in, GEM buffer handle */
+   __u32 op;  /* in, CPU want to read/write this buffer */
+   __s64 timeout_ns;  /* in, wait timeout in absulute time */
+};
+
+/**
+ * create a context
+ */
+struct drm_lima_ctx_create {
+   __u32 id;  /* out, context handle */
+   __u32 _pad;/* pad, must be zero */
+};
+
+/**
+ * free a context
+ */
+struct drm_lima_ctx_free {
+   __u32 id;  /* in, context handle */
+   __u32 _pad;/* pad, must be zero */
+};
+
+#define DRM_LIMA_GET_PARAM   0x00
+#define DRM_LIMA_GEM_CREATE  0x01
+#define DRM_LIMA_GEM_INFO0x02
+#define DRM_LIMA_GEM_SUBMIT  0x03
+#define DRM_LIMA_GEM_WAIT0x04
+#define DRM_LIMA_CTX_CREATE  0x05
+#define DRM_LIMA_CTX_FREE0x06
+
+#define DRM_IOCTL_LIMA_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + 
DRM_LIMA_GET_PARAM, struct drm_lima_get_param)
+#define DRM_IOCT

[Mesa-dev] [PATCH v2 4/8] gallium/u_vbuf: export u_vbuf_get_minmax_index

2019-03-22 Thread Qiang Yu
This helper function can be used by driver which
always need min/max index.

Signed-off-by: Qiang Yu 
---
 src/gallium/auxiliary/util/u_vbuf.c | 7 +++
 src/gallium/auxiliary/util/u_vbuf.h | 3 +++
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_vbuf.c 
b/src/gallium/auxiliary/util/u_vbuf.c
index f721613cbc5..02a59bc0575 100644
--- a/src/gallium/auxiliary/util/u_vbuf.c
+++ b/src/gallium/auxiliary/util/u_vbuf.c
@@ -1093,10 +1093,9 @@ u_vbuf_get_minmax_index_mapped(const struct 
pipe_draw_info *info,
*out_max_index = max;
 }
 
-static void
-u_vbuf_get_minmax_index(struct pipe_context *pipe,
-const struct pipe_draw_info *info,
-unsigned *out_min_index, unsigned *out_max_index)
+void u_vbuf_get_minmax_index(struct pipe_context *pipe,
+ const struct pipe_draw_info *info,
+ unsigned *out_min_index, unsigned *out_max_index)
 {
struct pipe_transfer *transfer = NULL;
const void *indices;
diff --git a/src/gallium/auxiliary/util/u_vbuf.h 
b/src/gallium/auxiliary/util/u_vbuf.h
index a6139834575..604e8c8b8b0 100644
--- a/src/gallium/auxiliary/util/u_vbuf.h
+++ b/src/gallium/auxiliary/util/u_vbuf.h
@@ -72,6 +72,9 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr,
unsigned start_slot, unsigned count,
const struct pipe_vertex_buffer *bufs);
 void u_vbuf_draw_vbo(struct u_vbuf *mgr, const struct pipe_draw_info *info);
+void u_vbuf_get_minmax_index(struct pipe_context *pipe,
+ const struct pipe_draw_info *info,
+ unsigned *out_min_index, unsigned *out_max_index);
 
 /* Save/restore functionality. */
 void u_vbuf_save_vertex_elements(struct u_vbuf *mgr);
-- 
2.17.1

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

[Mesa-dev] [PATCH v2 1/8] u_math: add ushort_to_float/float_to_ushort

2019-03-22 Thread Qiang Yu
v2:
- return 0 for NaN too

Cc: Roland Scheidegger 
Signed-off-by: Qiang Yu 
---
 src/util/u_math.h | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/src/util/u_math.h b/src/util/u_math.h
index e7dbbe5ca22..5e712dadb4a 100644
--- a/src/util/u_math.h
+++ b/src/util/u_math.h
@@ -389,6 +389,37 @@ float_to_ubyte(float f)
}
 }
 
+/**
+ * Convert ushort to float in [0, 1].
+ */
+static inline float
+ushort_to_float(ushort us)
+{
+   return (float) us * (1.0f / 65535.0f);
+}
+
+
+/**
+ * Convert float in [0,1] to ushort in [0,65535] with clamping.
+ */
+static inline ushort
+float_to_ushort(float f)
+{
+   /* return 0 for NaN too */
+   if (!(f > 0.0f)) {
+  return (ushort) 0;
+   }
+   else if (f >= 1.0f) {
+  return (ushort) 65535;
+   }
+   else {
+  union fi tmp;
+  tmp.f = f;
+  tmp.f = tmp.f * (65535.0f/65536.0f) + 128.0f;
+  return (ushort) tmp.i;
+   }
+}
+
 static inline float
 byte_to_float_tex(int8_t b)
 {
-- 
2.17.1

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

[Mesa-dev] [PATCH v2 3/8] u_dynarray: add util_dynarray_grow_cap

2019-03-22 Thread Qiang Yu
This is for the case that user only know a max size
it wants to append to the array and enlarge the array
capacity before writing into it.

v2:
- rename newsize to newcap
- rename util_dynarray_enlarge to util_dynarray_grow_cap

Cc: Caio Marcelo de Oliveira Filho 
Signed-off-by: Qiang Yu 
---
 src/util/u_dynarray.h | 23 +--
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/util/u_dynarray.h b/src/util/u_dynarray.h
index 9bed2b9c25c..b30fd7b1154 100644
--- a/src/util/u_dynarray.h
+++ b/src/util/u_dynarray.h
@@ -77,16 +77,14 @@ util_dynarray_clear(struct util_dynarray *buf)
 
 #define DYN_ARRAY_INITIAL_SIZE 64
 
-/* use util_dynarray_trim to reduce the allocated storage */
 static inline void *
-util_dynarray_resize(struct util_dynarray *buf, unsigned newsize)
+util_dynarray_ensure_cap(struct util_dynarray *buf, unsigned newcap)
 {
-   void *p;
-   if (newsize > buf->capacity) {
+   if (newcap > buf->capacity) {
   if (buf->capacity == 0)
  buf->capacity = DYN_ARRAY_INITIAL_SIZE;
 
-  while (newsize > buf->capacity)
+  while (newcap > buf->capacity)
  buf->capacity *= 2;
 
   if (buf->mem_ctx) {
@@ -96,7 +94,20 @@ util_dynarray_resize(struct util_dynarray *buf, unsigned 
newsize)
   }
}
 
-   p = (void *)((char *)buf->data + buf->size);
+   return (void *)((char *)buf->data + buf->size);
+}
+
+static inline void *
+util_dynarray_grow_cap(struct util_dynarray *buf, int diff)
+{
+   return util_dynarray_ensure_cap(buf, buf->size + diff);
+}
+
+/* use util_dynarray_trim to reduce the allocated storage */
+static inline void *
+util_dynarray_resize(struct util_dynarray *buf, unsigned newsize)
+{
+   void *p = util_dynarray_ensure_cap(buf, newsize);
buf->size = newsize;
 
return p;
-- 
2.17.1

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

[Mesa-dev] [PATCH v2 2/8] nir: add load uniform lower to scalar

2019-03-22 Thread Qiang Yu
This is needed for lima gp compiler.

Signed-off-by: Qiang Yu 
---
 src/compiler/nir/nir_intrinsics.py|  4 +--
 src/compiler/nir/nir_lower_io.c   |  2 +-
 src/compiler/nir/nir_lower_io_to_scalar.c | 41 +--
 3 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/src/compiler/nir/nir_intrinsics.py 
b/src/compiler/nir/nir_intrinsics.py
index ea092a991ca..3c67cbcb04d 100644
--- a/src/compiler/nir/nir_intrinsics.py
+++ b/src/compiler/nir/nir_intrinsics.py
@@ -607,8 +607,8 @@ def load(name, num_srcs, indices=[], flags=[]):
 intrinsic("load_" + name, [1] * num_srcs, dest_comp=0, indices=indices,
   flags=flags)
 
-# src[] = { offset }. const_index[] = { base, range }
-load("uniform", 1, [BASE, RANGE], [CAN_ELIMINATE, CAN_REORDER])
+# src[] = { offset }. const_index[] = { base, range, component }
+load("uniform", 1, [BASE, RANGE, COMPONENT], [CAN_ELIMINATE, CAN_REORDER])
 # src[] = { buffer_index, offset }. const_index[] = { align_mul, align_offset }
 load("ubo", 2, [ALIGN_MUL, ALIGN_OFFSET], flags=[CAN_ELIMINATE, CAN_REORDER])
 # src[] = { offset }. const_index[] = { base, component }
diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c
index 749ac91d47e..a852ee1f34a 100644
--- a/src/compiler/nir/nir_lower_io.c
+++ b/src/compiler/nir/nir_lower_io.c
@@ -251,7 +251,7 @@ lower_load(nir_intrinsic_instr *intrin, struct 
lower_io_state *state,
load->num_components = intrin->num_components;
 
nir_intrinsic_set_base(load, var->data.driver_location);
-   if (mode == nir_var_shader_in || mode == nir_var_shader_out)
+   if (mode == nir_var_shader_in || mode == nir_var_shader_out || mode == 
nir_var_uniform)
   nir_intrinsic_set_component(load, component);
 
if (load->intrinsic == nir_intrinsic_load_uniform)
diff --git a/src/compiler/nir/nir_lower_io_to_scalar.c 
b/src/compiler/nir/nir_lower_io_to_scalar.c
index 559d80b214a..1f0990d5dc5 100644
--- a/src/compiler/nir/nir_lower_io_to_scalar.c
+++ b/src/compiler/nir/nir_lower_io_to_scalar.c
@@ -27,8 +27,8 @@
 
 /** @file nir_lower_io_to_scalar.c
  *
- * Replaces nir_load_input/nir_store_output operations with num_components !=
- * 1 with individual per-channel operations.
+ * Replaces nir_load_input/nir_store_output/nir_load_uniform operations
+ * with num_components != 1 with individual per-channel operations.
  */
 
 static void
@@ -63,6 +63,39 @@ lower_load_input_to_scalar(nir_builder *b, 
nir_intrinsic_instr *intr)
nir_instr_remove(>instr);
 }
 
+static void
+lower_load_uniform_to_scalar(nir_builder *b, nir_intrinsic_instr *intr)
+{
+   b->cursor = nir_before_instr(>instr);
+
+   assert(intr->dest.is_ssa);
+
+   nir_ssa_def *loads[NIR_MAX_VEC_COMPONENTS];
+
+   for (unsigned i = 0; i < intr->num_components; i++) {
+  nir_intrinsic_instr *chan_intr =
+ nir_intrinsic_instr_create(b->shader, intr->intrinsic);
+  nir_ssa_dest_init(_intr->instr, _intr->dest,
+1, intr->dest.ssa.bit_size, NULL);
+  chan_intr->num_components = 1;
+
+  nir_intrinsic_set_base(chan_intr, nir_intrinsic_base(intr));
+  nir_intrinsic_set_component(chan_intr, nir_intrinsic_component(intr) + 
i);
+  nir_intrinsic_set_range(chan_intr, nir_intrinsic_range(intr));
+  /* offset */
+  nir_src_copy(_intr->src[0], >src[0], chan_intr);
+
+  nir_builder_instr_insert(b, _intr->instr);
+
+  loads[i] = _intr->dest.ssa;
+   }
+
+   nir_ssa_def_rewrite_uses(>dest.ssa,
+nir_src_for_ssa(nir_vec(b, loads,
+intr->num_components)));
+   nir_instr_remove(>instr);
+}
+
 static void
 lower_store_output_to_scalar(nir_builder *b, nir_intrinsic_instr *intr)
 {
@@ -120,6 +153,10 @@ nir_lower_io_to_scalar(nir_shader *shader, 
nir_variable_mode mask)
   if (mask & nir_var_shader_out)
  lower_store_output_to_scalar(, intr);
   break;
+   case nir_intrinsic_load_uniform:
+  if (mask & nir_var_uniform)
+ lower_load_uniform_to_scalar(, intr);
+  break;
default:
   break;
}
-- 
2.17.1

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

[Mesa-dev] [PATCH v2 0/8] Lima mesa driver

2019-03-22 Thread Qiang Yu
Mesa Gallium3D driver for ARM Mali 400/450 GPUs.

Lima is still in development and not ready for daily usage,
but can run some simple tests like kmscube and glamrk2, and some
single full screen application like kodi-gbm.

Mesa related EGL/GLX_EXT_buffer_age and EGL_KHR_partial_update
changes are not in this patch series because the solution has
not been settle down yet.

All lima commits are squashed. For whole history of this
driver's development, see:
https://gitlab.freedesktop.org/lima/mesa/commits/lima-18.3
https://gitlab.freedesktop.org/lima/mesa/commits/lima-18.1

Kernel driver is ready to be merged:
https://patchwork.kernel.org/patch/10845911/

I've also created a merge request for review on gitlab:
https://gitlab.freedesktop.org/mesa/mesa/merge_requests/465

v2:
- remove drm_fourcc.h change dependency
- drop CAP to calculate min/max index
- other minor changes inside each patch's comment

Qiang Yu (6):
  u_math: add ushort_to_float/float_to_ushort
  nir: add load uniform lower to scalar
  u_dynarray: add util_dynarray_grow_cap
  gallium/u_vbuf: export u_vbuf_get_minmax_index
  drm-uapi: add lima_drm.h
  gallium: add lima driver

Rob Herring (2):
  kmsro: Add lima renderonly support
  kmsro: Add platform support for exynos and sun4i

 include/drm-uapi/lima_drm.h   |  169 ++
 meson.build   |7 +-
 meson_options.txt |2 +-
 src/compiler/nir/nir_intrinsics.py|4 +-
 src/compiler/nir/nir_lower_io.c   |2 +-
 src/compiler/nir/nir_lower_io_to_scalar.c |   41 +-
 .../auxiliary/pipe-loader/pipe_loader_drm.c   |5 +
 .../auxiliary/target-helpers/drm_helper.h |   23 +
 .../target-helpers/drm_helper_public.h|3 +
 src/gallium/auxiliary/util/u_vbuf.c   |7 +-
 src/gallium/auxiliary/util/u_vbuf.h   |3 +
 src/gallium/drivers/lima/ir/gp/codegen.c  |  619 +++
 src/gallium/drivers/lima/ir/gp/codegen.h  |  166 ++
 src/gallium/drivers/lima/ir/gp/disasm.c   |  568 ++
 src/gallium/drivers/lima/ir/gp/gpir.h |  392 
 src/gallium/drivers/lima/ir/gp/instr.c|  488 +
 src/gallium/drivers/lima/ir/gp/lower.c|  529 ++
 src/gallium/drivers/lima/ir/gp/nir.c  |  420 +
 src/gallium/drivers/lima/ir/gp/node.c |  492 +
 .../drivers/lima/ir/gp/physical_regalloc.c|  135 ++
 .../drivers/lima/ir/gp/reduce_scheduler.c |  220 +++
 src/gallium/drivers/lima/ir/gp/scheduler.c|  809 
 .../drivers/lima/ir/gp/value_regalloc.c   |  170 ++
 src/gallium/drivers/lima/ir/lima_ir.h |   63 +
 src/gallium/drivers/lima/ir/pp/codegen.c  |  669 +++
 src/gallium/drivers/lima/ir/pp/codegen.h  |  359 
 src/gallium/drivers/lima/ir/pp/disasm.c   |  776 
 src/gallium/drivers/lima/ir/pp/instr.c|  311 
 src/gallium/drivers/lima/ir/pp/lower.c|  483 +
 src/gallium/drivers/lima/ir/pp/nir.c  |  497 +
 src/gallium/drivers/lima/ir/pp/node.c |  432 +
 .../drivers/lima/ir/pp/node_to_instr.c|  401 
 src/gallium/drivers/lima/ir/pp/ppir.h |  515 ++
 src/gallium/drivers/lima/ir/pp/regalloc.c |  757 
 src/gallium/drivers/lima/ir/pp/scheduler.c|  197 ++
 src/gallium/drivers/lima/lima_bo.c|  337 
 src/gallium/drivers/lima/lima_bo.h|   66 +
 src/gallium/drivers/lima/lima_context.c   |  262 +++
 src/gallium/drivers/lima/lima_context.h   |  294 +++
 src/gallium/drivers/lima/lima_draw.c  | 1646 +
 src/gallium/drivers/lima/lima_fence.c |  120 ++
 src/gallium/drivers/lima/lima_fence.h |   36 +
 src/gallium/drivers/lima/lima_program.c   |  311 
 src/gallium/drivers/lima/lima_program.h   |   35 +
 src/gallium/drivers/lima/lima_query.c |   96 +
 src/gallium/drivers/lima/lima_resource.c  |  599 ++
 src/gallium/drivers/lima/lima_resource.h  |   86 +
 src/gallium/drivers/lima/lima_screen.c|  544 ++
 src/gallium/drivers/lima/lima_screen.h|   93 +
 src/gallium/drivers/lima/lima_state.c |  516 ++
 src/gallium/drivers/lima/lima_submit.c|  184 ++
 src/gallium/drivers/lima/lima_submit.h|   43 +
 src/gallium/drivers/lima/lima_texture.c   |  278 +++
 src/gallium/drivers/lima/lima_texture.h   |   35 +
 src/gallium/drivers/lima/lima_tiling.c|  184 ++
 src/gallium/drivers/lima/lima_tiling.h|   44 +
 src/gallium/drivers/lima/lima_util.c  |   80 +
 src/gallium/drivers/lima/lima_util.h  |   37 +
 src/gallium/drivers/lima/meson.build  |   87 +
 src/gallium/meson.build   |6 +
 src/gallium/targets/dri/meson.build   |7 +-
 src/gallium/targets/dri/target.c  |5 +
 .../winsys/kmsro/drm/kmsro_drm_winsys.c   |   11 +
 src/gallium/winsys/kmsro/drm/meson.build  |3 +
 src

Re: [Mesa-dev] [PATCH 0/9] Lima mesa driver

2019-03-18 Thread Qiang Yu
On Sun, Mar 17, 2019 at 10:20 PM Rob Clark  wrote:
>
> Any chance you could submit a gitlab MR?  Replying with comments
> inline to the driver patch is a bit more than gmail can handle..

OK, I've created one:
https://gitlab.freedesktop.org/mesa/mesa/merge_requests/465

>
> but quick comments:
>
> In lima_pack_pp_frame_reg() maybe the swizzle field in 'struct
> util_format_description' is a better way to determine swap_channels?
> Not sure how many formats mali can render two, but I hope it is
> eventually more than two..  Maybe eventually you just want a formats
> table mapping pipe_format, to corresponding hw state for tex/fb/vbo.
> (Have a look at fd[3456]_format.c.. maybe a similar idea is useful to
> you?)

In fact we haven't do more investigate on other formats, have a table
is better, but we can fill in it for only a few formats now.

>
> Alyssa's drm_find_modifier() helper can make is_modifier_ok() go away.
>
> re: lima_screen_parse_env(), you might find
> DEBUG_GET_ONCE_FLAGS_OPTION() / struct debug_named_value useful?
>
> And for framebuffer (render target), pipe_surface's
> u.tex.level/first_layer aren't necessarily zero.  Maybe I'm
> overlooking it, but I don't see where you're adding the offset within
> the resource to the requested layer/level.  (I guess you'd hit that
> during mipmap generation, at least if relying on u_blitter for mipmap
> gen)

lima does not support mipmap generation yet, will add that when we
implement the mipmap generation.

Thanks,
Qiang
>
>
> BR,
> -R
>
>
> On Fri, Mar 15, 2019 at 9:30 PM Qiang Yu  wrote:
> >
> > Mesa Gallium3D driver for ARM Mali 400/450 GPUs.
> >
> > Lima is still in development and not ready for daily usage,
> > but can run some simple tests like kmscube and glamrk2, and some
> > single full screen application like kodi-gbm.
> >
> > Mesa related EGL/GLX_EXT_buffer_age and EGL_KHR_partial_update
> > changes are not in this patch series because the solution has
> > not been settle down yet.
> >
> > All lima commits are squashed. For whole history of this
> > driver's development, see:
> > https://gitlab.freedesktop.org/lima/mesa/commits/lima-18.3
> > https://gitlab.freedesktop.org/lima/mesa/commits/lima-18.1
> >
> > Kernel driver is ready to be merged:
> > https://patchwork.kernel.org/patch/10845911/
> >
> > This patch series also depends on a kernel patch which is
> > under review now:
> > https://patchwork.kernel.org/patch/10852619/
> >
> > Erico Nunes (1):
> >   gallium: add a cap to force compute minmax indices
> >
> > Qiang Yu (6):
> >   gallium/u_math: add ushort_to_float/float_to_ushort
> >   nir: add load uniform lower to scalar
> >   u_dynarray: add util_dynarray_enlarge
> >   drm-uapi: drm_fourcc.h add ARM GPU modifier
> >   drm-uapi: add lima_drm.h
> >   gallium: add lima driver
> >
> > Rob Herring (2):
> >   kmsro: Add lima renderonly support
> >   kmsro: Add platform support for exynos and sun4i
> >
> >  include/drm-uapi/drm_fourcc.h |   31 +-
> >  include/drm-uapi/lima_drm.h   |  169 ++
> >  meson.build   |7 +-
> >  meson_options.txt |2 +-
> >  src/compiler/nir/nir_intrinsics.py|4 +-
> >  src/compiler/nir/nir_lower_io.c   |2 +-
> >  src/compiler/nir/nir_lower_io_to_scalar.c |   41 +-
> >  .../auxiliary/pipe-loader/pipe_loader_drm.c   |5 +
> >  .../auxiliary/target-helpers/drm_helper.h |   23 +
> >  .../target-helpers/drm_helper_public.h|3 +
> >  src/gallium/auxiliary/util/u_screen.c |3 +
> >  src/gallium/drivers/lima/ir/gp/codegen.c  |  619 +++
> >  src/gallium/drivers/lima/ir/gp/codegen.h  |  166 ++
> >  src/gallium/drivers/lima/ir/gp/disasm.c   |  568 ++
> >  src/gallium/drivers/lima/ir/gp/gpir.h |  392 
> >  src/gallium/drivers/lima/ir/gp/instr.c|  488 +
> >  src/gallium/drivers/lima/ir/gp/lower.c|  529 ++
> >  src/gallium/drivers/lima/ir/gp/nir.c  |  420 +
> >  src/gallium/drivers/lima/ir/gp/node.c |  492 +
> >  .../drivers/lima/ir/gp/physical_regalloc.c|  135 ++
> >  .../drivers/lima/ir/gp/reduce_scheduler.c |  220 +++
> >  src/gallium/drivers/lima/ir/gp/scheduler.c|  809 
> >  .../drivers/lima/ir/gp/value_regalloc.c   |  170 ++
> >  src/gallium/drivers/lima/ir/lima_ir.h |   65 +
> >  src/gallium/drivers/lima/ir/pp/codegen.c  |  669 +++
> >  src/gallium/drivers/lima/ir/pp/codeg

Re: [Mesa-dev] [PATCH 3/9] u_dynarray: add util_dynarray_enlarge

2019-03-16 Thread Qiang Yu
On Sat, Mar 16, 2019 at 11:26 AM Caio Marcelo de Oliveira Filho
 wrote:
>
> On Sat, Mar 16, 2019 at 09:28:48AM +0800, Qiang Yu wrote:
> > This is for the case that user only know a max size
> > it wants to append to the array and enlarge the array
> > capacity before writing into it.
> >
> > Signed-off-by: Qiang Yu 
> > ---
> >  src/util/u_dynarray.h | 19 +++
> >  1 file changed, 15 insertions(+), 4 deletions(-)
> >
> > diff --git a/src/util/u_dynarray.h b/src/util/u_dynarray.h
> > index 9bed2b9c25c..c5217082b7f 100644
> > --- a/src/util/u_dynarray.h
> > +++ b/src/util/u_dynarray.h
> > @@ -77,11 +77,9 @@ util_dynarray_clear(struct util_dynarray *buf)
> >
> >  #define DYN_ARRAY_INITIAL_SIZE 64
> >
> > -/* use util_dynarray_trim to reduce the allocated storage */
> >  static inline void *
> > -util_dynarray_resize(struct util_dynarray *buf, unsigned newsize)
> > +util_dynarray_ensure_cap(struct util_dynarray *buf, unsigned newsize)
>
> Rename the parameter to newcap to avoid confusion in the body.
>
> >  {
> > -   void *p;
> > if (newsize > buf->capacity) {
> >if (buf->capacity == 0)
> >   buf->capacity = DYN_ARRAY_INITIAL_SIZE;
> > @@ -96,7 +94,20 @@ util_dynarray_resize(struct util_dynarray *buf, unsigned 
> > newsize)
> >}
> > }
> >
> > -   p = (void *)((char *)buf->data + buf->size);
> > +   return (void *)((char *)buf->data + buf->size);
> > +}
> > +
> > +static inline void *
> > +util_dynarray_enlarge(struct util_dynarray *buf, int diff)
> > +{
> > +   return util_dynarray_ensure_cap(buf, buf->size + diff);
> > +}
>
> We already have util_dynarray_grow for size, so enlarge can be
> confusing.  What do you think about calling this one
> util_dynarray_grow_cap?
>
Nice name.

Regards,
Qiang

>
> > +
> > +/* use util_dynarray_trim to reduce the allocated storage */
> > +static inline void *
> > +util_dynarray_resize(struct util_dynarray *buf, unsigned newsize)
> > +{
> > +   void *p = util_dynarray_ensure_cap(buf, newsize);
> > buf->size = newsize;
> >
> > return p;
> > --
> > 2.17.1
> >
> > ___
> > mesa-dev mailing list
> > mesa-dev@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
>
> Caio
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

[Mesa-dev] [PATCH 2/9] nir: add load uniform lower to scalar

2019-03-15 Thread Qiang Yu
This is needed for lima gp compiler.

Signed-off-by: Qiang Yu 
---
 src/compiler/nir/nir_intrinsics.py|  4 +--
 src/compiler/nir/nir_lower_io.c   |  2 +-
 src/compiler/nir/nir_lower_io_to_scalar.c | 41 +--
 3 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/src/compiler/nir/nir_intrinsics.py 
b/src/compiler/nir/nir_intrinsics.py
index a6c74dc2543..5aea515258f 100644
--- a/src/compiler/nir/nir_intrinsics.py
+++ b/src/compiler/nir/nir_intrinsics.py
@@ -603,8 +603,8 @@ def load(name, num_srcs, indices=[], flags=[]):
 intrinsic("load_" + name, [1] * num_srcs, dest_comp=0, indices=indices,
   flags=flags)
 
-# src[] = { offset }. const_index[] = { base, range }
-load("uniform", 1, [BASE, RANGE], [CAN_ELIMINATE, CAN_REORDER])
+# src[] = { offset }. const_index[] = { base, range, component }
+load("uniform", 1, [BASE, RANGE, COMPONENT], [CAN_ELIMINATE, CAN_REORDER])
 # src[] = { buffer_index, offset }. const_index[] = { align_mul, align_offset }
 load("ubo", 2, [ALIGN_MUL, ALIGN_OFFSET], flags=[CAN_ELIMINATE, CAN_REORDER])
 # src[] = { offset }. const_index[] = { base, component }
diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c
index d1f95cfe6ac..058151c915e 100644
--- a/src/compiler/nir/nir_lower_io.c
+++ b/src/compiler/nir/nir_lower_io.c
@@ -251,7 +251,7 @@ lower_load(nir_intrinsic_instr *intrin, struct 
lower_io_state *state,
load->num_components = intrin->num_components;
 
nir_intrinsic_set_base(load, var->data.driver_location);
-   if (mode == nir_var_shader_in || mode == nir_var_shader_out)
+   if (mode == nir_var_shader_in || mode == nir_var_shader_out || mode == 
nir_var_uniform)
   nir_intrinsic_set_component(load, component);
 
if (load->intrinsic == nir_intrinsic_load_uniform)
diff --git a/src/compiler/nir/nir_lower_io_to_scalar.c 
b/src/compiler/nir/nir_lower_io_to_scalar.c
index 559d80b214a..1f0990d5dc5 100644
--- a/src/compiler/nir/nir_lower_io_to_scalar.c
+++ b/src/compiler/nir/nir_lower_io_to_scalar.c
@@ -27,8 +27,8 @@
 
 /** @file nir_lower_io_to_scalar.c
  *
- * Replaces nir_load_input/nir_store_output operations with num_components !=
- * 1 with individual per-channel operations.
+ * Replaces nir_load_input/nir_store_output/nir_load_uniform operations
+ * with num_components != 1 with individual per-channel operations.
  */
 
 static void
@@ -63,6 +63,39 @@ lower_load_input_to_scalar(nir_builder *b, 
nir_intrinsic_instr *intr)
nir_instr_remove(>instr);
 }
 
+static void
+lower_load_uniform_to_scalar(nir_builder *b, nir_intrinsic_instr *intr)
+{
+   b->cursor = nir_before_instr(>instr);
+
+   assert(intr->dest.is_ssa);
+
+   nir_ssa_def *loads[NIR_MAX_VEC_COMPONENTS];
+
+   for (unsigned i = 0; i < intr->num_components; i++) {
+  nir_intrinsic_instr *chan_intr =
+ nir_intrinsic_instr_create(b->shader, intr->intrinsic);
+  nir_ssa_dest_init(_intr->instr, _intr->dest,
+1, intr->dest.ssa.bit_size, NULL);
+  chan_intr->num_components = 1;
+
+  nir_intrinsic_set_base(chan_intr, nir_intrinsic_base(intr));
+  nir_intrinsic_set_component(chan_intr, nir_intrinsic_component(intr) + 
i);
+  nir_intrinsic_set_range(chan_intr, nir_intrinsic_range(intr));
+  /* offset */
+  nir_src_copy(_intr->src[0], >src[0], chan_intr);
+
+  nir_builder_instr_insert(b, _intr->instr);
+
+  loads[i] = _intr->dest.ssa;
+   }
+
+   nir_ssa_def_rewrite_uses(>dest.ssa,
+nir_src_for_ssa(nir_vec(b, loads,
+intr->num_components)));
+   nir_instr_remove(>instr);
+}
+
 static void
 lower_store_output_to_scalar(nir_builder *b, nir_intrinsic_instr *intr)
 {
@@ -120,6 +153,10 @@ nir_lower_io_to_scalar(nir_shader *shader, 
nir_variable_mode mask)
   if (mask & nir_var_shader_out)
  lower_store_output_to_scalar(, intr);
   break;
+   case nir_intrinsic_load_uniform:
+  if (mask & nir_var_uniform)
+ lower_load_uniform_to_scalar(, intr);
+  break;
default:
   break;
}
-- 
2.17.1

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

[Mesa-dev] [PATCH 3/9] u_dynarray: add util_dynarray_enlarge

2019-03-15 Thread Qiang Yu
This is for the case that user only know a max size
it wants to append to the array and enlarge the array
capacity before writing into it.

Signed-off-by: Qiang Yu 
---
 src/util/u_dynarray.h | 19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/util/u_dynarray.h b/src/util/u_dynarray.h
index 9bed2b9c25c..c5217082b7f 100644
--- a/src/util/u_dynarray.h
+++ b/src/util/u_dynarray.h
@@ -77,11 +77,9 @@ util_dynarray_clear(struct util_dynarray *buf)
 
 #define DYN_ARRAY_INITIAL_SIZE 64
 
-/* use util_dynarray_trim to reduce the allocated storage */
 static inline void *
-util_dynarray_resize(struct util_dynarray *buf, unsigned newsize)
+util_dynarray_ensure_cap(struct util_dynarray *buf, unsigned newsize)
 {
-   void *p;
if (newsize > buf->capacity) {
   if (buf->capacity == 0)
  buf->capacity = DYN_ARRAY_INITIAL_SIZE;
@@ -96,7 +94,20 @@ util_dynarray_resize(struct util_dynarray *buf, unsigned 
newsize)
   }
}
 
-   p = (void *)((char *)buf->data + buf->size);
+   return (void *)((char *)buf->data + buf->size);
+}
+
+static inline void *
+util_dynarray_enlarge(struct util_dynarray *buf, int diff)
+{
+   return util_dynarray_ensure_cap(buf, buf->size + diff);
+}
+
+/* use util_dynarray_trim to reduce the allocated storage */
+static inline void *
+util_dynarray_resize(struct util_dynarray *buf, unsigned newsize)
+{
+   void *p = util_dynarray_ensure_cap(buf, newsize);
buf->size = newsize;
 
return p;
-- 
2.17.1

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

[Mesa-dev] [PATCH 8/9] kmsro: Add lima renderonly support

2019-03-15 Thread Qiang Yu
From: Rob Herring 

Enable using lima for KMS renderonly. This still needs KMS driver
name mapping to kmsro to be used automatically.

Signed-off-by: Rob Herring 
Signed-off-by: Qiang Yu 
---
 meson.build |  4 ++--
 src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c | 11 +++
 src/gallium/winsys/kmsro/drm/meson.build|  3 +++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/meson.build b/meson.build
index 98bbe756b39..318c4d59478 100644
--- a/meson.build
+++ b/meson.build
@@ -217,8 +217,8 @@ endif
 if with_dri_i915 and with_gallium_i915
   error('Only one i915 provider can be built')
 endif
-if with_gallium_kmsro and not (with_gallium_vc4 or with_gallium_etnaviv or 
with_gallium_freedreno or with_gallium_panfrost)
-  error('kmsro driver requires one or more renderonly drivers (vc4, etnaviv, 
freedreno, panfrost)')
+if with_gallium_kmsro and not (with_gallium_vc4 or with_gallium_etnaviv or 
with_gallium_freedreno or with_gallium_panfrost or with_gallium_lima)
+  error('kmsro driver requires one or more renderonly drivers (vc4, etnaviv, 
freedreno, panfrost, lima)')
 endif
 if with_gallium_tegra and not with_gallium_nouveau
   error('tegra driver requires nouveau driver')
diff --git a/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c 
b/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c
index 7752474f8aa..0bb8d437cd6 100644
--- a/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c
+++ b/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c
@@ -30,6 +30,7 @@
 #include "etnaviv/drm/etnaviv_drm_public.h"
 #include "freedreno/drm/freedreno_drm_public.h"
 #include "panfrost/drm/panfrost_drm_public.h"
+#include "lima/drm/lima_drm_public.h"
 #include "xf86drm.h"
 
 #include "pipe/p_screen.h"
@@ -105,7 +106,17 @@ struct pipe_screen *kmsro_drm_screen_create(int fd)
}
 #endif
 
+#if defined(GALLIUM_LIMA)
+   ro.gpu_fd = drmOpenWithType("lima", NULL, DRM_NODE_RENDER);
+   if (ro.gpu_fd >= 0) {
+  ro.create_for_resource = renderonly_create_kms_dumb_buffer_for_resource,
+  screen = lima_drm_screen_create_renderonly();
+  if (!screen)
+ close(ro.gpu_fd);
 
+  return screen;
+   }
+#endif
 
return screen;
 }
diff --git a/src/gallium/winsys/kmsro/drm/meson.build 
b/src/gallium/winsys/kmsro/drm/meson.build
index 51246b68e34..02064025b4d 100644
--- a/src/gallium/winsys/kmsro/drm/meson.build
+++ b/src/gallium/winsys/kmsro/drm/meson.build
@@ -22,6 +22,9 @@ kmsro_c_args = []
 if with_gallium_etnaviv
   kmsro_c_args += '-DGALLIUM_ETNAVIV'
 endif
+if with_gallium_lima
+  kmsro_c_args += '-DGALLIUM_LIMA'
+endif
 if with_gallium_vc4
   kmsro_c_args += '-DGALLIUM_VC4'
 endif
-- 
2.17.1

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

[Mesa-dev] [PATCH 5/9] drm-uapi: drm_fourcc.h add ARM GPU modifier

2019-03-15 Thread Qiang Yu
Signed-off-by: Qiang Yu 
---
 include/drm-uapi/drm_fourcc.h | 31 ++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/include/drm-uapi/drm_fourcc.h b/include/drm-uapi/drm_fourcc.h
index bab20298f42..56f737af8ca 100644
--- a/include/drm-uapi/drm_fourcc.h
+++ b/include/drm-uapi/drm_fourcc.h
@@ -585,6 +585,19 @@ extern "C" {
  */
 #define DRM_FORMAT_MOD_BROADCOM_UIF fourcc_mod_code(BROADCOM, 6)
 
+/*
+ * Arm Buffer Layout Type Code
+ *
+ * Arm has multiple types of buffer layout which are not totally shared
+ * across devices, so add a type field at the MSB of the format field
+ * to separate each type's encoding.
+ */
+#define DRM_FORMAT_MOD_ARM_TYPE_AFBC 0x00
+#define DRM_FORMAT_MOD_ARM_TYPE_AGTB 0x01
+
+#define DRM_FORMAT_MOD_ARM_CODE(type, val) \
+   fourcc_mod_code(ARM, ((__u64)type << 48) | ((val) & 
0xULL))
+
 /*
  * Arm Framebuffer Compression (AFBC) modifiers
  *
@@ -599,7 +612,8 @@ extern "C" {
  * Further information on the use of AFBC modifiers can be found in
  * Documentation/gpu/afbc.rst
  */
-#define DRM_FORMAT_MOD_ARM_AFBC(__afbc_mode)   fourcc_mod_code(ARM, 
__afbc_mode)
+#define DRM_FORMAT_MOD_ARM_AFBC(__afbc_mode) \
+   DRM_FORMAT_MOD_ARM_CODE(DRM_FORMAT_MOD_ARM_TYPE_AFBC, __afbc_mode)
 
 /*
  * AFBC superblock size
@@ -693,6 +707,21 @@ extern "C" {
  */
 #define AFBC_FORMAT_MOD_BCH (1ULL << 11)
 
+/*
+ * Arm Graphics Tiled Buffer (AGTB) modifiers
+ */
+#define DRM_FORMAT_MOD_ARM_AGTB(mode) \
+   DRM_FORMAT_MOD_ARM_CODE(DRM_FORMAT_MOD_ARM_TYPE_AGTB, mode)
+
+/*
+ * AGTB mode 0 modifier
+ *
+ * This is used by ARM Mali Utgard/Midgard GPU. It divides buffer into
+ * 16x16 pixel blocks. Blocks are stored linearly in order, but pixels
+ * in the block are reordered.
+ */
+#define DRM_FORMAT_MOD_ARM_AGTB_MODE0 DRM_FORMAT_MOD_ARM_AGTB(1)
+
 /*
  * Allwinner tiled modifier
  *
-- 
2.17.1

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

[Mesa-dev] [PATCH 4/9] gallium: add a cap to force compute minmax indices

2019-03-15 Thread Qiang Yu
From: Erico Nunes 

pipe_draw_info has min_index and max_index fields that can be useful in
indexed drawing, however gallium may decide to not compute them in some
cases to avoid impacting performance if the driver won't need them.
However, some drivers may need to always compute these values to build a
valid command stream for indexed draw.
Instead of reimplementing this functionality or having to explicitly
compute those in driver specific code, this new cap can be used to
ensure that gallium will not skip the computation.
Drivers that set this cap will be able to rely on those values to build
the command stream.

For more details on this patch:
https://lists.freedesktop.org/archives/mesa-dev/2018-March/189251.html

Signed-off-by: Erico Nunes 
---
 src/gallium/auxiliary/util/u_screen.c | 3 +++
 src/gallium/include/pipe/p_defines.h  | 1 +
 src/mesa/state_tracker/st_draw.c  | 5 -
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/util/u_screen.c 
b/src/gallium/auxiliary/util/u_screen.c
index 50964f3b3ef..e8fbdf56e2f 100644
--- a/src/gallium/auxiliary/util/u_screen.c
+++ b/src/gallium/auxiliary/util/u_screen.c
@@ -341,6 +341,9 @@ u_pipe_screen_get_param_defaults(struct pipe_screen 
*pscreen,
case PIPE_CAP_MAX_VARYINGS:
   return 8;
 
+   case PIPE_CAP_FORCE_COMPUTE_MINMAX_INDICES:
+  return 0;
+
default:
   unreachable("bad PIPE_CAP_*");
}
diff --git a/src/gallium/include/pipe/p_defines.h 
b/src/gallium/include/pipe/p_defines.h
index e2b0104ce43..495ba88e521 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -858,6 +858,7 @@ enum pipe_cap
PIPE_CAP_DEST_SURFACE_SRGB_CONTROL,
PIPE_CAP_NIR_COMPACT_ARRAYS,
PIPE_CAP_MAX_VARYINGS,
+   PIPE_CAP_FORCE_COMPUTE_MINMAX_INDICES,
 };
 
 /**
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 7485fc82b18..501c09817c0 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -195,9 +195,12 @@ st_draw_vbo(struct gl_context *ctx,
 
if (ib) {
   struct gl_buffer_object *bufobj = ib->obj;
+  struct pipe_screen *screen = st->pipe->screen;
+  bool needs_minmax_index = st->draw_needs_minmax_index ||
+ screen->get_param(screen, PIPE_CAP_FORCE_COMPUTE_MINMAX_INDICES);
 
   /* Get index bounds for user buffers. */
-  if (!index_bounds_valid && st->draw_needs_minmax_index) {
+  if (!index_bounds_valid && needs_minmax_index) {
  vbo_get_minmax_indices(ctx, prims, ib, _index, _index,
 nr_prims);
   }
-- 
2.17.1

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

[Mesa-dev] [PATCH 1/9] gallium/u_math: add ushort_to_float/float_to_ushort

2019-03-15 Thread Qiang Yu
Signed-off-by: Qiang Yu 
---
 src/util/u_math.h | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/src/util/u_math.h b/src/util/u_math.h
index e7dbbe5ca22..ffadfb47282 100644
--- a/src/util/u_math.h
+++ b/src/util/u_math.h
@@ -389,6 +389,37 @@ float_to_ubyte(float f)
}
 }
 
+/**
+ * Convert ushort to float in [0, 1].
+ */
+static inline float
+ushort_to_float(ushort us)
+{
+   return (float) us * (1.0f / 65535.0f);
+}
+
+
+/**
+ * Convert float in [0,1] to ushort in [0,65535] with clamping.
+ */
+static inline ushort
+float_to_ushort(float f)
+{
+   union fi tmp;
+
+   tmp.f = f;
+   if (tmp.i < 0) {
+  return (ushort) 0;
+   }
+   else if (tmp.i >= 0x3f80 /* 1.0f */) {
+  return (ushort) 65535;
+   }
+   else {
+  tmp.f = tmp.f * (65535.0f/65536.0f) + 128.0f;
+  return (ushort) tmp.i;
+   }
+}
+
 static inline float
 byte_to_float_tex(int8_t b)
 {
-- 
2.17.1

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

[Mesa-dev] [PATCH 6/9] drm-uapi: add lima_drm.h

2019-03-15 Thread Qiang Yu
Signed-of-by: Qiang Yu 
---
 include/drm-uapi/lima_drm.h | 169 
 1 file changed, 169 insertions(+)
 create mode 100644 include/drm-uapi/lima_drm.h

diff --git a/include/drm-uapi/lima_drm.h b/include/drm-uapi/lima_drm.h
new file mode 100644
index 000..95a00fb867e
--- /dev/null
+++ b/include/drm-uapi/lima_drm.h
@@ -0,0 +1,169 @@
+/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */
+/* Copyright 2017-2018 Qiang Yu  */
+
+#ifndef __LIMA_DRM_H__
+#define __LIMA_DRM_H__
+
+#include "drm.h"
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+enum drm_lima_param_gpu_id {
+   DRM_LIMA_PARAM_GPU_ID_UNKNOWN,
+   DRM_LIMA_PARAM_GPU_ID_MALI400,
+   DRM_LIMA_PARAM_GPU_ID_MALI450,
+};
+
+enum drm_lima_param {
+   DRM_LIMA_PARAM_GPU_ID,
+   DRM_LIMA_PARAM_NUM_PP,
+   DRM_LIMA_PARAM_GP_VERSION,
+   DRM_LIMA_PARAM_PP_VERSION,
+};
+
+/**
+ * get various information of the GPU
+ */
+struct drm_lima_get_param {
+   __u32 param; /* in, value in enum drm_lima_param */
+   __u32 pad;   /* pad, must be zero */
+   __u64 value; /* out, parameter value */
+};
+
+/**
+ * create a buffer for used by GPU
+ */
+struct drm_lima_gem_create {
+   __u32 size;/* in, buffer size */
+   __u32 flags;   /* in, currently no flags, must be zero */
+   __u32 handle;  /* out, GEM buffer handle */
+   __u32 pad; /* pad, must be zero */
+};
+
+/**
+ * get information of a buffer
+ */
+struct drm_lima_gem_info {
+   __u32 handle;  /* in, GEM buffer handle */
+   __u32 va;  /* out, virtual address mapped into GPU MMU */
+   __u64 offset;  /* out, used to mmap this buffer to CPU */
+};
+
+#define LIMA_SUBMIT_BO_READ   0x01
+#define LIMA_SUBMIT_BO_WRITE  0x02
+
+/* buffer information used by one task */
+struct drm_lima_gem_submit_bo {
+   __u32 handle;  /* in, GEM buffer handle */
+   __u32 flags;   /* in, buffer read/write by GPU */
+};
+
+#define LIMA_GP_FRAME_REG_NUM 6
+
+/* frame used to setup GP for each task */
+struct drm_lima_gp_frame {
+   __u32 frame[LIMA_GP_FRAME_REG_NUM];
+};
+
+#define LIMA_PP_FRAME_REG_NUM 23
+#define LIMA_PP_WB_REG_NUM 12
+
+/* frame used to setup mali400 GPU PP for each task */
+struct drm_lima_m400_pp_frame {
+   __u32 frame[LIMA_PP_FRAME_REG_NUM];
+   __u32 num_pp;
+   __u32 wb[3 * LIMA_PP_WB_REG_NUM];
+   __u32 plbu_array_address[4];
+   __u32 fragment_stack_address[4];
+};
+
+/* frame used to setup mali450 GPU PP for each task */
+struct drm_lima_m450_pp_frame {
+   __u32 frame[LIMA_PP_FRAME_REG_NUM];
+   __u32 num_pp;
+   __u32 wb[3 * LIMA_PP_WB_REG_NUM];
+   __u32 use_dlbu;
+   __u32 _pad;
+   union {
+   __u32 plbu_array_address[8];
+   __u32 dlbu_regs[4];
+   };
+   __u32 fragment_stack_address[8];
+};
+
+#define LIMA_PIPE_GP  0x00
+#define LIMA_PIPE_PP  0x01
+
+#define LIMA_SUBMIT_FLAG_EXPLICIT_FENCE (1 << 0)
+
+/**
+ * submit a task to GPU
+ *
+ * User can always merge multi sync_file and drm_syncobj
+ * into one drm_syncobj as in_sync[0], but we reserve
+ * in_sync[1] for another task's out_sync to avoid the
+ * export/import/merge pass when explicit sync.
+ */
+struct drm_lima_gem_submit {
+   __u32 ctx; /* in, context handle task is submitted to */
+   __u32 pipe;/* in, which pipe to use, GP/PP */
+   __u32 nr_bos;  /* in, array length of bos field */
+   __u32 frame_size;  /* in, size of frame field */
+   __u64 bos; /* in, array of drm_lima_gem_submit_bo */
+   __u64 frame;   /* in, GP/PP frame */
+   __u32 flags;   /* in, submit flags */
+   __u32 out_sync;/* in, drm_syncobj handle used to wait task finish 
after submission */
+   __u32 in_sync[2];  /* in, drm_syncobj handle used to wait before start 
this task */
+};
+
+#define LIMA_GEM_WAIT_READ   0x01
+#define LIMA_GEM_WAIT_WRITE  0x02
+
+/**
+ * wait pending GPU task finish of a buffer
+ */
+struct drm_lima_gem_wait {
+   __u32 handle;  /* in, GEM buffer handle */
+   __u32 op;  /* in, CPU want to read/write this buffer */
+   __s64 timeout_ns;  /* in, wait timeout in absulute time */
+};
+
+/**
+ * create a context
+ */
+struct drm_lima_ctx_create {
+   __u32 id;  /* out, context handle */
+   __u32 _pad;/* pad, must be zero */
+};
+
+/**
+ * free a context
+ */
+struct drm_lima_ctx_free {
+   __u32 id;  /* in, context handle */
+   __u32 _pad;/* pad, must be zero */
+};
+
+#define DRM_LIMA_GET_PARAM   0x00
+#define DRM_LIMA_GEM_CREATE  0x01
+#define DRM_LIMA_GEM_INFO0x02
+#define DRM_LIMA_GEM_SUBMIT  0x03
+#define DRM_LIMA_GEM_WAIT0x04
+#define DRM_LIMA_CTX_CREATE  0x05
+#define DRM_LIMA_CTX_FREE0x06
+
+#define DRM_IOCTL_LIMA_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + 
DRM_LIMA_GET_PARAM, struct drm_lima_get_param)
+#define DRM_IOCT

[Mesa-dev] [PATCH 9/9] kmsro: Add platform support for exynos and sun4i

2019-03-15 Thread Qiang Yu
From: Rob Herring 

Signed-off-by: Rob Herring 
Signed-off-by: Qiang Yu 
---
 src/gallium/targets/dri/meson.build | 2 ++
 src/gallium/targets/dri/target.c| 2 ++
 2 files changed, 4 insertions(+)

diff --git a/src/gallium/targets/dri/meson.build 
b/src/gallium/targets/dri/meson.build
index ff3455592ca..ae417d8ad5b 100644
--- a/src/gallium/targets/dri/meson.build
+++ b/src/gallium/targets/dri/meson.build
@@ -63,6 +63,7 @@ libgallium_dri = shared_library(
 )
 
 foreach d : [[with_gallium_kmsro, [
+   'exynos_dri.so',
'hx8357d_dri.so',
'ili9225_dri.so',
'ili9341_dri.so',
@@ -74,6 +75,7 @@ foreach d : [[with_gallium_kmsro, [
'rockchip_dri.so',
'st7586.so',
'st7735r.so',
+  'sun4i-drm_dri.so',
  ]],
  [with_gallium_radeonsi, 'radeonsi_dri.so'],
  [with_gallium_nouveau, 'nouveau_dri.so'],
diff --git a/src/gallium/targets/dri/target.c b/src/gallium/targets/dri/target.c
index c702058b0c9..ec657de277d 100644
--- a/src/gallium/targets/dri/target.c
+++ b/src/gallium/targets/dri/target.c
@@ -93,6 +93,7 @@ DEFINE_LOADER_DRM_ENTRYPOINT(tegra);
 #endif
 
 #if defined(GALLIUM_KMSRO)
+DEFINE_LOADER_DRM_ENTRYPOINT(exynos)
 DEFINE_LOADER_DRM_ENTRYPOINT(hx8357d)
 DEFINE_LOADER_DRM_ENTRYPOINT(ili9225)
 DEFINE_LOADER_DRM_ENTRYPOINT(ili9341)
@@ -103,6 +104,7 @@ DEFINE_LOADER_DRM_ENTRYPOINT(repaper)
 DEFINE_LOADER_DRM_ENTRYPOINT(rockchip)
 DEFINE_LOADER_DRM_ENTRYPOINT(st7586)
 DEFINE_LOADER_DRM_ENTRYPOINT(st7735r)
+DEFINE_LOADER_DRM_ENTRYPOINT(sun4i_drm)
 #endif
 
 #if defined(GALLIUM_LIMA)
-- 
2.17.1

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

[Mesa-dev] [PATCH 0/9] Lima mesa driver

2019-03-15 Thread Qiang Yu
Mesa Gallium3D driver for ARM Mali 400/450 GPUs.

Lima is still in development and not ready for daily usage,
but can run some simple tests like kmscube and glamrk2, and some
single full screen application like kodi-gbm.

Mesa related EGL/GLX_EXT_buffer_age and EGL_KHR_partial_update
changes are not in this patch series because the solution has
not been settle down yet.

All lima commits are squashed. For whole history of this
driver's development, see:
https://gitlab.freedesktop.org/lima/mesa/commits/lima-18.3
https://gitlab.freedesktop.org/lima/mesa/commits/lima-18.1

Kernel driver is ready to be merged:
https://patchwork.kernel.org/patch/10845911/

This patch series also depends on a kernel patch which is
under review now:
https://patchwork.kernel.org/patch/10852619/

Erico Nunes (1):
  gallium: add a cap to force compute minmax indices

Qiang Yu (6):
  gallium/u_math: add ushort_to_float/float_to_ushort
  nir: add load uniform lower to scalar
  u_dynarray: add util_dynarray_enlarge
  drm-uapi: drm_fourcc.h add ARM GPU modifier
  drm-uapi: add lima_drm.h
  gallium: add lima driver

Rob Herring (2):
  kmsro: Add lima renderonly support
  kmsro: Add platform support for exynos and sun4i

 include/drm-uapi/drm_fourcc.h |   31 +-
 include/drm-uapi/lima_drm.h   |  169 ++
 meson.build   |7 +-
 meson_options.txt |2 +-
 src/compiler/nir/nir_intrinsics.py|4 +-
 src/compiler/nir/nir_lower_io.c   |2 +-
 src/compiler/nir/nir_lower_io_to_scalar.c |   41 +-
 .../auxiliary/pipe-loader/pipe_loader_drm.c   |5 +
 .../auxiliary/target-helpers/drm_helper.h |   23 +
 .../target-helpers/drm_helper_public.h|3 +
 src/gallium/auxiliary/util/u_screen.c |3 +
 src/gallium/drivers/lima/ir/gp/codegen.c  |  619 +++
 src/gallium/drivers/lima/ir/gp/codegen.h  |  166 ++
 src/gallium/drivers/lima/ir/gp/disasm.c   |  568 ++
 src/gallium/drivers/lima/ir/gp/gpir.h |  392 
 src/gallium/drivers/lima/ir/gp/instr.c|  488 +
 src/gallium/drivers/lima/ir/gp/lower.c|  529 ++
 src/gallium/drivers/lima/ir/gp/nir.c  |  420 +
 src/gallium/drivers/lima/ir/gp/node.c |  492 +
 .../drivers/lima/ir/gp/physical_regalloc.c|  135 ++
 .../drivers/lima/ir/gp/reduce_scheduler.c |  220 +++
 src/gallium/drivers/lima/ir/gp/scheduler.c|  809 
 .../drivers/lima/ir/gp/value_regalloc.c   |  170 ++
 src/gallium/drivers/lima/ir/lima_ir.h |   65 +
 src/gallium/drivers/lima/ir/pp/codegen.c  |  669 +++
 src/gallium/drivers/lima/ir/pp/codegen.h  |  359 
 src/gallium/drivers/lima/ir/pp/disasm.c   |  776 
 src/gallium/drivers/lima/ir/pp/instr.c|  311 
 src/gallium/drivers/lima/ir/pp/lower.c|  483 +
 src/gallium/drivers/lima/ir/pp/nir.c  |  497 +
 src/gallium/drivers/lima/ir/pp/node.c |  432 +
 .../drivers/lima/ir/pp/node_to_instr.c|  401 
 src/gallium/drivers/lima/ir/pp/ppir.h |  515 ++
 src/gallium/drivers/lima/ir/pp/regalloc.c |  757 
 src/gallium/drivers/lima/ir/pp/scheduler.c|  197 ++
 src/gallium/drivers/lima/lima_bo.c|  337 
 src/gallium/drivers/lima/lima_bo.h|   66 +
 src/gallium/drivers/lima/lima_context.c   |  262 +++
 src/gallium/drivers/lima/lima_context.h   |  291 +++
 src/gallium/drivers/lima/lima_draw.c  | 1636 +
 src/gallium/drivers/lima/lima_fence.c |  120 ++
 src/gallium/drivers/lima/lima_fence.h |   36 +
 src/gallium/drivers/lima/lima_program.c   |  311 
 src/gallium/drivers/lima/lima_program.h   |   35 +
 src/gallium/drivers/lima/lima_query.c |   96 +
 src/gallium/drivers/lima/lima_resource.c  |  610 ++
 src/gallium/drivers/lima/lima_resource.h  |   86 +
 src/gallium/drivers/lima/lima_screen.c|  554 ++
 src/gallium/drivers/lima/lima_screen.h|   88 +
 src/gallium/drivers/lima/lima_state.c |  516 ++
 src/gallium/drivers/lima/lima_submit.c|  184 ++
 src/gallium/drivers/lima/lima_submit.h|   43 +
 src/gallium/drivers/lima/lima_texture.c   |  278 +++
 src/gallium/drivers/lima/lima_texture.h   |   35 +
 src/gallium/drivers/lima/lima_tiling.c|  184 ++
 src/gallium/drivers/lima/lima_tiling.h|   44 +
 src/gallium/drivers/lima/lima_util.c  |   80 +
 src/gallium/drivers/lima/lima_util.h  |   37 +
 src/gallium/drivers/lima/meson.build  |   87 +
 src/gallium/include/pipe/p_defines.h  |1 +
 src/gallium/meson.build   |6 +
 src/gallium/targets/dri/meson.build   |7 +-
 src/gallium/targets/dri/target.c  |5 +
 .../winsys/kmsro/drm/kmsro_drm_winsys.c   |   11 +
 src/gallium/winsys/kmsro/drm/meson.build  |3 +
 src

[Mesa-dev] [Question] nir_intrinsic_load_uniform use float const_offset now

2019-03-11 Thread Qiang Yu
Hi guys,

When doing rebase from 18.3 to master branch, I found nir_intrinsic_load_uniform
use float const_offset now. But most gallium drivers still treat it as
int except
freedreno.

I don't know which commit did this, is this expected?

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

Re: [Mesa-dev] [PATCH 0/4] Common KMS renderonly support

2019-01-26 Thread Qiang Yu
Sorry, I missed this part of change and thought there's only
kmsro_dri.so. Then there's no concern on my side.

Thanks,
Qiang

Rob Herring  于 2019年1月27日周日 上午3:43写道:

> On Fri, Jan 25, 2019 at 9:00 PM Qiang Yu  wrote:
> >
> > Thanks Rob, I'm OK with this kmsro approach.
> >
> > But I have to point out that this will break XServer AIGLX:
> > 1. modesetting DDX will report the display drm driver name like meson
> >   as DRI2 driver name
> > 2. libglx.so used by xserver will look after meson_dri.so for dlopen
> > 3. then dlsym __driDriverGetExtensions_meson for init
>
> 2 and 3 are now the only things you have to add to add a platform. Now
> it is a 2 line patch to add a platform. Specifically what you have to
> add are shown in the lima branch I sent you.
>
> Rob
>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 0/4] Common KMS renderonly support

2019-01-25 Thread Qiang Yu
Thanks Rob, I'm OK with this kmsro approach.

But I have to point out that this will break XServer AIGLX:
1. modesetting DDX will report the display drm driver name like meson
  as DRI2 driver name
2. libglx.so used by xserver will look after meson_dri.so for dlopen
3. then dlsym __driDriverGetExtensions_meson for init

With this serial applied, 2&3 will not be true any more. This may need
the fix in modesetting or libglx.so.

But as AIGLX is mostly not used, so I'm OK for this serial
go into mesa first, just a remind for somebody who cares.

Regards,
Qiang

On Fri, Jan 25, 2019 at 6:36 AM Rob Herring  wrote:
>
> This series aims to make supporting new platforms containing
> renderonly GPUs easier with less copy-n-paste. This hasn't been a big
> issue so far as the current renderonly drivers (vc4 and etnaviv) only
> exists on a few platforms. This is changing with i.MX+freedreno,
> armada+etnaviv and a slew of platforms using Mali lima and panfrost
> drivers.
>
> I've taken the kmsro winsys from Eric, extended the pipe-loader to
> fall back to kmsro, added etnaviv support, and switched imx to use
> kmsro.
>
> I've tested this with the panfrost tree. Help testing on i.MX would be
> nice. A git branch is here[1].
>
> Rob
>
> [1] https://github.com/robherring/mesa winsys-renderonly
>
> Eric Anholt (1):
>   pl111: Rename the pl111 driver to "kmsro".
>
> Rob Herring (3):
>   pipe-loader: Fallback to kmsro driver when no matching driver name
> found
>   kmsro: Add etnaviv renderonly support
>   Switch imx to kmsro and remove the imx winsys
>
>  .travis.yml   |  2 +-
>  Android.mk|  7 ++-
>  Makefile.am   |  2 +-
>  configure.ac  | 28 ---
>  meson.build   | 12 ++---
>  meson_options.txt |  4 +-
>  src/gallium/Android.mk|  3 +-
>  src/gallium/Makefile.am   |  8 +--
>  .../auxiliary/pipe-loader/pipe_loader_drm.c   | 18 +++
>  .../auxiliary/target-helpers/drm_helper.h | 35 +++--
>  .../target-helpers/drm_helper_public.h|  2 +-
>  src/gallium/drivers/imx/Automake.inc  |  9 
>  .../drivers/{pl111 => kmsro}/Android.mk   |  6 +--
>  src/gallium/drivers/kmsro/Automake.inc|  9 
>  .../drivers/{imx => kmsro}/Makefile.am|  4 +-
>  .../drivers/{pl111 => kmsro}/Makefile.sources |  0
>  src/gallium/drivers/pl111/Automake.inc|  9 
>  src/gallium/drivers/pl111/Makefile.am |  8 ---
>  src/gallium/meson.build   | 23 -
>  src/gallium/targets/dri/Makefile.am   |  3 +-
>  src/gallium/targets/dri/meson.build   |  8 +--
>  src/gallium/targets/dri/target.c  |  2 +-
>  src/gallium/winsys/imx/drm/Android.mk | 40 ---
>  src/gallium/winsys/imx/drm/Makefile.am| 35 -
>  src/gallium/winsys/imx/drm/Makefile.sources   |  3 --
>  src/gallium/winsys/imx/drm/imx_drm_public.h   | 34 -
>  src/gallium/winsys/imx/drm/imx_drm_winsys.c   | 50 ---
>  src/gallium/winsys/imx/drm/meson.build| 33 
>  .../winsys/{pl111 => kmsro}/drm/Android.mk|  2 +-
>  .../winsys/{pl111 => kmsro}/drm/Makefile.am   | 12 -
>  src/gallium/winsys/kmsro/drm/Makefile.sources |  3 ++
>  .../drm/kmsro_drm_public.h}   |  8 +--
>  .../drm/kmsro_drm_winsys.c}   | 42 +++-
>  .../winsys/{pl111 => kmsro}/drm/meson.build   | 23 ++---
>  src/gallium/winsys/pl111/drm/Makefile.sources |  3 --
>  35 files changed, 130 insertions(+), 360 deletions(-)
>  delete mode 100644 src/gallium/drivers/imx/Automake.inc
>  rename src/gallium/drivers/{pl111 => kmsro}/Android.mk (91%)
>  create mode 100644 src/gallium/drivers/kmsro/Automake.inc
>  rename src/gallium/drivers/{imx => kmsro}/Makefile.am (55%)
>  rename src/gallium/drivers/{pl111 => kmsro}/Makefile.sources (100%)
>  delete mode 100644 src/gallium/drivers/pl111/Automake.inc
>  delete mode 100644 src/gallium/drivers/pl111/Makefile.am
>  delete mode 100644 src/gallium/winsys/imx/drm/Android.mk
>  delete mode 100644 src/gallium/winsys/imx/drm/Makefile.am
>  delete mode 100644 src/gallium/winsys/imx/drm/Makefile.sources
>  delete mode 100644 src/gallium/winsys/imx/drm/imx_drm_public.h
>  delete mode 100644 src/gallium/winsys/imx/drm/imx_drm_winsys.c
>  delete mode 100644 src/gallium/winsys/imx/drm/meson.build
>  rename src/gallium/winsys/{pl111 => kmsro}/drm/Android.mk (97%)
>  rename src/gallium/winsys/{pl111 => kmsro}/drm/Makefile.am (87%)
>  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} (63%)
>  rename 

Re: [Mesa-dev] NIR constant problem for GPU which doesn't have native integer support

2019-01-04 Thread Qiang Yu
Thanks for your guys' information, although it's much deeper than my
question and also my understanding of the NIR and compiler knowledge.

This patch fix my problem:
https://patchwork.freedesktop.org/patch/268946/
But seems it's not the final solution, right? And I'm not sure if we will
have other integer problem besides constant for non-integer-gpu, do we?

To be honest, as a backend developer, NIR non-integer-gpu support is
out of my ability. So maybe I have to take this patch temporarily and work
on other topic for sometime to see if any progress of this support in NIR
in the future.

Thanks,
Qiang

On Sat, Jan 5, 2019 at 12:40 AM Ilia Mirkin  wrote:
>
> On Fri, Jan 4, 2019 at 10:46 AM Jason Ekstrand  wrote:
> >
> > On Fri, Jan 4, 2019 at 4:07 AM Erik Faye-Lund 
> >  wrote:
> >>
> >> On Thu, 2019-01-03 at 11:58 -0600, Jason Ekstrand wrote:
> >> > On Thu, Jan 3, 2019 at 3:39 AM Erik Faye-Lund <
> >> > erik.faye-l...@collabora.com> wrote:
> >> > > On Wed, 2019-01-02 at 10:16 -0600, Jason Ekstrand wrote:
> >> > > > On Wed, Jan 2, 2019 at 9:43 AM Ilia Mirkin 
> >> > > > wrote:
> >> > > > > Have a look at the first 4 patches in the series from Jonathan
> >> > > > > Marek
> >> > > > > to address some of these issues:
> >> > > > >
> >> > > > > https://patchwork.freedesktop.org/series/54295/
> >> > > > >
> >> > > > > Not sure exactly what state that work is in, but I've added
> >> > > > > Jonathan
> >> > > > > to CC, perhaps he can provide an update.
> >> > > > >
> >> > > > > Cheers,
> >> > > > >
> >> > > > >   -ilia
> >> > > > >
> >> > > > > On Wed, Jan 2, 2019 at 6:28 AM Qiang Yu 
> >> > > wrote:
> >> > > > > >
> >> > > > > > Hi guys,
> >> > > > > >
> >> > > > > > I found the problem with this test fragment shader when lima
> >> > > > > development:
> >> > > > > > uniform int color;
> >> > > > > > void main() {
> >> > > > > > if (color > 1)
> >> > > > > > gl_FragColor = vec4(1.0, 0.0, 0.0, 1);
> >> > > > > > else
> >> > > > > > gl_FragColor = vec4(0.0, 1.0, 0.0, 1);
> >> > > > > > }
> >> > > > > >
> >> > > > > > nir_print_shader output:
> >> > > > > > impl main {
> >> > > > > > block block_0:
> >> > > > > > /* preds: */
> >> > > > > > vec1 32 ssa_0 = load_const (0x0001 /* 0.00
> >> > > */)
> >> > > > > > vec4 32 ssa_1 = load_const (0x3f80 /* 1.00
> >> > > */,
> >> > > > > > 0x /* 0.00 */, 0x /* 0.00 */,
> >> > > 0x3f80
> >> > > > > /*
> >> > > > > > 1.00 */)
> >> > > > > > vec4 32 ssa_2 = load_const (0x /* 0.00
> >> > > */,
> >> > > > > > 0x3f80 /* 1.00 */, 0x /* 0.00 */,
> >> > > 0x3f80
> >> > > > > /*
> >> > > > > > 1.00 */)
> >> > > > > > vec1 32 ssa_3 = load_const (0x /* 0.00
> >> > > */)
> >> > > > > > vec1 32 ssa_4 = intrinsic load_uniform (ssa_3) (0, 1,
> >> > > 0)
> >> > > > > /*
> >> > > > > > base=0 */ /* range=1 */ /* component=0 */   /* color */
> >> > > > > > vec1 32 ssa_5 = slt ssa_0, ssa_4
> >> > > > > > vec1 32 ssa_6 = fnot ssa_5
> >> > > > > > vec4 32 ssa_7 = bcsel ssa_6., ssa_2, ssa_1
> >> > > > > > intrinsic store_output (ssa_7, ssa_3) (0, 15, 0) /*
> >> > > > > base=0 */
> >> > > > > > /* wrmask=xyzw */ /* component=0 */   /* gl_FragColor */
> >> > > > > > /* succs: block_1 */
> >> > > > > > block block_1:
> >> > > > > > }
> >> > > > > >
> >> > > > > > s

[Mesa-dev] NIR constant problem for GPU which doesn't have native integer support

2019-01-02 Thread Qiang Yu
Hi guys,

I found the problem with this test fragment shader when lima development:
uniform int color;
void main() {
if (color > 1)
gl_FragColor = vec4(1.0, 0.0, 0.0, 1);
else
gl_FragColor = vec4(0.0, 1.0, 0.0, 1);
}

nir_print_shader output:
impl main {
block block_0:
/* preds: */
vec1 32 ssa_0 = load_const (0x0001 /* 0.00 */)
vec4 32 ssa_1 = load_const (0x3f80 /* 1.00 */,
0x /* 0.00 */, 0x /* 0.00 */, 0x3f80 /*
1.00 */)
vec4 32 ssa_2 = load_const (0x /* 0.00 */,
0x3f80 /* 1.00 */, 0x /* 0.00 */, 0x3f80 /*
1.00 */)
vec1 32 ssa_3 = load_const (0x /* 0.00 */)
vec1 32 ssa_4 = intrinsic load_uniform (ssa_3) (0, 1, 0) /*
base=0 */ /* range=1 */ /* component=0 */   /* color */
vec1 32 ssa_5 = slt ssa_0, ssa_4
vec1 32 ssa_6 = fnot ssa_5
vec4 32 ssa_7 = bcsel ssa_6., ssa_2, ssa_1
intrinsic store_output (ssa_7, ssa_3) (0, 15, 0) /* base=0 */
/* wrmask=xyzw */ /* component=0 */   /* gl_FragColor */
/* succs: block_1 */
block block_1:
}

ssa0 is not converted to float when glsl to nir. I see glsl_to_nir.cpp
will create flt/ilt/ult
based on source type for gpu support native integer, but for gpu not
support native
integer, just create slt for all source type. And in
nir_lower_constant_initializers,
there's also no type conversion for integer constant.

Do you know how to fix this problem?

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


[Mesa-dev] [PATCH] loader: decouple USE_DRICONF from HAVE_LIBDRM

2018-08-20 Thread Qiang Yu
For user can use dri_driver drirc option even on
environment without libdrm.

Tested on build with and without libdrm.

Signed-off-by: Qiang Yu 
---
 src/loader/loader.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/loader/loader.c b/src/loader/loader.c
index 2e37d11..22cf320 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -45,11 +45,12 @@
 
 #ifdef HAVE_LIBDRM
 #include 
+#endif
+
 #ifdef USE_DRICONF
 #include "util/xmlconfig.h"
 #include "util/xmlpool.h"
 #endif
-#endif
 
 #define __IS_LOADER
 #include "pci_id_driver_map.h"
@@ -102,7 +103,6 @@ static char *loader_get_kernel_driver_name(int fd)
 #endif
 }
 
-#if defined(HAVE_LIBDRM)
 #ifdef USE_DRICONF
 static const char __driConfigOptionsLoader[] =
 DRI_CONF_BEGIN
@@ -134,7 +134,10 @@ static char *loader_get_dri_config_driver(int fd)
free(kernel_driver);
return dri_driver;
 }
+#endif
 
+#if defined(HAVE_LIBDRM)
+#ifdef USE_DRICONF
 static char *loader_get_dri_config_device_id(void)
 {
driOptionCache defaultInitOptions;
@@ -382,7 +385,7 @@ loader_get_driver_for_fd(int fd)
  return strdup(driver);
}
 
-#if defined(HAVE_LIBDRM) && defined(USE_DRICONF)
+#ifdef USE_DRICONF
driver = loader_get_dri_config_driver(fd);
if (driver)
   return driver;
-- 
2.7.4

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


[Mesa-dev] [PATCH v4 2/6] xmlconfig: read more config files from drirc.d/

2018-08-05 Thread Qiang Yu
Driver and application can put their drirc files in
${datadir}/drirc.d/ with name xxx.conf. Config files
will be read and applied in file name alphabetic order.

So there are three places for drirc listed in order:
1. /usr/share/drirc.d/
2. /etc/drirc
3. ~/.drirc

v4:
  fix meson build

v3:
  1. seperate driParseConfigFiles refine into another patch
  2. fix entries[i] mem leak

v2:
  drop /etc/drirc.d

Signed-off-by: Qiang Yu 
---
 docs/autoconf.html   |  7 +++
 src/util/Makefile.am |  1 +
 src/util/meson.build |  3 +++
 src/util/xmlconfig.c | 42 ++
 4 files changed, 53 insertions(+)

diff --git a/docs/autoconf.html b/docs/autoconf.html
index df243c2..0dd8a7b 100644
--- a/docs/autoconf.html
+++ b/docs/autoconf.html
@@ -94,6 +94,13 @@ Currently there's only one config file provided when dri 
drivers are
 enabled - it's drirc.
 
 
+--datadir=DIR
+This option specifies the directory where the data files will
+be installed. The default is ${prefix}/share.
+Currently when dri drivers are enabled, drirc.d/ is at
+this place.
+
+
 --enable-static, --disable-shared
 By default, Mesa
 will build shared libraries. Either of these options will force static
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index bafb574..8d8c156 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -67,6 +67,7 @@ libxmlconfig_la_CFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src \
-DSYSCONFDIR=\"$(sysconfdir)\" \
+   -DDATADIR=\"$(datadir)\" \
$(VISIBILITY_CFLAGS) \
$(EXPAT_CFLAGS)
 libxmlconfig_la_LIBADD = $(EXPAT_LIBS) -lm
diff --git a/src/util/meson.build b/src/util/meson.build
index 8c91be8..99f2bdd 100644
--- a/src/util/meson.build
+++ b/src/util/meson.build
@@ -123,6 +123,9 @@ libxmlconfig = static_library(
 '-DSYSCONFDIR="@0@"'.format(
   join_paths(get_option('prefix'), get_option('sysconfdir'))
 ),
+'-DDATADIR="@0@"'.format(
+  join_paths(get_option('prefix'), get_option('datadir'))
+),
   ],
   build_by_default : false,
 )
diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c
index 50beede..f12760a 100644
--- a/src/util/xmlconfig.c
+++ b/src/util/xmlconfig.c
@@ -36,6 +36,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include "xmlconfig.h"
 #include "process.h"
 
@@ -928,10 +930,49 @@ parseOneConfigFile(struct OptConfData *data, const char 
*filename)
 XML_ParserFree (p);
 }
 
+static int
+scandir_filter(const struct dirent *ent)
+{
+if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
+   return 0;
+
+if (fnmatch("*.conf", ent->d_name, 0))
+   return 0;
+
+return 1;
+}
+
+/** \brief Parse configuration files in a directory */
+static void
+parseConfigDir(struct OptConfData *data, const char *dirname)
+{
+int i, count;
+struct dirent **entries = NULL;
+
+count = scandir(dirname, , scandir_filter, alphasort);
+if (count < 0)
+return;
+
+for (i = 0; i < count; i++) {
+char filename[PATH_MAX];
+
+snprintf(filename, PATH_MAX, "%s/%s", dirname, entries[i]->d_name);
+free(entries[i]);
+
+parseOneConfigFile(data, filename);
+}
+
+free(entries);
+}
+
 #ifndef SYSCONFDIR
 #define SYSCONFDIR "/etc"
 #endif
 
+#ifndef DATADIR
+#define DATADIR "/usr/share"
+#endif
+
 void
 driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
 int screenNum, const char *driverName)
@@ -946,6 +987,7 @@ driParseConfigFiles(driOptionCache *cache, const 
driOptionCache *info,
 userData.driverName = driverName;
 userData.execName = util_get_process_name();
 
+parseConfigDir(, DATADIR "/drirc.d");
 parseOneConfigFile(, SYSCONFDIR "/drirc");
 
 if ((home = getenv ("HOME"))) {
-- 
2.7.4

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


[Mesa-dev] [PATCH v3 6/6] loader: add dri_driver option to override dri driver to load

2018-08-05 Thread Qiang Yu
drirc implementation of MESA_LOADER_DRIVER_OVERRIDE which can be
used to override dri driver to load.

Usage:

override dri driver for device with spec kernel driver name:


  


or


  


v3:
  1. seperate loader_get_kernel_driver_name into another patch
  2. seperate add kernel_driver attribute into another patch

v2:
  add kernel_driver device attribute to specify kernel
  driver name instead of reuse driver attribute

Suggested-by: Michel Dänzer 
Signed-off-by: Qiang Yu 
---
 src/loader/loader.c  | 34 +-
 src/util/xmlpool/t_options.h |  5 +
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/src/loader/loader.c b/src/loader/loader.c
index 39db094..f9adbe8 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -102,15 +102,41 @@ static char *loader_get_kernel_driver_name(int fd)
 #endif
 }
 
-#if defined(HAVE_LIBDRM)
 #ifdef USE_DRICONF
 static const char __driConfigOptionsLoader[] =
 DRI_CONF_BEGIN
 DRI_CONF_SECTION_INITIALIZATION
 DRI_CONF_DEVICE_ID_PATH_TAG()
+DRI_CONF_DRI_DRIVER()
 DRI_CONF_SECTION_END
 DRI_CONF_END;
 
+static char *loader_get_dri_config_driver(int fd)
+{
+   driOptionCache defaultInitOptions;
+   driOptionCache userInitOptions;
+   char *dri_driver = NULL;
+   char *kernel_driver = loader_get_kernel_driver_name(fd);
+
+   driParseOptionInfo(, __driConfigOptionsLoader);
+   driParseConfigFiles(, , 0,
+   "loader", kernel_driver);
+   if (driCheckOption(, "dri_driver", DRI_STRING)) {
+  char *opt = driQueryOptionstr(, "dri_driver");
+  /* not an empty string */
+  if (*opt)
+ dri_driver = strdup(opt);
+   }
+   driDestroyOptionCache();
+   driDestroyOptionInfo();
+
+   free(kernel_driver);
+   return dri_driver;
+}
+#endif
+
+#if defined(HAVE_LIBDRM)
+#ifdef USE_DRICONF
 static char *loader_get_dri_config_device_id(void)
 {
driOptionCache defaultInitOptions;
@@ -358,6 +384,12 @@ loader_get_driver_for_fd(int fd)
  return strdup(driver);
}
 
+#ifdef USE_DRICONF
+   driver = loader_get_dri_config_driver(fd);
+   if (driver)
+  return driver;
+#endif
+
if (!loader_get_pci_id_for_fd(fd, _id, _id)) {
   driver = loader_get_kernel_driver_name(fd);
   if (driver)
diff --git a/src/util/xmlpool/t_options.h b/src/util/xmlpool/t_options.h
index f0537e9..d4881b3 100644
--- a/src/util/xmlpool/t_options.h
+++ b/src/util/xmlpool/t_options.h
@@ -411,6 +411,11 @@ DRI_CONF_OPT_BEGIN(device_id, string, def) \
 DRI_CONF_DESC(en,gettext("Define the graphic device to use if 
possible")) \
 DRI_CONF_OPT_END
 
+#define DRI_CONF_DRI_DRIVER(def) \
+DRI_CONF_OPT_BEGIN(dri_driver, string, def) \
+DRI_CONF_DESC(en,gettext("Override the DRI driver to load")) \
+DRI_CONF_OPT_END
+
 /**
  * \brief Gallium-Nine specific configuration options
  */
-- 
2.7.4

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


[Mesa-dev] [PATCH v3 5/6] xmlconfig: add kernel_driver device attribute

2018-08-05 Thread Qiang Yu
This attribute can be used by loader to apply different
option to device use specific kernel driver.

Signed-off-by: Qiang Yu 
---
 src/gallium/auxiliary/pipe-loader/pipe_loader.c |  2 +-
 src/gallium/targets/d3dadapter9/drm.c   |  2 +-
 src/loader/loader.c |  2 +-
 src/mesa/drivers/dri/common/dri_util.c  |  2 +-
 src/mesa/drivers/dri/i915/intel_context.c   |  2 +-
 src/mesa/drivers/dri/i965/brw_context.c |  3 ++-
 src/mesa/drivers/dri/i965/intel_screen.c|  3 ++-
 src/mesa/drivers/dri/r200/r200_context.c|  2 +-
 src/mesa/drivers/dri/radeon/radeon_context.c|  2 +-
 src/util/xmlconfig.c| 10 --
 src/util/xmlconfig.h|  7 ---
 11 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.c 
b/src/gallium/auxiliary/pipe-loader/pipe_loader.c
index e7cf9f8..6fd1552 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader.c
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader.c
@@ -108,7 +108,7 @@ pipe_loader_load_options(struct pipe_loader_device *dev)
 
driParseOptionInfo(>option_info, xml_options);
driParseConfigFiles(>option_cache, >option_info, 0,
-   dev->driver_name);
+   dev->driver_name, NULL);
 }
 
 char *
diff --git a/src/gallium/targets/d3dadapter9/drm.c 
b/src/gallium/targets/d3dadapter9/drm.c
index 9c5bd8a..85b3e10 100644
--- a/src/gallium/targets/d3dadapter9/drm.c
+++ b/src/gallium/targets/d3dadapter9/drm.c
@@ -252,7 +252,7 @@ drm_create_adapter( int fd,
 ctx->base.throttling = FALSE;
 
 driParseOptionInfo(, __driConfigOptionsNine);
-driParseConfigFiles(, , 0, "nine");
+driParseConfigFiles(, , 0, "nine", 
NULL);
 if (driCheckOption(, "throttle_value", DRI_INT)) {
 throttling_value_user = driQueryOptioni(, 
"throttle_value");
 if (throttling_value_user == -1)
diff --git a/src/loader/loader.c b/src/loader/loader.c
index c8c7a65..39db094 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -118,7 +118,7 @@ static char *loader_get_dri_config_device_id(void)
char *prime = NULL;
 
driParseOptionInfo(, __driConfigOptionsLoader);
-   driParseConfigFiles(, , 0, "loader");
+   driParseConfigFiles(, , 0, "loader", 
NULL);
if (driCheckOption(, "device_id", DRI_STRING))
   prime = strdup(driQueryOptionstr(, "device_id"));
driDestroyOptionCache();
diff --git a/src/mesa/drivers/dri/common/dri_util.c 
b/src/mesa/drivers/dri/common/dri_util.c
index d257cb6..4649096 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -146,7 +146,7 @@ driCreateNewScreen2(int scrn, int fd,
 
 /* Option parsing before ->InitScreen(), as some options apply there. */
 driParseOptionInfo(>optionInfo, __dri2ConfigOptions);
-driParseConfigFiles(>optionCache, >optionInfo, psp->myNum, 
"dri2");
+driParseConfigFiles(>optionCache, >optionInfo, psp->myNum, 
"dri2", NULL);
 
 *driver_configs = psp->driver->InitScreen(psp);
 if (*driver_configs == NULL) {
diff --git a/src/mesa/drivers/dri/i915/intel_context.c 
b/src/mesa/drivers/dri/i915/intel_context.c
index f22ebbd..9a6e49d 100644
--- a/src/mesa/drivers/dri/i915/intel_context.c
+++ b/src/mesa/drivers/dri/i915/intel_context.c
@@ -448,7 +448,7 @@ intelInitContext(struct intel_context *intel,
  0, sizeof(ctx->TextureFormatSupported));
 
driParseConfigFiles(>optionCache, >optionCache,
-   sPriv->myNum, "i915");
+   sPriv->myNum, "i915", NULL);
intel->maxBatchSize = 4096;
 
/* Estimate the size of the mappable aperture into the GTT.  There's an
diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index 968fc1d..0f65438 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -788,7 +788,8 @@ brw_process_driconf_options(struct brw_context *brw)
 
driOptionCache *options = >optionCache;
driParseConfigFiles(options, >screen->optionCache,
-   brw->driContext->driScreenPriv->myNum, "i965");
+   brw->driContext->driScreenPriv->myNum,
+   "i965", NULL);
 
int bo_reuse_mode = driQueryOptioni(options, "bo_reuse");
switch (bo_reuse_mode) {
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index cb35741..03ed4f2 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -2442,7 +2442,8 @@ __DRIconfig **intelInitScreen2(__DRIscreen *dri_screen)
memset(, 0, sizeof(options));
 

[Mesa-dev] [PATCH v3 4/6] loader: abstract loader_get_kernel_driver_name for reuse

2018-08-05 Thread Qiang Yu
This function can be shared by the following kernel_driver
drirc patch.

Signed-off-by: Qiang Yu 
---
 src/loader/loader.c | 39 +++
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/src/loader/loader.c b/src/loader/loader.c
index 4327548..c8c7a65 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -82,6 +82,26 @@ loader_open_device(const char *device_name)
return fd;
 }
 
+static char *loader_get_kernel_driver_name(int fd)
+{
+#if HAVE_LIBDRM
+   char *driver;
+   drmVersionPtr version = drmGetVersion(fd);
+
+   if (!version) {
+  log_(_LOADER_WARNING, "failed to get driver name for fd %d\n", fd);
+  return NULL;
+   }
+
+   driver = strndup(version->name, version->name_len);
+
+   drmFreeVersion(version);
+   return driver;
+#else
+   return NULL;
+#endif
+}
+
 #if defined(HAVE_LIBDRM)
 #ifdef USE_DRICONF
 static const char __driConfigOptionsLoader[] =
@@ -339,22 +359,9 @@ loader_get_driver_for_fd(int fd)
}
 
if (!loader_get_pci_id_for_fd(fd, _id, _id)) {
-
-#if HAVE_LIBDRM
-  /* fallback to drmGetVersion(): */
-  drmVersionPtr version = drmGetVersion(fd);
-
-  if (!version) {
- log_(_LOADER_WARNING, "failed to get driver name for fd %d\n", fd);
- return NULL;
-  }
-
-  driver = strndup(version->name, version->name_len);
-  log_(_LOADER_INFO, "using driver %s for %d\n", driver, fd);
-
-  drmFreeVersion(version);
-#endif
-
+  driver = loader_get_kernel_driver_name(fd);
+  if (driver)
+ log_(_LOADER_INFO, "using driver %s for %d\n", driver, fd);
   return driver;
}
 
-- 
2.7.4

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


[Mesa-dev] [PATCH v3 3/6] driconf: move ${sysconfdir}/drirc to ${datadir}/drirc.d/00-mesa-defaults.conf

2018-08-05 Thread Qiang Yu
${sysconfdir} is for store admin config files, so move
this mesa default config file to ${datadir}/drirc.d.

Signed-off-by: Qiang Yu 
Reviewed-by: Emil Velikov 
---
 src/util/{drirc => 00-mesa-defaults.conf} | 0
 src/util/Makefile.am  | 5 +++--
 src/util/meson.build  | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
 rename src/util/{drirc => 00-mesa-defaults.conf} (100%)

diff --git a/src/util/drirc b/src/util/00-mesa-defaults.conf
similarity index 100%
rename from src/util/drirc
rename to src/util/00-mesa-defaults.conf
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 8d8c156..efb94ca 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -72,7 +72,8 @@ libxmlconfig_la_CFLAGS = \
$(EXPAT_CFLAGS)
 libxmlconfig_la_LIBADD = $(EXPAT_LIBS) -lm
 
-sysconf_DATA = drirc
+drircdir = $(datadir)/drirc.d
+drirc_DATA = 00-mesa-defaults.conf
 
 u_atomic_test_LDADD = libmesautil.la
 roundeven_test_LDADD = -lm
@@ -84,7 +85,7 @@ TESTS = $(check_PROGRAMS)
 BUILT_SOURCES = $(MESA_UTIL_GENERATED_FILES)
 CLEANFILES = $(BUILT_SOURCES)
 EXTRA_DIST = \
-   drirc \
+   00-mesa-defaults.conf \
format_srgb.py \
merge_driinfo.py \
SConscript \
diff --git a/src/util/meson.build b/src/util/meson.build
index 108524b..16c3ef9 100644
--- a/src/util/meson.build
+++ b/src/util/meson.build
@@ -89,7 +89,7 @@ files_mesa_util = files(
   'vma.h',
 )
 
-install_data('drirc', install_dir : get_option('sysconfdir'))
+install_data('00-mesa-defaults.conf', install_dir : 
join_paths(get_option('datadir'), 'drirc.d'))
 
 files_xmlconfig = files(
   'xmlconfig.c',
-- 
2.7.4

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


[Mesa-dev] [PATCH v3 2/6] xmlconfig: read more config files from drirc.d/

2018-08-05 Thread Qiang Yu
Driver and application can put their drirc files in
${datadir}/drirc.d/ with name xxx.conf. Config files
will be read and applied in file name alphabetic order.

So there are three places for drirc listed in order:
1. /usr/share/drirc.d/
2. /etc/drirc
3. ~/.drirc

v3:
  1. seperate driParseConfigFiles refine into another patch
  2. fix entries[i] mem leak

v2:
  drop /etc/drirc.d

Signed-off-by: Qiang Yu 
---
 docs/autoconf.html   |  7 +++
 src/util/Makefile.am |  1 +
 src/util/meson.build |  4 +++-
 src/util/xmlconfig.c | 42 ++
 4 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/docs/autoconf.html b/docs/autoconf.html
index df243c2..0dd8a7b 100644
--- a/docs/autoconf.html
+++ b/docs/autoconf.html
@@ -94,6 +94,13 @@ Currently there's only one config file provided when dri 
drivers are
 enabled - it's drirc.
 
 
+--datadir=DIR
+This option specifies the directory where the data files will
+be installed. The default is ${prefix}/share.
+Currently when dri drivers are enabled, drirc.d/ is at
+this place.
+
+
 --enable-static, --disable-shared
 By default, Mesa
 will build shared libraries. Either of these options will force static
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index bafb574..8d8c156 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -67,6 +67,7 @@ libxmlconfig_la_CFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src \
-DSYSCONFDIR=\"$(sysconfdir)\" \
+   -DDATADIR=\"$(datadir)\" \
$(VISIBILITY_CFLAGS) \
$(EXPAT_CFLAGS)
 libxmlconfig_la_LIBADD = $(EXPAT_LIBS) -lm
diff --git a/src/util/meson.build b/src/util/meson.build
index 8c91be8..108524b 100644
--- a/src/util/meson.build
+++ b/src/util/meson.build
@@ -121,7 +121,9 @@ libxmlconfig = static_library(
   c_args : [
 c_msvc_compat_args, c_vis_args,
 '-DSYSCONFDIR="@0@"'.format(
-  join_paths(get_option('prefix'), get_option('sysconfdir'))
+  join_paths(get_option('prefix'), get_option('sysconfdir')),
+'-DDATADIR="@0@"'.format(
+  join_paths(get_option('prefix'), get_option('datadir'))
 ),
   ],
   build_by_default : false,
diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c
index 50beede..f12760a 100644
--- a/src/util/xmlconfig.c
+++ b/src/util/xmlconfig.c
@@ -36,6 +36,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include "xmlconfig.h"
 #include "process.h"
 
@@ -928,10 +930,49 @@ parseOneConfigFile(struct OptConfData *data, const char 
*filename)
 XML_ParserFree (p);
 }
 
+static int
+scandir_filter(const struct dirent *ent)
+{
+if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
+   return 0;
+
+if (fnmatch("*.conf", ent->d_name, 0))
+   return 0;
+
+return 1;
+}
+
+/** \brief Parse configuration files in a directory */
+static void
+parseConfigDir(struct OptConfData *data, const char *dirname)
+{
+int i, count;
+struct dirent **entries = NULL;
+
+count = scandir(dirname, , scandir_filter, alphasort);
+if (count < 0)
+return;
+
+for (i = 0; i < count; i++) {
+char filename[PATH_MAX];
+
+snprintf(filename, PATH_MAX, "%s/%s", dirname, entries[i]->d_name);
+free(entries[i]);
+
+parseOneConfigFile(data, filename);
+}
+
+free(entries);
+}
+
 #ifndef SYSCONFDIR
 #define SYSCONFDIR "/etc"
 #endif
 
+#ifndef DATADIR
+#define DATADIR "/usr/share"
+#endif
+
 void
 driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
 int screenNum, const char *driverName)
@@ -946,6 +987,7 @@ driParseConfigFiles(driOptionCache *cache, const 
driOptionCache *info,
 userData.driverName = driverName;
 userData.execName = util_get_process_name();
 
+parseConfigDir(, DATADIR "/drirc.d");
 parseOneConfigFile(, SYSCONFDIR "/drirc");
 
 if ((home = getenv ("HOME"))) {
-- 
2.7.4

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


[Mesa-dev] [PATCH v3 1/6] xmlconfig: refine driParseConfigFiles to use parseOneConfigFile

2018-08-05 Thread Qiang Yu
Also prepare for the usage of following parseConfigDir patch.

Signed-off-by: Qiang Yu 
---
 src/util/xmlconfig.c | 62 
 1 file changed, 28 insertions(+), 34 deletions(-)

diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c
index d384791..50beede 100644
--- a/src/util/xmlconfig.c
+++ b/src/util/xmlconfig.c
@@ -866,9 +866,8 @@ initOptionCache(driOptionCache *cache, const driOptionCache 
*info)
 }
 }
 
-/** \brief Parse the named configuration file */
 static void
-parseOneConfigFile(XML_Parser p)
+_parseOneConfigFile(XML_Parser p)
 {
 #define BUF_SIZE 0x1000
 struct OptConfData *data = (struct OptConfData *)XML_GetUserData (p);
@@ -907,6 +906,28 @@ parseOneConfigFile(XML_Parser p)
 #undef BUF_SIZE
 }
 
+/** \brief Parse the named configuration file */
+static void
+parseOneConfigFile(struct OptConfData *data, const char *filename)
+{
+XML_Parser p;
+
+p = XML_ParserCreate (NULL); /* use encoding specified by file */
+XML_SetElementHandler (p, optConfStartElem, optConfEndElem);
+XML_SetUserData (p, data);
+data->parser = p;
+data->name = filename;
+data->ignoringDevice = 0;
+data->ignoringApp = 0;
+data->inDriConf = 0;
+data->inDevice = 0;
+data->inApp = 0;
+data->inOption = 0;
+
+_parseOneConfigFile (p);
+XML_ParserFree (p);
+}
+
 #ifndef SYSCONFDIR
 #define SYSCONFDIR "/etc"
 #endif
@@ -915,9 +936,7 @@ void
 driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
 int screenNum, const char *driverName)
 {
-char *filenames[2] = { SYSCONFDIR "/drirc", NULL};
 char *home;
-uint32_t i;
 struct OptConfData userData;
 
 initOptionCache (cache, info);
@@ -927,39 +946,14 @@ driParseConfigFiles(driOptionCache *cache, const 
driOptionCache *info,
 userData.driverName = driverName;
 userData.execName = util_get_process_name();
 
+parseOneConfigFile(, SYSCONFDIR "/drirc");
+
 if ((home = getenv ("HOME"))) {
-uint32_t len = strlen (home);
-filenames[1] = malloc(len + 7+1);
-if (filenames[1] == NULL)
-__driUtilMessage ("Can't allocate memory for %s/.drirc.", home);
-else {
-memcpy (filenames[1], home, len);
-memcpy (filenames[1] + len, "/.drirc", 7+1);
-}
-}
+char filename[PATH_MAX];
 
-for (i = 0; i < 2; ++i) {
-XML_Parser p;
-if (filenames[i] == NULL)
-continue;
-
-p = XML_ParserCreate (NULL); /* use encoding specified by file */
-XML_SetElementHandler (p, optConfStartElem, optConfEndElem);
-XML_SetUserData (p, );
-userData.parser = p;
-userData.name = filenames[i];
-userData.ignoringDevice = 0;
-userData.ignoringApp = 0;
-userData.inDriConf = 0;
-userData.inDevice = 0;
-userData.inApp = 0;
-userData.inOption = 0;
-
-parseOneConfigFile (p);
-XML_ParserFree (p);
+snprintf(filename, PATH_MAX, "%s/.drirc", home);
+parseOneConfigFile(, filename);
 }
-
-free(filenames[1]);
 }
 
 void
-- 
2.7.4

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


[Mesa-dev] [PATCH v3 0/6] support config for third-party DRI driver load

2018-08-05 Thread Qiang Yu
This patch series is discussed in thread:
https://lists.freedesktop.org/archives/mesa-dev/2018-July/201348.html

amdgpu-pro driver can use drirc config to override the mesa radeonsi
dri driver so that it can use the mesa libgbm instead of maintain
a customized one.

We also expand drirc config file location to some directory for the
ease of driver and application to add their own config files.

v3:
  1. split more patches
  2. fix dirent mem leak

v2:
  1. remove /etc/drirc.d
  2. move orginal /etc/drirc to /usr/share/drirc.d
  3. add kernel_driver device attribute

Qiang Yu (6):
  xmlconfig: refine driParseConfigFiles to use parseOneConfigFile
  xmlconfig: read more config files from drirc.d/
  driconf: move ${sysconfdir}/drirc to
${datadir}/drirc.d/00-mesa-defaults.conf
  loader: abstract loader_get_kernel_driver_name for reuse
  xmlconfig: add kernel_driver device attribute
  loader: add dri_driver option to override dri driver to load

 docs/autoconf.html  |   7 ++
 src/gallium/auxiliary/pipe-loader/pipe_loader.c |   2 +-
 src/gallium/targets/d3dadapter9/drm.c   |   2 +-
 src/loader/loader.c |  73 +++
 src/mesa/drivers/dri/common/dri_util.c  |   2 +-
 src/mesa/drivers/dri/i915/intel_context.c   |   2 +-
 src/mesa/drivers/dri/i965/brw_context.c |   3 +-
 src/mesa/drivers/dri/i965/intel_screen.c|   3 +-
 src/mesa/drivers/dri/r200/r200_context.c|   2 +-
 src/mesa/drivers/dri/radeon/radeon_context.c|   2 +-
 src/util/{drirc => 00-mesa-defaults.conf}   |   0
 src/util/Makefile.am|   6 +-
 src/util/meson.build|   6 +-
 src/util/xmlconfig.c| 114 
 src/util/xmlconfig.h|   7 +-
 src/util/xmlpool/t_options.h|   5 ++
 16 files changed, 168 insertions(+), 68 deletions(-)
 rename src/util/{drirc => 00-mesa-defaults.conf} (100%)

-- 
2.7.4

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


[Mesa-dev] [PATCH v2 3/3] loader: add drirc option to override dri driver to load

2018-08-03 Thread Qiang Yu
v2:
  add kernel_driver device attribute to specify kernel
  driver name instead of reuse driver attribute.

drirc implementation of MESA_LOADER_DRIVER_OVERRIDE which can be
used to override dri driver to load.

Usage:

override dri driver for device with spec kernel driver name:


  


or


  


Suggested-by: Michel Dänzer 
Signed-off-by: Qiang Yu 
---
 src/gallium/auxiliary/pipe-loader/pipe_loader.c |  2 +-
 src/gallium/targets/d3dadapter9/drm.c   |  2 +-
 src/loader/loader.c | 75 +++--
 src/mesa/drivers/dri/common/dri_util.c  |  2 +-
 src/mesa/drivers/dri/i915/intel_context.c   |  2 +-
 src/mesa/drivers/dri/i965/brw_context.c |  3 +-
 src/mesa/drivers/dri/i965/intel_screen.c|  2 +-
 src/mesa/drivers/dri/r200/r200_context.c|  2 +-
 src/mesa/drivers/dri/radeon/radeon_context.c|  2 +-
 src/util/xmlconfig.c| 10 +++-
 src/util/xmlconfig.h|  3 +-
 src/util/xmlpool/t_options.h|  5 ++
 12 files changed, 82 insertions(+), 28 deletions(-)

diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.c 
b/src/gallium/auxiliary/pipe-loader/pipe_loader.c
index e7cf9f8..6fd1552 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader.c
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader.c
@@ -108,7 +108,7 @@ pipe_loader_load_options(struct pipe_loader_device *dev)
 
driParseOptionInfo(>option_info, xml_options);
driParseConfigFiles(>option_cache, >option_info, 0,
-   dev->driver_name);
+   dev->driver_name, NULL);
 }
 
 char *
diff --git a/src/gallium/targets/d3dadapter9/drm.c 
b/src/gallium/targets/d3dadapter9/drm.c
index 9c5bd8a..85b3e10 100644
--- a/src/gallium/targets/d3dadapter9/drm.c
+++ b/src/gallium/targets/d3dadapter9/drm.c
@@ -252,7 +252,7 @@ drm_create_adapter( int fd,
 ctx->base.throttling = FALSE;
 
 driParseOptionInfo(, __driConfigOptionsNine);
-driParseConfigFiles(, , 0, "nine");
+driParseConfigFiles(, , 0, "nine", 
NULL);
 if (driCheckOption(, "throttle_value", DRI_INT)) {
 throttling_value_user = driQueryOptioni(, 
"throttle_value");
 if (throttling_value_user == -1)
diff --git a/src/loader/loader.c b/src/loader/loader.c
index 4327548..3ad6b36 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -82,15 +82,63 @@ loader_open_device(const char *device_name)
return fd;
 }
 
-#if defined(HAVE_LIBDRM)
+static char *loader_get_kernel_driver_name(int fd)
+{
+#if HAVE_LIBDRM
+   char *driver;
+   drmVersionPtr version = drmGetVersion(fd);
+
+   if (!version) {
+  log_(_LOADER_WARNING, "failed to get driver name for fd %d\n", fd);
+  return NULL;
+   }
+
+   driver = strndup(version->name, version->name_len);
+
+   drmFreeVersion(version);
+   return driver;
+#else
+   return NULL;
+#endif
+}
+
 #ifdef USE_DRICONF
 static const char __driConfigOptionsLoader[] =
 DRI_CONF_BEGIN
 DRI_CONF_SECTION_INITIALIZATION
 DRI_CONF_DEVICE_ID_PATH_TAG()
+DRI_CONF_DRI_DRIVER()
 DRI_CONF_SECTION_END
 DRI_CONF_END;
 
+static char *loader_get_dri_config_driver(int fd)
+{
+   driOptionCache defaultInitOptions;
+   driOptionCache userInitOptions;
+   char *dri_driver = NULL;
+   char *kernel_driver = loader_get_kernel_driver_name(fd);
+
+   driParseOptionInfo(, __driConfigOptionsLoader);
+   driParseConfigFiles(, , 0,
+   "loader", kernel_driver);
+   if (driCheckOption(, "dri_driver", DRI_STRING)) {
+  char *opt = driQueryOptionstr(, "dri_driver");
+  /* not an empty string */
+  if (*opt)
+ dri_driver = strdup(opt);
+   }
+   driDestroyOptionCache();
+   driDestroyOptionInfo();
+
+   if (kernel_driver)
+  free(kernel_driver);
+
+   return dri_driver;
+}
+#endif
+
+#if defined(HAVE_LIBDRM)
+#ifdef USE_DRICONF
 static char *loader_get_dri_config_device_id(void)
 {
driOptionCache defaultInitOptions;
@@ -98,7 +146,7 @@ static char *loader_get_dri_config_device_id(void)
char *prime = NULL;
 
driParseOptionInfo(, __driConfigOptionsLoader);
-   driParseConfigFiles(, , 0, "loader");
+   driParseConfigFiles(, , 0, "loader", 
NULL);
if (driCheckOption(, "device_id", DRI_STRING))
   prime = strdup(driQueryOptionstr(, "device_id"));
driDestroyOptionCache();
@@ -338,23 +386,16 @@ loader_get_driver_for_fd(int fd)
  return strdup(driver);
}
 
-   if (!loader_get_pci_id_for_fd(fd, _id, _id)) {
-
-#if HAVE_LIBDRM
-  /* fallback to drmGetVersion(): */
-  drmVersionPtr version = drmGetVersion(fd);
-
-  if (!version) {
- log_(_LOADER_WARNING, "failed to get driver name for fd %d\n", fd);
- return NULL;
-  }
-
-  driver = strndup(version->name, version->name_len);
-

[Mesa-dev] [PATCH v2 2/3] driconf: move ${sysconfdir}/drirc to ${datadir}/drirc.d/00-mesa-defaults.conf

2018-08-03 Thread Qiang Yu
${sysconfdir} is for store admin config files, so move
this mesa default config file to ${datadir}/drirc.d.

Signed-off-by: Qiang Yu 
---
 src/util/00-mesa-defaults.conf | 314 +
 src/util/Makefile.am   |   5 +-
 src/util/drirc | 314 -
 src/util/meson.build   |   2 +-
 4 files changed, 318 insertions(+), 317 deletions(-)
 create mode 100644 src/util/00-mesa-defaults.conf
 delete mode 100644 src/util/drirc

diff --git a/src/util/00-mesa-defaults.conf b/src/util/00-mesa-defaults.conf
new file mode 100644
index 000..8ece875
--- /dev/null
+++ b/src/util/00-mesa-defaults.conf
@@ -0,0 +1,314 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 8d8c156..efb94ca 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -72,7 +72,8 @@ libxmlconfig_la_CFLAGS = \
$(EXPAT_CFLAGS)
 libxmlconfig_la_LIBADD = $(EXPAT_LIBS) -lm
 
-sysconf_DATA = drirc
+drircdir = $(datadir)/drirc.d
+drirc_DATA = 00-mesa-defaults.conf
 
 u_atomic_test_LDADD = libmesautil.la
 roundeven_test_LDADD = -lm
@@ -84,7 +85,7 @@ TESTS = $(check_PROGRAMS)
 BUILT_SOURCES = $(MESA_UTIL_GENERATED_FILES)
 CLEANFILES = $(BUILT_SOURCES)
 EXTRA_DIST = \
-   drirc \
+   00-mesa-defaults.conf \
format_srgb.py \
merge_driinfo.py \
SConscript \
diff --git a/src/util/drirc b/src/util/drirc
deleted file mode 100644
index 8ece875..000
--- a/src/util/drirc
+++ /dev/null
@@ -1,314 +0,0

[Mesa-dev] [PATCH v2 1/3] xmlconfig: read more config files from drirc.d/

2018-08-03 Thread Qiang Yu
v2:
  drop /etc/drirc.d

Driver and application can put their drirc files in
${datadir}/drirc.d/ with name xxx.conf. Config files
will be read and applied in file name alphabete order.

So there are three places for drirc listed in order:
1. /usr/share/drirc.d/
2. /etc/drirc
3. ~/.drirc

Signed-off-by: Qiang Yu 
---
 docs/autoconf.html   |   7 
 src/util/Makefile.am |   1 +
 src/util/meson.build |   4 +-
 src/util/xmlconfig.c | 103 ++-
 4 files changed, 80 insertions(+), 35 deletions(-)

diff --git a/docs/autoconf.html b/docs/autoconf.html
index df243c2..0dd8a7b 100644
--- a/docs/autoconf.html
+++ b/docs/autoconf.html
@@ -94,6 +94,13 @@ Currently there's only one config file provided when dri 
drivers are
 enabled - it's drirc.
 
 
+--datadir=DIR
+This option specifies the directory where the data files will
+be installed. The default is ${prefix}/share.
+Currently when dri drivers are enabled, drirc.d/ is at
+this place.
+
+
 --enable-static, --disable-shared
 By default, Mesa
 will build shared libraries. Either of these options will force static
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index bafb574..8d8c156 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -67,6 +67,7 @@ libxmlconfig_la_CFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src \
-DSYSCONFDIR=\"$(sysconfdir)\" \
+   -DDATADIR=\"$(datadir)\" \
$(VISIBILITY_CFLAGS) \
$(EXPAT_CFLAGS)
 libxmlconfig_la_LIBADD = $(EXPAT_LIBS) -lm
diff --git a/src/util/meson.build b/src/util/meson.build
index 8c91be8..108524b 100644
--- a/src/util/meson.build
+++ b/src/util/meson.build
@@ -121,7 +121,9 @@ libxmlconfig = static_library(
   c_args : [
 c_msvc_compat_args, c_vis_args,
 '-DSYSCONFDIR="@0@"'.format(
-  join_paths(get_option('prefix'), get_option('sysconfdir'))
+  join_paths(get_option('prefix'), get_option('sysconfdir')),
+'-DDATADIR="@0@"'.format(
+  join_paths(get_option('prefix'), get_option('datadir'))
 ),
   ],
   build_by_default : false,
diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c
index d384791..120c6cf 100644
--- a/src/util/xmlconfig.c
+++ b/src/util/xmlconfig.c
@@ -36,6 +36,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include "xmlconfig.h"
 #include "process.h"
 
@@ -866,9 +868,8 @@ initOptionCache(driOptionCache *cache, const driOptionCache 
*info)
 }
 }
 
-/** \brief Parse the named configuration file */
 static void
-parseOneConfigFile(XML_Parser p)
+_parseOneConfigFile(XML_Parser p)
 {
 #define BUF_SIZE 0x1000
 struct OptConfData *data = (struct OptConfData *)XML_GetUserData (p);
@@ -907,17 +908,75 @@ parseOneConfigFile(XML_Parser p)
 #undef BUF_SIZE
 }
 
+/** \brief Parse the named configuration file */
+static void
+parseOneConfigFile(struct OptConfData *data, const char *filename)
+{
+XML_Parser p;
+
+p = XML_ParserCreate (NULL); /* use encoding specified by file */
+XML_SetElementHandler (p, optConfStartElem, optConfEndElem);
+XML_SetUserData (p, data);
+data->parser = p;
+data->name = filename;
+data->ignoringDevice = 0;
+data->ignoringApp = 0;
+data->inDriConf = 0;
+data->inDevice = 0;
+data->inApp = 0;
+data->inOption = 0;
+
+_parseOneConfigFile (p);
+XML_ParserFree (p);
+}
+
+static int
+scandir_filter(const struct dirent *ent)
+{
+if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
+   return 0;
+
+if (fnmatch("*.conf", ent->d_name, 0))
+   return 0;
+
+return 1;
+}
+
+/** \brief Parse configuration files in a directory */
+static void
+parseConfigDir(struct OptConfData *data, const char *dirname)
+{
+int i, count;
+struct dirent **entries = NULL;
+
+count = scandir(dirname, , scandir_filter, alphasort);
+if (count < 0)
+return;
+
+for (i = 0; i < count; i++) {
+char filename[PATH_MAX];
+
+snprintf(filename, PATH_MAX, "%s/%s", dirname, entries[i]->d_name);
+parseOneConfigFile(data, filename);
+}
+
+if (entries)
+free(entries);
+}
+
 #ifndef SYSCONFDIR
 #define SYSCONFDIR "/etc"
 #endif
 
+#ifndef DATADIR
+#define DATADIR "/usr/share"
+#endif
+
 void
 driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
 int screenNum, const char *driverName)
 {
-char *filenames[2] = { SYSCONFDIR "/drirc", NULL};
 char *home;
-uint32_t i;
 struct OptConfData userData;
 
 initOptionCache (cache, info);
@@ -927,39 +986,15 @@ driParseConfigFiles(driOptionCache *cache, const 
driOptionCache *info,
 userData.driverName = driverName;
 userData.execName = util_get_process_name();
 
+parseConfigDir(, DATADIR "/drirc.d");
+parseOneConfigFile(, SYSCONFDIR "/drirc");
+
   

[Mesa-dev] [PATCH v2 0/3] support config for third-party DRI driver load

2018-08-03 Thread Qiang Yu
v2:
  1. remove /etc/drirc.d
  2. move orginal /etc/drirc to /usr/share/drirc.d
  3. add kernel_driver device attribute

This patch series is discussed in thread:
https://lists.freedesktop.org/archives/mesa-dev/2018-July/201348.html

amdgpu-pro driver can use drirc config to override the mesa radeonsi
dri driver so that it can use the mesa libgbm instead of maintain
a customized one.

We also expand drirc config file location to some directory for the
ease of driver and application to add their own config files.

Qiang Yu (3):
  xmlconfig: read more config files from drirc.d/
  driconf: move ${sysconfdir}/drirc to
${datadir}/drirc.d/00-mesa-defaults.conf
  loader: add drirc option to override dri driver to load

 docs/autoconf.html  |   7 +
 src/gallium/auxiliary/pipe-loader/pipe_loader.c |   2 +-
 src/gallium/targets/d3dadapter9/drm.c   |   2 +-
 src/loader/loader.c |  75 --
 src/mesa/drivers/dri/common/dri_util.c  |   2 +-
 src/mesa/drivers/dri/i915/intel_context.c   |   2 +-
 src/mesa/drivers/dri/i965/brw_context.c |   3 +-
 src/mesa/drivers/dri/i965/intel_screen.c|   2 +-
 src/mesa/drivers/dri/r200/r200_context.c|   2 +-
 src/mesa/drivers/dri/radeon/radeon_context.c|   2 +-
 src/util/00-mesa-defaults.conf  | 314 
 src/util/Makefile.am|   6 +-
 src/util/drirc  | 314 
 src/util/meson.build|   6 +-
 src/util/xmlconfig.c| 113 ++---
 src/util/xmlconfig.h|   3 +-
 src/util/xmlpool/t_options.h|   5 +
 17 files changed, 480 insertions(+), 380 deletions(-)
 create mode 100644 src/util/00-mesa-defaults.conf
 delete mode 100644 src/util/drirc

-- 
2.7.4

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


[Mesa-dev] [PATCH 0/2] support config for third-party DRI driver load

2018-08-01 Thread Qiang Yu
This patch series is discussed in thread:
https://lists.freedesktop.org/archives/mesa-dev/2018-July/201348.html

amdgpu-pro driver can use drirc config to override the mesa radeonsi
dri driver so that it can use the mesa libgbm instead of maintain
a customized one.

We also expand drirc config file location to some directories for the
ease of driver and application to add their own config files.

Qiang Yu (2):
  xmlconfig: read more config files from drirc.d/
  loader: add dri_driver drirc option to override dri driver to load

 docs/autoconf.html   |  11 -
 src/loader/loader.c  |  75 ---
 src/util/Makefile.am |   1 +
 src/util/meson.build |   4 +-
 src/util/xmlconfig.c | 104 +--
 src/util/xmlpool/t_options.h |   5 +++
 6 files changed, 147 insertions(+), 53 deletions(-)

-- 
2.7.4

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


[Mesa-dev] [PATCH 1/2] xmlconfig: read more config files from drirc.d/

2018-08-01 Thread Qiang Yu
Add two places for hosting drirc config files:
/usr/share/drirc.d/ /etc/drirc.d/

Driver and application can put their drirc files in
these places with name xxx.conf. Config files will be
read and applied in file name alphabete order.

So there are four places for drirc listed in order:
1. /usr/share/drirc.d/
2. /etc/drirc.d/
3. /etc/drirc
4. ~/.drirc

Signed-off-by: Qiang Yu 
---
 docs/autoconf.html   |  11 +-
 src/util/Makefile.am |   1 +
 src/util/meson.build |   4 +-
 src/util/xmlconfig.c | 104 ++-
 4 files changed, 83 insertions(+), 37 deletions(-)

diff --git a/docs/autoconf.html b/docs/autoconf.html
index df243c2..5f1a006 100644
--- a/docs/autoconf.html
+++ b/docs/autoconf.html
@@ -90,8 +90,15 @@ tree.
 --sysconfdir=DIR
 This option specifies the directory where the configuration
 files will be installed. The default is ${prefix}/etc.
-Currently there's only one config file provided when dri drivers are
-enabled - it's drirc.
+Currently when dri drivers are enabled, drirc drirc.d/
+are in this place.
+
+
+--datadir=DIR
+This option specifies the directory where the data files will
+be installed. The default is ${prefix}/share.
+Currently when dri drivers are enabled, drirc.d/ is at
+this place.
 
 
 --enable-static, --disable-shared
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index bafb574..8d8c156 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -67,6 +67,7 @@ libxmlconfig_la_CFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src \
-DSYSCONFDIR=\"$(sysconfdir)\" \
+   -DDATADIR=\"$(datadir)\" \
$(VISIBILITY_CFLAGS) \
$(EXPAT_CFLAGS)
 libxmlconfig_la_LIBADD = $(EXPAT_LIBS) -lm
diff --git a/src/util/meson.build b/src/util/meson.build
index 8c91be8..108524b 100644
--- a/src/util/meson.build
+++ b/src/util/meson.build
@@ -121,7 +121,9 @@ libxmlconfig = static_library(
   c_args : [
 c_msvc_compat_args, c_vis_args,
 '-DSYSCONFDIR="@0@"'.format(
-  join_paths(get_option('prefix'), get_option('sysconfdir'))
+  join_paths(get_option('prefix'), get_option('sysconfdir')),
+'-DDATADIR="@0@"'.format(
+  join_paths(get_option('prefix'), get_option('datadir'))
 ),
   ],
   build_by_default : false,
diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c
index d384791..a3869ac 100644
--- a/src/util/xmlconfig.c
+++ b/src/util/xmlconfig.c
@@ -36,6 +36,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include "xmlconfig.h"
 #include "process.h"
 
@@ -866,9 +868,8 @@ initOptionCache(driOptionCache *cache, const driOptionCache 
*info)
 }
 }
 
-/** \brief Parse the named configuration file */
 static void
-parseOneConfigFile(XML_Parser p)
+_parseOneConfigFile(XML_Parser p)
 {
 #define BUF_SIZE 0x1000
 struct OptConfData *data = (struct OptConfData *)XML_GetUserData (p);
@@ -907,17 +908,75 @@ parseOneConfigFile(XML_Parser p)
 #undef BUF_SIZE
 }
 
+/** \brief Parse the named configuration file */
+static void
+parseOneConfigFile(struct OptConfData *data, const char *filename)
+{
+XML_Parser p;
+
+p = XML_ParserCreate (NULL); /* use encoding specified by file */
+XML_SetElementHandler (p, optConfStartElem, optConfEndElem);
+XML_SetUserData (p, data);
+data->parser = p;
+data->name = filename;
+data->ignoringDevice = 0;
+data->ignoringApp = 0;
+data->inDriConf = 0;
+data->inDevice = 0;
+data->inApp = 0;
+data->inOption = 0;
+
+_parseOneConfigFile (p);
+XML_ParserFree (p);
+}
+
+static int
+scandir_filter(const struct dirent *ent)
+{
+if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
+   return 0;
+
+if (fnmatch("*.conf", ent->d_name, 0))
+   return 0;
+
+return 1;
+}
+
+/** \brief Parse configuration files in a directory */
+static void
+parseConfigDir(struct OptConfData *data, const char *dirname)
+{
+int i, count;
+struct dirent **entries = NULL;
+
+count = scandir(dirname, , scandir_filter, alphasort);
+if (count < 0)
+return;
+
+for (i = 0; i < count; i++) {
+char filename[PATH_MAX];
+
+snprintf(filename, PATH_MAX, "%s/%s", dirname, entries[i]->d_name);
+parseOneConfigFile(data, filename);
+}
+
+if (entries)
+free(entries);
+}
+
 #ifndef SYSCONFDIR
 #define SYSCONFDIR "/etc"
 #endif
 
+#ifndef DATADIR
+#define DATADIR "/usr/share"
+#endif
+
 void
 driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
 int screenNum, const char *driverName)
 {
-char *filenames[2] = { SYSCONFDIR "/drirc", NULL};
 char *home;
-uint32_t i;
 struct OptConfData userData;
 
 initOptionCache (cache, info);
@@ -927,39 +986,16 @@ driParseConfigFiles(driOptionCache *cache, const 
driOptionCache *info,
 userData.dr

[Mesa-dev] [PATCH 2/2] loader: add dri_driver drirc option to override dri driver to load

2018-08-01 Thread Qiang Yu
drirc implementation of MESA_LOADER_DRIVER_OVERRIDE which can be
used to override dri driver to load.

Usage:

override dri driver for device with spec kernel driver name:

  


Signed-off-by: Qiang Yu 
---
 src/loader/loader.c  | 75 ++--
 src/util/xmlpool/t_options.h |  5 +++
 2 files changed, 64 insertions(+), 16 deletions(-)

diff --git a/src/loader/loader.c b/src/loader/loader.c
index 4327548..8c78096 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -82,15 +82,65 @@ loader_open_device(const char *device_name)
return fd;
 }
 
-#if defined(HAVE_LIBDRM)
+static char *loader_get_kernel_driver_name(int fd)
+{
+#if HAVE_LIBDRM
+   char *driver;
+   drmVersionPtr version = drmGetVersion(fd);
+
+   if (!version) {
+  log_(_LOADER_WARNING, "failed to get driver name for fd %d\n", fd);
+  return NULL;
+   }
+
+   driver = strndup(version->name, version->name_len);
+
+   drmFreeVersion(version);
+   return driver;
+#else
+   return NULL;
+#endif
+}
+
 #ifdef USE_DRICONF
 static const char __driConfigOptionsLoader[] =
 DRI_CONF_BEGIN
 DRI_CONF_SECTION_INITIALIZATION
 DRI_CONF_DEVICE_ID_PATH_TAG()
+DRI_CONF_DRI_DRIVER()
 DRI_CONF_SECTION_END
 DRI_CONF_END;
 
+static char *loader_get_dri_config_driver(int fd)
+{
+   driOptionCache defaultInitOptions;
+   driOptionCache userInitOptions;
+   char driver[32] = "k:null";
+   char *dri_driver = NULL;
+   char *kernel_driver = loader_get_kernel_driver_name(fd);
+
+   if (kernel_driver) {
+  snprintf(driver, 32, "k:%s", kernel_driver);
+  free(kernel_driver);
+   }
+
+   driParseOptionInfo(, __driConfigOptionsLoader);
+   driParseConfigFiles(, , 0, driver);
+   if (driCheckOption(, "dri_driver", DRI_STRING)) {
+  char *opt = driQueryOptionstr(, "dri_driver");
+  /* not an empty string */
+  if (*opt)
+ dri_driver = strdup(opt);
+   }
+   driDestroyOptionCache();
+   driDestroyOptionInfo();
+
+   return dri_driver;
+}
+#endif
+
+#if defined(HAVE_LIBDRM)
+#ifdef USE_DRICONF
 static char *loader_get_dri_config_device_id(void)
 {
driOptionCache defaultInitOptions;
@@ -338,23 +388,16 @@ loader_get_driver_for_fd(int fd)
  return strdup(driver);
}
 
-   if (!loader_get_pci_id_for_fd(fd, _id, _id)) {
-
-#if HAVE_LIBDRM
-  /* fallback to drmGetVersion(): */
-  drmVersionPtr version = drmGetVersion(fd);
-
-  if (!version) {
- log_(_LOADER_WARNING, "failed to get driver name for fd %d\n", fd);
- return NULL;
-  }
-
-  driver = strndup(version->name, version->name_len);
-  log_(_LOADER_INFO, "using driver %s for %d\n", driver, fd);
-
-  drmFreeVersion(version);
+#ifdef USE_DRICONF
+   driver = loader_get_dri_config_driver(fd);
+   if (driver)
+  return driver;
 #endif
 
+   if (!loader_get_pci_id_for_fd(fd, _id, _id)) {
+  driver = loader_get_kernel_driver_name(fd);
+  if (driver)
+ log_(_LOADER_INFO, "using driver %s for %d\n", driver, fd);
   return driver;
}
 
diff --git a/src/util/xmlpool/t_options.h b/src/util/xmlpool/t_options.h
index f0537e9..d4881b3 100644
--- a/src/util/xmlpool/t_options.h
+++ b/src/util/xmlpool/t_options.h
@@ -411,6 +411,11 @@ DRI_CONF_OPT_BEGIN(device_id, string, def) \
 DRI_CONF_DESC(en,gettext("Define the graphic device to use if 
possible")) \
 DRI_CONF_OPT_END
 
+#define DRI_CONF_DRI_DRIVER(def) \
+DRI_CONF_OPT_BEGIN(dri_driver, string, def) \
+DRI_CONF_DESC(en,gettext("Override the DRI driver to load")) \
+DRI_CONF_OPT_END
+
 /**
  * \brief Gallium-Nine specific configuration options
  */
-- 
2.7.4

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


Re: [Mesa-dev] [PATCH v2] egl: Fix missing clamping in eglSetDamageRegionKHR

2018-07-14 Thread Qiang Yu
Looks good for me.
Reviewed-by: Qiang Yu 

Regards,
Qiang
On Thu, Jul 12, 2018 at 12:28 AM Harish Krupo
 wrote:
>
>
> Harish Krupo  writes:
>
> > Clamp the x and y co-ordinates of the rectangles.
> >
> > v2: Clamp width/height after converting to co-ordinates
> > (Ilia Merkin)
> >
> > Signed-off-by: Harish Krupo 
> > ---
> >  src/egl/main/eglapi.c | 25 +++--
> >  1 file changed, 11 insertions(+), 14 deletions(-)
> >
> > diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
> > index c110349119..deb479b6d5 100644
> > --- a/src/egl/main/eglapi.c
> > +++ b/src/egl/main/eglapi.c
> > @@ -1320,9 +1320,7 @@ eglSwapBuffersWithDamageKHR(EGLDisplay dpy, 
> > EGLSurface surface,
> >  }
> >
> >  /**
> > - * If the width of the passed rect is greater than the surface's
> > - * width then it is clamped to the width of the surface. Same with
> > - * height.
> > + * Clamp the rectangles so that they lie within the surface.
> >   */
> >
> >  static void
> > @@ -1334,17 +1332,16 @@ _eglSetDamageRegionKHRClampRects(_EGLDisplay* disp, 
> > _EGLSurface* surf,
> > EGLint surf_width = surf->Width;
> >
> > for (i = 0; i < (4 * n_rects); i += 4) {
> > -  EGLint x, y, rect_width, rect_height;
> > -  x = rects[i];
> > -  y = rects[i + 1];
> > -  rect_width = rects[i + 2];
> > -  rect_height = rects[i + 3];
> > -
> > -  if (rect_width > surf_width - x)
> > - rects[i + 2] = surf_width - x;
> > -
> > -  if (rect_height > surf_height - y)
> > - rects[i + 3] = surf_height - y;
> > +  EGLint x1, y1, x2, y2;
> > +  x1 = rects[i];
> > +  y1 = rects[i + 1];
> > +  x2 = rects[i + 2] + x1;
> > +  y2 = rects[i + 3] + y1;
> > +
> > +  rects[i] = CLAMP(x1, 0, surf_width);
> > +  rects[i + 1] = CLAMP(y1, 0, surf_height);
> > +  rects[i + 2] = CLAMP(x2, 0, surf_width) - rects[i];
> > +  rects[i + 3] = CLAMP(y2, 0, surf_height) - rects[i + 1];
> > }
> >  }
>
> Gentle ping :)
>
> Thank you
> Regards
> Harish Krupo
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH rfc 0/3] Be able to disable EGL/GLX_EXT_buffer_age

2018-07-05 Thread Qiang Yu
On Fri, Jul 6, 2018 at 6:20 AM Eric Anholt  wrote:
>
> Qiang Yu  writes:
>
> > Hi Emil,
> >
> > On Thu, Jul 5, 2018 at 9:54 PM Emil Velikov  
> > wrote:
> >>
> >> On 5 July 2018 at 14:31, Emil Velikov  wrote:
> >> > Hi Qiang Yu
> >> >
> >> > On 5 July 2018 at 03:31, Qiang Yu  wrote:
> >> >> For GPU like ARM mali Utgard EGL/GLX_EXT_buffer_age will make
> >> >> performace worse. But mesa has no way to disable it.
> >> >>
> >> >> This patch series make driver be able to disable it and add a
> >> >> gallium pipe cap for gallium driver usage. Due to currently
> >> >> only out of tree lima driver need it, and not sure if this is
> >> >> the right way to disable it, so I send this RFC before lima be
> >> >> able to upstream.
> >> >>
> >> > Pretty sure we already have a way to handle that. Look for
> >> > glx_disable_ext_buffer_age - it was introduced for the VMWare driver.
> >> > Although we should:
> >> > a) tweak the name - kind of split if we need to
> >> > b) add glx/dri2 and egl support
> >> >
> >> Looking at the implementation - it uses a driver query, meaning that
> >> one could enable it at a later stage.
> >> No need to worry if the user has old drirc/etc as with current solution.
> >
> > Yes, use drirc to disable buffer age means it can be enabled by changing
> > the config (driver has to support it). But GPU like mali just don't want to
> > support it at all (need extra code do bad things).
>
> You must have the ability to load back into the tile buffer, so I think
> the driver should continue to support buffer age.  You don't know the
> complexity of recreating their whole frame, that decision should be up
> to them.
Yeah, mali can load back into the tile buffer. But buffer age ext has no
way to tell how much partial draw cost for different GPU, expose it
just tell application partial draw is cheaper.

Regards,
Qiang

> That said, it would be really nice for EGL to decide not to
> preserve buffers (and emit the resource invalidate call through gallium)
> when the client hasn't asked for a buffer age recently, and then just
> report the undefined buffer age value the first time they ask for it.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH rfc 0/3] Be able to disable EGL/GLX_EXT_buffer_age

2018-07-05 Thread Qiang Yu
Hi Emil,

On Thu, Jul 5, 2018 at 9:54 PM Emil Velikov  wrote:
>
> On 5 July 2018 at 14:31, Emil Velikov  wrote:
> > Hi Qiang Yu
> >
> > On 5 July 2018 at 03:31, Qiang Yu  wrote:
> >> For GPU like ARM mali Utgard EGL/GLX_EXT_buffer_age will make
> >> performace worse. But mesa has no way to disable it.
> >>
> >> This patch series make driver be able to disable it and add a
> >> gallium pipe cap for gallium driver usage. Due to currently
> >> only out of tree lima driver need it, and not sure if this is
> >> the right way to disable it, so I send this RFC before lima be
> >> able to upstream.
> >>
> > Pretty sure we already have a way to handle that. Look for
> > glx_disable_ext_buffer_age - it was introduced for the VMWare driver.
> > Although we should:
> > a) tweak the name - kind of split if we need to
> > b) add glx/dri2 and egl support
> >
> Looking at the implementation - it uses a driver query, meaning that
> one could enable it at a later stage.
> No need to worry if the user has old drirc/etc as with current solution.

Yes, use drirc to disable buffer age means it can be enabled by changing
the config (driver has to support it). But GPU like mali just don't want to
support it at all (need extra code do bad things).

Regards,
Qiang

>
> Having two ways of doing the same thing is a bad idea.
> Perhaps we can remove the drirc implementation and use this instead?
>
> Thomas, what do you think?
>
> Thanks
> Emil
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 0/3] Rectify KHR_partial_update extension implementation

2018-07-05 Thread Qiang Yu
Series is:
Reviewed-by: Qiang Yu 

Regards,
Qiang
On Wed, Jul 4, 2018 at 8:58 PM Harish Krupo  wrote:
>
> Based on the discussion in the thread starting at:
> https://lists.freedesktop.org/archives/mesa-dev/2018-June/198846.html
> it was identified that the implementation of the KHR_partial_update
> was incorrect and in that the damages were sent to the egl backends
> instead of the driver. This patch series removes that implementation
> and adds an interface for drivers to implement so that the damage can
> be reported to the drivers and the rendering can be restricted to those
> damage rectangles.
>
> Harish Krupo (3):
>   egl/android: Delete set_damage_region from egl dri vtbl
>   dri_interface: add an interface for setting damage region
>   egl/dri: Use __DRI2_DAMAGE extension for KHR_partial_update
>
>  include/GL/internal/dri_interface.h | 25 +++
>  src/egl/drivers/dri2/egl_dri2.c | 46 +++--
>  src/egl/drivers/dri2/egl_dri2.h |  5 +--
>  src/egl/drivers/dri2/egl_dri2_fallbacks.h   |  9 
>  src/egl/drivers/dri2/platform_android.c | 45 
>  src/egl/drivers/dri2/platform_drm.c |  1 -
>  src/egl/drivers/dri2/platform_surfaceless.c |  1 -
>  src/egl/drivers/dri2/platform_wayland.c |  1 -
>  src/egl/drivers/dri2/platform_x11.c |  2 -
>  src/egl/drivers/dri2/platform_x11_dri3.c|  1 -
>  10 files changed, 68 insertions(+), 68 deletions(-)
>
> --
> 2.18.0
>
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH rfc 2/3] gallium: add PIPE_CAP_BUFFER_AGE

2018-07-04 Thread Qiang Yu
For gallium drivers to expose EGL/GLX_EXT_buffer_age.

Signed-off-by: Qiang Yu 
---
 src/gallium/docs/source/screen.rst  | 1 +
 src/gallium/drivers/etnaviv/etnaviv_screen.c| 1 +
 src/gallium/drivers/freedreno/freedreno_screen.c| 1 +
 src/gallium/drivers/i915/i915_screen.c  | 1 +
 src/gallium/drivers/llvmpipe/lp_screen.c| 1 +
 src/gallium/drivers/nouveau/nv30/nv30_screen.c  | 1 +
 src/gallium/drivers/nouveau/nv50/nv50_screen.c  | 1 +
 src/gallium/drivers/nouveau/nvc0/nvc0_screen.c  | 1 +
 src/gallium/drivers/r300/r300_screen.c  | 1 +
 src/gallium/drivers/r600/r600_pipe.c| 1 +
 src/gallium/drivers/radeonsi/si_get.c   | 1 +
 src/gallium/drivers/softpipe/sp_screen.c| 1 +
 src/gallium/drivers/svga/svga_screen.c  | 1 +
 src/gallium/drivers/swr/swr_screen.cpp  | 1 +
 src/gallium/drivers/vc4/vc4_screen.c| 1 +
 src/gallium/drivers/vc5/vc5_screen.c| 1 +
 src/gallium/drivers/virgl/virgl_screen.c| 2 ++
 src/gallium/include/pipe/p_defines.h| 1 +
 src/gallium/state_trackers/dri/dri_query_renderer.c | 4 +++-
 19 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index 3837360fb4..427944bf70 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -420,6 +420,7 @@ The integer capabilities:
   by the driver, and the driver can throw assertion failures.
 * ``PIPE_CAP_PACKED_UNIFORMS``: True if the driver supports packed uniforms
   as opposed to padding to vec4s.
+* ``PIPE_CAP_BUFFER_AGE``: True if the driver wants to expose 
EGL/GLX_EXT_buffer_age.
 
 
 .. _pipe_capf:
diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c 
b/src/gallium/drivers/etnaviv/etnaviv_screen.c
index b0f8b4bebe..1b4276a36e 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c
@@ -144,6 +144,7 @@ etna_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_TGSI_TEXCOORD:
case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
+   case PIPE_CAP_BUFFER_AGE:
   return 1;
case PIPE_CAP_NATIVE_FENCE_FD:
   return screen->drm_version >= ETNA_DRM_VERSION_FENCE_FD;
diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c 
b/src/gallium/drivers/freedreno/freedreno_screen.c
index f338d756df..a7c6f4453e 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.c
+++ b/src/gallium/drivers/freedreno/freedreno_screen.c
@@ -186,6 +186,7 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
case PIPE_CAP_TEXTURE_BARRIER:
case PIPE_CAP_INVALIDATE_BUFFER:
+   case PIPE_CAP_BUFFER_AGE:
return 1;
 
case PIPE_CAP_VERTEXID_NOBASE:
diff --git a/src/gallium/drivers/i915/i915_screen.c 
b/src/gallium/drivers/i915/i915_screen.c
index 59d2ec6628..168912946c 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -205,6 +205,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap 
cap)
case PIPE_CAP_VERTEX_COLOR_CLAMPED:
case PIPE_CAP_USER_VERTEX_BUFFERS:
case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
+   case PIPE_CAP_BUFFER_AGE:
   return 1;
 
/* Unsupported features (boolean caps). */
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index 3f5d0327bf..495e3f96b6 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -110,6 +110,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum 
pipe_cap param)
case PIPE_CAP_NPOT_TEXTURES:
case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
+   case PIPE_CAP_BUFFER_AGE:
   return 1;
case PIPE_CAP_SM3:
   return 1;
diff --git a/src/gallium/drivers/nouveau/nv30/nv30_screen.c 
b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
index 1d1fbaad60..47030210b3 100644
--- a/src/gallium/drivers/nouveau/nv30/nv30_screen.c
+++ b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
@@ -94,6 +94,7 @@ nv30_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
+   case PIPE_CAP_BUFFER_AGE:
   return 1;
/* nv35 capabilities */
case PIPE_CAP_DEPTH_BOUNDS_TEST:
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index 6fd2982e3c..1dca07caf9 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -199,6 +199,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
  

[Mesa-dev] [PATCH rfc 0/3] Be able to disable EGL/GLX_EXT_buffer_age

2018-07-04 Thread Qiang Yu
For GPU like ARM mali Utgard EGL/GLX_EXT_buffer_age will make
performace worse. But mesa has no way to disable it.

This patch series make driver be able to disable it and add a
gallium pipe cap for gallium driver usage. Due to currently
only out of tree lima driver need it, and not sure if this is
the right way to disable it, so I send this RFC before lima be
able to upstream.

Qiang Yu (3):
  egl,glx: query dri integer to expose EGL/GLX_EXT_buffer_age
  gallium: add PIPE_CAP_BUFFER_AGE
  egl: fix query buffer age fail when EGL_KHR_partial_update

 include/GL/internal/dri_interface.h |  2 ++
 src/egl/drivers/dri2/egl_dri2.c |  3 +++
 src/egl/drivers/dri2/platform_android.c |  1 -
 src/egl/drivers/dri2/platform_drm.c |  4 ++--
 src/egl/drivers/dri2/platform_wayland.c |  2 --
 src/egl/drivers/dri2/platform_x11.c |  1 -
 src/egl/main/eglsurface.c   |  7 ++-
 src/gallium/docs/source/screen.rst  |  1 +
 src/gallium/drivers/etnaviv/etnaviv_screen.c|  1 +
 src/gallium/drivers/freedreno/freedreno_screen.c|  1 +
 src/gallium/drivers/i915/i915_screen.c  |  1 +
 src/gallium/drivers/llvmpipe/lp_screen.c|  1 +
 src/gallium/drivers/nouveau/nv30/nv30_screen.c  |  1 +
 src/gallium/drivers/nouveau/nv50/nv50_screen.c  |  1 +
 src/gallium/drivers/nouveau/nvc0/nvc0_screen.c  |  1 +
 src/gallium/drivers/r300/r300_screen.c  |  1 +
 src/gallium/drivers/r600/r600_pipe.c|  1 +
 src/gallium/drivers/radeonsi/si_get.c   |  1 +
 src/gallium/drivers/softpipe/sp_screen.c|  1 +
 src/gallium/drivers/svga/svga_screen.c  |  1 +
 src/gallium/drivers/swr/swr_screen.cpp  |  1 +
 src/gallium/drivers/vc4/vc4_screen.c|  1 +
 src/gallium/drivers/vc5/vc5_screen.c|  1 +
 src/gallium/drivers/virgl/virgl_screen.c|  2 ++
 src/gallium/include/pipe/p_defines.h|  1 +
 src/gallium/state_trackers/dri/dri_query_renderer.c |  5 +
 src/glx/dri3_glx.c  | 12 +---
 src/mesa/drivers/dri/i915/intel_screen.c|  3 +++
 src/mesa/drivers/dri/i965/intel_screen.c|  3 +++
 src/mesa/drivers/dri/nouveau/nouveau_screen.c   |  3 +++
 src/mesa/drivers/dri/radeon/radeon_screen.c |  3 +++
 src/mesa/drivers/dri/swrast/swrast.c|  3 +++
 32 files changed, 61 insertions(+), 10 deletions(-)

-- 
2.17.1

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


[Mesa-dev] [PATCH rfc 3/3] egl: fix query buffer age fail when EGL_KHR_partial_update

2018-07-04 Thread Qiang Yu
When no EGL_EXT_buffer_age but has EGL_KHR_partial_update,
query buffer age should not fail.

Signed-off-by: Qiang Yu 
---
 src/egl/main/eglsurface.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c
index 3bd14a8cd0..222ef4923d 100644
--- a/src/egl/main/eglsurface.c
+++ b/src/egl/main/eglsurface.c
@@ -388,7 +388,12 @@ _eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, 
_EGLSurface *surface,
   *value = surface->PostSubBufferSupportedNV;
   break;
case EGL_BUFFER_AGE_EXT:
-  if (!dpy->Extensions.EXT_buffer_age)
+  /* EGL_BUFFER_AGE_EXT belong to EGL_EXT_buffer_age
+   * EGL_BUFFER_AGE_KHR belong to EGL_KHR_partial_update
+   * but EGL_BUFFER_AGE_EXT == EGL_BUFFER_AGE_KHR by value
+   */
+  if (!dpy->Extensions.EXT_buffer_age &&
+  !dpy->Extensions.KHR_partial_update)
  return _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface");
 
   _EGLContext *ctx = _eglGetCurrentContext();
-- 
2.17.1

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


[Mesa-dev] [PATCH rfc 1/3] egl, glx: query dri integer to expose EGL/GLX_EXT_buffer_age

2018-07-04 Thread Qiang Yu
Add __DRI2_RENDERER_EXPOSE_BUFFER_AGE dri integer query for
driver to determine if want to expose EGL/GLX_EXT_buffer_age.

Without knowing damage region first, some tile buffer based
GPU like ARM Mali Utgard has to load whole render target to
tile buffer before partitial update, then write them back.

Expose this extension will mis-lead application to use it
which will make performance worse for this kind of GPU.

EGL_KHR_partial_update is better choice for this kind of GPU.

Signed-off-by: Qiang Yu 
---
 include/GL/internal/dri_interface.h |  2 ++
 src/egl/drivers/dri2/egl_dri2.c |  3 +++
 src/egl/drivers/dri2/platform_android.c |  1 -
 src/egl/drivers/dri2/platform_drm.c |  4 ++--
 src/egl/drivers/dri2/platform_wayland.c |  2 --
 src/egl/drivers/dri2/platform_x11.c |  1 -
 src/gallium/state_trackers/dri/dri_query_renderer.c |  3 +++
 src/glx/dri3_glx.c  | 12 +---
 src/mesa/drivers/dri/i915/intel_screen.c|  3 +++
 src/mesa/drivers/dri/i965/intel_screen.c|  3 +++
 src/mesa/drivers/dri/nouveau/nouveau_screen.c   |  3 +++
 src/mesa/drivers/dri/radeon/radeon_screen.c |  3 +++
 src/mesa/drivers/dri/swrast/swrast.c|  3 +++
 13 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 4f4795c7ae..9dd8a90381 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1856,6 +1856,8 @@ typedef struct __DRIDriverVtableExtensionRec {
 #define   __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_MEDIUM (1 << 1)
 #define   __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_HIGH   (1 << 2)
 
+#define __DRI2_RENDERER_EXPOSE_BUFFER_AGE 0x000e
+
 typedef struct __DRI2rendererQueryExtensionRec __DRI2rendererQueryExtension;
 struct __DRI2rendererQueryExtensionRec {
__DRIextension base;
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 45d0c7275c..8f91c91638 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -777,6 +777,9 @@ dri2_setup_screen(_EGLDisplay *disp)
 
if (dri2_dpy->flush_control)
   disp->Extensions.KHR_context_flush_control = EGL_TRUE;
+
+   disp->Extensions.EXT_buffer_age =
+  dri2_renderer_query_integer(dri2_dpy, __DRI2_RENDERER_EXPOSE_BUFFER_AGE);
 }
 
 void
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index 7f1a496ea2..d1ef070e6b 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -1270,7 +1270,6 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay 
*disp)
disp->Extensions.ANDROID_framebuffer_target = EGL_TRUE;
disp->Extensions.ANDROID_image_native_buffer = EGL_TRUE;
disp->Extensions.ANDROID_recordable = EGL_TRUE;
-   disp->Extensions.EXT_buffer_age = EGL_TRUE;
 #if ANDROID_API_LEVEL >= 23
disp->Extensions.KHR_partial_update = EGL_TRUE;
 #endif
diff --git a/src/egl/drivers/dri2/platform_drm.c 
b/src/egl/drivers/dri2/platform_drm.c
index dc4efea910..e9f4a6a055 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -769,8 +769,8 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
}
 
disp->Extensions.KHR_image_pixmap = EGL_TRUE;
-   if (dri2_dpy->dri2)
-  disp->Extensions.EXT_buffer_age = EGL_TRUE;
+   if (!dri2_dpy->dri2)
+  disp->Extensions.EXT_buffer_age = EGL_FALSE;
 
 #ifdef HAVE_WAYLAND_PLATFORM
dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd);
diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index 80853ac00b..78d9329f7e 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -1433,8 +1433,6 @@ dri2_initialize_wayland_drm(_EGLDriver *drv, _EGLDisplay 
*disp)
if (!dri2_dpy->is_different_gpu)
   disp->Extensions.WL_create_wayland_buffer_from_image = EGL_TRUE;
 
-   disp->Extensions.EXT_buffer_age = EGL_TRUE;
-
disp->Extensions.EXT_swap_buffers_with_damage = EGL_TRUE;
 
/* Fill vtbl last to prevent accidentally calling virtual function during
diff --git a/src/egl/drivers/dri2/platform_x11.c 
b/src/egl/drivers/dri2/platform_x11.c
index 60330b33df..3485ed1466 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -1340,7 +1340,6 @@ dri2_initialize_x11_dri3(_EGLDriver *drv, _EGLDisplay 
*disp)
   disp->Extensions.KHR_image_pixmap = EGL_TRUE;
disp->Extensions.NOK_texture_from_pixmap = EGL_TRUE;
disp->Extensions.CHROMIUM_sync_control = EGL_TRUE;
-   disp->Extensions.EXT_buffer_age = EGL_TRUE;
 
dri2_set_WL_bind_wayland_display(drv, disp);
 
diff --git a/src/gallium/state_trac

Re: [Mesa-dev] Question about EGL_KHR_partial_update implementation

2018-07-02 Thread Qiang Yu
Hi Harish,

>
> > To my understand this extension should only depend on the driver support 
> > instead
> > of platform support while the EGL_KHR_swap_buffers_with_damage is the 
> > opposite:
> > https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_swap_buffers_with_damage.txt
> >
>
> I always wondered why android didn't implement this in its EGL-Layer if
> all it had to do was to send the rectangles to the compositor.
> Now that I think about it, I too feel that it should be implemented by the 
> driver.
> Looking at the deqp test case for partial_udpate, it also looks like the
> intension was for the rendering to be restricted to only those rectangles.
>
> Side question: We could also send the damage to the compositor?
As the extension spec describe no compositor side effect, I think we should not
do this. This should be left to EGL_KHR_swap_buffers_with_damage.

>
> > For lima implementation, I want to use the damage region (buffer
> > damage) provided
> > by EGL_KHR_partial_update to skip rendering of un-damaged region when
> > eglSwapBuffersXXX. And tell damage region (surface damage) to compositor 
> > should
> > be left to eglSwapBuffersWithDamageKHR provided by
> > EGL_KHR_swap_buffers_with_damage.
> >
>
> How do you plan to implement it?
>
You mean the mesa framework part or the gpu driver part? For mesa
framework part I'd like
to add a driver callback to set damage region, and when flush, driver
use the damage region
to skip un-damage region's render. But I don't have a detail plan.

Mali GPU split FBO into 16x16 tiles, it renders each tile into a tile
buffer mem inside GPU, then
GPU write this tile buffer into RAM FBO. If mali want to draw
something based on the original
content of the FBO tile or draw part of the FBO tile, we have to load
the FBO tile into GPU tile
buffer first. If we don't know the damage region before render like
EGL_EXT_buffer_age,
GPU has to load the whole FBO into tile buffer, which makes partial
draw a whole FBO read/write.
But with EGL_KHR_partial_update, we can skip load of un-damaged FBO
tile which is really
partial draw. I think this is the intention of this extension (which
is also proposed by ARM guys)
to benifit tile GPU rendering.

Useful blog:
https://community.arm.com/graphics/b/blog/posts/mali-performance-3-is-egl_5f00_buffer_5f00_preserved-a-good-thing

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


[Mesa-dev] Question about EGL_KHR_partial_update implementation

2018-06-28 Thread Qiang Yu
Hi Harish,

I want to implement EGL_KHR_partial_update for lima mesa driver and find you
worked on Android/Wayland support for it:
https://patchwork.freedesktop.org/patch/160944/
https://patchwork.freedesktop.org/patch/188695/

So I have some question about it:
your implementation seems to depend on platform (Android, wayland) support,
for example call native_window_set_surface_damage() in Android implementation.
What's the purpose of it, tell the Android SurfaceFlinger to redraw the damage
region? And is this damage region the "surface damage" or "buffer
damage" metioned
in the EGL_KHR_partial_update?
https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_partial_update.txt

To my understand this extension should only depend on the driver support instead
of platform support while the EGL_KHR_swap_buffers_with_damage is the opposite:
https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_swap_buffers_with_damage.txt

For lima implementation, I want to use the damage region (buffer
damage) provided
by EGL_KHR_partial_update to skip rendering of un-damaged region when
eglSwapBuffersXXX. And tell damage region (surface damage) to compositor should
be left to eglSwapBuffersWithDamageKHR provided by
EGL_KHR_swap_buffers_with_damage.

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


[Mesa-dev] Question about NIR changes since mesa 17.3

2018-03-30 Thread Qiang Yu
Hi guys,

I'm rebasing the mesa-lima code from 17.3 to 18.0 and found the NIR changes
in 18.0 will always do nir_lower_io_to_scalar_early() for the output of
vertex
shader and input of fragment shader. My first question is:
Is it for the link time optimization that we can drop un-used channel in a
slot
and merge channels in different slots to one slot if possible?

Mali4xx GPU has different processor for vertex shader (GP) and fragment
shader (PP). Scalar is OK for GP, but PP more like vec ops. So this scalar
change make PP not comfortable. I like the link time optimization, so don't
want to just disable it. My second question is:
Is there any NIR helper that I can use to merge scalar input to vector
again?
Or what's the right way to make the scalar input vector again?

I see master mesa branch will further do nir_lower_alu_to_scalar
for all nir which will get more pain for mali PP, so my third question is:
How other vec GPU solve this problem or anyway to disable it?

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


Re: [Mesa-dev] Question about implementing viewport transfer and const load in nir

2017-08-30 Thread Qiang Yu
On Wed, Aug 30, 2017 at 9:03 PM, Rob Clark <robdcl...@gmail.com> wrote:
> On Wed, Aug 30, 2017 at 3:26 AM, Qiang Yu <yuq...@gmail.com> wrote:
>>> btw, does lima have some way to write to memory from cmdstream (ie.
>>> without setting up a full blown draw)?  If so perhaps you could get
>>> away with leaving some extra space at the end of your uniform buffer
>>> that you copy driver internal uniforms into before kicking the draw?
>> Unfortunately lima can't do this. Seems you guys all know how to
>> "reserve space in uniform buffer", how?
>>
>>>
>>> fwiw, freedreno does have driver specific uniforms, see
>>> ir3_driver_param.  Although normal uniforms (ie. non-UBO) get copied
>>> into internal memory, so I just upload driver specific uniforms (as
>>> needed) and immediates to the tail of the uniform memory before the
>>> draw.
>> So you mean freedreno will do an extra copy from the constant buffer
>> set by set_constant_buffer to a driver allocated memory then append
>> the driver spec uniform? If so, that can explain the trick above.
>
> Kind of.. it is really a copy into internal uniform memory that the
> shaders access.  Although if the uniforms were a buffer in system
> memory and you had a way to memcpy from cmdstream synchronized with
> draws, then that could work too.  (I do similar w/ some immediates
> too, since in some cases it avoids an extra move from immed
> instruction in the shader.)
lima store uniform in system memory and can't write memory in
cmd stream, so I have to do a memcpy before draw if not use the
constant buffer of set_constant_buffer.

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


Re: [Mesa-dev] Question about implementing viewport transfer and const load in nir

2017-08-30 Thread Qiang Yu
> btw, does lima have some way to write to memory from cmdstream (ie.
> without setting up a full blown draw)?  If so perhaps you could get
> away with leaving some extra space at the end of your uniform buffer
> that you copy driver internal uniforms into before kicking the draw?
Unfortunately lima can't do this. Seems you guys all know how to
"reserve space in uniform buffer", how?

>
> fwiw, freedreno does have driver specific uniforms, see
> ir3_driver_param.  Although normal uniforms (ie. non-UBO) get copied
> into internal memory, so I just upload driver specific uniforms (as
> needed) and immediates to the tail of the uniform memory before the
> draw.
So you mean freedreno will do an extra copy from the constant buffer
set by set_constant_buffer to a driver allocated memory then append
the driver spec uniform? If so, that can explain the trick above.

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


Re: [Mesa-dev] Question about implementing viewport transfer and const load in nir

2017-08-30 Thread Qiang Yu
> In my case, VC4 has lots of custom state-dependent uniforms, and uniform
> upload is where we spend most of our CPU time (basically each draw call
> needs to re-upload the uniform stream, and the stream has to be in the
> order they will be used by instructions, rather than where they appear
> in NIR).
>
> So, I've just got an array of {type of uniform, some sort of index}
> tuples attached to the compiled shader to represent the stream.  Each
> can reference "offset in gallium const buffer" or "a load_const value"
> or "my special viewport x scale" or whatever, and I walk it at draw time
> to write out my stream.
So in VC4:
1. st call set_constant_buffer
2. VC4 prepare draw stream and const buffer modify info
3. when draw, VC4 use the modify info to upload data to constant
buffer set by set_constant_buffer

How do you ensure:
1. st will call set_constant_buffer because some shader has no uniform
2. the constant buffer has enough space, because you don't tell st to
allocate more space for driver spec uniform, right?

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


Re: [Mesa-dev] Question about implementing viewport transfer and const load in nir

2017-08-30 Thread Qiang Yu
Thanks Kenneth, here attach my RFC prototype patch implementing these,
and comments follows.

>> When working on lima gp compiler, I come across two problems about
>> inserting extra uniform
>> and instructions in nir for the driver and don't know where's the
>> right place to do it. So I'd like
>> to hear your opinion and if there's other driver already did so.
>>
>> 1. viewport transfer
>> lima gp needs embed viewport transfer into vertex shader, so need to
>> insert a uniform which
>> holds the scale and transfer and some instruction to apply the
>> calculation to the gl_Position
>> varying output. If do this in driver callback create_vs_state(), seems
>> won't affect the state
>> tracker to allocate uniform space for it, maybe add something in
>> st_create_vp_variant()?
>
> The best way to handle this is probably to use the statevars mechanism.
> Extend src/mesa/program/prog_statevars.[ch] with new STATE_VIEWPORT_*
> enum values, and populate it with the viewport values you need from the
> GL context.
>
> Then, you can just refer to special built-in uniforms in NIR.  See how
> nir_lower_wpos_ytransform.c does this, for example.
So you mean add a STATE for the viewport and implement all in a none-driver
spec way? In fact my prototype just use the STATE_INTERNAL_DRIVER
and add a new pipe_context callback to do all this before st_finalize_nir.
I think I can move the viewport part out of driver spec way, but not the const
part.

>
>> 2. const load
>> lima gp needs const be loaded just as uniform, so I have to allocate
>> uniform space for them.
>> Besides the same problem as 1 (where to do it), the const node may be
>> eliminated after driver
>> nir optimization and won't have a base filed as uniform.
>
> Not sure what to recommend here.  It might be best to handle it as part
> of your compiler backend.  Or, perhaps late in the process, you could
> convert load_const into load_uniform intrinsics.  You can decide on the
> constant buffer layout yourself, and just set the driver locations / load
> offsets yourself...
If I don't allocate space before st_finalize_nir, how does st part know to
reserve constant buffer space for it?

>
>> Seems some of these (space allocation) need be done in non-driver
>> layer and some (instruction
>> insertion and uniform base assign to const) can be done in driver.
>>
>> BTW. lima gp can only have one uniform buffer, so I can't just use a
>> dedicated uniform buffer
>> for viewport transfer and const uniform.
>
> Makes sense.  That shouldn't be a problem.
I mean "can't"...

Regards,
Qiang
From e3aa50296a87b8b4cbf4d9f83939d5c87b75e948 Mon Sep 17 00:00:00 2001
From: Qiang Yu <yuq...@gmail.com>
Date: Wed, 30 Aug 2017 08:32:53 +0800
Subject: [PATCH 4/4] lima: add lower constant to uniform

Signed-off-by: Qiang Yu <yuq...@gmail.com>
---
 src/gallium/drivers/lima/Makefile.sources   |  1 +
 src/gallium/drivers/lima/ir/gp/gpir.h   |  6 +++
 src/gallium/drivers/lima/ir/gp/lower.c  | 17 +--
 src/gallium/drivers/lima/ir/gp/nir.c| 13 +
 src/gallium/drivers/lima/lima_nir_lower_const.c | 67 +
 src/gallium/drivers/lima/lima_program.c |  7 ++-
 src/gallium/drivers/lima/lima_program.h |  5 +-
 7 files changed, 107 insertions(+), 9 deletions(-)
 create mode 100644 src/gallium/drivers/lima/lima_nir_lower_const.c

diff --git a/src/gallium/drivers/lima/Makefile.sources b/src/gallium/drivers/lima/Makefile.sources
index f251810..083c3b3 100644
--- a/src/gallium/drivers/lima/Makefile.sources
+++ b/src/gallium/drivers/lima/Makefile.sources
@@ -17,4 +17,5 @@ C_SOURCES := \
 	  lima_draw.c \
 	  lima_program.c \
 	  lima_nir_lower_viewport_transform.c \
+	  lima_nir_lower_const.c \
 	  $(gpir_SOURCES)
diff --git a/src/gallium/drivers/lima/ir/gp/gpir.h b/src/gallium/drivers/lima/ir/gp/gpir.h
index 0f25fdf..76f1029 100644
--- a/src/gallium/drivers/lima/ir/gp/gpir.h
+++ b/src/gallium/drivers/lima/ir/gp/gpir.h
@@ -255,9 +255,15 @@ typedef struct {
 typedef struct gpir_compiler {
struct list_head block_list;
int cur_index;
+
/* array for searching ssa/reg node */
gpir_node **var_nodes;
unsigned reg_base;
+
+   /* constant info */
+   union fi *constants;
+   int num_constant;
+   int constant_base;
 } gpir_compiler;
 
 typedef struct gpir_prog {
diff --git a/src/gallium/drivers/lima/ir/gp/lower.c b/src/gallium/drivers/lima/ir/gp/lower.c
index c12b27a..a10c412 100644
--- a/src/gallium/drivers/lima/ir/gp/lower.c
+++ b/src/gallium/drivers/lima/ir/gp/lower.c
@@ -33,11 +33,20 @@ static void gpir_lower_const(gpir_compiler *comp)
  if (node->op == gpir_op_const) {
 gpir_const_node *c = gpir_node_to_const(node);
 
-fprintf(stderr, "gpir:

[Mesa-dev] Question about implementing viewport transfer and const load in nir

2017-08-26 Thread Qiang Yu
Hi guys,

When working on lima gp compiler, I come across two problems about
inserting extra uniform
and instructions in nir for the driver and don't know where's the
right place to do it. So I'd like
to hear your opinion and if there's other driver already did so.

1. viewport transfer
lima gp needs embed viewport transfer into vertex shader, so need to
insert a uniform which
holds the scale and transfer and some instruction to apply the
calculation to the gl_Position
varying output. If do this in driver callback create_vs_state(), seems
won't affect the state
tracker to allocate uniform space for it, maybe add something in
st_create_vp_variant()?

2. const load
lima gp needs const be loaded just as uniform, so I have to allocate
uniform space for them.
Besides the same problem as 1 (where to do it), the const node may be
eliminated after driver
nir optimization and won't have a base filed as uniform.

Seems some of these (space allocation) need be done in non-driver
layer and some (instruction
insertion and uniform base assign to const) can be done in driver.

BTW. lima gp can only have one uniform buffer, so I can't just use a
dedicated uniform buffer
for viewport transfer and const uniform.

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


Re: [Mesa-dev] Question for nir lower load uniform to scalar

2017-08-25 Thread Qiang Yu
On Sat, Aug 26, 2017 at 3:07 AM, Eric Anholt <e...@anholt.net> wrote:
> Qiang Yu <yuq...@gmail.com> writes:
>
>> Hi Eric,
>>
>> I'm working on lima gp compiler which should benefit from nir lowering
>> uniform load to scalar.
>> I notice you write the nir_lower_io_to_scalar.c which support lowering
>> shader_in/shader_out
>> but left the uniform lowering in vc4 driver, any reason why not
>> implement in the nir_lower_io_to_scalar.c?
>
> I think my theory was that drivers would want different units for the
> base/offset (bytes or dwords), so I left it in vc4.  Anyone else want to
> weigh in on this?  vc4 wants indirect load offsets in units of bytes.
Oh, I see, unfortunately lima gp need the base/offset in 4 components
just as the nir base/offset, so I have to come to add a component field.

>
>> I'm new to nir, tried to add it but seems not correct after
>> optimization pass. So I should missing
>> some place, anyone can help to point out?
>
> Your nir_lower_io.c code looks correct to me, so I'm not sure what might
> be missing.  I'm not sure about using the component field, though -- for
> VC4 all I want after lowering is a byte offset within the constant
> buffer.
After some dump, it just go wrong from the CSE pass which eliminate
the ssa from the component != 0. Maybe some change need for the
CSE to know the load_uniform component field just like load_input.

The problem is found to be my fault not change the num_indices:
- LOAD(uniform, 1, 2, BASE, RANGE, COMPONENT,
NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
+ LOAD(uniform, 1, 3, BASE, RANGE, COMPONENT,
NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)

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


[Mesa-dev] Question for nir lower load uniform to scalar

2017-08-25 Thread Qiang Yu
Hi Eric,

I'm working on lima gp compiler which should benefit from nir lowering
uniform load to scalar.
I notice you write the nir_lower_io_to_scalar.c which support lowering
shader_in/shader_out
but left the uniform lowering in vc4 driver, any reason why not
implement in the nir_lower_io_to_scalar.c?

I'm new to nir, tried to add it but seems not correct after
optimization pass. So I should missing
some place, anyone can help to point out?

Thanks,
Qiang
diff --git a/src/compiler/nir/nir_intrinsics.h b/src/compiler/nir/nir_intrinsics.h
index 3a519a73..93bf0fc 100644
--- a/src/compiler/nir/nir_intrinsics.h
+++ b/src/compiler/nir/nir_intrinsics.h
@@ -392,8 +392,8 @@ BARYCENTRIC(at_offset, 1, 2)
 #define LOAD(name, srcs, num_indices, idx0, idx1, idx2, flags) \
INTRINSIC(load_##name, srcs, ARR(1, 1, 1, 1), true, 0, 0, num_indices, idx0, idx1, idx2, flags)
 
-/* src[] = { offset }. const_index[] = { base, range } */
-LOAD(uniform, 1, 2, BASE, RANGE, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
+/* src[] = { offset }. const_index[] = { base, range, component } */
+LOAD(uniform, 1, 2, BASE, RANGE, COMPONENT, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
 /* src[] = { buffer_index, offset }. No const_index */
 LOAD(ubo, 2, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
 /* src[] = { offset }. const_index[] = { base, component } */
diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c
index 1ae2cc7..566f8d0 100644
--- a/src/compiler/nir/nir_lower_io.c
+++ b/src/compiler/nir/nir_lower_io.c
@@ -208,7 +208,7 @@ lower_load(nir_intrinsic_instr *intrin, struct lower_io_state *state,
load->num_components = intrin->num_components;
 
nir_intrinsic_set_base(load, var->data.driver_location);
-   if (mode == nir_var_shader_in || mode == nir_var_shader_out)
+   if (mode == nir_var_shader_in || mode == nir_var_shader_out || mode == nir_var_uniform)
   nir_intrinsic_set_component(load, component);
 
if (load->intrinsic == nir_intrinsic_load_uniform)
diff --git a/src/compiler/nir/nir_lower_io_to_scalar.c b/src/compiler/nir/nir_lower_io_to_scalar.c
index f2345d5..d838770 100644
--- a/src/compiler/nir/nir_lower_io_to_scalar.c
+++ b/src/compiler/nir/nir_lower_io_to_scalar.c
@@ -26,8 +26,8 @@
 
 /** @file nir_lower_io_to_scalar.c
  *
- * Replaces nir_load_input/nir_store_output operations with num_components !=
- * 1 with individual per-channel operations.
+ * Replaces nir_load_input/nir_store_output/nir_load_uniform operations
+ * with num_components != 1 with individual per-channel operations.
  */
 
 static void
@@ -63,6 +63,39 @@ lower_load_input_to_scalar(nir_builder *b, nir_intrinsic_instr *intr)
 }
 
 static void
+lower_load_uniform_to_scalar(nir_builder *b, nir_intrinsic_instr *intr)
+{
+   b->cursor = nir_before_instr(>instr);
+
+   assert(intr->dest.is_ssa);
+
+   nir_ssa_def *loads[4];
+
+   for (unsigned i = 0; i < intr->num_components; i++) {
+  nir_intrinsic_instr *chan_intr =
+ nir_intrinsic_instr_create(b->shader, intr->intrinsic);
+  nir_ssa_dest_init(_intr->instr, _intr->dest,
+1, intr->dest.ssa.bit_size, NULL);
+  chan_intr->num_components = 1;
+
+  nir_intrinsic_set_base(chan_intr, nir_intrinsic_base(intr));
+  nir_intrinsic_set_component(chan_intr, nir_intrinsic_component(intr) + i);
+  nir_intrinsic_set_range(chan_intr, nir_intrinsic_range(intr));
+  /* offset */
+  nir_src_copy(_intr->src[0], >src[0], chan_intr);
+
+  nir_builder_instr_insert(b, _intr->instr);
+
+  loads[i] = _intr->dest.ssa;
+   }
+
+   nir_ssa_def_rewrite_uses(>dest.ssa,
+nir_src_for_ssa(nir_vec(b, loads,
+intr->num_components)));
+   nir_instr_remove(>instr);
+}
+
+static void
 lower_store_output_to_scalar(nir_builder *b, nir_intrinsic_instr *intr)
 {
b->cursor = nir_before_instr(>instr);
@@ -119,6 +152,10 @@ nir_lower_io_to_scalar(nir_shader *shader, nir_variable_mode mask)
   if (mask & nir_var_shader_out)
  lower_store_output_to_scalar(, intr);
   break;
+   case nir_intrinsic_load_uniform:
+  if (mask & nir_var_uniform)
+ lower_load_uniform_to_scalar(, intr);
+  break;
default:
   break;
}
diff --git a/src/gallium/drivers/lima/ir/gp/nir.c b/src/gallium/drivers/lima/ir/gp/nir.c
index 1f6b91d..e71c0a0 100644
--- a/src/gallium/drivers/lima/ir/gp/nir.c
+++ b/src/gallium/drivers/lima/ir/gp/nir.c
@@ -123,8 +123,8 @@ static gpir_node *gpir_emit_intrinsic(gpir_compiler *comp, nir_intrinsic_instr *
   if (!lnode)
  return NULL;
 
-  lnode->index = instr->const_index[info->index_map[NIR_INTRINSIC_BASE] - 1];
-  lnode->component = instr->const_index[info->index_map[NIR_INTRINSIC_COMPONENT] - 1];
+  lnode->index = 

[Mesa-dev] [PATCH] android: fix gallium_dri.so can't be loaded by drm_gralloc

2017-08-17 Thread Qiang Yu
The problem is in gallium/winsys/amdgpu/drm/Android.mk
which will have duplacated symbols when linking
gallium_dri.so for libLLVMCore and libLLVM.

Signed-off-by: Qiang Yu <qiang...@amd.com>
Signed-off-by: Mauro Rossi <issor.or...@gmail.com>
Signed-off-by: Rob Herring <robherri...@gmail.com>
---
 Android.mk  | 7 ---
 src/amd/Android.common.mk   | 4 +---
 src/gallium/drivers/radeon/Android.mk   | 2 +-
 src/gallium/drivers/radeonsi/Android.mk | 2 +-
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/Android.mk b/Android.mk
index 6571161..5154a56 100644
--- a/Android.mk
+++ b/Android.mk
@@ -93,15 +93,16 @@ define mesa-build-with-llvm
 $(warning Unsupported LLVM version in Android 
$(MESA_ANDROID_MAJOR_VERSION)),) \
   $(if $(filter 6,$(MESA_ANDROID_MAJOR_VERSION)), \
 $(eval LOCAL_CFLAGS += -DHAVE_LLVM=0x0307 -DMESA_LLVM_VERSION_PATCH=0) \
-$(eval LOCAL_STATIC_LIBRARIES += libLLVMCore) \
+$(eval LOCAL_SHARED_LIBRARIES += libLLVM) \
 $(eval LOCAL_C_INCLUDES += external/llvm/include 
external/llvm/device/include),) \
   $(if $(filter 7,$(MESA_ANDROID_MAJOR_VERSION)), \
 $(eval LOCAL_CFLAGS += -DHAVE_LLVM=0x0308 -DMESA_LLVM_VERSION_PATCH=0) \
-$(eval LOCAL_STATIC_LIBRARIES += libLLVMCore) \
+$(eval LOCAL_SHARED_LIBRARIES += libLLVM) \
 $(eval LOCAL_C_INCLUDES += external/llvm/include 
external/llvm/device/include),) \
   $(if $(filter O,$(MESA_ANDROID_MAJOR_VERSION)), \
 $(eval LOCAL_CFLAGS += -DHAVE_LLVM=0x0309 -DMESA_LLVM_VERSION_PATCH=0) \
-$(eval LOCAL_HEADER_LIBRARIES += llvm-headers),)
+$(eval LOCAL_SHARED_LIBRARIES += libLLVM) \
+$(eval LOCAL_C_INCLUDES += external/llvm/include 
external/llvm/device/include),)
 endef
 
 # add subdirectories
diff --git a/src/amd/Android.common.mk b/src/amd/Android.common.mk
index 39d2732..92b2452 100644
--- a/src/amd/Android.common.mk
+++ b/src/amd/Android.common.mk
@@ -54,9 +54,7 @@ LOCAL_C_INCLUDES := \
$(call generated-sources-dir-for,STATIC_LIBRARIES,libmesa_nir,,)/nir \
$(MESA_TOP)/src/gallium/include \
$(MESA_TOP)/src/gallium/auxiliary \
-   $(intermediates)/common \
-   external/llvm/include \
-   external/llvm/device/include
+   $(intermediates)/common
 
 LOCAL_EXPORT_C_INCLUDE_DIRS := \
$(LOCAL_PATH)/common
diff --git a/src/gallium/drivers/radeon/Android.mk 
b/src/gallium/drivers/radeon/Android.mk
index eb1a321..c2d3a1c 100644
--- a/src/gallium/drivers/radeon/Android.mk
+++ b/src/gallium/drivers/radeon/Android.mk
@@ -30,7 +30,7 @@ include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := $(C_SOURCES)
 
-LOCAL_SHARED_LIBRARIES := libdrm_radeon libLLVM
+LOCAL_SHARED_LIBRARIES := libdrm_radeon
 LOCAL_MODULE := libmesa_pipe_radeon
 
 ifeq ($(MESA_ENABLE_LLVM),true)
diff --git a/src/gallium/drivers/radeonsi/Android.mk 
b/src/gallium/drivers/radeonsi/Android.mk
index 6fff91f..faf3880 100644
--- a/src/gallium/drivers/radeonsi/Android.mk
+++ b/src/gallium/drivers/radeonsi/Android.mk
@@ -40,7 +40,7 @@ LOCAL_C_INCLUDES := \
 
 LOCAL_STATIC_LIBRARIES := libmesa_amd_common
 
-LOCAL_SHARED_LIBRARIES := libdrm_radeon libLLVM
+LOCAL_SHARED_LIBRARIES := libdrm_radeon
 LOCAL_MODULE := libmesa_pipe_radeonsi
 
 $(call mesa-build-with-llvm)
-- 
1.9.1

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


[Mesa-dev] [PATCH v2] gbm: add support for loading third-party backend (v2)

2017-04-07 Thread Qiang Yu
V2:
  1. export gbmint.h and test backend/libgbm ABI compatible
  2. drop GBM_BACKEND_DIR, specify backend path in config file
  3. add GBM_CONFIG_DIR for config file
  4. add per backend priority
  5. take care of thread safe

Third-party can put their backend to a directory and create a
/etc/gbm.conf.d/*.conf file which contains the backend so file
path to overwrite the default builtin DRI backend.

The /etc/gbm.conf.d/*.conf will be sorted and the backends added
will be tried one-by-one until one can successfully create a gbm
device. The default DRI backend is tried at last.

/etc/gbm.conf.d/*.conf can also contain a "priority" field.
backend with bigger number will be tried first. Default priority
is 1000 inlcuding the builtin backend.

GBM config file example:
lib:/opt/amdgpu-pro/lib/gbm/amdgpu.so
priority:2000

People can still use GBM_BACKEND to overwrite the backend try
order.

Signed-off-by: Qiang Yu <qiang...@amd.com>
---
 configure.ac   |   9 +++
 src/gbm/Makefile.am|  11 +++-
 src/gbm/backends/dri/gbm_dri.c |   1 +
 src/gbm/main/backend.c | 130 ++---
 src/gbm/main/gbmint.h  |   7 ++-
 5 files changed, 146 insertions(+), 12 deletions(-)

diff --git a/configure.ac b/configure.ac
index 70885fb..792d1b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2221,6 +2221,15 @@ AC_ARG_WITH([d3d-libdir],
 [D3D_DRIVER_INSTALL_DIR="${libdir}/d3d"])
 AC_SUBST([D3D_DRIVER_INSTALL_DIR])
 
+dnl Directory for GBM
+
+AC_ARG_WITH([gbm-configdir],
+[AS_HELP_STRING([--with-gbm-configdir=DIR],
+[directory for the GBM configs @<:@/etc/gbm.conf.d@:>@])],
+[GBM_CONFIG_DIR="$withval"],
+[GBM_CONFIG_DIR='/etc/gbm.conf.d'])
+AC_SUBST([GBM_CONFIG_DIR])
+
 dnl
 dnl r300 doesn't strictly require LLVM, but for performance reasons we
 dnl highly recommend LLVM usage. So require it at least on x86 and x86_64
diff --git a/src/gbm/Makefile.am b/src/gbm/Makefile.am
index e34c1d4..2e29931 100644
--- a/src/gbm/Makefile.am
+++ b/src/gbm/Makefile.am
@@ -8,11 +8,17 @@ AM_CFLAGS = \
-I$(top_srcdir)/src/loader \
-I$(top_srcdir)/src/gbm/main \
$(DLOPEN_CFLAGS) \
+   $(PTHREAD_CFLAGS) \
$(DEFINES) \
$(VISIBILITY_CFLAGS)
 
+AM_CFLAGS += \
+   -DGBM_CONFIG_DIR='"$(GBM_CONFIG_DIR)"'
+
 lib_LTLIBRARIES = libgbm.la
-include_HEADERS = main/gbm.h
+include_HEADERS = \
+   main/gbm.h \
+   main/gbmint.h
 
 libgbm_la_SOURCES = \
$(gbm_core_FILES)
@@ -25,7 +31,8 @@ libgbm_la_LDFLAGS = \
 
 libgbm_la_LIBADD = \
$(top_builddir)/src/loader/libloader.la \
-   $(DLOPEN_LIBS)
+   $(DLOPEN_LIBS) \
+   $(PTHREAD_LIBS)
 
 if HAVE_PLATFORM_WAYLAND
 AM_CPPFLAGS = -DHAVE_WAYLAND_PLATFORM
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 189a8fc..f8d90bd 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -1393,4 +1393,5 @@ err_dri:
 struct gbm_backend gbm_dri_backend = {
.backend_name = "dri",
.create_device = dri_device_create,
+   .abi_version = GBM_BACKEND_ABI_VERSION,
 };
diff --git a/src/gbm/main/backend.c b/src/gbm/main/backend.c
index 37ec9c1..687fda6 100644
--- a/src/gbm/main/backend.c
+++ b/src/gbm/main/backend.c
@@ -25,13 +25,20 @@
  *Benjamin Franzke <benjaminfran...@googlemail.com>
  */
 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
+#include 
+#include 
+#include 
+#include 
+
 #include "backend.h"
+#include "gbmint.h"
 
 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
 
@@ -40,34 +47,69 @@ extern const struct gbm_backend gbm_dri_backend;
 struct backend_desc {
const char *name;
const struct gbm_backend *builtin;
+   int priority;
+   bool bad;
 };
 
-static const struct backend_desc backends[] = {
-   { "gbm_dri.so", _dri_backend },
+#define GBM_BACKEND_DEFAULT_PRIORITY 1000
+
+static const struct backend_desc builtin_backends[] = {
+   {
+  .name = "gbm_dri.so",
+  .builtin = _dri_backend,
+  .priority = GBM_BACKEND_DEFAULT_PRIORITY,
+   },
 };
 
+#define MAX_BACKENDS 16
+static struct backend_desc backends[MAX_BACKENDS];
+static int num_backends = 0;
+
 static const void *
-load_backend(const struct backend_desc *backend)
+load_backend(struct backend_desc *backend)
 {
const void *init = NULL;
+   static pthread_mutex_t backends_mutex = PTHREAD_MUTEX_INITIALIZER;
 
if (backend == NULL)
   return NULL;
 
+   pthread_mutex_lock(_mutex);
+
if (backend->builtin) {
   init = backend->builtin;
}
+   else if (!backend->bad) {
+  void *module;
+
+  module = dlopen(backend->name, RTLD_NOW | RTLD_GLOBAL);
+  if (module) {
+ backend->builtin = dlsym(module, "gbm_backend");
+ if (backend->builtin &&
+ backend->builtin->abi_version == 

[Mesa-dev] [PATCH] gbm: add support for loading third-party backend

2017-01-23 Thread Qiang Yu
Third-party can put their backend to a directory configured with
'--with-gbm-backenddir' and create a /etc/gbm.conf.d/*.conf file
which contains the backend so file name to overwrite the default
builtin DRI backend.

The /etc/gbm.conf.d/*.conf will be sorted and the backends added
will be tried one-by-one until one can successfully create a gbm
device. The default DRI backend is tried at last.

People can still use GBM_BACKEND to overwrite the backend try
order.

Signed-off-by: Qiang Yu <qiang...@amd.com>
---
 configure.ac   |  7 +
 src/gbm/Makefile.am|  1 +
 src/gbm/main/backend.c | 80 ++
 3 files changed, 82 insertions(+), 6 deletions(-)

diff --git a/configure.ac b/configure.ac
index 64ace9d..21aea75 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2201,6 +2201,13 @@ AC_ARG_WITH([d3d-libdir],
 [D3D_DRIVER_INSTALL_DIR="${libdir}/d3d"])
 AC_SUBST([D3D_DRIVER_INSTALL_DIR])
 
+AC_ARG_WITH([gbm-backenddir],
+[AS_HELP_STRING([--with-gbm-backenddir=DIR],
+[directory for the GBM backends @<:@${libdir}/gbm@:>@])],
+[GBM_BACKEND_DIR="$withval"],
+[GBM_BACKEND_DIR='${libdir}/gbm'])
+AC_SUBST([GBM_BACKEND_DIR])
+
 dnl
 dnl Gallium helper functions
 dnl
diff --git a/src/gbm/Makefile.am b/src/gbm/Makefile.am
index e34c1d4..a613005 100644
--- a/src/gbm/Makefile.am
+++ b/src/gbm/Makefile.am
@@ -39,6 +39,7 @@ libgbm_la_SOURCES += \
 
 AM_CFLAGS += \
-DDEFAULT_DRIVER_DIR='"$(DRI_DRIVER_SEARCH_DIR)"' \
+   -DGBM_BACKEND_DIR='"$(GBM_BACKEND_DIR)"' \
$(LIBDRM_CFLAGS) \
$(PTHREADSTUBS_CFLAGS)
 
diff --git a/src/gbm/main/backend.c b/src/gbm/main/backend.c
index 37ec9c1..0b89dde 100644
--- a/src/gbm/main/backend.c
+++ b/src/gbm/main/backend.c
@@ -31,6 +31,10 @@
 #include 
 #include 
 
+#include 
+#include 
+#include 
+
 #include "backend.h"
 
 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
@@ -42,12 +46,18 @@ struct backend_desc {
const struct gbm_backend *builtin;
 };
 
-static const struct backend_desc backends[] = {
+static const struct backend_desc builtin_backends[] = {
{ "gbm_dri.so", _dri_backend },
 };
 
+#define MAX_BACKENDS 10
+static struct backend_desc backends[MAX_BACKENDS];
+static int num_backends = 0;
+
+#define CONFIG_DIR "/etc/gbm.conf.d"
+
 static const void *
-load_backend(const struct backend_desc *backend)
+load_backend(struct backend_desc *backend)
 {
const void *init = NULL;
 
@@ -57,17 +67,28 @@ load_backend(const struct backend_desc *backend)
if (backend->builtin) {
   init = backend->builtin;
}
+   else {
+  char path[PATH_MAX];
+  void *module;
+
+  snprintf(path, PATH_MAX, "%s/%s", GBM_BACKEND_DIR, backend->name);
+  module = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
+  if (module) {
+ backend->builtin = dlsym(module, "gbm_backend");
+ init = backend->builtin;
+  }
+   }
 
return init;
 }
 
-static const struct backend_desc *
+static struct backend_desc *
 find_backend(const char *name)
 {
-   const struct backend_desc *backend = NULL;
+   struct backend_desc *backend = NULL;
unsigned i;
 
-   for (i = 0; i < ARRAY_SIZE(backends); ++i) {
+   for (i = 0; i < num_backends; ++i) {
   if (strcmp(backends[i].name, name) == 0) {
  backend = [i];
  break;
@@ -77,6 +98,50 @@ find_backend(const char *name)
return backend;
 }
 
+static int
+scandir_filter(const struct dirent *ent)
+{
+if (ent->d_type != DT_REG && ent->d_type != DT_LNK &&
+ent->d_type != DT_UNKNOWN)
+   return 0;
+
+if (fnmatch("*.conf", ent->d_name, 0))
+   return 0;
+
+return 1;
+}
+
+static void
+init_backends(void)
+{
+   int i, count;
+   struct dirent **entries = NULL;
+
+   count = scandir(CONFIG_DIR, , scandir_filter, alphasort);
+   for (i = 0; i < count; i++) {
+  char path[PATH_MAX];
+  FILE *file;
+
+  snprintf(path, PATH_MAX, "%s/%s", CONFIG_DIR, entries[i]->d_name);
+  if ((file = fopen(path, "r"))) {
+ while (fgets(path, PATH_MAX, file)) {
+int n = strlen(path);
+if (path[n - 1] == '\n')
+   path[n - 1] = '\0';
+if (!fnmatch("*.so", path, 0) &&
+num_backends < MAX_BACKENDS - ARRAY_SIZE(builtin_backends)) {
+   backends[num_backends].name = strdup(path);
+   backends[num_backends++].builtin = NULL;
+}
+ }
+ fclose(file);
+  }
+   }
+
+   memcpy(backends + num_backends, builtin_backends, sizeof(builtin_backends));
+   num_backends += ARRAY_SIZE(builtin_backends);
+}
+
 struct gbm_device *
 _gbm_create_device(int fd)
 {
@@ -85,6 +150,9 @@ _gbm_create_device(int fd)
unsigned i;
const char *b;
 
+   if (!num_backends)
+  init_backends();