Add error handler

This commit is contained in:
Andras Schmelczer 2023-04-30 16:57:14 +01:00
commit c44a6858e0
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
6 changed files with 104 additions and 39 deletions

View file

@ -1,7 +1,9 @@
import { ErrorHandler, Severity } from '../error-handler';
export const initializeGPU = async (): Promise<GPUDevice> => {
const gpu = navigator.gpu;
if (!gpu) {
throw new Error('WebGPU is not supported');
throw new Error('WebGPU is not supported in your browser');
}
const adapter = await gpu.requestAdapter({
@ -12,5 +14,15 @@ export const initializeGPU = async (): Promise<GPUDevice> => {
throw new Error('Could not request adatper');
}
return await adapter.requestDevice(); // could request more resources
ErrorHandler.addMetadata('adapter', await adapter.requestAdapterInfo());
ErrorHandler.addMetadata('features', adapter.features);
ErrorHandler.addMetadata('limits', adapter.limits);
const gpuDevice = await adapter.requestDevice(); // could request more resources
gpuDevice.addEventListener('uncapturederror', (event: GPUUncapturedErrorEvent) =>
ErrorHandler.addError(Severity.ERROR, event.error.message)
);
return gpuDevice;
};