Commit 4f66eeac by apatrick@chromium.org

Remove dependency on d3dcompiler import library.

It is now loaded with LoadLibrary. Added compile time option of having ANGLE enumerate various versions of d3dcompiler_nn.dll that the application can preload before eglInitialize(). Review URL: https://codereview.appspot.com/6816074 git-svn-id: https://angleproject.googlecode.com/svn/trunk@1385 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent b417815b
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
'target_defaults': { 'target_defaults': {
'defines': [ 'defines': [
'ANGLE_DISABLE_TRACE', 'ANGLE_DISABLE_TRACE',
'ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES={ L"d3dcompiler_46.dll", L"d3dcompiler_43.dll" }',
], ],
}, },
'targets': [ 'targets': [
...@@ -266,8 +267,6 @@ ...@@ -266,8 +267,6 @@
'AdditionalLibraryDirectories': ['$(DXSDK_DIR)/lib/x86'], 'AdditionalLibraryDirectories': ['$(DXSDK_DIR)/lib/x86'],
'AdditionalDependencies': [ 'AdditionalDependencies': [
'd3d9.lib', 'd3d9.lib',
'd3dx9.lib',
'd3dcompiler.lib',
], ],
} }
}, },
...@@ -279,6 +278,7 @@ ...@@ -279,6 +278,7 @@
'include_dirs': [ 'include_dirs': [
'.', '.',
'../include', '../include',
'$(DXSDK_DIR)/include',
], ],
'sources': [ 'sources': [
'common/angleutils.h', 'common/angleutils.h',
......
...@@ -70,7 +70,8 @@ egl::Display *Display::getDisplay(EGLNativeDisplayType displayId) ...@@ -70,7 +70,8 @@ egl::Display *Display::getDisplay(EGLNativeDisplayType displayId)
Display::Display(EGLNativeDisplayType displayId, HDC deviceContext, bool software) : mDc(deviceContext) Display::Display(EGLNativeDisplayType displayId, HDC deviceContext, bool software) : mDc(deviceContext)
{ {
mD3d9Module = NULL; mD3d9Module = NULL;
mD3dCompilerModule = NULL;
mD3d9 = NULL; mD3d9 = NULL;
mD3d9Ex = NULL; mD3d9Ex = NULL;
mDevice = NULL; mDevice = NULL;
...@@ -128,6 +129,31 @@ bool Display::initialize() ...@@ -128,6 +129,31 @@ bool Display::initialize()
typedef HRESULT (WINAPI *Direct3DCreate9ExFunc)(UINT, IDirect3D9Ex**); typedef HRESULT (WINAPI *Direct3DCreate9ExFunc)(UINT, IDirect3D9Ex**);
Direct3DCreate9ExFunc Direct3DCreate9ExPtr = reinterpret_cast<Direct3DCreate9ExFunc>(GetProcAddress(mD3d9Module, "Direct3DCreate9Ex")); Direct3DCreate9ExFunc Direct3DCreate9ExPtr = reinterpret_cast<Direct3DCreate9ExFunc>(GetProcAddress(mD3d9Module, "Direct3DCreate9Ex"));
#if defined(ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES)
// Find a D3DCompiler module that had already been loaded based on a predefined list of versions.
static TCHAR* d3dCompilerNames[] = ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES;
for (int i = 0; i < sizeof(d3dCompilerNames) / sizeof(*d3dCompilerNames); ++i)
{
if (GetModuleHandleEx(0, d3dCompilerNames[i], &mD3dCompilerModule))
{
break;
}
}
#else
// Load the version of the D3DCompiler DLL associated with the Direct3D version ANGLE was built with.
mD3dCompilerModule = LoadLibrary(D3DCOMPILER_DLL);
#endif // ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES
if (!mD3dCompilerModule)
{
terminate();
return false;
}
mD3DCompileFunc = reinterpret_cast<D3DCompileFunc>(GetProcAddress(mD3dCompilerModule, "D3DCompile"));
ASSERT(mD3DCompileFunc);
// Use Direct3D9Ex if available. Among other things, this version is less // Use Direct3D9Ex if available. Among other things, this version is less
// inclined to report a lost context, for example when the user switches // inclined to report a lost context, for example when the user switches
// desktop. Direct3D9Ex is available in Windows Vista and later if suitable drivers are available. // desktop. Direct3D9Ex is available in Windows Vista and later if suitable drivers are available.
...@@ -367,6 +393,12 @@ void Display::terminate() ...@@ -367,6 +393,12 @@ void Display::terminate()
{ {
mD3d9Module = NULL; mD3d9Module = NULL;
} }
if (mD3dCompilerModule)
{
FreeLibrary(mD3dCompilerModule);
mD3dCompilerModule = NULL;
}
} }
void Display::startScene() void Display::startScene()
...@@ -1236,6 +1268,11 @@ IDirect3DVertexShader9 *Display::createVertexShader(const DWORD *function, size_ ...@@ -1236,6 +1268,11 @@ IDirect3DVertexShader9 *Display::createVertexShader(const DWORD *function, size_
return mVertexShaderCache.create(function, length); return mVertexShaderCache.create(function, length);
} }
HRESULT Display::compileShaderSource(const char* hlsl, const char* sourceName, const char* profile, DWORD flags, ID3DBlob** binary, ID3DBlob** errorMessage)
{
return mD3DCompileFunc(hlsl, strlen(hlsl), sourceName, NULL, NULL, "main", profile, flags, 0, binary, errorMessage);
}
IDirect3DPixelShader9 *Display::createPixelShader(const DWORD *function, size_t length) IDirect3DPixelShader9 *Display::createPixelShader(const DWORD *function, size_t length)
{ {
return mPixelShaderCache.create(function, length); return mPixelShaderCache.create(function, length);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#endif #endif
#include <windows.h> #include <windows.h>
#include <d3d9.h> #include <d3d9.h>
#include <D3Dcompiler.h>
#include <set> #include <set>
#include <vector> #include <vector>
...@@ -109,6 +110,8 @@ class Display ...@@ -109,6 +110,8 @@ class Display
virtual IDirect3DVertexShader9 *createVertexShader(const DWORD *function, size_t length); virtual IDirect3DVertexShader9 *createVertexShader(const DWORD *function, size_t length);
virtual IDirect3DPixelShader9 *createPixelShader(const DWORD *function, size_t length); virtual IDirect3DPixelShader9 *createPixelShader(const DWORD *function, size_t length);
virtual HRESULT compileShaderSource(const char* hlsl, const char* sourceName, const char* profile, DWORD flags, ID3DBlob** binary, ID3DBlob** errorMessage);
private: private:
DISALLOW_COPY_AND_ASSIGN(Display); DISALLOW_COPY_AND_ASSIGN(Display);
...@@ -161,6 +164,21 @@ class Display ...@@ -161,6 +164,21 @@ class Display
void initExtensionString(); void initExtensionString();
std::string mExtensionString; std::string mExtensionString;
typedef HRESULT (WINAPI *D3DCompileFunc)(LPCVOID pSrcData,
SIZE_T SrcDataSize,
LPCSTR pSourceName,
CONST D3D_SHADER_MACRO* pDefines,
ID3DInclude* pInclude,
LPCSTR pEntrypoint,
LPCSTR pTarget,
UINT Flags1,
UINT Flags2,
ID3DBlob** ppCode,
ID3DBlob** ppErrorMsgs);
HMODULE mD3dCompilerModule;
D3DCompileFunc mD3DCompileFunc;
}; };
} }
......
...@@ -1086,8 +1086,7 @@ ID3D10Blob *ProgramBinary::compileToBinary(InfoLog &infoLog, const char *hlsl, c ...@@ -1086,8 +1086,7 @@ ID3D10Blob *ProgramBinary::compileToBinary(InfoLog &infoLog, const char *hlsl, c
{ {
ID3D10Blob *errorMessage = NULL; ID3D10Blob *errorMessage = NULL;
ID3D10Blob *binary = NULL; ID3D10Blob *binary = NULL;
result = D3DCompile(hlsl, strlen(hlsl), g_fakepath, NULL, NULL, "main", profile, flags | extraFlags[i], 0, &binary, &errorMessage); result = getDisplay()->compileShaderSource(hlsl, profile, g_fakepath, flags | extraFlags[i], &binary, &errorMessage);
if (errorMessage) if (errorMessage)
{ {
const char *message = (const char*)errorMessage->GetBufferPointer(); const char *message = (const char*)errorMessage->GetBufferPointer();
......
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
<DisableSpecificWarnings>4100;4127;4189;4239;4244;4245;4512;4702;%(DisableSpecificWarnings)</DisableSpecificWarnings> <DisableSpecificWarnings>4100;4127;4189;4239;4244;4245;4512;4702;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>d3d9.lib;d3dcompiler.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>libGLESv2.def</ModuleDefinitionFile> <ModuleDefinitionFile>libGLESv2.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
...@@ -130,7 +130,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -130,7 +130,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<DisableSpecificWarnings>4100;4127;4189;4239;4244;4245;4512;4702;4718;%(DisableSpecificWarnings)</DisableSpecificWarnings> <DisableSpecificWarnings>4100;4127;4189;4239;4244;4245;4512;4702;4718;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>d3d9.lib;d3dcompiler.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries> <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<ModuleDefinitionFile>libGLESv2.def</ModuleDefinitionFile> <ModuleDefinitionFile>libGLESv2.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
...@@ -170,7 +170,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -170,7 +170,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<TreatWarningAsError>true</TreatWarningAsError> <TreatWarningAsError>true</TreatWarningAsError>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>d3d9.lib;d3dcompiler.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>libGLESv2.def</ModuleDefinitionFile> <ModuleDefinitionFile>libGLESv2.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
...@@ -206,7 +206,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -206,7 +206,7 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<TreatWarningAsError>true</TreatWarningAsError> <TreatWarningAsError>true</TreatWarningAsError>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>d3d9.lib;d3dcompiler.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries> <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<ModuleDefinitionFile>libGLESv2.def</ModuleDefinitionFile> <ModuleDefinitionFile>libGLESv2.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
......
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