pngine 4.3.1 → 4.3.2
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 +26 -6
- package/dist/core.d.ts +54 -0
- package/dist/core.mjs +4 -4
- package/dist/dev.d.ts +115 -0
- package/dist/dev.mjs +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.mjs +2 -0
- package/dist/viewer.d.ts +115 -0
- package/dist/viewer.mjs +1 -1
- package/package.json +7 -7
- package/schema/pngine.sjon +276 -31
- package/src/anim.js +252 -8
- package/src/core.js +47 -0
- package/src/descriptor-decode.js +13 -7
- package/src/dev.js +1 -1
- package/src/enums.js +56 -0
- package/src/gpu-host-texture.js +395 -0
- package/src/gpu-queue-commands.js +462 -4
- package/src/gpu-resource-pass-commands.js +58 -2
- package/src/gpu.js +224 -26
- package/src/init-core.js +21 -0
- package/src/init.js +4 -0
- package/src/texture-layout.js +1893 -0
- package/src/viewer-init.js +4 -0
- package/src/viewer.js +1 -1
- package/src/worker-core.js +48 -9
- package/wasm/pngine-compiler.wasm +0 -0
- package/wasm/pngine.wasm +0 -0
package/src/anim.js
CHANGED
|
@@ -17,13 +17,30 @@ import { reduce } from "./playback-state.js";
|
|
|
17
17
|
* @typedef {{ bytes: Bytes, offset?: number, poolIndex?: number|"active" }} BufferWrite
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* One entry of a draw's `textures` map (all `writeTexture` options except the
|
|
22
|
+
* pending scheduler's `redraw`): bytes for a texture, by its SJON name.
|
|
23
|
+
* @typedef {ArrayBufferView|ArrayBuffer} TextureBytes
|
|
24
|
+
* @typedef {{
|
|
25
|
+
* bytes: TextureBytes,
|
|
26
|
+
* offset?: number,
|
|
27
|
+
* bytesPerRow?: number,
|
|
28
|
+
* rowsPerImage?: number,
|
|
29
|
+
* origin?: ArrayLike<number>,
|
|
30
|
+
* mipLevel?: number,
|
|
31
|
+
* aspect?: "all"|"depth-only"|"stencil-only",
|
|
32
|
+
* size?: ArrayLike<number>,
|
|
33
|
+
* poolIndex?: number|"active",
|
|
34
|
+
* }} TextureWrite
|
|
35
|
+
*/
|
|
36
|
+
|
|
20
37
|
/**
|
|
21
38
|
* Take the host state stored for "the next draw, whoever posts it"
|
|
22
|
-
* (setUniform/setUniforms/writeBuffer with `redraw: false`) and
|
|
23
|
-
* draw's own map over it — the draw's entry wins on a shared name,
|
|
24
|
-
* later intent. The store is cleared: it rode this message.
|
|
39
|
+
* (setUniform/setUniforms/writeBuffer/writeTexture with `redraw: false`) and
|
|
40
|
+
* merge the draw's own map over it — the draw's entry wins on a shared name,
|
|
41
|
+
* being the later intent. The store is cleared: it rode this message.
|
|
25
42
|
* @param {any} i
|
|
26
|
-
* @param {"pendingUniforms"|"pendingBuffers"} key
|
|
43
|
+
* @param {"pendingUniforms"|"pendingBuffers"|"pendingTextures"} key
|
|
27
44
|
* @param {object|undefined} own
|
|
28
45
|
*/
|
|
29
46
|
function takePending(i, key, own) {
|
|
@@ -89,14 +106,152 @@ function checkOptions(verb, opts) {
|
|
|
89
106
|
return opts;
|
|
90
107
|
}
|
|
91
108
|
|
|
109
|
+
/** The aspects the wire contract and the host driver share, in wire tag order. */
|
|
110
|
+
const TEXTURE_ASPECTS = ["all", "depth-only", "stencil-only"];
|
|
111
|
+
/** Every numeric texture option is a u32 in the wire/calculator contract. */
|
|
112
|
+
const U32_MAX = 0xffffffff;
|
|
113
|
+
|
|
114
|
+
/** @param {unknown} v @returns {boolean} */
|
|
115
|
+
function isU32(v) {
|
|
116
|
+
return typeof v === "number" && Number.isSafeInteger(v) && v >= 0 && v <= U32_MAX;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** @param {unknown} v @returns {boolean} */
|
|
120
|
+
function isArrayLike(v) {
|
|
121
|
+
return Array.isArray(v) || ArrayBuffer.isView(v);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** @param {unknown} b @returns {b is TextureBytes} */
|
|
125
|
+
function isBytes(b) {
|
|
126
|
+
return ArrayBuffer.isView(b) || b instanceof ArrayBuffer;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* D13's source-state refusal: host bytes are never transferred, and a source
|
|
131
|
+
* that has already been detached — or whose resizable/growable backing could
|
|
132
|
+
* move under the post/clone read — is refused by name instead of read stale or
|
|
133
|
+
* out-of-window. Returns the refusal message, or null for an ordinary source.
|
|
134
|
+
*
|
|
135
|
+
* @param {string} verb
|
|
136
|
+
* @param {string} name
|
|
137
|
+
* @param {TextureBytes} bytes
|
|
138
|
+
* @returns {string|null}
|
|
139
|
+
*/
|
|
140
|
+
function textureSourceRefusal(verb, name, bytes) {
|
|
141
|
+
const buffer = /** @type {ArrayBuffer} */ (ArrayBuffer.isView(bytes) ? bytes.buffer : bytes);
|
|
142
|
+
if (!buffer) return null;
|
|
143
|
+
if (/** @type {any} */ (buffer).detached === true) {
|
|
144
|
+
return `${verb} '${name}': detached-source — the source buffer has been detached; nothing can be read from it`;
|
|
145
|
+
}
|
|
146
|
+
if (/** @type {any} */ (buffer).resizable === true || /** @type {any} */ (buffer).growable === true) {
|
|
147
|
+
return `${verb} '${name}': resizable-source — a resizable/growable backing buffer is refused; pass a fixed-length view`;
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* One `textures` map entry, shape-checked and defaulted. Every check runs
|
|
154
|
+
* before the caller's map is posted or a pending entry changes, so a malformed
|
|
155
|
+
* write is a TypeError with no half-applied state (the same contract
|
|
156
|
+
* writeBuffer's bytes/offset/poolIndex checks carry).
|
|
157
|
+
*
|
|
158
|
+
* @param {string} verb
|
|
159
|
+
* @param {string} name
|
|
160
|
+
* @param {TextureBytes|TextureWrite} spec
|
|
161
|
+
* @returns {TextureWrite}
|
|
162
|
+
*/
|
|
163
|
+
function textureEntry(verb, name, spec) {
|
|
164
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
165
|
+
throw new TypeError(`${verb}: texture names must be nonempty strings, got ${String(name)}`);
|
|
166
|
+
}
|
|
167
|
+
const w = isBytes(spec) ? { bytes: spec } : /** @type {TextureWrite} */ (spec);
|
|
168
|
+
if (!w || typeof w !== "object" || Array.isArray(w) || !isBytes(w.bytes)) {
|
|
169
|
+
throw new TypeError(`${verb} '${name}': bytes must be an ArrayBufferView or an ArrayBuffer`);
|
|
170
|
+
}
|
|
171
|
+
const source = textureSourceRefusal(verb, name, w.bytes);
|
|
172
|
+
if (source) throw new TypeError(source);
|
|
173
|
+
|
|
174
|
+
const offset = w.offset === undefined ? 0 : w.offset;
|
|
175
|
+
if (!isU32(offset)) throw new TypeError(`${verb} '${name}': offset must be a non-negative u32 integer, got ${offset}`);
|
|
176
|
+
const mipLevel = w.mipLevel === undefined ? 0 : w.mipLevel;
|
|
177
|
+
if (!isU32(mipLevel)) throw new TypeError(`${verb} '${name}': mipLevel must be a non-negative u32 integer, got ${mipLevel}`);
|
|
178
|
+
if (w.bytesPerRow !== undefined && !isU32(w.bytesPerRow)) {
|
|
179
|
+
throw new TypeError(`${verb} '${name}': bytesPerRow must be a non-negative u32 integer, got ${w.bytesPerRow}`);
|
|
180
|
+
}
|
|
181
|
+
if (w.rowsPerImage !== undefined && !isU32(w.rowsPerImage)) {
|
|
182
|
+
throw new TypeError(`${verb} '${name}': rowsPerImage must be a non-negative u32 integer, got ${w.rowsPerImage}`);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const aspect = w.aspect === undefined ? "all" : w.aspect;
|
|
186
|
+
if (!TEXTURE_ASPECTS.includes(/** @type {any} */ (aspect))) {
|
|
187
|
+
throw new TypeError(`${verb} '${name}': aspect must be one of ${TEXTURE_ASPECTS.join(", ")}, got ${aspect}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const origin = w.origin === undefined ? [] : w.origin;
|
|
191
|
+
if (!isArrayLike(origin) || origin.length > 3) {
|
|
192
|
+
throw new TypeError(`${verb} '${name}': origin must be an array of 0-3 numbers`);
|
|
193
|
+
}
|
|
194
|
+
for (const v of Array.from(origin)) {
|
|
195
|
+
if (!isU32(v)) throw new TypeError(`${verb} '${name}': origin members must be non-negative u32 integers, got ${v}`);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (w.size !== undefined) {
|
|
199
|
+
if (!isArrayLike(w.size) || w.size.length < 1 || w.size.length > 3) {
|
|
200
|
+
throw new TypeError(`${verb} '${name}': size must be an array of 1-3 numbers`);
|
|
201
|
+
}
|
|
202
|
+
for (const v of Array.from(w.size)) {
|
|
203
|
+
if (!isU32(v)) throw new TypeError(`${verb} '${name}': size members must be non-negative u32 integers, got ${v}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (w.poolIndex !== undefined && w.poolIndex !== "active" && !isU32(w.poolIndex)) {
|
|
208
|
+
throw new TypeError(`${verb} '${name}': poolIndex must be a non-negative integer or "active", got ${w.poolIndex}`);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** @type {TextureWrite} */
|
|
212
|
+
const entry = { bytes: w.bytes };
|
|
213
|
+
if (w.offset !== undefined) entry.offset = offset;
|
|
214
|
+
if (w.bytesPerRow !== undefined) entry.bytesPerRow = w.bytesPerRow;
|
|
215
|
+
if (w.rowsPerImage !== undefined) entry.rowsPerImage = w.rowsPerImage;
|
|
216
|
+
if (w.origin !== undefined) entry.origin = w.origin;
|
|
217
|
+
if (w.mipLevel !== undefined) entry.mipLevel = mipLevel;
|
|
218
|
+
if (w.aspect !== undefined) entry.aspect = /** @type {"all"|"depth-only"|"stencil-only"} */ (aspect);
|
|
219
|
+
if (w.size !== undefined) entry.size = w.size;
|
|
220
|
+
if (w.poolIndex !== undefined) entry.poolIndex = w.poolIndex;
|
|
221
|
+
return entry;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Validate and normalize every entry of a `textures` map (a shorthand bytes
|
|
226
|
+
* value becomes `{ bytes }`). The map itself and every record are checked
|
|
227
|
+
* before the draw posts it, so a malformed map cannot replace a pending entry
|
|
228
|
+
* or reach the worker half-applied.
|
|
229
|
+
* @param {string} verb
|
|
230
|
+
* @param {Record<string, TextureBytes|TextureWrite>|null|undefined} textures
|
|
231
|
+
* @returns {Record<string, TextureWrite>|null}
|
|
232
|
+
*/
|
|
233
|
+
function textureMap(verb, textures) {
|
|
234
|
+
if (textures === null || textures === undefined) return null;
|
|
235
|
+
if (typeof textures !== "object" || Array.isArray(textures)) {
|
|
236
|
+
throw new TypeError(`${verb}: textures must be an object keyed by texture name`);
|
|
237
|
+
}
|
|
238
|
+
/** @type {Record<string, TextureWrite>} */
|
|
239
|
+
const out = {};
|
|
240
|
+
for (const [name, spec] of Object.entries(textures)) out[name] = textureEntry(verb, name, spec);
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
|
|
92
244
|
/**
|
|
93
245
|
* Draw a frame (sync, post-and-forget)
|
|
94
246
|
*
|
|
95
247
|
* Host state rides the message: `uniforms` (reflected struct fields, by
|
|
96
|
-
* name)
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
248
|
+
* name), `buffers` (raw bytes for a `(buffer :name …)`, by name) and
|
|
249
|
+
* `textures` (raw bytes or a TextureWrite for a `(texture :name …)`, by
|
|
250
|
+
* name). All are applied inside the worker's render lock at the head of the
|
|
251
|
+
* frame this draw renders — uniforms, then buffers, then textures — before
|
|
252
|
+
* the frame's own commands, and the worker never collapses a draw that
|
|
253
|
+
* carries any of them (a superseded rAF draw is dropped; one with host state
|
|
254
|
+
* is not).
|
|
100
255
|
*
|
|
101
256
|
* `frame` names which `(frame …)` this ONE draw renders; it does not move
|
|
102
257
|
* the pin setFrame holds. Absent, the draw carries the pin (null when none,
|
|
@@ -114,11 +269,16 @@ function checkOptions(verb, opts) {
|
|
|
114
269
|
* for the executor's choice; absent → the pin from setFrame
|
|
115
270
|
* @param {Object} [opts.uniforms]
|
|
116
271
|
* @param {Record<string, Bytes|BufferWrite>} [opts.buffers]
|
|
272
|
+
* @param {Record<string, TextureBytes|TextureWrite>} [opts.textures]
|
|
117
273
|
* @returns {Pngine}
|
|
118
274
|
*/
|
|
119
275
|
export function draw(p, opts = {}) {
|
|
120
276
|
if (opts.time !== undefined) checkTime(opts.time);
|
|
121
277
|
if (opts.frame !== undefined) checkFrame(opts.frame);
|
|
278
|
+
// The draw's own map is shape-checked before anything else changes; a
|
|
279
|
+
// deferred write is checked again after the merge, so one detached between
|
|
280
|
+
// its call and this post is refused at the posting boundary (D13).
|
|
281
|
+
const ownTextures = textureMap("draw", opts.textures);
|
|
122
282
|
const i = p._;
|
|
123
283
|
if (!i) return p;
|
|
124
284
|
|
|
@@ -128,6 +288,9 @@ export function draw(p, opts = {}) {
|
|
|
128
288
|
// An explicit time is recorded as the instance's time (what p.time reads).
|
|
129
289
|
if (opts.time !== undefined) i.pb = reduce(i.pb, { type: "DRAW", record: opts.time });
|
|
130
290
|
|
|
291
|
+
const pendingTextures = takePending(i, "pendingTextures", ownTextures);
|
|
292
|
+
const textures = textureMap("draw", pendingTextures);
|
|
293
|
+
|
|
131
294
|
i.worker.postMessage({
|
|
132
295
|
type: "draw",
|
|
133
296
|
time,
|
|
@@ -135,6 +298,7 @@ export function draw(p, opts = {}) {
|
|
|
135
298
|
pointer: i.pointer ?? null,
|
|
136
299
|
uniforms: takePending(i, "pendingUniforms", opts.uniforms),
|
|
137
300
|
buffers: takePending(i, "pendingBuffers", opts.buffers),
|
|
301
|
+
textures,
|
|
138
302
|
});
|
|
139
303
|
|
|
140
304
|
// Reset pointer deltas and scroll after each frame
|
|
@@ -375,6 +539,66 @@ export function writeBuffer(p, name, bytes, opts) {
|
|
|
375
539
|
return p;
|
|
376
540
|
}
|
|
377
541
|
|
|
542
|
+
/**
|
|
543
|
+
* Put bytes in a texture, by the `(texture :name …)` the document declares.
|
|
544
|
+
*
|
|
545
|
+
* The seam is the draw message: with `redraw` true (the default) this is one
|
|
546
|
+
* `draw(p, { time, textures: { [name]: entry } })`, so the write lands at the
|
|
547
|
+
* head of the frame that draw renders, after its uniforms and buffers and
|
|
548
|
+
* before the frame's own queue operations. With `redraw: false` the entry is
|
|
549
|
+
* stored for the next draw from anywhere (see setUniform), and its bytes are
|
|
550
|
+
* read when THAT draw is posted, not now.
|
|
551
|
+
*
|
|
552
|
+
* Every write is a copy: structured clone, once, on the way to the worker —
|
|
553
|
+
* and no transfer list, so the caller's arena, view window and lifetime are
|
|
554
|
+
* untouched. Only the view's own `byteOffset`/`byteLength` is read. A source
|
|
555
|
+
* whose backing buffer is already detached, or is resizable/growable, is a
|
|
556
|
+
* named TypeError (`detached-source` / `resizable-source`) before anything
|
|
557
|
+
* posts or is stored; never a stale or out-of-window read (D13).
|
|
558
|
+
*
|
|
559
|
+
* What the runtime cannot honour — an unknown name, a texture the frame
|
|
560
|
+
* itself writes every draw, a bad pool member, no `copy-dst`, a multisampled
|
|
561
|
+
* or 1D destination, a bad mip/origin/extent/stride/aspect, too little data —
|
|
562
|
+
* reaches options.onError as a PngineGPUError with source "write-texture";
|
|
563
|
+
* getTextures(p) says which names are writable and why not. Options are
|
|
564
|
+
* `offset` (default 0; unaligned allowed), `bytesPerRow`, `rowsPerImage`
|
|
565
|
+
* (presence preserved: absent stays absent at the WebGPU boundary, D26),
|
|
566
|
+
* `origin` ([x,y,z]; 0-3 members, missing are 0), `mipLevel` (0), `aspect`
|
|
567
|
+
* ("all"), `size` ([w], [w h] or [w h d]; default the remaining physical mip
|
|
568
|
+
* extent), and `poolIndex` (`k` for member k, `"active"` for the coming
|
|
569
|
+
* frame's member, absent for every member).
|
|
570
|
+
*
|
|
571
|
+
* @param {Pngine} p
|
|
572
|
+
* @param {string} name
|
|
573
|
+
* @param {TextureBytes} bytes
|
|
574
|
+
* @param {{
|
|
575
|
+
* offset?: number,
|
|
576
|
+
* bytesPerRow?: number,
|
|
577
|
+
* rowsPerImage?: number,
|
|
578
|
+
* origin?: ArrayLike<number>,
|
|
579
|
+
* mipLevel?: number,
|
|
580
|
+
* aspect?: "all"|"depth-only"|"stencil-only",
|
|
581
|
+
* size?: ArrayLike<number>,
|
|
582
|
+
* poolIndex?: number|"active",
|
|
583
|
+
* redraw?: boolean,
|
|
584
|
+
* }} [opts]
|
|
585
|
+
* @returns {Pngine}
|
|
586
|
+
*/
|
|
587
|
+
export function writeTexture(p, name, bytes, opts) {
|
|
588
|
+
const { redraw = true, ...write } = checkOptions("writeTexture", opts);
|
|
589
|
+
if (typeof redraw !== "boolean") throw new TypeError(`writeTexture: redraw must be a boolean, got ${String(redraw)}`);
|
|
590
|
+
const entry = textureEntry("writeTexture", name, { ...write, bytes });
|
|
591
|
+
const i = p._;
|
|
592
|
+
if (!i) return p;
|
|
593
|
+
|
|
594
|
+
if (redraw) {
|
|
595
|
+
draw(p, { time: i.pb.time, textures: { [name]: entry } });
|
|
596
|
+
} else {
|
|
597
|
+
(i.pendingTextures ??= {})[name] = entry;
|
|
598
|
+
}
|
|
599
|
+
return p;
|
|
600
|
+
}
|
|
601
|
+
|
|
378
602
|
/**
|
|
379
603
|
* The pointer source every draw posts: an ArrayLike of exactly twelve
|
|
380
604
|
* numbers (the pointer-inputs layout), or null to hand the lanes back to the
|
|
@@ -665,6 +889,26 @@ export function getBuffers(p) {
|
|
|
665
889
|
return workerRequest(i, { type: "getBuffers" }, "buffers", (d) => d.buffers || {}, {});
|
|
666
890
|
}
|
|
667
891
|
|
|
892
|
+
/**
|
|
893
|
+
* Every currently created named texture, by SJON name: `{ size, dimension,
|
|
894
|
+
* format, mipLevelCount, arrayDepth, usage, sampleCount, sizeSource, pool,
|
|
895
|
+
* frameWritten, writable, writableAspects }` each. Raw ids are never exposed.
|
|
896
|
+
* `writable` is the current host-write verdict (created, copy-dst, one
|
|
897
|
+
* sample, 2D/3D, not frameWritten, at least one legal aspect);
|
|
898
|
+
* `writableAspects` is format/aspect legality alone. The reply observes the
|
|
899
|
+
* same FIFO position as the other reflection queries, reports the current
|
|
900
|
+
* descriptor after a resize, and is `{}` before load, after device loss and
|
|
901
|
+
* after destroy.
|
|
902
|
+
*
|
|
903
|
+
* @param {Pngine} p - PNGine instance
|
|
904
|
+
* @returns {Promise<Record<string, import("./gpu-host-texture.js").TextureInfo>>}
|
|
905
|
+
*/
|
|
906
|
+
export function getTextures(p) {
|
|
907
|
+
const i = p._;
|
|
908
|
+
if (!i) return Promise.resolve({});
|
|
909
|
+
return workerRequest(i, { type: "getTextures" }, "textures", (d) => d.textures || {}, {});
|
|
910
|
+
}
|
|
911
|
+
|
|
668
912
|
/**
|
|
669
913
|
* Live resource counts for this instance — the instrument for a long-running
|
|
670
914
|
* session.
|
package/src/core.js
CHANGED
|
@@ -126,6 +126,53 @@ export function createCoreDispatcher(device, ctx) {
|
|
|
126
126
|
return dispatcher.getBuffers();
|
|
127
127
|
},
|
|
128
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Install the payload's texture names, so writeTextures/getTextures can
|
|
131
|
+
* address a texture by the `(texture :name …)` the author wrote. The
|
|
132
|
+
* map comes from parseUniformTable(bytecode).textures; call this after
|
|
133
|
+
* the init stream has executed, beside setBufferNames. It replaces the
|
|
134
|
+
* previous map whole, so a reload never inherits stale names.
|
|
135
|
+
* @param {Map<string, import("./gpu-host-texture.js").TextureName>|Record<string, import("./gpu-host-texture.js").TextureName>} names
|
|
136
|
+
*/
|
|
137
|
+
setTextureNames(names) {
|
|
138
|
+
dispatcher.setTextureNames(names);
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Put host bytes in textures, by name: `{ albedo: bytes }` or
|
|
143
|
+
* `{ albedo: { bytes, offset, bytesPerRow, rowsPerImage, origin,
|
|
144
|
+
* mipLevel, aspect, size, poolIndex } }`.
|
|
145
|
+
*
|
|
146
|
+
* The whole map is shape-checked before the first byte moves: a
|
|
147
|
+
* malformed record throws a TypeError. A name the runtime cannot honour
|
|
148
|
+
* (unknown, written by the frame itself, a bad pool member, no
|
|
149
|
+
* copy-dst, multisampled, 1D, a bad mip/origin/extent/stride/aspect, or
|
|
150
|
+
* too little data) is REFUSED through the callback installed with
|
|
151
|
+
* setOnError, with source "write-texture" — never silently dropped — and
|
|
152
|
+
* makes no queue call. A pooled name with no poolIndex writes every
|
|
153
|
+
* member; `"active"` needs the coming frame's counter
|
|
154
|
+
* (`wasm.getFrameCounter()`, read before `frame()`). Returns how many
|
|
155
|
+
* queue writes were made.
|
|
156
|
+
* @param {import("./gpu-host-texture.js").HostTextures} textures
|
|
157
|
+
* @param {number} [frameCounter]
|
|
158
|
+
* @returns {number}
|
|
159
|
+
*/
|
|
160
|
+
writeTextures(textures, frameCounter) {
|
|
161
|
+
return dispatcher.writeTextures(textures, frameCounter);
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Every currently created named texture, by SJON name: `{ size,
|
|
166
|
+
* dimension, format, mipLevelCount, arrayDepth, usage, sampleCount,
|
|
167
|
+
* sizeSource, pool, frameWritten, writable, writableAspects }`. Raw ids
|
|
168
|
+
* are never exposed. `writable` is the current host-write verdict;
|
|
169
|
+
* `writableAspects` describes format/aspect legality alone.
|
|
170
|
+
* @returns {Record<string, import("./gpu-host-texture.js").TextureInfo>}
|
|
171
|
+
*/
|
|
172
|
+
getTextures() {
|
|
173
|
+
return dispatcher.getTextures();
|
|
174
|
+
},
|
|
175
|
+
|
|
129
176
|
/**
|
|
130
177
|
* Hear command-stream faults: an unknown opcode, an empty descriptor,
|
|
131
178
|
* a resource that failed validation, a refused host write. Called
|
package/src/descriptor-decode.js
CHANGED
|
@@ -23,16 +23,19 @@ const RENDER_ATTACHMENT = 0x10;
|
|
|
23
23
|
* @param {number} cw - canvas width fallback for size
|
|
24
24
|
* @param {number} ch - canvas height fallback for size
|
|
25
25
|
* @param {Array} [bmp] - ImageBitmap table for size-from-image (field 0x0A)
|
|
26
|
-
* @returns {{desc: object, canvasBound: boolean, canvasScale: number
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* field 0x0B said otherwise; the
|
|
26
|
+
* @returns {{desc: object, canvasBound: boolean, canvasScale: number,
|
|
27
|
+
* extentSource: "explicit"|"canvas"|"image-bitmap"}} - descriptor, whether
|
|
28
|
+
* size tracks the canvas (bytecode omitted explicit width AND height), the
|
|
29
|
+
* fraction of the canvas it tracks (1 unless field 0x0B said otherwise; the
|
|
30
|
+
* resize path applies it again), and where the resolved extent came from.
|
|
31
|
+
* An image reference that has not decoded yet resolves to the canvas
|
|
32
|
+
* fallback, so its source is `canvas`: that is the extent actually created.
|
|
30
33
|
*/
|
|
31
34
|
export function decodeTextureDescriptor(bytes, defaultFormat, cw, ch, bmp) {
|
|
32
35
|
const v = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
33
36
|
let off = 2; // skip type tag + field count
|
|
34
37
|
const desc = { size: [cw || 512, ch || 512], format: defaultFormat, usage: RENDER_ATTACHMENT, sampleCount: 1 };
|
|
35
|
-
let hasW = false, hasH = false, scale = 1;
|
|
38
|
+
let hasW = false, hasH = false, scale = 1, fromImage = false;
|
|
36
39
|
const fc = bytes[1];
|
|
37
40
|
for (let i = 0; i < fc; i++) {
|
|
38
41
|
const fid = bytes[off++], vt = bytes[off++];
|
|
@@ -53,7 +56,7 @@ export function decodeTextureDescriptor(bytes, defaultFormat, cw, ch, bmp) {
|
|
|
53
56
|
// fid 0x0A = size_from_image_bitmap: use ImageBitmap dimensions
|
|
54
57
|
if (fid === 0x0A && bmp && bmp[val]) {
|
|
55
58
|
desc.size = [bmp[val].width, bmp[val].height];
|
|
56
|
-
hasW = true; hasH = true;
|
|
59
|
+
hasW = true; hasH = true; fromImage = true;
|
|
57
60
|
}
|
|
58
61
|
} else if (vt === 0x07) { // enum
|
|
59
62
|
const val = bytes[off++];
|
|
@@ -79,7 +82,10 @@ export function decodeTextureDescriptor(bytes, defaultFormat, cw, ch, bmp) {
|
|
|
79
82
|
desc.size[0] = scaleExtent(desc.size[0], scale);
|
|
80
83
|
desc.size[1] = scaleExtent(desc.size[1], scale);
|
|
81
84
|
}
|
|
82
|
-
|
|
85
|
+
// Where the CONCRETE extent came from: an unresolved image reference falls
|
|
86
|
+
// back to the canvas, so `canvas` is the truthful source for what exists.
|
|
87
|
+
const extentSource = canvasBound ? "canvas" : fromImage ? "image-bitmap" : "explicit";
|
|
88
|
+
return { desc, canvasBound, canvasScale: scale, extentSource };
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
/// Byte width of each scalar ValueType (src/types/descriptors.zig
|
package/src/dev.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// PNGine Dev API (full-feature profile)
|
|
2
2
|
|
|
3
3
|
export { pngine, destroy } from "./init.js";
|
|
4
|
-
export { draw, play, pause, stop, seek, setFrame, setUniform, setUniforms, getUniforms, writeBuffer, setPointer, getBuffers, getStats, restart, restartSettled } from "./anim.js";
|
|
4
|
+
export { draw, play, pause, stop, seek, setFrame, setUniform, setUniforms, getUniforms, writeBuffer, setPointer, getBuffers, writeTexture, getTextures, getStats, restart, restartSettled } from "./anim.js";
|
|
5
5
|
export { extractBytecode, detectFormat, isPng, isZip, isPngb } from "./extract.js";
|
|
6
6
|
export { parsePayload, createExecutor, getExecutorImports, getExecutorVariantName } from "./loader.js";
|
|
7
7
|
// The payload walker (02.C2): re-exported here so the types gate pins its
|
package/src/enums.js
CHANGED
|
@@ -82,6 +82,62 @@ export const TEXTURE_FORMAT = {
|
|
|
82
82
|
0x71: "rgb10a2uint",
|
|
83
83
|
0x72: "rg11b10ufloat",
|
|
84
84
|
0x73: "rgb9e5ufloat",
|
|
85
|
+
// BC compressed (plan 07 tranche A); creation requires texture-compression-bc
|
|
86
|
+
0x80: "bc1-rgba-unorm",
|
|
87
|
+
0x81: "bc1-rgba-unorm-srgb",
|
|
88
|
+
0x82: "bc2-rgba-unorm",
|
|
89
|
+
0x83: "bc2-rgba-unorm-srgb",
|
|
90
|
+
0x84: "bc3-rgba-unorm",
|
|
91
|
+
0x85: "bc3-rgba-unorm-srgb",
|
|
92
|
+
0x86: "bc4-r-unorm",
|
|
93
|
+
0x87: "bc4-r-snorm",
|
|
94
|
+
0x88: "bc5-rg-unorm",
|
|
95
|
+
0x89: "bc5-rg-snorm",
|
|
96
|
+
0x8a: "bc6h-rgb-ufloat",
|
|
97
|
+
0x8b: "bc6h-rgb-float",
|
|
98
|
+
0x8c: "bc7-rgba-unorm",
|
|
99
|
+
0x8d: "bc7-rgba-unorm-srgb",
|
|
100
|
+
// ETC2/EAC compressed (plan 07 tranche B); creation requires texture-compression-etc2
|
|
101
|
+
0x90: "etc2-rgb8unorm",
|
|
102
|
+
0x91: "etc2-rgb8unorm-srgb",
|
|
103
|
+
0x92: "etc2-rgb8a1unorm",
|
|
104
|
+
0x93: "etc2-rgb8a1unorm-srgb",
|
|
105
|
+
0x94: "etc2-rgba8unorm",
|
|
106
|
+
0x95: "etc2-rgba8unorm-srgb",
|
|
107
|
+
0x96: "eac-r11unorm",
|
|
108
|
+
0x97: "eac-r11snorm",
|
|
109
|
+
0x98: "eac-rg11unorm",
|
|
110
|
+
0x99: "eac-rg11snorm",
|
|
111
|
+
// ASTC compressed (plan 07 tranche C); creation requires
|
|
112
|
+
// texture-compression-astc, 3D additionally texture-compression-astc-sliced-3d
|
|
113
|
+
0xa0: "astc-4x4-unorm",
|
|
114
|
+
0xa1: "astc-4x4-unorm-srgb",
|
|
115
|
+
0xa2: "astc-5x4-unorm",
|
|
116
|
+
0xa3: "astc-5x4-unorm-srgb",
|
|
117
|
+
0xa4: "astc-5x5-unorm",
|
|
118
|
+
0xa5: "astc-5x5-unorm-srgb",
|
|
119
|
+
0xa6: "astc-6x5-unorm",
|
|
120
|
+
0xa7: "astc-6x5-unorm-srgb",
|
|
121
|
+
0xa8: "astc-6x6-unorm",
|
|
122
|
+
0xa9: "astc-6x6-unorm-srgb",
|
|
123
|
+
0xaa: "astc-8x5-unorm",
|
|
124
|
+
0xab: "astc-8x5-unorm-srgb",
|
|
125
|
+
0xac: "astc-8x6-unorm",
|
|
126
|
+
0xad: "astc-8x6-unorm-srgb",
|
|
127
|
+
0xae: "astc-8x8-unorm",
|
|
128
|
+
0xaf: "astc-8x8-unorm-srgb",
|
|
129
|
+
0xb0: "astc-10x5-unorm",
|
|
130
|
+
0xb1: "astc-10x5-unorm-srgb",
|
|
131
|
+
0xb2: "astc-10x6-unorm",
|
|
132
|
+
0xb3: "astc-10x6-unorm-srgb",
|
|
133
|
+
0xb4: "astc-10x8-unorm",
|
|
134
|
+
0xb5: "astc-10x8-unorm-srgb",
|
|
135
|
+
0xb6: "astc-10x10-unorm",
|
|
136
|
+
0xb7: "astc-10x10-unorm-srgb",
|
|
137
|
+
0xb8: "astc-12x10-unorm",
|
|
138
|
+
0xb9: "astc-12x10-unorm-srgb",
|
|
139
|
+
0xba: "astc-12x12-unorm",
|
|
140
|
+
0xbb: "astc-12x12-unorm-srgb",
|
|
85
141
|
// 0xFF: Use preferred canvas format (handled specially)
|
|
86
142
|
};
|
|
87
143
|
|