SCons: Cleanup hardcoded D3D12 driver workarounds

This commit is contained in:
Thaddeus Crews 2025-10-18 13:38:19 -05:00
parent 5f12ada7a4
commit b93d82a2b3
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
8 changed files with 83 additions and 156 deletions

View file

@ -7,49 +7,25 @@ from pathlib import Path
import methods import methods
Import("env") Import("env")
env_d3d12_rdd = env.Clone() 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. # Agility SDK.
if env["agility_sdk_path"] != "" and os.path.exists(env["agility_sdk_path"]): if env["agility_sdk_path"] != "" and os.path.exists(env["agility_sdk_path"]):
env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_ENABLED"]) env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_ENABLED"])
if env["agility_sdk_multiarch"]: if env["agility_sdk_multiarch"]:
env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_MULTIARCH_ENABLED"]) env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_MULTIARCH_ENABLED"])
# PIX. # PIX.
if env["use_pix"]: if env["use_pix"]:
env_d3d12_rdd.Append(CPPDEFINES=["PIX_ENABLED"]) env_d3d12_rdd.Append(CPPDEFINES=["PIX_ENABLED"])
env_d3d12_rdd.Append(CPPPATH=[env["pix_path"] + "/Include"]) env_d3d12_rdd.Append(CPPPATH=[env["pix_path"] + "/Include"])
# Direct composition. # Direct composition.
if "dcomp" in env.get("supported", []): if "dcomp" in env.get("supported", []):
env_d3d12_rdd.Append(CPPDEFINES=["DCOMP_ENABLED"]) env_d3d12_rdd.Append(CPPDEFINES=["DCOMP_ENABLED"])
env.Append(CPPDEFINES=["DCOMP_ENABLED"]) # Used in header included in platform. env.Append(CPPDEFINES=["DCOMP_ENABLED"]) # Used in header included in platform.
# Mesa (SPIR-V to DXIL functionality). # Mesa (SPIR-V to DXIL functionality).
mesa_libs = env["mesa_libs"] mesa_libs = env["mesa_libs"]
if env.msvc and os.path.exists(env["mesa_libs"] + "-" + env["arch"] + "-msvc"): if env.msvc and os.path.exists(env["mesa_libs"] + "-" + env["arch"] + "-msvc"):
mesa_libs = 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\\"'), ("PACKAGE_BUGREPORT", '\\"https://gitlab.freedesktop.org/mesa/mesa/-/issues\\"'),
"PIPE_SUBSYSTEM_WINDOWS_USER", "PIPE_SUBSYSTEM_WINDOWS_USER",
("_Static_assert", "static_assert"), ("_Static_assert", "static_assert"),
"HAVE_STRUCT_TIMESPEC",
] ]
if env.msvc: if env.msvc:
@ -148,30 +125,39 @@ if env.msvc:
"_SCL_SECURE_NO_WARNINGS", "_SCL_SECURE_NO_WARNINGS",
"_SCL_SECURE_NO_DEPRECATE", "_SCL_SECURE_NO_DEPRECATE",
"_ALLOW_KEYWORD_MACROS", "_ALLOW_KEYWORD_MACROS",
("_HAS_EXCEPTIONS", 0),
"NOMINMAX", "NOMINMAX",
"HAVE_STRUCT_TIMESPEC",
] ]
else: else:
extra_defines += [ 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: if methods.using_gcc(env) and methods.get_compiler_version(env)["major"] < 13:
# `region` & `endregion` not recognized as valid pragmas. # `region` & `endregion` not recognized as valid pragmas.
env_d3d12_rdd.Append(CCFLAGS=["-Wno-unknown-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. # This is needed since rendering_device_d3d12.cpp needs to include some Mesa internals.
env_d3d12_rdd.Prepend(CPPPATH=mesa_private_inc_paths) 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. # 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) 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 env.drivers_sources += thirdparty_obj
# Godot source files. # Godot source files.
driver_obj = [] driver_obj = []

View file

@ -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 <D3D12MemAlloc.cpp>
GODOT_GCC_WARNING_POP
GODOT_CLANG_WARNING_POP
GODOT_MSVC_WARNING_POP

View file

@ -51,6 +51,7 @@ GODOT_CLANG_WARNING_IGNORE("-Wstring-plus-int")
GODOT_CLANG_WARNING_IGNORE("-Wswitch") GODOT_CLANG_WARNING_IGNORE("-Wswitch")
#include <dxcapi.h> #include <dxcapi.h>
#include <dxgi1_6.h>
GODOT_GCC_WARNING_POP GODOT_GCC_WARNING_POP
GODOT_CLANG_WARNING_POP GODOT_CLANG_WARNING_POP
@ -58,9 +59,11 @@ GODOT_CLANG_WARNING_POP
#if !defined(_MSC_VER) #if !defined(_MSC_VER)
#include <guiddef.h> #include <guiddef.h>
#include <dxguids.h> #include <thirdparty/directx_headers/include/dxguids/dxguids.h>
#endif #endif
using Microsoft::WRL::ComPtr;
// Note: symbols are not available in MinGW and old MSVC import libraries. // 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 // 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 } }; 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 #define _MSC_VER 1800
#endif #endif
#define USE_PIX #define USE_PIX
#include "WinPixEventRuntime/pix3.h" #include <WinPixEventRuntime/pix3.h>
#if defined(__GNUC__) #if defined(__GNUC__)
#undef _MSC_VER #undef _MSC_VER
#endif #endif

View file

@ -37,6 +37,11 @@
#include "servers/display/display_server.h" #include "servers/display/display_server.h"
#include "servers/rendering/rendering_context_driver.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_PUSH
GODOT_GCC_WARNING_IGNORE("-Wimplicit-fallthrough") GODOT_GCC_WARNING_IGNORE("-Wimplicit-fallthrough")
GODOT_GCC_WARNING_IGNORE("-Wmissing-field-initializers") 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("-Wstring-plus-int")
GODOT_CLANG_WARNING_IGNORE("-Wswitch") GODOT_CLANG_WARNING_IGNORE("-Wswitch")
#include <thirdparty/directx_headers/include/directx/d3dx12.h>
GODOT_GCC_WARNING_POP
GODOT_CLANG_WARNING_POP
#if defined(AS) #if defined(AS)
#undef AS #undef AS
#endif #endif
@ -58,21 +68,13 @@ GODOT_CLANG_WARNING_IGNORE("-Wswitch")
#include <dcomp.h> #include <dcomp.h>
#endif #endif
#include <d3dx12.h>
#include <dxgi1_6.h>
#include <wrl/client.h> #include <wrl/client.h>
GODOT_GCC_WARNING_POP
GODOT_CLANG_WARNING_POP
using Microsoft::WRL::ComPtr;
#define ARRAY_SIZE(a) std_size(a) #define ARRAY_SIZE(a) std_size(a)
class RenderingContextDriverD3D12 : public RenderingContextDriver { class RenderingContextDriverD3D12 : public RenderingContextDriver {
ComPtr<ID3D12DeviceFactory> device_factory; Microsoft::WRL::ComPtr<ID3D12DeviceFactory> device_factory;
ComPtr<IDXGIFactory2> dxgi_factory; Microsoft::WRL::ComPtr<IDXGIFactory2> dxgi_factory;
TightLocalVector<Device> driver_devices; TightLocalVector<Device> driver_devices;
bool tearing_supported = false; bool tearing_supported = false;
@ -111,9 +113,9 @@ public:
DisplayServer::VSyncMode vsync_mode = DisplayServer::VSYNC_ENABLED; DisplayServer::VSyncMode vsync_mode = DisplayServer::VSYNC_ENABLED;
bool needs_resize = false; bool needs_resize = false;
#ifdef DCOMP_ENABLED #ifdef DCOMP_ENABLED
ComPtr<IDCompositionDevice> composition_device; Microsoft::WRL::ComPtr<IDCompositionDevice> composition_device;
ComPtr<IDCompositionTarget> composition_target; Microsoft::WRL::ComPtr<IDCompositionTarget> composition_target;
ComPtr<IDCompositionVisual> composition_visual; Microsoft::WRL::ComPtr<IDCompositionVisual> composition_visual;
#endif #endif
}; };

View file

@ -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(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". GODOT_MSVC_WARNING_IGNORE(4806) // "'&': unsafe operation: no value of type 'bool' promoted to type 'uint32_t' can equal the given constant".
#include <dxgi1_6.h>
#define D3D12MA_D3D12_HEADERS_ALREADY_INCLUDED
#include <thirdparty/d3d12ma/D3D12MemAlloc.h>
#include <nir_spirv.h> #include <nir_spirv.h>
#include <nir_to_dxil.h> #include <nir_to_dxil.h>
#include <spirv_to_dxil.h> #include <spirv_to_dxil.h>
@ -72,9 +76,11 @@ GODOT_MSVC_WARNING_POP
#if !defined(_MSC_VER) #if !defined(_MSC_VER)
#include <guiddef.h> #include <guiddef.h>
#include <dxguids.h> #include <thirdparty/directx_headers/include/dxguids/dxguids.h>
#endif #endif
using Microsoft::WRL::ComPtr;
// Mesa may define this. // Mesa may define this.
#ifdef UNUSED #ifdef UNUSED
#undef UNUSED #undef UNUSED
@ -85,7 +91,7 @@ GODOT_MSVC_WARNING_POP
#define _MSC_VER 1800 #define _MSC_VER 1800
#endif #endif
#define USE_PIX #define USE_PIX
#include "WinPixEventRuntime/pix3.h" #include <WinPixEventRuntime/pix3.h>
#if defined(__GNUC__) #if defined(__GNUC__)
#undef _MSC_VER #undef _MSC_VER
#endif #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)); adapter.Attach(context_driver->create_adapter(p_device_index));
ERR_FAIL_NULL_V(adapter, ERR_CANT_CREATE); ERR_FAIL_NULL_V(adapter, ERR_CANT_CREATE);
DXGI_ADAPTER_DESC adapter_desc;
HRESULT res = adapter->GetDesc(&adapter_desc); HRESULT res = adapter->GetDesc(&adapter_desc);
ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE); ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE);

View file

@ -37,10 +37,10 @@
#include "rendering_shader_container_d3d12.h" #include "rendering_shader_container_d3d12.h"
#include "servers/rendering/rendering_device_driver.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. // Match current version used by MinGW, MSVC and Direct3D 12 headers use 500.
#define __REQUIRED_RPCNDR_H_VERSION__ 475 #define __REQUIRED_RPCNDR_H_VERSION__ 475
#endif #endif // !defined(_MSC_VER) && !defined(__REQUIRED_RPCNDR_H_VERSION__)
GODOT_GCC_WARNING_PUSH GODOT_GCC_WARNING_PUSH
GODOT_GCC_WARNING_IGNORE("-Wimplicit-fallthrough") 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("-Wstring-plus-int")
GODOT_CLANG_WARNING_IGNORE("-Wswitch") GODOT_CLANG_WARNING_IGNORE("-Wswitch")
#include <d3dx12.h> #include <thirdparty/directx_headers/include/directx/d3dx12.h>
#include <dxgi1_6.h>
#define D3D12MA_D3D12_HEADERS_ALREADY_INCLUDED
#include <D3D12MemAlloc.h>
#include <wrl/client.h>
GODOT_GCC_WARNING_POP GODOT_GCC_WARNING_POP
GODOT_CLANG_WARNING_POP GODOT_CLANG_WARNING_POP
using Microsoft::WRL::ComPtr; #include <wrl/client.h>
#ifdef DEV_ENABLED #ifdef DEV_ENABLED
#define CUSTOM_INFO_QUEUE_ENABLED 0 #define CUSTOM_INFO_QUEUE_ENABLED 0
@ -73,6 +68,14 @@ using Microsoft::WRL::ComPtr;
class RenderingContextDriverD3D12; class RenderingContextDriverD3D12;
namespace D3D12MA {
class Allocation;
class Allocator;
}; // namespace D3D12MA
struct IDXGIAdapter;
struct IDXGISwapChain3;
// Design principles: // Design principles:
// - D3D12 structs are zero-initialized and fields not requiring a non-zero value are omitted (except in cases where expresivity reasons apply). // - 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 { class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver {
@ -123,9 +126,8 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver {
RenderingContextDriverD3D12 *context_driver = nullptr; RenderingContextDriverD3D12 *context_driver = nullptr;
RenderingContextDriver::Device context_device; RenderingContextDriver::Device context_device;
ComPtr<IDXGIAdapter> adapter; Microsoft::WRL::ComPtr<IDXGIAdapter> adapter;
DXGI_ADAPTER_DESC adapter_desc; Microsoft::WRL::ComPtr<ID3D12Device> device;
ComPtr<ID3D12Device> device;
DeviceLimits device_limits; DeviceLimits device_limits;
RDD::Capabilities device_capabilities; RDD::Capabilities device_capabilities;
uint32_t feature_level = 0; // Major * 10 + minor. uint32_t feature_level = 0; // Major * 10 + minor.
@ -144,7 +146,7 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver {
class CPUDescriptorsHeapPool; class CPUDescriptorsHeapPool;
struct CPUDescriptorsHeapHandle { struct CPUDescriptorsHeapHandle {
ComPtr<ID3D12DescriptorHeap> heap; Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> heap;
CPUDescriptorsHeapPool *pool = nullptr; CPUDescriptorsHeapPool *pool = nullptr;
uint32_t offset = 0; uint32_t offset = 0;
uint32_t base_offset = 0; uint32_t base_offset = 0;
@ -158,7 +160,7 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver {
Mutex mutex; Mutex mutex;
struct FreeBlockInfo { struct FreeBlockInfo {
ComPtr<ID3D12DescriptorHeap> heap; Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> heap;
uint32_t global_offset = 0; // Global offset in an address space shared by all the heaps. 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 base_offset = 0; // The offset inside the space of this heap.
uint32_t size = 0; uint32_t size = 0;
@ -230,7 +232,7 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver {
class GPUDescriptorsHeap { class GPUDescriptorsHeap {
D3D12_DESCRIPTOR_HEAP_DESC desc = {}; D3D12_DESCRIPTOR_HEAP_DESC desc = {};
ComPtr<ID3D12DescriptorHeap> heap; Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> heap;
uint32_t handle_size = 0; uint32_t handle_size = 0;
public: public:
@ -243,9 +245,9 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver {
CPUDescriptorsHeapPools cpu_descriptor_pool; CPUDescriptorsHeapPools cpu_descriptor_pool;
struct { struct {
ComPtr<ID3D12CommandSignature> draw; Microsoft::WRL::ComPtr<ID3D12CommandSignature> draw;
ComPtr<ID3D12CommandSignature> draw_indexed; Microsoft::WRL::ComPtr<ID3D12CommandSignature> draw_indexed;
ComPtr<ID3D12CommandSignature> dispatch; Microsoft::WRL::ComPtr<ID3D12CommandSignature> dispatch;
} indirect_cmd_signatures; } 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); 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 ****/ /**** MEMORY ****/
/****************/ /****************/
ComPtr<D3D12MA::Allocator> allocator; Microsoft::WRL::ComPtr<D3D12MA::Allocator> allocator;
/******************/ /******************/
/**** RESOURCE ****/ /**** RESOURCE ****/
@ -280,8 +282,8 @@ private:
ID3D12Resource *resource = nullptr; // Non-null even if not owned. ID3D12Resource *resource = nullptr; // Non-null even if not owned.
struct { struct {
ComPtr<ID3D12Resource> resource; Microsoft::WRL::ComPtr<ID3D12Resource> resource;
ComPtr<D3D12MA::Allocation> allocation; Microsoft::WRL::ComPtr<D3D12MA::Allocation> allocation;
States states; States states;
} owner_info; // All empty if the resource is not owned. } 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. States *states_ptr = nullptr; // Own or from another if it doesn't own the D3D12 resource.
@ -441,7 +443,7 @@ private:
/****************/ /****************/
struct FenceInfo { struct FenceInfo {
ComPtr<ID3D12Fence> d3d_fence = nullptr; Microsoft::WRL::ComPtr<ID3D12Fence> d3d_fence = nullptr;
HANDLE event_handle = nullptr; HANDLE event_handle = nullptr;
UINT64 fence_value = 0; UINT64 fence_value = 0;
}; };
@ -457,7 +459,7 @@ private:
/********************/ /********************/
struct SemaphoreInfo { struct SemaphoreInfo {
ComPtr<ID3D12Fence> d3d_fence = nullptr; Microsoft::WRL::ComPtr<ID3D12Fence> d3d_fence = nullptr;
UINT64 fence_value = 0; UINT64 fence_value = 0;
}; };
@ -476,7 +478,7 @@ private:
// ----- QUEUE ----- // ----- QUEUE -----
struct CommandQueueInfo { struct CommandQueueInfo {
ComPtr<ID3D12CommandQueue> d3d_queue; Microsoft::WRL::ComPtr<ID3D12CommandQueue> d3d_queue;
}; };
public: public:
@ -533,8 +535,8 @@ private:
// Store a self list reference to be used by the command pool. // Store a self list reference to be used by the command pool.
SelfList<CommandBufferInfo> command_buffer_info_elem{ this }; SelfList<CommandBufferInfo> command_buffer_info_elem{ this };
ComPtr<ID3D12CommandAllocator> cmd_allocator; Microsoft::WRL::ComPtr<ID3D12CommandAllocator> cmd_allocator;
ComPtr<ID3D12GraphicsCommandList> cmd_list; Microsoft::WRL::ComPtr<ID3D12GraphicsCommandList> cmd_list;
ID3D12PipelineState *graphics_pso = nullptr; ID3D12PipelineState *graphics_pso = nullptr;
ID3D12PipelineState *compute_pso = nullptr; ID3D12PipelineState *compute_pso = nullptr;
@ -564,7 +566,7 @@ private:
/********************/ /********************/
struct SwapChain { struct SwapChain {
ComPtr<IDXGISwapChain3> d3d_swap_chain; Microsoft::WRL::ComPtr<IDXGISwapChain3> d3d_swap_chain;
RenderingContextDriver::SurfaceID surface = RenderingContextDriver::SurfaceID(); RenderingContextDriver::SurfaceID surface = RenderingContextDriver::SurfaceID();
UINT present_flags = 0; UINT present_flags = 0;
UINT sync_interval = 1; UINT sync_interval = 1;
@ -677,8 +679,8 @@ private:
HashMap<ShaderStage, Vector<uint8_t>> stages_bytecode; HashMap<ShaderStage, Vector<uint8_t>> stages_bytecode;
ComPtr<ID3D12RootSignature> root_signature; Microsoft::WRL::ComPtr<ID3D12RootSignature> root_signature;
ComPtr<ID3D12RootSignatureDeserializer> root_signature_deserializer; Microsoft::WRL::ComPtr<ID3D12RootSignatureDeserializer> root_signature_deserializer;
const D3D12_ROOT_SIGNATURE_DESC *root_signature_desc = nullptr; // Owned by the deserializer. const D3D12_ROOT_SIGNATURE_DESC *root_signature_desc = nullptr; // Owned by the deserializer.
uint32_t root_signature_crc = 0; uint32_t root_signature_crc = 0;
}; };
@ -787,7 +789,7 @@ public:
}; };
struct PipelineInfo { struct PipelineInfo {
ComPtr<ID3D12PipelineState> pso; Microsoft::WRL::ComPtr<ID3D12PipelineState> pso;
const ShaderInfo *shader_info = nullptr; const ShaderInfo *shader_info = nullptr;
RenderPipelineInfo render_info; RenderPipelineInfo render_info;
}; };
@ -907,9 +909,9 @@ public:
private: private:
struct TimestampQueryPoolInfo { struct TimestampQueryPoolInfo {
ComPtr<ID3D12QueryHeap> query_heap; Microsoft::WRL::ComPtr<ID3D12QueryHeap> query_heap;
uint32_t query_count = 0; uint32_t query_count = 0;
ComPtr<D3D12MA::Allocation> results_buffer_allocation; Microsoft::WRL::ComPtr<D3D12MA::Allocation> results_buffer_allocation;
}; };
public: public:

View file

@ -36,11 +36,6 @@
#include <zlib.h> #include <zlib.h>
#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_PUSH
GODOT_GCC_WARNING_IGNORE("-Wimplicit-fallthrough") GODOT_GCC_WARNING_IGNORE("-Wimplicit-fallthrough")
GODOT_GCC_WARNING_IGNORE("-Wlogical-not-parentheses") 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(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". GODOT_MSVC_WARNING_IGNORE(4806) // "'&': unsafe operation: no value of type 'bool' promoted to type 'uint32_t' can equal the given constant".
#include <d3dx12.h>
#include <dxgi1_6.h> #include <dxgi1_6.h>
#include <thirdparty/directx_headers/include/directx/d3dx12.h>
#define D3D12MA_D3D12_HEADERS_ALREADY_INCLUDED #define D3D12MA_D3D12_HEADERS_ALREADY_INCLUDED
#include <D3D12MemAlloc.h> #include <thirdparty/d3d12ma/D3D12MemAlloc.h>
#include <wrl/client.h> #include <wrl/client.h>

View file

@ -77,8 +77,8 @@ private:
EXT_PROTO_XRRESULT_FUNC3(xrGetD3D12GraphicsRequirementsKHR, (XrInstance), p_instance, (XrSystemId), p_system_id, (XrGraphicsRequirementsD3D12KHR *), p_graphics_requirements) 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) EXT_PROTO_XRRESULT_FUNC4(xrEnumerateSwapchainImages, (XrSwapchain), p_swapchain, (uint32_t), p_image_capacity_input, (uint32_t *), p_image_count_output, (XrSwapchainImageBaseHeader *), p_images)
ComPtr<ID3D12Device> graphics_device; Microsoft::WRL::ComPtr<ID3D12Device> graphics_device;
ComPtr<ID3D12CommandQueue> command_queue; Microsoft::WRL::ComPtr<ID3D12CommandQueue> command_queue;
}; };
#endif // D3D12_ENABLED #endif // D3D12_ENABLED