rendering_context_driver.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**************************************************************************/
  2. /* rendering_context_driver.h */
  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. #ifndef RENDERING_CONTEXT_DRIVER_H
  31. #define RENDERING_CONTEXT_DRIVER_H
  32. #include "core/object/object.h"
  33. #include "servers/display_server.h"
  34. class RenderingDeviceDriver;
  35. class RenderingContextDriver {
  36. public:
  37. typedef uint64_t SurfaceID;
  38. private:
  39. HashMap<DisplayServer::WindowID, SurfaceID> window_surface_map;
  40. public:
  41. SurfaceID surface_get_from_window(DisplayServer::WindowID p_window) const;
  42. Error window_create(DisplayServer::WindowID p_window, const void *p_platform_data);
  43. void window_set_size(DisplayServer::WindowID p_window, uint32_t p_width, uint32_t p_height);
  44. void window_set_vsync_mode(DisplayServer::WindowID p_window, DisplayServer::VSyncMode p_vsync_mode);
  45. DisplayServer::VSyncMode window_get_vsync_mode(DisplayServer::WindowID p_window) const;
  46. void window_destroy(DisplayServer::WindowID p_window);
  47. public:
  48. enum Vendor {
  49. VENDOR_UNKNOWN = 0x0,
  50. VENDOR_AMD = 0x1002,
  51. VENDOR_IMGTEC = 0x1010,
  52. VENDOR_APPLE = 0x106B,
  53. VENDOR_NVIDIA = 0x10DE,
  54. VENDOR_ARM = 0x13B5,
  55. VENDOR_MICROSOFT = 0x1414,
  56. VENDOR_QUALCOMM = 0x5143,
  57. VENDOR_INTEL = 0x8086
  58. };
  59. enum DeviceType {
  60. DEVICE_TYPE_OTHER = 0x0,
  61. DEVICE_TYPE_INTEGRATED_GPU = 0x1,
  62. DEVICE_TYPE_DISCRETE_GPU = 0x2,
  63. DEVICE_TYPE_VIRTUAL_GPU = 0x3,
  64. DEVICE_TYPE_CPU = 0x4,
  65. DEVICE_TYPE_MAX = 0x5
  66. };
  67. struct Workarounds {
  68. bool avoid_compute_after_draw = false;
  69. };
  70. struct Device {
  71. String name = "Unknown";
  72. Vendor vendor = VENDOR_UNKNOWN;
  73. DeviceType type = DEVICE_TYPE_OTHER;
  74. Workarounds workarounds;
  75. };
  76. virtual ~RenderingContextDriver();
  77. virtual Error initialize() = 0;
  78. virtual const Device &device_get(uint32_t p_device_index) const = 0;
  79. virtual uint32_t device_get_count() const = 0;
  80. virtual bool device_supports_present(uint32_t p_device_index, SurfaceID p_surface) const = 0;
  81. virtual RenderingDeviceDriver *driver_create() = 0;
  82. virtual void driver_free(RenderingDeviceDriver *p_driver) = 0;
  83. virtual SurfaceID surface_create(const void *p_platform_data) = 0;
  84. virtual void surface_set_size(SurfaceID p_surface, uint32_t p_width, uint32_t p_height) = 0;
  85. virtual void surface_set_vsync_mode(SurfaceID p_surface, DisplayServer::VSyncMode p_vsync_mode) = 0;
  86. virtual DisplayServer::VSyncMode surface_get_vsync_mode(SurfaceID p_surface) const = 0;
  87. virtual uint32_t surface_get_width(SurfaceID p_surface) const = 0;
  88. virtual uint32_t surface_get_height(SurfaceID p_surface) const = 0;
  89. virtual void surface_set_needs_resize(SurfaceID p_surface, bool p_needs_resize) = 0;
  90. virtual bool surface_get_needs_resize(SurfaceID p_surface) const = 0;
  91. virtual void surface_destroy(SurfaceID p_surface) = 0;
  92. virtual bool is_debug_utils_enabled() const = 0;
  93. String get_driver_and_device_memory_report() const;
  94. virtual const char *get_tracked_object_name(uint32_t p_type_index) const;
  95. virtual uint64_t get_tracked_object_type_count() const;
  96. virtual uint64_t get_driver_total_memory() const;
  97. virtual uint64_t get_driver_allocation_count() const;
  98. virtual uint64_t get_driver_memory_by_object_type(uint32_t p_type) const;
  99. virtual uint64_t get_driver_allocs_by_object_type(uint32_t p_type) const;
  100. virtual uint64_t get_device_total_memory() const;
  101. virtual uint64_t get_device_allocation_count() const;
  102. virtual uint64_t get_device_memory_by_object_type(uint32_t p_type) const;
  103. virtual uint64_t get_device_allocs_by_object_type(uint32_t p_type) const;
  104. };
  105. #endif // RENDERING_CONTEXT_DRIVER_H