+void
+panfrost_job_submit(struct panfrost_context *ctx, struct panfrost_job *job)
+{
+ int ret;
+
+ panfrost_scoreboard_link_batch(job);
+
+ bool has_draws = job->last_job.gpu;
+ bool is_scanout = panfrost_is_scanout(ctx);
+
+ if (!job)
+ return;
+
+ ret = panfrost_drm_submit_vs_fs_job(ctx, has_draws, is_scanout);
+
+ if (ret)
+ fprintf(stderr, "panfrost_job_submit failed: %d\n", ret);
+}
+
+void
+panfrost_job_set_requirements(struct panfrost_context *ctx,
+ struct panfrost_job *job)
+{
+ if (ctx->rasterizer && ctx->rasterizer->base.multisample)
+ job->requirements |= PAN_REQ_MSAA;
+
+ if (ctx->depth_stencil && ctx->depth_stencil->depth.writemask)
+ job->requirements |= PAN_REQ_DEPTH_WRITE;
+}
+
+/* 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 */
+
+ bool has_alpha = util_format_has_alpha(format);
+ float clear_alpha = has_alpha ? color->f[3] : 1.0f;
+
+ /* Packed color depends on the framebuffer format */
+
+ const struct util_format_description *desc =
+ util_format_description(format);
+
+ if (util_format_is_rgba8_variant(desc)) {
+ 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;
+ unsigned g6 = CLAMP(color->f[1], 0.0, 1.0) * 63.0;
+ unsigned b5 = CLAMP(color->f[2], 0.0, 1.0) * 31.0;
+
+ /* Then we pack into a sparse u32. TODO: Why these shifts? */
+ 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 {
+ /* Try Gallium's generic default path. Doesn't work for all
+ * formats but it's a good guess. */
+
+ union util_color out;
+
+ 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)
+
+{
+ if (buffers & PIPE_CLEAR_COLOR) {
+ 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) {
+ job->clear_depth = depth;
+ }
+
+ if (buffers & PIPE_CLEAR_STENCIL) {
+ job->clear_stencil = stencil;
+ }
+
+ job->clear |= buffers;
+
+ /* Clearing affects the entire framebuffer (by definition -- this is
+ * the Gallium clear callback, which clears the whole framebuffer. If
+ * the scissor test were enabled from the GL side, the state tracker
+ * 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);
+}
+