diff --git a/Makefile b/Makefile index fb6a9ff..feb72f9 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ binding: $(BINDING) $(BINDING): $(VULKAN_DIR)/vulkan/*.h bindgen --no-layout-tests --rustfmt-bindings $(VULKAN_DIR)/vulkan/vulkan.h -o $(BINDING) -$(LIBRARY): src/*.rs Cargo.toml +$(LIBRARY): src/*.rs Cargo.toml Cargo.lock cargo build mkdir -p target/native diff --git a/native/test.c b/native/test.c index b10ac3a..20e525e 100644 --- a/native/test.c +++ b/native/test.c @@ -12,6 +12,7 @@ int main() { VkInstance instance; VkResult res; + unsigned int i; res = vkCreateInstance(&inst_info, NULL, &instance); if (res == VK_ERROR_INCOMPATIBLE_DRIVER) { @@ -36,7 +37,7 @@ int main() { assert(queue_family_count); int queue_family_index = -1; - for (unsigned int i = 0; i < queue_family_count; i++) { + for (i = 0; i < queue_family_count; i++) { if (queue_family_properties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { queue_family_index = i; break; diff --git a/src/lib.rs b/src/lib.rs index e3d8807..4c654d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ mod handle; use std::{cmp, slice}; use hal::{Device, Instance, PhysicalDevice, QueueFamily}; // traits only +use hal::pool::RawCommandPool; use back::Backend as B; use handle::Handle; @@ -462,6 +463,7 @@ pub type VkInstance = Handle; pub type VkPhysicalDevice = Handle>; pub type VkDevice = Handle>; pub type VkCommandPool = Handle<::CommandPool>; +pub type VkCommandBuffer = ::CommandBuffer; #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -477,12 +479,6 @@ pub struct VkSemaphore_T { pub type VkSemaphore = *mut VkSemaphore_T; #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct VkCommandBuffer_T { - _unused: [u8; 0], -} -pub type VkCommandBuffer = *mut VkCommandBuffer_T; -#[repr(C)] -#[derive(Debug, Copy, Clone)] pub struct VkFence_T { _unused: [u8; 0], } @@ -4890,22 +4886,53 @@ pub extern fn vkDestroyCommandPool( gpu.device.destroy_command_pool(*commandPool.unwrap()); } -extern "C" { - pub fn vkResetCommandPool(device: VkDevice, commandPool: VkCommandPool, - flags: VkCommandPoolResetFlags) -> VkResult; +#[no_mangle] +pub extern fn vkResetCommandPool( + _gpu: VkDevice, + mut commandPool: VkCommandPool, + _flags: VkCommandPoolResetFlags, +) -> VkResult { + commandPool.reset(); + VkResult::VK_SUCCESS } -extern "C" { - pub fn vkAllocateCommandBuffers(device: VkDevice, - pAllocateInfo: - *const VkCommandBufferAllocateInfo, - pCommandBuffers: *mut VkCommandBuffer) - -> VkResult; + +#[no_mangle] +pub extern fn vkAllocateCommandBuffers( + _gpu: VkDevice, + pAllocateInfo: *const VkCommandBufferAllocateInfo, + pCommandBuffers: *mut VkCommandBuffer, +) -> VkResult { + let info = unsafe { &mut *(pAllocateInfo as *mut VkCommandBufferAllocateInfo) }; + assert_eq!(info.level, VkCommandBufferLevel::VK_COMMAND_BUFFER_LEVEL_PRIMARY); //TODO + let count = info.commandBufferCount as usize; + + let cmd_bufs = info.commandPool.allocate(count); + + let output = unsafe { + slice::from_raw_parts_mut(pCommandBuffers, count) + }; + for (out, cmd_buf) in output.iter_mut().zip(cmd_bufs) { + *out = cmd_buf; + } + + VkResult::VK_SUCCESS } -extern "C" { - pub fn vkFreeCommandBuffers(device: VkDevice, commandPool: VkCommandPool, - commandBufferCount: u32, - pCommandBuffers: *const VkCommandBuffer); + +#[no_mangle] +pub extern fn vkFreeCommandBuffers( + _gpu: VkDevice, + mut commandPool: VkCommandPool, + commandBufferCount: u32, + pCommandBuffers: *const VkCommandBuffer, +) { + let buffer_slice = unsafe { + slice::from_raw_parts(pCommandBuffers, commandBufferCount as _) + }; + let buffers = buffer_slice.to_vec(); + + unsafe { commandPool.free(buffers) }; } + extern "C" { pub fn vkBeginCommandBuffer(commandBuffer: VkCommandBuffer, pBeginInfo: *const VkCommandBufferBeginInfo)