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.

This commit is contained in:
plapins
2016-06-14 12:27:47 +02:00
parent 2c06d5d63f
commit 6bce4d9799
7 changed files with 21 additions and 15 deletions

View File

@@ -439,9 +439,9 @@ namespace ApiWithoutSecrets {
} }
for( size_t i = 0; i < Vulkan.SwapChain.Images.size(); ++i ) { for( size_t i = 0; i < Vulkan.SwapChain.Images.size(); ++i ) {
if( Vulkan.SwapChain.Images[i].ImageView != VK_NULL_HANDLE ) { if( Vulkan.SwapChain.Images[i].View != VK_NULL_HANDLE ) {
vkDestroyImageView( GetDevice(), Vulkan.SwapChain.Images[i].ImageView, nullptr ); vkDestroyImageView( GetDevice(), Vulkan.SwapChain.Images[i].View, nullptr );
Vulkan.SwapChain.Images[i].ImageView = VK_NULL_HANDLE; Vulkan.SwapChain.Images[i].View = VK_NULL_HANDLE;
} }
} }
Vulkan.SwapChain.Images.clear(); 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; std::cout << "Could not create image view for framebuffer!" << std::endl;
return false; return false;
} }
@@ -700,8 +700,8 @@ namespace ApiWithoutSecrets {
vkDeviceWaitIdle( Vulkan.Device ); vkDeviceWaitIdle( Vulkan.Device );
for( size_t i = 0; i < Vulkan.SwapChain.Images.size(); ++i ) { for( size_t i = 0; i < Vulkan.SwapChain.Images.size(); ++i ) {
if( Vulkan.SwapChain.Images[i].ImageView != VK_NULL_HANDLE ) { if( Vulkan.SwapChain.Images[i].View != VK_NULL_HANDLE ) {
vkDestroyImageView( GetDevice(), Vulkan.SwapChain.Images[i].ImageView, nullptr ); vkDestroyImageView( GetDevice(), Vulkan.SwapChain.Images[i].View, nullptr );
} }
} }

View File

@@ -39,11 +39,15 @@ namespace ApiWithoutSecrets {
// ************************************************************ // // ************************************************************ //
struct ImageParameters { struct ImageParameters {
VkImage Handle; VkImage Handle;
VkImageView ImageView; VkImageView View;
VkSampler Sampler;
VkDeviceMemory Memory;
ImageParameters() : ImageParameters() :
Handle( VK_NULL_HANDLE ), Handle( VK_NULL_HANDLE ),
ImageView( VK_NULL_HANDLE ) { View( VK_NULL_HANDLE ),
Sampler( VK_NULL_HANDLE ),
Memory( VK_NULL_HANDLE ) {
} }
}; };

View File

@@ -85,7 +85,7 @@ namespace ApiWithoutSecrets {
0, // VkFramebufferCreateFlags flags 0, // VkFramebufferCreateFlags flags
Vulkan.RenderPass, // VkRenderPass renderPass Vulkan.RenderPass, // VkRenderPass renderPass
1, // uint32_t attachmentCount 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 width
300, // uint32_t height 300, // uint32_t height
1 // uint32_t layers 1 // uint32_t layers

View File

@@ -457,7 +457,7 @@ namespace ApiWithoutSecrets {
bool Tutorial04::AllocateBufferMemory( VkBuffer buffer, VkDeviceMemory *memory ) { bool Tutorial04::AllocateBufferMemory( VkBuffer buffer, VkDeviceMemory *memory ) {
VkMemoryRequirements buffer_memory_requirements; VkMemoryRequirements buffer_memory_requirements;
vkGetBufferMemoryRequirements( GetDevice(), Vulkan.VertexBuffer.Handle, &buffer_memory_requirements ); vkGetBufferMemoryRequirements( GetDevice(), buffer, &buffer_memory_requirements );
VkPhysicalDeviceMemoryProperties memory_properties; VkPhysicalDeviceMemoryProperties memory_properties;
vkGetPhysicalDeviceMemoryProperties( GetPhysicalDevice(), &memory_properties ); vkGetPhysicalDeviceMemoryProperties( GetPhysicalDevice(), &memory_properties );
@@ -482,7 +482,7 @@ namespace ApiWithoutSecrets {
} }
bool Tutorial04::PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer ) { 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; return false;
} }

View File

@@ -391,6 +391,7 @@ namespace ApiWithoutSecrets {
Vulkan.VertexBuffer.Size = static_cast<uint32_t>(vertex_data.size() * sizeof(vertex_data[0])); Vulkan.VertexBuffer.Size = static_cast<uint32_t>(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 ) ) { 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; std::cout << "Could not create vertex buffer!" << std::endl;
return false;
} }
return true; return true;
@@ -400,6 +401,7 @@ namespace ApiWithoutSecrets {
Vulkan.StagingBuffer.Size = 4000; Vulkan.StagingBuffer.Size = 4000;
if( !CreateBuffer( VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, Vulkan.StagingBuffer ) ) { if( !CreateBuffer( VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, Vulkan.StagingBuffer ) ) {
std::cout << "Could not staging buffer!" << std::endl; std::cout << "Could not staging buffer!" << std::endl;
return false;
} }
return true; return true;
@@ -437,7 +439,7 @@ namespace ApiWithoutSecrets {
bool Tutorial05::AllocateBufferMemory( VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory ) { bool Tutorial05::AllocateBufferMemory( VkBuffer buffer, VkMemoryPropertyFlagBits property, VkDeviceMemory *memory ) {
VkMemoryRequirements buffer_memory_requirements; VkMemoryRequirements buffer_memory_requirements;
vkGetBufferMemoryRequirements( GetDevice(), Vulkan.VertexBuffer.Handle, &buffer_memory_requirements ); vkGetBufferMemoryRequirements( GetDevice(), buffer, &buffer_memory_requirements );
VkPhysicalDeviceMemoryProperties memory_properties; VkPhysicalDeviceMemoryProperties memory_properties;
vkGetPhysicalDeviceMemoryProperties( GetPhysicalDevice(), &memory_properties ); vkGetPhysicalDeviceMemoryProperties( GetPhysicalDevice(), &memory_properties );
@@ -559,7 +561,7 @@ namespace ApiWithoutSecrets {
} }
bool Tutorial05::PrepareFrame( VkCommandBuffer command_buffer, const ImageParameters &image_parameters, VkFramebuffer &framebuffer ) { 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; return false;
} }

View File

@@ -130,4 +130,4 @@ namespace ApiWithoutSecrets {
} // namespace ApiWithoutSecrets } // namespace ApiWithoutSecrets
#endif // TUTORIAL_03_HEADER #endif // TUTORIAL_05_HEADER

View File

@@ -24,7 +24,7 @@ int main( int argc, char **argv ) {
return -1; return -1;
} }
// Tutorial 04 // Tutorial 05
if( !tutorial05.CreateRenderPass() ) { if( !tutorial05.CreateRenderPass() ) {
return -1; return -1;
} }