replace copy with blit, allowing for most swapchain formats

fixes #1
This commit is contained in:
PancakeTAS 2025-07-06 16:14:53 +02:00
parent 4ad1ea8523
commit 27eeea3d0c
No known key found for this signature in database
3 changed files with 25 additions and 16 deletions

View file

@ -186,15 +186,16 @@ namespace Layer {
const VkBufferMemoryBarrier* pBufferMemoryBarriers,
uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier* pImageMemoryBarriers);
/// Call to the original vkCmdCopyImage function.
void ovkCmdCopyImage(
/// Call to the original vkCmdBlitImage function.
void ovkCmdBlitImage(
VkCommandBuffer commandBuffer,
VkImage srcImage,
VkImageLayout srcImageLayout,
VkImage dstImage,
VkImageLayout dstImageLayout,
uint32_t regionCount,
const VkImageCopy* pRegions);
const VkImageBlit* pRegions,
VkFilter filter);
/// Call to the original vkAcquireNextImageKHR function.
VkResult ovkAcquireNextImageKHR(

View file

@ -46,7 +46,7 @@ namespace {
PFN_vkGetDeviceQueue next_vkGetDeviceQueue{};
PFN_vkQueueSubmit next_vkQueueSubmit{};
PFN_vkCmdPipelineBarrier next_vkCmdPipelineBarrier{};
PFN_vkCmdCopyImage next_vkCmdCopyImage{};
PFN_vkCmdBlitImage next_vkCmdBlitImage{};
PFN_vkAcquireNextImageKHR next_vkAcquireNextImageKHR{};
template<typename T>
@ -195,7 +195,7 @@ namespace {
success &= initDeviceFunc(*pDevice, "vkGetDeviceQueue", &next_vkGetDeviceQueue);
success &= initDeviceFunc(*pDevice, "vkQueueSubmit", &next_vkQueueSubmit);
success &= initDeviceFunc(*pDevice, "vkCmdPipelineBarrier", &next_vkCmdPipelineBarrier);
success &= initDeviceFunc(*pDevice, "vkCmdCopyImage", &next_vkCmdCopyImage);
success &= initDeviceFunc(*pDevice, "vkCmdBlitImage", &next_vkCmdBlitImage);
success &= initDeviceFunc(*pDevice, "vkAcquireNextImageKHR", &next_vkAcquireNextImageKHR);
if (!success) {
Log::error("layer", "Failed to get device function pointers");
@ -635,19 +635,20 @@ void Layer::ovkCmdPipelineBarrier(
bufferMemoryBarrierCount, pBufferMemoryBarriers,
imageMemoryBarrierCount, pImageMemoryBarriers);
}
void Layer::ovkCmdCopyImage(
void Layer::ovkCmdBlitImage(
VkCommandBuffer commandBuffer,
VkImage srcImage,
VkImageLayout srcImageLayout,
VkImage dstImage,
VkImageLayout dstImageLayout,
uint32_t regionCount,
const VkImageCopy* pRegions) {
Log::debug("vulkan2", "vkCmdCopyImage called for command buffer {:x}, src image {:x}, dst image {:x}",
const VkImageBlit* pRegions,
VkFilter filter) {
Log::debug("vulkan2", "vkCmdBlitImage called for command buffer {:x}, src image {:x}, dst image {:x}",
reinterpret_cast<uintptr_t>(commandBuffer),
reinterpret_cast<uintptr_t>(srcImage),
reinterpret_cast<uintptr_t>(dstImage));
next_vkCmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
next_vkCmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
}
VkResult Layer::ovkAcquireNextImageKHR(

View file

@ -6,6 +6,7 @@
#include <algorithm>
#include <optional>
#include <vulkan/vulkan_core.h>
using namespace Utils;
@ -96,25 +97,31 @@ void Utils::copyImage(VkCommandBuffer buf,
0, nullptr, 0, nullptr,
static_cast<uint32_t>(barriers.size()), barriers.data());
const VkImageCopy imageCopy{
const VkImageBlit imageBlit{
.srcSubresource = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.layerCount = 1
},
.srcOffsets = {
{ 0, 0, 0 },
{ static_cast<int32_t>(width), static_cast<int32_t>(height), 1 }
},
.dstSubresource = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.layerCount = 1
},
.extent = {
.width = width,
.height = height,
.depth = 1
.dstOffsets = {
{ 0, 0, 0 },
{ static_cast<int32_t>(width), static_cast<int32_t>(height), 1 }
}
};
Layer::ovkCmdCopyImage(buf,
Layer::ovkCmdBlitImage(
buf,
src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1, &imageCopy);
1, &imageBlit,
VK_FILTER_NEAREST
);
if (makeSrcPresentable) {
const VkImageMemoryBarrier presentBarrier{