@plasius/gpu-shader 0.1.1 → 0.1.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 +14 -2
- package/dist/cli.cjs +209 -26
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +209 -26
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +237 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +236 -114
- package/dist/index.js.map +1 -1
- package/dist/node.cjs +115 -23
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +115 -23
- package/dist/node.js.map +1 -1
- package/dist/testing.cjs +89 -10
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.js +89 -10
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -583,6 +583,7 @@ ${canonicalizeGpuContract(core)}`
|
|
|
583
583
|
// src/contracts.ts
|
|
584
584
|
var GPU_INTERFACE_MANIFEST_VERSION = "1.0.0";
|
|
585
585
|
var SHADER_VERSION_MANIFEST_VERSION = "1.0.0";
|
|
586
|
+
var SHADER_STYLE_PROFILE_MANIFEST_VERSION = "1.0.0";
|
|
586
587
|
var SHADER_COMPILE_UNIT_VERSION = "1.0.0";
|
|
587
588
|
var SHADER_VALIDATION_EVIDENCE_VERSION = "1.0.0";
|
|
588
589
|
var STABLE_WEBGPU_MATRIX_VERSION = "1.0.0";
|
|
@@ -598,6 +599,29 @@ var SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES = [
|
|
|
598
599
|
Object.freeze(SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES);
|
|
599
600
|
var SUPPORTED_ADDITIVE_WEBGPU_MATRIX_POLICIES = Object.freeze([]);
|
|
600
601
|
|
|
602
|
+
// src/asset-version.ts
|
|
603
|
+
var ASSET_VERSION_PATTERN = /^[0-9A-Za-z][0-9A-Za-z._-]{0,127}$/u;
|
|
604
|
+
var MUTABLE_VERSION_ALIASES = /* @__PURE__ */ new Set([
|
|
605
|
+
"latest",
|
|
606
|
+
"current",
|
|
607
|
+
"stable",
|
|
608
|
+
"preview",
|
|
609
|
+
"default",
|
|
610
|
+
"production",
|
|
611
|
+
"canary",
|
|
612
|
+
"next",
|
|
613
|
+
"head",
|
|
614
|
+
"main"
|
|
615
|
+
]);
|
|
616
|
+
var X_WILDCARD_SEGMENT_PATTERN = /^(?:[vV])?[xX](?:\.|-|$)|\.[xX](?:\.|-|$)/u;
|
|
617
|
+
var IMMUTABLE_VERSION_ERROR_MESSAGE = "Immutable asset version must be an exact token up to 128 characters; mutable aliases, ranges, wildcards, and URLs are not allowed.";
|
|
618
|
+
function assertImmutableAssetVersion(value) {
|
|
619
|
+
if (typeof value !== "string" || !ASSET_VERSION_PATTERN.test(value) || MUTABLE_VERSION_ALIASES.has(value.toLowerCase()) || X_WILDCARD_SEGMENT_PATTERN.test(value)) {
|
|
620
|
+
throw new TypeError(IMMUTABLE_VERSION_ERROR_MESSAGE);
|
|
621
|
+
}
|
|
622
|
+
return value;
|
|
623
|
+
}
|
|
624
|
+
|
|
601
625
|
// src/requirements-validation.ts
|
|
602
626
|
var ENABLED_FEATURES = Object.freeze({
|
|
603
627
|
f16: "shader-f16",
|
|
@@ -925,6 +949,15 @@ function validateShaderDerivedRequirements(input) {
|
|
|
925
949
|
// src/manifest-validation.ts
|
|
926
950
|
var stages = ["vertex", "fragment", "compute"];
|
|
927
951
|
var roles = ["material", "lighting", "outline", "shadow", "post-processing"];
|
|
952
|
+
function detachedJson(value, path2) {
|
|
953
|
+
try {
|
|
954
|
+
return JSON.parse(canonicalizeGpuContract(value));
|
|
955
|
+
} catch (cause) {
|
|
956
|
+
const detail = cause instanceof Error ? cause.message : "Contract snapshot failed.";
|
|
957
|
+
const boundedDetail = [...detail].slice(0, 512).join("");
|
|
958
|
+
throw new TypeError(`${path2} must contain detached JSON contract data: ${boundedDetail}`, { cause });
|
|
959
|
+
}
|
|
960
|
+
}
|
|
928
961
|
function object(value, path2) {
|
|
929
962
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path2} must be an object.`);
|
|
930
963
|
return value;
|
|
@@ -945,6 +978,16 @@ function token(value, path2) {
|
|
|
945
978
|
if (!/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/u.test(result) || result.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
|
|
946
979
|
return result;
|
|
947
980
|
}
|
|
981
|
+
function immutableVersion(value, path2) {
|
|
982
|
+
try {
|
|
983
|
+
return assertImmutableAssetVersion(value);
|
|
984
|
+
} catch (cause) {
|
|
985
|
+
throw new TypeError(
|
|
986
|
+
`${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`,
|
|
987
|
+
{ cause }
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
948
991
|
function enumeration(value, values, path2) {
|
|
949
992
|
if (!values.includes(value)) throw new TypeError(`${path2} is invalid.`);
|
|
950
993
|
return value;
|
|
@@ -1218,7 +1261,7 @@ function interfaceRef(value, path2) {
|
|
|
1218
1261
|
const input = object(value, path2);
|
|
1219
1262
|
exact(input, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path2);
|
|
1220
1263
|
token(input.interfaceId, `${path2}.interfaceId`);
|
|
1221
|
-
|
|
1264
|
+
immutableVersion(input.interfaceVersion, `${path2}.interfaceVersion`);
|
|
1222
1265
|
uri(input.manifestUri, `${path2}.manifestUri`);
|
|
1223
1266
|
digest(input.manifestSha256, `${path2}.manifestSha256`);
|
|
1224
1267
|
digest(input.interfaceAbiHash, `${path2}.interfaceAbiHash`);
|
|
@@ -1356,7 +1399,7 @@ function pipeline(value, path2, moduleIds) {
|
|
|
1356
1399
|
return input;
|
|
1357
1400
|
}
|
|
1358
1401
|
function parseSerializableGpuPipelineDescriptors(value, moduleIds, path2 = "pipelines") {
|
|
1359
|
-
const parsed = array(value, path2).map((item, index) => pipeline(item, `${path2}[${index}]`, new Set(moduleIds)));
|
|
1402
|
+
const parsed = array(detachedJson(value, path2), path2).map((item, index) => pipeline(item, `${path2}[${index}]`, new Set(moduleIds)));
|
|
1360
1403
|
unique(parsed, (item) => item.pipelineId, path2);
|
|
1361
1404
|
return freeze(parsed);
|
|
1362
1405
|
}
|
|
@@ -1364,7 +1407,7 @@ function compatibleModel(value, path2) {
|
|
|
1364
1407
|
const input = object(value, path2);
|
|
1365
1408
|
exact(input, ["interfaceId", "interfaceVersion", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path2);
|
|
1366
1409
|
token(input.interfaceId, `${path2}.interfaceId`);
|
|
1367
|
-
|
|
1410
|
+
immutableVersion(input.interfaceVersion, `${path2}.interfaceVersion`);
|
|
1368
1411
|
digest(input.manifestSha256, `${path2}.manifestSha256`);
|
|
1369
1412
|
digest(input.interfaceAbiHash, `${path2}.interfaceAbiHash`);
|
|
1370
1413
|
digest(input.modelAbiHash, `${path2}.modelAbiHash`);
|
|
@@ -1377,7 +1420,7 @@ function validationEvidenceRef(value, path2) {
|
|
|
1377
1420
|
uri(evidence.uri, `${path2}.uri`);
|
|
1378
1421
|
digest(evidence.sha256, `${path2}.sha256`);
|
|
1379
1422
|
token(evidence.matrixId, `${path2}.matrixId`);
|
|
1380
|
-
|
|
1423
|
+
immutableVersion(evidence.matrixVersion, `${path2}.matrixVersion`);
|
|
1381
1424
|
digest(evidence.matrixSha256, `${path2}.matrixSha256`);
|
|
1382
1425
|
const attestation = object(evidence.attestationRef, `${path2}.attestationRef`);
|
|
1383
1426
|
exact(attestation, ["uri", "sha256"], `${path2}.attestationRef`);
|
|
@@ -1404,11 +1447,11 @@ function reflectedRecordBindingSize(record) {
|
|
|
1404
1447
|
return Math.ceil(unrounded / record.alignment) * record.alignment;
|
|
1405
1448
|
}
|
|
1406
1449
|
function parseGpuInterfaceManifest(value) {
|
|
1407
|
-
const input = object(value, "GpuInterfaceManifest");
|
|
1450
|
+
const input = object(detachedJson(value, "GpuInterfaceManifest"), "GpuInterfaceManifest");
|
|
1408
1451
|
exact(input, ["contractVersion", "interfaceId", "interfaceVersion", "modules", "records", "bindings", "entryPoints", "vertexInputs", "overrides", "modelAbi", "modelAbiHash", "interfaceAbiHash", "generatedBy"], "GpuInterfaceManifest");
|
|
1409
1452
|
if (input.contractVersion !== GPU_INTERFACE_MANIFEST_VERSION) throw new TypeError("Unsupported GPU interface contract version.");
|
|
1410
1453
|
token(input.interfaceId, "GpuInterfaceManifest.interfaceId");
|
|
1411
|
-
|
|
1454
|
+
immutableVersion(input.interfaceVersion, "GpuInterfaceManifest.interfaceVersion");
|
|
1412
1455
|
const moduleValues = array(input.modules, "GpuInterfaceManifest.modules");
|
|
1413
1456
|
if (moduleValues.length === 0) throw new TypeError("GpuInterfaceManifest.modules must not be empty.");
|
|
1414
1457
|
const moduleIds = moduleValues.map((value2, index) => {
|
|
@@ -1590,11 +1633,11 @@ function parseGpuInterfaceManifest(value) {
|
|
|
1590
1633
|
return freeze(input);
|
|
1591
1634
|
}
|
|
1592
1635
|
function parseShaderVersionManifest(value) {
|
|
1593
|
-
const input = object(value, "ShaderVersionManifest");
|
|
1636
|
+
const input = object(detachedJson(value, "ShaderVersionManifest"), "ShaderVersionManifest");
|
|
1594
1637
|
exact(input, ["contractVersion", "shaderId", "version", "modules", "gpuInterface", "pipelines", "renderRoles", "compatibleModelInterfaces", "requirements", "shaderAbiHash", "validationEvidence", "additionalValidationEvidence"], "ShaderVersionManifest");
|
|
1595
1638
|
if (input.contractVersion !== SHADER_VERSION_MANIFEST_VERSION) throw new TypeError("Unsupported shader manifest contract version.");
|
|
1596
1639
|
token(input.shaderId, "ShaderVersionManifest.shaderId");
|
|
1597
|
-
|
|
1640
|
+
immutableVersion(input.version, "ShaderVersionManifest.version");
|
|
1598
1641
|
const moduleValues = array(input.modules, "ShaderVersionManifest.modules");
|
|
1599
1642
|
if (moduleValues.length === 0) throw new TypeError("ShaderVersionManifest.modules must not be empty.");
|
|
1600
1643
|
const moduleIds = moduleValues.map((item, index) => {
|
|
@@ -1707,7 +1750,7 @@ function parseShaderVersionManifest(value) {
|
|
|
1707
1750
|
return freeze(input);
|
|
1708
1751
|
}
|
|
1709
1752
|
function parseShaderVersionManifestCore(value) {
|
|
1710
|
-
const input = object(value, "ShaderVersionManifestCore");
|
|
1753
|
+
const input = object(detachedJson(value, "ShaderVersionManifestCore"), "ShaderVersionManifestCore");
|
|
1711
1754
|
if ("validationEvidence" in input || "additionalValidationEvidence" in input) {
|
|
1712
1755
|
throw new TypeError("ShaderVersionManifestCore must not contain validationEvidence or additionalValidationEvidence.");
|
|
1713
1756
|
}
|
|
@@ -1732,11 +1775,59 @@ function parseShaderVersionManifestCore(value) {
|
|
|
1732
1775
|
void additionalValidationEvidence;
|
|
1733
1776
|
return freeze(core);
|
|
1734
1777
|
}
|
|
1778
|
+
function parseShaderStyleProfileManifest(value) {
|
|
1779
|
+
const input = object(detachedJson(value, "ShaderStyleProfileManifest"), "ShaderStyleProfileManifest");
|
|
1780
|
+
exact(input, ["contractVersion", "profileId", "version", "style", "roles", "compatibleModelInterfaces", "requiredSemantics", "requiredValidationScopes"], "ShaderStyleProfileManifest");
|
|
1781
|
+
if (input.contractVersion !== SHADER_STYLE_PROFILE_MANIFEST_VERSION) throw new TypeError("Unsupported style-profile contract version.");
|
|
1782
|
+
token(input.profileId, "ShaderStyleProfileManifest.profileId");
|
|
1783
|
+
immutableVersion(input.version, "ShaderStyleProfileManifest.version");
|
|
1784
|
+
token(input.style, "ShaderStyleProfileManifest.style");
|
|
1785
|
+
const roleValues = array(input.roles, "ShaderStyleProfileManifest.roles", 5);
|
|
1786
|
+
if (roleValues.length === 0) throw new TypeError("ShaderStyleProfileManifest.roles must not be empty.");
|
|
1787
|
+
const roleNames = [];
|
|
1788
|
+
roleValues.forEach((item, index) => {
|
|
1789
|
+
const path2 = `ShaderStyleProfileManifest.roles[${index}]`;
|
|
1790
|
+
const role = object(item, path2);
|
|
1791
|
+
exact(role, ["role", "shader"], path2);
|
|
1792
|
+
roleNames.push(enumeration(role.role, roles, `${path2}.role`));
|
|
1793
|
+
const shader = object(role.shader, `${path2}.shader`);
|
|
1794
|
+
exact(shader, ["shaderId", "version", "manifestUri", "manifestSha256"], `${path2}.shader`);
|
|
1795
|
+
token(shader.shaderId, `${path2}.shader.shaderId`);
|
|
1796
|
+
immutableVersion(shader.version, `${path2}.shader.version`);
|
|
1797
|
+
uri(shader.manifestUri, `${path2}.shader.manifestUri`);
|
|
1798
|
+
digest(shader.manifestSha256, `${path2}.shader.manifestSha256`);
|
|
1799
|
+
});
|
|
1800
|
+
unique(roleNames, String, "ShaderStyleProfileManifest.roles");
|
|
1801
|
+
const compatible = array(input.compatibleModelInterfaces, "ShaderStyleProfileManifest.compatibleModelInterfaces").map((item, index) => compatibleModel(item, `ShaderStyleProfileManifest.compatibleModelInterfaces[${index}]`));
|
|
1802
|
+
if (compatible.length === 0) throw new TypeError("ShaderStyleProfileManifest.compatibleModelInterfaces must not be empty.");
|
|
1803
|
+
unique(compatible, (item) => `${item.interfaceId}:${item.interfaceVersion}:${item.manifestSha256}:${item.interfaceAbiHash}:${item.modelAbiHash}`, "ShaderStyleProfileManifest.compatibleModelInterfaces");
|
|
1804
|
+
tokenArray(input.requiredSemantics, "ShaderStyleProfileManifest.requiredSemantics");
|
|
1805
|
+
const requiredValidationScopes = array(input.requiredValidationScopes, "ShaderStyleProfileManifest.requiredValidationScopes").map((item, index) => {
|
|
1806
|
+
const path2 = `ShaderStyleProfileManifest.requiredValidationScopes[${index}]`;
|
|
1807
|
+
const requirement = object(item, path2);
|
|
1808
|
+
exact(requirement, ["scope", "matrixId", "matrixVersion", "matrixSha256"], path2);
|
|
1809
|
+
const scope = token(requirement.scope, `${path2}.scope`);
|
|
1810
|
+
if (scope === "universal") throw new TypeError(`${path2}.scope must not use the reserved universal scope.`);
|
|
1811
|
+
token(requirement.matrixId, `${path2}.matrixId`);
|
|
1812
|
+
immutableVersion(requirement.matrixVersion, `${path2}.matrixVersion`);
|
|
1813
|
+
const matrixSha256 = digest(requirement.matrixSha256, `${path2}.matrixSha256`);
|
|
1814
|
+
if (SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES.some((policy) => policy.matrixSha256 === matrixSha256)) {
|
|
1815
|
+
throw new TypeError(`${path2} must require an additive matrix policy, not the universal matrix policy.`);
|
|
1816
|
+
}
|
|
1817
|
+
if (!SUPPORTED_ADDITIVE_WEBGPU_MATRIX_POLICIES.some((policy) => scope === policy.scope && requirement.matrixId === policy.matrixId && requirement.matrixVersion === policy.matrixVersion && matrixSha256 === policy.matrixSha256)) {
|
|
1818
|
+
throw new TypeError(`${path2} is not a supported additive WebGPU matrix policy.`);
|
|
1819
|
+
}
|
|
1820
|
+
return requirement;
|
|
1821
|
+
});
|
|
1822
|
+
unique(requiredValidationScopes, (item) => String(item.scope), "ShaderStyleProfileManifest.requiredValidationScopes scopes");
|
|
1823
|
+
unique(requiredValidationScopes, (item) => String(item.matrixSha256), "ShaderStyleProfileManifest.requiredValidationScopes matrix policies");
|
|
1824
|
+
return freeze(input);
|
|
1825
|
+
}
|
|
1735
1826
|
function parseModelGpuCompatibilityDescriptor(value) {
|
|
1736
|
-
const input = object(value, "ModelGpuCompatibilityDescriptor");
|
|
1827
|
+
const input = object(detachedJson(value, "ModelGpuCompatibilityDescriptor"), "ModelGpuCompatibilityDescriptor");
|
|
1737
1828
|
exact(input, ["modelId", "version", "gpuInterface", "modelAbiHash", "providedSemantics", "defaultStyleProfile"], "ModelGpuCompatibilityDescriptor");
|
|
1738
1829
|
token(input.modelId, "ModelGpuCompatibilityDescriptor.modelId");
|
|
1739
|
-
|
|
1830
|
+
immutableVersion(input.version, "ModelGpuCompatibilityDescriptor.version");
|
|
1740
1831
|
const gpuInterface = interfaceRef(input.gpuInterface, "ModelGpuCompatibilityDescriptor.gpuInterface");
|
|
1741
1832
|
const modelAbiHash = digest(input.modelAbiHash, "ModelGpuCompatibilityDescriptor.modelAbiHash");
|
|
1742
1833
|
if (gpuInterface.modelAbiHash !== modelAbiHash) throw new TypeError("ModelGpuCompatibilityDescriptor.gpuInterface.modelAbiHash differs from modelAbiHash.");
|
|
@@ -1745,14 +1836,17 @@ function parseModelGpuCompatibilityDescriptor(value) {
|
|
|
1745
1836
|
const profile = object(input.defaultStyleProfile, "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
|
|
1746
1837
|
exact(profile, ["profileId", "version", "manifestUri", "manifestSha256"], "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
|
|
1747
1838
|
token(profile.profileId, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.profileId");
|
|
1748
|
-
|
|
1839
|
+
immutableVersion(profile.version, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.version");
|
|
1749
1840
|
uri(profile.manifestUri, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestUri");
|
|
1750
1841
|
digest(profile.manifestSha256, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestSha256");
|
|
1751
1842
|
}
|
|
1752
1843
|
return freeze(input);
|
|
1753
1844
|
}
|
|
1754
1845
|
function parseShaderQualificationModelCompatibilityFixture(value) {
|
|
1755
|
-
const input = object(
|
|
1846
|
+
const input = object(
|
|
1847
|
+
detachedJson(value, "ShaderQualificationModelCompatibilityFixture"),
|
|
1848
|
+
"ShaderQualificationModelCompatibilityFixture"
|
|
1849
|
+
);
|
|
1756
1850
|
exact(input, ["contractVersion", "fixtureId", "model"], "ShaderQualificationModelCompatibilityFixture");
|
|
1757
1851
|
if (input.contractVersion !== SHADER_QUALIFICATION_FIXTURE_VERSION) throw new TypeError("Unsupported model compatibility fixture version.");
|
|
1758
1852
|
token(input.fixtureId, "ShaderQualificationModelCompatibilityFixture.fixtureId");
|
|
@@ -1768,6 +1862,11 @@ function issue(code, message, path2) {
|
|
|
1768
1862
|
function object2(value) {
|
|
1769
1863
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
1770
1864
|
}
|
|
1865
|
+
function freezeJson(value) {
|
|
1866
|
+
if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
|
|
1867
|
+
for (const child of Object.values(value)) freezeJson(child);
|
|
1868
|
+
return Object.freeze(value);
|
|
1869
|
+
}
|
|
1771
1870
|
function exactKeys(value, keys2) {
|
|
1772
1871
|
const expected = new Set(keys2);
|
|
1773
1872
|
return Object.keys(value).every((key) => expected.has(key)) && keys2.every((key) => key in value);
|
|
@@ -1775,6 +1874,14 @@ function exactKeys(value, keys2) {
|
|
|
1775
1874
|
function safeToken(value) {
|
|
1776
1875
|
return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,159}$/u.test(value) && !value.includes("..");
|
|
1777
1876
|
}
|
|
1877
|
+
function immutableVersion2(value) {
|
|
1878
|
+
try {
|
|
1879
|
+
assertImmutableAssetVersion(value);
|
|
1880
|
+
return true;
|
|
1881
|
+
} catch {
|
|
1882
|
+
return false;
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1778
1885
|
function validSha(value) {
|
|
1779
1886
|
try {
|
|
1780
1887
|
asSha256Hex(String(value));
|
|
@@ -1784,8 +1891,20 @@ function validSha(value) {
|
|
|
1784
1891
|
}
|
|
1785
1892
|
}
|
|
1786
1893
|
function validateCompileUnitInventory(value) {
|
|
1787
|
-
|
|
1788
|
-
|
|
1894
|
+
let snapshot;
|
|
1895
|
+
try {
|
|
1896
|
+
snapshot = JSON.parse(canonicalizeGpuContract(value));
|
|
1897
|
+
} catch (cause) {
|
|
1898
|
+
return {
|
|
1899
|
+
ok: false,
|
|
1900
|
+
diagnostics: [issue(
|
|
1901
|
+
"invalid-contract",
|
|
1902
|
+
cause instanceof Error ? cause.message : "Compile-unit inventory must contain detached JSON data."
|
|
1903
|
+
)]
|
|
1904
|
+
};
|
|
1905
|
+
}
|
|
1906
|
+
const envelope = object2(snapshot);
|
|
1907
|
+
const candidate = envelope && Object.hasOwn(envelope, "inventory") ? object2(snapshot.inventory) : envelope;
|
|
1789
1908
|
const diagnostics = [];
|
|
1790
1909
|
if (!candidate || !exactKeys(candidate, ["contractVersion", "fragments", "compileUnits"])) {
|
|
1791
1910
|
return { ok: false, diagnostics: [issue("invalid-contract", "Compile-unit inventory has unknown or missing fields.")] };
|
|
@@ -1916,7 +2035,7 @@ function validateCompileUnitInventory(value) {
|
|
|
1916
2035
|
diagnostics.push(issue("invalid-contract", cause instanceof Error ? cause.message : "Compile-unit pipelines are invalid.", `${path2}.pipelines`));
|
|
1917
2036
|
}
|
|
1918
2037
|
const interfaceRef2 = object2(unit.interfaceRef);
|
|
1919
|
-
if (!interfaceRef2 || !exactKeys(interfaceRef2, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"]) || !safeToken(interfaceRef2.interfaceId) || !
|
|
2038
|
+
if (!interfaceRef2 || !exactKeys(interfaceRef2, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"]) || !safeToken(interfaceRef2.interfaceId) || !immutableVersion2(interfaceRef2.interfaceVersion) || typeof interfaceRef2.manifestUri !== "string" || !interfaceRef2.manifestUri.startsWith("https://") || !validSha(interfaceRef2.manifestSha256) || !validSha(interfaceRef2.interfaceAbiHash) || !validSha(interfaceRef2.modelAbiHash)) {
|
|
1920
2039
|
diagnostics.push(issue("invalid-contract", "Compile-unit interfaceRef is invalid.", `${path2}.interfaceRef`));
|
|
1921
2040
|
}
|
|
1922
2041
|
const fixture = object2(unit.qualificationFixture);
|
|
@@ -1927,7 +2046,7 @@ function validateCompileUnitInventory(value) {
|
|
|
1927
2046
|
for (const fragmentId of fragmentIds) {
|
|
1928
2047
|
if (!covered.has(fragmentId)) diagnostics.push(issue("uncovered-fragment", `WGSL fragment ${fragmentId} has no compile unit.`));
|
|
1929
2048
|
}
|
|
1930
|
-
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: candidate };
|
|
2049
|
+
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: freezeJson(candidate) };
|
|
1931
2050
|
}
|
|
1932
2051
|
|
|
1933
2052
|
// src/testing/qualification-bundle.ts
|
|
@@ -2019,6 +2138,18 @@ function object3(value, path2) {
|
|
|
2019
2138
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path2} must be an object.`);
|
|
2020
2139
|
return value;
|
|
2021
2140
|
}
|
|
2141
|
+
function detachedJson2(value, label) {
|
|
2142
|
+
try {
|
|
2143
|
+
return JSON.parse(canonicalizeGpuContract(value));
|
|
2144
|
+
} catch (cause) {
|
|
2145
|
+
throw new TypeError(`${label} must contain detached JSON contract data.`, { cause });
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
function freezeJson2(value) {
|
|
2149
|
+
if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
|
|
2150
|
+
for (const child of Object.values(value)) freezeJson2(child);
|
|
2151
|
+
return Object.freeze(value);
|
|
2152
|
+
}
|
|
2022
2153
|
function exact2(value, keys2, path2) {
|
|
2023
2154
|
const expected = new Set(keys2);
|
|
2024
2155
|
if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => key in value)) throw new TypeError(`${path2} has unknown or missing fields.`);
|
|
@@ -2027,6 +2158,16 @@ function token2(value, path2) {
|
|
|
2027
2158
|
if (typeof value !== "string" || !TOKEN.test(value) || value.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
|
|
2028
2159
|
return value;
|
|
2029
2160
|
}
|
|
2161
|
+
function immutableVersion3(value, path2) {
|
|
2162
|
+
try {
|
|
2163
|
+
return assertImmutableAssetVersion(value);
|
|
2164
|
+
} catch (cause) {
|
|
2165
|
+
throw new TypeError(
|
|
2166
|
+
`${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`,
|
|
2167
|
+
{ cause }
|
|
2168
|
+
);
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2030
2171
|
function path(value, label, extensions) {
|
|
2031
2172
|
if (typeof value !== "string" || !SAFE_PATH2.test(value) || !extensions.some((extension) => value.endsWith(extension))) {
|
|
2032
2173
|
throw new TypeError(`${label} must be a safe data-only bundle path (${extensions.join(", ")}).`);
|
|
@@ -2161,7 +2302,7 @@ function jsonValue(value, label, depth = 0) {
|
|
|
2161
2302
|
}
|
|
2162
2303
|
function validateQualificationFixture(value, unit) {
|
|
2163
2304
|
try {
|
|
2164
|
-
const fixture = object3(value, "fixture");
|
|
2305
|
+
const fixture = object3(detachedJson2(value, "fixture"), "fixture");
|
|
2165
2306
|
exact2(fixture, ["contractVersion", "fixtureId", "resources", "bindGroups", "commands", "layoutProbes", "readbacks", "bounds"], "fixture");
|
|
2166
2307
|
if (fixture.contractVersion !== SHADER_QUALIFICATION_FIXTURE_VERSION) throw new TypeError("Unsupported qualification fixture version.");
|
|
2167
2308
|
token2(fixture.fixtureId, "fixture.fixtureId");
|
|
@@ -2497,14 +2638,14 @@ function validateQualificationFixture(value, unit) {
|
|
|
2497
2638
|
}
|
|
2498
2639
|
unique2(probeIds, "fixture.layoutProbes probe IDs");
|
|
2499
2640
|
unique2(probeSources, "fixture.layoutProbes model sources");
|
|
2500
|
-
return { ok: true, value: fixture };
|
|
2641
|
+
return { ok: true, value: freezeJson2(fixture) };
|
|
2501
2642
|
} catch (cause) {
|
|
2502
2643
|
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification fixture." }] };
|
|
2503
2644
|
}
|
|
2504
2645
|
}
|
|
2505
2646
|
function validateQualificationBundleManifest(value) {
|
|
2506
2647
|
try {
|
|
2507
|
-
const bundle = object3(value, "qualification");
|
|
2648
|
+
const bundle = object3(detachedJson2(value, "qualification"), "qualification");
|
|
2508
2649
|
exact2(bundle, ["contractVersion", "inventory", "subject", "shaderManifestCorePath", "gpuInterfaceManifest", "modelCompatibilityFixtures", "modules", "fixtures"], "qualification");
|
|
2509
2650
|
if (bundle.contractVersion !== SHADER_QUALIFICATION_BUNDLE_VERSION) throw new TypeError("Unsupported qualification bundle version.");
|
|
2510
2651
|
const inventory = validateCompileUnitInventory(bundle.inventory);
|
|
@@ -2514,7 +2655,7 @@ function validateQualificationBundleManifest(value) {
|
|
|
2514
2655
|
const candidate = object3(subject.shaderManifestCore, "qualification.subject.shaderManifestCore");
|
|
2515
2656
|
exact2(candidate, ["shaderId", "version", "sha256"], "qualification.subject.shaderManifestCore");
|
|
2516
2657
|
token2(candidate.shaderId, "qualification.subject.shaderManifestCore.shaderId");
|
|
2517
|
-
|
|
2658
|
+
immutableVersion3(candidate.version, "qualification.subject.shaderManifestCore.version");
|
|
2518
2659
|
sha(candidate.sha256, "qualification.subject.shaderManifestCore.sha256");
|
|
2519
2660
|
path(bundle.shaderManifestCorePath, "qualification.shaderManifestCorePath", [".json"]);
|
|
2520
2661
|
const interfaceManifest = object3(bundle.gpuInterfaceManifest, "qualification.gpuInterfaceManifest");
|
|
@@ -2574,7 +2715,7 @@ function validateQualificationBundleManifest(value) {
|
|
|
2574
2715
|
const expectedUnits = [...inventory.value.compileUnits.map((unit) => unit.compileUnitId)].sort();
|
|
2575
2716
|
if (unitIds.join("\n") !== expectedUnits.join("\n")) throw new TypeError("Subject compile-unit IDs differ from inventory.");
|
|
2576
2717
|
orderedUniqueTokens(subject.requiredCellIds, "qualification.subject.requiredCellIds");
|
|
2577
|
-
return { ok: true, value: bundle };
|
|
2718
|
+
return { ok: true, value: freezeJson2(bundle) };
|
|
2578
2719
|
} catch (cause) {
|
|
2579
2720
|
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification bundle." }] };
|
|
2580
2721
|
}
|
|
@@ -8703,7 +8844,7 @@ function validatePipelineInterfaces(input) {
|
|
|
8703
8844
|
// package.json
|
|
8704
8845
|
var package_default = {
|
|
8705
8846
|
name: "@plasius/gpu-shader",
|
|
8706
|
-
version: "0.1.
|
|
8847
|
+
version: "0.1.2",
|
|
8707
8848
|
description: "Reflection-first WebGPU WGSL interfaces, CPU codecs, compatibility validation, style profiles, and qualification tooling",
|
|
8708
8849
|
type: "module",
|
|
8709
8850
|
sideEffects: false,
|
|
@@ -11954,11 +12095,21 @@ function verifyReflectedLayoutProbeOutputs(input) {
|
|
|
11954
12095
|
|
|
11955
12096
|
// src/compatibility.ts
|
|
11956
12097
|
function error(code, message, path2) {
|
|
11957
|
-
|
|
12098
|
+
const bounded = [...message].map((character) => {
|
|
12099
|
+
const codePoint = character.codePointAt(0);
|
|
12100
|
+
return codePoint <= 31 || codePoint === 127 ? " " : character;
|
|
12101
|
+
}).slice(0, 512).join("");
|
|
12102
|
+
return { code, severity: "error", message: bounded, ...path2 ? { path: path2 } : {} };
|
|
11958
12103
|
}
|
|
11959
12104
|
function interfaceMatches(item, model) {
|
|
11960
12105
|
return item.interfaceId === model.gpuInterface.interfaceId && item.interfaceVersion === model.gpuInterface.interfaceVersion && item.manifestSha256 === model.gpuInterface.manifestSha256 && item.interfaceAbiHash === model.gpuInterface.interfaceAbiHash && item.modelAbiHash === model.modelAbiHash;
|
|
11961
12106
|
}
|
|
12107
|
+
function detachedContract(value) {
|
|
12108
|
+
return JSON.parse(canonicalizeGpuContract(value));
|
|
12109
|
+
}
|
|
12110
|
+
function hasValidationEvidence(value) {
|
|
12111
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && (Object.hasOwn(value, "validationEvidence") || Object.hasOwn(value, "additionalValidationEvidence"));
|
|
12112
|
+
}
|
|
11962
12113
|
function validateRequirements(shader, gpuInterface, model, capabilities, diagnostics) {
|
|
11963
12114
|
const semantics = new Set(model.providedSemantics);
|
|
11964
12115
|
const requiredSemantics = /* @__PURE__ */ new Set([
|
|
@@ -11997,7 +12148,31 @@ function validateRequirements(shader, gpuInterface, model, capabilities, diagnos
|
|
|
11997
12148
|
}
|
|
11998
12149
|
function validateModelShaderCompatibility(input) {
|
|
11999
12150
|
const diagnostics = [];
|
|
12000
|
-
|
|
12151
|
+
let model;
|
|
12152
|
+
let shader;
|
|
12153
|
+
let gpuInterface;
|
|
12154
|
+
let profile;
|
|
12155
|
+
let capabilities;
|
|
12156
|
+
try {
|
|
12157
|
+
const modelSnapshot = detachedContract(input.model);
|
|
12158
|
+
const shaderSnapshot = detachedContract(input.shader);
|
|
12159
|
+
const gpuInterfaceSnapshot = detachedContract(input.gpuInterface);
|
|
12160
|
+
const profileValue = input.profile;
|
|
12161
|
+
const profileSnapshot = profileValue === void 0 ? void 0 : detachedContract(profileValue);
|
|
12162
|
+
model = parseModelGpuCompatibilityDescriptor(modelSnapshot);
|
|
12163
|
+
shader = hasValidationEvidence(shaderSnapshot) ? parseShaderVersionManifest(shaderSnapshot) : parseShaderVersionManifestCore(shaderSnapshot);
|
|
12164
|
+
gpuInterface = parseGpuInterfaceManifest(gpuInterfaceSnapshot);
|
|
12165
|
+
profile = profileSnapshot === void 0 ? void 0 : parseShaderStyleProfileManifest(profileSnapshot);
|
|
12166
|
+
capabilities = input.capabilities;
|
|
12167
|
+
} catch (cause) {
|
|
12168
|
+
return {
|
|
12169
|
+
ok: false,
|
|
12170
|
+
diagnostics: [error(
|
|
12171
|
+
"invalid-contract",
|
|
12172
|
+
cause instanceof Error ? cause.message : "GPU compatibility contract snapshot failed."
|
|
12173
|
+
)]
|
|
12174
|
+
};
|
|
12175
|
+
}
|
|
12001
12176
|
try {
|
|
12002
12177
|
validateShaderInterfaceRequirements({ manifest: shader, gpuInterface });
|
|
12003
12178
|
} catch (cause) {
|
|
@@ -12027,7 +12202,15 @@ function validateModelShaderCompatibility(input) {
|
|
|
12027
12202
|
}
|
|
12028
12203
|
}
|
|
12029
12204
|
}
|
|
12030
|
-
|
|
12205
|
+
try {
|
|
12206
|
+
validateRequirements(shader, gpuInterface, model, capabilities, diagnostics);
|
|
12207
|
+
} catch (cause) {
|
|
12208
|
+
diagnostics.push(error(
|
|
12209
|
+
"invalid-contract",
|
|
12210
|
+
cause instanceof Error ? cause.message : "GPU capability snapshot validation failed.",
|
|
12211
|
+
"capabilities"
|
|
12212
|
+
));
|
|
12213
|
+
}
|
|
12031
12214
|
if (diagnostics.length > 0) return { ok: false, diagnostics };
|
|
12032
12215
|
return {
|
|
12033
12216
|
ok: true,
|