diff --git a/src/gfx_device_vulkan.cpp b/src/gfx_device_vulkan.cpp index e39391e..01518aa 100644 --- a/src/gfx_device_vulkan.cpp +++ b/src/gfx_device_vulkan.cpp @@ -70,8 +70,8 @@ namespace engine { struct FrameData { VkFence renderFence = VK_NULL_HANDLE; VkSemaphore transferSemaphore = VK_NULL_HANDLE; - VkSemaphore presentSemaphore = VK_NULL_HANDLE; VkSemaphore renderSemaphore = VK_NULL_HANDLE; + VkSemaphore presentSemaphore = VK_NULL_HANDLE; VkCommandPool graphicsPool = VK_NULL_HANDLE; VkCommandBuffer drawBuf = VK_NULL_HANDLE; @@ -338,10 +338,11 @@ namespace engine { }; DeviceRequirements deviceRequirements{}; - deviceRequirements.requiredExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_EXT_MEMORY_BUDGET_EXTENSION_NAME }; - deviceRequirements.optionalExtensions = { VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME }; - deviceRequirements.requiredFeatures.samplerAnisotropy = VK_TRUE; - deviceRequirements.requiredFeatures.fillModeNonSolid = VK_TRUE; + deviceRequirements.requiredExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); + deviceRequirements.optionalExtensions.push_back(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME); + deviceRequirements.optionalExtensions.push_back(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME); + //deviceRequirements.requiredFeatures.samplerAnisotropy = VK_TRUE; + //deviceRequirements.requiredFeatures.fillModeNonSolid = VK_TRUE; deviceRequirements.formats.push_back( FormatRequirements{ .format = VK_FORMAT_R8G8B8A8_SRGB, @@ -423,8 +424,8 @@ namespace engine { .flags = 0 }; VKCHECK(vkCreateSemaphore(pimpl->device.device, &smphInfo, nullptr, &pimpl->frameData[i].transferSemaphore)); - VKCHECK(vkCreateSemaphore(pimpl->device.device, &smphInfo, nullptr, &pimpl->frameData[i].presentSemaphore)); VKCHECK(vkCreateSemaphore(pimpl->device.device, &smphInfo, nullptr, &pimpl->frameData[i].renderSemaphore)); + VKCHECK(vkCreateSemaphore(pimpl->device.device, &smphInfo, nullptr, &pimpl->frameData[i].presentSemaphore)); VkCommandPoolCreateInfo poolInfo{ .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, @@ -479,10 +480,10 @@ namespace engine { vkDestroyCommandPool(pimpl->device.device, pimpl->transferCommandPool, nullptr); for (uint32_t i = 0; i < FRAMES_IN_FLIGHT; i++) { - vkDestroyCommandPool(pimpl->device.device, pimpl->frameData[i].graphicsPool, nullptr); vkDestroyCommandPool(pimpl->device.device, pimpl->frameData[i].transferPool, nullptr); - vkDestroySemaphore(pimpl->device.device, pimpl->frameData[i].renderSemaphore, nullptr); + vkDestroyCommandPool(pimpl->device.device, pimpl->frameData[i].graphicsPool, nullptr); vkDestroySemaphore(pimpl->device.device, pimpl->frameData[i].presentSemaphore, nullptr); + vkDestroySemaphore(pimpl->device.device, pimpl->frameData[i].renderSemaphore, nullptr); vkDestroySemaphore(pimpl->device.device, pimpl->frameData[i].transferSemaphore, nullptr); vkDestroyFence(pimpl->device.device, pimpl->frameData[i].renderFence, nullptr); } diff --git a/src/vulkan/device.cpp b/src/vulkan/device.cpp index 1f41b81..145f0c1 100644 --- a/src/vulkan/device.cpp +++ b/src/vulkan/device.cpp @@ -47,7 +47,6 @@ namespace engine { res = vkEnumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, nullptr); assert(res == VK_SUCCESS); availableExtensions.resize(extensionCount); - std::vector availableExtensions(extensionCount); res = vkEnumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, availableExtensions.data()); assert(res == VK_SUCCESS); diff --git a/src/vulkan/gpu_allocator.cpp b/src/vulkan/gpu_allocator.cpp index bcfddf3..8aaf6a6 100644 --- a/src/vulkan/gpu_allocator.cpp +++ b/src/vulkan/gpu_allocator.cpp @@ -44,7 +44,7 @@ namespace engine { }; VmaAllocatorCreateInfo createInfo{ - .flags = VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT, + .flags = 0, .physicalDevice = device.physicalDevice, .device = device.device, .preferredLargeHeapBlockSize = 0, @@ -61,6 +61,10 @@ namespace engine { std::string(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME)) != device.enabledExtensions.end()) { createInfo.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT; } + if (std::find(device.enabledExtensions.begin(), device.enabledExtensions.end(), + std::string(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME)) != device.enabledExtensions.end()) { + createInfo.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT; + } [[maybe_unused]] VkResult res; VmaAllocator allocator; diff --git a/src/vulkan/swapchain.cpp b/src/vulkan/swapchain.cpp index 4ebea9a..9a3050c 100644 --- a/src/vulkan/swapchain.cpp +++ b/src/vulkan/swapchain.cpp @@ -300,9 +300,11 @@ namespace engine { depthAllocInfo.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE; depthAllocInfo.priority = 1.0f; // this is ignored if VK_EXT_memory_priority isn't found - // VMA automatically detects whether to use VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT - // https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/vk_khr_dedicated_allocation.html - depthAllocInfo.flags = 0; + // "Consider creating them as dedicated allocations using VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT, + // especially if they are large or if you plan to destroy and recreate them with different sizes + // e.g. when display resolution changes." + // https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/usage_patterns.html + depthAllocInfo.flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; res = vmaCreateImage(sc->allocator, &depthImageInfo, &depthAllocInfo, &depthImage, &depthAllocation, nullptr); if (res != VK_SUCCESS) throw std::runtime_error("Failed to create depth buffer image! Code: " + std::to_string(res));