webgl2 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage.md +25 -20
- package/package.json +2 -2
- package/src/webgl2_context.js +82 -6
- package/src/webgl2_resources.js +16 -0
- package/src/webgpu_context.js +301 -0
- package/webgl2.debug.wasm +0 -0
- package/webgl2.wasm +0 -0
package/coverage.md
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
1
|
# Coverage Report
|
|
2
2
|
|
|
3
|
+
> **Legend:** 🟢 ≥80% | 🟡 ≥50% (or ≤6 lines) | 🟠 ≥20% | 🔴 <20%
|
|
4
|
+
|
|
3
5
|
| File | Lines Covered | Lines Missed | Total Lines | Coverage |
|
|
4
6
|
|---|---|---|---|---|
|
|
5
|
-
| src/
|
|
6
|
-
| src/arrayvec.rs | 0 | 1 | 1 | 0.00% 🔴 |
|
|
7
|
-
| src/binary16.rs | 0 | 2 | 2 | 0.00% 🔴 |
|
|
8
|
-
| src/core/code.rs | 0 | 2 | 2 | 0.00% 🔴 |
|
|
9
|
-
| src/core/globals.rs | 1 | 0 | 1 | 100.00% 🟢 |
|
|
10
|
-
| src/core/imports.rs | 0 | 1 | 1 | 0.00% 🔴 |
|
|
11
|
-
| src/imp_std.rs | 0 | 6 | 6 | 0.00% 🔴 |
|
|
12
|
-
| src/lexer.rs | 6 | 2 | 8 | 75.00% 🟡 |
|
|
13
|
-
| src/lib.rs | 73 | 14 | 87 | 83.91% 🟢 |
|
|
14
|
-
| src/math/rint.rs | 0 | 2 | 2 | 0.00% 🔴 |
|
|
7
|
+
| src/lib.rs | 79 | 20 | 99 | 79.80% 🟡 |
|
|
15
8
|
| src/naga_wasm_backend/backend.rs | 39 | 0 | 39 | 100.00% 🟢 |
|
|
16
9
|
| src/naga_wasm_backend/control_flow.rs | 15 | 4 | 19 | 78.95% 🟡 |
|
|
17
10
|
| src/naga_wasm_backend/expressions.rs | 27 | 12 | 39 | 69.23% 🟡 |
|
|
18
11
|
| src/naga_wasm_backend/types.rs | 6 | 0 | 6 | 100.00% 🟢 |
|
|
19
|
-
| src/
|
|
20
|
-
| src/
|
|
21
|
-
| src/
|
|
22
|
-
| src/
|
|
23
|
-
| src/
|
|
24
|
-
| src/
|
|
25
|
-
| src/
|
|
26
|
-
| src/
|
|
27
|
-
| src/webgl2_context.rs |
|
|
28
|
-
|
|
|
12
|
+
| src/wasm_gl_emu/rasterizer.rs | 6 | 0 | 6 | 100.00% 🟢 |
|
|
13
|
+
| src/webgl2_context/buffers.rs | 16 | 2 | 18 | 88.89% 🟢 |
|
|
14
|
+
| src/webgl2_context/drawing.rs | 27 | 3 | 30 | 90.00% 🟢 |
|
|
15
|
+
| src/webgl2_context/framebuffers.rs | 8 | 0 | 8 | 100.00% 🟢 |
|
|
16
|
+
| src/webgl2_context/registry.rs | 3 | 2 | 5 | 60.00% 🟡 |
|
|
17
|
+
| src/webgl2_context/renderbuffers.rs | 10 | 0 | 10 | 100.00% 🟢 |
|
|
18
|
+
| src/webgl2_context/shaders.rs | 61 | 0 | 61 | 100.00% 🟢 |
|
|
19
|
+
| src/webgl2_context/state.rs | 5 | 1 | 6 | 83.33% 🟢 |
|
|
20
|
+
| src/webgl2_context/textures.rs | 9 | 0 | 9 | 100.00% 🟢 |
|
|
21
|
+
| src/webgl2_context/types.rs | 11 | 1 | 12 | 91.67% 🟢 |
|
|
22
|
+
| src/webgl2_context/vaos.rs | 24 | 0 | 24 | 100.00% 🟢 |
|
|
23
|
+
| src/webgpu/adapter.rs | 0 | 1 | 1 | 0.00% 🟡 |
|
|
24
|
+
| **Total** | **346** | **46** | **392** | **88.27% 🟢** |
|
|
25
|
+
|
|
26
|
+
## Top Missed Files
|
|
27
|
+
|
|
28
|
+
| File | Lines Missed | Illustrative Line | Coverage |
|
|
29
|
+
|---|---|---|---|
|
|
30
|
+
| src/lib.rs | 20/99 | [57] `pub fn js_log(level: u32, s: &str) {` | 79.80% 🟡 |
|
|
31
|
+
| src/naga_wasm_backend/expressions.rs | 12/39 | [49] `if component_idx == 0 {` | 69.23% 🟡 |
|
|
32
|
+
| src/naga_wasm_backend/control_flow.rs | 4/19 | [80] `for _ in 0..types.len() {` | 78.95% 🟡 |
|
|
33
|
+
| src/webgl2_context/drawing.rs | 3/30 | [434] `if i + 2 >= vertices.len() {` | 90.00% 🟢 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webgl2",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "WebGL2 tools to derisk large GPU projects on the web beyond toys and demos.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"build-debug": "npm run build-debug-wasm-only && npm run build-debug-distill",
|
|
13
13
|
"build": "npm run build-release && npm run build-debug",
|
|
14
14
|
"prepublishOnly": "npm run build",
|
|
15
|
-
"test": "
|
|
15
|
+
"test": "node --import ./test/all-coverage.js --test test/*.test.js"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
package/src/webgl2_context.js
CHANGED
|
@@ -15,7 +15,7 @@ export const ERR_GL = 5;
|
|
|
15
15
|
export const ERR_INTERNAL = 6;
|
|
16
16
|
|
|
17
17
|
import { WasmWebGLTexture } from './webgl2_texture.js';
|
|
18
|
-
import { WasmWebGLShader, WasmWebGLProgram, WasmWebGLBuffer } from './webgl2_resources.js';
|
|
18
|
+
import { WasmWebGLShader, WasmWebGLProgram, WasmWebGLBuffer, WasmWebGLRenderbuffer } from './webgl2_resources.js';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* @implements {WebGL2RenderingContext}
|
|
@@ -42,8 +42,22 @@ export class WasmWebGL2RenderingContext {
|
|
|
42
42
|
VIEWPORT = 0x0BA2;
|
|
43
43
|
COLOR_CLEAR_VALUE = 0x0C22;
|
|
44
44
|
BUFFER_SIZE = 0x8764;
|
|
45
|
+
MAX_VERTEX_ATTRIBS = 0x8869;
|
|
45
46
|
NO_ERROR = 0;
|
|
46
47
|
|
|
48
|
+
RENDERBUFFER = 0x8D41;
|
|
49
|
+
FRAMEBUFFER = 0x8D40;
|
|
50
|
+
DEPTH_COMPONENT16 = 0x81A5;
|
|
51
|
+
DEPTH_STENCIL = 0x84F9;
|
|
52
|
+
RGBA4 = 0x8056;
|
|
53
|
+
RGB565 = 0x8D62;
|
|
54
|
+
RGB5_A1 = 0x8057;
|
|
55
|
+
STENCIL_INDEX8 = 0x8D48;
|
|
56
|
+
COLOR_ATTACHMENT0 = 0x8CE0;
|
|
57
|
+
DEPTH_ATTACHMENT = 0x8D00;
|
|
58
|
+
STENCIL_ATTACHMENT = 0x8D20;
|
|
59
|
+
DEPTH_STENCIL_ATTACHMENT = 0x821A;
|
|
60
|
+
|
|
47
61
|
TEXTURE_2D = 0x0DE1;
|
|
48
62
|
TEXTURE_WRAP_S = 0x2802;
|
|
49
63
|
TEXTURE_WRAP_T = 0x2803;
|
|
@@ -238,6 +252,69 @@ export class WasmWebGL2RenderingContext {
|
|
|
238
252
|
_checkErr(code, this._instance);
|
|
239
253
|
}
|
|
240
254
|
|
|
255
|
+
createRenderbuffer() {
|
|
256
|
+
this._assertNotDestroyed();
|
|
257
|
+
const ex = this._instance.exports;
|
|
258
|
+
if (!ex || typeof ex.wasm_ctx_create_renderbuffer !== 'function') {
|
|
259
|
+
throw new Error('wasm_ctx_create_renderbuffer not found');
|
|
260
|
+
}
|
|
261
|
+
const handle = ex.wasm_ctx_create_renderbuffer(this._ctxHandle);
|
|
262
|
+
if (handle === 0) {
|
|
263
|
+
const msg = readErrorMessage(this._instance);
|
|
264
|
+
throw new Error(`Failed to create renderbuffer: ${msg}`);
|
|
265
|
+
}
|
|
266
|
+
return new WasmWebGLRenderbuffer(this, handle);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
bindRenderbuffer(target, renderbuffer) {
|
|
270
|
+
this._assertNotDestroyed();
|
|
271
|
+
const ex = this._instance.exports;
|
|
272
|
+
if (!ex || typeof ex.wasm_ctx_bind_renderbuffer !== 'function') {
|
|
273
|
+
throw new Error('wasm_ctx_bind_renderbuffer not found');
|
|
274
|
+
}
|
|
275
|
+
const rbHandle = renderbuffer && typeof renderbuffer === 'object' && typeof renderbuffer._handle === 'number' ? renderbuffer._handle : (renderbuffer >>> 0);
|
|
276
|
+
const code = ex.wasm_ctx_bind_renderbuffer(this._ctxHandle, target >>> 0, rbHandle);
|
|
277
|
+
_checkErr(code, this._instance);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
deleteRenderbuffer(renderbuffer) {
|
|
281
|
+
this._assertNotDestroyed();
|
|
282
|
+
const ex = this._instance.exports;
|
|
283
|
+
if (!ex || typeof ex.wasm_ctx_delete_renderbuffer !== 'function') {
|
|
284
|
+
throw new Error('wasm_ctx_delete_renderbuffer not found');
|
|
285
|
+
}
|
|
286
|
+
const rbHandle = renderbuffer && typeof renderbuffer === 'object' && typeof renderbuffer._handle === 'number' ? renderbuffer._handle : (renderbuffer >>> 0);
|
|
287
|
+
const code = ex.wasm_ctx_delete_renderbuffer(this._ctxHandle, rbHandle);
|
|
288
|
+
_checkErr(code, this._instance);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
renderbufferStorage(target, internalFormat, width, height) {
|
|
292
|
+
this._assertNotDestroyed();
|
|
293
|
+
const ex = this._instance.exports;
|
|
294
|
+
if (!ex || typeof ex.wasm_ctx_renderbuffer_storage !== 'function') {
|
|
295
|
+
throw new Error('wasm_ctx_renderbuffer_storage not found');
|
|
296
|
+
}
|
|
297
|
+
const code = ex.wasm_ctx_renderbuffer_storage(this._ctxHandle, target >>> 0, internalFormat >>> 0, width | 0, height | 0);
|
|
298
|
+
_checkErr(code, this._instance);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
framebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) {
|
|
302
|
+
this._assertNotDestroyed();
|
|
303
|
+
const ex = this._instance.exports;
|
|
304
|
+
if (!ex || typeof ex.wasm_ctx_framebuffer_renderbuffer !== 'function') {
|
|
305
|
+
throw new Error('wasm_ctx_framebuffer_renderbuffer not found');
|
|
306
|
+
}
|
|
307
|
+
const rbHandle = renderbuffer && typeof renderbuffer === 'object' && typeof renderbuffer._handle === 'number' ? renderbuffer._handle : (renderbuffer >>> 0);
|
|
308
|
+
const code = ex.wasm_ctx_framebuffer_renderbuffer(
|
|
309
|
+
this._ctxHandle,
|
|
310
|
+
target >>> 0,
|
|
311
|
+
attachment >>> 0,
|
|
312
|
+
renderbuffertarget >>> 0,
|
|
313
|
+
rbHandle
|
|
314
|
+
);
|
|
315
|
+
_checkErr(code, this._instance);
|
|
316
|
+
}
|
|
317
|
+
|
|
241
318
|
readPixels(x, y, width, height, format, type_, out) {
|
|
242
319
|
this._assertNotDestroyed();
|
|
243
320
|
const ex = this._instance.exports;
|
|
@@ -918,11 +995,6 @@ export class WasmWebGL2RenderingContext {
|
|
|
918
995
|
copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
919
996
|
texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
920
997
|
|
|
921
|
-
createRenderbuffer() { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
922
|
-
bindRenderbuffer(target, rb) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
923
|
-
deleteRenderbuffer(rb) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
924
|
-
renderbufferStorage(target, internalformat, width, height) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
925
|
-
framebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
926
998
|
checkFramebufferStatus(target) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
927
999
|
blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
928
1000
|
readBuffer(src) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
@@ -1071,6 +1143,10 @@ export class WasmWebGL2RenderingContext {
|
|
|
1071
1143
|
}
|
|
1072
1144
|
}
|
|
1073
1145
|
|
|
1146
|
+
if (pname === 0x8869 /* MAX_VERTEX_ATTRIBS */) {
|
|
1147
|
+
return 16;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1074
1150
|
throw new Error(`getParameter for ${pname} not implemented`);
|
|
1075
1151
|
}
|
|
1076
1152
|
getError() {
|
package/src/webgl2_resources.js
CHANGED
|
@@ -49,3 +49,19 @@ export class WasmWebGLBuffer {
|
|
|
49
49
|
this._deleted = false;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Thin wrapper for a WebGLRenderbuffer handle returned from WASM.
|
|
55
|
+
* @implements {WebGLRenderbuffer}
|
|
56
|
+
*/
|
|
57
|
+
export class WasmWebGLRenderbuffer {
|
|
58
|
+
/**
|
|
59
|
+
* @param {import('./webgl2_context.js').WasmWebGL2RenderingContext} ctx
|
|
60
|
+
* @param {number} handle
|
|
61
|
+
*/
|
|
62
|
+
constructor(ctx, handle) {
|
|
63
|
+
this._ctx = ctx;
|
|
64
|
+
this._handle = handle;
|
|
65
|
+
this._deleted = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebGPU API implementation for WebAssembly
|
|
3
|
+
*
|
|
4
|
+
* This module provides a complete WebGPU API surface that runs entirely in
|
|
5
|
+
* WebAssembly/Rust, enabling deterministic execution, advanced debugging,
|
|
6
|
+
* and software rasterization of WebGPU workloads.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export class GPU {
|
|
10
|
+
constructor(wasmModule, wasmMemory) {
|
|
11
|
+
this.wasm = wasmModule;
|
|
12
|
+
this.memory = wasmMemory;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Request a GPUAdapter
|
|
17
|
+
* @param {Object} options - Adapter request options
|
|
18
|
+
* @returns {Promise<GPUAdapter>}
|
|
19
|
+
*/
|
|
20
|
+
async requestAdapter(options = {}) {
|
|
21
|
+
// Create a WebGPU context
|
|
22
|
+
const ctxHandle = this.wasm.wasm_webgpu_create_context();
|
|
23
|
+
if (ctxHandle === 0) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return new GPUAdapter(this.wasm, this.memory, ctxHandle);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class GPUAdapter {
|
|
32
|
+
constructor(wasmModule, wasmMemory, ctxHandle) {
|
|
33
|
+
this.wasm = wasmModule;
|
|
34
|
+
this.memory = wasmMemory;
|
|
35
|
+
this.ctxHandle = ctxHandle;
|
|
36
|
+
this.features = new Set();
|
|
37
|
+
this.limits = {};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Request a GPUDevice
|
|
42
|
+
* @param {Object} descriptor - Device descriptor
|
|
43
|
+
* @returns {Promise<GPUDevice>}
|
|
44
|
+
*/
|
|
45
|
+
async requestDevice(descriptor = {}) {
|
|
46
|
+
// TODO: Call wasm function to create device
|
|
47
|
+
// Using placeholder handle until WASM integration is complete
|
|
48
|
+
const deviceHandle = 1; // FIXME: Generate unique handles
|
|
49
|
+
return new GPUDevice(this.wasm, this.memory, this.ctxHandle, deviceHandle);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class GPUDevice {
|
|
54
|
+
constructor(wasmModule, wasmMemory, ctxHandle, deviceHandle) {
|
|
55
|
+
this.wasm = wasmModule;
|
|
56
|
+
this.memory = wasmMemory;
|
|
57
|
+
this.ctxHandle = ctxHandle;
|
|
58
|
+
this.deviceHandle = deviceHandle;
|
|
59
|
+
this.queue = new GPUQueue(wasmModule, wasmMemory, ctxHandle, 1); // Placeholder queue handle
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Create a buffer
|
|
64
|
+
* @param {Object} descriptor - Buffer descriptor
|
|
65
|
+
* @returns {GPUBuffer}
|
|
66
|
+
*/
|
|
67
|
+
createBuffer(descriptor) {
|
|
68
|
+
// TODO: Call wasm function to create buffer
|
|
69
|
+
const bufferHandle = 1; // Placeholder
|
|
70
|
+
return new GPUBuffer(this.wasm, this.memory, this.ctxHandle, bufferHandle, descriptor.size);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Create a shader module
|
|
75
|
+
* @param {Object} descriptor - Shader module descriptor
|
|
76
|
+
* @returns {GPUShaderModule}
|
|
77
|
+
*/
|
|
78
|
+
createShaderModule(descriptor) {
|
|
79
|
+
// TODO: Call wasm function to create shader module
|
|
80
|
+
const moduleHandle = 1; // Placeholder
|
|
81
|
+
return new GPUShaderModule(this.wasm, this.memory, this.ctxHandle, moduleHandle);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Create a render pipeline
|
|
86
|
+
* @param {Object} descriptor - Render pipeline descriptor
|
|
87
|
+
* @returns {GPURenderPipeline}
|
|
88
|
+
*/
|
|
89
|
+
createRenderPipeline(descriptor) {
|
|
90
|
+
// TODO: Call wasm function to create render pipeline
|
|
91
|
+
const pipelineHandle = 1; // Placeholder
|
|
92
|
+
return new GPURenderPipeline(this.wasm, this.memory, this.ctxHandle, pipelineHandle);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Create a command encoder
|
|
97
|
+
* @param {Object} descriptor - Command encoder descriptor
|
|
98
|
+
* @returns {GPUCommandEncoder}
|
|
99
|
+
*/
|
|
100
|
+
createCommandEncoder(descriptor = {}) {
|
|
101
|
+
// TODO: Call wasm function to create command encoder
|
|
102
|
+
const encoderHandle = 1; // Placeholder
|
|
103
|
+
return new GPUCommandEncoder(this.wasm, this.memory, this.ctxHandle, encoderHandle);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Destroy the device
|
|
108
|
+
*/
|
|
109
|
+
destroy() {
|
|
110
|
+
// TODO: Clean up device resources
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export class GPUQueue {
|
|
115
|
+
constructor(wasmModule, wasmMemory, ctxHandle, queueHandle) {
|
|
116
|
+
this.wasm = wasmModule;
|
|
117
|
+
this.memory = wasmMemory;
|
|
118
|
+
this.ctxHandle = ctxHandle;
|
|
119
|
+
this.queueHandle = queueHandle;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Submit command buffers to the queue
|
|
124
|
+
* @param {Array<GPUCommandBuffer>} commandBuffers
|
|
125
|
+
*/
|
|
126
|
+
submit(commandBuffers) {
|
|
127
|
+
// TODO: Call wasm function to submit command buffers
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Write data to a buffer
|
|
132
|
+
* @param {GPUBuffer} buffer
|
|
133
|
+
* @param {number} bufferOffset
|
|
134
|
+
* @param {ArrayBuffer|TypedArray} data
|
|
135
|
+
* @param {number} dataOffset
|
|
136
|
+
* @param {number} size
|
|
137
|
+
*/
|
|
138
|
+
writeBuffer(buffer, bufferOffset, data, dataOffset = 0, size) {
|
|
139
|
+
// TODO: Call wasm function to write buffer
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export class GPUBuffer {
|
|
144
|
+
constructor(wasmModule, wasmMemory, ctxHandle, bufferHandle, size) {
|
|
145
|
+
this.wasm = wasmModule;
|
|
146
|
+
this.memory = wasmMemory;
|
|
147
|
+
this.ctxHandle = ctxHandle;
|
|
148
|
+
this.bufferHandle = bufferHandle;
|
|
149
|
+
this.size = size;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Map buffer for reading/writing
|
|
154
|
+
* @param {number} mode - Map mode
|
|
155
|
+
* @param {number} offset
|
|
156
|
+
* @param {number} size
|
|
157
|
+
* @returns {Promise<void>}
|
|
158
|
+
*/
|
|
159
|
+
async mapAsync(mode, offset = 0, size) {
|
|
160
|
+
// TODO: Implement buffer mapping
|
|
161
|
+
return Promise.resolve();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Get mapped range
|
|
166
|
+
* @param {number} offset
|
|
167
|
+
* @param {number} size
|
|
168
|
+
* @returns {ArrayBuffer}
|
|
169
|
+
*/
|
|
170
|
+
getMappedRange(offset = 0, size) {
|
|
171
|
+
// TODO: Return mapped range
|
|
172
|
+
return new ArrayBuffer(size || this.size);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Unmap the buffer
|
|
177
|
+
*/
|
|
178
|
+
unmap() {
|
|
179
|
+
// TODO: Implement unmapping
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Destroy the buffer
|
|
184
|
+
*/
|
|
185
|
+
destroy() {
|
|
186
|
+
// TODO: Call wasm function to destroy buffer
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export class GPUShaderModule {
|
|
191
|
+
constructor(wasmModule, wasmMemory, ctxHandle, moduleHandle) {
|
|
192
|
+
this.wasm = wasmModule;
|
|
193
|
+
this.memory = wasmMemory;
|
|
194
|
+
this.ctxHandle = ctxHandle;
|
|
195
|
+
this.moduleHandle = moduleHandle;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export class GPURenderPipeline {
|
|
200
|
+
constructor(wasmModule, wasmMemory, ctxHandle, pipelineHandle) {
|
|
201
|
+
this.wasm = wasmModule;
|
|
202
|
+
this.memory = wasmMemory;
|
|
203
|
+
this.ctxHandle = ctxHandle;
|
|
204
|
+
this.pipelineHandle = pipelineHandle;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export class GPUCommandEncoder {
|
|
209
|
+
constructor(wasmModule, wasmMemory, ctxHandle, encoderHandle) {
|
|
210
|
+
this.wasm = wasmModule;
|
|
211
|
+
this.memory = wasmMemory;
|
|
212
|
+
this.ctxHandle = ctxHandle;
|
|
213
|
+
this.encoderHandle = encoderHandle;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Begin a render pass
|
|
218
|
+
* @param {Object} descriptor - Render pass descriptor
|
|
219
|
+
* @returns {GPURenderPassEncoder}
|
|
220
|
+
*/
|
|
221
|
+
beginRenderPass(descriptor) {
|
|
222
|
+
// TODO: Call wasm function to begin render pass
|
|
223
|
+
const passHandle = 1; // Placeholder
|
|
224
|
+
return new GPURenderPassEncoder(this.wasm, this.memory, this.ctxHandle, passHandle);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Finish encoding and create a command buffer
|
|
229
|
+
* @returns {GPUCommandBuffer}
|
|
230
|
+
*/
|
|
231
|
+
finish() {
|
|
232
|
+
// TODO: Call wasm function to finish encoding
|
|
233
|
+
const commandBufferHandle = 1; // Placeholder
|
|
234
|
+
return new GPUCommandBuffer(this.wasm, this.memory, this.ctxHandle, commandBufferHandle);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export class GPURenderPassEncoder {
|
|
239
|
+
constructor(wasmModule, wasmMemory, ctxHandle, passHandle) {
|
|
240
|
+
this.wasm = wasmModule;
|
|
241
|
+
this.memory = wasmMemory;
|
|
242
|
+
this.ctxHandle = ctxHandle;
|
|
243
|
+
this.passHandle = passHandle;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Set the render pipeline
|
|
248
|
+
* @param {GPURenderPipeline} pipeline
|
|
249
|
+
*/
|
|
250
|
+
setPipeline(pipeline) {
|
|
251
|
+
// TODO: Call wasm function to set pipeline
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Set vertex buffer
|
|
256
|
+
* @param {number} slot
|
|
257
|
+
* @param {GPUBuffer} buffer
|
|
258
|
+
* @param {number} offset
|
|
259
|
+
* @param {number} size
|
|
260
|
+
*/
|
|
261
|
+
setVertexBuffer(slot, buffer, offset = 0, size) {
|
|
262
|
+
// TODO: Call wasm function to set vertex buffer
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Draw vertices
|
|
267
|
+
* @param {number} vertexCount
|
|
268
|
+
* @param {number} instanceCount
|
|
269
|
+
* @param {number} firstVertex
|
|
270
|
+
* @param {number} firstInstance
|
|
271
|
+
*/
|
|
272
|
+
draw(vertexCount, instanceCount = 1, firstVertex = 0, firstInstance = 0) {
|
|
273
|
+
// TODO: Call wasm function to draw
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* End the render pass
|
|
278
|
+
*/
|
|
279
|
+
end() {
|
|
280
|
+
// TODO: Call wasm function to end render pass
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export class GPUCommandBuffer {
|
|
285
|
+
constructor(wasmModule, wasmMemory, ctxHandle, commandBufferHandle) {
|
|
286
|
+
this.wasm = wasmModule;
|
|
287
|
+
this.memory = wasmMemory;
|
|
288
|
+
this.ctxHandle = ctxHandle;
|
|
289
|
+
this.commandBufferHandle = commandBufferHandle;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Create a navigator.gpu object
|
|
295
|
+
* @param {Object} wasmModule - WebAssembly module
|
|
296
|
+
* @param {WebAssembly.Memory} wasmMemory - WebAssembly memory
|
|
297
|
+
* @returns {GPU}
|
|
298
|
+
*/
|
|
299
|
+
export function createWebGPU(wasmModule, wasmMemory) {
|
|
300
|
+
return new GPU(wasmModule, wasmMemory);
|
|
301
|
+
}
|
package/webgl2.debug.wasm
CHANGED
|
Binary file
|
package/webgl2.wasm
CHANGED
|
Binary file
|