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_rgba8decodes mip 0 on the CPU via the optionaltexture2ddecoderpackage and returns RGBA8 pixels the standardupload_texture_pixelspath can ship asVK_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(nodecode_bc2); it maps toNone-> warn + -1. It is NOT aliased todecode_bc3because 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 mip 0 of a BC texture to a |
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
Nonewhen there is no decoder forvk_format(e.g. BC2) or thetexture2ddecoderpackage is not installed: the caller then warns + -1.