Re: [Mesa-dev] [PATCH 2/2] radeonsi: Add CIK SDMA support

2015-05-26 Thread Michel Dänzer
On 27.05.2015 04:29, Grigori Goronzy wrote:
> On 26.05.2015 09:28, Michel Dänzer wrote:
>> From: Michel Dänzer 
>>
>> Based on the corresponding SI support. Same as that, this is currently
>> only enabled for one-dimensional buffer copies due to issues with
>> multi-dimensional SDMA copies.
>>
> 
> What a pity, so CIK has exactly the same issues as SI?

Not exactly the same, just neither is working well enough to enable it
for multi-dimensional copies.


> Reviewed-by: Grigori Goronzy 

Thank you (and Alex and Marek).


-- 
Earthling Michel Dänzer   |   http://www.amd.com
Libre software enthusiast | Mesa and X developer
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 2/2] radeonsi: Add CIK SDMA support

2015-05-26 Thread Alex Deucher
On Tue, May 26, 2015 at 3:29 PM, Grigori Goronzy  wrote:
> On 26.05.2015 09:28, Michel Dänzer wrote:
>> From: Michel Dänzer 
>>
>> Based on the corresponding SI support. Same as that, this is currently
>> only enabled for one-dimensional buffer copies due to issues with
>> multi-dimensional SDMA copies.
>>
>
> What a pity, so CIK has exactly the same issues as SI? We should really
> try to figure out what's wrong with tiled DMA copies.

It's probably worth checking again with amdgpu and addrlib.  Might be
some alignment we are getting wrong somewhere.

Alex


>
> Anyway,
>
> Reviewed-by: Grigori Goronzy 
>
>> Signed-off-by: Michel Dänzer 
>> ---
>>  src/gallium/drivers/radeonsi/Makefile.sources |   1 +
>>  src/gallium/drivers/radeonsi/cik_sdma.c   | 364 
>> ++
>>  src/gallium/drivers/radeonsi/si_dma.c |  20 --
>>  src/gallium/drivers/radeonsi/si_pipe.h|   9 +
>>  src/gallium/drivers/radeonsi/si_state.c   |  22 +-
>>  src/gallium/drivers/radeonsi/si_state.h   |   1 +
>>  src/gallium/drivers/radeonsi/sid.h|  31 +++
>>  7 files changed, 427 insertions(+), 21 deletions(-)
>>  create mode 100644 src/gallium/drivers/radeonsi/cik_sdma.c
>>
>> diff --git a/src/gallium/drivers/radeonsi/Makefile.sources 
>> b/src/gallium/drivers/radeonsi/Makefile.sources
>> index 774dc22..2876c0a 100644
>> --- a/src/gallium/drivers/radeonsi/Makefile.sources
>> +++ b/src/gallium/drivers/radeonsi/Makefile.sources
>> @@ -1,4 +1,5 @@
>>  C_SOURCES := \
>> + cik_sdma.c \
>>   si_blit.c \
>>   si_commands.c \
>>   si_compute.c \
>> diff --git a/src/gallium/drivers/radeonsi/cik_sdma.c 
>> b/src/gallium/drivers/radeonsi/cik_sdma.c
>> new file mode 100644
>> index 000..3c0103a
>> --- /dev/null
>> +++ b/src/gallium/drivers/radeonsi/cik_sdma.c
>> @@ -0,0 +1,364 @@
>> +/*
>> + * Copyright 2010 Jerome Glisse 
>> + * Copyright 2014 Advanced Micro Devices, Inc.
>> + *
>> + * 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
>> + * on 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 AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
>> + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
>> + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
>> + * USE OR OTHER DEALINGS IN THE SOFTWARE.
>> + *
>> + * Authors:
>> + *  Jerome Glisse
>> + */
>> +
>> +#include "sid.h"
>> +#include "si_pipe.h"
>> +#include "../radeon/r600_cs.h"
>> +
>> +#include "util/u_format.h"
>> +
>> +static uint32_t cik_micro_tile_mode(struct si_screen *sscreen, unsigned 
>> tile_mode)
>> +{
>> + if (sscreen->b.info.si_tile_mode_array_valid) {
>> + uint32_t gb_tile_mode = 
>> sscreen->b.info.si_tile_mode_array[tile_mode];
>> +
>> + return G_009910_MICRO_TILE_MODE_NEW(gb_tile_mode);
>> + }
>> +
>> + /* The kernel cannod return the tile mode array. Guess? */
>> + return V_009910_ADDR_SURF_THIN_MICRO_TILING;
>> +}
>> +
>> +static void cik_sdma_do_copy_buffer(struct si_context *ctx,
>> + struct pipe_resource *dst,
>> + struct pipe_resource *src,
>> + uint64_t dst_offset,
>> + uint64_t src_offset,
>> + uint64_t size)
>> +{
>> + struct radeon_winsys_cs *cs = ctx->b.rings.dma.cs;
>> + unsigned i, ncopy, csize;
>> + struct r600_resource *rdst = (struct r600_resource*)dst;
>> + struct r600_resource *rsrc = (struct r600_resource*)src;
>> +
>> + dst_offset += r600_resource(dst)->gpu_address;
>> + src_offset += r600_resource(src)->gpu_address;
>> +
>> + ncopy = (size + CIK_SDMA_COPY_MAX_SIZE - 1) / CIK_SDMA_COPY_MAX_SIZE;
>> + r600_need_dma_space(&ctx->b, ncopy * 7);
>> +
>> + r600_context_bo_reloc(&ctx->b, &ctx->b.rings.dma, rsrc, 
>> RADEON_USAGE_READ,
>> +   RADEON_PRIO_MIN);
>> + r600_context_bo_reloc(&ctx->b, &ctx->b.rings.dma, rdst, 
>> RADEON_USAGE_WRITE,
>> +   RADEON_PRIO_MIN);
>> +
>> + for (i = 0; i < ncopy; i++) {
>> + csize = size < CIK_S

Re: [Mesa-dev] [PATCH 2/2] radeonsi: Add CIK SDMA support

2015-05-26 Thread Marek Olšák
I suggest we implement a thorough SDMA test first before trying to fix
it. We definitely want to test all implemented tiling modes,
dimensions, subrectangles of those (for the copies), bit depths,
number of samples, etc. and some of those parameters can differ
between src and dst. The list of tested dimensions and subrectangles
doesn't have to be exhaustive, but it should target various corner
cases (e.g. 1-129, then the next power-of-two value followed by a
non-power-of-two value, and repeat up to the maximum size). The test
should be part of the driver and should be invoked by
radeonsi_screen_create based on an environment variable. The
correctness of the test should be validated with resource_copy_region
(without SDMA).

After that, we can start fixing SDMA support.

Marek

On Tue, May 26, 2015 at 9:29 PM, Grigori Goronzy  wrote:
> On 26.05.2015 09:28, Michel Dänzer wrote:
>> From: Michel Dänzer 
>>
>> Based on the corresponding SI support. Same as that, this is currently
>> only enabled for one-dimensional buffer copies due to issues with
>> multi-dimensional SDMA copies.
>>
>
> What a pity, so CIK has exactly the same issues as SI? We should really
> try to figure out what's wrong with tiled DMA copies.
>
> Anyway,
>
> Reviewed-by: Grigori Goronzy 
>
>> Signed-off-by: Michel Dänzer 
>> ---
>>  src/gallium/drivers/radeonsi/Makefile.sources |   1 +
>>  src/gallium/drivers/radeonsi/cik_sdma.c   | 364 
>> ++
>>  src/gallium/drivers/radeonsi/si_dma.c |  20 --
>>  src/gallium/drivers/radeonsi/si_pipe.h|   9 +
>>  src/gallium/drivers/radeonsi/si_state.c   |  22 +-
>>  src/gallium/drivers/radeonsi/si_state.h   |   1 +
>>  src/gallium/drivers/radeonsi/sid.h|  31 +++
>>  7 files changed, 427 insertions(+), 21 deletions(-)
>>  create mode 100644 src/gallium/drivers/radeonsi/cik_sdma.c
>>
>> diff --git a/src/gallium/drivers/radeonsi/Makefile.sources 
>> b/src/gallium/drivers/radeonsi/Makefile.sources
>> index 774dc22..2876c0a 100644
>> --- a/src/gallium/drivers/radeonsi/Makefile.sources
>> +++ b/src/gallium/drivers/radeonsi/Makefile.sources
>> @@ -1,4 +1,5 @@
>>  C_SOURCES := \
>> + cik_sdma.c \
>>   si_blit.c \
>>   si_commands.c \
>>   si_compute.c \
>> diff --git a/src/gallium/drivers/radeonsi/cik_sdma.c 
>> b/src/gallium/drivers/radeonsi/cik_sdma.c
>> new file mode 100644
>> index 000..3c0103a
>> --- /dev/null
>> +++ b/src/gallium/drivers/radeonsi/cik_sdma.c
>> @@ -0,0 +1,364 @@
>> +/*
>> + * Copyright 2010 Jerome Glisse 
>> + * Copyright 2014 Advanced Micro Devices, Inc.
>> + *
>> + * 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
>> + * on 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 AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
>> + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
>> + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
>> + * USE OR OTHER DEALINGS IN THE SOFTWARE.
>> + *
>> + * Authors:
>> + *  Jerome Glisse
>> + */
>> +
>> +#include "sid.h"
>> +#include "si_pipe.h"
>> +#include "../radeon/r600_cs.h"
>> +
>> +#include "util/u_format.h"
>> +
>> +static uint32_t cik_micro_tile_mode(struct si_screen *sscreen, unsigned 
>> tile_mode)
>> +{
>> + if (sscreen->b.info.si_tile_mode_array_valid) {
>> + uint32_t gb_tile_mode = 
>> sscreen->b.info.si_tile_mode_array[tile_mode];
>> +
>> + return G_009910_MICRO_TILE_MODE_NEW(gb_tile_mode);
>> + }
>> +
>> + /* The kernel cannod return the tile mode array. Guess? */
>> + return V_009910_ADDR_SURF_THIN_MICRO_TILING;
>> +}
>> +
>> +static void cik_sdma_do_copy_buffer(struct si_context *ctx,
>> + struct pipe_resource *dst,
>> + struct pipe_resource *src,
>> + uint64_t dst_offset,
>> + uint64_t src_offset,
>> + uint64_t size)
>> +{
>> + struct radeon_winsys_cs *cs = ctx->b.rings.dma.cs;
>> + unsigned i, ncopy, csize;
>> + struct r600_resource *rdst = (struct r600_resource*)dst;
>> + struct 

Re: [Mesa-dev] [PATCH 2/2] radeonsi: Add CIK SDMA support

2015-05-26 Thread Grigori Goronzy
On 26.05.2015 09:28, Michel Dänzer wrote:
> From: Michel Dänzer 
> 
> Based on the corresponding SI support. Same as that, this is currently
> only enabled for one-dimensional buffer copies due to issues with
> multi-dimensional SDMA copies.
>

What a pity, so CIK has exactly the same issues as SI? We should really
try to figure out what's wrong with tiled DMA copies.

Anyway,

Reviewed-by: Grigori Goronzy 

> Signed-off-by: Michel Dänzer 
> ---
>  src/gallium/drivers/radeonsi/Makefile.sources |   1 +
>  src/gallium/drivers/radeonsi/cik_sdma.c   | 364 
> ++
>  src/gallium/drivers/radeonsi/si_dma.c |  20 --
>  src/gallium/drivers/radeonsi/si_pipe.h|   9 +
>  src/gallium/drivers/radeonsi/si_state.c   |  22 +-
>  src/gallium/drivers/radeonsi/si_state.h   |   1 +
>  src/gallium/drivers/radeonsi/sid.h|  31 +++
>  7 files changed, 427 insertions(+), 21 deletions(-)
>  create mode 100644 src/gallium/drivers/radeonsi/cik_sdma.c
> 
> diff --git a/src/gallium/drivers/radeonsi/Makefile.sources 
> b/src/gallium/drivers/radeonsi/Makefile.sources
> index 774dc22..2876c0a 100644
> --- a/src/gallium/drivers/radeonsi/Makefile.sources
> +++ b/src/gallium/drivers/radeonsi/Makefile.sources
> @@ -1,4 +1,5 @@
>  C_SOURCES := \
> + cik_sdma.c \
>   si_blit.c \
>   si_commands.c \
>   si_compute.c \
> diff --git a/src/gallium/drivers/radeonsi/cik_sdma.c 
> b/src/gallium/drivers/radeonsi/cik_sdma.c
> new file mode 100644
> index 000..3c0103a
> --- /dev/null
> +++ b/src/gallium/drivers/radeonsi/cik_sdma.c
> @@ -0,0 +1,364 @@
> +/*
> + * Copyright 2010 Jerome Glisse 
> + * Copyright 2014 Advanced Micro Devices, Inc.
> + *
> + * 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
> + * on 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 AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
> + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
> + * USE OR OTHER DEALINGS IN THE SOFTWARE.
> + *
> + * Authors:
> + *  Jerome Glisse
> + */
> +
> +#include "sid.h"
> +#include "si_pipe.h"
> +#include "../radeon/r600_cs.h"
> +
> +#include "util/u_format.h"
> +
> +static uint32_t cik_micro_tile_mode(struct si_screen *sscreen, unsigned 
> tile_mode)
> +{
> + if (sscreen->b.info.si_tile_mode_array_valid) {
> + uint32_t gb_tile_mode = 
> sscreen->b.info.si_tile_mode_array[tile_mode];
> +
> + return G_009910_MICRO_TILE_MODE_NEW(gb_tile_mode);
> + }
> +
> + /* The kernel cannod return the tile mode array. Guess? */
> + return V_009910_ADDR_SURF_THIN_MICRO_TILING;
> +}
> +
> +static void cik_sdma_do_copy_buffer(struct si_context *ctx,
> + struct pipe_resource *dst,
> + struct pipe_resource *src,
> + uint64_t dst_offset,
> + uint64_t src_offset,
> + uint64_t size)
> +{
> + struct radeon_winsys_cs *cs = ctx->b.rings.dma.cs;
> + unsigned i, ncopy, csize;
> + struct r600_resource *rdst = (struct r600_resource*)dst;
> + struct r600_resource *rsrc = (struct r600_resource*)src;
> +
> + dst_offset += r600_resource(dst)->gpu_address;
> + src_offset += r600_resource(src)->gpu_address;
> +
> + ncopy = (size + CIK_SDMA_COPY_MAX_SIZE - 1) / CIK_SDMA_COPY_MAX_SIZE;
> + r600_need_dma_space(&ctx->b, ncopy * 7);
> +
> + r600_context_bo_reloc(&ctx->b, &ctx->b.rings.dma, rsrc, 
> RADEON_USAGE_READ,
> +   RADEON_PRIO_MIN);
> + r600_context_bo_reloc(&ctx->b, &ctx->b.rings.dma, rdst, 
> RADEON_USAGE_WRITE,
> +   RADEON_PRIO_MIN);
> +
> + for (i = 0; i < ncopy; i++) {
> + csize = size < CIK_SDMA_COPY_MAX_SIZE ? size : 
> CIK_SDMA_COPY_MAX_SIZE;
> + cs->buf[cs->cdw++] = CIK_SDMA_PACKET(CIK_SDMA_OPCODE_COPY,
> +  
> CIK_SDMA_COPY_SUB_OPCODE_LINEAR,
> +  0);
> + cs->buf[cs->cdw++] = csize;

Re: [Mesa-dev] [PATCH 2/2] radeonsi: Add CIK SDMA support

2015-05-26 Thread Alex Deucher
On Tue, May 26, 2015 at 3:28 AM, Michel Dänzer  wrote:
> From: Michel Dänzer 
>
> Based on the corresponding SI support. Same as that, this is currently
> only enabled for one-dimensional buffer copies due to issues with
> multi-dimensional SDMA copies.
>
> Signed-off-by: Michel Dänzer 

For the series:
Reviewed-by: Alex Deucher 

> ---
>  src/gallium/drivers/radeonsi/Makefile.sources |   1 +
>  src/gallium/drivers/radeonsi/cik_sdma.c   | 364 
> ++
>  src/gallium/drivers/radeonsi/si_dma.c |  20 --
>  src/gallium/drivers/radeonsi/si_pipe.h|   9 +
>  src/gallium/drivers/radeonsi/si_state.c   |  22 +-
>  src/gallium/drivers/radeonsi/si_state.h   |   1 +
>  src/gallium/drivers/radeonsi/sid.h|  31 +++
>  7 files changed, 427 insertions(+), 21 deletions(-)
>  create mode 100644 src/gallium/drivers/radeonsi/cik_sdma.c
>
> diff --git a/src/gallium/drivers/radeonsi/Makefile.sources 
> b/src/gallium/drivers/radeonsi/Makefile.sources
> index 774dc22..2876c0a 100644
> --- a/src/gallium/drivers/radeonsi/Makefile.sources
> +++ b/src/gallium/drivers/radeonsi/Makefile.sources
> @@ -1,4 +1,5 @@
>  C_SOURCES := \
> +   cik_sdma.c \
> si_blit.c \
> si_commands.c \
> si_compute.c \
> diff --git a/src/gallium/drivers/radeonsi/cik_sdma.c 
> b/src/gallium/drivers/radeonsi/cik_sdma.c
> new file mode 100644
> index 000..3c0103a
> --- /dev/null
> +++ b/src/gallium/drivers/radeonsi/cik_sdma.c
> @@ -0,0 +1,364 @@
> +/*
> + * Copyright 2010 Jerome Glisse 
> + * Copyright 2014 Advanced Micro Devices, Inc.
> + *
> + * 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
> + * on 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 AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
> + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
> + * USE OR OTHER DEALINGS IN THE SOFTWARE.
> + *
> + * Authors:
> + *  Jerome Glisse
> + */
> +
> +#include "sid.h"
> +#include "si_pipe.h"
> +#include "../radeon/r600_cs.h"
> +
> +#include "util/u_format.h"
> +
> +static uint32_t cik_micro_tile_mode(struct si_screen *sscreen, unsigned 
> tile_mode)
> +{
> +   if (sscreen->b.info.si_tile_mode_array_valid) {
> +   uint32_t gb_tile_mode = 
> sscreen->b.info.si_tile_mode_array[tile_mode];
> +
> +   return G_009910_MICRO_TILE_MODE_NEW(gb_tile_mode);
> +   }
> +
> +   /* The kernel cannod return the tile mode array. Guess? */
> +   return V_009910_ADDR_SURF_THIN_MICRO_TILING;
> +}
> +
> +static void cik_sdma_do_copy_buffer(struct si_context *ctx,
> +   struct pipe_resource *dst,
> +   struct pipe_resource *src,
> +   uint64_t dst_offset,
> +   uint64_t src_offset,
> +   uint64_t size)
> +{
> +   struct radeon_winsys_cs *cs = ctx->b.rings.dma.cs;
> +   unsigned i, ncopy, csize;
> +   struct r600_resource *rdst = (struct r600_resource*)dst;
> +   struct r600_resource *rsrc = (struct r600_resource*)src;
> +
> +   dst_offset += r600_resource(dst)->gpu_address;
> +   src_offset += r600_resource(src)->gpu_address;
> +
> +   ncopy = (size + CIK_SDMA_COPY_MAX_SIZE - 1) / CIK_SDMA_COPY_MAX_SIZE;
> +   r600_need_dma_space(&ctx->b, ncopy * 7);
> +
> +   r600_context_bo_reloc(&ctx->b, &ctx->b.rings.dma, rsrc, 
> RADEON_USAGE_READ,
> + RADEON_PRIO_MIN);
> +   r600_context_bo_reloc(&ctx->b, &ctx->b.rings.dma, rdst, 
> RADEON_USAGE_WRITE,
> + RADEON_PRIO_MIN);
> +
> +   for (i = 0; i < ncopy; i++) {
> +   csize = size < CIK_SDMA_COPY_MAX_SIZE ? size : 
> CIK_SDMA_COPY_MAX_SIZE;
> +   cs->buf[cs->cdw++] = CIK_SDMA_PACKET(CIK_SDMA_OPCODE_COPY,
> +
> CIK_SDMA_COPY_SUB_OPCODE_LINEAR,
> +0);
> +   cs->buf[cs->cdw++] = csize;
> +   cs->buf[cs->cdw++] = 0; /* 

[Mesa-dev] [PATCH 2/2] radeonsi: Add CIK SDMA support

2015-05-26 Thread Michel Dänzer
From: Michel Dänzer 

Based on the corresponding SI support. Same as that, this is currently
only enabled for one-dimensional buffer copies due to issues with
multi-dimensional SDMA copies.

Signed-off-by: Michel Dänzer 
---
 src/gallium/drivers/radeonsi/Makefile.sources |   1 +
 src/gallium/drivers/radeonsi/cik_sdma.c   | 364 ++
 src/gallium/drivers/radeonsi/si_dma.c |  20 --
 src/gallium/drivers/radeonsi/si_pipe.h|   9 +
 src/gallium/drivers/radeonsi/si_state.c   |  22 +-
 src/gallium/drivers/radeonsi/si_state.h   |   1 +
 src/gallium/drivers/radeonsi/sid.h|  31 +++
 7 files changed, 427 insertions(+), 21 deletions(-)
 create mode 100644 src/gallium/drivers/radeonsi/cik_sdma.c

diff --git a/src/gallium/drivers/radeonsi/Makefile.sources 
b/src/gallium/drivers/radeonsi/Makefile.sources
index 774dc22..2876c0a 100644
--- a/src/gallium/drivers/radeonsi/Makefile.sources
+++ b/src/gallium/drivers/radeonsi/Makefile.sources
@@ -1,4 +1,5 @@
 C_SOURCES := \
+   cik_sdma.c \
si_blit.c \
si_commands.c \
si_compute.c \
diff --git a/src/gallium/drivers/radeonsi/cik_sdma.c 
b/src/gallium/drivers/radeonsi/cik_sdma.c
new file mode 100644
index 000..3c0103a
--- /dev/null
+++ b/src/gallium/drivers/radeonsi/cik_sdma.c
@@ -0,0 +1,364 @@
+/*
+ * Copyright 2010 Jerome Glisse 
+ * Copyright 2014 Advanced Micro Devices, Inc.
+ *
+ * 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
+ * on 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 AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *  Jerome Glisse
+ */
+
+#include "sid.h"
+#include "si_pipe.h"
+#include "../radeon/r600_cs.h"
+
+#include "util/u_format.h"
+
+static uint32_t cik_micro_tile_mode(struct si_screen *sscreen, unsigned 
tile_mode)
+{
+   if (sscreen->b.info.si_tile_mode_array_valid) {
+   uint32_t gb_tile_mode = 
sscreen->b.info.si_tile_mode_array[tile_mode];
+
+   return G_009910_MICRO_TILE_MODE_NEW(gb_tile_mode);
+   }
+
+   /* The kernel cannod return the tile mode array. Guess? */
+   return V_009910_ADDR_SURF_THIN_MICRO_TILING;
+}
+
+static void cik_sdma_do_copy_buffer(struct si_context *ctx,
+   struct pipe_resource *dst,
+   struct pipe_resource *src,
+   uint64_t dst_offset,
+   uint64_t src_offset,
+   uint64_t size)
+{
+   struct radeon_winsys_cs *cs = ctx->b.rings.dma.cs;
+   unsigned i, ncopy, csize;
+   struct r600_resource *rdst = (struct r600_resource*)dst;
+   struct r600_resource *rsrc = (struct r600_resource*)src;
+
+   dst_offset += r600_resource(dst)->gpu_address;
+   src_offset += r600_resource(src)->gpu_address;
+
+   ncopy = (size + CIK_SDMA_COPY_MAX_SIZE - 1) / CIK_SDMA_COPY_MAX_SIZE;
+   r600_need_dma_space(&ctx->b, ncopy * 7);
+
+   r600_context_bo_reloc(&ctx->b, &ctx->b.rings.dma, rsrc, 
RADEON_USAGE_READ,
+ RADEON_PRIO_MIN);
+   r600_context_bo_reloc(&ctx->b, &ctx->b.rings.dma, rdst, 
RADEON_USAGE_WRITE,
+ RADEON_PRIO_MIN);
+
+   for (i = 0; i < ncopy; i++) {
+   csize = size < CIK_SDMA_COPY_MAX_SIZE ? size : 
CIK_SDMA_COPY_MAX_SIZE;
+   cs->buf[cs->cdw++] = CIK_SDMA_PACKET(CIK_SDMA_OPCODE_COPY,
+
CIK_SDMA_COPY_SUB_OPCODE_LINEAR,
+0);
+   cs->buf[cs->cdw++] = csize;
+   cs->buf[cs->cdw++] = 0; /* src/dst endian swap */
+   cs->buf[cs->cdw++] = src_offset;
+   cs->buf[cs->cdw++] = src_offset >> 32;
+   cs->buf[cs->cdw++] = dst_offset;
+   cs->buf[cs->cdw++] = dst_offset >> 32;
+   dst_offset += csize;
+   src_offset += csize;
+   size -= csize