Stores by address are bounded: title buffers take the builder's only where it was given them to write
A directory entry says whether stores by address reach its page (translator and host). Faults take at most 128 pages a frame and 8,192 in all; every slot of the copies' run holds a null view until its copy is there; a page is looked at once a frame. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
5b2af05e9a
commit
fbe8ecc617
6 files changed
+136
-46
No files matched your search
@@ -1061,6 +1061,16 @@ impl State {
|
|||||||
h => crate::descriptor::heap(h as This).host(),
|
h => crate::descriptor::heap(h as This).host(),
|
||||||
}?;
|
}?;
|
||||||
let (mut addresses, mut constants) = (Vec::new(), Vec::new());
|
let (mut addresses, mut constants) = (Vec::new(), Vec::new());
|
||||||
|
// (What it may write: its root views of unordered access.)
|
||||||
|
let written: Vec<u64> = t
|
||||||
|
.used
|
||||||
|
.iter()
|
||||||
|
.filter(|u| u.kind == ResourceType::Uav && u.root == RootType::Descriptor)
|
||||||
|
.filter_map(|u| match self.roots_ref(compute).get(usize::from(u.slot)) {
|
||||||
|
Some(&Root::View(address)) => Some(address),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
for root in self.roots_ref(compute) {
|
for root in self.roots_ref(compute) {
|
||||||
match root {
|
match root {
|
||||||
// (Of a program that only walks structures, the structures'
|
// (Of a program that only walks structures, the structures'
|
||||||
@@ -1075,7 +1085,7 @@ impl State {
|
|||||||
addresses.push(self.view_address(compute, u.slot, u.dword));
|
addresses.push(self.view_address(compute, u.slot, u.dword));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
crate::memory::ready(list, heap, &addresses, &constants, use_)
|
crate::memory::ready(list, heap, &addresses, &written, &constants, use_)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The bound heap holding `handle`.
|
/// The bound heap holding `handle`.
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
//! stage, so before one of its dispatches the host makes ready what it can
|
//! stage, so before one of its dispatches the host makes ready what it can
|
||||||
//! see the dispatch name:
|
//! see the dispatch name:
|
||||||
//!
|
//!
|
||||||
//! - 1 MiB from each root view outside buffers, and where title memory has a
|
//! - 256 KiB from each root view outside buffers, and where title memory has a
|
||||||
//! packed ("dehydrated") structure there, all of it: the title ships its
|
//! packed ("dehydrated") structure there, all of it: the title ships its
|
||||||
//! structures packed, and the builder's rehydration stages unpack each in
|
//! structures packed, and the builder's rehydration stages unpack each in
|
||||||
//! place once it is streamed in;
|
//! place once it is streamed in;
|
||||||
@@ -53,6 +53,11 @@
|
|||||||
//! card holds them unpacked (run light-3: a quarter of the structures
|
//! card holds them unpacked (run light-3: a quarter of the structures
|
||||||
//! unpacked a second time, into garbage all over their neighbours).
|
//! unpacked a second time, into garbage all over their neighbours).
|
||||||
//!
|
//!
|
||||||
|
//! **Stores are bounded**: a structure the builder misreads makes it store
|
||||||
|
//! anywhere. Pages of title buffers take its stores only once one of its
|
||||||
|
//! dispatches was given that buffer as an unordered access view (its scratch
|
||||||
|
//! memory, its results); what else a store reaches is an arena's.
|
||||||
|
//!
|
||||||
//! shortcut: a page is kept for the rest of the run.
|
//! shortcut: a page is kept for the rest of the run.
|
||||||
//! shortcut: pages a list does not name are looked at again in turn, over
|
//! shortcut: pages a list does not name are looked at again in turn, over
|
||||||
//! [`SWEEP`] frames.
|
//! [`SWEEP`] frames.
|
||||||
@@ -60,7 +65,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use victory_shader::emit::{MEMORY_FAULTS, MEMORY_PAGES};
|
use victory_shader::emit::{MEMORY_FAULTS, MEMORY_PAGES, MEMORY_READ_ONLY};
|
||||||
use windows::Win32::Graphics::Direct3D12::*;
|
use windows::Win32::Graphics::Direct3D12::*;
|
||||||
|
|
||||||
use crate::descriptor::host::HostHeap;
|
use crate::descriptor::host::HostHeap;
|
||||||
@@ -84,14 +89,17 @@ const PACKED: u64 = 64 << 20;
|
|||||||
/// A packed structure not named for so many frames is another one.
|
/// A packed structure not named for so many frames is another one.
|
||||||
const AGAIN: u64 = 8;
|
const AGAIN: u64 = 8;
|
||||||
/// From a root view; from an address in constants.
|
/// From a root view; from an address in constants.
|
||||||
const VIEW: u64 = 1 << 20;
|
const VIEW: u64 = 256 << 10;
|
||||||
const BUILT: u64 = 4 << 20;
|
const BUILT: u64 = 4 << 20;
|
||||||
/// The biggest title buffer whose builder results come back.
|
/// The biggest title buffer whose builder results come back.
|
||||||
const BACK: u64 = 256 << 10;
|
const BACK: u64 = 256 << 10;
|
||||||
/// Pages taken from the faults of one frame, at most.
|
/// Pages taken from the faults, of one frame and in all, at most: a ray in a
|
||||||
const FAULTS: usize = 2048;
|
/// structure that is not right goes anywhere, and 2,048 a frame took all the
|
||||||
|
/// pages there are in the first seconds (run light-4).
|
||||||
|
const FAULTS: usize = 128;
|
||||||
|
const FAULTS_ALL: usize = 8192;
|
||||||
/// Frames over which every page is looked at once.
|
/// Frames over which every page is looked at once.
|
||||||
const SWEEP: usize = 32;
|
const SWEEP: usize = 128;
|
||||||
|
|
||||||
/// What a draw or dispatch does with title memory by address.
|
/// What a draw or dispatch does with title memory by address.
|
||||||
#[derive(Clone, Copy, PartialEq)]
|
#[derive(Clone, Copy, PartialEq)]
|
||||||
@@ -109,6 +117,8 @@ struct Held {
|
|||||||
copy: usize,
|
copy: usize,
|
||||||
/// The write-watch asking after which it was last taken (0: never).
|
/// The write-watch asking after which it was last taken (0: never).
|
||||||
taken: u64,
|
taken: u64,
|
||||||
|
/// The frame it was last looked at in.
|
||||||
|
looked: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Memory {
|
struct Memory {
|
||||||
@@ -131,6 +141,10 @@ struct Memory {
|
|||||||
windows: usize,
|
windows: usize,
|
||||||
/// Packed structures the builder came to: the frame it last did.
|
/// Packed structures the builder came to: the frame it last did.
|
||||||
packed: HashMap<u64, u64>,
|
packed: HashMap<u64, u64>,
|
||||||
|
/// Copies of title buffers the builder may store in.
|
||||||
|
open: std::collections::HashSet<usize>,
|
||||||
|
/// Pages taken from faults.
|
||||||
|
faulted: usize,
|
||||||
/// Per host view heap (by address): the first slot of its run, and how
|
/// Per host view heap (by address): the first slot of its run, and how
|
||||||
/// many copies have their view there.
|
/// many copies have their view there.
|
||||||
heaps: HashMap<usize, (u32, u32)>,
|
heaps: HashMap<usize, (u32, u32)>,
|
||||||
@@ -199,6 +213,8 @@ impl Memory {
|
|||||||
sweep: 0,
|
sweep: 0,
|
||||||
windows: 0,
|
windows: 0,
|
||||||
packed: HashMap::new(),
|
packed: HashMap::new(),
|
||||||
|
open: Default::default(),
|
||||||
|
faulted: 0,
|
||||||
heaps: HashMap::new(),
|
heaps: HashMap::new(),
|
||||||
frame: u64::MAX,
|
frame: u64::MAX,
|
||||||
refused: Default::default(),
|
refused: Default::default(),
|
||||||
@@ -221,7 +237,7 @@ impl Memory {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
// SAFETY: an entry of the directory.
|
// SAFETY: an entry of the directory.
|
||||||
(unsafe { self.entry(page).read() } as usize).checked_sub(1)
|
((unsafe { self.entry(page).read() } & !MEMORY_READ_ONLY) as usize).checked_sub(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether `page` can be given a place: in the directory, not turned down
|
/// Whether `page` can be given a place: in the directory, not turned down
|
||||||
@@ -293,12 +309,15 @@ impl Memory {
|
|||||||
let entry = self.entry(at / PAGE);
|
let entry = self.entry(at / PAGE);
|
||||||
// SAFETY: an entry of the directory.
|
// SAFETY: an entry of the directory.
|
||||||
if unsafe { entry.read() } == 0 {
|
if unsafe { entry.read() } == 0 {
|
||||||
fill(entry, n, at - first);
|
close(entry, n, at - first);
|
||||||
}
|
}
|
||||||
at += PAGE;
|
at += PAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fill(self.entry(page), n, start - shadow.span().0);
|
// SAFETY: as above.
|
||||||
|
if unsafe { self.entry(page).read() } == 0 {
|
||||||
|
close(self.entry(page), n, start - shadow.span().0);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Small title buffers in it: what the builder stores in them comes
|
// Small title buffers in it: what the builder stores in them comes
|
||||||
@@ -336,12 +355,34 @@ impl Memory {
|
|||||||
};
|
};
|
||||||
let offset = self.used * PAGE;
|
let offset = self.used * PAGE;
|
||||||
self.used += 1;
|
self.used += 1;
|
||||||
self.pages.insert(page, Held { at: arena + offset as usize, copy, taken: 0 });
|
self.pages.insert(page, Held { at: arena + offset as usize, copy, taken: 0, looked: u64::MAX });
|
||||||
self.order.push(page);
|
self.order.push(page);
|
||||||
fill(self.entry(page), copy, offset);
|
fill(self.entry(page), copy, offset);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A dispatch of the builder was given `address` to write: if it is in a
|
||||||
|
/// title buffer's copy, stores by address reach that from here on.
|
||||||
|
fn opens(&mut self, address: u64) {
|
||||||
|
let Some(n) = self.map(address / PAGE).then(|| self.copy_of(address / PAGE)).flatten() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if self.pages.contains_key(&(address / PAGE)) || !self.open.insert(n) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let (first, len) = self.copies[n].span();
|
||||||
|
tracing::info!(
|
||||||
|
start = format_args!("{first:#x}"),
|
||||||
|
len,
|
||||||
|
"title memory by address: the structure builder may store in a title buffer"
|
||||||
|
);
|
||||||
|
for page in first.div_ceil(PAGE)..(first + len) / PAGE {
|
||||||
|
if self.copy_of(page) == Some(n) {
|
||||||
|
fill(self.entry(page), n, page * PAGE - first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// [`Memory::map`] of the pages of `[address, address + len)`, up to the
|
/// [`Memory::map`] of the pages of `[address, address + len)`, up to the
|
||||||
/// first that is not the title's, and what the title wrote there since
|
/// first that is not the title's, and what the title wrote there since
|
||||||
/// they were taken goes into the arenas.
|
/// they were taken goes into the arenas.
|
||||||
@@ -357,7 +398,9 @@ impl Memory {
|
|||||||
/// Takes the pages `[first, end)` that are in arenas from title memory
|
/// Takes the pages `[first, end)` that are in arenas from title memory
|
||||||
/// where it wrote them.
|
/// where it wrote them.
|
||||||
fn bring(&mut self, first: u64, end: u64) {
|
fn bring(&mut self, first: u64, end: u64) {
|
||||||
if first >= end {
|
// Once a frame: the builder names the same pages list after list.
|
||||||
|
let frame = self.frame;
|
||||||
|
if !(first..end).any(|page| self.pages.get(&page).is_some_and(|h| h.looked != frame)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let started = std::time::Instant::now();
|
let started = std::time::Instant::now();
|
||||||
@@ -366,6 +409,10 @@ impl Memory {
|
|||||||
let Some(held) = self.pages.get_mut(&page) else {
|
let Some(held) = self.pages.get_mut(&page) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
if held.looked == frame {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
held.looked = frame;
|
||||||
self.stats.looked += 1;
|
self.stats.looked += 1;
|
||||||
let wrote = answer
|
let wrote = answer
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -396,18 +443,19 @@ impl Memory {
|
|||||||
|
|
||||||
/// If title memory has a packed structure at `address` that the builder
|
/// If title memory has a packed structure at `address` that the builder
|
||||||
/// comes to anew: all of it has its pages, and goes up as it is there.
|
/// comes to anew: all of it has its pages, and goes up as it is there.
|
||||||
fn unpacks(&mut self, address: u64) {
|
/// Whether there is a packed structure.
|
||||||
|
fn unpacks(&mut self, address: u64) -> bool {
|
||||||
if address & 0xFF != 0 || !self.possible(address / PAGE) {
|
if address & 0xFF != 0 || !self.possible(address / PAGE) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
let mut header = [0u8; 8];
|
let mut header = [0u8; 8];
|
||||||
crate::host::copy_mapped(header.as_mut_ptr(), address as *const u8, 8, false);
|
crate::host::copy_mapped(header.as_mut_ptr(), address as *const u8, 8, false);
|
||||||
let Some(len) = packed_len(u64::from_le_bytes(header)) else {
|
let Some(len) = packed_len(u64::from_le_bytes(header)) else {
|
||||||
return;
|
return false;
|
||||||
};
|
};
|
||||||
let last = self.packed.insert(address, self.frame);
|
let last = self.packed.insert(address, self.frame);
|
||||||
if last.is_some_and(|f| f + AGAIN >= self.frame) {
|
if last.is_some_and(|f| f + AGAIN >= self.frame) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
self.ready(address, len);
|
self.ready(address, len);
|
||||||
let mut title = [0u8; PIECE];
|
let mut title = [0u8; PIECE];
|
||||||
@@ -426,6 +474,7 @@ impl Memory {
|
|||||||
at += n as u64;
|
at += n as u64;
|
||||||
}
|
}
|
||||||
self.stats.packed += 1;
|
self.stats.packed += 1;
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The pages shaders found empty since the last frame.
|
/// The pages shaders found empty since the last frame.
|
||||||
@@ -449,8 +498,9 @@ impl Memory {
|
|||||||
pages.sort_unstable();
|
pages.sort_unstable();
|
||||||
let mut made = 0;
|
let mut made = 0;
|
||||||
for &page in &pages {
|
for &page in &pages {
|
||||||
if made < FAULTS && self.copy_of(page).is_none() && self.map(page) {
|
if made < FAULTS && self.faulted < FAULTS_ALL && self.copy_of(page).is_none() && self.map(page) {
|
||||||
made += 1;
|
made += 1;
|
||||||
|
self.faulted += 1;
|
||||||
self.bring(page, page + 1);
|
self.bring(page, page + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -546,6 +596,11 @@ impl Memory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// [`fill`] of a page stores by address do not reach.
|
||||||
|
fn close(entry: *mut u32, n: usize, offset: u64) {
|
||||||
|
fill(entry, n | MEMORY_READ_ONLY as usize, offset);
|
||||||
|
}
|
||||||
|
|
||||||
/// The offset first: a shader that sees the number sees it too.
|
/// The offset first: a shader that sees the number sees it too.
|
||||||
fn fill(entry: *mut u32, n: usize, offset: u64) {
|
fn fill(entry: *mut u32, n: usize, offset: u64) {
|
||||||
// SAFETY: an entry of the directory, under the mutex.
|
// SAFETY: an entry of the directory, under the mutex.
|
||||||
@@ -585,11 +640,19 @@ fn merge(title: &[u8; PIECE], ours: &mut [u8], never: bool) -> usize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Before a draw whose shader reads title memory by address: what its
|
/// Before a draw whose shader reads title memory by address: what its
|
||||||
/// root arguments name is made ready (`addresses`: its root views;
|
/// root arguments name is made ready (`addresses`: its root views, of them
|
||||||
/// `constants`: its root constants, see the module), every numbered copy
|
/// `written` those it writes; `constants`: its root constants, see the
|
||||||
|
/// module), every numbered copy
|
||||||
/// has its view in `heap`'s run and is brought up to date when `list` is
|
/// has its view in `heap`'s run and is brought up to date when `list` is
|
||||||
/// submitted. None if the host cannot hold it; the draw is then dropped.
|
/// submitted. None if the host cannot hold it; the draw is then dropped.
|
||||||
pub(crate) fn ready(list: &HostList, heap: &HostHeap, addresses: &[u64], constants: &[u32], use_: Use) -> Option<Ready> {
|
pub(crate) fn ready(
|
||||||
|
list: &HostList,
|
||||||
|
heap: &HostHeap,
|
||||||
|
addresses: &[u64],
|
||||||
|
written: &[u64],
|
||||||
|
constants: &[u32],
|
||||||
|
use_: Use,
|
||||||
|
) -> Option<Ready> {
|
||||||
let mut guard = MEMORY.lock().unwrap_or_else(|e| e.into_inner());
|
let mut guard = MEMORY.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
if guard.is_none() {
|
if guard.is_none() {
|
||||||
*guard = Memory::new();
|
*guard = Memory::new();
|
||||||
@@ -639,20 +702,20 @@ pub(crate) fn ready(list: &HostList, heap: &HostHeap, addresses: &[u64], constan
|
|||||||
}
|
}
|
||||||
for &at in addresses.iter().filter(|&&a| a >= 1 << 32) {
|
for &at in addresses.iter().filter(|&&a| a >= 1 << 32) {
|
||||||
// (Several structures to a page.)
|
// (Several structures to a page.)
|
||||||
if builds && list.first_use(usize::MAX - (3 << 33) - (at >> 8) as usize) {
|
let packed = builds && list.first_use(usize::MAX - (3 << 33) - (at >> 8) as usize) && m.unpacks(at);
|
||||||
m.unpacks(at);
|
if builds && written.contains(&at) && named(4, at) {
|
||||||
|
if let Some((start, len)) = crate::shadow::in_buffer(at, 1)
|
||||||
|
&& len <= BACK
|
||||||
|
&& use_ == (Use::Builds { back: true })
|
||||||
|
{
|
||||||
|
m.small(list, start, len);
|
||||||
|
}
|
||||||
|
m.opens(at);
|
||||||
}
|
}
|
||||||
if !named(2, at) {
|
if packed || !named(2, at) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
match crate::shadow::in_buffer(at, 1) {
|
match crate::shadow::in_buffer(at, 1) {
|
||||||
Some((start, len)) if builds && len <= BACK => {
|
|
||||||
if use_ == (Use::Builds { back: true }) {
|
|
||||||
m.small(list, start, len);
|
|
||||||
}
|
|
||||||
m.ready(at, 1);
|
|
||||||
m.named_in_upload(at);
|
|
||||||
}
|
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
m.ready(at, 1);
|
m.ready(at, 1);
|
||||||
m.named_in_upload(at);
|
m.named_in_upload(at);
|
||||||
@@ -666,7 +729,10 @@ pub(crate) fn ready(list: &HostList, heap: &HostHeap, addresses: &[u64], constan
|
|||||||
None => {
|
None => {
|
||||||
// Held for the heap's life: not given back with a list's slots.
|
// Held for the heap's life: not given back with a list's slots.
|
||||||
let base = heap.dynamic(COPIES + 1)?;
|
let base = heap.dynamic(COPIES + 1)?;
|
||||||
heap.null_raw_uav_at(base);
|
// Every slot of the run: a number shows no view of another kind.
|
||||||
|
for n in 0..=COPIES {
|
||||||
|
heap.null_raw_uav_at(base + n);
|
||||||
|
}
|
||||||
(base, 0)
|
(base, 0)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ impl<'a> Lower<'a> {
|
|||||||
let at = self.s.m.select(c, inside, at, outside);
|
let at = self.s.m.select(c, inside, at, outside);
|
||||||
return (handle, at);
|
return (handle, at);
|
||||||
}
|
}
|
||||||
self.memory(low, high, guard)
|
self.memory(low, high, guard, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `count` dwords of the node from its byte `base` + `offset` (`base`
|
/// `count` dwords of the node from its byte `base` + `offset` (`base`
|
||||||
|
|||||||
@@ -1783,7 +1783,7 @@ impl<'a> Lower<'a> {
|
|||||||
if let Some(bias) = self.root_bias(a.param) {
|
if let Some(bias) = self.root_bias(a.param) {
|
||||||
off = self.s.m.bin(c, Bin::Add, off, bias);
|
off = self.s.m.bin(c, Bin::Add, off, bias);
|
||||||
}
|
}
|
||||||
match self.root_memory(&src, off, guard) {
|
match self.root_memory(&src, off, guard, false) {
|
||||||
Some((h, byte)) => {
|
Some((h, byte)) => {
|
||||||
off = byte;
|
off = byte;
|
||||||
Some(h)
|
Some(h)
|
||||||
@@ -3013,8 +3013,10 @@ impl<'a> Lower<'a> {
|
|||||||
/// (and drops writes) through the null view at the first slot, and its
|
/// (and drops writes) through the null view at the first slot, and its
|
||||||
/// number is left for the host, for lanes that run (`guard`). Goes on in
|
/// number is left for the host, for lanes that run (`guard`). Goes on in
|
||||||
/// another block.
|
/// another block.
|
||||||
fn memory(&mut self, lo: V, hi: V, guard: Option<V>) -> (V, V) {
|
/// With `store`, a page that is not to be written ([`super::shader::MEMORY_READ_ONLY`])
|
||||||
use super::shader::{MEMORY_FAULTS, MEMORY_PAGES, SLOT_FAULTS, SLOT_MEMORY, USER_MEMORY_BASE};
|
/// is the null view.
|
||||||
|
fn memory(&mut self, lo: V, hi: V, guard: Option<V>, store: bool) -> (V, V) {
|
||||||
|
use super::shader::{MEMORY_FAULTS, MEMORY_PAGES, MEMORY_READ_ONLY, SLOT_FAULTS, SLOT_MEMORY, USER_MEMORY_BASE};
|
||||||
let c = self.cur;
|
let c = self.cur;
|
||||||
let (i32t, res) = (self.s.t.i32, self.s.t.res_ret);
|
let (i32t, res) = (self.s.t.i32, self.s.t.res_ret);
|
||||||
let k = |l: &mut Self, v: u32| l.s.m.i32(v);
|
let k = |l: &mut Self, v: u32| l.s.m.i32(v);
|
||||||
@@ -3043,7 +3045,9 @@ impl<'a> Lower<'a> {
|
|||||||
&[directory, at, iu, both, align],
|
&[directory, at, iu, both, align],
|
||||||
);
|
);
|
||||||
let (copy, start) = (self.s.m.extract(c, entry, 0), self.s.m.extract(c, entry, 1));
|
let (copy, start) = (self.s.m.extract(c, entry, 0), self.s.m.extract(c, entry, 1));
|
||||||
let (copy, start) = (self.as_int(copy), self.as_int(start));
|
let (number, start) = (self.as_int(copy), self.as_int(start));
|
||||||
|
let mask = k(self, !MEMORY_READ_ONLY);
|
||||||
|
let copy = self.s.m.bin(c, Bin::And, number, mask);
|
||||||
// A page without a copy: its number, at a place by the number. In a
|
// A page without a copy: its number, at a place by the number. In a
|
||||||
// branch: the notes lie in the PC's memory, and a store there with
|
// branch: the notes lie in the PC's memory, and a store there with
|
||||||
// every node of every ray would be most of what a trace does.
|
// every node of every ray would be most of what a trace does.
|
||||||
@@ -3073,6 +3077,12 @@ impl<'a> Lower<'a> {
|
|||||||
);
|
);
|
||||||
self.end_guarded(noting, &[]);
|
self.end_guarded(noting, &[]);
|
||||||
let c = self.cur;
|
let c = self.cur;
|
||||||
|
let copy = if store {
|
||||||
|
let closed = self.s.m.cmp(c, pred::SLT, number, zero);
|
||||||
|
self.s.m.select(c, closed, zero, copy)
|
||||||
|
} else {
|
||||||
|
copy
|
||||||
|
};
|
||||||
let base = self.host_word(RootType::Other(USER_MEMORY_BASE), 0, 0);
|
let base = self.host_word(RootType::Other(USER_MEMORY_BASE), 0, 0);
|
||||||
let slot = self.s.m.bin(c, Bin::Add, base, copy);
|
let slot = self.s.m.bin(c, Bin::Add, base, copy);
|
||||||
// The builder's threads read what others of the dispatch wrote (a
|
// The builder's threads read what others of the dispatch wrote (a
|
||||||
@@ -3112,7 +3122,7 @@ impl<'a> Lower<'a> {
|
|||||||
/// another block.
|
/// another block.
|
||||||
/// shortcut: an access of several dwords is taken not to cross the end
|
/// shortcut: an access of several dwords is taken not to cross the end
|
||||||
/// of a host copy (the builder's records lie on their size).
|
/// of a host copy (the builder's records lie on their size).
|
||||||
fn root_memory(&mut self, src: &Source, off: V, guard: Option<V>) -> Option<(V, V)> {
|
fn root_memory(&mut self, src: &Source, off: V, guard: Option<V>, store: bool) -> Option<(V, V)> {
|
||||||
let (lo, hi) = self.root_address(src)?;
|
let (lo, hi) = self.root_address(src)?;
|
||||||
let c = self.cur;
|
let c = self.cur;
|
||||||
let i32t = self.s.t.i32;
|
let i32t = self.s.t.i32;
|
||||||
@@ -3123,7 +3133,7 @@ impl<'a> Lower<'a> {
|
|||||||
let sign = self.s.m.bin(c, Bin::AShr, off, k31);
|
let sign = self.s.m.bin(c, Bin::AShr, off, k31);
|
||||||
let hi = self.s.m.bin(c, Bin::Add, hi, carry);
|
let hi = self.s.m.bin(c, Bin::Add, hi, carry);
|
||||||
let hi = self.s.m.bin(c, Bin::Add, hi, sign);
|
let hi = self.s.m.bin(c, Bin::Add, hi, sign);
|
||||||
let (h, byte) = self.memory(sum, hi, guard);
|
let (h, byte) = self.memory(sum, hi, guard, store);
|
||||||
self.root_copy = Some(h);
|
self.root_copy = Some(h);
|
||||||
Some((h, byte))
|
Some((h, byte))
|
||||||
}
|
}
|
||||||
@@ -3173,7 +3183,7 @@ impl<'a> Lower<'a> {
|
|||||||
let Some(Operand::Vector { reg, .. }) = *dst else {
|
let Some(Operand::Vector { reg, .. }) = *dst else {
|
||||||
return Err("a global load result");
|
return Err("a global load result");
|
||||||
};
|
};
|
||||||
let (h, byte) = self.memory(lo, hi, guard);
|
let (h, byte) = self.memory(lo, hi, guard, false);
|
||||||
let c = self.cur;
|
let c = self.cur;
|
||||||
let mask = self.s.m.i8((1u8 << n) - 1);
|
let mask = self.s.m.i8((1u8 << n) - 1);
|
||||||
let r = self.s.op(
|
let r = self.s.op(
|
||||||
@@ -3195,7 +3205,7 @@ impl<'a> Lower<'a> {
|
|||||||
let n = count(rest)?;
|
let n = count(rest)?;
|
||||||
let d = data.as_ref().ok_or("global store data")?;
|
let d = data.as_ref().ok_or("global store data")?;
|
||||||
let vals = self.vgprs(inst, d, n)?;
|
let vals = self.vgprs(inst, d, n)?;
|
||||||
let (h, byte) = self.memory(lo, hi, guard);
|
let (h, byte) = self.memory(lo, hi, guard, true);
|
||||||
let mut args = vec![h, byte, iu];
|
let mut args = vec![h, byte, iu];
|
||||||
args.extend(&vals);
|
args.extend(&vals);
|
||||||
args.resize(3 + 4, iu);
|
args.resize(3 + 4, iu);
|
||||||
@@ -3222,7 +3232,7 @@ impl<'a> Lower<'a> {
|
|||||||
Some(x) => self.i32_of(x)?,
|
Some(x) => self.i32_of(x)?,
|
||||||
None => self.s.m.i32(0),
|
None => self.s.m.i32(0),
|
||||||
};
|
};
|
||||||
let (h, byte) = self.memory(lo, hi, guard);
|
let (h, byte) = self.memory(lo, hi, guard, true);
|
||||||
let c = self.cur;
|
let c = self.cur;
|
||||||
// DXIL's atomic operations: add 0, and 1, or 2, xor 3, signed
|
// DXIL's atomic operations: add 0, and 1, or 2, xor 3, signed
|
||||||
// minimum 4 and maximum 5, unsigned 6 and 7, exchange 8.
|
// minimum 4 and maximum 5, unsigned 6 and 7, exchange 8.
|
||||||
@@ -3357,7 +3367,7 @@ impl<'a> Lower<'a> {
|
|||||||
for first in (0..count).step_by(4) {
|
for first in (0..count).step_by(4) {
|
||||||
let n = (count - first).min(4);
|
let n = (count - first).min(4);
|
||||||
let (lo, hi) = self.address_plus(lo, hi, offset + 4 * i32::from(first));
|
let (lo, hi) = self.address_plus(lo, hi, offset + 4 * i32::from(first));
|
||||||
let (h, byte) = self.memory(lo, hi, None);
|
let (h, byte) = self.memory(lo, hi, None, false);
|
||||||
let c = self.cur;
|
let c = self.cur;
|
||||||
let mask = self.s.m.i8((1u8 << n) - 1);
|
let mask = self.s.m.i8((1u8 << n) - 1);
|
||||||
let r = self.s.op(
|
let r = self.s.op(
|
||||||
@@ -6004,7 +6014,7 @@ impl<'a> Lower<'a> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if matches!(kind, Some(u) if u.kind == ResourceType::Srv) {
|
if matches!(kind, Some(u) if u.kind == ResourceType::Srv) {
|
||||||
let h = match self.root_memory(src, addr, None) {
|
let h = match self.root_memory(src, addr, None, false) {
|
||||||
Some((h, byte)) => {
|
Some((h, byte)) => {
|
||||||
addr = byte;
|
addr = byte;
|
||||||
h
|
h
|
||||||
@@ -11279,7 +11289,7 @@ impl<'a> Lower<'a> {
|
|||||||
off = self.s.m.bin(c, Bin::Add, element, off);
|
off = self.s.m.bin(c, Bin::Add, element, off);
|
||||||
index = None;
|
index = None;
|
||||||
}
|
}
|
||||||
if let Some((_, byte)) = self.root_memory(src, off, guard) {
|
if let Some((_, byte)) = self.root_memory(src, off, guard, store || atomic.is_some()) {
|
||||||
off = byte;
|
off = byte;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ pub use sampler::StaticSampler;
|
|||||||
pub use lower::{host_settings, set_host_max_wave};
|
pub use lower::{host_settings, set_host_max_wave};
|
||||||
pub use rect::rect_list_gs;
|
pub use rect::rect_list_gs;
|
||||||
pub use shader::{
|
pub use shader::{
|
||||||
MEMORY_FAULTS, MEMORY_PAGES, ROOT_CBV_SPACE, SAMPLER_SPACE, SLOT_FAULTS, SLOT_MEMORY, SLOT_STRIDES,
|
MEMORY_FAULTS, MEMORY_PAGES, MEMORY_READ_ONLY, ROOT_CBV_SPACE, SAMPLER_SPACE, SLOT_FAULTS, SLOT_MEMORY, SLOT_STRIDES,
|
||||||
SLOT_STRIDES_COUNT, USER_DATA_SPACE, USER_MEMORY_BASE, USER_ROOT_ADDRESS, USER_VIEW_ADDRESS, USER_VIEW_BIAS,
|
SLOT_STRIDES_COUNT, USER_DATA_SPACE, USER_MEMORY_BASE, USER_ROOT_ADDRESS, USER_VIEW_ADDRESS, USER_VIEW_BIAS,
|
||||||
raw_views, set_raw_views, set_view_heap_limit, view_heap_limit,
|
raw_views, set_raw_views, set_view_heap_limit, view_heap_limit,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ pub const SLOT_STRIDES_COUNT: u32 = 1 << 21;
|
|||||||
/// - the root SRV `t<SLOT_MEMORY>` in [`ROOT_CBV_SPACE`] is a directory of
|
/// - the root SRV `t<SLOT_MEMORY>` in [`ROOT_CBV_SPACE`] is a directory of
|
||||||
/// [`MEMORY_PAGES`] entries of two dwords, one per 64 KiB of title
|
/// [`MEMORY_PAGES`] entries of two dwords, one per 64 KiB of title
|
||||||
/// address space: the number of the host copy holding that page (0: none
|
/// address space: the number of the host copy holding that page (0: none
|
||||||
/// yet) and the page's byte offset in that copy;
|
/// yet; with [`MEMORY_READ_ONLY`]: stores there are dropped) and the page's
|
||||||
|
/// byte offset in that copy;
|
||||||
/// - copy `n` is the raw buffer view at view-heap slot `base + n`, `base`
|
/// - copy `n` is the raw buffer view at view-heap slot `base + n`, `base`
|
||||||
/// the user-data dword of kind [`USER_MEMORY_BASE`]; slot `base` itself
|
/// the user-data dword of kind [`USER_MEMORY_BASE`]; slot `base` itself
|
||||||
/// reads zeros and drops writes;
|
/// reads zeros and drops writes;
|
||||||
@@ -49,6 +50,9 @@ pub const SLOT_MEMORY: u8 = 254;
|
|||||||
pub const SLOT_FAULTS: u8 = 253;
|
pub const SLOT_FAULTS: u8 = 253;
|
||||||
/// Entries of the [`SLOT_MEMORY`] directory: title addresses below 128 GiB.
|
/// Entries of the [`SLOT_MEMORY`] directory: title addresses below 128 GiB.
|
||||||
pub const MEMORY_PAGES: u32 = 1 << 21;
|
pub const MEMORY_PAGES: u32 = 1 << 21;
|
||||||
|
/// In a directory entry's first dword: shaders do not store there by address
|
||||||
|
/// (a title buffer the structure builder has not been given to write).
|
||||||
|
pub const MEMORY_READ_ONLY: u32 = 1 << 31;
|
||||||
/// Dwords of the [`SLOT_FAULTS`] buffer.
|
/// Dwords of the [`SLOT_FAULTS`] buffer.
|
||||||
pub const MEMORY_FAULTS: u32 = 4096;
|
pub const MEMORY_FAULTS: u32 = 4096;
|
||||||
/// `RootType::Other` code of a user-data dword the host computes: the view
|
/// `RootType::Other` code of a user-data dword the host computes: the view
|
||||||
|
|||||||
Reference in new issue
Block a user