diff --git a/drivers/d3d12/SCsub b/drivers/d3d12/SCsub index 29b3714baea..0b028b66fd4 100644 --- a/drivers/d3d12/SCsub +++ b/drivers/d3d12/SCsub @@ -7,49 +7,25 @@ from pathlib import Path import methods Import("env") - env_d3d12_rdd = env.Clone() -thirdparty_obj = [] - - -# DirectX Headers (must take precedence over Windows SDK's). - -env.Prepend(CPPPATH=["#thirdparty/directx_headers/include/directx"]) -env_d3d12_rdd.Prepend(CPPPATH=["#thirdparty/directx_headers/include/directx"]) -env_d3d12_rdd.Prepend(CPPPATH=["#thirdparty/directx_headers/include/dxguids"]) - - -# Direct3D 12 Memory Allocator. - -env.Append(CPPPATH=["#thirdparty/d3d12ma"]) -env_d3d12_rdd.Append(CPPPATH=["#thirdparty/d3d12ma"]) - - # Agility SDK. - if env["agility_sdk_path"] != "" and os.path.exists(env["agility_sdk_path"]): env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_ENABLED"]) if env["agility_sdk_multiarch"]: env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_MULTIARCH_ENABLED"]) - # PIX. - if env["use_pix"]: env_d3d12_rdd.Append(CPPDEFINES=["PIX_ENABLED"]) env_d3d12_rdd.Append(CPPPATH=[env["pix_path"] + "/Include"]) - # Direct composition. - if "dcomp" in env.get("supported", []): env_d3d12_rdd.Append(CPPDEFINES=["DCOMP_ENABLED"]) env.Append(CPPDEFINES=["DCOMP_ENABLED"]) # Used in header included in platform. - # Mesa (SPIR-V to DXIL functionality). - mesa_libs = env["mesa_libs"] if env.msvc and os.path.exists(env["mesa_libs"] + "-" + env["arch"] + "-msvc"): mesa_libs = env["mesa_libs"] + "-" + env["arch"] + "-msvc" @@ -137,6 +113,7 @@ extra_defines += [ ("PACKAGE_BUGREPORT", '\\"https://gitlab.freedesktop.org/mesa/mesa/-/issues\\"'), "PIPE_SUBSYSTEM_WINDOWS_USER", ("_Static_assert", "static_assert"), + "HAVE_STRUCT_TIMESPEC", ] if env.msvc: @@ -148,30 +125,39 @@ if env.msvc: "_SCL_SECURE_NO_WARNINGS", "_SCL_SECURE_NO_DEPRECATE", "_ALLOW_KEYWORD_MACROS", - ("_HAS_EXCEPTIONS", 0), "NOMINMAX", - "HAVE_STRUCT_TIMESPEC", ] else: extra_defines += [ - "HAVE_STRUCT_TIMESPEC", + # Match current version used by MinGW. MSVC and Direct3D 12 headers use 500. + ("__REQUIRED_RPCNDR_H_VERSION__", 475), ] if methods.using_gcc(env) and methods.get_compiler_version(env)["major"] < 13: # `region` & `endregion` not recognized as valid pragmas. env_d3d12_rdd.Append(CCFLAGS=["-Wno-unknown-pragmas"]) - env.Append(CCFLAGS=["-Wno-unknown-pragmas"]) # This is needed since rendering_device_d3d12.cpp needs to include some Mesa internals. env_d3d12_rdd.Prepend(CPPPATH=mesa_private_inc_paths) # For the same reason as above, the defines must be the same as in the 3rd-party code itself. env_d3d12_rdd.Append(CPPDEFINES=extra_defines) +# Thirdparty. +thirdparty_obj = [] -# Add all. +env_thirdparty = env_d3d12_rdd.Clone() +env_thirdparty.disable_warnings() +env_thirdparty.Prepend( + CPPPATH=[ + "#thirdparty/directx_headers/include/directx", + "#thirdparty/directx_headers/include/dxguids", + "#thirdparty/d3d12ma", + ] +) + +env_thirdparty.add_source_files(thirdparty_obj, "#thirdparty/d3d12ma/D3D12MemAlloc.cpp") env.drivers_sources += thirdparty_obj - # Godot source files. driver_obj = [] diff --git a/drivers/d3d12/d3d12ma.cpp b/drivers/d3d12/d3d12ma.cpp deleted file mode 100644 index e76d78a5300..00000000000 --- a/drivers/d3d12/d3d12ma.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************/ -/* d3d12ma.cpp */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/**************************************************************************/ - -// Wrapper needed to set the required rpcndr version for MinGW compatibility. -// Since we're compiling thirdparty code in a Godot SCons environment with -// warnings enabled, we also need to silence them manually. - -#include "rendering_device_driver_d3d12.h" // For __REQUIRED_RPCNDR_H_VERSION__. - -GODOT_GCC_WARNING_PUSH -GODOT_GCC_WARNING_IGNORE("-Wduplicated-branches") -GODOT_GCC_WARNING_IGNORE("-Wimplicit-fallthrough") -GODOT_GCC_WARNING_IGNORE("-Wmaybe-uninitialized") -GODOT_GCC_WARNING_IGNORE("-Wmissing-field-initializers") -GODOT_GCC_WARNING_IGNORE("-Wnon-virtual-dtor") -GODOT_GCC_WARNING_IGNORE("-Wnonnull-compare") -GODOT_GCC_WARNING_IGNORE("-Wshadow") -GODOT_GCC_WARNING_IGNORE("-Wsign-compare") -GODOT_GCC_WARNING_IGNORE("-Wswitch") -GODOT_GCC_WARNING_IGNORE("-Wunused-function") -GODOT_GCC_WARNING_IGNORE("-Wunused-variable") -GODOT_CLANG_WARNING_PUSH -GODOT_CLANG_WARNING_IGNORE("-Wimplicit-fallthrough") -GODOT_CLANG_WARNING_IGNORE("-Wmissing-field-initializers") -GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor") -GODOT_CLANG_WARNING_IGNORE("-Wstring-plus-int") -GODOT_CLANG_WARNING_IGNORE("-Wswitch") -GODOT_CLANG_WARNING_IGNORE("-Wtautological-undefined-compare") -GODOT_CLANG_WARNING_IGNORE("-Wunused-but-set-variable") -GODOT_CLANG_WARNING_IGNORE("-Wunused-function") -GODOT_CLANG_WARNING_IGNORE("-Wunused-private-field") -GODOT_CLANG_WARNING_IGNORE("-Wunused-variable") -GODOT_MSVC_WARNING_PUSH -GODOT_MSVC_WARNING_IGNORE(4189) // "Local variable is initialized but not referenced". -GODOT_MSVC_WARNING_IGNORE(4505) // "Unreferenced local function has been removed". - -#include - -GODOT_GCC_WARNING_POP -GODOT_CLANG_WARNING_POP -GODOT_MSVC_WARNING_POP diff --git a/drivers/d3d12/rendering_context_driver_d3d12.cpp b/drivers/d3d12/rendering_context_driver_d3d12.cpp index eabfbe71d68..817b50eb240 100644 --- a/drivers/d3d12/rendering_context_driver_d3d12.cpp +++ b/drivers/d3d12/rendering_context_driver_d3d12.cpp @@ -51,6 +51,7 @@ GODOT_CLANG_WARNING_IGNORE("-Wstring-plus-int") GODOT_CLANG_WARNING_IGNORE("-Wswitch") #include +#include GODOT_GCC_WARNING_POP GODOT_CLANG_WARNING_POP @@ -58,9 +59,11 @@ GODOT_CLANG_WARNING_POP #if !defined(_MSC_VER) #include -#include +#include #endif +using Microsoft::WRL::ComPtr; + // Note: symbols are not available in MinGW and old MSVC import libraries. // GUID values from https://github.com/microsoft/DirectX-Headers/blob/7a9f4d06911d30eecb56a4956dab29dcca2709ed/include/directx/d3d12.idl#L5877-L5881 const GUID CLSID_D3D12DeviceFactoryGodot = { 0x114863bf, 0xc386, 0x4aee, { 0xb3, 0x9d, 0x8f, 0x0b, 0xbb, 0x06, 0x29, 0x55 } }; @@ -72,7 +75,7 @@ const GUID CLSID_D3D12SDKConfigurationGodot = { 0x7cda6aca, 0xa03e, 0x49c8, { 0x #define _MSC_VER 1800 #endif #define USE_PIX -#include "WinPixEventRuntime/pix3.h" +#include #if defined(__GNUC__) #undef _MSC_VER #endif diff --git a/drivers/d3d12/rendering_context_driver_d3d12.h b/drivers/d3d12/rendering_context_driver_d3d12.h index b8c2d6d2788..cd856e43f4c 100644 --- a/drivers/d3d12/rendering_context_driver_d3d12.h +++ b/drivers/d3d12/rendering_context_driver_d3d12.h @@ -37,6 +37,11 @@ #include "servers/display/display_server.h" #include "servers/rendering/rendering_context_driver.h" +#if !defined(_MSC_VER) && !defined(__REQUIRED_RPCNDR_H_VERSION__) +// Match current version used by MinGW, MSVC and Direct3D 12 headers use 500. +#define __REQUIRED_RPCNDR_H_VERSION__ 475 +#endif // !defined(_MSC_VER) && !defined(__REQUIRED_RPCNDR_H_VERSION__) + GODOT_GCC_WARNING_PUSH GODOT_GCC_WARNING_IGNORE("-Wimplicit-fallthrough") GODOT_GCC_WARNING_IGNORE("-Wmissing-field-initializers") @@ -50,6 +55,11 @@ GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor") GODOT_CLANG_WARNING_IGNORE("-Wstring-plus-int") GODOT_CLANG_WARNING_IGNORE("-Wswitch") +#include + +GODOT_GCC_WARNING_POP +GODOT_CLANG_WARNING_POP + #if defined(AS) #undef AS #endif @@ -58,21 +68,13 @@ GODOT_CLANG_WARNING_IGNORE("-Wswitch") #include #endif -#include -#include - #include -GODOT_GCC_WARNING_POP -GODOT_CLANG_WARNING_POP - -using Microsoft::WRL::ComPtr; - #define ARRAY_SIZE(a) std_size(a) class RenderingContextDriverD3D12 : public RenderingContextDriver { - ComPtr device_factory; - ComPtr dxgi_factory; + Microsoft::WRL::ComPtr device_factory; + Microsoft::WRL::ComPtr dxgi_factory; TightLocalVector driver_devices; bool tearing_supported = false; @@ -111,9 +113,9 @@ public: DisplayServer::VSyncMode vsync_mode = DisplayServer::VSYNC_ENABLED; bool needs_resize = false; #ifdef DCOMP_ENABLED - ComPtr composition_device; - ComPtr composition_target; - ComPtr composition_visual; + Microsoft::WRL::ComPtr composition_device; + Microsoft::WRL::ComPtr composition_target; + Microsoft::WRL::ComPtr composition_visual; #endif }; diff --git a/drivers/d3d12/rendering_device_driver_d3d12.cpp b/drivers/d3d12/rendering_device_driver_d3d12.cpp index e0c52c17cd9..8a7b22ac4ba 100644 --- a/drivers/d3d12/rendering_device_driver_d3d12.cpp +++ b/drivers/d3d12/rendering_device_driver_d3d12.cpp @@ -58,6 +58,10 @@ GODOT_MSVC_WARNING_PUSH GODOT_MSVC_WARNING_IGNORE(4200) // "nonstandard extension used: zero-sized array in struct/union". GODOT_MSVC_WARNING_IGNORE(4806) // "'&': unsafe operation: no value of type 'bool' promoted to type 'uint32_t' can equal the given constant". +#include +#define D3D12MA_D3D12_HEADERS_ALREADY_INCLUDED +#include + #include #include #include @@ -72,9 +76,11 @@ GODOT_MSVC_WARNING_POP #if !defined(_MSC_VER) #include -#include +#include #endif +using Microsoft::WRL::ComPtr; + // Mesa may define this. #ifdef UNUSED #undef UNUSED @@ -85,7 +91,7 @@ GODOT_MSVC_WARNING_POP #define _MSC_VER 1800 #endif #define USE_PIX -#include "WinPixEventRuntime/pix3.h" +#include #if defined(__GNUC__) #undef _MSC_VER #endif @@ -6611,6 +6617,7 @@ Error RenderingDeviceDriverD3D12::initialize(uint32_t p_device_index, uint32_t p adapter.Attach(context_driver->create_adapter(p_device_index)); ERR_FAIL_NULL_V(adapter, ERR_CANT_CREATE); + DXGI_ADAPTER_DESC adapter_desc; HRESULT res = adapter->GetDesc(&adapter_desc); ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE); diff --git a/drivers/d3d12/rendering_device_driver_d3d12.h b/drivers/d3d12/rendering_device_driver_d3d12.h index 23ccfaf5db5..e3daecc722f 100644 --- a/drivers/d3d12/rendering_device_driver_d3d12.h +++ b/drivers/d3d12/rendering_device_driver_d3d12.h @@ -37,10 +37,10 @@ #include "rendering_shader_container_d3d12.h" #include "servers/rendering/rendering_device_driver.h" -#ifndef _MSC_VER +#if !defined(_MSC_VER) && !defined(__REQUIRED_RPCNDR_H_VERSION__) // Match current version used by MinGW, MSVC and Direct3D 12 headers use 500. #define __REQUIRED_RPCNDR_H_VERSION__ 475 -#endif +#endif // !defined(_MSC_VER) && !defined(__REQUIRED_RPCNDR_H_VERSION__) GODOT_GCC_WARNING_PUSH GODOT_GCC_WARNING_IGNORE("-Wimplicit-fallthrough") @@ -55,17 +55,12 @@ GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor") GODOT_CLANG_WARNING_IGNORE("-Wstring-plus-int") GODOT_CLANG_WARNING_IGNORE("-Wswitch") -#include -#include -#define D3D12MA_D3D12_HEADERS_ALREADY_INCLUDED -#include - -#include +#include GODOT_GCC_WARNING_POP GODOT_CLANG_WARNING_POP -using Microsoft::WRL::ComPtr; +#include #ifdef DEV_ENABLED #define CUSTOM_INFO_QUEUE_ENABLED 0 @@ -73,6 +68,14 @@ using Microsoft::WRL::ComPtr; class RenderingContextDriverD3D12; +namespace D3D12MA { +class Allocation; +class Allocator; +}; // namespace D3D12MA + +struct IDXGIAdapter; +struct IDXGISwapChain3; + // Design principles: // - D3D12 structs are zero-initialized and fields not requiring a non-zero value are omitted (except in cases where expresivity reasons apply). class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver { @@ -123,9 +126,8 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver { RenderingContextDriverD3D12 *context_driver = nullptr; RenderingContextDriver::Device context_device; - ComPtr adapter; - DXGI_ADAPTER_DESC adapter_desc; - ComPtr device; + Microsoft::WRL::ComPtr adapter; + Microsoft::WRL::ComPtr device; DeviceLimits device_limits; RDD::Capabilities device_capabilities; uint32_t feature_level = 0; // Major * 10 + minor. @@ -144,7 +146,7 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver { class CPUDescriptorsHeapPool; struct CPUDescriptorsHeapHandle { - ComPtr heap; + Microsoft::WRL::ComPtr heap; CPUDescriptorsHeapPool *pool = nullptr; uint32_t offset = 0; uint32_t base_offset = 0; @@ -158,7 +160,7 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver { Mutex mutex; struct FreeBlockInfo { - ComPtr heap; + Microsoft::WRL::ComPtr heap; uint32_t global_offset = 0; // Global offset in an address space shared by all the heaps. uint32_t base_offset = 0; // The offset inside the space of this heap. uint32_t size = 0; @@ -230,7 +232,7 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver { class GPUDescriptorsHeap { D3D12_DESCRIPTOR_HEAP_DESC desc = {}; - ComPtr heap; + Microsoft::WRL::ComPtr heap; uint32_t handle_size = 0; public: @@ -243,9 +245,9 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver { CPUDescriptorsHeapPools cpu_descriptor_pool; struct { - ComPtr draw; - ComPtr draw_indexed; - ComPtr dispatch; + Microsoft::WRL::ComPtr draw; + Microsoft::WRL::ComPtr draw_indexed; + Microsoft::WRL::ComPtr dispatch; } indirect_cmd_signatures; static void STDMETHODCALLTYPE _debug_message_func(D3D12_MESSAGE_CATEGORY p_category, D3D12_MESSAGE_SEVERITY p_severity, D3D12_MESSAGE_ID p_id, LPCSTR p_description, void *p_context); @@ -265,7 +267,7 @@ private: /**** MEMORY ****/ /****************/ - ComPtr allocator; + Microsoft::WRL::ComPtr allocator; /******************/ /**** RESOURCE ****/ @@ -280,8 +282,8 @@ private: ID3D12Resource *resource = nullptr; // Non-null even if not owned. struct { - ComPtr resource; - ComPtr allocation; + Microsoft::WRL::ComPtr resource; + Microsoft::WRL::ComPtr allocation; States states; } owner_info; // All empty if the resource is not owned. States *states_ptr = nullptr; // Own or from another if it doesn't own the D3D12 resource. @@ -441,7 +443,7 @@ private: /****************/ struct FenceInfo { - ComPtr d3d_fence = nullptr; + Microsoft::WRL::ComPtr d3d_fence = nullptr; HANDLE event_handle = nullptr; UINT64 fence_value = 0; }; @@ -457,7 +459,7 @@ private: /********************/ struct SemaphoreInfo { - ComPtr d3d_fence = nullptr; + Microsoft::WRL::ComPtr d3d_fence = nullptr; UINT64 fence_value = 0; }; @@ -476,7 +478,7 @@ private: // ----- QUEUE ----- struct CommandQueueInfo { - ComPtr d3d_queue; + Microsoft::WRL::ComPtr d3d_queue; }; public: @@ -533,8 +535,8 @@ private: // Store a self list reference to be used by the command pool. SelfList command_buffer_info_elem{ this }; - ComPtr cmd_allocator; - ComPtr cmd_list; + Microsoft::WRL::ComPtr cmd_allocator; + Microsoft::WRL::ComPtr cmd_list; ID3D12PipelineState *graphics_pso = nullptr; ID3D12PipelineState *compute_pso = nullptr; @@ -564,7 +566,7 @@ private: /********************/ struct SwapChain { - ComPtr d3d_swap_chain; + Microsoft::WRL::ComPtr d3d_swap_chain; RenderingContextDriver::SurfaceID surface = RenderingContextDriver::SurfaceID(); UINT present_flags = 0; UINT sync_interval = 1; @@ -677,8 +679,8 @@ private: HashMap> stages_bytecode; - ComPtr root_signature; - ComPtr root_signature_deserializer; + Microsoft::WRL::ComPtr root_signature; + Microsoft::WRL::ComPtr root_signature_deserializer; const D3D12_ROOT_SIGNATURE_DESC *root_signature_desc = nullptr; // Owned by the deserializer. uint32_t root_signature_crc = 0; }; @@ -787,7 +789,7 @@ public: }; struct PipelineInfo { - ComPtr pso; + Microsoft::WRL::ComPtr pso; const ShaderInfo *shader_info = nullptr; RenderPipelineInfo render_info; }; @@ -907,9 +909,9 @@ public: private: struct TimestampQueryPoolInfo { - ComPtr query_heap; + Microsoft::WRL::ComPtr query_heap; uint32_t query_count = 0; - ComPtr results_buffer_allocation; + Microsoft::WRL::ComPtr results_buffer_allocation; }; public: diff --git a/drivers/d3d12/rendering_shader_container_d3d12.cpp b/drivers/d3d12/rendering_shader_container_d3d12.cpp index c1acc64cbed..75c4fe2d62b 100644 --- a/drivers/d3d12/rendering_shader_container_d3d12.cpp +++ b/drivers/d3d12/rendering_shader_container_d3d12.cpp @@ -36,11 +36,6 @@ #include -#ifndef _MSC_VER -// Match current version used by MinGW, MSVC and Direct3D 12 headers use 500. -#define __REQUIRED_RPCNDR_H_VERSION__ 475 -#endif - GODOT_GCC_WARNING_PUSH GODOT_GCC_WARNING_IGNORE("-Wimplicit-fallthrough") GODOT_GCC_WARNING_IGNORE("-Wlogical-not-parentheses") @@ -59,10 +54,10 @@ GODOT_MSVC_WARNING_PUSH GODOT_MSVC_WARNING_IGNORE(4200) // "nonstandard extension used: zero-sized array in struct/union". GODOT_MSVC_WARNING_IGNORE(4806) // "'&': unsafe operation: no value of type 'bool' promoted to type 'uint32_t' can equal the given constant". -#include #include +#include #define D3D12MA_D3D12_HEADERS_ALREADY_INCLUDED -#include +#include #include diff --git a/modules/openxr/extensions/platform/openxr_d3d12_extension.h b/modules/openxr/extensions/platform/openxr_d3d12_extension.h index c9f95966ab9..a0365b5efe7 100644 --- a/modules/openxr/extensions/platform/openxr_d3d12_extension.h +++ b/modules/openxr/extensions/platform/openxr_d3d12_extension.h @@ -77,8 +77,8 @@ private: EXT_PROTO_XRRESULT_FUNC3(xrGetD3D12GraphicsRequirementsKHR, (XrInstance), p_instance, (XrSystemId), p_system_id, (XrGraphicsRequirementsD3D12KHR *), p_graphics_requirements) EXT_PROTO_XRRESULT_FUNC4(xrEnumerateSwapchainImages, (XrSwapchain), p_swapchain, (uint32_t), p_image_capacity_input, (uint32_t *), p_image_count_output, (XrSwapchainImageBaseHeader *), p_images) - ComPtr graphics_device; - ComPtr command_queue; + Microsoft::WRL::ComPtr graphics_device; + Microsoft::WRL::ComPtr command_queue; }; #endif // D3D12_ENABLED