mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
make depth-stencil images dedicated allocations
This commit is contained in:
parent
0cdc7403b9
commit
41174515a8
@ -70,8 +70,8 @@ namespace engine {
|
|||||||
struct FrameData {
|
struct FrameData {
|
||||||
VkFence renderFence = VK_NULL_HANDLE;
|
VkFence renderFence = VK_NULL_HANDLE;
|
||||||
VkSemaphore transferSemaphore = VK_NULL_HANDLE;
|
VkSemaphore transferSemaphore = VK_NULL_HANDLE;
|
||||||
VkSemaphore presentSemaphore = VK_NULL_HANDLE;
|
|
||||||
VkSemaphore renderSemaphore = VK_NULL_HANDLE;
|
VkSemaphore renderSemaphore = VK_NULL_HANDLE;
|
||||||
|
VkSemaphore presentSemaphore = VK_NULL_HANDLE;
|
||||||
|
|
||||||
VkCommandPool graphicsPool = VK_NULL_HANDLE;
|
VkCommandPool graphicsPool = VK_NULL_HANDLE;
|
||||||
VkCommandBuffer drawBuf = VK_NULL_HANDLE;
|
VkCommandBuffer drawBuf = VK_NULL_HANDLE;
|
||||||
@ -338,10 +338,11 @@ namespace engine {
|
|||||||
};
|
};
|
||||||
|
|
||||||
DeviceRequirements deviceRequirements{};
|
DeviceRequirements deviceRequirements{};
|
||||||
deviceRequirements.requiredExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_EXT_MEMORY_BUDGET_EXTENSION_NAME };
|
deviceRequirements.requiredExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
|
||||||
deviceRequirements.optionalExtensions = { VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME };
|
deviceRequirements.optionalExtensions.push_back(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME);
|
||||||
deviceRequirements.requiredFeatures.samplerAnisotropy = VK_TRUE;
|
deviceRequirements.optionalExtensions.push_back(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME);
|
||||||
deviceRequirements.requiredFeatures.fillModeNonSolid = VK_TRUE;
|
//deviceRequirements.requiredFeatures.samplerAnisotropy = VK_TRUE;
|
||||||
|
//deviceRequirements.requiredFeatures.fillModeNonSolid = VK_TRUE;
|
||||||
deviceRequirements.formats.push_back(
|
deviceRequirements.formats.push_back(
|
||||||
FormatRequirements{
|
FormatRequirements{
|
||||||
.format = VK_FORMAT_R8G8B8A8_SRGB,
|
.format = VK_FORMAT_R8G8B8A8_SRGB,
|
||||||
@ -423,8 +424,8 @@ namespace engine {
|
|||||||
.flags = 0
|
.flags = 0
|
||||||
};
|
};
|
||||||
VKCHECK(vkCreateSemaphore(pimpl->device.device, &smphInfo, nullptr, &pimpl->frameData[i].transferSemaphore));
|
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].renderSemaphore));
|
||||||
|
VKCHECK(vkCreateSemaphore(pimpl->device.device, &smphInfo, nullptr, &pimpl->frameData[i].presentSemaphore));
|
||||||
|
|
||||||
VkCommandPoolCreateInfo poolInfo{
|
VkCommandPoolCreateInfo poolInfo{
|
||||||
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
||||||
@ -479,10 +480,10 @@ namespace engine {
|
|||||||
vkDestroyCommandPool(pimpl->device.device, pimpl->transferCommandPool, nullptr);
|
vkDestroyCommandPool(pimpl->device.device, pimpl->transferCommandPool, nullptr);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < FRAMES_IN_FLIGHT; i++) {
|
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);
|
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].presentSemaphore, nullptr);
|
||||||
|
vkDestroySemaphore(pimpl->device.device, pimpl->frameData[i].renderSemaphore, nullptr);
|
||||||
vkDestroySemaphore(pimpl->device.device, pimpl->frameData[i].transferSemaphore, nullptr);
|
vkDestroySemaphore(pimpl->device.device, pimpl->frameData[i].transferSemaphore, nullptr);
|
||||||
vkDestroyFence(pimpl->device.device, pimpl->frameData[i].renderFence, nullptr);
|
vkDestroyFence(pimpl->device.device, pimpl->frameData[i].renderFence, nullptr);
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,6 @@ namespace engine {
|
|||||||
res = vkEnumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, nullptr);
|
res = vkEnumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, nullptr);
|
||||||
assert(res == VK_SUCCESS);
|
assert(res == VK_SUCCESS);
|
||||||
availableExtensions.resize(extensionCount);
|
availableExtensions.resize(extensionCount);
|
||||||
std::vector<VkExtensionProperties> availableExtensions(extensionCount);
|
|
||||||
res = vkEnumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, availableExtensions.data());
|
res = vkEnumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, availableExtensions.data());
|
||||||
assert(res == VK_SUCCESS);
|
assert(res == VK_SUCCESS);
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ namespace engine {
|
|||||||
};
|
};
|
||||||
|
|
||||||
VmaAllocatorCreateInfo createInfo{
|
VmaAllocatorCreateInfo createInfo{
|
||||||
.flags = VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT,
|
.flags = 0,
|
||||||
.physicalDevice = device.physicalDevice,
|
.physicalDevice = device.physicalDevice,
|
||||||
.device = device.device,
|
.device = device.device,
|
||||||
.preferredLargeHeapBlockSize = 0,
|
.preferredLargeHeapBlockSize = 0,
|
||||||
@ -61,6 +61,10 @@ namespace engine {
|
|||||||
std::string(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME)) != device.enabledExtensions.end()) {
|
std::string(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME)) != device.enabledExtensions.end()) {
|
||||||
createInfo.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT;
|
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;
|
[[maybe_unused]] VkResult res;
|
||||||
VmaAllocator allocator;
|
VmaAllocator allocator;
|
||||||
|
@ -300,9 +300,11 @@ namespace engine {
|
|||||||
depthAllocInfo.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
|
depthAllocInfo.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
|
||||||
depthAllocInfo.priority = 1.0f; // this is ignored if VK_EXT_memory_priority isn't found
|
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
|
// "Consider creating them as dedicated allocations using VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT,
|
||||||
// https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/vk_khr_dedicated_allocation.html
|
// especially if they are large or if you plan to destroy and recreate them with different sizes
|
||||||
depthAllocInfo.flags = 0;
|
// 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);
|
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));
|
if (res != VK_SUCCESS) throw std::runtime_error("Failed to create depth buffer image! Code: " + std::to_string(res));
|
||||||
|
Loading…
Reference in New Issue
Block a user