Commit c49856b5 authored by Alyssa Rosenzweig's avatar Alyssa Rosenzweig 💜

Galliumified uniform upload

parent f77ab0de
......@@ -61,6 +61,11 @@ trans_invalidate_frame(struct panfrost_context *ctx)
trans_viewport(ctx, 0.0, 1.0, 0, 0, 400, 320);
ctx->dirty |= PAN_DIRTY_VIEWPORT;
/* Uniforms are all discarded with the above stack discard */
for (int i = 0; i <= PIPE_SHADER_FRAGMENT; ++i)
ctx->constant_buffer[i].dirty = true;
}
/* Framebuffer descriptor */
......@@ -498,6 +503,30 @@ trans_emit_for_draw(struct panfrost_context *ctx)
ctx->dirty &= ~PAN_DIRTY_VIEWPORT;
}
for (int i = 0; i < PIPE_SHADER_TYPES; ++i) {
struct panfrost_constant_buffer *buf = &ctx->constant_buffer[i];
if (buf->dirty) {
mali_ptr address = panfrost_upload(&ctx->cmdstream, buf->buffer, buf->size, false);
switch (i) {
case PIPE_SHADER_VERTEX:
ctx->payload_vertex.uniforms = address;
break;
case PIPE_SHADER_FRAGMENT:
ctx->payload_tiler.uniforms = address;
break;
default:
printf("Unknown shader stage %d in uniform upload\n", i);
break;
}
buf->dirty = 0;
}
}
}
/* Corresponds to exactly one draw, but does not submit anything */
......@@ -853,8 +882,11 @@ panfrost_set_constant_buffer(
enum pipe_shader_type shader, uint index,
const struct pipe_constant_buffer *buf)
{
struct panfrost_context *ctx = panfrost_context(pctx);
size_t sz = buf->buffer_size;
printf("Constant buffer set... %d %d\n", index, sz);
/* Multiple constant buffers not yet supported */
assert(index == 0);
void *cpu;
......@@ -871,7 +903,19 @@ panfrost_set_constant_buffer(
return;
}
printf("Val %f..\n", ((float *) cpu)[0]);
/* Copy the constant buffer into the driver context and adjust dirty
* flags as necessary */
struct panfrost_constant_buffer *pbuf = &ctx->constant_buffer[shader];
pbuf->dirty = true;
pbuf->size = sz;
if (pbuf->buffer)
free(pbuf->buffer);
pbuf->buffer = malloc(sz);
memcpy(pbuf->buffer, cpu, sz);
}
......@@ -1013,6 +1057,7 @@ panfrost_create_context(struct pipe_screen *screen, void *priv, unsigned flags)
screen->resource_create_front = panfrost_resource_create_front;
struct panfrost_context *ctx = CALLOC_STRUCT(panfrost_context);
memset(ctx, 0, sizeof(*ctx));
struct pipe_context *gallium = (struct pipe_context *) ctx;
gallium->transfer_map = panfrost_transfer_map;
......
......@@ -38,6 +38,12 @@
#define PAN_DIRTY_VERT_BUF (1 << 6)
#define PAN_DIRTY_VIEWPORT (1 << 7)
struct panfrost_constant_buffer {
bool dirty;
size_t size;
void *buffer;
};
struct panfrost_context {
/* Gallium context */
struct pipe_context base;
......@@ -100,6 +106,10 @@ struct panfrost_context {
struct mali_viewport viewport;
/* TODO: Multiple uniform buffers (index =/= 0), finer updates? */
struct panfrost_constant_buffer constant_buffer[PIPE_SHADER_TYPES];
/* CSOs */
struct panfrost_rasterizer *rasterizer;
......
......@@ -55,7 +55,7 @@ int main(int argc, const char **argv)
gallium->set_vertex_buffers(gallium, 0, 1, &buff);
float uniforms[] = {
1.0, 0.2, 0.2, 1.0
0.8, 0.2, 0.2, 1.0
};
templ.width0 = sizeof(uniforms);
......@@ -71,13 +71,6 @@ int main(int argc, const char **argv)
gallium->set_constant_buffer(gallium, PIPE_SHADER_VERTEX, 0, &consts);
for (int i = 0; i < 60; ++i) {
float uniforms_1[] = {
0.8, 0.2, 0.2, 1.0
};
mali_ptr uniforms_1_p = panfrost_upload(&ctx->cmdstream, &uniforms_1, sizeof(uniforms_1), false);
ctx->payload_vertex.uniforms = uniforms_1_p;
attributes_data_1_0[0] -= 0.005f;
memcpy(attrib_trans,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment