[Mesa-dev] [PATCH 04/11] nvc0: bind constant buffers for compute on Kepler
Samuel Pitoiset
samuel.pitoiset at gmail.com
Sat Feb 27 14:02:00 UTC 2016
Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
src/gallium/drivers/nouveau/nvc0/nve4_compute.c | 70 +++++++++++++++++++++++--
src/gallium/drivers/nouveau/nvc0/nve4_compute.h | 2 +-
2 files changed, 66 insertions(+), 6 deletions(-)
diff --git a/src/gallium/drivers/nouveau/nvc0/nve4_compute.c b/src/gallium/drivers/nouveau/nvc0/nve4_compute.c
index 47e3cfe..557dbdc 100644
--- a/src/gallium/drivers/nouveau/nvc0/nve4_compute.c
+++ b/src/gallium/drivers/nouveau/nvc0/nve4_compute.c
@@ -309,6 +309,52 @@ nve4_compute_set_tex_handles(struct nvc0_context *nvc0)
}
static void
+nve4_compute_validate_constbufs(struct nvc0_context *nvc0)
+{
+ struct nouveau_pushbuf *push = nvc0->base.pushbuf;
+ const int s = 5;
+
+ while (nvc0->constbuf_dirty[s]) {
+ int i = ffs(nvc0->constbuf_dirty[s]) - 1;
+ nvc0->constbuf_dirty[s] &= ~(1 << i);
+
+ if (nvc0->constbuf[s][i].user) {
+ struct nouveau_bo *bo = nvc0->screen->uniform_bo;
+ const unsigned base = NVC0_CB_USR_INFO(s);
+ const unsigned size = nvc0->constbuf[s][0].size;
+ assert(i == 0); /* we really only want OpenGL uniforms here */
+ assert(nvc0->constbuf[s][0].u.data);
+
+ BEGIN_NVC0(push, NVE4_CP(UPLOAD_DST_ADDRESS_HIGH), 2);
+ PUSH_DATAh(push, bo->offset + base);
+ PUSH_DATA (push, bo->offset + base);
+ BEGIN_NVC0(push, NVE4_CP(UPLOAD_LINE_LENGTH_IN), 2);
+ PUSH_DATA (push, size);
+ PUSH_DATA (push, 0x1);
+ BEGIN_1IC0(push, NVE4_CP(UPLOAD_EXEC), 1 + (size / 4));
+ PUSH_DATA (push, NVE4_COMPUTE_UPLOAD_EXEC_LINEAR | (0x20 << 1));
+ PUSH_DATAp(push, nvc0->constbuf[s][0].u.data, size / 4);
+ }
+ else {
+ struct nv04_resource *res =
+ nv04_resource(nvc0->constbuf[s][i].u.buf);
+ if (res) {
+ /* UBOs don't need to be bound but they have to be set up in the
+ * launch descriptor. */
+ BCTX_REFN(nvc0->bufctx_cp, CP_CB(i), res, RD);
+
+ res->cb_bindings[s] |= 1 << i;
+ }
+ if (i == 0)
+ nvc0->state.uniform_buffer_bound[s] = 0;
+ }
+ }
+
+ BEGIN_NVC0(push, NVE4_CP(FLUSH), 1);
+ PUSH_DATA (push, NVE4_COMPUTE_FLUSH_CB);
+}
+
+static void
nve4_compute_validate_buffers(struct nvc0_context *nvc0)
{
struct nouveau_pushbuf *push = nvc0->base.pushbuf;
@@ -359,6 +405,8 @@ nve4_compute_state_validate(struct nvc0_context *nvc0)
nve4_compute_validate_surfaces(nvc0);
if (nvc0->dirty_cp & NVC0_NEW_CP_GLOBALS)
nvc0_compute_validate_globals(nvc0);
+ if (nvc0->dirty_cp & NVC0_NEW_CP_CONSTBUF)
+ nve4_compute_validate_constbufs(nvc0);
if (nvc0->dirty_cp & NVC0_NEW_CP_BUFFERS)
nve4_compute_validate_buffers(nvc0);
@@ -375,7 +423,9 @@ nve4_compute_state_validate(struct nvc0_context *nvc0)
static void
-nve4_compute_upload_input(struct nvc0_context *nvc0, const void *input,
+nve4_compute_upload_input(struct nvc0_context *nvc0,
+ struct nve4_cp_launch_desc *desc,
+ const void *input,
const uint *block_layout,
const uint *grid_layout)
{
@@ -396,6 +446,11 @@ nve4_compute_upload_input(struct nvc0_context *nvc0, const void *input,
BEGIN_1IC0(push, NVE4_CP(UPLOAD_EXEC), 1 + (cp->parm_size / 4));
PUSH_DATA (push, NVE4_COMPUTE_UPLOAD_EXEC_LINEAR | (0x20 << 1));
PUSH_DATAp(push, input, cp->parm_size / 4);
+
+ /* Bind user parameters coming from clover. */
+ /* TODO: This should be harmonized with uniform_bo. */
+ assert(!(desc->cb_mask & (1 << 0)));
+ nve4_cp_launch_desc_set_cb(desc, 0, screen->parm, 0, 1 << 12);
}
BEGIN_NVC0(push, NVE4_CP(UPLOAD_DST_ADDRESS_HIGH), 2);
PUSH_DATAh(push, address + NVC0_CB_AUX_GRID_INFO);
@@ -456,10 +511,14 @@ nve4_compute_setup_launch_desc(struct nvc0_context *nvc0,
for (i = 0; i < 7; ++i) {
const unsigned s = 5;
+ if (nvc0->constbuf[s][i].user) {
+ assert(i == 0);
+ nve4_cp_launch_desc_set_cb(desc, 0, screen->uniform_bo,
+ NVC0_CB_USR_INFO(s), 1 << 16);
+ } else
if (nvc0->constbuf[s][i].u.buf)
- nve4_cp_launch_desc_set_ctx_cb(desc, i + 1, &nvc0->constbuf[s][i]);
+ nve4_cp_launch_desc_set_ctx_cb(desc, i, &nvc0->constbuf[s][i]);
}
- nve4_cp_launch_desc_set_cb(desc, 0, screen->parm, 0, NVE4_CP_INPUT_SIZE);
nve4_cp_launch_desc_set_cb(desc, 7, screen->uniform_bo,
NVC0_CB_AUX_INFO(5), 1 << 10);
}
@@ -503,13 +562,14 @@ nve4_launch_grid(struct pipe_context *pipe, const struct pipe_grid_info *info)
nve4_compute_setup_launch_desc(nvc0, desc, info->pc,
info->block, info->grid);
+
+ nve4_compute_upload_input(nvc0, desc, info->input, info->block, info->grid);
+
#ifdef DEBUG
if (debug_get_num_option("NV50_PROG_DEBUG", 0))
nve4_compute_dump_launch_desc(desc);
#endif
- nve4_compute_upload_input(nvc0, info->input, info->block, info->grid);
-
/* upload descriptor and flush */
#if 0
BEGIN_NVC0(push, NVE4_CP(UPLOAD_DST_ADDRESS_HIGH), 2);
diff --git a/src/gallium/drivers/nouveau/nvc0/nve4_compute.h b/src/gallium/drivers/nouveau/nvc0/nve4_compute.h
index dcafbed..8f08248 100644
--- a/src/gallium/drivers/nouveau/nvc0/nve4_compute.h
+++ b/src/gallium/drivers/nouveau/nvc0/nve4_compute.h
@@ -56,7 +56,7 @@ static inline void
nve4_cp_launch_desc_set_cb(struct nve4_cp_launch_desc *desc,
unsigned index,
struct nouveau_bo *bo,
- uint32_t base, uint16_t size)
+ uint32_t base, uint32_t size)
{
uint64_t address = bo->offset + base;
--
2.7.1
More information about the mesa-dev
mailing list