panfrost: Fix near/far depth clip

Near/far depth clip was implemented by setting the low/high_depth_clamp
to -/+INFINITY, which is invalid on Mali.

This commit removes the modification of the depth clamp values and
enables depth clipping by setting the depth_cull_enable state in the ZS
descriptor for v9+ (the equivalent pre-v9 RSD state is already set
correctly) and setting the primitive cull flags correctly for both.

Finally, it disables PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE for v9+, as
both plane clips are controlled by a single value.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11506
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31041>
This commit is contained in:
Lars-Ivar Hesselberg Simonsen 2024-09-05 12:13:06 +02:00 committed by Marge Bot
parent 5fd523fafb
commit f5dab1b77e
6 changed files with 23 additions and 9 deletions

View file

@ -741,8 +741,8 @@ panfrost_emit_viewport(struct panfrost_batch *batch)
maxx--;
maxy--;
batch->minimum_z = rast->depth_clip_near ? minz : -INFINITY;
batch->maximum_z = rast->depth_clip_far ? maxz : +INFINITY;
batch->minimum_z = minz;
batch->maximum_z = maxz;
#if PAN_ARCH <= 7
struct panfrost_ptr T = pan_pool_alloc_desc(&batch->pool.base, VIEWPORT);
@ -802,6 +802,9 @@ panfrost_emit_depth_stencil(struct panfrost_batch *batch)
cfg.depth_units = panfrost_z_depth_offset(ctx, rast->base.offset_units);
cfg.depth_factor = rast->base.offset_scale;
cfg.depth_bias_clamp = rast->base.offset_clamp;
assert(rast->base.depth_clip_near == rast->base.depth_clip_far);
cfg.depth_cull_enable = rast->base.depth_clip_near;
}
pan_merge(dynamic, zsa->desc, DEPTH_STENCIL);
@ -3512,7 +3515,9 @@ panfrost_create_depth_stencil_state(
pan_pipe_to_stencil(&front, &so->stencil_front);
pan_pipe_to_stencil(&back, &so->stencil_back);
#else
pan_pack(&so->desc, DEPTH_STENCIL, cfg) {
/* Pack with nodefaults so only explicitly set fields affect pan_merge() when
* emitting depth stencil descriptor */
pan_pack_nodefaults(&so->desc, DEPTH_STENCIL, cfg) {
cfg.front_compare_function = (enum mali_func)front.func;
cfg.front_stencil_fail = pan_pipe_to_stencil_op(front.fail_op);
cfg.front_depth_fail = pan_pipe_to_stencil_op(front.zfail_op);

View file

@ -784,6 +784,8 @@ csf_emit_draw_state(struct panfrost_batch *batch,
if (info->index_size)
cs_move64_to(b, cs_reg64(b, 54), batch->indices);
struct pipe_rasterizer_state *rast = &ctx->rasterizer->base;
uint32_t primitive_flags = 0;
pan_pack(&primitive_flags, PRIMITIVE_FLAGS, cfg) {
if (panfrost_writes_point_size(ctx))
@ -791,6 +793,9 @@ csf_emit_draw_state(struct panfrost_batch *batch,
cfg.allow_rotating_primitives = allow_rotating_primitives(fs, info);
cfg.low_depth_cull = rast->depth_clip_near;
cfg.high_depth_cull = rast->depth_clip_far;
/* Non-fixed restart indices should have been lowered */
assert(!cfg.primitive_restart || panfrost_is_implicit_prim_restart(info));
cfg.primitive_restart = info->primitive_restart;
@ -802,8 +807,6 @@ csf_emit_draw_state(struct panfrost_batch *batch,
cs_move32_to(b, cs_reg32(b, 56), primitive_flags);
struct pipe_rasterizer_state *rast = &ctx->rasterizer->base;
uint32_t dcd_flags0 = 0, dcd_flags1 = 0;
pan_pack(&dcd_flags0, DCD_FLAGS_0, cfg) {
enum mesa_prim reduced_mode = u_reduced_prim(info->mode);
@ -918,7 +921,9 @@ csf_emit_draw_state(struct panfrost_batch *batch,
cs_move64_to(b, cs_reg64(b, 60), primsize);
uint32_t flags_override;
pan_pack(&flags_override, PRIMITIVE_FLAGS, cfg) {
/* Pack with nodefaults so only explicitly set override fields affect the
* previously set register values */
pan_pack_nodefaults(&flags_override, PRIMITIVE_FLAGS, cfg) {
cfg.draw_mode = pan_draw_mode(info->mode);
cfg.index_type = panfrost_translate_index_size(info->index_size);
cfg.secondary_shader = secondary_shader;

View file

@ -694,6 +694,9 @@ jm_emit_primitive(struct panfrost_batch *batch,
assert(!cfg.primitive_restart || panfrost_is_implicit_prim_restart(info));
#endif
cfg.low_depth_cull = rast->depth_clip_near;
cfg.high_depth_cull = rast->depth_clip_far;
cfg.index_count = draw->count;
cfg.index_type = panfrost_translate_index_size(info->index_size);

View file

@ -115,7 +115,6 @@ panfrost_get_param(struct pipe_screen *screen, enum pipe_cap param)
case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD:
case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
case PIPE_CAP_DEPTH_CLIP_DISABLE:
case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
case PIPE_CAP_FRONTEND_NOOP:
case PIPE_CAP_SAMPLE_SHADING:
@ -126,6 +125,10 @@ panfrost_get_param(struct pipe_screen *screen, enum pipe_cap param)
case PIPE_CAP_HAS_CONST_BW:
return 1;
/* Removed in v9 (Valhall) */
case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
return dev->arch < 9;
case PIPE_CAP_MAX_RENDER_TARGETS:
case PIPE_CAP_FBFETCH:
case PIPE_CAP_FBFETCH_COHERENT:

View file

@ -14,7 +14,6 @@ shaders@point-vertex-id gl_vertexid,Fail
shaders@point-vertex-id gl_vertexid gl_instanceid divisor,Fail
shaders@point-vertex-id gl_vertexid gl_instanceid,Fail
spec@arb_base_instance@arb_base_instance-drawarrays,Fail
spec@arb_depth_clamp@depth-clamp-range,Fail
spec@arb_direct_state_access@gettextureimage-formats,Fail
spec@arb_direct_state_access@gettextureimage-formats init-by-rendering,Fail
spec@arb_point_sprite@arb_point_sprite-mipmap,Fail

View file

@ -24,7 +24,6 @@ shaders@point-vertex-id gl_vertexid,Fail
shaders@point-vertex-id gl_vertexid gl_instanceid divisor,Fail
shaders@point-vertex-id gl_vertexid gl_instanceid,Fail
spec@arb_base_instance@arb_base_instance-drawarrays,Fail
spec@arb_depth_clamp@depth-clamp-range,Fail
spec@arb_direct_state_access@gettextureimage-formats,Fail
spec@arb_direct_state_access@gettextureimage-formats init-by-rendering,Fail
spec@arb_point_sprite@arb_point_sprite-mipmap,Fail