oidn-webgpu 0.0.0-stage → 0.6.0
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/CHANGELOG.md +182 -0
- package/LICENSE +21 -0
- package/README.md +89 -2
- package/dist/oidn.js +6140 -0
- package/dist/oidn.umd.cjs +1513 -0
- package/lib/UNet.d.ts +161 -0
- package/lib/UNet.js +536 -0
- package/lib/UNet.js.map +1 -0
- package/lib/WGPUComputePass.d.ts +62 -0
- package/lib/WGPUComputePass.js +278 -0
- package/lib/WGPUComputePass.js.map +1 -0
- package/lib/WGPUFullQuadPass.d.ts +50 -0
- package/lib/WGPUFullQuadPass.js +261 -0
- package/lib/WGPUFullQuadPass.js.map +1 -0
- package/lib/backend.d.ts +1 -0
- package/lib/backend.js +39 -0
- package/lib/backend.js.map +1 -0
- package/lib/finalRgbShader.d.ts +13 -0
- package/lib/finalRgbShader.js +160 -0
- package/lib/finalRgbShader.js.map +1 -0
- package/lib/gpuTypes.d.ts +158 -0
- package/lib/gpuTypes.js +27 -0
- package/lib/gpuTypes.js.map +1 -0
- package/lib/graphOptimizer.d.ts +54 -0
- package/lib/graphOptimizer.js +216 -0
- package/lib/graphOptimizer.js.map +1 -0
- package/lib/hdr.d.ts +31 -0
- package/lib/hdr.js +340 -0
- package/lib/hdr.js.map +1 -0
- package/lib/hdrTransfer.d.ts +22 -0
- package/lib/hdrTransfer.js +128 -0
- package/lib/hdrTransfer.js.map +1 -0
- package/lib/main.d.ts +57 -0
- package/lib/main.js +24 -0
- package/lib/main.js.map +1 -0
- package/lib/modelSpec.d.ts +80 -0
- package/lib/modelSpec.js +270 -0
- package/lib/modelSpec.js.map +1 -0
- package/lib/native/denoise.d.ts +25 -0
- package/lib/native/denoise.js +223 -0
- package/lib/native/denoise.js.map +1 -0
- package/lib/native/program.d.ts +53 -0
- package/lib/native/program.js +310 -0
- package/lib/native/program.js.map +1 -0
- package/lib/native/recordingDevice.d.ts +125 -0
- package/lib/native/recordingDevice.js +247 -0
- package/lib/native/recordingDevice.js.map +1 -0
- package/lib/nativeUNet.d.ts +25 -0
- package/lib/nativeUNet.js +184 -0
- package/lib/nativeUNet.js.map +1 -0
- package/lib/nativeUNetCore.d.ts +202 -0
- package/lib/nativeUNetCore.js +2945 -0
- package/lib/nativeUNetCore.js.map +1 -0
- package/lib/process.d.ts +37 -0
- package/lib/process.js +328 -0
- package/lib/process.js.map +1 -0
- package/lib/resourceTracker.d.ts +26 -0
- package/lib/resourceTracker.js +65 -0
- package/lib/resourceTracker.js.map +1 -0
- package/lib/sanitize.d.ts +15 -0
- package/lib/sanitize.js +28 -0
- package/lib/sanitize.js.map +1 -0
- package/lib/tileScheduler.d.ts +61 -0
- package/lib/tileScheduler.js +199 -0
- package/lib/tileScheduler.js.map +1 -0
- package/lib/tza.d.ts +15 -0
- package/lib/tza.js +114 -0
- package/lib/tza.js.map +1 -0
- package/lib/webnnUNet.d.ts +52 -0
- package/lib/webnnUNet.js +535 -0
- package/lib/webnnUNet.js.map +1 -0
- package/package.json +43 -4
- package/src/UNet.ts +861 -0
- package/src/WGPUComputePass.ts +382 -0
- package/src/WGPUFullQuadPass.ts +348 -0
- package/src/backend.ts +42 -0
- package/src/finalRgbShader.ts +186 -0
- package/src/gpuTypes.ts +179 -0
- package/src/graphOptimizer.ts +301 -0
- package/src/hdr.ts +398 -0
- package/src/hdrTransfer.ts +169 -0
- package/src/main.ts +126 -0
- package/src/modelSpec.ts +414 -0
- package/src/native/core-profile.json +40 -0
- package/src/native/denoise.ts +268 -0
- package/src/native/program.ts +326 -0
- package/src/native/recordingDevice.ts +341 -0
- package/src/nativeUNet.ts +269 -0
- package/src/nativeUNetCore.ts +3735 -0
- package/src/process.ts +368 -0
- package/src/resourceTracker.ts +94 -0
- package/src/sanitize.ts +29 -0
- package/src/tileScheduler.ts +330 -0
- package/src/tza.ts +136 -0
- package/src/webnnUNet.ts +812 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { OIDNGPUAdapterInfo, OIDNGPUBindGroup, OIDNGPUBindGroupEntry, OIDNGPUBindGroupLayout, OIDNGPUBuffer, OIDNGPUCommandBuffer, OIDNGPUCommandEncoder, OIDNGPUComputePipeline, OIDNGPUDevice, OIDNGPUFeatures, OIDNGPULimits, OIDNGPUQuerySet, OIDNGPUQueue, OIDNGPUShaderModule } from '../gpuTypes.js';
|
|
2
|
+
/**
|
|
3
|
+
* An OIDNGPUDevice that executes nothing: it records every resource and queue
|
|
4
|
+
* operation so that a native host can create the same resources once and
|
|
5
|
+
* replay the recorded commands with its own GPU API.
|
|
6
|
+
*/
|
|
7
|
+
export declare class RecordedBuffer implements OIDNGPUBuffer {
|
|
8
|
+
readonly id: number;
|
|
9
|
+
readonly size: number;
|
|
10
|
+
readonly usage: number;
|
|
11
|
+
readonly label: string;
|
|
12
|
+
mapState: string;
|
|
13
|
+
data?: Uint8Array;
|
|
14
|
+
destroyed: boolean;
|
|
15
|
+
constructor(id: number, size: number, usage: number, label: string, mapped: boolean);
|
|
16
|
+
getMappedRange(): ArrayBuffer;
|
|
17
|
+
unmap(): void;
|
|
18
|
+
destroy(): void;
|
|
19
|
+
}
|
|
20
|
+
export declare class RecordedShaderModule implements OIDNGPUShaderModule {
|
|
21
|
+
readonly id: number;
|
|
22
|
+
readonly label: string;
|
|
23
|
+
readonly code: string;
|
|
24
|
+
constructor(id: number, label: string, code: string);
|
|
25
|
+
}
|
|
26
|
+
export declare class RecordedBindGroupLayout implements OIDNGPUBindGroupLayout {
|
|
27
|
+
readonly label: string;
|
|
28
|
+
readonly pipeline: number;
|
|
29
|
+
readonly group: number;
|
|
30
|
+
constructor(label: string, pipeline: number, group: number);
|
|
31
|
+
}
|
|
32
|
+
export declare class RecordedPipeline implements OIDNGPUComputePipeline {
|
|
33
|
+
readonly id: number;
|
|
34
|
+
readonly label: string;
|
|
35
|
+
readonly shader: number;
|
|
36
|
+
readonly entryPoint: string;
|
|
37
|
+
constructor(id: number, label: string, shader: number, entryPoint: string);
|
|
38
|
+
getBindGroupLayout(index: number): OIDNGPUBindGroupLayout;
|
|
39
|
+
}
|
|
40
|
+
export interface RecordedBinding {
|
|
41
|
+
binding: number;
|
|
42
|
+
buffer: number;
|
|
43
|
+
offset: number;
|
|
44
|
+
/** Zero binds the rest of the buffer. */
|
|
45
|
+
size: number;
|
|
46
|
+
}
|
|
47
|
+
export declare class RecordedBindGroup implements OIDNGPUBindGroup {
|
|
48
|
+
readonly id: number;
|
|
49
|
+
readonly label: string;
|
|
50
|
+
readonly pipeline: number;
|
|
51
|
+
readonly group: number;
|
|
52
|
+
readonly entries: RecordedBinding[];
|
|
53
|
+
constructor(id: number, label: string, pipeline: number, group: number, entries: RecordedBinding[]);
|
|
54
|
+
}
|
|
55
|
+
export interface RecordedCommand {
|
|
56
|
+
/** 0 = dispatch, 1 = buffer copy. */
|
|
57
|
+
kind: number;
|
|
58
|
+
pipeline: number;
|
|
59
|
+
bindGroup: number;
|
|
60
|
+
x: number;
|
|
61
|
+
y: number;
|
|
62
|
+
z: number;
|
|
63
|
+
source: number;
|
|
64
|
+
sourceOffset: number;
|
|
65
|
+
destination: number;
|
|
66
|
+
destinationOffset: number;
|
|
67
|
+
size: number;
|
|
68
|
+
}
|
|
69
|
+
export declare class RecordedCommandBuffer implements OIDNGPUCommandBuffer {
|
|
70
|
+
readonly label: string;
|
|
71
|
+
readonly commands: RecordedCommand[];
|
|
72
|
+
constructor(label: string, commands: RecordedCommand[]);
|
|
73
|
+
}
|
|
74
|
+
export interface RecordedQueueOperation {
|
|
75
|
+
/** 0 = submit, 1 = buffer write. */
|
|
76
|
+
kind: number;
|
|
77
|
+
commands: RecordedCommand[];
|
|
78
|
+
buffer: number;
|
|
79
|
+
offset: number;
|
|
80
|
+
data?: Uint8Array;
|
|
81
|
+
}
|
|
82
|
+
export interface RecordingDeviceDescriptor {
|
|
83
|
+
features: string[];
|
|
84
|
+
limits: OIDNGPULimits;
|
|
85
|
+
adapterInfo: OIDNGPUAdapterInfo;
|
|
86
|
+
}
|
|
87
|
+
export declare class RecordingDevice implements OIDNGPUDevice {
|
|
88
|
+
readonly features: OIDNGPUFeatures;
|
|
89
|
+
readonly limits: OIDNGPULimits;
|
|
90
|
+
readonly adapterInfo: OIDNGPUAdapterInfo;
|
|
91
|
+
readonly queue: OIDNGPUQueue;
|
|
92
|
+
readonly buffers: RecordedBuffer[];
|
|
93
|
+
readonly shaders: RecordedShaderModule[];
|
|
94
|
+
readonly pipelines: RecordedPipeline[];
|
|
95
|
+
readonly bindGroups: RecordedBindGroup[];
|
|
96
|
+
operations: RecordedQueueOperation[];
|
|
97
|
+
constructor(descriptor: RecordingDeviceDescriptor);
|
|
98
|
+
createBuffer(descriptor: {
|
|
99
|
+
label?: string;
|
|
100
|
+
size: number;
|
|
101
|
+
usage: number;
|
|
102
|
+
mappedAtCreation?: boolean;
|
|
103
|
+
}): OIDNGPUBuffer;
|
|
104
|
+
createShaderModule(descriptor: {
|
|
105
|
+
label?: string;
|
|
106
|
+
code: string;
|
|
107
|
+
}): OIDNGPUShaderModule;
|
|
108
|
+
createComputePipeline(descriptor: {
|
|
109
|
+
label?: string;
|
|
110
|
+
layout: 'auto';
|
|
111
|
+
compute: {
|
|
112
|
+
module: OIDNGPUShaderModule;
|
|
113
|
+
entryPoint: string;
|
|
114
|
+
};
|
|
115
|
+
}): OIDNGPUComputePipeline;
|
|
116
|
+
createBindGroup(descriptor: {
|
|
117
|
+
label?: string;
|
|
118
|
+
layout: OIDNGPUBindGroupLayout;
|
|
119
|
+
entries: OIDNGPUBindGroupEntry[];
|
|
120
|
+
}): OIDNGPUBindGroup;
|
|
121
|
+
createCommandEncoder(descriptor?: {
|
|
122
|
+
label?: string;
|
|
123
|
+
}): OIDNGPUCommandEncoder;
|
|
124
|
+
createQuerySet(): OIDNGPUQuerySet;
|
|
125
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An OIDNGPUDevice that executes nothing: it records every resource and queue
|
|
3
|
+
* operation so that a native host can create the same resources once and
|
|
4
|
+
* replay the recorded commands with its own GPU API.
|
|
5
|
+
*/
|
|
6
|
+
export class RecordedBuffer {
|
|
7
|
+
id;
|
|
8
|
+
size;
|
|
9
|
+
usage;
|
|
10
|
+
label;
|
|
11
|
+
mapState = 'unmapped';
|
|
12
|
+
data;
|
|
13
|
+
destroyed = false;
|
|
14
|
+
constructor(id, size, usage, label, mapped) {
|
|
15
|
+
this.id = id;
|
|
16
|
+
this.size = size;
|
|
17
|
+
this.usage = usage;
|
|
18
|
+
this.label = label;
|
|
19
|
+
if (mapped) {
|
|
20
|
+
this.data = new Uint8Array(size);
|
|
21
|
+
this.mapState = 'mapped';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
getMappedRange() {
|
|
25
|
+
if (!this.data)
|
|
26
|
+
throw new Error(`Recorded buffer ${this.label} is not mapped`);
|
|
27
|
+
return this.data.buffer;
|
|
28
|
+
}
|
|
29
|
+
unmap() {
|
|
30
|
+
this.mapState = 'unmapped';
|
|
31
|
+
}
|
|
32
|
+
destroy() {
|
|
33
|
+
this.destroyed = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export class RecordedShaderModule {
|
|
37
|
+
id;
|
|
38
|
+
label;
|
|
39
|
+
code;
|
|
40
|
+
constructor(id, label, code) {
|
|
41
|
+
this.id = id;
|
|
42
|
+
this.label = label;
|
|
43
|
+
this.code = code;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class RecordedBindGroupLayout {
|
|
47
|
+
label;
|
|
48
|
+
pipeline;
|
|
49
|
+
group;
|
|
50
|
+
constructor(label, pipeline, group) {
|
|
51
|
+
this.label = label;
|
|
52
|
+
this.pipeline = pipeline;
|
|
53
|
+
this.group = group;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class RecordedPipeline {
|
|
57
|
+
id;
|
|
58
|
+
label;
|
|
59
|
+
shader;
|
|
60
|
+
entryPoint;
|
|
61
|
+
constructor(id, label, shader, entryPoint) {
|
|
62
|
+
this.id = id;
|
|
63
|
+
this.label = label;
|
|
64
|
+
this.shader = shader;
|
|
65
|
+
this.entryPoint = entryPoint;
|
|
66
|
+
}
|
|
67
|
+
getBindGroupLayout(index) {
|
|
68
|
+
return new RecordedBindGroupLayout(this.label, this.id, index);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export class RecordedBindGroup {
|
|
72
|
+
id;
|
|
73
|
+
label;
|
|
74
|
+
pipeline;
|
|
75
|
+
group;
|
|
76
|
+
entries;
|
|
77
|
+
constructor(id, label, pipeline, group, entries) {
|
|
78
|
+
this.id = id;
|
|
79
|
+
this.label = label;
|
|
80
|
+
this.pipeline = pipeline;
|
|
81
|
+
this.group = group;
|
|
82
|
+
this.entries = entries;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export class RecordedCommandBuffer {
|
|
86
|
+
label;
|
|
87
|
+
commands;
|
|
88
|
+
constructor(label, commands) {
|
|
89
|
+
this.label = label;
|
|
90
|
+
this.commands = commands;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function command(kind) {
|
|
94
|
+
return {
|
|
95
|
+
kind,
|
|
96
|
+
pipeline: -1,
|
|
97
|
+
bindGroup: -1,
|
|
98
|
+
x: 0,
|
|
99
|
+
y: 0,
|
|
100
|
+
z: 0,
|
|
101
|
+
source: -1,
|
|
102
|
+
sourceOffset: 0,
|
|
103
|
+
destination: -1,
|
|
104
|
+
destinationOffset: 0,
|
|
105
|
+
size: 0
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
class RecordingPass {
|
|
109
|
+
_commands;
|
|
110
|
+
_pipeline = -1;
|
|
111
|
+
_bindGroup = -1;
|
|
112
|
+
constructor(_commands) {
|
|
113
|
+
this._commands = _commands;
|
|
114
|
+
}
|
|
115
|
+
setPipeline(pipeline) {
|
|
116
|
+
this._pipeline = pipeline.id;
|
|
117
|
+
}
|
|
118
|
+
setBindGroup(index, bindGroup) {
|
|
119
|
+
if (index !== 0)
|
|
120
|
+
throw new Error('Recorded passes support bind group 0 only');
|
|
121
|
+
this._bindGroup = bindGroup.id;
|
|
122
|
+
}
|
|
123
|
+
dispatchWorkgroups(x, y, z) {
|
|
124
|
+
const recorded = command(0);
|
|
125
|
+
recorded.pipeline = this._pipeline;
|
|
126
|
+
recorded.bindGroup = this._bindGroup;
|
|
127
|
+
recorded.x = x;
|
|
128
|
+
recorded.y = y ?? 1;
|
|
129
|
+
recorded.z = z ?? 1;
|
|
130
|
+
this._commands.push(recorded);
|
|
131
|
+
}
|
|
132
|
+
end() { }
|
|
133
|
+
}
|
|
134
|
+
class RecordingEncoder {
|
|
135
|
+
_label;
|
|
136
|
+
_commands = [];
|
|
137
|
+
constructor(_label) {
|
|
138
|
+
this._label = _label;
|
|
139
|
+
}
|
|
140
|
+
beginComputePass() {
|
|
141
|
+
return new RecordingPass(this._commands);
|
|
142
|
+
}
|
|
143
|
+
copyBufferToBuffer(source, sourceOffset, destination, destinationOffset, size) {
|
|
144
|
+
const recorded = command(1);
|
|
145
|
+
recorded.source = source.id;
|
|
146
|
+
recorded.sourceOffset = sourceOffset;
|
|
147
|
+
recorded.destination = destination.id;
|
|
148
|
+
recorded.destinationOffset = destinationOffset;
|
|
149
|
+
recorded.size = size;
|
|
150
|
+
this._commands.push(recorded);
|
|
151
|
+
}
|
|
152
|
+
resolveQuerySet() {
|
|
153
|
+
throw new Error('Recorded devices do not support timestamp queries');
|
|
154
|
+
}
|
|
155
|
+
finish() {
|
|
156
|
+
return new RecordedCommandBuffer(this._label, this._commands);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
class RecordingQueue {
|
|
160
|
+
_device;
|
|
161
|
+
constructor(_device) {
|
|
162
|
+
this._device = _device;
|
|
163
|
+
}
|
|
164
|
+
submit(commandBuffers) {
|
|
165
|
+
const commands = [];
|
|
166
|
+
for (const commandBuffer of commandBuffers) {
|
|
167
|
+
for (const recorded of commandBuffer.commands) {
|
|
168
|
+
commands.push(recorded);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
this._device.operations.push({ kind: 0, commands, buffer: -1, offset: 0 });
|
|
172
|
+
}
|
|
173
|
+
writeBuffer(buffer, bufferOffset, data) {
|
|
174
|
+
const bytes = new Uint8Array(data.byteLength);
|
|
175
|
+
bytes.set(data);
|
|
176
|
+
this._device.operations.push({
|
|
177
|
+
kind: 1,
|
|
178
|
+
commands: [],
|
|
179
|
+
buffer: buffer.id,
|
|
180
|
+
offset: bufferOffset,
|
|
181
|
+
data: bytes
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
class RecordedFeatures {
|
|
186
|
+
_names;
|
|
187
|
+
constructor(_names) {
|
|
188
|
+
this._names = _names;
|
|
189
|
+
}
|
|
190
|
+
has(name) {
|
|
191
|
+
return this._names.includes(name);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
class RecordedQuerySet {
|
|
195
|
+
destroy() { }
|
|
196
|
+
}
|
|
197
|
+
export class RecordingDevice {
|
|
198
|
+
features;
|
|
199
|
+
limits;
|
|
200
|
+
adapterInfo;
|
|
201
|
+
queue;
|
|
202
|
+
buffers = [];
|
|
203
|
+
shaders = [];
|
|
204
|
+
pipelines = [];
|
|
205
|
+
bindGroups = [];
|
|
206
|
+
operations = [];
|
|
207
|
+
constructor(descriptor) {
|
|
208
|
+
this.features = new RecordedFeatures(descriptor.features);
|
|
209
|
+
this.limits = descriptor.limits;
|
|
210
|
+
this.adapterInfo = descriptor.adapterInfo;
|
|
211
|
+
this.queue = new RecordingQueue(this);
|
|
212
|
+
}
|
|
213
|
+
createBuffer(descriptor) {
|
|
214
|
+
const buffer = new RecordedBuffer(this.buffers.length, descriptor.size, descriptor.usage, descriptor.label ?? '', descriptor.mappedAtCreation === true);
|
|
215
|
+
this.buffers.push(buffer);
|
|
216
|
+
return buffer;
|
|
217
|
+
}
|
|
218
|
+
createShaderModule(descriptor) {
|
|
219
|
+
const module = new RecordedShaderModule(this.shaders.length, descriptor.label ?? '', descriptor.code);
|
|
220
|
+
this.shaders.push(module);
|
|
221
|
+
return module;
|
|
222
|
+
}
|
|
223
|
+
createComputePipeline(descriptor) {
|
|
224
|
+
const pipeline = new RecordedPipeline(this.pipelines.length, descriptor.label ?? '', descriptor.compute.module.id, descriptor.compute.entryPoint);
|
|
225
|
+
this.pipelines.push(pipeline);
|
|
226
|
+
return pipeline;
|
|
227
|
+
}
|
|
228
|
+
createBindGroup(descriptor) {
|
|
229
|
+
const layout = descriptor.layout;
|
|
230
|
+
const entries = descriptor.entries.map((entry) => ({
|
|
231
|
+
binding: entry.binding,
|
|
232
|
+
buffer: entry.resource.buffer.id,
|
|
233
|
+
offset: entry.resource.offset ?? 0,
|
|
234
|
+
size: entry.resource.size ?? 0
|
|
235
|
+
}));
|
|
236
|
+
const bindGroup = new RecordedBindGroup(this.bindGroups.length, descriptor.label ?? '', layout.pipeline, layout.group, entries);
|
|
237
|
+
this.bindGroups.push(bindGroup);
|
|
238
|
+
return bindGroup;
|
|
239
|
+
}
|
|
240
|
+
createCommandEncoder(descriptor) {
|
|
241
|
+
return new RecordingEncoder(descriptor?.label ?? '');
|
|
242
|
+
}
|
|
243
|
+
createQuerySet() {
|
|
244
|
+
return new RecordedQuerySet();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=recordingDevice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recordingDevice.js","sourceRoot":"","sources":["../../src/native/recordingDevice.ts"],"names":[],"mappings":"AAkBA;;;;GAIG;AAEH,MAAM,OAAO,cAAc;IAMd;IACA;IACA;IACA;IARX,QAAQ,GAAG,UAAU,CAAC;IACtB,IAAI,CAAc;IAClB,SAAS,GAAG,KAAK,CAAC;IAElB,YACW,EAAU,EACV,IAAY,EACZ,KAAa,EACb,KAAa,EACtB,MAAe;QAJN,OAAE,GAAF,EAAE,CAAQ;QACV,SAAI,GAAJ,IAAI,CAA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AC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type OIDNGPUBuffer, type OIDNGPUQuerySet } from './gpuTypes.js';
|
|
2
|
+
import type { ValidatedUNetModel } from './modelSpec';
|
|
3
|
+
import { NativeUNetCore, type CachedExecution, type NativeSubgroupMatrixConfig, type NativeUNetExecutionProfile, type NativeUNetOptions, type NativeUNetPrecision, type NativeUNetPrecisionSetting } from './nativeUNetCore.js';
|
|
4
|
+
export * from './nativeUNetCore.js';
|
|
5
|
+
export declare function resolveNativeUNetPrecision(device: GPUDevice, requested?: NativeUNetPrecisionSetting): NativeUNetPrecision;
|
|
6
|
+
export declare function selectSubgroupMatrixConfig(device: GPUDevice, accumulation?: 'f32' | 'f16'): NativeSubgroupMatrixConfig | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Native, model-driven OIDN U-Net executor for browser WebGPU devices. The
|
|
9
|
+
* device must also provide the asynchronous WebGPU operations.
|
|
10
|
+
*/
|
|
11
|
+
export declare class NativeUNetExecutor extends NativeUNetCore {
|
|
12
|
+
private _lastExecutionProfile?;
|
|
13
|
+
constructor(device: GPUDevice, model: ValidatedUNetModel, options?: NativeUNetOptions);
|
|
14
|
+
execute(inputBuffers: readonly GPUBuffer[], width: number, height: number): GPUBuffer;
|
|
15
|
+
private get _asyncDevice();
|
|
16
|
+
private get _pipelinePromises();
|
|
17
|
+
getLastExecutionProfile(): Promise<NativeUNetExecutionProfile> | undefined;
|
|
18
|
+
private _pipelineAsync;
|
|
19
|
+
protected _retireExecution(execution: CachedExecution): void;
|
|
20
|
+
/** Compiles all shape-independent kernels before the model reports ready. */
|
|
21
|
+
prepare(): Promise<void>;
|
|
22
|
+
protected _readProfile(querySet: OIDNGPUQuerySet, resolveBuffer: OIDNGPUBuffer, readbackBuffer: OIDNGPUBuffer, labels: string[]): void;
|
|
23
|
+
/** Executes interleaved CPU image data through the native GPU runtime. */
|
|
24
|
+
executeCPU(interleavedInput: Float32Array, width: number, height: number): Promise<Float32Array>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { optimizeModelGraph } from './graphOptimizer.js';
|
|
2
|
+
import { BufferUsage, MapMode } from './gpuTypes.js';
|
|
3
|
+
import { createInputPackShader, NativeUNetCore, resolveNativeUNetPrecision as resolveCorePrecision, selectSubgroupMatrixConfig as selectCoreSubgroupMatrixConfig } from './nativeUNetCore.js';
|
|
4
|
+
// The browser declarations below shadow the core's OIDNGPUDevice signatures.
|
|
5
|
+
export * from './nativeUNetCore.js';
|
|
6
|
+
// A GPUDevice provides every OIDNGPUAsyncDevice operation at runtime, but its
|
|
7
|
+
// branded WebGPU types (GPUBindGroup, Iterable<GPUCommandBuffer>) are not
|
|
8
|
+
// structurally assignable, so the browser API converts at this boundary.
|
|
9
|
+
function asOIDNDevice(device) {
|
|
10
|
+
return device;
|
|
11
|
+
}
|
|
12
|
+
export function resolveNativeUNetPrecision(device, requested) {
|
|
13
|
+
return resolveCorePrecision(asOIDNDevice(device), requested);
|
|
14
|
+
}
|
|
15
|
+
export function selectSubgroupMatrixConfig(device, accumulation) {
|
|
16
|
+
return selectCoreSubgroupMatrixConfig(asOIDNDevice(device), accumulation);
|
|
17
|
+
}
|
|
18
|
+
const pendingPipelinesByDevice = new WeakMap();
|
|
19
|
+
/**
|
|
20
|
+
* Native, model-driven OIDN U-Net executor for browser WebGPU devices. The
|
|
21
|
+
* device must also provide the asynchronous WebGPU operations.
|
|
22
|
+
*/
|
|
23
|
+
export class NativeUNetExecutor extends NativeUNetCore {
|
|
24
|
+
_lastExecutionProfile;
|
|
25
|
+
constructor(device, model, options) {
|
|
26
|
+
super(asOIDNDevice(device), model, options);
|
|
27
|
+
}
|
|
28
|
+
// Inputs and outputs are buffers of the browser device, so they are GPUBuffers.
|
|
29
|
+
execute(inputBuffers, width, height) {
|
|
30
|
+
return super.execute(inputBuffers, width, height);
|
|
31
|
+
}
|
|
32
|
+
get _asyncDevice() {
|
|
33
|
+
return this._device;
|
|
34
|
+
}
|
|
35
|
+
get _pipelinePromises() {
|
|
36
|
+
let pending = pendingPipelinesByDevice.get(this._device);
|
|
37
|
+
if (!pending) {
|
|
38
|
+
pending = new Map();
|
|
39
|
+
pendingPipelinesByDevice.set(this._device, pending);
|
|
40
|
+
}
|
|
41
|
+
return pending;
|
|
42
|
+
}
|
|
43
|
+
getLastExecutionProfile() {
|
|
44
|
+
return this._lastExecutionProfile;
|
|
45
|
+
}
|
|
46
|
+
_pipelineAsync(key, code) {
|
|
47
|
+
const ready = this._pipelineCache.get(key);
|
|
48
|
+
if (ready)
|
|
49
|
+
return Promise.resolve(ready);
|
|
50
|
+
const pending = this._pipelinePromises.get(key);
|
|
51
|
+
if (pending)
|
|
52
|
+
return pending;
|
|
53
|
+
const promise = this._asyncDevice.createComputePipelineAsync({
|
|
54
|
+
label: `oidn/${key}`,
|
|
55
|
+
layout: 'auto',
|
|
56
|
+
compute: {
|
|
57
|
+
module: this._device.createShaderModule({
|
|
58
|
+
label: `oidn/${key}`,
|
|
59
|
+
code
|
|
60
|
+
}),
|
|
61
|
+
entryPoint: 'main'
|
|
62
|
+
}
|
|
63
|
+
}).then((pipeline) => {
|
|
64
|
+
this._pipelineCache.set(key, pipeline);
|
|
65
|
+
this._pipelinePromises.delete(key);
|
|
66
|
+
return pipeline;
|
|
67
|
+
}, (error) => {
|
|
68
|
+
this._pipelinePromises.delete(key);
|
|
69
|
+
throw error;
|
|
70
|
+
});
|
|
71
|
+
this._pipelinePromises.set(key, promise);
|
|
72
|
+
return promise;
|
|
73
|
+
}
|
|
74
|
+
_retireExecution(execution) {
|
|
75
|
+
// Commands using an evicted plan may still be submitted. Defer actual
|
|
76
|
+
// destruction until all work currently on the shared queue completes.
|
|
77
|
+
this._retiredExecutions.add(execution);
|
|
78
|
+
void this._asyncDevice.queue.onSubmittedWorkDone()
|
|
79
|
+
.catch(() => undefined)
|
|
80
|
+
.then(() => {
|
|
81
|
+
this._retiredExecutions.delete(execution);
|
|
82
|
+
this._destroyExecution(execution);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/** Compiles all shape-independent kernels before the model reports ready. */
|
|
86
|
+
async prepare() {
|
|
87
|
+
if (this._disposed)
|
|
88
|
+
throw new Error('Native OIDN executor is disposed');
|
|
89
|
+
const graph = optimizeModelGraph(this._model, { fuseConvPool: false });
|
|
90
|
+
const sourceCount = this._model.inputChannels / 3;
|
|
91
|
+
const specs = [
|
|
92
|
+
{
|
|
93
|
+
key: `pack/${this.precision}/${sourceCount}`,
|
|
94
|
+
code: createInputPackShader(this.precision, sourceCount)
|
|
95
|
+
},
|
|
96
|
+
...graph.nodes.map((node) => this._nodePipelineSpec(node, node.id === graph.spec.output))
|
|
97
|
+
];
|
|
98
|
+
await Promise.all(specs.map(({ key, code }) => this._pipelineAsync(key, code)));
|
|
99
|
+
}
|
|
100
|
+
_readProfile(querySet, resolveBuffer, readbackBuffer, labels) {
|
|
101
|
+
this._lastExecutionProfile = (async () => {
|
|
102
|
+
try {
|
|
103
|
+
await readbackBuffer.mapAsync(MapMode.READ);
|
|
104
|
+
// Little-endian u64 nanoseconds as u32 pairs; differences stay exact.
|
|
105
|
+
const words = new Uint32Array(readbackBuffer.getMappedRange());
|
|
106
|
+
const timestamp = (query) => words[query * 2 + 1] * 4294967296 + words[query * 2];
|
|
107
|
+
const layers = labels.map((id, index) => ({
|
|
108
|
+
id,
|
|
109
|
+
durationMs: (timestamp(index * 2 + 1) - timestamp(index * 2)) / 1_000_000
|
|
110
|
+
}));
|
|
111
|
+
return {
|
|
112
|
+
totalMs: layers.reduce((sum, layer) => sum + layer.durationMs, 0),
|
|
113
|
+
layers
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
if (readbackBuffer.mapState === 'mapped') {
|
|
118
|
+
readbackBuffer.unmap();
|
|
119
|
+
}
|
|
120
|
+
this._releaseQuerySet(querySet);
|
|
121
|
+
this._releaseBuffer(resolveBuffer);
|
|
122
|
+
this._releaseBuffer(readbackBuffer);
|
|
123
|
+
this._profileOperations--;
|
|
124
|
+
}
|
|
125
|
+
})();
|
|
126
|
+
}
|
|
127
|
+
/** Executes interleaved CPU image data through the native GPU runtime. */
|
|
128
|
+
async executeCPU(interleavedInput, width, height) {
|
|
129
|
+
const expectedLength = width * height * this._model.inputChannels;
|
|
130
|
+
if (interleavedInput.length !== expectedLength) {
|
|
131
|
+
throw new Error(`Native OIDN CPU input has ${interleavedInput.length} values, expected ${expectedLength}`);
|
|
132
|
+
}
|
|
133
|
+
const execution = this._execution(width, height);
|
|
134
|
+
const sourceCount = this._model.inputChannels / 3;
|
|
135
|
+
const pixelCount = width * height;
|
|
136
|
+
if (!execution.cpuInputBuffers) {
|
|
137
|
+
execution.cpuInputBuffers = Array.from({ length: sourceCount }, (_, index) => {
|
|
138
|
+
const buffer = this._device.createBuffer({
|
|
139
|
+
label: `oidn/cpu-input/${width}x${height}/${index}`,
|
|
140
|
+
size: pixelCount * 16,
|
|
141
|
+
usage: BufferUsage.STORAGE | BufferUsage.COPY_DST
|
|
142
|
+
});
|
|
143
|
+
this._resources.track('gpu-buffer', buffer);
|
|
144
|
+
execution.ownedBuffers.push(buffer);
|
|
145
|
+
return buffer;
|
|
146
|
+
});
|
|
147
|
+
execution.cpuReadbackBuffer = this._device.createBuffer({
|
|
148
|
+
label: `oidn/cpu-readback/${width}x${height}`,
|
|
149
|
+
size: pixelCount * 16,
|
|
150
|
+
usage: BufferUsage.COPY_DST | BufferUsage.MAP_READ
|
|
151
|
+
});
|
|
152
|
+
this._resources.track('gpu-buffer', execution.cpuReadbackBuffer);
|
|
153
|
+
execution.ownedBuffers.push(execution.cpuReadbackBuffer);
|
|
154
|
+
}
|
|
155
|
+
for (let source = 0; source < sourceCount; source++) {
|
|
156
|
+
const upload = new Float32Array(pixelCount * 4);
|
|
157
|
+
for (let pixel = 0; pixel < pixelCount; pixel++) {
|
|
158
|
+
const inputOffset = pixel * this._model.inputChannels + source * 3;
|
|
159
|
+
const outputOffset = pixel * 4;
|
|
160
|
+
upload[outputOffset] = interleavedInput[inputOffset];
|
|
161
|
+
upload[outputOffset + 1] = interleavedInput[inputOffset + 1];
|
|
162
|
+
upload[outputOffset + 2] = interleavedInput[inputOffset + 2];
|
|
163
|
+
}
|
|
164
|
+
this._device.queue.writeBuffer(execution.cpuInputBuffers[source], 0, new Uint8Array(upload.buffer, upload.byteOffset, upload.byteLength));
|
|
165
|
+
}
|
|
166
|
+
const output = super.execute(execution.cpuInputBuffers, width, height);
|
|
167
|
+
const encoder = this._device.createCommandEncoder({
|
|
168
|
+
label: `oidn/cpu-readback/${width}x${height}`
|
|
169
|
+
});
|
|
170
|
+
encoder.copyBufferToBuffer(output, 0, execution.cpuReadbackBuffer, 0, pixelCount * 16);
|
|
171
|
+
this._device.queue.submit([encoder.finish()]);
|
|
172
|
+
await execution.cpuReadbackBuffer.mapAsync(MapMode.READ);
|
|
173
|
+
const rgba = new Float32Array(execution.cpuReadbackBuffer.getMappedRange());
|
|
174
|
+
const rgb = new Float32Array(pixelCount * 3);
|
|
175
|
+
for (let pixel = 0; pixel < pixelCount; pixel++) {
|
|
176
|
+
rgb[pixel * 3] = rgba[pixel * 4];
|
|
177
|
+
rgb[pixel * 3 + 1] = rgba[pixel * 4 + 1];
|
|
178
|
+
rgb[pixel * 3 + 2] = rgba[pixel * 4 + 2];
|
|
179
|
+
}
|
|
180
|
+
execution.cpuReadbackBuffer.unmap();
|
|
181
|
+
return rgb;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=nativeUNet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeUNet.js","sourceRoot":"","sources":["../src/nativeUNet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EACL,WAAW,EACX,OAAO,EAOR,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,qBAAqB,EACrB,cAAc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