video_core: Fix renderpass cache bug and introduce RGBA -> BGR converter

This commit is contained in:
GPUCode
2022-10-09 14:05:44 +03:00
parent b0fc94f155
commit 11de7700aa
5 changed files with 26 additions and 4 deletions

View File

@ -142,8 +142,12 @@ void TextureRuntime::FormatConvert(const Surface& surface, bool upload, std::spa
} else if (format == VideoCore::PixelFormat::RGB8 && driver.IsOpenGLES()) { } else if (format == VideoCore::PixelFormat::RGB8 && driver.IsOpenGLES()) {
return Pica::Texture::ConvertBGRToRGB(source, dest); return Pica::Texture::ConvertBGRToRGB(source, dest);
} else { } else {
ASSERT(dest.size() >= source.size()); // Sometimes the source size might be larger than the destination.
std::memcpy(dest.data(), source.data(), source.size()); // This can happen during texture downloads when FromInterval aligns
// the flush range to scanline boundaries. In that case only copy
// what we need
const std::size_t copy_size = std::min(source.size(), dest.size());
std::memcpy(dest.data(), source.data(), copy_size);
} }
} }

View File

@ -30,7 +30,7 @@ VideoCore::PixelFormat ToFormatDepth(u32 index) {
switch (index) { switch (index) {
case 0: case 0:
return VideoCore::PixelFormat::D16; return VideoCore::PixelFormat::D16;
case 1: case 2:
return VideoCore::PixelFormat::D24; return VideoCore::PixelFormat::D24;
case 3: case 3:
return VideoCore::PixelFormat::D24S8; return VideoCore::PixelFormat::D24S8;

View File

@ -222,7 +222,11 @@ void TextureRuntime::FormatConvert(const Surface& surface, bool upload, std::spa
// Handle simple D24S8 interleave case // Handle simple D24S8 interleave case
if (surface.GetInternalFormat() == vk::Format::eD24UnormS8Uint) { if (surface.GetInternalFormat() == vk::Format::eD24UnormS8Uint) {
if (!upload) {
return Pica::Texture::InterleaveD24S8(source, dest); return Pica::Texture::InterleaveD24S8(source, dest);
} else {
UNREACHABLE();
}
} }
if (upload) { if (upload) {
@ -242,6 +246,8 @@ void TextureRuntime::FormatConvert(const Surface& surface, bool upload, std::spa
return Pica::Texture::ConvertD32S8ToD24S8(source, dest); return Pica::Texture::ConvertD32S8ToD24S8(source, dest);
case VideoCore::PixelFormat::RGBA4: case VideoCore::PixelFormat::RGBA4:
return Pica::Texture::ConvertRGBA8ToRGBA4(source, dest); return Pica::Texture::ConvertRGBA8ToRGBA4(source, dest);
case VideoCore::PixelFormat::RGB8:
return Pica::Texture::ConvertRGBAToBGR(source, dest);
default: default:
break; break;
} }

View File

@ -242,6 +242,16 @@ void ConvertBGRToRGBA(std::span<const std::byte> source, std::span<std::byte> de
} }
} }
void ConvertRGBAToBGR(std::span<const std::byte> source, std::span<std::byte> dest) {
u32 j = 0;
for (std::size_t i = 0; i < dest.size(); i += 3) {
dest[i] = source[j + 2];
dest[i + 1] = source[j + 1];
dest[i + 2] = source[j];
j += 4;
}
}
void ConvertABGRToRGBA(std::span<const std::byte> source, std::span<std::byte> dest) { void ConvertABGRToRGBA(std::span<const std::byte> source, std::span<std::byte> dest) {
for (u32 i = 0; i < dest.size(); i += 4) { for (u32 i = 0; i < dest.size(); i += 4) {
u32 abgr; u32 abgr;

View File

@ -71,6 +71,8 @@ void ConvertBGRToRGB(std::span<const std::byte> source, std::span<std::byte> des
*/ */
void ConvertBGRToRGBA(std::span<const std::byte> source, std::span<std::byte> dest); void ConvertBGRToRGBA(std::span<const std::byte> source, std::span<std::byte> dest);
void ConvertRGBAToBGR(std::span<const std::byte> source, std::span<std::byte> dest);
/** /**
* Converts pixel data encoded in ABGR format to RGBA * Converts pixel data encoded in ABGR format to RGBA
* *