From 99652c5eda7b0d89d547686484ccb9e2666154b1 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Wed, 12 Jan 2022 22:59:00 +0000 Subject: [PATCH] Support partially mapped cbufs Buggy games sometimes supply an incorrect cbuf size so limit buffers to the first unmapped region. --- app/src/main/cpp/skyline/common/span.h | 2 +- app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/skyline/common/span.h b/app/src/main/cpp/skyline/common/span.h index 7aad8181..2904adf7 100644 --- a/app/src/main/cpp/skyline/common/span.h +++ b/app/src/main/cpp/skyline/common/span.h @@ -89,7 +89,7 @@ namespace skyline { /** * @return If the span is valid by not being null */ - constexpr bool valid() { + constexpr bool valid() const { return this->data() != nullptr; } diff --git a/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h b/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h index 5e253c8f..9eb769d7 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h +++ b/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include #include #include @@ -603,6 +604,10 @@ namespace skyline::gpu::interconnect { return constantBufferSelector; auto mappings{channelCtx.asCtx->gmmu.TranslateRange(constantBufferSelector.iova, constantBufferSelector.size)}; + + // Ignore unmapped areas from mappings due to buggy games setting the wrong cbuf size + mappings.erase(ranges::find_if(mappings, [](const auto &mapping) { return !mapping.valid(); }), mappings.end()); + constantBufferSelector.guest.mappings.assign(mappings.begin(), mappings.end()); constantBufferSelector.view = gpu.buffer.FindOrCreate(constantBufferSelector.guest);