D3D: Fall back to old compiler DLL.

This is a workaround for Windows 7 users sometimes not having the UCRT
required for the new versions of the MS HLSL compiler. It requires a
specific version of the Windows SDK with the old compiler DLL.

Bug: chromium:920704
Change-Id: Id9adb3b9d569272cbd69a8b4fc99dc160d837dbc
Reviewed-on: https://chromium-review.googlesource.com/c/1403254
Reviewed-by: Jamie Madill <jmadill@google.com>
Reviewed-by: Bruce Dawson <brucedawson@chromium.org>
Commit-Queue: Jamie Madill <jmadill@google.com>
This commit is contained in:
Jamie Madill
2019-02-22 10:24:44 -05:00
committed by Commit Bot
parent cf9b2853a7
commit d09546e1ec
3 changed files with 67 additions and 8 deletions

View File

@@ -153,12 +153,23 @@ config("build_id_config") {
# Windows ARM64 is available since 10.0.16299 so no need to copy
# d3dcompiler_47.dll because this file is available as inbox.
if (is_win && target_cpu != "arm64") {
# We also ship an older DLL for compatiblity with Windows 7 machines without
# the UCRT. This DLL isn't available in the standard SDK distribution.
_old_compiler = "$windows_sdk_path/Redist/D3D/$target_cpu/d3dcompiler_old.dll"
_has_old_compiler =
exec_script("scripts/file_exists.py", [ _old_compiler ], "value")
copy("copy_compiler_dll") {
sources = [
"$windows_sdk_path/Redist/D3D/$target_cpu/d3dcompiler_47.dll",
]
if (_has_old_compiler) {
sources += [ _old_compiler ]
}
outputs = [
"$root_out_dir/d3dcompiler_47.dll",
"$root_out_dir/{{source_file_part}}",
]
}
}

22
scripts/file_exists.py Normal file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/python2
# Copyright 2019 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Simple helper for use in 'gn' files to check if a file exists.
import os, shutil, sys
def main():
if len(sys.argv) != 2:
print "Usage: %s <path>" % sys.argv[0]
sys.exit(1)
if os.path.exists(sys.argv[1]):
print "true"
else:
print "false"
sys.exit(0)
if __name__ == '__main__':
main()

View File

@@ -16,9 +16,9 @@
#include "libANGLE/renderer/d3d/ContextD3D.h"
#include "third_party/trace_event/trace_event.h"
#if ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO == ANGLE_ENABLED
namespace
{
#if ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO == ANGLE_ENABLED
# ifdef CREATE_COMPILER_FLAG_INFO
# undef CREATE_COMPILER_FLAG_INFO
# endif
@@ -81,9 +81,19 @@ bool IsCompilerFlagSet(UINT mask, UINT flag)
return isFlagSet;
}
}
} // anonymous namespace
#endif // ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO == ANGLE_ENABLED
constexpr char kOldCompilerLibrary[] = "d3dcompiler_old.dll";
enum D3DCompilerLoadLibraryResult
{
D3DCompilerDefaultLibrarySuccess,
D3DCompilerOldLibrarySuccess,
D3DCompilerFailure,
D3DCompilerEnumBoundary,
};
} // anonymous namespace
namespace rx
{
@@ -132,15 +142,31 @@ angle::Result HLSLCompiler::ensureInitialized(d3d::Context *context)
// built with.
mD3DCompilerModule = LoadLibraryA(D3DCOMPILER_DLL_A);
if (!mD3DCompilerModule)
if (mD3DCompilerModule)
{
DWORD lastError = GetLastError();
ERR() << "LoadLibrary(" << D3DCOMPILER_DLL_A << ") failed. GetLastError=" << lastError;
ANGLE_TRY_HR(context, E_OUTOFMEMORY, "LoadLibrary failed to load D3D Compiler DLL.");
ANGLE_HISTOGRAM_ENUMERATION("GPU.ANGLE.D3DCompilerLoadLibraryResult",
D3DCompilerDefaultLibrarySuccess, D3DCompilerEnumBoundary);
}
else
{
WARN() << "Failed to load HLSL compiler library. Trying old DLL.";
mD3DCompilerModule = LoadLibraryA(kOldCompilerLibrary);
if (mD3DCompilerModule)
{
ANGLE_HISTOGRAM_ENUMERATION("GPU.ANGLE.D3DCompilerLoadLibraryResult",
D3DCompilerOldLibrarySuccess, D3DCompilerEnumBoundary);
}
}
}
ASSERT(mD3DCompilerModule);
if (!mD3DCompilerModule)
{
DWORD lastError = GetLastError();
ERR() << "LoadLibrary(" << D3DCOMPILER_DLL_A << ") failed. GetLastError=" << lastError;
ANGLE_HISTOGRAM_ENUMERATION("GPU.ANGLE.D3DCompilerLoadLibraryResult", D3DCompilerFailure,
D3DCompilerEnumBoundary);
ANGLE_TRY_HR(context, E_OUTOFMEMORY, "LoadLibrary failed to load D3D Compiler DLL.");
}
mD3DCompileFunc =
reinterpret_cast<pD3DCompile>(GetProcAddress(mD3DCompilerModule, "D3DCompile"));