From 8fdb51ab46079941175546242604b08054ca4306 Mon Sep 17 00:00:00 2001
From: Fernando Sahmkow <fsahmkow27@gmail.com>
Date: Fri, 24 Sep 2021 01:13:42 +0200
Subject: [PATCH 1/3] QueryCache: Flush queries in order of running.

---
 src/video_core/query_cache.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/video_core/query_cache.h b/src/video_core/query_cache.h
index aac8512533..a19b9f9316 100644
--- a/src/video_core/query_cache.h
+++ b/src/video_core/query_cache.h
@@ -257,9 +257,9 @@ private:
 
     void AsyncFlushQuery(VAddr addr) {
         if (!uncommitted_flushes) {
-            uncommitted_flushes = std::make_shared<std::unordered_set<VAddr>>();
+            uncommitted_flushes = std::make_shared<std::vector<VAddr>>();
         }
-        uncommitted_flushes->insert(addr);
+        uncommitted_flushes->push_back(addr);
     }
 
     static constexpr std::uintptr_t PAGE_SIZE = 4096;
@@ -275,8 +275,8 @@ private:
 
     std::array<CounterStream, VideoCore::NumQueryTypes> streams;
 
-    std::shared_ptr<std::unordered_set<VAddr>> uncommitted_flushes{};
-    std::list<std::shared_ptr<std::unordered_set<VAddr>>> committed_flushes;
+    std::shared_ptr<std::vector<VAddr>> uncommitted_flushes{};
+    std::list<std::shared_ptr<std::vector<VAddr>>> committed_flushes;
 };
 
 template <class QueryCache, class HostCounter>

From d702b393a4db452f354c6976c18d7093c934a003 Mon Sep 17 00:00:00 2001
From: Fernando Sahmkow <fsahmkow27@gmail.com>
Date: Fri, 24 Sep 2021 01:14:17 +0200
Subject: [PATCH 2/3] Vulkan Query Cache: make sure to wait for the query
 result.

---
 src/video_core/renderer_vulkan/vk_query_cache.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/video_core/renderer_vulkan/vk_query_cache.cpp b/src/video_core/renderer_vulkan/vk_query_cache.cpp
index c9cb32d713..259cba156b 100644
--- a/src/video_core/renderer_vulkan/vk_query_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_query_cache.cpp
@@ -117,7 +117,8 @@ u64 HostCounter::BlockingQuery() const {
     cache.GetScheduler().Wait(tick);
     u64 data;
     const VkResult query_result = cache.GetDevice().GetLogical().GetQueryResults(
-        query.first, query.second, 1, sizeof(data), &data, sizeof(data), VK_QUERY_RESULT_64_BIT);
+        query.first, query.second, 1, sizeof(data), &data, sizeof(data),
+        VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT);
 
     switch (query_result) {
     case VK_SUCCESS:

From 3f4444b552c47e07ff934750e25740a60382db0b Mon Sep 17 00:00:00 2001
From: Fernando Sahmkow <fsahmkow27@gmail.com>
Date: Fri, 24 Sep 2021 01:14:49 +0200
Subject: [PATCH 3/3] Shader Compiler: avoid overflowed indices on indixed
 samplers.

---
 src/shader_recompiler/ir_opt/texture_pass.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/shader_recompiler/ir_opt/texture_pass.cpp b/src/shader_recompiler/ir_opt/texture_pass.cpp
index 44ad10d43f..225c238fb6 100644
--- a/src/shader_recompiler/ir_opt/texture_pass.cpp
+++ b/src/shader_recompiler/ir_opt/texture_pass.cpp
@@ -492,7 +492,8 @@ void TexturePass(Environment& env, IR::Program& program) {
             const auto insert_point{IR::Block::InstructionList::s_iterator_to(*inst)};
             IR::IREmitter ir{*texture_inst.block, insert_point};
             const IR::U32 shift{ir.Imm32(std::countr_zero(DESCRIPTOR_SIZE))};
-            inst->SetArg(0, ir.ShiftRightArithmetic(cbuf.dynamic_offset, shift));
+            inst->SetArg(0, ir.SMin(ir.ShiftRightArithmetic(cbuf.dynamic_offset, shift),
+                                    ir.Imm32(DESCRIPTOR_SIZE - 1)));
         } else {
             inst->SetArg(0, IR::Value{});
         }