@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,239 @@
|
|
|
1
|
+
import { type Component, type YaliPlugin } from '@yali-engine/core';
|
|
2
|
+
import { OrbitCamera } from './camera.ts';
|
|
3
|
+
import { DebugLines } from './debug-lines.ts';
|
|
4
|
+
import { type Gpu } from './device.ts';
|
|
5
|
+
import { MaterialStore, MeshStore } from './meshes.ts';
|
|
6
|
+
import { type DeviceFilterRule, type DeviceProfile, type Tier } from './device-profile.ts';
|
|
7
|
+
import { FrameGraph } from './frame-graph.ts';
|
|
8
|
+
import { GpuHealth } from './gpu-health.ts';
|
|
9
|
+
import { GpuTimer } from './gpu-timer.ts';
|
|
10
|
+
import { PipelineCache } from './pipeline-cache.ts';
|
|
11
|
+
import { type SkyOptions } from './environment.ts';
|
|
12
|
+
import { type ShadowOptions } from './shadows.ts';
|
|
13
|
+
import { type LightingOptions, type SceneControls } from './scene.ts';
|
|
14
|
+
import { type TextureFamily, TextureStore } from './textures.ts';
|
|
15
|
+
import { type ToneCurve } from './tonemap.ts';
|
|
16
|
+
import { type PostControls, type PostOptions } from './post-options.ts';
|
|
17
|
+
import { Viewport, type ViewportOptions } from './viewport.ts';
|
|
18
|
+
/** The tone-mapping knobs: `exposure` and `curve` may change any frame. */
|
|
19
|
+
export interface ToneControls {
|
|
20
|
+
exposure: number;
|
|
21
|
+
curve: ToneCurve;
|
|
22
|
+
}
|
|
23
|
+
/** The environment lighting: a procedural sky (`setSky` rebuilds the cube and SH). */
|
|
24
|
+
export interface EnvironmentControls {
|
|
25
|
+
setSky(sky: SkyOptions): void;
|
|
26
|
+
readonly sky: Readonly<Required<SkyOptions>>;
|
|
27
|
+
}
|
|
28
|
+
/** The sun's shadows: `distance` may change at run time. */
|
|
29
|
+
export interface ShadowControls {
|
|
30
|
+
readonly enabled: boolean;
|
|
31
|
+
readonly cascades: number;
|
|
32
|
+
readonly size: number;
|
|
33
|
+
distance: number;
|
|
34
|
+
}
|
|
35
|
+
/** Which backend draws (ADR-0070). */
|
|
36
|
+
export type RenderBackend = 'webgpu' | 'webgpu-compat' | 'webgl2';
|
|
37
|
+
/** What `@yali-engine/render` provides to other plugins (as the `render` resource). Fields are
|
|
38
|
+
* swapped in place on device recovery, so read them each frame rather than caching. */
|
|
39
|
+
export interface RenderContext {
|
|
40
|
+
/** WebGPU (core or compatibility mode), or the WebGL2 fallback where there is no WebGPU (ADR-0070). */
|
|
41
|
+
readonly backend: RenderBackend;
|
|
42
|
+
/** The WebGPU device and canvas context (replaced on recovery); null on WebGL2. */
|
|
43
|
+
gpu: Gpu | null;
|
|
44
|
+
/** The scene renderer's knobs and counters (replaced on recovery). */
|
|
45
|
+
scene: SceneControls;
|
|
46
|
+
/** The tone-mapping pass (replaced on recovery). */
|
|
47
|
+
tonemap: ToneControls;
|
|
48
|
+
/** The post-processing chain's knobs (ADR-0092): bloom, grading, TAA, FXAA. */
|
|
49
|
+
readonly post: PostControls;
|
|
50
|
+
/** The environment lighting (procedural sky, `setSky`); replaced on recovery. */
|
|
51
|
+
environment: EnvironmentControls;
|
|
52
|
+
/** Clustered point and spot lights (ADR-0067): `count`, `dropped`; replaced on recovery. */
|
|
53
|
+
lights: {
|
|
54
|
+
readonly count: number;
|
|
55
|
+
readonly dropped: number;
|
|
56
|
+
};
|
|
57
|
+
/** The sun's cascaded shadow maps (ADR-0068); replaced on recovery. */
|
|
58
|
+
shadows: ShadowControls;
|
|
59
|
+
/** The `render.Light` component (point / spot lights at their `GlobalTransform`), or null without a world. */
|
|
60
|
+
readonly Light: Component | null;
|
|
61
|
+
/** The frame graph (WebGPU; null on WebGL2, whose frame is fixed). */
|
|
62
|
+
graph: FrameGraph | null;
|
|
63
|
+
/** GPU pass timing (WebGPU; null on WebGL2). */
|
|
64
|
+
timer: GpuTimer | null;
|
|
65
|
+
/** Shared pipelines for this device (WebGPU, rebuilt on recovery; null on WebGL2). */
|
|
66
|
+
pipelines: PipelineCache | null;
|
|
67
|
+
/** Render-target sizing; `viewport.renderScale` is the dynamic-resolution knob. */
|
|
68
|
+
readonly viewport: Viewport;
|
|
69
|
+
readonly camera: OrbitCamera;
|
|
70
|
+
/** Debug line segments for this frame (ADR-0087): queue them in Extract or later; drawn over the scene, depth-tested. */
|
|
71
|
+
readonly debug: DebugLines;
|
|
72
|
+
/**
|
|
73
|
+
* Commands each frame records after the scene's uploads and before the frame graph, given the
|
|
74
|
+
* rigid vertex and index pools: GPU deformables writing the vertices this frame draws (ADR-0101)
|
|
75
|
+
* and, torn, their triangles (ADR-0104). WebGPU only.
|
|
76
|
+
*/
|
|
77
|
+
readonly prepasses: ((encoder: GPUCommandEncoder, vertexPool: GPUBuffer, indexPool: GPUBuffer) => void)[];
|
|
78
|
+
readonly health: GpuHealth;
|
|
79
|
+
readonly profile: DeviceProfile;
|
|
80
|
+
readonly tier: Tier;
|
|
81
|
+
/** Every loaded mesh (CPU side; `meshes.add` returns the id `render.Mesh` stores). Mesh 0 is a unit cube. */
|
|
82
|
+
readonly meshes: MeshStore;
|
|
83
|
+
/** Every material (`materials.add` returns the id `render.Mesh.material` stores). Material 0 is white. */
|
|
84
|
+
readonly materials: MaterialStore;
|
|
85
|
+
/** Material textures (ADR-0060): two arrays in the family this device samples, one size class per tier. */
|
|
86
|
+
readonly textures: TextureStore;
|
|
87
|
+
/**
|
|
88
|
+
* The `render.Mesh` component (mesh id, material id, colour), or null without a world.
|
|
89
|
+
* Every entity with it and a `GlobalTransform` is drawn: the plugin extracts them itself.
|
|
90
|
+
*/
|
|
91
|
+
readonly Mesh: Component | null;
|
|
92
|
+
/** Device recoveries this session. */
|
|
93
|
+
recoveries: number;
|
|
94
|
+
/** CPU time of the last frame's encode + submit (including the upload), in ms. */
|
|
95
|
+
submitMs: number;
|
|
96
|
+
/** CPU time of the last frame's instance upload (`writeBuffer` from linear memory), in ms. */
|
|
97
|
+
uploadMs: number;
|
|
98
|
+
/**
|
|
99
|
+
* The most frames submitted to the GPU and not yet finished (live; 0, the default: no cap). A browser
|
|
100
|
+
* that paces frames (vsync) never queues more than two or three; one that does not (a headless
|
|
101
|
+
* benchmark with no frame-rate limit) queues frames until the GPU is a second behind. With a cap, a
|
|
102
|
+
* frame whose turn comes while that many are in flight is not drawn (the world still steps), so
|
|
103
|
+
* the GPU is always busy and never behind (ADR-0129). Not for golden pages, which step the app in a
|
|
104
|
+
* loop and expect every frame drawn.
|
|
105
|
+
*/
|
|
106
|
+
maxFramesInFlight: number;
|
|
107
|
+
/** Frames submitted and not yet finished on the GPU. */
|
|
108
|
+
readonly framesInFlight: number;
|
|
109
|
+
/** Frames not drawn because `maxFramesInFlight` were in flight. */
|
|
110
|
+
readonly skippedFrames: number;
|
|
111
|
+
/**
|
|
112
|
+
* Reads back the next frame exactly as drawn: RGBA8, `width × height × 4` bytes, top row
|
|
113
|
+
* first. Decoded pixels, not a screenshot (no colour conversion, no compositor); golden
|
|
114
|
+
* image tests compare these.
|
|
115
|
+
*/
|
|
116
|
+
capture(): Promise<FrameCapture>;
|
|
117
|
+
/**
|
|
118
|
+
* Destroys the device as if the GPU process had crashed, to exercise recovery. The loss
|
|
119
|
+
* is reported as `unknown`. (A real `destroy()` reports `destroyed`, which is an
|
|
120
|
+
* intentional teardown and is never recovered.)
|
|
121
|
+
*/
|
|
122
|
+
simulateDeviceLoss(): void;
|
|
123
|
+
}
|
|
124
|
+
/** One frame read back by `render.capture()`. */
|
|
125
|
+
export interface FrameCapture {
|
|
126
|
+
readonly width: number;
|
|
127
|
+
readonly height: number;
|
|
128
|
+
/** RGBA8, rows top to bottom, no padding. */
|
|
129
|
+
readonly rgba: Uint8Array;
|
|
130
|
+
}
|
|
131
|
+
/** `@yali-engine/render` options. */
|
|
132
|
+
export interface RenderPluginOptions {
|
|
133
|
+
/** The page's canvas, or the OffscreenCanvas a render worker received (`connectRenderWorker`). */
|
|
134
|
+
readonly canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
135
|
+
/**
|
|
136
|
+
* `auto` (default): WebGPU (core, then compatibility mode), else WebGL2 where the browser
|
|
137
|
+
* has no WebGPU or no adapter (ADR-0070). `webgpu` never falls back; `webgl2` skips WebGPU
|
|
138
|
+
* (tests the fallback on a WebGPU machine).
|
|
139
|
+
*/
|
|
140
|
+
readonly backend?: 'auto' | 'webgpu' | 'webgl2';
|
|
141
|
+
/** Initial instance capacity (grows on demand). */
|
|
142
|
+
readonly capacity?: number;
|
|
143
|
+
/** Force a tier instead of selecting one. */
|
|
144
|
+
readonly tier?: Tier;
|
|
145
|
+
/** Sizing policy (DPR cap, pixel cap, initial render scale). */
|
|
146
|
+
readonly viewport?: ViewportOptions;
|
|
147
|
+
/** Replay a recorded render bundle of the scene's draws (default true: 0.36 → 0.11 ms encode at 5,000 draws, ADR-0050). */
|
|
148
|
+
readonly bundles?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Upload instances through a mapped staging ring. Default: on with a core WebGPU adapter
|
|
151
|
+
* (4–5× faster than `writeBuffer` under 4 MiB, measured in bench/webgpu-upload), off in
|
|
152
|
+
* compatibility mode, where mapping costs far more (Galaxy F04: 11.6 ms against 0.8 ms per
|
|
153
|
+
* 640 KB frame, ADR-0056).
|
|
154
|
+
*/
|
|
155
|
+
readonly staging?: boolean;
|
|
156
|
+
/** Let the frame-budget governor lower the render scale under GPU load (default true). */
|
|
157
|
+
readonly dynamicResolution?: boolean;
|
|
158
|
+
/** Let the governor coarsen LODs and drop sub-pixel instances under GPU load (`render.lodBias`, default true). */
|
|
159
|
+
readonly dynamicLod?: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* How instances reach the vertex stage (ADR-0045): `auto` (default) uses storage buffers
|
|
162
|
+
* when the device allows two in the vertex stage, else the compacted vertex-buffer path.
|
|
163
|
+
*/
|
|
164
|
+
readonly instances?: 'auto' | 'storage' | 'vertex';
|
|
165
|
+
/**
|
|
166
|
+
* Who culls and picks LODs (ADR-0057): `gpu` (a compute pass feeding indirect draws),
|
|
167
|
+
* `cpu` (the extract, with ordinary draws), or `auto` (default): `cpu` in compatibility
|
|
168
|
+
* mode, where indirect draws measured ~9 ms per frame on a Galaxy F04, else `gpu`.
|
|
169
|
+
*/
|
|
170
|
+
readonly cull?: 'auto' | 'gpu' | 'cpu';
|
|
171
|
+
/**
|
|
172
|
+
* Two-pass occlusion culling (ADR-0095): `occlusion()` from `@yali-engine/render/occlusion`. WebGPU's GPU
|
|
173
|
+
* cull on the storage path only (elsewhere it is off and `render.scene.occlusionActive` says so).
|
|
174
|
+
*/
|
|
175
|
+
readonly occlusion?: import('./occlusion.ts').OcclusionFactory;
|
|
176
|
+
/**
|
|
177
|
+
* Cluster culling for big meshes (ADR-0100): `meshlets()` from `@yali-engine/render/meshlets`. The GPU
|
|
178
|
+
* cull's storage path only (elsewhere the meshes draw whole).
|
|
179
|
+
*/
|
|
180
|
+
readonly meshlets?: import('./meshlets.ts').MeshletSupport;
|
|
181
|
+
/** Ask for a WebGPU compatibility-mode adapter first (tests the T0 path on desktop). */
|
|
182
|
+
readonly compat?: boolean;
|
|
183
|
+
/** Texels per side of a texture-array layer. Default per tier: T0 512, T1 1024, T2 2048 (ADR-0060). */
|
|
184
|
+
readonly textureSize?: number;
|
|
185
|
+
/** Force the texture family (default: the best the device samples, `pickFamily`). Textures must be that variant. */
|
|
186
|
+
readonly textureFamily?: TextureFamily;
|
|
187
|
+
/** The tone curve from the HDR scene to the screen (default `neutral`, Khronos PBR Neutral). */
|
|
188
|
+
readonly toneMapping?: ToneCurve;
|
|
189
|
+
/** Linear exposure before the tone curve (default 1). */
|
|
190
|
+
readonly exposure?: number;
|
|
191
|
+
/**
|
|
192
|
+
* Post-processing (ADR-0092): bloom, colour grading, TAA, FXAA, on WebGPU with the HDR
|
|
193
|
+
* target (asking for any turns `hdr` on unless it is set false). WebGL2 grades only.
|
|
194
|
+
*/
|
|
195
|
+
readonly post?: PostOptions;
|
|
196
|
+
/** The procedural sky the environment lighting comes from (M2 increment 5). */
|
|
197
|
+
readonly sky?: SkyOptions;
|
|
198
|
+
/** The sun's colour and intensity and the ambient intensity (the sun's direction is `camera.lightDir`). */
|
|
199
|
+
readonly lighting?: Partial<LightingOptions>;
|
|
200
|
+
/** The sun's cascaded shadow maps (ADR-0068; default on, sized per tier), or `false` for none. */
|
|
201
|
+
readonly shadows?: ShadowOptions | false;
|
|
202
|
+
/**
|
|
203
|
+
* Draw into a half-float HDR target and tone-map it in a pass (default on T1 and T2). Off
|
|
204
|
+
* (T0's default, ADR-0071), the draw tone-maps inline and writes the display directly: the
|
|
205
|
+
* same curve per fragment, without the HDR target's bandwidth or the full-screen pass.
|
|
206
|
+
*/
|
|
207
|
+
readonly hdr?: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Let the governor step the shading down under GPU load (`render.shading`, ADR-0072):
|
|
210
|
+
* full PBR, then Lambert with the ambient and the sun's shadow, then flat with no shadows.
|
|
211
|
+
* Default on T0, where full PBR costs a Galaxy F04 ~30 ms at 20k instances.
|
|
212
|
+
*/
|
|
213
|
+
readonly dynamicShading?: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Benchmarks only: a transform of the linked draw shader, compiled beside it as extra shading
|
|
216
|
+
* levels (`SceneRenderer.shaderVariant`), for A/B measurements in one page.
|
|
217
|
+
*/
|
|
218
|
+
readonly shaderVariant?: (wgsl: string) => string;
|
|
219
|
+
/**
|
|
220
|
+
* The device-filter table (DESIGN.md §14), instead of the engine's `DEVICE_FILTER`; spread
|
|
221
|
+
* that to extend it. A matching rule may lower the tier and turn features off; an option
|
|
222
|
+
* set explicitly here still wins over a turned-off feature.
|
|
223
|
+
*/
|
|
224
|
+
readonly deviceFilter?: readonly DeviceFilterRule[];
|
|
225
|
+
}
|
|
226
|
+
/** The scene's colour target: linear HDR, tone-mapped to the swapchain by `post.tonemap`. */
|
|
227
|
+
export declare const HDR_FORMAT: GPUTextureFormat;
|
|
228
|
+
/**
|
|
229
|
+
* The render plugin (DESIGN.md §11–§14). It acquires a WebGPU device (core, then
|
|
230
|
+
* compatibility mode) or, where the browser has no WebGPU, falls back to WebGL2 (ADR-0070),
|
|
231
|
+
* selects the tier, draws extracted instances each frame (Submit stage), and rebuilds its
|
|
232
|
+
* whole device state after device loss without restarting the app (DESIGN.md §3).
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* const app = App.create({ plugins: [renderPlugin({ canvas }), gamePlugin] });
|
|
236
|
+
* await app.init();
|
|
237
|
+
* app.start();
|
|
238
|
+
*/
|
|
239
|
+
export declare function renderPlugin(options: RenderPluginOptions): YaliPlugin;
|