Translator: the lowering's unnormalized-sampler and heap-flag paths nothing reaches are deleted
The second half of the cleanup after the resident core's deletion (0ce2f39b71): crate-private lowering paths whose inputs nothing sets, and the docs that still describe deleted machinery. Unnormalized constexpr samplers. No selection picks PixelPosition::Unnormalized or UnnormalizedTexel (pixel_position answers Scaled, Texel, TexelBySpec or TexelByWord), so they go with BindingKey::unnormalized, PixelPosition::unnormalized(), emit's two coordinate arms and two offset matches, the sampler.pixel_unnormalized and sampler.pixel_unnormalized_gather census arms, pixel_note's and centre_denormals' arms, finish()'s invariant for an unnormalized identity sampling, and constexpr_desc's zero bias for a SamplerUse of unnormalized coordinates, which no constexpr sampler's use is. The runtime's unnormalized twins of linear pixel samplers (SamplerUse::unnormalized, vk_sampler's form, offset_texels) stay. Heap handle flags. AccessPlan's heap_class_index, heap_red_blue and heap_unreadable had no setter; only heap_alpha is set. They go with carries_class(), Lookup::Flagged's class, red_blue and unreadable fields (Flagged is now the alpha-carrying form alone), the handle constants FLAG_TEXEL_CLASS, FLAG_RED_BLUE, FLAG_STORAGE_UNREADABLE, HANDLE_TEXEL_CLASS, HANDLE_RED_BLUE and HANDLE_STORAGE_UNREADABLE, the sampler.heap.texel_class census arm, heap_element_of's unreadable branch (its one caller passed false), and identity_refusal's HeapResource refusal of a flagged form other than the alpha's, which could not fire. The handle-table search, which only the function-table directory calls, in its element and entry forms, keeps its generic carry of the alpha flag: Lookup is shared with the identity handle's form, whose element mask the heap accesses read. Docs that named deleted items now say what the code does: the PixelSamplerScaling entry (a constexpr pixel sampler's linear sample or gather records it on every device; the runtime slot's nearest test is its word, SamplerWord::nearest_pixel, not a specialization), ViewBaseTexelOffset (no heap_raw; a slot's footprint placed so is refused, IdentityCause::TextureState), SimdgroupAccessOrder (no resident-table profile), constexpr.rs, memory::handles (heap handles are the identity arrays' elements; the handle table is the function-table directory's search), bind::heap, lower::texture (is_null, border texels, level views and the out-of-bounds alpha come from the resource ID's word), heap_raw's mentions in the sampler modules, the resident-table mentions in access::object, provenance::objects and validation's tier table, the OpenCL line variant's docs (the runtime refuses such a binding, Gap::OpenClLineTexture), and PushField's TextureLevels. SlotPlan::border_texels, never set, goes. Tests: engine_identity's expected lookup is Lookup::Flagged; the search's host-model test runs the element, flagged and entry forms; the census assertions of sampler.pixel_unnormalized, which no arm names now, go. Consumer: in reims at 7d016acc9c, and at 8f3ca9df99, nothing names a crate-private item here (lower and memory are pub(crate)), and the public-item search is the previous commit's. Nothing compiled changes: no selection reached the deleted arms, no flag was set, and the census words of every plan are the same, so SEMANTICS_VERSION and ARTIFACT_FORMAT_VERSION stay. runtime-sources.sha256 moves without a RUNTIME_VERSION bump: memory/handles.rs loses constants and fields nothing set, and metal/sampler.rs, metal/texel_format.rs, metal/format/mod.rs and bind/heap.rs change in comments and a test. docs/REFUSALS.md regenerates unchanged; the signature table is unchanged. Verified, on the CPU with no device: - m3-max-86179, at the series' tip (the two cleanup commits and the README line): fmt, the refusal surface's, the signatures', both coverage docs' and scripts/api-docs' checks, clippy (plain, --cfg m2v_gpu, --cfg m2v_cpu_icd), Rustdoc, private docs (metal2vulkan and metal2vulkan-runtime) and doctests pass. The metal2vulkan suites ran 3,492 tests: 3,491 passed, 24 skipped, and the failure is golden_hashes_match_the_table, which fails at the base too (a bless due at the next pin). Validation ran 1,343 tests, all passed, 2 skipped; conformance ran 1,061, all passed. - m3-max-86194 and m3-max-86213, at the tip and at its basedb7bedc60d: the golden table's changed lines are the same 5,114 at both, line for line, so no cell moves.
This commit is contained in:
1 parent
27a6c1ebd3
commit
8fb26059c7
32 files changed
+284
-617
No files matched your search
@@ -1 +1 @@
|
||||
37e49e9dfc20120c254fc8ba13788ad0bb51721c8ce9e5c9249f9bf42d3cf713
|
||||
59e88d1199c8cb7978cb06359ff600b743afe11d5a9cd5dd5c2f7e8e0e08c63f
|
||||
@@ -50,9 +50,9 @@ impl TierProfile {
|
||||
}
|
||||
}
|
||||
|
||||
/// A tier-table entry: a committed profile in one leg, and the profile lowering compiles for: the
|
||||
/// resident-table domains, whose containment mechanisms (the root table, descriptor views, the
|
||||
/// robustness legs) these tests check.
|
||||
/// A tier-table entry: a committed profile in one leg, and the profile lowering compiles for,
|
||||
/// whose containment mechanisms (the root table, descriptor views, the robustness legs) these
|
||||
/// tests check.
|
||||
pub struct CommittedProfile {
|
||||
pub tier: TierProfile,
|
||||
pub profile: DeviceProfile,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
//! The set-1 heap's classes, as the lowering reads them.
|
||||
//!
|
||||
//! The heap arrays on a profile are of the image classes the core can declare and the four
|
||||
//! sampler classes. The texture lowering declares the handle table (`Synthetic(HandleTable)`, one
|
||||
//! per stage that loads a heap texture) and one heap array per class a heap texture reaches, and
|
||||
//! link numbers them (set 1 for the arrays). The consumer writes the arrays and the tables; this
|
||||
//! module holds what the lowering decides from a class:
|
||||
//! sampler classes. The texture lowering declares one heap array per class a heap texture reaches,
|
||||
//! and link numbers them (set 1). The consumer writes the arrays; this module holds what the
|
||||
//! lowering decides from a class:
|
||||
//!
|
||||
//! - [`fit`]: how a texture fits a class's array: the Metal texture type's dimension,
|
||||
//! arrayedness, and multisampling, a sample count above 1 exactly when multisampled, the numeric
|
||||
@@ -298,8 +297,7 @@ fn member_storage_format(
|
||||
};
|
||||
// The declaration names no format, so the member's format must serve those accesses
|
||||
// without one. Where the formats' own bits alone grant a read, a member whose view's
|
||||
// format lacks the read bit is held for its writes and flagged
|
||||
// (`memory::handles::FLAG_STORAGE_UNREADABLE`).
|
||||
// format lacks the read bit is held for its writes.
|
||||
let gaps = without_format_gaps(format, use_, profile);
|
||||
if !gaps.is_empty() {
|
||||
return Err(BindError::Unsupported(Unsupported::needs_any_of(
|
||||
@@ -335,8 +333,7 @@ fn storage_read_gaps(
|
||||
/// (`device::metal::read_write_tier_formats`), whose `read_write` reads Metal's contract defines:
|
||||
/// each such view's [`storage_read_gaps`], so empty but where the profile reads storage without a
|
||||
/// format by the formats' own bits alone. A function that reads the array through a handle needs
|
||||
/// them (`lower::texture::slot`): without them it would read such a member as
|
||||
/// the null element (`memory::handles::FLAG_STORAGE_UNREADABLE`).
|
||||
/// them (`lower::texture::slot`): without them it would read such a member as the null element.
|
||||
pub(crate) fn tier_read_gaps(
|
||||
profile: &DeviceProfile,
|
||||
class: &ImageHandleClass,
|
||||
@@ -397,7 +394,7 @@ pub(crate) struct StorageConversion {
|
||||
/// handle carries.
|
||||
pub index: u32,
|
||||
/// Its pixel format is blue-first (`metal::format::red_blue_exchanged`), which its handle
|
||||
/// carries (`memory::handles::FLAG_RED_BLUE`).
|
||||
/// carries.
|
||||
pub red_blue: bool,
|
||||
/// The conversion: `SwizzleBgra` exchanges red and blue, `SrgbEncode` decodes and encodes the
|
||||
/// sRGB codes of the color lanes by the device's transfer, `SrgbEncodeBgra` both.
|
||||
|
||||
Vendored
+6
-6
@@ -245,8 +245,7 @@ pub struct VariantKey {
|
||||
/// than the default) whose texels the function reads or writes
|
||||
/// (`LoweringInputs::swizzled_storage`): a Vulkan storage view takes no swizzle, so the
|
||||
/// function applies the bound texture's swizzle to its reads and undoes it on its writes, as
|
||||
/// plain Metal does, under the slot's `SpecKey::TextureSwizzle`, and the slot's storage view
|
||||
/// takes none. It holds too each sampled slot of
|
||||
/// plain Metal does, and the slot's storage view takes none. It holds too each sampled slot of
|
||||
/// `extended_range` bound to such a texture whose texels the function reads or samples: its
|
||||
/// view holds raw codes, so the function swizzles the decoded texels and the view takes none.
|
||||
/// So does, on a device without Metal's own sampler, each sampled slot bound to a swizzled
|
||||
@@ -281,10 +280,11 @@ pub struct VariantKey {
|
||||
/// a list's base vertex cannot carry (`RuntimeFact::PrivateList`).
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub private_list: bool,
|
||||
/// The texture slots of a kernel of OpenCL mode whose `RuntimeFact::OpenClLineTexture` (a 1D
|
||||
/// image it reads as the 2D texture of height 1 Apple's OpenCL binds) the shape binds a 1D or
|
||||
/// 1D array texture at (`LoweringInputs::open_cl_lines`): the variant's kernel declares each
|
||||
/// as that 1D texture and reads it.
|
||||
/// The texture slots of a kernel of OpenCL mode, each a 1D image it reads as the 2D texture of
|
||||
/// height 1 Apple's OpenCL binds, that the shape binds a 1D or 1D array texture at
|
||||
/// (`LoweringInputs::open_cl_lines`): the variant's kernel declares each as that 1D texture and
|
||||
/// reads it. `metal2vulkan-runtime` asks for none: it refuses such a binding
|
||||
/// (`Gap::OpenClLineTexture`).
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub open_cl_lines: BTreeSet<SlotRef>,
|
||||
/// The render pipeline draws a rasterization-rate-mapped pass's regions several at a time,
|
||||
|
||||
@@ -1231,7 +1231,7 @@ pub fn emit(
|
||||
/// below the set-1 image arrays' length (`pipeline::link::IDENTITY_TEXTURES`, a power of two), the
|
||||
/// element of those arrays (0, nil, the null descriptor), with the word's missing-alpha bit
|
||||
/// (`TextureWord::OUT_OF_BOUNDS_ALPHA_ONE`) moved to `HANDLE_ALPHA_ONE` where the function's
|
||||
/// handles carry it (`memory::handles::Lookup::Flagged`'s `alpha`), and the word's low bits
|
||||
/// handles carry it (`memory::handles::Lookup::Flagged`), and the word's low bits
|
||||
/// above the index where the function reads an argument buffer's texture through a sampler, whose
|
||||
/// border texels they hold (`AccessPlan::heap_border`), or samples, gathers or reads an argument
|
||||
/// buffer's texture as a `float` sampled image, with `lower::texture::extended_unorm`'s
|
||||
@@ -1253,7 +1253,7 @@ fn emit_identity_handle(
|
||||
let index = fb.binary(BinOp::BitwiseAnd, low, mask)?;
|
||||
let h = match cx.plan.families.access.lookup() {
|
||||
handles::Lookup::Element => index,
|
||||
handles::Lookup::Flagged { alpha: true, .. } => {
|
||||
handles::Lookup::Flagged => {
|
||||
let word = fb.composite_extract(id, &[1])?;
|
||||
let shift = handles::HANDLE_ALPHA_ONE.trailing_zeros()
|
||||
- TextureWord::OUT_OF_BOUNDS_ALPHA_ONE.trailing_zeros();
|
||||
|
||||
@@ -811,27 +811,15 @@ pub struct AccessPlan {
|
||||
/// slot is a device-address slot, and a slot's Metal address is its root entry's `guest +
|
||||
/// bind_offset` ([`replay_guest_base`]), never a `SlotGuestBase` push field.
|
||||
pub replay: bool,
|
||||
/// A heap read the shader checks observes its texel's alpha (`lower::texture`): the
|
||||
/// handle-table search carries the alpha (`memory::handles::Lookup::Flagged`), so every heap
|
||||
/// handle carries its entry's out-of-bounds-alpha flag beside its element.
|
||||
/// A heap read the shader checks observes its texel's alpha (`lower::texture`): every heap
|
||||
/// handle carries its texture's out-of-bounds-alpha flag beside its element
|
||||
/// (`memory::handles::Lookup::Flagged`), from the resource ID's word
|
||||
/// (`access::handle::emit_identity_handle`).
|
||||
pub heap_alpha: bool,
|
||||
/// Some visible-function table is read by its resource id ([`function_table`]): the function
|
||||
/// reads the stage's function-table directory, one more storage descriptor, whose search reads
|
||||
/// the ids as this states, and the stage's function-table snapshot, one more again.
|
||||
pub function_tables: Option<function_table::TableReads>,
|
||||
/// A heap texture's float write the function makes tests its texel class's index
|
||||
/// (`lower::texture::emit`): the handle-table search carries the index
|
||||
/// (`memory::handles::Lookup::Flagged`), so every heap handle carries it beside its element.
|
||||
pub heap_class_index: bool,
|
||||
/// A heap storage access the function makes converts a member by its texel class and its
|
||||
/// red-blue order (`lower::texture::heap_storage_conversions`): the handle-table search
|
||||
/// carries the entry's `FLAG_RED_BLUE` too (`memory::handles::Lookup::Flagged`).
|
||||
pub heap_red_blue: bool,
|
||||
/// A heap storage read the function makes on a device that reads storage without a format by
|
||||
/// the formats' own bits alone reads the null element where the handle carries the entry's
|
||||
/// `FLAG_STORAGE_UNREADABLE` (`lower::texture::emit`): the handle-table search carries it
|
||||
/// (`memory::handles::Lookup::Flagged`).
|
||||
pub heap_unreadable: bool,
|
||||
/// A heap texture's read through a sampler may hand back its border texels
|
||||
/// (`lower::texture::Through`), which bits 0-11 of the texture's resource ID's word hold
|
||||
/// (`docs/RESOURCE-ID.md`), as they do a slot's: each heap handle carries its word's low bits
|
||||
@@ -849,25 +837,13 @@ pub struct AccessPlan {
|
||||
}
|
||||
|
||||
impl AccessPlan {
|
||||
/// Whether the handle-table search carries each heap handle's texel class index.
|
||||
pub fn carries_class(&self) -> bool {
|
||||
self.heap_class_index
|
||||
}
|
||||
|
||||
/// What the function's handle-table search yields.
|
||||
/// The form of the function's heap texture handles: flagged where they carry the
|
||||
/// out-of-bounds alpha ([`heap_alpha`](Self::heap_alpha)).
|
||||
pub fn lookup(&self) -> crate::memory::handles::Lookup {
|
||||
use crate::memory::handles::Lookup;
|
||||
let (alpha, class, red_blue) = (self.heap_alpha, self.carries_class(), self.heap_red_blue);
|
||||
let unreadable = self.heap_unreadable;
|
||||
if alpha || class || red_blue || unreadable {
|
||||
Lookup::Flagged {
|
||||
alpha,
|
||||
class,
|
||||
red_blue,
|
||||
unreadable,
|
||||
}
|
||||
} else {
|
||||
Lookup::Element
|
||||
match self.heap_alpha {
|
||||
true => Lookup::Flagged,
|
||||
false => Lookup::Element,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,9 @@
|
||||
//!
|
||||
//! **Encoder operations** ([`select`]). This module lowers none. Under the identity domains the
|
||||
//! operations `icb` lowers (a render command's buffer setters, its indexed triangle draw and a
|
||||
//! reset) are selected there, before this module; every other encoder operation, and every one
|
||||
//! under the resident-table domains, is `Unsupported{GpuEncodedIndirectCommands, NotImplemented}`,
|
||||
//! and one whose command is not an object word is `Unsupported{ArgumentBufferObjects,
|
||||
//! NotImplemented}`.
|
||||
//! reset) are selected there, before this module; every other encoder operation is
|
||||
//! `Unsupported{GpuEncodedIndirectCommands, NotImplemented}`, and one whose command is not an
|
||||
//! object word is `Unsupported{ArgumentBufferObjects, NotImplemented}`.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
@@ -11,10 +11,9 @@
|
||||
//! with a texel depends on the bound pixel format, which an immutable `VK_FILTER_CUBIC_EXT` sampler
|
||||
//! cannot follow (and no committed profile has `VK_EXT_filter_cubic`); a gather through a bicubic
|
||||
//! sampler ignores the filter, so the `VkSampler` of a bicubic sampler has nearest filters and its
|
||||
//! address modes. Pixel coordinates are a sampler property on the Vulkan side only where a binding
|
||||
//! reads them through the device's unnormalized sampler (`SamplerUse::unnormalized`, a linear
|
||||
//! sample's); elsewhere the shader hands a pixel coordinate over the texture's size to a normalized
|
||||
//! `VkSampler` (`lower::sampler`'s pixel coordinates).
|
||||
//! address modes. A constexpr sampler's `VkSampler` is normalized whatever its coordinates: the
|
||||
//! shader hands a pixel coordinate over the texture's size to it (`lower::sampler`'s pixel
|
||||
//! coordinates).
|
||||
|
||||
use crate::air::abi::{
|
||||
AddressMode, BorderColor, CompareFunction, Coordinates, Filter, MipFilter, Reduction,
|
||||
@@ -240,11 +239,7 @@ pub fn constexpr_desc(
|
||||
) -> Result<vk::SamplerDesc, Error> {
|
||||
let s = state_of(words)?;
|
||||
let mut desc = crate::metal::sampler::vk_sampler(&descriptor(&s)?, use_, profile)?;
|
||||
// A sampler that reads texel coordinates reads level 0 by one filter: a bias selects nothing.
|
||||
let bias = match use_.unnormalized {
|
||||
true => 0.0,
|
||||
false => s.lod_bias.to_f32(),
|
||||
};
|
||||
let bias = s.lod_bias.to_f32();
|
||||
if bias.is_nan() {
|
||||
return Err(Unsupported::not_representable(Feature::SamplerLodBias).into());
|
||||
}
|
||||
|
||||
@@ -1022,15 +1022,9 @@ fn device_sampled_value(
|
||||
return with_word(cx, fb, &s.result, x, None);
|
||||
}
|
||||
let (mut coord, mut grad) = plane_and_gradients(cx, fb, s, grads)?;
|
||||
// Pixel coordinates: the plane coordinate (or its texel's centre) moved by its offset to the
|
||||
// device's unnormalized sampler; or the plane coordinate (or its texel's centre) and any
|
||||
// gradient over the level-0 size, always or behind the runtime sampler's word.
|
||||
if s.position == PixelPosition::UnnormalizedTexel {
|
||||
let centre = placed(fb, coord, s.lanes, Centre::Texel)?;
|
||||
coord = offset_texels(cx, fb, s, centre)?;
|
||||
} else if s.position == PixelPosition::Unnormalized {
|
||||
coord = offset_texels(cx, fb, s, coord)?;
|
||||
} else if let Some(spec) = pixel_coordinates(cx, fb, s)? {
|
||||
// Pixel coordinates: the plane coordinate (or its texel's centre) and any gradient over the
|
||||
// level-0 size, always or behind the runtime sampler's word.
|
||||
if let Some(spec) = pixel_coordinates(cx, fb, s)? {
|
||||
let img = fb.image(si)?;
|
||||
let zero = fb.u32_const(0)?;
|
||||
let zero = fb.module().const_value(zero)?;
|
||||
@@ -1057,11 +1051,6 @@ fn device_sampled_value(
|
||||
min_lod,
|
||||
offset,
|
||||
} => {
|
||||
// The device's unnormalized sampler takes no offset operand: the coordinate holds it.
|
||||
let offset = match s.position.unnormalized() {
|
||||
true => &None,
|
||||
false => offset,
|
||||
};
|
||||
let (ops, dref, beyond) = sample_operands(
|
||||
cx,
|
||||
fb,
|
||||
@@ -1105,11 +1094,6 @@ fn device_sampled_value(
|
||||
dref,
|
||||
offset,
|
||||
} => {
|
||||
// The device's unnormalized sampler's coordinate holds its offset.
|
||||
let offset = match s.position.unnormalized() {
|
||||
true => &None,
|
||||
false => offset,
|
||||
};
|
||||
let mut ops = ImageOperands::default();
|
||||
offset_operands(cx, fb, offset, s.lanes, &mut ops)?;
|
||||
let component = *component;
|
||||
@@ -1385,10 +1369,9 @@ fn offset_texels(
|
||||
fb.binary(BinOp::FAdd, x, k)
|
||||
}
|
||||
|
||||
/// The [`Centre`] of sampling `s` of `image`: through a runtime sampler slot its texel's centre
|
||||
/// where the slot's `NearestPixelSampler` specialization holds, through an argument buffer's
|
||||
/// sampler where its table entry's word states a nearest pixel sampler of one isotropic level
|
||||
/// (`SamplerWord::nearest_pixel`; any filter of an integer texture).
|
||||
/// The [`Centre`] of sampling `s` of `image`: through a runtime sampler slot or an argument
|
||||
/// buffer's sampler its texel's centre where its word states a nearest pixel sampler of one
|
||||
/// isotropic level (`SamplerWord::nearest_pixel`; any filter of an integer texture).
|
||||
pub(super) fn centre(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
@@ -1396,9 +1379,7 @@ pub(super) fn centre(
|
||||
image: CombinedImage,
|
||||
) -> BResult<Centre> {
|
||||
Ok(match s.position {
|
||||
PixelPosition::Scaled | PixelPosition::Unnormalized | PixelPosition::UnnormalizedTexel => {
|
||||
Centre::None
|
||||
}
|
||||
PixelPosition::Scaled => Centre::None,
|
||||
PixelPosition::Texel => Centre::Texel,
|
||||
PixelPosition::TexelBySpec => {
|
||||
let Pixel::Spec(_) = s.pixel else {
|
||||
|
||||
@@ -163,8 +163,8 @@
|
||||
//! from 446,777 words made in 7.1 to 9.6 s with the code at each site to 259,809 words made in 2.8
|
||||
//! to 4.8 s), and a driver that inlines every call compiles a copy per sample either way. The
|
||||
//! known loss: on ANV (the Iris Xe) the routine made the same variant in 18.0 to 18.3 s against the
|
||||
//! site code's 17.6 to 17.7 s, 2 to 3% slower to create. A heap element's sample (`heap_raw`) is
|
||||
//! its site's own code.
|
||||
//! site code's 17.6 to 17.7 s, 2 to 3% slower to create. A heap element's sample is its site's own
|
||||
//! code.
|
||||
|
||||
use crate::air::abi::{BorderColor, MipFilter, SamplerState};
|
||||
use crate::air::ir::ValueId;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! What the device-sampled filters share with the emulated ones the device has no form for
|
||||
//! (`extended`, `heap_raw`, `bicubic`): the census words of a filter's footprint and
|
||||
//! of a runtime sampler's word, the rule of an axis whose two taps read one texel ([`merged`]), and
|
||||
//! the samplers that read one texel of one level ([`unfiltered`]).
|
||||
//! (`extended`, `bicubic`): the census words of a filter's footprint and of a runtime sampler's
|
||||
//! word, the rule of an axis whose two taps read one texel ([`merged`]), and the samplers that read
|
||||
//! one texel of one level ([`unfiltered`]).
|
||||
//!
|
||||
//! Every filtered sample of a format the device samples is the device's own
|
||||
//! (`VkProperty::DeviceSampling`, recorded as `PrecisionNote::DeviceSampling`).
|
||||
|
||||
@@ -211,15 +211,12 @@ impl FamilyStrategy for SamplerStrategy {
|
||||
}
|
||||
|
||||
/// One combined image-sampler binding of the function, before its texture's numeric type is
|
||||
/// final: the texture slot index, the sampler, whether it samples with comparison, and whether it
|
||||
/// reads a pixel sampler's texel coordinates through the device's unnormalized sampler
|
||||
/// ([`PixelPosition::unnormalized`]).
|
||||
/// final: the texture slot index, the sampler, and whether it samples with comparison.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct BindingKey {
|
||||
pub texture: u32,
|
||||
pub sampler: SamplerRef,
|
||||
pub compare: bool,
|
||||
pub unnormalized: bool,
|
||||
}
|
||||
|
||||
/// One separate heap sampler use: heap group `group` sampled through `sampler`, with comparison or
|
||||
@@ -258,8 +255,7 @@ pub struct ConstexprArray {
|
||||
pub first: u32,
|
||||
/// Each element's canonical state words (`SamplerRef::Constexpr`).
|
||||
pub samplers: Vec<[u64; 2]>,
|
||||
/// Each element's sampler word (`metal::sampler::SamplerWord`), which a sampling reads where
|
||||
/// the element's state decides what it does (`heap_raw::State::Table`).
|
||||
/// Each element's sampler word (`metal::sampler::SamplerWord`).
|
||||
pub words: Vec<u32>,
|
||||
}
|
||||
|
||||
@@ -573,44 +569,21 @@ pub enum Pixel {
|
||||
pub enum PixelPosition {
|
||||
/// `x / N`: the device reads its texels and weights from the quotient in its own arithmetic
|
||||
/// (`PrecisionNote::PixelSamplerScaling`, `PrecisionNote::ArgumentPixelSamplerScaling`). A
|
||||
/// linear filter's sample and a gather the device's unnormalized sampler does not take, and a
|
||||
/// level query.
|
||||
/// linear filter's sample, a gather, and a level query.
|
||||
Scaled,
|
||||
/// `(floor(x) + 0.5) / N`, the centre of the texel Metal's nearest filter reads at `x`: a
|
||||
/// sample through a sampler that filters nearest (or of an integer texture, which every filter
|
||||
/// reads nearest), whose device reads exactly that texel, plus any offset, under its own
|
||||
/// address mode and border.
|
||||
Texel,
|
||||
/// A runtime sampler slot's sample: [`Texel`](Self::Texel) where the slot's
|
||||
/// `NearestPixelSampler` specialization states a nearest pixel sampler of one isotropic level,
|
||||
/// [`Scaled`](Self::Scaled) where its `SamplerState` word states another pixel sampler.
|
||||
/// A runtime sampler slot's sample: [`Texel`](Self::Texel) where the slot's word states a
|
||||
/// nearest pixel sampler of one isotropic level (`SamplerWord::nearest_pixel`),
|
||||
/// [`Scaled`](Self::Scaled) where it states another pixel sampler.
|
||||
TexelBySpec,
|
||||
/// An argument buffer's sampler's sample: [`Texel`](Self::Texel) where the table entry's word
|
||||
/// states a nearest pixel sampler of one isotropic level (`SamplerWord::nearest_pixel`),
|
||||
/// [`Scaled`](Self::Scaled) where it states another pixel sampler.
|
||||
TexelByWord,
|
||||
/// `x` itself, moved by any texel offset (`x + k` in the device's `float` add, exact wherever
|
||||
/// it is a float), to the device's unnormalized sampler (`VkSamplerCreateInfo::
|
||||
/// unnormalizedCoordinates`) at level 0 of a view of the texture's first level: the device's
|
||||
/// own sampler reads its texel, footprint and weights from `x`. A sample or gather without
|
||||
/// comparison through a constexpr pixel sampler that sampler reads as it is
|
||||
/// (`metal::sampler::unnormalized_reads`), of a 1D or 2D texture that is no array
|
||||
/// ([`BindingKey::unnormalized`]), but a nearest
|
||||
/// sample with an offset ([`UnnormalizedTexel`](Self::UnnormalizedTexel)).
|
||||
Unnormalized,
|
||||
/// `floor(x) + 0.5 + k`, the centre of the texel Metal's nearest filter reads at `x` moved by
|
||||
/// the sample's offset `k` (Metal adds it to the texel, where `x + k` in `float` may round
|
||||
/// across the texel's edge), to the device's unnormalized sampler as at
|
||||
/// [`Unnormalized`](Self::Unnormalized): a nearest sample with an offset (or any filter's of an
|
||||
/// integer texture) that would otherwise take `x` itself.
|
||||
UnnormalizedTexel,
|
||||
}
|
||||
|
||||
impl PixelPosition {
|
||||
/// Whether the device's unnormalized sampler takes the coordinate.
|
||||
pub fn unnormalized(self) -> bool {
|
||||
matches!(self, Self::Unnormalized | Self::UnnormalizedTexel)
|
||||
}
|
||||
}
|
||||
|
||||
/// A sampling operation on a combined image sampler, or on a heap element through a heap sampler.
|
||||
@@ -743,21 +716,11 @@ impl Sampling {
|
||||
SampleOp::QueryLevel { .. } => "sampler.heap.query_level",
|
||||
};
|
||||
}
|
||||
// A constexpr pixel sampler's sample and gather of `x` itself through the device's
|
||||
// unnormalized sampler, and its nearest sample at its texel's centre.
|
||||
match (&self.op, self.pixel, self.position) {
|
||||
(
|
||||
SampleOp::Sample { .. },
|
||||
Pixel::Always,
|
||||
PixelPosition::Unnormalized | PixelPosition::UnnormalizedTexel,
|
||||
) => return "sampler.pixel_unnormalized",
|
||||
(SampleOp::Gather { .. }, Pixel::Always, PixelPosition::Unnormalized) => {
|
||||
return "sampler.pixel_unnormalized_gather"
|
||||
}
|
||||
(SampleOp::Sample { .. }, Pixel::Always, PixelPosition::Texel) => {
|
||||
return "sampler.pixel_texel"
|
||||
}
|
||||
_ => {}
|
||||
// A constexpr pixel sampler's nearest sample at its texel's centre.
|
||||
if let (SampleOp::Sample { .. }, Pixel::Always, PixelPosition::Texel) =
|
||||
(&self.op, self.pixel, self.position)
|
||||
{
|
||||
return "sampler.pixel_texel";
|
||||
}
|
||||
match &self.op {
|
||||
SampleOp::Sample {
|
||||
@@ -891,15 +854,10 @@ impl Sampling {
|
||||
};
|
||||
// A pixel coordinate's texel centre: the floor, the shift, and their constants; by a
|
||||
// runtime slot's specialization or an argument buffer's word, also the test and the
|
||||
// selection. Unnormalized coordinates' offset: its conversion and the add.
|
||||
// selection.
|
||||
let centre = match (self.pixel, self.position) {
|
||||
(Pixel::None, _) | (_, PixelPosition::Scaled) => 0,
|
||||
(
|
||||
_,
|
||||
PixelPosition::Texel
|
||||
| PixelPosition::Unnormalized
|
||||
| PixelPosition::UnnormalizedTexel,
|
||||
) => 24,
|
||||
(_, PixelPosition::Texel) => 24,
|
||||
(_, PixelPosition::TexelBySpec | PixelPosition::TexelByWord) => 24 + 32,
|
||||
};
|
||||
// An argument buffer's sampler reads its entry's word for each test of it: its pixel
|
||||
@@ -941,7 +899,6 @@ impl Sampling {
|
||||
+ if self.cube { face::TIE_WORDS } else { 0 }
|
||||
+ match (self.pixel, self.position) {
|
||||
(Pixel::None, _) => 0,
|
||||
(_, p) if p.unnormalized() => 0,
|
||||
_ => 48,
|
||||
}
|
||||
}
|
||||
@@ -1135,11 +1092,6 @@ pub fn finish(cx: &mut SelectCx<'_>) -> Result<(), Error> {
|
||||
x_channel: false,
|
||||
};
|
||||
let refused = || Unsupported::identity(IdentityCause::TextureState);
|
||||
if key.unnormalized {
|
||||
return Err(invariant(
|
||||
"an identity sampling through the device's unnormalized sampler",
|
||||
));
|
||||
}
|
||||
if let SamplerRef::Constexpr(_) = key.sampler {
|
||||
cx.push
|
||||
.insert(crate::pipeline::sym::PushField::ConstexprSampler(sampler));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Metal's texel-space position of a normalized coordinate, which the filters the device has no
|
||||
//! form for read their footprints from (`bicubic`, `extended` and `heap_raw`), and Metal's
|
||||
//! form for read their footprints from (`bicubic` and `extended`), and Metal's
|
||||
//! placement of a texel offset on a repeating or mirrored axis.
|
||||
//!
|
||||
//! **The position** (Apple M3 Max, macOS 26.7, and Apple M4, macOS 27.0.1, byte-identical; the
|
||||
|
||||
@@ -542,18 +542,16 @@ fn select_heap_switch(
|
||||
/// A heap image sampled through one of the constexpr samplers `cands`, chosen by handle
|
||||
/// `smp_handle`, as one sampling through an array of the candidates' samplers
|
||||
/// (`Source::HeapArray`): its element `smp_handle - first` is exactly the sampler of the candidate
|
||||
/// of that handle, and the raw emulation reads that element's state word
|
||||
/// (`heap_raw::State::Table`). Where every candidate is a constexpr sampler,
|
||||
/// their handles consecutive (`first..first + n`); the device indexes an array of samplers by a
|
||||
/// value that may differ between invocations (`shaderSampledImageArrayNonUniformIndexing`, which
|
||||
/// the heap's own image array already needs); the use is not tangled; and each candidate's
|
||||
/// sampling is the same but for its sampler and the state its raw emulation follows. `None`
|
||||
/// otherwise. Under the identity domains no set-0 array holds: the sampling reads the set-1
|
||||
/// sampler array of its use at the pushed index (`PushField::ConstexprSampler`) of the candidate
|
||||
/// the handle names (`emit::identity_element`), and only where the sampling reads a float class,
|
||||
/// without comparison and in normalized coordinates; the switch over the candidates stays for the
|
||||
/// rest. No emulation arises there through Metal's bicubic filter, which an argument buffer's
|
||||
/// texture refuses (`bicubic::check`).
|
||||
/// of that handle. Where every candidate is a constexpr sampler, their handles consecutive
|
||||
/// (`first..first + n`); the device indexes an array of samplers by a value that may differ between
|
||||
/// invocations (`shaderSampledImageArrayNonUniformIndexing`, which the heap's own image array
|
||||
/// already needs); the use is not tangled; and each candidate's sampling is the same but for its
|
||||
/// sampler. `None` otherwise. Under the identity domains no set-0 array holds: the sampling reads
|
||||
/// the set-1 sampler array of its use at the pushed index (`PushField::ConstexprSampler`) of the
|
||||
/// candidate the handle names (`emit::identity_element`), and only where the sampling reads a float
|
||||
/// class, without comparison and in normalized coordinates; the switch over the candidates stays
|
||||
/// for the rest. No emulation arises there through Metal's bicubic filter, which an argument
|
||||
/// buffer's texture refuses (`bicubic::check`).
|
||||
fn select_heap_array(
|
||||
cx: &mut SelectCx<'_>,
|
||||
call: Call<'_>,
|
||||
@@ -1860,7 +1858,6 @@ fn select_one(
|
||||
texture,
|
||||
sampler,
|
||||
compare,
|
||||
unnormalized: position.unnormalized(),
|
||||
};
|
||||
cx.families.sampler.combined.insert(key);
|
||||
Source::Combined(key)
|
||||
@@ -1963,12 +1960,7 @@ fn select_one(
|
||||
&& !shape.depth;
|
||||
let exact = match key.sampler {
|
||||
SamplerRef::Slot(n) if pixel == Pixel::Spec(n) && n < 16 => {
|
||||
plain_op
|
||||
&& plane
|
||||
&& !integer
|
||||
&& !key.compare
|
||||
&& !key.unnormalized
|
||||
&& !offset_base
|
||||
plain_op && plane && !integer && !key.compare && !offset_base
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
@@ -2045,14 +2037,14 @@ fn clamps_reference(
|
||||
|
||||
/// Where a sampling through a sampler of pixel coordinates `pixel` hands the device a coordinate
|
||||
/// scaled by the texture's level-0 size, whose texels the device's sampler decides
|
||||
/// (`PrecisionNote::PixelSamplerScaling`): the clauses of the arms that do (empty: none). Neither
|
||||
/// `x` itself to the device's unnormalized sampler nor a texel's centre (`position`) is such a
|
||||
/// coordinate: the device reads exactly Metal's texel from a centre, and its own footprint from `x`.
|
||||
/// (`PrecisionNote::PixelSamplerScaling`): the clauses of the arms that do (empty: none). A
|
||||
/// texel's centre (`position`) is no such coordinate: the device reads exactly Metal's texel from
|
||||
/// it.
|
||||
///
|
||||
/// - A constexpr pixel sampler: always (its exact fetch, `SampleOp::PixelFetch`, reaches here with
|
||||
/// [`Pixel::None`]).
|
||||
/// - A runtime sampler slot: where its word states pixel coordinates, and, for a sample at its
|
||||
/// texel's centre by its `NearestPixelSampler` specialization ([`PixelPosition::TexelBySpec`]),
|
||||
/// texel's centre by its word (`SamplerWord::nearest_pixel`, [`PixelPosition::TexelBySpec`]),
|
||||
/// where that does not hold.
|
||||
/// - An argument buffer's sampler ([`PrecisionNote::ArgumentPixelSamplerScaling`]): always, since
|
||||
/// its word, which the specialized module cannot read, may state pixel coordinates (through a
|
||||
@@ -2061,7 +2053,6 @@ fn clamps_reference(
|
||||
fn pixel_note(pixel: Pixel, position: PixelPosition) -> bool {
|
||||
match (pixel, position) {
|
||||
(Pixel::None, _) | (_, PixelPosition::Texel) => false,
|
||||
(_, p) if p.unnormalized() => false,
|
||||
(Pixel::Always | Pixel::Heap(_) | Pixel::Spec(_), _) => true,
|
||||
}
|
||||
}
|
||||
@@ -2073,8 +2064,8 @@ fn pixel_note(pixel: Pixel, position: PixelPosition) -> bool {
|
||||
/// texel 0: an address mode that reads texel -1 as texel 0 ([`centre_parts`] false: clamp to edge,
|
||||
/// mirror clamp to edge, mirrored repeat) answers alike. So:
|
||||
///
|
||||
/// - a constexpr sampler's centre ([`PixelPosition::Texel`], [`PixelPosition::UnnormalizedTexel`]):
|
||||
/// where its `s` or `t` mode parts the two texels;
|
||||
/// - a constexpr sampler's centre ([`PixelPosition::Texel`]): where its `s` or `t` mode parts the
|
||||
/// two texels;
|
||||
/// - a runtime sampler slot's, where its word may state pixel coordinates (an integer texture's
|
||||
/// centre, [`PixelPosition::Texel`], or [`PixelPosition::TexelBySpec`]): always, its bound
|
||||
/// state's modes unknown;
|
||||
@@ -2088,7 +2079,7 @@ fn centre_denormals(
|
||||
Ok(match (pixel, position) {
|
||||
(Pixel::Spec(_), PixelPosition::Texel | PixelPosition::TexelBySpec) => true,
|
||||
(Pixel::Heap(_), _) => false,
|
||||
(_, PixelPosition::Texel | PixelPosition::UnnormalizedTexel) => match stat {
|
||||
(_, PixelPosition::Texel) => match stat {
|
||||
Some(SamplerRef::Constexpr(words)) => {
|
||||
let s = super::state_of(words)?;
|
||||
centre_parts(s.address_s) || centre_parts(s.address_t)
|
||||
@@ -2112,12 +2103,12 @@ fn centre_parts(mode: AddressMode) -> bool {
|
||||
|
||||
/// What the device's normalized sampler is handed of the pixel coordinate of `op` through a sampler
|
||||
/// of pixel coordinates `pixel` (the static sampler `stat`, of a texture whose texels are `integer`
|
||||
/// or not), where the device's unnormalized sampler does not take `x` itself:
|
||||
/// or not):
|
||||
///
|
||||
/// - a sample through a constexpr pixel sampler that filters nearest, without a mip filter or
|
||||
/// anisotropy, or of an integer texture (which every filter reads nearest): its texel's centre;
|
||||
/// - a sample through a runtime sampler slot: its texel's centre where the slot's
|
||||
/// `NearestPixelSampler` specialization states such a sampler, or always of an integer texture;
|
||||
/// - a sample through a runtime sampler slot: its texel's centre where the slot's word states
|
||||
/// such a sampler (`SamplerWord::nearest_pixel`), or always of an integer texture;
|
||||
/// - a sample through an argument buffer's sampler: its texel's centre where the table entry's
|
||||
/// word states such a sampler (`SamplerWord::nearest_pixel`);
|
||||
/// - else the quotient: a linear filter's sample, a gather (whose block the device's sampler
|
||||
|
||||
@@ -1848,23 +1848,6 @@ fn identity_refusal(plan: &Plan) -> Option<(IdentityCause, String)> {
|
||||
));
|
||||
}
|
||||
}
|
||||
let lookup = plan.families.access.lookup();
|
||||
let entry = matches!(
|
||||
lookup,
|
||||
crate::memory::handles::Lookup::Element
|
||||
| crate::memory::handles::Lookup::Flagged {
|
||||
class: false,
|
||||
red_blue: false,
|
||||
unreadable: false,
|
||||
..
|
||||
}
|
||||
);
|
||||
if !entry {
|
||||
return Some((
|
||||
IdentityCause::HeapResource,
|
||||
format!("a texture handle that reads its table entry beyond its element ({lookup:?})"),
|
||||
));
|
||||
}
|
||||
if let Some(s) = t.slots.values().find(|s| !s.identity_lowered()) {
|
||||
return Some((
|
||||
IdentityCause::TextureState,
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
//! Metal's out-of-bounds read is the zero texel with the pixel format's missing alpha read as 1,
|
||||
//! so where the shader selects that texel itself (a read it checks, or a level-view read past
|
||||
//! the bound level count on any profile), its alpha depends on the bound texture's format, which
|
||||
//! the binder specializes (`SpecKey::OutOfBoundsAlpha`). A read whose fourth lane nothing observes
|
||||
//! needs no such constant: its out-of-bounds texel is zero in every lane anything reads.
|
||||
//! the texture's resource ID's word states (`TextureWord::OUT_OF_BOUNDS_ALPHA_ONE`). A read whose
|
||||
//! fourth lane nothing observes needs no such bit: its out-of-bounds texel is zero in every lane
|
||||
//! anything reads.
|
||||
//!
|
||||
//! A read returns `{<4 x T>, i8}` where its declaration states a residency status
|
||||
//! (`intrinsics::Texture::status`, which AIR 2.2 added), and its texel is taken by
|
||||
|
||||
@@ -530,15 +530,14 @@ pub(crate) struct HeapElement {
|
||||
/// The handle is live (not the null element). `None` under the identity domains, whose
|
||||
/// element 0 is a null descriptor that answers as Metal's nil texture does.
|
||||
pub live: Option<SValue>,
|
||||
/// The handle's flags, where the function's handle-table search carries the element's
|
||||
/// out-of-bounds-alpha flag (`memory::handles::Lookup`'s `alpha`): `heap_alpha_one` reads
|
||||
/// the flag.
|
||||
/// The handle's flags, where the function's heap handles carry the texture's
|
||||
/// out-of-bounds-alpha flag (`memory::handles::Lookup::Flagged`): `heap_alpha_one` reads the
|
||||
/// flag.
|
||||
pub flagged: Option<HeapFlags>,
|
||||
}
|
||||
|
||||
/// The element of heap handle `h` (as the function's handle-table search yields it): the handle
|
||||
/// masked to its element where the search carries anything beside it
|
||||
/// (`memory::handles::Lookup::element_mask`), or, under the identity domains, where the handle
|
||||
/// The element of heap handle `h`: the handle masked to its element where it carries the
|
||||
/// out-of-bounds alpha beside it (`memory::handles::Lookup::element_mask`), or where the handle
|
||||
/// carries its word's low bits (`words::HANDLE_WORD`: always where the function reads a heap
|
||||
/// texture's border texels, `AccessPlan::heap_border`, else where the stage's
|
||||
/// `SpecKey::TexelBufferWords` holds), else the handle itself.
|
||||
@@ -568,10 +567,9 @@ fn heap_element_index(cx: &EmitCx<'_>, fb: &mut FunctionBuilder<'_>, h: SValue)
|
||||
fb.binary(BinOp::BitwiseAnd, h, mask)
|
||||
}
|
||||
|
||||
/// The flags of a heap handle its uses read (its texel class, red-blue order and
|
||||
/// out-of-bounds-alpha flag, as the function's search reads them), in the layout of the handle
|
||||
/// a flagged search yields (`memory::handles::Lookup::Flagged`: `HANDLE_TEXEL_CLASS`,
|
||||
/// `HANDLE_RED_BLUE`, `HANDLE_ALPHA_ONE`): the handle itself, which carries them.
|
||||
/// The flag of a heap handle its uses read (its out-of-bounds-alpha flag), in the layout of a
|
||||
/// flagged handle (`memory::handles::Lookup::Flagged`: `HANDLE_ALPHA_ONE`): the handle itself,
|
||||
/// which carries it.
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) struct HeapFlags(pub(super) SValue);
|
||||
|
||||
@@ -624,34 +622,22 @@ pub(crate) fn heap_element(
|
||||
let Some(declared) = declared else {
|
||||
return Err(cx.fail(format!("heap group {group} is not declared")));
|
||||
};
|
||||
heap_element_of(cx, fb, declared, handle, false)
|
||||
heap_element_of(cx, fb, declared, handle)
|
||||
}
|
||||
|
||||
/// The element of heap handle `handle` in the array of heap class `class`, declared `decl`: the
|
||||
/// null element where `unreadable` and the handle carries `FLAG_STORAGE_UNREADABLE`.
|
||||
/// The element of heap handle `handle` in the array of heap class `class`, declared `decl`.
|
||||
fn heap_element_of(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
(class, decl): (crate::pipeline::sym::ImageHandleClass, ImageDecl),
|
||||
handle: ValueId,
|
||||
unreadable: bool,
|
||||
) -> BResult<HeapElement> {
|
||||
let Some(g) = cx.decl.families.texture.heap.get(&class).copied() else {
|
||||
return Err(cx.fail(format!("heap class {class:?} is not declared")));
|
||||
};
|
||||
let base = fb.module().global_value(g)?;
|
||||
let h = cx.operand(fb, handle)?;
|
||||
let mut element = heap_element_index(cx, fb, h)?;
|
||||
if unreadable {
|
||||
use crate::memory::handles::HANDLE_STORAGE_UNREADABLE;
|
||||
let flags = HeapFlags(h);
|
||||
let bit = u32s(fb, 1, HANDLE_STORAGE_UNREADABLE)?;
|
||||
let set = fb.binary(BinOp::BitwiseAnd, flags.0, bit)?;
|
||||
let zero = u32s(fb, 1, 0)?;
|
||||
let readable = fb.binary(BinOp::IEqual, set, zero)?;
|
||||
let null = u32s(fb, 1, NEUTRAL_ELEMENT)?;
|
||||
element = fb.select(readable, element, null)?;
|
||||
}
|
||||
let element = heap_element_index(cx, fb, h)?;
|
||||
let flagged = match cx.plan.families.access.heap_alpha {
|
||||
true => Some(HeapFlags(h)),
|
||||
false => None,
|
||||
|
||||
@@ -38,15 +38,15 @@
|
||||
//!
|
||||
//! **Operations.** `read` is `OpImageFetch` on a sampled image and `OpImageRead` on a storage
|
||||
//! image; `write` is `OpImageWrite`; `get_*` are `OpImageQuery*`; `fence` is an image memory
|
||||
//! barrier; `is_null` reads the slot's `ResourcePresence` specialization constant. Texels move
|
||||
//! between the image's 32-bit `vec4` and AIR's held forms: a slot's `half` texels are the device's
|
||||
//! texels rounded to nearest even (`PrecisionNote::HalfTexelConversion`; a texture buffer's
|
||||
//! included), and a heap element's `half` texels are rounded exactly, half subnormals and the
|
||||
//! decoded NaN kept (`narrow::round_texel`; the NaN is the device's decode,
|
||||
//! `PrecisionNote::DeviceNanEncoding`), 16-bit integers are held zero-extended and written
|
||||
//! sign-extended, and a storage image of class `SwizzleBgra` or `SrgbEncode` converts in the
|
||||
//! shader, the latter by the device's sRGB transfer (`PrecisionNote::SrgbTexelDecode` for a read,
|
||||
//! `PrecisionNote::DevicePackConversion` for a write).
|
||||
//! barrier; `is_null` tests the slot's resource ID's element for nil. Texels move between the
|
||||
//! image's 32-bit `vec4` and AIR's held forms: a slot's `half` texels are the device's texels
|
||||
//! rounded to nearest even (`PrecisionNote::HalfTexelConversion`; a texture buffer's included), and
|
||||
//! a heap element's `half` texels are rounded exactly, half subnormals and the decoded NaN kept
|
||||
//! (`narrow::round_texel`; the NaN is the device's decode, `PrecisionNote::DeviceNanEncoding`),
|
||||
//! 16-bit integers are held zero-extended and written sign-extended, and a storage image of class
|
||||
//! `SwizzleBgra` or `SrgbEncode` converts in the shader, the latter by the device's sRGB transfer
|
||||
//! (`PrecisionNote::SrgbTexelDecode` for a read, `PrecisionNote::DevicePackConversion` for a
|
||||
//! write).
|
||||
//!
|
||||
//! **Containment**. A write is discarded out of bounds (Metal's semantics) by a builder-closed
|
||||
//! bounds check unless the profile's robustness discards it already (`robustImageAccess`;
|
||||
@@ -54,12 +54,10 @@
|
||||
//! the pixel format's missing alpha read as 1 ([`ReadCheck`]): the device's under
|
||||
//! `robustImageAccess2` (`robustBufferAccess2` for texel buffers), otherwise, under containment,
|
||||
//! the shader clamps the level, coordinate, layer, and sample index into the bound image and
|
||||
//! selects that texel where one was out of range, its alpha from the slot's `OutOfBoundsAlpha`
|
||||
//! specialization when the function observes it (`alpha`). A heap read's alpha is its handle's: the
|
||||
//! binder writes the out-of-bounds-alpha flag in the handle-table entry of a texture whose format
|
||||
//! has no alpha, and a module with such a read looks handles up in
|
||||
//! `memory::handles::Lookup::Flagged`, which carries the flag in the handle's top bit (masked off
|
||||
//! before indexing). A cube face or cube index out of range addresses a layer past the 2D-array
|
||||
//! selects that texel where one was out of range, its alpha from the texture's resource ID's word
|
||||
//! when the function observes it (`alpha`). A heap read's alpha is its handle's: a module with such
|
||||
//! a read takes `memory::handles::Lookup::Flagged` handles, which carry the resource ID word's
|
||||
//! out-of-bounds-alpha flag in the handle's top bit (masked off before indexing). A cube face or cube index out of range addresses a layer past the 2D-array
|
||||
//! view, never another cube's face.
|
||||
//!
|
||||
//! **Reads through a sampler** (MSL 4.1 §6.13, [`Through`]). Metal 4.1's `read(sampler s, coord
|
||||
@@ -77,8 +75,8 @@
|
||||
//! - Its signed coordinate plus its offset is tested per axis against that level's extent.
|
||||
//! Outside it, an axis whose address mode is `clamp_to_zero` or `clamp_to_border` reads the
|
||||
//! border texel, the sampler's border color (under `clamp_to_zero` too) in the format's channels
|
||||
//! through the texture's swizzle (`metal::sampler::border_texels`), which a slot's
|
||||
//! `BorderTexels` specialization states; every other mode (`clamp_to_edge`, `repeat`,
|
||||
//! through the texture's swizzle (`metal::sampler::border_texels`), which a slot's resource
|
||||
//! ID's word states; every other mode (`clamp_to_edge`, `repeat`,
|
||||
//! `mirrored_repeat`, `mirror_clamp_to_edge`) clamps the index into the level.
|
||||
//! - A texture buffer's index outside it is addressed as the first texel of a row past its one row:
|
||||
//! it reads the border texel where the `t` axis's mode is a border mode, else its first texel,
|
||||
@@ -101,20 +99,18 @@
|
||||
//! (`OpImageRead`/`OpImageWrite` take no `Lod`). A storage slot that is read or written at a level
|
||||
//! other than the constant 0 is declared as an array of `N` storage images, `N` the most levels a
|
||||
//! texture of its type can have on the device (`⌊log2 maxImageDimension⌋ + 1`), which the binder
|
||||
//! fills with single-level views of the bound texture's levels and neutrals
|
||||
//! past them (`RuntimeFact::StorageTextureLevelViews`). Every access of such a slot indexes the
|
||||
//! array: by a constant level below `N` as is (the neutral where the texture lacks that level),
|
||||
//! else by the level clamped below the bound texture's level count (`PushField::TextureLevels`,
|
||||
//! `RuntimeFact::StorageTextureLevels`), a `NonUniform` index. A read or write at a level the
|
||||
//! texture lacks is out of bounds (MSL 4.1 §6.13): Metal ignores the write, and the write is
|
||||
//! dropped; Metal reads zero components (alpha 1 where the format has none), and the read selects
|
||||
//! that texel on every profile, whatever the device's robustness, since the element it read is
|
||||
//! another level or a neutral (the out-of-bounds texel, its alpha from the slot's
|
||||
//! `OutOfBoundsAlpha` where the function observes it). `get_num_mip_levels` of a storage texture
|
||||
//! is the pushed count, 0 for a neutral; of a 1D
|
||||
//! texture or 1D texture array, sampled or storage, always 0 (Metal has no mipmapped 1D
|
||||
//! textures). Heap storage images take only the constant 0, and a
|
||||
//! texture atomic on a slot with level views is not implemented.
|
||||
//! fills with single-level views of the bound texture's levels and neutrals past them. Every access
|
||||
//! of such a slot indexes the array: by a constant level below `N` as is (the neutral where the
|
||||
//! texture lacks that level), else by the level clamped below the bound texture's level count
|
||||
//! (`PushField::TextureLevels`), a `NonUniform` index. A read or write at a level the texture lacks
|
||||
//! is out of bounds (MSL 4.1 §6.13): Metal ignores the write, and the write is dropped; Metal reads
|
||||
//! zero components (alpha 1 where the format has none), and the read selects that texel on every
|
||||
//! profile, whatever the device's robustness, since the element it read is another level or a
|
||||
//! neutral (the out-of-bounds texel, its alpha from the slot's resource ID's word where the
|
||||
//! function observes it). `get_num_mip_levels` of a storage texture is the pushed count, 0 for a
|
||||
//! neutral; of a 1D texture or 1D texture array, sampled or storage, always 0 (Metal has no
|
||||
//! mipmapped 1D textures). Heap storage images take only the constant 0, and a texture atomic on a
|
||||
//! slot with level views is not implemented.
|
||||
//!
|
||||
//! Under the identity domains the level views are no array of the slot's own: they are a run of
|
||||
//! the set-1 storage array, each element a single-level view of the bound texture's level, in
|
||||
@@ -317,9 +313,9 @@ pub struct Read {
|
||||
/// How an out-of-bounds read returns Metal's texel.
|
||||
pub check: ReadCheck,
|
||||
/// Where the shader selects the out-of-bounds texel (under [`ReadCheck::Shader`], or past a
|
||||
/// level-view read's level count), its alpha is the bound format's (the function observes
|
||||
/// the alpha): a slot's `OutOfBoundsAlpha` specialization, or a heap element's
|
||||
/// out-of-bounds-alpha flag, which its handle carries; otherwise it is 0.
|
||||
/// level-view read's level count), its alpha is the bound format's (the function observes the
|
||||
/// alpha): a slot's resource ID's word, or a heap element's out-of-bounds-alpha flag, which its
|
||||
/// handle carries; otherwise it is 0.
|
||||
pub alpha: bool,
|
||||
/// A Metal 4.1 read through a sampler ([`Through`]).
|
||||
pub through: Option<Through>,
|
||||
@@ -550,7 +546,7 @@ pub enum TextureStrategy {
|
||||
Query(QueryOp),
|
||||
/// `fence`: an image memory barrier.
|
||||
Fence,
|
||||
/// `is_null`: the negated `ResourcePresence` of the slot.
|
||||
/// `is_null`: whether the slot's resource ID's element is nil.
|
||||
IsNull {
|
||||
index: u32,
|
||||
},
|
||||
@@ -1384,22 +1380,17 @@ fn heap_group(cx: &mut SelectCx<'_>, tex: Value, m: &mut Meter) -> Result<u32, E
|
||||
Ok(group)
|
||||
}
|
||||
|
||||
/// The words of the flags a heap handle carries: where the handle-table search carries any, every
|
||||
/// The words of the flag a heap handle carries: where it carries the out-of-bounds alpha, every
|
||||
/// heap operation masks its handle to its element (an `OpBitwiseAnd`), and a read that selects the
|
||||
/// out-of-bounds alpha also tests that flag (an `OpBitwiseAnd` and an `OpINotEqual`), with their
|
||||
/// constants once; the census's for the strategy that asks for them, `texture.read_clamped.heap`
|
||||
/// where the alpha is carried, else [`HEAP_CLASS_CENSUS`].
|
||||
/// constants once, under `texture.read_clamped.heap`.
|
||||
pub fn routine_words(
|
||||
texture: &TexturePlan,
|
||||
access: &crate::lower::access::AccessPlan,
|
||||
) -> impl Iterator<Item = (&'static str, u64)> {
|
||||
let flags = (access.heap_alpha || access.carries_class()).then(|| {
|
||||
let flags = access.heap_alpha.then(|| {
|
||||
let words = 16 + 16 * u64::from(texture.heap_uses);
|
||||
let name = match access.heap_alpha {
|
||||
true => "texture.read_clamped.heap",
|
||||
false => HEAP_CLASS_CENSUS,
|
||||
};
|
||||
(name, words)
|
||||
("texture.read_clamped.heap", words)
|
||||
});
|
||||
// The routines of the texture buffers held as words, once each.
|
||||
let words = (!texture.words.routines.is_empty()).then(|| {
|
||||
@@ -1411,10 +1402,6 @@ pub fn routine_words(
|
||||
flags.into_iter().chain(words)
|
||||
}
|
||||
|
||||
/// The census name of the words a heap texel class costs: where no other flag is carried, the masks
|
||||
/// of the heap handles.
|
||||
pub const HEAP_CLASS_CENSUS: &str = "sampler.heap.texel_class";
|
||||
|
||||
/// What a `float` write to texture `image` (of storage class `class`) records where it may reach a
|
||||
/// half-float image ([`may_store_half`]), which the device converts whole. Its rounding of each
|
||||
/// channel to `half` (Metal rounds toward zero, a finite value past 65504 to 65504) is the device's
|
||||
@@ -2207,9 +2194,9 @@ fn constant_read_sampler(state: &crate::air::abi::SamplerState) -> ReadSampler {
|
||||
|
||||
/// Plan what read through a sampler `t` of `image` reads besides the image: a runtime slot's
|
||||
/// word (`RuntimeSlot::reads`), and where an index outside the level may read the border texel, a
|
||||
/// slot's `BorderTexels` specialization (`RuntimeFact::BorderTexels`; under the identity domains
|
||||
/// its resource ID's word holds them, `emit::identity_id`), or a heap element's, which its
|
||||
/// resource ID's word holds and its handle then carries (`AccessPlan::heap_border`). A `ulong`
|
||||
/// slot's border texels, which its resource ID's word holds (`emit::identity_id`), or a heap
|
||||
/// element's, which its resource ID's word holds and its handle then carries
|
||||
/// (`AccessPlan::heap_border`). A `ulong`
|
||||
/// texel's border, which is not measured, is not implemented.
|
||||
fn select_through(
|
||||
cx: &mut SelectCx<'_>,
|
||||
|
||||
@@ -156,16 +156,12 @@ pub struct SlotPlan {
|
||||
/// The texel class its reads and writes spell; `None` when only queries use it.
|
||||
pub texel: Option<TexelClass>,
|
||||
pub uses: Uses,
|
||||
/// `is_null` observes the slot's presence (`RuntimeFact::ResourcePresence`).
|
||||
/// `is_null` observes the slot's presence, its resource ID's element.
|
||||
pub presence: bool,
|
||||
/// A read whose out-of-bounds texel the shader selects observes its alpha, which the slot's
|
||||
/// resource ID's word gives (`TextureWord::OUT_OF_BOUNDS_ALPHA_ONE`): a read the shader checks,
|
||||
/// or a level-view read under any check, past the bound level count.
|
||||
pub oob_alpha: bool,
|
||||
/// A read of the slot through a sampler may read the border texel, which the slot's
|
||||
/// `BorderTexels` specialization gives (`RuntimeFact::BorderTexels`). Never under the identity
|
||||
/// domains, where the slot's resource ID's word holds the border texels.
|
||||
pub border_texels: bool,
|
||||
/// The device is left both an out-of-bounds store and an out-of-bounds load of the slot, so
|
||||
/// its variable is decorated `Volatile`; set by [`finish`].
|
||||
pub volatile: bool,
|
||||
@@ -196,7 +192,6 @@ impl SlotPlan {
|
||||
uses: Uses::default(),
|
||||
presence: false,
|
||||
oob_alpha: false,
|
||||
border_texels: false,
|
||||
volatile: false,
|
||||
swizzle: false,
|
||||
offset_base: false,
|
||||
@@ -400,13 +395,13 @@ fn declare_heap(
|
||||
VkFeature::DescriptorBindingStorageImageUpdateAfterBind,
|
||||
);
|
||||
}
|
||||
// A heap's storage classes are declared without a format, and the binder views its
|
||||
// members for every access the device's features grant (`bind::heap`). The features name
|
||||
// storage texel buffers too. A read needs `shaderStorageImageReadWithoutFormat`, or the
|
||||
// formats' own bits (`DeviceProfile::storage_reads_by_format_bits`): the binder then
|
||||
// holds a member whose view's format lacks the read bit for its writes alone, flagged,
|
||||
// and a read through its handle reads the null element (`Read::heap_unreadable`), where
|
||||
// no read-write tier format's view lacks it (below).
|
||||
// A heap's storage classes are declared without a format, and the binder views its members
|
||||
// for every access the device's features grant (`bind::heap`). The features name storage
|
||||
// texel buffers too. A read needs `shaderStorageImageReadWithoutFormat`, or the formats'
|
||||
// own bits (`DeviceProfile::storage_reads_by_format_bits`): the binder then holds a member
|
||||
// whose view's format lacks the read bit for its writes alone, flagged, and a read through
|
||||
// its handle reads the null element, where no read-write tier format's view lacks it
|
||||
// (below).
|
||||
need(
|
||||
!h.uses.read
|
||||
|| images.storage_read_without_format
|
||||
|
||||
@@ -24,42 +24,42 @@
|
||||
//! family's.
|
||||
//!
|
||||
//! **Heap handles**. A texture handle loaded from an argument buffer is the guest's 8-byte
|
||||
//! `gpuResourceID`. Its load calls the module's one search of the **handle table**
|
||||
//! ([`define_lookup`], [`lookup`]), a read-only storage buffer (`Synthetic(HandleTable)`) of
|
||||
//! 16-byte entries `{resource_id: u64, element: u32, flags: u32}` sorted by id, and yields the
|
||||
//! resident resource's **element** in the set-1 heap: one runtime descriptor array per image class
|
||||
//! (`ResourceKind::Heap`), indexed `NonUniform`. Element [`NEUTRAL_ELEMENT`] (0) holds each class's
|
||||
//! neutral and is the value of a null handle and of every id the table misses, so the heap domain
|
||||
//! has the static domain's null handle and needs no switch. The table's first entry is the null
|
||||
//! entry `{0, 0, 0}` (Metal's nil resource id), so it is never empty and every entry the search
|
||||
//! reads is inside it; it holds at most [`TABLE_CAPACITY`] entries, the reach of the
|
||||
//! [`SEARCH_STEPS`]-step branch-free search. A value whose roots are `Dynamic` and possibly null is
|
||||
//! a heap handle ([`Domain::Heap`]); mixing static candidates with heap handles is
|
||||
//! `Unsupported{ArgumentBufferTextures, NotImplemented}`. [`HeapGroups`] joins the heap handles
|
||||
//! that `phi`, `select`, `freeze`, and casts merge, so the texture family declares one heap class
|
||||
//! per group from all of its uses, as it declares one image per slot.
|
||||
//! `gpuResourceID`, whose index names the texture's **element** in the set-1 identity arrays
|
||||
//! (`docs/RESOURCE-ID.md`): its load masks the index below the arrays' length
|
||||
//! (`pipeline::link::IDENTITY_TEXTURES`) and yields it (`access::handle::emit_identity_handle`),
|
||||
//! and each use indexes its class's array by it, `NonUniform`. Element [`NEUTRAL_ELEMENT`] (0)
|
||||
//! holds each class's neutral, the null descriptor, and is the value of a null handle, so the heap
|
||||
//! domain has the static domain's null handle and needs no switch. A value whose roots are
|
||||
//! `Dynamic` and possibly null is a heap handle ([`Domain::Heap`]); mixing static candidates with
|
||||
//! heap handles is `Unsupported{ArgumentBufferTextures, NotImplemented}`. [`HeapGroups`] joins the
|
||||
//! heap handles that `phi`, `select`, `freeze`, and casts merge, so the texture family declares one
|
||||
//! heap class per group from all of its uses, as it declares one image per slot.
|
||||
//!
|
||||
//! **The out-of-bounds alpha**. A texture entry's flags carry [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`] when
|
||||
//! the resident texture's pixel format has no alpha, whose out-of-bounds read then returns alpha 1,
|
||||
//! as Metal's read of such a texture bound to a slot does (no heap texture was measured). A module
|
||||
//! whose shader-checked heap read observes the alpha calls the search's flagged form
|
||||
//! ([`Lookup::Flagged`]): the handle is the element with that flag in bit 31
|
||||
//! ([`HANDLE_ALPHA_ONE`]), which every heap access masks off ([`Lookup::element_mask`]) and the
|
||||
//! read selects its out-of-bounds alpha by. An element is below [`TABLE_CAPACITY`], so the bit is
|
||||
//! never an element's.
|
||||
//! **The out-of-bounds alpha**. A module whose shader-checked heap read observes the alpha takes
|
||||
//! flagged handles ([`Lookup::Flagged`]): the handle is the element with the resource ID word's
|
||||
//! missing-alpha flag in bit 31 ([`HANDLE_ALPHA_ONE`]), which every heap access masks off
|
||||
//! ([`Lookup::element_mask`]) and the read selects its out-of-bounds alpha by: alpha 1 where the
|
||||
//! texture's pixel format has none, as Metal's read of such a texture bound to a slot returns (no
|
||||
//! heap texture was measured). An element is below the arrays' length, so the bit is never an
|
||||
//! element's.
|
||||
//!
|
||||
//! **Heap samplers** (the sampler half). A sampler handle loaded from an argument buffer is the
|
||||
//! guest's resource id of an `MTLSamplerState`, searched in the stage's **sampler table**
|
||||
//! (`Synthetic(SamplerTable)`), the handle table's layout over the argument buffers' samplers: a
|
||||
//! sampler's resource id is not a texture's, so the two never share a table. The search's entry
|
||||
//! form ([`Lookup::Entry`]) yields the index of the entry it finds, or 0, the null entry, for a
|
||||
//! miss, and that index is the handle. Each use reads the entry's element
|
||||
//! ([`EntryField::Element`]), which indexes the set-1 sampler array of the sampling's use
|
||||
//! (`HandleClass::Sampler`, whose element 0 is the neutral sampler), and its flags word
|
||||
//! ([`EntryField::Flags`]), the sampler's [`SamplerWord`](crate::metal::sampler::SamplerWord): the
|
||||
//! state the shader reads of a sampler it learns at run time (pixel coordinates, and with them the
|
||||
//! exact fetch and the centre of a nearest pixel sampler's texel). A null entry's element and word
|
||||
//! are 0: the neutral sampler, and the state of `MTLSamplerDescriptor`'s defaults.
|
||||
//! guest's resource id of an `MTLSamplerState` (`access::handle::emit_identity_sampler`). Each use
|
||||
//! reads its element ([`EntryField::Element`]), the id's guarded index into the set-1 sampler array
|
||||
//! of the sampling's use (`HandleClass::Sampler`, whose element 0 is the neutral sampler), and its
|
||||
//! word ([`EntryField::Flags`]), the sampler's
|
||||
//! [`SamplerWord`](crate::metal::sampler::SamplerWord): the state the shader reads of a sampler it
|
||||
//! learns at run time (pixel coordinates, and with them the exact fetch and the centre of a
|
||||
//! nearest pixel sampler's texel).
|
||||
//!
|
||||
//! **The handle table** ([`define_lookup`], [`lookup`]) is the search of the function-table
|
||||
//! directory (`lower::access::function_table`): a read-only storage buffer of 16-byte entries
|
||||
//! `{resource_id: u64, element: u32, flags: u32}` sorted by id, whose first entry is the null entry
|
||||
//! `{0, 0, 0}` (Metal's nil resource id), so it is never empty and every entry the search reads is
|
||||
//! inside it; it holds at most [`TABLE_CAPACITY`] entries, the reach of the [`SEARCH_STEPS`]-step
|
||||
//! branch-free search. Its element form ([`Lookup::Element`]) yields the found entry's element,
|
||||
//! [`NEUTRAL_ELEMENT`] for a miss, and its entry form ([`Lookup::Entry`]) the found entry's index,
|
||||
//! 0 for a miss, whose fields a use reads ([`entry_field`]).
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
@@ -378,57 +378,12 @@ pub const TABLE_ENTRY_BYTES: u32 = 16;
|
||||
/// bound to a slot returns alpha 1 (MSL 4.1 section 2.9.1), which a read through the table takes
|
||||
/// too; no heap texture was measured.
|
||||
pub const FLAG_OUT_OF_BOUNDS_ALPHA_ONE: u32 = 1 << 1;
|
||||
/// The flag of a texture entry whose pixel format a storage view may hold through its RGBA-order
|
||||
/// twin, red and blue exchanged (`metal::format::red_blue_exchanged`: `BGRA8Unorm`,
|
||||
/// `BGRA8Unorm_sRGB`, `BGR10A2Unorm`), which tells such a member from the red-first format of its
|
||||
/// texel class (`RGBA8Unorm`, `RGBA8Unorm_sRGB`, `RGB10A2Unorm`): a storage access through a heap
|
||||
/// handle exchanges the channels of a member its storage array views so
|
||||
/// (`bind::heap::storage_conversions`). A handle carries it beside its class
|
||||
/// ([`HANDLE_RED_BLUE`]).
|
||||
pub const FLAG_RED_BLUE: u32 = 1 << 2;
|
||||
/// The field of a texture entry's flags holding the index of its texel class in the heap's layout
|
||||
/// (`metal::texel_format::heap_class_index`): the class a slot bound to the texture would take
|
||||
/// (`metal::texel_format::with_border`), `OTHER` (index 0) for a swizzled texture, by which a
|
||||
/// function converts or reads the texture's texels where the module reads it (a fetched gather, a
|
||||
/// NaN texel's rule, a raw-held form's emulation). A heap handle carries it in place, in a module
|
||||
/// whose search carries it ([`Lookup::Flagged`]'s `class`), so [`HANDLE_TEXEL_CLASS`] is this
|
||||
/// field. Its 12 bits hold every index `metal::texel_format::heap_class_index` gives, which a test
|
||||
/// checks.
|
||||
pub const FLAG_TEXEL_CLASS: u32 = 0xfff << 16;
|
||||
/// The flag of a texture entry whose view in the heap's storage arrays (`bind::heap`) a device
|
||||
/// that reads storage without a format by the formats' own bits alone cannot read so: the view's
|
||||
/// format lacks `VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT`, which such a read needs
|
||||
/// (`VUID-vkCmdDispatch-OpTypeImage-07028`). A storage read through its handle reads the null
|
||||
/// element instead, as a nil texture's read does ([`Lookup::Flagged`]'s `unreadable`); its writes
|
||||
/// store as before. Set only on such a device (`bind::heap::storage_unreadable`). A handle carries
|
||||
/// it in place, in [`HANDLE_STORAGE_UNREADABLE`].
|
||||
pub const FLAG_STORAGE_UNREADABLE: u32 = 1 << 28;
|
||||
/// The bit of a heap handle that carries its entry's [`FLAG_STORAGE_UNREADABLE`], in place, in a
|
||||
/// module whose search carries it ([`Lookup::Flagged`]'s `unreadable`).
|
||||
pub const HANDLE_STORAGE_UNREADABLE: u32 = FLAG_STORAGE_UNREADABLE;
|
||||
/// The field of a heap handle that carries its entry's [`FLAG_TEXEL_CLASS`], in place, in a
|
||||
/// module whose search carries it ([`Lookup::Flagged`]'s `class`).
|
||||
pub const HANDLE_TEXEL_CLASS: u32 = FLAG_TEXEL_CLASS;
|
||||
/// The bit of a heap handle that carries its entry's [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`], in a
|
||||
/// module whose search carries it ([`Lookup::Flagged`]'s `alpha`).
|
||||
/// The bit of a flagged heap handle ([`Lookup::Flagged`]) that carries its texture's
|
||||
/// out-of-bounds-alpha flag: the resource ID word's (`access::handle::emit_identity_handle`), or a
|
||||
/// handle-table entry's [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`] through the search's flagged form.
|
||||
pub const HANDLE_ALPHA_ONE: u32 = 1 << 31;
|
||||
/// The bit of a heap handle that carries its entry's [`FLAG_RED_BLUE`], in a module whose search
|
||||
/// carries the texel class ([`Lookup::Flagged`]'s `class`).
|
||||
pub const HANDLE_RED_BLUE: u32 = 1 << 30;
|
||||
// Every element is below the table's capacity, so no carried bit is an element's, and the
|
||||
// carried fields do not overlap.
|
||||
const _: () = assert!(TABLE_CAPACITY <= 1 << HANDLE_TEXEL_CLASS.trailing_zeros());
|
||||
const _: () = assert!(HANDLE_TEXEL_CLASS & HANDLE_ALPHA_ONE == 0);
|
||||
const _: () = assert!((HANDLE_TEXEL_CLASS | HANDLE_ALPHA_ONE) & HANDLE_RED_BLUE == 0);
|
||||
const _: () = assert!(FLAG_TEXEL_CLASS & FLAG_OUT_OF_BOUNDS_ALPHA_ONE == 0);
|
||||
const _: () = assert!((FLAG_TEXEL_CLASS | FLAG_OUT_OF_BOUNDS_ALPHA_ONE) & FLAG_RED_BLUE == 0);
|
||||
const _: () = assert!(
|
||||
(HANDLE_TEXEL_CLASS | HANDLE_ALPHA_ONE | HANDLE_RED_BLUE) & HANDLE_STORAGE_UNREADABLE == 0
|
||||
);
|
||||
const _: () = assert!(
|
||||
(FLAG_TEXEL_CLASS | FLAG_OUT_OF_BOUNDS_ALPHA_ONE | FLAG_RED_BLUE) & FLAG_STORAGE_UNREADABLE
|
||||
== 0
|
||||
);
|
||||
// Every element is below the table's capacity, so the carried bit is no element's.
|
||||
const _: () = assert!(TABLE_CAPACITY <= 1 << HANDLE_ALPHA_ONE.trailing_zeros());
|
||||
|
||||
/// Unrolled steps of the handle-table search.
|
||||
pub const SEARCH_STEPS: u32 = 16;
|
||||
@@ -1285,21 +1240,11 @@ fn entry_member(fb: &mut FunctionBuilder<'_>, t: Table, k: SValue, member: u32)
|
||||
pub enum Lookup {
|
||||
/// The entry's element.
|
||||
Element,
|
||||
/// The entry's element with flags of its entry beside it: where `alpha`, its
|
||||
/// [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`] in [`HANDLE_ALPHA_ONE`], the handle of a module whose
|
||||
/// shader-checked heap read observes the alpha; where `class`, its [`FLAG_TEXEL_CLASS`] in
|
||||
/// [`HANDLE_TEXEL_CLASS`], the handle of a module that reads a heap texture's texel class;
|
||||
/// where `red_blue`, its [`FLAG_RED_BLUE`] in [`HANDLE_RED_BLUE`], the handle of a module whose
|
||||
/// storage access converts a member by it (`bind::heap::storage_conversions`); where
|
||||
/// `unreadable`, its [`FLAG_STORAGE_UNREADABLE`] in [`HANDLE_STORAGE_UNREADABLE`], the handle
|
||||
/// of a module that reads a heap storage class on a device that reads storage without a format
|
||||
/// by the formats' own bits alone. Every heap access masks them off ([`Lookup::element_mask`]).
|
||||
Flagged {
|
||||
alpha: bool,
|
||||
class: bool,
|
||||
red_blue: bool,
|
||||
unreadable: bool,
|
||||
},
|
||||
/// The element with its out-of-bounds-alpha flag beside it, in [`HANDLE_ALPHA_ONE`]: the
|
||||
/// handle of a module whose shader-checked heap read observes the alpha (through the search,
|
||||
/// the entry's [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`]). Every heap access masks it off
|
||||
/// ([`Lookup::element_mask`]).
|
||||
Flagged,
|
||||
/// The index of the entry found, 0 (the null entry) for a miss: the handle of an argument
|
||||
/// buffer's sampler, whose uses read the entry's element and word ([`entry_field`]).
|
||||
Entry,
|
||||
@@ -1307,33 +1252,15 @@ pub enum Lookup {
|
||||
|
||||
impl Lookup {
|
||||
/// The entry flags this form's uses read in the handle, each with the left shift that moves it
|
||||
/// there: the ones `Flagged`'s search carries into it.
|
||||
/// there: the one `Flagged`'s search carries into it.
|
||||
fn carried(self) -> Vec<(u32, u32)> {
|
||||
let Lookup::Flagged {
|
||||
alpha,
|
||||
class,
|
||||
red_blue,
|
||||
unreadable,
|
||||
} = self
|
||||
else {
|
||||
return Vec::new();
|
||||
};
|
||||
let alpha = alpha.then_some((
|
||||
FLAG_OUT_OF_BOUNDS_ALPHA_ONE,
|
||||
HANDLE_ALPHA_ONE.trailing_zeros() - FLAG_OUT_OF_BOUNDS_ALPHA_ONE.trailing_zeros(),
|
||||
));
|
||||
let class = class.then_some((FLAG_TEXEL_CLASS, 0));
|
||||
let red_blue = red_blue.then_some((
|
||||
FLAG_RED_BLUE,
|
||||
HANDLE_RED_BLUE.trailing_zeros() - FLAG_RED_BLUE.trailing_zeros(),
|
||||
));
|
||||
let unreadable = unreadable.then_some((FLAG_STORAGE_UNREADABLE, 0));
|
||||
alpha
|
||||
.into_iter()
|
||||
.chain(class)
|
||||
.chain(red_blue)
|
||||
.chain(unreadable)
|
||||
.collect()
|
||||
match self {
|
||||
Lookup::Flagged => vec![(
|
||||
FLAG_OUT_OF_BOUNDS_ALPHA_ONE,
|
||||
HANDLE_ALPHA_ONE.trailing_zeros() - FLAG_OUT_OF_BOUNDS_ALPHA_ONE.trailing_zeros(),
|
||||
)],
|
||||
Lookup::Element | Lookup::Entry => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The bits of a handle this form yields that are its element, where it carries anything
|
||||
@@ -1373,8 +1300,7 @@ pub enum EntryField {
|
||||
/// The heap element.
|
||||
Element,
|
||||
/// The flags: for a sampler, its [`SamplerWord`](crate::metal::sampler::SamplerWord); for a
|
||||
/// texture, [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`], [`FLAG_RED_BLUE`], the index of its texel class
|
||||
/// in [`FLAG_TEXEL_CLASS`], and [`FLAG_STORAGE_UNREADABLE`], every other bit 0.
|
||||
/// texture, [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`], every other bit 0.
|
||||
Flags,
|
||||
}
|
||||
|
||||
@@ -1716,95 +1642,32 @@ mod tests {
|
||||
/// several sizes up to [`TABLE_CAPACITY`] entries (the null id, present ids, absent ids between
|
||||
/// and beyond them) gets [`reference`]'s element, through an entry array (`u64` ids).
|
||||
/// [`Lookup::Flagged`] also carries a found entry's [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`]
|
||||
/// in [`HANDLE_ALPHA_ONE`] where it carries the alpha, its texel class where it carries that,
|
||||
/// and its [`FLAG_RED_BLUE`] in [`HANDLE_RED_BLUE`] where it carries that, carrying no other
|
||||
/// bit of the entry; and [`Lookup::Entry`] yields the index of the last entry of the key's id,
|
||||
/// 0 for a miss.
|
||||
/// in [`HANDLE_ALPHA_ONE`], carrying no other bit of the entry; and [`Lookup::Entry`] yields
|
||||
/// the index of the last entry of the key's id, 0 for a miss.
|
||||
#[test]
|
||||
fn the_emitted_search_matches_the_host_model() {
|
||||
let flagged = |alpha, class, red_blue, unreadable| Lookup::Flagged {
|
||||
alpha,
|
||||
class,
|
||||
red_blue,
|
||||
unreadable,
|
||||
};
|
||||
for form in [
|
||||
Lookup::Element,
|
||||
flagged(true, false, false, false),
|
||||
flagged(false, true, false, false),
|
||||
flagged(false, false, true, false),
|
||||
flagged(false, false, false, true),
|
||||
flagged(true, true, false, false),
|
||||
flagged(true, true, true, false),
|
||||
flagged(true, true, true, true),
|
||||
Lookup::Entry,
|
||||
] {
|
||||
for form in [Lookup::Element, Lookup::Flagged, Lookup::Entry] {
|
||||
emitted_search_matches_the_host_model(form);
|
||||
}
|
||||
}
|
||||
|
||||
/// Each flagged form's element mask clears exactly the bits it carries.
|
||||
/// The flagged form's element mask clears exactly the bit it carries.
|
||||
#[test]
|
||||
fn a_flagged_handle_masks_off_the_bits_it_carries() {
|
||||
let flagged = |alpha, class, red_blue, unreadable| {
|
||||
Lookup::Flagged {
|
||||
alpha,
|
||||
class,
|
||||
red_blue,
|
||||
unreadable,
|
||||
}
|
||||
.element_mask()
|
||||
};
|
||||
fn a_flagged_handle_masks_off_the_bit_it_carries() {
|
||||
assert_eq!(Lookup::Element.element_mask(), None);
|
||||
assert_eq!(Lookup::Entry.element_mask(), None);
|
||||
assert_eq!(flagged(false, false, false, false), None);
|
||||
assert_eq!(flagged(true, false, false, false), Some(!HANDLE_ALPHA_ONE));
|
||||
assert_eq!(HANDLE_TEXEL_CLASS, 0xfff << 16);
|
||||
assert_eq!(
|
||||
flagged(false, true, false, false),
|
||||
Some(!HANDLE_TEXEL_CLASS)
|
||||
);
|
||||
assert_eq!(flagged(false, false, true, false), Some(!HANDLE_RED_BLUE));
|
||||
assert_eq!(
|
||||
flagged(false, false, false, true),
|
||||
Some(!HANDLE_STORAGE_UNREADABLE)
|
||||
);
|
||||
assert_eq!(
|
||||
flagged(true, true, true, true),
|
||||
Some(
|
||||
!(HANDLE_ALPHA_ONE
|
||||
| HANDLE_TEXEL_CLASS
|
||||
| HANDLE_RED_BLUE
|
||||
| HANDLE_STORAGE_UNREADABLE)
|
||||
),
|
||||
"every carried field is masked off, and the element's 16 bits stay"
|
||||
);
|
||||
}
|
||||
|
||||
/// Every texel class index fits [`FLAG_TEXEL_CLASS`], so no index reaches
|
||||
/// [`FLAG_STORAGE_UNREADABLE`] above it.
|
||||
#[test]
|
||||
fn every_texel_class_index_fits_its_field() {
|
||||
let field = FLAG_TEXEL_CLASS >> FLAG_TEXEL_CLASS.trailing_zeros();
|
||||
for &pf in crate::metal::PixelFormat::ALL {
|
||||
let index = crate::metal::texel_format::heap_class_index(
|
||||
pf,
|
||||
crate::metal::TextureSwizzleChannels::DEFAULT,
|
||||
);
|
||||
assert_eq!(index & !field, 0, "{pf:?}");
|
||||
}
|
||||
assert_eq!(Lookup::Flagged.element_mask(), Some(!HANDLE_ALPHA_ONE));
|
||||
}
|
||||
|
||||
/// The flags of the test tables' entry of `element`: none on the null entry, else its low six
|
||||
/// bits, a class index of it, its bit 4 moved to bit 15, which no form carries, and
|
||||
/// [`FLAG_STORAGE_UNREADABLE`] where its bit 3 is, so each carried flag occurs set and clear,
|
||||
/// beside bits no form carries.
|
||||
/// bits, scattered bits of it at 16-27, its bit 4 moved to bit 15 and its bit 3 to bit 28, so
|
||||
/// the carried flag occurs set and clear, beside bits no form carries.
|
||||
fn flags(element: u32) -> u32 {
|
||||
if element == NEUTRAL_ELEMENT {
|
||||
return 0;
|
||||
}
|
||||
(element % 64)
|
||||
| ((element.wrapping_mul(2_654_435_761) >> 7) & FLAG_TEXEL_CLASS)
|
||||
| ((element.wrapping_mul(2_654_435_761) >> 7) & (0xfff << 16))
|
||||
| ((element & 16) << 11)
|
||||
| ((element & 8) << 25)
|
||||
}
|
||||
@@ -1872,29 +1735,14 @@ mod tests {
|
||||
let at = 4 * (2 * KEYS as usize + i);
|
||||
let got = u32::from_le_bytes(io[at..at + 4].try_into().expect("word"));
|
||||
let e = reference(&t, *id);
|
||||
let carried = |on: bool, flag: u32, bit: u32| match on {
|
||||
true if flags(e) & flag != 0 => bit,
|
||||
_ => 0,
|
||||
let carried = |flag: u32, bit: u32| match flags(e) & flag {
|
||||
0 => 0,
|
||||
_ => bit,
|
||||
};
|
||||
let want = match form {
|
||||
Lookup::Element => e,
|
||||
Lookup::Flagged {
|
||||
alpha,
|
||||
class,
|
||||
red_blue,
|
||||
unreadable,
|
||||
} => {
|
||||
e | carried(alpha, FLAG_OUT_OF_BOUNDS_ALPHA_ONE, HANDLE_ALPHA_ONE)
|
||||
| carried(red_blue, FLAG_RED_BLUE, HANDLE_RED_BLUE)
|
||||
| carried(
|
||||
unreadable,
|
||||
FLAG_STORAGE_UNREADABLE,
|
||||
HANDLE_STORAGE_UNREADABLE,
|
||||
)
|
||||
| match class {
|
||||
true => flags(e) & FLAG_TEXEL_CLASS,
|
||||
false => 0,
|
||||
}
|
||||
Lookup::Flagged => {
|
||||
e | carried(FLAG_OUT_OF_BOUNDS_ALPHA_ONE, HANDLE_ALPHA_ONE)
|
||||
}
|
||||
Lookup::Entry => {
|
||||
t.iter().rposition(|(k, _)| k == id).map_or(0, |i| i as u32)
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
//! The bytes of an argument buffer's indirect-command objects.
|
||||
//!
|
||||
//! Metal's encoder writes an object's resource id into a command-buffer or compute or render
|
||||
//! pipeline-state member of an argument buffer. Under the identity domains a command buffer's
|
||||
//! field holds its word, the `gpuResourceID` the program or the host wrote there: the device
|
||||
//! address of its records (`lower::access::icb`). Metal lays a Tier 2 argument buffer out as the
|
||||
//! equivalent C structure, whose contents the GPU and the CPU may both modify, so an access to
|
||||
//! those bytes is a plain access of the buffer's memory, as an access to any other member's is.
|
||||
//! Any other object's field, and a command buffer's under the resident-table domains, holds no
|
||||
//! value a translation defines. Only the handle load reads it: a pointer load of exactly one such
|
||||
//! field, at a translation-time constant offset in the buffer's first element, which
|
||||
//! `Walk::seed_loaded` classes as the object's handle (`lower::access::object`). Any other access
|
||||
//! that may reach such an object's bytes is `ArgumentBufferObjects`, not implemented:
|
||||
//! pipeline-state member of an argument buffer. Under the identity domains a command buffer's field
|
||||
//! holds its word, the `gpuResourceID` the program or the host wrote there: the device address of
|
||||
//! its records (`lower::access::icb`). Metal lays a Tier 2 argument buffer out as the equivalent C
|
||||
//! structure, whose contents the GPU and the CPU may both modify, so an access to those bytes is a
|
||||
//! plain access of the buffer's memory, as an access to any other member's is. Any other object's
|
||||
//! field holds no value a translation defines. Only the handle load reads it: a pointer load of
|
||||
//! exactly one such field, at a translation-time constant offset in the buffer's first element,
|
||||
//! which `Walk::seed_loaded` classes as the object's handle (`lower::access::object`). Any other
|
||||
//! access that may reach such an object's bytes is `ArgumentBufferObjects`, not implemented:
|
||||
//!
|
||||
//! - **The offsets an access may take** are its shape's (a constant, or a constant plus multiples
|
||||
//! of its strides) within its range. An access at least as wide as its step touches one
|
||||
|
||||
@@ -2918,9 +2918,9 @@ pub fn storage_view_formats(pf: PixelFormat, profile: &DeviceProfile) -> Vec<vk:
|
||||
|
||||
/// Whether a storage view of a texture of `pf` may be an RGBA-order twin, red and blue exchanged
|
||||
/// in the shader ([`storage_choice`]'s `SwizzleBgra` and `SrgbEncodeBgra`): the blue-first
|
||||
/// `BGRA8Unorm`, `BGRA8Unorm_sRGB` and `BGR10A2Unorm`, on every device. A heap texture's
|
||||
/// handle-table entry carries it (`memory::handles::FLAG_RED_BLUE`), which tells such a member
|
||||
/// from the red-first format of the same texel class.
|
||||
/// `BGRA8Unorm`, `BGRA8Unorm_sRGB` and `BGR10A2Unorm`, on every device. It tells a heap storage
|
||||
/// member of such a format from the red-first format of the same texel class
|
||||
/// (`bind::heap::storage_conversions`).
|
||||
pub(crate) fn red_blue_exchanged(pf: PixelFormat) -> bool {
|
||||
matches!(
|
||||
pf,
|
||||
|
||||
@@ -1763,9 +1763,8 @@ fn storage_choices_on_committed_profiles_are_declarable() {
|
||||
|
||||
/// A storage choice that exchanges red and blue in the shader (`SwizzleBgra`, `SrgbEncodeBgra`) is
|
||||
/// one of a format `red_blue_exchanged` names, on every committed profile and for every use, and
|
||||
/// each such format takes one on some profile: the flag a heap entry carries for it
|
||||
/// (`memory::handles::FLAG_RED_BLUE`) is what tells its member from the red-first format of its
|
||||
/// texel class.
|
||||
/// each such format takes one on some profile: it is what tells a heap storage member of it from
|
||||
/// the red-first format of its texel class (`bind::heap::storage_conversions`).
|
||||
#[test]
|
||||
fn a_red_blue_exchange_is_a_blue_first_format_s() {
|
||||
let mut exchanged = BTreeSet::new();
|
||||
|
||||
@@ -717,16 +717,16 @@ fn through(m: vk::ComponentMapping, texel: [bool; 4]) -> [bool; 4] {
|
||||
pub(crate) const BORDER_COLORS: [[bool; 4]; 3] =
|
||||
[[false; 4], [false, false, false, true], [true; 4]];
|
||||
|
||||
/// The `SpecKey::BorderTexels` of a texture of `pf` made with `swizzle`: bit `3c + b` is set where
|
||||
/// channel `c` (0 red to 3 alpha) of Metal's border texel ([`border_texel`]) for border color `b`
|
||||
/// (`MTLSamplerBorderColor`'s value, as [`BORDER_COLORS`] orders them) reads 1, not 0: the texel a
|
||||
/// Metal 4.1 read through a sampler hands back at an index outside the level on a border axis
|
||||
/// (`lower::texture::Through`). A color format's channels are its own
|
||||
/// ([`channels`](crate::metal::format::channels)). A depth or stencil format reads as red, green
|
||||
/// and blue, alpha 1: an Apple M3 Max (macOS 27.0.1) reads `Depth32Float` through a
|
||||
/// `texture2d<float>` as `(d, d, d, 1)` and its border as `(0, 0, 0, 1)`, `(0, 0, 0, 1)` and
|
||||
/// `(1, 1, 1, 1)` for the three colors; the other depth and stencil formats take that rule, an
|
||||
/// inference. `None` for a format of no stated channels (the placeholders).
|
||||
/// The border texels of a texture of `pf` made with `swizzle` (`TextureWord::BORDER_TEXELS`, in a
|
||||
/// texture's resource ID's word): bit `3c + b` is set where channel `c` (0 red to 3 alpha) of
|
||||
/// Metal's border texel ([`border_texel`]) for border color `b` (`MTLSamplerBorderColor`'s value,
|
||||
/// as [`BORDER_COLORS`] orders them) reads 1, not 0: the texel a Metal 4.1 read through a sampler
|
||||
/// hands back at an index outside the level on a border axis (`lower::texture::Through`). A color
|
||||
/// format's channels are its own ([`channels`](crate::metal::format::channels)). A depth or stencil
|
||||
/// format reads as red, green and blue, alpha 1: an Apple M3 Max (macOS 27.0.1) reads
|
||||
/// `Depth32Float` through a `texture2d<float>` as `(d, d, d, 1)` and its border as `(0, 0, 0, 1)`,
|
||||
/// `(0, 0, 0, 1)` and `(1, 1, 1, 1)` for the three colors; the other depth and stencil formats take
|
||||
/// that rule, an inference. `None` for a format of no stated channels (the placeholders).
|
||||
pub(crate) fn border_texels(pf: PixelFormat, swizzle: TextureSwizzleChannels) -> Option<u32> {
|
||||
let present = match crate::metal::format::is_depth_stencil(pf) {
|
||||
true => [true, true, true, false],
|
||||
|
||||
@@ -884,16 +884,14 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// The heap classes are few enough for a handle-table entry's class field, `OTHER` first; each
|
||||
/// unswizzled format's index names its slot class with its border texels, and a swizzled
|
||||
/// texture's names `OTHER`. An unswizzled texture of a form a heap reads names that form past
|
||||
/// the base, an `OTHER` entry; a swizzled one `OTHER`'s. An integer color format names its
|
||||
/// numeric marker; a format a read of another class does not take, its class past the own-only
|
||||
/// base, so only a crossing float format's texture names an own class (below the extended
|
||||
/// base).
|
||||
/// The heap classes start with `OTHER`; each unswizzled format's index names its slot class
|
||||
/// with its border texels, and a swizzled texture's names `OTHER`. An unswizzled texture of a
|
||||
/// form a heap reads names that form past the base, an `OTHER` entry; a swizzled one
|
||||
/// `OTHER`'s. An integer color format names its numeric marker; a format a read of another
|
||||
/// class does not take, its class past the own-only base, so only a crossing float format's
|
||||
/// texture names an own class (below the extended base).
|
||||
#[test]
|
||||
fn a_heap_texture_names_its_class_by_index() {
|
||||
use crate::memory::handles::FLAG_TEXEL_CLASS;
|
||||
use crate::metal::format::ExtendedRange;
|
||||
let classes = &heap_layout().classes;
|
||||
let base = heap_layout().extended as usize;
|
||||
@@ -908,12 +906,6 @@ mod tests {
|
||||
.all(|&c| c == TexelFormat::OTHER.0));
|
||||
assert_eq!(classes.get(own_only), Some(&TexelFormat::OTHER.0));
|
||||
assert!(classes[own_only..].windows(2).all(|w| w[0] < w[1]));
|
||||
let field = FLAG_TEXEL_CLASS >> FLAG_TEXEL_CLASS.trailing_zeros();
|
||||
assert!(
|
||||
classes.len() <= field as usize + 1,
|
||||
"{} classes",
|
||||
classes.len()
|
||||
);
|
||||
let swizzle = TextureSwizzleChannels::new(
|
||||
crate::metal::TextureSwizzle::Blue,
|
||||
crate::metal::TextureSwizzle::Green,
|
||||
|
||||
@@ -415,25 +415,25 @@ pub enum PrecisionNote {
|
||||
/// to the edge of a texel pair, a gather's 2x2 block or one of the sub-texel steps of the
|
||||
/// filter's weight, where it may read the neighbouring pair, block or step. Recorded on every
|
||||
/// device where no other form takes the coordinate: a linear sample or a gather through a
|
||||
/// constexpr pixel sampler of an array or a 3D texture (Vulkan's unnormalized sampler takes
|
||||
/// neither), a level query, and every linear sample, gather and comparison through a runtime
|
||||
/// constexpr pixel sampler (whose device sampler the consumer makes normalized), a level
|
||||
/// query, and every linear sample, gather and comparison through a runtime
|
||||
/// sampler slot (whose state the function does not know), held where the bound sampler states
|
||||
/// pixel coordinates and, for a sample or comparison, that it is not a nearest one of one
|
||||
/// isotropic level (`SpecKey::NearestPixelSampler`), and for a sample or gather of a float 1D
|
||||
/// isotropic level (`SamplerWord::nearest_pixel`), and for a sample or gather of a float 1D
|
||||
/// or 2D texture that is no array, that its word does not read unnormalized
|
||||
/// ([`SamplerWord::reads_unnormalized`](crate::metal::sampler::SamplerWord::reads_unnormalized))
|
||||
/// or that a draw reads the texture as its pass's attachment. Not
|
||||
/// recorded where Metal's texel or footprint
|
||||
/// follows from `x` itself: a constexpr pixel sampler's sample or gather of a 1D or 2D texture
|
||||
/// that is no array hands `x` (moved by its offset) to the device's unnormalized sampler, and
|
||||
/// so does such a sample or gather through a runtime sampler slot whose bound state's word
|
||||
/// reads unnormalized, through the state's unnormalized twin at the texture's level-0 element
|
||||
/// follows from `x` itself: a sample or gather of a float 1D or 2D texture that is no array
|
||||
/// through a runtime sampler slot whose bound state's word reads unnormalized hands `x` (moved
|
||||
/// by its offset) to the device's unnormalized sampler, through the state's unnormalized twin
|
||||
/// at the texture's level-0 element
|
||||
/// ([`LEVEL_ZERO_ELEMENT`](crate::pipeline::LEVEL_ZERO_ELEMENT),
|
||||
/// [`UNNORMALIZED_TWIN_ELEMENT`](crate::pipeline::UNNORMALIZED_TWIN_ELEMENT)), the operation
|
||||
/// recording the note for the states whose word does not; a
|
||||
/// nearest sample elsewhere hands the device its texel's centre `floor(x) + 0.5` over the size,
|
||||
/// where the device reads exactly that texel (through a runtime slot behind the slot's
|
||||
/// `NearestPixelSampler` specialization); and a nearest constexpr sampler clamped to the edge
|
||||
/// where the device reads exactly that texel (through a runtime slot where its word states
|
||||
/// such a sampler); and a nearest constexpr sampler clamped to the edge
|
||||
/// fetches its texel (`sampler.pixel_fetch`). Measured: the device answers as its normalized
|
||||
/// sampler at a coordinate within one `f32` ulp of the quotient `x / N` on MoltenVK, and at the
|
||||
/// quotient itself on lavapipe (800 coordinates at and around each texel edge of a 5x3
|
||||
@@ -768,15 +768,15 @@ pub enum PrecisionNote {
|
||||
/// operation's result.
|
||||
QuadsCountedBeforeDiscard,
|
||||
/// The module places a texel offset on an axis that may repeat or mirror as Metal does in an
|
||||
/// access of an argument buffer's texture: in an emulated raw sample (`heap_raw`) or a bicubic
|
||||
/// filter's footprint, on every device. Metal drops the offset on a repeating
|
||||
/// or mirrored axis whose level size lies in `[2, 7]` and whose texture's base-level size is
|
||||
/// not a power of two, reading the base-level size of the texture a view was made from; a heap
|
||||
/// element's access can read only the bound view's. So on a view whose first level lies above
|
||||
/// its parent's base level, an axis of view size 2 or 4 under a parent whose base-level size is
|
||||
/// not a power of two keeps an offset Metal drops, and the access reads the texel or footprint
|
||||
/// one offset away. Any other texture or view places it as Metal does, and a texture slot's
|
||||
/// access reads the parent's through the slot's `SpecKey::OffsetBaseAxes`, recording nothing.
|
||||
/// access of an argument buffer's texture: in a bicubic filter's footprint, on every device.
|
||||
/// Metal drops the offset on a repeating or mirrored axis whose level size lies in `[2, 7]` and
|
||||
/// whose texture's base-level size is not a power of two, reading the base-level size of the
|
||||
/// texture a view was made from; a heap element's access can read only the bound view's. So on
|
||||
/// a view whose first level lies above its parent's base level, an axis of view size 2 or 4
|
||||
/// under a parent whose base-level size is not a power of two keeps an offset Metal drops, and
|
||||
/// the access reads the texel or footprint one offset away. Any other texture or view places it
|
||||
/// as Metal does, and a texture slot's footprint placed so is refused
|
||||
/// (`IdentityCause::TextureState`), recording nothing.
|
||||
///
|
||||
/// Validation derives no tolerance and no explanation from it: a difference stays a mismatch
|
||||
/// for review (no authored case binds such a view).
|
||||
@@ -1745,8 +1745,7 @@ pub enum PrecisionNote {
|
||||
/// the AIR states it, so the device runs the threads in its own order between barriers, and the
|
||||
/// values the pair reads and leaves may be other than Metal's. Static per kernel, from the
|
||||
/// AIR's structure alone: recorded on every device for a kernel in which the translator finds
|
||||
/// such a pair. A profile that orders the pairs with barriers of its own (the resident-table
|
||||
/// domains) records none.
|
||||
/// such a pair.
|
||||
///
|
||||
/// Validation derives no tolerance from it: a difference stays a mismatch, which the note
|
||||
/// explains.
|
||||
|
||||
@@ -642,12 +642,11 @@ pub struct LoweringInputs {
|
||||
/// that writes no such texel, compiles as without it.
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub texture_write_rounding: metal::TextureWriteRoundingMode,
|
||||
/// With [`open_cl_mode`](Self::open_cl_mode), the kernel's texture slots of a 1D image
|
||||
/// (`RuntimeFact::OpenClLineTexture`) bound to a 1D or 1D array texture
|
||||
/// (`VariantKey::open_cl_lines`), where Apple's OpenCL binds a 2D texture of height 1: the
|
||||
/// kernel declares each as that 1D texture and reads it, as a Radeon Pro 5300M (macOS 26.7.1)
|
||||
/// answers (`air::SpecRequest::open_cl_lines`). Every other 1D image is read as the 2D
|
||||
/// texture. Empty for any other function.
|
||||
/// With [`open_cl_mode`](Self::open_cl_mode), the kernel's texture slots of a 1D image bound to
|
||||
/// a 1D or 1D array texture (`VariantKey::open_cl_lines`), where Apple's OpenCL binds a 2D
|
||||
/// texture of height 1: the kernel declares each as that 1D texture and reads it, as a Radeon
|
||||
/// Pro 5300M (macOS 26.7.1) answers (`air::SpecRequest::open_cl_lines`). Every other 1D image
|
||||
/// is read as the 2D texture. Empty for any other function.
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub open_cl_lines: BTreeSet<SlotRef>,
|
||||
/// The `float` and `half` varyings the fragment function reads interpolated (`center`,
|
||||
|
||||
@@ -556,9 +556,8 @@ pub enum PushField {
|
||||
TessellationFactorInstanceStride,
|
||||
/// The encoder's tessellation factor scale rounded to `half` (`float`), a control-stage field.
|
||||
TessellationFactorScale,
|
||||
/// The mipmap level count (`u32`) of the storage texture bound to the slot, 0 where the binder
|
||||
/// binds a neutral (`RuntimeFact::StorageTextureLevels`). Under the identity domains no fact
|
||||
/// is stated: 0 where the slot's resource ID is nil.
|
||||
/// The mipmap level count (`u32`) of the storage texture bound to the slot, 0 where the slot's
|
||||
/// resource ID is nil.
|
||||
TextureLevels(SlotRef),
|
||||
/// Under the identity domains, the first element (`u32`) of the run of set 1's storage-image
|
||||
/// array that holds the levels of the storage texture bound to a slot read or written at a
|
||||
|
||||
@@ -1964,12 +1964,7 @@ fn textures_at_their_resource_ids(ab: bool) {
|
||||
let handles = match (ab, checked) {
|
||||
(false, _) => None,
|
||||
(true, false) => Some(Lookup::Element),
|
||||
(true, true) => Some(Lookup::Flagged {
|
||||
alpha: true,
|
||||
class: false,
|
||||
red_blue: false,
|
||||
unreadable: false,
|
||||
}),
|
||||
(true, true) => Some(Lookup::Flagged),
|
||||
};
|
||||
let used = !plan.families.texture.heap.is_empty();
|
||||
assert_eq!(
|
||||
|
||||
@@ -416,7 +416,6 @@ fn gathers_gradients_and_pixel_constexpr_samplers() {
|
||||
// device's arithmetic on the quotient (`PixelSamplerScaling`).
|
||||
let x = ok(&bc, "sample_pixel", &p);
|
||||
assert!(x.precision.contains(&PrecisionNote::PixelSamplerScaling));
|
||||
assert_eq!(uses(&x, "sampler.pixel_unnormalized"), 0);
|
||||
}
|
||||
|
||||
/// A `half` sample of a texture slot is the device's texel rounded to nearest even, which records
|
||||
|
||||
@@ -229,7 +229,6 @@ fn a_clamp_to_zero_pixel_sampler_samples_its_texel_centre() {
|
||||
let a = ok(&bc, "sample_pixel_zero", &m3());
|
||||
assert_eq!(count(&a, OP_IMAGE_FETCH), 0);
|
||||
assert_eq!(uses(&a, "sampler.pixel_texel"), 1);
|
||||
assert_eq!(uses(&a, "sampler.pixel_unnormalized"), 0);
|
||||
assert!(glsl(&a, GLSL_FLOOR) > 0);
|
||||
assert!(!a.precision.contains(&PrecisionNote::PixelSamplerScaling));
|
||||
}
|
||||
|
||||
+20
-24
@@ -877,11 +877,11 @@ through buffer arguments it reads at any index.
|
||||
coordinate at the row's centre), as both Macs answer. A real 1D texture bound for an
|
||||
`image1d_t`, or a 1D array texture for an `image1d_array_t`, which Apple's OpenCL never binds,
|
||||
takes the kernel's variant that declares that slot as the 1D texture
|
||||
(`RuntimeFact::OpenClLineTexture`, `VariantKey::open_cl_lines`): each read, sample and size
|
||||
(`VariantKey::open_cl_lines`): each read, sample and size
|
||||
query answers the 1D texture's values, of the layer an array access names, as a Radeon Pro
|
||||
5300M (macOS 26.7.1) answers (an Intel UHD Graphics 630 reads layer 0 of the array, an M3 Max
|
||||
texel 0 at every coordinate). Under the identity domains no variant is made: the kernel states
|
||||
no `OpenClLineTexture`, reads each 1D image as the 2D texture, and a consumer refuses a 1D
|
||||
texel 0 at every coordinate). Under the identity domains no variant is made: the kernel reads
|
||||
each 1D image as the 2D texture, and a consumer refuses a 1D
|
||||
texture bound for it (the runtime's `Gap::OpenClLineTexture`), since no reading of one is
|
||||
documented Metal. Apple's OpenCL binds an image of most
|
||||
channel orders as a swizzled view (on an M3 Max, macOS 27.0.1, with `CL_UNORM_INT8`: `CL_R`,
|
||||
@@ -1850,25 +1850,22 @@ category, and says what makes an operation carry the note and what may differ. E
|
||||
coordinate in its own arithmetic: within a few units in the last place of the edge of a linear
|
||||
filter's pair of texels, a gather's block or one of the filter's sub-texel steps it may read the
|
||||
neighbouring pair, block or step, where Metal's sampler reads the coordinate as given. Recorded
|
||||
for a linear sample, a gather and a level query through a constexpr pixel sampler of an array or a
|
||||
3D texture, and through a runtime sampler slot (where the bound state reads pixel coordinates, for
|
||||
a sample or comparison where it is not a nearest one of one isotropic level, and for a sample or
|
||||
gather of a float 1D or 2D texture that is no array where the state's word does not read
|
||||
unnormalized, `SamplerWord::reads_unnormalized`, or a draw reads the texture as its pass's
|
||||
attachment). Measured: the device's normalized sampler's answer within one `f32` ulp of the
|
||||
quotient on MoltenVK and at the quotient on lavapipe; a linear downscale by 8 within 1/255 of
|
||||
Metal's on MoltenVK and 2/255 on lavapipe. Under the identity domains it is also recorded for a
|
||||
linear sample and a gather through any constexpr pixel sampler, whose device sampler the consumer
|
||||
makes normalized. Nothing is
|
||||
recorded where Metal's texel or footprint follows from the coordinate itself: elsewhere a
|
||||
constexpr pixel sampler's sample or gather of a 1D or 2D texture that is no array hands the
|
||||
coordinate, moved by its offset, to the device's unnormalized sampler; so does such a sample or
|
||||
gather through a runtime sampler slot whose bound state's word reads unnormalized (one nearest
|
||||
or linear filter, no mip filter, isotropic, clamping to the edge, zero or the border on `s` and
|
||||
`t`), through the state's unnormalized twin at the texture's level-0 element (docs/RESOURCE-ID.md),
|
||||
where the note stays recorded for the states whose word does not; a nearest sample elsewhere
|
||||
hands the device its texel's centre, where the device reads exactly Metal's texel; and a nearest
|
||||
constexpr sampler clamped to the edge fetches its texel.
|
||||
for a linear sample, a gather and a level query through a constexpr pixel sampler, whose device
|
||||
sampler the consumer makes normalized, and through a runtime sampler slot (where the bound state
|
||||
reads pixel coordinates, for a sample or comparison where it is not a nearest one of one isotropic
|
||||
level, and for a sample or gather of a float 1D or 2D texture that is no array where the state's
|
||||
word does not read unnormalized, `SamplerWord::reads_unnormalized`, or a draw reads the texture as
|
||||
its pass's attachment). Measured: the device's normalized sampler's answer within one `f32` ulp of
|
||||
the quotient on MoltenVK and at the quotient on lavapipe; a linear downscale by 8 within 1/255 of
|
||||
Metal's on MoltenVK and 2/255 on lavapipe. Nothing is recorded where Metal's texel or footprint
|
||||
follows from the coordinate itself: a sample or gather of a float 1D or 2D texture that is no
|
||||
array through a runtime sampler slot whose bound state's word reads unnormalized (one nearest or
|
||||
linear filter, no mip filter, isotropic, clamping to the edge, zero or the border on `s` and `t`)
|
||||
hands the coordinate, moved by its offset, to the device's unnormalized sampler, through the
|
||||
state's unnormalized twin at the texture's level-0 element (docs/RESOURCE-ID.md), where the note
|
||||
stays recorded for the states whose word does not; a nearest sample elsewhere hands the device its
|
||||
texel's centre, where the device reads exactly Metal's texel; and a nearest constexpr sampler
|
||||
clamped to the edge fetches its texel.
|
||||
- `metal2vulkan-degrade-device-arithmetic` (precision). `PrecisionNote::DeviceArithmetic`: Float
|
||||
division, remainder, square root, fused multiply-add, and dot products use Vulkan's precision
|
||||
bounds (e.g. 2.5 ULP division, a possibly unfused `Fma`) rather than correct rounding. A
|
||||
@@ -2132,8 +2129,7 @@ category, and says what makes an operation carry the note and what may differ. E
|
||||
discard on a path to it, in a shape where Metal's placement of it is not known.
|
||||
- `metal2vulkan-degrade-view-base-texel-offset` (precision). `PrecisionNote::ViewBaseTexelOffset`:
|
||||
The module places a texel offset on an axis that may repeat or mirror as Metal does in an access
|
||||
of an argument buffer's texture: in an emulated raw sample (`heap_raw`) or a bicubic filter's
|
||||
footprint.
|
||||
of an argument buffer's texture: in a bicubic filter's footprint.
|
||||
- `metal2vulkan-degrade-device-color-conversion` (precision).
|
||||
`PrecisionNote::DeviceColorConversion`: A fragment function writes a float to a color channel
|
||||
whose conversion the device makes, on every device: a normalized, sRGB or small float channel,
|
||||
|
||||
Reference in new issue
Block a user