diff --git a/rpcs3/Emu/RSX/Core/RSXContext.cpp b/rpcs3/Emu/RSX/Core/RSXContext.cpp index 41fe199f2d..3d770b8ce2 100644 --- a/rpcs3/Emu/RSX/Core/RSXContext.cpp +++ b/rpcs3/Emu/RSX/Core/RSXContext.cpp @@ -38,4 +38,13 @@ namespace rsx return {}; } + + utils::address_range GCM_tile_reference::tile_align(const utils::address_range& range) const + { + const auto alignment = 64 * tile->pitch; + const u32 start_offset = rsx::align_down2(range.start - base_address, alignment); + const u32 end_offset = rsx::align2(range.end - base_address + 1, alignment); + + return utils::address_range::start_length(start_offset + base_address, end_offset - start_offset); + } } diff --git a/rpcs3/Emu/RSX/Core/RSXContext.h b/rpcs3/Emu/RSX/Core/RSXContext.h index 13fe40e77e..c61529e4ff 100644 --- a/rpcs3/Emu/RSX/Core/RSXContext.h +++ b/rpcs3/Emu/RSX/Core/RSXContext.h @@ -25,6 +25,8 @@ namespace rsx { return !!tile; } + + utils::address_range tile_align(const rsx::address_range& range) const; }; struct GCM_context diff --git a/rpcs3/Emu/RSX/rsx_utils.h b/rpcs3/Emu/RSX/rsx_utils.h index eeef27c8c2..07cc4cc6ab 100644 --- a/rpcs3/Emu/RSX/rsx_utils.h +++ b/rpcs3/Emu/RSX/rsx_utils.h @@ -306,6 +306,13 @@ namespace rsx return ((value + alignment - 1) / alignment) * alignment; } + // General purpose downward alignment without power-of-2 constraint + template + static inline T align_down2(T value, U alignment) + { + return (value / alignment) * alignment; + } + // Copy memory in inverse direction from source // Used to scale negatively x axis while transfering image data template