panfrost: Implement ARB_depth_clamp
authorIcecream95 <ixn@keemail.me>
Thu, 14 May 2020 03:58:04 +0000 (15:58 +1200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 16 Jun 2020 12:59:10 +0000 (12:59 +0000)
This significantly improves the quality of shadows in OpenMW.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5453>

src/gallium/drivers/panfrost/pan_cmdstream.c
src/gallium/drivers/panfrost/pan_screen.c
src/panfrost/include/panfrost-job.h
src/panfrost/pandecode/decode.c

index aa82d0ca3391d75449d5c7ae5087245b6d2cae11..0ea5bc0e16a4998f3d6d82ba2eaaf28ffeed4b26 100644 (file)
@@ -550,6 +550,8 @@ panfrost_frag_meta_rasterizer_update(struct panfrost_context *ctx,
                 fragmeta->depth_factor = 0.0f;
                 SET_BIT(fragmeta->unknown2_4, MALI_DEPTH_RANGE_A, false);
                 SET_BIT(fragmeta->unknown2_4, MALI_DEPTH_RANGE_B, false);
+                SET_BIT(fragmeta->unknown2_3, MALI_DEPTH_CLIP_NEAR, true);
+                SET_BIT(fragmeta->unknown2_3, MALI_DEPTH_CLIP_FAR, true);
                 return;
         }
 
@@ -567,6 +569,9 @@ panfrost_frag_meta_rasterizer_update(struct panfrost_context *ctx,
 
         SET_BIT(fragmeta->unknown2_4, MALI_DEPTH_RANGE_A, rast->offset_tri);
         SET_BIT(fragmeta->unknown2_4, MALI_DEPTH_RANGE_B, rast->offset_tri);
+
+        SET_BIT(fragmeta->unknown2_3, MALI_DEPTH_CLIP_NEAR, rast->depth_clip_near);
+        SET_BIT(fragmeta->unknown2_3, MALI_DEPTH_CLIP_FAR, rast->depth_clip_far);
 }
 
 static void
@@ -826,7 +831,7 @@ panfrost_frag_shader_meta_init(struct panfrost_context *ctx,
         fs = panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT);
 
         fragmeta->alpha_coverage = ~MALI_ALPHA_COVERAGE(0.000000);
-        fragmeta->unknown2_3 = MALI_DEPTH_FUNC(MALI_FUNC_ALWAYS) | 0x3010;
+        fragmeta->unknown2_3 = MALI_DEPTH_FUNC(MALI_FUNC_ALWAYS) | 0x10;
         fragmeta->unknown2_4 = 0x4e0;
 
         /* unknown2_4 has 0x10 bit set on T6XX and T720. We don't know why this
@@ -1024,8 +1029,16 @@ panfrost_mali_viewport_init(struct panfrost_context *ctx,
         mvp->viewport0[1] = miny;
         mvp->viewport1[1] = MALI_POSITIVE(maxy);
 
-        mvp->clip_minz = minz;
-        mvp->clip_maxz = maxz;
+        bool clip_near = true;
+        bool clip_far = true;
+
+        if (ctx->rasterizer) {
+                clip_near = ctx->rasterizer->base.depth_clip_near;
+                clip_far = ctx->rasterizer->base.depth_clip_far;
+        }
+
+        mvp->clip_minz = clip_near ? minz : -INFINITY;
+        mvp->clip_maxz = clip_far ? maxz : INFINITY;
 }
 
 void
index b9872398061bf833a0ce01b686d19516e44a445a..2fe09c51ab70f2d21ab0c556cc8fe6dfa1a17cc4 100644 (file)
@@ -109,6 +109,8 @@ panfrost_get_param(struct pipe_screen *screen, enum pipe_cap param)
         case PIPE_CAP_VERTEX_SHADER_SATURATE:
         case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
         case PIPE_CAP_POINT_SPRITE:
+        case PIPE_CAP_DEPTH_CLIP_DISABLE:
+        case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
                 return 1;
 
         case PIPE_CAP_MAX_RENDER_TARGETS:
index 0fef5e420b5835654621c99db9ccc7cc1cdd4a76..f7b864e0d6479dda05c1a4d8877552c47bb323bf 100644 (file)
@@ -104,6 +104,9 @@ enum mali_func {
 
 #define MALI_DEPTH_WRITEMASK    (1 << 11)
 
+#define MALI_DEPTH_CLIP_NEAR    (1 << 12)
+#define MALI_DEPTH_CLIP_FAR     (1 << 13)
+
 /* Next flags to unknown2_4 */
 #define MALI_STENCIL_TEST              (1 << 0)
 
index 8358603feaf72435ebcef9a60ad62b8af2dbd00f..76352173b933d2dcfb2dfcb4503f6b8c6df13e58 100644 (file)
@@ -226,6 +226,8 @@ static const struct pandecode_flag_info u3_flag_info[] = {
         FLAG_INFO(CAN_DISCARD),
         FLAG_INFO(HAS_BLEND_SHADER),
         FLAG_INFO(DEPTH_WRITEMASK),
+        FLAG_INFO(DEPTH_CLIP_NEAR),
+        FLAG_INFO(DEPTH_CLIP_FAR),
         {}
 };