gpu-handle-types 0.2.0

Typed, owned native GPU resource handles (Vulkan, D3D11/12, Metal, OpenGL, CUDA, OpenCL, DMA-BUF, IOSurface, AHardwareBuffer, WebGPU, ...), cross-API sync points and video pixel formats, for passing GPU resources between libraries.
Documentation
// SPDX-License-Identifier: MIT OR Apache-2.0
//
// Pin every (variant, shader_id) pair literally. The ordinals are the
// load-bearing identity a GPU shader (WGSL / OpenCL / CUDA) switches on;
// a silent variant-reorder must fail CI loudly. The colour ordinals are
// pinned the same way in `video-types`.

use gpu_handle_types::PixelFormat;

#[test]
fn pixel_format_shader_ids() {
    assert_eq!(PixelFormat::NV12.shader_id(), 0);
    assert_eq!(PixelFormat::NV21.shader_id(), 1);
    assert_eq!(PixelFormat::P010LE.shader_id(), 2);
    assert_eq!(PixelFormat::P016LE.shader_id(), 3);
    assert_eq!(PixelFormat::P210LE.shader_id(), 4);
    assert_eq!(PixelFormat::P216LE.shader_id(), 5);
    assert_eq!(PixelFormat::P410LE.shader_id(), 6);
    assert_eq!(PixelFormat::P416LE.shader_id(), 7);
    assert_eq!(PixelFormat::YUV420P.shader_id(), 8);
    assert_eq!(PixelFormat::YUV422P.shader_id(), 9);
    assert_eq!(PixelFormat::YUV444P.shader_id(), 10);
    assert_eq!(PixelFormat::YUV420P10LE.shader_id(), 11);
    assert_eq!(PixelFormat::YUV420P12LE.shader_id(), 12);
    assert_eq!(PixelFormat::YUV420P14LE.shader_id(), 13);
    assert_eq!(PixelFormat::YUV420P16LE.shader_id(), 14);
    assert_eq!(PixelFormat::YUV422P10LE.shader_id(), 15);
    assert_eq!(PixelFormat::YUV422P12LE.shader_id(), 16);
    assert_eq!(PixelFormat::YUV422P14LE.shader_id(), 17);
    assert_eq!(PixelFormat::YUV422P16LE.shader_id(), 18);
    assert_eq!(PixelFormat::YUV444P10LE.shader_id(), 19);
    assert_eq!(PixelFormat::YUV444P12LE.shader_id(), 20);
    assert_eq!(PixelFormat::YUV444P14LE.shader_id(), 21);
    assert_eq!(PixelFormat::YUV444P16LE.shader_id(), 22);
    assert_eq!(PixelFormat::UYVY422.shader_id(), 23);
    assert_eq!(PixelFormat::YUYV422.shader_id(), 24);
    assert_eq!(PixelFormat::AYUV64LE.shader_id(), 25);
    assert_eq!(PixelFormat::RgbaU8.shader_id(), 26);
    assert_eq!(PixelFormat::BgraU8.shader_id(), 27);
    assert_eq!(PixelFormat::RgbaU16.shader_id(), 28);
    assert_eq!(PixelFormat::BgraU16.shader_id(), 29);
    assert_eq!(PixelFormat::RgbaF16.shader_id(), 30);
    assert_eq!(PixelFormat::BgraF16.shader_id(), 31);
    assert_eq!(PixelFormat::RgbaF32.shader_id(), 32);
    assert_eq!(PixelFormat::BgraF32.shader_id(), 33);
    assert_eq!(PixelFormat::RgbU16.shader_id(), 34);
    assert_eq!(PixelFormat::R16U.shader_id(), 35);
    assert_eq!(PixelFormat::R32F.shader_id(), 36);
    assert_eq!(PixelFormat::Rgba16U.shader_id(), 37);
    assert_eq!(PixelFormat::YUVA444P10LE.shader_id(), 38);
    assert_eq!(PixelFormat::YUVA444P12LE.shader_id(), 39);
    assert_eq!(PixelFormat::Rgb10A2.shader_id(), 40);
    assert_eq!(PixelFormat::NV16.shader_id(), 41);
    assert_eq!(PixelFormat::NV24.shader_id(), 42);
    assert_eq!(PixelFormat::V216.shader_id(), 43);
    assert_eq!(PixelFormat::NV12A.shader_id(), 44);
    assert_eq!(PixelFormat::Y210LE.shader_id(), 45);
    assert_eq!(PixelFormat::RgbxU8.shader_id(), 46);
    assert_eq!(PixelFormat::BgrxU8.shader_id(), 47);
    // The roster and the ordinals are the same table (asserted at compile
    // time in `pixel_format.rs`); pinning the length here makes an added
    // variant say so in this gate too.
    assert_eq!(PixelFormat::ALL.len(), PixelFormat::COUNT);
}

/// Confirms shader_id ordinals are *unique* — guards against a typo that
/// accidentally maps two variants to the same ordinal.
#[test]
fn shader_ids_unique() {
    use std::collections::HashSet;

    let mut seen = HashSet::new();
    // The canonical roster rather than a hand-maintained copy, which could
    // silently miss the newest variants and leave their ordinals covered by
    // nothing.
    assert!(PixelFormat::ALL.iter().all(|x| seen.insert(x.shader_id())));
}