Re: [Mesa-dev] [PATCH v2 60/64] radeonsi: upload new descriptors when resident buffers are invalidated

2017-06-07 Thread Marek Olšák
On Wed, Jun 7, 2017 at 4:47 PM, Samuel Pitoiset
 wrote:
>
>
> On 06/07/2017 03:59 PM, Marek Olšák wrote:
>>
>> On Tue, May 30, 2017 at 10:36 PM, Samuel Pitoiset
>>  wrote:
>>>
>>> When texture buffers are invalidated the addr in the resident
>>> descriptor has to be updated but we can't create a new descriptor
>>> because the resident handle has to be the same.
>>>
>>> Instead, use the WRITE_DATA packet which allows to update memory
>>> directly but graphics/compute have to be idle in case the GPU is
>>> reading the descriptor.
>>>
>>> v2: - store pipe_sampler_view instead of si_sampler_view
>>>
>>> Signed-off-by: Samuel Pitoiset 
>>> ---
>>>   src/gallium/drivers/radeon/r600_pipe_common.h |   4 +
>>>   src/gallium/drivers/radeonsi/si_descriptors.c | 145
>>> ++
>>>   src/gallium/drivers/radeonsi/si_pipe.h|   3 +
>>>   3 files changed, 152 insertions(+)
>>>
>>> diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h
>>> b/src/gallium/drivers/radeon/r600_pipe_common.h
>>> index b17b690fab..6c4df2e733 100644
>>> --- a/src/gallium/drivers/radeon/r600_pipe_common.h
>>> +++ b/src/gallium/drivers/radeon/r600_pipe_common.h
>>> @@ -181,6 +181,10 @@ struct r600_resource {
>>>
>>>  /* Whether the resource has been exported via
>>> resource_get_handle. */
>>>  unsignedexternal_usage; /*
>>> PIPE_HANDLE_USAGE_* */
>>> +
>>> +   /* Whether this resource is referenced by bindless handles. */
>>> +   booltexture_handle_allocated;
>>> +   boolimage_handle_allocated;
>>>   };
>>>
>>>   struct r600_transfer {
>>> diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c
>>> b/src/gallium/drivers/radeonsi/si_descriptors.c
>>> index 357039a78a..1b58afba2a 100644
>>> --- a/src/gallium/drivers/radeonsi/si_descriptors.c
>>> +++ b/src/gallium/drivers/radeonsi/si_descriptors.c
>>> @@ -1857,6 +1857,67 @@ static void si_rebind_buffer(struct pipe_context
>>> *ctx, struct pipe_resource *buf
>>>  }
>>>  }
>>>  }
>>> +
>>> +   /* Bindless texture handles */
>>> +   if (rbuffer->texture_handle_allocated) {
>>> +   unsigned num_resident_tex_handles;
>>> +
>>> +   num_resident_tex_handles =
>>> sctx->resident_tex_handles.size /
>>> +  sizeof(struct
>>> si_texture_handle *);
>>> +
>>> +   for (i = 0; i < num_resident_tex_handles; i++) {
>>> +   struct si_texture_handle *tex_handle =
>>> +
>>> *util_dynarray_element(>resident_tex_handles,
>>> +  struct
>>> si_texture_handle *, i);
>>> +   struct pipe_sampler_view *view =
>>> tex_handle->view;
>>> +   struct si_bindless_descriptor *desc =
>>> tex_handle->desc;
>>> +
>>> +   if (view->texture == buf) {
>>> +   si_set_buf_desc_address(rbuffer,
>>> +
>>> view->u.buf.offset,
>>> +
>>> >desc_list[4]);
>>> +   desc->dirty = true;
>>> +   sctx->bindless_descriptors_dirty = true;
>>> +
>>> +   radeon_add_to_buffer_list_check_mem(
>>> +   >b, >b.gfx, rbuffer,
>>> +   RADEON_USAGE_READ,
>>> +   RADEON_PRIO_SAMPLER_BUFFER,
>>> true);
>>> +   }
>>> +   }
>>> +   }
>>> +
>>> +   /* Bindless image handles */
>>> +   if (rbuffer->image_handle_allocated) {
>>> +   unsigned num_resident_img_handles;
>>> +
>>> +   num_resident_img_handles =
>>> sctx->resident_img_handles.size /
>>> +  sizeof(struct si_image_handle
>>> *);
>>> +
>>> +   for (i = 0; i < num_resident_img_handles; i++) {
>>> +   struct si_image_handle *img_handle =
>>> +
>>> *util_dynarray_element(>resident_img_handles,
>>> +  struct
>>> si_image_handle *, i);
>>> +   struct pipe_image_view *view = _handle->view;
>>> +   struct si_bindless_descriptor *desc =
>>> img_handle->desc;
>>> +
>>> +   if (view->resource == buf) {
>>> +   if (view->access &
>>> PIPE_IMAGE_ACCESS_WRITE)
>>> +   si_mark_image_range_valid(view);
>>> +
>>> +   si_set_buf_desc_address(rbuffer,
>>> +
>>> view->u.buf.offset,
>>> +
>>> >desc_list[4]);
>>> +   desc->dirty = true;
>>> +   sctx->bindless_descriptors_dirty = true;
>>> +
>>> +   

Re: [Mesa-dev] [PATCH v2 60/64] radeonsi: upload new descriptors when resident buffers are invalidated

2017-06-07 Thread Samuel Pitoiset



On 06/07/2017 03:59 PM, Marek Olšák wrote:

On Tue, May 30, 2017 at 10:36 PM, Samuel Pitoiset
 wrote:

When texture buffers are invalidated the addr in the resident
descriptor has to be updated but we can't create a new descriptor
because the resident handle has to be the same.

Instead, use the WRITE_DATA packet which allows to update memory
directly but graphics/compute have to be idle in case the GPU is
reading the descriptor.

v2: - store pipe_sampler_view instead of si_sampler_view

Signed-off-by: Samuel Pitoiset 
---
  src/gallium/drivers/radeon/r600_pipe_common.h |   4 +
  src/gallium/drivers/radeonsi/si_descriptors.c | 145 ++
  src/gallium/drivers/radeonsi/si_pipe.h|   3 +
  3 files changed, 152 insertions(+)

diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h 
b/src/gallium/drivers/radeon/r600_pipe_common.h
index b17b690fab..6c4df2e733 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.h
+++ b/src/gallium/drivers/radeon/r600_pipe_common.h
@@ -181,6 +181,10 @@ struct r600_resource {

 /* Whether the resource has been exported via resource_get_handle. */
 unsignedexternal_usage; /* PIPE_HANDLE_USAGE_* 
*/
+
+   /* Whether this resource is referenced by bindless handles. */
+   booltexture_handle_allocated;
+   boolimage_handle_allocated;
  };

  struct r600_transfer {
diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c 
b/src/gallium/drivers/radeonsi/si_descriptors.c
index 357039a78a..1b58afba2a 100644
--- a/src/gallium/drivers/radeonsi/si_descriptors.c
+++ b/src/gallium/drivers/radeonsi/si_descriptors.c
@@ -1857,6 +1857,67 @@ static void si_rebind_buffer(struct pipe_context *ctx, 
struct pipe_resource *buf
 }
 }
 }
+
+   /* Bindless texture handles */
+   if (rbuffer->texture_handle_allocated) {
+   unsigned num_resident_tex_handles;
+
+   num_resident_tex_handles = sctx->resident_tex_handles.size /
+  sizeof(struct si_texture_handle *);
+
+   for (i = 0; i < num_resident_tex_handles; i++) {
+   struct si_texture_handle *tex_handle =
+   
*util_dynarray_element(>resident_tex_handles,
+  struct si_texture_handle 
*, i);
+   struct pipe_sampler_view *view = tex_handle->view;
+   struct si_bindless_descriptor *desc = tex_handle->desc;
+
+   if (view->texture == buf) {
+   si_set_buf_desc_address(rbuffer,
+   view->u.buf.offset,
+   >desc_list[4]);
+   desc->dirty = true;
+   sctx->bindless_descriptors_dirty = true;
+
+   radeon_add_to_buffer_list_check_mem(
+   >b, >b.gfx, rbuffer,
+   RADEON_USAGE_READ,
+   RADEON_PRIO_SAMPLER_BUFFER, true);
+   }
+   }
+   }
+
+   /* Bindless image handles */
+   if (rbuffer->image_handle_allocated) {
+   unsigned num_resident_img_handles;
+
+   num_resident_img_handles = sctx->resident_img_handles.size /
+  sizeof(struct si_image_handle *);
+
+   for (i = 0; i < num_resident_img_handles; i++) {
+   struct si_image_handle *img_handle =
+   
*util_dynarray_element(>resident_img_handles,
+  struct si_image_handle 
*, i);
+   struct pipe_image_view *view = _handle->view;
+   struct si_bindless_descriptor *desc = img_handle->desc;
+
+   if (view->resource == buf) {
+   if (view->access & PIPE_IMAGE_ACCESS_WRITE)
+   si_mark_image_range_valid(view);
+
+   si_set_buf_desc_address(rbuffer,
+   view->u.buf.offset,
+   >desc_list[4]);
+   desc->dirty = true;
+   sctx->bindless_descriptors_dirty = true;
+
+   radeon_add_to_buffer_list_check_mem(
+   >b, >b.gfx, rbuffer,
+   RADEON_USAGE_READWRITE,
+   RADEON_PRIO_SAMPLER_BUFFER, true);
+   }
+   }
+   }
  }

  /* 

Re: [Mesa-dev] [PATCH v2 60/64] radeonsi: upload new descriptors when resident buffers are invalidated

2017-06-07 Thread Marek Olšák
On Tue, May 30, 2017 at 10:36 PM, Samuel Pitoiset
 wrote:
> When texture buffers are invalidated the addr in the resident
> descriptor has to be updated but we can't create a new descriptor
> because the resident handle has to be the same.
>
> Instead, use the WRITE_DATA packet which allows to update memory
> directly but graphics/compute have to be idle in case the GPU is
> reading the descriptor.
>
> v2: - store pipe_sampler_view instead of si_sampler_view
>
> Signed-off-by: Samuel Pitoiset 
> ---
>  src/gallium/drivers/radeon/r600_pipe_common.h |   4 +
>  src/gallium/drivers/radeonsi/si_descriptors.c | 145 
> ++
>  src/gallium/drivers/radeonsi/si_pipe.h|   3 +
>  3 files changed, 152 insertions(+)
>
> diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h 
> b/src/gallium/drivers/radeon/r600_pipe_common.h
> index b17b690fab..6c4df2e733 100644
> --- a/src/gallium/drivers/radeon/r600_pipe_common.h
> +++ b/src/gallium/drivers/radeon/r600_pipe_common.h
> @@ -181,6 +181,10 @@ struct r600_resource {
>
> /* Whether the resource has been exported via resource_get_handle. */
> unsignedexternal_usage; /* 
> PIPE_HANDLE_USAGE_* */
> +
> +   /* Whether this resource is referenced by bindless handles. */
> +   booltexture_handle_allocated;
> +   boolimage_handle_allocated;
>  };
>
>  struct r600_transfer {
> diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c 
> b/src/gallium/drivers/radeonsi/si_descriptors.c
> index 357039a78a..1b58afba2a 100644
> --- a/src/gallium/drivers/radeonsi/si_descriptors.c
> +++ b/src/gallium/drivers/radeonsi/si_descriptors.c
> @@ -1857,6 +1857,67 @@ static void si_rebind_buffer(struct pipe_context *ctx, 
> struct pipe_resource *buf
> }
> }
> }
> +
> +   /* Bindless texture handles */
> +   if (rbuffer->texture_handle_allocated) {
> +   unsigned num_resident_tex_handles;
> +
> +   num_resident_tex_handles = sctx->resident_tex_handles.size /
> +  sizeof(struct si_texture_handle *);
> +
> +   for (i = 0; i < num_resident_tex_handles; i++) {
> +   struct si_texture_handle *tex_handle =
> +   
> *util_dynarray_element(>resident_tex_handles,
> +  struct 
> si_texture_handle *, i);
> +   struct pipe_sampler_view *view = tex_handle->view;
> +   struct si_bindless_descriptor *desc = 
> tex_handle->desc;
> +
> +   if (view->texture == buf) {
> +   si_set_buf_desc_address(rbuffer,
> +   view->u.buf.offset,
> +   >desc_list[4]);
> +   desc->dirty = true;
> +   sctx->bindless_descriptors_dirty = true;
> +
> +   radeon_add_to_buffer_list_check_mem(
> +   >b, >b.gfx, rbuffer,
> +   RADEON_USAGE_READ,
> +   RADEON_PRIO_SAMPLER_BUFFER, true);
> +   }
> +   }
> +   }
> +
> +   /* Bindless image handles */
> +   if (rbuffer->image_handle_allocated) {
> +   unsigned num_resident_img_handles;
> +
> +   num_resident_img_handles = sctx->resident_img_handles.size /
> +  sizeof(struct si_image_handle *);
> +
> +   for (i = 0; i < num_resident_img_handles; i++) {
> +   struct si_image_handle *img_handle =
> +   
> *util_dynarray_element(>resident_img_handles,
> +  struct si_image_handle 
> *, i);
> +   struct pipe_image_view *view = _handle->view;
> +   struct si_bindless_descriptor *desc = 
> img_handle->desc;
> +
> +   if (view->resource == buf) {
> +   if (view->access & PIPE_IMAGE_ACCESS_WRITE)
> +   si_mark_image_range_valid(view);
> +
> +   si_set_buf_desc_address(rbuffer,
> +   view->u.buf.offset,
> +   >desc_list[4]);
> +   desc->dirty = true;
> +   sctx->bindless_descriptors_dirty = true;
> +
> +   radeon_add_to_buffer_list_check_mem(
> +   >b, >b.gfx, rbuffer,
> +