Re: [Mesa-dev] [PATCH 1/3] virgl: add initial images support (v2)

2018-07-31 Thread Gert Wollny
Looks good, Patches 1-3 
  Reviwed-by: Gert Wollny  

Am Dienstag, den 31.07.2018, 04:47 +1000 schrieb Dave Airlie:
> From: Dave Airlie 
> 
> v2: add max image samples support
> ---
>  src/gallium/drivers/virgl/virgl_context.c  | 44
> ++
>  src/gallium/drivers/virgl/virgl_context.h  |  1 +
>  src/gallium/drivers/virgl/virgl_encode.c   | 29 
>  src/gallium/drivers/virgl/virgl_encode.h   |  4 +++
>  src/gallium/drivers/virgl/virgl_hw.h   |  3 ++
>  src/gallium/drivers/virgl/virgl_protocol.h | 12 
>  src/gallium/drivers/virgl/virgl_screen.c   | 11 
>  src/gallium/drivers/virgl/virgl_winsys.h   |  1 +
>  8 files changed, 105 insertions(+)
> 
> diff --git a/src/gallium/drivers/virgl/virgl_context.c
> b/src/gallium/drivers/virgl/virgl_context.c
> index 74b232fe6cf..41ba853805b 100644
> --- a/src/gallium/drivers/virgl/virgl_context.c
> +++ b/src/gallium/drivers/virgl/virgl_context.c
> @@ -182,6 +182,20 @@ static void
> virgl_attach_res_shader_buffers(struct virgl_context *vctx,
> }
>  }
>  
> +static void virgl_attach_res_shader_images(struct virgl_context
> *vctx,
> +   enum pipe_shader_type
> shader_type)
> +{
> +   struct virgl_winsys *vws = virgl_screen(vctx->base.screen)->vws;
> +   struct virgl_resource *res;
> +   unsigned i;
> +   for (i = 0; i < PIPE_MAX_SHADER_IMAGES; i++) {
> +  res = virgl_resource(vctx->images[shader_type][i]);
> +  if (res) {
> + vws->emit_res(vws, vctx->cbuf, res->hw_res, FALSE);
> +  }
> +   }
> +}
> +
>  /*
>   * after flushing, the hw context still has a bunch of
>   * resources bound, so we need to rebind those here.
> @@ -198,6 +212,7 @@ static void virgl_reemit_res(struct virgl_context
> *vctx)
>virgl_attach_res_sampler_views(vctx, shader_type);
>virgl_attach_res_uniform_buffers(vctx, shader_type);
>virgl_attach_res_shader_buffers(vctx, shader_type);
> +  virgl_attach_res_shader_images(vctx, shader_type);
> }
> virgl_attach_res_vertex_buffers(vctx);
> virgl_attach_res_so_targets(vctx);
> @@ -954,6 +969,34 @@ static void virgl_set_shader_buffers(struct
> pipe_context *ctx,
> virgl_encode_set_shader_buffers(vctx, shader, start_slot, count,
> buffers);
>  }
>  
> +static void virgl_set_shader_images(struct pipe_context *ctx,
> +enum pipe_shader_type shader,
> +unsigned start_slot, unsigned
> count,
> +const struct pipe_image_view
> *images)
> +{
> +   struct virgl_context *vctx = virgl_context(ctx);
> +   struct virgl_screen *rs = virgl_screen(ctx->screen);
> +
> +   for (unsigned i = 0; i < count; i++) {
> +  unsigned idx = start_slot + i;
> +
> +  if (images) {
> + if (images[i].resource) {
> +pipe_resource_reference(>images[shader][idx],
> images[i].resource);
> +continue;
> + }
> +  }
> +  pipe_resource_reference(>images[shader][idx], NULL);
> +   }
> +
> +   uint32_t max_shader_images = shader == PIPE_SHADER_FRAGMENT ?
> + rs->caps.caps.v2.max_shader_image_frag_compute :
> + rs->caps.caps.v2.max_shader_image_other_stages;
> +   if (!max_shader_images)
> +  return;
> +   virgl_encode_set_shader_images(vctx, shader, start_slot, count,
> images);
> +}
> +
>  static void
>  virgl_context_destroy( struct pipe_context *ctx )
>  {
> @@ -1092,6 +1135,7 @@ struct pipe_context
> *virgl_context_create(struct pipe_screen *pscreen,
> vctx->base.blit =  virgl_blit;
>  
> vctx->base.set_shader_buffers = virgl_set_shader_buffers;
> +   vctx->base.set_shader_images = virgl_set_shader_images;
> virgl_init_context_resource_functions(>base);
> virgl_init_query_functions(vctx);
> virgl_init_so_functions(vctx);
> diff --git a/src/gallium/drivers/virgl/virgl_context.h
> b/src/gallium/drivers/virgl/virgl_context.h
> index 5747654ea82..38d1f450e17 100644
> --- a/src/gallium/drivers/virgl/virgl_context.h
> +++ b/src/gallium/drivers/virgl/virgl_context.h
> @@ -70,6 +70,7 @@ struct virgl_context {
> struct pipe_resource
> *ubos[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
>  
> struct pipe_resource
> *ssbos[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
> +   struct pipe_resource
> *images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
> int num_transfers;
> int num_draws;
> struct list_head to_flush_bufs;
> diff --git a/src/gallium/drivers/virgl/virgl_encode.c
> b/src/gallium/drivers/virgl/virgl_encode.c
> index b09366dcee6..88eebcbaa63 100644
> --- a/src/gallium/drivers/virgl/virgl_encode.c
> +++ b/src/gallium/drivers/virgl/virgl_encode.c
> @@ -943,3 +943,32 @@ int virgl_encode_set_shader_buffers(struct
> virgl_context *ctx,
> }
> return 0;
>  }
> +
> +int virgl_encode_set_shader_images(struct virgl_context *ctx,
> +   enum pipe_shader_type shader,
> +  

[Mesa-dev] [PATCH 1/3] virgl: add initial images support (v2)

2018-07-30 Thread Dave Airlie
From: Dave Airlie 

v2: add max image samples support
---
 src/gallium/drivers/virgl/virgl_context.c  | 44 ++
 src/gallium/drivers/virgl/virgl_context.h  |  1 +
 src/gallium/drivers/virgl/virgl_encode.c   | 29 
 src/gallium/drivers/virgl/virgl_encode.h   |  4 +++
 src/gallium/drivers/virgl/virgl_hw.h   |  3 ++
 src/gallium/drivers/virgl/virgl_protocol.h | 12 
 src/gallium/drivers/virgl/virgl_screen.c   | 11 
 src/gallium/drivers/virgl/virgl_winsys.h   |  1 +
 8 files changed, 105 insertions(+)

diff --git a/src/gallium/drivers/virgl/virgl_context.c 
b/src/gallium/drivers/virgl/virgl_context.c
index 74b232fe6cf..41ba853805b 100644
--- a/src/gallium/drivers/virgl/virgl_context.c
+++ b/src/gallium/drivers/virgl/virgl_context.c
@@ -182,6 +182,20 @@ static void virgl_attach_res_shader_buffers(struct 
virgl_context *vctx,
}
 }
 
+static void virgl_attach_res_shader_images(struct virgl_context *vctx,
+   enum pipe_shader_type shader_type)
+{
+   struct virgl_winsys *vws = virgl_screen(vctx->base.screen)->vws;
+   struct virgl_resource *res;
+   unsigned i;
+   for (i = 0; i < PIPE_MAX_SHADER_IMAGES; i++) {
+  res = virgl_resource(vctx->images[shader_type][i]);
+  if (res) {
+ vws->emit_res(vws, vctx->cbuf, res->hw_res, FALSE);
+  }
+   }
+}
+
 /*
  * after flushing, the hw context still has a bunch of
  * resources bound, so we need to rebind those here.
@@ -198,6 +212,7 @@ static void virgl_reemit_res(struct virgl_context *vctx)
   virgl_attach_res_sampler_views(vctx, shader_type);
   virgl_attach_res_uniform_buffers(vctx, shader_type);
   virgl_attach_res_shader_buffers(vctx, shader_type);
+  virgl_attach_res_shader_images(vctx, shader_type);
}
virgl_attach_res_vertex_buffers(vctx);
virgl_attach_res_so_targets(vctx);
@@ -954,6 +969,34 @@ static void virgl_set_shader_buffers(struct pipe_context 
*ctx,
virgl_encode_set_shader_buffers(vctx, shader, start_slot, count, buffers);
 }
 
+static void virgl_set_shader_images(struct pipe_context *ctx,
+enum pipe_shader_type shader,
+unsigned start_slot, unsigned count,
+const struct pipe_image_view *images)
+{
+   struct virgl_context *vctx = virgl_context(ctx);
+   struct virgl_screen *rs = virgl_screen(ctx->screen);
+
+   for (unsigned i = 0; i < count; i++) {
+  unsigned idx = start_slot + i;
+
+  if (images) {
+ if (images[i].resource) {
+pipe_resource_reference(>images[shader][idx], 
images[i].resource);
+continue;
+ }
+  }
+  pipe_resource_reference(>images[shader][idx], NULL);
+   }
+
+   uint32_t max_shader_images = shader == PIPE_SHADER_FRAGMENT ?
+ rs->caps.caps.v2.max_shader_image_frag_compute :
+ rs->caps.caps.v2.max_shader_image_other_stages;
+   if (!max_shader_images)
+  return;
+   virgl_encode_set_shader_images(vctx, shader, start_slot, count, images);
+}
+
 static void
 virgl_context_destroy( struct pipe_context *ctx )
 {
@@ -1092,6 +1135,7 @@ struct pipe_context *virgl_context_create(struct 
pipe_screen *pscreen,
vctx->base.blit =  virgl_blit;
 
vctx->base.set_shader_buffers = virgl_set_shader_buffers;
+   vctx->base.set_shader_images = virgl_set_shader_images;
virgl_init_context_resource_functions(>base);
virgl_init_query_functions(vctx);
virgl_init_so_functions(vctx);
diff --git a/src/gallium/drivers/virgl/virgl_context.h 
b/src/gallium/drivers/virgl/virgl_context.h
index 5747654ea82..38d1f450e17 100644
--- a/src/gallium/drivers/virgl/virgl_context.h
+++ b/src/gallium/drivers/virgl/virgl_context.h
@@ -70,6 +70,7 @@ struct virgl_context {
struct pipe_resource *ubos[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
 
struct pipe_resource *ssbos[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
+   struct pipe_resource *images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
int num_transfers;
int num_draws;
struct list_head to_flush_bufs;
diff --git a/src/gallium/drivers/virgl/virgl_encode.c 
b/src/gallium/drivers/virgl/virgl_encode.c
index b09366dcee6..88eebcbaa63 100644
--- a/src/gallium/drivers/virgl/virgl_encode.c
+++ b/src/gallium/drivers/virgl/virgl_encode.c
@@ -943,3 +943,32 @@ int virgl_encode_set_shader_buffers(struct virgl_context 
*ctx,
}
return 0;
 }
+
+int virgl_encode_set_shader_images(struct virgl_context *ctx,
+   enum pipe_shader_type shader,
+   unsigned start_slot, unsigned count,
+   const struct pipe_image_view *images)
+{
+   int i;
+   virgl_encoder_write_cmd_dword(ctx, VIRGL_CMD0(VIRGL_CCMD_SET_SHADER_IMAGES, 
0, VIRGL_SET_SHADER_IMAGE_SIZE(count)));
+
+   virgl_encoder_write_dword(ctx->cbuf, shader);
+   virgl_encoder_write_dword(ctx->cbuf, start_slot);
+   for (i