@obinexusltd/obix-driver-gpu-acceleration 0.1.0 → 0.1.1
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/README.md +189 -0
- package/dist/buffer-manager.d.ts +7 -0
- package/dist/buffer-manager.d.ts.map +1 -0
- package/dist/buffer-manager.js +93 -0
- package/dist/buffer-manager.js.map +1 -0
- package/dist/compute-pipeline.d.ts +7 -0
- package/dist/compute-pipeline.d.ts.map +1 -0
- package/dist/compute-pipeline.js +34 -0
- package/dist/compute-pipeline.js.map +1 -0
- package/dist/index.d.ts +12 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +230 -15
- package/dist/index.js.map +1 -1
- package/dist/profiler.d.ts +7 -0
- package/dist/profiler.d.ts.map +1 -0
- package/dist/profiler.js +105 -0
- package/dist/profiler.js.map +1 -0
- package/dist/render-queue.d.ts +7 -0
- package/dist/render-queue.d.ts.map +1 -0
- package/dist/render-queue.js +96 -0
- package/dist/render-queue.js.map +1 -0
- package/dist/resource-manager.d.ts +6 -0
- package/dist/resource-manager.d.ts.map +1 -0
- package/dist/resource-manager.js +91 -0
- package/dist/resource-manager.js.map +1 -0
- package/dist/shader-compiler.d.ts +7 -0
- package/dist/shader-compiler.d.ts.map +1 -0
- package/dist/shader-compiler.js +177 -0
- package/dist/shader-compiler.js.map +1 -0
- package/dist/texture-manager.d.ts +7 -0
- package/dist/texture-manager.d.ts.map +1 -0
- package/dist/texture-manager.js +155 -0
- package/dist/texture-manager.js.map +1 -0
- package/dist/types.d.ts +189 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/webgl-context.d.ts +7 -0
- package/dist/webgl-context.d.ts.map +1 -0
- package/dist/webgl-context.js +110 -0
- package/dist/webgl-context.js.map +1 -0
- package/dist/webgpu-backend.d.ts +7 -0
- package/dist/webgpu-backend.d.ts.map +1 -0
- package/dist/webgpu-backend.js +77 -0
- package/dist/webgpu-backend.js.map +1 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# @obinexusltd/obix-driver-gpu-acceleration
|
|
2
|
+
|
|
3
|
+
**Version:** 0.1.0 | **License:** MIT | **Author:** OBINexus <okpalan@protonmail.com>
|
|
4
|
+
|
|
5
|
+
A unified GPU acceleration driver for the OBIX SDK, providing WebGL 2.0 and WebGPU canvas rendering with shader management, resource lifecycle tracking, and performance profiling.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Dual backend support** — WebGPU (preferred) with automatic fallback to WebGL 2.0
|
|
12
|
+
- **Shader management** — GLSL compilation, caching, and deduplication via source hashing
|
|
13
|
+
- **Buffer management** — Vertex, index, and uniform buffer creation with CPU-side copies for context recovery
|
|
14
|
+
- **Texture management** — Multi-format texture allocation (`rgba8`, `rgb8`, `r8`, `depth24`, `depth32f`), mipmapping, and framebuffer objects
|
|
15
|
+
- **Render queue** — Command batching sorted by shader to minimize GPU state changes
|
|
16
|
+
- **Compute pipeline** — WebGPU compute shader dispatch
|
|
17
|
+
- **Resource manager** — Reference counting and garbage collection with leak detection
|
|
18
|
+
- **Profiler** — Frame time tracking, GPU timing queries, and throttle detection
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @obinexusltd/obix-driver-gpu-acceleration
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { createGPUAccelerationDriver } from '@obinexusltd/obix-driver-gpu-acceleration';
|
|
34
|
+
|
|
35
|
+
const canvas = document.querySelector<HTMLCanvasElement>('#canvas')!;
|
|
36
|
+
|
|
37
|
+
const driver = createGPUAccelerationDriver({
|
|
38
|
+
canvas,
|
|
39
|
+
preferWebGPU: true,
|
|
40
|
+
enableProfiling: true,
|
|
41
|
+
powerPreference: 'high-performance',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
await driver.initialize();
|
|
45
|
+
|
|
46
|
+
// Load and compile a shader
|
|
47
|
+
const shader = await driver.loadShader('main', vertSrc, fragSrc);
|
|
48
|
+
|
|
49
|
+
// Frame loop
|
|
50
|
+
function render() {
|
|
51
|
+
driver.beginFrame();
|
|
52
|
+
driver.clear([0, 0, 0, 1]);
|
|
53
|
+
|
|
54
|
+
// Create a vertex buffer
|
|
55
|
+
const vbuf = driver.createBuffer('vertex', new Float32Array([...]));
|
|
56
|
+
|
|
57
|
+
// Queue a draw call
|
|
58
|
+
driver.drawIndexed(shader, vbuf, indexBuf, indexCount);
|
|
59
|
+
|
|
60
|
+
driver.endFrame();
|
|
61
|
+
|
|
62
|
+
const metrics = driver.getMetrics();
|
|
63
|
+
console.log(`Frame: ${metrics.frameTime.toFixed(2)}ms | Draw calls: ${metrics.drawCalls}`);
|
|
64
|
+
|
|
65
|
+
requestAnimationFrame(render);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
requestAnimationFrame(render);
|
|
69
|
+
|
|
70
|
+
// Cleanup
|
|
71
|
+
window.addEventListener('beforeunload', () => driver.destroy());
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Configuration
|
|
77
|
+
|
|
78
|
+
| Option | Type | Default | Description |
|
|
79
|
+
|--------|------|---------|-------------|
|
|
80
|
+
| `canvas` | `HTMLCanvasElement` | required | Target canvas element |
|
|
81
|
+
| `preferWebGPU` | `boolean` | `false` | Use WebGPU when available; falls back to WebGL 2.0 |
|
|
82
|
+
| `antialias` | `boolean` | `true` | Enable antialiasing (WebGL only) |
|
|
83
|
+
| `enableProfiling` | `boolean` | `true` | Enable frame time and GPU query tracking |
|
|
84
|
+
| `powerPreference` | `'default' \| 'high-performance' \| 'low-power'` | `'default'` | GPU power hint |
|
|
85
|
+
| `contextLossStrategy` | `'restore' \| 'recreate' \| 'notify'` | `'restore'` | How to handle WebGL context loss |
|
|
86
|
+
| `maxTextureSize` | `number` | queried from GL | Maximum texture dimension |
|
|
87
|
+
| `shaderPaths` | `string[]` | `[]` | Planned: paths for shader asset loading |
|
|
88
|
+
| `resourcePoolSize` | `number` | — | Planned: pre-allocated resource pool size |
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## API Overview
|
|
93
|
+
|
|
94
|
+
### Lifecycle
|
|
95
|
+
|
|
96
|
+
| Method | Description |
|
|
97
|
+
|--------|-------------|
|
|
98
|
+
| `initialize()` | Set up the GPU backend and all sub-modules |
|
|
99
|
+
| `destroy()` | Release all GPU resources and tear down the backend |
|
|
100
|
+
|
|
101
|
+
### Frame
|
|
102
|
+
|
|
103
|
+
| Method | Description |
|
|
104
|
+
|--------|-------------|
|
|
105
|
+
| `beginFrame()` | Start a new render frame |
|
|
106
|
+
| `endFrame()` | Flush the render queue and submit commands |
|
|
107
|
+
| `clear(color?)` | Clear the canvas with an optional RGBA color |
|
|
108
|
+
|
|
109
|
+
### Shaders
|
|
110
|
+
|
|
111
|
+
| Method | Description |
|
|
112
|
+
|--------|-------------|
|
|
113
|
+
| `loadShader(name, vert, frag)` | Compile and cache a GLSL shader program |
|
|
114
|
+
| `useShader(shader)` | Bind a compiled shader program |
|
|
115
|
+
|
|
116
|
+
### Buffers
|
|
117
|
+
|
|
118
|
+
| Method | Description |
|
|
119
|
+
|--------|-------------|
|
|
120
|
+
| `createBuffer(usage, data)` | Allocate a vertex, index, or uniform buffer |
|
|
121
|
+
| `updateBuffer(handle, data)` | Upload new data to an existing buffer |
|
|
122
|
+
| `deleteBuffer(handle)` | Free a buffer and release its GPU memory |
|
|
123
|
+
|
|
124
|
+
### Textures
|
|
125
|
+
|
|
126
|
+
| Method | Description |
|
|
127
|
+
|--------|-------------|
|
|
128
|
+
| `createTexture(width, height, format, data?)` | Allocate a 2D texture |
|
|
129
|
+
| `createFramebuffer(texture)` | Create a framebuffer backed by a texture |
|
|
130
|
+
|
|
131
|
+
### Draw
|
|
132
|
+
|
|
133
|
+
| Method | Description |
|
|
134
|
+
|--------|-------------|
|
|
135
|
+
| `drawIndexed(shader, vbuf, ibuf, count, uniforms?)` | Queue an indexed draw call |
|
|
136
|
+
|
|
137
|
+
### Compute (WebGPU only)
|
|
138
|
+
|
|
139
|
+
| Method | Description |
|
|
140
|
+
|--------|-------------|
|
|
141
|
+
| `dispatchCompute(shader, x, y, z)` | Dispatch a compute shader workgroup |
|
|
142
|
+
|
|
143
|
+
### Profiler
|
|
144
|
+
|
|
145
|
+
| Method | Description |
|
|
146
|
+
|--------|-------------|
|
|
147
|
+
| `getMetrics()` | Returns `FrameMetrics`: frameTime, gpuTime, drawCalls, triangles, memory, throttled |
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Architecture
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
GPUAccelerationDriver
|
|
155
|
+
├── Backend selection
|
|
156
|
+
│ ├── WebGPU (preferred, when navigator.gpu is available)
|
|
157
|
+
│ └── WebGL 2.0 (fallback)
|
|
158
|
+
├── ShaderCompiler — GLSL compilation & uniform caching
|
|
159
|
+
├── BufferManager — Vertex / index / uniform buffers
|
|
160
|
+
├── TextureManager — 2D textures & framebuffers
|
|
161
|
+
├── RenderQueue — Batched, shader-sorted draw commands
|
|
162
|
+
├── ComputePipeline — WebGPU compute dispatch
|
|
163
|
+
├── ResourceManager — Reference counting & GC
|
|
164
|
+
└── Profiler — Frame timing & GPU queries
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Backend selection happens at `initialize()`. If `preferWebGPU: true` and `navigator.gpu` is present the WebGPU path is taken; otherwise the driver falls back to WebGL 2.0. All public APIs are backend-agnostic.
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Development
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# Build (TypeScript -> dist/)
|
|
175
|
+
npm run build
|
|
176
|
+
|
|
177
|
+
# Run tests
|
|
178
|
+
npm test
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- Source: `src/`
|
|
182
|
+
- Output: `dist/` (ES modules + `.d.ts` declarations)
|
|
183
|
+
- Test runner: [Vitest](https://vitest.dev)
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
MIT — Copyright (c) OBINexus (okpalan@protonmail.com)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vertex & Index Buffer Management
|
|
3
|
+
* GPU buffer creation, data upload, and memory management
|
|
4
|
+
*/
|
|
5
|
+
import type { BackendContext, BufferManagerAPI, ResourceManagerAPI } from './types.js';
|
|
6
|
+
export declare function createBufferManager(backend: BackendContext, resourceManager: ResourceManagerAPI): BufferManagerAPI;
|
|
7
|
+
//# sourceMappingURL=buffer-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-manager.d.ts","sourceRoot":"","sources":["../src/buffer-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,cAAc,EAGd,gBAAgB,EAEhB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAepB,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,cAAc,EACvB,eAAe,EAAE,kBAAkB,GAClC,gBAAgB,CAyFlB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vertex & Index Buffer Management
|
|
3
|
+
* GPU buffer creation, data upload, and memory management
|
|
4
|
+
*/
|
|
5
|
+
function getGLBufferTarget(gl, usage) {
|
|
6
|
+
switch (usage) {
|
|
7
|
+
case 'vertex': return gl.ARRAY_BUFFER;
|
|
8
|
+
case 'index': return gl.ELEMENT_ARRAY_BUFFER;
|
|
9
|
+
case 'uniform': return gl.UNIFORM_BUFFER;
|
|
10
|
+
case 'storage': return gl.ARRAY_BUFFER; // WebGL2 uses SSBO-like patterns via UBO
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function getGLUsageHint(gl, dynamic) {
|
|
14
|
+
return dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
|
|
15
|
+
}
|
|
16
|
+
export function createBufferManager(backend, resourceManager) {
|
|
17
|
+
const bufferTargets = new Map();
|
|
18
|
+
const bufferDataCopies = new Map();
|
|
19
|
+
let totalMemory = 0;
|
|
20
|
+
return {
|
|
21
|
+
create(descriptor) {
|
|
22
|
+
const gl = backend.gl;
|
|
23
|
+
const id = resourceManager.nextId();
|
|
24
|
+
const byteSize = descriptor.data.byteLength;
|
|
25
|
+
let glBuffer;
|
|
26
|
+
if (gl) {
|
|
27
|
+
const buffer = gl.createBuffer();
|
|
28
|
+
if (buffer) {
|
|
29
|
+
glBuffer = buffer;
|
|
30
|
+
const target = getGLBufferTarget(gl, descriptor.usage);
|
|
31
|
+
gl.bindBuffer(target, buffer);
|
|
32
|
+
gl.bufferData(target, descriptor.data, getGLUsageHint(gl, descriptor.dynamic ?? false));
|
|
33
|
+
gl.bindBuffer(target, null);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const handle = {
|
|
37
|
+
id,
|
|
38
|
+
type: 'buffer',
|
|
39
|
+
byteSize,
|
|
40
|
+
glBuffer,
|
|
41
|
+
};
|
|
42
|
+
bufferTargets.set(id, descriptor.usage);
|
|
43
|
+
// Keep CPU-side copy for context loss recovery
|
|
44
|
+
bufferDataCopies.set(id, descriptor.data);
|
|
45
|
+
totalMemory += byteSize;
|
|
46
|
+
resourceManager.register(handle, () => {
|
|
47
|
+
if (gl && glBuffer) {
|
|
48
|
+
gl.deleteBuffer(glBuffer);
|
|
49
|
+
}
|
|
50
|
+
bufferTargets.delete(id);
|
|
51
|
+
bufferDataCopies.delete(id);
|
|
52
|
+
totalMemory -= byteSize;
|
|
53
|
+
});
|
|
54
|
+
return handle;
|
|
55
|
+
},
|
|
56
|
+
update(handle, data, offset = 0) {
|
|
57
|
+
const gl = backend.gl;
|
|
58
|
+
if (!gl || !handle.glBuffer)
|
|
59
|
+
return;
|
|
60
|
+
const usage = bufferTargets.get(handle.id);
|
|
61
|
+
if (!usage)
|
|
62
|
+
return;
|
|
63
|
+
const target = getGLBufferTarget(gl, usage);
|
|
64
|
+
gl.bindBuffer(target, handle.glBuffer);
|
|
65
|
+
gl.bufferSubData(target, offset, data);
|
|
66
|
+
gl.bindBuffer(target, null);
|
|
67
|
+
// Update CPU-side copy
|
|
68
|
+
bufferDataCopies.set(handle.id, data);
|
|
69
|
+
},
|
|
70
|
+
bind(handle) {
|
|
71
|
+
const gl = backend.gl;
|
|
72
|
+
if (!gl || !handle.glBuffer)
|
|
73
|
+
return;
|
|
74
|
+
const usage = bufferTargets.get(handle.id);
|
|
75
|
+
if (!usage)
|
|
76
|
+
return;
|
|
77
|
+
const target = getGLBufferTarget(gl, usage);
|
|
78
|
+
gl.bindBuffer(target, handle.glBuffer);
|
|
79
|
+
},
|
|
80
|
+
delete(handle) {
|
|
81
|
+
resourceManager.release(handle.id);
|
|
82
|
+
},
|
|
83
|
+
getMemoryUsage() {
|
|
84
|
+
return totalMemory;
|
|
85
|
+
},
|
|
86
|
+
destroy() {
|
|
87
|
+
bufferTargets.clear();
|
|
88
|
+
bufferDataCopies.clear();
|
|
89
|
+
totalMemory = 0;
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=buffer-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-manager.js","sourceRoot":"","sources":["../src/buffer-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,SAAS,iBAAiB,CAAC,EAA0B,EAAE,KAAkB;IACvE,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC,YAAY,CAAC;QACtC,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AAC,CAAC;YACvC,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAE5B,uBAAuB;YACvB,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACxC,CAAC;QAED,IAAI,CAAC,MAAoB;YACvB,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;YACtB,IAAI,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ;gBAAE,OAAO;YAEpC,MAAM,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAC3C,IAAI,CAAC,KAAK;gBAAE,OAAO;YAEnB,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YAC5C,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;QACzC,CAAC;QAED,MAAM,CAAC,MAAoB;YACzB,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACrC,CAAC;QAED,cAAc;YACZ,OAAO,WAAW,CAAC;QACrB,CAAC;QAED,OAAO;YACL,aAAa,CAAC,KAAK,EAAE,CAAC;YACtB,gBAAgB,CAAC,KAAK,EAAE,CAAC;YACzB,WAAW,GAAG,CAAC,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute Shader Pipeline (WebGPU-only)
|
|
3
|
+
* General-purpose GPU computing for data-parallel tasks
|
|
4
|
+
*/
|
|
5
|
+
import type { BackendContext, ComputePipelineAPI } from './types.js';
|
|
6
|
+
export declare function createComputePipeline(backend: BackendContext): ComputePipelineAPI;
|
|
7
|
+
//# sourceMappingURL=compute-pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compute-pipeline.d.ts","sourceRoot":"","sources":["../src/compute-pipeline.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErE,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,GAAG,kBAAkB,CAmCjF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute Shader Pipeline (WebGPU-only)
|
|
3
|
+
* General-purpose GPU computing for data-parallel tasks
|
|
4
|
+
*/
|
|
5
|
+
export function createComputePipeline(backend) {
|
|
6
|
+
const isWebGPU = backend.type === 'webgpu';
|
|
7
|
+
return {
|
|
8
|
+
get supported() {
|
|
9
|
+
return isWebGPU;
|
|
10
|
+
},
|
|
11
|
+
dispatch(shader, workgroups) {
|
|
12
|
+
if (!isWebGPU) {
|
|
13
|
+
throw new Error(`Compute shaders require WebGPU backend (current: ${backend.type}). ` +
|
|
14
|
+
'Set preferWebGPU: true in driver config if WebGPU is available.');
|
|
15
|
+
}
|
|
16
|
+
// WebGPU compute dispatch would use:
|
|
17
|
+
// const pipeline = device.createComputePipeline(...)
|
|
18
|
+
// const encoder = device.createCommandEncoder()
|
|
19
|
+
// const pass = encoder.beginComputePass()
|
|
20
|
+
// pass.setPipeline(pipeline)
|
|
21
|
+
// pass.dispatchWorkgroups(...workgroups)
|
|
22
|
+
// pass.end()
|
|
23
|
+
// device.queue.submit([encoder.finish()])
|
|
24
|
+
// Placeholder: log dispatch for now since full WebGPU pipeline
|
|
25
|
+
// requires device reference not currently exposed through BackendContext
|
|
26
|
+
void shader;
|
|
27
|
+
void workgroups;
|
|
28
|
+
},
|
|
29
|
+
destroy() {
|
|
30
|
+
// Clean up compute pipelines
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=compute-pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compute-pipeline.js","sourceRoot":"","sources":["../src/compute-pipeline.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,UAAU,qBAAqB,CAAC,OAAuB;IAC3D,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC;IAE3C,OAAO;QACL,IAAI,SAAS;YACX,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,QAAQ,CAAC,MAAc,EAAE,UAAoC;YAC3D,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CACb,oDAAoD,OAAO,CAAC,IAAI,KAAK;oBACrE,iEAAiE,CAClE,CAAC;YACJ,CAAC;YAED,qCAAqC;YACrC,qDAAqD;YACrD,gDAAgD;YAChD,0CAA0C;YAC1C,6BAA6B;YAC7B,yCAAyC;YACzC,aAAa;YACb,0CAA0C;YAE1C,+DAA+D;YAC/D,yEAAyE;YACzE,KAAK,MAAM,CAAC;YACZ,KAAK,UAAU,CAAC;QAClB,CAAC;QAED,OAAO;YACL,6BAA6B;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* GPU Acceleration Driver
|
|
3
|
-
* WebGL/WebGPU canvas rendering and shader management
|
|
3
|
+
* Cross-platform WebGL/WebGPU canvas rendering and shader management
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
export interface GPUAccelerationDriverAPI {
|
|
17
|
-
initialize(): Promise<void>;
|
|
18
|
-
loadShader(name: string, program: ShaderProgram): Promise<void>;
|
|
19
|
-
beginFrame(): void;
|
|
20
|
-
endFrame(): void;
|
|
21
|
-
clear(color?: [number, number, number, number]): void;
|
|
22
|
-
drawIndexed(vertexCount: number, indexCount: number): void;
|
|
23
|
-
setShaderProgram(name: string): void;
|
|
24
|
-
setUniform(name: string, value: unknown): void;
|
|
25
|
-
destroy(): Promise<void>;
|
|
26
|
-
}
|
|
5
|
+
export type { BackendContext, BackendType, BufferDescriptor, BufferHandle, BufferManagerAPI, BufferUsage, CompiledShader, ComputePipelineAPI, ContextLossStrategy, Disposable, FrameMetrics, FramebufferDescriptor, FramebufferHandle, GPUAccelerationDriverAPI, GPUAccelerationDriverConfig, GPUResourceHandle, PowerPreference, ProfilerAPI, RenderCommand, RenderQueueAPI, ResourceManagerAPI, ResourceType, ShaderCompilerAPI, ShaderError, ShaderProgram, TextureDescriptor, TextureFormat, TextureHandle, TextureManagerAPI, } from './types.js';
|
|
6
|
+
import type { GPUAccelerationDriverAPI, GPUAccelerationDriverConfig } from './types.js';
|
|
7
|
+
export { createResourceManager } from './resource-manager.js';
|
|
8
|
+
export { createWebGLContext } from './webgl-context.js';
|
|
9
|
+
export { createWebGPUBackend } from './webgpu-backend.js';
|
|
10
|
+
export { createShaderCompiler } from './shader-compiler.js';
|
|
11
|
+
export { createBufferManager } from './buffer-manager.js';
|
|
12
|
+
export { createTextureManager } from './texture-manager.js';
|
|
13
|
+
export { createComputePipeline } from './compute-pipeline.js';
|
|
14
|
+
export { createRenderQueue } from './render-queue.js';
|
|
15
|
+
export { createProfiler } from './profiler.js';
|
|
27
16
|
export declare function createGPUAccelerationDriver(config: GPUAccelerationDriverConfig): GPUAccelerationDriverAPI;
|
|
28
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EACV,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACV,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,wBAAwB,EACxB,2BAA2B,EAC3B,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EASV,wBAAwB,EACxB,2BAA2B,EAS5B,MAAM,YAAY,CAAC;AAapB,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,2BAA2B,GAClC,wBAAwB,CAwR1B"}
|