From 931e7b4c7a16fdb4f9231d4af6ecb1b20ddaae2f Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 5 Aug 2020 22:02:32 -0400 Subject: [PATCH] panfrost: XMLify stencil test Signed-off-by: Alyssa Rosenzweig Reviewed-by: Tomeu Vizoso Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 24 +++++++------- src/panfrost/include/panfrost-job.h | 17 ++-------- src/panfrost/lib/decode.c | 34 ++------------------ src/panfrost/lib/midgard.xml | 9 ++++++ src/panfrost/lib/pan_blit.c | 12 +++---- 5 files changed, 32 insertions(+), 64 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 8376cafd2f1..8f6142f7b4a 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -519,15 +519,15 @@ void panfrost_sampler_desc_init_bifrost(const struct pipe_sampler_state *cso, static void panfrost_make_stencil_state(const struct pipe_stencil_state *in, - struct mali_stencil_test *out) + void *out) { - out->ref = 0; /* Gallium gets it from elsewhere */ - - out->mask = in->valuemask; - out->func = panfrost_translate_compare_func(in->func); - out->sfail = panfrost_translate_stencil_op(in->fail_op); - out->dpfail = panfrost_translate_stencil_op(in->zfail_op); - out->dppass = panfrost_translate_stencil_op(in->zpass_op); + pan_pack(out, STENCIL, cfg) { + cfg.mask = in->valuemask; + cfg.compare_function = panfrost_translate_compare_func(in->func); + cfg.stencil_fail = panfrost_translate_stencil_op(in->fail_op); + cfg.depth_fail = panfrost_translate_stencil_op(in->zfail_op); + cfg.depth_pass = panfrost_translate_stencil_op(in->zpass_op); + } } static void @@ -605,7 +605,10 @@ panfrost_frag_meta_zsa_update(struct panfrost_context *ctx, panfrost_make_stencil_state(&zsa->stencil[0], &fragmeta->stencil_front); fragmeta->stencil_mask_front = zsa->stencil[0].writemask; - fragmeta->stencil_front.ref = ctx->stencil_ref.ref_value[0]; + + /* Bottom 8-bits of stencil state is the stencil ref, ref is no + * more than 8-bits. Be extra careful. */ + fragmeta->stencil_front.opaque[0] |= ctx->stencil_ref.ref_value[0]; /* If back-stencil is not enabled, use the front values */ @@ -613,11 +616,10 @@ panfrost_frag_meta_zsa_update(struct panfrost_context *ctx, panfrost_make_stencil_state(&zsa->stencil[1], &fragmeta->stencil_back); fragmeta->stencil_mask_back = zsa->stencil[1].writemask; - fragmeta->stencil_back.ref = ctx->stencil_ref.ref_value[1]; + fragmeta->stencil_back.opaque[0] |= ctx->stencil_ref.ref_value[1]; } else { fragmeta->stencil_back = fragmeta->stencil_front; fragmeta->stencil_mask_back = fragmeta->stencil_mask_front; - fragmeta->stencil_back.ref = fragmeta->stencil_front.ref; } if (zsa->depth.enabled) diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h index 6d409a5ecb7..7f8e85e0f0a 100644 --- a/src/panfrost/include/panfrost-job.h +++ b/src/panfrost/include/panfrost-job.h @@ -85,19 +85,6 @@ typedef uint64_t mali_ptr; #define MALI_DEPTH_RANGE_B (1 << 13) #define MALI_NO_MSAA (1 << 14) -/* Stencil test state is all encoded in a single u32, just with a lot of - * enums... */ - -struct mali_stencil_test { - unsigned ref : 8; - unsigned mask : 8; - enum mali_func func : 3; - enum mali_stencil_op sfail : 3; - enum mali_stencil_op dpfail : 3; - enum mali_stencil_op dppass : 3; - unsigned zero : 4; -} __attribute__((packed)); - #define MALI_MASK_R (1 << 0) #define MALI_MASK_G (1 << 1) #define MALI_MASK_B (1 << 2) @@ -590,8 +577,8 @@ struct mali_shader_meta { u8 stencil_mask_back; u16 unknown2_4; - struct mali_stencil_test stencil_front; - struct mali_stencil_test stencil_back; + struct mali_stencil_packed stencil_front; + struct mali_stencil_packed stencil_back; union { struct { diff --git a/src/panfrost/lib/decode.c b/src/panfrost/lib/decode.c index 83d762d27dd..487d23c3cae 100644 --- a/src/panfrost/lib/decode.c +++ b/src/panfrost/lib/decode.c @@ -1588,36 +1588,6 @@ pandecode_shader_address(const char *name, mali_ptr ptr) return shader_ptr; } -static void -pandecode_stencil(const char *name, const struct mali_stencil_test *stencil) -{ - unsigned any_nonzero = - stencil->ref | stencil->mask | stencil->func | - stencil->sfail | stencil->dpfail | stencil->dppass; - - if (any_nonzero == 0) - return; - - const char *func = mali_func_as_str(stencil->func); - const char *sfail = mali_stencil_op_as_str(stencil->sfail); - const char *dpfail = mali_stencil_op_as_str(stencil->dpfail); - const char *dppass = mali_stencil_op_as_str(stencil->dppass); - - if (stencil->zero) - pandecode_msg("XXX: stencil zero tripped: %X\n", stencil->zero); - - pandecode_log(".stencil_%s = {\n", name); - pandecode_indent++; - pandecode_prop("ref = %d", stencil->ref); - pandecode_prop("mask = 0x%02X", stencil->mask); - pandecode_prop("func = %s", func); - pandecode_prop("sfail = %s", sfail); - pandecode_prop("dpfail = %s", dpfail); - pandecode_prop("dppass = %s", dppass); - pandecode_indent--; - pandecode_log("},\n"); -} - static void pandecode_blend_equation(const struct mali_blend_equation *blend) { @@ -2705,8 +2675,8 @@ pandecode_vertex_tiler_postfix_pre( pandecode_prop("stencil_mask_back = 0x%02X", s->stencil_mask_back); } - pandecode_stencil("front", &s->stencil_front); - pandecode_stencil("back", &s->stencil_back); + DUMP_CL("Stencil front", STENCIL, &s->stencil_front, 1); + DUMP_CL("Stencil back", STENCIL, &s->stencil_back, 1); if (is_bifrost) { pandecode_log(".bifrost2 = {\n"); diff --git a/src/panfrost/lib/midgard.xml b/src/panfrost/lib/midgard.xml index 54493a444aa..d3a40da45bd 100644 --- a/src/panfrost/lib/midgard.xml +++ b/src/panfrost/lib/midgard.xml @@ -60,6 +60,15 @@ + + + + + + + + + diff --git a/src/panfrost/lib/pan_blit.c b/src/panfrost/lib/pan_blit.c index cbf58f4a539..b93fcee962c 100644 --- a/src/panfrost/lib/pan_blit.c +++ b/src/panfrost/lib/pan_blit.c @@ -206,12 +206,12 @@ panfrost_load_midg( .format = MALI_RGBA32F }; - struct mali_stencil_test stencil = { - .mask = 0xFF, - .func = MALI_FUNC_ALWAYS, - .sfail = MALI_STENCIL_OP_REPLACE, - .dpfail = MALI_STENCIL_OP_REPLACE, - .dppass = MALI_STENCIL_OP_REPLACE, + struct mali_stencil_packed stencil; + pan_pack(&stencil, STENCIL, cfg) { + cfg.compare_function = MALI_FUNC_ALWAYS; + cfg.stencil_fail = MALI_STENCIL_OP_REPLACE; + cfg.depth_fail = MALI_STENCIL_OP_REPLACE; + cfg.depth_pass = MALI_STENCIL_OP_REPLACE; }; union midgard_blend replace = { -- 2.30.2