diff --git a/README.md b/README.md index e5139b588..b89326e82 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,7 @@ For the runtime, start at [its README](crates/metal2vulkan-runtime/README.md). | [Runtime README](crates/metal2vulkan-runtime/README.md) | You use the Metal API on Vulkan | | [docs/HOWTO.md](docs/HOWTO.md) | You integrate: tools, caching, failures, isolation, the runtime's shader cache | | [docs/RUNTIME-PORTING.md](docs/RUNTIME-PORTING.md) | You port Metal calls (Objective-C or metal-rs) to the runtime | +| [docs/RESOURCE-ID.md](docs/RESOURCE-ID.md) | You compute a texture's or sampler's `gpuResourceID` on the guest's side | | [docs/FAST-PATHS.md](docs/FAST-PATHS.md) | You need every speed-for-accuracy default and its exact switch | | [docs/METAL-COVERAGE.md](docs/METAL-COVERAGE.md) | You ask whether a Metal API item is covered | | [docs/REFUSALS.md](docs/REFUSALS.md) | You ask what Metal accepts that the code refuses | diff --git a/crates/metal2vulkan/src/metal/mod.rs b/crates/metal2vulkan/src/metal/mod.rs index c1249dac4..550705f2b 100644 --- a/crates/metal2vulkan/src/metal/mod.rs +++ b/crates/metal2vulkan/src/metal/mod.rs @@ -444,6 +444,7 @@ impl TextureWriteRoundingMode { pub(crate) mod bicubic; pub mod format; +pub mod resource_word; pub mod sampler; pub mod state; pub(crate) mod texel_format; diff --git a/crates/metal2vulkan/src/metal/resource_word.rs b/crates/metal2vulkan/src/metal/resource_word.rs new file mode 100644 index 000000000..3b3b6f5ac --- /dev/null +++ b/crates/metal2vulkan/src/metal/resource_word.rs @@ -0,0 +1,83 @@ +//! The high word of a texture's `gpuResourceID`: what a shader reads of a texture it learns only +//! at run time, as a pure function of the Metal texture descriptor, so a guest computes it with +//! no round trip. `docs/RESOURCE-ID.md` is the specification; a sampler's word is +//! [`SamplerWord`](crate::metal::sampler::SamplerWord). + +use crate::metal::{PixelFormat, TextureSwizzleChannels}; + +/// The high word of a texture's `gpuResourceID`, from its pixel format and swizzle alone. The +/// bits: +/// +/// | bits | field | +/// |---|---| +/// | 0-11 | [`BORDER_TEXELS`](Self::BORDER_TEXELS): Metal's border texel for each border color | +/// | 12 | [`OUT_OF_BOUNDS_ALPHA_ONE`](Self::OUT_OF_BOUNDS_ALPHA_ONE): the format has no alpha | +/// | 13-15 | 0 | +/// | 16-31 | [`PIXEL_FORMAT`](Self::PIXEL_FORMAT): the `MTLPixelFormat` raw value | +/// +/// Bit `3c + b` of the border texels is set where channel `c` (0 red to 3 alpha) of the texel a +/// Metal 4.1 read through a sampler hands back outside the level on a border axis, for border +/// color `b` (`MTLSamplerBorderColor`'s raw value: transparent black, opaque black, opaque +/// white), reads 1 rather than 0, after the swizzle. A color format's channels are its own; a +/// depth or stencil format reads as red, green and blue, alpha 1. An out-of-bounds `read` of a +/// format without alpha reads alpha 1 (MSL 4.1 sections 2.9.1 and 6.13). Every pixel format's +/// raw value is above 0, so a texture's word is never 0, and the nil `gpuResourceID`, 0, has the +/// word 0. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct TextureWord(pub u32); + +impl TextureWord { + /// The border texels' bits. + pub const BORDER_TEXELS: u32 = 0xfff; + /// The format has no alpha: an out-of-bounds read reads alpha 1. + pub const OUT_OF_BOUNDS_ALPHA_ONE: u32 = 1 << 12; + /// The lowest bit of the pixel format. + pub const PIXEL_FORMAT_SHIFT: u32 = 16; + /// The pixel format's bits. + pub const PIXEL_FORMAT: u32 = 0xffff << Self::PIXEL_FORMAT_SHIFT; + + /// The word of a texture of `pixel_format` made with `swizzle`. `None` for the placeholders + /// (`Invalid`, `Unspecialized`) and the formats of which the translator holds no texture or + /// which it only copies, which no shader reads. + pub fn of(pixel_format: PixelFormat, swizzle: TextureSwizzleChannels) -> Option { + let border = crate::metal::sampler::border_texels(pixel_format, swizzle)?; + let alpha_one = crate::metal::format::out_of_bounds_alpha_one(pixel_format)?; + let mut w = border | (pixel_format.as_raw() << Self::PIXEL_FORMAT_SHIFT); + if alpha_one { + w |= Self::OUT_OF_BOUNDS_ALPHA_ONE; + } + Some(TextureWord(w)) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::metal::TextureSwizzle; + + /// Each field lands in its bits: `RGBA8Unorm` (raw 70) has every channel, so white reads 1 in + /// each and opaque black in alpha; `R8Unorm` (raw 10) has red alone, so its green and blue + /// read 0 under every color, its alpha 1 under every color, and its out-of-bounds alpha is 1; + /// a swizzle of red from one and green from zero sets and clears those channels' bits; + /// `Invalid` has no word. + #[test] + fn each_field_lands_in_its_bits() { + let rgba = TextureWord::of(PixelFormat::RGBA8Unorm, TextureSwizzleChannels::DEFAULT); + assert_eq!(rgba, Some(TextureWord(70 << 16 | 0b110_100_100_100))); + let r = TextureWord::of(PixelFormat::R8Unorm, TextureSwizzleChannels::DEFAULT); + assert_eq!(r, Some(TextureWord(10 << 16 | 1 << 12 | 0b111_000_000_100))); + let ones = TextureSwizzleChannels::new( + TextureSwizzle::One, + TextureSwizzle::Zero, + TextureSwizzle::Blue, + TextureSwizzle::Alpha, + ); + let swizzled = TextureWord::of(PixelFormat::RGBA8Unorm, ones); + assert_eq!(swizzled, Some(TextureWord(70 << 16 | 0b110_100_000_111))); + assert_eq!( + TextureWord::of(PixelFormat::Invalid, TextureSwizzleChannels::DEFAULT), + None + ); + } +} diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index d0d2f1487..c67a80332 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -468,6 +468,10 @@ assoc-const metal2vulkan::device::ResolveMode::ALL pub const ALL: [ResolveMode; assoc-const metal2vulkan::metal::DataType::ALL pub const ALL: [DataType; 17] assoc-const metal2vulkan::metal::TextureSwizzleChannels::DEFAULT pub const DEFAULT: TextureSwizzleChannels assoc-const metal2vulkan::metal::format::ExtendedRange::HEAP_READ pub const HEAP_READ: [ExtendedRange; 7] +assoc-const metal2vulkan::metal::resource_word::TextureWord::BORDER_TEXELS pub const BORDER_TEXELS: u32 +assoc-const metal2vulkan::metal::resource_word::TextureWord::OUT_OF_BOUNDS_ALPHA_ONE pub const OUT_OF_BOUNDS_ALPHA_ONE: u32 +assoc-const metal2vulkan::metal::resource_word::TextureWord::PIXEL_FORMAT pub const PIXEL_FORMAT: u32 +assoc-const metal2vulkan::metal::resource_word::TextureWord::PIXEL_FORMAT_SHIFT pub const PIXEL_FORMAT_SHIFT: u32 assoc-const metal2vulkan::metal::sampler::AddressModeMap::IDENTITY pub const IDENTITY: AddressModeMap assoc-const metal2vulkan::metal::sampler::SamplerWord::ADDRESS pub const ADDRESS: [u32; 3] assoc-const metal2vulkan::metal::sampler::SamplerWord::ADDRESS_SHIFT pub const ADDRESS_SHIFT: [u32; 3] @@ -988,6 +992,10 @@ assoc-const-value metal2vulkan::device::ResolveMode::ALL [ResolveMode::SampleZer assoc-const-value metal2vulkan::metal::DataType::ALL [DataType::Float32, DataType::Float16, DataType::BFloat16, DataType::Int2, DataType::Int4, DataType::Int8, DataType::Int16, DataType::Int32, DataType::UInt2, DataType::UInt4, DataType::UInt8, DataType::UInt16, DataType::UInt32, DataType::Fp4E2M1, DataType::Fp8E4M3, DataType::Fp8E5M2, DataType::Fp8UE8M0] assoc-const-value metal2vulkan::metal::TextureSwizzleChannels::DEFAULT TextureSwizzleChannels assoc-const-value metal2vulkan::metal::format::ExtendedRange::HEAP_READ [ExtendedRange::Bgr10 { srgb: false }, ExtendedRange::Bgra10 { srgb: false }, ExtendedRange::R10X6, ExtendedRange::Rg10X12, ExtendedRange::R16Bfloat, ExtendedRange::Rg16Bfloat, ExtendedRange::Rgba16Bfloat] +assoc-const-value metal2vulkan::metal::resource_word::TextureWord::BORDER_TEXELS 0xfff +assoc-const-value metal2vulkan::metal::resource_word::TextureWord::OUT_OF_BOUNDS_ALPHA_ONE 1 <<12 +assoc-const-value metal2vulkan::metal::resource_word::TextureWord::PIXEL_FORMAT 0xffff < Option method metal2vulkan::metal::format::WordAttachment::pack pub fn pack(self, codes: [u32; 4]) -> u32 method metal2vulkan::metal::format::WordAttachment::word_format pub fn word_format(self) -> vk::Format +method metal2vulkan::metal::resource_word::TextureWord::of pub fn of(pixel_format: PixelFormat, swizzle: TextureSwizzleChannels) -> Option method metal2vulkan::metal::sampler::AddressModeMap::constexpr_mode pub fn constexpr_mode(&self, from: SamplerAddressMode) -> Option method metal2vulkan::metal::sampler::AddressModeMap::is_identity pub fn is_identity(&self) -> bool method metal2vulkan::metal::sampler::AddressModeMap::mode pub fn mode(&self, from: SamplerAddressMode) -> SamplerAddressMode @@ -11133,6 +11142,7 @@ struct metal2vulkan::metal::TextureSwizzleChannels #[cfg_attr(feature = "serde", struct metal2vulkan::metal::format::FormatMapping #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub struct FormatMapping struct metal2vulkan::metal::format::WordField #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct WordField struct metal2vulkan::metal::format::YCbCrFormat #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub struct YCbCrFormat +struct metal2vulkan::metal::resource_word::TextureWord #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct TextureWord(pub u32) struct metal2vulkan::metal::sampler::AddressModeMap #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct AddressModeMap struct metal2vulkan::metal::sampler::SamplerUse #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub struct SamplerUse struct metal2vulkan::metal::sampler::SamplerWord #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SamplerWord(pub u32) diff --git a/crates/metal2vulkan/tests/api_surface.rs b/crates/metal2vulkan/tests/api_surface.rs index 67a4a9bd8..f73291e02 100644 --- a/crates/metal2vulkan/tests/api_surface.rs +++ b/crates/metal2vulkan/tests/api_surface.rs @@ -958,6 +958,7 @@ surface! { enum VertexStepFunction N; enum Winding E; mod format; + mod resource_word; mod sampler; mod state; mod vertex; @@ -1007,6 +1008,9 @@ surface! { fn alpha_in_red; fn alpha_in_red_format; } + "metal::resource_word" => metal2vulkan::metal::resource_word { + struct TextureWord E; + } "metal::sampler" => metal2vulkan::metal::sampler { struct SamplerUse N; struct SamplerWord E; @@ -2372,6 +2376,7 @@ fn scanned_modules() -> Vec<&'static str> { "cache", "metal", "metal::format", + "metal::resource_word", "metal::sampler", "metal::state", "metal::vertex", diff --git a/crates/metal2vulkan/tests/resource_words.rs b/crates/metal2vulkan/tests/resource_words.rs new file mode 100644 index 000000000..172827482 --- /dev/null +++ b/crates/metal2vulkan/tests/resource_words.rs @@ -0,0 +1,283 @@ +//! The `gpuResourceID` high words' test vectors (`docs/RESOURCE-ID.md`): `resource_words.tsv` +//! beside this file holds one Metal descriptor per line, as raw Metal values, and its word. A +//! guest's own computation of the words checks itself against the same file. +//! +//! `the_vectors_are_the_words` reads every line and computes its word through the public API, so +//! the file means what the specification says of its columns; `the_vectors_are_current` holds the +//! file equal to what `bless_resource_words` writes, so a change of any word is a change of this +//! file, which the guest's copy then fails on. Bless with +//! `cargo nextest run -p metal2vulkan --all-features --run-ignored ignored-only -E +//! 'test(bless_resource_words)'`. + +use std::collections::BTreeSet; +use std::fmt::Write as _; +use std::path::PathBuf; + +use metal2vulkan::bind::SamplerDescriptor; +use metal2vulkan::metal::resource_word::TextureWord; +use metal2vulkan::metal::sampler::SamplerWord; +use metal2vulkan::metal::{ + CompareFunction, PixelFormat, SamplerAddressMode, SamplerBorderColor, SamplerMinMagFilter, + SamplerMipFilter, SamplerReductionMode, TextureSwizzle, TextureSwizzleChannels, +}; + +const HEADER: &str = "\ +# gpuResourceID high words (docs/RESOURCE-ID.md): one Metal descriptor per line, raw Metal values. +# texture\tpixelFormat\tswizzleRed\tswizzleGreen\tswizzleBlue\tswizzleAlpha\tword +# sampler\tminFilter\tmagFilter\tmipFilter\tsAddressMode\ttAddressMode\trAddressMode\tborderColor\tnormalizedCoordinates\tlodMinClamp\tlodMaxClamp\tlodAverage\tmaxAnisotropy\tcompareFunction\treductionMode\tword +# lodMinClamp and lodMaxClamp are a float's IEEE-754 bits; booleans are 0 or 1; words are hex. +"; + +fn path() -> PathBuf { + PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/resource_words.tsv") +} + +fn swizzle(channels: TextureSwizzleChannels) -> [TextureSwizzle; 4] { + [channels.red, channels.green, channels.blue, channels.alpha] +} + +/// The texture lines: every pixel format with a word under the default swizzle, then each +/// channel of a few formats of one to four channels, depth, integer and rotated, read from each +/// other source. +fn textures(out: &mut String) { + let mut line = |pf: PixelFormat, channels: TextureSwizzleChannels| { + let Some(TextureWord(word)) = TextureWord::of(pf, channels) else { + return; + }; + let s = swizzle(channels).map(|s| s.as_raw().to_string()).join("\t"); + let _ = writeln!(out, "texture\t{}\t{s}\t{word:#010x}", pf.as_raw()); + }; + for &pf in PixelFormat::ALL { + line(pf, TextureSwizzleChannels::DEFAULT); + } + let formats = [ + PixelFormat::A8Unorm, + PixelFormat::R8Unorm, + PixelFormat::RG8Unorm, + PixelFormat::RGBA8Unorm, + PixelFormat::BGRA8Unorm, + PixelFormat::R32Uint, + PixelFormat::Depth32Float, + ]; + for pf in formats { + for channel in 0..4 { + for &source in TextureSwizzle::ALL { + let mut s = swizzle(TextureSwizzleChannels::DEFAULT); + if s[channel] == source { + continue; + } + s[channel] = source; + line(pf, TextureSwizzleChannels::new(s[0], s[1], s[2], s[3])); + } + } + } +} + +fn sampler_line(out: &mut String, d: &SamplerDescriptor) { + let SamplerWord(word) = SamplerWord::of(d); + let fields = [ + d.min_filter.as_raw(), + d.mag_filter.as_raw(), + d.mip_filter.as_raw(), + d.s_address_mode.as_raw(), + d.t_address_mode.as_raw(), + d.r_address_mode.as_raw(), + d.border_color.as_raw(), + u32::from(d.normalized_coordinates), + ]; + let fields = fields.map(|f| f.to_string()).join("\t"); + let _ = writeln!( + out, + "sampler\t{fields}\t{:#010x}\t{:#010x}\t{}\t{}\t{}\t{}\t{word:#010x}", + d.lod_min_clamp.to_bits(), + d.lod_max_clamp.to_bits(), + u32::from(d.lod_average), + d.max_anisotropy, + d.compare_function.as_raw(), + d.reduction_mode.as_raw(), + ); +} + +/// The sampler lines: the default descriptor, each field through each of its values with the +/// others at their defaults, the level clamps around the points a nearest mip filter's level +/// turns at, and one descriptor with every field away from its default. +fn samplers(out: &mut String) { + let base = SamplerDescriptor::new(); + let mut each = |set: &dyn Fn(&mut SamplerDescriptor)| { + let mut d = base; + set(&mut d); + sampler_line(out, &d); + }; + each(&|_| {}); + for &f in SamplerMinMagFilter::ALL { + each(&|d| d.min_filter = f); + each(&|d| d.mag_filter = f); + } + for &f in SamplerMipFilter::ALL { + each(&|d| d.mip_filter = f); + } + for &m in SamplerAddressMode::ALL { + each(&|d| d.s_address_mode = m); + each(&|d| d.t_address_mode = m); + each(&|d| d.r_address_mode = m); + } + for &b in SamplerBorderColor::ALL { + each(&|d| d.border_color = b); + } + each(&|d| d.normalized_coordinates = false); + let mins = [ + 0.0, + 0.25, + 0.5, + 0.515625, + 0.53125, + 1.0, + 1.4, + 1.6, + 2.75, + 14.5, + 14.6, + 15.0, + 100.0, + f32::MAX, + ]; + for c in mins { + each(&|d| d.lod_min_clamp = c); + } + let maxes = [0.0, 0.5, 0.515625, 0.53125, 3.9, 14.0, 14.6, 15.0, 1000.0]; + for c in maxes { + each(&|d| d.lod_max_clamp = c); + } + each(&|d| d.lod_average = true); + for a in [2, 3, 16] { + each(&|d| d.max_anisotropy = a); + } + for &f in CompareFunction::ALL { + each(&|d| d.compare_function = f); + } + for &r in SamplerReductionMode::ALL { + each(&|d| d.reduction_mode = r); + } + each(&|d| { + d.min_filter = SamplerMinMagFilter::Linear; + d.mag_filter = SamplerMinMagFilter::Cubic; + d.mip_filter = SamplerMipFilter::Linear; + d.s_address_mode = SamplerAddressMode::Repeat; + d.t_address_mode = SamplerAddressMode::MirrorRepeat; + d.r_address_mode = SamplerAddressMode::ClampToBorderColor; + d.border_color = SamplerBorderColor::OpaqueWhite; + d.normalized_coordinates = false; + d.lod_min_clamp = 2.75; + d.lod_max_clamp = 9.25; + d.lod_average = true; + d.max_anisotropy = 8; + d.compare_function = CompareFunction::GreaterEqual; + d.reduction_mode = SamplerReductionMode::Maximum; + }); +} + +/// The file: the header, then the texture and sampler lines, each line once. +fn generate() -> String { + let mut lines = String::new(); + textures(&mut lines); + samplers(&mut lines); + let mut seen = BTreeSet::new(); + let mut out = String::from(HEADER); + for line in lines.lines().filter(|l| seen.insert(*l)) { + out.push_str(line); + out.push('\n'); + } + out +} + +fn raw(all: &[T], as_raw: impl Fn(T) -> u32, field: &str) -> T { + let v: u32 = field.parse().unwrap_or_else(|_| panic!("field {field}")); + all.iter() + .copied() + .find(|&t| as_raw(t) == v) + .unwrap_or_else(|| panic!("no value {v}")) +} + +fn hex(field: &str) -> u32 { + let digits = field + .strip_prefix("0x") + .unwrap_or_else(|| panic!("hex {field}")); + u32::from_str_radix(digits, 16).unwrap_or_else(|_| panic!("hex {field}")) +} + +fn flag(field: &str) -> bool { + match field { + "0" => false, + "1" => true, + _ => panic!("boolean {field}"), + } +} + +/// The word a line's descriptor has, computed through the public API from its columns alone. +fn word_of(fields: &[&str]) -> u32 { + match fields { + ["texture", pf, r, g, b, a] => { + let pf = raw(PixelFormat::ALL, PixelFormat::as_raw, pf); + let s = |f: &str| raw(TextureSwizzle::ALL, TextureSwizzle::as_raw, f); + let channels = TextureSwizzleChannels::new(s(r), s(g), s(b), s(a)); + TextureWord::of(pf, channels).expect("a word").0 + } + ["sampler", min, mag, mip, sa, ta, ra, border, normalized, lo, hi, average, aniso, compare, reduction] => + { + let mut d = SamplerDescriptor::new(); + let filter = |f: &str| raw(SamplerMinMagFilter::ALL, SamplerMinMagFilter::as_raw, f); + let mode = |f: &str| raw(SamplerAddressMode::ALL, SamplerAddressMode::as_raw, f); + d.min_filter = filter(min); + d.mag_filter = filter(mag); + d.mip_filter = raw(SamplerMipFilter::ALL, SamplerMipFilter::as_raw, mip); + d.s_address_mode = mode(sa); + d.t_address_mode = mode(ta); + d.r_address_mode = mode(ra); + d.border_color = raw(SamplerBorderColor::ALL, SamplerBorderColor::as_raw, border); + d.normalized_coordinates = flag(normalized); + d.lod_min_clamp = f32::from_bits(hex(lo)); + d.lod_max_clamp = f32::from_bits(hex(hi)); + d.lod_average = flag(average); + d.max_anisotropy = aniso.parse().expect("maxAnisotropy"); + d.compare_function = raw(CompareFunction::ALL, CompareFunction::as_raw, compare); + d.reduction_mode = raw( + SamplerReductionMode::ALL, + SamplerReductionMode::as_raw, + reduction, + ); + SamplerWord::of(&d).0 + } + _ => panic!("unknown line {fields:?}"), + } +} + +#[test] +fn the_vectors_are_the_words() { + let text = std::fs::read_to_string(path()).expect("resource_words.tsv"); + let mut lines = 0; + for line in text.lines().filter(|l| !l.starts_with('#')) { + let fields: Vec<&str> = line.split('\t').collect(); + let Some((word, descriptor)) = fields.split_last() else { + panic!("empty line"); + }; + assert_eq!(word_of(descriptor), hex(word), "{line}"); + lines += 1; + } + assert!(lines > 0, "no vectors"); +} + +#[test] +fn the_vectors_are_current() { + let text = std::fs::read_to_string(path()).expect("resource_words.tsv"); + assert!( + text == generate(), + "resource_words.tsv is not what the words are now: bless it (this file's docs) and tell \ + the guest's port" + ); +} + +#[test] +#[ignore = "writes tests/resource_words.tsv"] +fn bless_resource_words() { + std::fs::write(path(), generate()).expect("write resource_words.tsv"); +} diff --git a/crates/metal2vulkan/tests/resource_words.tsv b/crates/metal2vulkan/tests/resource_words.tsv new file mode 100644 index 000000000..259e9e2f0 --- /dev/null +++ b/crates/metal2vulkan/tests/resource_words.tsv @@ -0,0 +1,396 @@ +# gpuResourceID high words (docs/RESOURCE-ID.md): one Metal descriptor per line, raw Metal values. +# texture pixelFormat swizzleRed swizzleGreen swizzleBlue swizzleAlpha word +# sampler minFilter magFilter mipFilter sAddressMode tAddressMode rAddressMode borderColor normalizedCoordinates lodMinClamp lodMaxClamp lodAverage maxAnisotropy compareFunction reductionMode word +# lodMinClamp and lodMaxClamp are a float's IEEE-754 bits; booleans are 0 or 1; words are hex. +texture 1 2 3 4 5 0x00010800 +texture 10 2 3 4 5 0x000a1e04 +texture 11 2 3 4 5 0x000b1e04 +texture 12 2 3 4 5 0x000c1e04 +texture 13 2 3 4 5 0x000d1e04 +texture 14 2 3 4 5 0x000e1e04 +texture 20 2 3 4 5 0x00141e04 +texture 22 2 3 4 5 0x00161e04 +texture 23 2 3 4 5 0x00171e04 +texture 24 2 3 4 5 0x00181e04 +texture 25 2 3 4 5 0x00191e04 +texture 30 2 3 4 5 0x001e1e24 +texture 31 2 3 4 5 0x001f1e24 +texture 32 2 3 4 5 0x00201e24 +texture 33 2 3 4 5 0x00211e24 +texture 34 2 3 4 5 0x00221e24 +texture 40 2 3 4 5 0x00281f24 +texture 41 2 3 4 5 0x00290d24 +texture 42 2 3 4 5 0x002a0d24 +texture 43 2 3 4 5 0x002b0d24 +texture 53 2 3 4 5 0x00351e04 +texture 54 2 3 4 5 0x00361e04 +texture 55 2 3 4 5 0x00371e04 +texture 60 2 3 4 5 0x003c1e24 +texture 62 2 3 4 5 0x003e1e24 +texture 63 2 3 4 5 0x003f1e24 +texture 64 2 3 4 5 0x00401e24 +texture 65 2 3 4 5 0x00411e24 +texture 70 2 3 4 5 0x00460d24 +texture 71 2 3 4 5 0x00470d24 +texture 72 2 3 4 5 0x00480d24 +texture 73 2 3 4 5 0x00490d24 +texture 74 2 3 4 5 0x004a0d24 +texture 80 2 3 4 5 0x00500d24 +texture 81 2 3 4 5 0x00510d24 +texture 90 2 3 4 5 0x005a0d24 +texture 91 2 3 4 5 0x005b0d24 +texture 92 2 3 4 5 0x005c1f24 +texture 93 2 3 4 5 0x005d1f24 +texture 94 2 3 4 5 0x005e0d24 +texture 554 2 3 4 5 0x022a1f24 +texture 555 2 3 4 5 0x022b1f24 +texture 103 2 3 4 5 0x00671e24 +texture 104 2 3 4 5 0x00681e24 +texture 105 2 3 4 5 0x00691e24 +texture 110 2 3 4 5 0x006e0d24 +texture 112 2 3 4 5 0x00700d24 +texture 113 2 3 4 5 0x00710d24 +texture 114 2 3 4 5 0x00720d24 +texture 115 2 3 4 5 0x00730d24 +texture 552 2 3 4 5 0x02280d24 +texture 553 2 3 4 5 0x02290d24 +texture 123 2 3 4 5 0x007b0d24 +texture 124 2 3 4 5 0x007c0d24 +texture 125 2 3 4 5 0x007d0d24 +texture 130 2 3 4 5 0x00820d24 +texture 131 2 3 4 5 0x00830d24 +texture 132 2 3 4 5 0x00840d24 +texture 133 2 3 4 5 0x00850d24 +texture 134 2 3 4 5 0x00860d24 +texture 135 2 3 4 5 0x00870d24 +texture 140 2 3 4 5 0x008c1e04 +texture 141 2 3 4 5 0x008d1e04 +texture 142 2 3 4 5 0x008e1e24 +texture 143 2 3 4 5 0x008f1e24 +texture 150 2 3 4 5 0x00961f24 +texture 151 2 3 4 5 0x00971f24 +texture 152 2 3 4 5 0x00980d24 +texture 153 2 3 4 5 0x00990d24 +texture 160 2 3 4 5 0x00a01f24 +texture 161 2 3 4 5 0x00a11f24 +texture 162 2 3 4 5 0x00a21f24 +texture 163 2 3 4 5 0x00a31f24 +texture 164 2 3 4 5 0x00a40d24 +texture 165 2 3 4 5 0x00a50d24 +texture 166 2 3 4 5 0x00a60d24 +texture 167 2 3 4 5 0x00a70d24 +texture 170 2 3 4 5 0x00aa1e04 +texture 172 2 3 4 5 0x00ac1e04 +texture 174 2 3 4 5 0x00ae1e24 +texture 176 2 3 4 5 0x00b01e24 +texture 178 2 3 4 5 0x00b20d24 +texture 179 2 3 4 5 0x00b30d24 +texture 180 2 3 4 5 0x00b41f24 +texture 181 2 3 4 5 0x00b51f24 +texture 182 2 3 4 5 0x00b60d24 +texture 183 2 3 4 5 0x00b70d24 +texture 186 2 3 4 5 0x00ba0d24 +texture 187 2 3 4 5 0x00bb0d24 +texture 188 2 3 4 5 0x00bc0d24 +texture 189 2 3 4 5 0x00bd0d24 +texture 190 2 3 4 5 0x00be0d24 +texture 192 2 3 4 5 0x00c00d24 +texture 193 2 3 4 5 0x00c10d24 +texture 194 2 3 4 5 0x00c20d24 +texture 195 2 3 4 5 0x00c30d24 +texture 196 2 3 4 5 0x00c40d24 +texture 197 2 3 4 5 0x00c50d24 +texture 198 2 3 4 5 0x00c60d24 +texture 199 2 3 4 5 0x00c70d24 +texture 200 2 3 4 5 0x00c80d24 +texture 204 2 3 4 5 0x00cc0d24 +texture 205 2 3 4 5 0x00cd0d24 +texture 206 2 3 4 5 0x00ce0d24 +texture 207 2 3 4 5 0x00cf0d24 +texture 208 2 3 4 5 0x00d00d24 +texture 210 2 3 4 5 0x00d20d24 +texture 211 2 3 4 5 0x00d30d24 +texture 212 2 3 4 5 0x00d40d24 +texture 213 2 3 4 5 0x00d50d24 +texture 214 2 3 4 5 0x00d60d24 +texture 215 2 3 4 5 0x00d70d24 +texture 216 2 3 4 5 0x00d80d24 +texture 217 2 3 4 5 0x00d90d24 +texture 218 2 3 4 5 0x00da0d24 +texture 222 2 3 4 5 0x00de0d24 +texture 223 2 3 4 5 0x00df0d24 +texture 224 2 3 4 5 0x00e00d24 +texture 225 2 3 4 5 0x00e10d24 +texture 226 2 3 4 5 0x00e20d24 +texture 228 2 3 4 5 0x00e40d24 +texture 229 2 3 4 5 0x00e50d24 +texture 230 2 3 4 5 0x00e60d24 +texture 231 2 3 4 5 0x00e70d24 +texture 232 2 3 4 5 0x00e80d24 +texture 233 2 3 4 5 0x00e90d24 +texture 234 2 3 4 5 0x00ea0d24 +texture 235 2 3 4 5 0x00eb0d24 +texture 236 2 3 4 5 0x00ec0d24 +texture 240 2 3 4 5 0x00f01f24 +texture 241 2 3 4 5 0x00f11f24 +texture 250 2 3 4 5 0x00fa1f24 +texture 252 2 3 4 5 0x00fc1f24 +texture 253 2 3 4 5 0x00fd1f24 +texture 255 2 3 4 5 0x00ff1f24 +texture 260 2 3 4 5 0x01041f24 +texture 261 2 3 4 5 0x01051f24 +texture 262 2 3 4 5 0x01061f24 +texture 84 2 3 4 5 0x005409a4 +texture 550 2 3 4 5 0x02260d24 +texture 551 2 3 4 5 0x02270d24 +texture 500 2 3 4 5 0x01f41f24 +texture 502 2 3 4 5 0x01f61f24 +texture 503 2 3 4 5 0x01f71f24 +texture 505 2 3 4 5 0x01f91f24 +texture 506 2 3 4 5 0x01fa1f24 +texture 507 2 3 4 5 0x01fb1f24 +texture 508 2 3 4 5 0x01fc1f24 +texture 509 2 3 4 5 0x01fd1f24 +texture 510 2 3 4 5 0x01fe1f24 +texture 520 2 3 4 5 0x02081f24 +texture 522 2 3 4 5 0x020a1f24 +texture 523 2 3 4 5 0x020b1f24 +texture 525 2 3 4 5 0x020d1f24 +texture 526 2 3 4 5 0x020e1f24 +texture 527 2 3 4 5 0x020f1f24 +texture 528 2 3 4 5 0x02101f24 +texture 529 2 3 4 5 0x02111f24 +texture 530 2 3 4 5 0x02121f24 +texture 540 2 3 4 5 0x021c1f24 +texture 541 2 3 4 5 0x021d1f24 +texture 542 2 3 4 5 0x021e1f24 +texture 543 2 3 4 5 0x021f1f24 +texture 544 2 3 4 5 0x02201f24 +texture 545 2 3 4 5 0x02211f24 +texture 185 2 3 4 5 0x00b90d24 +texture 191 2 3 4 5 0x00bf0d24 +texture 203 2 3 4 5 0x00cb0d24 +texture 209 2 3 4 5 0x00d10d24 +texture 221 2 3 4 5 0x00dd0d24 +texture 227 2 3 4 5 0x00e30d24 +texture 26 2 3 4 5 0x001a1e04 +texture 44 2 3 4 5 0x002c0d24 +texture 66 2 3 4 5 0x00421e24 +texture 116 2 3 4 5 0x00740d24 +texture 300 2 3 4 5 0x012c1f24 +texture 301 2 3 4 5 0x012d1f24 +texture 302 2 3 4 5 0x012e1f24 +texture 303 2 3 4 5 0x012f1f24 +texture 304 2 3 4 5 0x01301f24 +texture 313 2 3 4 5 0x01391f24 +texture 314 2 3 4 5 0x013a1f24 +texture 315 2 3 4 5 0x013b1f24 +texture 323 2 3 4 5 0x01431f24 +texture 324 2 3 4 5 0x01441f24 +texture 325 2 3 4 5 0x01451f24 +texture 576 2 3 4 5 0x02401e04 +texture 577 2 3 4 5 0x02411e04 +texture 578 2 3 4 5 0x02421e24 +texture 579 2 3 4 5 0x02431e24 +texture 586 2 3 4 5 0x024a0d24 +texture 1 0 3 4 5 0x00010800 +texture 1 1 3 4 5 0x00010807 +texture 1 3 3 4 5 0x00010800 +texture 1 4 3 4 5 0x00010800 +texture 1 5 3 4 5 0x00010804 +texture 1 2 0 4 5 0x00010800 +texture 1 2 1 4 5 0x00010838 +texture 1 2 2 4 5 0x00010800 +texture 1 2 4 4 5 0x00010800 +texture 1 2 5 4 5 0x00010820 +texture 1 2 3 0 5 0x00010800 +texture 1 2 3 1 5 0x000109c0 +texture 1 2 3 2 5 0x00010800 +texture 1 2 3 3 5 0x00010800 +texture 1 2 3 5 5 0x00010900 +texture 1 2 3 4 0 0x00010000 +texture 1 2 3 4 1 0x00010e00 +texture 1 2 3 4 2 0x00010000 +texture 1 2 3 4 3 0x00010000 +texture 1 2 3 4 4 0x00010000 +texture 10 0 3 4 5 0x000a1e00 +texture 10 1 3 4 5 0x000a1e07 +texture 10 3 3 4 5 0x000a1e00 +texture 10 4 3 4 5 0x000a1e00 +texture 10 5 3 4 5 0x000a1e07 +texture 10 2 0 4 5 0x000a1e04 +texture 10 2 1 4 5 0x000a1e3c +texture 10 2 2 4 5 0x000a1e24 +texture 10 2 4 4 5 0x000a1e04 +texture 10 2 5 4 5 0x000a1e3c +texture 10 2 3 0 5 0x000a1e04 +texture 10 2 3 1 5 0x000a1fc4 +texture 10 2 3 2 5 0x000a1f04 +texture 10 2 3 3 5 0x000a1e04 +texture 10 2 3 5 5 0x000a1fc4 +texture 10 2 3 4 0 0x000a1004 +texture 10 2 3 4 1 0x000a1e04 +texture 10 2 3 4 2 0x000a1804 +texture 10 2 3 4 3 0x000a1004 +texture 10 2 3 4 4 0x000a1004 +texture 30 0 3 4 5 0x001e1e20 +texture 30 1 3 4 5 0x001e1e27 +texture 30 3 3 4 5 0x001e1e24 +texture 30 4 3 4 5 0x001e1e20 +texture 30 5 3 4 5 0x001e1e27 +texture 30 2 0 4 5 0x001e1e04 +texture 30 2 1 4 5 0x001e1e3c +texture 30 2 2 4 5 0x001e1e24 +texture 30 2 4 4 5 0x001e1e04 +texture 30 2 5 4 5 0x001e1e3c +texture 30 2 3 0 5 0x001e1e24 +texture 30 2 3 1 5 0x001e1fe4 +texture 30 2 3 2 5 0x001e1f24 +texture 30 2 3 3 5 0x001e1f24 +texture 30 2 3 5 5 0x001e1fe4 +texture 30 2 3 4 0 0x001e1024 +texture 30 2 3 4 1 0x001e1e24 +texture 30 2 3 4 2 0x001e1824 +texture 30 2 3 4 3 0x001e1824 +texture 30 2 3 4 4 0x001e1024 +texture 70 0 3 4 5 0x00460d20 +texture 70 1 3 4 5 0x00460d27 +texture 70 3 3 4 5 0x00460d24 +texture 70 4 3 4 5 0x00460d24 +texture 70 5 3 4 5 0x00460d26 +texture 70 2 0 4 5 0x00460d04 +texture 70 2 1 4 5 0x00460d3c +texture 70 2 2 4 5 0x00460d24 +texture 70 2 4 4 5 0x00460d24 +texture 70 2 5 4 5 0x00460d34 +texture 70 2 3 0 5 0x00460c24 +texture 70 2 3 1 5 0x00460de4 +texture 70 2 3 2 5 0x00460d24 +texture 70 2 3 3 5 0x00460d24 +texture 70 2 3 5 5 0x00460da4 +texture 70 2 3 4 0 0x00460124 +texture 70 2 3 4 1 0x00460f24 +texture 70 2 3 4 2 0x00460924 +texture 70 2 3 4 3 0x00460924 +texture 70 2 3 4 4 0x00460924 +texture 80 0 3 4 5 0x00500d20 +texture 80 1 3 4 5 0x00500d27 +texture 80 3 3 4 5 0x00500d24 +texture 80 4 3 4 5 0x00500d24 +texture 80 5 3 4 5 0x00500d26 +texture 80 2 0 4 5 0x00500d04 +texture 80 2 1 4 5 0x00500d3c +texture 80 2 2 4 5 0x00500d24 +texture 80 2 4 4 5 0x00500d24 +texture 80 2 5 4 5 0x00500d34 +texture 80 2 3 0 5 0x00500c24 +texture 80 2 3 1 5 0x00500de4 +texture 80 2 3 2 5 0x00500d24 +texture 80 2 3 3 5 0x00500d24 +texture 80 2 3 5 5 0x00500da4 +texture 80 2 3 4 0 0x00500124 +texture 80 2 3 4 1 0x00500f24 +texture 80 2 3 4 2 0x00500924 +texture 80 2 3 4 3 0x00500924 +texture 80 2 3 4 4 0x00500924 +texture 53 0 3 4 5 0x00351e00 +texture 53 1 3 4 5 0x00351e07 +texture 53 3 3 4 5 0x00351e00 +texture 53 4 3 4 5 0x00351e00 +texture 53 5 3 4 5 0x00351e07 +texture 53 2 0 4 5 0x00351e04 +texture 53 2 1 4 5 0x00351e3c +texture 53 2 2 4 5 0x00351e24 +texture 53 2 4 4 5 0x00351e04 +texture 53 2 5 4 5 0x00351e3c +texture 53 2 3 0 5 0x00351e04 +texture 53 2 3 1 5 0x00351fc4 +texture 53 2 3 2 5 0x00351f04 +texture 53 2 3 3 5 0x00351e04 +texture 53 2 3 5 5 0x00351fc4 +texture 53 2 3 4 0 0x00351004 +texture 53 2 3 4 1 0x00351e04 +texture 53 2 3 4 2 0x00351804 +texture 53 2 3 4 3 0x00351004 +texture 53 2 3 4 4 0x00351004 +texture 252 0 3 4 5 0x00fc1f20 +texture 252 1 3 4 5 0x00fc1f27 +texture 252 3 3 4 5 0x00fc1f24 +texture 252 4 3 4 5 0x00fc1f24 +texture 252 5 3 4 5 0x00fc1f27 +texture 252 2 0 4 5 0x00fc1f04 +texture 252 2 1 4 5 0x00fc1f3c +texture 252 2 2 4 5 0x00fc1f24 +texture 252 2 4 4 5 0x00fc1f24 +texture 252 2 5 4 5 0x00fc1f3c +texture 252 2 3 0 5 0x00fc1e24 +texture 252 2 3 1 5 0x00fc1fe4 +texture 252 2 3 2 5 0x00fc1f24 +texture 252 2 3 3 5 0x00fc1f24 +texture 252 2 3 5 5 0x00fc1fe4 +texture 252 2 3 4 0 0x00fc1124 +texture 252 2 3 4 1 0x00fc1f24 +texture 252 2 3 4 2 0x00fc1924 +texture 252 2 3 4 3 0x00fc1924 +texture 252 2 3 4 4 0x00fc1924 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000000 +sampler 1 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000002 +sampler 0 1 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000004 +sampler 2 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x40000000 +sampler 0 2 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x40000000 +sampler 0 0 1 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000008 +sampler 0 0 2 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000010 +sampler 0 0 0 1 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000020 +sampler 0 0 0 0 1 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000100 +sampler 0 0 0 0 0 1 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000800 +sampler 0 0 0 2 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000040 +sampler 0 0 0 0 2 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000200 +sampler 0 0 0 0 0 2 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00001000 +sampler 0 0 0 3 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000060 +sampler 0 0 0 0 3 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000300 +sampler 0 0 0 0 0 3 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00001800 +sampler 0 0 0 4 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000080 +sampler 0 0 0 0 4 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000400 +sampler 0 0 0 0 0 4 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00002000 +sampler 0 0 0 5 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x000000a0 +sampler 0 0 0 0 5 0 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00000500 +sampler 0 0 0 0 0 5 0 1 0x00000000 0x7f7fffff 0 1 0 0 0x00002800 +sampler 0 0 0 0 0 0 1 1 0x00000000 0x7f7fffff 0 1 0 0 0x00004000 +sampler 0 0 0 0 0 0 2 1 0x00000000 0x7f7fffff 0 1 0 0 0x00008000 +sampler 0 0 0 0 0 0 0 0 0x00000000 0x7f7fffff 0 1 0 0 0x00000001 +sampler 0 0 0 0 0 0 0 1 0x3e800000 0x7f7fffff 0 1 0 0 0x00000000 +sampler 0 0 0 0 0 0 0 1 0x3f000000 0x7f7fffff 0 1 0 0 0x00000000 +sampler 0 0 0 0 0 0 0 1 0x3f040000 0x7f7fffff 0 1 0 0 0x00400000 +sampler 0 0 0 0 0 0 0 1 0x3f080000 0x7f7fffff 0 1 0 0 0x00400000 +sampler 0 0 0 0 0 0 0 1 0x3f800000 0x7f7fffff 0 1 0 0 0x00400000 +sampler 0 0 0 0 0 0 0 1 0x3fb33333 0x7f7fffff 0 1 0 0 0x00400000 +sampler 0 0 0 0 0 0 0 1 0x3fcccccd 0x7f7fffff 0 1 0 0 0x00800000 +sampler 0 0 0 0 0 0 0 1 0x40300000 0x7f7fffff 0 1 0 0 0x00c00000 +sampler 0 0 0 0 0 0 0 1 0x41680000 0x7f7fffff 0 1 0 0 0x03800000 +sampler 0 0 0 0 0 0 0 1 0x4169999a 0x7f7fffff 0 1 0 0 0x03c00000 +sampler 0 0 0 0 0 0 0 1 0x41700000 0x7f7fffff 0 1 0 0 0x03c00000 +sampler 0 0 0 0 0 0 0 1 0x42c80000 0x7f7fffff 0 1 0 0 0x03c00000 +sampler 0 0 0 0 0 0 0 1 0x7f7fffff 0x7f7fffff 0 1 0 0 0x03c00000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x00000000 0 1 0 0 0x3c000000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x3f000000 0 1 0 0 0x3c000000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x3f040000 0 1 0 0 0x38000000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x3f080000 0 1 0 0 0x38000000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x4079999a 0 1 0 0 0x2c000000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x41600000 0 1 0 0 0x04000000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x4169999a 0 1 0 0 0x00000000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x41700000 0 1 0 0 0x00000000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x447a0000 0 1 0 0 0x00000000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 1 1 0 0 0x00000000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 2 0 0 0x00200000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 3 0 0 0x00200000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 16 0 0 0x00200000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 1 0 0x00010000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 2 0 0x00020000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 3 0 0x00030000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 4 0 0x00040000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 5 0 0x00050000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 6 0 0x00060000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 7 0 0x00070000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 1 0x00080000 +sampler 0 0 0 0 0 0 0 1 0x00000000 0x7f7fffff 0 1 0 2 0x00100000 +sampler 1 2 2 2 3 5 2 0 0x40300000 0x41140000 1 8 6 2 0x58f6ab53 diff --git a/docs/RESOURCE-ID.md b/docs/RESOURCE-ID.md new file mode 100644 index 000000000..1e6c45935 --- /dev/null +++ b/docs/RESOURCE-ID.md @@ -0,0 +1,85 @@ +# Resource IDs + +A Metal texture's or sampler's `gpuResourceID` is a 64-bit value that a shader reads from an +argument buffer or a buffer of its own and then samples, reads or writes through. Under the +translator's identity binding domains the ID is computed on the guest's side, with no round trip +to the runtime, from the index the consumer grants and the object's Metal descriptor: + +```text +gpuResourceID = index | word << 32 +``` + +The low 32 bits are the index into the pipeline's heap arrays (set 1, [API.md](API.md) section 5); +the high 32 bits are the word, which carries what a shader reads of the object beyond its +descriptor. Both are pure functions of what the guest already holds, so the same program produces +the same IDs on every run, and a replay reproduces them. + +## Index classes + +| Index | Object | Arrays it is valid in | +|---|---|---| +| 0 | nil (the ID 0) | none | +| 1 to 4,095 | a storage-capable texture: usage with `MTLTextureUsageShaderWrite`, or `MTLTextureUsageUnknown` | the sampled-image array and the storage-image array | +| 4,096 to 65,535 | any other texture | the sampled-image array | +| 1 to 3,999 | a sampler | the sampler array | + +A texture view takes its own index, in the class of its own usage. A texture buffer has no index: +it is a typed refusal under these domains. + +## The texture word + +`metal2vulkan::metal::resource_word::TextureWord::of(pixelFormat, swizzle)`: + +| Bits | Field | +|---|---| +| 0-11 | the border texels: bit `3c + b` is set where channel `c` (0 red, 1 green, 2 blue, 3 alpha) reads 1 rather than 0 outside the level for border color `b` (`MTLSamplerBorderColor`'s raw value) | +| 12 | the format has no alpha, so an out-of-bounds `read` reads alpha 1 | +| 13-15 | 0 | +| 16-31 | the `MTLPixelFormat` raw value | + +The border texels are taken after the swizzle. A color format's channels are its own, a missing +red, green or blue reads 0 and a missing alpha reads 1; `A8Unorm`'s alpha is the color's red; a +format held rotated (`ARGB8Unorm`) reads red from the color's green, green from its blue, blue from +its alpha and alpha from its red; a depth or stencil format reads as red, green and blue, alpha 1. +Every pixel format's raw value is above 0, so a texture's word is never 0. The placeholders +(`Invalid`, `Unspecialized`) and the formats the translator holds no texture of or only copies have +no word. + +## The sampler word + +`metal2vulkan::metal::sampler::SamplerWord::of(descriptor)`. Each field holds its +`MTLSamplerDescriptor` value's raw Metal value, so the default descriptor's word is 0: + +| Bits | Field | +|---|---| +| 0 | `normalizedCoordinates` is false | +| 1 | `minFilter` is `Linear` | +| 2 | `magFilter` is `Linear` | +| 3-4 | `mipFilter` | +| 5-7, 8-10, 11-13 | `sAddressMode`, `tAddressMode`, `rAddressMode` | +| 14-15 | `borderColor` | +| 16-18 | `compareFunction` | +| 19-20 | `reductionMode` | +| 21 | `maxAnisotropy` is above 1 | +| 22-25 | the level a nearest mip filter reads at `lodMinClamp` | +| 26-29 | 15 less the level a nearest mip filter reads at `lodMaxClamp` | +| 30 | `minFilter` or `magFilter` is `Cubic` | +| 31 | 0 | + +The level a nearest mip filter reads at a clamp `c`: take `c` below 0 as 0, and below 64 truncate +it onto sixty-fourths of a level; if the result is 15 or more the level is 15; otherwise, with `L` +its whole levels and `q` its fraction, the level is `L + 1` where `q` is above one half, else `L`. +The LOD clamps themselves, `lodAverage` and the anisotropy's degree are not in the word: the +Vulkan sampler applies them. + +## Test vectors + +[`crates/metal2vulkan/tests/resource_words.tsv`](../crates/metal2vulkan/tests/resource_words.tsv) +holds one descriptor per line with its word, in tab-separated raw Metal values; its header names +the columns. A texture line is a pixel format and its four swizzle sources; a sampler line is every +`MTLSamplerDescriptor` field above, with `lodMinClamp` and `lodMaxClamp` as the float's IEEE-754 +bits. Words are hexadecimal. + +The translator's tests (`tests/resource_words.rs`) recompute every line's word and hold the file +equal to what the word functions generate, so a changed word changes the file. A guest's own +computation of the words checks itself against the same file.