@flighthq/scene2d-wgpu 0.5.1-next.920.da8f530 → 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 +20 -19
- 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 +26 -14
- 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 +29 -25
- package/dist/wgpuQuadBatch.js.map +1 -1
- package/dist/wgpuQuadBatchWriter.d.ts +11 -5
- package/dist/wgpuQuadBatchWriter.d.ts.map +1 -1
- package/dist/wgpuQuadBatchWriter.js +45 -19
- 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 +49 -35
- 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 +30 -36
- 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 +17 -32
- 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 +68 -48
- 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 +20 -19
- 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 +95 -90
- package/dist/wgpuVelocity.js.map +1 -1
- package/package.json +31 -24
- 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 +99 -38
- package/src/wgpuQuadBatch.test.ts +126 -32
- package/src/wgpuQuadBatchWriter.test.ts +108 -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 +38 -41
- 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 +67 -24
- 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,
|
|
@@ -14,8 +22,11 @@ import {
|
|
|
14
22
|
prepareWgpuQuadBatchWrite,
|
|
15
23
|
recordWgpuQuadBatchColorScaleBias,
|
|
16
24
|
resetWgpuQuadBatchWriterBufferPool,
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
writeWgpuQuadBatchAffineInstance,
|
|
26
|
+
writeWgpuQuadBatchInstance,
|
|
27
|
+
} from './wgpuQuadBatchWriter.ts';
|
|
28
|
+
import { getWgpuRenderStats, resetWgpuRenderStats } from './wgpuRenderStats.ts';
|
|
29
|
+
import { standardWgpuQuadMaterialRenderer } from './wgpuStandardMaterial.ts';
|
|
19
30
|
|
|
20
31
|
beforeAll(() => {
|
|
21
32
|
installWgpuMock();
|
|
@@ -30,8 +41,8 @@ function makeTexture(): WgpuTextureEntry {
|
|
|
30
41
|
[EntityRuntimeKey]: undefined,
|
|
31
42
|
bindings: new Map(),
|
|
32
43
|
mipLevelCount: 1,
|
|
33
|
-
texture: {} as
|
|
34
|
-
view: {} as
|
|
44
|
+
texture: {} as WgpuTexture,
|
|
45
|
+
view: {} as WgpuTextureView,
|
|
35
46
|
};
|
|
36
47
|
}
|
|
37
48
|
|
|
@@ -82,18 +93,18 @@ describe('ensureWgpuQuadBatchResources', () => {
|
|
|
82
93
|
describe('flushWgpuQuadBatchWriter', () => {
|
|
83
94
|
it('does nothing when batch count is zero', async () => {
|
|
84
95
|
const state = await createWgpuRenderStateForTest();
|
|
85
|
-
|
|
96
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
86
97
|
expect(() => flushWgpuQuadBatchWriter(state)).not.toThrow();
|
|
87
|
-
|
|
98
|
+
submitWgpuFrame(state);
|
|
88
99
|
});
|
|
89
100
|
|
|
90
101
|
it('resets state after flush', async () => {
|
|
91
102
|
const state = await createWgpuRenderStateForTest();
|
|
92
|
-
|
|
103
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
93
104
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
94
105
|
const tex = makeTexture();
|
|
95
106
|
|
|
96
|
-
prepareWgpuQuadBatchWrite(state, tex, null, null, null,
|
|
107
|
+
prepareWgpuQuadBatchWrite(state, tex, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
97
108
|
runtime.quadBatchWriterCount = 1;
|
|
98
109
|
flushWgpuQuadBatchWriter(state);
|
|
99
110
|
|
|
@@ -101,23 +112,56 @@ describe('flushWgpuQuadBatchWriter', () => {
|
|
|
101
112
|
expect(runtime.quadBatchWriterTexture).toBeNull();
|
|
102
113
|
expect(runtime.quadBatchWriterBlendMode).toBeNull();
|
|
103
114
|
expect(runtime.quadBatchWriterMaterial).toBeNull();
|
|
104
|
-
|
|
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);
|
|
105
149
|
});
|
|
106
150
|
|
|
107
151
|
it('claims a distinct buffer per flush so deferred draws never share one', async () => {
|
|
108
152
|
// The canvas pass is submitted once at end of frame; if successive flushes reused one instance
|
|
109
153
|
// buffer, every draw would read the last flush's data and the batch would collapse to one spot.
|
|
110
154
|
const state = await createWgpuRenderStateForTest();
|
|
111
|
-
|
|
155
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
112
156
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
113
157
|
const tex1 = makeTexture();
|
|
114
158
|
const tex2 = makeTexture();
|
|
115
159
|
|
|
116
|
-
prepareWgpuQuadBatchWrite(state, tex1, null, null, null,
|
|
160
|
+
prepareWgpuQuadBatchWrite(state, tex1, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
117
161
|
runtime.quadBatchWriterCount = 1;
|
|
118
162
|
flushWgpuQuadBatchWriter(state);
|
|
119
163
|
|
|
120
|
-
prepareWgpuQuadBatchWrite(state, tex2, null, null, null,
|
|
164
|
+
prepareWgpuQuadBatchWrite(state, tex2, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
121
165
|
runtime.quadBatchWriterCount = 1;
|
|
122
166
|
flushWgpuQuadBatchWriter(state);
|
|
123
167
|
|
|
@@ -126,7 +170,7 @@ describe('flushWgpuQuadBatchWriter', () => {
|
|
|
126
170
|
expect(runtime.quadBatchWriterBufferPool[0].instanceBuffer).not.toBe(
|
|
127
171
|
runtime.quadBatchWriterBufferPool[1].instanceBuffer,
|
|
128
172
|
);
|
|
129
|
-
|
|
173
|
+
submitWgpuFrame(state);
|
|
130
174
|
});
|
|
131
175
|
});
|
|
132
176
|
|
|
@@ -147,7 +191,7 @@ describe('getWgpuQuadBatchPipeline', () => {
|
|
|
147
191
|
const module = state.device.createShaderModule({ code: '' });
|
|
148
192
|
const blendOf = (mode: BlendMode) => {
|
|
149
193
|
const pipeline = getWgpuQuadBatchPipeline(state, resources, module, false, mode) as unknown as {
|
|
150
|
-
__descriptor:
|
|
194
|
+
__descriptor: WgpuRenderPipelineDescriptor;
|
|
151
195
|
};
|
|
152
196
|
return [...pipeline.__descriptor.fragment!.targets][0]!.blend!.color;
|
|
153
197
|
};
|
|
@@ -189,41 +233,41 @@ describe('prepareWgpuQuadBatchWrite', () => {
|
|
|
189
233
|
const state = await createWgpuRenderStateForTest();
|
|
190
234
|
const tex = makeTexture();
|
|
191
235
|
|
|
192
|
-
const base = prepareWgpuQuadBatchWrite(state, tex, null, null, null,
|
|
236
|
+
const base = prepareWgpuQuadBatchWrite(state, tex, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
193
237
|
expect(base).toBe(0);
|
|
194
238
|
});
|
|
195
239
|
|
|
196
240
|
it('flushes when texture changes', async () => {
|
|
197
241
|
const state = await createWgpuRenderStateForTest();
|
|
198
|
-
|
|
242
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
199
243
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
200
244
|
const tex1 = makeTexture();
|
|
201
245
|
const tex2 = makeTexture();
|
|
202
246
|
|
|
203
|
-
prepareWgpuQuadBatchWrite(state, tex1, null, null, null,
|
|
247
|
+
prepareWgpuQuadBatchWrite(state, tex1, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
204
248
|
runtime.quadBatchWriterCount = 1;
|
|
205
|
-
prepareWgpuQuadBatchWrite(state, tex2, null, null, null,
|
|
249
|
+
prepareWgpuQuadBatchWrite(state, tex2, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
206
250
|
|
|
207
251
|
expect(runtime.quadBatchWriterTexture).toBe(tex2);
|
|
208
252
|
expect(runtime.quadBatchWriterCount).toBe(0);
|
|
209
|
-
|
|
253
|
+
submitWgpuFrame(state);
|
|
210
254
|
});
|
|
211
255
|
|
|
212
256
|
it('flushes when material changes', async () => {
|
|
213
257
|
const state = await createWgpuRenderStateForTest();
|
|
214
|
-
|
|
258
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
215
259
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
216
260
|
const tex = makeTexture();
|
|
217
261
|
const materialA = makeMaterial();
|
|
218
262
|
const materialB = makeMaterial();
|
|
219
263
|
|
|
220
|
-
prepareWgpuQuadBatchWrite(state, tex, null, null, materialA,
|
|
264
|
+
prepareWgpuQuadBatchWrite(state, tex, null, null, materialA, standardWgpuQuadMaterialRenderer, 1);
|
|
221
265
|
runtime.quadBatchWriterCount = 1;
|
|
222
|
-
prepareWgpuQuadBatchWrite(state, tex, null, null, materialB,
|
|
266
|
+
prepareWgpuQuadBatchWrite(state, tex, null, null, materialB, standardWgpuQuadMaterialRenderer, 1);
|
|
223
267
|
|
|
224
268
|
expect(runtime.quadBatchWriterMaterial).toBe(materialB);
|
|
225
269
|
expect(runtime.quadBatchWriterCount).toBe(0);
|
|
226
|
-
|
|
270
|
+
submitWgpuFrame(state);
|
|
227
271
|
});
|
|
228
272
|
});
|
|
229
273
|
|
|
@@ -253,31 +297,61 @@ describe('recordWgpuQuadBatchColorScaleBias', () => {
|
|
|
253
297
|
it('an untinted batch on flush uses the lean material module (no fold)', async () => {
|
|
254
298
|
const state = await createWgpuRenderStateForTest();
|
|
255
299
|
registerWgpuColorAdjustmentMaterialFeature(state);
|
|
256
|
-
|
|
300
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
257
301
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
258
302
|
const tex = makeTexture();
|
|
259
|
-
prepareWgpuQuadBatchWrite(state, tex, null, null, null,
|
|
303
|
+
prepareWgpuQuadBatchWrite(state, tex, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
260
304
|
recordWgpuQuadBatchColorScaleBias(state, null, 0);
|
|
261
305
|
runtime.quadBatchWriterCount = 1;
|
|
262
306
|
expect(() => flushWgpuQuadBatchWriter(state)).not.toThrow();
|
|
263
|
-
|
|
307
|
+
submitWgpuFrame(state);
|
|
264
308
|
});
|
|
265
309
|
});
|
|
266
310
|
|
|
267
311
|
describe('resetWgpuQuadBatchWriterBufferPool', () => {
|
|
268
312
|
it('rewinds the pool cursor so slots are reclaimed next frame', async () => {
|
|
269
313
|
const state = await createWgpuRenderStateForTest();
|
|
270
|
-
|
|
314
|
+
beginWgpuScreenRenderPassForTest(state);
|
|
271
315
|
const runtime = getWgpuRenderStateRuntime(state);
|
|
272
316
|
const tex = makeTexture();
|
|
273
317
|
|
|
274
|
-
prepareWgpuQuadBatchWrite(state, tex, null, null, null,
|
|
318
|
+
prepareWgpuQuadBatchWrite(state, tex, null, null, null, standardWgpuQuadMaterialRenderer, 1);
|
|
275
319
|
runtime.quadBatchWriterCount = 1;
|
|
276
320
|
flushWgpuQuadBatchWriter(state);
|
|
277
321
|
expect(runtime.quadBatchWriterBufferCursor).toBe(1);
|
|
278
322
|
|
|
279
323
|
resetWgpuQuadBatchWriterBufferPool(state);
|
|
280
324
|
expect(runtime.quadBatchWriterBufferCursor).toBe(0);
|
|
281
|
-
|
|
325
|
+
submitWgpuFrame(state);
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
describe('writeWgpuQuadBatchAffineInstance', () => {
|
|
330
|
+
it('packs pre-scaled geometry and two affine UV axes into thirteen floats', () => {
|
|
331
|
+
const data = new Float32Array(13);
|
|
332
|
+
writeWgpuQuadBatchAffineInstance(
|
|
333
|
+
data,
|
|
334
|
+
0,
|
|
335
|
+
{ a: 2, b: 3, c: 4, d: 5, tx: 6, ty: 7 },
|
|
336
|
+
10,
|
|
337
|
+
20,
|
|
338
|
+
0.1,
|
|
339
|
+
0.2,
|
|
340
|
+
0.3,
|
|
341
|
+
0.4,
|
|
342
|
+
0.5,
|
|
343
|
+
0.6,
|
|
344
|
+
0.9,
|
|
345
|
+
);
|
|
346
|
+
expect(Array.from(data.slice(0, 6))).toEqual([20, 30, 80, 100, 6, 7]);
|
|
347
|
+
[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.9].forEach((expected, index) => expect(data[index + 6]).toBeCloseTo(expected));
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
describe('writeWgpuQuadBatchInstance', () => {
|
|
352
|
+
it('maps an axis-aligned UV rectangle onto the affine record', () => {
|
|
353
|
+
const data = new Float32Array(13);
|
|
354
|
+
writeWgpuQuadBatchInstance(data, 0, { a: 1, b: 0, c: 0, d: 1, tx: 2, ty: 3 }, 4, 5, 0.1, 0.2, 0.7, 0.8, 0.9);
|
|
355
|
+
[0.1, 0.2, 0.6, 0, 0, 0.6, 0.9].forEach((expected, index) => expect(data[index + 6]).toBeCloseTo(expected));
|
|
282
356
|
});
|
|
283
357
|
});
|
|
@@ -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', () => {
|