1
0
Fork 0
mirror of https://github.com/italicsjenga/portability.git synced 2025-02-23 17:47:43 +11:00

Fix dispatchable handles

This commit is contained in:
msiglreith 2018-03-14 22:24:26 +01:00
parent 3cfbc39c86
commit 7817b77c0b
5 changed files with 24 additions and 16 deletions
libportability-gfx
libportability-icd
libportability

View file

@ -4,7 +4,7 @@ publish = false
version = "0.1.0" version = "0.1.0"
authors = [ authors = [
"Dzmitry Malyshau <kvark@mozilla.com>", "Dzmitry Malyshau <kvark@mozilla.com>",
"Markus Siglreightmaier <m.siglreith@gmail.com>", "Markus Siglreithmaier <m.siglreith@gmail.com>",
] ]
[lib] [lib]

View file

@ -1,6 +1,7 @@
use VK_NULL_HANDLE; use VK_NULL_HANDLE;
use std::{borrow, fmt, ops}; use std::{borrow, fmt, ops};
#[repr(C)] #[repr(C)]
pub struct Handle<T>(*mut T); pub struct Handle<T>(*mut T);
@ -59,28 +60,32 @@ pub type DispatchHandle<T> = Handle<T>;
#[cfg(feature = "dispatch")] #[cfg(feature = "dispatch")]
mod dispatch { mod dispatch {
const ICD_LOADER_MAGIC: u32 = 0x01CDC0DE; use VK_NULL_HANDLE;
use std::{borrow, fmt, ops};
const ICD_LOADER_MAGIC: u64 = 0x01CDC0DE;
#[repr(C)] #[repr(C)]
pub struct DispatchHandle<T>(u32, super::Handle<T>); pub struct DispatchHandle<T>(*mut (u64, T));
impl<T> DispatchHandle<T> { impl<T> DispatchHandle<T> {
pub fn new(value: T) -> Self { pub fn new(value: T) -> Self {
DispatchHandle(ICD_LOADER_MAGIC, super::Handle::new(value)) let ptr = Box::into_raw(Box::new((ICD_LOADER_MAGIC, value)));
DispatchHandle(ptr)
} }
pub fn unwrap(self) -> Box<T> { pub fn unwrap(self) -> Box<(u64, T)> {
self.1.unwrap() unsafe { Box::from_raw(self.0) }
} }
pub fn is_null(&self) -> bool { pub fn is_null(&self) -> bool {
self.1.is_null() self.0 == VK_NULL_HANDLE as *mut _
} }
} }
impl<T> Clone for DispatchHandle<T> { impl<T> Clone for DispatchHandle<T> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
DispatchHandle(self.0, self.1) DispatchHandle(self.0)
} }
} }
@ -89,25 +94,25 @@ mod dispatch {
impl<T> ops::Deref for DispatchHandle<T> { impl<T> ops::Deref for DispatchHandle<T> {
type Target = T; type Target = T;
fn deref(&self) -> &T { fn deref(&self) -> &T {
self.1.deref() unsafe { &(*self.0).1 }
} }
} }
impl<T> ops::DerefMut for DispatchHandle<T> { impl<T> ops::DerefMut for DispatchHandle<T> {
fn deref_mut(&mut self) -> &mut T { fn deref_mut(&mut self) -> &mut T {
self.1.deref_mut() unsafe { &mut (*self.0).1 }
} }
} }
impl<T> borrow::Borrow<T> for DispatchHandle<T> { impl<T> borrow::Borrow<T> for DispatchHandle<T> {
fn borrow(&self) -> &T { fn borrow(&self) -> &T {
self.1.borrow() unsafe { &(*self.0).1 }
} }
} }
impl<T> fmt::Debug for DispatchHandle<T> { impl<T> fmt::Debug for DispatchHandle<T> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "DispatchHandle({:p})", (self.1).0) write!(formatter, "DispatchHandle({:p})", self.0)
} }
} }
} }

View file

@ -43,7 +43,7 @@ pub extern "C" fn gfxCreateInstance(
env_logger::init(); env_logger::init();
} }
let instance = back::Instance::create("portability", 1); let instance = back::Instance::create("portability", 1);
unsafe { *pInstance = DispatchHandle::new(instance) }; unsafe { *pInstance = Handle::new(instance) };
VkResult::VK_SUCCESS VkResult::VK_SUCCESS
} }
@ -342,7 +342,7 @@ pub extern "C" fn gfxGetDeviceProcAddr(
vkAllocateDescriptorSets, PFN_vkAllocateDescriptorSets => gfxAllocateDescriptorSets, vkAllocateDescriptorSets, PFN_vkAllocateDescriptorSets => gfxAllocateDescriptorSets,
vkFreeDescriptorSets, PFN_vkFreeDescriptorSets => gfxFreeDescriptorSets, vkFreeDescriptorSets, PFN_vkFreeDescriptorSets => gfxFreeDescriptorSets,
vkUpdateDescriptorSets, PFN_vkUpdateDescriptorSets => gfxUpdateDescriptorSets, vkUpdateDescriptorSets, PFN_vkUpdateDescriptorSets => gfxUpdateDescriptorSets,
vkCreateFence, PFN_vkCreateFence => gfxCreateFence, vkCreateFence, PFN_vkCreateFence => gfxCreateFence,
vkDestroyFence, PFN_vkDestroyFence => gfxDestroyFence, vkDestroyFence, PFN_vkDestroyFence => gfxDestroyFence,
vkWaitForFences, PFN_vkWaitForFences => gfxWaitForFences, vkWaitForFences, PFN_vkWaitForFences => gfxWaitForFences,
@ -2168,10 +2168,13 @@ pub extern "C" fn gfxFreeCommandBuffers(
commandBufferCount: u32, commandBufferCount: u32,
pCommandBuffers: *const VkCommandBuffer, pCommandBuffers: *const VkCommandBuffer,
) { ) {
// TODO:
/*
let buffer_slice = unsafe { slice::from_raw_parts(pCommandBuffers, commandBufferCount as _) }; let buffer_slice = unsafe { slice::from_raw_parts(pCommandBuffers, commandBufferCount as _) };
let buffers = buffer_slice.iter().map(|buffer| *buffer.unwrap()).collect(); let buffers = buffer_slice.iter().map(|buffer| *buffer.unwrap()).collect();
unsafe { commandPool.free(buffers) }; unsafe { commandPool.free(buffers) };
*/
} }
#[inline] #[inline]

View file

@ -4,7 +4,7 @@ publish = false
version = "0.1.0" version = "0.1.0"
authors = [ authors = [
"Dzmitry Malyshau <kvark@mozilla.com>", "Dzmitry Malyshau <kvark@mozilla.com>",
"Markus Siglreightmaier <m.siglreith@gmail.com>", "Markus Siglreithmaier <m.siglreith@gmail.com>",
] ]
[lib] [lib]

View file

@ -4,7 +4,7 @@ publish = false
version = "0.1.0" version = "0.1.0"
authors = [ authors = [
"Dzmitry Malyshau <kvark@mozilla.com>", "Dzmitry Malyshau <kvark@mozilla.com>",
"Markus Siglreightmaier <m.siglreith@gmail.com>", "Markus Siglreithmaier <m.siglreith@gmail.com>",
] ]
[lib] [lib]