On Tue, Aug 21, 2018 at 8:02 PM Sagar Ghuge <sagar.gh...@intel.com> wrote: > > Enable _mesa_PushAttrib() and _mesa_PopAttrib() to handle > GL_DEPTH_CLAMP_NEAR_AMD and GL_DEPTH_CLAMP_FAR_AMD tokens. > > Remove DepthClamp, because DepthClampNear + DepthClampFar replaces it, > as suggested by Marek Olsak. > > Driver that enables AMD_depth_clamp_separate will only ever look at > DepthClampNear and DepthClampFar, as suggested by Ian Romanick. > > Signed-off-by: Sagar Ghuge <sagar.gh...@intel.com> > --- > src/mesa/drivers/dri/i965/genX_state_upload.c | 11 ++++++---- > src/mesa/main/attrib.c | 21 ++++++++++++------- > src/mesa/main/enable.c | 9 +++++--- > src/mesa/main/get.c | 4 ++++ > src/mesa/main/get_hash_params.py | 2 +- > src/mesa/main/mtypes.h | 1 - > src/mesa/main/rastpos.c | 6 ++++-- > src/mesa/state_tracker/st_atom_rasterizer.c | 3 ++- > src/mesa/state_tracker/st_cb_drawpixels.c | 3 ++- > src/mesa/swrast/s_span.c | 2 +- > src/mesa/tnl/t_vb_program.c | 6 ++++-- > src/mesa/tnl/t_vb_vertex.c | 8 ++++--- > 12 files changed, 50 insertions(+), 26 deletions(-) > > diff --git a/src/mesa/drivers/dri/i965/genX_state_upload.c > b/src/mesa/drivers/dri/i965/genX_state_upload.c > index c051848985..dc54cb67af 100644 > --- a/src/mesa/drivers/dri/i965/genX_state_upload.c > +++ b/src/mesa/drivers/dri/i965/genX_state_upload.c > @@ -1399,7 +1399,8 @@ genX(upload_clip_state)(struct brw_context *brw) > clip.ScreenSpaceViewportYMax = 1; > > clip.ViewportXYClipTestEnable = true; > - clip.ViewportZClipTestEnable = !ctx->Transform.DepthClamp; > + clip.ViewportZClipTestEnable = !(ctx->Transform.DepthClampNear && > + ctx->Transform.DepthClampFar); > > /* _NEW_TRANSFORM */ > if (GEN_GEN == 5 || GEN_IS_G4X) { > @@ -1493,7 +1494,8 @@ genX(upload_clip_state)(struct brw_context *brw) > clip.UserClipDistanceCullTestEnableBitmask = > brw_vue_prog_data(brw->vs.base.prog_data)->cull_distance_mask; > > - clip.ViewportZClipTestEnable = !ctx->Transform.DepthClamp; > + clip.ViewportZClipTestEnable = !(ctx->Transform.DepthClampNear && > + ctx->Transform.DepthClampFar); > #endif > > /* _NEW_LIGHT */ > @@ -2338,7 +2340,7 @@ genX(upload_cc_viewport)(struct brw_context *brw) > for (unsigned i = 0; i < viewport_count; i++) { > /* _NEW_VIEWPORT | _NEW_TRANSFORM */ > const struct gl_viewport_attrib *vp = &ctx->ViewportArray[i]; > - if (ctx->Transform.DepthClamp) { > + if (ctx->Transform.DepthClampNear && ctx->Transform.DepthClampFar) { > ccv.MinimumDepth = MIN2(vp->Near, vp->Far); > ccv.MaximumDepth = MAX2(vp->Near, vp->Far); > } else { > @@ -4605,7 +4607,8 @@ genX(upload_raster)(struct brw_context *brw) > raster.ScissorRectangleEnable = ctx->Scissor.EnableFlags; > > /* _NEW_TRANSFORM */ > - if (!ctx->Transform.DepthClamp) { > + if (!(ctx->Transform.DepthClampNear && > + ctx->Transform.DepthClampFar)) { > #if GEN_GEN >= 9 > raster.ViewportZFarClipTestEnable = true; > raster.ViewportZNearClipTestEnable = true; > diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c > index cbe93ab6fa..cce5d8582e 100644 > --- a/src/mesa/main/attrib.c > +++ b/src/mesa/main/attrib.c > @@ -72,7 +72,8 @@ struct gl_enable_attrib > GLbitfield ClipPlanes; > GLboolean ColorMaterial; > GLboolean CullFace; > - GLboolean DepthClamp; > + GLboolean DepthClampNear; > + GLboolean DepthClampFar; > GLboolean DepthTest; > GLboolean Dither; > GLboolean Fog; > @@ -336,7 +337,8 @@ _mesa_PushAttrib(GLbitfield mask) > attr->ClipPlanes = ctx->Transform.ClipPlanesEnabled; > attr->ColorMaterial = ctx->Light.ColorMaterialEnabled; > attr->CullFace = ctx->Polygon.CullFlag; > - attr->DepthClamp = ctx->Transform.DepthClamp; > + attr->DepthClampNear = ctx->Transform.DepthClampNear; > + attr->DepthClampFar = ctx->Transform.DepthClampFar; > attr->DepthTest = ctx->Depth.Test; > attr->Dither = ctx->Color.DitherFlag; > attr->Fog = ctx->Fog.Enabled; > @@ -627,8 +629,10 @@ pop_enable_group(struct gl_context *ctx, const struct > gl_enable_attrib *enable) > TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled, enable->ColorMaterial, > GL_COLOR_MATERIAL); > TEST_AND_UPDATE(ctx->Polygon.CullFlag, enable->CullFace, GL_CULL_FACE); > - TEST_AND_UPDATE(ctx->Transform.DepthClamp, enable->DepthClamp, > - GL_DEPTH_CLAMP); > + TEST_AND_UPDATE(ctx->Transform.DepthClampNear, enable->DepthClampNear, > + GL_DEPTH_CLAMP_NEAR_AMD); > + TEST_AND_UPDATE(ctx->Transform.DepthClampFar, enable->DepthClampFar, > + GL_DEPTH_CLAMP_FAR_AMD);
If AMD_depth_clamp_separate is unsupported, this should use GL_DEPTH_CLAMP only. > TEST_AND_UPDATE(ctx->Depth.Test, enable->DepthTest, GL_DEPTH_TEST); > TEST_AND_UPDATE(ctx->Color.DitherFlag, enable->Dither, GL_DITHER); > TEST_AND_UPDATE(ctx->Fog.Enabled, enable->Fog, GL_FOG); > @@ -1433,9 +1437,12 @@ _mesa_PopAttrib(void) > if (xform->RescaleNormals != ctx->Transform.RescaleNormals) > _mesa_set_enable(ctx, GL_RESCALE_NORMAL_EXT, > ctx->Transform.RescaleNormals); > - if (xform->DepthClamp != ctx->Transform.DepthClamp) > - _mesa_set_enable(ctx, GL_DEPTH_CLAMP, > - ctx->Transform.DepthClamp); > + if (xform->DepthClampNear != ctx->Transform.DepthClampNear) > + _mesa_set_enable(ctx, GL_DEPTH_CLAMP_NEAR_AMD, > + ctx->Transform.DepthClampNear); > + if (xform->DepthClampFar != ctx->Transform.DepthClampFar) > + _mesa_set_enable(ctx, GL_DEPTH_CLAMP_FAR_AMD, > + ctx->Transform.DepthClampFar); Same here. > if (ctx->Extensions.ARB_clip_control) > _mesa_ClipControl(xform->ClipOrigin, xform->ClipDepthMode); > } > diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c > index d1b2f3a962..4bde9052bc 100644 > --- a/src/mesa/main/enable.c > +++ b/src/mesa/main/enable.c > @@ -1007,12 +1007,14 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, > GLboolean state) > if (!_mesa_is_desktop_gl(ctx)) > goto invalid_enum_error; > CHECK_EXTENSION(ARB_depth_clamp, cap); > - if (ctx->Transform.DepthClamp == state) > + if (ctx->Transform.DepthClampNear == state && > + ctx->Transform.DepthClampFar == state) > return; > FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepthClamp ? 0 : > _NEW_TRANSFORM); > ctx->NewDriverState |= ctx->DriverFlags.NewDepthClamp; > - ctx->Transform.DepthClamp = state; > + ctx->Transform.DepthClampNear = state; > + ctx->Transform.DepthClampFar = state; > break; > > case GL_FRAGMENT_SHADER_ATI: > @@ -1684,7 +1686,8 @@ _mesa_IsEnabled( GLenum cap ) > if (!_mesa_is_desktop_gl(ctx)) > goto invalid_enum_error; > CHECK_EXTENSION(ARB_depth_clamp); > - return ctx->Transform.DepthClamp; > + return (ctx->Transform.DepthClampNear || > + ctx->Transform.DepthClampFar); > > case GL_FRAGMENT_SHADER_ATI: > if (ctx->API != API_OPENGL_COMPAT) > diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c > index f870b217db..6b2e3637e6 100644 > --- a/src/mesa/main/get.c > +++ b/src/mesa/main/get.c > @@ -698,6 +698,10 @@ find_custom_value(struct gl_context *ctx, const struct > value_desc *d, union valu > v->value_int_4[3] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3); > break; > > + case GL_DEPTH_CLAMP: > + v->value_bool = (ctx->Transform.DepthClampNear || > ctx->Transform.DepthClampFar); Unnecessary parentheses here and elsewhere, though this is not too important. > + break; > + > case GL_EDGE_FLAG: > v->value_bool = ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0] == 1.0F; > break; > diff --git a/src/mesa/main/get_hash_params.py > b/src/mesa/main/get_hash_params.py > index 5c672a3312..ae1fc6f062 100644 > --- a/src/mesa/main/get_hash_params.py > +++ b/src/mesa/main/get_hash_params.py > @@ -903,7 +903,7 @@ descriptor=[ > [ "DEPTH_BOUNDS_EXT", "CONTEXT_FLOAT2(Depth.BoundsMin), > extra_EXT_depth_bounds_test" ], > > # GL_ARB_depth_clamp > - [ "DEPTH_CLAMP", "CONTEXT_BOOL(Transform.DepthClamp), > extra_ARB_depth_clamp" ], > + [ "DEPTH_CLAMP", "LOC_CUSTOM, TYPE_BOOLEAN, 0, extra_ARB_depth_clamp" ], > > # GL_ATI_fragment_shader > [ "FRAGMENT_SHADER_ATI", "CONTEXT_BOOL(ATIFragmentShader.Enabled), > extra_ATI_fragment_shader" ], > diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h > index 3df657cc5d..eb4ccc1804 100644 > --- a/src/mesa/main/mtypes.h > +++ b/src/mesa/main/mtypes.h > @@ -1282,7 +1282,6 @@ struct gl_transform_attrib > GLboolean Normalize; /**< Normalize all > normals? */ > GLboolean RescaleNormals; /**< GL_EXT_rescale_normal */ > GLboolean RasterPositionUnclipped; /**< GL_IBM_rasterpos_clip */ > - GLboolean DepthClamp; /**< GL_ARB_depth_clamp */ > GLboolean DepthClampNear; /**< > GL_AMD_depth_clamp_separate */ > GLboolean DepthClampFar; /**< > GL_AMD_depth_clamp_separate */ > /** GL_ARB_clip_control */ > diff --git a/src/mesa/main/rastpos.c b/src/mesa/main/rastpos.c > index 1ca83c78b0..fb437c52b2 100644 > --- a/src/mesa/main/rastpos.c > +++ b/src/mesa/main/rastpos.c > @@ -389,7 +389,8 @@ _mesa_RasterPos(struct gl_context *ctx, const GLfloat > vObj[4]) > TRANSFORM_POINT( clip, ctx->ProjectionMatrixStack.Top->m, eye ); > > /* clip to view volume. */ > - if (!ctx->Transform.DepthClamp) { > + if (!(ctx->Transform.DepthClampNear && > + ctx->Transform.DepthClampFar)) { > if (viewclip_point_z(clip) == 0) { viewclip_point_z needs to be split and test the near and far planes separately. > ctx->Current.RasterPosValid = GL_FALSE; > return; > @@ -420,7 +421,8 @@ _mesa_RasterPos(struct gl_context *ctx, const GLfloat > vObj[4]) > ctx->Current.RasterPos[2] = ndc[2] * scale[2] + translate[2]; > ctx->Current.RasterPos[3] = clip[3]; > > - if (ctx->Transform.DepthClamp) { > + if (ctx->Transform.DepthClampNear && > + ctx->Transform.DepthClampFar) { > ctx->Current.RasterPos[3] = CLAMP(ctx->Current.RasterPos[3], Instead of CLAMP, MIN2 and MAX2 should be used to clamp against the near and far planes separately. The remaining code is OK. Marek _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev