| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
|
| 42 |
#define __REQUIRED_RPCNDR_H_VERSION__ 475 |
| 43 |
#endif |
| 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 |
|
| 104 |
struct WindowPlatformData { |
| 105 |
HWND window; |
| 106 |
}; |
| 107 |
|
| 108 |
|
| 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 |
}; |