Moved queue family iteration code shared by KRDevice::createImage and KRDevice::createBuffer into a utility function.
Added imageCreateFlags argument to KRDevice::createImage
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user