upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author101Leafy <6332664+101Leafy@users.noreply.github.com>2026-11-30 02:08:49 +0100
committerFayber <contact@fayber.dev>2026-11-30 02:08:49 +0100
commitc124d2f78d1bf46404fca506aac37c7e368060c8 (patch)
tree8f5d6a17ddde289d4ad7342031b4ff818847899d
parente802c48fe28e9b5dbb578da564e53634ea00db0f (diff)
Pipeline library: a save the host has no memory for waits for a later one instead of aborting the processdev
(from VIctory-NVIDIA e0e9ffc3f, upstream 63be24fbf)
-rw-r--r--crates/victory-gpu/src/pipeline/library.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/crates/victory-gpu/src/pipeline/library.rs b/crates/victory-gpu/src/pipeline/library.rs
index a299501e..0fb817dd 100644
--- a/crates/victory-gpu/src/pipeline/library.rs
+++ b/crates/victory-gpu/src/pipeline/library.rs
@@ -878,12 +878,24 @@ fn serialise(library: &ID3D12PipelineLibrary1, tmp: &std::path::Path, size: usiz
878 // SAFETY: a buffer of the size the library asks for. 878 // SAFETY: a buffer of the size the library asks for.
879 return unsafe { library.Serialize(file.bytes_mut()) }.map_err(failed); 879 return unsafe { library.Serialize(file.bytes_mut()) }.map_err(failed);
880 } 880 }
881 let mut bytes = vec![0u8; size]; 881 // The library is about 1.7 GB on NVIDIA (each pipeline's machine code):
882 // an allocation of that size that cannot fail aborted the whole process
883 // ("memory allocation of 2650101862 bytes failed", RTX 4050 Laptop).
884 // Refused, the save waits for a later one and the pipelines stay added.
885 let mut bytes = zeroed(size).ok_or_else(|| std::io::Error::from(std::io::ErrorKind::OutOfMemory))?;
882 // SAFETY: a buffer of the size the library asks for. 886 // SAFETY: a buffer of the size the library asks for.
883 unsafe { library.Serialize(&mut bytes) }.map_err(failed)?; 887 unsafe { library.Serialize(&mut bytes) }.map_err(failed)?;
884 std::fs::write(tmp, &bytes) 888 std::fs::write(tmp, &bytes)
885} 889}
886 890
891/// `n` zero bytes, or `None` when the host has no memory for them.
892fn zeroed(n: usize) -> Option<Vec<u8>> {
893 let mut v = Vec::new();
894 v.try_reserve_exact(n).ok()?;
895 v.resize(n, 0);
896 Some(v)
897}
898
887/// Renames the written library `tmp` over the library's file in `dir`. This 899/// Renames the written library `tmp` over the library's file in `dir`. This
888/// run may have that file mapped: Windows 11 replaces a mapped file, and 900/// run may have that file mapped: Windows 11 replaces a mapped file, and
889/// the mapping goes on reading the old one for as long as a handle on it 901/// the mapping goes on reading the old one for as long as a handle on it
@@ -1010,6 +1022,13 @@ pub(crate) fn note_used(key: &str) {
1010mod tests { 1022mod tests {
1011 use super::*; 1023 use super::*;
1012 1024
1025 /// A size the host cannot give is refused, not fatal; others are zeros.
1026 #[test]
1027 fn a_save_buffer_the_host_cannot_give_is_refused() {
1028 assert!(zeroed(usize::MAX / 2).is_none());
1029 assert_eq!(zeroed(100).as_deref(), Some(&[0u8; 100][..]));
1030 }
1031
1013 #[test] 1032 #[test]
1014 fn bypassing_the_library_calls_pipeline_creation() { 1033 fn bypassing_the_library_calls_pipeline_creation() {
1015 let created = std::cell::Cell::new(false); 1034 let created = std::cell::Cell::new(false);