mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-25 07:09:48 -06:00
VideoBackends: Set the maximum range when the depth range is oversized.
The depth values generated by the vertex shader need to be clamped correctly.
This commit is contained in:
@ -576,10 +576,12 @@ void Renderer::SetViewport()
|
|||||||
Ht = -Ht;
|
Ht = -Ht;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If an inverted depth range is used, which D3D doesn't support,
|
// If an inverted or oversized depth range is used, we need to calculate the depth range in the
|
||||||
// we need to calculate the depth range in the vertex shader.
|
// vertex shader.
|
||||||
if (xfmem.viewport.zRange < 0.0f)
|
if (xfmem.viewport.zRange < 0.0f || fabs(xfmem.viewport.zRange) > 16777215.0f ||
|
||||||
|
fabs(xfmem.viewport.farZ) > 16777215.0f)
|
||||||
{
|
{
|
||||||
|
// We need to ensure depth values are clamped the maximum value supported by the console GPU.
|
||||||
min_depth = 0.0f;
|
min_depth = 0.0f;
|
||||||
max_depth = GX_MAX_DEPTH;
|
max_depth = GX_MAX_DEPTH;
|
||||||
}
|
}
|
||||||
|
@ -481,10 +481,12 @@ void Renderer::SetViewport()
|
|||||||
height = -height;
|
height = -height;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If an inverted depth range is used, which D3D doesn't support,
|
// If an inverted or oversized depth range is used, we need to calculate the depth range in the
|
||||||
// we need to calculate the depth range in the vertex shader.
|
// vertex shader.
|
||||||
if (xfmem.viewport.zRange < 0.0f)
|
if (xfmem.viewport.zRange < 0.0f || fabs(xfmem.viewport.zRange) > 16777215.0f ||
|
||||||
|
fabs(xfmem.viewport.farZ) > 16777215.0f)
|
||||||
{
|
{
|
||||||
|
// We need to ensure depth values are clamped the maximum value supported by the console GPU.
|
||||||
min_depth = 0.0f;
|
min_depth = 0.0f;
|
||||||
max_depth = GX_MAX_DEPTH;
|
max_depth = GX_MAX_DEPTH;
|
||||||
}
|
}
|
||||||
|
@ -1123,6 +1123,24 @@ void Renderer::SetViewport()
|
|||||||
Height *= -1;
|
Height *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If an oversized depth range is used, we need to calculate the depth range in the vertex shader.
|
||||||
|
if (g_ActiveConfig.backend_info.bSupportsDepthClamp &&
|
||||||
|
(fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f))
|
||||||
|
{
|
||||||
|
// We need to ensure depth values are clamped the maximum value supported by the console GPU.
|
||||||
|
// Taking into account whether the depth range is inverted or not.
|
||||||
|
if (xfmem.viewport.zRange < 0.0f)
|
||||||
|
{
|
||||||
|
min_depth = GX_MAX_DEPTH;
|
||||||
|
max_depth = 0.0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
min_depth = 0.0f;
|
||||||
|
max_depth = GX_MAX_DEPTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update the view port
|
// Update the view port
|
||||||
if (g_ogl_config.bSupportViewportFloat)
|
if (g_ogl_config.bSupportViewportFloat)
|
||||||
{
|
{
|
||||||
@ -1134,10 +1152,7 @@ void Renderer::SetViewport()
|
|||||||
glViewport(iceilf(X), iceilf(Y), iceilf(Width), iceilf(Height));
|
glViewport(iceilf(X), iceilf(Y), iceilf(Width), iceilf(Height));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the reversed depth range. If we do depth clipping and depth range in the
|
// Set the reversed depth range.
|
||||||
// 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.
|
|
||||||
glDepthRangef(max_depth, min_depth);
|
glDepthRangef(max_depth, min_depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "VideoBackends/Vulkan/Renderer.h"
|
#include "VideoBackends/Vulkan/Renderer.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@ -1655,11 +1656,13 @@ void Renderer::SetViewport()
|
|||||||
height = -height;
|
height = -height;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If an inverted depth range is used, which the Vulkan drivers don't
|
// If an oversized or inverted depth range is used, we need to calculate the depth range in the
|
||||||
// support, we need to calculate the depth range in the vertex shader.
|
// vertex shader.
|
||||||
// TODO: Make this into a DriverDetails bug and write a test for CTS.
|
// TODO: Inverted depth ranges are bugged in all drivers, which should be added to DriverDetails.
|
||||||
if (xfmem.viewport.zRange < 0.0f)
|
if (xfmem.viewport.zRange < 0.0f || fabs(xfmem.viewport.zRange) > 16777215.0f ||
|
||||||
|
fabs(xfmem.viewport.farZ) > 16777215.0f)
|
||||||
{
|
{
|
||||||
|
// We need to ensure depth values are clamped the maximum value supported by the console GPU.
|
||||||
min_depth = 0.0f;
|
min_depth = 0.0f;
|
||||||
max_depth = GX_MAX_DEPTH;
|
max_depth = GX_MAX_DEPTH;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user