@margoengine/quality 0.0.0-stage → 0.1.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 0.1.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("0.1.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 0.1.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+ const t=(engine,version="0.1.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,39 @@
1
+ import type { EngineKernel } from '@margoengine/core';
2
+ /** What {@link warmUp} did. */
3
+ export interface WarmUpReport {
4
+ /** Render and compute pipelines created with the async API ahead of their first visible frame. */
5
+ pipelines: number;
6
+ /** Pipelines that had to be created synchronously after all (the retried call did not match its warmed descriptor). */
7
+ fallbacks: number;
8
+ /** Warm render calls, including the stopped ones that discovered a pipeline. */
9
+ rounds: number;
10
+ /** A feature failed after a stopped warm frame, so the device was restored (`engine.rebootDevice()`) and the
11
+ * remaining warm frames created their pipelines synchronously. */
12
+ rebooted: boolean;
13
+ }
14
+ /** Options for {@link warmUp}. */
15
+ export interface WarmUpOptions {
16
+ /** Complete warm frames to render once no new pipeline is found; the second catches history-dependent variants. Default 2. */
17
+ frames?: number;
18
+ /** Safety cap on warm render calls. Default 256. */
19
+ maxRounds?: number;
20
+ /** Stops the warm-up: the promise rejects with `signal.reason` and the device is left unpatched. */
21
+ signal?: AbortSignal;
22
+ }
23
+ /**
24
+ * Create the GPU pipelines of every attached feature with the async WebGPU API, so their first visible frame does not
25
+ * stall on shader compilation. Call during loading, after attaching features and adding the scene and before
26
+ * `engine.start()`. Features create pipelines lazily inside their passes, so warmUp renders warm frames (delta 0) into
27
+ * an offscreen target (nothing is presented): when a frame reaches a pipeline that does not exist yet, the frame is
28
+ * stopped there (an exception out of the synchronous create call), the work it already encoded is submitted (one-time
29
+ * work such as lookup tables and static shadow casters stays done), the pipeline compiles with
30
+ * `createRenderPipelineAsync` / `createComputePipelineAsync`, and the frame is rendered again until one completes; the
31
+ * retried call is answered with the finished pipeline. Frames rendered meanwhile by the engine's own loop are
32
+ * untouched. It resolves once the GPU has finished the warm frames, so pipelines a feature created synchronously at
33
+ * attach have compiled by then too. Without WebGPU it resolves at once. A feature that stores state before creating its pipeline (so the
34
+ * retry skips the creation) fails on the retry; then every feature is reset through device restoration and the warm
35
+ * frames finish with synchronous creation (`report.rebooted`).
36
+ * ponytail: a feature that is off (`enabled = false`) or attached later is not warmed; call warmUp again after
37
+ * attaching it.
38
+ */
39
+ export declare function warmUp(engine: EngineKernel, { frames, maxRounds, signal }?: WarmUpOptions): Promise<WarmUpReport>;
package/dist/warm.js ADDED
@@ -0,0 +1,101 @@
1
+ //#region src/warm.ts
2
+ var e = [
3
+ "createRenderPipeline",
4
+ "createComputePipeline",
5
+ "createShaderModule",
6
+ "createCommandEncoder"
7
+ ], t = class extends Error {};
8
+ function n(e, t, n) {
9
+ let r = Object.getOwnPropertyDescriptor(e, t);
10
+ return Object.defineProperty(e, t, {
11
+ configurable: !0,
12
+ writable: !0,
13
+ value: n
14
+ }), () => {
15
+ r ? Object.defineProperty(e, t, r) : delete e[t];
16
+ };
17
+ }
18
+ async function r(r, { frames: i = 2, maxRounds: a = 256, signal: o } = {}) {
19
+ o?.throwIfAborted();
20
+ let s = {
21
+ pipelines: 0,
22
+ fallbacks: 0,
23
+ rounds: 0,
24
+ rebooted: !1
25
+ }, c = () => r.gpu, l = c(), u = r.canvas.getContext("webgpu");
26
+ if (!l || !u || r.backend !== "webgpu") return s;
27
+ let d = Object.fromEntries(e.map((e) => [e, l[e]])), f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new Map(), g = [], _ = !1, v = "", y = 0, b, x, S = (e, t, n) => e + JSON.stringify(t, (e, t) => {
28
+ if (typeof t != "object" || !t || Array.isArray(t) || Object.getPrototypeOf(t) === Object.prototype) return t;
29
+ let r = p.get(t);
30
+ return r === void 0 ? n ? "object" : (m.has(t) || m.set(t, y++), "object:" + m.get(t)) : "module" + r;
31
+ }), C = (e) => function(n) {
32
+ if (!_) return d[e].call(this, n);
33
+ let r = S(e, n, !1), i = h.get(r);
34
+ if (i) return i;
35
+ let a = S(e, n, !0);
36
+ if (a === v) return v = "", s.fallbacks++, d[e].call(this, n);
37
+ throw v = a, s.pipelines++, b = this[e + "Async"].call(this, n).then((e) => {
38
+ h.set(r, e);
39
+ }, () => {}), new t(e);
40
+ }, w = [
41
+ n(l, "createRenderPipeline", C("createRenderPipeline")),
42
+ n(l, "createComputePipeline", C("createComputePipeline")),
43
+ n(l, "createShaderModule", function(e) {
44
+ let t = d.createShaderModule.call(this, e);
45
+ return f.has(e.code) || f.set(e.code, f.size), p.set(t, f.get(e.code)), t;
46
+ }),
47
+ n(l, "createCommandEncoder", function(e) {
48
+ let t = d.createCommandEncoder.call(this, e);
49
+ if (!_) return t;
50
+ let r = { encoder: t };
51
+ g.push(r);
52
+ for (let e of ["beginRenderPass", "beginComputePass"]) {
53
+ let i = t[e];
54
+ n(t, e, (e) => {
55
+ let a = r.pass = i.call(t, e), o = a.end;
56
+ return n(a, "end", () => {
57
+ r.pass = void 0, o.call(a);
58
+ }), a;
59
+ });
60
+ }
61
+ let i = t.finish;
62
+ return n(t, "finish", (e) => (r.finished = !0, i.call(t, e))), t;
63
+ }),
64
+ n(u, "getCurrentTexture", function() {
65
+ if (!_) return GPUCanvasContext.prototype.getCurrentTexture.call(this);
66
+ let { width: e, height: t } = r.canvas, { format: n, usage: i = 16 } = u.getConfiguration();
67
+ return (x?.width !== e || x.height !== t || x.format !== n) && (x?.destroy(), x = l.createTexture({
68
+ size: [e, t],
69
+ format: n,
70
+ usage: i | 16
71
+ })), x;
72
+ })
73
+ ], T = () => {
74
+ for (let e of w.splice(0)) e();
75
+ };
76
+ try {
77
+ for (let e = 0; e < i && s.rounds < a && !r.disposed;) {
78
+ o?.throwIfAborted(), s.rounds++, b = void 0, g.length = 0, _ = c() === l;
79
+ try {
80
+ r.render({ delta: 0 }), e++;
81
+ } catch (e) {
82
+ if (e instanceof t) {
83
+ l.pushErrorScope("validation");
84
+ let e = g.filter((e) => !e.finished).map((e) => (e.pass?.end(), e.encoder.finish()));
85
+ e.length && l.queue.submit(e), l.popErrorScope();
86
+ continue;
87
+ }
88
+ if (!s.pipelines || s.rebooted) throw e;
89
+ s.rebooted = !0, _ = !1, T(), await r.rebootDevice();
90
+ } finally {
91
+ _ = !1, b && await b;
92
+ }
93
+ }
94
+ r.disposed || await c()?.queue.onSubmittedWorkDone(), o?.throwIfAborted();
95
+ } finally {
96
+ T(), x?.destroy();
97
+ }
98
+ return s;
99
+ }
100
+ //#endregion
101
+ export { r as warmUp };
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
- {
2
- "name": "@margoengine/quality",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@margoengine/quality",
3
+ "version": "0.1.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": "^0.1.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
+ }