memory: Improve buffer size clamping

This commit is contained in:
IndecisiveTurtle 2025-02-24 11:26:32 +02:00
commit 4da373f208
2 changed files with 16 additions and 6 deletions

View file

@ -57,15 +57,25 @@ void MemoryManager::SetupMemoryRegions(u64 flexible_size, bool use_extended_mem1
} }
u64 MemoryManager::ClampRangeSize(VAddr virtual_addr, u64 size) { u64 MemoryManager::ClampRangeSize(VAddr virtual_addr, u64 size) {
static constexpr u64 MinSizeToClamp = 1_GB; static constexpr u64 MinSizeToClamp = 512_MB;
// Dont bother with clamping if the size is small so we dont pay a map lookup on every buffer. // Dont bother with clamping if the size is small so we dont pay a map lookup on every buffer.
if (size < MinSizeToClamp) { if (size < MinSizeToClamp) {
return size; return size;
} }
const auto vma = FindVMA(virtual_addr);
// Clamp size to the remaining size of the current VMA.
auto vma = FindVMA(virtual_addr);
ASSERT_MSG(vma != vma_map.end(), "Attempted to access invalid GPU address {:#x}", virtual_addr); ASSERT_MSG(vma != vma_map.end(), "Attempted to access invalid GPU address {:#x}", virtual_addr);
const u64 clamped_size = u64 clamped_size = vma->second.base + vma->second.size - virtual_addr;
std::min<u64>(size, vma->second.base + vma->second.size - virtual_addr); ++vma;
// Keep adding to the size while there is contigious virtual address space.
while (!vma->second.IsFree() && clamped_size < size) {
clamped_size += vma->second.size;
++vma;
}
clamped_size = std::min(clamped_size, size);
if (size != clamped_size) { if (size != clamped_size) {
LOG_WARNING(Kernel_Vmm, "Clamped requested buffer range addr={:#x}, size={:#x} to {:#x}", LOG_WARNING(Kernel_Vmm, "Clamped requested buffer range addr={:#x}, size={:#x} to {:#x}",
virtual_addr, size, clamped_size); virtual_addr, size, clamped_size);

View file

@ -240,8 +240,8 @@ std::tuple<ImageId, int, int> TextureCache::ResolveOverlap(const ImageInfo& imag
if (auto mip = tex_cache_image.info.MipOf(image_info); mip >= 0) { if (auto mip = tex_cache_image.info.MipOf(image_info); mip >= 0) {
if (auto slice = tex_cache_image.info.SliceOf(image_info, mip); slice >= 0) { if (auto slice = tex_cache_image.info.SliceOf(image_info, mip); slice >= 0) {
if (tex_cache_image.binding.is_target) { if (tex_cache_image.binding.is_target) {
// We have a larger image created and a separate one, representing a subres of it, // We have a larger image created and a separate one, representing a subres of
// bound as render target. In this case we need to rebind render target. // it, bound as render target. In this case we need to rebind render target.
tex_cache_image.binding.needs_rebind = 1u; tex_cache_image.binding.needs_rebind = 1u;
if (merged_image_id) { if (merged_image_id) {
GetImage(merged_image_id).binding.is_target = 1u; GetImage(merged_image_id).binding.is_target = 1u;