From 37d536039964d5d3a35126f5c5fa325385801365 Mon Sep 17 00:00:00 2001 From: "XTra.KrazzY" Date: Sun, 1 Mar 2009 10:38:04 +0000 Subject: [PATCH] One step closer towards CgD3D to work. Now something is being compiled twice... git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2501 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Plugin_VideoDX9/Src/PixelShaderCache.cpp | 51 ++++++------------- .../Plugin_VideoDX9/Src/PixelShaderCache.h | 18 ++----- .../Plugin_VideoDX9/Src/VertexShaderCache.cpp | 49 ++++++------------ .../Plugin_VideoDX9/Src/VertexShaderCache.h | 15 ++---- 4 files changed, 41 insertions(+), 92 deletions(-) diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp index a291e444e8..16074e5d5e 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp @@ -34,24 +34,13 @@ 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); - - - // TODO: The Cg Way - /** CGparameter param = cgGetNamedParameter(program, "someParameter"); - cgSetParameter4f(param, f1, f2, f3, f4); **/ - + const float f[4] = {f1, f2, f3, f4}; + D3D::dev->SetPixelShaderConstantF(const_number, f, 1); } void SetPSConstant4fv(int const_number, const float *f) { - //D3D::dev->SetPixelShaderConstantF(const_number, f, 1); - - // TODO: The Cg Way - /** CGparameter param = cgGetNamedParameter(program, "someParameter"); - cgSetParameter4fv(param, f); **/ - + D3D::dev->SetPixelShaderConstantF(const_number, f, 1); } void PixelShaderCache::Init() @@ -72,8 +61,7 @@ void PixelShaderCache::SetShader() if (D3D::GetShaderVersion() < 2) return; // we are screwed - //static LPDIRECT3DPIXELSHADER9 lastShader = 0; - static CGprogram lastShader = NULL; + static LPDIRECT3DPIXELSHADER9 lastShader = NULL; DVSTARTPROFILE(); PIXELSHADERUID uid; @@ -88,10 +76,7 @@ void PixelShaderCache::SetShader() PSCacheEntry &entry = iter->second; if (!lastShader || entry.shader != lastShader) { - //D3D::dev->SetPixelShader(entry.shader); - if(!cgD3D9IsProgramLoaded(entry.shader)) - cgD3D9LoadProgram(entry.shader, false, 0); - cgD3D9BindProgram(entry.shader); + D3D::dev->SetPixelShader(entry.shader); lastShader = entry.shader; } return; @@ -99,7 +84,7 @@ void PixelShaderCache::SetShader() const char *code = GeneratePixelShader(PixelShaderManager::GetTextureMask(), false, false); //LPDIRECT3DPIXELSHADER9 shader = D3D::CompilePixelShader(code, (int)(strlen(code))); - CGprogram shader = CompileCgShader(code); + LPDIRECT3DPIXELSHADER9 shader = CompileCgShader(code); if (shader) { @@ -109,29 +94,21 @@ void PixelShaderCache::SetShader() newentry.frameCount = frameCount; PixelShaders[uid] = newentry; - // There seems to be an unknown Cg error here for some reason - ///PanicAlert("Load pShader"); - if(!cgD3D9IsProgramLoaded(shader)) - cgD3D9LoadProgram(shader, false, 0); - cgD3D9BindProgram(shader); - D3D::dev->SetFVF(NULL); - ///PanicAlert("Loaded pShader"); + D3D::dev->SetPixelShader(shader); INCSTAT(stats.numPixelShadersCreated); SETSTAT(stats.numPixelShadersAlive, (int)PixelShaders.size()); } else PanicAlert("Failed to compile Pixel Shader:\n\n%s", code); - - //D3D::dev->SetPixelShader(shader); } -CGprogram PixelShaderCache::CompileCgShader(const char *pstrprogram) +LPDIRECT3DPIXELSHADER9 PixelShaderCache::CompileCgShader(const char *pstrprogram) { - char stropt[64]; + //char stropt[64]; //sprintf(stropt, "MaxLocalParams=256,MaxInstructions=%d", s_nMaxVertexInstructions); - //const char *opts[] = {"-profileopts", stropt, "-O2", "-q", NULL}; + const char *opts[] = {"-profileopts", "MaxLocalParams=256", "-O2", "-q", NULL}; - const char **opts = cgD3D9GetOptimalOptions(g_cgvProf); + //const char **opts = cgD3D9GetOptimalOptions(g_cgvProf); CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgfProf, "main", opts); if (!cgIsProgram(tempprog) || cgGetError() != CG_NO_ERROR) { ERROR_LOG(VIDEO, "Failed to create ps %s:\n", cgGetLastListing(g_cgcontext)); @@ -149,7 +126,11 @@ CGprogram PixelShaderCache::CompileCgShader(const char *pstrprogram) plocal = strstr(plocal+13, "program.local"); } - return tempprog; + LPDIRECT3DPIXELSHADER9 shader = D3D::CompilePixelShader(pcompiledprog, strlen(pcompiledprog)); + + cgDestroyProgram(tempprog); + + return shader; } diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h index e69df35643..a4b9ad7719 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h @@ -25,9 +25,6 @@ #include "PixelShaderGen.h" #include "VertexShaderGen.h" -#include -#include - typedef u32 tevhash; tevhash GetCurrentTEV(); @@ -36,9 +33,8 @@ class PixelShaderCache { struct PSCacheEntry { - //LPDIRECT3DPIXELSHADER9 shader; - CGprogram shader; - + LPDIRECT3DPIXELSHADER9 shader; + int frameCount; PSCacheEntry() { @@ -47,12 +43,8 @@ class PixelShaderCache } void Destroy() { - if (shader) { - cgD3D9UnloadProgram(shader); - cgDestroyProgram(shader); - // shader->Release(); - } - + if (shader) + shader->Release(); } }; @@ -65,7 +57,7 @@ public: static void Cleanup(); static void Shutdown(); static void SetShader(); - static CGprogram CompileCgShader(const char *pstrprogram); + static LPDIRECT3DPIXELSHADER9 CompileCgShader(const char *pstrprogram); }; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp index 5e10d883f1..6f2dda61b4 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp @@ -34,23 +34,13 @@ VertexShaderCache::VSCache VertexShaderCache::vshaders; void SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4) { - //const float f[4] = {f1, f2, f3, f4}; - //D3D::dev->SetVertexShaderConstantF(const_number, f, 1); - - - // TODO: The Cg Way - /** CGparameter param = cgGetNamedParameter(program, "someParameter"); - cgSetParameter4f(param, f1, f2, f3, f4); **/ + const float f[4] = {f1, f2, f3, f4}; + D3D::dev->SetVertexShaderConstantF(const_number, f, 1); } void SetVSConstant4fv(int const_number, const float *f) { - //D3D::dev->SetVertexShaderConstantF(const_number, f, 1); - - - // TODO: The Cg Way - /** CGparameter param = cgGetNamedParameter(program, "someParameter"); - cgSetParameter4fv(param, f); **/ + D3D::dev->SetVertexShaderConstantF(const_number, f, 1); } @@ -71,11 +61,11 @@ void VertexShaderCache::Shutdown() void VertexShaderCache::SetShader(u32 components) { - static CGprogram shader = NULL; + static LPDIRECT3DVERTEXSHADER9 shader = NULL; if (D3D::GetShaderVersion() < 2) return; // we are screwed - static CGprogram lastShader = NULL; + static LPDIRECT3DVERTEXSHADER9 lastShader = NULL; DVSTARTPROFILE(); VERTEXSHADERUID uid; @@ -90,10 +80,7 @@ void VertexShaderCache::SetShader(u32 components) VSCacheEntry &entry = iter->second; if (!lastShader || entry.shader != lastShader) { - //D3D::dev->SetVertexShader(entry.shader); - if(!cgD3D9IsProgramLoaded(entry.shader)) - cgD3D9LoadProgram(entry.shader, false, 0); - cgD3D9BindProgram(entry.shader); + D3D::dev->SetVertexShader(entry.shader); lastShader = entry.shader; } return; @@ -110,28 +97,20 @@ void VertexShaderCache::SetShader(u32 components) entry.frameCount = frameCount; vshaders[uid] = entry; - // There seems to be an unknown Cg error here for some reason - ///PanicAlert("Load vShader"); - if(!cgD3D9IsProgramLoaded(shader)) - cgD3D9LoadProgram(shader, false, 0); - cgD3D9BindProgram(shader); - D3D::dev->SetFVF(NULL); - ///PanicAlert("Loaded vShader"); + D3D::dev->SetVertexShader(shader); INCSTAT(stats.numVertexShadersCreated); SETSTAT(stats.numVertexShadersAlive, (int)vshaders.size()); } else PanicAlert("Failed to compile Vertex Shader:\n\n%s", code); - - //D3D::dev->SetVertexShader(shader); } -CGprogram VertexShaderCache::CompileCgShader(const char *pstrprogram) +LPDIRECT3DVERTEXSHADER9 VertexShaderCache::CompileCgShader(const char *pstrprogram) { - char stropt[64]; + //char stropt[64]; //sprintf(stropt, "MaxLocalParams=256,MaxInstructions=%d", s_nMaxVertexInstructions); - //const char *opts[] = {"-profileopts", stropt, "-O2", "-q", NULL}; - const char **opts = cgD3D9GetOptimalOptions(g_cgvProf); + const char *opts[] = {"-profileopts", "MaxLocalParams=256", "-O2", "-q", NULL}; + //const char **opts = cgD3D9GetOptimalOptions(g_cgvProf); CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", opts); if (!cgIsProgram(tempprog) || cgGetError() != CG_NO_ERROR) { ERROR_LOG(VIDEO, "Failed to load vs %s:\n", cgGetLastListing(g_cgcontext)); @@ -149,7 +128,11 @@ CGprogram VertexShaderCache::CompileCgShader(const char *pstrprogram) plocal = strstr(plocal + 13, "program.local"); } - return tempprog; + LPDIRECT3DVERTEXSHADER9 shader = D3D::CompileVertexShader(pcompiledprog, strlen(pcompiledprog)); + + cgDestroyProgram(tempprog); + + return shader; } void VertexShaderCache::Cleanup() diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.h b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.h index b34d123d0e..0131d7947e 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.h @@ -25,15 +25,11 @@ #include "D3DBase.h" #include "VertexShaderGen.h" -#include -#include - class VertexShaderCache { struct VSCacheEntry { - //LPDIRECT3DVERTEXSHADER9 shader; - CGprogram shader; + LPDIRECT3DVERTEXSHADER9 shader; int frameCount; VSCacheEntry() { @@ -42,11 +38,8 @@ class VertexShaderCache } void Destroy() { - if (shader) { - cgD3D9UnloadProgram(shader); - cgDestroyProgram(shader); - // shader->Release(); - } + if (shader) + shader->Release(); } }; @@ -59,7 +52,7 @@ public: static void Cleanup(); static void Shutdown(); static void SetShader(u32 components); - static CGprogram CompileCgShader(const char *pstrprogram); + static LPDIRECT3DVERTEXSHADER9 CompileCgShader(const char *pstrprogram); }; #endif // _VERTEXSHADERCACHE_H