Re: [Mesa-dev] [PATCH RFC 2/8] nvc0: bind images for 3d/cp shaders on GM107+

2016-07-18 Thread Samuel Pitoiset



On 07/18/2016 11:13 PM, Ilia Mirkin wrote:

On Mon, Jul 18, 2016 at 4:55 PM, Samuel Pitoiset
 wrote:

On Maxwell, images binding is slightly different (and much better)
regarding Fermi and Kepler because a texture view needs to be uploaded
for each image and this is going to simplify the thing a lot.

Signed-off-by: Samuel Pitoiset 
---
 src/gallium/drivers/nouveau/nvc0/nvc0_context.c |   5 +-
 src/gallium/drivers/nouveau/nvc0/nvc0_context.h |   4 +
 src/gallium/drivers/nouveau/nvc0/nvc0_state.c   |  10 ++-
 src/gallium/drivers/nouveau/nvc0/nvc0_tex.c | 110 ++--
 src/gallium/drivers/nouveau/nvc0/nve4_compute.c |  91 ++--
 5 files changed, 202 insertions(+), 18 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.c 
b/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
index 1137e6c..4bd240b 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
@@ -161,8 +161,11 @@ nvc0_context_unreference_resources(struct nvc0_context 
*nvc0)
   for (i = 0; i < NVC0_MAX_BUFFERS; ++i)
  pipe_resource_reference(>buffers[s][i].buffer, NULL);

-  for (i = 0; i < NVC0_MAX_IMAGES; ++i)
+  for (i = 0; i < NVC0_MAX_IMAGES; ++i) {
  pipe_resource_reference(>images[s][i].resource, NULL);
+ if (nvc0->screen->base.class_3d >= GM107_3D_CLASS)
+pipe_sampler_view_reference(>images_tic[s][i], NULL);
+  }
}

for (s = 0; s < 2; ++s) {
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h 
b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
index 4b73ec3..1d9fca1 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
@@ -246,6 +246,7 @@ struct nvc0_context {
uint32_t buffers_valid[6];

struct pipe_image_view images[6][NVC0_MAX_IMAGES];
+   struct pipe_sampler_view *images_tic[6][NVC0_MAX_IMAGES]; /* GM107+ */
uint16_t images_dirty[6];
uint16_t images_valid[6];

@@ -349,6 +350,9 @@ struct pipe_sampler_view *
 nvc0_create_sampler_view(struct pipe_context *,
  struct pipe_resource *,
  const struct pipe_sampler_view *);
+struct pipe_sampler_view *
+gm107_create_texture_view_from_image(struct pipe_context *,
+ struct pipe_image_view *);

 /* nvc0_transfer.c */
 void
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c 
b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
index 441cfc9..98becf4 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
@@ -1303,8 +1303,16 @@ nvc0_bind_images_range(struct nvc0_context *nvc0, const 
unsigned s,
   mask = ((1 << nr) - 1) << start;
   if (!(nvc0->images_valid[s] & mask))
  return false;
-  for (i = start; i < end; ++i)
+  for (i = start; i < end; ++i) {
  pipe_resource_reference(>images[s][i].resource, NULL);
+ if (nvc0->screen->base.class_3d >= GM107_3D_CLASS) {
+struct nv50_tic_entry *old = 
nv50_tic_entry(nvc0->images_tic[s][i]);
+if (old) {
+   nvc0_screen_tic_unlock(nvc0->screen, old);
+   pipe_sampler_view_reference(>images_tic[s][i], NULL);
+}
+ }
+  }
   nvc0->images_valid[s] &= ~mask;
}
nvc0->images_dirty[s] |= mask;
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_tex.c 
b/src/gallium/drivers/nouveau/nvc0/nvc0_tex.c
index 5f7bba8..efbaacf 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_tex.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_tex.c
@@ -236,6 +236,38 @@ gm107_create_texture_view(struct pipe_context *pipe,
return >pipe;
 }

+struct pipe_sampler_view *
+gm107_create_texture_view_from_image(struct pipe_context *pipe,
+ struct pipe_image_view *view)
+{
+   struct nv04_resource *res = nv04_resource(view->resource);
+   enum pipe_texture_target target = res->base.target;
+   struct pipe_sampler_view templ = {};
+   uint32_t flags = 0;
+
+   if (target == PIPE_TEXTURE_CUBE || target == PIPE_TEXTURE_CUBE_ARRAY)
+  target = PIPE_TEXTURE_2D_ARRAY;
+
+   templ.format = view->format;
+   templ.swizzle_r = PIPE_SWIZZLE_X;
+   templ.swizzle_g = PIPE_SWIZZLE_Y;
+   templ.swizzle_b = PIPE_SWIZZLE_Z;
+   templ.swizzle_a = PIPE_SWIZZLE_W;
+
+   if (target == PIPE_BUFFER) {
+  templ.u.buf.first_element = view->u.buf.first_element;
+  templ.u.buf.last_element = view->u.buf.last_element;
+   } else {
+  templ.u.tex.first_layer = view->u.tex.first_layer;
+  templ.u.tex.last_layer = view->u.tex.last_layer;
+  templ.u.tex.first_level = templ.u.tex.last_level = view->u.tex.level;
+   }
+
+   flags = res->base.last_level ? 0 : NV50_TEXVIEW_SCALED_COORDS;


I think you just want 0 here, always.


I thought too, but this will hit the assert at nvc0_tex.c:134 for image 

Re: [Mesa-dev] [PATCH RFC 2/8] nvc0: bind images for 3d/cp shaders on GM107+

2016-07-18 Thread Ilia Mirkin
On Mon, Jul 18, 2016 at 4:55 PM, Samuel Pitoiset
 wrote:
> On Maxwell, images binding is slightly different (and much better)
> regarding Fermi and Kepler because a texture view needs to be uploaded
> for each image and this is going to simplify the thing a lot.
>
> Signed-off-by: Samuel Pitoiset 
> ---
>  src/gallium/drivers/nouveau/nvc0/nvc0_context.c |   5 +-
>  src/gallium/drivers/nouveau/nvc0/nvc0_context.h |   4 +
>  src/gallium/drivers/nouveau/nvc0/nvc0_state.c   |  10 ++-
>  src/gallium/drivers/nouveau/nvc0/nvc0_tex.c | 110 
> ++--
>  src/gallium/drivers/nouveau/nvc0/nve4_compute.c |  91 ++--
>  5 files changed, 202 insertions(+), 18 deletions(-)
>
> diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.c 
> b/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
> index 1137e6c..4bd240b 100644
> --- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
> +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
> @@ -161,8 +161,11 @@ nvc0_context_unreference_resources(struct nvc0_context 
> *nvc0)
>for (i = 0; i < NVC0_MAX_BUFFERS; ++i)
>   pipe_resource_reference(>buffers[s][i].buffer, NULL);
>
> -  for (i = 0; i < NVC0_MAX_IMAGES; ++i)
> +  for (i = 0; i < NVC0_MAX_IMAGES; ++i) {
>   pipe_resource_reference(>images[s][i].resource, NULL);
> + if (nvc0->screen->base.class_3d >= GM107_3D_CLASS)
> +pipe_sampler_view_reference(>images_tic[s][i], NULL);
> +  }
> }
>
> for (s = 0; s < 2; ++s) {
> diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h 
> b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
> index 4b73ec3..1d9fca1 100644
> --- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
> +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
> @@ -246,6 +246,7 @@ struct nvc0_context {
> uint32_t buffers_valid[6];
>
> struct pipe_image_view images[6][NVC0_MAX_IMAGES];
> +   struct pipe_sampler_view *images_tic[6][NVC0_MAX_IMAGES]; /* GM107+ */
> uint16_t images_dirty[6];
> uint16_t images_valid[6];
>
> @@ -349,6 +350,9 @@ struct pipe_sampler_view *
>  nvc0_create_sampler_view(struct pipe_context *,
>   struct pipe_resource *,
>   const struct pipe_sampler_view *);
> +struct pipe_sampler_view *
> +gm107_create_texture_view_from_image(struct pipe_context *,
> + struct pipe_image_view *);
>
>  /* nvc0_transfer.c */
>  void
> diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c 
> b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
> index 441cfc9..98becf4 100644
> --- a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
> +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
> @@ -1303,8 +1303,16 @@ nvc0_bind_images_range(struct nvc0_context *nvc0, 
> const unsigned s,
>mask = ((1 << nr) - 1) << start;
>if (!(nvc0->images_valid[s] & mask))
>   return false;
> -  for (i = start; i < end; ++i)
> +  for (i = start; i < end; ++i) {
>   pipe_resource_reference(>images[s][i].resource, NULL);
> + if (nvc0->screen->base.class_3d >= GM107_3D_CLASS) {
> +struct nv50_tic_entry *old = 
> nv50_tic_entry(nvc0->images_tic[s][i]);
> +if (old) {
> +   nvc0_screen_tic_unlock(nvc0->screen, old);
> +   pipe_sampler_view_reference(>images_tic[s][i], NULL);
> +}
> + }
> +  }
>nvc0->images_valid[s] &= ~mask;
> }
> nvc0->images_dirty[s] |= mask;
> diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_tex.c 
> b/src/gallium/drivers/nouveau/nvc0/nvc0_tex.c
> index 5f7bba8..efbaacf 100644
> --- a/src/gallium/drivers/nouveau/nvc0/nvc0_tex.c
> +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_tex.c
> @@ -236,6 +236,38 @@ gm107_create_texture_view(struct pipe_context *pipe,
> return >pipe;
>  }
>
> +struct pipe_sampler_view *
> +gm107_create_texture_view_from_image(struct pipe_context *pipe,
> + struct pipe_image_view *view)
> +{
> +   struct nv04_resource *res = nv04_resource(view->resource);
> +   enum pipe_texture_target target = res->base.target;
> +   struct pipe_sampler_view templ = {};
> +   uint32_t flags = 0;
> +
> +   if (target == PIPE_TEXTURE_CUBE || target == PIPE_TEXTURE_CUBE_ARRAY)
> +  target = PIPE_TEXTURE_2D_ARRAY;
> +
> +   templ.format = view->format;
> +   templ.swizzle_r = PIPE_SWIZZLE_X;
> +   templ.swizzle_g = PIPE_SWIZZLE_Y;
> +   templ.swizzle_b = PIPE_SWIZZLE_Z;
> +   templ.swizzle_a = PIPE_SWIZZLE_W;
> +
> +   if (target == PIPE_BUFFER) {
> +  templ.u.buf.first_element = view->u.buf.first_element;
> +  templ.u.buf.last_element = view->u.buf.last_element;
> +   } else {
> +  templ.u.tex.first_layer = view->u.tex.first_layer;
> +  templ.u.tex.last_layer = view->u.tex.last_layer;
> +  templ.u.tex.first_level = templ.u.tex.last_level = view->u.tex.level;
> +   }
> +
> +   

[Mesa-dev] [PATCH RFC 2/8] nvc0: bind images for 3d/cp shaders on GM107+

2016-07-18 Thread Samuel Pitoiset
On Maxwell, images binding is slightly different (and much better)
regarding Fermi and Kepler because a texture view needs to be uploaded
for each image and this is going to simplify the thing a lot.

Signed-off-by: Samuel Pitoiset 
---
 src/gallium/drivers/nouveau/nvc0/nvc0_context.c |   5 +-
 src/gallium/drivers/nouveau/nvc0/nvc0_context.h |   4 +
 src/gallium/drivers/nouveau/nvc0/nvc0_state.c   |  10 ++-
 src/gallium/drivers/nouveau/nvc0/nvc0_tex.c | 110 ++--
 src/gallium/drivers/nouveau/nvc0/nve4_compute.c |  91 ++--
 5 files changed, 202 insertions(+), 18 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.c 
b/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
index 1137e6c..4bd240b 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
@@ -161,8 +161,11 @@ nvc0_context_unreference_resources(struct nvc0_context 
*nvc0)
   for (i = 0; i < NVC0_MAX_BUFFERS; ++i)
  pipe_resource_reference(>buffers[s][i].buffer, NULL);
 
-  for (i = 0; i < NVC0_MAX_IMAGES; ++i)
+  for (i = 0; i < NVC0_MAX_IMAGES; ++i) {
  pipe_resource_reference(>images[s][i].resource, NULL);
+ if (nvc0->screen->base.class_3d >= GM107_3D_CLASS)
+pipe_sampler_view_reference(>images_tic[s][i], NULL);
+  }
}
 
for (s = 0; s < 2; ++s) {
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h 
b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
index 4b73ec3..1d9fca1 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
@@ -246,6 +246,7 @@ struct nvc0_context {
uint32_t buffers_valid[6];
 
struct pipe_image_view images[6][NVC0_MAX_IMAGES];
+   struct pipe_sampler_view *images_tic[6][NVC0_MAX_IMAGES]; /* GM107+ */
uint16_t images_dirty[6];
uint16_t images_valid[6];
 
@@ -349,6 +350,9 @@ struct pipe_sampler_view *
 nvc0_create_sampler_view(struct pipe_context *,
  struct pipe_resource *,
  const struct pipe_sampler_view *);
+struct pipe_sampler_view *
+gm107_create_texture_view_from_image(struct pipe_context *,
+ struct pipe_image_view *);
 
 /* nvc0_transfer.c */
 void
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c 
b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
index 441cfc9..98becf4 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
@@ -1303,8 +1303,16 @@ nvc0_bind_images_range(struct nvc0_context *nvc0, const 
unsigned s,
   mask = ((1 << nr) - 1) << start;
   if (!(nvc0->images_valid[s] & mask))
  return false;
-  for (i = start; i < end; ++i)
+  for (i = start; i < end; ++i) {
  pipe_resource_reference(>images[s][i].resource, NULL);
+ if (nvc0->screen->base.class_3d >= GM107_3D_CLASS) {
+struct nv50_tic_entry *old = 
nv50_tic_entry(nvc0->images_tic[s][i]);
+if (old) {
+   nvc0_screen_tic_unlock(nvc0->screen, old);
+   pipe_sampler_view_reference(>images_tic[s][i], NULL);
+}
+ }
+  }
   nvc0->images_valid[s] &= ~mask;
}
nvc0->images_dirty[s] |= mask;
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_tex.c 
b/src/gallium/drivers/nouveau/nvc0/nvc0_tex.c
index 5f7bba8..efbaacf 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_tex.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_tex.c
@@ -236,6 +236,38 @@ gm107_create_texture_view(struct pipe_context *pipe,
return >pipe;
 }
 
+struct pipe_sampler_view *
+gm107_create_texture_view_from_image(struct pipe_context *pipe,
+ struct pipe_image_view *view)
+{
+   struct nv04_resource *res = nv04_resource(view->resource);
+   enum pipe_texture_target target = res->base.target;
+   struct pipe_sampler_view templ = {};
+   uint32_t flags = 0;
+
+   if (target == PIPE_TEXTURE_CUBE || target == PIPE_TEXTURE_CUBE_ARRAY)
+  target = PIPE_TEXTURE_2D_ARRAY;
+
+   templ.format = view->format;
+   templ.swizzle_r = PIPE_SWIZZLE_X;
+   templ.swizzle_g = PIPE_SWIZZLE_Y;
+   templ.swizzle_b = PIPE_SWIZZLE_Z;
+   templ.swizzle_a = PIPE_SWIZZLE_W;
+
+   if (target == PIPE_BUFFER) {
+  templ.u.buf.first_element = view->u.buf.first_element;
+  templ.u.buf.last_element = view->u.buf.last_element;
+   } else {
+  templ.u.tex.first_layer = view->u.tex.first_layer;
+  templ.u.tex.last_layer = view->u.tex.last_layer;
+  templ.u.tex.first_level = templ.u.tex.last_level = view->u.tex.level;
+   }
+
+   flags = res->base.last_level ? 0 : NV50_TEXVIEW_SCALED_COORDS;
+
+   return gm107_create_texture_view(pipe, >base, , flags, target);
+}
+
 static struct pipe_sampler_view *
 gf100_create_texture_view(struct pipe_context *pipe,
   struct pipe_resource *texture,
@@ -1099,6 +1131,66 @@