Path: blob/master/drivers/d3d12/rendering_context_driver_d3d12.h
9981 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_server.h"37#include "servers/rendering/rendering_context_driver.h"3839#if defined(AS)40#undef AS41#endif4243#ifdef DCOMP_ENABLED44#include <dcomp.h>45#endif4647#include <d3dx12.h>48#include <dxgi1_6.h>4950#include <wrl/client.h>5152using Microsoft::WRL::ComPtr;5354#define ARRAY_SIZE(a) std::size(a)5556class RenderingContextDriverD3D12 : public RenderingContextDriver {57ComPtr<ID3D12DeviceFactory> device_factory;58ComPtr<IDXGIFactory2> dxgi_factory;59TightLocalVector<Device> driver_devices;60bool tearing_supported = false;6162Error _init_device_factory();63Error _initialize_debug_layers();64Error _initialize_devices();6566public:67virtual Error initialize() override;68virtual const Device &device_get(uint32_t p_device_index) const override;69virtual uint32_t device_get_count() const override;70virtual bool device_supports_present(uint32_t p_device_index, SurfaceID p_surface) const override;71virtual RenderingDeviceDriver *driver_create() override;72virtual void driver_free(RenderingDeviceDriver *p_driver) override;73virtual SurfaceID surface_create(const void *p_platform_data) override;74virtual void surface_set_size(SurfaceID p_surface, uint32_t p_width, uint32_t p_height) override;75virtual void surface_set_vsync_mode(SurfaceID p_surface, DisplayServer::VSyncMode p_vsync_mode) override;76virtual DisplayServer::VSyncMode surface_get_vsync_mode(SurfaceID p_surface) const override;77virtual uint32_t surface_get_width(SurfaceID p_surface) const override;78virtual uint32_t surface_get_height(SurfaceID p_surface) const override;79virtual void surface_set_needs_resize(SurfaceID p_surface, bool p_needs_resize) override;80virtual bool surface_get_needs_resize(SurfaceID p_surface) const override;81virtual void surface_destroy(SurfaceID p_surface) override;82virtual bool is_debug_utils_enabled() const override;8384// Platform-specific data for the Windows embedded in this driver.85struct WindowPlatformData {86HWND window;87};8889// D3D12-only methods.90struct Surface {91HWND hwnd = nullptr;92uint32_t width = 0;93uint32_t height = 0;94DisplayServer::VSyncMode vsync_mode = DisplayServer::VSYNC_ENABLED;95bool needs_resize = false;96#ifdef DCOMP_ENABLED97ComPtr<IDCompositionDevice> composition_device;98ComPtr<IDCompositionTarget> composition_target;99ComPtr<IDCompositionVisual> composition_visual;100#endif101};102103HMODULE lib_d3d12 = nullptr;104HMODULE lib_dxgi = nullptr;105#ifdef DCOMP_ENABLED106HMODULE lib_dcomp = nullptr;107#endif108109IDXGIAdapter1 *create_adapter(uint32_t p_adapter_index) const;110ID3D12DeviceFactory *device_factory_get() const;111IDXGIFactory2 *dxgi_factory_get() const;112bool get_tearing_supported() const;113bool use_validation_layers() const;114115RenderingContextDriverD3D12();116virtual ~RenderingContextDriverD3D12() override;117};118119120