Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>WebGPU Full System Check</title>
- <style>
- body { background:#111; color:#eee; font-family:monospace; margin:16px; }
- h1 { font-size:18px; margin:0 0 4px 0; }
- p { color:#aaa; font-size:13px; max-width:900px; }
- button { font-family:monospace; font-size:14px; padding:6px 12px; margin:4px 8px 12px 0; cursor:pointer; }
- #summary { font-size:15px; font-weight:bold; margin:10px 0; }
- #report { white-space:pre-wrap; word-break:break-word; background:#000; padding:12px; border:1px solid #333; }
- #c { width:640px; height:640px; max-width:100%; border:1px solid #333; display:block; margin-top:12px; background:#0d0f14; }
- .pass { color:#7f7; }
- .fail { color:#f77; }
- </style>
- </head>
- <body>
- <h1>WebGPU Full System Check</h1>
- <p>Open this file in Chrome (headed). It runs every check on its own and prints one copyable report: environment, each adapter type, adapter info / features / limits, device, WGSL compile (good and broken shader), a compute shader with exact expected values, a live canvas demo (a rotating silver teapot above a reflective checkered floor), and an offscreen render with pixel readback verified against the spiral math. In headless Chrome the adapter steps are expected to come back null — that is the headless result, not a page error.</p>
- <button id="copyBtn">Copy report</button>
- <button id="dlBtn">Download report (.txt)</button>
- <button id="rerunBtn">Run again</button>
- <div id="summary">Running…</div>
- <pre id="report"></pre>
- <canvas id="c" width="1280" height="1280"></canvas>
- <script>
- const reportEl = document.getElementById("report");
- const summaryEl = document.getElementById("summary");
- const lines = [];
- let passCount = 0;
- let failCount = 0;
- function add(m) { lines.push(m); reportEl.textContent = lines.join("\n"); }
- function section(t) { add(""); add("== " + t + " =="); }
- function check(name, ok, detail) {
- if (ok) { passCount++; add("PASS " + name + (detail ? " " + detail : "")); }
- else { failCount++; add("FAIL " + name + (detail ? " " + detail : "")); }
- }
- function info(m) { add(" " + m); }
- function ms(t0) { return (performance.now() - t0).toFixed(1) + " ms"; }
- function mat4Multiply(a, b) {
- const o = new Float32Array(16);
- for (let c = 0; c < 4; c++) for (let r = 0; r < 4; r++) {
- let s = 0;
- for (let k = 0; k < 4; k++) s += a[k * 4 + r] * b[c * 4 + k];
- o[c * 4 + r] = s;
- }
- return o;
- }
- function mat4Perspective(fovy, aspect, near, far) {
- const f = 1 / Math.tan(fovy / 2);
- const o = new Float32Array(16);
- o[0] = f / aspect; o[5] = f; o[10] = far / (near - far); o[11] = -1; o[14] = near * far / (near - far);
- return o;
- }
- function mat4LookAt(eye, target, up) {
- let zx = eye[0] - target[0], zy = eye[1] - target[1], zz = eye[2] - target[2];
- let l = Math.hypot(zx, zy, zz); zx /= l; zy /= l; zz /= l;
- let xx = up[1] * zz - up[2] * zy, xy = up[2] * zx - up[0] * zz, xz = up[0] * zy - up[1] * zx;
- l = Math.hypot(xx, xy, xz); xx /= l; xy /= l; xz /= l;
- const yx = zy * xz - zz * xy, yy = zz * xx - zx * xz, yz = zx * xy - zy * xx;
- const o = new Float32Array(16);
- o[0] = xx; o[1] = yx; o[2] = zx;
- o[4] = xy; o[5] = yy; o[6] = zy;
- o[8] = xz; o[9] = yz; o[10] = zz;
- o[12] = -(xx * eye[0] + xy * eye[1] + xz * eye[2]);
- o[13] = -(yx * eye[0] + yy * eye[1] + yz * eye[2]);
- o[14] = -(zx * eye[0] + zy * eye[1] + zz * eye[2]);
- o[15] = 1;
- return o;
- }
- function mat4Translate(x, y, z) {
- const o = new Float32Array(16);
- o[0] = 1; o[5] = 1; o[10] = 1; o[15] = 1; o[12] = x; o[13] = y; o[14] = z;
- return o;
- }
- function mat4RotY(a) {
- const c = Math.cos(a), s = Math.sin(a);
- const o = new Float32Array(16);
- o[0] = c; o[2] = -s; o[5] = 1; o[8] = s; o[10] = c; o[15] = 1;
- return o;
- }
- function mat4Scale(x, y, z) {
- const o = new Float32Array(16);
- o[0] = x; o[5] = y; o[10] = z; o[15] = 1;
- return o;
- }
- function mat4Point(m, p) {
- const x = p[0], y = p[1], z = p[2];
- const w = m[3] * x + m[7] * y + m[11] * z + m[15];
- return [
- (m[0] * x + m[4] * y + m[8] * z + m[12]) / w,
- (m[1] * x + m[5] * y + m[9] * z + m[13]) / w,
- (m[2] * x + m[6] * y + m[10] * z + m[14]) / w
- ];
- }
- const TEAPOT_CP = [
- 1.4, 0, 2.4, 1.4, -0.784, 2.4, 0.784, -1.4, 2.4, 0, -1.4, 2.4, 1.3375, 0, 2.53125, 1.3375, -0.749, 2.53125,
- 0.749, -1.3375, 2.53125, 0, -1.3375, 2.53125, 1.4375, 0, 2.53125, 1.4375, -0.805, 2.53125, 0.805, -1.4375, 2.53125, 0, -1.4375, 2.53125,
- 1.5, 0, 2.4, 1.5, -0.84, 2.4, 0.84, -1.5, 2.4, 0, -1.5, 2.4, -0.784, -1.4, 2.4, -1.4, -0.784, 2.4,
- -1.4, 0, 2.4, -0.749, -1.3375, 2.53125, -1.3375, -0.749, 2.53125, -1.3375, 0, 2.53125, -0.805, -1.4375, 2.53125, -1.4375, -0.805, 2.53125,
- -1.4375, 0, 2.53125, -0.84, -1.5, 2.4, -1.5, -0.84, 2.4, -1.5, 0, 2.4, -1.4, 0.784, 2.4, -0.784, 1.4, 2.4,
- 0, 1.4, 2.4, -1.3375, 0.749, 2.53125, -0.749, 1.3375, 2.53125, 0, 1.3375, 2.53125, -1.4375, 0.805, 2.53125, -0.805, 1.4375, 2.53125,
- 0, 1.4375, 2.53125, -1.5, 0.84, 2.4, -0.84, 1.5, 2.4, 0, 1.5, 2.4, 0.784, 1.4, 2.4, 1.4, 0.784, 2.4,
- 0.749, 1.3375, 2.53125, 1.3375, 0.749, 2.53125, 0.805, 1.4375, 2.53125, 1.4375, 0.805, 2.53125, 0.84, 1.5, 2.4, 1.5, 0.84, 2.4,
- 1.75, 0, 1.875, 1.75, -0.98, 1.875, 0.98, -1.75, 1.875, 0, -1.75, 1.875, 2, 0, 1.35, 2, -1.12, 1.35,
- 1.12, -2, 1.35, 0, -2, 1.35, 2, 0, 0.9, 2, -1.12, 0.9, 1.12, -2, 0.9, 0, -2, 0.9,
- -0.98, -1.75, 1.875, -1.75, -0.98, 1.875, -1.75, 0, 1.875, -1.12, -2, 1.35, -2, -1.12, 1.35, -2, 0, 1.35,
- -1.12, -2, 0.9, -2, -1.12, 0.9, -2, 0, 0.9, -1.75, 0.98, 1.875, -0.98, 1.75, 1.875, 0, 1.75, 1.875,
- -2, 1.12, 1.35, -1.12, 2, 1.35, 0, 2, 1.35, -2, 1.12, 0.9, -1.12, 2, 0.9, 0, 2, 0.9,
- 0.98, 1.75, 1.875, 1.75, 0.98, 1.875, 1.12, 2, 1.35, 2, 1.12, 1.35, 1.12, 2, 0.9, 2, 1.12, 0.9,
- 2, 0, 0.45, 2, -1.12, 0.45, 1.12, -2, 0.45, 0, -2, 0.45, 1.5, 0, 0.225, 1.5, -0.84, 0.225,
- 0.84, -1.5, 0.225, 0, -1.5, 0.225, 1.5, 0, 0.15, 1.5, -0.84, 0.15, 0.84, -1.5, 0.15, 0, -1.5, 0.15,
- -1.12, -2, 0.45, -2, -1.12, 0.45, -2, 0, 0.45, -0.84, -1.5, 0.225, -1.5, -0.84, 0.225, -1.5, 0, 0.225,
- -0.84, -1.5, 0.15, -1.5, -0.84, 0.15, -1.5, 0, 0.15, -2, 1.12, 0.45, -1.12, 2, 0.45, 0, 2, 0.45,
- -1.5, 0.84, 0.225, -0.84, 1.5, 0.225, 0, 1.5, 0.225, -1.5, 0.84, 0.15, -0.84, 1.5, 0.15, 0, 1.5, 0.15,
- 1.12, 2, 0.45, 2, 1.12, 0.45, 0.84, 1.5, 0.225, 1.5, 0.84, 0.225, 0.84, 1.5, 0.15, 1.5, 0.84, 0.15,
- -1.6, 0, 2.025, -1.6, -0.3, 2.025, -1.5, -0.3, 2.25, -1.5, 0, 2.25, -2.3, 0, 2.025, -2.3, -0.3, 2.025,
- -2.5, -0.3, 2.25, -2.5, 0, 2.25, -2.7, 0, 2.025, -2.7, -0.3, 2.025, -3, -0.3, 2.25, -3, 0, 2.25,
- -2.7, 0, 1.8, -2.7, -0.3, 1.8, -3, -0.3, 1.8, -3, 0, 1.8, -1.5, 0.3, 2.25, -1.6, 0.3, 2.025,
- -2.5, 0.3, 2.25, -2.3, 0.3, 2.025, -3, 0.3, 2.25, -2.7, 0.3, 2.025, -3, 0.3, 1.8, -2.7, 0.3, 1.8,
- -2.7, 0, 1.575, -2.7, -0.3, 1.575, -3, -0.3, 1.35, -3, 0, 1.35, -2.5, 0, 1.125, -2.5, -0.3, 1.125,
- -2.65, -0.3, 0.9375, -2.65, 0, 0.9375, -2, -0.3, 0.9, -1.9, -0.3, 0.6, -1.9, 0, 0.6, -3, 0.3, 1.35,
- -2.7, 0.3, 1.575, -2.65, 0.3, 0.9375, -2.5, 0.3, 1.125, -1.9, 0.3, 0.6, -2, 0.3, 0.9, 1.7, 0, 1.425,
- 1.7, -0.66, 1.425, 1.7, -0.66, 0.6, 1.7, 0, 0.6, 2.6, 0, 1.425, 2.6, -0.66, 1.425, 3.1, -0.66, 0.825,
- 3.1, 0, 0.825, 2.3, 0, 2.1, 2.3, -0.25, 2.1, 2.4, -0.25, 2.025, 2.4, 0, 2.025, 2.7, 0, 2.4,
- 2.7, -0.25, 2.4, 3.3, -0.25, 2.4, 3.3, 0, 2.4, 1.7, 0.66, 0.6, 1.7, 0.66, 1.425, 3.1, 0.66, 0.825,
- 2.6, 0.66, 1.425, 2.4, 0.25, 2.025, 2.3, 0.25, 2.1, 3.3, 0.25, 2.4, 2.7, 0.25, 2.4, 2.8, 0, 2.475,
- 2.8, -0.25, 2.475, 3.525, -0.25, 2.49375, 3.525, 0, 2.49375, 2.9, 0, 2.475, 2.9, -0.15, 2.475, 3.45, -0.15, 2.5125,
- 3.45, 0, 2.5125, 2.8, 0, 2.4, 2.8, -0.15, 2.4, 3.2, -0.15, 2.4, 3.2, 0, 2.4, 3.525, 0.25, 2.49375,
- 2.8, 0.25, 2.475, 3.45, 0.15, 2.5125, 2.9, 0.15, 2.475, 3.2, 0.15, 2.4, 2.8, 0.15, 2.4, 0, 0, 3.15,
- 0, -0.002, 3.15, 0.002, 0, 3.15, 0.8, 0, 3.15, 0.8, -0.45, 3.15, 0.45, -0.8, 3.15, 0, -0.8, 3.15,
- 0, 0, 2.85, 0.2, 0, 2.7, 0.2, -0.112, 2.7, 0.112, -0.2, 2.7, 0, -0.2, 2.7, -0.002, 0, 3.15,
- -0.45, -0.8, 3.15, -0.8, -0.45, 3.15, -0.8, 0, 3.15, -0.112, -0.2, 2.7, -0.2, -0.112, 2.7, -0.2, 0, 2.7,
- 0, 0.002, 3.15, -0.8, 0.45, 3.15, -0.45, 0.8, 3.15, 0, 0.8, 3.15, -0.2, 0.112, 2.7, -0.112, 0.2, 2.7,
- 0, 0.2, 2.7, 0.45, 0.8, 3.15, 0.8, 0.45, 3.15, 0.112, 0.2, 2.7, 0.2, 0.112, 2.7, 0.4, 0, 2.55,
- 0.4, -0.224, 2.55, 0.224, -0.4, 2.55, 0, -0.4, 2.55, 1.3, 0, 2.55, 1.3, -0.728, 2.55, 0.728, -1.3, 2.55,
- 0, -1.3, 2.55, 1.3, 0, 2.4, 1.3, -0.728, 2.4, 0.728, -1.3, 2.4, 0, -1.3, 2.4, -0.224, -0.4, 2.55,
- -0.4, -0.224, 2.55, -0.4, 0, 2.55, -0.728, -1.3, 2.55, -1.3, -0.728, 2.55, -1.3, 0, 2.55, -0.728, -1.3, 2.4,
- -1.3, -0.728, 2.4, -1.3, 0, 2.4, -0.4, 0.224, 2.55, -0.224, 0.4, 2.55, 0, 0.4, 2.55, -1.3, 0.728, 2.55,
- -0.728, 1.3, 2.55, 0, 1.3, 2.55, -1.3, 0.728, 2.4, -0.728, 1.3, 2.4, 0, 1.3, 2.4, 0.224, 0.4, 2.55,
- 0.4, 0.224, 2.55, 0.728, 1.3, 2.55, 1.3, 0.728, 2.55, 0.728, 1.3, 2.4, 1.3, 0.728, 2.4, 0, 0, 0,
- 1.5, 0, 0.15, 1.5, 0.84, 0.15, 0.84, 1.5, 0.15, 0, 1.5, 0.15, 1.5, 0, 0.075, 1.5, 0.84, 0.075,
- 0.84, 1.5, 0.075, 0, 1.5, 0.075, 1.425, 0, 0, 1.425, 0.798, 0, 0.798, 1.425, 0, 0, 1.425, 0,
- -0.84, 1.5, 0.15, -1.5, 0.84, 0.15, -1.5, 0, 0.15, -0.84, 1.5, 0.075, -1.5, 0.84, 0.075, -1.5, 0, 0.075,
- -0.798, 1.425, 0, -1.425, 0.798, 0, -1.425, 0, 0, -1.5, -0.84, 0.15, -0.84, -1.5, 0.15, 0, -1.5, 0.15,
- -1.5, -0.84, 0.075, -0.84, -1.5, 0.075, 0, -1.5, 0.075, -1.425, -0.798, 0, -0.798, -1.425, 0, 0, -1.425, 0,
- 0.84, -1.5, 0.15, 1.5, -0.84, 0.15, 0.84, -1.5, 0.075, 1.5, -0.84, 0.075, 0.798, -1.425, 0, 1.425, -0.798, 0
- ];
- const TEAPOT_PATCHES = [
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 3, 16, 17, 18, 7, 19, 20, 21, 11, 22, 23, 24, 15, 25, 26, 27,
- 18, 28, 29, 30, 21, 31, 32, 33, 24, 34, 35, 36, 27, 37, 38, 39,
- 30, 40, 41, 0, 33, 42, 43, 4, 36, 44, 45, 8, 39, 46, 47, 12,
- 12, 13, 14, 15, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
- 15, 25, 26, 27, 51, 60, 61, 62, 55, 63, 64, 65, 59, 66, 67, 68,
- 27, 37, 38, 39, 62, 69, 70, 71, 65, 72, 73, 74, 68, 75, 76, 77,
- 39, 46, 47, 12, 71, 78, 79, 48, 74, 80, 81, 52, 77, 82, 83, 56,
- 56, 57, 58, 59, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 59, 66, 67, 68, 87, 96, 97, 98, 91, 99, 100, 101, 95, 102, 103, 104,
- 68, 75, 76, 77, 98, 105, 106, 107, 101, 108, 109, 110, 104, 111, 112, 113,
- 77, 82, 83, 56, 107, 114, 115, 84, 110, 116, 117, 88, 113, 118, 119, 92,
- 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135,
- 123, 136, 137, 120, 127, 138, 139, 124, 131, 140, 141, 128, 135, 142, 143, 132,
- 132, 133, 134, 135, 144, 145, 146, 147, 148, 149, 150, 151, 68, 152, 153, 154,
- 135, 142, 143, 132, 147, 155, 156, 144, 151, 157, 158, 148, 154, 159, 160, 68,
- 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176,
- 164, 177, 178, 161, 168, 179, 180, 165, 172, 181, 182, 169, 176, 183, 184, 173,
- 173, 174, 175, 176, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
- 176, 183, 184, 173, 188, 197, 198, 185, 192, 199, 200, 189, 196, 201, 202, 193,
- 203, 203, 203, 203, 206, 207, 208, 209, 210, 210, 210, 210, 211, 212, 213, 214,
- 203, 203, 203, 203, 209, 216, 217, 218, 210, 210, 210, 210, 214, 219, 220, 221,
- 203, 203, 203, 203, 218, 223, 224, 225, 210, 210, 210, 210, 221, 226, 227, 228,
- 203, 203, 203, 203, 225, 229, 230, 206, 210, 210, 210, 210, 228, 231, 232, 211,
- 211, 212, 213, 214, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
- 214, 219, 220, 221, 236, 245, 246, 247, 240, 248, 249, 250, 244, 251, 252, 253,
- 221, 226, 227, 228, 247, 254, 255, 256, 250, 257, 258, 259, 253, 260, 261, 262,
- 228, 231, 232, 211, 256, 263, 264, 233, 259, 265, 266, 237, 262, 267, 268, 241,
- 269, 269, 269, 269, 278, 279, 280, 281, 274, 275, 276, 277, 270, 271, 272, 273,
- 269, 269, 269, 269, 281, 288, 289, 290, 277, 285, 286, 287, 273, 282, 283, 284,
- 269, 269, 269, 269, 290, 297, 298, 299, 287, 294, 295, 296, 284, 291, 292, 293,
- 269, 269, 269, 269, 299, 304, 305, 278, 296, 302, 303, 274, 293, 300, 301, 270,
- ];
- function buildTeapot() {
- const divs = 16;
- const pos = [];
- const idx = [];
- const weld = new Map();
- function bern(t) { const u = 1 - t; return [u * u * u, 3 * u * u * t, 3 * u * t * t, t * t * t]; }
- function vert(p) {
- const key = Math.round(p[0] * 10000) + "," + Math.round(p[1] * 10000) + "," + Math.round(p[2] * 10000);
- let id = weld.get(key);
- if (id === undefined) { id = pos.length / 3; weld.set(key, id); pos.push(p[0], p[1], p[2]); }
- return id;
- }
- for (let pn = 0; pn < 32; pn++) {
- const cp = [];
- for (let i = 0; i < 16; i++) { const o = TEAPOT_PATCHES[pn * 16 + i] * 3; cp.push([TEAPOT_CP[o], TEAPOT_CP[o + 1], TEAPOT_CP[o + 2]]); }
- const grid = [];
- for (let j = 0; j <= divs; j++) {
- const bv = bern(j / divs);
- const row = [];
- for (let i = 0; i <= divs; i++) {
- const bu = bern(i / divs);
- let x = 0, y = 0, z = 0;
- for (let r = 0; r < 4; r++) for (let c = 0; c < 4; c++) {
- const w = bu[c] * bv[r];
- const p = cp[r * 4 + c];
- x += w * p[0]; y += w * p[1]; z += w * p[2];
- }
- row.push(vert([x, y, z]));
- }
- grid.push(row);
- }
- for (let j = 0; j < divs; j++) for (let i = 0; i < divs; i++) {
- const a = grid[j][i], b = grid[j + 1][i], c = grid[j + 1][i + 1], d = grid[j][i + 1];
- idx.push(a, c, b, a, d, c);
- }
- }
- let mnx = 1e9, mxx = -1e9, mny = 1e9, mxy = -1e9, mnz = 1e9;
- for (let i = 0; i < pos.length; i += 3) {
- if (pos[i] < mnx) mnx = pos[i];
- if (pos[i] > mxx) mxx = pos[i];
- if (pos[i + 1] < mny) mny = pos[i + 1];
- if (pos[i + 1] > mxy) mxy = pos[i + 1];
- if (pos[i + 2] < mnz) mnz = pos[i + 2];
- }
- const s = 3.7 / (mxx - mnx);
- const cx = (mnx + mxx) / 2, cy = (mny + mxy) / 2;
- for (let i = 0; i < pos.length; i += 3) {
- const x = pos[i], y = pos[i + 1], z = pos[i + 2];
- pos[i] = (x - cx) * s;
- pos[i + 1] = (z - mnz) * s + 0.5;
- pos[i + 2] = -(y - cy) * s;
- }
- const normals = new Float32Array(pos.length);
- for (let i = 0; i < idx.length; i += 3) {
- const a = idx[i] * 3, b = idx[i + 1] * 3, c = idx[i + 2] * 3;
- const ux = pos[b] - pos[a], uy = pos[b + 1] - pos[a + 1], uz = pos[b + 2] - pos[a + 2];
- const vx = pos[c] - pos[a], vy = pos[c + 1] - pos[a + 1], vz = pos[c + 2] - pos[a + 2];
- const nx = uy * vz - uz * vy, ny = uz * vx - ux * vz, nz = ux * vy - uy * vx;
- normals[a] += nx; normals[a + 1] += ny; normals[a + 2] += nz;
- normals[b] += nx; normals[b + 1] += ny; normals[b + 2] += nz;
- normals[c] += nx; normals[c + 1] += ny; normals[c + 2] += nz;
- }
- for (let i = 0; i < normals.length; i += 3) {
- const l = Math.hypot(normals[i], normals[i + 1], normals[i + 2]);
- if (l < 1e-9) { normals[i] = 0; normals[i + 1] = 1; normals[i + 2] = 0; }
- else { normals[i] /= l; normals[i + 1] /= l; normals[i + 2] /= l; }
- }
- return { positions: new Float32Array(pos), normals, indices: new Uint32Array(idx) };
- }
- const _hf32 = new Float32Array(1);
- const _hu32 = new Uint32Array(_hf32.buffer);
- function floatToHalf(v) {
- _hf32[0] = v;
- const x = _hu32[0];
- let bits = (x >> 16) & 0x8000;
- let m = (x >> 12) & 0x07ff;
- const e = (x >> 23) & 0xff;
- if (e < 103) return bits;
- if (e > 142) { bits |= 0x7c00; return bits; }
- if (e < 113) {
- m |= 0x0800;
- bits |= (m >> (114 - e)) + ((m >> (113 - e)) & 1);
- return bits;
- }
- bits |= ((e - 112) << 10) | (m >> 1);
- bits += m & 1;
- return bits;
- }
- function envColor(dx, dy, dz) {
- const dl = Math.hypot(dx, dy, dz) || 1;
- dx /= dl; dy /= dl; dz /= dl;
- let r, g, b;
- if (dy >= 0) {
- const t = Math.pow(dy, 0.6);
- r = 0.34 + (0.05 - 0.34) * t;
- g = 0.37 + (0.07 - 0.37) * t;
- b = 0.41 + (0.11 - 0.41) * t;
- } else {
- const t = Math.min(-dy * 2.2, 1);
- r = 0.34 + (0.03 - 0.34) * t;
- g = 0.37 + (0.028 - 0.37) * t;
- b = 0.41 + (0.025 - 0.41) * t;
- }
- const horizon = Math.exp(-Math.abs(dy - 0.02) * 9);
- r += 0.1 * horizon; g += 0.105 * horizon; b += 0.11 * horizon;
- const lobes = [
- [0.5, 0.72, 0.62, 6, 2.6, 1.0, 0.98, 0.94],
- [0.15, 0.5, 0.85, 45, 7.0, 0.95, 0.98, 1.0],
- [0.62, 0.8, 0.45, 300, 16.0, 1.0, 1.0, 1.0],
- [-0.7, 0.35, -0.55, 14, 1.6, 1.0, 0.82, 0.6],
- [-0.25, 0.6, -0.75, 90, 5.0, 0.75, 0.85, 1.0],
- [0.85, 0.12, -0.4, 24, 1.1, 0.9, 0.93, 1.0],
- [-0.9, -0.05, 0.3, 30, 0.5, 1.0, 0.95, 0.88]
- ];
- for (const L of lobes) {
- const ll = Math.hypot(L[0], L[1], L[2]);
- const d = Math.max((dx * L[0] + dy * L[1] + dz * L[2]) / ll, 0);
- const s = Math.pow(d, L[3]) * L[4];
- r += s * L[5]; g += s * L[6]; b += s * L[7];
- }
- return [r, g, b];
- }
- function buildEnvData() {
- let w = 256, h = 128;
- let cur = new Float32Array(w * h * 3);
- for (let y = 0; y < h; y++) {
- const v = (y + 0.5) / h;
- const phi = v * Math.PI;
- const sp = Math.sin(phi), dy = Math.cos(phi);
- for (let x = 0; x < w; x++) {
- const u = (x + 0.5) / w;
- const theta = (u - 0.5) * Math.PI * 2;
- const c = envColor(sp * Math.cos(theta), dy, sp * Math.sin(theta));
- const o = (y * w + x) * 3;
- cur[o] = c[0]; cur[o + 1] = c[1]; cur[o + 2] = c[2];
- }
- }
- const levels = [];
- while (true) {
- const data = new Uint16Array(w * h * 4);
- for (let i = 0; i < w * h; i++) {
- data[i * 4] = floatToHalf(cur[i * 3]);
- data[i * 4 + 1] = floatToHalf(cur[i * 3 + 1]);
- data[i * 4 + 2] = floatToHalf(cur[i * 3 + 2]);
- data[i * 4 + 3] = floatToHalf(1);
- }
- levels.push({ w, h, data });
- if (w <= 16) break;
- const nw = w / 2, nh = h / 2;
- const nxt = new Float32Array(nw * nh * 3);
- for (let y = 0; y < nh; y++) {
- for (let x = 0; x < nw; x++) {
- let sr = 0, sg = 0, sb = 0;
- for (let oy = 0; oy < 2; oy++) {
- for (let ox = 0; ox < 2; ox++) {
- const sx = (x * 2 + ox) % w, sy = Math.min(y * 2 + oy, h - 1);
- const o = (sy * w + sx) * 3;
- sr += cur[o]; sg += cur[o + 1]; sb += cur[o + 2];
- }
- }
- const o = (y * nw + x) * 3;
- nxt[o] = sr / 4; nxt[o + 1] = sg / 4; nxt[o + 2] = sb / 4;
- }
- }
- cur = nxt; w = nw; h = nh;
- }
- return levels;
- }
- const PALETTE = [
- [255,0,0],[255,64,0],[255,128,0],[255,192,0],[255,255,0],[192,255,0],
- [128,255,0],[0,255,0],[0,255,128],[0,255,192],[0,255,255],[0,192,255],
- [0,128,255],[0,64,255],[64,0,255],[128,0,255],[192,0,255],[255,0,255],[255,0,128]
- ];
- const SPIRAL = `
- const palette = array<vec3f, 19>(
- vec3f(255.0, 0.0, 0.0), vec3f(255.0, 64.0, 0.0), vec3f(255.0, 128.0, 0.0),
- vec3f(255.0, 192.0, 0.0), vec3f(255.0, 255.0, 0.0), vec3f(192.0, 255.0, 0.0),
- vec3f(128.0, 255.0, 0.0), vec3f(0.0, 255.0, 0.0), vec3f(0.0, 255.0, 128.0),
- vec3f(0.0, 255.0, 192.0), vec3f(0.0, 255.0, 255.0), vec3f(0.0, 192.0, 255.0),
- vec3f(0.0, 128.0, 255.0), vec3f(0.0, 64.0, 255.0), vec3f(64.0, 0.0, 255.0),
- vec3f(128.0, 0.0, 255.0), vec3f(192.0, 0.0, 255.0), vec3f(255.0, 0.0, 255.0),
- vec3f(255.0, 0.0, 128.0)
- );
- @vertex fn vs_main(@builtin(vertex_index) idx : u32) -> @builtin(position) vec4f {
- var pos = array<vec2f, 3>(vec2f(-1.0, -1.0), vec2f(3.0, -1.0), vec2f(-1.0, 3.0));
- return vec4f(pos[idx], 0.0, 1.0);
- }
- @fragment fn fs_main(@builtin(position) coord: vec4f) -> @location(0) vec4f {
- let cx = 640.0;
- let cy = 640.0;
- let dx = coord.x - cx;
- let dy = coord.y - cy;
- let r = sqrt(dx*dx + dy*dy);
- if (r > 1000.0 || r < 1.0) { return vec4f(0.0, 0.0, 0.0, 0.0); }
- let angle_deg = 2000.0 - (2.0 * r);
- let angle_rad = angle_deg * 3.1415926535 / 180.0;
- var local_angle = atan2(dy, dx);
- if (local_angle < 0.0) { local_angle += 2.0 * 3.1415926535; }
- var source_angle = (local_angle - angle_rad) % (2.0 * 3.1415926535);
- if (source_angle < 0.0) { source_angle += 2.0 * 3.1415926535; }
- let idx = i32(floor(source_angle / ((2.0 * 3.1415926535) / 19.0))) % 19;
- return vec4f(palette[idx] / 255.0, 1.0);
- }
- `;
- const COMPUTE = `
- @group(0) @binding(0) var<storage, read> a : array<f32, 8>;
- @group(0) @binding(1) var<storage, read> b : array<f32, 8>;
- @group(0) @binding(2) var<storage, read_write> outBuf : array<f32, 8>;
- @compute @workgroup_size(8) fn main(@builtin(global_invocation_id) id : vec3<u32>) {
- outBuf[id.x] = a[id.x] * a[id.x] + b[id.x];
- }
- `;
- const TEAPOT = `
- struct U { mvp: mat4x4f, model: mat4x4f, camPos: vec4f, lightDir: vec4f };
- @group(0) @binding(0) var<uniform> u: U;
- @group(0) @binding(1) var envTex: texture_2d<f32>;
- @group(0) @binding(2) var envSamp: sampler;
- struct VOut { @builtin(position) pos: vec4f, @location(0) world: vec3f, @location(1) normal: vec3f };
- @vertex fn vs_main(@location(0) p: vec3f, @location(1) n: vec3f) -> VOut {
- var o: VOut;
- let w = u.model * vec4f(p, 1.0);
- o.world = w.xyz;
- o.normal = (u.model * vec4f(n, 0.0)).xyz;
- o.pos = u.mvp * vec4f(p, 1.0);
- return o;
- }
- fn envUV(d: vec3f) -> vec2f {
- return vec2f(atan2(d.z, d.x) / 6.2831853 + 0.5, acos(clamp(d.y, -1.0, 1.0)) / 3.14159265);
- }
- fn hash3(p: vec3f) -> f32 {
- let q = fract(p * 0.3183099 + vec3f(0.11, 0.17, 0.23));
- return fract(q.x * q.y * q.z * (q.x + q.y + q.z) * 17.0);
- }
- fn vnoise(p: vec3f) -> f32 {
- let i = floor(p);
- let f = fract(p);
- let s = f * f * (3.0 - 2.0 * f);
- return mix(
- mix(mix(hash3(i), hash3(i + vec3f(1.0, 0.0, 0.0)), s.x),
- mix(hash3(i + vec3f(0.0, 1.0, 0.0)), hash3(i + vec3f(1.0, 1.0, 0.0)), s.x), s.y),
- mix(mix(hash3(i + vec3f(0.0, 0.0, 1.0)), hash3(i + vec3f(1.0, 0.0, 1.0)), s.x),
- mix(hash3(i + vec3f(0.0, 1.0, 1.0)), hash3(i + vec3f(1.0, 1.0, 1.0)), s.x), s.y), s.z);
- }
- fn ggxD(noh: f32, rough: f32) -> f32 {
- let a = rough * rough;
- let a2 = a * a;
- let d = noh * noh * (a2 - 1.0) + 1.0;
- return a2 / (3.14159265 * d * d);
- }
- fn ggxG1(x: f32, rough: f32) -> f32 {
- let k = (rough + 1.0) * (rough + 1.0) / 8.0;
- return x / (x * (1.0 - k) + k);
- }
- fn fresnel(f0: vec3f, voh: f32) -> vec3f {
- return f0 + (vec3f(1.0) - f0) * pow(1.0 - voh, 5.0);
- }
- fn specDirect(n: vec3f, v: vec3f, l: vec3f, rough: f32, f0: vec3f) -> vec3f {
- let nol = max(dot(n, l), 0.0);
- if (nol <= 0.0) { return vec3f(0.0); }
- let h = normalize(l + v);
- let nov = max(dot(n, v), 0.0);
- let noh = max(dot(n, h), 0.0);
- let voh = max(dot(v, h), 0.0);
- let d = ggxD(noh, rough);
- let g = ggxG1(nov, rough) * ggxG1(nol, rough);
- let f = fresnel(f0, voh);
- return d * g * f / max(4.0 * nov * nol, 0.0001) * nol;
- }
- fn envBRDF(f0: vec3f, rough: f32, nov: f32) -> vec3f {
- let c0 = vec4f(-1.0, -0.0275, -0.572, 0.022);
- let c1 = vec4f(1.0, 0.0425, 1.04, -0.04);
- let r = rough * c0 + c1;
- let a004 = min(r.x * r.x, exp2(-9.28 * nov)) * r.x + r.y;
- let ab = vec2f(-1.04, 1.04) * a004 + r.zw;
- return f0 * ab.x + ab.y;
- }
- fn shade(world: vec3f, normal: vec3f) -> vec3f {
- let n = normalize(normal);
- let v = normalize(u.camPos.xyz - world);
- let nov = max(dot(n, v), 0.0);
- let rough = clamp(0.13 + (vnoise(world * 3.0) - 0.5) * 0.09 + (vnoise(world * 18.0) - 0.5) * 0.05, 0.04, 0.3);
- let f0 = vec3f(0.97, 0.96, 0.94);
- let rd = reflect(-v, n);
- let lod = rough * 4.0;
- let env = textureSampleLevel(envTex, envSamp, envUV(rd), lod).rgb;
- var col = env * envBRDF(f0, rough, nov);
- col += specDirect(n, v, normalize(u.lightDir.xyz), rough, f0) * vec3f(3.2, 3.1, 2.95);
- col += specDirect(n, v, normalize(vec3f(-0.6, 0.3, -0.7)), rough, f0) * vec3f(0.8, 0.95, 1.25);
- return col;
- }
- fn tonemap(c: vec3f) -> vec3f {
- let x = max(c * 1.15, vec3f(0.0));
- let aces = clamp(x * (2.51 * x + 0.03) / (x * (2.43 * x + 0.59) + 0.14), vec3f(0.0), vec3f(1.0));
- return pow(aces, vec3f(0.45454545));
- }
- @fragment fn fs_main(@builtin(front_facing) ff: bool, @location(0) world: vec3f, @location(1) normal: vec3f) -> @location(0) vec4f {
- return vec4f(tonemap(shade(world, select(-normal, normal, ff))), 1.0);
- }
- @fragment fn fs_refl(@builtin(front_facing) ff: bool, @location(0) world: vec3f, @location(1) normal: vec3f) -> @location(0) vec4f {
- return vec4f(clamp(shade(world, select(-normal, normal, ff)), vec3f(0.0), vec3f(1.0)), 1.0);
- }
- `;
- const FLOOR = `
- struct U { mvp: mat4x4f, camPos: vec4f, size: vec4f };
- @group(0) @binding(0) var<uniform> u: U;
- @group(0) @binding(1) var reflTex: texture_2d<f32>;
- @group(0) @binding(2) var reflSamp: sampler;
- struct VOut { @builtin(position) pos: vec4f, @location(0) world: vec3f };
- @vertex fn vs_main(@location(0) p: vec3f) -> VOut {
- var o: VOut;
- o.world = p;
- o.pos = u.mvp * vec4f(p, 1.0);
- return o;
- }
- fn tonemap(c: vec3f) -> vec3f {
- let x = max(c * 1.15, vec3f(0.0));
- let aces = clamp(x * (2.51 * x + 0.03) / (x * (2.43 * x + 0.59) + 0.14), vec3f(0.0), vec3f(1.0));
- return pow(aces, vec3f(0.45454545));
- }
- @fragment fn fs_main(@builtin(position) fp: vec4f, @location(0) world: vec3f) -> @location(0) vec4f {
- let ix = i32(floor(world.x));
- let iz = i32(floor(world.z));
- let odd = (abs(ix) % 2 == 1) != (abs(iz) % 2 == 1);
- let th = fract(sin(dot(vec2f(f32(ix), f32(iz)), vec2f(127.1, 311.7))) * 43758.5453);
- var albedo = select(vec3f(0.018, 0.018, 0.02), vec3f(0.62, 0.62, 0.64), odd);
- albedo *= 0.92 + 0.16 * th;
- let fx = fract(world.x);
- let fz = fract(world.z);
- let gd = min(min(fx, 1.0 - fx), min(fz, 1.0 - fz));
- let grout = smoothstep(0.0, 0.035, gd);
- albedo *= mix(0.35, 1.0, grout);
- var col = albedo * 1.05;
- let d2 = dot(world.xz, world.xz);
- col *= 1.0 - 0.38 * exp(-d2 / 1.5);
- let uv = clamp(fp.xy / u.size.xy, vec2f(0.0), vec2f(1.0));
- let refl = textureSample(reflTex, reflSamp, uv);
- let v = normalize(u.camPos.xyz - world);
- var f = clamp(0.9 - v.y * 0.6, 0.25, 0.8);
- f *= exp(-length(world.xz) * 0.1);
- f *= mix(0.45, 1.0, grout) * (0.7 + 0.55 * th);
- col = mix(col, refl.rgb, clamp(f, 0.0, 1.0) * refl.a);
- let l = normalize(vec3f(0.5, 0.85, 0.35));
- let hv = normalize(l + v);
- col += vec3f(pow(max(hv.y, 0.0), 140.0)) * 0.3 * grout;
- let edge = smoothstep(5.4, 6.0, max(abs(world.x), abs(world.z)));
- col = mix(col, vec3f(0.012, 0.014, 0.018), edge);
- return vec4f(tonemap(col), 1.0);
- }
- `;
- const BACKGROUND = `
- struct U { right: vec4f, up: vec4f, fwd: vec4f, params: vec4f };
- @group(0) @binding(0) var<uniform> u: U;
- @group(0) @binding(1) var envTex: texture_2d<f32>;
- @group(0) @binding(2) var envSamp: sampler;
- struct VOut { @builtin(position) pos: vec4f, @location(0) ndc: vec2f };
- @vertex fn vs_main(@builtin(vertex_index) idx: u32) -> VOut {
- var pts = array<vec2f, 3>(vec2f(-1.0, -1.0), vec2f(3.0, -1.0), vec2f(-1.0, 3.0));
- var o: VOut;
- o.ndc = pts[idx];
- o.pos = vec4f(pts[idx], 1.0, 1.0);
- return o;
- }
- fn tonemap(c: vec3f) -> vec3f {
- let x = max(c * 1.15, vec3f(0.0));
- let aces = clamp(x * (2.51 * x + 0.03) / (x * (2.43 * x + 0.59) + 0.14), vec3f(0.0), vec3f(1.0));
- return pow(aces, vec3f(0.45454545));
- }
- @fragment fn fs_main(@location(0) ndc: vec2f) -> @location(0) vec4f {
- let ray = normalize(u.fwd.xyz + ndc.x * u.params.x * u.right.xyz + ndc.y * u.params.x * u.up.xyz);
- let uv = vec2f(atan2(ray.z, ray.x) / 6.2831853 + 0.5, acos(clamp(ray.y, -1.0, 1.0)) / 3.14159265);
- let env = textureSampleLevel(envTex, envSamp, uv, 1.0).rgb;
- return vec4f(tonemap(env), 1.0);
- }
- `;
- let demoGen = 0;
- function expectedPixel(x, y) {
- const dx = x + 0.5 - 640;
- const dy = y + 0.5 - 640;
- const r = Math.sqrt(dx * dx + dy * dy);
- if (r > 1000 || r < 1) return [0, 0, 0, 0];
- const angleRad = (2000 - 2 * r) * Math.PI / 180;
- let local = Math.atan2(dy, dx);
- if (local < 0) local += 2 * Math.PI;
- let src = (local - angleRad) % (2 * Math.PI);
- if (src < 0) src += 2 * Math.PI;
- const idx = Math.floor(src / ((2 * Math.PI) / 19)) % 19;
- return [PALETTE[idx][0], PALETTE[idx][1], PALETTE[idx][2], 255];
- }
- async function describeAdapter(label, adapter) {
- const t0 = performance.now();
- if (!adapter) { check(label + " adapter", false, "null in " + ms(t0)); return null; }
- check(label + " adapter", true, "returned in " + ms(t0));
- const inf = adapter.info || {};
- info("vendor=" + (inf.vendor || "?") + " architecture=" + (inf.architecture || "?") +
- " device=" + (inf.device || "?") + " description=" + (inf.description || "?"));
- info("isFallbackAdapter=" + adapter.isFallbackAdapter);
- const feats = [...adapter.features].sort();
- info("features (" + feats.length + "): " + (feats.join(", ") || "none"));
- const lim = adapter.limits || {};
- const keys = Object.keys(lim).sort();
- info("limits (" + keys.length + "):");
- for (const k of keys) info(" " + k + "=" + lim[k]);
- return adapter;
- }
- async function main() {
- lines.length = 0;
- passCount = 0;
- failCount = 0;
- reportEl.textContent = "";
- summaryEl.textContent = "Running\u2026";
- const started = new Date();
- add("WebGPU Full System Check");
- add("run at " + started.toISOString() + " local " + started.toString());
- section("1 Environment");
- check("secure context", !!window.isSecureContext, "isSecureContext=" + window.isSecureContext + " protocol=" + location.protocol + " host=" + (location.host || "(file)"));
- info("userAgent=" + navigator.userAgent);
- info("platform=" + (navigator.platform || "?") + " hardwareConcurrency=" + navigator.hardwareConcurrency + " deviceMemory=" + (navigator.deviceMemory || "?") + "GB");
- check("navigator.gpu present", !!navigator.gpu, "navigator.gpu=" + !!navigator.gpu);
- if (navigator.gpu && navigator.gpu.wgslLanguageFeatures) {
- info("wgslLanguageFeatures: " + [...navigator.gpu.wgslLanguageFeatures].sort().join(", "));
- }
- if (!navigator.gpu) {
- add("STOP: no navigator.gpu, nothing further can run.");
- finish();
- return;
- }
- section("2 Adapter requests (each tried separately)");
- let t0 = performance.now();
- let defAdapter = null;
- try { defAdapter = await navigator.gpu.requestAdapter(); } catch (e) { info("default threw: " + e.message); }
- await describeAdapter("default", defAdapter);
- let hpAdapter = null;
- try { hpAdapter = await navigator.gpu.requestAdapter({ powerPreference: "high-performance" }); } catch (e) { info("high-performance threw: " + e.message); }
- await describeAdapter("high-performance", hpAdapter);
- let lpAdapter = null;
- try { lpAdapter = await navigator.gpu.requestAdapter({ powerPreference: "low-power" }); } catch (e) { info("low-power threw: " + e.message); }
- await describeAdapter("low-power", lpAdapter);
- let fbAdapter = null;
- try { fbAdapter = await navigator.gpu.requestAdapter({ forceFallbackAdapter: true }); } catch (e) { info("fallback threw: " + e.message); }
- await describeAdapter("fallback (forceFallbackAdapter)", fbAdapter);
- info("adapter requests total: " + ms(t0));
- const adapter = defAdapter || hpAdapter || lpAdapter || fbAdapter;
- if (!adapter) {
- add("STOP: every adapter request returned null. WebGPU cannot run in this browser/launch mode.");
- add("If this was headless Chrome, that matches the known headless result: headed Chrome on the same machine returned an adapter.");
- finish();
- return;
- }
- const which = defAdapter ? "default" : hpAdapter ? "high-performance" : lpAdapter ? "low-power" : "fallback";
- info("using adapter: " + which);
- section("3 Device");
- let device = null;
- t0 = performance.now();
- try {
- device = await adapter.requestDevice();
- check("requestDevice", !!device, "in " + ms(t0));
- } catch (e) {
- check("requestDevice", false, e.message);
- finish();
- return;
- }
- info("device.features (" + device.features.size + "): " + [...device.features].sort().join(", "));
- const dlim = device.limits || {};
- const dkeys = Object.keys(dlim).sort();
- info("device.limits (" + dkeys.length + "):");
- for (const k of dkeys) info(" " + k + "=" + dlim[k]);
- if (device.label !== undefined) info("device.label=" + JSON.stringify(device.label));
- device.addEventListener("uncapturederror", (e) => { add("UNCAPTURED DEVICE ERROR: " + e.error.message); });
- section("4 WGSL compile");
- const module = device.createShaderModule({ code: SPIRAL });
- t0 = performance.now();
- const ci = await module.getCompilationInfo();
- const errors = ci.messages.filter((m) => m.type === "error");
- const warnings = ci.messages.filter((m) => m.type === "warning");
- check("spiral WGSL compiles", errors.length === 0, errors.length + " errors, " + warnings.length + " warnings, in " + ms(t0));
- for (const m of ci.messages) info("[" + m.type + "] L" + m.lineNum + ":" + m.linePos + " " + m.message);
- if (ci.messages.length === 0) info("compilation clean");
- const badModule = device.createShaderModule({ code: "@fragment fn broken( {" });
- const badInfo = await badModule.getCompilationInfo();
- const badErrors = badInfo.messages.filter((m) => m.type === "error");
- check("broken WGSL is caught", badErrors.length > 0, badErrors.length + " error(s) reported; first: " + (badErrors[0] ? badErrors[0].message : "none"));
- section("5 Compute shader (exact values)");
- const aVals = new Float32Array([1, 2, 3, 4, 5, 6, 7, 8]);
- const bVals = new Float32Array([10, 20, 30, 40, 50, 60, 70, 80]);
- const expected = [11, 24, 39, 56, 75, 96, 119, 144];
- let computeOk = false;
- let computeDetail = "";
- try {
- t0 = performance.now();
- const compModule = device.createShaderModule({ code: COMPUTE });
- const compPipeline = device.createComputePipeline({ layout: "auto", compute: { module: compModule, entryPoint: "main" } });
- function storageBuf(vals) {
- const buf = device.createBuffer({ size: vals.byteLength, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST });
- device.queue.writeBuffer(buf, 0, vals);
- return buf;
- }
- const aBuf = storageBuf(aVals);
- const bBuf = storageBuf(bVals);
- const outBuf = device.createBuffer({ size: 32, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC });
- const readBuf = device.createBuffer({ size: 32, usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST });
- const bindGroup = device.createBindGroup({
- layout: compPipeline.getBindGroupLayout(0),
- entries: [
- { binding: 0, resource: { buffer: aBuf } },
- { binding: 1, resource: { buffer: bBuf } },
- { binding: 2, resource: { buffer: outBuf } }
- ]
- });
- device.pushErrorScope("validation");
- const enc = device.createCommandEncoder();
- const pass = enc.beginComputePass();
- pass.setPipeline(compPipeline);
- pass.setBindGroup(0, bindGroup);
- pass.dispatchWorkgroups(1);
- pass.end();
- enc.copyBufferToBuffer(outBuf, 0, readBuf, 0, 32);
- device.queue.submit([enc.finish()]);
- const compErr = await device.popErrorScope();
- if (compErr) throw new Error("validation: " + compErr.message);
- await readBuf.mapAsync(GPUMapMode.READ);
- const got = Array.from(new Float32Array(readBuf.getMappedRange()));
- readBuf.unmap();
- computeOk = got.length === 8 && got.every((v, i) => v === expected[i]);
- computeDetail = "got [" + got.join(", ") + "] expected [" + expected.join(", ") + "] in " + ms(t0);
- } catch (e) {
- computeDetail = e.message;
- }
- check("compute a*a+b", computeOk, computeDetail);
- section("6 Canvas demo (rotating silver teapot, visible below)");
- let canvasOk = false;
- let canvasDetail = "";
- try {
- t0 = performance.now();
- const gen = ++demoGen;
- const canvas = document.getElementById("c");
- const ctx = canvas.getContext("webgpu");
- const format = navigator.gpu.getPreferredCanvasFormat();
- info("preferred canvas format: " + format);
- const potModule = device.createShaderModule({ code: TEAPOT });
- const potCI = await potModule.getCompilationInfo();
- const potErrs = potCI.messages.filter((m) => m.type === "error");
- info("teapot WGSL: " + potErrs.length + " errors, " + potCI.messages.length + " messages");
- if (potErrs.length) throw new Error("teapot WGSL: " + potErrs[0].message);
- const floorModule = device.createShaderModule({ code: FLOOR });
- const floorCI = await floorModule.getCompilationInfo();
- const floorErrs = floorCI.messages.filter((m) => m.type === "error");
- info("floor WGSL: " + floorErrs.length + " errors, " + floorCI.messages.length + " messages");
- if (floorErrs.length) throw new Error("floor WGSL: " + floorErrs[0].message);
- const bgModule = device.createShaderModule({ code: BACKGROUND });
- const bgCI = await bgModule.getCompilationInfo();
- const bgErrs = bgCI.messages.filter((m) => m.type === "error");
- info("background WGSL: " + bgErrs.length + " errors, " + bgCI.messages.length + " messages");
- if (bgErrs.length) throw new Error("background WGSL: " + bgErrs[0].message);
- const envLevels = buildEnvData();
- const envTex = device.createTexture({ size: [envLevels[0].w, envLevels[0].h, 1], mipLevelCount: envLevels.length, format: "rgba16float", usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST });
- for (let i = 0; i < envLevels.length; i++) {
- const L = envLevels[i];
- device.queue.writeTexture({ texture: envTex, mipLevel: i }, L.data, { bytesPerRow: L.w * 8, rowsPerImage: L.h }, [L.w, L.h, 1]);
- }
- info("environment: procedural HDR studio equirect " + envLevels[0].w + "x" + envLevels[0].h + " rgba16float, " + envLevels.length + " mip levels (roughness blur)");
- const envSampler = device.createSampler({ addressModeU: "repeat", addressModeV: "clamp-to-edge", magFilter: "linear", minFilter: "linear", mipmapFilter: "linear" });
- const mesh = buildTeapot();
- info("teapot mesh: " + (mesh.positions.length / 3) + " vertices, " + (mesh.indices.length / 3) + " triangles (Utah teapot: 32 bicubic Bezier patches, 306 control points, Crow 1987 data, welded and tessellated in code)");
- const vCount = mesh.positions.length / 3;
- const vData = new Float32Array(vCount * 6);
- for (let i = 0; i < vCount; i++) {
- vData.set(mesh.positions.subarray(i * 3, i * 3 + 3), i * 6);
- vData.set(mesh.normals.subarray(i * 3, i * 3 + 3), i * 6 + 3);
- }
- const vBuf = device.createBuffer({ size: vData.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST });
- device.queue.writeBuffer(vBuf, 0, vData);
- const iBuf = device.createBuffer({ size: mesh.indices.byteLength, usage: GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST });
- device.queue.writeBuffer(iBuf, 0, mesh.indices);
- const potLayout = {
- arrayStride: 24,
- attributes: [
- { shaderLocation: 0, offset: 0, format: "float32x3" },
- { shaderLocation: 1, offset: 12, format: "float32x3" }
- ]
- };
- function potPipe(targetFormat, cull, fragEntry) {
- return device.createRenderPipeline({
- layout: "auto",
- vertex: { module: potModule, entryPoint: "vs_main", buffers: [potLayout] },
- fragment: { module: potModule, entryPoint: fragEntry, targets: [{ format: targetFormat }] },
- primitive: { topology: "triangle-list", cullMode: cull },
- depthStencil: { format: "depth24plus", depthWriteEnabled: true, depthCompare: "less" }
- });
- }
- const potPipeCanvas = potPipe(format, "none", "fs_main");
- const potPipeRefl = potPipe("rgba8unorm", "none", "fs_refl");
- const floorVerts = new Float32Array([-6, 0, -6, 6, 0, -6, -6, 0, 6, 6, 0, 6]);
- const floorIdx = new Uint32Array([0, 2, 1, 1, 2, 3]);
- const floorVBuf = device.createBuffer({ size: floorVerts.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST });
- device.queue.writeBuffer(floorVBuf, 0, floorVerts);
- const floorIBuf = device.createBuffer({ size: floorIdx.byteLength, usage: GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST });
- device.queue.writeBuffer(floorIBuf, 0, floorIdx);
- const floorPipe = device.createRenderPipeline({
- layout: "auto",
- vertex: { module: floorModule, entryPoint: "vs_main", buffers: [{ arrayStride: 12, attributes: [{ shaderLocation: 0, offset: 0, format: "float32x3" }] }] },
- fragment: { module: floorModule, entryPoint: "fs_main", targets: [{ format }] },
- primitive: { topology: "triangle-list", cullMode: "none" },
- depthStencil: { format: "depth24plus", depthWriteEnabled: false, depthCompare: "less" }
- });
- const bgPipe = device.createRenderPipeline({
- layout: "auto",
- vertex: { module: bgModule, entryPoint: "vs_main" },
- fragment: { module: bgModule, entryPoint: "fs_main", targets: [{ format }] },
- primitive: { topology: "triangle-list", cullMode: "none" },
- depthStencil: { format: "depth24plus", depthWriteEnabled: false, depthCompare: "always" }
- });
- const bgUni = device.createBuffer({ size: 80, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST });
- const bgBind = device.createBindGroup({
- layout: bgPipe.getBindGroupLayout(0),
- entries: [
- { binding: 0, resource: { buffer: bgUni } },
- { binding: 1, resource: envTex.createView() },
- { binding: 2, resource: envSampler }
- ]
- });
- ctx.configure({ device, format, alphaMode: "premultiplied" });
- const eye = [4.4, 3.2, 5.6];
- const view = mat4LookAt(eye, [0, 1.15, 0], [0, 1, 0]);
- const proj = mat4Perspective(0.75, 1, 0.1, 100);
- const vp = mat4Multiply(proj, view);
- function uniBuf(bytes) { return device.createBuffer({ size: bytes, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }); }
- const potUni = uniBuf(160);
- const potUniRefl = uniBuf(160);
- const floorUni = uniBuf(96);
- function writePot(buf, model) {
- const d = new Float32Array(40);
- d.set(mat4Multiply(vp, model), 0);
- d.set(model, 16);
- d.set([eye[0], eye[1], eye[2], 0], 32);
- d.set([0.5, 0.85, 0.35, 0], 36);
- device.queue.writeBuffer(buf, 0, d);
- }
- function writeFloor() {
- const d = new Float32Array(24);
- d.set(vp, 0);
- d.set([eye[0], eye[1], eye[2], 0], 16);
- d.set([1280, 1280, 0, 0], 20);
- device.queue.writeBuffer(floorUni, 0, d);
- }
- writeFloor();
- {
- let fx = -eye[0], fy = 1.15 - eye[1], fz = -eye[2];
- let l = Math.hypot(fx, fy, fz); fx /= l; fy /= l; fz /= l;
- let rx = -fz, ry = 0, rz = fx;
- l = Math.hypot(rx, ry, rz); rx /= l; ry /= l; rz /= l;
- const ux = ry * fz - rz * fy, uy = rz * fx - rx * fz, uz = rx * fy - ry * fx;
- const d = new Float32Array(20);
- d.set([rx, ry, rz, 0], 0);
- d.set([ux, uy, uz, 0], 4);
- d.set([fx, fy, fz, 0], 8);
- d.set([Math.tan(0.375), 1, 0, 0], 12);
- device.queue.writeBuffer(bgUni, 0, d);
- }
- const reflTex = device.createTexture({ size: [640, 640, 1], format: "rgba8unorm", usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING });
- const reflDepth = device.createTexture({ size: [640, 640, 1], format: "depth24plus", usage: GPUTextureUsage.RENDER_ATTACHMENT });
- const canvasDepth = device.createTexture({ size: [1280, 1280, 1], format: "depth24plus", usage: GPUTextureUsage.RENDER_ATTACHMENT });
- const potBind = device.createBindGroup({
- layout: potPipeCanvas.getBindGroupLayout(0),
- entries: [
- { binding: 0, resource: { buffer: potUni } },
- { binding: 1, resource: envTex.createView() },
- { binding: 2, resource: envSampler }
- ]
- });
- const potBindRefl = device.createBindGroup({
- layout: potPipeRefl.getBindGroupLayout(0),
- entries: [
- { binding: 0, resource: { buffer: potUniRefl } },
- { binding: 1, resource: envTex.createView() },
- { binding: 2, resource: envSampler }
- ]
- });
- const sampler = device.createSampler({ magFilter: "linear", minFilter: "linear" });
- const floorBind = device.createBindGroup({
- layout: floorPipe.getBindGroupLayout(0),
- entries: [
- { binding: 0, resource: { buffer: floorUni } },
- { binding: 1, resource: reflTex.createView() },
- { binding: 2, resource: sampler }
- ]
- });
- function drawFrame(now, validate) {
- const ang = now * 0.0007;
- const bob = Math.sin(now * 0.0011) * 0.06;
- const model = mat4Multiply(mat4Translate(0, bob, 0), mat4RotY(ang));
- const modelRefl = mat4Multiply(mat4Scale(1, -1, 1), model);
- writePot(potUni, model);
- writePot(potUniRefl, modelRefl);
- if (validate) device.pushErrorScope("validation");
- const enc = device.createCommandEncoder();
- const rp = enc.beginRenderPass({
- colorAttachments: [{ view: reflTex.createView(), clearValue: { r: 0, g: 0, b: 0, a: 0 }, loadOp: "clear", storeOp: "store" }],
- depthStencilAttachment: { view: reflDepth.createView(), depthClearValue: 1, depthLoadOp: "clear", depthStoreOp: "store" }
- });
- rp.setPipeline(potPipeRefl);
- rp.setBindGroup(0, potBindRefl);
- rp.setVertexBuffer(0, vBuf);
- rp.setIndexBuffer(iBuf, "uint32");
- rp.drawIndexed(mesh.indices.length);
- rp.end();
- const cp = enc.beginRenderPass({
- colorAttachments: [{ view: ctx.getCurrentTexture().createView(), clearValue: { r: 0.05, g: 0.06, b: 0.08, a: 1 }, loadOp: "clear", storeOp: "store" }],
- depthStencilAttachment: { view: canvasDepth.createView(), depthClearValue: 1, depthLoadOp: "clear", depthStoreOp: "store" }
- });
- cp.setPipeline(bgPipe);
- cp.setBindGroup(0, bgBind);
- cp.draw(3);
- cp.setPipeline(floorPipe);
- cp.setBindGroup(0, floorBind);
- cp.setVertexBuffer(0, floorVBuf);
- cp.setIndexBuffer(floorIBuf, "uint32");
- cp.drawIndexed(6);
- cp.setPipeline(potPipeCanvas);
- cp.setBindGroup(0, potBind);
- cp.setVertexBuffer(0, vBuf);
- cp.setIndexBuffer(iBuf, "uint32");
- cp.drawIndexed(mesh.indices.length);
- cp.end();
- device.queue.submit([enc.finish()]);
- if (validate) return device.popErrorScope();
- return null;
- }
- const firstErr = await drawFrame(0, true);
- if (firstErr) throw new Error("validation: " + firstErr.message);
- await device.queue.onSubmittedWorkDone();
- canvasOk = true;
- canvasDetail = "teapot first frame complete in " + ms(t0) + "; rotating live (GGX PBR silver, procedural HDR studio environment, ACES, mirrored reflection on checkered floor)";
- const loop = (now) => {
- if (gen !== demoGen) return;
- try { drawFrame(now, false); } catch (e) { return; }
- requestAnimationFrame(loop);
- };
- requestAnimationFrame(loop);
- } catch (e) {
- canvasDetail = e.message;
- }
- check("canvas demo (silver teapot)", canvasOk, canvasDetail);
- section("7 Offscreen render + pixel readback");
- let readOk = false;
- let readDetail = "";
- try {
- t0 = performance.now();
- const tex = device.createTexture({
- size: [1280, 1280, 1],
- format: "rgba8unorm",
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC
- });
- const pipe = device.createRenderPipeline({
- layout: "auto",
- vertex: { module, entryPoint: "vs_main" },
- fragment: { module, entryPoint: "fs_main", targets: [{ format: "rgba8unorm" }] },
- primitive: { topology: "triangle-list" }
- });
- const bytesPerRow = 1280 * 4;
- const readBuf = device.createBuffer({ size: bytesPerRow * 1280, usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST });
- device.pushErrorScope("validation");
- const enc = device.createCommandEncoder();
- const pass = enc.beginRenderPass({
- colorAttachments: [{ view: tex.createView(), clearValue: { r: 0, g: 0, b: 0, a: 0 }, loadOp: "clear", storeOp: "store" }]
- });
- pass.setPipeline(pipe);
- pass.draw(3);
- pass.end();
- enc.copyTextureToBuffer({ texture: tex }, { buffer: readBuf, bytesPerRow }, [1280, 1280, 1]);
- device.queue.submit([enc.finish()]);
- const err = await device.popErrorScope();
- if (err) throw new Error("validation: " + err.message);
- await device.queue.onSubmittedWorkDone();
- await readBuf.mapAsync(GPUMapMode.READ);
- const data = new Uint8Array(readBuf.getMappedRange());
- const samples = [[940, 640], [640, 940], [340, 640], [640, 340], [1140, 840], [840, 1140], [640, 640], [100, 100]];
- let bad = 0;
- for (const [x, y] of samples) {
- const o = (y * 1280 + x) * 4;
- const got = [data[o], data[o + 1], data[o + 2], data[o + 3]];
- const exp = expectedPixel(x, y);
- const close = got.every((v, i) => Math.abs(v - exp[i]) <= 2);
- info("pixel (" + x + "," + y + ") got [" + got.join(",") + "] expected [" + exp.join(",") + "] " + (close ? "match" : "MISMATCH"));
- if (!close) bad++;
- }
- const seen = new Set();
- for (let y = 0; y < 1280; y += 16) {
- for (let x = 0; x < 1280; x += 16) {
- const o = (y * 1280 + x) * 4;
- seen.add(data[o] + "," + data[o + 1] + "," + data[o + 2]);
- }
- }
- info("distinct colours in 16px sample grid: " + seen.size + " (spiral palette has 19 + black)");
- readBuf.unmap();
- readOk = bad === 0 && seen.size >= 10;
- readDetail = bad + " pixel mismatches, " + seen.size + " distinct colours, in " + ms(t0);
- } catch (e) {
- readDetail = e.message;
- }
- check("offscreen pixels match spiral math", readOk, readDetail);
- finish();
- }
- function finish() {
- add("");
- add("== Summary ==");
- add("PASS " + passCount + " FAIL " + failCount);
- add(failCount === 0 ? "RESULT: WebGPU fully working on this system." : "RESULT: " + failCount + " check(s) failed - see FAIL lines above.");
- summaryEl.textContent = failCount === 0 ? "PASS " + passCount + " / FAIL 0 - WebGPU fully working" : "PASS " + passCount + " / FAIL " + failCount;
- summaryEl.className = failCount === 0 ? "pass" : "fail";
- }
- document.getElementById("copyBtn").addEventListener("click", async () => {
- try { await navigator.clipboard.writeText(reportEl.textContent); summaryEl.textContent += " (report copied)"; }
- catch (e) {
- const sel = window.getSelection();
- sel.selectAllChildren(reportEl);
- }
- });
- document.getElementById("dlBtn").addEventListener("click", () => {
- const blob = new Blob([reportEl.textContent], { type: "text/plain" });
- const a = document.createElement("a");
- a.href = URL.createObjectURL(blob);
- a.download = "webgpu-full-check.txt";
- a.click();
- URL.revokeObjectURL(a.href);
- });
- document.getElementById("rerunBtn").addEventListener("click", () => { main().catch((e) => add("ERROR: " + e.message)); });
- main().catch((e) => { add("ERROR: " + (e && e.message)); finish(); });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment