Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/drivers/d3d12/rendering_context_driver_d3d12.h
9981 views
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_server.h"
38
#include "servers/rendering/rendering_context_driver.h"
39
40
#if defined(AS)
41
#undef AS
42
#endif
43
44
#ifdef DCOMP_ENABLED
45
#include <dcomp.h>
46
#endif
47
48
#include <d3dx12.h>
49
#include <dxgi1_6.h>
50
51
#include <wrl/client.h>
52
53
using Microsoft::WRL::ComPtr;
54
55
#define ARRAY_SIZE(a) std::size(a)
56
57
class RenderingContextDriverD3D12 : public RenderingContextDriver {
58
ComPtr<ID3D12DeviceFactory> device_factory;
59
ComPtr<IDXGIFactory2> dxgi_factory;
60
TightLocalVector<Device> driver_devices;
61
bool tearing_supported = false;
62
63
Error _init_device_factory();
64
Error _initialize_debug_layers();
65
Error _initialize_devices();
66
67
public:
68
virtual Error initialize() override;
69
virtual const Device &device_get(uint32_t p_device_index) const override;
70
virtual uint32_t device_get_count() const override;
71
virtual bool device_supports_present(uint32_t p_device_index, SurfaceID p_surface) const override;
72
virtual RenderingDeviceDriver *driver_create() override;
73
virtual void driver_free(RenderingDeviceDriver *p_driver) override;
74
virtual SurfaceID surface_create(const void *p_platform_data) override;
75
virtual void surface_set_size(SurfaceID p_surface, uint32_t p_width, uint32_t p_height) override;
76
virtual void surface_set_vsync_mode(SurfaceID p_surface, DisplayServer::VSyncMode p_vsync_mode) override;
77
virtual DisplayServer::VSyncMode surface_get_vsync_mode(SurfaceID p_surface) const override;
78
virtual uint32_t surface_get_width(SurfaceID p_surface) const override;
79
virtual uint32_t surface_get_height(SurfaceID p_surface) const override;
80
virtual void surface_set_needs_resize(SurfaceID p_surface, bool p_needs_resize) override;
81
virtual bool surface_get_needs_resize(SurfaceID p_surface) const override;
82
virtual void surface_destroy(SurfaceID p_surface) override;
83
virtual bool is_debug_utils_enabled() const override;
84
85
// Platform-specific data for the Windows embedded in this driver.
86
struct WindowPlatformData {
87
HWND window;
88
};
89
90
// D3D12-only methods.
91
struct Surface {
92
HWND hwnd = nullptr;
93
uint32_t width = 0;
94
uint32_t height = 0;
95
DisplayServer::VSyncMode vsync_mode = DisplayServer::VSYNC_ENABLED;
96
bool needs_resize = false;
97
#ifdef DCOMP_ENABLED
98
ComPtr<IDCompositionDevice> composition_device;
99
ComPtr<IDCompositionTarget> composition_target;
100
ComPtr<IDCompositionVisual> composition_visual;
101
#endif
102
};
103
104
HMODULE lib_d3d12 = nullptr;
105
HMODULE lib_dxgi = nullptr;
106
#ifdef DCOMP_ENABLED
107
HMODULE lib_dcomp = nullptr;
108
#endif
109
110
IDXGIAdapter1 *create_adapter(uint32_t p_adapter_index) const;
111
ID3D12DeviceFactory *device_factory_get() const;
112
IDXGIFactory2 *dxgi_factory_get() const;
113
bool get_tearing_supported() const;
114
bool use_validation_layers() const;
115
116
RenderingContextDriverD3D12();
117
virtual ~RenderingContextDriverD3D12() override;
118
};
119
120