@motion-core/motion-gpu
Version:
Framework-agnostic WebGPU runtime for fullscreen WGSL shaders with explicit Svelte, React, and Vue adapter entrypoints.
63 lines (62 loc) • 2.48 kB
JavaScript
//#region src/lib/core/recompile-policy.ts
function isPlainRecord(value) {
return typeof value === "object" && value !== null;
}
function stableSignatureValue(value) {
if (value === void 0) return;
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
if (typeof value === "number") return Number.isNaN(value) ? "NaN" : value;
if (Array.isArray(value)) return value.map((entry) => stableSignatureValue(entry));
if (value instanceof Set) return Array.from(value).map((entry) => stableSignatureValue(entry)).sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
if (!isPlainRecord(value)) return String(value);
const normalized = {};
for (const key of Object.keys(value).sort((a, b) => a.localeCompare(b))) {
const next = stableSignatureValue(value[key]);
if (next !== void 0) normalized[key] = next;
}
return normalized;
}
function normalizeRequiredFeatures(features) {
if (features === void 0) return;
return Array.from(features).map((feature) => String(feature)).sort((a, b) => a.localeCompare(b));
}
function normalizeAdapterOptions(options) {
return stableSignatureValue(options ?? {});
}
function normalizeDeviceDescriptor(descriptor) {
if (!descriptor) return {};
const normalized = {};
const source = descriptor;
for (const key of Object.keys(source).sort((a, b) => a.localeCompare(b))) {
if (key === "requiredFeatures") continue;
const next = stableSignatureValue(source[key]);
if (next !== void 0) normalized[key] = next;
}
const requiredFeatures = normalizeRequiredFeatures(descriptor.requiredFeatures);
if (requiredFeatures !== void 0) normalized.requiredFeatures = requiredFeatures;
return normalized;
}
/**
* Returns deterministic renderer pipeline signature.
*
* Rebuild triggers:
* - material signature changes (shader/layout related)
* - color pipeline, output encoding, or HDR presentation options change
* - adapter request options or device descriptor changes
*
* Non-triggers:
* - runtime uniform values
* - runtime texture sources
* - clear color changes
*/
function buildRendererPipelineSignature(input) {
return JSON.stringify({
materialSignature: input.materialSignature,
color: stableSignatureValue(input.color ?? {}),
adapterOptions: normalizeAdapterOptions(input.adapterOptions),
deviceDescriptor: normalizeDeviceDescriptor(input.deviceDescriptor)
});
}
//#endregion
export { buildRendererPipelineSignature };
//# sourceMappingURL=recompile-policy.js.map