panfrost: XMLify stencil op
[mesa.git] / src / gallium / drivers / panfrost / pan_cmdstream.c
index dbfe1f4461b66c219ae9bf65442b0c693ee59e0a..c1a5ebbf3ea96d83cff936e2722742c9f5d8a84e 100644 (file)
@@ -101,7 +101,7 @@ panfrost_vt_update_primitive_size(struct panfrost_context *ctx,
         struct panfrost_rasterizer *rasterizer = ctx->rasterizer;
 
         if (!panfrost_writes_point_size(ctx)) {
-                bool points = prefix->draw_mode == MALI_POINTS;
+                bool points = prefix->draw_mode == MALI_DRAW_MODE_POINTS;
                 float val = 0.0f;
 
                 if (rasterizer)
@@ -369,7 +369,7 @@ panfrost_translate_compare_func(enum pipe_compare_func in)
                 return MALI_FUNC_GREATER;
 
         case PIPE_FUNC_NOTEQUAL:
-                return MALI_FUNC_NOTEQUAL;
+                return MALI_FUNC_NOT_EQUAL;
 
         case PIPE_FUNC_GEQUAL:
                 return MALI_FUNC_GEQUAL;
@@ -387,28 +387,28 @@ panfrost_translate_stencil_op(enum pipe_stencil_op in)
 {
         switch (in) {
         case PIPE_STENCIL_OP_KEEP:
-                return MALI_STENCIL_KEEP;
+                return MALI_STENCIL_OP_KEEP;
 
         case PIPE_STENCIL_OP_ZERO:
-                return MALI_STENCIL_ZERO;
+                return MALI_STENCIL_OP_ZERO;
 
         case PIPE_STENCIL_OP_REPLACE:
-               return MALI_STENCIL_REPLACE;
+               return MALI_STENCIL_OP_REPLACE;
 
         case PIPE_STENCIL_OP_INCR:
-                return MALI_STENCIL_INCR;
+                return MALI_STENCIL_OP_INCR_SAT;
 
         case PIPE_STENCIL_OP_DECR:
-                return MALI_STENCIL_DECR;
+                return MALI_STENCIL_OP_DECR_SAT;
 
         case PIPE_STENCIL_OP_INCR_WRAP:
-                return MALI_STENCIL_INCR_WRAP;
+                return MALI_STENCIL_OP_INCR_WRAP;
 
         case PIPE_STENCIL_OP_DECR_WRAP:
-                return MALI_STENCIL_DECR_WRAP;
+                return MALI_STENCIL_OP_DECR_WRAP;
 
         case PIPE_STENCIL_OP_INVERT:
-                return MALI_STENCIL_INVERT;
+                return MALI_STENCIL_OP_INVERT;
 
         default:
                 unreachable("Invalid stencil op");
@@ -554,8 +554,13 @@ panfrost_frag_meta_rasterizer_update(struct panfrost_context *ctx,
         SET_BIT(fragmeta->unknown2_3, MALI_HAS_MSAA, msaa);
         SET_BIT(fragmeta->unknown2_4, MALI_NO_MSAA, !msaa);
 
-        SET_BIT(fragmeta->unknown2_3, MALI_PER_SAMPLE,
-                        msaa && ctx->min_samples > 1);
+        struct panfrost_shader_state *fs;
+        fs = panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT);
+
+        /* EXT_shader_framebuffer_fetch requires the shader to be run
+         * per-sample when outputs are read. */
+        bool per_sample = ctx->min_samples > 1 || fs->outputs_read;
+        SET_BIT(fragmeta->unknown2_3, MALI_PER_SAMPLE, msaa && per_sample);
 
         fragmeta->depth_units = rast->offset_units * 2.0f;
         fragmeta->depth_factor = rast->offset_scale;
@@ -580,9 +585,9 @@ panfrost_frag_meta_zsa_update(struct panfrost_context *ctx,
                 struct pipe_stencil_state default_stencil = {
                         .enabled = 0,
                         .func = PIPE_FUNC_ALWAYS,
-                        .fail_op = MALI_STENCIL_KEEP,
-                        .zfail_op = MALI_STENCIL_KEEP,
-                        .zpass_op = MALI_STENCIL_KEEP,
+                        .fail_op = PIPE_STENCIL_OP_KEEP,
+                        .zfail_op = PIPE_STENCIL_OP_KEEP,
+                        .zpass_op = PIPE_STENCIL_OP_KEEP,
                         .writemask = 0xFF,
                         .valuemask = 0xFF
                 };
@@ -867,14 +872,21 @@ panfrost_frag_shader_meta_init(struct panfrost_context *ctx,
                 SET_BIT(fragmeta->midgard1.flags_lo, MALI_HELPER_INVOCATIONS,
                         fs->helper_invocations);
 
+                /* If discard is enabled, which bit we set to convey this
+                 * depends on if depth/stencil is used for the draw or not.
+                 * Just one of depth OR stencil is enough to trigger this. */
+
                 const struct pipe_depth_stencil_alpha_state *zsa = ctx->depth_stencil;
+                bool zs_enabled = fs->writes_depth || fs->writes_stencil;
 
-                bool depth_enabled = fs->writes_depth ||
-                   (zsa && zsa->depth.enabled && zsa->depth.func != PIPE_FUNC_ALWAYS);
+                if (zsa) {
+                        zs_enabled |= (zsa->depth.enabled && zsa->depth.func != PIPE_FUNC_ALWAYS);
+                        zs_enabled |= zsa->stencil[0].enabled;
+                }
 
                 SET_BIT(fragmeta->midgard1.flags_lo, MALI_READS_TILEBUFFER,
-                        fs->outputs_read || (!depth_enabled && fs->can_discard));
-                SET_BIT(fragmeta->midgard1.flags_lo, MALI_READS_ZS, depth_enabled && fs->can_discard);
+                        fs->outputs_read || (!zs_enabled && fs->can_discard));
+                SET_BIT(fragmeta->midgard1.flags_lo, MALI_READS_ZS, zs_enabled && fs->can_discard);
         }
 
         panfrost_frag_meta_rasterizer_update(ctx, fragmeta);
@@ -1407,7 +1419,7 @@ panfrost_update_sampler_view(struct panfrost_sampler_view *view,
 {
         struct panfrost_resource *rsrc = pan_resource(view->base.texture);
         if (view->texture_bo != rsrc->bo->gpu ||
-            view->layout != rsrc->layout) {
+            view->modifier != rsrc->modifier) {
                 panfrost_bo_unreference(view->bo);
                 panfrost_create_sampler_view_bo(view, pctx, &rsrc->base);
         }
@@ -2195,9 +2207,9 @@ panfrost_emit_vertex_tiler_jobs(struct panfrost_batch *batch,
         if (wallpapering) {
                 /* Inject in reverse order, with "predicted" job indices.
                  * THIS IS A HACK XXX */
-                panfrost_new_job(&batch->pool, &batch->scoreboard, JOB_TYPE_TILER, false,
+                panfrost_new_job(&batch->pool, &batch->scoreboard, MALI_JOB_TYPE_TILER, false,
                                  batch->scoreboard.job_index + 2, tp, tp_size, true);
-                panfrost_new_job(&batch->pool, &batch->scoreboard, JOB_TYPE_VERTEX, false, 0,
+                panfrost_new_job(&batch->pool, &batch->scoreboard, MALI_JOB_TYPE_VERTEX, false, 0,
                                  vp, vp_size, true);
                 return;
         }
@@ -2207,13 +2219,13 @@ panfrost_emit_vertex_tiler_jobs(struct panfrost_batch *batch,
         bool rasterizer_discard = ctx->rasterizer &&
                                   ctx->rasterizer->base.rasterizer_discard;
 
-        unsigned vertex = panfrost_new_job(&batch->pool, &batch->scoreboard, JOB_TYPE_VERTEX, false, 0,
+        unsigned vertex = panfrost_new_job(&batch->pool, &batch->scoreboard, MALI_JOB_TYPE_VERTEX, false, 0,
                                            vp, vp_size, false);
 
         if (rasterizer_discard)
                 return;
 
-        panfrost_new_job(&batch->pool, &batch->scoreboard, JOB_TYPE_TILER, false, vertex, tp, tp_size,
+        panfrost_new_job(&batch->pool, &batch->scoreboard, MALI_JOB_TYPE_TILER, false, vertex, tp, tp_size,
                          false);
 }