Load the compiler module for D3D11.

TRAC #22191
Signed-off-by: Shannon Woods
Signed-off-by: Daniel Koch
Author: Nicolas Capens

git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1528 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/renderer/Renderer11.cpp b/src/libGLESv2/renderer/Renderer11.cpp
index a62f734..cbcf57a 100644
--- a/src/libGLESv2/renderer/Renderer11.cpp
+++ b/src/libGLESv2/renderer/Renderer11.cpp
@@ -37,6 +37,7 @@
 {
     mD3d11Module = NULL;
     mDxgiModule = NULL;
+    mD3dCompilerModule = NULL;
 
     mDeviceLost = false;
 
@@ -85,6 +86,12 @@
         FreeLibrary(mDxgiModule);
         mDxgiModule = NULL;
     }
+
+    if (mD3dCompilerModule)
+    {
+        FreeLibrary(mD3dCompilerModule);
+        mD3dCompilerModule = NULL;
+    }
 }
 
 Renderer11 *Renderer11::makeRenderer11(Renderer *renderer)
@@ -171,6 +178,31 @@
         return EGL_NOT_INITIALIZED;
     }
 
+#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<pD3DCompile>(GetProcAddress(mD3dCompilerModule, "D3DCompile"));
+    ASSERT(mD3DCompileFunc);
+
     initializeDevice();
 
     return EGL_SUCCESS;