simvx.graphics.assets.block_decode

CPU decode of BC block-compressed mip 0 to RGBA8, the universal fallback.

When the GPU lacks textureCompressionBC (or a specific BC format’s SAMPLED feature) the compressed-upload path cannot run. Rather than drop the texture,

func:

decode_blocks_to_rgba8 decodes mip 0 on the CPU via the optional texture2ddecoder package and returns RGBA8 pixels the standard upload_texture_pixels path can ship as VK_FORMAT_R8G8B8A8_UNORM.

texture2ddecoder returns BGRA bytes (probe-confirmed: a solid-red BC1 block decodes to [0, 0, 255, 255]), so the channels are swizzled to RGBA before upload. A missed swizzle would render red as blue.

The package is imported LAZILY inside the function: missing it returns None so the caller degrades to warn + -1, never a crash, and this module imports cleanly without it (the web/Pyodide path is unaffected).

Notes / known gaps:

  • BC2 has no decoder in texture2ddecoder (no decode_bc2); it maps to None -> warn + -1. It is NOT aliased to decode_bc3 because the alpha layouts differ and that would corrupt the image. BC2 is rare.

  • BC6H decodes to an 8-bit approximation of an HDR format, and BC*_SRGB sources lose sRGB-on-sample (the upload format is hard-coded UNORM). Both are acceptable for a degraded fallback; the GPU-native path stays correct.

Module Contents

Functions

decode_blocks_to_rgba8

Decode mip 0 of a BC texture to a (height, width, 4) uint8 RGBA array.

Data

API

simvx.graphics.assets.block_decode.__all__

[‘decode_blocks_to_rgba8’]

simvx.graphics.assets.block_decode.log

‘getLogger(…)’

simvx.graphics.assets.block_decode.decode_blocks_to_rgba8(vk_format: int, width: int, height: int, level0_blocks: bytes) numpy.ndarray | None[source]

Decode mip 0 of a BC texture to a (height, width, 4) uint8 RGBA array.

Returns None when there is no decoder for vk_format (e.g. BC2) or the texture2ddecoder package is not installed: the caller then warns + -1.