From 7a3a11fafcd02f9e64785bb1be8cece6152e3899 Mon Sep 17 00:00:00 2001 From: msiglreith Date: Tue, 26 Dec 2017 19:59:30 +0100 Subject: [PATCH] Implement vkBindImageMemory and remaining parts of the depth buffer example --- libportability-gfx/src/impls.rs | 20 ++++++++++++--- native/test.cpp | 44 +++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs index fe951a2..28253e3 100644 --- a/libportability-gfx/src/impls.rs +++ b/libportability-gfx/src/impls.rs @@ -317,12 +317,26 @@ extern "C" { } #[inline] pub extern fn gfxBindImageMemory( - device: VkDevice, - image: VkImage, + gpu: VkDevice, + mut image: VkImage, memory: VkDeviceMemory, memoryOffset: VkDeviceSize, ) -> VkResult { - unimplemented!() + let new_img = match *image.unwrap() { + Image::Image(_) => panic!("An Image can only be bound once!"), + Image::Unbound(unbound) => { + gpu.device.bind_image_memory( + &memory, + memoryOffset, + unbound, + ).unwrap() // TODO + } + }; + + // Replace the unbound image with an actual image under the hood. + *image = Image::Image(new_img); + + VkResult::VK_SUCCESS } extern "C" { pub fn vkGetBufferMemoryRequirements(device: VkDevice, buffer: VkBuffer, diff --git a/native/test.cpp b/native/test.cpp index 36230bf..a2abf3d 100644 --- a/native/test.cpp +++ b/native/test.cpp @@ -268,26 +268,8 @@ int main() { mem_alloc.allocationSize = 0; mem_alloc.memoryTypeIndex = 0; - VkImageViewCreateInfo view_info = {}; - view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - view_info.pNext = NULL; - view_info.image = VK_NULL_HANDLE; - view_info.format = depth_format; - view_info.components.r = VK_COMPONENT_SWIZZLE_R; - view_info.components.g = VK_COMPONENT_SWIZZLE_G; - view_info.components.b = VK_COMPONENT_SWIZZLE_B; - view_info.components.a = VK_COMPONENT_SWIZZLE_A; - view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; - view_info.subresourceRange.baseMipLevel = 0; - view_info.subresourceRange.levelCount = 1; - view_info.subresourceRange.baseArrayLayer = 0; - view_info.subresourceRange.layerCount = 1; - view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; - view_info.flags = 0; - VkMemoryRequirements mem_reqs; - /* Create image */ VkImage depth_image = 0; res = vkCreateImage(device, &image_info, NULL, &depth_image); printf("\tvkCreateImage: res=%d\n", res); @@ -316,6 +298,32 @@ int main() { printf("\tvkAllocateMemory: res=%d\n", res); assert(!res); + res = vkBindImageMemory(device, depth_image, depth_memory, 0); + printf("\tvkBindImageMemory: res=%d\n", res); + assert(!res); + + VkImageViewCreateInfo view_info = {}; + view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + view_info.pNext = NULL; + view_info.image = depth_image; + view_info.format = depth_format; + view_info.components.r = VK_COMPONENT_SWIZZLE_R; + view_info.components.g = VK_COMPONENT_SWIZZLE_G; + view_info.components.b = VK_COMPONENT_SWIZZLE_B; + view_info.components.a = VK_COMPONENT_SWIZZLE_A; + view_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; + view_info.subresourceRange.baseMipLevel = 0; + view_info.subresourceRange.levelCount = 1; + view_info.subresourceRange.baseArrayLayer = 0; + view_info.subresourceRange.layerCount = 1; + view_info.viewType = VK_IMAGE_VIEW_TYPE_2D; + view_info.flags = 0; + + VkImageView depth_view = 0; + res = vkCreateImageView(device, &view_info, NULL, &depth_view); + printf("\tvkCreateImageView: 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;