From 0b7e013fbebaa0d92a4f95cfb36eff84654f60a0 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Tue, 10 May 2022 00:09:13 +0300 Subject: [PATCH] rsx: Simplify ZCULL logic a bit --- rpcs3/Emu/RSX/RSXZCULL.cpp | 48 +++++++++++--------------------- rpcs3/Emu/RSX/RSXZCULL.h | 8 +++++- rpcs3/Emu/RSX/VK/VKQueryPool.cpp | 13 +++------ 3 files changed, 27 insertions(+), 42 deletions(-) diff --git a/rpcs3/Emu/RSX/RSXZCULL.cpp b/rpcs3/Emu/RSX/RSXZCULL.cpp index 8c56f71892..71c2dc427e 100644 --- a/rpcs3/Emu/RSX/RSXZCULL.cpp +++ b/rpcs3/Emu/RSX/RSXZCULL.cpp @@ -102,9 +102,9 @@ namespace rsx { rsx_log.error("ZCULL queue interrupted by data type change!"); - // Stop+start the current setup - set_active(ptimer, false, false); - set_active(ptimer, true, false); + // Stop+start the current setup + set_active(ptimer, false, false); + set_active(ptimer, true, false); } } } @@ -134,7 +134,7 @@ namespace rsx if (m_pending_writes.empty()) { // No need to queue this if there is no pending request in the pipeline anyway - write(sink, ptimer->timestamp(), type, m_statistics_map[m_statistics_tag_id]); + write(sink, ptimer->timestamp(), type, m_statistics_map[m_statistics_tag_id].result); return; } @@ -168,7 +168,7 @@ namespace rsx ptimer->async_tasks_pending++; - if (m_statistics_map[m_statistics_tag_id] != 0) + if (m_statistics_map[m_statistics_tag_id].result != 0) { // Flush guaranteed results; only one positive is needed update(ptimer); @@ -256,7 +256,7 @@ namespace rsx } m_statistics_tag_id++; - m_statistics_map[m_statistics_tag_id] = 0; + m_statistics_map[m_statistics_tag_id] = {}; } void ZCULL_control::on_draw() @@ -326,7 +326,7 @@ namespace rsx if (!writer->forwarder) { // No other queries in the chain, write result - const auto value = (writer->type == CELL_GCM_ZPASS_PIXEL_CNT) ? m_statistics_map[writer->counter_tag] : result; + const auto value = (writer->type == CELL_GCM_ZPASS_PIXEL_CNT) ? m_statistics_map[writer->counter_tag].result : result; write(writer, ptimer->timestamp(), value); } @@ -379,38 +379,30 @@ namespace rsx break; auto query = writer.query; - u32 result = m_statistics_map[writer.counter_tag]; + auto& counter = m_statistics_map[writer.counter_tag]; if (query) { ensure(query->pending); const bool implemented = (writer.type == CELL_GCM_ZPASS_PIXEL_CNT || writer.type == CELL_GCM_ZCULL_STATS3); - const bool have_result = result && !g_cfg.video.precise_zpass_count; + const bool have_result = counter.result && !g_cfg.video.precise_zpass_count; if (implemented && !have_result && query->num_draws) { get_occlusion_query_result(query); - - if (query->result) - { - result += query->result; - if (query->data_type & CELL_GCM_ZPASS_PIXEL_CNT) - { - m_statistics_map[writer.counter_tag] += query->result; - } - } + counter.result += query->result; } else { - //Already have a hit, no need to retest + // Already have a hit, no need to retest discard_occlusion_query(query); } free_query(query); } - retire(ptimer, &writer, result); + retire(ptimer, &writer, counter.result); processed++; } @@ -526,7 +518,7 @@ namespace rsx } auto query = writer.query; - u32 result = m_statistics_map[writer.counter_tag]; + auto& counter = m_statistics_map[writer.counter_tag]; const bool force_read = (sync_address != 0); if (force_read && writer.sink == sync_address && !writer.forwarder) @@ -540,7 +532,7 @@ namespace rsx ensure(query->pending); const bool implemented = (writer.type == CELL_GCM_ZPASS_PIXEL_CNT || writer.type == CELL_GCM_ZCULL_STATS3); - const bool have_result = result && !g_cfg.video.precise_zpass_count; + const bool have_result = counter.result && !g_cfg.video.precise_zpass_count; if (!implemented || !query->num_draws || have_result) { @@ -549,15 +541,7 @@ namespace rsx else if (force_read || check_occlusion_query_status(query)) { get_occlusion_query_result(query); - - if (query->result) - { - result += query->result; - if (query->data_type & CELL_GCM_ZPASS_PIXEL_CNT) - { - m_statistics_map[writer.counter_tag] += query->result; - } - } + counter.result += query->result; } else { @@ -571,7 +555,7 @@ namespace rsx stat_tag_to_remove = writer.counter_tag; - retire(ptimer, &writer, result); + retire(ptimer, &writer, counter.result); processed++; } diff --git a/rpcs3/Emu/RSX/RSXZCULL.h b/rpcs3/Emu/RSX/RSXZCULL.h index 91083b7eed..74e6cb2859 100644 --- a/rpcs3/Emu/RSX/RSXZCULL.h +++ b/rpcs3/Emu/RSX/RSXZCULL.h @@ -45,6 +45,12 @@ namespace rsx std::vector queries; }; + struct query_stat_counter + { + u32 result; + u32 reserved; + }; + enum sync_control { sync_none = 0, @@ -84,7 +90,7 @@ namespace rsx u64 m_timer = 0; std::vector m_pending_writes{}; - std::unordered_map m_statistics_map{}; + std::unordered_map m_statistics_map{}; // Enables/disables the ZCULL unit void set_active(class ::rsx::thread* ptimer, bool state, bool flush_queue); diff --git a/rpcs3/Emu/RSX/VK/VKQueryPool.cpp b/rpcs3/Emu/RSX/VK/VKQueryPool.cpp index aaff365369..e8a9d6b06d 100644 --- a/rpcs3/Emu/RSX/VK/VKQueryPool.cpp +++ b/rpcs3/Emu/RSX/VK/VKQueryPool.cpp @@ -36,15 +36,10 @@ namespace vk } case VK_NOT_READY: { - if (result[0] && (flags & VK_QUERY_RESULT_PARTIAL_BIT)) - { - query.any_passed = true; - query.ready = true; - query.data = result[0]; - return true; - } - - return false; + query.any_passed = !!result[0]; + query.ready = query.any_passed && !!(flags & VK_QUERY_RESULT_PARTIAL_BIT); + query.data = result[0]; + return query.ready; } default: die_with_error(error);