Skip to main content

Crate drmkit_fmt

Crate drmkit_fmt 

Source
Expand description

Format-modifier and hardware-compression support for drmkit’s plane allocator.

Port of src/fmt/ from drm-cxx @ dc2915b.

§Design contract

Carried verbatim from the C++, because the allocator depends on all three:

  • IN_FORMATS prunes the bipartite graph — necessary, not sufficient.
  • The atomic TEST_ONLY commit is ground truth for what a plane can scan out.
  • BandwidthClass is a cost input to placement scoring, never a correctness gate.

This keeps every vendor on one code path — AFBC (Arm/Rockchip/MediaTek), AMD DCC, Qualcomm UBWC, NVIDIA block-linear, Broadcom tiling: a (fourcc, modifier) pair flows from the producer’s allocation, through IN_FORMATS eligibility, to a probed-and-memoized test commit.

§Scope

This crate is no_std + alloc and device-free. Two pieces of the C++ fmt/ header live elsewhere in the port:

  • FormatTable::from_plane(fd, plane_id) — blob fetching belongs to drmkit-core’s property layer, which hands the bytes to FormatTable::from_blob. The C++ had already split the parser out for testability; this makes the split structural.
  • ScanoutBuffer — not ported as one type: GBM allocation is drmkit-gbm’s GbmBuffer, and the framebuffer modifier rule is drmkit-core’s framebuffer_modifier.

§Example

use drmkit_fmt::{
    BandwidthClass, FormatTable, Modifier, classify, fourcc, layer_fits_plane,
};

let plane = FormatTable::from_pairs([
    (fourcc::XRGB8888, Modifier::LINEAR),
    (fourcc::NV12, Modifier::LINEAR),
]);

assert!(layer_fits_plane(&plane, fourcc::XRGB8888, Modifier::LINEAR));
assert!(!layer_fits_plane(&plane, fourcc::ARGB8888, Modifier::LINEAR));

// The INVALID sentinel is interchangeable with LINEAR.
assert!(layer_fits_plane(&plane, fourcc::NV12, Modifier::INVALID));

assert_eq!(classify(Modifier::LINEAR), BandwidthClass::Linear);

Re-exports§

pub use fourcc::format_bpp;
pub use fourcc::format_name;

Modules§

afbc_block
AFBC superblock-size codes (low 4 bits of the modifier body).
afbc_flag
AFBC feature flags.
arm_type
Arm modifier type field (bits 55:52).
broadcom
Broadcom layout codes (low byte of the modifier body).
fourcc
DRM FourCC pixel-format codes and their bit depths.
vendor
DRM modifier vendor identifiers (DRM_FORMAT_MOD_VENDOR_*, the top 8 bits).

Structs§

FormatMod
A (fourcc, modifier) pair a plane accepts.
FormatTable
A plane’s accepted (fourcc, modifier) pairs, sorted and de-duplicated.
Modifier
A DRM format modifier.
ModifierProbeCache
Memoizes atomic TEST_ONLY verdicts.

Enums§

BandwidthClass
What a modifier does to bus traffic.
ModifierFamily
The family a modifier belongs to, for eligibility matching.
Rotation
Display-plane rotation. 90/270 transpose the scanout fetch order; 0/180 do not.
Verdict
The cached outcome of probing a (crtc, plane, fourcc, modifier) tuple with an atomic TEST_ONLY commit.

Constants§

ARM_16X16_BLOCK_U_INTERLEAVED
Legacy DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED.
DEFAULT_COMPRESSED_RATIO
The default worst-case compression ratio used when a modifier’s BandwidthClass is Compression.

Functions§

classify
Classify a modifier’s effect on scanout bandwidth.
describe
A human-readable rendering, e.g. ARM_AFBC(16x16|YTR|SPARSE) or QCOM_COMPRESSED(UBWC).
layer_fits_plane
Edge eligibility for the allocator’s bipartite pre-solve: an IN_FORMATS check with family awareness.
mod_code
Build a modifier value from a vendor and a 56-bit body, matching the fourcc_mod_code macro.
rotation_compatible
Can a buffer with modifier m be scanned out under rotation r?
sand128_col_height
Build a Broadcom SAND128 modifier with an explicit column height.
sand_col_height
The column height baked into a SAND64, SAND128 or SAND256 modifier, or None for anything else, SAND32 included.
scanout_cost_bytes
Approximate per-frame scanout read in bytes, for the allocator’s content-priority and spatial-split cost model.