From 83ea50384f1eba479189fbad80a63f24eb013939 Mon Sep 17 00:00:00 2001 From: kearwood Date: Sat, 16 Jul 2022 00:45:17 -0700 Subject: [PATCH] Moved queue family iteration code shared by KRDevice::createImage and KRDevice::createBuffer into a utility function. Added imageCreateFlags argument to KRDevice::createImage --- kraken/KRDevice.cpp | 31 +++++++++++++++---------------- kraken/KRDevice.h | 4 +++- kraken/KRTexture2D.cpp | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/kraken/KRDevice.cpp b/kraken/KRDevice.cpp index d9ba92d..23a7696 100644 --- a/kraken/KRDevice.cpp +++ b/kraken/KRDevice.cpp @@ -430,17 +430,18 @@ VmaAllocator KRDevice::getAllocator() return m_allocator; } -bool KRDevice::createImage(Vector2i dimensions, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation) +void KRDevice::getQueueFamiliesForSharing(uint32_t* queueFamilyIndices, uint32_t* familyCount) { - // TODO - Break block into own function to be shared with createBuffer - int familyCount = 1; - uint32_t queueFamilyIndices[2] = {}; + *familyCount = 1; queueFamilyIndices[0] = m_graphicsFamilyQueueIndex; if (m_graphicsFamilyQueueIndex != m_transferFamilyQueueIndex) { queueFamilyIndices[1] = m_transferFamilyQueueIndex; - familyCount++; + *familyCount++; } +} +bool KRDevice::createImage(Vector2i dimensions, VkImageCreateFlags imageCreateFlags, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation) +{ VkImageCreateInfo imageInfo{}; imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; imageInfo.imageType = VK_IMAGE_TYPE_2D; @@ -454,10 +455,13 @@ bool KRDevice::createImage(Vector2i dimensions, VkMemoryPropertyFlags properties imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; - imageInfo.flags = 0; + imageInfo.flags = imageCreateFlags; imageInfo.sharingMode = VK_SHARING_MODE_CONCURRENT; + + uint32_t queueFamilyIndices[2] = {}; imageInfo.pQueueFamilyIndices = queueFamilyIndices; - imageInfo.queueFamilyIndexCount = familyCount; + imageInfo.queueFamilyIndexCount = 0; + getQueueFamiliesForSharing(queueFamilyIndices, &imageInfo.queueFamilyIndexCount); VmaAllocationCreateInfo allocInfo = {}; allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; @@ -476,20 +480,15 @@ bool KRDevice::createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemor #endif ) { - int familyCount = 1; - uint32_t queueFamilyIndices[2] = {}; - queueFamilyIndices[0] = m_graphicsFamilyQueueIndex; - if (m_graphicsFamilyQueueIndex != m_transferFamilyQueueIndex) { - queueFamilyIndices[1] = m_transferFamilyQueueIndex; - familyCount++; - } - VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; bufferInfo.size = size; bufferInfo.usage = usage; bufferInfo.sharingMode = VK_SHARING_MODE_CONCURRENT; - bufferInfo.queueFamilyIndexCount = familyCount; + + uint32_t queueFamilyIndices[2] = {}; bufferInfo.pQueueFamilyIndices = queueFamilyIndices; + bufferInfo.queueFamilyIndexCount = 0; + getQueueFamiliesForSharing(queueFamilyIndices, &bufferInfo.queueFamilyIndexCount); VmaAllocationCreateInfo allocInfo = {}; allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; diff --git a/kraken/KRDevice.h b/kraken/KRDevice.h index ce55557..e088628 100644 --- a/kraken/KRDevice.h +++ b/kraken/KRDevice.h @@ -55,7 +55,7 @@ public: #endif ); - bool createImage(Vector2i dimensions, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation); + bool createImage(Vector2i dimensions, VkImageCreateFlags imageCreateFlags, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation); KrResult selectSurfaceFormat(VkSurfaceKHR& surface, VkSurfaceFormatKHR& surfaceFormat); KrResult selectDepthFormat(VkFormat& selectedDepthFormat); @@ -103,4 +103,6 @@ public: size_t m_graphicsStagingBufferUsage; void* m_graphicsStagingBufferData; private: + + void getQueueFamiliesForSharing(uint32_t* queueFamilyIndices, uint32_t* familyCount); }; diff --git a/kraken/KRTexture2D.cpp b/kraken/KRTexture2D.cpp index a1923b2..aa87a7a 100755 --- a/kraken/KRTexture2D.cpp +++ b/kraken/KRTexture2D.cpp @@ -61,7 +61,7 @@ bool KRTexture2D::createGPUTexture(int lod_max_dim) { texture.allocation = VK_NULL_HANDLE; texture.image = VK_NULL_HANDLE; - if (!device.createImage(getDimensions(), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture.image, &texture.allocation)) { + if (!device.createImage(getDimensions(), 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture.image, &texture.allocation)) { success = false; break; }