mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-05-26 19:37:01 +02:00
This will fix 1 of 2 performance regression to LM3 introduced between 0.0.2 and 0.0.3rc1. Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3218 Reviewed-by: Maufeat <sahyno1996@gmail.com> Reviewed-by: Lizzie <lizzie@eden-emu.dev> Reviewed-by: DraVee <dravee@eden-emu.dev> Co-authored-by: John <john@eden-emu.dev> Co-committed-by: John <john@eden-emu.dev>
This commit is contained in:
parent
b53aa06505
commit
28f08e43f1
6 changed files with 6 additions and 101 deletions
|
|
@ -100,14 +100,6 @@ Status BufferQueueConsumer::AcquireBuffer(BufferItem* out_buffer,
|
||||||
slots[slot].needs_cleanup_on_release = false;
|
slots[slot].needs_cleanup_on_release = false;
|
||||||
slots[slot].buffer_state = BufferState::Acquired;
|
slots[slot].buffer_state = BufferState::Acquired;
|
||||||
|
|
||||||
// Mark tracked buffer history records as acquired
|
|
||||||
for (auto& buffer_history_record : core->buffer_history) {
|
|
||||||
if (buffer_history_record.frame_number == core->frame_counter) {
|
|
||||||
buffer_history_record.state = BufferState::Acquired;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: for now, avoid resetting the fence, so that when we next return this
|
// TODO: for now, avoid resetting the fence, so that when we next return this
|
||||||
// slot to the producer, it will wait for the fence to pass. We should fix this
|
// slot to the producer, it will wait for the fence to pass. We should fix this
|
||||||
// by properly waiting for the fence in the BufferItemConsumer.
|
// by properly waiting for the fence in the BufferItemConsumer.
|
||||||
|
|
|
||||||
|
|
@ -14,17 +14,8 @@
|
||||||
namespace Service::android {
|
namespace Service::android {
|
||||||
|
|
||||||
BufferQueueCore::BufferQueueCore() = default;
|
BufferQueueCore::BufferQueueCore() = default;
|
||||||
BufferQueueCore::~BufferQueueCore() = default;
|
|
||||||
|
|
||||||
void BufferQueueCore::PushHistory(u64 frame_number, s64 queue_time, s64 presentation_time, BufferState state) {
|
BufferQueueCore::~BufferQueueCore() = default;
|
||||||
buffer_history_pos = (buffer_history_pos + 1) % BUFFER_HISTORY_SIZE;
|
|
||||||
buffer_history[buffer_history_pos] = BufferHistoryInfo{
|
|
||||||
.frame_number = frame_number,
|
|
||||||
.queue_time = queue_time,
|
|
||||||
.presentation_time = presentation_time,
|
|
||||||
.state = state,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void BufferQueueCore::SignalDequeueCondition() {
|
void BufferQueueCore::SignalDequeueCondition() {
|
||||||
dequeue_possible.store(true);
|
dequeue_possible.store(true);
|
||||||
|
|
|
||||||
|
|
@ -18,29 +18,12 @@
|
||||||
|
|
||||||
#include "core/hle/service/nvnflinger/buffer_item.h"
|
#include "core/hle/service/nvnflinger/buffer_item.h"
|
||||||
#include "core/hle/service/nvnflinger/buffer_queue_defs.h"
|
#include "core/hle/service/nvnflinger/buffer_queue_defs.h"
|
||||||
#include "core/hle/service/nvnflinger/buffer_slot.h"
|
|
||||||
#include "core/hle/service/nvnflinger/pixel_format.h"
|
#include "core/hle/service/nvnflinger/pixel_format.h"
|
||||||
#include "core/hle/service/nvnflinger/status.h"
|
#include "core/hle/service/nvnflinger/status.h"
|
||||||
#include "core/hle/service/nvnflinger/window.h"
|
#include "core/hle/service/nvnflinger/window.h"
|
||||||
|
|
||||||
namespace Service::android {
|
namespace Service::android {
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
struct BufferHistoryInfo {
|
|
||||||
#elif defined(__GNUC__) || defined(__clang__)
|
|
||||||
struct __attribute__((packed)) BufferHistoryInfo {
|
|
||||||
#endif
|
|
||||||
u64 frame_number;
|
|
||||||
s64 queue_time;
|
|
||||||
s64 presentation_time;
|
|
||||||
BufferState state;
|
|
||||||
};
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma pack(pop)
|
|
||||||
#endif
|
|
||||||
static_assert(sizeof(BufferHistoryInfo) == 0x1C, "BufferHistoryInfo must be 28 bytes");
|
|
||||||
|
|
||||||
class IConsumerListener;
|
class IConsumerListener;
|
||||||
class IProducerListener;
|
class IProducerListener;
|
||||||
|
|
||||||
|
|
@ -50,13 +33,10 @@ class BufferQueueCore final {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr s32 INVALID_BUFFER_SLOT = BufferItem::INVALID_BUFFER_SLOT;
|
static constexpr s32 INVALID_BUFFER_SLOT = BufferItem::INVALID_BUFFER_SLOT;
|
||||||
static constexpr u32 BUFFER_HISTORY_SIZE = 8;
|
|
||||||
|
|
||||||
BufferQueueCore();
|
BufferQueueCore();
|
||||||
~BufferQueueCore();
|
~BufferQueueCore();
|
||||||
|
|
||||||
void PushHistory(u64 frame_number, s64 queue_time, s64 presentation_time, BufferState state);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SignalDequeueCondition();
|
void SignalDequeueCondition();
|
||||||
bool WaitForDequeueCondition(std::unique_lock<std::mutex>& lk);
|
bool WaitForDequeueCondition(std::unique_lock<std::mutex>& lk);
|
||||||
|
|
@ -92,8 +72,6 @@ private:
|
||||||
const s32 max_acquired_buffer_count{}; // This is always zero on HOS
|
const s32 max_acquired_buffer_count{}; // This is always zero on HOS
|
||||||
bool buffer_has_been_queued{};
|
bool buffer_has_been_queued{};
|
||||||
u64 frame_counter{};
|
u64 frame_counter{};
|
||||||
std::array<BufferHistoryInfo, BUFFER_HISTORY_SIZE> buffer_history{};
|
|
||||||
u32 buffer_history_pos{BUFFER_HISTORY_SIZE-1};
|
|
||||||
u32 transform_hint{};
|
u32 transform_hint{};
|
||||||
bool is_allocating{};
|
bool is_allocating{};
|
||||||
mutable std::condition_variable_any is_allocating_condition;
|
mutable std::condition_variable_any is_allocating_condition;
|
||||||
|
|
|
||||||
|
|
@ -515,8 +515,6 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input,
|
||||||
slots[slot].buffer_state = BufferState::Queued;
|
slots[slot].buffer_state = BufferState::Queued;
|
||||||
++core->frame_counter;
|
++core->frame_counter;
|
||||||
slots[slot].frame_number = core->frame_counter;
|
slots[slot].frame_number = core->frame_counter;
|
||||||
slots[slot].queue_time = timestamp;
|
|
||||||
slots[slot].presentation_time = 0;
|
|
||||||
|
|
||||||
item.acquire_called = slots[slot].acquire_called;
|
item.acquire_called = slots[slot].acquire_called;
|
||||||
item.graphic_buffer = slots[slot].graphic_buffer;
|
item.graphic_buffer = slots[slot].graphic_buffer;
|
||||||
|
|
@ -549,15 +547,6 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input,
|
||||||
// mark it as freed
|
// mark it as freed
|
||||||
if (core->StillTracking(*front)) {
|
if (core->StillTracking(*front)) {
|
||||||
slots[front->slot].buffer_state = BufferState::Free;
|
slots[front->slot].buffer_state = BufferState::Free;
|
||||||
|
|
||||||
// Mark tracked buffer history records as free
|
|
||||||
for (auto& buffer_history_record : core->buffer_history) {
|
|
||||||
if (buffer_history_record.frame_number == front->frame_number) {
|
|
||||||
buffer_history_record.state = BufferState::Free;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset the frame number of the freed buffer so that it is the first in line to
|
// Reset the frame number of the freed buffer so that it is the first in line to
|
||||||
// be dequeued again
|
// be dequeued again
|
||||||
slots[front->slot].frame_number = 0;
|
slots[front->slot].frame_number = 0;
|
||||||
|
|
@ -571,7 +560,6 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
core->PushHistory(core->frame_counter, slots[slot].queue_time, slots[slot].presentation_time, BufferState::Queued);
|
|
||||||
core->buffer_has_been_queued = true;
|
core->buffer_has_been_queued = true;
|
||||||
core->SignalDequeueCondition();
|
core->SignalDequeueCondition();
|
||||||
output->Inflate(core->default_width, core->default_height, core->transform_hint,
|
output->Inflate(core->default_width, core->default_height, core->transform_hint,
|
||||||
|
|
@ -822,10 +810,6 @@ Status BufferQueueProducer::SetPreallocatedBuffer(s32 slot,
|
||||||
return Status::NoError;
|
return Status::NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
Kernel::KReadableEvent* BufferQueueProducer::GetNativeHandle(u32 type_id) {
|
|
||||||
return &buffer_wait_event->GetReadableEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BufferQueueProducer::Transact(u32 code, std::span<const u8> parcel_data,
|
void BufferQueueProducer::Transact(u32 code, std::span<const u8> parcel_data,
|
||||||
std::span<u8> parcel_reply, u32 flags) {
|
std::span<u8> parcel_reply, u32 flags) {
|
||||||
// Values used by BnGraphicBufferProducer onTransact
|
// Values used by BnGraphicBufferProducer onTransact
|
||||||
|
|
@ -945,49 +929,9 @@ void BufferQueueProducer::Transact(u32 code, std::span<const u8> parcel_data,
|
||||||
status = SetBufferCount(buffer_count);
|
status = SetBufferCount(buffer_count);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TransactionId::GetBufferHistory: {
|
case TransactionId::GetBufferHistory:
|
||||||
LOG_DEBUG(Service_Nvnflinger, "called, transaction=GetBufferHistory");
|
LOG_WARNING(Service_Nvnflinger, "(STUBBED) called, transaction=GetBufferHistory");
|
||||||
|
|
||||||
const s32 request = parcel_in.Read<s32>();
|
|
||||||
if (request <= 0) {
|
|
||||||
parcel_out.Write(Status::BadValue);
|
|
||||||
parcel_out.Write<s32>(0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr u32 history_max = BufferQueueCore::BUFFER_HISTORY_SIZE;
|
|
||||||
std::array<BufferHistoryInfo, history_max> buffer_history_snapshot{};
|
|
||||||
s32 valid_index{};
|
|
||||||
{
|
|
||||||
std::scoped_lock lk(core->mutex);
|
|
||||||
|
|
||||||
const u32 current_history_pos = core->buffer_history_pos;
|
|
||||||
u32 index_reversed{};
|
|
||||||
for (u32 i = 0; i < history_max; ++i) {
|
|
||||||
// Wrap values backwards e.g. 7, 6, 5, etc. in the range of 0-7
|
|
||||||
index_reversed = (current_history_pos + history_max - i) % history_max;
|
|
||||||
const auto& current_history_buffer = core->buffer_history[index_reversed];
|
|
||||||
|
|
||||||
// Here we use the frame number as a terminator.
|
|
||||||
// Because a buffer without frame_number is not considered complete
|
|
||||||
if (current_history_buffer.frame_number == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer_history_snapshot[valid_index] = current_history_buffer;
|
|
||||||
++valid_index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const s32 limit = std::min(request, valid_index);
|
|
||||||
parcel_out.Write(Status::NoError);
|
|
||||||
parcel_out.Write<s32>(limit);
|
|
||||||
for (s32 i = 0; i < limit; ++i) {
|
|
||||||
parcel_out.Write(buffer_history_snapshot[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
ASSERT_MSG(false, "Unimplemented TransactionId {}", code);
|
ASSERT_MSG(false, "Unimplemented TransactionId {}", code);
|
||||||
break;
|
break;
|
||||||
|
|
@ -1000,5 +944,8 @@ void BufferQueueProducer::Transact(u32 code, std::span<const u8> parcel_data,
|
||||||
(std::min)(parcel_reply.size(), serialized.size()));
|
(std::min)(parcel_reply.size(), serialized.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Kernel::KReadableEvent* BufferQueueProducer::GetNativeHandle(u32 type_id) {
|
||||||
|
return &buffer_wait_event->GetReadableEvent();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Service::android
|
} // namespace Service::android
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,6 @@ private:
|
||||||
s32 current_callback_ticket{};
|
s32 current_callback_ticket{};
|
||||||
std::condition_variable_any callback_condition;
|
std::condition_variable_any callback_condition;
|
||||||
|
|
||||||
u64 position;
|
|
||||||
|
|
||||||
Service::Nvidia::NvCore::NvMap& nvmap;
|
Service::Nvidia::NvCore::NvMap& nvmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ struct BufferSlot final {
|
||||||
bool needs_cleanup_on_release{};
|
bool needs_cleanup_on_release{};
|
||||||
bool attached_by_consumer{};
|
bool attached_by_consumer{};
|
||||||
bool is_preallocated{};
|
bool is_preallocated{};
|
||||||
s64 queue_time{}, presentation_time{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Service::android
|
} // namespace Service::android
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue