webgpu 0.0.1__py3-none-any.whl
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.
- webgpu/__init__.py +12 -0
- webgpu/_version.py +21 -0
- webgpu/camera.py +189 -0
- webgpu/canvas.py +144 -0
- webgpu/clipping.py +137 -0
- webgpu/colormap.py +325 -0
- webgpu/draw.py +35 -0
- webgpu/font.py +162 -0
- webgpu/fonts.json +52 -0
- webgpu/gpu.py +191 -0
- webgpu/input_handler.py +81 -0
- webgpu/jupyter.py +159 -0
- webgpu/jupyter_pyodide.py +363 -0
- webgpu/labels.py +132 -0
- webgpu/light.py +12 -0
- webgpu/lilgui.py +73 -0
- webgpu/link/__init__.py +3 -0
- webgpu/link/base.py +431 -0
- webgpu/link/link.js +431 -0
- webgpu/link/proxy.py +81 -0
- webgpu/link/websocket.py +115 -0
- webgpu/main.py +177 -0
- webgpu/platform.py +129 -0
- webgpu/render_object.py +155 -0
- webgpu/scene.py +201 -0
- webgpu/shaders/__init__.py +0 -0
- webgpu/shaders/camera.wgsl +21 -0
- webgpu/shaders/clipping.wgsl +35 -0
- webgpu/shaders/colormap.wgsl +60 -0
- webgpu/shaders/font.wgsl +53 -0
- webgpu/shaders/light.wgsl +9 -0
- webgpu/shaders/text.wgsl +57 -0
- webgpu/shaders/triangulation.wgsl +34 -0
- webgpu/shaders/vector.wgsl +118 -0
- webgpu/triangles.py +66 -0
- webgpu/uniforms.py +111 -0
- webgpu/utils.py +379 -0
- webgpu/vectors.py +101 -0
- webgpu/webgpu_api.py +1731 -0
- webgpu-0.0.1.dist-info/METADATA +32 -0
- webgpu-0.0.1.dist-info/RECORD +44 -0
- webgpu-0.0.1.dist-info/WHEEL +5 -0
- webgpu-0.0.1.dist-info/licenses/LICENSE +504 -0
- webgpu-0.0.1.dist-info/top_level.txt +1 -0
webgpu/webgpu_api.py
ADDED
|
@@ -0,0 +1,1731 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
from enum import Enum, IntFlag
|
|
4
|
+
|
|
5
|
+
from . import platform
|
|
6
|
+
from .platform import JsPromise, JsProxy, create_proxy, is_pyodide, toJS
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class BaseWebGPUHandle:
|
|
10
|
+
handle: JsProxy
|
|
11
|
+
|
|
12
|
+
def __init__(self, handle):
|
|
13
|
+
self.handle = handle
|
|
14
|
+
|
|
15
|
+
def destroy(self):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
def __del__(self):
|
|
19
|
+
pass
|
|
20
|
+
# self.destroy()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def fromJS(obj):
|
|
24
|
+
if type(obj) in [str, int, float, bool]:
|
|
25
|
+
return obj
|
|
26
|
+
return dict(obj)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class BaseWebGPUObject:
|
|
30
|
+
def toJS(self):
|
|
31
|
+
return toJS(self.__dict__)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Sampler(BaseWebGPUHandle):
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class BindGroup(BaseWebGPUHandle):
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class BindGroupLayout(BaseWebGPUHandle):
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class CommandBuffer(BaseWebGPUHandle):
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class PipelineLayout(BaseWebGPUHandle):
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class RenderBundle(BaseWebGPUHandle):
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class TextureView(BaseWebGPUHandle):
|
|
59
|
+
pass
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class AutoLayoutMode(str, Enum):
|
|
63
|
+
auto = "auto"
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class AdapterType(str, Enum):
|
|
67
|
+
discrete_GPU = "discrete_GPU"
|
|
68
|
+
integrated_GPU = "integrated_GPU"
|
|
69
|
+
CPU = "CPU"
|
|
70
|
+
unknown = "unknown"
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class AddressMode(str, Enum):
|
|
74
|
+
undefined = "undefined"
|
|
75
|
+
clamp_to_edge = "clamp-to-edge"
|
|
76
|
+
repeat = "repeat"
|
|
77
|
+
mirror_repeat = "mirror-repeat"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class BackendType(str, Enum):
|
|
81
|
+
undefined = "undefined"
|
|
82
|
+
null = "null"
|
|
83
|
+
WebGPU = "WebGPU"
|
|
84
|
+
D3D11 = "D3D11"
|
|
85
|
+
D3D12 = "D3D12"
|
|
86
|
+
metal = "metal"
|
|
87
|
+
vulkan = "vulkan"
|
|
88
|
+
openGL = "openGL"
|
|
89
|
+
openGLES = "openGLES"
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class BlendFactor(str, Enum):
|
|
93
|
+
undefined = "undefined"
|
|
94
|
+
zero = "zero"
|
|
95
|
+
one = "one"
|
|
96
|
+
src = "src"
|
|
97
|
+
one_minus_src = "one-minus-src"
|
|
98
|
+
src_alpha = "src-alpha"
|
|
99
|
+
one_minus_src_alpha = "one-minus-src-alpha"
|
|
100
|
+
dst = "dst"
|
|
101
|
+
one_minus_dst = "one-minus-dst"
|
|
102
|
+
dst_alpha = "dst-alpha"
|
|
103
|
+
one_minus_dst_alpha = "one-minus-dst-alpha"
|
|
104
|
+
src_alpha_saturated = "src-alpha-saturated"
|
|
105
|
+
constant = "constant"
|
|
106
|
+
one_minus_constant = "one-minus-constant"
|
|
107
|
+
src1 = "src1"
|
|
108
|
+
one_minus_src1 = "one-minus-src1"
|
|
109
|
+
src1_alpha = "src1-alpha"
|
|
110
|
+
one_minus_src1_alpha = "one-minus-src1-alpha"
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class BlendOperation(str, Enum):
|
|
114
|
+
undefined = "undefined"
|
|
115
|
+
add = "add"
|
|
116
|
+
subtract = "subtract"
|
|
117
|
+
reverse_subtract = "reverse-subtract"
|
|
118
|
+
min = "min"
|
|
119
|
+
max = "max"
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class BufferBindingType(str, Enum):
|
|
123
|
+
binding_not_used = "binding_not_used"
|
|
124
|
+
undefined = "undefined"
|
|
125
|
+
uniform = "uniform"
|
|
126
|
+
storage = "storage"
|
|
127
|
+
read_only_storage = "read_only_storage"
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class BufferMapState(str, Enum):
|
|
131
|
+
unmapped = "unmapped"
|
|
132
|
+
pending = "pending"
|
|
133
|
+
mapped = "mapped"
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class CallbackMode(str, Enum):
|
|
137
|
+
wait_any_only = "wait_any_only"
|
|
138
|
+
allow_process_events = "allow_process_events"
|
|
139
|
+
allow_spontaneous = "allow_spontaneous"
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class CompareFunction(str, Enum):
|
|
143
|
+
undefined = "undefined"
|
|
144
|
+
never = "never"
|
|
145
|
+
less = "less"
|
|
146
|
+
equal = "equal"
|
|
147
|
+
less_equal = "less-equal"
|
|
148
|
+
greater = "greater"
|
|
149
|
+
not_equal = "not-equal"
|
|
150
|
+
greater_equal = "greater-equal"
|
|
151
|
+
always = "always"
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class CompilationInfoRequestStatus(str, Enum):
|
|
155
|
+
success = "success"
|
|
156
|
+
instance_dropped = "instance_dropped"
|
|
157
|
+
error = "error"
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class CompilationMessageType(str, Enum):
|
|
161
|
+
error = "error"
|
|
162
|
+
warning = "warning"
|
|
163
|
+
info = "info"
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
class CompositeAlphaMode(str, Enum):
|
|
167
|
+
auto = "auto"
|
|
168
|
+
opaque = "opaque"
|
|
169
|
+
premultiplied = "premultiplied"
|
|
170
|
+
unpremultiplied = "unpremultiplied"
|
|
171
|
+
inherit = "inherit"
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class CullMode(str, Enum):
|
|
175
|
+
none = "none"
|
|
176
|
+
front = "front"
|
|
177
|
+
back = "back"
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class DeviceLostReason(str, Enum):
|
|
181
|
+
unknown = "unknown"
|
|
182
|
+
destroyed = "destroyed"
|
|
183
|
+
instance_dropped = "instance_dropped"
|
|
184
|
+
failed_creation = "failed_creation"
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
class ErrorFilter(str, Enum):
|
|
188
|
+
validation = "validation"
|
|
189
|
+
out_of_memory = "out-of-memory"
|
|
190
|
+
internal = "internal"
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
class FeatureLevel(str, Enum):
|
|
194
|
+
compatibility = "compatibility"
|
|
195
|
+
core = "core"
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
class FeatureName(str):
|
|
199
|
+
undefined = "undefined"
|
|
200
|
+
depth_clip_control = "depth-clip-control"
|
|
201
|
+
depth32_float_stencil8 = "depth32float-stencil8"
|
|
202
|
+
timestamp_query = "timestamp-query"
|
|
203
|
+
texture_compression_BC = "texture-compression-BC"
|
|
204
|
+
texture_compression_BC_sliced_3D = "texture-compression-BC-sliced-3D"
|
|
205
|
+
texture_compression_ETC2 = "texture-compression-ETC2"
|
|
206
|
+
texture_compression_ASTC = "texture-compression-ASTC"
|
|
207
|
+
texture_compression_ASTC_sliced_3D = "texture-compression-ASTC-sliced-3D"
|
|
208
|
+
indirect_first_instance = "indirect-first-instance"
|
|
209
|
+
shader_f16 = "shader-f16"
|
|
210
|
+
rg11b10ufloat_renderable = "rg11b10ufloat-renderable"
|
|
211
|
+
bgra8unorm_storage = "bgra8unorm-storage"
|
|
212
|
+
float32_filterable = "float32-filterable"
|
|
213
|
+
float32_blendable = "float32-blendable"
|
|
214
|
+
clip_distances = "clip-distances"
|
|
215
|
+
dual_source_blending = "dual-source-blending"
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
class FilterMode(str, Enum):
|
|
219
|
+
nearest = "nearest"
|
|
220
|
+
linear = "linear"
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class FrontFace(str, Enum):
|
|
224
|
+
CCW = "ccw"
|
|
225
|
+
CW = "cw"
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
class IndexFormat(str, Enum):
|
|
229
|
+
uint16 = "uint16"
|
|
230
|
+
uint32 = "uint32"
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
class LoadOp(str, Enum):
|
|
234
|
+
load = "load"
|
|
235
|
+
clear = "clear"
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
class MipmapFilterMode(str, Enum):
|
|
239
|
+
nearest = "nearest"
|
|
240
|
+
linear = "linear"
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
class PowerPreference(str, Enum):
|
|
244
|
+
low_power = "low-power"
|
|
245
|
+
high_performance = "high-performance"
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
class PresentMode(str, Enum):
|
|
249
|
+
undefined = "undefined"
|
|
250
|
+
fifo = "fifo"
|
|
251
|
+
fifo_relaxed = "fifo_relaxed"
|
|
252
|
+
immediate = "immediate"
|
|
253
|
+
mailbox = "mailbox"
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class PrimitiveTopology(str, Enum):
|
|
257
|
+
point_list = "point-list"
|
|
258
|
+
line_list = "line-list"
|
|
259
|
+
line_strip = "line-strip"
|
|
260
|
+
triangle_list = "triangle-list"
|
|
261
|
+
triangle_strip = "triangle-strip"
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
class QueryType(str, Enum):
|
|
265
|
+
occlusion = "occlusion"
|
|
266
|
+
timestamp = "timestamp"
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
class QuerySet(BaseWebGPUHandle):
|
|
270
|
+
@property
|
|
271
|
+
def type(self) -> QueryType:
|
|
272
|
+
return self.handle.type()
|
|
273
|
+
|
|
274
|
+
@property
|
|
275
|
+
def count(self) -> int:
|
|
276
|
+
return self.handle.count()
|
|
277
|
+
|
|
278
|
+
def destroy(self) -> None:
|
|
279
|
+
return self.handle.destroy()
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
class SamplerBindingType(str, Enum):
|
|
283
|
+
filtering = "filtering"
|
|
284
|
+
non_filtering = "non-filtering"
|
|
285
|
+
comparison = "comparison"
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
class Status(str, Enum):
|
|
289
|
+
success = "success"
|
|
290
|
+
error = "error"
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
class StencilOperation(str, Enum):
|
|
294
|
+
undefined = "undefined"
|
|
295
|
+
keep = "keep"
|
|
296
|
+
zero = "zero"
|
|
297
|
+
replace = "replace"
|
|
298
|
+
invert = "invert"
|
|
299
|
+
increment_clamp = "increment-clamp"
|
|
300
|
+
decrement_clamp = "decrement-clamp"
|
|
301
|
+
increment_wrap = "increment-wrap"
|
|
302
|
+
decrement_wrap = "decrement-wrap"
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
class StorageTextureAccess(str, Enum):
|
|
306
|
+
write_only = "write-only"
|
|
307
|
+
read_only = "read-ony"
|
|
308
|
+
read_write = "read-write"
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
class StoreOp(str, Enum):
|
|
312
|
+
store = "store"
|
|
313
|
+
discard = "discard"
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
class TextureAspect(str, Enum):
|
|
317
|
+
all = "all"
|
|
318
|
+
stencil_only = "stencil-only"
|
|
319
|
+
depth_only = "depth-only"
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def TextureDimensionInt2Str(dim: int):
|
|
323
|
+
return ["1d", "2d", "3d"][dim - 1]
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
class TextureFormat(str, Enum):
|
|
327
|
+
# 8-bit formats
|
|
328
|
+
r8unorm = "r8unorm"
|
|
329
|
+
r8snorm = "r8snorm"
|
|
330
|
+
r8uint = "r8uint"
|
|
331
|
+
r8sint = "r8sint"
|
|
332
|
+
|
|
333
|
+
# 16-bit formats
|
|
334
|
+
r16uint = "r16uint"
|
|
335
|
+
r16sint = "r16sint"
|
|
336
|
+
r16float = "r16float"
|
|
337
|
+
rg8unorm = "rg8unorm"
|
|
338
|
+
rg8snorm = "rg8snorm"
|
|
339
|
+
rg8uint = "rg8uint"
|
|
340
|
+
rg8sint = "rg8sint"
|
|
341
|
+
|
|
342
|
+
# 32-bit formats
|
|
343
|
+
r32uint = "r32uint"
|
|
344
|
+
r32sint = "r32sint"
|
|
345
|
+
r32float = "r32float"
|
|
346
|
+
rg16uint = "rg16uint"
|
|
347
|
+
rg16sint = "rg16sint"
|
|
348
|
+
rg16float = "rg16float"
|
|
349
|
+
rgba8unorm = "rgba8unorm"
|
|
350
|
+
rgba8unorm_srgb = "rgba8unorm-srgb"
|
|
351
|
+
rgba8snorm = "rgba8snorm"
|
|
352
|
+
rgba8uint = "rgba8uint"
|
|
353
|
+
rgba8sint = "rgba8sint"
|
|
354
|
+
bgra8unorm = "bgra8unorm"
|
|
355
|
+
bgra8unorm_srgb = "bgra8unorm-srgb"
|
|
356
|
+
# Packed 32-bit formats
|
|
357
|
+
rgb9e5ufloat = "rgb9e5ufloat"
|
|
358
|
+
rgb10a2uint = "rgb10a2uint"
|
|
359
|
+
rgb10a2unorm = "rgb10a2unorm"
|
|
360
|
+
rg11b10ufloat = "rg11b10ufloat"
|
|
361
|
+
|
|
362
|
+
# 64-bit formats
|
|
363
|
+
rg32uint = "rg32uint"
|
|
364
|
+
rg32sint = "rg32sint"
|
|
365
|
+
rg32float = "rg32float"
|
|
366
|
+
rgba16uint = "rgba16uint"
|
|
367
|
+
rgba16sint = "rgba16sint"
|
|
368
|
+
rgba16float = "rgba16float"
|
|
369
|
+
|
|
370
|
+
# 128-bit formats
|
|
371
|
+
rgba32uint = "rgba32uint"
|
|
372
|
+
rgba32sint = "rgba32sint"
|
|
373
|
+
rgba32float = "rgba32float"
|
|
374
|
+
|
|
375
|
+
# Depth/stencil formats
|
|
376
|
+
stencil8 = "stencil8"
|
|
377
|
+
depth16unorm = "depth16unorm"
|
|
378
|
+
depth24plus = "depth24plus"
|
|
379
|
+
depth24plus_stencil8 = "depth24plus-stencil8"
|
|
380
|
+
depth32float = "depth32float"
|
|
381
|
+
|
|
382
|
+
# "depth32float-stencil8" feature
|
|
383
|
+
depth32float_stencil8 = "depth32float-stencil8"
|
|
384
|
+
|
|
385
|
+
# BC compressed formats usable if "texture-compression-bc" is both
|
|
386
|
+
# supported by the device/user agent and enabled in requestDevice.
|
|
387
|
+
bc1_rgba_unorm = "bc1-rgba-unorm"
|
|
388
|
+
bc1_rgba_unorm_srgb = "bc1-rgba-unorm-srgb"
|
|
389
|
+
bc2_rgba_unorm = "bc2-rgba-unorm"
|
|
390
|
+
bc2_rgba_unorm_srgb = "bc2-rgba-unorm-srgb"
|
|
391
|
+
bc3_rgba_unorm = "bc3-rgba-unorm"
|
|
392
|
+
bc3_rgba_unorm_srgb = "bc3-rgba-unorm-srgb"
|
|
393
|
+
bc4_r_unorm = "bc4-r-unorm"
|
|
394
|
+
bc4_r_snorm = "bc4-r-snorm"
|
|
395
|
+
bc5_rg_unorm = "bc5-rg-unorm"
|
|
396
|
+
bc5_rg_snorm = "bc5-rg-snorm"
|
|
397
|
+
bc6h_rgb_ufloat = "bc6h-rgb-ufloat"
|
|
398
|
+
bc6h_rgb_float = "bc6h-rgb-float"
|
|
399
|
+
bc7_rgba_unorm = "bc7-rgba-unorm"
|
|
400
|
+
bc7_rgba_unorm_srgb = "bc7-rgba-unorm-srgb"
|
|
401
|
+
|
|
402
|
+
# ETC2 compressed formats usable if "texture-compression-etc2" is both
|
|
403
|
+
# supported by the device/user agent and enabled in requestDevice.
|
|
404
|
+
etc2_rgb8unorm = "etc2-rgb8unorm"
|
|
405
|
+
etc2_rgb8unorm_srgb = "etc2-rgb8unorm-srgb"
|
|
406
|
+
etc2_rgb8a1unorm = "etc2-rgb8a1unorm"
|
|
407
|
+
etc2_rgb8a1unorm_srgb = "etc2-rgb8a1unorm-srgb"
|
|
408
|
+
etc2_rgba8unorm = "etc2-rgba8unorm"
|
|
409
|
+
etc2_rgba8unorm_srgb = "etc2-rgba8unorm-srgb"
|
|
410
|
+
eac_r11unorm = "eac-r11unorm"
|
|
411
|
+
eac_r11snorm = "eac-r11snorm"
|
|
412
|
+
eac_rg11unorm = "eac-rg11unorm"
|
|
413
|
+
eac_rg11snorm = "eac-rg11snorm"
|
|
414
|
+
|
|
415
|
+
# ASTC compressed formats usable if "texture-compression-astc" is both
|
|
416
|
+
# supported by the device/user agent and enabled in requestDevice.
|
|
417
|
+
astc_4x4_unorm = "astc-4x4-unorm"
|
|
418
|
+
astc_4x4_unorm_srgb = "astc-4x4-unorm-srgb"
|
|
419
|
+
astc_5x4_unorm = "astc-5x4-unorm"
|
|
420
|
+
astc_5x4_unorm_srgb = "astc-5x4-unorm-srgb"
|
|
421
|
+
astc_5x5_unorm = "astc-5x5-unorm"
|
|
422
|
+
astc_5x5_unorm_srgb = "astc-5x5-unorm-srgb"
|
|
423
|
+
astc_6x5_unorm = "astc-6x5-unorm"
|
|
424
|
+
astc_6x5_unorm_srgb = "astc-6x5-unorm-srgb"
|
|
425
|
+
astc_6x6_unorm = "astc-6x6-unorm"
|
|
426
|
+
astc_6x6_unorm_srgb = "astc-6x6-unorm-srgb"
|
|
427
|
+
astc_8x5_unorm = "astc-8x5-unorm"
|
|
428
|
+
astc_8x5_unorm_srgb = "astc-8x5-unorm-srgb"
|
|
429
|
+
astc_8x6_unorm = "astc-8x6-unorm"
|
|
430
|
+
astc_8x6_unorm_srgb = "astc-8x6-unorm-srgb"
|
|
431
|
+
astc_8x8_unorm = "astc-8x8-unorm"
|
|
432
|
+
astc_8x8_unorm_srgb = "astc-8x8-unorm-srgb"
|
|
433
|
+
astc_10x5_unorm = "astc-10x5-unorm"
|
|
434
|
+
astc_10x5_unorm_srgb = "astc-10x5-unorm-srgb"
|
|
435
|
+
astc_10x6_unorm = "astc-10x6-unorm"
|
|
436
|
+
astc_10x6_unorm_srgb = "astc-10x6-unorm-srgb"
|
|
437
|
+
astc_10x8_unorm = "astc-10x8-unorm"
|
|
438
|
+
astc_10x8_unorm_srgb = "astc-10x8-unorm-srgb"
|
|
439
|
+
astc_10x10_unorm = "astc-10x10-unorm"
|
|
440
|
+
astc_10x10_unorm_srgb = "astc-10x10-unorm-srgb"
|
|
441
|
+
astc_12x10_unorm = "astc-12x10-unorm"
|
|
442
|
+
astc_12x10_unorm_srgb = "astc-12x10-unorm-srgb"
|
|
443
|
+
astc_12x12_unorm = "astc-12x12-unorm"
|
|
444
|
+
astc_12x12_unorm_srgb = "astc-12x12-unorm-srgb"
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
class TextureSampleType(str, Enum):
|
|
448
|
+
float = "float"
|
|
449
|
+
unfilterable_float = "unfilterable_float"
|
|
450
|
+
depth = "depth"
|
|
451
|
+
sint = "sint"
|
|
452
|
+
uint = "uint"
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
class VertexFormat(str, Enum):
|
|
456
|
+
uint8 = "uint8"
|
|
457
|
+
uint8x2 = "uint8x2"
|
|
458
|
+
uint8x4 = "uint8x4"
|
|
459
|
+
sint8 = "sint8"
|
|
460
|
+
sint8x2 = "sint8x2"
|
|
461
|
+
sint8x4 = "sint8x4"
|
|
462
|
+
unorm8 = "unorm8"
|
|
463
|
+
unorm8x2 = "unorm8x2"
|
|
464
|
+
unorm8x4 = "unorm8x4"
|
|
465
|
+
snorm8 = "snorm8"
|
|
466
|
+
snorm8x2 = "snorm8x2"
|
|
467
|
+
snorm8x4 = "snorm8x4"
|
|
468
|
+
uint16 = "uint16"
|
|
469
|
+
uint16x2 = "uint16x2"
|
|
470
|
+
uint16x4 = "uint16x4"
|
|
471
|
+
sint16 = "sint16"
|
|
472
|
+
sint16x2 = "sint16x2"
|
|
473
|
+
sint16x4 = "sint16x4"
|
|
474
|
+
unorm16 = "unorm16"
|
|
475
|
+
unorm16x2 = "unorm16x2"
|
|
476
|
+
unorm16x4 = "unorm16x4"
|
|
477
|
+
snorm16 = "snorm16"
|
|
478
|
+
snorm16x2 = "snorm16x2"
|
|
479
|
+
snorm16x4 = "snorm16x4"
|
|
480
|
+
float16 = "float16"
|
|
481
|
+
float16x2 = "float16x2"
|
|
482
|
+
float16x4 = "float16x4"
|
|
483
|
+
float32 = "float32"
|
|
484
|
+
float32x2 = "float32x2"
|
|
485
|
+
float32x3 = "float32x3"
|
|
486
|
+
float32x4 = "float32x4"
|
|
487
|
+
uint32 = "uint32"
|
|
488
|
+
uint32x2 = "uint32x2"
|
|
489
|
+
uint32x3 = "uint32x3"
|
|
490
|
+
uint32x4 = "uint32x4"
|
|
491
|
+
sint32 = "sint32"
|
|
492
|
+
sint32x2 = "sint32x2"
|
|
493
|
+
sint32x3 = "sint32x3"
|
|
494
|
+
sint32x4 = "sint32x4"
|
|
495
|
+
unorm10__10__10__2 = "unorm10__10__10__2"
|
|
496
|
+
unorm8x4_B_G_R_A = "unorm8x4_B_G_R_A"
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
class VertexStepMode(str, Enum):
|
|
500
|
+
vertex = "vertex"
|
|
501
|
+
instance = "instance"
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
class BufferUsage(IntFlag):
|
|
505
|
+
NONE = 0
|
|
506
|
+
MAP_READ = 0x01
|
|
507
|
+
MAP_WRITE = 0x02
|
|
508
|
+
COPY_SRC = 0x04
|
|
509
|
+
COPY_DST = 0x08
|
|
510
|
+
INDEX = 0x10
|
|
511
|
+
VERTEX = 0x20
|
|
512
|
+
UNIFORM = 0x40
|
|
513
|
+
STORAGE = 0x80
|
|
514
|
+
INDIRECT = 0x100
|
|
515
|
+
QUERY_RESOLVE = 0x200
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
class ColorWriteMask(IntFlag):
|
|
519
|
+
NONE = 0
|
|
520
|
+
RED = 1
|
|
521
|
+
GREEN = 2
|
|
522
|
+
BLUE = 4
|
|
523
|
+
ALPHA = 8
|
|
524
|
+
ALL = 15
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
class MapMode(IntFlag):
|
|
528
|
+
NONE = 0
|
|
529
|
+
READ = 1
|
|
530
|
+
WRITE = 2
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
class ShaderStage(IntFlag):
|
|
534
|
+
NONE = 0
|
|
535
|
+
VERTEX = 1
|
|
536
|
+
FRAGMENT = 2
|
|
537
|
+
COMPUTE = 4
|
|
538
|
+
ALL = 7
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
class TextureUsage(IntFlag):
|
|
542
|
+
NONE = 0
|
|
543
|
+
COPY_SRC = 1
|
|
544
|
+
COPY_DST = 2
|
|
545
|
+
TEXTURE_BINDING = 4
|
|
546
|
+
STORAGE_BINDING = 8
|
|
547
|
+
RENDER_ATTACHMENT = 16
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
@dataclass
|
|
551
|
+
class AdapterInfo(BaseWebGPUObject):
|
|
552
|
+
vendor: str = ""
|
|
553
|
+
architecture: str = ""
|
|
554
|
+
device: str = ""
|
|
555
|
+
description: str = ""
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
@dataclass
|
|
559
|
+
class BindGroupEntry(BaseWebGPUObject):
|
|
560
|
+
binding: int
|
|
561
|
+
resource: "Sampler | TextureView | Buffer"
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
@dataclass
|
|
565
|
+
class BindGroupDescriptor(BaseWebGPUObject):
|
|
566
|
+
layout: BindGroupLayout
|
|
567
|
+
entries: list[BindGroupEntry] = field(default_factory=list)
|
|
568
|
+
label: str = ""
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
@dataclass
|
|
572
|
+
class BindGroupLayoutDescriptor(BaseWebGPUObject):
|
|
573
|
+
label: str = ""
|
|
574
|
+
entries: list["BindGroupLayoutEntry"] = field(default_factory=list)
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
@dataclass
|
|
578
|
+
class BindGroupLayoutEntry(BaseWebGPUObject):
|
|
579
|
+
binding: int = 0
|
|
580
|
+
visibility: ShaderStage = ShaderStage.NONE
|
|
581
|
+
buffer: "BufferBindingLayout | None" = None
|
|
582
|
+
sampler: "SamplerBindingLayout | None" = None
|
|
583
|
+
texture: "TextureBindingLayout | None" = None
|
|
584
|
+
storageTexture: "StorageTextureBindingLayout | None" = None
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
@dataclass
|
|
588
|
+
class BlendComponent(BaseWebGPUObject):
|
|
589
|
+
operation: BlendOperation = BlendOperation.add
|
|
590
|
+
srcFactor: BlendFactor = BlendFactor.one
|
|
591
|
+
dstFactor: BlendFactor = BlendFactor.zero
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
@dataclass
|
|
595
|
+
class BlendState(BaseWebGPUObject):
|
|
596
|
+
color: BlendComponent
|
|
597
|
+
alpha: BlendComponent
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
@dataclass
|
|
601
|
+
class BufferBindingLayout(BaseWebGPUObject):
|
|
602
|
+
type: BufferBindingType = BufferBindingType.uniform
|
|
603
|
+
hasDynamicOffset: bool = False
|
|
604
|
+
minBindingSize: int = 0
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
@dataclass
|
|
608
|
+
class BufferDescriptor(BaseWebGPUObject):
|
|
609
|
+
size: int
|
|
610
|
+
usage: BufferUsage
|
|
611
|
+
mappedAtCreation: bool = False
|
|
612
|
+
label: str = ""
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
@dataclass
|
|
616
|
+
class Color(BaseWebGPUObject):
|
|
617
|
+
r: float = 0.0
|
|
618
|
+
g: float = 0.0
|
|
619
|
+
b: float = 0.0
|
|
620
|
+
a: float = 0.0
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
@dataclass
|
|
624
|
+
class ColorTargetState(BaseWebGPUObject):
|
|
625
|
+
format: TextureFormat
|
|
626
|
+
blend: BlendState | None = None
|
|
627
|
+
writeMask: ColorWriteMask = ColorWriteMask.ALL
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
@dataclass
|
|
631
|
+
class CommandBufferDescriptor(BaseWebGPUObject):
|
|
632
|
+
label: str = ""
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
@dataclass
|
|
636
|
+
class CommandEncoderDescriptor(BaseWebGPUObject):
|
|
637
|
+
label: str = ""
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
@dataclass
|
|
641
|
+
class CompilationMessage(BaseWebGPUObject):
|
|
642
|
+
message: str
|
|
643
|
+
type: CompilationMessageType
|
|
644
|
+
lineNum: int
|
|
645
|
+
linePos: int
|
|
646
|
+
offset: int
|
|
647
|
+
length: int
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
@dataclass
|
|
651
|
+
class CompilationInfo(BaseWebGPUObject):
|
|
652
|
+
messages: list[CompilationMessage] = field(default_factory=list)
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
@dataclass
|
|
656
|
+
class ComputePassDescriptor(BaseWebGPUObject):
|
|
657
|
+
timestampWrites: "PassTimestampWrites"
|
|
658
|
+
label: str = ""
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
@dataclass
|
|
662
|
+
class ComputeState(BaseWebGPUObject):
|
|
663
|
+
module: "ShaderModule"
|
|
664
|
+
entryPoint: str = ""
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
@dataclass
|
|
668
|
+
class ComputePipelineDescriptor(BaseWebGPUObject):
|
|
669
|
+
layout: "PipelineLayout"
|
|
670
|
+
compute: ComputeState
|
|
671
|
+
label: str = ""
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
@dataclass
|
|
675
|
+
class StencilFaceState(BaseWebGPUObject):
|
|
676
|
+
compare: "CompareFunction | None" = None
|
|
677
|
+
failOp: "StencilOperation | None" = None
|
|
678
|
+
depthFailOp: "StencilOperation | None" = None
|
|
679
|
+
passOp: "StencilOperation | None" = None
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
@dataclass
|
|
683
|
+
class DepthStencilState(BaseWebGPUObject):
|
|
684
|
+
format: TextureFormat
|
|
685
|
+
depthWriteEnabled: bool
|
|
686
|
+
depthCompare: CompareFunction
|
|
687
|
+
stencilFront: StencilFaceState = field(default_factory=StencilFaceState)
|
|
688
|
+
stencilBack: StencilFaceState = field(default_factory=StencilFaceState)
|
|
689
|
+
stencilReadMask: int = 0xFFFFFFFF
|
|
690
|
+
stencilWriteMask: int = 0xFFFFFFFF
|
|
691
|
+
depthBias: int = 0
|
|
692
|
+
depthBiasSlopeScale: float = 0.0
|
|
693
|
+
depthBiasClamp: float = 0.0
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
@dataclass
|
|
697
|
+
class Limits(BaseWebGPUObject):
|
|
698
|
+
maxTextureDimension1D: int | None = None
|
|
699
|
+
maxTextureDimension2D: int | None = None
|
|
700
|
+
maxTextureDimension3D: int | None = None
|
|
701
|
+
maxTextureArrayLayers: int | None = None
|
|
702
|
+
maxBindGroups: int | None = None
|
|
703
|
+
maxBindGroupsPlusVertexBuffers: int | None = None
|
|
704
|
+
maxBindingsPerBindGroup: int | None = None
|
|
705
|
+
maxDynamicUniformBuffersPerPipelineLayout: int | None = None
|
|
706
|
+
maxDynamicStorageBuffersPerPipelineLayout: int | None = None
|
|
707
|
+
maxSampledTexturesPerShaderStage: int | None = None
|
|
708
|
+
maxSamplersPerShaderStage: int | None = None
|
|
709
|
+
maxStorageBuffersPerShaderStage: int | None = None
|
|
710
|
+
maxStorageTexturesPerShaderStage: int | None = None
|
|
711
|
+
maxUniformBuffersPerShaderStage: int | None = None
|
|
712
|
+
maxUniformBufferBindingSize: int | None = None
|
|
713
|
+
maxStorageBufferBindingSize: int | None = None
|
|
714
|
+
minUniformBufferOffsetAlignment: int | None = None
|
|
715
|
+
minStorageBufferOffsetAlignment: int | None = None
|
|
716
|
+
maxVertexBuffers: int | None = None
|
|
717
|
+
maxBufferSize: int | None = None
|
|
718
|
+
maxVertexAttributes: int | None = None
|
|
719
|
+
maxVertexBufferArrayStride: int | None = None
|
|
720
|
+
maxInterStageShaderVariables: int | None = None
|
|
721
|
+
maxColorAttachments: int | None = None
|
|
722
|
+
maxColorAttachmentBytesPerSample: int | None = None
|
|
723
|
+
maxComputeWorkgroupStorageSize: int | None = None
|
|
724
|
+
maxComputeInvocationsPerWorkgroup: int | None = None
|
|
725
|
+
maxComputeWorkgroupSizeX: int | None = None
|
|
726
|
+
maxComputeWorkgroupSizeY: int | None = None
|
|
727
|
+
maxComputeWorkgroupSizeZ: int | None = None
|
|
728
|
+
maxComputeWorkgroupsPerDimension: int | None = None
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
@dataclass
|
|
732
|
+
class QueueDescriptor(BaseWebGPUObject):
|
|
733
|
+
label: str = ""
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
@dataclass
|
|
737
|
+
class DeviceDescriptor(BaseWebGPUObject):
|
|
738
|
+
requiredFeatures: list["FeatureName"] | None = None
|
|
739
|
+
requiredLimits: Limits | None = None
|
|
740
|
+
defaultQueue: QueueDescriptor | None = None
|
|
741
|
+
label: str = ""
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
@dataclass
|
|
745
|
+
class Extent3d(BaseWebGPUObject):
|
|
746
|
+
width: int = 0
|
|
747
|
+
height: int = 0
|
|
748
|
+
depthOrArrayLayers: int = 0
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
@dataclass
|
|
752
|
+
class FragmentState(BaseWebGPUObject):
|
|
753
|
+
module: "ShaderModule | None" = None
|
|
754
|
+
entryPoint: str = ""
|
|
755
|
+
targets: list[ColorTargetState] = field(default_factory=list)
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
@dataclass
|
|
759
|
+
class MultisampleState(BaseWebGPUObject):
|
|
760
|
+
count: int = 1
|
|
761
|
+
mask: int = 0xFFFFFFFF
|
|
762
|
+
alphaToCoverageEnabled: bool = False
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
@dataclass
|
|
766
|
+
class Origin3d(BaseWebGPUObject):
|
|
767
|
+
x: int = 0
|
|
768
|
+
y: int = 0
|
|
769
|
+
z: int = 0
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
@dataclass
|
|
773
|
+
class PassTimestampWrites(BaseWebGPUObject):
|
|
774
|
+
querySet: "QuerySet"
|
|
775
|
+
beginningOfPassWriteIndex: int
|
|
776
|
+
endOfPassWriteIndex: int
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
@dataclass
|
|
780
|
+
class PipelineLayoutDescriptor(BaseWebGPUObject):
|
|
781
|
+
bindGroupLayouts: list["BindGroupLayout"] = field(default_factory=list)
|
|
782
|
+
label: str = ""
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
@dataclass
|
|
786
|
+
class PrimitiveState(BaseWebGPUObject):
|
|
787
|
+
topology: "PrimitiveTopology | None" = None
|
|
788
|
+
stripIndexFormat: IndexFormat | None = None
|
|
789
|
+
frontFace: FrontFace = FrontFace.CCW
|
|
790
|
+
cullMode: CullMode = CullMode.none
|
|
791
|
+
unclippedDepth: bool = False
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
@dataclass
|
|
795
|
+
class QuerySetDescriptor(BaseWebGPUObject):
|
|
796
|
+
type: QueryType
|
|
797
|
+
count: int
|
|
798
|
+
label: str = ""
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
@dataclass
|
|
802
|
+
class RenderBundleDescriptor(BaseWebGPUObject):
|
|
803
|
+
label: str = ""
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
@dataclass
|
|
807
|
+
class RenderBundleEncoderDescriptor(BaseWebGPUObject):
|
|
808
|
+
colorFormats: list[TextureFormat]
|
|
809
|
+
depthStencilFormat: TextureFormat
|
|
810
|
+
sampleCount: int = 1
|
|
811
|
+
depthReadOnly: bool = False
|
|
812
|
+
stencilReadOnly: bool = False
|
|
813
|
+
label: str = ""
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
@dataclass
|
|
817
|
+
class RenderPassColorAttachment(BaseWebGPUObject):
|
|
818
|
+
view: TextureView
|
|
819
|
+
resolveTarget: TextureView | None = None
|
|
820
|
+
loadOp: LoadOp = LoadOp.load
|
|
821
|
+
storeOp: StoreOp = StoreOp.store
|
|
822
|
+
clearValue: Color = field(default_factory=Color)
|
|
823
|
+
depthSlice: int | None = None
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
@dataclass
|
|
827
|
+
class RenderPassDepthStencilAttachment(BaseWebGPUObject):
|
|
828
|
+
view: TextureView
|
|
829
|
+
depthLoadOp: LoadOp = LoadOp.load
|
|
830
|
+
depthStoreOp: StoreOp = StoreOp.store
|
|
831
|
+
depthClearValue: float = 0.0
|
|
832
|
+
depthReadOnly: bool = False
|
|
833
|
+
stencilClearValue: int = 0
|
|
834
|
+
stencilLoadOp: LoadOp | None = None
|
|
835
|
+
stencilStoreOp: StoreOp | None = None
|
|
836
|
+
stencilReadOnly: bool = False
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
@dataclass
|
|
840
|
+
class RenderPassDescriptor(BaseWebGPUObject):
|
|
841
|
+
colorAttachments: list[RenderPassColorAttachment]
|
|
842
|
+
depthStencilAttachment: RenderPassDepthStencilAttachment
|
|
843
|
+
occlusionQuerySet: "QuerySet | None" = None
|
|
844
|
+
timestampWrites: PassTimestampWrites | None = None
|
|
845
|
+
label: str = ""
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
@dataclass
|
|
849
|
+
class RenderPipelineDescriptor(BaseWebGPUObject):
|
|
850
|
+
layout: PipelineLayout | AutoLayoutMode
|
|
851
|
+
vertex: "VertexState"
|
|
852
|
+
fragment: "FragmentState"
|
|
853
|
+
depthStencil: "DepthStencilState"
|
|
854
|
+
primitive: PrimitiveState = field(default_factory=PrimitiveState)
|
|
855
|
+
multisample: MultisampleState = field(default_factory=MultisampleState)
|
|
856
|
+
label: str = ""
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
@dataclass
|
|
860
|
+
class RequestAdapterOptions(BaseWebGPUObject):
|
|
861
|
+
featureLevel: FeatureLevel | None = None
|
|
862
|
+
powerPreference: "PowerPreference | None" = None
|
|
863
|
+
forceFallbackAdapter: bool = False
|
|
864
|
+
xrCompatible: bool = False
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
async def requestAdapter(
|
|
868
|
+
featureLevel: FeatureLevel | None = None,
|
|
869
|
+
powerPreference: "PowerPreference | None" = None,
|
|
870
|
+
forceFallbackAdapter: bool = False,
|
|
871
|
+
xrCompatible: bool = False,
|
|
872
|
+
) -> "Adapter":
|
|
873
|
+
if not platform.js.navigator.gpu:
|
|
874
|
+
platform.js.alert("WebGPU is not supported")
|
|
875
|
+
sys.exit(1)
|
|
876
|
+
|
|
877
|
+
reqAdapter = platform.js.navigator.gpu.requestAdapter
|
|
878
|
+
options = RequestAdapterOptions(
|
|
879
|
+
featureLevel=featureLevel,
|
|
880
|
+
powerPreference=powerPreference,
|
|
881
|
+
forceFallbackAdapter=forceFallbackAdapter,
|
|
882
|
+
xrCompatible=xrCompatible,
|
|
883
|
+
).toJS()
|
|
884
|
+
print("requestAdapter", reqAdapter, options)
|
|
885
|
+
handle = reqAdapter(options)
|
|
886
|
+
try:
|
|
887
|
+
handle = await handle
|
|
888
|
+
except:
|
|
889
|
+
pass
|
|
890
|
+
if not handle:
|
|
891
|
+
platform.js.alert("WebGPU is not supported")
|
|
892
|
+
sys.exit(1)
|
|
893
|
+
return Adapter(handle)
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
@dataclass
|
|
897
|
+
class SamplerBindingLayout(BaseWebGPUObject):
|
|
898
|
+
type: SamplerBindingType = SamplerBindingType.filtering
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
@dataclass
|
|
902
|
+
class SamplerDescriptor(BaseWebGPUObject):
|
|
903
|
+
label: str = ""
|
|
904
|
+
addressModeU: AddressMode = AddressMode.clamp_to_edge
|
|
905
|
+
addressModeV: AddressMode = AddressMode.clamp_to_edge
|
|
906
|
+
addressModeW: AddressMode = AddressMode.clamp_to_edge
|
|
907
|
+
magFilter: FilterMode = FilterMode.nearest
|
|
908
|
+
minFilter: FilterMode = FilterMode.nearest
|
|
909
|
+
mipmapFilter: MipmapFilterMode = MipmapFilterMode.nearest
|
|
910
|
+
lodMinClamp: float = 0.0
|
|
911
|
+
lodMaxClamp: float = 32
|
|
912
|
+
compare: "CompareFunction | None" = None
|
|
913
|
+
maxAnisotropy: int = 1
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
@dataclass
|
|
917
|
+
class ShaderModuleCompilationHint(BaseWebGPUObject):
|
|
918
|
+
entryPoint: str
|
|
919
|
+
layout: PipelineLayout | AutoLayoutMode
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
@dataclass
|
|
923
|
+
class ShaderModuleDescriptor(BaseWebGPUObject):
|
|
924
|
+
code: str
|
|
925
|
+
compilationHints: list["ShaderModuleCompilationHint"] = field(default_factory=list)
|
|
926
|
+
label: str = ""
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
@dataclass
|
|
930
|
+
class StorageTextureBindingLayout(BaseWebGPUObject):
|
|
931
|
+
format: TextureFormat
|
|
932
|
+
access: StorageTextureAccess = StorageTextureAccess.write_only
|
|
933
|
+
viewDimension: str = "2d"
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
@dataclass
|
|
937
|
+
class TexelCopyBufferLayout(BaseWebGPUObject):
|
|
938
|
+
bytesPerRow: int
|
|
939
|
+
offset: int = 0
|
|
940
|
+
rowsPerImage: int | None = None
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
@dataclass
|
|
944
|
+
class TexelCopyBufferInfo(BaseWebGPUObject):
|
|
945
|
+
layout: TexelCopyBufferLayout
|
|
946
|
+
buffer: "Buffer"
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
@dataclass
|
|
950
|
+
class TexelCopyTextureInfo(BaseWebGPUObject):
|
|
951
|
+
texture: "Texture"
|
|
952
|
+
mipLevel: int = 0
|
|
953
|
+
origin: Origin3d = field(default_factory=Origin3d)
|
|
954
|
+
aspect: TextureAspect = TextureAspect.all
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
@dataclass
|
|
958
|
+
class TextureBindingLayout(BaseWebGPUObject):
|
|
959
|
+
sampleType: TextureSampleType = TextureSampleType.float
|
|
960
|
+
viewDimension: str = "2d"
|
|
961
|
+
multisampled: bool = False
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
@dataclass
|
|
965
|
+
class TextureDescriptor(BaseWebGPUObject):
|
|
966
|
+
size: list
|
|
967
|
+
usage: TextureUsage
|
|
968
|
+
format: TextureFormat
|
|
969
|
+
sampleCount: int = 1
|
|
970
|
+
dimension: str = "2d"
|
|
971
|
+
mipLevelCount: int = 1
|
|
972
|
+
viewFormats: list["TextureFormat"] | None = None
|
|
973
|
+
label: str = ""
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
@dataclass
|
|
977
|
+
class TextureViewDescriptor(BaseWebGPUObject):
|
|
978
|
+
format: TextureFormat
|
|
979
|
+
dimension: str
|
|
980
|
+
baseMipLevel: int = 0
|
|
981
|
+
mipLevelCount: int = 1
|
|
982
|
+
baseArrayLayer: int = 0
|
|
983
|
+
arrayLayerCount: int = 0
|
|
984
|
+
aspect: TextureAspect = TextureAspect.all
|
|
985
|
+
usage: TextureUsage = TextureUsage.NONE
|
|
986
|
+
label: str = ""
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
@dataclass
|
|
990
|
+
class VertexAttribute(BaseWebGPUObject):
|
|
991
|
+
format: VertexFormat
|
|
992
|
+
offset: int
|
|
993
|
+
shaderLocation: int
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
@dataclass
|
|
997
|
+
class VertexBufferLayout(BaseWebGPUObject):
|
|
998
|
+
arrayStride: int
|
|
999
|
+
stepMode: VertexStepMode = VertexStepMode.vertex
|
|
1000
|
+
attributes: list["VertexAttribute"] = field(default_factory=list)
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
@dataclass
|
|
1004
|
+
class VertexState(BaseWebGPUObject):
|
|
1005
|
+
module: "ShaderModule"
|
|
1006
|
+
entryPoint: str = ""
|
|
1007
|
+
buffers: list["VertexBufferLayout"] = field(default_factory=list)
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
class Adapter(BaseWebGPUHandle):
|
|
1011
|
+
|
|
1012
|
+
@property
|
|
1013
|
+
def limits(self) -> Limits:
|
|
1014
|
+
return self.handle.limits
|
|
1015
|
+
|
|
1016
|
+
@property
|
|
1017
|
+
def features(self) -> list[FeatureName]:
|
|
1018
|
+
return [FeatureName(f) for f in self.handle.features]
|
|
1019
|
+
|
|
1020
|
+
@property
|
|
1021
|
+
def info(self) -> AdapterInfo:
|
|
1022
|
+
return self.handle.info
|
|
1023
|
+
|
|
1024
|
+
@property
|
|
1025
|
+
def isFallbackAdapter(self) -> bool:
|
|
1026
|
+
return self.handle.isFallbackAdapter
|
|
1027
|
+
|
|
1028
|
+
async def requestDevice(
|
|
1029
|
+
self,
|
|
1030
|
+
requiredFeatures: list["FeatureName"] | None = None,
|
|
1031
|
+
requiredLimits: Limits | None = None,
|
|
1032
|
+
defaultQueue: QueueDescriptor | None = None,
|
|
1033
|
+
label: str = "",
|
|
1034
|
+
) -> "Device":
|
|
1035
|
+
|
|
1036
|
+
device = self.handle.requestDevice(
|
|
1037
|
+
DeviceDescriptor(
|
|
1038
|
+
requiredFeatures=requiredFeatures,
|
|
1039
|
+
requiredLimits=requiredLimits.toJS() if requiredLimits else None,
|
|
1040
|
+
defaultQueue=defaultQueue,
|
|
1041
|
+
label=label,
|
|
1042
|
+
).toJS()
|
|
1043
|
+
)
|
|
1044
|
+
|
|
1045
|
+
try:
|
|
1046
|
+
device = await device
|
|
1047
|
+
except:
|
|
1048
|
+
pass
|
|
1049
|
+
return Device(device)
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
class Buffer(BaseWebGPUHandle):
|
|
1053
|
+
async def mapAsync(self, mode: MapMode, offset: int = 0, size: int = 0) -> None:
|
|
1054
|
+
return await self.handle.mapAsync(mode, offset, size)
|
|
1055
|
+
|
|
1056
|
+
def getMappedRange(self, offset: int = 0, size: int = 0) -> int:
|
|
1057
|
+
return self.handle.getMappedRange(offset, size)
|
|
1058
|
+
|
|
1059
|
+
def getConstMappedRange(self, offset: int = 0, size: int = 0) -> int:
|
|
1060
|
+
return self.handle.getConstMappedRange(offset, size)
|
|
1061
|
+
|
|
1062
|
+
@property
|
|
1063
|
+
def usage(self) -> BufferUsage:
|
|
1064
|
+
return self.handle.usage
|
|
1065
|
+
|
|
1066
|
+
@property
|
|
1067
|
+
def size(self) -> int:
|
|
1068
|
+
return self.handle.size
|
|
1069
|
+
|
|
1070
|
+
@property
|
|
1071
|
+
def mapState(self) -> BufferMapState:
|
|
1072
|
+
return self.handle.mapState
|
|
1073
|
+
|
|
1074
|
+
def unmap(self) -> None:
|
|
1075
|
+
self.handle.unmap()
|
|
1076
|
+
|
|
1077
|
+
def destroy(self) -> None:
|
|
1078
|
+
self.handle.destroy()
|
|
1079
|
+
|
|
1080
|
+
def __del__(self):
|
|
1081
|
+
self.destroy()
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
class CommandEncoder(BaseWebGPUHandle):
|
|
1085
|
+
_first_render_pass: bool = True
|
|
1086
|
+
|
|
1087
|
+
def __init__(self, handle):
|
|
1088
|
+
super().__init__(handle)
|
|
1089
|
+
self._first_render_pass = True
|
|
1090
|
+
|
|
1091
|
+
def getLoadOp(self) -> LoadOp:
|
|
1092
|
+
if self._first_render_pass:
|
|
1093
|
+
self._first_render_pass = False
|
|
1094
|
+
return LoadOp.clear
|
|
1095
|
+
return LoadOp.load
|
|
1096
|
+
|
|
1097
|
+
def finish(self, label: str = "") -> "CommandBuffer":
|
|
1098
|
+
return self.handle.finish(CommandBufferDescriptor(label=label).toJS())
|
|
1099
|
+
|
|
1100
|
+
def beginComputePass(
|
|
1101
|
+
self, timestampWrites: PassTimestampWrites | None = None, label: str = ""
|
|
1102
|
+
) -> "ComputePassEncoder":
|
|
1103
|
+
return self.handle.beginComputePass(
|
|
1104
|
+
ComputePassDescriptor(timestampWrites=timestampWrites, label=label).toJS()
|
|
1105
|
+
)
|
|
1106
|
+
|
|
1107
|
+
def beginRenderPass(
|
|
1108
|
+
self,
|
|
1109
|
+
colorAttachments: list[RenderPassColorAttachment],
|
|
1110
|
+
depthStencilAttachment: RenderPassDepthStencilAttachment,
|
|
1111
|
+
occlusionQuerySet: "QuerySet | None" = None,
|
|
1112
|
+
timestampWrites: PassTimestampWrites | None = None,
|
|
1113
|
+
label: str = "",
|
|
1114
|
+
) -> "RenderPassEncoder":
|
|
1115
|
+
|
|
1116
|
+
return self.handle.beginRenderPass(
|
|
1117
|
+
RenderPassDescriptor(
|
|
1118
|
+
colorAttachments=colorAttachments,
|
|
1119
|
+
depthStencilAttachment=depthStencilAttachment,
|
|
1120
|
+
occlusionQuerySet=occlusionQuerySet,
|
|
1121
|
+
timestampWrites=timestampWrites,
|
|
1122
|
+
label=label,
|
|
1123
|
+
).toJS()
|
|
1124
|
+
)
|
|
1125
|
+
|
|
1126
|
+
def copyBufferToBuffer(
|
|
1127
|
+
self, source: Buffer, sourceOffset, destination: Buffer, destinationOffset, size
|
|
1128
|
+
) -> None:
|
|
1129
|
+
return self.handle.copyBufferToBuffer(
|
|
1130
|
+
source.handle, sourceOffset, destination.handle, destinationOffset, size
|
|
1131
|
+
)
|
|
1132
|
+
|
|
1133
|
+
def copyBufferToTexture(
|
|
1134
|
+
self,
|
|
1135
|
+
source: TexelCopyBufferInfo,
|
|
1136
|
+
destination: TexelCopyTextureInfo,
|
|
1137
|
+
copySize: list,
|
|
1138
|
+
) -> None:
|
|
1139
|
+
return self.handle.copyBufferToTexture(source.toJS(), destination.toJS(), copySize)
|
|
1140
|
+
|
|
1141
|
+
def copyTextureToBuffer(
|
|
1142
|
+
self,
|
|
1143
|
+
source: TexelCopyTextureInfo,
|
|
1144
|
+
destination: TexelCopyBufferInfo,
|
|
1145
|
+
copySize: list,
|
|
1146
|
+
) -> None:
|
|
1147
|
+
return self.handle.copyTextureToBuffer(source.toJS(), destination.toJS(), copySize)
|
|
1148
|
+
|
|
1149
|
+
def copyTextureToTexture(
|
|
1150
|
+
self,
|
|
1151
|
+
source: TexelCopyTextureInfo,
|
|
1152
|
+
destination: TexelCopyTextureInfo,
|
|
1153
|
+
copySize: list,
|
|
1154
|
+
) -> None:
|
|
1155
|
+
return self.handle.copyTextureToTexture(source.toJS(), destination.toJS(), copySize)
|
|
1156
|
+
|
|
1157
|
+
def clearBuffer(self, buffer: Buffer, offset: int = 0, size: int = 0) -> None:
|
|
1158
|
+
return self.handle.clearBuffer(buffer.handle, offset, size)
|
|
1159
|
+
|
|
1160
|
+
def insertDebugMarker(self, markerLabel: str = "") -> None:
|
|
1161
|
+
return self.handle.insertDebugMarker(markerLabel)
|
|
1162
|
+
|
|
1163
|
+
def popDebugGroup(self) -> None:
|
|
1164
|
+
return self.handle.popDebugGroup()
|
|
1165
|
+
|
|
1166
|
+
def pushDebugGroup(self, groupLabel: str = "") -> None:
|
|
1167
|
+
return self.handle.pushDebugGroup(groupLabel)
|
|
1168
|
+
|
|
1169
|
+
def resolveQuerySet(
|
|
1170
|
+
self,
|
|
1171
|
+
querySet: "QuerySet",
|
|
1172
|
+
firstQuery: int,
|
|
1173
|
+
queryCount: int,
|
|
1174
|
+
destination: Buffer,
|
|
1175
|
+
destinationOffset: int = 0,
|
|
1176
|
+
) -> None:
|
|
1177
|
+
return self.handle.resolveQuerySet(
|
|
1178
|
+
querySet, firstQuery, queryCount, destination.handle, destinationOffset
|
|
1179
|
+
)
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
class ComputePassEncoder(BaseWebGPUHandle):
|
|
1183
|
+
def insertDebugMarker(self, markerLabel: str = "") -> None:
|
|
1184
|
+
return self.handle.insertDebugMarker(markerLabel)
|
|
1185
|
+
|
|
1186
|
+
def popDebugGroup(self) -> None:
|
|
1187
|
+
return self.handle.popDebugGroup()
|
|
1188
|
+
|
|
1189
|
+
def pushDebugGroup(self, groupLabel: str = "") -> None:
|
|
1190
|
+
return self.handle.pushDebugGroup(groupLabel)
|
|
1191
|
+
|
|
1192
|
+
def setPipeline(self, pipeline: "ComputePipeline | None" = None) -> None:
|
|
1193
|
+
return self.handle.setPipeline(pipeline)
|
|
1194
|
+
|
|
1195
|
+
def setBindGroup(
|
|
1196
|
+
self,
|
|
1197
|
+
index: int,
|
|
1198
|
+
bindGroup: BindGroup,
|
|
1199
|
+
dynamicOffsets: list[int] = [],
|
|
1200
|
+
) -> None:
|
|
1201
|
+
return self.handle.setBindGroup(index, bindGroup, dynamicOffsets)
|
|
1202
|
+
|
|
1203
|
+
def dispatchWorkgroups(
|
|
1204
|
+
self,
|
|
1205
|
+
workgroupCountX: int,
|
|
1206
|
+
workgroupCountY: int = 0,
|
|
1207
|
+
workgroupCountZ: int = 0,
|
|
1208
|
+
) -> None:
|
|
1209
|
+
return self.handle.dispatchWorkgroups(workgroupCountX, workgroupCountY, workgroupCountZ)
|
|
1210
|
+
|
|
1211
|
+
def dispatchWorkgroupsIndirect(self, indirectBuffer: Buffer, indirectOffset: int = 0) -> None:
|
|
1212
|
+
return self.handle.dispatchWorkgroupsIndirect(indirectBuffer.handle, indirectOffset)
|
|
1213
|
+
|
|
1214
|
+
def end(self) -> None:
|
|
1215
|
+
return self.handle.end()
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
class ComputePipeline(BaseWebGPUHandle):
|
|
1219
|
+
def getBindGroupLayout(self, groupIndex: int = 0) -> BindGroupLayout:
|
|
1220
|
+
return self.handle.getBindGroupLayout(groupIndex)
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
class Device(BaseWebGPUHandle):
|
|
1224
|
+
def createBindGroup(
|
|
1225
|
+
self,
|
|
1226
|
+
layout: "BindGroupLayout",
|
|
1227
|
+
entries: list["BindGroupEntry"] = field(default_factory=list),
|
|
1228
|
+
label: str = "",
|
|
1229
|
+
) -> BindGroup:
|
|
1230
|
+
|
|
1231
|
+
return self.handle.createBindGroup(
|
|
1232
|
+
BindGroupDescriptor(
|
|
1233
|
+
layout=layout,
|
|
1234
|
+
entries=entries,
|
|
1235
|
+
label=label,
|
|
1236
|
+
).toJS()
|
|
1237
|
+
)
|
|
1238
|
+
|
|
1239
|
+
def createBindGroupLayout(
|
|
1240
|
+
self,
|
|
1241
|
+
entries: list["BindGroupLayoutEntry"] = field(default_factory=list),
|
|
1242
|
+
label: str = "",
|
|
1243
|
+
) -> "BindGroupLayout":
|
|
1244
|
+
return self.handle.createBindGroupLayout(
|
|
1245
|
+
BindGroupLayoutDescriptor(entries=entries, label=label).toJS()
|
|
1246
|
+
)
|
|
1247
|
+
|
|
1248
|
+
def createBuffer(
|
|
1249
|
+
self,
|
|
1250
|
+
size: int,
|
|
1251
|
+
usage: BufferUsage,
|
|
1252
|
+
mappedAtCreation: bool = False,
|
|
1253
|
+
label: str = "",
|
|
1254
|
+
) -> Buffer:
|
|
1255
|
+
return Buffer(
|
|
1256
|
+
self.handle.createBuffer(
|
|
1257
|
+
BufferDescriptor(
|
|
1258
|
+
size=size,
|
|
1259
|
+
usage=usage,
|
|
1260
|
+
mappedAtCreation=mappedAtCreation,
|
|
1261
|
+
label=label,
|
|
1262
|
+
).toJS()
|
|
1263
|
+
)
|
|
1264
|
+
)
|
|
1265
|
+
|
|
1266
|
+
def createCommandEncoder(
|
|
1267
|
+
self,
|
|
1268
|
+
label: str = "",
|
|
1269
|
+
) -> CommandEncoder:
|
|
1270
|
+
return CommandEncoder(
|
|
1271
|
+
self.handle.createCommandEncoder(CommandEncoderDescriptor(label=label).toJS())
|
|
1272
|
+
)
|
|
1273
|
+
|
|
1274
|
+
async def createComputePipelineAsync(
|
|
1275
|
+
self,
|
|
1276
|
+
layout: "PipelineLayout",
|
|
1277
|
+
compute: ComputeState,
|
|
1278
|
+
label: str = "",
|
|
1279
|
+
) -> ComputePipeline:
|
|
1280
|
+
return await self.handle.createComputePipelineAsync(
|
|
1281
|
+
ComputePipelineDescriptor(
|
|
1282
|
+
layout=layout,
|
|
1283
|
+
compute=compute,
|
|
1284
|
+
label=label,
|
|
1285
|
+
).toJS()
|
|
1286
|
+
)
|
|
1287
|
+
|
|
1288
|
+
def createComputePipeline(
|
|
1289
|
+
self,
|
|
1290
|
+
layout: "PipelineLayout",
|
|
1291
|
+
compute: ComputeState,
|
|
1292
|
+
label: str = "",
|
|
1293
|
+
) -> ComputePipeline:
|
|
1294
|
+
return self.handle.createComputePipeline(
|
|
1295
|
+
ComputePipelineDescriptor(
|
|
1296
|
+
layout=layout,
|
|
1297
|
+
compute=compute,
|
|
1298
|
+
label=label,
|
|
1299
|
+
).toJS()
|
|
1300
|
+
)
|
|
1301
|
+
|
|
1302
|
+
def createPipelineLayout(
|
|
1303
|
+
self,
|
|
1304
|
+
bindGroupLayouts: list[BindGroupLayout] = [],
|
|
1305
|
+
label: str = "",
|
|
1306
|
+
) -> PipelineLayout:
|
|
1307
|
+
return self.handle.createPipelineLayout(
|
|
1308
|
+
PipelineLayoutDescriptor(bindGroupLayouts=bindGroupLayouts, label=label).toJS()
|
|
1309
|
+
)
|
|
1310
|
+
|
|
1311
|
+
def createQuerySet(self, count: int, label: str = "") -> "QuerySet":
|
|
1312
|
+
return self.handle.createQuerySet(
|
|
1313
|
+
QuerySetDescriptor(type=QueryType.occlusion, count=count, label=label).toJS()
|
|
1314
|
+
)
|
|
1315
|
+
|
|
1316
|
+
def createRenderPipeline(
|
|
1317
|
+
self,
|
|
1318
|
+
layout: PipelineLayout | AutoLayoutMode,
|
|
1319
|
+
vertex: VertexState,
|
|
1320
|
+
fragment: FragmentState,
|
|
1321
|
+
depthStencil: DepthStencilState,
|
|
1322
|
+
primitive: PrimitiveState = field(default_factory=PrimitiveState),
|
|
1323
|
+
multisample: MultisampleState = field(default_factory=MultisampleState),
|
|
1324
|
+
label: str = "",
|
|
1325
|
+
) -> None:
|
|
1326
|
+
return self.handle.createRenderPipeline(
|
|
1327
|
+
RenderPipelineDescriptor(
|
|
1328
|
+
layout=layout,
|
|
1329
|
+
vertex=vertex,
|
|
1330
|
+
fragment=fragment,
|
|
1331
|
+
depthStencil=depthStencil,
|
|
1332
|
+
primitive=primitive,
|
|
1333
|
+
multisample=multisample,
|
|
1334
|
+
label=label,
|
|
1335
|
+
).toJS()
|
|
1336
|
+
)
|
|
1337
|
+
|
|
1338
|
+
async def createRenderPipelineAsync(
|
|
1339
|
+
self,
|
|
1340
|
+
layout: "PipelineLayout",
|
|
1341
|
+
vertex: "VertexState",
|
|
1342
|
+
fragment: "FragmentState",
|
|
1343
|
+
depthStencil: "DepthStencilState",
|
|
1344
|
+
primitive: "PrimitiveState" = field(default_factory=PrimitiveState),
|
|
1345
|
+
multisample: "MultisampleState" = field(default_factory=MultisampleState),
|
|
1346
|
+
label: str = "",
|
|
1347
|
+
) -> None:
|
|
1348
|
+
return await self.handle.createRenderPipelineAsync(
|
|
1349
|
+
RenderPipelineDescriptor(
|
|
1350
|
+
layout=layout,
|
|
1351
|
+
vertex=vertex,
|
|
1352
|
+
fragment=fragment,
|
|
1353
|
+
depthStencil=depthStencil,
|
|
1354
|
+
primitive=primitive,
|
|
1355
|
+
multisample=multisample,
|
|
1356
|
+
label=label,
|
|
1357
|
+
).toJS()
|
|
1358
|
+
)
|
|
1359
|
+
|
|
1360
|
+
def createRenderBundleEncoder(self, label: str = "") -> "RenderBundleEncoder":
|
|
1361
|
+
return self.handle.createRenderBundleEncoder(RenderBundleDescriptor(label=label).toJS())
|
|
1362
|
+
|
|
1363
|
+
def createSampler(
|
|
1364
|
+
self,
|
|
1365
|
+
addressModeU: AddressMode = AddressMode.clamp_to_edge,
|
|
1366
|
+
addressModeV: AddressMode = AddressMode.clamp_to_edge,
|
|
1367
|
+
addressModeW: AddressMode = AddressMode.clamp_to_edge,
|
|
1368
|
+
magFilter: FilterMode = FilterMode.nearest,
|
|
1369
|
+
minFilter: FilterMode = FilterMode.nearest,
|
|
1370
|
+
mipmapFilter: MipmapFilterMode = MipmapFilterMode.nearest,
|
|
1371
|
+
lodMinClamp: float = 0.0,
|
|
1372
|
+
lodMaxClamp: float = 32,
|
|
1373
|
+
compare: "CompareFunction | None" = None,
|
|
1374
|
+
maxAnisotropy: int = 1,
|
|
1375
|
+
label: str = "",
|
|
1376
|
+
):
|
|
1377
|
+
return self.handle.createSampler(
|
|
1378
|
+
SamplerDescriptor(
|
|
1379
|
+
addressModeU=addressModeU,
|
|
1380
|
+
addressModeV=addressModeV,
|
|
1381
|
+
addressModeW=addressModeW,
|
|
1382
|
+
magFilter=magFilter,
|
|
1383
|
+
minFilter=minFilter,
|
|
1384
|
+
mipmapFilter=mipmapFilter,
|
|
1385
|
+
lodMinClamp=lodMinClamp,
|
|
1386
|
+
lodMaxClamp=lodMaxClamp,
|
|
1387
|
+
compare=compare,
|
|
1388
|
+
maxAnisotropy=maxAnisotropy,
|
|
1389
|
+
label=label,
|
|
1390
|
+
).toJS()
|
|
1391
|
+
)
|
|
1392
|
+
|
|
1393
|
+
def createShaderModule(
|
|
1394
|
+
self,
|
|
1395
|
+
code: str,
|
|
1396
|
+
compilationHints: list[ShaderModuleCompilationHint] = [],
|
|
1397
|
+
label: str = "",
|
|
1398
|
+
) -> "ShaderModule":
|
|
1399
|
+
return self.handle.createShaderModule(
|
|
1400
|
+
ShaderModuleDescriptor(
|
|
1401
|
+
code=code,
|
|
1402
|
+
compilationHints=compilationHints,
|
|
1403
|
+
label=label,
|
|
1404
|
+
).toJS()
|
|
1405
|
+
)
|
|
1406
|
+
|
|
1407
|
+
def createTexture(
|
|
1408
|
+
self,
|
|
1409
|
+
size: list,
|
|
1410
|
+
usage: TextureUsage,
|
|
1411
|
+
format: TextureFormat,
|
|
1412
|
+
sampleCount: int = 1,
|
|
1413
|
+
dimension: str = "2d",
|
|
1414
|
+
mipLevelCount: int = 1,
|
|
1415
|
+
viewFormats: list["TextureFormat"] | None = None,
|
|
1416
|
+
label: str = "",
|
|
1417
|
+
) -> "Texture":
|
|
1418
|
+
return self.handle.createTexture(
|
|
1419
|
+
TextureDescriptor(
|
|
1420
|
+
size=size,
|
|
1421
|
+
usage=usage,
|
|
1422
|
+
format=format,
|
|
1423
|
+
sampleCount=sampleCount,
|
|
1424
|
+
dimension=dimension,
|
|
1425
|
+
mipLevelCount=mipLevelCount,
|
|
1426
|
+
viewFormats=viewFormats,
|
|
1427
|
+
label=label,
|
|
1428
|
+
).toJS()
|
|
1429
|
+
)
|
|
1430
|
+
|
|
1431
|
+
def destroy(self) -> None:
|
|
1432
|
+
return self.handle.destroy()
|
|
1433
|
+
|
|
1434
|
+
def __del__(self):
|
|
1435
|
+
self.destroy()
|
|
1436
|
+
|
|
1437
|
+
@property
|
|
1438
|
+
def limits(self) -> Limits:
|
|
1439
|
+
return self.handle.limits
|
|
1440
|
+
|
|
1441
|
+
@property
|
|
1442
|
+
def features(self) -> list[FeatureName]:
|
|
1443
|
+
return [FeatureName(f) for f in self.handle.features]
|
|
1444
|
+
|
|
1445
|
+
@property
|
|
1446
|
+
def adapterInfo(self) -> AdapterInfo:
|
|
1447
|
+
return self.handle.adapterInfo
|
|
1448
|
+
|
|
1449
|
+
@property
|
|
1450
|
+
def queue(self) -> "Queue":
|
|
1451
|
+
return Queue(self.handle.queue)
|
|
1452
|
+
|
|
1453
|
+
def pushErrorScope(self, filter: ErrorFilter) -> None:
|
|
1454
|
+
return self.handle.pushErrorScope(filter)
|
|
1455
|
+
|
|
1456
|
+
def popErrorScope(self) -> None:
|
|
1457
|
+
return self.handle.popErrorScope()
|
|
1458
|
+
|
|
1459
|
+
|
|
1460
|
+
class Queue(BaseWebGPUHandle):
|
|
1461
|
+
def submit(self, commands: list[CommandBuffer] = []) -> None:
|
|
1462
|
+
return self.handle.submit(commands)
|
|
1463
|
+
|
|
1464
|
+
def onSubmittedWorkDone(self) -> JsPromise:
|
|
1465
|
+
return self.handle.onSubmittedWorkDone()
|
|
1466
|
+
|
|
1467
|
+
def writeBuffer(
|
|
1468
|
+
self,
|
|
1469
|
+
buffer: Buffer,
|
|
1470
|
+
bufferOffset: int,
|
|
1471
|
+
data: bytes,
|
|
1472
|
+
dataOffset: int = 0,
|
|
1473
|
+
size: int | None = None,
|
|
1474
|
+
):
|
|
1475
|
+
self.handle.writeBuffer(
|
|
1476
|
+
buffer.handle,
|
|
1477
|
+
bufferOffset,
|
|
1478
|
+
toJS(memoryview(data)),
|
|
1479
|
+
dataOffset,
|
|
1480
|
+
size,
|
|
1481
|
+
)
|
|
1482
|
+
|
|
1483
|
+
def writeTexture(
|
|
1484
|
+
self,
|
|
1485
|
+
destination: TexelCopyTextureInfo,
|
|
1486
|
+
data: bytes,
|
|
1487
|
+
dataLayout: TexelCopyBufferLayout,
|
|
1488
|
+
size: list,
|
|
1489
|
+
) -> None:
|
|
1490
|
+
return self.handle.writeTexture(
|
|
1491
|
+
destination.toJS(),
|
|
1492
|
+
toJS(memoryview(bytes(data))),
|
|
1493
|
+
dataLayout.toJS(),
|
|
1494
|
+
size,
|
|
1495
|
+
)
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
class RenderBundleEncoder(BaseWebGPUHandle):
|
|
1499
|
+
def setPipeline(self, pipeline: "RenderPipeline | None" = None) -> None:
|
|
1500
|
+
self.handle.setPipeline(pipeline)
|
|
1501
|
+
|
|
1502
|
+
def setBindGroup(
|
|
1503
|
+
self,
|
|
1504
|
+
groupIndex: int = 0,
|
|
1505
|
+
group: "BindGroup | None" = None,
|
|
1506
|
+
dynamicOffsets: list[int] = [],
|
|
1507
|
+
) -> None:
|
|
1508
|
+
return self.handle.setBindGroup(groupIndex, group, dynamicOffsets)
|
|
1509
|
+
|
|
1510
|
+
def draw(
|
|
1511
|
+
self,
|
|
1512
|
+
vertexCount: int = 0,
|
|
1513
|
+
instanceCount: int = 0,
|
|
1514
|
+
firstVertex: int = 0,
|
|
1515
|
+
firstInstance: int = 0,
|
|
1516
|
+
) -> None:
|
|
1517
|
+
return self.handle.draw(vertexCount, instanceCount, firstVertex, firstInstance)
|
|
1518
|
+
|
|
1519
|
+
def drawIndexed(
|
|
1520
|
+
self,
|
|
1521
|
+
indexCount: int = 0,
|
|
1522
|
+
instanceCount: int = 0,
|
|
1523
|
+
firstIndex: int = 0,
|
|
1524
|
+
baseVertex: int = 0,
|
|
1525
|
+
firstInstance: int = 0,
|
|
1526
|
+
) -> None:
|
|
1527
|
+
return self.handle.drawIndexed(
|
|
1528
|
+
indexCount, instanceCount, firstIndex, baseVertex, firstInstance
|
|
1529
|
+
)
|
|
1530
|
+
|
|
1531
|
+
def drawIndirect(self, indirectBuffer: Buffer, indirectOffset: int = 0) -> None:
|
|
1532
|
+
return self.handle.drawIndirect(indirectBuffer.handle, indirectOffset)
|
|
1533
|
+
|
|
1534
|
+
def drawIndexedIndirect(self, indirectBuffer: Buffer, indirectOffset: int = 0) -> None:
|
|
1535
|
+
return self.handle.drawIndexedIndirect(indirectBuffer.handle, indirectOffset)
|
|
1536
|
+
|
|
1537
|
+
def insertDebugMarker(self, markerLabel: str = "") -> None:
|
|
1538
|
+
return self.handle.insertDebugMarker(markerLabel)
|
|
1539
|
+
|
|
1540
|
+
def popDebugGroup(self) -> None:
|
|
1541
|
+
return self.handle.popDebugGroup()
|
|
1542
|
+
|
|
1543
|
+
def pushDebugGroup(self, groupLabel: str = "") -> None:
|
|
1544
|
+
return self.handle.pushDebugGroup(groupLabel)
|
|
1545
|
+
|
|
1546
|
+
def setVertexBuffer(
|
|
1547
|
+
self,
|
|
1548
|
+
slot: int = 0,
|
|
1549
|
+
buffer: "Buffer | None" = None,
|
|
1550
|
+
offset: int = 0,
|
|
1551
|
+
size: int = 0,
|
|
1552
|
+
) -> None:
|
|
1553
|
+
return self.handle.setVertexBuffer(
|
|
1554
|
+
slot, None if buffer is None else buffer.handle, offset, size
|
|
1555
|
+
)
|
|
1556
|
+
|
|
1557
|
+
def setIndexBuffer(
|
|
1558
|
+
self,
|
|
1559
|
+
buffer: "Buffer | None" = None,
|
|
1560
|
+
format: "IndexFormat | None" = None,
|
|
1561
|
+
offset: int = 0,
|
|
1562
|
+
size: int = 0,
|
|
1563
|
+
) -> None:
|
|
1564
|
+
return self.handle.setIndexBuffer(
|
|
1565
|
+
None if buffer is None else buffer.handle, format, offset, size
|
|
1566
|
+
)
|
|
1567
|
+
|
|
1568
|
+
def finish(
|
|
1569
|
+
self,
|
|
1570
|
+
label: str = "",
|
|
1571
|
+
) -> "RenderBundle":
|
|
1572
|
+
return self.handle.finish(RenderBundleDescriptor(label=label).toJS())
|
|
1573
|
+
|
|
1574
|
+
|
|
1575
|
+
class RenderPassEncoder(BaseWebGPUHandle):
|
|
1576
|
+
def setPipeline(self, pipeline: "RenderPipeline | None" = None) -> None:
|
|
1577
|
+
return self.handle.setPipeline(pipeline)
|
|
1578
|
+
|
|
1579
|
+
def setBindGroup(
|
|
1580
|
+
self,
|
|
1581
|
+
groupIndex: int = 0,
|
|
1582
|
+
group: "BindGroup | None" = None,
|
|
1583
|
+
dynamicOffsets: list[int] = [],
|
|
1584
|
+
) -> None:
|
|
1585
|
+
return self.handle.setBindGroup(groupIndex, group, dynamicOffsets)
|
|
1586
|
+
|
|
1587
|
+
def draw(
|
|
1588
|
+
self,
|
|
1589
|
+
vertexCount: int = 0,
|
|
1590
|
+
instanceCount: int = 0,
|
|
1591
|
+
firstVertex: int = 0,
|
|
1592
|
+
firstInstance: int = 0,
|
|
1593
|
+
) -> None:
|
|
1594
|
+
return self.handle.draw(vertexCount, instanceCount, firstVertex, firstInstance)
|
|
1595
|
+
|
|
1596
|
+
def drawIndexed(
|
|
1597
|
+
self,
|
|
1598
|
+
indexCount: int = 0,
|
|
1599
|
+
instanceCount: int = 0,
|
|
1600
|
+
firstIndex: int = 0,
|
|
1601
|
+
baseVertex: int = 0,
|
|
1602
|
+
firstInstance: int = 0,
|
|
1603
|
+
) -> None:
|
|
1604
|
+
return self.handle.drawIndexed(
|
|
1605
|
+
indexCount, instanceCount, firstIndex, baseVertex, firstInstance
|
|
1606
|
+
)
|
|
1607
|
+
|
|
1608
|
+
def drawIndirect(self, indirectBuffer: Buffer, indirectOffset: int = 0) -> None:
|
|
1609
|
+
return self.handle.drawIndirect(indirectBuffer.handle, indirectOffset)
|
|
1610
|
+
|
|
1611
|
+
def drawIndexedIndirect(self, indirectBuffer: Buffer, indirectOffset: int = 0) -> None:
|
|
1612
|
+
return self.handle.drawIndexedIndirect(indirectBuffer.handle, indirectOffset)
|
|
1613
|
+
|
|
1614
|
+
def executeBundles(self, bundles: list["RenderBundle"] = []) -> None:
|
|
1615
|
+
return self.handle.executeBundles(bundles)
|
|
1616
|
+
|
|
1617
|
+
def insertDebugMarker(self, markerLabel: str = "") -> None:
|
|
1618
|
+
return self.handle.insertDebugMarker(markerLabel)
|
|
1619
|
+
|
|
1620
|
+
def popDebugGroup(self) -> None:
|
|
1621
|
+
return self.handle.popDebugGroup()
|
|
1622
|
+
|
|
1623
|
+
def pushDebugGroup(self, groupLabel: str = "") -> None:
|
|
1624
|
+
return self.handle.pushDebugGroup(groupLabel)
|
|
1625
|
+
|
|
1626
|
+
def setStencilReference(self, reference: int = 0) -> None:
|
|
1627
|
+
return self.handle.setStencilReference(reference)
|
|
1628
|
+
|
|
1629
|
+
def setBlendConstant(self, color: "Color | None" = None) -> None:
|
|
1630
|
+
return self.handle.setBlendConstant(color)
|
|
1631
|
+
|
|
1632
|
+
def setViewport(
|
|
1633
|
+
self,
|
|
1634
|
+
x: float = 0.0,
|
|
1635
|
+
y: float = 0.0,
|
|
1636
|
+
width: float = 0.0,
|
|
1637
|
+
height: float = 0.0,
|
|
1638
|
+
minDepth: float = 0.0,
|
|
1639
|
+
maxDepth: float = 0.0,
|
|
1640
|
+
) -> None:
|
|
1641
|
+
return self.handle.setViewport(x, y, width, height, minDepth, maxDepth)
|
|
1642
|
+
|
|
1643
|
+
def setScissorRect(self, x: int = 0, y: int = 0, width: int = 0, height: int = 0) -> None:
|
|
1644
|
+
return self.handle.setScissorRect(x, y, width, height)
|
|
1645
|
+
|
|
1646
|
+
def setVertexBuffer(
|
|
1647
|
+
self,
|
|
1648
|
+
slot: int = 0,
|
|
1649
|
+
buffer: "Buffer | None" = None,
|
|
1650
|
+
offset: int = 0,
|
|
1651
|
+
size: int = 0,
|
|
1652
|
+
) -> None:
|
|
1653
|
+
return self.handle.setVertexBuffer(
|
|
1654
|
+
slot, None if buffer is None else buffer.handle, offset, size
|
|
1655
|
+
)
|
|
1656
|
+
|
|
1657
|
+
def setIndexBuffer(
|
|
1658
|
+
self,
|
|
1659
|
+
buffer: "Buffer | None" = None,
|
|
1660
|
+
format: "IndexFormat | None" = None,
|
|
1661
|
+
offset: int = 0,
|
|
1662
|
+
size: int = 0,
|
|
1663
|
+
) -> None:
|
|
1664
|
+
return self.handle.setIndexBuffer(
|
|
1665
|
+
None if buffer is None else buffer.handle, format, offset, size
|
|
1666
|
+
)
|
|
1667
|
+
|
|
1668
|
+
def beginOcclusionQuery(self, queryIndex: int = 0) -> None:
|
|
1669
|
+
return self.handle.beginOcclusionQuery(queryIndex)
|
|
1670
|
+
|
|
1671
|
+
def endOcclusionQuery(self) -> None:
|
|
1672
|
+
return self.handle.endOcclusionQuery()
|
|
1673
|
+
|
|
1674
|
+
def end(self) -> None:
|
|
1675
|
+
return self.handle.end()
|
|
1676
|
+
|
|
1677
|
+
|
|
1678
|
+
class RenderPipeline(BaseWebGPUHandle):
|
|
1679
|
+
def getBindGroupLayout(self, groupIndex: int = 0) -> "BindGroupLayout":
|
|
1680
|
+
return self.handle.getBindGroupLayout(groupIndex)
|
|
1681
|
+
|
|
1682
|
+
|
|
1683
|
+
class ShaderModule(BaseWebGPUHandle):
|
|
1684
|
+
def getCompilationInfo(self) -> None:
|
|
1685
|
+
return self.handle.getCompilationInfo()
|
|
1686
|
+
|
|
1687
|
+
|
|
1688
|
+
class Texture(BaseWebGPUHandle):
|
|
1689
|
+
def createView(self, descriptor: TextureViewDescriptor | None = None) -> "TextureView":
|
|
1690
|
+
if descriptor is None:
|
|
1691
|
+
return TextureView(self.handle.createView())
|
|
1692
|
+
return TextureView(self.handle.createView(descriptor.toJS()))
|
|
1693
|
+
|
|
1694
|
+
@property
|
|
1695
|
+
def width(self) -> int:
|
|
1696
|
+
return self.handle.width
|
|
1697
|
+
|
|
1698
|
+
@property
|
|
1699
|
+
def height(self) -> int:
|
|
1700
|
+
return self.handle.height
|
|
1701
|
+
|
|
1702
|
+
@property
|
|
1703
|
+
def depthOrArrayLayers(self) -> int:
|
|
1704
|
+
return self.handle.depthOrArrayLayers
|
|
1705
|
+
|
|
1706
|
+
@property
|
|
1707
|
+
def mipLevelCount(self) -> int:
|
|
1708
|
+
return self.handle.mipLevelCount
|
|
1709
|
+
|
|
1710
|
+
@property
|
|
1711
|
+
def sampleCount(self) -> int:
|
|
1712
|
+
return self.handle.sampleCount
|
|
1713
|
+
|
|
1714
|
+
@property
|
|
1715
|
+
def dimension(self) -> str:
|
|
1716
|
+
return self.handle.dimension
|
|
1717
|
+
|
|
1718
|
+
@property
|
|
1719
|
+
def format(self) -> "TextureFormat":
|
|
1720
|
+
return TextureFormat(self.handle.format())
|
|
1721
|
+
|
|
1722
|
+
@property
|
|
1723
|
+
def usage(self) -> "TextureUsage":
|
|
1724
|
+
return TextureUsage(self.handle.usage())
|
|
1725
|
+
|
|
1726
|
+
def destroy(self) -> None:
|
|
1727
|
+
print("destroy texture")
|
|
1728
|
+
return self.handle.destroy()
|
|
1729
|
+
|
|
1730
|
+
def __del__(self):
|
|
1731
|
+
self.destroy()
|