@next2d/webgpu 3.0.0 → 3.0.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.
Files changed (2) hide show
  1. package/README.md +176 -517
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,574 +1,233 @@
1
1
  # @next2d/webgpu
2
2
 
3
- WebGPU-based rendering engine for Next2D (Experimental / Work in Progress)
4
-
5
- WebGPU ベースのレンダリングエンジン(実験的 / 開発中)
6
-
7
- ---
8
-
9
- ## ⚠️ Warning / 警告
10
-
11
- **This package is currently under development and NOT production-ready.**
12
-
13
- **本パッケージは現在開発中であり、本番環境での使用には対応していません。**
14
-
15
- - Many features are incomplete or placeholder implementations
16
- - APIs may change without notice
17
- - Performance has not been optimized
18
- - Testing is incomplete
19
-
20
- ---
3
+ WebGPU-based rendering engine for Next2D Player / Next2D Player用のWebGPUベースレンダリングエンジン
21
4
 
22
5
  ## Overview / 概要
23
6
 
24
- This package provides a WebGPU-based rendering backend for Next2D Player, designed as an alternative to the existing WebGL implementation. WebGPU is a modern graphics API that offers better performance and more control over GPU resources.
7
+ The `@next2d/webgpu` package is a rendering backend for Next2D Player, providing a high-performance, shader-based drawing pipeline built on WebGPU. This package handles all graphics rendering operations including vector shapes, bitmaps, filters, and effects.
25
8
 
26
- 本パッケージは Next2D Player 向けの WebGPU ベースのレンダリングバックエンドを提供します。既存の WebGL 実装の代替として設計されており、WebGPU は優れたパフォーマンスと GPU リソースに対するより細かい制御を提供する最新のグラフィックス API です。
9
+ `@next2d/webgpu`パッケージは、Next2D Playerのレンダリングバックエンドであり、WebGPU上に構築された高性能なシェーダーベースの描画パイプラインを提供します。このパッケージは、ベクター図形、ビットマップ、フィルター、エフェクトなど、すべてのグラフィックスレンダリング操作を処理します。
27
10
 
28
- ### Key Features / 主な機能
11
+ ### Key Features / 主な特徴
29
12
 
30
- - WGSL (WebGPU Shading Language) shader implementations
31
- - Texture atlas management for efficient rendering
32
- - Instance-based batch rendering
33
- - Blend mode support
34
- - Mask rendering capabilities
35
- - Filter effects (Blur, Glow, Drop Shadow, Color Matrix)
13
+ - **WebGPU-based rendering** - Hardware-accelerated graphics using modern WebGPU API / WebGPU APIを使用したハードウェアアクセラレーション
14
+ - **Shader-based pipeline** - Efficient WGSL shader processing for all rendering operations / すべてのレンダリング操作に対する効率的なWGSLシェーダー処理
15
+ - **Texture atlas management** - Optimized texture packing and management / 最適化されたテクスチャパッキングと管理
16
+ - **Advanced filters** - Full support for color matrix, blur, glow, displacement map and more / カラーマトリックス、ブラー、グロー、ディスプレースメントマップなどのフルサポート
17
+ - **Blend modes** - Multiple blend mode support with stencil operations / ステンシル操作による複数のブレンドモードサポート
18
+ - **Masking system** - Stencil buffer-based masking for complex clipping / 複雑なクリッピングのためのステンシルバッファベースのマスキング
19
+ - **Compute shaders** - GPU compute-based blur processing for high-performance filter effects / 高性能フィルターエフェクトのためのGPUコンピュートベースのブラー処理
36
20
 
37
- ---
21
+ ## Installation / インストール
22
+
23
+ ```bash
24
+ npm install @next2d/webgpu
25
+ ```
38
26
 
39
27
  ## Directory Structure / ディレクトリ構造
40
28
 
41
29
  ```
42
30
  src/
43
- ├── Context.ts # Main rendering context (WebGPU版のメインコンテキスト)
44
- ├── WebGPUUtil.ts # Utility functions and global state management
45
-
46
- ├── Managers / マネージャー
47
- ├── AtlasManager.ts # Atlas texture management (アトラステクスチャ管理)
48
- ├── AttachmentManager.ts # Offscreen attachment/FBO management (オフスクリーンアタッチメント管理)
49
- ├── BufferManager.ts # Vertex/Uniform buffer management (バッファ管理)
50
- ├── DrawManager.ts # Drawing operations helper (描画操作ヘルパー)
51
- ├── FrameBufferManager.ts # Framebuffer management (フレームバッファ管理)
52
- │ └── TextureManager.ts # Texture and sampler management (テクスチャ/サンプラー管理)
53
-
54
- ├── Core Components / コアコンポーネント
55
- ├── PathCommand.ts # Path drawing commands (moveTo, lineTo, bezierCurveTo, etc.)
56
- │ │ ├── PathCommandState.ts # Path command state management
57
- │ ├── service/
58
- │ │ │ ├── PathCommandBeginPathService.ts
59
- │ │ │ ├── PathCommandEqualsToLastPointService.ts
60
- │ │ ├── PathCommandPushCurrentPathToVerticesService.ts
61
- │ │ └── PathCommandPushPointToCurrentPathService.ts
62
- │ │ └── usecase/
63
- │ │ ├── PathCommandArcUseCase.ts
64
- ├── PathCommandBezierCurveToUseCase.ts
65
- │ ├── PathCommandClosePathUseCase.ts
66
- │ │ ├── PathCommandLineToUseCase.ts
67
- ├── PathCommandMoveToUseCase.ts
68
- │ └── PathCommandQuadraticCurveToUseCase.ts
69
- │ ├── Mesh.ts # Mesh data structures and utilities
70
- ├── service/
71
- │ │ ├── MeshCalculateNormalVectorService.ts
72
- │ │ ├── MeshFillGenerateService.ts
73
- │ │ ├── MeshGetQuadraticBezierPointService.ts
74
- │ │ ├── MeshGetQuadraticBezierTangentService.ts
75
- │ │ └── MeshLerpService.ts
76
- │ └── usecase/
77
- ├── MeshBitmapStrokeGenerateUseCase.ts
78
- │ ├── MeshFillGenerateUseCase.ts
79
- │ │ ├── MeshGradientStrokeGenerateUseCase.ts
80
- │ ├── MeshSplitQuadraticBezierUseCase.ts
81
- │ │ └── MeshStrokeGenerateUseCase.ts
82
- │ ├── BezierConverter.ts # Bezier curve conversion utilities
83
- ├── service/
84
- │ │ ├── BezierConverterCubicToQuadService.ts
85
- │ │ └── BezierConverterSplitCubicService.ts
86
- │ └── usecase/
87
- │ │ └── BezierConverterAdaptiveCubicToQuadUseCase.ts
88
- ├── Blend.ts # Blend mode state management
89
- ├── Mask.ts # Mask rendering state management
90
- └── Grid.ts # Grid/9-slice system
91
-
92
- ├── Shader/ シェーダー関連
93
- ├── ShaderSource.ts # WGSL shader source code
94
- ├── PipelineManager.ts # Render pipeline management
95
- │ ├── ShaderInstancedManager.ts # Instance rendering shader management
96
- │ ├── BlendModeShader.ts # Blend mode shader implementations
97
- │ └── GradientLUTGenerator.ts # Gradient lookup table generation
98
- ├── service/
99
- ├── GradientLUTCalculateResolutionService.ts
100
- ├── GradientLUTGeneratePixelsService.ts
101
- │ │ ├── GradientLUTInterpolateColorService.ts
102
- │ │ └── GradientLUTParseStopsService.ts
103
- │ └── usecase/
104
- │ └── GradientLUTGenerateDataUseCase.ts
105
-
106
- ├── Gradient/ グラデーション関連
107
- │ ├── GradientLUTCache.ts # Gradient LUT cache management
108
- │ └── GradientLUTGenerator.ts # Gradient LUT generation
109
-
110
- ├── Filter/ フィルター実装
111
- │ ├── index.ts # Filter exports
112
- │ ├── BlurFilterShader.ts # Blur filter implementation
113
- │ ├── BlurFilterUseCase.ts # Blur filter use case
114
- │ ├── GlowFilterShader.ts # Glow filter implementation
115
- │ ├── DropShadowFilterShader.ts # Drop shadow filter implementation
116
- │ ├── ColorMatrixFilterShader.ts # Color matrix filter implementation
117
- │ ├── BevelFilter/
118
- │ │ └── FilterApplyBevelFilterUseCase.ts
119
- │ ├── BlurFilter/
120
- │ │ └── FilterApplyBlurFilterUseCase.ts
121
- │ ├── ColorMatrixFilter/
122
- │ │ └── FilterApplyColorMatrixFilterUseCase.ts
123
- │ ├── ConvolutionFilter/
124
- │ │ └── FilterApplyConvolutionFilterUseCase.ts
125
- │ ├── DisplacementMapFilter/
126
- │ │ └── FilterApplyDisplacementMapFilterUseCase.ts
127
- │ ├── DropShadowFilter/
128
- │ │ └── FilterApplyDropShadowFilterUseCase.ts
129
- │ ├── GlowFilter/
130
- │ │ └── FilterApplyGlowFilterUseCase.ts
131
- │ ├── GradientBevelFilter/
132
- │ │ └── FilterApplyGradientBevelFilterUseCase.ts
133
- │ └── GradientGlowFilter/
134
- │ └── FilterApplyGradientGlowFilterUseCase.ts
135
-
136
- ├── Blend/ ブレンド関連
137
- │ ├── BlendInstancedManager.ts # Instance-based blend rendering
138
- │ ├── service/
139
- │ │ ├── BlendAddService.ts
140
- │ │ ├── BlendAlphaService.ts
141
- │ │ ├── BlendEraseService.ts
142
- │ │ ├── BlendGetStateService.ts
143
- │ │ ├── BlendOneZeroService.ts
144
- │ │ ├── BlendResetService.ts
145
- │ │ ├── BlendScreenService.ts
146
- │ │ └── BlendSetModeService.ts
147
- │ └── usecase/
148
- │ ├── BlendApplyComplexBlendUseCase.ts
149
- │ └── BlendOperationUseCase.ts
150
-
151
- ├── Mask/ マスク関連
152
- │ ├── service/
153
- │ │ ├── MaskBeginMaskService.ts
154
- │ │ ├── MaskEndMaskService.ts
155
- │ │ ├── MaskSetMaskBoundsService.ts
156
- │ │ └── MaskUnionMaskService.ts
157
- │ └── usecase/
158
- │ ├── MaskLeaveMaskUseCase.ts
159
- │ └── MaskBindUseCase.ts
160
-
161
- └── interface/ 型定義
162
- ├── IAttachmentObject.ts # Attachment object interface
163
- ├── IBlendMode.ts # Blend mode types
164
- ├── IBounds.ts # Bounds rectangle interface
165
- ├── IFillType.ts # Fill type definitions
166
- ├── IPath.ts # Path interface
167
- ├── IPoint.ts # Point interface
168
- └── ITextureObject.ts # Texture object interface
31
+ ├── Context.ts # Main rendering context / メインレンダリングコンテキスト
32
+ ├── Context/
33
+ ├── service/ # Context services / コンテキストサービス
34
+ │ └── usecase/ # Context use cases / コンテキストユースケース
35
+ ├── AtlasManager.ts # Texture atlas management / テクスチャアトラス管理
36
+ ├── FrameBufferManager.ts # Render target management / レンダーターゲット管理
37
+ ├── AttachmentManager.ts # Color/stencil attachment management / カラー/ステンシルアタッチメント管理
38
+ ├── BufferManager.ts # Vertex/Uniform buffer management / 頂点/Uniformバッファ管理
39
+ ├── TextureManager.ts # Texture management / テクスチャ管理
40
+ ├── TexturePool.ts # Temporary texture pooling / 一時テクスチャプーリング
41
+ ├── FillTexturePool.ts # Fill/gradient texture pooling / 塗り/グラデーションテクスチャプーリング
42
+ ├── SamplerCache.ts # GPU sampler caching / GPUサンプラーキャッシュ
43
+ ├── Blend.ts # Blend mode handling / ブレンドモード処理
44
+ ├── Blend/
45
+ └── BlendInstancedManager.ts # Blend instanced rendering / ブレンドインスタンスレンダリング
46
+ ├── Mask.ts # Stencil-based masking / ステンシルベースのマスキング
47
+ ├── Mesh/ # Mesh generation / メッシュ生成
48
+ │ ├── service/ # Mesh services / メッシュサービス
49
+ │ └── usecase/ # Mesh use cases (fill, stroke, gradient stroke) / メッシュユースケース
50
+ ├── PathCommand.ts # Path command processing / パスコマンド処理
51
+ ├── Compute/ # GPU compute shader execution / GPUコンピュートシェーダー実行
52
+ │ ├── ComputePipelineManager.ts # Compute pipeline management / コンピュートパイプライン管理
53
+ └── ComputeExecuteBlurService.ts # Blur compute execution / ブラーコンピュート実行
54
+ ├── Filter/ # Filter implementations / フィルター実装
55
+ │ ├── FilterGradientLUTCache.ts # Gradient LUT cache / グラデーションLUTキャッシュ
56
+ ├── FilterOffset.ts # Filter offset calculation / フィルターオフセット計算
57
+ │ ├── BitmapFilterShader.ts # Bitmap filter shader / ビットマップフィルターシェーダー
58
+ │ ├── BevelFilter/ # Bevel filter / ベベルフィルター
59
+ │ ├── BlurFilter/ # Blur filter / ブラーフィルター
60
+ │ ├── ColorMatrixFilter/ # Color matrix filter / カラーマトリックスフィルター
61
+ │ ├── ConvolutionFilter/ # Convolution filter / コンボリューションフィルター
62
+ │ ├── DisplacementMapFilter/ # Displacement map filter / ディスプレースメントマップフィルター
63
+ ├── DropShadowFilter/ # Drop shadow filter / ドロップシャドウフィルター
64
+ ├── GlowFilter/ # Glow filter / グローフィルター
65
+ │ ├── GradientBevelFilter/ # Gradient bevel filter / グラデーションベベルフィルター
66
+ └── GradientGlowFilter/ # Gradient glow filter / グラデーショングローフィルター
67
+ ├── Gradient/
68
+ └── GradientLUTGenerator.ts # Gradient LUT generation and caching / グラデーションLUT生成とキャッシュ
69
+ ├── Shader/ # WGSL shader system / WGSLシェーダーシステム
70
+ │ ├── PipelineManager.ts # Render pipeline management / レンダーパイプライン管理
71
+ │ ├── ShaderSource.ts # Shader source management / シェーダーソース管理
72
+ │ ├── ShaderInstancedManager.ts # Instanced rendering manager / インスタンスレンダリング管理
73
+ ├── BlendModeShader.ts # Blend mode shader definitions / ブレンドモードシェーダー定義
74
+ ├── GradientLUTGenerator/ # Gradient LUT generation / グラデーションLUT生成
75
+ │ │ ├── service/ # LUT generation services / LUT生成サービス
76
+ │ └── usecase/ # LUT generation use cases / LUT生成ユースケース
77
+ └── wgsl/ # WGSL shader sources / WGSLシェーダーソース
78
+ ├── vertex/ # Vertex shaders / バーテックスシェーダー
79
+ ├── fragment/ # Fragment shaders / フラグメントシェーダー
80
+ │ └── common/ # Shared WGSL utilities / 共有WGSLユーティリティ
81
+ ├── Grid.ts # Grid system for rendering / レンダリング用グリッドシステム
82
+ ├── BezierConverter/ # Bezier curve conversion / ベジェ曲線変換
83
+ │ ├── BezierConverter.ts # Main class / メインクラス
84
+ │ ├── service/ # BezierConverter services / サービス
85
+ │ └── usecase/ # BezierConverter use cases / ユースケース
86
+ ├── TexturePool/ # Temporary texture pooling services / 一時テクスチャプーリングサービス
87
+ │ ├── service/ # TexturePool services / サービス
88
+ └── usecase/ # TexturePool use cases / ユースケース
89
+ ├── WebGPUUtil.ts # WebGPU utility functions / WebGPUユーティリティ関数
90
+ └── interface/ # TypeScript interfaces / TypeScript インターフェース
169
91
  ```
170
92
 
171
- ---
172
-
173
- ## Implementation Status / 実装状況
174
-
175
- ### ✅ Implemented / 実装済み
176
-
177
- #### Core Rendering / コア描画機能
178
- - ✅ Basic initialization and device setup (基本的な初期化とデバイスセットアップ)
179
- - ✅ Canvas context configuration (キャンバスコンテキストの設定)
180
- - ✅ Frame lifecycle management (beginFrame/endFrame) (フレームライフサイクル管理)
181
- - ✅ Transform matrix operations (save/restore/setTransform/transform) (変換行列操作)
182
- - ✅ Background color fill (背景色の塗りつぶし)
183
- - ✅ Resize handling (リサイズ処理)
184
-
185
- #### Path Drawing / パス描画
186
- - ✅ Path commands (beginPath, moveTo, lineTo, closePath) (パスコマンド)
187
- - ✅ Bezier curves (quadraticCurveTo, bezierCurveTo) (ベジェ曲線)
188
- - ✅ Arc drawing (円弧描画)
189
- - Fill operations with solid colors (単色塗りつぶし)
190
- - ✅ Stroke operations with mesh generation (ストローク描画とメッシュ生成)
191
- - Vertex triangulation for path filling (パス塗りつぶし用の頂点三角形分割)
192
-
193
- #### Texture & Atlas Management / テクスチャ・アトラス管理
194
- - Atlas texture creation (4096x4096) (アトラステクスチャ作成)
195
- - Node allocation in texture atlas (テクスチャアトラスのノード割り当て)
196
- - ✅ Texture from pixels/ImageBitmap (ピクセル/ImageBitmapからのテクスチャ作成)
197
- - Sampler creation (linear, nearest, repeat) (サンプラー作成)
198
- - Texture pool management (テクスチャプール管理)
199
-
200
- #### Buffer Management / バッファ管理
201
- - Vertex buffer creation and management (頂点バッファ作成と管理)
202
- - Uniform buffer creation and updates (Uniformバッファ作成と更新)
203
- - Rectangle vertex generation (矩形頂点生成)
204
-
205
- #### Offscreen Rendering / オフスクリーンレンダリング
206
- - Attachment object pool (アタッチメントオブジェクトプール)
207
- - Bind/unbind attachment operations (アタッチメントのバインド/アンバインド)
208
- - Render target switching (レンダーターゲットの切り替え)
209
- - ✅ Stencil texture creation (ステンシルテクスチャ作成)
210
-
211
- #### Shader Pipelines / シェーダーパイプライン
212
- - ✅ Fill pipeline (solid color) (単色塗りつぶしパイプライン)
213
- - ✅ Mask pipeline (Bezier curve anti-aliasing) (マスクパイプライン - ベジェ曲線アンチエイリアス)
214
- - ✅ Basic pipeline (基本パイプライン)
215
- - ✅ Texture pipeline (テクスチャパイプライン)
216
- - ✅ Instanced rendering pipeline (インスタンス描画パイプライン)
217
- - ✅ Gradient pipeline structure (グラデーションパイプライン構造)
218
- - ✅ Blend mode pipeline structure (ブレンドモードパイプライン構造)
219
-
220
- #### Instance Rendering / インスタンス描画
221
- - ✅ Instance data management (インスタンスデータ管理)
222
- - ✅ Display object to instance array conversion (表示オブジェクトのインスタンス配列変換)
223
- - ✅ Batch rendering with instancing (インスタンシングによるバッチ描画)
224
- - ✅ Color transform (multiply/add) (カラー変換 - 乗算/加算)
225
-
226
- #### Image Operations / 画像操作
227
- - ✅ Draw pixels to atlas node (アトラスノードへのピクセル描画)
228
- - ✅ Draw OffscreenCanvas/ImageBitmap to atlas (OffscreenCanvas/ImageBitmapのアトラス描画)
229
- - ✅ Create ImageBitmap from GPU texture (GPUテクスチャからのImageBitmap作成)
230
- - ✅ Premultiplied alpha conversion (プリマルチプライドアルファ変換)
231
-
232
- ### 🚧 Partially Implemented / 部分的に実装
233
-
234
- #### Drawing Operations / 描画操作
235
- - 🚧 Gradient fill (gradientFill) - Placeholder, falls back to solid fill
236
- - グラデーション塗りつぶし - プレースホルダー実装、単色塗りつぶしにフォールバック
237
- - 🚧 Bitmap fill (bitmapFill) - Texture creation works, shader integration pending
238
- - ビットマップ塗りつぶし - テクスチャ作成は動作、シェーダー統合は保留
239
- - 🚧 Gradient stroke (gradientStroke) - Placeholder
240
- - グラデーションストローク - プレースホルダー実装
241
- - 🚧 Bitmap stroke (bitmapStroke) - Placeholder
242
- - ビットマップストローク - プレースホルダー実装
243
-
244
- #### Masking / マスク処理
245
- - 🚧 Clip operations (clip) - Basic structure, stencil buffer integration needed
246
- - クリッピング操作 - 基本構造はあるが、ステンシルバッファ統合が必要
247
- - 🚧 Mask begin/end (beginMask, endMask, setMaskBounds, leaveMask) - Service layer exists
248
- - マスク開始/終了 - サービス層は存在
249
-
250
- #### Filters / フィルター
251
- - 🚧 applyFilter - Framework exists, filter shaders created but not integrated
252
- - フィルター適用 - フレームワークは存在、フィルターシェーダーは作成済みだが統合されていない
253
- - BlurFilterShader, GlowFilterShader, DropShadowFilterShader, ColorMatrixFilterShader
254
-
255
- ### ❌ TODO / 未実装
256
-
257
- #### Core Features / コア機能
258
- - ❌ Cache clearing implementation (resize時のキャッシュクリア)
259
- - ❌ clearRect with scissor/clear operations (シザー/クリア操作によるclearRect)
260
- - ❌ 9-slice grid transformation (useGrid) (9スライスグリッド変換)
261
-
262
- #### Advanced Rendering / 高度なレンダリング
263
- - ❌ Complete gradient LUT texture generation (完全なグラデーションLUTテクスチャ生成)
264
- - ❌ Gradient shader parameter passing (グラデーションシェーダーのパラメータ渡し)
265
- - ❌ Bitmap fill/stroke shader integration (ビットマップ塗りつぶし/ストロークシェーダー統合)
266
- - ❌ Stencil buffer-based clipping (ステンシルバッファベースのクリッピング)
267
- - ❌ Two-pass rendering for masks (マスク用の2パスレンダリング)
268
-
269
- #### Blend Modes / ブレンドモード
270
- - ❌ Full blend mode integration (multiply, screen, add, etc.)
271
- - 完全なブレンドモード統合(乗算、スクリーン、加算など)
272
- - ❌ Advanced blend modes (overlay, hard-light, soft-light, etc.)
273
- - 高度なブレンドモード(オーバーレイ、ハードライト、ソフトライトなど)
274
-
275
- #### Filters / フィルター
276
- - ❌ Filter parameter binding and execution (フィルターパラメータバインディングと実行)
277
- - ❌ Multi-pass filter rendering (複数パスフィルターレンダリング)
278
- - ❌ Convolution filter (コンボリューションフィルター)
279
- - ❌ Displacement map filter (ディスプレイスメントマップフィルター)
280
-
281
- #### Optimization / 最適化
282
- - ❌ Buffer reuse and pooling optimization (バッファ再利用とプール最適化)
283
- - ❌ Command encoder reuse (コマンドエンコーダー再利用)
284
- - ❌ Pipeline state caching (パイプライン状態キャッシング)
285
- - ❌ Batch draw call optimization (バッチ描画コール最適化)
286
-
287
- #### Testing & Documentation / テストとドキュメント
288
- - ❌ Unit tests (ユニットテスト)
289
- - ❌ Integration tests (統合テスト)
290
- - ❌ Performance benchmarks (パフォーマンスベンチマーク)
291
- - ❌ API documentation (API ドキュメント)
292
-
293
- ---
294
-
295
- ## Context.ts - Implementation Analysis / Context.ts 実装分析
296
-
297
- The `Context.ts` file is the main entry point for the WebGPU rendering engine. Here's a detailed breakdown of its implementation status:
298
-
299
- `Context.ts` ファイルは WebGPU レンダリングエンジンのメインエントリーポイントです。実装状況の詳細な内訳は以下の通りです:
300
-
301
- ### Fully Implemented Methods / 完全実装済みメソッド
302
-
303
- | Method | Status | Notes |
304
- |--------|--------|-------|
305
- | `constructor` | ✅ Complete | Device, context, format initialization |
306
- | `save` / `restore` | ✅ Complete | Matrix stack operations |
307
- | `setTransform` / `transform` | ✅ Complete | 2D transformation matrix |
308
- | `reset` | ✅ Complete | Reset context state |
309
- | `beginPath` / `moveTo` / `lineTo` | ✅ Complete | Path command delegation |
310
- | `quadraticCurveTo` / `bezierCurveTo` | ✅ Complete | Bezier curve support |
311
- | `arc` / `closePath` | ✅ Complete | Path operations |
312
- | `fillStyle` / `strokeStyle` | ✅ Complete | Color style setters |
313
- | `fill` | ✅ Complete | Solid color fill with pipeline |
314
- | `stroke` | ✅ Complete | Stroke with mesh generation |
315
- | `updateBackgroundColor` | ✅ Complete | Background color update |
316
- | `fillBackgroundColor` | ✅ Complete | Clear with background color |
317
- | `resize` | ✅ Complete | Canvas resize (cache clear TODO) |
318
- | `beginFrame` / `endFrame` | ✅ Complete | Frame lifecycle management |
319
- | `bindAttachment` / `unbindAttachment` | ✅ Complete | Offscreen rendering |
320
- | `getAttachmentObject` / `releaseAttachment` | ✅ Complete | Attachment management |
321
- | `createNode` / `removeNode` | ✅ Complete | Atlas node management |
322
- | `drawPixels` / `drawElement` | ✅ Complete | Pixel/element to atlas |
323
- | `drawDisplayObject` | ✅ Complete | Instance array addition |
324
- | `drawArraysInstanced` | ✅ Complete | Batch instance rendering |
325
- | `clearArraysInstanced` | ✅ Complete | Clear instance data |
326
- | `createImageBitmap` | ✅ Complete | GPU→ImageBitmap conversion |
327
- | `beginMask` / `setMaskBounds` / `endMask` / `leaveMask` | ✅ Complete | Mask service delegation |
328
-
329
- ### Placeholder / Incomplete Methods / プレースホルダー/不完全なメソッド
330
-
331
- | Method | Status | Notes |
332
- |--------|--------|-------|
333
- | `clearRect` | 🚧 Partial | Has console.log, needs scissor+clear implementation |
334
- | `gradientFill` | 🚧 Placeholder | console.log + falls back to fill() |
335
- | `bitmapFill` | 🚧 Partial | Creates texture but falls back to fill() |
336
- | `gradientStroke` | 🚧 Placeholder | console.log + falls back to stroke() |
337
- | `bitmapStroke` | 🚧 Placeholder | console.log + falls back to stroke() |
338
- | `clip` | 🚧 Placeholder | console.log + falls back to fill() |
339
- | `useGrid` | 🚧 Placeholder | console.log, 9-slice not implemented |
340
- | `applyFilter` | 🚧 Placeholder | console.log, filter shaders not integrated |
341
-
342
- ### Debug Markers / デバッグマーカー
343
-
344
- The code contains multiple `console.log` statements indicating work-in-progress areas:
345
-
346
- コードには開発中の領域を示す複数の `console.log` 文が含まれています:
347
-
348
- - Line 250: `clearRect()` - "TODO: シザーとクリアを使用した実装"
349
- - Line 228: `resize()` - "TODO: キャッシュクリア実装"
350
- - Line 270: `clearRect()` - "TODO: シザーとクリアを使用した実装"
351
- - Line 781: `gradientFill()` - "TODO: グラデーションLUTテクスチャを生成"
352
- - Line 790: `gradientFill()` - "TODO: グラデーション用のシェーダーを使用"
353
- - Line 847: `bitmapFill()` - "TODO: ビットマップ塗りつぶし用のシェーダーを使用"
354
- - Line 876: `gradientStroke()` - "TODO: グラデーションストローク実装"
355
- - Line 901: `bitmapStroke()` - "TODO: ビットマップストローク実装"
356
- - Line 918: `clip()` - "TODO: ステンシルバッファを使用したクリッピング実装"
357
- - Line 962: `useGrid()` - "TODO: Grid/9-slice transformation implementation"
358
- - Line 1312-1320: `applyFilter()` - Multiple filter TODOs
359
- - Line 1660: `leaveMask()` - "TODO: WebGPU版のインスタンス描画を実装後に追加"
360
-
361
- ---
362
-
363
- ## Shader Implementation / シェーダー実装
364
-
365
- ### WGSL Shaders in ShaderSource.ts / ShaderSource.ts の WGSL シェーダー
366
-
367
- The package includes complete WGSL shader implementations for:
368
-
369
- パッケージには以下の完全な WGSL シェーダー実装が含まれています:
370
-
371
- 1. **Fill Shader** (単色塗りつぶし)
372
- - WebGL-compatible vertex transformation
373
- - Premultiplied alpha blending
374
- - Viewport normalization
375
-
376
- 2. **Mask Shader** (マスク)
377
- - Bezier curve rendering with anti-aliasing
378
- - Partial derivative-based edge smoothing
379
-
380
- 3. **Texture Shader** (テクスチャ)
381
- - Sampled texture rendering
382
- - Color modulation
383
-
384
- 4. **Instanced Shader** (インスタンス描画)
385
- - Per-instance transformation matrices
386
- - Color transform (multiply + add)
387
- - Atlas texture sampling
388
- - Unpremultiply → transform → premultiply workflow
389
-
390
- 5. **Gradient Shader** (グラデーション) - Structure only
391
- - Linear/Radial gradient support
392
- - LUT-based color lookup
393
-
394
- 6. **Blend Shader** (ブレンド) - Structure only
395
- - Normal, Multiply, Screen, Add modes
396
- - Dual texture sampling
397
-
398
- ---
399
-
400
- ## Pipeline Architecture / パイプラインアーキテクチャ
401
-
402
- The `PipelineManager` creates and manages 6 render pipelines:
403
-
404
- `PipelineManager` は 6 つのレンダーパイプラインを作成・管理します:
405
-
406
- 1. **fill** - Solid color fill (単色塗りつぶし)
407
- 2. **mask** - Stencil/clip operations (ステンシル/クリップ操作)
408
- 3. **basic** - Simple color rendering (シンプルカラーレンダリング)
409
- 4. **texture** - Textured quad rendering (テクスチャ付き矩形レンダリング)
410
- 5. **instanced** - Batch instance rendering (バッチインスタンス描画)
411
- 6. **gradient** - Gradient fill (グラデーション塗りつぶし) - Not yet integrated
412
- 7. **blend** - Blend mode operations (ブレンドモード操作) - Not yet integrated
413
-
414
- All pipelines use:
415
- - Premultiplied alpha blending
416
- - Triangle list topology
417
- - No backface culling
418
-
419
- すべてのパイプラインは以下を使用:
420
- - プリマルチプライドアルファブレンディング
421
- - トライアングルリストトポロジー
422
- - バックフェースカリング無効
93
+ ## Rendering Pipeline / レンダリングパイプライン
94
+
95
+ The WebGPU package implements a sophisticated rendering pipeline that processes graphics commands through multiple stages:
96
+
97
+ WebGPUパッケージは、複数のステージを通じてグラフィックスコマンドを処理する洗練されたレンダリングパイプラインを実装しています:
98
+
99
+ ```mermaid
100
+ flowchart TB
101
+ Start([Start Rendering])
102
+ Context[Context<br/>レンダリングコンテキスト]
103
+ PathCommand[PathCommand<br/>パスコマンド処理]
104
+ Mesh[Mesh<br/>メッシュ生成]
105
+ Shader[Shader<br/>シェーダー実行]
106
+ FrameBuffer[FrameBuffer<br/>レンダーターゲット]
107
+ Atlas[AtlasManager<br/>テクスチャアトラス]
108
+ Filter[Filter<br/>フィルター処理]
109
+ Blend[Blend<br/>ブレンド処理]
110
+ Mask[Mask<br/>マスク処理]
111
+ Output([Output to Canvas])
112
+
113
+ Start --> Context
114
+ Context --> PathCommand
115
+ PathCommand --> Mesh
116
+ Mesh --> Shader
117
+ Shader --> FrameBuffer
118
+
119
+ Context -.-> Atlas
120
+ Atlas -.-> Shader
121
+
122
+ FrameBuffer --> Filter
123
+ Filter --> Blend
124
+ Blend --> Mask
125
+ Mask --> Output
126
+
127
+ style Context fill:#e1f5ff
128
+ style Shader fill:#fff4e1
129
+ style FrameBuffer fill:#f0e1ff
130
+ style Atlas fill:#e1ffe1
131
+ ```
423
132
 
424
- ---
133
+ ### Pipeline Stages / パイプラインステージ
425
134
 
426
- ## Known Limitations / 既知の制限事項
135
+ 1. **Context**: Main rendering context that manages the WebGPU state and coordinates all rendering operations
136
+ - **コンテキスト**: WebGPU状態を管理し、すべてのレンダリング操作を調整するメインレンダリングコンテキスト
427
137
 
428
- 1. **Stencil Operations** - Depth-stencil attachment configuration incomplete
429
- - ステンシル操作 - Depth-stencilアタッチメント設定が不完全
138
+ 2. **PathCommand**: Processes vector path commands (moveTo, lineTo, curveTo, etc.) into renderable primitives
139
+ - **パスコマンド**: ベクターパスコマンド(moveTo、lineTo、curveToなど)をレンダリング可能なプリミティブに処理
430
140
 
431
- 2. **Filter Effects** - Shader code exists but parameter passing not implemented
432
- - フィルター効果 - シェーダーコードは存在するがパラメータ渡しが未実装
141
+ 3. **Mesh**: Generates triangle meshes from path data for fills and strokes
142
+ - **メッシュ**: 塗りと線のパスデータから三角形メッシュを生成
433
143
 
434
- 3. **Blend Modes** - Only normal blend mode fully functional
435
- - ブレンドモード - ノーマルブレンドモードのみ完全に機能
144
+ 4. **Shader**: Executes WGSL shaders to render meshes with appropriate materials and effects
145
+ - **シェーダー**: 適切なマテリアルとエフェクトでメッシュをレンダリングするWGSLシェーダーを実行
436
146
 
437
- 4. **Gradient Rendering** - LUT generation incomplete
438
- - グラデーションレンダリング - LUT生成が不完全
147
+ 5. **FrameBuffer**: Manages render targets and intermediate rendering buffers
148
+ - **フレームバッファ**: レンダーターゲットと中間レンダリングバッファを管理
439
149
 
440
- 5. **Performance** - No optimization for buffer reuse, pipeline caching
441
- - パフォーマンス - バッファ再利用、パイプラインキャッシングの最適化なし
150
+ 6. **AtlasManager**: Optimizes texture usage through texture atlas packing
151
+ - **アトラスマネージャー**: テクスチャアトラスパッキングによりテクスチャ使用を最適化
442
152
 
443
- 6. **Error Handling** - Limited validation and error recovery
444
- - エラーハンドリング - 検証とエラー回復が制限的
153
+ 7. **Filter**: Applies post-processing effects (blur, glow, color matrix, etc.)
154
+ - **フィルター**: ポストプロセスエフェクト(ブラー、グロー、カラーマトリックスなど)を適用
445
155
 
446
- ---
156
+ 8. **Blend**: Handles blend mode operations for compositing
157
+ - **ブレンド**: 合成のためのブレンドモード操作を処理
447
158
 
448
- ## Development Notes / 開発ノート
159
+ 9. **Mask**: Implements stencil-based masking for clipping and complex shapes
160
+ - **マスク**: クリッピングと複雑な形状のためのステンシルベースのマスキングを実装
449
161
 
450
- ### Architecture / アーキテクチャ
162
+ ## Atlas-Based Rendering Approach / アトラスベースのレンダリングアプローチ
451
163
 
452
- The package follows a manager-based architecture similar to the WebGL implementation:
164
+ The WebGPU package uses a texture atlas system to optimize rendering performance:
453
165
 
454
- パッケージは WebGL 実装と同様のマネージャーベースアーキテクチャに従います:
166
+ WebGPUパッケージは、レンダリングパフォーマンスを最適化するためにテクスチャアトラスシステムを使用しています:
455
167
 
456
- - **Context**: Main rendering interface (メインレンダリングインターフェース)
457
- - **Managers**: Resource lifecycle management (リソースライフサイクル管理)
458
- - **Services/UseCases**: Business logic separation (ビジネスロジック分離)
459
- - **Shaders**: WGSL source and pipeline configuration (WGSL ソースとパイプライン設定)
168
+ ### Benefits / 利点
460
169
 
461
- ### Frame Lifecycle / フレームライフサイクル
170
+ - **Reduced draw calls**: Multiple textures are packed into a single atlas, reducing the number of texture bindings
171
+ - **描画コールの削減**: 複数のテクスチャが単一のアトラスにパックされ、テクスチャバインディングの数が削減されます
462
172
 
463
- ```
464
- clearTransferBounds()
465
- → beginFrame()
466
- → [drawing operations]
467
- → endFrame()/transferMainCanvas()
468
- ```
173
+ - **Memory efficiency**: Optimal packing algorithm minimizes wasted GPU memory
174
+ - **メモリ効率**: 最適なパッキングアルゴリズムにより、無駄なGPUメモリが最小化されます
469
175
 
470
- ### Rendering Flow / レンダリングフロー
176
+ - **Cache coherency**: Better GPU cache utilization through spatial locality
177
+ - **キャッシュコヒーレンシー**: 空間的局所性による優れたGPUキャッシュ利用
471
178
 
472
- 1. Acquire canvas texture (once per frame) (キャンバステクスチャ取得 - フレーム毎に1回)
473
- 2. Create command encoder (コマンドエンコーダー作成)
474
- 3. Begin render pass with load/clear (ロード/クリアでレンダーパス開始)
475
- 4. Set pipeline and bind resources (パイプライン設定とリソースバインド)
476
- 5. Draw commands (描画コマンド)
477
- 6. End render pass (レンダーパス終了)
478
- 7. Submit commands to queue (コマンドをキューに送信)
179
+ ### Atlas Management / アトラス管理
479
180
 
480
- ---
181
+ The `AtlasManager` component uses the `@next2d/texture-packer` package to:
481
182
 
482
- ## Browser Compatibility / ブラウザ互換性
183
+ `AtlasManager`コンポーネントは`@next2d/texture-packer`パッケージを使用して以下を実行します:
483
184
 
484
- WebGPU support is required. As of 2024:
185
+ - Dynamically pack textures into optimal atlas layouts
186
+ - テクスチャを最適なアトラスレイアウトに動的にパック
187
+ - Track texture usage and automatically manage atlas allocation
188
+ - テクスチャ使用状況を追跡し、アトラス割り当てを自動管理
189
+ - Support multiple atlas instances when texture requirements exceed single atlas capacity
190
+ - テクスチャ要件が単一のアトラス容量を超える場合、複数のアトラスインスタンスをサポート
485
191
 
486
- WebGPU サポートが必要です。2024年時点:
192
+ ### Rendering with Atlases / アトラスを使用したレンダリング
487
193
 
488
- - Chrome/Edge 113+
489
- - ✅ Firefox 131+ (experimental)
490
- - ✅ Safari 18+ (experimental)
491
- - ❌ Older browsers (need WebGL fallback)
194
+ 1. Textures are uploaded to GPU and registered with the atlas manager
195
+ - テクスチャがGPUにアップロードされ、アトラスマネージャーに登録されます
492
196
 
493
- ---
197
+ 2. The atlas manager assigns UV coordinates for each texture region
198
+ - アトラスマネージャーが各テクスチャ領域のUV座標を割り当てます
494
199
 
495
- ## Usage / 使用方法
200
+ 3. Shaders use these UV coordinates to sample from the correct atlas region
201
+ - シェーダーがこれらのUV座標を使用して正しいアトラス領域からサンプリングします
496
202
 
497
- ```typescript
498
- import { Context } from "@next2d/webgpu";
203
+ 4. Multiple objects can be rendered in a single draw call using the same atlas
204
+ - 同じアトラスを使用して複数のオブジェクトを単一の描画コールでレンダリング可能
499
205
 
500
- // Get WebGPU adapter and device
501
- const adapter = await navigator.gpu.requestAdapter();
502
- const device = await adapter.requestDevice();
206
+ ## Architecture Patterns / アーキテクチャパターン
503
207
 
504
- // Get canvas context
505
- const canvas = document.getElementById("canvas") as HTMLCanvasElement;
506
- const context = canvas.getContext("webgpu") as GPUCanvasContext;
208
+ The codebase follows a clean architecture approach with clear separation of concerns:
507
209
 
508
- // Get preferred format
509
- const format = navigator.gpu.getPreferredCanvasFormat();
210
+ コードベースは、関心事の明確な分離を伴うクリーンアーキテクチャアプローチに従っています:
510
211
 
511
- // Create rendering context
512
- const ctx = new Context(device, context, format);
212
+ ### Service Layer / サービス層
513
213
 
514
- // Rendering
515
- ctx.clearTransferBounds(); // Begin frame
516
- ctx.fillStyle(1, 0, 0, 1); // Red
517
- ctx.beginPath();
518
- ctx.arc(100, 100, 50);
519
- ctx.fill();
520
- ctx.transferMainCanvas(); // End frame and submit
521
- ```
214
+ Services contain low-level operations and business logic. They are pure functions that perform specific tasks.
522
215
 
523
- ---
216
+ サービスは低レベルの操作とビジネスロジックを含みます。特定のタスクを実行する純粋な関数です。
524
217
 
525
- ## Contributing / 貢献
218
+ ### Use Case Layer / ユースケース層
526
219
 
527
- As this package is work in progress, contributions are welcome! Priority areas:
220
+ Use cases orchestrate multiple services to accomplish higher-level operations. They represent application-specific business rules.
528
221
 
529
- このパッケージは開発中のため、貢献を歓迎します!優先領域:
222
+ ユースケースは、より高レベルの操作を達成するために複数のサービスを調整します。アプリケーション固有のビジネスルールを表します。
530
223
 
531
- 1. Completing gradient and bitmap fill/stroke shaders
532
- 2. Implementing filter parameter binding
533
- 3. Stencil-based masking operations
534
- 4. Performance optimization (buffer pooling, pipeline caching)
535
- 5. Comprehensive testing
224
+ ## Dependencies / 依存関係
536
225
 
537
- ---
226
+ - `@next2d/texture-packer`: Texture atlas packing and management / テクスチャアトラスのパッキングと管理
227
+ - `@next2d/render-queue`: Rendering operation queue management / レンダリング操作キュー管理
538
228
 
539
229
  ## License / ライセンス
540
230
 
541
- MIT License
542
-
543
- Copyright (c) 2021 Next2D
544
-
545
- Permission is hereby granted, free of charge, to any person obtaining a copy
546
- of this software and associated documentation files (the "Software"), to deal
547
- in the Software without restriction, including without limitation the rights
548
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
549
- copies of the Software, and to permit persons to whom the Software is
550
- furnished to do so, subject to the following conditions:
551
-
552
- The above copyright notice and this permission notice shall be included in all
553
- copies or substantial portions of the Software.
554
-
555
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
556
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
557
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
558
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
559
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
560
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
561
- SOFTWARE.
562
-
563
- ---
564
-
565
- ## Related Packages / 関連パッケージ
566
-
567
- - `@next2d/texture-packer` - Texture atlas management
568
- - `@next2d/render-queue` - Render queue for batch operations
569
-
570
- ---
571
-
572
- **Last Updated**: 2024-12-08
231
+ This project is licensed under the [MIT License](https://opensource.org/licenses/MIT) - see the [LICENSE](LICENSE) file for details.
573
232
 
574
- **Status**: 🚧 Experimental - Active Development
233
+ このプロジェクトは[MITライセンス](https://opensource.org/licenses/MIT)の下でライセンスされています - 詳細は[LICENSE](LICENSE)ファイルを参照してください。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next2d/webgpu",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Next2D WebGPU Package",
5
5
  "author": "Toshiyuki Ienaga<ienaga@next2d.app> (https://github.com/ienaga/)",
6
6
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  "url": "git+https://github.com/Next2D/Player.git"
25
25
  },
26
26
  "dependencies": {
27
- "@next2d/texture-packer": "3.0.0",
28
- "@next2d/render-queue": "3.0.0"
27
+ "@next2d/texture-packer": "3.0.1",
28
+ "@next2d/render-queue": "3.0.1"
29
29
  }
30
30
  }