@threenative/core 0.3.11 → 0.3.13
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 +1 -1
- package/capabilities.json +1988 -204
- package/dist/{assets-YUbXa3-Y.d.ts → assets-CfMKnOsK.d.ts} +78 -1
- package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
- package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-G7ttVy7y.d.ts} +1 -1
- package/dist/chunk-4SRAQFTU.js +133 -0
- package/dist/chunk-CFGTPFUH.js +231 -0
- package/dist/chunk-DIPIJICH.js +8916 -0
- package/dist/chunk-EEABDLUC.js +2237 -0
- package/dist/chunk-EFWZWLPY.js +1895 -0
- package/dist/chunk-GXY7B3JG.js +46 -0
- package/dist/chunk-GYUZJQ7U.js +280 -0
- package/dist/chunk-H4J6IAJE.js +504 -0
- package/dist/chunk-KIRUKTBQ.js +187 -0
- package/dist/chunk-QWJEMUUT.js +94 -0
- package/dist/chunk-SV4QVUTQ.js +31 -0
- package/dist/chunk-U4YHUKKL.js +615 -0
- package/dist/chunk-VP43GIWW.js +18 -0
- package/dist/chunk-XDTZ4QMO.js +160 -0
- package/dist/default-tone-mapping-GgKPTiBP.d.ts +4 -0
- package/dist/{game-DzMcitDO.d.ts → game-k8K3hZai.d.ts} +85 -9
- package/dist/hot.d.ts +5 -4
- package/dist/hot.js +5 -52
- package/dist/index.d.ts +633 -1351
- package/dist/index.js +12873 -23068
- package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-DPTzeCcD.d.ts} +35 -3
- package/dist/playtest.d.ts +5 -4
- package/dist/playtest.js +25 -75
- package/dist/quality-BYqKGAwo.d.ts +868 -0
- package/dist/react-css.js +1 -215
- package/dist/react.d.ts +3 -2
- package/dist/render-environment.d.ts +170 -0
- package/dist/render-environment.js +352 -0
- package/dist/{renderer-rZm0hVqq.d.ts → renderer-BtOSseYf.d.ts} +42 -35
- package/dist/spells/index.d.ts +643 -0
- package/dist/spells/index.js +1558 -0
- package/dist/spells/ultra/index.d.ts +1600 -0
- package/dist/spells/ultra/index.js +6804 -0
- package/dist/terrain-jobs-worker.js +1 -123
- package/dist/two-sided-foliage-W523J3UM.js +1 -0
- package/dist/ui-layer.js +6 -384
- package/dist/worker.js +13 -43
- package/dist/world.d.ts +988 -268
- package/dist/world.js +17464 -18290
- package/mcp/animation-server.mjs +1 -1
- package/mcp/animation.mjs +2 -3
- package/mcp/engine-server.mjs +245 -52
- package/mcp/servers.mjs +10 -3
- package/mcp/terrain.mjs +8 -0
- package/package.json +19 -7
- package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
- package/patches/three@0.187.0.patch +2004 -407
- package/src/animation-batch.ts +193 -0
- package/src/animation-layers.ts +7 -3
- package/src/animation.ts +209 -29
- package/src/asset-cache.ts +3 -3
- package/src/asset-memo.ts +202 -0
- package/src/assets.ts +437 -125
- package/src/auto-batch.ts +190 -44
- package/src/card-lod.ts +152 -0
- package/src/compressed-texture-preparation.ts +1008 -0
- package/src/compute-driven.ts +1 -1
- package/src/config.ts +8 -0
- package/src/debug.ts +103 -22
- package/src/dev-global.ts +54 -0
- package/src/engine-hooks.ts +37 -0
- package/src/frame-budget.ts +50 -23
- package/src/game-boot-phase.ts +269 -0
- package/src/game-dev-tools.ts +86 -0
- package/src/game-frame-loop.ts +958 -0
- package/src/game-renderer-metrics.ts +77 -0
- package/src/game-startup.ts +1076 -0
- package/src/game-ui.ts +84 -0
- package/src/game-validate.ts +70 -0
- package/src/game.ts +198 -2264
- package/src/gamepad-mappings.ts +269 -0
- package/src/generated/console-markers.ts +13 -0
- package/src/geometry-capture.ts +28 -4
- package/src/gpu-readings.ts +98 -0
- package/src/gpu-scene-bvh.ts +149 -36
- package/src/hot.ts +4 -7
- package/src/index.ts +141 -9
- package/src/input.ts +237 -25
- package/src/instanced-batch-lod.ts +3 -8
- package/src/interpolation.ts +171 -40
- package/src/launch-diagnostics.ts +22 -12
- package/src/look/ao-admission.ts +25 -0
- package/src/look/auto-exposure.ts +5 -16
- package/src/look/default-tone-mapping.ts +41 -5
- package/src/look/filmic-tone-mapping.ts +15 -13
- package/src/look/local-exposure.ts +2 -7
- package/src/look/look-diagnostics.ts +3 -3
- package/src/look/quad-pass.ts +21 -0
- package/src/look/quality.ts +14 -5
- package/src/look/unreal-bloom.ts +4 -13
- package/src/look/world-environment.ts +113 -103
- package/src/loop.ts +29 -0
- package/src/merge-parts.ts +20 -24
- package/src/model-lod.ts +139 -17
- package/src/particle-kinds.ts +515 -0
- package/src/particle-significance.ts +12 -0
- package/src/particles.ts +19 -10
- package/src/picking.ts +17 -3
- package/src/platform.ts +23 -4
- package/src/playtest.ts +27 -1
- package/src/profiling/FrameStages.ts +5 -6
- package/src/profiling/Spans.ts +3 -17
- package/src/profiling/debug-telemetry.ts +2 -6
- package/src/profiling/render-list-validate.ts +6 -15
- package/src/projection-apply.ts +4 -1
- package/src/projection-marker.ts +2 -1
- package/src/projection-plan.ts +9 -6
- package/src/quiet-markers.ts +3 -10
- package/src/render/cpu-bvh.ts +100 -0
- package/src/render/depth-pyramid.ts +6 -14
- package/src/render/environment/environmentContribution.ts +202 -0
- package/src/render/environment/environmentRadiance.ts +44 -0
- package/src/render/environment/environmentSampleCache.ts +56 -0
- package/src/render/environment/environmentSampling.ts +201 -0
- package/src/render/environment/environmentSnapshot.ts +71 -0
- package/src/render/environment/gate.ts +57 -0
- package/src/render/mesh-pool.ts +4 -20
- package/src/render/probe-trace.ts +872 -0
- package/src/render/probe-volume.ts +780 -34
- package/src/render/radiance-cache.ts +17 -0
- package/src/render/resolution-subrect.ts +2 -0
- package/src/render/rough-diffuse.ts +46 -12
- package/src/render/soft-shadow.ts +27 -12
- package/src/render/virtual-shadow-adaptive.ts +55 -0
- package/src/render/virtual-shadow-casters.ts +175 -0
- package/src/render/virtual-shadow-layers.ts +76 -0
- package/src/render/virtual-shadow-level.ts +224 -0
- package/src/render/virtual-shadow-markers.ts +193 -0
- package/src/render/virtual-shadow-options.ts +370 -0
- package/src/render/virtual-shadow-pages.ts +5 -0
- package/src/render/virtual-shadow-partial.ts +13 -0
- package/src/render/virtual-shadow.ts +231 -1008
- package/src/render/world-impostor-surface.ts +402 -40
- package/src/render/world-impostor.ts +5 -2
- package/src/render-camera-cull.ts +98 -3
- package/src/render-environment.ts +41 -0
- package/src/render-pass-budget.ts +34 -7
- package/src/renderProjection.ts +22 -0
- package/src/renderer-config.ts +36 -0
- package/src/renderer-facts.ts +37 -0
- package/src/renderer.ts +144 -65
- package/src/resolution-scaler.ts +3 -2
- package/src/scene-entry-inspectors.ts +61 -0
- package/src/snow-field.ts +2 -1
- package/src/spells/cast-pool.ts +361 -0
- package/src/spells/index.ts +177 -0
- package/src/spells/mechanisms.ts +295 -0
- package/src/spells/reaction-field.ts +415 -0
- package/src/spells/spell-lights.ts +139 -0
- package/src/spells/spell-world.ts +187 -0
- package/src/spells/spell.ts +397 -0
- package/src/spells/spells.ts +283 -0
- package/src/spells/ultra/engine/camera.ts +184 -0
- package/src/spells/ultra/engine/quality.ts +96 -0
- package/src/spells/ultra/index.ts +52 -0
- package/src/spells/ultra/main.ts +305 -0
- package/src/spells/ultra/scene/arenaMaterial.ts +325 -0
- package/src/spells/ultra/spells/cast.ts +233 -0
- package/src/spells/ultra/spells/fire.ts +1267 -0
- package/src/spells/ultra/vfx/FluidVolume.ts +816 -0
- package/src/spells/ultra/vfx/FluidVolume.tsl.ts +855 -0
- package/src/spells/ultra/vfx/FxTarget.ts +61 -0
- package/src/spells/ultra/vfx/GroundField.ts +1399 -0
- package/src/spells/ultra/vfx/Particles.ts +1475 -0
- package/src/spells/ultra/vfx/Ribbons.ts +645 -0
- package/src/spells/ultra/vfx/Shockwaves.ts +286 -0
- package/src/spells/ultra/vfx/Volumes.ts +489 -0
- package/src/spells/ultra/vfx/common.ts +1195 -0
- package/src/spells/ultra/vfx/noise.ts +441 -0
- package/src/startup-offscreen-bytes.ts +78 -0
- package/src/startup-readiness.ts +128 -34
- package/src/static-transform.ts +25 -19
- package/src/streamed-textures.ts +112 -0
- package/src/streaming.ts +68 -4
- package/src/texture-streaming.ts +331 -0
- package/src/version.ts +1 -1
- package/src/warmup.ts +56 -8
- package/src/water-surface.ts +9 -3
- package/src/worker.ts +12 -2
- package/src/world-bundle-safety.ts +446 -0
- package/src/world-cell-batches.ts +1178 -0
- package/src/world-cell-chunks.ts +1128 -0
- package/src/world-cell-data.ts +995 -0
- package/src/world-cell-impostors.ts +1461 -0
- package/src/world-cell-lod-bias.ts +151 -0
- package/src/world-cell-models.ts +1074 -0
- package/src/world-cell-options.ts +177 -0
- package/src/world-cell-placements.ts +798 -0
- package/src/world-cell-prewarm.ts +592 -0
- package/src/world-cell-readiness.ts +357 -0
- package/src/world-cell-records.ts +401 -0
- package/src/world-cell-render-bundles.ts +459 -0
- package/src/world-cell-render-gpu-dress.ts +710 -0
- package/src/world-cell-render-main-cull.ts +540 -0
- package/src/world-cell-render-shadow-claims.ts +198 -0
- package/src/world-cell-render-util.ts +259 -0
- package/src/world-cell-render.ts +1501 -0
- package/src/world-cell-residency.ts +754 -0
- package/src/world-cell-stale.ts +238 -0
- package/src/world-cells.ts +1335 -10418
- package/src/world-chunk-shadow.ts +308 -0
- package/src/world-collar.ts +315 -0
- package/src/world-gpu-flags.ts +131 -0
- package/src/world-gpu-readback.ts +881 -0
- package/src/world-gpu-reference.ts +524 -0
- package/src/world-gpu-scene.ts +256 -2286
- package/src/world-gpu-shadow.ts +203 -0
- package/src/world-gpu-types.ts +409 -0
- package/src/world-gpu-validation.ts +518 -0
- package/src/world-heightfield.ts +802 -0
- package/src/world-load-limiter.ts +111 -0
- package/src/world-model-sections.ts +80 -0
- package/src/world-noise.ts +241 -0
- package/src/world-package.ts +42 -0
- package/src/world-region.ts +1 -1
- package/src/world-river-ribbon.ts +282 -0
- package/src/world-root-frame.ts +39 -0
- package/src/world-shore-field.ts +91 -0
- package/src/world-static-pose.ts +163 -0
- package/src/world-surface-sampler.ts +48 -0
- package/src/world-terrain-splat.ts +361 -153
- package/src/world-tile-budget.ts +249 -0
- package/src/world-tile-geometry.ts +469 -0
- package/src/world-tile-lod.ts +408 -0
- package/src/world-tile-observation.ts +566 -0
- package/src/world-tile-stitch.ts +166 -0
- package/src/world-tiles.ts +247 -1755
- package/src/world-validate.ts +6 -14
- package/src/world-warm.ts +51 -0
- package/src/world-water-bodies.ts +359 -0
- package/src/world.ts +48 -741
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Fn,
|
|
3
|
+
If,
|
|
4
|
+
Loop,
|
|
5
|
+
Return,
|
|
6
|
+
abs,
|
|
7
|
+
atomicAdd,
|
|
8
|
+
float,
|
|
9
|
+
instanceIndex,
|
|
10
|
+
int,
|
|
11
|
+
length,
|
|
12
|
+
mat4,
|
|
13
|
+
max,
|
|
14
|
+
min,
|
|
15
|
+
storage,
|
|
16
|
+
uint,
|
|
17
|
+
vec3,
|
|
18
|
+
} from "three/tsl";
|
|
19
|
+
import type { IndirectStorageBufferAttribute, StorageInstancedBufferAttribute } from "three/webgpu";
|
|
20
|
+
import { GATE_STEP } from "./world-gpu-reference.js";
|
|
21
|
+
import type { IGpuKernel, IGpuSceneBuffers } from "./world-gpu-types.js";
|
|
22
|
+
import { PLACEMENT_ROWS, nodes } from "./world-gpu-types.js";
|
|
23
|
+
import { DRAW_ARGS_WORDS } from "./world-gpu-validation.js";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The shadow twins: a record per key and a run per key at the layout the main pass already gave each
|
|
27
|
+
* key, and the kernel that fills them for one level.
|
|
28
|
+
*
|
|
29
|
+
* The twins are a second copy of two numbers rather than a new key space — the shadow kernel reads
|
|
30
|
+
* the same source, gate, level and key tables and writes at the same offsets into buffers of its
|
|
31
|
+
* own. They are allocated only once a provider has registered, so a launch that never asked for
|
|
32
|
+
* them pays nothing for this module.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The shadow twins' two buffers: a record per key and a run per key, at the layout the main pass
|
|
37
|
+
* already gave each key. Allocated only once a provider has registered.
|
|
38
|
+
*/
|
|
39
|
+
export interface IShadowBuffers {
|
|
40
|
+
readonly args: IndirectStorageBufferAttribute;
|
|
41
|
+
readonly drawn: StorageInstancedBufferAttribute;
|
|
42
|
+
/** Key name to the main key index it twins, so a missing twin is a missing draw, not a crash. */
|
|
43
|
+
readonly keys: Map<string, number>;
|
|
44
|
+
/** The same indices the other way, so a record write knows whether this key has a twin at all. */
|
|
45
|
+
readonly held: Set<number>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* What a built shadow pass reads: the scene's buffers, its own twins, the level's three numbers and
|
|
50
|
+
* the main pass's eye and bias — a shadow map draws each placement at the level the main pass draws
|
|
51
|
+
* it, as the cluster path does.
|
|
52
|
+
*/
|
|
53
|
+
export interface IShadowKernelInput {
|
|
54
|
+
readonly buffers: IGpuSceneBuffers;
|
|
55
|
+
readonly shadow: IShadowBuffers;
|
|
56
|
+
/** The six planes of this map's own shadow camera, as uniforms the dispatch wrote. */
|
|
57
|
+
readonly planes: readonly unknown[];
|
|
58
|
+
/** `(placements, slots, keys, keys)`, written by the dispatch before it submits. */
|
|
59
|
+
readonly counts: unknown;
|
|
60
|
+
readonly eye: unknown;
|
|
61
|
+
readonly bias: unknown;
|
|
62
|
+
/** The level's texel gate in world metres. */
|
|
63
|
+
readonly gate: unknown;
|
|
64
|
+
/** The chain level this map draws at, floored over the placement's own. */
|
|
65
|
+
readonly base: unknown;
|
|
66
|
+
/** Whether a launch asked to measure occlusion, which is the one reason the clear is two threads. */
|
|
67
|
+
readonly measureOcclusion: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The shadow twin of {@link #buildKernel}: the same clear and the same per-placement selection,
|
|
72
|
+
* reading the same source, gate, level and key tables and writing the twin records and runs.
|
|
73
|
+
*
|
|
74
|
+
* Two branches are the level's rather than the camera's — the planes it tests against and its
|
|
75
|
+
* texel gate — and one is the level's base, which floors the main pass's own level at the shape the
|
|
76
|
+
* cluster path hands it. A level whose key has no minted twin (`keys.w`) casts nothing.
|
|
77
|
+
*/
|
|
78
|
+
export function buildShadowKernel(input: IShadowKernelInput): IGpuKernel {
|
|
79
|
+
const { buffers, shadow } = input;
|
|
80
|
+
const source = nodes(storage(buffers.source, "vec4", buffers.source.count));
|
|
81
|
+
const drawn = nodes(storage(shadow.drawn, "mat4", shadow.drawn.count));
|
|
82
|
+
const argsPlain = nodes(storage(shadow.args, "uint", shadow.args.count));
|
|
83
|
+
const argsAtomic = nodes(storage(shadow.args, "uint", shadow.args.count).toAtomic());
|
|
84
|
+
const keys = nodes(storage(buffers.keys, "vec4", buffers.keys.count));
|
|
85
|
+
const locals = nodes(storage(buffers.locals, "mat4", buffers.locals.count));
|
|
86
|
+
const gates = nodes(storage(buffers.gates, "vec4", buffers.gates.count));
|
|
87
|
+
const levels = nodes(storage(buffers.levels, "vec4", buffers.levels.count));
|
|
88
|
+
const counts = nodes(input.counts);
|
|
89
|
+
// The main pass's own eye and bias, which this frame's main dispatch set: a shadow map draws each
|
|
90
|
+
// placement at the level the main pass draws it, as the cluster path does.
|
|
91
|
+
const eye = nodes(input.eye);
|
|
92
|
+
const bias = nodes(input.bias);
|
|
93
|
+
const gate = nodes(input.gate);
|
|
94
|
+
const base = nodes(input.base);
|
|
95
|
+
const planes = input.planes.map((plane) => nodes(plane));
|
|
96
|
+
// Measuring doubles the clear: the second thread per key zeroes that key's word of the
|
|
97
|
+
// measured-occlusion tally, which is why the args buffer is sized for it (see `argsWords`).
|
|
98
|
+
// A run that is not measuring never pays the second thread.
|
|
99
|
+
const clearWidth = input.measureOcclusion ? 2 : 1;
|
|
100
|
+
const clear = Fn(() => {
|
|
101
|
+
If(instanceIndex.greaterThanEqual(counts.w.mul(clearWidth)), () => Return());
|
|
102
|
+
If(instanceIndex.lessThan(counts.w), () => {
|
|
103
|
+
const key = keys.element(instanceIndex);
|
|
104
|
+
argsPlain.element(key.z.mul(DRAW_ARGS_WORDS).add(1)).assign(int(0));
|
|
105
|
+
});
|
|
106
|
+
If(instanceIndex.greaterThanEqual(counts.w), () => {
|
|
107
|
+
argsPlain
|
|
108
|
+
.element(
|
|
109
|
+
nodes(counts.w.mul(DRAW_ARGS_WORDS)).add(
|
|
110
|
+
nodes(float(instanceIndex).sub(counts.w).floor()),
|
|
111
|
+
),
|
|
112
|
+
)
|
|
113
|
+
.assign(int(0));
|
|
114
|
+
});
|
|
115
|
+
})().compute(Math.max(1, buffers.keys.count * clearWidth));
|
|
116
|
+
const cull = Fn(() => {
|
|
117
|
+
If(instanceIndex.greaterThanEqual(counts.x), () => Return());
|
|
118
|
+
// One placement is `PLACEMENT_ROWS` consecutive `vec4` rows: the world matrix's four columns,
|
|
119
|
+
// then the sphere, then `info`. The main kernel reads the same rows; see `world-gpu-reference.ts`.
|
|
120
|
+
const base = instanceIndex.mul(uint(PLACEMENT_ROWS));
|
|
121
|
+
const matrix = mat4(
|
|
122
|
+
source.element(base),
|
|
123
|
+
source.element(base.add(uint(1))),
|
|
124
|
+
source.element(base.add(uint(2))),
|
|
125
|
+
source.element(base.add(uint(3))),
|
|
126
|
+
);
|
|
127
|
+
const centre = source.element(base.add(uint(4)));
|
|
128
|
+
const info = source.element(base.add(uint(5)));
|
|
129
|
+
const slot = info.x;
|
|
130
|
+
If(slot.lessThan(0.0), () => Return());
|
|
131
|
+
If(slot.greaterThanEqual(counts.y), () => Return());
|
|
132
|
+
const radius = centre.w;
|
|
133
|
+
for (const plane of planes) If(plane.dot(centre.xyz).lessThan(radius.negate()), () => Return());
|
|
134
|
+
// Sub-texel, the level's own gate rather than a camera's: a caster this map cannot resolve
|
|
135
|
+
// casts no shadow a fragment could tell from ground cover.
|
|
136
|
+
If(gate.greaterThan(0.0).and(radius.mul(2.0).lessThan(gate)), () => Return());
|
|
137
|
+
const asset = gates.element(slot);
|
|
138
|
+
const distance = length(vec3(centre.x.sub(eye.x), 0.0, centre.z.sub(eye.z)));
|
|
139
|
+
If(asset.w.mod(2.0).greaterThan(0.5).and(distance.greaterThan(asset.z)), () => Return());
|
|
140
|
+
// The main pass's own biased distance and level; see `shadowLevel`, which the reference runs.
|
|
141
|
+
const lodDistance = nodes(distance).mul(bias as never);
|
|
142
|
+
const level = int(0).toVar();
|
|
143
|
+
const scale = abs(info.y);
|
|
144
|
+
Loop({ start: int(1), end: asset.y, type: "int", condition: "<" }, ({ i }: { i: unknown }) => {
|
|
145
|
+
const candidate = levels.element(asset.x.add(i as never));
|
|
146
|
+
const threshold = nodes(candidate.x).toVar();
|
|
147
|
+
If(candidate.w.greaterThan(0.5), () => {
|
|
148
|
+
const previous = levels.element(asset.x.add(i as never).sub(1)).x;
|
|
149
|
+
const floor = previous.add(abs(previous).mul(GATE_STEP));
|
|
150
|
+
threshold.assign(max(floor, candidate.x.mul(scale)));
|
|
151
|
+
});
|
|
152
|
+
// A level the prewarm has minted no key for is not taken, as in the main kernel: see
|
|
153
|
+
// `drawableLevel`, which the reference mirrors.
|
|
154
|
+
If(lodDistance.greaterThan(threshold), () => {
|
|
155
|
+
If(candidate.z.greaterThan(0.5), () => {
|
|
156
|
+
level.assign(i as never);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
// A level casts when its first key has a minted twin (`keys.w`). The shape is the last
|
|
161
|
+
// casting level in `[0, max(level, base)]`: a placement whose own level casts nothing casts
|
|
162
|
+
// with the coarsest one below it that does, and the map's base floors it, clamped to the last
|
|
163
|
+
// level that casts, so a coarse map never asks for a twin that was not minted. None: no cast.
|
|
164
|
+
const castsAt = (index: unknown): unknown => {
|
|
165
|
+
const entry = levels.element(asset.x.add(index as never));
|
|
166
|
+
return nodes(entry.z.greaterThan(0.5)).and(keys.element(entry.y).w.greaterThan(0.5));
|
|
167
|
+
};
|
|
168
|
+
// Authored LODs past castLevels cast nothing, matching WorldCells#castLevelOf.
|
|
169
|
+
If(asset.w.greaterThan(1.5).and(nodes(castsAt(level)).not()), () => Return());
|
|
170
|
+
const shape = int(-1).toVar();
|
|
171
|
+
Loop(
|
|
172
|
+
{
|
|
173
|
+
start: int(0),
|
|
174
|
+
end: nodes(
|
|
175
|
+
max(level as never, int(min(base as never, asset.y.sub(1.0) as never)) as never),
|
|
176
|
+
).add(1),
|
|
177
|
+
type: "int",
|
|
178
|
+
condition: "<",
|
|
179
|
+
},
|
|
180
|
+
({ i }: { i: unknown }) => {
|
|
181
|
+
If(castsAt(i) as never, () => {
|
|
182
|
+
shape.assign(i as never);
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
);
|
|
186
|
+
If(shape.lessThan(0), () => Return());
|
|
187
|
+
const at = levels.element(asset.x.add(shape));
|
|
188
|
+
Loop({ start: int(0), end: at.z, type: "int", condition: "<" }, ({ i }: { i: unknown }) => {
|
|
189
|
+
const keyIndex = at.y.add(i as never);
|
|
190
|
+
const key = keys.element(keyIndex);
|
|
191
|
+
const taken = nodes(atomicAdd(argsAtomic.element(key.z.mul(DRAW_ARGS_WORDS).add(1)), int(1)));
|
|
192
|
+
If(taken.toFloat().lessThan(key.y), () => {
|
|
193
|
+
drawn.element(key.x.add(taken)).assign(matrix.mul(locals.element(keyIndex)));
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
})().compute(
|
|
197
|
+
// One thread per placement record, not per `vec4` row of the source buffer.
|
|
198
|
+
Math.max(1, Math.ceil(buffers.source.count / PLACEMENT_ROWS)),
|
|
199
|
+
);
|
|
200
|
+
clear.setName("worldGpuSceneShadowClear");
|
|
201
|
+
cull.setName("worldGpuSceneShadowCull");
|
|
202
|
+
return { clear, cull };
|
|
203
|
+
}
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import type { BufferAttribute, Matrix4 } from "three";
|
|
2
|
+
import type {
|
|
3
|
+
IndirectStorageBufferAttribute,
|
|
4
|
+
ReadbackBuffer,
|
|
5
|
+
StorageBufferAttribute,
|
|
6
|
+
StorageInstancedBufferAttribute,
|
|
7
|
+
} from "three/webgpu";
|
|
8
|
+
import type { IKernelOcclusion } from "./render/depth-pyramid.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The six frustum planes of `matrix` (projection times view) into `out` as `[nx, ny, nz, d]` rows,
|
|
12
|
+
* the planes three's `Frustum.setFromProjectionMatrix` writes with its default (WebGL) near plane.
|
|
13
|
+
* Read straight from the elements, not through a `Frustum`: the owned engine's facade has no
|
|
14
|
+
* `planes` array (`planes.entries()` threw and stopped the render loop, PRD-857), and one
|
|
15
|
+
* `elements` read replaces 24 bridged getters a frame.
|
|
16
|
+
*/
|
|
17
|
+
export function frustumPlanes(matrix: Matrix4, out: Float32Array): void {
|
|
18
|
+
const m = matrix.elements;
|
|
19
|
+
// [column, sign]: left, right, bottom, top, far, near; each plane is row 3 plus sign times row k.
|
|
20
|
+
const rows = [0, -1, 0, 1, 1, 1, 1, -1, 2, -1, 2, 1] as const;
|
|
21
|
+
for (let plane = 0; plane < 6; plane += 1) {
|
|
22
|
+
const k = rows[plane * 2] as number;
|
|
23
|
+
const sign = rows[plane * 2 + 1] as number;
|
|
24
|
+
const x = (m[3] as number) + sign * (m[k] as number);
|
|
25
|
+
const y = (m[7] as number) + sign * (m[4 + k] as number);
|
|
26
|
+
const z = (m[11] as number) + sign * (m[8 + k] as number);
|
|
27
|
+
const w = (m[15] as number) + sign * (m[12 + k] as number);
|
|
28
|
+
const inverse = 1 / Math.hypot(x, y, z);
|
|
29
|
+
const at = plane * 4;
|
|
30
|
+
out[at] = x * inverse;
|
|
31
|
+
out[at + 1] = y * inverse;
|
|
32
|
+
out[at + 2] = z * inverse;
|
|
33
|
+
out[at + 3] = w * inverse;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** `DrawIndexedIndirect`: indexCount, instanceCount, firstIndex, baseVertex, firstInstance. */
|
|
38
|
+
export const DRAW_ARGS_WORDS = 5;
|
|
39
|
+
/** `mat4` per key: the part's own offset inside the model, the same matrix the CPU composes. */
|
|
40
|
+
export const LOCAL_WORDS = 16;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Everything the GPU scene's buffers, kernels and validation have in common: the layout constants,
|
|
44
|
+
* the record of a resident placement, an asset's gate table, one key's region, what a dispatch reads
|
|
45
|
+
* and what it produced.
|
|
46
|
+
*
|
|
47
|
+
* These live apart from {@link WorldGpuScene} because the validation module imports them and the
|
|
48
|
+
* scene imports the validation module: with the types here, that pair is a chain of one direction
|
|
49
|
+
* and the two files no longer import each other.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/** Words one placement record holds: `mat4` + `centre` (xyz, radius) + `info` (asset slot, …; not `meta`, a reserved WGSL keyword). */
|
|
53
|
+
export const PLACEMENT_WORDS = 24;
|
|
54
|
+
/** The same record in bytes, which is the unit `BufferGeometry.setIndirect` takes its offset in. */
|
|
55
|
+
export const DRAW_ARGS_BYTES = DRAW_ARGS_WORDS * 4;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* How many words the args buffer holds for `keys` keys: one indirect record each, plus one word
|
|
59
|
+
* each of measured-occlusion tally past the last record.
|
|
60
|
+
*
|
|
61
|
+
* The tally rides this buffer rather than a buffer of its own so a measured run reads the two out
|
|
62
|
+
* of the one readback the GPU-selected tally already issues on its own clock — a second readback on
|
|
63
|
+
* a second buffer is a second queue submission per window for eight bytes.
|
|
64
|
+
*/
|
|
65
|
+
export function argsWords(keys: number): number {
|
|
66
|
+
return keys * DRAW_ARGS_WORDS + keys;
|
|
67
|
+
}
|
|
68
|
+
/** One `vec4` per key, per asset slot and per level gate. */
|
|
69
|
+
export const VEC4_WORDS = 4;
|
|
70
|
+
/** Slots a placement may name before the kernel is refused rather than read out of bounds. */
|
|
71
|
+
export const SLOT_NONE = -1;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* One element of every WGSL type this module declares a storage buffer as, in array words.
|
|
75
|
+
*
|
|
76
|
+
* A storage binding's minimum size is one element of its declared type: a `mat4` buffer is 64 bytes
|
|
77
|
+
* whether it holds one matrix or a thousand, and a bound buffer under that is not a wrong picture but
|
|
78
|
+
* a refused pipeline — every dispatch on it is invalid, silently, and only the device complains. So
|
|
79
|
+
* the element count and the element size are not two independent numbers here: they are written down
|
|
80
|
+
* together, once, and every buffer is allocated from this table and nowhere else.
|
|
81
|
+
*/
|
|
82
|
+
export const STORAGE_WORDS = {
|
|
83
|
+
/**
|
|
84
|
+
* `mat4` + `centre` (vec4) + `info` (vec4), so one placement is 96 bytes and one stride. Nothing
|
|
85
|
+
* is allocated from this key any more: the kernels read one placement as {@link PLACEMENT_ROWS}
|
|
86
|
+
* consecutive `vec4` rows, and the source buffer is allocated in those rows. The key stays as the
|
|
87
|
+
* name of the record's whole stride.
|
|
88
|
+
*/
|
|
89
|
+
// quality-allow: the object key names one placement's whole stride, so it keeps that spelling.
|
|
90
|
+
// biome-ignore lint/style/useNamingConvention: the key names one placement's whole stride, spelled as its record.
|
|
91
|
+
GpuPlacement: PLACEMENT_WORDS,
|
|
92
|
+
/** `mat4`, one per key: the part's own offset inside the model, the same one the CPU composes. */
|
|
93
|
+
mat4: LOCAL_WORDS,
|
|
94
|
+
/** `DrawIndexedIndirect`'s five words; `uint` is one word, so the element count is the word count. */
|
|
95
|
+
uint: 1,
|
|
96
|
+
/** One `vec4` per key, per asset slot and per level gate. */
|
|
97
|
+
vec4: VEC4_WORDS,
|
|
98
|
+
} as const;
|
|
99
|
+
|
|
100
|
+
/** A WGSL type the cull kernel declares a storage buffer as, and {@link STORAGE_WORDS}'s key. */
|
|
101
|
+
export type StorageType = keyof typeof STORAGE_WORDS;
|
|
102
|
+
|
|
103
|
+
/** Bytes one element of `type` occupies, which is what a storage binding of it must be at least. */
|
|
104
|
+
export function storageElementBytes(type: StorageType): number {
|
|
105
|
+
return STORAGE_WORDS[type] * 4;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* One storage attribute holding `count` elements — at least one, because a zero-element binding is
|
|
110
|
+
* a zero-byte buffer and zero bytes is under every declared type — of the WGSL `type` the kernel
|
|
111
|
+
* binds it as.
|
|
112
|
+
*
|
|
113
|
+
* The class and the array class are parameters because three's three storage attributes differ only
|
|
114
|
+
* in what the renderer does with them, and this module needs all three: a plain one, the instanced
|
|
115
|
+
* buffer a dressed batch's `instanceMatrix` is, and the indirect records `BufferGeometry.setIndirect`
|
|
116
|
+
* reads. Handing the item size in by hand is how `drawn` was allocated four words wide and bound as
|
|
117
|
+
* a `mat4`: a one-element, 16-byte buffer against a 64-byte requirement, so the cull kernel never
|
|
118
|
+
* ran on a real GPU at all. The size is not a free choice here, so it is not written at a call site.
|
|
119
|
+
*/
|
|
120
|
+
export function storageAttribute<A extends BufferAttribute>(
|
|
121
|
+
ctor: new (count: Float32Array | Uint32Array, itemSize: number) => A,
|
|
122
|
+
type: StorageType,
|
|
123
|
+
count: number,
|
|
124
|
+
array: Float32ArrayConstructor | Uint32ArrayConstructor = Float32Array,
|
|
125
|
+
): A {
|
|
126
|
+
const words = STORAGE_WORDS[type];
|
|
127
|
+
return new ctor(new array(Math.max(1, count) * words), words);
|
|
128
|
+
}
|
|
129
|
+
/** Dispatches between readbacks: a mapped buffer is a queue submission, so not every frame. */
|
|
130
|
+
export const VALIDATE_EVERY = 30;
|
|
131
|
+
/**
|
|
132
|
+
* Dispatches between the tally's own readbacks, on the same budget as a validation.
|
|
133
|
+
*
|
|
134
|
+
* The tally reads the same indirect args buffer a validation reads, so it reuses that readback path
|
|
135
|
+
* and the renderer's one staging buffer rather than adding a second copy: when validation is on its
|
|
136
|
+
* landed bytes feed the tally, and when it is off this is the interval alone.
|
|
137
|
+
*/
|
|
138
|
+
export const TALLY_EVERY = 30;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* How many `vec4` rows one placement record is: the world matrix's four columns, then `centre`, then
|
|
142
|
+
* `info`. The kernels read the source buffer as these rows rather than as one struct element, which
|
|
143
|
+
* the owned engine refuses, and the 24 words are the same words either way.
|
|
144
|
+
*/
|
|
145
|
+
export const PLACEMENT_ROWS = PLACEMENT_WORDS / VEC4_WORDS;
|
|
146
|
+
|
|
147
|
+
/** One resident placement as the source buffer holds it. */
|
|
148
|
+
export interface IGpuPlacement {
|
|
149
|
+
readonly matrix: Float32Array;
|
|
150
|
+
/** X, Y, Z and the bounding-sphere radius; the frustum test reads the first three. */
|
|
151
|
+
readonly centre: Float32Array;
|
|
152
|
+
/** The asset slot in `0`; `SLOT_NONE` for a record whose cell has left the ring. */
|
|
153
|
+
slot: number;
|
|
154
|
+
/**
|
|
155
|
+
* The placement's uniform scale, in `info.y`: the whole-asset impostor's terminal gate is the
|
|
156
|
+
* base-sphere projected distance scaled by this, so a placement scaled ten times does not switch
|
|
157
|
+
* to the atlas until it is ten times as far. `1` when a caller does not carry one.
|
|
158
|
+
*/
|
|
159
|
+
scale?: number;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** One asset's slots: its level gates and the keys each level's parts draw into. */
|
|
163
|
+
export interface IAssetSlot {
|
|
164
|
+
/** Level switch distances, ascending, `0` first; the same numbers the CPU path crosses at. */
|
|
165
|
+
readonly distances: readonly number[];
|
|
166
|
+
/** `maxDistance` less its eighth, or `undefined` for an asset with no cull distance. */
|
|
167
|
+
readonly cull: number | undefined;
|
|
168
|
+
/** Per level: the first key its parts draw into and how many parts it has. */
|
|
169
|
+
readonly levels: readonly { readonly firstKey: number; readonly parts: number }[];
|
|
170
|
+
/**
|
|
171
|
+
* Whether the last level is a whole-asset impostor: its gate is the base-sphere projected
|
|
172
|
+
* distance, and the placement's own scale is applied to it at selection. The reference and the
|
|
173
|
+
* kernel both read it, so an impostor terminal and an authored one cannot be crossed differently.
|
|
174
|
+
*/
|
|
175
|
+
readonly impostor?: boolean;
|
|
176
|
+
/** Derived LODs keep the last casting shape; authored LODs may opt out. Defaults to true. */
|
|
177
|
+
readonly shadowFallback?: boolean;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** One key's region of the shared drawn buffer, and the args record that counts it. */
|
|
181
|
+
export interface IRegion {
|
|
182
|
+
/** Where this key's survivors are written. Moves only in a re-layout, which rewrites every record. */
|
|
183
|
+
start: number;
|
|
184
|
+
/** Instances this region holds. Grows only in a re-layout, which resizes the whole level. */
|
|
185
|
+
capacity: number;
|
|
186
|
+
readonly argsIndex: number;
|
|
187
|
+
/** The part's own offset inside the model; drawn as `placement * local`, as the CPU does. */
|
|
188
|
+
readonly local: Float32Array;
|
|
189
|
+
/** The main key this region is, which is what the validation marker names a mismatch by. */
|
|
190
|
+
readonly name?: string;
|
|
191
|
+
/**
|
|
192
|
+
* The dressed geometry's own index count, which the record's `indexCount` has to say for the draw
|
|
193
|
+
* to name a triangle at all. The owner records it when it dresses the mesh — the scene does not
|
|
194
|
+
* know what shape a key draws — and the validation holds the record against it.
|
|
195
|
+
*/
|
|
196
|
+
indexCount: number;
|
|
197
|
+
/**
|
|
198
|
+
* This key has no shadow twin (its level is past the world's `castLevels`), so a shadow map drops
|
|
199
|
+
* a placement the main pass draws here. The GPU twin reads the same fact as `keys.w`, which only a
|
|
200
|
+
* minted twin sets.
|
|
201
|
+
*/
|
|
202
|
+
readonly uncast?: boolean;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* One storage attribute widened by doubling until it holds `needed`, or itself when it already does.
|
|
207
|
+
* The contents are carried over and marked as one upload range, which is what makes a regrow a copy
|
|
208
|
+
* rather than a fresh zeroed buffer.
|
|
209
|
+
*/
|
|
210
|
+
export function growBuffer<A extends BufferAttribute>(
|
|
211
|
+
current: A,
|
|
212
|
+
needed: number,
|
|
213
|
+
make: (count: number) => A,
|
|
214
|
+
): A {
|
|
215
|
+
if (current.count >= needed) return current;
|
|
216
|
+
let capacity = Math.max(1, current.count);
|
|
217
|
+
while (capacity < needed) capacity *= 2;
|
|
218
|
+
const grown = make(capacity);
|
|
219
|
+
grown.array.set(current.array as Uint32Array);
|
|
220
|
+
grown.addUpdateRange(0, current.array.length);
|
|
221
|
+
return grown;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Adds an update range, extending the last one when the new range touches or overlaps it. */
|
|
225
|
+
export function addRange(
|
|
226
|
+
attribute: {
|
|
227
|
+
updateRanges: { start: number; count: number }[];
|
|
228
|
+
addUpdateRange(start: number, count: number): void;
|
|
229
|
+
},
|
|
230
|
+
start: number,
|
|
231
|
+
count: number,
|
|
232
|
+
): void {
|
|
233
|
+
const last = attribute.updateRanges[attribute.updateRanges.length - 1];
|
|
234
|
+
if (last === undefined || start > last.start + last.count || start + count < last.start) {
|
|
235
|
+
attribute.addUpdateRange(start, count);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const newStart = Math.min(last.start, start);
|
|
239
|
+
// Set the count first. It is measured from the old start.
|
|
240
|
+
last.count = Math.max(last.start + last.count, start + count) - newStart;
|
|
241
|
+
last.start = newStart;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** One level's parts and the single capacity all of them are sized from. */
|
|
245
|
+
export interface ILevelGroup {
|
|
246
|
+
capacity: number;
|
|
247
|
+
/**
|
|
248
|
+
* The key index the level's run starts at, claimed whole at its first key and never moved, so
|
|
249
|
+
* `firstKey + part` names that part's own key however the parts were minted. The run is claimed
|
|
250
|
+
* rather than appended to because keys are not minted in level order: a prewarm mints every level
|
|
251
|
+
* and part of one asset before the next, a walk that arrives mid-prewarm mints whatever its cell
|
|
252
|
+
* needs, and the keys minted in between are not this level's. A run built by appending is a run
|
|
253
|
+
* with another asset's keys inside it, and a gate table that names it draws that asset's placements
|
|
254
|
+
* through this level's parts and this level's placements through the other's — which is a forest
|
|
255
|
+
* drawn with another tree's geometry, and a check that reproduces the same addressing reads it as
|
|
256
|
+
* agreement.
|
|
257
|
+
*/
|
|
258
|
+
firstKey: number;
|
|
259
|
+
/** How many parts the level has, which is the width of the run the gate table names. */
|
|
260
|
+
parts: number;
|
|
261
|
+
/** Part index to the region that part draws into; laid out in this order. */
|
|
262
|
+
readonly minted: Map<number, number>;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Which of a level's parts a key is, so the parts of one level stay the contiguous run the kernel
|
|
267
|
+
* and the gate table both address as `firstKey + part`. `undefined` mints a key of its own, which
|
|
268
|
+
* is every key a caller that has no level to be a part of wants.
|
|
269
|
+
*/
|
|
270
|
+
export interface ILevelKey {
|
|
271
|
+
/** The level this part belongs to — one group, however many parts it has. */
|
|
272
|
+
readonly group: string;
|
|
273
|
+
/** The part's own index in that level, which is the order the group is laid out in. */
|
|
274
|
+
readonly part: number;
|
|
275
|
+
/**
|
|
276
|
+
* How many parts the level has altogether, so the run is claimed once and in full. The caller knows
|
|
277
|
+
* it: the level is an array of parts, and every part of it will be asked for. A part outside the
|
|
278
|
+
* run the level declared is refused rather than laid over another level's key.
|
|
279
|
+
*/
|
|
280
|
+
readonly parts: number;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** The offset a part that has not been minted yet draws with: none at all, and nowhere to draw. */
|
|
284
|
+
export const NO_LOCAL = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
285
|
+
|
|
286
|
+
/** What the kernel reads, and the whole of what a dispatch touches. */
|
|
287
|
+
export interface IKernelInput {
|
|
288
|
+
readonly placements: readonly IGpuPlacement[];
|
|
289
|
+
readonly count: number;
|
|
290
|
+
readonly camera: {
|
|
291
|
+
readonly planes: Float32Array;
|
|
292
|
+
readonly x: number;
|
|
293
|
+
readonly y: number;
|
|
294
|
+
readonly z: number;
|
|
295
|
+
};
|
|
296
|
+
readonly slots: readonly IAssetSlot[];
|
|
297
|
+
readonly regions: readonly IRegion[];
|
|
298
|
+
readonly regionCount: number;
|
|
299
|
+
/**
|
|
300
|
+
* The hierarchical-depth occlusion test, when a launch asked for one. Absent, the frustum is the
|
|
301
|
+
* whole visibility rule; present, every placement the frustum kept is reprojected into the
|
|
302
|
+
* pyramid's own frame and tested. See {@link IKernelOcclusion}.
|
|
303
|
+
*/
|
|
304
|
+
readonly occlusion?: IKernelOcclusion;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** What one dispatch produced: the compacted survivors and the per-key instance counts. */
|
|
308
|
+
export interface IKernelResult {
|
|
309
|
+
/** `DRAW_ARGS_WORDS` per region, `1` the instance count; everything else is the CPU's. */
|
|
310
|
+
readonly args: Uint32Array;
|
|
311
|
+
readonly drawn: Float32Array;
|
|
312
|
+
/** Instances drawn per region, which is what the args record's count must say. */
|
|
313
|
+
readonly counts: Uint32Array;
|
|
314
|
+
/**
|
|
315
|
+
* What the pyramid test hid, and only when one ran: the instances and the triangles of every
|
|
316
|
+
* placement it would have dropped. Absent is "no test ran", never "the test hid nothing" — a
|
|
317
|
+
* measured run reads these while drawing every one of them.
|
|
318
|
+
*/
|
|
319
|
+
readonly occluded?: { readonly instances: number; readonly triangles: number };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* One dispatch's own copy of everything its kernel read, taken while that dispatch runs, plus the
|
|
324
|
+
* attribute the readback has to name.
|
|
325
|
+
*
|
|
326
|
+
* A streamed world changes its placement set, its gate table and its region layout between one frame
|
|
327
|
+
* and the next, so a reference computed when a readback lands describes the frames that followed the
|
|
328
|
+
* dispatch that produced the bytes — which is how a check that compared nothing came to report
|
|
329
|
+
* `compared=0` over 21,147 resident placements. Copied at dispatch time, the reference is a pure
|
|
330
|
+
* function of the snapshot and nothing that happens afterwards can change it.
|
|
331
|
+
*/
|
|
332
|
+
export interface IValidationSnapshot extends IKernelInput {
|
|
333
|
+
/** The indirect records this dispatch wrote, which is what its readback must name. */
|
|
334
|
+
readonly args: unknown;
|
|
335
|
+
/** The shared matrix buffer this dispatch compacted into, which its other readback must name. */
|
|
336
|
+
readonly drawn: unknown;
|
|
337
|
+
/** Resident placements the scene held when this dispatch ran. */
|
|
338
|
+
readonly placed: number;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export interface IValidationReadbacks {
|
|
342
|
+
readonly args: ReadbackBuffer;
|
|
343
|
+
readonly drawn: ReadbackBuffer;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* A TSL node this module pokes at through the swizzles and the `.element()` chain.
|
|
348
|
+
*
|
|
349
|
+
* Three's node types are precise about which swizzle a `vec4` answers and deliberately vague about
|
|
350
|
+
* what a struct member or an atomic result resolves to, and the kernels are the one place in core
|
|
351
|
+
* that has to read a struct member and an atomic's return value. The cast is confined here so the
|
|
352
|
+
* kernels read as the plain shaders they are.
|
|
353
|
+
*/
|
|
354
|
+
// quality-allow: the kernel is a typed handle onto three's TSL nodes, which resolve to `any` in 0.185.
|
|
355
|
+
// biome-ignore lint/suspicious/noExplicitAny: three's TSL types refuse the swizzles this kernel reads.
|
|
356
|
+
export type Kernel = Record<string, any>;
|
|
357
|
+
|
|
358
|
+
/** `storage(...)` results reach the kernel through this, once. */
|
|
359
|
+
export function nodes(value: unknown): Kernel {
|
|
360
|
+
return value as Kernel;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/** The pair a built pass submits: every key's count cleared, then every placement selected. */
|
|
364
|
+
export interface IGpuKernel {
|
|
365
|
+
readonly cull: unknown;
|
|
366
|
+
readonly clear: unknown;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export interface IGpuSceneBuffers {
|
|
370
|
+
readonly args: IndirectStorageBufferAttribute;
|
|
371
|
+
readonly drawn: StorageInstancedBufferAttribute;
|
|
372
|
+
readonly gates: StorageBufferAttribute;
|
|
373
|
+
readonly keys: StorageBufferAttribute;
|
|
374
|
+
readonly levels: StorageBufferAttribute;
|
|
375
|
+
readonly locals: StorageBufferAttribute;
|
|
376
|
+
readonly source: StorageBufferAttribute;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** One of the scene's own storage buffers, by the name it is allocated and grown under. */
|
|
380
|
+
export type BufferName = keyof IGpuSceneBuffers;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* The declared WGSL type of every buffer that is a plain `StorageBufferAttribute` in
|
|
384
|
+
* {@link IGpuSceneBuffers}. `args` and `drawn` are absent because each needs a three class of its own,
|
|
385
|
+
* so `#growOf` names those two literally; the other five share one.
|
|
386
|
+
*/
|
|
387
|
+
export const STORAGE_PLAIN: Record<Exclude<BufferName, "args" | "drawn">, StorageType> = {
|
|
388
|
+
gates: "vec4",
|
|
389
|
+
keys: "vec4",
|
|
390
|
+
levels: "vec4",
|
|
391
|
+
locals: "mat4",
|
|
392
|
+
source: "vec4",
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
/** Resident placements the source buffer is sized to hold before the first reallocation. */
|
|
396
|
+
export const SOURCE_FLOOR = 16;
|
|
397
|
+
|
|
398
|
+
/** One storage buffer as the check reads it: the type the kernel declares and what was allocated. */
|
|
399
|
+
export interface IGpuSceneBufferFootprint {
|
|
400
|
+
readonly type: StorageType;
|
|
401
|
+
readonly count: number;
|
|
402
|
+
/** `array.byteLength` — the size WebGPU compares against one element of `type`. */
|
|
403
|
+
readonly bytes: number;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** The slice of a `GPUDevice` the validation seam reads, so a test can stand in a fake. */
|
|
407
|
+
export interface IDeviceLike {
|
|
408
|
+
onuncapturederror?: ((event: unknown) => void) | null;
|
|
409
|
+
}
|