Read ASTC, ETC2/EAC, PVRTC and 4:2:2 textures the device lacks through twins of Metal's decode
On a device without a texture's compressed or chroma format, the runtime now makes the texture and
reads it as Metal does. Before, such a texture was refused at its making (ASTC, ETC2/EAC) or at its
first read (PVRTC, 4:2:2, held for copies alone). The consumer's guest on the RTX 5080 stopped at
ASTC_8x8_LDR, PVRTC_RGB_2BPP and EAC_R11Unorm. NVIDIA, RADV and lavapipe have none of these formats,
and Vulkan's 4:2:2 formats need a sampler Y'CbCr conversion whose chroma reconstruction is the
implementation's.
What changes:
- The store. The blocks lie in a carrier image of the same block bytes and shape (a compressed
format the device copies: BC1, BC4, BC7, BC3, BC2, BC5, ETC2, EAC or ASTC 4x4; R8G8 for 4:2:2).
replace_region, get_bytes, blits, fills and texture copies move Metal's blocks unchanged.
- The twin. Reads go to a decoded twin holding Metal's decode, kept in step on the GPU as a BC
texture's twin is: a decode pass after a blit, a texture copy or a submitted CPU copy, and a CPU
decode on the device's decode thread after a host write. No write costs a GPU-to-CPU round trip.
A write's decode covers whole levels for PVRTC and whole rows for 4:2:2, whose texels read their
neighbours. A new texture's twin starts at the decode of zero blocks (magenta for ASTC's error
block), not at zeros.
- The decoders, our own, written from the Khronos ASTC specification, the Khronos Data Format
Specification's ETC2 and EAC chapters, and Metal's measured answers for PVRTC1 and 4:2:2:
bind::AstcDecode, EtcDecode, PvrtcDecode and ChromaDecode, with their GPU kernels
astc_decode_module, etc_decode_module, pvrtc_decode_module and chroma_decode_module on the block
decode's bindings (new api_surface rows, with AstcTexels, EtcTexels and DecodedTexelsPolicy).
- Metal's decode, matched: an ASTC LDR channel is (C >> 4) / 4095 of the 16-bit interpolated C;
an 8-bit ETC2/EAC channel c / 255, an 11-bit one c / 2047 (signed c / 1023); PVRTC upscales
colours A and B from the four block centres around a texel and blends them by its index; a 4:2:2
texel takes its own green, and red and blue (3c + n + 2) >> 2 of its pair and the pair beside it.
- sRGB forms. The ASTC, PVRTC and ETC2/EAC sRGB formats read their twin's codes raw through an
R8G8B8A8_UNORM view and decode them through Metal's table, as the 8-bit and BC sRGB formats do:
reads, nearest samples and gathers exact, with no precision notice. Linear samples keep the
device's sRGB filter (the exact sum under SamplingPolicy::Exact). A device that has the ASTC
block keeps its own sRGB decode. The linear PVRTC and 8-bit linear ETC2/EAC formats take BC1 to
BC3's Argb8 texel class, so under TexelConversionPolicy::Exact their reads are Metal's c / 255.
- The switch: DevicePolicy::decoded_texels, DecodedTexelsPolicy { Compact (default), Exact };
exact_answers() selects Exact. Compact holds an ASTC LDR twin in 8-bit codes nearest Metal's
12-bit value (at most 1/510 off) and an EAC 11-bit twin in the nearest 16-bit codes, announced
decoded-texel-precision. Exact holds their floats. PVRTC, the 8-bit ETC2/EAC formats, the ASTC
sRGB formats and 4:2:2 are exact under both. Tested by fast_paths; a FAST-PATHS row.
- Views in the other colour space. An ASTC texture viewed in its other colour space reads a second
twin, made at the first such view: Metal reads that view exactly as a texture of the view's
format over the same blocks, and the two forms widen endpoints apart, so one twin cannot serve
both. Its decodes are queued on the device and recorded by the next batch with work. Counted by
WorkCounts::second_twins, second_twin_checks and second_twin_decodes. PVRTC and 8-bit ETC2/EAC
views of the other colour space share the one twin.
- Copies between a compressed texture and an uncompressed one whose texel is the block's bytes
(BC1 or ETC2 with RG32Uint, BC7 or ASTC with RGBA32Uint) run with Metal's rule: every coordinate
in the destination's texels, a block per texel. They were refused as formats of different units.
- Notices: carried-decoded-twin (Performance) on every twinned texture; decoded-texel-precision
(Precision) only for an ASTC LDR or EAC 11-bit twin under Compact.
- Typed refusals: RuntimeGap::DecodedHeapTexture (a heap's ASTC texture, a sparse heap's carried
texture; the heap size query refuses alike); views of the ASTC HDR form, of another footprint or
PVRTC block, and of an EAC 11-bit format as its other signedness (Unsupported(TextureView));
copies between PVRTC and an uncompressed format, between two compressed formats of one block size
and different extents, and level or slice copies between compressed and uncompressed formats
(NotImplemented(Format)). A device with the native format keeps the direct path.
- Docs: the API.md catalogue entries, the FAST-PATHS decoded_texels row and known gaps, and the
module docs of astc.rs, etc.rs, pvrtc.rs, chroma_pairs.rs and decoded_twin.rs.
Why: Metal makes, reads and samples these textures on Apple GPUs, and the consumer's guest uses
them; the desktop Vulkan drivers have no such formats.
Verified:
- Metal's answers, probed on an M3 Max under macOS 27.0.1: ASTC (seeded random blocks, all 14
footprints, linear and sRGB, read as float and half) bit for bit, digests pinned by
seeded_blocks_read_as_metal_read_them; ETC2/EAC (4096 random blocks of each of the ten formats)
digests equal; PVRTC (all eight formats) every digest equal; 4:2:2 every read, sample and gather
bit for bit what an RGBA8Unorm texture of the decoded codes answers; the copy rule on every listed
pair both ways.
- On the CPU SPIR-V interpreter each GPU kernel writes the CPU decode on every texel: ASTC on every
footprint, linear and sRGB, Float and Unorm8, with blocks covering all 16 endpoint modes, every
partition count, dual plane and void extent; ETC on every decode and both texel forms; PVRTC on
every format. The kernels are valid on every committed profile.
- Runtime unit filters 63 passed and translator unit filters 183 passed (ETC2/EAC); the runtime's
unit suite 952 of 953 (the one failure the recorder's module-list test, fixed with the recorder).
- On lavapipe: chroma_pairs, pvrtc_textures, the mipmap, fill, buffer-texture and degrade-notice
lanes, 45 passed; format_copies, the whole module. A lavapipe batch caught PVRTC codes read one
ulp high under exact answers, fixed by the Argb8 class.
- clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd) and rustdoc on ms01 and gem10.
This commit is contained in:
1 parent
6b322fb50f
commit
930d746df7
69 files changed
+9934
-570
No files matched your search
+33
@@ -1797,6 +1797,39 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound.
|
||||
the decoded twin on the host or the staging queue: the first command buffer that may read the
|
||||
texture waits at its submission for that, and the call waits for it where a command buffer that
|
||||
may read the texture is submitted and not yet complete, or the texture is untracked.
|
||||
- `metal2vulkan-degrade-carried-decoded-twin` (performance). `CarriedDecodedTwin`: A texture of an ASTC
|
||||
LDR format (`ASTC_4x4_LDR` to `ASTC_12x12_LDR`, the sRGB forms too) made on a device without that
|
||||
ASTC format, of a PVRTC format on a device without it (every device but MoltenVK's, and there
|
||||
the four RGB formats), or of an ETC2 or EAC format on a device without them (desktop GPUs and
|
||||
lavapipe): its blocks lie in an image of a carrier format whose blocks are also 16 (ASTC,
|
||||
`EAC_RGBA8`, `RG11`) or 8 (PVRTC, the other ETC2 and EAC formats) bytes, which copies and
|
||||
`get_bytes` move unchanged, and its samples read a decoded twin, Metal's decode of the blocks in
|
||||
the texels `DecodedTexelsPolicy` names (a PVRTC texture's, and an 8-bit ETC2 or EAC texture's,
|
||||
8-bit codes, exact under either: its sRGB form's slots decode them through Metal's table, and one
|
||||
twin serves the views of the linear and sRGB forms; an ASTC sRGB texture's, its own 8-bit codes,
|
||||
read the same way), decoded after each write into it as a BC
|
||||
texture's twin is (`decoded-block-twin`; a PVRTC texture's whole levels, since each texel's
|
||||
colors come from the blocks around it). An ASTC texture's first view in its other colour
|
||||
space (its sRGB form as LDR, or the other way) gives it a second twin of that form's decode, kept
|
||||
in step by GPU passes its command buffers' submissions record. Also a texture of a 4:2:2 format
|
||||
(`GBGR422`, `BGRG422`) on every device, whose Vulkan formats reconstruct chroma by the
|
||||
implementation's rules: its texels' bytes lie in an `R8G8_UNORM` carrier, and its twin holds
|
||||
Metal's texels as 8-bit codes, exact (each texel's own green, its red and blue interpolated with
|
||||
the pair beside it), decoded in whole rows. Cost: a carrier image of its
|
||||
blocks, at most about 1 byte a texel (a 4:2:2 texture's 2), and a decoded twin of 4 bytes a texel (R8G8B8A8,
|
||||
`DecodedTexelsPolicy::Compact`; an EAC 11-bit texture's 16-bit codes, 2 bytes a channel) or 16
|
||||
(R32G32B32A32_SFLOAT, `DecodedTexelsPolicy::Exact`; an EAC 11-bit texture's floats, 4 bytes a
|
||||
channel), two for an ASTC texture viewed in both colour spaces, and a decode after each write into it: a pass on
|
||||
the GPU for a blit, a copy from a texture or a CPU copy through a submission; on the CPU, on the
|
||||
device's decode thread, where its CPU copies go on the host or the staging queue.
|
||||
- `metal2vulkan-degrade-decoded-texel-precision` (precision). `DecodedTexelPrecision`: A texture with an
|
||||
ASTC LDR decoded twin of 8-bit codes, or an EAC 11-bit one (`R11`, `RG11`) of 16-bit normalized
|
||||
codes, under `DecodedTexelsPolicy::Compact`. Cost: a read, sample or gather of its texels answers
|
||||
the nearest 8-bit code to Metal's 12-bit value, at most 1/510 off it; an EAC 11-bit texture's,
|
||||
the nearest 16-bit normalized code to Metal's `c / 2047` (signed `c / 1023`), at most half a
|
||||
16-bit step off it. `DecodedTexelsPolicy::Exact` holds Metal's values instead. An ASTC sRGB
|
||||
texture's twin holds Metal's own 8-bit codes, which its slots decode through Metal's table:
|
||||
exact, under either.
|
||||
- `metal2vulkan-degrade-shared-present-queue` (performance). `SharedPresentQueue`: A command queue
|
||||
made for presenting (`Device::new_command_queue_for_presenting`) on a device that reserved no
|
||||
`VkQueue` for presenting: its queue family has no queue past the ones the round robin takes
|
||||
|
||||
Reference in new issue
Block a user