Fix polygon offset depth clamp and units resolution.
OpenGL requires depth values to be clamped to the [0, 1] range. Due to
frustum clipping already limiting the range, this can only happen when
non-zero polygon offset parameters are active.
Also fix the 'minimum resolvable difference' for the 32-bit floating-
point internal depth format that we use.
Bug swiftshader:82
Change-Id: Ic9ebcac182a2bc81ab51d79cfe0bb451d340bd1e
Reviewed-on: https://swiftshader-review.googlesource.com/12108
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Renderer/Context.cpp b/src/Renderer/Context.cpp
index e5ee4dc..45ad436 100644
--- a/src/Renderer/Context.cpp
+++ b/src/Renderer/Context.cpp
@@ -276,6 +276,9 @@
cullMode = CULL_CLOCKWISE;
alphaReference = 0.0f;
+ depthBias = 0.0f;
+ slopeDepthBias = 0.0f;
+
for(int i = 0; i < RENDERTARGETS; i++)
{
colorWriteMask[i] = 0x0000000F;
diff --git a/src/Renderer/Context.hpp b/src/Renderer/Context.hpp
index 640ec4e..6116794 100644
--- a/src/Renderer/Context.hpp
+++ b/src/Renderer/Context.hpp
@@ -434,6 +434,9 @@
CullMode cullMode;
float alphaReference;
+ float depthBias;
+ float slopeDepthBias;
+
TextureStage textureStage[8];
Sampler sampler[TOTAL_IMAGE_UNITS];
diff --git a/src/Renderer/PixelProcessor.cpp b/src/Renderer/PixelProcessor.cpp
index db11aed..abf6593 100644
--- a/src/Renderer/PixelProcessor.cpp
+++ b/src/Renderer/PixelProcessor.cpp
@@ -990,6 +990,7 @@
state.pixelFogMode = context->pixelFogActive();
state.wBasedFog = context->wBasedFog && context->pixelFogActive() != FOG_NONE;
state.perspective = context->perspectiveActive();
+ state.depthClamp = (context->depthBias != 0.0f) || (context->slopeDepthBias != 0.0f);
if(context->alphaBlendActive())
{
diff --git a/src/Renderer/PixelProcessor.hpp b/src/Renderer/PixelProcessor.hpp
index 65f6b92..d3b0602 100644
--- a/src/Renderer/PixelProcessor.hpp
+++ b/src/Renderer/PixelProcessor.hpp
@@ -66,6 +66,7 @@
bool occlusionEnabled : 1;
bool wBasedFog : 1;
bool perspective : 1;
+ bool depthClamp : 1;
bool alphaBlendActive : 1;
BlendFactor sourceBlendFactor : BITS(BLEND_LAST);
diff --git a/src/Renderer/Renderer.cpp b/src/Renderer/Renderer.cpp
index 32e2027..0869697 100644
--- a/src/Renderer/Renderer.cpp
+++ b/src/Renderer/Renderer.cpp
@@ -545,7 +545,7 @@
if(context->isDrawTriangle(false))
{
- N += depthBias;
+ N += context->depthBias;
}
if(complementaryDepthBuffer)
@@ -583,7 +583,7 @@
data->halfPixelX = replicate(0.5f / W);
data->halfPixelY = replicate(0.5f / H);
data->viewportHeight = abs(viewport.height);
- data->slopeDepthBias = slopeDepthBias;
+ data->slopeDepthBias = context->slopeDepthBias;
data->depthRange = Z;
data->depthNear = N;
draw->clipFlags = clipFlags;
@@ -2447,12 +2447,12 @@
void Renderer::setDepthBias(float bias)
{
- depthBias = bias;
+ context->depthBias = bias;
}
void Renderer::setSlopeDepthBias(float slopeBias)
{
- slopeDepthBias = slopeBias;
+ context->slopeDepthBias = slopeBias;
}
void Renderer::setRasterizerDiscard(bool rasterizerDiscard)
diff --git a/src/Renderer/SetupProcessor.cpp b/src/Renderer/SetupProcessor.cpp
index 772327f..bc456e9 100644
--- a/src/Renderer/SetupProcessor.cpp
+++ b/src/Renderer/SetupProcessor.cpp
@@ -85,7 +85,7 @@
state.pointSprite = context->pointSpriteActive();
state.cullMode = context->cullMode;
state.twoSidedStencil = context->stencilActive() && context->twoSidedStencil;
- state.slopeDepthBias = slopeDepthBias != 0.0f;
+ state.slopeDepthBias = context->slopeDepthBias != 0.0f;
state.vFace = context->pixelShader && context->pixelShader->isVFaceDeclared();
state.positionRegister = Pos;
diff --git a/src/Renderer/SetupProcessor.hpp b/src/Renderer/SetupProcessor.hpp
index 2750d4c..be0adc7 100644
--- a/src/Renderer/SetupProcessor.hpp
+++ b/src/Renderer/SetupProcessor.hpp
@@ -95,9 +95,6 @@
void setRoutineCacheSize(int cacheSize);
- float depthBias;
- float slopeDepthBias;
-
private:
Context *const context;