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
This commit is contained in:
XTra.KrazzY 2009-03-01 10:38:04 +00:00
parent 917fca3e70
commit 37d5360399
4 changed files with 41 additions and 92 deletions

View File

@ -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;
}

View File

@ -25,9 +25,6 @@
#include "PixelShaderGen.h"
#include "VertexShaderGen.h"
#include <Cg/cg.h>
#include <Cg/cgD3D9.h>
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);
};

View File

@ -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()

View File

@ -25,15 +25,11 @@
#include "D3DBase.h"
#include "VertexShaderGen.h"
#include <Cg/cg.h>
#include <Cg/cgD3D9.h>
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