xbintsc 0.6.13 → 0.6.18
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/dist/src/cli/help.d.ts +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/gui/features.d.ts +2 -0
- package/dist/src/extensions/gui/features.js +24 -0
- package/dist/src/extensions/gui/features.js.map +1 -1
- package/dist/src/extensions/gui/index.js +39 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/tests/e2e/gui-example-pelican3d.test.d.ts +6 -4
- package/dist/tests/e2e/gui-example-pelican3d.test.js +103 -44
- package/dist/tests/e2e/gui-example-pelican3d.test.js.map +1 -1
- package/dist/tests/e2e/gui-example-webgpu.test.d.ts +9 -0
- package/dist/tests/e2e/gui-example-webgpu.test.js +59 -0
- package/dist/tests/e2e/gui-example-webgpu.test.js.map +1 -0
- package/dist/tests/e2e/gui-helpers.d.ts +1 -1
- package/dist/tests/e2e/gui-webgpu.test.d.ts +11 -0
- package/dist/tests/e2e/gui-webgpu.test.js +402 -0
- package/dist/tests/e2e/gui-webgpu.test.js.map +1 -0
- package/dist/tests/extensions/gui-features.test.js +18 -1
- package/dist/tests/extensions/gui-features.test.js.map +1 -1
- package/doc/ai/extensions.md +7 -1
- package/doc/ai/zh-CN/extensions.md +6 -1
- package/doc/gui/webgpu.md +121 -0
- package/doc/gui.md +12 -1
- package/doc/zh-CN/gui/webgpu.md +111 -0
- package/doc/zh-CN/gui.md +10 -1
- package/llms.txt +1 -0
- package/package.json +7 -7
- package/runtime/ext_gui/browser.cpp +10 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +21 -0
- package/runtime/ext_gui/dom_api_canvas_extra.cpp +61 -0
- package/runtime/ext_gui/gpu_feature.cpp +2 -0
- package/runtime/ext_gui/gpu_shader_api.h +6 -0
- package/runtime/ext_gui/gui_canvas.cpp +18 -0
- package/runtime/ext_gui/renderer_image.cpp +6 -0
- package/runtime/ext_gui/webgl_glsl.h +8 -0
- package/runtime/ext_gui/webgl_glsl_compile.cpp +11 -5
- package/runtime/ext_gui/webgl_msl.cpp +20 -9
- package/runtime/ext_gui/webgl_msl.h +4 -0
- package/runtime/ext_gui/webgpu.h +371 -0
- package/runtime/ext_gui/webgpu_api.h +42 -0
- package/runtime/ext_gui/webgpu_bindings.cpp +364 -0
- package/runtime/ext_gui/webgpu_bindings.h +59 -0
- package/runtime/ext_gui/webgpu_bridge.c +21 -0
- package/runtime/ext_gui/webgpu_buffer.cpp +293 -0
- package/runtime/ext_gui/webgpu_canvas.cpp +305 -0
- package/runtime/ext_gui/webgpu_command.cpp +510 -0
- package/runtime/ext_gui/webgpu_compute_pass.cpp +138 -0
- package/runtime/ext_gui/webgpu_convert.cpp +313 -0
- package/runtime/ext_gui/webgpu_device.cpp +370 -0
- package/runtime/ext_gui/webgpu_feature.cpp +74 -0
- package/runtime/ext_gui/webgpu_objects.cpp +125 -0
- package/runtime/ext_gui/webgpu_pass.cpp +295 -0
- package/runtime/ext_gui/webgpu_pass.h +33 -0
- package/runtime/ext_gui/webgpu_pipeline.cpp +463 -0
- package/runtime/ext_gui/webgpu_queue.cpp +222 -0
- package/runtime/ext_gui/webgpu_render_pass.cpp +417 -0
- package/runtime/ext_gui/webgpu_resources.cpp +315 -0
- package/runtime/ext_gui/webgpu_shader.cpp +246 -0
- package/runtime/ext_gui/wgsl.h +99 -0
- package/runtime/ext_gui/wgsl_api.cpp +137 -0
- package/runtime/ext_gui/wgsl_ast.h +233 -0
- package/runtime/ext_gui/wgsl_emit.cpp +452 -0
- package/runtime/ext_gui/wgsl_emit.h +128 -0
- package/runtime/ext_gui/wgsl_emit_call.cpp +281 -0
- package/runtime/ext_gui/wgsl_emit_expr.cpp +192 -0
- package/runtime/ext_gui/wgsl_emit_stmt.cpp +209 -0
- package/runtime/ext_gui/wgsl_entry.cpp +189 -0
- package/runtime/ext_gui/wgsl_infer.cpp +171 -0
- package/runtime/ext_gui/wgsl_lexer.cpp +179 -0
- package/runtime/ext_gui/wgsl_lexer.h +32 -0
- package/runtime/ext_gui/wgsl_parse_expr.cpp +215 -0
- package/runtime/ext_gui/wgsl_parse_stmt.cpp +259 -0
- package/runtime/ext_gui/wgsl_parser.cpp +457 -0
- package/runtime/ext_gui/wgsl_parser.h +77 -0
- package/runtime/ext_gui/wgsl_type.cpp +232 -0
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/features.ts +24 -0
- package/src/extensions/gui/index.ts +39 -0
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — WebGPU command encoding.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#include <cstring>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
#include "webgpu_bindings.h"
|
|
9
|
+
#include "webgpu_pass.h"
|
|
10
|
+
|
|
11
|
+
namespace xtgui {
|
|
12
|
+
namespace webgpu {
|
|
13
|
+
namespace {
|
|
14
|
+
|
|
15
|
+
SDL_GPUCommandBuffer *encoder_cmd(CommandEncoder &encoder) {
|
|
16
|
+
if (encoder.cmd == nullptr && !encoder.finished) {
|
|
17
|
+
encoder.cmd = SDL_AcquireGPUCommandBuffer(gpu_device());
|
|
18
|
+
}
|
|
19
|
+
return encoder.cmd;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* Flush the encoder so an immediate readback/copy can run in order. */
|
|
23
|
+
void flush_encoder(CommandEncoder &encoder) {
|
|
24
|
+
if (encoder.cmd == nullptr) return;
|
|
25
|
+
SDL_SubmitGPUCommandBuffer(encoder.cmd);
|
|
26
|
+
encoder.cmd = nullptr;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
xt_value encoder_label(Object &object) { return xt_string_from_cstr(object.label.c_str()); }
|
|
30
|
+
|
|
31
|
+
xt_value value_id(xt_value value) {
|
|
32
|
+
if (!XT_IS_OBJECT(value)) return 0;
|
|
33
|
+
return (uint32_t)xt_to_number(xt_object_get_cstr(value, "__xt_webgpu_id"));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Buffer *buffer_at(xt_value value) {
|
|
37
|
+
std::shared_ptr<Object> object = get_object(value_id(value), Kind::Buffer);
|
|
38
|
+
return object == nullptr ? nullptr : static_cast<Buffer *>(object.get());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Texture *texture_at(xt_value value) {
|
|
42
|
+
std::shared_ptr<Object> object = get_object(value_id(value), Kind::Texture);
|
|
43
|
+
return object == nullptr ? nullptr : static_cast<Texture *>(object.get());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
xt_value view_id_of(xt_value view) {
|
|
47
|
+
return xt_number((double)value_id(view));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
bool read_texture_rows(Texture &texture, uint32_t mip, uint32_t x, uint32_t y, uint32_t z,
|
|
51
|
+
uint32_t width, uint32_t height, uint32_t depth, uint32_t bytes_per_row,
|
|
52
|
+
std::vector<uint8_t> *out) {
|
|
53
|
+
SDL_GPUCommandBuffer *cmd = SDL_AcquireGPUCommandBuffer(gpu_device());
|
|
54
|
+
if (cmd == nullptr) return false;
|
|
55
|
+
const uint32_t bytes_per_pixel = Convert::bytes_per_pixel(texture.format);
|
|
56
|
+
const uint64_t row_bytes = (uint64_t)width * bytes_per_pixel;
|
|
57
|
+
const uint64_t rows_per_image = height;
|
|
58
|
+
const uint64_t total = ((row_bytes + bytes_per_row - 1) / bytes_per_row) * bytes_per_row *
|
|
59
|
+
rows_per_image * depth;
|
|
60
|
+
SDL_GPUTransferBufferCreateInfo info = {};
|
|
61
|
+
info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_DOWNLOAD;
|
|
62
|
+
info.size = (Uint32)total;
|
|
63
|
+
SDL_GPUTransferBuffer *transfer = SDL_CreateGPUTransferBuffer(gpu_device(), &info);
|
|
64
|
+
if (transfer == nullptr) return false;
|
|
65
|
+
SDL_GPUCopyPass *pass = SDL_BeginGPUCopyPass(cmd);
|
|
66
|
+
SDL_GPUTextureRegion region = {};
|
|
67
|
+
region.texture = texture.gpu;
|
|
68
|
+
region.mip_level = mip;
|
|
69
|
+
region.layer = z;
|
|
70
|
+
region.x = x;
|
|
71
|
+
region.y = y;
|
|
72
|
+
region.z = 0;
|
|
73
|
+
region.w = width;
|
|
74
|
+
region.h = height;
|
|
75
|
+
region.d = depth;
|
|
76
|
+
SDL_GPUTextureTransferInfo destination = {};
|
|
77
|
+
destination.transfer_buffer = transfer;
|
|
78
|
+
destination.offset = 0;
|
|
79
|
+
destination.pixels_per_row = bytes_per_row / bytes_per_pixel;
|
|
80
|
+
destination.rows_per_layer = (Uint32)rows_per_image;
|
|
81
|
+
SDL_DownloadFromGPUTexture(pass, ®ion, &destination);
|
|
82
|
+
SDL_EndGPUCopyPass(pass);
|
|
83
|
+
SDL_GPUFence *fence = SDL_SubmitGPUCommandBufferAndAcquireFence(cmd);
|
|
84
|
+
if (fence != nullptr) {
|
|
85
|
+
SDL_GPUFence *fences[1] = {fence};
|
|
86
|
+
SDL_WaitForGPUFences(gpu_device(), true, fences, 1);
|
|
87
|
+
SDL_ReleaseGPUFence(gpu_device(), fence);
|
|
88
|
+
}
|
|
89
|
+
void *mapped = SDL_MapGPUTransferBuffer(gpu_device(), transfer, false);
|
|
90
|
+
if (mapped != nullptr) {
|
|
91
|
+
out->assign((const uint8_t *)mapped, (const uint8_t *)mapped + total);
|
|
92
|
+
SDL_UnmapGPUTransferBuffer(gpu_device(), transfer);
|
|
93
|
+
}
|
|
94
|
+
SDL_ReleaseGPUTransferBuffer(gpu_device(), transfer);
|
|
95
|
+
return mapped != nullptr;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
bool upload_texture_rows(Texture &texture, uint32_t mip, uint32_t x, uint32_t y, uint32_t z,
|
|
99
|
+
uint32_t width, uint32_t height, uint32_t depth, uint32_t bytes_per_row,
|
|
100
|
+
const std::vector<uint8_t> &data, uint64_t offset) {
|
|
101
|
+
SDL_GPUCommandBuffer *cmd = SDL_AcquireGPUCommandBuffer(gpu_device());
|
|
102
|
+
if (cmd == nullptr) return false;
|
|
103
|
+
SDL_GPUTransferBufferCreateInfo info = {};
|
|
104
|
+
info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
|
|
105
|
+
info.size = (Uint32)data.size();
|
|
106
|
+
SDL_GPUTransferBuffer *transfer = SDL_CreateGPUTransferBuffer(gpu_device(), &info);
|
|
107
|
+
if (transfer == nullptr) return false;
|
|
108
|
+
void *mapped = SDL_MapGPUTransferBuffer(gpu_device(), transfer, false);
|
|
109
|
+
if (mapped != nullptr) {
|
|
110
|
+
memcpy(mapped, data.data(), data.size());
|
|
111
|
+
SDL_UnmapGPUTransferBuffer(gpu_device(), transfer);
|
|
112
|
+
}
|
|
113
|
+
const uint32_t bytes_per_pixel = Convert::bytes_per_pixel(texture.format);
|
|
114
|
+
SDL_GPUCopyPass *pass = SDL_BeginGPUCopyPass(cmd);
|
|
115
|
+
SDL_GPUTextureTransferInfo source = {};
|
|
116
|
+
source.transfer_buffer = transfer;
|
|
117
|
+
source.offset = (Uint32)offset;
|
|
118
|
+
source.pixels_per_row = bytes_per_row / (bytes_per_pixel == 0 ? 1 : bytes_per_pixel);
|
|
119
|
+
source.rows_per_layer = height;
|
|
120
|
+
SDL_GPUTextureRegion region = {};
|
|
121
|
+
region.texture = texture.gpu;
|
|
122
|
+
region.mip_level = mip;
|
|
123
|
+
region.layer = z;
|
|
124
|
+
region.x = x;
|
|
125
|
+
region.y = y;
|
|
126
|
+
region.w = width;
|
|
127
|
+
region.h = height;
|
|
128
|
+
region.d = depth;
|
|
129
|
+
SDL_UploadToGPUTexture(pass, &source, ®ion, true);
|
|
130
|
+
SDL_EndGPUCopyPass(pass);
|
|
131
|
+
SDL_SubmitGPUCommandBuffer(cmd);
|
|
132
|
+
SDL_ReleaseGPUTransferBuffer(gpu_device(), transfer);
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
bool write_buffer_bytes(Buffer &buffer, uint64_t offset, const std::vector<uint8_t> &data) {
|
|
137
|
+
if (buffer.has_shadow && offset + data.size() <= buffer.shadow.size()) {
|
|
138
|
+
memcpy(buffer.shadow.data() + offset, data.data(), data.size());
|
|
139
|
+
}
|
|
140
|
+
if (!buffer.has_gpu || buffer.gpu == nullptr) return true;
|
|
141
|
+
SDL_GPUCommandBuffer *cmd = SDL_AcquireGPUCommandBuffer(gpu_device());
|
|
142
|
+
SDL_GPUTransferBufferCreateInfo info = {};
|
|
143
|
+
info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
|
|
144
|
+
info.size = (Uint32)data.size();
|
|
145
|
+
SDL_GPUTransferBuffer *transfer = SDL_CreateGPUTransferBuffer(gpu_device(), &info);
|
|
146
|
+
if (transfer == nullptr) return false;
|
|
147
|
+
void *mapped = SDL_MapGPUTransferBuffer(gpu_device(), transfer, false);
|
|
148
|
+
if (mapped != nullptr) {
|
|
149
|
+
memcpy(mapped, data.data(), data.size());
|
|
150
|
+
SDL_UnmapGPUTransferBuffer(gpu_device(), transfer);
|
|
151
|
+
}
|
|
152
|
+
SDL_GPUCopyPass *pass = SDL_BeginGPUCopyPass(cmd);
|
|
153
|
+
SDL_GPUTransferBufferLocation source = {};
|
|
154
|
+
source.transfer_buffer = transfer;
|
|
155
|
+
source.offset = 0;
|
|
156
|
+
SDL_GPUBufferRegion region = {};
|
|
157
|
+
region.buffer = buffer.gpu;
|
|
158
|
+
region.offset = (Uint32)offset;
|
|
159
|
+
region.size = (Uint32)data.size();
|
|
160
|
+
SDL_UploadToGPUBuffer(pass, &source, ®ion, true);
|
|
161
|
+
SDL_EndGPUCopyPass(pass);
|
|
162
|
+
SDL_SubmitGPUCommandBuffer(cmd);
|
|
163
|
+
SDL_ReleaseGPUTransferBuffer(gpu_device(), transfer);
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/* -- render pass ---------------------------------------------------------- */
|
|
168
|
+
|
|
169
|
+
xt_value begin_render_pass(Object &object, int argc, xt_value *argv) {
|
|
170
|
+
CommandEncoder &encoder = static_cast<CommandEncoder &>(object);
|
|
171
|
+
xt_value descriptor = arg_object(argc, argv, 0);
|
|
172
|
+
if (!XT_IS_OBJECT(descriptor)) {
|
|
173
|
+
throw_type_error("beginRenderPass needs a descriptor");
|
|
174
|
+
return XT_UNDEFINED;
|
|
175
|
+
}
|
|
176
|
+
if (encoder.finished) return XT_UNDEFINED;
|
|
177
|
+
std::vector<SDL_GPUColorTargetInfo> targets;
|
|
178
|
+
uint32_t target_width = 0;
|
|
179
|
+
uint32_t target_height = 0;
|
|
180
|
+
xt_value colors = prop_object(descriptor, "colorAttachments");
|
|
181
|
+
if (XT_IS_ARRAY(colors)) {
|
|
182
|
+
const uint32_t count = (uint32_t)xt_to_number(xt_array_length(colors));
|
|
183
|
+
for (uint32_t i = 0; i < count; i++) {
|
|
184
|
+
xt_value item = xt_array_get(colors, xt_number((double)i));
|
|
185
|
+
SDL_GPUColorTargetInfo target = {};
|
|
186
|
+
xt_value view = prop_object(item, "view");
|
|
187
|
+
const uint32_t view_id = (uint32_t)value_id(view);
|
|
188
|
+
std::shared_ptr<Object> view_object = get_object(view_id, Kind::TextureView);
|
|
189
|
+
if (view_object != nullptr) {
|
|
190
|
+
std::shared_ptr<Object> texture_object =
|
|
191
|
+
get_object(static_cast<TextureView *>(view_object.get())->texture, Kind::Texture);
|
|
192
|
+
if (texture_object != nullptr) {
|
|
193
|
+
Texture *native = static_cast<Texture *>(texture_object.get());
|
|
194
|
+
target.texture = native->gpu;
|
|
195
|
+
if (target_width == 0) {
|
|
196
|
+
target_width = native->width;
|
|
197
|
+
target_height = native->height;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
xt_value clear = prop_object(item, "clearValue");
|
|
202
|
+
target.clear_color.r = (float)prop_number(clear, "r", 0.0);
|
|
203
|
+
target.clear_color.g = (float)prop_number(clear, "g", 0.0);
|
|
204
|
+
target.clear_color.b = (float)prop_number(clear, "b", 0.0);
|
|
205
|
+
target.clear_color.a = (float)prop_number(clear, "a", 1.0);
|
|
206
|
+
target.load_op = prop_string(item, "loadOp") == "load" ? SDL_GPU_LOADOP_LOAD
|
|
207
|
+
: SDL_GPU_LOADOP_CLEAR;
|
|
208
|
+
target.store_op = prop_string(item, "storeOp") == "discard" ? SDL_GPU_STOREOP_DONT_CARE
|
|
209
|
+
: SDL_GPU_STOREOP_STORE;
|
|
210
|
+
xt_value resolve = prop_object(item, "resolveTarget");
|
|
211
|
+
if (XT_IS_OBJECT(resolve)) {
|
|
212
|
+
std::shared_ptr<Object> resolve_view = get_object((uint32_t)value_id(resolve),
|
|
213
|
+
Kind::TextureView);
|
|
214
|
+
if (resolve_view != nullptr) {
|
|
215
|
+
std::shared_ptr<Object> texture_object = get_object(
|
|
216
|
+
static_cast<TextureView *>(resolve_view.get())->texture, Kind::Texture);
|
|
217
|
+
if (texture_object != nullptr) {
|
|
218
|
+
target.resolve_texture = static_cast<Texture *>(texture_object.get())->gpu;
|
|
219
|
+
target.store_op = SDL_GPU_STOREOP_RESOLVE;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
target.cycle = true;
|
|
224
|
+
targets.push_back(target);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
SDL_GPUDepthStencilTargetInfo depth = {};
|
|
228
|
+
bool has_depth = false;
|
|
229
|
+
xt_value depth_value = prop_object(descriptor, "depthStencilAttachment");
|
|
230
|
+
if (XT_IS_OBJECT(depth_value)) {
|
|
231
|
+
xt_value view = prop_object(depth_value, "view");
|
|
232
|
+
std::shared_ptr<Object> view_object = get_object((uint32_t)value_id(view), Kind::TextureView);
|
|
233
|
+
if (view_object != nullptr) {
|
|
234
|
+
std::shared_ptr<Object> texture_object =
|
|
235
|
+
get_object(static_cast<TextureView *>(view_object.get())->texture, Kind::Texture);
|
|
236
|
+
if (texture_object != nullptr) {
|
|
237
|
+
depth.texture = static_cast<Texture *>(texture_object.get())->gpu;
|
|
238
|
+
has_depth = true;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
depth.clear_depth = (float)prop_number(depth_value, "depthClearValue", 1.0);
|
|
242
|
+
depth.load_op = prop_string(depth_value, "depthLoadOp") == "load" ? SDL_GPU_LOADOP_LOAD
|
|
243
|
+
: SDL_GPU_LOADOP_CLEAR;
|
|
244
|
+
depth.store_op = prop_string(depth_value, "depthStoreOp") == "discard"
|
|
245
|
+
? SDL_GPU_STOREOP_DONT_CARE
|
|
246
|
+
: SDL_GPU_STOREOP_STORE;
|
|
247
|
+
depth.clear_stencil = (Uint8)prop_u64(depth_value, "stencilClearValue", 0);
|
|
248
|
+
depth.stencil_load_op = SDL_GPU_LOADOP_CLEAR;
|
|
249
|
+
depth.stencil_store_op = SDL_GPU_STOREOP_STORE;
|
|
250
|
+
depth.cycle = true;
|
|
251
|
+
}
|
|
252
|
+
SDL_GPUCommandBuffer *cmd = encoder_cmd(encoder);
|
|
253
|
+
SDL_GPURenderPass *pass =
|
|
254
|
+
SDL_BeginGPURenderPass(cmd, targets.empty() ? nullptr : targets.data(),
|
|
255
|
+
(Uint32)targets.size(), has_depth ? &depth : nullptr);
|
|
256
|
+
if (pass == nullptr) {
|
|
257
|
+
std::shared_ptr<Device> device = device_for(encoder, nullptr);
|
|
258
|
+
if (device != nullptr) validation(*device, "beginRenderPass failed");
|
|
259
|
+
return XT_UNDEFINED;
|
|
260
|
+
}
|
|
261
|
+
if (target_width > 0 && target_height > 0) {
|
|
262
|
+
SDL_GPUViewport viewport = {};
|
|
263
|
+
viewport.w = (float)target_width;
|
|
264
|
+
viewport.h = (float)target_height;
|
|
265
|
+
viewport.min_depth = 0.0f;
|
|
266
|
+
viewport.max_depth = 1.0f;
|
|
267
|
+
SDL_SetGPUViewport(pass, &viewport);
|
|
268
|
+
SDL_Rect scissor = {};
|
|
269
|
+
scissor.w = (int)target_width;
|
|
270
|
+
scissor.h = (int)target_height;
|
|
271
|
+
SDL_SetGPUScissor(pass, &scissor);
|
|
272
|
+
}
|
|
273
|
+
auto pass_object = std::make_shared<RenderPassEncoder>();
|
|
274
|
+
pass_object->kind = Kind::RenderPassEncoder;
|
|
275
|
+
pass_object->device_id = encoder.device_id;
|
|
276
|
+
pass_object->encoder = encoder.id;
|
|
277
|
+
pass_object->pass = pass;
|
|
278
|
+
return handle_of(add_object(pass_object));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/* -- compute pass --------------------------------------------------------- */
|
|
282
|
+
|
|
283
|
+
xt_value begin_compute_pass(Object &object, int argc, xt_value *argv) {
|
|
284
|
+
(void)argc;
|
|
285
|
+
(void)argv;
|
|
286
|
+
CommandEncoder &encoder = static_cast<CommandEncoder &>(object);
|
|
287
|
+
if (encoder.finished) return XT_UNDEFINED;
|
|
288
|
+
auto pass_object = std::make_shared<ComputePassEncoder>();
|
|
289
|
+
pass_object->kind = Kind::ComputePassEncoder;
|
|
290
|
+
pass_object->device_id = encoder.device_id;
|
|
291
|
+
pass_object->encoder = encoder.id;
|
|
292
|
+
return handle_of(add_object(pass_object));
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/* -- copies --------------------------------------------------------------- */
|
|
296
|
+
|
|
297
|
+
xt_value copy_buffer_to_buffer(Object &object, int argc, xt_value *argv) {
|
|
298
|
+
CommandEncoder &encoder = static_cast<CommandEncoder &>(object);
|
|
299
|
+
Buffer *source = buffer_at(xt_arg(argc, argv, 0));
|
|
300
|
+
const uint64_t source_offset = arg_u64(argc, argv, 1);
|
|
301
|
+
Buffer *destination = buffer_at(xt_arg(argc, argv, 2));
|
|
302
|
+
const uint64_t destination_offset = arg_u64(argc, argv, 3);
|
|
303
|
+
uint64_t size = arg_u64(argc, argv, 4);
|
|
304
|
+
if (source == nullptr || destination == nullptr || size == 0) return XT_UNDEFINED;
|
|
305
|
+
if (source->has_gpu && destination->has_gpu) {
|
|
306
|
+
SDL_GPUCommandBuffer *cmd = encoder_cmd(encoder);
|
|
307
|
+
SDL_GPUCopyPass *pass = SDL_BeginGPUCopyPass(cmd);
|
|
308
|
+
SDL_GPUBufferLocation from = {};
|
|
309
|
+
from.buffer = source->gpu;
|
|
310
|
+
from.offset = (Uint32)source_offset;
|
|
311
|
+
SDL_GPUBufferLocation to = {};
|
|
312
|
+
to.buffer = destination->gpu;
|
|
313
|
+
to.offset = (Uint32)destination_offset;
|
|
314
|
+
SDL_CopyGPUBufferToBuffer(pass, &from, &to, (Uint32)size, true);
|
|
315
|
+
SDL_EndGPUCopyPass(pass);
|
|
316
|
+
return XT_UNDEFINED;
|
|
317
|
+
}
|
|
318
|
+
if (source->has_shadow && destination->has_shadow && source_offset + size <= source->shadow.size() &&
|
|
319
|
+
destination_offset + size <= destination->shadow.size()) {
|
|
320
|
+
memcpy(destination->shadow.data() + destination_offset, source->shadow.data() + source_offset,
|
|
321
|
+
(size_t)size);
|
|
322
|
+
}
|
|
323
|
+
return XT_UNDEFINED;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
xt_value copy_buffer_to_texture(Object &object, int argc, xt_value *argv) {
|
|
327
|
+
CommandEncoder &encoder = static_cast<CommandEncoder &>(object);
|
|
328
|
+
xt_value source_value = arg_object(argc, argv, 0);
|
|
329
|
+
Buffer *source = buffer_at(prop_object(source_value, "buffer"));
|
|
330
|
+
xt_value destination = arg_object(argc, argv, 1);
|
|
331
|
+
Texture *texture = texture_at(prop_object(destination, "texture"));
|
|
332
|
+
xt_value size = arg_object(argc, argv, 2);
|
|
333
|
+
if (source == nullptr || texture == nullptr) return XT_UNDEFINED;
|
|
334
|
+
const uint64_t source_offset = prop_u64(source_value, "offset", 0);
|
|
335
|
+
const uint32_t width = (uint32_t)prop_u64(size, "width", 0);
|
|
336
|
+
const uint32_t height = (uint32_t)prop_u64(size, "height", 1);
|
|
337
|
+
const uint32_t depth = (uint32_t)prop_u64(size, "depthOrArrayLayers", 1);
|
|
338
|
+
xt_value origin = prop_object(destination, "origin");
|
|
339
|
+
const uint32_t bytes_per_row = (uint32_t)prop_u64(source_value, "bytesPerRow", 0);
|
|
340
|
+
const uint32_t rows_per_image = (uint32_t)prop_u64(source_value, "rowsPerImage", 0);
|
|
341
|
+
const uint32_t row_bytes = width * Convert::bytes_per_pixel(texture->format);
|
|
342
|
+
const uint32_t stride = bytes_per_row != 0 ? bytes_per_row : row_bytes;
|
|
343
|
+
std::vector<uint8_t> data;
|
|
344
|
+
const uint64_t needed = (uint64_t)stride * (rows_per_image != 0 ? rows_per_image : height) * depth;
|
|
345
|
+
if (source->has_shadow && source_offset + needed <= source->shadow.size()) {
|
|
346
|
+
data.assign(source->shadow.begin() + (size_t)source_offset,
|
|
347
|
+
source->shadow.begin() + (size_t)(source_offset + needed));
|
|
348
|
+
} else {
|
|
349
|
+
flush_encoder(encoder);
|
|
350
|
+
std::vector<uint8_t> download;
|
|
351
|
+
if (!read_texture_rows(*texture, 0, 0, 0, 0, 1, 1, 1, 4, &download)) return XT_UNDEFINED;
|
|
352
|
+
data.assign((size_t)needed, 0);
|
|
353
|
+
}
|
|
354
|
+
upload_texture_rows(*texture, (uint32_t)prop_u64(destination, "mipLevel", 0),
|
|
355
|
+
(uint32_t)prop_u64(origin, "x", 0), (uint32_t)prop_u64(origin, "y", 0),
|
|
356
|
+
(uint32_t)prop_u64(origin, "z", 0), width, height, depth, stride, data,
|
|
357
|
+
source_offset);
|
|
358
|
+
return XT_UNDEFINED;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
xt_value copy_texture_to_buffer(Object &object, int argc, xt_value *argv) {
|
|
362
|
+
CommandEncoder &encoder = static_cast<CommandEncoder &>(object);
|
|
363
|
+
xt_value source = arg_object(argc, argv, 0);
|
|
364
|
+
Texture *texture = texture_at(prop_object(source, "texture"));
|
|
365
|
+
xt_value destination_value = arg_object(argc, argv, 1);
|
|
366
|
+
Buffer *destination = buffer_at(prop_object(destination_value, "buffer"));
|
|
367
|
+
xt_value size = arg_object(argc, argv, 2);
|
|
368
|
+
if (texture == nullptr || destination == nullptr) return XT_UNDEFINED;
|
|
369
|
+
flush_encoder(encoder);
|
|
370
|
+
const uint32_t width = (uint32_t)prop_u64(size, "width", 0);
|
|
371
|
+
const uint32_t height = (uint32_t)prop_u64(size, "height", 1);
|
|
372
|
+
const uint32_t depth = (uint32_t)prop_u64(size, "depthOrArrayLayers", 1);
|
|
373
|
+
const uint32_t bytes_per_row =
|
|
374
|
+
(uint32_t)prop_u64(destination_value, "bytesPerRow", width * 4);
|
|
375
|
+
std::vector<uint8_t> data;
|
|
376
|
+
xt_value origin = prop_object(source, "origin");
|
|
377
|
+
if (!read_texture_rows(*texture, (uint32_t)prop_u64(source, "mipLevel", 0),
|
|
378
|
+
(uint32_t)prop_u64(origin, "x", 0), (uint32_t)prop_u64(origin, "y", 0),
|
|
379
|
+
(uint32_t)prop_u64(origin, "z", 0), width, height, depth, bytes_per_row,
|
|
380
|
+
&data)) {
|
|
381
|
+
return XT_UNDEFINED;
|
|
382
|
+
}
|
|
383
|
+
write_buffer_bytes(*destination, prop_u64(destination_value, "offset", 0), data);
|
|
384
|
+
return XT_UNDEFINED;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
xt_value copy_texture_to_texture(Object &object, int argc, xt_value *argv) {
|
|
388
|
+
CommandEncoder &encoder = static_cast<CommandEncoder &>(object);
|
|
389
|
+
xt_value source = arg_object(argc, argv, 0);
|
|
390
|
+
Texture *from = texture_at(prop_object(source, "texture"));
|
|
391
|
+
xt_value destination = arg_object(argc, argv, 1);
|
|
392
|
+
Texture *to = texture_at(prop_object(destination, "texture"));
|
|
393
|
+
xt_value size = arg_object(argc, argv, 2);
|
|
394
|
+
if (from == nullptr || to == nullptr) return XT_UNDEFINED;
|
|
395
|
+
xt_value origin = prop_object(source, "origin");
|
|
396
|
+
SDL_GPUCommandBuffer *cmd = encoder_cmd(encoder);
|
|
397
|
+
SDL_GPUCopyPass *pass = SDL_BeginGPUCopyPass(cmd);
|
|
398
|
+
SDL_GPUTextureLocation from_location = {};
|
|
399
|
+
from_location.texture = from->gpu;
|
|
400
|
+
from_location.mip_level = (Uint32)prop_u64(source, "mipLevel", 0);
|
|
401
|
+
from_location.layer = (Uint32)prop_u64(origin, "z", 0);
|
|
402
|
+
from_location.x = (Uint32)prop_u64(origin, "x", 0);
|
|
403
|
+
from_location.y = (Uint32)prop_u64(origin, "y", 0);
|
|
404
|
+
xt_value target_origin = prop_object(destination, "origin");
|
|
405
|
+
SDL_GPUTextureLocation to_location = {};
|
|
406
|
+
to_location.texture = to->gpu;
|
|
407
|
+
to_location.mip_level = (Uint32)prop_u64(destination, "mipLevel", 0);
|
|
408
|
+
to_location.layer = (Uint32)prop_u64(target_origin, "z", 0);
|
|
409
|
+
to_location.x = (Uint32)prop_u64(target_origin, "x", 0);
|
|
410
|
+
to_location.y = (Uint32)prop_u64(target_origin, "y", 0);
|
|
411
|
+
SDL_CopyGPUTextureToTexture(pass, &from_location, &to_location,
|
|
412
|
+
(Uint32)prop_u64(size, "width", 1),
|
|
413
|
+
(Uint32)prop_u64(size, "height", 1),
|
|
414
|
+
(Uint32)prop_u64(size, "depthOrArrayLayers", 1), true);
|
|
415
|
+
SDL_EndGPUCopyPass(pass);
|
|
416
|
+
return XT_UNDEFINED;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
xt_value clear_buffer(Object &object, int argc, xt_value *argv) {
|
|
420
|
+
CommandEncoder &encoder = static_cast<CommandEncoder &>(object);
|
|
421
|
+
Buffer *buffer = buffer_at(xt_arg(argc, argv, 0));
|
|
422
|
+
const uint64_t offset = arg_u64(argc, argv, 1);
|
|
423
|
+
uint64_t size = arg_u64(argc, argv, 2);
|
|
424
|
+
if (buffer == nullptr) return XT_UNDEFINED;
|
|
425
|
+
if (size == 0) size = buffer->size > offset ? buffer->size - offset : 0;
|
|
426
|
+
flush_encoder(encoder);
|
|
427
|
+
write_buffer_bytes(*buffer, offset, std::vector<uint8_t>((size_t)size, 0));
|
|
428
|
+
return XT_UNDEFINED;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
xt_value resolve_query_set(Object &object, int argc, xt_value *argv) {
|
|
432
|
+
(void)argc;
|
|
433
|
+
(void)argv;
|
|
434
|
+
std::shared_ptr<Device> device = device_for(object, nullptr);
|
|
435
|
+
if (device != nullptr) {
|
|
436
|
+
record_error(*device, ErrorKind::Validation,
|
|
437
|
+
"resolveQuerySet: this SDL_GPU build has no query support");
|
|
438
|
+
}
|
|
439
|
+
return XT_UNDEFINED;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
xt_value write_timestamp(Object &object, int argc, xt_value *argv) {
|
|
443
|
+
(void)argc;
|
|
444
|
+
(void)argv;
|
|
445
|
+
std::shared_ptr<Device> device = device_for(object, nullptr);
|
|
446
|
+
if (device != nullptr) {
|
|
447
|
+
record_error(*device, ErrorKind::Validation,
|
|
448
|
+
"writeTimestamp: this SDL_GPU build has no timestamp support");
|
|
449
|
+
}
|
|
450
|
+
return XT_UNDEFINED;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
xt_value finish_encoder(Object &object, int argc, xt_value *argv) {
|
|
454
|
+
(void)argc;
|
|
455
|
+
(void)argv;
|
|
456
|
+
CommandEncoder &encoder = static_cast<CommandEncoder &>(object);
|
|
457
|
+
if (encoder.finished) return XT_UNDEFINED;
|
|
458
|
+
encoder.finished = true;
|
|
459
|
+
auto command = std::make_shared<CommandBuffer>();
|
|
460
|
+
command->kind = Kind::CommandBuffer;
|
|
461
|
+
command->device_id = encoder.device_id;
|
|
462
|
+
command->cmd = encoder.cmd;
|
|
463
|
+
encoder.cmd = nullptr;
|
|
464
|
+
return handle_of(add_object(command));
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
xt_value encoder_push_debug(Object &object, int argc, xt_value *argv) {
|
|
468
|
+
CommandEncoder &encoder = static_cast<CommandEncoder &>(object);
|
|
469
|
+
SDL_GPUCommandBuffer *cmd = encoder_cmd(encoder);
|
|
470
|
+
const std::string name = arg_string(argc, argv, 0);
|
|
471
|
+
if (cmd != nullptr) SDL_PushGPUDebugGroup(cmd, name.c_str());
|
|
472
|
+
return XT_UNDEFINED;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
xt_value encoder_pop_debug(Object &object, int argc, xt_value *argv) {
|
|
476
|
+
(void)argc;
|
|
477
|
+
(void)argv;
|
|
478
|
+
CommandEncoder &encoder = static_cast<CommandEncoder &>(object);
|
|
479
|
+
if (encoder.cmd != nullptr) SDL_PopGPUDebugGroup(encoder.cmd);
|
|
480
|
+
return XT_UNDEFINED;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
xt_value encoder_insert_debug(Object &object, int argc, xt_value *argv) {
|
|
484
|
+
(void)object;
|
|
485
|
+
(void)argc;
|
|
486
|
+
(void)argv;
|
|
487
|
+
return XT_UNDEFINED;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
} // namespace
|
|
491
|
+
|
|
492
|
+
void register_command_methods() {
|
|
493
|
+
add_getter(Kind::CommandEncoder, "label", encoder_label);
|
|
494
|
+
add_method(Kind::CommandEncoder, "beginRenderPass", begin_render_pass);
|
|
495
|
+
add_method(Kind::CommandEncoder, "beginComputePass", begin_compute_pass);
|
|
496
|
+
add_method(Kind::CommandEncoder, "copyBufferToBuffer", copy_buffer_to_buffer);
|
|
497
|
+
add_method(Kind::CommandEncoder, "copyBufferToTexture", copy_buffer_to_texture);
|
|
498
|
+
add_method(Kind::CommandEncoder, "copyTextureToBuffer", copy_texture_to_buffer);
|
|
499
|
+
add_method(Kind::CommandEncoder, "copyTextureToTexture", copy_texture_to_texture);
|
|
500
|
+
add_method(Kind::CommandEncoder, "clearBuffer", clear_buffer);
|
|
501
|
+
add_method(Kind::CommandEncoder, "resolveQuerySet", resolve_query_set);
|
|
502
|
+
add_method(Kind::CommandEncoder, "writeTimestamp", write_timestamp);
|
|
503
|
+
add_method(Kind::CommandEncoder, "finish", finish_encoder);
|
|
504
|
+
add_method(Kind::CommandEncoder, "pushDebugGroup", encoder_push_debug);
|
|
505
|
+
add_method(Kind::CommandEncoder, "popDebugGroup", encoder_pop_debug);
|
|
506
|
+
add_method(Kind::CommandEncoder, "insertDebugMarker", encoder_insert_debug);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
} // namespace webgpu
|
|
510
|
+
} // namespace xtgui
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — WebGPU compute passes.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#include "webgpu_bindings.h"
|
|
6
|
+
#include "webgpu_pass.h"
|
|
7
|
+
|
|
8
|
+
namespace xtgui {
|
|
9
|
+
namespace webgpu {
|
|
10
|
+
namespace {
|
|
11
|
+
|
|
12
|
+
uint32_t object_id(xt_value value) {
|
|
13
|
+
if (!XT_IS_OBJECT(value)) return 0;
|
|
14
|
+
return (uint32_t)xt_to_number(xt_object_get_cstr(value, "__xt_webgpu_id"));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
SDL_GPUCommandBuffer *command_of(ComputePassEncoder &pass) {
|
|
18
|
+
std::shared_ptr<Object> object = get_object(pass.encoder, Kind::CommandEncoder);
|
|
19
|
+
if (object == nullptr) return nullptr;
|
|
20
|
+
CommandEncoder *encoder = static_cast<CommandEncoder *>(object.get());
|
|
21
|
+
if (encoder->cmd == nullptr && !encoder->finished) {
|
|
22
|
+
encoder->cmd = SDL_AcquireGPUCommandBuffer(gpu_device());
|
|
23
|
+
}
|
|
24
|
+
return encoder->cmd;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
ComputePipeline *pipeline_of(ComputePassEncoder &pass) {
|
|
28
|
+
std::shared_ptr<Object> object = get_object(pass.pipeline, Kind::ComputePipeline);
|
|
29
|
+
return object == nullptr ? nullptr : static_cast<ComputePipeline *>(object.get());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
xt_value compute_label(Object &object) { return xt_string_from_cstr(object.label.c_str()); }
|
|
33
|
+
|
|
34
|
+
xt_value compute_set_pipeline(Object &object, int argc, xt_value *argv) {
|
|
35
|
+
ComputePassEncoder &pass = static_cast<ComputePassEncoder &>(object);
|
|
36
|
+
pass.pipeline = object_id(xt_arg(argc, argv, 0));
|
|
37
|
+
return XT_UNDEFINED;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
xt_value compute_set_bind_group(Object &object, int argc, xt_value *argv) {
|
|
41
|
+
ComputePassEncoder &pass = static_cast<ComputePassEncoder &>(object);
|
|
42
|
+
const int index = (int)arg_number(argc, argv, 0);
|
|
43
|
+
BindGroupSlot slot;
|
|
44
|
+
slot.group = object_id(xt_arg(argc, argv, 1));
|
|
45
|
+
xt_value offsets = xt_arg(argc, argv, 2);
|
|
46
|
+
if (XT_IS_ARRAY(offsets)) {
|
|
47
|
+
const uint32_t count = (uint32_t)xt_to_number(xt_array_length(offsets));
|
|
48
|
+
for (uint32_t i = 0; i < count; i++) {
|
|
49
|
+
slot.dynamic_offsets.push_back(
|
|
50
|
+
(uint32_t)xt_to_number(xt_array_get(offsets, xt_number((double)i))));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
pass.groups[index] = std::move(slot);
|
|
54
|
+
return XT_UNDEFINED;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
xt_value compute_dispatch(Object &object, int argc, xt_value *argv) {
|
|
58
|
+
ComputePassEncoder &pass = static_cast<ComputePassEncoder &>(object);
|
|
59
|
+
ComputePipeline *pipeline = pipeline_of(pass);
|
|
60
|
+
if (pipeline == nullptr) {
|
|
61
|
+
std::shared_ptr<Device> device = device_for(object, nullptr);
|
|
62
|
+
if (device != nullptr) validation(*device, "dispatchWorkgroups: no compute pipeline is bound");
|
|
63
|
+
return XT_UNDEFINED;
|
|
64
|
+
}
|
|
65
|
+
SDL_GPUCommandBuffer *command = command_of(pass);
|
|
66
|
+
if (!bind_compute_resources(pass, *pipeline, command)) return XT_UNDEFINED;
|
|
67
|
+
SDL_BindGPUComputePipeline(pass.pass, pipeline->gpu);
|
|
68
|
+
SDL_DispatchGPUCompute(pass.pass, (Uint32)arg_number(argc, argv, 0),
|
|
69
|
+
(Uint32)arg_number(argc, argv, 1), (Uint32)arg_number(argc, argv, 2));
|
|
70
|
+
return XT_UNDEFINED;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
xt_value compute_dispatch_indirect(Object &object, int argc, xt_value *argv) {
|
|
74
|
+
ComputePassEncoder &pass = static_cast<ComputePassEncoder &>(object);
|
|
75
|
+
ComputePipeline *pipeline = pipeline_of(pass);
|
|
76
|
+
std::shared_ptr<Object> buffer = get_object(object_id(xt_arg(argc, argv, 0)), Kind::Buffer);
|
|
77
|
+
if (pipeline == nullptr || buffer == nullptr) return XT_UNDEFINED;
|
|
78
|
+
Buffer *native = static_cast<Buffer *>(buffer.get());
|
|
79
|
+
if (!native->has_gpu) return XT_UNDEFINED;
|
|
80
|
+
SDL_GPUCommandBuffer *command = command_of(pass);
|
|
81
|
+
if (!bind_compute_resources(pass, *pipeline, command)) return XT_UNDEFINED;
|
|
82
|
+
SDL_BindGPUComputePipeline(pass.pass, pipeline->gpu);
|
|
83
|
+
SDL_DispatchGPUComputeIndirect(pass.pass, native->gpu, (Uint32)arg_u64(argc, argv, 1));
|
|
84
|
+
return XT_UNDEFINED;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
xt_value compute_end(Object &object, int argc, xt_value *argv) {
|
|
88
|
+
(void)argc;
|
|
89
|
+
(void)argv;
|
|
90
|
+
ComputePassEncoder &pass = static_cast<ComputePassEncoder &>(object);
|
|
91
|
+
if (pass.ended) return XT_UNDEFINED;
|
|
92
|
+
if (pass.pass != nullptr) SDL_EndGPUComputePass(pass.pass);
|
|
93
|
+
pass.pass = nullptr;
|
|
94
|
+
pass.ended = true;
|
|
95
|
+
return XT_UNDEFINED;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
xt_value compute_push_debug(Object &object, int argc, xt_value *argv) {
|
|
99
|
+
(void)argc;
|
|
100
|
+
(void)argv;
|
|
101
|
+
ComputePassEncoder &pass = static_cast<ComputePassEncoder &>(object);
|
|
102
|
+
SDL_GPUCommandBuffer *command = command_of(pass);
|
|
103
|
+
if (command != nullptr) SDL_PushGPUDebugGroup(command, arg_string(argc, argv, 0).c_str());
|
|
104
|
+
return XT_UNDEFINED;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
xt_value compute_pop_debug(Object &object, int argc, xt_value *argv) {
|
|
108
|
+
(void)argc;
|
|
109
|
+
(void)argv;
|
|
110
|
+
ComputePassEncoder &pass = static_cast<ComputePassEncoder &>(object);
|
|
111
|
+
SDL_GPUCommandBuffer *command = command_of(pass);
|
|
112
|
+
if (command != nullptr) SDL_PopGPUDebugGroup(command);
|
|
113
|
+
return XT_UNDEFINED;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
xt_value compute_noop(Object &object, int argc, xt_value *argv) {
|
|
117
|
+
(void)object;
|
|
118
|
+
(void)argc;
|
|
119
|
+
(void)argv;
|
|
120
|
+
return XT_UNDEFINED;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
} // namespace
|
|
124
|
+
|
|
125
|
+
void register_compute_pass_methods() {
|
|
126
|
+
add_getter(Kind::ComputePassEncoder, "label", compute_label);
|
|
127
|
+
add_method(Kind::ComputePassEncoder, "setPipeline", compute_set_pipeline);
|
|
128
|
+
add_method(Kind::ComputePassEncoder, "setBindGroup", compute_set_bind_group);
|
|
129
|
+
add_method(Kind::ComputePassEncoder, "dispatchWorkgroups", compute_dispatch);
|
|
130
|
+
add_method(Kind::ComputePassEncoder, "dispatchWorkgroupsIndirect", compute_dispatch_indirect);
|
|
131
|
+
add_method(Kind::ComputePassEncoder, "end", compute_end);
|
|
132
|
+
add_method(Kind::ComputePassEncoder, "pushDebugGroup", compute_push_debug);
|
|
133
|
+
add_method(Kind::ComputePassEncoder, "popDebugGroup", compute_pop_debug);
|
|
134
|
+
add_method(Kind::ComputePassEncoder, "insertDebugMarker", compute_noop);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
} // namespace webgpu
|
|
138
|
+
} // namespace xtgui
|