From 25bdc076cd9428c5ec1ca83530348711b87ef88b Mon Sep 17 00:00:00 2001 From: kd-11 Date: Wed, 15 Mar 2017 23:36:02 +0300 Subject: [PATCH] gl: Add surface offset calculations (broken atm/ WIP) --- rpcs3/Emu/RSX/GL/GLTextureCache.h | 18 +++++++++-- rpcs3/Emu/RSX/rsx_cache.h | 1 + rpcs3/Emu/RSX/rsx_methods.cpp | 53 ++++++++++++++++--------------- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/rpcs3/Emu/RSX/GL/GLTextureCache.h b/rpcs3/Emu/RSX/GL/GLTextureCache.h index 5e4c069685..c2d2432afc 100644 --- a/rpcs3/Emu/RSX/GL/GLTextureCache.h +++ b/rpcs3/Emu/RSX/GL/GLTextureCache.h @@ -1056,15 +1056,27 @@ namespace gl const areai src_area = {0, 0, src.width, src.slice_h}; const areai dst_area = {0, 0, dst.width, dst.height}; const position2i clip_offset = {dst.clip_x, dst.clip_y}; - const position2i dst_offset = {dst.offset_x, dst.offset_y}; + + position2i dst_offset = {dst.offset_x, dst.offset_y}; const size2i clip_dimensions = {dst.clip_width, dst.clip_height}; const size2i dst_dimensions = {dst.pitch/(dst_is_argb8? 4: 2), dst.height}; auto old_cached_texture = find_texture(dst.rsx_address, dst.pitch * dst.height); u32 dst_surface = 0; - if (old_cached_texture && old_cached_texture->matches(old_cached_texture->get_section_base(), dst.width, dst.height, 1)) + if (old_cached_texture/* && old_cached_texture->matches(old_cached_texture->get_section_base(), dst.width, dst.height, 1)*/) + { dst_surface = old_cached_texture->id(); + + const u32 address_offset = dst.rsx_address - old_cached_texture->get_section_base(); + + const u16 bpp = dst_is_argb8 ? 4 : 2; + const u16 offset_x = address_offset / dst.pitch; + const u16 offset_y = address_offset % dst.pitch; + + dst_offset.x += offset_x / bpp; + dst_offset.y += offset_y / bpp; + } u32 texture_id = m_hw_blitter.scale_image(tmp_tex, dst_surface, src_area, dst_area, dst_offset, clip_offset, dst_dimensions, clip_dimensions, dst_is_argb8); glDeleteTextures(1, &tmp_tex); @@ -1083,7 +1095,7 @@ namespace gl std::lock_guard lock(m_section_mutex); cached_texture_section &cached = create_texture(texture_id, dst.rsx_address, dst.pitch * dst.height, dst.width, dst.height, 1); - cached.protect(utils::protection::ro); + cached.protect(utils::protection::no); cached.set_dirty(false); return true; diff --git a/rpcs3/Emu/RSX/rsx_cache.h b/rpcs3/Emu/RSX/rsx_cache.h index 328647efc4..58502e56ec 100644 --- a/rpcs3/Emu/RSX/rsx_cache.h +++ b/rpcs3/Emu/RSX/rsx_cache.h @@ -58,6 +58,7 @@ namespace rsx bool swizzled; void *pixels; + u32 rsx_address; }; diff --git a/rpcs3/Emu/RSX/rsx_methods.cpp b/rpcs3/Emu/RSX/rsx_methods.cpp index d66e057d80..0dc82c5659 100644 --- a/rpcs3/Emu/RSX/rsx_methods.cpp +++ b/rpcs3/Emu/RSX/rsx_methods.cpp @@ -543,36 +543,37 @@ namespace rsx } } - blit_src_info src_info; - blit_dst_info dst_info; - - src_info.format = src_color_format; - src_info.width = in_w; - src_info.height = in_h; - src_info.pitch = in_pitch; - src_info.slice_h = slice_h; - src_info.offset_x = in_x; - src_info.offset_y = in_y; - src_info.pixels = pixels_src; - - dst_info.format = dst_color_format; - dst_info.width = convert_w; - dst_info.height = convert_h; - dst_info.clip_x = clip_x; - dst_info.clip_y = clip_y; - dst_info.clip_width = clip_w; - dst_info.clip_height = clip_h; - dst_info.offset_x = out_x; - dst_info.offset_y = out_y; - dst_info.pitch = out_pitch; - dst_info.pixels = pixels_dst; - dst_info.rsx_address = get_address(dst_offset, dst_dma); - dst_info.swizzled = (method_registers.blit_engine_context_surface() == blit_engine::context_surface::swizzle2d); - if (need_convert) { //For now, only use this for actual scaled images, there are use cases that should not go through 3d engine, e.g program ucode transfer //TODO: Figure out more instances where we can use this without problems + + blit_src_info src_info; + blit_dst_info dst_info; + + src_info.format = src_color_format; + src_info.width = in_w; + src_info.height = in_h; + src_info.pitch = in_pitch; + src_info.slice_h = slice_h; + src_info.offset_x = in_x; + src_info.offset_y = in_y; + src_info.pixels = pixels_src; + + dst_info.format = dst_color_format; + dst_info.width = convert_w; + dst_info.height = convert_h; + dst_info.clip_x = clip_x; + dst_info.clip_y = clip_y; + dst_info.clip_width = clip_w; + dst_info.clip_height = clip_h; + dst_info.offset_x = out_x; + dst_info.offset_y = out_y; + dst_info.pitch = out_pitch; + dst_info.pixels = pixels_dst; + dst_info.rsx_address = get_address(dst_offset, dst_dma); + dst_info.swizzled = (method_registers.blit_engine_context_surface() == blit_engine::context_surface::swizzle2d); + if (rsx->scaled_image_from_memory(src_info, dst_info, in_inter == blit_engine::transfer_interpolator::foh)) return; }