From: Icecream95 Date: Thu, 14 May 2020 03:58:04 +0000 (+1200) Subject: panfrost: Implement ARB_depth_clamp X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ec628aba76e3526d85938ec12870267c34806a1d;p=mesa.git panfrost: Implement ARB_depth_clamp This significantly improves the quality of shadows in OpenMW. Reviewed-by: Alyssa Rosenzweig Part-of: --- diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index aa82d0ca339..0ea5bc0e16a 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -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 diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c index b9872398061..2fe09c51ab7 100644 --- a/src/gallium/drivers/panfrost/pan_screen.c +++ b/src/gallium/drivers/panfrost/pan_screen.c @@ -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: diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h index 0fef5e420b5..f7b864e0d64 100644 --- a/src/panfrost/include/panfrost-job.h +++ b/src/panfrost/include/panfrost-job.h @@ -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) diff --git a/src/panfrost/pandecode/decode.c b/src/panfrost/pandecode/decode.c index 8358603feaf..76352173b93 100644 --- a/src/panfrost/pandecode/decode.c +++ b/src/panfrost/pandecode/decode.c @@ -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), {} };