mirror of
https://github.com/italicsjenga/portability.git
synced 2025-02-18 15:17:43 +11:00
Implement vkQueueSubmit, vkCreateFence, vkDestroyFence, vkWaitForFences, vkCreateFramebuffer, vkDestroyFramebuffer, vkBeginCommandBuffer and vkEndCommandBuffer
This commit is contained in:
parent
2d047648c3
commit
63847cc271
3 changed files with 119 additions and 28 deletions
|
@ -3,7 +3,10 @@ use hal::{
|
||||||
Backend, DescriptorPool, Device, Instance, PhysicalDevice, QueueFamily,
|
Backend, DescriptorPool, Device, Instance, PhysicalDevice, QueueFamily,
|
||||||
Surface, Swapchain as HalSwapchain, FrameSync,
|
Surface, Swapchain as HalSwapchain, FrameSync,
|
||||||
};
|
};
|
||||||
|
use hal::device::WaitFor;
|
||||||
use hal::pool::RawCommandPool;
|
use hal::pool::RawCommandPool;
|
||||||
|
use hal::command::RawCommandBuffer;
|
||||||
|
use hal::queue::RawCommandQueue;
|
||||||
|
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
@ -349,12 +352,47 @@ pub extern "C" fn gfxGetDeviceQueue(
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxQueueSubmit(
|
pub extern "C" fn gfxQueueSubmit(
|
||||||
queue: VkQueue,
|
mut queue: VkQueue,
|
||||||
submitCount: u32,
|
submitCount: u32,
|
||||||
pSubmits: *const VkSubmitInfo,
|
pSubmits: *const VkSubmitInfo,
|
||||||
fence: VkFence,
|
fence: VkFence,
|
||||||
) -> VkResult {
|
) -> VkResult {
|
||||||
unimplemented!()
|
assert_eq!(submitCount, 1); // TODO;
|
||||||
|
|
||||||
|
let submission = unsafe { *pSubmits };
|
||||||
|
let cmd_buffers = unsafe {
|
||||||
|
slice::from_raw_parts(submission.pCommandBuffers, submission.commandBufferCount as _)
|
||||||
|
.into_iter()
|
||||||
|
.map(|cmd_buffer| **cmd_buffer)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
};
|
||||||
|
let wait_semaphores = unsafe {
|
||||||
|
let semaphores = slice::from_raw_parts(submission.pWaitSemaphores, submission.waitSemaphoreCount as _);
|
||||||
|
let stages = slice::from_raw_parts(submission.pWaitDstStageMask, submission.waitSemaphoreCount as _);
|
||||||
|
|
||||||
|
stages.into_iter()
|
||||||
|
.zip(semaphores.into_iter())
|
||||||
|
.map(|(stage, semaphore)| (semaphore.deref(), conv::map_pipeline_stage_flags(*stage)))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
};
|
||||||
|
let signal_semaphores = unsafe {
|
||||||
|
slice::from_raw_parts(submission.pSignalSemaphores, submission.signalSemaphoreCount as _)
|
||||||
|
.into_iter()
|
||||||
|
.map(|semaphore| semaphore.deref())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
};
|
||||||
|
|
||||||
|
let submission = hal::queue::RawSubmission {
|
||||||
|
cmd_buffers: &cmd_buffers,
|
||||||
|
wait_semaphores: &wait_semaphores,
|
||||||
|
signal_semaphores: &signal_semaphores,
|
||||||
|
};
|
||||||
|
|
||||||
|
let fence = if fence.is_null() { None } else { Some(&*fence) };
|
||||||
|
|
||||||
|
unsafe { queue.submit_raw(submission, fence); }
|
||||||
|
|
||||||
|
VkResult::VK_SUCCESS
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxQueueWaitIdle(queue: VkQueue) -> VkResult {
|
pub extern "C" fn gfxQueueWaitIdle(queue: VkQueue) -> VkResult {
|
||||||
|
@ -554,20 +592,31 @@ pub extern "C" fn gfxQueueBindSparse(
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxCreateFence(
|
pub extern "C" fn gfxCreateFence(
|
||||||
device: VkDevice,
|
gpu: VkDevice,
|
||||||
pCreateInfo: *const VkFenceCreateInfo,
|
pCreateInfo: *const VkFenceCreateInfo,
|
||||||
pAllocator: *const VkAllocationCallbacks,
|
_pAllocator: *const VkAllocationCallbacks,
|
||||||
pFence: *mut VkFence,
|
pFence: *mut VkFence,
|
||||||
) -> VkResult {
|
) -> VkResult {
|
||||||
unimplemented!()
|
let flags = unsafe { (*pCreateInfo).flags };
|
||||||
|
let signalled = flags & VkFenceCreateFlagBits::VK_FENCE_CREATE_SIGNALED_BIT as u32 != 0;
|
||||||
|
|
||||||
|
let fence = gpu
|
||||||
|
.device
|
||||||
|
.create_fence(signalled);
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
*pFence = Handle::new(fence);
|
||||||
|
}
|
||||||
|
|
||||||
|
VkResult::VK_SUCCESS
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxDestroyFence(
|
pub extern "C" fn gfxDestroyFence(
|
||||||
device: VkDevice,
|
gpu: VkDevice,
|
||||||
fence: VkFence,
|
fence: VkFence,
|
||||||
pAllocator: *const VkAllocationCallbacks,
|
_pAllocator: *const VkAllocationCallbacks,
|
||||||
) {
|
) {
|
||||||
unimplemented!()
|
gpu.device.destroy_fence(*fence.unwrap());
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxResetFences(
|
pub extern "C" fn gfxResetFences(
|
||||||
|
@ -583,13 +632,29 @@ pub extern "C" fn gfxGetFenceStatus(device: VkDevice, fence: VkFence) -> VkResul
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxWaitForFences(
|
pub extern "C" fn gfxWaitForFences(
|
||||||
device: VkDevice,
|
gpu: VkDevice,
|
||||||
fenceCount: u32,
|
fenceCount: u32,
|
||||||
pFences: *const VkFence,
|
pFences: *const VkFence,
|
||||||
waitAll: VkBool32,
|
waitAll: VkBool32,
|
||||||
timeout: u64,
|
timeout: u64,
|
||||||
) -> VkResult {
|
) -> VkResult {
|
||||||
unimplemented!()
|
let fences = unsafe {
|
||||||
|
slice::from_raw_parts(pFences, fenceCount as _)
|
||||||
|
.into_iter()
|
||||||
|
.map(|fence| fence.deref())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
};
|
||||||
|
|
||||||
|
let wait_for = match waitAll {
|
||||||
|
VK_FALSE => WaitFor::Any,
|
||||||
|
_ => WaitFor::All,
|
||||||
|
};
|
||||||
|
|
||||||
|
if gpu.device.wait_for_fences(&fences, wait_for, timeout as _) {
|
||||||
|
VkResult::VK_SUCCESS
|
||||||
|
} else {
|
||||||
|
VkResult::VK_TIMEOUT
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxCreateSemaphore(
|
pub extern "C" fn gfxCreateSemaphore(
|
||||||
|
@ -1201,20 +1266,45 @@ pub extern "C" fn gfxUpdateDescriptorSets(
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxCreateFramebuffer(
|
pub extern "C" fn gfxCreateFramebuffer(
|
||||||
device: VkDevice,
|
gpu: VkDevice,
|
||||||
pCreateInfo: *const VkFramebufferCreateInfo,
|
pCreateInfo: *const VkFramebufferCreateInfo,
|
||||||
pAllocator: *const VkAllocationCallbacks,
|
_pAllocator: *const VkAllocationCallbacks,
|
||||||
pFramebuffer: *mut VkFramebuffer,
|
pFramebuffer: *mut VkFramebuffer,
|
||||||
) -> VkResult {
|
) -> VkResult {
|
||||||
unimplemented!()
|
let info = unsafe { &*pCreateInfo };
|
||||||
|
|
||||||
|
let attachments = unsafe {
|
||||||
|
slice::from_raw_parts(info.pAttachments, info.attachmentCount as _)
|
||||||
|
};
|
||||||
|
let attachments = attachments
|
||||||
|
.into_iter()
|
||||||
|
.map(|attachment| attachment.deref())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let extent = hal::device::Extent {
|
||||||
|
width: info.width,
|
||||||
|
height: info.height,
|
||||||
|
depth: info.layers,
|
||||||
|
};
|
||||||
|
|
||||||
|
let framebuffer = gpu
|
||||||
|
.device
|
||||||
|
.create_framebuffer(&*info.renderPass, &attachments, extent)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
*pFramebuffer = Handle::new(framebuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
VkResult::VK_SUCCESS
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxDestroyFramebuffer(
|
pub extern "C" fn gfxDestroyFramebuffer(
|
||||||
device: VkDevice,
|
gpu: VkDevice,
|
||||||
framebuffer: VkFramebuffer,
|
framebuffer: VkFramebuffer,
|
||||||
pAllocator: *const VkAllocationCallbacks,
|
_pAllocator: *const VkAllocationCallbacks,
|
||||||
) {
|
) {
|
||||||
unimplemented!()
|
gpu.device.destroy_framebuffer(*framebuffer.unwrap());
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxCreateRenderPass(
|
pub extern "C" fn gfxCreateRenderPass(
|
||||||
|
@ -1481,14 +1571,20 @@ pub extern "C" fn gfxFreeCommandBuffers(
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxBeginCommandBuffer(
|
pub extern "C" fn gfxBeginCommandBuffer(
|
||||||
commandBuffer: VkCommandBuffer,
|
mut commandBuffer: VkCommandBuffer,
|
||||||
pBeginInfo: *const VkCommandBufferBeginInfo,
|
pBeginInfo: *const VkCommandBufferBeginInfo,
|
||||||
) -> VkResult {
|
) -> VkResult {
|
||||||
unimplemented!()
|
assert_eq!(unsafe { (*pBeginInfo).flags }, 0); // TODO
|
||||||
|
|
||||||
|
commandBuffer.begin();
|
||||||
|
|
||||||
|
VkResult::VK_SUCCESS
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxEndCommandBuffer(commandBuffer: VkCommandBuffer) -> VkResult {
|
pub extern "C" fn gfxEndCommandBuffer(mut commandBuffer: VkCommandBuffer) -> VkResult {
|
||||||
unimplemented!()
|
commandBuffer.finish();
|
||||||
|
|
||||||
|
VkResult::VK_SUCCESS
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxResetCommandBuffer(
|
pub extern "C" fn gfxResetCommandBuffer(
|
||||||
|
|
|
@ -45,6 +45,7 @@ pub type VkBuffer = Handle<Buffer<B>>;
|
||||||
pub type VkSemaphore = Handle<<B as hal::Backend>::Semaphore>;
|
pub type VkSemaphore = Handle<<B as hal::Backend>::Semaphore>;
|
||||||
pub type VkFence = Handle<<B as hal::Backend>::Fence>;
|
pub type VkFence = Handle<<B as hal::Backend>::Fence>;
|
||||||
pub type VkRenderPass = Handle<<B as hal::Backend>::RenderPass>;
|
pub type VkRenderPass = Handle<<B as hal::Backend>::RenderPass>;
|
||||||
|
pub type VkFramebuffer = Handle<<B as hal::Backend>::Framebuffer>;
|
||||||
|
|
||||||
pub type QueueFamilyIndex = u32;
|
pub type QueueFamilyIndex = u32;
|
||||||
|
|
||||||
|
@ -543,12 +544,6 @@ pub struct VkPipeline_T {
|
||||||
_unused: [u8; 0],
|
_unused: [u8; 0],
|
||||||
}
|
}
|
||||||
pub type VkPipeline = *mut VkPipeline_T;
|
pub type VkPipeline = *mut VkPipeline_T;
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct VkFramebuffer_T {
|
|
||||||
_unused: [u8; 0],
|
|
||||||
}
|
|
||||||
pub type VkFramebuffer = *mut VkFramebuffer_T;
|
|
||||||
|
|
||||||
pub const VkPipelineCacheHeaderVersion_VK_PIPELINE_CACHE_HEADER_VERSION_BEGIN_RANGE:
|
pub const VkPipelineCacheHeaderVersion_VK_PIPELINE_CACHE_HEADER_VERSION_BEGIN_RANGE:
|
||||||
VkPipelineCacheHeaderVersion =
|
VkPipelineCacheHeaderVersion =
|
||||||
|
|
|
@ -895,11 +895,11 @@ pub extern "C" fn vkBeginCommandBuffer(
|
||||||
commandBuffer: VkCommandBuffer,
|
commandBuffer: VkCommandBuffer,
|
||||||
pBeginInfo: *const VkCommandBufferBeginInfo,
|
pBeginInfo: *const VkCommandBufferBeginInfo,
|
||||||
) -> VkResult {
|
) -> VkResult {
|
||||||
unimplemented!()
|
gfxBeginCommandBuffer(commandBuffer, pBeginInfo)
|
||||||
}
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn vkEndCommandBuffer(commandBuffer: VkCommandBuffer) -> VkResult {
|
pub extern "C" fn vkEndCommandBuffer(commandBuffer: VkCommandBuffer) -> VkResult {
|
||||||
unimplemented!()
|
gfxEndCommandBuffer(commandBuffer)
|
||||||
}
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn vkResetCommandBuffer(
|
pub extern "C" fn vkResetCommandBuffer(
|
||||||
|
|
Loading…
Add table
Reference in a new issue