From 0259c09e9a4a112c778c605f0ef8aaf76dd91123 Mon Sep 17 00:00:00 2001 From: Ivan 'provod' Avdeev Date: Sun, 22 Aug 2021 13:26:25 -0700 Subject: [PATCH] add swizzle for RGBA-BGRA format pair when saving screenshot this is the pair that breaks on nvidia (yay there's at least one thing that amd is better at!) --- ref_vk/vk_framectl.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/ref_vk/vk_framectl.c b/ref_vk/vk_framectl.c index e5b4a701..ac45581e 100644 --- a/ref_vk/vk_framectl.c +++ b/ref_vk/vk_framectl.c @@ -506,7 +506,7 @@ static rgbdata_t *XVK_ReadPixels( void ) { const int width = vk_frame.surface_caps.currentExtent.width, height = vk_frame.surface_caps.currentExtent.height; - const qboolean blit = canBlitFromSwapchainToFormat( dest_format ); + qboolean blit = canBlitFromSwapchainToFormat( dest_format ); if (g_frame.last_frame_index < 0) return NULL; @@ -689,8 +689,28 @@ static rgbdata_t *XVK_ReadPixels( void ) { r_shot->palette = NULL; r_shot->buffer = Mem_Malloc( r_temppool, r_shot->size ); - for (int y = 0; y < height; ++y, mapped += layout.rowPitch) { - memcpy(r_shot->buffer + row_size * y, mapped, row_size); + if (!blit) { + if (dest_format != VK_FORMAT_R8G8B8A8_UNORM || vk_frame.create_info.imageFormat != VK_FORMAT_B8G8R8A8_UNORM) { + gEngine.Con_Printf(S_WARN "Don't have a blit function for this format pair, will save as-is w/o conversion; expect image to look wrong\n"); + blit = true; + } else { + char *dst = r_shot->buffer; + for (int y = 0; y < height; ++y, mapped += layout.rowPitch) { + const char *src = mapped; + for (int x = 0; x < width; ++x, dst += 4, src += 4) { + dst[0] = src[2]; + dst[1] = src[1]; + dst[2] = src[0]; + dst[3] = src[3]; + } + } + } + } + + if (blit) { + for (int y = 0; y < height; ++y, mapped += layout.rowPitch) { + memcpy(r_shot->buffer + row_size * y, mapped, row_size); + } } }