Skip to content

Commit

Permalink
If available, use 16-bit texture formats for MakePixelTexture when ap…
Browse files Browse the repository at this point in the history
…propriate.

Optimization for God of War on low-end platforms. Avoids calling a color
conversion function that's currently only SIMD-optimized on x86, so will
also benefit ARM a little bit.
  • Loading branch information
hrydgard committed Nov 12, 2023
1 parent 49f5da3 commit 7782548
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions Common/Data/Convert/ColorConv.cpp
Expand Up @@ -617,6 +617,7 @@ void ConvertRGB565ToBGR565(u16 *dst, const u16 *src, u32 numPixels) {
u32 i = 0;
#endif

// TODO: Add a 64-bit loop too.
const u32 *src32 = (const u32 *)src;
u32 *dst32 = (u32 *)dst;
for (; i < numPixels / 2; i++) {
Expand Down
17 changes: 15 additions & 2 deletions GPU/Common/FramebufferManagerCommon.cpp
Expand Up @@ -1342,6 +1342,14 @@ Draw::Texture *FramebufferManagerCommon::MakePixelTexture(const u8 *srcPixels, G
// No usable single channel format. Can't be bothered.
return nullptr;
}
} else if (srcPixelFormat == GE_FORMAT_565) {
// Check for supported matching formats.
// This mainly benefits the redundant copies in God of War on low-end platforms.
if ((draw_->GetDataFormatSupport(Draw::DataFormat::B5G6R5_UNORM_PACK16) & Draw::FMT_TEXTURE) != 0) {
texFormat = Draw::DataFormat::B5G6R5_UNORM_PACK16;
} else if ((draw_->GetDataFormatSupport(Draw::DataFormat::R5G6B5_UNORM_PACK16) & Draw::FMT_TEXTURE) != 0) {
texFormat = Draw::DataFormat::R5G6B5_UNORM_PACK16;
}
}

// TODO: We can just change the texture format and flip some bits around instead of this.
Expand All @@ -1355,10 +1363,15 @@ Draw::Texture *FramebufferManagerCommon::MakePixelTexture(const u8 *srcPixels, G
u8 *dst8 = (u8 *)(data + byteStride * y);
switch (srcPixelFormat) {
case GE_FORMAT_565:
if (texFormat == Draw::DataFormat::B8G8R8A8_UNORM)
if (texFormat == Draw::DataFormat::B5G6R5_UNORM_PACK16) {
memcpy(dst16, src16, w * sizeof(uint16_t));
} else if (texFormat == Draw::DataFormat::R5G6B5_UNORM_PACK16) {
ConvertRGB565ToBGR565(dst16, src16, width); // Fast!
} else if (texFormat == Draw::DataFormat::B8G8R8A8_UNORM) {
ConvertRGB565ToBGRA8888(dst, src16, width);
else
} else {
ConvertRGB565ToRGBA8888(dst, src16, width);
}
break;

case GE_FORMAT_5551:
Expand Down

0 comments on commit 7782548

Please sign in to comment.