Skip to content

Compressed texture support #3608

@superdump

Description

@superdump

Description

  • Support DDS, KTX2, and Basis Universal compressed textures
  • Support loading them from gltf

Solution

  • [Merged by Bors] - KTX2/DDS/.basis compressed texture support #3884
  • Generic compressed texture support
    • Load compressed texture data as-is by adding create_texture_with_data to RenderDevice and using it
    • When preparing the GpuImage, if it is a compressed format, use RenderDevice::create_texture_with_data with the specified format, which includes all mipmaps. If it is not compressed, copy mipmap level 0 only as before.
    • Explicitly specify whether a texture to be loaded from a buffer is sRGB or linear at load time. For glTF textures are marked as being linear or not and this is used to indicate sRGB or not.
    • Respect platform-supported compressed formats
      • Add CompressedImageFormats flag type with ASTC_LDR, BC, and ETC2 flags to match what is supported by wgpu::Features
      • Add a supported_compressed_formats member to ImageTextureLoader and GltfLoader and populate it based on WgpuOptions at loader-initialisation-time.
      • When loading an Image using Image::from_buffer(), pass the CompressedImageFormats stored in the loader to inform the load() about whether compressed formats are supported, and/or about formats to transcode to, in case of universal compressed formats such as UASTC/ETC1S.
  • DDS
    • Load raw data from DDS files, using the ddsfile crate, into Image and set the correct image format. Note that this includes all mipmaps.
    • Map all DDS formats, both D3D and DXGI to wgpu texture formats
  • KTX2
    • Load raw mip level data from KTX2 files, using the ktx2 crate, into Image and set the correct image format. Note that this includes all mipmaps.
    • Map all KTX2 formats to wgpu texture formats
    • KTX2 supercompression support
      • Parse the Data Format Descriptor and Sample Information sections of the KTX2 header to get all the necessary information needed to identify the format. PR here: Data format descriptor BVE-Reborn/ktx2#4
      • ZLIB using flate2 which in turn uses miniz_oxide which is a rust DEFLATE implementation
      • Zstandard using ruzstd which is a rust Zstandard decompressor
    • Transcoding from KTX2 UASTC to an appropriate format using the basis-universal crate which uses bindings to the C++ Basis Universal library
  • Basis Universal
    • .basis file support for ETC1S/UASTC with transcoding to an appropriate format, also using the basis-universal crate
  • Support for 2-component normal maps stored in the red and green channels, deriving the third component assuming the stored normal is a unit normal.

Next Steps

  • WASM target support for both .basis files and transcoding UASTC from KTX2 files. The basis-universal library has been compiled to WASM. It is possible to call other JavaScript code from rust code compiled to WASM using C-style FFI so maybe it will work for WASM to WASM as well?
  • KTX2 BasisLZ supercompression support. BasisLZ is quite non-trivial so I feel like it is reasonable to only support it via .basis files to start with.

Metadata

Metadata

Assignees

Labels

A-RenderingDrawing game state to the screenC-FeatureA new feature, making something new possible

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions