Re: [Mesa-dev] [PATCH] radv/gfx9: add 3d sampler image->buffer copy shader. (v2)

2017-12-20 Thread Dave Airlie
On 21 December 2017 at 03:46, Alex Smith  wrote:
> Looks like blit2d needs this fix as well - been debugging an issue that's
> turned out to be due to a corrupted copy of a 3D texture with CmdCopyImage.
> I can do that tomorrow.

I already wrote that as well,

https://github.com/airlied/mesa/tree/radv-wip-vega-3d

>
> However, I did notice that with KHR_maintenance1, it seems like creating 2D
> views of 3D textures (and binding them to 2D samplers) is expected to work -
> see VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR. Is there no way to make
> that work on GFX9?

I'm not sure I assume there is some way, I just haven't seen a failing
CTS test yet,
which leads me to believe cts coverage in some of this stuff is
lacking, since we only
seem to fail when we get down into lower mipmaps.

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


Re: [Mesa-dev] [PATCH] radv/gfx9: add 3d sampler image->buffer copy shader. (v2)

2017-12-20 Thread Alex Smith
Looks like blit2d needs this fix as well - been debugging an issue that's
turned out to be due to a corrupted copy of a 3D texture with CmdCopyImage.
I can do that tomorrow.

However, I did notice that with KHR_maintenance1, it seems like creating 2D
views of 3D textures (and binding them to 2D samplers) is expected to work
- see VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR. Is there no way to make
that work on GFX9?

Thanks,
Alex

On 20 December 2017 at 14:49, Alex Smith 
wrote:

> Tested-by: Alex Smith 
>
> Fixes 3D texture contents being captured incorrectly in RenderDoc for me.
>
> On 19 December 2017 at 07:36, Dave Airlie  wrote:
>
>> From: Dave Airlie 
>>
>> On GFX9 we must access 3D textures with 3D samplers AFAICS.
>>
>> This fixes:
>> dEQP-VK.api.image_clearing.core.clear_color_image.3d.single_layer
>>
>> on GFX9 for me.
>>
>> v2: fixes a bunch of other tests as well.
>>
>> v1.1: fix tex->sampler_dim to dim
>> v2: send layer in from outside
>>
>> Fixes: e38685cc62e 'Revert "radv: disable support for VEGA for now."'
>> Signed-off-by: Dave Airlie 
>> ---
>>  src/amd/vulkan/radv_meta_bufimage.c | 87 ++
>> ---
>>  src/amd/vulkan/radv_private.h   |  1 +
>>  2 files changed, 72 insertions(+), 16 deletions(-)
>>
>> diff --git a/src/amd/vulkan/radv_meta_bufimage.c
>> b/src/amd/vulkan/radv_meta_bufimage.c
>> index dfd99aa75f..4a61beef18 100644
>> --- a/src/amd/vulkan/radv_meta_bufimage.c
>> +++ b/src/amd/vulkan/radv_meta_bufimage.c
>> @@ -29,11 +29,15 @@
>>   * Compute queue: implementation also of buffer->image, image->image,
>> and image clear.
>>   */
>>
>> +/* GFX9 needs to use a 3D sampler to access 3D resources, so the shader
>> has the options
>> + * for that.
>> + */
>>  static nir_shader *
>> -build_nir_itob_compute_shader(struct radv_device *dev)
>> +build_nir_itob_compute_shader(struct radv_device *dev, bool is_3d)
>>  {
>> nir_builder b;
>> -   const struct glsl_type *sampler_type =
>> glsl_sampler_type(GLSL_SAMPLER_DIM_2D,
>> +   enum glsl_sampler_dim dim = is_3d ? GLSL_SAMPLER_DIM_3D :
>> GLSL_SAMPLER_DIM_2D;
>> +   const struct glsl_type *sampler_type = glsl_sampler_type(dim,
>>  false,
>>  false,
>>
>>  GLSL_TYPE_FLOAT);
>> @@ -42,7 +46,7 @@ build_nir_itob_compute_shader(struct radv_device *dev)
>>  false,
>>
>>  GLSL_TYPE_FLOAT);
>> nir_builder_init_simple_shader(, NULL, MESA_SHADER_COMPUTE,
>> NULL);
>> -   b.shader->info.name = ralloc_strdup(b.shader, "meta_itob_cs");
>> +   b.shader->info.name = ralloc_strdup(b.shader, is_3d ?
>> "meta_itob_cs_3d" : "meta_itob_cs");
>> b.shader->info.cs.local_size[0] = 16;
>> b.shader->info.cs.local_size[1] = 16;
>> b.shader->info.cs.local_size[2] = 1;
>> @@ -69,32 +73,46 @@ build_nir_itob_compute_shader(struct radv_device
>> *dev)
>>
>> nir_intrinsic_instr *offset = nir_intrinsic_instr_create(b.shader,
>> nir_intrinsic_load_push_constant);
>> nir_intrinsic_set_base(offset, 0);
>> -   nir_intrinsic_set_range(offset, 12);
>> +   nir_intrinsic_set_range(offset, 16);
>> offset->src[0] = nir_src_for_ssa(nir_imm_int(, 0));
>> -   offset->num_components = 2;
>> -   nir_ssa_dest_init(>instr, >dest, 2, 32,
>> "offset");
>> +   offset->num_components = 3;
>> +   nir_ssa_dest_init(>instr, >dest, 3, 32,
>> "offset");
>> nir_builder_instr_insert(, >instr);
>>
>> nir_intrinsic_instr *stride = nir_intrinsic_instr_create(b.shader,
>> nir_intrinsic_load_push_constant);
>> nir_intrinsic_set_base(stride, 0);
>> -   nir_intrinsic_set_range(stride, 12);
>> -   stride->src[0] = nir_src_for_ssa(nir_imm_int(, 8));
>> +   nir_intrinsic_set_range(stride, 16);
>> +   stride->src[0] = nir_src_for_ssa(nir_imm_int(, 12));
>> stride->num_components = 1;
>> nir_ssa_dest_init(>instr, >dest, 1, 32,
>> "stride");
>> nir_builder_instr_insert(, >instr);
>>
>> nir_ssa_def *img_coord = nir_iadd(, global_id,
>> >dest.ssa);
>>
>> +   nir_ssa_def *img_coord_3d = NULL;
>> +
>> +   if (is_3d) {
>> +   nir_ssa_def *chans[3];
>> +
>> +   chans[0] = nir_channel(, img_coord, 0);
>> +   chans[1] = nir_channel(, img_coord, 1);
>> +   chans[2] = nir_channel(, img_coord, 2);
>> +   img_coord_3d = nir_vec(, chans, 3);
>> +   }
>> +
>> nir_tex_instr *tex = nir_tex_instr_create(b.shader, 2);
>> -   tex->sampler_dim = GLSL_SAMPLER_DIM_2D;
>> +   tex->sampler_dim = dim;
>> tex->op = nir_texop_txf;
>> tex->src[0].src_type = nir_tex_src_coord;
>> -   tex->src[0].src = 

Re: [Mesa-dev] [PATCH] radv/gfx9: add 3d sampler image->buffer copy shader. (v2)

2017-12-20 Thread Alex Smith
Tested-by: Alex Smith 

Fixes 3D texture contents being captured incorrectly in RenderDoc for me.

On 19 December 2017 at 07:36, Dave Airlie  wrote:

> From: Dave Airlie 
>
> On GFX9 we must access 3D textures with 3D samplers AFAICS.
>
> This fixes:
> dEQP-VK.api.image_clearing.core.clear_color_image.3d.single_layer
>
> on GFX9 for me.
>
> v2: fixes a bunch of other tests as well.
>
> v1.1: fix tex->sampler_dim to dim
> v2: send layer in from outside
>
> Fixes: e38685cc62e 'Revert "radv: disable support for VEGA for now."'
> Signed-off-by: Dave Airlie 
> ---
>  src/amd/vulkan/radv_meta_bufimage.c | 87 ++
> ---
>  src/amd/vulkan/radv_private.h   |  1 +
>  2 files changed, 72 insertions(+), 16 deletions(-)
>
> diff --git a/src/amd/vulkan/radv_meta_bufimage.c
> b/src/amd/vulkan/radv_meta_bufimage.c
> index dfd99aa75f..4a61beef18 100644
> --- a/src/amd/vulkan/radv_meta_bufimage.c
> +++ b/src/amd/vulkan/radv_meta_bufimage.c
> @@ -29,11 +29,15 @@
>   * Compute queue: implementation also of buffer->image, image->image, and
> image clear.
>   */
>
> +/* GFX9 needs to use a 3D sampler to access 3D resources, so the shader
> has the options
> + * for that.
> + */
>  static nir_shader *
> -build_nir_itob_compute_shader(struct radv_device *dev)
> +build_nir_itob_compute_shader(struct radv_device *dev, bool is_3d)
>  {
> nir_builder b;
> -   const struct glsl_type *sampler_type = glsl_sampler_type(GLSL_
> SAMPLER_DIM_2D,
> +   enum glsl_sampler_dim dim = is_3d ? GLSL_SAMPLER_DIM_3D :
> GLSL_SAMPLER_DIM_2D;
> +   const struct glsl_type *sampler_type = glsl_sampler_type(dim,
>  false,
>  false,
>
>  GLSL_TYPE_FLOAT);
> @@ -42,7 +46,7 @@ build_nir_itob_compute_shader(struct radv_device *dev)
>  false,
>
>  GLSL_TYPE_FLOAT);
> nir_builder_init_simple_shader(, NULL, MESA_SHADER_COMPUTE,
> NULL);
> -   b.shader->info.name = ralloc_strdup(b.shader, "meta_itob_cs");
> +   b.shader->info.name = ralloc_strdup(b.shader, is_3d ?
> "meta_itob_cs_3d" : "meta_itob_cs");
> b.shader->info.cs.local_size[0] = 16;
> b.shader->info.cs.local_size[1] = 16;
> b.shader->info.cs.local_size[2] = 1;
> @@ -69,32 +73,46 @@ build_nir_itob_compute_shader(struct radv_device *dev)
>
> nir_intrinsic_instr *offset = nir_intrinsic_instr_create(b.shader,
> nir_intrinsic_load_push_constant);
> nir_intrinsic_set_base(offset, 0);
> -   nir_intrinsic_set_range(offset, 12);
> +   nir_intrinsic_set_range(offset, 16);
> offset->src[0] = nir_src_for_ssa(nir_imm_int(, 0));
> -   offset->num_components = 2;
> -   nir_ssa_dest_init(>instr, >dest, 2, 32, "offset");
> +   offset->num_components = 3;
> +   nir_ssa_dest_init(>instr, >dest, 3, 32, "offset");
> nir_builder_instr_insert(, >instr);
>
> nir_intrinsic_instr *stride = nir_intrinsic_instr_create(b.shader,
> nir_intrinsic_load_push_constant);
> nir_intrinsic_set_base(stride, 0);
> -   nir_intrinsic_set_range(stride, 12);
> -   stride->src[0] = nir_src_for_ssa(nir_imm_int(, 8));
> +   nir_intrinsic_set_range(stride, 16);
> +   stride->src[0] = nir_src_for_ssa(nir_imm_int(, 12));
> stride->num_components = 1;
> nir_ssa_dest_init(>instr, >dest, 1, 32, "stride");
> nir_builder_instr_insert(, >instr);
>
> nir_ssa_def *img_coord = nir_iadd(, global_id,
> >dest.ssa);
>
> +   nir_ssa_def *img_coord_3d = NULL;
> +
> +   if (is_3d) {
> +   nir_ssa_def *chans[3];
> +
> +   chans[0] = nir_channel(, img_coord, 0);
> +   chans[1] = nir_channel(, img_coord, 1);
> +   chans[2] = nir_channel(, img_coord, 2);
> +   img_coord_3d = nir_vec(, chans, 3);
> +   }
> +
> nir_tex_instr *tex = nir_tex_instr_create(b.shader, 2);
> -   tex->sampler_dim = GLSL_SAMPLER_DIM_2D;
> +   tex->sampler_dim = dim;
> tex->op = nir_texop_txf;
> tex->src[0].src_type = nir_tex_src_coord;
> -   tex->src[0].src = nir_src_for_ssa(nir_channels(, img_coord,
> 0x3));
> +   if (is_3d)
> +   tex->src[0].src = nir_src_for_ssa(nir_channels(,
> img_coord_3d, 0x7));
> +   else
> +   tex->src[0].src = nir_src_for_ssa(nir_channels(,
> img_coord, 0x3));
> tex->src[1].src_type = nir_tex_src_lod;
> tex->src[1].src = nir_src_for_ssa(nir_imm_int(, 0));
> tex->dest_type = nir_type_float;
> tex->is_array = false;
> -   tex->coord_components = 2;
> +   tex->coord_components = is_3d ? 3 : 2;
> tex->texture = nir_deref_var_create(tex, input_img);
> tex->sampler = NULL;
>
> @@ -126,8 +144,11 @@ 

[Mesa-dev] [PATCH] radv/gfx9: add 3d sampler image->buffer copy shader. (v2)

2017-12-18 Thread Dave Airlie
From: Dave Airlie 

On GFX9 we must access 3D textures with 3D samplers AFAICS.

This fixes:
dEQP-VK.api.image_clearing.core.clear_color_image.3d.single_layer

on GFX9 for me.

v2: fixes a bunch of other tests as well.

v1.1: fix tex->sampler_dim to dim
v2: send layer in from outside

Fixes: e38685cc62e 'Revert "radv: disable support for VEGA for now."'
Signed-off-by: Dave Airlie 
---
 src/amd/vulkan/radv_meta_bufimage.c | 87 ++---
 src/amd/vulkan/radv_private.h   |  1 +
 2 files changed, 72 insertions(+), 16 deletions(-)

diff --git a/src/amd/vulkan/radv_meta_bufimage.c 
b/src/amd/vulkan/radv_meta_bufimage.c
index dfd99aa75f..4a61beef18 100644
--- a/src/amd/vulkan/radv_meta_bufimage.c
+++ b/src/amd/vulkan/radv_meta_bufimage.c
@@ -29,11 +29,15 @@
  * Compute queue: implementation also of buffer->image, image->image, and 
image clear.
  */
 
+/* GFX9 needs to use a 3D sampler to access 3D resources, so the shader has 
the options
+ * for that.
+ */
 static nir_shader *
-build_nir_itob_compute_shader(struct radv_device *dev)
+build_nir_itob_compute_shader(struct radv_device *dev, bool is_3d)
 {
nir_builder b;
-   const struct glsl_type *sampler_type = 
glsl_sampler_type(GLSL_SAMPLER_DIM_2D,
+   enum glsl_sampler_dim dim = is_3d ? GLSL_SAMPLER_DIM_3D : 
GLSL_SAMPLER_DIM_2D;
+   const struct glsl_type *sampler_type = glsl_sampler_type(dim,
 false,
 false,
 
GLSL_TYPE_FLOAT);
@@ -42,7 +46,7 @@ build_nir_itob_compute_shader(struct radv_device *dev)
 false,
 GLSL_TYPE_FLOAT);
nir_builder_init_simple_shader(, NULL, MESA_SHADER_COMPUTE, NULL);
-   b.shader->info.name = ralloc_strdup(b.shader, "meta_itob_cs");
+   b.shader->info.name = ralloc_strdup(b.shader, is_3d ? "meta_itob_cs_3d" 
: "meta_itob_cs");
b.shader->info.cs.local_size[0] = 16;
b.shader->info.cs.local_size[1] = 16;
b.shader->info.cs.local_size[2] = 1;
@@ -69,32 +73,46 @@ build_nir_itob_compute_shader(struct radv_device *dev)
 
nir_intrinsic_instr *offset = nir_intrinsic_instr_create(b.shader, 
nir_intrinsic_load_push_constant);
nir_intrinsic_set_base(offset, 0);
-   nir_intrinsic_set_range(offset, 12);
+   nir_intrinsic_set_range(offset, 16);
offset->src[0] = nir_src_for_ssa(nir_imm_int(, 0));
-   offset->num_components = 2;
-   nir_ssa_dest_init(>instr, >dest, 2, 32, "offset");
+   offset->num_components = 3;
+   nir_ssa_dest_init(>instr, >dest, 3, 32, "offset");
nir_builder_instr_insert(, >instr);
 
nir_intrinsic_instr *stride = nir_intrinsic_instr_create(b.shader, 
nir_intrinsic_load_push_constant);
nir_intrinsic_set_base(stride, 0);
-   nir_intrinsic_set_range(stride, 12);
-   stride->src[0] = nir_src_for_ssa(nir_imm_int(, 8));
+   nir_intrinsic_set_range(stride, 16);
+   stride->src[0] = nir_src_for_ssa(nir_imm_int(, 12));
stride->num_components = 1;
nir_ssa_dest_init(>instr, >dest, 1, 32, "stride");
nir_builder_instr_insert(, >instr);
 
nir_ssa_def *img_coord = nir_iadd(, global_id, >dest.ssa);
 
+   nir_ssa_def *img_coord_3d = NULL;
+
+   if (is_3d) {
+   nir_ssa_def *chans[3];
+
+   chans[0] = nir_channel(, img_coord, 0);
+   chans[1] = nir_channel(, img_coord, 1);
+   chans[2] = nir_channel(, img_coord, 2);
+   img_coord_3d = nir_vec(, chans, 3);
+   }
+
nir_tex_instr *tex = nir_tex_instr_create(b.shader, 2);
-   tex->sampler_dim = GLSL_SAMPLER_DIM_2D;
+   tex->sampler_dim = dim;
tex->op = nir_texop_txf;
tex->src[0].src_type = nir_tex_src_coord;
-   tex->src[0].src = nir_src_for_ssa(nir_channels(, img_coord, 0x3));
+   if (is_3d)
+   tex->src[0].src = nir_src_for_ssa(nir_channels(, 
img_coord_3d, 0x7));
+   else
+   tex->src[0].src = nir_src_for_ssa(nir_channels(, img_coord, 
0x3));
tex->src[1].src_type = nir_tex_src_lod;
tex->src[1].src = nir_src_for_ssa(nir_imm_int(, 0));
tex->dest_type = nir_type_float;
tex->is_array = false;
-   tex->coord_components = 2;
+   tex->coord_components = is_3d ? 3 : 2;
tex->texture = nir_deref_var_create(tex, input_img);
tex->sampler = NULL;
 
@@ -126,8 +144,11 @@ radv_device_init_meta_itob_state(struct radv_device 
*device)
 {
VkResult result;
struct radv_shader_module cs = { .nir = NULL };
+   struct radv_shader_module cs_3d = { .nir = NULL };
 
-   cs.nir = build_nir_itob_compute_shader(device);
+   cs.nir =