From 6bce4d97992b3360a479653285f6c26d62736703 Mon Sep 17 00:00:00 2001 From: plapins Date: Tue, 14 Jun 2016 12:27:47 +0200 Subject: [PATCH] Fixed bug in buffer memory allocation code in tutorials 04 and 05. Modified ImageParameters structure (renamed "ImageView" member to "View", added "Sampler" member) and updated tutorial 03, 04 and 05. Fixed typos in comments. --- Project/Common/VulkanCommon.cpp | 12 ++++++------ Project/Common/VulkanCommon.h | 8 ++++++-- Project/Tutorial03/Tutorial03.cpp | 2 +- Project/Tutorial04/Tutorial04.cpp | 4 ++-- Project/Tutorial05/Tutorial05.cpp | 6 ++++-- Project/Tutorial05/Tutorial05.h | 2 +- Project/Tutorial05/main.cpp | 2 +- 7 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Project/Common/VulkanCommon.cpp b/Project/Common/VulkanCommon.cpp index c33d6e7..8c34150 100644 --- a/Project/Common/VulkanCommon.cpp +++ b/Project/Common/VulkanCommon.cpp @@ -439,9 +439,9 @@ namespace ApiWithoutSecrets { } for( size_t i = 0; i < Vulkan.SwapChain.Images.size(); ++i ) { - if( Vulkan.SwapChain.Images[i].ImageView != VK_NULL_HANDLE ) { - vkDestroyImageView( GetDevice(), Vulkan.SwapChain.Images[i].ImageView, nullptr ); - Vulkan.SwapChain.Images[i].ImageView = VK_NULL_HANDLE; + if( Vulkan.SwapChain.Images[i].View != VK_NULL_HANDLE ) { + vkDestroyImageView( GetDevice(), Vulkan.SwapChain.Images[i].View, nullptr ); + Vulkan.SwapChain.Images[i].View = VK_NULL_HANDLE; } } Vulkan.SwapChain.Images.clear(); @@ -570,7 +570,7 @@ namespace ApiWithoutSecrets { } }; - if( vkCreateImageView( GetDevice(), &image_view_create_info, nullptr, &Vulkan.SwapChain.Images[i].ImageView ) != VK_SUCCESS ) { + if( vkCreateImageView( GetDevice(), &image_view_create_info, nullptr, &Vulkan.SwapChain.Images[i].View ) != VK_SUCCESS ) { std::cout << "Could not create image view for framebuffer!" << std::endl; return false; } @@ -700,8 +700,8 @@ namespace ApiWithoutSecrets { vkDeviceWaitIdle( Vulkan.Device ); for( size_t i = 0; i < Vulkan.SwapChain.Images.size(); ++i ) { - if( Vulkan.SwapChain.Images[i].ImageView != VK_NULL_HANDLE ) { - vkDestroyImageView( GetDevice(), Vulkan.SwapChain.Images[i].ImageView, nullptr ); + if( Vulkan.SwapChain.Images[i].View != VK_NULL_HANDLE ) { + vkDestroyImageView( GetDevice(), Vulkan.SwapChain.Images[i].View, nullptr ); } } diff --git a/Project/Common/VulkanCommon.h b/Project/Common/VulkanCommon.h index 31fe405..0184026 100644 --- a/Project/Common/VulkanCommon.h +++ b/Project/Common/VulkanCommon.h @@ -39,11 +39,15 @@ namespace ApiWithoutSecrets { // ************************************************************ // struct ImageParameters { VkImage Handle; - VkImageView ImageView; + VkImageView View; + VkSampler Sampler; + VkDeviceMemory Memory; ImageParameters() : Handle( VK_NULL_HANDLE ), - ImageView( VK_NULL_HANDLE ) { + View( VK_NULL_HANDLE ), + Sampler( VK_NULL_HANDLE ), + Memory( VK_NULL_HANDLE ) { } }; diff --git a/Project/Tutorial03/Tutorial03.cpp b/Project/Tutorial03/Tutorial03.cpp index 008175d..4674560 100644 --- a/Project/Tutorial03/Tutorial03.cpp +++ b/Project/Tutorial03/Tutorial03.cpp @@ -85,7 +85,7 @@ namespace ApiWithoutSecrets { 0, // VkFramebufferCreateFlags flags Vulkan.RenderPass, // VkRenderPass renderPass 1, // uint32_t attachmentCount - &swap_chain_images[i].ImageView, // const VkImageView *pAttachments + &swap_chain_images[i].View, // const VkImageView *pAttachments 300, // uint32_t width 300, // uint32_t height 1 // uint32_t layers diff --git a/Project/Tutorial04/Tutorial04.cpp b/Project/Tutorial04/Tutorial04.cpp index 177ad79..c75b4e7 100644 --- a/Project/Tutorial04/Tutorial04.cpp +++ b/Project/Tutorial04/Tutorial04.cpp @@ -457,7 +457,7 @@ namespace ApiWithoutSecrets { bool Tutorial04::AllocateBufferMemory( VkBuffer buffer, VkDeviceMemory *memory ) { VkMemoryRequirements buffer_memory_requirements; - vkGetBufferMemoryRequirements( GetDevice(), Vulkan.VertexBuffer.Handle, &buffer_memory_requirements ); + vkGetBufferMemoryRequirements( GetDevice(), buffer, &buffer_memory_requirements ); VkPhysicalDeviceMemoryProperties memory_properties; vkGetPhysicalDeviceMemoryProperties( GetPhysicalDevice(), &memory_properties ); @@ -482,7 +482,7 @@ namespace ApiWithoutSecrets { } bool Tutorial04::PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer ) { - if( !CreateFramebuffer( framebuffer, image_parameters.ImageView ) ) { + if( !CreateFramebuffer( framebuffer, image_parameters.View ) ) { return false; } diff --git a/Project/Tutorial05/Tutorial05.cpp b/Project/Tutorial05/Tutorial05.cpp index 31f82b6..40cf9bd 100644 --- a/Project/Tutorial05/Tutorial05.cpp +++ b/Project/Tutorial05/Tutorial05.cpp @@ -391,6 +391,7 @@ namespace ApiWithoutSecrets { Vulkan.VertexBuffer.Size = static_cast(vertex_data.size() * sizeof(vertex_data[0])); if( !CreateBuffer( VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, Vulkan.VertexBuffer ) ) { std::cout << "Could not create vertex buffer!" << std::endl; + return false; } return true; @@ -400,6 +401,7 @@ namespace ApiWithoutSecrets { Vulkan.StagingBuffer.Size = 4000; if( !CreateBuffer( VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, Vulkan.StagingBuffer ) ) { std::cout << "Could not staging buffer!" << std::endl; + return false; } return true; @@ -437,7 +439,7 @@ namespace ApiWithoutSecrets { bool Tutorial05::AllocateBufferMemory( VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory ) { VkMemoryRequirements buffer_memory_requirements; - vkGetBufferMemoryRequirements( GetDevice(), Vulkan.VertexBuffer.Handle, &buffer_memory_requirements ); + vkGetBufferMemoryRequirements( GetDevice(), buffer, &buffer_memory_requirements ); VkPhysicalDeviceMemoryProperties memory_properties; vkGetPhysicalDeviceMemoryProperties( GetPhysicalDevice(), &memory_properties ); @@ -559,7 +561,7 @@ namespace ApiWithoutSecrets { } bool Tutorial05::PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer ) { - if( !CreateFramebuffer( framebuffer, image_parameters.ImageView ) ) { + if( !CreateFramebuffer( framebuffer, image_parameters.View ) ) { return false; } diff --git a/Project/Tutorial05/Tutorial05.h b/Project/Tutorial05/Tutorial05.h index 67cb8e7..ac7c556 100644 --- a/Project/Tutorial05/Tutorial05.h +++ b/Project/Tutorial05/Tutorial05.h @@ -130,4 +130,4 @@ namespace ApiWithoutSecrets { } // namespace ApiWithoutSecrets -#endif // TUTORIAL_03_HEADER \ No newline at end of file +#endif // TUTORIAL_05_HEADER \ No newline at end of file diff --git a/Project/Tutorial05/main.cpp b/Project/Tutorial05/main.cpp index bb6294e..32fbe1d 100644 --- a/Project/Tutorial05/main.cpp +++ b/Project/Tutorial05/main.cpp @@ -24,7 +24,7 @@ int main( int argc, char **argv ) { return -1; } - // Tutorial 04 + // Tutorial 05 if( !tutorial05.CreateRenderPass() ) { return -1; }