Implementing MipMap support for Vulkan
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
This commit is contained in:
@@ -788,15 +788,6 @@ void KRDevice::streamUpload(void* data, size_t size, Vector3i dimensions, VkImag
|
|||||||
streamUploadImpl(size, dimensions, destination, 0, 1);
|
streamUploadImpl(size, dimensions, destination, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRDevice::streamUpload(Block& data, VkImage destination, size_t offset, size_t size, Vector3i dimensions, uint32_t baseMipLevel, uint32_t levelCount)
|
|
||||||
{
|
|
||||||
checkFlushStreamBuffer(size);
|
|
||||||
|
|
||||||
data.copy((uint8_t*)m_streamingStagingBuffer.data + m_streamingStagingBuffer.usage, offset, size);
|
|
||||||
|
|
||||||
streamUploadImpl(size, dimensions, destination, 0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void KRDevice::streamUploadImpl(size_t size, Vector3i dimensions, VkImage destination, uint32_t baseMipLevel, uint32_t levelCount)
|
void KRDevice::streamUploadImpl(size_t size, Vector3i dimensions, VkImage destination, uint32_t baseMipLevel, uint32_t levelCount)
|
||||||
{
|
{
|
||||||
// TODO - Refactor memory barriers into helper functions
|
// TODO - Refactor memory barriers into helper functions
|
||||||
@@ -812,9 +803,9 @@ void KRDevice::streamUploadImpl(size_t size, Vector3i dimensions, VkImage destin
|
|||||||
barrier.image = destination;
|
barrier.image = destination;
|
||||||
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
barrier.subresourceRange.baseMipLevel = 0;
|
barrier.subresourceRange.baseMipLevel = 0;
|
||||||
barrier.subresourceRange.levelCount = 1;
|
barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
|
||||||
barrier.subresourceRange.baseArrayLayer = 0;
|
barrier.subresourceRange.baseArrayLayer = 0;
|
||||||
barrier.subresourceRange.layerCount = 1;
|
barrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
||||||
|
|
||||||
// For VK_IMAGE_LAYOUT_UNDEFINED -> VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
|
// For VK_IMAGE_LAYOUT_UNDEFINED -> VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
|
||||||
barrier.srcAccessMask = 0;
|
barrier.srcAccessMask = 0;
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ public:
|
|||||||
|
|
||||||
void streamStart();
|
void streamStart();
|
||||||
void streamUpload(mimir::Block& data, VkBuffer destination);
|
void streamUpload(mimir::Block& data, VkBuffer destination);
|
||||||
void streamUpload(mimir::Block& data, VkImage destination, size_t offset, size_t size, hydra::Vector3i dimensions, uint32_t baseMipLevel, uint32_t levelCount);
|
|
||||||
void streamUpload(void* data, size_t size, VkBuffer destination);
|
void streamUpload(void* data, size_t size, VkBuffer destination);
|
||||||
void streamUpload(void* data, size_t size, hydra::Vector3i dimensions, VkImage destination);
|
void streamUpload(void* data, size_t size, hydra::Vector3i dimensions, VkImage destination);
|
||||||
void streamEnd();
|
void streamEnd();
|
||||||
|
|||||||
@@ -288,21 +288,23 @@ VkImage KRTexture::getImage(KrDeviceHandle device)
|
|||||||
return VK_NULL_HANDLE;
|
return VK_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KRTexture::allocate(KRDevice& device, hydra::Vector3i dimensions, VkImageCreateFlags imageCreateFlags, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation
|
bool KRTexture::allocate(KRDevice& device, int target_lod, VkImageCreateFlags imageCreateFlags, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, const char* debug_label
|
, const char* debug_label
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
hydra::Vector3i dimensions = getDimensions() / (1 << target_lod);
|
||||||
|
|
||||||
VkImageCreateInfo imageInfo{};
|
VkImageCreateInfo imageInfo{};
|
||||||
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||||
imageInfo.imageType = VK_IMAGE_TYPE_2D;
|
imageInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||||
imageInfo.extent.width = static_cast<uint32_t>(dimensions.x);
|
imageInfo.extent.width = static_cast<uint32_t>(dimensions.x);
|
||||||
imageInfo.extent.height = static_cast<uint32_t>(dimensions.y);
|
imageInfo.extent.height = static_cast<uint32_t>(dimensions.y);
|
||||||
imageInfo.extent.depth = static_cast<uint32_t>(dimensions.z);
|
imageInfo.extent.depth = static_cast<uint32_t>(dimensions.z);
|
||||||
imageInfo.mipLevels = 1;
|
imageInfo.mipLevels = KRMAX(m_lod_count - target_lod, 1);
|
||||||
imageInfo.arrayLayers = 1;
|
imageInfo.arrayLayers = 1;
|
||||||
imageInfo.format = VK_FORMAT_R8G8B8A8_SRGB;
|
imageInfo.format = getFormat();
|
||||||
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||||
imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ protected:
|
|||||||
float m_last_frame_max_lod_coverage;
|
float m_last_frame_max_lod_coverage;
|
||||||
texture_usage_t m_last_frame_usage;
|
texture_usage_t m_last_frame_usage;
|
||||||
|
|
||||||
bool allocate(KRDevice& device, hydra::Vector3i dimensions, VkImageCreateFlags imageCreateFlags, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation
|
bool allocate(KRDevice& device, int target_lod, VkImageCreateFlags imageCreateFlags, VkMemoryPropertyFlags properties, VkImage* image, VmaAllocation* allocation
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, const char* debug_label
|
, const char* debug_label
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ bool KRTexture2D::createGPUTexture(int lod)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
int prev_lod = m_new_lod;
|
int target_lod = m_new_lod;
|
||||||
m_new_lod = -1;
|
m_new_lod = -1;
|
||||||
|
|
||||||
KRDeviceManager* deviceManager = getContext().getDeviceManager();
|
KRDeviceManager* deviceManager = getContext().getDeviceManager();
|
||||||
@@ -76,7 +76,7 @@ bool KRTexture2D::createGPUTexture(int lod)
|
|||||||
texture.allocation = VK_NULL_HANDLE;
|
texture.allocation = VK_NULL_HANDLE;
|
||||||
texture.image = VK_NULL_HANDLE;
|
texture.image = VK_NULL_HANDLE;
|
||||||
|
|
||||||
if (!allocate(device, getDimensions(), 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture.image, &texture.allocation
|
if (!allocate(device, target_lod, 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture.image, &texture.allocation
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, getName().c_str()
|
, getName().c_str()
|
||||||
#endif
|
#endif
|
||||||
@@ -92,7 +92,7 @@ bool KRTexture2D::createGPUTexture(int lod)
|
|||||||
viewInfo.format = getFormat();
|
viewInfo.format = getFormat();
|
||||||
viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
viewInfo.subresourceRange.baseMipLevel = 0;
|
viewInfo.subresourceRange.baseMipLevel = 0;
|
||||||
viewInfo.subresourceRange.levelCount = 1;
|
viewInfo.subresourceRange.levelCount = KRMAX(m_lod_count - target_lod, 1);
|
||||||
viewInfo.subresourceRange.baseArrayLayer = 0;
|
viewInfo.subresourceRange.baseArrayLayer = 0;
|
||||||
viewInfo.subresourceRange.layerCount = 1;
|
viewInfo.subresourceRange.layerCount = 1;
|
||||||
VkResult res = vkCreateImageView(device.m_logicalDevice, &viewInfo, nullptr, &texture.fullImageView);
|
VkResult res = vkCreateImageView(device.m_logicalDevice, &viewInfo, nullptr, &texture.fullImageView);
|
||||||
@@ -107,7 +107,7 @@ bool KRTexture2D::createGPUTexture(int lod)
|
|||||||
delete buffer;
|
delete buffer;
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
m_new_lod = prev_lod;
|
m_new_lod = target_lod;
|
||||||
m_haveNewHandles = true;
|
m_haveNewHandles = true;
|
||||||
} else {
|
} else {
|
||||||
destroyNewHandles();
|
destroyNewHandles();
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ bool KRTextureCube::createGPUTexture(int lod)
|
|||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
int prev_lod = m_new_lod;
|
int target_lod = m_new_lod;
|
||||||
m_new_lod = -1;
|
m_new_lod = -1;
|
||||||
bool bMipMaps = false;
|
bool bMipMaps = false;
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ bool KRTextureCube::createGPUTexture(int lod)
|
|||||||
texture.allocation = VK_NULL_HANDLE;
|
texture.allocation = VK_NULL_HANDLE;
|
||||||
texture.image = VK_NULL_HANDLE;
|
texture.image = VK_NULL_HANDLE;
|
||||||
|
|
||||||
if (!allocate(device, Vector3i::Create(dimensions.x, dimensions.y, 1), VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture.image, &texture.allocation
|
if (!allocate(device, target_lod, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &texture.image, &texture.allocation
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, getName().c_str()
|
, getName().c_str()
|
||||||
#endif
|
#endif
|
||||||
@@ -130,7 +130,7 @@ bool KRTextureCube::createGPUTexture(int lod)
|
|||||||
m_haveNewHandles = true;
|
m_haveNewHandles = true;
|
||||||
} else {
|
} else {
|
||||||
destroyHandles();
|
destroyHandles();
|
||||||
m_new_lod = prev_lod;
|
m_new_lod = target_lod;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user