mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 16:19:28 +01:00
D3D: minor vs constant-setting optimization, remove a stupid memcpy that doesn't do anything, don't see much benefit though :/ At least the PIX logs will be cleaner.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4301 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
0d9543030b
commit
dae1a68bfc
@ -100,8 +100,7 @@ void VertexShaderManager::SetConstants()
|
||||
int startn = nNormalMatricesChanged[0] / 3;
|
||||
int endn = (nNormalMatricesChanged[1] + 2) / 3;
|
||||
const float *pnstart = (const float*)&xfmem[XFMEM_NORMALMATRICES+3*startn];
|
||||
for (int i = startn; i < endn; ++i, pnstart += 3)
|
||||
SetVSConstant4fv(C_NORMALMATRICES + i, pnstart); // looks like we're reading one too much..
|
||||
SetMultiVSConstant3fv(C_NORMALMATRICES + startn, endn - startn, pnstart);
|
||||
nNormalMatricesChanged[0] = nNormalMatricesChanged[1] = -1;
|
||||
}
|
||||
|
||||
@ -165,9 +164,7 @@ void VertexShaderManager::SetConstants()
|
||||
const float *norm = (const float *)xfmem + XFMEM_NORMALMATRICES + 3 * (MatrixIndexA.PosNormalMtxIdx & 31);
|
||||
|
||||
SetMultiVSConstant4fv(C_POSNORMALMATRIX, 3, pos);
|
||||
SetVSConstant4fv(C_POSNORMALMATRIX+3, norm);
|
||||
SetVSConstant4fv(C_POSNORMALMATRIX+4, norm + 3);
|
||||
SetVSConstant4fv(C_POSNORMALMATRIX+5, norm + 6);
|
||||
SetMultiVSConstant3fv(C_POSNORMALMATRIX + 3, 3, norm);
|
||||
}
|
||||
|
||||
if (bTexMatricesChanged[0])
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
|
||||
void SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4);
|
||||
void SetVSConstant4fv(int const_number, const float *f);
|
||||
void SetMultiVSConstant3fv(int const_number, int count, const float *f);
|
||||
void SetMultiVSConstant4fv(int const_number, int count, const float *f);
|
||||
|
||||
#endif // _VERTEXSHADERMANAGER_H
|
||||
|
@ -58,6 +58,7 @@ static DWORD m_RenderStates[MaxRenderStates];
|
||||
static DWORD m_TextureStageStates[MaxTextureStages][MaxTextureTypes];
|
||||
static DWORD m_SamplerStates[MaxSamplerSize][MaxSamplerTypes];
|
||||
LPDIRECT3DBASETEXTURE9 m_Textures[16];
|
||||
LPDIRECT3DVERTEXDECLARATION9 m_VtxDecl;
|
||||
|
||||
void Enumerate();
|
||||
|
||||
@ -256,25 +257,18 @@ HRESULT Create(int adapter, HWND wnd, bool _fullscreen, int _resolution, int aa_
|
||||
adapter,
|
||||
D3DDEVTYPE_HAL,
|
||||
wnd,
|
||||
D3DCREATE_HARDWARE_VERTEXPROCESSING,
|
||||
D3DCREATE_HARDWARE_VERTEXPROCESSING, // | D3DCREATE_PUREDEVICE, doesn't seem to make a difference
|
||||
&d3dpp, &dev)))
|
||||
{
|
||||
MessageBox(wnd,
|
||||
_T("Sorry, but it looks like your 3D accelerator is too old,\n")
|
||||
_T("or doesn't support features that Dolphin requires.\n")
|
||||
_T("Falling back to software vertex processing.\n"),
|
||||
_T("Dolphin Direct3D plugin"), MB_OK | MB_ICONERROR);
|
||||
if (FAILED(D3D->CreateDevice(
|
||||
adapter,
|
||||
D3DDEVTYPE_HAL,
|
||||
wnd,
|
||||
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED,
|
||||
// |D3DCREATE_MULTITHREADED /* | D3DCREATE_PUREDEVICE*/,
|
||||
//D3DCREATE_SOFTWARE_VERTEXPROCESSING ,
|
||||
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
|
||||
&d3dpp, &dev)))
|
||||
{
|
||||
MessageBox(wnd,
|
||||
_T("Software VP failed too. Upgrade your graphics card."),
|
||||
_T("Failed to initialize Direct3D."),
|
||||
_T("Dolphin Direct3D plugin"), MB_OK | MB_ICONERROR);
|
||||
return E_FAIL;
|
||||
}
|
||||
@ -442,6 +436,7 @@ void ApplyCachedState()
|
||||
// so no stale state is around.
|
||||
memset(m_Textures, 0, sizeof(m_Textures));
|
||||
memset(m_TextureStageStates, 0xFF, sizeof(m_TextureStageStates));
|
||||
m_VtxDecl = NULL;
|
||||
}
|
||||
|
||||
void SetTexture(DWORD Stage, LPDIRECT3DBASETEXTURE9 pTexture)
|
||||
@ -481,4 +476,17 @@ void SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value)
|
||||
}
|
||||
}
|
||||
|
||||
void SetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 decl)
|
||||
{
|
||||
if (!decl) {
|
||||
m_VtxDecl = NULL;
|
||||
return;
|
||||
}
|
||||
if (decl != m_VtxDecl)
|
||||
{
|
||||
D3D::dev->SetVertexDeclaration(decl);
|
||||
m_VtxDecl = decl;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -73,6 +73,7 @@ void SetTexture(DWORD Stage, IDirect3DBaseTexture9 *pTexture);
|
||||
void SetRenderState(D3DRENDERSTATETYPE State, DWORD Value);
|
||||
void SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value);
|
||||
void SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value);
|
||||
void SetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 decl);
|
||||
void ApplyCachedState();
|
||||
|
||||
// Utility functions for vendor specific hacks. So far, just the one.
|
||||
|
@ -227,6 +227,7 @@ void CD3DFont::SetRenderStates()
|
||||
dev->SetPixelShader(0);
|
||||
dev->SetVertexShader(0);
|
||||
|
||||
D3D::SetVertexDeclaration(NULL); // throw away cached vtx decl
|
||||
dev->SetFVF(D3DFVF_FONT2DVERTEX);
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
@ -366,6 +367,7 @@ void quad2d(float x1, float y1, float x2, float y2, u32 color, float u1, float v
|
||||
dev->SetVertexShader(0);
|
||||
dev->SetVertexDeclaration(0);
|
||||
|
||||
D3D::SetVertexDeclaration(NULL); // throw away cached vtx decl
|
||||
dev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
|
||||
dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coords, sizeof(Q2DVertex));
|
||||
|
||||
|
@ -162,7 +162,7 @@ void D3DVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl)
|
||||
void D3DVertexFormat::SetupVertexPointers() const
|
||||
{
|
||||
if (d3d_decl)
|
||||
D3D::dev->SetVertexDeclaration(d3d_decl);
|
||||
D3D::SetVertexDeclaration(d3d_decl);
|
||||
else
|
||||
ERROR_LOG(VIDEO, "invalid d3d decl");
|
||||
}
|
@ -99,6 +99,7 @@ void Shutdown()
|
||||
|
||||
void CreateDeviceObjects()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DestroyDeviceObjects()
|
||||
@ -140,12 +141,8 @@ void AddVertices(int _primitive, int _numVertices)
|
||||
|
||||
if (collection != type)
|
||||
{
|
||||
//We are NOT collecting the right type.
|
||||
// We are NOT collecting the right type.
|
||||
Flush();
|
||||
|
||||
// Copy the extra verts that we lost.
|
||||
memcpy(s_pCurBufferPointer, fakeVBuffer, _numVertices * g_nativeVertexFmt->GetVertexStride());
|
||||
|
||||
collection = type;
|
||||
u16 *ptr = 0;
|
||||
if (type != C_POINTS)
|
||||
|
@ -43,11 +43,11 @@ void SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4)
|
||||
lastVSconstants[const_number][3] != f4)
|
||||
{
|
||||
const float f[4] = {f1, f2, f3, f4};
|
||||
D3D::dev->SetVertexShaderConstantF(const_number, f, 1);
|
||||
lastVSconstants[const_number][0] = f1;
|
||||
lastVSconstants[const_number][1] = f2;
|
||||
lastVSconstants[const_number][2] = f3;
|
||||
lastVSconstants[const_number][3] = f4;
|
||||
D3D::dev->SetVertexShaderConstantF(const_number, lastVSconstants[const_number], 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,11 +58,37 @@ void SetVSConstant4fv(int const_number, const float *f)
|
||||
lastVSconstants[const_number][2] != f[2] ||
|
||||
lastVSconstants[const_number][3] != f[3])
|
||||
{
|
||||
D3D::dev->SetVertexShaderConstantF(const_number, f, 1);
|
||||
lastVSconstants[const_number][0] = f[0];
|
||||
lastVSconstants[const_number][1] = f[1];
|
||||
lastVSconstants[const_number][2] = f[2];
|
||||
lastVSconstants[const_number][3] = f[3];
|
||||
D3D::dev->SetVertexShaderConstantF(const_number, lastVSconstants[const_number], 1);
|
||||
}
|
||||
}
|
||||
|
||||
void SetMultiVSConstant3fv(int const_number, int count, const float *f)
|
||||
{
|
||||
bool change = false;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (lastVSconstants[const_number + i][0] != f[0 + i*3] ||
|
||||
lastVSconstants[const_number + i][1] != f[1 + i*3] ||
|
||||
lastVSconstants[const_number + i][2] != f[2 + i*3])
|
||||
{
|
||||
change = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (change)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
lastVSconstants[const_number + i][0] = f[0 + i*3];
|
||||
lastVSconstants[const_number + i][1] = f[1 + i*3];
|
||||
lastVSconstants[const_number + i][2] = f[2 + i*3];
|
||||
lastVSconstants[const_number + i][3] = 0.0f;
|
||||
}
|
||||
D3D::dev->SetVertexShaderConstantF(const_number, lastVSconstants[const_number], count);
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,13 +108,14 @@ void SetMultiVSConstant4fv(int const_number, int count, const float *f)
|
||||
}
|
||||
if (change)
|
||||
{
|
||||
D3D::dev->SetVertexShaderConstantF(const_number, f, count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
lastVSconstants[const_number + i][0] = f[0 + i*4];
|
||||
lastVSconstants[const_number + i][1] = f[1 + i*4];
|
||||
lastVSconstants[const_number + i][2] = f[2 + i*4];
|
||||
lastVSconstants[const_number + i][3] = f[3 + i*4];
|
||||
}
|
||||
D3D::dev->SetVertexShaderConstantF(const_number, lastVSconstants[const_number], count);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,12 +50,11 @@ void SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4)
|
||||
lastVSconstants[const_number][2] != f3 ||
|
||||
lastVSconstants[const_number][3] != f4)
|
||||
{
|
||||
const float f[4] = {f1, f2, f3, f4};
|
||||
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, const_number, f1, f2, f3, f4);
|
||||
lastVSconstants[const_number][0] = f1;
|
||||
lastVSconstants[const_number][1] = f2;
|
||||
lastVSconstants[const_number][2] = f3;
|
||||
lastVSconstants[const_number][3] = f4;
|
||||
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number, lastVSconstants[const_number]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,11 +65,11 @@ void SetVSConstant4fv(int const_number, const float *f)
|
||||
lastVSconstants[const_number][2] != f[2] ||
|
||||
lastVSconstants[const_number][3] != f[3])
|
||||
{
|
||||
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number, f);
|
||||
lastVSconstants[const_number][0] = f[0];
|
||||
lastVSconstants[const_number][1] = f[1];
|
||||
lastVSconstants[const_number][2] = f[2];
|
||||
lastVSconstants[const_number][3] = f[3];
|
||||
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number, lastVSconstants[const_number]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,15 +82,34 @@ void SetMultiVSConstant4fv(int const_number, int count, const float *f)
|
||||
lastVSconstants[const_number + i][2] != f[2 + i*4] ||
|
||||
lastVSconstants[const_number + i][3] != f[3 + i*4])
|
||||
{
|
||||
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, f + i * 4);
|
||||
lastVSconstants[const_number + i][0] = f[0 + i*4];
|
||||
lastVSconstants[const_number + i][1] = f[1 + i*4];
|
||||
lastVSconstants[const_number + i][2] = f[2 + i*4];
|
||||
lastVSconstants[const_number + i][3] = f[3 + i*4];
|
||||
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, lastVSconstants[const_number + i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetMultiVSConstant3fv(int const_number, int count, const float *f)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (lastVSconstants[const_number + i][0] != f[0 + i*3] ||
|
||||
lastVSconstants[const_number + i][1] != f[1 + i*3] ||
|
||||
lastVSconstants[const_number + i][2] != f[2 + i*3] ||
|
||||
lastVSconstants[const_number + i][3] != 0.0f)
|
||||
{
|
||||
lastVSconstants[const_number + i][0] = f[0 + i*3];
|
||||
lastVSconstants[const_number + i][1] = f[1 + i*3];
|
||||
lastVSconstants[const_number + i][2] = f[2 + i*3];
|
||||
lastVSconstants[const_number + i][3] = 0.0f;
|
||||
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, lastVSconstants[const_number + i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void VertexShaderCache::Init()
|
||||
{
|
||||
for( int i=0;i<(C_FOGPARAMS+8)*4;i++)
|
||||
|
Loading…
x
Reference in New Issue
Block a user