diff options
Diffstat (limited to 'servers/rendering/rendering_server_default.cpp')
-rw-r--r-- | servers/rendering/rendering_server_default.cpp | 98 |
1 files changed, 58 insertions, 40 deletions
diff --git a/servers/rendering/rendering_server_default.cpp b/servers/rendering/rendering_server_default.cpp index 2ce9a20b6b..8071b7e416 100644 --- a/servers/rendering/rendering_server_default.cpp +++ b/servers/rendering/rendering_server_default.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -48,7 +48,7 @@ void RenderingServerDefault::_free(RID p_rid) { if (unlikely(p_rid.is_null())) { return; } - if (RSG::storage->free(p_rid)) { + if (RSG::utilities->free(p_rid)) { return; } if (RSG::canvas->free(p_rid)) { @@ -84,7 +84,7 @@ void RenderingServerDefault::_draw(bool p_swap_buffers, double frame_step) { frame_setup_time = double(OS::get_singleton()->get_ticks_usec() - time_usec) / 1000.0; - RSG::storage->update_particles(); //need to be done after instances are updated (colliders and particle transforms), and colliders are rendered + RSG::particles_storage->update_particles(); //need to be done after instances are updated (colliders and particle transforms), and colliders are rendered RSG::scene->render_probes(); @@ -93,6 +93,12 @@ void RenderingServerDefault::_draw(bool p_swap_buffers, double frame_step) { RSG::rasterizer->end_frame(p_swap_buffers); + XRServer *xr_server = XRServer::get_singleton(); + if (xr_server != nullptr) { + // let our XR server know we're done so we can get our frame timing + xr_server->end_frame(); + } + RSG::canvas->update_visibility_notifiers(); RSG::scene->update_visibility_notifiers(); @@ -100,7 +106,7 @@ void RenderingServerDefault::_draw(bool p_swap_buffers, double frame_step) { Callable c = frame_drawn_callbacks.front()->get(); Variant result; Callable::CallError ce; - c.call(nullptr, 0, result, ce); + c.callp(nullptr, 0, result, ce); if (ce.error != Callable::CallError::CALL_OK) { String err = Variant::get_callable_error_text(c, nullptr, 0, ce); ERR_PRINT("Error calling frame drawn function: " + err); @@ -110,35 +116,35 @@ void RenderingServerDefault::_draw(bool p_swap_buffers, double frame_step) { } RS::get_singleton()->emit_signal(SNAME("frame_post_draw")); - if (RSG::storage->get_captured_timestamps_count()) { + if (RSG::utilities->get_captured_timestamps_count()) { Vector<FrameProfileArea> new_profile; - if (RSG::storage->capturing_timestamps) { - new_profile.resize(RSG::storage->get_captured_timestamps_count()); + if (RSG::utilities->capturing_timestamps) { + new_profile.resize(RSG::utilities->get_captured_timestamps_count()); } - uint64_t base_cpu = RSG::storage->get_captured_timestamp_cpu_time(0); - uint64_t base_gpu = RSG::storage->get_captured_timestamp_gpu_time(0); - for (uint32_t i = 0; i < RSG::storage->get_captured_timestamps_count(); i++) { - uint64_t time_cpu = RSG::storage->get_captured_timestamp_cpu_time(i); - uint64_t time_gpu = RSG::storage->get_captured_timestamp_gpu_time(i); + uint64_t base_cpu = RSG::utilities->get_captured_timestamp_cpu_time(0); + uint64_t base_gpu = RSG::utilities->get_captured_timestamp_gpu_time(0); + for (uint32_t i = 0; i < RSG::utilities->get_captured_timestamps_count(); i++) { + uint64_t time_cpu = RSG::utilities->get_captured_timestamp_cpu_time(i); + uint64_t time_gpu = RSG::utilities->get_captured_timestamp_gpu_time(i); - String name = RSG::storage->get_captured_timestamp_name(i); + String name = RSG::utilities->get_captured_timestamp_name(i); if (name.begins_with("vp_")) { RSG::viewport->handle_timestamp(name, time_cpu, time_gpu); } - if (RSG::storage->capturing_timestamps) { + if (RSG::utilities->capturing_timestamps) { new_profile.write[i].gpu_msec = double((time_gpu - base_gpu) / 1000) / 1000.0; new_profile.write[i].cpu_msec = double(time_cpu - base_cpu) / 1000.0; - new_profile.write[i].name = RSG::storage->get_captured_timestamp_name(i); + new_profile.write[i].name = RSG::utilities->get_captured_timestamp_name(i); } } frame_profile = new_profile; } - frame_profile_frame = RSG::storage->get_captured_timestamps_frame(); + frame_profile_frame = RSG::utilities->get_captured_timestamps_frame(); if (print_gpu_profile) { if (print_frame_profile_ticks_from == 0) { @@ -173,10 +179,10 @@ void RenderingServerDefault::_draw(bool p_swap_buffers, double frame_step) { print_line("GPU PROFILE (total " + rtos(total_time) + "ms): "); float print_threshold = 0.01; - for (OrderedHashMap<String, float>::Element E = print_gpu_profile_task_time.front(); E; E = E.next()) { - double time = E.value() / double(print_frame_profile_frame_count); + for (const KeyValue<String, float> &E : print_gpu_profile_task_time) { + double time = E.value / double(print_frame_profile_frame_count); if (time > print_threshold) { - print_line("\t-" + E.key() + ": " + rtos(time) + "ms"); + print_line("\t-" + E.key + ": " + rtos(time) + "ms"); } } print_gpu_profile_task_time.clear(); @@ -185,7 +191,7 @@ void RenderingServerDefault::_draw(bool p_swap_buffers, double frame_step) { } } - RSG::storage->update_memory_info(); + RSG::utilities->update_memory_info(); } double RenderingServerDefault::get_frame_setup_time_cpu() const { @@ -244,19 +250,27 @@ uint64_t RenderingServerDefault::get_rendering_info(RenderingInfo p_info) { } else if (p_info == RENDERING_INFO_TOTAL_DRAW_CALLS_IN_FRAME) { return RSG::viewport->get_total_draw_calls_used(); } - return RSG::storage->get_rendering_info(p_info); + return RSG::utilities->get_rendering_info(p_info); } String RenderingServerDefault::get_video_adapter_name() const { - return RSG::storage->get_video_adapter_name(); + return RSG::utilities->get_video_adapter_name(); } String RenderingServerDefault::get_video_adapter_vendor() const { - return RSG::storage->get_video_adapter_vendor(); + return RSG::utilities->get_video_adapter_vendor(); +} + +RenderingDevice::DeviceType RenderingServerDefault::get_video_adapter_type() const { + return RSG::utilities->get_video_adapter_type(); +} + +String RenderingServerDefault::get_video_adapter_api_version() const { + return RSG::utilities->get_video_adapter_api_version(); } void RenderingServerDefault::set_frame_profiling_enabled(bool p_enable) { - RSG::storage->capturing_timestamps = p_enable; + RSG::utilities->capturing_timestamps = p_enable; } uint64_t RenderingServerDefault::get_frame_profile_frame() { @@ -287,7 +301,7 @@ void RenderingServerDefault::sdfgi_set_debug_probe_select(const Vector3 &p_posit } void RenderingServerDefault::set_print_gpu_profile(bool p_enable) { - RSG::storage->capturing_timestamps = p_enable; + RSG::utilities->capturing_timestamps = p_enable; print_gpu_profile = p_enable; } @@ -299,19 +313,19 @@ RID RenderingServerDefault::get_test_cube() { } bool RenderingServerDefault::has_os_feature(const String &p_feature) const { - return RSG::storage->has_os_feature(p_feature); + if (RSG::utilities) { + return RSG::utilities->has_os_feature(p_feature); + } else { + return false; + } } void RenderingServerDefault::set_debug_generate_wireframes(bool p_generate) { - RSG::storage->set_debug_generate_wireframes(p_generate); + RSG::utilities->set_debug_generate_wireframes(p_generate); } bool RenderingServerDefault::is_low_end() const { - // FIXME: Commented out when rebasing vulkan branch on master, - // causes a crash, it seems rasterizer is not initialized yet the - // first time it's called. - //return RSG::rasterizer->is_low_end(); - return false; + return RendererCompositor::is_low_end(); } void RenderingServerDefault::_thread_exit() { @@ -319,13 +333,10 @@ void RenderingServerDefault::_thread_exit() { } void RenderingServerDefault::_thread_draw(bool p_swap_buffers, double frame_step) { - if (!draw_pending.decrement()) { - _draw(p_swap_buffers, frame_step); - } + _draw(p_swap_buffers, frame_step); } void RenderingServerDefault::_thread_flush() { - draw_pending.decrement(); } void RenderingServerDefault::_thread_callback(void *_instance) { @@ -356,7 +367,6 @@ void RenderingServerDefault::_thread_loop() { void RenderingServerDefault::sync() { if (create_thread) { - draw_pending.increment(); command_queue.push_and_sync(this, &RenderingServerDefault::_thread_flush); } else { command_queue.flush_all(); //flush all pending from other threads @@ -365,7 +375,6 @@ void RenderingServerDefault::sync() { void RenderingServerDefault::draw(bool p_swap_buffers, double frame_step) { if (create_thread) { - draw_pending.increment(); command_queue.push(this, &RenderingServerDefault::_thread_draw, p_swap_buffers, frame_step); } else { _draw(p_swap_buffers, frame_step); @@ -374,6 +383,8 @@ void RenderingServerDefault::draw(bool p_swap_buffers, double frame_step) { RenderingServerDefault::RenderingServerDefault(bool p_create_thread) : command_queue(p_create_thread) { + RenderingServer::init(); + create_thread = p_create_thread; if (!p_create_thread) { @@ -388,7 +399,14 @@ RenderingServerDefault::RenderingServerDefault(bool p_create_thread) : RendererSceneCull *sr = memnew(RendererSceneCull); RSG::scene = sr; RSG::rasterizer = RendererCompositor::create(); - RSG::storage = RSG::rasterizer->get_storage(); + RSG::utilities = RSG::rasterizer->get_utilities(); + RSG::light_storage = RSG::rasterizer->get_light_storage(); + RSG::material_storage = RSG::rasterizer->get_material_storage(); + RSG::mesh_storage = RSG::rasterizer->get_mesh_storage(); + RSG::particles_storage = RSG::rasterizer->get_particles_storage(); + RSG::texture_storage = RSG::rasterizer->get_texture_storage(); + RSG::gi = RSG::rasterizer->get_gi(); + RSG::fog = RSG::rasterizer->get_fog(); RSG::canvas_render = RSG::rasterizer->get_canvas(); sr->set_scene_render(RSG::rasterizer->get_scene()); |