mirror of
https://github.com/webgpu/webgpufundamentals.git
synced 2026-05-16 15:02:24 -04:00
61 lines
1.3 KiB
HTML
61 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
|
<title>WebGPU Debugging - Helping WebGPU report errors (fixed)</title>
|
|
<style>
|
|
@import url(resources/webgpu-lesson.css);
|
|
</style>
|
|
</head>
|
|
<body>
|
|
</body>
|
|
<script type="module">
|
|
async function main() {
|
|
const adapter = await navigator.gpu?.requestAdapter();
|
|
const device = await adapter?.requestDevice();
|
|
if (!device) {
|
|
fail('need a browser that supports WebGPU');
|
|
return;
|
|
}
|
|
|
|
device.addEventListener('uncapturederror', event => {
|
|
log('uncaptured error:', event.error.message);
|
|
});
|
|
|
|
device.pushErrorScope('validation');
|
|
device.createShaderModule({
|
|
code: /* wgsl */ `
|
|
this shader won't compile
|
|
`,
|
|
});
|
|
const error = await device.popErrorScope();
|
|
if (error) {
|
|
log('captured error:', error.message);
|
|
}
|
|
|
|
device.createShaderModule({
|
|
code: /* wgsl */ `
|
|
also, this shader won't compile
|
|
`,
|
|
});
|
|
|
|
device.queue.submit([]);
|
|
log('--done--');
|
|
}
|
|
|
|
function fail(msg) {
|
|
// eslint-disable-next-line no-alert
|
|
alert(msg);
|
|
}
|
|
|
|
function log(...args) {
|
|
const elem = document.createElement('pre');
|
|
elem.textContent = args.join(' ');
|
|
document.body.appendChild(elem);
|
|
}
|
|
|
|
main();
|
|
</script>
|
|
</html>
|