* Asynchronously load webgpu pipelines when possible. * @param mod The input module.
(mod: Module)
| 1833 | * @param mod The input module. |
| 1834 | */ |
| 1835 | async asyncLoadWebGPUPipelines(mod: Module): Promise<void> { |
| 1836 | if (this.lib.webGPUContext === undefined) throw Error("WebGPU not initialied"); |
| 1837 | const webgpuContext = this.lib.webGPUContext; |
| 1838 | |
| 1839 | this.beginScope(); |
| 1840 | const fmap_str = mod.getFunction("webgpu.get_fmap", true)() as string; |
| 1841 | const fmap: Record<string, FunctionInfo> = JSON.parse(fmap_str); |
| 1842 | const fGetShader = this.detachFromCurrentScope( |
| 1843 | mod.getFunction("webgpu.get_shader") |
| 1844 | ); |
| 1845 | const fUpdatePrebuild = this.detachFromCurrentScope( |
| 1846 | mod.getFunction("webgpu.update_prebuild") |
| 1847 | ); |
| 1848 | this.endScope(); |
| 1849 | |
| 1850 | const perf = compact.getPerformance(); |
| 1851 | const tstart = perf.now(); |
| 1852 | let tlastReport = tstart; |
| 1853 | let finishCounter = 0; |
| 1854 | const fmapEntries = Object.entries(fmap); |
| 1855 | |
| 1856 | let allEvents = Promise.resolve(); |
| 1857 | |
| 1858 | for (const [key, finfo] of fmapEntries) { |
| 1859 | const code = fGetShader(key); |
| 1860 | assert(key === finfo.name); |
| 1861 | const event = webgpuContext.createShaderAsync(finfo, code).then((func) => { |
| 1862 | this.beginScope(); |
| 1863 | fUpdatePrebuild(key, func); |
| 1864 | this.endScope(); |
| 1865 | |
| 1866 | }).then(() => { |
| 1867 | finishCounter += 1; |
| 1868 | const tend = perf.now(); |
| 1869 | // skip report if gap is smaller than 1000 |
| 1870 | if ((tend - tlastReport) < 1000 && finishCounter != fmapEntries.length) { |
| 1871 | return; |
| 1872 | } |
| 1873 | tlastReport = tend; |
| 1874 | const timeElapsed = Math.ceil((perf.now() - tstart) / 1000); |
| 1875 | // report |
| 1876 | for (let j = 0; j < this.initProgressCallback.length; ++j) { |
| 1877 | const progress = finishCounter / fmapEntries.length; |
| 1878 | let text = "Loading GPU shader modules[" + finishCounter + "/" + fmapEntries.length + "]: "; |
| 1879 | text += Math.floor(progress * 100).toString() + "% completed, " |
| 1880 | text += timeElapsed + " secs elapsed."; |
| 1881 | this.initProgressCallback[j]({ |
| 1882 | progress: progress, |
| 1883 | timeElapsed: timeElapsed, |
| 1884 | text: text |
| 1885 | }); |
| 1886 | } |
| 1887 | }); |
| 1888 | allEvents = Promise.all([allEvents, event]).then(() => { }); |
| 1889 | } |
| 1890 | await allEvents; |
| 1891 | assert(finishCounter === fmapEntries.length); |
| 1892 | } |
nothing calls this directly
no test coverage detected