Take the fix/amd-view-heap-clamp branch of triippywhale's fork (as one commit)
Every host view heap ends at a null slot that view indices past the heap read (a host that takes large heaps gets 2^21 views; one that caps them keeps the capped heap), the cache key includes that limit, and v_permlane16/x16 are lowered. Both forks lower v_cvt_f32_f64. The IEEE form with its test is the one in use; this branch's flush-to-zero form is kept beside it, unused, and its test is ignored until the console's float mode for the instruction is checked. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
1 parent
3bff182ef4
commit
31714deb2d
6 files changed
+302
-49
No files matched your search
@@ -509,34 +509,52 @@ pub(crate) fn near_heaps(va: u64) -> String {
|
||||
/// tiers 1 and 2; tier 3 hardware may take more.
|
||||
const PORTABLE_VIEWS: u32 = 1_000_000;
|
||||
|
||||
/// Asks the host, once, whether it caps view heaps at [`PORTABLE_VIEWS`],
|
||||
/// and if so tells the translator now (`set_view_heap_limit`) instead of
|
||||
/// when the title's heap is made: a shader keeps the limit it was
|
||||
/// translated with, and the title makes 25 pipelines (their
|
||||
/// shaders translated at once) before it makes its view heap. Those would
|
||||
/// read a view index past the heap unclamped, the read that hangs NVIDIA.
|
||||
/// Called before a shader is translated.
|
||||
/// shortcut: the limit is the capped heap's last slot whatever size the
|
||||
/// title's heap turns out to have; a heap that fits is not capped and
|
||||
/// keeps no null slot there (an index past it is as undefined as before).
|
||||
/// The size of every host view heap on a host that takes more than
|
||||
/// [`PORTABLE_VIEWS`] (AMD): the title's heap (a little over 1,000,000
|
||||
/// views in the retail game) plus [`DYNAMIC`] fits with room to spare, and
|
||||
/// the last slot is the null slot every view index at or past it reads.
|
||||
const UNCAPPED_VIEWS: u32 = 1 << 21;
|
||||
|
||||
/// Picks, once, the null slot at the end of every host view heap and tells
|
||||
/// the translator now (`set_view_heap_limit`) instead of when the title's
|
||||
/// heap is made: a shader keeps the limit it was translated with, and the
|
||||
/// title makes 25 pipelines (their shaders translated at once) before it
|
||||
/// makes its view heap. Called before a shader is translated and before a
|
||||
/// view heap is made.
|
||||
///
|
||||
/// Every host clamps. A host that caps view heaps at [`PORTABLE_VIEWS`]
|
||||
/// (NVIDIA) hung on a view index past the heap; one that does not (AMD
|
||||
/// RDNA3, RX 7900 XT) took a page fault and removed the device on entering
|
||||
/// the world: a compute program read view slot 16,777,088 (0xffff80) of a
|
||||
/// heap of 1,507,328, past its end. Unclamped, that index is undefined on
|
||||
/// any host.
|
||||
pub(crate) fn probe_view_limit() {
|
||||
static ONCE: std::sync::Once = std::sync::Once::new();
|
||||
ONCE.call_once(|| {
|
||||
let Some(host) = host() else { return };
|
||||
// SAFETY: plain heap creation; the heap is released at once.
|
||||
let made: windows::core::Result<ID3D12DescriptorHeap> = unsafe {
|
||||
host.device
|
||||
.CreateDescriptorHeap(&D3D12_DESCRIPTOR_HEAP_DESC {
|
||||
Type: D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
|
||||
NumDescriptors: PORTABLE_VIEWS + 1,
|
||||
Flags: D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
|
||||
NodeMask: 0,
|
||||
})
|
||||
let fits = |count: u32| {
|
||||
// SAFETY: plain heap creation; the heap is released at once.
|
||||
let made: windows::core::Result<ID3D12DescriptorHeap> = unsafe {
|
||||
host.device
|
||||
.CreateDescriptorHeap(&D3D12_DESCRIPTOR_HEAP_DESC {
|
||||
Type: D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
|
||||
NumDescriptors: count,
|
||||
Flags: D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
|
||||
NodeMask: 0,
|
||||
})
|
||||
};
|
||||
made.is_ok()
|
||||
};
|
||||
if made.is_err() {
|
||||
tracing::info!("the host caps view heaps at {PORTABLE_VIEWS}: view indices are clamped from the first shader on");
|
||||
victory_shader::emit::set_view_heap_limit(PORTABLE_VIEWS - 1);
|
||||
}
|
||||
let views = if fits(UNCAPPED_VIEWS) {
|
||||
UNCAPPED_VIEWS
|
||||
} else {
|
||||
PORTABLE_VIEWS
|
||||
};
|
||||
tracing::info!(
|
||||
views,
|
||||
"host view heaps hold {views} views; view indices are clamped to the null slot at the end from the first shader on"
|
||||
);
|
||||
victory_shader::emit::set_view_heap_limit(views - 1);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -574,20 +592,41 @@ impl HostHeap {
|
||||
}
|
||||
};
|
||||
let extra = if sampler { 0 } else { DYNAMIC };
|
||||
let (heap, count, size) = match make(count + extra) {
|
||||
Ok(heap) => (heap, count, count + extra),
|
||||
Err(e) if !sampler && count + extra > PORTABLE_VIEWS => {
|
||||
// shortcut: descriptors past the host's limit are left out; a title that reaches
|
||||
// them needs remapping. The heap's last slot stays null, and shaders read it for
|
||||
// any view index from there on (`set_view_heap_limit`): a read past the heap's
|
||||
// end hung NVIDIA's GPU (the title's heap is a little over 1 000 000 views).
|
||||
tracing::warn!(error = %e, count, "host view heap capped at {PORTABLE_VIEWS}; views past it read a null slot");
|
||||
victory_shader::emit::set_view_heap_limit(PORTABLE_VIEWS - 1);
|
||||
(make(PORTABLE_VIEWS).ok()?, PORTABLE_VIEWS - extra - 1, PORTABLE_VIEWS)
|
||||
// A view heap ends at the null slot shaders clamp view indices to
|
||||
// (`probe_view_limit`), whatever the title's own count: the title's
|
||||
// slots, then the dynamic ones, then null up to and with that slot.
|
||||
if !sampler {
|
||||
probe_view_limit();
|
||||
}
|
||||
let null = if sampler {
|
||||
0
|
||||
} else {
|
||||
victory_shader::emit::view_heap_limit()
|
||||
};
|
||||
let (heap, count, size) = if null == 0 {
|
||||
match make(count + extra) {
|
||||
Ok(heap) => (heap, count, count + extra),
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, count, sampler, "no host descriptor heap");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, count, sampler, "no host descriptor heap");
|
||||
return None;
|
||||
} else {
|
||||
let size = null + 1;
|
||||
let fitted = if count + extra <= null {
|
||||
count
|
||||
} else {
|
||||
// shortcut: descriptors past the host's limit are left out; a title that reaches
|
||||
// them needs remapping. They read the null slot instead.
|
||||
tracing::warn!(count, "host view heap capped at {size}; views past it read a null slot");
|
||||
null - extra
|
||||
};
|
||||
match make(size) {
|
||||
Ok(heap) => (heap, fitted, size),
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, count, size, "no host view heap");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
};
|
||||
// SAFETY: a live heap.
|
||||
@@ -602,7 +641,7 @@ impl HostHeap {
|
||||
let gpu = unsafe { heap.GetGPUDescriptorHandleForHeapStart().ptr };
|
||||
GPU_RANGES.lock().unwrap_or_else(|e| e.into_inner()).push((
|
||||
gpu,
|
||||
u64::from(count + extra) * u64::from(step),
|
||||
u64::from(size) * u64::from(step),
|
||||
u64::from(step),
|
||||
sampler,
|
||||
));
|
||||
|
||||
@@ -54,6 +54,10 @@ fn build() -> &'static [u8; 32] {
|
||||
match exe {
|
||||
Ok(mut bytes) => {
|
||||
bytes.extend_from_slice(&limit.to_le_bytes());
|
||||
// So is the view heap's null slot (it differs by host GPU):
|
||||
// a translation cached without the clamp must not be served.
|
||||
crate::descriptor::host::probe_view_limit();
|
||||
bytes.extend_from_slice(&victory_shader::emit::view_heap_limit().to_le_bytes());
|
||||
// Which group barriers wait is part of the translation too.
|
||||
bytes.push(victory_shader::emit::group_sync());
|
||||
// So are the switches that pick the form of a wave64 program:
|
||||
|
||||
Reference in new issue
Block a user