Commit 8ea5afef by apatrick@chromium.org

Switched to D3D10 shader compiler.

I figured out how to call in to D3DCompiler_xx.dll and still get the ID3DXConstantTable metadata used by ANGLE. There are more optimization levels available with this compiler and the lowest level (0) allows MetaTunnel and MandelBox to compile their shaders quickly. MetaTunnel still does not render correctly unfortunately. I benchmarked eight of the ShaderToy demos and did not notice any performance regression on an nVidia Quadro FX 380. Intel might be adversely affected. I built ANGLE against D3DCompiler_43.dll, while Chrome still ships with 42. I'm not sure if that will make a difference but I'll rev Chrome soon. I also checked WebGL Aquarium and ran the WebGL conformance tests. This will also let me roll r590 into Chromium. It turns out the ForceSymbolReferences setting I added to the libGLESv2 target caused the linker to sometimes crash when making changes and the changes between r577 and r590 consistently lead to a crash. libGLESv2 now has a hard dependency on D3DCompiler_xx.dll via the call in Program.cpp and this seems to not make the linker crash. Review URL: http://codereview.appspot.com/4275063 git-svn-id: https://angleproject.googlecode.com/svn/trunk@591 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent a06aa870
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
'target_defaults': { 'target_defaults': {
'defines': [ 'defines': [
'ANGLE_DISABLE_TRACE', 'ANGLE_DISABLE_TRACE',
'ANGLE_COMPILE_OPTIMIZATION_LEVEL=D3DCOMPILE_OPTIMIZATION_LEVEL0',
], ],
}, },
'targets': [ 'targets': [
...@@ -188,9 +189,6 @@ ...@@ -188,9 +189,6 @@
'd3dx9.lib', 'd3dx9.lib',
'd3dcompiler.lib', 'd3dcompiler.lib',
], ],
# Import at least one symbol from D3DCompiler_x.dll to force a
# static dependency.
'ForceSymbolReferences': ['_D3DCompile@44'],
} }
}, },
}, },
......
#define MAJOR_VERSION 0 #define MAJOR_VERSION 0
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 590 #define BUILD_REVISION 591
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#include "libGLESv2/Shader.h" #include "libGLESv2/Shader.h"
#include "libGLESv2/utilities.h" #include "libGLESv2/utilities.h"
#if !defined(ANGLE_COMPILE_OPTIMIZATION_LEVEL)
#define ANGLE_COMPILE_OPTIMIZATION_LEVEL D3DCOMPILE_OPTIMIZATION_LEVEL3
#endif
namespace gl namespace gl
{ {
unsigned int Program::mCurrentSerial = 1; unsigned int Program::mCurrentSerial = 1;
...@@ -933,44 +937,38 @@ void Program::applyUniforms() ...@@ -933,44 +937,38 @@ void Program::applyUniforms()
} }
// Compiles the HLSL code of the attached shaders into executable binaries // Compiles the HLSL code of the attached shaders into executable binaries
ID3DXBuffer *Program::compileToBinary(const char *hlsl, const char *profile, ID3DXConstantTable **constantTable) ID3D10Blob *Program::compileToBinary(const char *hlsl, const char *profile, ID3DXConstantTable **constantTable)
{ {
if (!hlsl) if (!hlsl)
{ {
return NULL; return NULL;
} }
ID3DXBuffer *binary = NULL;
ID3DXBuffer *errorMessage = NULL;
DWORD result; DWORD result;
UINT flags = 0;
std::string sourceText;
if (perfActive()) if (perfActive())
{ {
DWORD flags = D3DXSHADER_DEBUG; flags |= D3DCOMPILE_DEBUG;
#ifndef NDEBUG #ifdef NDEBUG
flags |= D3DXSHADER_SKIPOPTIMIZATION; flags |= ANGLE_COMPILE_OPTIMIZATION_LEVEL;
#else
flags |= D3DCOMPILE_SKIP_OPTIMIZATION;
#endif #endif
std::string sourcePath = getTempPath(); std::string sourcePath = getTempPath();
std::string sourceText = std::string("#line 2 \"") + sourcePath + std::string("\"\n\n") + std::string(hlsl); sourceText = std::string("#line 2 \"") + sourcePath + std::string("\"\n\n") + std::string(hlsl);
writeFile(sourcePath.c_str(), sourceText.c_str(), sourceText.size()); writeFile(sourcePath.c_str(), sourceText.c_str(), sourceText.size());
result = D3DXCompileShader(sourceText.c_str(), sourceText.size(), NULL, NULL, "main", profile, flags, &binary, &errorMessage, constantTable);
} }
else else
{ {
result = D3DXCompileShader(hlsl, (UINT)strlen(hlsl), NULL, NULL, "main", profile, 0, &binary, &errorMessage, constantTable); flags |= ANGLE_COMPILE_OPTIMIZATION_LEVEL;
sourceText = hlsl;
} }
if (SUCCEEDED(result)) ID3D10Blob *binary = NULL;
{ ID3D10Blob *errorMessage = NULL;
return binary; result = D3DCompile(hlsl, strlen(hlsl), NULL, NULL, NULL, "main", profile, flags, 0, &binary, &errorMessage);
}
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{
return error(GL_OUT_OF_MEMORY, (ID3DXBuffer*)NULL);
}
if (errorMessage) if (errorMessage)
{ {
...@@ -979,9 +977,37 @@ ID3DXBuffer *Program::compileToBinary(const char *hlsl, const char *profile, ID3 ...@@ -979,9 +977,37 @@ ID3DXBuffer *Program::compileToBinary(const char *hlsl, const char *profile, ID3
appendToInfoLog("%s\n", message); appendToInfoLog("%s\n", message);
TRACE("\n%s", hlsl); TRACE("\n%s", hlsl);
TRACE("\n%s", message); TRACE("\n%s", message);
errorMessage->Release();
errorMessage = NULL;
} }
if (FAILED(result))
{
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{
error(GL_OUT_OF_MEMORY);
}
return NULL;
}
result = D3DXGetShaderConstantTable(static_cast<const DWORD*>(binary->GetBufferPointer()), constantTable);
if (FAILED(result))
{
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
{
error(GL_OUT_OF_MEMORY);
}
binary->Release();
return NULL; 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
...@@ -1497,8 +1523,8 @@ void Program::link() ...@@ -1497,8 +1523,8 @@ void Program::link()
const char *vertexProfile = context->supportsShaderModel3() ? "vs_3_0" : "vs_2_0"; const char *vertexProfile = context->supportsShaderModel3() ? "vs_3_0" : "vs_2_0";
const char *pixelProfile = context->supportsShaderModel3() ? "ps_3_0" : "ps_2_0"; const char *pixelProfile = context->supportsShaderModel3() ? "ps_3_0" : "ps_2_0";
ID3DXBuffer *vertexBinary = compileToBinary(mVertexHLSL.c_str(), vertexProfile, &mConstantTableVS); ID3D10Blob *vertexBinary = compileToBinary(mVertexHLSL.c_str(), vertexProfile, &mConstantTableVS);
ID3DXBuffer *pixelBinary = compileToBinary(mPixelHLSL.c_str(), pixelProfile, &mConstantTablePS); ID3D10Blob *pixelBinary = compileToBinary(mPixelHLSL.c_str(), pixelProfile, &mConstantTablePS);
if (vertexBinary && pixelBinary) if (vertexBinary && pixelBinary)
{ {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define LIBGLESV2_PROGRAM_H_ #define LIBGLESV2_PROGRAM_H_
#include <d3dx9.h> #include <d3dx9.h>
#include <d3dcompiler.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <set> #include <set>
...@@ -129,7 +130,7 @@ class Program ...@@ -129,7 +130,7 @@ class Program
private: private:
DISALLOW_COPY_AND_ASSIGN(Program); DISALLOW_COPY_AND_ASSIGN(Program);
ID3DXBuffer *compileToBinary(const char *hlsl, const char *profile, ID3DXConstantTable **constantTable); ID3D10Blob *compileToBinary(const char *hlsl, const char *profile, ID3DXConstantTable **constantTable);
void unlink(bool destroy = false); void unlink(bool destroy = false);
int packVaryings(const Varying *packing[][4]); int packVaryings(const Varying *packing[][4]);
......
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