mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-13 07:58:36 +02:00
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:
parent
917fca3e70
commit
37d5360399
@ -34,24 +34,13 @@ PixelShaderCache::PSCache PixelShaderCache::PixelShaders;
|
|||||||
|
|
||||||
void SetPSConstant4f(int const_number, float f1, float f2, float f3, float f4)
|
void SetPSConstant4f(int const_number, float f1, float f2, float f3, float f4)
|
||||||
{
|
{
|
||||||
//const float f[4] = {f1, f2, f3, f4};
|
const float f[4] = {f1, f2, f3, f4};
|
||||||
//D3D::dev->SetPixelShaderConstantF(const_number, f, 1);
|
D3D::dev->SetPixelShaderConstantF(const_number, f, 1);
|
||||||
|
|
||||||
|
|
||||||
// TODO: The Cg Way
|
|
||||||
/** CGparameter param = cgGetNamedParameter(program, "someParameter");
|
|
||||||
cgSetParameter4f(param, f1, f2, f3, f4); **/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetPSConstant4fv(int const_number, const float *f)
|
void SetPSConstant4fv(int const_number, const float *f)
|
||||||
{
|
{
|
||||||
//D3D::dev->SetPixelShaderConstantF(const_number, f, 1);
|
D3D::dev->SetPixelShaderConstantF(const_number, f, 1);
|
||||||
|
|
||||||
// TODO: The Cg Way
|
|
||||||
/** CGparameter param = cgGetNamedParameter(program, "someParameter");
|
|
||||||
cgSetParameter4fv(param, f); **/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelShaderCache::Init()
|
void PixelShaderCache::Init()
|
||||||
@ -72,8 +61,7 @@ void PixelShaderCache::SetShader()
|
|||||||
if (D3D::GetShaderVersion() < 2)
|
if (D3D::GetShaderVersion() < 2)
|
||||||
return; // we are screwed
|
return; // we are screwed
|
||||||
|
|
||||||
//static LPDIRECT3DPIXELSHADER9 lastShader = 0;
|
static LPDIRECT3DPIXELSHADER9 lastShader = NULL;
|
||||||
static CGprogram lastShader = NULL;
|
|
||||||
DVSTARTPROFILE();
|
DVSTARTPROFILE();
|
||||||
|
|
||||||
PIXELSHADERUID uid;
|
PIXELSHADERUID uid;
|
||||||
@ -88,10 +76,7 @@ void PixelShaderCache::SetShader()
|
|||||||
PSCacheEntry &entry = iter->second;
|
PSCacheEntry &entry = iter->second;
|
||||||
if (!lastShader || entry.shader != lastShader)
|
if (!lastShader || entry.shader != lastShader)
|
||||||
{
|
{
|
||||||
//D3D::dev->SetPixelShader(entry.shader);
|
D3D::dev->SetPixelShader(entry.shader);
|
||||||
if(!cgD3D9IsProgramLoaded(entry.shader))
|
|
||||||
cgD3D9LoadProgram(entry.shader, false, 0);
|
|
||||||
cgD3D9BindProgram(entry.shader);
|
|
||||||
lastShader = entry.shader;
|
lastShader = entry.shader;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -99,7 +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 = D3D::CompilePixelShader(code, (int)(strlen(code)));
|
||||||
CGprogram shader = CompileCgShader(code);
|
LPDIRECT3DPIXELSHADER9 shader = CompileCgShader(code);
|
||||||
|
|
||||||
if (shader)
|
if (shader)
|
||||||
{
|
{
|
||||||
@ -109,29 +94,21 @@ void PixelShaderCache::SetShader()
|
|||||||
newentry.frameCount = frameCount;
|
newentry.frameCount = frameCount;
|
||||||
PixelShaders[uid] = newentry;
|
PixelShaders[uid] = newentry;
|
||||||
|
|
||||||
// There seems to be an unknown Cg error here for some reason
|
D3D::dev->SetPixelShader(shader);
|
||||||
///PanicAlert("Load pShader");
|
|
||||||
if(!cgD3D9IsProgramLoaded(shader))
|
|
||||||
cgD3D9LoadProgram(shader, false, 0);
|
|
||||||
cgD3D9BindProgram(shader);
|
|
||||||
D3D::dev->SetFVF(NULL);
|
|
||||||
///PanicAlert("Loaded pShader");
|
|
||||||
|
|
||||||
INCSTAT(stats.numPixelShadersCreated);
|
INCSTAT(stats.numPixelShadersCreated);
|
||||||
SETSTAT(stats.numPixelShadersAlive, (int)PixelShaders.size());
|
SETSTAT(stats.numPixelShadersAlive, (int)PixelShaders.size());
|
||||||
} else
|
} else
|
||||||
PanicAlert("Failed to compile Pixel Shader:\n\n%s", code);
|
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);
|
//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);
|
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgfProf, "main", opts);
|
||||||
if (!cgIsProgram(tempprog) || cgGetError() != CG_NO_ERROR) {
|
if (!cgIsProgram(tempprog) || cgGetError() != CG_NO_ERROR) {
|
||||||
ERROR_LOG(VIDEO, "Failed to create ps %s:\n", cgGetLastListing(g_cgcontext));
|
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");
|
plocal = strstr(plocal+13, "program.local");
|
||||||
}
|
}
|
||||||
|
|
||||||
return tempprog;
|
LPDIRECT3DPIXELSHADER9 shader = D3D::CompilePixelShader(pcompiledprog, strlen(pcompiledprog));
|
||||||
|
|
||||||
|
cgDestroyProgram(tempprog);
|
||||||
|
|
||||||
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,9 +25,6 @@
|
|||||||
#include "PixelShaderGen.h"
|
#include "PixelShaderGen.h"
|
||||||
#include "VertexShaderGen.h"
|
#include "VertexShaderGen.h"
|
||||||
|
|
||||||
#include <Cg/cg.h>
|
|
||||||
#include <Cg/cgD3D9.h>
|
|
||||||
|
|
||||||
typedef u32 tevhash;
|
typedef u32 tevhash;
|
||||||
|
|
||||||
tevhash GetCurrentTEV();
|
tevhash GetCurrentTEV();
|
||||||
@ -36,8 +33,7 @@ class PixelShaderCache
|
|||||||
{
|
{
|
||||||
struct PSCacheEntry
|
struct PSCacheEntry
|
||||||
{
|
{
|
||||||
//LPDIRECT3DPIXELSHADER9 shader;
|
LPDIRECT3DPIXELSHADER9 shader;
|
||||||
CGprogram shader;
|
|
||||||
|
|
||||||
int frameCount;
|
int frameCount;
|
||||||
PSCacheEntry()
|
PSCacheEntry()
|
||||||
@ -47,12 +43,8 @@ class PixelShaderCache
|
|||||||
}
|
}
|
||||||
void Destroy()
|
void Destroy()
|
||||||
{
|
{
|
||||||
if (shader) {
|
if (shader)
|
||||||
cgD3D9UnloadProgram(shader);
|
shader->Release();
|
||||||
cgDestroyProgram(shader);
|
|
||||||
// shader->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -65,7 +57,7 @@ public:
|
|||||||
static void Cleanup();
|
static void Cleanup();
|
||||||
static void Shutdown();
|
static void Shutdown();
|
||||||
static void SetShader();
|
static void SetShader();
|
||||||
static CGprogram CompileCgShader(const char *pstrprogram);
|
static LPDIRECT3DPIXELSHADER9 CompileCgShader(const char *pstrprogram);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,23 +34,13 @@ VertexShaderCache::VSCache VertexShaderCache::vshaders;
|
|||||||
|
|
||||||
void SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4)
|
void SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4)
|
||||||
{
|
{
|
||||||
//const float f[4] = {f1, f2, f3, f4};
|
const float f[4] = {f1, f2, f3, f4};
|
||||||
//D3D::dev->SetVertexShaderConstantF(const_number, f, 1);
|
D3D::dev->SetVertexShaderConstantF(const_number, f, 1);
|
||||||
|
|
||||||
|
|
||||||
// TODO: The Cg Way
|
|
||||||
/** CGparameter param = cgGetNamedParameter(program, "someParameter");
|
|
||||||
cgSetParameter4f(param, f1, f2, f3, f4); **/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetVSConstant4fv(int const_number, const float *f)
|
void SetVSConstant4fv(int const_number, const float *f)
|
||||||
{
|
{
|
||||||
//D3D::dev->SetVertexShaderConstantF(const_number, f, 1);
|
D3D::dev->SetVertexShaderConstantF(const_number, f, 1);
|
||||||
|
|
||||||
|
|
||||||
// TODO: The Cg Way
|
|
||||||
/** CGparameter param = cgGetNamedParameter(program, "someParameter");
|
|
||||||
cgSetParameter4fv(param, f); **/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -71,11 +61,11 @@ void VertexShaderCache::Shutdown()
|
|||||||
|
|
||||||
void VertexShaderCache::SetShader(u32 components)
|
void VertexShaderCache::SetShader(u32 components)
|
||||||
{
|
{
|
||||||
static CGprogram shader = NULL;
|
static LPDIRECT3DVERTEXSHADER9 shader = NULL;
|
||||||
if (D3D::GetShaderVersion() < 2)
|
if (D3D::GetShaderVersion() < 2)
|
||||||
return; // we are screwed
|
return; // we are screwed
|
||||||
|
|
||||||
static CGprogram lastShader = NULL;
|
static LPDIRECT3DVERTEXSHADER9 lastShader = NULL;
|
||||||
DVSTARTPROFILE();
|
DVSTARTPROFILE();
|
||||||
|
|
||||||
VERTEXSHADERUID uid;
|
VERTEXSHADERUID uid;
|
||||||
@ -90,10 +80,7 @@ void VertexShaderCache::SetShader(u32 components)
|
|||||||
VSCacheEntry &entry = iter->second;
|
VSCacheEntry &entry = iter->second;
|
||||||
if (!lastShader || entry.shader != lastShader)
|
if (!lastShader || entry.shader != lastShader)
|
||||||
{
|
{
|
||||||
//D3D::dev->SetVertexShader(entry.shader);
|
D3D::dev->SetVertexShader(entry.shader);
|
||||||
if(!cgD3D9IsProgramLoaded(entry.shader))
|
|
||||||
cgD3D9LoadProgram(entry.shader, false, 0);
|
|
||||||
cgD3D9BindProgram(entry.shader);
|
|
||||||
lastShader = entry.shader;
|
lastShader = entry.shader;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -110,28 +97,20 @@ void VertexShaderCache::SetShader(u32 components)
|
|||||||
entry.frameCount = frameCount;
|
entry.frameCount = frameCount;
|
||||||
vshaders[uid] = entry;
|
vshaders[uid] = entry;
|
||||||
|
|
||||||
// There seems to be an unknown Cg error here for some reason
|
D3D::dev->SetVertexShader(shader);
|
||||||
///PanicAlert("Load vShader");
|
|
||||||
if(!cgD3D9IsProgramLoaded(shader))
|
|
||||||
cgD3D9LoadProgram(shader, false, 0);
|
|
||||||
cgD3D9BindProgram(shader);
|
|
||||||
D3D::dev->SetFVF(NULL);
|
|
||||||
///PanicAlert("Loaded vShader");
|
|
||||||
|
|
||||||
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->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);
|
//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_cgvProf, "main", opts);
|
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", opts);
|
||||||
if (!cgIsProgram(tempprog) || cgGetError() != CG_NO_ERROR) {
|
if (!cgIsProgram(tempprog) || cgGetError() != CG_NO_ERROR) {
|
||||||
ERROR_LOG(VIDEO, "Failed to load vs %s:\n", cgGetLastListing(g_cgcontext));
|
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");
|
plocal = strstr(plocal + 13, "program.local");
|
||||||
}
|
}
|
||||||
|
|
||||||
return tempprog;
|
LPDIRECT3DVERTEXSHADER9 shader = D3D::CompileVertexShader(pcompiledprog, strlen(pcompiledprog));
|
||||||
|
|
||||||
|
cgDestroyProgram(tempprog);
|
||||||
|
|
||||||
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexShaderCache::Cleanup()
|
void VertexShaderCache::Cleanup()
|
||||||
|
@ -25,15 +25,11 @@
|
|||||||
#include "D3DBase.h"
|
#include "D3DBase.h"
|
||||||
#include "VertexShaderGen.h"
|
#include "VertexShaderGen.h"
|
||||||
|
|
||||||
#include <Cg/cg.h>
|
|
||||||
#include <Cg/cgD3D9.h>
|
|
||||||
|
|
||||||
class VertexShaderCache
|
class VertexShaderCache
|
||||||
{
|
{
|
||||||
struct VSCacheEntry
|
struct VSCacheEntry
|
||||||
{
|
{
|
||||||
//LPDIRECT3DVERTEXSHADER9 shader;
|
LPDIRECT3DVERTEXSHADER9 shader;
|
||||||
CGprogram shader;
|
|
||||||
int frameCount;
|
int frameCount;
|
||||||
VSCacheEntry()
|
VSCacheEntry()
|
||||||
{
|
{
|
||||||
@ -42,11 +38,8 @@ class VertexShaderCache
|
|||||||
}
|
}
|
||||||
void Destroy()
|
void Destroy()
|
||||||
{
|
{
|
||||||
if (shader) {
|
if (shader)
|
||||||
cgD3D9UnloadProgram(shader);
|
shader->Release();
|
||||||
cgDestroyProgram(shader);
|
|
||||||
// shader->Release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -59,7 +52,7 @@ public:
|
|||||||
static void Cleanup();
|
static void Cleanup();
|
||||||
static void Shutdown();
|
static void Shutdown();
|
||||||
static void SetShader(u32 components);
|
static void SetShader(u32 components);
|
||||||
static CGprogram CompileCgShader(const char *pstrprogram);
|
static LPDIRECT3DVERTEXSHADER9 CompileCgShader(const char *pstrprogram);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _VERTEXSHADERCACHE_H
|
#endif // _VERTEXSHADERCACHE_H
|
||||||
|
Loading…
Reference in New Issue
Block a user