mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-13 15:41:18 +00:00
Fix a vertex shader generation bug that crashed Super Monkey Ball. Better shader error handling. Random warning fixes.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4170 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
50593397f3
commit
1e016dd522
@ -110,19 +110,19 @@ void ConsoleListener::BufferWidthHeight(int BufferWidth, int BufferHeight, int S
|
||||
{
|
||||
// Change screen buffer size
|
||||
COORD Co = {BufferWidth, BufferHeight};
|
||||
SB = SetConsoleScreenBufferSize(hConsole, Co);
|
||||
SB = (bool)SetConsoleScreenBufferSize(hConsole, Co);
|
||||
// Change the screen buffer window size
|
||||
SMALL_RECT coo = {0,0,ScreenWidth, ScreenHeight}; // top, left, right, bottom
|
||||
SW = SetConsoleWindowInfo(hConsole, TRUE, &coo);
|
||||
SW = (bool)SetConsoleWindowInfo(hConsole, TRUE, &coo);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Change the screen buffer window size
|
||||
SMALL_RECT coo = {0,0, ScreenWidth, ScreenHeight}; // top, left, right, bottom
|
||||
SW = SetConsoleWindowInfo(hConsole, TRUE, &coo);
|
||||
SW = (bool)SetConsoleWindowInfo(hConsole, TRUE, &coo);
|
||||
// Change screen buffer size
|
||||
COORD Co = {BufferWidth, BufferHeight};
|
||||
SB = SetConsoleScreenBufferSize(hConsole, Co);
|
||||
SB = (bool)SetConsoleScreenBufferSize(hConsole, Co);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -198,7 +198,7 @@ void ConsoleListener::PixelSpace(int Left, int Top, int Width, int Height, bool
|
||||
int BytesRead = 0;
|
||||
int i = 0;
|
||||
int LastAttrRead = 0;
|
||||
while(BytesRead < BufferSize)
|
||||
while (BytesRead < BufferSize)
|
||||
{
|
||||
Str.push_back(new char[MAX_BYTES]);
|
||||
if (!ReadConsoleOutputCharacter(hConsole, Str[i], ReadBufferSize, coordScreen, &cCharsRead))
|
||||
@ -215,8 +215,8 @@ void ConsoleListener::PixelSpace(int Left, int Top, int Width, int Height, bool
|
||||
LastAttrRead = cAttrRead;
|
||||
}
|
||||
// Letter space
|
||||
int LWidth = floor((float)Width / 8.0) - 1.0;
|
||||
int LHeight = floor((float)Height / 12.0) - 1.0;
|
||||
int LWidth = (int)floor((float)Width / 8.0) - 1.0;
|
||||
int LHeight = (int)floor((float)Height / 12.0) - 1.0;
|
||||
int LBufWidth = LWidth + 1;
|
||||
int LBufHeight = floor((float)BufferSize / (float)LBufWidth);
|
||||
// Change screen buffer size
|
||||
|
@ -660,13 +660,13 @@ void Callback_VideoCopiedToXFB(bool video_update)
|
||||
double wait_frametime = (1000.0 / VideoInterface::TargetRefreshRate);
|
||||
|
||||
if (Timer.GetTimeDifference() >= wait_frametime * frames)
|
||||
no_framelimit=Timer.GetTimeDifference();
|
||||
no_framelimit = (u32)Timer.GetTimeDifference();
|
||||
|
||||
while (Timer.GetTimeDifference() < wait_frametime * videoupd)
|
||||
{
|
||||
// TODO : This is wrong, the sleep shouldn't be there but rather in cputhread
|
||||
// as it's not based on the fps but on the refresh rate...
|
||||
if (no_framelimit==0)
|
||||
if (no_framelimit == 0)
|
||||
Common::SleepCurrentThread(1);
|
||||
}
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ const char *GenerateVertexShader(u32 components, bool D3D)
|
||||
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
|
||||
WRITE(p, "float4 coord = float4(rawnorm0.xyz, 1.0);\n");
|
||||
}
|
||||
else WRITE(p, "float4 coord = 0;\n");
|
||||
else WRITE(p, "float4 coord = float4(0.0f, 0.0f, 1.0f, 1.0f);\n"); // avoid errors
|
||||
break;
|
||||
case XF_SRCCOLORS_INROW:
|
||||
_assert_( texinfo.texgentype == XF_TEXGEN_COLOR_STRGBC0 || texinfo.texgentype == XF_TEXGEN_COLOR_STRGBC1 );
|
||||
@ -346,21 +346,21 @@ const char *GenerateVertexShader(u32 components, bool D3D)
|
||||
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
|
||||
WRITE(p, "float4 coord = float4(rawnorm1.xyz, 1.0);\n");
|
||||
}
|
||||
else WRITE(p, "float4 coord = 0;\n");
|
||||
else WRITE(p, "float4 coord = float4(0.0f, 0.0f, 1.0f, 1.0f);\n"); // avoid errors
|
||||
break;
|
||||
case XF_SRCBINORMAL_B_INROW:
|
||||
if (components & VB_HAS_NRM2) {
|
||||
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
|
||||
WRITE(p, "float4 coord = float4(rawnorm2.xyz, 1.0);\n");
|
||||
}
|
||||
else WRITE(p, "float4 coord = 0;\n");
|
||||
else WRITE(p, "float4 coord = float4(0.0f, 0.0f, 1.0f, 1.0f);\n"); // avoid errors
|
||||
break;
|
||||
default:
|
||||
_assert_(texinfo.sourcerow <= XF_SRCTEX7_INROW);
|
||||
if (components & (VB_HAS_UV0<<(texinfo.sourcerow - XF_SRCTEX0_INROW)) )
|
||||
WRITE(p, "float4 coord = float4(tex%d.x, tex%d.y, 1.0f, 1.0f);\n", texinfo.sourcerow - XF_SRCTEX0_INROW, texinfo.sourcerow - XF_SRCTEX0_INROW);
|
||||
else
|
||||
WRITE(p, "float4 coord = float4(0.0f, 0.0f, 1.0f, 1.0f);\n");
|
||||
WRITE(p, "float4 coord = float4(0.0f, 0.0f, 1.0f, 1.0f);\n"); // avoid errors
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -57,10 +57,8 @@ void PixelShaderCache::Shutdown()
|
||||
PixelShaders.clear();
|
||||
}
|
||||
|
||||
void PixelShaderCache::SetShader(bool dstAlpha)
|
||||
bool PixelShaderCache::SetShader(bool dstAlpha)
|
||||
{
|
||||
static LPDIRECT3DPIXELSHADER9 last_shader = NULL;
|
||||
|
||||
DVSTARTPROFILE();
|
||||
|
||||
PIXELSHADERUID uid;
|
||||
@ -68,19 +66,14 @@ void PixelShaderCache::SetShader(bool dstAlpha)
|
||||
|
||||
PSCache::iterator iter;
|
||||
iter = PixelShaders.find(uid);
|
||||
|
||||
if (iter != PixelShaders.end())
|
||||
{
|
||||
iter->second.frameCount = frameCount;
|
||||
const PSCacheEntry &entry = iter->second;
|
||||
D3D::dev->SetPixelShader(entry.shader);
|
||||
last_entry = &entry;
|
||||
if (!last_shader || entry.shader != last_shader)
|
||||
{
|
||||
D3D::dev->SetPixelShader(entry.shader);
|
||||
last_shader = entry.shader;
|
||||
DEBUGGER_PAUSE_COUNT_N(NEXT_PIXEL_SHADER_CHANGE);
|
||||
}
|
||||
return;
|
||||
DEBUGGER_PAUSE_COUNT_N(NEXT_PIXEL_SHADER_CHANGE);
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *code = GeneratePixelShader(PixelShaderManager::GetTextureMask(), dstAlpha, true);
|
||||
@ -88,26 +81,27 @@ void PixelShaderCache::SetShader(bool dstAlpha)
|
||||
|
||||
if (shader)
|
||||
{
|
||||
//Make an entry in the table
|
||||
// Make an entry in the table
|
||||
PSCacheEntry newentry;
|
||||
newentry.shader = shader;
|
||||
newentry.frameCount = frameCount;
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
newentry.code = code;
|
||||
#endif
|
||||
PixelShaders[uid] = newentry;
|
||||
last_entry = &PixelShaders[uid];
|
||||
|
||||
D3D::dev->SetPixelShader(shader);
|
||||
last_shader = shader;
|
||||
|
||||
INCSTAT(stats.numPixelShadersCreated);
|
||||
SETSTAT(stats.numPixelShadersAlive, (int)PixelShaders.size());
|
||||
return true;
|
||||
}
|
||||
else if (g_Config.bShowShaderErrors)
|
||||
{
|
||||
PanicAlert("Failed to compile Pixel Shader:\n\n%s", code);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -131,7 +125,7 @@ void PixelShaderCache::Cleanup()
|
||||
SETSTAT(stats.numPixelShadersAlive, (int)PixelShaders.size());
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
std::string PixelShaderCache::GetCurrentShaderCode()
|
||||
{
|
||||
if (last_entry)
|
||||
|
@ -36,7 +36,7 @@ private:
|
||||
{
|
||||
LPDIRECT3DPIXELSHADER9 shader;
|
||||
int frameCount;
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
std::string code;
|
||||
#endif
|
||||
PSCacheEntry() : shader(NULL), frameCount(0) {}
|
||||
@ -56,8 +56,8 @@ public:
|
||||
static void Init();
|
||||
static void Cleanup();
|
||||
static void Shutdown();
|
||||
static void SetShader(bool dstAlpha);
|
||||
#ifdef _DEBUG
|
||||
static bool SetShader(bool dstAlpha);
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
static std::string GetCurrentShaderCode();
|
||||
#endif
|
||||
static LPDIRECT3DPIXELSHADER9 CompileCgShader(const char *pstrprogram);
|
||||
|
@ -185,10 +185,6 @@ void Flush()
|
||||
DVSTARTPROFILE();
|
||||
if (collection != C_NOTHING)
|
||||
{
|
||||
// setup the pointers
|
||||
if (g_nativeVertexFmt)
|
||||
g_nativeVertexFmt->SetupVertexPointers();
|
||||
|
||||
u32 usedtextures = 0;
|
||||
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; ++i) {
|
||||
if (bpmem.tevorders[i/2].getEnable(i & 1))
|
||||
@ -230,8 +226,10 @@ void Flush()
|
||||
VertexShaderManager::SetConstants();
|
||||
PixelShaderManager::SetConstants();
|
||||
|
||||
PixelShaderCache::SetShader(false);
|
||||
VertexShaderCache::SetShader(g_nativeVertexFmt->m_components);
|
||||
if (!PixelShaderCache::SetShader(false))
|
||||
goto shader_fail;
|
||||
if (!VertexShaderCache::SetShader(g_nativeVertexFmt->m_components))
|
||||
goto shader_fail;
|
||||
|
||||
int stride = g_nativeVertexFmt->GetVertexStride();
|
||||
g_nativeVertexFmt->SetupVertexPointers();
|
||||
@ -245,12 +243,12 @@ void Flush()
|
||||
D3DFMT_INDEX16,
|
||||
fakeVBuffer,
|
||||
stride))) {
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
std::string error_shaders;
|
||||
error_shaders.append(VertexShaderCache::GetCurrentShaderCode());
|
||||
error_shaders.append(PixelShaderCache::GetCurrentShaderCode());
|
||||
File::WriteStringToFile(true, error_shaders, "bad_shader_combo.txt");
|
||||
PanicAlert("DrawIndexedPrimitiveUP failed. Shaders written to shaders.txt.");
|
||||
PanicAlert("DrawIndexedPrimitiveUP failed. Shaders written to bad_shader_combo.txt.");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -263,7 +261,8 @@ void Flush()
|
||||
if (bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate)
|
||||
{
|
||||
DWORD write = 0;
|
||||
PixelShaderCache::SetShader(true);
|
||||
if (!PixelShaderCache::SetShader(true))
|
||||
goto shader_fail;
|
||||
|
||||
// update alpha only
|
||||
Renderer::SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA);
|
||||
@ -280,12 +279,12 @@ void Flush()
|
||||
D3DFMT_INDEX16,
|
||||
fakeVBuffer,
|
||||
stride))) {
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
std::string error_shaders;
|
||||
error_shaders.append(VertexShaderCache::GetCurrentShaderCode());
|
||||
error_shaders.append(PixelShaderCache::GetCurrentShaderCode());
|
||||
File::WriteStringToFile(true, error_shaders, "bad_shader_combo.txt");
|
||||
PanicAlert("DrawIndexedPrimitiveUP failed. Shaders written to shaders.txt.");
|
||||
PanicAlert("DrawIndexedPrimitiveUP failed (dstalpha). Shaders written to bad_shader_combo.txt.");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -309,7 +308,7 @@ void Flush()
|
||||
|
||||
INCSTAT(stats.thisFrame.numDrawCalls);
|
||||
}
|
||||
|
||||
shader_fail:
|
||||
collection = C_NOTHING;
|
||||
VertexManager::s_pCurBufferPointer = fakeVBuffer;
|
||||
DEBUGGER_PAUSE_COUNT_N(NEXT_FLUSH);
|
||||
|
@ -57,11 +57,8 @@ void VertexShaderCache::Shutdown()
|
||||
vshaders.clear();
|
||||
}
|
||||
|
||||
|
||||
void VertexShaderCache::SetShader(u32 components)
|
||||
bool VertexShaderCache::SetShader(u32 components)
|
||||
{
|
||||
static LPDIRECT3DVERTEXSHADER9 last_shader = NULL;
|
||||
|
||||
DVSTARTPROFILE();
|
||||
|
||||
VERTEXSHADERUID uid;
|
||||
@ -73,15 +70,10 @@ void VertexShaderCache::SetShader(u32 components)
|
||||
{
|
||||
iter->second.frameCount = frameCount;
|
||||
const VSCacheEntry &entry = iter->second;
|
||||
D3D::dev->SetVertexShader(entry.shader);
|
||||
last_entry = &entry;
|
||||
if (!last_shader || entry.shader != last_shader)
|
||||
{
|
||||
D3D::dev->SetVertexShader(entry.shader);
|
||||
last_shader = entry.shader;
|
||||
|
||||
DEBUGGER_PAUSE_COUNT_N(NEXT_VERTEX_SHADER_CHANGE);
|
||||
}
|
||||
return;
|
||||
DEBUGGER_PAUSE_COUNT_N(NEXT_VERTEX_SHADER_CHANGE);
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *code = GenerateVertexShader(components, true);
|
||||
@ -93,22 +85,23 @@ void VertexShaderCache::SetShader(u32 components)
|
||||
VSCacheEntry entry;
|
||||
entry.shader = shader;
|
||||
entry.frameCount = frameCount;
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
entry.code = code;
|
||||
#endif
|
||||
vshaders[uid] = entry;
|
||||
last_entry = &vshaders[uid];
|
||||
last_shader = entry.shader;
|
||||
|
||||
D3D::dev->SetVertexShader(shader);
|
||||
|
||||
INCSTAT(stats.numVertexShadersCreated);
|
||||
SETSTAT(stats.numVertexShadersAlive, (int)vshaders.size());
|
||||
return true;
|
||||
}
|
||||
else if (g_Config.bShowShaderErrors)
|
||||
{
|
||||
PanicAlert("Failed to compile Vertex Shader:\n\n%s", code);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void VertexShaderCache::Cleanup()
|
||||
@ -129,7 +122,7 @@ void VertexShaderCache::Cleanup()
|
||||
SETSTAT(stats.numVertexShadersAlive, (int)vshaders.size());
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
std::string VertexShaderCache::GetCurrentShaderCode()
|
||||
{
|
||||
if (last_entry)
|
||||
|
@ -33,7 +33,7 @@ private:
|
||||
{
|
||||
LPDIRECT3DVERTEXSHADER9 shader;
|
||||
int frameCount;
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
std::string code;
|
||||
#endif
|
||||
VSCacheEntry() : shader(NULL), frameCount(0) {}
|
||||
@ -53,8 +53,8 @@ public:
|
||||
static void Init();
|
||||
static void Cleanup();
|
||||
static void Shutdown();
|
||||
static void SetShader(u32 components);
|
||||
#ifdef _DEBUG
|
||||
static bool SetShader(u32 components);
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
static std::string GetCurrentShaderCode();
|
||||
#endif
|
||||
static LPDIRECT3DVERTEXSHADER9 CompileCgShader(const char *pstrprogram);
|
||||
|
Loading…
x
Reference in New Issue
Block a user