Skip to content

Commit

Permalink
Misc commit for reviewing DO NOT MERGE
Browse files Browse the repository at this point in the history
  • Loading branch information
darksylinc committed Apr 6, 2024
1 parent e5b4ef8 commit 56874ef
Show file tree
Hide file tree
Showing 75 changed files with 4,366 additions and 717 deletions.
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))
#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 @@ -1501,6 +1501,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);

This comment has been minimized.

Copy link
@Calinou

Calinou Apr 8, 2024

This should be able to go to higher values, as many devices have 120 Hz, 144 Hz or even 165 Hz displays. Running games at those framerates is viable if they're lightweight (such as 2D games or retro-styled 3D games).

As of writing, the highest value reached in a commercially available Android device is 240 Hz, so we can probably use that as a maximum for the setting.

This comment has been minimized.

Copy link
@darksylinc

darksylinc Apr 8, 2024

Author Owner

Hi!

I'm not sure what was TheForge's rationale here (there may not be any) but please bear in mind the following:

  1. This is about frame pacing when not struggling. That means no frames are skipped, no frames are repeated, all frames are issued at roughly the same time since the start of the VBLANK. In other words, perfect smooth presentation. On PC even with Vulkan, drivers usually handle this. On Android proper presentation timing needs to be done by hand to keep it consistent and that's what this setting is for.
  2. Let's say the game can run at 165hz, but it has lots of spikes and issues. However after targeting 90hz, it is low enough to guarantee perfect smooth presentation. Just because the phone can reach that target, it doesn't mean it can maintain perfect pacing (which gets increasingly harder for higher framerates).
  3. I never saw a 240hz Android screen, but the battery consumption must be ginormous. One thing is to use 240hz when scrolling and then falling back to lower refresh rates when idle; another thing is to keep it constant. At the current resolution of roughly 2300x1080, that would require at least 2.22GB/s of monitor BW. If we add rendering it'd require at least 6.66GB/s (much more actually, considering how Godot renders). BW consumes a ton of battery and makes phones hot.

That setting would need testing on actual devices to see if it makes sense to have such large values. It may make sense; but we shouldn't rush it.


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 @@ -1635,6 +1646,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 @@ -1644,6 +1661,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 @@ -1791,10 +1847,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

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 @@ -498,6 +498,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;

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);

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

0 comments on commit 56874ef

Please sign in to comment.