[Mesa-dev] [PATCH v2 04/11] nvc0: bind shader buffers for compute on Fermi

Samuel Pitoiset samuel.pitoiset at gmail.com
Sun Feb 7 20:49:55 UTC 2016


Loosely based on 3D.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/gallium/drivers/nouveau/nvc0/nvc0_compute.c | 34 +++++++++++++++++++++++++
 src/gallium/drivers/nouveau/nvc0/nvc0_context.c | 12 ++++++---
 src/gallium/drivers/nouveau/nvc0/nvc0_context.h |  4 ++-
 src/gallium/drivers/nouveau/nvc0/nvc0_program.c |  1 +
 src/gallium/drivers/nouveau/nvc0/nvc0_state.c   | 13 +++++++---
 5 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_compute.c b/src/gallium/drivers/nouveau/nvc0/nvc0_compute.c
index c76b707..2e8a69e 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_compute.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_compute.c
@@ -196,6 +196,38 @@ nvc0_compute_validate_constbufs(struct nvc0_context *nvc0)
    PUSH_DATA (push, NVC0_COMPUTE_FLUSH_CB);
 }
 
+static void
+nvc0_compute_validate_buffers(struct nvc0_context *nvc0)
+{
+   struct nouveau_pushbuf *push = nvc0->base.pushbuf;
+   const int s = 5;
+   int i;
+
+   BEGIN_NVC0(push, NVC0_COMPUTE(CB_SIZE), 3);
+   PUSH_DATA (push, 1024);
+   PUSH_DATAh(push, nvc0->screen->uniform_bo->offset + (6 << 16) + (s << 10));
+   PUSH_DATA (push, nvc0->screen->uniform_bo->offset + (6 << 16) + (s << 10));
+   BEGIN_1IC0(push, NVC0_COMPUTE(CB_POS), 1 + 4 * NVC0_MAX_BUFFERS);
+   PUSH_DATA (push, 512);
+
+   for (i = 0; i < NVC0_MAX_BUFFERS; i++) {
+      if (nvc0->buffers[s][i].buffer) {
+         struct nv04_resource *res =
+            nv04_resource(nvc0->buffers[s][i].buffer);
+         PUSH_DATA (push, res->address + nvc0->buffers[s][i].buffer_offset);
+         PUSH_DATAh(push, res->address + nvc0->buffers[s][i].buffer_offset);
+         PUSH_DATA (push, nvc0->buffers[s][i].buffer_size);
+         PUSH_DATA (push, 0);
+         BCTX_REFN(nvc0->bufctx_cp, CP_BUF, res, RDWR);
+      } else {
+         PUSH_DATA (push, 0);
+         PUSH_DATA (push, 0);
+         PUSH_DATA (push, 0);
+         PUSH_DATA (push, 0);
+      }
+   }
+}
+
 static bool
 nvc0_compute_state_validate(struct nvc0_context *nvc0)
 {
@@ -203,6 +235,8 @@ nvc0_compute_state_validate(struct nvc0_context *nvc0)
       return false;
    if (nvc0->dirty_cp & NVC0_NEW_CP_CONSTBUF)
       nvc0_compute_validate_constbufs(nvc0);
+   if (nvc0->dirty_cp & NVC0_NEW_CP_BUFFERS)
+      nvc0_compute_validate_buffers(nvc0);
 
    /* TODO: textures, samplers, surfaces, global memory buffers */
 
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.c b/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
index 4fed7b2..0635b98 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
@@ -261,12 +261,17 @@ nvc0_invalidate_resource_storage(struct nouveau_context *ctx,
       }
       }
 
-      for (s = 0; s < 5; ++s) {
+      for (s = 0; s < 6; ++s) {
       for (i = 0; i < NVC0_MAX_BUFFERS; ++i) {
          if (nvc0->buffers[s][i].buffer == res) {
             nvc0->buffers_dirty[s] |= 1 << i;
-            nvc0->dirty |= NVC0_NEW_BUFFERS;
-            nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_BUF);
+            if (unlikely(s == 5)) {
+               nvc0->dirty_cp |= NVC0_NEW_CP_BUFFERS;
+               nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_BUF);
+            } else {
+               nvc0->dirty |= NVC0_NEW_BUFFERS;
+               nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_BUF);
+            }
             if (!--ref)
                return ref;
          }
@@ -368,6 +373,7 @@ nvc0_create(struct pipe_screen *pscreen, void *priv, unsigned ctxflags)
    BCTX_REFN_bo(nvc0->bufctx_3d, SCREEN, flags, screen->txc);
    if (screen->compute) {
       BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->text);
+      BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->uniform_bo);
       BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->txc);
       BCTX_REFN_bo(nvc0->bufctx_cp, CP_SCREEN, flags, screen->parm);
    }
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
index 2e726e6..c6936c1 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
@@ -64,6 +64,7 @@
 #define NVC0_NEW_CP_SAMPLERS  (1 << 3)
 #define NVC0_NEW_CP_CONSTBUF  (1 << 4)
 #define NVC0_NEW_CP_GLOBALS   (1 << 5)
+#define NVC0_NEW_CP_BUFFERS   (1 << 6)
 
 /* 3d bufctx (during draw_vbo, blit_3d) */
 #define NVC0_BIND_FB            0
@@ -87,7 +88,8 @@
 #define NVC0_BIND_CP_DESC        50
 #define NVC0_BIND_CP_SCREEN      51
 #define NVC0_BIND_CP_QUERY       52
-#define NVC0_BIND_CP_COUNT       53
+#define NVC0_BIND_CP_BUF         53
+#define NVC0_BIND_CP_COUNT       54
 
 /* bufctx for other operations */
 #define NVC0_BIND_2D            0
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_program.c b/src/gallium/drivers/nouveau/nvc0/nvc0_program.c
index afcff53..bc884d6 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_program.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_program.c
@@ -546,6 +546,7 @@ nvc0_program_translate(struct nvc0_program *prog, uint16_t chipset,
          info->prop.cp.gridInfoBase = NVE4_CP_INPUT_GRID_INFO(0);
       } else {
          info->io.resInfoCBSlot = 15;
+         info->io.suInfoBase = 512;
       }
       info->io.msInfoCBSlot = 0;
       info->io.msInfoBase = NVE4_CP_INPUT_MS_OFFSETS;
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
index 1246a9c..578a42c 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
@@ -1256,7 +1256,7 @@ nvc0_bind_buffers_range(struct nvc0_context *nvc0, const unsigned t,
    const unsigned mask = ((1 << nr) - 1) << start;
    unsigned i;
 
-   assert(t < 5);
+   assert(t < 6);
 
    if (pbuffers) {
       for (i = start; i < end; ++i) {
@@ -1276,7 +1276,11 @@ nvc0_bind_buffers_range(struct nvc0_context *nvc0, const unsigned t,
    }
    nvc0->buffers_dirty[t] |= mask;
 
-   nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_BUF);
+   if (t == 5)
+      nouveau_bufctx_reset(nvc0->bufctx_cp, NVC0_BIND_CP_BUF);
+   else
+      nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_BUF);
+
 }
 
 static void
@@ -1288,7 +1292,10 @@ nvc0_set_shader_buffers(struct pipe_context *pipe,
    const unsigned s = nvc0_shader_stage(shader);
    nvc0_bind_buffers_range(nvc0_context(pipe), s, start, nr, buffers);
 
-   nvc0_context(pipe)->dirty |= NVC0_NEW_BUFFERS;
+   if (s == 5)
+      nvc0_context(pipe)->dirty_cp |= NVC0_NEW_CP_BUFFERS;
+   else
+      nvc0_context(pipe)->dirty |= NVC0_NEW_BUFFERS;
 }
 
 static inline void
-- 
2.6.4



More information about the mesa-dev mailing list