summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends
diff options
context:
space:
mode:
authorJules Blok <jules.blok@gmail.com>2016-11-23 23:25:44 +0100
committerJules Blok <jules.blok@gmail.com>2016-12-27 14:31:17 +0100
commitef82aebb971f5fd792e93facbfcb7b5bf757776c (patch)
tree3c923c01d898aefa981040f18a5503e785c7dc57 /Source/Core/VideoBackends
parent8e506cb974521017e2563821221784eb54cf8e98 (diff)
VideoCommon: Don't process the depth range in the vertex shader if it's not oversized.
Diffstat (limited to 'Source/Core/VideoBackends')
-rw-r--r--Source/Core/VideoBackends/D3D/Render.cpp11
-rw-r--r--Source/Core/VideoBackends/D3D12/Render.cpp11
-rw-r--r--Source/Core/VideoBackends/OGL/Render.cpp22
-rw-r--r--Source/Core/VideoBackends/Vulkan/Renderer.cpp29
4 files changed, 35 insertions, 38 deletions
diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp
index df9335265a..1877fde9d7 100644
--- a/Source/Core/VideoBackends/D3D/Render.cpp
+++ b/Source/Core/VideoBackends/D3D/Render.cpp
@@ -559,6 +559,10 @@ void Renderer::SetViewport()
float Y = Renderer::EFBToScaledYf(xfmem.viewport.yOrig + xfmem.viewport.ht - scissorYOff);
float Wd = Renderer::EFBToScaledXf(2.0f * xfmem.viewport.wd);
float Ht = Renderer::EFBToScaledYf(-2.0f * xfmem.viewport.ht);
+ float range = MathUtil::Clamp<float>(xfmem.viewport.zRange, 0.0f, 16777216.0f);
+ float min_depth =
+ MathUtil::Clamp<float>(xfmem.viewport.farZ - range, 0.0f, 16777215.0f) / 16777216.0f;
+ float max_depth = MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f;
if (Wd < 0.0f)
{
X += Wd;
@@ -569,6 +573,11 @@ void Renderer::SetViewport()
Y += Ht;
Ht = -Ht;
}
+ if (xfmem.viewport.zRange < 0.0f)
+ {
+ min_depth = 1.0f - min_depth;
+ max_depth = 1.0f - max_depth;
+ }
// In D3D, the viewport rectangle must fit within the render target.
X = (X >= 0.f) ? X : 0.f;
@@ -581,7 +590,7 @@ void Renderer::SetViewport()
// the maximum value supported by the console GPU. We also need to account for the
// fact that the entire depth buffer is inverted on D3D, so we set GX_MAX_DEPTH as
// an inverted near value.
- D3D11_VIEWPORT vp = CD3D11_VIEWPORT(X, Y, Wd, Ht, 1.0f - GX_MAX_DEPTH, D3D11_MAX_DEPTH);
+ D3D11_VIEWPORT vp = CD3D11_VIEWPORT(X, Y, Wd, Ht, 1.0f - max_depth, 1.0f - min_depth);
D3D::context->RSSetViewports(1, &vp);
}
diff --git a/Source/Core/VideoBackends/D3D12/Render.cpp b/Source/Core/VideoBackends/D3D12/Render.cpp
index d5a2baa661..ce22583c68 100644
--- a/Source/Core/VideoBackends/D3D12/Render.cpp
+++ b/Source/Core/VideoBackends/D3D12/Render.cpp
@@ -464,6 +464,10 @@ void Renderer::SetViewport()
float y = Renderer::EFBToScaledYf(xfmem.viewport.yOrig + xfmem.viewport.ht - scissor_y_offset);
float width = Renderer::EFBToScaledXf(2.0f * xfmem.viewport.wd);
float height = Renderer::EFBToScaledYf(-2.0f * xfmem.viewport.ht);
+ float range = MathUtil::Clamp<float>(xfmem.viewport.zRange, 0.0f, 16777216.0f);
+ float min_depth =
+ MathUtil::Clamp<float>(xfmem.viewport.farZ - range, 0.0f, 16777215.0f) / 16777216.0f;
+ float max_depth = MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f;
if (width < 0.0f)
{
x += width;
@@ -474,6 +478,11 @@ void Renderer::SetViewport()
y += height;
height = -height;
}
+ if (xfmem.viewport.zRange < 0.0f)
+ {
+ min_depth = 1.0f - min_depth;
+ max_depth = 1.0f - max_depth;
+ }
// In D3D, the viewport rectangle must fit within the render target.
x = (x >= 0.f) ? x : 0.f;
@@ -486,7 +495,7 @@ void Renderer::SetViewport()
// the maximum value supported by the console GPU. We also need to account for the
// fact that the entire depth buffer is inverted on D3D, so we set GX_MAX_DEPTH as
// an inverted near value.
- D3D12_VIEWPORT vp = {x, y, width, height, 1.0f - GX_MAX_DEPTH, D3D12_MAX_DEPTH};
+ D3D12_VIEWPORT vp = {x, y, width, height, 1.0f - max_depth, 1.0f - min_depth};
D3D::current_command_list->RSSetViewports(1, &vp);
}
diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp
index c3416f2b4d..f49e501ff0 100644
--- a/Source/Core/VideoBackends/OGL/Render.cpp
+++ b/Source/Core/VideoBackends/OGL/Render.cpp
@@ -1122,12 +1122,10 @@ void Renderer::SetViewport()
(float)scissorYOff);
float Width = EFBToScaledXf(2.0f * xfmem.viewport.wd);
float Height = EFBToScaledYf(-2.0f * xfmem.viewport.ht);
- float GLNear = MathUtil::Clamp<float>(
- xfmem.viewport.farZ -
- MathUtil::Clamp<float>(xfmem.viewport.zRange, -16777216.0f, 16777216.0f),
- 0.0f, 16777215.0f) /
- 16777216.0f;
- float GLFar = MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f;
+ float range = MathUtil::Clamp<float>(xfmem.viewport.zRange, -16777216.0f, 16777216.0f);
+ float min_depth =
+ MathUtil::Clamp<float>(xfmem.viewport.farZ - range, 0.0f, 16777215.0f) / 16777216.0f;
+ float max_depth = MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f;
if (Width < 0)
{
X += Width;
@@ -1154,17 +1152,7 @@ void Renderer::SetViewport()
// vertex shader we only need to ensure depth values don't exceed the maximum
// value supported by the console GPU. If not, we simply clamp the near/far values
// themselves to the maximum value as done above.
- if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
- {
- if (xfmem.viewport.zRange < 0.0f)
- glDepthRangef(0.0f, GX_MAX_DEPTH);
- else
- glDepthRangef(GX_MAX_DEPTH, 0.0f);
- }
- else
- {
- glDepthRangef(GLFar, GLNear);
- }
+ glDepthRangef(max_depth, min_depth);
}
void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable,
diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp
index 9c558aa9f9..a375d89012 100644
--- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp
+++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp
@@ -1635,6 +1635,10 @@ void Renderer::SetViewport()
float y = Renderer::EFBToScaledYf(xfmem.viewport.yOrig + xfmem.viewport.ht - scissor_y_offset);
float width = Renderer::EFBToScaledXf(2.0f * xfmem.viewport.wd);
float height = Renderer::EFBToScaledYf(-2.0f * xfmem.viewport.ht);
+ float range = MathUtil::Clamp<float>(xfmem.viewport.zRange, -16777216.0f, 16777216.0f);
+ float min_depth =
+ MathUtil::Clamp<float>(xfmem.viewport.farZ - range, 0.0f, 16777215.0f) / 16777216.0f;
+ float max_depth = MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f;
if (width < 0.0f)
{
x += width;
@@ -1645,29 +1649,16 @@ void Renderer::SetViewport()
y += height;
height = -height;
}
+ if (xfmem.viewport.zRange < 0.0f)
+ {
+ min_depth = 1.0f - min_depth;
+ max_depth = 1.0f - max_depth;
+ }
// If we do depth clipping and depth range in the vertex shader we only need to ensure
// depth values don't exceed the maximum value supported by the console GPU. If not,
// we simply clamp the near/far values themselves to the maximum value as done above.
- float min_depth, max_depth;
- if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
- {
- min_depth = 1.0f - GX_MAX_DEPTH;
- max_depth = 1.0f;
- }
- else
- {
- float near_val = MathUtil::Clamp<float>(xfmem.viewport.farZ -
- MathUtil::Clamp<float>(xfmem.viewport.zRange,
- -16777216.0f, 16777216.0f),
- 0.0f, 16777215.0f) /
- 16777216.0f;
- float far_val = MathUtil::Clamp<float>(xfmem.viewport.farZ, 0.0f, 16777215.0f) / 16777216.0f;
- min_depth = near_val;
- max_depth = far_val;
- }
-
- VkViewport viewport = {x, y, width, height, min_depth, max_depth};
+ VkViewport viewport = {x, y, width, height, 1.0f - max_depth, 1.0f - min_depth};
StateTracker::GetInstance()->SetViewport(viewport);
}