Merge pull request #4655 from Armada651/vertex-depth-no-uid

VertexShaderGen: Remove the need for an extra UID.
This commit is contained in:
Markus Wick 2017-01-15 23:02:13 +01:00 committed by GitHub
commit 23104b6939
3 changed files with 46 additions and 45 deletions

View File

@ -30,10 +30,6 @@ VertexShaderUid GetVertexShaderUid()
uid_data->msaa = g_ActiveConfig.iMultisamples > 1;
uid_data->ssaa = g_ActiveConfig.iMultisamples > 1 && g_ActiveConfig.bSSAA;
uid_data->numColorChans = xfmem.numChan.numColorChans;
uid_data->vertex_depth =
g_ActiveConfig.backend_info.bSupportsDepthClamp &&
((fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f) ||
(xfmem.viewport.zRange < 0.0f && !g_ActiveConfig.backend_info.bSupportsReversedDepthRange));
GetLightingShaderUid(uid_data->lighting);
@ -438,23 +434,15 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da
// override it with the correct values if not then early z culling will improve speed.
// There are two different ways to do this, when the depth range is oversized, we process
// the depth range in the vertex shader, if not we let the host driver handle it.
if (uid_data->vertex_depth)
{
// Adjust z for the depth range. We're using an equation which incorperates a depth inversion,
// so we can map the console -1..0 range to the 0..1 range used in the depth buffer.
// We have to handle the depth range in the vertex shader instead of after the perspective
// divide, because some games will use a depth range larger than what is allowed by the
// graphics API. These large depth ranges will still be clipped to the 0..1 range, so these
// games effectively add a depth bias to the values written to the depth buffer.
out.Write("o.pos.z = o.pos.w * " I_PIXELCENTERCORRECTION ".w - "
"o.pos.z * " I_PIXELCENTERCORRECTION ".z;\n");
}
else
{
// Here we rely on the host driver to process the depth range, however we still need to invert
// the console -1..0 range to the 0..1 range used in the depth buffer.
out.Write("o.pos.z = -o.pos.z;\n");
}
//
// Adjust z for the depth range. We're using an equation which incorperates a depth inversion,
// so we can map the console -1..0 range to the 0..1 range used in the depth buffer.
// We have to handle the depth range in the vertex shader instead of after the perspective
// divide, because some games will use a depth range larger than what is allowed by the
// graphics API. These large depth ranges will still be clipped to the 0..1 range, so these
// games effectively add a depth bias to the values written to the depth buffer.
out.Write("o.pos.z = o.pos.w * " I_PIXELCENTERCORRECTION ".w - "
"o.pos.z * " I_PIXELCENTERCORRECTION ".z;\n");
if (!g_ActiveConfig.backend_info.bSupportsClipControl)
{

View File

@ -43,8 +43,7 @@ struct vertex_shader_uid_data
u32 texMtxInfo_n_projection : 16; // Stored separately to guarantee that the texMtxInfo struct is
// 8 bits wide
u32 ssaa : 1;
u32 vertex_depth : 1;
u32 pad : 14;
u32 pad : 15;
struct
{

View File

@ -387,30 +387,44 @@ void VertexShaderManager::SetConstants()
constants.pixelcentercorrection[0] = pixel_center_correction * pixel_size_x;
constants.pixelcentercorrection[1] = pixel_center_correction * pixel_size_y;
// The depth range is handled in the vertex shader. We need to reverse
// the far value to get a reversed depth range mapping. This is necessary
// because the standard depth range equation pushes all depth values towards
// the back of the depth buffer where conventionally depth buffers have the
// least precision.
if (g_ActiveConfig.backend_info.bSupportsReversedDepthRange)
// By default we don't change the depth value at all in the vertex shader.
constants.pixelcentercorrection[2] = 1.0f;
constants.pixelcentercorrection[3] = 0.0f;
if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
{
// For backends that support reversing the depth range we also support cases
// where the console also uses reversed depth with the same accuracy. We need
// to make sure the depth range is positive here and then reverse the depth in
// the backend viewport.
constants.pixelcentercorrection[2] = fabs(xfmem.viewport.zRange) / 16777215.0f;
if (xfmem.viewport.zRange < 0.0f)
constants.pixelcentercorrection[3] = xfmem.viewport.farZ / 16777215.0f;
// Oversized depth ranges are handled in the vertex shader. We need to reverse
// the far value to get a reversed depth range mapping. This is necessary
// because the standard depth range equation pushes all depth values towards
// the back of the depth buffer where conventionally depth buffers have the
// least precision.
if (g_ActiveConfig.backend_info.bSupportsReversedDepthRange)
{
if (fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f)
{
// For backends that support reversing the depth range we also support cases
// where the console also uses reversed depth with the same accuracy. We need
// to make sure the depth range is positive here and then reverse the depth in
// the backend viewport.
constants.pixelcentercorrection[2] = fabs(xfmem.viewport.zRange) / 16777215.0f;
if (xfmem.viewport.zRange < 0.0f)
constants.pixelcentercorrection[3] = xfmem.viewport.farZ / 16777215.0f;
else
constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f;
}
}
else
constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f;
}
else
{
// For backends that don't support reversing the depth range we can still render
// cases where the console uses reversed depth correctly. But we simply can't
// provide the same accuracy as the console.
constants.pixelcentercorrection[2] = xfmem.viewport.zRange / 16777215.0f;
constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f;
{
if (xfmem.viewport.zRange < 0.0f || xfmem.viewport.zRange > 16777215.0f ||
fabs(xfmem.viewport.farZ) > 16777215.0f)
{
// For backends that don't support reversing the depth range we can still render
// cases where the console uses reversed depth correctly. But we simply can't
// provide the same accuracy as the console.
constants.pixelcentercorrection[2] = xfmem.viewport.zRange / 16777215.0f;
constants.pixelcentercorrection[3] = 1.0f - xfmem.viewport.farZ / 16777215.0f;
}
}
}
dirty = true;