euv-engine 0.28.33

A high-performance 2D game engine built on the euv framework, featuring ECS, fixed-timestep game loop, canvas rendering, physics, collision detection, sprite animation, and audio.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
/// The `sampleType` property key inside `GpuTextureBindingLayout`.
pub(crate) const WEBGPU_PROPERTY_SAMPLE_TYPE: &str = "sampleType";

/// `rowsPerImage` property key inside `GpuImageDataLayout`.
pub(crate) const WEBGPU_PROPERTY_ROWS_PER_IMAGE: &str = "rowsPerImage";

/// `addressModeV` property key inside `GpuSamplerDescriptor`.
pub(crate) const WEBGPU_PROPERTY_ADDRESS_MODE_V: &str = "addressModeV";

/// `magFilter` property key inside `GpuSamplerDescriptor`.
pub(crate) const WEBGPU_PROPERTY_MAG_FILTER: &str = "magFilter";

/// The JavaScript method name `resolveQuerySet` on `GpuCommandEncoder`.
pub(crate) const WEBGPU_METHOD_RESOLVE_QUERY_SET: &str = "resolveQuerySet";

/// `compare` property key inside `GpuSamplerDescriptor`.
pub(crate) const WEBGPU_PROPERTY_COMPARE: &str = "compare";

/// `origin` property key inside `GpuImageCopyTexture`.
pub(crate) const WEBGPU_PROPERTY_ORIGIN: &str = "origin";

/// The JavaScript method name `setBindGroup` on `GpuComputePassEncoder`.
/// The JavaScript method name `setPipeline` on `GpuComputePassEncoder`.
pub(crate) const WEBGPU_METHOD_SET_PIPELINE_COMPUTE: &str = "setPipeline";

/// `GpuDevice.createComputePipeline(descriptor)` method name.
pub(crate) const WEBGPU_METHOD_CREATE_COMPUTE_PIPELINE: &str = "createComputePipeline";

/// The `read-only` value for `GpuBufferBindingLayout.type` (read-only storage).
pub(crate) const WEBGPU_BUFFER_BINDING_TYPE_READ_ONLY_STORAGE: &str = "read-only-storage";

/// `offset` property key inside `GpuImageDataLayout` (used by `queue.writeTexture`).
///
/// The spec spells this key `offset`, not `offsetBytes`: a layout written
/// with the longer name validates, because WebGPU ignores dictionary keys
/// it does not recognise, and then silently writes from byte zero. That is
/// why this is a separate constant from
/// [`WEBGPU_PROPERTY_OFFSET`] rather than a second name for it: the two
/// live in different dictionaries and mean different things, but they do
/// share a wire spelling.
pub(crate) const WEBGPU_PROPERTY_IMAGE_DATA_OFFSET: &str = "offset";

/// `width` property key (used by `GpuExtent3D`, `GpuOrigin3D`, viewport / scissor).
pub(crate) const WEBGPU_PROPERTY_WIDTH: &str = "width";

/// `GpuDevice.createSampler(descriptor)` method name.
pub(crate) const WEBGPU_METHOD_CREATE_SAMPLER: &str = "createSampler";

/// `GpuCommandEncoder.beginComputePass(descriptor)` method name.
pub(crate) const WEBGPU_METHOD_BEGIN_COMPUTE_PASS: &str = "beginComputePass";

/// `minFilter` property key inside `GpuSamplerDescriptor`.
pub(crate) const WEBGPU_PROPERTY_MIN_FILTER: &str = "minFilter";

/// `bytesPerRow` property key inside `GpuImageDataLayout`.
pub(crate) const WEBGPU_PROPERTY_BYTES_PER_ROW: &str = "bytesPerRow";

/// `mipmapFilter` property key inside `GpuSamplerDescriptor`.
pub(crate) const WEBGPU_PROPERTY_MIPMAP_FILTER: &str = "mipmapFilter";

/// The JavaScript method name `drawIndexed(indexCount)` on `GpuRenderPassEncoder`.
pub(crate) const WEBGPU_METHOD_DRAW_INDEXED: &str = "drawIndexed";

/// The `multisampled` property key inside `GpuTextureBindingLayout`.
pub(crate) const WEBGPU_PROPERTY_MULTISAMPLED: &str = "multisampled";

/// `height` property key (used by `GpuExtent3D`, `GpuOrigin3D`, viewport / scissor).
pub(crate) const WEBGPU_PROPERTY_HEIGHT: &str = "height";

/// `texture` property key inside a texture binding entry / `writeTexture` dest.
pub(crate) const WEBGPU_PROPERTY_TEXTURE: &str = "texture";

/// The JavaScript method name `createBindGroupLayout` on `GpuDevice`.
pub(crate) const WEBGPU_METHOD_CREATE_BIND_GROUP_LAYOUT: &str = "createBindGroupLayout";

/// `GpuComputePassEncoder.dispatch(x, y, z)` method name.
pub(crate) const WEBGPU_METHOD_DISPATCH: &str = "dispatchWorkgroups";

/// The JavaScript method name `setIndexBuffer(buffer, format)` on `GpuRenderPassEncoder`.
pub(crate) const WEBGPU_METHOD_SET_INDEX_BUFFER: &str = "setIndexBuffer";

/// The `hasDynamicOffset` property key inside `GpuBufferBindingLayout`.
/// The `storage` value for `GpuBufferBindingLayout.type` (read-write storage).
pub(crate) const WEBGPU_BUFFER_BINDING_TYPE_STORAGE: &str = "storage";

/// `pass.timestampWrites` operation on render / compute pass encoders.
pub(crate) const WEBGPU_METHOD_TIMESTAMP: &str = "timestamp";

/// The `visibility` property key inside `GpuBindGroupLayoutEntry`.
pub(crate) const WEBGPU_PROPERTY_VISIBILITY: &str = "visibility";

/// `lost` property key inside the `GpuDevice.lost` Promise.
pub(crate) const WEBGPU_PROPERTY_LOST: &str = "lost";

/// `addressModeW` property key inside `GpuSamplerDescriptor`.
pub(crate) const WEBGPU_PROPERTY_ADDRESS_MODE_W: &str = "addressModeW";

/// `destination` property key inside `GpuImageCopyTexture` (used by `writeTexture`).
pub(crate) const WEBGPU_PROPERTY_DESTINATION: &str = "destination";

/// `GpuCommandEncoder.copyTextureToBuffer(...)` method name.
pub(crate) const WEBGPU_METHOD_COPY_TEXTURE_TO_BUFFER: &str = "copyTextureToBuffer";

/// The JavaScript method name `createQuerySet` on `GpuDevice`.
pub(crate) const WEBGPU_METHOD_CREATE_QUERY_SET: &str = "createQuerySet";

/// The `uniform` value for `GpuBufferBindingLayout.type`.
pub(crate) const WEBGPU_BUFFER_BINDING_TYPE_UNIFORM: &str = "uniform";

/// `source` property key inside `GpuImageCopyTexture` (used by `copyTextureToBuffer`).
pub(crate) const WEBGPU_PROPERTY_SOURCE: &str = "source";

/// The `storageTexture` value for `GpuBindingLayoutEntry`/`GpuBindGroupEntry`.
pub(crate) const WEBGPU_PROPERTY_STORAGE_TEXTURE: &str = "storageTexture";

pub(crate) const WEBGPU_TEXTURE_DIMENSION_2D: &str = "2d";

/// `mipLevel` property key inside a texture binding entry / `writeTexture` dest.
pub(crate) const WEBGPU_PROPERTY_MIP_LEVEL: &str = "mipLevel";

/// The `viewDimension` property key inside texture binding layouts.
pub(crate) const WEBGPU_PROPERTY_VIEW_DIMENSION: &str = "viewDimension";

/// `addressModeU` property key inside `GpuSamplerDescriptor`.
pub(crate) const WEBGPU_PROPERTY_ADDRESS_MODE_U: &str = "addressModeU";

/// `GpuQueue.writeTexture(destination, data, dataLayout, size)` method name.
pub(crate) const WEBGPU_METHOD_WRITE_TEXTURE: &str = "writeTexture";

/// `compute` property key inside `GpuRenderPassDescriptor` (compute-pass dispatch).
pub(crate) const WEBGPU_PROPERTY_COMPUTE: &str = "compute";

/// `depthOrArrayLayers` property key inside `GpuExtent3D`.
pub(crate) const WEBGPU_PROPERTY_DEPTH_OR_1: &str = "depthOrArrayLayers";

/// `copySize` property key inside `GpuImageCopyTexture` (used by `copyTextureToBuffer`).
pub(crate) const WEBGPU_PROPERTY_COPY_SIZE: &str = "copySize";

/// The `comparison` property key inside `GpuSamplerBindingLayout`.
/// The `readOnly` property key inside storage-texture binding layouts.
pub(crate) const WEBGPU_PROPERTY_READ_ONLY: &str = "readOnly";

/// The JavaScript method name `setVertexBuffer(slot, buffer)` on `GpuRenderPassEncoder`.
pub(crate) const WEBGPU_METHOD_SET_VERTEX_BUFFER: &str = "setVertexBuffer";

/// The `texture` property key inside `GpuTextureBindingLayout`.
/// The `sampler` property key inside `GpuSamplerBindingLayout`.
pub(crate) const WEBGPU_PROPERTY_SAMPLER_BINDING_TYPE: &str = "sampler";

/// The `querySet` property key inside `GpuComputePassDescriptor.timestampWrites`.
/// The `beginningOfPassWriteIndex` property key for timestamp writes.
/// The `endOfPassWriteIndex` property key for timestamp writes.
/// The `timestamp-writes` descriptor field on render / compute passes.
/// The bitmask value for `GPUBufferUsage.MAP_READ` (`0x01`).
/// The bitmask value for `GPUBufferUsage.MAP_WRITE` (`0x02`).
/// The bitmask value for `GPUBufferUsage.STORAGE` (`0x80`).
///
/// Required on any buffer that is bound as `var<storage>` in WGSL.
/// The bitmask value for `GPUBufferUsage.INDIRECT` (`0x100`).
///
/// Required on buffers used as the indirect argument of `drawIndexedIndirect` / `drawIndirect`.
/// The bitmask value for `GPUBufferUsage.QUERY_RESOLVE` (`0x200`).
///
/// Required on the destination buffer of `commandEncoder.resolveQuerySet`.
/// `timestamp` query type inside `GpuQuerySetDescriptor`.
pub(crate) const WEBGPU_QUERY_TYPE_TIMESTAMP: &str = "timestamp";

/// The `indexFormat` property key inside `GpuRenderPipelineDescriptor.primitive`.
/// The `type` property key inside `GpuBufferBindingLayout`.
pub(crate) const WEBGPU_PROPERTY_TYPE: &str = "type";

/// `label` property key (debug marker string, set on every WebGPU object).
pub(crate) const WEBGPU_PROPERTY_LABEL: &str = "label";

/// The JavaScript method name `getPreferredCanvasFormat` on `Gpu`.
pub(crate) const WEBGPU_METHOD_GET_PREFERRED_FORMAT: &str = "getPreferredCanvasFormat";

/// `depthWriteEnabled` property key inside `GpuDepthStencilState`.
pub(crate) const WEBGPU_PROPERTY_DEPTH_WRITE_ENABLED: &str = "depthWriteEnabled";

/// 16-bit unorm depth, no stencil. Cheaper than depth24plus, but no
/// stencil, slightly more z-fighting.
pub(crate) const WEBGPU_DEPTH_FORMAT_DEPTH16_UNORM: &str = "depth16unorm";

/// The JavaScript method name `finish` on `GpuCommandEncoder`.
pub(crate) const WEBGPU_METHOD_FINISH: &str = "finish";

/// The JavaScript method name `configure` on `GpuCanvasContext`.
pub(crate) const WEBGPU_METHOD_CONFIGURE: &str = "configure";

/// `offset` property key inside `GpuVertexAttribute`.
pub(crate) const WEBGPU_PROPERTY_OFFSET: &str = "offset";

/// The JavaScript method name `createShaderModule` on `GpuDevice`.
pub(crate) const WEBGPU_METHOD_CREATE_SHADER_MODULE: &str = "createShaderModule";

/// The JavaScript property name `view` on `GpuRenderPassColorAttachment`.
pub(crate) const WEBGPU_PROPERTY_VIEW: &str = "view";

/// `shaderLocation` property key inside `GpuVertexAttribute`.
pub(crate) const WEBGPU_PROPERTY_SHADER_LOCATION: &str = "shaderLocation";

/// Default `maxDepth` value passed to `setViewport` when the caller did not
/// supply one. WebGPU's spec default is `1.0`.
pub(crate) const WEBGPU_DEFAULT_VIEWPORT_MAX_DEPTH: f64 = 1.0;

/// Map a buffer for CPU write. Requires `MAP_WRITE` usage.
pub(crate) const WEBGPU_MAP_MODE_WRITE: f64 = 2.0;

/// `baseMipLevel` property key inside `GpuTextureViewDescriptor`.
pub(crate) const WEBGPU_PROPERTY_BASE_MIP_LEVEL: &str = "baseMipLevel";

/// `GpuTexture.generateMipmap()` method name (Chrome extension, not spec).
pub(crate) const WEBGPU_METHOD_GENERATE_MIPMAP: &str = "generateMipmap";

/// The JavaScript property name `b` on `GpuColorDict`.
pub(crate) const WEBGPU_PROPERTY_B: &str = "b";

pub(crate) const WEBGPU_PROPERTY_DST_FACTOR: &str = "dstFactor";

pub(crate) const WEBGPU_PROPERTY_CULL_MODE: &str = "cullMode";

/// `textureView` property key inside `GpuTextureBinding`.
pub(crate) const WEBGPU_PROPERTY_TEXTURE_VIEW: &str = "textureView";

/// The JavaScript method name `createBindGroup` on `GpuDevice`.
pub(crate) const WEBGPU_METHOD_CREATE_BIND_GROUP: &str = "createBindGroup";

pub(crate) const WEBGPU_PROPERTY_COLOR: &str = "color";

/// `sampler` property key inside a sampler binding entry.
pub(crate) const WEBGPU_PROPERTY_SAMPLER: &str = "sampler";

/// `GpuBuffer.unmap()` method name.
pub(crate) const WEBGPU_METHOD_UNMAP: &str = "unmap";

/// The JavaScript property name `queue` on `GpuDevice`.
pub(crate) const WEBGPU_PROPERTY_QUEUE: &str = "queue";

/// The JavaScript property name `entryPoint` on `GpuVertexState` / `GpuFragmentState`.
pub(crate) const WEBGPU_PROPERTY_ENTRY_POINT: &str = "entryPoint";

/// The bitmask value for `GpuTextureUsage.RENDER_ATTACHMENT`.
///
/// WebGPU spec defines this as `0x10`. The multisample texture must carry this
/// usage so it can be bound as a color attachment in `beginRenderPass`.
pub(crate) const WEBGPU_TEXTURE_USAGE_RENDER_ATTACHMENT: f64 = 16.0;

/// The JavaScript property name `a` on `GpuColorDict`.
pub(crate) const WEBGPU_PROPERTY_A: &str = "a";

/// `GpuBuffer.mapAsync(mode, offset, size)` method name.
pub(crate) const WEBGPU_METHOD_MAP_ASYNC: &str = "mapAsync";

/// The `GpuMultisampleState` property key in a render pipeline descriptor.
pub(crate) const WEBGPU_PROPERTY_MULTISAMPLE: &str = "multisample";

/// The JavaScript property name `primitive` on `GpuRenderPipelineDescriptor`.
pub(crate) const WEBGPU_PROPERTY_PRIMITIVE: &str = "primitive";

/// The JavaScript property name `clearValue` on `GpuRenderPassColorAttachment`.
pub(crate) const WEBGPU_PROPERTY_CLEAR_VALUE: &str = "clearValue";

pub(crate) const WEBGPU_PROPERTY_ALPHA: &str = "alpha";

/// The JavaScript property name `buffers` on `GpuVertexState`.
pub(crate) const WEBGPU_PROPERTY_BUFFERS: &str = "buffers";

/// `arrayLayerCount` property key inside `GpuTextureViewDescriptor`.
pub(crate) const WEBGPU_PROPERTY_ARRAY_LAYER_COUNT: &str = "arrayLayerCount";

/// `depthLoadOp` property key inside `GpuRenderPassDepthStencilAttachment`.
pub(crate) const WEBGPU_PROPERTY_DEPTH_LOAD_OP: &str = "depthLoadOp";

/// The JavaScript method name `createBuffer` on `GpuDevice`.
pub(crate) const WEBGPU_METHOD_CREATE_BUFFER: &str = "createBuffer";

/// `GpuBuffer.getMappedRange(offset, size)` method name.
pub(crate) const WEBGPU_METHOD_GET_MAPPED_RANGE: &str = "getMappedRange";

/// `depthClearValue` property key inside `GpuRenderPassDepthStencilAttachment`.
pub(crate) const WEBGPU_PROPERTY_DEPTH_CLEAR_VALUE: &str = "depthClearValue";

/// `depthCompare` property key inside `GpuDepthStencilState`.
pub(crate) const WEBGPU_PROPERTY_DEPTH_COMPARE: &str = "depthCompare";

/// The JavaScript property name `loadOp` on `GpuRenderPassColorAttachment`.
pub(crate) const WEBGPU_PROPERTY_LOAD_OP: &str = "loadOp";

/// The JavaScript method name `requestDevice` on `GpuAdapter`.
pub(crate) const WEBGPU_METHOD_REQUEST_DEVICE: &str = "requestDevice";

/// The JavaScript method name `setBindGroup` on `GpuRenderPassEncoder`.
pub(crate) const WEBGPU_METHOD_SET_BIND_GROUP: &str = "setBindGroup";

/// The JavaScript property name for `powerPreference` on `GpuRequestAdapterOptions`.
pub(crate) const WEBGPU_PROPERTY_POWER_PREFERENCE: &str = "powerPreference";

/// The `resource` property key inside `GpuBindGroupEntry`.
pub(crate) const WEBGPU_PROPERTY_RESOURCE: &str = "resource";

/// The JavaScript method name `unconfigure` on `GpuCanvasContext`.
///
/// Releases the GPU resources associated with the canvas context so that
/// the DOM canvas can be detached/GCed and the WebGPU device can be
/// safely destroyed. Called from `WebGpuRenderer::dispose` to tear down
/// a renderer cleanly when its host component is unmounted.
pub(crate) const WEBGPU_METHOD_UNCONFIGURE: &str = "unconfigure";

/// The spec-compliant value for `GPURenderPipelineDescriptor.layout`
/// when no explicit `GPUPipelineLayout` is supplied.
///
/// Per the WebGPU spec, `layout` is `GPUPipelineLayout | "auto"`. The
/// string `"auto"` instructs the implementation to derive an implicit
/// pipeline layout from the shader bindings. Setting `layout` to JS
/// `null` works on some browsers but is NOT spec-compliant and produces
/// a pipeline that the GPU driver may reject silently (the symptom we
/// saw: `WebGPU: No pipeline set.` at draw time, with no create error).
pub(crate) const WEBGPU_AUTO_LAYOUT: &str = "auto";

/// The `binding` property key inside `GpuBindGroupEntry`.
pub(crate) const WEBGPU_PROPERTY_BINDING: &str = "binding";

/// `GpuRenderPassEncoder.setStencilReference(value)` method name.
pub(crate) const WEBGPU_METHOD_SET_STENCIL_REFERENCE: &str = "setStencilReference";

pub(crate) const WEBGPU_PROPERTY_BLEND: &str = "blend";

/// The `sampleCount` property key inside `GpuTextureDescriptor`.
///
/// Sets the multisample count for the texture. Must be `1` for non-multisampled
/// textures or `4` (or `8`, depending on adapter support) for MSAA textures.
pub(crate) const WEBGPU_PROPERTY_SAMPLE_COUNT: &str = "sampleCount";

/// `depthStoreOp` property key inside `GpuRenderPassDepthStencilAttachment`.
pub(crate) const WEBGPU_PROPERTY_DEPTH_STORE_OP: &str = "depthStoreOp";

/// Upper bound, in milliseconds, for how long `WebGpuRenderer::init` is
/// allowed to wait on the adapter and device promises before falling into
/// the `WebGPU Not Supported` branch.
///
/// The browser's `navigator.gpu.requestAdapter()` / `requestDevice()`
/// promises are not always guaranteed to settle — headless contexts,
/// sandboxed iframes, and some GPU device-lost paths leave them pending
/// indefinitely. To keep the UI from stalling on `Initializing...` in those
/// cases, each promise is raced against a timer that rejects after this
/// many milliseconds (see `timeout_promise` / `with_timeout` in
/// `impl.rs`); on timeout the caller surfaces `RENDERER_TIMEOUT_ERROR_MESSAGE`
/// and treats the outcome the same as "no adapter available".
pub(crate) const INIT_PROMISE_TIMEOUT_MILLIS: i32 = 3000;

/// Error message used when the WebGPU init promise race loses to the
/// `INIT_PROMISE_TIMEOUT_MILLIS` timer. Surfaced to `JsFuture::await` as
/// `Err`, which causes the caller to fall into its `WebGPU Not Supported`
/// branch instead of leaving the UI stuck on `Initializing...`.
pub(crate) const RENDERER_TIMEOUT_ERROR_MESSAGE: &str = "WebGPU initialization timed out";

/// The `depthOrArrayLayers` property key inside `GpuExtent3dDict`.
///
/// Always `1` for 2D textures; required by the spec even when unused.
pub(crate) const WEBGPU_PROPERTY_EXTENT_DEPTH: &str = "depthOrArrayLayers";

/// `GpuDevice.popErrorScope()` method name.
pub(crate) const WEBGPU_METHOD_POP_ERROR_SCOPE: &str = "popErrorScope";

/// The JavaScript property name `layout` on `GpuRenderPipelineDescriptor`.
pub(crate) const WEBGPU_PROPERTY_LAYOUT: &str = "layout";

/// Texture usage: storage texture binding.
pub(crate) const WEBGPU_TEXTURE_USAGE_STORAGE_BINDING: f64 = 8.0;

/// The `usage` property key inside `GpuTextureDescriptor`.
///
/// Bitmask of `GpuTextureUsage` flags. We use `RENDER_ATTACHMENT` (bit 0x10)
/// for the multisample color buffer that render passes draw into and from
/// which the swap chain resolves.
pub(crate) const WEBGPU_PROPERTY_USAGE: &str = "usage";

/// The `width` property key inside `GpuExtent3dDict`.
pub(crate) const WEBGPU_PROPERTY_EXTENT_WIDTH: &str = "width";

/// `aspect` property key inside `GpuTextureViewDescriptor`.
pub(crate) const WEBGPU_PROPERTY_ASPECT: &str = "aspect";

/// Texture usage: read in a shader (sampled texture / uniform texel buffer).
pub(crate) const WEBGPU_TEXTURE_USAGE_COPY_SRC: f64 = 1.0;

/// The `height` property key inside `GpuExtent3dDict`.
pub(crate) const WEBGPU_PROPERTY_EXTENT_HEIGHT: &str = "height";

/// The `Navigator` property name that exposes the WebGPU `GPU` interface.
///
/// Per the WebGPU spec and MDN (`Navigator.gpu`), browsers expose the
/// entry point to the API under the property name `"gpu"` - not
/// `"webgpu"`. Using [`WEBGPU_CONTEXT_TYPE`] (which is `"webgpu"`)
/// as the key for `Reflect::get(navigator, ...)` always returns
/// `undefined`, even when WebGPU is fully supported, because
/// `navigator` does not have a `"webgpu"` property. This constant
/// exists to make the correct key explicit at every probe site.
pub(crate) const WEBGPU_NAVIGATOR_GPU_KEY: &str = "gpu";

/// The JavaScript method name `createCommandEncoder` on `GpuDevice`.
pub(crate) const WEBGPU_METHOD_CREATE_COMMAND_ENCODER: &str = "createCommandEncoder";

/// The JavaScript property name `fragment` on `GpuRenderPipelineDescriptor`.
pub(crate) const WEBGPU_PROPERTY_FRAGMENT: &str = "fragment";

/// The JavaScript method name `requestAdapter` on `Gpu`.
pub(crate) const WEBGPU_METHOD_REQUEST_ADAPTER: &str = "requestAdapter";

/// The JavaScript property name `device` on `GpuCanvasConfiguration`.
pub(crate) const WEBGPU_PROPERTY_DEVICE: &str = "device";

/// The JavaScript property name `storeOp` on `GpuRenderPassColorAttachment`.
pub(crate) const WEBGPU_PROPERTY_STORE_OP: &str = "storeOp";

/// The JavaScript property name `format` on `GpuCanvasConfiguration`.
pub(crate) const WEBGPU_PROPERTY_FORMAT: &str = "format";

/// `baseArrayLayer` property key inside `GpuTextureViewDescriptor`.
pub(crate) const WEBGPU_PROPERTY_BASE_ARRAY_LAYER: &str = "baseArrayLayer";

/// The vertex shader entry point name used in WGSL shaders.
pub(crate) const WEBGPU_VERTEX_ENTRY_POINT: &str = "vs_main";

/// The JavaScript method name `setPipeline` on `GpuRenderPassEncoder`.
pub(crate) const WEBGPU_METHOD_SET_PIPELINE: &str = "setPipeline";

/// The JavaScript method name `writeBuffer` on `GpuQueue`.
///
/// Uploads host data into a `GpuBuffer` without a staging encoder, which is
/// the canonical way to refresh small per-frame uniform buffers.
pub(crate) const WEBGPU_METHOD_WRITE_BUFFER: &str = "writeBuffer";

/// The `depth` value for `GpuTextureBindingLayout.sampleType`.
/// The `float` value for `GpuTextureBindingLayout.sampleType`.
/// The `unfilterable-float` value for `GpuTextureBindingLayout.sampleType`.
/// The `2d-array` view-dimension value inside texture binding layouts.
/// The `cube` view-dimension value inside texture binding layouts.
/// `uint16` value for `GpuRenderPipelineDescriptor.primitive.indexFormat`.
/// `uint32` value for `GpuRenderPipelineDescriptor.primitive.indexFormat`.
/// The `entries` property key inside `GpuBindGroupDescriptor`.
pub(crate) const WEBGPU_PROPERTY_ENTRIES: &str = "entries";

pub(crate) const WEBGPU_PROPERTY_SRC_FACTOR: &str = "srcFactor";

/// The JavaScript property name `targets` on `GpuFragmentState`.
pub(crate) const WEBGPU_PROPERTY_TARGETS: &str = "targets";

/// The `count` property key inside `GpuMultisampleState`.
///
/// When `count` is `1`, MSAA is disabled (one sample per pixel). Values like
/// `4` enable 4x multisample anti-aliasing.
pub(crate) const WEBGPU_PROPERTY_COUNT: &str = "count";

/// The JavaScript property name `module` on `GpuVertexState` / `GpuFragmentState`.
pub(crate) const WEBGPU_PROPERTY_MODULE: &str = "module";

/// The JavaScript method name `draw` on `GpuRenderPassEncoder`.
pub(crate) const WEBGPU_METHOD_DRAW: &str = "draw";

/// The `resolveTarget` property key inside `GpuRenderPassColorAttachment`.
///
/// Holds the destination `GpuTextureView` for MSAA resolve. Omit when MSAA is
/// disabled; present when the attachment's texture has `sampleCount > 1`.
pub(crate) const WEBGPU_PROPERTY_RESOLVE_TARGET: &str = "resolveTarget";

pub(crate) const WEBGPU_PROPERTY_WRITE_MASK: &str = "writeMask";

/// The `format` property key inside `GpuTextureDescriptor`.
pub(crate) const WEBGPU_PROPERTY_TEXTURE_FORMAT: &str = "format";

pub(crate) const WEBGPU_PROPERTY_MASK: &str = "mask";

/// `attributes` property key inside `GpuVertexBufferLayout`.
pub(crate) const WEBGPU_PROPERTY_ATTRIBUTES: &str = "attributes";

/// The WebGPU context type string used to obtain a `GpuCanvasContext` from a canvas element.
///
/// This is the argument to `HTMLCanvasElement.getContext(...)` - **not** a
/// property name on `Navigator`. The browser exposes WebGPU via
/// `Navigator.gpu` (the string `"gpu"`), which is a separate concept.
/// Mixing the two up is a long-standing bug; see
/// [`WEBGPU_NAVIGATOR_GPU_KEY`] for the navigator-side key.
pub(crate) const WEBGPU_CONTEXT_TYPE: &str = "webgpu";

/// `GpuRenderPassEncoder.setScissorRect(x, y, w, h)` method name.
pub(crate) const WEBGPU_METHOD_SET_SCISSOR_RECT: &str = "setScissorRect";

/// `GpuRenderPassEncoder.setViewport(x, y, w, h, minDepth, maxDepth)` method name.
pub(crate) const WEBGPU_METHOD_SET_VIEWPORT: &str = "setViewport";

/// The JavaScript property name `vertex` on `GpuRenderPipelineDescriptor`.
pub(crate) const WEBGPU_PROPERTY_VERTEX: &str = "vertex";

/// The JavaScript method name `destroy` on `GpuDevice`.
///
/// Used by `WebGpuRenderer::dispose` to release GPU memory. After
/// `destroy` is called any further use of the device raises a JS
/// error, so this must only run as the final teardown step.
pub(crate) const WEBGPU_METHOD_DESTROY: &str = "destroy";

/// `GpuRenderPassEncoder.setBlendConstant(color)` method name.
pub(crate) const WEBGPU_METHOD_SET_BLEND_CONSTANT: &str = "setBlendConstant";

/// The JavaScript method name `createRenderPipeline` on `GpuDevice`.
pub(crate) const WEBGPU_METHOD_CREATE_RENDER_PIPELINE: &str = "createRenderPipeline";

/// The `buffer` property key inside `GpuBufferBinding`.
pub(crate) const WEBGPU_PROPERTY_BUFFER: &str = "buffer";

/// `depthStencilAttachment` property key inside `GpuRenderPassDescriptor` (alt spelling).
pub(crate) const WEBGPU_PROPERTY_DEPTH_STENCIL_ATTACHMENT: &str = "depthStencilAttachment";

/// Map a buffer for CPU readback. Requires `MAP_READ` usage.
pub(crate) const WEBGPU_MAP_MODE_READ: f64 = 1.0;

/// The JavaScript property name `colorAttachments` on `GpuRenderPassDescriptor`.
pub(crate) const WEBGPU_PROPERTY_COLOR_ATTACHMENTS: &str = "colorAttachments";

/// The JavaScript method name `createView` on `GpuTexture`.
pub(crate) const WEBGPU_METHOD_CREATE_VIEW: &str = "createView";

/// `mipLevelCount` property key inside `GpuTextureViewDescriptor`.
pub(crate) const WEBGPU_PROPERTY_MIP_LEVEL_COUNT: &str = "mipLevelCount";

pub(crate) const WEBGPU_PROPERTY_UNCLIPPED_DEPTH: &str = "unclippedDepth";

/// Texture usage: sampled texture binding.
pub(crate) const WEBGPU_TEXTURE_USAGE_TEXTURE_BINDING: f64 = 4.0;

pub(crate) const WEBGPU_PROPERTY_OPERATION: &str = "operation";

/// The JavaScript method name `end` on `GpuRenderPassEncoder`.
pub(crate) const WEBGPU_METHOD_END: &str = "end";

/// Texture usage: written in a shader (storage texture).
pub(crate) const WEBGPU_TEXTURE_USAGE_COPY_DST: f64 = 2.0;

/// `dimension` property key inside `GpuTextureViewDescriptor`.
pub(crate) const WEBGPU_PROPERTY_DIMENSION: &str = "dimension";

/// The JavaScript property name `code` on `GpuShaderModuleDescriptor`.
pub(crate) const WEBGPU_PROPERTY_CODE: &str = "code";

pub(crate) const WEBGPU_PROPERTY_FRONT_FACE: &str = "frontFace";

pub(crate) const WEBGPU_PROPERTY_STRIP_INDEX_FORMAT: &str = "stripIndexFormat";

/// The JavaScript method name `getCurrentTexture` on `GpuCanvasContext`.
pub(crate) const WEBGPU_METHOD_GET_CURRENT_TEXTURE: &str = "getCurrentTexture";

/// `depthReadOnly` property key inside `GpuRenderPassDepthStencilAttachment`.
pub(crate) const WEBGPU_PROPERTY_DEPTH_READ_ONLY: &str = "depthReadOnly";

/// The JavaScript method name `createTexture` on `GpuDevice`.
pub(crate) const WEBGPU_METHOD_CREATE_TEXTURE: &str = "createTexture";

/// The JavaScript method name `getBindGroupLayout` on `GpuRenderPipeline`.
///
/// With `layout: "auto"` pipelines the bind group layout is derived from the
/// shader; index `0` corresponds to `@group(0)` in WGSL.
pub(crate) const WEBGPU_METHOD_GET_BIND_GROUP_LAYOUT: &str = "getBindGroupLayout";

/// The JavaScript property name `r` on `GpuColorDict`.
pub(crate) const WEBGPU_PROPERTY_R: &str = "r";

/// The JavaScript property name `g` on `GpuColorDict`.
pub(crate) const WEBGPU_PROPERTY_G: &str = "g";

/// The `size` property key inside `GpuTextureDescriptor`.
///
/// Holds a `GpuExtent3dDict` describing width/height/depth of the texture.
pub(crate) const WEBGPU_PROPERTY_SIZE: &str = "size";

/// `GpuDevice.pushErrorScope(filter)` method name.
pub(crate) const WEBGPU_METHOD_PUSH_ERROR_SCOPE: &str = "pushErrorScope";

/// The JavaScript property name `topology` on `GpuPrimitiveState`.
pub(crate) const WEBGPU_PROPERTY_TOPOLOGY: &str = "topology";

/// The JavaScript method name `submit` on `GpuQueue`.
pub(crate) const WEBGPU_METHOD_SUBMIT: &str = "submit";

/// `depthStencil` property key inside `GpuRenderPassDescriptor`.
pub(crate) const WEBGPU_PROPERTY_DEPTH_STENCIL: &str = "depthStencil";

/// `arrayStride` property key inside `GpuVertexBufferLayout`.
pub(crate) const WEBGPU_PROPERTY_ARRAY_STRIDE: &str = "arrayStride";

/// `stepMode` property key inside `GpuVertexBufferLayout`.
pub(crate) const WEBGPU_PROPERTY_STEP_MODE: &str = "stepMode";

/// The fragment shader entry point name used in WGSL shaders.
pub(crate) const WEBGPU_FRAGMENT_ENTRY_POINT: &str = "fs_main";

/// The JavaScript method name `beginRenderPass` on `GpuCommandEncoder`.
pub(crate) const WEBGPU_METHOD_BEGIN_RENDER_PASS: &str = "beginRenderPass";

/// The diagnostic code for a failed `Reflect::get` on `navigator` while
/// probing for the WebGPU entry point.
pub(crate) const WEBGPU_INIT_ERROR_NAVIGATOR_LOOKUP: &str = "WEBGPU_NAVIGATOR_LOOKUP";

/// The diagnostic code for a `navigator` with no `gpu` property.
pub(crate) const WEBGPU_INIT_ERROR_NAVIGATOR_GPU_MISSING: &str = "WEBGPU_NAVIGATOR_GPU_MISSING";

/// The diagnostic code for a failed `Reflect::get` of `requestAdapter`.
pub(crate) const WEBGPU_INIT_ERROR_REQUEST_ADAPTER_LOOKUP: &str = "WEBGPU_REQUEST_ADAPTER_LOOKUP";

/// The diagnostic code for a throwing `requestAdapter` call.
pub(crate) const WEBGPU_INIT_ERROR_REQUEST_ADAPTER_CALL: &str = "WEBGPU_REQUEST_ADAPTER_CALL";

/// The diagnostic code for a rejected `requestAdapter` promise.
pub(crate) const WEBGPU_INIT_ERROR_ADAPTER_PROMISE: &str = "WEBGPU_ADAPTER_PROMISE";

/// The diagnostic code for a `requestAdapter` that resolved to no adapter.
pub(crate) const WEBGPU_INIT_ERROR_ADAPTER_UNAVAILABLE: &str = "WEBGPU_ADAPTER_UNAVAILABLE";

/// The diagnostic code for a failed `Reflect::get` of `requestDevice`.
pub(crate) const WEBGPU_INIT_ERROR_REQUEST_DEVICE_LOOKUP: &str = "WEBGPU_REQUEST_DEVICE_LOOKUP";

/// The diagnostic code for a throwing `requestDevice` call.
pub(crate) const WEBGPU_INIT_ERROR_REQUEST_DEVICE_CALL: &str = "WEBGPU_REQUEST_DEVICE_CALL";

/// The diagnostic code for a rejected `requestDevice` promise.
pub(crate) const WEBGPU_INIT_ERROR_DEVICE_PROMISE: &str = "WEBGPU_DEVICE_PROMISE";

/// The diagnostic code for a `requestDevice` that resolved to no device.
pub(crate) const WEBGPU_INIT_ERROR_DEVICE_UNAVAILABLE: &str = "WEBGPU_DEVICE_UNAVAILABLE";

/// The diagnostic code for a canvas element that could not be found.
pub(crate) const WEBGPU_INIT_ERROR_CANVAS_NOT_FOUND: &str = "WEBGPU_CANVAS_NOT_FOUND";

/// The diagnostic code for a failed canvas `querySelector`.
pub(crate) const WEBGPU_INIT_ERROR_CANVAS_QUERY: &str = "WEBGPU_CANVAS_QUERY";

/// The diagnostic code for a canvas whose WebGPU context is unavailable.
pub(crate) const WEBGPU_INIT_ERROR_CANVAS_CONTEXT_UNAVAILABLE: &str =
    "WEBGPU_CANVAS_CONTEXT_UNAVAILABLE";

/// The diagnostic code for a failed `getPreferredCanvasFormat` lookup.
pub(crate) const WEBGPU_INIT_ERROR_PREFERRED_FORMAT_LOOKUP: &str = "WEBGPU_PREFERRED_FORMAT_LOOKUP";

/// The diagnostic code for a throwing `getPreferredCanvasFormat` call.
pub(crate) const WEBGPU_INIT_ERROR_PREFERRED_FORMAT_CALL: &str = "WEBGPU_PREFERRED_FORMAT_CALL";

/// The diagnostic code for a `getPreferredCanvasFormat` result of the wrong type.
pub(crate) const WEBGPU_INIT_ERROR_PREFERRED_FORMAT_TYPE: &str = "WEBGPU_PREFERRED_FORMAT_TYPE";

/// The diagnostic code for a failed `GpuCanvasContext.configure` lookup.
pub(crate) const WEBGPU_INIT_ERROR_CONFIGURE_LOOKUP: &str = "WEBGPU_CONFIGURE_LOOKUP";

/// The diagnostic code for a failed `GpuDevice.queue` lookup.
pub(crate) const WEBGPU_INIT_ERROR_QUEUE_LOOKUP: &str = "WEBGPU_QUEUE_LOOKUP";

/// Placeholder text used by `js_error_to_string` when a `JsValue` is
/// `undefined` and therefore has no string form of its own.
pub(crate) const WEBGPU_JS_ERROR_UNDEFINED_LABEL: &str = "<undefined>";

/// Placeholder text used by `js_error_to_string` when a `JsValue` is `null`
/// and therefore has no string form of its own.
pub(crate) const WEBGPU_JS_ERROR_NULL_LABEL: &str = "<null>";