noclip.website icon indicating copy to clipboard operation
noclip.website copied to clipboard

Rewrite BCn texture utilities

Open magcius opened this issue 3 years ago • 5 comments

  • [ ] Rewrite software BCn texture utilities in Rust (for performance)
  • [ ] Make utilities sRGB aware
  • [ ] Make utilities optionally automatically use queryTextureFormatSupported
  • [x] Expand queryTextureFormatSupported to include w/h queries to see if we can use native hardware decoding

magcius avatar Aug 06 '21 09:08 magcius

https://github.com/Jellonator/noclip.website/tree/bcn Finished first task. Moved deswizzle and BCn decompression to Rust. I managed to eek out a bit more performance by performing both in the same function. My (admittedly not exactly rigorous) testing seems to show that it is about 40% faster than before.

Jellonator avatar Aug 11 '21 00:08 Jellonator

I made the texture loading bit async, dunno if you want to keep that or not. It's difficult to make it synchronous due to the way loading WASM works.

Jellonator avatar Aug 11 '21 00:08 Jellonator

Can you file a PR so I can review it?

magcius avatar Aug 11 '21 00:08 magcius

Expanding on the notes for the other checkboxes.

  • [ ] sRGB-aware blending only needs to happen when computing the blended midpoints for the color tables. The way I expect it's going to work, we'll decode sRGB BC1 textures to an RGBA_U8_SRGB texture, so the endpoints should already be correct. We won't be able to get blending 100% correct for magnified textures, but we can do our best for the midpoints.

  • [x] queryTextureFormatSupported needs to accept width and height as arguments, and only return true for the BCn formats if they are divisible by 4 on the WebGL 2 backend. WebGPU could potentially support non-block-aligned mip textures as an extension, but should also do the same check for now, see https://github.com/gpuweb/gpuweb/issues/2006

  • [ ] Non-swizzling decoding could should also be added to Rust. Maybe there's some clever way to support both kinds of deswizzlers using a polymorphic struct so we can keep the combined deswizzle/pixel decode system (see something similar in gx_texture.rs)

  • [ ] The high-level game-facing API for this that's going to replace bc_texture.ts should be adapted to ask the device backend if it supports native hardware textures, and if so, uses that directly, and if it doesn't, falls back to decoding on the HW.

For game support, currently:

  • [ ] Source Engine and The Witness assume hardware BC1 support and does not have software decoding as a fallback
  • [ ] Psychonauts always decompresses
  • [ ] GTA has the option of using Basis textures, but its TXD fallback supports both hardware and non-hardware BC1
  • [ ] Dark Souls supports supports both hardware and non-hardware BC1

These games should all be changed to use the new game-facing API. Doesn't have to happen in one go.

magcius avatar Aug 11 '21 02:08 magcius

queryTextureFormatSupported needs to accept width and height as arguments

This has now been done in 0c5baaf6073c016613b355e3afc00cb35458e459

magcius avatar Aug 14 '21 21:08 magcius