mirror of
https://github.com/italicsjenga/portability.git
synced 2024-11-22 15:01:31 +11:00
Command buffer allocation/freeing
This commit is contained in:
parent
82d4e84e03
commit
fcdebb5160
2
Makefile
2
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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
65
src/lib.rs
65
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<back::Instance>;
|
|||
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 = <B as hal::Backend>::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)
|
||||
|
|
Loading…
Reference in a new issue