From 49337ec410ae5a8d6e9282e2fefc43c9d638a5e8 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Sat, 7 Aug 2021 00:20:59 +0200 Subject: [PATCH] gallium: add rasterizer depth_clamp enable bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Part-of: --- docs/gallium/cso/rasterizer.rst | 13 +++++++++---- docs/gallium/screen.rst | 3 +++ src/gallium/auxiliary/util/u_screen.c | 1 + src/gallium/drivers/llvmpipe/lp_screen.c | 2 ++ src/gallium/drivers/llvmpipe/lp_state_fs.c | 4 +--- src/gallium/frontends/d3d10umd/Rasterizer.cpp | 1 + src/gallium/include/pipe/p_defines.h | 1 + src/gallium/include/pipe/p_state.h | 7 +++++++ src/mesa/state_tracker/st_atom_rasterizer.c | 1 + src/mesa/state_tracker/st_cb_drawpixels.c | 1 + 10 files changed, 27 insertions(+), 7 deletions(-) diff --git a/docs/gallium/cso/rasterizer.rst b/docs/gallium/cso/rasterizer.rst index e75f5886d82..48986c07f43 100644 --- a/docs/gallium/cso/rasterizer.rst +++ b/docs/gallium/cso/rasterizer.rst @@ -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, diff --git a/docs/gallium/screen.rst b/docs/gallium/screen.rst index 879714fd403..279ef397f10 100644 --- a/docs/gallium/screen.rst +++ b/docs/gallium/screen.rst @@ -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 diff --git a/src/gallium/auxiliary/util/u_screen.c b/src/gallium/auxiliary/util/u_screen.c index f682eede342..8c519ba4e5a 100644 --- a/src/gallium/auxiliary/util/u_screen.c +++ b/src/gallium/auxiliary/util/u_screen.c @@ -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: diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c index bedf7bb6fb3..59d2cf633cf 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.c +++ b/src/gallium/drivers/llvmpipe/lp_screen.c @@ -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: diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 400eafe9e5a..23416b958e3 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -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 || diff --git a/src/gallium/frontends/d3d10umd/Rasterizer.cpp b/src/gallium/frontends/d3d10umd/Rasterizer.cpp index df127c793c5..48c9f75a4e7 100644 --- a/src/gallium/frontends/d3d10umd/Rasterizer.cpp +++ b/src/gallium/frontends/d3d10umd/Rasterizer.cpp @@ -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; diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index 6f4fd7e7e06..908b74e8509 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -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, diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 785a5906237..63833a8b19f 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -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). diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c index d03b1b3f5c6..f4a788eea65 100644 --- a/src/mesa/state_tracker/st_atom_rasterizer.c +++ b/src/mesa/state_tracker/st_atom_rasterizer.c @@ -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); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index d3a392ca2c4..c7c8f94aab4 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -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); }