Implement vkBindImageMemory and remaining parts of the depth buffer example

This commit is contained in:
msiglreith 2017-12-26 19:59:30 +01:00
parent 458568cad2
commit 7a3a11fafc
2 changed files with 43 additions and 21 deletions

View file

@ -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,

View file

@ -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;