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

View File

@ -35,7 +35,7 @@ PixelShaderCache::PSCache PixelShaderCache::PixelShaders;
void SetPSConstant4f(int const_number, float f1, float f2, float f3, float f4)
{
const float f[4] = {f1, f2, f3, f4};
D3D::dev->SetPixelShaderConstantF(const_number, f, 1);
D3D::dev->SetPixelShaderConstantF(const_number, f, 1);
}
void SetPSConstant4fv(int const_number, const float *f)
@ -62,7 +62,8 @@ void PixelShaderCache::SetShader()
return; // we are screwed
static LPDIRECT3DPIXELSHADER9 lastShader = NULL;
DVSTARTPROFILE();
DVSTARTPROFILE();
PIXELSHADERUID uid;
GetPixelShaderId(uid, PixelShaderManager::GetTextureMask(), false, false);
@ -83,9 +84,7 @@ void PixelShaderCache::SetShader()
}
const char *code = GeneratePixelShader(PixelShaderManager::GetTextureMask(), false, false);
//LPDIRECT3DPIXELSHADER9 shader = D3D::CompilePixelShader(code, (int)(strlen(code)));
LPDIRECT3DPIXELSHADER9 shader = CompileCgShader(code);
if (shader)
{
//Make an entry in the table
@ -94,6 +93,7 @@ void PixelShaderCache::SetShader()
newentry.frameCount = frameCount;
PixelShaders[uid] = newentry;
D3D::dev->SetFVF(NULL);
D3D::dev->SetPixelShader(shader);
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!
// It SHOULD not have any nasty side effects though - but you never know...
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");
}
LPDIRECT3DPIXELSHADER9 shader = D3D::CompilePixelShader(pcompiledprog, strlen(pcompiledprog));
LPD3DXBUFFER shader_binary;
LPD3DXBUFFER error_msg;
// 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);
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
{
LPDIRECT3DPIXELSHADER9 shader;
int frameCount;
PSCacheEntry()
{
shader = 0;
frameCount = 0;
}
PSCacheEntry() : shader(NULL), frameCount(0) {}
void Destroy()
{
if (shader)

View File

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

View File

@ -61,11 +61,11 @@ void VertexShaderCache::Shutdown()
void VertexShaderCache::SetShader(u32 components)
{
static LPDIRECT3DVERTEXSHADER9 shader = NULL;
if (D3D::GetShaderVersion() < 2)
return; // we are screwed
static LPDIRECT3DVERTEXSHADER9 lastShader = NULL;
DVSTARTPROFILE();
VERTEXSHADERUID uid;
@ -73,7 +73,6 @@ void VertexShaderCache::SetShader(u32 components)
VSCache::iterator iter;
iter = vshaders.find(uid);
if (iter != vshaders.end())
{
iter->second.frameCount = frameCount;
@ -87,11 +86,10 @@ void VertexShaderCache::SetShader(u32 components)
}
const char *code = GenerateVertexShader(components, false);
//shader = D3D::CompileVertexShader(code, (int)strlen(code));
shader = CompileCgShader(code);
LPDIRECT3DVERTEXSHADER9 shader = CompileCgShader(code);
if (shader)
{
//Make an entry in the table
// Make an entry in the table
VSCacheEntry entry;
entry.shader = shader;
entry.frameCount = frameCount;
@ -101,8 +99,12 @@ void VertexShaderCache::SetShader(u32 components)
INCSTAT(stats.numVertexShadersCreated);
SETSTAT(stats.numVertexShadersAlive, (int)vshaders.size());
} else
} else {
PanicAlert("Failed to compile Vertex Shader:\n\n%s", code);
}
D3D::dev->SetFVF(NULL);
D3D::dev->SetVertexShader(shader);
}
LPDIRECT3DVERTEXSHADER9 VertexShaderCache::CompileCgShader(const char *pstrprogram)
@ -117,22 +119,36 @@ LPDIRECT3DVERTEXSHADER9 VertexShaderCache::CompileCgShader(const char *pstrprogr
ERROR_LOG(VIDEO, pstrprogram);
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!
// It SHOULD not have any nasty side effects though - but you never know...
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));
LPD3DXBUFFER shader_binary;
LPD3DXBUFFER error_msg;
// 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);
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()

View File

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

View File

@ -315,7 +315,7 @@ HRESULT ScreenShot(const char *File)
void Video_Screenshot(const char *_szFilename)
{
if(ScreenShot(_szFilename) != S_OK)
if (ScreenShot(_szFilename) != S_OK)
PanicAlert("Error while capturing screen");
else {
std::string message = "Saved ";