Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/util/d3d_common.h
4208 views
1
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]>
2
// SPDX-License-Identifier: CC-BY-NC-ND-4.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 <dxgitype.h>
15
#include <optional>
16
#include <string>
17
#include <vector>
18
#include <wrl/client.h>
19
20
class Error;
21
22
enum class GPUDriverType : u16;
23
24
struct D3D12_ROOT_SIGNATURE_DESC;
25
26
struct IDXGIFactory5;
27
struct IDXGIAdapter;
28
struct IDXGIAdapter1;
29
struct IDXGIOutput;
30
struct ID3D11Device;
31
struct ID3D11DeviceContext;
32
struct ID3D12Debug;
33
struct ID3D12Device1;
34
35
namespace D3DCommon {
36
37
// returns string representation of feature level
38
const char* GetFeatureLevelString(u32 render_api_version);
39
u32 GetRenderAPIVersionForFeatureLevel(D3D_FEATURE_LEVEL feature_level);
40
D3D_FEATURE_LEVEL GetFeatureLevelForNumber(u32 render_api_version);
41
u32 GetShaderModelForFeatureLevelNumber(u32 render_api_version);
42
43
// returns max feature level of a device
44
D3D_FEATURE_LEVEL GetDeviceMaxFeatureLevel(IDXGIAdapter1* adapter);
45
46
// create a dxgi factory
47
Microsoft::WRL::ComPtr<IDXGIFactory5> CreateFactory(bool debug, Error* error);
48
bool SupportsAllowTearing(IDXGIFactory5* factory);
49
50
// create a D3D device
51
bool CreateD3D11Device(IDXGIAdapter* adapter, UINT create_flags, const D3D_FEATURE_LEVEL* feature_levels,
52
UINT num_feature_levels, Microsoft::WRL::ComPtr<ID3D11Device>* device,
53
D3D_FEATURE_LEVEL* out_feature_level,
54
Microsoft::WRL::ComPtr<ID3D11DeviceContext>* immediate_context, Error* error);
55
56
// D3D12 functions
57
bool GetD3D12DebugInterface(Microsoft::WRL::ComPtr<ID3D12Debug>* debug, Error* error);
58
bool CreateD3D12Device(IDXGIAdapter* adapter, D3D_FEATURE_LEVEL feature_level,
59
Microsoft::WRL::ComPtr<ID3D12Device1>* device, Error* error);
60
Microsoft::WRL::ComPtr<ID3DBlob> SerializeRootSignature(const D3D12_ROOT_SIGNATURE_DESC* desc, Error* error);
61
62
// returns a list of all adapter names
63
GPUDevice::AdapterInfoList GetAdapterInfoList();
64
65
// returns the fullscreen mode to use for the specified dimensions
66
std::optional<DXGI_MODE_DESC>
67
GetRequestedExclusiveFullscreenModeDesc(IDXGIAdapter* adapter, const RECT& window_rect,
68
const GPUDevice::ExclusiveFullscreenMode* requested_fullscreen_mode,
69
DXGI_FORMAT format, IDXGIOutput** output);
70
71
// get an adapter based on name
72
Microsoft::WRL::ComPtr<IDXGIAdapter1> GetAdapterByName(IDXGIFactory5* factory, std::string_view name);
73
74
// returns the first adapter in the system
75
Microsoft::WRL::ComPtr<IDXGIAdapter1> GetFirstAdapter(IDXGIFactory5* factory);
76
77
// returns the adapter specified in the configuration, or the default
78
Microsoft::WRL::ComPtr<IDXGIAdapter1> GetChosenOrFirstAdapter(IDXGIFactory5* factory, std::string_view name);
79
80
// returns a utf-8 string of the specified adapter's name
81
std::string GetAdapterName(IDXGIAdapter1* adapter, GPUDriverType* out_driver_type = nullptr);
82
83
// returns the driver version from the registry as a string
84
std::string GetDriverVersionFromLUID(const LUID& luid);
85
86
std::optional<DynamicHeapArray<u8>> CompileShader(u32 shader_model, bool debug_device, GPUShaderStage stage,
87
std::string_view source, const char* entry_point, Error* error);
88
89
struct DXGIFormatMapping
90
{
91
DXGI_FORMAT resource_format;
92
DXGI_FORMAT srv_format;
93
DXGI_FORMAT rtv_format;
94
DXGI_FORMAT dsv_format;
95
};
96
const DXGIFormatMapping& GetFormatMapping(GPUTexture::Format format);
97
GPUTexture::Format GetFormatForDXGIFormat(DXGI_FORMAT format);
98
99
} // namespace D3DCommon
100
101