@wildshard/shard-format 0.23.0 → 0.25.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/package.json +1 -1
- package/src/format/boot-memory-cost.ts +123 -0
- package/src/format/budget.ts +17 -10
- package/src/format/contentCost.ts +23 -4
- package/src/format/memory-epoch.ts +1 -1
- package/src/format/memory-line.ts +12 -13
- package/src/format/shardfile-assets.ts +13 -7
- package/src/format/shardfile-stream-admit.ts +1 -1
- package/src/format/shardfileValidation.ts +4 -4
- package/src/format/skinData.ts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { controlFileHashes } from './admissionControl.ts'
|
|
2
|
+
import { textureMipBytes } from './contentBounds.ts'
|
|
3
|
+
import { spawnViewSceneFiles } from './spawnView.ts'
|
|
4
|
+
import { parseWorldScenes, worldScenesForTier } from './worldScenes.ts'
|
|
5
|
+
|
|
6
|
+
import type { Shardfile } from './shardSchema.ts'
|
|
7
|
+
import type { WorldScenesSection } from './worldScenes.ts'
|
|
8
|
+
|
|
9
|
+
interface BootMemoryCosts {
|
|
10
|
+
readonly heldSpawnParts: number
|
|
11
|
+
readonly largestDecode: number
|
|
12
|
+
readonly shaderCompile: number
|
|
13
|
+
readonly farSlabIndices: number
|
|
14
|
+
readonly paintArrayGpu: number
|
|
15
|
+
readonly paintArrayStaging: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const NO_BYTES = 0
|
|
19
|
+
const TRIANGLE_CORNERS = 3
|
|
20
|
+
const INDEX_COPIES = 2
|
|
21
|
+
const FAR_SLAB_INDEX_SHARE = 0.75
|
|
22
|
+
const RGBA_BYTES = 4
|
|
23
|
+
const BASE_LEVEL = 1
|
|
24
|
+
// MG6: Nine's cold phone-tier shader step rose by 193 MB in the mini's
|
|
25
|
+
// Chromium capture (04d76bcf). The calibrated increment rounds to 168 MB.
|
|
26
|
+
const SHADER_COMPILE_BYTES = 168_000_000
|
|
27
|
+
|
|
28
|
+
function spawnMemoryCosts(
|
|
29
|
+
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
|
|
30
|
+
shard: Shardfile,
|
|
31
|
+
sections: ReadonlyMap<string, unknown>,
|
|
32
|
+
): Pick<BootMemoryCosts, 'heldSpawnParts' | 'largestDecode'> {
|
|
33
|
+
const controls = new Set([
|
|
34
|
+
...controlFileHashes(shard),
|
|
35
|
+
...spawnViewSceneFiles(sections),
|
|
36
|
+
])
|
|
37
|
+
let heldSpawnParts = Object.values(shard.requires.commonsWire).reduce(
|
|
38
|
+
(sum, bytes): number => sum + bytes,
|
|
39
|
+
NO_BYTES,
|
|
40
|
+
)
|
|
41
|
+
let largestDecode = NO_BYTES
|
|
42
|
+
for (const file of shard.files) {
|
|
43
|
+
if (controls.has(file.hash)) {
|
|
44
|
+
heldSpawnParts += file.compressed
|
|
45
|
+
largestDecode = Math.max(largestDecode, file.decoded)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { heldSpawnParts, largestDecode }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type SlabFile = Readonly<Pick<Shardfile['files'][number], 'hash' | 'triangles'>>
|
|
52
|
+
|
|
53
|
+
function farSlabBytes(
|
|
54
|
+
files: readonly SlabFile[],
|
|
55
|
+
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's scene rows, only read
|
|
56
|
+
scene: WorldScenesSection | undefined,
|
|
57
|
+
): number {
|
|
58
|
+
const slabs = new Set<string>()
|
|
59
|
+
for (const library of scene?.libraries ?? []) {
|
|
60
|
+
if (library.kind === 'slabs') {
|
|
61
|
+
for (const tile of library.tiles) {
|
|
62
|
+
for (const file of tile.files) {
|
|
63
|
+
slabs.add(file.file)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// NB23: engine's slabLibrary reserves 75% more indices for the far levels.
|
|
69
|
+
const triangles = files.reduce(
|
|
70
|
+
(sum, file): number =>
|
|
71
|
+
sum +
|
|
72
|
+
(slabs.has(file.hash)
|
|
73
|
+
? Math.ceil(file.triangles * FAR_SLAB_INDEX_SHARE)
|
|
74
|
+
: NO_BYTES),
|
|
75
|
+
NO_BYTES,
|
|
76
|
+
)
|
|
77
|
+
return (
|
|
78
|
+
triangles * TRIANGLE_CORNERS * Uint32Array.BYTES_PER_ELEMENT * INDEX_COPIES
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function paintArrayBytes(
|
|
83
|
+
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's scene rows, only read
|
|
84
|
+
scene: WorldScenesSection | undefined,
|
|
85
|
+
): Pick<BootMemoryCosts, 'paintArrayGpu' | 'paintArrayStaging'> {
|
|
86
|
+
let paintArrayGpu = NO_BYTES
|
|
87
|
+
let paintArrayStaging = NO_BYTES
|
|
88
|
+
for (const row of scene?.lent ?? []) {
|
|
89
|
+
if (row.kind === 'layers') {
|
|
90
|
+
const edge = row.size.phone
|
|
91
|
+
paintArrayGpu +=
|
|
92
|
+
textureMipBytes(
|
|
93
|
+
edge,
|
|
94
|
+
edge,
|
|
95
|
+
Math.floor(Math.log2(edge)) + BASE_LEVEL,
|
|
96
|
+
false,
|
|
97
|
+
) * row.layers.length
|
|
98
|
+
paintArrayStaging += edge * edge * RGBA_BYTES * row.layers.length
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { paintArrayGpu, paintArrayStaging }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Boot memory that sits outside the steady-state file and tile budgets. */
|
|
105
|
+
function bootMemoryCosts(
|
|
106
|
+
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
|
|
107
|
+
shard: Shardfile,
|
|
108
|
+
sections: ReadonlyMap<string, unknown>,
|
|
109
|
+
): BootMemoryCosts {
|
|
110
|
+
const rawScene = sections.get('world/scenes')
|
|
111
|
+
const scene =
|
|
112
|
+
rawScene === undefined
|
|
113
|
+
? undefined
|
|
114
|
+
: worldScenesForTier(parseWorldScenes(rawScene), 'phone')
|
|
115
|
+
return {
|
|
116
|
+
...spawnMemoryCosts(shard, sections),
|
|
117
|
+
shaderCompile: SHADER_COMPILE_BYTES,
|
|
118
|
+
farSlabIndices: farSlabBytes(shard.files, scene),
|
|
119
|
+
...paintArrayBytes(scene),
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { type BootMemoryCosts, bootMemoryCosts }
|
package/src/format/budget.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { CONTENT_CAPS as C } from './contentBounds.ts';
|
|
|
2
2
|
import { contentCost } from './contentCost.ts';
|
|
3
3
|
import type { Shardfile } from './shardSchema.ts';
|
|
4
4
|
import { NEAR_PLACEHOLDER_LIMITS, nearPlaceholderCost } from './nearPlaceholder.ts';
|
|
5
|
+
import type { BootMemoryCosts } from './boot-memory-cost.ts';
|
|
5
6
|
|
|
6
7
|
/** Category resident targets are tradeable warnings; only the complete playing/loading totals refuse memory. */
|
|
7
8
|
export function memoryTargetWarnings(shard: Shardfile): { category: string; bytes: number; target: number }[] {
|
|
@@ -59,7 +60,12 @@ interface LocationModel {
|
|
|
59
60
|
cost: (x: number, z: number) => LocationCost;
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
interface BudgetOptions { readonly commons: number; readonly boot: BootMemoryCosts }
|
|
64
|
+
const NO_BYTES = 0;
|
|
65
|
+
|
|
66
|
+
function locationModels(shard: Shardfile, options: number | BudgetOptions): LocationModel[] {
|
|
67
|
+
const commons = typeof options === 'number' ? options : options.commons;
|
|
68
|
+
const boot = typeof options === 'number' ? undefined : options.boot;
|
|
63
69
|
const bytesOf = ownTileBytes(shard), own = shard.tiles.filter(tile => tile.lod === 0).map(tile => {
|
|
64
70
|
const bounds = tile.drawBounds ?? tile.bounds;
|
|
65
71
|
return { x0: bounds.min[0], z0: bounds.min[2], x1: bounds.max[0], z1: bounds.max[2], bytes: bytesOf(tile) };
|
|
@@ -93,10 +99,10 @@ function locationModels(shard: Shardfile, commons: number): LocationModel[] {
|
|
|
93
99
|
return l0;
|
|
94
100
|
};
|
|
95
101
|
models.push({
|
|
96
|
-
neighbours: neighbours.map(({ cx, cz }) => [cx, cz] as const), fixed: l1 + far + sims + commons + nearBytes,
|
|
102
|
+
neighbours: neighbours.map(({ cx, cz }) => [cx, cz] as const), fixed: l1 + far + sims + commons + nearBytes + (boot?.farSlabIndices ?? NO_BYTES) + (boot?.paintArrayGpu ?? NO_BYTES),
|
|
97
103
|
cost: (x, z) => {
|
|
98
104
|
const l0 = l0At(x, z);
|
|
99
|
-
return { ...contentCost({ l0, l1, far, libraries, sims, commons, near: nearBytes, overlap }), location: [x, z] };
|
|
105
|
+
return { ...contentCost({ l0, l1, far, libraries, sims, commons, near: nearBytes, overlap, boot }), location: [x, z] };
|
|
100
106
|
},
|
|
101
107
|
});
|
|
102
108
|
}
|
|
@@ -104,10 +110,11 @@ function locationModels(shard: Shardfile, commons: number): LocationModel[] {
|
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
/** Conservative total around an actual player location, using the same neighbour assumptions as admission. */
|
|
107
|
-
export function nearbyContentCost(shard: Shardfile, x: number, z: number,
|
|
113
|
+
export function nearbyContentCost(shard: Shardfile, x: number, z: number, options: number | BudgetOptions = 0): LocationCost {
|
|
114
|
+
const commons = typeof options === 'number' ? options : options.commons;
|
|
108
115
|
if (![x, z, commons].every(Number.isFinite) || commons < 0) throw new Error('Invalid memory estimate location');
|
|
109
116
|
let worst: LocationCost = { playing: 0, loading: 0, accounted: 0, location: [x, z] };
|
|
110
|
-
for (const model of locationModels(shard,
|
|
117
|
+
for (const model of locationModels(shard, options)) { const cost = model.cost(x, z); if (cost.playing > worst.playing) worst = cost; }
|
|
111
118
|
return worst;
|
|
112
119
|
}
|
|
113
120
|
|
|
@@ -118,14 +125,14 @@ const worstCache = new Map<string, LocationCost>();
|
|
|
118
125
|
const syntheticCells = new Map<string, { l0: Uint8Array; active: Uint8Array }>();
|
|
119
126
|
|
|
120
127
|
/** Worst disc with three synthetic neighbours at the platform targets; grid padding covers unsampled gaps. */
|
|
121
|
-
export function worstContentCost(shard: Shardfile,
|
|
122
|
-
const steps = worstContentCostSteps(shard,
|
|
128
|
+
export function worstContentCost(shard: Shardfile, options: number | BudgetOptions = 0): LocationCost {
|
|
129
|
+
const steps = worstContentCostSteps(shard, options);
|
|
123
130
|
for (;;) { const step = steps.next(); if (step.done === true) return step.value; }
|
|
124
131
|
}
|
|
125
132
|
|
|
126
133
|
/** `worstContentCost` in steps, one per own tile and synthetic neighbour tile the grids sum, then one per scanned row:
|
|
127
134
|
* a live admission paints between them (Pine's activation spent ~90 ms of a frame in this scan at 4x CPU). */
|
|
128
|
-
export function* worstContentCostSteps(shard: Shardfile,
|
|
135
|
+
export function* worstContentCostSteps(shard: Shardfile, options: number | BudgetOptions = 0): Generator<void, LocationCost> {
|
|
129
136
|
const bytesOf = ownTileBytes(shard);
|
|
130
137
|
// The cache key is the JSON of every tile's [lod, bytes, x0, z0, x1, z1] and the shard's budgets, written row by row
|
|
131
138
|
// (the same text, without an array per tile).
|
|
@@ -136,7 +143,7 @@ export function* worstContentCostSteps(shard: Shardfile, commons = 0): Generator
|
|
|
136
143
|
const bounds = tile.drawBounds ?? tile.bounds;
|
|
137
144
|
rows += `${i > 0 ? ',' : ''}[${json(tile.lod)},${json(bytesOf(tile))},${json(bounds.min[0])},${json(bounds.min[2])},${json(bounds.max[0])},${json(bounds.max[2])}]`;
|
|
138
145
|
}
|
|
139
|
-
const key = `[[${rows}],${JSON.stringify([shard.far === null ? null : [shard.far.decoded, shard.far.gpu], shard.budgets.library.resident, shard.budgets.sim.resident, shard.budgets.overlap, shard.serverBudget.memory,
|
|
146
|
+
const key = `[[${rows}],${JSON.stringify([shard.far === null ? null : [shard.far.decoded, shard.far.gpu], shard.budgets.library.resident, shard.budgets.sim.resident, shard.budgets.overlap, shard.serverBudget.memory, options,
|
|
140
147
|
shard.near === undefined ? 0 : nearPlaceholderCost(shard.near, shard).total.resident]).slice(1)}`;
|
|
141
148
|
const cached = worstCache.get(key);
|
|
142
149
|
if (cached !== undefined) return { ...cached, location: [...cached.location] };
|
|
@@ -193,7 +200,7 @@ export function* worstContentCostSteps(shard: Shardfile, commons = 0): Generator
|
|
|
193
200
|
syntheticCells.set(id, made); return made;
|
|
194
201
|
};
|
|
195
202
|
let worstAccounted = Number.NEGATIVE_INFINITY;
|
|
196
|
-
for (const model of locationModels(shard,
|
|
203
|
+
for (const model of locationModels(shard, options)) {
|
|
197
204
|
const found: { l0: Uint8Array; active: Uint8Array }[] = [];
|
|
198
205
|
for (const neighbour of model.neighbours) found.push(yield* cellOf(neighbour));
|
|
199
206
|
const [a, b, c] = found;
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { CONTENT_CAPS as C } from './contentBounds.ts';
|
|
2
|
+
import type { BootMemoryCosts } from './boot-memory-cost.ts';
|
|
3
|
+
|
|
4
|
+
const NO_BYTES = 0;
|
|
5
|
+
|
|
6
|
+
function bootResident(boot: BootMemoryCosts | undefined): number {
|
|
7
|
+
return boot === undefined ? NO_BYTES : boot.farSlabIndices + boot.paintArrayGpu;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function bootOverlap(overlap: number, boot: BootMemoryCosts): number {
|
|
11
|
+
// Stores release their parts before compile. Charge the larger of the
|
|
12
|
+
// transport/decode phase and the compiler/paint upload phase.
|
|
13
|
+
return Math.max(overlap, boot.heldSpawnParts + boot.largestDecode, boot.shaderCompile + boot.paintArrayStaging);
|
|
14
|
+
}
|
|
2
15
|
|
|
3
16
|
/** Shared resident-cost input: dependency-deduplicated category bytes, including persistent CPU and GPU data. */
|
|
4
17
|
export interface ContentCostInput {
|
|
@@ -6,19 +19,25 @@ export interface ContentCostInput {
|
|
|
6
19
|
products?: number; near?: number;
|
|
7
20
|
/** Actual concurrent decode headroom; zero when no overlap is present. */
|
|
8
21
|
overlap: number;
|
|
22
|
+
/** Additional resident and transient costs derived from the cold boot. */
|
|
23
|
+
boot?: BootMemoryCosts | undefined;
|
|
9
24
|
/** Calibrated base after any explicitly split renderer-component credit. */
|
|
10
25
|
engineBase?: number;
|
|
11
26
|
/** Actual grid page allocations only. Standalone callers omit this; no grid
|
|
12
27
|
* program cache, road or continuation allowance is implicit in this model. */
|
|
13
28
|
page?: number;
|
|
14
29
|
}
|
|
30
|
+
|
|
15
31
|
/** Estimated resident cost, calibrated against the Simulator template census.
|
|
16
32
|
* Process/GPU measurements remain observations, distinct from this prediction. */
|
|
17
33
|
export function contentCost(input: ContentCostInput): { playing: number; loading: number; accounted: number } {
|
|
18
|
-
const resident = input.l0 + input.l1 + input.far + input.libraries + input.sims + input.commons + (input.products ?? 0) + (input.near ?? 0);
|
|
34
|
+
const resident = input.l0 + input.l1 + input.far + input.libraries + input.sims + input.commons + (input.products ?? 0) + (input.near ?? 0) + bootResident(input.boot);
|
|
19
35
|
const page = input.page ?? 0, accounted = resident + page;
|
|
20
|
-
const
|
|
21
|
-
|
|
36
|
+
const base = (input.engineBase ?? C.engineBase) + page + Math.ceil(resident * C.residentFactor);
|
|
37
|
+
const playing = base + input.overlap;
|
|
38
|
+
// The boot phases and playing churn share the same allocation headroom.
|
|
39
|
+
const loading = input.boot === undefined ? playing + input.overlap : base + bootOverlap(input.overlap, input.boot);
|
|
40
|
+
return { playing, loading, accounted };
|
|
22
41
|
}
|
|
23
42
|
|
|
24
43
|
/** G762: an advisory projection needs an independently measured engine base.
|
|
@@ -36,7 +55,7 @@ export interface ContentEstimate {
|
|
|
36
55
|
/** Predict component costs without an accuracy pass/fail or a native-budget verdict.
|
|
37
56
|
* The measured base must exclude the separately supplied content/page components.
|
|
38
57
|
* Runtime admission retains its independent, conservative contentCost contract. */
|
|
39
|
-
export function contentEstimate(input: Omit<ContentCostInput, 'engineBase'>, measuredEngineBytes: number | null): ContentEstimate {
|
|
58
|
+
export function contentEstimate(input: Omit<ContentCostInput, 'engineBase' | 'boot'>, measuredEngineBytes: number | null): ContentEstimate {
|
|
40
59
|
if (measuredEngineBytes !== null && (!Number.isSafeInteger(measuredEngineBytes) || measuredEngineBytes < 0)) throw new RangeError('Invalid measured engine base');
|
|
41
60
|
const components = { l0: input.l0, l1: input.l1, far: input.far, libraries: input.libraries, sims: input.sims, commons: input.commons,
|
|
42
61
|
products: input.products ?? 0, near: input.near ?? 0, page: input.page ?? 0 };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* `runtimeCost` reading must have been taken against. It rises when the model changes what it charges (MG6 adds shader
|
|
3
3
|
* compile, load transients, far slabs and paint arrays); from then a reading from an older epoch is refused until the
|
|
4
4
|
* shard re-measures. A reading with no `epoch` is epoch 1, the model before MG6. */
|
|
5
|
-
const MEMORY_EPOCH =
|
|
5
|
+
const MEMORY_EPOCH = 2
|
|
6
6
|
const LEGACY_EPOCH = 1
|
|
7
7
|
|
|
8
8
|
interface EpochRow {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bootMemoryCosts } from './boot-memory-cost.ts'
|
|
1
2
|
import { worstContentCost } from './budget.ts'
|
|
2
3
|
import { runtimeAccountedBytes } from './runtimeCost.ts'
|
|
3
4
|
|
|
@@ -39,20 +40,23 @@ function hardLineIssue(
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
/**
|
|
43
|
-
function
|
|
43
|
+
/** Count cold-boot costs and any opaque runtime residency in offline admission. */
|
|
44
|
+
function offlineMemoryIssues(
|
|
44
45
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard type, read only
|
|
45
46
|
source: Shardfile,
|
|
47
|
+
sections: ReadonlyMap<string, unknown>,
|
|
46
48
|
): ReturnType<typeof hardLineIssue>[] {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const runtime = runtimeAccountedBytes(source.runtime.cost)
|
|
49
|
+
const native = source.runtime?.cost
|
|
50
|
+
const runtime =
|
|
51
|
+
native === undefined ? EMPTY_BYTES : runtimeAccountedBytes(native)
|
|
51
52
|
const commons = Object.values(source.requires.commonsCosts).reduce(
|
|
52
53
|
(sum, row): number => sum + row.decoded + row.gpu,
|
|
53
54
|
EMPTY_BYTES,
|
|
54
55
|
)
|
|
55
|
-
const cost = worstContentCost(source,
|
|
56
|
+
const cost = worstContentCost(source, {
|
|
57
|
+
commons: runtime + commons,
|
|
58
|
+
boot: bootMemoryCosts(source, sections),
|
|
59
|
+
})
|
|
56
60
|
return (['playing', 'loading'] as const)
|
|
57
61
|
.filter((kind): boolean => cost[kind] > MEMORY_HARD_BYTES)
|
|
58
62
|
.map((kind): ReturnType<typeof hardLineIssue> =>
|
|
@@ -60,9 +64,4 @@ function offlineRuntimeMemoryIssues(
|
|
|
60
64
|
)
|
|
61
65
|
}
|
|
62
66
|
|
|
63
|
-
export {
|
|
64
|
-
MEMORY_HARD_BYTES,
|
|
65
|
-
hardLineIssue,
|
|
66
|
-
offlineRuntimeMemoryIssues,
|
|
67
|
-
overHardLine,
|
|
68
|
-
}
|
|
67
|
+
export { MEMORY_HARD_BYTES, hardLineIssue, offlineMemoryIssues, overHardLine }
|
|
@@ -15,6 +15,7 @@ import { worstContentCost, memoryTargetWarnings, nearbyContentCost } from "./bud
|
|
|
15
15
|
import { CONTENT_CAPS as C, MEMORY_GATES } from './contentBounds.ts';
|
|
16
16
|
import { staleRuntimeIssues } from './memory-epoch.ts';
|
|
17
17
|
import { MEMORY_HARD_BYTES, hardLineIssue } from './memory-line.ts';
|
|
18
|
+
import { bootMemoryCosts } from './boot-memory-cost.ts';
|
|
18
19
|
import { VIEW_DRAWS, viewDraws } from './view-draws.ts';
|
|
19
20
|
import { DEFAULT_GRAPH_BUDGET } from "./materialGraph.ts";
|
|
20
21
|
import { SCRIPT_LIMITS } from './scriptLimits.ts';
|
|
@@ -22,11 +23,17 @@ import { runtimeAccountedBytes } from "./runtimeCost.ts";
|
|
|
22
23
|
import { MemoryAdmission } from './memoryAdmission.ts';
|
|
23
24
|
import { nearPlaceholderRoots } from './nearPlaceholder.ts';
|
|
24
25
|
import type { IssueCodeOf } from './issue-codes.ts';
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/** Actual costs derived from a bounded parser, never trusted from the author declaration. */
|
|
28
26
|
import { isNavigationData, navigationCost } from './navigationBytes.ts';
|
|
29
27
|
|
|
28
|
+
type PerformancePolicy = 'refuse' | 'warn';
|
|
29
|
+
interface PerformanceOptions { readonly policy: PerformancePolicy; readonly sections: ReadonlyMap<string, unknown> }
|
|
30
|
+
|
|
31
|
+
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
|
|
32
|
+
function reportMemory(source: Shardfile, nativeBytes: number, sections: ReadonlyMap<string, unknown>): PerformanceReport['memory'] {
|
|
33
|
+
const commons = nativeBytes + Object.values(source.requires.commonsCosts).reduce((sum, row) => sum + row.decoded + row.gpu, 0);
|
|
34
|
+
const budget = { commons, boot: bootMemoryCosts(source, sections) };
|
|
35
|
+
return { near: nearbyContentCost(source, source.spawn.x, source.spawn.z, budget), worst: worstContentCost(source, budget), playingLimit: C.playing, loadingLimit: C.loading };
|
|
36
|
+
}
|
|
30
37
|
/** A performance issue's code and its metric words. */
|
|
31
38
|
type Named = readonly [code: IssueCodeOf<'performance'>, metric: string];
|
|
32
39
|
|
|
@@ -300,11 +307,10 @@ export function validatePropDrawBounds(source: Shardfile, assets: ReadonlyMap<st
|
|
|
300
307
|
}
|
|
301
308
|
|
|
302
309
|
/** Report deterministic declared bounds and measured native execution; the caller supplies trusted provenance policy. */
|
|
303
|
-
export function performanceReport(source: Shardfile, observations: PerformanceObservations,
|
|
310
|
+
export function performanceReport(source: Shardfile, observations: PerformanceObservations, options: PerformancePolicy | PerformanceOptions = 'refuse'): PerformanceReport {
|
|
311
|
+
const { policy, sections } = typeof options === 'string' ? { policy: options, sections: new Map<string, unknown>() } : options;
|
|
304
312
|
const native = { resident: source.runtime?.cost === undefined ? 0 : runtimeAccountedBytes(source.runtime.cost), evidence: source.runtime?.cost?.evidence ?? null, unmeasuredViewAndDownload: source.runtime !== null };
|
|
305
|
-
const
|
|
306
|
-
const worst = worstContentCost(source, commons), spawn = source.spawn;
|
|
307
|
-
const memory = { near: nearbyContentCost(source, spawn.x, spawn.z, commons), worst, playingLimit: C.playing, loadingLimit: C.loading };
|
|
313
|
+
const memory = reportMemory(source, native.resident, sections), { worst } = memory, spawn = source.spawn;
|
|
308
314
|
const issues: PerformanceIssue[] = memoryTargetWarnings(source).map(row => ({ code: 'perf-memory-target', metric: `${row.category} resident target (tradeable)`, actual: row.bytes, limit: row.target, severity: 'warning' }));
|
|
309
315
|
issues.push(...performanceTargetIssues(source, policy));
|
|
310
316
|
const check = ([code, metric]: Named, actual: number, limit: number): void => {
|
|
@@ -37,7 +37,7 @@ function admitHead(
|
|
|
37
37
|
preflightDeclaredCosts(shard, offlineMemoryAdmission('warn'))
|
|
38
38
|
})
|
|
39
39
|
withIssueCode('performance-targets', (): void => {
|
|
40
|
-
assertShardfileTargets(shard, 'warn')
|
|
40
|
+
assertShardfileTargets(shard, 'warn', payloads)
|
|
41
41
|
})
|
|
42
42
|
return shard
|
|
43
43
|
}
|
|
@@ -21,7 +21,7 @@ import { shardfileRecordings } from './shardfile-audio.ts';
|
|
|
21
21
|
import type { RecordingMeasure } from './audio-measure.ts';
|
|
22
22
|
import { issueError, withIssueCode as coded } from './issue-codes.ts';
|
|
23
23
|
import { staleRuntimeIssues } from './memory-epoch.ts';
|
|
24
|
-
import {
|
|
24
|
+
import { offlineMemoryIssues } from './memory-line.ts';
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* P1-F3 format validation of a built shardfile product (format 2: `shard.json`, sections, blobs, packs): the schema,
|
|
@@ -108,8 +108,8 @@ export function outputBlobExtension(kind: OutputFile['kind'], bytes: Uint8Array)
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/** Refuse the declared targets a policy treats as refusals, before any byte is read or executed. */
|
|
111
|
-
export function assertShardfileTargets(source: Shardfile, policy: 'warn' | 'refuse'): void {
|
|
112
|
-
const issues = [...staleRuntimeIssues(source.runtime), ...
|
|
111
|
+
export function assertShardfileTargets(source: Shardfile, policy: 'warn' | 'refuse', sections: ReadonlyMap<string, unknown> = new Map()): void {
|
|
112
|
+
const issues = [...staleRuntimeIssues(source.runtime), ...offlineMemoryIssues(source, sections), ...performanceTargetIssues(source, policy).filter(issue => issue.severity === 'refusal')];
|
|
113
113
|
if (issues.length === 0) return;
|
|
114
114
|
throw issueError('performance-targets', issues.map(issue => `REFUSAL: ${issue.metric}: ${issue.actual} > ${issue.limit}`).join('\n'));
|
|
115
115
|
}
|
|
@@ -119,7 +119,7 @@ export function admitShardfileFolder(input: unknown, assets: ReadonlyMap<string,
|
|
|
119
119
|
policy: 'warn' | 'refuse' = 'refuse', scripts: ScriptAdmissionRows = [], sections?: ReadonlyMap<string, unknown>): Shardfile {
|
|
120
120
|
const source = coded('shard-schema', (): Shardfile => parseShardfile(input, sections));
|
|
121
121
|
coded('declared-costs', (): void => { preflightDeclaredCosts(source, offlineMemoryAdmission(policy)); });
|
|
122
|
-
coded('performance-targets', (): void => { assertShardfileTargets(source, policy); });
|
|
122
|
+
coded('performance-targets', (): void => { assertShardfileTargets(source, policy, sections); });
|
|
123
123
|
return coded('asset-admission', (): Shardfile => validateShardfileAssets(source, assets, hash, offlineMemoryAdmission(policy), undefined, scripts, sections));
|
|
124
124
|
}
|
|
125
125
|
|
package/src/format/skinData.ts
CHANGED
|
@@ -11,10 +11,11 @@ export const SkinClipNameSchema: v.GenericSchema<SkinClipNameRowsInput, SkinClip
|
|
|
11
11
|
const joint = v.pipe(v.string(), v.regex(/^[A-Za-z][A-Za-z0-9_.-]*$/u), v.maxLength(64));
|
|
12
12
|
const bytes = v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(25_000_000));
|
|
13
13
|
|
|
14
|
-
/** One exported skin
|
|
14
|
+
/** One exported skin: the GLB hash and rig. Clips may be empty for a poser-driven
|
|
15
|
+
* rig; loop bindings must still name a declared clip. */
|
|
15
16
|
export const SkinRowSchema: v.GenericSchema<SkinRowInput, SkinRow> = v.object({
|
|
16
17
|
id, file: hash, family: v.picklist(['toon', 'pbr']),
|
|
17
|
-
rig: v.strictObject({ skeleton: v.pipe(v.string(), v.regex(/^[a-z][A-Za-z0-9.]*$/u), v.maxLength(128)), joints: v.pipe(v.array(v.pipe(v.array(joint), v.minLength(1), v.maxLength(128))), v.length(1)), clips: v.pipe(v.array(SkinClipNameSchema), v.
|
|
18
|
+
rig: v.strictObject({ skeleton: v.pipe(v.string(), v.regex(/^[a-z][A-Za-z0-9.]*$/u), v.maxLength(128)), joints: v.pipe(v.array(v.pipe(v.array(joint), v.minLength(1), v.maxLength(128))), v.length(1)), clips: v.pipe(v.array(SkinClipNameSchema), v.maxLength(32)), sockets: v.pipe(v.array(joint), v.maxLength(32)) }),
|
|
18
19
|
cost: v.strictObject({ decoded: bytes, gpu: bytes, triangles: v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(400_000)), draws: v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(512)) }),
|
|
19
20
|
});
|
|
20
21
|
/** A validated exported skin row. */
|