ugly-game 0.15.29 → 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.
- package/dist/gpuShadow.d.ts +57 -0
- package/dist/gpuShadow.js +67 -0
- package/package.json +1 -1
package/dist/gpuShadow.d.ts
CHANGED
|
@@ -152,6 +152,46 @@ export declare function packFaceMats(m: readonly number[]): [number, number];
|
|
|
152
152
|
* change away from being quietly wrong.
|
|
153
153
|
*/
|
|
154
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
|
+
};
|
|
155
195
|
/**
|
|
156
196
|
* One rigid transform over a contiguous run of instances — see `GpuShadowRenderer.setBodyTransforms`.
|
|
157
197
|
* `first`/`count` are INSTANCE SLOTS in the buffer, matching what `updateInstanceRange` wrote.
|
|
@@ -841,6 +881,23 @@ export declare class GpuShadowRenderer {
|
|
|
841
881
|
* Out-of-range and empty writes are no-ops rather than errors: a caller assembling a frame should not
|
|
842
882
|
* have to special-case "this segment happens to be empty right now".
|
|
843
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;
|
|
844
901
|
updateInstanceRange(instances: CubeInstance[], first: number): void;
|
|
845
902
|
/** How many instances the cull + draw passes consider, whatever is in the buffer past that. Pairs with
|
|
846
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;
|
|
@@ -3732,6 +3772,33 @@ export class GpuShadowRenderer {
|
|
|
3732
3772
|
* Out-of-range and empty writes are no-ops rather than errors: a caller assembling a frame should not
|
|
3733
3773
|
* have to special-case "this segment happens to be empty right now".
|
|
3734
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
|
+
}
|
|
3735
3802
|
updateInstanceRange(instances, first) {
|
|
3736
3803
|
const capN = (this.scratch.length / INST_F) | 0;
|
|
3737
3804
|
if (first < 0 || first >= capN)
|