diff --git a/src/dawn_native/Toggles.cpp b/src/dawn_native/Toggles.cpp index eb6ecd7bf7..b4ec0db0e3 100644 --- a/src/dawn_native/Toggles.cpp +++ b/src/dawn_native/Toggles.cpp @@ -128,6 +128,9 @@ namespace dawn_native { "Enable use of a small D3D12 shader visible heap, instead of using a large one by " "default. This setting is used to test bindgroup encoding.", "https://crbug.com/dawn/155"}}, + {Toggle::UseDXC, + {"use_dxc", "Use DXC instead of FXC for compiling HLSL", + "https://crbug.com/dawn/402"}}, }}; } // anonymous namespace diff --git a/src/dawn_native/Toggles.h b/src/dawn_native/Toggles.h index 93a31d2e9d..18a26a9a63 100644 --- a/src/dawn_native/Toggles.h +++ b/src/dawn_native/Toggles.h @@ -41,6 +41,7 @@ namespace dawn_native { DisableBaseVertex, DisableBaseInstance, UseD3D12SmallShaderVisibleHeapForTesting, + UseDXC, EnumCount, InvalidEnum = EnumCount, diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index ce935a9813..cfd109f691 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -432,6 +432,7 @@ namespace dawn_native { namespace d3d12 { SetToggle(Toggle::UseD3D12ResourceHeapTier2, useResourceHeapTier2); SetToggle(Toggle::UseD3D12RenderPass, GetDeviceInfo().supportsRenderPass); SetToggle(Toggle::UseD3D12ResidencyManagement, true); + SetToggle(Toggle::UseDXC, false); // By default use the maximum shader-visible heap size allowed. SetToggle(Toggle::UseD3D12SmallShaderVisibleHeapForTesting, false); diff --git a/src/dawn_native/d3d12/PlatformFunctions.cpp b/src/dawn_native/d3d12/PlatformFunctions.cpp index 1e79f88c93..467e8d79ef 100644 --- a/src/dawn_native/d3d12/PlatformFunctions.cpp +++ b/src/dawn_native/d3d12/PlatformFunctions.cpp @@ -26,7 +26,9 @@ namespace dawn_native { namespace d3d12 { MaybeError PlatformFunctions::LoadFunctions() { DAWN_TRY(LoadD3D12()); DAWN_TRY(LoadDXGI()); - DAWN_TRY(LoadD3DCompiler()); + LoadDXIL(); + LoadDXCompiler(); + DAWN_TRY(LoadFXCompiler()); DAWN_TRY(LoadD3D11()); LoadPIXRuntime(); return {}; @@ -72,10 +74,24 @@ namespace dawn_native { namespace d3d12 { return {}; } - MaybeError PlatformFunctions::LoadD3DCompiler() { + void PlatformFunctions::LoadDXIL() { + if (!mDXILLib.Open("dxil.dll", nullptr)) { + mDXILLib.Close(); + } + } + + void PlatformFunctions::LoadDXCompiler() { + // DXIL must be loaded before DXC, otherwise shader signing is unavailable + if (!mDXCompilerLib.Open("dxcompiler.dll", nullptr) || + !mDXCompilerLib.GetProc(&dxcCreateInstance, "DxcCreateInstance", nullptr)) { + mDXCompilerLib.Close(); + } + } + + MaybeError PlatformFunctions::LoadFXCompiler() { std::string error; - if (!mD3DCompilerLib.Open("d3dcompiler_47.dll", &error) || - !mD3DCompilerLib.GetProc(&d3dCompile, "D3DCompile", &error)) { + if (!mFXCompilerLib.Open("d3dcompiler_47.dll", &error) || + !mFXCompilerLib.GetProc(&d3dCompile, "D3DCompile", &error)) { return DAWN_INTERNAL_ERROR(error.c_str()); } @@ -86,6 +102,10 @@ namespace dawn_native { namespace d3d12 { return mPIXEventRuntimeLib.Valid(); } + bool PlatformFunctions::IsDXCAvailable() const { + return mDXILLib.Valid() && mDXCompilerLib.Valid(); + } + void PlatformFunctions::LoadPIXRuntime() { if (!mPIXEventRuntimeLib.Open("WinPixEventRuntime.dll") || !mPIXEventRuntimeLib.GetProc(&pixBeginEventOnCommandList, diff --git a/src/dawn_native/d3d12/PlatformFunctions.h b/src/dawn_native/d3d12/PlatformFunctions.h index a9e85d274b..7b2851b2d9 100644 --- a/src/dawn_native/d3d12/PlatformFunctions.h +++ b/src/dawn_native/d3d12/PlatformFunctions.h @@ -36,6 +36,7 @@ namespace dawn_native { namespace d3d12 { MaybeError LoadFunctions(); bool IsPIXEventRuntimeLoaded() const; + bool IsDXCAvailable() const; // Functions from d3d12.dll PFN_D3D12_CREATE_DEVICE d3d12CreateDevice = nullptr; @@ -58,6 +59,12 @@ namespace dawn_native { namespace d3d12 { _COM_Outptr_ void** ppFactory); PFN_CREATE_DXGI_FACTORY2 createDxgiFactory2 = nullptr; + // Functions from dxcompiler.dll + using PFN_DXC_CREATE_INSTANCE = HRESULT(WINAPI*)(REFCLSID rclsid, + REFIID riid, + _COM_Outptr_ void** ppCompiler); + PFN_DXC_CREATE_INSTANCE dxcCreateInstance = nullptr; + // Functions from d3d3compiler.dll pD3DCompile d3dCompile = nullptr; @@ -84,13 +91,17 @@ namespace dawn_native { namespace d3d12 { MaybeError LoadD3D12(); MaybeError LoadD3D11(); MaybeError LoadDXGI(); - MaybeError LoadD3DCompiler(); + void LoadDXIL(); + void LoadDXCompiler(); + MaybeError LoadFXCompiler(); void LoadPIXRuntime(); DynamicLib mD3D12Lib; DynamicLib mD3D11Lib; DynamicLib mDXGILib; - DynamicLib mD3DCompilerLib; + DynamicLib mDXILLib; + DynamicLib mDXCompilerLib; + DynamicLib mFXCompilerLib; DynamicLib mPIXEventRuntimeLib; };