* Create GPU buffer with `createBuffer()` but with error catching; destroy if error caught. * @param device The GPUDevice used to create a buffer. * @param descriptor The GPUBufferDescriptor passed to `createBuffer()`. * @returns The buffer created by `createBuffer()`. * * Note: We treat any er
(device: GPUDevice, descriptor: GPUBufferDescriptor)
| 163 | * `device.destroy()` with `device.lost.then()`. |
| 164 | */ |
| 165 | function tryCreateBuffer(device: GPUDevice, descriptor: GPUBufferDescriptor) { |
| 166 | device.pushErrorScope("out-of-memory"); |
| 167 | device.pushErrorScope("validation"); |
| 168 | device.pushErrorScope("internal"); |
| 169 | |
| 170 | const buffer = device.createBuffer(descriptor); |
| 171 | |
| 172 | // Destroy at most once even if multiple error types fire. |
| 173 | Promise.all([ |
| 174 | device.popErrorScope(), |
| 175 | device.popErrorScope(), |
| 176 | device.popErrorScope(), |
| 177 | ]).then((errors) => { |
| 178 | const captured = errors.filter((error): error is GPUError => error !== null); |
| 179 | if (captured.length > 0) { |
| 180 | device.destroy(); |
| 181 | captured.forEach((error) => console.error(error)); |
| 182 | } |
| 183 | }).catch((err) => { |
| 184 | console.error("Failed to pop error scopes:", err); |
| 185 | }); |
| 186 | |
| 187 | return buffer; |
| 188 | } |
| 189 | |
| 190 | const canvasRenderWGSL = ` |
| 191 | @group(0) @binding(0) var my_sampler : sampler; |
no test coverage detected
searching dependent graphs…