Path: blob/master/drivers/d3d12/rendering_context_driver_d3d12.h
22517 views
/**************************************************************************/1/* rendering_context_driver_d3d12.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/os/mutex.h"33#include "core/string/ustring.h"34#include "core/templates/rid_owner.h"35#include "rendering_device_driver_d3d12.h"36#include "servers/display/display_server.h"37#include "servers/rendering/rendering_context_driver.h"3839#if !defined(_MSC_VER) && !defined(__REQUIRED_RPCNDR_H_VERSION__)40// Match current version used by MinGW, MSVC and Direct3D 12 headers use 500.41#define __REQUIRED_RPCNDR_H_VERSION__ 47542#endif // !defined(_MSC_VER) && !defined(__REQUIRED_RPCNDR_H_VERSION__)4344GODOT_GCC_WARNING_PUSH45GODOT_GCC_WARNING_IGNORE("-Wimplicit-fallthrough")46GODOT_GCC_WARNING_IGNORE("-Wmissing-field-initializers")47GODOT_GCC_WARNING_IGNORE("-Wnon-virtual-dtor")48GODOT_GCC_WARNING_IGNORE("-Wshadow")49GODOT_GCC_WARNING_IGNORE("-Wswitch")50GODOT_CLANG_WARNING_PUSH51GODOT_CLANG_WARNING_IGNORE("-Wimplicit-fallthrough")52GODOT_CLANG_WARNING_IGNORE("-Wmissing-field-initializers")53GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor")54GODOT_CLANG_WARNING_IGNORE("-Wstring-plus-int")55GODOT_CLANG_WARNING_IGNORE("-Wswitch")5657#include <thirdparty/directx_headers/include/directx/d3dx12.h>5859GODOT_GCC_WARNING_POP60GODOT_CLANG_WARNING_POP6162#if defined(AS)63#undef AS64#endif6566#ifdef DCOMP_ENABLED67#include <dcomp.h>68#endif6970#include <wrl/client.h>7172#define ARRAY_SIZE(a) std_size(a)7374class RenderingContextDriverD3D12 : public RenderingContextDriver {75Microsoft::WRL::ComPtr<ID3D12DeviceFactory> device_factory;76Microsoft::WRL::ComPtr<IDXGIFactory2> dxgi_factory;77TightLocalVector<Device> driver_devices;78bool tearing_supported = false;7980Error _init_device_factory();81Error _initialize_debug_layers();82Error _create_dxgi_factory();83Error _initialize_devices();8485public:86virtual Error initialize() override;87virtual const Device &device_get(uint32_t p_device_index) const override;88virtual uint32_t device_get_count() const override;89virtual bool device_supports_present(uint32_t p_device_index, SurfaceID p_surface) const override;90virtual RenderingDeviceDriver *driver_create() override;91virtual void driver_free(RenderingDeviceDriver *p_driver) override;92virtual SurfaceID surface_create(const void *p_platform_data) override;93virtual void surface_set_size(SurfaceID p_surface, uint32_t p_width, uint32_t p_height) override;94virtual void surface_set_vsync_mode(SurfaceID p_surface, DisplayServer::VSyncMode p_vsync_mode) override;95virtual DisplayServer::VSyncMode surface_get_vsync_mode(SurfaceID p_surface) const override;96virtual void surface_set_hdr_output_enabled(SurfaceID p_surface, bool p_enabled) override;97virtual bool surface_get_hdr_output_enabled(SurfaceID p_surface) const override;98virtual void surface_set_hdr_output_reference_luminance(SurfaceID p_surface, float p_reference_luminance) override;99virtual float surface_get_hdr_output_reference_luminance(SurfaceID p_surface) const override;100virtual void surface_set_hdr_output_max_luminance(SurfaceID p_surface, float p_max_luminance) override;101virtual float surface_get_hdr_output_max_luminance(SurfaceID p_surface) const override;102virtual void surface_set_hdr_output_linear_luminance_scale(SurfaceID p_surface, float p_linear_luminance_scale) override;103virtual float surface_get_hdr_output_linear_luminance_scale(SurfaceID p_surface) const override;104virtual float surface_get_hdr_output_max_value(SurfaceID p_surface) const override;105virtual uint32_t surface_get_width(SurfaceID p_surface) const override;106virtual uint32_t surface_get_height(SurfaceID p_surface) const override;107virtual void surface_set_needs_resize(SurfaceID p_surface, bool p_needs_resize) override;108virtual bool surface_get_needs_resize(SurfaceID p_surface) const override;109virtual void surface_destroy(SurfaceID p_surface) override;110virtual bool is_debug_utils_enabled() const override;111112// Platform-specific data for the Windows embedded in this driver.113struct WindowPlatformData {114HWND window;115};116117// D3D12-only methods.118struct Surface {119HWND hwnd = nullptr;120uint32_t width = 0;121uint32_t height = 0;122DisplayServer::VSyncMode vsync_mode = DisplayServer::VSYNC_ENABLED;123bool needs_resize = false;124125bool hdr_output = false;126// BT.2408 recommendation of 203 nits for HDR Reference White, rounded to 200127// to be a more pleasant player-facing value. This value is used by Steam128// Deck and other Windows emulation that does not provide an SDRWhiteLevel.129float hdr_reference_luminance = 200.0f;130float hdr_max_luminance = 1000.0f;131float hdr_linear_luminance_scale = 80.0f;132133#ifdef DCOMP_ENABLED134Microsoft::WRL::ComPtr<IDCompositionDevice> composition_device;135Microsoft::WRL::ComPtr<IDCompositionTarget> composition_target;136Microsoft::WRL::ComPtr<IDCompositionVisual> composition_visual;137#endif138};139140HMODULE lib_d3d12 = nullptr;141HMODULE lib_dxgi = nullptr;142#ifdef DCOMP_ENABLED143HMODULE lib_dcomp = nullptr;144#endif145146IDXGIAdapter1 *create_adapter(uint32_t p_adapter_index) const;147ID3D12DeviceFactory *device_factory_get() const;148IDXGIFactory2 *dxgi_factory_get();149bool get_tearing_supported() const;150bool use_validation_layers() const;151152RenderingContextDriverD3D12();153virtual ~RenderingContextDriverD3D12() override;154};155156157