@plasius/gpu-shader 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +203 -0
- package/README.md +434 -0
- package/dist/cli.cjs +12742 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +4 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +12718 -0
- package/dist/cli.js.map +1 -0
- package/dist/contracts-C4eel8MT.d.cts +1220 -0
- package/dist/contracts-C4eel8MT.d.ts +1220 -0
- package/dist/index.cjs +2512 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +88 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +2456 -0
- package/dist/index.js.map +1 -0
- package/dist/node.cjs +10131 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +50 -0
- package/dist/node.d.ts +50 -0
- package/dist/node.js +10099 -0
- package/dist/node.js.map +1 -0
- package/dist/testing.cjs +1927 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +82 -0
- package/dist/testing.d.ts +82 -0
- package/dist/testing.js +1888 -0
- package/dist/testing.js.map +1 -0
- package/matrices/stable-webgpu-2026-07-13.json +545 -0
- package/package.json +100 -0
package/dist/testing.js
ADDED
|
@@ -0,0 +1,1888 @@
|
|
|
1
|
+
// src/contracts.ts
|
|
2
|
+
var SHADER_COMPILE_UNIT_VERSION = "1.0.0";
|
|
3
|
+
var SHADER_VALIDATION_EVIDENCE_VERSION = "1.0.0";
|
|
4
|
+
var STABLE_WEBGPU_MATRIX_VERSION = "1.0.0";
|
|
5
|
+
var SHADER_QUALIFICATION_FIXTURE_VERSION = "1.0.0";
|
|
6
|
+
var SHADER_QUALIFICATION_BUNDLE_VERSION = "1.0.0";
|
|
7
|
+
var SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES = [
|
|
8
|
+
Object.freeze({
|
|
9
|
+
matrixId: "stable-webgpu",
|
|
10
|
+
matrixVersion: "2026-07-13",
|
|
11
|
+
matrixSha256: "9b47ff8162b055d49e38c4fe90b9074992ab8c9e1125926e936f8122e6119fd8"
|
|
12
|
+
})
|
|
13
|
+
];
|
|
14
|
+
Object.freeze(SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES);
|
|
15
|
+
var SUPPORTED_ADDITIVE_WEBGPU_MATRIX_POLICIES = Object.freeze([]);
|
|
16
|
+
|
|
17
|
+
// src/canonical-json.ts
|
|
18
|
+
function isPlainObject(value) {
|
|
19
|
+
const prototype = Object.getPrototypeOf(value);
|
|
20
|
+
return prototype === Object.prototype || prototype === null;
|
|
21
|
+
}
|
|
22
|
+
function assertUnicodeScalarString(value, path2) {
|
|
23
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
24
|
+
const code = value.charCodeAt(index);
|
|
25
|
+
if (code >= 55296 && code <= 56319) {
|
|
26
|
+
const next = value.charCodeAt(index + 1);
|
|
27
|
+
if (!(next >= 56320 && next <= 57343)) throw new TypeError(`${path2} contains an unpaired UTF-16 surrogate.`);
|
|
28
|
+
index += 1;
|
|
29
|
+
} else if (code >= 56320 && code <= 57343) throw new TypeError(`${path2} contains an unpaired UTF-16 surrogate.`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function canonicalizeGpuContract(value) {
|
|
33
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
34
|
+
const visit = (current, path2) => {
|
|
35
|
+
if (current === null) return "null";
|
|
36
|
+
if (typeof current === "string" || typeof current === "boolean") {
|
|
37
|
+
if (typeof current === "string") assertUnicodeScalarString(current, path2);
|
|
38
|
+
return JSON.stringify(current);
|
|
39
|
+
}
|
|
40
|
+
if (typeof current === "number") {
|
|
41
|
+
if (!Number.isFinite(current)) {
|
|
42
|
+
throw new TypeError(`${path2} contains a non-finite number.`);
|
|
43
|
+
}
|
|
44
|
+
return Object.is(current, -0) ? "0" : JSON.stringify(current);
|
|
45
|
+
}
|
|
46
|
+
if (typeof current !== "object") {
|
|
47
|
+
throw new TypeError(`${path2} contains a value that JSON cannot represent.`);
|
|
48
|
+
}
|
|
49
|
+
if (ancestors.has(current)) {
|
|
50
|
+
throw new TypeError(`${path2} contains a circular reference.`);
|
|
51
|
+
}
|
|
52
|
+
ancestors.add(current);
|
|
53
|
+
try {
|
|
54
|
+
if (Array.isArray(current)) {
|
|
55
|
+
return `[${current.map((item, index) => visit(item, `${path2}[${index}]`)).join(",")}]`;
|
|
56
|
+
}
|
|
57
|
+
if (!isPlainObject(current)) {
|
|
58
|
+
throw new TypeError(`${path2} must contain only plain JSON objects.`);
|
|
59
|
+
}
|
|
60
|
+
const keys2 = Object.keys(current).sort();
|
|
61
|
+
const properties = keys2.map((key) => {
|
|
62
|
+
assertUnicodeScalarString(key, `${path2} key`);
|
|
63
|
+
const member = current[key];
|
|
64
|
+
if (member === void 0) {
|
|
65
|
+
throw new TypeError(`${path2}.${key} is undefined.`);
|
|
66
|
+
}
|
|
67
|
+
return `${JSON.stringify(key)}:${visit(member, `${path2}.${key}`)}`;
|
|
68
|
+
});
|
|
69
|
+
return `{${properties.join(",")}}`;
|
|
70
|
+
} finally {
|
|
71
|
+
ancestors.delete(current);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return visit(value, "$root");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/hash.ts
|
|
78
|
+
var SHA256_PATTERN = /^[a-f0-9]{64}$/u;
|
|
79
|
+
function asSha256Hex(value) {
|
|
80
|
+
if (!SHA256_PATTERN.test(value)) {
|
|
81
|
+
throw new TypeError("SHA-256 values must be lowercase 64-character hexadecimal strings.");
|
|
82
|
+
}
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
async function computeSha256(value) {
|
|
86
|
+
const subtle = globalThis.crypto?.subtle;
|
|
87
|
+
if (!subtle) {
|
|
88
|
+
throw new Error("Web Crypto SHA-256 support is required.");
|
|
89
|
+
}
|
|
90
|
+
const bytes = typeof value === "string" ? new TextEncoder().encode(value) : value;
|
|
91
|
+
const digest = await subtle.digest("SHA-256", bytes);
|
|
92
|
+
return asSha256Hex(
|
|
93
|
+
Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("")
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/manifest-validation.ts
|
|
98
|
+
var stages = ["vertex", "fragment", "compute"];
|
|
99
|
+
function object(value, path2) {
|
|
100
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path2} must be an object.`);
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
function exact(value, keys2, path2) {
|
|
104
|
+
const allowed = new Set(keys2);
|
|
105
|
+
for (const key of Object.keys(value)) if (!allowed.has(key)) throw new TypeError(`${path2}.${key} is not part of this contract version.`);
|
|
106
|
+
for (const key of keys2) if (!(key in value)) throw new TypeError(`${path2}.${key} is required.`);
|
|
107
|
+
}
|
|
108
|
+
function text(value, path2, maximum = 512) {
|
|
109
|
+
if (typeof value !== "string" || value.length === 0 || value.length > maximum || [...value].some((character) => character.charCodeAt(0) <= 31)) {
|
|
110
|
+
throw new TypeError(`${path2} must be a bounded non-empty string without control characters.`);
|
|
111
|
+
}
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
function token(value, path2) {
|
|
115
|
+
const result = text(value, path2, 160);
|
|
116
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/u.test(result) || result.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
function enumeration(value, values, path2) {
|
|
120
|
+
if (!values.includes(value)) throw new TypeError(`${path2} is invalid.`);
|
|
121
|
+
return value;
|
|
122
|
+
}
|
|
123
|
+
function integer(value, path2, minimum = 0, maximum = 4294967295) {
|
|
124
|
+
if (!Number.isSafeInteger(value) || value < minimum || value > maximum) {
|
|
125
|
+
throw new TypeError(`${path2} must be an integer from ${minimum} through ${maximum}.`);
|
|
126
|
+
}
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
function finite(value, path2) {
|
|
130
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new TypeError(`${path2} must be finite.`);
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
function array(value, path2, maximum = 4096) {
|
|
134
|
+
if (!Array.isArray(value) || value.length > maximum) throw new TypeError(`${path2} must be a bounded array.`);
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
function nullableToken(value, path2) {
|
|
138
|
+
return value === null ? null : token(value, path2);
|
|
139
|
+
}
|
|
140
|
+
function unique(values, key, path2) {
|
|
141
|
+
const seen = /* @__PURE__ */ new Set();
|
|
142
|
+
for (const value of values) {
|
|
143
|
+
const identity = key(value);
|
|
144
|
+
if (seen.has(identity)) throw new TypeError(`${path2} contains duplicate ${identity}.`);
|
|
145
|
+
seen.add(identity);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function bindingResource(value, path2) {
|
|
149
|
+
const input = object(value, path2);
|
|
150
|
+
const kind = enumeration(input.kind, ["buffer", "sampler", "texture", "storage-texture", "external-texture"], `${path2}.kind`);
|
|
151
|
+
if (kind === "buffer") {
|
|
152
|
+
exact(input, ["kind", "addressSpace", "access", "recordName", "minimumBindingSize"], path2);
|
|
153
|
+
enumeration(input.addressSpace, ["uniform", "storage"], `${path2}.addressSpace`);
|
|
154
|
+
enumeration(input.access, ["read", "write", "read_write"], `${path2}.access`);
|
|
155
|
+
if (input.addressSpace === "uniform" && input.access !== "read") throw new TypeError(`${path2}.access must be read for uniform buffers.`);
|
|
156
|
+
nullableToken(input.recordName, `${path2}.recordName`);
|
|
157
|
+
integer(input.minimumBindingSize, `${path2}.minimumBindingSize`);
|
|
158
|
+
} else if (kind === "sampler") {
|
|
159
|
+
exact(input, ["kind", "samplerType"], path2);
|
|
160
|
+
enumeration(input.samplerType, ["filtering", "non-filtering", "comparison"], `${path2}.samplerType`);
|
|
161
|
+
} else if (kind === "texture") {
|
|
162
|
+
exact(input, ["kind", "sampleType", "viewDimension", "multisampled"], path2);
|
|
163
|
+
enumeration(input.sampleType, ["float", "unfilterable-float", "depth", "sint", "uint"], `${path2}.sampleType`);
|
|
164
|
+
enumeration(input.viewDimension, ["1d", "2d", "2d-array", "cube", "cube-array", "3d"], `${path2}.viewDimension`);
|
|
165
|
+
if (typeof input.multisampled !== "boolean") throw new TypeError(`${path2}.multisampled must be boolean.`);
|
|
166
|
+
} else if (kind === "storage-texture") {
|
|
167
|
+
exact(input, ["kind", "access", "format", "viewDimension"], path2);
|
|
168
|
+
enumeration(input.access, ["write-only", "read-only", "read-write"], `${path2}.access`);
|
|
169
|
+
token(input.format, `${path2}.format`);
|
|
170
|
+
enumeration(input.viewDimension, ["1d", "2d", "2d-array", "3d"], `${path2}.viewDimension`);
|
|
171
|
+
} else exact(input, ["kind"], path2);
|
|
172
|
+
return input;
|
|
173
|
+
}
|
|
174
|
+
function visibility(value, path2) {
|
|
175
|
+
const result = array(value, path2, 3).map((item, index) => enumeration(item, stages, `${path2}[${index}]`));
|
|
176
|
+
unique(result, String, path2);
|
|
177
|
+
if (result.length === 0) throw new TypeError(`${path2} must include at least one shader stage.`);
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
function programmable(value, path2, moduleIds) {
|
|
181
|
+
const input = object(value, path2);
|
|
182
|
+
exact(input, ["moduleId", "entryPoint", "constants"], path2);
|
|
183
|
+
const moduleId = token(input.moduleId, `${path2}.moduleId`);
|
|
184
|
+
if (!moduleIds.has(moduleId)) throw new TypeError(`${path2}.moduleId is not in modules.`);
|
|
185
|
+
token(input.entryPoint, `${path2}.entryPoint`);
|
|
186
|
+
const constants = object(input.constants, `${path2}.constants`);
|
|
187
|
+
for (const [name, value2] of Object.entries(constants)) {
|
|
188
|
+
token(name, `${path2}.constants key`);
|
|
189
|
+
if (typeof value2 !== "boolean") finite(value2, `${path2}.constants.${name}`);
|
|
190
|
+
}
|
|
191
|
+
return input;
|
|
192
|
+
}
|
|
193
|
+
function pipeline(value, path2, moduleIds) {
|
|
194
|
+
const input = object(value, path2);
|
|
195
|
+
const kind = enumeration(input.kind, ["compute", "render"], `${path2}.kind`);
|
|
196
|
+
const common = kind === "compute" ? ["kind", "pipelineId", "layout", "compute"] : ["kind", "pipelineId", "layout", "vertex", "fragment", "vertexBuffers", "primitive", "colorTargets", "depthStencil", "multisample"];
|
|
197
|
+
exact(input, common, path2);
|
|
198
|
+
token(input.pipelineId, `${path2}.pipelineId`);
|
|
199
|
+
const layout = object(input.layout, `${path2}.layout`);
|
|
200
|
+
exact(layout, ["bindGroups"], `${path2}.layout`);
|
|
201
|
+
const groups = array(layout.bindGroups, `${path2}.layout.bindGroups`);
|
|
202
|
+
const groupIds = [];
|
|
203
|
+
groups.forEach((value2, groupIndex) => {
|
|
204
|
+
const groupPath = `${path2}.layout.bindGroups[${groupIndex}]`;
|
|
205
|
+
const group = object(value2, groupPath);
|
|
206
|
+
exact(group, ["group", "entries"], groupPath);
|
|
207
|
+
const groupId = integer(group.group, `${groupPath}.group`);
|
|
208
|
+
groupIds.push(groupId);
|
|
209
|
+
const entries = array(group.entries, `${groupPath}.entries`);
|
|
210
|
+
const bindingIds = [];
|
|
211
|
+
entries.forEach((entryValue, entryIndex) => {
|
|
212
|
+
const entryPath = `${groupPath}.entries[${entryIndex}]`;
|
|
213
|
+
const entry = object(entryValue, entryPath);
|
|
214
|
+
exact(entry, ["group", "binding", "resource", "visibility"], entryPath);
|
|
215
|
+
if (integer(entry.group, `${entryPath}.group`) !== groupId) throw new TypeError(`${entryPath}.group differs from its parent.`);
|
|
216
|
+
bindingIds.push(integer(entry.binding, `${entryPath}.binding`));
|
|
217
|
+
bindingResource(entry.resource, `${entryPath}.resource`);
|
|
218
|
+
visibility(entry.visibility, `${entryPath}.visibility`);
|
|
219
|
+
});
|
|
220
|
+
unique(bindingIds, String, `${groupPath}.entries`);
|
|
221
|
+
});
|
|
222
|
+
unique(groupIds, String, `${path2}.layout.bindGroups`);
|
|
223
|
+
[...groupIds].sort((a, b) => a - b).forEach((group, index) => {
|
|
224
|
+
if (group !== index) throw new TypeError(`${path2}.layout.bindGroups must be contiguous from zero.`);
|
|
225
|
+
});
|
|
226
|
+
if (kind === "compute") programmable(input.compute, `${path2}.compute`, moduleIds);
|
|
227
|
+
else {
|
|
228
|
+
programmable(input.vertex, `${path2}.vertex`, moduleIds);
|
|
229
|
+
if (input.fragment !== null) programmable(input.fragment, `${path2}.fragment`, moduleIds);
|
|
230
|
+
array(input.vertexBuffers, `${path2}.vertexBuffers`, 16).forEach((value2, bufferIndex) => {
|
|
231
|
+
const bufferPath = `${path2}.vertexBuffers[${bufferIndex}]`;
|
|
232
|
+
const buffer = object(value2, bufferPath);
|
|
233
|
+
exact(buffer, ["arrayStride", "stepMode", "attributes"], bufferPath);
|
|
234
|
+
integer(buffer.arrayStride, `${bufferPath}.arrayStride`, 0, 2048);
|
|
235
|
+
enumeration(buffer.stepMode, ["vertex", "instance"], `${bufferPath}.stepMode`);
|
|
236
|
+
array(buffer.attributes, `${bufferPath}.attributes`, 16).forEach((value3, attributeIndex) => {
|
|
237
|
+
const attributePath = `${bufferPath}.attributes[${attributeIndex}]`;
|
|
238
|
+
const attribute = object(value3, attributePath);
|
|
239
|
+
exact(attribute, ["format", "offset", "shaderLocation", "semantic"], attributePath);
|
|
240
|
+
token(attribute.format, `${attributePath}.format`);
|
|
241
|
+
integer(attribute.offset, `${attributePath}.offset`);
|
|
242
|
+
integer(attribute.shaderLocation, `${attributePath}.shaderLocation`);
|
|
243
|
+
nullableToken(attribute.semantic, `${attributePath}.semantic`);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
const primitive = object(input.primitive, `${path2}.primitive`);
|
|
247
|
+
exact(primitive, ["topology", "stripIndexFormat", "frontFace", "cullMode", "unclippedDepth"], `${path2}.primitive`);
|
|
248
|
+
const topology = enumeration(primitive.topology, ["point-list", "line-list", "line-strip", "triangle-list", "triangle-strip"], `${path2}.primitive.topology`);
|
|
249
|
+
if (primitive.stripIndexFormat !== null) enumeration(primitive.stripIndexFormat, ["uint16", "uint32"], `${path2}.primitive.stripIndexFormat`);
|
|
250
|
+
if (primitive.stripIndexFormat !== null && topology !== "line-strip" && topology !== "triangle-strip") throw new TypeError(`${path2}.primitive.stripIndexFormat is only valid for strip topologies.`);
|
|
251
|
+
enumeration(primitive.frontFace, ["ccw", "cw"], `${path2}.primitive.frontFace`);
|
|
252
|
+
enumeration(primitive.cullMode, ["none", "front", "back"], `${path2}.primitive.cullMode`);
|
|
253
|
+
if (typeof primitive.unclippedDepth !== "boolean") throw new TypeError(`${path2}.primitive.unclippedDepth must be boolean.`);
|
|
254
|
+
const compare = ["never", "less", "equal", "less-equal", "greater", "not-equal", "greater-equal", "always"];
|
|
255
|
+
const operations = ["keep", "zero", "replace", "invert", "increment-clamp", "decrement-clamp", "increment-wrap", "decrement-wrap"];
|
|
256
|
+
const factors = ["zero", "one", "src", "one-minus-src", "src-alpha", "one-minus-src-alpha", "dst", "one-minus-dst", "dst-alpha", "one-minus-dst-alpha", "src-alpha-saturated", "constant", "one-minus-constant"];
|
|
257
|
+
const parseBlend = (value2, label) => {
|
|
258
|
+
const component = object(value2, label);
|
|
259
|
+
exact(component, ["operation", "srcFactor", "dstFactor"], label);
|
|
260
|
+
enumeration(component.operation, ["add", "subtract", "reverse-subtract", "min", "max"], `${label}.operation`);
|
|
261
|
+
enumeration(component.srcFactor, factors, `${label}.srcFactor`);
|
|
262
|
+
enumeration(component.dstFactor, factors, `${label}.dstFactor`);
|
|
263
|
+
};
|
|
264
|
+
const colorTargets = array(input.colorTargets, `${path2}.colorTargets`, 8);
|
|
265
|
+
if (input.fragment === null && colorTargets.length !== 0) throw new TypeError(`${path2}.colorTargets must be empty when fragment is null.`);
|
|
266
|
+
colorTargets.forEach((value2, index) => {
|
|
267
|
+
const label = `${path2}.colorTargets[${index}]`;
|
|
268
|
+
const target = object(value2, label);
|
|
269
|
+
exact(target, ["format", "blend", "writeMask"], label);
|
|
270
|
+
token(target.format, `${label}.format`);
|
|
271
|
+
integer(target.writeMask, `${label}.writeMask`, 0, 15);
|
|
272
|
+
if (target.blend !== null) {
|
|
273
|
+
const blend = object(target.blend, `${label}.blend`);
|
|
274
|
+
exact(blend, ["color", "alpha"], `${label}.blend`);
|
|
275
|
+
parseBlend(blend.color, `${label}.blend.color`);
|
|
276
|
+
parseBlend(blend.alpha, `${label}.blend.alpha`);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
const parseStencil = (value2, label) => {
|
|
280
|
+
const stencil = object(value2, label);
|
|
281
|
+
exact(stencil, ["compare", "failOp", "depthFailOp", "passOp"], label);
|
|
282
|
+
enumeration(stencil.compare, compare, `${label}.compare`);
|
|
283
|
+
enumeration(stencil.failOp, operations, `${label}.failOp`);
|
|
284
|
+
enumeration(stencil.depthFailOp, operations, `${label}.depthFailOp`);
|
|
285
|
+
enumeration(stencil.passOp, operations, `${label}.passOp`);
|
|
286
|
+
};
|
|
287
|
+
if (input.depthStencil !== null) {
|
|
288
|
+
const depth = object(input.depthStencil, `${path2}.depthStencil`);
|
|
289
|
+
exact(depth, ["format", "depthWriteEnabled", "depthCompare", "stencilFront", "stencilBack", "stencilReadMask", "stencilWriteMask", "depthBias", "depthBiasSlopeScale", "depthBiasClamp"], `${path2}.depthStencil`);
|
|
290
|
+
token(depth.format, `${path2}.depthStencil.format`);
|
|
291
|
+
if (typeof depth.depthWriteEnabled !== "boolean") throw new TypeError(`${path2}.depthStencil.depthWriteEnabled must be boolean.`);
|
|
292
|
+
enumeration(depth.depthCompare, compare, `${path2}.depthStencil.depthCompare`);
|
|
293
|
+
parseStencil(depth.stencilFront, `${path2}.depthStencil.stencilFront`);
|
|
294
|
+
parseStencil(depth.stencilBack, `${path2}.depthStencil.stencilBack`);
|
|
295
|
+
integer(depth.stencilReadMask, `${path2}.depthStencil.stencilReadMask`);
|
|
296
|
+
integer(depth.stencilWriteMask, `${path2}.depthStencil.stencilWriteMask`);
|
|
297
|
+
integer(depth.depthBias, `${path2}.depthStencil.depthBias`, -2147483648, 2147483647);
|
|
298
|
+
finite(depth.depthBiasSlopeScale, `${path2}.depthStencil.depthBiasSlopeScale`);
|
|
299
|
+
finite(depth.depthBiasClamp, `${path2}.depthStencil.depthBiasClamp`);
|
|
300
|
+
}
|
|
301
|
+
const multisample = object(input.multisample, `${path2}.multisample`);
|
|
302
|
+
exact(multisample, ["count", "mask", "alphaToCoverageEnabled"], `${path2}.multisample`);
|
|
303
|
+
enumeration(multisample.count, [1, 4], `${path2}.multisample.count`);
|
|
304
|
+
integer(multisample.mask, `${path2}.multisample.mask`);
|
|
305
|
+
if (typeof multisample.alphaToCoverageEnabled !== "boolean") throw new TypeError(`${path2}.multisample.alphaToCoverageEnabled must be boolean.`);
|
|
306
|
+
if (multisample.alphaToCoverageEnabled && multisample.count === 1) throw new TypeError(`${path2}.multisample.alphaToCoverageEnabled requires multisampling.`);
|
|
307
|
+
}
|
|
308
|
+
return input;
|
|
309
|
+
}
|
|
310
|
+
function parseSerializableGpuPipelineDescriptors(value, moduleIds, path2 = "pipelines") {
|
|
311
|
+
const parsed = array(value, path2).map((item, index) => pipeline(item, `${path2}[${index}]`, new Set(moduleIds)));
|
|
312
|
+
unique(parsed, (item) => item.pipelineId, path2);
|
|
313
|
+
return freeze(parsed);
|
|
314
|
+
}
|
|
315
|
+
function freeze(value) {
|
|
316
|
+
if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
|
|
317
|
+
for (const child of Object.values(value)) freeze(child);
|
|
318
|
+
return Object.freeze(value);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// src/testing/inventory.ts
|
|
322
|
+
var SAFE_PATH = /^(?!\/)(?!.*\/\/)(?!.*(?:^|\/)\.\.(?:\/|$))[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/u;
|
|
323
|
+
function issue(code, message, path2) {
|
|
324
|
+
return { code, severity: "error", message, ...path2 ? { path: path2 } : {} };
|
|
325
|
+
}
|
|
326
|
+
function object2(value) {
|
|
327
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
328
|
+
}
|
|
329
|
+
function exactKeys(value, keys2) {
|
|
330
|
+
const expected = new Set(keys2);
|
|
331
|
+
return Object.keys(value).every((key) => expected.has(key)) && keys2.every((key) => key in value);
|
|
332
|
+
}
|
|
333
|
+
function safeToken(value) {
|
|
334
|
+
return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,159}$/u.test(value) && !value.includes("..");
|
|
335
|
+
}
|
|
336
|
+
function validSha(value) {
|
|
337
|
+
try {
|
|
338
|
+
asSha256Hex(String(value));
|
|
339
|
+
return true;
|
|
340
|
+
} catch {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function defineShaderCompileUnit(unit) {
|
|
345
|
+
return Object.freeze(unit);
|
|
346
|
+
}
|
|
347
|
+
function validateCompileUnitInventory(value) {
|
|
348
|
+
const envelope = object2(value);
|
|
349
|
+
const candidate = envelope && "inventory" in envelope ? object2(value.inventory) : envelope;
|
|
350
|
+
const diagnostics = [];
|
|
351
|
+
if (!candidate || !exactKeys(candidate, ["contractVersion", "fragments", "compileUnits"])) {
|
|
352
|
+
return { ok: false, diagnostics: [issue("invalid-contract", "Compile-unit inventory has unknown or missing fields.")] };
|
|
353
|
+
}
|
|
354
|
+
if (candidate.contractVersion !== SHADER_COMPILE_UNIT_VERSION) {
|
|
355
|
+
diagnostics.push(issue("invalid-contract", "Unsupported compile-unit inventory version.", "contractVersion"));
|
|
356
|
+
}
|
|
357
|
+
if (!Array.isArray(candidate.fragments) || !Array.isArray(candidate.compileUnits)) {
|
|
358
|
+
diagnostics.push(issue("invalid-contract", "Inventory fragments and compileUnits must be arrays."));
|
|
359
|
+
return { ok: false, diagnostics };
|
|
360
|
+
}
|
|
361
|
+
if (candidate.fragments.length > 1e4 || candidate.compileUnits.length > 1e4) {
|
|
362
|
+
diagnostics.push(issue("invalid-contract", "Inventory exceeds the bounded item count."));
|
|
363
|
+
return { ok: false, diagnostics };
|
|
364
|
+
}
|
|
365
|
+
const fragmentIds = /* @__PURE__ */ new Set();
|
|
366
|
+
for (const [index, raw] of candidate.fragments.entries()) {
|
|
367
|
+
const path2 = `fragments[${index}]`;
|
|
368
|
+
const fragment = object2(raw);
|
|
369
|
+
if (!fragment || !exactKeys(fragment, ["fragmentId", "path", "sha256"])) {
|
|
370
|
+
diagnostics.push(issue("invalid-contract", "Fragment has unknown or missing fields.", path2));
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (!safeToken(fragment.fragmentId) || fragmentIds.has(fragment.fragmentId)) {
|
|
374
|
+
diagnostics.push(issue("invalid-contract", "Fragment IDs must be unique safe tokens.", `${path2}.fragmentId`));
|
|
375
|
+
} else fragmentIds.add(fragment.fragmentId);
|
|
376
|
+
if (typeof fragment.path !== "string" || !SAFE_PATH.test(fragment.path) || !fragment.path.endsWith(".wgsl")) {
|
|
377
|
+
diagnostics.push(issue("invalid-contract", "Fragment path must remain inside the data-only bundle.", `${path2}.path`));
|
|
378
|
+
}
|
|
379
|
+
if (!validSha(fragment.sha256)) diagnostics.push(issue("invalid-contract", "Fragment digest is invalid.", `${path2}.sha256`));
|
|
380
|
+
}
|
|
381
|
+
const covered = /* @__PURE__ */ new Set();
|
|
382
|
+
const unitIds = /* @__PURE__ */ new Set();
|
|
383
|
+
for (const [index, raw] of candidate.compileUnits.entries()) {
|
|
384
|
+
const path2 = `compileUnits[${index}]`;
|
|
385
|
+
const unit = object2(raw);
|
|
386
|
+
const keys2 = [
|
|
387
|
+
"contractVersion",
|
|
388
|
+
"compileUnitId",
|
|
389
|
+
"fragmentIds",
|
|
390
|
+
"modules",
|
|
391
|
+
"entryPoints",
|
|
392
|
+
"pipelines",
|
|
393
|
+
"interfaceRef",
|
|
394
|
+
"overrideValues",
|
|
395
|
+
"qualificationFixture"
|
|
396
|
+
];
|
|
397
|
+
if (!unit || !exactKeys(unit, keys2)) {
|
|
398
|
+
diagnostics.push(issue("invalid-contract", "Compile unit has unknown or missing fields.", path2));
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
if (unit.contractVersion !== SHADER_COMPILE_UNIT_VERSION || !safeToken(unit.compileUnitId) || unitIds.has(String(unit.compileUnitId))) {
|
|
402
|
+
diagnostics.push(issue("invalid-contract", "Compile-unit identity/version is invalid or duplicated.", path2));
|
|
403
|
+
} else unitIds.add(unit.compileUnitId);
|
|
404
|
+
if (!Array.isArray(unit.fragmentIds) || unit.fragmentIds.length === 0 || new Set(unit.fragmentIds).size !== unit.fragmentIds.length) {
|
|
405
|
+
diagnostics.push(issue("invalid-contract", "Compile unit requires unique fragment IDs.", `${path2}.fragmentIds`));
|
|
406
|
+
} else {
|
|
407
|
+
for (const id of unit.fragmentIds) {
|
|
408
|
+
if (typeof id !== "string" || !fragmentIds.has(id)) diagnostics.push(issue("invalid-contract", `Compile unit references unknown fragment ${String(id)}.`, `${path2}.fragmentIds`));
|
|
409
|
+
else covered.add(id);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
if (!Array.isArray(unit.modules) || unit.modules.length === 0 || !Array.isArray(unit.entryPoints) || unit.entryPoints.length === 0 || !Array.isArray(unit.pipelines) || unit.pipelines.length === 0) {
|
|
413
|
+
diagnostics.push(issue("invalid-contract", "Compile unit requires modules, entry points, and explicit pipelines.", path2));
|
|
414
|
+
}
|
|
415
|
+
const modules = Array.isArray(unit.modules) ? unit.modules : [];
|
|
416
|
+
const moduleIds = /* @__PURE__ */ new Set();
|
|
417
|
+
for (const [moduleIndex, moduleRaw] of modules.entries()) {
|
|
418
|
+
const module = object2(moduleRaw);
|
|
419
|
+
if (!module || !exactKeys(module, ["moduleId", "sha256", "assembly"]) || !safeToken(module.moduleId) || moduleIds.has(String(module.moduleId)) || !validSha(module.sha256)) {
|
|
420
|
+
diagnostics.push(issue("invalid-contract", "Compile-unit module reference is invalid or duplicated.", `${path2}.modules[${moduleIndex}]`));
|
|
421
|
+
} else {
|
|
422
|
+
moduleIds.add(module.moduleId);
|
|
423
|
+
const assembly = object2(module.assembly);
|
|
424
|
+
if (!assembly || !exactKeys(assembly, ["kind", "fragmentIds"]) || assembly.kind !== "concat-v1" || !Array.isArray(assembly.fragmentIds) || assembly.fragmentIds.length === 0 || new Set(assembly.fragmentIds).size !== assembly.fragmentIds.length || assembly.fragmentIds.some((id) => typeof id !== "string" || !fragmentIds.has(id))) {
|
|
425
|
+
diagnostics.push(issue("invalid-contract", "Module requires a non-vacuous concat-v1 recipe over exact inventory fragments.", `${path2}.modules[${moduleIndex}].assembly`));
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const recipeFragments = new Set(modules.flatMap((moduleRaw) => {
|
|
430
|
+
const module = object2(moduleRaw);
|
|
431
|
+
const assembly = module ? object2(module.assembly) : null;
|
|
432
|
+
return Array.isArray(assembly?.fragmentIds) ? assembly.fragmentIds.filter((id) => typeof id === "string") : [];
|
|
433
|
+
}));
|
|
434
|
+
if (Array.isArray(unit.fragmentIds) && [...recipeFragments].sort().join("\n") !== [...unit.fragmentIds].sort().join("\n")) {
|
|
435
|
+
diagnostics.push(issue("invalid-contract", "Compile-unit fragment claims must exactly equal deterministic assembly inputs.", `${path2}.fragmentIds`));
|
|
436
|
+
}
|
|
437
|
+
const entryKeys = /* @__PURE__ */ new Set();
|
|
438
|
+
if (Array.isArray(unit.entryPoints)) for (const [entryIndex, entryRaw] of unit.entryPoints.entries()) {
|
|
439
|
+
const entry = object2(entryRaw);
|
|
440
|
+
const entryPath = `${path2}.entryPoints[${entryIndex}]`;
|
|
441
|
+
if (!entry || !exactKeys(entry, ["moduleId", "name", "stage"]) || !safeToken(entry.moduleId) || !moduleIds.has(String(entry.moduleId)) || !safeToken(entry.name) || !["vertex", "fragment", "compute"].includes(String(entry.stage))) diagnostics.push(issue("invalid-contract", "Compile-unit entry point is invalid.", entryPath));
|
|
442
|
+
else {
|
|
443
|
+
const key = `${entry.moduleId}:${entry.stage}:${entry.name}`;
|
|
444
|
+
if (entryKeys.has(key)) diagnostics.push(issue("invalid-contract", "Compile-unit entry point is duplicated.", entryPath));
|
|
445
|
+
entryKeys.add(key);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
try {
|
|
449
|
+
const pipelines = parseSerializableGpuPipelineDescriptors(unit.pipelines, [...moduleIds], `${path2}.pipelines`);
|
|
450
|
+
const usedEntries = /* @__PURE__ */ new Set();
|
|
451
|
+
for (const pipeline2 of pipelines) {
|
|
452
|
+
if (pipeline2.kind === "compute") usedEntries.add(`${pipeline2.compute.moduleId}:compute:${pipeline2.compute.entryPoint}`);
|
|
453
|
+
else {
|
|
454
|
+
usedEntries.add(`${pipeline2.vertex.moduleId}:vertex:${pipeline2.vertex.entryPoint}`);
|
|
455
|
+
if (pipeline2.fragment) usedEntries.add(`${pipeline2.fragment.moduleId}:fragment:${pipeline2.fragment.entryPoint}`);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
for (const key of usedEntries) if (!entryKeys.has(key)) diagnostics.push(issue("invalid-contract", `Pipeline references undeclared compile-unit entry point ${key}.`, `${path2}.pipelines`));
|
|
459
|
+
for (const key of entryKeys) if (!usedEntries.has(key)) diagnostics.push(issue("invalid-contract", `Compile-unit entry point ${key} is not used by a pipeline.`, `${path2}.entryPoints`));
|
|
460
|
+
const overrideValues = object2(unit.overrideValues);
|
|
461
|
+
if (!overrideValues) diagnostics.push(issue("invalid-contract", "overrideValues must be an object.", `${path2}.overrideValues`));
|
|
462
|
+
else {
|
|
463
|
+
for (const [name, value2] of Object.entries(overrideValues)) if (!safeToken(name) || typeof value2 !== "boolean" && (typeof value2 !== "number" || !Number.isFinite(value2))) diagnostics.push(issue("invalid-contract", `Override value ${name} is invalid.`, `${path2}.overrideValues`));
|
|
464
|
+
const derived = /* @__PURE__ */ new Map();
|
|
465
|
+
for (const descriptor of pipelines) {
|
|
466
|
+
const stages2 = descriptor.kind === "compute" ? [descriptor.compute] : [descriptor.vertex, ...descriptor.fragment ? [descriptor.fragment] : []];
|
|
467
|
+
for (const stage of stages2) for (const [name, constant] of Object.entries(stage.constants)) {
|
|
468
|
+
const previous = derived.get(name);
|
|
469
|
+
if (previous !== void 0 && !Object.is(previous, constant)) diagnostics.push(issue("invalid-contract", `Override ${name} has conflicting stage values.`, `${path2}.pipelines`));
|
|
470
|
+
else derived.set(name, constant);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const exactOverrides = Object.fromEntries([...derived.entries()].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0));
|
|
474
|
+
if (canonicalizeGpuContract(overrideValues) !== canonicalizeGpuContract(exactOverrides)) diagnostics.push(issue("invalid-contract", "overrideValues must exactly equal the union of programmable-stage constants.", `${path2}.overrideValues`));
|
|
475
|
+
}
|
|
476
|
+
} catch (cause) {
|
|
477
|
+
diagnostics.push(issue("invalid-contract", cause instanceof Error ? cause.message : "Compile-unit pipelines are invalid.", `${path2}.pipelines`));
|
|
478
|
+
}
|
|
479
|
+
const interfaceRef = object2(unit.interfaceRef);
|
|
480
|
+
if (!interfaceRef || !exactKeys(interfaceRef, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"]) || !safeToken(interfaceRef.interfaceId) || !safeToken(interfaceRef.interfaceVersion) || typeof interfaceRef.manifestUri !== "string" || !interfaceRef.manifestUri.startsWith("https://") || !validSha(interfaceRef.manifestSha256) || !validSha(interfaceRef.interfaceAbiHash) || !validSha(interfaceRef.modelAbiHash)) {
|
|
481
|
+
diagnostics.push(issue("invalid-contract", "Compile-unit interfaceRef is invalid.", `${path2}.interfaceRef`));
|
|
482
|
+
}
|
|
483
|
+
const fixture = object2(unit.qualificationFixture);
|
|
484
|
+
if (!fixture || !exactKeys(fixture, ["fixtureId", "path", "sha256"]) || !safeToken(fixture.fixtureId) || typeof fixture.path !== "string" || !SAFE_PATH.test(fixture.path) || !fixture.path.endsWith(".json") || !validSha(fixture.sha256)) {
|
|
485
|
+
diagnostics.push(issue("invalid-contract", "Compile unit requires an exact declarative qualification fixture.", `${path2}.qualificationFixture`));
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
for (const fragmentId of fragmentIds) {
|
|
489
|
+
if (!covered.has(fragmentId)) diagnostics.push(issue("uncovered-fragment", `WGSL fragment ${fragmentId} has no compile unit.`));
|
|
490
|
+
}
|
|
491
|
+
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: candidate };
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// src/testing/matrix.ts
|
|
495
|
+
function issue2(message, path2) {
|
|
496
|
+
return { code: "invalid-contract", severity: "error", message, ...path2 ? { path: path2 } : {} };
|
|
497
|
+
}
|
|
498
|
+
function object3(value) {
|
|
499
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
500
|
+
}
|
|
501
|
+
function keys(value, expected) {
|
|
502
|
+
const set = new Set(expected);
|
|
503
|
+
return Object.keys(value).every((key) => set.has(key)) && expected.every((key) => key in value);
|
|
504
|
+
}
|
|
505
|
+
var browserNames = /* @__PURE__ */ new Set(["chromium", "chrome", "edge", "firefox", "safari"]);
|
|
506
|
+
var osNames = /* @__PURE__ */ new Set(["ubuntu", "windows", "macos", "chromeos", "android", "ios", "ipados", "visionos"]);
|
|
507
|
+
var backends = /* @__PURE__ */ new Set(["swiftshader", "d3d12", "metal", "vulkan"]);
|
|
508
|
+
var automation = /* @__PURE__ */ new Set(["playwright", "webdriver", "device-farm", "safari-webdriver"]);
|
|
509
|
+
var VERSION_REQUIREMENTS = /* @__PURE__ */ new Map([
|
|
510
|
+
["android-adreno-chrome-vulkan", { kind: "minimum-major", value: 12 }],
|
|
511
|
+
["android-mali-chrome-vulkan", { kind: "minimum-major", value: 12 }],
|
|
512
|
+
["chromeos-arm-chrome-vulkan", { kind: "stable-channel", channel: "stable" }],
|
|
513
|
+
["chromeos-intel-chrome-vulkan", { kind: "stable-channel", channel: "stable" }],
|
|
514
|
+
["ios-iphone-safari-metal", { kind: "major", value: 26 }],
|
|
515
|
+
["ipados-ipad-safari-metal", { kind: "major", value: 26 }],
|
|
516
|
+
["macos-apple-chrome-metal", { kind: "major", value: 26 }],
|
|
517
|
+
["macos-apple-firefox-metal", { kind: "major", value: 26 }],
|
|
518
|
+
["macos-apple-safari-metal", { kind: "major", value: 26 }],
|
|
519
|
+
["swiftshader.chromium.ubuntu-x64", { kind: "exact", value: "24.04" }],
|
|
520
|
+
["ubuntu-intel-chrome-vulkan", { kind: "exact", value: "24.04" }],
|
|
521
|
+
["ubuntu-nvidia-chrome-vulkan", { kind: "exact", value: "24.04" }],
|
|
522
|
+
["visionos-safari-metal", { kind: "major", value: 26 }],
|
|
523
|
+
["win11-amd-firefox-d3d12", { kind: "major", value: 11 }],
|
|
524
|
+
["win11-intel-chrome-d3d12", { kind: "major", value: 11 }],
|
|
525
|
+
["win11-nvidia-edge-d3d12", { kind: "major", value: 11 }]
|
|
526
|
+
]);
|
|
527
|
+
var BASELINE = /* @__PURE__ */ new Map([
|
|
528
|
+
["android-adreno-chrome-vulkan", "chrome|android|arm64|physical|qualcomm|adreno|vulkan|playwright|self-hosted,Linux,X64,shader-validation,device-controller,physical-gpu,android-adreno,vulkan"],
|
|
529
|
+
["android-mali-chrome-vulkan", "chrome|android|arm64|physical|arm|mali|vulkan|playwright|self-hosted,Linux,X64,shader-validation,device-controller,physical-gpu,android-mali,vulkan"],
|
|
530
|
+
["chromeos-arm-chrome-vulkan", "chrome|chromeos|arm64|physical|arm|qualified-arm|vulkan|webdriver|self-hosted,Linux,X64,shader-validation,device-controller,physical-gpu,chromeos-arm,vulkan"],
|
|
531
|
+
["chromeos-intel-chrome-vulkan", "chrome|chromeos|x64|physical|intel|qualified-intel|vulkan|webdriver|self-hosted,Linux,X64,shader-validation,device-controller,physical-gpu,chromeos-intel,vulkan"],
|
|
532
|
+
["ios-iphone-safari-metal", "safari|ios|arm64|physical|apple|iphone|metal|safari-webdriver|self-hosted,macOS,ARM64,shader-validation,device-controller,physical-gpu,ios-safari,metal"],
|
|
533
|
+
["ipados-ipad-safari-metal", "safari|ipados|arm64|physical|apple|ipad|metal|safari-webdriver|self-hosted,macOS,ARM64,shader-validation,device-controller,physical-gpu,ipados-safari,metal"],
|
|
534
|
+
["macos-apple-chrome-metal", "chrome|macos|arm64|physical|apple|apple-silicon|metal|playwright|self-hosted,macOS,ARM64,shader-validation,physical-gpu,gpu-apple,metal"],
|
|
535
|
+
["macos-apple-firefox-metal", "firefox|macos|arm64|physical|apple|apple-silicon|metal|webdriver|self-hosted,macOS,ARM64,shader-validation,physical-gpu,gpu-apple,metal"],
|
|
536
|
+
["macos-apple-safari-metal", "safari|macos|arm64|physical|apple|apple-silicon|metal|safari-webdriver|self-hosted,macOS,ARM64,shader-validation,physical-gpu,gpu-apple,metal"],
|
|
537
|
+
["swiftshader.chromium.ubuntu-x64", "chromium|ubuntu|x64|software|google|swiftshader|swiftshader|playwright|ubuntu-24.04"],
|
|
538
|
+
["ubuntu-intel-chrome-vulkan", "chrome|ubuntu|x64|physical|intel|qualified-intel|vulkan|playwright|self-hosted,Linux,X64,shader-validation,physical-gpu,gpu-intel,vulkan"],
|
|
539
|
+
["ubuntu-nvidia-chrome-vulkan", "chrome|ubuntu|x64|physical|nvidia|qualified-nvidia|vulkan|playwright|self-hosted,Linux,X64,shader-validation,physical-gpu,gpu-nvidia,vulkan"],
|
|
540
|
+
["visionos-safari-metal", "safari|visionos|arm64|physical|apple|vision-pro|metal|safari-webdriver|self-hosted,macOS,ARM64,shader-validation,device-controller,physical-gpu,visionos-safari,metal"],
|
|
541
|
+
["win11-amd-firefox-d3d12", "firefox|windows|x64|physical|amd|qualified-amd|d3d12|webdriver|self-hosted,Windows,X64,shader-validation,physical-gpu,gpu-amd,d3d12"],
|
|
542
|
+
["win11-intel-chrome-d3d12", "chrome|windows|x64|physical|intel|qualified-intel|d3d12|playwright|self-hosted,Windows,X64,shader-validation,physical-gpu,gpu-intel,d3d12"],
|
|
543
|
+
["win11-nvidia-edge-d3d12", "edge|windows|x64|physical|nvidia|qualified-nvidia|d3d12|playwright|self-hosted,Windows,X64,shader-validation,physical-gpu,gpu-nvidia,d3d12"]
|
|
544
|
+
]);
|
|
545
|
+
function validateStableWebGpuMatrix(value) {
|
|
546
|
+
const matrix = object3(value);
|
|
547
|
+
const diagnostics = [];
|
|
548
|
+
if (!matrix || !keys(matrix, ["contractVersion", "matrixId", "version", "policy", "cells"])) {
|
|
549
|
+
return { ok: false, diagnostics: [issue2("Matrix has unknown or missing top-level fields.")] };
|
|
550
|
+
}
|
|
551
|
+
if (matrix.contractVersion !== STABLE_WEBGPU_MATRIX_VERSION) diagnostics.push(issue2("Unsupported matrix contract version.", "contractVersion"));
|
|
552
|
+
const stablePolicy = SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES[0];
|
|
553
|
+
if (matrix.matrixId !== stablePolicy?.matrixId || matrix.version !== stablePolicy.matrixVersion) diagnostics.push(issue2("Matrix identity/version differs from the supported universal policy."));
|
|
554
|
+
const policy = object3(matrix.policy);
|
|
555
|
+
const policyKeys = ["coverage", "unavailable", "skipped", "timeout", "deviceLoss", "requiredPhysicalCellCount", "requiredBlockingCellCount"];
|
|
556
|
+
if (!policy || !keys(policy, policyKeys) || policy.coverage !== "all-cells-required" || policy.unavailable !== "fail" || policy.skipped !== "fail" || policy.timeout !== "fail" || policy.deviceLoss !== "fail" || policy.requiredPhysicalCellCount !== 15 || policy.requiredBlockingCellCount !== 16) {
|
|
557
|
+
diagnostics.push(issue2("Matrix policy must fail closed with 15 physical and 16 blocking cells.", "policy"));
|
|
558
|
+
}
|
|
559
|
+
if (!Array.isArray(matrix.cells) || matrix.cells.length !== 16) {
|
|
560
|
+
diagnostics.push(issue2("Stable WebGPU matrix must contain exactly 16 cells.", "cells"));
|
|
561
|
+
return { ok: false, diagnostics };
|
|
562
|
+
}
|
|
563
|
+
const ids = /* @__PURE__ */ new Set();
|
|
564
|
+
let physical = 0;
|
|
565
|
+
let blocking = 0;
|
|
566
|
+
let software = 0;
|
|
567
|
+
for (const [index, raw] of matrix.cells.entries()) {
|
|
568
|
+
const path2 = `cells[${index}]`;
|
|
569
|
+
const cell = object3(raw);
|
|
570
|
+
if (!cell || !keys(cell, [
|
|
571
|
+
"cellId",
|
|
572
|
+
"runnerLabels",
|
|
573
|
+
"browser",
|
|
574
|
+
"os",
|
|
575
|
+
"adapter",
|
|
576
|
+
"automation",
|
|
577
|
+
"timeoutMs",
|
|
578
|
+
"blocking",
|
|
579
|
+
"countsTowardStableCoverage"
|
|
580
|
+
])) {
|
|
581
|
+
diagnostics.push(issue2("Matrix cell has unknown or missing fields.", path2));
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
if (typeof cell.cellId !== "string" || !/^[a-z0-9][a-z0-9._-]+$/u.test(cell.cellId) || ids.has(cell.cellId)) diagnostics.push(issue2("Cell ID is invalid or duplicated.", `${path2}.cellId`));
|
|
585
|
+
else ids.add(cell.cellId);
|
|
586
|
+
if (!Array.isArray(cell.runnerLabels) || cell.runnerLabels.length === 0 || cell.runnerLabels.some((label) => typeof label !== "string" || !label) || new Set(cell.runnerLabels).size !== cell.runnerLabels.length) diagnostics.push(issue2("Runner labels must be unique non-empty strings.", `${path2}.runnerLabels`));
|
|
587
|
+
const browser = object3(cell.browser);
|
|
588
|
+
const os = object3(cell.os);
|
|
589
|
+
const adapter = object3(cell.adapter);
|
|
590
|
+
const adapterAutomation = object3(cell.automation);
|
|
591
|
+
if (!browser || !keys(browser, ["name", "channel"]) || !browserNames.has(String(browser.name))) diagnostics.push(issue2("Browser descriptor is invalid.", `${path2}.browser`));
|
|
592
|
+
if (!os || !keys(os, ["name", "versionRequirement", "architecture"]) || !osNames.has(String(os.name)) || !["x64", "arm64"].includes(String(os.architecture))) diagnostics.push(issue2("OS descriptor is invalid.", `${path2}.os`));
|
|
593
|
+
else {
|
|
594
|
+
const requirement = object3(os.versionRequirement);
|
|
595
|
+
const kind = String(requirement?.kind);
|
|
596
|
+
const validRequirement = requirement && (kind === "exact" ? keys(requirement, ["kind", "value"]) && typeof requirement.value === "string" && /^\d+(?:\.\d+)*$/u.test(requirement.value) : kind === "major" || kind === "minimum-major" ? keys(requirement, ["kind", "value"]) && Number.isSafeInteger(requirement.value) && Number(requirement.value) > 0 : kind === "stable-channel" && keys(requirement, ["kind", "channel"]) && requirement.channel === "stable");
|
|
597
|
+
if (!validRequirement) diagnostics.push(issue2("OS version requirement is invalid.", `${path2}.os.versionRequirement`));
|
|
598
|
+
if (typeof cell.cellId === "string" && JSON.stringify(requirement) !== JSON.stringify(VERSION_REQUIREMENTS.get(cell.cellId))) diagnostics.push(issue2("OS version requirement differs from the stable baseline.", `${path2}.os.versionRequirement`));
|
|
599
|
+
}
|
|
600
|
+
if (!adapter || !keys(adapter, ["kind", "vendor", "family", "backend"]) || !["software", "physical"].includes(String(adapter.kind)) || !backends.has(String(adapter.backend))) diagnostics.push(issue2("Adapter descriptor is invalid.", `${path2}.adapter`));
|
|
601
|
+
if (!adapterAutomation || !keys(adapterAutomation, ["kind"]) || !automation.has(String(adapterAutomation.kind))) diagnostics.push(issue2("Automation descriptor is invalid.", `${path2}.automation`));
|
|
602
|
+
const signature = `${String(browser?.name)}|${String(os?.name)}|${String(os?.architecture)}|${String(adapter?.kind)}|${String(adapter?.vendor)}|${String(adapter?.family)}|${String(adapter?.backend)}|${String(adapterAutomation?.kind)}|${Array.isArray(cell.runnerLabels) ? cell.runnerLabels.join(",") : ""}`;
|
|
603
|
+
if (typeof cell.cellId === "string" && BASELINE.get(cell.cellId) !== signature) diagnostics.push(issue2("Cell identity, target, automation, or runner labels differ from the stable baseline.", path2));
|
|
604
|
+
if (typeof cell.cellId === "string" && [...BASELINE.keys()][index] !== cell.cellId) diagnostics.push(issue2("Stable matrix cells must remain in fixed code-unit order.", `${path2}.cellId`));
|
|
605
|
+
if (!Number.isSafeInteger(cell.timeoutMs) || Number(cell.timeoutMs) < 1e3 || Number(cell.timeoutMs) > 36e5) diagnostics.push(issue2("Cell timeout must be bounded.", `${path2}.timeoutMs`));
|
|
606
|
+
if (cell.blocking !== true) diagnostics.push(issue2("Every stable matrix cell must block delivery.", `${path2}.blocking`));
|
|
607
|
+
else blocking += 1;
|
|
608
|
+
if (adapter?.kind === "physical") {
|
|
609
|
+
physical += 1;
|
|
610
|
+
if (browser?.channel !== "stable" || cell.countsTowardStableCoverage !== true) diagnostics.push(issue2("Physical cells must use stable browsers and count toward stable coverage.", path2));
|
|
611
|
+
} else if (adapter?.kind === "software") {
|
|
612
|
+
software += 1;
|
|
613
|
+
if (adapter.backend !== "swiftshader" || browser?.name !== "chromium" || browser.channel !== "playwright-bundled" || cell.countsTowardStableCoverage !== false) diagnostics.push(issue2("The sole software lane must be bundled Chromium with SwiftShader smoke coverage.", path2));
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
if (physical !== 15 || blocking !== 16 || software !== 1 || ids.size !== BASELINE.size) diagnostics.push(issue2("Matrix must contain the exact 15 physical baseline cells plus one SwiftShader smoke cell."));
|
|
617
|
+
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: matrix };
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// src/testing/qualification-bundle.ts
|
|
621
|
+
var SAFE_PATH2 = /^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[A-Za-z0-9._/-]+$/u;
|
|
622
|
+
var TOKEN = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,159}$/u;
|
|
623
|
+
var BUFFER_USAGE = /* @__PURE__ */ new Set(["map-read", "map-write", "copy-src", "copy-dst", "index", "vertex", "uniform", "storage", "indirect", "query-resolve"]);
|
|
624
|
+
var TEXTURE_USAGE = /* @__PURE__ */ new Set(["copy-src", "copy-dst", "texture-binding", "storage-binding", "render-attachment"]);
|
|
625
|
+
var UNCOMPRESSED_COLOR_BYTES = /* @__PURE__ */ new Map([
|
|
626
|
+
["r8unorm", 1],
|
|
627
|
+
["r8snorm", 1],
|
|
628
|
+
["r8uint", 1],
|
|
629
|
+
["r8sint", 1],
|
|
630
|
+
["r16unorm", 2],
|
|
631
|
+
["r16snorm", 2],
|
|
632
|
+
["r16uint", 2],
|
|
633
|
+
["r16sint", 2],
|
|
634
|
+
["r16float", 2],
|
|
635
|
+
["rg8unorm", 2],
|
|
636
|
+
["rg8snorm", 2],
|
|
637
|
+
["rg8uint", 2],
|
|
638
|
+
["rg8sint", 2],
|
|
639
|
+
["r32uint", 4],
|
|
640
|
+
["r32sint", 4],
|
|
641
|
+
["r32float", 4],
|
|
642
|
+
["rg16unorm", 4],
|
|
643
|
+
["rg16snorm", 4],
|
|
644
|
+
["rg16uint", 4],
|
|
645
|
+
["rg16sint", 4],
|
|
646
|
+
["rg16float", 4],
|
|
647
|
+
["rgba8unorm", 4],
|
|
648
|
+
["rgba8unorm-srgb", 4],
|
|
649
|
+
["rgba8snorm", 4],
|
|
650
|
+
["rgba8uint", 4],
|
|
651
|
+
["rgba8sint", 4],
|
|
652
|
+
["bgra8unorm", 4],
|
|
653
|
+
["bgra8unorm-srgb", 4],
|
|
654
|
+
["rgb9e5ufloat", 4],
|
|
655
|
+
["rgb10a2uint", 4],
|
|
656
|
+
["rgb10a2unorm", 4],
|
|
657
|
+
["rg11b10ufloat", 4],
|
|
658
|
+
["rg32uint", 8],
|
|
659
|
+
["rg32sint", 8],
|
|
660
|
+
["rg32float", 8],
|
|
661
|
+
["rgba16unorm", 8],
|
|
662
|
+
["rgba16snorm", 8],
|
|
663
|
+
["rgba16uint", 8],
|
|
664
|
+
["rgba16sint", 8],
|
|
665
|
+
["rgba16float", 8],
|
|
666
|
+
["rgba32uint", 16],
|
|
667
|
+
["rgba32sint", 16],
|
|
668
|
+
["rgba32float", 16]
|
|
669
|
+
]);
|
|
670
|
+
var COMPRESSED_COLOR_FORMATS = /* @__PURE__ */ new Set([
|
|
671
|
+
"bc1-rgba-unorm",
|
|
672
|
+
"bc1-rgba-unorm-srgb",
|
|
673
|
+
"bc2-rgba-unorm",
|
|
674
|
+
"bc2-rgba-unorm-srgb",
|
|
675
|
+
"bc3-rgba-unorm",
|
|
676
|
+
"bc3-rgba-unorm-srgb",
|
|
677
|
+
"bc4-r-unorm",
|
|
678
|
+
"bc4-r-snorm",
|
|
679
|
+
"bc5-rg-unorm",
|
|
680
|
+
"bc5-rg-snorm",
|
|
681
|
+
"bc6h-rgb-ufloat",
|
|
682
|
+
"bc6h-rgb-float",
|
|
683
|
+
"bc7-rgba-unorm",
|
|
684
|
+
"bc7-rgba-unorm-srgb",
|
|
685
|
+
"etc2-rgb8unorm",
|
|
686
|
+
"etc2-rgb8unorm-srgb",
|
|
687
|
+
"etc2-rgb8a1unorm",
|
|
688
|
+
"etc2-rgb8a1unorm-srgb",
|
|
689
|
+
"etc2-rgba8unorm",
|
|
690
|
+
"etc2-rgba8unorm-srgb",
|
|
691
|
+
"eac-r11unorm",
|
|
692
|
+
"eac-r11snorm",
|
|
693
|
+
"eac-rg11unorm",
|
|
694
|
+
"eac-rg11snorm",
|
|
695
|
+
...["4x4", "5x4", "5x5", "6x5", "6x6", "8x5", "8x6", "8x8", "10x5", "10x6", "10x8", "10x10", "12x10", "12x12"].flatMap((block) => [`astc-${block}-unorm`, `astc-${block}-unorm-srgb`])
|
|
696
|
+
]);
|
|
697
|
+
var DEPTH_STENCIL_FORMATS = /* @__PURE__ */ new Map([
|
|
698
|
+
["stencil8", "stencil"],
|
|
699
|
+
["depth16unorm", "depth"],
|
|
700
|
+
["depth24plus", "depth"],
|
|
701
|
+
["depth24plus-stencil8", "depth-stencil"],
|
|
702
|
+
["depth32float", "depth"],
|
|
703
|
+
["depth32float-stencil8", "depth-stencil"]
|
|
704
|
+
]);
|
|
705
|
+
function object4(value, path2) {
|
|
706
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path2} must be an object.`);
|
|
707
|
+
return value;
|
|
708
|
+
}
|
|
709
|
+
function exact2(value, keys2, path2) {
|
|
710
|
+
const expected = new Set(keys2);
|
|
711
|
+
if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => key in value)) throw new TypeError(`${path2} has unknown or missing fields.`);
|
|
712
|
+
}
|
|
713
|
+
function token2(value, path2) {
|
|
714
|
+
if (typeof value !== "string" || !TOKEN.test(value) || value.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
|
|
715
|
+
return value;
|
|
716
|
+
}
|
|
717
|
+
function path(value, label, extensions) {
|
|
718
|
+
if (typeof value !== "string" || !SAFE_PATH2.test(value) || !extensions.some((extension) => value.endsWith(extension))) {
|
|
719
|
+
throw new TypeError(`${label} must be a safe data-only bundle path (${extensions.join(", ")}).`);
|
|
720
|
+
}
|
|
721
|
+
return value;
|
|
722
|
+
}
|
|
723
|
+
function sha(value, label) {
|
|
724
|
+
try {
|
|
725
|
+
return asSha256Hex(String(value));
|
|
726
|
+
} catch (cause) {
|
|
727
|
+
throw new TypeError(`${label} must be a lowercase SHA-256 digest.`, { cause });
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
function integer2(value, label, minimum = 0, maximum = 4294967295) {
|
|
731
|
+
if (!Number.isSafeInteger(value) || Number(value) < minimum || Number(value) > maximum) throw new TypeError(`${label} is outside its integer bound.`);
|
|
732
|
+
return Number(value);
|
|
733
|
+
}
|
|
734
|
+
function boundedArray(value, label, maximum = 4096) {
|
|
735
|
+
if (!Array.isArray(value) || value.length > maximum) throw new TypeError(`${label} must be a bounded array.`);
|
|
736
|
+
return value;
|
|
737
|
+
}
|
|
738
|
+
function unique2(values, label) {
|
|
739
|
+
if (new Set(values).size !== values.length) throw new TypeError(`${label} contains duplicates.`);
|
|
740
|
+
}
|
|
741
|
+
function orderedUniqueTokens(value, label) {
|
|
742
|
+
const result = boundedArray(value, label).map((item, index) => token2(item, `${label}[${index}]`));
|
|
743
|
+
unique2(result, label);
|
|
744
|
+
if (result.some((item, index) => index > 0 && result[index - 1] >= item)) throw new TypeError(`${label} must use fixed code-unit order.`);
|
|
745
|
+
return result;
|
|
746
|
+
}
|
|
747
|
+
function tuple(value, label, length, minimum = 0) {
|
|
748
|
+
const result = boundedArray(value, label, length);
|
|
749
|
+
if (result.length !== length) throw new TypeError(`${label} must contain ${length} elements.`);
|
|
750
|
+
return result.map((item, index) => integer2(item, `${label}[${index}]`, minimum));
|
|
751
|
+
}
|
|
752
|
+
function finiteTuple(value, label, length) {
|
|
753
|
+
const result = boundedArray(value, label, length);
|
|
754
|
+
if (result.length !== length || result.some((item) => typeof item !== "number" || !Number.isFinite(item))) throw new TypeError(`${label} must contain ${length} finite numbers.`);
|
|
755
|
+
return result;
|
|
756
|
+
}
|
|
757
|
+
function checkedProduct(left, right, label) {
|
|
758
|
+
const result = left * right;
|
|
759
|
+
if (!Number.isSafeInteger(result)) throw new TypeError(`${label} exceeds the safe integer bound.`);
|
|
760
|
+
return result;
|
|
761
|
+
}
|
|
762
|
+
function checkedSum(left, right, label) {
|
|
763
|
+
const result = left + right;
|
|
764
|
+
if (!Number.isSafeInteger(result)) throw new TypeError(`${label} exceeds the safe integer bound.`);
|
|
765
|
+
return result;
|
|
766
|
+
}
|
|
767
|
+
function textureFormatAspect(format, label) {
|
|
768
|
+
if (UNCOMPRESSED_COLOR_BYTES.has(format) || COMPRESSED_COLOR_FORMATS.has(format)) return "color";
|
|
769
|
+
const aspect = DEPTH_STENCIL_FORMATS.get(format);
|
|
770
|
+
if (!aspect) throw new TypeError(`${label} is not a qualification-fixture-v1 WebGPU texture format.`);
|
|
771
|
+
return aspect;
|
|
772
|
+
}
|
|
773
|
+
function mipExtent(texture, mipLevel) {
|
|
774
|
+
const divisor = 2 ** mipLevel;
|
|
775
|
+
const width = Math.max(1, Math.floor(texture.size[0] / divisor));
|
|
776
|
+
const height = texture.dimension === "1d" ? 1 : Math.max(1, Math.floor(texture.size[1] / divisor));
|
|
777
|
+
const depthOrArrayLayers = texture.dimension === "3d" ? Math.max(1, Math.floor(texture.size[2] / divisor)) : texture.dimension === "2d" ? texture.size[2] : 1;
|
|
778
|
+
return [width, height, depthOrArrayLayers];
|
|
779
|
+
}
|
|
780
|
+
function linearTextureDataBounds(extent, bytesPerTexel, bytesPerRow, rowsPerImage, label) {
|
|
781
|
+
const rowBytes = checkedProduct(extent[0], bytesPerTexel, `${label} row byte length`);
|
|
782
|
+
if (bytesPerRow < rowBytes || bytesPerRow % bytesPerTexel !== 0) throw new TypeError(`${label}.bytesPerRow is incompatible with the copied texel row.`);
|
|
783
|
+
if (rowsPerImage < extent[1]) throw new TypeError(`${label}.rowsPerImage is smaller than the copied image height.`);
|
|
784
|
+
const imageStride = checkedProduct(bytesPerRow, rowsPerImage, `${label} image stride`);
|
|
785
|
+
const priorImages = checkedProduct(imageStride, extent[2] - 1, `${label} prior-image byte length`);
|
|
786
|
+
const priorRows = checkedProduct(bytesPerRow, extent[1] - 1, `${label} prior-row byte length`);
|
|
787
|
+
const minimum = checkedSum(priorImages, checkedSum(priorRows, rowBytes, `${label} final-image byte length`), `${label} required byte length`);
|
|
788
|
+
const maximum = checkedProduct(imageStride, extent[2], `${label} padded byte capacity`);
|
|
789
|
+
return { minimum, maximum };
|
|
790
|
+
}
|
|
791
|
+
function textureView(value, label, texture) {
|
|
792
|
+
const view = object4(value, label);
|
|
793
|
+
exact2(view, ["format", "dimension", "aspect", "baseMipLevel", "mipLevelCount", "baseArrayLayer", "arrayLayerCount"], label);
|
|
794
|
+
const dimension = view.dimension === null ? null : String(view.dimension);
|
|
795
|
+
if (dimension !== null && !["1d", "2d", "2d-array", "cube", "cube-array", "3d"].includes(dimension)) throw new TypeError(`${label}.dimension is invalid.`);
|
|
796
|
+
const aspect = String(view.aspect);
|
|
797
|
+
if (!["all", "depth-only", "stencil-only"].includes(aspect)) throw new TypeError(`${label}.aspect is invalid.`);
|
|
798
|
+
const resourceAspect = textureFormatAspect(texture.format, `${label} resource format`);
|
|
799
|
+
const aspectIsPresent = aspect === "all" || aspect === "depth-only" && (resourceAspect === "depth" || resourceAspect === "depth-stencil") || aspect === "stencil-only" && (resourceAspect === "stencil" || resourceAspect === "depth-stencil");
|
|
800
|
+
if (!aspectIsPresent) throw new TypeError(`${label}.aspect is not present in texture format ${texture.format}.`);
|
|
801
|
+
const resolvedFormat = aspect === "all" ? texture.format : aspect === "stencil-only" ? "stencil8" : texture.format === "depth24plus-stencil8" ? "depth24plus" : texture.format === "depth32float-stencil8" ? "depth32float" : texture.format;
|
|
802
|
+
if (view.format !== null && token2(view.format, `${label}.format`) !== resolvedFormat) {
|
|
803
|
+
throw new TypeError(`${label}.format differs from the texture aspect format ${resolvedFormat}.`);
|
|
804
|
+
}
|
|
805
|
+
const baseMipLevel = integer2(view.baseMipLevel, `${label}.baseMipLevel`);
|
|
806
|
+
if (baseMipLevel >= texture.mipLevelCount) throw new TypeError(`${label}.baseMipLevel is out of bounds.`);
|
|
807
|
+
const mipLevelCount = view.mipLevelCount === null ? texture.mipLevelCount - baseMipLevel : integer2(view.mipLevelCount, `${label}.mipLevelCount`, 1);
|
|
808
|
+
if (mipLevelCount > texture.mipLevelCount - baseMipLevel) throw new TypeError(`${label}.mipLevelCount is out of bounds.`);
|
|
809
|
+
const textureArrayLayers = texture.dimension === "2d" ? texture.size[2] : 1;
|
|
810
|
+
const baseArrayLayer = integer2(view.baseArrayLayer, `${label}.baseArrayLayer`);
|
|
811
|
+
if (baseArrayLayer >= textureArrayLayers) throw new TypeError(`${label}.baseArrayLayer is out of bounds.`);
|
|
812
|
+
const resolvedDimension = dimension ?? (texture.dimension === "2d" && textureArrayLayers > 1 ? "2d-array" : texture.dimension);
|
|
813
|
+
const defaultArrayLayerCount = resolvedDimension === "cube" ? 6 : resolvedDimension === "2d-array" || resolvedDimension === "cube-array" ? textureArrayLayers - baseArrayLayer : 1;
|
|
814
|
+
const arrayLayerCount = view.arrayLayerCount === null ? defaultArrayLayerCount : integer2(view.arrayLayerCount, `${label}.arrayLayerCount`, 1);
|
|
815
|
+
if (arrayLayerCount > textureArrayLayers - baseArrayLayer) throw new TypeError(`${label}.arrayLayerCount is out of bounds.`);
|
|
816
|
+
if (resolvedDimension === "1d" && texture.dimension !== "1d" || resolvedDimension === "3d" && texture.dimension !== "3d" || ["2d", "2d-array", "cube", "cube-array"].includes(resolvedDimension) && texture.dimension !== "2d") {
|
|
817
|
+
throw new TypeError(`${label}.dimension is incompatible with the texture dimension.`);
|
|
818
|
+
}
|
|
819
|
+
if (["1d", "2d", "3d"].includes(resolvedDimension) && arrayLayerCount !== 1) throw new TypeError(`${label}.arrayLayerCount must be one for ${resolvedDimension} views.`);
|
|
820
|
+
if (resolvedDimension === "cube" && arrayLayerCount !== 6 || resolvedDimension === "cube-array" && arrayLayerCount % 6 !== 0) throw new TypeError(`${label}.arrayLayerCount is invalid for a cube view.`);
|
|
821
|
+
if ((resolvedDimension === "cube" || resolvedDimension === "cube-array") && texture.size[0] !== texture.size[1]) throw new TypeError(`${label} cube views require square texture layers.`);
|
|
822
|
+
if (texture.sampleCount > 1 && (resolvedDimension !== "2d" || mipLevelCount !== 1 || arrayLayerCount !== 1)) throw new TypeError(`${label} multisampled texture views must select one 2d subresource.`);
|
|
823
|
+
}
|
|
824
|
+
function dataRef(value, label) {
|
|
825
|
+
const ref = object4(value, label);
|
|
826
|
+
exact2(ref, ["path", "sha256"], label);
|
|
827
|
+
path(ref.path, `${label}.path`, [".bin"]);
|
|
828
|
+
sha(ref.sha256, `${label}.sha256`);
|
|
829
|
+
}
|
|
830
|
+
function jsonValue(value, label, depth = 0) {
|
|
831
|
+
if (depth > 32) throw new TypeError(`${label} exceeds the structured-value nesting bound.`);
|
|
832
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return;
|
|
833
|
+
if (typeof value === "number") {
|
|
834
|
+
if (!Number.isFinite(value)) throw new TypeError(`${label} must be finite.`);
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
if (Array.isArray(value)) {
|
|
838
|
+
if (value.length > 65536) throw new TypeError(`${label} exceeds the structured-value item bound.`);
|
|
839
|
+
value.forEach((item, index) => jsonValue(item, `${label}[${index}]`, depth + 1));
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
const input = object4(value, label);
|
|
843
|
+
if (Object.keys(input).length > 4096) throw new TypeError(`${label} has too many members.`);
|
|
844
|
+
for (const [key, item] of Object.entries(input)) {
|
|
845
|
+
token2(key, `${label} key`);
|
|
846
|
+
jsonValue(item, `${label}.${key}`, depth + 1);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
function validateQualificationFixture(value, unit) {
|
|
850
|
+
try {
|
|
851
|
+
const fixture = object4(value, "fixture");
|
|
852
|
+
exact2(fixture, ["contractVersion", "fixtureId", "resources", "bindGroups", "commands", "layoutProbes", "readbacks", "bounds"], "fixture");
|
|
853
|
+
if (fixture.contractVersion !== SHADER_QUALIFICATION_FIXTURE_VERSION) throw new TypeError("Unsupported qualification fixture version.");
|
|
854
|
+
token2(fixture.fixtureId, "fixture.fixtureId");
|
|
855
|
+
const bounds = object4(fixture.bounds, "fixture.bounds");
|
|
856
|
+
exact2(bounds, ["maxBufferBytes", "maxTextureTexels", "maxCommands", "timeoutMs"], "fixture.bounds");
|
|
857
|
+
const maxBufferBytes = integer2(bounds.maxBufferBytes, "fixture.bounds.maxBufferBytes", 1, 67108864);
|
|
858
|
+
const maxTextureTexels = integer2(bounds.maxTextureTexels, "fixture.bounds.maxTextureTexels", 1, 16777216);
|
|
859
|
+
const maxCommands = integer2(bounds.maxCommands, "fixture.bounds.maxCommands", 1, 1e3);
|
|
860
|
+
integer2(bounds.timeoutMs, "fixture.bounds.timeoutMs", 1, 3e5);
|
|
861
|
+
const resources = /* @__PURE__ */ new Map();
|
|
862
|
+
let bufferBytes = 0;
|
|
863
|
+
let textureTexels = 0;
|
|
864
|
+
const resourceValues = boundedArray(fixture.resources, "fixture.resources", 256);
|
|
865
|
+
if (resourceValues.length === 0) throw new TypeError("Fixture requires resources.");
|
|
866
|
+
for (const [index, value2] of resourceValues.entries()) {
|
|
867
|
+
const label = `fixture.resources[${index}]`;
|
|
868
|
+
const resource = object4(value2, label);
|
|
869
|
+
const kind = String(resource.kind);
|
|
870
|
+
if (kind === "buffer") {
|
|
871
|
+
exact2(resource, ["kind", "resourceId", "byteLength", "usage", "initialData"], label);
|
|
872
|
+
const id = token2(resource.resourceId, `${label}.resourceId`);
|
|
873
|
+
if (resources.has(id)) throw new TypeError(`Duplicate resource ${id}.`);
|
|
874
|
+
const byteLength = integer2(resource.byteLength, `${label}.byteLength`, 1, maxBufferBytes);
|
|
875
|
+
bufferBytes += byteLength;
|
|
876
|
+
const usage = boundedArray(resource.usage, `${label}.usage`, BUFFER_USAGE.size).map(String);
|
|
877
|
+
unique2(usage, `${label}.usage`);
|
|
878
|
+
if (usage.length === 0 || usage.some((item) => !BUFFER_USAGE.has(item))) throw new TypeError(`${label}.usage is invalid.`);
|
|
879
|
+
if (resource.initialData !== null) dataRef(resource.initialData, `${label}.initialData`);
|
|
880
|
+
resources.set(id, { kind: "buffer", byteLength, usage, hasInitialData: resource.initialData !== null });
|
|
881
|
+
} else if (kind === "texture") {
|
|
882
|
+
exact2(resource, ["kind", "resourceId", "dimension", "size", "mipLevelCount", "sampleCount", "format", "usage", "initialData"], label);
|
|
883
|
+
const id = token2(resource.resourceId, `${label}.resourceId`);
|
|
884
|
+
if (resources.has(id)) throw new TypeError(`Duplicate resource ${id}.`);
|
|
885
|
+
const dimensionValue = String(resource.dimension);
|
|
886
|
+
if (!["1d", "2d", "3d"].includes(dimensionValue)) throw new TypeError(`${label}.dimension is invalid.`);
|
|
887
|
+
const dimension = dimensionValue;
|
|
888
|
+
const parsedSize = tuple(resource.size, `${label}.size`, 3, 1);
|
|
889
|
+
const size = parsedSize;
|
|
890
|
+
if (dimension === "1d" && (size[1] !== 1 || size[2] !== 1)) throw new TypeError(`${label}.size is inconsistent with dimension.`);
|
|
891
|
+
const mipLevelCount = integer2(resource.mipLevelCount, `${label}.mipLevelCount`, 1, 32);
|
|
892
|
+
const maximumMipDimension = dimension === "1d" ? size[0] : dimension === "2d" ? Math.max(size[0], size[1]) : Math.max(...size);
|
|
893
|
+
const maximumMipLevels = Math.floor(Math.log2(maximumMipDimension)) + 1;
|
|
894
|
+
if (mipLevelCount > maximumMipLevels) throw new TypeError(`${label}.mipLevelCount exceeds its spatial size.`);
|
|
895
|
+
const sampleCount = integer2(resource.sampleCount, `${label}.sampleCount`, 1, 4);
|
|
896
|
+
if (sampleCount !== 1 && sampleCount !== 4) throw new TypeError(`${label}.sampleCount is unsupported.`);
|
|
897
|
+
if (sampleCount > 1 && (dimension !== "2d" || size[2] !== 1 || mipLevelCount !== 1)) throw new TypeError(`${label} multisampling requires one single-mip 2d layer.`);
|
|
898
|
+
const resourceTexels = checkedProduct(checkedProduct(checkedProduct(size[0], size[1], `${label} texel count`), size[2], `${label} texel count`), sampleCount, `${label} sampled texel count`);
|
|
899
|
+
textureTexels = checkedSum(textureTexels, resourceTexels, "fixture texture texel count");
|
|
900
|
+
const format = token2(resource.format, `${label}.format`);
|
|
901
|
+
textureFormatAspect(format, `${label}.format`);
|
|
902
|
+
const usage = boundedArray(resource.usage, `${label}.usage`, TEXTURE_USAGE.size).map(String);
|
|
903
|
+
unique2(usage, `${label}.usage`);
|
|
904
|
+
if (usage.length === 0 || usage.some((item) => !TEXTURE_USAGE.has(item))) throw new TypeError(`${label}.usage is invalid.`);
|
|
905
|
+
const textureInfo = { kind: "texture", usage, hasInitialData: resource.initialData !== null, dimension, size, mipLevelCount, sampleCount, format };
|
|
906
|
+
if (resource.initialData !== null) {
|
|
907
|
+
const initialLabel = `${label}.initialData`;
|
|
908
|
+
const initial = object4(resource.initialData, initialLabel);
|
|
909
|
+
exact2(initial, ["path", "sha256", "bytesPerRow", "rowsPerImage", "mipLevel", "origin", "aspect"], initialLabel);
|
|
910
|
+
path(initial.path, `${initialLabel}.path`, [".bin"]);
|
|
911
|
+
sha(initial.sha256, `${initialLabel}.sha256`);
|
|
912
|
+
if (sampleCount !== 1) throw new TypeError(`${label} multisampled textures cannot have initialData.`);
|
|
913
|
+
if (!usage.includes("copy-dst")) throw new TypeError(`${initialLabel} requires copy-dst texture usage.`);
|
|
914
|
+
const bytesPerTexel = UNCOMPRESSED_COLOR_BYTES.get(format);
|
|
915
|
+
if (!bytesPerTexel) throw new TypeError(`${initialLabel} supports only uncompressed color formats in fixture v1.`);
|
|
916
|
+
const mipLevel = integer2(initial.mipLevel, `${initialLabel}.mipLevel`);
|
|
917
|
+
if (mipLevel !== 0) throw new TypeError(`${initialLabel}.mipLevel must be zero in fixture v1.`);
|
|
918
|
+
const origin = tuple(initial.origin, `${initialLabel}.origin`, 3);
|
|
919
|
+
if (origin.some((axis) => axis !== 0)) throw new TypeError(`${initialLabel}.origin must be zero in fixture v1.`);
|
|
920
|
+
if (initial.aspect !== "all") throw new TypeError(`${initialLabel}.aspect must be all for an uncompressed color upload.`);
|
|
921
|
+
const bytesPerRow = integer2(initial.bytesPerRow, `${initialLabel}.bytesPerRow`, 1);
|
|
922
|
+
const rowsPerImage = integer2(initial.rowsPerImage, `${initialLabel}.rowsPerImage`, 1);
|
|
923
|
+
linearTextureDataBounds(mipExtent(textureInfo, 0), bytesPerTexel, bytesPerRow, rowsPerImage, initialLabel);
|
|
924
|
+
}
|
|
925
|
+
resources.set(id, textureInfo);
|
|
926
|
+
} else if (kind === "sampler") {
|
|
927
|
+
exact2(resource, ["kind", "resourceId", "descriptor"], label);
|
|
928
|
+
const id = token2(resource.resourceId, `${label}.resourceId`);
|
|
929
|
+
if (resources.has(id)) throw new TypeError(`Duplicate resource ${id}.`);
|
|
930
|
+
const descriptor = object4(resource.descriptor, `${label}.descriptor`);
|
|
931
|
+
const samplerKeys = /* @__PURE__ */ new Set(["addressModeU", "addressModeV", "addressModeW", "magFilter", "minFilter", "mipmapFilter", "lodMinClamp", "lodMaxClamp", "compare", "maxAnisotropy"]);
|
|
932
|
+
for (const key of Object.keys(descriptor)) if (!samplerKeys.has(key)) throw new TypeError(`${label}.descriptor.${key} is unsupported.`);
|
|
933
|
+
for (const key of ["addressModeU", "addressModeV", "addressModeW"]) if (descriptor[key] !== void 0 && !["clamp-to-edge", "repeat", "mirror-repeat"].includes(String(descriptor[key]))) throw new TypeError(`${label}.descriptor.${key} is invalid.`);
|
|
934
|
+
for (const key of ["magFilter", "minFilter", "mipmapFilter"]) if (descriptor[key] !== void 0 && !["nearest", "linear"].includes(String(descriptor[key]))) throw new TypeError(`${label}.descriptor.${key} is invalid.`);
|
|
935
|
+
if (descriptor.compare !== void 0 && !["never", "less", "equal", "less-equal", "greater", "not-equal", "greater-equal", "always"].includes(String(descriptor.compare))) throw new TypeError(`${label}.descriptor.compare is invalid.`);
|
|
936
|
+
const lodMin = descriptor.lodMinClamp === void 0 ? 0 : Number(descriptor.lodMinClamp);
|
|
937
|
+
const lodMax = descriptor.lodMaxClamp === void 0 ? 32 : Number(descriptor.lodMaxClamp);
|
|
938
|
+
if (!Number.isFinite(lodMin) || !Number.isFinite(lodMax) || lodMin < 0 || lodMax < lodMin || lodMax > 32) throw new TypeError(`${label}.descriptor LOD clamps are invalid.`);
|
|
939
|
+
if (descriptor.maxAnisotropy !== void 0) integer2(descriptor.maxAnisotropy, `${label}.descriptor.maxAnisotropy`, 1, 16);
|
|
940
|
+
resources.set(id, { kind: "sampler", usage: [], hasInitialData: false, descriptor });
|
|
941
|
+
} else throw new TypeError(`${label}.kind is unsupported.`);
|
|
942
|
+
}
|
|
943
|
+
if (bufferBytes > maxBufferBytes || textureTexels > maxTextureTexels) throw new TypeError("Fixture resources exceed declared bounds.");
|
|
944
|
+
const bindGroups = /* @__PURE__ */ new Map();
|
|
945
|
+
for (const [index, value2] of boundedArray(fixture.bindGroups, "fixture.bindGroups", 32).entries()) {
|
|
946
|
+
const label = `fixture.bindGroups[${index}]`;
|
|
947
|
+
const group = object4(value2, label);
|
|
948
|
+
exact2(group, ["bindGroupId", "group", "entries"], label);
|
|
949
|
+
const id = token2(group.bindGroupId, `${label}.bindGroupId`);
|
|
950
|
+
if (bindGroups.has(id)) throw new TypeError(`Duplicate bind group ${id}.`);
|
|
951
|
+
const groupIndex = integer2(group.group, `${label}.group`);
|
|
952
|
+
const parsedEntries = [];
|
|
953
|
+
const bindingIds = [];
|
|
954
|
+
for (const [entryIndex, value3] of boundedArray(group.entries, `${label}.entries`, 64).entries()) {
|
|
955
|
+
const entryLabel = `${label}.entries[${entryIndex}]`;
|
|
956
|
+
const entry = object4(value3, entryLabel);
|
|
957
|
+
parsedEntries.push(entry);
|
|
958
|
+
exact2(entry, ["binding", "resource"], entryLabel);
|
|
959
|
+
bindingIds.push(String(integer2(entry.binding, `${entryLabel}.binding`)));
|
|
960
|
+
const ref = object4(entry.resource, `${entryLabel}.resource`);
|
|
961
|
+
const kind = String(ref.kind);
|
|
962
|
+
if (kind === "buffer") {
|
|
963
|
+
exact2(ref, ["kind", "resourceId", "offset", "size"], `${entryLabel}.resource`);
|
|
964
|
+
const source = resources.get(token2(ref.resourceId, `${entryLabel}.resource.resourceId`));
|
|
965
|
+
const offset = integer2(ref.offset, `${entryLabel}.resource.offset`);
|
|
966
|
+
const size = integer2(ref.size, `${entryLabel}.resource.size`, 1);
|
|
967
|
+
if (source?.kind !== "buffer" || offset + size > source.byteLength) throw new TypeError(`${entryLabel}.resource is out of bounds.`);
|
|
968
|
+
} else if (kind === "texture-view") {
|
|
969
|
+
exact2(ref, ["kind", "resourceId", "view"], `${entryLabel}.resource`);
|
|
970
|
+
const source = resources.get(token2(ref.resourceId, `${entryLabel}.resource.resourceId`));
|
|
971
|
+
if (source?.kind !== "texture") throw new TypeError(`${entryLabel}.resource is not a texture.`);
|
|
972
|
+
textureView(ref.view, `${entryLabel}.resource.view`, source);
|
|
973
|
+
} else if (kind === "sampler") {
|
|
974
|
+
exact2(ref, ["kind", "resourceId"], `${entryLabel}.resource`);
|
|
975
|
+
if (resources.get(token2(ref.resourceId, `${entryLabel}.resource.resourceId`))?.kind !== "sampler") throw new TypeError(`${entryLabel}.resource is not a sampler.`);
|
|
976
|
+
} else throw new TypeError(`${entryLabel}.resource.kind is unsupported.`);
|
|
977
|
+
}
|
|
978
|
+
unique2(bindingIds, `${label}.entries`);
|
|
979
|
+
bindGroups.set(id, { group: groupIndex, entries: parsedEntries });
|
|
980
|
+
}
|
|
981
|
+
const pipelines = new Map(unit?.pipelines.map((pipeline2) => [pipeline2.pipelineId, pipeline2]) ?? []);
|
|
982
|
+
const pipelineIds = new Set(pipelines.keys());
|
|
983
|
+
const commandBindGroups = (value2, pipelineId, label) => {
|
|
984
|
+
const ids = boundedArray(value2, label, 32).map((item, index) => token2(item, `${label}[${index}]`));
|
|
985
|
+
unique2(ids, label);
|
|
986
|
+
const pipeline2 = pipelines.get(pipelineId);
|
|
987
|
+
if (!pipeline2) {
|
|
988
|
+
if (unit) throw new TypeError(`${label} pipeline is missing.`);
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
const expectedGroups = [...pipeline2.layout.bindGroups].sort((left, right) => left.group - right.group);
|
|
992
|
+
if (ids.length !== expectedGroups.length) throw new TypeError(`${label} must bind every pipeline group exactly once.`);
|
|
993
|
+
ids.forEach((id, index) => {
|
|
994
|
+
const actual = bindGroups.get(id);
|
|
995
|
+
const expected = expectedGroups[index];
|
|
996
|
+
if (!actual || actual.group !== expected.group) throw new TypeError(`${label}[${index}] does not match pipeline group ${expected.group}.`);
|
|
997
|
+
const actualBindings = actual.entries.map((entry) => Number(entry.binding)).sort((left, right) => left - right);
|
|
998
|
+
const expectedBindings = expected.entries.map((entry) => entry.binding).sort((left, right) => left - right);
|
|
999
|
+
if (actualBindings.join(",") !== expectedBindings.join(",")) throw new TypeError(`${label}[${index}] bind-group entries differ from the pipeline layout.`);
|
|
1000
|
+
});
|
|
1001
|
+
};
|
|
1002
|
+
const commands = boundedArray(fixture.commands, "fixture.commands", maxCommands);
|
|
1003
|
+
if (commands.length === 0 || commands.length > maxCommands) throw new TypeError("Fixture requires bounded commands.");
|
|
1004
|
+
let executionCommands = 0;
|
|
1005
|
+
for (const [index, value2] of commands.entries()) {
|
|
1006
|
+
const label = `fixture.commands[${index}]`;
|
|
1007
|
+
const command = object4(value2, label);
|
|
1008
|
+
const kind = String(command.kind);
|
|
1009
|
+
if (kind === "dispatch") {
|
|
1010
|
+
executionCommands += 1;
|
|
1011
|
+
exact2(command, ["kind", "pipelineId", "bindGroupIds", "workgroups"], label);
|
|
1012
|
+
const id = token2(command.pipelineId, `${label}.pipelineId`);
|
|
1013
|
+
if (unit && pipelines.get(id)?.kind !== "compute") throw new TypeError(`${label} references a missing or non-compute pipeline.`);
|
|
1014
|
+
commandBindGroups(command.bindGroupIds, id, `${label}.bindGroupIds`);
|
|
1015
|
+
const workgroups = tuple(command.workgroups, `${label}.workgroups`, 3, 1);
|
|
1016
|
+
if (workgroups[0] * workgroups[1] * workgroups[2] > 1048576) throw new TypeError(`${label}.workgroups exceeds the hard dispatch bound.`);
|
|
1017
|
+
} else if (kind === "copy-buffer") {
|
|
1018
|
+
exact2(command, ["kind", "source", "destination", "byteLength"], label);
|
|
1019
|
+
const source = resources.get(token2(command.source, `${label}.source`));
|
|
1020
|
+
const destination = resources.get(token2(command.destination, `${label}.destination`));
|
|
1021
|
+
const bytes = integer2(command.byteLength, `${label}.byteLength`, 1);
|
|
1022
|
+
if (source?.kind !== "buffer" || destination?.kind !== "buffer" || bytes > (source.byteLength ?? 0) || bytes > (destination.byteLength ?? 0)) throw new TypeError(`${label} is out of bounds.`);
|
|
1023
|
+
} else if (kind === "copy-texture-to-buffer") {
|
|
1024
|
+
exact2(command, ["kind", "source", "destination", "extent"], label);
|
|
1025
|
+
const source = object4(command.source, `${label}.source`);
|
|
1026
|
+
exact2(source, ["resourceId", "mipLevel", "origin", "aspect"], `${label}.source`);
|
|
1027
|
+
const sourceResource = resources.get(token2(source.resourceId, `${label}.source.resourceId`));
|
|
1028
|
+
if (sourceResource?.kind !== "texture") throw new TypeError(`${label}.source is not a texture.`);
|
|
1029
|
+
if (!sourceResource.usage.includes("copy-src")) throw new TypeError(`${label}.source requires copy-src texture usage.`);
|
|
1030
|
+
if (sourceResource.sampleCount !== 1) throw new TypeError(`${label}.source must not be multisampled.`);
|
|
1031
|
+
const bytesPerTexel = UNCOMPRESSED_COLOR_BYTES.get(sourceResource.format);
|
|
1032
|
+
if (!bytesPerTexel || source.aspect !== "all") throw new TypeError(`${label}.source format/aspect is unsupported for a fixture-v1 texture readback.`);
|
|
1033
|
+
const mipLevel = integer2(source.mipLevel, `${label}.source.mipLevel`);
|
|
1034
|
+
if (mipLevel >= sourceResource.mipLevelCount) throw new TypeError(`${label}.source.mipLevel is out of bounds.`);
|
|
1035
|
+
const origin = tuple(source.origin, `${label}.source.origin`, 3);
|
|
1036
|
+
const extent = tuple(command.extent, `${label}.extent`, 3, 1);
|
|
1037
|
+
const available = mipExtent(sourceResource, mipLevel);
|
|
1038
|
+
if (origin.some((axis, axisIndex) => checkedSum(axis, extent[axisIndex], `${label}.source copy range`) > available[axisIndex])) throw new TypeError(`${label}.source copy range is out of bounds.`);
|
|
1039
|
+
const destination = object4(command.destination, `${label}.destination`);
|
|
1040
|
+
exact2(destination, ["resourceId", "offset", "bytesPerRow", "rowsPerImage"], `${label}.destination`);
|
|
1041
|
+
const destinationResource = resources.get(token2(destination.resourceId, `${label}.destination.resourceId`));
|
|
1042
|
+
if (destinationResource?.kind !== "buffer") throw new TypeError(`${label}.destination is not a buffer.`);
|
|
1043
|
+
if (!destinationResource.usage.includes("copy-dst")) throw new TypeError(`${label}.destination requires copy-dst buffer usage.`);
|
|
1044
|
+
const offset = integer2(destination.offset, `${label}.destination.offset`);
|
|
1045
|
+
if (offset % bytesPerTexel !== 0) throw new TypeError(`${label}.destination.offset must be texel-block aligned.`);
|
|
1046
|
+
const bytesPerRow = integer2(destination.bytesPerRow, `${label}.destination.bytesPerRow`, 1);
|
|
1047
|
+
if (bytesPerRow % 256 !== 0) throw new TypeError(`${label}.destination.bytesPerRow must be 256-byte aligned.`);
|
|
1048
|
+
const rowsPerImage = integer2(destination.rowsPerImage, `${label}.destination.rowsPerImage`, 1);
|
|
1049
|
+
const requiredBytes = linearTextureDataBounds(extent, bytesPerTexel, bytesPerRow, rowsPerImage, `${label}.destination`).minimum;
|
|
1050
|
+
if (checkedSum(offset, requiredBytes, `${label}.destination range`) > destinationResource.byteLength) throw new TypeError(`${label}.destination range is out of bounds.`);
|
|
1051
|
+
} else if (kind === "draw") {
|
|
1052
|
+
executionCommands += 1;
|
|
1053
|
+
exact2(command, ["kind", "pipelineId", "bindGroupIds", "vertexBuffers", "colorAttachments", "depthStencilAttachment", "vertexCount", "instanceCount", "firstVertex", "firstInstance"], label);
|
|
1054
|
+
const id = token2(command.pipelineId, `${label}.pipelineId`);
|
|
1055
|
+
if (unit && pipelines.get(id)?.kind !== "render") throw new TypeError(`${label} references a missing or non-render pipeline.`);
|
|
1056
|
+
commandBindGroups(command.bindGroupIds, id, `${label}.bindGroupIds`);
|
|
1057
|
+
boundedArray(command.vertexBuffers, `${label}.vertexBuffers`, 16).forEach((value3, vertexIndex) => {
|
|
1058
|
+
const vertexLabel = `${label}.vertexBuffers[${vertexIndex}]`;
|
|
1059
|
+
const vertex = object4(value3, vertexLabel);
|
|
1060
|
+
exact2(vertex, ["slot", "resourceId", "offset", "size"], vertexLabel);
|
|
1061
|
+
integer2(vertex.slot, `${vertexLabel}.slot`);
|
|
1062
|
+
const resource = resources.get(token2(vertex.resourceId, `${vertexLabel}.resourceId`));
|
|
1063
|
+
const offset = integer2(vertex.offset, `${vertexLabel}.offset`);
|
|
1064
|
+
const size = integer2(vertex.size, `${vertexLabel}.size`, 1);
|
|
1065
|
+
if (resource?.kind !== "buffer" || !resource.usage.includes("vertex") || offset + size > resource.byteLength) throw new TypeError(`${vertexLabel} is not a bounded vertex buffer.`);
|
|
1066
|
+
});
|
|
1067
|
+
boundedArray(command.colorAttachments, `${label}.colorAttachments`, 8).forEach((value3, attachmentIndex) => {
|
|
1068
|
+
const attachmentLabel = `${label}.colorAttachments[${attachmentIndex}]`;
|
|
1069
|
+
const attachment = object4(value3, attachmentLabel);
|
|
1070
|
+
exact2(attachment, ["resourceId", "view", "clearValue", "loadOp", "storeOp"], attachmentLabel);
|
|
1071
|
+
const target = resources.get(token2(attachment.resourceId, `${attachmentLabel}.resourceId`));
|
|
1072
|
+
if (target?.kind !== "texture" || !target.usage.includes("render-attachment")) throw new TypeError(`${attachmentLabel} is not a render-attachment texture.`);
|
|
1073
|
+
textureView(attachment.view, `${attachmentLabel}.view`, target);
|
|
1074
|
+
if (textureFormatAspect(target.format, `${attachmentLabel} format`) !== "color") throw new TypeError(`${attachmentLabel} must use a color texture format.`);
|
|
1075
|
+
finiteTuple(attachment.clearValue, `${attachmentLabel}.clearValue`, 4);
|
|
1076
|
+
if (!["clear", "load"].includes(String(attachment.loadOp)) || !["store", "discard"].includes(String(attachment.storeOp))) throw new TypeError(`${attachmentLabel} has invalid ops.`);
|
|
1077
|
+
});
|
|
1078
|
+
if (command.depthStencilAttachment !== null) {
|
|
1079
|
+
const attachment = object4(command.depthStencilAttachment, `${label}.depthStencilAttachment`);
|
|
1080
|
+
exact2(attachment, ["resourceId", "view", "depthClearValue", "depthLoadOp", "depthStoreOp", "stencilClearValue", "stencilLoadOp", "stencilStoreOp"], `${label}.depthStencilAttachment`);
|
|
1081
|
+
const target = resources.get(token2(attachment.resourceId, `${label}.depthStencilAttachment.resourceId`));
|
|
1082
|
+
if (target?.kind !== "texture" || !target.usage.includes("render-attachment")) throw new TypeError(`${label}.depthStencilAttachment is not a render-attachment texture.`);
|
|
1083
|
+
textureView(attachment.view, `${label}.depthStencilAttachment.view`, target);
|
|
1084
|
+
if (textureFormatAspect(target.format, `${label}.depthStencilAttachment format`) === "color") throw new TypeError(`${label}.depthStencilAttachment must use a depth/stencil texture format.`);
|
|
1085
|
+
if (typeof attachment.depthClearValue !== "number" || !Number.isFinite(attachment.depthClearValue) || attachment.depthClearValue < 0 || attachment.depthClearValue > 1) throw new TypeError(`${label}.depthClearValue is invalid.`);
|
|
1086
|
+
integer2(attachment.stencilClearValue, `${label}.stencilClearValue`, 0, 255);
|
|
1087
|
+
if (!["clear", "load"].includes(String(attachment.depthLoadOp)) || !["store", "discard"].includes(String(attachment.depthStoreOp)) || attachment.stencilLoadOp !== null && !["clear", "load"].includes(String(attachment.stencilLoadOp)) || attachment.stencilStoreOp !== null && !["store", "discard"].includes(String(attachment.stencilStoreOp)) || attachment.stencilLoadOp === null !== (attachment.stencilStoreOp === null)) throw new TypeError(`${label}.depth/stencil attachment has invalid ops.`);
|
|
1088
|
+
}
|
|
1089
|
+
const vertexCount = integer2(command.vertexCount, `${label}.vertexCount`, 1);
|
|
1090
|
+
const instanceCount = integer2(command.instanceCount, `${label}.instanceCount`, 1);
|
|
1091
|
+
if (vertexCount * instanceCount > 16777216) throw new TypeError(`${label} exceeds the hard draw invocation bound.`);
|
|
1092
|
+
integer2(command.firstVertex, `${label}.firstVertex`);
|
|
1093
|
+
integer2(command.firstInstance, `${label}.firstInstance`);
|
|
1094
|
+
} else throw new TypeError(`${label}.kind is unsupported.`);
|
|
1095
|
+
}
|
|
1096
|
+
if (executionCommands === 0) throw new TypeError("Fixture requires a bounded dispatch or draw command.");
|
|
1097
|
+
const readbacks = boundedArray(fixture.readbacks, "fixture.readbacks", 512);
|
|
1098
|
+
if (readbacks.length === 0) throw new TypeError("Fixture requires semantic readback evidence.");
|
|
1099
|
+
const parsedReadbacks = [];
|
|
1100
|
+
for (const [index, value2] of readbacks.entries()) {
|
|
1101
|
+
const label = `fixture.readbacks[${index}]`;
|
|
1102
|
+
const readback = object4(value2, label);
|
|
1103
|
+
parsedReadbacks.push(readback);
|
|
1104
|
+
exact2(readback, ["resourceId", "byteOffset", "byteLength", "expectedSha256"], label);
|
|
1105
|
+
const resource = resources.get(token2(readback.resourceId, `${label}.resourceId`));
|
|
1106
|
+
const offset = integer2(readback.byteOffset, `${label}.byteOffset`);
|
|
1107
|
+
const size = integer2(readback.byteLength, `${label}.byteLength`, 1);
|
|
1108
|
+
if (resource?.kind !== "buffer" || !resource.usage.includes("map-read") || offset + size > (resource.byteLength ?? 0)) throw new TypeError(`${label} is not a bounded map-read buffer range.`);
|
|
1109
|
+
sha(readback.expectedSha256, `${label}.expectedSha256`);
|
|
1110
|
+
}
|
|
1111
|
+
const probes = boundedArray(fixture.layoutProbes, "fixture.layoutProbes", 512);
|
|
1112
|
+
if (probes.length === 0) throw new TypeError("Fixture requires at least one structured CPU-to-GPU and GPU-to-CPU layout probe.");
|
|
1113
|
+
const probeIds = [];
|
|
1114
|
+
const probeSources = [];
|
|
1115
|
+
for (const [index, value2] of probes.entries()) {
|
|
1116
|
+
const label = `fixture.layoutProbes[${index}]`;
|
|
1117
|
+
const probe = object4(value2, label);
|
|
1118
|
+
probeIds.push(token2(probe.probeId, `${label}.probeId`));
|
|
1119
|
+
const commandIndex = integer2(probe.commandIndex, `${label}.commandIndex`, 0, commands.length - 1);
|
|
1120
|
+
const command = object4(commands[commandIndex], `${label}.command`);
|
|
1121
|
+
if (probe.kind === "buffer-record") {
|
|
1122
|
+
exact2(probe, ["kind", "probeId", "source", "pipelineId", "commandIndex", "input", "output"], label);
|
|
1123
|
+
const source = object4(probe.source, `${label}.source`);
|
|
1124
|
+
exact2(source, ["moduleId", "group", "binding", "recordName"], `${label}.source`);
|
|
1125
|
+
const moduleId = token2(source.moduleId, `${label}.source.moduleId`);
|
|
1126
|
+
const group = integer2(source.group, `${label}.source.group`);
|
|
1127
|
+
const binding = integer2(source.binding, `${label}.source.binding`);
|
|
1128
|
+
token2(source.recordName, `${label}.source.recordName`);
|
|
1129
|
+
probeSources.push(`binding:${moduleId}:${group}:${binding}`);
|
|
1130
|
+
const pipelineId = token2(probe.pipelineId, `${label}.pipelineId`);
|
|
1131
|
+
if (unit && !pipelineIds.has(pipelineId)) throw new TypeError(`${label}.pipelineId is missing.`);
|
|
1132
|
+
if (command.pipelineId !== pipelineId || command.kind !== "dispatch" && command.kind !== "draw") throw new TypeError(`${label} must target its declared executable pipeline command.`);
|
|
1133
|
+
const input = object4(probe.input, `${label}.input`);
|
|
1134
|
+
exact2(input, ["resourceId", "byteOffset", "byteLength", "value"], `${label}.input`);
|
|
1135
|
+
const inputId = token2(input.resourceId, `${label}.input.resourceId`);
|
|
1136
|
+
const inputResource = resources.get(inputId);
|
|
1137
|
+
const inputOffset = integer2(input.byteOffset, `${label}.input.byteOffset`);
|
|
1138
|
+
const inputLength = integer2(input.byteLength, `${label}.input.byteLength`, 1);
|
|
1139
|
+
if (inputResource?.kind !== "buffer" || !inputResource.hasInitialData || inputOffset + inputLength > (inputResource.byteLength ?? 0)) throw new TypeError(`${label}.input must be an initialized bounded buffer range.`);
|
|
1140
|
+
jsonValue(input.value, `${label}.input.value`);
|
|
1141
|
+
const commandGroups = boundedArray(command.bindGroupIds, `${label}.command.bindGroupIds`).map(String);
|
|
1142
|
+
const bindsSource = commandGroups.some((id) => {
|
|
1143
|
+
const selected = bindGroups.get(id);
|
|
1144
|
+
if (selected?.group !== group) return false;
|
|
1145
|
+
const entry = selected.entries.find((candidate) => candidate.binding === binding);
|
|
1146
|
+
return entry ? object4(entry.resource, `${label}.boundResource`).resourceId === inputId : false;
|
|
1147
|
+
});
|
|
1148
|
+
if (!bindsSource) throw new TypeError(`${label}.input is not bound at the declared model source in its command.`);
|
|
1149
|
+
} else if (probe.kind === "vertex-input") {
|
|
1150
|
+
exact2(probe, ["kind", "probeId", "source", "commandIndex", "input", "output"], label);
|
|
1151
|
+
const source = object4(probe.source, `${label}.source`);
|
|
1152
|
+
exact2(source, ["pipelineId", "shaderLocation", "semantic"], `${label}.source`);
|
|
1153
|
+
const pipelineId = token2(source.pipelineId, `${label}.source.pipelineId`);
|
|
1154
|
+
const shaderLocation = integer2(source.shaderLocation, `${label}.source.shaderLocation`);
|
|
1155
|
+
const semantic = token2(source.semantic, `${label}.source.semantic`);
|
|
1156
|
+
probeSources.push(`vertex:${pipelineId}:${shaderLocation}:${semantic}`);
|
|
1157
|
+
if (command.kind !== "draw" || command.pipelineId !== pipelineId) throw new TypeError(`${label} must target its declared render pipeline draw command.`);
|
|
1158
|
+
const input = object4(probe.input, `${label}.input`);
|
|
1159
|
+
exact2(input, ["resourceId", "vertexBufferSlot", "elementIndex", "value"], `${label}.input`);
|
|
1160
|
+
const inputId = token2(input.resourceId, `${label}.input.resourceId`);
|
|
1161
|
+
const inputResource = resources.get(inputId);
|
|
1162
|
+
const slot = integer2(input.vertexBufferSlot, `${label}.input.vertexBufferSlot`);
|
|
1163
|
+
const elementIndex = integer2(input.elementIndex, `${label}.input.elementIndex`);
|
|
1164
|
+
if (inputResource?.kind !== "buffer" || !inputResource.hasInitialData || !inputResource.usage.includes("vertex")) throw new TypeError(`${label}.input must be an initialized vertex buffer.`);
|
|
1165
|
+
jsonValue(input.value, `${label}.input.value`);
|
|
1166
|
+
if (unit) {
|
|
1167
|
+
const pipeline2 = pipelines.get(pipelineId);
|
|
1168
|
+
if (!pipeline2 || pipeline2.kind !== "render") throw new TypeError(`${label}.source.pipelineId is not a render pipeline.`);
|
|
1169
|
+
const layout = pipeline2.vertexBuffers[slot];
|
|
1170
|
+
const attribute = layout?.attributes.find((item) => item.shaderLocation === shaderLocation);
|
|
1171
|
+
if (!layout || !attribute || attribute.semantic !== semantic) throw new TypeError(`${label} does not identify an exact pipeline vertex semantic.`);
|
|
1172
|
+
const commandBuffer = boundedArray(command.vertexBuffers, `${label}.command.vertexBuffers`).map((item) => object4(item, `${label}.command.vertexBuffer`)).find((item) => item.slot === slot);
|
|
1173
|
+
if (!commandBuffer || commandBuffer.resourceId !== inputId) throw new TypeError(`${label}.input is not bound to its declared vertex-buffer slot.`);
|
|
1174
|
+
const first = integer2(layout.stepMode === "vertex" ? command.firstVertex : command.firstInstance, `${label}.command.firstElement`);
|
|
1175
|
+
const count = integer2(layout.stepMode === "vertex" ? command.vertexCount : command.instanceCount, `${label}.command.elementCount`, 1);
|
|
1176
|
+
if (elementIndex < first || elementIndex >= first + count) throw new TypeError(`${label}.input element is not consumed by its draw command.`);
|
|
1177
|
+
}
|
|
1178
|
+
} else throw new TypeError(`${label}.kind is unsupported in qualification fixture v1.`);
|
|
1179
|
+
const output = object4(probe.output, `${label}.output`);
|
|
1180
|
+
exact2(output, ["readbackIndex", "recordName", "expectedValue"], `${label}.output`);
|
|
1181
|
+
integer2(output.readbackIndex, `${label}.output.readbackIndex`, 0, parsedReadbacks.length - 1);
|
|
1182
|
+
token2(output.recordName, `${label}.output.recordName`);
|
|
1183
|
+
jsonValue(output.expectedValue, `${label}.output.expectedValue`);
|
|
1184
|
+
}
|
|
1185
|
+
unique2(probeIds, "fixture.layoutProbes probe IDs");
|
|
1186
|
+
unique2(probeSources, "fixture.layoutProbes model sources");
|
|
1187
|
+
return { ok: true, value: fixture };
|
|
1188
|
+
} catch (cause) {
|
|
1189
|
+
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification fixture." }] };
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
function validateQualificationBundleManifest(value) {
|
|
1193
|
+
try {
|
|
1194
|
+
const bundle = object4(value, "qualification");
|
|
1195
|
+
exact2(bundle, ["contractVersion", "inventory", "subject", "shaderManifestCorePath", "gpuInterfaceManifest", "modelCompatibilityFixtures", "modules", "fixtures"], "qualification");
|
|
1196
|
+
if (bundle.contractVersion !== SHADER_QUALIFICATION_BUNDLE_VERSION) throw new TypeError("Unsupported qualification bundle version.");
|
|
1197
|
+
const inventory = validateCompileUnitInventory(bundle.inventory);
|
|
1198
|
+
if (!inventory.ok) throw new TypeError(inventory.diagnostics.map((item) => item.message).join("; "));
|
|
1199
|
+
const subject = object4(bundle.subject, "qualification.subject");
|
|
1200
|
+
exact2(subject, ["shaderManifestCore", "compileUnitInventorySha256", "shaderAbiHash", "interfaceManifestSha256", "modelAbiHashes", "modules", "requiredCompileUnitIds", "requiredCellIds"], "qualification.subject");
|
|
1201
|
+
const candidate = object4(subject.shaderManifestCore, "qualification.subject.shaderManifestCore");
|
|
1202
|
+
exact2(candidate, ["shaderId", "version", "sha256"], "qualification.subject.shaderManifestCore");
|
|
1203
|
+
token2(candidate.shaderId, "qualification.subject.shaderManifestCore.shaderId");
|
|
1204
|
+
token2(candidate.version, "qualification.subject.shaderManifestCore.version");
|
|
1205
|
+
sha(candidate.sha256, "qualification.subject.shaderManifestCore.sha256");
|
|
1206
|
+
path(bundle.shaderManifestCorePath, "qualification.shaderManifestCorePath", [".json"]);
|
|
1207
|
+
const interfaceManifest = object4(bundle.gpuInterfaceManifest, "qualification.gpuInterfaceManifest");
|
|
1208
|
+
exact2(interfaceManifest, ["path", "sha256"], "qualification.gpuInterfaceManifest");
|
|
1209
|
+
path(interfaceManifest.path, "qualification.gpuInterfaceManifest.path", [".json"]);
|
|
1210
|
+
const interfaceSha = sha(interfaceManifest.sha256, "qualification.gpuInterfaceManifest.sha256");
|
|
1211
|
+
if (interfaceSha !== subject.interfaceManifestSha256) throw new TypeError("GPU interface file digest differs from subject.");
|
|
1212
|
+
const modelFixtures = boundedArray(bundle.modelCompatibilityFixtures, "qualification.modelCompatibilityFixtures").map((item, index) => {
|
|
1213
|
+
const label = `qualification.modelCompatibilityFixtures[${index}]`;
|
|
1214
|
+
const fixture = object4(item, label);
|
|
1215
|
+
exact2(fixture, ["fixtureId", "path", "sha256"], label);
|
|
1216
|
+
return { fixtureId: token2(fixture.fixtureId, `${label}.fixtureId`), path: path(fixture.path, `${label}.path`, [".json"]), sha256: sha(fixture.sha256, `${label}.sha256`) };
|
|
1217
|
+
});
|
|
1218
|
+
if (modelFixtures.length === 0) throw new TypeError("Qualification requires at least one model compatibility fixture.");
|
|
1219
|
+
unique2(modelFixtures.map((item) => item.fixtureId), "qualification.modelCompatibilityFixtures");
|
|
1220
|
+
unique2(modelFixtures.map((item) => item.path), "qualification.modelCompatibilityFixtures paths");
|
|
1221
|
+
sha(subject.compileUnitInventorySha256, "qualification.subject.compileUnitInventorySha256");
|
|
1222
|
+
sha(subject.shaderAbiHash, "qualification.subject.shaderAbiHash");
|
|
1223
|
+
sha(subject.interfaceManifestSha256, "qualification.subject.interfaceManifestSha256");
|
|
1224
|
+
const modelHashes = boundedArray(subject.modelAbiHashes, "qualification.subject.modelAbiHashes").map((item, index) => sha(item, `qualification.subject.modelAbiHashes[${index}]`));
|
|
1225
|
+
if (modelHashes.length === 0) throw new TypeError("Qualification requires at least one model ABI hash.");
|
|
1226
|
+
unique2(modelHashes, "qualification.subject.modelAbiHashes");
|
|
1227
|
+
const modules = boundedArray(bundle.modules, "qualification.modules").map((item, index) => {
|
|
1228
|
+
const label = `qualification.modules[${index}]`;
|
|
1229
|
+
const module = object4(item, label);
|
|
1230
|
+
exact2(module, ["moduleId", "path", "sha256"], label);
|
|
1231
|
+
return { moduleId: token2(module.moduleId, `${label}.moduleId`), path: path(module.path, `${label}.path`, [".wgsl"]), sha256: sha(module.sha256, `${label}.sha256`) };
|
|
1232
|
+
});
|
|
1233
|
+
if (modules.length === 0) throw new TypeError("Qualification requires at least one final WGSL module.");
|
|
1234
|
+
unique2(modules.map((item) => item.moduleId), "qualification.modules");
|
|
1235
|
+
unique2(modules.map((item) => item.path), "qualification.modules paths");
|
|
1236
|
+
const subjectModules = boundedArray(subject.modules, "qualification.subject.modules").map((item, index) => {
|
|
1237
|
+
const label = `qualification.subject.modules[${index}]`;
|
|
1238
|
+
const module = object4(item, label);
|
|
1239
|
+
exact2(module, ["moduleId", "sha256"], label);
|
|
1240
|
+
return `${token2(module.moduleId, `${label}.moduleId`)}:${sha(module.sha256, `${label}.sha256`)}`;
|
|
1241
|
+
});
|
|
1242
|
+
unique2(subjectModules, "qualification.subject.modules");
|
|
1243
|
+
const moduleIdentities = modules.map((item) => `${item.moduleId}:${item.sha256}`);
|
|
1244
|
+
if ([...subjectModules].sort().join("\n") !== [...moduleIdentities].sort().join("\n")) throw new TypeError("Subject module set differs from bundle modules.");
|
|
1245
|
+
const fixtures = boundedArray(bundle.fixtures, "qualification.fixtures").map((item, index) => {
|
|
1246
|
+
const label = `qualification.fixtures[${index}]`;
|
|
1247
|
+
const fixture = object4(item, label);
|
|
1248
|
+
exact2(fixture, ["fixtureId", "path", "sha256", "kind"], label);
|
|
1249
|
+
if (fixture.kind !== "qualification-fixture") throw new TypeError(`${label}.kind is invalid.`);
|
|
1250
|
+
return { fixtureId: token2(fixture.fixtureId, `${label}.fixtureId`), path: path(fixture.path, `${label}.path`, [".json"]), sha256: sha(fixture.sha256, `${label}.sha256`) };
|
|
1251
|
+
});
|
|
1252
|
+
if (fixtures.length === 0) throw new TypeError("Qualification requires at least one semantic fixture.");
|
|
1253
|
+
unique2(fixtures.map((item) => item.fixtureId), "qualification.fixtures");
|
|
1254
|
+
unique2(fixtures.map((item) => item.path), "qualification.fixtures paths");
|
|
1255
|
+
const fixtureIdentities = new Set(fixtures.map((item) => `${item.fixtureId}:${item.path}:${item.sha256}`));
|
|
1256
|
+
for (const unit of inventory.value.compileUnits) {
|
|
1257
|
+
const ref = unit.qualificationFixture;
|
|
1258
|
+
if (!fixtureIdentities.has(`${ref.fixtureId}:${ref.path}:${ref.sha256}`)) throw new TypeError(`Compile unit ${unit.compileUnitId} fixture is absent or stale.`);
|
|
1259
|
+
}
|
|
1260
|
+
const unitIds = orderedUniqueTokens(subject.requiredCompileUnitIds, "qualification.subject.requiredCompileUnitIds");
|
|
1261
|
+
const expectedUnits = [...inventory.value.compileUnits.map((unit) => unit.compileUnitId)].sort();
|
|
1262
|
+
if (unitIds.join("\n") !== expectedUnits.join("\n")) throw new TypeError("Subject compile-unit IDs differ from inventory.");
|
|
1263
|
+
orderedUniqueTokens(subject.requiredCellIds, "qualification.subject.requiredCellIds");
|
|
1264
|
+
return { ok: true, value: bundle };
|
|
1265
|
+
} catch (cause) {
|
|
1266
|
+
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification bundle." }] };
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// src/testing/evidence.ts
|
|
1271
|
+
function object5(value, path2) {
|
|
1272
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path2} must be an object.`);
|
|
1273
|
+
return value;
|
|
1274
|
+
}
|
|
1275
|
+
function exact3(value, keys2, path2) {
|
|
1276
|
+
const expected = new Set(keys2);
|
|
1277
|
+
if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => key in value)) throw new TypeError(`${path2} has unknown or missing fields.`);
|
|
1278
|
+
}
|
|
1279
|
+
function token3(value, path2, maximum = 512) {
|
|
1280
|
+
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.`);
|
|
1281
|
+
return value;
|
|
1282
|
+
}
|
|
1283
|
+
function sha2(value, path2) {
|
|
1284
|
+
try {
|
|
1285
|
+
return asSha256Hex(token3(value, path2, 64));
|
|
1286
|
+
} catch (cause) {
|
|
1287
|
+
throw new TypeError(`${path2} is not a SHA-256 digest.`, { cause });
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
function integer3(value, path2, minimum = 0) {
|
|
1291
|
+
if (!Number.isSafeInteger(value) || Number(value) < minimum) throw new TypeError(`${path2} is not a safe integer.`);
|
|
1292
|
+
return Number(value);
|
|
1293
|
+
}
|
|
1294
|
+
function timestamp(value, path2) {
|
|
1295
|
+
const parsed = token3(value, path2, 64);
|
|
1296
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/u.test(parsed) || !Number.isFinite(Date.parse(parsed))) throw new TypeError(`${path2} must be an ISO UTC timestamp.`);
|
|
1297
|
+
return parsed;
|
|
1298
|
+
}
|
|
1299
|
+
function array2(value, path2, maximum = 1e5) {
|
|
1300
|
+
if (!Array.isArray(value) || value.length > maximum) throw new TypeError(`${path2} must be a bounded array.`);
|
|
1301
|
+
return value;
|
|
1302
|
+
}
|
|
1303
|
+
function gitObject(value, path2) {
|
|
1304
|
+
const input = object5(value, path2);
|
|
1305
|
+
exact3(input, ["algorithm", "hex"], path2);
|
|
1306
|
+
const algorithm = input.algorithm;
|
|
1307
|
+
if (algorithm !== "sha1" && algorithm !== "sha256") throw new TypeError(`${path2}.algorithm is invalid.`);
|
|
1308
|
+
const hex = token3(input.hex, `${path2}.hex`, 64);
|
|
1309
|
+
const length = algorithm === "sha1" ? 40 : 64;
|
|
1310
|
+
if (!new RegExp(`^[a-f0-9]{${length}}$`, "u").test(hex)) throw new TypeError(`${path2}.hex does not match its algorithm.`);
|
|
1311
|
+
return input;
|
|
1312
|
+
}
|
|
1313
|
+
var TRUSTED_WORKFLOW_PREFIX = "Plasius-LTD/gpu-shader/.github/workflows/shader-qualification.yml@";
|
|
1314
|
+
function trustedWorkflowRef(value, path2) {
|
|
1315
|
+
const result = token3(value, path2, 1024);
|
|
1316
|
+
if (result !== `${TRUSTED_WORKFLOW_PREFIX}refs/heads/main`) throw new TypeError(`${path2} must bind the trusted shader-qualification workflow on protected main.`);
|
|
1317
|
+
return result;
|
|
1318
|
+
}
|
|
1319
|
+
function parseTrustedWorkflowProvenance(value, path2 = "provenance") {
|
|
1320
|
+
const input = object5(value, path2);
|
|
1321
|
+
exact3(input, ["repository", "commit", "ref", "workflowRef", "workflowSha", "runId", "runAttempt", "job", "eventName", "oidcAttestation"], path2);
|
|
1322
|
+
const repository = token3(input.repository, `${path2}.repository`);
|
|
1323
|
+
if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
|
|
1324
|
+
gitObject(input.commit, `${path2}.commit`);
|
|
1325
|
+
token3(input.ref, `${path2}.ref`);
|
|
1326
|
+
gitObject(input.workflowSha, `${path2}.workflowSha`);
|
|
1327
|
+
trustedWorkflowRef(input.workflowRef, `${path2}.workflowRef`);
|
|
1328
|
+
token3(input.runId, `${path2}.runId`);
|
|
1329
|
+
integer3(input.runAttempt, `${path2}.runAttempt`, 1);
|
|
1330
|
+
token3(input.job, `${path2}.job`);
|
|
1331
|
+
token3(input.eventName, `${path2}.eventName`);
|
|
1332
|
+
const oidc = object5(input.oidcAttestation, `${path2}.oidcAttestation`);
|
|
1333
|
+
exact3(oidc, ["issuer", "subject", "audience", "verifiedClaimsSha256", "verifiedAt", "source"], `${path2}.oidcAttestation`);
|
|
1334
|
+
if (oidc.issuer !== "https://token.actions.githubusercontent.com" || oidc.source !== "trusted-runner-preflight") throw new TypeError(`${path2}.oidcAttestation is not GitHub trusted-preflight provenance.`);
|
|
1335
|
+
token3(oidc.subject, `${path2}.oidcAttestation.subject`, 2048);
|
|
1336
|
+
token3(oidc.audience, `${path2}.oidcAttestation.audience`, 2048);
|
|
1337
|
+
sha2(oidc.verifiedClaimsSha256, `${path2}.oidcAttestation.verifiedClaimsSha256`);
|
|
1338
|
+
timestamp(oidc.verifiedAt, `${path2}.oidcAttestation.verifiedAt`);
|
|
1339
|
+
return input;
|
|
1340
|
+
}
|
|
1341
|
+
function parseQualificationExecutionProducer(value, path2 = "producer") {
|
|
1342
|
+
const input = object5(value, path2);
|
|
1343
|
+
exact3(input, ["repository", "commit", "ref", "runId", "runAttempt", "job", "trustedWorkflowRepository", "trustedWorkflowRef", "trustedWorkflowSha", "runner"], path2);
|
|
1344
|
+
const repository = token3(input.repository, `${path2}.repository`);
|
|
1345
|
+
if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
|
|
1346
|
+
gitObject(input.commit, `${path2}.commit`);
|
|
1347
|
+
token3(input.ref, `${path2}.ref`);
|
|
1348
|
+
token3(input.runId, `${path2}.runId`);
|
|
1349
|
+
integer3(input.runAttempt, `${path2}.runAttempt`, 1);
|
|
1350
|
+
if (!["swiftshader", "physical", "physical-runner-preflight"].includes(String(input.job))) throw new TypeError(`${path2}.job is not a qualification workflow job.`);
|
|
1351
|
+
if (input.trustedWorkflowRepository !== "Plasius-LTD/gpu-shader") throw new TypeError(`${path2}.trustedWorkflowRepository differs.`);
|
|
1352
|
+
gitObject(input.trustedWorkflowSha, `${path2}.trustedWorkflowSha`);
|
|
1353
|
+
trustedWorkflowRef(input.trustedWorkflowRef, `${path2}.trustedWorkflowRef`);
|
|
1354
|
+
const runner = object5(input.runner, `${path2}.runner`);
|
|
1355
|
+
exact3(runner, ["name", "environment", "os", "architecture"], `${path2}.runner`);
|
|
1356
|
+
token3(runner.name, `${path2}.runner.name`);
|
|
1357
|
+
if (!["github-hosted", "self-hosted", "device-farm"].includes(String(runner.environment))) throw new TypeError(`${path2}.runner.environment is invalid.`);
|
|
1358
|
+
token3(runner.os, `${path2}.runner.os`);
|
|
1359
|
+
token3(runner.architecture, `${path2}.runner.architecture`);
|
|
1360
|
+
return input;
|
|
1361
|
+
}
|
|
1362
|
+
function assertProducerMatchesPreflight(producer, provenance, cell, path2, expectedJob) {
|
|
1363
|
+
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.`);
|
|
1364
|
+
if (expectedJob === "swiftshader" && producer.runner.environment !== "github-hosted") throw new TypeError(`${path2} must identify the hosted SwiftShader job.`);
|
|
1365
|
+
if (expectedJob === "physical" && producer.runner.environment === "github-hosted") throw new TypeError(`${path2} cannot use a hosted runner for a physical execution cell.`);
|
|
1366
|
+
if (expectedJob === "physical-runner-preflight" && producer.runner.environment !== "github-hosted") throw new TypeError(`${path2} must identify its hosted orchestration job truthfully.`);
|
|
1367
|
+
}
|
|
1368
|
+
function canonicalEqual(left, right) {
|
|
1369
|
+
return canonicalizeGpuContract(left) === canonicalizeGpuContract(right);
|
|
1370
|
+
}
|
|
1371
|
+
function foldRunnerLabel(value) {
|
|
1372
|
+
return value.replace(/[A-Z]/gu, (character) => character.toLowerCase());
|
|
1373
|
+
}
|
|
1374
|
+
async function computeQualificationInventorySha256(bundle) {
|
|
1375
|
+
return computeSha256(canonicalizeGpuContract(bundle.inventory));
|
|
1376
|
+
}
|
|
1377
|
+
async function computeQualificationSubjectBinding(input) {
|
|
1378
|
+
return computeSha256(`plasius.gpu.qualification-subject/v1
|
|
1379
|
+
${canonicalizeGpuContract(input)}`);
|
|
1380
|
+
}
|
|
1381
|
+
async function computeValidationEvidenceId(value) {
|
|
1382
|
+
const input = object5(value, "evidence identity input");
|
|
1383
|
+
const projection = Object.fromEntries(Object.entries(input).filter(([key]) => key !== "evidenceId"));
|
|
1384
|
+
return `qualification-${(await computeSha256(`plasius.gpu.validation-evidence/v1
|
|
1385
|
+
${canonicalizeGpuContract(projection)}`)).slice(0, 24)}`;
|
|
1386
|
+
}
|
|
1387
|
+
function immutableBlobUri(value) {
|
|
1388
|
+
const url = new URL(value);
|
|
1389
|
+
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 === ".."))) {
|
|
1390
|
+
throw new TypeError("Source URI must be a normalized immutable Azure Blob .tar URL.");
|
|
1391
|
+
}
|
|
1392
|
+
const versionIds = [...url.searchParams.entries()].filter(([key]) => key.toLowerCase() === "versionid");
|
|
1393
|
+
if ([...url.searchParams.keys()].length !== 1 || versionIds.length !== 1 || !/^[A-Za-z0-9._:-]{1,128}$/u.test(versionIds[0][1])) throw new TypeError("Source URI must use exactly one versionId and no other query parameters.");
|
|
1394
|
+
return { host: url.host.toLowerCase(), versionId: versionIds[0][1], uri: value };
|
|
1395
|
+
}
|
|
1396
|
+
async function createQualificationPreflight(input) {
|
|
1397
|
+
token3(input.qualificationId, "qualificationId");
|
|
1398
|
+
let parsedMatrix;
|
|
1399
|
+
try {
|
|
1400
|
+
parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
|
|
1401
|
+
} catch (cause) {
|
|
1402
|
+
throw new TypeError("Selected matrix artifact is not UTF-8 JSON.", { cause });
|
|
1403
|
+
}
|
|
1404
|
+
if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Selected matrix artifact bytes differ from the supplied matrix value.");
|
|
1405
|
+
const actualMatrixSha256 = await computeSha256(input.matrixBytes);
|
|
1406
|
+
if (actualMatrixSha256 !== input.matrixSha256) throw new TypeError("Selected matrix digest is not derived from the exact matrix manifest.");
|
|
1407
|
+
const inventorySha256 = await computeQualificationInventorySha256(input.bundle);
|
|
1408
|
+
if (inventorySha256 !== input.bundle.subject.compileUnitInventorySha256) throw new TypeError("Bundle subject contains a stale compile-unit inventory digest.");
|
|
1409
|
+
const requiredCells = input.matrix.cells.map((cell) => cell.cellId);
|
|
1410
|
+
if (!canonicalEqual(input.bundle.subject.requiredCellIds, requiredCells)) throw new TypeError("Bundle subject cell set differs from the selected matrix.");
|
|
1411
|
+
const subjectBindingSha256 = await computeQualificationSubjectBinding({
|
|
1412
|
+
subject: input.bundle.subject,
|
|
1413
|
+
dataBundleSha256: input.dataBundleSha256,
|
|
1414
|
+
compileUnitInventorySha256: inventorySha256,
|
|
1415
|
+
matrixSha256: input.matrixSha256,
|
|
1416
|
+
harnessSha256: input.harnessSha256
|
|
1417
|
+
});
|
|
1418
|
+
return {
|
|
1419
|
+
contractVersion: SHADER_VALIDATION_EVIDENCE_VERSION,
|
|
1420
|
+
kind: "shader-qualification-preflight",
|
|
1421
|
+
qualificationId: input.qualificationId,
|
|
1422
|
+
sourceBlob: immutableBlobUri(input.sourceUri),
|
|
1423
|
+
dataBundleSha256: input.dataBundleSha256,
|
|
1424
|
+
compileUnitInventorySha256: inventorySha256,
|
|
1425
|
+
matrixSha256: input.matrixSha256,
|
|
1426
|
+
harnessSha256: input.harnessSha256,
|
|
1427
|
+
subjectBindingSha256,
|
|
1428
|
+
provenance: parseTrustedWorkflowProvenance(input.provenance, "preflight.provenance")
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1431
|
+
function assertDiagnostic(value, path2) {
|
|
1432
|
+
const input = object5(value, path2);
|
|
1433
|
+
const allowed = /* @__PURE__ */ new Set(["code", "severity", "message", "path", "expected", "actual"]);
|
|
1434
|
+
if (!Object.keys(input).every((key) => allowed.has(key)) || !["code", "severity", "message"].every((key) => key in input)) throw new TypeError(`${path2} has unknown or missing fields.`);
|
|
1435
|
+
token3(input.code, `${path2}.code`);
|
|
1436
|
+
if (!["error", "warning", "info"].includes(String(input.severity))) throw new TypeError(`${path2}.severity is invalid.`);
|
|
1437
|
+
token3(input.message, `${path2}.message`, 4096);
|
|
1438
|
+
if (input.path !== void 0) token3(input.path, `${path2}.path`, 1024);
|
|
1439
|
+
return input;
|
|
1440
|
+
}
|
|
1441
|
+
var phaseNames = ["assembly", "reflection-schema", "shader-compilation", "pipeline-layout", "pipeline-creation", "bind-group-creation", "cpu-to-gpu-layout", "gpu-to-cpu-layout", "bounded-execution", "semantic-readback"];
|
|
1442
|
+
function osVersionMatches(cell, version, channel) {
|
|
1443
|
+
if (!/^\d+(?:\.\d+)*(?:[-+][A-Za-z0-9.]+)?$/u.test(version)) return false;
|
|
1444
|
+
const requirement = cell.os.versionRequirement;
|
|
1445
|
+
if (requirement.kind === "exact") return channel === null && version === requirement.value;
|
|
1446
|
+
const major = Number.parseInt(version.split(".")[0], 10);
|
|
1447
|
+
if (requirement.kind === "major") return channel === null && major === requirement.value;
|
|
1448
|
+
if (requirement.kind === "minimum-major") return channel === null && major >= requirement.value;
|
|
1449
|
+
return channel === requirement.channel;
|
|
1450
|
+
}
|
|
1451
|
+
function assertResult(value, path2, cell, passingRequired, timeBounds, expectedRunner) {
|
|
1452
|
+
const input = object5(value, path2);
|
|
1453
|
+
exact3(input, ["compileUnitId", "cellId", "status", "startedAt", "completedAt", "observed", "phases", "diagnostics"], path2);
|
|
1454
|
+
token3(input.compileUnitId, `${path2}.compileUnitId`);
|
|
1455
|
+
if (input.cellId !== cell.cellId) throw new TypeError(`${path2}.cellId differs from its cell evidence.`);
|
|
1456
|
+
const status = String(input.status);
|
|
1457
|
+
if (!["passed", "failed", "skipped", "timeout", "device-lost", "runner-unavailable", "adapter-unavailable"].includes(status)) throw new TypeError(`${path2}.status is invalid.`);
|
|
1458
|
+
const started = timestamp(input.startedAt, `${path2}.startedAt`);
|
|
1459
|
+
const completed = timestamp(input.completedAt, `${path2}.completedAt`);
|
|
1460
|
+
if (Date.parse(completed) < Date.parse(started)) throw new TypeError(`${path2} has reversed timestamps.`);
|
|
1461
|
+
if (timeBounds && (Date.parse(started) < Date.parse(timeBounds.earliest) || Date.parse(completed) > Date.parse(timeBounds.latest))) throw new TypeError(`${path2} timestamps fall outside trusted preflight and aggregation bounds.`);
|
|
1462
|
+
const observed = object5(input.observed, `${path2}.observed`);
|
|
1463
|
+
exact3(observed, ["runner", "os", "browser", "adapter", "features", "limits"], `${path2}.observed`);
|
|
1464
|
+
const runner = object5(observed.runner, `${path2}.observed.runner`);
|
|
1465
|
+
exact3(runner, ["id", "labels"], `${path2}.observed.runner`);
|
|
1466
|
+
const runnerId = token3(runner.id, `${path2}.observed.runner.id`);
|
|
1467
|
+
const labels = array2(runner.labels, `${path2}.observed.runner.labels`).map((item, index) => token3(item, `${path2}.observed.runner.labels[${index}]`));
|
|
1468
|
+
const normalizedLabels = labels.map(foldRunnerLabel);
|
|
1469
|
+
if (new Set(normalizedLabels).size !== normalizedLabels.length || cell.runnerLabels.some((label) => !normalizedLabels.includes(foldRunnerLabel(label)))) throw new TypeError(`${path2} actual runner labels do not contain the matrix route (ASCII case-insensitive).`);
|
|
1470
|
+
if (expectedRunner && (runnerId !== expectedRunner.name || !canonicalEqual(labels, expectedRunner.labels))) throw new TypeError(`${path2} runner identity/labels differ from the exact runner API preflight observation.`);
|
|
1471
|
+
const os = object5(observed.os, `${path2}.observed.os`);
|
|
1472
|
+
exact3(os, ["name", "version", "channel", "architecture"], `${path2}.observed.os`);
|
|
1473
|
+
const osVersion = token3(os.version, `${path2}.observed.os.version`);
|
|
1474
|
+
const osChannel = os.channel === null ? null : token3(os.channel, `${path2}.observed.os.channel`);
|
|
1475
|
+
if (os.name !== cell.os.name || os.architecture !== cell.os.architecture || status === "passed" && !osVersionMatches(cell, osVersion, osChannel) || status !== "passed" && osVersion !== "unavailable" && !osVersionMatches(cell, osVersion, osChannel)) throw new TypeError(`${path2} observed the wrong OS target or failed its version requirement.`);
|
|
1476
|
+
const browser = object5(observed.browser, `${path2}.observed.browser`);
|
|
1477
|
+
exact3(browser, ["name", "version", "channel"], `${path2}.observed.browser`);
|
|
1478
|
+
if (browser.name !== cell.browser.name || browser.channel !== cell.browser.channel) throw new TypeError(`${path2} observed the wrong browser target.`);
|
|
1479
|
+
const browserVersion = token3(browser.version, `${path2}.observed.browser.version`);
|
|
1480
|
+
const adapter = object5(observed.adapter, `${path2}.observed.adapter`);
|
|
1481
|
+
exact3(adapter, ["physical", "vendor", "family", "architecture", "device", "description", "backend", "driver"], `${path2}.observed.adapter`);
|
|
1482
|
+
if (adapter.physical !== (cell.adapter.kind === "physical") || adapter.backend !== cell.adapter.backend || String(adapter.vendor).trim().toLowerCase() !== cell.adapter.vendor || String(adapter.family).trim().toLowerCase() !== cell.adapter.family) throw new TypeError(`${path2} observed the wrong adapter vendor/family/backend.`);
|
|
1483
|
+
for (const key of ["vendor", "family", "architecture", "device", "description", "driver"]) token3(adapter[key], `${path2}.observed.adapter.${key}`, 1024);
|
|
1484
|
+
const features = array2(observed.features, `${path2}.observed.features`).map((item, index) => token3(item, `${path2}.observed.features[${index}]`));
|
|
1485
|
+
if (new Set(features).size !== features.length) throw new TypeError(`${path2}.observed.features contains duplicates.`);
|
|
1486
|
+
const limits = object5(observed.limits, `${path2}.observed.limits`);
|
|
1487
|
+
for (const [name, limit] of Object.entries(limits)) {
|
|
1488
|
+
token3(name, `${path2}.observed.limits key`);
|
|
1489
|
+
if (typeof limit !== "number" || !Number.isFinite(limit) || limit < 0) throw new TypeError(`${path2}.observed.limits.${name} is invalid.`);
|
|
1490
|
+
}
|
|
1491
|
+
const phases = array2(input.phases, `${path2}.phases`, phaseNames.length).map((phaseValue, index) => {
|
|
1492
|
+
const phasePath = `${path2}.phases[${index}]`;
|
|
1493
|
+
const phase = object5(phaseValue, phasePath);
|
|
1494
|
+
const name = String(phase.name);
|
|
1495
|
+
if (name === "shader-compilation") {
|
|
1496
|
+
exact3(phase, ["name", "status", "durationMs", "compilationMessagesSha256", "errorCount"], phasePath);
|
|
1497
|
+
sha2(phase.compilationMessagesSha256, `${phasePath}.compilationMessagesSha256`);
|
|
1498
|
+
integer3(phase.errorCount, `${phasePath}.errorCount`);
|
|
1499
|
+
} else if (name === "semantic-readback") {
|
|
1500
|
+
exact3(phase, ["name", "status", "durationMs", "expectedSha256", "actualSha256"], phasePath);
|
|
1501
|
+
sha2(phase.expectedSha256, `${phasePath}.expectedSha256`);
|
|
1502
|
+
sha2(phase.actualSha256, `${phasePath}.actualSha256`);
|
|
1503
|
+
} else {
|
|
1504
|
+
exact3(phase, ["name", "status", "durationMs", "evidenceSha256"], phasePath);
|
|
1505
|
+
sha2(phase.evidenceSha256, `${phasePath}.evidenceSha256`);
|
|
1506
|
+
}
|
|
1507
|
+
if (!phaseNames.includes(name) || !["passed", "failed"].includes(String(phase.status))) throw new TypeError(`${phasePath} is invalid.`);
|
|
1508
|
+
integer3(phase.durationMs, `${phasePath}.durationMs`);
|
|
1509
|
+
return phase;
|
|
1510
|
+
});
|
|
1511
|
+
const diagnostics = array2(input.diagnostics, `${path2}.diagnostics`, 256).map((item, index) => assertDiagnostic(item, `${path2}.diagnostics[${index}]`));
|
|
1512
|
+
if (passingRequired || status === "passed") {
|
|
1513
|
+
if (status !== "passed" || phases.length !== phaseNames.length || !phaseNames.every((name, index) => phases[index]?.name === name && phases[index]?.status === "passed")) throw new TypeError(`${path2} lacks all ten passed qualification phases in fixed order.`);
|
|
1514
|
+
if (runnerId === "unavailable" || browserVersion === "unavailable" || adapter.device === "unavailable" || adapter.driver === "unavailable") throw new TypeError(`${path2} passed without concrete runner/browser/adapter/driver observations.`);
|
|
1515
|
+
const compilation = phases.find((phase) => phase.name === "shader-compilation");
|
|
1516
|
+
if (compilation.errorCount !== 0) throw new TypeError(`${path2} contains compilation errors.`);
|
|
1517
|
+
const readback = phases.find((phase) => phase.name === "semantic-readback");
|
|
1518
|
+
if (readback.expectedSha256 !== readback.actualSha256) throw new TypeError(`${path2} semantic readback differs.`);
|
|
1519
|
+
if (diagnostics.some((item) => item.severity === "error")) throw new TypeError(`${path2} passed with an error diagnostic.`);
|
|
1520
|
+
}
|
|
1521
|
+
return input;
|
|
1522
|
+
}
|
|
1523
|
+
function assertCellEvidence(value, cell, matrix, preflight, harness, adapterHarness, expectedRunner, expectedUnits, latest) {
|
|
1524
|
+
const input = object5(value, `cellEvidence.${cell.cellId}`);
|
|
1525
|
+
exact3(input, ["contractVersion", "qualificationId", "matrixId", "matrixVersion", "matrixSha256", "cellId", "dataBundleSha256", "compileUnitInventorySha256", "harness", "automation", "subjectBindingSha256", "qualificationPreflightProvenance", "producer", "results"], `cellEvidence.${cell.cellId}`);
|
|
1526
|
+
if (input.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION || input.qualificationId !== preflight.qualificationId || input.matrixId !== matrix.matrixId || input.matrixVersion !== matrix.version || input.cellId !== cell.cellId || input.matrixSha256 !== preflight.matrixSha256 || input.dataBundleSha256 !== preflight.dataBundleSha256 || input.compileUnitInventorySha256 !== preflight.compileUnitInventorySha256 || input.subjectBindingSha256 !== preflight.subjectBindingSha256) throw new TypeError(`Cell evidence ${cell.cellId} has stale subject/matrix identities.`);
|
|
1527
|
+
const actualHarness = object5(input.harness, `cellEvidence.${cell.cellId}.harness`);
|
|
1528
|
+
exact3(actualHarness, ["id", "version", "sha256"], `cellEvidence.${cell.cellId}.harness`);
|
|
1529
|
+
if (!canonicalEqual(actualHarness, harness)) throw new TypeError(`Cell evidence ${cell.cellId} used a different harness.`);
|
|
1530
|
+
const automation2 = object5(input.automation, `cellEvidence.${cell.cellId}.automation`);
|
|
1531
|
+
exact3(automation2, ["kind", "driver", "version", "sha256"], `cellEvidence.${cell.cellId}.automation`);
|
|
1532
|
+
if (automation2.kind !== cell.automation.kind) throw new TypeError(`Cell evidence ${cell.cellId} used the wrong automation route.`);
|
|
1533
|
+
token3(automation2.driver, `cellEvidence.${cell.cellId}.automation.driver`);
|
|
1534
|
+
token3(automation2.version, `cellEvidence.${cell.cellId}.automation.version`);
|
|
1535
|
+
sha2(automation2.sha256, `cellEvidence.${cell.cellId}.automation.sha256`);
|
|
1536
|
+
if (adapterHarness !== null && !canonicalEqual({ id: automation2.driver, version: automation2.version, sha256: automation2.sha256 }, adapterHarness)) throw new TypeError(`Cell evidence ${cell.cellId} automation differs from its independently verified preflight adapter harness.`);
|
|
1537
|
+
if (!canonicalEqual(parseTrustedWorkflowProvenance(input.qualificationPreflightProvenance), preflight.provenance)) throw new TypeError(`Cell evidence ${cell.cellId} changed trusted prepare provenance.`);
|
|
1538
|
+
const producer = parseQualificationExecutionProducer(input.producer, `cellEvidence.${cell.cellId}.producer`);
|
|
1539
|
+
assertProducerMatchesPreflight(producer, preflight.provenance, cell, `cellEvidence.${cell.cellId}.producer`, cell.adapter.kind === "software" ? "swiftshader" : "physical");
|
|
1540
|
+
const results = array2(input.results, `cellEvidence.${cell.cellId}.results`);
|
|
1541
|
+
if (results.length !== expectedUnits.size) throw new TypeError(`Cell evidence ${cell.cellId} result count is incomplete.`);
|
|
1542
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1543
|
+
results.forEach((result, index) => {
|
|
1544
|
+
const parsed = assertResult(result, `cellEvidence.${cell.cellId}.results[${index}]`, cell, true, { earliest: preflight.provenance.oidcAttestation.verifiedAt, latest }, expectedRunner);
|
|
1545
|
+
if (parsed.observed.runner.id !== producer.runner.name) throw new TypeError(`Cell evidence ${cell.cellId} result runner differs from its producer.`);
|
|
1546
|
+
if (!expectedUnits.has(parsed.compileUnitId) || ids.has(parsed.compileUnitId)) throw new TypeError(`Cell evidence ${cell.cellId} has duplicate/unexpected compile unit ${parsed.compileUnitId}.`);
|
|
1547
|
+
ids.add(parsed.compileUnitId);
|
|
1548
|
+
});
|
|
1549
|
+
return input;
|
|
1550
|
+
}
|
|
1551
|
+
function syntheticResult(unitId, cell, status, message, now) {
|
|
1552
|
+
return {
|
|
1553
|
+
compileUnitId: unitId,
|
|
1554
|
+
cellId: cell.cellId,
|
|
1555
|
+
status,
|
|
1556
|
+
startedAt: now,
|
|
1557
|
+
completedAt: now,
|
|
1558
|
+
observed: {
|
|
1559
|
+
runner: { id: "unavailable", labels: cell.runnerLabels },
|
|
1560
|
+
os: { name: cell.os.name, version: "unavailable", channel: null, architecture: cell.os.architecture },
|
|
1561
|
+
browser: { name: cell.browser.name, version: "unavailable", channel: cell.browser.channel },
|
|
1562
|
+
adapter: { physical: cell.adapter.kind === "physical", vendor: cell.adapter.vendor, family: cell.adapter.family, architecture: cell.os.architecture, device: "unavailable", description: "unavailable", backend: cell.adapter.backend, driver: "unavailable" },
|
|
1563
|
+
features: [],
|
|
1564
|
+
limits: {}
|
|
1565
|
+
},
|
|
1566
|
+
phases: [],
|
|
1567
|
+
diagnostics: [{ code: status === "timeout" ? "timeout" : "runner-unavailable", severity: "error", message }]
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1570
|
+
async function aggregateShaderValidationEvidence(input) {
|
|
1571
|
+
const verifyArtifact = async (artifact, label) => {
|
|
1572
|
+
if (await computeSha256(artifact.bytes) !== artifact.sha256) throw new TypeError(`${label} artifact digest is not derived from its exact bytes.`);
|
|
1573
|
+
let parsed;
|
|
1574
|
+
try {
|
|
1575
|
+
parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(artifact.bytes));
|
|
1576
|
+
} catch (cause) {
|
|
1577
|
+
throw new TypeError(`${label} bytes are not UTF-8 JSON.`, { cause });
|
|
1578
|
+
}
|
|
1579
|
+
if (!canonicalEqual(parsed, artifact.value)) throw new TypeError(`${label} parsed value differs from its exact bytes.`);
|
|
1580
|
+
};
|
|
1581
|
+
await verifyArtifact(input.preflight, "Qualification preflight");
|
|
1582
|
+
for (const artifact of input.cellEvidence) await verifyArtifact(artifact, "Cell evidence");
|
|
1583
|
+
for (const artifact of input.runnerPreflights) await verifyArtifact(artifact, "Runner preflight");
|
|
1584
|
+
for (const artifact of input.workflowDiagnostics) await verifyArtifact(artifact, "Workflow diagnostic");
|
|
1585
|
+
const preflight = input.preflight.value;
|
|
1586
|
+
const preflightInput = object5(preflight, "Qualification preflight");
|
|
1587
|
+
exact3(preflightInput, ["contractVersion", "kind", "qualificationId", "sourceBlob", "dataBundleSha256", "compileUnitInventorySha256", "matrixSha256", "harnessSha256", "subjectBindingSha256", "provenance"], "Qualification preflight");
|
|
1588
|
+
if (preflight.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION || preflight.kind !== "shader-qualification-preflight") throw new TypeError("Missing trusted qualification preflight.");
|
|
1589
|
+
token3(preflight.qualificationId, "Qualification preflight.qualificationId");
|
|
1590
|
+
sha2(preflight.dataBundleSha256, "Qualification preflight.dataBundleSha256");
|
|
1591
|
+
sha2(preflight.compileUnitInventorySha256, "Qualification preflight.compileUnitInventorySha256");
|
|
1592
|
+
sha2(preflight.matrixSha256, "Qualification preflight.matrixSha256");
|
|
1593
|
+
sha2(preflight.harnessSha256, "Qualification preflight.harnessSha256");
|
|
1594
|
+
sha2(preflight.subjectBindingSha256, "Qualification preflight.subjectBindingSha256");
|
|
1595
|
+
const preflightProvenance = parseTrustedWorkflowProvenance(preflight.provenance, "Qualification preflight.provenance");
|
|
1596
|
+
const sourceBlob = object5(preflight.sourceBlob, "Qualification preflight.sourceBlob");
|
|
1597
|
+
exact3(sourceBlob, ["host", "versionId", "uri"], "Qualification preflight.sourceBlob");
|
|
1598
|
+
const normalizedSource = immutableBlobUri(token3(sourceBlob.uri, "Qualification preflight.sourceBlob.uri", 2048));
|
|
1599
|
+
if (!canonicalEqual(sourceBlob, normalizedSource)) throw new TypeError("Qualification preflight source Blob claims are stale.");
|
|
1600
|
+
let parsedMatrix;
|
|
1601
|
+
try {
|
|
1602
|
+
parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
|
|
1603
|
+
} catch (cause) {
|
|
1604
|
+
throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
|
|
1605
|
+
}
|
|
1606
|
+
if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
|
|
1607
|
+
const actualMatrixSha256 = await computeSha256(input.matrixBytes);
|
|
1608
|
+
if (preflight.matrixSha256 !== actualMatrixSha256) throw new TypeError("Qualification preflight matrix artifact digest is stale.");
|
|
1609
|
+
const actualInventorySha256 = await computeQualificationInventorySha256(input.bundle);
|
|
1610
|
+
if (preflight.compileUnitInventorySha256 !== actualInventorySha256 || input.bundle.subject.compileUnitInventorySha256 !== actualInventorySha256) throw new TypeError("Qualification preflight inventory digest is stale.");
|
|
1611
|
+
const actualSubjectBinding = await computeQualificationSubjectBinding({ subject: input.bundle.subject, dataBundleSha256: preflight.dataBundleSha256, compileUnitInventorySha256: actualInventorySha256, matrixSha256: actualMatrixSha256, harnessSha256: input.harness.sha256 });
|
|
1612
|
+
if (preflight.subjectBindingSha256 !== actualSubjectBinding) throw new TypeError("Qualification preflight subject binding is stale.");
|
|
1613
|
+
const units = new Set(input.bundle.inventory.compileUnits.map((unit) => unit.compileUnitId));
|
|
1614
|
+
const now = input.generatedAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
1615
|
+
timestamp(now, "generatedAt");
|
|
1616
|
+
if (Date.parse(now) < Date.parse(preflightProvenance.oidcAttestation.verifiedAt)) throw new TypeError("Aggregate timestamp predates trusted preflight verification.");
|
|
1617
|
+
if (input.harness.sha256 !== preflight.harnessSha256) throw new TypeError("Harness digest differs from trusted preflight.");
|
|
1618
|
+
const cells = new Map(input.matrix.cells.map((cell) => [cell.cellId, cell]));
|
|
1619
|
+
const cellArtifacts = /* @__PURE__ */ new Map();
|
|
1620
|
+
for (const artifact of input.cellEvidence) {
|
|
1621
|
+
const id = artifact.value.cellId;
|
|
1622
|
+
if (!cells.has(id) || cellArtifacts.has(id)) throw new TypeError(`Duplicate or unexpected cell evidence ${id}.`);
|
|
1623
|
+
cellArtifacts.set(id, artifact);
|
|
1624
|
+
}
|
|
1625
|
+
const runnerArtifacts = /* @__PURE__ */ new Map();
|
|
1626
|
+
for (const artifact of input.runnerPreflights) {
|
|
1627
|
+
const id = artifact.value.cellId;
|
|
1628
|
+
if (!cells.has(id) || runnerArtifacts.has(id)) throw new TypeError(`Duplicate or unexpected runner preflight ${id}.`);
|
|
1629
|
+
runnerArtifacts.set(id, artifact);
|
|
1630
|
+
}
|
|
1631
|
+
const diagnosticArtifacts = /* @__PURE__ */ new Map();
|
|
1632
|
+
for (const artifact of input.workflowDiagnostics) {
|
|
1633
|
+
const id = artifact.value.cellId;
|
|
1634
|
+
if (!cells.has(id) || diagnosticArtifacts.has(id)) throw new TypeError(`Duplicate or unexpected workflow diagnostic ${id}.`);
|
|
1635
|
+
diagnosticArtifacts.set(id, artifact);
|
|
1636
|
+
}
|
|
1637
|
+
const results = [];
|
|
1638
|
+
const cellRuns = [];
|
|
1639
|
+
for (const cell of input.matrix.cells) {
|
|
1640
|
+
const runner = runnerArtifacts.get(cell.cellId);
|
|
1641
|
+
const diagnostic = diagnosticArtifacts.get(cell.cellId);
|
|
1642
|
+
const cellArtifact = cellArtifacts.get(cell.cellId);
|
|
1643
|
+
if (!runner) throw new TypeError(`Cell ${cell.cellId} lacks runner preflight evidence.`);
|
|
1644
|
+
if (runner) {
|
|
1645
|
+
const value2 = runner.value;
|
|
1646
|
+
const raw = object5(value2, `runnerPreflight.${cell.cellId}`);
|
|
1647
|
+
exact3(raw, ["contractVersion", "kind", "qualificationId", "cellId", "status", "matrixSha256", "runnerLabels", "matchedRunners", "adapterHarness", "qualificationPreflightProvenance", "producer"], `runnerPreflight.${cell.cellId}`);
|
|
1648
|
+
const producer = parseQualificationExecutionProducer(value2.producer, `runnerPreflight.${cell.cellId}.producer`);
|
|
1649
|
+
assertProducerMatchesPreflight(producer, preflight.provenance, cell, `runnerPreflight.${cell.cellId}.producer`, cell.adapter.kind === "software" ? "swiftshader" : "physical-runner-preflight");
|
|
1650
|
+
if (value2.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION || value2.kind !== "shader-runner-cell-preflight-evidence" || value2.qualificationId !== preflight.qualificationId || value2.cellId !== cell.cellId || value2.matrixSha256 !== preflight.matrixSha256 || !canonicalEqual(value2.runnerLabels, cell.runnerLabels) || !canonicalEqual(value2.qualificationPreflightProvenance, preflight.provenance)) throw new TypeError(`Runner preflight ${cell.cellId} is stale or inconsistent.`);
|
|
1651
|
+
const requestedLabels = cell.runnerLabels.map(foldRunnerLabel);
|
|
1652
|
+
const matched = array2(value2.matchedRunners, `runnerPreflight.${cell.cellId}.matchedRunners`).map((item, index) => {
|
|
1653
|
+
const label = `runnerPreflight.${cell.cellId}.matchedRunners[${index}]`;
|
|
1654
|
+
const match = object5(item, label);
|
|
1655
|
+
exact3(match, ["name", "labels"], label);
|
|
1656
|
+
const labels = array2(match.labels, `${label}.labels`).map((entry, labelIndex) => token3(entry, `${label}.labels[${labelIndex}]`));
|
|
1657
|
+
const normalized = labels.map(foldRunnerLabel);
|
|
1658
|
+
if (labels.length === 0 || new Set(normalized).size !== normalized.length || requestedLabels.some((required) => !normalized.includes(required))) throw new TypeError(`${label} does not preserve the actual runner API labels containing the requested matrix route.`);
|
|
1659
|
+
return { name: token3(match.name, `${label}.name`), labels };
|
|
1660
|
+
});
|
|
1661
|
+
if (new Set(matched.map((item) => item.name)).size !== matched.length) throw new TypeError(`Runner preflight ${cell.cellId} repeats matched runners.`);
|
|
1662
|
+
if (value2.adapterHarness !== null) {
|
|
1663
|
+
const adapterHarness = object5(value2.adapterHarness, `runnerPreflight.${cell.cellId}.adapterHarness`);
|
|
1664
|
+
exact3(adapterHarness, ["id", "version", "sha256"], `runnerPreflight.${cell.cellId}.adapterHarness`);
|
|
1665
|
+
token3(adapterHarness.id, `runnerPreflight.${cell.cellId}.adapterHarness.id`);
|
|
1666
|
+
token3(adapterHarness.version, `runnerPreflight.${cell.cellId}.adapterHarness.version`);
|
|
1667
|
+
sha2(adapterHarness.sha256, `runnerPreflight.${cell.cellId}.adapterHarness.sha256`);
|
|
1668
|
+
}
|
|
1669
|
+
if (value2.status === "available" && matched.length === 0) throw new TypeError(`Available cell ${cell.cellId} has no matched runner.`);
|
|
1670
|
+
if (value2.status === "runner-unavailable" && matched.length !== 0) throw new TypeError(`Unavailable cell ${cell.cellId} claims matched runners.`);
|
|
1671
|
+
if (value2.status === "runner-unavailable" && value2.adapterHarness !== null) throw new TypeError(`Unavailable cell ${cell.cellId} claims an executed adapter harness.`);
|
|
1672
|
+
if (value2.status === "available" && cell.adapter.kind === "software" && value2.adapterHarness === null) throw new TypeError(`Hosted SwiftShader cell ${cell.cellId} lacks its independently observable adapter harness.`);
|
|
1673
|
+
}
|
|
1674
|
+
if (diagnostic && cellArtifact) throw new TypeError(`Cell ${cell.cellId} has conflicting diagnostic and qualification evidence.`);
|
|
1675
|
+
if (runner?.value.status === "runner-unavailable") {
|
|
1676
|
+
if (cellArtifact || diagnostic) throw new TypeError(`Unavailable cell ${cell.cellId} has conflicting evidence.`);
|
|
1677
|
+
for (const unit of units) results.push(syntheticResult(unit, cell, "runner-unavailable", "Required physical runner was unavailable.", now));
|
|
1678
|
+
const cellResults = results.slice(-units.size);
|
|
1679
|
+
cellRuns.push({ cellId: cell.cellId, source: "runner-preflight", sourceArtifactSha256: runner.sha256, resultsSha256: await computeSha256(canonicalizeGpuContract(cellResults)), qualificationPreflightProvenance: preflight.provenance, producer: runner.value.producer, harness: input.harness, automation: null, resultCount: units.size, status: "runner-unavailable" });
|
|
1680
|
+
continue;
|
|
1681
|
+
}
|
|
1682
|
+
if (diagnostic) {
|
|
1683
|
+
const value2 = diagnostic.value;
|
|
1684
|
+
const raw = object5(value2, `workflowDiagnostic.${cell.cellId}`);
|
|
1685
|
+
exact3(raw, ["contractVersion", "kind", "qualificationId", "cellId", "status", "matrixSha256", "message", "qualificationPreflightProvenance", "producer"], `workflowDiagnostic.${cell.cellId}`);
|
|
1686
|
+
const producer = parseQualificationExecutionProducer(value2.producer, `workflowDiagnostic.${cell.cellId}.producer`);
|
|
1687
|
+
assertProducerMatchesPreflight(producer, preflight.provenance, cell, `workflowDiagnostic.${cell.cellId}.producer`, cell.adapter.kind === "software" ? "swiftshader" : "physical");
|
|
1688
|
+
if (!runner.value.matchedRunners.some((item) => item.name === producer.runner.name)) throw new TypeError(`Workflow diagnostic ${cell.cellId} was not produced by a runner matched in preflight.`);
|
|
1689
|
+
if (value2.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION || value2.kind !== "non-qualifying-workflow-diagnostic" || value2.qualificationId !== preflight.qualificationId || value2.cellId !== cell.cellId || value2.matrixSha256 !== preflight.matrixSha256 || !canonicalEqual(value2.qualificationPreflightProvenance, preflight.provenance)) throw new TypeError(`Workflow diagnostic ${cell.cellId} is stale or inconsistent.`);
|
|
1690
|
+
token3(value2.message, `workflowDiagnostic.${cell.cellId}.message`, 4096);
|
|
1691
|
+
const status2 = value2.status === "timeout" ? "timeout" : "failed";
|
|
1692
|
+
for (const unit of units) results.push(syntheticResult(unit, cell, status2, value2.message, now));
|
|
1693
|
+
const cellResults = results.slice(-units.size);
|
|
1694
|
+
cellRuns.push({ cellId: cell.cellId, source: "workflow-diagnostic", sourceArtifactSha256: diagnostic.sha256, resultsSha256: await computeSha256(canonicalizeGpuContract(cellResults)), qualificationPreflightProvenance: preflight.provenance, producer: value2.producer, harness: input.harness, automation: null, resultCount: units.size, status: status2 });
|
|
1695
|
+
continue;
|
|
1696
|
+
}
|
|
1697
|
+
if (!cellArtifact) throw new TypeError(`Cell ${cell.cellId} has no qualification evidence.`);
|
|
1698
|
+
const matchedRunner = runner.value.matchedRunners.find((item) => item.name === cellArtifact.value.producer.runner.name);
|
|
1699
|
+
if (!matchedRunner) throw new TypeError(`Cell evidence ${cell.cellId} producer was not matched by runner preflight.`);
|
|
1700
|
+
const value = assertCellEvidence(cellArtifact.value, cell, input.matrix, preflight, input.harness, runner.value.adapterHarness, matchedRunner, units, now);
|
|
1701
|
+
results.push(...value.results);
|
|
1702
|
+
cellRuns.push({ cellId: cell.cellId, source: "cell-evidence", sourceArtifactSha256: cellArtifact.sha256, resultsSha256: await computeSha256(canonicalizeGpuContract(value.results)), qualificationPreflightProvenance: value.qualificationPreflightProvenance, producer: value.producer, harness: value.harness, automation: value.automation, resultCount: value.results.length, status: "passed" });
|
|
1703
|
+
}
|
|
1704
|
+
const expectedResults = units.size * cells.size;
|
|
1705
|
+
if (results.length !== expectedResults) throw new TypeError("Aggregate result product is incomplete.");
|
|
1706
|
+
const status = results.every((result) => result.status === "passed") ? "passed" : "failed";
|
|
1707
|
+
const subject = { ...input.bundle.subject, dataBundleSha256: preflight.dataBundleSha256 };
|
|
1708
|
+
const draft = {
|
|
1709
|
+
contractVersion: SHADER_VALIDATION_EVIDENCE_VERSION,
|
|
1710
|
+
status,
|
|
1711
|
+
generatedAt: now,
|
|
1712
|
+
subjectBindingSha256: preflight.subjectBindingSha256,
|
|
1713
|
+
subject,
|
|
1714
|
+
matrixRef: { matrixId: input.matrix.matrixId, version: input.matrix.version, sha256: preflight.matrixSha256 },
|
|
1715
|
+
toolchain: { packageVersion: input.packageVersion, reflectorVersion: "1.5.0", harness: input.harness },
|
|
1716
|
+
qualificationPreflightProvenance: preflight.provenance,
|
|
1717
|
+
counts: { compileUnits: units.size, cells: cells.size, expectedResults, passedResults: results.filter((result) => result.status === "passed").length },
|
|
1718
|
+
cellRuns,
|
|
1719
|
+
results
|
|
1720
|
+
};
|
|
1721
|
+
return { ...draft, evidenceId: await computeValidationEvidenceId(draft) };
|
|
1722
|
+
}
|
|
1723
|
+
async function validateShaderValidationEvidence(input) {
|
|
1724
|
+
try {
|
|
1725
|
+
const evidence = object5(input.evidence, "evidence");
|
|
1726
|
+
exact3(evidence, ["contractVersion", "evidenceId", "status", "generatedAt", "subjectBindingSha256", "subject", "matrixRef", "toolchain", "qualificationPreflightProvenance", "counts", "cellRuns", "results"], "evidence");
|
|
1727
|
+
if (evidence.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION) throw new TypeError("Unsupported evidence contract version.");
|
|
1728
|
+
const evidenceId = token3(evidence.evidenceId, "evidence.evidenceId");
|
|
1729
|
+
const generatedAt = timestamp(evidence.generatedAt, "evidence.generatedAt");
|
|
1730
|
+
const subjectBindingSha256 = sha2(evidence.subjectBindingSha256, "evidence.subjectBindingSha256");
|
|
1731
|
+
if (evidence.status !== "passed" && evidence.status !== "failed") throw new TypeError("Evidence status is invalid.");
|
|
1732
|
+
let parsedMatrix;
|
|
1733
|
+
try {
|
|
1734
|
+
parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
|
|
1735
|
+
} catch (cause) {
|
|
1736
|
+
throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
|
|
1737
|
+
}
|
|
1738
|
+
if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
|
|
1739
|
+
const matrixSha256 = await computeSha256(input.matrixBytes);
|
|
1740
|
+
const inventorySha256 = await computeQualificationInventorySha256(input.bundle);
|
|
1741
|
+
if (inventorySha256 !== input.bundle.subject.compileUnitInventorySha256) throw new TypeError("Bundle subject inventory digest is stale.");
|
|
1742
|
+
const subject = object5(evidence.subject, "evidence.subject");
|
|
1743
|
+
const expectedSubjectKeys = [...Object.keys(input.bundle.subject), "dataBundleSha256"];
|
|
1744
|
+
exact3(subject, expectedSubjectKeys, "evidence.subject");
|
|
1745
|
+
const candidateSubject = Object.fromEntries(Object.entries(subject).filter(([key]) => key !== "dataBundleSha256"));
|
|
1746
|
+
if (!canonicalEqual(candidateSubject, input.bundle.subject)) throw new TypeError("Evidence candidate subject differs from bundle.");
|
|
1747
|
+
const dataBundleSha256 = sha2(subject.dataBundleSha256, "evidence.subject.dataBundleSha256");
|
|
1748
|
+
if (input.dataBundleSha256 && input.dataBundleSha256 !== dataBundleSha256) throw new TypeError("Evidence data bundle digest differs from the exact archive.");
|
|
1749
|
+
if (subject.compileUnitInventorySha256 !== inventorySha256) throw new TypeError("Evidence compile-unit inventory digest is stale.");
|
|
1750
|
+
const matrixRef = object5(evidence.matrixRef, "evidence.matrixRef");
|
|
1751
|
+
exact3(matrixRef, ["matrixId", "version", "sha256"], "evidence.matrixRef");
|
|
1752
|
+
if (matrixRef.matrixId !== input.matrix.matrixId || matrixRef.version !== input.matrix.version || matrixRef.sha256 !== matrixSha256) throw new TypeError("Evidence matrix artifact identity differs.");
|
|
1753
|
+
const toolchain = object5(evidence.toolchain, "evidence.toolchain");
|
|
1754
|
+
exact3(toolchain, ["packageVersion", "reflectorVersion", "harness"], "evidence.toolchain");
|
|
1755
|
+
token3(toolchain.packageVersion, "evidence.toolchain.packageVersion");
|
|
1756
|
+
if (toolchain.reflectorVersion !== "1.5.0") throw new TypeError("Evidence reflector version differs.");
|
|
1757
|
+
const harness = object5(toolchain.harness, "evidence.toolchain.harness");
|
|
1758
|
+
exact3(harness, ["id", "version", "sha256"], "evidence.toolchain.harness");
|
|
1759
|
+
token3(harness.id, "evidence.toolchain.harness.id");
|
|
1760
|
+
token3(harness.version, "evidence.toolchain.harness.version");
|
|
1761
|
+
const harnessSha256 = sha2(harness.sha256, "evidence.toolchain.harness.sha256");
|
|
1762
|
+
const preflightProvenance = parseTrustedWorkflowProvenance(evidence.qualificationPreflightProvenance, "evidence.qualificationPreflightProvenance");
|
|
1763
|
+
if (Date.parse(generatedAt) < Date.parse(preflightProvenance.oidcAttestation.verifiedAt)) throw new TypeError("Evidence predates trusted preflight verification.");
|
|
1764
|
+
const expectedBinding = await computeQualificationSubjectBinding({ subject: input.bundle.subject, dataBundleSha256, compileUnitInventorySha256: inventorySha256, matrixSha256, harnessSha256 });
|
|
1765
|
+
if (subjectBindingSha256 !== expectedBinding) throw new TypeError("Evidence subject binding is stale.");
|
|
1766
|
+
if (evidenceId !== await computeValidationEvidenceId(evidence)) throw new TypeError("Evidence identity is stale.");
|
|
1767
|
+
const units = new Set(input.bundle.inventory.compileUnits.map((unit) => unit.compileUnitId));
|
|
1768
|
+
const cells = new Map(input.matrix.cells.map((cell) => [cell.cellId, cell]));
|
|
1769
|
+
const expected = units.size * cells.size;
|
|
1770
|
+
const results = array2(evidence.results, "evidence.results");
|
|
1771
|
+
if (results.length !== expected) throw new TypeError("Evidence result product is incomplete.");
|
|
1772
|
+
const identities = /* @__PURE__ */ new Set();
|
|
1773
|
+
const parsedResults = [];
|
|
1774
|
+
let passed = 0;
|
|
1775
|
+
for (const [index, value] of results.entries()) {
|
|
1776
|
+
const raw = object5(value, `evidence.results[${index}]`);
|
|
1777
|
+
const cell = cells.get(String(raw.cellId));
|
|
1778
|
+
if (!cell || !units.has(String(raw.compileUnitId))) throw new TypeError(`Evidence result ${index} is unexpected.`);
|
|
1779
|
+
const result = assertResult(value, `evidence.results[${index}]`, cell, evidence.status === "passed", { earliest: preflightProvenance.oidcAttestation.verifiedAt, latest: generatedAt });
|
|
1780
|
+
const key = `${result.cellId}:${result.compileUnitId}`;
|
|
1781
|
+
if (identities.has(key)) throw new TypeError(`Evidence repeats ${key}.`);
|
|
1782
|
+
identities.add(key);
|
|
1783
|
+
parsedResults.push(result);
|
|
1784
|
+
if (result.status === "passed") passed += 1;
|
|
1785
|
+
}
|
|
1786
|
+
const counts = object5(evidence.counts, "evidence.counts");
|
|
1787
|
+
exact3(counts, ["compileUnits", "cells", "expectedResults", "passedResults"], "evidence.counts");
|
|
1788
|
+
if (counts.compileUnits !== units.size || counts.cells !== cells.size || counts.expectedResults !== expected || counts.passedResults !== passed) throw new TypeError("Evidence counts are stale.");
|
|
1789
|
+
const runs = array2(evidence.cellRuns, "evidence.cellRuns");
|
|
1790
|
+
if (runs.length !== cells.size) throw new TypeError("Evidence cell-run provenance is incomplete.");
|
|
1791
|
+
const runIds = /* @__PURE__ */ new Set();
|
|
1792
|
+
for (const [index, value] of runs.entries()) {
|
|
1793
|
+
const path2 = `evidence.cellRuns[${index}]`;
|
|
1794
|
+
const run = object5(value, path2);
|
|
1795
|
+
exact3(run, ["cellId", "source", "sourceArtifactSha256", "resultsSha256", "qualificationPreflightProvenance", "producer", "harness", "automation", "resultCount", "status"], path2);
|
|
1796
|
+
const cellId = token3(run.cellId, `${path2}.cellId`);
|
|
1797
|
+
const cell = cells.get(cellId);
|
|
1798
|
+
if (!cell || runIds.has(cellId)) throw new TypeError(`${path2}.cellId is duplicate/unexpected.`);
|
|
1799
|
+
runIds.add(cellId);
|
|
1800
|
+
if (!["cell-evidence", "runner-preflight", "workflow-diagnostic"].includes(String(run.source))) throw new TypeError(`${path2}.source is invalid.`);
|
|
1801
|
+
const sourceArtifactSha256 = sha2(run.sourceArtifactSha256, `${path2}.sourceArtifactSha256`);
|
|
1802
|
+
if (/^0{64}$/u.test(sourceArtifactSha256)) throw new TypeError(`${path2}.sourceArtifactSha256 cannot be a placeholder.`);
|
|
1803
|
+
const resultsSha256 = sha2(run.resultsSha256, `${path2}.resultsSha256`);
|
|
1804
|
+
if (!canonicalEqual(parseTrustedWorkflowProvenance(run.qualificationPreflightProvenance, `${path2}.qualificationPreflightProvenance`), preflightProvenance)) throw new TypeError(`${path2} changed qualification preflight provenance.`);
|
|
1805
|
+
const producer = parseQualificationExecutionProducer(run.producer, `${path2}.producer`);
|
|
1806
|
+
const expectedJob = run.source === "runner-preflight" ? cell.adapter.kind === "software" ? "swiftshader" : "physical-runner-preflight" : cell.adapter.kind === "software" ? "swiftshader" : "physical";
|
|
1807
|
+
assertProducerMatchesPreflight(producer, preflightProvenance, cell, `${path2}.producer`, expectedJob);
|
|
1808
|
+
if (!canonicalEqual(run.harness, harness)) throw new TypeError(`${path2}.harness differs.`);
|
|
1809
|
+
if (run.source === "cell-evidence") {
|
|
1810
|
+
const automation2 = object5(run.automation, `${path2}.automation`);
|
|
1811
|
+
exact3(automation2, ["kind", "driver", "version", "sha256"], `${path2}.automation`);
|
|
1812
|
+
if (automation2.kind !== cell.automation.kind) throw new TypeError(`${path2}.automation route differs.`);
|
|
1813
|
+
token3(automation2.driver, `${path2}.automation.driver`);
|
|
1814
|
+
token3(automation2.version, `${path2}.automation.version`);
|
|
1815
|
+
sha2(automation2.sha256, `${path2}.automation.sha256`);
|
|
1816
|
+
} else if (run.automation !== null) throw new TypeError(`${path2}.automation must be null when no adapter completed a cell run.`);
|
|
1817
|
+
const cellResults = parsedResults.filter((result) => result.cellId === cellId);
|
|
1818
|
+
if (run.resultCount !== units.size || cellResults.length !== units.size || await computeSha256(canonicalizeGpuContract(cellResults)) !== resultsSha256) throw new TypeError(`${path2} result count/digest is stale.`);
|
|
1819
|
+
const resultStatuses = new Set(cellResults.map((result) => result.status));
|
|
1820
|
+
if (resultStatuses.size !== 1 || !resultStatuses.has(String(run.status))) throw new TypeError(`${path2}.status differs from its results.`);
|
|
1821
|
+
if (run.source === "cell-evidence" && run.status !== "passed") throw new TypeError(`${path2} cell evidence must contain passing results.`);
|
|
1822
|
+
if (run.source === "runner-preflight" && run.status !== "runner-unavailable") throw new TypeError(`${path2} runner-preflight source has the wrong status.`);
|
|
1823
|
+
if (run.source === "workflow-diagnostic" && run.status !== "failed" && run.status !== "timeout") throw new TypeError(`${path2} workflow diagnostic has the wrong status.`);
|
|
1824
|
+
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.`);
|
|
1825
|
+
}
|
|
1826
|
+
if (evidence.status === "passed" !== (passed === expected) || input.requirePassed !== false && evidence.status !== "passed") throw new TypeError("Evidence does not satisfy the required passed gate.");
|
|
1827
|
+
return { ok: true, value: evidence };
|
|
1828
|
+
} catch (cause) {
|
|
1829
|
+
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid shader validation evidence." }] };
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
function parseShaderValidationEvidenceAttestationRef(value) {
|
|
1833
|
+
const input = object5(value, "attestationRef");
|
|
1834
|
+
exact3(input, ["contractVersion", "kind", "evidence", "attestation", "producer"], "attestationRef");
|
|
1835
|
+
if (input.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION || input.kind !== "shader-validation-evidence-attestation-ref") throw new TypeError("Unsupported evidence attestation ref.");
|
|
1836
|
+
const producer = object5(input.producer, "attestationRef.producer");
|
|
1837
|
+
exact3(producer, ["repository", "runId", "runAttempt", "trustedWorkflowRepository", "trustedWorkflowRef", "trustedWorkflowSha"], "attestationRef.producer");
|
|
1838
|
+
const repository = token3(producer.repository, "attestationRef.producer.repository");
|
|
1839
|
+
if (!/^Plasius-LTD\/[A-Za-z0-9._-]+$/u.test(repository)) throw new TypeError("Attestation caller repository is outside Plasius-LTD or malformed.");
|
|
1840
|
+
if (producer.trustedWorkflowRepository !== "Plasius-LTD/gpu-shader") throw new TypeError("Attestation trusted workflow repository differs.");
|
|
1841
|
+
gitObject(producer.trustedWorkflowSha, "attestationRef.producer.trustedWorkflowSha");
|
|
1842
|
+
trustedWorkflowRef(producer.trustedWorkflowRef, "attestationRef.producer.trustedWorkflowRef");
|
|
1843
|
+
token3(producer.runId, "attestationRef.producer.runId");
|
|
1844
|
+
integer3(producer.runAttempt, "attestationRef.producer.runAttempt", 1);
|
|
1845
|
+
const evidence = object5(input.evidence, "attestationRef.evidence");
|
|
1846
|
+
exact3(evidence, ["name", "sha256"], "attestationRef.evidence");
|
|
1847
|
+
const evidenceName = token3(evidence.name, "attestationRef.evidence.name");
|
|
1848
|
+
if (!/^[A-Za-z0-9._-]+\.json$/u.test(evidenceName)) throw new TypeError("Attested evidence name must be a JSON basename.");
|
|
1849
|
+
sha2(evidence.sha256, "attestationRef.evidence.sha256");
|
|
1850
|
+
const attestation = object5(input.attestation, "attestationRef.attestation");
|
|
1851
|
+
exact3(attestation, ["id", "url", "bundle"], "attestationRef.attestation");
|
|
1852
|
+
token3(attestation.id, "attestationRef.attestation.id");
|
|
1853
|
+
const url = new URL(token3(attestation.url, "attestationRef.attestation.url", 2048));
|
|
1854
|
+
const expectedPrefix = `/${repository}/attestations/`;
|
|
1855
|
+
if (url.protocol !== "https:" || url.hostname !== "github.com" || url.port || url.username || url.password || url.search || url.hash || !url.pathname.startsWith(expectedPrefix) || url.pathname.length <= expectedPrefix.length) throw new TypeError("Attestation URL must be an exact GitHub repository attestation URL.");
|
|
1856
|
+
const bundle = object5(attestation.bundle, "attestationRef.attestation.bundle");
|
|
1857
|
+
exact3(bundle, ["name", "sha256"], "attestationRef.attestation.bundle");
|
|
1858
|
+
const bundleName = token3(bundle.name, "attestationRef.attestation.bundle.name");
|
|
1859
|
+
if (!/^[A-Za-z0-9._-]+\.json$/u.test(bundleName)) throw new TypeError("Attestation bundle name must be a JSON basename.");
|
|
1860
|
+
sha2(bundle.sha256, "attestationRef.attestation.bundle.sha256");
|
|
1861
|
+
return input;
|
|
1862
|
+
}
|
|
1863
|
+
async function verifyShaderValidationEvidenceAttestation(input) {
|
|
1864
|
+
try {
|
|
1865
|
+
const ref = parseShaderValidationEvidenceAttestationRef(input.ref);
|
|
1866
|
+
if (await computeSha256(input.evidenceBytes) !== ref.evidence.sha256 || await computeSha256(input.bundleBytes) !== ref.attestation.bundle.sha256) throw new TypeError("Attested evidence or bundle digest differs.");
|
|
1867
|
+
if (!await input.verifyCryptographicBundle({ ref, evidenceBytes: input.evidenceBytes, bundleBytes: input.bundleBytes })) throw new TypeError("External build-provenance cryptographic verification failed.");
|
|
1868
|
+
return { ok: true, value: ref };
|
|
1869
|
+
} catch (cause) {
|
|
1870
|
+
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Evidence attestation verification failed." }] };
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
export {
|
|
1874
|
+
aggregateShaderValidationEvidence,
|
|
1875
|
+
computeQualificationInventorySha256,
|
|
1876
|
+
computeQualificationSubjectBinding,
|
|
1877
|
+
createQualificationPreflight,
|
|
1878
|
+
defineShaderCompileUnit,
|
|
1879
|
+
parseShaderValidationEvidenceAttestationRef,
|
|
1880
|
+
parseTrustedWorkflowProvenance,
|
|
1881
|
+
validateCompileUnitInventory,
|
|
1882
|
+
validateQualificationBundleManifest,
|
|
1883
|
+
validateQualificationFixture,
|
|
1884
|
+
validateShaderValidationEvidence,
|
|
1885
|
+
validateStableWebGpuMatrix,
|
|
1886
|
+
verifyShaderValidationEvidenceAttestation
|
|
1887
|
+
};
|
|
1888
|
+
//# sourceMappingURL=testing.js.map
|