Debian Codegraph @

Source/Core/VideoBackends/D3D/D3DBase.h

raw symbols SCIP
1 // Copyright 2010 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <d3d11_4.h>
7 #include <d3dcompiler.h>
8 #include <dxgi1_6.h>
9 #include <fmt/format.h>
10 #include <vector>
11 #include <wrl/client.h>
12
13 #include "Common/CommonTypes.h"
14 #include "Common/HRWrap.h"
15
16 namespace DX11
17 {
18 using Microsoft::WRL::ComPtr;
19 class SwapChain;
20
21 namespace D3D
22 {
23 extern ComPtr<IDXGIFactory> dxgi_factory;
24 extern ComPtr<ID3D11Device> device;
25 extern ComPtr<ID3D11Device1> device1;
26 extern ComPtr<ID3D11DeviceContext> context;
27 extern D3D_FEATURE_LEVEL feature_level;
28
29 bool Create(u32 adapter_index, bool enable_debug_layer);
30 void Destroy();
31
32 // Returns a list of supported AA modes for the current device.
33 std::vector<u32> GetAAModes(u32 adapter_index);
34
35 // Checks for support of the given texture format.
36 bool SupportsTextureFormat(DXGI_FORMAT format);
37
38 // Checks for logic op support.
39 bool SupportsLogicOp(u32 adapter_index);
40
41 } // namespace D3D
42
43 // Wrapper for HRESULT to be used with fmt. Note that we can't create a fmt::formatter directly
44 // for HRESULT as HRESULT is simply a typedef on long and not a distinct type.
45 // Unlike the version in Common, this variant also knows to call GetDeviceRemovedReason if needed.
46 struct DX11HRWrap
47 {
48 constexpr explicit DX11HRWrap(HRESULT hr) : m_hr(hr) {}
49 const HRESULT m_hr;
50 };
51
52 } // namespace DX11
53
54 template <>
55 struct fmt::formatter<DX11::DX11HRWrap>
56 {
57 constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
58 template <typename FormatContext>
59 auto format(const DX11::DX11HRWrap& hr, FormatContext& ctx) const
60 {
61 if (hr.m_hr == DXGI_ERROR_DEVICE_REMOVED && DX11::D3D::device != nullptr)
62 {
63 return fmt::format_to(ctx.out(), "{}\nDevice removal reason: {}", Common::HRWrap(hr.m_hr),
64 Common::HRWrap(DX11::D3D::device->GetDeviceRemovedReason()));
65 }
66 else
67 {
68 return fmt::format_to(ctx.out(), "{}", Common::HRWrap(hr.m_hr));
69 }
70 }
71 };