SEMANTICS 2128, RUNTIME 2398: Buffer views read at their bind offset where a pushed word lengthens every thread's payload
On ANV (Mesa 26.2.6) on the Iris Xe RPL-P, a compute function that reads a client push word gets a longer per-thread payload (the base workgroup id moves 17 registers further), and a light kernel runs about 2.2 times as long: 120.2 us against 55.7 us a dispatch on the same module with the push read removed (raw Vulkan chains, jobs m3-max-34063 and m3-max-34038). The 780M (RADV) shows no such gap (m3-max-34031). The runtime's storage views read their SlotBindOffset residual on every access, so every kernel paid it there. A measured DriverWorkaround row, PushReadsLengthenThreadPayload, on that driver and GPU: - the translator declares SpecKey::RangeAtBindOffset for storage views too on that profile (access plan's storage_at_bind; the pulled vertex fetch of a shared slot folds its residual under the same key), so a key at 1 reads no push word once the driver folds it; - the binder sets a storage view's key only at bind offset 0, where the runtime tells offset 0 apart at the slot (StageTable::zero_offset_views, class ZERO_OFFSET_CLASS), and only where instantiation's range starts there (starts_at_bind), so the bytes before a bind offset stay reachable through the range from the buffer's start at every other offset; - the runtime keeps the zero-offset slots beside the uniform ones (AtBindViews), leaving out a slot once it is bound at another offset, and reads views at their bind offsets on that profile (reads_views_at_bind), the uniform views' existing form included. Every other profile declares no new key and its modules are unchanged; its stage tables leave zero_offset_views 0, so its shapes and plans are as before. Also a FAST-PATHS known gap: on the Iris Xe, kernels over exportable or host-pointer-imported memory run about 2.2x (125.53 and 122.95 us against 55.73, m3-max-33760), cause unobserved; zero copy stays. Tests: engine_access (a storage view's module at key 1 reads no SlotBindOffset, at key 0 it does, answers on the interpreter; no key on the other profiles), the binder's offset-0 rule and class, the committed profiles' form choice, and a runtime device test of a storage view at offset 0 and past it. Verified in the lane: touched tests in msi jobs 34174/34198 (engine_access, bind::, fast_paths, api_signatures, the runtime pipeline and argument_table tests); lavapipe m2v_cpu_icd 21/21 (34190: uniform_bind_offsets and the new storage test, answers at offset 0, past it and at 0 again); clippy plain 0 (34198), m2v_cpu_icd and m2v_gpu 0 (34200); rustdoc 0 (34213). golden_hashes reads stale only for intel-irisxe-rplp-anv (re-keyed: 1788 cells, fingerprint 6d95bb254f9f9d66 -> 2f820bef4bfb9669); no cell under an unchanged key moved. The table is re-blessed on development.
This commit is contained in:
1 parent
244fa02286
commit
d3b1dbdbe0
27 files changed
+704
-141
No files matched your search
@@ -54,6 +54,7 @@ use super::upload::Upload;
|
||||
use super::work_counts::{Counting, ReshapedBy};
|
||||
use ash::vk;
|
||||
use metal2vulkan::bind::{BindState, BoundBuffer, BoundSampler, BoundTexture, StageTable};
|
||||
use metal2vulkan::device::DriverWorkaround;
|
||||
use metal2vulkan::pipeline::{
|
||||
BufferKind, PipelineInterface, RenderPipeline, SlotClass, SlotInterface, SlotRef, Stage,
|
||||
};
|
||||
@@ -91,9 +92,18 @@ const VIEW_STAGES: [Stage; 5] = [
|
||||
/// bound at offsets that move takes one shape and one pipeline, its view read at its residual
|
||||
/// (exact at any offset), not a shape and a pipeline for each in turn, whose draws would each
|
||||
/// settle and switch pipelines on the encoding thread.
|
||||
///
|
||||
/// On a profile that takes `DriverWorkaround::PushReadsLengthenThreadPayload` it keeps a second
|
||||
/// set alike, the slots whose bind offset class tells offset 0 apart
|
||||
/// (`StageTable::zero_offset_views`): at first those its functions read through a storage view
|
||||
/// (`PipelineInterface::storage_view_buffers`), which a command bound at offset 0 reads at its bind
|
||||
/// offset alone; a slot a command binds at another offset is left out from then on. Elsewhere that
|
||||
/// set is empty, and every shape and plan is as without it.
|
||||
pub(crate) struct AtBindViews {
|
||||
/// Each stage's of [`VIEW_STAGES`], bit `i` for buffer index `i`.
|
||||
slots: [AtomicU64; VIEW_STAGES.len()],
|
||||
/// Each stage's of [`VIEW_STAGES`] that tell offset 0 apart, bit `i` for buffer index `i`.
|
||||
zero_slots: [AtomicU64; VIEW_STAGES.len()],
|
||||
/// The device's view base alignment (`BindState::view_base_alignment_of`).
|
||||
alignment: u32,
|
||||
/// Whether the device reads every uniform view at its residual
|
||||
@@ -109,16 +119,27 @@ impl AtBindViews {
|
||||
/// alignment of `device`: on every device, so a command's shape and its plan are the ones the
|
||||
/// translator makes of its binds there. On a device that reads every uniform view at its
|
||||
/// residual (`pipeline::reads_views_at_bind`) only the key the plan gives takes its residual
|
||||
/// form (`RenderVariant::plan`, `Variant::keyed_regions`). The state's bind state holds the
|
||||
/// slots `read` holds.
|
||||
/// form (`RenderVariant::plan`, `Variant::keyed_regions`). The slots it reads through a
|
||||
/// storage view tell offset 0 apart where the profile of `device` takes
|
||||
/// `DriverWorkaround::PushReadsLengthenThreadPayload`, the one profile whose modules declare
|
||||
/// their key (`lower::access`); none elsewhere. The state's bind state holds the slots `read`
|
||||
/// holds.
|
||||
pub(crate) fn new(
|
||||
device: &Device,
|
||||
interface: &PipelineInterface,
|
||||
read: ReadSlots,
|
||||
) -> AtBindViews {
|
||||
let limits = device.compile_device().profile().limits();
|
||||
let profile = device.compile_device().profile();
|
||||
let limits = profile.limits();
|
||||
let storage_at_bind =
|
||||
(profile.workarounds()).contains(&DriverWorkaround::PushReadsLengthenThreadPayload);
|
||||
let storage = |stage| match storage_at_bind {
|
||||
true => interface.storage_view_buffers(stage),
|
||||
false => 0,
|
||||
};
|
||||
AtBindViews {
|
||||
slots: VIEW_STAGES.map(|stage| AtomicU64::new(interface.uniform_view_buffers(stage))),
|
||||
zero_slots: VIEW_STAGES.map(|stage| AtomicU64::new(storage(stage))),
|
||||
alignment: BindState::view_base_alignment_of(limits),
|
||||
at_residual: !crate::pipeline::reads_views_at_bind(device),
|
||||
read,
|
||||
@@ -146,13 +167,14 @@ impl AtBindViews {
|
||||
self.at_residual
|
||||
}
|
||||
|
||||
/// Whether `stage`'s slots are `slots` (none for a stage it does not keep): a table read under
|
||||
/// them that binds the same offsets leaves the same out ([`ArgumentTable::at_bind_views`]),
|
||||
/// as it left out its own as it was read.
|
||||
pub(super) fn holds(&self, stage: Stage, slots: u64) -> bool {
|
||||
self.of(stage)
|
||||
.map_or(0, |kept| kept.load(Ordering::Relaxed))
|
||||
== slots
|
||||
/// Whether `stage`'s slots of both sets are those `table` holds (none for a stage it does not
|
||||
/// keep): a table read under them that binds the same offsets leaves the same out
|
||||
/// ([`ArgumentTable::at_bind_views`], [`ArgumentTable::zero_offset_views`]), as it left out
|
||||
/// its own as it was read.
|
||||
pub(super) fn holds(&self, stage: Stage, table: &StageTable) -> bool {
|
||||
let now = |slots: Option<&AtomicU64>| slots.map_or(0, |s| s.load(Ordering::Relaxed));
|
||||
now(self.of(stage)) == table.at_bind_views
|
||||
&& now(self.zero_of(stage)) == table.zero_offset_views
|
||||
}
|
||||
|
||||
/// `stage`'s slots, none for a stage it does not keep.
|
||||
@@ -160,6 +182,12 @@ impl AtBindViews {
|
||||
let at = VIEW_STAGES.iter().position(|s| *s == stage)?;
|
||||
Some(&self.slots[at])
|
||||
}
|
||||
|
||||
/// `stage`'s slots that tell offset 0 apart, none for a stage it does not keep.
|
||||
fn zero_of(&self, stage: Stage) -> Option<&AtomicU64> {
|
||||
let at = VIEW_STAGES.iter().position(|s| *s == stage)?;
|
||||
Some(&self.zero_slots[at])
|
||||
}
|
||||
}
|
||||
|
||||
/// The render stages whose slots [`ReadSlots`] tells apart, in its order.
|
||||
@@ -1482,7 +1510,8 @@ impl ArgumentTable {
|
||||
/// stops the command (an M3 Max and an M4), and so is a table bound where it reads a buffer,
|
||||
/// whose slot then reads zeros, as plain Metal's read (an M4). Its slots that tell the device's
|
||||
/// view base alignment apart are those of `views`, the state's, as
|
||||
/// [`at_bind_views`](Self::at_bind_views) leaves them.
|
||||
/// [`at_bind_views`](Self::at_bind_views) leaves them, and its slots that tell offset 0 apart
|
||||
/// as [`zero_offset_views`](Self::zero_offset_views) leaves them.
|
||||
pub(super) fn stage_table_reading(
|
||||
&self,
|
||||
stage: Stage,
|
||||
@@ -1491,6 +1520,7 @@ impl ArgumentTable {
|
||||
) -> StageTable {
|
||||
let mut table = self.stage_table();
|
||||
table.at_bind_views = self.at_bind_views(stage, views);
|
||||
table.zero_offset_views = self.zero_offset_views(stage, views);
|
||||
let read = |class, index| views.read.reads(stage, class, index);
|
||||
table
|
||||
.buffers
|
||||
@@ -1509,21 +1539,35 @@ impl ArgumentTable {
|
||||
/// each that binds a buffer here at an offset the alignment does not divide left out, now and
|
||||
/// from then on ([`AtBindViews`]). Inline bytes leave none out.
|
||||
fn at_bind_views(&self, stage: Stage, views: &AtBindViews) -> u64 {
|
||||
let Some(kept) = views.of(stage) else {
|
||||
let alignment = u64::from(views.alignment);
|
||||
self.views_left(views.of(stage), |offset| {
|
||||
alignment != 0 && !offset.is_multiple_of(alignment)
|
||||
})
|
||||
}
|
||||
|
||||
/// The slots of `stage` whose bind offset class tells offset 0 apart for a command binding
|
||||
/// this table (`StageTable::zero_offset_views`): the state's `views` of it, each that binds a
|
||||
/// buffer here at an offset other than 0 left out, now and from then on ([`AtBindViews`]).
|
||||
/// Inline bytes leave none out.
|
||||
fn zero_offset_views(&self, stage: Stage, views: &AtBindViews) -> u64 {
|
||||
self.views_left(views.zero_of(stage), |offset| offset != 0)
|
||||
}
|
||||
|
||||
/// The slots `kept` holds (none where it is `None`), each that binds a buffer here at an
|
||||
/// offset `moved` holds of left out, in `kept` too.
|
||||
fn views_left(&self, kept: Option<&AtomicU64>, moved: impl Fn(u64) -> bool) -> u64 {
|
||||
let Some(kept) = kept else {
|
||||
return 0;
|
||||
};
|
||||
let alignment = views.alignment;
|
||||
let viewed = kept.load(Ordering::Relaxed);
|
||||
let mut slots = viewed;
|
||||
let mut left = viewed;
|
||||
while left != 0 {
|
||||
let index = left.trailing_zeros();
|
||||
left &= left - 1;
|
||||
let moved = alignment != 0
|
||||
&& !self.bytes.contains_key(&index)
|
||||
&& (self.buffers.get(&index))
|
||||
.is_some_and(|(_, offset)| !offset.is_multiple_of(u64::from(alignment)));
|
||||
if moved {
|
||||
let out = !self.bytes.contains_key(&index)
|
||||
&& (self.buffers.get(&index)).is_some_and(|(_, offset)| moved(*offset));
|
||||
if out {
|
||||
slots &= !(1 << index);
|
||||
}
|
||||
}
|
||||
@@ -1569,9 +1613,13 @@ impl ArgumentTable {
|
||||
reshape: &mut Reshape,
|
||||
) {
|
||||
let read = (stage, interface);
|
||||
// The slots that tell the view base alignment apart first, which the buffers' shapes
|
||||
// read.
|
||||
// The slots that tell the view base alignment and offset 0 apart first, which the
|
||||
// buffers' shapes read.
|
||||
reshape.field(&mut kept.at_bind_views, self.at_bind_views(stage, views));
|
||||
reshape.field(
|
||||
&mut kept.zero_offset_views,
|
||||
self.zero_offset_views(stage, views),
|
||||
);
|
||||
let alignment = views.alignment;
|
||||
// The slots the state holds alone (`ReadSlots`).
|
||||
let held = |class, index| views.read.reads(stage, class, index);
|
||||
@@ -1692,7 +1740,9 @@ impl ArgumentTable {
|
||||
return false;
|
||||
};
|
||||
// A buffer's shape reads these slots: where they changed, every buffer is read again.
|
||||
if self.at_bind_views(stage, views) != kept.at_bind_views {
|
||||
if self.at_bind_views(stage, views) != kept.at_bind_views
|
||||
|| self.zero_offset_views(stage, views) != kept.zero_offset_views
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let alignment = views.alignment;
|
||||
@@ -1880,34 +1930,48 @@ impl ArgumentTable {
|
||||
) {
|
||||
let (stage, _) = read;
|
||||
const DIFFERS: &str = "a stage table brought in place that is not the table read whole";
|
||||
// The slots that tell the view base alignment apart, which the buffers' shapes read: each
|
||||
// binds no buffer here at an offset the alignment does not divide, and they hold every slot
|
||||
// the state's views hold now. A slot leaves those for good, and another encoder of the
|
||||
// state may leave one out after this table read them, so `kept` may hold more than a
|
||||
// table read whole now would, never fewer.
|
||||
let now = views
|
||||
.of(stage)
|
||||
.map_or(0, |slots| slots.load(Ordering::Relaxed));
|
||||
assert!(
|
||||
now & !kept.at_bind_views == 0,
|
||||
"{DIFFERS}: {stage:?} tells the view base alignment apart at {:#x}, the state's views \
|
||||
at {now:#x}",
|
||||
kept.at_bind_views
|
||||
);
|
||||
let mut told = kept.at_bind_views;
|
||||
while told != 0 {
|
||||
let index = told.trailing_zeros();
|
||||
told &= told - 1;
|
||||
let moved = !self.bytes.contains_key(&index)
|
||||
&& (self.buffers.get(&index)).is_some_and(|(_, offset)| {
|
||||
views.alignment != 0 && !offset.is_multiple_of(u64::from(views.alignment))
|
||||
});
|
||||
// The slots that tell the view base alignment apart, and those that tell offset 0 apart,
|
||||
// which the buffers' shapes read: each binds no buffer here at an offset the alignment
|
||||
// does not divide, or other than 0, and they hold every slot the state's views hold now. A
|
||||
// slot leaves those for good, and another encoder of the state may leave one out after
|
||||
// this table read them, so `kept` may hold more than a table read whole now would, never
|
||||
// fewer.
|
||||
let alignment = u64::from(views.alignment);
|
||||
let off_alignment = |offset: u64| alignment != 0 && !offset.is_multiple_of(alignment);
|
||||
let off_zero = |offset: u64| offset != 0;
|
||||
let sets: [(&str, u64, Option<&AtomicU64>, &dyn Fn(u64) -> bool); 2] = [
|
||||
(
|
||||
"the view base alignment",
|
||||
kept.at_bind_views,
|
||||
views.of(stage),
|
||||
&off_alignment,
|
||||
),
|
||||
(
|
||||
"offset 0",
|
||||
kept.zero_offset_views,
|
||||
views.zero_of(stage),
|
||||
&off_zero,
|
||||
),
|
||||
];
|
||||
for (what, told, slots, moved) in sets {
|
||||
let now = slots.map_or(0, |slots| slots.load(Ordering::Relaxed));
|
||||
assert!(
|
||||
!moved,
|
||||
"{DIFFERS}: {stage:?} buffer {index} tells the view base alignment {} apart at an \
|
||||
offset it does not divide",
|
||||
views.alignment
|
||||
now & !told == 0,
|
||||
"{DIFFERS}: {stage:?} tells {what} apart at {told:#x}, the state's views at \
|
||||
{now:#x}"
|
||||
);
|
||||
let mut left = told;
|
||||
while left != 0 {
|
||||
let index = left.trailing_zeros();
|
||||
left &= left - 1;
|
||||
let out = !self.bytes.contains_key(&index)
|
||||
&& (self.buffers.get(&index)).is_some_and(|(_, offset)| moved(*offset));
|
||||
assert!(
|
||||
!out,
|
||||
"{DIFFERS}: {stage:?} buffer {index} tells {what} apart at an offset that \
|
||||
leaves it out (view base alignment {alignment})"
|
||||
);
|
||||
}
|
||||
}
|
||||
// A buffer slot as `stage_table_reading` reads it: inline bytes where they are bound,
|
||||
// else the buffer within its length, and nothing where the function reads it unbound.
|
||||
|
||||
@@ -211,7 +211,7 @@ impl LiveDispatch {
|
||||
let kept = state.stages.entry(Stage::Kernel).or_default();
|
||||
// Its slots that tell the view base alignment apart are as the state holds them
|
||||
// (`AtBindViews::holds`): another table's offsets may have left some out since.
|
||||
let views_held = views.holds(Stage::Kernel, kept.at_bind_views);
|
||||
let views_held = views.holds(Stage::Kernel, kept);
|
||||
let read_under = self.read_from.table.filter(|_| same && views_held);
|
||||
if read_under == Some(table.stamp()) {
|
||||
#[cfg(debug_assertions)]
|
||||
|
||||
@@ -37,13 +37,17 @@
|
||||
//! (`Variant::begin_region_pipeline`).
|
||||
//! - **One form where the bind offset buys nothing** ([`reads_views_at_bind`]). Where the driver
|
||||
//! is not measured to load a uniform read at a constant offset ahead of the shader
|
||||
//! (`DriverFact::ConstantOffsetUniformReadsPreloaded`, which no driver carries today) every
|
||||
//! key is its residual form, because the other form costs each state a second `VkPipeline` at
|
||||
//! its first draw and buys nothing measurable: on MoltenVK a uniform view is a Metal constant
|
||||
//! buffer reached through an argument buffer and the two forms were measured alike, and on
|
||||
//! llvmpipe, RADV and NVIDIA the second form was counted and then timed no faster (the fact's
|
||||
//! own documentation holds the figures). The plans' specializations and the dispatches'
|
||||
//! regions take the residual form before any key is looked up (`RenderVariant::plan`,
|
||||
//! (`DriverFact::ConstantOffsetUniformReadsPreloaded`, which no driver carries today), nor to
|
||||
//! run a function that reads a pushed word slower
|
||||
//! (`DriverWorkaround::PushReadsLengthenThreadPayload`, ANV on one Iris Xe), every key is its
|
||||
//! residual form, because the other form costs each state a second `VkPipeline` at its first
|
||||
//! draw and buys nothing measurable: on MoltenVK a uniform view is a Metal constant buffer
|
||||
//! reached through an argument buffer and the two forms were measured alike, and on llvmpipe,
|
||||
//! RADV and NVIDIA the second form was counted and then timed no faster (the fact's own
|
||||
//! documentation holds the figures). On the workaround's profile a storage view declares the
|
||||
//! key too, which a bind at offset 0 sets (`bind::ZERO_OFFSET_CLASS`), so a key whose views all
|
||||
//! read at their bind offsets reads no residual word. The plans' specializations and the
|
||||
//! dispatches' regions take the residual form before any key is looked up (`RenderVariant::plan`,
|
||||
//! `Variant::keyed_regions`): a state's creation makes the one pipeline its draws at every bind
|
||||
//! offset take. The shapes and plans stay every device's (`argument_table::AtBindViews`): a bind
|
||||
//! offset the view base alignment divides still makes a shape and a plan of its own, whose key
|
||||
@@ -102,7 +106,7 @@ use crate::pipeline::making::Begun;
|
||||
use crate::pipeline::objects::RawPipeline;
|
||||
use crate::render_target::RenderPassObject;
|
||||
use metal2vulkan::cache::SpecializationKey;
|
||||
use metal2vulkan::device::DriverFact;
|
||||
use metal2vulkan::device::{DriverFact, DriverWorkaround};
|
||||
use metal2vulkan::pipeline::{SpecConstant, SpecKey};
|
||||
use std::collections::BTreeSet;
|
||||
use std::sync::Arc;
|
||||
@@ -258,18 +262,26 @@ fn zeroed(
|
||||
/// (the module docs); where not, every key is its residual form, and a state's pipelines are the
|
||||
/// residual form's alone.
|
||||
///
|
||||
/// The question is the driver's, and it is the driver fact that answers it, never the driver's
|
||||
/// name: a driver that loads a uniform read at a constant offset ahead of the shader
|
||||
/// ([`DriverFact::ConstantOffsetUniformReadsPreloaded`]) is one where the second form earns the
|
||||
/// second pipeline. No driver is measured with the fact, so every device reads its views at their
|
||||
/// residuals today; the fact's own documentation holds what was measured where, and a driver
|
||||
/// measured with it takes the other form with no change here.
|
||||
/// The question is the driver's, and it is the driver's measured rows that answer it, never the
|
||||
/// driver's name: a driver that loads a uniform read at a constant offset ahead of the shader
|
||||
/// ([`DriverFact::ConstantOffsetUniformReadsPreloaded`]), or one that runs a function reading a
|
||||
/// pushed word slower ([`DriverWorkaround::PushReadsLengthenThreadPayload`], whose profile's
|
||||
/// storage views declare the key too), is one where the second form earns the second pipeline.
|
||||
/// No driver is measured with the fact, and only ANV on one Iris Xe with the workaround; the
|
||||
/// rows' own documentation holds what was measured where, and a driver measured with either takes
|
||||
/// the other form with no change here.
|
||||
pub(crate) fn reads_views_at_bind(device: &crate::Device) -> bool {
|
||||
views_read_at_bind(&device.properties().driver_facts)
|
||||
let workarounds = device.compile_device().profile().workarounds();
|
||||
views_read_at_bind(&device.properties().driver_facts, workarounds)
|
||||
}
|
||||
|
||||
/// [`reads_views_at_bind`] of a device's driver facts alone, which a test can hand the facts of
|
||||
/// each committed profile: the fact, and nothing of the driver's identity.
|
||||
pub(crate) fn views_read_at_bind(facts: &BTreeSet<DriverFact>) -> bool {
|
||||
/// [`reads_views_at_bind`] of a device's driver facts and its profile's workarounds alone, which
|
||||
/// a test can hand those of each committed profile: the rows, and nothing of the driver's
|
||||
/// identity.
|
||||
pub(crate) fn views_read_at_bind(
|
||||
facts: &BTreeSet<DriverFact>,
|
||||
workarounds: &[DriverWorkaround],
|
||||
) -> bool {
|
||||
facts.contains(&DriverFact::ConstantOffsetUniformReadsPreloaded)
|
||||
|| workarounds.contains(&DriverWorkaround::PushReadsLengthenThreadPayload)
|
||||
}
|
||||
@@ -6945,7 +6945,7 @@ impl RenderLowering {
|
||||
let kept = state.stages.entry(stage).or_default();
|
||||
// Its slots that tell the view base alignment apart are as the state holds them
|
||||
// (`AtBindViews::holds`): another table's offsets may have left some out since.
|
||||
let views_held = views.holds(stage, kept.at_bind_views);
|
||||
let views_held = views.holds(stage, kept);
|
||||
if same && views_held && live.read_from.unchanged(at, table.stamp()) {
|
||||
#[cfg(debug_assertions)]
|
||||
table.check_reading(kept, (stage, interface), (maps, views));
|
||||
|
||||
@@ -822,7 +822,7 @@ impl RenderLowering {
|
||||
}
|
||||
let state = live.state.stages.get(&stage);
|
||||
let read = carried || live.read_from.read_under(at) == Some(under);
|
||||
if !read || !state.is_some_and(|state| views.holds(stage, state.at_bind_views)) {
|
||||
if !read || !state.is_some_and(|state| views.holds(stage, state)) {
|
||||
return Err(ArgumentsStop::Unread);
|
||||
}
|
||||
let since = table.changed_since(under).ok_or(ArgumentsStop::Unlisted)?;
|
||||
|
||||
@@ -154,7 +154,8 @@ fn the_check_compares_every_field() {
|
||||
"samplers",
|
||||
"threadgroup_lengths",
|
||||
"acceleration_structures",
|
||||
"at_bind_views"
|
||||
"at_bind_views",
|
||||
"zero_offset_views"
|
||||
]
|
||||
);
|
||||
let sampler = BoundSampler::new(SamplerDescriptor::new());
|
||||
|
||||
@@ -18,7 +18,7 @@ use super::super::pipeline::{
|
||||
};
|
||||
use super::super::values::Size;
|
||||
use metal2vulkan::cache::SpecializationKey;
|
||||
use metal2vulkan::device::{DeviceDescription, DriverFact};
|
||||
use metal2vulkan::device::{DriverFact, DriverWorkaround};
|
||||
use metal2vulkan::library::{FunctionConstantValue, FunctionConstantValues, Library};
|
||||
use metal2vulkan::metal::DataType;
|
||||
use metal2vulkan::pipeline::{LinkedFunction, LinkedFunctions, SpecKey};
|
||||
@@ -215,49 +215,40 @@ fn a_pipelines_constants_take_the_keys_values_else_their_defaults() {
|
||||
assert!(specialization_values(std::iter::empty(), &key).is_empty());
|
||||
}
|
||||
|
||||
/// Which `VkPipeline` a state's draws take is the driver's **fact**, never its name
|
||||
/// Which `VkPipeline` a state's draws take is the driver's measured rows, never its name
|
||||
/// (`pipeline/render/residual.rs`): a driver measured to load a uniform read at a constant offset
|
||||
/// ahead of the shader (`DriverFact::ConstantOffsetUniformReadsPreloaded`) reads a view at its
|
||||
/// bind offset alone, a second pipeline per state; every other driver reads every view at its
|
||||
/// residual, the one pipeline its creation made.
|
||||
/// ahead of the shader (`DriverFact::ConstantOffsetUniformReadsPreloaded`), or to run a function
|
||||
/// that reads a pushed word slower (`DriverWorkaround::PushReadsLengthenThreadPayload`), reads a
|
||||
/// view at its bind offset alone, a second pipeline per state; every other driver reads every view
|
||||
/// at its residual, the one pipeline its creation made.
|
||||
///
|
||||
/// No committed profile carries the fact, so each of them -- MoltenVK's, RADV's, ANV's, NVIDIA's,
|
||||
/// lavapipe's and SwiftShader's alike -- takes the residual form. That is the check: a decision
|
||||
/// that told one driver apart would answer otherwise for its profile than for the rest, and a
|
||||
/// `MEASURED` row written without a measurement would show here as a profile that reads at its
|
||||
/// bind offset.
|
||||
/// No committed profile carries the fact, and only the Iris Xe RPL-P's under ANV
|
||||
/// (`intel-irisxe-rplp-anv`, the device the workaround was measured on) takes the workaround, so
|
||||
/// it alone reads at its bind offsets, and every other -- MoltenVK's, RADV's, the other ANV
|
||||
/// profiles', NVIDIA's, lavapipe's and SwiftShader's alike -- takes the residual form. That is the
|
||||
/// check: a decision that told one driver apart by anything but its rows would answer otherwise
|
||||
/// for some profile, and a `MEASURED` row written without a measurement would show here as another
|
||||
/// profile that reads at its bind offset.
|
||||
#[test]
|
||||
fn every_committed_driver_reads_its_uniform_views_at_their_residuals() {
|
||||
let dir = metal2vulkan_devtools::validation_dir().join("profiles");
|
||||
let mut read = 0;
|
||||
for entry in std::fs::read_dir(&dir).expect("validation/profiles is readable") {
|
||||
let path = entry.expect("directory entry").path();
|
||||
if path.extension().is_none_or(|x| x != "json") {
|
||||
continue;
|
||||
}
|
||||
let text = std::fs::read_to_string(&path).expect("profile is readable");
|
||||
let description =
|
||||
DeviceDescription::from_khronos_json(&text, None).expect("profile parses");
|
||||
fn only_the_measured_driver_reads_its_views_at_their_bind_offsets() {
|
||||
let mut at_bind = Vec::new();
|
||||
for (stem, description, device) in super::image_plan::committed() {
|
||||
let facts = description.driver_facts();
|
||||
assert!(
|
||||
!facts.contains(&DriverFact::ConstantOffsetUniformReadsPreloaded),
|
||||
"{} is measured with a fact no measurement took",
|
||||
path.display()
|
||||
"{stem} is measured with a fact no measurement took"
|
||||
);
|
||||
assert!(
|
||||
!views_read_at_bind(&facts),
|
||||
"{} reads a uniform view at its bind offset alone",
|
||||
path.display()
|
||||
);
|
||||
read += 1;
|
||||
if views_read_at_bind(&facts, device.profile().workarounds()) {
|
||||
at_bind.push(stem);
|
||||
}
|
||||
}
|
||||
assert!(read > 1, "profiles read: {read}");
|
||||
// The other form is kept and reachable: the fact alone chooses it.
|
||||
assert!(views_read_at_bind(
|
||||
&[DriverFact::ConstantOffsetUniformReadsPreloaded]
|
||||
.into_iter()
|
||||
.collect()
|
||||
));
|
||||
assert_eq!(at_bind, ["intel-irisxe-rplp-anv"]);
|
||||
// The other form is kept and reachable: either row alone chooses it.
|
||||
let fact = [DriverFact::ConstantOffsetUniformReadsPreloaded];
|
||||
assert!(views_read_at_bind(&fact.into_iter().collect(), &[]));
|
||||
let workaround = [DriverWorkaround::PushReadsLengthenThreadPayload];
|
||||
assert!(views_read_at_bind(&Default::default(), &workaround));
|
||||
assert!(!views_read_at_bind(&Default::default(), &[]));
|
||||
}
|
||||
|
||||
/// A compute or tile state whose descriptor requires a threadgroup size answers that size's
|
||||
|
||||
@@ -10,13 +10,16 @@
|
||||
//! is made on the device's pool (`pipeline/render/residual.rs`); a compute state's creation makes
|
||||
//! its predicted region's, which a dispatch takes alike (`pipeline/dispatch_making.rs`). A device
|
||||
//! whose driver is not measured to load a uniform read at a constant offset ahead of the shader
|
||||
//! (`DriverFact::ConstantOffsetUniformReadsPreloaded`, which no driver carries today) makes no
|
||||
//! other form.
|
||||
//! (`DriverFact::ConstantOffsetUniformReadsPreloaded`, which no driver carries today), nor to run
|
||||
//! a function that reads a pushed word slower (`DriverWorkaround::PushReadsLengthenThreadPayload`,
|
||||
//! ANV on one Iris Xe), makes no other form. On the workaround's device a kernel's storage view
|
||||
//! bound at offset 0 reads at its bind offset alone too, until a command binds it elsewhere.
|
||||
//!
|
||||
//! A device test: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`,
|
||||
//! `m2v_cpu_icd`), on the kind of device the cfg selects. The functions are those of the owned
|
||||
//! fixture `validation/fixtures/public/engine/ubo_bind_offsets.ll` (`llvm-as`), and, for draws
|
||||
//! moved along a buffer, of `cof_offsets.ll` beside it.
|
||||
//! fixture `validation/fixtures/public/engine/ubo_bind_offsets.ll` (`llvm-as`), for draws moved
|
||||
//! along a buffer of `cof_offsets.ll` beside it, and for a storage view of
|
||||
//! `buffer_end_byte_load.ll`.
|
||||
|
||||
use super::blit_holds::{device, Scratch, WAIT};
|
||||
use crate::{
|
||||
@@ -922,3 +925,71 @@ fn kernel_constants_read_at_every_bind_offset() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A kernel reads a `device` buffer through a storage view at bind offset 0, then at offsets past
|
||||
/// it and at 0 again (`engine/buffer_end_byte_load.ll`: `out[0] = in[5]`), and each dispatch reads
|
||||
/// the bound bytes, whichever form its key takes. On a device whose profile takes
|
||||
/// `DriverWorkaround::PushReadsLengthenThreadPayload` the storage views declare
|
||||
/// `SpecKey::RangeAtBindOffset`: the first dispatch's key reads both slots at their bind offsets,
|
||||
/// a pipeline beside the creation's residual form, and a bind of the source at another offset
|
||||
/// leaves its slot out from then on (`argument_table::AtBindViews`), so every later dispatch, at
|
||||
/// offset 0 too, reads it at its residual beside the output's at its bind offset, one pipeline
|
||||
/// more. On every other device the key is not declared, and every dispatch takes the creation's
|
||||
/// pipeline: none is made.
|
||||
#[test]
|
||||
fn a_storage_view_reads_its_bytes_at_bind_offset_0_and_past_it() {
|
||||
use metal2vulkan::device::DriverWorkaround;
|
||||
let scratch = Scratch::new("storage-bind-offsets");
|
||||
let device = device(&scratch.0);
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
let ll = metal2vulkan_devtools::engine_dir().join("buffer_end_byte_load.ll");
|
||||
let bitcode = metal2vulkan_devtools::llvm_assemble(&ll).unwrap();
|
||||
let library = metal2vulkan::library::Library::from_air(&bitcode).unwrap();
|
||||
let function = (device.new_library_with_compile_library(library))
|
||||
.new_function_with_name("buffer_end_byte_load")
|
||||
.unwrap();
|
||||
let state = kernel_state(&device, &function);
|
||||
let row = (device.compile_device().profile().workarounds())
|
||||
.contains(&DriverWorkaround::PushReadsLengthenThreadPayload);
|
||||
let data: Vec<u8> = (0..=255).collect();
|
||||
let source = device
|
||||
.new_buffer_with_bytes(&data, ResourceOptions::shared())
|
||||
.unwrap();
|
||||
let [width, height, depth] = PREDICTED_THREADS;
|
||||
let threads = Size::new(u64::from(width), u64::from(height), u64::from(depth));
|
||||
let dispatch = |offsets: &[u64]| -> Vec<u8> {
|
||||
let outputs: Vec<Buffer> = offsets
|
||||
.iter()
|
||||
.map(|_| device.new_buffer(16, ResourceOptions::shared()).unwrap())
|
||||
.collect();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
let mut encoder = command_buffer.compute_command_encoder().unwrap();
|
||||
encoder.set_compute_pipeline_state(&state).unwrap();
|
||||
for (at, output) in offsets.iter().zip(&outputs) {
|
||||
encoder.set_buffer(Some(&source), *at, 0).unwrap();
|
||||
encoder.set_buffer(Some(output), 0, 1).unwrap();
|
||||
encoder
|
||||
.dispatch_threadgroups(Size::new(1, 1, 1), threads)
|
||||
.unwrap();
|
||||
}
|
||||
encoder.end_encoding().unwrap();
|
||||
command_buffer.commit().unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(command_buffer.error(), None);
|
||||
outputs.iter().map(|o| bytes_of(o)[0]).collect()
|
||||
};
|
||||
let made = || idle(&device).variant_pipelines_made;
|
||||
let start = made();
|
||||
assert_eq!(dispatch(&[0]), [5], "the source at offset 0");
|
||||
assert_eq!(made() - start, u64::from(row), "pipelines made at offset 0");
|
||||
assert_eq!(
|
||||
dispatch(&[64, 4, 0, 128]),
|
||||
[69, 9, 5, 133],
|
||||
"the source at offsets past 0, and at 0 again"
|
||||
);
|
||||
assert_eq!(
|
||||
made() - start,
|
||||
2 * u64::from(row),
|
||||
"pipelines made once the source moved"
|
||||
);
|
||||
}
|
||||
@@ -397,6 +397,19 @@ fn fixed_function_fetches_only_what_vulkan_can_bind() {
|
||||
offsets.map(|o| offset_alignment(o, 64)),
|
||||
[64, 1, 2, 1, 4, 2, 4, 4, 64, 64, 64, 2]
|
||||
);
|
||||
// Where offset 0 is told apart, it alone takes its class, which the vertex fetch reads as any
|
||||
// aligned offset's; every other offset classes as where nothing is told apart.
|
||||
use crate::bind::{ZERO_OFFSET_CLASS, ZERO_OFFSET_TOLD};
|
||||
assert_eq!(
|
||||
offsets.map(|o| offset_alignment(o, ZERO_OFFSET_TOLD)),
|
||||
[ZERO_OFFSET_CLASS, 1, 2, 1, 4, 2, 4, 4, 4, 4, 4, 2]
|
||||
);
|
||||
assert!(fetchable(
|
||||
&first,
|
||||
&rules(None, true),
|
||||
ZERO_OFFSET_CLASS,
|
||||
None
|
||||
));
|
||||
}
|
||||
|
||||
/// An attribute's alignment is its component size (the whole word of a packed format) and the
|
||||
|
||||
@@ -611,9 +611,11 @@ pub(crate) fn shared_range(
|
||||
/// the window does not state, are reachable as Metal's own memory is. Where that range would
|
||||
/// exceed the view's `max_range` or reach past `2^32` (a `u32` residual and offset), or the bind
|
||||
/// offset lies at or past the padded end, it takes [`descriptor_range`]'s range;
|
||||
/// - a storage view of a `Bounded` window, which every function reads at its residual, and a
|
||||
/// uniform view of one where `views_at_residual` (no function reads it at its bind offset
|
||||
/// alone, `SpecKey::RangeAtBindOffset`), take [`shared_range`]'s, where it holds the window;
|
||||
/// - a storage view of a `Bounded` window, which a function reads at its residual but at bind
|
||||
/// offset 0 (`SpecKey::RangeAtBindOffset`, where its profile declares the key, set only where
|
||||
/// [`starts_at_bind`] holds there, which leaves that range's residual 0), and a uniform view of
|
||||
/// one where `views_at_residual` (no function reads it at its bind offset alone), take
|
||||
/// [`shared_range`]'s, where it holds the window;
|
||||
/// - every other slot takes [`descriptor_range`]'s, which starts at the bind offset aligned down
|
||||
/// to the descriptor base alignment: a uniform view's key may read it at its bind offset alone,
|
||||
/// where its residual is 0.
|
||||
|
||||
@@ -309,7 +309,7 @@ pub use state::{
|
||||
ImageblockSize, ResourceClass, SamplerDescriptor, SamplerShape, StageInRegion, StageShape,
|
||||
StageTable, TessellationFactorBuffer, TessellationFactors, TextureFacts, TextureShape,
|
||||
TileThreadgroupArgument, TileThreadgroupMemory, UsedClass, UsedResource, UsedShape,
|
||||
VertexAmplification, ViewMapping,
|
||||
VertexAmplification, ViewMapping, ZERO_OFFSET_CLASS, ZERO_OFFSET_TOLD,
|
||||
};
|
||||
// How `BindState::shape` classes a buffer: the crate reads it from `state`, and a consumer takes
|
||||
// shapes from `BindState::shape`; only the crate's tests and validation reach it here.
|
||||
|
||||
@@ -169,14 +169,19 @@ pub(crate) fn plan_buffer(
|
||||
/// The `SpecKey::RangeAtBindOffset` of buffer slot `b`, bound as `shape` states: whether the
|
||||
/// descriptor range starts at its bind offset (`instantiate::starts_at_bind`, under the view's
|
||||
/// descriptor base alignment, as [`plan_buffer`] takes it): inline bytes, at offset 0 of the
|
||||
/// consumer's aligned upload; a buffer, at an offset whose alignment class
|
||||
/// (`BufferShape::Buffer::offset_alignment`: `BindState::view_base_alignment` where the runtime
|
||||
/// tells it apart at the slot and it divides the offset, else a power of two up to 4) the base
|
||||
/// alignment divides. A slot bound to nothing takes false, the form that reads at the residual:
|
||||
/// its residual is 0 (`instantiate::slot_field`), so either form reads the Metal offset alone of
|
||||
/// the same descriptor, and false keeps the key of a draw that leaves the slot unbound the key
|
||||
/// that reads every such slot at its residual, which a consumer can make before any draw binds
|
||||
/// it (the runtime's creation, `pipeline/predicted.rs`).
|
||||
/// consumer's aligned upload; a buffer read through a uniform view, at an offset whose alignment
|
||||
/// class (`BufferShape::Buffer::offset_alignment`: `BindState::view_base_alignment` where the
|
||||
/// runtime tells it apart at the slot and it divides the offset, else a power of two up to 4) the
|
||||
/// base alignment divides; a buffer read through a storage view, at offset 0 alone
|
||||
/// (`bind::ZERO_OFFSET_CLASS`, where the runtime tells it apart at the slot): a storage view's
|
||||
/// range starts at the buffer's start or its window's aligned first byte
|
||||
/// (`instantiate::planned_range`), so its residual is 0 there and elsewhere the bind offset's share
|
||||
/// of it, which keeps the bytes before the bind offset reachable as Metal's are. A slot bound to
|
||||
/// nothing takes false, the form that reads at the residual: its residual is 0
|
||||
/// (`instantiate::slot_field`), so either form reads the Metal offset alone of the same descriptor,
|
||||
/// and false keeps the key of a draw that leaves the slot unbound the key that reads every such
|
||||
/// slot at its residual, which a consumer can make before any draw binds it (the runtime's
|
||||
/// creation, `pipeline/predicted.rs`).
|
||||
pub(crate) fn range_at_bind_offset(
|
||||
b: &BufferSlot,
|
||||
shape: Option<&BufferShape>,
|
||||
@@ -187,6 +192,12 @@ pub(crate) fn range_at_bind_offset(
|
||||
false => limits.min_storage_buffer_offset_alignment,
|
||||
};
|
||||
let offset = match shape {
|
||||
// A storage view's range starts at its bind offset only where that is the buffer's start.
|
||||
Some(&BufferShape::Buffer {
|
||||
offset_alignment: crate::bind::ZERO_OFFSET_CLASS,
|
||||
..
|
||||
}) if !b.form.uniform_view() => 0,
|
||||
Some(BufferShape::Buffer { .. }) if !b.form.uniform_view() => return false,
|
||||
Some(&BufferShape::Buffer {
|
||||
offset_alignment, ..
|
||||
}) => u64::from(offset_alignment),
|
||||
|
||||
@@ -540,6 +540,72 @@ fn a_uniform_range_starts_at_the_bind_offset_where_the_specialization_says() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A storage view's `RangeAtBindOffset` (which its module declares on a profile that takes
|
||||
/// `DriverWorkaround::PushReadsLengthenThreadPayload`) holds only at bind offset 0 of a slot the
|
||||
/// runtime tells offset 0 apart at (`StageTable::zero_offset_views`, the class
|
||||
/// `ZERO_OFFSET_CLASS`), and there only where instantiation's range starts at the bind offset, its
|
||||
/// residual 0: on every committed profile, under each window, for an allocation the view's range
|
||||
/// holds whole (whose range runs from the buffer's start) and one longer than the view's maximum
|
||||
/// (a block or the bind offset's own range). At every other bind offset it is false, the residual
|
||||
/// form, whose range from the buffer's start keeps the bytes before the bind offset reachable; and
|
||||
/// so it is at every offset of a slot whose class tells no offset apart, as on every profile
|
||||
/// without the row.
|
||||
#[test]
|
||||
fn a_storage_range_starts_at_the_bind_offset_only_at_offset_0() {
|
||||
for (stem, p) in committed_profiles().expect("profiles") {
|
||||
let limits = &p.fields().limits;
|
||||
let past = u64::from(limits.max_storage_buffer_range) + (1 << 20);
|
||||
for window in [
|
||||
Window::Whole,
|
||||
Window::Bounded { start: 0, len: 64 },
|
||||
Window::Bounded { start: 4, len: 28 },
|
||||
Window::Bounded {
|
||||
start: 192,
|
||||
len: 16,
|
||||
},
|
||||
Window::Bounded { start: -8, len: 40 },
|
||||
] {
|
||||
let b = BufferSlot {
|
||||
access: AccessSet::READ,
|
||||
window,
|
||||
form: BufferForm::Descriptor(DescriptorView::Storage),
|
||||
kind: BufferKind::Buffer,
|
||||
};
|
||||
let bindings = [(BindingSource::Buffer(slot(0)), (0, 0))].into();
|
||||
for length in [4096, past] {
|
||||
for bind_offset in [0, 4, 16, 64, 256, 1024] {
|
||||
let what = format!("{stem} {window:?} {length} {bind_offset}");
|
||||
let bound = BoundBuffer::Buffer {
|
||||
gpu_address: 0x1_0000,
|
||||
length,
|
||||
offset: bind_offset,
|
||||
device_address: None,
|
||||
attribute_stride: None,
|
||||
};
|
||||
let untold = bound.shape(0);
|
||||
assert!(
|
||||
!range_at_bind_offset(&b, Some(&untold), limits),
|
||||
"{what}: untold"
|
||||
);
|
||||
let told = bound.shape(crate::bind::ZERO_OFFSET_TOLD);
|
||||
let at = range_at_bind_offset(&b, Some(&told), limits);
|
||||
let pb = plan_buffer((slot(0), &b, Some(&told)), false, limits, &bindings)
|
||||
.unwrap_or_else(|e| panic!("{what}: {e:?}"));
|
||||
let starts = crate::bind::instantiate::starts_at_bind(0, window, pb.alignment);
|
||||
assert_eq!(at, bind_offset == 0 && starts, "{what}");
|
||||
// A range past the view's maximum that no form holds takes the device-address
|
||||
// variant (`BufferRangeLimit`), whose module declares no key.
|
||||
let range =
|
||||
crate::bind::instantiate::planned_range(&pb, bind_offset, length, false);
|
||||
if let (true, Ok((_, residual))) = (at, range) {
|
||||
assert_eq!(residual, 0, "{what}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A slot whose function observes residency (`RuntimeFact::SparseTexture`) binds a texture that is
|
||||
/// not sparse (or nothing) on every profile, and a sparse one where the module has the sparse arm
|
||||
/// or the tile-map arm; without either a sparse texture is refused, naming
|
||||
|
||||
@@ -1214,11 +1214,14 @@ impl StageTable {
|
||||
}
|
||||
|
||||
/// The alignment above the vertex fetch's that the bind offset class of a buffer at index
|
||||
/// `index` tells apart ([`BoundBuffer::shape`]): `view_base_alignment` at a slot of
|
||||
/// [`at_bind_views`](Self::at_bind_views), else 0 (none).
|
||||
/// `index` tells apart ([`BoundBuffer::shape`]): offset 0 at a slot of
|
||||
/// [`zero_offset_views`](Self::zero_offset_views) ([`ZERO_OFFSET_TOLD`]),
|
||||
/// `view_base_alignment` at a slot of [`at_bind_views`](Self::at_bind_views), else 0 (none).
|
||||
pub fn class_alignment(&self, index: u32, view_base_alignment: u32) -> u32 {
|
||||
let viewed = index < u64::BITS && (self.at_bind_views >> index) & 1 == 1;
|
||||
if viewed {
|
||||
let told = |slots: u64| index < u64::BITS && (slots >> index) & 1 == 1;
|
||||
if told(self.zero_offset_views) {
|
||||
ZERO_OFFSET_TOLD
|
||||
} else if told(self.at_bind_views) {
|
||||
view_base_alignment
|
||||
} else {
|
||||
0
|
||||
@@ -1292,6 +1295,17 @@ impl BoundBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
/// The bind offset class of a buffer bound at offset 0 at a slot of
|
||||
/// [`StageTable::zero_offset_views`] ([`BufferShape::Buffer::offset_alignment`]): a power of two,
|
||||
/// which divides 0 and above every alignment a class tells apart, so the vertex fetch reads it as
|
||||
/// any aligned offset's; no other bind offset takes it, there or elsewhere.
|
||||
pub const ZERO_OFFSET_CLASS: u32 = 1 << 31;
|
||||
|
||||
/// The class alignment ([`StageTable::class_alignment`]) of a slot of
|
||||
/// [`StageTable::zero_offset_views`], which the binder's offset classes read as telling offset 0
|
||||
/// apart ([`ZERO_OFFSET_CLASS`]) and no alignment above the vertex fetch's.
|
||||
pub const ZERO_OFFSET_TOLD: u32 = u32::MAX;
|
||||
|
||||
/// The alignment class of bind offset `offset` (a buffer's,
|
||||
/// [`BufferShape::Buffer::offset_alignment`]): `view_base_alignment` where that divides it (the
|
||||
/// uniform views' descriptor base alignment, [`BindState::view_base_alignment`]: a view's range
|
||||
@@ -1300,8 +1314,16 @@ impl BoundBuffer {
|
||||
/// fixed-function vertex input can fetch every attribute format at a buffer bound there). These
|
||||
/// are the only predicates a plan reads of a bind offset, so offsets moving between multiples of
|
||||
/// 4 that the base alignment does not divide, or between those it divides, keep one shape; a
|
||||
/// `view_base_alignment` of 4 or less (0, the default) tells only the vertex fetch's apart.
|
||||
/// `view_base_alignment` of 4 or less (0, the default) tells only the vertex fetch's apart. At a
|
||||
/// slot that tells offset 0 apart (`view_base_alignment` [`ZERO_OFFSET_TOLD`]), offset 0 is
|
||||
/// [`ZERO_OFFSET_CLASS`] and every other offset classes as under 0.
|
||||
pub fn offset_alignment(offset: u64, view_base_alignment: u32) -> u32 {
|
||||
if view_base_alignment == ZERO_OFFSET_TOLD {
|
||||
return match offset {
|
||||
0 => ZERO_OFFSET_CLASS,
|
||||
_ => offset_alignment(offset, 0),
|
||||
};
|
||||
}
|
||||
if view_base_alignment > metal::vertex::MAX_VERTEX_ALIGNMENT
|
||||
&& offset.is_multiple_of(u64::from(view_base_alignment))
|
||||
{
|
||||
@@ -1444,6 +1466,16 @@ pub struct StageTable {
|
||||
/// runtime leaves out a slot it finds bound at moving offsets, so that its draws keep one shape.
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub at_bind_views: u64,
|
||||
/// The buffer slots (bit `i` for index `i`) whose bind offset class tells offset 0 apart
|
||||
/// ([`ZERO_OFFSET_CLASS`]), which the runtime sets on a profile that takes
|
||||
/// `DriverWorkaround::PushReadsLengthenThreadPayload`: the slots its function reads through a
|
||||
/// storage view, whose residual is 0 where the buffer is bound at offset 0
|
||||
/// (`SpecKey::RangeAtBindOffset`). No plan reads that predicate of another slot. A slot left
|
||||
/// out (none, the default) reads its view at its residual, exact at every offset: a runtime
|
||||
/// leaves out a slot it finds bound at an offset other than 0, so that its draws and dispatches
|
||||
/// keep one shape.
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub zero_offset_views: u64,
|
||||
}
|
||||
|
||||
/// What the consumer knows of a Metal acceleration structure bound at a buffer slot.
|
||||
|
||||
Vendored
+2
-2
@@ -61,7 +61,7 @@ mod tests;
|
||||
/// unchanged version, and its bless records the version. Independent of the crate's version and of
|
||||
/// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no
|
||||
/// history.
|
||||
pub const SEMANTICS_VERSION: u32 = 2127;
|
||||
pub const SEMANTICS_VERSION: u32 = 2128;
|
||||
|
||||
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
|
||||
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
|
||||
@@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 523;
|
||||
/// changes no behaviour, and then updates that hash alone with the commit saying why, or changes
|
||||
/// behaviour and also bumps this version. The commit that bumps it says what changed; this comment
|
||||
/// keeps no history.
|
||||
pub const RUNTIME_VERSION: u32 = 2397;
|
||||
pub const RUNTIME_VERSION: u32 = 2398;
|
||||
|
||||
/// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex,
|
||||
/// of the manifest, the build script, and exactly the files the crate roots' module tree compiles
|
||||
|
||||
@@ -877,6 +877,19 @@ const fn moltenvk_on_apple<F>(fact: F) -> Measured<F> {
|
||||
/// Radeon 780M (Phoenix and Hawk Point), answered every word of both as Metal's under the same
|
||||
/// modes, so it is not listed. One row per GPU, the GPUs NVIDIA's `MetalFloatDenormals` rows
|
||||
/// name.
|
||||
/// - `PushReadsLengthenThreadPayload`: ANV, Mesa 26.2.6 on the Iris Xe of RPL-P, ran
|
||||
/// `dispatch_chain`'s one-word kernel (4480 threadgroups of 256, 200 dispatches a command
|
||||
/// buffer, 9 interleaved rounds, medians) over a plain allocation in 55.73 us a dispatch, and the
|
||||
/// runtime's own module of it in 120.24 us (job m3-max-34063); with the module's one push read,
|
||||
/// its storage view's `SlotBindOffset` residual, replaced by a constant 0 it ran in 55.69 us,
|
||||
/// and without its `Aliased` or its specialized-away barrier in 120.24 and 120.17 us. Pushing
|
||||
/// the runtime's 36 bytes of push constants to the plain kernel, which reads none, ran in
|
||||
/// 55.68 us, and the runtime's module on the plain kernel's device in 120.19 us (job
|
||||
/// m3-max-34038). Both modules' loads and stores are the same `untyped_read` and
|
||||
/// `untyped_write` of binding table entry 1 (job m3-max-33825). A cost fact: it only chooses
|
||||
/// between two exact encodings. RADV, Mesa 26.2.6 on the Radeon 780M, ran the runtime's form and
|
||||
/// the plain one alike (109.6 and 109.1 to 114.1 us, job m3-max-34031), so it is not listed; the
|
||||
/// row names the GPU measured.
|
||||
pub(crate) const DEFECTS: &[Measured<DriverWorkaround>] = &[
|
||||
Measured {
|
||||
fact: DriverWorkaround::BothBarycentricFormsRejected,
|
||||
@@ -946,6 +959,11 @@ pub(crate) const DEFECTS: &[Measured<DriverWorkaround>] = &[
|
||||
DriverWorkaround::FloatDenormalsKeptUnderHalfControls,
|
||||
NVIDIA_RTX_5080_LAPTOP,
|
||||
),
|
||||
mesa_on(
|
||||
DriverWorkaround::PushReadsLengthenThreadPayload,
|
||||
DriverId::INTEL_OPEN_SOURCE_MESA,
|
||||
(INTEL_VENDOR_ID, INTEL_IRIS_XE_RPL_P),
|
||||
),
|
||||
];
|
||||
|
||||
/// The defects translation works around on the driver `description` names, on its GPU.
|
||||
|
||||
@@ -1557,6 +1557,21 @@ pub enum DriverWorkaround {
|
||||
/// otherwise (`Needs::DriverDefect`), never handed to the driver. The bound rises when a larger
|
||||
/// compile is measured within host-sized memory.
|
||||
CompilerMemoryGrowsWithStageSize,
|
||||
/// A compute shader that reads a push constant runs each thread with a longer payload, and so
|
||||
/// more slowly on a light kernel: a measured cost fact (`device::driver_facts`) that chooses
|
||||
/// between two exact encodings of a buffer slot's offset. ANV
|
||||
/// (`VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA`), Mesa 26.2.6, on the Iris Xe of RPL-P, ran a kernel
|
||||
/// that reads and writes one word a thread over a 4.6 MB storage buffer (4480 threadgroups of
|
||||
/// 256, 200 dispatches a command buffer) in 120.2 us a dispatch where the buffer's offset is
|
||||
/// its pushed `SlotBindOffset` residual plus the Metal offset, and in 55.7 us where that read
|
||||
/// is a constant 0. There the native code holds the driver's own base workgroup ID 17
|
||||
/// registers further into the thread's payload than in the kernel that reads no push
|
||||
/// constant. Keyed on the driver and that GPU alone. There a storage view's slot declares
|
||||
/// `SpecKey::RangeAtBindOffset` as a uniform view's does (`lower::access`), which the binder
|
||||
/// sets where the slot is bound at offset 0, a storage view's range then starting at its bind
|
||||
/// offset (`bind::plan::slots::range_at_bind_offset`); the runtime takes each view's form at
|
||||
/// its bind offset there, a uniform view's included. It changes no answer.
|
||||
PushReadsLengthenThreadPayload,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -289,8 +289,9 @@ pub(super) fn prepare(
|
||||
};
|
||||
let residual = cx.push_field(fb, PushField::SlotBindOffset(choice.slot))?;
|
||||
let shifted = u32_op(fb, BinOp::IAdd, residual, m)?;
|
||||
// Where the binder starts a uniform view's range at the bind offset (`RangeAtBindOffset`), the
|
||||
// residual is 0: the offset alone, a constant for a constant member, which a driver can push.
|
||||
// Where the binder starts a view's range at the bind offset (`RangeAtBindOffset`: a uniform
|
||||
// view's, or a storage view's where the plan declares it), the residual is 0: the offset alone,
|
||||
// a constant for a constant member, which a driver can push, and no push word read.
|
||||
let off = match cx
|
||||
.decl
|
||||
.families
|
||||
|
||||
@@ -124,7 +124,7 @@ use std::collections::{BTreeMap, BTreeSet};
|
||||
use crate::air::abi::{AbiInt, ParamBinding, ParamRole};
|
||||
use crate::air::ir::{AddrSpace, CastOp, Const, Inst, InstId, InstKind, Type, Value, ValueId};
|
||||
use crate::budget::Meter;
|
||||
use crate::device::profile::{BufferAccess, Containment, Limits};
|
||||
use crate::device::profile::{BufferAccess, Containment, DriverWorkaround, Limits};
|
||||
use crate::device::requirements::VkLimit;
|
||||
use crate::device::DeviceProfile;
|
||||
use crate::error::{Capability, Error, Feature, LowerFamily, Unsupported};
|
||||
@@ -697,6 +697,11 @@ pub struct AccessPlan {
|
||||
/// The narrow units device-address accesses load and store directly (`psb::narrow_units` of
|
||||
/// the profile): a sub-word store there is one narrow store instead of two word atomics.
|
||||
pub psb_units: Units,
|
||||
/// A storage view's slot declares its `RangeAtBindOffset` specialization, as a uniform view's
|
||||
/// does: the profile takes `DriverWorkaround::PushReadsLengthenThreadPayload`, so a read of
|
||||
/// the slot at its bind offset alone, which reads no push word, is worth the key
|
||||
/// ([`Declared::at_bind`]).
|
||||
pub storage_at_bind: bool,
|
||||
/// The arenas the function uses.
|
||||
pub local: local::LocalPlan,
|
||||
/// The function's index extensions ([`index`]): planned before any instruction is selected
|
||||
@@ -873,9 +878,10 @@ pub struct Declared {
|
||||
/// The stage's view of the command buffer's `ExecutionStatus` buffer, where it binds the
|
||||
/// buffer ([`absent::declare`]).
|
||||
pub status: Option<View>,
|
||||
/// The `RangeAtBindOffset` specialization of each slot read through a uniform view, by
|
||||
/// memory-plan slot index: where it holds, an access reads the view at the Metal offset alone
|
||||
/// ([`range_at_bind_offset`]).
|
||||
/// The `RangeAtBindOffset` specialization of each slot read through a uniform view, and of
|
||||
/// each read through a storage view where the plan says so (`AccessPlan::storage_at_bind`),
|
||||
/// by memory-plan slot index: where it holds, an access reads the view at the Metal offset
|
||||
/// alone ([`range_at_bind_offset`]).
|
||||
pub at_bind: Vec<Option<SValue>>,
|
||||
}
|
||||
|
||||
@@ -1547,6 +1553,9 @@ fn place_slots(cx: &mut SelectCx<'_>, m: &mut Meter) -> Result<Vec<Option<SlotCh
|
||||
cx.families.access.slots = lowering;
|
||||
cx.families.access.psb_contained = p.fields().containment != Containment::UnsafeOff;
|
||||
cx.families.access.psb_units = psb::narrow_units(p);
|
||||
cx.families.access.storage_at_bind = p
|
||||
.workarounds()
|
||||
.contains(&DriverWorkaround::PushReadsLengthenThreadPayload);
|
||||
Ok(slots)
|
||||
}
|
||||
|
||||
@@ -1845,6 +1854,9 @@ pub fn declare(
|
||||
(Some(c), Some(ViewKind::UniformWords { .. } | ViewKind::UniformVec4 { .. })) => {
|
||||
Some(range_at_bind_offset(mb, c.slot)?)
|
||||
}
|
||||
(Some(c), Some(ViewKind::Storage)) if plan.families.access.storage_at_bind => {
|
||||
Some(range_at_bind_offset(mb, c.slot)?)
|
||||
}
|
||||
_ => None,
|
||||
});
|
||||
let units = plan
|
||||
|
||||
@@ -359,6 +359,22 @@ fn source(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, buffer: u32) -> BRe
|
||||
match (lowering, view) {
|
||||
(Some(SlotLowering::View(ViewKind::Storage)), Some(view)) => {
|
||||
let residual = cx.push_field(fb, PushField::SlotBindOffset(slot))?;
|
||||
// A shared slot whose view the binder starts at the bind offset
|
||||
// (`RangeAtBindOffset`, where the plan declares it) has residual 0: the fetch reads
|
||||
// no push word there, as the function's own accesses do (`emit::prepare`).
|
||||
let at_bind = match reach {
|
||||
Some(Reach::Shared { slot }) => {
|
||||
cx.decl.families.access.at_bind.get(slot).copied().flatten()
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let residual = match at_bind {
|
||||
Some(at_bind) => {
|
||||
let zero = k32(fb, 0)?;
|
||||
fb.select(at_bind, zero, residual)?
|
||||
}
|
||||
None => residual,
|
||||
};
|
||||
Ok(Source::View { view, residual })
|
||||
}
|
||||
(Some(SlotLowering::Psb { start }), _) => {
|
||||
|
||||
@@ -864,10 +864,26 @@ impl PipelineInterface {
|
||||
/// uniform view ([`BufferForm::uniform_view`]): the slots whose bind offset class can tell the
|
||||
/// device's view base alignment apart (`StageTable::at_bind_views`).
|
||||
pub fn uniform_view_buffers(&self, stage: Stage) -> u64 {
|
||||
self.buffers_where(stage, BufferForm::uniform_view)
|
||||
}
|
||||
|
||||
/// The buffer slots of `stage` (bit `i` for index `i`, below 64) its function reads through a
|
||||
/// storage view (`BufferForm::Descriptor(DescriptorView::Storage)`): on a profile that takes
|
||||
/// `DriverWorkaround::PushReadsLengthenThreadPayload`, the slots whose bind offset class can
|
||||
/// tell offset 0 apart (`StageTable::zero_offset_views`), where such a view's
|
||||
/// `SpecKey::RangeAtBindOffset` reads it at its bind offset alone.
|
||||
pub fn storage_view_buffers(&self, stage: Stage) -> u64 {
|
||||
self.buffers_where(stage, |form| {
|
||||
form == BufferForm::Descriptor(DescriptorView::Storage)
|
||||
})
|
||||
}
|
||||
|
||||
/// The buffer slots of `stage` (bit `i` for index `i`, below 64) whose form `takes`.
|
||||
fn buffers_where(&self, stage: Stage, takes: impl Fn(BufferForm) -> bool) -> u64 {
|
||||
let mut slots = 0;
|
||||
for (slot, interface) in &self.slots {
|
||||
if let SlotInterface::Buffer(b) = interface {
|
||||
if slot.stage == stage && slot.index < u64::BITS && b.form.uniform_view() {
|
||||
if slot.stage == stage && slot.index < u64::BITS && takes(b.form) {
|
||||
slots |= 1 << slot.index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -842,7 +842,13 @@ pub enum SpecKey {
|
||||
/// first aligned block. A slot bound to nothing takes true: its residual is 0. Where it holds,
|
||||
/// the function reads the slot at the Metal offset alone, a constant for a constant member,
|
||||
/// which a driver can load into registers ahead of the shader (Mesa's ANV does so only for a
|
||||
/// uniform load at a constant offset); elsewhere at the residual plus the offset.
|
||||
/// uniform load at a constant offset); elsewhere at the residual plus the offset. A slot read
|
||||
/// through a storage view declares it too on a profile that takes
|
||||
/// `DriverWorkaround::PushReadsLengthenThreadPayload`: true where the buffer is bound at
|
||||
/// offset 0 (inline bytes, or a buffer whose bind offset class is
|
||||
/// `bind::ZERO_OFFSET_CLASS`), where its range starts at the buffer's start, the bind offset,
|
||||
/// so the residual is 0 and the function reads no push word for it; false elsewhere, so the
|
||||
/// bytes before a bind offset stay reachable through the residual as Metal's are.
|
||||
RangeAtBindOffset(SlotRef),
|
||||
/// The word of the runtime sampler bound to the slot (`u32`: its whole
|
||||
/// [`SamplerWord`](crate::metal::sampler::SamplerWord), its address modes as the bound
|
||||
|
||||
@@ -27,13 +27,13 @@
|
||||
//!
|
||||
//! `llvm-as` assembles the fixtures; without it the tests skip visibly.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
use crate::air;
|
||||
use crate::budget::SPIRV_WORDS;
|
||||
use crate::device::profile::{BufferAccess, DeviceProfile};
|
||||
use crate::device::profile::{BufferAccess, DeviceProfile, DriverWorkaround};
|
||||
use crate::device::requirements::VkFeature;
|
||||
use crate::device::{Device, DeviceDescription, DevicePolicy};
|
||||
use crate::error::{Error, Feature, LowerFamily, Needs, Unsupported};
|
||||
@@ -53,7 +53,9 @@ use crate::pipeline::testing::{
|
||||
AssembleError,
|
||||
};
|
||||
use crate::spirv::interp::{run, Buffer, Config, InterpError, Resources};
|
||||
use crate::spirv::ir::{GlobalKind, Inst, StorageClass, Type, TypedModule};
|
||||
use crate::spirv::ir::{
|
||||
ConstBits, ConstKind, GlobalKind, Inst, StorageClass, Type, TypedModule, ValueOrigin,
|
||||
};
|
||||
use crate::spirv::verify::verify;
|
||||
|
||||
/// Profiles with and without 64-bit integers and 8/16-bit storage.
|
||||
@@ -343,6 +345,190 @@ fn a_uniform_view_read_at_its_bind_offset_drops_the_residual() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The committed profile that takes `DriverWorkaround::PushReadsLengthenThreadPayload`: the Iris
|
||||
/// Xe RPL-P under ANV, where the row was measured.
|
||||
const AT_BIND_PROFILE: &str = "intel-irisxe-rplp-anv";
|
||||
|
||||
/// Whether a function of `m` reads push member `field` with the specialization constant of `key`
|
||||
/// at `value`: whether a value the member's word reaches is read by an instruction other than one
|
||||
/// that computes its own result from its operands alone (`spirv::dead::removable`, a result the
|
||||
/// word reaches in turn), or a terminator. An `OpSelect` on the key's constant reaches only the
|
||||
/// arm the value takes, as a driver folds it once the constant is specialized; then every value
|
||||
/// the word reaches is dead, and the driver's dead-code removal drops the push read itself.
|
||||
fn reads_push_word(m: &TypedModule, field: PushField, (key, value): (SpecKey, bool)) -> bool {
|
||||
let Some(member) = m.push_members().iter().find(|p| p.field == field) else {
|
||||
return false;
|
||||
};
|
||||
let member = ConstBits(u64::from(member.index));
|
||||
let push = m.globals().iter().find(|g| g.kind == GlobalKind::PushBlock);
|
||||
let push = push.map(|g| g.value);
|
||||
let cond = m.consts().iter().find_map(|(c, d)| match &d.kind {
|
||||
ConstKind::Spec { key: k, .. } if *k == key => m.const_value(c).ok(),
|
||||
_ => None,
|
||||
});
|
||||
let is_member = |v| match m.value(v).map(|d| d.origin) {
|
||||
Ok(ValueOrigin::Const(c)) => m.consts().scalar_bits(c) == Some(member),
|
||||
_ => false,
|
||||
};
|
||||
// The arm `inst` reads its reached operands through: a select on the key's constant reads
|
||||
// only the arm it takes.
|
||||
let reads = |inst: &Inst, reached: &BTreeSet<crate::spirv::ids::Value>| match inst {
|
||||
Inst::Select { cond: c, t, f } if Some(*c) == cond => {
|
||||
reached.contains(if value { t } else { f })
|
||||
}
|
||||
_ => {
|
||||
let mut any = false;
|
||||
inst.for_each_value(|v| any |= reached.contains(&v));
|
||||
any
|
||||
}
|
||||
};
|
||||
let mut reached = BTreeSet::new();
|
||||
loop {
|
||||
let before = reached.len();
|
||||
for blk in m.blocks() {
|
||||
for phi in &blk.phis {
|
||||
if phi.incoming.iter().any(|(v, _)| reached.contains(v)) {
|
||||
reached.insert(phi.result);
|
||||
}
|
||||
}
|
||||
for node in &blk.insts {
|
||||
let Some(r) = node.result else { continue };
|
||||
let reaches = match &node.inst {
|
||||
Inst::AccessChain { base, indices, .. } if Some(*base) == push => {
|
||||
indices.first().is_some_and(|&i| is_member(i))
|
||||
}
|
||||
inst => reads(inst, &reached),
|
||||
};
|
||||
if reaches {
|
||||
reached.insert(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
if reached.len() == before {
|
||||
break;
|
||||
}
|
||||
}
|
||||
m.blocks().iter().any(|blk| {
|
||||
let mut term = false;
|
||||
blk.term.for_each_value(|v| term |= reached.contains(&v));
|
||||
term || blk.insts.iter().any(|node| {
|
||||
let pure = node.result.is_some_and(|r| reached.contains(&r))
|
||||
&& crate::spirv::dead::removable(&node.inst);
|
||||
reads(&node.inst, &reached) && !pure
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// On the profile that takes `DriverWorkaround::PushReadsLengthenThreadPayload`, a storage view's
|
||||
/// slot declares its `RangeAtBindOffset` specialization, as a uniform view's does: at 1, which the
|
||||
/// binder sets where the view's range starts at the bind offset (offset 0,
|
||||
/// `bind::ZERO_OFFSET_CLASS`), no value the slot's `SlotBindOffset` word reaches is read once the
|
||||
/// key is folded ([`reads_push_word`]), and a load takes the Metal offset alone whatever residual
|
||||
/// is pushed; at 0, the negative control, the word is read and a load takes the residual plus the
|
||||
/// offset, as before. A load, a sub-word store and atomics, in both encodings.
|
||||
#[test]
|
||||
fn a_storage_view_read_at_its_bind_offset_reads_no_residual() {
|
||||
let cases = [
|
||||
("buffer_end_byte_load", "buffer_end_byte_load", &[0u32][..]),
|
||||
("buffer_end_byte_store", "buffer_end_byte_store", &[0]),
|
||||
("a27_ob1_buffer_atomic", "ob1_buffer_atomic", &[0, 1]),
|
||||
];
|
||||
for (fixture, entry, slots) in cases {
|
||||
let Some(bc) = assemble_file(fixture) else {
|
||||
return;
|
||||
};
|
||||
for robust in [true, false] {
|
||||
let what = format!("{fixture} robust={robust}");
|
||||
let p = profile_with(AT_BIND_PROFILE, robust, true);
|
||||
assert!(
|
||||
p.workarounds()
|
||||
.contains(&DriverWorkaround::PushReadsLengthenThreadPayload),
|
||||
"{what}"
|
||||
);
|
||||
check_l3(&bc, entry, &p, &what);
|
||||
let a = compile(&bc, entry, &p).unwrap_or_else(|e| panic!("{what}: {e}"));
|
||||
let (_, m) = typed_module(&bc, entry, &p).expect("module");
|
||||
for &i in slots {
|
||||
let key = SpecKey::RangeAtBindOffset(sref(i));
|
||||
let field = PushField::SlotBindOffset(sref(i));
|
||||
let form = match a.interface.slots.get(&sref(i)) {
|
||||
Some(SlotInterface::Buffer(b)) => b.form,
|
||||
other => panic!("{what}: {other:?}"),
|
||||
};
|
||||
assert_eq!(
|
||||
form,
|
||||
BufferForm::Descriptor(DescriptorView::Storage),
|
||||
"{what} slot {i}"
|
||||
);
|
||||
assert!(a.interface.read_keys().contains(&key), "{what} slot {i}");
|
||||
assert!(
|
||||
!reads_push_word(&m, field, (key, true)),
|
||||
"{what} slot {i} at 1"
|
||||
);
|
||||
assert!(
|
||||
reads_push_word(&m, field, (key, false)),
|
||||
"{what} slot {i} at 0"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
let Some(bc) = assemble_file("buffer_end_byte_load") else {
|
||||
return;
|
||||
};
|
||||
let data = [1u8, 2, 3, 4, 5, 0x9C];
|
||||
let key = SpecKey::RangeAtBindOffset(sref(0));
|
||||
for robust in [true, false] {
|
||||
let p = profile_with(AT_BIND_PROFILE, robust, true);
|
||||
let (plan, m) = typed_module(&bc, "buffer_end_byte_load", &p).expect("module");
|
||||
// The data at byte 0, a residual of 8 pushed: byte 5 when the range starts at the bind
|
||||
// offset, byte 13 (the padding) when it does not.
|
||||
for (at_bind, want) in [(1u64, 0x9Cu8), (0, 0x77)] {
|
||||
let res = Resources {
|
||||
buffers: vec![bound(0, 0, &data, 0x77), bound(1, 0, &[0; 4], 0)],
|
||||
push: push_bytes(&plan, &[(0, 8)]),
|
||||
spec: [(key, at_bind)].into(),
|
||||
};
|
||||
let out = run(&m, &Config::default(), res).expect("run");
|
||||
assert_eq!(
|
||||
out.buffers[1][..4],
|
||||
[want, 0, 0, 0],
|
||||
"robust={robust} at_bind={at_bind}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// On every other tested profile, the same driver's on another GPU among them
|
||||
/// (`intel-irisxe-anv`), no storage view declares `RangeAtBindOffset`: the key a binder sets stays
|
||||
/// absent, every access reads the slot's `SlotBindOffset` residual as before, and the plan's slot
|
||||
/// takes the class it took before (`bind::plan::slots`). The modules are the ones those profiles
|
||||
/// made before the row existed (`golden_hashes` pins every public fixture's on every committed
|
||||
/// profile).
|
||||
#[test]
|
||||
fn a_storage_view_reads_its_residual_without_the_row() {
|
||||
let Some(bc) = assemble_file("buffer_end_byte_load") else {
|
||||
return;
|
||||
};
|
||||
let key = SpecKey::RangeAtBindOffset(sref(0));
|
||||
let field = PushField::SlotBindOffset(sref(0));
|
||||
for stem in PROFILES.into_iter().chain(["intel-irisxe-anv"]) {
|
||||
for robust in [true, false] {
|
||||
let what = format!("{stem} robust={robust}");
|
||||
let p = profile_with(stem, robust, true);
|
||||
assert!(
|
||||
!p.workarounds()
|
||||
.contains(&DriverWorkaround::PushReadsLengthenThreadPayload),
|
||||
"{what}"
|
||||
);
|
||||
let a =
|
||||
compile(&bc, "buffer_end_byte_load", &p).unwrap_or_else(|e| panic!("{what}: {e}"));
|
||||
assert!(!a.interface.read_keys().contains(&key), "{what}");
|
||||
let (_, m) = typed_module(&bc, "buffer_end_byte_load", &p).expect("module");
|
||||
assert!(reads_push_word(&m, field, (key, true)), "{what}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A `constant` struct of 6 bytes whose first and last bytes are read: its window starts at 0.
|
||||
const CONSTANT_ENDS: &str = r#"define void @constant_ends(ptr addrspace(2) noundef "air-buffer-no-alias" %0, ptr addrspace(1) noundef "air-buffer-no-alias" %1) {
|
||||
entry:
|
||||
|
||||
@@ -1084,6 +1084,8 @@ const metal2vulkan::bind::METAL_OBJECT_GRID_TOTAL pub const METAL_OBJECT_GRID_TO
|
||||
const metal2vulkan::bind::NEUTRAL_HEAP_ELEMENT pub const NEUTRAL_HEAP_ELEMENT: u32
|
||||
const metal2vulkan::bind::SRGB_RESOLVE_LINEAR pub const SRGB_RESOLVE_LINEAR: [u16; 256]
|
||||
const metal2vulkan::bind::SRGB_RESOLVE_THRESHOLDS pub const SRGB_RESOLVE_THRESHOLDS: [u16; 255]
|
||||
const metal2vulkan::bind::ZERO_OFFSET_CLASS pub const ZERO_OFFSET_CLASS: u32
|
||||
const metal2vulkan::bind::ZERO_OFFSET_TOLD pub const ZERO_OFFSET_TOLD: u32
|
||||
const metal2vulkan::bind::fan_out::BLOCK_SET pub const BLOCK_SET: u32
|
||||
const metal2vulkan::bind::fan_out::BLOCK_TRIANGLES pub const BLOCK_TRIANGLES: u32
|
||||
const metal2vulkan::bind::fan_out::BOUND_BUCKETS pub const BOUND_BUCKETS: u32
|
||||
@@ -1172,6 +1174,8 @@ const-value metal2vulkan::bind::METAL_OBJECT_GRID_TOTAL 1 <<29
|
||||
const-value metal2vulkan::bind::NEUTRAL_HEAP_ELEMENT NEUTRAL_ELEMENT
|
||||
const-value metal2vulkan::bind::SRGB_RESOLVE_LINEAR [0, 1, 2, 4, 5, 6, 7, 9, 10, 11, 12, 14, 15, 16, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35, 37, 40, 42, 45, 48, 50, 53, 56, 59, 62, 66, 69, 72, 76, 79, 83, 87, 91, 95, 99, 103, 107, 112, 116, 121, 126, 131, 136, 141, 146, 151, 156, 162, 168, 173, 179, 185, 191, 197, 204, 210, 216, 223, 230, 237, 244, 251, 258, 265, 273, 280, 288, 296, 304, 312, 320, 329, 337, 346, 354, 363, 372, 381, 390, 400, 409, 419, 428, 438, 448, 458, 469, 479, 490, 500, 511, 522, 533, 544, 555, 567, 578, 590, 602, 614, 626, 639, 651, 664, 676, 689, 702, 715, 728, 742, 755, 769, 783, 797, 811, 825, 840, 854, 869, 884, 899, 914, 929, 945, 960, 976, 992, 1008, 1024, 1041, 1057, 1074, 1091, 1108, 1125, 1142, 1159, 1177, 1195, 1213, 1231, 1249, 1267, 1286, 1304, 1323, 1342, 1361, 1381, 1400, 1420, 1440, 1459, 1480, 1500, 1520, 1541, 1562, 1582, 1603, 1625, 1646, 1668, 1689, 1711, 1733, 1755, 1778, 1800, 1823, 1846, 1869, 1892, 1916, 1939, 1963, 1987, 2011, 2035, 2059, 2084, 2109, 2133, 2159, 2184, 2209, 2235, 2260, 2286, 2312, 2339, 2365, 2392, 2419, 2446, 2473, 2500, 2527, 2555, 2583, 2611, 2639, 2668, 2696, 2725, 2754, 2783, 2812, 2841, 2871, 2901, 2931, 2961, 2991, 3022, 3052, 3083, 3114, 3146, 3177, 3209, 3240, 3272, 3304, 3337, 3369, 3402, 3435, 3468, 3501, 3535, 3568, 3602, 3636, 3670, 3705, 3739, 3774, 3809, 3844, 3879, 3915, 3950, 3986, 4022, 4059, 4095]
|
||||
const-value metal2vulkan::bind::SRGB_RESOLVE_THRESHOLDS [1, 2, 4, 5, 6, 7, 9, 10, 11, 12, 14, 15, 16, 18, 19, 21, 23, 24, 26, 28, 30, 32, 34, 37, 39, 42, 44, 47, 49, 52, 55, 58, 61, 64, 68, 71, 74, 78, 82, 85, 89, 93, 97, 102, 106, 110, 115, 119, 124, 129, 134, 139, 144, 149, 154, 160, 165, 171, 177, 183, 189, 195, 201, 207, 214, 220, 227, 234, 241, 248, 255, 262, 270, 277, 285, 293, 300, 308, 317, 325, 333, 342, 350, 359, 368, 377, 386, 395, 405, 414, 424, 434, 444, 454, 464, 474, 485, 495, 506, 517, 528, 539, 550, 562, 573, 585, 597, 609, 621, 633, 645, 658, 670, 683, 696, 709, 722, 736, 749, 763, 777, 790, 804, 819, 833, 848, 862, 877, 892, 907, 922, 938, 953, 969, 985, 1001, 1017, 1033, 1049, 1066, 1083, 1100, 1117, 1134, 1151, 1169, 1186, 1204, 1222, 1240, 1259, 1277, 1296, 1314, 1333, 1352, 1371, 1391, 1410, 1430, 1450, 1470, 1490, 1510, 1531, 1552, 1572, 1593, 1615, 1636, 1657, 1679, 1701, 1723, 1745, 1767, 1790, 1812, 1835, 1858, 1881, 1904, 1928, 1951, 1975, 1999, 2023, 2048, 2072, 2097, 2121, 2146, 2172, 2197, 2222, 2248, 2274, 2300, 2326, 2352, 2379, 2406, 2433, 2460, 2487, 2514, 2542, 2569, 2597, 2626, 2654, 2682, 2711, 2740, 2769, 2798, 2827, 2857, 2886, 2916, 2946, 2977, 3007, 3038, 3068, 3099, 3130, 3162, 3193, 3225, 3257, 3289, 3321, 3354, 3386, 3419, 3452, 3485, 3518, 3552, 3586, 3620, 3654, 3688, 3722, 3757, 3792, 3827, 3862, 3897, 3933, 3969, 4005, 4041, 4077]
|
||||
const-value metal2vulkan::bind::ZERO_OFFSET_CLASS 1 <<31
|
||||
const-value metal2vulkan::bind::ZERO_OFFSET_TOLD u32::MAX
|
||||
const-value metal2vulkan::bind::fan_out::BLOCK_SET 5
|
||||
const-value metal2vulkan::bind::fan_out::BLOCK_TRIANGLES 64
|
||||
const-value metal2vulkan::bind::fan_out::BOUND_BUCKETS 16
|
||||
@@ -4365,6 +4369,7 @@ field metal2vulkan::bind::StageTable.buffers pub buffers: BTreeMap<u32, BoundBuf
|
||||
field metal2vulkan::bind::StageTable.samplers pub samplers: BTreeMap<u32, BoundSampler>
|
||||
field metal2vulkan::bind::StageTable.textures pub textures: BTreeMap<u32, BoundTexture>
|
||||
field metal2vulkan::bind::StageTable.threadgroup_lengths pub threadgroup_lengths: BTreeMap<u32, u32>
|
||||
field metal2vulkan::bind::StageTable.zero_offset_views pub zero_offset_views: u64
|
||||
field metal2vulkan::bind::StatusReport.absent_argument_read pub absent_argument_read: bool
|
||||
field metal2vulkan::bind::StatusReport.cubic_argument_sampler pub cubic_argument_sampler: bool
|
||||
field metal2vulkan::bind::StatusReport.index_pool_overflow pub index_pool_overflow: bool
|
||||
@@ -10179,6 +10184,7 @@ method metal2vulkan::pipeline::MeshPipelineDescriptor::unwritten_fragment_inputs
|
||||
method metal2vulkan::pipeline::MeshRecords::group_words pub fn group_words(&self) -> u64
|
||||
method metal2vulkan::pipeline::MeshRecords::primitive_base pub fn primitive_base(&self) -> u64
|
||||
method metal2vulkan::pipeline::MeshRecords::topology pub fn topology(&self) -> vk::PrimitiveTopology
|
||||
method metal2vulkan::pipeline::PipelineInterface::storage_view_buffers pub fn storage_view_buffers(&self, stage: Stage) -> u64
|
||||
method metal2vulkan::pipeline::PipelineInterface::uniform_view_buffers pub fn uniform_view_buffers(&self, stage: Stage) -> u64
|
||||
method metal2vulkan::pipeline::PrecisionNote::of_float_operator pub fn of_float_operator(op: AirBin, width: FloatWidth, fmf: FastMath, p: &DeviceProfile, math: EntryMath) -> Option<BTreeSet<PrecisionNote>>
|
||||
method metal2vulkan::pipeline::PrecisionNote::of_math_call pub fn of_math_call(call: Math, fmf: FastMath, p: &DeviceProfile, math: EntryMath) -> Option<BTreeSet<PrecisionNote>>
|
||||
@@ -13875,6 +13881,7 @@ variant metal2vulkan::device::DriverWorkaround::MeshIndexComponentStoresMisplace
|
||||
variant metal2vulkan::device::DriverWorkaround::NarrowMaskAfterSignedClamp NarrowMaskAfterSignedClamp
|
||||
variant metal2vulkan::device::DriverWorkaround::OppositeZeroProductsMerged OppositeZeroProductsMerged
|
||||
variant metal2vulkan::device::DriverWorkaround::PerspectiveReadsExtrapolated PerspectiveReadsExtrapolated
|
||||
variant metal2vulkan::device::DriverWorkaround::PushReadsLengthenThreadPayload PushReadsLengthenThreadPayload
|
||||
variant metal2vulkan::device::DriverWorkaround::RegisterAllocatorOverflowsLargeModules RegisterAllocatorOverflowsLargeModules
|
||||
variant metal2vulkan::device::DriverWorkaround::SerializedStageWrapsLargeModules SerializedStageWrapsLargeModules
|
||||
variant metal2vulkan::device::DriverWorkaround::TessellatorNotMetals TessellatorNotMetals
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -560,6 +560,8 @@ surface! {
|
||||
enum UsedClass N;
|
||||
struct UsedResource N;
|
||||
struct UsedShape N;
|
||||
const ZERO_OFFSET_CLASS;
|
||||
const ZERO_OFFSET_TOLD;
|
||||
struct VertexAmplification N;
|
||||
struct ViewMapping N;
|
||||
struct ImageblockSize N;
|
||||
|
||||
+12
-2
@@ -1459,9 +1459,19 @@ for dependency in &pipeline.dependencies {
|
||||
shape and one pipeline (the runtime leaves out each slot of a state once it finds one bound at
|
||||
an offset the alignment does not divide). A consumer that draws and dispatches every key at its
|
||||
residual form (each `RangeAtBindOffset` at 0, as the runtime does on every device whose driver
|
||||
is not measured to load such reads ahead of the shader) says so with
|
||||
is not measured to load such reads ahead of the shader, nor takes the workaround below) says so
|
||||
with
|
||||
`state.uniform_views_at_residual = true`: its uniform views then bind ranges their bind offsets
|
||||
share (below), as a bounded storage view's do.
|
||||
share (below), as a bounded storage view's do. On a profile that takes
|
||||
`DriverWorkaround::PushReadsLengthenThreadPayload` (ANV on the Iris Xe RPL-P, where a light kernel
|
||||
that reads a pushed word was measured at about 2.2 times the time of one that reads none) a
|
||||
storage view declares the key too, and takes the form that reads no residual only at bind offset 0
|
||||
of a slot whose table tells offset 0 apart (the slot's bit in its table's `zero_offset_views`;
|
||||
`interface.storage_view_buffers(stage)` lists the slots that can take it), its class then
|
||||
`bind::ZERO_OFFSET_CLASS`: leave out a slot bound at another offset, as the runtime does, so that
|
||||
the bytes before a bind offset stay reachable through the range from the buffer's start and its
|
||||
dispatches keep one shape. Elsewhere no storage view declares the key, and `zero_offset_views`
|
||||
changes nothing.
|
||||
- A two-plane YCbCr texture whose planes a function may read in place states them in its facts
|
||||
(`TextureFacts::ycbcr_in_place`, a `YCbCrInPlace` of its planes; the runtime states one on a
|
||||
device whose memory is the host's, `DeviceProfile::reads_ycbcr_planes_in_place`: an integrated
|
||||
|
||||
@@ -876,6 +876,17 @@ driver's. Each is open work.
|
||||
image in place where the device's check finds its copies losing those bytes too
|
||||
(`LineWriteBack`, `line-write-back`, and the host-pages row of **Fast defaults**); a buffer's
|
||||
own copies and a kernel's stores are not announced.
|
||||
- **On the Iris Xe (ANV), a kernel over memory the device allocates exportable, or imports from
|
||||
host pages, runs about 2.2 times as long as over memory it allocates plainly**; why is not
|
||||
observed. A raw Vulkan probe of a chain of light kernels, each one dispatch over one 4.4 MiB
|
||||
buffer, the same SPIR-V and the same memory type (type 0, `DEVICE_LOCAL` alone) in every arm,
|
||||
took 125.53 µs a dispatch (median of nine) over an allocation exportable as an opaque file
|
||||
descriptor and 122.95 µs over anonymous host pages imported by pointer
|
||||
(`VK_EXT_external_memory_host`), against 55.73 µs over a plain allocation (Iris Xe RPL-P, Mesa
|
||||
26.2.6). The memory Metal's contract puts in place stays in place (the owner's ruling: zero
|
||||
copy): a no-copy buffer over host pages, a guest's RAM and memory the consumer exports, so a
|
||||
kernel over them is expected to pay this on that device (the runtime's own path over them is not
|
||||
timed). Other devices are not measured for it.
|
||||
- **On RADV, a texture whose rows lie a number of bytes apart that is no multiple of 256 is a
|
||||
shadow where only an image at that pitch would hold it** (`shadowed-texture`, naming the pitch;
|
||||
`WorkCounts::host_texture_shadows_refused_pitch` over host pages and dma-bufs). RADV lays a
|
||||
|
||||
Reference in new issue
Block a user