Skip to content

Commit a50e253

Browse files
committed
Vulkan: Remove unused code path for texture copies
In 2020 we switched to drawcalls for texture copies replacing the copy-via-buffer path. It's not been used since so lets remove it
1 parent 1f9b891 commit a50e253

File tree

3 files changed

+1
-146
lines changed

3 files changed

+1
-146
lines changed

src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -577,20 +577,6 @@ VulkanRenderer::VulkanRenderer()
577577
for (sint32 i = 0; i < OCCLUSION_QUERY_POOL_SIZE; i++)
578578
m_occlusionQueries.list_availableQueryIndices.emplace_back(i);
579579

580-
// enable surface copies via buffer if we have plenty of memory available (otherwise use drawcalls)
581-
size_t availableSurfaceCopyBufferMem = memoryManager->GetTotalMemoryForBufferType(VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
582-
//m_featureControl.mode.useBufferSurfaceCopies = availableSurfaceCopyBufferMem >= 2000ull * 1024ull * 1024ull; // enable if at least 2000MB VRAM
583-
m_featureControl.mode.useBufferSurfaceCopies = false;
584-
585-
if (m_featureControl.mode.useBufferSurfaceCopies)
586-
{
587-
//cemuLog_log(LogType::Force, "Enable surface copies via buffer");
588-
}
589-
else
590-
{
591-
//cemuLog_log(LogType::Force, "Disable surface copies via buffer (Requires 2GB. Has only {}MB available)", availableSurfaceCopyBufferMem / 1024ull / 1024ull);
592-
}
593-
594580
// start compilation threads
595581
RendererShaderVk::Init();
596582
}

src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h

-6
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ class VulkanRenderer : public Renderer
311311
void surfaceCopy_notifyTextureRelease(LatteTextureVk* hostTexture);
312312

313313
private:
314-
void surfaceCopy_viaBuffer(LatteTextureVk* srcTextureVk, sint32 texSrcMip, sint32 texSrcLevel, LatteTextureVk* dstTextureVk, sint32 texDstMip, sint32 texDstLevel, sint32 effectiveCopyWidth, sint32 effectiveCopyHeight);
315314
void surfaceCopy_viaDrawcall(LatteTextureVk* srcTextureVk, sint32 texSrcMip, sint32 texSrcSlice, LatteTextureVk* dstTextureVk, sint32 texDstMip, sint32 texDstSlice, sint32 effectiveCopyWidth, sint32 effectiveCopyHeight);
316315

317316
void surfaceCopy_cleanup();
@@ -328,10 +327,6 @@ class VulkanRenderer : public Renderer
328327

329328
std::unordered_map<uint64, struct CopySurfacePipelineInfo*> m_copySurfacePipelineCache;
330329

331-
VkBuffer m_surfaceCopyBuffer = VK_NULL_HANDLE;
332-
VkDeviceMemory m_surfaceCopyBufferMemory = VK_NULL_HANDLE;
333-
size_t m_surfaceCopyBufferSize{};
334-
335330
public:
336331
// renderer interface
337332
void bufferCache_init(const sint32 bufferSize) override;
@@ -470,7 +465,6 @@ class VulkanRenderer : public Renderer
470465

471466
struct
472467
{
473-
bool useBufferSurfaceCopies; // if GPU has enough VRAM to spare, allow to use a buffer to copy surfaces (instead of drawcalls)
474468
bool useTFEmulationViaSSBO = true; // emulate transform feedback via shader writes to a storage buffer
475469
}mode;
476470

src/Cafe/HW/Latte/Renderer/Vulkan/VulkanSurfaceCopy.cpp

+1-126
Original file line numberDiff line numberDiff line change
@@ -763,110 +763,6 @@ bool vkIsBitCompatibleColorDepthFormat(VkFormat format1, VkFormat format2)
763763
return false;
764764
}
765765

766-
void VulkanRenderer::surfaceCopy_viaBuffer(LatteTextureVk* srcTextureVk, sint32 texSrcMip, sint32 texSrcSlice, LatteTextureVk* dstTextureVk, sint32 texDstMip, sint32 texDstSlice, sint32 effectiveCopyWidth, sint32 effectiveCopyHeight)
767-
{
768-
cemu_assert_debug(false); // not used currently
769-
770-
cemu_assert_debug(m_featureControl.mode.useBufferSurfaceCopies);
771-
772-
if (srcTextureVk->dim == Latte::E_DIM::DIM_3D)
773-
{
774-
cemu_assert_debug(false);
775-
return;
776-
}
777-
if (dstTextureVk->dim == Latte::E_DIM::DIM_3D)
778-
{
779-
cemu_assert_debug(false);
780-
return;
781-
}
782-
783-
draw_endRenderPass();
784-
785-
// calculate buffer size required for copy
786-
VkDeviceSize copySize = std::max(srcTextureVk->getAllocation()->getAllocationSize(), dstTextureVk->getAllocation()->getAllocationSize());
787-
788-
// make sure allocated buffer is large enough
789-
if (m_surfaceCopyBuffer == VK_NULL_HANDLE || copySize > m_surfaceCopyBufferSize)
790-
{
791-
if (m_surfaceCopyBuffer != VK_NULL_HANDLE)
792-
{
793-
// free existing buffer
794-
destroyDeviceMemory(m_surfaceCopyBufferMemory);
795-
m_surfaceCopyBufferMemory = VK_NULL_HANDLE;
796-
destroyBuffer(m_surfaceCopyBuffer);
797-
m_surfaceCopyBuffer = VK_NULL_HANDLE;
798-
}
799-
VkDeviceSize allocSize = (copySize + 1024ull * 1024ull - 1ull) & ~(1024ull * 1024ull - 1ull); // align to whole MB
800-
m_surfaceCopyBufferSize = allocSize;
801-
memoryManager->CreateBuffer(m_surfaceCopyBufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, m_surfaceCopyBuffer, m_surfaceCopyBufferMemory);
802-
if (m_surfaceCopyBuffer == VK_NULL_HANDLE)
803-
{
804-
cemuLog_log(LogType::Force, "Vulkan: Failed to allocate surface copy buffer with size {}", allocSize);
805-
return;
806-
}
807-
}
808-
if (m_surfaceCopyBuffer == VK_NULL_HANDLE)
809-
return;
810-
811-
auto vkObjSrcTexture = srcTextureVk->GetImageObj();
812-
auto vkObjDstTexture = dstTextureVk->GetImageObj();
813-
vkObjSrcTexture->flagForCurrentCommandBuffer();
814-
vkObjDstTexture->flagForCurrentCommandBuffer();
815-
816-
VkBufferImageCopy region{};
817-
region.bufferOffset = 0;
818-
region.bufferRowLength = effectiveCopyWidth;
819-
region.bufferImageHeight = effectiveCopyHeight;
820-
821-
if (srcTextureVk->isDepth)
822-
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
823-
else
824-
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
825-
region.imageSubresource.baseArrayLayer = texSrcSlice;
826-
region.imageSubresource.layerCount = 1;
827-
region.imageSubresource.mipLevel = texSrcMip;
828-
829-
region.imageOffset = { 0,0,0 };
830-
region.imageExtent = { (uint32)effectiveCopyWidth, (uint32)effectiveCopyHeight, 1 };
831-
832-
// make sure all write operations to the src image have finished
833-
barrier_image<SYNC_OP::IMAGE_WRITE | SYNC_OP::ANY_TRANSFER, SYNC_OP::ANY_TRANSFER>(srcTextureVk, region.imageSubresource, VK_IMAGE_LAYOUT_GENERAL);
834-
835-
vkCmdCopyImageToBuffer(getCurrentCommandBuffer(), vkObjSrcTexture->m_image, VK_IMAGE_LAYOUT_GENERAL, m_surfaceCopyBuffer, 1, &region);
836-
837-
// copy buffer to image
838-
839-
VkBufferImageCopy imageRegion[2]{};
840-
sint32 imageRegionCount = 0;
841-
842-
// color or depth only copy
843-
imageRegion[0].bufferOffset = 0;
844-
imageRegion[0].imageExtent.width = effectiveCopyWidth;
845-
imageRegion[0].imageExtent.height = effectiveCopyHeight;
846-
imageRegion[0].imageExtent.depth = 1;
847-
848-
imageRegion[0].imageSubresource.mipLevel = texDstMip;
849-
if (dstTextureVk->isDepth)
850-
imageRegion[0].imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
851-
else
852-
imageRegion[0].imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
853-
imageRegion[0].imageSubresource.baseArrayLayer = texDstSlice;
854-
imageRegion[0].imageSubresource.layerCount = 1;
855-
856-
imageRegionCount = 1;
857-
858-
// make sure the transfer to the buffer finished
859-
barrier_bufferRange<SYNC_OP::ANY_TRANSFER, SYNC_OP::ANY_TRANSFER>(m_surfaceCopyBuffer, 0, VK_WHOLE_SIZE);
860-
861-
// make sure all read and write operations to the dst image have finished
862-
barrier_image<SYNC_OP::IMAGE_READ | SYNC_OP::IMAGE_WRITE | SYNC_OP::ANY_TRANSFER, SYNC_OP::ANY_TRANSFER>(dstTextureVk, imageRegion[0].imageSubresource, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
863-
864-
vkCmdCopyBufferToImage(m_state.currentCommandBuffer, m_surfaceCopyBuffer, vkObjDstTexture->m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, imageRegionCount, imageRegion);
865-
866-
// make sure transfer has finished before any other operation
867-
barrier_image<SYNC_OP::ANY_TRANSFER, SYNC_OP::ANY_TRANSFER | SYNC_OP::IMAGE_READ | SYNC_OP::IMAGE_WRITE>(dstTextureVk, imageRegion[0].imageSubresource, VK_IMAGE_LAYOUT_GENERAL);
868-
}
869-
870766
void VulkanRenderer::surfaceCopy_copySurfaceWithFormatConversion(LatteTexture* sourceTexture, sint32 srcMip, sint32 srcSlice, LatteTexture* destinationTexture, sint32 dstMip, sint32 dstSlice, sint32 width, sint32 height)
871767
{
872768
// scale copy size to effective size
@@ -899,28 +795,7 @@ void VulkanRenderer::surfaceCopy_copySurfaceWithFormatConversion(LatteTexture* s
899795
return;
900796
}
901797

902-
VkFormat srcFormatVk = srcTextureVk->GetFormat();
903-
VkFormat dstFormatVk = dstTextureVk->GetFormat();
904-
905-
if ((srcTextureVk->isDepth && !dstTextureVk->isDepth) ||
906-
!srcTextureVk->isDepth && dstTextureVk->isDepth)
907-
{
908-
// depth to color or
909-
// color to depth
910-
if (m_featureControl.mode.useBufferSurfaceCopies && vkIsBitCompatibleColorDepthFormat(srcFormatVk, dstFormatVk))
911-
surfaceCopy_viaBuffer(srcTextureVk, texSrcMip, texSrcSlice, dstTextureVk, texDstMip, texDstSlice, effectiveCopyWidth, effectiveCopyHeight);
912-
else
913-
surfaceCopy_viaDrawcall(srcTextureVk, texSrcMip, texSrcSlice, dstTextureVk, texDstMip, texDstSlice, effectiveCopyWidth, effectiveCopyHeight);
914-
}
915-
else
916-
{
917-
// depth to depth or
918-
// color to color
919-
if (m_featureControl.mode.useBufferSurfaceCopies && srcFormatVk == dstFormatVk)
920-
surfaceCopy_viaBuffer(srcTextureVk, texSrcMip, texSrcSlice, dstTextureVk, texDstMip, texDstSlice, effectiveCopyWidth, effectiveCopyHeight);
921-
else
922-
surfaceCopy_viaDrawcall(srcTextureVk, texSrcMip, texSrcSlice, dstTextureVk, texDstMip, texDstSlice, effectiveCopyWidth, effectiveCopyHeight);
923-
}
798+
surfaceCopy_viaDrawcall(srcTextureVk, texSrcMip, texSrcSlice, dstTextureVk, texDstMip, texDstSlice, effectiveCopyWidth, effectiveCopyHeight);
924799
}
925800

926801
// called whenever a texture is destroyed

0 commit comments

Comments
 (0)