Translator: the two-word 64-bit integer forms deleted; every profile holds 64-bit integers in u64s
What: the arithmetic family's word form of 64-bit integers is deleted: Held::Wide and every arm on it, lower/arith/wide.rs (its word arithmetic, division, casts and lane moves) with its tests, ArithStrategy::Wide and ArithPlan's wide and divides, the profile's wide forms (wide_form_on, wide_demote, widen, widen_const, holds_wide), the two-word switch selector (SelectorForm::Words), the chunked vector's two-word lanes, the ulong texel's word form (TexelConv::U64Words loses its flag), the matrix descriptor's word form, and in the access family the two-word address (pointer.rs's Address enum and its helpers, the handle table's word entries and HandleIds, psb.rs's word base). The helpers the u64 paths still use move to arith/ops.rs (low_word, zext_word) and access/psb.rs (Pair, split). Every !int64 refusal goes with them: Feature::Int64Arithmetic, and Feature::PointerCompare, whose one producer was the static guest plan's !int64 arm. LeafCaps::int64 is deleted, and the mesh fold no longer asks for shaderInt64. BinOp::ISubBorrow, which only the word subtraction built, goes with its interpreter and builder arms (the grammar's Op::ISubBorrow stays in spv.rs). Why: Device::from_queries refuses a device without bufferDeviceAddress and shaderInt64 (IdentityDomains), and it is the only way to make a profile, so every profile has shaderInt64 and every arm deleted here was unreachable. This commit's parent is the last that holds the word form. Consumer search: reims-vgpu development cadac770c2 plus its steelbrain refs younger than a day (190 refs): 0 hits each for Int64Arithmetic, PointerCompare, LeafCaps and leaf.int64. The profile's fingerprint changes on every device (the field leaves the profile's Debug text), so the golden cells read "profile changed" until the table is re-blessed; no key stays unchanged, so SEMANTICS_VERSION does not move. The module words do not move: the u64 paths emit the same instructions in the same order (the uvec2 the slot offset builds is the same type the word form's type helper made). Tests: chunk.rs keeps the chunked lane-move and fragment-shuffle bound tests, on 64-bit and 32-bit lanes held whole; the selector test drops the word cases; the tests that asserted or filtered on the int64 field or Int64Arithmetic drop those lines; the dynamic move between slots runs L3 on every profile. docs/API.md (the object grid's needs), docs/REFUSALS.md, scripts/refusal-surface/reach.tsv and tests/api_signatures.tsv are updated; runtime-sources.sha256 is re-pinned. Verified: job m3-max-84770 at this commit (CPU only; the device steps on lavapipe): clippy plain, --cfg m2v_gpu and --cfg m2v_cpu_icd EXIT=0; rustdoc EXIT=0 and private-item docs of five crates with 0 diagnostics; the translator's suite 2,594 of 2,595 passed, 20 skipped, the one failure golden_hashes_match_the_table (28,950 cells under a changed profile fingerprint, 0 changed under an unchanged key); air, runtime, devtools and harness 872 passed, 4 skipped; validation 1,348 passed, 2 skipped; conformance 1,053 passed; doctests passed; the conformance replay on lavapipe EXIT=0 with 0 ledger drift lines; the refusal-surface and signatures checks EXIT=0. The golden and engine inventory lists at the parent and at this commit show 0 computed cells moved and no inventory line.
This commit is contained in:
1 parent
31d8a874f1
commit
fa5d051b64
60 files changed
+603
-5022
No files matched your search
@@ -74,8 +74,7 @@ impl Default for Target {
|
||||
/// index the generators build is a small non-negative `i32`, so the three spellings name the same
|
||||
/// element; they reach different index forms of the engine (a zero-extended word, a
|
||||
/// sign-extended word, and an `i32` index the GEP itself extends), and [`IndexForm::Narrow32`]
|
||||
/// programs compute no 64-bit index or offset, which a profile without `shaderInt64` (`vk12-floor`)
|
||||
/// runs without two-word emulation.
|
||||
/// programs compute no 64-bit index or offset.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum IndexForm {
|
||||
/// `zext i32 %v to i64`, the Metal front end's spelling of an unsigned index.
|
||||
|
||||
@@ -1 +1 @@
|
||||
eccf4a8b077f3b9b365540dbda6a5493442fa17f1a555aa1934c69e13a5f6d93
|
||||
596a528ed6d2aa047bed0f8a3fc06b7b586690bebc90c3a1f060a3b4dbe505b2
|
||||
@@ -155,7 +155,6 @@ fn derive_fields(desc: &DeviceDescription) -> ProfileFields {
|
||||
let leaf = LeafCaps {
|
||||
int8: has(VkFeature::ShaderInt8),
|
||||
int16: has(VkFeature::ShaderInt16),
|
||||
int64: has(VkFeature::ShaderInt64),
|
||||
float16: has(VkFeature::ShaderFloat16),
|
||||
float64: has(VkFeature::ShaderFloat64),
|
||||
storage_buffer_8bit: has(VkFeature::StorageBuffer8BitAccess),
|
||||
|
||||
@@ -245,7 +245,6 @@ fn unsupported_features(profile: &DeviceProfile) -> Vec<Unsupported> {
|
||||
let f = profile.fields();
|
||||
let feature = Capability::Feature;
|
||||
let mut out = Vec::new();
|
||||
// 64-bit integer arithmetic needs no `shaderInt64`: it is held as two words.
|
||||
if !f.leaf.float64 {
|
||||
out.push(Unsupported::needs(
|
||||
Feature::Float64Arithmetic,
|
||||
|
||||
@@ -457,7 +457,6 @@ impl EnabledCaps {
|
||||
pub struct LeafCaps {
|
||||
pub int8: bool,
|
||||
pub int16: bool,
|
||||
pub int64: bool,
|
||||
pub float16: bool,
|
||||
pub float64: bool,
|
||||
pub storage_buffer_8bit: bool,
|
||||
|
||||
@@ -646,8 +646,6 @@ fn metal_properties_report_d3_d4_values() {
|
||||
assert!(m.simd.kernel.matrix);
|
||||
assert!(!m.simd.fragment.matrix);
|
||||
let has = |f: &Feature| m.unsupported_features.iter().any(|u| u.feature == *f);
|
||||
// 64-bit integers are two words without `shaderInt64`, on every pipeline.
|
||||
assert!(!has(&Feature::Int64Arithmetic));
|
||||
assert!(has(&Feature::RasterOrderGroups));
|
||||
// No pixel interlock: framebuffer fetch reads input attachments ordered between draws, a
|
||||
// note, not a refusal.
|
||||
@@ -659,8 +657,4 @@ fn metal_properties_report_d3_d4_values() {
|
||||
assert_eq!(m.argument_buffers_tier, ArgumentBuffersTier::Tier2);
|
||||
assert!(m.simd.kernel.matrix);
|
||||
assert!(m.simd.kernel.cross_lane.contains(OpBits::SHUFFLE));
|
||||
assert!(!m
|
||||
.unsupported_features
|
||||
.iter()
|
||||
.any(|u| u.feature == Feature::Int64Arithmetic));
|
||||
}
|
||||
@@ -638,8 +638,6 @@ pub enum Feature {
|
||||
ArgumentBufferObjects,
|
||||
/// Dereferencing a pointer loaded from memory or made from an integer.
|
||||
DereferenceLoadedPointer,
|
||||
/// Comparing pointers with different roots.
|
||||
PointerCompare,
|
||||
/// A resource handle used as a byte pointer, or conflicting handle provenance.
|
||||
HandleAsPointer,
|
||||
/// A constant global whose address escapes.
|
||||
@@ -660,8 +658,6 @@ pub enum Feature {
|
||||
DescriptorCount,
|
||||
|
||||
// ---- Arithmetic ----
|
||||
/// 64-bit integer arithmetic.
|
||||
Int64Arithmetic,
|
||||
/// 64-bit float arithmetic.
|
||||
Float64Arithmetic,
|
||||
|
||||
|
||||
@@ -46,9 +46,7 @@
|
||||
//! which is exact for any overlap. Buffer endpoints with different or several candidate slots may
|
||||
//! alias through the binding (one buffer bound at two slots), and a wide endpoint may reach any
|
||||
//! buffer: those compare the endpoints' Metal addresses instead (`Overlap::Addressed`; a static
|
||||
//! candidate's is its `SlotGuestBase` plus its displacement, a wide pointer's its root entry's
|
||||
//! `guest + bind_offset + offset`), which needs `shaderInt64` for the `u64` addresses
|
||||
//! (`Unsupported{PointerCompare}` naming it otherwise).
|
||||
//! candidate's is its `SlotGuestBase` plus its displacement, a wide pointer's the `u64` it holds).
|
||||
//!
|
||||
//! **Volatile** intrinsics lower as the others, every unit accessed exactly once and in order, with
|
||||
//! every word load and store of a unit carrying `Volatile` (a volatile load or store's operand; the
|
||||
@@ -184,8 +182,7 @@ pub enum Source {
|
||||
pub enum Length {
|
||||
/// `count` whole units, then `tail` bytes (below the unit).
|
||||
Const { count: u32, tail: u32 },
|
||||
/// The operand `len`, an `i32` (held in a `u32`) or an `i64` (`wide`, held in a `u64`, or as
|
||||
/// two `u32` words without `shaderInt64`).
|
||||
/// The operand `len`, an `i32` (held in a `u32`) or an `i64` (`wide`, held in a `u64`).
|
||||
Dynamic { len: ValueId, wide: bool },
|
||||
}
|
||||
|
||||
@@ -538,11 +535,6 @@ pub fn select(
|
||||
let wide = match cx.lowered_repr(n, ty)? {
|
||||
DemoteTy::Scalar(ScalarTy::Int { bits: 32 }) => false,
|
||||
DemoteTy::Scalar(ScalarTy::Int { bits: 64 }) => true,
|
||||
// An `i64` held as two words without `shaderInt64`.
|
||||
DemoteTy::Vector {
|
||||
elem: ScalarTy::Int { bits: 32 },
|
||||
len: 2,
|
||||
} => true,
|
||||
_ => return Err(refuse(AccessCause::AccessType)),
|
||||
};
|
||||
Span::Dynamic(Length::Dynamic {
|
||||
@@ -739,7 +731,7 @@ fn directed(cx: &mut SelectCx<'_>, dst: &Endpoint, from: &Endpoint) -> Result<Ov
|
||||
/// `SlotGuestBase`.
|
||||
fn addressed(cx: &mut SelectCx<'_>, statics: &[&Access]) -> Result<Overlap, Error> {
|
||||
for a in statics {
|
||||
dynamic::plan_static_guest(cx, &a.targets, crate::error::Feature::PointerCompare)?;
|
||||
dynamic::plan_static_guest(cx, &a.targets)?;
|
||||
}
|
||||
Ok(Overlap::Addressed)
|
||||
}
|
||||
@@ -1026,7 +1018,7 @@ fn span(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, op: &MemOp) -> BResul
|
||||
width: 32,
|
||||
signed: false,
|
||||
})?;
|
||||
if wide && !cx.plan.families.arith.wide && op.only_wide() {
|
||||
if wide && op.only_wide() {
|
||||
// A `u64` length between wide endpoints, counted exactly.
|
||||
if op.unit == 1 {
|
||||
return Ok((Count::Wide(len), Count::Const(0)));
|
||||
@@ -1039,19 +1031,12 @@ fn span(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, op: &MemOp) -> BResul
|
||||
return Ok((Count::Wide(units), Count::Value(tail)));
|
||||
}
|
||||
let len = if wide {
|
||||
// A `u64`, or the two words `(low, high)` of a profile without `shaderInt64`.
|
||||
let (low, over) = if cx.plan.families.arith.wide {
|
||||
let low = fb.composite_extract(len, &[0])?;
|
||||
let high = fb.composite_extract(len, &[1])?;
|
||||
let zero = k32(fb, 0)?;
|
||||
(low, fb.binary(BinOp::INotEqual, high, zero)?)
|
||||
} else {
|
||||
let low = fb.convert(ConvOp::UConvert, len, u32_)?;
|
||||
let k = psb::k64(fb, 32)?;
|
||||
let high = fb.binary(BinOp::ShiftRightLogical, len, k)?;
|
||||
let zero = psb::k64(fb, 0)?;
|
||||
(low, fb.binary(BinOp::INotEqual, high, zero)?)
|
||||
};
|
||||
// A `u64`: its low word, or `u32::MAX` where its high word is not zero.
|
||||
let low = fb.convert(ConvOp::UConvert, len, u32_)?;
|
||||
let k = psb::k64(fb, 32)?;
|
||||
let high = fb.binary(BinOp::ShiftRightLogical, len, k)?;
|
||||
let zero = psb::k64(fb, 0)?;
|
||||
let over = fb.binary(BinOp::INotEqual, high, zero)?;
|
||||
let max = k32(fb, u32::MAX)?;
|
||||
fb.select(over, max, low)?
|
||||
} else {
|
||||
|
||||
@@ -66,7 +66,7 @@ use crate::air::ir::{
|
||||
};
|
||||
use crate::budget::Meter;
|
||||
use crate::device::requirements::VkFeature;
|
||||
use crate::error::{AccessCause, Capability, Error, Feature, LowerFamily, Unsupported};
|
||||
use crate::error::{AccessCause, Error, LowerFamily};
|
||||
use crate::lower::arith::{Form, Held};
|
||||
use crate::lower::emit::EmitCx;
|
||||
use crate::lower::select::SelectCx;
|
||||
@@ -1147,20 +1147,8 @@ pub(super) fn static_guest_address(
|
||||
}
|
||||
|
||||
/// Plan the Metal addresses of the static-root candidates `targets` ([`static_guest_address`]):
|
||||
/// their `SlotGuestBase` push fields, summed with displacements in `u64` arithmetic that needs
|
||||
/// `shaderInt64` (named in the refusal of `feature` otherwise).
|
||||
pub(super) fn plan_static_guest(
|
||||
cx: &mut SelectCx<'_>,
|
||||
targets: &[Target],
|
||||
feature: Feature,
|
||||
) -> Result<(), Error> {
|
||||
if !cx.profile.fields().leaf.int64 {
|
||||
return Err(Unsupported::needs(
|
||||
feature,
|
||||
Capability::Feature(crate::device::requirements::VkFeature::ShaderInt64),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
/// their `SlotGuestBase` push fields, summed with displacements in `u64` arithmetic.
|
||||
pub(super) fn plan_static_guest(cx: &mut SelectCx<'_>, targets: &[Target]) -> Result<(), Error> {
|
||||
for t in targets {
|
||||
let slot = cx
|
||||
.memory
|
||||
|
||||
@@ -653,8 +653,8 @@ pub(super) fn index_u32(
|
||||
let zero = k32(fb, 0)?;
|
||||
fb.select(x, one, zero)
|
||||
}
|
||||
// A `u64`, or two words without `shaderInt64`.
|
||||
IndexForm::Wide => crate::lower::arith::wide::low_word(fb, x),
|
||||
// A `u64`.
|
||||
IndexForm::Wide => crate::lower::arith::ops::low_word(fb, x),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ use std::borrow::Cow;
|
||||
use crate::air::intrinsics::{AirIntrinsic, FunctionTable};
|
||||
use crate::air::ir::{Callee, Inst, InstKind, ValueId};
|
||||
use crate::error::Error;
|
||||
use crate::lower::arith::legal;
|
||||
use crate::lower::emit::EmitCx;
|
||||
use crate::lower::select::{DescriptorCounts, Plan, SelectCx};
|
||||
use crate::memory::handles::{self, EntryField};
|
||||
@@ -55,7 +54,6 @@ use crate::spirv::error::BResult;
|
||||
use crate::spirv::ids::FuncId;
|
||||
use crate::spirv::ir::{BinOp, ConvOp, Type as SType};
|
||||
|
||||
use super::handle::HandleIds;
|
||||
use super::psb::{k64, PsbMem};
|
||||
|
||||
/// Where a function's table reads find the tables' words.
|
||||
@@ -71,9 +69,6 @@ pub enum TableWords {
|
||||
/// How a function reads tables by their resource ids.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct TableReads {
|
||||
/// How the directory's ids are held: one `u64`, or two words on a profile without
|
||||
/// `shaderInt64`.
|
||||
pub ids: HandleIds,
|
||||
/// Where the words are.
|
||||
pub words: TableWords,
|
||||
}
|
||||
@@ -170,16 +165,12 @@ pub fn select(cx: &mut SelectCx<'_>, inst: &Inst) -> Result<Option<TableWord>, E
|
||||
let [id, word] = call.args[..] else {
|
||||
return Err(cx.invariant("a table word read of another arity"));
|
||||
};
|
||||
let ids = match legal::holds_wide(cx.profile) {
|
||||
true => HandleIds::Words,
|
||||
false => HandleIds::U64,
|
||||
};
|
||||
let addressed = cx.inputs.addressed_function_tables;
|
||||
let (words, storage_buffers) = match addressed {
|
||||
true => (TableWords::Addressed, 1),
|
||||
false => (TableWords::Snapshot, 2),
|
||||
};
|
||||
let reads = TableReads { ids, words };
|
||||
let reads = TableReads { words };
|
||||
if cx.families.access.function_tables.is_none() {
|
||||
cx.families.access.function_tables = Some(reads);
|
||||
cx.descriptors = cx.descriptors.plus(&DescriptorCounts {
|
||||
@@ -206,8 +197,7 @@ pub fn select(cx: &mut SelectCx<'_>, inst: &Inst) -> Result<Option<TableWord>, E
|
||||
pub fn routine_words(tables: Option<TableReads>) -> impl Iterator<Item = (&'static str, u64)> {
|
||||
tables
|
||||
.map(|reads| {
|
||||
let words =
|
||||
handles::lookup_routine_words(reads.ids == HandleIds::U64, lookup_form(reads));
|
||||
let words = handles::lookup_routine_words(lookup_form(reads));
|
||||
("access.function_table.word", u64::from(words))
|
||||
})
|
||||
.into_iter()
|
||||
@@ -222,18 +212,14 @@ fn lookup_form(reads: TableReads) -> handles::Lookup {
|
||||
}
|
||||
}
|
||||
|
||||
/// Declare the stage's function-table directory (an entry array, or a word view on a profile
|
||||
/// without `shaderInt64`), the module's search of it, and the stage's snapshot (none for an
|
||||
/// addressed read), when the plan reads a table by its resource id.
|
||||
/// Declare the stage's function-table directory (an entry array), the module's search of it, and
|
||||
/// the stage's snapshot (none for an addressed read), when the plan reads a table by its resource
|
||||
/// id.
|
||||
pub fn declare(mb: &mut ModuleBuilder, plan: &Plan) -> BResult<Option<FunctionTables>> {
|
||||
let Some(reads) = plan.families.access.function_tables else {
|
||||
return Ok(None);
|
||||
};
|
||||
let directory = handles::declare_table(
|
||||
mb,
|
||||
directory_symbol(plan.stage),
|
||||
reads.ids == HandleIds::U64,
|
||||
)?;
|
||||
let directory = handles::declare_table(mb, directory_symbol(plan.stage))?;
|
||||
let lookup = handles::define_lookup(mb, directory, lookup_form(reads))?;
|
||||
if reads.words == TableWords::Addressed {
|
||||
return Ok(Some(FunctionTables {
|
||||
@@ -261,22 +247,14 @@ pub fn emit(
|
||||
return Err(cx.fail("a table word read without its directory"));
|
||||
};
|
||||
let id = cx.operand(fb, s.id)?;
|
||||
let (lo, hi) = match s.reads.ids {
|
||||
HandleIds::Words => (
|
||||
fb.composite_extract(id, &[0])?,
|
||||
fb.composite_extract(id, &[1])?,
|
||||
),
|
||||
HandleIds::U64 => {
|
||||
let u32_ty = fb.module().ty(SType::Int {
|
||||
width: 32,
|
||||
signed: false,
|
||||
})?;
|
||||
let lo = fb.convert(ConvOp::UConvert, id, u32_ty)?;
|
||||
let shift = k32(fb, 32)?;
|
||||
let high = fb.binary(BinOp::ShiftRightLogical, id, shift)?;
|
||||
(lo, fb.convert(ConvOp::UConvert, high, u32_ty)?)
|
||||
}
|
||||
};
|
||||
let u32_ty = fb.module().ty(SType::Int {
|
||||
width: 32,
|
||||
signed: false,
|
||||
})?;
|
||||
let lo = fb.convert(ConvOp::UConvert, id, u32_ty)?;
|
||||
let shift = k32(fb, 32)?;
|
||||
let high = fb.binary(BinOp::ShiftRightLogical, id, shift)?;
|
||||
let hi = fb.convert(ConvOp::UConvert, high, u32_ty)?;
|
||||
let Some(element) = fb.call(tables.lookup, &[lo, hi])? else {
|
||||
return Err(cx.fail("a directory search without a result"));
|
||||
};
|
||||
|
||||
@@ -1151,14 +1151,6 @@ fn lookup(
|
||||
/// handle's arithmetic (`OpCompositeExtract` of 5 words each, and the rest's).
|
||||
const LOOKUP_CALL_WORDS: u32 = 24;
|
||||
|
||||
/// How a function-table directory search reads an entry's resource id: as one `u64` on a profile
|
||||
/// with `shaderInt64`, else as two words.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum HandleIds {
|
||||
U64,
|
||||
Words,
|
||||
}
|
||||
|
||||
/// Emit handle strategy `s`, defining value `vid`.
|
||||
pub fn emit(
|
||||
cx: &mut EmitCx<'_>,
|
||||
|
||||
@@ -203,7 +203,7 @@ fn address(cx: &mut SelectCx<'_>, v: Value, m: &mut Meter) -> Result<Address, Er
|
||||
if in_blob {
|
||||
return Err(refuse(AccessCause::ConstantAddress));
|
||||
}
|
||||
dynamic::plan_static_guest(cx, &targets, Feature::GpuEncodedIndirectCommands)?;
|
||||
dynamic::plan_static_guest(cx, &targets)?;
|
||||
Ok(Address::Static {
|
||||
ptr: operand(cx, v)?,
|
||||
targets,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! with `zext`/`sext i32 %x to i64` followed by the GEP. A static-root offset is a `u32`: the GEP
|
||||
//! only needs each index modulo 2³², and the low word of a zero or sign extension of a value of at
|
||||
//! most 32 bits is that value zero- or sign-extended to 32 bits. The 64-bit extension is therefore
|
||||
//! dead arithmetic that would need `shaderInt64`.
|
||||
//! dead arithmetic.
|
||||
//!
|
||||
//! The rule is structural: an **index extension** is a scalar `zext`/`sext` instruction whose
|
||||
//! operand is a non-constant integer of 1 to 32 bits and whose result is an integer of 33 to 64
|
||||
@@ -24,7 +24,7 @@
|
||||
//! pointer's offset is 64-bit, so an index of one needs the whole value and keeps its 64-bit form.
|
||||
//! Both sets are the largest fixed point of these rules ([`index_values`]). Any other `i64` index
|
||||
//! (a 64-bit load, a shift right, arithmetic with any other use) is a 64-bit value of the arith
|
||||
//! family and still needs `shaderInt64`.
|
||||
//! family.
|
||||
//!
|
||||
//! **Across blocks**. An index extension has no value of its own: a use of it reads its operand,
|
||||
//! where the use stands. `select` computes the block-crossing values and `lower::emit` each block's
|
||||
|
||||
@@ -34,10 +34,8 @@
|
||||
//! function form from the argument (C++ pointer arithmetic stays within `[b, b + size]`, and a
|
||||
//! descriptor slot's range is at most `maxStorageBufferRange`), else the 2³² bytes from the
|
||||
//! window's start (every pointer an access reaches). A slot whose address only a compare observes
|
||||
//! is a `Whole` window. A wide pointer's address is its root entry's `guest + bind_offset +
|
||||
//! offset`. With `shaderInt64` the address is a `u64`; without it, two `u32` words compared high
|
||||
//! word first, and `SlotGuestBase` is placed as a `uvec2` on every profile (the same eight
|
||||
//! bytes).
|
||||
//! is a `Whole` window. A wide pointer's address is the `u64` it holds. Every address is a
|
||||
//! `u64`, and `SlotGuestBase` is placed as a `uvec2` (the same eight bytes).
|
||||
//!
|
||||
//! **Stored and converted pointers** ([`PointerValue::ToInt`], [`PointerValue::StorePointer`]).
|
||||
//! An escaping slot root stays static (`memory::plan`), so `ptrtoint` of a static fat pointer is
|
||||
@@ -59,7 +57,6 @@ use crate::air::ir::{
|
||||
};
|
||||
use crate::budget::Meter;
|
||||
use crate::error::{AccessCause, Error, Feature, Unsupported};
|
||||
use crate::lower::arith::wide::{self, Pair};
|
||||
use crate::lower::arith::{Form, Held};
|
||||
use crate::lower::emit::{EmitCx, SlotMemo};
|
||||
use crate::lower::select::SelectCx;
|
||||
@@ -126,36 +123,30 @@ pub enum PointerValue {
|
||||
start: Option<i64>,
|
||||
slot: Option<usize>,
|
||||
},
|
||||
/// `icmp` of Metal addresses, in two words without `shaderInt64` (`words`).
|
||||
/// `icmp` of Metal addresses.
|
||||
CompareAddresses {
|
||||
pred: IntPredicate,
|
||||
a: Addr,
|
||||
b: Addr,
|
||||
words: bool,
|
||||
},
|
||||
/// `ptrtoint` of a static fat pointer to `i<bits>`.
|
||||
ToInt { of: Addr, bits: u8, words: bool },
|
||||
ToInt { of: Addr, bits: u8 },
|
||||
/// A static fat pointer stored as its 8-byte Metal address through a static-root pointer, a
|
||||
/// wide pointer, or an arena's pointer cell.
|
||||
StorePointer {
|
||||
to: Box<Source>,
|
||||
value: Addr,
|
||||
words: bool,
|
||||
},
|
||||
StorePointer { to: Box<Source>, value: Addr },
|
||||
}
|
||||
|
||||
/// SPIR-V words of one candidate's address: the guest base, the displacement, the sum, and the
|
||||
/// root select (twice that in two words).
|
||||
/// root select.
|
||||
const CANDIDATE_WORDS: u32 = 48;
|
||||
|
||||
impl Addr {
|
||||
fn words(&self, two: bool) -> u32 {
|
||||
let per = if two { 2 } else { 1 };
|
||||
fn words(&self) -> u32 {
|
||||
match self {
|
||||
Addr::Null => 4,
|
||||
Addr::Static(s) => (s.targets.len() as u32 + u32::from(s.null))
|
||||
.saturating_add(1)
|
||||
.saturating_mul(CANDIDATE_WORDS * per),
|
||||
.saturating_mul(CANDIDATE_WORDS),
|
||||
Addr::Wide(_) => 80,
|
||||
}
|
||||
}
|
||||
@@ -166,10 +157,9 @@ impl PointerValue {
|
||||
/// Metal address carry `Volatile`; the refusal of any other strategy.
|
||||
pub(super) fn volatile(self) -> Result<PointerValue, Error> {
|
||||
match self {
|
||||
PointerValue::StorePointer { to, value, words } => Ok(PointerValue::StorePointer {
|
||||
PointerValue::StorePointer { to, value } => Ok(PointerValue::StorePointer {
|
||||
to: Box::new((*to).volatile()),
|
||||
value,
|
||||
words,
|
||||
}),
|
||||
_ => Err(refuse(AccessCause::Volatile)),
|
||||
}
|
||||
@@ -182,12 +172,7 @@ impl PointerValue {
|
||||
pub fn name(&self, slots: &AccessPlan) -> Cow<'static, str> {
|
||||
match self {
|
||||
PointerValue::CompareOffsets { .. } => "access.pointer.compare_offsets".into(),
|
||||
PointerValue::CompareAddresses { words: false, .. } => {
|
||||
"access.pointer.compare_addresses".into()
|
||||
}
|
||||
PointerValue::CompareAddresses { words: true, .. } => {
|
||||
"access.pointer.compare_addresses.words".into()
|
||||
}
|
||||
PointerValue::CompareAddresses { .. } => "access.pointer.compare_addresses".into(),
|
||||
PointerValue::ToInt { .. } => "access.pointer.ptrtoint".into(),
|
||||
PointerValue::StorePointer { to, .. } => match &**to {
|
||||
Source::Static(a) => a.reach(slots).qualify("access.pointer.store_pointer"),
|
||||
@@ -201,15 +186,13 @@ impl PointerValue {
|
||||
pub fn words(&self) -> u32 {
|
||||
match self {
|
||||
PointerValue::CompareOffsets { .. } => 24,
|
||||
PointerValue::CompareAddresses { a, b, words, .. } => a
|
||||
.words(*words)
|
||||
.saturating_add(b.words(*words))
|
||||
.saturating_add(if *words { 48 } else { 8 }),
|
||||
PointerValue::ToInt { of, words, .. } => of.words(*words).saturating_add(16),
|
||||
PointerValue::StorePointer { to, value, words } => to
|
||||
.words()
|
||||
.saturating_add(value.words(*words))
|
||||
.saturating_add(8),
|
||||
PointerValue::CompareAddresses { a, b, .. } => {
|
||||
a.words().saturating_add(b.words()).saturating_add(8)
|
||||
}
|
||||
PointerValue::ToInt { of, .. } => of.words().saturating_add(16),
|
||||
PointerValue::StorePointer { to, value } => {
|
||||
to.words().saturating_add(value.words()).saturating_add(8)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -415,18 +398,10 @@ fn compare(
|
||||
}
|
||||
}
|
||||
(Kind::Null | Kind::Fat | Kind::Wide, Kind::Null | Kind::Fat | Kind::Wide) => {
|
||||
let words = !cx.profile.fields().leaf.int64;
|
||||
let x = address(cx, a, &ka, m)?;
|
||||
let y = address(cx, b, &kb, m)?;
|
||||
if words && (matches!(x, Addr::Wide(_)) || matches!(y, Addr::Wide(_))) {
|
||||
// A wide pointer implies Profile A, which implies `shaderInt64`.
|
||||
return Err(cx.invariant("a wide pointer on a profile without shaderInt64"));
|
||||
}
|
||||
PointerValue::CompareAddresses {
|
||||
pred,
|
||||
a: x,
|
||||
b: y,
|
||||
words,
|
||||
a: address(cx, a, &ka, m)?,
|
||||
b: address(cx, b, &kb, m)?,
|
||||
}
|
||||
}
|
||||
_ => return Err(refuse(AccessCause::PointerCompare)),
|
||||
@@ -446,19 +421,14 @@ fn static_escape(cx: &SelectCx<'_>, v: Value) -> Result<Option<Kind>, Error> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The 8-byte leaf of a stored Metal address of AIR pointer type `ty` (a `u64`, or two words
|
||||
/// without `shaderInt64`).
|
||||
/// The 8-byte leaf of a stored Metal address of AIR pointer type `ty` (a `u64`).
|
||||
fn address_leaf(cx: &SelectCx<'_>, ty: TypeId, align: Option<Align>) -> Result<Leaf, Error> {
|
||||
if cx.memory.layouts.store_size(ty) != Some(8) {
|
||||
return Err(refuse(AccessCause::PointerSize));
|
||||
}
|
||||
let held = if cx.profile.fields().leaf.int64 {
|
||||
Held::Int {
|
||||
bits: 64,
|
||||
container: 64,
|
||||
}
|
||||
} else {
|
||||
Held::Wide { bits: 64 }
|
||||
let held = Held::Int {
|
||||
bits: 64,
|
||||
container: 64,
|
||||
};
|
||||
Ok(Leaf {
|
||||
form: Form { held, lanes: 1 },
|
||||
@@ -499,11 +469,9 @@ fn store_pointer(
|
||||
}
|
||||
_ => dynamic::store_destination(cx, ptr, leaf)?,
|
||||
};
|
||||
let words = !cx.profile.fields().leaf.int64;
|
||||
Ok(PointerValue::StorePointer {
|
||||
to: Box::new(to),
|
||||
value: address(cx, val, &k, m)?,
|
||||
words,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -537,11 +505,9 @@ pub fn select(
|
||||
Some(Type::Int(b @ 1..=64)) => *b,
|
||||
_ => return Err(refuse(AccessCause::PointerInteger)),
|
||||
};
|
||||
let words = !cx.profile.fields().leaf.int64;
|
||||
Ok(Some(PointerValue::ToInt {
|
||||
of: address(cx, *v, &k, m)?,
|
||||
bits,
|
||||
words,
|
||||
}))
|
||||
}
|
||||
InstKind::Store {
|
||||
@@ -682,100 +648,6 @@ fn null_thread_source(cx: &EmitCx<'_>, v: ValueId) -> bool {
|
||||
)
|
||||
}
|
||||
|
||||
/// A 64-bit Metal address: a `u64`, or its two words without `shaderInt64`.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
enum Address {
|
||||
U64(SValue),
|
||||
Words(Pair),
|
||||
}
|
||||
|
||||
fn zero(fb: &mut FunctionBuilder<'_>, words: bool) -> BResult<Address> {
|
||||
Ok(if words {
|
||||
let z = k32(fb, 0)?;
|
||||
Address::Words(Pair { lo: z, hi: z })
|
||||
} else {
|
||||
Address::U64(k64(fb, 0)?)
|
||||
})
|
||||
}
|
||||
|
||||
fn mismatch(cx: &mut EmitCx<'_>) -> crate::spirv::error::BuildError {
|
||||
cx.fail("a Metal address in two forms")
|
||||
}
|
||||
|
||||
fn add(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
a: Address,
|
||||
b: Address,
|
||||
) -> BResult<Address> {
|
||||
match (a, b) {
|
||||
(Address::U64(x), Address::U64(y)) => Ok(Address::U64(fb.binary(BinOp::IAdd, x, y)?)),
|
||||
(Address::Words(x), Address::Words(y)) => Ok(Address::Words(wide::add(fb, x, y)?)),
|
||||
_ => Err(mismatch(cx)),
|
||||
}
|
||||
}
|
||||
|
||||
fn pick(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
c: SValue,
|
||||
a: Address,
|
||||
b: Address,
|
||||
) -> BResult<Address> {
|
||||
match (a, b) {
|
||||
(Address::U64(x), Address::U64(y)) => Ok(Address::U64(fb.select(c, x, y)?)),
|
||||
(Address::Words(x), Address::Words(y)) => Ok(Address::Words(wide::sel(fb, c, x, y)?)),
|
||||
_ => Err(mismatch(cx)),
|
||||
}
|
||||
}
|
||||
|
||||
/// The displacement `start + zext((m − start) mod 2³²)` the `u32` offset `m` stands for.
|
||||
fn displacement(
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
m: SValue,
|
||||
start: i64,
|
||||
words: bool,
|
||||
) -> BResult<Address> {
|
||||
if !words {
|
||||
return Ok(Address::U64(psb::displacement(fb, m, start)?));
|
||||
}
|
||||
let z = k32(fb, 0)?;
|
||||
if start == 0 {
|
||||
return Ok(Address::Words(Pair { lo: m, hi: z }));
|
||||
}
|
||||
// The two's-complement bits of `start` are its value modulo 2³² and 2⁶⁴.
|
||||
let low = k32(fb, start as u32)?;
|
||||
let rel = fb.binary(BinOp::ISub, m, low)?;
|
||||
let high = k32(fb, ((start as u64) >> 32) as u32)?;
|
||||
Ok(Address::Words(wide::add(
|
||||
fb,
|
||||
Pair { lo: low, hi: high },
|
||||
Pair { lo: rel, hi: z },
|
||||
)?))
|
||||
}
|
||||
|
||||
/// Buffer slot `slot`'s Metal address ([`slot_address`]) in the address form.
|
||||
fn guest_base(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
slot: SlotRef,
|
||||
words: bool,
|
||||
) -> BResult<Address> {
|
||||
if !words {
|
||||
return Ok(Address::U64(slot_address(cx, fb, slot)?));
|
||||
}
|
||||
let v = cx.push_field(fb, PushField::SlotGuestBase(slot))?;
|
||||
let word = wide::split(fb, v)?;
|
||||
if !biased(cx) {
|
||||
return Ok(Address::Words(word));
|
||||
}
|
||||
let bias = Pair {
|
||||
lo: k32(fb, super::SLOT_ADDRESS_BIAS as u32)?,
|
||||
hi: k32(fb, 0)?,
|
||||
};
|
||||
Ok(Address::Words(wide::add(fb, word, bias)?))
|
||||
}
|
||||
|
||||
/// Whether buffer slots' `SlotGuestBase` words are their Metal addresses less
|
||||
/// [`SLOT_ADDRESS_BIAS`](super::SLOT_ADDRESS_BIAS), as the runtime pushes them. A replay variant
|
||||
/// reads each slot's address itself from its root entry.
|
||||
@@ -783,8 +655,7 @@ fn biased(cx: &EmitCx<'_>) -> bool {
|
||||
!cx.plan.families.access.replay
|
||||
}
|
||||
|
||||
/// Buffer slot `slot`'s `SlotGuestBase` word (a `uvec2`, low word first) as a `u64` (needs
|
||||
/// `shaderInt64`).
|
||||
/// Buffer slot `slot`'s `SlotGuestBase` word (a `uvec2`, low word first) as a `u64`.
|
||||
fn slot_word(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, slot: SlotRef) -> BResult<SValue> {
|
||||
let v = cx.push_field(fb, PushField::SlotGuestBase(slot))?;
|
||||
let u64_ = fb.module().ty(SType::Int {
|
||||
@@ -795,7 +666,7 @@ fn slot_word(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, slot: SlotRef) -
|
||||
}
|
||||
|
||||
/// Buffer slot `slot`'s Metal address, the bound buffer's `gpuAddress` plus the bind offset, as a
|
||||
/// `u64` (needs `shaderInt64`): its `SlotGuestBase` word, plus
|
||||
/// `u64`: its `SlotGuestBase` word, plus
|
||||
/// [`SLOT_ADDRESS_BIAS`](super::SLOT_ADDRESS_BIAS) where the word is biased ([`biased`]), added to
|
||||
/// the low word with the carry into the high word (`psb::add_slot_offset`). Made once, before the
|
||||
/// body ([`make_ahead`]). What a pointer compare, a converted or stored pointer, and an access
|
||||
@@ -846,19 +717,19 @@ pub(super) fn direct_base(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
slot: SlotRef,
|
||||
) -> BResult<Pair> {
|
||||
) -> BResult<psb::Pair> {
|
||||
let (lo, hi) = (
|
||||
SlotMemo::DirectBase(slot, false),
|
||||
SlotMemo::DirectBase(slot, true),
|
||||
);
|
||||
if let (Some(lo), Some(hi)) = (cx.recall_slot(fb, lo), cx.recall_slot(fb, hi)) {
|
||||
return Ok(Pair { lo, hi });
|
||||
return Ok(psb::Pair { lo, hi });
|
||||
}
|
||||
if !biased(cx) {
|
||||
return Err(cx.fail("a direct access of a slot whose SlotGuestBase word is not biased"));
|
||||
}
|
||||
let v = cx.push_field(fb, PushField::SlotGuestBase(slot))?;
|
||||
let base = wide::split(fb, v)?;
|
||||
let base = psb::split(fb, v)?;
|
||||
cx.remember_slot(fb, lo, base.lo);
|
||||
cx.remember_slot(fb, hi, base.hi);
|
||||
Ok(base)
|
||||
@@ -886,42 +757,32 @@ fn window_start(cx: &mut EmitCx<'_>, slot: usize) -> BResult<(SlotRef, i64)> {
|
||||
Ok((choice.slot, start))
|
||||
}
|
||||
|
||||
/// The Metal address of `a` in the open block.
|
||||
fn emit_address(
|
||||
cx: &mut EmitCx<'_>,
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
a: &Addr,
|
||||
words: bool,
|
||||
) -> BResult<Address> {
|
||||
/// The Metal address of `a` (a `u64`) in the open block.
|
||||
fn emit_address(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, a: &Addr) -> BResult<SValue> {
|
||||
match a {
|
||||
Addr::Null => zero(fb, words),
|
||||
Addr::Wide(p) => {
|
||||
if words {
|
||||
return Err(cx.fail("a wide pointer's address in two words"));
|
||||
}
|
||||
// A wide pointer is the address it holds.
|
||||
Ok(Address::U64(cx.operand(fb, *p)?))
|
||||
}
|
||||
Addr::Null => k64(fb, 0),
|
||||
// A wide pointer is the address it holds.
|
||||
Addr::Wide(p) => cx.operand(fb, *p),
|
||||
Addr::Static(s) => {
|
||||
let fat = cx.operand(fb, s.ptr)?;
|
||||
let root = fat_part(fb, fat, 0)?;
|
||||
let m = fat_part(fb, fat, 1)?;
|
||||
let mut acc = if s.null {
|
||||
Some(displacement(fb, m, s.start.unwrap_or(0), words)?)
|
||||
Some(psb::displacement(fb, m, s.start.unwrap_or(0))?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
for &(slot, r) in &s.targets {
|
||||
let (slot, window) = window_start(cx, slot)?;
|
||||
let base = guest_base(cx, fb, slot, words)?;
|
||||
let d = displacement(fb, m, s.start.unwrap_or(window), words)?;
|
||||
let here = add(cx, fb, base, d)?;
|
||||
let base = slot_address(cx, fb, slot)?;
|
||||
let d = psb::displacement(fb, m, s.start.unwrap_or(window))?;
|
||||
let here = fb.binary(BinOp::IAdd, base, d)?;
|
||||
acc = Some(match acc {
|
||||
None => here,
|
||||
Some(prev) => {
|
||||
let rk = k32(fb, r)?;
|
||||
let is = fb.binary(BinOp::IEqual, root, rk)?;
|
||||
pick(cx, fb, is, here, prev)?
|
||||
fb.select(is, here, prev)?
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -959,32 +820,21 @@ fn offset_value(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, o: Offset) ->
|
||||
}
|
||||
}
|
||||
|
||||
/// Address `a` truncated to `i<bits>`, held as its value family holds it: an `i1` as a `bool` (the
|
||||
/// low bit), up to 32 bits zero-extended in a `u32`, a wider integer masked in a `u64` or, in two
|
||||
/// words, as `Held::Wide`.
|
||||
fn truncated(fb: &mut FunctionBuilder<'_>, a: Address, bits: u8) -> BResult<SValue> {
|
||||
let low = match a {
|
||||
Address::U64(x) if bits > 32 => {
|
||||
if bits == 64 {
|
||||
return Ok(x);
|
||||
}
|
||||
let m = k64(fb, (1u64 << bits) - 1)?;
|
||||
return fb.binary(BinOp::BitwiseAnd, x, m);
|
||||
/// Address `x` (a `u64`) truncated to `i<bits>`, held as its value family holds it: an `i1` as a
|
||||
/// `bool` (the low bit), up to 32 bits zero-extended in a `u32`, a wider integer masked in a `u64`.
|
||||
fn truncated(fb: &mut FunctionBuilder<'_>, x: SValue, bits: u8) -> BResult<SValue> {
|
||||
if bits > 32 {
|
||||
if bits == 64 {
|
||||
return Ok(x);
|
||||
}
|
||||
Address::Words(p) if bits > 32 => {
|
||||
let f = wide::wide_form(bits, 1);
|
||||
let p = wide::mask_top(fb, f, p)?;
|
||||
return wide::join(fb, f, p);
|
||||
}
|
||||
Address::U64(x) => {
|
||||
let u32_ = fb.module().ty(SType::Int {
|
||||
width: 32,
|
||||
signed: false,
|
||||
})?;
|
||||
fb.convert(ConvOp::UConvert, x, u32_)?
|
||||
}
|
||||
Address::Words(p) => p.lo,
|
||||
};
|
||||
let m = k64(fb, (1u64 << bits) - 1)?;
|
||||
return fb.binary(BinOp::BitwiseAnd, x, m);
|
||||
}
|
||||
let u32_ = fb.module().ty(SType::Int {
|
||||
width: 32,
|
||||
signed: false,
|
||||
})?;
|
||||
let low = fb.convert(ConvOp::UConvert, x, u32_)?;
|
||||
match bits {
|
||||
1 => {
|
||||
let one = k32(fb, 1)?;
|
||||
@@ -1000,14 +850,6 @@ fn truncated(fb: &mut FunctionBuilder<'_>, a: Address, bits: u8) -> BResult<SVal
|
||||
}
|
||||
}
|
||||
|
||||
/// Address `a` as the register value of an 8-byte address leaf.
|
||||
fn address_value(fb: &mut FunctionBuilder<'_>, a: Address) -> BResult<SValue> {
|
||||
match a {
|
||||
Address::U64(x) => Ok(x),
|
||||
Address::Words(p) => wide::join(fb, wide::wide_form(64, 1), p),
|
||||
}
|
||||
}
|
||||
|
||||
/// Emit pointer-value strategy `s`, defining value `vid`.
|
||||
pub fn emit(
|
||||
cx: &mut EmitCx<'_>,
|
||||
@@ -1039,27 +881,17 @@ pub fn emit(
|
||||
}
|
||||
fb.binary(predicate_op(*pred), x, y)?
|
||||
}
|
||||
PointerValue::CompareAddresses { pred, a, b, words } => {
|
||||
let x = emit_address(cx, fb, a, *words)?;
|
||||
let y = emit_address(cx, fb, b, *words)?;
|
||||
match (x, y) {
|
||||
(Address::U64(x), Address::U64(y)) => fb.binary(predicate_op(*pred), x, y)?,
|
||||
(Address::Words(x), Address::Words(y)) => {
|
||||
let f = wide::wide_form(64, 1);
|
||||
let x = wide::join(fb, f, x)?;
|
||||
let y = wide::join(fb, f, y)?;
|
||||
wide::int_compare(fb, *pred, f, x, y)?
|
||||
}
|
||||
_ => return Err(mismatch(cx)),
|
||||
}
|
||||
PointerValue::CompareAddresses { pred, a, b } => {
|
||||
let x = emit_address(cx, fb, a)?;
|
||||
let y = emit_address(cx, fb, b)?;
|
||||
fb.binary(predicate_op(*pred), x, y)?
|
||||
}
|
||||
PointerValue::ToInt { of, bits, words } => {
|
||||
let a = emit_address(cx, fb, of, *words)?;
|
||||
PointerValue::ToInt { of, bits } => {
|
||||
let a = emit_address(cx, fb, of)?;
|
||||
truncated(fb, a, *bits)?
|
||||
}
|
||||
PointerValue::StorePointer { to, value, words } => {
|
||||
let a = emit_address(cx, fb, value, *words)?;
|
||||
let v = address_value(fb, a)?;
|
||||
PointerValue::StorePointer { to, value } => {
|
||||
let v = emit_address(cx, fb, value)?;
|
||||
match &**to {
|
||||
Source::Static(to) => {
|
||||
let p = cx.operand(fb, to.ptr)?;
|
||||
|
||||
@@ -46,7 +46,6 @@
|
||||
|
||||
use super::SLOT_ADDRESS_BIAS;
|
||||
use crate::device::DeviceProfile;
|
||||
use crate::lower::arith::wide;
|
||||
use crate::memory::leaf::{k32, u32_op, Units, WordMem, WordOps};
|
||||
use crate::spirv::builder::FunctionBuilder;
|
||||
use crate::spirv::error::BResult;
|
||||
@@ -62,19 +61,39 @@ fn u64_ty(fb: &mut FunctionBuilder<'_>) -> BResult<TypeId> {
|
||||
})
|
||||
}
|
||||
|
||||
/// A `u64` as its two `u32` words, low word first.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Pair {
|
||||
pub lo: Value,
|
||||
pub hi: Value,
|
||||
}
|
||||
|
||||
/// The two words of `uvec2` `x`, low word first.
|
||||
pub fn split(fb: &mut FunctionBuilder<'_>, x: Value) -> BResult<Pair> {
|
||||
Ok(Pair {
|
||||
lo: fb.composite_extract(x, &[0])?,
|
||||
hi: fb.composite_extract(x, &[1])?,
|
||||
})
|
||||
}
|
||||
|
||||
/// A device address as a `u64`: `base` (its low and high words) plus the `u32` `offset` read as
|
||||
/// unsigned, added to the low word with the carry into the high word, so no 64-bit add takes a
|
||||
/// constant. One `OpIAddCarry`, its two words, one add of the carry, and the words joined.
|
||||
pub(super) fn add_slot_offset(
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
base: wide::Pair,
|
||||
base: Pair,
|
||||
offset: Value,
|
||||
) -> BResult<Value> {
|
||||
let sum = fb.binary(BinOp::IAddCarry, base.lo, offset)?;
|
||||
let lo = fb.composite_extract(sum, &[0])?;
|
||||
let carry = fb.composite_extract(sum, &[1])?;
|
||||
let hi = fb.binary(BinOp::IAdd, base.hi, carry)?;
|
||||
let words = wide::join(fb, wide::wide_form(64, 1), wide::Pair { lo, hi })?;
|
||||
let u32_ = fb.module().ty(Type::Int {
|
||||
width: 32,
|
||||
signed: false,
|
||||
})?;
|
||||
let uvec2 = fb.module().ty(Type::Vector { elem: u32_, len: 2 })?;
|
||||
let words = fb.composite_construct(uvec2, &[lo, hi])?;
|
||||
let address = u64_ty(fb)?;
|
||||
fb.convert(ConvOp::Bitcast, words, address)
|
||||
}
|
||||
@@ -163,7 +182,7 @@ enum Reach {
|
||||
/// ([`add_slot_offset`]); the base's words are made once where they dominate
|
||||
/// (`pointer::direct_base`). The address holds the binder's alignment
|
||||
/// (`RuntimeFact::AddressAlignment`), the first field.
|
||||
Direct(u32, wide::Pair),
|
||||
Direct(u32, Pair),
|
||||
}
|
||||
|
||||
/// Prepare an access of a static slot at the `u32` displacement `m` from its bind offset, read as
|
||||
@@ -197,7 +216,7 @@ pub fn prepare_at(fb: &mut FunctionBuilder<'_>, address: Value, m: Value) -> BRe
|
||||
/// buffer lies within 2^31 bytes of each bind address in it, the runtime making no buffer longer
|
||||
/// than 2 GiB (`metal2vulkan_runtime::MAX_BUFFER_LENGTH`), so the offset is exact whatever the
|
||||
/// slot's window. Nothing is rounded. The check, where the access takes one, is `emit::prepare`'s.
|
||||
pub fn prepare_direct(base: wide::Pair, m: Value, held: u32) -> PsbAccess {
|
||||
pub fn prepare_direct(base: Pair, m: Value, held: u32) -> PsbAccess {
|
||||
PsbAccess {
|
||||
mem: PsbMem {
|
||||
reach: Reach::Direct(held, base),
|
||||
|
||||
@@ -30,8 +30,7 @@ fn shape_type(mb: &mut ModuleBuilder, sh: FieldShape) -> BResult<TypeId> {
|
||||
})?;
|
||||
match sh {
|
||||
FieldShape::U32 => Ok(u32_),
|
||||
// Only address fields are 64-bit; they are placed only where device addresses (and
|
||||
// `shaderInt64`) are.
|
||||
// Only address fields are 64-bit.
|
||||
FieldShape::U64 => mb.ty(Type::Int {
|
||||
width: 64,
|
||||
signed: false,
|
||||
|
||||
@@ -733,17 +733,10 @@ fn emit_build(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, b: &Build) -> B
|
||||
}
|
||||
fb.composite_extract(x, path)
|
||||
}
|
||||
Build::Const(k) => {
|
||||
let k = if cx.plan.families.arith.wide {
|
||||
legal::widen_const(k.clone())
|
||||
} else {
|
||||
k.clone()
|
||||
};
|
||||
match super::materialize(fb, &k)? {
|
||||
Some(x) => Ok(x),
|
||||
None => Err(cx.fail("a member constant arith does not materialize")),
|
||||
}
|
||||
}
|
||||
Build::Const(k) => match super::materialize(fb, k)? {
|
||||
Some(x) => Ok(x),
|
||||
None => Err(cx.fail("a member constant arith does not materialize")),
|
||||
},
|
||||
Build::Zero(d) => zero_value(cx, fb, d),
|
||||
Build::Parts { ty, parts } => {
|
||||
let mut xs = Vec::with_capacity(parts.len());
|
||||
|
||||
@@ -22,12 +22,6 @@
|
||||
//! moves as its format bits, a 64-bit lane as a word pair), so no 64-bit integer is needed
|
||||
//! for the move itself.
|
||||
//!
|
||||
//! - **Two-word lanes**: without `shaderInt64` a chunk of 64-bit integer lanes is their wide
|
||||
//! representation (a `uvec2` for a one-lane chunk, else a struct of the low-word and high-word
|
||||
//! vectors), a lane-wise operation is the wide lowering's per chunk (`wide::select_in`), a lane
|
||||
//! move moves both words of the lane, a dynamic index of 64 bits reads its low word (an index of
|
||||
//! `2^32` or more is out of range), and a bitcast takes the lane's words as they are.
|
||||
//!
|
||||
//! - **`dot`** of chunked vectors sums each chunk's `OpDot` (a product for a one-lane chunk) in
|
||||
//! `f32` and rounds a narrow result once; **`sincos`** of one takes each chunk's sine and
|
||||
//! cosine, and its cosine is stored as one chunked leaf (`memory::leaf`).
|
||||
@@ -42,7 +36,7 @@ use crate::error::Error;
|
||||
use crate::lower::arith::legal::{self, chunk_lanes, not_lowered, Form, Held};
|
||||
use crate::lower::arith::libm::Lib;
|
||||
use crate::lower::arith::math::{self, FloatFn};
|
||||
use crate::lower::arith::{narrow, operands_of, ops, wide, ArithStrategy};
|
||||
use crate::lower::arith::{narrow, operands_of, ops, ArithStrategy};
|
||||
use crate::lower::emit::EmitCx;
|
||||
use crate::lower::select::SelectCx;
|
||||
use crate::spirv::builder::FunctionBuilder;
|
||||
@@ -68,9 +62,8 @@ impl Shape {
|
||||
}
|
||||
}
|
||||
|
||||
/// Where lane `i` lives: its member path, or, for a lane of two words inside a vector of two
|
||||
/// or more lanes, the paths of its low and high words.
|
||||
fn path(self, i: u32) -> LanePath {
|
||||
/// Where lane `i` lives: its member path (the value itself when empty).
|
||||
fn path(self, i: u32) -> Vec<u32> {
|
||||
let (mut prefix, size, j) = if self.chunked {
|
||||
let c = i / 4;
|
||||
let sizes = chunk_lanes(u32::from(self.lanes));
|
||||
@@ -78,17 +71,10 @@ impl Shape {
|
||||
} else {
|
||||
(Vec::new(), u8::try_from(self.lanes).unwrap_or(1), i)
|
||||
};
|
||||
if size == 1 {
|
||||
return LanePath::Whole(prefix);
|
||||
if size > 1 {
|
||||
prefix.push(j);
|
||||
}
|
||||
if matches!(self.held, Held::Wide { .. }) {
|
||||
let mut hi = prefix.clone();
|
||||
prefix.extend([0, j]);
|
||||
hi.extend([1, j]);
|
||||
return LanePath::Words(prefix, hi);
|
||||
}
|
||||
prefix.push(j);
|
||||
LanePath::Whole(prefix)
|
||||
prefix
|
||||
}
|
||||
|
||||
/// The form of one lane.
|
||||
@@ -109,8 +95,7 @@ impl Shape {
|
||||
}
|
||||
}
|
||||
|
||||
/// The shape of AIR type `ty` on the profile (64-bit integer lanes as two words without
|
||||
/// `shaderInt64`), or the refusal of one arith does not hold.
|
||||
/// The shape of AIR type `ty` on the profile, or the refusal of one arith does not hold.
|
||||
pub(super) fn shape_of(cx: &SelectCx<'_>, ty: AirTypeId) -> Result<Shape, Error> {
|
||||
if let Some((held, lanes)) = legal::chunked(cx.entry.module.types(), ty) {
|
||||
let held = legal::held_on(cx.profile, held)?;
|
||||
@@ -121,7 +106,7 @@ pub(super) fn shape_of(cx: &SelectCx<'_>, ty: AirTypeId) -> Result<Shape, Error>
|
||||
chunked: true,
|
||||
});
|
||||
}
|
||||
let f = legal::wide_form_on(cx.entry, cx.profile, ty)?;
|
||||
let f = legal::form_on(cx.entry, cx.profile, ty)?;
|
||||
Ok(Shape {
|
||||
held: f.held,
|
||||
lanes: u16::from(f.lanes),
|
||||
@@ -129,14 +114,6 @@ pub(super) fn shape_of(cx: &SelectCx<'_>, ty: AirTypeId) -> Result<Shape, Error>
|
||||
})
|
||||
}
|
||||
|
||||
/// Where one lane of a scalar, vector, or chunked value lives ([`Shape::path`]).
|
||||
enum LanePath {
|
||||
/// The member at this path (the value itself when empty).
|
||||
Whole(Vec<u32>),
|
||||
/// A two-word lane: its low word and its high word, each a component of a word vector.
|
||||
Words(Vec<u32>, Vec<u32>),
|
||||
}
|
||||
|
||||
/// Whether `ty` is a chunked vector type.
|
||||
fn is_chunked(cx: &SelectCx<'_>, ty: AirTypeId) -> bool {
|
||||
legal::chunked(cx.entry.module.types(), ty).is_some()
|
||||
@@ -183,14 +160,13 @@ fn lanes_of(cx: &SelectCx<'_>, inst: &Inst) -> Option<u32> {
|
||||
.map(|(_, n)| n)
|
||||
}
|
||||
|
||||
/// The integer form of a dynamic lane index `v` (a held integer, or two words, of which the low
|
||||
/// one names the lane: an index of `2^32` or more is out of range), or a refusal.
|
||||
/// The integer form of a dynamic lane index `v` (a held integer), or a refusal.
|
||||
fn index_form(cx: &SelectCx<'_>, v: Value) -> Result<Form, Error> {
|
||||
let t = cx
|
||||
.value_ty(v)
|
||||
.ok_or_else(|| cx.invariant("a lane index without a type"))?;
|
||||
let f = legal::wide_form_on(cx.entry, cx.profile, t)?;
|
||||
if !(f.is_int() || f.is_wide()) || f.lanes != 1 {
|
||||
let f = legal::form_on(cx.entry, cx.profile, t)?;
|
||||
if !f.is_int() || f.lanes != 1 {
|
||||
return Err(not_lowered());
|
||||
}
|
||||
Ok(f)
|
||||
@@ -325,16 +301,10 @@ pub fn select(
|
||||
// (`dot`) is not lowered per chunk.
|
||||
return Err(not_lowered());
|
||||
}
|
||||
// Chunks of two-word lanes are the wide lowering's.
|
||||
let wide_lanes = wide::involved_chunked(cx, inst);
|
||||
let mut parts: Vec<(u8, ArithStrategy)> = Vec::new();
|
||||
for k in chunk_lanes(n) {
|
||||
if parts.iter().all(|(s, _)| *s != k) {
|
||||
let part = if wide_lanes {
|
||||
wide::select_in(cx, at, inst, Some(k))?
|
||||
} else {
|
||||
super::select_in(cx, at, inst, Some(k), m)?
|
||||
};
|
||||
let part = super::select_in(cx, at, inst, Some(k), m)?;
|
||||
parts.push((k, part));
|
||||
}
|
||||
}
|
||||
@@ -534,39 +504,16 @@ pub enum LaneMove {
|
||||
Shuffle,
|
||||
}
|
||||
|
||||
/// Words to read a two-word lane ([`lane`]): two `OpCompositeExtract` of at most 3 indices (7
|
||||
/// words each) and the `uvec2` construct (5).
|
||||
const WIDE_READ: u32 = 2 * 7 + 5;
|
||||
/// Words to write a two-word lane ([`with_lane`]): its split (two 1-index extracts, 5 words each)
|
||||
/// and two `OpCompositeInsert` of at most 3 indices (8 each).
|
||||
const WIDE_WRITE: u32 = 2 * 5 + 2 * 8;
|
||||
/// A two-word lane's share of building a vector ([`build`]): its split (10 words), its
|
||||
/// constituent in the low-word and high-word constructs (2), and at most half of a 2-lane
|
||||
/// chunk's two construct headers, join, and member constituent (`(2 * 3 + 5 + 1) / 2`).
|
||||
const WIDE_BUILD: u32 = 2 * 5 + 2 + 6;
|
||||
/// Words per lane of a dynamic index: the lane constant (4), `OpIEqual` (5), `OpSelect` (6).
|
||||
const PICK: u32 = 4 + 5 + 6;
|
||||
|
||||
/// An upper estimate of the SPIR-V words of lane move `m` on shape `s` (dynamic: by a dynamic
|
||||
/// index), from the emission below. A lane held whole is one extract or insert (the flat bounds); a
|
||||
/// two-word lane is read, written, and gathered word by word (19, 26, and 18 words, and 15 per lane
|
||||
/// of a dynamic index), each move with 8 words of slack for a new type.
|
||||
/// index), from the emission below: a lane is held whole, so a constant move is one extract or
|
||||
/// insert.
|
||||
pub fn move_words(s: Shape, m: LaneMove, dynamic: bool) -> u32 {
|
||||
let n = s.lanes;
|
||||
if !matches!(s.held, Held::Wide { .. }) {
|
||||
return match (m, dynamic) {
|
||||
(LaneMove::Extract | LaneMove::Insert, false) => 8,
|
||||
(LaneMove::Extract, true) => lane_words(n, 24),
|
||||
(LaneMove::Insert, true) => lane_words(n, 40),
|
||||
(LaneMove::Shuffle, _) => lane_words(n, 16),
|
||||
};
|
||||
}
|
||||
match (m, dynamic) {
|
||||
(LaneMove::Extract, false) => WIDE_READ + 8,
|
||||
(LaneMove::Insert, false) => WIDE_WRITE + 8,
|
||||
(LaneMove::Extract, true) => lane_words(n, WIDE_READ + PICK) + 8,
|
||||
(LaneMove::Insert, true) => lane_words(n, WIDE_READ + PICK + WIDE_BUILD) + 8,
|
||||
(LaneMove::Shuffle, _) => lane_words(n, WIDE_READ + WIDE_BUILD) + 8,
|
||||
(LaneMove::Extract | LaneMove::Insert, false) => 8,
|
||||
(LaneMove::Extract, true) => lane_words(n, 24),
|
||||
(LaneMove::Insert, true) => lane_words(n, 40),
|
||||
(LaneMove::Shuffle, _) => lane_words(n, 16),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,17 +532,13 @@ fn operand_error() -> BuildError {
|
||||
}
|
||||
}
|
||||
|
||||
/// Lane `i` of `v` (shape `s`) as a scalar (a two-word lane as its `uvec2`).
|
||||
/// Lane `i` of `v` (shape `s`) as a scalar.
|
||||
fn lane(fb: &mut FunctionBuilder<'_>, s: Shape, v: SValue, i: u32) -> BResult<SValue> {
|
||||
match s.path(i) {
|
||||
LanePath::Whole(p) if p.is_empty() => Ok(v),
|
||||
LanePath::Whole(p) => fb.composite_extract(v, &p),
|
||||
LanePath::Words(lo, hi) => {
|
||||
let lo = fb.composite_extract(v, &lo)?;
|
||||
let hi = fb.composite_extract(v, &hi)?;
|
||||
wide::join(fb, s.lane_form(), wide::Pair { lo, hi })
|
||||
}
|
||||
let p = s.path(i);
|
||||
if p.is_empty() {
|
||||
return Ok(v);
|
||||
}
|
||||
fb.composite_extract(v, &p)
|
||||
}
|
||||
|
||||
/// `v` (shape `s`) with lane `i` replaced by scalar `x`.
|
||||
@@ -606,15 +549,11 @@ fn with_lane(
|
||||
i: u32,
|
||||
x: SValue,
|
||||
) -> BResult<SValue> {
|
||||
match s.path(i) {
|
||||
LanePath::Whole(p) if p.is_empty() => Ok(x),
|
||||
LanePath::Whole(p) => fb.composite_insert(x, v, &p),
|
||||
LanePath::Words(lo, hi) => {
|
||||
let w = wide::split(fb, x)?;
|
||||
let v = fb.composite_insert(w.lo, v, &lo)?;
|
||||
fb.composite_insert(w.hi, v, &hi)
|
||||
}
|
||||
let p = s.path(i);
|
||||
if p.is_empty() {
|
||||
return Ok(x);
|
||||
}
|
||||
fb.composite_insert(x, v, &p)
|
||||
}
|
||||
|
||||
/// Every lane of `v` (shape `s`) as a scalar.
|
||||
@@ -626,28 +565,14 @@ fn lanes(fb: &mut FunctionBuilder<'_>, s: Shape, v: SValue) -> BResult<Vec<SValu
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The scalar or vector of `xs.len()` lanes of `held` with scalar lanes `xs` (two-word lanes
|
||||
/// gathered into their low-word and high-word vectors).
|
||||
/// The scalar or vector of `xs.len()` lanes of `held` with scalar lanes `xs`.
|
||||
fn vector_of(fb: &mut FunctionBuilder<'_>, held: Held, xs: &[SValue]) -> BResult<SValue> {
|
||||
let lanes = u8::try_from(xs.len()).map_err(|_| operand_error())?;
|
||||
if lanes == 1 {
|
||||
return xs.first().copied().ok_or_else(operand_error);
|
||||
}
|
||||
let f = Form { held, lanes };
|
||||
if !f.is_wide() {
|
||||
let t = ops::ty(fb, f)?;
|
||||
return fb.composite_construct(t, xs);
|
||||
}
|
||||
let t = ops::ty(fb, wide::words_form(lanes))?;
|
||||
let (mut los, mut his) = (Vec::with_capacity(xs.len()), Vec::with_capacity(xs.len()));
|
||||
for x in xs {
|
||||
let w = wide::split(fb, *x)?;
|
||||
los.push(w.lo);
|
||||
his.push(w.hi);
|
||||
}
|
||||
let lo = fb.composite_construct(t, &los)?;
|
||||
let hi = fb.composite_construct(t, &his)?;
|
||||
wide::join(fb, f, wide::Pair { lo, hi })
|
||||
let t = ops::ty(fb, Form { held, lanes })?;
|
||||
fb.composite_construct(t, xs)
|
||||
}
|
||||
|
||||
/// The value of shape `s` with scalar lanes `xs`.
|
||||
@@ -668,16 +593,6 @@ fn build(fb: &mut FunctionBuilder<'_>, s: Shape, xs: &[SValue]) -> BResult<SValu
|
||||
fb.composite_construct(t, &members)
|
||||
}
|
||||
|
||||
/// A dynamic lane index `i` of form `index` as a held integer: a two-word index's low word (an
|
||||
/// index of `2^32` or more is out of range, so any lane or none will do).
|
||||
fn index_value(fb: &mut FunctionBuilder<'_>, index: Form, i: SValue) -> BResult<(Form, SValue)> {
|
||||
if index.is_wide() {
|
||||
Ok((wide::words_form(1), wide::low_word(fb, i)?))
|
||||
} else {
|
||||
Ok((index, i))
|
||||
}
|
||||
}
|
||||
|
||||
/// Emit a lane-wise operation per chunk: `parts` holds the operation per chunk size, `wide`
|
||||
/// which operands are chunked.
|
||||
pub fn emit_chunked(
|
||||
@@ -734,7 +649,6 @@ pub fn extract(
|
||||
(Some(i), _) => lane(fb, src, v, i),
|
||||
(None, Some(f)) => {
|
||||
let i = xs.get(1).copied().ok_or_else(operand_error)?;
|
||||
let (f, i) = index_value(fb, f, i)?;
|
||||
let ls = lanes(fb, src, v)?;
|
||||
pick(fb, f, i, &ls)
|
||||
}
|
||||
@@ -756,7 +670,6 @@ pub fn insert(
|
||||
(Some(i), _) => with_lane(fb, dst, v, i, e),
|
||||
(None, Some(f)) => {
|
||||
let i = xs.get(2).copied().ok_or_else(operand_error)?;
|
||||
let (f, i) = index_value(fb, f, i)?;
|
||||
let mut ls = lanes(fb, dst, v)?;
|
||||
for (k, l) in ls.iter_mut().enumerate() {
|
||||
let kk = ops::splat(fb, f, k as u64)?;
|
||||
@@ -800,7 +713,6 @@ const FRAGMENT_LANES: usize = 2;
|
||||
fn fragment_shape(s: Shape) -> bool {
|
||||
s.chunked
|
||||
&& s.lanes == 64
|
||||
&& !matches!(s.held, Held::Wide { .. })
|
||||
&& chunk_lanes(u32::from(s.lanes))
|
||||
.first()
|
||||
.is_some_and(|&k| usize::from(k) >= FRAGMENT_LANES)
|
||||
@@ -877,11 +789,6 @@ fn words_of(fb: &mut FunctionBuilder<'_>, s: Shape, v: SValue) -> BResult<Vec<SV
|
||||
let mut at = 0u32;
|
||||
for x in lanes(fb, s, v)? {
|
||||
match (bits, lane.held) {
|
||||
// Two words already.
|
||||
(_, Held::Wide { .. }) => {
|
||||
words.push(fb.composite_extract(x, &[0])?);
|
||||
words.push(fb.composite_extract(x, &[1])?);
|
||||
}
|
||||
(64, _) => {
|
||||
let pair = ops::ty(
|
||||
fb,
|
||||
@@ -950,12 +857,7 @@ fn from_words(fb: &mut FunctionBuilder<'_>, s: Shape, ws: &[SValue]) -> BResult<
|
||||
},
|
||||
)?;
|
||||
let p = fb.composite_construct(pair, &[lo, hi])?;
|
||||
// A two-word lane is the pair itself.
|
||||
xs.push(if lane.is_wide() {
|
||||
p
|
||||
} else {
|
||||
fb.convert(ConvOp::Bitcast, p, lt)?
|
||||
});
|
||||
xs.push(fb.convert(ConvOp::Bitcast, p, lt)?);
|
||||
}
|
||||
(32, Held::Float(_)) => {
|
||||
let w = next.next().ok_or_else(operand_error)?;
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
//! Value legality: how every non-pointer AIR value is held in SPIR-V.
|
||||
//!
|
||||
//! The representation depends on the AIR type and one profile bit, `shaderInt64`; constants are
|
||||
//! selected without a profile and widened where emission's plan holds words ([`widen_const`]).
|
||||
//! Otherwise the profile only decides whether a representation is available ([`check`]):
|
||||
//! The representation depends on the AIR type alone; constants are selected without a profile. The
|
||||
//! profile only decides whether a representation is available ([`check`]):
|
||||
//!
|
||||
//! - `i1` is `bool`; every other integer is held **zero-extended** in an unsigned 32-bit
|
||||
//! container (`i2`..`i32`) or 64-bit container (`i33`..`i64`), or, without `shaderInt64`, as
|
||||
//! two `u32` words ([`Held::Wide`], [`widen`], `super::wide`). The bits above the AIR width are
|
||||
//! container (`i2`..`i32`) or 64-bit container (`i33`..`i64`). The bits above the AIR width are
|
||||
//! zero in every value that is not poison, so an operation that can set them (add, sub, mul,
|
||||
//! shl, signed results) masks its result, and a signed operation sign-extends its operands
|
||||
//! first. An add, sub, mul or shl the AIR marks `nuw` in a container is not masked: its only
|
||||
//! results that would set them are poison (`super::ops::int_binary`; a loop counter's
|
||||
//! increment is one, and a masked latch hides the loop's trip count from the driver). Where a
|
||||
//! value must be defined although its operand is poison, it is masked: `freeze`, the bytes a
|
||||
//! store writes (`memory::leaf`), a narrow atomic's operand, and a bitcast's packed lanes. The
|
||||
//! two-word form keeps its masks. `i8`/`i16` therefore never need `Int8`/`Int16`.
|
||||
//! store writes (`memory::leaf`), a narrow atomic's operand, and a bitcast's packed lanes.
|
||||
//! `i8`/`i16` therefore never need `Int8`/`Int16`.
|
||||
//! - `float` is `f32` and `double` is `f64` (needs `shaderFloat64`, else refused). `half` and
|
||||
//! `bfloat` are **held widened** in an `f32` that is always exactly a value of the narrow format,
|
||||
//! on every profile ([`super::narrow`]): no profile needs `shaderFloat16`, and a constant
|
||||
@@ -68,13 +66,6 @@ pub enum Held {
|
||||
container: u8,
|
||||
},
|
||||
Float(FloatFmt),
|
||||
/// An `i<bits>` (33 to 64 bits) held zero-extended as two `u32` words, low word first, on a
|
||||
/// profile without `shaderInt64` ([`super::wide`]): a scalar is a `uvec2`, a vector of `n`
|
||||
/// lanes a struct of two `u32` vectors of `n` lanes (the low words, then the high words). Only
|
||||
/// [`wide_form_on`] produces it; [`form_on`] keeps refusing such a type.
|
||||
Wide {
|
||||
bits: u8,
|
||||
},
|
||||
}
|
||||
|
||||
/// A float format and its container.
|
||||
@@ -228,16 +219,11 @@ impl Form {
|
||||
Held::Float(f) => ScalarTy::Float {
|
||||
bits: f.container(),
|
||||
},
|
||||
// The element of each of its two words.
|
||||
Held::Wide { .. } => ScalarTy::Int { bits: 32 },
|
||||
}
|
||||
}
|
||||
|
||||
/// The lowered representation.
|
||||
pub fn demote(self) -> DemoteTy {
|
||||
if let Held::Wide { .. } = self.held {
|
||||
return wide_demote(self.lanes);
|
||||
}
|
||||
if self.lanes == 1 {
|
||||
DemoteTy::Scalar(self.scalar())
|
||||
} else {
|
||||
@@ -257,18 +243,17 @@ impl Form {
|
||||
pub fn bits(self) -> u8 {
|
||||
match self.held {
|
||||
Held::Bool => 1,
|
||||
Held::Int { bits, .. } | Held::Wide { bits } => bits,
|
||||
Held::Int { bits, .. } => bits,
|
||||
Held::Float(f) => f.bits(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The container width in bits (a wide integer's two words are 64 bits).
|
||||
/// The container width in bits.
|
||||
pub fn container(self) -> u8 {
|
||||
match self.held {
|
||||
Held::Bool => 1,
|
||||
Held::Int { container, .. } => container,
|
||||
Held::Float(f) => f.container(),
|
||||
Held::Wide { .. } => 64,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,11 +269,6 @@ impl Form {
|
||||
matches!(self.held, Held::Float { .. })
|
||||
}
|
||||
|
||||
/// An integer held as two words.
|
||||
pub fn is_wide(self) -> bool {
|
||||
matches!(self.held, Held::Wide { .. })
|
||||
}
|
||||
|
||||
/// An integer held in a container wider than its AIR width.
|
||||
pub fn legalized(self) -> bool {
|
||||
matches!(self.held, Held::Int { bits, container } if bits < container)
|
||||
@@ -322,76 +302,6 @@ impl Form {
|
||||
}
|
||||
}
|
||||
|
||||
/// The representation of a wide integer of `lanes` lanes: a `uvec2` (low, high) for a scalar, else
|
||||
/// a struct of the low-word vector and the high-word vector.
|
||||
pub fn wide_demote(lanes: u8) -> DemoteTy {
|
||||
let word = ScalarTy::Int { bits: 32 };
|
||||
if lanes == 1 {
|
||||
DemoteTy::Vector { elem: word, len: 2 }
|
||||
} else {
|
||||
let v = DemoteTy::Vector {
|
||||
elem: word,
|
||||
len: lanes,
|
||||
};
|
||||
DemoteTy::Composite(vec![v.clone(), v].into())
|
||||
}
|
||||
}
|
||||
|
||||
/// `d` with every 64-bit integer scalar or vector replaced by its wide representation.
|
||||
pub fn widen(d: &DemoteTy) -> DemoteTy {
|
||||
match d {
|
||||
DemoteTy::Scalar(ScalarTy::Int { bits: 64 }) => wide_demote(1),
|
||||
DemoteTy::Vector {
|
||||
elem: ScalarTy::Int { bits: 64 },
|
||||
len,
|
||||
} => wide_demote(*len),
|
||||
DemoteTy::Composite(parts) => DemoteTy::Composite(parts.iter().map(widen).collect()),
|
||||
other => other.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Constant `k` with every 64-bit integer scalar or vector in its wide representation.
|
||||
pub fn widen_const(k: LoweredConst) -> LoweredConst {
|
||||
let word = ScalarTy::Int { bits: 32 };
|
||||
let lo = |b: u64| b & 0xFFFF_FFFF;
|
||||
let hi = |b: u64| b >> 32;
|
||||
match k {
|
||||
LoweredConst::Scalar {
|
||||
ty: ScalarTy::Int { bits: 64 },
|
||||
bits,
|
||||
} => LoweredConst::Vector {
|
||||
elem: word,
|
||||
lanes: vec![lo(bits), hi(bits)].into(),
|
||||
},
|
||||
LoweredConst::Vector {
|
||||
elem: ScalarTy::Int { bits: 64 },
|
||||
lanes,
|
||||
} => {
|
||||
let n = u8::try_from(lanes.len()).unwrap_or(u8::MAX);
|
||||
LoweredConst::Composite {
|
||||
ty: wide_demote(n),
|
||||
parts: vec![
|
||||
LoweredConst::Vector {
|
||||
elem: word,
|
||||
lanes: lanes.iter().map(|b| lo(*b)).collect(),
|
||||
},
|
||||
LoweredConst::Vector {
|
||||
elem: word,
|
||||
lanes: lanes.iter().map(|b| hi(*b)).collect(),
|
||||
},
|
||||
]
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
LoweredConst::Composite { ty, parts } => LoweredConst::Composite {
|
||||
ty: widen(&ty),
|
||||
parts: parts.into_vec().into_iter().map(widen_const).collect(),
|
||||
},
|
||||
LoweredConst::Undef(d) => LoweredConst::Undef(widen(&d)),
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
impl LoweredConst {
|
||||
/// The lowered representation of the constant.
|
||||
pub fn demote(&self) -> DemoteTy {
|
||||
@@ -428,7 +338,7 @@ pub fn held_of(t: &Type) -> Option<Held> {
|
||||
}
|
||||
|
||||
/// Whether AIR type `ty` is an integer or 2-4-lane integer vector of 33 to 64 bits: a type held
|
||||
/// in a 64-bit container, or as two words without `shaderInt64`.
|
||||
/// in a 64-bit container.
|
||||
pub fn is_wide_int(types: &TypeTable, ty: AirTypeId) -> bool {
|
||||
match types.get(ty) {
|
||||
Some(Type::Int(33..=64)) => true,
|
||||
@@ -582,18 +492,12 @@ pub fn bool_lanes(types: &TypeTable, ty: AirTypeId) -> Option<u8> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether profile `p` can hold scalar `s`: 64-bit integers need `shaderInt64`, 64-bit floats
|
||||
/// `shaderFloat64` (both refused naming the feature). No lowered representation is a 16-bit float
|
||||
/// (narrow floats are held widened), so one is not this family's.
|
||||
/// Whether profile `p` can hold scalar `s`: 64-bit floats need `shaderFloat64` (refused naming
|
||||
/// the feature). No lowered representation is a 16-bit float (narrow floats are held widened), so
|
||||
/// one is not this family's.
|
||||
pub fn check_scalar(p: &DeviceProfile, s: ScalarTy) -> Result<(), Error> {
|
||||
let leaf = &p.fields().leaf;
|
||||
match s {
|
||||
ScalarTy::Int { bits: 64 } if !leaf.int64 => Err(Unsupported::needs(
|
||||
Feature::Int64Arithmetic,
|
||||
Capability::Feature(VkFeature::ShaderInt64),
|
||||
)
|
||||
.into()),
|
||||
ScalarTy::Float { bits: 64 } if !leaf.float64 => Err(Unsupported::needs(
|
||||
ScalarTy::Float { bits: 64 } if !p.fields().leaf.float64 => Err(Unsupported::needs(
|
||||
Feature::Float64Arithmetic,
|
||||
Capability::Feature(VkFeature::ShaderFloat64),
|
||||
)
|
||||
@@ -619,19 +523,6 @@ pub fn form_on(e: &Entry, p: &DeviceProfile, ty: AirTypeId) -> Result<Form, Erro
|
||||
Ok(f)
|
||||
}
|
||||
|
||||
/// Whether profile `p` holds 64-bit integers as two words: it lacks `shaderInt64`.
|
||||
pub fn holds_wide(p: &DeviceProfile) -> bool {
|
||||
!p.fields().leaf.int64
|
||||
}
|
||||
|
||||
/// [`form_on`], except that an integer of 33 to 64 bits is [`Held::Wide`] on a profile without
|
||||
/// `shaderInt64`. Only families that lower the wide form call it; every other family keeps refusing
|
||||
/// such a type through [`form_on`].
|
||||
pub fn wide_form_on(e: &Entry, p: &DeviceProfile, ty: AirTypeId) -> Result<Form, Error> {
|
||||
let f = form_of(e.module.types(), ty)?;
|
||||
Ok(f.with(held_on(p, f.held)?))
|
||||
}
|
||||
|
||||
/// Refuse a 64-bit integer (a scalar or 2-4-lane vector of AIR type `ty`) as a stage interface
|
||||
/// value of entry `e`. Metal's compiler rejects `long` and `ulong` as a vertex attribute, a varying
|
||||
/// (flat or not), a color output or input, and a stage builtin ("type 'long' is not valid for
|
||||
@@ -669,20 +560,11 @@ pub fn refuse_bfloat_color(e: &Entry, ty: AirTypeId) -> Result<(), Error> {
|
||||
)))
|
||||
}
|
||||
|
||||
/// How profile `p` holds an element held as `h` profile-independently: an integer of 33 to 64
|
||||
/// bits as [`Held::Wide`] without `shaderInt64`, anything else as it is once `p` can hold its
|
||||
/// scalar ([`check_scalar`]). The element of a chunked vector takes its form here.
|
||||
/// Element form `h`, once profile `p` can hold its scalar ([`check_scalar`]). The element of a
|
||||
/// chunked vector takes its form here.
|
||||
pub fn held_on(p: &DeviceProfile, h: Held) -> Result<Held, Error> {
|
||||
match h {
|
||||
Held::Int {
|
||||
bits,
|
||||
container: 64,
|
||||
} if holds_wide(p) => Ok(Held::Wide { bits }),
|
||||
_ => {
|
||||
check_scalar(p, Form { held: h, lanes: 1 }.scalar())?;
|
||||
Ok(h)
|
||||
}
|
||||
}
|
||||
check_scalar(p, Form { held: h, lanes: 1 }.scalar())?;
|
||||
Ok(h)
|
||||
}
|
||||
|
||||
// ---- Constants ----
|
||||
|
||||
@@ -16,11 +16,8 @@
|
||||
//! [`lowered_type`] is what `select` demotes block-crossing values and phis to and what it requires
|
||||
//! of terminator operands, [`constant`] is which constants lowering materializes, and
|
||||
//! [`spirv_type`] and [`materialize`] are their emission. The representation depends on the AIR
|
||||
//! type and `shaderInt64` only: `i1` is `bool`, other integers are held zero-extended in a 32- or
|
||||
//! 64-bit unsigned container (so `i8`/`i16`/`i2`/`i40` need no narrow capability), `i33`..`i64` as
|
||||
//! two `u32` words without `shaderInt64` ([`wide`]: every operation on them is
|
||||
//! `ArithStrategy::Wide`, per chunk in a chunked vector; division unrolled without a loop), `float`
|
||||
//! and `double` are native (`f64` needs `shaderFloat64`), and `half` and `bfloat` are held widened
|
||||
//! type only: `i1` is `bool`, other integers are held zero-extended in a 32- or 64-bit unsigned
|
||||
//! container (so `i8`/`i16`/`i2`/`i40` need no narrow capability), `float` and `double` are native (`f64` needs `shaderFloat64`), and `half` and `bfloat` are held widened
|
||||
//! in an `f32` that is always a value of the narrow format ([`narrow`]): each operation rounds its
|
||||
//! `f32` result back to the format, so no profile needs `shaderFloat16`; where the device's 16-bit
|
||||
//! `+ - *`, kept apart, is Metal's `half` arithmetic and the profile has `shaderFloat16`, a `half`
|
||||
@@ -83,7 +80,6 @@ pub mod output_precision;
|
||||
pub mod pack;
|
||||
pub mod srgb;
|
||||
pub mod texel_round;
|
||||
pub mod wide;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -122,42 +118,24 @@ use ops::{BitcastPlan, CastKind};
|
||||
/// lowered value of `ty` has, which is always demotable. A type this family does not lower yet is
|
||||
/// `Unsupported{Lowering(Arith), NotImplemented}`; a type that needs a capability the profile lacks
|
||||
/// is a typed refusal naming it.
|
||||
///
|
||||
/// On a profile without `shaderInt64` every 64-bit integer scalar or vector is held as two words
|
||||
/// ([`legal::widen`]), each chunk of a chunked vector of them too.
|
||||
pub fn lowered_type(e: &Entry, p: &DeviceProfile, ty: AirTypeId) -> Result<DemoteTy, Error> {
|
||||
let mut d = demote_of(e.module.types(), ty)?;
|
||||
if legal::holds_wide(p) {
|
||||
d = legal::widen(&d);
|
||||
}
|
||||
let d = demote_of(e.module.types(), ty)?;
|
||||
check(p, &d)?;
|
||||
Ok(d)
|
||||
}
|
||||
|
||||
/// `v` as a constant lowering materializes, in its profile-independent representation (64-bit
|
||||
/// integers native). It is `Some` only for constants of a type [`lowered_type`] lowers on some
|
||||
/// profile; `select` checks the profile. Emission materializes [`constant_in`].
|
||||
/// `v` as a constant lowering materializes, in its lowered representation. It is `Some` only for
|
||||
/// constants of a type [`lowered_type`] lowers on some profile; `select` checks the profile.
|
||||
/// Emission materializes it.
|
||||
pub fn constant(e: &Entry, v: Value) -> Option<LoweredConst> {
|
||||
let Value::Const(c) = v else { return None };
|
||||
legal::lower_const(e, c)
|
||||
}
|
||||
|
||||
/// [`constant`] in the representation of the plan's profile: 64-bit integers as two words where
|
||||
/// the plan holds them so.
|
||||
pub fn constant_in(e: &Entry, plan: &ArithPlan, v: Value) -> Option<LoweredConst> {
|
||||
let k = constant(e, v)?;
|
||||
Some(if plan.wide { legal::widen_const(k) } else { k })
|
||||
}
|
||||
|
||||
/// [`constant`] in lowered representation `d`: the constant itself, or its wide form when `d` is
|
||||
/// the wide representation of its type; `None` when neither is `d`.
|
||||
/// [`constant`], when its lowered representation is `d`; `None` otherwise.
|
||||
pub fn constant_as(e: &Entry, v: Value, d: &DemoteTy) -> Option<LoweredConst> {
|
||||
let k = constant(e, v)?;
|
||||
if k.demote() == *d {
|
||||
return Some(k);
|
||||
}
|
||||
let w = legal::widen_const(k);
|
||||
(w.demote() == *d).then_some(w)
|
||||
(k.demote() == *d).then_some(k)
|
||||
}
|
||||
|
||||
/// The SPIR-V type of lowered representation `ty`, or `None` for one this family does not
|
||||
@@ -385,9 +363,6 @@ pub enum ArithStrategy {
|
||||
elem: Form,
|
||||
contract: Contraction,
|
||||
},
|
||||
/// An operation with a wide integer operand or result on a profile without `shaderInt64`,
|
||||
/// on the two words of each value ([`wide`]).
|
||||
Wide(wide::WideOp),
|
||||
/// An `insertvalue` or `extractvalue` whose result is an aggregate that holds a pointer: no
|
||||
/// SPIR-V value ([`aggregate`]).
|
||||
PointerAggregate,
|
||||
@@ -504,7 +479,6 @@ impl FamilyStrategy for ArithStrategy {
|
||||
S::LaneShuffle { fragment: true, .. } => "arith.shuffle.fragment",
|
||||
S::LaneShuffle { .. } => "arith.shuffle.chunked",
|
||||
S::WordBitcast { .. } => "arith.bitcast.chunked",
|
||||
S::Wide(w) => w.name(),
|
||||
S::PointerAggregate => "arith.aggregate.pointer",
|
||||
S::Handle(_) => "arith.aggregate.handle",
|
||||
S::Forward(_) => "arith.aggregate.forward",
|
||||
@@ -616,7 +590,6 @@ impl FamilyStrategy for ArithStrategy {
|
||||
} => chunk::fragment_shuffle_words(*out),
|
||||
S::LaneShuffle { out, .. } => chunk::move_words(*out, chunk::LaneMove::Shuffle, false),
|
||||
S::WordBitcast { from, to } => chunk::bitcast_words(*from, *to),
|
||||
S::Wide(w) => w.words(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -693,11 +666,6 @@ pub struct ArithPlan {
|
||||
/// The widths whose `SignedZeroInfNanPreserve` execution mode the entry declares: those of
|
||||
/// `preserve` the profile supports.
|
||||
pub modes: BTreeSet<u8>,
|
||||
/// Whether 64-bit integers are held as two words (the profile lacks `shaderInt64`), so emission
|
||||
/// materializes their constants in that form ([`constant_in`]).
|
||||
pub wide: bool,
|
||||
/// The shared division routines the wide divisions call, each defined once by [`declare`].
|
||||
pub divides: BTreeSet<wide::Divide>,
|
||||
/// The value each forwarding `extractvalue` reads ([`aggregate::forwarded`]), and the
|
||||
/// member-wise phi each member extraction reads.
|
||||
pub forwards: BTreeMap<InstId, Value>,
|
||||
@@ -762,10 +730,7 @@ pub fn routine_words(plan: &ArithPlan) -> impl Iterator<Item = (&'static str, u6
|
||||
let fmod = plan
|
||||
.fmod
|
||||
.then_some((libm::FMOD_NAME, u64::from(libm::FMOD_WORDS)));
|
||||
plan.divides
|
||||
.iter()
|
||||
.map(|d| (wide::DIVIDE, u64::from(d.words())))
|
||||
.chain(fmod)
|
||||
fmod.into_iter()
|
||||
}
|
||||
|
||||
/// The census name of `air.fast_fmod` on `float` ([`ArithStrategy::FastFmod`]).
|
||||
@@ -780,7 +745,6 @@ pub const FAST_DIVIDE: &str = "arith.fdiv.fast";
|
||||
/// ([`ArithPlan::native_fma`]), and `NativeNanEncoding` where the entry reaches a signalling
|
||||
/// `float` NaN constant ([`nan::holds_signalling_float`]).
|
||||
pub fn finish(cx: &mut SelectCx<'_>, m: &mut Meter) -> Result<(), Error> {
|
||||
cx.families.arith.wide = legal::holds_wide(cx.profile);
|
||||
cx.families.arith.quantize = narrow::quantize_form(cx.profile);
|
||||
cx.families.arith.native_half = narrow::native_rounding(cx.families.arith.quantize).is_some();
|
||||
// Under the float controls a `half`'s NaN is the device's conversion's.
|
||||
@@ -814,19 +778,16 @@ pub fn finish(cx: &mut SelectCx<'_>, m: &mut Meter) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The arith family's module-scope objects: the shared wide division routines and precise
|
||||
/// `fmod`'s routine (the `GLSL.std.450` import is the serializer's, and constants are
|
||||
/// interned where they are used).
|
||||
/// The arith family's module-scope objects: precise `fmod`'s routine (the `GLSL.std.450` import is
|
||||
/// the serializer's, and constants are interned where they are used).
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Declared {
|
||||
/// The function of each of the plan's [`ArithPlan::divides`].
|
||||
pub divides: BTreeMap<wide::Divide, FuncId>,
|
||||
/// Precise `fmod`'s routine, when [`ArithPlan::fmod`].
|
||||
pub fmod: Option<FuncId>,
|
||||
}
|
||||
|
||||
/// Declare the arith family's module-scope objects and entry execution modes: one function per
|
||||
/// shared division routine the plan calls, and one `SignedZeroInfNanPreserve` per width the plan
|
||||
/// Declare the arith family's module-scope objects and entry execution modes: precise `fmod`'s
|
||||
/// routine where the plan calls it, and one `SignedZeroInfNanPreserve` per width the plan
|
||||
/// selected.
|
||||
pub fn declare(
|
||||
mb: &mut ModuleBuilder,
|
||||
@@ -837,9 +798,6 @@ pub fn declare(
|
||||
modes.push(ExecMode::SignedZeroInfNanPreserve { width: *w });
|
||||
}
|
||||
let mut decl = Declared::default();
|
||||
for d in &plan.families.arith.divides {
|
||||
decl.divides.insert(*d, wide::define_divide(mb, *d)?);
|
||||
}
|
||||
if plan.families.arith.fmod {
|
||||
decl.fmod = Some(libm::define_fmod(mb)?);
|
||||
}
|
||||
@@ -1189,9 +1147,6 @@ pub fn select(
|
||||
if chunk::involved(cx, inst) {
|
||||
return chunk::select(cx, at, inst, m);
|
||||
}
|
||||
if wide::involved(cx, inst) {
|
||||
return wide::select(cx, at, inst);
|
||||
}
|
||||
select_in(cx, at, inst, None, m)
|
||||
}
|
||||
|
||||
@@ -1250,8 +1205,7 @@ fn select_in(
|
||||
return select_call(cx, at, inst, call, chunk, m);
|
||||
}
|
||||
let mut ops = operands_of(&inst.kind);
|
||||
// A constant element index is a literal of the instruction, never a materialized value (an
|
||||
// `i64` index needs no `shaderInt64`).
|
||||
// A constant element index is a literal of the instruction, never a materialized value.
|
||||
if let InstKind::ExtractElement { idx, .. } | InstKind::InsertElement { idx, .. } = &inst.kind {
|
||||
if matches!(idx, Value::Const(_)) {
|
||||
ops.retain(|v| v != idx);
|
||||
@@ -2616,7 +2570,6 @@ fn arity(s: &ArithStrategy) -> Option<usize> {
|
||||
| S::Null(_)
|
||||
| S::Member { .. } => Some(0),
|
||||
S::Chunked { parts, .. } => parts.first().and_then(|(_, p)| arity(p)),
|
||||
S::Wide(w) => w.arity(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -2792,16 +2745,6 @@ fn value(
|
||||
}
|
||||
S::IntFn { f, form } => math::int_fn(fb, *f, *form, xs)?,
|
||||
S::IntFnBy { f, k, form } => math::funnel_by(fb, *f, *form, *k, xs)?,
|
||||
S::Wide(w) => {
|
||||
let routine = match w.routine() {
|
||||
Some(d) => match cx.decl.families.arith.divides.get(&d) {
|
||||
Some(f) => Some(*f),
|
||||
None => return Err(cx.fail("a wide division whose routine is not declared")),
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
wide::emit(fb, w, xs, routine)?
|
||||
}
|
||||
S::FloatFn { f, form, contract } => {
|
||||
let lib = lib(cx);
|
||||
math::float_fn(fb, *f, *form, *contract, xs, &lib)?
|
||||
|
||||
@@ -22,7 +22,7 @@ pub fn ones(bits: u8) -> u64 {
|
||||
}
|
||||
}
|
||||
|
||||
/// The SPIR-V element type of `h` (a wide integer's: its words').
|
||||
/// The SPIR-V element type of `h`.
|
||||
pub fn elem_ty(fb: &mut FunctionBuilder<'_>, h: Held) -> BResult<TypeId> {
|
||||
fb.module().ty(match h {
|
||||
Held::Bool => Type::Bool,
|
||||
@@ -30,33 +30,14 @@ pub fn elem_ty(fb: &mut FunctionBuilder<'_>, h: Held) -> BResult<TypeId> {
|
||||
width: container,
|
||||
signed: false,
|
||||
},
|
||||
Held::Wide { .. } => Type::Int {
|
||||
width: 32,
|
||||
signed: false,
|
||||
},
|
||||
Held::Float(f) => Type::Float {
|
||||
width: f.container(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/// The SPIR-V type of `f` (a wide integer's: [`super::legal::wide_demote`]).
|
||||
/// The SPIR-V type of `f`.
|
||||
pub fn ty(fb: &mut FunctionBuilder<'_>, f: Form) -> BResult<TypeId> {
|
||||
if f.is_wide() {
|
||||
let words = f.with(Held::Int {
|
||||
bits: 32,
|
||||
container: 32,
|
||||
});
|
||||
let w = ty(fb, words)?;
|
||||
return if f.lanes == 1 {
|
||||
fb.module().ty(Type::Vector { elem: w, len: 2 })
|
||||
} else {
|
||||
fb.module().ty(Type::Struct {
|
||||
members: vec![w, w].into(),
|
||||
layout: None,
|
||||
})
|
||||
};
|
||||
}
|
||||
let e = elem_ty(fb, f.held)?;
|
||||
if f.lanes == 1 {
|
||||
Ok(e)
|
||||
@@ -68,11 +49,26 @@ pub fn ty(fb: &mut FunctionBuilder<'_>, f: Form) -> BResult<TypeId> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The low word of 64-bit integer `x` (a GEP's index word).
|
||||
pub fn low_word(fb: &mut FunctionBuilder<'_>, x: Value) -> BResult<Value> {
|
||||
let u = fb.module().ty(Type::Int {
|
||||
width: 32,
|
||||
signed: false,
|
||||
})?;
|
||||
fb.convert(ConvOp::UConvert, x, u)
|
||||
}
|
||||
|
||||
/// `u32` value `w` zero-extended to integer form `f` (a 32- or 64-bit container).
|
||||
pub fn zext_word(fb: &mut FunctionBuilder<'_>, f: Form, w: Value) -> BResult<Value> {
|
||||
if f.container() == 32 {
|
||||
return Ok(w);
|
||||
}
|
||||
let t = ty(fb, f)?;
|
||||
fb.convert(ConvOp::UConvert, w, t)
|
||||
}
|
||||
|
||||
/// The constant of form `f` with `bits` (in the container) in every lane.
|
||||
pub fn splat(fb: &mut FunctionBuilder<'_>, f: Form, bits: u64) -> BResult<Value> {
|
||||
if f.is_wide() {
|
||||
return super::wide::splat(fb, f, bits);
|
||||
}
|
||||
let e = elem_ty(fb, f.held)?;
|
||||
let bits = match f.held {
|
||||
Held::Bool => bits & 1,
|
||||
|
||||
@@ -149,15 +149,6 @@ fn const_of(fb: &mut FunctionBuilder<'_>, ty: TypeId, bits: u64) -> BResult<Valu
|
||||
|
||||
/// Load one operand of form `f` from word `at + k` on.
|
||||
fn load(fb: &mut FunctionBuilder<'_>, f: Form, buf: GlobalId, at: Value, k: u32) -> BResult<Value> {
|
||||
if f.is_wide() {
|
||||
// Two words per lane, low first.
|
||||
let mut ws = Vec::new();
|
||||
for j in 0..2 * u32::from(f.lanes) {
|
||||
let p = word_ptr(fb, buf, at, k + j)?;
|
||||
ws.push(fb.load(p, MemAccess::default())?);
|
||||
}
|
||||
return super::wide::from_words(fb, f, &ws);
|
||||
}
|
||||
let lane = f.scalar_form();
|
||||
let et = ops::ty(fb, lane)?;
|
||||
let mut lanes = Vec::new();
|
||||
@@ -218,14 +209,6 @@ fn store(
|
||||
v: Value,
|
||||
lanes: bool,
|
||||
) -> BResult<()> {
|
||||
if f.is_wide() {
|
||||
let ws = super::wide::to_words(fb, f, v)?;
|
||||
for (j, w) in ws.into_iter().enumerate() {
|
||||
let p = word_ptr(fb, buf, at, j as u32)?;
|
||||
fb.store(p, w, MemAccess::default())?;
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
let lane = f.scalar_form();
|
||||
let u32_ = u32_ty(fb.module())?;
|
||||
// A narrow vector encodes once, as the memory leaf's store does; with `lanes`, each lane is
|
||||
@@ -378,16 +361,16 @@ fn kernel_defs(
|
||||
Ok(m)
|
||||
}
|
||||
|
||||
/// A committed profile with 64-bit integers and floats and 16-bit floats (for L3).
|
||||
/// A committed profile with 64-bit floats and 16-bit floats (for L3).
|
||||
fn wide_profile() -> DeviceProfile {
|
||||
let all = committed_profiles().expect("profiles");
|
||||
all.into_iter()
|
||||
.map(|(_, p)| p)
|
||||
.find(|p| {
|
||||
let l = &p.fields().leaf;
|
||||
l.int64 && l.float64 && l.float16
|
||||
l.float64 && l.float16
|
||||
})
|
||||
.expect("a committed profile with int64, float64, and float16")
|
||||
.expect("a committed profile with float64 and float16")
|
||||
}
|
||||
|
||||
/// One case: per operand, per lane, the held bits.
|
||||
@@ -4125,6 +4108,7 @@ fn aggregate_leaf_total_is_capped_before_expansion() {
|
||||
|
||||
mod atan2;
|
||||
mod bicubic;
|
||||
mod chunk;
|
||||
mod color_write;
|
||||
mod convert_suffix;
|
||||
mod divide;
|
||||
@@ -4136,7 +4120,6 @@ mod pack;
|
||||
mod round_texel;
|
||||
mod specials;
|
||||
mod texel_round;
|
||||
mod wide;
|
||||
|
||||
/// `air.convert` from an integer to `bool` is C++'s `x != 0`, lane by lane, at every width and
|
||||
/// whatever the source's sign: the values that differ from the low bit (2, 0x80, the top bit) are
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
//! Word bounds of the lane moves on chunked vectors (`chunk::move_words`,
|
||||
//! `chunk::fragment_shuffle_words`, `chunk::bitcast_words`) against what they emit.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// The word bound of each lane move on a chunked vector covers what it emits, for 64-bit and 32-bit
|
||||
/// lanes: constant and dynamic (32-bit and 64-bit index) extracts and inserts, shuffles, and word
|
||||
/// bitcasts of 64-bit lanes to 32-bit lanes and back, at 5, 6, and 8 lanes (chunks of 4 and 1, 4
|
||||
/// and 2, and two of 4).
|
||||
#[test]
|
||||
fn chunked_lane_moves_bound_their_emission() {
|
||||
use super::super::chunk::{self, Shape};
|
||||
use super::super::ArithStrategy as S;
|
||||
use crate::lower::strategy::FamilyStrategy;
|
||||
use crate::spirv::serialize::serialize;
|
||||
let size = |ins: &[Form], out: Form, body: Body<'_>| -> usize {
|
||||
let m = kernel(ins, out, body).expect("build");
|
||||
serialize(m).expect("serialize").words.len()
|
||||
};
|
||||
let check = |what: &str, s: &S, with: usize, without: usize| {
|
||||
let bound = s.words() as usize;
|
||||
assert!(
|
||||
with - without <= bound,
|
||||
"{what}: {} words above the kernel, bound {bound}",
|
||||
with - without
|
||||
);
|
||||
};
|
||||
for lane in [int(64), int(32)] {
|
||||
let four = Shape {
|
||||
held: lane.held,
|
||||
lanes: 4,
|
||||
chunked: false,
|
||||
};
|
||||
let v4 = vec(lane, 4);
|
||||
for n in [5u16, 6, 8] {
|
||||
let s = Shape {
|
||||
held: lane.held,
|
||||
lanes: n,
|
||||
chunked: true,
|
||||
};
|
||||
let what = |m: &str| format!("{m} {lane:?} x {n}");
|
||||
let all: Vec<u32> = (0..u32::from(n)).collect();
|
||||
// The chunked operand, from the first two (4-lane) operands.
|
||||
let make = |fb: &mut FunctionBuilder<'_>, x: &[Value]| {
|
||||
chunk::shuffle(fb, four, four, s, &all, &x[..2])
|
||||
};
|
||||
// Lane 0 of a chunked value, as the kernel's output.
|
||||
let first =
|
||||
|fb: &mut FunctionBuilder<'_>, v: Value| chunk::extract(fb, s, Some(0), None, &[v]);
|
||||
let unmoved = |ins: &[Form]| {
|
||||
size(ins, lane, &|fb, x| {
|
||||
let v = make(fb, x)?;
|
||||
first(fb, v)
|
||||
})
|
||||
};
|
||||
// Constant moves of lane 1, which lives in a 4-lane chunk.
|
||||
let ins = [v4, v4, lane];
|
||||
let kept = size(&ins, lane, &|fb, x| {
|
||||
make(fb, x)?;
|
||||
Ok(x[2])
|
||||
});
|
||||
let with = size(&ins, lane, &|fb, x| {
|
||||
let v = make(fb, x)?;
|
||||
chunk::extract(fb, s, Some(1), None, &[v])
|
||||
});
|
||||
let extract = S::LaneExtract {
|
||||
src: s,
|
||||
at: Some(1),
|
||||
index: None,
|
||||
};
|
||||
check(&what("extract"), &extract, with, kept);
|
||||
let with = size(&ins, lane, &|fb, x| {
|
||||
let v = make(fb, x)?;
|
||||
let r = chunk::insert(fb, s, Some(1), None, &[v, x[2]])?;
|
||||
first(fb, r)
|
||||
});
|
||||
let insert = S::LaneInsert {
|
||||
dst: s,
|
||||
at: Some(1),
|
||||
index: None,
|
||||
};
|
||||
check(&what("insert"), &insert, with, unmoved(&ins));
|
||||
// Dynamic moves.
|
||||
for index in [int(32), int(64)] {
|
||||
let ins = [v4, v4, lane, index];
|
||||
let kept = size(&ins, lane, &|fb, x| {
|
||||
make(fb, x)?;
|
||||
Ok(x[2])
|
||||
});
|
||||
let with = size(&ins, lane, &|fb, x| {
|
||||
let v = make(fb, x)?;
|
||||
chunk::extract(fb, s, None, Some(index), &[v, x[3]])
|
||||
});
|
||||
let extract = S::LaneExtract {
|
||||
src: s,
|
||||
at: None,
|
||||
index: Some(index),
|
||||
};
|
||||
check(&what("dynamic extract"), &extract, with, kept);
|
||||
let with = size(&ins, lane, &|fb, x| {
|
||||
let v = make(fb, x)?;
|
||||
let r = chunk::insert(fb, s, None, Some(index), &[v, x[2], x[3]])?;
|
||||
first(fb, r)
|
||||
});
|
||||
let insert = S::LaneInsert {
|
||||
dst: s,
|
||||
at: None,
|
||||
index: Some(index),
|
||||
};
|
||||
check(&what("dynamic insert"), &insert, with, unmoved(&ins));
|
||||
}
|
||||
// A shuffle of every lane from both operands.
|
||||
let ins = [v4, v4];
|
||||
let mask: Box<[u32]> = (0..u32::from(n))
|
||||
.map(|i| (i * 5 + 3) % (2 * u32::from(n)))
|
||||
.collect();
|
||||
let with = size(&ins, lane, &|fb, x| {
|
||||
let v = make(fb, x)?;
|
||||
let r = chunk::shuffle(fb, s, s, s, &mask, &[v, v])?;
|
||||
first(fb, r)
|
||||
});
|
||||
let shuffle = S::LaneShuffle {
|
||||
a: s,
|
||||
b: s,
|
||||
out: s,
|
||||
mask: mask.clone(),
|
||||
fragment: false,
|
||||
};
|
||||
check(&what("shuffle"), &shuffle, with, unmoved(&ins));
|
||||
// Word bitcasts of 64-bit lanes to twice as many 32-bit lanes and back.
|
||||
if lane.bits() == 64 {
|
||||
let words = Shape {
|
||||
held: int(32).held,
|
||||
lanes: 2 * n,
|
||||
chunked: true,
|
||||
};
|
||||
let with = size(&ins, lane, &|fb, x| {
|
||||
let v = make(fb, x)?;
|
||||
let u = chunk::bitcast(fb, s, words, v)?;
|
||||
let r = chunk::bitcast(fb, words, s, u)?;
|
||||
first(fb, r)
|
||||
});
|
||||
let there = S::WordBitcast { from: s, to: words };
|
||||
let back = S::WordBitcast { from: words, to: s };
|
||||
let bound = (there.words() + back.words()) as usize;
|
||||
let emitted = with - unmoved(&ins);
|
||||
assert!(
|
||||
emitted <= bound,
|
||||
"{}: {emitted} words above the kernel, bound {bound}",
|
||||
what("bitcast and back")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A shuffle into a simdgroup matrix's fragment (64 lanes held whole) emits no more than its bound,
|
||||
/// `chunk::fragment_shuffle_words`, for a merge taking lanes 0 and 1 from one operand and the rest
|
||||
/// from the other, of 32-bit integer and of `float` lanes.
|
||||
#[test]
|
||||
fn a_fragment_shuffle_bounds_its_emission() {
|
||||
use super::super::chunk::{self, Shape};
|
||||
use super::super::ArithStrategy as S;
|
||||
use crate::lower::strategy::FamilyStrategy;
|
||||
use crate::spirv::serialize::serialize;
|
||||
let size = |ins: &[Form], out: Form, body: Body<'_>| -> usize {
|
||||
let m = kernel(ins, out, body).expect("build");
|
||||
serialize(m).expect("serialize").words.len()
|
||||
};
|
||||
for lane in [int(32), float(32)] {
|
||||
let four = Shape {
|
||||
held: lane.held,
|
||||
lanes: 4,
|
||||
chunked: false,
|
||||
};
|
||||
let s = Shape {
|
||||
held: lane.held,
|
||||
lanes: 64,
|
||||
chunked: true,
|
||||
};
|
||||
let v4 = vec(lane, 4);
|
||||
let ins = [v4, v4];
|
||||
let spread: Vec<u32> = (0..64).map(|i| i % 8).collect();
|
||||
let make = |fb: &mut FunctionBuilder<'_>, x: &[Value]| {
|
||||
chunk::shuffle(fb, four, four, s, &spread, &x[..2])
|
||||
};
|
||||
let first =
|
||||
|fb: &mut FunctionBuilder<'_>, v: Value| chunk::extract(fb, s, Some(0), None, &[v]);
|
||||
let without = size(&ins, lane, &|fb, x| {
|
||||
let v = make(fb, x)?;
|
||||
first(fb, v)
|
||||
});
|
||||
let mask: Box<[u32]> = [0, 1].into_iter().chain(66..128).collect();
|
||||
let with = size(&ins, lane, &|fb, x| {
|
||||
let v = make(fb, x)?;
|
||||
let r = chunk::shuffle_fragment(fb, s, s, s, &mask, &[v, v])?;
|
||||
first(fb, r)
|
||||
});
|
||||
let strategy = S::LaneShuffle {
|
||||
a: s,
|
||||
b: s,
|
||||
out: s,
|
||||
mask,
|
||||
fragment: true,
|
||||
};
|
||||
let bound = strategy.words() as usize;
|
||||
assert!(
|
||||
with - without <= bound,
|
||||
"{lane:?}: {} words above the kernel, bound {bound}",
|
||||
with - without
|
||||
);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -775,8 +775,7 @@ impl<'a> EmitCx<'a> {
|
||||
if let Some(b) = val.and_then(|val| access::handle::absent_param(entry, val)) {
|
||||
return access::handle::absent_param_value(self, fb, b);
|
||||
}
|
||||
let wide = &self.plan.families.arith;
|
||||
let Some(k) = val.and_then(|val| arith::constant_in(self.entry, wide, val)) else {
|
||||
let Some(k) = val.and_then(|val| arith::constant(self.entry, val)) else {
|
||||
// A null buffer pointer constant is the null fat pointer.
|
||||
if let Some(x) = access::pointer::null_operand(self, fb, v)? {
|
||||
return Ok(x);
|
||||
@@ -1568,14 +1567,6 @@ impl CodeEmitter for Emitter<'_> {
|
||||
let miss = k(fb, miss)?;
|
||||
fb.select(fits, low, miss)
|
||||
}
|
||||
SelectorForm::Words { miss } => {
|
||||
let low = fb.composite_extract(x, &[0])?;
|
||||
let high = fb.composite_extract(x, &[1])?;
|
||||
let zero = k(fb, 0)?;
|
||||
let fits = fb.binary(BinOp::IEqual, high, zero)?;
|
||||
let miss = k(fb, miss)?;
|
||||
fb.select(fits, low, miss)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ pub(super) fn form(cx: &SelectCx<'_>, ty: AirTypeId) -> Result<Form, Error> {
|
||||
let held32 = match form.held {
|
||||
Held::Int { container, .. } => container == 32,
|
||||
Held::Float(f) => f.container() == 32,
|
||||
Held::Bool | Held::Wide { .. } => false,
|
||||
Held::Bool => false,
|
||||
};
|
||||
if !held32 || !(1..=4).contains(&form.lanes) {
|
||||
return Err(not_lowered());
|
||||
|
||||
@@ -343,13 +343,12 @@ pub fn mesh_stages(p: &DeviceProfile) -> bool {
|
||||
|
||||
/// Whether profile `p` compiles an object function folded (`LoweringInputs::folded_groups`), so
|
||||
/// that its draws run any object grid Metal runs in pieces within the task stage's limits
|
||||
/// (`bind::mesh_arguments`): it runs mesh functions natively, and has 64-bit integers (the
|
||||
/// threadgroup's number), `multiDrawIndirect` (a direct draw's pieces, and `maxDrawIndirectCount`
|
||||
/// at least 65,535) and `drawIndirectCount` (an indirect draw's).
|
||||
/// (`bind::mesh_arguments`): it runs mesh functions natively, and has `multiDrawIndirect` (a
|
||||
/// direct draw's pieces, and `maxDrawIndirectCount` at least 65,535) and `drawIndirectCount` (an
|
||||
/// indirect draw's).
|
||||
pub fn folds_object_grids(p: &DeviceProfile) -> bool {
|
||||
let features = &p.enabled().features;
|
||||
mesh_stages(p)
|
||||
&& features.contains(&VkFeature::ShaderInt64)
|
||||
&& features.contains(&VkFeature::MultiDrawIndirect)
|
||||
&& features.contains(&VkFeature::DrawIndirectCount)
|
||||
}
|
||||
|
||||
@@ -1959,7 +1959,7 @@ fn select_one(
|
||||
ImageRef::Slot(index)
|
||||
if texel_op && !shape.depth && crate::lower::texture::swizzled_storage(cx, image)? =>
|
||||
{
|
||||
if form.is_none_or(|f| f.lanes != 4 || matches!(f.conv, TexelConv::U64Words { .. })) {
|
||||
if form.is_none_or(|f| f.lanes != 4 || matches!(f.conv, TexelConv::U64Words)) {
|
||||
return Err(Unsupported::not_implemented(Feature::TextureSwizzle).into());
|
||||
}
|
||||
crate::lower::texture::swizzles(cx, index)?;
|
||||
|
||||
@@ -48,7 +48,7 @@ use crate::air::Entry;
|
||||
use crate::budget::{tree_bytes, Growth, Meter};
|
||||
use crate::device::function_storage;
|
||||
use crate::device::profile::Limits;
|
||||
use crate::device::requirements::{VkFeature, VkLimit};
|
||||
use crate::device::requirements::VkLimit;
|
||||
use crate::device::subgroup::{self, SimdClass, SubgroupRequirement, Tier};
|
||||
use crate::device::DeviceProfile;
|
||||
use crate::error::{
|
||||
@@ -86,9 +86,6 @@ pub enum SelectorForm {
|
||||
/// An `i64`: its low word when the high word is 0, else `miss`, a `u32` that is no case
|
||||
/// literal of any switch on the value (literals fit 32 bits, WideSwitchLiteral).
|
||||
Narrow64 { miss: u32 },
|
||||
/// An `i33`..`i64` held as two words without `shaderInt64`: the low word when the high word is
|
||||
/// 0, else `miss`, as [`SelectorForm::Narrow64`] reads the 64-bit container.
|
||||
Words { miss: u32 },
|
||||
}
|
||||
|
||||
/// A slot's selected form with its proven use.
|
||||
@@ -1025,23 +1022,13 @@ pub fn miss_literal(literals: &BTreeSet<u64>) -> Option<u32> {
|
||||
///
|
||||
/// Each form assumes the lowered value holds the AIR integer zero-extended, so its bits are the
|
||||
/// case literals': an `i8`/`i16` held at its own width, an `Int(2..=32)` in the 32-bit container,
|
||||
/// an `Int(33..=64)` in the 64-bit one, or, without `shaderInt64`, as two words (a `uvec2`, low
|
||||
/// word first). Any other pairing of AIR type and representation is not a form this function knows
|
||||
/// and is refused until one is added for it.
|
||||
/// an `Int(33..=64)` in the 64-bit one. Any other pairing of AIR type and representation is not a
|
||||
/// form this function knows and is refused until one is added for it.
|
||||
pub fn selector_form(
|
||||
air: &Type,
|
||||
lowered: &DemoteTy,
|
||||
int64: bool,
|
||||
literals: &BTreeSet<u64>,
|
||||
) -> Result<SelectorForm, Error> {
|
||||
let words = DemoteTy::Vector {
|
||||
elem: ScalarTy::Int { bits: 32 },
|
||||
len: 2,
|
||||
};
|
||||
if matches!(air, Type::Int(33..=64)) && !int64 && *lowered == words {
|
||||
let miss = miss_literal(literals).ok_or_else(|| not_lowered(LowerFamily::Arith))?;
|
||||
return Ok(SelectorForm::Words { miss });
|
||||
}
|
||||
let DemoteTy::Scalar(repr) = lowered else {
|
||||
return Err(not_lowered(LowerFamily::Arith));
|
||||
};
|
||||
@@ -1054,13 +1041,6 @@ pub fn selector_form(
|
||||
// zero-extended bit patterns: the container is the selector.
|
||||
(Type::Int(2..=32), ScalarTy::Int { bits: 32 }) => Ok(SelectorForm::Direct),
|
||||
(Type::Int(33..=64), ScalarTy::Int { bits: 64 }) => {
|
||||
if !int64 {
|
||||
return Err(Unsupported::needs(
|
||||
Feature::Int64Arithmetic,
|
||||
Capability::Feature(VkFeature::ShaderInt64),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
let miss = miss_literal(literals).ok_or_else(|| not_lowered(LowerFamily::Arith))?;
|
||||
Ok(SelectorForm::Narrow64 { miss })
|
||||
}
|
||||
@@ -1459,8 +1439,7 @@ fn select_body(
|
||||
.and_then(|t| cx.entry.module.types().get(t))
|
||||
.ok_or_else(|| invariant("a switch selector without a type"))?;
|
||||
let lits = switch_literals.get(v).cloned().unwrap_or_default();
|
||||
let int64 = cx.profile.fields().leaf.int64;
|
||||
let form = selector_form(air, &lowered, int64, &lits)
|
||||
let form = selector_form(air, &lowered, &lits)
|
||||
.map_err(|e| located(e, cx, b.raw(), tid))?;
|
||||
let id = values
|
||||
.id(*v)
|
||||
@@ -1942,79 +1921,41 @@ mod tests {
|
||||
fn selector_forms_follow_the_lowered_representation() {
|
||||
let int = |bits| DemoteTy::Scalar(ScalarTy::Int { bits });
|
||||
let lits: BTreeSet<u64> = [0, 1, 5].into_iter().collect();
|
||||
let form =
|
||||
|air: Type, lowered: &DemoteTy, int64| selector_form(&air, lowered, int64, &lits);
|
||||
let form = |air: Type, lowered: &DemoteTy| selector_form(&air, lowered, &lits);
|
||||
assert_eq!(
|
||||
form(Type::Int(1), &DemoteTy::Scalar(ScalarTy::Bool), false),
|
||||
form(Type::Int(1), &DemoteTy::Scalar(ScalarTy::Bool)),
|
||||
Ok(SelectorForm::Bool)
|
||||
);
|
||||
assert_eq!(
|
||||
form(Type::Int(8), &int(8), false),
|
||||
Ok(SelectorForm::ZeroExtend)
|
||||
);
|
||||
assert_eq!(
|
||||
form(Type::Int(16), &int(16), false),
|
||||
Ok(SelectorForm::ZeroExtend)
|
||||
);
|
||||
assert_eq!(
|
||||
form(Type::Int(32), &int(32), false),
|
||||
Ok(SelectorForm::Direct)
|
||||
);
|
||||
assert_eq!(
|
||||
form(Type::Int(64), &int(64), true),
|
||||
Ok(SelectorForm::Narrow64 { miss: 2 })
|
||||
);
|
||||
assert_eq!(
|
||||
form(Type::Int(64), &int(64), false),
|
||||
Err(Unsupported::needs(
|
||||
Feature::Int64Arithmetic,
|
||||
Capability::Feature(VkFeature::ShaderInt64),
|
||||
)
|
||||
.into())
|
||||
);
|
||||
assert_eq!(form(Type::Int(8), &int(8)), Ok(SelectorForm::ZeroExtend));
|
||||
assert_eq!(form(Type::Int(16), &int(16)), Ok(SelectorForm::ZeroExtend));
|
||||
assert_eq!(form(Type::Int(32), &int(32)), Ok(SelectorForm::Direct));
|
||||
// The held forms: narrow widths are zero-extended in their container.
|
||||
for w in [2, 8, 16, 24, 31] {
|
||||
assert_eq!(
|
||||
form(Type::Int(w), &int(32), false),
|
||||
form(Type::Int(w), &int(32)),
|
||||
Ok(SelectorForm::Direct),
|
||||
"i{w}"
|
||||
);
|
||||
}
|
||||
// Without `shaderInt64` the selector is two words.
|
||||
// Two words are not a representation of any integer.
|
||||
let words = DemoteTy::Vector {
|
||||
elem: ScalarTy::Int { bits: 32 },
|
||||
len: 2,
|
||||
};
|
||||
for w in [33, 40, 63, 64] {
|
||||
assert_eq!(
|
||||
form(Type::Int(w), &int(64), true),
|
||||
form(Type::Int(w), &int(64)),
|
||||
Ok(SelectorForm::Narrow64 { miss: 2 }),
|
||||
"i{w}"
|
||||
);
|
||||
assert_eq!(
|
||||
form(Type::Int(w), &int(64), false),
|
||||
Err(Unsupported::needs(
|
||||
Feature::Int64Arithmetic,
|
||||
Capability::Feature(VkFeature::ShaderInt64),
|
||||
)
|
||||
.into()),
|
||||
"i{w}"
|
||||
);
|
||||
assert_eq!(
|
||||
form(Type::Int(w), &words, false),
|
||||
Ok(SelectorForm::Words { miss: 2 }),
|
||||
"i{w}"
|
||||
);
|
||||
// Two words are the representation only without `shaderInt64`.
|
||||
assert_eq!(
|
||||
form(Type::Int(w), &words, true),
|
||||
form(Type::Int(w), &words),
|
||||
Err(not_lowered(LowerFamily::Arith)),
|
||||
"i{w}"
|
||||
);
|
||||
}
|
||||
// A two-word representation of a narrower integer is not a selector form.
|
||||
assert_eq!(
|
||||
form(Type::Int(32), &words, false),
|
||||
form(Type::Int(32), &words),
|
||||
Err(not_lowered(LowerFamily::Arith))
|
||||
);
|
||||
for (air, lowered) in [
|
||||
@@ -2033,7 +1974,7 @@ mod tests {
|
||||
),
|
||||
] {
|
||||
assert_eq!(
|
||||
form(air, &lowered, true),
|
||||
form(air, &lowered),
|
||||
Err(not_lowered(LowerFamily::Arith)),
|
||||
"{lowered:?}"
|
||||
);
|
||||
|
||||
@@ -97,7 +97,7 @@ pub(super) fn check(g: &GroupPlan) -> Result<(), ()> {
|
||||
let form = match (g.scope, g.op) {
|
||||
(_, G::All | G::Any | G::IsFirst) => f.is_bool() && f.lanes == 1,
|
||||
(GroupScope::Simdgroup, G::Ballot | G::ActiveThreadsMask) => {
|
||||
(f.is_int() || f.is_wide()) && f.container() == 64 && f.lanes == 1
|
||||
f.is_int() && f.container() == 64 && f.lanes == 1
|
||||
}
|
||||
(GroupScope::Quad, G::Ballot | G::ActiveThreadsMask) => {
|
||||
f.is_int() && f.container() == 32 && f.lanes == 1
|
||||
@@ -956,7 +956,7 @@ fn simd_op(
|
||||
// Metal's `simd_vote`: bit `i` is Metal lane `i`, zero-extended to the 64-bit result.
|
||||
G::Ballot => {
|
||||
let w = ln.word(fb, v()?)?;
|
||||
crate::lower::arith::wide::zext_word(fb, g.form, w)
|
||||
crate::lower::arith::ops::zext_word(fb, g.form, w)
|
||||
}
|
||||
G::IsFirst if ln.cluster => {
|
||||
let act = ln.active(fb)?;
|
||||
@@ -968,7 +968,7 @@ fn simd_op(
|
||||
// Metal's `simd_active_threads_mask`: the ballot of `true`, bit `i` Metal lane `i`.
|
||||
G::ActiveThreadsMask => {
|
||||
let w = ln.active(fb)?;
|
||||
crate::lower::arith::wide::zext_word(fb, g.form, w)
|
||||
crate::lower::arith::ops::zext_word(fb, g.form, w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ use crate::lower::access::copy::{self, Delta, Endpoint};
|
||||
use crate::lower::access::AccessPlan;
|
||||
use crate::lower::arith::legal::{self, FloatFmt, Form, Held, LoweredConst};
|
||||
use crate::lower::arith::narrow::{self, Fp8Layout};
|
||||
use crate::lower::arith::{self, ops, wide};
|
||||
use crate::lower::arith::{self, ops};
|
||||
use crate::lower::emit::EmitCx;
|
||||
use crate::lower::select::SelectCx;
|
||||
use crate::memory::leaf::{k32, Leaf, Path};
|
||||
@@ -165,11 +165,11 @@ pub struct Mac {
|
||||
}
|
||||
|
||||
/// A block descriptor (`stride` or `origin`): a constant `(x, y)`, or a runtime `<2 x i64>`
|
||||
/// held as a `u64` vector or, without `shaderInt64`, as two words per lane (`wide`).
|
||||
/// held as a `u64` vector.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum Desc {
|
||||
Const([u64; 2]),
|
||||
Value { id: ValueId, wide: bool },
|
||||
Value { id: ValueId },
|
||||
}
|
||||
|
||||
/// How a block addresses its cells.
|
||||
@@ -420,26 +420,21 @@ fn descriptor(cx: &SelectCx<'_>, v: Value) -> Result<Desc, Error> {
|
||||
let ty = cx
|
||||
.value_ty(v)
|
||||
.ok_or_else(|| cx.invariant("a matrix descriptor without a type"))?;
|
||||
let wide = match legal::wide_form_on(cx.entry, cx.profile, ty)? {
|
||||
Form {
|
||||
held: Held::Int {
|
||||
bits: 64,
|
||||
container: 64,
|
||||
},
|
||||
lanes: 2,
|
||||
} => false,
|
||||
Form {
|
||||
held: Held::Wide { bits: 64 },
|
||||
lanes: 2,
|
||||
} => true,
|
||||
_ => return Err(cx.invariant("a matrix descriptor outside its signature")),
|
||||
let descriptor = Form {
|
||||
held: Held::Int {
|
||||
bits: 64,
|
||||
container: 64,
|
||||
},
|
||||
lanes: 2,
|
||||
};
|
||||
if legal::form_on(cx.entry, cx.profile, ty)? != descriptor {
|
||||
return Err(cx.invariant("a matrix descriptor outside its signature"));
|
||||
}
|
||||
if matches!(v, Value::Const(_)) {
|
||||
return Err(cx.invariant("a matrix descriptor constant without lanes"));
|
||||
}
|
||||
Ok(Desc::Value {
|
||||
id: value_id(cx, v)?,
|
||||
wide,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -919,14 +914,10 @@ fn component(
|
||||
) -> BResult<SValue> {
|
||||
match d {
|
||||
Desc::Const([x, y]) => k32(fb, if j == 0 { x } else { y } as u32),
|
||||
Desc::Value { id, wide: true } => {
|
||||
let x = cx.operand(fb, id)?;
|
||||
fb.composite_extract(x, &[0, j])
|
||||
}
|
||||
Desc::Value { id, wide: false } => {
|
||||
Desc::Value { id } => {
|
||||
let x = cx.operand(fb, id)?;
|
||||
let l = fb.composite_extract(x, &[j])?;
|
||||
wide::low_word(fb, l)
|
||||
ops::low_word(fb, l)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,8 +168,7 @@
|
||||
//! sums, products and prefix sums and products of a simdgroup record
|
||||
//! `PrecisionNote::ReductionOrder`. A `double` needs `shaderSubgroupExtendedTypes`. Metal has no
|
||||
//! simdgroup or quad function that moves or combines 64-bit integers, so a call of one is
|
||||
//! `InvalidInput` on every profile; a 64-bit mask is not such a value (the ballot's is two words
|
||||
//! without `shaderInt64`).
|
||||
//! `InvalidInput` on every profile; a 64-bit mask is not such a value.
|
||||
//!
|
||||
//! **Not subgroup operations.** `air.all`/`air.any` of a `bool` vector are `OpAll`/`OpAny`, and
|
||||
//! `air.is_uniform` (Metal's `uniform<T>` assertion, whose result the frontend feeds to
|
||||
@@ -226,7 +225,7 @@ use crate::error::{
|
||||
Capability, Error, Feature, InputError, InputErrorKind, Location, LowerFamily, Unsupported,
|
||||
};
|
||||
use crate::lower::arith;
|
||||
use crate::lower::arith::legal::{form_on, wide_form_on, Form, Held, LoweredConst};
|
||||
use crate::lower::arith::legal::{form_on, Form, Held, LoweredConst};
|
||||
use crate::lower::emit::EmitCx;
|
||||
use crate::lower::select::{FamilyPlans, Plan, SelectCx};
|
||||
use crate::lower::strategy::{FamilyStrategy, Strategy};
|
||||
@@ -1195,13 +1194,7 @@ fn select_group(
|
||||
Location::function(cx.entry.ep.name.clone(), None, Some(at.raw())),
|
||||
)));
|
||||
}
|
||||
// A simdgroup's 64-bit ballot or active mask is two words without `shaderInt64`.
|
||||
let mask = matches!(g.op, GroupOp::Ballot | GroupOp::ActiveThreadsMask);
|
||||
let form = if mask && g.scope == GroupScope::Simdgroup {
|
||||
wide_form_on(cx.entry, cx.profile, inst.ty)?
|
||||
} else {
|
||||
form_on(cx.entry, cx.profile, inst.ty)?
|
||||
};
|
||||
let form = form_on(cx.entry, cx.profile, inst.ty)?;
|
||||
if form.container() == 64
|
||||
&& moves_values(g.op)
|
||||
&& !cx
|
||||
|
||||
@@ -82,7 +82,7 @@ use crate::air::ir::{BinOp as AirBin, ValueId};
|
||||
use crate::budget::Meter;
|
||||
use crate::error::{Error, Feature, LowerFamily, Unsupported};
|
||||
use crate::lower::arith::legal::{Form, Held};
|
||||
use crate::lower::arith::{narrow, ops, wide};
|
||||
use crate::lower::arith::{narrow, ops};
|
||||
use crate::lower::emit::EmitCx;
|
||||
use crate::lower::select::SelectCx;
|
||||
use crate::lower::strategy::Strategy;
|
||||
@@ -1429,7 +1429,7 @@ pub(super) fn simd_op(
|
||||
}
|
||||
G::Ballot => {
|
||||
let (w, _) = word(fb, ln, e, base, v()?, false)?;
|
||||
wide::zext_word(fb, g.form, w)
|
||||
ops::zext_word(fb, g.form, w)
|
||||
}
|
||||
// The ballot of `true`: in a divergent block the active lanes; else every lane of the
|
||||
// simdgroup below the thread count.
|
||||
@@ -1441,7 +1441,7 @@ pub(super) fn simd_op(
|
||||
}
|
||||
None => present(fb, e, base, SIMD_WIDTH)?,
|
||||
};
|
||||
wide::zext_word(fb, g.form, w)
|
||||
ops::zext_word(fb, g.form, w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ pub(super) fn select(
|
||||
// which no form is built for (the module's docs).
|
||||
match texel.0.conv {
|
||||
TexelConv::I32 => {}
|
||||
TexelConv::U64Words { .. } if matches!(op, AirOp::Min | AirOp::Max) => {
|
||||
TexelConv::U64Words if matches!(op, AirOp::Min | AirOp::Max) => {
|
||||
return Err(Unsupported::not_implemented(Feature::ImageAtomics).into());
|
||||
}
|
||||
_ => return Err(refuse()),
|
||||
|
||||
@@ -266,24 +266,10 @@ fn u64_ty(fb: &mut FunctionBuilder<'_>) -> BResult<TypeId> {
|
||||
|
||||
/// Metal's `ulong` texel `(R | G << 32, 0, 0, 1)` of `RG32` image texel `x`: the low word in R and
|
||||
/// the high word in G (measured on Apple M3 Max), and Metal's constant lanes past the first, which
|
||||
/// out of bounds, where R and G are 0, are the same. `wide`: held as the low words `(R, 0, 0, 1)`
|
||||
/// and the high words `(G, 0, 0, 0)`.
|
||||
fn join_words(fb: &mut FunctionBuilder<'_>, x: SValue, wide: bool) -> BResult<SValue> {
|
||||
/// out of bounds, where R and G are 0, are the same.
|
||||
fn join_words(fb: &mut FunctionBuilder<'_>, x: SValue) -> BResult<SValue> {
|
||||
let lo = fb.composite_extract(x, &[0])?;
|
||||
let hi = fb.composite_extract(x, &[1])?;
|
||||
if wide {
|
||||
let u = u32_ty(fb)?;
|
||||
let uvec = vec(fb, u, 4)?;
|
||||
let zero = u32s(fb, 1, 0)?;
|
||||
let one = u32s(fb, 1, 1)?;
|
||||
let low = fb.composite_construct(uvec, &[lo, zero, zero, one])?;
|
||||
let high = fb.composite_construct(uvec, &[hi, zero, zero, zero])?;
|
||||
let ty = fb.module().ty(SType::Struct {
|
||||
members: vec![uvec, uvec].into(),
|
||||
layout: None,
|
||||
})?;
|
||||
return fb.composite_construct(ty, &[low, high]);
|
||||
}
|
||||
let u64_ = u64_ty(fb)?;
|
||||
let lo = fb.convert(ConvOp::UConvert, lo, u64_)?;
|
||||
let hi = fb.convert(ConvOp::UConvert, hi, u64_)?;
|
||||
@@ -297,23 +283,15 @@ fn join_words(fb: &mut FunctionBuilder<'_>, x: SValue, wide: bool) -> BResult<SV
|
||||
}
|
||||
|
||||
/// The `RG32` image texel `(low, high, 0, 0)` of lane 0 of held `ulong` texel `v`: Metal's write
|
||||
/// stores that lane only, its low word in R and its high word in G. `wide`: `v` is held as its low
|
||||
/// words and its high words.
|
||||
fn split_words(fb: &mut FunctionBuilder<'_>, v: SValue, wide: bool) -> BResult<SValue> {
|
||||
/// stores that lane only, its low word in R and its high word in G.
|
||||
fn split_words(fb: &mut FunctionBuilder<'_>, v: SValue) -> BResult<SValue> {
|
||||
let u = u32_ty(fb)?;
|
||||
let (lo, hi) = if wide {
|
||||
(
|
||||
fb.composite_extract(v, &[0, 0])?,
|
||||
fb.composite_extract(v, &[1, 0])?,
|
||||
)
|
||||
} else {
|
||||
let u64_ = u64_ty(fb)?;
|
||||
let x = fb.composite_extract(v, &[0])?;
|
||||
let lo = fb.convert(ConvOp::UConvert, x, u)?;
|
||||
let shift = splat(fb, u64_, 1, 32)?;
|
||||
let hi = fb.binary(BinOp::ShiftRightLogical, x, shift)?;
|
||||
(lo, fb.convert(ConvOp::UConvert, hi, u)?)
|
||||
};
|
||||
let u64_ = u64_ty(fb)?;
|
||||
let x = fb.composite_extract(v, &[0])?;
|
||||
let lo = fb.convert(ConvOp::UConvert, x, u)?;
|
||||
let shift = splat(fb, u64_, 1, 32)?;
|
||||
let hi = fb.binary(BinOp::ShiftRightLogical, x, shift)?;
|
||||
let hi = fb.convert(ConvOp::UConvert, hi, u)?;
|
||||
let zero = u32s(fb, 1, 0)?;
|
||||
let ty = vec(fb, u, 4)?;
|
||||
fb.composite_construct(ty, &[lo, hi, zero, zero])
|
||||
@@ -963,7 +941,7 @@ pub fn held_texel(
|
||||
let mask = u32s(fb, n, 0xFFFF)?;
|
||||
fb.binary(BinOp::BitwiseAnd, x, mask)
|
||||
}
|
||||
TexelConv::U64Words { wide } => join_words(fb, x, wide),
|
||||
TexelConv::U64Words => join_words(fb, x),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1103,7 +1081,7 @@ pub fn to_image(
|
||||
fb.binary(BinOp::ShiftRightArithmetic, s, sixteen)?
|
||||
}
|
||||
TexelConv::I16 { .. } => v,
|
||||
TexelConv::U64Words { wide } => split_words(fb, v, wide)?,
|
||||
TexelConv::U64Words => split_words(fb, v)?,
|
||||
};
|
||||
let x = match decl.class {
|
||||
StorageImageClass::Identity => x,
|
||||
@@ -1354,7 +1332,7 @@ fn held_lane(
|
||||
match form.conv {
|
||||
TexelConv::F32 | TexelConv::F16 => Ok((f32_ty(fb)?, u64::from(1.0f32.to_bits()))),
|
||||
TexelConv::I32 | TexelConv::I16 { .. } => Ok((u32_ty(fb)?, 1)),
|
||||
TexelConv::U64Words { .. } => Err(cx.fail("a swizzled `ulong` texel")),
|
||||
TexelConv::U64Words => Err(cx.fail("a swizzled `ulong` texel")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2399,7 +2377,7 @@ fn slice_texel(fb: &mut FunctionBuilder<'_>, form: TexelForm, v: SValue) -> BRes
|
||||
let elem = match form.conv {
|
||||
TexelConv::F32 | TexelConv::F16 => f32_ty(fb)?,
|
||||
TexelConv::I32 | TexelConv::I16 { .. } => u32_ty(fb)?,
|
||||
TexelConv::U64Words { .. } => u64_ty(fb)?,
|
||||
TexelConv::U64Words => u64_ty(fb)?,
|
||||
};
|
||||
let ty = vec(fb, elem, 4)?;
|
||||
let zero = |fb: &mut FunctionBuilder<'_>| -> BResult<SValue> {
|
||||
|
||||
@@ -239,9 +239,8 @@ pub enum TexelConv {
|
||||
/// Metal's `ulong` texel as the two 32-bit words of an `RG32` image texel, the low word in R
|
||||
/// (measured on Apple M3 Max): a read is `(R | G << 32, 0, 0, 1)` (Metal's lanes, the same out
|
||||
/// of bounds, where R and G are 0), and a write stores lane 0's low word in R and its high word
|
||||
/// in G. Held in `u64`s, or, `wide` on a profile without `shaderInt64`, as the low words' and
|
||||
/// the high words' `uvec4`s.
|
||||
U64Words { wide: bool },
|
||||
/// in G. Held in `u64`s.
|
||||
U64Words,
|
||||
}
|
||||
|
||||
/// The texel an operation reads or writes: its conversion and lane count (4, or 1 for a depth
|
||||
@@ -1209,16 +1208,11 @@ pub(crate) fn texel_conv(elem: Elem, sign: Option<Sign>) -> Result<(TexelConv, T
|
||||
})
|
||||
}
|
||||
|
||||
/// [`texel_conv`] of a read, write, or atomic on profile `p`, which also takes Metal's `ulong`
|
||||
/// texel (no sampling takes it), held as `p` holds 64-bit integers.
|
||||
fn image_texel_conv(
|
||||
elem: Elem,
|
||||
sign: Option<Sign>,
|
||||
p: &crate::device::profile::DeviceProfile,
|
||||
) -> Result<(TexelConv, TexelClass), Error> {
|
||||
/// [`texel_conv`] of a read, write, or atomic, which also takes Metal's `ulong` texel (no sampling
|
||||
/// takes it).
|
||||
fn image_texel_conv(elem: Elem, sign: Option<Sign>) -> Result<(TexelConv, TexelClass), Error> {
|
||||
if (elem, sign) == (Elem::I64, Some(Sign::Unsigned)) {
|
||||
let wide = crate::lower::arith::legal::holds_wide(p);
|
||||
return Ok((TexelConv::U64Words { wide }, TexelClass::Uint64));
|
||||
return Ok((TexelConv::U64Words, TexelClass::Uint64));
|
||||
}
|
||||
texel_conv(elem, sign)
|
||||
}
|
||||
@@ -1860,12 +1854,12 @@ fn select_image(
|
||||
) -> Result<TextureStrategy, Error> {
|
||||
let shape = t.image;
|
||||
let texel = match t.texel {
|
||||
Some(x) if matches!(t.op, TexOp::Read | TexOp::Write | TexOp::Atomic(_)) => Some(
|
||||
image_texel_conv(x.ty.elem, x.sign, cx.profile).map(|(c, class)| {
|
||||
Some(x) if matches!(t.op, TexOp::Read | TexOp::Write | TexOp::Atomic(_)) => {
|
||||
Some(image_texel_conv(x.ty.elem, x.sign).map(|(c, class)| {
|
||||
let lanes = u8::try_from(x.ty.lanes).unwrap_or(0);
|
||||
(TexelForm { conv: c, lanes }, class)
|
||||
})?,
|
||||
),
|
||||
})?)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
observe(cx, image, shape, texel.map(|(_, c)| c))?;
|
||||
@@ -2101,7 +2095,7 @@ fn select_read(
|
||||
// to the decoded texel. So does a packed normalized sampled slot of the
|
||||
// variant, to the texel its class converts: the variant holds no other sampled slot.
|
||||
let storage_swizzle = shape.dim != ImageDim::Buffer && swizzled_storage(cx, image)?;
|
||||
if storage_swizzle && (texel.lanes != 4 || matches!(texel.conv, TexelConv::U64Words { .. })) {
|
||||
if storage_swizzle && (texel.lanes != 4 || matches!(texel.conv, TexelConv::U64Words)) {
|
||||
return Err(Unsupported::not_implemented(Feature::TextureSwizzle).into());
|
||||
}
|
||||
// A `ulong` read's lanes past the first are Metal's constants `(0, 0, 1)` in and out of
|
||||
@@ -2109,7 +2103,7 @@ fn select_read(
|
||||
// the alpha wherever the function reads a lane.
|
||||
let observed = (check == ReadCheck::Shader || level_views || residency)
|
||||
&& texel.lanes == 4
|
||||
&& !matches!(texel.conv, TexelConv::U64Words { .. })
|
||||
&& !matches!(texel.conv, TexelConv::U64Words)
|
||||
&& (storage_swizzle || alpha_read(cx, at));
|
||||
let alpha = match image {
|
||||
ImageRef::Slot(index) if observed => {
|
||||
@@ -2280,7 +2274,7 @@ fn select_through(
|
||||
if !t.sampler.bordered() {
|
||||
return Ok(());
|
||||
}
|
||||
if matches!(texel.conv, TexelConv::U64Words { .. }) {
|
||||
if matches!(texel.conv, TexelConv::U64Words) {
|
||||
return Err(Unsupported::not_implemented(Feature::Lowering(LowerFamily::Texture)).into());
|
||||
}
|
||||
match image {
|
||||
@@ -2370,7 +2364,7 @@ fn select_write(
|
||||
// A storage slot bound to a swizzled texture stores each channel from the lane the swizzle
|
||||
// takes it to, under its variant, as plain Metal writes it. A `ulong` texel's is not measured.
|
||||
let swizzle = shape.dim != ImageDim::Buffer && swizzled_storage(cx, image)?;
|
||||
if swizzle && (texel.lanes != 4 || matches!(texel.conv, TexelConv::U64Words { .. })) {
|
||||
if swizzle && (texel.lanes != 4 || matches!(texel.conv, TexelConv::U64Words)) {
|
||||
return Err(Unsupported::not_implemented(Feature::TextureSwizzle).into());
|
||||
}
|
||||
if let (true, ImageRef::Slot(index)) = (swizzle, image) {
|
||||
|
||||
@@ -70,7 +70,6 @@ use crate::error::{
|
||||
AccessCause, Error, Feature, InternalError, InternalKind, LowerFamily, Unsupported,
|
||||
};
|
||||
use crate::memory::leaf::k32;
|
||||
use crate::memory::views::{self, View};
|
||||
use crate::pipeline::sym::ImageAccess;
|
||||
use crate::pipeline::sym::ResourceSlot;
|
||||
use crate::spirv::builder::{FunctionBuilder, ModuleBuilder};
|
||||
@@ -374,19 +373,6 @@ fn walk_roots(
|
||||
pub const NEUTRAL_ELEMENT: u32 = 0;
|
||||
/// Bytes of one handle-table entry.
|
||||
pub const TABLE_ENTRY_BYTES: u32 = 16;
|
||||
/// Words of one handle-table entry: the resource id's low and high words, the element, the flags.
|
||||
const ENTRY_WORDS: u32 = 4;
|
||||
/// Word of an entry holding the resource id's low 32 bits.
|
||||
pub const ENTRY_ID_LO: u32 = 0;
|
||||
/// Word of an entry holding the resource id's high 32 bits.
|
||||
pub const ENTRY_ID_HI: u32 = 1;
|
||||
/// Word of an entry holding the heap element.
|
||||
pub const ENTRY_ELEMENT: u32 = 2;
|
||||
/// Word of an entry holding 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.
|
||||
pub const ENTRY_FLAGS: u32 = 3;
|
||||
/// The flag of a texture entry whose pixel format has no alpha
|
||||
/// (`metal::format::out_of_bounds_alpha_one`): Metal's out-of-bounds read of such a texture
|
||||
/// bound to a slot returns alpha 1 (MSL 4.1 section 2.9.1), which a read through the table takes
|
||||
@@ -1250,24 +1236,13 @@ impl Working {
|
||||
pub struct Table {
|
||||
global: SGlobalId,
|
||||
u32_ty: TypeId,
|
||||
/// The `u64` type when the table is an entry array `{ Entry entries[]; }`, `Entry { u64 id;
|
||||
/// u32 element; u32 flags; }` (a profile with `shaderInt64`), whose search compares each id
|
||||
/// in one instruction; `None` for a word view `{ u32 words[]; }`, which compares an id's two
|
||||
/// words.
|
||||
u64_ty: Option<TypeId>,
|
||||
/// The `u64` type of the entry array `{ Entry entries[]; }`, `Entry { u64 id; u32 element;
|
||||
/// u32 flags; }`, whose search compares each id in one instruction.
|
||||
u64_ty: TypeId,
|
||||
}
|
||||
|
||||
/// Declare the handle table at binding symbol `sym`: an entry array when `int64` (the profile
|
||||
/// has `shaderInt64`), else a word storage view.
|
||||
pub fn declare_table(mb: &mut ModuleBuilder, sym: ResourceSlot, int64: bool) -> BResult<Table> {
|
||||
if !int64 {
|
||||
let v = views::declare_at(mb, sym)?;
|
||||
return Ok(Table {
|
||||
global: v.global,
|
||||
u32_ty: v.u32_ty,
|
||||
u64_ty: None,
|
||||
});
|
||||
}
|
||||
/// Declare the handle table at binding symbol `sym`: an entry array.
|
||||
pub fn declare_table(mb: &mut ModuleBuilder, sym: ResourceSlot) -> BResult<Table> {
|
||||
let int = |width| SType::Int {
|
||||
width,
|
||||
signed: false,
|
||||
@@ -1292,32 +1267,10 @@ pub fn declare_table(mb: &mut ModuleBuilder, sym: ResourceSlot, int64: bool) ->
|
||||
Ok(Table {
|
||||
global,
|
||||
u32_ty,
|
||||
u64_ty: Some(u64_ty),
|
||||
u64_ty,
|
||||
})
|
||||
}
|
||||
|
||||
/// `a ≤ b` for two 64-bit values held as `(low, high)` word pairs.
|
||||
fn le64(fb: &mut FunctionBuilder<'_>, a: (SValue, SValue), b: (SValue, SValue)) -> BResult<SValue> {
|
||||
let hi_lt = fb.binary(BinOp::ULessThan, a.1, b.1)?;
|
||||
let hi_eq = fb.binary(BinOp::IEqual, a.1, b.1)?;
|
||||
let lo_le = fb.binary(BinOp::ULessThanEqual, a.0, b.0)?;
|
||||
let tie = fb.binary(BinOp::LogicalAnd, hi_eq, lo_le)?;
|
||||
fb.binary(BinOp::LogicalOr, hi_lt, tie)
|
||||
}
|
||||
|
||||
/// Word `field` of entry `k` (a `u32`) of the word view `table`.
|
||||
fn entry_word(fb: &mut FunctionBuilder<'_>, table: View, k: SValue, field: u32) -> BResult<SValue> {
|
||||
let stride = k32(fb, ENTRY_WORDS)?;
|
||||
let at = fb.binary(BinOp::IMul, k, stride)?;
|
||||
let at = if field == 0 {
|
||||
at
|
||||
} else {
|
||||
let f = k32(fb, field)?;
|
||||
fb.binary(BinOp::IAdd, at, f)?
|
||||
};
|
||||
views::read_word(fb, table, at)
|
||||
}
|
||||
|
||||
/// Member `member` of entry `k` of the entry array `t` (0 the id, 1 the element, 2 the flags).
|
||||
fn entry_member(fb: &mut FunctionBuilder<'_>, t: Table, k: SValue, member: u32) -> BResult<SValue> {
|
||||
let base = fb.module().global_value(t.global)?;
|
||||
@@ -1419,12 +1372,13 @@ fn carry(
|
||||
pub enum EntryField {
|
||||
/// The heap element.
|
||||
Element,
|
||||
/// The flags: a sampler entry's [`SamplerWord`](crate::metal::sampler::SamplerWord).
|
||||
/// 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.
|
||||
Flags,
|
||||
}
|
||||
|
||||
/// An upper estimate of [`entry_field`]'s words: over a word view, the index's scaling and offset,
|
||||
/// the access chain, and the load; over an entry array, the access chain and the load; with their
|
||||
/// An upper estimate of [`entry_field`]'s words: the access chain and the load, with their
|
||||
/// constants.
|
||||
pub const ENTRY_FIELD_WORDS: u32 = 32;
|
||||
|
||||
@@ -1436,34 +1390,18 @@ pub fn entry_field(
|
||||
k: SValue,
|
||||
field: EntryField,
|
||||
) -> BResult<SValue> {
|
||||
let (member, word) = match field {
|
||||
EntryField::Element => (1, ENTRY_ELEMENT),
|
||||
EntryField::Flags => (2, ENTRY_FLAGS),
|
||||
let member = match field {
|
||||
EntryField::Element => 1,
|
||||
EntryField::Flags => 2,
|
||||
};
|
||||
match t.u64_ty {
|
||||
Some(_) => entry_member(fb, t, k, member),
|
||||
None => {
|
||||
let words = View {
|
||||
global: t.global,
|
||||
u32_ty: t.u32_ty,
|
||||
};
|
||||
entry_word(fb, words, k, word)
|
||||
}
|
||||
}
|
||||
entry_member(fb, t, k, member)
|
||||
}
|
||||
|
||||
/// The index of the last entry of the handle table `t` (its largest id's), from its length
|
||||
/// (`OpArrayLength`): the null entry's, 0, where the table holds no other.
|
||||
pub fn last_entry(fb: &mut FunctionBuilder<'_>, t: Table) -> BResult<SValue> {
|
||||
let base_ptr = fb.module().global_value(t.global)?;
|
||||
let len = fb.array_length(base_ptr, 0)?;
|
||||
let count = match t.u64_ty {
|
||||
Some(_) => len,
|
||||
None => {
|
||||
let two = k32(fb, 2)?;
|
||||
fb.binary(BinOp::ShiftRightLogical, len, two)?
|
||||
}
|
||||
};
|
||||
let count = fb.array_length(base_ptr, 0)?;
|
||||
let one = k32(fb, 1)?;
|
||||
fb.binary(BinOp::ISub, count, one)
|
||||
}
|
||||
@@ -1472,10 +1410,10 @@ pub fn last_entry(fb: &mut FunctionBuilder<'_>, t: Table) -> BResult<SValue> {
|
||||
/// (the module docs' layout): a branch-free binary search of [`SEARCH_STEPS`] steps for the last
|
||||
/// entry whose id is at most the key, then the entry's element if its id is the key, else
|
||||
/// [`NEUTRAL_ELEMENT`]. Entry 0 is the null entry (id 0), so the search always finds an entry,
|
||||
/// and every entry it reads is below the table's length (`OpArrayLength`). An entry array
|
||||
/// compares each id as one `u64`; a word view compares its two words. [`Lookup::Flagged`] also
|
||||
/// moves the found entry's flags it carries into their handle bits (a miss is
|
||||
/// [`NEUTRAL_ELEMENT`] without them), and [`Lookup::Entry`] yields the found entry's index in place of its element, 0 for a miss.
|
||||
/// and every entry it reads is below the table's length (`OpArrayLength`). It compares each id as
|
||||
/// one `u64`. [`Lookup::Flagged`] also moves the found entry's flags it carries into their handle
|
||||
/// bits (a miss is [`NEUTRAL_ELEMENT`] without them), and [`Lookup::Entry`] yields the found
|
||||
/// entry's index in place of its element, 0 for a miss.
|
||||
pub fn lookup(
|
||||
fb: &mut FunctionBuilder<'_>,
|
||||
t: Table,
|
||||
@@ -1487,39 +1425,18 @@ pub fn lookup(
|
||||
let len = fb.array_length(base_ptr, 0)?;
|
||||
let one = k32(fb, 1)?;
|
||||
let zero = k32(fb, 0)?;
|
||||
let words = View {
|
||||
global: t.global,
|
||||
u32_ty: t.u32_ty,
|
||||
};
|
||||
// The key, and the id of an entry, in the table's form.
|
||||
let (key, count) = match t.u64_ty {
|
||||
Some(u64_ty) => {
|
||||
let l = fb.convert(ConvOp::UConvert, lo, u64_ty)?;
|
||||
let h = fb.convert(ConvOp::UConvert, hi, u64_ty)?;
|
||||
let s = k32(fb, 32)?;
|
||||
let h = fb.binary(BinOp::ShiftLeftLogical, h, s)?;
|
||||
(fb.binary(BinOp::BitwiseOr, h, l)?, len)
|
||||
}
|
||||
None => {
|
||||
let two = k32(fb, 2)?;
|
||||
(lo, fb.binary(BinOp::ShiftRightLogical, len, two)?)
|
||||
}
|
||||
};
|
||||
// The key as one `u64`.
|
||||
let l = fb.convert(ConvOp::UConvert, lo, t.u64_ty)?;
|
||||
let h = fb.convert(ConvOp::UConvert, hi, t.u64_ty)?;
|
||||
let s = k32(fb, 32)?;
|
||||
let h = fb.binary(BinOp::ShiftLeftLogical, h, s)?;
|
||||
let key = fb.binary(BinOp::BitwiseOr, h, l)?;
|
||||
let at_most_key = |fb: &mut FunctionBuilder<'_>, k: SValue| -> BResult<SValue> {
|
||||
match t.u64_ty {
|
||||
Some(_) => {
|
||||
let id = entry_member(fb, t, k, 0)?;
|
||||
fb.binary(BinOp::ULessThanEqual, id, key)
|
||||
}
|
||||
None => {
|
||||
let id_lo = entry_word(fb, words, k, ENTRY_ID_LO)?;
|
||||
let id_hi = entry_word(fb, words, k, ENTRY_ID_HI)?;
|
||||
le64(fb, (id_lo, id_hi), (lo, hi))
|
||||
}
|
||||
}
|
||||
let id = entry_member(fb, t, k, 0)?;
|
||||
fb.binary(BinOp::ULessThanEqual, id, key)
|
||||
};
|
||||
let mut base = zero;
|
||||
let mut len = count;
|
||||
let mut len = len;
|
||||
for _ in 0..SEARCH_STEPS {
|
||||
let half = fb.binary(BinOp::ShiftRightLogical, len, one)?;
|
||||
let mid = fb.binary(BinOp::IAdd, base, half)?;
|
||||
@@ -1527,19 +1444,8 @@ pub fn lookup(
|
||||
base = fb.select(take, mid, base)?;
|
||||
len = fb.binary(BinOp::ISub, len, half)?;
|
||||
}
|
||||
let hit = match t.u64_ty {
|
||||
Some(_) => {
|
||||
let id = entry_member(fb, t, base, 0)?;
|
||||
fb.binary(BinOp::IEqual, id, key)?
|
||||
}
|
||||
None => {
|
||||
let id_lo = entry_word(fb, words, base, ENTRY_ID_LO)?;
|
||||
let id_hi = entry_word(fb, words, base, ENTRY_ID_HI)?;
|
||||
let eq_lo = fb.binary(BinOp::IEqual, id_lo, lo)?;
|
||||
let eq_hi = fb.binary(BinOp::IEqual, id_hi, hi)?;
|
||||
fb.binary(BinOp::LogicalAnd, eq_lo, eq_hi)?
|
||||
}
|
||||
};
|
||||
let id = entry_member(fb, t, base, 0)?;
|
||||
let hit = fb.binary(BinOp::IEqual, id, key)?;
|
||||
if form == Lookup::Entry {
|
||||
// The null entry, index 0, for a miss.
|
||||
return fb.select(hit, base, zero);
|
||||
@@ -1556,14 +1462,13 @@ pub fn lookup(
|
||||
fb.select(hit, handle, neutral)
|
||||
}
|
||||
|
||||
/// An upper estimate of [`define_lookup`]'s words, counted once per module: per search step, over
|
||||
/// an entry array, the id's access chain and load, the compare, and the step's arithmetic, or, over
|
||||
/// a word view, two word reads (about 20 words each) and a five-instruction compare; then the
|
||||
/// An upper estimate of [`define_lookup`]'s words, counted once per module: per search step, the
|
||||
/// id's access chain and load, the compare, and the step's arithmetic; then the
|
||||
/// entry's id and element, and the function's own instructions and types. The flagged form also
|
||||
/// reads the entry's flags (a word read) and moves each carried field (three instructions and two
|
||||
/// constants); the entry form reads no element.
|
||||
pub fn lookup_routine_words(int64: bool, form: Lookup) -> u32 {
|
||||
let step = if int64 { 48 } else { 96 };
|
||||
pub fn lookup_routine_words(form: Lookup) -> u32 {
|
||||
let step = 48;
|
||||
let carried = 48 * form.carried().len() as u32;
|
||||
SEARCH_STEPS * step + 160 + carried
|
||||
}
|
||||
@@ -1584,6 +1489,7 @@ pub fn define_lookup(mb: &mut ModuleBuilder, t: Table, form: Lookup) -> BResult<
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::memory::views;
|
||||
|
||||
#[test]
|
||||
fn handle_indices_keep_the_classes_apart() {
|
||||
@@ -1755,16 +1661,14 @@ mod tests {
|
||||
|
||||
/// A kernel that looks up the [`KEYS`] ids (low, high word pairs) at the start of the
|
||||
/// buffer at slot 1 in the handle table at slot 0 by calling [`define_lookup`]'s search in
|
||||
/// `form`, and writes each element after them. The table is an entry array when `int64`, else
|
||||
/// a word view.
|
||||
fn lookup_module(int64: bool, form: Lookup) -> BResult<crate::spirv::ir::TypedModule> {
|
||||
search_module(int64, form, |_, _, h| Ok(vec![h]))
|
||||
/// `form`, and writes each element after them.
|
||||
fn lookup_module(form: Lookup) -> BResult<crate::spirv::ir::TypedModule> {
|
||||
search_module(form, |_, _, h| Ok(vec![h]))
|
||||
}
|
||||
|
||||
/// [`lookup_module`] writing the words `per_key` makes of each key's handle (`per_key` of the
|
||||
/// function, the table and the handle), each key's words after the keys in turn.
|
||||
fn search_module(
|
||||
int64: bool,
|
||||
form: Lookup,
|
||||
per_key: impl Fn(&mut FunctionBuilder<'_>, Table, SValue) -> BResult<Vec<SValue>>,
|
||||
) -> BResult<crate::spirv::ir::TypedModule> {
|
||||
@@ -1777,7 +1681,7 @@ mod tests {
|
||||
index,
|
||||
};
|
||||
let mut b = ModuleBuilder::new();
|
||||
let t = declare_table(&mut b, sym(0), int64)?;
|
||||
let t = declare_table(&mut b, sym(0))?;
|
||||
let io = views::declare_at(&mut b, sym(1))?;
|
||||
let search = define_lookup(&mut b, t, form)?;
|
||||
let void = b.ty(Type::Void)?;
|
||||
@@ -1810,34 +1714,32 @@ mod tests {
|
||||
|
||||
/// The emitted search is the host model: over the CPU interpreter, every key of tables of
|
||||
/// 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) and a
|
||||
/// word view. [`Lookup::Flagged`] also carries a found entry's [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`]
|
||||
/// 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.
|
||||
#[test]
|
||||
fn the_emitted_search_matches_the_host_model() {
|
||||
for int64 in [true, false] {
|
||||
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,
|
||||
] {
|
||||
emitted_search_matches_the_host_model(int64, form);
|
||||
}
|
||||
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,
|
||||
] {
|
||||
emitted_search_matches_the_host_model(form);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1918,10 +1820,10 @@ mod tests {
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn emitted_search_matches_the_host_model(int64: bool, form: Lookup) {
|
||||
fn emitted_search_matches_the_host_model(form: Lookup) {
|
||||
use crate::pipeline::sym::{ResourceKind, ResourceSlot, Stage};
|
||||
use crate::spirv::interp::{run, Buffer, Config, Resources};
|
||||
let m = lookup_module(int64, form).expect("module");
|
||||
let m = lookup_module(form).expect("module");
|
||||
let sym = |index| ResourceSlot {
|
||||
stage: Stage::Kernel,
|
||||
kind: ResourceKind::Buffer,
|
||||
@@ -1998,7 +1900,7 @@ mod tests {
|
||||
t.iter().rposition(|(k, _)| k == id).map_or(0, |i| i as u32)
|
||||
}
|
||||
};
|
||||
assert_eq!(got, want, "int64 {int64} {form:?} n {n} id {id:#x}");
|
||||
assert_eq!(got, want, "{form:?} n {n} id {id:#x}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,10 +129,9 @@ use crate::air::ir::{Type, TypeId as AirTypeId, TypeLayouts};
|
||||
use crate::air::Entry;
|
||||
use crate::device::DeviceProfile;
|
||||
use crate::error::{AccessCause, Error, Unsupported};
|
||||
use crate::lower::arith::legal::{self, wide_form_on};
|
||||
use crate::lower::arith::legal::{self, form_on};
|
||||
use crate::lower::arith::narrow;
|
||||
use crate::lower::arith::ops;
|
||||
use crate::lower::arith::wide;
|
||||
use crate::lower::arith::{FloatFmt, Form, Held};
|
||||
use crate::spirv::builder::constructs::{ArmEnd, ArmFn};
|
||||
use crate::spirv::builder::FunctionBuilder;
|
||||
@@ -346,7 +345,6 @@ pub fn leaf_of(
|
||||
align: u64,
|
||||
proven: u64,
|
||||
) -> Result<Leaf, Error> {
|
||||
// A 64-bit integer is two words on a profile without `shaderInt64`, in a chunk too.
|
||||
let form = match legal::chunked(e.module.types(), ty) {
|
||||
Some((held, lanes)) => Form {
|
||||
held: legal::held_on(p, held)?,
|
||||
@@ -355,7 +353,7 @@ pub fn leaf_of(
|
||||
.filter(|l| *l > 4)
|
||||
.ok_or_else(|| not_lowered(AccessCause::AccessType))?,
|
||||
},
|
||||
None => wide_form_on(e, p, ty)?,
|
||||
None => form_on(e, p, ty)?,
|
||||
};
|
||||
let bytes = layouts
|
||||
.store_size(ty)
|
||||
@@ -363,7 +361,7 @@ pub fn leaf_of(
|
||||
let bytes = u32::try_from(bytes).map_err(|_| not_lowered(AccessCause::AccessType))?;
|
||||
if form.lanes > 1 {
|
||||
let lane_bits = match form.held {
|
||||
Held::Int { bits, .. } | Held::Wide { bits } => bits,
|
||||
Held::Int { bits, .. } => bits,
|
||||
Held::Float(f) => f.bits(),
|
||||
Held::Bool => return Err(not_lowered(AccessCause::AccessType)),
|
||||
};
|
||||
@@ -823,10 +821,6 @@ pub fn value_of(fb: &mut FunctionBuilder<'_>, leaf: &Leaf, words: &[Value]) -> B
|
||||
let ty = chunked_ty(fb, form)?;
|
||||
return fb.composite_construct(ty, &parts);
|
||||
}
|
||||
if form.is_wide() {
|
||||
// Two words per lane, low first.
|
||||
return wide::from_words(fb, form, words);
|
||||
}
|
||||
if form.lanes > 1 {
|
||||
if let Some(v) = vector_of(fb, form, words)? {
|
||||
return Ok(v);
|
||||
@@ -875,7 +869,6 @@ pub fn value_of(fb: &mut FunctionBuilder<'_>, leaf: &Leaf, words: &[Value]) -> B
|
||||
};
|
||||
join64(fb, lo, hi, elem)
|
||||
}
|
||||
Held::Wide { .. } => Err(dangling()),
|
||||
Held::Float(FloatFmt::Half | FloatFmt::BFloat) => {
|
||||
// A narrow float is held widened: its 16 format bits (`from_bits` reads only the
|
||||
// low 16 bits), a `half` widened from its word where the device widens it.
|
||||
@@ -992,12 +985,6 @@ pub fn words_of(fb: &mut FunctionBuilder<'_>, leaf: &Leaf, v: Value) -> BResult<
|
||||
}
|
||||
return Ok(out);
|
||||
}
|
||||
if form.is_wide() {
|
||||
// Its words are the value's; an `i33..i63` high word covers fewer bytes.
|
||||
let mut ws = wide::to_words(fb, form, v)?;
|
||||
ws.truncate(leaf.words() as usize);
|
||||
return Ok(ws);
|
||||
}
|
||||
if form.lanes > 1 {
|
||||
if let Some(ws) = vector_words(fb, leaf, v)? {
|
||||
return Ok(ws);
|
||||
@@ -1034,7 +1021,6 @@ pub fn words_of(fb: &mut FunctionBuilder<'_>, leaf: &Leaf, v: Value) -> BResult<
|
||||
let x = ops::mask(fb, scalar, x)?;
|
||||
put(fb, &mut out, i * lane_bytes, x)?;
|
||||
}
|
||||
Held::Wide { .. } => return Err(dangling()),
|
||||
Held::Int { .. } | Held::Float(FloatFmt::F64) => {
|
||||
let x = ops::mask(fb, scalar, x)?;
|
||||
let (lo, hi) = split64(fb, x)?;
|
||||
@@ -1150,12 +1136,11 @@ fn vector_words(
|
||||
}
|
||||
|
||||
/// Whether a vector unit's leaf (8 or 16 bytes) has a register value of the `uvecN`'s bits:
|
||||
/// 32-bit lanes, or 64-bit ones, filling its bytes, held natively (not chunked, nor as word pairs).
|
||||
/// 32-bit lanes, or 64-bit ones, filling its bytes, held natively (not chunked).
|
||||
fn vec_bits(leaf: &Leaf) -> bool {
|
||||
let form = leaf.form;
|
||||
let lanes = u32::from(form.lanes);
|
||||
!leaf.chunked()
|
||||
&& !form.is_wide()
|
||||
&& match form.held {
|
||||
Held::Int {
|
||||
bits: 32,
|
||||
|
||||
@@ -88,13 +88,11 @@ pub struct LoweringInputs {
|
||||
/// So everything the function reads of its buffers is in the root table, which the device
|
||||
/// replay's preprocess writes per replayed command from the command's record (`bind::replay`).
|
||||
/// A vertex or fragment function compiles so too, for a replayed draw: its buffers are the
|
||||
/// command's, in the slot table at its own stage's `RootTableAddress`. It needs device
|
||||
/// addresses (`bufferDeviceAddress` and `shaderInt64`: `GpuEncodedIndirectCommands` names
|
||||
/// them otherwise); a tile, object or mesh function, a kernel with a stage-input descriptor,
|
||||
/// and a vertex function that fetches an attribute in fixed function are
|
||||
/// `Unsupported{GpuEncodedIndirectCommands, NotImplemented}` under it (a replayed command is a
|
||||
/// compute dispatch with no stage-in region, or a draw whose buffers no fixed-function input
|
||||
/// reads: a pulled attribute reads its slot table).
|
||||
/// command's, in the slot table at its own stage's `RootTableAddress`. A tile, object or mesh
|
||||
/// function, a kernel with a stage-input descriptor, and a vertex function that fetches an
|
||||
/// attribute in fixed function are `Unsupported{GpuEncodedIndirectCommands, NotImplemented}`
|
||||
/// under it (a replayed command is a compute dispatch with no stage-in region, or a draw whose
|
||||
/// buffers no fixed-function input reads: a pulled attribute reads its slot table).
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub replay_bindings: bool,
|
||||
/// With `replay_bindings`, the vertex function of a draw replay merged into one draw
|
||||
@@ -285,8 +283,7 @@ pub struct LoweringInputs {
|
||||
/// `PushField::IndirectBase`, in its first block, and an invocation of a command outside the
|
||||
/// range (`command - location >= length`, in `u32`) stores its `[[position]]` as `(2, 2, 2,
|
||||
/// 1)`, outside every clip volume, and returns before the body, so its command draws nothing
|
||||
/// and writes no memory. A direct draw of the state is pushed a range of every command. Refused
|
||||
/// on a device without device addresses (`Feature::GpuEncodedIndirectCommands`).
|
||||
/// and writes no memory. A direct draw of the state is pushed a range of every command.
|
||||
/// `Device::compile_render_pipeline` sets it for a `Function` vertex stage of a descriptor that
|
||||
/// sets the flag, whose vertex function then pulls every attribute it reads. Any other function
|
||||
/// compiles as without it.
|
||||
|
||||
@@ -172,7 +172,7 @@ impl FunctionBuilder<'_> {
|
||||
}
|
||||
self.bool_ty(x.n)?
|
||||
}
|
||||
BinOp::IAddCarry | BinOp::ISubBorrow | BinOp::UMulExtended | BinOp::SMulExtended => {
|
||||
BinOp::IAddCarry | BinOp::UMulExtended | BinOp::SMulExtended => {
|
||||
// The struct members, and so both operands, share one type; all but
|
||||
// `SMulExtended` require it unsigned.
|
||||
let unsigned = op != BinOp::SMulExtended;
|
||||
|
||||
@@ -817,7 +817,7 @@ fn binary(p: &Prog<'_>, op: BinOp, a: Value, va: &Val, vb: &Val) -> IResult<Val>
|
||||
)))
|
||||
})
|
||||
}
|
||||
B::IAddCarry | B::ISubBorrow | B::UMulExtended | B::SMulExtended => {
|
||||
B::IAddCarry | B::UMulExtended | B::SMulExtended => {
|
||||
let w = p.t.num_of(a)?.width;
|
||||
let (xs, ys) = (va.comps()?, vb.comps()?);
|
||||
let (mut lo, mut hi) = (Vec::new(), Vec::new());
|
||||
@@ -827,7 +827,6 @@ fn binary(p: &Prog<'_>, op: BinOp, a: Value, va: &Val, vb: &Val) -> IResult<Val>
|
||||
let s = u128::from(x) + u128::from(y);
|
||||
(s as u64 & mask(w), u64::from(s >> w != 0))
|
||||
}
|
||||
B::ISubBorrow => ((x.wrapping_sub(y)) & mask(w), u64::from(x < y)),
|
||||
B::UMulExtended => {
|
||||
let pr = u128::from(x) * u128::from(y);
|
||||
(pr as u64 & mask(w), (pr >> w) as u64 & mask(w))
|
||||
|
||||
@@ -97,8 +97,6 @@ pub enum BinOp {
|
||||
FUnordGreaterThanEqual,
|
||||
/// Result: `struct { T, T }` (sum, carry).
|
||||
IAddCarry,
|
||||
/// Result: `struct { T, T }` (difference, borrow).
|
||||
ISubBorrow,
|
||||
/// Result: `struct { T, T }` (low, high).
|
||||
UMulExtended,
|
||||
/// Result: `struct { T, T }` (low, high).
|
||||
@@ -184,7 +182,6 @@ impl BinOp {
|
||||
BinOp::FOrdGreaterThanEqual => Op::FOrdGreaterThanEqual,
|
||||
BinOp::FUnordGreaterThanEqual => Op::FUnordGreaterThanEqual,
|
||||
BinOp::IAddCarry => Op::IAddCarry,
|
||||
BinOp::ISubBorrow => Op::ISubBorrow,
|
||||
BinOp::UMulExtended => Op::UMulExtended,
|
||||
BinOp::SMulExtended => Op::SMulExtended,
|
||||
BinOp::VectorTimesScalar => Op::VectorTimesScalar,
|
||||
|
||||
@@ -253,7 +253,7 @@ fn binary_operations() {
|
||||
}
|
||||
}
|
||||
for (a, b) in [(u, u), (uv, uv)] {
|
||||
for op in [IAddCarry, ISubBorrow, UMulExtended] {
|
||||
for op in [IAddCarry, UMulExtended] {
|
||||
f.binary(op, *a, *b)
|
||||
.unwrap_or_else(|e| panic!("{op:?}: {e}"));
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ use crate::pipeline::testing::{
|
||||
use crate::spirv::interp::{run, Buffer, Config, InterpError, Resources};
|
||||
use crate::spirv::ir::{GlobalKind, TypedModule};
|
||||
|
||||
/// Profiles with and without 64-bit integers and 8/16-bit storage.
|
||||
/// Profiles with and without 8/16-bit storage.
|
||||
const PROFILES: [&str; 3] = ["moltenvk-m3", "runtime-floor", "lavapipe"];
|
||||
|
||||
/// Committed profile `stem`.
|
||||
@@ -356,8 +356,8 @@ fn leaf_kernels() -> Vec<LeafKernel> {
|
||||
k("load_half5_bytes", "<5 x half>", 10, 1),
|
||||
k("load_uchar8", "<8 x i8>", 8, 8),
|
||||
// A 16-byte leaf aligned to 16 is one `uvec4` of the slot's `uvec4` view: one bitcast for
|
||||
// four 32-bit or two 64-bit lanes (two words each without `shaderInt64`), the vector's
|
||||
// words for a chunked one; aligned to 4 it moves word by word.
|
||||
// four 32-bit or two 64-bit lanes, the vector's words for a chunked one; aligned to 4 it
|
||||
// moves word by word.
|
||||
k("load_float4", "<4 x float>", 16, 16),
|
||||
k("load_long2", "<2 x i64>", 16, 16),
|
||||
k("load_half8", "<8 x half>", 16, 16),
|
||||
|
||||
@@ -38,7 +38,7 @@ use crate::pipeline::testing::{
|
||||
use crate::spirv::interp::{run, Buffer, Config, InterpError, Order, Resources, SubgroupSize};
|
||||
use crate::spirv::ir::TypedModule;
|
||||
|
||||
/// Profiles with and without 64-bit integers, 16 and 32 KiB of shared memory.
|
||||
/// Profiles with 16 and 32 KiB of shared memory.
|
||||
const PROFILES: [&str; 3] = ["moltenvk-m3", "runtime-floor", "lavapipe"];
|
||||
|
||||
const DATALAYOUT: &str = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32";
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! The arith family end to end: owned kernels go through the whole new pipeline (decode →
|
||||
//! specialize → analyze → select → emit → verify → serialize → link) on committed profiles and pass
|
||||
//! L3, and their typed modules compute the Metal/LLVM result on the CPU SPIR-V interpreter.
|
||||
//! Profiles without `shaderInt64` hold 64-bit integers as two words, a switch on one included, and
|
||||
//! profiles without `shaderFloat64` refuse `double` with the typed capability; `half` and `bfloat`
|
||||
//! are held widened on every profile.
|
||||
//! 64-bit integers, a switch on one included, are `u64`s on every profile; profiles without
|
||||
//! `shaderFloat64` refuse `double` with the typed capability; `half` and `bfloat` are held widened
|
||||
//! on every profile.
|
||||
//!
|
||||
//! Each kernel stores one word to buffer 0 (the skeleton's static-root store). Canonicalization
|
||||
//! folds integer arithmetic on constants but never float arithmetic, so each kernel makes its
|
||||
@@ -327,8 +327,7 @@ fn kernels() -> Vec<Kernel> {
|
||||
),
|
||||
13,
|
||||
));
|
||||
// Without `shaderInt64` the selector is two words; a nonzero high word matches no (32-bit) case
|
||||
// literal.
|
||||
// A selector whose high word is nonzero matches no (32-bit) case literal.
|
||||
v.push(k(
|
||||
"switch_on_an_i40",
|
||||
format!(
|
||||
@@ -385,8 +384,7 @@ fn kernels() -> Vec<Kernel> {
|
||||
needs: &[],
|
||||
note: None,
|
||||
});
|
||||
// Without `shaderInt64` 64-bit integers are two words; division is the exact word division
|
||||
// (`udivrem`), with no loop.
|
||||
// 64-bit division and remainder, signed and unsigned, of scalars and vectors.
|
||||
v.push(k(
|
||||
"i64_division_as_words",
|
||||
format!(
|
||||
@@ -420,10 +418,9 @@ fn kernels() -> Vec<Kernel> {
|
||||
),
|
||||
0x00BC_614D,
|
||||
));
|
||||
// Chunked vectors of 64-bit integers are chunks of two-word lanes without `shaderInt64`:
|
||||
// lane-wise operations per chunk, constant and `i64` dynamic lane moves, a shuffle into a
|
||||
// five-lane vector (its last chunk one lane), a lane-wise intrinsic, a word bitcast, and a
|
||||
// truncation.
|
||||
// Chunked vectors of 64-bit integers: lane-wise operations per chunk, constant and `i64` dynamic
|
||||
// lane moves, a shuffle into a five-lane vector (its last chunk one lane), a lane-wise
|
||||
// intrinsic, a word bitcast, and a truncation.
|
||||
v.push(k(
|
||||
"chunked_i64_lanes",
|
||||
format!(
|
||||
@@ -793,8 +790,8 @@ fn kernels() -> Vec<Kernel> {
|
||||
note: None,
|
||||
});
|
||||
// An 8-bit float to an integer is its value under the saturating rule (448 to `char` is 127,
|
||||
// -1.0 to `uint` is 0, 57344 and -2.0 to 64 bits, held as two words where the profile lacks
|
||||
// `shaderInt64`), and records `Fp8Value`; a widening to a float does not.
|
||||
// -1.0 to `uint` is 0, 57344 and -2.0 to 64 bits), and records `Fp8Value`; a widening to a float
|
||||
// does not.
|
||||
for (name, call, bits, wide, want) in [
|
||||
(
|
||||
"fp8_e4m3fn_to_char_saturates",
|
||||
|
||||
@@ -40,7 +40,7 @@ use crate::pipeline::testing::{
|
||||
use crate::spirv::interp::{run, Buffer, Config, InterpError, Order, Resources};
|
||||
use crate::spirv::ir::TypedModule;
|
||||
|
||||
/// Profiles with and without 64-bit integers.
|
||||
/// Profiles with and without 64-bit atomics.
|
||||
const PROFILES: [&str; 4] = [
|
||||
"moltenvk-m3",
|
||||
"runtime-floor",
|
||||
@@ -537,11 +537,6 @@ fn int64_atomics_refuse_by_the_profiles_features() {
|
||||
let Error::Unsupported(u) = e else {
|
||||
panic!("{stem} {space}: {e:?}");
|
||||
};
|
||||
// Without Int64 the `zext` is held as two words, so the refusal is the atomic's own: a
|
||||
// 64-bit atomic needs its int64-atomic feature, which such a profile lacks.
|
||||
if !prof.fields().leaf.int64 {
|
||||
assert!(!have, "{stem} {space}");
|
||||
}
|
||||
let want = if have {
|
||||
Unsupported::not_implemented(Feature::Lowering(LowerFamily::Access))
|
||||
} else {
|
||||
|
||||
@@ -28,9 +28,7 @@ const STEM: &str = "kernel_bit_manipulation";
|
||||
|
||||
/// The committed `moltenvk-m3` profile: 64-bit operands in 64-bit containers.
|
||||
fn m3() -> DeviceProfile {
|
||||
let p = profile("moltenvk-m3").expect("profile");
|
||||
assert!(p.fields().leaf.int64);
|
||||
p
|
||||
profile("moltenvk-m3").expect("profile")
|
||||
}
|
||||
|
||||
fn mask(n: u32) -> u64 {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
//! the direction the offsets require; a `volatile` `memcpy` lowers as a plain one; a dynamic
|
||||
//! `memmove` between two slots compares their Metal addresses.
|
||||
//! - `i64` lengths (Metal's `size_t`), loaded or scaled from a `uint` count, are exact on every
|
||||
//! profile, with `shaderInt64` and without it (the length is two words there); one of 2³² or more
|
||||
//! profile; one of 2³² or more
|
||||
//! counts as `u32::MAX` bytes and every access it makes at a device address is contained (the
|
||||
//! CPU interpreter's step limit stops the run; no execution bound does; a bound buffer's view is
|
||||
//! the device's robust buffer access, which the interpreter does not model). The Metal-compiled
|
||||
@@ -25,8 +25,6 @@ use std::collections::BTreeMap;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
use crate::device::profile::DeviceProfile;
|
||||
use crate::device::requirements::VkFeature;
|
||||
use crate::error::{Capability, Error, Feature, Unsupported};
|
||||
use crate::lower::select::Plan;
|
||||
use crate::pipeline::interface::PushLoc;
|
||||
use crate::pipeline::sym::{PushField, ResourceKind, ResourceSlot, SpecKey, Stage};
|
||||
@@ -590,35 +588,22 @@ declare void @llvm.memmove.p1.p1.i32(ptr addrspace(1), ptr addrspace(1), i32, i1
|
||||
|
||||
/// A dynamic `memmove` between two buffer slots (possibly one buffer bound twice, with no
|
||||
/// comparable offsets) compares the endpoints' Metal addresses (each slot's `SlotGuestBase`), never
|
||||
/// a guessed direction: it passes L3 where the profile has `shaderInt64` for those `u64` addresses
|
||||
/// and is refused naming it elsewhere (`engine_pointer_memory` executes it).
|
||||
/// a guessed direction: it passes L3 on every profile (`engine_pointer_memory` executes it).
|
||||
#[test]
|
||||
fn a_dynamic_move_between_slots_compares_metal_addresses() {
|
||||
let Some(bc) = assemble("aliased", ALIASED_MOVE) else {
|
||||
return;
|
||||
};
|
||||
for (what, prof) in profiles() {
|
||||
if prof.fields().leaf.int64 {
|
||||
l3(&bc, "aliased", &prof, &what);
|
||||
let (plan, _) = typed_module(&bc, "aliased", &prof).expect("module");
|
||||
assert!(
|
||||
plan.push
|
||||
.fields
|
||||
.iter()
|
||||
.any(|f| matches!(f.field, PushField::SlotGuestBase(_))),
|
||||
"{what}"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
let e = compile(&bc, "aliased", &prof).expect_err("refused");
|
||||
let Error::Unsupported(u) = e else {
|
||||
panic!("{what}: {e:?}");
|
||||
};
|
||||
let want = Unsupported::needs(
|
||||
Feature::PointerCompare,
|
||||
Capability::Feature(VkFeature::ShaderInt64),
|
||||
l3(&bc, "aliased", &prof, &what);
|
||||
let (plan, _) = typed_module(&bc, "aliased", &prof).expect("module");
|
||||
assert!(
|
||||
plan.push
|
||||
.fields
|
||||
.iter()
|
||||
.any(|f| matches!(f.field, PushField::SlotGuestBase(_))),
|
||||
"{what}"
|
||||
);
|
||||
assert_eq!((u.feature, u.needs), (want.feature, want.needs), "{what}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -591,7 +591,6 @@ fn an_i64_index_that_is_not_an_extension_is_a_64_bit_value() {
|
||||
};
|
||||
for stem in PROFILES {
|
||||
let p = profile_with(stem);
|
||||
assert!(p.fields().leaf.int64, "{stem}");
|
||||
let a = compile(&bc, name, &p).unwrap_or_else(|e| panic!("{name} {stem}: {e}"));
|
||||
assert!(
|
||||
!a.strategies.entries.contains_key("arith.index_extension"),
|
||||
|
||||
@@ -308,12 +308,6 @@ fn index_arithmetic_with_other_uses_or_operators_keeps_64_bits() {
|
||||
!a.strategies.entries.contains_key("arith.index_word"),
|
||||
"{name} {stem}"
|
||||
);
|
||||
let words = a
|
||||
.strategies
|
||||
.entries
|
||||
.keys()
|
||||
.any(|n| n.starts_with("arith.wide"));
|
||||
assert!(!words, "{name} {stem}");
|
||||
link_and_validate(&a, &p).unwrap_or_else(|e| panic!("{name} {stem}: L3: {e}"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,7 @@ const WORDS: usize = 32;
|
||||
|
||||
/// The committed `moltenvk-m3` profile: 64-bit operands in 64-bit containers.
|
||||
fn m3() -> DeviceProfile {
|
||||
let p = profile("moltenvk-m3").expect("profile");
|
||||
assert!(p.fields().leaf.int64);
|
||||
p
|
||||
profile("moltenvk-m3").expect("profile")
|
||||
}
|
||||
|
||||
/// splitmix64's output for `x`.
|
||||
|
||||
@@ -511,12 +511,6 @@ fn simd_kernels_compile_or_refuse_with_the_tier() {
|
||||
emulated += 1;
|
||||
}
|
||||
}
|
||||
Err(Error::Unsupported(u)) => match u.feature {
|
||||
// A value the profile cannot hold (the ballot's 64-bit result) is refused
|
||||
// while selecting, before the tier.
|
||||
Feature::Int64Arithmetic => {}
|
||||
_ => panic!("{stem} {kernel}: {u:?}"),
|
||||
},
|
||||
Err(e) => panic!("{stem} {kernel}: {e}"),
|
||||
}
|
||||
}
|
||||
@@ -978,8 +972,8 @@ fn compute_derivatives_with_a_simd_operation_are_refused() {
|
||||
|
||||
/// Metal has no simdgroup or quad function of 64-bit integers but the ballot (its `metal_simdgroup`
|
||||
/// and `metal_quadgroup` headers enable them for 8- to 32-bit integers, `half`, `float`, and
|
||||
/// `double` only), so a call of one is invalid input on every committed profile, never
|
||||
/// `Int64Arithmetic` or a subgroup capability.
|
||||
/// `double` only), so a call of one is invalid input on every committed profile, never a subgroup
|
||||
/// capability.
|
||||
#[test]
|
||||
fn sixty_four_bit_group_operations_are_not_metal() {
|
||||
let text = std::fs::read_to_string(engine_dir().join("store_const.ll")).expect("read");
|
||||
|
||||
@@ -683,8 +683,7 @@ fn a_gated_off_attribute_in_use_reads_zero() {
|
||||
|
||||
/// Metal rejects `long`/`ulong` as a vertex attribute, a varying, a stage builtin, a color output,
|
||||
/// and a color input ("type 'long' is not valid for attribute"), so a 64-bit integer there is
|
||||
/// invalid input on every committed profile, never `Int64Arithmetic` (which `shaderInt64` would not
|
||||
/// fix). Each case edits one fixture entry's value to `i64`.
|
||||
/// invalid input on every committed profile. Each case edits one fixture entry's value to `i64`.
|
||||
#[test]
|
||||
fn sixty_four_bit_interface_values_are_not_metal() {
|
||||
use crate::air::error::AbiError;
|
||||
|
||||
@@ -9628,7 +9628,6 @@ variant metal2vulkan::error::Feature::IndependentBlending IndependentBlending
|
||||
variant metal2vulkan::error::Feature::IndirectRenderState IndirectRenderState
|
||||
variant metal2vulkan::error::Feature::InlineAsm InlineAsm
|
||||
variant metal2vulkan::error::Feature::Instruction Instruction { code: u32 }
|
||||
variant metal2vulkan::error::Feature::Int64Arithmetic Int64Arithmetic
|
||||
variant metal2vulkan::error::Feature::Int64Atomics Int64Atomics
|
||||
variant metal2vulkan::error::Feature::InterfaceComponents InterfaceComponents
|
||||
variant metal2vulkan::error::Feature::IntersectionFunctionTable IntersectionFunctionTable
|
||||
@@ -9644,7 +9643,6 @@ variant metal2vulkan::error::Feature::ModuleRecord ModuleRecord { code: u32 }
|
||||
variant metal2vulkan::error::Feature::PartialThreadgroups PartialThreadgroups
|
||||
variant metal2vulkan::error::Feature::PixelCoverageAtSampleRate PixelCoverageAtSampleRate
|
||||
variant metal2vulkan::error::Feature::PixelSamplerCompare PixelSamplerCompare
|
||||
variant metal2vulkan::error::Feature::PointerCompare PointerCompare
|
||||
variant metal2vulkan::error::Feature::PostDepthCoverage PostDepthCoverage
|
||||
variant metal2vulkan::error::Feature::PrimitiveId PrimitiveId
|
||||
variant metal2vulkan::error::Feature::PrivateMemory PrivateMemory
|
||||
|
||||
|
Can't render this file because it is too large.
|
+2
-2
@@ -1151,8 +1151,8 @@ measured on the M3 Max) draws nothing: an object function's wrapper launches not
|
||||
grid.
|
||||
|
||||
An object grid runs at any count Metal runs, past the task stage's limits too, on a device with
|
||||
device addresses, `shaderInt64`, `multiDrawIndirect` and `drawIndirectCount` (every committed
|
||||
profile with the extension): the object function is compiled folded, its object stage reading the
|
||||
`multiDrawIndirect` and `drawIndirectCount` (every committed profile with the extension): the
|
||||
object function is compiled folded, its object stage reading the
|
||||
threadgroups Metal runs and its grid from a 32-byte region record at its
|
||||
`PushField::ReplayRegionAddress`, so a draw runs its grid in pieces within the task limits. Metal's
|
||||
threads per grid wrap to 32 bits along each axis, as its builtins report them. The lowering takes
|
||||
|
||||
+2
-6
@@ -26,7 +26,7 @@ Columns:
|
||||
|
||||
| Kind | Variants | With a site | Reach system | Reach app | Reach rare | Reach none | Unassessed |
|
||||
|---|---|---|---|---|---|---|---|
|
||||
| Translator and front-end refusals | 117 | 113 | 6 | 25 | 65 | 21 | 0 |
|
||||
| Translator and front-end refusals | 115 | 111 | 6 | 25 | 63 | 21 | 0 |
|
||||
| Translation caps | 14 | 14 | 0 | 0 | 7 | 7 | 0 |
|
||||
| Rate maps the compile layer does not compile | 5 | 5 | 0 | 0 | 4 | 1 | 0 |
|
||||
| The translation deadline | 1 | 1 | 0 | 0 | 0 | 1 | 0 |
|
||||
@@ -39,7 +39,7 @@ Columns:
|
||||
|
||||
| Kind | `metal-measured` | `metal-documented` | `metal-takes` | `device` | `ours` | `unknown` | `delegated` | `-` |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
| Translator and front-end refusals | 0 | 0 | 3 | 43 | 67 | 0 | 0 | 4 |
|
||||
| Translator and front-end refusals | 0 | 0 | 3 | 41 | 67 | 0 | 0 | 4 |
|
||||
| Translation caps | 0 | 0 | 0 | 0 | 14 | 0 | 0 | 0 |
|
||||
| Rate maps the compile layer does not compile | 0 | 0 | 0 | 0 | 5 | 0 | 0 | 0 |
|
||||
| The translation deadline | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
|
||||
@@ -78,7 +78,6 @@ Columns:
|
||||
| `ArgumentBufferTextures` | Argument buffers holding textures or samplers (handle domain) | devices without a capability the site computes (`gaps`); devices without a capability the site computes (`missing`); every device (not implemented) | `ours` | 12: `crates/metal2vulkan/src/bind/heap.rs (member_storage_format, 4 sites)`, `crates/metal2vulkan/src/bind/heap.rs (member_texel_view, 2 sites)` (+5) | `app`: argument buffers holding textures and samplers (bindless) |
|
||||
| `ArgumentBufferObjects` | Argument-buffer members that are pipeline states, ICBs, function tables, or acceleration structures | every device (not implemented) | `ours` | 4: `crates/metal2vulkan/src/lower/access/icb.rs (select)`, `crates/metal2vulkan/src/lower/access/object.rs (select)` (+2) | `rare`: pipeline states and ICBs in argument buffers |
|
||||
| `DereferenceLoadedPointer` | Dereferencing a pointer loaded from memory or made from an integer | every device (no Vulkan mechanism) | `device` | 2: `crates/metal2vulkan/src/lower/access/local.rs (access_ptr)`, `crates/metal2vulkan/src/lower/access/local.rs (threadgroup_constant_refusal)` | `app`: pointers loaded from argument buffers |
|
||||
| `PointerCompare` | Comparing pointers with different roots | devices without VkFeature::ShaderInt64 | `device` | via a helper: 1: `crates/metal2vulkan/src/lower/access/copy.rs (addressed)` | `rare`: comparing pointers of different roots |
|
||||
| `HandleAsPointer` | A resource handle used as a byte pointer, or conflicting handle provenance | every device (no Vulkan mechanism); every device (not implemented) | `ours` | 6: `crates/metal2vulkan/src/lower/access/handle.rs (domain_kind)`, `crates/metal2vulkan/src/lower/access/handle.rs (element, 2 sites)` (+3) | `rare`: resource handles used as byte pointers |
|
||||
| `ConstantGlobalEscaping` | A constant global whose address escapes | every device (not implemented) | `ours` | 2: `crates/metal2vulkan/src/memory/plan.rs (blob_nodes)`, `crates/metal2vulkan/src/memory/plan.rs (serialize)` | `rare`: a constant global whose address escapes |
|
||||
| `ThreadgroupMemorySize` | Threadgroup memory above the device limit | devices short of a device limit the site names; every device (no Vulkan mechanism) | `device` | 2: `crates/metal2vulkan/src/memory/arena.rs (check)`, `crates/metal2vulkan/src/memory/plan.rs (too_large)` | `rare`: threadgroup memory past a smaller device's limit |
|
||||
@@ -87,7 +86,6 @@ Columns:
|
||||
| `Int64Atomics` | 64-bit atomics | devices short of a Vulkan feature the site names | `device` | 1: `crates/metal2vulkan/src/lower/access/atomic.rs (select)` | `rare`: 64-bit atomics |
|
||||
| `ImageAtomics` | Image atomics beyond 32-bit integers | every device (not implemented) | `ours` | 1: `crates/metal2vulkan/src/lower/texture/atomic.rs (select)` | `rare`: texture atomics beyond 32-bit integers |
|
||||
| `DescriptorCount` | Too many descriptors of one kind in a stage or pipeline | devices short of a device limit the site names | `device` | 2: `crates/metal2vulkan/src/lower/select.rs (finish)`, `crates/metal2vulkan/src/pipeline/link.rs (limit_error)` | `app`: many textures or buffers in one stage on a smaller device |
|
||||
| `Int64Arithmetic` | 64-bit integer arithmetic | devices without VkFeature::ShaderInt64 | `device` | 2: `crates/metal2vulkan/src/lower/arith/legal.rs (check_scalar)`, `crates/metal2vulkan/src/lower/select.rs (selector_form)` | `rare`: 64-bit integers on a device without shaderInt64 |
|
||||
| `Float64Arithmetic` | 64-bit float arithmetic | devices without VkFeature::ShaderFloat64 | `device` | 2: `crates/metal2vulkan/src/device/metal.rs (unsupported_features)`, `crates/metal2vulkan/src/lower/arith/legal.rs (check_scalar)` | `rare`: doubles (MSL has none outside Apple's own code) |
|
||||
| `Format` | A pixel or vertex format not supported for the required use | devices without VkFeature::ShaderStorageImageExtendedFormats; devices without a capability the site computes (`alternatives`); devices without a capability the site computes (`missing`); devices without a capability the site computes (`routes`); devices without a format's usage; every device (no Vulkan mechanism); every device (not implemented) | `ours` | 47: `crates/metal2vulkan/src/lower/access/tile.rs (storage_format)`, `crates/metal2vulkan/src/lower/fragment/color.rs (select_param, 5 sites)` (+25) | `system`: pixel formats a device lacks for a use (CoreVideo's 4:2:x and 10-bit formats among them) |
|
||||
| `DivergentImplicitLod` | Divergent implicit-LOD sampling or LOD query through a multi-candidate handle | every device (not implemented) | `ours` | 1: `crates/metal2vulkan/src/lower/sampler/select.rs (tangled)` | `app`: implicit-LOD sampling through a dynamically chosen texture |
|
||||
@@ -410,7 +408,6 @@ Each refusal's sites, with the function that builds it.
|
||||
- `feature::ArgumentBufferTextures`: `crates/metal2vulkan/src/bind/heap.rs (member_storage_format, 4 sites)`; `crates/metal2vulkan/src/bind/heap.rs (member_texel_view, 2 sites)`; `crates/metal2vulkan/src/lower/access/handle.rs (select)`; `crates/metal2vulkan/src/lower/sampler/select.rs (select_one)`; `crates/metal2vulkan/src/lower/sampler/select.rs (select_sampling)`; `crates/metal2vulkan/src/lower/texture/atomic.rs (select)`; `crates/metal2vulkan/src/lower/texture/slot.rs (declare_heap, 2 sites)`
|
||||
- `feature::ArgumentBufferObjects`: `crates/metal2vulkan/src/lower/access/icb.rs (select)`; `crates/metal2vulkan/src/lower/access/object.rs (select)`; `crates/metal2vulkan/src/memory/provenance.rs (access)`; `crates/metal2vulkan/src/memory/provenance.rs (classify)`
|
||||
- `feature::DereferenceLoadedPointer`: `crates/metal2vulkan/src/lower/access/local.rs (access_ptr)`; `crates/metal2vulkan/src/lower/access/local.rs (threadgroup_constant_refusal)`
|
||||
- `feature::PointerCompare`: `crates/metal2vulkan/src/lower/access/copy.rs (addressed)`
|
||||
- `feature::HandleAsPointer`: `crates/metal2vulkan/src/lower/access/handle.rs (domain_kind)`; `crates/metal2vulkan/src/lower/access/handle.rs (element, 2 sites)`; `crates/metal2vulkan/src/memory/plan.rs (reprs)`; `crates/metal2vulkan/src/memory/provenance.rs (classify)`; `crates/metal2vulkan/src/memory/provenance.rs (seed)`
|
||||
- `feature::ConstantGlobalEscaping`: `crates/metal2vulkan/src/memory/plan.rs (blob_nodes)`; `crates/metal2vulkan/src/memory/plan.rs (serialize)`
|
||||
- `feature::ThreadgroupMemorySize`: `crates/metal2vulkan/src/memory/arena.rs (check)`; `crates/metal2vulkan/src/memory/plan.rs (too_large)`
|
||||
@@ -419,7 +416,6 @@ Each refusal's sites, with the function that builds it.
|
||||
- `feature::Int64Atomics`: `crates/metal2vulkan/src/lower/access/atomic.rs (select)`
|
||||
- `feature::ImageAtomics`: `crates/metal2vulkan/src/lower/texture/atomic.rs (select)`
|
||||
- `feature::DescriptorCount`: `crates/metal2vulkan/src/lower/select.rs (finish)`; `crates/metal2vulkan/src/pipeline/link.rs (limit_error)`
|
||||
- `feature::Int64Arithmetic`: `crates/metal2vulkan/src/lower/arith/legal.rs (check_scalar)`; `crates/metal2vulkan/src/lower/select.rs (selector_form)`
|
||||
- `feature::Float64Arithmetic`: `crates/metal2vulkan/src/device/metal.rs (unsupported_features)`; `crates/metal2vulkan/src/lower/arith/legal.rs (check_scalar)`
|
||||
- `feature::Format`: `crates/metal2vulkan/src/lower/access/tile.rs (storage_format)`; `crates/metal2vulkan/src/lower/fragment/color.rs (select_param, 5 sites)`; `crates/metal2vulkan/src/lower/sampler/select.rs (select_extended)`; `crates/metal2vulkan/src/lower/stage_io/extended_color.rs (plan, 2 sites)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (entry)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs (zeroed_output)`; `crates/metal2vulkan/src/lower/stage_io/word_color.rs (plan)`; `crates/metal2vulkan/src/lower/texture/mod.rs (select)`; `crates/metal2vulkan/src/lower/texture/mod.rs (select_image)`; `crates/metal2vulkan/src/lower/texture/mod.rs (select_read)`; `crates/metal2vulkan/src/lower/texture/slot.rs (atomic_format, 2 sites)`; `crates/metal2vulkan/src/lower/texture/slot.rs (declare_slot)`; `crates/metal2vulkan/src/lower/texture/slot.rs (storage_format, 6 sites)`; `crates/metal2vulkan/src/lower/texture/slot.rs (ulong_format, 3 sites)`; `crates/metal2vulkan/src/lower/texture/words.rs (not_built)`; `crates/metal2vulkan/src/metal/format/mod.rs (candidates)`; `crates/metal2vulkan/src/metal/format/mod.rs (held_storage_choice, 3 sites)`; `crates/metal2vulkan/src/metal/format/mod.rs (storage_choice)`; `crates/metal2vulkan/src/metal/format/mod.rs (vk_format, 2 sites)`; `crates/metal2vulkan/src/metal/vertex.rs (fetch_as, 2 sites)`; `crates/metal2vulkan/src/pipeline/color_writes.rs (rotated_blend_in_shader)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs (extended_write_mask, 2 sites)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs (graphics_state, 2 sites)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs (reads_alpha_to_coverage, 2 sites)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs (textured_fetches)`; `crates/metal2vulkan/src/pipeline/rotated_blend.rs (alpha_in_red_blend)`; `crates/metal2vulkan/src/pipeline/rotated_blend.rs (rotated_blend)`
|
||||
- `feature::DivergentImplicitLod`: `crates/metal2vulkan/src/lower/sampler/select.rs (tangled)`
|
||||
|
||||
@@ -28,7 +28,6 @@ feature SimdgroupMatrix16x16x16 rare 16x16x16 simdgroup matrix products (Metal:
|
||||
feature ArgumentBufferTextures app argument buffers holding textures and samplers (bindless)
|
||||
feature ArgumentBufferObjects rare pipeline states and ICBs in argument buffers
|
||||
feature DereferenceLoadedPointer app pointers loaded from argument buffers
|
||||
feature PointerCompare rare comparing pointers of different roots
|
||||
feature HandleAsPointer rare resource handles used as byte pointers
|
||||
feature ConstantGlobalEscaping rare a constant global whose address escapes
|
||||
feature ThreadgroupMemorySize rare threadgroup memory past a smaller device's limit
|
||||
@@ -37,7 +36,6 @@ feature CoherentMemory rare coherent(device) accesses
|
||||
feature Int64Atomics rare 64-bit atomics
|
||||
feature ImageAtomics rare texture atomics beyond 32-bit integers
|
||||
feature DescriptorCount app many textures or buffers in one stage on a smaller device
|
||||
feature Int64Arithmetic rare 64-bit integers on a device without shaderInt64
|
||||
feature Float64Arithmetic rare doubles (MSL has none outside Apple's own code)
|
||||
feature Format system pixel formats a device lacks for a use (CoreVideo's 4:2:x and 10-bit formats among them)
|
||||
feature DivergentImplicitLod app implicit-LOD sampling through a dynamically chosen texture
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 17 and column 65.
|
Reference in new issue
Block a user