@flighthq/render-wgpu 0.5.1-next.1069.554a2ac → 0.5.1-next.1201.9b49dee
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/contract.d.ts +9 -6
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +9 -6
- package/dist/contract.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/wgpuDraw.js +1 -1
- package/dist/wgpuDraw.js.map +1 -1
- package/dist/wgpuFrame.d.ts +23 -0
- package/dist/wgpuFrame.d.ts.map +1 -0
- package/dist/{wgpuBackground.js → wgpuFrame.js} +67 -121
- package/dist/wgpuFrame.js.map +1 -0
- package/dist/wgpuFullscreenPass.d.ts +2 -2
- package/dist/wgpuFullscreenPass.d.ts.map +1 -1
- package/dist/wgpuFullscreenPass.js +1 -2
- package/dist/wgpuFullscreenPass.js.map +1 -1
- package/dist/wgpuHost.d.ts +6 -6
- package/dist/wgpuHost.d.ts.map +1 -1
- package/dist/wgpuHost.js +17 -3
- package/dist/wgpuHost.js.map +1 -1
- package/dist/wgpuRenderPass.d.ts +9 -0
- package/dist/wgpuRenderPass.d.ts.map +1 -0
- package/dist/wgpuRenderPass.js +222 -0
- package/dist/wgpuRenderPass.js.map +1 -0
- package/dist/wgpuRenderState.d.ts +3 -4
- package/dist/wgpuRenderState.d.ts.map +1 -1
- package/dist/wgpuRenderState.js +17 -88
- package/dist/wgpuRenderState.js.map +1 -1
- package/dist/wgpuRenderTarget.d.ts +12 -29
- package/dist/wgpuRenderTarget.d.ts.map +1 -1
- package/dist/wgpuRenderTarget.js +19 -252
- package/dist/wgpuRenderTarget.js.map +1 -1
- package/dist/wgpuRenderTargetPool.d.ts +5 -5
- package/dist/wgpuRenderTargetPool.d.ts.map +1 -1
- package/dist/wgpuRenderTargetPool.js +7 -7
- package/dist/wgpuRenderTargetPool.js.map +1 -1
- package/dist/wgpuRenderTexture.d.ts +5 -4
- package/dist/wgpuRenderTexture.d.ts.map +1 -1
- package/dist/wgpuRenderTexture.js +14 -16
- package/dist/wgpuRenderTexture.js.map +1 -1
- package/dist/wgpuRenderTexturePool.js +1 -3
- package/dist/wgpuRenderTexturePool.js.map +1 -1
- package/dist/wgpuScissor.d.ts +1 -1
- package/dist/wgpuScissor.d.ts.map +1 -1
- package/dist/wgpuScissor.js +7 -4
- package/dist/wgpuScissor.js.map +1 -1
- package/dist/wgpuScreenAntialias.d.ts +3 -0
- package/dist/wgpuScreenAntialias.d.ts.map +1 -0
- package/dist/wgpuScreenAntialias.js +119 -0
- package/dist/wgpuScreenAntialias.js.map +1 -0
- package/dist/wgpuScreenCapture.d.ts +5 -0
- package/dist/wgpuScreenCapture.d.ts.map +1 -0
- package/dist/{wgpuSurface.js → wgpuScreenCapture.js} +55 -73
- package/dist/wgpuScreenCapture.js.map +1 -0
- package/dist/wgpuScreenRenderTarget.d.ts +9 -0
- package/dist/wgpuScreenRenderTarget.d.ts.map +1 -0
- package/dist/wgpuScreenRenderTarget.js +123 -0
- package/dist/wgpuScreenRenderTarget.js.map +1 -0
- package/dist/wgpuShader.js +2 -2
- package/dist/wgpuShader.js.map +1 -1
- package/dist/wgpuTestHelper.d.ts +8 -2
- package/dist/wgpuTestHelper.d.ts.map +1 -1
- package/dist/wgpuTestHelper.js +38 -3
- package/dist/wgpuTestHelper.js.map +1 -1
- package/dist/wgpuTextureRenderTarget.d.ts +18 -0
- package/dist/wgpuTextureRenderTarget.d.ts.map +1 -0
- package/dist/wgpuTextureRenderTarget.js +122 -0
- package/dist/wgpuTextureRenderTarget.js.map +1 -0
- package/package.json +11 -11
- package/src/wgpuDraw.test.ts +8 -8
- package/src/{wgpuBackground.test.ts → wgpuFrame.test.ts} +34 -20
- package/src/wgpuFullscreenPass.test.ts +7 -7
- package/src/wgpuHost.test.ts +28 -82
- package/src/wgpuRenderPass.test.ts +258 -0
- package/src/wgpuRenderState.test.ts +34 -313
- package/src/wgpuRenderTarget.test.ts +44 -219
- package/src/wgpuRenderTargetPool.test.ts +21 -21
- package/src/wgpuRenderTexture.test.ts +17 -15
- package/src/wgpuScissor.test.ts +43 -13
- package/src/wgpuScreenAntialias.test.ts +60 -0
- package/src/wgpuScreenCapture.test.ts +156 -0
- package/src/wgpuScreenRenderTarget.test.ts +152 -0
- package/src/wgpuShader.test.ts +5 -6
- package/src/wgpuTextureRenderTarget.test.ts +129 -0
- package/src/wgpuTextureResolver.test.ts +5 -5
- package/dist/wgpuAntialias.d.ts +0 -14
- package/dist/wgpuAntialias.d.ts.map +0 -1
- package/dist/wgpuAntialias.js +0 -155
- package/dist/wgpuAntialias.js.map +0 -1
- package/dist/wgpuBackground.d.ts +0 -20
- package/dist/wgpuBackground.d.ts.map +0 -1
- package/dist/wgpuBackground.js.map +0 -1
- package/dist/wgpuElement.d.ts +0 -7
- package/dist/wgpuElement.d.ts.map +0 -1
- package/dist/wgpuElement.js +0 -20
- package/dist/wgpuElement.js.map +0 -1
- package/dist/wgpuSurface.d.ts +0 -6
- package/dist/wgpuSurface.d.ts.map +0 -1
- package/dist/wgpuSurface.js.map +0 -1
- package/src/wgpuAntialias.test.ts +0 -239
- package/src/wgpuElement.test.ts +0 -145
- package/src/wgpuSurface.test.ts +0 -141
package/dist/wgpuHost.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { EntityConstruction,
|
|
2
|
-
export declare function createWebWgpuHostBackend():
|
|
3
|
-
export declare function getWgpuHostBackend():
|
|
4
|
-
export declare function initializeWebWgpuHostBackend(out: EntityConstruction<
|
|
5
|
-
export declare function installWgpuHostBackend(backend:
|
|
1
|
+
import type { EntityConstruction, HostWgpuProvider } from '@flighthq/types/contract';
|
|
2
|
+
export declare function createWebWgpuHostBackend(): HostWgpuProvider;
|
|
3
|
+
export declare function getWgpuHostBackend(): HostWgpuProvider;
|
|
4
|
+
export declare function initializeWebWgpuHostBackend(out: EntityConstruction<HostWgpuProvider>): void;
|
|
5
|
+
export declare function installWgpuHostBackend(backend: HostWgpuProvider): void;
|
|
6
6
|
export declare function resetWgpuHostBackendForTest(): void;
|
|
7
|
-
export declare function setWgpuHostBackend(backend:
|
|
7
|
+
export declare function setWgpuHostBackend(backend: HostWgpuProvider | null): void;
|
|
8
8
|
//# sourceMappingURL=wgpuHost.d.ts.map
|
package/dist/wgpuHost.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wgpuHost.d.ts","sourceRoot":"","sources":["../src/wgpuHost.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAuB,
|
|
1
|
+
{"version":3,"file":"wgpuHost.d.ts","sourceRoot":"","sources":["../src/wgpuHost.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAuB,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAI1G,wBAAgB,wBAAwB,IAAI,gBAAgB,CAI3D;AAED,wBAAgB,kBAAkB,IAAI,gBAAgB,CAErD;AAED,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,kBAAkB,CAAC,gBAAgB,CAAC,GAAG,IAAI,CA4D5F;AAGD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAEtE;AAED,wBAAgB,2BAA2B,IAAI,IAAI,CAGlD;AAID,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAEzE"}
|
package/dist/wgpuHost.js
CHANGED
|
@@ -10,7 +10,7 @@ export function getWgpuHostBackend() {
|
|
|
10
10
|
return _custom ?? _host ?? _web;
|
|
11
11
|
}
|
|
12
12
|
export function initializeWebWgpuHostBackend(out) {
|
|
13
|
-
out.acquire = async (
|
|
13
|
+
out.acquire = async (surface, options) => {
|
|
14
14
|
const gpu = getWebWgpu();
|
|
15
15
|
if (gpu === null)
|
|
16
16
|
throw new Error('WebGPU is not supported in this browser.');
|
|
@@ -33,7 +33,7 @@ export function initializeWebWgpuHostBackend(out) {
|
|
|
33
33
|
const device = await adapter.requestDevice(descriptor);
|
|
34
34
|
try {
|
|
35
35
|
const format = options.format ?? gpu.getPreferredCanvasFormat();
|
|
36
|
-
const context =
|
|
36
|
+
const context = surface.getContext('webgpu');
|
|
37
37
|
if (context === null)
|
|
38
38
|
throw new Error('Failed to get WebGPU canvas context.');
|
|
39
39
|
const acquisition = allocateEntity();
|
|
@@ -41,7 +41,7 @@ export function initializeWebWgpuHostBackend(out) {
|
|
|
41
41
|
acquisition.device = device;
|
|
42
42
|
acquisition.format = format;
|
|
43
43
|
acquisition.ownership = 'flight';
|
|
44
|
-
acquisition.surface =
|
|
44
|
+
acquisition.surface = surface;
|
|
45
45
|
return finishEntity(acquisition);
|
|
46
46
|
}
|
|
47
47
|
catch (error) {
|
|
@@ -49,6 +49,20 @@ export function initializeWebWgpuHostBackend(out) {
|
|
|
49
49
|
throw error;
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
+
out.attachSurface = (surface, attachment) => {
|
|
53
|
+
const context = surface.getContext('webgpu');
|
|
54
|
+
if (context === null)
|
|
55
|
+
return null;
|
|
56
|
+
// COPY_SRC lets the swap-chain texture be read back with copyTextureToBuffer. It is the only reliable
|
|
57
|
+
// way to read a Wgpu frame in headless/software contexts, and it also backs user-facing screenshots.
|
|
58
|
+
context.configure({
|
|
59
|
+
device: attachment.device,
|
|
60
|
+
format: attachment.format,
|
|
61
|
+
alphaMode: attachment.alphaMode,
|
|
62
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
|
|
63
|
+
});
|
|
64
|
+
return context;
|
|
65
|
+
};
|
|
52
66
|
out.isSupported = () => {
|
|
53
67
|
return getWebWgpu() !== null;
|
|
54
68
|
};
|
package/dist/wgpuHost.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wgpuHost.js","source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SAAS,CAAC,GAAG,IAAI,IAAI,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,IAAI,GAAG,wBAAwB,EAAE,CAAC;AACxC,IAAI,OAAO,GAA4B,IAAI,CAAC;AAC5C,IAAI,KAAK,GAA4B,IAAI,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Matrix, RenderTargetClear, WgpuRenderPass, WgpuRenderPassViewport, WgpuRenderState, WgpuRenderTarget } from '@flighthq/types/contract';
|
|
2
|
+
export declare function beginWgpuRenderPass(state: WgpuRenderState, target: WgpuRenderTarget, clear?: Readonly<RenderTargetClear>): WgpuRenderPass;
|
|
3
|
+
export declare function endWgpuRenderPass(pass: WgpuRenderPass): void;
|
|
4
|
+
export declare function getWgpuActiveRenderPass(state: WgpuRenderState): WgpuRenderPass | null;
|
|
5
|
+
export declare function getWgpuRenderPassViewport(state: WgpuRenderState): Readonly<WgpuRenderPassViewport>;
|
|
6
|
+
export declare function resumeWgpuRenderPass(pass: WgpuRenderPass): void;
|
|
7
|
+
export declare function setWgpuRenderTransform2D(pass: WgpuRenderPass, transform: Readonly<Matrix>): void;
|
|
8
|
+
export declare function suspendWgpuRenderPass(pass: WgpuRenderPass): void;
|
|
9
|
+
//# sourceMappingURL=wgpuRenderPass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wgpuRenderPass.d.ts","sourceRoot":"","sources":["../src/wgpuRenderPass.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,MAAM,EACN,iBAAiB,EACjB,cAAc,EACd,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EAIjB,MAAM,0BAA0B,CAAC;AAwBlC,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,eAAe,EACtB,MAAM,EAAE,gBAAgB,EACxB,KAAK,CAAC,EAAE,QAAQ,CAAC,iBAAiB,CAAC,GAClC,cAAc,CAgDhB;AAOD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CA+B5D;AAKD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,eAAe,GAAG,cAAc,GAAG,IAAI,CAErF;AAMD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,eAAe,GAAG,QAAQ,CAAC,sBAAsB,CAAC,CAIlG;AAID,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAK/D;AAMD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,CAIhG;AAID,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAKhE"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
|
+
import { copyMatrix, createMatrix } from '@flighthq/geometry/contract';
|
|
3
|
+
import { beginWgpuFrame, submitWgpuFrame } from './wgpuFrame';
|
|
4
|
+
import { getWgpuRenderStateRuntime } from './wgpuRenderState';
|
|
5
|
+
import { getWgpuRenderTargetSupersampleScale } from './wgpuRenderTarget';
|
|
6
|
+
import { bindWgpuScreenRenderTarget, isWgpuScreenRenderTarget } from './wgpuScreenRenderTarget';
|
|
7
|
+
// Opens a render pass into `target` and returns the handle to draw through. Aspects named in `clear` are
|
|
8
|
+
// overwritten with the given values; omitted aspects are preserved (loadOp 'load'). Color values are
|
|
9
|
+
// linear float RGBA, in the space the target holds.
|
|
10
|
+
//
|
|
11
|
+
// The pass — not the state — is what a draw entry point takes, because "which target is being drawn
|
|
12
|
+
// into" is a property of the pass and of nothing else:
|
|
13
|
+
//
|
|
14
|
+
// const pass = beginWgpuRenderPass(state, screen, { color: [0.1, 0.1, 0.18, 1.0], depth: 1.0 });
|
|
15
|
+
// renderWgpuScene2D(pass, root);
|
|
16
|
+
// endWgpuRenderPass(pass);
|
|
17
|
+
//
|
|
18
|
+
// Passes nest across targets: an offscreen pass opened inside a screen pass suspends it, and ending the
|
|
19
|
+
// inner one resumes the outer with loadOp 'load'. A pass carries no 2D transform — a 2D pass that needs a
|
|
20
|
+
// specific root device transform calls setWgpuRenderTransform2D after begin, and the bracket restores it.
|
|
21
|
+
//
|
|
22
|
+
// The handle is pooled: begin claims one, end returns it. Using a handle after its end is a bug, the same
|
|
23
|
+
// contract as every other acquire/release bracket.
|
|
24
|
+
export function beginWgpuRenderPass(state, target, clear) {
|
|
25
|
+
const runtime = getWgpuRenderStateRuntime(state);
|
|
26
|
+
// A WebGPU pass encoder cannot be suspended, only ended; the enclosing pass is re-recorded from its
|
|
27
|
+
// saved attachments when this one ends. The live encoder is read from the runtime rather than from the
|
|
28
|
+
// enclosing handle, because a frame borrower shares the owner's encoder before it shares its stack.
|
|
29
|
+
if (runtime.renderPass !== null) {
|
|
30
|
+
runtime.renderPass.end();
|
|
31
|
+
runtime.renderPass = null;
|
|
32
|
+
}
|
|
33
|
+
const enclosing = runtime.passStack.at(-1);
|
|
34
|
+
if (enclosing !== undefined)
|
|
35
|
+
enclosing.encoder = null;
|
|
36
|
+
const ownsFrame = runtime.commandEncoder === null;
|
|
37
|
+
beginWgpuFrame(state);
|
|
38
|
+
const saved = {
|
|
39
|
+
clipForms: runtime.clipForms,
|
|
40
|
+
colorFormat: runtime.currentColorFormat,
|
|
41
|
+
currentMaskDepth: runtime.currentMaskDepth,
|
|
42
|
+
currentScissorRect: runtime.currentScissorRect,
|
|
43
|
+
maskWriteMode: runtime.maskWriteMode,
|
|
44
|
+
renderTarget: runtime.currentRenderTarget,
|
|
45
|
+
renderTargetViewport: runtime.renderTargetViewport,
|
|
46
|
+
renderTransform2D: state.renderTransform2D,
|
|
47
|
+
scissorStack: runtime.scissorStack,
|
|
48
|
+
};
|
|
49
|
+
const colorView = bindWgpuRenderPassTarget(state, target);
|
|
50
|
+
const pass = acquireWgpuRenderPassHandle(state, target, colorView, saved, ownsFrame);
|
|
51
|
+
const scale = getWgpuRenderTargetSupersampleScale(target);
|
|
52
|
+
pass.viewport = { height: target.height / scale, width: target.width / scale };
|
|
53
|
+
runtime.passStack.push(pass);
|
|
54
|
+
runtime.currentRenderTarget = target;
|
|
55
|
+
runtime.currentColorFormat = target.format;
|
|
56
|
+
runtime.renderTargetViewport = pass.viewport;
|
|
57
|
+
// A pass owns its logical clip unwind state. Inheriting the enclosing entries would let a nested pass
|
|
58
|
+
// pop clips it never pushed, desynchronizing the logical and hardware stacks once the outer resumes.
|
|
59
|
+
runtime.clipForms = [];
|
|
60
|
+
runtime.currentMaskDepth = 0;
|
|
61
|
+
runtime.maskWriteMode = false;
|
|
62
|
+
runtime.currentScissorRect = null;
|
|
63
|
+
runtime.scissorStack = [];
|
|
64
|
+
pass.encoder = recordWgpuRenderPassEncoder(state, target, colorView, clear);
|
|
65
|
+
runtime.renderPass = pass.encoder;
|
|
66
|
+
return pass;
|
|
67
|
+
}
|
|
68
|
+
// Ends the pass: closes its encoder, restores the enclosing pass state, and resumes the enclosing pass
|
|
69
|
+
// (re-recorded with loadOp 'load') if there is one. When this pass opened the frame, its end also submits
|
|
70
|
+
// it — a caller that opened the frame itself with beginWgpuFrame submits it itself, which is how a
|
|
71
|
+
// multi-pass recipe still costs one submit. Ending a pass twice, or out of order, throws: an unbalanced
|
|
72
|
+
// bracket is a programmer error, and accepting it silently hides a leaked pass.
|
|
73
|
+
export function endWgpuRenderPass(pass) {
|
|
74
|
+
const state = pass.state;
|
|
75
|
+
const runtime = getWgpuRenderStateRuntime(state);
|
|
76
|
+
if (runtime.passStack.at(-1) !== pass) {
|
|
77
|
+
throw new Error('endWgpuRenderPass: this pass is not the innermost open pass');
|
|
78
|
+
}
|
|
79
|
+
runtime.passStack.pop();
|
|
80
|
+
if (pass.encoder !== null) {
|
|
81
|
+
pass.encoder.end();
|
|
82
|
+
pass.encoder = null;
|
|
83
|
+
}
|
|
84
|
+
runtime.renderPass = null;
|
|
85
|
+
const saved = pass.saved;
|
|
86
|
+
runtime.currentRenderTarget = saved.renderTarget;
|
|
87
|
+
runtime.currentColorFormat = saved.colorFormat;
|
|
88
|
+
runtime.renderTargetViewport = saved.renderTargetViewport;
|
|
89
|
+
runtime.clipForms = saved.clipForms;
|
|
90
|
+
runtime.currentMaskDepth = saved.currentMaskDepth;
|
|
91
|
+
runtime.maskWriteMode = saved.maskWriteMode;
|
|
92
|
+
runtime.currentScissorRect = saved.currentScissorRect;
|
|
93
|
+
runtime.scissorStack = saved.scissorStack;
|
|
94
|
+
state.renderTransform2D = saved.renderTransform2D;
|
|
95
|
+
const enclosing = runtime.passStack.at(-1);
|
|
96
|
+
if (enclosing !== undefined)
|
|
97
|
+
resumeWgpuRenderPass(enclosing);
|
|
98
|
+
const ownsFrame = pass.ownsFrame;
|
|
99
|
+
releaseWgpuRenderPassHandle(pass);
|
|
100
|
+
if (ownsFrame)
|
|
101
|
+
submitWgpuFrame(state);
|
|
102
|
+
}
|
|
103
|
+
// The pass a draw entered through, when a caller holds the state rather than the handle: a registered
|
|
104
|
+
// renderer is dispatched with the state, and the active pass is what tells it where its draw lands.
|
|
105
|
+
// Null outside any pass.
|
|
106
|
+
export function getWgpuActiveRenderPass(state) {
|
|
107
|
+
return getWgpuRenderStateRuntime(state).passStack.at(-1) ?? null;
|
|
108
|
+
}
|
|
109
|
+
// The logical extent of the innermost open pass — the space 2D transforms, projections, and scissor
|
|
110
|
+
// rectangles are expressed in, whether the pass is supersampled or not. Throws outside a pass: a draw
|
|
111
|
+
// with no target bound is API misuse, and inventing a canvas-sized default hides it until the picture
|
|
112
|
+
// comes out the wrong size.
|
|
113
|
+
export function getWgpuRenderPassViewport(state) {
|
|
114
|
+
const viewport = getWgpuRenderStateRuntime(state).renderTargetViewport;
|
|
115
|
+
if (viewport === null)
|
|
116
|
+
throw new Error('No Wgpu render pass is open — call beginWgpuRenderPass first');
|
|
117
|
+
return viewport;
|
|
118
|
+
}
|
|
119
|
+
// Re-records the pass's GPU encoder over the same attachments with loadOp 'load', after a suspend or an
|
|
120
|
+
// inner pass. Pixels already drawn are preserved; a suspended pass is resumed exactly once.
|
|
121
|
+
export function resumeWgpuRenderPass(pass) {
|
|
122
|
+
const runtime = getWgpuRenderStateRuntime(pass.state);
|
|
123
|
+
pass.colorView = bindWgpuRenderPassTarget(pass.state, pass.target);
|
|
124
|
+
pass.encoder = recordWgpuRenderPassEncoder(pass.state, pass.target, pass.colorView, undefined);
|
|
125
|
+
runtime.renderPass = pass.encoder;
|
|
126
|
+
}
|
|
127
|
+
// Sets the 2D root device transform the display-object update pass reads to place nodes with no scene
|
|
128
|
+
// parent. Call after beginWgpuRenderPass when a 2D pass renders into a target with its own coordinate
|
|
129
|
+
// system (the render cache); the matching endWgpuRenderPass restores the previous value. A fresh matrix
|
|
130
|
+
// is allocated rather than mutated in place, because the bracket saved the previous reference.
|
|
131
|
+
export function setWgpuRenderTransform2D(pass, transform) {
|
|
132
|
+
const next = createMatrix();
|
|
133
|
+
copyMatrix(next, transform);
|
|
134
|
+
pass.state.renderTransform2D = next;
|
|
135
|
+
}
|
|
136
|
+
// Ends the pass's GPU encoder while leaving the pass open, so a caller can record its own render passes
|
|
137
|
+
// into the same frame (the effect pipeline's fullscreen passes). Pair with resumeWgpuRenderPass.
|
|
138
|
+
export function suspendWgpuRenderPass(pass) {
|
|
139
|
+
if (pass.encoder === null)
|
|
140
|
+
return;
|
|
141
|
+
pass.encoder.end();
|
|
142
|
+
pass.encoder = null;
|
|
143
|
+
getWgpuRenderStateRuntime(pass.state).renderPass = null;
|
|
144
|
+
}
|
|
145
|
+
function acquireWgpuRenderPassHandle(state, target, colorView, saved, ownsFrame) {
|
|
146
|
+
const pooled = _passPool.pop();
|
|
147
|
+
if (pooled !== undefined) {
|
|
148
|
+
pooled.colorView = colorView;
|
|
149
|
+
pooled.encoder = null;
|
|
150
|
+
pooled.ownsFrame = ownsFrame;
|
|
151
|
+
pooled.saved = saved;
|
|
152
|
+
pooled.state = state;
|
|
153
|
+
pooled.target = target;
|
|
154
|
+
return pooled;
|
|
155
|
+
}
|
|
156
|
+
const out = allocateEntity();
|
|
157
|
+
out.colorView = colorView;
|
|
158
|
+
out.encoder = null;
|
|
159
|
+
out.ownsFrame = ownsFrame;
|
|
160
|
+
out.saved = saved;
|
|
161
|
+
out.state = state;
|
|
162
|
+
out.target = target;
|
|
163
|
+
out.viewport = { height: 0, width: 0 };
|
|
164
|
+
return finishEntity(out);
|
|
165
|
+
}
|
|
166
|
+
// Resolves the color view to attach: the swap-chain (or supersample) view for a screen target, the
|
|
167
|
+
// target's own view for a texture target. Screen storage is sized to its surface here, which is why a
|
|
168
|
+
// caller never announces a canvas resize.
|
|
169
|
+
function bindWgpuRenderPassTarget(state, target) {
|
|
170
|
+
if (isWgpuScreenRenderTarget(target)) {
|
|
171
|
+
const view = bindWgpuScreenRenderTarget(state, target);
|
|
172
|
+
getWgpuRenderStateRuntime(state).frameScreenTarget = target;
|
|
173
|
+
return view;
|
|
174
|
+
}
|
|
175
|
+
return target.view;
|
|
176
|
+
}
|
|
177
|
+
function recordWgpuRenderPassEncoder(state, target, colorView, clear) {
|
|
178
|
+
const runtime = getWgpuRenderStateRuntime(state);
|
|
179
|
+
const hasColor = clear !== undefined && (clear.color !== undefined || clear.colors !== undefined);
|
|
180
|
+
const encoder = runtime.commandEncoder.beginRenderPass({
|
|
181
|
+
colorAttachments: [
|
|
182
|
+
{
|
|
183
|
+
view: colorView,
|
|
184
|
+
clearValue: resolveWgpuClearColor(clear),
|
|
185
|
+
loadOp: hasColor ? 'clear' : 'load',
|
|
186
|
+
storeOp: 'store',
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
depthStencilAttachment: {
|
|
190
|
+
view: target.depthStencilView,
|
|
191
|
+
depthClearValue: clear?.depth ?? 1.0,
|
|
192
|
+
depthLoadOp: clear?.depth !== undefined ? 'clear' : 'load',
|
|
193
|
+
depthStoreOp: 'discard',
|
|
194
|
+
stencilClearValue: clear?.stencil ?? 0,
|
|
195
|
+
stencilLoadOp: 'clear',
|
|
196
|
+
stencilStoreOp: 'discard',
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
encoder.setViewport(0, 0, target.width, target.height, 0, 1);
|
|
200
|
+
return encoder;
|
|
201
|
+
}
|
|
202
|
+
// A released handle keeps its state/target references until the next acquire overwrites them: they are
|
|
203
|
+
// plain references to objects the caller still owns, and nulling them would cost the non-null field types
|
|
204
|
+
// that make a live handle safe to read.
|
|
205
|
+
function releaseWgpuRenderPassHandle(pass) {
|
|
206
|
+
pass.encoder = null;
|
|
207
|
+
_passPool.push(pass);
|
|
208
|
+
}
|
|
209
|
+
// One color value broadcasts to every attachment; `colors` selects per attachment. WebGPU takes the
|
|
210
|
+
// clear through the attachment's load operation, so only attachment 0 is expressible today — the
|
|
211
|
+
// broadcast and the first per-attachment entry resolve to the same thing here.
|
|
212
|
+
function resolveWgpuClearColor(clear) {
|
|
213
|
+
const rgba = clear?.colors?.[0] ?? clear?.color;
|
|
214
|
+
if (rgba === undefined)
|
|
215
|
+
return { r: 0, g: 0, b: 0, a: 0 };
|
|
216
|
+
return { r: rgba[0], g: rgba[1], b: rgba[2], a: rgba[3] };
|
|
217
|
+
}
|
|
218
|
+
// Pass handles are per-frame scaffolding, so a render loop must not allocate one per frame. The pool is
|
|
219
|
+
// module-scoped rather than per-state: a handle carries no device resource, only references cleared on
|
|
220
|
+
// release, so two states on one thread can share the free list.
|
|
221
|
+
const _passPool = [];
|
|
222
|
+
//# sourceMappingURL=wgpuRenderPass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wgpuRenderPass.js","sourceRoot":"","sources":["../src/wgpuRenderPass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAavE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE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Feature, WgpuColorAdjustmentMaterialFeatureGuard, WgpuDeviceRuntime, WgpuDeviceRuntimeResources, WgpuDeviceState, WgpuHostAcquisition, WgpuHostAcquisitionOptions, WgpuOffscreenRenderStateResult, WgpuPipeline,
|
|
2
|
-
export declare function
|
|
1
|
+
import type { EntityConstruction, TextureWrap, WgpuColorAdjustmentMaterialFeature, WgpuColorAdjustmentMaterialFeatureGuard, WgpuDeviceRuntime, WgpuDeviceRuntimeResources, WgpuDeviceState, WgpuHostAcquisition, WgpuHostAcquisitionOptions, WgpuOffscreenRenderStateResult, WgpuPipeline, WgpuRenderOptions, WgpuRenderState, WgpuRenderStateRuntime, WgpuScreenSurface } from '@flighthq/types/contract';
|
|
2
|
+
export declare function createWgpuAcquisition(surface: WgpuScreenSurface, options?: Readonly<WgpuHostAcquisitionOptions>): Promise<WgpuHostAcquisition | null>;
|
|
3
3
|
export declare function createWgpuDeviceState(device: GPUDevice): WgpuDeviceState;
|
|
4
4
|
/**
|
|
5
5
|
* Creates a device-only render state with its own frame-local resources.
|
|
@@ -10,8 +10,7 @@ export declare function createWgpuDeviceState(device: GPUDevice): WgpuDeviceStat
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function createWgpuOffscreenRenderState(source: WgpuRenderState): WgpuOffscreenRenderStateResult;
|
|
12
12
|
export declare function createWgpuOffscreenRenderState(deviceState: Readonly<WgpuDeviceState>, pipeline: Readonly<WgpuPipeline>, options?: Readonly<WgpuRenderOptions>): WgpuRenderState;
|
|
13
|
-
export declare function createWgpuRenderState(
|
|
14
|
-
export declare function createWgpuRenderStateFromCanvasElement(canvas: HTMLCanvasElement, pipeline: Readonly<WgpuPipeline>, options?: Readonly<WgpuRenderOptions & WgpuHostAcquisitionOptions>): Promise<WgpuPresentationRenderState>;
|
|
13
|
+
export declare function createWgpuRenderState(device: GPUDevice, pipeline: Readonly<WgpuPipeline>, options?: Readonly<WgpuRenderOptions>): WgpuRenderState;
|
|
15
14
|
export declare function createWgpuRenderStateRuntime(deviceStateOrRuntime: Readonly<WgpuDeviceState> | WgpuRenderStateRuntime, pipeline?: Readonly<WgpuPipeline>): WgpuRenderStateRuntime;
|
|
16
15
|
export declare function destroyWgpuRenderState(state: WgpuRenderState): void;
|
|
17
16
|
export declare function getWgpuColorAdjustmentMaterialFeature(state: WgpuRenderState): Readonly<WgpuColorAdjustmentMaterialFeature> | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wgpuRenderState.d.ts","sourceRoot":"","sources":["../src/wgpuRenderState.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wgpuRenderState.d.ts","sourceRoot":"","sources":["../src/wgpuRenderState.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EACX,kCAAkC,EAClC,uCAAuC,EACvC,iBAAiB,EACjB,0BAA0B,EAC1B,eAAe,EACf,mBAAmB,EACnB,0BAA0B,EAC1B,8BAA8B,EAC9B,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAgBlC,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,GAAE,QAAQ,CAAC,0BAA0B,CAAM,GACjD,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CASrC;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,eAAe,CAMxE;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,eAAe,GAAG,8BAA8B,CAAC;AACxG,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,QAAQ,CAAC,eAAe,CAAC,EACtC,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,EAChC,OAAO,CAAC,EAAE,QAAQ,CAAC,iBAAiB,CAAC,GACpC,eAAe,CAAC;AA8CnB,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,QAA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AAED,wBAAgB,kDAAkD,CAChE,GAAG,EAAE,kBAAkB,CAAC,OAAO,CAAC,8BAA8B,EAAE;IAAE,MAAM,EAAE,aAAa,CAAA;CAAE,CAAC,CAAC,EAC3F,IAAI,EAAE,iBAAiB,GACtB,IAAI,CAGN;AAED,wBAAgB,0CAA0C,CACxD,GAAG,EAAE,kBAAkB,CAAC,OAAO,CAAC,8BAA8B,EAAE;IAAE,MAAM,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC,EAClF,KAAK,EAAE,eAAe,GACrB,IAAI,CAGN;AAED,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,GAAG,IAAI,CAE9G;AAED,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,GACzC,IAAI,CAEN;AAiCD,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,QAAQ,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAEvF;AA6BD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAQnG"}
|
package/dist/wgpuRenderState.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
2
|
import { createMatrix } from '@flighthq/geometry/contract';
|
|
3
|
-
import { createRenderState as _createRenderState, createRenderStateRuntime, destroyRenderState,
|
|
3
|
+
import { createRenderState as _createRenderState, createRenderStateRuntime, destroyRenderState, } from '@flighthq/render/contract';
|
|
4
4
|
import { EntityRuntimeKey, RegistryEntryState } from '@flighthq/types/contract';
|
|
5
5
|
import { observeWgpuDeviceLoss } from './wgpuDeviceLoss';
|
|
6
6
|
import { warmWgpuPipelines } from './wgpuDraw';
|
|
@@ -13,9 +13,9 @@ const RING_SLOT_COUNT = 4096;
|
|
|
13
13
|
// ends their life with `releaseWgpuAcquisition`, and a state built on them leaves them intact when it is
|
|
14
14
|
// destroyed. Returns `null` rather than throwing, because "this environment has no WebGPU" is an expected
|
|
15
15
|
// outcome and not a programmer error.
|
|
16
|
-
export async function
|
|
16
|
+
export async function createWgpuAcquisition(surface, options = {}) {
|
|
17
17
|
try {
|
|
18
|
-
const acquired = await getWgpuHostBackend().acquire(
|
|
18
|
+
const acquired = await getWgpuHostBackend().acquire(surface, options);
|
|
19
19
|
const out = allocateEntity();
|
|
20
20
|
initializeWgpuHostAcquisition(out, acquired, 'caller');
|
|
21
21
|
return finishEntity(out);
|
|
@@ -45,7 +45,6 @@ export function createWgpuOffscreenRenderState(sourceOrDeviceState, pipeline, op
|
|
|
45
45
|
})();
|
|
46
46
|
const derivedPipeline = createWgpuPipeline(sourceRuntime.registries);
|
|
47
47
|
const state = initializeWgpuDeviceRenderState(source.deviceState, derivedPipeline, {
|
|
48
|
-
backgroundColor: source.backgroundColor,
|
|
49
48
|
format: source.format,
|
|
50
49
|
imageSmoothingEnabled: source.allowSmoothing,
|
|
51
50
|
pixelRatio: source.pixelRatio,
|
|
@@ -63,30 +62,16 @@ export function createWgpuOffscreenRenderState(sourceOrDeviceState, pipeline, op
|
|
|
63
62
|
initializeWgpuOffscreenRenderStateOkResult(out, state);
|
|
64
63
|
return finishEntity(out);
|
|
65
64
|
}
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// backend happened to check. The policy belongs here, where it holds for every backend.
|
|
77
|
-
if (acquisition.ownership !== 'caller')
|
|
78
|
-
hostBackend.release(acquisition);
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// The canvas convenience: acquire, then build. The handles are `flight`-owned, so destroying the state
|
|
83
|
-
// releases them — the behavior every existing caller had when it passed a canvas.
|
|
84
|
-
export async function createWgpuRenderStateFromCanvasElement(canvas, pipeline, options = {}) {
|
|
85
|
-
const acquisition = await getWgpuHostBackend().acquire(canvas, {
|
|
86
|
-
format: options.format,
|
|
87
|
-
powerPreference: options.powerPreference,
|
|
88
|
-
});
|
|
89
|
-
return createWgpuRenderState(acquisition, pipeline, options);
|
|
65
|
+
// Takes the driver handle directly: the device is how a state talks to the GPU — shader compilation,
|
|
66
|
+
// texture upload, renderer registration — and none of that needs a target. Which surface a frame lands on
|
|
67
|
+
// is a per-pass decision, so the screen target is created separately and flows in at beginWgpuRenderPass.
|
|
68
|
+
//
|
|
69
|
+
// Synchronous, because everything asynchronous (adapter and device discovery) happens before this call:
|
|
70
|
+
// const acquisition = await createWgpuAcquisition(canvas);
|
|
71
|
+
// const screen = createWgpuScreenRenderTarget(acquisition.device, canvas, { format: acquisition.format });
|
|
72
|
+
// const state = createWgpuRenderState(acquisition.device, pipeline, { format: acquisition.format });
|
|
73
|
+
export function createWgpuRenderState(device, pipeline, options = {}) {
|
|
74
|
+
return initializeWgpuDeviceRenderState(createWgpuDeviceState(device), pipeline, options);
|
|
90
75
|
}
|
|
91
76
|
export function createWgpuRenderStateRuntime(deviceStateOrRuntime, pipeline) {
|
|
92
77
|
const deviceRuntime = EntityRuntimeKey in deviceStateOrRuntime
|
|
@@ -98,25 +83,6 @@ export function createWgpuRenderStateRuntime(deviceStateOrRuntime, pipeline) {
|
|
|
98
83
|
: deviceStateOrRuntime.registries);
|
|
99
84
|
return createWgpuRenderStateRuntimeInternal(deviceRuntime, resolvedPipeline);
|
|
100
85
|
}
|
|
101
|
-
function initializeWgpuPresentationRenderState(options, acquisition, pipeline, hostBackend) {
|
|
102
|
-
const { context, device, format } = acquisition;
|
|
103
|
-
// COPY_SRC lets the canvas texture be read back via copyTextureToBuffer (createBitmapFromWgpuRenderState).
|
|
104
|
-
// It is the only reliable way to read a Wgpu frame in headless/software contexts, where canvas
|
|
105
|
-
// presentation does not surface the swapchain; it also backs user-facing screenshot/save-pixels needs.
|
|
106
|
-
context.configure({
|
|
107
|
-
device,
|
|
108
|
-
format,
|
|
109
|
-
alphaMode: 'premultiplied',
|
|
110
|
-
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
|
|
111
|
-
});
|
|
112
|
-
const deviceState = createWgpuDeviceState(device);
|
|
113
|
-
const ownership = { acquisition, hostBackend, references: 0 };
|
|
114
|
-
_acquisitionByDeviceRuntime.set(getWgpuDeviceRuntime(deviceState), ownership);
|
|
115
|
-
const state = initializeWgpuDeviceRenderState(deviceState, pipeline, { ...options, format });
|
|
116
|
-
Object.assign(state, { context, surface: acquisition.surface });
|
|
117
|
-
getWgpuRenderStateRuntime(state).surfaceAntialiasEnabled = options.antialias ?? false;
|
|
118
|
-
return state;
|
|
119
|
-
}
|
|
120
86
|
function initializeWgpuDeviceRenderState(deviceState, pipeline, options) {
|
|
121
87
|
const device = deviceState.device;
|
|
122
88
|
const format = options.format ?? 'bgra8unorm';
|
|
@@ -141,13 +107,10 @@ function initializeWgpuDeviceRenderState(deviceState, pipeline, options) {
|
|
|
141
107
|
roundPixels: options.roundPixels ?? false,
|
|
142
108
|
sceneGraphSyncPolicy: options.sceneGraphSyncPolicy,
|
|
143
109
|
});
|
|
144
|
-
if (options.backgroundColor != null)
|
|
145
|
-
setRenderStateBackgroundColor(state, options.backgroundColor);
|
|
146
110
|
state.applyBlendMode = null;
|
|
147
111
|
Object.assign(state, { deviceState, device, format, pipeline });
|
|
148
112
|
const runtime = createWgpuRenderStateRuntime(deviceState, pipeline);
|
|
149
113
|
state[EntityRuntimeKey] = runtime;
|
|
150
|
-
runtime.surfaceAntialiasEnabled = false;
|
|
151
114
|
runtime.currentBlendMode = null;
|
|
152
115
|
runtime.currentRenderTarget = null;
|
|
153
116
|
runtime.uniformBuffer = uniformBuffer;
|
|
@@ -177,18 +140,7 @@ function initializeWgpuDeviceRenderState(deviceState, pipeline, options) {
|
|
|
177
140
|
runtime.quadBatchWriterBufferCursor = 0;
|
|
178
141
|
runtime.commandEncoder = null;
|
|
179
142
|
runtime.renderPass = null;
|
|
180
|
-
runtime.
|
|
181
|
-
runtime.canvasViewCleared = false;
|
|
182
|
-
runtime.frameCaptureEnabled = false;
|
|
183
|
-
runtime.frameCaptureTexture = null;
|
|
184
|
-
runtime.frameCaptureBuffer = null;
|
|
185
|
-
runtime.frameCaptureBytesPerRow = 0;
|
|
186
|
-
runtime.frameCaptureWidth = 0;
|
|
187
|
-
runtime.frameCaptureHeight = 0;
|
|
188
|
-
runtime.depthStencilTexture = null;
|
|
189
|
-
runtime.depthStencilView = null;
|
|
190
|
-
runtime.depthStencilWidth = 0;
|
|
191
|
-
runtime.depthStencilHeight = 0;
|
|
143
|
+
runtime.frameScreenTarget = null;
|
|
192
144
|
runtime.currentMaskDepth = 0;
|
|
193
145
|
runtime.maskWriteMode = false;
|
|
194
146
|
runtime.clipContourPipelines = undefined;
|
|
@@ -198,7 +150,7 @@ function initializeWgpuDeviceRenderState(deviceState, pipeline, options) {
|
|
|
198
150
|
runtime.scissorStack = [];
|
|
199
151
|
runtime.currentScissorRect = null;
|
|
200
152
|
runtime.renderTargetViewport = null;
|
|
201
|
-
runtime.
|
|
153
|
+
runtime.passStack = [];
|
|
202
154
|
warmWgpuPipelines(state);
|
|
203
155
|
return state;
|
|
204
156
|
}
|
|
@@ -209,8 +161,8 @@ function initializeWgpuDeviceRenderState(deviceState, pipeline, options) {
|
|
|
209
161
|
//
|
|
210
162
|
// GC-managed Wgpu objects with no destroy() (pipelines, bind groups, layouts, samplers, shader
|
|
211
163
|
// modules, texture views) are not touched. textureCache is a WeakMap and cannot be enumerated; its
|
|
212
|
-
// entries' textures are freed per-node by the dispose* paths.
|
|
213
|
-
//
|
|
164
|
+
// entries' textures are freed per-node by the dispose* paths. Surface storage belongs to the screen
|
|
165
|
+
// render target, not to a state, so destroyWgpuScreenRenderTarget frees that side.
|
|
214
166
|
export function destroyWgpuRenderState(state) {
|
|
215
167
|
if (_destroyedStates.has(state))
|
|
216
168
|
return;
|
|
@@ -222,8 +174,6 @@ export function destroyWgpuRenderState(state) {
|
|
|
222
174
|
destroyRenderState(state);
|
|
223
175
|
runtime.uniformBuffer?.destroy();
|
|
224
176
|
runtime.particleInstanceBuffer?.destroy();
|
|
225
|
-
runtime.depthStencilTexture?.destroy();
|
|
226
|
-
runtime.surfaceAntialiasTexture?.destroy();
|
|
227
177
|
for (const slot of runtime.quadBatchWriterBufferPool) {
|
|
228
178
|
slot.instanceBuffer?.destroy();
|
|
229
179
|
slot.materialBuffer?.destroy();
|
|
@@ -239,13 +189,6 @@ export function destroyWgpuRenderState(state) {
|
|
|
239
189
|
teardown(device);
|
|
240
190
|
ctx.teardowns.length = 0;
|
|
241
191
|
}
|
|
242
|
-
const ownership = _acquisitionByStateRuntime.get(runtime);
|
|
243
|
-
if (ownership !== undefined) {
|
|
244
|
-
ownership.references--;
|
|
245
|
-
if (ownership.references === 0 && ownership.acquisition.ownership !== 'caller') {
|
|
246
|
-
ownership.hostBackend.release(ownership.acquisition);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
192
|
}
|
|
250
193
|
function createWgpuRenderStateRuntimeInternal(deviceRuntime, pipeline) {
|
|
251
194
|
const runtime = createRenderStateRuntime();
|
|
@@ -254,23 +197,11 @@ function createWgpuRenderStateRuntimeInternal(deviceRuntime, pipeline) {
|
|
|
254
197
|
// reaches an instanced draw — presentation, offscreen, or a test helper's — has the pool to claim from.
|
|
255
198
|
runtime.meshInstanceBufferPool = [];
|
|
256
199
|
runtime.meshInstanceBufferCursor = 0;
|
|
257
|
-
runtime.surfaceAntialiasEnabled = false;
|
|
258
|
-
runtime.surfaceAntialiasTexture = null;
|
|
259
|
-
runtime.surfaceAntialiasView = null;
|
|
260
|
-
runtime.surfaceAntialiasWidth = 0;
|
|
261
|
-
runtime.surfaceAntialiasHeight = 0;
|
|
262
200
|
runtime.surfaceAntialiasResolveBindGroupLayout = null;
|
|
263
201
|
runtime.surfaceAntialiasResolvePipeline = null;
|
|
264
|
-
runtime.surfaceAntialiasResolveBindGroup = null;
|
|
265
|
-
runtime.surfacePresentationView = null;
|
|
266
202
|
runtime.registries = { ...pipeline.registries };
|
|
267
203
|
runtime.teardowns = [];
|
|
268
204
|
runtime.borrowedSurfaceExtent = null;
|
|
269
|
-
const ownership = _acquisitionByDeviceRuntime.get(deviceRuntime);
|
|
270
|
-
if (ownership !== undefined) {
|
|
271
|
-
ownership.references++;
|
|
272
|
-
_acquisitionByStateRuntime.set(runtime, ownership);
|
|
273
|
-
}
|
|
274
205
|
deviceRuntime.references++;
|
|
275
206
|
runtime.context = deviceRuntime;
|
|
276
207
|
return runtime;
|
|
@@ -413,8 +344,6 @@ function createMinimalDeviceRuntime(device) {
|
|
|
413
344
|
observeWgpuDeviceLoss(runtime);
|
|
414
345
|
return runtime;
|
|
415
346
|
}
|
|
416
|
-
const _acquisitionByStateRuntime = new WeakMap();
|
|
417
|
-
const _acquisitionByDeviceRuntime = new WeakMap();
|
|
418
347
|
const _destroyedStates = new WeakSet();
|
|
419
348
|
// Resolve the blend hook at the draw seam rather than hiding derived-state delegation behind an
|
|
420
349
|
// entity accessor. A locally installed hook wins; otherwise walk toward the screen pipeline so
|