From 1c3f944fb1d85af67841ef6836dc0b62c9fc9e29 Mon Sep 17 00:00:00 2001 From: maik klein Date: Fri, 23 Dec 2016 10:49:39 +0100 Subject: [PATCH] Add experimental allocator --- src/allocator.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/allocator.rs diff --git a/src/allocator.rs b/src/allocator.rs new file mode 100644 index 0000000..f5a90b9 --- /dev/null +++ b/src/allocator.rs @@ -0,0 +1,70 @@ +use vk; +use std::ptr; +pub trait VkAllocation { + unsafe extern "system" fn allocation(*mut (), + vk::size_t, + vk::size_t, + vk::SystemAllocationScope) + -> *mut (); + unsafe extern "system" fn reallocation(*mut vk::c_void, + *mut vk::c_void, + vk::size_t, + vk::size_t, + vk::SystemAllocationScope) + -> *mut vk::c_void; + unsafe extern "system" fn free(*mut vk::c_void, *mut vk::c_void); + unsafe extern "system" fn internal_allocation(*mut vk::c_void, + vk::size_t, + vk::InternalAllocationType, + vk::SystemAllocationScope); + unsafe extern "system" fn internal_free(*mut vk::c_void, + vk::size_t, + vk::InternalAllocationType, + vk::SystemAllocationScope); + fn create_allocation_callback() -> Option { + let alloc = vk::AllocationCallbacks { + p_user_data: ptr::null_mut(), + pfn_allocation: Self::allocation, + pfn_reallocation: Self::reallocation, + pfn_free: Self::free, + pfn_internal_allocation: Self::internal_allocation, + pfn_internal_free: Self::internal_free, + }; + Some(alloc) + } +} + +pub struct DefaultAllocatorCallback; + +impl VkAllocation for DefaultAllocatorCallback { + unsafe extern "system" fn allocation(user: *mut (), + a: vk::size_t, + b: vk::size_t, + c: vk::SystemAllocationScope) + -> *mut () { + ptr::null_mut() + } + + unsafe extern "system" fn reallocation(a: *mut vk::c_void, + b: *mut vk::c_void, + c: vk::size_t, + d: vk::size_t, + e: vk::SystemAllocationScope) + -> *mut vk::c_void { + ptr::null_mut() + } + unsafe extern "system" fn free(a: *mut vk::c_void, b: *mut vk::c_void) {} + unsafe extern "system" fn internal_allocation(a: *mut vk::c_void, + b: vk::size_t, + c: vk::InternalAllocationType, + d: vk::SystemAllocationScope) { + } + unsafe extern "system" fn internal_free(a: *mut vk::c_void, + b: vk::size_t, + c: vk::InternalAllocationType, + d: vk::SystemAllocationScope) { + } + fn create_allocation_callback() -> Option { + None + } +}