From 3c9be8d22054c0920747e05342de10178c790a71 Mon Sep 17 00:00:00 2001 From: Tobias Frisch <tfrisch@uni-koblenz.de> Date: Sat, 8 Oct 2022 22:20:11 +0200 Subject: [PATCH] Adjust code with some changes for a memory priority extension Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de> --- include/vkcv/FeatureManager.hpp | 11 +++++ src/vkcv/BufferManager.cpp | 31 +++++++++++-- src/vkcv/FeatureManager.cpp | 9 ++++ src/vkcv/ImageManager.cpp | 81 ++++++++++++++++++++++++--------- 4 files changed, 106 insertions(+), 26 deletions(-) diff --git a/include/vkcv/FeatureManager.hpp b/include/vkcv/FeatureManager.hpp index f2138f6f..4a6be317 100644 --- a/include/vkcv/FeatureManager.hpp +++ b/include/vkcv/FeatureManager.hpp @@ -334,6 +334,17 @@ namespace vkcv { */ [[nodiscard]] bool checkSupport(const vk::PhysicalDeviceIndexTypeUint8FeaturesEXT &features, bool required) const; + + /** + * @brief Checks support of the @p vk::PhysicalDevicePageableDeviceLocalMemoryFeaturesEXT. + * + * @param[in] features The features + * @param[in] required True, if the @p features are required, else false + * @return @p True, if the @p features are supported, else @p false + */ + [[nodiscard]] bool + FeatureManager::checkSupport(const vk::PhysicalDevicePageableDeviceLocalMemoryFeaturesEXT &features, + bool required) const; /** * @brief Searches for a base structure of a given structure type. diff --git a/src/vkcv/BufferManager.cpp b/src/vkcv/BufferManager.cpp index 567041bb..62a2f86d 100644 --- a/src/vkcv/BufferManager.cpp +++ b/src/vkcv/BufferManager.cpp @@ -14,8 +14,13 @@ namespace vkcv { return false; } - m_stagingBuffer = createBuffer(TypeGuard(1), BufferType::STAGING, - BufferMemoryType::HOST_VISIBLE, 1024 * 1024, false); + m_stagingBuffer = createBuffer( + TypeGuard(1), + BufferType::STAGING, + BufferMemoryType::HOST_VISIBLE, + 1024 * 1024, + false + ); return true; } @@ -119,13 +124,29 @@ namespace vkcv { auto bufferAllocation = allocator.createBuffer( vk::BufferCreateInfo(createFlags, size, usageFlags), - vma::AllocationCreateInfo(vma::AllocationCreateFlags(), memoryUsage, memoryTypeFlags, - memoryTypeFlags, 0, vma::Pool(), nullptr)); + vma::AllocationCreateInfo( + vma::AllocationCreateFlags(), + memoryUsage, + memoryTypeFlags, + memoryTypeFlags, + 0, + vma::Pool(), + nullptr + ) + ); vk::Buffer buffer = bufferAllocation.first; vma::Allocation allocation = bufferAllocation.second; - return add({ typeGuard, type, memoryType, size, buffer, allocation, mappable }); + return add({ + typeGuard, + type, + memoryType, + size, + buffer, + allocation, + mappable + }); } /** diff --git a/src/vkcv/FeatureManager.cpp b/src/vkcv/FeatureManager.cpp index bc9640c7..503bfa59 100644 --- a/src/vkcv/FeatureManager.cpp +++ b/src/vkcv/FeatureManager.cpp @@ -485,6 +485,15 @@ namespace vkcv { return true; } + + bool FeatureManager::checkSupport(const vk::PhysicalDevicePageableDeviceLocalMemoryFeaturesEXT &features, + bool required) const { + vkcv_check_init_features2(vk::PhysicalDevicePageableDeviceLocalMemoryFeaturesEXT); + + vkcv_check_feature(pageableDeviceLocalMemory); + + return true; + } vk::BaseOutStructure* FeatureManager::findFeatureStructure(vk::StructureType type) const { for (auto &base : m_featuresExtensions) { diff --git a/src/vkcv/ImageManager.cpp b/src/vkcv/ImageManager.cpp index 993243cb..d65f5881 100644 --- a/src/vkcv/ImageManager.cpp +++ b/src/vkcv/ImageManager.cpp @@ -96,10 +96,17 @@ namespace vkcv { vk::ImageSubresourceLayers(aspectMask, srcMip, 0, 1), { vk::Offset3D(0, 0, 0), vk::Offset3D(srcWidth, srcHeight, srcDepth) }, vk::ImageSubresourceLayers(aspectMask, dstMip, 0, 1), - { vk::Offset3D(0, 0, 0), vk::Offset3D(dstWidth, dstHeight, dstDepth) }); - - cmdBuffer.blitImage(image.m_handle, vk::ImageLayout::eGeneral, image.m_handle, - vk::ImageLayout::eGeneral, region, vk::Filter::eLinear); + { vk::Offset3D(0, 0, 0), vk::Offset3D(dstWidth, dstHeight, dstDepth) } + ); + + cmdBuffer.blitImage( + image.m_handle, + vk::ImageLayout::eGeneral, + image.m_handle, + vk::ImageLayout::eGeneral, + region, + vk::Filter::eLinear + ); srcWidth = dstWidth; srcHeight = dstHeight; @@ -234,10 +241,16 @@ namespace vkcv { auto imageAllocation = allocator.createImage( imageCreateInfo, - vma::AllocationCreateInfo(vma::AllocationCreateFlags(), vma::MemoryUsage::eGpuOnly, - vk::MemoryPropertyFlagBits::eDeviceLocal, - vk::MemoryPropertyFlagBits::eDeviceLocal, 0, vma::Pool(), - nullptr)); + vma::AllocationCreateInfo( + vma::AllocationCreateFlags(), + vma::MemoryUsage::eGpuOnly, + vk::MemoryPropertyFlagBits::eDeviceLocal, + vk::MemoryPropertyFlagBits::eDeviceLocal, + 0, + vma::Pool(), + nullptr + ) + ); vk::Image image = imageAllocation.first; vma::Allocation allocation = imageAllocation.second; @@ -259,9 +272,19 @@ namespace vkcv { const vk::ImageViewCreateInfo imageViewCreateInfo( {}, image, imageViewType, format, vk::ComponentMapping( - vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, - vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity), - vk::ImageSubresourceRange(aspectFlags, mip, mipCount - mip, 0, arrayLayers)); + vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity + ), + vk::ImageSubresourceRange( + aspectFlags, + mip, + mipCount - mip, + 0, + arrayLayers + ) + ); views.push_back(device.createImageView(imageViewCreateInfo)); } @@ -270,20 +293,36 @@ namespace vkcv { const vk::ImageViewCreateInfo imageViewCreateInfo( {}, image, vk::ImageViewType::e2DArray, format, vk::ComponentMapping( - vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity, - vk::ComponentSwizzle::eIdentity, vk::ComponentSwizzle::eIdentity), - vk::ImageSubresourceRange(aspectFlags, mip, 1, 0, arrayLayers)); + vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity, + vk::ComponentSwizzle::eIdentity + ), + vk::ImageSubresourceRange( + aspectFlags, + mip, + 1, + 0, + arrayLayers + ) + ); arrayViews.push_back(device.createImageView(imageViewCreateInfo)); } - return add({ image, allocation, - - views, arrayViews, - - width, height, depth, - - format, arrayLayers, vk::ImageLayout::eUndefined, supportStorage }); + return add({ + image, + allocation, + views, + arrayViews, + width, + height, + depth, + format, + arrayLayers, + vk::ImageLayout::eUndefined, + supportStorage + }); } ImageHandle ImageManager::createSwapchainImage() const { -- GitLab