Path: blob/master/servers/rendering/rendering_context_driver.cpp
10277 views
/**************************************************************************/1/* rendering_context_driver.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "rendering_context_driver.h"3132RenderingContextDriver::~RenderingContextDriver() {33}3435RenderingContextDriver::SurfaceID RenderingContextDriver::surface_get_from_window(DisplayServer::WindowID p_window) const {36HashMap<DisplayServer::WindowID, SurfaceID>::ConstIterator it = window_surface_map.find(p_window);37if (it != window_surface_map.end()) {38return it->value;39} else {40return SurfaceID();41}42}4344Error RenderingContextDriver::window_create(DisplayServer::WindowID p_window, const void *p_platform_data) {45SurfaceID surface = surface_create(p_platform_data);46if (surface != 0) {47window_surface_map[p_window] = surface;48return OK;49} else {50return ERR_CANT_CREATE;51}52}5354void RenderingContextDriver::window_set_size(DisplayServer::WindowID p_window, uint32_t p_width, uint32_t p_height) {55SurfaceID surface = surface_get_from_window(p_window);56if (surface) {57surface_set_size(surface, p_width, p_height);58}59}6061void RenderingContextDriver::window_set_vsync_mode(DisplayServer::WindowID p_window, DisplayServer::VSyncMode p_vsync_mode) {62SurfaceID surface = surface_get_from_window(p_window);63if (surface) {64surface_set_vsync_mode(surface, p_vsync_mode);65}66}6768DisplayServer::VSyncMode RenderingContextDriver::window_get_vsync_mode(DisplayServer::WindowID p_window) const {69SurfaceID surface = surface_get_from_window(p_window);70if (surface) {71return surface_get_vsync_mode(surface);72} else {73return DisplayServer::VSYNC_DISABLED;74}75}7677void RenderingContextDriver::window_destroy(DisplayServer::WindowID p_window) {78SurfaceID surface = surface_get_from_window(p_window);79if (surface) {80surface_destroy(surface);81}8283window_surface_map.erase(p_window);84}8586String RenderingContextDriver::get_driver_and_device_memory_report() const {87String report;8889const uint32_t num_tracked_obj_types = static_cast<uint32_t>(get_tracked_object_type_count());9091report += "=== Driver Memory Report ===";9293report += "\nLaunch with --extra-gpu-memory-tracking and build with "94"DEBUG_ENABLED for this functionality to work.";95report += "\nDevice memory may be unavailable if the API does not support it"96"(e.g. VK_EXT_device_memory_report is unsupported).";97report += "\n";9899report += "\nTotal Driver Memory:";100report += String::num_real(double(get_driver_total_memory()) / (1024.0 * 1024.0));101report += " MB";102report += "\nTotal Driver Num Allocations: ";103report += String::num_uint64(get_driver_allocation_count());104105report += "\nTotal Device Memory:";106report += String::num_real(double(get_device_total_memory()) / (1024.0 * 1024.0));107report += " MB";108report += "\nTotal Device Num Allocations: ";109report += String::num_uint64(get_device_allocation_count());110111report += "\n\nMemory use by object type (CSV format):";112report += "\n\nCategory; Driver memory in MB; Driver Allocation Count; "113"Device memory in MB; Device Allocation Count";114115for (uint32_t i = 0u; i < num_tracked_obj_types; ++i) {116report += "\n";117report += get_tracked_object_name(i);118report += ";";119report += String::num_real(double(get_driver_memory_by_object_type(i)) / (1024.0 * 1024.0));120report += ";";121report += String::num_uint64(get_driver_allocs_by_object_type(i));122report += ";";123report += String::num_real(double(get_device_memory_by_object_type(i)) / (1024.0 * 1024.0));124report += ";";125report += String::num_uint64(get_device_allocs_by_object_type(i));126}127128return report;129}130131const char *RenderingContextDriver::get_tracked_object_name(uint32_t p_type_index) const {132return "Tracking Unsupported by API";133}134135uint64_t RenderingContextDriver::get_tracked_object_type_count() const {136return 0;137}138139uint64_t RenderingContextDriver::get_driver_total_memory() const {140return 0;141}142143uint64_t RenderingContextDriver::get_driver_allocation_count() const {144return 0;145}146147uint64_t RenderingContextDriver::get_driver_memory_by_object_type(uint32_t) const {148return 0;149}150151uint64_t RenderingContextDriver::get_driver_allocs_by_object_type(uint32_t) const {152return 0;153}154155uint64_t RenderingContextDriver::get_device_total_memory() const {156return 0;157}158159uint64_t RenderingContextDriver::get_device_allocation_count() const {160return 0;161}162163uint64_t RenderingContextDriver::get_device_memory_by_object_type(uint32_t) const {164return 0;165}166167uint64_t RenderingContextDriver::get_device_allocs_by_object_type(uint32_t) const {168return 0;169}170171172