gallium: add rasterizer depth_clamp enable bit

This is required for d3d10+, which has depth_clamp always enabled
regardless of depth_clip (in contrast to OpenGL, where enabling
depth_clamp disables depth_clip). There doesn't seem to be a GL
extension for it, but it will be used for lavapipe to implement
VK_EXT_depth_clip_enable.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12260>
This commit is contained in:
Roland Scheidegger 2021-08-07 00:20:59 +02:00 committed by Marge Bot
parent 869f0a4992
commit 49337ec410
10 changed files with 27 additions and 7 deletions

View File

@ -326,10 +326,15 @@ clip_halfz
When true clip space in the z axis goes from [0..1] (D3D). When false
[-1, 1] (GL)
depth_clip
When false, the near and far depth clipping planes of the view volume are
disabled and the depth value will be clamped at the per-pixel level, after
polygon offset has been applied and before depth testing.
depth_clip_near
When false, the near depth clipping plane of the view volume is disabled.
depth_clip_far
When false, the far depth clipping plane of the view volume is disabled.
depth_clamp
Whether the depth value will be clamped to the interval defined by the
near and far depth range at the per-pixel level, after polygon offset has
been applied and before depth testing. Note that a clamp to [0,1] according
to GL rules should always happen even if this is disabled.
clip_plane_enable
For each k in [0, PIPE_MAX_CLIP_PLANES), if bit k of this field is set,

View File

@ -80,6 +80,9 @@ The integer capabilities:
disabling depth clipping (through pipe_rasterizer_state) separately for
the near and far plane. If not, depth_clip_near and depth_clip_far will be
equal.
``PIPE_CAP_DEPTH_CLAMP_ENABLE``: Whether the driver is capable of
enabling depth clamping (through pipe_rasterizer_state) separately from depth
clipping. If not, depth_clamp will be the inverse of depth_clip_far.
* ``PIPE_CAP_SHADER_STENCIL_EXPORT``: Whether a stencil reference value can be
written from a fragment shader.
* ``PIPE_CAP_TGSI_INSTANCEID``: Whether TGSI_SEMANTIC_INSTANCEID is supported

View File

@ -77,6 +77,7 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen,
case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
case PIPE_CAP_DEPTH_CLIP_DISABLE:
case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
case PIPE_CAP_DEPTH_CLAMP_ENABLE:
case PIPE_CAP_SHADER_STENCIL_EXPORT:
case PIPE_CAP_TGSI_INSTANCEID:
case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:

View File

@ -170,6 +170,8 @@ llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
return 1;
case PIPE_CAP_DEPTH_CLIP_DISABLE:
return 1;
case PIPE_CAP_DEPTH_CLAMP_ENABLE:
return 1;
case PIPE_CAP_SHADER_STENCIL_EXPORT:
return 1;
case PIPE_CAP_TGSI_INSTANCEID:

View File

@ -4165,10 +4165,8 @@ make_variant_key(struct llvmpipe_context *lp,
/*
* Propagate the depth clamp setting from the rasterizer state.
* depth_clip == 0 implies depth clamping is enabled.
*
*/
key->depth_clamp = (lp->rasterizer->depth_clip_near == 0) ? 1 : 0;
key->depth_clamp = lp->rasterizer->depth_clamp;
/* alpha test only applies if render buffer 0 is non-integer (or does not exist) */
if (!lp->framebuffer.nr_cbufs ||

View File

@ -226,6 +226,7 @@ CreateRasterizerState(
state.clip_halfz = 1;
state.depth_clip_near = pRasterizerDesc->DepthClipEnable ? 1 : 0;
state.depth_clip_far = pRasterizerDesc->DepthClipEnable ? 1 : 0;
state.depth_clamp = 1;
state.point_quad_rasterization = 1;
state.point_size = 1.0f;

View File

@ -764,6 +764,7 @@ enum pipe_cap
PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER,
PIPE_CAP_DEPTH_CLIP_DISABLE,
PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE,
PIPE_CAP_DEPTH_CLAMP_ENABLE,
PIPE_CAP_SHADER_STENCIL_EXPORT,
PIPE_CAP_TGSI_INSTANCEID,
PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR,

View File

@ -162,6 +162,13 @@ struct pipe_rasterizer_state
unsigned depth_clip_near:1;
unsigned depth_clip_far:1;
/**
* When true, depth clamp is enabled.
* If PIPE_CAP_DEPTH_CLAMP_ENABLE is unsupported, this is always the inverse
* of depth_clip_far.
*/
unsigned depth_clamp:1;
/**
* When true clip space in the z axis goes from [0..1] (D3D). When false
* [-1, 1] (GL).

View File

@ -300,6 +300,7 @@ st_update_rasterizer(struct st_context *st)
!ctx->Transform.DepthClampNear;
raster->depth_clip_far = st->clamp_frag_depth_in_shader ||
!ctx->Transform.DepthClampFar;
raster->depth_clamp = !raster->depth_clip_far;
raster->clip_plane_enable = ctx->Transform.ClipPlanesEnabled;
raster->clip_halfz = (ctx->Transform.ClipDepthMode == GL_ZERO_TO_ONE);

View File

@ -789,6 +789,7 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
!ctx->Transform.DepthClampNear;
rasterizer.depth_clip_far = st->clamp_frag_depth_in_shader ||
!ctx->Transform.DepthClampFar;
rasterizer.depth_clamp = !rasterizer.depth_clip_far;
rasterizer.scissor = ctx->Scissor.EnableFlags;
cso_set_rasterizer(cso, &rasterizer);
}