Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
gpu_surface.hpp
Go to the documentation of this file.
1#pragma once
2
3#if defined(PULP_GPU_RUNTIME)
4// This build's device layer is gpu-runtime's (tools/cmake/PulpGpuRuntime.cmake):
5// these are its types and functions under their Pulp names, so a Pulp object
6// and a gpu-runtime object are one and the same.
7#include <gpu_runtime/gpu_surface.hpp>
8
9namespace pulp::render {
10using gpu_runtime::GpuSurface;
11using gpu_runtime::SwapchainResizeState;
12} // namespace pulp::render
13#else // !PULP_GPU_RUNTIME
14
15#include <cstdint>
16#include <memory>
17#include <string>
18
19namespace pulp::render {
20
29 public:
31 void request(uint32_t width, uint32_t height) {
32 requested_width_ = width;
33 requested_height_ = height;
34 }
35
38 configured_width_ = requested_width_;
39 configured_height_ = requested_height_;
40 configured_ = true;
41 }
42
45 void invalidate() {
46 configured_ = false;
47 }
48
51 bool presentable() const {
52 return requested_width_ != 0 && requested_height_ != 0;
53 }
54
56 bool needs_configure() const {
57 return presentable() && (!configured_ || requested_width_ != configured_width_ ||
58 requested_height_ != configured_height_);
59 }
60
63 void note_frame(bool configured) {
64 if (configured)
65 stable_frames_ = 0;
66 else if (stable_frames_ < kSettleFrames)
67 ++stable_frames_;
68 }
69
75 bool settled() const {
76 return presentable() && !needs_configure() && stable_frames_ >= kSettleFrames;
77 }
78
79 static constexpr uint32_t kSettleFrames = 2;
80
82 uint32_t width() const {
83 return requested_width_;
84 }
85 uint32_t height() const {
86 return requested_height_;
87 }
88
89 private:
90 uint32_t requested_width_ = 0;
91 uint32_t requested_height_ = 0;
92 uint32_t configured_width_ = 0;
93 uint32_t configured_height_ = 0;
94 bool configured_ = false;
95 uint32_t stable_frames_ = 0;
96};
97
113public:
123
135
136 struct AdapterInfo {
137 bool available = false;
138 bool native_bridge = false;
144 bool null_backend = false;
145 std::string backend = "unavailable";
146 std::string backend_type = "Unknown";
147 std::string name = "Mock Dawn Adapter";
148 std::string vendor = "Pulp";
149 std::string architecture = "unavailable";
150 std::string description = "Mock Dawn Adapter";
151 std::string preferred_canvas_format = "bgra8unorm";
152 };
153
154 struct Config {
155 uint32_t width = 800;
156 uint32_t height = 600;
157 bool vsync = true;
158
173 bool enable_gpu_timing = false;
174
178
187 void* native_surface_handle = nullptr;
188 };
189
197 void* display = nullptr; // Display*
198 unsigned long window = 0; // Window
199 };
200
201 virtual ~GpuSurface() = default;
202
203 virtual bool initialize(const Config& config) = 0;
204
208 virtual void resize(uint32_t width, uint32_t height) = 0;
209
213 virtual bool begin_frame() = 0;
214
216 virtual void end_frame() = 0;
217
218 virtual bool is_initialized() const = 0;
219 virtual bool has_surface() const = 0;
220 virtual uint32_t width() const = 0;
221 virtual uint32_t height() const = 0;
222
226 virtual void* dawn_device_handle() const = 0;
227 virtual void* dawn_queue_handle() const = 0;
228 virtual void* dawn_instance_handle() const = 0;
229
232 virtual void* current_texture_handle() const = 0;
233
236 virtual AdapterInfo adapter_info() const = 0;
237
238 static std::unique_ptr<GpuSurface> create_dawn();
239
244 double instance_ms = -1.0;
246 double adapter_ms = -1.0;
248 double device_ms = -1.0;
250 double surface_ms = -1.0;
251 };
252
256 virtual StartupTimings startup_timings() const { return {}; }
257
263 uint64_t configure_count = 0;
264 double configure_ms = 0.0;
266 bool settled = false;
267 };
268
271 return {};
272 }
273};
274
275} // namespace pulp::render
276
277#endif // PULP_GPU_RUNTIME
Abstract GPU surface — a presentable rendering target backed by a native window/view.
Definition gpu_surface.hpp:112
virtual bool initialize(const Config &config)=0
virtual void * dawn_queue_handle() const =0
virtual void end_frame()=0
Present to native surface (or just process events if offscreen).
virtual void * current_texture_handle() const =0
The current presentable texture, valid only between begin_frame/end_frame.
virtual bool is_initialized() const =0
virtual ~GpuSurface()=default
virtual void * dawn_device_handle() const =0
Opaque accessors for the Dawn device/queue/texture.
virtual SwapchainStats swapchain_stats() const
Kept at the vtable tail for the same reason as startup_timings().
Definition gpu_surface.hpp:270
virtual AdapterInfo adapter_info() const =0
Snapshot describing the current adapter/device state for higher-level bridges.
static std::unique_ptr< GpuSurface > create_dawn()
virtual uint32_t height() const =0
virtual void * dawn_instance_handle() const =0
virtual uint32_t width() const =0
virtual bool has_surface() const =0
virtual StartupTimings startup_timings() const
Stage timings recorded by the most recent initialize() call.
Definition gpu_surface.hpp:256
virtual bool begin_frame()=0
Acquire the current presentable texture, first configuring the swapchain if the size changed since th...
virtual void resize(uint32_t width, uint32_t height)=0
Record a new size.
AdapterType
Native adapter type reported by Dawn/WebGPU.
Definition gpu_surface.hpp:117
@ integrated_gpu
Definition gpu_surface.hpp:119
@ discrete_gpu
Definition gpu_surface.hpp:120
@ unknown
Definition gpu_surface.hpp:118
@ cpu
Definition gpu_surface.hpp:121
AdapterBackendPreference
Definition gpu_surface.hpp:124
@ d3d12
Use the D3D12 backend without Dawn's fallback-adapter hint.
Definition gpu_surface.hpp:133
@ null_backend
Definition gpu_surface.hpp:126
@ vulkan
Use the Vulkan backend without Dawn's fallback-adapter hint.
Definition gpu_surface.hpp:130
@ default_backend
Definition gpu_surface.hpp:125
Decides when a presentable swapchain has to be (re)configured.
Definition gpu_surface.hpp:28
void note_frame(bool configured)
Record a presented frame.
Definition gpu_surface.hpp:63
static constexpr uint32_t kSettleFrames
Definition gpu_surface.hpp:79
bool settled() const
Settled: the last kSettleFrames frames presented without configuring, and no resize is pending,...
Definition gpu_surface.hpp:75
uint32_t height() const
Definition gpu_surface.hpp:85
uint32_t width() const
The requested size, which is what GpuSurface::width()/height() report.
Definition gpu_surface.hpp:82
void invalidate()
Make the next frame configure even at an unchanged size, for a swapchain the surface reported as subo...
Definition gpu_surface.hpp:45
bool needs_configure() const
True when the next frame must configure before it acquires a texture.
Definition gpu_surface.hpp:56
bool presentable() const
A zero dimension (a minimised or collapsed window) has nothing to present, and a swapchain cannot be ...
Definition gpu_surface.hpp:51
void mark_configured()
The swapchain now matches the requested size.
Definition gpu_surface.hpp:37
void request(uint32_t width, uint32_t height)
Record the size the host wants. Configures nothing.
Definition gpu_surface.hpp:31
Definition gpu_fwd.hpp:31
Definition gpu_surface.hpp:136
std::string name
Definition gpu_surface.hpp:147
AdapterType adapter_type
Definition gpu_surface.hpp:139
bool available
Definition gpu_surface.hpp:137
std::string backend
Definition gpu_surface.hpp:145
std::string backend_type
Definition gpu_surface.hpp:146
std::string description
Definition gpu_surface.hpp:150
std::string architecture
Definition gpu_surface.hpp:149
std::string vendor
Definition gpu_surface.hpp:148
std::string preferred_canvas_format
Definition gpu_surface.hpp:151
bool null_backend
Authoritative backend classification reported by Dawn/WebGPU.
Definition gpu_surface.hpp:144
bool native_bridge
Definition gpu_surface.hpp:138
Definition gpu_surface.hpp:154
bool force_fallback_adapter
Definition gpu_surface.hpp:175
AdapterBackendPreference backend_preference
Definition gpu_surface.hpp:176
uint32_t width
Definition gpu_surface.hpp:155
bool enable_gpu_timing
Request Dawn's timestamp-query feature for GPU render timing.
Definition gpu_surface.hpp:173
uint32_t height
Definition gpu_surface.hpp:156
bool vsync
Definition gpu_surface.hpp:157
void * native_surface_handle
Opaque platform-specific handle for on-screen rendering.
Definition gpu_surface.hpp:187
Wall-clock milliseconds spent in each stage of initialize(), measured with a monotonic clock.
Definition gpu_surface.hpp:243
double surface_ms
Native surface creation plus the first swapchain configure.
Definition gpu_surface.hpp:250
double instance_ms
Definition gpu_surface.hpp:244
double device_ms
Device request, including feature and toggle negotiation.
Definition gpu_surface.hpp:248
double adapter_ms
Adapter request (RequestAdapter / EnumerateAdapters).
Definition gpu_surface.hpp:246
Swapchain configurations issued since initialize(), the first one included, their total wall-clock mi...
Definition gpu_surface.hpp:262
bool settled
SwapchainResizeState::settled(): the size has held for two frames.
Definition gpu_surface.hpp:266
double configure_ms
Definition gpu_surface.hpp:264
uint64_t configure_count
Definition gpu_surface.hpp:263
Typed X11 surface handle.
Definition gpu_surface.hpp:196
unsigned long window
Definition gpu_surface.hpp:198
void * display
Definition gpu_surface.hpp:197