Skip to content

Commit 547b6eb

Browse files
committed
rsx: Narrow the race condition window further
- Needs aliased paging to be implemented to fix properly or a re-entrant global IO lock
1 parent fffd25c commit 547b6eb

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

rpcs3/Emu/RSX/Common/texture_cache.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -939,25 +939,30 @@ namespace rsx
939939
}
940940

941941
//TODO: This bit can cause race conditions if other threads are accessing this memory
942-
//1. Unprotect all memory in case of overlapping pages
942+
//1. Force readback if surface is not synchronized yet to make unlocked part finish quickly
943943
for (auto &tex : data.sections_to_flush)
944944
{
945945
if (tex->is_locked())
946946
{
947-
tex->unprotect();
947+
if (!tex->is_synchronized())
948+
tex->copy_texture(true, std::forward<Args>(extras)...);
949+
948950
m_cache[get_block_address(tex->get_section_base())].remove_one();
949951
}
950952
}
951953

952-
//2. Write all the memory
954+
//TODO: Acquire global io lock here
955+
956+
//2. Unprotect all the memory
953957
for (auto &tex : data.sections_to_flush)
954958
{
955-
if (!tex->flush(std::forward<Args>(extras)...))
956-
{
957-
//Missed address, note this
958-
//TODO: Lower severity when successful to keep the cache from overworking
959-
record_cache_miss(*tex);
960-
}
959+
tex->unprotect();
960+
}
961+
962+
//3. Write all the memory
963+
for (auto &tex : data.sections_to_flush)
964+
{
965+
tex->flush(std::forward<Args>(extras)...);
961966
}
962967

963968
//Restore protection on the sections to reprotect

rpcs3/Emu/RSX/VK/VKGSRender.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ bool VKGSRender::on_access_violation(u32 address, bool is_writing)
794794
vk::texture_cache::thrashed_set result;
795795
{
796796
std::lock_guard<std::mutex> lock(m_secondary_cb_guard);
797-
result = std::move(m_texture_cache.invalidate_address(address, is_writing, false, *m_device, m_secondary_command_buffer, m_memory_type_mapping, m_swap_chain->get_present_queue()));
797+
result = std::move(m_texture_cache.invalidate_address(address, is_writing, false, m_secondary_command_buffer, m_memory_type_mapping, m_swap_chain->get_present_queue()));
798798
}
799799

800800
if (!result.violation_handled)
@@ -882,7 +882,7 @@ bool VKGSRender::on_access_violation(u32 address, bool is_writing)
882882
}
883883
}
884884

885-
m_texture_cache.flush_all(result, *m_device, m_secondary_command_buffer, m_memory_type_mapping, m_swap_chain->get_present_queue());
885+
m_texture_cache.flush_all(result, m_secondary_command_buffer, m_memory_type_mapping, m_swap_chain->get_present_queue());
886886

887887
if (has_queue_ref)
888888
{
@@ -897,7 +897,7 @@ void VKGSRender::on_notify_memory_unmapped(u32 address_base, u32 size)
897897
{
898898
std::lock_guard<std::mutex> lock(m_secondary_cb_guard);
899899
if (m_texture_cache.invalidate_range(address_base, size, true, true, false,
900-
*m_device, m_secondary_command_buffer, m_memory_type_mapping, m_swap_chain->get_present_queue()).violation_handled)
900+
m_secondary_command_buffer, m_memory_type_mapping, m_swap_chain->get_present_queue()).violation_handled)
901901
{
902902
m_texture_cache.purge_dirty();
903903
{

rpcs3/Emu/RSX/VK/VKTextureCache.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,14 @@ namespace vk
244244
}
245245
}
246246

247-
bool flush(vk::render_device& dev, vk::command_buffer& cmd, vk::memory_type_mapping& memory_types, VkQueue submit_queue)
247+
bool flush(vk::command_buffer& cmd, vk::memory_type_mapping& memory_types, VkQueue submit_queue)
248248
{
249249
if (flushed) return true;
250250

251251
if (m_device == nullptr)
252-
m_device = &dev;
252+
{
253+
m_device = &cmd.get_command_pool().get_owner();
254+
}
253255

254256
// Return false if a flush occured 'late', i.e we had a miss
255257
bool result = true;
@@ -883,7 +885,7 @@ namespace vk
883885
template<typename RsxTextureType>
884886
sampled_image_descriptor _upload_texture(vk::command_buffer& cmd, RsxTextureType& tex, rsx::vk_render_targets& m_rtts)
885887
{
886-
return upload_texture(cmd, tex, m_rtts, *m_device, cmd, m_memory_types, const_cast<const VkQueue>(m_submit_queue));
888+
return upload_texture(cmd, tex, m_rtts, cmd, m_memory_types, const_cast<const VkQueue>(m_submit_queue));
887889
}
888890

889891
bool blit(rsx::blit_src_info& src, rsx::blit_dst_info& dst, bool interpolate, rsx::vk_render_targets& m_rtts, vk::command_buffer& cmd)
@@ -924,7 +926,7 @@ namespace vk
924926
}
925927
helper(&cmd);
926928

927-
return upload_scaled_image(src, dst, interpolate, cmd, m_rtts, helper, *m_device, cmd, m_memory_types, const_cast<const VkQueue>(m_submit_queue));
929+
return upload_scaled_image(src, dst, interpolate, cmd, m_rtts, helper, cmd, m_memory_types, const_cast<const VkQueue>(m_submit_queue));
928930
}
929931

930932
const u32 get_unreleased_textures_count() const override

0 commit comments

Comments
 (0)