[Mesa-dev] [PATCH libdrm 4/9] panfrost/midgard: Move clearing logic into pan_job
Rohan Garg
rohan.garg at collabora.com
Wed Jun 12 11:24:34 UTC 2019
---
src/gallium/drivers/panfrost/pan_context.c | 49 +-----------------
src/gallium/drivers/panfrost/pan_job.c | 59 ++++++++++++++++++++++
src/gallium/drivers/panfrost/pan_job.h | 8 +++
3 files changed, 68 insertions(+), 48 deletions(-)
diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index 4c53b2d58f5..d372f295979 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -245,40 +245,6 @@ panfrost_is_scanout(struct panfrost_context *ctx)
ctx->pipe_framebuffer.cbufs[0]->texture->bind & PIPE_BIND_SHARED;
}
-static uint32_t
-pan_pack_color(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)) {
- 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);
- } 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? */
- return (b5 << 25) | (g6 << 14) | (r5 << 5);
- } else {
- /* Unknown format */
- assert(0);
- }
-
- return 0;
-}
-
static void
panfrost_clear(
struct pipe_context *pipe,
@@ -289,20 +255,7 @@ panfrost_clear(
struct panfrost_context *ctx = pan_context(pipe);
struct panfrost_job *job = panfrost_get_job_for_fbo(ctx);
- if (buffers & PIPE_CLEAR_COLOR) {
- enum pipe_format format = ctx->pipe_framebuffer.cbufs[0]->format;
- job->clear_color = pan_pack_color(color, format);
- }
-
- if (buffers & PIPE_CLEAR_DEPTH) {
- job->clear_depth = depth;
- }
-
- if (buffers & PIPE_CLEAR_STENCIL) {
- job->clear_stencil = stencil;
- }
-
- job->clear |= buffers;
+ panfrost_job_clear(ctx, job, buffers, color, depth, stencil);
}
static mali_ptr
diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c
index 0083ca6499e..be2742a0dc5 100644
--- a/src/gallium/drivers/panfrost/pan_job.c
+++ b/src/gallium/drivers/panfrost/pan_job.c
@@ -26,6 +26,7 @@
#include "pan_context.h"
#include "util/hash_table.h"
#include "util/ralloc.h"
+#include "util/u_format.h"
struct panfrost_job *
panfrost_create_job(struct panfrost_context *ctx)
@@ -175,6 +176,64 @@ 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)
+{
+ /* 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)) {
+ 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);
+ } 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? */
+ return (b5 << 25) | (g6 << 14) | (r5 << 5);
+ } else {
+ /* Unknown format */
+ assert(0);
+ }
+
+ return 0;
+}
+
+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) {
+ enum pipe_format format = ctx->pipe_framebuffer.cbufs[0]->format;
+ job->clear_color = pan_pack_color(color, format);
+ }
+
+ if (buffers & PIPE_CLEAR_DEPTH) {
+ job->clear_depth = depth;
+ }
+
+ if (buffers & PIPE_CLEAR_STENCIL) {
+ job->clear_stencil = stencil;
+ }
+
+ job->clear |= buffers;
+}
+
void
panfrost_flush_jobs_reading_resource(struct panfrost_context *panfrost,
struct pipe_resource *prsc)
diff --git a/src/gallium/drivers/panfrost/pan_job.h b/src/gallium/drivers/panfrost/pan_job.h
index cbfd6cb0c7f..2e7c0532341 100644
--- a/src/gallium/drivers/panfrost/pan_job.h
+++ b/src/gallium/drivers/panfrost/pan_job.h
@@ -94,4 +94,12 @@ panfrost_job_submit(struct panfrost_context *ctx, struct panfrost_job *job);
void
panfrost_job_set_requirements(struct panfrost_context *ctx,
struct panfrost_job *job);
+
+void
+panfrost_job_clear(struct panfrost_context *ctx,
+ struct panfrost_job *job,
+ unsigned buffers,
+ const union pipe_color_union *color,
+ double depth, unsigned stencil);
+
#endif
--
2.17.1
More information about the mesa-dev
mailing list