Skip to content

Commit 3a8524d

Browse files
authored
Merge pull request #83452 from RandomShaper/rd_common
Split `RenderingDevice` into API-agnostic and `RenderingDeviceDriver` parts
2 parents c28a091 + 12a519b commit 3a8524d

File tree

83 files changed

+37356
-31621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+37356
-31621
lines changed

core/config/project_settings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const PackedStringArray ProjectSettings::_get_supported_features() {
9595
features.append(VERSION_FULL_CONFIG);
9696
features.append(VERSION_FULL_BUILD);
9797

98-
#if defined(VULKAN_ENABLED) || defined(D3D12_ENABLED)
98+
#ifdef RD_ENABLED
9999
features.append("Forward Plus");
100100
features.append("Mobile");
101101
#endif
@@ -1476,6 +1476,7 @@ ProjectSettings::ProjectSettings() {
14761476
GLOBAL_DEF("rendering/rendering_device/staging_buffer/texture_upload_region_size_px", 64);
14771477
GLOBAL_DEF("rendering/rendering_device/pipeline_cache/save_chunk_size_mb", 3.0);
14781478
GLOBAL_DEF("rendering/rendering_device/vulkan/max_descriptors_per_pool", 64);
1479+
14791480
GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_resource_descriptors_per_frame", 16384);
14801481
custom_prop_info["rendering/rendering_device/d3d12/max_resource_descriptors_per_frame"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_resource_descriptors_per_frame", PROPERTY_HINT_RANGE, "512,262144");
14811482
GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_sampler_descriptors_per_frame", 1024);

core/templates/paged_allocator.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class PagedAllocator {
5858
};
5959

6060
template <class... Args>
61-
T *alloc(const Args &&...p_args) {
61+
T *alloc(Args &&...p_args) {
6262
if (thread_safe) {
6363
spin_lock.lock();
6464
}
@@ -99,6 +99,10 @@ class PagedAllocator {
9999
}
100100
}
101101

102+
template <class... Args>
103+
T *new_allocation(Args &&...p_args) { return alloc(p_args...); }
104+
void delete_allocation(T *p_mem) { free(p_mem); }
105+
102106
private:
103107
void _reset(bool p_allow_unfreed) {
104108
if (!p_allow_unfreed || !std::is_trivially_destructible<T>::value) {

core/templates/rb_map.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,16 @@ class RBMap {
111111
return *this;
112112
}
113113

114-
_FORCE_INLINE_ bool operator==(const Iterator &b) const { return E == b.E; }
115-
_FORCE_INLINE_ bool operator!=(const Iterator &b) const { return E != b.E; }
114+
_FORCE_INLINE_ bool operator==(const Iterator &p_it) const { return E == p_it.E; }
115+
_FORCE_INLINE_ bool operator!=(const Iterator &p_it) const { return E != p_it.E; }
116116
explicit operator bool() const {
117117
return E != nullptr;
118118
}
119+
120+
Iterator &operator=(const Iterator &p_it) {
121+
E = p_it.E;
122+
return *this;
123+
}
119124
Iterator(Element *p_E) { E = p_E; }
120125
Iterator() {}
121126
Iterator(const Iterator &p_it) { E = p_it.E; }
@@ -138,11 +143,16 @@ class RBMap {
138143
return *this;
139144
}
140145

141-
_FORCE_INLINE_ bool operator==(const ConstIterator &b) const { return E == b.E; }
142-
_FORCE_INLINE_ bool operator!=(const ConstIterator &b) const { return E != b.E; }
146+
_FORCE_INLINE_ bool operator==(const ConstIterator &p_it) const { return E == p_it.E; }
147+
_FORCE_INLINE_ bool operator!=(const ConstIterator &p_it) const { return E != p_it.E; }
143148
explicit operator bool() const {
144149
return E != nullptr;
145150
}
151+
152+
ConstIterator &operator=(const ConstIterator &p_it) {
153+
E = p_it.E;
154+
return *this;
155+
}
146156
ConstIterator(const Element *p_E) { E = p_E; }
147157
ConstIterator() {}
148158
ConstIterator(const ConstIterator &p_it) { E = p_it.E; }

core/typedefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#undef Error
9393
#undef OK
9494
#undef CONNECT_DEFERRED // override from Windows SDK, clashes with Object enum
95+
#undef MemoryBarrier
9596
#endif
9697

9798
// Make room for our constexpr's below by overriding potential system-specific macros.

core/variant/type_info.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,17 @@ class BitField {
287287
int64_t value = 0;
288288

289289
public:
290-
_FORCE_INLINE_ void set_flag(T p_flag) { value |= (int64_t)p_flag; }
290+
_FORCE_INLINE_ BitField<T> &set_flag(T p_flag) {
291+
value |= (int64_t)p_flag;
292+
return *this;
293+
}
291294
_FORCE_INLINE_ bool has_flag(T p_flag) const { return value & (int64_t)p_flag; }
292295
_FORCE_INLINE_ bool is_empty() const { return value == 0; }
293296
_FORCE_INLINE_ void clear_flag(T p_flag) { value &= ~(int64_t)p_flag; }
294297
_FORCE_INLINE_ void clear() { value = 0; }
295-
_FORCE_INLINE_ BitField() = default;
296-
_FORCE_INLINE_ BitField(int64_t p_value) { value = p_value; }
297-
_FORCE_INLINE_ BitField(T p_value) { value = (int64_t)p_value; }
298+
_FORCE_INLINE_ constexpr BitField() = default;
299+
_FORCE_INLINE_ constexpr BitField(int64_t p_value) { value = p_value; }
300+
_FORCE_INLINE_ constexpr BitField(T p_value) { value = (int64_t)p_value; }
298301
_FORCE_INLINE_ operator int64_t() const { return value; }
299302
_FORCE_INLINE_ operator Variant() const { return value; }
300303
};

doc/classes/RenderingDevice.xml

Lines changed: 75 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -796,12 +796,13 @@
796796
Returns the data format used to create this texture.
797797
</description>
798798
</method>
799-
<method name="texture_get_native_handle">
799+
<method name="texture_get_native_handle" is_deprecated="true">
800800
<return type="int" />
801801
<param index="0" name="texture" type="RID" />
802802
<description>
803803
Returns the internal graphics handle for this texture object. For use when communicating with third-party APIs mostly with GDExtension.
804804
[b]Note:[/b] This function returns a [code]uint64_t[/code] which internally maps to a [code]GLuint[/code] (OpenGL) or [code]VkImage[/code] (Vulkan).
805+
[i]Deprecated.[/i] Use [method get_driver_resource] with [constant DRIVER_RESOURCE_TEXTURE] instead.
805806
</description>
806807
</method>
807808
<method name="texture_is_format_supported_for_usage" qualifiers="const">
@@ -928,44 +929,91 @@
928929
<constant name="DEVICE_TYPE_MAX" value="5" enum="DeviceType">
929930
Represents the size of the [enum DeviceType] enum.
930931
</constant>
931-
<constant name="DRIVER_RESOURCE_VULKAN_DEVICE" value="0" enum="DriverResource">
932-
Vulkan device driver resource. This is a "global" resource and ignores the RID passed in
932+
<constant name="DRIVER_RESOURCE_LOGICAL_DEVICE" value="0" enum="DriverResource">
933+
Specific device object based on a physical device.
934+
- Vulkan: Vulkan device driver resource ([code]VkDevice[/code]). ([code]rid[/code] argument doesn't apply.)
933935
</constant>
934-
<constant name="DRIVER_RESOURCE_VULKAN_PHYSICAL_DEVICE" value="1" enum="DriverResource">
935-
Physical device (graphics card) driver resource.
936+
<constant name="DRIVER_RESOURCE_PHYSICAL_DEVICE" value="1" enum="DriverResource">
937+
Physical device the specific logical device is based on.
938+
- Vulkan: [code]VkDevice[/code]. ([code]rid[/code] argument doesn't apply.)
936939
</constant>
937-
<constant name="DRIVER_RESOURCE_VULKAN_INSTANCE" value="2" enum="DriverResource">
938-
Vulkan instance driver resource.
940+
<constant name="DRIVER_RESOURCE_TOPMOST_OBJECT" value="2" enum="DriverResource">
941+
Top-most graphics API entry object.
942+
- Vulkan: [code]VkInstance[/code]. ([code]rid[/code] argument doesn't apply.)
939943
</constant>
940-
<constant name="DRIVER_RESOURCE_VULKAN_QUEUE" value="3" enum="DriverResource">
941-
Vulkan queue driver resource.
944+
<constant name="DRIVER_RESOURCE_COMMAND_QUEUE" value="3" enum="DriverResource">
945+
The main graphics-compute command queue.
946+
- Vulkan: [code]VkQueue[/code]. ([code]rid[/code] argument doesn't apply.)
942947
</constant>
943-
<constant name="DRIVER_RESOURCE_VULKAN_QUEUE_FAMILY_INDEX" value="4" enum="DriverResource">
944-
Vulkan queue family index driver resource.
948+
<constant name="DRIVER_RESOURCE_QUEUE_FAMILY" value="4" enum="DriverResource">
949+
The specific family the main queue belongs to.
950+
- Vulkan: the queue family index, an [code]uint32_t[/code]. ([code]rid[/code] argument doesn't apply.)
945951
</constant>
946-
<constant name="DRIVER_RESOURCE_VULKAN_IMAGE" value="5" enum="DriverResource">
947-
Vulkan image driver resource.
952+
<constant name="DRIVER_RESOURCE_TEXTURE" value="5" enum="DriverResource">
953+
- Vulkan: [code]VkImage[/code].
948954
</constant>
949-
<constant name="DRIVER_RESOURCE_VULKAN_IMAGE_VIEW" value="6" enum="DriverResource">
950-
Vulkan image view driver resource.
955+
<constant name="DRIVER_RESOURCE_TEXTURE_VIEW" value="6" enum="DriverResource">
956+
The view of an owned or shared texture.
957+
- Vulkan: [code]VkImageView[/code].
951958
</constant>
952-
<constant name="DRIVER_RESOURCE_VULKAN_IMAGE_NATIVE_TEXTURE_FORMAT" value="7" enum="DriverResource">
953-
Vulkan image native texture format driver resource.
959+
<constant name="DRIVER_RESOURCE_TEXTURE_DATA_FORMAT" value="7" enum="DriverResource">
960+
The native id of the data format of the texture.
961+
- Vulkan: [code]VkFormat[/code].
954962
</constant>
955-
<constant name="DRIVER_RESOURCE_VULKAN_SAMPLER" value="8" enum="DriverResource">
956-
Vulkan sampler driver resource.
963+
<constant name="DRIVER_RESOURCE_SAMPLER" value="8" enum="DriverResource">
964+
- Vulkan: [code]VkSampler[/code].
957965
</constant>
958-
<constant name="DRIVER_RESOURCE_VULKAN_DESCRIPTOR_SET" value="9" enum="DriverResource">
959-
Vulkan [url=https://vkguide.dev/docs/chapter-4/descriptors/]descriptor set[/url] driver resource.
966+
<constant name="DRIVER_RESOURCE_UNIFORM_SET" value="9" enum="DriverResource">
967+
- Vulkan: [code]VkDescriptorSet[/code].
960968
</constant>
961-
<constant name="DRIVER_RESOURCE_VULKAN_BUFFER" value="10" enum="DriverResource">
962-
Vulkan buffer driver resource.
969+
<constant name="DRIVER_RESOURCE_BUFFER" value="10" enum="DriverResource">
970+
Buffer of any kind of (storage, vertex, etc.).
971+
- Vulkan: [code]VkBuffer[/code].
963972
</constant>
964-
<constant name="DRIVER_RESOURCE_VULKAN_COMPUTE_PIPELINE" value="11" enum="DriverResource">
965-
Vulkan compute pipeline driver resource.
973+
<constant name="DRIVER_RESOURCE_COMPUTE_PIPELINE" value="11" enum="DriverResource">
974+
- Vulkan: [code]VkPipeline[/code].
966975
</constant>
967-
<constant name="DRIVER_RESOURCE_VULKAN_RENDER_PIPELINE" value="12" enum="DriverResource">
968-
Vulkan render pipeline driver resource.
976+
<constant name="DRIVER_RESOURCE_RENDER_PIPELINE" value="12" enum="DriverResource">
977+
- Vulkan: [code]VkPipeline[/code].
978+
</constant>
979+
<constant name="DRIVER_RESOURCE_VULKAN_DEVICE" value="0" enum="DriverResource" is_deprecated="true">
980+
[i]Deprecated.[/i] Use [constant DRIVER_RESOURCE_LOGICAL_DEVICE].
981+
</constant>
982+
<constant name="DRIVER_RESOURCE_VULKAN_PHYSICAL_DEVICE" value="1" enum="DriverResource" is_deprecated="true">
983+
[i]Deprecated.[/i] Use [constant DRIVER_RESOURCE_PHYSICAL_DEVICE].
984+
</constant>
985+
<constant name="DRIVER_RESOURCE_VULKAN_INSTANCE" value="2" enum="DriverResource" is_deprecated="true">
986+
[i]Deprecated.[/i] Use [constant DRIVER_RESOURCE_TOPMOST_OBJECT].
987+
</constant>
988+
<constant name="DRIVER_RESOURCE_VULKAN_QUEUE" value="3" enum="DriverResource" is_deprecated="true">
989+
[i]Deprecated.[/i] Use [constant DRIVER_RESOURCE_COMMAND_QUEUE].
990+
</constant>
991+
<constant name="DRIVER_RESOURCE_VULKAN_QUEUE_FAMILY_INDEX" value="4" enum="DriverResource" is_deprecated="true">
992+
[i]Deprecated.[/i] Use [constant DRIVER_RESOURCE_QUEUE_FAMILY].
993+
</constant>
994+
<constant name="DRIVER_RESOURCE_VULKAN_IMAGE" value="5" enum="DriverResource" is_deprecated="true">
995+
[i]Deprecated.[/i] Use [constant DRIVER_RESOURCE_TEXTURE].
996+
</constant>
997+
<constant name="DRIVER_RESOURCE_VULKAN_IMAGE_VIEW" value="6" enum="DriverResource" is_deprecated="true">
998+
[i]Deprecated.[/i] Use [constant DRIVER_RESOURCE_TEXTURE_VIEW].
999+
</constant>
1000+
<constant name="DRIVER_RESOURCE_VULKAN_IMAGE_NATIVE_TEXTURE_FORMAT" value="7" enum="DriverResource" is_deprecated="true">
1001+
[i]Deprecated.[/i] Use [constant DRIVER_RESOURCE_TEXTURE_DATA_FORMAT].
1002+
</constant>
1003+
<constant name="DRIVER_RESOURCE_VULKAN_SAMPLER" value="8" enum="DriverResource" is_deprecated="true">
1004+
[i]Deprecated.[/i] Use [constant DRIVER_RESOURCE_SAMPLER].
1005+
</constant>
1006+
<constant name="DRIVER_RESOURCE_VULKAN_DESCRIPTOR_SET" value="9" enum="DriverResource" is_deprecated="true">
1007+
[i]Deprecated.[/i] Use [constant DRIVER_RESOURCE_UNIFORM_SET].
1008+
</constant>
1009+
<constant name="DRIVER_RESOURCE_VULKAN_BUFFER" value="10" enum="DriverResource" is_deprecated="true">
1010+
[i]Deprecated.[/i] Use [constant DRIVER_RESOURCE_BUFFER].
1011+
</constant>
1012+
<constant name="DRIVER_RESOURCE_VULKAN_COMPUTE_PIPELINE" value="11" enum="DriverResource" is_deprecated="true">
1013+
[i]Deprecated.[/i] Use [constant DRIVER_RESOURCE_COMPUTE_PIPELINE].
1014+
</constant>
1015+
<constant name="DRIVER_RESOURCE_VULKAN_RENDER_PIPELINE" value="12" enum="DriverResource" is_deprecated="true">
1016+
[i]Deprecated.[/i] Use [constant DRIVER_RESOURCE_RENDER_PIPELINE].
9691017
</constant>
9701018
<constant name="DATA_FORMAT_R4G4_UNORM_PACK8" value="0" enum="DataFormat">
9711019
4-bit-per-channel red/green channel data format, packed into 8 bits. Values are in the [code][0.0, 1.0][/code] range.

drivers/d3d12/SCsub

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,39 @@ from pathlib import Path
55

66
Import("env")
77

8-
env_d3d12_rd = env.Clone()
8+
env.Append(CPPDEFINES=["RD_ENABLED"])
9+
10+
env_d3d12_rdd = env.Clone()
911

1012
thirdparty_obj = []
1113

1214

1315
# DirectX Headers (must take precedence over Windows SDK's).
1416

15-
env.Prepend(CPPPATH=["#thirdparty/directx_headers"])
16-
env_d3d12_rd.Prepend(CPPPATH=["#thirdparty/directx_headers"])
17+
env.Prepend(CPPPATH=["#thirdparty/directx_headers/include/directx"])
18+
env_d3d12_rdd.Prepend(CPPPATH=["#thirdparty/directx_headers/include/directx"])
19+
env_d3d12_rdd.Prepend(CPPPATH=["#thirdparty/directx_headers/include/dxguids"])
1720

1821

1922
# Direct3D 12 Memory Allocator.
2023

2124
env.Append(CPPPATH=["#thirdparty/d3d12ma"])
22-
env_d3d12_rd.Append(CPPPATH=["#thirdparty/d3d12ma"])
25+
env_d3d12_rdd.Append(CPPPATH=["#thirdparty/d3d12ma"])
2326

2427

2528
# Agility SDK.
2629

2730
if env["agility_sdk_path"] != "":
28-
env_d3d12_rd.Append(CPPDEFINES=["AGILITY_SDK_ENABLED"])
31+
env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_ENABLED"])
2932
if env["agility_sdk_multiarch"]:
30-
env_d3d12_rd.Append(CPPDEFINES=["AGILITY_SDK_MULTIARCH_ENABLED"])
33+
env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_MULTIARCH_ENABLED"])
3134

3235

3336
# PIX.
3437

3538
if env["pix_path"] != "":
36-
env_d3d12_rd.Append(CPPDEFINES=["PIX_ENABLED"])
37-
env_d3d12_rd.Append(CPPPATH=[env["pix_path"] + "/Include"])
39+
env_d3d12_rdd.Append(CPPDEFINES=["PIX_ENABLED"])
40+
env_d3d12_rdd.Append(CPPPATH=[env["pix_path"] + "/Include"])
3841

3942

4043
# Mesa (SPIR-V to DXIL functionality).
@@ -105,12 +108,16 @@ extra_defines = [
105108
"WINDOWS_NO_FUTEX",
106109
]
107110

111+
mesa_ver = Path(mesa_absdir + "/VERSION.info")
112+
if not mesa_ver.is_file():
113+
mesa_ver = Path(mesa_absdir + "/VERSION")
114+
108115
# These defines are inspired by the Meson build scripts in the original repo.
109116
extra_defines += [
110117
"__STDC_CONSTANT_MACROS",
111118
"__STDC_FORMAT_MACROS",
112119
"__STDC_LIMIT_MACROS",
113-
("PACKAGE_VERSION", '\\"' + Path(mesa_absdir + "/VERSION").read_text().strip() + '\\"'),
120+
("PACKAGE_VERSION", '\\"' + mesa_ver.read_text().strip() + '\\"'),
114121
("PACKAGE_BUGREPORT", '\\"https://gitlab.freedesktop.org/mesa/mesa/-/issues\\"'),
115122
"PIPE_SUBSYSTEM_WINDOWS_USER",
116123
("_Static_assert", "static_assert"),
@@ -129,11 +136,16 @@ if env.msvc:
129136
"NOMINMAX",
130137
"HAVE_STRUCT_TIMESPEC",
131138
]
139+
else:
140+
extra_defines += [
141+
("__REQUIRED_RPCNDR_H_VERSION__", 475),
142+
"HAVE_STRUCT_TIMESPEC",
143+
]
132144

133145
# This is needed since rendering_device_d3d12.cpp needs to include some Mesa internals.
134-
env_d3d12_rd.Prepend(CPPPATH=mesa_private_inc_paths)
146+
env_d3d12_rdd.Prepend(CPPPATH=mesa_private_inc_paths)
135147
# For the same reason as above, the defines must be the same as in the 3rd-party code itself.
136-
env_d3d12_rd.Append(CPPDEFINES=extra_defines)
148+
env_d3d12_rdd.Append(CPPDEFINES=extra_defines)
137149

138150

139151
# Add all.
@@ -144,7 +156,7 @@ env.drivers_sources += thirdparty_obj
144156
# Godot source files.
145157

146158
driver_obj = []
147-
env_d3d12_rd.add_source_files(driver_obj, "*.cpp")
159+
env_d3d12_rdd.add_source_files(driver_obj, "*.cpp")
148160
env.drivers_sources += driver_obj
149161

150162
# Needed to force rebuilding the driver files when the thirdparty code is updated.

0 commit comments

Comments
 (0)