[service, nvnflinger] Implement GetBufferHistory

Should help with UE4 games and many other buffer dependant titles.
Thanks to master Camille for the code and Shinmegumi for the placement!

Co-authored-by: CamilleLaVey <camillelavey99@gmail.com>
Co-committed-by: CamilleLaVey <camillelavey99@gmail.com>
This commit is contained in:
JPikachu 2025-07-18 22:17:45 +01:00
parent 7cb8a1acd3
commit 885ce4c58c
3 changed files with 41 additions and 5 deletions

View file

@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <deque>
#include <mutex>
#include <common/assert.h>
struct BufferHistoryEntry { s32 slot; s64 timestamp; s64 frame_number; };
class BufferHistoryManager { public: void PushEntry(s32 slot, s64 timestamp, s64 frame_number) { std::lock_guardstd::mutex lock(mutex_); if (entries_.size() >= kMaxHistorySize) entries_.pop_front();
entries_.emplace_back(BufferHistoryEntry{slot, timestamp, frame_number});
}
s32 GetHistory(std::span<BufferHistoryEntry> out_entries) {
std::lock_guard<std::mutex> lock(mutex_);
s32 count = std::min(static_cast<s32>(entries_.size()), static_cast<s32>(out_entries.size()));
for (s32 i = 0; i < count; ++i)
out_entries[i] = entries_[entries_.size() - count + i];
return count;
}
private: static constexpr size_t kMaxHistorySize = 16; std::deque<BufferHistoryEntry> entries_; std::mutex mutex_; };

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-FileCopyrightText: Copyright 2014 The Android Open Source Project
// SPDX-License-Identifier: GPL-3.0-or-later
@ -16,6 +19,7 @@
#include "core/hle/service/nvnflinger/parcel.h"
#include "core/hle/service/nvnflinger/ui/graphic_buffer.h"
#include "core/hle/service/nvnflinger/window.h"
#include "core/hle/service/nvnflinger/buffer_history.h"
namespace Service::android {
@ -922,11 +926,11 @@ void BufferQueueProducer::Transact(u32 code, std::span<const u8> parcel_data,
status = SetBufferCount(buffer_count);
break;
}
case TransactionId::GetBufferHistory:
LOG_WARNING(Service_Nvnflinger, "(STUBBED) called, transaction=GetBufferHistory");
break;
default:
ASSERT_MSG(false, "Unimplemented TransactionId {}", code);
case TransactionId::GetBufferHistory: {
LOG_DEBUG(Service_Nvnflinger, "GetBufferHistory");
auto out_span = request.PopRaw<std::span<BufferHistoryEntry>>();
s32 count = buffer_history_.GetHistory(out_span);
response.Push(s32(count));
break;
}

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-FileCopyrightText: Copyright 2014 The Android Open Source Project
// SPDX-License-Identifier: GPL-3.0-or-later
@ -80,6 +83,8 @@ private:
std::shared_ptr<BufferQueueCore> core;
BufferQueueDefs::SlotsType& slots;
BufferHistoryManager buffer_history_;
buffer_history_.PushEntry(slot, timestamp, frame_number);
u32 sticky_transform{};
std::mutex callback_mutex;
s32 next_callback_ticket{};