Skip to content

Commit

Permalink
rsx: Fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
kd-11 committed Jul 16, 2019
1 parent 71d3738 commit 5c71bc1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
17 changes: 1 addition & 16 deletions rpcs3/Emu/RSX/Common/surface_store.h
Expand Up @@ -196,7 +196,7 @@ namespace rsx
{
auto surface = Traits::get(e.second);

if (new_surface->last_use_tag > surface->last_use_tag ||
if (new_surface->last_use_tag >= surface->last_use_tag ||
new_surface == surface ||
address == e.first)
{
Expand Down Expand Up @@ -274,15 +274,6 @@ namespace rsx
for (const auto& e : list2) surface_info.push_back(e);
}

if (UNLIKELY(surface_info.size() > 1))
{
// Sort with oldest first for early exit
std::sort(surface_info.begin(), surface_info.end(), [](const auto& a, const auto& b)
{
return (a.second->last_use_tag < b.second->last_use_tag);
});
}

// TODO: Modify deferred_clip_region::direct_copy() to take a few more things into account!
const areau child_region = new_surface->get_normalized_memory_area();
const auto child_w = child_region.width();
Expand Down Expand Up @@ -343,12 +334,6 @@ namespace rsx
continue;
}

if (child_w == size.width && child_h == size.height && surface_info.size() > 1)
{
// If the write covers the whole area, discard anything older
new_surface->clear_rw_barrier();
}

// TODO: Eventually need to stack all the overlapping regions, but for now just do the latest rect in the space
deferred_clipped_region<surface_type> region;
region.src_x = src_offset.x;
Expand Down
31 changes: 31 additions & 0 deletions rpcs3/Emu/RSX/Common/surface_utils.h
Expand Up @@ -318,6 +318,37 @@ namespace rsx
old_contents.clear();
}

template <typename T>
u32 prepare_rw_barrier_for_transfer(T *target)
{
if (old_contents.size() <= 1)
return 0;

// Sort here before doing transfers since surfaces may have been updated in the meantime
std::sort(old_contents.begin(), old_contents.end(), [](auto& a, auto &b)
{
auto _a = static_cast<T*>(a.source);
auto _b = static_cast<T*>(b.source);
return (_a->last_use_tag < _b->last_use_tag);
});

// Try and optimize by omitting possible overlapped transfers
for (size_t i = old_contents.size() - 1; i > 0 /* Intentional */; i--)
{
old_contents[i].init_transfer(target);

const auto dst_area = old_contents[i].dst_rect();
if (unsigned(dst_area.x2) == target->width() && unsigned(dst_area.y2) == target->height() &&
!dst_area.x1 && !dst_area.y1)
{
// This transfer will overwrite everything older
return u32(i);
}
}

return 0;
}

template<typename T>
void set_old_contents(T* other)
{
Expand Down
9 changes: 6 additions & 3 deletions rpcs3/Emu/RSX/GL/GLRenderTargets.cpp
Expand Up @@ -623,11 +623,15 @@ void gl::render_target::memory_barrier(gl::command_context& cmd, bool force_init
return;
}

for (auto &section : old_contents)
const bool dst_is_depth = !!(aspect() & gl::image_aspect::depth);
const auto dst_bpp = get_bpp();
unsigned first = prepare_rw_barrier_for_transfer(this);

for (auto i = first; i < old_contents.size(); ++i)
{
auto &section = old_contents[i];
auto src_texture = gl::as_rtt(section.source);
const auto src_bpp = src_texture->get_bpp();
const auto dst_bpp = get_bpp();
rsx::typeless_xfer typeless_info{};

if (get_internal_format() == src_texture->get_internal_format())
Expand All @@ -649,7 +653,6 @@ void gl::render_target::memory_barrier(gl::command_context& cmd, bool force_init
}
}

const bool dst_is_depth = !!(aspect() & gl::image_aspect::depth);
section.init_transfer(this);

if (state_flags & rsx::surface_state_flags::erase_bkgnd)
Expand Down
13 changes: 8 additions & 5 deletions rpcs3/Emu/RSX/VK/VKRenderTargets.h
Expand Up @@ -315,14 +315,20 @@ namespace vk
return;
}

// Memory transfers
vk::image *target_image = (samples() > 1) ? get_resolve_target() : this;
vk::blitter hw_blitter;
bool optimize_copy = true;
for (auto &section : old_contents)
const auto dst_bpp = get_bpp();
unsigned first = prepare_rw_barrier_for_transfer(this);

for (auto i = first; i < old_contents.size(); ++i)
{
auto &section = old_contents[i];
auto src_texture = static_cast<vk::render_target*>(section.source);
src_texture->read_barrier(cmd);

const auto src_bpp = src_texture->get_bpp();
const auto dst_bpp = get_bpp();
rsx::typeless_xfer typeless_info{};

if (src_texture->info.format == info.format)
Expand All @@ -342,9 +348,7 @@ namespace vk
}
}

vk::blitter hw_blitter;
section.init_transfer(this);

auto src_area = section.src_rect();
auto dst_area = section.dst_rect();

Expand All @@ -354,7 +358,6 @@ namespace vk
this->transform_pixels_to_samples(dst_area);
}

vk::image *target_image = (samples() > 1) ? get_resolve_target() : this;
bool memory_load = true;
if (dst_area.x1 == 0 && dst_area.y1 == 0 &&
unsigned(dst_area.x2) == target_image->width() && unsigned(dst_area.y2) == target_image->height())
Expand Down

0 comments on commit 5c71bc1

Please sign in to comment.