@yali-engine/render 0.0.0-stage → 0.4.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/dist/bvh.d.ts +66 -0
- package/dist/bvh.js +493 -0
- package/dist/bvh.js.map +1 -0
- package/dist/camera.d.ts +34 -0
- package/dist/camera.js +66 -0
- package/dist/camera.js.map +1 -0
- package/dist/cluster-build.d.ts +46 -0
- package/dist/cluster-build.js +179 -0
- package/dist/cluster-build.js.map +1 -0
- package/dist/cluster-pages.d.ts +70 -0
- package/dist/cluster-pages.js +203 -0
- package/dist/cluster-pages.js.map +1 -0
- package/dist/cluster-stream.d.ts +83 -0
- package/dist/cluster-stream.js +226 -0
- package/dist/cluster-stream.js.map +1 -0
- package/dist/culled-draws.d.ts +30 -0
- package/dist/culled-draws.js +103 -0
- package/dist/culled-draws.js.map +1 -0
- package/dist/debug-lines.d.ts +51 -0
- package/dist/debug-lines.js +158 -0
- package/dist/debug-lines.js.map +1 -0
- package/dist/device-profile.d.ts +100 -0
- package/dist/device-profile.js +131 -0
- package/dist/device-profile.js.map +1 -0
- package/dist/device.d.ts +39 -0
- package/dist/device.js +79 -0
- package/dist/device.js.map +1 -0
- package/dist/environment.d.ts +60 -0
- package/dist/environment.js +204 -0
- package/dist/environment.js.map +1 -0
- package/dist/extract.d.ts +74 -0
- package/dist/extract.js +194 -0
- package/dist/extract.js.map +1 -0
- package/dist/frame-graph.d.ts +112 -0
- package/dist/frame-graph.js +226 -0
- package/dist/frame-graph.js.map +1 -0
- package/dist/gpu-health.d.ts +74 -0
- package/dist/gpu-health.js +106 -0
- package/dist/gpu-health.js.map +1 -0
- package/dist/gpu-timer.d.ts +26 -0
- package/dist/gpu-timer.js +93 -0
- package/dist/gpu-timer.js.map +1 -0
- package/dist/headless.d.ts +28 -0
- package/dist/headless.js +91 -0
- package/dist/headless.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/lights.d.ts +81 -0
- package/dist/lights.js +247 -0
- package/dist/lights.js.map +1 -0
- package/dist/matrix.d.ts +6 -0
- package/dist/matrix.js +59 -0
- package/dist/matrix.js.map +1 -0
- package/dist/meshes.d.ts +411 -0
- package/dist/meshes.js +545 -0
- package/dist/meshes.js.map +1 -0
- package/dist/meshlets-decoder.d.ts +20 -0
- package/dist/meshlets-decoder.js +47 -0
- package/dist/meshlets-decoder.js.map +1 -0
- package/dist/meshlets.d.ts +186 -0
- package/dist/meshlets.js +1040 -0
- package/dist/meshlets.js.map +1 -0
- package/dist/occlusion.d.ts +51 -0
- package/dist/occlusion.js +188 -0
- package/dist/occlusion.js.map +1 -0
- package/dist/pick-decoder.d.ts +19 -0
- package/dist/pick-decoder.js +45 -0
- package/dist/pick-decoder.js.map +1 -0
- package/dist/pick.d.ts +86 -0
- package/dist/pick.js +452 -0
- package/dist/pick.js.map +1 -0
- package/dist/pipeline-cache.d.ts +53 -0
- package/dist/pipeline-cache.js +96 -0
- package/dist/pipeline-cache.js.map +1 -0
- package/dist/post-options.d.ts +109 -0
- package/dist/post-options.js +23 -0
- package/dist/post-options.js.map +1 -0
- package/dist/post-shaders.gen.d.ts +40 -0
- package/dist/post-shaders.gen.js +43 -0
- package/dist/post-shaders.gen.js.map +1 -0
- package/dist/post.d.ts +101 -0
- package/dist/post.js +555 -0
- package/dist/post.js.map +1 -0
- package/dist/render-plugin.d.ts +239 -0
- package/dist/render-plugin.js +633 -0
- package/dist/render-plugin.js.map +1 -0
- package/dist/scene.d.ts +406 -0
- package/dist/scene.js +2005 -0
- package/dist/scene.js.map +1 -0
- package/dist/shaders.gen.d.ts +40 -0
- package/dist/shaders.gen.js +43 -0
- package/dist/shaders.gen.js.map +1 -0
- package/dist/shadows.d.ts +104 -0
- package/dist/shadows.js +227 -0
- package/dist/shadows.js.map +1 -0
- package/dist/staging-ring.d.ts +41 -0
- package/dist/staging-ring.js +125 -0
- package/dist/staging-ring.js.map +1 -0
- package/dist/textures.d.ts +165 -0
- package/dist/textures.js +361 -0
- package/dist/textures.js.map +1 -0
- package/dist/tonemap.d.ts +45 -0
- package/dist/tonemap.js +141 -0
- package/dist/tonemap.js.map +1 -0
- package/dist/viewport.d.ts +78 -0
- package/dist/viewport.js +130 -0
- package/dist/viewport.js.map +1 -0
- package/dist/webgl2/plugin.d.ts +40 -0
- package/dist/webgl2/plugin.js +190 -0
- package/dist/webgl2/plugin.js.map +1 -0
- package/dist/webgl2/program.d.ts +27 -0
- package/dist/webgl2/program.js +74 -0
- package/dist/webgl2/program.js.map +1 -0
- package/dist/webgl2/renderer.d.ts +128 -0
- package/dist/webgl2/renderer.js +976 -0
- package/dist/webgl2/renderer.js.map +1 -0
- package/dist/webgl2/shaders.glsl.gen.d.ts +27 -0
- package/dist/webgl2/shaders.glsl.gen.js +20 -0
- package/dist/webgl2/shaders.glsl.gen.js.map +1 -0
- package/dist/webgl2/textures.d.ts +11 -0
- package/dist/webgl2/textures.js +82 -0
- package/dist/webgl2/textures.js.map +1 -0
- package/dist/webgl2/webgl2.d.ts +1 -0
- package/dist/webgl2/webgl2.js +4 -0
- package/dist/webgl2/webgl2.js.map +1 -0
- package/dist/worker-mode.d.ts +85 -0
- package/dist/worker-mode.js +204 -0
- package/dist/worker-mode.js.map +1 -0
- package/package.json +47 -3
- package/README.md +0 -3
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { envSky } from "./shaders.gen.js";
|
|
2
|
+
/** The default sky. */
|
|
3
|
+
export const DEFAULT_SKY = {
|
|
4
|
+
sun: [0.45, 0.8, 0.4],
|
|
5
|
+
zenith: [0.18, 0.32, 0.62],
|
|
6
|
+
horizon: [0.62, 0.68, 0.74],
|
|
7
|
+
ground: [0.16, 0.14, 0.12],
|
|
8
|
+
sunDisk: [60, 56, 50],
|
|
9
|
+
sunAngle: 1.2,
|
|
10
|
+
};
|
|
11
|
+
/** Texels per cube face at the base level, and its mip count. */
|
|
12
|
+
export const ENV_SIZE = 128;
|
|
13
|
+
// Down to 4×4: a 1×1 face shows rough reflections as six flat cube faces.
|
|
14
|
+
export const ENV_MIPS = 6;
|
|
15
|
+
const SIZE = ENV_SIZE;
|
|
16
|
+
const MIPS = ENV_MIPS;
|
|
17
|
+
/** Bytes per uniform slot (one per face and mip; dynamic offsets need 256-byte alignment). */
|
|
18
|
+
const SLOT = 256;
|
|
19
|
+
const FACES = 6;
|
|
20
|
+
/**
|
|
21
|
+
* The environment for image-based lighting (M2 increment 5): a procedural sky rendered into a
|
|
22
|
+
* cube map, each lower mip GGX-prefiltered for its roughness (`shaders/env/sky.wesl`), and the
|
|
23
|
+
* same sky projected onto nine spherical-harmonic coefficients for diffuse irradiance (CPU).
|
|
24
|
+
* Built once at start and again when `setSky` changes it; render passes only, so compatibility
|
|
25
|
+
* mode can run it. The draw reads `prefiltered` and `sh9`.
|
|
26
|
+
*/
|
|
27
|
+
export class Environment {
|
|
28
|
+
device;
|
|
29
|
+
/** Cube map the draw samples by roughness (mip m: roughness m / (mips − 1)). */
|
|
30
|
+
prefiltered;
|
|
31
|
+
mips = MIPS;
|
|
32
|
+
/** Irradiance / π as SH9, 9 × vec4 (rgb, 0): the draw's diffuse ambient for a normal n. */
|
|
33
|
+
sh9 = new Float32Array(36);
|
|
34
|
+
/** Bumped when the cube or SH changed. */
|
|
35
|
+
version = 0;
|
|
36
|
+
#base;
|
|
37
|
+
#sky = { ...DEFAULT_SKY };
|
|
38
|
+
#params;
|
|
39
|
+
#skyPipeline;
|
|
40
|
+
#filterPipeline;
|
|
41
|
+
#layout;
|
|
42
|
+
#sampler;
|
|
43
|
+
constructor(device) {
|
|
44
|
+
this.device = device;
|
|
45
|
+
const cube = (label) => device.createTexture({
|
|
46
|
+
label,
|
|
47
|
+
size: { width: SIZE, height: SIZE, depthOrArrayLayers: FACES },
|
|
48
|
+
mipLevelCount: MIPS,
|
|
49
|
+
format: 'rgba16float',
|
|
50
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST,
|
|
51
|
+
textureBindingViewDimension: 'cube',
|
|
52
|
+
});
|
|
53
|
+
this.#base = cube('yali:env:base');
|
|
54
|
+
this.prefiltered = cube('yali:env:prefiltered');
|
|
55
|
+
this.#params = device.createBuffer({ label: 'yali:env:params', size: SLOT * FACES * MIPS, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST });
|
|
56
|
+
this.#sampler = device.createSampler({ label: 'yali:env', magFilter: 'linear', minFilter: 'linear', mipmapFilter: 'linear' });
|
|
57
|
+
this.#layout = device.createBindGroupLayout({
|
|
58
|
+
label: 'yali:env',
|
|
59
|
+
entries: [
|
|
60
|
+
{ binding: 0, visibility: GPUShaderStage.FRAGMENT, buffer: { type: 'uniform', hasDynamicOffset: true, minBindingSize: 96 } },
|
|
61
|
+
{ binding: 1, visibility: GPUShaderStage.FRAGMENT, texture: { viewDimension: 'cube' } },
|
|
62
|
+
{ binding: 2, visibility: GPUShaderStage.FRAGMENT, sampler: {} },
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async init(cache) {
|
|
67
|
+
// An explicit layout (dynamic uniform offsets): created here, not through the cache, whose
|
|
68
|
+
// pipelines use `auto` layouts; the shader module still comes from it.
|
|
69
|
+
const layout = this.device.createPipelineLayout({ label: 'yali:env', bindGroupLayouts: [this.#layout] });
|
|
70
|
+
const module = await cache.module(envSky, 'yali:env');
|
|
71
|
+
const make = (entry) => this.device.createRenderPipelineAsync({
|
|
72
|
+
label: `yali:env:${entry}`,
|
|
73
|
+
layout,
|
|
74
|
+
vertex: { module, entryPoint: 'vs' },
|
|
75
|
+
fragment: { module, entryPoint: entry, targets: [{ format: 'rgba16float' }] },
|
|
76
|
+
primitive: { topology: 'triangle-list' },
|
|
77
|
+
});
|
|
78
|
+
[this.#skyPipeline, this.#filterPipeline] = await Promise.all([make('fs_sky'), make('fs_prefilter')]);
|
|
79
|
+
this.build();
|
|
80
|
+
}
|
|
81
|
+
/** Changes the sky (unset fields keep their values) and rebuilds the cube and SH. */
|
|
82
|
+
setSky(sky) {
|
|
83
|
+
this.#sky = mergeSky(this.#sky, sky);
|
|
84
|
+
this.build();
|
|
85
|
+
}
|
|
86
|
+
/** The current sky. */
|
|
87
|
+
get sky() {
|
|
88
|
+
return this.#sky;
|
|
89
|
+
}
|
|
90
|
+
/** Renders the sky into every mip of the base cube, then prefilters; projects SH9. */
|
|
91
|
+
build() {
|
|
92
|
+
const slots = new Float32Array((SLOT / 4) * FACES * MIPS);
|
|
93
|
+
for (let m = 0; m < MIPS; m++)
|
|
94
|
+
for (let f = 0; f < FACES; f++)
|
|
95
|
+
packSkyParams(slots, ((m * FACES + f) * SLOT) / 4, this.#sky, m, f);
|
|
96
|
+
this.device.queue.writeBuffer(this.#params, 0, slots);
|
|
97
|
+
const group = (source) => this.device.createBindGroup({
|
|
98
|
+
layout: this.#layout,
|
|
99
|
+
entries: [
|
|
100
|
+
{ binding: 0, resource: { buffer: this.#params, size: 96 } },
|
|
101
|
+
{ binding: 1, resource: source.createView({ dimension: 'cube' }) },
|
|
102
|
+
{ binding: 2, resource: this.#sampler },
|
|
103
|
+
],
|
|
104
|
+
});
|
|
105
|
+
// The sky pass reads no texture; bind the prefiltered cube as a dummy (never sampled).
|
|
106
|
+
const skyGroup = group(this.prefiltered);
|
|
107
|
+
const filterGroup = group(this.#base);
|
|
108
|
+
const enc = this.device.createCommandEncoder({ label: 'yali:env:build' });
|
|
109
|
+
const draw = (target, m, f, pipeline, g) => {
|
|
110
|
+
const pass = enc.beginRenderPass({
|
|
111
|
+
colorAttachments: [{ view: target.createView({ dimension: '2d', baseMipLevel: m, mipLevelCount: 1, baseArrayLayer: f, arrayLayerCount: 1 }), loadOp: 'clear', storeOp: 'store', clearValue: { r: 0, g: 0, b: 0, a: 1 } }],
|
|
112
|
+
});
|
|
113
|
+
pass.setPipeline(pipeline);
|
|
114
|
+
pass.setBindGroup(0, g, [(m * FACES + f) * SLOT]);
|
|
115
|
+
pass.draw(3);
|
|
116
|
+
pass.end();
|
|
117
|
+
};
|
|
118
|
+
for (let m = 0; m < MIPS; m++)
|
|
119
|
+
for (let f = 0; f < FACES; f++)
|
|
120
|
+
draw(this.#base, m, f, this.#skyPipeline, skyGroup);
|
|
121
|
+
enc.copyTextureToTexture({ texture: this.#base, mipLevel: 0 }, { texture: this.prefiltered, mipLevel: 0 }, { width: SIZE, height: SIZE, depthOrArrayLayers: FACES });
|
|
122
|
+
for (let m = 1; m < MIPS; m++)
|
|
123
|
+
for (let f = 0; f < FACES; f++)
|
|
124
|
+
draw(this.prefiltered, m, f, this.#filterPipeline, filterGroup);
|
|
125
|
+
this.device.queue.submit([enc.finish()]);
|
|
126
|
+
skySh9(this.sh9, this.#sky);
|
|
127
|
+
this.version++;
|
|
128
|
+
}
|
|
129
|
+
destroy() {
|
|
130
|
+
this.#base.destroy();
|
|
131
|
+
this.prefiltered.destroy();
|
|
132
|
+
this.#params.destroy();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** `sky` with `changes`' set fields applied. */
|
|
136
|
+
export function mergeSky(sky, changes) {
|
|
137
|
+
return { ...sky, ...Object.fromEntries(Object.entries(changes).filter(([, v]) => v !== undefined)) };
|
|
138
|
+
}
|
|
139
|
+
/** The sky pass's `SkyParams` (24 floats) for cube face `f` of mip `m`, at `out[o]`: every backend packs it so. */
|
|
140
|
+
export function packSkyParams(out, o, s, m, f) {
|
|
141
|
+
const sun = normalize(s.sun);
|
|
142
|
+
out.set([...sun, m / (MIPS - 1)], o);
|
|
143
|
+
out.set([...s.zenith, 0, ...s.horizon, 0, ...s.ground, 0], o + 4);
|
|
144
|
+
out.set([...s.sunDisk, Math.cos((s.sunAngle * Math.PI) / 180)], o + 16);
|
|
145
|
+
out.set([f, SIZE, MIPS, 0], o + 20);
|
|
146
|
+
}
|
|
147
|
+
/** The SH9 irradiance of sky `s` (`Environment.sh9`), into `out`. */
|
|
148
|
+
export function skySh9(out, s) {
|
|
149
|
+
const sun = normalize(s.sun);
|
|
150
|
+
projectSh9(out, (d) => skyRadiance(s, sun, d));
|
|
151
|
+
}
|
|
152
|
+
function normalize(v) {
|
|
153
|
+
const l = Math.hypot(v[0], v[1], v[2]) || 1;
|
|
154
|
+
return [v[0] / l, v[1] / l, v[2] / l];
|
|
155
|
+
}
|
|
156
|
+
const smoothstep = (a, b, x) => {
|
|
157
|
+
const t = Math.min(1, Math.max(0, (x - a) / (b - a)));
|
|
158
|
+
return t * t * (3 - 2 * t);
|
|
159
|
+
};
|
|
160
|
+
const sat = (x) => Math.min(1, Math.max(0, x));
|
|
161
|
+
/** `sky` of shaders/env/sky.wesl, in TS (for the SH projection). */
|
|
162
|
+
export function skyRadiance(s, sun, d) {
|
|
163
|
+
const up = d[1];
|
|
164
|
+
const out = [0, 0, 0];
|
|
165
|
+
const ta = Math.pow(sat(up), 0.5);
|
|
166
|
+
const tb = sat(-up * 4);
|
|
167
|
+
const disk = smoothstep(Math.cos((s.sunAngle * Math.PI) / 180), 1, d[0] * sun[0] + d[1] * sun[1] + d[2] * sun[2]) * (up >= 0 ? 1 : 0);
|
|
168
|
+
for (let c = 0; c < 3; c++) {
|
|
169
|
+
const above = s.horizon[c] + (s.zenith[c] - s.horizon[c]) * ta;
|
|
170
|
+
const below = s.horizon[c] + (s.ground[c] - s.horizon[c]) * tb;
|
|
171
|
+
out[c] = (up >= 0 ? above : below) + s.sunDisk[c] * disk;
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Projects `radiance` onto real SH up to l = 2 and convolves with the clamped cosine
|
|
177
|
+
* (Ramamoorthi & Hanrahan 2001), divided by π: `out` evaluated at n is the Lambert
|
|
178
|
+
* diffuse radiance for albedo 1. Coefficient order: Y00, Y1-1 (y), Y10 (z), Y11 (x), Y2-2 (xy),
|
|
179
|
+
* Y2-1 (yz), Y20, Y21 (xz), Y22 (x² − y²): `sh_irradiance` in draw.wesl reads the same.
|
|
180
|
+
*/
|
|
181
|
+
export function projectSh9(out, radiance) {
|
|
182
|
+
out.fill(0);
|
|
183
|
+
const nTheta = 64;
|
|
184
|
+
const nPhi = 128;
|
|
185
|
+
const A = [Math.PI, (2 * Math.PI) / 3, (2 * Math.PI) / 3, (2 * Math.PI) / 3, Math.PI / 4, Math.PI / 4, Math.PI / 4, Math.PI / 4, Math.PI / 4];
|
|
186
|
+
for (let i = 0; i < nTheta; i++) {
|
|
187
|
+
const theta = ((i + 0.5) / nTheta) * Math.PI;
|
|
188
|
+
const dOmega = (Math.PI / nTheta) * ((2 * Math.PI) / nPhi) * Math.sin(theta);
|
|
189
|
+
for (let j = 0; j < nPhi; j++) {
|
|
190
|
+
const phi = ((j + 0.5) / nPhi) * 2 * Math.PI;
|
|
191
|
+
const d = [Math.sin(theta) * Math.cos(phi), Math.cos(theta), Math.sin(theta) * Math.sin(phi)];
|
|
192
|
+
const L = radiance(d);
|
|
193
|
+
const [x, y, z] = d;
|
|
194
|
+
const Y = [0.282095, 0.488603 * y, 0.488603 * z, 0.488603 * x, 1.092548 * x * y, 1.092548 * y * z, 0.315392 * (3 * z * z - 1), 1.092548 * x * z, 0.546274 * (x * x - y * y)];
|
|
195
|
+
for (let k = 0; k < 9; k++)
|
|
196
|
+
for (let c = 0; c < 3; c++)
|
|
197
|
+
out[k * 4 + c] += L[c] * Y[k] * dOmega;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
for (let k = 0; k < 9; k++)
|
|
201
|
+
for (let c = 0; c < 3; c++)
|
|
202
|
+
out[k * 4 + c] *= A[k] / Math.PI;
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAe1C,uBAAuB;AACvB,M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AE,CAAC,CAAC,GAAG,CAAC,CAAC;YACpB,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,CAAC,GAAG,CAAC,EAAE,QAAQ,GAAG,CAAC,GAAG,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,GAAG,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAC7K,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;gBAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;oBAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;QACjG,CAAC;IACH,CAAC;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;AAC3F,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type Component, type World } from '@yali-engine/core';
|
|
2
|
+
import { type MeshStore } from './meshes.ts';
|
|
3
|
+
/** What one extract left in linear memory (read by `SceneRenderer.upload`). */
|
|
4
|
+
export interface ExtractedInstances {
|
|
5
|
+
/** Byte address of the records. GPU cull: the transform region, the static region `cap * 32` bytes later. CPU cull: interleaved 40-byte records grouped by draw slot (ADR-0059). */
|
|
6
|
+
readonly address: number;
|
|
7
|
+
/** Records the buffer holds (the static region's offset, in records). */
|
|
8
|
+
readonly cap: number;
|
|
9
|
+
/** Records written. */
|
|
10
|
+
readonly count: number;
|
|
11
|
+
/** True when a static record (colour, mesh, material) changed this frame (GPU cull only). */
|
|
12
|
+
readonly staticChanged: boolean;
|
|
13
|
+
/** Bumped when the buffer was reallocated: its static region must be uploaded whole. */
|
|
14
|
+
readonly epoch: number;
|
|
15
|
+
/** GPU cull: the f64 point the transform records are relative to (ADR-0075); the shaders subtract the camera's offset from it. */
|
|
16
|
+
readonly anchor: Float64Array;
|
|
17
|
+
/** GPU cull: transform ranges rewritten this frame, at `dirtyAt` as `[first, end)` record pairs; -1 = every record (ADR-0075). */
|
|
18
|
+
readonly dirty: number;
|
|
19
|
+
/** Byte address of the dirty ranges (after the count word). */
|
|
20
|
+
readonly dirtyAt: number;
|
|
21
|
+
/** Byte address of the per-mesh counts (GPU cull) or per-slot counts, `mesh * 8 + lod` (CPU cull). */
|
|
22
|
+
readonly countsAt: number;
|
|
23
|
+
/** Meshes counted. */
|
|
24
|
+
readonly meshes: number;
|
|
25
|
+
/** True when this frame was culled on the CPU (`yali_extract_culled`, ADR-0057). */
|
|
26
|
+
readonly culled: boolean;
|
|
27
|
+
/** The shadow cascades the CPU cull partitioned each slot by (0 = none; ADR-0073). */
|
|
28
|
+
readonly cascades: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Floats in the CPU cull's parameter block: six planes, lod scale, error px, min radius px,
|
|
32
|
+
* the cascade count, then five caster planes per cascade (ADR-0073).
|
|
33
|
+
*/
|
|
34
|
+
export declare const CULL_FLOATS = 88;
|
|
35
|
+
/**
|
|
36
|
+
* The render Extract step (M2 increment 2): one core call writes every entity with
|
|
37
|
+
* `render.Mesh` and `GlobalTransform` into linear memory. By default the GPU culls
|
|
38
|
+
* (`yali_extract_instances`: records grouped by mesh, 32-byte transforms relative to an
|
|
39
|
+
* anchor near the camera (ADR-0075) plus 16-byte static records rewritten only on change,
|
|
40
|
+
* ADR-0055; only chunks that changed are rewritten, and the ranges are reported); with
|
|
41
|
+
* `runCulled` the CPU culls and picks LODs (`yali_extract_culled`, ADR-0057: interleaved
|
|
42
|
+
* records grouped by draw slot, with per-slot counts). Owns its linear-memory buffers and
|
|
43
|
+
* grows them when the scene does; allocation-free per frame after that.
|
|
44
|
+
*/
|
|
45
|
+
export declare class InstanceExtractor implements ExtractedInstances {
|
|
46
|
+
#private;
|
|
47
|
+
readonly world: World;
|
|
48
|
+
address: number;
|
|
49
|
+
cap: number;
|
|
50
|
+
count: number;
|
|
51
|
+
staticChanged: boolean;
|
|
52
|
+
epoch: number;
|
|
53
|
+
countsAt: number;
|
|
54
|
+
meshes: number;
|
|
55
|
+
culled: boolean;
|
|
56
|
+
/** The shadow cascades the last CPU cull partitioned by (ADR-0073). */
|
|
57
|
+
cascades: number;
|
|
58
|
+
readonly anchor: Float64Array<ArrayBuffer>;
|
|
59
|
+
dirty: number;
|
|
60
|
+
get dirtyAt(): number;
|
|
61
|
+
/** The CPU cull's parameter block (CULL_FLOATS f32), for `SceneRenderer.writeCullParams`. */
|
|
62
|
+
readonly cullAt: number;
|
|
63
|
+
constructor(world: World, Mesh: Component);
|
|
64
|
+
/** Extracts this frame's instances for the camera at `eye`, for meshes `0..meshes`, for the GPU to cull. Returns the record count. */
|
|
65
|
+
run(eye: Float64Array, meshes: number): number;
|
|
66
|
+
/**
|
|
67
|
+
* Extracts only the visible instances, culled and LOD-selected on the CPU (ADR-0057), with
|
|
68
|
+
* the parameters at `cullAt` (write them first: `SceneRenderer.writeCullParams`) and the
|
|
69
|
+
* meshes' bounds and LOD errors from `store`. Returns the record count.
|
|
70
|
+
*/
|
|
71
|
+
runCulled(eye: Float64Array, store: MeshStore): number;
|
|
72
|
+
/** Frees the linear-memory buffers. */
|
|
73
|
+
dispose(): void;
|
|
74
|
+
}
|
package/dist/extract.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { registerTransforms } from '@yali-engine/core';
|
|
2
|
+
import { MAX_LODS } from "./meshes.js";
|
|
3
|
+
import { INSTANCE_BYTES } from "./scene.js";
|
|
4
|
+
/**
|
|
5
|
+
* Floats in the CPU cull's parameter block: six planes, lod scale, error px, min radius px,
|
|
6
|
+
* the cascade count, then five caster planes per cascade (ADR-0073).
|
|
7
|
+
*/
|
|
8
|
+
export const CULL_FLOATS = 88;
|
|
9
|
+
const MESH_WORDS = 16;
|
|
10
|
+
/** Most dirty ranges the core reports before it says "every record". */
|
|
11
|
+
const DIRTY_CAP = 64;
|
|
12
|
+
/** The anchor moves when the camera is this far from it (metres): f32 offsets stay ~0.06 mm near the camera. */
|
|
13
|
+
const REBASE_DISTANCE = 1000;
|
|
14
|
+
/** The anchor snaps to this grid (metres). */
|
|
15
|
+
const ANCHOR_GRID = 256;
|
|
16
|
+
/**
|
|
17
|
+
* The render Extract step (M2 increment 2): one core call writes every entity with
|
|
18
|
+
* `render.Mesh` and `GlobalTransform` into linear memory. By default the GPU culls
|
|
19
|
+
* (`yali_extract_instances`: records grouped by mesh, 32-byte transforms relative to an
|
|
20
|
+
* anchor near the camera (ADR-0075) plus 16-byte static records rewritten only on change,
|
|
21
|
+
* ADR-0055; only chunks that changed are rewritten, and the ranges are reported); with
|
|
22
|
+
* `runCulled` the CPU culls and picks LODs (`yali_extract_culled`, ADR-0057: interleaved
|
|
23
|
+
* records grouped by draw slot, with per-slot counts). Owns its linear-memory buffers and
|
|
24
|
+
* grows them when the scene does; allocation-free per frame after that.
|
|
25
|
+
*/
|
|
26
|
+
export class InstanceExtractor {
|
|
27
|
+
world;
|
|
28
|
+
#query;
|
|
29
|
+
address = 0;
|
|
30
|
+
cap = 0;
|
|
31
|
+
count = 0;
|
|
32
|
+
staticChanged = false;
|
|
33
|
+
epoch = 0;
|
|
34
|
+
countsAt = 0;
|
|
35
|
+
#countsCap = 0;
|
|
36
|
+
meshes = 0;
|
|
37
|
+
culled = false;
|
|
38
|
+
/** The shadow cascades the last CPU cull partitioned by (ADR-0073). */
|
|
39
|
+
cascades = 0;
|
|
40
|
+
anchor = new Float64Array(3);
|
|
41
|
+
#anchored = false;
|
|
42
|
+
dirty = -1;
|
|
43
|
+
/** The count word, then DIRTY_CAP range pairs. */
|
|
44
|
+
#dirtyWordsAt;
|
|
45
|
+
get dirtyAt() {
|
|
46
|
+
return this.#dirtyWordsAt + 4;
|
|
47
|
+
}
|
|
48
|
+
/** One u32 the core sets when a static record changed. */
|
|
49
|
+
#changedAt;
|
|
50
|
+
/** The CPU cull's parameter block (CULL_FLOATS f32), for `SceneRenderer.writeCullParams`. */
|
|
51
|
+
cullAt;
|
|
52
|
+
#tableAt = 0;
|
|
53
|
+
#tableCap = 0;
|
|
54
|
+
#tableVersion = -1;
|
|
55
|
+
constructor(world, Mesh) {
|
|
56
|
+
this.world = world;
|
|
57
|
+
const { GlobalTransform } = registerTransforms(world);
|
|
58
|
+
this.#query = world.query({
|
|
59
|
+
with: [Mesh, GlobalTransform],
|
|
60
|
+
columns: [[GlobalTransform, 't'], [GlobalTransform, 'r'], [GlobalTransform, 's'], [Mesh, 'mesh'], [Mesh, 'material'], [Mesh, 'color'], [Mesh, 'skin']],
|
|
61
|
+
});
|
|
62
|
+
const x = world.core.exports;
|
|
63
|
+
this.#changedAt = x.yali_alloc(4);
|
|
64
|
+
this.#dirtyWordsAt = x.yali_alloc((1 + 2 * DIRTY_CAP) * 4);
|
|
65
|
+
this.cullAt = x.yali_alloc(CULL_FLOATS * 4);
|
|
66
|
+
}
|
|
67
|
+
/** Moves the anchor to the camera's grid cell when the camera is far from it (a rare full rewrite). */
|
|
68
|
+
#rebase(eye) {
|
|
69
|
+
const a = this.anchor;
|
|
70
|
+
const d = Math.hypot(eye[0] - a[0], eye[1] - a[1], eye[2] - a[2]);
|
|
71
|
+
if (this.#anchored && d <= REBASE_DISTANCE)
|
|
72
|
+
return;
|
|
73
|
+
for (let i = 0; i < 3; i++)
|
|
74
|
+
a[i] = Math.round(eye[i] / ANCHOR_GRID) * ANCHOR_GRID;
|
|
75
|
+
this.#anchored = true;
|
|
76
|
+
}
|
|
77
|
+
#ensureCounts(words) {
|
|
78
|
+
if (this.#countsCap >= words)
|
|
79
|
+
return;
|
|
80
|
+
const x = this.world.core.exports;
|
|
81
|
+
if (this.#countsCap > 0)
|
|
82
|
+
x.yali_dealloc(this.countsAt, this.#countsCap * 4);
|
|
83
|
+
this.#countsCap = nextPow2(words);
|
|
84
|
+
this.countsAt = x.yali_alloc(this.#countsCap * 4);
|
|
85
|
+
}
|
|
86
|
+
#grow(n) {
|
|
87
|
+
const x = this.world.core.exports;
|
|
88
|
+
if (this.cap > 0)
|
|
89
|
+
x.yali_dealloc(this.address, this.cap * INSTANCE_BYTES);
|
|
90
|
+
this.cap = nextPow2(n);
|
|
91
|
+
this.address = x.yali_alloc(this.cap * INSTANCE_BYTES);
|
|
92
|
+
this.epoch++;
|
|
93
|
+
}
|
|
94
|
+
/** Extracts this frame's instances for the camera at `eye`, for meshes `0..meshes`, for the GPU to cull. Returns the record count. */
|
|
95
|
+
run(eye, meshes) {
|
|
96
|
+
const w = this.world;
|
|
97
|
+
this.#ensureCounts(meshes);
|
|
98
|
+
this.#rebase(eye);
|
|
99
|
+
let n = this.#instances(meshes);
|
|
100
|
+
if (n > this.cap) {
|
|
101
|
+
this.#grow(n);
|
|
102
|
+
n = this.#instances(meshes);
|
|
103
|
+
}
|
|
104
|
+
w.core.heap.refresh();
|
|
105
|
+
const u32 = w.core.heap.u32;
|
|
106
|
+
this.staticChanged = u32[this.#changedAt >>> 2] !== 0;
|
|
107
|
+
const ranges = u32[this.#dirtyWordsAt >>> 2];
|
|
108
|
+
this.dirty = ranges === 0xffffffff ? -1 : ranges;
|
|
109
|
+
this.count = n;
|
|
110
|
+
this.meshes = meshes;
|
|
111
|
+
this.culled = false;
|
|
112
|
+
return n;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Extracts only the visible instances, culled and LOD-selected on the CPU (ADR-0057), with
|
|
116
|
+
* the parameters at `cullAt` (write them first: `SceneRenderer.writeCullParams`) and the
|
|
117
|
+
* meshes' bounds and LOD errors from `store`. Returns the record count.
|
|
118
|
+
*/
|
|
119
|
+
runCulled(eye, store) {
|
|
120
|
+
const w = this.world;
|
|
121
|
+
const meshes = store.entries.length;
|
|
122
|
+
this.#syncTable(store);
|
|
123
|
+
w.core.heap.refresh();
|
|
124
|
+
this.cascades = Math.max(0, Math.min(3, w.core.heap.f32[(this.cullAt >>> 2) + 27] | 0));
|
|
125
|
+
this.#ensureCounts(meshes * MAX_LODS << this.cascades);
|
|
126
|
+
let n = this.#culled(eye, meshes);
|
|
127
|
+
if (n > this.cap) {
|
|
128
|
+
this.#grow(n);
|
|
129
|
+
n = this.#culled(eye, meshes);
|
|
130
|
+
}
|
|
131
|
+
w.core.heap.refresh();
|
|
132
|
+
this.staticChanged = true;
|
|
133
|
+
this.dirty = -1;
|
|
134
|
+
this.count = n;
|
|
135
|
+
this.meshes = meshes;
|
|
136
|
+
this.culled = true;
|
|
137
|
+
return n;
|
|
138
|
+
}
|
|
139
|
+
#instances(meshes) {
|
|
140
|
+
const w = this.world;
|
|
141
|
+
const a = this.anchor;
|
|
142
|
+
return w.check(w.core.exports.yali_extract_instances(w.handle, this.#query.id, a[0], a[1], a[2], this.address, this.cap, this.countsAt, meshes, this.#changedAt, this.#dirtyWordsAt, DIRTY_CAP));
|
|
143
|
+
}
|
|
144
|
+
#culled(eye, meshes) {
|
|
145
|
+
const w = this.world;
|
|
146
|
+
return w.check(w.core.exports.yali_extract_culled(w.handle, this.#query.id, eye[0], eye[1], eye[2], this.cullAt, this.#tableAt, meshes, this.address, this.cap, this.countsAt));
|
|
147
|
+
}
|
|
148
|
+
/** The mesh table the CPU cull reads (centre, radius, LOD count, LOD errors), rebuilt when the store changes. */
|
|
149
|
+
#syncTable(store) {
|
|
150
|
+
if (this.#tableVersion === store.version)
|
|
151
|
+
return;
|
|
152
|
+
const x = this.world.core.exports;
|
|
153
|
+
const meshes = store.entries.length;
|
|
154
|
+
if (this.#tableCap < meshes) {
|
|
155
|
+
if (this.#tableCap > 0)
|
|
156
|
+
x.yali_dealloc(this.#tableAt, this.#tableCap * MESH_WORDS * 4);
|
|
157
|
+
this.#tableCap = nextPow2(meshes);
|
|
158
|
+
this.#tableAt = x.yali_alloc(this.#tableCap * MESH_WORDS * 4);
|
|
159
|
+
}
|
|
160
|
+
this.world.core.heap.refresh();
|
|
161
|
+
const f32 = this.world.core.heap.f32;
|
|
162
|
+
const u32 = this.world.core.heap.u32;
|
|
163
|
+
for (let m = 0; m < meshes; m++) {
|
|
164
|
+
const e = store.entries[m];
|
|
165
|
+
const o = (this.#tableAt >>> 2) + m * MESH_WORDS;
|
|
166
|
+
f32[o] = e.center[0];
|
|
167
|
+
f32[o + 1] = e.center[1];
|
|
168
|
+
f32[o + 2] = e.center[2];
|
|
169
|
+
f32[o + 3] = e.radius;
|
|
170
|
+
u32[o + 4] = e.lods.length;
|
|
171
|
+
for (let l = 0; l < MAX_LODS; l++)
|
|
172
|
+
f32[o + 8 + l] = e.lods[l]?.error ?? 0;
|
|
173
|
+
}
|
|
174
|
+
this.#tableVersion = store.version;
|
|
175
|
+
}
|
|
176
|
+
/** Frees the linear-memory buffers. */
|
|
177
|
+
dispose() {
|
|
178
|
+
const x = this.world.core.exports;
|
|
179
|
+
if (this.cap > 0)
|
|
180
|
+
x.yali_dealloc(this.address, this.cap * INSTANCE_BYTES);
|
|
181
|
+
if (this.#countsCap > 0)
|
|
182
|
+
x.yali_dealloc(this.countsAt, this.#countsCap * 4);
|
|
183
|
+
if (this.#tableCap > 0)
|
|
184
|
+
x.yali_dealloc(this.#tableAt, this.#tableCap * MESH_WORDS * 4);
|
|
185
|
+
x.yali_dealloc(this.#changedAt, 4);
|
|
186
|
+
x.yali_dealloc(this.#dirtyWordsAt, (1 + 2 * DIRTY_CAP) * 4);
|
|
187
|
+
x.yali_dealloc(this.cullAt, CULL_FLOATS * 4);
|
|
188
|
+
this.cap = this.#countsCap = this.#tableCap = 0;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function nextPow2(n) {
|
|
192
|
+
return n <= 1 ? 1 : 2 ** Math.ceil(Math.log2(n));
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=extract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,kBAAkB,EAAc,MAAM,mBAAmB,CAAC;AAE/F,OAAO,EAAE,QAAQ,EAAkB,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA8B5C;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAC;AAC9B,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,wEAAwE;AACxE,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,gHAAgH;AAChH,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,8CAA8C;AAC9C,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB;;;;;;;;;GASG;AACH,MAAM,OAAO,iBAAiB;IACnB,KAAK,CAAQ;IACtB,MAAM,CAAQ;IACd,OAAO,GAAG,CAAC,CAAC;IACZ,GAAG,GAAG,CAAC,CAAC;IACR,KAAK,GAAG,CAAC,CAAC;IACV,aAAa,GAAG,KAAK,CAAC;IACtB,KAAK,GAAG,CAAC,CAAC;IACV,QAAQ,GAAG,CAAC,CAAC;IACb,UAAU,GAAG,CAAC,CAAC;IACf,MAAM,GAAG,CAAC,CAAC;IACX,MAAM,GAAG,KAAK,CAAC;IACf,uEAAuE;IACvE,QAAQ,GAAG,CAAC,CAAC;IACJ,MAAM,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;IACtC,SAAS,GAAG,KAAK,CA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AAC,SAAS,GAAG,CAAC,CAAC;IAClD,CAAC;CACF;AAED,SAAS,QAAQ,CAAC,CAAS;IACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/** Context handed to every pass's `execute`. */
|
|
2
|
+
export interface FrameContext {
|
|
3
|
+
readonly device: GPUDevice;
|
|
4
|
+
/** Current render size in pixels (the scene's targets). */
|
|
5
|
+
readonly width: number;
|
|
6
|
+
readonly height: number;
|
|
7
|
+
/** The output size: the canvas, larger than the render size when TAA upscales (ADR-0135); else the same. */
|
|
8
|
+
readonly outputWidth: number;
|
|
9
|
+
readonly outputHeight: number;
|
|
10
|
+
/** A graph texture's view (to sample what an earlier pass wrote). */
|
|
11
|
+
view(name: string): GPUTextureView;
|
|
12
|
+
/** A transient's texture (to copy from it; imported textures have only views). */
|
|
13
|
+
texture(name: string): GPUTexture;
|
|
14
|
+
/** Changes whenever transient textures are (re)allocated: rebuild bind groups that hold views. */
|
|
15
|
+
readonly generation: number;
|
|
16
|
+
}
|
|
17
|
+
interface PassBase {
|
|
18
|
+
/** Unique, conventionally `plugin.what`. */
|
|
19
|
+
readonly name: string;
|
|
20
|
+
/** Logical resources the pass reads (textures or buffers, by name). */
|
|
21
|
+
readonly reads?: readonly string[];
|
|
22
|
+
/** Logical resources the pass writes. */
|
|
23
|
+
readonly writes?: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
/** A compute pass. */
|
|
26
|
+
export interface ComputePassDef extends PassBase {
|
|
27
|
+
readonly kind: 'compute';
|
|
28
|
+
execute(pass: GPUComputePassEncoder, ctx: FrameContext): void;
|
|
29
|
+
}
|
|
30
|
+
/** A render pass. Its attachments are graph textures, so the graph builds the descriptor. */
|
|
31
|
+
export interface RenderPassDef extends PassBase {
|
|
32
|
+
readonly kind: 'render';
|
|
33
|
+
/** The colour attachment; none for a depth-only pass (a shadow map). `load` keeps what an earlier pass drew. */
|
|
34
|
+
readonly color?: {
|
|
35
|
+
readonly target: string;
|
|
36
|
+
readonly clear: GPUColorDict;
|
|
37
|
+
readonly load?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Reverse-Z (ADR-0008): clear depth to 0 and compare `greater`. Depth is discarded after
|
|
41
|
+
* the pass unless `store` (a shadow map another pass samples).
|
|
42
|
+
*/
|
|
43
|
+
readonly depth?: {
|
|
44
|
+
readonly target: string;
|
|
45
|
+
readonly clear: number;
|
|
46
|
+
readonly store?: boolean;
|
|
47
|
+
readonly load?: boolean;
|
|
48
|
+
};
|
|
49
|
+
execute(pass: GPURenderPassEncoder, ctx: FrameContext): void;
|
|
50
|
+
}
|
|
51
|
+
/** Commands outside a pass (a texture copy): the frame's encoder itself. */
|
|
52
|
+
export interface EncoderPassDef extends PassBase {
|
|
53
|
+
readonly kind: 'encoder';
|
|
54
|
+
execute(encoder: GPUCommandEncoder, ctx: FrameContext): void;
|
|
55
|
+
}
|
|
56
|
+
/** A pass of any kind. */
|
|
57
|
+
export type PassDef = ComputePassDef | RenderPassDef | EncoderPassDef;
|
|
58
|
+
/** A texture the graph allocates per frame size and may alias between passes. */
|
|
59
|
+
export interface TransientTexture {
|
|
60
|
+
readonly format: GPUTextureFormat;
|
|
61
|
+
readonly usage: GPUTextureUsageFlags;
|
|
62
|
+
/** Fraction of its size (1 = full resolution). */
|
|
63
|
+
readonly scale?: number;
|
|
64
|
+
/** Sized from the output size instead of the render size: what runs after TAA's upscale (ADR-0135). */
|
|
65
|
+
readonly output?: boolean;
|
|
66
|
+
}
|
|
67
|
+
/** GPU timing hooks (the profiler implements them). */
|
|
68
|
+
export interface PassTimer {
|
|
69
|
+
/** Timestamp writes for pass `index`, or undefined when timestamps are unavailable. */
|
|
70
|
+
timestampWrites(index: number): GPUComputePassTimestampWrites | undefined;
|
|
71
|
+
}
|
|
72
|
+
export declare class FrameGraph {
|
|
73
|
+
#private;
|
|
74
|
+
readonly device: GPUDevice;
|
|
75
|
+
/** Names of the compiled passes in execution order; pass `i` uses timestamp slot `i`.
|
|
76
|
+
* Replaced (not mutated) on each compile, so a holder can detect a recompile by identity. */
|
|
77
|
+
passNames: readonly string[];
|
|
78
|
+
timer: PassTimer | null;
|
|
79
|
+
constructor(device: GPUDevice);
|
|
80
|
+
/** A texture owned outside the graph (the swapchain), fetched once per frame. */
|
|
81
|
+
importTexture(name: string, view: () => GPUTextureView): void;
|
|
82
|
+
/** A texture the graph allocates for the current size. */
|
|
83
|
+
transientTexture(name: string, desc: TransientTexture): void;
|
|
84
|
+
/** Adds a pass. Names are unique. */
|
|
85
|
+
addPass(def: PassDef): void;
|
|
86
|
+
/** The resource the frame exists to produce (usually `backbuffer`). */
|
|
87
|
+
setOutput(name: string): void;
|
|
88
|
+
/** Resizes transients (on the next `execute`); the output size defaults to the render size. */
|
|
89
|
+
resize(width: number, height: number, outputWidth?: number, outputHeight?: number): void;
|
|
90
|
+
/**
|
|
91
|
+
* Orders passes (a pass runs after every earlier-declared pass that writes what it
|
|
92
|
+
* reads), culls passes that don't contribute to the output, and allocates transients.
|
|
93
|
+
*/
|
|
94
|
+
compile(): void;
|
|
95
|
+
/** Bytes the allocated transient textures hold (M2's render-target budget, `budgets.json`). */
|
|
96
|
+
get transientBytes(): number;
|
|
97
|
+
/** Records every compiled pass into `encoder`. */
|
|
98
|
+
execute(encoder: GPUCommandEncoder): void;
|
|
99
|
+
/** Transient textures currently allocated (for the dispose leak check). */
|
|
100
|
+
get liveTextures(): number;
|
|
101
|
+
/** Forces transients to be rebuilt on the next frame (the attachment-mismatch heal). */
|
|
102
|
+
invalidate(): void;
|
|
103
|
+
/** Destroys every transient texture. */
|
|
104
|
+
destroy(): void;
|
|
105
|
+
/** The compiled graph, for inspection (CLI, MCP, overlay). */
|
|
106
|
+
describe(): {
|
|
107
|
+
passes: string[];
|
|
108
|
+
culled: string[];
|
|
109
|
+
transients: string[];
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
export {};
|