Commit 637ca47c by apatrick@chromium.org

Retry D3DCompile with different compile settings if it fails.

Now also tries with D3DCOMPILE_AVOID_FLOW_CONTROL, and D3DCOMPILE_PREFER_FLOW_CONTROL. Review URL: https://codereview.appspot.com/6593069 git-svn-id: https://angleproject.googlecode.com/svn/trunk@1289 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 2b5af7b9
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 1288 #define BUILD_REVISION 1289
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -1044,7 +1044,7 @@ ID3D10Blob *ProgramBinary::compileToBinary(InfoLog &infoLog, const char *hlsl, c ...@@ -1044,7 +1044,7 @@ ID3D10Blob *ProgramBinary::compileToBinary(InfoLog &infoLog, const char *hlsl, c
return NULL; return NULL;
} }
DWORD result; DWORD result = NOERROR;
UINT flags = 0; UINT flags = 0;
std::string sourceText; std::string sourceText;
if (perfActive()) if (perfActive())
...@@ -1066,43 +1066,74 @@ ID3D10Blob *ProgramBinary::compileToBinary(InfoLog &infoLog, const char *hlsl, c ...@@ -1066,43 +1066,74 @@ ID3D10Blob *ProgramBinary::compileToBinary(InfoLog &infoLog, const char *hlsl, c
sourceText = hlsl; sourceText = hlsl;
} }
ID3D10Blob *binary = NULL; // Sometimes D3DCompile will fail with the default compilation flags for complicated shaders when it would otherwise pass with alternative options.
ID3D10Blob *errorMessage = NULL; // Try the default flags first and if compilation fails, try some alternatives.
result = D3DCompile(hlsl, strlen(hlsl), g_fakepath, NULL, NULL, "main", profile, flags, 0, &binary, &errorMessage); const static UINT extraFlags[] =
if (errorMessage)
{ {
const char *message = (const char*)errorMessage->GetBufferPointer(); 0,
D3DCOMPILE_AVOID_FLOW_CONTROL,
infoLog.appendSanitized(message); D3DCOMPILE_PREFER_FLOW_CONTROL
TRACE("\n%s", hlsl); };
TRACE("\n%s", message);
errorMessage->Release(); const static char * const extraFlagNames[] =
errorMessage = NULL; {
} "default",
"avoid flow control",
"prefer flow control"
};
if (FAILED(result)) for (int i = 0; i < sizeof(extraFlags) / sizeof(UINT); ++i)
{ {
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) ID3D10Blob *errorMessage = NULL;
ID3D10Blob *binary = NULL;
result = D3DCompile(hlsl, strlen(hlsl), g_fakepath, NULL, NULL, "main", profile, flags | extraFlags[i], 0, &binary, &errorMessage);
if (errorMessage)
{ {
error(GL_OUT_OF_MEMORY); const char *message = (const char*)errorMessage->GetBufferPointer();
infoLog.appendSanitized(message);
TRACE("\n%s", hlsl);
TRACE("\n%s", message);
errorMessage->Release();
errorMessage = NULL;
} }
return NULL; if (SUCCEEDED(result))
} {
D3DConstantTable *table = new D3DConstantTable(binary->GetBufferPointer(), binary->GetBufferSize());
if (table->error())
{
delete table;
binary->Release();
return NULL;
}
*constantTable = table;
D3DConstantTable *table = new D3DConstantTable(binary->GetBufferPointer(), binary->GetBufferSize()); return binary;
if (table->error()) }
{ else
delete table; {
binary->Release(); if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
return NULL; {
return error(GL_OUT_OF_MEMORY, (ID3D10Blob*) NULL);
}
infoLog.append("Warning: D3D shader compilation failed with ");
infoLog.append(extraFlagNames[i]);
infoLog.append(" flags.");
if (i + 1 < sizeof(extraFlagNames) / sizeof(char*))
{
infoLog.append(" Retrying with ");
infoLog.append(extraFlagNames[i + 1]);
infoLog.append(".\n");
}
}
} }
*constantTable = table; return NULL;
return binary;
} }
// Packs varyings into generic varying registers, using the algorithm from [OpenGL ES Shading Language 1.00 rev. 17] appendix A section 7 page 111 // Packs varyings into generic varying registers, using the algorithm from [OpenGL ES Shading Language 1.00 rev. 17] appendix A section 7 page 111
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment