@margoengine/quality 0.0.0-stage → 1.0.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.
@@ -0,0 +1,166 @@
1
+ // @margo/core-built 1.0.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+
4
+ //#region ../core/dist/quality.js
5
+ var e = /Mobi|Android/;
6
+ function t(t) {
7
+ return t?.exact || (globalThis.margoLow || e.test(globalThis.navigator?.userAgent) ? 1 : 4);
8
+ }
9
+ //#endregion
10
+ //#region src/pacing.ts
11
+ function n(e, t, n) {
12
+ let r = 1e3 / n, i = Math.min(2, r * .1), a = e[1];
13
+ e[1] = t;
14
+ let o = t - a;
15
+ if (!a || o > r * 4) return e[2] = 0, e[0] = t + r, !0;
16
+ if (e[2] = e[2] ? e[2] + (o - e[2]) * .1 : o, e[2] >= r - i) e[0] = Math.min(e[0], t);
17
+ else if (t + i < e[0]) return !1;
18
+ return e[0] = Math.max(e[0] + r, t - r), !0;
19
+ }
20
+ function r(e, t, n) {
21
+ if (!t) return "Measuring browser cadence…";
22
+ let r = Math.round(t);
23
+ return e > t * 1.15 ? `${e} FPS target · browser supplies ~${r} Hz. Rendering load or browser/display limits can reduce this cadence.` : n < e * .85 ? `${e} FPS target · rendering ~${Math.round(n)} FPS; browser cadence ~${r} Hz.` : `${e} FPS target · browser cadence ~${r} Hz.`;
24
+ }
25
+ //#endregion
26
+ //#region src/index.ts
27
+ var i = {
28
+ shadows: {
29
+ resolution: 1024,
30
+ filter: "pcf"
31
+ },
32
+ ssao: { samples: 16 },
33
+ ssr: {
34
+ enabled: !1,
35
+ steps: 32
36
+ },
37
+ volumetric: { grid: [
38
+ 80,
39
+ 45,
40
+ 32
41
+ ] },
42
+ localShadows: { resolution: 256 },
43
+ vfx: { capacity: 1e5 }
44
+ }, a = {
45
+ high: {},
46
+ light: i,
47
+ phone: {
48
+ ...i,
49
+ shadows: {
50
+ ...i.shadows,
51
+ cascades: 2
52
+ },
53
+ ssao: { enabled: !1 },
54
+ volumetric: { enabled: !1 },
55
+ scatter: { lodFade: 0 }
56
+ }
57
+ }, o = () => a[(m ?? (v(), m)).tier], s = 55, c = 8, l = "margoQualityLowered", u = "margoQuality", d = "held", f = "timestamp-query";
58
+ function p(e) {
59
+ let t = e.requestDevice;
60
+ function n(e = {}) {
61
+ return t.call(this, this.features.has(f) ? {
62
+ ...e,
63
+ requiredFeatures: /* @__PURE__ */ new Set([...e.requiredFeatures ?? [], f])
64
+ } : e);
65
+ }
66
+ return e.requestDevice = n, () => {
67
+ e.requestDevice === n && (e.requestDevice = t);
68
+ };
69
+ }
70
+ var m, h, g = () => {
71
+ try {
72
+ return globalThis.localStorage;
73
+ } catch {
74
+ return;
75
+ }
76
+ }, _ = () => {
77
+ try {
78
+ return globalThis.sessionStorage;
79
+ } catch {
80
+ return;
81
+ }
82
+ };
83
+ function v({ search: e = globalThis.location?.search, page: t = globalThis.location?.pathname, storage: n = g(), session: r = _(), userAgent: i = globalThis.navigator?.userAgent ?? "" } = {}) {
84
+ let o = new URLSearchParams(e), s = o.get("quality") ?? void 0, c = t ? `${u}:${t}` : u, f, v = !1;
85
+ try {
86
+ f = n?.getItem(c) ?? void 0;
87
+ } catch {}
88
+ try {
89
+ v = !!r?.getItem(l);
90
+ } catch {}
91
+ let y = s === "high" || s === "low" ? s : void 0, b = y ?? f, x = v && !y && f === "high", S = /Mobi|Android|iPhone/.test(i) ? "phone" : b === "high" && !x ? "high" : "light";
92
+ S === "high" ? delete globalThis.margoLow : globalThis.margoLow = S === "phone" ? 1 : Math.min(2, Math.max(1, Number(o.get("scale")) || 1)), globalThis.margoPreset = a[S];
93
+ let C = y ?? (x ? "power" : void 0);
94
+ return m = {
95
+ tier: S,
96
+ stored: b,
97
+ forced: C,
98
+ storage: n,
99
+ key: c
100
+ }, h?.(), h = S === "light" && !C && f !== d && typeof GPUAdapter < "u" ? p(GPUAdapter.prototype) : void 0, S;
101
+ }
102
+ var y = () => (m ?? (v(), m)).tier;
103
+ function b(e, t = 60) {
104
+ let n = 1e3 / t + 1, r = (/* @__PURE__ */ new Float64Array(16)).fill(Infinity), i = /* @__PURE__ */ new Float64Array(16), a = -Infinity, o = -Infinity, s = 0, c = 0;
105
+ e.pace = (e) => {
106
+ let t = e - o;
107
+ o = e, t < n * 4 && (r[s++ % 16] = t), i.set(r), i.sort();
108
+ let l = i[Math.min(s, 16) - 1 >> 1];
109
+ return ++c < Math.floor(n / l) && e - a < n ? !1 : (a = e, c = 0, !0);
110
+ };
111
+ }
112
+ function x(e) {
113
+ (m ?? (v(), m)).tier === "light" && b(e);
114
+ }
115
+ function S({ request: e = globalThis.requestAnimationFrame?.bind(globalThis), queue: t = typeof GPUQueue > "u" ? void 0 : GPUQueue.prototype, device: n = typeof GPUDevice > "u" ? void 0 : GPUDevice.prototype, onReading: r, store: i, reload: a = () => location.reload() } = {}) {
116
+ let o = m ?? (v(), m), s = i ?? ((e) => o.storage?.setItem(o.key, e === "low" ? d : e));
117
+ if (h?.(), h = void 0, o.tier !== "phone" && !o.forced && e) {
118
+ if (o.tier === "high") {
119
+ let t = 0, n = 0, r = 0, i = 0, o = 0, c = (l) => {
120
+ if (l - n > 250) t = l, r = i = 0;
121
+ else if (++r, l - t >= 1e3) {
122
+ if (i = r * 1e3 / (l - t) < 55 ? i + 1 : 0, t = l, r = 0, i === 5) {
123
+ try {
124
+ s("low");
125
+ } catch {
126
+ return;
127
+ }
128
+ a();
129
+ return;
130
+ }
131
+ if (++o === 30) return;
132
+ }
133
+ n = l, e(c);
134
+ };
135
+ e(c);
136
+ } else o.stored !== d && t && n && import("./reading-DeIpfOlV.js").then(({ readGpuTime: i }) => i(t, n, e, (e) => {
137
+ if (e !== void 0 && e < 8) try {
138
+ s("high");
139
+ } catch {}
140
+ r?.(e);
141
+ }), () => r?.(void 0));
142
+ }
143
+ }
144
+ var C = 0;
145
+ function w(e, t, n = globalThis.requestAnimationFrame?.bind(globalThis)) {
146
+ let r = `redraw-after-restore-${++C}`, i = !0, a = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
147
+ name: r,
148
+ setup() {},
149
+ onDeviceRestored: () => {
150
+ i && n(() => {
151
+ i && (t(), i && n(() => {
152
+ i && t();
153
+ }));
154
+ });
155
+ },
156
+ dispose() {
157
+ i = !1;
158
+ }
159
+ };
160
+ return e.use(a), () => {
161
+ i = !1, e.sceneOf(a)?.removePlugin(r);
162
+ };
163
+ }
164
+ var T = t;
165
+ //#endregion
166
+ export { v as a, x as c, T as d, S as f, t as h, s as i, o as l, r as m, l as n, b as o, n as p, a as r, y as s, c as t, w as u };
package/dist/ssaa.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import type { Camera, EngineKernel } from '@margoengine/core';
2
+ /** Options of {@link supersample}. */
3
+ export interface SupersampleOptions {
4
+ /** Frames averaged into the picture, 1 to 1024. Each is one full render. Default 16. */
5
+ samples?: number;
6
+ /** Width of the picture in pixels. Default the canvas width. */
7
+ width?: number;
8
+ /** Height of the picture in pixels. Default the canvas height. */
9
+ height?: number;
10
+ /** Camera to shoot through. Default the engine's camera. */
11
+ camera?: Camera;
12
+ /** Stops between frames and while reading: the promise rejects with `signal.reason`. */
13
+ signal?: AbortSignal;
14
+ }
15
+ /** A still from {@link supersample}: RGBA, 8 bits per channel, opaque, top row first, no padding. `new ImageData(data, width)` takes it. */
16
+ export interface SupersampledImage {
17
+ width: number;
18
+ height: number;
19
+ data: Uint8ClampedArray<ArrayBuffer>;
20
+ }
21
+ /** Options of {@link supersampleBlob}. */
22
+ export interface SupersampleBlobOptions extends SupersampleOptions {
23
+ /** Image type. Default 'image/png'. */
24
+ type?: string;
25
+ /** Encoder quality, 0 to 1, for lossy types. Default the browser's. */
26
+ quality?: number;
27
+ }
28
+ /** The sub-pixel offset of frame `index` of `samples`, each axis in [-0.5, 0.5): Halton (2, 3) points fill the pixel
29
+ * evenly at any count, and the same call gives the same picture. A single frame is not moved. */
30
+ export declare function sampleOffset(index: number, samples: number): readonly [number, number];
31
+ /**
32
+ * Renders a still with supersampling: `samples` whole frames, each moved by a fraction of a pixel, averaged in linear
33
+ * light. Every edge, thin line, shadow boundary and shader highlight gets `samples` samples per pixel, on any tier,
34
+ * and memory does not grow with the sample count. `width` and `height` can exceed the canvas, up to the device's
35
+ * texture limit. Time stands still (delta 0). The canvas is left showing an ordinary frame, and frames from the
36
+ * engine's own loop are untouched.
37
+ * @throws RangeError for invalid options; MargoError `'unsupported'` without WebGPU.
38
+ */
39
+ export declare function supersample(instance: EngineKernel, { samples, width, height, camera, signal }?: SupersampleOptions): Promise<SupersampledImage>;
40
+ /** {@link supersample} as an encoded image file, ready for a download link or an upload. Browser only. */
41
+ export declare function supersampleBlob(engine: EngineKernel, { type, quality, ...options }?: SupersampleBlobOptions): Promise<Blob>;
package/dist/ssaa.js ADDED
@@ -0,0 +1,140 @@
1
+ // @margo/core-built 1.0.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+ const t=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
+ import { n as e } from "./errors-XvcwUnU4.js";
5
+ import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
6
+ //#region src/ssaa.ts
7
+ var n = "fn linear(c:vec3f)->vec3f {return select(c/12.92,pow((c+0.055)/1.055,vec3f(2.4)),c>vec3f(0.04045));}", r = "fn display(c:vec3f)->vec3f {return select(c*12.92,1.055*pow(c,vec3f(1.0/2.4))-0.055,c>vec3f(0.0031308));}", i = `${n}
8
+ @group(0) @binding(0) var frame:texture_2d<f32>;
9
+ @group(0) @binding(1) var before:texture_2d<f32>;
10
+ @group(0) @binding(2) var after:texture_storage_2d<rgba32float,write>;
11
+ @compute @workgroup_size(8,8) fn main(@builtin(global_invocation_id) id:vec3u) {
12
+ if(any(id.xy>=textureDimensions(after))){return;}
13
+ let p=vec2i(id.xy);
14
+ textureStore(after,p,vec4f(textureLoad(before,p,0).rgb+linear(textureLoad(frame,p,0).rgb),1));
15
+ }`, a = `${r}
16
+ override samples:f32=1;
17
+ @group(0) @binding(0) var sum:texture_2d<f32>;
18
+ @group(0) @binding(1) var image:texture_storage_2d<rgba8unorm,write>;
19
+ @compute @workgroup_size(8,8) fn main(@builtin(global_invocation_id) id:vec3u) {
20
+ if(any(id.xy>=textureDimensions(image))){return;}
21
+ let p=vec2i(id.xy);
22
+ textureStore(image,p,vec4f(display(textureLoad(sum,p,0).rgb/samples),1));
23
+ }`, o = 4, s = /* @__PURE__ */ new WeakMap();
24
+ function c(e, t, n) {
25
+ let r = s.get(e);
26
+ r || s.set(e, r = /* @__PURE__ */ new Map());
27
+ let i = n ? `${t}
28
+ ${JSON.stringify(n)}` : t, a = r.get(i);
29
+ return a || (a = e.createComputePipeline({
30
+ layout: "auto",
31
+ compute: {
32
+ module: e.createShaderModule({ code: t }),
33
+ entryPoint: "main",
34
+ constants: n
35
+ }
36
+ }), r.set(i, a)), a;
37
+ }
38
+ function l(e, t) {
39
+ let n = 0, r = 1 / t;
40
+ for (let i = e; i > 0; i = Math.floor(i / t), r /= t) n += i % t * r;
41
+ return n;
42
+ }
43
+ function u(e, t) {
44
+ return t === 1 ? [0, 0] : [l(e + 1, 2) - .5, l(e + 1, 3) - .5];
45
+ }
46
+ async function d(n, { samples: r = 16, width: s, height: l, camera: d, signal: f } = {}) {
47
+ f?.throwIfAborted();
48
+ let p = t(n), m = p.gpu;
49
+ if (!m) throw e("unsupported", "supersample requires WebGPU; it does not run on the WebGL2 fallback");
50
+ let h = s ?? p.canvas.width, g = l ?? p.canvas.height, _ = m.limits.maxTextureDimension2D;
51
+ if (!Number.isInteger(r) || r < 1 || r > 1024) throw RangeError("supersample samples must be an integer in 1..1024");
52
+ if (!Number.isInteger(h) || !Number.isInteger(g) || h < 1 || g < 1 || h > _ || g > _) throw RangeError(`supersample width and height must be integers in 1..${_}`);
53
+ let v = d ?? p.camera, y = v.update, b = [], x = (e, t) => {
54
+ let n = m.createTexture({
55
+ size: [h, g],
56
+ format: e,
57
+ usage: t
58
+ });
59
+ return b.push(n), n;
60
+ }, S = (e, t) => c(m, e, t), C = Math.ceil(h * 4 / 256) * 256, w = m.createBuffer({
61
+ size: C * g,
62
+ usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST
63
+ });
64
+ b.push(w);
65
+ try {
66
+ let e = x(navigator.gpu.getPreferredCanvasFormat(), GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING), t = [0, 1].map(() => x("rgba32float", GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.STORAGE_BINDING)), n = x("rgba8unorm", GPUTextureUsage.STORAGE_BINDING | GPUTextureUsage.COPY_SRC), s = S(i), c = S(a, { samples: r }), l = e.createView(), d = t.map((e) => e.createView()), _ = [0, 1].map((e) => m.createBindGroup({
67
+ layout: s.getBindGroupLayout(0),
68
+ entries: [
69
+ l,
70
+ d[e],
71
+ d[1 - e]
72
+ ].map((e, t) => ({
73
+ binding: t,
74
+ resource: e
75
+ }))
76
+ })), b = (e, t, n) => {
77
+ let r = e.beginComputePass();
78
+ r.setPipeline(t), r.setBindGroup(0, n), r.dispatchWorkgroups(Math.ceil(h / 8), Math.ceil(g / 8)), r.end();
79
+ }, T = [{
80
+ camera: v,
81
+ viewport: [
82
+ 0,
83
+ 0,
84
+ 1,
85
+ 1
86
+ ],
87
+ target: { color: e },
88
+ id: "supersample"
89
+ }];
90
+ for (let e = 0; e < r; e++) {
91
+ let [t, n] = u(e, r);
92
+ v.update = function(e, r) {
93
+ y.call(this, e, r);
94
+ let i = this.matrix;
95
+ for (let e = 0; e < 4; e++) i[e * 4] += 2 * t / h * i[e * 4 + 3], i[e * 4 + 1] -= 2 * n / g * i[e * 4 + 3];
96
+ };
97
+ try {
98
+ p.render({ views: T });
99
+ } finally {
100
+ v.update = y;
101
+ }
102
+ let i = m.createCommandEncoder();
103
+ b(i, s, _[e & 1]), m.queue.submit([i.finish()]), e % o === 3 && (await m.queue.onSubmittedWorkDone(), f?.throwIfAborted());
104
+ }
105
+ let E = m.createCommandEncoder();
106
+ b(E, c, m.createBindGroup({
107
+ layout: c.getBindGroupLayout(0),
108
+ entries: [{
109
+ binding: 0,
110
+ resource: d[r & 1]
111
+ }, {
112
+ binding: 1,
113
+ resource: n.createView()
114
+ }]
115
+ })), E.copyTextureToBuffer({ texture: n }, {
116
+ buffer: w,
117
+ bytesPerRow: C,
118
+ rowsPerImage: g
119
+ }, [h, g]), m.queue.submit([E.finish()]), await w.mapAsync(GPUMapMode.READ), f?.throwIfAborted();
120
+ let D = new Uint8Array(w.getMappedRange()), O = new Uint8ClampedArray(h * g * 4);
121
+ for (let e = 0; e < g; e++) O.set(D.subarray(e * C, e * C + h * 4), e * h * 4);
122
+ return {
123
+ width: h,
124
+ height: g,
125
+ data: O
126
+ };
127
+ } finally {
128
+ for (let e of b) e.destroy();
129
+ p.render(p.views?.length ? { views: p.views } : {});
130
+ }
131
+ }
132
+ async function f(e, { type: t = "image/png", quality: n, ...r } = {}) {
133
+ let { width: i, height: a, data: o } = await d(e, r), s = new OffscreenCanvas(i, a);
134
+ return s.getContext("2d").putImageData(new ImageData(o, i, a), 0, 0), s.convertToBlob({
135
+ type: t,
136
+ quality: n
137
+ });
138
+ }
139
+ //#endregion
140
+ export { u as sampleOffset, d as supersample, f as supersampleBlob };
package/dist/warm.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ import type { EngineKernel } from '@margoengine/core';
2
+ /** What {@link warmUp} did. */
3
+ export interface WarmUpReport {
4
+ /**
5
+ * Render and compute pipelines created with the async API ahead of their first visible frame; on the WebGL2 layer's
6
+ * frame route (see {@link warmUp}), the distinct pipelines the warm frames made, whose links the layer held them for.
7
+ */
8
+ pipelines: number;
9
+ /** Pipelines that had to be created synchronously after all (the retried call did not match its warmed descriptor). */
10
+ fallbacks: number;
11
+ /** Warm render calls, including the stopped ones that discovered a pipeline (on the frame route every one is whole). */
12
+ rounds: number;
13
+ /** A feature failed after a stopped warm frame, so the device was restored (`engine.rebootDevice()`) and the
14
+ * remaining warm frames created their pipelines synchronously. */
15
+ rebooted: boolean;
16
+ }
17
+ /** Options for {@link warmUp}. */
18
+ export interface WarmUpOptions {
19
+ /** Complete warm frames to render once no new pipeline is found; the second catches history-dependent variants. Default 2. */
20
+ frames?: number;
21
+ /** Safety cap on warm render calls. Default 256. */
22
+ maxRounds?: number;
23
+ /** Stops the warm-up: the promise rejects with `signal.reason` and the device is left unpatched. */
24
+ signal?: AbortSignal;
25
+ }
26
+ /**
27
+ * Create the GPU pipelines of every attached feature with the async WebGPU API, so their first visible frame does not
28
+ * stall on shader compilation. Call during loading, after attaching features and adding the scene and before
29
+ * `engine.start()`. Features create pipelines lazily inside their passes, so warmUp renders warm frames (delta 0) into
30
+ * an offscreen target (nothing is presented): when a frame reaches a pipeline that does not exist yet, the frame is
31
+ * stopped there (an exception out of the synchronous create call), the work it already encoded is submitted (one-time
32
+ * work such as lookup tables and static shadow casters stays done), the pipeline compiles with
33
+ * `createRenderPipelineAsync` / `createComputePipelineAsync`, and the frame is rendered again until one completes; the
34
+ * retried call is answered with the finished pipeline. Frames rendered meanwhile by the engine's own loop are
35
+ * untouched. It resolves once the GPU has finished the warm frames, so pipelines a feature created synchronously at
36
+ * attach have compiled by then too. Without WebGPU it resolves at once. A feature that stores state before creating its pipeline (so the
37
+ * retry skips the creation) fails on the retry; then every feature is reset through device restoration and the warm
38
+ * frames finish with synchronous creation (`report.rebooted`).
39
+ * On the WebGL2 compatibility layer with KHR_parallel_shader_compile (its queue carries the link hold,
40
+ * `Symbol.for('margoengine.queue.holdsLinks')`) no frame is stopped: each warm frame runs whole with the hold on, so the
41
+ * layer keeps that frame's submits, and the writes after them in order, in its queue until every program the frame made
42
+ * has linked and drawn once, and all of a frame's links run side by side on the driver's threads instead of one per
43
+ * round (KB-QUALITY-WARMSERIAL1). It ends after `frames` frames in a row that made no new pipeline.
44
+ * The layer then replays a held frame in tasks of about 50 ms, each after the GPU has run the one before, so the page
45
+ * stays responsive while it plays back.
46
+ * Limit: call it before `engine.start()`. On the layer's frame route the frames a running loop renders meanwhile wait
47
+ * in the queue behind the held frame (their tapes and write copies kept) and replay after it.
48
+ * ponytail: a feature that is off (`enabled = false`) or attached later is not warmed; call warmUp again after
49
+ * attaching it.
50
+ */
51
+ export declare function warmUp(engine: EngineKernel, { frames, maxRounds, signal }?: WarmUpOptions): Promise<WarmUpReport>;
package/dist/warm.js ADDED
@@ -0,0 +1,126 @@
1
+ //#region ../shared/queue-hold.js
2
+ var e = Symbol.for("margoengine.queue.holdsLinks"), t = [
3
+ "createRenderPipeline",
4
+ "createComputePipeline",
5
+ "createShaderModule",
6
+ "createCommandEncoder",
7
+ "createBindGroupLayout",
8
+ "createPipelineLayout"
9
+ ], n = class extends Error {};
10
+ function r(e, t, n) {
11
+ let r = Object.getOwnPropertyDescriptor(e, t);
12
+ return Object.defineProperty(e, t, {
13
+ configurable: !0,
14
+ writable: !0,
15
+ value: n
16
+ }), () => {
17
+ r ? Object.defineProperty(e, t, r) : delete e[t];
18
+ };
19
+ }
20
+ async function i(i, { frames: a = 2, maxRounds: o = 256, signal: s } = {}) {
21
+ s?.throwIfAborted();
22
+ let c = {
23
+ pipelines: 0,
24
+ fallbacks: 0,
25
+ rounds: 0,
26
+ rebooted: !1
27
+ }, l = () => i.gpu, u = l(), d = i.canvas.getContext("webgpu");
28
+ if (!u || !d || i.backend !== "webgpu") return c;
29
+ let f = u.queue[e], p = Object.fromEntries(t.map((e) => [e, u[e]])), m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new Map(), y = [], b = /* @__PURE__ */ new Set(), x = !1, S = !1, C = "", w = 0, T, E, D = (e, t, n) => e + JSON.stringify(t, (e, t) => {
30
+ if (typeof t != "object" || !t || Array.isArray(t) || Object.getPrototypeOf(t) === Object.prototype) return t;
31
+ let r = h.get(t);
32
+ if (r !== void 0) return "module" + r;
33
+ let i = g.get(t);
34
+ return i === void 0 ? n ? "object" : (_.has(t) || _.set(t, w++), "object:" + _.get(t)) : "layout" + i;
35
+ }), O = (e) => function(t) {
36
+ if (!S) return p[e].call(this, t);
37
+ if (f) {
38
+ let n = D(e, t, !0);
39
+ return b.has(n) || (b.add(n), c.pipelines++, x = !0), p[e].call(this, t);
40
+ }
41
+ let r = D(e, t, !1), i = v.get(r);
42
+ if (i) return i;
43
+ let a = D(e, t, !0);
44
+ if (a === C) return C = "", c.fallbacks++, p[e].call(this, t);
45
+ throw C = a, c.pipelines++, T = this[e + "Async"].call(this, t).then((e) => {
46
+ v.set(r, e);
47
+ }, () => {}), new n(e);
48
+ }, k = [
49
+ r(u, "createRenderPipeline", O("createRenderPipeline")),
50
+ r(u, "createComputePipeline", O("createComputePipeline")),
51
+ r(u, "createShaderModule", function(e) {
52
+ let t = p.createShaderModule.call(this, e);
53
+ return m.has(e.code) || m.set(e.code, m.size), h.set(t, m.get(e.code)), t;
54
+ }),
55
+ r(u, "createBindGroupLayout", function(e) {
56
+ let t = p.createBindGroupLayout.call(this, e);
57
+ return g.set(t, D("createRenderPipeline", { entries: e.entries }, !1)), t;
58
+ }),
59
+ r(u, "createPipelineLayout", function(e) {
60
+ let t = p.createPipelineLayout.call(this, e);
61
+ return g.set(t, D("createRenderPipeline", { groups: e.bindGroupLayouts }, !1)), t;
62
+ }),
63
+ r(u, "createCommandEncoder", function(e) {
64
+ let t = p.createCommandEncoder.call(this, e);
65
+ if (!S || f) return t;
66
+ let n = { encoder: t };
67
+ y.push(n);
68
+ for (let e of ["beginRenderPass", "beginComputePass"]) {
69
+ let i = t[e];
70
+ r(t, e, (e) => {
71
+ let a = n.pass = i.call(t, e), o = a.end;
72
+ return r(a, "end", () => {
73
+ n.pass = void 0, o.call(a);
74
+ }), a;
75
+ });
76
+ }
77
+ let i = t.finish;
78
+ return r(t, "finish", (e) => (n.finished = !0, i.call(t, e))), t;
79
+ }),
80
+ r(d, "getCurrentTexture", function() {
81
+ if (!S) return GPUCanvasContext.prototype.getCurrentTexture.call(this);
82
+ let { width: e, height: t } = i.canvas, { format: n, usage: r = 16 } = d.getConfiguration();
83
+ return (E?.width !== e || E.height !== t || E.format !== n) && (E?.destroy(), E = u.createTexture({
84
+ size: [e, t],
85
+ format: n,
86
+ usage: r | 16
87
+ })), E;
88
+ })
89
+ ], A = () => {
90
+ for (let e of k.splice(0)) e();
91
+ };
92
+ try {
93
+ for (let e = 0; f && e < a && c.rounds < o && !i.disposed;) {
94
+ s?.throwIfAborted(), c.rounds++, x = !1, S = l() === u, f(!0);
95
+ try {
96
+ i.render({ delta: 0 });
97
+ } finally {
98
+ S = !1, f(!1);
99
+ }
100
+ await u.queue.onSubmittedWorkDone(), e = x ? 0 : e + 1;
101
+ }
102
+ for (let e = 0; !f && e < a && c.rounds < o && !i.disposed;) {
103
+ s?.throwIfAborted(), c.rounds++, T = void 0, y.length = 0, S = l() === u;
104
+ try {
105
+ i.render({ delta: 0 }), e++;
106
+ } catch (e) {
107
+ if (e instanceof n) {
108
+ u.pushErrorScope("validation");
109
+ let e = y.filter((e) => !e.finished).map((e) => (e.pass?.end(), e.encoder.finish()));
110
+ e.length && u.queue.submit(e), u.popErrorScope();
111
+ continue;
112
+ }
113
+ if (!c.pipelines || c.rebooted) throw e;
114
+ c.rebooted = !0, S = !1, A(), await i.rebootDevice();
115
+ } finally {
116
+ S = !1, T && await T;
117
+ }
118
+ }
119
+ i.disposed || await l()?.queue.onSubmittedWorkDone(), s?.throwIfAborted();
120
+ } finally {
121
+ A(), E?.destroy();
122
+ }
123
+ return c;
124
+ }
125
+ //#endregion
126
+ export { i as warmUp };
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "@margoengine/quality",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Measured quality tiers: start light, time the GPU, remember full 4x quality only where it has headroom.",
5
+ "keywords": [
6
+ "margoengine",
7
+ "webgpu",
8
+ "3d",
9
+ "quality"
10
+ ],
11
+ "homepage": "https://margoengine.com",
12
+ "bugs": {
13
+ "url": "https://github.com/scottcampbelldata/margoengine/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/scottcampbelldata/margoengine.git",
18
+ "directory": "packages/quality"
19
+ },
20
+ "license": "Apache-2.0",
21
+ "author": "Scott Campbell",
22
+ "type": "module",
23
+ "sideEffects": false,
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
29
+ "./warm": {
30
+ "types": "./dist/warm.d.ts",
31
+ "import": "./dist/warm.js"
32
+ },
33
+ "./ssaa": {
34
+ "types": "./dist/ssaa.d.ts",
35
+ "import": "./dist/ssaa.js"
36
+ },
37
+ "./features": {
38
+ "types": "./dist/features.d.ts",
39
+ "import": "./dist/features.js"
40
+ },
41
+ "./power": {
42
+ "types": "./dist/power.d.ts",
43
+ "import": "./dist/power.js"
44
+ },
45
+ "./demand": {
46
+ "types": "./dist/demand.d.ts",
47
+ "import": "./dist/demand.js"
48
+ },
49
+ "./events": {
50
+ "types": "./dist/events.d.ts",
51
+ "import": "./dist/events.js"
52
+ },
53
+ "./knobs": {
54
+ "types": "./dist/knobs.d.ts",
55
+ "import": "./dist/knobs.js"
56
+ }
57
+ },
58
+ "files": [
59
+ "dist",
60
+ "LICENSE",
61
+ "NOTICE"
62
+ ],
63
+ "publishConfig": {
64
+ "access": "public"
65
+ },
66
+ "peerDependencies": {
67
+ "@margoengine/core": "^1.0.0"
68
+ },
69
+ "scripts": {
70
+ "build": "node ../../scripts/build-optional.js quality",
71
+ "test": "npm run build && node --test test/*.test.js ../../examples/package-benchmarks/proofs/package-guard.mjs",
72
+ "test:gpu": "cd ../.. && node packages/quality/test/browser-check.mjs && node packages/quality/test/ssaa-browser.mjs && node packages/quality/test/features-browser.mjs && node packages/quality/test/power-browser.mjs && node packages/quality/test/scene-owner-browser.mjs && node packages/quality/test/demand-browser.mjs && node packages/quality/test/events-browser.mjs && node packages/quality/test/knobs-browser.mjs",
73
+ "prepack": "npm run build"
74
+ }
75
+ }