From d937776989392ce907a4639bf05dc2037b924d75 Mon Sep 17 00:00:00 2001 From: Gilles <43683714+corp-0@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:53:27 -0300 Subject: [PATCH] fix: pass a null pointer on an empty blob for proton compatibility (cherry picked from commit dad5e48913cb63a34dac6d56c284c04c186eeacf) --- crates/victory-gpu/src/pipeline/library.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/victory-gpu/src/pipeline/library.rs b/crates/victory-gpu/src/pipeline/library.rs index f81db57..06db5a1 100644 --- a/crates/victory-gpu/src/pipeline/library.rs +++ b/crates/victory-gpu/src/pipeline/library.rs @@ -506,14 +506,33 @@ fn library() -> Option<&'static Library> { .as_ref() } +/// vkd3d-proton refuses a zero-length blob whose pointer is not null; a Rust +/// empty slice's pointer never is. +fn null_when_empty(bytes: &[u8]) -> *const std::ffi::c_void { + if bytes.is_empty() { + return std::ptr::null(); + } + bytes.as_ptr().cast() +} + /// The library in `blob`, or an empty one if the host rejects the blob (an /// adapter or driver change, damage). fn open(device: &ID3D12Device1, blob: Blob) -> Option { let make = |bytes: &[u8]| -> windows::core::Result { + let pointer = null_when_empty(bytes); + let mut library: Option = None; // SAFETY: the bytes outlive the library (kept beside it). unsafe { - device.CreatePipelineLibrary::(bytes)?.cast() + (Interface::vtable(device).CreatePipelineLibrary)( + Interface::as_raw(device), + pointer, + bytes.len(), + &ID3D12PipelineLibrary::IID, + (&raw mut library).cast(), + ) + .ok()?; } + library.ok_or_else(|| windows::core::Error::from(windows::Win32::Foundation::E_POINTER))?.cast() }; if !blob.bytes().is_empty() { match make(blob.bytes()) {