Skip to content

Commit

Permalink
Merge pull request #12687 from unknownbrackets/vulkan-scaling
Browse files Browse the repository at this point in the history
Vulkan: Ensure scaling happens in cached RAM
  • Loading branch information
hrydgard committed Mar 8, 2020
2 parents 3ce9483 + ac909d2 commit 0166a19
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions GPU/Vulkan/TextureCacheVulkan.cpp
Expand Up @@ -38,19 +38,14 @@

#include "GPU/ge_constants.h"
#include "GPU/GPUState.h"
#include "GPU/Common/TextureCacheCommon.h"
#include "GPU/Common/TextureDecoder.h"
#include "GPU/Vulkan/TextureCacheVulkan.h"
#include "GPU/Vulkan/FramebufferVulkan.h"
#include "GPU/Vulkan/FragmentShaderGeneratorVulkan.h"
#include "GPU/Vulkan/DepalettizeShaderVulkan.h"
#include "GPU/Vulkan/ShaderManagerVulkan.h"
#include "GPU/Vulkan/DrawEngineVulkan.h"
#include "GPU/Common/TextureDecoder.h"

#ifdef _M_SSE
#include <emmintrin.h>
#endif

#define TEXCACHE_MAX_TEXELS_SCALED (256*256) // Per frame

#define TEXCACHE_MIN_SLAB_SIZE (8 * 1024 * 1024)
#define TEXCACHE_MAX_SLAB_SIZE (32 * 1024 * 1024)
Expand Down Expand Up @@ -1356,7 +1351,9 @@ void TextureCacheVulkan::LoadTextureLevel(TexCacheEntry &entry, uint8_t *writePt

if (scaleFactor > 1) {
u32 fmt = dstFmt;
scaler.ScaleAlways((u32 *)writePtr, pixelData, fmt, w, h, scaleFactor);
// CPU scaling reads from the destination buffer so we want cached RAM.
uint8_t *rearrange = (uint8_t *)AllocateAlignedMemory(w * scaleFactor * h * scaleFactor * 4, 16);
scaler.ScaleAlways((u32 *)rearrange, pixelData, fmt, w, h, scaleFactor);
pixelData = (u32 *)writePtr;
dstFmt = (VkFormat)fmt;

Expand All @@ -1366,13 +1363,14 @@ void TextureCacheVulkan::LoadTextureLevel(TexCacheEntry &entry, uint8_t *writePt
decPitch = w * bpp;

if (decPitch != rowPitch) {
// Rearrange in place to match the requested pitch.
// (it can only be larger than w * bpp, and a match is likely.)
for (int y = h - 1; y >= 0; --y) {
memcpy(writePtr + rowPitch * y, writePtr + decPitch * y, w * bpp);
for (int y = 0; y < h; ++y) {
memcpy(writePtr + rowPitch * y, rearrange + decPitch * y, w * bpp);
}
decPitch = rowPitch;
} else {
memcpy(writePtr, rearrange, w * h * 4);
}
FreeAlignedMemory(rearrange);
}
}
}
Expand Down

0 comments on commit 0166a19

Please sign in to comment.