@next2d/webgpu 3.11.0 → 3.12.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.
Files changed (46) hide show
  1. package/package.json +3 -3
  2. package/src/Blend/BlendInstancedManager.d.ts +2 -1
  3. package/src/Blend/BlendInstancedManager.js +18 -15
  4. package/src/Blend/usecase/BlendApplyComplexBlendUseCase.d.ts +3 -1
  5. package/src/Blend/usecase/BlendApplyComplexBlendUseCase.js +24 -17
  6. package/src/BufferManager.d.ts +14 -0
  7. package/src/BufferManager.js +47 -0
  8. package/src/Context/usecase/ContextApplyFilterUseCase.js +12 -12
  9. package/src/Context/usecase/ContextContainerEndLayerUseCase.js +8 -8
  10. package/src/Context/usecase/ContextDrawArraysInstancedUseCase.js +4 -3
  11. package/src/Context/usecase/ContextDrawIndirectUseCase.d.ts +3 -1
  12. package/src/Context/usecase/ContextDrawIndirectUseCase.js +33 -15
  13. package/src/Context/usecase/ContextProcessComplexBlendQueueUseCase.js +18 -62
  14. package/src/Context.d.ts +20 -19
  15. package/src/Context.js +203 -105
  16. package/src/ExternalImageUploadBatch.d.ts +24 -0
  17. package/src/ExternalImageUploadBatch.js +133 -0
  18. package/src/Filter/BevelFilter/FilterApplyBevelFilterUseCase.js +5 -20
  19. package/src/Filter/BlurFilter/FilterApplyBlurFilterUseCase.js +38 -11
  20. package/src/Filter/ColorMatrixFilter/FilterApplyColorMatrixFilterUseCase.js +3 -10
  21. package/src/Filter/ConvolutionFilter/FilterApplyConvolutionFilterUseCase.js +3 -10
  22. package/src/Filter/DisplacementMapFilter/FilterApplyDisplacementMapFilterUseCase.js +5 -11
  23. package/src/Filter/DropShadowFilter/FilterApplyDropShadowFilterUseCase.js +8 -5
  24. package/src/Filter/GlowFilter/FilterApplyGlowFilterUseCase.js +8 -5
  25. package/src/Filter/GradientBevelFilter/FilterApplyGradientBevelFilterUseCase.js +5 -20
  26. package/src/Filter/GradientGlowFilter/FilterApplyGradientGlowFilterUseCase.js +3 -10
  27. package/src/Filter/service/FilterAllocateUniformBindingService.d.ts +11 -0
  28. package/src/Filter/service/FilterAllocateUniformBindingService.js +20 -0
  29. package/src/FrameBufferManager/usecase/FrameBufferManagerCreateAttachmentUseCase.js +2 -1
  30. package/src/InstanceBufferAllocator.d.ts +24 -0
  31. package/src/InstanceBufferAllocator.js +123 -0
  32. package/src/Shader/PipelineManager.d.ts +5 -0
  33. package/src/Shader/PipelineManager.js +55 -7
  34. package/src/Shader/ShaderSource.d.ts +9 -1
  35. package/src/Shader/ShaderSource.js +28 -6
  36. package/src/Shader/wgsl/fragment/FilterFragment.d.ts +4 -6
  37. package/src/Shader/wgsl/fragment/FilterFragment.js +10 -4
  38. package/src/TexturePool/service/TexturePoolCleanupService.d.ts +2 -2
  39. package/src/TexturePool/service/TexturePoolCleanupService.js +2 -1
  40. package/src/TexturePool/service/TexturePoolReleaseService.d.ts +2 -2
  41. package/src/TexturePool/service/TexturePoolReleaseService.js +8 -1
  42. package/src/TexturePool/usecase/TexturePoolAcquireUseCase.d.ts +2 -2
  43. package/src/TexturePool/usecase/TexturePoolAcquireUseCase.js +3 -1
  44. package/src/TexturePool.d.ts +1 -0
  45. package/src/TexturePool.js +11 -3
  46. package/src/interface/IFilterConfig.d.ts +1 -0
@@ -3,11 +3,6 @@ import { execute as blendApplyComplexBlendUseCase } from "../../Blend/usecase/Bl
3
3
  import { $getAtlasAttachmentObject } from "../../AtlasManager";
4
4
  import { execute as frameBufferManagerResolveAttachmentService } from "../../FrameBufferManager/service/FrameBufferManagerResolveAttachmentService";
5
5
  // プリアロケート配列
6
- /**
7
- * @description ユニフォームデータの事前確保配列(4要素)
8
- * Pre-allocated uniform data array (4 elements)
9
- */
10
- const $uniform4 = new Float32Array(4);
11
6
  /**
12
7
  * @description ユニフォームデータの事前確保配列(6要素)
13
8
  * Pre-allocated uniform data array (6 elements)
@@ -33,51 +28,6 @@ const $entries3 = [
33
28
  { "binding": 1, "resource": null },
34
29
  { "binding": 2, "resource": null }
35
30
  ];
36
- /**
37
- * @description レンダーパスを使用してテクスチャ領域をコピーする
38
- * Copies a texture region via render pass
39
- * @param {GPUDevice} device GPUデバイス / GPU device
40
- * @param {GPUCommandEncoder} command_encoder コマンドエンコーダ / Command encoder
41
- * @param {GPUTextureView} src_view ソーステクスチャビュー / Source texture view
42
- * @param {IAttachmentObject} dst_attachment デスティネーションアタッチメント / Destination attachment
43
- * @param {number} src_x ソースX座標 / Source X coordinate
44
- * @param {number} src_y ソースY座標 / Source Y coordinate
45
- * @param {number} src_width ソース幅 / Source width
46
- * @param {number} src_height ソース高さ / Source height
47
- * @param {number} copy_width コピー幅 / Copy width
48
- * @param {number} copy_height コピー高さ / Copy height
49
- * @param {FrameBufferManager} frame_buffer_manager フレームバッファマネージャ / Frame buffer manager
50
- * @param {TextureManager} texture_manager テクスチャマネージャ / Texture manager
51
- * @param {PipelineManager} pipeline_manager パイプラインマネージャ / Pipeline manager
52
- * @param {BufferManager} buffer_manager バッファマネージャ / Buffer manager
53
- * @return {void}
54
- */
55
- const $copyTextureRegionViaRenderPass = (device, command_encoder, src_view, dst_attachment, src_x, src_y, src_width, src_height, copy_width, copy_height, frame_buffer_manager, texture_manager, pipeline_manager, buffer_manager) => {
56
- const pipeline = pipeline_manager.getPipeline("complex_blend_copy");
57
- const bindGroupLayout = pipeline_manager.getBindGroupLayout("texture_copy");
58
- if (!pipeline || !bindGroupLayout) {
59
- return;
60
- }
61
- $uniform4[0] = copy_width / src_width;
62
- $uniform4[1] = copy_height / src_height;
63
- $uniform4[2] = src_x / src_width;
64
- $uniform4[3] = src_y / src_height;
65
- const uniformBuffer = buffer_manager.acquireAndWriteUniformBuffer($uniform4);
66
- const sampler = texture_manager.createSampler("complex_blend_copy_sampler", false);
67
- $entries3[0].resource.buffer = uniformBuffer;
68
- $entries3[1].resource = sampler;
69
- $entries3[2].resource = src_view;
70
- const bindGroup = device.createBindGroup({
71
- "layout": bindGroupLayout,
72
- "entries": $entries3
73
- });
74
- const renderPassDescriptor = frame_buffer_manager.createRenderPassDescriptor(dst_attachment.texture.view, 0, 0, 0, 0, "clear");
75
- const passEncoder = command_encoder.beginRenderPass(renderPassDescriptor);
76
- passEncoder.setPipeline(pipeline);
77
- passEncoder.setBindGroup(0, bindGroup);
78
- passEncoder.draw(6, 1, 0, 0);
79
- passEncoder.end();
80
- };
81
31
  /**
82
32
  * @description ブレンド結果をメインアタッチメントに描画する
83
33
  * Draws blend result to the main attachment
@@ -109,9 +59,9 @@ const $drawToMainAttachment = (device, command_encoder, src_attachment, main_att
109
59
  $uniform8[5] = main_attachment.height;
110
60
  $uniform8[6] = 0;
111
61
  $uniform8[7] = 0;
112
- const uniformBuffer = buffer_manager.acquireAndWriteUniformBuffer($uniform8);
62
+ const uniformBinding = buffer_manager.allocateUniformBinding($uniform8);
113
63
  const sampler = texture_manager.createSampler("complex_blend_output_sampler", false);
114
- $entries3[0].resource.buffer = uniformBuffer;
64
+ $entries3[0].resource = uniformBinding;
115
65
  $entries3[1].resource = sampler;
116
66
  $entries3[2].resource = src_attachment.texture.view;
117
67
  const bindGroup = device.createBindGroup({
@@ -214,9 +164,9 @@ export const execute = (device, command_encoder, main_attachment, frame_buffer_m
214
164
  $uniform12[9] = blendHeight;
215
165
  $uniform12[10] = 0;
216
166
  $uniform12[11] = 0;
217
- const uniformBuffer = buffer_manager.acquireAndWriteUniformBuffer($uniform12, 48);
167
+ const uniformBinding = buffer_manager.allocateUniformBinding($uniform12);
218
168
  const sampler = texture_manager.createSampler("scale_sampler", true);
219
- $entries3[0].resource.buffer = uniformBuffer;
169
+ $entries3[0].resource = uniformBinding;
220
170
  $entries3[1].resource = sampler;
221
171
  $entries3[2].resource = originalAttachment.texture.view;
222
172
  const bindGroup = device.createBindGroup({
@@ -251,11 +201,18 @@ export const execute = (device, command_encoder, main_attachment, frame_buffer_m
251
201
  "origin": { "x": 0, "y": 0, "z": 0 }
252
202
  }, { "width": blendWidth, "height": blendHeight });
253
203
  }
254
- // 2. デスティネーションテクスチャを作成(メインからレンダーパスでコピー)
255
- // メインのリゾルブ済みテクスチャを読むため、未リゾルブ分を先に解決する
256
- frameBufferManagerResolveAttachmentService(command_encoder, frame_buffer_manager, main_attachment);
257
- const dstAttachment = frame_buffer_manager.createTemporaryAttachment(blendWidth, blendHeight);
258
- $copyTextureRegionViaRenderPass(device, command_encoder, main_attachment.texture.view, dstAttachment, dstX, dstY, main_attachment.width, main_attachment.height, blendWidth, blendHeight, frame_buffer_manager, texture_manager, pipeline_manager, buffer_manager);
204
+ // 2. 4x UNORM8背景は必要な領域だけを合成シェーダー内で解決する。
205
+ // 解決済みテクスチャ自体は更新しないため、msaaDirtyは維持する。
206
+ const msaa = main_attachment.msaaTexture;
207
+ const resource = msaa?.resource;
208
+ const useMsaaBackdrop = main_attachment.msaa && main_attachment.msaaDirty
209
+ && !!msaa?.view
210
+ && resource?.sampleCount === 4
211
+ && (resource.usage & GPUTextureUsage.TEXTURE_BINDING) !== 0
212
+ && (resource.format === "rgba8unorm" || resource.format === "bgra8unorm");
213
+ if (!useMsaaBackdrop) {
214
+ frameBufferManagerResolveAttachmentService(command_encoder, frame_buffer_manager, main_attachment);
215
+ }
259
216
  // 3. カラートランスフォームを準備(add値は生値)
260
217
  $uniform8[0] = color_transform[0];
261
218
  $uniform8[1] = color_transform[1];
@@ -266,7 +223,7 @@ export const execute = (device, command_encoder, main_attachment, frame_buffer_m
266
223
  $uniform8[6] = color_transform[6];
267
224
  $uniform8[7] = 0;
268
225
  // 4. 複雑なブレンドを適用
269
- const blendedAttachment = blendApplyComplexBlendUseCase(srcAttachment, dstAttachment, blend_mode, $uniform8, {
226
+ const blendedAttachment = blendApplyComplexBlendUseCase(srcAttachment, main_attachment, blend_mode, $uniform8, {
270
227
  "device": device,
271
228
  "commandEncoder": command_encoder,
272
229
  "bufferManager": buffer_manager,
@@ -274,12 +231,11 @@ export const execute = (device, command_encoder, main_attachment, frame_buffer_m
274
231
  "pipelineManager": pipeline_manager,
275
232
  "textureManager": texture_manager,
276
233
  "frameTextures": []
277
- });
234
+ }, [dstX, dstY], useMsaaBackdrop ? msaa.view : undefined);
278
235
  // 5. 結果をメインアタッチメントに描画
279
236
  $drawToMainAttachment(device, command_encoder, blendedAttachment, main_attachment, dstX, dstY, frame_buffer_manager, texture_manager, pipeline_manager, buffer_manager);
280
237
  // 6. 一時テクスチャを解放
281
238
  frame_buffer_manager.releaseTemporaryAttachment(srcAttachment);
282
- frame_buffer_manager.releaseTemporaryAttachment(dstAttachment);
283
239
  frame_buffer_manager.releaseTemporaryAttachment(blendedAttachment);
284
240
  }
285
241
  clearComplexBlendQueue();
package/src/Context.d.ts CHANGED
@@ -9,6 +9,7 @@ import type { Node } from "@next2d/texture-packer";
9
9
  * @class
10
10
  */
11
11
  export declare class Context {
12
+ private readonly _nodeRoots;
12
13
  /** @description 変換行列スタック / Transform matrix stack */
13
14
  readonly $stack: Float32Array[];
14
15
  /** @description 現在の2D変換行列 / Current 2D transform matrix */
@@ -55,6 +56,11 @@ export declare class Context {
55
56
  private commandEncoder;
56
57
  /** @description レンダーパスエンコーダー / Render pass encoder */
57
58
  private renderPassEncoder;
59
+ /** @description 連続するキャッシュ出力だけで再利用するパスと出力先 / Pass owned by consecutive cached-filter output */
60
+ private cachedFilterPass;
61
+ private cachedFilterPassColorView;
62
+ /** @description このContextの固定UV・sampler・layoutだけを使う弱参照キャッシュ / Context-owned immutable identity bindings */
63
+ private readonly cachedFilterBindGroups;
58
64
  /**
59
65
  * @description 現在openなrenderPassEncoderがインスタンスバッチ用パスかどうか。
60
66
  * インスタンスパスは連続バッチ間で再利用されるが、fill/clip等の
@@ -76,6 +82,7 @@ export declare class Context {
76
82
  private pooledTextures;
77
83
  /** @description フレームごとのレンダーテクスチャプール管理(endFrame()でプールに返却) / Per-frame render texture pool (returned to pool in endFrame()) */
78
84
  private pooledRenderTextures;
85
+ private externalImageUploadBatch;
79
86
  /** @description 現在のレンダーターゲット(メインまたはアトラス) / Current render target (could be main or atlas) */
80
87
  private currentRenderTarget;
81
88
  /** @description 現在のビューポート幅(アトラス描画時はアトラスサイズ) / Current viewport width (atlas size during atlas rendering) */
@@ -531,16 +538,15 @@ export declare class Context {
531
538
  * @param {number} x_max - バウンディングボックス右端 / Bounding box right
532
539
  * @param {number} y_max - バウンディングボックス下端 / Bounding box bottom
533
540
  * @param {Float32Array} color_transform - カラー変換パラメータ / Color transform parameters
541
+ * @param {number} color_transform_offset - 要素単位の開始位置 / Start offset in elements
534
542
  * @return {void}
535
543
  */
536
- drawDisplayObject(node: Node, x_min: number, y_min: number, x_max: number, y_max: number, color_transform: Float32Array): void;
544
+ drawDisplayObject(node: Node, x_min: number, y_min: number, x_max: number, y_max: number, color_transform: Float32Array, color_transform_offset?: number): void;
537
545
  /**
538
546
  * @description インスタンス配列を描画
539
547
  * Draw instanced arrays
540
548
  *
541
- * useOptimizedInstancingがtrueの場合、Storage BufferとIndirect Drawingを使用。
542
- * - Storage Buffer: メモリアロケーション削減、CPU負荷15-25%軽減
543
- * - Indirect Drawing: CPU-GPUオーバーヘッド5-15%削減
549
+ * useOptimizedInstancingがtrueの場合、連続バッチの描画パスを再利用する。
544
550
  *
545
551
  * @return {void}
546
552
  */
@@ -607,18 +613,9 @@ export declare class Context {
607
613
  * @return {void}
608
614
  */
609
615
  drawElement(node: Node, element: OffscreenCanvas | ImageBitmap, flip_y?: boolean): void;
610
- /**
611
- * @description 一時テクスチャ経由でMSAAテクスチャに直接描画
612
- * Draw to MSAA texture directly via a temporary texture
613
- *
614
- * @param {IAttachmentObject} attachment - アタッチメントオブジェクト / Attachment object
615
- * @param {Node} node - 描画対象ノード / Target node
616
- * @param {OffscreenCanvas | ImageBitmap} element - 描画要素 / Element to draw
617
- * @param {number} width - 幅 / Width
618
- * @param {number} height - 高さ / Height
619
- * @param {boolean} flip_y - Y軸反転フラグ / Y-axis flip flag
620
- * @return {void}
621
- */
616
+ /** Snapshot eligible text canvases into the batch; other images upload directly. */
617
+ private uploadElementTexture;
618
+ /** Draw to the MSAA atlas through a frame-owned temporary image texture. */
622
619
  private drawElementToMsaa;
623
620
  /**
624
621
  * @description 一時テクスチャ経由で通常テクスチャに描画(非MSAA版)
@@ -752,11 +749,13 @@ export declare class Context {
752
749
  */
753
750
  addFrameTexture(texture: GPUTexture): void;
754
751
  /**
755
- * @description フレーム終了とコマンド送信(レンダリング完了後に呼ぶ)
756
- * End the frame and submit commands (call after rendering is complete)
752
+ * @description 提出済みGPU処理の完了を通知する(画面提示の完了ではない)
753
+ * Observe submitted GPU work, not presentation completion.
757
754
  *
758
- * @return {void}
755
+ * @return {Promise<void>}
759
756
  */
757
+ getRenderCompletion(): Promise<void>;
758
+ /** End the frame and submit commands before returning temporary resources. */
760
759
  endFrame(): void;
761
760
  /**
762
761
  * @description コマンドを送信(後方互換性のため残す)
@@ -775,6 +774,8 @@ export declare class Context {
775
774
  * @return {Node} 作成されたノード / Created node
776
775
  */
777
776
  createNode(width: number, height: number): Node;
777
+ /** Select the page of a live cached node without reallocating its rectangle. */
778
+ reuseNode(node: Node): boolean;
778
779
  /**
779
780
  * @description ノードを削除
780
781
  * Remove a node from the texture atlas