Merge pull request #1392 from kayru/d3d_viewport_depth

D3D: Replaced shader-based depth range remap with viewport
This commit is contained in:
Lioncash 2014-12-03 14:49:30 -05:00
commit 88cd27bbca
5 changed files with 9 additions and 12 deletions

View File

@ -485,10 +485,9 @@ void Renderer::SetViewport()
Wd = (X + Wd <= GetTargetWidth()) ? Wd : (GetTargetWidth() - X);
Ht = (Y + Ht <= GetTargetHeight()) ? Ht : (GetTargetHeight() - Y);
// Some games set invalid values for z-min and z-max so fix them to the max and min allowed and let the shaders do this work
D3D11_VIEWPORT vp = CD3D11_VIEWPORT(X, Y, Wd, Ht,
0.f, // (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f;
1.f); // xfmem.viewport.farZ / 16777216.0f;
std::max(0.0f, std::min(1.0f, (xfmem.viewport.farZ - xfmem.viewport.zRange) / 16777216.0f)),
std::max(0.0f, std::min(1.0f, xfmem.viewport.farZ / 16777216.0f)));
D3D::context->RSSetViewports(1, &vp);
}

View File

@ -42,7 +42,7 @@ struct VertexShaderConstants
float4 transformmatrices[64];
float4 normalmatrices[32];
float4 posttransformmatrices[64];
float4 depthparams;
float4 pixelcentercorrection;
float4 stereoparams;
};

View File

@ -238,7 +238,7 @@ private:
#define I_TRANSFORMMATRICES "ctrmtx"
#define I_NORMALMATRICES "cnmtx"
#define I_POSTTRANSFORMMATRICES "cpostmtx"
#define I_DEPTHPARAMS "cDepth" // farZ, zRange
#define I_PIXELCENTERCORRECTION "cpixelcenter"
#define I_STEREOPARAMS "cstereo"
static const char s_shader_uniforms[] =
@ -250,5 +250,5 @@ static const char s_shader_uniforms[] =
"\tfloat4 " I_TRANSFORMMATRICES"[64];\n"
"\tfloat4 " I_NORMALMATRICES"[32];\n"
"\tfloat4 " I_POSTTRANSFORMMATRICES"[64];\n"
"\tfloat4 " I_DEPTHPARAMS";\n"
"\tfloat4 " I_PIXELCENTERCORRECTION";\n"
"\tfloat4 " I_STEREOPARAMS";\n";

View File

@ -405,7 +405,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
//if not early z culling will improve speed
if (api_type == API_D3D)
{
out.Write("o.pos.z = " I_DEPTHPARAMS".x * o.pos.w + o.pos.z * " I_DEPTHPARAMS".y;\n");
out.Write("o.pos.z = o.pos.w + o.pos.z;\n");
}
else // OGL
{
@ -430,7 +430,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
// which in turn can be critical if it happens for clear quads.
// Hence, we compensate for this pixel center difference so that primitives
// get rasterized correctly.
out.Write("o.pos.xy = o.pos.xy - " I_DEPTHPARAMS".zw;\n");
out.Write("o.pos.xy = o.pos.xy - " I_PIXELCENTERCORRECTION".xy;\n");
if (api_type == API_OPENGL)
{

View File

@ -359,8 +359,6 @@ void VertexShaderManager::SetConstants()
if (bViewportChanged)
{
bViewportChanged = false;
constants.depthparams[0] = xfmem.viewport.farZ / 16777216.0f;
constants.depthparams[1] = xfmem.viewport.zRange / 16777216.0f;
// The console GPU places the pixel center at 7/12 unless antialiasing
// is enabled, while D3D and OpenGL place it at 0.5. See the comment
@ -370,8 +368,8 @@ void VertexShaderManager::SetConstants()
const float pixel_center_correction = 7.0f / 12.0f - 0.5f;
const float pixel_size_x = 2.f / Renderer::EFBToScaledXf(2.f * xfmem.viewport.wd);
const float pixel_size_y = 2.f / Renderer::EFBToScaledXf(2.f * xfmem.viewport.ht);
constants.depthparams[2] = pixel_center_correction * pixel_size_x;
constants.depthparams[3] = pixel_center_correction * pixel_size_y;
constants.pixelcentercorrection[0] = pixel_center_correction * pixel_size_x;
constants.pixelcentercorrection[1] = pixel_center_correction * pixel_size_y;
dirty = true;
// This is so implementation-dependent that we can't have it here.
g_renderer->SetViewport();