X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fpanfrost%2Fpan_job.c;h=6339b39d29a01eb7e69881227672fd66161a43a7;hb=204a3bb816fe6382ac14ac06a2395f4afdded43e;hp=88bed457da9bc3ef63f5bad42fb88d378f826779;hpb=5f81669d880bfc9f3a85d5231d4629d95332a488;p=mesa.git diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c index 88bed457da9..6339b39d29a 100644 --- a/src/gallium/drivers/panfrost/pan_job.c +++ b/src/gallium/drivers/panfrost/pan_job.c @@ -27,6 +27,7 @@ #include "util/hash_table.h" #include "util/ralloc.h" #include "util/u_format.h" +#include "util/u_pack_color.h" struct panfrost_job * panfrost_create_job(struct panfrost_context *ctx) @@ -41,10 +42,12 @@ panfrost_create_job(struct panfrost_context *ctx) job->minx = job->miny = ~0; job->maxx = job->maxy = 0; + job->transient_offset = 0; util_dynarray_init(&job->headers, job); util_dynarray_init(&job->gpu_headers, job); - + util_dynarray_init(&job->transient_indices, job); + return job; } @@ -59,6 +62,14 @@ panfrost_free_job(struct panfrost_context *ctx, struct panfrost_job *job) panfrost_bo_unreference(ctx->base.screen, bo); } + /* Free up the transient BOs we're sitting on */ + struct panfrost_screen *screen = pan_screen(ctx->base.screen); + + util_dynarray_foreach(&job->transient_indices, unsigned, index) { + /* Mark it free */ + BITSET_SET(screen->free_transient, *index); + } + _mesa_hash_table_remove_key(ctx->jobs, &job->key); if (ctx->job == job) @@ -69,7 +80,7 @@ panfrost_free_job(struct panfrost_context *ctx, struct panfrost_job *job) struct panfrost_job * panfrost_get_job(struct panfrost_context *ctx, - struct pipe_surface **cbufs, struct pipe_surface *zsbuf) + struct pipe_surface **cbufs, struct pipe_surface *zsbuf) { /* Lookup the job first */ @@ -82,7 +93,7 @@ panfrost_get_job(struct panfrost_context *ctx, }, .zsbuf = zsbuf }; - + struct hash_entry *entry = _mesa_hash_table_search(ctx->jobs, &key); if (entry) @@ -140,11 +151,11 @@ panfrost_job_add_bo(struct panfrost_job *job, struct panfrost_bo *bo) void panfrost_flush_jobs_writing_resource(struct panfrost_context *panfrost, - struct pipe_resource *prsc) + struct pipe_resource *prsc) { #if 0 struct hash_entry *entry = _mesa_hash_table_search(panfrost->write_jobs, - prsc); + prsc); if (entry) { struct panfrost_job *job = entry->data; panfrost_job_submit(panfrost, job); @@ -156,8 +167,6 @@ panfrost_flush_jobs_writing_resource(struct panfrost_context *panfrost, void panfrost_job_submit(struct panfrost_context *ctx, struct panfrost_job *job) { - struct pipe_context *gallium = (struct pipe_context *) ctx; - struct panfrost_screen *screen = pan_screen(gallium->screen); int ret; panfrost_scoreboard_link_batch(job); @@ -176,7 +185,7 @@ panfrost_job_submit(struct panfrost_context *ctx, struct panfrost_job *job) void panfrost_job_set_requirements(struct panfrost_context *ctx, - struct panfrost_job *job) + struct panfrost_job *job) { if (ctx->rasterizer && ctx->rasterizer->base.multisample) job->requirements |= PAN_REQ_MSAA; @@ -185,8 +194,26 @@ panfrost_job_set_requirements(struct panfrost_context *ctx, job->requirements |= PAN_REQ_DEPTH_WRITE; } -static uint32_t -pan_pack_color(const union pipe_color_union *color, enum pipe_format format) +/* Helper to smear a 32-bit color across 128-bit components */ + +static void +pan_pack_color_32(uint32_t *packed, uint32_t v) +{ + for (unsigned i = 0; i < 4; ++i) + packed[i] = v; +} + +static void +pan_pack_color_64(uint32_t *packed, uint32_t lo, uint32_t hi) +{ + for (unsigned i = 0; i < 4; i += 2) { + packed[i + 0] = lo; + packed[i + 1] = hi; + } +} + +static void +pan_pack_color(uint32_t *packed, const union pipe_color_union *color, enum pipe_format format) { /* Alpha magicked to 1.0 if there is no alpha */ @@ -199,10 +226,11 @@ pan_pack_color(const union pipe_color_union *color, enum pipe_format format) util_format_description(format); if (util_format_is_rgba8_variant(desc)) { - return (float_to_ubyte(clear_alpha) << 24) | - (float_to_ubyte(color->f[2]) << 16) | - (float_to_ubyte(color->f[1]) << 8) | - (float_to_ubyte(color->f[0]) << 0); + pan_pack_color_32(packed, + (float_to_ubyte(clear_alpha) << 24) | + (float_to_ubyte(color->f[2]) << 16) | + (float_to_ubyte(color->f[1]) << 8) | + (float_to_ubyte(color->f[0]) << 0)); } else if (format == PIPE_FORMAT_B5G6R5_UNORM) { /* First, we convert the components to R5, G6, B5 separately */ unsigned r5 = CLAMP(color->f[0], 0.0, 1.0) * 31.0; @@ -210,26 +238,71 @@ pan_pack_color(const union pipe_color_union *color, enum pipe_format format) unsigned b5 = CLAMP(color->f[2], 0.0, 1.0) * 31.0; /* Then we pack into a sparse u32. TODO: Why these shifts? */ - return (b5 << 25) | (g6 << 14) | (r5 << 5); + pan_pack_color_32(packed, (b5 << 25) | (g6 << 14) | (r5 << 5)); + } else if (format == PIPE_FORMAT_B4G4R4A4_UNORM) { + /* We scale the components against 0xF0 (=240.0), rather than 0xFF */ + unsigned r4 = CLAMP(color->f[0], 0.0, 1.0) * 240.0; + unsigned g4 = CLAMP(color->f[1], 0.0, 1.0) * 240.0; + unsigned b4 = CLAMP(color->f[2], 0.0, 1.0) * 240.0; + unsigned a4 = CLAMP(clear_alpha, 0.0, 1.0) * 240.0; + + /* Pack on *byte* intervals */ + pan_pack_color_32(packed, (a4 << 24) | (b4 << 16) | (g4 << 8) | r4); + } else if (format == PIPE_FORMAT_B5G5R5A1_UNORM) { + /* Scale as expected but shift oddly */ + unsigned r5 = round(CLAMP(color->f[0], 0.0, 1.0)) * 31.0; + unsigned g5 = round(CLAMP(color->f[1], 0.0, 1.0)) * 31.0; + unsigned b5 = round(CLAMP(color->f[2], 0.0, 1.0)) * 31.0; + unsigned a1 = round(CLAMP(clear_alpha, 0.0, 1.0)) * 1.0; + + pan_pack_color_32(packed, (a1 << 31) | (b5 << 25) | (g5 << 15) | (r5 << 5)); } else { - /* Unknown format */ - assert(0); - } + /* Try Gallium's generic default path. Doesn't work for all + * formats but it's a good guess. */ + + union util_color out; - return 0; + if (util_format_is_pure_integer(format)) { + memcpy(out.ui, color->ui, 16); + } else { + util_pack_color(color->f, format, &out); + } + + unsigned size = util_format_get_blocksize(format); + + if (size == 1) { + unsigned b = out.ui[0]; + unsigned s = b | (b << 8); + pan_pack_color_32(packed, s | (s << 16)); + } else if (size == 2) + pan_pack_color_32(packed, out.ui[0] | (out.ui[0] << 16)); + else if (size == 4) + pan_pack_color_32(packed, out.ui[0]); + else if (size == 8) + pan_pack_color_64(packed, out.ui[0], out.ui[1]); + else if (size == 16) + memcpy(packed, out.ui, 16); + else + unreachable("Unknown generic format size packing clear colour"); + } } void panfrost_job_clear(struct panfrost_context *ctx, - struct panfrost_job *job, - unsigned buffers, - const union pipe_color_union *color, - double depth, unsigned stencil) + struct panfrost_job *job, + unsigned buffers, + const union pipe_color_union *color, + double depth, unsigned stencil) { if (buffers & PIPE_CLEAR_COLOR) { - enum pipe_format format = ctx->pipe_framebuffer.cbufs[0]->format; - job->clear_color = pan_pack_color(color, format); + for (unsigned i = 0; i < PIPE_MAX_COLOR_BUFS; ++i) { + if (!(buffers & (PIPE_CLEAR_COLOR0 << i))) + continue; + + enum pipe_format format = ctx->pipe_framebuffer.cbufs[i]->format; + pan_pack_color(job->clear_color[i], color, format); + } } if (buffers & PIPE_CLEAR_DEPTH) { @@ -248,13 +321,13 @@ panfrost_job_clear(struct panfrost_context *ctx, * would emit a quad instead and we wouldn't go down this code path) */ panfrost_job_union_scissor(job, 0, 0, - ctx->pipe_framebuffer.width, - ctx->pipe_framebuffer.height); + ctx->pipe_framebuffer.width, + ctx->pipe_framebuffer.height); } void panfrost_flush_jobs_reading_resource(struct panfrost_context *panfrost, - struct pipe_resource *prsc) + struct pipe_resource *prsc) { struct panfrost_resource *rsc = pan_resource(prsc); @@ -288,8 +361,8 @@ panfrost_job_hash(const void *key) void panfrost_job_union_scissor(struct panfrost_job *job, - unsigned minx, unsigned miny, - unsigned maxx, unsigned maxy) + unsigned minx, unsigned miny, + unsigned maxx, unsigned maxy) { job->minx = MIN2(job->minx, minx); job->miny = MIN2(job->miny, miny); @@ -305,6 +378,6 @@ panfrost_job_init(struct panfrost_context *ctx) panfrost_job_compare); ctx->write_jobs = _mesa_hash_table_create(ctx, - _mesa_hash_pointer, - _mesa_key_pointer_equal); + _mesa_hash_pointer, + _mesa_key_pointer_equal); }