2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
#include "Common.h"
|
2009-09-02 07:25:22 +00:00
|
|
|
#include "FileUtil.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
#include "D3DBase.h"
|
2010-06-29 14:40:37 +00:00
|
|
|
#include "Fifo.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "Statistics.h"
|
|
|
|
#include "Profiler.h"
|
|
|
|
#include "VertexManager.h"
|
|
|
|
#include "OpcodeDecoding.h"
|
|
|
|
#include "IndexGenerator.h"
|
2008-12-25 15:56:36 +00:00
|
|
|
#include "VertexShaderManager.h"
|
2008-12-26 19:39:12 +00:00
|
|
|
#include "VertexShaderCache.h"
|
2008-12-25 15:56:36 +00:00
|
|
|
#include "PixelShaderManager.h"
|
2008-12-26 19:39:12 +00:00
|
|
|
#include "PixelShaderCache.h"
|
2009-02-28 22:10:38 +00:00
|
|
|
#include "NativeVertexFormat.h"
|
2009-03-07 18:05:29 +00:00
|
|
|
#include "TextureCache.h"
|
2010-08-04 21:02:32 +00:00
|
|
|
#include "main.h"
|
2009-02-28 22:10:38 +00:00
|
|
|
|
2009-06-22 09:31:30 +00:00
|
|
|
#include "BPStructs.h"
|
2009-02-28 22:10:38 +00:00
|
|
|
#include "XFStructs.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-02 06:33:41 +00:00
|
|
|
#include "debugger/debugger.h"
|
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
// internal state for loading vertices
|
|
|
|
extern NativeVertexFormat *g_nativeVertexFmt;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-10-03 00:41:06 +00:00
|
|
|
namespace DX9
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
|
|
|
|
2009-11-01 02:03:26 +00:00
|
|
|
inline void DumpBadShaders()
|
|
|
|
{
|
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
|
|
|
std::string error_shaders;
|
|
|
|
error_shaders.append(VertexShaderCache::GetCurrentShaderCode());
|
|
|
|
error_shaders.append(PixelShaderCache::GetCurrentShaderCode());
|
|
|
|
char filename[512] = "bad_shader_combo_0.txt";
|
|
|
|
int which = 0;
|
|
|
|
while (File::Exists(filename))
|
|
|
|
{
|
|
|
|
which++;
|
|
|
|
sprintf(filename, "bad_shader_combo_%i.txt", which);
|
|
|
|
}
|
|
|
|
File::WriteStringToFile(true, error_shaders, filename);
|
|
|
|
PanicAlert("DrawIndexedPrimitiveUP failed. Shaders written to %s", filename);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-10-03 00:41:06 +00:00
|
|
|
void VertexManager::Draw(int stride)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2010-09-28 02:15:02 +00:00
|
|
|
if (IndexGenerator::GetNumTriangles() > 0)
|
2009-09-19 13:14:55 +00:00
|
|
|
{
|
2009-10-02 14:03:07 +00:00
|
|
|
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
2009-11-01 02:03:26 +00:00
|
|
|
D3DPT_TRIANGLELIST,
|
2010-06-05 01:38:22 +00:00
|
|
|
0, IndexGenerator::GetNumVerts(), IndexGenerator::GetNumTriangles(),
|
|
|
|
TIBuffer,
|
|
|
|
D3DFMT_INDEX16,
|
|
|
|
LocalVBuffer,
|
|
|
|
stride)))
|
2009-11-01 02:03:26 +00:00
|
|
|
{
|
|
|
|
DumpBadShaders();
|
|
|
|
}
|
2009-10-02 14:03:07 +00:00
|
|
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
|
|
|
}
|
2010-09-28 02:15:02 +00:00
|
|
|
if (IndexGenerator::GetNumLines() > 0)
|
2009-10-02 14:03:07 +00:00
|
|
|
{
|
|
|
|
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
2009-11-01 02:03:26 +00:00
|
|
|
D3DPT_LINELIST,
|
2010-06-05 01:38:22 +00:00
|
|
|
0, IndexGenerator::GetNumVerts(), IndexGenerator::GetNumLines(),
|
|
|
|
LIBuffer,
|
|
|
|
D3DFMT_INDEX16,
|
|
|
|
LocalVBuffer,
|
|
|
|
stride)))
|
2009-11-01 02:03:26 +00:00
|
|
|
{
|
|
|
|
DumpBadShaders();
|
|
|
|
}
|
2009-10-02 14:03:07 +00:00
|
|
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
2009-09-19 13:14:55 +00:00
|
|
|
}
|
2010-09-28 02:15:02 +00:00
|
|
|
if (IndexGenerator::GetNumPoints() > 0)
|
2009-09-19 13:14:55 +00:00
|
|
|
{
|
2009-10-02 14:03:07 +00:00
|
|
|
if (FAILED(D3D::dev->DrawIndexedPrimitiveUP(
|
2009-11-01 02:03:26 +00:00
|
|
|
D3DPT_POINTLIST,
|
2010-06-05 01:38:22 +00:00
|
|
|
0, IndexGenerator::GetNumVerts(), IndexGenerator::GetNumPoints(),
|
|
|
|
PIBuffer,
|
|
|
|
D3DFMT_INDEX16,
|
|
|
|
LocalVBuffer,
|
|
|
|
stride)))
|
2009-11-01 02:03:26 +00:00
|
|
|
{
|
|
|
|
DumpBadShaders();
|
|
|
|
}
|
2009-10-02 14:03:07 +00:00
|
|
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
2009-11-01 02:03:26 +00:00
|
|
|
}
|
2009-09-19 13:14:55 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-10-03 00:41:06 +00:00
|
|
|
void VertexManager::vFlush()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2010-06-05 01:38:22 +00:00
|
|
|
if (LocalVBuffer == s_pCurBufferPointer) return;
|
2010-09-28 02:15:02 +00:00
|
|
|
if (Flushed) return;
|
2010-10-03 00:41:06 +00:00
|
|
|
Flushed = true;
|
2010-06-29 14:40:37 +00:00
|
|
|
VideoFifo_CheckEFBAccess();
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2009-02-28 22:10:38 +00:00
|
|
|
DVSTARTPROFILE();
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2009-10-06 14:24:10 +00:00
|
|
|
u32 usedtextures = 0;
|
2010-09-28 02:15:02 +00:00
|
|
|
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; ++i)
|
|
|
|
if (bpmem.tevorders[i / 2].getEnable(i & 1))
|
2009-10-06 14:24:10 +00:00
|
|
|
usedtextures |= 1 << bpmem.tevorders[i/2].getTexMap(i & 1);
|
2009-03-07 18:05:29 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
if (bpmem.genMode.numindstages > 0)
|
|
|
|
for (unsigned int i = 0; i < bpmem.genMode.numtevstages + 1; ++i)
|
|
|
|
if (bpmem.tevind[i].IsActive() && bpmem.tevind[i].bt < bpmem.genMode.numindstages)
|
2009-10-06 14:24:10 +00:00
|
|
|
usedtextures |= 1 << bpmem.tevindref.getTexMap(bpmem.tevind[i].bt);
|
2009-03-07 18:05:29 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
for (unsigned int i = 0; i < 8; i++)
|
2009-10-06 14:24:10 +00:00
|
|
|
{
|
2010-09-28 02:15:02 +00:00
|
|
|
if (usedtextures & (1 << i))
|
|
|
|
{
|
2010-01-21 22:32:24 +00:00
|
|
|
Renderer::SetSamplerState(i & 3, i >> 2);
|
2009-10-06 14:24:10 +00:00
|
|
|
FourTexUnits &tex = bpmem.tex[i >> 2];
|
|
|
|
TextureCache::TCacheEntry* tentry = TextureCache::Load(i,
|
2010-09-28 02:15:02 +00:00
|
|
|
(tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5,
|
|
|
|
tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1,
|
2009-10-06 14:24:10 +00:00
|
|
|
tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9,
|
2010-04-14 13:57:16 +00:00
|
|
|
tex.texTlut[i&3].tlut_format,
|
2010-09-28 02:15:02 +00:00
|
|
|
(tex.texMode0[i&3].min_filter & 3) && (tex.texMode0[i&3].min_filter != 8) && g_ActiveConfig.bUseNativeMips,
|
2010-06-06 14:44:35 +00:00
|
|
|
(tex.texMode1[i&3].max_lod >> 4));
|
2009-10-06 14:24:10 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
if (tentry)
|
|
|
|
{
|
|
|
|
// 0s are probably for no manual wrapping needed.
|
2009-10-06 14:24:10 +00:00
|
|
|
PixelShaderManager::SetTexDims(i, tentry->w, tentry->h, 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERROR_LOG(VIDEO, "error loading texture");
|
2009-03-07 18:05:29 +00:00
|
|
|
}
|
2009-10-06 14:24:10 +00:00
|
|
|
}
|
2009-07-19 08:17:41 +00:00
|
|
|
|
2009-10-06 14:24:10 +00:00
|
|
|
// set global constants
|
|
|
|
VertexShaderManager::SetConstants();
|
|
|
|
PixelShaderManager::SetConstants();
|
2009-03-10 14:15:46 +00:00
|
|
|
|
2010-09-23 02:17:48 +00:00
|
|
|
if (!PixelShaderCache::SetShader(false,g_nativeVertexFmt->m_components))
|
2009-10-06 14:24:10 +00:00
|
|
|
{
|
|
|
|
DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
|
|
|
goto shader_fail;
|
|
|
|
}
|
|
|
|
if (!VertexShaderCache::SetShader(g_nativeVertexFmt->m_components))
|
|
|
|
{
|
|
|
|
DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set vertex shader\n");});
|
|
|
|
goto shader_fail;
|
2009-03-10 14:15:46 +00:00
|
|
|
|
2009-10-06 14:24:10 +00:00
|
|
|
}
|
2009-09-20 03:29:43 +00:00
|
|
|
|
2009-10-06 14:24:10 +00:00
|
|
|
int stride = g_nativeVertexFmt->GetVertexStride();
|
|
|
|
g_nativeVertexFmt->SetupVertexPointers();
|
2010-01-12 03:39:14 +00:00
|
|
|
|
2009-10-06 14:24:10 +00:00
|
|
|
Draw(stride);
|
2009-09-02 04:10:40 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
if (bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate)
|
2009-10-06 14:24:10 +00:00
|
|
|
{
|
2010-06-12 15:38:42 +00:00
|
|
|
DWORD write = 0;
|
2010-10-03 00:41:06 +00:00
|
|
|
if (!PixelShaderCache::SetShader(true, g_nativeVertexFmt->m_components))
|
2010-06-12 15:38:42 +00:00
|
|
|
{
|
|
|
|
DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
|
|
|
goto shader_fail;
|
|
|
|
}
|
|
|
|
// update alpha only
|
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
|
|
|
D3D::ChangeRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA);
|
|
|
|
D3D::ChangeRenderState(D3DRS_ALPHABLENDENABLE, false);
|
2010-10-03 00:41:06 +00:00
|
|
|
|
2010-06-12 15:38:42 +00:00
|
|
|
Draw(stride);
|
2010-10-03 00:41:06 +00:00
|
|
|
|
2010-01-12 03:39:14 +00:00
|
|
|
D3D::RefreshRenderState(D3DRS_COLORWRITEENABLE);
|
2010-06-05 01:38:22 +00:00
|
|
|
D3D::RefreshRenderState(D3DRS_ALPHABLENDENABLE);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-10-06 14:24:10 +00:00
|
|
|
DEBUGGER_PAUSE_AT(NEXT_FLUSH,true);
|
|
|
|
|
|
|
|
shader_fail:
|
|
|
|
ResetBuffer();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2010-10-03 00:41:06 +00:00
|
|
|
|
|
|
|
}
|