summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlyssa Rosenzweig <[email protected]>2019-06-20 16:07:57 -0700
committerAlyssa Rosenzweig <[email protected]>2019-06-24 12:57:40 -0700
commitca2caf01dff2e26da8a4aaa41465fdf31faa85dc (patch)
tree68ba75213b68aa9d3a11956cf83dc75d809848a3
parentf35f37385038099158e05602ae0ca083429258dc (diff)
panfrost: Constant buffer refactor
We refactor panfrost_constant_buffer to mirror v3d's constant buffer handling, to enable UBOs as well as a single set of uniforms. Signed-off-by: Alyssa Rosenzweig <[email protected]>
-rw-r--r--src/gallium/drivers/panfrost/pan_context.c66
-rw-r--r--src/gallium/drivers/panfrost/pan_context.h6
2 files changed, 34 insertions, 38 deletions
diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index 895dcceff4e..3cc5988d3cc 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -987,6 +987,20 @@ static void panfrost_upload_sysvals(struct panfrost_context *ctx, void *buf,
}
}
+static const void *
+panfrost_map_constant_buffer_cpu(struct panfrost_constant_buffer *buf, unsigned index)
+{
+ struct pipe_constant_buffer *cb = &buf->cb[index];
+ struct panfrost_resource *rsrc = pan_resource(cb->buffer);
+
+ if (rsrc)
+ return rsrc->bo->cpu;
+ else if (cb->user_buffer)
+ return cb->user_buffer;
+ else
+ unreachable("No constant buffer");
+}
+
/* Go through dirty flags and actualise them in the cmdstream. */
void
@@ -1213,16 +1227,23 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data)
struct panfrost_shader_state *fs = &ctx->fs->variants[ctx->fs->active_variant];
struct panfrost_shader_state *ss = (i == PIPE_SHADER_FRAGMENT) ? fs : vs;
+ /* Uniforms are implicitly UBO #0 */
+ bool has_uniforms = buf->enabled_mask & (1 << 0);
+
/* Allocate room for the sysval and the uniforms */
size_t sys_size = sizeof(float) * 4 * ss->sysval_count;
- size_t size = sys_size + buf->size;
+ size_t uniform_size = has_uniforms ? (buf->cb[0].buffer_size) : 0;
+ size_t size = sys_size + uniform_size;
struct panfrost_transfer transfer = panfrost_allocate_transient(ctx, size);
/* Upload sysvals requested by the shader */
panfrost_upload_sysvals(ctx, transfer.cpu, ss, i);
/* Upload uniforms */
- memcpy(transfer.cpu + sys_size, buf->buffer, buf->size);
+ if (has_uniforms) {
+ const void *cpu = panfrost_map_constant_buffer_cpu(buf, 0);
+ memcpy(transfer.cpu + sys_size, cpu, uniform_size);
+ }
int uniform_count = 0;
@@ -1256,7 +1277,7 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data)
postfix->uniforms = transfer.gpu;
postfix->uniform_buffers = ubufs;
- buf->dirty = 0;
+ buf->dirty_mask = 0;
}
/* TODO: Upload the viewport somewhere more appropriate */
@@ -1985,43 +2006,18 @@ panfrost_set_constant_buffer(
struct panfrost_context *ctx = pan_context(pctx);
struct panfrost_constant_buffer *pbuf = &ctx->constant_buffer[shader];
- size_t sz = buf ? buf->buffer_size : 0;
-
- /* Free previous buffer */
-
- pbuf->dirty = true;
- pbuf->size = sz;
+ util_copy_constant_buffer(&pbuf->cb[index], buf);
- if (pbuf->buffer) {
- ralloc_free(pbuf->buffer);
- pbuf->buffer = NULL;
- }
-
- /* If unbinding, we're done */
+ unsigned mask = (1 << index);
- if (!buf)
- return;
-
- /* Multiple constant buffers not yet supported */
- assert(index == 0);
-
- const uint8_t *cpu;
-
- struct panfrost_resource *rsrc = (struct panfrost_resource *) (buf->buffer);
-
- if (rsrc) {
- cpu = rsrc->bo->cpu;
- } else if (buf->user_buffer) {
- cpu = buf->user_buffer;
- } else {
- DBG("No constant buffer?\n");
+ if (unlikely(!buf)) {
+ pbuf->enabled_mask &= ~mask;
+ pbuf->dirty_mask &= ~mask;
return;
}
- /* Copy the constant buffer into the driver context for later upload */
-
- pbuf->buffer = rzalloc_size(ctx, sz);
- memcpy(pbuf->buffer, cpu + buf->buffer_offset, sz);
+ pbuf->enabled_mask |= mask;
+ pbuf->dirty_mask |= mask;
}
static void
diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h
index fc8fc3c1291..41999b5fed5 100644
--- a/src/gallium/drivers/panfrost/pan_context.h
+++ b/src/gallium/drivers/panfrost/pan_context.h
@@ -67,9 +67,9 @@ struct prim_convert_context;
lval &= ~(bit);
struct panfrost_constant_buffer {
- bool dirty;
- size_t size;
- void *buffer;
+ struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS];
+ uint32_t enabled_mask;
+ uint32_t dirty_mask;
};
struct panfrost_query {