plusui-native-core 0.1.21 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Core/include/plusui/app.hpp +73 -73
- package/Core/include/plusui/browser.hpp +68 -68
- package/Core/include/plusui/clipboard.hpp +41 -41
- package/Core/include/plusui/custom_bindings.hpp +17 -17
- package/Core/include/plusui/display.hpp +90 -90
- package/Core/include/plusui/keyboard.hpp +112 -112
- package/Core/include/plusui/menu.hpp +153 -153
- package/Core/include/plusui/native_bindings.hpp +19 -19
- package/Core/include/plusui/tray.hpp +94 -94
- package/Core/include/plusui/webgpu.hpp +434 -434
- package/Core/include/plusui/webview.hpp +142 -142
- package/Core/include/plusui/window.hpp +111 -111
- package/Core/include/plusui/window_manager.hpp +59 -59
- package/package.json +1 -1
|
@@ -1,434 +1,434 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <string>
|
|
4
|
-
#include <memory>
|
|
5
|
-
#include <unordered_map>
|
|
6
|
-
#include <vector>
|
|
7
|
-
#include <functional>
|
|
8
|
-
#include <optional>
|
|
9
|
-
|
|
10
|
-
namespace plusui {
|
|
11
|
-
|
|
12
|
-
// Forward declarations for WebGPU types
|
|
13
|
-
class WebGPU;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @brief Configuration options for WebGPU initialization
|
|
17
|
-
*/
|
|
18
|
-
struct WebGPUConfig {
|
|
19
|
-
/// Enable WebGPU feature
|
|
20
|
-
bool enabled = false;
|
|
21
|
-
|
|
22
|
-
/// Enable API validation in debug builds
|
|
23
|
-
bool validateAPI = true;
|
|
24
|
-
|
|
25
|
-
/// Enable verbose logging for debugging
|
|
26
|
-
bool verbose = false;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @brief WebGPU Resource Manager
|
|
31
|
-
*
|
|
32
|
-
* Manages GPU resources and provides access to WebGPU API.
|
|
33
|
-
* Uses handle-based resource management to support JSON-RPC communication.
|
|
34
|
-
*/
|
|
35
|
-
class WebGPU {
|
|
36
|
-
public:
|
|
37
|
-
WebGPU();
|
|
38
|
-
~WebGPU();
|
|
39
|
-
|
|
40
|
-
// Prevent copying but allow moving
|
|
41
|
-
WebGPU(const WebGPU&) = delete;
|
|
42
|
-
WebGPU& operator=(const WebGPU&) = delete;
|
|
43
|
-
WebGPU(WebGPU&&) noexcept;
|
|
44
|
-
WebGPU& operator=(WebGPU&&) noexcept;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @brief Create a WebGPU instance with configuration
|
|
48
|
-
* @param config WebGPU configuration options
|
|
49
|
-
* @return New WebGPU instance
|
|
50
|
-
*/
|
|
51
|
-
static WebGPU create(const WebGPUConfig& config);
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @brief Initialize the WebGPU subsystem
|
|
55
|
-
* @return true if initialization successful, false otherwise
|
|
56
|
-
*/
|
|
57
|
-
bool initialize();
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @brief Destroy all GPU resources and shut down WebGPU
|
|
61
|
-
*/
|
|
62
|
-
void destroy();
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @brief Check if WebGPU is initialized and available
|
|
66
|
-
* @return true if WebGPU is ready to use
|
|
67
|
-
*/
|
|
68
|
-
bool isAvailable() const;
|
|
69
|
-
|
|
70
|
-
// ========================================================================
|
|
71
|
-
// Adapter API
|
|
72
|
-
// ========================================================================
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @brief Request a GPU adapter with specified options
|
|
76
|
-
* @param options JSON string with request options (e.g., power preference)
|
|
77
|
-
* @return JSON string with adapter info and handle, or empty string if failed
|
|
78
|
-
*/
|
|
79
|
-
std::string requestAdapter(const std::string& options);
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @brief Get all available GPU adapters
|
|
83
|
-
* @return JSON string with array of adapters
|
|
84
|
-
*/
|
|
85
|
-
std::string getAdapters();
|
|
86
|
-
|
|
87
|
-
// ========================================================================
|
|
88
|
-
// Device API
|
|
89
|
-
// ========================================================================
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @brief Request a logical GPU device from an adapter
|
|
93
|
-
* @param adapterId Adapter handle (from requestAdapter)
|
|
94
|
-
* @param descriptor JSON string with device descriptor
|
|
95
|
-
* @return JSON string with device info and handle, or empty string if failed
|
|
96
|
-
*/
|
|
97
|
-
std::string requestDevice(const std::string& adapterId, const std::string& descriptor);
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @brief Get device info and features
|
|
101
|
-
* @param deviceId Device handle
|
|
102
|
-
* @return JSON string with device information
|
|
103
|
-
*/
|
|
104
|
-
std::string getDeviceInfo(const std::string& deviceId);
|
|
105
|
-
|
|
106
|
-
// ========================================================================
|
|
107
|
-
// Buffer API
|
|
108
|
-
// ========================================================================
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* @brief Create a GPU buffer
|
|
112
|
-
* @param deviceId Device handle
|
|
113
|
-
* @param descriptor JSON string with buffer descriptor
|
|
114
|
-
* @return Buffer handle (string ID), or empty string if failed
|
|
115
|
-
*/
|
|
116
|
-
std::string createBuffer(const std::string& deviceId, const std::string& descriptor);
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* @brief Write data to a GPU buffer
|
|
120
|
-
* @param bufferId Buffer handle
|
|
121
|
-
* @param offset Offset in bytes
|
|
122
|
-
* @param data Raw binary data as base64 or hex string
|
|
123
|
-
* @return true if successful
|
|
124
|
-
*/
|
|
125
|
-
bool writeBuffer(const std::string& bufferId, uint32_t offset, const std::string& data);
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* @brief Map a buffer for CPU access
|
|
129
|
-
* @param bufferId Buffer handle
|
|
130
|
-
* @param mode Access mode ("read" or "write")
|
|
131
|
-
* @return true if mapping successful
|
|
132
|
-
*/
|
|
133
|
-
bool mapBuffer(const std::string& bufferId, const std::string& mode);
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @brief Unmap a previously mapped buffer
|
|
137
|
-
* @param bufferId Buffer handle
|
|
138
|
-
* @return true if unmapping successful
|
|
139
|
-
*/
|
|
140
|
-
bool unmapBuffer(const std::string& bufferId);
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* @brief Get mapped buffer data
|
|
144
|
-
* @param bufferId Buffer handle
|
|
145
|
-
* @return Data as base64 or hex string
|
|
146
|
-
*/
|
|
147
|
-
std::string getMappedBufferData(const std::string& bufferId);
|
|
148
|
-
|
|
149
|
-
// ========================================================================
|
|
150
|
-
// Texture API
|
|
151
|
-
// ========================================================================
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @brief Create a GPU texture
|
|
155
|
-
* @param deviceId Device handle
|
|
156
|
-
* @param descriptor JSON string with texture descriptor
|
|
157
|
-
* @return Texture handle, or empty string if failed
|
|
158
|
-
*/
|
|
159
|
-
std::string createTexture(const std::string& deviceId, const std::string& descriptor);
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* @brief Write data to a GPU texture
|
|
163
|
-
* @param textureId Texture handle
|
|
164
|
-
* @param descriptor JSON string with write descriptor
|
|
165
|
-
* @param data Raw texture data
|
|
166
|
-
* @return true if successful
|
|
167
|
-
*/
|
|
168
|
-
bool writeTexture(const std::string& textureId, const std::string& descriptor, const std::string& data);
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* @brief Create a texture view
|
|
172
|
-
* @param textureId Texture handle
|
|
173
|
-
* @param descriptor JSON string with view descriptor
|
|
174
|
-
* @return Texture view handle
|
|
175
|
-
*/
|
|
176
|
-
std::string createTextureView(const std::string& textureId, const std::string& descriptor);
|
|
177
|
-
|
|
178
|
-
// ========================================================================
|
|
179
|
-
// Sampler API
|
|
180
|
-
// ========================================================================
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* @brief Create a GPU sampler for texture sampling
|
|
184
|
-
* @param deviceId Device handle
|
|
185
|
-
* @param descriptor JSON string with sampler descriptor
|
|
186
|
-
* @return Sampler handle
|
|
187
|
-
*/
|
|
188
|
-
std::string createSampler(const std::string& deviceId, const std::string& descriptor);
|
|
189
|
-
|
|
190
|
-
// ========================================================================
|
|
191
|
-
// Shader API
|
|
192
|
-
// ========================================================================
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* @brief Create a shader module from WGSL source code
|
|
196
|
-
* @param deviceId Device handle
|
|
197
|
-
* @param wgslSource WGSL shader source code
|
|
198
|
-
* @return Shader module handle, or empty string if compilation failed
|
|
199
|
-
*/
|
|
200
|
-
std::string createShaderModule(const std::string& deviceId, const std::string& wgslSource);
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* @brief Get shader compilation errors
|
|
204
|
-
* @param shaderId Shader module handle
|
|
205
|
-
* @return Error messages as JSON string
|
|
206
|
-
*/
|
|
207
|
-
std::string getShaderErrors(const std::string& shaderId);
|
|
208
|
-
|
|
209
|
-
// ========================================================================
|
|
210
|
-
// Pipeline API
|
|
211
|
-
// ========================================================================
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* @brief Create a render pipeline
|
|
215
|
-
* @param deviceId Device handle
|
|
216
|
-
* @param descriptor JSON string with pipeline descriptor
|
|
217
|
-
* @return Pipeline handle, or empty string if failed
|
|
218
|
-
*/
|
|
219
|
-
std::string createRenderPipeline(const std::string& deviceId, const std::string& descriptor);
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* @brief Create a compute pipeline
|
|
223
|
-
* @param deviceId Device handle
|
|
224
|
-
* @param descriptor JSON string with pipeline descriptor
|
|
225
|
-
* @return Pipeline handle, or empty string if failed
|
|
226
|
-
*/
|
|
227
|
-
std::string createComputePipeline(const std::string& deviceId, const std::string& descriptor);
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* @brief Get pipeline info
|
|
231
|
-
* @param pipelineId Pipeline handle
|
|
232
|
-
* @return Pipeline information as JSON
|
|
233
|
-
*/
|
|
234
|
-
std::string getPipelineInfo(const std::string& pipelineId);
|
|
235
|
-
|
|
236
|
-
// ========================================================================
|
|
237
|
-
// Bind Group API
|
|
238
|
-
// ========================================================================
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* @brief Create a bind group layout
|
|
242
|
-
* @param deviceId Device handle
|
|
243
|
-
* @param descriptor JSON string with layout descriptor
|
|
244
|
-
* @return Layout handle
|
|
245
|
-
*/
|
|
246
|
-
std::string createBindGroupLayout(const std::string& deviceId, const std::string& descriptor);
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* @brief Create a bind group
|
|
250
|
-
* @param deviceId Device handle
|
|
251
|
-
* @param descriptor JSON string with bind group descriptor
|
|
252
|
-
* @return Bind group handle
|
|
253
|
-
*/
|
|
254
|
-
std::string createBindGroup(const std::string& deviceId, const std::string& descriptor);
|
|
255
|
-
|
|
256
|
-
// ========================================================================
|
|
257
|
-
// Surface API
|
|
258
|
-
// ========================================================================
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* @brief Create a GPU surface for rendering
|
|
262
|
-
* @param windowHandle Native window handle (HWND on Windows, NSView* on macOS, etc.)
|
|
263
|
-
* @param width Surface width
|
|
264
|
-
* @param height Surface height
|
|
265
|
-
* @return Surface handle
|
|
266
|
-
*/
|
|
267
|
-
std::string createSurface(void* windowHandle, uint32_t width, uint32_t height);
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* @brief Configure a surface
|
|
271
|
-
* @param surfaceId Surface handle
|
|
272
|
-
* @param descriptor JSON string with configuration
|
|
273
|
-
* @return true if successful
|
|
274
|
-
*/
|
|
275
|
-
bool configureSurface(const std::string& surfaceId, const std::string& descriptor);
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* @brief Resize a surface
|
|
279
|
-
* @param surfaceId Surface handle
|
|
280
|
-
* @param width New width
|
|
281
|
-
* @param height New height
|
|
282
|
-
* @return true if successful
|
|
283
|
-
*/
|
|
284
|
-
bool resizeSurface(const std::string& surfaceId, uint32_t width, uint32_t height);
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* @brief Get the next texture from the swap chain
|
|
288
|
-
* @param surfaceId Surface handle
|
|
289
|
-
* @return Texture handle for current frame
|
|
290
|
-
*/
|
|
291
|
-
std::string getNextTexture(const std::string& surfaceId);
|
|
292
|
-
|
|
293
|
-
// ========================================================================
|
|
294
|
-
// Command Encoding API
|
|
295
|
-
// ========================================================================
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* @brief Create a command encoder
|
|
299
|
-
* @param deviceId Device handle
|
|
300
|
-
* @return Command encoder handle
|
|
301
|
-
*/
|
|
302
|
-
std::string createCommandEncoder(const std::string& deviceId);
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* @brief Begin a render pass
|
|
306
|
-
* @param encoderId Command encoder handle
|
|
307
|
-
* @param descriptor JSON string with render pass descriptor
|
|
308
|
-
* @return Render pass encoder handle
|
|
309
|
-
*/
|
|
310
|
-
std::string beginRenderPass(const std::string& encoderId, const std::string& descriptor);
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* @brief End a render pass
|
|
314
|
-
* @param passId Render pass encoder handle
|
|
315
|
-
* @return true if successful
|
|
316
|
-
*/
|
|
317
|
-
bool endRenderPass(const std::string& passId);
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* @brief Set the current render pipeline
|
|
321
|
-
* @param passId Render pass encoder handle
|
|
322
|
-
* @param pipelineId Pipeline handle
|
|
323
|
-
* @return true if successful
|
|
324
|
-
*/
|
|
325
|
-
bool setRenderPipeline(const std::string& passId, const std::string& pipelineId);
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* @brief Set a bind group for rendering
|
|
329
|
-
* @param passId Render pass encoder handle
|
|
330
|
-
* @param groupIndex Bind group index
|
|
331
|
-
* @param bindGroupId Bind group handle
|
|
332
|
-
* @return true if successful
|
|
333
|
-
*/
|
|
334
|
-
bool setBindGroup(const std::string& passId, uint32_t groupIndex, const std::string& bindGroupId);
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* @brief Set vertex buffer
|
|
338
|
-
* @param passId Render pass encoder handle
|
|
339
|
-
* @param slot Vertex buffer slot
|
|
340
|
-
* @param bufferId Buffer handle
|
|
341
|
-
* @param offset Offset in buffer
|
|
342
|
-
* @return true if successful
|
|
343
|
-
*/
|
|
344
|
-
bool setVertexBuffer(const std::string& passId, uint32_t slot, const std::string& bufferId, uint64_t offset);
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* @brief Set index buffer
|
|
348
|
-
* @param passId Render pass encoder handle
|
|
349
|
-
* @param bufferId Buffer handle
|
|
350
|
-
* @param format Index format ("uint16" or "uint32")
|
|
351
|
-
* @param offset Offset in buffer
|
|
352
|
-
* @return true if successful
|
|
353
|
-
*/
|
|
354
|
-
bool setIndexBuffer(const std::string& passId, const std::string& bufferId, const std::string& format, uint64_t offset);
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* @brief Issue a draw command
|
|
358
|
-
* @param passId Render pass encoder handle
|
|
359
|
-
* @param vertexCount Number of vertices to draw
|
|
360
|
-
* @param instanceCount Number of instances
|
|
361
|
-
* @param firstVertex First vertex index
|
|
362
|
-
* @param firstInstance First instance index
|
|
363
|
-
* @return true if successful
|
|
364
|
-
*/
|
|
365
|
-
bool draw(const std::string& passId, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* @brief Issue an indexed draw command
|
|
369
|
-
* @param passId Render pass encoder handle
|
|
370
|
-
* @param indexCount Number of indices
|
|
371
|
-
* @param instanceCount Number of instances
|
|
372
|
-
* @param firstIndex First index
|
|
373
|
-
* @param baseVertex Base vertex offset
|
|
374
|
-
* @param firstInstance First instance index
|
|
375
|
-
* @return true if successful
|
|
376
|
-
*/
|
|
377
|
-
bool drawIndexed(const std::string& passId, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance);
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* @brief Finish command encoding and get the command buffer
|
|
381
|
-
* @param encoderId Command encoder handle
|
|
382
|
-
* @return Command buffer handle
|
|
383
|
-
*/
|
|
384
|
-
std::string finish(const std::string& encoderId);
|
|
385
|
-
|
|
386
|
-
// ========================================================================
|
|
387
|
-
// Queue API
|
|
388
|
-
// ========================================================================
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* @brief Submit command buffers to the GPU queue
|
|
392
|
-
* @param deviceId Device handle
|
|
393
|
-
* @param commandBufferIds JSON array of command buffer handles
|
|
394
|
-
* @return true if submission successful
|
|
395
|
-
*/
|
|
396
|
-
bool submitCommands(const std::string& deviceId, const std::string& commandBufferIds);
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* @brief Present a surface
|
|
400
|
-
* @param surfaceId Surface handle
|
|
401
|
-
* @return true if presentation successful
|
|
402
|
-
*/
|
|
403
|
-
bool presentSurface(const std::string& surfaceId);
|
|
404
|
-
|
|
405
|
-
// ========================================================================
|
|
406
|
-
// Resource Management
|
|
407
|
-
// ========================================================================
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* @brief Destroy a GPU resource
|
|
411
|
-
* @param handle Resource handle
|
|
412
|
-
* @return true if destroyed successfully
|
|
413
|
-
*/
|
|
414
|
-
bool destroyResource(const std::string& handle);
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* @brief Destroy a device and all its resources
|
|
418
|
-
* @param deviceId Device handle
|
|
419
|
-
* @return true if destroyed successfully
|
|
420
|
-
*/
|
|
421
|
-
bool destroyDevice(const std::string& deviceId);
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* @brief Get memory usage statistics
|
|
425
|
-
* @return JSON string with memory usage info
|
|
426
|
-
*/
|
|
427
|
-
std::string getMemoryStats();
|
|
428
|
-
|
|
429
|
-
private:
|
|
430
|
-
struct Impl;
|
|
431
|
-
std::shared_ptr<Impl> pImpl;
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
} // namespace plusui
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <unordered_map>
|
|
6
|
+
#include <vector>
|
|
7
|
+
#include <functional>
|
|
8
|
+
#include <optional>
|
|
9
|
+
|
|
10
|
+
namespace plusui {
|
|
11
|
+
|
|
12
|
+
// Forward declarations for WebGPU types
|
|
13
|
+
class WebGPU;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @brief Configuration options for WebGPU initialization
|
|
17
|
+
*/
|
|
18
|
+
struct WebGPUConfig {
|
|
19
|
+
/// Enable WebGPU feature
|
|
20
|
+
bool enabled = false;
|
|
21
|
+
|
|
22
|
+
/// Enable API validation in debug builds
|
|
23
|
+
bool validateAPI = true;
|
|
24
|
+
|
|
25
|
+
/// Enable verbose logging for debugging
|
|
26
|
+
bool verbose = false;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @brief WebGPU Resource Manager
|
|
31
|
+
*
|
|
32
|
+
* Manages GPU resources and provides access to WebGPU API.
|
|
33
|
+
* Uses handle-based resource management to support JSON-RPC communication.
|
|
34
|
+
*/
|
|
35
|
+
class WebGPU {
|
|
36
|
+
public:
|
|
37
|
+
WebGPU();
|
|
38
|
+
~WebGPU();
|
|
39
|
+
|
|
40
|
+
// Prevent copying but allow moving
|
|
41
|
+
WebGPU(const WebGPU&) = delete;
|
|
42
|
+
WebGPU& operator=(const WebGPU&) = delete;
|
|
43
|
+
WebGPU(WebGPU&&) noexcept;
|
|
44
|
+
WebGPU& operator=(WebGPU&&) noexcept;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @brief Create a WebGPU instance with configuration
|
|
48
|
+
* @param config WebGPU configuration options
|
|
49
|
+
* @return New WebGPU instance
|
|
50
|
+
*/
|
|
51
|
+
static WebGPU create(const WebGPUConfig& config);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @brief Initialize the WebGPU subsystem
|
|
55
|
+
* @return true if initialization successful, false otherwise
|
|
56
|
+
*/
|
|
57
|
+
bool initialize();
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @brief Destroy all GPU resources and shut down WebGPU
|
|
61
|
+
*/
|
|
62
|
+
void destroy();
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @brief Check if WebGPU is initialized and available
|
|
66
|
+
* @return true if WebGPU is ready to use
|
|
67
|
+
*/
|
|
68
|
+
bool isAvailable() const;
|
|
69
|
+
|
|
70
|
+
// ========================================================================
|
|
71
|
+
// Adapter API
|
|
72
|
+
// ========================================================================
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @brief Request a GPU adapter with specified options
|
|
76
|
+
* @param options JSON string with request options (e.g., power preference)
|
|
77
|
+
* @return JSON string with adapter info and handle, or empty string if failed
|
|
78
|
+
*/
|
|
79
|
+
std::string requestAdapter(const std::string& options);
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @brief Get all available GPU adapters
|
|
83
|
+
* @return JSON string with array of adapters
|
|
84
|
+
*/
|
|
85
|
+
std::string getAdapters();
|
|
86
|
+
|
|
87
|
+
// ========================================================================
|
|
88
|
+
// Device API
|
|
89
|
+
// ========================================================================
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @brief Request a logical GPU device from an adapter
|
|
93
|
+
* @param adapterId Adapter handle (from requestAdapter)
|
|
94
|
+
* @param descriptor JSON string with device descriptor
|
|
95
|
+
* @return JSON string with device info and handle, or empty string if failed
|
|
96
|
+
*/
|
|
97
|
+
std::string requestDevice(const std::string& adapterId, const std::string& descriptor);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @brief Get device info and features
|
|
101
|
+
* @param deviceId Device handle
|
|
102
|
+
* @return JSON string with device information
|
|
103
|
+
*/
|
|
104
|
+
std::string getDeviceInfo(const std::string& deviceId);
|
|
105
|
+
|
|
106
|
+
// ========================================================================
|
|
107
|
+
// Buffer API
|
|
108
|
+
// ========================================================================
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @brief Create a GPU buffer
|
|
112
|
+
* @param deviceId Device handle
|
|
113
|
+
* @param descriptor JSON string with buffer descriptor
|
|
114
|
+
* @return Buffer handle (string ID), or empty string if failed
|
|
115
|
+
*/
|
|
116
|
+
std::string createBuffer(const std::string& deviceId, const std::string& descriptor);
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @brief Write data to a GPU buffer
|
|
120
|
+
* @param bufferId Buffer handle
|
|
121
|
+
* @param offset Offset in bytes
|
|
122
|
+
* @param data Raw binary data as base64 or hex string
|
|
123
|
+
* @return true if successful
|
|
124
|
+
*/
|
|
125
|
+
bool writeBuffer(const std::string& bufferId, uint32_t offset, const std::string& data);
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @brief Map a buffer for CPU access
|
|
129
|
+
* @param bufferId Buffer handle
|
|
130
|
+
* @param mode Access mode ("read" or "write")
|
|
131
|
+
* @return true if mapping successful
|
|
132
|
+
*/
|
|
133
|
+
bool mapBuffer(const std::string& bufferId, const std::string& mode);
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @brief Unmap a previously mapped buffer
|
|
137
|
+
* @param bufferId Buffer handle
|
|
138
|
+
* @return true if unmapping successful
|
|
139
|
+
*/
|
|
140
|
+
bool unmapBuffer(const std::string& bufferId);
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @brief Get mapped buffer data
|
|
144
|
+
* @param bufferId Buffer handle
|
|
145
|
+
* @return Data as base64 or hex string
|
|
146
|
+
*/
|
|
147
|
+
std::string getMappedBufferData(const std::string& bufferId);
|
|
148
|
+
|
|
149
|
+
// ========================================================================
|
|
150
|
+
// Texture API
|
|
151
|
+
// ========================================================================
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @brief Create a GPU texture
|
|
155
|
+
* @param deviceId Device handle
|
|
156
|
+
* @param descriptor JSON string with texture descriptor
|
|
157
|
+
* @return Texture handle, or empty string if failed
|
|
158
|
+
*/
|
|
159
|
+
std::string createTexture(const std::string& deviceId, const std::string& descriptor);
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @brief Write data to a GPU texture
|
|
163
|
+
* @param textureId Texture handle
|
|
164
|
+
* @param descriptor JSON string with write descriptor
|
|
165
|
+
* @param data Raw texture data
|
|
166
|
+
* @return true if successful
|
|
167
|
+
*/
|
|
168
|
+
bool writeTexture(const std::string& textureId, const std::string& descriptor, const std::string& data);
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @brief Create a texture view
|
|
172
|
+
* @param textureId Texture handle
|
|
173
|
+
* @param descriptor JSON string with view descriptor
|
|
174
|
+
* @return Texture view handle
|
|
175
|
+
*/
|
|
176
|
+
std::string createTextureView(const std::string& textureId, const std::string& descriptor);
|
|
177
|
+
|
|
178
|
+
// ========================================================================
|
|
179
|
+
// Sampler API
|
|
180
|
+
// ========================================================================
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @brief Create a GPU sampler for texture sampling
|
|
184
|
+
* @param deviceId Device handle
|
|
185
|
+
* @param descriptor JSON string with sampler descriptor
|
|
186
|
+
* @return Sampler handle
|
|
187
|
+
*/
|
|
188
|
+
std::string createSampler(const std::string& deviceId, const std::string& descriptor);
|
|
189
|
+
|
|
190
|
+
// ========================================================================
|
|
191
|
+
// Shader API
|
|
192
|
+
// ========================================================================
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @brief Create a shader module from WGSL source code
|
|
196
|
+
* @param deviceId Device handle
|
|
197
|
+
* @param wgslSource WGSL shader source code
|
|
198
|
+
* @return Shader module handle, or empty string if compilation failed
|
|
199
|
+
*/
|
|
200
|
+
std::string createShaderModule(const std::string& deviceId, const std::string& wgslSource);
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @brief Get shader compilation errors
|
|
204
|
+
* @param shaderId Shader module handle
|
|
205
|
+
* @return Error messages as JSON string
|
|
206
|
+
*/
|
|
207
|
+
std::string getShaderErrors(const std::string& shaderId);
|
|
208
|
+
|
|
209
|
+
// ========================================================================
|
|
210
|
+
// Pipeline API
|
|
211
|
+
// ========================================================================
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @brief Create a render pipeline
|
|
215
|
+
* @param deviceId Device handle
|
|
216
|
+
* @param descriptor JSON string with pipeline descriptor
|
|
217
|
+
* @return Pipeline handle, or empty string if failed
|
|
218
|
+
*/
|
|
219
|
+
std::string createRenderPipeline(const std::string& deviceId, const std::string& descriptor);
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @brief Create a compute pipeline
|
|
223
|
+
* @param deviceId Device handle
|
|
224
|
+
* @param descriptor JSON string with pipeline descriptor
|
|
225
|
+
* @return Pipeline handle, or empty string if failed
|
|
226
|
+
*/
|
|
227
|
+
std::string createComputePipeline(const std::string& deviceId, const std::string& descriptor);
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @brief Get pipeline info
|
|
231
|
+
* @param pipelineId Pipeline handle
|
|
232
|
+
* @return Pipeline information as JSON
|
|
233
|
+
*/
|
|
234
|
+
std::string getPipelineInfo(const std::string& pipelineId);
|
|
235
|
+
|
|
236
|
+
// ========================================================================
|
|
237
|
+
// Bind Group API
|
|
238
|
+
// ========================================================================
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* @brief Create a bind group layout
|
|
242
|
+
* @param deviceId Device handle
|
|
243
|
+
* @param descriptor JSON string with layout descriptor
|
|
244
|
+
* @return Layout handle
|
|
245
|
+
*/
|
|
246
|
+
std::string createBindGroupLayout(const std::string& deviceId, const std::string& descriptor);
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @brief Create a bind group
|
|
250
|
+
* @param deviceId Device handle
|
|
251
|
+
* @param descriptor JSON string with bind group descriptor
|
|
252
|
+
* @return Bind group handle
|
|
253
|
+
*/
|
|
254
|
+
std::string createBindGroup(const std::string& deviceId, const std::string& descriptor);
|
|
255
|
+
|
|
256
|
+
// ========================================================================
|
|
257
|
+
// Surface API
|
|
258
|
+
// ========================================================================
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* @brief Create a GPU surface for rendering
|
|
262
|
+
* @param windowHandle Native window handle (HWND on Windows, NSView* on macOS, etc.)
|
|
263
|
+
* @param width Surface width
|
|
264
|
+
* @param height Surface height
|
|
265
|
+
* @return Surface handle
|
|
266
|
+
*/
|
|
267
|
+
std::string createSurface(void* windowHandle, uint32_t width, uint32_t height);
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @brief Configure a surface
|
|
271
|
+
* @param surfaceId Surface handle
|
|
272
|
+
* @param descriptor JSON string with configuration
|
|
273
|
+
* @return true if successful
|
|
274
|
+
*/
|
|
275
|
+
bool configureSurface(const std::string& surfaceId, const std::string& descriptor);
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @brief Resize a surface
|
|
279
|
+
* @param surfaceId Surface handle
|
|
280
|
+
* @param width New width
|
|
281
|
+
* @param height New height
|
|
282
|
+
* @return true if successful
|
|
283
|
+
*/
|
|
284
|
+
bool resizeSurface(const std::string& surfaceId, uint32_t width, uint32_t height);
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @brief Get the next texture from the swap chain
|
|
288
|
+
* @param surfaceId Surface handle
|
|
289
|
+
* @return Texture handle for current frame
|
|
290
|
+
*/
|
|
291
|
+
std::string getNextTexture(const std::string& surfaceId);
|
|
292
|
+
|
|
293
|
+
// ========================================================================
|
|
294
|
+
// Command Encoding API
|
|
295
|
+
// ========================================================================
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* @brief Create a command encoder
|
|
299
|
+
* @param deviceId Device handle
|
|
300
|
+
* @return Command encoder handle
|
|
301
|
+
*/
|
|
302
|
+
std::string createCommandEncoder(const std::string& deviceId);
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* @brief Begin a render pass
|
|
306
|
+
* @param encoderId Command encoder handle
|
|
307
|
+
* @param descriptor JSON string with render pass descriptor
|
|
308
|
+
* @return Render pass encoder handle
|
|
309
|
+
*/
|
|
310
|
+
std::string beginRenderPass(const std::string& encoderId, const std::string& descriptor);
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* @brief End a render pass
|
|
314
|
+
* @param passId Render pass encoder handle
|
|
315
|
+
* @return true if successful
|
|
316
|
+
*/
|
|
317
|
+
bool endRenderPass(const std::string& passId);
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* @brief Set the current render pipeline
|
|
321
|
+
* @param passId Render pass encoder handle
|
|
322
|
+
* @param pipelineId Pipeline handle
|
|
323
|
+
* @return true if successful
|
|
324
|
+
*/
|
|
325
|
+
bool setRenderPipeline(const std::string& passId, const std::string& pipelineId);
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* @brief Set a bind group for rendering
|
|
329
|
+
* @param passId Render pass encoder handle
|
|
330
|
+
* @param groupIndex Bind group index
|
|
331
|
+
* @param bindGroupId Bind group handle
|
|
332
|
+
* @return true if successful
|
|
333
|
+
*/
|
|
334
|
+
bool setBindGroup(const std::string& passId, uint32_t groupIndex, const std::string& bindGroupId);
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* @brief Set vertex buffer
|
|
338
|
+
* @param passId Render pass encoder handle
|
|
339
|
+
* @param slot Vertex buffer slot
|
|
340
|
+
* @param bufferId Buffer handle
|
|
341
|
+
* @param offset Offset in buffer
|
|
342
|
+
* @return true if successful
|
|
343
|
+
*/
|
|
344
|
+
bool setVertexBuffer(const std::string& passId, uint32_t slot, const std::string& bufferId, uint64_t offset);
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* @brief Set index buffer
|
|
348
|
+
* @param passId Render pass encoder handle
|
|
349
|
+
* @param bufferId Buffer handle
|
|
350
|
+
* @param format Index format ("uint16" or "uint32")
|
|
351
|
+
* @param offset Offset in buffer
|
|
352
|
+
* @return true if successful
|
|
353
|
+
*/
|
|
354
|
+
bool setIndexBuffer(const std::string& passId, const std::string& bufferId, const std::string& format, uint64_t offset);
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* @brief Issue a draw command
|
|
358
|
+
* @param passId Render pass encoder handle
|
|
359
|
+
* @param vertexCount Number of vertices to draw
|
|
360
|
+
* @param instanceCount Number of instances
|
|
361
|
+
* @param firstVertex First vertex index
|
|
362
|
+
* @param firstInstance First instance index
|
|
363
|
+
* @return true if successful
|
|
364
|
+
*/
|
|
365
|
+
bool draw(const std::string& passId, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* @brief Issue an indexed draw command
|
|
369
|
+
* @param passId Render pass encoder handle
|
|
370
|
+
* @param indexCount Number of indices
|
|
371
|
+
* @param instanceCount Number of instances
|
|
372
|
+
* @param firstIndex First index
|
|
373
|
+
* @param baseVertex Base vertex offset
|
|
374
|
+
* @param firstInstance First instance index
|
|
375
|
+
* @return true if successful
|
|
376
|
+
*/
|
|
377
|
+
bool drawIndexed(const std::string& passId, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance);
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* @brief Finish command encoding and get the command buffer
|
|
381
|
+
* @param encoderId Command encoder handle
|
|
382
|
+
* @return Command buffer handle
|
|
383
|
+
*/
|
|
384
|
+
std::string finish(const std::string& encoderId);
|
|
385
|
+
|
|
386
|
+
// ========================================================================
|
|
387
|
+
// Queue API
|
|
388
|
+
// ========================================================================
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* @brief Submit command buffers to the GPU queue
|
|
392
|
+
* @param deviceId Device handle
|
|
393
|
+
* @param commandBufferIds JSON array of command buffer handles
|
|
394
|
+
* @return true if submission successful
|
|
395
|
+
*/
|
|
396
|
+
bool submitCommands(const std::string& deviceId, const std::string& commandBufferIds);
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* @brief Present a surface
|
|
400
|
+
* @param surfaceId Surface handle
|
|
401
|
+
* @return true if presentation successful
|
|
402
|
+
*/
|
|
403
|
+
bool presentSurface(const std::string& surfaceId);
|
|
404
|
+
|
|
405
|
+
// ========================================================================
|
|
406
|
+
// Resource Management
|
|
407
|
+
// ========================================================================
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* @brief Destroy a GPU resource
|
|
411
|
+
* @param handle Resource handle
|
|
412
|
+
* @return true if destroyed successfully
|
|
413
|
+
*/
|
|
414
|
+
bool destroyResource(const std::string& handle);
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* @brief Destroy a device and all its resources
|
|
418
|
+
* @param deviceId Device handle
|
|
419
|
+
* @return true if destroyed successfully
|
|
420
|
+
*/
|
|
421
|
+
bool destroyDevice(const std::string& deviceId);
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* @brief Get memory usage statistics
|
|
425
|
+
* @return JSON string with memory usage info
|
|
426
|
+
*/
|
|
427
|
+
std::string getMemoryStats();
|
|
428
|
+
|
|
429
|
+
private:
|
|
430
|
+
struct Impl;
|
|
431
|
+
std::shared_ptr<Impl> pImpl;
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
} // namespace plusui
|