@flighthq/scene2d-wgpu 0.5.1-next.973.788d3d7 → 0.6.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.
- package/README.md +2 -2
- package/dist/.tsbuildinfo.contract +1 -0
- package/dist/.tsbuildinfo.runtime +1 -0
- package/dist/contract.d.ts +32 -34
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +32 -34
- package/dist/contract.js.map +1 -1
- package/dist/contract.scene2d-wgpu-types.d.ts +6 -0
- package/dist/contract.scene2d-wgpu-types.d.ts.map +1 -0
- package/dist/contract.scene2d-wgpu-types.js +2 -0
- package/dist/contract.scene2d-wgpu-types.js.map +1 -0
- package/dist/enableWgpuColorAdjustmentGuards.d.ts +3 -2
- package/dist/enableWgpuColorAdjustmentGuards.d.ts.map +1 -1
- package/dist/enableWgpuColorAdjustmentGuards.js +23 -14
- package/dist/enableWgpuColorAdjustmentGuards.js.map +1 -1
- package/dist/enableWgpuStrokePathTessellation.d.ts +1 -1
- package/dist/enableWgpuStrokePathTessellation.d.ts.map +1 -1
- package/dist/enableWgpuStrokePathTessellation.js +1 -6
- package/dist/enableWgpuStrokePathTessellation.js.map +1 -1
- package/dist/index.d.ts +23 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -2
- package/dist/index.js.map +1 -1
- package/dist/scene2DWgpuPipeline.d.ts +13 -0
- package/dist/scene2DWgpuPipeline.d.ts.map +1 -0
- package/dist/scene2DWgpuPipeline.js +59 -0
- package/dist/scene2DWgpuPipeline.js.map +1 -0
- package/dist/types/WgpuColorAdjustmentMaterialFeature.d.ts +2 -0
- package/dist/types/WgpuColorAdjustmentMaterialFeature.d.ts.map +1 -0
- package/dist/types/WgpuColorAdjustmentMaterialFeature.js +2 -0
- package/dist/types/WgpuColorAdjustmentMaterialFeature.js.map +1 -0
- package/dist/types/WgpuRenderStats.d.ts +12 -0
- package/dist/types/WgpuRenderStats.d.ts.map +1 -0
- package/dist/types/WgpuRenderStats.js +2 -0
- package/dist/types/WgpuRenderStats.js.map +1 -0
- package/dist/types/WgpuRichTextOverlay.d.ts +4 -0
- package/dist/types/WgpuRichTextOverlay.d.ts.map +1 -0
- package/dist/types/WgpuRichTextOverlay.js +2 -0
- package/dist/types/WgpuRichTextOverlay.js.map +1 -0
- package/dist/types/WgpuShapeMesh.d.ts +2 -0
- package/dist/types/WgpuShapeMesh.d.ts.map +1 -0
- package/dist/types/WgpuShapeMesh.js +2 -0
- package/dist/types/WgpuShapeMesh.js.map +1 -0
- package/dist/types/WgpuShapeRendererData.d.ts +17 -0
- package/dist/types/WgpuShapeRendererData.d.ts.map +1 -0
- package/dist/types/WgpuShapeRendererData.js +2 -0
- package/dist/types/WgpuShapeRendererData.js.map +1 -0
- package/dist/wgpuBitmapText.d.ts +2 -2
- package/dist/wgpuBitmapText.d.ts.map +1 -1
- package/dist/wgpuBitmapText.js +6 -6
- package/dist/wgpuBitmapText.js.map +1 -1
- package/dist/wgpuCache.d.ts +9 -6
- package/dist/wgpuCache.d.ts.map +1 -1
- package/dist/wgpuCache.js +17 -18
- package/dist/wgpuCache.js.map +1 -1
- package/dist/wgpuClip.d.ts +1 -1
- package/dist/wgpuClip.d.ts.map +1 -1
- package/dist/wgpuClip.js +2 -2
- package/dist/wgpuClip.js.map +1 -1
- package/dist/wgpuClipContours.d.ts +3 -1
- package/dist/wgpuClipContours.d.ts.map +1 -1
- package/dist/wgpuClipContours.js +7 -8
- package/dist/wgpuClipContours.js.map +1 -1
- package/dist/wgpuClipRectangle.d.ts +2 -1
- package/dist/wgpuClipRectangle.d.ts.map +1 -1
- package/dist/wgpuClipRectangle.js +4 -5
- package/dist/wgpuClipRectangle.js.map +1 -1
- package/dist/wgpuColorAdjustmentMaterialFeature.d.ts +1 -1
- package/dist/wgpuColorAdjustmentMaterialFeature.d.ts.map +1 -1
- package/dist/wgpuColorAdjustmentMaterialFeature.js +9 -13
- package/dist/wgpuColorAdjustmentMaterialFeature.js.map +1 -1
- package/dist/wgpuMeshShapeRenderer.d.ts +3 -2
- package/dist/wgpuMeshShapeRenderer.d.ts.map +1 -1
- package/dist/wgpuMeshShapeRenderer.js +9 -8
- package/dist/wgpuMeshShapeRenderer.js.map +1 -1
- package/dist/wgpuNode2D.d.ts +6 -3
- package/dist/wgpuNode2D.d.ts.map +1 -1
- package/dist/wgpuNode2D.js +20 -4
- package/dist/wgpuNode2D.js.map +1 -1
- package/dist/wgpuParticleEmitter2D.d.ts +4 -2
- package/dist/wgpuParticleEmitter2D.d.ts.map +1 -1
- package/dist/wgpuParticleEmitter2D.js +8 -8
- package/dist/wgpuParticleEmitter2D.js.map +1 -1
- package/dist/wgpuQuadBatch.d.ts +3 -3
- package/dist/wgpuQuadBatch.d.ts.map +1 -1
- package/dist/wgpuQuadBatch.js +6 -6
- package/dist/wgpuQuadBatch.js.map +1 -1
- package/dist/wgpuQuadBatchWriter.d.ts +9 -5
- package/dist/wgpuQuadBatchWriter.d.ts.map +1 -1
- package/dist/wgpuQuadBatchWriter.js +12 -8
- package/dist/wgpuQuadBatchWriter.js.map +1 -1
- package/dist/wgpuRasterShapeRenderer.d.ts +3 -2
- package/dist/wgpuRasterShapeRenderer.d.ts.map +1 -1
- package/dist/wgpuRasterShapeRenderer.js +41 -22
- package/dist/wgpuRasterShapeRenderer.js.map +1 -1
- package/dist/wgpuRenderStats.d.ts +2 -1
- package/dist/wgpuRenderStats.d.ts.map +1 -1
- package/dist/wgpuRenderStats.js.map +1 -1
- package/dist/wgpuRendererData.d.ts +2 -1
- package/dist/wgpuRendererData.d.ts.map +1 -1
- package/dist/wgpuRendererData.js +1 -1
- package/dist/wgpuRendererData.js.map +1 -1
- package/dist/wgpuRichText.d.ts +6 -3
- package/dist/wgpuRichText.d.ts.map +1 -1
- package/dist/wgpuRichText.js +67 -34
- package/dist/wgpuRichText.js.map +1 -1
- package/dist/wgpuScale9Mapper.d.ts +2 -1
- package/dist/wgpuScale9Mapper.d.ts.map +1 -1
- package/dist/wgpuScale9Mapper.js.map +1 -1
- package/dist/wgpuScale9Shape.d.ts +10 -5
- package/dist/wgpuScale9Shape.d.ts.map +1 -1
- package/dist/wgpuScale9Shape.js +54 -28
- package/dist/wgpuScale9Shape.js.map +1 -1
- package/dist/wgpuScale9Sprite.d.ts +3 -2
- package/dist/wgpuScale9Sprite.d.ts.map +1 -1
- package/dist/wgpuScale9Sprite.js +9 -10
- package/dist/wgpuScale9Sprite.js.map +1 -1
- package/dist/wgpuShape.d.ts +4 -3
- package/dist/wgpuShape.d.ts.map +1 -1
- package/dist/wgpuShape.js +7 -7
- package/dist/wgpuShape.js.map +1 -1
- package/dist/wgpuShapeData.d.ts +8 -3
- package/dist/wgpuShapeData.d.ts.map +1 -1
- package/dist/wgpuShapeData.js +12 -9
- package/dist/wgpuShapeData.js.map +1 -1
- package/dist/wgpuShapeMesh.d.ts +4 -2
- package/dist/wgpuShapeMesh.d.ts.map +1 -1
- package/dist/wgpuShapeMesh.js +9 -8
- package/dist/wgpuShapeMesh.js.map +1 -1
- package/dist/wgpuShapeRasterizer.d.ts +2 -1
- package/dist/wgpuShapeRasterizer.d.ts.map +1 -1
- package/dist/wgpuShapeRasterizer.js +3 -8
- package/dist/wgpuShapeRasterizer.js.map +1 -1
- package/dist/wgpuSprite.d.ts +3 -2
- package/dist/wgpuSprite.d.ts.map +1 -1
- package/dist/wgpuSprite.js +7 -8
- package/dist/wgpuSprite.js.map +1 -1
- package/dist/wgpuStandardMaterial.d.ts +2 -2
- package/dist/wgpuStandardMaterial.d.ts.map +1 -1
- package/dist/wgpuStandardMaterial.js +5 -5
- package/dist/wgpuStandardMaterial.js.map +1 -1
- package/dist/wgpuTextInput.d.ts +2 -1
- package/dist/wgpuTextInput.d.ts.map +1 -1
- package/dist/wgpuTextInput.js +6 -7
- package/dist/wgpuTextInput.js.map +1 -1
- package/dist/wgpuTextLabel.d.ts +3 -2
- package/dist/wgpuTextLabel.d.ts.map +1 -1
- package/dist/wgpuTextLabel.js +67 -35
- package/dist/wgpuTextLabel.js.map +1 -1
- package/dist/wgpuTilemap.d.ts +2 -2
- package/dist/wgpuTilemap.d.ts.map +1 -1
- package/dist/wgpuTilemap.js +6 -6
- package/dist/wgpuTilemap.js.map +1 -1
- package/dist/wgpuVelocity.d.ts +10 -7
- package/dist/wgpuVelocity.d.ts.map +1 -1
- package/dist/wgpuVelocity.js +89 -87
- package/dist/wgpuVelocity.js.map +1 -1
- package/package.json +31 -25
- package/src/contract.test.ts +13 -0
- package/src/enableWgpuColorAdjustmentGuards.test.ts +50 -28
- package/src/enableWgpuStrokePathTessellation.test.ts +4 -9
- package/src/scene2DWgpuPipeline.test.ts +53 -0
- package/src/wgpuBitmapText.test.ts +10 -10
- package/src/wgpuCache.test.ts +130 -168
- package/src/wgpuClip.test.ts +1 -1
- package/src/wgpuClipContours.test.ts +13 -6
- package/src/wgpuClipRectangle.test.ts +8 -8
- package/src/wgpuColorAdjustmentMaterialFeature.test.ts +20 -19
- package/src/wgpuMeshShapeRenderer.test.ts +51 -52
- package/src/wgpuNode2D.test.ts +14 -14
- package/src/wgpuParticleEmitter2D.test.ts +52 -45
- package/src/wgpuQuadBatch.test.ts +62 -60
- package/src/wgpuQuadBatchWriter.test.ts +76 -34
- package/src/wgpuRasterShapeRenderer.test.ts +95 -57
- package/src/wgpuRenderStats.test.ts +1 -1
- package/src/wgpuRendererData.test.ts +2 -2
- package/src/wgpuRichText.test.ts +109 -58
- package/src/wgpuScale9Mapper.test.ts +1 -1
- package/src/wgpuScale9Shape.test.ts +103 -62
- package/src/wgpuScale9Sprite.test.ts +31 -36
- package/src/wgpuShape.test.ts +111 -76
- package/src/wgpuShapeData.test.ts +96 -53
- package/src/wgpuShapeMesh.test.ts +39 -25
- package/src/wgpuShapeRasterizer.test.ts +11 -7
- package/src/wgpuSprite.test.ts +36 -27
- package/src/wgpuStandardMaterial.test.ts +9 -13
- package/src/wgpuTextInput.test.ts +9 -6
- package/src/wgpuTextLabel.test.ts +145 -88
- package/src/wgpuTilemap.test.ts +11 -11
- package/src/wgpuVelocity.test.ts +86 -86
- package/dist/scene2dWgpuPipeline.d.ts +0 -3
- package/dist/scene2dWgpuPipeline.d.ts.map +0 -1
- package/dist/scene2dWgpuPipeline.js +0 -40
- package/dist/scene2dWgpuPipeline.js.map +0 -1
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ColorScaleBias } from '@flighthq/adjustments/contract';
|
|
2
|
+
import { EntityRuntimeKey } from '@flighthq/entity/contract';
|
|
3
|
+
import type { Material } from '@flighthq/materials/contract';
|
|
4
|
+
import { BlendMode } from '@flighthq/materials/contract';
|
|
5
|
+
import { beginWgpuScreenRenderPassForTest, submitWgpuFrame } from '@flighthq/render-wgpu/contract';
|
|
2
6
|
import { getWgpuRenderStateRuntime } from '@flighthq/render-wgpu/contract';
|
|
3
7
|
import { createWgpuRenderStateForTest, installWgpuMock } from '@flighthq/render-wgpu/contract';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
import type {
|
|
9
|
+
WgpuRenderPipelineDescriptor,
|
|
10
|
+
WgpuTexture,
|
|
11
|
+
WgpuTextureEntry,
|
|
12
|
+
WgpuTextureView,
|
|
13
|
+
} from '@flighthq/render-wgpu/contract';
|
|
14
|
+
|
|
15
|
+
import { registerWgpuColorAdjustmentMaterialFeature } from './wgpuColorAdjustmentMaterialFeature.ts';
|
|
8
16
|
import {
|
|
9
17
|
ensureWgpuQuadBatchResources,
|
|
10
18
|
flushWgpuQuadBatchWriter,
|
|
@@ -16,8 +24,9 @@ import {
|
|
|
16
24
|
resetWgpuQuadBatchWriterBufferPool,
|
|
17
25
|
writeWgpuQuadBatchAffineInstance,
|
|
18
26
|
writeWgpuQuadBatchInstance,
|
|
19
|
-
} from './wgpuQuadBatchWriter';
|
|
20
|
-
import {
|
|
27
|
+
} from './wgpuQuadBatchWriter.ts';
|
|
28
|
+
import { getWgpuRenderStats, resetWgpuRenderStats } from './wgpuRenderStats.ts';
|
|
29
|
+
import { standardWgpuQuadMaterialRenderer } from './wgpuStandardMaterial.ts';
|
|
21
30
|
|
|
22
31
|
beforeAll(() => {
|
|
23
32
|
installWgpuMock();
|
|
@@ -32,8 +41,8 @@ function makeTexture(): WgpuTextureEntry {
|
|
|
32
41
|
[EntityRuntimeKey]: undefined,
|
|
33
42
|
bindings: new Map(),
|
|
34
43
|
mipLevelCount: 1,
|
|
35
|
-
texture: {} as
|
|
36
|
-
view: {} as
|
|
44
|
+
texture: {} as WgpuTexture,
|
|
45
|
+
view: {} as WgpuTextureView,
|
|
37
46
|
};
|
|
38
47
|
}
|
|
39
48
|
|
|
@@ -84,18 +93,18 @@ describe('ensureWgpuQuadBatchResources', () => {
|
|
|
84
93
|
describe('flushWgpuQuadBatchWriter', () => {
|
|
85
94
|
it('does nothing when batch count is zero', async () => {
|
|
86
95
|
const state = await createWgpuRenderStateForTest();
|
|
87
|
-
|
|
96
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
88
97
|
expect(() => flushWgpuQuadBatchWriter(state)).not.toThrow();
|
|
89
|
-
|
|
98
|
+
submitWgpuFrame(state);
|
|
90
99
|
});
|
|
91
100
|
|
|
92
101
|
it('resets state after flush', async () => {
|
|
93
102
|
const state = await createWgpuRenderStateForTest();
|
|
94
|
-
|
|
103
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
95
104
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
96
105
|
const tex = makeTexture();
|
|
97
106
|
|
|
98
|
-
prepareWgpuQuadBatchWrite(state, tex, null, null, null,
|
|
107
|
+
prepareWgpuQuadBatchWrite(state, tex, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
99
108
|
runtime.quadBatchWriterCount = 1;
|
|
100
109
|
flushWgpuQuadBatchWriter(state);
|
|
101
110
|
|
|
@@ -103,23 +112,56 @@ describe('flushWgpuQuadBatchWriter', () => {
|
|
|
103
112
|
expect(runtime.quadBatchWriterTexture).toBeNull();
|
|
104
113
|
expect(runtime.quadBatchWriterBlendMode).toBeNull();
|
|
105
114
|
expect(runtime.quadBatchWriterMaterial).toBeNull();
|
|
106
|
-
|
|
115
|
+
submitWgpuFrame(state);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('records the flush in render stats, from the LIVE draw path', async () => {
|
|
119
|
+
// The stats functions were unit-tested by calling recordWgpuBatchFlush directly, which is why the
|
|
120
|
+
// production path could reach here recording nothing at all and every test still pass. This drives
|
|
121
|
+
// the real flush and asserts the counters moved.
|
|
122
|
+
const state = await createWgpuRenderStateForTest();
|
|
123
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
124
|
+
const runtime = getWgpuRenderStateRuntime(state);
|
|
125
|
+
resetWgpuRenderStats(state);
|
|
126
|
+
|
|
127
|
+
prepareWgpuQuadBatchWrite(state, makeTexture(), null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
128
|
+
runtime.quadBatchWriterCount = 3;
|
|
129
|
+
flushWgpuQuadBatchWriter(state);
|
|
130
|
+
|
|
131
|
+
const stats = getWgpuRenderStats(state);
|
|
132
|
+
expect(stats.batchFlushCount).toBe(1);
|
|
133
|
+
expect(stats.drawCallCount).toBe(1);
|
|
134
|
+
// The instance count is the batch size, not one per flush — a caller reading this to size buffers
|
|
135
|
+
// needs the quads, not the draws.
|
|
136
|
+
expect(stats.instanceCount).toBe(3);
|
|
137
|
+
submitWgpuFrame(state);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('records nothing when the flush issues no draw', async () => {
|
|
141
|
+
// An empty writer returns early without drawing. Counting that would report batches the GPU never
|
|
142
|
+
// saw, which is worse than not counting at all: it makes a frame look busier than it was.
|
|
143
|
+
const state = await createWgpuRenderStateForTest();
|
|
144
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
145
|
+
resetWgpuRenderStats(state);
|
|
146
|
+
flushWgpuQuadBatchWriter(state);
|
|
147
|
+
expect(getWgpuRenderStats(state).batchFlushCount).toBe(0);
|
|
148
|
+
submitWgpuFrame(state);
|
|
107
149
|
});
|
|
108
150
|
|
|
109
151
|
it('claims a distinct buffer per flush so deferred draws never share one', async () => {
|
|
110
152
|
// The canvas pass is submitted once at end of frame; if successive flushes reused one instance
|
|
111
153
|
// buffer, every draw would read the last flush's data and the batch would collapse to one spot.
|
|
112
154
|
const state = await createWgpuRenderStateForTest();
|
|
113
|
-
|
|
155
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
114
156
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
115
157
|
const tex1 = makeTexture();
|
|
116
158
|
const tex2 = makeTexture();
|
|
117
159
|
|
|
118
|
-
prepareWgpuQuadBatchWrite(state, tex1, null, null, null,
|
|
160
|
+
prepareWgpuQuadBatchWrite(state, tex1, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
119
161
|
runtime.quadBatchWriterCount = 1;
|
|
120
162
|
flushWgpuQuadBatchWriter(state);
|
|
121
163
|
|
|
122
|
-
prepareWgpuQuadBatchWrite(state, tex2, null, null, null,
|
|
164
|
+
prepareWgpuQuadBatchWrite(state, tex2, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
123
165
|
runtime.quadBatchWriterCount = 1;
|
|
124
166
|
flushWgpuQuadBatchWriter(state);
|
|
125
167
|
|
|
@@ -128,7 +170,7 @@ describe('flushWgpuQuadBatchWriter', () => {
|
|
|
128
170
|
expect(runtime.quadBatchWriterBufferPool[0].instanceBuffer).not.toBe(
|
|
129
171
|
runtime.quadBatchWriterBufferPool[1].instanceBuffer,
|
|
130
172
|
);
|
|
131
|
-
|
|
173
|
+
submitWgpuFrame(state);
|
|
132
174
|
});
|
|
133
175
|
});
|
|
134
176
|
|
|
@@ -149,7 +191,7 @@ describe('getWgpuQuadBatchPipeline', () => {
|
|
|
149
191
|
const module = state.device.createShaderModule({ code: '' });
|
|
150
192
|
const blendOf = (mode: BlendMode) => {
|
|
151
193
|
const pipeline = getWgpuQuadBatchPipeline(state, resources, module, false, mode) as unknown as {
|
|
152
|
-
__descriptor:
|
|
194
|
+
__descriptor: WgpuRenderPipelineDescriptor;
|
|
153
195
|
};
|
|
154
196
|
return [...pipeline.__descriptor.fragment!.targets][0]!.blend!.color;
|
|
155
197
|
};
|
|
@@ -191,41 +233,41 @@ describe('prepareWgpuQuadBatchWrite', () => {
|
|
|
191
233
|
const state = await createWgpuRenderStateForTest();
|
|
192
234
|
const tex = makeTexture();
|
|
193
235
|
|
|
194
|
-
const base = prepareWgpuQuadBatchWrite(state, tex, null, null, null,
|
|
236
|
+
const base = prepareWgpuQuadBatchWrite(state, tex, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
195
237
|
expect(base).toBe(0);
|
|
196
238
|
});
|
|
197
239
|
|
|
198
240
|
it('flushes when texture changes', async () => {
|
|
199
241
|
const state = await createWgpuRenderStateForTest();
|
|
200
|
-
|
|
242
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
201
243
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
202
244
|
const tex1 = makeTexture();
|
|
203
245
|
const tex2 = makeTexture();
|
|
204
246
|
|
|
205
|
-
prepareWgpuQuadBatchWrite(state, tex1, null, null, null,
|
|
247
|
+
prepareWgpuQuadBatchWrite(state, tex1, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
206
248
|
runtime.quadBatchWriterCount = 1;
|
|
207
|
-
prepareWgpuQuadBatchWrite(state, tex2, null, null, null,
|
|
249
|
+
prepareWgpuQuadBatchWrite(state, tex2, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
208
250
|
|
|
209
251
|
expect(runtime.quadBatchWriterTexture).toBe(tex2);
|
|
210
252
|
expect(runtime.quadBatchWriterCount).toBe(0);
|
|
211
|
-
|
|
253
|
+
submitWgpuFrame(state);
|
|
212
254
|
});
|
|
213
255
|
|
|
214
256
|
it('flushes when material changes', async () => {
|
|
215
257
|
const state = await createWgpuRenderStateForTest();
|
|
216
|
-
|
|
258
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
217
259
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
218
260
|
const tex = makeTexture();
|
|
219
261
|
const materialA = makeMaterial();
|
|
220
262
|
const materialB = makeMaterial();
|
|
221
263
|
|
|
222
|
-
prepareWgpuQuadBatchWrite(state, tex, null, null, materialA,
|
|
264
|
+
prepareWgpuQuadBatchWrite(state, tex, null, null, materialA, standardWgpuQuadMaterialRenderer, 1);
|
|
223
265
|
runtime.quadBatchWriterCount = 1;
|
|
224
|
-
prepareWgpuQuadBatchWrite(state, tex, null, null, materialB,
|
|
266
|
+
prepareWgpuQuadBatchWrite(state, tex, null, null, materialB, standardWgpuQuadMaterialRenderer, 1);
|
|
225
267
|
|
|
226
268
|
expect(runtime.quadBatchWriterMaterial).toBe(materialB);
|
|
227
269
|
expect(runtime.quadBatchWriterCount).toBe(0);
|
|
228
|
-
|
|
270
|
+
submitWgpuFrame(state);
|
|
229
271
|
});
|
|
230
272
|
});
|
|
231
273
|
|
|
@@ -255,32 +297,32 @@ describe('recordWgpuQuadBatchColorScaleBias', () => {
|
|
|
255
297
|
it('an untinted batch on flush uses the lean material module (no fold)', async () => {
|
|
256
298
|
const state = await createWgpuRenderStateForTest();
|
|
257
299
|
registerWgpuColorAdjustmentMaterialFeature(state);
|
|
258
|
-
|
|
300
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
259
301
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
260
302
|
const tex = makeTexture();
|
|
261
|
-
prepareWgpuQuadBatchWrite(state, tex, null, null, null,
|
|
303
|
+
prepareWgpuQuadBatchWrite(state, tex, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
262
304
|
recordWgpuQuadBatchColorScaleBias(state, null, 0);
|
|
263
305
|
runtime.quadBatchWriterCount = 1;
|
|
264
306
|
expect(() => flushWgpuQuadBatchWriter(state)).not.toThrow();
|
|
265
|
-
|
|
307
|
+
submitWgpuFrame(state);
|
|
266
308
|
});
|
|
267
309
|
});
|
|
268
310
|
|
|
269
311
|
describe('resetWgpuQuadBatchWriterBufferPool', () => {
|
|
270
312
|
it('rewinds the pool cursor so slots are reclaimed next frame', async () => {
|
|
271
313
|
const state = await createWgpuRenderStateForTest();
|
|
272
|
-
|
|
314
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
273
315
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
274
316
|
const tex = makeTexture();
|
|
275
317
|
|
|
276
|
-
prepareWgpuQuadBatchWrite(state, tex, null, null, null,
|
|
318
|
+
prepareWgpuQuadBatchWrite(state, tex, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
277
319
|
runtime.quadBatchWriterCount = 1;
|
|
278
320
|
flushWgpuQuadBatchWriter(state);
|
|
279
321
|
expect(runtime.quadBatchWriterBufferCursor).toBe(1);
|
|
280
322
|
|
|
281
323
|
resetWgpuQuadBatchWriterBufferPool(state);
|
|
282
324
|
expect(runtime.quadBatchWriterBufferCursor).toBe(0);
|
|
283
|
-
|
|
325
|
+
submitWgpuFrame(state);
|
|
284
326
|
});
|
|
285
327
|
});
|
|
286
328
|
|
|
@@ -1,15 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createImageResource,
|
|
3
|
+
registerTestImageDimensionResolver,
|
|
4
|
+
unregisterTestImageDimensionResolver,
|
|
5
|
+
} from '@flighthq/image/contract';
|
|
6
|
+
import type { HostImageCapability } from '@flighthq/image/contract';
|
|
2
7
|
import * as flightNode from '@flighthq/node/contract';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
import {
|
|
9
|
+
beginWgpuScreenRenderPassForTest,
|
|
10
|
+
createWgpuRenderStateForTest,
|
|
11
|
+
getWgpuRenderStateRuntime,
|
|
12
|
+
installWgpuMock,
|
|
13
|
+
} from '@flighthq/render-wgpu/contract';
|
|
14
|
+
import type { WgpuRenderPassEncoder } from '@flighthq/render-wgpu/contract';
|
|
15
|
+
import { enableRenderRegistriesGuards, explainRenderRegistriesMisses, BatchFormat } from '@flighthq/render/contract';
|
|
16
|
+
import { RenderRegistryTable } from '@flighthq/render/contract';
|
|
17
|
+
import type { RenderProxy2D } from '@flighthq/render/contract';
|
|
6
18
|
import { appendShapeBeginFill, appendShapeEndFill, appendShapeRectangle, createShape } from '@flighthq/shape/contract';
|
|
7
|
-
import type {
|
|
8
|
-
import { BatchFormat, EntityRuntimeKey, RenderRegistry } from '@flighthq/types/contract';
|
|
19
|
+
import type { CanvasSurface, HostCanvasCapability } from '@flighthq/surface/contract';
|
|
9
20
|
|
|
10
|
-
import {
|
|
11
|
-
import { registerWgpuShapeRasterizer } from './wgpuShapeRasterizer';
|
|
12
|
-
import { registerWgpuStandardMaterial } from './wgpuStandardMaterial';
|
|
21
|
+
import { wgpuRasterShapeRenderer, drawWgpuRasterShape } from './wgpuRasterShapeRenderer.ts';
|
|
22
|
+
import { registerWgpuShapeRasterizer } from './wgpuShapeRasterizer.ts';
|
|
23
|
+
import { registerWgpuStandardMaterial } from './wgpuStandardMaterial.ts';
|
|
24
|
+
|
|
25
|
+
// A test that wraps a host handle supplies the host: the resource measures through the registered
|
|
26
|
+
// resolver, and clearing after each test keeps this file from covering for another's missing one.
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
registerTestImageDimensionResolver();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
unregisterTestImageDimensionResolver();
|
|
33
|
+
});
|
|
13
34
|
|
|
14
35
|
beforeAll(() => installWgpuMock());
|
|
15
36
|
|
|
@@ -29,38 +50,55 @@ afterEach(() => {
|
|
|
29
50
|
vi.restoreAllMocks();
|
|
30
51
|
});
|
|
31
52
|
|
|
32
|
-
function
|
|
53
|
+
function createTestSurface(width: number, height: number): CanvasSurface {
|
|
54
|
+
const canvas = document.createElement('canvas');
|
|
55
|
+
canvas.width = width;
|
|
56
|
+
canvas.height = height;
|
|
57
|
+
const context = canvas.getContext('2d')!;
|
|
33
58
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
canvas.
|
|
39
|
-
const context = canvas.getContext('2d')!;
|
|
40
|
-
return {
|
|
41
|
-
[EntityRuntimeKey]: undefined,
|
|
42
|
-
get width() {
|
|
43
|
-
return canvas.width;
|
|
44
|
-
},
|
|
45
|
-
set width(value: number) {
|
|
46
|
-
canvas.width = value;
|
|
47
|
-
},
|
|
48
|
-
get height() {
|
|
49
|
-
return canvas.height;
|
|
50
|
-
},
|
|
51
|
-
set height(value: number) {
|
|
52
|
-
canvas.height = value;
|
|
53
|
-
},
|
|
54
|
-
context,
|
|
55
|
-
image: createImageResource(canvas),
|
|
56
|
-
};
|
|
59
|
+
get width() {
|
|
60
|
+
return canvas.width;
|
|
61
|
+
},
|
|
62
|
+
set width(value: number) {
|
|
63
|
+
canvas.width = value;
|
|
57
64
|
},
|
|
58
|
-
|
|
65
|
+
get height() {
|
|
66
|
+
return canvas.height;
|
|
67
|
+
},
|
|
68
|
+
set height(value: number) {
|
|
69
|
+
canvas.height = value;
|
|
70
|
+
},
|
|
71
|
+
context,
|
|
72
|
+
} as unknown as CanvasSurface;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function createTestCanvasHost(): HostCanvasCapability {
|
|
76
|
+
return {
|
|
77
|
+
acquire: () => null,
|
|
78
|
+
create: () => null,
|
|
79
|
+
createSurface: createTestSurface,
|
|
80
|
+
destroySurface() {},
|
|
81
|
+
release() {},
|
|
59
82
|
};
|
|
60
83
|
}
|
|
61
84
|
|
|
85
|
+
function createTestImageHost(): HostImageCapability {
|
|
86
|
+
return {
|
|
87
|
+
createImageFromSurface(surface) {
|
|
88
|
+
return createImageResource((surface as unknown as { context: CanvasRenderingContext2D }).context.canvas);
|
|
89
|
+
},
|
|
90
|
+
loadImageFromUrl: () => Promise.reject(new Error('not implemented')),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function setTestHosts(state: { canvasHost: unknown; imageHost: unknown }): void {
|
|
95
|
+
state.canvasHost = createTestCanvasHost();
|
|
96
|
+
state.imageHost = createTestImageHost();
|
|
97
|
+
}
|
|
98
|
+
|
|
62
99
|
function makeShapeData() {
|
|
63
100
|
return {
|
|
101
|
+
image: null,
|
|
64
102
|
surface: null,
|
|
65
103
|
lastContentId: -1,
|
|
66
104
|
lastPixelRatio: 0,
|
|
@@ -93,7 +131,7 @@ function makeShapeProxy(data: Record<string, unknown>, rendererData: unknown = m
|
|
|
93
131
|
} as unknown as RenderProxy2D;
|
|
94
132
|
}
|
|
95
133
|
|
|
96
|
-
function makeMeshPassSpy():
|
|
134
|
+
function makeMeshPassSpy(): WgpuRenderPassEncoder {
|
|
97
135
|
return {
|
|
98
136
|
setPipeline: vi.fn(),
|
|
99
137
|
setBindGroup: vi.fn(),
|
|
@@ -103,7 +141,7 @@ function makeMeshPassSpy(): GPURenderPassEncoder {
|
|
|
103
141
|
draw: vi.fn(),
|
|
104
142
|
drawIndexed: vi.fn(),
|
|
105
143
|
end: vi.fn(),
|
|
106
|
-
} as unknown as
|
|
144
|
+
} as unknown as WgpuRenderPassEncoder;
|
|
107
145
|
}
|
|
108
146
|
|
|
109
147
|
// A plain solid rectangle — precisely the shape the mesh strategy would tessellate.
|
|
@@ -115,20 +153,11 @@ function solidShape() {
|
|
|
115
153
|
return shape;
|
|
116
154
|
}
|
|
117
155
|
|
|
118
|
-
describe('defaultWgpuRasterShapeRenderer', () => {
|
|
119
|
-
it('declares BatchFormat.Quad and the shared shape data lifecycle', () => {
|
|
120
|
-
expect(defaultWgpuRasterShapeRenderer.format).toBe(BatchFormat.Quad);
|
|
121
|
-
expect(typeof defaultWgpuRasterShapeRenderer.createData).toBe('function');
|
|
122
|
-
expect(typeof defaultWgpuRasterShapeRenderer.destroyData).toBe('function');
|
|
123
|
-
expect(defaultWgpuRasterShapeRenderer.submit).toBe(drawWgpuRasterShape);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
156
|
describe('drawWgpuRasterShape', () => {
|
|
128
157
|
it('rasterizes a fill the mesh path could have tessellated, which is what pinning this strategy means', async () => {
|
|
129
158
|
const state = await createWgpuRenderStateForTest();
|
|
130
|
-
state
|
|
131
|
-
|
|
159
|
+
setTestHosts(state);
|
|
160
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
132
161
|
registerWgpuStandardMaterial(state);
|
|
133
162
|
const pass = makeMeshPassSpy();
|
|
134
163
|
getWgpuRenderStateRuntime(state).renderPass = pass;
|
|
@@ -144,8 +173,8 @@ describe('drawWgpuRasterShape', () => {
|
|
|
144
173
|
|
|
145
174
|
it('replays the whole command stream, not the subset a mesh path could not express', async () => {
|
|
146
175
|
const state = await createWgpuRenderStateForTest();
|
|
147
|
-
state
|
|
148
|
-
|
|
176
|
+
setTestHosts(state);
|
|
177
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
149
178
|
registerWgpuStandardMaterial(state);
|
|
150
179
|
getWgpuRenderStateRuntime(state).renderPass = makeMeshPassSpy();
|
|
151
180
|
const shape = solidShape();
|
|
@@ -161,22 +190,22 @@ describe('drawWgpuRasterShape', () => {
|
|
|
161
190
|
|
|
162
191
|
it('reports a ShapeRasterizer miss when no rasterizer is registered', async () => {
|
|
163
192
|
const state = await createWgpuRenderStateForTest();
|
|
164
|
-
state
|
|
165
|
-
|
|
193
|
+
setTestHosts(state);
|
|
194
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
166
195
|
getWgpuRenderStateRuntime(state).renderPass = makeMeshPassSpy();
|
|
167
|
-
|
|
196
|
+
enableRenderRegistriesGuards(state, null);
|
|
168
197
|
|
|
169
198
|
drawWgpuRasterShape(state, makeShapeProxy({ commands: solidShape().data.commands, version: 1 }));
|
|
170
199
|
|
|
171
|
-
expect(
|
|
200
|
+
expect(explainRenderRegistriesMisses(state).misses).toContainEqual({
|
|
172
201
|
kind: 'Shape',
|
|
173
|
-
registry:
|
|
202
|
+
registry: RenderRegistryTable.ShapeRasterizer,
|
|
174
203
|
});
|
|
175
204
|
});
|
|
176
205
|
|
|
177
206
|
it('preserves expected surface absence without rasterizing or writing a batch', async () => {
|
|
178
207
|
const state = await createWgpuRenderStateForTest();
|
|
179
|
-
|
|
208
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
180
209
|
registerWgpuStandardMaterial(state);
|
|
181
210
|
getWgpuRenderStateRuntime(state).renderPass = makeMeshPassSpy();
|
|
182
211
|
const rasterizer = vi.fn();
|
|
@@ -190,8 +219,8 @@ describe('drawWgpuRasterShape', () => {
|
|
|
190
219
|
|
|
191
220
|
it('does nothing without a render pass, for an empty command list, or with absent renderer data', async () => {
|
|
192
221
|
const state = await createWgpuRenderStateForTest();
|
|
193
|
-
state
|
|
194
|
-
|
|
222
|
+
setTestHosts(state);
|
|
223
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
195
224
|
registerWgpuStandardMaterial(state);
|
|
196
225
|
const rasterizer = vi.fn();
|
|
197
226
|
registerWgpuShapeRasterizer(state, rasterizer);
|
|
@@ -205,3 +234,12 @@ describe('drawWgpuRasterShape', () => {
|
|
|
205
234
|
expect(rasterizer).not.toHaveBeenCalled();
|
|
206
235
|
});
|
|
207
236
|
});
|
|
237
|
+
|
|
238
|
+
describe('wgpuRasterShapeRenderer', () => {
|
|
239
|
+
it('declares BatchFormat.Quad and the shared shape data lifecycle', () => {
|
|
240
|
+
expect(wgpuRasterShapeRenderer.format).toBe(BatchFormat.Quad);
|
|
241
|
+
expect(typeof wgpuRasterShapeRenderer.createData).toBe('function');
|
|
242
|
+
expect(typeof wgpuRasterShapeRenderer.destroyData).toBe('function');
|
|
243
|
+
expect(wgpuRasterShapeRenderer.submit).toBe(drawWgpuRasterShape);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EntityRuntimeKey } from '@flighthq/
|
|
1
|
+
import { EntityRuntimeKey } from '@flighthq/entity/contract';
|
|
2
2
|
|
|
3
|
-
import { createWgpuRendererData, getWgpuRendererData, initializeWgpuRendererData } from './wgpuRendererData';
|
|
3
|
+
import { createWgpuRendererData, getWgpuRendererData, initializeWgpuRendererData } from './wgpuRendererData.ts';
|
|
4
4
|
|
|
5
5
|
describe('createWgpuRendererData', () => {
|
|
6
6
|
it('adds the RendererData entity slot to the input object', () => {
|