From 35e61c77e0e6de05ff08fd567e3c98b3ae6eeaa7 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Mon, 19 Aug 2019 18:21:45 +0300 Subject: [PATCH] gl: Fixup for D24S8 readback --- rpcs3/Emu/RSX/GL/GLRenderTargets.cpp | 2 +- rpcs3/Emu/RSX/GL/GLTextureCache.h | 51 +++++++++++++++++++++------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp b/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp index 9734698f5b..ce5c1dd8e1 100644 --- a/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp +++ b/rpcs3/Emu/RSX/GL/GLRenderTargets.cpp @@ -380,7 +380,7 @@ void GLGSRender::init_buffers(rsx::framebuffer_creation_context context, bool sk const auto depth_format_gl = rsx::internals::surface_depth_format_to_gl(surface->get_surface_depth_format()); format = depth_format_gl.format; type = depth_format_gl.type; - swap_bytes = true; + swap_bytes = (type != gl::texture::type::uint_24_8); } else { diff --git a/rpcs3/Emu/RSX/GL/GLTextureCache.h b/rpcs3/Emu/RSX/GL/GLTextureCache.h index 1a0f053950..b037fcdf28 100644 --- a/rpcs3/Emu/RSX/GL/GLTextureCache.h +++ b/rpcs3/Emu/RSX/GL/GLTextureCache.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "stdafx.h" @@ -357,23 +357,50 @@ namespace gl glUnmapBuffer(GL_PIXEL_PACK_BUFFER); glBindBuffer(GL_PIXEL_PACK_BUFFER, GL_NONE); - // Shuffle - bool require_manual_shuffle = false; - if (pack_unpack_swap_bytes) - { - if (type == gl::texture::type::sbyte || type == gl::texture::type::ubyte) - require_manual_shuffle = true; - } - const auto valid_range = get_confirmed_range_delta(); const u32 valid_offset = valid_range.first; const u32 valid_length = valid_range.second; void *dst = get_ptr(get_section_base() + valid_offset); - if (require_manual_shuffle) + if (pack_unpack_swap_bytes) { - //byte swapping does not work on byte types, use uint_8_8_8_8 for rgba8 instead to avoid penalty - rsx::shuffle_texel_data_wzyx(dst, rsx_pitch, width, align(valid_length, rsx_pitch) / rsx_pitch); + // Shuffle + // TODO: Do this with a compute shader + switch (type) + { + case gl::texture::type::sbyte: + case gl::texture::type::ubyte: + { + if (pack_unpack_swap_bytes) + { + // byte swapping does not work on byte types, use uint_8_8_8_8 for rgba8 instead to avoid penalty + rsx::shuffle_texel_data_wzyx(dst, rsx_pitch, width, align(valid_length, rsx_pitch) / rsx_pitch); + } + break; + } + case gl::texture::type::uint_24_8: + { + verify(HERE), pack_unpack_swap_bytes == false; + verify(HERE), real_pitch == (width * 4); + if (LIKELY(rsx_pitch == real_pitch)) + { + rsx::convert_le_d24x8_to_be_d24x8(dst, dst, valid_length / 4, 1); + } + else + { + const u32 num_rows = align(valid_length, rsx_pitch) / rsx_pitch; + u8* data = static_cast(dst); + for (u32 row = 0; row < num_rows; ++row) + { + rsx::convert_le_d24x8_to_be_d24x8(data, data, width, 1); + data += rsx_pitch; + } + } + break; + } + default: + break; + } } if (context == rsx::texture_upload_context::framebuffer_storage)