Get 2501 closer to "working".

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2502 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2009-03-01 10:53:23 +00:00
parent 37d5360399
commit f597a66b8d
7 changed files with 73 additions and 51 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="9.00" Version="9,00"
Name="Plugin_VideoDX9" Name="Plugin_VideoDX9"
ProjectGUID="{636FAD5F-02D1-4E9A-BE67-FB8EA99B9A18}" ProjectGUID="{636FAD5F-02D1-4E9A-BE67-FB8EA99B9A18}"
RootNamespace="Plugin_VideoDX9" RootNamespace="Plugin_VideoDX9"
@ -208,6 +208,7 @@
SuppressStartupBanner="true" SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\..\Externals\Cg64" AdditionalLibraryDirectories="..\..\..\Externals\Cg64"
GenerateManifest="false" GenerateManifest="false"
GenerateDebugInformation="true"
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb" ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
RandomizedBaseAddress="1" RandomizedBaseAddress="1"
DataExecutionPrevention="0" DataExecutionPrevention="0"
@ -1196,10 +1197,6 @@
RelativePath=".\Src\NativeVertexFormat.cpp" RelativePath=".\Src\NativeVertexFormat.cpp"
> >
</File> </File>
<File
RelativePath=".\Src\VertexShaderCache.cpp"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="Render" Name="Render"
@ -1236,6 +1233,10 @@
RelativePath=".\Src\VertexManager.h" RelativePath=".\Src\VertexManager.h"
> >
</File> </File>
<File
RelativePath=".\Src\VertexShaderCache.cpp"
>
</File>
<File <File
RelativePath=".\Src\VertexShaderCache.h" RelativePath=".\Src\VertexShaderCache.h"
> >

View File

@ -62,6 +62,7 @@ void PixelShaderCache::SetShader()
return; // we are screwed return; // we are screwed
static LPDIRECT3DPIXELSHADER9 lastShader = NULL; static LPDIRECT3DPIXELSHADER9 lastShader = NULL;
DVSTARTPROFILE(); DVSTARTPROFILE();
PIXELSHADERUID uid; PIXELSHADERUID uid;
@ -83,9 +84,7 @@ void PixelShaderCache::SetShader()
} }
const char *code = GeneratePixelShader(PixelShaderManager::GetTextureMask(), false, false); const char *code = GeneratePixelShader(PixelShaderManager::GetTextureMask(), false, false);
//LPDIRECT3DPIXELSHADER9 shader = D3D::CompilePixelShader(code, (int)(strlen(code)));
LPDIRECT3DPIXELSHADER9 shader = CompileCgShader(code); LPDIRECT3DPIXELSHADER9 shader = CompileCgShader(code);
if (shader) if (shader)
{ {
//Make an entry in the table //Make an entry in the table
@ -94,6 +93,7 @@ void PixelShaderCache::SetShader()
newentry.frameCount = frameCount; newentry.frameCount = frameCount;
PixelShaders[uid] = newentry; PixelShaders[uid] = newentry;
D3D::dev->SetFVF(NULL);
D3D::dev->SetPixelShader(shader); D3D::dev->SetPixelShader(shader);
INCSTAT(stats.numPixelShadersCreated); INCSTAT(stats.numPixelShadersCreated);
@ -119,18 +119,34 @@ LPDIRECT3DPIXELSHADER9 PixelShaderCache::CompileCgShader(const char *pstrprogram
// This looks evil - we modify the program through the const char * we got from cgGetProgramString! // This looks evil - we modify the program through the const char * we got from cgGetProgramString!
// It SHOULD not have any nasty side effects though - but you never know... // It SHOULD not have any nasty side effects though - but you never know...
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM); char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
char *plocal = strstr(pcompiledprog, "program.local"); LPD3DXBUFFER shader_binary;
while (plocal != NULL) { LPD3DXBUFFER error_msg;
const char *penv = " program.env";
memcpy(plocal, penv, 13);
plocal = strstr(plocal+13, "program.local");
}
LPDIRECT3DPIXELSHADER9 shader = D3D::CompilePixelShader(pcompiledprog, strlen(pcompiledprog));
// Step one - Assemble into binary code. This binary code could be cached.
if (FAILED(D3DXAssembleShader(pcompiledprog, (UINT)strlen(pcompiledprog), NULL, NULL, 0, &shader_binary, &error_msg)))
PanicAlert("Asm fail");
// Destroy Cg program as early as possible - we want as little as possible to do with Cg due to
// our rather extreme performance requirements.
cgDestroyProgram(tempprog); cgDestroyProgram(tempprog);
tempprog = NULL;
return shader; // Create pixel shader from the binary code.
LPDIRECT3DPIXELSHADER9 pixel_shader = NULL;
if (SUCCEEDED(D3D::dev->CreatePixelShader((const DWORD *)shader_binary->GetBufferPointer(), &pixel_shader))) {
// PanicAlert("Success Pixel!");
} else {
if (error_msg) {
PanicAlert("failure pixel %s", error_msg->GetBufferPointer());
MessageBox(0, pcompiledprog, 0, 0);
}
else
PanicAlert("failure pixel with no error message.");
}
if (shader_binary)
shader_binary->Release();
if (error_msg)
error_msg->Release();
return pixel_shader;
} }

View File

@ -34,13 +34,9 @@ class PixelShaderCache
struct PSCacheEntry struct PSCacheEntry
{ {
LPDIRECT3DPIXELSHADER9 shader; LPDIRECT3DPIXELSHADER9 shader;
int frameCount; int frameCount;
PSCacheEntry()
{ PSCacheEntry() : shader(NULL), frameCount(0) {}
shader = 0;
frameCount = 0;
}
void Destroy() void Destroy()
{ {
if (shader) if (shader)

View File

@ -93,7 +93,6 @@ void Renderer::Init(SVideoInitialize &_VideoInitialize)
cgGetError(); cgGetError();
cgSetErrorHandler(HandleCgError, NULL); cgSetErrorHandler(HandleCgError, NULL);
cgD3D9SetDevice(D3D::dev); cgD3D9SetDevice(D3D::dev);
g_cgvProf = cgD3D9GetLatestVertexProfile(); g_cgvProf = cgD3D9GetLatestVertexProfile();
g_cgfProf = cgD3D9GetLatestPixelProfile(); g_cgfProf = cgD3D9GetLatestPixelProfile();
@ -144,10 +143,8 @@ void Renderer::Initialize()
m_Textures.reserve(MaxTextureStages); m_Textures.reserve(MaxTextureStages);
for (int i = 0; i < MaxTextureStages; i++) for (int i = 0; i < MaxTextureStages; i++)
m_Textures.push_back(NULL); m_Textures.push_back(NULL);
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
D3D::dev->SetSamplerState(i, D3DSAMP_MAXANISOTROPY, 16); D3D::dev->SetSamplerState(i, D3DSAMP_MAXANISOTROPY, 16);
Postprocess::Initialize(); Postprocess::Initialize();
Postprocess::BeginFrame(); Postprocess::BeginFrame();
D3D::BeginFrame(true, 0); D3D::BeginFrame(true, 0);

View File

@ -61,11 +61,11 @@ void VertexShaderCache::Shutdown()
void VertexShaderCache::SetShader(u32 components) void VertexShaderCache::SetShader(u32 components)
{ {
static LPDIRECT3DVERTEXSHADER9 shader = NULL;
if (D3D::GetShaderVersion() < 2) if (D3D::GetShaderVersion() < 2)
return; // we are screwed return; // we are screwed
static LPDIRECT3DVERTEXSHADER9 lastShader = NULL; static LPDIRECT3DVERTEXSHADER9 lastShader = NULL;
DVSTARTPROFILE(); DVSTARTPROFILE();
VERTEXSHADERUID uid; VERTEXSHADERUID uid;
@ -73,7 +73,6 @@ void VertexShaderCache::SetShader(u32 components)
VSCache::iterator iter; VSCache::iterator iter;
iter = vshaders.find(uid); iter = vshaders.find(uid);
if (iter != vshaders.end()) if (iter != vshaders.end())
{ {
iter->second.frameCount = frameCount; iter->second.frameCount = frameCount;
@ -87,8 +86,7 @@ void VertexShaderCache::SetShader(u32 components)
} }
const char *code = GenerateVertexShader(components, false); const char *code = GenerateVertexShader(components, false);
//shader = D3D::CompileVertexShader(code, (int)strlen(code)); LPDIRECT3DVERTEXSHADER9 shader = CompileCgShader(code);
shader = CompileCgShader(code);
if (shader) if (shader)
{ {
// Make an entry in the table // Make an entry in the table
@ -101,10 +99,14 @@ void VertexShaderCache::SetShader(u32 components)
INCSTAT(stats.numVertexShadersCreated); INCSTAT(stats.numVertexShadersCreated);
SETSTAT(stats.numVertexShadersAlive, (int)vshaders.size()); SETSTAT(stats.numVertexShadersAlive, (int)vshaders.size());
} else } else {
PanicAlert("Failed to compile Vertex Shader:\n\n%s", code); PanicAlert("Failed to compile Vertex Shader:\n\n%s", code);
} }
D3D::dev->SetFVF(NULL);
D3D::dev->SetVertexShader(shader);
}
LPDIRECT3DVERTEXSHADER9 VertexShaderCache::CompileCgShader(const char *pstrprogram) LPDIRECT3DVERTEXSHADER9 VertexShaderCache::CompileCgShader(const char *pstrprogram)
{ {
//char stropt[64]; //char stropt[64];
@ -117,22 +119,36 @@ LPDIRECT3DVERTEXSHADER9 VertexShaderCache::CompileCgShader(const char *pstrprogr
ERROR_LOG(VIDEO, pstrprogram); ERROR_LOG(VIDEO, pstrprogram);
return NULL; return NULL;
} }
const char *pcompiledprog = cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
// This looks evil - we modify the program through the const char * we got from cgGetProgramString! LPD3DXBUFFER shader_binary;
// It SHOULD not have any nasty side effects though - but you never know... LPD3DXBUFFER error_msg;
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
char *plocal = strstr(pcompiledprog, "program.local");
while (plocal != NULL) {
const char* penv = " program.env";
memcpy(plocal, penv, 13);
plocal = strstr(plocal + 13, "program.local");
}
LPDIRECT3DVERTEXSHADER9 shader = D3D::CompileVertexShader(pcompiledprog, strlen(pcompiledprog));
// Step one - Assemble into binary code. This binary code could be cached.
if (FAILED(D3DXAssembleShader(pcompiledprog, (UINT)strlen(pcompiledprog), NULL, NULL, 0, &shader_binary, &error_msg)))
PanicAlert("Asm fail");
// Destroy Cg program as early as possible - we want as little as possible to do with Cg due to
// our rather extreme performance requirements.
cgDestroyProgram(tempprog); cgDestroyProgram(tempprog);
tempprog = NULL;
return shader; // Create vertex shader from the binary code.
LPDIRECT3DVERTEXSHADER9 vertex_shader = NULL;
if (SUCCEEDED(D3D::dev->CreateVertexShader((const DWORD *)shader_binary->GetBufferPointer(), &vertex_shader))) {
// PanicAlert("Successvertex!");
} else {
if (error_msg) {
PanicAlert("failure vertex %s", error_msg->GetBufferPointer());
MessageBox(0, pcompiledprog, 0, 0);
}
else
PanicAlert("failure vertex with no error message.");
}
if (shader_binary)
shader_binary->Release();
if (error_msg)
error_msg->Release();
return vertex_shader;
} }
void VertexShaderCache::Cleanup() void VertexShaderCache::Cleanup()

View File

@ -31,11 +31,7 @@ class VertexShaderCache
{ {
LPDIRECT3DVERTEXSHADER9 shader; LPDIRECT3DVERTEXSHADER9 shader;
int frameCount; int frameCount;
VSCacheEntry() VSCacheEntry() : shader(NULL), frameCount(0) {}
{
shader = 0;
frameCount = 0;
}
void Destroy() void Destroy()
{ {
if (shader) if (shader)