Code cleanup

This commit is contained in:
Sascha Willems 2024-03-19 21:51:27 +01:00
parent 720afde027
commit a9ae9eafaa
3 changed files with 11 additions and 10 deletions

View file

@ -1,7 +1,7 @@
/* /*
* Vulkan Example base class * Vulkan Example base class
* *
* Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de * Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
* *
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/ */
@ -910,7 +910,7 @@ VulkanExampleBase::~VulkanExampleBase()
} }
vkDestroyImageView(device, depthStencil.view, nullptr); vkDestroyImageView(device, depthStencil.view, nullptr);
vkDestroyImage(device, depthStencil.image, nullptr); vkDestroyImage(device, depthStencil.image, nullptr);
vkFreeMemory(device, depthStencil.mem, nullptr); vkFreeMemory(device, depthStencil.memory, nullptr);
vkDestroyPipelineCache(device, pipelineCache, nullptr); vkDestroyPipelineCache(device, pipelineCache, nullptr);
@ -3007,8 +3007,8 @@ void VulkanExampleBase::setupDepthStencil()
memAllloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; memAllloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
memAllloc.allocationSize = memReqs.size; memAllloc.allocationSize = memReqs.size;
memAllloc.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); memAllloc.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
VK_CHECK_RESULT(vkAllocateMemory(device, &memAllloc, nullptr, &depthStencil.mem)); VK_CHECK_RESULT(vkAllocateMemory(device, &memAllloc, nullptr, &depthStencil.memory));
VK_CHECK_RESULT(vkBindImageMemory(device, depthStencil.image, depthStencil.mem, 0)); VK_CHECK_RESULT(vkBindImageMemory(device, depthStencil.image, depthStencil.memory, 0));
VkImageViewCreateInfo imageViewCI{}; VkImageViewCreateInfo imageViewCI{};
imageViewCI.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; imageViewCI.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
@ -3149,7 +3149,7 @@ void VulkanExampleBase::windowResize()
// Recreate the frame buffers // Recreate the frame buffers
vkDestroyImageView(device, depthStencil.view, nullptr); vkDestroyImageView(device, depthStencil.view, nullptr);
vkDestroyImage(device, depthStencil.image, nullptr); vkDestroyImage(device, depthStencil.image, nullptr);
vkFreeMemory(device, depthStencil.mem, nullptr); vkFreeMemory(device, depthStencil.memory, nullptr);
setupDepthStencil(); setupDepthStencil();
for (uint32_t i = 0; i < frameBuffers.size(); i++) { for (uint32_t i = 0; i < frameBuffers.size(); i++) {
vkDestroyFramebuffer(device, frameBuffers[i], nullptr); vkDestroyFramebuffer(device, frameBuffers[i], nullptr);

View file

@ -1,7 +1,7 @@
/* /*
* Vulkan Example base class * Vulkan Example base class
* *
* Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de * Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
* *
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/ */
@ -202,11 +202,12 @@ public:
std::string name = "vulkanExample"; std::string name = "vulkanExample";
uint32_t apiVersion = VK_API_VERSION_1_0; uint32_t apiVersion = VK_API_VERSION_1_0;
/** @brief Default depth stencil attachment used by the default render pass */
struct { struct {
VkImage image; VkImage image;
VkDeviceMemory mem; VkDeviceMemory memory;
VkImageView view; VkImageView view;
} depthStencil; } depthStencil{};
struct { struct {
glm::vec2 axisLeft = glm::vec2(0.0f); glm::vec2 axisLeft = glm::vec2(0.0f);

View file

@ -485,8 +485,8 @@ public:
vkGetImageMemoryRequirements(device, depthStencil.image, &memReqs); vkGetImageMemoryRequirements(device, depthStencil.image, &memReqs);
memAlloc.allocationSize = memReqs.size; memAlloc.allocationSize = memReqs.size;
memAlloc.memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); memAlloc.memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
VK_CHECK_RESULT(vkAllocateMemory(device, &memAlloc, nullptr, &depthStencil.mem)); VK_CHECK_RESULT(vkAllocateMemory(device, &memAlloc, nullptr, &depthStencil.memory));
VK_CHECK_RESULT(vkBindImageMemory(device, depthStencil.image, depthStencil.mem, 0)); VK_CHECK_RESULT(vkBindImageMemory(device, depthStencil.image, depthStencil.memory, 0));
// Create a view for the depth stencil image // Create a view for the depth stencil image
// Images aren't directly accessed in Vulkan, but rather through views described by a subresource range // Images aren't directly accessed in Vulkan, but rather through views described by a subresource range