diff --git a/ext/native/thin3d/VulkanQueueRunner.cpp b/ext/native/thin3d/VulkanQueueRunner.cpp index b2468b556c..c92031149a 100644 --- a/ext/native/thin3d/VulkanQueueRunner.cpp +++ b/ext/native/thin3d/VulkanQueueRunner.cpp @@ -754,19 +754,18 @@ void VulkanQueueRunner::ApplyRenderPassMerge(std::vector &steps) { for (int i = 0; i < (int)steps.size(); i++) { if (steps[i]->stepType == VKRStepType::RENDER && counts[steps[i]->render.framebuffer] > 1) { auto fb = steps[i]->render.framebuffer; + TinySet touchedFramebuffers; // must be the same fast-size as the dependencies TinySet for annoying reasons. for (int j = i + 1; j < (int)steps.size(); j++) { // If any other passes are reading from this framebuffer as-is, we cancel the scan. switch (steps[j]->stepType) { - case VKRStepType::COPY: - if (steps[j]->copy.src == fb) { - // We're done. - goto done_fb; - } - break; case VKRStepType::RENDER: if (steps[j]->dependencies.contains(fb)) { goto done_fb; } + // Prevent Unknown's example case from https://github.com/hrydgard/ppsspp/pull/12242 + if (steps[j]->dependencies.contains(touchedFramebuffers)) { + goto done_fb; + } if (steps[j]->render.framebuffer == fb) { // ok. Now, if it's a render, slurp up all the commands // and kill the step. @@ -775,8 +774,18 @@ void VulkanQueueRunner::ApplyRenderPassMerge(std::vector &steps) { steps[i]->commands.insert(steps[i]->commands.end(), steps[j]->commands.begin(), steps[j]->commands.end()); steps[j]->stepType = VKRStepType::RENDER_SKIP; } + // Remember the framebuffer this wrote to. We can't merge with later passes that depend on these. + if (steps[j]->render.framebuffer != fb) { + touchedFramebuffers.insert(steps[j]->render.framebuffer); + } // keep going. break; + case VKRStepType::COPY: + if (steps[j]->copy.src == fb) { + // We're done. + goto done_fb; + } + break; case VKRStepType::BLIT: if (steps[j]->blit.src == fb) { goto done_fb; diff --git a/ext/native/thin3d/VulkanQueueRunner.h b/ext/native/thin3d/VulkanQueueRunner.h index 8f15b8d0d8..3c840856c6 100644 --- a/ext/native/thin3d/VulkanQueueRunner.h +++ b/ext/native/thin3d/VulkanQueueRunner.h @@ -48,6 +48,20 @@ struct TinySet { } return false; } + bool contains(const TinySet &otherSet) { + // Awkward, kind of ruins the fun. + for (int i = 0; i < fastCount; i++) { + if (otherSet.contains(fastLookup_[i])) + return true; + } + if (slowLookup_) { + for (auto x : *slowLookup_) { + if (otherSet.contains(x)) + return true; + } + } + return false; + } private: void insertSlow(T t) {