summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/panfrost/pan_job.c
diff options
context:
space:
mode:
authorRohan Garg <[email protected]>2019-06-05 19:04:04 +0200
committerAlyssa Rosenzweig <[email protected]>2019-06-18 12:32:43 -0700
commitad284f794cdd1de7d4546b1cb2a3772860436da4 (patch)
tree89a47893d8fe1ce28da45dcefba2887e829adb8d /src/gallium/drivers/panfrost/pan_job.c
parent98eda99ab88b8a5bcf5da5daa7ca4edbf34592fd (diff)
panfrost: Move clearing logic into pan_job
Reviewed-by: Alyssa Rosenzweig <[email protected]>
Diffstat (limited to 'src/gallium/drivers/panfrost/pan_job.c')
-rw-r--r--src/gallium/drivers/panfrost/pan_job.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c
index a7fc5f975cf..1882cc4faf3 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)
@@ -176,6 +177,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)