[Mesa-dev,123/140] radeonsi/gfx9: set/validate GFX9 BO metadata

Submitted by Marek Olšák on March 20, 2017, 10:49 p.m.

Details

Message ID 1490050166-6119-32-git-send-email-maraeo@gmail.com
State Accepted
Commit de55e57e29d3392bfc7a7cb31ddf883e382d8138
Headers show
Series "RadeonSI: Initial Vega10 support" ( rev: 23 ) in Mesa

Not browsing as part of any series.

Commit Message

Marek Olšák March 20, 2017, 10:49 p.m.
From: Marek Olšák <marek.olsak@amd.com>

---
 src/gallium/drivers/radeon/r600_texture.c  | 20 +++++++++++++++++++-
 src/gallium/drivers/radeon/radeon_winsys.h |  5 +++++
 2 files changed, 24 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/src/gallium/drivers/radeon/r600_texture.c b/src/gallium/drivers/radeon/r600_texture.c
index 2e66dd0..df260b6 100644
--- a/src/gallium/drivers/radeon/r600_texture.c
+++ b/src/gallium/drivers/radeon/r600_texture.c
@@ -291,6 +291,7 @@  static void r600_texture_init_metadata(struct r600_common_screen *rscreen,
 	memset(metadata, 0, sizeof(*metadata));
 
 	if (rscreen->chip_class >= GFX9) {
+		metadata->u.gfx9.swizzle_mode = surface->u.gfx9.surf.swizzle_mode;
 	} else {
 		metadata->u.legacy.microtile = surface->u.legacy.level[0].mode >= RADEON_SURF_MODE_1D ?
 					   RADEON_LAYOUT_TILED : RADEON_LAYOUT_LINEAR;
@@ -1345,6 +1346,7 @@  static struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen
 	int r;
 	struct radeon_bo_metadata metadata = {};
 	struct r600_texture *rtex;
+	bool is_scanout;
 
 	/* Support only 2D textures without mipmaps */
 	if ((templ->target != PIPE_TEXTURE_2D && templ->target != PIPE_TEXTURE_RECT) ||
@@ -1358,6 +1360,13 @@  static struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen
 	rscreen->ws->buffer_get_metadata(buf, &metadata);
 
 	if (rscreen->chip_class >= GFX9) {
+		if (metadata.u.gfx9.swizzle_mode > 0)
+			array_mode = RADEON_SURF_MODE_2D;
+		else
+			array_mode = RADEON_SURF_MODE_LINEAR_ALIGNED;
+
+		is_scanout = metadata.u.gfx9.swizzle_mode == 0 ||
+			     metadata.u.gfx9.swizzle_mode % 4 == 2;
 	} else {
 		surface.u.legacy.pipe_config = metadata.u.legacy.pipe_config;
 		surface.u.legacy.bankw = metadata.u.legacy.bankw;
@@ -1372,10 +1381,12 @@  static struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen
 			array_mode = RADEON_SURF_MODE_1D;
 		else
 			array_mode = RADEON_SURF_MODE_LINEAR_ALIGNED;
+
+		is_scanout = metadata.u.legacy.scanout;
 	}
 
 	r = r600_init_surface(rscreen, &surface, templ, array_mode, stride,
-			      offset, true, metadata.u.legacy.scanout, false, false);
+			      offset, true, is_scanout, false, false);
 	if (r) {
 		return NULL;
 	}
@@ -1390,6 +1401,13 @@  static struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen
 	if (rscreen->apply_opaque_metadata)
 		rscreen->apply_opaque_metadata(rscreen, rtex, &metadata);
 
+	/* Validate that addrlib arrived at the same surface parameters. */
+	if (rscreen->chip_class >= GFX9) {
+		struct gfx9_surf_layout *gfx9 = &surface.u.gfx9;
+
+		assert(metadata.u.gfx9.swizzle_mode == gfx9->surf.swizzle_mode);
+	}
+
 	return &rtex->resource.b.b;
 }
 
diff --git a/src/gallium/drivers/radeon/radeon_winsys.h b/src/gallium/drivers/radeon/radeon_winsys.h
index b3c7608..7839170 100644
--- a/src/gallium/drivers/radeon/radeon_winsys.h
+++ b/src/gallium/drivers/radeon/radeon_winsys.h
@@ -250,6 +250,11 @@  struct radeon_bo_metadata {
             unsigned                stride;
             bool                    scanout;
         } legacy;
+
+        struct {
+            /* surface flags */
+            unsigned swizzle_mode:5;
+        } gfx9;
     } u;
 
     /* Additional metadata associated with the buffer, in bytes.

Comments

This patch gives me a warning

/var/tmp/portage/media-libs/mesa-9999/work/mesa-9999/src/gallium/drivers/radeon/r600_texture.c:
In function ‘r600_texture_from_handle’:
/var/tmp/portage/media-libs/mesa-9999/work/mesa-9999/src/gallium/drivers/radeon/r600_texture.c:1441:28:
warning: unused variable ‘gfx9’ [-Wunused-variable]
   struct gfx9_surf_layout *gfx9 = &surface.u.gfx9;
                            ^~~~


On Mon, 20 Mar 2017 at 22:54 Marek Olšák <maraeo@gmail.com> wrote:

> From: Marek Olšák <marek.olsak@amd.com>
>
> ---
>  src/gallium/drivers/radeon/r600_texture.c  | 20 +++++++++++++++++++-
>  src/gallium/drivers/radeon/radeon_winsys.h |  5 +++++
>  2 files changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/src/gallium/drivers/radeon/r600_texture.c
> b/src/gallium/drivers/radeon/r600_texture.c
> index 2e66dd0..df260b6 100644
> --- a/src/gallium/drivers/radeon/r600_texture.c
> +++ b/src/gallium/drivers/radeon/r600_texture.c
> @@ -291,6 +291,7 @@ static void r600_texture_init_metadata(struct
> r600_common_screen *rscreen,
>         memset(metadata, 0, sizeof(*metadata));
>
>         if (rscreen->chip_class >= GFX9) {
> +               metadata->u.gfx9.swizzle_mode =
> surface->u.gfx9.surf.swizzle_mode;
>         } else {
>                 metadata->u.legacy.microtile =
> surface->u.legacy.level[0].mode >= RADEON_SURF_MODE_1D ?
>                                            RADEON_LAYOUT_TILED :
> RADEON_LAYOUT_LINEAR;
> @@ -1345,6 +1346,7 @@ static struct pipe_resource
> *r600_texture_from_handle(struct pipe_screen *screen
>         int r;
>         struct radeon_bo_metadata metadata = {};
>         struct r600_texture *rtex;
> +       bool is_scanout;
>
>         /* Support only 2D textures without mipmaps */
>         if ((templ->target != PIPE_TEXTURE_2D && templ->target !=
> PIPE_TEXTURE_RECT) ||
> @@ -1358,6 +1360,13 @@ static struct pipe_resource
> *r600_texture_from_handle(struct pipe_screen *screen
>         rscreen->ws->buffer_get_metadata(buf, &metadata);
>
>         if (rscreen->chip_class >= GFX9) {
> +               if (metadata.u.gfx9.swizzle_mode > 0)
> +                       array_mode = RADEON_SURF_MODE_2D;
> +               else
> +                       array_mode = RADEON_SURF_MODE_LINEAR_ALIGNED;
> +
> +               is_scanout = metadata.u.gfx9.swizzle_mode == 0 ||
> +                            metadata.u.gfx9.swizzle_mode % 4 == 2;
>         } else {
>                 surface.u.legacy.pipe_config =
> metadata.u.legacy.pipe_config;
>                 surface.u.legacy.bankw = metadata.u.legacy.bankw;
> @@ -1372,10 +1381,12 @@ static struct pipe_resource
> *r600_texture_from_handle(struct pipe_screen *screen
>                         array_mode = RADEON_SURF_MODE_1D;
>                 else
>                         array_mode = RADEON_SURF_MODE_LINEAR_ALIGNED;
> +
> +               is_scanout = metadata.u.legacy.scanout;
>         }
>
>         r = r600_init_surface(rscreen, &surface, templ, array_mode, stride,
> -                             offset, true, metadata.u.legacy.scanout,
> false, false);
> +                             offset, true, is_scanout, false, false);
>         if (r) {
>                 return NULL;
>         }
> @@ -1390,6 +1401,13 @@ static struct pipe_resource
> *r600_texture_from_handle(struct pipe_screen *screen
>         if (rscreen->apply_opaque_metadata)
>                 rscreen->apply_opaque_metadata(rscreen, rtex, &metadata);
>
> +       /* Validate that addrlib arrived at the same surface parameters. */
> +       if (rscreen->chip_class >= GFX9) {
> +               struct gfx9_surf_layout *gfx9 = &surface.u.gfx9;
> +
> +               assert(metadata.u.gfx9.swizzle_mode ==
> gfx9->surf.swizzle_mode);
> +       }
> +
>         return &rtex->resource.b.b;
>  }
>
> diff --git a/src/gallium/drivers/radeon/radeon_winsys.h
> b/src/gallium/drivers/radeon/radeon_winsys.h
> index b3c7608..7839170 100644
> --- a/src/gallium/drivers/radeon/radeon_winsys.h
> +++ b/src/gallium/drivers/radeon/radeon_winsys.h
> @@ -250,6 +250,11 @@ struct radeon_bo_metadata {
>              unsigned                stride;
>              bool                    scanout;
>          } legacy;
> +
> +        struct {
> +            /* surface flags */
> +            unsigned swizzle_mode:5;
> +        } gfx9;
>      } u;
>
>      /* Additional metadata associated with the buffer, in bytes.
> --
> 2.7.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
Fixed in master. Thanks.

Marek

On Thu, Mar 30, 2017 at 3:58 PM, Mike Lothian <mike@fireburn.co.uk> wrote:
> This patch gives me a warning
>
> /var/tmp/portage/media-libs/mesa-9999/work/mesa-9999/src/gallium/drivers/radeon/r600_texture.c:
> In function ‘r600_texture_from_handle’:
> /var/tmp/portage/media-libs/mesa-9999/work/mesa-9999/src/gallium/drivers/radeon/r600_texture.c:1441:28:
> warning: unused variable ‘gfx9’ [-Wunused-variable]
>    struct gfx9_surf_layout *gfx9 = &surface.u.gfx9;
>                             ^~~~
>
>
> On Mon, 20 Mar 2017 at 22:54 Marek Olšák <maraeo@gmail.com> wrote:
>>
>> From: Marek Olšák <marek.olsak@amd.com>
>>
>> ---
>>  src/gallium/drivers/radeon/r600_texture.c  | 20 +++++++++++++++++++-
>>  src/gallium/drivers/radeon/radeon_winsys.h |  5 +++++
>>  2 files changed, 24 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/gallium/drivers/radeon/r600_texture.c
>> b/src/gallium/drivers/radeon/r600_texture.c
>> index 2e66dd0..df260b6 100644
>> --- a/src/gallium/drivers/radeon/r600_texture.c
>> +++ b/src/gallium/drivers/radeon/r600_texture.c
>> @@ -291,6 +291,7 @@ static void r600_texture_init_metadata(struct
>> r600_common_screen *rscreen,
>>         memset(metadata, 0, sizeof(*metadata));
>>
>>         if (rscreen->chip_class >= GFX9) {
>> +               metadata->u.gfx9.swizzle_mode =
>> surface->u.gfx9.surf.swizzle_mode;
>>         } else {
>>                 metadata->u.legacy.microtile =
>> surface->u.legacy.level[0].mode >= RADEON_SURF_MODE_1D ?
>>                                            RADEON_LAYOUT_TILED :
>> RADEON_LAYOUT_LINEAR;
>> @@ -1345,6 +1346,7 @@ static struct pipe_resource
>> *r600_texture_from_handle(struct pipe_screen *screen
>>         int r;
>>         struct radeon_bo_metadata metadata = {};
>>         struct r600_texture *rtex;
>> +       bool is_scanout;
>>
>>         /* Support only 2D textures without mipmaps */
>>         if ((templ->target != PIPE_TEXTURE_2D && templ->target !=
>> PIPE_TEXTURE_RECT) ||
>> @@ -1358,6 +1360,13 @@ static struct pipe_resource
>> *r600_texture_from_handle(struct pipe_screen *screen
>>         rscreen->ws->buffer_get_metadata(buf, &metadata);
>>
>>         if (rscreen->chip_class >= GFX9) {
>> +               if (metadata.u.gfx9.swizzle_mode > 0)
>> +                       array_mode = RADEON_SURF_MODE_2D;
>> +               else
>> +                       array_mode = RADEON_SURF_MODE_LINEAR_ALIGNED;
>> +
>> +               is_scanout = metadata.u.gfx9.swizzle_mode == 0 ||
>> +                            metadata.u.gfx9.swizzle_mode % 4 == 2;
>>         } else {
>>                 surface.u.legacy.pipe_config =
>> metadata.u.legacy.pipe_config;
>>                 surface.u.legacy.bankw = metadata.u.legacy.bankw;
>> @@ -1372,10 +1381,12 @@ static struct pipe_resource
>> *r600_texture_from_handle(struct pipe_screen *screen
>>                         array_mode = RADEON_SURF_MODE_1D;
>>                 else
>>                         array_mode = RADEON_SURF_MODE_LINEAR_ALIGNED;
>> +
>> +               is_scanout = metadata.u.legacy.scanout;
>>         }
>>
>>         r = r600_init_surface(rscreen, &surface, templ, array_mode,
>> stride,
>> -                             offset, true, metadata.u.legacy.scanout,
>> false, false);
>> +                             offset, true, is_scanout, false, false);
>>         if (r) {
>>                 return NULL;
>>         }
>> @@ -1390,6 +1401,13 @@ static struct pipe_resource
>> *r600_texture_from_handle(struct pipe_screen *screen
>>         if (rscreen->apply_opaque_metadata)
>>                 rscreen->apply_opaque_metadata(rscreen, rtex, &metadata);
>>
>> +       /* Validate that addrlib arrived at the same surface parameters.
>> */
>> +       if (rscreen->chip_class >= GFX9) {
>> +               struct gfx9_surf_layout *gfx9 = &surface.u.gfx9;
>> +
>> +               assert(metadata.u.gfx9.swizzle_mode ==
>> gfx9->surf.swizzle_mode);
>> +       }
>> +
>>         return &rtex->resource.b.b;
>>  }
>>
>> diff --git a/src/gallium/drivers/radeon/radeon_winsys.h
>> b/src/gallium/drivers/radeon/radeon_winsys.h
>> index b3c7608..7839170 100644
>> --- a/src/gallium/drivers/radeon/radeon_winsys.h
>> +++ b/src/gallium/drivers/radeon/radeon_winsys.h
>> @@ -250,6 +250,11 @@ struct radeon_bo_metadata {
>>              unsigned                stride;
>>              bool                    scanout;
>>          } legacy;
>> +
>> +        struct {
>> +            /* surface flags */
>> +            unsigned swizzle_mode:5;
>> +        } gfx9;
>>      } u;
>>
>>      /* Additional metadata associated with the buffer, in bytes.
>> --
>> 2.7.4
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/mesa-dev