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.
- 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 +309 -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 +242 -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,232 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — WGSL type model helpers.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#include "wgsl_ast.h"
|
|
6
|
+
|
|
7
|
+
#include <cstdlib>
|
|
8
|
+
|
|
9
|
+
namespace xtgui {
|
|
10
|
+
namespace wgsl {
|
|
11
|
+
|
|
12
|
+
TypePtr make_scalar(Scalar scalar) {
|
|
13
|
+
auto type = std::make_shared<Type>();
|
|
14
|
+
type->kind = Kind::Scalar;
|
|
15
|
+
type->scalar = scalar;
|
|
16
|
+
return type;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
TypePtr make_vector(Scalar scalar, int width) {
|
|
20
|
+
auto type = std::make_shared<Type>();
|
|
21
|
+
type->kind = Kind::Vector;
|
|
22
|
+
type->scalar = scalar;
|
|
23
|
+
type->width = width;
|
|
24
|
+
return type;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
TypePtr make_matrix(Scalar scalar, int cols, int rows) {
|
|
28
|
+
auto type = std::make_shared<Type>();
|
|
29
|
+
type->kind = Kind::Matrix;
|
|
30
|
+
type->scalar = scalar;
|
|
31
|
+
type->cols = cols;
|
|
32
|
+
type->rows = rows;
|
|
33
|
+
return type;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
TypePtr make_array(TypePtr elem, int length) {
|
|
37
|
+
auto type = std::make_shared<Type>();
|
|
38
|
+
type->kind = Kind::Array;
|
|
39
|
+
type->elem = std::move(elem);
|
|
40
|
+
type->length = length;
|
|
41
|
+
return type;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
std::string scalar_glsl(Scalar scalar) {
|
|
45
|
+
switch (scalar) {
|
|
46
|
+
case Scalar::Bool: return "bool";
|
|
47
|
+
case Scalar::I32: return "int";
|
|
48
|
+
case Scalar::U32: return "uint";
|
|
49
|
+
default: return "float";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
namespace {
|
|
54
|
+
|
|
55
|
+
std::string vector_prefix(Scalar scalar) {
|
|
56
|
+
switch (scalar) {
|
|
57
|
+
case Scalar::Bool: return "b";
|
|
58
|
+
case Scalar::I32: return "i";
|
|
59
|
+
case Scalar::U32: return "u";
|
|
60
|
+
default: return "";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
std::string texture_glsl(const Type &type) {
|
|
65
|
+
const bool storage = type.kind == Kind::StorageTexture;
|
|
66
|
+
const bool depth = type.depth;
|
|
67
|
+
const TextureDim dim = type.dim;
|
|
68
|
+
if (storage) {
|
|
69
|
+
switch (dim) {
|
|
70
|
+
case TextureDim::D1: return "image1D";
|
|
71
|
+
case TextureDim::D2Array: return "image2DArray";
|
|
72
|
+
case TextureDim::D3: return "image3D";
|
|
73
|
+
case TextureDim::Cube:
|
|
74
|
+
case TextureDim::CubeArray: return "imageCube";
|
|
75
|
+
default: return "image2D";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
switch (dim) {
|
|
79
|
+
case TextureDim::D1: return "sampler1D";
|
|
80
|
+
case TextureDim::D2Array: return depth ? "sampler2DArrayShadow" : "sampler2DArray";
|
|
81
|
+
case TextureDim::D3: return "sampler3D";
|
|
82
|
+
case TextureDim::Cube: return depth ? "samplerCubeShadow" : "samplerCube";
|
|
83
|
+
case TextureDim::CubeArray: return "samplerCubeArray";
|
|
84
|
+
case TextureDim::Multisampled2D: return "sampler2DMS";
|
|
85
|
+
default: break;
|
|
86
|
+
}
|
|
87
|
+
return depth ? "sampler2DShadow" : "sampler2D";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
} // namespace
|
|
91
|
+
|
|
92
|
+
std::string glsl_type(const Type &type) {
|
|
93
|
+
switch (type.kind) {
|
|
94
|
+
case Kind::Void: return "void";
|
|
95
|
+
case Kind::Scalar: return scalar_glsl(type.scalar);
|
|
96
|
+
case Kind::Vector:
|
|
97
|
+
return vector_prefix(type.scalar) + "vec" + std::to_string(type.width > 0 ? type.width : 1);
|
|
98
|
+
case Kind::Matrix: {
|
|
99
|
+
if (type.cols == type.rows) return "mat" + std::to_string(type.cols);
|
|
100
|
+
return "mat" + std::to_string(type.cols) + "x" + std::to_string(type.rows);
|
|
101
|
+
}
|
|
102
|
+
case Kind::Array: {
|
|
103
|
+
std::string element = type.elem != nullptr ? glsl_type(*type.elem) : "float";
|
|
104
|
+
return element + "[" + std::to_string(type.length) + "]";
|
|
105
|
+
}
|
|
106
|
+
case Kind::Struct: return type.strct != nullptr ? type.strct->name : "xt_unknown";
|
|
107
|
+
case Kind::Atomic: return "uint";
|
|
108
|
+
case Kind::Sampler: return "sampler2D";
|
|
109
|
+
case Kind::SamplerComparison: return "sampler2DShadow";
|
|
110
|
+
case Kind::Texture:
|
|
111
|
+
case Kind::StorageTexture: return texture_glsl(type);
|
|
112
|
+
default: return "float";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
std::string glsl_decl(const Type &type, const std::string &name) {
|
|
117
|
+
if (type.kind == Kind::Array && type.elem != nullptr) {
|
|
118
|
+
return glsl_decl(*type.elem, name + "[" + std::to_string(type.length) + "]");
|
|
119
|
+
}
|
|
120
|
+
return glsl_type(type) + " " + name;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
std::string wgsl_type(const Type &type) {
|
|
124
|
+
switch (type.kind) {
|
|
125
|
+
case Kind::Void: return "void";
|
|
126
|
+
case Kind::Scalar:
|
|
127
|
+
switch (type.scalar) {
|
|
128
|
+
case Scalar::Bool: return "bool";
|
|
129
|
+
case Scalar::I32: return "i32";
|
|
130
|
+
case Scalar::U32: return "u32";
|
|
131
|
+
default: return "f32";
|
|
132
|
+
}
|
|
133
|
+
case Kind::Vector: {
|
|
134
|
+
const std::string base = glsl_type(type);
|
|
135
|
+
return std::string("vec") + std::to_string(type.width) +
|
|
136
|
+
(base[0] == 'b' ? "b" : base[0] == 'i' ? "i" : base[0] == 'u' ? "u" : "f");
|
|
137
|
+
}
|
|
138
|
+
case Kind::Matrix: return "mat" + std::to_string(type.cols) + "x" + std::to_string(type.rows) + "f";
|
|
139
|
+
case Kind::Array: return "array<" + (type.elem ? wgsl_type(*type.elem) : "f32") + ", " +
|
|
140
|
+
std::to_string(type.length) + ">";
|
|
141
|
+
case Kind::Struct: return type.strct != nullptr ? type.strct->name : "struct";
|
|
142
|
+
case Kind::Atomic: return "atomic<u32>";
|
|
143
|
+
case Kind::Sampler: return "sampler";
|
|
144
|
+
case Kind::SamplerComparison: return "sampler_comparison";
|
|
145
|
+
case Kind::Texture: return "texture";
|
|
146
|
+
case Kind::StorageTexture: return "texture_storage";
|
|
147
|
+
default: return "unknown";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
TypePtr type_by_name(const Module &module, const std::string &name) {
|
|
152
|
+
if (name == "f32" || name == "f16") return make_scalar(Scalar::F32);
|
|
153
|
+
if (name == "i32") return make_scalar(Scalar::I32);
|
|
154
|
+
if (name == "u32") return make_scalar(Scalar::U32);
|
|
155
|
+
if (name == "bool") return make_scalar(Scalar::Bool);
|
|
156
|
+
if (name == "sampler") {
|
|
157
|
+
auto type = std::make_shared<Type>();
|
|
158
|
+
type->kind = Kind::Sampler;
|
|
159
|
+
return type;
|
|
160
|
+
}
|
|
161
|
+
if (name == "sampler_comparison") {
|
|
162
|
+
auto type = std::make_shared<Type>();
|
|
163
|
+
type->kind = Kind::SamplerComparison;
|
|
164
|
+
return type;
|
|
165
|
+
}
|
|
166
|
+
/* Vector shorthands: vec3f, vec2i, vec4u (and the generic vec3<f32> form is
|
|
167
|
+
* parsed directly, not looked up by name). */
|
|
168
|
+
if (name.size() >= 5 && name.compare(0, 3, "vec") == 0 && name[3] >= '2' && name[3] <= '4') {
|
|
169
|
+
const int width = name[3] - '0';
|
|
170
|
+
const char suffix = name[4];
|
|
171
|
+
Scalar scalar = Scalar::F32;
|
|
172
|
+
if (suffix == 'i') scalar = Scalar::I32;
|
|
173
|
+
else if (suffix == 'u') scalar = Scalar::U32;
|
|
174
|
+
else if (suffix == 'b') scalar = Scalar::Bool;
|
|
175
|
+
return make_vector(scalar, width);
|
|
176
|
+
}
|
|
177
|
+
/* Matrix shorthands: mat4x4f, mat3x2f, mat2f (= mat2x2f). */
|
|
178
|
+
if (name.size() >= 5 && name.compare(0, 3, "mat") == 0) {
|
|
179
|
+
int cols = 0;
|
|
180
|
+
int rows = 0;
|
|
181
|
+
size_t at = 3;
|
|
182
|
+
while (at < name.size() && name[at] >= '0' && name[at] <= '9') {
|
|
183
|
+
cols = cols * 10 + (name[at] - '0');
|
|
184
|
+
at++;
|
|
185
|
+
}
|
|
186
|
+
if (at < name.size() && name[at] == 'x') {
|
|
187
|
+
at++;
|
|
188
|
+
while (at < name.size() && name[at] >= '0' && name[at] <= '9') {
|
|
189
|
+
rows = rows * 10 + (name[at] - '0');
|
|
190
|
+
at++;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (rows == 0) rows = cols;
|
|
194
|
+
if (cols >= 2 && cols <= 4 && rows >= 2 && rows <= 4) return make_matrix(Scalar::F32, cols, rows);
|
|
195
|
+
}
|
|
196
|
+
for (const StructDecl &decl : module.structs) {
|
|
197
|
+
if (decl.name == name) {
|
|
198
|
+
auto type = std::make_shared<Type>();
|
|
199
|
+
type->kind = Kind::Struct;
|
|
200
|
+
type->strct = &decl;
|
|
201
|
+
type->width = 1;
|
|
202
|
+
return type;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
for (const auto &alias : module.aliases) {
|
|
206
|
+
if (alias.first == name && alias.second != nullptr) {
|
|
207
|
+
return std::make_shared<Type>(*alias.second);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return nullptr;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
std::string image_format_glsl(ImageFormat format) {
|
|
214
|
+
switch (format) {
|
|
215
|
+
case ImageFormat::Rgba8Unorm: return "rgba8";
|
|
216
|
+
case ImageFormat::Rgba8Snorm: return "rgba8_snorm";
|
|
217
|
+
case ImageFormat::Rgba8Uint: return "rgba8ui";
|
|
218
|
+
case ImageFormat::Rgba8Sint: return "rgba8i";
|
|
219
|
+
case ImageFormat::Rgba16Float: return "rgba16f";
|
|
220
|
+
case ImageFormat::Rgba32Float: return "rgba32f";
|
|
221
|
+
case ImageFormat::R32Float: return "r32f";
|
|
222
|
+
case ImageFormat::R32Uint: return "r32ui";
|
|
223
|
+
case ImageFormat::R32Sint: return "r32i";
|
|
224
|
+
case ImageFormat::Rgba16Uint: return "rgba16ui";
|
|
225
|
+
case ImageFormat::Rgba16Sint: return "rgba16i";
|
|
226
|
+
case ImageFormat::Bgra8Unorm: return "rgba8";
|
|
227
|
+
default: return "rgba8";
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
} // namespace wgsl
|
|
232
|
+
} // namespace xtgui
|
package/src/driver/version.ts
CHANGED
|
@@ -40,9 +40,21 @@ export function hasMediaUsage(usage: ProgramUsage): boolean {
|
|
|
40
40
|
return usage.strings.some((value) => MEDIA_TAG.test(value) || MEDIA_TAG_NAME.test(value));
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/** True when the program may use `navigator.gpu` / WGSL shaders. */
|
|
44
|
+
export function hasWebgpuUsage(usage: ProgramUsage): boolean {
|
|
45
|
+
if (usage.dynamicMarkup) return true;
|
|
46
|
+
for (const name of usage.identifiers) {
|
|
47
|
+
if (name.startsWith("GPU")) return true;
|
|
48
|
+
}
|
|
49
|
+
return usage.strings.some((value) =>
|
|
50
|
+
/webgpu|navigator\.gpu|requestAdapter|createShaderModule|@vertex|@fragment|@compute|wgsl/i.test(value),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
/** True when the program may compile GLSL at run time (WebGL or blending). */
|
|
44
55
|
export function hasGpuUsage(usage: ProgramUsage): boolean {
|
|
45
56
|
if (usage.dynamicMarkup) return true;
|
|
57
|
+
if (hasWebgpuUsage(usage)) return true;
|
|
46
58
|
if (usage.identifiers.has("mixBlendMode") || usage.identifiers.has("backdropFilter")) return true;
|
|
47
59
|
if (usage.getContext.some((kind) => kind === undefined || /webgl/i.test(kind))) return true;
|
|
48
60
|
return usage.strings.some((value) => GPU_TOKEN.test(value));
|
|
@@ -151,6 +163,18 @@ export const guiLinkFeatures: readonly LinkFeature[] = [
|
|
|
151
163
|
runtimeSources: () => [join(findRuntimeDir(), "ext_gui", "text_bridge.c")],
|
|
152
164
|
used: hasShapingUsage,
|
|
153
165
|
},
|
|
166
|
+
{
|
|
167
|
+
name: "webgpu",
|
|
168
|
+
description: "WebGPU (navigator.gpu, WGSL) rendering over SDL_GPU (requires gpu)",
|
|
169
|
+
requires: ["gpu"],
|
|
170
|
+
/**
|
|
171
|
+
* `webgpu_bridge.c` installs `XtWebgpuApi` and references the WebGPU
|
|
172
|
+
* runtime, pulling the object model, WGSL front end and canvas bindings
|
|
173
|
+
* out of `gui.a`. A page without WebGPU links none of them.
|
|
174
|
+
*/
|
|
175
|
+
runtimeSources: () => [join(findRuntimeDir(), "ext_gui", "webgpu_bridge.c")],
|
|
176
|
+
used: hasWebgpuUsage,
|
|
177
|
+
},
|
|
154
178
|
{
|
|
155
179
|
name: "webgl",
|
|
156
180
|
description: "WebGL context and DOM API (requires gpu)",
|
|
@@ -105,6 +105,45 @@ const hostTypes = [
|
|
|
105
105
|
"WebGLTransformFeedback",
|
|
106
106
|
"XRWebGLLayer",
|
|
107
107
|
"XRWebGLBinding",
|
|
108
|
+
/* WebGPU interfaces (see runtime/ext_gui/webgpu_bindings.cpp). The `webgpu`
|
|
109
|
+
* link feature installs them; without it `xt_browser_type` falls back to the
|
|
110
|
+
* DOM answer, so a `typeof GPUDevice` probe is honest. */
|
|
111
|
+
"GPU",
|
|
112
|
+
"GPUAdapter",
|
|
113
|
+
"GPUAdapterInfo",
|
|
114
|
+
"GPUDevice",
|
|
115
|
+
"GPUQueue",
|
|
116
|
+
"GPUBuffer",
|
|
117
|
+
"GPUTexture",
|
|
118
|
+
"GPUTextureView",
|
|
119
|
+
"GPUSampler",
|
|
120
|
+
"GPUShaderModule",
|
|
121
|
+
"GPUBindGroupLayout",
|
|
122
|
+
"GPUPipelineLayout",
|
|
123
|
+
"GPUBindGroup",
|
|
124
|
+
"GPURenderPipeline",
|
|
125
|
+
"GPUComputePipeline",
|
|
126
|
+
"GPUCommandEncoder",
|
|
127
|
+
"GPUCommandBuffer",
|
|
128
|
+
"GPURenderPassEncoder",
|
|
129
|
+
"GPUComputePassEncoder",
|
|
130
|
+
"GPURenderBundleEncoder",
|
|
131
|
+
"GPURenderBundle",
|
|
132
|
+
"GPUQuerySet",
|
|
133
|
+
"GPUCanvasContext",
|
|
134
|
+
"GPUCompilationInfo",
|
|
135
|
+
"GPUCompilationMessage",
|
|
136
|
+
"GPUSupportedFeatures",
|
|
137
|
+
"GPUSupportedLimits",
|
|
138
|
+
"GPUBufferUsage",
|
|
139
|
+
"GPUTextureUsage",
|
|
140
|
+
"GPUShaderStage",
|
|
141
|
+
"GPUMapMode",
|
|
142
|
+
"GPUColorWrite",
|
|
143
|
+
"GPUValidationError",
|
|
144
|
+
"GPUOutOfMemoryError",
|
|
145
|
+
"GPUInternalError",
|
|
146
|
+
"GPUDeviceLostInfo",
|
|
108
147
|
] as const;
|
|
109
148
|
|
|
110
149
|
const browserGlobals: Record<string, { symbol: string; argument?: string }> = {
|