@next2d/webgpu 3.11.1 → 3.12.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 (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
@@ -154,6 +154,11 @@ export declare class PipelineManager {
154
154
  * Create texture copy pipelines (various blend modes, filter output, MSAA variants)
155
155
  */
156
156
  private createTextureCopyPipeline;
157
+ /**
158
+ * @description キャッシュ色変換の初回使用時だけ専用パイプラインを作成する
159
+ * Create fused cached CT pipelines only on first use
160
+ */
161
+ private createCachedColorTransformPipelines;
157
162
  /**
158
163
  * @description 位置指定テクスチャ描画用パイプラインを作成する(RGBA/ビットマップレンダー対応)
159
164
  * Create positioned texture pipelines (RGBA, bitmap render, MSAA variants)
@@ -27,6 +27,13 @@ const $BLEND_PREMULTIPLIED_ALPHA = {
27
27
  "operation": "add"
28
28
  }
29
29
  };
30
+ // Shared by ordinary output and the fused cached ColorTransform output.
31
+ const $FILTER_OUTPUT_BLEND_VARIANTS = [
32
+ ["filter_output_add", { "color": { "srcFactor": "one", "dstFactor": "one", "operation": "add" }, "alpha": { "srcFactor": "one", "dstFactor": "one", "operation": "add" } }],
33
+ ["filter_output_screen", { "color": { "srcFactor": "one", "dstFactor": "one-minus-src", "operation": "add" }, "alpha": { "srcFactor": "one", "dstFactor": "one-minus-src-alpha", "operation": "add" } }],
34
+ ["filter_output_alpha", { "color": { "srcFactor": "zero", "dstFactor": "src-alpha", "operation": "add" }, "alpha": { "srcFactor": "zero", "dstFactor": "src-alpha", "operation": "add" } }],
35
+ ["filter_output_erase", { "color": { "srcFactor": "zero", "dstFactor": "one-minus-src-alpha", "operation": "add" }, "alpha": { "srcFactor": "zero", "dstFactor": "one-minus-src-alpha", "operation": "add" } }]
36
+ ];
30
37
  /**
31
38
  * @description WebGPUレンダーパイプラインの管理クラス。パイプラインとバインドグループレイアウトの生成・キャッシュを行う
32
39
  * Manager class for WebGPU render pipelines. Creates, caches, and manages pipelines and bind group layouts
@@ -139,6 +146,7 @@ export class PipelineManager {
139
146
  ["filter_output_msaa", "texture_copy"], ["filter_output_add_msaa", "texture_copy"],
140
147
  ["filter_output_screen_msaa", "texture_copy"], ["filter_output_alpha_msaa", "texture_copy"],
141
148
  ["filter_output_erase_msaa", "texture_copy"],
149
+ ...["", "_add", "_screen", "_alpha", "_erase"].flatMap((suffix) => ["", "_msaa"].map((msaa) => [`cached_ct${suffix}${msaa}`, "cached_ct"])),
142
150
  ["filter_output_masked", "texture_copy"], ["filter_output_masked_msaa", "texture_copy"],
143
151
  ["positioned_texture", "texture_copy"], ["positioned_texture_rgba", "texture_copy"],
144
152
  ["bitmap_render_msaa", "texture_copy"], ["bitmap_render", "texture_copy"],
@@ -149,6 +157,9 @@ export class PipelineManager {
149
157
  ["bevel_filter", "filter"], ["gradient_glow_filter", "filter"],
150
158
  ["gradient_bevel_filter", "filter"],
151
159
  ["complex_blend", "complex_blend"],
160
+ ["complex_blend_region", "complex_blend"],
161
+ ["complex_blend_region_msaa", "complex_blend"],
162
+ ["complex_blend_msaa", "complex_blend"],
152
163
  ["complex_blend_copy", "complex_blend"],
153
164
  ["complex_blend_scale", "complex_blend"], ["complex_blend_output", "complex_blend"],
154
165
  ["complex_blend_output_msaa", "complex_blend"],
@@ -254,6 +265,9 @@ export class PipelineManager {
254
265
  case "texture_copy":
255
266
  this.createTextureCopyPipeline();
256
267
  break;
268
+ case "cached_ct":
269
+ this.createCachedColorTransformPipelines();
270
+ break;
257
271
  case "bitmap_sync":
258
272
  this.createBitmapSyncPipeline();
259
273
  break;
@@ -270,7 +284,7 @@ export class PipelineManager {
270
284
  * Preload all lazy initialization groups eagerly
271
285
  */
272
286
  preloadLazyGroups() {
273
- const groups = ["blur_filter", "texture_copy", "bitmap_sync", "filter", "complex_blend"];
287
+ const groups = ["blur_filter", "texture_copy", "bitmap_sync", "filter", "complex_blend", "cached_ct"];
274
288
  for (const group of groups) {
275
289
  this.ensureLazyGroup(group);
276
290
  }
@@ -2245,12 +2259,7 @@ export class PipelineManager {
2245
2259
  this.pipelines.set("texture_copy_bgra", this.createFullscreenQuadPipeline(pipelineLayout, vertexShaderModule, fragmentShaderModule, this.format, BLEND_REPLACE));
2246
2260
  const filterOutputShaderModule = this.getOrCreateShaderModule("filterOutputFragment", ShaderSource.getFilterOutputFragmentShader());
2247
2261
  this.pipelines.set("filter_output", this.createFullscreenQuadPipeline(pipelineLayout, vertexShaderModule, filterOutputShaderModule, this.format, BLEND_ALPHA));
2248
- const filterOutputBlendVariants = [
2249
- ["filter_output_add", { "color": { "srcFactor": "one", "dstFactor": "one", "operation": "add" }, "alpha": { "srcFactor": "one", "dstFactor": "one", "operation": "add" } }],
2250
- ["filter_output_screen", { "color": { "srcFactor": "one", "dstFactor": "one-minus-src", "operation": "add" }, "alpha": { "srcFactor": "one", "dstFactor": "one-minus-src-alpha", "operation": "add" } }],
2251
- ["filter_output_alpha", { "color": { "srcFactor": "zero", "dstFactor": "src-alpha", "operation": "add" }, "alpha": { "srcFactor": "zero", "dstFactor": "src-alpha", "operation": "add" } }],
2252
- ["filter_output_erase", { "color": { "srcFactor": "zero", "dstFactor": "one-minus-src-alpha", "operation": "add" }, "alpha": { "srcFactor": "zero", "dstFactor": "one-minus-src-alpha", "operation": "add" } }]
2253
- ];
2262
+ const filterOutputBlendVariants = $FILTER_OUTPUT_BLEND_VARIANTS;
2254
2263
  for (const [name, blend] of filterOutputBlendVariants) {
2255
2264
  this.pipelines.set(name, this.createFullscreenQuadPipeline(pipelineLayout, vertexShaderModule, filterOutputShaderModule, this.format, blend));
2256
2265
  }
@@ -2289,6 +2298,26 @@ export class PipelineManager {
2289
2298
  this.createPositionedTexturePipeline();
2290
2299
  this.createTextureScalePipeline();
2291
2300
  }
2301
+ /**
2302
+ * @description キャッシュ色変換の初回使用時だけ専用パイプラインを作成する
2303
+ * Create fused cached CT pipelines only on first use
2304
+ */
2305
+ createCachedColorTransformPipelines() {
2306
+ const bindGroupLayout = this.getBindGroupLayout("texture_copy");
2307
+ const pipelineLayout = this.device.createPipelineLayout({ "bindGroupLayouts": [bindGroupLayout] });
2308
+ const vertexShaderModule = this.getOrCreateShaderModule("blurFilterVertex", ShaderSource.getBlurFilterVertexShader());
2309
+ const fragmentShaderModule = this.getOrCreateShaderModule("cachedColorTransformFragment", ShaderSource.getCachedColorTransformFragmentShader());
2310
+ const variants = [
2311
+ ["filter_output", $BLEND_PREMULTIPLIED_ALPHA], ...$FILTER_OUTPUT_BLEND_VARIANTS
2312
+ ];
2313
+ for (const [name, blend] of variants) {
2314
+ const cachedName = name.replace("filter_output", "cached_ct");
2315
+ this.pipelines.set(cachedName, this.createFullscreenQuadPipeline(pipelineLayout, vertexShaderModule, fragmentShaderModule, this.format, blend));
2316
+ if (this.sampleCount > 1) {
2317
+ this.pipelines.set(`${cachedName}_msaa`, this.createFullscreenQuadPipeline(pipelineLayout, vertexShaderModule, fragmentShaderModule, this.format, blend, this.sampleCount));
2318
+ }
2319
+ }
2320
+ }
2292
2321
  /**
2293
2322
  * @description 位置指定テクスチャ描画用パイプラインを作成する(RGBA/ビットマップレンダー対応)
2294
2323
  * Create positioned texture pipelines (RGBA, bitmap render, MSAA variants)
@@ -2731,6 +2760,25 @@ export class PipelineManager {
2731
2760
  }
2732
2761
  });
2733
2762
  this.pipelines.set("complex_blend", pipeline);
2763
+ const regionFragment = this.getOrCreateShaderModule("complexBlendRegionFragment", ShaderSource.getUnifiedComplexBlendFragmentShader(true));
2764
+ this.pipelines.set("complex_blend_region", this.createFullscreenQuadPipeline(pipelineLayout, vertexShaderModule, regionFragment, "rgba8unorm", {
2765
+ "color": { "srcFactor": "one", "dstFactor": "zero", "operation": "add" },
2766
+ "alpha": { "srcFactor": "one", "dstFactor": "zero", "operation": "add" }
2767
+ }));
2768
+ const msaaLayout = this.device.createBindGroupLayout({ "entries": [
2769
+ { "binding": 0, "visibility": GPUShaderStage.FRAGMENT, "buffer": { "type": "uniform" } },
2770
+ { "binding": 1, "visibility": GPUShaderStage.FRAGMENT, "sampler": {} },
2771
+ { "binding": 2, "visibility": GPUShaderStage.FRAGMENT,
2772
+ "texture": { "multisampled": true, "sampleType": "unfilterable-float" } },
2773
+ { "binding": 3, "visibility": GPUShaderStage.FRAGMENT, "texture": {} }
2774
+ ] });
2775
+ this.bindGroupLayouts.set("complex_blend_msaa", msaaLayout);
2776
+ const msaaPipelineLayout = this.device.createPipelineLayout({ "bindGroupLayouts": [msaaLayout] });
2777
+ const msaaFragment = this.getOrCreateShaderModule("complexBlendRegionMsaaFragment", ShaderSource.getUnifiedComplexBlendFragmentShader(true, true));
2778
+ this.pipelines.set("complex_blend_region_msaa", this.createFullscreenQuadPipeline(msaaPipelineLayout, vertexShaderModule, msaaFragment, "rgba8unorm", {
2779
+ "color": { "srcFactor": "one", "dstFactor": "zero", "operation": "add" },
2780
+ "alpha": { "srcFactor": "one", "dstFactor": "zero", "operation": "add" }
2781
+ }));
2734
2782
  this.createComplexBlendCopyPipeline();
2735
2783
  this.createComplexBlendOutputPipeline();
2736
2784
  }
@@ -3,6 +3,12 @@
3
3
  * WebGPU shader source management class providing all vertex and fragment shaders
4
4
  */
5
5
  export declare class ShaderSource {
6
+ /**
7
+ * @description 中間RGBA8量子化を維持するキャッシュ色変換シェーダー
8
+ * Cached color transform retaining intermediate RGBA8 quantization
9
+ * @return {string}
10
+ */
11
+ static getCachedColorTransformFragmentShader(): string;
6
12
  /**
7
13
  * @description 塗り用頂点シェーダーを取得する
8
14
  * Get fill vertex shader
@@ -272,9 +278,11 @@ export declare class ShaderSource {
272
278
  * @description 統合複合ブレンドフラグメントシェーダーを取得する
273
279
  * Get unified complex blend fragment shader
274
280
  *
281
+ * @param {boolean} use_dst_region - 解決済み背景の整数ピクセル領域を直接読むかどうか
282
+ * @param {boolean} use_dst_msaa - 4x MSAA背景を領域内で解決するかどうか(RGBA8/BGRA8 UNORM用)
275
283
  * @return {string}
276
284
  */
277
- static getUnifiedComplexBlendFragmentShader(): string;
285
+ static getUnifiedComplexBlendFragmentShader(use_dst_region?: boolean, use_dst_msaa?: boolean): string;
278
286
  /**
279
287
  * @description ディスプレースメントマップフィルターフラグメントシェーダーを生成する
280
288
  * Generate displacement map filter fragment shader
@@ -13,7 +13,7 @@ import { BasicFragment, TextureFragment } from "./wgsl/fragment/BasicFragment";
13
13
  import { InstancedFragment } from "./wgsl/fragment/InstancedFragment";
14
14
  import { GradientFillFragment, GradientFillStencilFragment } from "./wgsl/fragment/GradientFragment";
15
15
  import { BitmapFillFragment } from "./wgsl/fragment/BitmapFragment";
16
- import { TextureCopyFragment, BlurTextureCopyFragment, FilterOutputFragment, ColorTransformFragment, YFlipColorTransformFragment, ColorMatrixFilterFragment, NodeClearFragment, PositionedTextureFragment, BlendGenericFragment, BitmapSyncFragment } from "./wgsl/fragment/FilterFragment";
16
+ import { TextureCopyFragment, BlurTextureCopyFragment, FilterOutputFragment, ColorTransformFragment, CachedColorTransformFragment, YFlipColorTransformFragment, ColorMatrixFilterFragment, NodeClearFragment, PositionedTextureFragment, BlendGenericFragment, BitmapSyncFragment } from "./wgsl/fragment/FilterFragment";
17
17
  import { GlowFilterFragment, DropShadowFilterFragment, GradientGlowFilterFragment, GradientBevelFilterFragment, BevelFilterFragment, BevelBaseFragment } from "./wgsl/fragment/EffectFragment";
18
18
  import { WgslIsInside, WgslVertexOutput } from "./wgsl/common/SharedWgsl";
19
19
  /**
@@ -21,6 +21,14 @@ import { WgslIsInside, WgslVertexOutput } from "./wgsl/common/SharedWgsl";
21
21
  * WebGPU shader source management class providing all vertex and fragment shaders
22
22
  */
23
23
  export class ShaderSource {
24
+ /**
25
+ * @description 中間RGBA8量子化を維持するキャッシュ色変換シェーダー
26
+ * Cached color transform retaining intermediate RGBA8 quantization
27
+ * @return {string}
28
+ */
29
+ static getCachedColorTransformFragmentShader() {
30
+ return CachedColorTransformFragment;
31
+ }
24
32
  /**
25
33
  * @description 塗り用頂点シェーダーを取得する
26
34
  * Get fill vertex shader
@@ -496,9 +504,11 @@ fn fs_main(fragInput: VertexOutput) -> @location(0) vec4<f32> {
496
504
  * @description 統合複合ブレンドフラグメントシェーダーを取得する
497
505
  * Get unified complex blend fragment shader
498
506
  *
507
+ * @param {boolean} use_dst_region - 解決済み背景の整数ピクセル領域を直接読むかどうか
508
+ * @param {boolean} use_dst_msaa - 4x MSAA背景を領域内で解決するかどうか(RGBA8/BGRA8 UNORM用)
499
509
  * @return {string}
500
510
  */
501
- static getUnifiedComplexBlendFragmentShader() {
511
+ static getUnifiedComplexBlendFragmentShader(use_dst_region = false, use_dst_msaa = false) {
502
512
  return /* wgsl */ `
503
513
  ${WgslVertexOutput}
504
514
 
@@ -506,14 +516,14 @@ struct BlendUniforms {
506
516
  mulColor: vec4<f32>,
507
517
  addColor: vec4<f32>,
508
518
  blendMode: f32,
509
- _pad0: f32,
510
- _pad1: f32,
519
+ dstX: f32,
520
+ dstY: f32,
511
521
  _pad2: f32,
512
522
  }
513
523
 
514
524
  @group(0) @binding(0) var<uniform> uniforms: BlendUniforms;
515
525
  @group(0) @binding(1) var textureSampler: sampler;
516
- @group(0) @binding(2) var dstTexture: texture_2d<f32>;
526
+ @group(0) @binding(2) var dstTexture: ${use_dst_region && use_dst_msaa ? "texture_multisampled_2d" : "texture_2d"}<f32>;
517
527
  @group(0) @binding(3) var srcTexture: texture_2d<f32>;
518
528
 
519
529
  fn blend(src: vec4<f32>, dst: vec4<f32>, mode: i32) -> vec4<f32> {
@@ -575,7 +585,19 @@ fn blend(src: vec4<f32>, dst: vec4<f32>, mode: i32) -> vec4<f32> {
575
585
 
576
586
  @fragment
577
587
  fn main(input: VertexOutput) -> @location(0) vec4<f32> {
578
- var dst = textureSample(dstTexture, textureSampler, input.texCoord);
588
+ ${use_dst_region ? `// The old copy and blend each flip Y; the combined backdrop lookup is framebuffer-oriented.
589
+ let dstSize = vec2<i32>(textureDimensions(dstTexture));
590
+ let dstPixel = clamp(vec2<i32>(input.position.xy) + vec2<i32>(i32(uniforms.dstX), i32(uniforms.dstY)),
591
+ vec2<i32>(0), dstSize - vec2<i32>(1));
592
+ ${use_dst_msaa ? `// Recover exact UNORM8 integers before averaging so floating-point load error
593
+ // cannot move a half-integer result to the other side of a rounding tie.
594
+ let resolved = (round(textureLoad(dstTexture, dstPixel, 0) * 255.0)
595
+ + round(textureLoad(dstTexture, dstPixel, 1) * 255.0)
596
+ + round(textureLoad(dstTexture, dstPixel, 2) * 255.0)
597
+ + round(textureLoad(dstTexture, dstPixel, 3) * 255.0)) * 0.25;
598
+ var dst = floor(resolved + 0.5) / 255.0;`
599
+ : "var dst = textureLoad(dstTexture, dstPixel, 0);"}`
600
+ : "var dst = textureSample(dstTexture, textureSampler, input.texCoord);"}
579
601
  var src = textureSample(srcTexture, textureSampler, input.texCoord);
580
602
  let mul = uniforms.mulColor;
581
603
  let add = uniforms.addColor;
@@ -22,14 +22,12 @@ export declare const BlurTextureCopyFragment = "\n\nstruct VertexOutput {\n @
22
22
  * @constant
23
23
  */
24
24
  export declare const FilterOutputFragment = "\n\nstruct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) texCoord: vec2<f32>,\n}\n\nstruct CopyUniforms {\n scale: vec2<f32>,\n offset: vec2<f32>,\n}\n\n@group(0) @binding(0) var<uniform> uniforms: CopyUniforms;\n@group(0) @binding(1) var textureSampler: sampler;\n@group(0) @binding(2) var inputTexture: texture_2d<f32>;\n\n@fragment\nfn main(input: VertexOutput) -> @location(0) vec4<f32> {\n let uv = input.texCoord * uniforms.scale + uniforms.offset;\n let clampedUv = clamp(uv, vec2<f32>(0.0), vec2<f32>(1.0));\n let color = textureSampleLevel(inputTexture, textureSampler, clampedUv, 0);\n let inBounds = uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0;\n return select(vec4<f32>(0.0, 0.0, 0.0, 0.0), color, inBounds);\n}\n";
25
+ export declare const ColorTransformFragment: string;
25
26
  /**
26
- * @description カラー変換フラグメントシェーダー(乗算・加算カラー適用)
27
- * Color transform fragment shader with multiply and add color application
28
- *
29
- * @type {string}
30
- * @constant
27
+ * @description 等倍キャッシュ出力専用。色変換の中間RGBA8テクスチャへの保存・再読込を再現する。
28
+ * Cached 1:1 output only: reproduce the intermediate RGBA8 store/load before blending.
31
29
  */
32
- export declare const ColorTransformFragment = "\n\nstruct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) texCoord: vec2<f32>,\n}\n\nstruct ColorTransformUniforms {\n mul: vec4<f32>,\n add: vec4<f32>,\n}\n\n@group(0) @binding(0) var<uniform> ct: ColorTransformUniforms;\n@group(0) @binding(1) var textureSampler: sampler;\n@group(0) @binding(2) var inputTexture: texture_2d<f32>;\n\n@fragment\nfn main(input: VertexOutput) -> @location(0) vec4<f32> {\n var color = textureSampleLevel(inputTexture, textureSampler, input.texCoord, 0);\n\n color = vec4<f32>(color.rgb / max(vec3<f32>(0.0001), vec3<f32>(color.a)), color.a);\n color = clamp(color * ct.mul + ct.add, vec4<f32>(0.0), vec4<f32>(1.0));\n color = vec4<f32>(color.rgb * color.a, color.a);\n\n return color;\n}\n";
30
+ export declare const CachedColorTransformFragment: string;
33
31
  /**
34
32
  * @description Y軸反転付きカラー変換フラグメントシェーダー
35
33
  * Y-flip color transform fragment shader
@@ -84,10 +84,10 @@ fn main(input: VertexOutput) -> @location(0) vec4<f32> {
84
84
  * @description カラー変換フラグメントシェーダー(乗算・加算カラー適用)
85
85
  * Color transform fragment shader with multiply and add color application
86
86
  *
87
- * @type {string}
88
- * @constant
87
+ * @param {boolean} quantize - 中間RGBA8出力の量子化を再現する / Reproduce intermediate RGBA8 quantization
88
+ * @return {string}
89
89
  */
90
- export const ColorTransformFragment = /* wgsl */ `
90
+ const $createColorTransformFragment = (quantize) => /* wgsl */ `
91
91
  ${WgslVertexOutput}
92
92
 
93
93
  struct ColorTransformUniforms {
@@ -107,9 +107,15 @@ fn main(input: VertexOutput) -> @location(0) vec4<f32> {
107
107
  color = clamp(color * ct.mul + ct.add, vec4<f32>(0.0), vec4<f32>(1.0));
108
108
  color = vec4<f32>(color.rgb * color.a, color.a);
109
109
 
110
- return color;
110
+ return ${quantize ? "unpack4x8unorm(pack4x8unorm(color))" : "color"};
111
111
  }
112
112
  `;
113
+ export const ColorTransformFragment = $createColorTransformFragment(false);
114
+ /**
115
+ * @description 等倍キャッシュ出力専用。色変換の中間RGBA8テクスチャへの保存・再読込を再現する。
116
+ * Cached 1:1 output only: reproduce the intermediate RGBA8 store/load before blending.
117
+ */
118
+ export const CachedColorTransformFragment = $createColorTransformFragment(true);
113
119
  /**
114
120
  * @description Y軸反転付きカラー変換フラグメントシェーダー
115
121
  * Y-flip color transform fragment shader
@@ -1,4 +1,4 @@
1
- import type { ITexturePoolBuckets } from "../../interface/IPooledTexture";
1
+ import type { IPooledTexture, ITexturePoolBuckets } from "../../interface/IPooledTexture";
2
2
  /**
3
3
  * @description 古いプールエントリをクリーンアップ(バケットMap版 LRU回収)
4
4
  * Cleanup old pool entries (bucket Map version, LRU eviction)
@@ -11,4 +11,4 @@ import type { ITexturePoolBuckets } from "../../interface/IPooledTexture";
11
11
  * @method
12
12
  * @protected
13
13
  */
14
- export declare const execute: (buckets: ITexturePoolBuckets, current_frame: number, threshold: number, total_count: number[]) => void;
14
+ export declare const execute: (buckets: ITexturePoolBuckets, current_frame: number, threshold: number, total_count: number[], entries?: WeakMap<GPUTexture, IPooledTexture>) => void;
@@ -10,13 +10,14 @@
10
10
  * @method
11
11
  * @protected
12
12
  */
13
- export const execute = (buckets, current_frame, threshold, total_count) => {
13
+ export const execute = (buckets, current_frame, threshold, total_count, entries) => {
14
14
  const frameThreshold = current_frame - threshold;
15
15
  for (const [key, bucket] of buckets) {
16
16
  for (let i = bucket.length - 1; i >= 0; i--) {
17
17
  const entry = bucket[i];
18
18
  if (!entry.inUse && entry.lastUsedFrame < frameThreshold) {
19
19
  entry.texture.destroy();
20
+ entries?.delete(entry.texture);
20
21
  bucket.splice(i, 1);
21
22
  total_count[0]--;
22
23
  }
@@ -1,4 +1,4 @@
1
- import type { ITexturePoolBuckets } from "../../interface/IPooledTexture";
1
+ import type { IPooledTexture, ITexturePoolBuckets } from "../../interface/IPooledTexture";
2
2
  /**
3
3
  * @description テクスチャをプールに返却(バケットMap版)
4
4
  * Release texture back to pool (bucket Map version)
@@ -10,4 +10,4 @@ import type { ITexturePoolBuckets } from "../../interface/IPooledTexture";
10
10
  * @method
11
11
  * @protected
12
12
  */
13
- export declare const execute: (buckets: ITexturePoolBuckets, texture: GPUTexture, current_frame: number) => void;
13
+ export declare const execute: (buckets: ITexturePoolBuckets, texture: GPUTexture, current_frame: number, entries?: WeakMap<GPUTexture, IPooledTexture>) => void;
@@ -9,12 +9,19 @@
9
9
  * @method
10
10
  * @protected
11
11
  */
12
- export const execute = (buckets, texture, current_frame) => {
12
+ export const execute = (buckets, texture, current_frame, entries) => {
13
+ const entry = entries?.get(texture);
14
+ if (entry) {
15
+ entry.inUse = false;
16
+ entry.lastUsedFrame = current_frame;
17
+ return;
18
+ }
13
19
  for (const bucket of buckets.values()) {
14
20
  for (let i = 0; i < bucket.length; i++) {
15
21
  if (bucket[i].texture === texture) {
16
22
  bucket[i].inUse = false;
17
23
  bucket[i].lastUsedFrame = current_frame;
24
+ entries?.set(texture, bucket[i]);
18
25
  return;
19
26
  }
20
27
  }
@@ -1,4 +1,4 @@
1
- import type { ITexturePoolBuckets } from "../../interface/IPooledTexture";
1
+ import type { IPooledTexture, ITexturePoolBuckets } from "../../interface/IPooledTexture";
2
2
  /**
3
3
  * @description テクスチャを取得または作成(バケットMap検索)
4
4
  * Acquire texture from pool or create new one (bucket Map lookup)
@@ -16,4 +16,4 @@ import type { ITexturePoolBuckets } from "../../interface/IPooledTexture";
16
16
  * @method
17
17
  * @protected
18
18
  */
19
- export declare const execute: (device: GPUDevice, buckets: ITexturePoolBuckets, width: number, height: number, format: GPUTextureFormat, usage: GPUTextureUsageFlags, current_frame: number, max_pool_size: number, total_count: number[]) => GPUTexture;
19
+ export declare const execute: (device: GPUDevice, buckets: ITexturePoolBuckets, width: number, height: number, format: GPUTextureFormat, usage: GPUTextureUsageFlags, current_frame: number, max_pool_size: number, total_count: number[], entries?: WeakMap<GPUTexture, IPooledTexture>) => GPUTexture;
@@ -27,7 +27,7 @@ const buildKey = (width, height, format) => {
27
27
  * @method
28
28
  * @protected
29
29
  */
30
- export const execute = (device, buckets, width, height, format, usage, current_frame, max_pool_size, total_count) => {
30
+ export const execute = (device, buckets, width, height, format, usage, current_frame, max_pool_size, total_count, entries) => {
31
31
  const key = buildKey(width, height, format);
32
32
  // バケットから未使用テクスチャを検索(O(1)バケット + O(n)バケット内走査)
33
33
  const bucket = buckets.get(key);
@@ -59,6 +59,7 @@ export const execute = (device, buckets, width, height, format, usage, current_f
59
59
  if (oldestIdx >= 0) {
60
60
  const bEntries = buckets.get(oldestKey);
61
61
  bEntries[oldestIdx].texture.destroy();
62
+ entries?.delete(bEntries[oldestIdx].texture);
62
63
  bEntries.splice(oldestIdx, 1);
63
64
  if (bEntries.length === 0) {
64
65
  buckets.delete(oldestKey);
@@ -80,6 +81,7 @@ export const execute = (device, buckets, width, height, format, usage, current_f
80
81
  "lastUsedFrame": current_frame,
81
82
  "inUse": true
82
83
  };
84
+ entries?.set(texture, entry);
83
85
  if (bucket) {
84
86
  bucket.push(entry);
85
87
  }
@@ -19,6 +19,7 @@ export declare class TexturePool {
19
19
  * @type {ITexturePoolBuckets}
20
20
  */
21
21
  private buckets;
22
+ private entries;
22
23
  /**
23
24
  * @description 現在のフレーム番号
24
25
  * Current frame number for LRU tracking
@@ -51,6 +51,12 @@ export class TexturePool {
51
51
  writable: true,
52
52
  value: void 0
53
53
  });
54
+ Object.defineProperty(this, "entries", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: void 0
59
+ });
54
60
  /**
55
61
  * @description 現在のフレーム番号
56
62
  * Current frame number for LRU tracking
@@ -75,6 +81,7 @@ export class TexturePool {
75
81
  });
76
82
  this.device = device;
77
83
  this.buckets = new Map();
84
+ this.entries = new WeakMap();
78
85
  this.currentFrame = 0;
79
86
  this.totalCount = [0];
80
87
  }
@@ -87,7 +94,7 @@ export class TexturePool {
87
94
  this.currentFrame++;
88
95
  // 定期的にプールをクリーンアップ(LRU回収)
89
96
  if (this.currentFrame % 60 === 0) {
90
- texturePoolCleanupService(this.buckets, this.currentFrame, $CACHE_CLEANUP_THRESHOLD, this.totalCount);
97
+ texturePoolCleanupService(this.buckets, this.currentFrame, $CACHE_CLEANUP_THRESHOLD, this.totalCount, this.entries);
91
98
  }
92
99
  }
93
100
  /**
@@ -102,7 +109,7 @@ export class TexturePool {
102
109
  acquire(width, height, format = "rgba8unorm", usage = GPUTextureUsage.TEXTURE_BINDING |
103
110
  GPUTextureUsage.COPY_DST |
104
111
  GPUTextureUsage.RENDER_ATTACHMENT) {
105
- return texturePoolAcquireUseCase(this.device, this.buckets, width, height, format, usage, this.currentFrame, $MAX_POOL_SIZE, this.totalCount);
112
+ return texturePoolAcquireUseCase(this.device, this.buckets, width, height, format, usage, this.currentFrame, $MAX_POOL_SIZE, this.totalCount, this.entries);
106
113
  }
107
114
  /**
108
115
  * @description テクスチャをプールに返却する
@@ -111,7 +118,7 @@ export class TexturePool {
111
118
  * @return {void}
112
119
  */
113
120
  release(texture) {
114
- texturePoolReleaseService(this.buckets, texture, this.currentFrame);
121
+ texturePoolReleaseService(this.buckets, texture, this.currentFrame, this.entries);
115
122
  }
116
123
  /**
117
124
  * @description 全テクスチャを破棄しプールを解放する
@@ -125,6 +132,7 @@ export class TexturePool {
125
132
  }
126
133
  }
127
134
  this.buckets.clear();
135
+ this.entries = new WeakMap();
128
136
  this.totalCount[0] = 0;
129
137
  }
130
138
  }
@@ -21,6 +21,7 @@ export interface IFilterConfig {
21
21
  bufferManager?: {
22
22
  acquireUniformBuffer(requiredSize: number): GPUBuffer;
23
23
  acquireAndWriteUniformBuffer(data: Float32Array, byteLength?: number): GPUBuffer;
24
+ allocateUniformBinding(data: Float32Array): GPUBufferBinding;
24
25
  };
25
26
  /**
26
27
  * @description フレームバッファの管理インターフェース