Initial port of zfreeze branch (3.5-1729)

Initial port of original zfreeze branch (3.5-1729) by neobrain into
most recent build of Dolphin.

Makes Rogue Squadron 2 very playable at full speed thanks to recent core
speedups made to Dolphin. Works on DirectX Video plugin only for now.

Enjoy!  and Merry Xmas!!
This commit is contained in:
NanoByte011
2014-12-25 00:34:22 -07:00
committed by Scott Mansell
parent 4984215971
commit 937844b9e3
12 changed files with 173 additions and 4 deletions

View File

@ -42,6 +42,13 @@ static size_t s_index_offset;
VertexManager::VertexManager()
{
LocalVBuffer.resize(MAXVBUFFERSIZE);
s_pCurBufferPointer = s_pBaseBufferPointer = &LocalVBuffer[0];
s_pEndBufferPointer = s_pBaseBufferPointer + LocalVBuffer.size();
LocalIBuffer.resize(MAXIBUFFERSIZE);
CreateDeviceObjects();
}
@ -131,6 +138,7 @@ void VertexManager::vFlush(bool useDstAlpha)
{
GLVertexFormat *nativeVertexFmt = (GLVertexFormat*)VertexLoaderManager::GetCurrentVertexFormat();
u32 stride = nativeVertexFmt->GetVertexStride();
u32 indices = IndexGenerator::GetIndexLen();
if (m_last_vao != nativeVertexFmt->VAO)
{
@ -140,6 +148,47 @@ void VertexManager::vFlush(bool useDstAlpha)
PrepareDrawBuffers(stride);
if (!bpmem.genMode.zfreeze && indices >= 3)
{
float vtx[9];
float out[12];
// Lookup vertices of the last rendered triangle and software-transform them
// This allows us to determine the depth slope, which will be used if zfreeze
// is enabled in the following flush.
for (unsigned int i = 0; i < 3; ++i)
{
const int base_index = GetIndexBuffer()[indices - 3 + i];
u8* vtx_ptr = &((u8*)GetVertexBuffer())[base_index * stride];
vtx[0 + i * 3] = ((float*)vtx_ptr)[0];
vtx[1 + i * 3] = ((float*)vtx_ptr)[1];
vtx[2 + i * 3] = ((float*)vtx_ptr)[2];
VertexShaderManager::TransformToClipSpace(&vtx[i * 3], &out[i * 4]);
// viewport offset ignored because we only look at coordinate differences.
out[0 + i * 4] = out[0 + i * 4] / out[3 + i * 4] * xfmem.viewport.wd;
out[1 + i * 4] = out[1 + i * 4] / out[3 + i * 4] * xfmem.viewport.ht;
out[2 + i * 4] = out[2 + i * 4] / out[3 + i * 4] * xfmem.viewport.zRange + xfmem.viewport.farZ;
}
float dx31 = out[8] - out[0];
float dx12 = out[0] - out[4];
float dy12 = out[1] - out[5];
float dy31 = out[9] - out[1];
float DF31 = out[10] - out[2];
float DF21 = out[6] - out[2];
float a = DF31 * -dy12 - DF21 * dy31;
float b = dx31 * DF21 + dx12 * DF31;
float c = -dx12 * dy31 - dx31 * -dy12;
float slope_dfdx = -a / c;
float slope_dfdy = -b / c;
float slope_f0 = out[2];
PixelShaderManager::SetZSlopeChanged(slope_dfdx, slope_dfdy, slope_f0);
}
// Makes sure we can actually do Dual source blending
bool dualSourcePossible = g_ActiveConfig.backend_info.bSupportsDualSourceBlend;