1 // Copyright 2018 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef DAWNNATIVE_D3D12_PLATFORMFUNCTIONS_H_ 16 #define DAWNNATIVE_D3D12_PLATFORMFUNCTIONS_H_ 17 18 #include "dawn_native/d3d12/d3d12_platform.h" 19 20 #include "common/DynamicLib.h" 21 #include "dawn_native/Error.h" 22 23 #include <d3dcompiler.h> 24 25 namespace dawn_native { namespace d3d12 { 26 27 // Loads the functions required from the platform dynamically so that we don't need to rely on 28 // them being present in the system. For example linking against d3d12.lib would prevent 29 // dawn_native from loading on Windows 7 system where d3d12.dll doesn't exist. 30 class PlatformFunctions { 31 public: 32 PlatformFunctions(); 33 ~PlatformFunctions(); 34 35 MaybeError LoadFunctions(); 36 bool IsPIXEventRuntimeLoaded() const; 37 bool IsDXCAvailable() const; 38 39 // Functions from d3d12.dll 40 PFN_D3D12_CREATE_DEVICE d3d12CreateDevice = nullptr; 41 PFN_D3D12_GET_DEBUG_INTERFACE d3d12GetDebugInterface = nullptr; 42 43 PFN_D3D12_SERIALIZE_ROOT_SIGNATURE d3d12SerializeRootSignature = nullptr; 44 PFN_D3D12_CREATE_ROOT_SIGNATURE_DESERIALIZER d3d12CreateRootSignatureDeserializer = nullptr; 45 PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE d3d12SerializeVersionedRootSignature = nullptr; 46 PFN_D3D12_CREATE_VERSIONED_ROOT_SIGNATURE_DESERIALIZER 47 d3d12CreateVersionedRootSignatureDeserializer = nullptr; 48 49 // Functions from dxgi.dll 50 using PFN_DXGI_GET_DEBUG_INTERFACE1 = HRESULT(WINAPI*)(UINT Flags, 51 REFIID riid, 52 _COM_Outptr_ void** pDebug); 53 PFN_DXGI_GET_DEBUG_INTERFACE1 dxgiGetDebugInterface1 = nullptr; 54 55 using PFN_CREATE_DXGI_FACTORY2 = HRESULT(WINAPI*)(UINT Flags, 56 REFIID riid, 57 _COM_Outptr_ void** ppFactory); 58 PFN_CREATE_DXGI_FACTORY2 createDxgiFactory2 = nullptr; 59 60 // Functions from dxcompiler.dll 61 using PFN_DXC_CREATE_INSTANCE = HRESULT(WINAPI*)(REFCLSID rclsid, 62 REFIID riid, 63 _COM_Outptr_ void** ppCompiler); 64 PFN_DXC_CREATE_INSTANCE dxcCreateInstance = nullptr; 65 66 // Functions from d3d3compiler.dll 67 pD3DCompile d3dCompile = nullptr; 68 pD3DDisassemble d3dDisassemble = nullptr; 69 70 // Functions from WinPixEventRuntime.dll 71 using PFN_PIX_END_EVENT_ON_COMMAND_LIST = 72 HRESULT(WINAPI*)(ID3D12GraphicsCommandList* commandList); 73 74 PFN_PIX_END_EVENT_ON_COMMAND_LIST pixEndEventOnCommandList = nullptr; 75 76 using PFN_PIX_BEGIN_EVENT_ON_COMMAND_LIST = HRESULT( 77 WINAPI*)(ID3D12GraphicsCommandList* commandList, UINT64 color, _In_ PCSTR formatString); 78 79 PFN_PIX_BEGIN_EVENT_ON_COMMAND_LIST pixBeginEventOnCommandList = nullptr; 80 81 using PFN_SET_MARKER_ON_COMMAND_LIST = HRESULT( 82 WINAPI*)(ID3D12GraphicsCommandList* commandList, UINT64 color, _In_ PCSTR formatString); 83 84 PFN_SET_MARKER_ON_COMMAND_LIST pixSetMarkerOnCommandList = nullptr; 85 86 // Functions from D3D11.dll 87 PFN_D3D11ON12_CREATE_DEVICE d3d11on12CreateDevice = nullptr; 88 89 private: 90 MaybeError LoadD3D12(); 91 MaybeError LoadD3D11(); 92 MaybeError LoadDXGI(); 93 void LoadDXCLibraries(); 94 void LoadDXIL(const std::string& baseWindowsSDKPath); 95 void LoadDXCompiler(const std::string& baseWindowsSDKPath); 96 MaybeError LoadFXCompiler(); 97 void LoadPIXRuntime(); 98 99 DynamicLib mD3D12Lib; 100 DynamicLib mD3D11Lib; 101 DynamicLib mDXGILib; 102 DynamicLib mDXILLib; 103 DynamicLib mDXCompilerLib; 104 DynamicLib mFXCompilerLib; 105 DynamicLib mPIXEventRuntimeLib; 106 }; 107 108 }} // namespace dawn_native::d3d12 109 110 #endif // DAWNNATIVE_D3D12_PLATFORMFUNCTIONS_H_ 111