mirror of
https://github.com/italicsjenga/portability.git
synced 2024-11-22 15:01:31 +11:00
Implement vkAllocateMemory and vkFreeMemory
This commit is contained in:
parent
04835a3aeb
commit
4f409de59e
|
@ -10,12 +10,10 @@ name = "portability_gfx"
|
|||
lazy_static = "1.0"
|
||||
|
||||
[dependencies.gfx-hal]
|
||||
#path = "../gfx/src/hal"
|
||||
git = "https://github.com/gfx-rs/gfx"
|
||||
branch = "portable"
|
||||
|
||||
[dependencies.gfx-backend-vulkan]
|
||||
#path = "../gfx/src/backend/vulkan"
|
||||
git = "https://github.com/gfx-rs/gfx"
|
||||
branch = "portable"
|
||||
features = ["portable"]
|
||||
|
|
|
@ -262,11 +262,25 @@ pub extern fn gfxAllocateMemory(
|
|||
_pAllocator: *const VkAllocationCallbacks,
|
||||
pMemory: *mut VkDeviceMemory,
|
||||
) -> VkResult {
|
||||
unimplemented!()
|
||||
let info = unsafe { &*pAllocateInfo };
|
||||
let memory = gpu
|
||||
.device
|
||||
.allocate_memory(
|
||||
hal::MemoryTypeId(info.memoryTypeIndex as _),
|
||||
info.allocationSize,
|
||||
)
|
||||
.unwrap(); // TODO:
|
||||
|
||||
unsafe { *pMemory = Handle::new(memory); }
|
||||
VkResult::VK_SUCCESS
|
||||
}
|
||||
extern "C" {
|
||||
pub fn vkFreeMemory(device: VkDevice, memory: VkDeviceMemory,
|
||||
pAllocator: *const VkAllocationCallbacks);
|
||||
#[inline]
|
||||
pub extern fn gfxFreeMemory(
|
||||
gpu: VkDevice,
|
||||
memory: VkDeviceMemory,
|
||||
pAllocator: *const VkAllocationCallbacks,
|
||||
) {
|
||||
gpu.device.free_memory(*memory.unwrap());
|
||||
}
|
||||
extern "C" {
|
||||
pub fn vkMapMemory(device: VkDevice, memory: VkDeviceMemory,
|
||||
|
|
|
@ -26,6 +26,7 @@ pub type VkPhysicalDevice = Handle<hal::Adapter<B>>;
|
|||
pub type VkDevice = Handle<hal::Gpu<B>>;
|
||||
pub type VkCommandPool = Handle<<B as hal::Backend>::CommandPool>;
|
||||
pub type VkCommandBuffer = Handle<<B as hal::Backend>::CommandBuffer>;
|
||||
pub type VkDeviceMemory = Handle<<B as hal::Backend>::Memory>;
|
||||
|
||||
pub enum Image<B: hal::Backend> {
|
||||
Image(B::Image),
|
||||
|
@ -512,12 +513,6 @@ pub struct VkFence_T {
|
|||
pub type VkFence = *mut VkFence_T;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct VkDeviceMemory_T {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
pub type VkDeviceMemory = *mut VkDeviceMemory_T;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct VkBuffer_T {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
|
|
|
@ -64,6 +64,14 @@ pub extern fn vkAllocateMemory(
|
|||
gfxAllocateMemory(device, pAllocateInfo, pAllocator, pMemory)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub extern fn vkFreeMemory(
|
||||
device: VkDevice,
|
||||
memory: VkDeviceMemory,
|
||||
pAllocator: *const VkAllocationCallbacks,
|
||||
) {
|
||||
gfxFreeMemory(device, memory, pAllocator)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub extern fn vkBindImageMemory(
|
||||
device: VkDevice,
|
||||
image: VkImage,
|
||||
|
|
|
@ -311,6 +311,11 @@ int main() {
|
|||
&mem_alloc.memoryTypeIndex);
|
||||
assert(pass);
|
||||
|
||||
VkDeviceMemory depth_memory = 0;
|
||||
res = vkAllocateMemory(device, &mem_alloc, NULL, &depth_memory);
|
||||
printf("\tvkAllocateMemory: res=%d\n", res);
|
||||
assert(!res);
|
||||
|
||||
VkCommandPool cmd_pool = 0;
|
||||
VkCommandPoolCreateInfo cmd_pool_info = {};
|
||||
cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||
|
@ -339,6 +344,8 @@ int main() {
|
|||
|
||||
}
|
||||
|
||||
vkFreeMemory(device, depth_memory, NULL);
|
||||
printf("\tvkFreeMemory\n");
|
||||
for(auto view : swapchain_views) {
|
||||
vkDestroyImageView(device, view, NULL);
|
||||
printf("\tvkDestroyImageView\n");
|
||||
|
|
Loading…
Reference in a new issue