* Initialize webgpu in the runtime. * @param device The given GPU device.
(device: GPUDevice)
| 1896 | * @param device The given GPU device. |
| 1897 | */ |
| 1898 | initWebGPU(device: GPUDevice): void { |
| 1899 | device.addEventListener("uncapturederror", (event) => { |
| 1900 | console.error("A WebGPU error was not captured: ", event); |
| 1901 | }); |
| 1902 | |
| 1903 | device.lost.then((info: any) => { |
| 1904 | if (this.deviceLostIsError) { |
| 1905 | console.error("Device lost, calling Instance.dispose(). Please initialize again. ", info); |
| 1906 | this.dispose(); |
| 1907 | } |
| 1908 | }); |
| 1909 | this.deviceLostIsError = true; |
| 1910 | |
| 1911 | const webGPUContext = new WebGPUContext( |
| 1912 | this.memory, device |
| 1913 | ); |
| 1914 | this.registerFunc("wasm.WebGPUDeviceAPI", (name: string) => { |
| 1915 | return webGPUContext.getDeviceAPI(name); |
| 1916 | }); |
| 1917 | this.registerFunc("wasm.WebGPUCreateShader", (info: string, code: string) => { |
| 1918 | const finfo = JSON.parse(info) as FunctionInfo; |
| 1919 | return webGPUContext.createShader(finfo, code); |
| 1920 | }); |
| 1921 | this.registerAsyncServerFunc("wasm.WebGPUWaitForTasks", async () => { |
| 1922 | await webGPUContext.sync(); |
| 1923 | }); |
| 1924 | if (this.asyncifyHandler.enabled()) { |
| 1925 | this.registerAsyncifyFunc("__asyncify.WebGPUWaitForTasks", async () => { |
| 1926 | await webGPUContext.sync(); |
| 1927 | }); |
| 1928 | } |
| 1929 | this.lib.webGPUContext = webGPUContext; |
| 1930 | } |
| 1931 | |
| 1932 | /** Register all object factory */ |
| 1933 | private registerObjectFactoryFuncs(): void { |
no test coverage detected