fix: pass a null pointer on an empty blob for proton compatibility
(cherry picked from commit dad5e48913cb63a34dac6d56c284c04c186eeacf)
This commit is contained in:
1 parent
36fd13df5e
commit
d937776989
1 file changed
+20
-1
@@ -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<Library> {
|
||||
let make = |bytes: &[u8]| -> windows::core::Result<ID3D12PipelineLibrary1> {
|
||||
let pointer = null_when_empty(bytes);
|
||||
let mut library: Option<ID3D12PipelineLibrary> = None;
|
||||
// SAFETY: the bytes outlive the library (kept beside it).
|
||||
unsafe {
|
||||
device.CreatePipelineLibrary::<ID3D12PipelineLibrary>(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()) {
|
||||
|
||||
Reference in new issue
Block a user