Move KRDevice::createImage to KRTexture::allocate
This commit is contained in:
@@ -591,48 +591,6 @@ void KRDevice::setDebugLabel(const VkDevice& device, const char* debugLabel)
|
||||
|
||||
#endif // KRENGINE_DEBUG_GPU_LABELS
|
||||
|
||||
|
||||
bool KRDevice::createImage(Vector2i dimensions, VkImageCreateFlags imageCreateFlags, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation
|
||||
#if KRENGINE_DEBUG_GPU_LABELS
|
||||
, const char* debug_label
|
||||
#endif
|
||||
)
|
||||
{
|
||||
VkImageCreateInfo imageInfo{};
|
||||
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
imageInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||
imageInfo.extent.width = static_cast<uint32_t>(dimensions.x);
|
||||
imageInfo.extent.height = static_cast<uint32_t>(dimensions.y);
|
||||
imageInfo.extent.depth = 1;
|
||||
imageInfo.mipLevels = 1;
|
||||
imageInfo.arrayLayers = 1;
|
||||
imageInfo.format = VK_FORMAT_R8G8B8A8_SRGB;
|
||||
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
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 = imageCreateFlags;
|
||||
|
||||
|
||||
uint32_t queueFamilyIndices[2] = {};
|
||||
imageInfo.pQueueFamilyIndices = queueFamilyIndices;
|
||||
imageInfo.queueFamilyIndexCount = 0;
|
||||
getQueueFamiliesForSharing(queueFamilyIndices, &imageInfo.queueFamilyIndexCount, &imageInfo.sharingMode);
|
||||
|
||||
VmaAllocationCreateInfo allocInfo = {};
|
||||
allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
|
||||
allocInfo.requiredFlags = properties;
|
||||
|
||||
VkResult res = vmaCreateImage(m_allocator, &imageInfo, &allocInfo, image, allocation, nullptr);
|
||||
if (res != VK_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
#if KRENGINE_DEBUG_GPU_LABELS
|
||||
setDebugLabel(*image, debug_label);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KRDevice::createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer* buffer, VmaAllocation* allocation
|
||||
#if KRENGINE_DEBUG_GPU_LABELS
|
||||
, const char* debug_label
|
||||
|
||||
@@ -64,12 +64,6 @@ public:
|
||||
#endif
|
||||
);
|
||||
|
||||
bool createImage(Vector2i dimensions, VkImageCreateFlags imageCreateFlags, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation
|
||||
#if KRENGINE_DEBUG_GPU_LABELS
|
||||
, const char* debug_label
|
||||
#endif
|
||||
);
|
||||
|
||||
KrResult selectSurfaceFormat(VkSurfaceKHR& surface, VkSurfaceFormatKHR& surfaceFormat) const;
|
||||
KrResult selectDepthFormat(VkFormat& selectedDepthFormat) const;
|
||||
KrResult selectPresentMode(VkSurfaceKHR& surface, VkPresentModeKHR& selectedPresentMode) const;
|
||||
@@ -126,10 +120,10 @@ public:
|
||||
// This will be used for uploading assets procedurally generated while recording the graphics command buffer.
|
||||
// TODO - We should allocate at least two of these and double-buffer for increased CPU-GPU concurrency
|
||||
StagingBufferInfo m_graphicsStagingBuffer;
|
||||
private:
|
||||
void checkFlushStreamBuffer(size_t size);
|
||||
|
||||
void getQueueFamiliesForSharing(uint32_t* queueFamilyIndices, uint32_t* familyCount, VkSharingMode* sharingMode);
|
||||
private:
|
||||
void checkFlushStreamBuffer(size_t size);
|
||||
|
||||
// Initialization helper functions
|
||||
bool getAndCheckDeviceCapabilities(const std::vector<const char*>& deviceExtensions);
|
||||
|
||||
@@ -280,3 +280,43 @@ VkImage KRTexture::getImage(KrDeviceHandle device)
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
bool KRTexture::allocate(KRDevice& device, Vector2i dimensions, VkImageCreateFlags imageCreateFlags, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation
|
||||
#if KRENGINE_DEBUG_GPU_LABELS
|
||||
, const char* debug_label
|
||||
#endif
|
||||
)
|
||||
{
|
||||
VkImageCreateInfo imageInfo{};
|
||||
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
imageInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||
imageInfo.extent.width = static_cast<uint32_t>(dimensions.x);
|
||||
imageInfo.extent.height = static_cast<uint32_t>(dimensions.y);
|
||||
imageInfo.extent.depth = 1;
|
||||
imageInfo.mipLevels = 1;
|
||||
imageInfo.arrayLayers = 1;
|
||||
imageInfo.format = VK_FORMAT_R8G8B8A8_SRGB;
|
||||
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
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 = imageCreateFlags;
|
||||
|
||||
|
||||
uint32_t queueFamilyIndices[2] = {};
|
||||
imageInfo.pQueueFamilyIndices = queueFamilyIndices;
|
||||
imageInfo.queueFamilyIndexCount = 0;
|
||||
device.getQueueFamiliesForSharing(queueFamilyIndices, &imageInfo.queueFamilyIndexCount, &imageInfo.sharingMode);
|
||||
|
||||
VmaAllocationCreateInfo allocInfo = {};
|
||||
allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
|
||||
allocInfo.requiredFlags = properties;
|
||||
|
||||
VkResult res = vmaCreateImage(device.getAllocator(), &imageInfo, &allocInfo, image, allocation, nullptr);
|
||||
if (res != VK_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
#if KRENGINE_DEBUG_GPU_LABELS
|
||||
device.setDebugLabel(*image, debug_label);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
class KRDataBlock;
|
||||
class KRCamera;
|
||||
class KRDeviceManager;
|
||||
class KRDevice;
|
||||
|
||||
class KRTexture : public KRResource
|
||||
{
|
||||
@@ -125,6 +126,12 @@ protected:
|
||||
float m_last_frame_max_lod_coverage;
|
||||
texture_usage_t m_last_frame_usage;
|
||||
|
||||
bool allocate(KRDevice& device, Vector2i dimensions, VkImageCreateFlags imageCreateFlags, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation
|
||||
#if KRENGINE_DEBUG_GPU_LABELS
|
||||
, const char* debug_label
|
||||
#endif
|
||||
);
|
||||
|
||||
private:
|
||||
std::atomic<long> m_textureMemUsed;
|
||||
std::atomic<long> m_newTextureMemUsed;
|
||||
|
||||
@@ -64,7 +64,7 @@ bool KRTexture2D::createGPUTexture(int lod_max_dim)
|
||||
texture.allocation = VK_NULL_HANDLE;
|
||||
texture.image = VK_NULL_HANDLE;
|
||||
|
||||
if (!device.createImage(getDimensions(), 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture.image, &texture.allocation
|
||||
if (!allocate(device, getDimensions(), 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture.image, &texture.allocation
|
||||
#if KRENGINE_DEBUG_GPU_LABELS
|
||||
, getName().c_str()
|
||||
#endif
|
||||
|
||||
@@ -101,7 +101,7 @@ bool KRTextureCube::createGPUTexture(int lod_max_dim)
|
||||
texture.allocation = VK_NULL_HANDLE;
|
||||
texture.image = VK_NULL_HANDLE;
|
||||
|
||||
if (!device.createImage(dimensions, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture.image, &texture.allocation
|
||||
if (!allocate(device, dimensions, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture.image, &texture.allocation
|
||||
#if KRENGINE_DEBUG_GPU_LABELS
|
||||
, getName().c_str()
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user