-
-
Notifications
You must be signed in to change notification settings - Fork 26.4k
Expand file tree
/
Copy pathrendering_context_driver.h
More file actions
151 lines (133 loc) · 8 KB
/
Copy pathrendering_context_driver.h
File metadata and controls
151 lines (133 loc) · 8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**************************************************************************/
/* rendering_context_driver.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#pragma once
#include "core/string/ustring.h"
#include "core/templates/hash_map.h"
#include "servers/display/display_server_enums.h"
#include <cstdint>
class RenderingDeviceDriver;
class RenderingContextDriver {
public:
typedef uint64_t SurfaceID;
private:
HashMap<DisplayServerEnums::WindowID, SurfaceID> window_surface_map;
protected:
Error _check_excluded_devices();
public:
SurfaceID surface_get_from_window(DisplayServerEnums::WindowID p_window) const;
Error window_create(DisplayServerEnums::WindowID p_window, const void *p_platform_data);
void window_set_size(DisplayServerEnums::WindowID p_window, uint32_t p_width, uint32_t p_height);
void window_set_vsync_mode(DisplayServerEnums::WindowID p_window, DisplayServerEnums::VSyncMode p_vsync_mode);
DisplayServerEnums::VSyncMode window_get_vsync_mode(DisplayServerEnums::WindowID p_window) const;
void window_set_hdr_output_enabled(DisplayServerEnums::WindowID p_window, bool p_enabled);
bool window_get_hdr_output_enabled(DisplayServerEnums::WindowID p_window) const;
void window_set_hdr_output_reference_luminance(DisplayServerEnums::WindowID p_window, float p_reference_luminance);
float window_get_hdr_output_reference_luminance(DisplayServerEnums::WindowID p_window) const;
void window_set_hdr_output_max_luminance(DisplayServerEnums::WindowID p_window, float p_max_luminance);
float window_get_hdr_output_max_luminance(DisplayServerEnums::WindowID p_window) const;
void window_set_hdr_output_linear_luminance_scale(DisplayServerEnums::WindowID p_window, float p_linear_luminance_scale);
float window_get_hdr_output_linear_luminance_scale(DisplayServerEnums::WindowID p_window) const;
float window_get_output_max_linear_value(DisplayServerEnums::WindowID p_window) const;
void window_destroy(DisplayServerEnums::WindowID p_window);
public:
// Not an enum as these values are matched against values returned by
// the various drivers, which report them in uint32_t. Casting to an
// enum value is dangerous in this case as we don't actually know what
// range the driver is reporting a value in.
struct Vendor {
constexpr static uint32_t VENDOR_UNKNOWN = 0x0;
constexpr static uint32_t VENDOR_AMD = 0x1002;
constexpr static uint32_t VENDOR_IMGTEC = 0x1010;
constexpr static uint32_t VENDOR_APPLE = 0x106B;
constexpr static uint32_t VENDOR_NVIDIA = 0x10DE;
constexpr static uint32_t VENDOR_ARM = 0x13B5;
constexpr static uint32_t VENDOR_MICROSOFT = 0x1414;
constexpr static uint32_t VENDOR_QUALCOMM = 0x5143;
constexpr static uint32_t VENDOR_INTEL = 0x8086;
};
enum DeviceType {
DEVICE_TYPE_OTHER = 0x0,
DEVICE_TYPE_INTEGRATED_GPU = 0x1,
DEVICE_TYPE_DISCRETE_GPU = 0x2,
DEVICE_TYPE_VIRTUAL_GPU = 0x3,
DEVICE_TYPE_CPU = 0x4,
DEVICE_TYPE_MAX = 0x5
};
struct Workarounds {
bool avoid_compute_after_draw = false;
};
struct Device {
String name = "Unknown";
uint32_t vendor = Vendor::VENDOR_UNKNOWN;
DeviceType type = DEVICE_TYPE_OTHER;
Workarounds workarounds;
};
virtual ~RenderingContextDriver();
virtual Error initialize() = 0;
virtual const Device &device_get(uint32_t p_device_index) const = 0;
virtual uint32_t device_get_count() const = 0;
virtual bool device_supports_present(uint32_t p_device_index, SurfaceID p_surface) const = 0;
virtual RenderingDeviceDriver *driver_create() = 0;
virtual void driver_free(RenderingDeviceDriver *p_driver) = 0;
virtual SurfaceID surface_create(const void *p_platform_data) = 0;
virtual void surface_set_size(SurfaceID p_surface, uint32_t p_width, uint32_t p_height) = 0;
virtual void surface_set_vsync_mode(SurfaceID p_surface, DisplayServerEnums::VSyncMode p_vsync_mode) = 0;
virtual DisplayServerEnums::VSyncMode surface_get_vsync_mode(SurfaceID p_surface) const = 0;
virtual void surface_set_hdr_output_enabled(SurfaceID p_surface, bool p_enabled) = 0;
virtual bool surface_get_hdr_output_enabled(SurfaceID p_surface) const = 0;
virtual void surface_set_hdr_output_reference_luminance(SurfaceID p_surface, float p_reference_luminance) = 0;
virtual float surface_get_hdr_output_reference_luminance(SurfaceID p_surface) const = 0;
virtual void surface_set_hdr_output_max_luminance(SurfaceID p_surface, float p_max_luminance) = 0;
virtual float surface_get_hdr_output_max_luminance(SurfaceID p_surface) const = 0;
virtual void surface_set_hdr_output_linear_luminance_scale(SurfaceID p_surface, float p_linear_luminance_scale) = 0;
virtual float surface_get_hdr_output_linear_luminance_scale(SurfaceID p_surface) const = 0;
virtual float surface_get_hdr_output_max_value(SurfaceID p_surface) const = 0;
virtual uint32_t surface_get_width(SurfaceID p_surface) const = 0;
virtual uint32_t surface_get_height(SurfaceID p_surface) const = 0;
virtual void surface_set_needs_resize(SurfaceID p_surface, bool p_needs_resize) = 0;
virtual bool surface_get_needs_resize(SurfaceID p_surface) const = 0;
virtual void surface_destroy(SurfaceID p_surface) = 0;
virtual bool is_debug_utils_enabled() const = 0;
int32_t pick_device(SurfaceID p_surface, bool p_print_verbose);
String get_driver_and_device_memory_report() const;
virtual const char *get_tracked_object_name(uint32_t p_type_index) const;
virtual uint64_t get_tracked_object_type_count() const;
virtual uint64_t get_driver_total_memory() const;
virtual uint64_t get_driver_allocation_count() const;
virtual uint64_t get_driver_memory_by_object_type(uint32_t p_type) const;
virtual uint64_t get_driver_allocs_by_object_type(uint32_t p_type) const;
virtual uint64_t get_device_total_memory() const;
virtual uint64_t get_device_allocation_count() const;
virtual uint64_t get_device_memory_by_object_type(uint32_t p_type) const;
virtual uint64_t get_device_allocs_by_object_type(uint32_t p_type) const;
static String get_device_vendor_name(const Device &p_device);
static String get_device_type_name(const Device &p_device);
static uint32_t get_device_type_score(const Device &p_device);
};