@plasius/gpu-shader 0.1.1 → 0.1.3
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 +50 -2
- package/dist/cli.cjs +539 -143
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +539 -143
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +738 -218
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.js +737 -218
- package/dist/index.js.map +1 -1
- package/dist/node.cjs +329 -86
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +329 -86
- package/dist/node.js.map +1 -1
- package/dist/testing.cjs +436 -115
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.js +436 -115
- package/dist/testing.js.map +1 -1
- package/package.json +2 -1
package/dist/cli.cjs
CHANGED
|
@@ -34,63 +34,244 @@ var import_promises = require("fs/promises");
|
|
|
34
34
|
var import_node_path = require("path");
|
|
35
35
|
|
|
36
36
|
// src/canonical-json.ts
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
var GPU_CONTRACT_SNAPSHOT_LIMITS = Object.freeze({
|
|
38
|
+
maximumDepth: 64,
|
|
39
|
+
maximumNodes: 262144,
|
|
40
|
+
maximumProperties: 131072,
|
|
41
|
+
maximumElements: 131072,
|
|
42
|
+
maximumArrayLength: 1e5,
|
|
43
|
+
maximumStringBytes: 1024 * 1024,
|
|
44
|
+
maximumAggregateStringBytes: 8 * 1024 * 1024,
|
|
45
|
+
maximumAggregateBytes: 16 * 1024 * 1024,
|
|
46
|
+
maximumInputBytes: 16 * 1024 * 1024
|
|
47
|
+
});
|
|
48
|
+
var QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS = Object.freeze({
|
|
49
|
+
maximumDepth: 96,
|
|
50
|
+
maximumNodes: 4e6,
|
|
51
|
+
maximumProperties: 2e6,
|
|
52
|
+
maximumElements: 2e6,
|
|
53
|
+
maximumArrayLength: 25e4,
|
|
54
|
+
maximumStringBytes: 4 * 1024 * 1024,
|
|
55
|
+
maximumAggregateStringBytes: 128 * 1024 * 1024,
|
|
56
|
+
maximumAggregateBytes: 256 * 1024 * 1024,
|
|
57
|
+
maximumInputBytes: 256 * 1024 * 1024
|
|
58
|
+
});
|
|
59
|
+
var FAILURE_MESSAGES = Object.freeze({
|
|
60
|
+
"aggregate-bytes": "GPU contract snapshot exceeds the aggregate byte limit.",
|
|
61
|
+
"aggregate-string-bytes": "GPU contract snapshot exceeds the aggregate string byte limit.",
|
|
62
|
+
"array-length": "GPU contract snapshot exceeds the single-array element limit.",
|
|
63
|
+
cycle: "GPU contract snapshot contains a circular reference.",
|
|
64
|
+
depth: "GPU contract snapshot exceeds the nesting-depth limit.",
|
|
65
|
+
elements: "GPU contract snapshot exceeds the total element limit.",
|
|
66
|
+
inspection: "GPU contract snapshot rejected unsafe object inspection.",
|
|
67
|
+
nodes: "GPU contract snapshot exceeds the total node limit.",
|
|
68
|
+
"non-finite": "GPU contract snapshot contains a non-finite number.",
|
|
69
|
+
properties: "GPU contract snapshot exceeds the total property limit.",
|
|
70
|
+
shape: "GPU contract snapshot requires plain JSON objects with own enumerable data properties and dense arrays.",
|
|
71
|
+
"string-bytes": "GPU contract snapshot exceeds the individual string byte limit.",
|
|
72
|
+
unicode: "GPU contract snapshot contains an invalid Unicode scalar string or unpaired UTF-16 surrogate.",
|
|
73
|
+
value: "GPU contract snapshot contains undefined or another value that JSON cannot represent."
|
|
74
|
+
});
|
|
75
|
+
var GpuContractSnapshotError = class extends TypeError {
|
|
76
|
+
code;
|
|
77
|
+
constructor(code) {
|
|
78
|
+
super(FAILURE_MESSAGES[code]);
|
|
79
|
+
this.name = "GpuContractSnapshotError";
|
|
80
|
+
this.code = code;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var TYPED_ARRAY_PROTOTYPE = Reflect.getPrototypeOf(Uint8Array.prototype);
|
|
84
|
+
var TYPED_ARRAY_BYTE_LENGTH = Reflect.getOwnPropertyDescriptor(
|
|
85
|
+
TYPED_ARRAY_PROTOTYPE,
|
|
86
|
+
"byteLength"
|
|
87
|
+
)?.get;
|
|
88
|
+
var TYPED_ARRAY_TAG = Reflect.getOwnPropertyDescriptor(
|
|
89
|
+
TYPED_ARRAY_PROTOTYPE,
|
|
90
|
+
Symbol.toStringTag
|
|
91
|
+
)?.get;
|
|
92
|
+
var UINT8_ARRAY_SET = Uint8Array.prototype.set;
|
|
93
|
+
function snapshotUint8Array(value, maximumBytes) {
|
|
94
|
+
if (!Number.isSafeInteger(maximumBytes) || maximumBytes < 0) {
|
|
95
|
+
throw new TypeError("GPU contract byte limit must be a non-negative safe integer.");
|
|
96
|
+
}
|
|
97
|
+
let byteLength;
|
|
98
|
+
let tag;
|
|
99
|
+
try {
|
|
100
|
+
if (!TYPED_ARRAY_BYTE_LENGTH || !TYPED_ARRAY_TAG) throw new TypeError();
|
|
101
|
+
byteLength = Reflect.apply(TYPED_ARRAY_BYTE_LENGTH, value, []);
|
|
102
|
+
tag = Reflect.apply(TYPED_ARRAY_TAG, value, []);
|
|
103
|
+
} catch {
|
|
104
|
+
throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
|
|
105
|
+
}
|
|
106
|
+
if (tag !== "Uint8Array" || !Number.isSafeInteger(byteLength) || byteLength > maximumBytes) {
|
|
107
|
+
throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
|
|
108
|
+
}
|
|
109
|
+
const output = new Uint8Array(byteLength);
|
|
110
|
+
try {
|
|
111
|
+
Reflect.apply(UINT8_ARRAY_SET, output, [value]);
|
|
112
|
+
} catch {
|
|
113
|
+
throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
|
|
114
|
+
}
|
|
115
|
+
return output;
|
|
116
|
+
}
|
|
117
|
+
function fail(reason) {
|
|
118
|
+
throw new GpuContractSnapshotError(reason);
|
|
119
|
+
}
|
|
120
|
+
function inspected(operation) {
|
|
121
|
+
try {
|
|
122
|
+
return operation();
|
|
123
|
+
} catch {
|
|
124
|
+
return fail("inspection");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function assertLimit(value, maximum, reason) {
|
|
128
|
+
if (!Number.isSafeInteger(value) || value > maximum) fail(reason);
|
|
40
129
|
}
|
|
41
|
-
function
|
|
130
|
+
function quotedJsonByteLength(value, maximum) {
|
|
131
|
+
let raw = 0;
|
|
132
|
+
let quoted = 2;
|
|
42
133
|
for (let index = 0; index < value.length; index += 1) {
|
|
43
134
|
const code = value.charCodeAt(index);
|
|
44
|
-
if (code
|
|
135
|
+
if (code <= 127) {
|
|
136
|
+
raw += 1;
|
|
137
|
+
if (code <= 31) quoted += code === 8 || code === 9 || code === 10 || code === 12 || code === 13 ? 2 : 6;
|
|
138
|
+
else quoted += code === 34 || code === 92 ? 2 : 1;
|
|
139
|
+
} else if (code <= 2047) {
|
|
140
|
+
raw += 2;
|
|
141
|
+
quoted += 2;
|
|
142
|
+
} else if (code >= 55296 && code <= 56319) {
|
|
45
143
|
const next = value.charCodeAt(index + 1);
|
|
46
|
-
if (!(next >= 56320 && next <= 57343))
|
|
144
|
+
if (!(next >= 56320 && next <= 57343)) fail("unicode");
|
|
145
|
+
raw += 4;
|
|
146
|
+
quoted += 4;
|
|
47
147
|
index += 1;
|
|
48
|
-
} else if (code >= 56320 && code <= 57343)
|
|
148
|
+
} else if (code >= 56320 && code <= 57343) fail("unicode");
|
|
149
|
+
else {
|
|
150
|
+
raw += 3;
|
|
151
|
+
quoted += 3;
|
|
152
|
+
}
|
|
153
|
+
if (raw > maximum) fail("string-bytes");
|
|
49
154
|
}
|
|
155
|
+
return { raw, quoted };
|
|
50
156
|
}
|
|
51
|
-
function
|
|
157
|
+
function assertLimits(limits) {
|
|
158
|
+
for (const value of Object.values(limits)) {
|
|
159
|
+
if (!Number.isSafeInteger(value) || value < 1) throw new TypeError("GPU contract snapshot limits must be positive safe integers.");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function snapshotGpuContract(value, limits = GPU_CONTRACT_SNAPSHOT_LIMITS) {
|
|
163
|
+
assertLimits(limits);
|
|
52
164
|
const ancestors = /* @__PURE__ */ new Set();
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
165
|
+
let nodes = 0;
|
|
166
|
+
let properties = 0;
|
|
167
|
+
let elements = 0;
|
|
168
|
+
let aggregateStringBytes = 0;
|
|
169
|
+
let aggregateBytes = 0;
|
|
170
|
+
const addAggregate = (bytes2) => {
|
|
171
|
+
aggregateBytes += bytes2;
|
|
172
|
+
assertLimit(aggregateBytes, limits.maximumAggregateBytes, "aggregate-bytes");
|
|
173
|
+
};
|
|
174
|
+
const addString = (text2) => {
|
|
175
|
+
const measured = quotedJsonByteLength(text2, limits.maximumStringBytes);
|
|
176
|
+
aggregateStringBytes += measured.raw;
|
|
177
|
+
assertLimit(aggregateStringBytes, limits.maximumAggregateStringBytes, "aggregate-string-bytes");
|
|
178
|
+
return measured.quoted;
|
|
179
|
+
};
|
|
180
|
+
const visit = (current, depth) => {
|
|
181
|
+
if (depth > limits.maximumDepth) fail("depth");
|
|
182
|
+
nodes += 1;
|
|
183
|
+
assertLimit(nodes, limits.maximumNodes, "nodes");
|
|
184
|
+
if (current === null) {
|
|
185
|
+
addAggregate(4);
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
if (typeof current === "string") {
|
|
189
|
+
addAggregate(addString(current));
|
|
190
|
+
return current;
|
|
191
|
+
}
|
|
192
|
+
if (typeof current === "boolean") {
|
|
193
|
+
addAggregate(current ? 4 : 5);
|
|
194
|
+
return current;
|
|
58
195
|
}
|
|
59
196
|
if (typeof current === "number") {
|
|
60
|
-
if (!Number.isFinite(current))
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
if (typeof current !== "object")
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
197
|
+
if (!Number.isFinite(current)) fail("non-finite");
|
|
198
|
+
const normalized = Object.is(current, -0) ? 0 : current;
|
|
199
|
+
addAggregate(JSON.stringify(normalized).length);
|
|
200
|
+
return normalized;
|
|
201
|
+
}
|
|
202
|
+
if (typeof current !== "object") fail("value");
|
|
203
|
+
if (ancestors.has(current)) fail("cycle");
|
|
204
|
+
const isArray = inspected(() => Array.isArray(current));
|
|
205
|
+
const prototype = inspected(() => Reflect.getPrototypeOf(current));
|
|
206
|
+
if (isArray ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) fail("shape");
|
|
71
207
|
ancestors.add(current);
|
|
72
208
|
try {
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
209
|
+
if (isArray) {
|
|
210
|
+
const lengthDescriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, "length"));
|
|
211
|
+
if (!lengthDescriptor || !Object.hasOwn(lengthDescriptor, "value") || lengthDescriptor.enumerable || typeof lengthDescriptor.value !== "number" || !Number.isSafeInteger(lengthDescriptor.value) || lengthDescriptor.value < 0) fail("shape");
|
|
212
|
+
const length = lengthDescriptor.value;
|
|
213
|
+
assertLimit(length, limits.maximumArrayLength, "array-length");
|
|
214
|
+
elements += length;
|
|
215
|
+
assertLimit(elements, limits.maximumElements, "elements");
|
|
216
|
+
const ownKeys2 = inspected(() => Reflect.ownKeys(current));
|
|
217
|
+
if (ownKeys2.some((key) => typeof key !== "string")) fail("shape");
|
|
218
|
+
if (ownKeys2.length !== length + 1) fail("shape");
|
|
219
|
+
const keySet = new Set(ownKeys2);
|
|
220
|
+
if (!keySet.delete("length")) fail("shape");
|
|
221
|
+
const output2 = new Array(length);
|
|
222
|
+
addAggregate(2 + Math.max(0, length - 1));
|
|
223
|
+
for (let index = 0; index < length; index += 1) {
|
|
224
|
+
const key = String(index);
|
|
225
|
+
if (!keySet.delete(key)) fail("shape");
|
|
226
|
+
const descriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, key));
|
|
227
|
+
if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) fail("shape");
|
|
228
|
+
Object.defineProperty(output2, key, {
|
|
229
|
+
configurable: true,
|
|
230
|
+
enumerable: true,
|
|
231
|
+
value: visit(descriptor.value, depth + 1),
|
|
232
|
+
writable: true
|
|
233
|
+
});
|
|
85
234
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
235
|
+
if (keySet.size !== 0) fail("shape");
|
|
236
|
+
return output2;
|
|
237
|
+
}
|
|
238
|
+
const ownKeys = inspected(() => Reflect.ownKeys(current));
|
|
239
|
+
if (ownKeys.some((key) => typeof key !== "string")) fail("shape");
|
|
240
|
+
properties += ownKeys.length;
|
|
241
|
+
assertLimit(properties, limits.maximumProperties, "properties");
|
|
242
|
+
addAggregate(2 + Math.max(0, ownKeys.length - 1) + ownKeys.length);
|
|
243
|
+
const output = {};
|
|
244
|
+
for (const key of ownKeys) {
|
|
245
|
+
addAggregate(addString(key));
|
|
246
|
+
const descriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, key));
|
|
247
|
+
if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) fail("shape");
|
|
248
|
+
Object.defineProperty(output, key, {
|
|
249
|
+
configurable: true,
|
|
250
|
+
enumerable: true,
|
|
251
|
+
value: visit(descriptor.value, depth + 1),
|
|
252
|
+
writable: true
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return output;
|
|
89
256
|
} finally {
|
|
90
257
|
ancestors.delete(current);
|
|
91
258
|
}
|
|
92
259
|
};
|
|
93
|
-
return visit(value,
|
|
260
|
+
return visit(value, 0);
|
|
261
|
+
}
|
|
262
|
+
function serializeSnapshot(value) {
|
|
263
|
+
if (value === null) return "null";
|
|
264
|
+
if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
265
|
+
if (typeof value === "number") return JSON.stringify(value);
|
|
266
|
+
if (Array.isArray(value)) return `[${value.map(serializeSnapshot).join(",")}]`;
|
|
267
|
+
const input = value;
|
|
268
|
+
return `{${Object.keys(input).sort().map((key) => `${JSON.stringify(key)}:${serializeSnapshot(input[key])}`).join(",")}}`;
|
|
269
|
+
}
|
|
270
|
+
function canonicalizeGpuContract(value) {
|
|
271
|
+
return serializeSnapshot(snapshotGpuContract(value));
|
|
272
|
+
}
|
|
273
|
+
function canonicalizeQualificationGpuContract(value) {
|
|
274
|
+
return serializeSnapshot(snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS));
|
|
94
275
|
}
|
|
95
276
|
|
|
96
277
|
// src/codec/codec.ts
|
|
@@ -562,39 +743,41 @@ function modelProjection(manifest) {
|
|
|
562
743
|
};
|
|
563
744
|
}
|
|
564
745
|
async function computeGpuAbiHash(input) {
|
|
565
|
-
|
|
746
|
+
const snapshot = snapshotGpuContract(input);
|
|
747
|
+
if (snapshot.kind === "model") {
|
|
566
748
|
return computeSha256(
|
|
567
749
|
`plasius.gpu.model-abi/v1
|
|
568
|
-
${canonicalizeGpuContract(modelProjection(
|
|
750
|
+
${canonicalizeGpuContract(modelProjection(snapshot.interface))}`
|
|
569
751
|
);
|
|
570
752
|
}
|
|
571
|
-
if (
|
|
753
|
+
if (snapshot.kind === "interface") {
|
|
572
754
|
return computeSha256(
|
|
573
755
|
`plasius.gpu.interface-abi/v1
|
|
574
|
-
${canonicalizeGpuContract(interfaceProjection(
|
|
756
|
+
${canonicalizeGpuContract(interfaceProjection(snapshot.interface))}`
|
|
575
757
|
);
|
|
576
758
|
}
|
|
577
759
|
const pipelines = sorted(
|
|
578
|
-
|
|
760
|
+
snapshot.pipelines,
|
|
579
761
|
(left, right) => compareString(left.pipelineId, right.pipelineId)
|
|
580
762
|
);
|
|
581
763
|
const requirements = {
|
|
582
|
-
semantics: [...
|
|
583
|
-
features: [...
|
|
584
|
-
limits: sorted(
|
|
585
|
-
formats: [...
|
|
764
|
+
semantics: [...snapshot.requirements.semantics].sort(),
|
|
765
|
+
features: [...snapshot.requirements.features].sort(),
|
|
766
|
+
limits: sorted(snapshot.requirements.limits, (left, right) => compareString(left.name, right.name)),
|
|
767
|
+
formats: [...snapshot.requirements.formats].sort()
|
|
586
768
|
};
|
|
587
769
|
return computeSha256(
|
|
588
770
|
`plasius.gpu.shader-abi/v1
|
|
589
771
|
${canonicalizeGpuContract({
|
|
590
|
-
interface: interfaceProjection(
|
|
772
|
+
interface: interfaceProjection(snapshot.interface),
|
|
591
773
|
pipelines,
|
|
592
774
|
requirements
|
|
593
775
|
})}`
|
|
594
776
|
);
|
|
595
777
|
}
|
|
596
778
|
async function computeShaderManifestCoreSha256(manifest) {
|
|
597
|
-
const
|
|
779
|
+
const snapshot = snapshotGpuContract(manifest);
|
|
780
|
+
const core = Object.fromEntries(Object.entries(snapshot).filter(
|
|
598
781
|
([key]) => key !== "validationEvidence" && key !== "additionalValidationEvidence"
|
|
599
782
|
));
|
|
600
783
|
return computeSha256(
|
|
@@ -606,6 +789,7 @@ ${canonicalizeGpuContract(core)}`
|
|
|
606
789
|
// src/contracts.ts
|
|
607
790
|
var GPU_INTERFACE_MANIFEST_VERSION = "1.0.0";
|
|
608
791
|
var SHADER_VERSION_MANIFEST_VERSION = "1.0.0";
|
|
792
|
+
var SHADER_STYLE_PROFILE_MANIFEST_VERSION = "1.0.0";
|
|
609
793
|
var SHADER_COMPILE_UNIT_VERSION = "1.0.0";
|
|
610
794
|
var SHADER_VALIDATION_EVIDENCE_VERSION = "1.0.0";
|
|
611
795
|
var STABLE_WEBGPU_MATRIX_VERSION = "1.0.0";
|
|
@@ -621,6 +805,29 @@ var SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES = [
|
|
|
621
805
|
Object.freeze(SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES);
|
|
622
806
|
var SUPPORTED_ADDITIVE_WEBGPU_MATRIX_POLICIES = Object.freeze([]);
|
|
623
807
|
|
|
808
|
+
// src/asset-version.ts
|
|
809
|
+
var ASSET_VERSION_PATTERN = /^[0-9A-Za-z][0-9A-Za-z._-]{0,127}$/u;
|
|
810
|
+
var MUTABLE_VERSION_ALIASES = /* @__PURE__ */ new Set([
|
|
811
|
+
"latest",
|
|
812
|
+
"current",
|
|
813
|
+
"stable",
|
|
814
|
+
"preview",
|
|
815
|
+
"default",
|
|
816
|
+
"production",
|
|
817
|
+
"canary",
|
|
818
|
+
"next",
|
|
819
|
+
"head",
|
|
820
|
+
"main"
|
|
821
|
+
]);
|
|
822
|
+
var X_WILDCARD_SEGMENT_PATTERN = /^(?:[vV])?[xX](?:\.|-|$)|\.[xX](?:\.|-|$)/u;
|
|
823
|
+
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.";
|
|
824
|
+
function assertImmutableAssetVersion(value) {
|
|
825
|
+
if (typeof value !== "string" || !ASSET_VERSION_PATTERN.test(value) || MUTABLE_VERSION_ALIASES.has(value.toLowerCase()) || X_WILDCARD_SEGMENT_PATTERN.test(value)) {
|
|
826
|
+
throw new TypeError(IMMUTABLE_VERSION_ERROR_MESSAGE);
|
|
827
|
+
}
|
|
828
|
+
return value;
|
|
829
|
+
}
|
|
830
|
+
|
|
624
831
|
// src/requirements-validation.ts
|
|
625
832
|
var ENABLED_FEATURES = Object.freeze({
|
|
626
833
|
f16: "shader-f16",
|
|
@@ -948,6 +1155,14 @@ function validateShaderDerivedRequirements(input) {
|
|
|
948
1155
|
// src/manifest-validation.ts
|
|
949
1156
|
var stages = ["vertex", "fragment", "compute"];
|
|
950
1157
|
var roles = ["material", "lighting", "outline", "shadow", "post-processing"];
|
|
1158
|
+
function detachedJson(value, path2) {
|
|
1159
|
+
try {
|
|
1160
|
+
return snapshotGpuContract(value);
|
|
1161
|
+
} catch (cause) {
|
|
1162
|
+
const detail = cause instanceof GpuContractSnapshotError ? ` ${cause.message}` : "";
|
|
1163
|
+
throw new TypeError(`${path2} must contain bounded detached JSON contract data.${detail}`);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
951
1166
|
function object(value, path2) {
|
|
952
1167
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path2} must be an object.`);
|
|
953
1168
|
return value;
|
|
@@ -955,7 +1170,7 @@ function object(value, path2) {
|
|
|
955
1170
|
function exact(value, keys2, path2) {
|
|
956
1171
|
const allowed = new Set(keys2);
|
|
957
1172
|
for (const key of Object.keys(value)) if (!allowed.has(key)) throw new TypeError(`${path2}.${key} is not part of this contract version.`);
|
|
958
|
-
for (const key of keys2) if (!(key
|
|
1173
|
+
for (const key of keys2) if (!Object.hasOwn(value, key)) throw new TypeError(`${path2}.${key} is required.`);
|
|
959
1174
|
}
|
|
960
1175
|
function text(value, path2, maximum = 512) {
|
|
961
1176
|
if (typeof value !== "string" || value.length === 0 || value.length > maximum || [...value].some((character) => character.charCodeAt(0) <= 31)) {
|
|
@@ -968,6 +1183,13 @@ function token(value, path2) {
|
|
|
968
1183
|
if (!/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/u.test(result) || result.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
|
|
969
1184
|
return result;
|
|
970
1185
|
}
|
|
1186
|
+
function immutableVersion(value, path2) {
|
|
1187
|
+
try {
|
|
1188
|
+
return assertImmutableAssetVersion(value);
|
|
1189
|
+
} catch {
|
|
1190
|
+
throw new TypeError(`${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
971
1193
|
function enumeration(value, values, path2) {
|
|
972
1194
|
if (!values.includes(value)) throw new TypeError(`${path2} is invalid.`);
|
|
973
1195
|
return value;
|
|
@@ -995,8 +1217,8 @@ function nullableToken(value, path2) {
|
|
|
995
1217
|
function digest(value, path2) {
|
|
996
1218
|
try {
|
|
997
1219
|
return asSha256Hex(text(value, path2, 64));
|
|
998
|
-
} catch
|
|
999
|
-
throw new TypeError(`${path2} must be a lowercase SHA-256 digest
|
|
1220
|
+
} catch {
|
|
1221
|
+
throw new TypeError(`${path2} must be a lowercase SHA-256 digest.`);
|
|
1000
1222
|
}
|
|
1001
1223
|
}
|
|
1002
1224
|
function uri(value, path2) {
|
|
@@ -1004,8 +1226,8 @@ function uri(value, path2) {
|
|
|
1004
1226
|
let parsed;
|
|
1005
1227
|
try {
|
|
1006
1228
|
parsed = new URL(result);
|
|
1007
|
-
} catch
|
|
1008
|
-
throw new TypeError(`${path2} must be an absolute immutable asset URI
|
|
1229
|
+
} catch {
|
|
1230
|
+
throw new TypeError(`${path2} must be an absolute immutable asset URI.`);
|
|
1009
1231
|
}
|
|
1010
1232
|
if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.hash) throw new TypeError(`${path2} must be credential-free HTTPS without a fragment.`);
|
|
1011
1233
|
const keys2 = [...parsed.searchParams.keys()].map((key) => key.toLowerCase());
|
|
@@ -1241,7 +1463,7 @@ function interfaceRef(value, path2) {
|
|
|
1241
1463
|
const input = object(value, path2);
|
|
1242
1464
|
exact(input, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path2);
|
|
1243
1465
|
token(input.interfaceId, `${path2}.interfaceId`);
|
|
1244
|
-
|
|
1466
|
+
immutableVersion(input.interfaceVersion, `${path2}.interfaceVersion`);
|
|
1245
1467
|
uri(input.manifestUri, `${path2}.manifestUri`);
|
|
1246
1468
|
digest(input.manifestSha256, `${path2}.manifestSha256`);
|
|
1247
1469
|
digest(input.interfaceAbiHash, `${path2}.interfaceAbiHash`);
|
|
@@ -1379,7 +1601,7 @@ function pipeline(value, path2, moduleIds) {
|
|
|
1379
1601
|
return input;
|
|
1380
1602
|
}
|
|
1381
1603
|
function parseSerializableGpuPipelineDescriptors(value, moduleIds, path2 = "pipelines") {
|
|
1382
|
-
const parsed = array(value, path2).map((item, index) => pipeline(item, `${path2}[${index}]`, new Set(moduleIds)));
|
|
1604
|
+
const parsed = array(detachedJson(value, path2), path2).map((item, index) => pipeline(item, `${path2}[${index}]`, new Set(moduleIds)));
|
|
1383
1605
|
unique(parsed, (item) => item.pipelineId, path2);
|
|
1384
1606
|
return freeze(parsed);
|
|
1385
1607
|
}
|
|
@@ -1387,7 +1609,7 @@ function compatibleModel(value, path2) {
|
|
|
1387
1609
|
const input = object(value, path2);
|
|
1388
1610
|
exact(input, ["interfaceId", "interfaceVersion", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path2);
|
|
1389
1611
|
token(input.interfaceId, `${path2}.interfaceId`);
|
|
1390
|
-
|
|
1612
|
+
immutableVersion(input.interfaceVersion, `${path2}.interfaceVersion`);
|
|
1391
1613
|
digest(input.manifestSha256, `${path2}.manifestSha256`);
|
|
1392
1614
|
digest(input.interfaceAbiHash, `${path2}.interfaceAbiHash`);
|
|
1393
1615
|
digest(input.modelAbiHash, `${path2}.modelAbiHash`);
|
|
@@ -1400,7 +1622,7 @@ function validationEvidenceRef(value, path2) {
|
|
|
1400
1622
|
uri(evidence.uri, `${path2}.uri`);
|
|
1401
1623
|
digest(evidence.sha256, `${path2}.sha256`);
|
|
1402
1624
|
token(evidence.matrixId, `${path2}.matrixId`);
|
|
1403
|
-
|
|
1625
|
+
immutableVersion(evidence.matrixVersion, `${path2}.matrixVersion`);
|
|
1404
1626
|
digest(evidence.matrixSha256, `${path2}.matrixSha256`);
|
|
1405
1627
|
const attestation = object(evidence.attestationRef, `${path2}.attestationRef`);
|
|
1406
1628
|
exact(attestation, ["uri", "sha256"], `${path2}.attestationRef`);
|
|
@@ -1427,11 +1649,11 @@ function reflectedRecordBindingSize(record) {
|
|
|
1427
1649
|
return Math.ceil(unrounded / record.alignment) * record.alignment;
|
|
1428
1650
|
}
|
|
1429
1651
|
function parseGpuInterfaceManifest(value) {
|
|
1430
|
-
const input = object(value, "GpuInterfaceManifest");
|
|
1652
|
+
const input = object(detachedJson(value, "GpuInterfaceManifest"), "GpuInterfaceManifest");
|
|
1431
1653
|
exact(input, ["contractVersion", "interfaceId", "interfaceVersion", "modules", "records", "bindings", "entryPoints", "vertexInputs", "overrides", "modelAbi", "modelAbiHash", "interfaceAbiHash", "generatedBy"], "GpuInterfaceManifest");
|
|
1432
1654
|
if (input.contractVersion !== GPU_INTERFACE_MANIFEST_VERSION) throw new TypeError("Unsupported GPU interface contract version.");
|
|
1433
1655
|
token(input.interfaceId, "GpuInterfaceManifest.interfaceId");
|
|
1434
|
-
|
|
1656
|
+
immutableVersion(input.interfaceVersion, "GpuInterfaceManifest.interfaceVersion");
|
|
1435
1657
|
const moduleValues = array(input.modules, "GpuInterfaceManifest.modules");
|
|
1436
1658
|
if (moduleValues.length === 0) throw new TypeError("GpuInterfaceManifest.modules must not be empty.");
|
|
1437
1659
|
const moduleIds = moduleValues.map((value2, index) => {
|
|
@@ -1613,11 +1835,11 @@ function parseGpuInterfaceManifest(value) {
|
|
|
1613
1835
|
return freeze(input);
|
|
1614
1836
|
}
|
|
1615
1837
|
function parseShaderVersionManifest(value) {
|
|
1616
|
-
const input = object(value, "ShaderVersionManifest");
|
|
1838
|
+
const input = object(detachedJson(value, "ShaderVersionManifest"), "ShaderVersionManifest");
|
|
1617
1839
|
exact(input, ["contractVersion", "shaderId", "version", "modules", "gpuInterface", "pipelines", "renderRoles", "compatibleModelInterfaces", "requirements", "shaderAbiHash", "validationEvidence", "additionalValidationEvidence"], "ShaderVersionManifest");
|
|
1618
1840
|
if (input.contractVersion !== SHADER_VERSION_MANIFEST_VERSION) throw new TypeError("Unsupported shader manifest contract version.");
|
|
1619
1841
|
token(input.shaderId, "ShaderVersionManifest.shaderId");
|
|
1620
|
-
|
|
1842
|
+
immutableVersion(input.version, "ShaderVersionManifest.version");
|
|
1621
1843
|
const moduleValues = array(input.modules, "ShaderVersionManifest.modules");
|
|
1622
1844
|
if (moduleValues.length === 0) throw new TypeError("ShaderVersionManifest.modules must not be empty.");
|
|
1623
1845
|
const moduleIds = moduleValues.map((item, index) => {
|
|
@@ -1730,7 +1952,7 @@ function parseShaderVersionManifest(value) {
|
|
|
1730
1952
|
return freeze(input);
|
|
1731
1953
|
}
|
|
1732
1954
|
function parseShaderVersionManifestCore(value) {
|
|
1733
|
-
const input = object(value, "ShaderVersionManifestCore");
|
|
1955
|
+
const input = object(detachedJson(value, "ShaderVersionManifestCore"), "ShaderVersionManifestCore");
|
|
1734
1956
|
if ("validationEvidence" in input || "additionalValidationEvidence" in input) {
|
|
1735
1957
|
throw new TypeError("ShaderVersionManifestCore must not contain validationEvidence or additionalValidationEvidence.");
|
|
1736
1958
|
}
|
|
@@ -1755,11 +1977,59 @@ function parseShaderVersionManifestCore(value) {
|
|
|
1755
1977
|
void additionalValidationEvidence;
|
|
1756
1978
|
return freeze(core);
|
|
1757
1979
|
}
|
|
1980
|
+
function parseShaderStyleProfileManifest(value) {
|
|
1981
|
+
const input = object(detachedJson(value, "ShaderStyleProfileManifest"), "ShaderStyleProfileManifest");
|
|
1982
|
+
exact(input, ["contractVersion", "profileId", "version", "style", "roles", "compatibleModelInterfaces", "requiredSemantics", "requiredValidationScopes"], "ShaderStyleProfileManifest");
|
|
1983
|
+
if (input.contractVersion !== SHADER_STYLE_PROFILE_MANIFEST_VERSION) throw new TypeError("Unsupported style-profile contract version.");
|
|
1984
|
+
token(input.profileId, "ShaderStyleProfileManifest.profileId");
|
|
1985
|
+
immutableVersion(input.version, "ShaderStyleProfileManifest.version");
|
|
1986
|
+
token(input.style, "ShaderStyleProfileManifest.style");
|
|
1987
|
+
const roleValues = array(input.roles, "ShaderStyleProfileManifest.roles", 5);
|
|
1988
|
+
if (roleValues.length === 0) throw new TypeError("ShaderStyleProfileManifest.roles must not be empty.");
|
|
1989
|
+
const roleNames = [];
|
|
1990
|
+
roleValues.forEach((item, index) => {
|
|
1991
|
+
const path2 = `ShaderStyleProfileManifest.roles[${index}]`;
|
|
1992
|
+
const role = object(item, path2);
|
|
1993
|
+
exact(role, ["role", "shader"], path2);
|
|
1994
|
+
roleNames.push(enumeration(role.role, roles, `${path2}.role`));
|
|
1995
|
+
const shader = object(role.shader, `${path2}.shader`);
|
|
1996
|
+
exact(shader, ["shaderId", "version", "manifestUri", "manifestSha256"], `${path2}.shader`);
|
|
1997
|
+
token(shader.shaderId, `${path2}.shader.shaderId`);
|
|
1998
|
+
immutableVersion(shader.version, `${path2}.shader.version`);
|
|
1999
|
+
uri(shader.manifestUri, `${path2}.shader.manifestUri`);
|
|
2000
|
+
digest(shader.manifestSha256, `${path2}.shader.manifestSha256`);
|
|
2001
|
+
});
|
|
2002
|
+
unique(roleNames, String, "ShaderStyleProfileManifest.roles");
|
|
2003
|
+
const compatible = array(input.compatibleModelInterfaces, "ShaderStyleProfileManifest.compatibleModelInterfaces").map((item, index) => compatibleModel(item, `ShaderStyleProfileManifest.compatibleModelInterfaces[${index}]`));
|
|
2004
|
+
if (compatible.length === 0) throw new TypeError("ShaderStyleProfileManifest.compatibleModelInterfaces must not be empty.");
|
|
2005
|
+
unique(compatible, (item) => `${item.interfaceId}:${item.interfaceVersion}:${item.manifestSha256}:${item.interfaceAbiHash}:${item.modelAbiHash}`, "ShaderStyleProfileManifest.compatibleModelInterfaces");
|
|
2006
|
+
tokenArray(input.requiredSemantics, "ShaderStyleProfileManifest.requiredSemantics");
|
|
2007
|
+
const requiredValidationScopes = array(input.requiredValidationScopes, "ShaderStyleProfileManifest.requiredValidationScopes").map((item, index) => {
|
|
2008
|
+
const path2 = `ShaderStyleProfileManifest.requiredValidationScopes[${index}]`;
|
|
2009
|
+
const requirement = object(item, path2);
|
|
2010
|
+
exact(requirement, ["scope", "matrixId", "matrixVersion", "matrixSha256"], path2);
|
|
2011
|
+
const scope = token(requirement.scope, `${path2}.scope`);
|
|
2012
|
+
if (scope === "universal") throw new TypeError(`${path2}.scope must not use the reserved universal scope.`);
|
|
2013
|
+
token(requirement.matrixId, `${path2}.matrixId`);
|
|
2014
|
+
immutableVersion(requirement.matrixVersion, `${path2}.matrixVersion`);
|
|
2015
|
+
const matrixSha256 = digest(requirement.matrixSha256, `${path2}.matrixSha256`);
|
|
2016
|
+
if (SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES.some((policy) => policy.matrixSha256 === matrixSha256)) {
|
|
2017
|
+
throw new TypeError(`${path2} must require an additive matrix policy, not the universal matrix policy.`);
|
|
2018
|
+
}
|
|
2019
|
+
if (!SUPPORTED_ADDITIVE_WEBGPU_MATRIX_POLICIES.some((policy) => scope === policy.scope && requirement.matrixId === policy.matrixId && requirement.matrixVersion === policy.matrixVersion && matrixSha256 === policy.matrixSha256)) {
|
|
2020
|
+
throw new TypeError(`${path2} is not a supported additive WebGPU matrix policy.`);
|
|
2021
|
+
}
|
|
2022
|
+
return requirement;
|
|
2023
|
+
});
|
|
2024
|
+
unique(requiredValidationScopes, (item) => String(item.scope), "ShaderStyleProfileManifest.requiredValidationScopes scopes");
|
|
2025
|
+
unique(requiredValidationScopes, (item) => String(item.matrixSha256), "ShaderStyleProfileManifest.requiredValidationScopes matrix policies");
|
|
2026
|
+
return freeze(input);
|
|
2027
|
+
}
|
|
1758
2028
|
function parseModelGpuCompatibilityDescriptor(value) {
|
|
1759
|
-
const input = object(value, "ModelGpuCompatibilityDescriptor");
|
|
2029
|
+
const input = object(detachedJson(value, "ModelGpuCompatibilityDescriptor"), "ModelGpuCompatibilityDescriptor");
|
|
1760
2030
|
exact(input, ["modelId", "version", "gpuInterface", "modelAbiHash", "providedSemantics", "defaultStyleProfile"], "ModelGpuCompatibilityDescriptor");
|
|
1761
2031
|
token(input.modelId, "ModelGpuCompatibilityDescriptor.modelId");
|
|
1762
|
-
|
|
2032
|
+
immutableVersion(input.version, "ModelGpuCompatibilityDescriptor.version");
|
|
1763
2033
|
const gpuInterface = interfaceRef(input.gpuInterface, "ModelGpuCompatibilityDescriptor.gpuInterface");
|
|
1764
2034
|
const modelAbiHash = digest(input.modelAbiHash, "ModelGpuCompatibilityDescriptor.modelAbiHash");
|
|
1765
2035
|
if (gpuInterface.modelAbiHash !== modelAbiHash) throw new TypeError("ModelGpuCompatibilityDescriptor.gpuInterface.modelAbiHash differs from modelAbiHash.");
|
|
@@ -1768,14 +2038,17 @@ function parseModelGpuCompatibilityDescriptor(value) {
|
|
|
1768
2038
|
const profile = object(input.defaultStyleProfile, "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
|
|
1769
2039
|
exact(profile, ["profileId", "version", "manifestUri", "manifestSha256"], "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
|
|
1770
2040
|
token(profile.profileId, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.profileId");
|
|
1771
|
-
|
|
2041
|
+
immutableVersion(profile.version, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.version");
|
|
1772
2042
|
uri(profile.manifestUri, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestUri");
|
|
1773
2043
|
digest(profile.manifestSha256, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestSha256");
|
|
1774
2044
|
}
|
|
1775
2045
|
return freeze(input);
|
|
1776
2046
|
}
|
|
1777
2047
|
function parseShaderQualificationModelCompatibilityFixture(value) {
|
|
1778
|
-
const input = object(
|
|
2048
|
+
const input = object(
|
|
2049
|
+
detachedJson(value, "ShaderQualificationModelCompatibilityFixture"),
|
|
2050
|
+
"ShaderQualificationModelCompatibilityFixture"
|
|
2051
|
+
);
|
|
1779
2052
|
exact(input, ["contractVersion", "fixtureId", "model"], "ShaderQualificationModelCompatibilityFixture");
|
|
1780
2053
|
if (input.contractVersion !== SHADER_QUALIFICATION_FIXTURE_VERSION) throw new TypeError("Unsupported model compatibility fixture version.");
|
|
1781
2054
|
token(input.fixtureId, "ShaderQualificationModelCompatibilityFixture.fixtureId");
|
|
@@ -1791,13 +2064,26 @@ function issue(code, message, path2) {
|
|
|
1791
2064
|
function object2(value) {
|
|
1792
2065
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
1793
2066
|
}
|
|
2067
|
+
function freezeJson(value) {
|
|
2068
|
+
if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
|
|
2069
|
+
for (const child of Object.values(value)) freezeJson(child);
|
|
2070
|
+
return Object.freeze(value);
|
|
2071
|
+
}
|
|
1794
2072
|
function exactKeys(value, keys2) {
|
|
1795
2073
|
const expected = new Set(keys2);
|
|
1796
|
-
return Object.keys(value).every((key) => expected.has(key)) && keys2.every((key) => key
|
|
2074
|
+
return Object.keys(value).every((key) => expected.has(key)) && keys2.every((key) => Object.hasOwn(value, key));
|
|
1797
2075
|
}
|
|
1798
2076
|
function safeToken(value) {
|
|
1799
2077
|
return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,159}$/u.test(value) && !value.includes("..");
|
|
1800
2078
|
}
|
|
2079
|
+
function immutableVersion2(value) {
|
|
2080
|
+
try {
|
|
2081
|
+
assertImmutableAssetVersion(value);
|
|
2082
|
+
return true;
|
|
2083
|
+
} catch {
|
|
2084
|
+
return false;
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
1801
2087
|
function validSha(value) {
|
|
1802
2088
|
try {
|
|
1803
2089
|
asSha256Hex(String(value));
|
|
@@ -1807,8 +2093,20 @@ function validSha(value) {
|
|
|
1807
2093
|
}
|
|
1808
2094
|
}
|
|
1809
2095
|
function validateCompileUnitInventory(value) {
|
|
1810
|
-
|
|
1811
|
-
|
|
2096
|
+
let snapshot;
|
|
2097
|
+
try {
|
|
2098
|
+
snapshot = snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
|
|
2099
|
+
} catch {
|
|
2100
|
+
return {
|
|
2101
|
+
ok: false,
|
|
2102
|
+
diagnostics: [issue(
|
|
2103
|
+
"invalid-contract",
|
|
2104
|
+
"Compile-unit inventory must contain bounded detached JSON contract data."
|
|
2105
|
+
)]
|
|
2106
|
+
};
|
|
2107
|
+
}
|
|
2108
|
+
const envelope = object2(snapshot);
|
|
2109
|
+
const candidate = envelope && Object.hasOwn(envelope, "inventory") ? object2(snapshot.inventory) : envelope;
|
|
1812
2110
|
const diagnostics = [];
|
|
1813
2111
|
if (!candidate || !exactKeys(candidate, ["contractVersion", "fragments", "compileUnits"])) {
|
|
1814
2112
|
return { ok: false, diagnostics: [issue("invalid-contract", "Compile-unit inventory has unknown or missing fields.")] };
|
|
@@ -1939,7 +2237,7 @@ function validateCompileUnitInventory(value) {
|
|
|
1939
2237
|
diagnostics.push(issue("invalid-contract", cause instanceof Error ? cause.message : "Compile-unit pipelines are invalid.", `${path2}.pipelines`));
|
|
1940
2238
|
}
|
|
1941
2239
|
const interfaceRef2 = object2(unit.interfaceRef);
|
|
1942
|
-
if (!interfaceRef2 || !exactKeys(interfaceRef2, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"]) || !safeToken(interfaceRef2.interfaceId) || !
|
|
2240
|
+
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)) {
|
|
1943
2241
|
diagnostics.push(issue("invalid-contract", "Compile-unit interfaceRef is invalid.", `${path2}.interfaceRef`));
|
|
1944
2242
|
}
|
|
1945
2243
|
const fixture = object2(unit.qualificationFixture);
|
|
@@ -1950,7 +2248,7 @@ function validateCompileUnitInventory(value) {
|
|
|
1950
2248
|
for (const fragmentId of fragmentIds) {
|
|
1951
2249
|
if (!covered.has(fragmentId)) diagnostics.push(issue("uncovered-fragment", `WGSL fragment ${fragmentId} has no compile unit.`));
|
|
1952
2250
|
}
|
|
1953
|
-
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: candidate };
|
|
2251
|
+
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: freezeJson(candidate) };
|
|
1954
2252
|
}
|
|
1955
2253
|
|
|
1956
2254
|
// src/testing/qualification-bundle.ts
|
|
@@ -2042,14 +2340,33 @@ function object3(value, path2) {
|
|
|
2042
2340
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path2} must be an object.`);
|
|
2043
2341
|
return value;
|
|
2044
2342
|
}
|
|
2343
|
+
function detachedJson2(value, label) {
|
|
2344
|
+
try {
|
|
2345
|
+
return snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
|
|
2346
|
+
} catch {
|
|
2347
|
+
throw new TypeError(`${label} must contain bounded detached JSON contract data.`);
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
function freezeJson2(value) {
|
|
2351
|
+
if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
|
|
2352
|
+
for (const child of Object.values(value)) freezeJson2(child);
|
|
2353
|
+
return Object.freeze(value);
|
|
2354
|
+
}
|
|
2045
2355
|
function exact2(value, keys2, path2) {
|
|
2046
2356
|
const expected = new Set(keys2);
|
|
2047
|
-
if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => key
|
|
2357
|
+
if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => Object.hasOwn(value, key))) throw new TypeError(`${path2} has unknown or missing fields.`);
|
|
2048
2358
|
}
|
|
2049
2359
|
function token2(value, path2) {
|
|
2050
2360
|
if (typeof value !== "string" || !TOKEN.test(value) || value.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
|
|
2051
2361
|
return value;
|
|
2052
2362
|
}
|
|
2363
|
+
function immutableVersion3(value, path2) {
|
|
2364
|
+
try {
|
|
2365
|
+
return assertImmutableAssetVersion(value);
|
|
2366
|
+
} catch {
|
|
2367
|
+
throw new TypeError(`${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`);
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2053
2370
|
function path(value, label, extensions) {
|
|
2054
2371
|
if (typeof value !== "string" || !SAFE_PATH2.test(value) || !extensions.some((extension) => value.endsWith(extension))) {
|
|
2055
2372
|
throw new TypeError(`${label} must be a safe data-only bundle path (${extensions.join(", ")}).`);
|
|
@@ -2059,8 +2376,8 @@ function path(value, label, extensions) {
|
|
|
2059
2376
|
function sha(value, label) {
|
|
2060
2377
|
try {
|
|
2061
2378
|
return asSha256Hex(String(value));
|
|
2062
|
-
} catch
|
|
2063
|
-
throw new TypeError(`${label} must be a lowercase SHA-256 digest
|
|
2379
|
+
} catch {
|
|
2380
|
+
throw new TypeError(`${label} must be a lowercase SHA-256 digest.`);
|
|
2064
2381
|
}
|
|
2065
2382
|
}
|
|
2066
2383
|
function integer4(value, label, minimum = 0, maximum = 4294967295) {
|
|
@@ -2184,7 +2501,8 @@ function jsonValue(value, label, depth = 0) {
|
|
|
2184
2501
|
}
|
|
2185
2502
|
function validateQualificationFixture(value, unit) {
|
|
2186
2503
|
try {
|
|
2187
|
-
const
|
|
2504
|
+
const compileUnit = unit === void 0 ? void 0 : detachedJson2(unit, "compile unit");
|
|
2505
|
+
const fixture = object3(detachedJson2(value, "fixture"), "fixture");
|
|
2188
2506
|
exact2(fixture, ["contractVersion", "fixtureId", "resources", "bindGroups", "commands", "layoutProbes", "readbacks", "bounds"], "fixture");
|
|
2189
2507
|
if (fixture.contractVersion !== SHADER_QUALIFICATION_FIXTURE_VERSION) throw new TypeError("Unsupported qualification fixture version.");
|
|
2190
2508
|
token2(fixture.fixtureId, "fixture.fixtureId");
|
|
@@ -2314,14 +2632,14 @@ function validateQualificationFixture(value, unit) {
|
|
|
2314
2632
|
unique2(bindingIds, `${label}.entries`);
|
|
2315
2633
|
bindGroups.set(id, { group: groupIndex, entries: parsedEntries });
|
|
2316
2634
|
}
|
|
2317
|
-
const pipelines = new Map(
|
|
2635
|
+
const pipelines = new Map(compileUnit?.pipelines.map((pipeline2) => [pipeline2.pipelineId, pipeline2]) ?? []);
|
|
2318
2636
|
const pipelineIds = new Set(pipelines.keys());
|
|
2319
2637
|
const commandBindGroups = (value2, pipelineId, label) => {
|
|
2320
2638
|
const ids = boundedArray(value2, label, 32).map((item, index) => token2(item, `${label}[${index}]`));
|
|
2321
2639
|
unique2(ids, label);
|
|
2322
2640
|
const pipeline2 = pipelines.get(pipelineId);
|
|
2323
2641
|
if (!pipeline2) {
|
|
2324
|
-
if (
|
|
2642
|
+
if (compileUnit) throw new TypeError(`${label} pipeline is missing.`);
|
|
2325
2643
|
return;
|
|
2326
2644
|
}
|
|
2327
2645
|
const expectedGroups = [...pipeline2.layout.bindGroups].sort((left, right) => left.group - right.group);
|
|
@@ -2346,7 +2664,7 @@ function validateQualificationFixture(value, unit) {
|
|
|
2346
2664
|
executionCommands += 1;
|
|
2347
2665
|
exact2(command, ["kind", "pipelineId", "bindGroupIds", "workgroups"], label);
|
|
2348
2666
|
const id = token2(command.pipelineId, `${label}.pipelineId`);
|
|
2349
|
-
if (
|
|
2667
|
+
if (compileUnit && pipelines.get(id)?.kind !== "compute") throw new TypeError(`${label} references a missing or non-compute pipeline.`);
|
|
2350
2668
|
commandBindGroups(command.bindGroupIds, id, `${label}.bindGroupIds`);
|
|
2351
2669
|
const workgroups = tuple(command.workgroups, `${label}.workgroups`, 3, 1);
|
|
2352
2670
|
if (workgroups[0] * workgroups[1] * workgroups[2] > 1048576) throw new TypeError(`${label}.workgroups exceeds the hard dispatch bound.`);
|
|
@@ -2520,14 +2838,14 @@ function validateQualificationFixture(value, unit) {
|
|
|
2520
2838
|
}
|
|
2521
2839
|
unique2(probeIds, "fixture.layoutProbes probe IDs");
|
|
2522
2840
|
unique2(probeSources, "fixture.layoutProbes model sources");
|
|
2523
|
-
return { ok: true, value: fixture };
|
|
2841
|
+
return { ok: true, value: freezeJson2(fixture) };
|
|
2524
2842
|
} catch (cause) {
|
|
2525
2843
|
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification fixture." }] };
|
|
2526
2844
|
}
|
|
2527
2845
|
}
|
|
2528
2846
|
function validateQualificationBundleManifest(value) {
|
|
2529
2847
|
try {
|
|
2530
|
-
const bundle = object3(value, "qualification");
|
|
2848
|
+
const bundle = object3(detachedJson2(value, "qualification"), "qualification");
|
|
2531
2849
|
exact2(bundle, ["contractVersion", "inventory", "subject", "shaderManifestCorePath", "gpuInterfaceManifest", "modelCompatibilityFixtures", "modules", "fixtures"], "qualification");
|
|
2532
2850
|
if (bundle.contractVersion !== SHADER_QUALIFICATION_BUNDLE_VERSION) throw new TypeError("Unsupported qualification bundle version.");
|
|
2533
2851
|
const inventory = validateCompileUnitInventory(bundle.inventory);
|
|
@@ -2537,7 +2855,7 @@ function validateQualificationBundleManifest(value) {
|
|
|
2537
2855
|
const candidate = object3(subject.shaderManifestCore, "qualification.subject.shaderManifestCore");
|
|
2538
2856
|
exact2(candidate, ["shaderId", "version", "sha256"], "qualification.subject.shaderManifestCore");
|
|
2539
2857
|
token2(candidate.shaderId, "qualification.subject.shaderManifestCore.shaderId");
|
|
2540
|
-
|
|
2858
|
+
immutableVersion3(candidate.version, "qualification.subject.shaderManifestCore.version");
|
|
2541
2859
|
sha(candidate.sha256, "qualification.subject.shaderManifestCore.sha256");
|
|
2542
2860
|
path(bundle.shaderManifestCorePath, "qualification.shaderManifestCorePath", [".json"]);
|
|
2543
2861
|
const interfaceManifest = object3(bundle.gpuInterfaceManifest, "qualification.gpuInterfaceManifest");
|
|
@@ -2597,7 +2915,7 @@ function validateQualificationBundleManifest(value) {
|
|
|
2597
2915
|
const expectedUnits = [...inventory.value.compileUnits.map((unit) => unit.compileUnitId)].sort();
|
|
2598
2916
|
if (unitIds.join("\n") !== expectedUnits.join("\n")) throw new TypeError("Subject compile-unit IDs differ from inventory.");
|
|
2599
2917
|
orderedUniqueTokens(subject.requiredCellIds, "qualification.subject.requiredCellIds");
|
|
2600
|
-
return { ok: true, value: bundle };
|
|
2918
|
+
return { ok: true, value: freezeJson2(bundle) };
|
|
2601
2919
|
} catch (cause) {
|
|
2602
2920
|
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification bundle." }] };
|
|
2603
2921
|
}
|
|
@@ -8726,7 +9044,7 @@ function validatePipelineInterfaces(input) {
|
|
|
8726
9044
|
// package.json
|
|
8727
9045
|
var package_default = {
|
|
8728
9046
|
name: "@plasius/gpu-shader",
|
|
8729
|
-
version: "0.1.
|
|
9047
|
+
version: "0.1.3",
|
|
8730
9048
|
description: "Reflection-first WebGPU WGSL interfaces, CPU codecs, compatibility validation, style profiles, and qualification tooling",
|
|
8731
9049
|
type: "module",
|
|
8732
9050
|
sideEffects: false,
|
|
@@ -8818,6 +9136,7 @@ var package_default = {
|
|
|
8818
9136
|
access: "public"
|
|
8819
9137
|
},
|
|
8820
9138
|
overrides: {
|
|
9139
|
+
esbuild: "^0.28.1",
|
|
8821
9140
|
minimatch: "^10.2.1"
|
|
8822
9141
|
},
|
|
8823
9142
|
engines: {
|
|
@@ -9989,7 +10308,37 @@ function object4(value, path2) {
|
|
|
9989
10308
|
}
|
|
9990
10309
|
function exact3(value, keys2, path2) {
|
|
9991
10310
|
const expected = new Set(keys2);
|
|
9992
|
-
if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => key
|
|
10311
|
+
if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => Object.hasOwn(value, key))) throw new TypeError(`${path2} has unknown or missing fields.`);
|
|
10312
|
+
}
|
|
10313
|
+
function detachedQualificationContract(value) {
|
|
10314
|
+
try {
|
|
10315
|
+
return snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
|
|
10316
|
+
} catch {
|
|
10317
|
+
throw new TypeError("Qualification data must contain bounded detached JSON contract data.");
|
|
10318
|
+
}
|
|
10319
|
+
}
|
|
10320
|
+
function parseQualificationJsonBytes(bytes2, label) {
|
|
10321
|
+
let snapshot;
|
|
10322
|
+
try {
|
|
10323
|
+
snapshot = snapshotUint8Array(
|
|
10324
|
+
bytes2,
|
|
10325
|
+
QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes
|
|
10326
|
+
);
|
|
10327
|
+
} catch {
|
|
10328
|
+
throw new TypeError(`${label} is not bounded UTF-8 JSON.`);
|
|
10329
|
+
}
|
|
10330
|
+
let parsed;
|
|
10331
|
+
try {
|
|
10332
|
+
parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(snapshot));
|
|
10333
|
+
} catch {
|
|
10334
|
+
throw new TypeError(`${label} is not valid UTF-8 JSON.`);
|
|
10335
|
+
}
|
|
10336
|
+
return detachedQualificationContract(parsed);
|
|
10337
|
+
}
|
|
10338
|
+
function freezeJson3(value) {
|
|
10339
|
+
if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
|
|
10340
|
+
for (const child of Object.values(value)) freezeJson3(child);
|
|
10341
|
+
return Object.freeze(value);
|
|
9993
10342
|
}
|
|
9994
10343
|
function token3(value, path2, maximum = 512) {
|
|
9995
10344
|
if (typeof value !== "string" || value.length === 0 || value.length > maximum || [...value].some((character) => character.charCodeAt(0) <= 31)) throw new TypeError(`${path2} is not a bounded string.`);
|
|
@@ -9998,8 +10347,8 @@ function token3(value, path2, maximum = 512) {
|
|
|
9998
10347
|
function sha2(value, path2) {
|
|
9999
10348
|
try {
|
|
10000
10349
|
return asSha256Hex(token3(value, path2, 64));
|
|
10001
|
-
} catch
|
|
10002
|
-
throw new TypeError(`${path2} is not a SHA-256 digest
|
|
10350
|
+
} catch {
|
|
10351
|
+
throw new TypeError(`${path2} is not a SHA-256 digest.`);
|
|
10003
10352
|
}
|
|
10004
10353
|
}
|
|
10005
10354
|
function integer5(value, path2, minimum = 0) {
|
|
@@ -10032,7 +10381,7 @@ function trustedWorkflowRef(value, path2) {
|
|
|
10032
10381
|
return result;
|
|
10033
10382
|
}
|
|
10034
10383
|
function parseTrustedWorkflowProvenance(value, path2 = "provenance") {
|
|
10035
|
-
const input = object4(value, path2);
|
|
10384
|
+
const input = object4(detachedQualificationContract(value), path2);
|
|
10036
10385
|
exact3(input, ["repository", "commit", "ref", "workflowRef", "workflowSha", "runId", "runAttempt", "job", "eventName", "oidcAttestation"], path2);
|
|
10037
10386
|
const repository = token3(input.repository, `${path2}.repository`);
|
|
10038
10387
|
if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
|
|
@@ -10051,10 +10400,10 @@ function parseTrustedWorkflowProvenance(value, path2 = "provenance") {
|
|
|
10051
10400
|
token3(oidc.audience, `${path2}.oidcAttestation.audience`, 2048);
|
|
10052
10401
|
sha2(oidc.verifiedClaimsSha256, `${path2}.oidcAttestation.verifiedClaimsSha256`);
|
|
10053
10402
|
timestamp(oidc.verifiedAt, `${path2}.oidcAttestation.verifiedAt`);
|
|
10054
|
-
return input;
|
|
10403
|
+
return freezeJson3(input);
|
|
10055
10404
|
}
|
|
10056
10405
|
function parseQualificationExecutionProducer(value, path2 = "producer") {
|
|
10057
|
-
const input = object4(value, path2);
|
|
10406
|
+
const input = object4(detachedQualificationContract(value), path2);
|
|
10058
10407
|
exact3(input, ["repository", "commit", "ref", "runId", "runAttempt", "job", "trustedWorkflowRepository", "trustedWorkflowRef", "trustedWorkflowSha", "runner"], path2);
|
|
10059
10408
|
const repository = token3(input.repository, `${path2}.repository`);
|
|
10060
10409
|
if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
|
|
@@ -10072,7 +10421,7 @@ function parseQualificationExecutionProducer(value, path2 = "producer") {
|
|
|
10072
10421
|
if (!["github-hosted", "self-hosted", "device-farm"].includes(String(runner.environment))) throw new TypeError(`${path2}.runner.environment is invalid.`);
|
|
10073
10422
|
token3(runner.os, `${path2}.runner.os`);
|
|
10074
10423
|
token3(runner.architecture, `${path2}.runner.architecture`);
|
|
10075
|
-
return input;
|
|
10424
|
+
return freezeJson3(input);
|
|
10076
10425
|
}
|
|
10077
10426
|
function assertProducerMatchesPreflight(producer, provenance, cell, path2, expectedJob) {
|
|
10078
10427
|
if (producer.repository !== provenance.repository || !canonicalEqual(producer.commit, provenance.commit) || producer.ref !== provenance.ref || producer.runId !== provenance.runId || producer.runAttempt !== provenance.runAttempt || producer.trustedWorkflowRepository !== "Plasius-LTD/gpu-shader" || producer.trustedWorkflowRef !== provenance.workflowRef || !canonicalEqual(producer.trustedWorkflowSha, provenance.workflowSha) || producer.job !== expectedJob) throw new TypeError(`${path2} does not match the exact qualification workflow run or subject.`);
|
|
@@ -10081,26 +10430,32 @@ function assertProducerMatchesPreflight(producer, provenance, cell, path2, expec
|
|
|
10081
10430
|
if (expectedJob === "physical-runner-preflight" && producer.runner.environment !== "github-hosted") throw new TypeError(`${path2} must identify its hosted orchestration job truthfully.`);
|
|
10082
10431
|
}
|
|
10083
10432
|
function canonicalEqual(left, right) {
|
|
10084
|
-
return
|
|
10433
|
+
return canonicalizeQualificationGpuContract(left) === canonicalizeQualificationGpuContract(right);
|
|
10085
10434
|
}
|
|
10086
10435
|
function foldRunnerLabel(value) {
|
|
10087
10436
|
return value.replace(/[A-Z]/gu, (character) => character.toLowerCase());
|
|
10088
10437
|
}
|
|
10089
10438
|
async function computeQualificationInventorySha256(bundle) {
|
|
10090
|
-
|
|
10439
|
+
const snapshot = detachedQualificationContract(bundle);
|
|
10440
|
+
return computeSha256(canonicalizeQualificationGpuContract(snapshot.inventory));
|
|
10091
10441
|
}
|
|
10092
10442
|
async function computeQualificationSubjectBinding(input) {
|
|
10093
10443
|
return computeSha256(`plasius.gpu.qualification-subject/v1
|
|
10094
|
-
${
|
|
10444
|
+
${canonicalizeQualificationGpuContract(input)}`);
|
|
10095
10445
|
}
|
|
10096
10446
|
async function computeValidationEvidenceId(value) {
|
|
10097
10447
|
const input = object4(value, "evidence identity input");
|
|
10098
10448
|
const projection = Object.fromEntries(Object.entries(input).filter(([key]) => key !== "evidenceId"));
|
|
10099
10449
|
return `qualification-${(await computeSha256(`plasius.gpu.validation-evidence/v1
|
|
10100
|
-
${
|
|
10450
|
+
${canonicalizeQualificationGpuContract(projection)}`)).slice(0, 24)}`;
|
|
10101
10451
|
}
|
|
10102
10452
|
function immutableBlobUri(value) {
|
|
10103
|
-
|
|
10453
|
+
let url;
|
|
10454
|
+
try {
|
|
10455
|
+
url = new URL(value);
|
|
10456
|
+
} catch {
|
|
10457
|
+
throw new TypeError("Source URI must be a normalized immutable Azure Blob .tar URL.");
|
|
10458
|
+
}
|
|
10104
10459
|
if (url.protocol !== "https:" || url.username || url.password || url.hash || url.port || !/^[a-z0-9]{3,24}\.blob\.core\.windows\.net$/u.test(url.hostname) || !/^[A-Za-z0-9][A-Za-z0-9._/-]*\.tar$/u.test(url.pathname.slice(1)) || url.pathname.split("/").some((segment, index) => index > 0 && (!segment || segment === "." || segment === ".."))) {
|
|
10105
10460
|
throw new TypeError("Source URI must be a normalized immutable Azure Blob .tar URL.");
|
|
10106
10461
|
}
|
|
@@ -10110,12 +10465,7 @@ function immutableBlobUri(value) {
|
|
|
10110
10465
|
}
|
|
10111
10466
|
async function createQualificationPreflight(input) {
|
|
10112
10467
|
token3(input.qualificationId, "qualificationId");
|
|
10113
|
-
|
|
10114
|
-
try {
|
|
10115
|
-
parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
|
|
10116
|
-
} catch (cause) {
|
|
10117
|
-
throw new TypeError("Selected matrix artifact is not UTF-8 JSON.", { cause });
|
|
10118
|
-
}
|
|
10468
|
+
const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Selected matrix artifact");
|
|
10119
10469
|
if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Selected matrix artifact bytes differ from the supplied matrix value.");
|
|
10120
10470
|
const actualMatrixSha256 = await computeSha256(input.matrixBytes);
|
|
10121
10471
|
if (actualMatrixSha256 !== input.matrixSha256) throw new TypeError("Selected matrix digest is not derived from the exact matrix manifest.");
|
|
@@ -10285,12 +10635,7 @@ function syntheticResult(unitId, cell, status, message, now) {
|
|
|
10285
10635
|
async function aggregateShaderValidationEvidence(input) {
|
|
10286
10636
|
const verifyArtifact = async (artifact2, label) => {
|
|
10287
10637
|
if (await computeSha256(artifact2.bytes) !== artifact2.sha256) throw new TypeError(`${label} artifact digest is not derived from its exact bytes.`);
|
|
10288
|
-
|
|
10289
|
-
try {
|
|
10290
|
-
parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(artifact2.bytes));
|
|
10291
|
-
} catch (cause) {
|
|
10292
|
-
throw new TypeError(`${label} bytes are not UTF-8 JSON.`, { cause });
|
|
10293
|
-
}
|
|
10638
|
+
const parsed = parseQualificationJsonBytes(artifact2.bytes, `${label} bytes`);
|
|
10294
10639
|
if (!canonicalEqual(parsed, artifact2.value)) throw new TypeError(`${label} parsed value differs from its exact bytes.`);
|
|
10295
10640
|
};
|
|
10296
10641
|
await verifyArtifact(input.preflight, "Qualification preflight");
|
|
@@ -10312,12 +10657,7 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
10312
10657
|
exact3(sourceBlob, ["host", "versionId", "uri"], "Qualification preflight.sourceBlob");
|
|
10313
10658
|
const normalizedSource = immutableBlobUri(token3(sourceBlob.uri, "Qualification preflight.sourceBlob.uri", 2048));
|
|
10314
10659
|
if (!canonicalEqual(sourceBlob, normalizedSource)) throw new TypeError("Qualification preflight source Blob claims are stale.");
|
|
10315
|
-
|
|
10316
|
-
try {
|
|
10317
|
-
parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
|
|
10318
|
-
} catch (cause) {
|
|
10319
|
-
throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
|
|
10320
|
-
}
|
|
10660
|
+
const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Matrix artifact");
|
|
10321
10661
|
if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
|
|
10322
10662
|
const actualMatrixSha256 = await computeSha256(input.matrixBytes);
|
|
10323
10663
|
if (preflight.matrixSha256 !== actualMatrixSha256) throw new TypeError("Qualification preflight matrix artifact digest is stale.");
|
|
@@ -10391,7 +10731,7 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
10391
10731
|
if (cellArtifact || diagnostic) throw new TypeError(`Unavailable cell ${cell.cellId} has conflicting evidence.`);
|
|
10392
10732
|
for (const unit of units) results.push(syntheticResult(unit, cell, "runner-unavailable", "Required physical runner was unavailable.", now));
|
|
10393
10733
|
const cellResults = results.slice(-units.size);
|
|
10394
|
-
cellRuns.push({ cellId: cell.cellId, source: "runner-preflight", sourceArtifactSha256: runner.sha256, resultsSha256: await computeSha256(
|
|
10734
|
+
cellRuns.push({ cellId: cell.cellId, source: "runner-preflight", sourceArtifactSha256: runner.sha256, resultsSha256: await computeSha256(canonicalizeQualificationGpuContract(cellResults)), qualificationPreflightProvenance: preflight.provenance, producer: runner.value.producer, harness: input.harness, automation: null, resultCount: units.size, status: "runner-unavailable" });
|
|
10395
10735
|
continue;
|
|
10396
10736
|
}
|
|
10397
10737
|
if (diagnostic) {
|
|
@@ -10406,7 +10746,7 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
10406
10746
|
const status2 = value2.status === "timeout" ? "timeout" : "failed";
|
|
10407
10747
|
for (const unit of units) results.push(syntheticResult(unit, cell, status2, value2.message, now));
|
|
10408
10748
|
const cellResults = results.slice(-units.size);
|
|
10409
|
-
cellRuns.push({ cellId: cell.cellId, source: "workflow-diagnostic", sourceArtifactSha256: diagnostic.sha256, resultsSha256: await computeSha256(
|
|
10749
|
+
cellRuns.push({ cellId: cell.cellId, source: "workflow-diagnostic", sourceArtifactSha256: diagnostic.sha256, resultsSha256: await computeSha256(canonicalizeQualificationGpuContract(cellResults)), qualificationPreflightProvenance: preflight.provenance, producer: value2.producer, harness: input.harness, automation: null, resultCount: units.size, status: status2 });
|
|
10410
10750
|
continue;
|
|
10411
10751
|
}
|
|
10412
10752
|
if (!cellArtifact) throw new TypeError(`Cell ${cell.cellId} has no qualification evidence.`);
|
|
@@ -10414,7 +10754,7 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
10414
10754
|
if (!matchedRunner) throw new TypeError(`Cell evidence ${cell.cellId} producer was not matched by runner preflight.`);
|
|
10415
10755
|
const value = assertCellEvidence(cellArtifact.value, cell, input.matrix, preflight, input.harness, runner.value.adapterHarness, matchedRunner, units, now);
|
|
10416
10756
|
results.push(...value.results);
|
|
10417
|
-
cellRuns.push({ cellId: cell.cellId, source: "cell-evidence", sourceArtifactSha256: cellArtifact.sha256, resultsSha256: await computeSha256(
|
|
10757
|
+
cellRuns.push({ cellId: cell.cellId, source: "cell-evidence", sourceArtifactSha256: cellArtifact.sha256, resultsSha256: await computeSha256(canonicalizeQualificationGpuContract(value.results)), qualificationPreflightProvenance: value.qualificationPreflightProvenance, producer: value.producer, harness: value.harness, automation: value.automation, resultCount: value.results.length, status: "passed" });
|
|
10418
10758
|
}
|
|
10419
10759
|
const expectedResults = units.size * cells.size;
|
|
10420
10760
|
if (results.length !== expectedResults) throw new TypeError("Aggregate result product is incomplete.");
|
|
@@ -10437,34 +10777,31 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
10437
10777
|
}
|
|
10438
10778
|
async function validateShaderValidationEvidence(input) {
|
|
10439
10779
|
try {
|
|
10440
|
-
const evidence = object4(input.evidence, "evidence");
|
|
10780
|
+
const evidence = object4(detachedQualificationContract(input.evidence), "evidence");
|
|
10781
|
+
const bundle = detachedQualificationContract(input.bundle);
|
|
10782
|
+
const matrix = detachedQualificationContract(input.matrix);
|
|
10441
10783
|
exact3(evidence, ["contractVersion", "evidenceId", "status", "generatedAt", "subjectBindingSha256", "subject", "matrixRef", "toolchain", "qualificationPreflightProvenance", "counts", "cellRuns", "results"], "evidence");
|
|
10442
10784
|
if (evidence.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION) throw new TypeError("Unsupported evidence contract version.");
|
|
10443
10785
|
const evidenceId = token3(evidence.evidenceId, "evidence.evidenceId");
|
|
10444
10786
|
const generatedAt = timestamp(evidence.generatedAt, "evidence.generatedAt");
|
|
10445
10787
|
const subjectBindingSha256 = sha2(evidence.subjectBindingSha256, "evidence.subjectBindingSha256");
|
|
10446
10788
|
if (evidence.status !== "passed" && evidence.status !== "failed") throw new TypeError("Evidence status is invalid.");
|
|
10447
|
-
|
|
10448
|
-
|
|
10449
|
-
parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
|
|
10450
|
-
} catch (cause) {
|
|
10451
|
-
throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
|
|
10452
|
-
}
|
|
10453
|
-
if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
|
|
10789
|
+
const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Matrix artifact");
|
|
10790
|
+
if (!canonicalEqual(parsedMatrix, matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
|
|
10454
10791
|
const matrixSha256 = await computeSha256(input.matrixBytes);
|
|
10455
|
-
const inventorySha256 = await computeQualificationInventorySha256(
|
|
10456
|
-
if (inventorySha256 !==
|
|
10792
|
+
const inventorySha256 = await computeQualificationInventorySha256(bundle);
|
|
10793
|
+
if (inventorySha256 !== bundle.subject.compileUnitInventorySha256) throw new TypeError("Bundle subject inventory digest is stale.");
|
|
10457
10794
|
const subject = object4(evidence.subject, "evidence.subject");
|
|
10458
|
-
const expectedSubjectKeys = [...Object.keys(
|
|
10795
|
+
const expectedSubjectKeys = [...Object.keys(bundle.subject), "dataBundleSha256"];
|
|
10459
10796
|
exact3(subject, expectedSubjectKeys, "evidence.subject");
|
|
10460
10797
|
const candidateSubject = Object.fromEntries(Object.entries(subject).filter(([key]) => key !== "dataBundleSha256"));
|
|
10461
|
-
if (!canonicalEqual(candidateSubject,
|
|
10798
|
+
if (!canonicalEqual(candidateSubject, bundle.subject)) throw new TypeError("Evidence candidate subject differs from bundle.");
|
|
10462
10799
|
const dataBundleSha256 = sha2(subject.dataBundleSha256, "evidence.subject.dataBundleSha256");
|
|
10463
10800
|
if (input.dataBundleSha256 && input.dataBundleSha256 !== dataBundleSha256) throw new TypeError("Evidence data bundle digest differs from the exact archive.");
|
|
10464
10801
|
if (subject.compileUnitInventorySha256 !== inventorySha256) throw new TypeError("Evidence compile-unit inventory digest is stale.");
|
|
10465
10802
|
const matrixRef = object4(evidence.matrixRef, "evidence.matrixRef");
|
|
10466
10803
|
exact3(matrixRef, ["matrixId", "version", "sha256"], "evidence.matrixRef");
|
|
10467
|
-
if (matrixRef.matrixId !==
|
|
10804
|
+
if (matrixRef.matrixId !== matrix.matrixId || matrixRef.version !== matrix.version || matrixRef.sha256 !== matrixSha256) throw new TypeError("Evidence matrix artifact identity differs.");
|
|
10468
10805
|
const toolchain = object4(evidence.toolchain, "evidence.toolchain");
|
|
10469
10806
|
exact3(toolchain, ["packageVersion", "reflectorVersion", "harness"], "evidence.toolchain");
|
|
10470
10807
|
token3(toolchain.packageVersion, "evidence.toolchain.packageVersion");
|
|
@@ -10476,11 +10813,11 @@ async function validateShaderValidationEvidence(input) {
|
|
|
10476
10813
|
const harnessSha256 = sha2(harness.sha256, "evidence.toolchain.harness.sha256");
|
|
10477
10814
|
const preflightProvenance = parseTrustedWorkflowProvenance(evidence.qualificationPreflightProvenance, "evidence.qualificationPreflightProvenance");
|
|
10478
10815
|
if (Date.parse(generatedAt) < Date.parse(preflightProvenance.oidcAttestation.verifiedAt)) throw new TypeError("Evidence predates trusted preflight verification.");
|
|
10479
|
-
const expectedBinding = await computeQualificationSubjectBinding({ subject:
|
|
10816
|
+
const expectedBinding = await computeQualificationSubjectBinding({ subject: bundle.subject, dataBundleSha256, compileUnitInventorySha256: inventorySha256, matrixSha256, harnessSha256 });
|
|
10480
10817
|
if (subjectBindingSha256 !== expectedBinding) throw new TypeError("Evidence subject binding is stale.");
|
|
10481
10818
|
if (evidenceId !== await computeValidationEvidenceId(evidence)) throw new TypeError("Evidence identity is stale.");
|
|
10482
|
-
const units = new Set(
|
|
10483
|
-
const cells = new Map(
|
|
10819
|
+
const units = new Set(bundle.inventory.compileUnits.map((unit) => unit.compileUnitId));
|
|
10820
|
+
const cells = new Map(matrix.cells.map((cell) => [cell.cellId, cell]));
|
|
10484
10821
|
const expected = units.size * cells.size;
|
|
10485
10822
|
const results = array2(evidence.results, "evidence.results");
|
|
10486
10823
|
if (results.length !== expected) throw new TypeError("Evidence result product is incomplete.");
|
|
@@ -10530,7 +10867,7 @@ async function validateShaderValidationEvidence(input) {
|
|
|
10530
10867
|
sha2(automation2.sha256, `${path2}.automation.sha256`);
|
|
10531
10868
|
} else if (run.automation !== null) throw new TypeError(`${path2}.automation must be null when no adapter completed a cell run.`);
|
|
10532
10869
|
const cellResults = parsedResults.filter((result) => result.cellId === cellId);
|
|
10533
|
-
if (run.resultCount !== units.size || cellResults.length !== units.size || await computeSha256(
|
|
10870
|
+
if (run.resultCount !== units.size || cellResults.length !== units.size || await computeSha256(canonicalizeQualificationGpuContract(cellResults)) !== resultsSha256) throw new TypeError(`${path2} result count/digest is stale.`);
|
|
10534
10871
|
const resultStatuses = new Set(cellResults.map((result) => result.status));
|
|
10535
10872
|
if (resultStatuses.size !== 1 || !resultStatuses.has(String(run.status))) throw new TypeError(`${path2}.status differs from its results.`);
|
|
10536
10873
|
if (run.source === "cell-evidence" && run.status !== "passed") throw new TypeError(`${path2} cell evidence must contain passing results.`);
|
|
@@ -10539,7 +10876,7 @@ async function validateShaderValidationEvidence(input) {
|
|
|
10539
10876
|
if (run.source === "cell-evidence" && cellResults.some((result) => result.observed.runner.id !== producer.runner.name)) throw new TypeError(`${path2} producer runner differs from its results.`);
|
|
10540
10877
|
}
|
|
10541
10878
|
if (evidence.status === "passed" !== (passed === expected) || input.requirePassed !== false && evidence.status !== "passed") throw new TypeError("Evidence does not satisfy the required passed gate.");
|
|
10542
|
-
return { ok: true, value: evidence };
|
|
10879
|
+
return { ok: true, value: freezeJson3(evidence) };
|
|
10543
10880
|
} catch (cause) {
|
|
10544
10881
|
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid shader validation evidence." }] };
|
|
10545
10882
|
}
|
|
@@ -10554,7 +10891,12 @@ function object5(value) {
|
|
|
10554
10891
|
}
|
|
10555
10892
|
function keys(value, expected) {
|
|
10556
10893
|
const set = new Set(expected);
|
|
10557
|
-
return Object.keys(value).every((key) => set.has(key)) && expected.every((key) => key
|
|
10894
|
+
return Object.keys(value).every((key) => set.has(key)) && expected.every((key) => Object.hasOwn(value, key));
|
|
10895
|
+
}
|
|
10896
|
+
function freezeJson4(value) {
|
|
10897
|
+
if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
|
|
10898
|
+
for (const child of Object.values(value)) freezeJson4(child);
|
|
10899
|
+
return Object.freeze(value);
|
|
10558
10900
|
}
|
|
10559
10901
|
function canonicalEqual2(left, right) {
|
|
10560
10902
|
try {
|
|
@@ -10604,7 +10946,13 @@ var BASELINE = /* @__PURE__ */ new Map([
|
|
|
10604
10946
|
["win11-nvidia-edge-d3d12", "edge|windows|x64|physical|nvidia|qualified-nvidia|d3d12|playwright|self-hosted,Windows,X64,shader-validation,physical-gpu,gpu-nvidia,d3d12"]
|
|
10605
10947
|
]);
|
|
10606
10948
|
function validateStableWebGpuMatrix(value) {
|
|
10607
|
-
|
|
10949
|
+
let snapshot;
|
|
10950
|
+
try {
|
|
10951
|
+
snapshot = snapshotGpuContract(value);
|
|
10952
|
+
} catch {
|
|
10953
|
+
return { ok: false, diagnostics: [issue3("Matrix must contain bounded detached JSON contract data.")] };
|
|
10954
|
+
}
|
|
10955
|
+
const matrix = object5(snapshot);
|
|
10608
10956
|
const diagnostics = [];
|
|
10609
10957
|
if (!matrix || !keys(matrix, ["contractVersion", "matrixId", "version", "policy", "cells"])) {
|
|
10610
10958
|
return { ok: false, diagnostics: [issue3("Matrix has unknown or missing top-level fields.")] };
|
|
@@ -10677,7 +11025,7 @@ function validateStableWebGpuMatrix(value) {
|
|
|
10677
11025
|
}
|
|
10678
11026
|
}
|
|
10679
11027
|
if (physical !== 15 || blocking !== 16 || software !== 1 || ids.size !== BASELINE.size) diagnostics.push(issue3("Matrix must contain the exact 15 physical baseline cells plus one SwiftShader smoke cell."));
|
|
10680
|
-
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: matrix };
|
|
11028
|
+
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: freezeJson4(matrix) };
|
|
10681
11029
|
}
|
|
10682
11030
|
|
|
10683
11031
|
// src/testing/runner/playwright-swiftshader.ts
|
|
@@ -11977,11 +12325,18 @@ function verifyReflectedLayoutProbeOutputs(input) {
|
|
|
11977
12325
|
|
|
11978
12326
|
// src/compatibility.ts
|
|
11979
12327
|
function error(code, message, path2) {
|
|
11980
|
-
|
|
12328
|
+
const bounded = [...message].map((character) => {
|
|
12329
|
+
const codePoint = character.codePointAt(0);
|
|
12330
|
+
return codePoint <= 31 || codePoint === 127 ? " " : character;
|
|
12331
|
+
}).slice(0, 512).join("");
|
|
12332
|
+
return { code, severity: "error", message: bounded, ...path2 ? { path: path2 } : {} };
|
|
11981
12333
|
}
|
|
11982
12334
|
function interfaceMatches(item, model) {
|
|
11983
12335
|
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;
|
|
11984
12336
|
}
|
|
12337
|
+
function hasValidationEvidence(value) {
|
|
12338
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && (Object.hasOwn(value, "validationEvidence") || Object.hasOwn(value, "additionalValidationEvidence"));
|
|
12339
|
+
}
|
|
11985
12340
|
function validateRequirements(shader, gpuInterface, model, capabilities, diagnostics) {
|
|
11986
12341
|
const semantics = new Set(model.providedSemantics);
|
|
11987
12342
|
const requiredSemantics = /* @__PURE__ */ new Set([
|
|
@@ -12020,7 +12375,40 @@ function validateRequirements(shader, gpuInterface, model, capabilities, diagnos
|
|
|
12020
12375
|
}
|
|
12021
12376
|
function validateModelShaderCompatibility(input) {
|
|
12022
12377
|
const diagnostics = [];
|
|
12023
|
-
|
|
12378
|
+
let model;
|
|
12379
|
+
let shader;
|
|
12380
|
+
let gpuInterface;
|
|
12381
|
+
let profile;
|
|
12382
|
+
let capabilities;
|
|
12383
|
+
try {
|
|
12384
|
+
const snapshot = snapshotGpuContract(input);
|
|
12385
|
+
if (typeof snapshot !== "object" || snapshot === null || Array.isArray(snapshot)) {
|
|
12386
|
+
throw new TypeError("GPU compatibility input must be a bounded contract object.");
|
|
12387
|
+
}
|
|
12388
|
+
const envelope = snapshot;
|
|
12389
|
+
const keys2 = Object.keys(envelope);
|
|
12390
|
+
const allowed = /* @__PURE__ */ new Set(["model", "shader", "gpuInterface", "profile", "capabilities"]);
|
|
12391
|
+
if (keys2.some((key) => !allowed.has(key)) || !["model", "shader", "gpuInterface"].every((key) => Object.hasOwn(envelope, key))) {
|
|
12392
|
+
throw new TypeError("GPU compatibility input has unknown or missing fields.");
|
|
12393
|
+
}
|
|
12394
|
+
const modelSnapshot = envelope.model;
|
|
12395
|
+
const shaderSnapshot = envelope.shader;
|
|
12396
|
+
const gpuInterfaceSnapshot = envelope.gpuInterface;
|
|
12397
|
+
const profileSnapshot = Object.hasOwn(envelope, "profile") ? envelope.profile : void 0;
|
|
12398
|
+
model = parseModelGpuCompatibilityDescriptor(modelSnapshot);
|
|
12399
|
+
shader = hasValidationEvidence(shaderSnapshot) ? parseShaderVersionManifest(shaderSnapshot) : parseShaderVersionManifestCore(shaderSnapshot);
|
|
12400
|
+
gpuInterface = parseGpuInterfaceManifest(gpuInterfaceSnapshot);
|
|
12401
|
+
profile = profileSnapshot === void 0 ? void 0 : parseShaderStyleProfileManifest(profileSnapshot);
|
|
12402
|
+
capabilities = Object.hasOwn(envelope, "capabilities") ? envelope.capabilities : void 0;
|
|
12403
|
+
} catch (cause) {
|
|
12404
|
+
return {
|
|
12405
|
+
ok: false,
|
|
12406
|
+
diagnostics: [error(
|
|
12407
|
+
"invalid-contract",
|
|
12408
|
+
cause instanceof Error ? cause.message : "GPU compatibility contract snapshot failed."
|
|
12409
|
+
)]
|
|
12410
|
+
};
|
|
12411
|
+
}
|
|
12024
12412
|
try {
|
|
12025
12413
|
validateShaderInterfaceRequirements({ manifest: shader, gpuInterface });
|
|
12026
12414
|
} catch (cause) {
|
|
@@ -12050,7 +12438,15 @@ function validateModelShaderCompatibility(input) {
|
|
|
12050
12438
|
}
|
|
12051
12439
|
}
|
|
12052
12440
|
}
|
|
12053
|
-
|
|
12441
|
+
try {
|
|
12442
|
+
validateRequirements(shader, gpuInterface, model, capabilities, diagnostics);
|
|
12443
|
+
} catch (cause) {
|
|
12444
|
+
diagnostics.push(error(
|
|
12445
|
+
"invalid-contract",
|
|
12446
|
+
cause instanceof Error ? cause.message : "GPU capability snapshot validation failed.",
|
|
12447
|
+
"capabilities"
|
|
12448
|
+
));
|
|
12449
|
+
}
|
|
12054
12450
|
if (diagnostics.length > 0) return { ok: false, diagnostics };
|
|
12055
12451
|
return {
|
|
12056
12452
|
ok: true,
|