RUNTIME 2311: ICB records lie in pooled memory where a held pointer import taxes every submission
What: DevicePolicy gains indirect_records (IndirectRecordsPolicy, a runtime
choice no profile carries). Under the default, Untaxed, an indirect command
buffer's records and overflow slots take fresh pages of the runtime's own
(a pointer import held for the buffer's life) only where the device's import
tax check has not found that a held pointer import costs every submission, or
has not answered; where it has (RADV, ANV on i915), they lie in pooled
host-visible memory as the runtime's other buffers do. Under Carried, which
exact_answers() selects, they lie in fresh pages wherever the device imports
host pointers, as before, so a recovery keeps them. A recovery of a taxed
device under the default loses pooled records and rewrites them as a new
buffer's (carry.rs's existing pooled path); the device-recovered notice
already counts such buffers ("N indirect command buffers, M of them whose
records were lost"), as on a device without pointer imports and for
device-local records on discrete GPUs. No new Degradation kind.
Why: on a Radeon 780M (RADV, Mesa 26.2.6, Linux 7.3.3) beside a guest game
whose ICB records were the process's only pointer imports (3 buffers, 19.6 MB),
the submission thread had 5 windows of 65-140 ms in 12 s in which every
amdgpu_cs_ioctl waited in mmu_interval_read_begin or returned EAGAIN (373 of
the run's 382 failed calls, retried at once by libdrm). RADV lists every
imported memory in every CS, amdgpu re-faults every userptr page each CS and
adds the CS fence to every listed BO, so a page migration of one of those
pages (kcompactd, khugepaged, and the runtime's own block making in direct
compaction) waits in amdgpu_hmm_invalidate_gfx for all the process's GPU work
in flight while every submission waits behind it. With no userptr BO listed,
compaction migrates pages without waiting on any fence.
Docs: the FAST-PATHS ledger row (default, switch, the recovery cost, the
measured chain), API.md's device-recovered text, HOWTO's residency section,
fresh_pages.rs, indirect_command_buffer.rs and carry.rs, the conformance
crate's Policy::Exact list. API: signatures blessed, api_surface row,
REFUSALS.md regenerated.
Tests: tests::icb_records_policy (Linux, cpu_icd/gpu): the import tax forced
Holds/Fails; under Untaxed+Holds the records lie in pooled memory, no fresh
pages made, a recovery moves them and its notice counts 1 lost; under
Untaxed+Fails and Carried+Holds in the runtime's own pages, kept, 0 lost. The
translator's fast_paths names the choice, checks it keys no profile and that
exact_answers() takes Carried. icb_carry_race's own-pages cases run on a
Carried device (device_recovery::carried_device), so they assert the carry of
own pages whatever the device's verdict.
RUNTIME_VERSION moves: where records lie and what a recovery keeps change on taxed devices.
New public items: metal2vulkan::device::IndirectRecordsPolicy { Untaxed, Carried } and
DevicePolicy::indirect_records.
Verified, msi m3-max-30127 at cba1ec585a (the fix plus a test-only fix: DevicePolicy is
non-exhaustive, so the tests set the field on a copy):
- clippy -D warnings --all-targets --all-features: metal2vulkan + runtime plain 0, runtime
--cfg m2v_cpu_icd 0;
- translator tests 49/49 (fast_paths with the new choice, its no-profile key and exact_answers
tests, api_surface, api_signatures);
- runtime under cpu_icd on llvmpipe 34/34: icb_records_policy, icb_carry_race, icb_records_home,
indirect_command_buffer*, device_recovery_every_kind, device_recovery_carry.
ICB-RECORDS lines:
- Untaxed with the tax forced Holds: records not in own pages, 0 fresh-page buffers, the
carry moved them, notice "1 of them whose records were lost";
- Untaxed with the tax forced Fails: own pages, 2 fresh-page buffers, kept;
- Carried with the tax forced Holds: own pages, 2, kept.
Workload proof owed: reims's traced loaded-desktop walk on the 780M (per-CS get_user_pages 0, no
-EAGAIN windows).
This commit is contained in:
1 parent
483b4650d1
commit
dfda37628d
18 files changed
+392
-74
No files matched your search
@@ -269,8 +269,8 @@ pub enum Policy {
|
||||
/// `Uncompressed`, `heap_answers` `Metal`, `completion` `Exact`, `batch_order` `Exact`, `render_lowering` `AtCall`,
|
||||
/// `host_page_textures` `Shadow`, `half_chains` `EachOperation`, `pipeline_waits` `Exact`,
|
||||
/// `wide_lines` `Exact`, `extended_range_blits` `Canonical`, `queue_sharing` `PerQueue`,
|
||||
/// `dont_care_colors` `Kept`, `unstored_dont_care_loads` `Cleared`, `vertex_reach` `Exact`
|
||||
/// and `managed_copy_in` `AtCommit`.
|
||||
/// `dont_care_colors` `Kept`, `unstored_dont_care_loads` `Cleared`, `vertex_reach` `Exact`,
|
||||
/// `managed_copy_in` `AtCommit` and `indirect_records` `Carried`.
|
||||
Exact,
|
||||
/// The runtime's own defaults: the fast form of every choice, which is what a consumer runs.
|
||||
Default,
|
||||
|
||||
@@ -56,7 +56,7 @@ use super::Device;
|
||||
use crate::release;
|
||||
use ash::vk;
|
||||
use metal2vulkan::bind::ResidentRange;
|
||||
use metal2vulkan::device::ManagedCopyInPolicy;
|
||||
use metal2vulkan::device::{IndirectRecordsPolicy, ManagedCopyInPolicy};
|
||||
use std::any::Any;
|
||||
use std::mem::ManuallyDrop;
|
||||
use std::ops::Range;
|
||||
@@ -3096,8 +3096,8 @@ impl Device {
|
||||
|
||||
/// A `Shared` buffer of the runtime's own of `length` bytes, all zero, at `placement`, for an
|
||||
/// indirect command buffer's records or the slots past them: in fresh pages of its own at any
|
||||
/// length, whatever a held import costs, where the device takes them, so that a recovery's
|
||||
/// carry keeps its pages and its bytes (`FreshPages::Always`); else where
|
||||
/// length where the device takes them and [`Device::records_take_own_pages`] says so, so that a
|
||||
/// recovery's carry keeps its pages and its bytes (`FreshPages::Records`); else where
|
||||
/// [`zeroed_buffer`](Device::zeroed_buffer) lays such a buffer ([`Buffer::in_own_pages`]
|
||||
/// tells which). Refused as that is.
|
||||
pub(super) fn records_buffer(
|
||||
@@ -3107,11 +3107,24 @@ impl Device {
|
||||
modes: Modes,
|
||||
placement: impl Into<Place>,
|
||||
) -> Result<Buffer, Error> {
|
||||
let of = NewBufferOf::Runtime(FreshPages::Always);
|
||||
let of = NewBufferOf::Runtime(FreshPages::Records);
|
||||
let placed = (placement.into(), None);
|
||||
self.zeroed_buffer_of(call, length, (modes, MemoryClass::Shared), of, placed)
|
||||
}
|
||||
|
||||
/// Whether an indirect command buffer's records made now take fresh pages of the runtime's own
|
||||
/// where the device takes them (`DevicePolicy::indirect_records`): under
|
||||
/// `IndirectRecordsPolicy::Untaxed` (the default) only while the device's check has not found
|
||||
/// that a held pointer import costs every submission (`submit_check.rs`, the import tax:
|
||||
/// RADV and ANV on i915 pay one), as such an import is held for the buffer's life; under
|
||||
/// `IndirectRecordsPolicy::Carried` always, so that a recovery keeps them.
|
||||
pub(super) fn records_take_own_pages(&self) -> bool {
|
||||
match self.compile_device().policy().indirect_records {
|
||||
IndirectRecordsPolicy::Carried => true,
|
||||
_ => !self.pointer_imports_tax_submissions(),
|
||||
}
|
||||
}
|
||||
|
||||
/// A `Private` buffer of the runtime's own of `length` bytes at `placement`, for an indirect
|
||||
/// command buffer's records in device-local memory (`indirect_command_buffer/home.rs`): its
|
||||
/// bytes as placed, no fill noted, as the caller sets every byte before any use. Refused as
|
||||
@@ -3361,21 +3374,26 @@ impl Device {
|
||||
// host-visible one of the runtime's own lies in fresh pages where the device takes them
|
||||
// and its check found a held import adds nothing to its submissions (`fresh_pages.rs`).
|
||||
// The in-place check's buffer of pooled memory lies in neither.
|
||||
// An indirect command buffer's records lie in them at any length, whatever a held import
|
||||
// costs (`FreshPages::Always`).
|
||||
let takes = match fresh {
|
||||
FreshPages::Always => fresh_pages::class_takes_fresh_pages(class),
|
||||
FreshPages::WherePaid | FreshPages::Wherever => {
|
||||
fresh_pages::takes_fresh_pages(size, class)
|
||||
}
|
||||
// An indirect command buffer's records lie in them at any length, as the device's policy
|
||||
// says where a held import costs its submissions (`FreshPages::Records`).
|
||||
let (takes, paid) = match fresh {
|
||||
FreshPages::Records => (
|
||||
fresh_pages::class_takes_fresh_pages(class),
|
||||
self.records_take_own_pages(),
|
||||
),
|
||||
FreshPages::WherePaid => (
|
||||
fresh_pages::takes_fresh_pages(size, class),
|
||||
self.fresh_pages_pay_now(),
|
||||
),
|
||||
FreshPages::Wherever => (fresh_pages::takes_fresh_pages(size, class), true),
|
||||
};
|
||||
let wants_fresh = !of_heap
|
||||
&& !plain
|
||||
&& lead == 0
|
||||
&& takes
|
||||
&& (shared.host_import.as_ref()).is_ok_and(|importer| importer.pointers().is_some())
|
||||
&& (fresh != FreshPages::WherePaid || self.fresh_pages_pay_now());
|
||||
let parks = matches!(fresh, FreshPages::WherePaid | FreshPages::Always);
|
||||
&& paid;
|
||||
let parks = matches!(fresh, FreshPages::WherePaid | FreshPages::Records);
|
||||
let making = (!of_heap && !plain && lead == 0 && parks).then_some(BufferMaking {
|
||||
size,
|
||||
class,
|
||||
@@ -4083,10 +4101,10 @@ enum FreshPages {
|
||||
/// which lies where a rebind's copy under an image in place lies whatever that cost
|
||||
/// (`buffer_descriptor.rs`'s `copied_pages`), and whose import lives only for its round.
|
||||
Wherever,
|
||||
/// Wherever the device takes them, at any length: an indirect command buffer's records and
|
||||
/// slots past them, which a recovery's carry keeps only in the runtime's own pages
|
||||
/// (`indirect_command_buffer/carry.rs`, `fresh_pages.rs`).
|
||||
Always,
|
||||
/// Where the device takes them, at any length, as [`Device::records_take_own_pages`] says: an
|
||||
/// indirect command buffer's records and slots past them, which a recovery's carry keeps
|
||||
/// only in the runtime's own pages (`indirect_command_buffer/carry.rs`, `fresh_pages.rs`).
|
||||
Records,
|
||||
}
|
||||
|
||||
/// What a new buffer's bytes hold as [`Device::placed_new_buffer`] makes it.
|
||||
|
||||
@@ -37,12 +37,21 @@
|
||||
//! (16 us per MiB). An import also costs 17 to 43 us whatever its size, against a pooled
|
||||
//! placement's none.
|
||||
//! - **An indirect command buffer's records** (and its slots past them) lie in fresh pages of
|
||||
//! their own at any length, whatever a held import costs, where the device imports host
|
||||
//! pointers and the class's best type takes them: a device's recovery keeps them only in the
|
||||
//! runtime's own pages, as Metal keeps a buffer's records across its GPU's restart
|
||||
//! (`indirect_command_buffer/carry.rs`). Each such buffer is one more held import, which ANV on
|
||||
//! i915 lists in every execbuffer at about 0.35 us (`submit_check.rs`) and RADV pays by its
|
||||
//! pages.
|
||||
//! their own at any length where the device imports host pointers and the class's best type
|
||||
//! takes them, and either its check found a held import adds nothing to its submissions or has
|
||||
//! not answered, or the device's policy keeps them there whatever that costs
|
||||
//! (`IndirectRecordsPolicy::Carried`, which `DevicePolicy::exact_answers()` selects): a
|
||||
//! device's recovery keeps them only in the runtime's own pages, as Metal keeps a buffer's
|
||||
//! records across its GPU's restart (`indirect_command_buffer/carry.rs`). Each such buffer is
|
||||
//! one more held import, which ANV on i915 lists in every execbuffer at about 0.35 us
|
||||
//! (`submit_check.rs`) and RADV pays by its pages: amdgpu gets every page of each such import
|
||||
//! (a userptr) again in every submission, and a migration of one of its pages by the kernel's
|
||||
//! compaction waits for every fence of the import, all the process's work in flight, while
|
||||
//! every submission of the process waits behind it or fails with `EAGAIN` (a Radeon 780M, Mesa
|
||||
//! 26.2.6, Linux 7.3.3: windows of 65 to 140 ms, the records of a guest's indirect command
|
||||
//! buffers the only pointer imports). So under the default policy
|
||||
//! (`IndirectRecordsPolicy::Untaxed`) a device whose check found the tax lays them in pooled
|
||||
//! host-visible memory, as its other buffers, which a recovery loses (docs/FAST-PATHS.md).
|
||||
//! - **Recycled.** A parked buffer of the same making (`recycle.rs`) is still taken first, and its
|
||||
//! bytes set to zero on the host (0.29 ms for 64 MiB), since its pages hold its last owner's.
|
||||
//! Only a buffer made here reads zero unwritten.
|
||||
@@ -81,7 +90,7 @@ pub(super) fn takes_fresh_pages(size: u64, class: MemoryClass) -> bool {
|
||||
|
||||
/// Whether a buffer in memory of `class` may lie in fresh pages at all, whatever its length: the
|
||||
/// host maps memory of the class, on a system that maps such pages. An indirect command buffer's
|
||||
/// records take them at any length (`buffer.rs`'s `FreshPages::Always`).
|
||||
/// records take them at any length (`buffer.rs`'s `FreshPages::Records`).
|
||||
pub(super) fn class_takes_fresh_pages(class: MemoryClass) -> bool {
|
||||
let host_visible = matches!(
|
||||
class,
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
//! CPU reaching those only through copies (`indirect_command_buffer/home.rs`). The host's
|
||||
//! records, and the slots past them, lie in fresh pages of the runtime's own where the device
|
||||
//! imports host pointers (`fresh_pages.rs`), so that a device's recovery keeps them, as Metal
|
||||
//! keeps a buffer's records across its GPU's restart; elsewhere in pooled memory, which the
|
||||
//! recovery's carry cannot keep (`indirect_command_buffer/carry.rs`).
|
||||
//! keeps a buffer's records across its GPU's restart, but, under the default
|
||||
//! `IndirectRecordsPolicy::Untaxed`, on a device whose check found a held pointer import costs
|
||||
//! every submission (`submit_check.rs`); elsewhere in pooled memory, which the recovery's carry
|
||||
//! cannot keep (`indirect_command_buffer/carry.rs`).
|
||||
//! - **CPU encoding.** [`IndirectCommandBuffer::indirect_compute_command_at`] gives a compute
|
||||
//! command's setters, which write its record as Metal's do (an M3 Max on macOS 26.7 and an M4 on
|
||||
//! 27.0.1): a buffer's address plus its offset's low 32 bits as one address; threadgroup lengths
|
||||
@@ -629,8 +631,8 @@ impl Device {
|
||||
&self.shared().identifiers,
|
||||
metal_allocated_size(descriptor, size),
|
||||
)?;
|
||||
// In the runtime's own pages where the device imports them, so that a recovery keeps
|
||||
// the records (`indirect_command_buffer/carry.rs`).
|
||||
// In the runtime's own pages where the device imports them and its policy takes them,
|
||||
// so that a recovery keeps the records (`indirect_command_buffer/carry.rs`).
|
||||
let storage = self.records_buffer(CALL, length, backing, Place::Records(held.id))?;
|
||||
// The slots past the record's, of their own buffer, as long as Metal's storage grows.
|
||||
let overflow = match (layout, overflow_bytes) {
|
||||
|
||||
@@ -5,12 +5,13 @@
|
||||
//! - **The records.** Its storage, and the buffer of the slots past its records ([`Overflow`]),
|
||||
//! are buffers of the runtime's own whose `contents` pointer no program holds, carried as such
|
||||
//! (`Buffer::carry_runtime`): in the runtime's own pages, where every such buffer lies on a
|
||||
//! device that imports host pointers (`fresh_pages.rs`), the same pages there, the records as
|
||||
//! the CPU and the GPU left them, as Metal keeps them across its GPU's restart; in pooled
|
||||
//! host-visible memory, on a device that imports none or where the import failed, new memory
|
||||
//! there, the records lost with the `VkDevice`, whose memory Vulkan makes undefined (vkspec
|
||||
//! 5.2.3, "Lost Device"), written again as a new buffer's: its header, every command reset, its
|
||||
//! slots past them zero. The CPU's writes of the records under `pipelines` wait for the carry
|
||||
//! device that imports host pointers (`fresh_pages.rs`) but one whose held pointer import
|
||||
//! costs every submission under the default `IndirectRecordsPolicy::Untaxed`, the same pages
|
||||
//! there, the records as the CPU and the GPU left them, as Metal keeps them across its GPU's
|
||||
//! restart; in pooled host-visible memory, on a device that imports none, where the import
|
||||
//! failed, or on such a device under that default, new memory there, the records lost with the
|
||||
//! `VkDevice`, whose memory Vulkan makes undefined (vkspec 5.2.3, "Lost Device"), written again
|
||||
//! as a new buffer's: its header, every command reset, its slots past them zero. The CPU's writes of the records under `pipelines` wait for the carry
|
||||
//! and read the records' bytes under it. A setter's write without it (`Batch`: one that adds
|
||||
//! nothing to what the records may hold) in the runtime's own pages writes the pages the carry
|
||||
//! keeps, whenever it lands; in pooled memory it is waited out before the carry begins, and one
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::{
|
||||
DegradeNotice, Device, DeviceKind, DeviceOptions, Error, EventRef, MessageSink,
|
||||
ResourceOptions, ShaderCacheOptions,
|
||||
};
|
||||
use metal2vulkan::device::VkExtension;
|
||||
use metal2vulkan::device::{DevicePolicy, IndirectRecordsPolicy, VkExtension};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
@@ -54,14 +54,28 @@ impl Drop for Scratch {
|
||||
/// The device the cfg selects: a CPU device under `m2v_cpu_icd`, else a GPU, its shader cache
|
||||
/// in `cache`.
|
||||
pub(super) fn device(cache: &Path) -> Device {
|
||||
device_with(cache, None, &[])
|
||||
device_with(cache, None, &[], DevicePolicy::UNTRUSTED)
|
||||
}
|
||||
|
||||
/// [`device`] whose indirect command buffers' records lie in the runtime's own pages wherever it
|
||||
/// imports host pointers, whatever a held import costs its submissions
|
||||
/// (`IndirectRecordsPolicy::Carried`): records a recovery's carry keeps.
|
||||
pub(super) fn carried_device(cache: &Path) -> Device {
|
||||
let mut policy = DevicePolicy::UNTRUSTED;
|
||||
policy.indirect_records = IndirectRecordsPolicy::Carried;
|
||||
device_with(cache, None, &[], policy)
|
||||
}
|
||||
|
||||
/// [`device`] made without `VK_EXT_external_memory_host` (`DeviceOptions::withheld_extensions`),
|
||||
/// as a device whose driver lists none is: the runtime's own buffers lie in pooled memory, an
|
||||
/// indirect command buffer's records among them, which a recovery's carry moves.
|
||||
pub(super) fn pooled_device(cache: &Path) -> Device {
|
||||
device_with(cache, None, &[VkExtension::ExtExternalMemoryHost])
|
||||
device_with(
|
||||
cache,
|
||||
None,
|
||||
&[VkExtension::ExtExternalMemoryHost],
|
||||
DevicePolicy::UNTRUSTED,
|
||||
)
|
||||
}
|
||||
|
||||
/// The degrade notices a device's sink heard, in order.
|
||||
@@ -69,6 +83,11 @@ pub(super) type Heard = Arc<Mutex<Vec<DegradeNotice>>>;
|
||||
|
||||
/// [`device`], its degrade notices kept in `heard`.
|
||||
pub(super) fn heard_device(cache: &Path, heard: &Heard) -> Device {
|
||||
heard_device_with(cache, heard, DevicePolicy::UNTRUSTED)
|
||||
}
|
||||
|
||||
/// [`heard_device`] of `policy`.
|
||||
pub(super) fn heard_device_with(cache: &Path, heard: &Heard, policy: DevicePolicy) -> Device {
|
||||
let heard = Arc::clone(heard);
|
||||
device_with(
|
||||
cache,
|
||||
@@ -78,12 +97,18 @@ pub(super) fn heard_device(cache: &Path, heard: &Heard) -> Device {
|
||||
}
|
||||
})),
|
||||
&[],
|
||||
policy,
|
||||
)
|
||||
}
|
||||
|
||||
/// [`device`], its messages sent to `messages` where given, made without the extensions
|
||||
/// `withheld`.
|
||||
fn device_with(cache: &Path, messages: Option<MessageSink>, withheld: &[VkExtension]) -> Device {
|
||||
/// [`device`] of `policy`, its messages sent to `messages` where given, made without the
|
||||
/// extensions `withheld`.
|
||||
fn device_with(
|
||||
cache: &Path,
|
||||
messages: Option<MessageSink>,
|
||||
withheld: &[VkExtension],
|
||||
policy: DevicePolicy,
|
||||
) -> Device {
|
||||
let options = DeviceOptions {
|
||||
kinds: match cfg!(m2v_cpu_icd) {
|
||||
true => vec![DeviceKind::Cpu],
|
||||
@@ -99,6 +124,7 @@ fn device_with(cache: &Path, messages: Option<MessageSink>, withheld: &[VkExtens
|
||||
},
|
||||
messages,
|
||||
withheld_extensions: withheld.iter().copied().collect(),
|
||||
policy,
|
||||
..DeviceOptions::default()
|
||||
};
|
||||
Device::system_default_with(&options).unwrap()
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
//!
|
||||
//! - the commands the CPU encoded before it read back and run after it, as Metal keeps a
|
||||
//! buffer's records across its GPU's restart, where the records lie in the runtime's own pages,
|
||||
//! as they do on a device that imports host pointers; and a setter's write without the lock,
|
||||
//! as they do on a device that imports host pointers under `IndirectRecordsPolicy::Carried`
|
||||
//! (and under the default where a held import costs its submissions nothing); and a setter's
|
||||
//! write without the lock,
|
||||
//! held by a hook (`hold_next_set`) inside it while the recovery runs to the end, lands there;
|
||||
//! - on a device that imports none, whose buffers' records lie in pooled memory, which the carry
|
||||
//! moves to new memory and resets: a set held once its batch is made, while the recovery runs to
|
||||
@@ -20,7 +22,7 @@
|
||||
//! the cfg selects (docs/VALIDATION.md). No GPU fault: the loss is marked (`Device::recover_for_test`).
|
||||
//! The function is the owned fixture `examples/runtime_examples.ll` (`llvm-as`).
|
||||
|
||||
use super::device_recovery::{device, pooled_device, Scratch};
|
||||
use super::device_recovery::{carried_device, pooled_device, Scratch};
|
||||
use super::device_recovery_carry::BYTES;
|
||||
use super::device_recovery_live_table::{
|
||||
dispatched, dispatches, encode_command, execute, indirect_state, WORDS,
|
||||
@@ -324,7 +326,7 @@ fn a_recovery_s_carry_waits_for_a_write_without_the_lock() {
|
||||
#[test]
|
||||
fn a_write_held_across_a_recovery_lands_on_the_records_it_keeps() {
|
||||
let scratch = Scratch::new();
|
||||
let device = device(&scratch.0);
|
||||
let device = carried_device(&scratch.0);
|
||||
let compute = indirect_state(&device);
|
||||
let icb = dispatches(&device);
|
||||
let buffers = buffers(&device);
|
||||
@@ -401,13 +403,13 @@ const DRAWS: u64 = 64;
|
||||
/// Metal keeps a buffer's records across its GPU's restart: a compute command encoded whole
|
||||
/// (state, buffers, dispatch) runs, and each of a buffer of draws' commands reads back its two
|
||||
/// vertex and two fragment buffers, nil at offsets of their own, which the setters wrote without
|
||||
/// the lock. The records lie in the runtime's own pages where the device imports host pointers,
|
||||
/// which the carry keeps (`Kept`); in pooled memory it moved them to new memory and reset every
|
||||
/// command (`Lost`), where Metal's are kept.
|
||||
/// the lock. The records lie in the runtime's own pages where the device imports host pointers
|
||||
/// (its policy `IndirectRecordsPolicy::Carried`), which the carry keeps (`Kept`); in pooled memory
|
||||
/// it moved them to new memory and reset every command (`Lost`), where Metal's are kept.
|
||||
#[test]
|
||||
fn a_recovery_keeps_the_commands_the_cpu_encoded() {
|
||||
let scratch = Scratch::new();
|
||||
let device = device(&scratch.0);
|
||||
let device = carried_device(&scratch.0);
|
||||
let compute = indirect_state(&device);
|
||||
let icb = dispatches(&device);
|
||||
let private = || {
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
//! Where an indirect command buffer's records lie as the device's policy says
|
||||
//! (`DevicePolicy::indirect_records`, `buffer.rs`'s `Device::records_take_own_pages`), and what a
|
||||
//! recovery's carry does with them there:
|
||||
//!
|
||||
//! - under the default, `IndirectRecordsPolicy::Untaxed`, on a device whose check found that a
|
||||
//! held host-pointer import costs every submission (the import tax, forced to hold here), the
|
||||
//! records lie in pooled host-visible memory, no fresh pages made for them, and a recovery
|
||||
//! moves them to new memory and resets every command, its notice counting the buffer as one
|
||||
//! whose records were lost;
|
||||
//! - where the tax is forced to fail, and under `IndirectRecordsPolicy::Carried` whatever it
|
||||
//! answers, they lie in fresh pages of the runtime's own, imported by their pointer, which a
|
||||
//! recovery keeps, its notice counting none lost.
|
||||
//!
|
||||
//! Each case prints an `ICB-RECORDS` line: the policy, the verdict, where the records lie, the
|
||||
//! fresh pages made for them and what the carry did.
|
||||
//!
|
||||
//! A device test: compiled only under the validation crate's GPU safety cfgs, on Linux (the forced
|
||||
//! verdict is a Linux test hook), on the kind of device the cfg selects (docs/VALIDATION.md). No
|
||||
//! GPU fault: the loss is marked (`Device::recover_for_test`).
|
||||
|
||||
use super::device_recovery::{heard_device_with, recovery_notices, Heard, Scratch};
|
||||
use super::device_recovery_live_table::dispatches;
|
||||
use crate::submit_check::{Check, Verdict};
|
||||
use crate::Device;
|
||||
use metal2vulkan::device::{DevicePolicy, IndirectRecordsPolicy};
|
||||
use std::time::Duration;
|
||||
|
||||
/// How long a case waits for the device's own submission checks to answer before it forces the
|
||||
/// import tax's verdict over theirs.
|
||||
const SETTLE: Duration = Duration::from_secs(60);
|
||||
|
||||
/// What one case found: whether the records lay in the runtime's own pages, whether the recovery
|
||||
/// kept them there, and the recovery's notice.
|
||||
struct Found {
|
||||
own_pages: bool,
|
||||
kept: bool,
|
||||
notice: String,
|
||||
}
|
||||
|
||||
/// Whether `device` imports host pointers at all: where it does not, the records lie in pooled
|
||||
/// memory under every policy and verdict.
|
||||
fn imports_pointers(device: &Device) -> bool {
|
||||
(device.shared().host_import.as_ref()).is_ok_and(|importer| importer.pointers().is_some())
|
||||
}
|
||||
|
||||
/// An indirect command buffer made on a device of `policy` whose import tax answers `verdict`,
|
||||
/// and that device's recovery: `None` where the device imports no host pointer.
|
||||
fn case(policy: IndirectRecordsPolicy, verdict: Verdict) -> Option<Found> {
|
||||
let scratch = Scratch::new();
|
||||
let heard = Heard::default();
|
||||
let mut device_policy = DevicePolicy::UNTRUSTED;
|
||||
device_policy.indirect_records = policy;
|
||||
let device = heard_device_with(&scratch.0, &heard, device_policy);
|
||||
if !imports_pointers(&device) {
|
||||
eprintln!(
|
||||
"ICB-RECORDS {}: the device imports no host pointer; not run",
|
||||
device.name()
|
||||
);
|
||||
return None;
|
||||
}
|
||||
// The device's own verdicts first, so that none lands over the forced one.
|
||||
device.settle_submit_checks(SETTLE);
|
||||
(device.shared().submit_checks).force(Check::ImportTax, verdict);
|
||||
let before = device.work_counts();
|
||||
let icb = dispatches(&device);
|
||||
let made = device.work_counts();
|
||||
let fresh = made.fresh_page_buffers_made - before.fresh_page_buffers_made;
|
||||
let own_pages = icb.records_in_own_pages();
|
||||
let records = icb.records_address();
|
||||
let from = heard.lock().unwrap().len();
|
||||
device.recover_for_test().unwrap();
|
||||
let kept = icb.records_address() == records;
|
||||
let said = recovery_notices(&heard, from, "the device");
|
||||
assert_eq!(said.len(), 1, "{said:?}");
|
||||
let notice = said[0].clone();
|
||||
eprintln!(
|
||||
"ICB-RECORDS {} {policy:?}, import tax forced {verdict:?}: records in the runtime's own \
|
||||
pages {own_pages}, {fresh} fresh-page buffers made, the carry {}",
|
||||
device.name(),
|
||||
match kept {
|
||||
true => "kept them",
|
||||
false => "moved them",
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
fresh > 0,
|
||||
own_pages,
|
||||
"fresh pages made for the records where, and only where, they lie in them"
|
||||
);
|
||||
Some(Found {
|
||||
own_pages,
|
||||
kept,
|
||||
notice,
|
||||
})
|
||||
}
|
||||
|
||||
/// Under the default, a device whose held pointer import costs every submission lays the records
|
||||
/// in pooled memory, which its recovery loses and announces; where the import costs nothing, in
|
||||
/// the runtime's own pages, which its recovery keeps.
|
||||
#[test]
|
||||
fn records_lie_in_pooled_memory_where_a_held_import_taxes_submissions() {
|
||||
let Some(untaxed) = case(IndirectRecordsPolicy::Untaxed, Verdict::Fails) else {
|
||||
return;
|
||||
};
|
||||
assert!(
|
||||
untaxed.own_pages,
|
||||
"where a held import costs nothing, the records lie in the runtime's own pages"
|
||||
);
|
||||
assert!(
|
||||
untaxed.kept,
|
||||
"the carry keeps records in the runtime's own pages"
|
||||
);
|
||||
assert!(
|
||||
untaxed
|
||||
.notice
|
||||
.contains(", and 1 indirect command buffers, 0 of them whose records were lost"),
|
||||
"{}",
|
||||
untaxed.notice
|
||||
);
|
||||
let taxed = case(IndirectRecordsPolicy::Untaxed, Verdict::Holds).expect("the same device");
|
||||
assert!(
|
||||
!taxed.own_pages,
|
||||
"where a held import costs every submission, the records lie in pooled memory"
|
||||
);
|
||||
assert!(!taxed.kept, "the carry moves records in pooled memory");
|
||||
assert!(
|
||||
taxed
|
||||
.notice
|
||||
.contains(", and 1 indirect command buffers, 1 of them whose records were lost"),
|
||||
"{}",
|
||||
taxed.notice
|
||||
);
|
||||
}
|
||||
|
||||
/// Under `IndirectRecordsPolicy::Carried`, which `DevicePolicy::exact_answers()` selects, the
|
||||
/// records lie in the runtime's own pages whatever a held import costs, and the recovery keeps
|
||||
/// them, as Metal keeps a buffer's records across its GPU's restart.
|
||||
#[test]
|
||||
fn carried_records_lie_in_the_runtime_s_own_pages_whatever_the_tax() {
|
||||
assert_eq!(
|
||||
DevicePolicy::UNTRUSTED.exact_answers().indirect_records,
|
||||
IndirectRecordsPolicy::Carried
|
||||
);
|
||||
let Some(taxed) = case(IndirectRecordsPolicy::Carried, Verdict::Holds) else {
|
||||
return;
|
||||
};
|
||||
assert!(
|
||||
taxed.own_pages,
|
||||
"carried records lie in the runtime's own pages"
|
||||
);
|
||||
assert!(taxed.kept, "the carry keeps them");
|
||||
assert!(
|
||||
taxed
|
||||
.notice
|
||||
.contains(", and 1 indirect command buffers, 0 of them whose records were lost"),
|
||||
"{}",
|
||||
taxed.notice
|
||||
);
|
||||
}
|
||||
@@ -372,6 +372,8 @@ mod icb_carry_race;
|
||||
mod icb_encode_bench;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod icb_records_home;
|
||||
#[cfg(all(any(m2v_gpu, m2v_cpu_icd), target_os = "linux"))]
|
||||
mod icb_records_policy;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod icon_coverage;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
|
||||
Vendored
+1
-1
@@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 522;
|
||||
/// 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 = 2310;
|
||||
pub const RUNTIME_VERSION: u32 = 2311;
|
||||
|
||||
/// 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
|
||||
|
||||
@@ -68,9 +68,9 @@ pub use metal::{MetalDeviceProperties, SimdSupport, StageSimd};
|
||||
pub use policy::{
|
||||
BatchOrderPolicy, CompletionPolicy, ContainmentPolicy, DevicePolicy, DontCareColorPolicy,
|
||||
ExtendedRangeBlitPolicy, HalfChainPolicy, HeapAnswerPolicy, HeapCompressionPolicy,
|
||||
HostPageTexturePolicy, ManagedCopyInPolicy, PipelineWaitPolicy, QueueSharingPolicy,
|
||||
RateMapRegionPolicy, RenderLoweringPolicy, UnsharedIsolationPolicy, UnstoredDontCarePolicy,
|
||||
VertexReachPolicy, WideLinePolicy, YCbCrInPlacePolicy,
|
||||
HostPageTexturePolicy, IndirectRecordsPolicy, ManagedCopyInPolicy, PipelineWaitPolicy,
|
||||
QueueSharingPolicy, RateMapRegionPolicy, RenderLoweringPolicy, UnsharedIsolationPolicy,
|
||||
UnstoredDontCarePolicy, VertexReachPolicy, WideLinePolicy, YCbCrInPlacePolicy,
|
||||
};
|
||||
pub(crate) use profile::whole_point_size;
|
||||
pub use profile::{DeviceProfile, SpirvValidation};
|
||||
|
||||
@@ -8,9 +8,9 @@ use std::time::Duration;
|
||||
/// `completion`, `batch_order`, `render_lowering`, `host_page_textures`, `pipeline_waits`,
|
||||
/// `pipeline_creation_wait`, `pipeline_commit_wait`, `wide_lines`, `extended_range_blits`,
|
||||
/// `queue_sharing`, `unshared_isolation`, `dont_care_colors`, `unstored_dont_care_loads`,
|
||||
/// `vertex_reach`, `rate_map_regions` and `managed_copy_in` can change emitted code, so the profile
|
||||
/// carries it (containment as the encoding it selects) and its fingerprint covers it; those
|
||||
/// eighteen are the runtime's alone (a heap's
|
||||
/// `vertex_reach`, `rate_map_regions`, `managed_copy_in` and `indirect_records` can change emitted
|
||||
/// code, so the profile carries it (containment as the encoding it selects) and its fingerprint
|
||||
/// covers it; those nineteen are the runtime's alone (a heap's
|
||||
/// compressed texture's image, what a heap texture's size query answers, when the host sees a
|
||||
/// command buffer complete, how a batch begins after the earlier ones
|
||||
/// of its queue, where a render encoder's calls are lowered, what holds a sampled texture over host
|
||||
@@ -20,8 +20,9 @@ use std::time::Duration;
|
||||
/// queue's on a `VkQueue` they share, what a colour attachment stored `DontCare` keeps, what a pass
|
||||
/// reads of an attachment it loads `DontCare` and does not store, which draws fetch a vertex
|
||||
/// layout in the shader where the device's fixed-function input would wrap past 4 GiB, how a
|
||||
/// rate-mapped pass's draws reach its regions, and when a `Managed` buffer's GPU copy takes the
|
||||
/// bytes a `didModifyRange:` names), and no profile carries them.
|
||||
/// rate-mapped pass's draws reach its regions, when a `Managed` buffer's GPU copy takes the
|
||||
/// bytes a `didModifyRange:` names, and where an indirect command buffer's records lie on a device
|
||||
/// whose held host-pointer imports cost every submission), and no profile carries them.
|
||||
#[non_exhaustive]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
@@ -149,6 +150,14 @@ pub struct DevicePolicy {
|
||||
/// submission runs (the default), or copied on the CPU at the commit as the host copy holds
|
||||
/// them then. The runtime's choice alone: no emitted code changes.
|
||||
pub managed_copy_in: ManagedCopyInPolicy,
|
||||
/// Where an indirect command buffer's records lie on a device that imports host pointers and
|
||||
/// whose own check found a held pointer import costs every submission (RADV, ANV on i915):
|
||||
/// in pooled host-visible memory, as every other buffer of the runtime's own lies there,
|
||||
/// which a recovery of the device loses (the default), or in pages of the runtime's own
|
||||
/// imported by their pointer, which a recovery keeps, as Metal keeps a buffer's records
|
||||
/// across its GPU's restart. Elsewhere the records lie in the runtime's own pages under
|
||||
/// either. The runtime's choice alone: no emitted code changes.
|
||||
pub indirect_records: IndirectRecordsPolicy,
|
||||
}
|
||||
|
||||
impl DevicePolicy {
|
||||
@@ -166,8 +175,9 @@ impl DevicePolicy {
|
||||
/// cleared where its driver clears it no slower, a vertex layout pulled past a wrapping
|
||||
/// fixed-function input only where the draw's own values reach past 4 GiB, a rate-mapped
|
||||
/// pass's triangles a host step records fanned out to its regions where a probe finds they
|
||||
/// can be, and a `Managed` buffer's named range copied in by the GPU from its host copy as the
|
||||
/// submission runs.
|
||||
/// can be, a `Managed` buffer's named range copied in by the GPU from its host copy as the
|
||||
/// submission runs, and an indirect command buffer's records in pooled memory where a held
|
||||
/// host-pointer import costs the device's every submission.
|
||||
pub const UNTRUSTED: DevicePolicy = DevicePolicy {
|
||||
pointer_domain: PointerDomain::ResidentTable,
|
||||
handle_domain: HandleDomain::Table,
|
||||
@@ -193,6 +203,7 @@ impl DevicePolicy {
|
||||
vertex_reach: VertexReachPolicy::Bounded,
|
||||
rate_map_regions: RateMapRegionPolicy::FanOut,
|
||||
managed_copy_in: ManagedCopyInPolicy::AtSubmission,
|
||||
indirect_records: IndirectRecordsPolicy::Untaxed,
|
||||
};
|
||||
|
||||
/// This policy with Metal's answer wherever the choices offer it: a heap's texture whose bytes
|
||||
@@ -221,8 +232,10 @@ impl DevicePolicy {
|
||||
/// layout a draw may fetch past 4 GiB of its bind offset pulled where the device's
|
||||
/// fixed-function input wraps there, wherever the draw's reach is stated
|
||||
/// ([`VertexReachPolicy::Exact`]), every draw of a rate-mapped pass recorded once per
|
||||
/// region ([`RateMapRegionPolicy::Exact`]), and every `Managed` buffer's named range taken
|
||||
/// on the CPU at the commit ([`ManagedCopyInPolicy::AtCommit`]). Every other field is kept,
|
||||
/// region ([`RateMapRegionPolicy::Exact`]), every `Managed` buffer's named range taken
|
||||
/// on the CPU at the commit ([`ManagedCopyInPolicy::AtCommit`]), and every indirect command
|
||||
/// buffer's records in the runtime's own pages wherever the device imports host pointers,
|
||||
/// which a recovery keeps ([`IndirectRecordsPolicy::Carried`]). Every other field is kept,
|
||||
/// `unshared_isolation` among them: its default is the one nearer Metal's, whose queues do
|
||||
/// not wait for each other's whole command buffers.
|
||||
pub const fn exact_answers(self) -> DevicePolicy {
|
||||
@@ -244,6 +257,7 @@ impl DevicePolicy {
|
||||
vertex_reach: VertexReachPolicy::Exact,
|
||||
rate_map_regions: RateMapRegionPolicy::Exact,
|
||||
managed_copy_in: ManagedCopyInPolicy::AtCommit,
|
||||
indirect_records: IndirectRecordsPolicy::Carried,
|
||||
..self
|
||||
}
|
||||
}
|
||||
@@ -810,3 +824,33 @@ pub enum ManagedCopyInPolicy {
|
||||
/// bytes at each commit.
|
||||
AtCommit,
|
||||
}
|
||||
|
||||
/// Where an indirect command buffer's records (and the slots past them) lie on a device that
|
||||
/// imports host pointers (`VK_EXT_external_memory_host`) and whose own check found that a held
|
||||
/// pointer import adds to the cost of every submission. There such an import is held for the
|
||||
/// buffer's life and listed in every kernel submission: on RADV every imported memory is on every
|
||||
/// submission's list, amdgpu gets every page of each pointer import (a userptr) again in each, and
|
||||
/// a migration of any of those pages by the kernel's compaction waits for every fence of the
|
||||
/// import, so for all the process's work in flight, while every submission of the process waits
|
||||
/// behind it (a Radeon 780M, Mesa 26.2.6, Linux 7.3.3: windows of 65 to 140 ms in which every
|
||||
/// submission waited or failed with `EAGAIN`, with gameload's ICB records the only pointer
|
||||
/// imports). On every other device the records lie in the runtime's own pages under either value.
|
||||
/// The runtime's choice alone: no emitted code changes.
|
||||
#[non_exhaustive]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum IndirectRecordsPolicy {
|
||||
/// In the runtime's own pages imported by their pointer only where a held pointer import
|
||||
/// costs the device's submissions nothing, or its check has not answered (the default); where
|
||||
/// it costs them, in pooled host-visible memory, as the runtime's other buffers lie there. A
|
||||
/// recovery of such a device loses records in pooled memory with the `VkDevice` and writes
|
||||
/// them again as a new buffer's (its header, every command reset), where Metal keeps them;
|
||||
/// its notice counts such buffers (`device-recovered`).
|
||||
#[default]
|
||||
Untaxed,
|
||||
/// In the runtime's own pages imported by their pointer wherever the device imports host
|
||||
/// pointers, whatever a held import costs, so that a recovery keeps the records as the CPU
|
||||
/// and the GPU left them, as Metal does. Its cost, on such a device, is the held import in
|
||||
/// every submission while the buffer lives.
|
||||
Carried,
|
||||
}
|
||||
@@ -8,9 +8,9 @@
|
||||
use crate::device::{
|
||||
BatchOrderPolicy, CompletionPolicy, DevicePolicy, DontCareColorPolicy, ExtendedRangeBlitPolicy,
|
||||
HalfChainPolicy, HeapAnswerPolicy, HeapCompressionPolicy, HostPageTexturePolicy,
|
||||
ManagedCopyInPolicy, PipelineWaitPolicy, QueueSharingPolicy, RateMapRegionPolicy,
|
||||
RenderLoweringPolicy, UnsharedIsolationPolicy, UnstoredDontCarePolicy, VertexReachPolicy,
|
||||
WideLinePolicy, YCbCrInPlacePolicy,
|
||||
IndirectRecordsPolicy, ManagedCopyInPolicy, PipelineWaitPolicy, QueueSharingPolicy,
|
||||
RateMapRegionPolicy, RenderLoweringPolicy, UnsharedIsolationPolicy, UnstoredDontCarePolicy,
|
||||
VertexReachPolicy, WideLinePolicy, YCbCrInPlacePolicy,
|
||||
};
|
||||
use crate::pipeline::PrecisionNote;
|
||||
use std::collections::BTreeSet;
|
||||
@@ -70,8 +70,10 @@ fn choices() -> Vec<Choice> {
|
||||
// queue submits to, how much of other queues' work goes ahead of an unshared queue's, what
|
||||
// a colour attachment stored `DontCare` keeps, what a pass reads of an attachment it loads
|
||||
// `DontCare` and does not store, which draws pull a vertex layout past a wrapping
|
||||
// fixed-function input, how a rate-mapped pass's draws reach its regions, and when a
|
||||
// `Managed` buffer's GPU copy takes the bytes `didModifyRange:` names.
|
||||
// fixed-function input, how a rate-mapped pass's draws reach its regions, when a
|
||||
// `Managed` buffer's GPU copy takes the bytes `didModifyRange:` names, and where an
|
||||
// indirect command buffer's records lie where a held pointer import costs every
|
||||
// submission.
|
||||
heap_compression: _,
|
||||
heap_answers: _,
|
||||
completion: _,
|
||||
@@ -90,6 +92,7 @@ fn choices() -> Vec<Choice> {
|
||||
vertex_reach: _,
|
||||
rate_map_regions: _,
|
||||
managed_copy_in: _,
|
||||
indirect_records: _,
|
||||
// The translator's: how a `half` chain rounds without `shaderFloat16`, and how planes of a
|
||||
// two-plane YCbCr texture read in place are sampled.
|
||||
half_chains: _,
|
||||
@@ -114,6 +117,7 @@ fn choices() -> Vec<Choice> {
|
||||
choice!(p.vertex_reach: VertexReachPolicy { Bounded, Exact }),
|
||||
choice!(p.rate_map_regions: RateMapRegionPolicy { FanOut, Exact }),
|
||||
choice!(p.managed_copy_in: ManagedCopyInPolicy { AtSubmission, AtCommit }),
|
||||
choice!(p.indirect_records: IndirectRecordsPolicy { Untaxed, Carried }),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -818,6 +822,40 @@ fn exact_answers_take_a_managed_range_at_the_commit() {
|
||||
);
|
||||
}
|
||||
|
||||
/// The runtime's choice of where an indirect command buffer's records lie on a device whose held
|
||||
/// pointer imports cost every submission (`indirect_records`) moves no committed profile's
|
||||
/// fingerprint: no profile carries it.
|
||||
#[test]
|
||||
fn the_runtime_s_indirect_records_choice_keys_no_profile() {
|
||||
use crate::spirv::testing::committed_profiles_with;
|
||||
let untaxed = committed_profiles_with(DevicePolicy::UNTRUSTED).expect("profiles");
|
||||
let carried = committed_profiles_with(DevicePolicy {
|
||||
indirect_records: IndirectRecordsPolicy::Carried,
|
||||
..DevicePolicy::UNTRUSTED
|
||||
})
|
||||
.expect("profiles");
|
||||
assert_eq!(untaxed.len(), carried.len());
|
||||
for ((stem, u), (other, c)) in untaxed.iter().zip(&carried) {
|
||||
assert_eq!(stem, other);
|
||||
assert_eq!(u.fingerprint(), c.fingerprint(), "{stem}");
|
||||
}
|
||||
}
|
||||
|
||||
/// `DevicePolicy::exact_answers()` keeps every indirect command buffer's records in the runtime's
|
||||
/// own pages wherever the device imports host pointers, which a recovery keeps, and the default
|
||||
/// lays them in pooled memory where a held pointer import costs every submission.
|
||||
#[test]
|
||||
fn exact_answers_keep_indirect_records_in_the_runtime_s_own_pages() {
|
||||
assert_eq!(
|
||||
DevicePolicy::UNTRUSTED.indirect_records,
|
||||
IndirectRecordsPolicy::Untaxed
|
||||
);
|
||||
assert_eq!(
|
||||
DevicePolicy::UNTRUSTED.exact_answers().indirect_records,
|
||||
IndirectRecordsPolicy::Carried
|
||||
);
|
||||
}
|
||||
|
||||
/// The ledger's row of the pipeline waits states each bound as the default policy sets it, as
|
||||
/// `field = N s`: a changed bound changes its row.
|
||||
#[test]
|
||||
|
||||
@@ -1516,6 +1516,7 @@ enum metal2vulkan::device::HeapAnswerPolicy #[cfg_attr(feature = "serde", derive
|
||||
enum metal2vulkan::device::HeapCompressionPolicy #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum HeapCompressionPolicy
|
||||
enum metal2vulkan::device::HostPageTexturePolicy #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum HostPageTexturePolicy
|
||||
enum metal2vulkan::device::Independence #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum Independence
|
||||
enum metal2vulkan::device::IndirectRecordsPolicy #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum IndirectRecordsPolicy
|
||||
enum metal2vulkan::device::ManagedCopyInPolicy #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum ManagedCopyInPolicy
|
||||
enum metal2vulkan::device::PipelineWaitPolicy #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum PipelineWaitPolicy
|
||||
enum metal2vulkan::device::PointerDomain #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum PointerDomain
|
||||
@@ -4512,6 +4513,7 @@ field metal2vulkan::device::DevicePolicy.handle_domain pub handle_domain: Handle
|
||||
field metal2vulkan::device::DevicePolicy.heap_answers pub heap_answers: HeapAnswerPolicy
|
||||
field metal2vulkan::device::DevicePolicy.heap_compression pub heap_compression: HeapCompressionPolicy
|
||||
field metal2vulkan::device::DevicePolicy.host_page_textures pub host_page_textures: HostPageTexturePolicy
|
||||
field metal2vulkan::device::DevicePolicy.indirect_records pub indirect_records: IndirectRecordsPolicy
|
||||
field metal2vulkan::device::DevicePolicy.isolation pub isolation: GuestIsolation
|
||||
field metal2vulkan::device::DevicePolicy.managed_copy_in pub managed_copy_in: ManagedCopyInPolicy
|
||||
field metal2vulkan::device::DevicePolicy.pipeline_commit_wait pub pipeline_commit_wait: Duration
|
||||
@@ -13797,6 +13799,8 @@ variant metal2vulkan::device::HostPageTexturePolicy::Shadow Shadow
|
||||
variant metal2vulkan::device::Independence::All All
|
||||
variant metal2vulkan::device::Independence::None None
|
||||
variant metal2vulkan::device::Independence::Only32Bit Only32Bit
|
||||
variant metal2vulkan::device::IndirectRecordsPolicy::Carried Carried
|
||||
variant metal2vulkan::device::IndirectRecordsPolicy::Untaxed Untaxed
|
||||
variant metal2vulkan::device::ManagedCopyInPolicy::AtCommit AtCommit
|
||||
variant metal2vulkan::device::ManagedCopyInPolicy::AtSubmission AtSubmission
|
||||
variant metal2vulkan::device::PipelineWaitPolicy::Bounded Bounded
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -247,6 +247,7 @@ surface! {
|
||||
enum VertexReachPolicy N;
|
||||
enum RateMapRegionPolicy N;
|
||||
enum ManagedCopyInPolicy N;
|
||||
enum IndirectRecordsPolicy N;
|
||||
struct DeviceProfile O;
|
||||
struct SpirvValidation N;
|
||||
struct EnabledCaps N;
|
||||
|
||||
+7
-3
@@ -4003,9 +4003,13 @@ bound.
|
||||
whatever that memory holds, and of a texture of `new_texture` or of a `Private` heap of any
|
||||
storage mode (it reads as a new one) but a texture buffer over its texels' buffer carried, a
|
||||
heap over the caller's memory and what is placed in it reading the same pages, and of an indirect
|
||||
command buffer's records on a device that imports no host pointer, or where their import failed
|
||||
(every command reset; the notice counts such buffers), where Metal's are kept, as they are in
|
||||
the runtime's own pages everywhere else; the other objects
|
||||
command buffer's records on a device that imports no host pointer, where their import failed,
|
||||
or, under the default `DevicePolicy::indirect_records = IndirectRecordsPolicy::Untaxed`, on a
|
||||
device whose check found a held host-pointer import costs every submission (RADV, ANV on i915),
|
||||
where they lie in pooled memory (every command reset; the notice counts such buffers), where
|
||||
Metal's are kept, as they are in the runtime's own pages everywhere else and under
|
||||
`IndirectRecordsPolicy::Carried`, which `exact_answers()` selects (docs/FAST-PATHS.md); the
|
||||
other objects
|
||||
made before it are refused (`MadeBeforeRecovery`), where Metal's go on; the calls during it wait
|
||||
for it, and a device call the loss met while it ran runs again after it. A no-copy buffer is
|
||||
made again over
|
||||
|
||||
@@ -49,6 +49,7 @@ three consumer pipelines: A2X (`a2x-s4`, `a2x-s96`), Xgc14 (`xgc14-bgra8`) and X
|
||||
| A vertex buffer layout a draw fetches in fixed function, on a driver whose fixed-function vertex input takes an element's displacement modulo `2^32` (`RuntimeDriverDefect::VertexFetchWrapsPast4GiB`: lavapipe), where the draw's indices (`uint` indices, a per-vertex layout) or its indirect arguments (any layout but a constant one) state how far it fetches: the layout keeps the fixed-function fetch, so an element `2^32` bytes or more past the buffer's bind offset reads the bytes at its displacement's low 32 bits, where Metal reads zero past a buffer that ends before them (`render/vertex_reach.rs`). A layout whose reach the draw's own values bound (its last vertex without indices, `65535` plus its base vertex with `ushort` indices, its base instance plus its last instance over the step rate) is pulled where that reach passes `2^32`, under either value, and reads zero. Other drivers read zero (RADV on the 780M, MoltenVK 1.4.2: `runtime_lane::far_vertex_fetches`). | `vertex_reach = VertexReachPolicy::Bounded` | `vertex_reach = VertexReachPolicy::Exact`: such a layout is pulled too, wherever its stride and furthest attribute could reach past `2^32` from the largest index or argument (on lavapipe, every `uint`-indexed draw's per-vertex layout of a stride above 0, and every indirect draw's layout but a constant one), the plan's pulled-vertex-buffer variant (`WorkCounts::far_vertex_fetch_pulled_draws`) | Under `Bounded`, on lavapipe, an element of such a draw at or past `2^32` reads the wrapped bytes: the conformance case `vertex-fetch-past-4gib-small-buffer` replayed under the default policy differs in 8 elements (its two far `uint`-indexed draws at stride 4), and passes under `Exact`. `VertexFetchMayWrap` (`vertex-fetch-may-wrap`), once per device, for a draw left so; `runtime_lane::far_vertex_fetches` (both values) | Measured on lavapipe (Mesa 26.2.4, LLVM 23.1.1) on a Core Ultra 9 275HX shared with other jobs (`runtime_lane::far_vertex_fetches::far_reach_costs`): a state drawn without indices and then with `uint` indices makes one pipeline under `Bounded` and two under `Exact`, the pulled variant made at the first `uint`-indexed draw; a pass of one draw of 65,536 `uint`-indexed points, from the encoder's making to the wait's return, takes 2.3 to 2.8 times as long pulled (medians of 20 passes: 0.94 against 2.41 ms beside two builds, 3.5 to 4.8 against 9.7 to 12.0 ms at a load average of 59 on 24 threads). On every other driver neither value changes a draw |
|
||||
| A draw of triangles in a rasterization-rate-mapped pass that a host step records (an execution whose records the GPU writes or whose range a buffer holds), filled, of one amplification, without a compensation or a band, whose pipeline chooses no slice or viewport and writes no memory from its vertex function, over a map whose layers are alike and whose plan is a grid of at most 128 columns and rows, on a device that enables `geometryShader`, `shaderClipDistance` and `vertexPipelineStoresAndAtomics`, is drawn once and fanned out to the regions its triangles touch (`rate_mapped_pass.rs`, **Fan-out**): its variant's geometry stage emits a copy of each triangle for each region it touches, at most the copies the device's `maxGeometryTotalOutputComponents` allows up to 16, through one viewport over the render area, four clip distances keeping each copy to its region's pixels, where Metal shades each region through its own viewport. A probe recorded before the pass, submitted and waited for, flags a draw a triangle of which crosses `w = 0` or touches more regions than the copies, with the first and the last such triangle: a flagged list of triangles of one instance whose pipeline reads no `[[primitive_id]]` and writes no memory is drawn in parts in its place, its runs of blocks of 64 triangles that hold a flagged one region by region (the probe sets each flagged triangle's block's bit, `bind::fan_out::BLOCK_TRIANGLES`), each run only into the regions its blocks' bounds reach (the probe raises in a block's word the buckets of segments, 16 an axis, that each of its triangles' widened bounds reach, a triangle crossing `w = 0` by its part where `w` is positive: its vertices of positive `w`, unbounded on each side an edge crosses `w = 0`, a subgroup's triangles raising each word once where the device runs subgroup operations in the geometry stage, else each triangle its own; `bind::fan_out::PROBE_BOUNDS_AT`), cut to the first and the last flagged triangle, runs fewer than 170 triangles apart joined (`rate_mapped_pass::RUN_GAP`, what a region draw costs beyond its vertices) and at most four a draw, the nearest joined first, and the triangles before, between and after them fanned out (`render/fan_out.rs`, **Parts**), and another flagged draw region by region; and marks a draw a triangle of which it does not flag touches more than four (`bind::fan_out::FEW_COPIES`): a draw it marks none of, and a flagged draw's parts fanned out, is drawn through the variant of four copies, whose geometry stage declares the output of fewer vertices, the three variants (the probe's, four copies and the most) begun at `commit`; it stops at a command's barrier and after a draw that writes memory. On such a device that also enables `multiViewport`, `shaderOutputViewportIndex` and `shaderDrawParameters`, every other draw of the pass the variant takes (the encoder's own, the commands `commit` records, those the probe does not probe or whose step does not probe, a flagged draw's runs and a flagged draw drawn whole) is drawn region by region through its region-copy variant (`render/fan_out.rs`, **Region-copy variant**): no geometry stage, its vertex function putting each vertex in its region by the instructions that put a fanned-out copy's (`pipeline::link::fan_out::region_copy`), decorated `NoContraction`, its `Position` and `ClipDistance` `Invariant` (no rounding mode is forced), a recording per region or per as many regions as a direct draw's multi-draw takes, each pushing its first region, the vertex function storing its draw's index as `ViewportIndex`, every viewport the recording sets the fan-out's over the render area and the scissor at a draw's index its region's (`bind::fan_out::scissors`; Vulkan's viewport transform is determined by the selected viewport's extent, centre and depth range, *Controlling the Viewport*), so every route of the pass puts a vertex in a region at one window position and a later pass's `Equal` depth test meets the depth another route stored. A copy's window coordinates are the region viewport's computed in the geometry stage, so a pixel centre within a rounding error of a triangle's edge may be covered under one policy and not the other | `rate_map_regions = RateMapRegionPolicy::FanOut` | `rate_map_regions = RateMapRegionPolicy::Exact`: every draw recorded once per region of the map's plan, each through its own viewport and scissor, its vertex function run once per region | No note of its own: the map's creation announces the pass as a near-equivalent (`rasterization-rate-map`). `WorkCounts::rate_map_probes`, `rate_map_flagged_draws` and `rate_map_fanned_draws` count the probes, the draws they flagged and the draws fanned out whole, `rate_map_fanned_few_draws` the fanned-out draws of four copies, `rate_map_parted_draws` the flagged draws drawn in parts, `rate_map_region_runs` their runs drawn region by region and `rate_map_parted_region_triangles` those runs' triangles, `rate_map_run_region_draws` the regions tLine truncated
|
||||
| A `Managed` buffer's range that `did_modify_range` names, on a device without unified memory (two copies: the runtime's own host copy, or the caller's pages through their import, `managed.rs`, `managed_copy.rs`), is copied into the GPU's copy by the GPU as the submission of the next command buffer committed that uses the buffer runs, from the host copy as it holds the range then: no copy on the CPU and no staging (pages no import of their own maps are staged by the CPU at the commit under either value, but those a guest RAM's chunk imports hold all of, which the GPU copies from those imports: `WorkCounts::managed_bytes_copied_in_from_ram`, `managed_bytes_staged_in`). Macs differ on a CPU write of the range after the commit, before the GPU runs the command buffer: an AMD Radeon Pro 5300M (two copies, macOS 26.7.1) read the bytes at the commit, an Intel UHD Graphics 630 (one copy) read the later write (steps A,B,B,A,B against A,B,B,B,B; `runtime_lane::device_copies`), so the cheaper answer is the default. | `managed_copy_in = ManagedCopyInPolicy::AtSubmission` | `managed_copy_in = ManagedCopyInPolicy::AtCommit`: the commit takes the range as the host copy holds it then, by a CPU copy into staging buffers of host-cached system memory, freed once the submission that copies them in completed (at most 256 MiB staged ahead); a write after the commit reaches no command buffer committed before it, the 5300M's answer | A CPU write after the commit, before the GPU runs the command buffer, may be read. No notice: both answers are a Mac's. `tests::managed_copy_device`'s `ranges_named_*` (the default: each round reads its own bytes or those written after its commit, never an earlier round's; `AtCommit`: its own alone) and `runtime_lane::device_copies`'s `a_did_modify_range_reaches_the_bytes_the_next_commit_finds` (step 4 reads either answer) and `exact_answers_take_a_did_modify_range_at_the_commit` (step 4 reads the bytes at the commit) | A CPU copy of each range at the commit into system memory, which the commit waits for. `tests::managed_copy_device::managed_copy_in_bench` (`MANAGED-COPY-IN`, medians of 40 commits of 32 MiB each, two rounds, over the runtime's own buffer and the caller's pages): RTX 3090 (an eGPU, NVIDIA 620.70.06) `AtSubmission` commit 0.034 to 0.045 ms and 17.3 to 17.7 ms to the completion, `AtCommit` 1.8 to 2.9 ms and 19.2 to 20.2 ms; RX 7900 XTX (RADV, Mesa 26.2.6) `AtSubmission` 0.012 to 0.036 ms and 5.1 to 5.5 ms, `AtCommit` 1.9 to 2.2 ms and 7.1 to 7.5 ms. Memory: the staged ranges until their submission completed, in buffers the device parks and takes again |
|
||||
| An indirect command buffer's records, and the slots past them, on a device that imports host pointers and whose own check found that a held pointer import costs every submission (`submit_check.rs`'s import tax: RADV, ANV on i915), lie in pooled host-visible memory, as every other buffer of the runtime's own does there (`buffer.rs`'s `Device::records_take_own_pages`), not in pages of the runtime's own imported by their pointer and held for the buffer's life. On RADV such an import is an amdgpu userptr listed in every kernel submission (RADV lists every imported memory in each), whose every page the kernel gets again in each, and the kernel's compaction or `khugepaged` migrating one of its pages waits for every fence of the import, all the process's work in flight, while every submission of the process waits behind it or fails with `EAGAIN` and is made again at once. On every other device, and before the check answers, the records lie in the runtime's own pages under either value. | `indirect_records = IndirectRecordsPolicy::Untaxed` | `indirect_records = IndirectRecordsPolicy::Carried`: the records lie in the runtime's own pages wherever the device imports host pointers, whatever a held import costs, as before | A recovery of such a device loses the records with the `VkDevice` and writes them again as a new buffer's (its header, every command reset, its slots past them zero), where Metal keeps a buffer's records across its GPU's restart: as on a device that imports no host pointer and for records in device-local memory on a discrete GPU. The recovery's notice counts such buffers (`device-recovered`: "N indirect command buffers, M of them whose records were lost"). `tests::icb_records_policy` (records in pooled memory under the default where the tax is forced to hold, in the runtime's own pages under `Carried` and where it is forced to fail, and a recovery's carry `Lost` against `Kept`) | A held pointer import for each live indirect command buffer in every submission. Measured on a Radeon 780M (RADV, Mesa 26.2.6, Linux 7.3.3), a guest desktop beside a guest game whose indirect command buffers' records were the process's only pointer imports (3 buffers, 19.6 MB): 5 windows of 65 to 140 ms in 12 s in which the submission thread's every `amdgpu_cs_ioctl` waited in `mmu_interval_read_begin` or returned `EAGAIN` (373 of the run's 382 failed calls), behind `kcompactd`, `khugepaged` and the runtime's own block allocation compacting memory, each waiting in `amdgpu_hmm_invalidate_gfx` for the import's fences. The probe of `submit_check.rs`: 10.3 us more a submission for one 16 MiB pointer import on the 780M, 45.8 on the RX 550 |
|
||||
|
||||
All at once: `DevicePolicy::exact_answers()` sets every switch above; each row states its own cost.
|
||||
|
||||
|
||||
+11
-4
@@ -343,10 +343,17 @@ released:
|
||||
and cost the next blit an import.
|
||||
|
||||
An indirect command buffer's records, and the slots past them, lie in an import of the runtime's
|
||||
own pages wherever the device imports host pointers, whatever the import tax, held for the
|
||||
buffer's life and never released: a device's recovery keeps the records only there, as Metal keeps
|
||||
them across its GPU's restart. Each live indirect command buffer is so one more held import, about
|
||||
0.35 us a submission on ANV on i915 (the tax check's measure) and by its pages on RADV.
|
||||
own pages where the device imports host pointers and no held import costs its submissions (or its
|
||||
check has not answered), held for the buffer's life and never released: a device's recovery keeps
|
||||
the records only there, as Metal keeps them across its GPU's restart. Where the import tax holds
|
||||
(RADV, ANV on i915), they lie in pooled host-visible memory by default, as the runtime's other
|
||||
buffers do, so a recovery resets their commands: on RADV each such import is a userptr whose every
|
||||
page amdgpu gets again in each submission, and the kernel's compaction migrating one of its pages
|
||||
waits for all the process's work in flight while every submission waits behind it (windows of 65
|
||||
to 140 ms on a Radeon 780M). `DevicePolicy::indirect_records = IndirectRecordsPolicy::Carried`
|
||||
(which `exact_answers()` selects) keeps them in the runtime's own pages there too, each live
|
||||
indirect command buffer one more held import, about 0.35 us a submission on ANV on i915 (the tax
|
||||
check's measure) and by its pages on RADV.
|
||||
|
||||
A buffer stays imported for good once its Metal address is handed out (`gpu_address`, a binding, an
|
||||
argument buffer or table, an indirect command buffer, `use_resource`), its `VkBuffer` is read, a
|
||||
|
||||
Reference in new issue
Block a user