xbintsc 0.6.13 → 0.6.17

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.
Files changed (79) hide show
  1. package/dist/src/cli/help.d.ts +1 -1
  2. package/dist/src/driver/version.d.ts +1 -1
  3. package/dist/src/driver/version.js +1 -1
  4. package/dist/src/extensions/gui/features.d.ts +2 -0
  5. package/dist/src/extensions/gui/features.js +24 -0
  6. package/dist/src/extensions/gui/features.js.map +1 -1
  7. package/dist/src/extensions/gui/index.js +39 -0
  8. package/dist/src/extensions/gui/index.js.map +1 -1
  9. package/dist/tests/e2e/gui-example-pelican3d.test.d.ts +6 -4
  10. package/dist/tests/e2e/gui-example-pelican3d.test.js +103 -44
  11. package/dist/tests/e2e/gui-example-pelican3d.test.js.map +1 -1
  12. package/dist/tests/e2e/gui-example-webgpu.test.d.ts +9 -0
  13. package/dist/tests/e2e/gui-example-webgpu.test.js +59 -0
  14. package/dist/tests/e2e/gui-example-webgpu.test.js.map +1 -0
  15. package/dist/tests/e2e/gui-helpers.d.ts +1 -1
  16. package/dist/tests/e2e/gui-webgpu.test.d.ts +11 -0
  17. package/dist/tests/e2e/gui-webgpu.test.js +402 -0
  18. package/dist/tests/e2e/gui-webgpu.test.js.map +1 -0
  19. package/dist/tests/extensions/gui-features.test.js +18 -1
  20. package/dist/tests/extensions/gui-features.test.js.map +1 -1
  21. package/doc/ai/extensions.md +7 -1
  22. package/doc/ai/zh-CN/extensions.md +6 -1
  23. package/doc/gui/webgpu.md +121 -0
  24. package/doc/gui.md +12 -1
  25. package/doc/zh-CN/gui/webgpu.md +111 -0
  26. package/doc/zh-CN/gui.md +10 -1
  27. package/llms.txt +1 -0
  28. package/package.json +7 -7
  29. package/runtime/ext_gui/browser.cpp +10 -0
  30. package/runtime/ext_gui/dom_api_canvas.cpp +21 -0
  31. package/runtime/ext_gui/dom_api_canvas_extra.cpp +61 -0
  32. package/runtime/ext_gui/gpu_feature.cpp +2 -0
  33. package/runtime/ext_gui/gpu_shader_api.h +6 -0
  34. package/runtime/ext_gui/gui_canvas.cpp +18 -0
  35. package/runtime/ext_gui/renderer_image.cpp +6 -0
  36. package/runtime/ext_gui/webgl_glsl.h +8 -0
  37. package/runtime/ext_gui/webgl_glsl_compile.cpp +11 -5
  38. package/runtime/ext_gui/webgl_msl.cpp +20 -9
  39. package/runtime/ext_gui/webgl_msl.h +4 -0
  40. package/runtime/ext_gui/webgpu.h +371 -0
  41. package/runtime/ext_gui/webgpu_api.h +42 -0
  42. package/runtime/ext_gui/webgpu_bindings.cpp +364 -0
  43. package/runtime/ext_gui/webgpu_bindings.h +59 -0
  44. package/runtime/ext_gui/webgpu_bridge.c +21 -0
  45. package/runtime/ext_gui/webgpu_buffer.cpp +293 -0
  46. package/runtime/ext_gui/webgpu_canvas.cpp +305 -0
  47. package/runtime/ext_gui/webgpu_command.cpp +510 -0
  48. package/runtime/ext_gui/webgpu_compute_pass.cpp +138 -0
  49. package/runtime/ext_gui/webgpu_convert.cpp +309 -0
  50. package/runtime/ext_gui/webgpu_device.cpp +370 -0
  51. package/runtime/ext_gui/webgpu_feature.cpp +74 -0
  52. package/runtime/ext_gui/webgpu_objects.cpp +125 -0
  53. package/runtime/ext_gui/webgpu_pass.cpp +295 -0
  54. package/runtime/ext_gui/webgpu_pass.h +33 -0
  55. package/runtime/ext_gui/webgpu_pipeline.cpp +463 -0
  56. package/runtime/ext_gui/webgpu_queue.cpp +222 -0
  57. package/runtime/ext_gui/webgpu_render_pass.cpp +417 -0
  58. package/runtime/ext_gui/webgpu_resources.cpp +315 -0
  59. package/runtime/ext_gui/webgpu_shader.cpp +242 -0
  60. package/runtime/ext_gui/wgsl.h +99 -0
  61. package/runtime/ext_gui/wgsl_api.cpp +137 -0
  62. package/runtime/ext_gui/wgsl_ast.h +233 -0
  63. package/runtime/ext_gui/wgsl_emit.cpp +452 -0
  64. package/runtime/ext_gui/wgsl_emit.h +128 -0
  65. package/runtime/ext_gui/wgsl_emit_call.cpp +281 -0
  66. package/runtime/ext_gui/wgsl_emit_expr.cpp +192 -0
  67. package/runtime/ext_gui/wgsl_emit_stmt.cpp +209 -0
  68. package/runtime/ext_gui/wgsl_entry.cpp +189 -0
  69. package/runtime/ext_gui/wgsl_infer.cpp +171 -0
  70. package/runtime/ext_gui/wgsl_lexer.cpp +179 -0
  71. package/runtime/ext_gui/wgsl_lexer.h +32 -0
  72. package/runtime/ext_gui/wgsl_parse_expr.cpp +215 -0
  73. package/runtime/ext_gui/wgsl_parse_stmt.cpp +259 -0
  74. package/runtime/ext_gui/wgsl_parser.cpp +457 -0
  75. package/runtime/ext_gui/wgsl_parser.h +77 -0
  76. package/runtime/ext_gui/wgsl_type.cpp +232 -0
  77. package/src/driver/version.ts +1 -1
  78. package/src/extensions/gui/features.ts +24 -0
  79. package/src/extensions/gui/index.ts +39 -0
@@ -25,8 +25,8 @@
25
25
 
26
26
  namespace xtgui {
27
27
 
28
- bool cross_compile_msl(const std::vector<uint32_t> &spirv, bool fragment,
29
- std::string *source, std::string *entry, std::string *log) {
28
+ bool cross_compile_msl_stage(const std::vector<uint32_t> &spirv, int stage,
29
+ std::string *source, std::string *entry, std::string *log) {
30
30
  if (source == nullptr || entry == nullptr || log == nullptr) return false;
31
31
  source->clear();
32
32
  entry->clear();
@@ -55,11 +55,12 @@ bool cross_compile_msl(const std::vector<uint32_t> &spirv, bool fragment,
55
55
  * one shows what SPIRV-Cross handed the Metal backend, which is where a
56
56
  * backend-only sampling difference (depth/comparison samplers) shows up. */
57
57
  if (getenv("XT_WEBGL_DUMP_MSL") != nullptr) {
58
- fprintf(stderr, "--- MSL %s ---\n%s\n---\n", fragment ? "fragment" : "vertex",
59
- source->c_str());
58
+ fprintf(stderr, "--- MSL stage %d ---\n%s\n---\n", stage, source->c_str());
60
59
  }
61
- *entry = compiler.get_cleansed_entry_point_name(
62
- "main", fragment ? spv::ExecutionModelFragment : spv::ExecutionModelVertex);
60
+ spv::ExecutionModel model = spv::ExecutionModelVertex;
61
+ if (stage == 1) model = spv::ExecutionModelFragment;
62
+ else if (stage == 2) model = spv::ExecutionModelGLCompute;
63
+ *entry = compiler.get_cleansed_entry_point_name("main", model);
63
64
  if (entry->empty()) {
64
65
  *log = "MSL entry point vanished during translation";
65
66
  source->clear();
@@ -79,6 +80,11 @@ bool cross_compile_msl(const std::vector<uint32_t> &spirv, bool fragment,
79
80
  }
80
81
  }
81
82
 
83
+ bool cross_compile_msl(const std::vector<uint32_t> &spirv, bool fragment,
84
+ std::string *source, std::string *entry, std::string *log) {
85
+ return cross_compile_msl_stage(spirv, fragment ? 1 : 0, source, entry, log);
86
+ }
87
+
82
88
  } // namespace xtgui
83
89
 
84
90
  #else /* !__APPLE__ */
@@ -92,16 +98,21 @@ namespace xtgui {
92
98
  * this; it exists so the callers keep one unconditional branch and a device that
93
99
  * ever did advertise MSL fails with an actionable log instead of a wrong shader.
94
100
  */
95
- bool cross_compile_msl(const std::vector<uint32_t> &spirv, bool fragment,
96
- std::string *source, std::string *entry, std::string *log) {
101
+ bool cross_compile_msl_stage(const std::vector<uint32_t> &spirv, int stage,
102
+ std::string *source, std::string *entry, std::string *log) {
97
103
  (void)spirv;
98
- (void)fragment;
104
+ (void)stage;
99
105
  source->clear();
100
106
  entry->clear();
101
107
  *log = "this build has no MSL backend (SPIRV-Cross is macOS-only)";
102
108
  return false;
103
109
  }
104
110
 
111
+ bool cross_compile_msl(const std::vector<uint32_t> &spirv, bool fragment,
112
+ std::string *source, std::string *entry, std::string *log) {
113
+ return cross_compile_msl_stage(spirv, fragment ? 1 : 0, source, entry, log);
114
+ }
115
+
105
116
  } // namespace xtgui
106
117
 
107
118
  #endif /* __APPLE__ */
@@ -34,6 +34,10 @@ namespace xtgui {
34
34
  bool cross_compile_msl(const std::vector<uint32_t> &spirv, bool fragment,
35
35
  std::string *source, std::string *entry, std::string *log);
36
36
 
37
+ /** Stage-explicit form: 0 = vertex, 1 = fragment, 2 = compute. */
38
+ bool cross_compile_msl_stage(const std::vector<uint32_t> &spirv, int stage,
39
+ std::string *source, std::string *entry, std::string *log);
40
+
37
41
  } // namespace xtgui
38
42
 
39
43
  #endif /* XT_GUI_WEBGL_MSL_H */
@@ -0,0 +1,371 @@
1
+ /*
2
+ * xbintsc GUI engine — WebGPU object model.
3
+ *
4
+ * The engine's GPU device (SDL_GPU, shared with the HTML compositor) backs the
5
+ * `navigator.gpu` surface: adapters, devices, queues, buffers, textures,
6
+ * samplers, shader modules, bind groups, pipelines, command encoders and the
7
+ * `<canvas>` context. Objects live in one registry keyed by an integer id; the
8
+ * JavaScript handle only carries that id, so a handle can be validated against
9
+ * its kind before any method runs.
10
+ */
11
+ #ifndef XT_GUI_WEBGPU_H
12
+ #define XT_GUI_WEBGPU_H
13
+
14
+ #include <cstdint>
15
+ #include <map>
16
+ #include <memory>
17
+ #include <string>
18
+ #include <unordered_map>
19
+ #include <vector>
20
+
21
+ #include "gui_engine.h"
22
+ #include "wgsl.h"
23
+
24
+ namespace xtgui {
25
+ namespace webgpu {
26
+
27
+ enum class Kind : int {
28
+ Gpu = 1,
29
+ Adapter,
30
+ Device,
31
+ Queue,
32
+ Buffer,
33
+ Texture,
34
+ TextureView,
35
+ Sampler,
36
+ ShaderModule,
37
+ BindGroupLayout,
38
+ PipelineLayout,
39
+ BindGroup,
40
+ RenderPipeline,
41
+ ComputePipeline,
42
+ CommandEncoder,
43
+ CommandBuffer,
44
+ RenderPassEncoder,
45
+ ComputePassEncoder,
46
+ RenderBundleEncoder,
47
+ RenderBundle,
48
+ QuerySet,
49
+ CanvasContext
50
+ };
51
+
52
+ struct Object {
53
+ Kind kind = Kind::Gpu;
54
+ uint32_t id = 0;
55
+ uint32_t device_id = 0;
56
+ std::string label;
57
+ virtual ~Object() = default;
58
+ };
59
+
60
+ /** `pushErrorScope` / `popErrorScope` bookkeeping. */
61
+ struct ErrorScope {
62
+ int filter = 0;
63
+ bool filled = false;
64
+ int kind = 0;
65
+ std::string message;
66
+ };
67
+
68
+ struct Device : Object {
69
+ std::vector<ErrorScope> scopes;
70
+ bool destroyed = false;
71
+ bool lost = false;
72
+ /** The JS device, rooted so uncaptured-error listeners stay reachable. */
73
+ xt_value js = XT_UNDEFINED;
74
+ /** `device.lost`: created with the device, settled by `destroy()`. */
75
+ xt_value lost_promise = XT_UNDEFINED;
76
+ xt_value lost_resolve = XT_UNDEFINED;
77
+ std::string lost_reason;
78
+ /** Lazily created resources used when a binding is missing. */
79
+ SDL_GPUTexture *fallback_texture = nullptr;
80
+ SDL_GPUSampler *fallback_sampler = nullptr;
81
+ };
82
+
83
+ struct Buffer : Object {
84
+ uint64_t size = 0;
85
+ uint32_t usage = 0;
86
+ SDL_GPUBuffer *gpu = nullptr;
87
+ bool has_gpu = false;
88
+ /** CPU mirror for buffers used as uniform buffers (SDL pushes them by value). */
89
+ bool has_shadow = false;
90
+ std::vector<uint8_t> shadow;
91
+ int map_state = 0; // 0 unmapped, 1 pending, 2 mapped
92
+ int map_mode = 0; // 1 READ, 2 WRITE
93
+ bool destroyed = false;
94
+ std::vector<uint8_t> mapped;
95
+ xt_value mapped_array = XT_UNDEFINED;
96
+ uint64_t mapped_offset = 0;
97
+ uint64_t mapped_size = 0;
98
+ };
99
+
100
+ struct Texture : Object {
101
+ SDL_GPUTexture *gpu = nullptr;
102
+ SDL_GPUTextureFormat format = SDL_GPU_TEXTUREFORMAT_INVALID;
103
+ uint32_t width = 0;
104
+ uint32_t height = 0;
105
+ uint32_t depth = 1;
106
+ uint32_t mips = 1;
107
+ uint32_t samples = 1;
108
+ uint32_t usage = 0;
109
+ std::string dimension = "2d";
110
+ /** Non-zero for a `<canvas>` backbuffer: the compositor samples this. */
111
+ uint64_t canvas_id = 0;
112
+ bool external = false;
113
+ bool destroyed = false;
114
+ };
115
+
116
+ struct TextureView : Object {
117
+ uint32_t texture = 0;
118
+ };
119
+
120
+ struct Sampler : Object {
121
+ SDL_GPUSampler *gpu = nullptr;
122
+ bool compare = false;
123
+ };
124
+
125
+ struct ShaderModule : Object {
126
+ std::string source;
127
+ bool valid = true;
128
+ std::string error;
129
+ int error_line = 0;
130
+ int error_column = 0;
131
+ /** Translations keyed by `<stage>:<entry>`; the GLSL and binding layout are
132
+ * produced once per entry point. */
133
+ std::map<std::string, wgsl::StageCode> stages;
134
+ };
135
+
136
+ struct LayoutEntry {
137
+ int binding = 0;
138
+ int visibility = 0; // 1 vertex, 2 fragment, 4 compute
139
+ std::string type; // buffer, texture, sampler, storage-texture
140
+ std::string buffer_type; // uniform, storage, read-only-storage
141
+ bool has_dynamic_offset = false;
142
+ uint64_t min_binding_size = 0;
143
+ };
144
+
145
+ struct BindGroupLayout : Object {
146
+ std::vector<LayoutEntry> entries;
147
+ };
148
+
149
+ struct PipelineLayout : Object {
150
+ std::vector<uint32_t> layouts;
151
+ };
152
+
153
+ struct BindGroupEntry {
154
+ int binding = 0;
155
+ uint32_t buffer = 0;
156
+ uint32_t sampler = 0;
157
+ uint32_t view = 0;
158
+ uint64_t offset = 0;
159
+ uint64_t size = 0;
160
+ };
161
+
162
+ struct BindGroup : Object {
163
+ uint32_t layout = 0;
164
+ std::vector<BindGroupEntry> entries;
165
+
166
+ const BindGroupEntry *find(int binding) const {
167
+ for (const BindGroupEntry &entry : entries) {
168
+ if (entry.binding == binding) return &entry;
169
+ }
170
+ return nullptr;
171
+ }
172
+ };
173
+
174
+ /** One compiled SDL shader stage plus the binding layout of its GLSL. */
175
+ struct StageResources {
176
+ wgsl::StageCode code;
177
+ SDL_GPUShader *shader = nullptr;
178
+ /** SPIR-V words and, on Metal, the MSL text the device consumes. */
179
+ std::vector<uint32_t> spirv;
180
+ std::string msl;
181
+ SDL_GPUShaderFormat format = SDL_GPU_SHADERFORMAT_INVALID;
182
+ std::string entry = "main";
183
+ };
184
+
185
+ struct RenderPipeline : Object {
186
+ SDL_GPUGraphicsPipeline *gpu = nullptr;
187
+ uint32_t layout = 0;
188
+ StageResources vertex;
189
+ StageResources fragment;
190
+ bool has_fragment = false;
191
+ bool valid = true;
192
+ };
193
+
194
+ struct ComputePipeline : Object {
195
+ SDL_GPUComputePipeline *gpu = nullptr;
196
+ uint32_t layout = 0;
197
+ StageResources stage;
198
+ uint32_t workgroup[3] = {1, 1, 1};
199
+ bool valid = true;
200
+ };
201
+
202
+ struct QuerySet : Object {
203
+ int type = 0; // 0 occlusion, 1 timestamp
204
+ uint32_t count = 0;
205
+ };
206
+
207
+ struct CommandEncoder : Object {
208
+ SDL_GPUCommandBuffer *cmd = nullptr;
209
+ bool finished = false;
210
+ };
211
+
212
+ struct CommandBuffer : Object {
213
+ SDL_GPUCommandBuffer *cmd = nullptr;
214
+ };
215
+
216
+ struct BindGroupSlot {
217
+ uint32_t group = 0;
218
+ std::vector<uint32_t> dynamic_offsets;
219
+ };
220
+
221
+ struct RenderPassEncoder : Object {
222
+ uint32_t encoder = 0;
223
+ SDL_GPURenderPass *pass = nullptr;
224
+ bool ended = false;
225
+ uint32_t pipeline = 0;
226
+ std::map<int, BindGroupSlot> groups;
227
+ uint32_t vertex_buffers[16] = {0};
228
+ uint64_t vertex_offsets[16] = {0};
229
+ uint32_t index_buffer = 0;
230
+ uint64_t index_offset = 0;
231
+ int index_format = 0; // 16 or 32
232
+ };
233
+
234
+ struct ComputePassEncoder : Object {
235
+ uint32_t encoder = 0;
236
+ SDL_GPUComputePass *pass = nullptr;
237
+ bool begun = false;
238
+ bool ended = false;
239
+ uint32_t pipeline = 0;
240
+ std::map<int, BindGroupSlot> groups;
241
+ };
242
+
243
+ struct RenderBundleEncoder : Object {
244
+ struct Command {
245
+ int kind = 0; // 1 pipeline, 2 group, 3 vertex, 4 index, 5 draw, 6 draw-indexed
246
+ uint32_t object = 0;
247
+ int slot = 0;
248
+ uint64_t offset = 0;
249
+ uint32_t count = 0;
250
+ uint32_t instances = 0;
251
+ uint32_t first = 0;
252
+ std::vector<uint32_t> dynamic_offsets;
253
+ };
254
+ std::vector<Command> commands;
255
+ bool finished = false;
256
+ };
257
+
258
+ struct RenderBundle : Object {
259
+ std::vector<RenderBundleEncoder::Command> commands;
260
+ };
261
+
262
+ struct CanvasContext : Object {
263
+ uint64_t canvas_id = 0;
264
+ uint32_t device = 0;
265
+ uint32_t texture = 0;
266
+ uint32_t width = 300;
267
+ uint32_t height = 150;
268
+ bool configured = false;
269
+ SDL_GPUTextureFormat format = SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM;
270
+ std::string format_name = "bgra8unorm";
271
+ uint32_t usage = 0;
272
+ std::string alpha_mode = "opaque";
273
+ xt_value canvas_js = XT_UNDEFINED;
274
+ };
275
+
276
+ /* -- object registry (webgpu_objects.cpp) --------------------------------- */
277
+
278
+ uint32_t add_object(std::shared_ptr<Object> object);
279
+ std::shared_ptr<Object> get_object(uint32_t id, Kind kind);
280
+ std::shared_ptr<Object> get_object(uint32_t id);
281
+ void remove_object(uint32_t id);
282
+ void device_children(uint32_t device_id, std::vector<uint32_t> *out);
283
+
284
+ /* -- errors and queue state ----------------------------------------------- */
285
+
286
+ enum class ErrorKind { Validation = 0, OutOfMemory = 1, Internal = 2 };
287
+ void record_error(Device &device, ErrorKind kind, const std::string &message);
288
+ xt_value make_error(ErrorKind kind, const std::string &message);
289
+ xt_value make_device_lost(const std::string &reason);
290
+
291
+ /** The single SDL_GPU device the GUI and WebGPU share, or null. */
292
+ SDL_GPUDevice *gpu_device();
293
+
294
+ /* -- feature entry points (webgpu_feature.cpp) ---------------------------- */
295
+
296
+ xt_value navigator_gpu();
297
+ xt_value host_type(const std::string &name);
298
+ xt_value context_proto();
299
+ xt_value context_handle(xt_value self, uint32_t id);
300
+ bool canvas_context(XtGuiWindow *win, const void *node, uint32_t *out_id);
301
+ bool canvas_find(XtGuiWindow *win, const void *node, uint32_t *out_id);
302
+ void canvas_forget(XtGuiWindow *win, const void *node);
303
+ void canvas_shutdown(XtGuiWindow *win);
304
+ void canvas_resize(uint32_t id, int width, int height);
305
+ void *canvas_color_texture(uint64_t canvas_id);
306
+ bool canvas_info(uint32_t id, float *width, float *height, uint64_t *canvas_id);
307
+
308
+ /* -- conversion helpers (webgpu_convert.cpp) ------------------------------ */
309
+
310
+ struct Convert {
311
+ static bool texture_format(const std::string &name, SDL_GPUTextureFormat *out);
312
+ static const char *texture_format_name(SDL_GPUTextureFormat format);
313
+ static bool vertex_format(const std::string &name, SDL_GPUVertexElementFormat *out);
314
+ static SDL_GPUPrimitiveType topology(const std::string &name);
315
+ static SDL_GPUCompareOp compare(const std::string &name);
316
+ static SDL_GPUBlendFactor blend_factor(const std::string &name);
317
+ static SDL_GPUBlendOp blend_op(const std::string &name);
318
+ static SDL_GPUSamplerAddressMode address_mode(const std::string &name);
319
+ static SDL_GPUFilter filter(const std::string &name);
320
+ static SDL_GPUSamplerMipmapMode mipmap_mode(const std::string &name);
321
+ static uint32_t texture_usage(uint32_t usage, SDL_GPUTextureFormat format);
322
+ static uint32_t bytes_per_pixel(SDL_GPUTextureFormat format);
323
+ static bool is_depth_format(SDL_GPUTextureFormat format);
324
+ };
325
+
326
+ /* -- binding descriptors -------------------------------------------------- */
327
+
328
+ std::string arg_string(int argc, xt_value *argv, int index);
329
+ double arg_number(int argc, xt_value *argv, int index);
330
+ uint64_t arg_u64(int argc, xt_value *argv, int index);
331
+ bool arg_bool(int argc, xt_value *argv, int index, bool fallback);
332
+ xt_value arg_object(int argc, xt_value *argv, int index);
333
+ std::string prop_string(xt_value object, const char *name);
334
+ double prop_number(xt_value object, const char *name, double fallback);
335
+ uint64_t prop_u64(xt_value object, const char *name, uint64_t fallback);
336
+ bool prop_bool(xt_value object, const char *name, bool fallback);
337
+ std::string prop_name(xt_value object, const char *name);
338
+ xt_value prop_object(xt_value object, const char *name);
339
+ bool read_bytes(xt_value value, std::vector<uint8_t> *out);
340
+
341
+ /** The JS handle for a native object; `proto` is the interface prototype. */
342
+ xt_value wrap_object(const std::shared_ptr<Object> &object, xt_value proto);
343
+ xt_value queue_object(uint32_t device_id);
344
+ xt_value device_object(uint32_t device_id);
345
+
346
+ /* -- pipeline/shader helpers (webgpu_shader.cpp) -------------------------- */
347
+
348
+ bool translate_stage(Device &device, ShaderModule &module, const std::string &entry, int stage,
349
+ wgsl::StageCode *code, std::string *error);
350
+ bool compile_shader(Device &device, ShaderModule &module, const std::string &entry, int stage,
351
+ StageResources *resources, std::string *error);
352
+ /** Compile without creating an SDL shader (compute pipelines take the code). */
353
+ bool compile_shader_code(Device &device, ShaderModule &module, const std::string &entry, int stage,
354
+ StageResources *resources, std::string *error);
355
+ /** One implicit bind-group layout per group index used by the stages. */
356
+ std::vector<uint32_t> make_auto_layouts(
357
+ Device &device, const std::vector<std::pair<int, wgsl::StageCode>> &stages);
358
+ bool build_bind_group_layout(Device &device, xt_value descriptor,
359
+ const std::shared_ptr<BindGroupLayout> &layout, std::string *error);
360
+
361
+ /* -- pass helpers shared with bundles ------------------------------------- */
362
+
363
+ struct PassState {
364
+ RenderPassEncoder *pass = nullptr;
365
+ RenderPipeline *pipeline = nullptr;
366
+ };
367
+
368
+ } // namespace webgpu
369
+ } // namespace xtgui
370
+
371
+ #endif /* XT_GUI_WEBGPU_H */
@@ -0,0 +1,42 @@
1
+ /*
2
+ * xbintsc GUI engine — optional WebGPU canvas/context bridge.
3
+ *
4
+ * The WebGPU DOM surface is large and lives behind the `webgpu` link feature.
5
+ * The engine's canvas and paint code reaches it through this table, exactly the
6
+ * way it reaches WebGL through `webgl_api.h`: without the feature the table is
7
+ * null, `getContext("webgpu")` answers null and a canvas's colour texture is
8
+ * never redirected.
9
+ */
10
+ #ifndef XT_GUI_WEBGPU_API_H
11
+ #define XT_GUI_WEBGPU_API_H
12
+
13
+ #include <cstdint>
14
+
15
+ #include "rt.h"
16
+
17
+ struct XtGuiWindow;
18
+
19
+ struct XtWebgpuApi {
20
+ /** Create/find a canvas's WebGPU context; `node` is a `xtgui::Node*`. */
21
+ bool (*canvas_get)(XtGuiWindow *win, const void *node, uint32_t *id);
22
+ /** The existing context id, or 0. */
23
+ bool (*canvas_find)(XtGuiWindow *win, const void *node, uint32_t *id);
24
+ void (*canvas_forget)(XtGuiWindow *win, const void *node);
25
+ void (*shutdown)(XtGuiWindow *win);
26
+ /** Canvas pixel size and the id the paint pipeline keys textures by. */
27
+ void (*info)(uint32_t id, float *width, float *height, uint64_t *canvas_id);
28
+ void (*resize)(uint32_t id, int width, int height);
29
+ /** Wrap a context in a DOM handle; `self` is the canvas element handle. */
30
+ xt_value (*handle)(xt_value self, uint32_t id);
31
+ xt_value (*proto)();
32
+ /** `navigator.gpu` and the `GPU…` host types/namespaces. */
33
+ xt_value (*navigator_gpu)();
34
+ xt_value (*host_type)(const char *name);
35
+ /** The colour texture of a canvas, for the paint pipeline. */
36
+ void *(*color_texture)(uint64_t canvas_id);
37
+ };
38
+
39
+ void xt_webgpu_api_install(const XtWebgpuApi *api);
40
+ const XtWebgpuApi *xt_webgpu_api();
41
+
42
+ #endif /* XT_GUI_WEBGPU_API_H */