revert the mess i made in the d3d plugin. Add way to use HLSL directly without going through Cg. Not that the results look much better... i do see shadows of spinning cars in Burnout 2 after clicking around in the dark. Then it crashes.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2504 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
fca8d04a11
commit
7607d6dc6a
|
@ -133,7 +133,7 @@ void GetPixelShaderId(PIXELSHADERUID &uid, u32 s_texturemask, u32 zbufrender, u3
|
|||
static void WriteStage(char *&p, int n, u32 texture_mask);
|
||||
static void WrapNonPow2Tex(char* &p, const char* var, int texmap, u32 texture_mask);
|
||||
static void WriteAlphaCompare(char *&p, int num, int comp);
|
||||
static bool WriteAlphaTest(char *&p);
|
||||
static bool WriteAlphaTest(char *&p, bool HLSL);
|
||||
static void WriteFog(char *&p, bool bOutputZ);
|
||||
|
||||
const float epsilon8bit = 1.0f / 255.0f;
|
||||
|
@ -369,7 +369,7 @@ static void BuildSwapModeTable()
|
|||
}
|
||||
}
|
||||
|
||||
const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRenderZToCol0)
|
||||
const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRenderZToCol0, bool HLSL)
|
||||
{
|
||||
text[sizeof(text) - 1] = 0x7C; // canary
|
||||
DVSTARTPROFILE();
|
||||
|
@ -516,7 +516,7 @@ const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool
|
|||
|
||||
//if (bpmem.genMode.numindstages ) WRITE(p, "prev.rg = indtex0.xy;\nprev.b = 0;\n");
|
||||
|
||||
if (!WriteAlphaTest(p)) {
|
||||
if (!WriteAlphaTest(p, HLSL)) {
|
||||
// alpha test will always fail, so restart the shader and just make it an empty function
|
||||
p = pmainstart;
|
||||
WRITE(p, "discard;\n");
|
||||
|
@ -535,6 +535,8 @@ const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool
|
|||
*/
|
||||
WriteFog(p, bOutputZ);
|
||||
WRITE(p, " ocol0 = prev;\n");
|
||||
} else {
|
||||
WRITE(p, " ocol0 = prev;\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -889,7 +891,7 @@ static void WriteAlphaCompare(char *&p, int num, int comp)
|
|||
}
|
||||
}
|
||||
|
||||
static bool WriteAlphaTest(char *&p)
|
||||
static bool WriteAlphaTest(char *&p, bool HLSL)
|
||||
{
|
||||
u32 op = bpmem.alphaFunc.logic;
|
||||
u32 comp[2] = {bpmem.alphaFunc.comp0,bpmem.alphaFunc.comp1};
|
||||
|
@ -928,7 +930,11 @@ static bool WriteAlphaTest(char *&p)
|
|||
}
|
||||
|
||||
// Seems we need discard for Cg and clip for d3d. sigh.
|
||||
if (HLSL)
|
||||
WRITE(p, "clip( ");
|
||||
else {
|
||||
WRITE(p, "discard( ");
|
||||
}
|
||||
WriteAlphaCompare(p, 0, bpmem.alphaFunc.comp0);
|
||||
|
||||
// negated because testing the inverse condition
|
||||
|
|
|
@ -91,7 +91,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRenderZToCol0);
|
||||
const char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRenderZToCol0, bool HLSL = false);
|
||||
void GetPixelShaderId(PIXELSHADERUID &, u32 s_texturemask, u32 zbufrender, u32 zBufRenderToCol0);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,18 +24,18 @@
|
|||
namespace D3D
|
||||
{
|
||||
|
||||
LPDIRECT3DVERTEXSHADER9 CompileVertexShader(const char *code, int len)
|
||||
LPDIRECT3DVERTEXSHADER9 CompileVertexShader(const char *code, int len, bool assembly)
|
||||
{
|
||||
//try to compile
|
||||
LPD3DXBUFFER shaderBuffer = 0;
|
||||
LPD3DXBUFFER errorBuffer = 0;
|
||||
LPDIRECT3DVERTEXSHADER9 vShader = 0;
|
||||
HRESULT hr = D3DXAssembleShader(code, len, 0, 0, 0, &shaderBuffer, &errorBuffer);
|
||||
/*if (FAILED(hr))
|
||||
{
|
||||
//let's try 2.0
|
||||
HRESULT hr;
|
||||
|
||||
if (assembly)
|
||||
hr = D3DXAssembleShader(code, len, 0, 0, 0, &shaderBuffer, &errorBuffer);
|
||||
else
|
||||
hr = D3DXCompileShader(code, len, 0, 0, "main", "vs_2_0", 0, &shaderBuffer, &errorBuffer, 0);
|
||||
}*/
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
|
@ -67,14 +67,19 @@ LPDIRECT3DVERTEXSHADER9 CompileVertexShader(const char *code, int len)
|
|||
return vShader;
|
||||
}
|
||||
|
||||
LPDIRECT3DPIXELSHADER9 CompilePixelShader(const char *code, int len)
|
||||
LPDIRECT3DPIXELSHADER9 CompilePixelShader(const char *code, int len, bool assembly)
|
||||
{
|
||||
LPD3DXBUFFER shaderBuffer = 0;
|
||||
LPD3DXBUFFER errorBuffer = 0;
|
||||
LPDIRECT3DPIXELSHADER9 pShader = 0;
|
||||
static char *versions[6] = {"ERROR", "ps_1_1", "ps_1_4", "ps_2_0", "ps_3_0", "ps_4_0"};
|
||||
|
||||
HRESULT hr = D3DXAssembleShader(code, len, 0, 0, 0, &shaderBuffer, &errorBuffer);
|
||||
HRESULT hr;
|
||||
if (assembly)
|
||||
hr = D3DXAssembleShader(code, len, 0, 0, 0, &shaderBuffer, &errorBuffer);
|
||||
else
|
||||
hr = D3DXCompileShader(code, len, 0, 0, "main", "ps_2_0", // Pixel Shader 2.0 is enough for all we do
|
||||
0, &shaderBuffer, &errorBuffer, 0);
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
|
|
|
@ -21,6 +21,6 @@
|
|||
|
||||
namespace D3D
|
||||
{
|
||||
LPDIRECT3DVERTEXSHADER9 CompileVertexShader(const char *code, int len);
|
||||
LPDIRECT3DPIXELSHADER9 CompilePixelShader(const char *code, int len);
|
||||
LPDIRECT3DVERTEXSHADER9 CompileVertexShader(const char *code, int len, bool assembly);
|
||||
LPDIRECT3DPIXELSHADER9 CompilePixelShader(const char *code, int len, bool assembly);
|
||||
}
|
|
@ -83,8 +83,9 @@ void PixelShaderCache::SetShader()
|
|||
return;
|
||||
}
|
||||
|
||||
const char *code = GeneratePixelShader(PixelShaderManager::GetTextureMask(), false, false);
|
||||
LPDIRECT3DPIXELSHADER9 shader = CompileCgShader(code);
|
||||
bool HLSL = false;
|
||||
const char *code = GeneratePixelShader(PixelShaderManager::GetTextureMask(), false, false, HLSL);
|
||||
LPDIRECT3DPIXELSHADER9 shader = HLSL ? D3D::CompilePixelShader(code, strlen(code), false) : CompileCgShader(code);
|
||||
if (shader)
|
||||
{
|
||||
//Make an entry in the table
|
||||
|
@ -104,10 +105,7 @@ void PixelShaderCache::SetShader()
|
|||
|
||||
LPDIRECT3DPIXELSHADER9 PixelShaderCache::CompileCgShader(const char *pstrprogram)
|
||||
{
|
||||
//char stropt[64];
|
||||
//sprintf(stropt, "MaxLocalParams=256,MaxInstructions=%d", s_nMaxVertexInstructions);
|
||||
const char *opts[] = {"-profileopts", "MaxLocalParams=256", "-O2", "-q", NULL};
|
||||
|
||||
//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) {
|
||||
|
@ -116,36 +114,11 @@ LPDIRECT3DPIXELSHADER9 PixelShaderCache::CompileCgShader(const char *pstrprogram
|
|||
return false;
|
||||
}
|
||||
|
||||
// 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);
|
||||
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.
|
||||
LPDIRECT3DPIXELSHADER9 pixel_shader = D3D::CompilePixelShader(pcompiledprog, (int)strlen(pcompiledprog), true);
|
||||
cgDestroyProgram(tempprog);
|
||||
tempprog = NULL;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -85,10 +85,6 @@ void Renderer::Init(SVideoInitialize &_VideoInitialize)
|
|||
EmuWindow::SetSize(g_Res[g_Config.iWindowedRes][0], g_Res[g_Config.iWindowedRes][1]);
|
||||
|
||||
D3D::Create(g_Config.iAdapter, EmuWindow::GetWnd(), g_Config.bFullscreen, g_Config.iFSResolution, g_Config.iMultisampleMode);
|
||||
|
||||
D3DVIEWPORT9 vp;
|
||||
D3D::dev->GetViewport(&vp);
|
||||
|
||||
g_cgcontext = cgCreateContext();
|
||||
|
||||
cgGetError();
|
||||
|
@ -97,31 +93,23 @@ void Renderer::Init(SVideoInitialize &_VideoInitialize)
|
|||
g_cgvProf = cgD3D9GetLatestVertexProfile();
|
||||
g_cgfProf = cgD3D9GetLatestPixelProfile();
|
||||
|
||||
float width = (float)D3D::GetDisplayWidth();
|
||||
float height = (float)D3D::GetDisplayHeight();
|
||||
|
||||
m_x = 0;
|
||||
m_y = 0;
|
||||
m_width = (float)vp.Width;
|
||||
m_height = (float)vp.Height;
|
||||
xScale = 640.0f / (float)vp.Width;
|
||||
yScale = 480.0f / (float)vp.Height;
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
xScale = width / (float)EFB_WIDTH;
|
||||
yScale = height / (float)EFB_HEIGHT;
|
||||
|
||||
// We're not using much fixed function. Let's just set the matrices to identity.
|
||||
D3DXMATRIX mtx;
|
||||
D3DXMatrixIdentity(&mtx);
|
||||
D3D::dev->SetTransform(D3DTS_VIEW, &mtx);
|
||||
D3D::dev->SetTransform(D3DTS_WORLD, &mtx);
|
||||
float width = (float)D3D::GetDisplayWidth();
|
||||
float height = (float)D3D::GetDisplayHeight();
|
||||
|
||||
xScale = width/640.0f;
|
||||
yScale = height/480.0f;
|
||||
/*
|
||||
RECT rc =
|
||||
{
|
||||
(LONG)(m_x*xScale),
|
||||
(LONG)(m_y*yScale),
|
||||
(LONG)(m_width*xScale),
|
||||
(LONG)(m_height*yScale)
|
||||
};
|
||||
*/
|
||||
|
||||
D3D::font.Init();
|
||||
Initialize();
|
||||
}
|
||||
|
@ -145,6 +133,7 @@ void Renderer::Initialize()
|
|||
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);
|
||||
|
@ -158,7 +147,8 @@ void Renderer::AddMessage(const std::string &message, u32 ms)
|
|||
|
||||
void Renderer::ProcessMessages()
|
||||
{
|
||||
if (s_listMsgs.size() > 0) {
|
||||
if (s_listMsgs.size() > 0)
|
||||
{
|
||||
int left = 25, top = 15;
|
||||
std::list<Message>::iterator it = s_listMsgs.begin();
|
||||
|
||||
|
@ -213,8 +203,6 @@ void Renderer::SwapBuffers()
|
|||
int height = rcWindow.bottom - rcWindow.top;
|
||||
|
||||
::MoveWindow(EmuWindow::GetWnd(), 0, 0, width, height, FALSE);
|
||||
// nBackbufferWidth = width;
|
||||
// nBackbufferHeight = height;
|
||||
}
|
||||
|
||||
//Finish up the current frame, print some stats
|
||||
|
@ -290,6 +278,7 @@ void Renderer::SwapBuffers()
|
|||
rc.right = (LONG)m_width;
|
||||
rc.bottom = (LONG)m_height;
|
||||
D3D::dev->SetScissorRect(&rc);
|
||||
D3D::dev->SetRenderState(D3DRS_SCISSORTESTENABLE, false);
|
||||
|
||||
D3D::dev->Clear(0, 0, D3DCLEAR_TARGET, 0x101010, 0, 0);
|
||||
u32 clearColor = (bpmem.clearcolorAR << 16) | bpmem.clearcolorGB;
|
||||
|
@ -347,6 +336,7 @@ void Renderer::SetViewport(float* _Viewport)
|
|||
|
||||
void Renderer::SetScissorRect()
|
||||
{
|
||||
/*
|
||||
RECT rc = {0,0,0,0}; // FIXX
|
||||
rc.left = (int)(rc.left * xScale);
|
||||
rc.top = (int)(rc.top * yScale);
|
||||
|
@ -355,7 +345,7 @@ void Renderer::SetScissorRect()
|
|||
if (rc.right >= rc.left && rc.bottom >= rc.top)
|
||||
D3D::dev->SetScissorRect(&rc);
|
||||
else
|
||||
g_VideoInitialize.pLog("SCISSOR ERROR", FALSE);
|
||||
g_VideoInitialize.pLog("SCISSOR ERROR", FALSE);*/
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -493,10 +483,6 @@ void UpdateViewport()
|
|||
int yoffs = 0;
|
||||
int wid, hei, actualWid, actualHei;
|
||||
|
||||
int winw = 640;
|
||||
int winh = 480;
|
||||
float ratio = (float)winw / (float)winh / fourThree;
|
||||
|
||||
vp.MinZ = (xfregs.rawViewport[5] - xfregs.rawViewport[2])/16777215.0f;
|
||||
vp.MaxZ = xfregs.rawViewport[5]/16777215.0f;
|
||||
|
||||
|
|
|
@ -85,8 +85,9 @@ void VertexShaderCache::SetShader(u32 components)
|
|||
return;
|
||||
}
|
||||
|
||||
bool HLSL = false;
|
||||
const char *code = GenerateVertexShader(components, false);
|
||||
LPDIRECT3DVERTEXSHADER9 shader = CompileCgShader(code);
|
||||
LPDIRECT3DVERTEXSHADER9 shader = HLSL ? D3D::CompileVertexShader(code, strlen(code), false) : CompileCgShader(code);
|
||||
if (shader)
|
||||
{
|
||||
// Make an entry in the table
|
||||
|
@ -121,33 +122,9 @@ LPDIRECT3DVERTEXSHADER9 VertexShaderCache::CompileCgShader(const char *pstrprogr
|
|||
}
|
||||
const char *pcompiledprog = cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
|
||||
|
||||
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.
|
||||
LPDIRECT3DVERTEXSHADER9 vertex_shader = D3D::CompileVertexShader(pcompiledprog, (int)strlen(pcompiledprog), true);
|
||||
cgDestroyProgram(tempprog);
|
||||
tempprog = NULL;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue