d3d_common.h (2656B)
1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0) 3 4 #pragma once 5 6 #include "gpu_device.h" 7 8 #include "common/heap_array.h" 9 #include "common/types.h" 10 #include "common/windows_headers.h" 11 12 #include <d3dcommon.h> 13 #include <dxgiformat.h> 14 #include <optional> 15 #include <string> 16 #include <vector> 17 #include <wrl/client.h> 18 19 class Error; 20 21 struct IDXGIFactory5; 22 struct IDXGIAdapter1; 23 struct IDXGIOutput; 24 struct DXGI_MODE_DESC; 25 26 namespace D3DCommon { 27 // returns string representation of feature level 28 const char* GetFeatureLevelString(D3D_FEATURE_LEVEL feature_level); 29 const char* GetFeatureLevelShaderModelString(D3D_FEATURE_LEVEL feature_level); 30 31 // returns max feature level of a device 32 D3D_FEATURE_LEVEL GetDeviceMaxFeatureLevel(IDXGIAdapter1* adapter); 33 34 // create a dxgi factory 35 Microsoft::WRL::ComPtr<IDXGIFactory5> CreateFactory(bool debug, Error* error); 36 37 // returns a list of all adapter names 38 GPUDevice::AdapterInfoList GetAdapterInfoList(); 39 40 // returns the fullscreen mode to use for the specified dimensions 41 bool GetRequestedExclusiveFullscreenModeDesc(IDXGIFactory5* factory, const RECT& window_rect, u32 width, u32 height, 42 float refresh_rate, DXGI_FORMAT format, DXGI_MODE_DESC* fullscreen_mode, 43 IDXGIOutput** output); 44 45 // get an adapter based on name 46 Microsoft::WRL::ComPtr<IDXGIAdapter1> GetAdapterByName(IDXGIFactory5* factory, std::string_view name); 47 48 // returns the first adapter in the system 49 Microsoft::WRL::ComPtr<IDXGIAdapter1> GetFirstAdapter(IDXGIFactory5* factory); 50 51 // returns the adapter specified in the configuration, or the default 52 Microsoft::WRL::ComPtr<IDXGIAdapter1> GetChosenOrFirstAdapter(IDXGIFactory5* factory, std::string_view name); 53 54 // returns a utf-8 string of the specified adapter's name 55 std::string GetAdapterName(IDXGIAdapter1* adapter); 56 57 // returns the driver version from the registry as a string 58 std::string GetDriverVersionFromLUID(const LUID& luid); 59 60 u32 GetShaderModelForFeatureLevel(D3D_FEATURE_LEVEL feature_level); 61 62 std::optional<DynamicHeapArray<u8>> CompileShader(u32 shader_model, bool debug_device, GPUShaderStage stage, 63 std::string_view source, const char* entry_point, Error* error); 64 65 struct DXGIFormatMapping 66 { 67 DXGI_FORMAT resource_format; 68 DXGI_FORMAT srv_format; 69 DXGI_FORMAT rtv_format; 70 DXGI_FORMAT dsv_format; 71 }; 72 const DXGIFormatMapping& GetFormatMapping(GPUTexture::Format format); 73 GPUTexture::Format GetFormatForDXGIFormat(DXGI_FORMAT format); 74 } // namespace D3DCommon