From: Gert Wollny Date: Thu, 25 Jul 2019 08:38:24 +0000 (+0200) Subject: mesa/st: Add depth clamping to rasterizer code X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d004fcc04a52dd53c4e7008f55c5a9a2d8101ad5;p=mesa.git mesa/st: Add depth clamping to rasterizer code implemented by Erik Faye-Lund v2: Use current depth range values for clamping (Erik) v3: fix scons-win64 build Signed-off-by: Gert Wollny Reviewed-by: Reviewed-by: Marek Olšák --- diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c index 0d7d4c16fa6..b1ac4b3f133 100644 --- a/src/mesa/state_tracker/st_atom_rasterizer.c +++ b/src/mesa/state_tracker/st_atom_rasterizer.c @@ -295,8 +295,10 @@ st_update_rasterizer(struct st_context *st) } /* _NEW_TRANSFORM */ - raster->depth_clip_near = !ctx->Transform.DepthClampNear; - raster->depth_clip_far = !ctx->Transform.DepthClampFar; + raster->depth_clip_near = st->clamp_frag_depth_in_shader || + !ctx->Transform.DepthClampNear; + raster->depth_clip_far = st->clamp_frag_depth_in_shader || + !ctx->Transform.DepthClampFar; 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 ffbeae9fd7a..6c650fd1962 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -787,8 +787,10 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z, ctx->Color._ClampFragmentColor; rasterizer.half_pixel_center = 1; rasterizer.bottom_edge_rule = 1; - rasterizer.depth_clip_near = !ctx->Transform.DepthClampNear; - rasterizer.depth_clip_far = !ctx->Transform.DepthClampFar; + rasterizer.depth_clip_near = st->clamp_frag_depth_in_shader || + !ctx->Transform.DepthClampNear; + rasterizer.depth_clip_far = st->clamp_frag_depth_in_shader || + !ctx->Transform.DepthClampFar; rasterizer.scissor = ctx->Scissor.EnableFlags; cso_set_rasterizer(cso, &rasterizer); } @@ -1260,6 +1262,34 @@ setup_sampler_swizzle(struct pipe_sampler_view *sv, GLenum format, GLenum type) } +/** + * Compute the effective raster z position. This performs depth-clamping + * if needed. + */ +static float +get_effective_raster_z(struct gl_context *ctx) +{ + float z = ctx->Current.RasterPos[2]; + if (st_context(ctx)->clamp_frag_depth_in_shader) { + GLfloat depth_near; + GLfloat depth_far; + if (ctx->ViewportArray[0].Near < ctx->ViewportArray[0].Far) { + depth_near = ctx->ViewportArray[0].Near; + depth_far = ctx->ViewportArray[0].Far; + } else { + depth_near = ctx->ViewportArray[0].Far; + depth_far = ctx->ViewportArray[0].Near; + } + + if (ctx->Transform.DepthClampNear) + z = MAX2(z, depth_near); + if (ctx->Transform.DepthClampFar) + z = MIN2(z, depth_far); + } + return z; +} + + /** * Called via ctx->Driver.DrawPixels() */ @@ -1376,7 +1406,7 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y, num_sampler_view++; } - draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2], + draw_textured_quad(ctx, x, y, get_effective_raster_z(ctx), width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY, sv, @@ -1851,7 +1881,8 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy, /* OK, the texture 'pt' contains the src image/pixels. Now draw a * textured quad with that texture. */ - draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2], + + draw_textured_quad(ctx, dstx, dsty, get_effective_raster_z(ctx), width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY, sv, num_sampler_view,