From cf569e2c5857c773a180c3c7bb53bfe1da5450c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BF=8A=E5=98=89?= Date: Tue, 27 Apr 2021 06:09:36 +0000 Subject: [PATCH] Remove reduntant dependencies in UWP compilation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove d3d12.li, dxgi.lib and d3d11.lib dependencies when targeting UWP. Add dxgi.lib only for DXGIGetDebugInterface1 in debug build when targeting UWP. Use DXGIGetDebugInterface1 only in debug build when targeting UWP. Bug: dawn:766 Change-Id: I5fa53dbb257acf604836f861f75a122a7d417e7c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/49040 Reviewed-by: Austin Eng Commit-Queue: 陈俊嘉 --- src/dawn_native/BUILD.gn | 34 ++++++++++++--------- src/dawn_native/d3d12/BackendD3D12.cpp | 3 +- src/dawn_native/d3d12/PlatformFunctions.cpp | 7 +++++ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/dawn_native/BUILD.gn b/src/dawn_native/BUILD.gn index 515ca9d3e3..711fa8c80a 100644 --- a/src/dawn_native/BUILD.gn +++ b/src/dawn_native/BUILD.gn @@ -309,24 +309,28 @@ source_set("dawn_native_sources") { ] } - if (is_win) { + # Only win32 app needs to link with user32.lib + # In UWP, all availiable APIs are defined in WindowsApp.lib + if (is_win && !dawn_is_winuwp) { libs += [ "user32.lib" ] - if (dawn_is_winuwp) { - # UWP has a limited DLL search space. - # So we have to link with stub libs provided by Windows SDK - # to load DLLs correctly. - libs += [ - "dxgi.lib", - "d3d12.lib", - "d3d11.lib", - - # TODO(dawn:766): - # Somehow use dxcompiler.lib makes CoreApp unable to activate - # WinPIX should be added as third party tools and linked statically - ] - } } + if (dawn_is_winuwp && is_debug) { + # DXGIGetDebugInterface1 is defined in dxgi.lib + # But this API is tagged as a development-only capability + # which implies that linking to this function will cause + # the application to fail Windows store certification + # So we only link to it in debug build when compiling for UWP. + # In win32 we load dxgi.dll using LoadLibrary + # so no need for static linking. + libs += [ "dxgi.lib" ] + } + + # TODO(dawn:766): + # Should link dxcompiler.lib and WinPixEventRuntime_UAP.lib in UWP + # Somehow use dxcompiler.lib makes CoreApp unable to activate + # WinPIX should be added as third party tools and linked statically + if (dawn_enable_d3d12) { libs += [ "dxguid.lib" ] sources += [ diff --git a/src/dawn_native/d3d12/BackendD3D12.cpp b/src/dawn_native/d3d12/BackendD3D12.cpp index df61c2af73..3e5c15b5b8 100644 --- a/src/dawn_native/d3d12/BackendD3D12.cpp +++ b/src/dawn_native/d3d12/BackendD3D12.cpp @@ -50,7 +50,8 @@ namespace dawn_native { namespace d3d12 { if (beginCaptureOnStartup) { ComPtr graphicsAnalysis; - if (SUCCEEDED(functions->dxgiGetDebugInterface1( + if (functions->dxgiGetDebugInterface1 != nullptr && + SUCCEEDED(functions->dxgiGetDebugInterface1( 0, IID_PPV_ARGS(&graphicsAnalysis)))) { graphicsAnalysis->BeginCapture(); } diff --git a/src/dawn_native/d3d12/PlatformFunctions.cpp b/src/dawn_native/d3d12/PlatformFunctions.cpp index ba1868e22e..8e0654ea35 100644 --- a/src/dawn_native/d3d12/PlatformFunctions.cpp +++ b/src/dawn_native/d3d12/PlatformFunctions.cpp @@ -158,7 +158,14 @@ namespace dawn_native { namespace d3d12 { MaybeError PlatformFunctions::LoadDXGI() { #if DAWN_PLATFORM_WINUWP +# if defined(_DEBUG) + // DXGIGetDebugInterface1 is tagged as a development-only capability + // which implies that linking to this function will cause + // the application to fail Windows store certification + // But we need it when debuging using VS Graphics Diagnostics or PIX + // So we only link to it in debug build dxgiGetDebugInterface1 = &DXGIGetDebugInterface1; +# endif createDxgiFactory2 = &CreateDXGIFactory2; #else std::string error;