From 225764fc2d135edb210f2a27922332cc2dbea067 Mon Sep 17 00:00:00 2001 From: msiglreith Date: Fri, 12 Jan 2018 13:24:01 +0100 Subject: [PATCH] Implement vkCmdBeginRenderPass --- libportability-gfx/src/conv.rs | 12 +++++++++++- libportability-gfx/src/impls.rs | 30 +++++++++++++++++++++++++++--- libportability/src/lib.rs | 21 +++++++++++++++------ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/libportability-gfx/src/conv.rs b/libportability-gfx/src/conv.rs index 7948322..e853bf5 100644 --- a/libportability-gfx/src/conv.rs +++ b/libportability-gfx/src/conv.rs @@ -1,4 +1,4 @@ -use hal::{adapter, buffer, format, image, memory, pass, pso, window}; +use hal::{adapter, buffer, command, format, image, memory, pass, pso, window}; use std::mem; @@ -430,3 +430,13 @@ pub fn map_image_acces(access: VkAccessFlags) -> image::Access { mask } + +pub fn map_subpass_contents(contents: VkSubpassContents) -> command::SubpassContents { + match contents { + VkSubpassContents::VK_SUBPASS_CONTENTS_INLINE => command::SubpassContents::Inline, + VkSubpassContents::VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS => + command::SubpassContents::SecondaryBuffers, + + _ => panic!("Unexpected subpass contents: {:?}", contents), + } +} diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs index 4a4b7ce..64d45af 100644 --- a/libportability-gfx/src/impls.rs +++ b/libportability-gfx/src/impls.rs @@ -5,7 +5,7 @@ use hal::{ }; use hal::device::WaitFor; use hal::pool::RawCommandPool; -use hal::command::RawCommandBuffer; +use hal::command::{ClearValueRaw, RawCommandBuffer, Rect}; use hal::queue::RawCommandQueue; use std::ffi::CString; @@ -1990,11 +1990,35 @@ pub extern "C" fn gfxCmdPushConstants( } #[inline] pub extern "C" fn gfxCmdBeginRenderPass( - commandBuffer: VkCommandBuffer, + mut commandBuffer: VkCommandBuffer, pRenderPassBegin: *const VkRenderPassBeginInfo, contents: VkSubpassContents, ) { - unimplemented!() + let info = unsafe { &*pRenderPassBegin }; + + let render_area = Rect { + x: info.renderArea.offset.x as _, + y: info.renderArea.offset.y as _, + w: info.renderArea.extent.width as _, + h: info.renderArea.extent.height as _, + }; + let clear_values = unsafe { + slice::from_raw_parts(info.pClearValues, info.clearValueCount as _) + .into_iter() + .map(|cv| { + // HAL and Vulkan clear value union sharing same memory representation + mem::transmute::<_, ClearValueRaw>(*cv) + }) + }; + let contents = conv::map_subpass_contents(contents); + + commandBuffer.begin_renderpass_raw( + &*info.renderPass, + &*info.framebuffer, + render_area, + clear_values, + contents, + ); } #[inline] pub extern "C" fn gfxCmdNextSubpass(commandBuffer: VkCommandBuffer, contents: VkSubpassContents) { diff --git a/libportability/src/lib.rs b/libportability/src/lib.rs index f87f2dc..9a23968 100644 --- a/libportability/src/lib.rs +++ b/libportability/src/lib.rs @@ -1290,7 +1290,16 @@ pub extern "C" fn vkCmdCopyQueryPoolResults( stride: VkDeviceSize, flags: VkQueryResultFlags, ) { - unimplemented!() + gfxCmdCopyQueryPoolResults( + commandBuffer, + queryPool, + firstQuery, + queryCount, + dstBuffer, + dstOffset, + stride, + flags, + ) } #[no_mangle] pub extern "C" fn vkCmdPushConstants( @@ -1301,7 +1310,7 @@ pub extern "C" fn vkCmdPushConstants( size: u32, pValues: *const ::std::os::raw::c_void, ) { - unimplemented!() + gfxCmdPushConstants(commandBuffer, layout, stageFlags, offset, size, pValues) } #[no_mangle] pub extern "C" fn vkCmdBeginRenderPass( @@ -1309,15 +1318,15 @@ pub extern "C" fn vkCmdBeginRenderPass( pRenderPassBegin: *const VkRenderPassBeginInfo, contents: VkSubpassContents, ) { - unimplemented!() + gfxCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents) } #[no_mangle] pub extern "C" fn vkCmdNextSubpass(commandBuffer: VkCommandBuffer, contents: VkSubpassContents) { - unimplemented!() + gfxCmdNextSubpass(commandBuffer, contents) } #[no_mangle] pub extern "C" fn vkCmdEndRenderPass(commandBuffer: VkCommandBuffer) { - unimplemented!() + gfxCmdEndRenderPass(commandBuffer) } #[no_mangle] pub extern "C" fn vkCmdExecuteCommands( @@ -1325,7 +1334,7 @@ pub extern "C" fn vkCmdExecuteCommands( commandBufferCount: u32, pCommandBuffers: *const VkCommandBuffer, ) { - unimplemented!() + gfxCmdExecuteCommands(commandBuffer, commandBufferCount, pCommandBuffers) } #[no_mangle] pub extern "C" fn vkAcquireNextImageKHR(