akarisub 0.2.0 → 0.2.2

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.
Files changed (46) hide show
  1. package/LICENSE +3 -0
  2. package/README.md +56 -54
  3. package/THIRD_PARTY_NOTICES.md +1590 -0
  4. package/dist/COPYRIGHT +1588 -949
  5. package/dist/akarisub-worker.js +2 -2
  6. package/dist/akarisub-worker.wasm +0 -0
  7. package/dist/akarisub.umd.js +3 -3
  8. package/dist/index.js +3 -3
  9. package/dist/ts/index.d.ts +14 -0
  10. package/dist/ts/index.d.ts.map +1 -0
  11. package/dist/ts/index.js +17 -0
  12. package/dist/ts/index.js.map +1 -0
  13. package/dist/ts/ts/akarisub.d.ts +225 -0
  14. package/dist/ts/ts/akarisub.d.ts.map +1 -0
  15. package/dist/ts/ts/akarisub.js +1073 -0
  16. package/dist/ts/ts/akarisub.js.map +1 -0
  17. package/dist/ts/ts/types.d.ts +424 -0
  18. package/dist/ts/ts/types.d.ts.map +1 -0
  19. package/dist/ts/ts/types.js +5 -0
  20. package/dist/ts/ts/types.js.map +1 -0
  21. package/dist/ts/ts/utils.d.ts +78 -0
  22. package/dist/ts/ts/utils.d.ts.map +1 -0
  23. package/dist/ts/ts/utils.js +395 -0
  24. package/dist/ts/ts/utils.js.map +1 -0
  25. package/dist/ts/ts/webgl2-renderer.d.ts +52 -0
  26. package/dist/ts/ts/webgl2-renderer.d.ts.map +1 -0
  27. package/dist/ts/ts/webgl2-renderer.js +391 -0
  28. package/dist/ts/ts/webgl2-renderer.js.map +1 -0
  29. package/dist/ts/ts/webgpu-renderer.d.ts +62 -0
  30. package/dist/ts/ts/webgpu-renderer.d.ts.map +1 -0
  31. package/dist/ts/ts/webgpu-renderer.js +577 -0
  32. package/dist/ts/ts/webgpu-renderer.js.map +1 -0
  33. package/dist/ts/ts/worker.d.ts +6 -0
  34. package/dist/ts/ts/worker.d.ts.map +1 -0
  35. package/dist/ts/ts/worker.js +1762 -0
  36. package/dist/ts/ts/worker.js.map +1 -0
  37. package/dist/ts/wrapper.d.ts +8 -0
  38. package/dist/ts/wrapper.d.ts.map +1 -0
  39. package/dist/ts/wrapper.js +9 -0
  40. package/dist/ts/wrapper.js.map +1 -0
  41. package/package.json +9 -6
  42. package/src/ts/akarisub.ts +48 -12
  43. package/src/ts/types.ts +22 -7
  44. package/src/ts/webgl2-renderer.ts +19 -13
  45. package/src/ts/webgpu-renderer.ts +26 -71
  46. package/src/ts/worker.ts +303 -70
@@ -0,0 +1,577 @@
1
+ /// <reference types="@webgpu/types" />
2
+ // Maximum images per batch
3
+ const MAX_IMAGES_PER_BATCH = 256;
4
+ // WebGPU max texture array layers
5
+ const MAX_TEXTURE_ARRAY_LAYERS = 256;
6
+ // WGSL Vertex Shader
7
+ const VERTEX_SHADER = /* wgsl */ `
8
+ struct VertexOutput {
9
+ @builtin(position) position: vec4f,
10
+ @location(0) @interpolate(flat) instanceIndex: u32,
11
+ @location(1) @interpolate(flat) destXY: vec2f,
12
+ @location(2) @interpolate(flat) texSize: vec2f,
13
+ }
14
+
15
+ struct Uniforms {
16
+ resolution: vec2f,
17
+ }
18
+
19
+ struct ImageData {
20
+ destRect: vec4f, // x, y, w, h
21
+ texInfo: vec4f, // texW, texH, texIndex, 0
22
+ }
23
+
24
+ @group(0) @binding(0) var<uniform> uniforms: Uniforms;
25
+ @group(0) @binding(1) var<storage, read> imageData: array<ImageData>;
26
+
27
+ // Quad vertices (two triangles)
28
+ const QUAD_POSITIONS = array<vec2f, 6>(
29
+ vec2f(0.0, 0.0),
30
+ vec2f(1.0, 0.0),
31
+ vec2f(0.0, 1.0),
32
+ vec2f(1.0, 0.0),
33
+ vec2f(1.0, 1.0),
34
+ vec2f(0.0, 1.0)
35
+ );
36
+
37
+ @vertex
38
+ fn vertexMain(
39
+ @builtin(vertex_index) vertexIndex: u32,
40
+ @builtin(instance_index) instanceIndex: u32
41
+ ) -> VertexOutput {
42
+ var output: VertexOutput;
43
+
44
+ let data = imageData[instanceIndex];
45
+ let quadPos = QUAD_POSITIONS[vertexIndex];
46
+ let wh = data.destRect.zw;
47
+
48
+ // Calculate pixel position
49
+ let pixelPos = data.destRect.xy + quadPos * wh;
50
+
51
+ // Convert to clip space (-1 to 1)
52
+ var clipPos = (pixelPos / uniforms.resolution) * 2.0 - 1.0;
53
+ clipPos.y = -clipPos.y;
54
+
55
+ output.position = vec4f(clipPos, 0.0, 1.0);
56
+ output.instanceIndex = instanceIndex;
57
+ output.destXY = data.destRect.xy;
58
+ output.texSize = data.texInfo.xy;
59
+
60
+ return output;
61
+ }
62
+ `;
63
+ // WGSL Fragment Shader
64
+ const FRAGMENT_SHADER = /* wgsl */ `
65
+ @group(0) @binding(2) var texArray: texture_2d_array<f32>;
66
+
67
+ struct ImageData {
68
+ destRect: vec4f,
69
+ texInfo: vec4f,
70
+ }
71
+
72
+ @group(0) @binding(1) var<storage, read> imageData: array<ImageData>;
73
+
74
+ struct FragmentInput {
75
+ @builtin(position) fragCoord: vec4f,
76
+ @location(0) @interpolate(flat) instanceIndex: u32,
77
+ @location(1) @interpolate(flat) destXY: vec2f,
78
+ @location(2) @interpolate(flat) texSize: vec2f,
79
+ }
80
+
81
+ @fragment
82
+ fn fragmentMain(input: FragmentInput) -> @location(0) vec4f {
83
+ let data = imageData[input.instanceIndex];
84
+ let texIndex = u32(data.texInfo.z);
85
+
86
+ // Calculate texel coordinates
87
+ let texCoordF = floor(input.fragCoord.xy - input.destXY);
88
+ let texCoord = vec2i(texCoordF);
89
+
90
+ // Bounds check
91
+ let texSizeI = vec2i(input.texSize);
92
+ if (texCoord.x < 0 || texCoord.y < 0 || texCoord.x >= texSizeI.x || texCoord.y >= texSizeI.y) {
93
+ discard;
94
+ }
95
+
96
+ // Load from texture array
97
+ let color = textureLoad(texArray, texCoord, texIndex, 0);
98
+
99
+ // Premultiplied alpha output
100
+ return vec4f(color.rgb * color.a, color.a);
101
+ }
102
+ `;
103
+ /**
104
+ * Check if WebGPU is supported in the current browser.
105
+ */
106
+ export function isWebGPUSupported() {
107
+ return typeof navigator !== 'undefined' && 'gpu' in navigator;
108
+ }
109
+ function toUint8View(data) {
110
+ if (data instanceof ArrayBuffer) {
111
+ return new Uint8Array(data);
112
+ }
113
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
114
+ }
115
+ /**
116
+ * High-performance WebGPU subtitle renderer for AkariSub.
117
+ */
118
+ export class WebGPURenderer {
119
+ device = null;
120
+ context = null;
121
+ pipeline = null;
122
+ bindGroupLayout = null;
123
+ uniformBuffer = null;
124
+ imageDataBuffer = null;
125
+ // Texture array for batched rendering
126
+ textureArray = null;
127
+ textureArrayView = null;
128
+ textureArraySize = 0;
129
+ textureArrayWidth = 0;
130
+ textureArrayHeight = 0;
131
+ pendingDestroyTextures = [];
132
+ // Pre-allocated typed arrays (reused every frame - ZERO allocations in hot path)
133
+ imageDataArray;
134
+ resolutionArray = new Float32Array(2);
135
+ // Bind group (recreated only when texture array changes)
136
+ bindGroup = null;
137
+ bindGroupDirty = true;
138
+ // Track canvas size to avoid redundant updates
139
+ lastCanvasWidth = 0;
140
+ lastCanvasHeight = 0;
141
+ format = 'bgra8unorm';
142
+ _canvas = null;
143
+ _initPromise = null;
144
+ _initialized = false;
145
+ constructor() {
146
+ // Pre-allocate buffer for max images (8 floats per image: destRect + texInfo)
147
+ this.imageDataArray = new Float32Array(MAX_IMAGES_PER_BATCH * 8);
148
+ }
149
+ async init() {
150
+ if (this._initPromise)
151
+ return this._initPromise;
152
+ this._initPromise = this._initDevice();
153
+ return this._initPromise;
154
+ }
155
+ async _initDevice() {
156
+ if (!navigator.gpu) {
157
+ throw new Error('WebGPU not supported');
158
+ }
159
+ const adapter = await navigator.gpu.requestAdapter({
160
+ powerPreference: 'high-performance'
161
+ });
162
+ if (!adapter) {
163
+ throw new Error('No WebGPU adapter found');
164
+ }
165
+ this.device = await adapter.requestDevice();
166
+ this.format = navigator.gpu.getPreferredCanvasFormat();
167
+ const vertexModule = this.device.createShaderModule({ code: VERTEX_SHADER });
168
+ const fragmentModule = this.device.createShaderModule({ code: FRAGMENT_SHADER });
169
+ this.uniformBuffer = this.device.createBuffer({
170
+ size: 16,
171
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
172
+ });
173
+ // Large storage buffer for all image data
174
+ this.imageDataBuffer = this.device.createBuffer({
175
+ size: MAX_IMAGES_PER_BATCH * 8 * 4,
176
+ usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
177
+ });
178
+ // Create initial texture array with reasonable defaults
179
+ this.createTextureArray(256, 256, 32);
180
+ this.bindGroupLayout = this.device.createBindGroupLayout({
181
+ entries: [
182
+ { binding: 0, visibility: GPUShaderStage.VERTEX, buffer: { type: 'uniform' } },
183
+ {
184
+ binding: 1,
185
+ visibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT,
186
+ buffer: { type: 'read-only-storage' }
187
+ },
188
+ {
189
+ binding: 2,
190
+ visibility: GPUShaderStage.FRAGMENT,
191
+ texture: { sampleType: 'unfilterable-float', viewDimension: '2d-array' }
192
+ }
193
+ ]
194
+ });
195
+ const pipelineLayout = this.device.createPipelineLayout({
196
+ bindGroupLayouts: [this.bindGroupLayout]
197
+ });
198
+ this.pipeline = this.device.createRenderPipeline({
199
+ layout: pipelineLayout,
200
+ vertex: { module: vertexModule, entryPoint: 'vertexMain' },
201
+ fragment: {
202
+ module: fragmentModule,
203
+ entryPoint: 'fragmentMain',
204
+ targets: [
205
+ {
206
+ format: this.format,
207
+ blend: {
208
+ color: { srcFactor: 'one', dstFactor: 'one-minus-src-alpha', operation: 'add' },
209
+ alpha: { srcFactor: 'one', dstFactor: 'one-minus-src-alpha', operation: 'add' }
210
+ }
211
+ }
212
+ ]
213
+ },
214
+ primitive: { topology: 'triangle-list' }
215
+ });
216
+ this._initialized = true;
217
+ }
218
+ // Round up to a multiple of 64: gives headroom against size jitter without
219
+ // power-of-2 over-allocation (a 1920x1080 blend region would otherwise
220
+ // round to 2048x2048 and waste ~2x memory).
221
+ roundDim(n) {
222
+ return (Math.max(n, 64) + 63) & ~63;
223
+ }
224
+ // Round layers up to a multiple of 8, clamped to the WebGPU max
225
+ roundLayers(n) {
226
+ return Math.min((Math.max(n, 8) + 7) & ~7, MAX_TEXTURE_ARRAY_LAYERS);
227
+ }
228
+ createTextureArray(width, height, layers) {
229
+ if (this.textureArray) {
230
+ this.pendingDestroyTextures.push(this.textureArray);
231
+ }
232
+ const w = this.roundDim(width);
233
+ const h = this.roundDim(height);
234
+ const l = this.roundLayers(layers);
235
+ this.textureArray = this.device.createTexture({
236
+ size: [w, h, l],
237
+ format: 'rgba8unorm',
238
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT
239
+ });
240
+ this.textureArrayView = this.textureArray.createView({ dimension: '2d-array' });
241
+ this.textureArrayWidth = w;
242
+ this.textureArrayHeight = h;
243
+ this.textureArraySize = l;
244
+ this.bindGroupDirty = true;
245
+ // Clear all texture layers to transparent to prevent garbage border artifacts
246
+ const commandEncoder = this.device.createCommandEncoder();
247
+ for (let layer = 0; layer < l; layer++) {
248
+ const layerView = this.textureArray.createView({
249
+ dimension: '2d',
250
+ baseArrayLayer: layer,
251
+ arrayLayerCount: 1
252
+ });
253
+ const renderPass = commandEncoder.beginRenderPass({
254
+ colorAttachments: [
255
+ {
256
+ view: layerView,
257
+ clearValue: { r: 0, g: 0, b: 0, a: 0 },
258
+ loadOp: 'clear',
259
+ storeOp: 'store'
260
+ }
261
+ ]
262
+ });
263
+ renderPass.end();
264
+ }
265
+ this.device.queue.submit([commandEncoder.finish()]);
266
+ }
267
+ ensureTextureArray(maxWidth, maxHeight, count) {
268
+ // Clamp count to max layers
269
+ const clampedCount = Math.min(count, MAX_TEXTURE_ARRAY_LAYERS);
270
+ if (maxWidth <= this.textureArrayWidth &&
271
+ maxHeight <= this.textureArrayHeight &&
272
+ clampedCount <= this.textureArraySize) {
273
+ return false;
274
+ }
275
+ const newWidth = Math.max(this.textureArrayWidth, maxWidth);
276
+ const newHeight = Math.max(this.textureArrayHeight, maxHeight);
277
+ const newLayers = Math.max(clampedCount, Math.min(this.textureArraySize, 16));
278
+ this.createTextureArray(newWidth, newHeight, newLayers);
279
+ return true;
280
+ }
281
+ updateBindGroup() {
282
+ if (!this.bindGroupDirty || !this.device || !this.bindGroupLayout)
283
+ return;
284
+ this.bindGroup = this.device.createBindGroup({
285
+ layout: this.bindGroupLayout,
286
+ entries: [
287
+ { binding: 0, resource: { buffer: this.uniformBuffer } },
288
+ { binding: 1, resource: { buffer: this.imageDataBuffer } },
289
+ { binding: 2, resource: this.textureArrayView }
290
+ ]
291
+ });
292
+ this.bindGroupDirty = false;
293
+ }
294
+ async setCanvas(canvas, width, height) {
295
+ await this.init();
296
+ if (!this.device)
297
+ throw new Error('WebGPU device not initialized');
298
+ if (width <= 0 || height <= 0)
299
+ return;
300
+ this._canvas = canvas;
301
+ canvas.width = width;
302
+ canvas.height = height;
303
+ if (!this.context) {
304
+ this.context = canvas.getContext('webgpu');
305
+ if (!this.context)
306
+ throw new Error('Could not get WebGPU context');
307
+ this.context.configure({
308
+ device: this.device,
309
+ format: this.format,
310
+ alphaMode: 'premultiplied'
311
+ });
312
+ }
313
+ this.resolutionArray[0] = width;
314
+ this.resolutionArray[1] = height;
315
+ this.device.queue.writeBuffer(this.uniformBuffer, 0, this.resolutionArray);
316
+ this.lastCanvasWidth = width;
317
+ this.lastCanvasHeight = height;
318
+ }
319
+ updateSize(width, height) {
320
+ if (!this.device || !this._canvas || width <= 0 || height <= 0)
321
+ return;
322
+ if (width === this.lastCanvasWidth && height === this.lastCanvasHeight)
323
+ return;
324
+ this._canvas.width = width;
325
+ this._canvas.height = height;
326
+ this.resolutionArray[0] = width;
327
+ this.resolutionArray[1] = height;
328
+ this.device.queue.writeBuffer(this.uniformBuffer, 0, this.resolutionArray);
329
+ this.lastCanvasWidth = width;
330
+ this.lastCanvasHeight = height;
331
+ }
332
+ /**
333
+ * Render ImageBitmaps (async render mode)
334
+ * Handles batching when image count exceeds MAX_TEXTURE_ARRAY_LAYERS
335
+ */
336
+ renderBitmaps(images, _canvasWidth, _canvasHeight) {
337
+ if (!this.device || !this.context || !this.pipeline)
338
+ return;
339
+ const len = images.length;
340
+ if (len === 0) {
341
+ this.clear();
342
+ return;
343
+ }
344
+ const currentTexture = this.context.getCurrentTexture();
345
+ if (currentTexture.width === 0 || currentTexture.height === 0)
346
+ return;
347
+ // Single pass: find max dimensions and count valid images
348
+ let maxW = 0, maxH = 0, validCount = 0;
349
+ for (let i = 0; i < len; i++) {
350
+ const { image } = images[i];
351
+ const w = image.width, h = image.height;
352
+ if (w > 0 && h > 0) {
353
+ if (w > maxW)
354
+ maxW = w;
355
+ if (h > maxH)
356
+ maxH = h;
357
+ validCount++;
358
+ }
359
+ }
360
+ if (validCount === 0) {
361
+ this.clear();
362
+ return;
363
+ }
364
+ // Ensure texture array is large enough (capped at MAX_TEXTURE_ARRAY_LAYERS)
365
+ const batchSize = Math.min(validCount, MAX_TEXTURE_ARRAY_LAYERS);
366
+ this.ensureTextureArray(maxW, maxH, batchSize);
367
+ this.updateBindGroup();
368
+ const device = this.device;
369
+ const queue = device.queue;
370
+ const textureArray = this.textureArray;
371
+ const imageDataArray = this.imageDataArray;
372
+ const textureView = currentTexture.createView();
373
+ // Process images in batches if needed
374
+ let imageIndex = 0;
375
+ let isFirstBatch = true;
376
+ while (imageIndex < len) {
377
+ let texIndex = 0;
378
+ // Upload batch of textures
379
+ while (imageIndex < len && texIndex < MAX_TEXTURE_ARRAY_LAYERS) {
380
+ const img = images[imageIndex++];
381
+ const bitmap = img.image;
382
+ const w = bitmap.width, h = bitmap.height;
383
+ if (w <= 0 || h <= 0)
384
+ continue;
385
+ // Copy to texture array layer
386
+ queue.copyExternalImageToTexture({ source: bitmap, flipY: false }, { texture: textureArray, origin: [0, 0, texIndex], premultipliedAlpha: false }, { width: w, height: h });
387
+ // Fill pre-allocated array
388
+ const offset = texIndex << 3;
389
+ imageDataArray[offset] = img.x;
390
+ imageDataArray[offset + 1] = img.y;
391
+ imageDataArray[offset + 2] = w;
392
+ imageDataArray[offset + 3] = h;
393
+ imageDataArray[offset + 4] = w;
394
+ imageDataArray[offset + 5] = h;
395
+ imageDataArray[offset + 6] = texIndex;
396
+ imageDataArray[offset + 7] = 0;
397
+ texIndex++;
398
+ }
399
+ if (texIndex === 0)
400
+ continue;
401
+ // Upload buffer and draw batch
402
+ queue.writeBuffer(this.imageDataBuffer, 0, imageDataArray.buffer, 0, texIndex << 5);
403
+ const commandEncoder = device.createCommandEncoder();
404
+ const renderPass = commandEncoder.beginRenderPass({
405
+ colorAttachments: [
406
+ {
407
+ view: textureView,
408
+ clearValue: { r: 0, g: 0, b: 0, a: 0 },
409
+ loadOp: isFirstBatch ? 'clear' : 'load',
410
+ storeOp: 'store'
411
+ }
412
+ ]
413
+ });
414
+ renderPass.setPipeline(this.pipeline);
415
+ renderPass.setBindGroup(0, this.bindGroup);
416
+ renderPass.draw(6, texIndex);
417
+ renderPass.end();
418
+ queue.submit([commandEncoder.finish()]);
419
+ isFirstBatch = false;
420
+ }
421
+ this.cleanupPendingTextures();
422
+ }
423
+ /**
424
+ * Render from raw ArrayBuffer data (non-async render mode)
425
+ * Handles batching when image count exceeds MAX_TEXTURE_ARRAY_LAYERS
426
+ */
427
+ render(images, _canvasWidth, _canvasHeight) {
428
+ if (!this.device || !this.context || !this.pipeline)
429
+ return;
430
+ const len = images.length;
431
+ if (len === 0) {
432
+ this.clear();
433
+ return;
434
+ }
435
+ const currentTexture = this.context.getCurrentTexture();
436
+ if (currentTexture.width === 0 || currentTexture.height === 0)
437
+ return;
438
+ // Single pass: find max dimensions and count valid images
439
+ let maxW = 0, maxH = 0, validCount = 0;
440
+ for (let i = 0; i < len; i++) {
441
+ const { w, h } = images[i];
442
+ if (w > 0 && h > 0) {
443
+ if (w > maxW)
444
+ maxW = w;
445
+ if (h > maxH)
446
+ maxH = h;
447
+ validCount++;
448
+ }
449
+ }
450
+ if (validCount === 0) {
451
+ this.clear();
452
+ return;
453
+ }
454
+ // Ensure texture array is large enough (capped at MAX_TEXTURE_ARRAY_LAYERS)
455
+ const batchSize = Math.min(validCount, MAX_TEXTURE_ARRAY_LAYERS);
456
+ this.ensureTextureArray(maxW, maxH, batchSize);
457
+ this.updateBindGroup();
458
+ const device = this.device;
459
+ const queue = device.queue;
460
+ const textureArray = this.textureArray;
461
+ const imageDataArray = this.imageDataArray;
462
+ const textureView = currentTexture.createView();
463
+ // Process images in batches if needed
464
+ let imageIndex = 0;
465
+ let isFirstBatch = true;
466
+ while (imageIndex < len) {
467
+ let texIndex = 0;
468
+ // Upload batch of textures
469
+ while (imageIndex < len && texIndex < MAX_TEXTURE_ARRAY_LAYERS) {
470
+ const img = images[imageIndex++];
471
+ const w = img.w, h = img.h;
472
+ if (w <= 0 || h <= 0)
473
+ continue;
474
+ // Upload texture data
475
+ const imgData = img.image;
476
+ if (imgData instanceof ImageBitmap) {
477
+ queue.copyExternalImageToTexture({ source: imgData, flipY: false }, { texture: textureArray, origin: [0, 0, texIndex], premultipliedAlpha: false }, { width: w, height: h });
478
+ }
479
+ else if (imgData instanceof ArrayBuffer || imgData instanceof Uint8Array || imgData instanceof Uint8ClampedArray) {
480
+ this.uploadTextureData(texIndex, imgData, w, h);
481
+ }
482
+ // Fill pre-allocated array
483
+ const offset = texIndex << 3;
484
+ imageDataArray[offset] = img.x;
485
+ imageDataArray[offset + 1] = img.y;
486
+ imageDataArray[offset + 2] = w;
487
+ imageDataArray[offset + 3] = h;
488
+ imageDataArray[offset + 4] = w;
489
+ imageDataArray[offset + 5] = h;
490
+ imageDataArray[offset + 6] = texIndex;
491
+ imageDataArray[offset + 7] = 0;
492
+ texIndex++;
493
+ }
494
+ if (texIndex === 0)
495
+ continue;
496
+ // Upload buffer and draw batch
497
+ queue.writeBuffer(this.imageDataBuffer, 0, imageDataArray.buffer, 0, texIndex << 5);
498
+ const commandEncoder = device.createCommandEncoder();
499
+ const renderPass = commandEncoder.beginRenderPass({
500
+ colorAttachments: [
501
+ {
502
+ view: textureView,
503
+ clearValue: { r: 0, g: 0, b: 0, a: 0 },
504
+ loadOp: isFirstBatch ? 'clear' : 'load',
505
+ storeOp: 'store'
506
+ }
507
+ ]
508
+ });
509
+ renderPass.setPipeline(this.pipeline);
510
+ renderPass.setBindGroup(0, this.bindGroup);
511
+ renderPass.draw(6, texIndex);
512
+ renderPass.end();
513
+ queue.submit([commandEncoder.finish()]);
514
+ isFirstBatch = false;
515
+ }
516
+ this.cleanupPendingTextures();
517
+ }
518
+ uploadTextureData(layerIndex, rgbaBuffer, width, height) {
519
+ this.device.queue.writeTexture({ texture: this.textureArray, origin: [0, 0, layerIndex] }, toUint8View(rgbaBuffer), { bytesPerRow: width * 4 }, { width, height });
520
+ }
521
+ cleanupPendingTextures() {
522
+ const pending = this.pendingDestroyTextures;
523
+ const len = pending.length;
524
+ if (len === 0)
525
+ return;
526
+ for (let i = 0; i < len; i++) {
527
+ pending[i].destroy();
528
+ }
529
+ pending.length = 0;
530
+ }
531
+ clear() {
532
+ if (!this.device || !this.context)
533
+ return;
534
+ try {
535
+ const currentTexture = this.context.getCurrentTexture();
536
+ if (currentTexture.width === 0 || currentTexture.height === 0)
537
+ return;
538
+ const commandEncoder = this.device.createCommandEncoder();
539
+ const renderPass = commandEncoder.beginRenderPass({
540
+ colorAttachments: [
541
+ {
542
+ view: currentTexture.createView(),
543
+ clearValue: { r: 0, g: 0, b: 0, a: 0 },
544
+ loadOp: 'clear',
545
+ storeOp: 'store'
546
+ }
547
+ ]
548
+ });
549
+ renderPass.end();
550
+ this.device.queue.submit([commandEncoder.finish()]);
551
+ }
552
+ catch {
553
+ // Ignore errors
554
+ }
555
+ }
556
+ get initialized() {
557
+ return this._initialized;
558
+ }
559
+ destroy() {
560
+ this.cleanupPendingTextures();
561
+ this.textureArray?.destroy();
562
+ this.textureArray = null;
563
+ this.textureArrayView = null;
564
+ this.uniformBuffer?.destroy();
565
+ this.uniformBuffer = null;
566
+ this.imageDataBuffer?.destroy();
567
+ this.imageDataBuffer = null;
568
+ this.bindGroup = null;
569
+ this.device?.destroy();
570
+ this.device = null;
571
+ this.context = null;
572
+ this._canvas = null;
573
+ this._initialized = false;
574
+ this._initPromise = null;
575
+ }
576
+ }
577
+ //# sourceMappingURL=webgpu-renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webgpu-renderer.js","sourceRoot":"","sources":["../../../src/ts/webgpu-renderer.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAIvC,2BAA2B;AAC3B,MAAM,oBAAoB,GAAG,GAAG,CAAA;AAEhC,kCAAkC;AAClC,MAAM,wBAAwB,GAAG,GAAG,CAAA;AAEpC,qBAAqB;AACrB,MAAM,aAAa,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuDhC,CAAA;AAED,uBAAuB;AACvB,MAAM,eAAe,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsClC,CAAA;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,OAAO,SAAS,KAAK,WAAW,IAAI,KAAK,IAAI,SAAS,CAAA;AAC/D,CAAC;AAED,SAAS,WAAW,CAAC,IAAkD;IACrE,IAAI,IAAI,YAAY,WAAW,EAAE,CAAC;QAChC,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;AACtE,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,cAAc;IACjB,MAAM,GAAqB,IAAI,CAAA;IAC/B,OAAO,GAA4B,IAAI,CAAA;IACvC,QAAQ,GAA6B,IAAI,CAAA;IACzC,eAAe,GAA8B,IAAI,CA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ChB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;QACrD,CAAC;QAAC,MAAM,CAAC;YACP,gBAAgB;QAClB,CAAC;IACH,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAA;IAC1B,CAAC;IAED,OAAO;QACL,IAAI,CAAC,sBAAsB,EAAE,CAAA;QAE7B,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE,CAAA;QAC5B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAA;QACxB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAA;QAE5B,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,CAAA;QAC7B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;QACzB,IAAI,CAAC,eAAe,EAAE,OAAO,EAAE,CAAA;QAC/B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAA;QAE3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;QAErB,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QAClB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAA;QACzB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAA;IAC1B,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * AkariSub Worker - TypeScript implementation.
3
+ * Runs in a Web Worker to offload subtitle rendering from the main thread.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/ts/worker.ts"],"names":[],"mappings":"AAAA;;;GAGG"}