ugly-game 0.15.27 → 0.15.28

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.
@@ -129,6 +129,17 @@ export interface AtlasLayout {
129
129
  * wrapping to an unrelated texture.
130
130
  */
131
131
  export declare function packFaceMats(m: readonly number[]): [number, number];
132
+ /**
133
+ * Bytes one instance occupies in the instance storage buffer.
134
+ *
135
+ * EXPORTED BECAUSE THE CALLER HAS TO SIZE `requiredLimits` WITH IT. A device built by a plain
136
+ * `requestDevice()` gets WebGPU's DEFAULT limits — 256 MiB `maxBufferSize`, 128 MiB
137
+ * `maxStorageBufferBindingSize` — no matter what the adapter advertises, so a consumer that wants a
138
+ * capacity past ~1.67 M instances must request the higher limit at device creation or the allocation
139
+ * is rejected. Working that out requires this number, and a caller that hardcodes 80 is one struct
140
+ * change away from being quietly wrong.
141
+ */
142
+ export declare const INSTANCE_BYTES: number;
132
143
  /**
133
144
  * One rigid transform over a contiguous run of instances — see `GpuShadowRenderer.setBodyTransforms`.
134
145
  * `first`/`count` are INSTANCE SLOTS in the buffer, matching what `updateInstanceRange` wrote.
@@ -754,7 +765,20 @@ export declare class GpuShadowRenderer {
754
765
  setAtlas(tex: GPUTexture, layout: AtlasLayout): void;
755
766
  /** Static scene: sizes the buffer to exactly these instances. */
756
767
  setScene(instances: CubeInstance[]): void;
757
- /** Dynamic scene: pre-allocate for `cap` instances; call updateInstances() each frame. */
768
+ /**
769
+ * Dynamic scene: pre-allocate for `cap` instances; call updateInstances() each frame.
770
+ *
771
+ * ⚠️ THIS THROWS RATHER THAN LETTING THE DEVICE REJECT THE BUFFER, because the rejection is
772
+ * COMPLETELY SILENT and costs days. `createBuffer` past a device limit does not throw — it returns
773
+ * an INVALID buffer, and the failure only surfaces as `[Invalid Buffer] is invalid due to a
774
+ * previous error` on an `onuncapturederror` handler that most apps never install. Every bind group
775
+ * built from it is invalid, every pass using them is a no-op, and the symptom is a black frame with
776
+ * correct geometry, a full instance buffer, and zero visible instances in EVERY frustum at once.
777
+ * That is indistinguishable by inspection from a cull bug, a camera bug, or a matrix bug, and it
778
+ * was mistaken for all three before anyone thought to compare `device.limits` against the size.
779
+ *
780
+ * The limits are checkable up front and the message names the fix, so it is checked up front.
781
+ */
758
782
  setCapacity(cap: number): void;
759
783
  updateInstances(instances: CubeInstance[]): void;
760
784
  /**
package/dist/gpuShadow.js CHANGED
@@ -59,6 +59,17 @@ export function packFaceMats(m) {
59
59
  // anyway. Spending the other two on a spare slot is free, and the last time this buffer grew it was
60
60
  // for the contact decal, which had to widen it for exactly the same reason.
61
61
  const INST_F = 20;
62
+ /**
63
+ * Bytes one instance occupies in the instance storage buffer.
64
+ *
65
+ * EXPORTED BECAUSE THE CALLER HAS TO SIZE `requiredLimits` WITH IT. A device built by a plain
66
+ * `requestDevice()` gets WebGPU's DEFAULT limits — 256 MiB `maxBufferSize`, 128 MiB
67
+ * `maxStorageBufferBindingSize` — no matter what the adapter advertises, so a consumer that wants a
68
+ * capacity past ~1.67 M instances must request the higher limit at device creation or the allocation
69
+ * is rejected. Working that out requires this number, and a caller that hardcodes 80 is one struct
70
+ * change away from being quietly wrong.
71
+ */
72
+ export const INSTANCE_BYTES = INST_F * 4;
62
73
  const OVERLAY_CAP = 512; // max translucent overlay cubes per frame (the place ghost + headroom)
63
74
  /** Rigid-body table: `bodies[0]` is the header, so this is bodies + 1. See `struct Body` in the WGSL. */
64
75
  export const MAX_BODIES = 32;
@@ -3606,8 +3617,30 @@ export class GpuShadowRenderer {
3606
3617
  this.device.queue.writeBuffer(this.instBuf, 0, this.scratch);
3607
3618
  this.makeBindGroups();
3608
3619
  }
3609
- /** Dynamic scene: pre-allocate for `cap` instances; call updateInstances() each frame. */
3620
+ /**
3621
+ * Dynamic scene: pre-allocate for `cap` instances; call updateInstances() each frame.
3622
+ *
3623
+ * ⚠️ THIS THROWS RATHER THAN LETTING THE DEVICE REJECT THE BUFFER, because the rejection is
3624
+ * COMPLETELY SILENT and costs days. `createBuffer` past a device limit does not throw — it returns
3625
+ * an INVALID buffer, and the failure only surfaces as `[Invalid Buffer] is invalid due to a
3626
+ * previous error` on an `onuncapturederror` handler that most apps never install. Every bind group
3627
+ * built from it is invalid, every pass using them is a no-op, and the symptom is a black frame with
3628
+ * correct geometry, a full instance buffer, and zero visible instances in EVERY frustum at once.
3629
+ * That is indistinguishable by inspection from a cull bug, a camera bug, or a matrix bug, and it
3630
+ * was mistaken for all three before anyone thought to compare `device.limits` against the size.
3631
+ *
3632
+ * The limits are checkable up front and the message names the fix, so it is checked up front.
3633
+ */
3610
3634
  setCapacity(cap) {
3635
+ const need = Math.max(INST_F * 4, cap * INST_F * 4);
3636
+ const lim = this.device.limits;
3637
+ if (need > lim.maxBufferSize || need > lim.maxStorageBufferBindingSize)
3638
+ throw new Error(`GpuShadowRenderer.setCapacity(${cap}): the instance buffer needs ${(need / 1048576).toFixed(1)} MiB, ` +
3639
+ `past this device's maxBufferSize ${(lim.maxBufferSize / 1048576).toFixed(1)} MiB / ` +
3640
+ `maxStorageBufferBindingSize ${(lim.maxStorageBufferBindingSize / 1048576).toFixed(1)} MiB. ` +
3641
+ `A plain requestDevice() grants WebGPU's DEFAULT limits regardless of what the adapter supports — ` +
3642
+ `pass requiredLimits: { maxBufferSize, maxStorageBufferBindingSize } at device creation, ` +
3643
+ `clamped to adapter.limits, or lower the capacity.`);
3611
3644
  this.cap = cap;
3612
3645
  this.scratch = new Float32Array(cap * INST_F);
3613
3646
  this.sceneReady = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.27",
3
+ "version": "0.15.28",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {