Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final results of collaboration with Google and The Forge #90284

Open
wants to merge 186 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
0fc0325
New: buffer_get_persistent_address to return UMA address when possible
ShadyTF Nov 23, 2023
b25b49e
possible usage scenarios for persistently mapped buffers
ShadyTF Nov 23, 2023
16fe4ee
adding new flag BUFFER_USAGE_PERSISTENT_BIT for uma mapped buffers
ShadyTF Dec 1, 2023
c1250b8
initial implementation for linearly allocated persistent buffers
ShadyTF Dec 1, 2023
6cf9b26
add a flag to globally toggle persistent buffers + remove usage in ve…
ShadyTF Dec 1, 2023
b611cf8
missed in previous commit
ShadyTF Dec 1, 2023
3315786
usage example for persistent buffers for RenderSceneDataRD
ShadyTF Dec 1, 2023
39bb921
globally enable persistent buffers
ShadyTF Dec 1, 2023
c9d9294
bitfirelds for buffer creation bits, and update uniform and storage b…
ShadyTF Dec 4, 2023
5b2369f
usage of persistent buffers with particles, skeletons
ShadyTF Dec 4, 2023
45e9cc5
persistent buffer for material storage uniforms
ShadyTF Dec 4, 2023
bdc5a1d
update owner of persistent buffer to match changes from 4.3
ShadyTF Dec 6, 2023
2718c27
persistent buffer usage with material storage
ShadyTF Dec 7, 2023
c2b1658
persistent buffer for vertex, index and uniforms
ShadyTF Dec 7, 2023
f103234
perf report function, can be used to show metrics on screen
ShadyTF Dec 7, 2023
eecc81f
Support for lazily allocatted buffers
ShadyTF Dec 11, 2023
84c4eaf
request debug marker extension along side debug utils, and assign the…
ShadyTF Dec 14, 2023
aa4ed9b
debug marker extenstion usages for begin_label/end_label/ inser_label…
ShadyTF Dec 14, 2023
35961df
VK_EXT_DEBUG_MARKER_EXTENSION_NAME is a device extension, not an inst…
ShadyTF Dec 14, 2023
b02cf06
fixes for debug marker extensions, they should be coming from the dev…
ShadyTF Dec 14, 2023
07ecf9d
adding a function to vma to verify that lazily allocated buffers are …
ShadyTF Dec 15, 2023
062d8f1
function to destroy shader modules, should be called on shaders after…
ShadyTF Jan 10, 2024
7ea1c92
adding function on device level to destroy a specific shader modules,…
ShadyTF Jan 10, 2024
9600903
usage examples for destroy shader modules
ShadyTF Jan 10, 2024
390d12e
fix android build <unused variables>
ShadyTF Jan 12, 2024
4f30636
adding memory advice library
ShadyTF Jan 17, 2024
09f9cd0
linking with memory advice, initialize it in the glue code, and usage…
ShadyTF Jan 18, 2024
3bb0366
report percent available when memory approaches limit
ShadyTF Jan 19, 2024
c64defe
thermal support on the main level of engine
ShadyTF Jan 25, 2024
4151bac
Kotlin activity and java glue call back for thermal status reporting
ShadyTF Jan 25, 2024
2a9ea57
Merge branch 'master_rendergraph' into track1_milstone3_thermal
ShadyTF Jan 25, 2024
27ee7b4
Godot thermal headroom support added
ShadyTF Jan 26, 2024
0be8ab1
get_thermal_headroom on main level
ShadyTF Jan 26, 2024
db6c6aa
ASTC decode mode extension
ShadyTF Jan 30, 2024
9fc7df4
Fix Editor UI issue when UMA buffers are enabled, now enable persist…
ShadyTF Feb 1, 2024
d275e88
Merge branch 'master_rendergraph' into track1_milestone2
ShadyTF Feb 2, 2024
074848f
Merge branch 'master_rendergraph' into track1_milstone3_astc_decode
ShadyTF Feb 2, 2024
9f9e8a5
Descriptor optimizations : remove FREE_DESCRIPTOR flag from descripto…
ShadyTF Feb 6, 2024
0ad217f
Add ability to create linearly allocated uniform set pools, to be use…
ShadyTF Feb 14, 2024
247cd05
fix linear descriptor set pools to be reset on a per frame basis
ShadyTF Feb 15, 2024
55a9f4e
fix resetting of per frame linear descriptor pools, use a reference a…
ShadyTF Feb 15, 2024
679d451
do not use linear pool if its disabled
ShadyTF Feb 15, 2024
ca71b28
using linearly allocatoted descriptor set pool with forward mobile se…
ShadyTF Feb 16, 2024
4e4acda
driver bug work around for linear pools
ShadyTF Feb 16, 2024
57f7647
immutable sampler : vulkan device driver
ShadyTF Feb 23, 2024
e5b954a
immutable sampler : rendering device changes
ShadyTF Feb 23, 2024
7fa2420
shader RD : passing immutable samplers to rendering device
ShadyTF Feb 23, 2024
6b0c8c6
usage case for immutable sampler : shadow sampler
ShadyTF Feb 23, 2024
4dc90d3
replace push constants by UBO, usage example for sky shader in mobile…
ShadyTF Feb 29, 2024
887ea97
prepare sky params for half res cube map
ShadyTF Mar 1, 2024
e05686e
forward mobile renderer : replace push constants for draw params by u…
ShadyTF Mar 1, 2024
74302f4
replacing push constants with uniform buffers
ShadyTF Mar 8, 2024
6e5c134
Revert "forward mobile renderer : replace push constants for draw par…
ShadyTF Mar 8, 2024
2127b8f
Manually reset command pool
NicolaTF Nov 24, 2023
d3889a9
Reset split lists command pools
NicolaTF Nov 26, 2023
6dbc22b
Reset command pool when flushing
NicolaTF Nov 27, 2023
5bc9ac3
Batch descriptor sets binding calls
NicolaTF Nov 29, 2023
654841d
Avoid submitting empty setup command buffer
NicolaTF Dec 4, 2023
45dbf8c
Setup blit command buffer
NicolaTF Dec 11, 2023
62179b2
Split offscreen / onscreen submissions
NicolaTF Dec 11, 2023
3d21db1
Remove api_context_rd.h
NicolaTF Mar 12, 2024
6e6e147
Fix queue synchronization
NicolaTF Mar 12, 2024
4b40e7b
Fix split queue submission
NicolaTF Mar 12, 2024
6854421
Fix multiple swapchains
NicolaTF Mar 12, 2024
062183e
Fix cherry pick leftovers and compute DS batching
NicolaTF Jan 16, 2024
95cc7c1
Setup manual swapchain rotation
NicolaTF Mar 12, 2024
08064c7
Add swapchain transform, implement methods to retrieve device rotation
NicolaTF Dec 14, 2023
22fd9a3
Fix Android errors
NicolaTF Dec 14, 2023
2f617bb
Implement getCurrentScreenRotation()
NicolaTF Dec 14, 2023
6e27edd
Only pass sin and cos of rotation angle to shader
NicolaTF Dec 14, 2023
64939a0
Use native size when creating the swapchain, swap width and height fo…
NicolaTF Dec 15, 2023
e6894bb
Remove unused code, fix leftovers
NicolaTF Dec 15, 2023
62095d8
Remove sc_optimizations
NicolaTF Mar 12, 2024
2d466bb
Fix boot image not showing up on startup
NicolaTF Jan 10, 2024
baa46a6
Fix getCurrentScreenOrientation
NicolaTF Jan 11, 2024
f3b94fb
Render shadow cascades in the same pass
NicolaTF Jan 16, 2024
1a153ed
Issue commands only if they contain a draw, dispatch or clear op
NicolaTF Jan 17, 2024
3409532
Add back support for multiple directional shadows
NicolaTF Jan 17, 2024
a9da7e3
Sort render list by shader and depth
NicolaTF Jan 18, 2024
ecbe3c9
Sort by specialization constants
NicolaTF Jan 18, 2024
2d64d49
Spawn correct amount of threads for GPU particles
NicolaTF Jan 19, 2024
01656c5
Fix descriptor set batching bug
NicolaTF Jan 26, 2024
e133787
Fix flickering bug
NicolaTF Feb 7, 2024
3ce6ccb
Fix cube shadows bug, render ALL directional shadows in the same pass
NicolaTF Feb 8, 2024
fa2e079
Fix cherry pick leftovers
NicolaTF Mar 12, 2024
e0b7815
Start breadcrumb interface
NicolaTF Jan 24, 2024
fe8a243
Move breadcrumbs at render pass level
NicolaTF Jan 25, 2024
bfbe4c0
Write to breadcrumb buffer
NicolaTF Jan 25, 2024
76bc465
Implement breadcrumbs
NicolaTF Jan 25, 2024
778f798
Insert breadcrumbs before render pass
NicolaTF Jan 26, 2024
829da6c
Remove TYPE_BIND_UNIFORM_SET
NicolaTF Jan 31, 2024
b3dbdec
Automatically print breadcrumbs where necessary
NicolaTF Jan 31, 2024
b05f59a
Dynamically map breadcrumb buffer
NicolaTF Jan 31, 2024
61db948
Flush GPU breadcrumb write, crash to avoid additional commands
NicolaTF Feb 1, 2024
5b8c36a
Add callbacks for device memory tracking
NicolaTF Feb 5, 2024
16146f3
Track calls in device driver
NicolaTF Feb 6, 2024
b451518
Fix alignment bugs, make it cross platform
NicolaTF Feb 6, 2024
9fc2bf0
Add support for arbitrary alignment
NicolaTF Feb 6, 2024
9b1c3fe
Fix variable naming, remove leftovers
NicolaTF Feb 6, 2024
6d0e8bd
Add memory report callback
NicolaTF Feb 7, 2024
6e27db7
Add memory report and getter functions
NicolaTF Feb 7, 2024
8d2587d
Add VMA allocators, polish memory tracking
NicolaTF Feb 13, 2024
38a3753
Only enable driver tracking with Vulkan in debug or dev mode
NicolaTF Feb 14, 2024
2806d85
Expose driver memory data to GDscript
NicolaTF Feb 14, 2024
d613b80
Fix error message in case of unknown object type
NicolaTF Feb 14, 2024
730eb17
Add bindings for device memory report
NicolaTF Feb 15, 2024
2d1d9e5
Fix memory report bugs
NicolaTF Feb 15, 2024
816a77b
Properly track VMA allocations
NicolaTF Feb 15, 2024
0206947
Fix surface creation on other platforms
NicolaTF Feb 15, 2024
c4d827f
Add toggles for driver and device memory
NicolaTF Feb 19, 2024
ae5abe2
Handle realloc case where pOriginal is null
NicolaTF Feb 19, 2024
368de5f
Use VK_EXT_device_fault when available
NicolaTF Feb 19, 2024
3b79e68
Retrieve device fault info on device lost
NicolaTF Feb 19, 2024
3e2cfe5
Fix shadow rendering and shadow breadcrumb
NicolaTF Feb 19, 2024
1b4b41c
Enable breadcrumbs only on debug/dev mode
NicolaTF Feb 21, 2024
2b5f8af
Use Godot's naming conventions
NicolaTF Feb 21, 2024
566ffe6
Fix tracking cherry pick
NicolaTF Mar 13, 2024
12ef522
Add Swappy files
NicolaTF Feb 21, 2024
faf5ac8
Fix Swappy linking
NicolaTF Feb 21, 2024
1e469ab
Integrate Swappy frame pacer
NicolaTF Feb 21, 2024
6a7bb35
Fix needed Swappy extension
NicolaTF Feb 21, 2024
4638dfd
Add settings for Swappy
NicolaTF Feb 21, 2024
3b636c3
Fix project settings
NicolaTF Mar 13, 2024
fb2e2cd
Enable custom target frame rates
NicolaTF Mar 13, 2024
ff787c1
Compile and link spirv-opt
NicolaTF Mar 1, 2024
a7ec312
Enable shader optimizer
NicolaTF Mar 4, 2024
55659dd
Preserve spec consts
NicolaTF Mar 4, 2024
a8abe64
Fix crash when optimizing size
NicolaTF Mar 5, 2024
9ef8c3e
Remove debug code, use the builtin optimizer config
NicolaTF Mar 8, 2024
97fdd8b
Make spirv-opt optional
NicolaTF Mar 11, 2024
0ad3b3a
Fix Swappy build errors
NicolaTF Mar 13, 2024
9a20b8d
Merge branch 'TF_final' of https://github.com/ConfettiFX/GodotImprove…
NicolaTF Mar 13, 2024
72045eb
Add back device fault and enable memory report
NicolaTF Mar 13, 2024
9aff40c
TF : adding support for Dynamic UBO feature
ShadyTF Mar 13, 2024
e939cc6
Merge branch 'track1_milestone2' into TF_Final_Track1
ShadyTF Mar 13, 2024
a8070b7
track1 ms 2 conflict fixes
ShadyTF Mar 13, 2024
bf7b8c5
Merge branch 'track1_milestone3' into TF_Final_Track1
ShadyTF Mar 13, 2024
ac16158
Merge branch 'track1_milstone3_thermal' into TF_Final_Track1
ShadyTF Mar 13, 2024
af70976
Merge branch 'track1_milstone3_astc_decode' into TF_Final_Track1
ShadyTF Mar 13, 2024
a5141bd
fix ASTC decode extension
ShadyTF Mar 13, 2024
266313a
Update rendering_device_driver_vulkan.cpp
ShadyTF Mar 13, 2024
c084f58
Merge branch 'track1_milestone4' into TF_Final_Track1
ShadyTF Mar 13, 2024
89ad7e4
track 1 ms 4 fixes
ShadyTF Mar 13, 2024
095df16
Merge branch 'track1_milestone5' into TF_Final_Track1
ShadyTF Mar 13, 2024
0623cc1
follow up fixes for ms5 dynamic ubo
ShadyTF Mar 13, 2024
e4ca8e8
Remove memory advisor
NicolaTF Mar 14, 2024
b038d52
Remove memory advisor usage
NicolaTF Mar 14, 2024
1f5d484
Fix swapchain rotation
NicolaTF Mar 14, 2024
be47c6a
Merge branch 'TF_final' of https://github.com/ConfettiFX/GodotImprove…
NicolaTF Mar 14, 2024
651aef8
Fix Android build
NicolaTF Mar 14, 2024
459a180
Fix spot light shadows
NicolaTF Mar 14, 2024
f63d39a
Merge branch 'TF_final' of https://github.com/ConfettiFX/GodotImprove…
NicolaTF Mar 14, 2024
5a78540
Make light type a necessary parameter
NicolaTF Mar 14, 2024
4ca458d
Merge branch 'track1_milestone4_immutable_samplers' into TF_final
ShadyTF Mar 14, 2024
1e7ec83
disable immutable samplers
ShadyTF Mar 14, 2024
931629d
Track Swappy libs
NicolaTF Mar 14, 2024
5bb5f88
Merge branch 'TF_final' of https://github.com/ConfettiFX/GodotImprove…
NicolaTF Mar 14, 2024
aad4c71
Fix Android build
NicolaTF Mar 14, 2024
e4f87d1
Add toggles for DS batching & command pool reset
NicolaTF Mar 14, 2024
cef59d7
Add toggle for separate queue submissions
NicolaTF Mar 14, 2024
a6fc5f2
Add toggle for render pass optimizations, fix bug when retrieving spe…
NicolaTF Mar 14, 2024
75d6cd7
remove Debug changes
ShadyTF Mar 15, 2024
8ccf882
Fix semaphore and linear descriptor pools leaks
NicolaTF Mar 15, 2024
7e66978
Merge branch 'TF_final' of https://github.com/ConfettiFX/GodotImprove…
NicolaTF Mar 15, 2024
ecf643e
Fix immutable samplers creating holes in the descriptor set writes array
NicolaTF Mar 17, 2024
b1bca37
Fix persistent buffers reset causing validation errors
NicolaTF Mar 17, 2024
9ee5068
Fix immutable samplers errors when creating the shader
NicolaTF Mar 19, 2024
52ccd58
Fix descriptor pool reset bug
NicolaTF Mar 19, 2024
abaf0b5
Fix uniform buffer update via editor
NicolaTF Mar 20, 2024
f1a04a8
Fix errors when preparing for post processing while rendering reflect…
NicolaTF Mar 20, 2024
d928c3f
Remove redundant SPIR-V optimizations
NicolaTF Mar 20, 2024
c7452b2
Fix post processing creating black screens in F+ renderer
NicolaTF Mar 21, 2024
c238452
Fix raster mip map creation
NicolaTF Mar 21, 2024
4d97ca6
Fix 3D text rendering, transparent surfaces
NicolaTF Mar 21, 2024
0b3fb61
Rework persistent buffers, fix flickering shadows
NicolaTF Mar 22, 2024
bf44bf6
Fix F+ renderer
NicolaTF Mar 24, 2024
3f0ff05
Fix support for multiple directional lights
NicolaTF Mar 24, 2024
207bd6c
Fix hardcoded frames in flight value
NicolaTF Mar 25, 2024
dae972c
Add more use cases for persistent buffers
NicolaTF Mar 26, 2024
805780d
Improve performance by sorting by depth
NicolaTF Mar 26, 2024
0a5efd0
Replace more push constants with uniform buffers
NicolaTF Mar 27, 2024
f67d2c4
fix issue of missing glow, simpler prepare params for tone mapper
ShadyTF Mar 27, 2024
c0c7853
Fix buffer update happening during command recording
NicolaTF Mar 28, 2024
5ce0ddc
Fix error msg print on device lost
NicolaTF Mar 28, 2024
12d87ba
Fix leak
NicolaTF Mar 29, 2024
8529a3b
Only reset linear buffers for the current frame
NicolaTF May 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions core/config/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
#include "core/templates/list.h"
#include "core/templates/vector.h"

#if defined(VULKAN_ENABLED) && (defined(DEBUG_ENABLED) || defined(DEV_ENABLED))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be moved to drivers/vulkan.

Copy link
Contributor

@darksylinc darksylinc Apr 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking into this PR.

It seems like it can't be moved there.

It appears that the VK_TRACK_DEVICE_MEMORY is a debug-only macro (it's only defined in debug & dev builds).

When that macro is defined, objects from core inform the Vulkan subsystem what subsystem they belong to.

e.g. in core/core_bind.cpp we have things like:

#if defined(VK_TRACK_DRIVER_MEMORY) || defined(VK_TRACK_DEVICE_MEMORY)
String Engine::get_tracked_object_name(uint32_t typeIndex) const {
	return RenderingContextDriverVulkan::get_tracked_object_name(typeIndex);
}
uint64_t Engine::get_tracked_object_type_count() const {
	return RenderingContextDriverVulkan::get_tracked_object_type_count();
}
#endif

Where get_tracked_object_name returns a string like "INSTANCE", "PHYSICAL_DEVICE", "DESCRIPTOR_SET_LAYOUT".

I don't know if there is a better way yet, but it's not a simple thing of moving that line to a different header.

#define VK_TRACK_DRIVER_MEMORY
#define VK_TRACK_DEVICE_MEMORY
#endif

template <typename T>
class TypedArray;

Expand Down
5 changes: 5 additions & 0 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,11 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("display/window/subwindows/embed_subwindows", true);
// Keep the enum values in sync with the `DisplayServer::VSyncMode` enum.
custom_prop_info["display/window/vsync/vsync_mode"] = PropertyInfo(Variant::INT, "display/window/vsync/vsync_mode", PROPERTY_HINT_ENUM, "Disabled,Enabled,Adaptive,Mailbox");

GLOBAL_DEF("display/window/frame_pacing/android/enable_frame_pacing", false);
GLOBAL_DEF("display/window/frame_pacing/android/enable_auto_swap", true);
GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/frame_pacing/android/target_frame_rate", PROPERTY_HINT_RANGE, "0.0, 90.0, 1.0"), 60);

custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
GLOBAL_DEF("physics/2d/run_on_separate_thread", false);
GLOBAL_DEF("physics/3d/run_on_separate_thread", false);
Expand Down
80 changes: 80 additions & 0 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@
#include "core/os/thread_safe.h"
#include "core/variant/typed_array.h"


#if defined(VK_TRACK_DRIVER_MEMORY) || defined(VK_TRACK_DEVICE_MEMORY)
#include "drivers/vulkan/rendering_context_driver_vulkan.h"
#endif

// <TF>
// @ShadyTF script function to get performance report text
#include "servers/rendering/rendering_device.h"
// </TF>


namespace core_bind {

////// ResourceLoader //////
Expand Down Expand Up @@ -1594,6 +1605,12 @@ int Engine::get_max_fps() const {
double Engine::get_frames_per_second() const {
return ::Engine::get_singleton()->get_frames_per_second();
}
// <TF>
// @ShadyTF script function to get performance report text
String Engine::get_perf_report() const {
return RenderingDevice::get_singleton()->get_perf_report();
}
// </TF>

uint64_t Engine::get_physics_frames() const {
return ::Engine::get_singleton()->get_physics_frames();
Expand All @@ -1603,6 +1620,45 @@ uint64_t Engine::get_process_frames() const {
return ::Engine::get_singleton()->get_process_frames();
}

#if defined(VK_TRACK_DRIVER_MEMORY) || defined(VK_TRACK_DEVICE_MEMORY)
String Engine::get_tracked_object_name(uint32_t typeIndex) const {
return RenderingContextDriverVulkan::get_tracked_object_name(typeIndex);
}
uint64_t Engine::get_tracked_object_type_count() const {
return RenderingContextDriverVulkan::get_tracked_object_type_count();
}
#endif

#if defined(VK_TRACK_DRIVER_MEMORY)
uint64_t Engine::get_driver_total_memory() const {
return RenderingContextDriverVulkan::get_driver_total_memory();
}
uint64_t Engine::get_driver_allocation_count() const {
return RenderingContextDriverVulkan::get_driver_allocation_count();
}
uint64_t Engine::get_driver_memory_by_object_type(uint32_t type) const {
return RenderingContextDriverVulkan::get_driver_memory_by_object_type(type);
}
uint64_t Engine::get_driver_allocs_by_object_type(uint32_t type) const {
return RenderingContextDriverVulkan::get_driver_allocs_by_object_type(type);
}
#endif

#if defined(VK_TRACK_DEVICE_MEMORY)
uint64_t Engine::get_device_total_memory() const {
return RenderingContextDriverVulkan::get_device_total_memory();
}
uint64_t Engine::get_device_allocation_count() const {
return RenderingContextDriverVulkan::get_device_allocation_count();
}
uint64_t Engine::get_device_memory_by_object_type(uint32_t type) const {
return RenderingContextDriverVulkan::get_device_memory_by_object_type(type);
}
uint64_t Engine::get_device_allocs_by_object_type(uint32_t type) const {
return RenderingContextDriverVulkan::get_device_allocs_by_object_type(type);
}
#endif

void Engine::set_time_scale(double p_scale) {
::Engine::get_singleton()->set_time_scale(p_scale);
}
Expand Down Expand Up @@ -1748,10 +1804,34 @@ void Engine::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_time_scale"), &Engine::get_time_scale);

ClassDB::bind_method(D_METHOD("get_frames_drawn"), &Engine::get_frames_drawn);
// <TF>
// @ShadyTF script function to get performance report text
ClassDB::bind_method(D_METHOD("get_frames_per_second"), &Engine::get_frames_per_second);
// </TF>

ClassDB::bind_method(D_METHOD("get_perf_report"), &Engine::get_perf_report);
ClassDB::bind_method(D_METHOD("get_physics_frames"), &Engine::get_physics_frames);
ClassDB::bind_method(D_METHOD("get_process_frames"), &Engine::get_process_frames);

#if defined(VK_TRACK_DRIVER_MEMORY) || defined(VK_TRACK_DEVICE_MEMORY)
ClassDB::bind_method(D_METHOD("get_tracked_object_name"), &Engine::get_tracked_object_name);
ClassDB::bind_method(D_METHOD("get_tracked_object_type_count"), &Engine::get_tracked_object_type_count);
#endif

#if defined(VK_TRACK_DRIVER_MEMORY)
ClassDB::bind_method(D_METHOD("get_driver_total_memory"), &Engine::get_driver_total_memory);
ClassDB::bind_method(D_METHOD("get_driver_allocation_count"), &Engine::get_driver_allocation_count);
ClassDB::bind_method(D_METHOD("get_driver_memory_by_object_type"), &Engine::get_driver_memory_by_object_type);
ClassDB::bind_method(D_METHOD("get_driver_allocs_by_object_type"), &Engine::get_driver_allocs_by_object_type);
#endif

#if defined(VK_TRACK_DEVICE_MEMORY)
ClassDB::bind_method(D_METHOD("get_device_total_memory"), &Engine::get_device_total_memory);
ClassDB::bind_method(D_METHOD("get_device_allocation_count"), &Engine::get_device_allocation_count);
ClassDB::bind_method(D_METHOD("get_device_memory_by_object_type"), &Engine::get_device_memory_by_object_type);
ClassDB::bind_method(D_METHOD("get_device_allocs_by_object_type"), &Engine::get_device_allocs_by_object_type);
#endif
Comment on lines +1816 to +1833
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will mess up documentation generation, so should not be ifdefed, but instead always active, call methods from RenderingContext instance (RenderingDevice::get_singleton()->...) and have dummy implementations in the base RenderingContext class (since same can be later implemented for Metal and DX12).


ClassDB::bind_method(D_METHOD("get_main_loop"), &Engine::get_main_loop);

ClassDB::bind_method(D_METHOD("get_version_info"), &Engine::get_version_info);
Expand Down
23 changes: 23 additions & 0 deletions core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,29 @@ class Engine : public Object {
double get_frames_per_second() const;
uint64_t get_physics_frames() const;
uint64_t get_process_frames() const;
// <TF>
// @ShadyTF script function to get performance report text
String get_perf_report() const;
// </TF>

#if defined(VK_TRACK_DRIVER_MEMORY) || defined(VK_TRACK_DEVICE_MEMORY)
String get_tracked_object_name(uint32_t typeIndex) const;
uint64_t get_tracked_object_type_count() const;
#endif

#if defined(VK_TRACK_DRIVER_MEMORY)
uint64_t get_driver_total_memory() const;
uint64_t get_driver_allocation_count() const;
uint64_t get_driver_memory_by_object_type(uint32_t type) const;
uint64_t get_driver_allocs_by_object_type(uint32_t type) const;
#endif

#if defined(VK_TRACK_DEVICE_MEMORY)
uint64_t get_device_total_memory() const;
uint64_t get_device_allocation_count() const;
uint64_t get_device_memory_by_object_type(uint32_t type) const;
uint64_t get_device_allocs_by_object_type(uint32_t type) const;
#endif

int get_frames_drawn();

Expand Down
26 changes: 26 additions & 0 deletions core/os/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@ SafeNumeric<uint64_t> Memory::max_usage;

SafeNumeric<uint64_t> Memory::alloc_count;

void *Memory::alloc_aligned_static(size_t p_bytes, size_t p_alignment) {
void *p1, *p2;
if ((p1 = (void *)malloc(p_bytes + p_alignment - 1 + sizeof(uint32_t))) == NULL)
return NULL;
Comment on lines +70 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ((p1 = (void *)malloc(p_bytes + p_alignment - 1 + sizeof(uint32_t))) == NULL)
return NULL;
if ((p1 = (void *)malloc(p_bytes + p_alignment - 1 + sizeof(uint32_t))) == nullptr) {
return nullptr;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason it's not using C11 aligned_alloc?


p2 = (void *)(((uintptr_t)p1 + sizeof(uint32_t) + p_alignment - 1) & ~((p_alignment)-1));
*((uint32_t *)p2 - 1) = (uint32_t)((uintptr_t)p2 - (uintptr_t)p1);
return p2;
}

void *Memory::realloc_aligned_static(void* p_memory, size_t p_bytes, size_t p_prev_bytes, size_t p_alignment) {
if (p_memory == NULL)
return alloc_aligned_static(p_bytes, p_alignment);
Comment on lines +79 to +80
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (p_memory == NULL)
return alloc_aligned_static(p_bytes, p_alignment);
if (p_memory == nullptr) {
return alloc_aligned_static(p_bytes, p_alignment);
}


void *ret = alloc_aligned_static(p_bytes, p_alignment);
memcpy(ret, p_memory, p_prev_bytes);
free_aligned_static(p_memory);
return ret;
}

void Memory::free_aligned_static(void* p_memory) {
uint32_t offset = *((uint32_t *)p_memory - 1);
void *p = (void *)((uint8_t *)p_memory - offset);
free(p);
}

void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) {
#ifdef DEBUG_ENABLED
bool prepad = true;
Expand Down
5 changes: 5 additions & 0 deletions core/os/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class Memory {
static void *realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align = false);
static void free_static(void *p_ptr, bool p_pad_align = false);

static void *alloc_aligned_static(size_t p_bytes, size_t p_alignment);
static void *realloc_aligned_static(void *p_memory, size_t p_bytes, size_t p_prev_bytes, size_t p_alignment);
static void free_aligned_static(void* p_memory);


static uint64_t get_mem_available();
static uint64_t get_mem_usage();
static uint64_t get_mem_max_usage();
Expand Down
7 changes: 7 additions & 0 deletions drivers/gles3/storage/texture_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2583,6 +2583,13 @@ bool TextureStorage::render_target_is_using_hdr(RID p_render_target) const {
return rt->hdr;
}

int64_t TextureStorage::render_target_get_format(RID p_render_target) const {
RenderTarget *rt = render_target_owner.get_or_null(p_render_target);
ERR_FAIL_NULL_V(rt, false);

return RenderingDevice::get_singleton()->framebuffer_get_format(rt->texture);
}

GLuint TextureStorage::render_target_get_color_internal_format(RID p_render_target) const {
RenderTarget *rt = render_target_owner.get_or_null(p_render_target);
ERR_FAIL_NULL_V(rt, GL_RGBA8);
Expand Down
1 change: 1 addition & 0 deletions drivers/gles3/storage/texture_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ class TextureStorage : public RendererTextureStorage {
virtual void render_target_do_msaa_resolve(RID p_render_target) override {}
virtual void render_target_set_use_hdr(RID p_render_target, bool p_use_hdr_2d) override;
virtual bool render_target_is_using_hdr(RID p_render_target) const override;
virtual int64_t render_target_get_format(RID p_render_target) const override;

// new
void render_target_set_as_unused(RID p_render_target) override {
Expand Down
Loading