rendering_context_driver.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**************************************************************************/
  2. /* rendering_context_driver.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "rendering_context_driver.h"
  31. RenderingContextDriver::~RenderingContextDriver() {
  32. }
  33. RenderingContextDriver::SurfaceID RenderingContextDriver::surface_get_from_window(DisplayServer::WindowID p_window) const {
  34. HashMap<DisplayServer::WindowID, SurfaceID>::ConstIterator it = window_surface_map.find(p_window);
  35. if (it != window_surface_map.end()) {
  36. return it->value;
  37. } else {
  38. return SurfaceID();
  39. }
  40. }
  41. Error RenderingContextDriver::window_create(DisplayServer::WindowID p_window, const void *p_platform_data) {
  42. SurfaceID surface = surface_create(p_platform_data);
  43. if (surface != 0) {
  44. window_surface_map[p_window] = surface;
  45. return OK;
  46. } else {
  47. return ERR_CANT_CREATE;
  48. }
  49. }
  50. void RenderingContextDriver::window_set_size(DisplayServer::WindowID p_window, uint32_t p_width, uint32_t p_height) {
  51. SurfaceID surface = surface_get_from_window(p_window);
  52. if (surface) {
  53. surface_set_size(surface, p_width, p_height);
  54. }
  55. }
  56. void RenderingContextDriver::window_set_vsync_mode(DisplayServer::WindowID p_window, DisplayServer::VSyncMode p_vsync_mode) {
  57. SurfaceID surface = surface_get_from_window(p_window);
  58. if (surface) {
  59. surface_set_vsync_mode(surface, p_vsync_mode);
  60. }
  61. }
  62. DisplayServer::VSyncMode RenderingContextDriver::window_get_vsync_mode(DisplayServer::WindowID p_window) const {
  63. SurfaceID surface = surface_get_from_window(p_window);
  64. if (surface) {
  65. return surface_get_vsync_mode(surface);
  66. } else {
  67. return DisplayServer::VSYNC_DISABLED;
  68. }
  69. }
  70. void RenderingContextDriver::window_destroy(DisplayServer::WindowID p_window) {
  71. SurfaceID surface = surface_get_from_window(p_window);
  72. if (surface) {
  73. surface_destroy(surface);
  74. }
  75. window_surface_map.erase(p_window);
  76. }
  77. String RenderingContextDriver::get_driver_and_device_memory_report() const {
  78. String report;
  79. const uint32_t num_tracked_obj_types = static_cast<uint32_t>(get_tracked_object_type_count());
  80. report += "=== Driver Memory Report ===";
  81. report += "\nLaunch with --extra-gpu-memory-tracking and build with "
  82. "DEBUG_ENABLED for this functionality to work.";
  83. report += "\nDevice memory may be unavailable if the API does not support it"
  84. "(e.g. VK_EXT_device_memory_report is unsupported).";
  85. report += "\n";
  86. report += "\nTotal Driver Memory:";
  87. report += String::num_real(double(get_driver_total_memory()) / (1024.0 * 1024.0));
  88. report += " MB";
  89. report += "\nTotal Driver Num Allocations: ";
  90. report += String::num_uint64(get_driver_allocation_count());
  91. report += "\nTotal Device Memory:";
  92. report += String::num_real(double(get_device_total_memory()) / (1024.0 * 1024.0));
  93. report += " MB";
  94. report += "\nTotal Device Num Allocations: ";
  95. report += String::num_uint64(get_device_allocation_count());
  96. report += "\n\nMemory use by object type (CSV format):";
  97. report += "\n\nCategory; Driver memory in MB; Driver Allocation Count; "
  98. "Device memory in MB; Device Allocation Count";
  99. for (uint32_t i = 0u; i < num_tracked_obj_types; ++i) {
  100. report += "\n";
  101. report += get_tracked_object_name(i);
  102. report += ";";
  103. report += String::num_real(double(get_driver_memory_by_object_type(i)) / (1024.0 * 1024.0));
  104. report += ";";
  105. report += String::num_uint64(get_driver_allocs_by_object_type(i));
  106. report += ";";
  107. report += String::num_real(double(get_device_memory_by_object_type(i)) / (1024.0 * 1024.0));
  108. report += ";";
  109. report += String::num_uint64(get_device_allocs_by_object_type(i));
  110. }
  111. return report;
  112. }
  113. const char *RenderingContextDriver::get_tracked_object_name(uint32_t p_type_index) const {
  114. return "Tracking Unsupported by API";
  115. }
  116. uint64_t RenderingContextDriver::get_tracked_object_type_count() const {
  117. return 0;
  118. }
  119. uint64_t RenderingContextDriver::get_driver_total_memory() const {
  120. return 0;
  121. }
  122. uint64_t RenderingContextDriver::get_driver_allocation_count() const {
  123. return 0;
  124. }
  125. uint64_t RenderingContextDriver::get_driver_memory_by_object_type(uint32_t) const {
  126. return 0;
  127. }
  128. uint64_t RenderingContextDriver::get_driver_allocs_by_object_type(uint32_t) const {
  129. return 0;
  130. }
  131. uint64_t RenderingContextDriver::get_device_total_memory() const {
  132. return 0;
  133. }
  134. uint64_t RenderingContextDriver::get_device_allocation_count() const {
  135. return 0;
  136. }
  137. uint64_t RenderingContextDriver::get_device_memory_by_object_type(uint32_t) const {
  138. return 0;
  139. }
  140. uint64_t RenderingContextDriver::get_device_allocs_by_object_type(uint32_t) const {
  141. return 0;
  142. }