test_queue_write_invalid_device.html (1273B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" href="/tests/SimpleTest/test.css" /> 7 </head> 8 <body> 9 <script> 10 ok( 11 SpecialPowers.getBoolPref("dom.webgpu.enabled"), 12 "Pref should be enabled." 13 ); 14 15 const func = async function () { 16 const adapter = await navigator.gpu.requestAdapter(); 17 const device = await adapter.requestDevice(); 18 19 // Destroy the device, making it invalid. 20 device.destroy(); 21 22 // Creating a buffer on an invalid device will create an invalid 23 // buffer. 24 const buffer = device.createBuffer({ 25 size: 16, 26 usage: 27 GPUBufferUsage.COPY_DST | 28 GPUBufferUsage.COPY_SRC | 29 GPUBufferUsage.VERTEX, 30 }); 31 const arrayBuf = new ArrayBuffer(16); 32 new Int32Array(arrayBuf).fill(5); 33 34 // Writing to an invalid buffer should not throw an error. 35 device.queue.writeBuffer(buffer, 0, arrayBuf, 0); 36 }; 37 38 SimpleTest.waitForExplicitFinish(); 39 func() 40 .catch(e => ok(false, "Unhandled exception " + e)) 41 .finally(() => SimpleTest.finish()); 42 </script> 43 </body> 44 </html>