Debian Codegraph @

drivers/d3d12/rendering_context_driver_d3d12.h

raw symbols SCIP
1 /**************************************************************************/
2 /* rendering_context_driver_d3d12.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/os/mutex.h"
34 #include "core/string/ustring.h"
35 #include "core/templates/rid_owner.h"
36 #include "rendering_device_driver_d3d12.h"
37 #include "servers/display/display_server.h"
38 #include "servers/rendering/rendering_context_driver.h"
39
40 #if !defined(_MSC_VER) && !defined(__REQUIRED_RPCNDR_H_VERSION__)
41 // Match current version used by MinGW, MSVC and Direct3D 12 headers use 500.
42 #define __REQUIRED_RPCNDR_H_VERSION__ 475
43 #endif // !defined(_MSC_VER) && !defined(__REQUIRED_RPCNDR_H_VERSION__)
44
45 GODOT_GCC_WARNING_PUSH
46 GODOT_GCC_WARNING_IGNORE("-Wimplicit-fallthrough")
47 GODOT_GCC_WARNING_IGNORE("-Wmissing-field-initializers")
48 GODOT_GCC_WARNING_IGNORE("-Wnon-virtual-dtor")
49 GODOT_GCC_WARNING_IGNORE("-Wshadow")
50 GODOT_GCC_WARNING_IGNORE("-Wswitch")
51 GODOT_CLANG_WARNING_PUSH
52 GODOT_CLANG_WARNING_IGNORE("-Wimplicit-fallthrough")
53 GODOT_CLANG_WARNING_IGNORE("-Wmissing-field-initializers")
54 GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor")
55 GODOT_CLANG_WARNING_IGNORE("-Wstring-plus-int")
56 GODOT_CLANG_WARNING_IGNORE("-Wswitch")
57
58 #include <thirdparty/directx_headers/include/directx/d3dx12.h>
59
60 GODOT_GCC_WARNING_POP
61 GODOT_CLANG_WARNING_POP
62
63 #if defined(AS)
64 #undef AS
65 #endif
66
67 #ifdef DCOMP_ENABLED
68 #include <dcomp.h>
69 #endif
70
71 #include <wrl/client.h>
72
73 #define ARRAY_SIZE(a) std_size(a)
74
75 class RenderingContextDriverD3D12 : public RenderingContextDriver {
76 Microsoft::WRL::ComPtr<ID3D12DeviceFactory> device_factory;
77 Microsoft::WRL::ComPtr<IDXGIFactory2> dxgi_factory;
78 TightLocalVector<Device> driver_devices;
79 bool tearing_supported = false;
80
81 Error _init_device_factory();
82 Error _initialize_debug_layers();
83 Error _initialize_devices();
84
85 public:
86 virtual Error initialize() override;
87 virtual const Device &device_get(uint32_t p_device_index) const override;
88 virtual uint32_t device_get_count() const override;
89 virtual bool device_supports_present(uint32_t p_device_index, SurfaceID p_surface) const override;
90 virtual RenderingDeviceDriver *driver_create() override;
91 virtual void driver_free(RenderingDeviceDriver *p_driver) override;
92 virtual SurfaceID surface_create(const void *p_platform_data) override;
93 virtual void surface_set_size(SurfaceID p_surface, uint32_t p_width, uint32_t p_height) override;
94 virtual void surface_set_vsync_mode(SurfaceID p_surface, DisplayServer::VSyncMode p_vsync_mode) override;
95 virtual DisplayServer::VSyncMode surface_get_vsync_mode(SurfaceID p_surface) const override;
96 virtual uint32_t surface_get_width(SurfaceID p_surface) const override;
97 virtual uint32_t surface_get_height(SurfaceID p_surface) const override;
98 virtual void surface_set_needs_resize(SurfaceID p_surface, bool p_needs_resize) override;
99 virtual bool surface_get_needs_resize(SurfaceID p_surface) const override;
100 virtual void surface_destroy(SurfaceID p_surface) override;
101 virtual bool is_debug_utils_enabled() const override;
102
103 // Platform-specific data for the Windows embedded in this driver.
104 struct WindowPlatformData {
105 HWND window;
106 };
107
108 // D3D12-only methods.
109 struct Surface {
110 HWND hwnd = nullptr;
111 uint32_t width = 0;
112 uint32_t height = 0;
113 DisplayServer::VSyncMode vsync_mode = DisplayServer::VSYNC_ENABLED;
114 bool needs_resize = false;
115 #ifdef DCOMP_ENABLED
116 Microsoft::WRL::ComPtr<IDCompositionDevice> composition_device;
117 Microsoft::WRL::ComPtr<IDCompositionTarget> composition_target;
118 Microsoft::WRL::ComPtr<IDCompositionVisual> composition_visual;
119 #endif
120 };
121
122 HMODULE lib_d3d12 = nullptr;
123 HMODULE lib_dxgi = nullptr;
124 #ifdef DCOMP_ENABLED
125 HMODULE lib_dcomp = nullptr;
126 #endif
127
128 IDXGIAdapter1 *create_adapter(uint32_t p_adapter_index) const;
129 ID3D12DeviceFactory *device_factory_get() const;
130 IDXGIFactory2 *dxgi_factory_get() const;
131 bool get_tearing_supported() const;
132 bool use_validation_layers() const;
133
134 RenderingContextDriverD3D12();
135 virtual ~RenderingContextDriverD3D12() override;
136 };