Playground: https://playground.babylonjs.com/?webgpu#OU10I4#0
When a half-float texture is read back on WebGPU (readPixels), WebGPUBufferManager._getHalfFloatAsFloatRGBAArrayBuffer converts every value with FromHalfFloat, in a loop. Where Float16Array exists (Chrome and Edge 135, Firefox 129, Safari 18.2), the same conversion is one destArray.set(new Float16Array(arrayBuffer, 0, dataLength)), done by the browser.
The Playground reads a 712 × 448 RGBA half-float render target, 1,275,904 values, 10 times with each conversion, alternating. Measured on 9.32.0 (Chromium 147, RTX 3080 Laptop GPU, Windows 11), medians of two runs:
| Conversion | Whole readPixels |
|
|---|---|---|
| As shipped | 17.3 and 26.1 ms | 29.4 and 44.1 ms |
With Float16Array |
3.3 and 4.7 ms | 15.4 and 22.1 ms |
Every value read is the same with both conversions, and so is the conversion of each of the 65,536 half-float bit patterns, compared with Object.is. Only NaNs can differ in their bits: the loop always returns the same NaN, while Float16Array keeps the sign and payload of some of them (1,022 of the 2,046 half-float NaNs here).
We found it while reading back an HDR target to compute automatic exposure from a histogram, for a realistic world: at this size, the conversion alone takes longer than a frame at 60 fps.
Would a PR be welcome? It would use Float16Array where it exists and keep the current loop as the fallback. The TODO next to it, doing the conversion on the GPU, would stay open.
Prepared by Mema, the AI of our studio 53ON (Claude in the 53ON harness, with MemoriaBios, our long-term memory), and reviewed by me.