ugly-game 0.15.28 → 0.15.30

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.
@@ -9,6 +9,18 @@ export interface CubeInstance {
9
9
  hue: number;
10
10
  emissive?: number;
11
11
  rot?: [number, number, number, number];
12
+ /**
13
+ * WHICH FACES TO DRAW: bit d, in FACE_DIRS order (+X −X +Y −Y +Z −Z). See FACE_MASK_ALL.
14
+ *
15
+ * ⚠️ 0 IS "UNKNOWN ⇒ DRAW ALL SIX", NOT "DRAW NOTHING" — the same sentinel `occ` uses, and what
16
+ * makes this safe to adopt one producer at a time. "Draw nothing" never needs expressing: a cube
17
+ * with no visible face is dropped by the mesher and never reaches the buffer.
18
+ *
19
+ * ⚠️ NOT A SUBSTITUTE FOR `occ`, WHICH IS STILL REQUIRED IN FULL. `occ` is 27-bit OCCUPANCY and
20
+ * vertex AO reads its DIAGONALS; this is only the six axial answers culling needs, shipped rather
21
+ * than re-derived per vertex. Ignored in faceMats/patchwork mode, where the slots carry materials.
22
+ */
23
+ faceMask?: number;
12
24
  /**
13
25
  * ATLAS TILE ID, or a sentinel.
14
26
  *
@@ -140,6 +152,46 @@ export declare function packFaceMats(m: readonly number[]): [number, number];
140
152
  * change away from being quietly wrong.
141
153
  */
142
154
  export declare const INSTANCE_BYTES: number;
155
+ /** Floats per instance record. Pairs with INSTANCE_OFF for writing records directly. */
156
+ export declare const INSTANCE_FLOATS = 20;
157
+ /**
158
+ * THE INSTANCE RECORD'S FIELD OFFSETS, so a producer can write the GPU layout DIRECTLY.
159
+ *
160
+ * ⚠️ THIS EXISTS TO DELETE A PER-INSTANCE JAVASCRIPT OBJECT FROM THE HOT PATH. The object route is
161
+ * `updateInstanceRange(CubeInstance[])`, which is convenient and costs two heap allocations plus
162
+ * ~15 property reads for every instance, on the main thread, every time anything changes. Measured
163
+ * in all-mine-sky: 149 ms of allocation for a full draw set, then ~0.1 µs an instance to read the
164
+ * objects back and pack them — together the whole of a 445 ms frame at N=512.
165
+ *
166
+ * A mesher that already walks its cells can write these twenty floats as it goes and hand over bytes
167
+ * the GPU can take verbatim. See `updateInstanceRaw`.
168
+ *
169
+ * ⚠️ SLOTS 16 AND 17 ARE OVERLOADED, and which reading applies is decided by `tile`:
170
+ * tile >= 0 or -1 occupancy — 16 is occ's low 14 bits, 17 its high 13 PLUS the face mask above them
171
+ * tile == -2 six FACE MATERIALS, three per slot (see packFaceMats)
172
+ * tile == -3 PATCHWORK — 16 is the table offset, 17 the texels per face edge
173
+ * Writing the wrong pair for the tile sentinel is silent: the shader reads whichever the sentinel
174
+ * says, so an occupancy written under -2 becomes six material ids and the cube retextures itself.
175
+ */
176
+ export declare const INSTANCE_OFF: {
177
+ readonly x: 0;
178
+ readonly y: 1;
179
+ readonly z: 2;
180
+ readonly hue: 3;
181
+ readonly sx: 4;
182
+ readonly sy: 5;
183
+ readonly sz: 6;
184
+ readonly emissive: 7;
185
+ readonly rot: 8;
186
+ readonly tile: 12;
187
+ readonly up: 13;
188
+ readonly decalPos: 14;
189
+ readonly decalKind: 15;
190
+ readonly aux0: 16;
191
+ readonly aux1: 17;
192
+ readonly jitter: 18;
193
+ readonly texFit: 19;
194
+ };
143
195
  /**
144
196
  * One rigid transform over a contiguous run of instances — see `GpuShadowRenderer.setBodyTransforms`.
145
197
  * `first`/`count` are INSTANCE SLOTS in the buffer, matching what `updateInstanceRange` wrote.
@@ -489,10 +541,33 @@ BEVEL_SEG?: number): number;
489
541
  * is set rather than silently producing holes.
490
542
  */
491
543
  export declare const FACE_DIRS: readonly (readonly [number, number, number])[];
492
- /** Is face `d` open to air? A SET bit means the neighbour is SOLID — see occAt. */
493
- export declare function faceExposed(mask: number, d: number): boolean;
494
- /** How many faces this instance actually has to draw. mask 0 is the "unknown" sentinel ⇒ all six. */
495
- export declare function exposedFaceCount(mask: number): number;
544
+ /**
545
+ * THE FACE MASK: BIT d MEANS "DRAW FACE d". Six bits, in FACE_DIRS order.
546
+ *
547
+ * ⚠️ THIS IS NOT `occ`, AND THE TWO MUST NOT BE CONFLATED. `occ` is a 27-bit OCCUPANCY mask — a set
548
+ * bit is a SOLID neighbour — and it is still required in full, because vertex AO reads the DIAGONAL
549
+ * neighbours (`cornerAOAt` samples n+a1, n+a2 and n+a1+a2) and the bevel shapes edges from the same
550
+ * neighbourhood. Face culling needs only the six axial answers, and the producer already knows them:
551
+ * deriving them again per vertex in the shader meant a six-iteration loop calling `occAt`, which
552
+ * recomputes a 3D neighbour index every time, in the hottest shader in the engine.
553
+ *
554
+ * So the mesher ships what it already computed. `occ` keeps its 27 bits for AO and bevel; this
555
+ * carries the six that culling needs.
556
+ *
557
+ * ⚠️ ZERO IS "UNKNOWN ⇒ DRAW ALL SIX", NOT "DRAW NOTHING", which is the same sentinel `occ` uses.
558
+ * That is what makes the change safe to land incrementally: a producer that has not been taught to
559
+ * fill this in writes 0 and keeps its whole cube, rather than silently vanishing. "Draw nothing"
560
+ * never needs expressing — a cube with no visible face is dropped by the mesher and never reaches
561
+ * the buffer at all.
562
+ */
563
+ export declare const FACE_MASK_ALL = 63;
564
+ /** Is face `d` drawn? Bit d set ⇒ yes. 0 is the unknown sentinel ⇒ every face. */
565
+ export declare function faceExposed(faceMask: number, d: number): boolean;
566
+ /** How many faces this instance actually has to draw. 0 is the "unknown" sentinel ⇒ all six. */
567
+ export declare function exposedFaceCount(faceMask: number): number;
568
+ /** The six axial bits of a 27-bit occupancy mask, inverted into a face mask. For producers that
569
+ * already hold an `occ` — a solid neighbour hides its face. */
570
+ export declare function faceMaskFromOcc(occ: number): number;
496
571
  /**
497
572
  * Vertex counts for the three face-cull buckets, and the classifier that picks one.
498
573
  *
@@ -505,7 +580,7 @@ export declare function exposedFaceCount(mask: number): number;
505
580
  * making as cheap as it can be — a 6x cut for the common case.
506
581
  */
507
582
  export declare const FACE_CULL_BUCKET_VERTS: readonly number[];
508
- export declare function faceCullClass(mask: number): number;
583
+ export declare function faceCullClass(faceMask: number): number;
509
584
  export declare function bevelVertex(corner: readonly [number, number, number], home: readonly [number, number, number], mask: number, bevel: number, role?: number, axis?: readonly [number, number, number],
510
585
  /** The CONCAVE radius. Separate from `bevel` (the convex one) so the two halves of the rounding
511
586
  * can be turned up, down and off independently — the only way to tell which one a defect is in.
@@ -806,6 +881,23 @@ export declare class GpuShadowRenderer {
806
881
  * Out-of-range and empty writes are no-ops rather than errors: a caller assembling a frame should not
807
882
  * have to special-case "this segment happens to be empty right now".
808
883
  */
884
+ /**
885
+ * WRITE ALREADY-PACKED RECORDS AT SLOT `first` — no objects, no repack, no scratch.
886
+ *
887
+ * `src` must be in this engine's layout (INSTANCE_FLOATS floats each, INSTANCE_OFF for the
888
+ * fields). The bytes go straight to the GPU: there is no per-instance JavaScript on this path at
889
+ * all, which is the entire point. A worker that already walks its cells can produce this directly
890
+ * and the main thread never touches an instance again.
891
+ *
892
+ * Partial by construction — write one entry's range without disturbing its neighbours, the same
893
+ * contract `updateInstanceRange` offers and the reason a mostly-static scene need not re-upload.
894
+ *
895
+ * ⚠️ IT BYPASSES THE CPU MIRROR, WHICH IS SAFE ONLY BECAUSE NOTHING READS PAST WHAT IT WROTE.
896
+ * `scratch` is filled and then uploaded over the same range by every other path, so it is never
897
+ * read beyond the range just written. Do not add a reader that assumes `scratch` mirrors the
898
+ * whole buffer, or ranges written through here will be silently stale to it.
899
+ */
900
+ updateInstanceRaw(src: Float32Array<ArrayBuffer>, first: number): void;
809
901
  updateInstanceRange(instances: CubeInstance[], first: number): void;
810
902
  /** How many instances the cull + draw passes consider, whatever is in the buffer past that. Pairs with
811
903
  * `updateInstanceRange`: shrinking the dynamic tail is a count change, not an upload. */
package/dist/gpuShadow.js CHANGED
@@ -70,6 +70,46 @@ const INST_F = 20;
70
70
  * change away from being quietly wrong.
71
71
  */
72
72
  export const INSTANCE_BYTES = INST_F * 4;
73
+ /** Floats per instance record. Pairs with INSTANCE_OFF for writing records directly. */
74
+ export const INSTANCE_FLOATS = INST_F;
75
+ /**
76
+ * THE INSTANCE RECORD'S FIELD OFFSETS, so a producer can write the GPU layout DIRECTLY.
77
+ *
78
+ * ⚠️ THIS EXISTS TO DELETE A PER-INSTANCE JAVASCRIPT OBJECT FROM THE HOT PATH. The object route is
79
+ * `updateInstanceRange(CubeInstance[])`, which is convenient and costs two heap allocations plus
80
+ * ~15 property reads for every instance, on the main thread, every time anything changes. Measured
81
+ * in all-mine-sky: 149 ms of allocation for a full draw set, then ~0.1 µs an instance to read the
82
+ * objects back and pack them — together the whole of a 445 ms frame at N=512.
83
+ *
84
+ * A mesher that already walks its cells can write these twenty floats as it goes and hand over bytes
85
+ * the GPU can take verbatim. See `updateInstanceRaw`.
86
+ *
87
+ * ⚠️ SLOTS 16 AND 17 ARE OVERLOADED, and which reading applies is decided by `tile`:
88
+ * tile >= 0 or -1 occupancy — 16 is occ's low 14 bits, 17 its high 13 PLUS the face mask above them
89
+ * tile == -2 six FACE MATERIALS, three per slot (see packFaceMats)
90
+ * tile == -3 PATCHWORK — 16 is the table offset, 17 the texels per face edge
91
+ * Writing the wrong pair for the tile sentinel is silent: the shader reads whichever the sentinel
92
+ * says, so an occupancy written under -2 becomes six material ids and the cube retextures itself.
93
+ */
94
+ export const INSTANCE_OFF = {
95
+ x: 0,
96
+ y: 1,
97
+ z: 2,
98
+ hue: 3,
99
+ sx: 4,
100
+ sy: 5,
101
+ sz: 6,
102
+ emissive: 7,
103
+ rot: 8, // 8..11, xyzw; identity is (0,0,0,1)
104
+ tile: 12,
105
+ up: 13,
106
+ decalPos: 14,
107
+ decalKind: 15,
108
+ aux0: 16, // occ low 14 | faceMats[0] | patch.at
109
+ aux1: 17, // occ high 13 + faceMask<<13 | faceMats[1] | patch.res
110
+ jitter: 18,
111
+ texFit: 19,
112
+ };
73
113
  const OVERLAY_CAP = 512; // max translucent overlay cubes per frame (the place ghost + headroom)
74
114
  /** Rigid-body table: `bodies[0]` is the header, so this is bodies + 1. See `struct Body` in the WGSL. */
75
115
  export const MAX_BODIES = 32;
@@ -1052,22 +1092,54 @@ export const FACE_DIRS = [
1052
1092
  [0, 0, 1],
1053
1093
  [0, 0, -1],
1054
1094
  ];
1055
- /** Is face `d` open to air? A SET bit means the neighbour is SOLID — see occAt. */
1056
- export function faceExposed(mask, d) {
1057
- const o = FACE_DIRS[d];
1058
- const idx = o[0] + 1 + (o[1] + 1) * 3 + (o[2] + 1) * 9;
1059
- return ((mask >>> idx) & 1) === 0;
1095
+ /**
1096
+ * THE FACE MASK: BIT d MEANS "DRAW FACE d". Six bits, in FACE_DIRS order.
1097
+ *
1098
+ * ⚠️ THIS IS NOT `occ`, AND THE TWO MUST NOT BE CONFLATED. `occ` is a 27-bit OCCUPANCY mask — a set
1099
+ * bit is a SOLID neighbour — and it is still required in full, because vertex AO reads the DIAGONAL
1100
+ * neighbours (`cornerAOAt` samples n+a1, n+a2 and n+a1+a2) and the bevel shapes edges from the same
1101
+ * neighbourhood. Face culling needs only the six axial answers, and the producer already knows them:
1102
+ * deriving them again per vertex in the shader meant a six-iteration loop calling `occAt`, which
1103
+ * recomputes a 3D neighbour index every time, in the hottest shader in the engine.
1104
+ *
1105
+ * So the mesher ships what it already computed. `occ` keeps its 27 bits for AO and bevel; this
1106
+ * carries the six that culling needs.
1107
+ *
1108
+ * ⚠️ ZERO IS "UNKNOWN ⇒ DRAW ALL SIX", NOT "DRAW NOTHING", which is the same sentinel `occ` uses.
1109
+ * That is what makes the change safe to land incrementally: a producer that has not been taught to
1110
+ * fill this in writes 0 and keeps its whole cube, rather than silently vanishing. "Draw nothing"
1111
+ * never needs expressing — a cube with no visible face is dropped by the mesher and never reaches
1112
+ * the buffer at all.
1113
+ */
1114
+ export const FACE_MASK_ALL = 0b111111;
1115
+ /** Is face `d` drawn? Bit d set ⇒ yes. 0 is the unknown sentinel ⇒ every face. */
1116
+ export function faceExposed(faceMask, d) {
1117
+ return faceMask === 0 || ((faceMask >>> d) & 1) === 1;
1060
1118
  }
1061
- /** How many faces this instance actually has to draw. mask 0 is the "unknown" sentinel ⇒ all six. */
1062
- export function exposedFaceCount(mask) {
1063
- if (mask === 0)
1119
+ /** How many faces this instance actually has to draw. 0 is the "unknown" sentinel ⇒ all six. */
1120
+ export function exposedFaceCount(faceMask) {
1121
+ if (faceMask === 0)
1064
1122
  return 6;
1065
1123
  let n = 0;
1066
1124
  for (let d = 0; d < 6; d++)
1067
- if (faceExposed(mask, d))
1125
+ if ((faceMask >>> d) & 1)
1068
1126
  n++;
1069
1127
  return n;
1070
1128
  }
1129
+ /** The six axial bits of a 27-bit occupancy mask, inverted into a face mask. For producers that
1130
+ * already hold an `occ` — a solid neighbour hides its face. */
1131
+ export function faceMaskFromOcc(occ) {
1132
+ if (occ === 0)
1133
+ return 0; // unknown stays unknown
1134
+ let m = 0;
1135
+ for (let d = 0; d < 6; d++) {
1136
+ const o = FACE_DIRS[d];
1137
+ const idx = o[0] + 1 + (o[1] + 1) * 3 + (o[2] + 1) * 9;
1138
+ if (((occ >>> idx) & 1) === 0)
1139
+ m |= 1 << d;
1140
+ }
1141
+ return m;
1142
+ }
1071
1143
  /**
1072
1144
  * Vertex counts for the three face-cull buckets, and the classifier that picks one.
1073
1145
  *
@@ -1080,8 +1152,8 @@ export function exposedFaceCount(mask) {
1080
1152
  * making as cheap as it can be — a 6x cut for the common case.
1081
1153
  */
1082
1154
  export const FACE_CULL_BUCKET_VERTS = [6, 18, 36];
1083
- export function faceCullClass(mask) {
1084
- const n = exposedFaceCount(mask);
1155
+ export function faceCullClass(faceMask) {
1156
+ const n = exposedFaceCount(faceMask);
1085
1157
  return n <= 1 ? 6 : n <= 3 ? 18 : 36;
1086
1158
  }
1087
1159
  // THE RIM TURN IS GONE, AND ITS ABSENCE IS THE POINT. rimTurn() clipped a face's corner and grew a
@@ -1587,29 +1659,27 @@ fn occAt(mask: u32, o: vec3<f32>) -> f32 {
1587
1659
  // ── FACE CULLING ────────────────────────────────────────────────────────────────────────────────
1588
1660
  // Mirrors faceExposed / exposedFaceCount / faceCullRemap in TS — ONE source, spliced into both the
1589
1661
  // draw and cull shaders, so there is no third copy. See the FACE CULLING block above buildCube.
1590
- const FACE_N = array<vec3<f32>, 6>(
1591
- vec3(1.0, 0.0, 0.0), vec3(-1.0, 0.0, 0.0),
1592
- vec3(0.0, 1.0, 0.0), vec3(0.0, -1.0, 0.0),
1593
- vec3(0.0, 0.0, 1.0), vec3(0.0, 0.0, -1.0),
1594
- );
1595
- fn faceExposedW(mask: u32, d: u32) -> bool {
1596
- return occAt(mask, FACE_N[d]) < 0.5; // a SET bit is a SOLID neighbour
1662
+ // ⚠️ THESE TAKE THE FACE MASK, NOT occ. Bit d means "draw face d". The mesher already computed the
1663
+ // six axial answers, so the shader no longer re-derives them from the 27-bit occupancy mask: that
1664
+ // cost a six-iteration loop calling occAt — which recomputes a 3D neighbour index per iteration —
1665
+ // for every vertex of every instance. occ is still needed in FULL for AO (cornerAOAt reads the
1666
+ // diagonals) and the bevel; it is simply not what culling asks.
1667
+ fn faceExposedW(fm: u32, d: u32) -> bool {
1668
+ return fm == 0u || ((fm >> d) & 1u) == 1u; // 0 = unknown, draw everything
1597
1669
  }
1598
- fn exposedFaceCountW(mask: u32) -> u32 {
1599
- if (mask == 0u) { return 6u; } // unknown ⇒ draw everything, same sentinel as the bevel
1600
- var n = 0u;
1601
- for (var d = 0u; d < 6u; d = d + 1u) { if (faceExposedW(mask, d)) { n = n + 1u; } }
1602
- return n;
1670
+ fn exposedFaceCountW(fm: u32) -> u32 {
1671
+ if (fm == 0u) { return 6u; } // unknown ⇒ draw everything, same sentinel as the bevel
1672
+ return countOneBits(fm & 63u);
1603
1673
  }
1604
1674
  // Rewrite a sharp-cube vertex index onto the (vi / 6)-th EXPOSED face, keeping its corner. Returns
1605
1675
  // 0xffffffff when this slot has no face left — the draw's bucket is sized for the WORST instance in
1606
1676
  // it, so most instances have slots to spare and the vertex shader collapses those to a point.
1607
- fn faceCullRemap(mask: u32, vi: u32) -> u32 {
1677
+ fn faceCullRemap(fm: u32, vi: u32) -> u32 {
1608
1678
  let slot = vi / 6u;
1609
1679
  let corner = vi % 6u;
1610
1680
  var seen = 0u;
1611
1681
  for (var d = 0u; d < 6u; d = d + 1u) {
1612
- if (faceExposedW(mask, d)) {
1682
+ if (faceExposedW(fm, d)) {
1613
1683
  if (seen == slot) { return d * 6u + corner; }
1614
1684
  seen = seen + 1u;
1615
1685
  }
@@ -2200,9 +2270,11 @@ fn cull(@builtin(global_invocation_id) gid: vec3<u32>) {
2200
2270
  // faceCull.test.mts are what hold that, one per mode.
2201
2271
  var b = 0u;
2202
2272
  if (cc.lod.y > 0.5) {
2203
- let mask = select(u32(inst.aux2.x) | (u32(inst.aux2.y) << 14u), 0u, inst.aux.x < -1.5);
2273
+ let raw2 = select(u32(inst.aux2.y), 0u, inst.aux.x < -1.5);
2274
+ let mask = select(u32(inst.aux2.x) | ((raw2 & 8191u) << 14u), 0u, inst.aux.x < -1.5);
2275
+ let fmask = raw2 >> 13u; // the six face bits riding above occ's high 13
2204
2276
  if (cc.lod.y > 1.5) {
2205
- let n = exposedFaceCountW(mask);
2277
+ let n = exposedFaceCountW(fmask);
2206
2278
  if (n > 3u) { b = 2u; } else if (n > 1u) { b = 1u; }
2207
2279
  } else {
2208
2280
  let cls = bevelClass(mask, cc.lod.z, cc.lod.w);
@@ -2310,7 +2382,10 @@ fn faceVec(code: f32) -> vec3<f32> {
2310
2382
  // TS template literal, so one ends the shader mid-string and the error surfaces as a TS parse failure
2311
2383
  // dozens of lines later.
2312
2384
  let isPatch = inst.aux.x < -1.5;
2313
- let mask = select(u32(inst.aux2.x) | (u32(inst.aux2.y) << 14u), 0u, isPatch);
2385
+ let raw2 = select(u32(inst.aux2.y), 0u, isPatch);
2386
+ let mask = select(u32(inst.aux2.x) | ((raw2 & 8191u) << 14u), 0u, isPatch);
2387
+ // The six face bits the mesher already computed, riding above occ's high 13. 0 = unknown ⇒ all six.
2388
+ let fmask = raw2 >> 13u;
2314
2389
  // THE BEVELED CUBE. cam.eye.w is the bevel amount; at 0 — every caller that has not opted in —
2315
2390
  // bevelPos returns the sharp corner and this is buildCube()'s geometry exactly. The draw is only
2316
2391
  // 36 vertices long in that case anyway (see the indirect args), so the tail is never even reached.
@@ -2326,7 +2401,7 @@ fn faceVec(code: f32) -> vec3<f32> {
2326
2401
  var vv = vi;
2327
2402
  var faceless = false; // this slot has no exposed face left → collapse it below
2328
2403
  if (cam.csm.w > 0.5 && cam.eye.w <= 0.0 && cam.csm.z <= 0.0 && mask != 0u) {
2329
- let r = faceCullRemap(mask, vi);
2404
+ let r = faceCullRemap(fmask, vi);
2330
2405
  if (r == 0xffffffffu) { faceless = true; } else { vv = r; }
2331
2406
  }
2332
2407
  let sharp = BEV_CORNER[vv];
@@ -3445,7 +3520,19 @@ export class GpuShadowRenderer {
3445
3520
  const pt = c.tile === -3 ? c.patch : undefined;
3446
3521
  const occ = c.occ ?? 0;
3447
3522
  scratch[o + 16] = pt ? pt.at : fm ? fm[0] : occ & 0x3fff;
3448
- scratch[o + 17] = pt ? pt.res : fm ? fm[1] : (occ / 0x4000) | 0;
3523
+ // ⚠️ THE FACE MASK RIDES ABOVE occ's HIGH 13 BITS, IN THE SAME FLOAT, AT NO WIRE COST. occ is
3524
+ // 27 bits split 14/13, so slot 17 carries values under 2^13 and an f32 holds integers exactly
3525
+ // to 2^24 — six more bits fit with room to spare (8192·64 = 524 288). The face mask could not
3526
+ // simply REPLACE occ: vertex AO reads the DIAGONAL neighbours (cornerAOAt samples n+a1+a2) and
3527
+ // the bevel shapes edges from the same neighbourhood, so all 27 bits are still required.
3528
+ //
3529
+ // Never in patchwork or face-material mode — there slots 16/17 are SIX MATERIAL IDS and the
3530
+ // shader already forces the mask to the 0 "unknown" sentinel.
3531
+ scratch[o + 17] = pt
3532
+ ? pt.res
3533
+ : fm
3534
+ ? fm[1]
3535
+ : ((occ / 0x4000) | 0) + (c.faceMask ?? 0) * 0x2000;
3449
3536
  scratch[o + 18] = c.jitter ?? 0;
3450
3537
  scratch[o + 19] = c.texFit ?? 0; // texFit: one atlas tile per face at any draw scale (see CubeInstance.texFit)
3451
3538
  }
@@ -3685,6 +3772,33 @@ export class GpuShadowRenderer {
3685
3772
  * Out-of-range and empty writes are no-ops rather than errors: a caller assembling a frame should not
3686
3773
  * have to special-case "this segment happens to be empty right now".
3687
3774
  */
3775
+ /**
3776
+ * WRITE ALREADY-PACKED RECORDS AT SLOT `first` — no objects, no repack, no scratch.
3777
+ *
3778
+ * `src` must be in this engine's layout (INSTANCE_FLOATS floats each, INSTANCE_OFF for the
3779
+ * fields). The bytes go straight to the GPU: there is no per-instance JavaScript on this path at
3780
+ * all, which is the entire point. A worker that already walks its cells can produce this directly
3781
+ * and the main thread never touches an instance again.
3782
+ *
3783
+ * Partial by construction — write one entry's range without disturbing its neighbours, the same
3784
+ * contract `updateInstanceRange` offers and the reason a mostly-static scene need not re-upload.
3785
+ *
3786
+ * ⚠️ IT BYPASSES THE CPU MIRROR, WHICH IS SAFE ONLY BECAUSE NOTHING READS PAST WHAT IT WROTE.
3787
+ * `scratch` is filled and then uploaded over the same range by every other path, so it is never
3788
+ * read beyond the range just written. Do not add a reader that assumes `scratch` mirrors the
3789
+ * whole buffer, or ranges written through here will be silently stale to it.
3790
+ */
3791
+ updateInstanceRaw(src, first) {
3792
+ const capN = (this.scratch.length / INST_F) | 0;
3793
+ if (first < 0 || first >= capN)
3794
+ return;
3795
+ const n = Math.min((src.length / INST_F) | 0, capN - first);
3796
+ if (n <= 0)
3797
+ return;
3798
+ this.device.queue.writeBuffer(this.instBuf, first * INST_F * 4, src, 0, n * INST_F);
3799
+ if (first + n > this.count)
3800
+ this.count = first + n;
3801
+ }
3688
3802
  updateInstanceRange(instances, first) {
3689
3803
  const capN = (this.scratch.length / INST_F) | 0;
3690
3804
  if (first < 0 || first >= capN)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.28",
3
+ "version": "0.15.30",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {