@yft-design/engine 0.0.8 → 0.0.9

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.
@@ -31,6 +31,7 @@ import { type AnimationPlaybackInfo, type ScrollTextTrackInfo, type SinglePrevie
31
31
  import { type TableCellEditingHost } from './interact/tableCellEditing';
32
32
  import type { TableInteractionHost } from './interact/tableInteraction';
33
33
  import { type TextEditingHost } from './interact/textEditing';
34
+ import { RenderEpoch } from './render/renderEpoch';
34
35
  import { GradientRampCache } from './render/gradientRamp';
35
36
  import { GLTextureCache, type TextureCacheStats } from './render/GLTextureCache';
36
37
  import { BatchOrder } from './render/batchOrder';
@@ -76,6 +77,9 @@ export declare class EngineCanvas implements PointerHost, TextEditingHost, Sourc
76
77
  readonly textures: GLTextureCache;
77
78
  readonly gradientRamps: GradientRampCache;
78
79
  private readonly glyphAtlas;
80
+ /** 渲染产物统一失效纪元(批次 374 方向一):GlyphAtlas.reset/纹理淘汰经
81
+ * bump 汇入,保留式帧门链单点消费(RetainedFrameHost.renderEpoch) */
82
+ readonly renderEpoch: RenderEpoch;
79
83
  /** 源加载与图案/蒙版纹理(loadObjects 编排;渲染侧 SceneRenderer 读) */
80
84
  private readonly sources;
81
85
  /** 文本渲染管线(字形/背景/装饰/虚线/变形文本烘焙) */
@@ -33,6 +33,7 @@ import { TextEditingController } from './interact/textEditing';
33
33
  import { createGLContext } from './render/GLContext';
34
34
  import { FontInvalidationController } from './render/fontInvalidationController';
35
35
  import { GlyphAtlas } from './render/GlyphAtlas';
36
+ import { RenderEpoch } from './render/renderEpoch';
36
37
  import { GradientRampCache } from './render/gradientRamp';
37
38
  import { GLTextureCache } from './render/GLTextureCache';
38
39
  import { BatchOrder } from './render/batchOrder';
@@ -81,6 +82,9 @@ export class EngineCanvas {
81
82
  textures;
82
83
  gradientRamps;
83
84
  glyphAtlas;
85
+ /** 渲染产物统一失效纪元(批次 374 方向一):GlyphAtlas.reset/纹理淘汰经
86
+ * bump 汇入,保留式帧门链单点消费(RetainedFrameHost.renderEpoch) */
87
+ renderEpoch = new RenderEpoch();
84
88
  /** 源加载与图案/蒙版纹理(loadObjects 编排;渲染侧 SceneRenderer 读) */
85
89
  sources;
86
90
  /** 文本渲染管线(字形/背景/装饰/虚线/变形文本烘焙) */
@@ -168,12 +172,12 @@ export class EngineCanvas {
168
172
  this.batchOrder = new BatchOrder(this.batch, this.meshBatch);
169
173
  this.batch.order = this.batchOrder;
170
174
  this.meshBatch.order = this.batchOrder;
171
- this.textures = new GLTextureCache(handle.gl);
175
+ this.textures = new GLTextureCache(handle.gl, { epoch: this.renderEpoch });
172
176
  this.gradientRamps = new GradientRampCache(handle.gl);
173
177
  // 批次 42:provisional cell 被 loadingdone 丢弃后立即补帧(否则空转等下一次
174
178
  // 外部触发才重烘真字形);批次 46:帧界 settle(事件失联自愈路径)上报
175
179
  // family 集 → 宿主补齐排版/度量/烘焙失效(见 fontInvalidation 的 pendingSettle)
176
- this.glyphAtlas = new GlyphAtlas(handle.gl, () => this.requestRenderAll(), (families) => this.fontInvalidation.queueSettle(families));
180
+ this.glyphAtlas = new GlyphAtlas(handle.gl, () => this.requestRenderAll(), (families) => this.fontInvalidation.queueSettle(families), this.renderEpoch);
177
181
  this.dpr = options.dpr ?? (typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1);
178
182
  this.mobileControls = options.mobileControls ?? false;
179
183
  this.background = options.background ?? [0, 0, 0, 0];
@@ -26,6 +26,7 @@
26
26
  *
27
27
  * context lost:invalidateAll() 清空(恢复事件里由渲染层重建)。
28
28
  */
29
+ import { RenderEpoch } from './renderEpoch';
29
30
  export type TextureSource = HTMLImageElement | HTMLCanvasElement | HTMLVideoElement;
30
31
  export interface GLTextureCacheOptions {
31
32
  /** 字节预算(估算口径),超出从最旧端淘汰;缺省 512 MiB */
@@ -35,6 +36,9 @@ export interface GLTextureCacheOptions {
35
36
  /** 插入压力淘汰的近帧宽限(帧数):lastFrame 距当前帧不足此值的条目跳过
36
37
  * 淘汰。缺省 30。1 = 仅本帧(旧行为)。 */
37
38
  evictGraceFrames?: number;
39
+ /** 统一失效纪元(批次 374 方向一):淘汰删句柄即 bump;EngineCanvas 注入
40
+ * 共享实例,缺省自建(直构单测=独立纪元) */
41
+ epoch?: RenderEpoch;
38
42
  }
39
43
  export interface TextureCacheStats {
40
44
  entries: number;
@@ -59,6 +63,8 @@ export declare class GLTextureCache {
59
63
  private evictions;
60
64
  private trackedBytes;
61
65
  private disposed;
66
+ /** 统一失效纪元(批次 374 方向一):淘汰即 bump,保留式门链经宿主共享实例消费 */
67
+ private readonly epoch;
62
68
  constructor(gl: WebGL2RenderingContext, options?: GLTextureCacheOptions);
63
69
  /** 帧界推进(EngineCanvas.render 顶部调用):此后的取用都算「本帧」。
64
70
  * 批次 321:不再做预算强制结算——帧界强逐在工作集超预算时构成
@@ -26,6 +26,7 @@
26
26
  *
27
27
  * context lost:invalidateAll() 清空(恢复事件里由渲染层重建)。
28
28
  */
29
+ import { RenderEpoch } from './renderEpoch';
29
30
  const DEFAULT_BUDGET_BYTES = 512 * 1024 * 1024;
30
31
  const DEFAULT_MAX_ENTRIES = 2048;
31
32
  const DEFAULT_EVICT_GRACE_FRAMES = 30;
@@ -44,11 +45,14 @@ export class GLTextureCache {
44
45
  evictions = 0;
45
46
  trackedBytes = 0;
46
47
  disposed = false;
48
+ /** 统一失效纪元(批次 374 方向一):淘汰即 bump,保留式门链经宿主共享实例消费 */
49
+ epoch;
47
50
  constructor(gl, options = {}) {
48
51
  this.gl = gl;
49
52
  this.budgetBytes = options.budgetBytes ?? DEFAULT_BUDGET_BYTES;
50
53
  this.maxEntries = options.maxEntries ?? DEFAULT_MAX_ENTRIES;
51
54
  this.evictGraceFrames = options.evictGraceFrames ?? DEFAULT_EVICT_GRACE_FRAMES;
55
+ this.epoch = options.epoch ?? new RenderEpoch();
52
56
  }
53
57
  /** 帧界推进(EngineCanvas.render 顶部调用):此后的取用都算「本帧」。
54
58
  * 批次 321:不再做预算强制结算——帧界强逐在工作集超预算时构成
@@ -156,6 +160,8 @@ export class GLTextureCache {
156
160
  this.cache.delete(source);
157
161
  this.trackedBytes -= entry.bytes;
158
162
  this.evictions += 1;
163
+ // 统一失效纪元(批次 374):被逐句柄可能已被保留式快照命令表引用
164
+ this.epoch.bump('texture-evict');
159
165
  return true;
160
166
  }
161
167
  return false;
@@ -19,6 +19,7 @@
19
19
  * 再做 pad+ankle mipmap 或 SDF。
20
20
  */
21
21
  import { type TextStrokeDecl, type TextStyleProps } from '../model/textLayout';
22
+ import { RenderEpoch } from './renderEpoch';
22
23
  export interface GlyphCell {
23
24
  /** 归属页索引(textureOf 反查) */
24
25
  pageIndex: number;
@@ -97,7 +98,10 @@ export declare class GlyphAtlas {
97
98
  * 全量失效,重复上报只会带来重复重排 */
98
99
  private readonly onProvisionalSettled?;
99
100
  private detachFontsListener;
100
- constructor(gl: WebGL2RenderingContext, onCellsInvalidated?: () => void, onProvisionalSettled?: (families: string[]) => void);
101
+ /** 统一失效纪元(批次 374 方向一):reset 删页纹理即 bump;EngineCanvas 注入
102
+ * 共享实例,缺省自建(直构单测=独立纪元) */
103
+ private readonly epoch;
104
+ constructor(gl: WebGL2RenderingContext, onCellsInvalidated?: () => void, onProvisionalSettled?: (families: string[]) => void, epoch?: RenderEpoch);
101
105
  /** document.fonts 的防御式取位(jsdom 旧版/非浏览器宿主可能缺) */
102
106
  private fontSet;
103
107
  /** 声明的 face 是否尚未就绪。两态都算 pending:
@@ -21,6 +21,7 @@
21
21
  import { fontDeclaration, GENERIC_FONTS } from '../model/textLayout';
22
22
  import { isRetainedDebugEnabled } from '../engineFlag';
23
23
  import { normalizeFamily } from './fontInvalidation';
24
+ import { RenderEpoch } from './renderEpoch';
24
25
  const PAGE_SIZE = 1024;
25
26
  const CELL_PAD = 2;
26
27
  /** miter 留白上限(px):防极端 miterLimit 让 cell 撑爆整页而让字形整体消失 */
@@ -93,10 +94,14 @@ export class GlyphAtlas {
93
94
  * 全量失效,重复上报只会带来重复重排 */
94
95
  onProvisionalSettled;
95
96
  detachFontsListener = null;
96
- constructor(gl, onCellsInvalidated, onProvisionalSettled) {
97
+ /** 统一失效纪元(批次 374 方向一):reset 删页纹理即 bump;EngineCanvas 注入
98
+ * 共享实例,缺省自建(直构单测=独立纪元) */
99
+ epoch;
100
+ constructor(gl, onCellsInvalidated, onProvisionalSettled, epoch = new RenderEpoch()) {
97
101
  this.gl = gl;
98
102
  this.onCellsInvalidated = onCellsInvalidated;
99
103
  this.onProvisionalSettled = onProvisionalSettled;
104
+ this.epoch = epoch;
100
105
  this.tmpCanvas = document.createElement('canvas');
101
106
  this.tmpCanvas.width = 8;
102
107
  this.tmpCanvas.height = 8;
@@ -225,6 +230,9 @@ export class GlyphAtlas {
225
230
  this.provisionalCells.clear();
226
231
  if (hadContent) {
227
232
  this._generation++;
233
+ // 统一失效纪元(批次 374):与 generation 同守卫块——reset 删全部页纹理,
234
+ // 快照命令表持有的活引用变死句柄,纪元 bump 进保留式门链
235
+ this.epoch.bump('atlas-reset');
228
236
  if (isRetainedDebugEnabled()) {
229
237
  console.warn('[retained] GlyphAtlas.reset → generation', this._generation, new Error('reset 调用栈取证').stack);
230
238
  }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 渲染产物统一失效纪元(方向一第一刀,
3
+ * docs/2026-10-13_webgl2-render-jank-causes-and-watchlist.md §6.2)。
4
+ *
5
+ * 批次 223/225 的教训:纹理级失效(GlyphAtlas.reset 删全部页纹理、
6
+ * GLTextureCache 淘汰删句柄)不产生任何节点染脏——保留式快照持有死引用
7
+ * 重放即整层消失,自愈链对这类失效天然失明,只能靠失效源各自把计数
8
+ * 「接进门链」。此前是两个独立信号各自为政(atlas generation /
9
+ * evictionCount),批次 374 起收敛为单一单调纪元:
10
+ * - 失效源(reset/淘汰/未来的烘焙删除口)统一 `bump(reason)`;
11
+ * - 保留式帧门链快照只记一个 `artifactEpoch`,不等即回退全量帧——
12
+ * 新增失效源接一个 bump 就自动入门链,不可能再静默绕过(结构性收口);
13
+ * - `lastReason` 仅诊断(门链回退打点/快照收录日志)。
14
+ *
15
+ * 纪元只承载「产物级销毁」信号;节点级内容失效仍走 renderDirty 染脏
16
+ * (脏集重推语义不变)。EngineCanvas 持唯一实例注入 GlyphAtlas/
17
+ * GLTextureCache(缺省自建=独立纪元,直构单测等价旧口径)。
18
+ */
19
+ export declare class RenderEpoch {
20
+ private _value;
21
+ private _lastReason;
22
+ /** 单调纪元值(快照收录时记录比对) */
23
+ get value(): number;
24
+ /** 最近一次失效原因(仅诊断打点) */
25
+ get lastReason(): string;
26
+ /** 失效通知:任何「删了已被快照命令表引用的产物」的路径必须调用 */
27
+ bump(reason: string): void;
28
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * 渲染产物统一失效纪元(方向一第一刀,
3
+ * docs/2026-10-13_webgl2-render-jank-causes-and-watchlist.md §6.2)。
4
+ *
5
+ * 批次 223/225 的教训:纹理级失效(GlyphAtlas.reset 删全部页纹理、
6
+ * GLTextureCache 淘汰删句柄)不产生任何节点染脏——保留式快照持有死引用
7
+ * 重放即整层消失,自愈链对这类失效天然失明,只能靠失效源各自把计数
8
+ * 「接进门链」。此前是两个独立信号各自为政(atlas generation /
9
+ * evictionCount),批次 374 起收敛为单一单调纪元:
10
+ * - 失效源(reset/淘汰/未来的烘焙删除口)统一 `bump(reason)`;
11
+ * - 保留式帧门链快照只记一个 `artifactEpoch`,不等即回退全量帧——
12
+ * 新增失效源接一个 bump 就自动入门链,不可能再静默绕过(结构性收口);
13
+ * - `lastReason` 仅诊断(门链回退打点/快照收录日志)。
14
+ *
15
+ * 纪元只承载「产物级销毁」信号;节点级内容失效仍走 renderDirty 染脏
16
+ * (脏集重推语义不变)。EngineCanvas 持唯一实例注入 GlyphAtlas/
17
+ * GLTextureCache(缺省自建=独立纪元,直构单测等价旧口径)。
18
+ */
19
+ export class RenderEpoch {
20
+ _value = 0;
21
+ _lastReason = '';
22
+ /** 单调纪元值(快照收录时记录比对) */
23
+ get value() {
24
+ return this._value;
25
+ }
26
+ /** 最近一次失效原因(仅诊断打点) */
27
+ get lastReason() {
28
+ return this._lastReason;
29
+ }
30
+ /** 失效通知:任何「删了已被快照命令表引用的产物」的路径必须调用 */
31
+ bump(reason) {
32
+ this._value++;
33
+ this._lastReason = reason;
34
+ }
35
+ }
@@ -19,6 +19,7 @@
19
19
  import type { EngineDocument } from '../model/document';
20
20
  import type { Mat } from '../core/mat2d';
21
21
  import type { BatchOrder } from './batchOrder';
22
+ import type { RenderEpoch } from './renderEpoch';
22
23
  import type { GLTextureCache } from './GLTextureCache';
23
24
  import type { GlyphAtlas } from './GlyphAtlas';
24
25
  import type { MeshBatch } from './MeshBatch';
@@ -37,6 +38,9 @@ export interface RetainedFrameHost {
37
38
  readonly renderer: SceneRenderer;
38
39
  readonly textures: GLTextureCache;
39
40
  readonly glyphAtlas: GlyphAtlas;
41
+ /** 渲染产物统一失效纪元(批次 374 方向一):GlyphAtlas.reset/GLTextureCache
42
+ * 淘汰(及未来任何产物级删除口)经 bump 汇入,门链单点消费 */
43
+ readonly renderEpoch: RenderEpoch;
40
44
  readonly progressiveLoad: {
41
45
  readonly limit: number;
42
46
  };
@@ -60,12 +60,12 @@ export class RetainedFrameController {
60
60
  return this.gateFail('vpt');
61
61
  if (rf.dpr !== host.dpr || rf.sizeKey !== `${host.canvasEl.width}x${host.canvasEl.height}`)
62
62
  return this.gateFail('surface');
63
- if (rf.evictions !== host.textures.evictionCount)
64
- return this.gateFail('texture-evict');
65
- // 图集世代门(重落核心修复):reset 删全部页纹理零染脏——重放死句柄即
66
- // 文本整层消失;世代不等回退全量帧重栅格化
67
- if (rf.atlasGeneration !== host.glyphAtlas.generation)
68
- return this.gateFail('atlas-generation');
63
+ // 产物失效纪元门(批次 374 折叠图集世代+纹理淘汰两信号):纹理级失效
64
+ // (reset 删页纹理/淘汰删句柄)零节点染脏,快照命令表持有活引用——重放
65
+ // 死句柄 = 文本整层消失(模板 273 回归根因)。新增失效源经 renderEpoch
66
+ // .bump 汇入即自动入门链(方向一:结构性收口,不可能静默绕过)
67
+ if (rf.artifactEpoch !== host.renderEpoch.value)
68
+ return this.gateFail(`artifact-epoch(${host.renderEpoch.lastReason})`);
69
69
  const snap = rf.snap;
70
70
  const dirty = host.doc.renderDirty;
71
71
  for (const node of dirty) {
@@ -104,12 +104,12 @@ export class RetainedFrameController {
104
104
  if (host.batchOrder.hasNovelPaintReferences(snap))
105
105
  return this.gateFail('repush-commands');
106
106
  }
107
- // 批次 321 复检:重推期(renderSceneNode)新纹理插入可触发预算淘汰
108
- // (get miss → evictIfNeeded),被逐句柄若在快照命令表里(干净节点的
109
- // 纹理),重放即整帧消失。入口门读数在重推前——计数已变即整体回退
110
- // 全量帧(调用方全量重写覆盖本帧缓冲,无残留语义)
111
- if (rf.evictions !== host.textures.evictionCount)
112
- return this.gateFail('texture-evict-late');
107
+ // 批次 321 复检(批次 374 纪元化):重推期(renderSceneNode)新纹理插入
108
+ // 可触发预算淘汰(get miss → evictIfNeeded),被逐句柄若在快照命令表里
109
+ // (干净节点的纹理),重放即整帧消失。入口门读数在重推前——纪元已变即
110
+ // 整体回退全量帧(调用方全量重写覆盖本帧缓冲,无残留语义)
111
+ if (rf.artifactEpoch !== host.renderEpoch.value)
112
+ return this.gateFail(`artifact-epoch-late(${host.renderEpoch.lastReason})`);
113
113
  host.batch.restoreTotals(snap.quadTotal);
114
114
  host.meshBatch.restoreTotals(snap.meshTotal);
115
115
  host.batchOrder.discardRecorded();
@@ -141,8 +141,7 @@ export class RetainedFrameController {
141
141
  vptKey: host.vpt.join(','),
142
142
  dpr: host.dpr,
143
143
  sizeKey: `${host.canvasEl.width}x${host.canvasEl.height}`,
144
- evictions: host.textures.evictionCount,
145
- atlasGeneration: host.glyphAtlas.generation
144
+ artifactEpoch: host.renderEpoch.value
146
145
  }
147
146
  : null;
148
147
  if (snap && isRetainedDebugEnabled()) {
@@ -153,8 +152,8 @@ export class RetainedFrameController {
153
152
  meshSlots: snap.meshSlots.size,
154
153
  structureVersion: host.doc.structureVersion,
155
154
  atlasPages: atlas.pages,
156
- atlasGeneration: atlas.generation,
157
- evictions: host.textures.evictionCount
155
+ artifactEpoch: host.renderEpoch.value,
156
+ epochLastReason: host.renderEpoch.lastReason
158
157
  });
159
158
  }
160
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yft-design/engine",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "yft-design 的 WebGL2 画布引擎:接受 fabric toObject 格式 JSON,输出 GL 画布 / 位图(任意倍率 FBO 读回)/ SVG(纯数据序列化器)",
5
5
  "repository": {
6
6
  "type": "git",