panfrost: XMLify stencil test
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Thu, 6 Aug 2020 02:02:32 +0000 (22:02 -0400)
committerTomeu Vizoso <tomeu.vizoso@collabora.com>
Thu, 13 Aug 2020 06:55:16 +0000 (08:55 +0200)
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6195>

src/gallium/drivers/panfrost/pan_cmdstream.c
src/panfrost/include/panfrost-job.h
src/panfrost/lib/decode.c
src/panfrost/lib/midgard.xml
src/panfrost/lib/pan_blit.c

index 8376cafd2f1e7882820722c228a8db70601c68ba..8f6142f7b4a76415eda630638ce97e7d4bc1120f 100644 (file)
@@ -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)
index 6d409a5ecb7c9ddf76692276d1ced40883281577..7f8e85e0f0a14035bf3441cd202d25b8363e8b98 100644 (file)
@@ -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 {
index 83d762d27dde08ea291af1248f972f5f4261f58d..487d23c3caef505efcdaff4741e375ed7539378d 100644 (file)
@@ -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");
index 54493a444aadc941dc228c769a6da62110c1fb52..d3a40da45bdadb797661b964cc56b4d13da7132f 100644 (file)
     <value name="Mirrored Clamp to Border" value="15"/>
   </enum>
 
+  <struct name="Stencil">
+    <field name="Reference Value" size="8" start="0" type="uint"/>
+    <field name="Mask" size="8" start="8" type="uint" default="0xFF"/>
+    <field name="Compare Function" size="3" start="16" type="Func"/>
+    <field name="Stencil Fail" size="3" start="19" type="Stencil Op"/>
+    <field name="Depth Fail" size="3" start="22" type="Stencil Op"/>
+    <field name="Depth Pass" size="3" start="25" type="Stencil Op"/>
+  </struct>
+
   <struct name="Uniform Buffer">
     <field name="Entries" size="12" start="0" type="uint" modifier="minus(1)"/>
     <field name="Pointer" size="52" start="12" type="address" modifier="shr(4)" element="16" count="Entries"/>
index cbf58f4a5399eb63ba52c5a5ac7edcd9983744a6..b93fcee962c9b11b7b3ba0a3324f61cab6171d29 100644 (file)
@@ -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 = {