mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-10-03 05:09:41 +00:00
[core, hle, video_core, memory] Improve multi-process, display layers, dynamic shader cache and rework overlay (#4238)
- [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions). - [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md) - [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability. ------------------- - Dynamic shader cache reloading capability for qlaunch - Multi-process improvements (thanks to @frank1734), instead of just using the main application we now respect caller process (also did it for HID devices while I was at it) - Layer stack masks & shared buffer screenshot for video core, added different masks (screenshot, recording, etc.) this was discovered as an issue due to how in qlaunch the transition was not right between applications. May not be perfect but also fixes screenshots while using qlaunch - Reworked overlay display management (input and visibility) - instead of random numbers as I've previously did, I decided to add an AppletZIndex enum for better readability. Also split capability of input by touch and gamepad. - etc. Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4238 Reviewed-by: Samuel <lizzie@eden-emu.dev> Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Reviewed-by: MaranBr <maranbr@eden-emu.dev>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
@@ -166,6 +166,16 @@ Result Container::GetLayerZIndex(u64 layer_id, s32* out_z_index) {
|
||||
R_RETURN(VI::ResultNotFound);
|
||||
}
|
||||
|
||||
Result Container::SetLayerStackMask(u64 layer_id, u32 layer_stack_mask) {
|
||||
std::scoped_lock lk{m_lock};
|
||||
|
||||
auto* const layer = m_layers.GetLayerById(layer_id);
|
||||
R_UNLESS(layer != nullptr, VI::ResultNotFound);
|
||||
|
||||
m_surface_flinger->SetLayerStackMask(layer->GetConsumerBinderId(), layer_stack_mask);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result Container::SetLayerIsOverlay(u64 layer_id, bool is_overlay) {
|
||||
std::scoped_lock lk{m_lock};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
@@ -68,6 +68,7 @@ public:
|
||||
Result SetLayerZIndex(u64 layer_id, s32 z_index);
|
||||
Result GetLayerZIndex(u64 layer_id, s32* out_z_index);
|
||||
Result SetLayerIsOverlay(u64 layer_id, bool is_overlay);
|
||||
Result SetLayerStackMask(u64 layer_id, u32 layer_stack_mask);
|
||||
|
||||
void LinkVsyncEvent(u64 display_id, Event* event);
|
||||
void UnlinkVsyncEvent(u64 display_id, Event* event);
|
||||
|
||||
@@ -4,9 +4,15 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <random>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/logging.h"
|
||||
#include "common/scratch_buffer.h"
|
||||
#include "core/core.h"
|
||||
#include "core/hle/kernel/k_page_group.h"
|
||||
#include "core/hle/kernel/k_process.h"
|
||||
#include "core/hle/kernel/k_system_resource.h"
|
||||
#include "core/hle/service/nvdrv/devices/nvmap.h"
|
||||
@@ -47,7 +53,7 @@ Result AllocateSharedBufferMemory(std::unique_ptr<Kernel::KPageGroup>* out_page_
|
||||
u32* end = system.DeviceMemory().GetPointer<u32>(block.GetAddress() + block.GetSize());
|
||||
|
||||
for (; start < end; start++) {
|
||||
*start = 0xFF0000FF;
|
||||
*start = 0x00000000;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +174,14 @@ constexpr u32 SharedBufferBlockLinearWidth = 1280;
|
||||
constexpr u32 SharedBufferBlockLinearHeight = 768;
|
||||
constexpr u32 SharedBufferBlockLinearStride =
|
||||
SharedBufferBlockLinearWidth * SharedBufferBlockLinearBpp;
|
||||
constexpr u32 SharedBufferNumSlots = 7;
|
||||
|
||||
constexpr u32 SharedBufferNumCaptureSlots = 3;
|
||||
constexpr u32 SharedBufferSlotsPerSession = 2;
|
||||
constexpr u32 SharedBufferMaxSessions = 2;
|
||||
|
||||
constexpr u32 SharedBufferNumSlots =
|
||||
SharedBufferNumCaptureSlots + SharedBufferSlotsPerSession * SharedBufferMaxSessions;
|
||||
static_assert(SharedBufferNumSlots <= 16, "Shared buffer pool exceeds the maximum texture count");
|
||||
|
||||
constexpr u32 SharedBufferWidth = 1280;
|
||||
constexpr u32 SharedBufferHeight = 720;
|
||||
@@ -192,7 +205,52 @@ constexpr SharedMemoryPoolLayout SharedBufferPoolLayout = [] {
|
||||
return layout;
|
||||
}();
|
||||
|
||||
void MakeGraphicBuffer(android::BufferQueueProducer& producer, u32 slot, u32 handle) {
|
||||
constexpr u32 GetCaptureSlot(CaptureKind kind) {
|
||||
return static_cast<u32>(kind);
|
||||
}
|
||||
static_assert(static_cast<u32>(CaptureKind::CallerApplet) + 1 == SharedBufferNumCaptureSlots,
|
||||
"Capture slot count does not match CaptureKind");
|
||||
|
||||
constexpr u32 GetPresentationSlot(u32 slot_base, u32 index) {
|
||||
return SharedBufferNumCaptureSlots + slot_base + index;
|
||||
}
|
||||
|
||||
constexpr u32 ColorOpaqueBlackRgba32 = 0xFF000000;
|
||||
|
||||
template <typename F>
|
||||
void ForEachPoolChunk(Core::System& system, Kernel::KPageGroup& page_group, u64 offset, u64 size,
|
||||
F&& writer) {
|
||||
Common::ScratchBuffer<u32> scratch;
|
||||
const u64 range_end = offset + size;
|
||||
u64 pool_pos = 0;
|
||||
|
||||
for (auto& block : page_group) {
|
||||
const u64 block_begin = pool_pos;
|
||||
const u64 block_end = block_begin + block.GetSize();
|
||||
pool_pos = block_end;
|
||||
|
||||
if (block_end <= offset) {
|
||||
continue;
|
||||
}
|
||||
if (block_begin >= range_end) {
|
||||
break;
|
||||
}
|
||||
|
||||
const u64 chunk_begin = (std::max)(block_begin, offset);
|
||||
const u64 chunk_end = (std::min)(block_end, range_end);
|
||||
const u64 chunk_size = chunk_end - chunk_begin;
|
||||
|
||||
u8* const dst =
|
||||
system.DeviceMemory().GetPointer<u8>(block.GetAddress()) + (chunk_begin - block_begin);
|
||||
|
||||
writer(dst, chunk_begin - offset, chunk_size);
|
||||
|
||||
system.GPU().Host1x().MemoryManager().ApplyOpOnPointer(
|
||||
dst, scratch, [&](DAddr addr) { system.GPU().InvalidateRegion(addr, chunk_size); });
|
||||
}
|
||||
}
|
||||
|
||||
void MakeGraphicBuffer(android::BufferQueueProducer& producer, u32 producer_slot, u32 pool_slot, u32 handle) {
|
||||
auto buffer = std::make_shared<android::NvGraphicBuffer>();
|
||||
buffer->width = SharedBufferWidth;
|
||||
buffer->height = SharedBufferHeight;
|
||||
@@ -200,8 +258,8 @@ void MakeGraphicBuffer(android::BufferQueueProducer& producer, u32 slot, u32 han
|
||||
buffer->format = SharedBufferBlockLinearFormat;
|
||||
buffer->external_format = SharedBufferBlockLinearFormat;
|
||||
buffer->buffer_id = handle;
|
||||
buffer->offset = slot * SharedBufferSlotSize;
|
||||
ASSERT(producer.SetPreallocatedBuffer(slot, buffer) == android::Status::NoError);
|
||||
buffer->offset = pool_slot * SharedBufferSlotSize;
|
||||
ASSERT(producer.SetPreallocatedBuffer(producer_slot, buffer) == android::Status::NoError);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -215,59 +273,91 @@ SharedBufferManager::~SharedBufferManager() = default;
|
||||
Result SharedBufferManager::CreateSession(Kernel::KProcess* owner_process, u64* out_buffer_id,
|
||||
u64* out_layer_handle, u64 display_id,
|
||||
bool enable_blending) {
|
||||
std::scoped_lock lk{m_guard};
|
||||
{
|
||||
std::scoped_lock lk{m_guard};
|
||||
|
||||
// Ensure we haven't already created.
|
||||
const u64 aruid = owner_process->GetProcessId();
|
||||
R_UNLESS(!m_sessions.contains(aruid), VI::ResultPermissionDenied);
|
||||
// Ensure we haven't already created.
|
||||
const u64 aruid = owner_process->GetProcessId();
|
||||
R_UNLESS(!m_sessions.contains(aruid), VI::ResultPermissionDenied);
|
||||
|
||||
// Allocate memory for the shared buffer if needed.
|
||||
if (!m_buffer_page_group) {
|
||||
R_TRY(AllocateSharedBufferMemory(std::addressof(m_buffer_page_group), m_system,
|
||||
SharedBufferSize));
|
||||
// Allocate memory for the shared buffer if needed.
|
||||
if (!m_buffer_page_group) {
|
||||
R_TRY(AllocateSharedBufferMemory(std::addressof(m_buffer_page_group), m_system,
|
||||
SharedBufferSize));
|
||||
|
||||
// Record buffer id.
|
||||
m_buffer_id = m_next_buffer_id++;
|
||||
// Record buffer id.
|
||||
m_buffer_id = m_next_buffer_id++;
|
||||
|
||||
// Record display id.
|
||||
m_display_id = display_id;
|
||||
// Record display id.
|
||||
m_display_id = display_id;
|
||||
|
||||
for (u32 slot = 0; slot < SharedBufferNumCaptureSlots; slot++) {
|
||||
ForEachPoolChunk(m_system, *m_buffer_page_group, u64{slot} * SharedBufferSlotSize,
|
||||
SharedBufferSlotSize, [](u8* dst, u64, u64 length) {
|
||||
std::fill_n(reinterpret_cast<u32*>(dst), length / sizeof(u32),
|
||||
ColorOpaqueBlackRgba32);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Claim a presentation slot range.
|
||||
u32 slot_base = 0;
|
||||
|
||||
std::array<bool, SharedBufferMaxSessions> in_use{};
|
||||
for (const auto& [existing_aruid, existing] : m_sessions) {
|
||||
const u32 index = existing.presentation_slot_base / SharedBufferSlotsPerSession;
|
||||
|
||||
if (index < in_use.size())
|
||||
in_use[index] = true;
|
||||
}
|
||||
|
||||
u32 index = 0;
|
||||
while (index < in_use.size() && in_use[index])
|
||||
index++;
|
||||
|
||||
if (index >= in_use.size()) {
|
||||
LOG_ERROR(Service_VI, "Out of shared buffer presentation slots ({} sessions)", SharedBufferMaxSessions);
|
||||
R_THROW(VI::ResultOperationFailed);
|
||||
}
|
||||
|
||||
slot_base = index * SharedBufferSlotsPerSession;
|
||||
|
||||
// Map into process.
|
||||
Common::ProcessAddress map_address{};
|
||||
R_TRY(MapSharedBufferIntoProcessAddressSpace(std::addressof(map_address), m_buffer_page_group,
|
||||
owner_process, m_system));
|
||||
|
||||
// Create new session.
|
||||
auto [it, was_emplaced] = m_sessions.emplace(aruid, SharedBufferSession{});
|
||||
auto& session = it->second;
|
||||
session.presentation_slot_base = slot_base;
|
||||
|
||||
auto& container = m_nvdrv->GetContainer();
|
||||
session.session_id = container.OpenSession(owner_process);
|
||||
session.nvmap_fd = m_nvdrv->Open("/dev/nvmap", session.session_id);
|
||||
|
||||
// Create an nvmap handle for the buffer and assign the memory to it.
|
||||
R_TRY(AllocateHandleForBuffer(std::addressof(session.buffer_nvmap_handle), *m_nvdrv,
|
||||
session.nvmap_fd, map_address, SharedBufferSize));
|
||||
|
||||
// Create and open a layer for the display.
|
||||
s32 producer_binder_id;
|
||||
R_TRY(m_container.CreateStrayLayer(std::addressof(producer_binder_id),
|
||||
std::addressof(session.layer_id), display_id));
|
||||
|
||||
// Configure blending and z-index
|
||||
R_ASSERT(m_container.SetLayerBlending(session.layer_id, enable_blending));
|
||||
|
||||
// Get the producer and set preallocated buffers.
|
||||
std::shared_ptr<android::BufferQueueProducer> producer;
|
||||
R_TRY(m_container.GetLayerProducerHandle(std::addressof(producer), session.layer_id));
|
||||
for (u32 i = 0; i < SharedBufferSlotsPerSession; i++)
|
||||
MakeGraphicBuffer(*producer, i, GetPresentationSlot(session.presentation_slot_base, i), session.buffer_nvmap_handle);
|
||||
|
||||
// Assign outputs.
|
||||
*out_buffer_id = m_buffer_id;
|
||||
*out_layer_handle = session.layer_id;
|
||||
}
|
||||
|
||||
// Map into process.
|
||||
Common::ProcessAddress map_address{};
|
||||
R_TRY(MapSharedBufferIntoProcessAddressSpace(std::addressof(map_address), m_buffer_page_group,
|
||||
owner_process, m_system));
|
||||
|
||||
// Create new session.
|
||||
auto [it, was_emplaced] = m_sessions.emplace(aruid, SharedBufferSession{});
|
||||
auto& session = it->second;
|
||||
|
||||
auto& container = m_nvdrv->GetContainer();
|
||||
session.session_id = container.OpenSession(owner_process);
|
||||
session.nvmap_fd = m_nvdrv->Open("/dev/nvmap", session.session_id);
|
||||
|
||||
// Create an nvmap handle for the buffer and assign the memory to it.
|
||||
R_TRY(AllocateHandleForBuffer(std::addressof(session.buffer_nvmap_handle), *m_nvdrv,
|
||||
session.nvmap_fd, map_address, SharedBufferSize));
|
||||
|
||||
// Create and open a layer for the display.
|
||||
s32 producer_binder_id;
|
||||
R_TRY(m_container.CreateStrayLayer(std::addressof(producer_binder_id),
|
||||
std::addressof(session.layer_id), display_id));
|
||||
|
||||
// Configure blending and z-index
|
||||
R_ASSERT(m_container.SetLayerBlending(session.layer_id, enable_blending));
|
||||
|
||||
// Get the producer and set preallocated buffers.
|
||||
std::shared_ptr<android::BufferQueueProducer> producer;
|
||||
R_TRY(m_container.GetLayerProducerHandle(std::addressof(producer), session.layer_id));
|
||||
MakeGraphicBuffer(*producer, 0, session.buffer_nvmap_handle);
|
||||
MakeGraphicBuffer(*producer, 1, session.buffer_nvmap_handle);
|
||||
|
||||
// Assign outputs.
|
||||
*out_buffer_id = m_buffer_id;
|
||||
*out_layer_handle = session.layer_id;
|
||||
|
||||
// We succeeded.
|
||||
R_SUCCEED();
|
||||
}
|
||||
@@ -336,14 +426,51 @@ Result SharedBufferManager::AcquireSharedFrameBuffer(android::Fence* out_fence,
|
||||
SharedBufferBlockLinearFormat, 0) == android::Status::NoError,
|
||||
VI::ResultOperationFailed);
|
||||
|
||||
// Assign remaining outputs.
|
||||
*out_target_slot = slot;
|
||||
out_slot_indexes = {0, 1, -1, -1};
|
||||
out_slot_indexes.fill(-1);
|
||||
|
||||
{
|
||||
std::scoped_lock lk{m_guard};
|
||||
const auto* const session = this->FindSessionByLayerIdLocked(layer_id);
|
||||
if (session == nullptr) {
|
||||
producer->CancelBuffer(slot, *out_fence);
|
||||
// LOG_DEBUG(Service_VI, "No Session found");
|
||||
R_THROW(VI::ResultNotFound);
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < SharedBufferSlotsPerSession; i++)
|
||||
out_slot_indexes[i] =
|
||||
static_cast<s32>(GetPresentationSlot(session->presentation_slot_base, i));
|
||||
|
||||
*out_target_slot = static_cast<s64>(
|
||||
GetPresentationSlot(session->presentation_slot_base, static_cast<u32>(slot)));
|
||||
}
|
||||
|
||||
// We succeeded.
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SharedBufferManager::GetProducerSlotLocked(s32* out_producer_slot, u64 layer_id,
|
||||
s64 pool_slot) const {
|
||||
const auto* const session = this->FindSessionByLayerIdLocked(layer_id);
|
||||
R_UNLESS(session != nullptr, VI::ResultNotFound);
|
||||
|
||||
const s64 base = GetPresentationSlot(session->presentation_slot_base, 0);
|
||||
const s64 producer_slot = pool_slot - base;
|
||||
R_UNLESS(producer_slot >= 0 && producer_slot < SharedBufferSlotsPerSession,
|
||||
VI::ResultOperationFailed);
|
||||
|
||||
*out_producer_slot = static_cast<s32>(producer_slot);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
const SharedBufferSession* SharedBufferManager::FindSessionByLayerIdLocked(u64 layer_id) const {
|
||||
for (const auto& [aruid, session] : m_sessions)
|
||||
if (session.layer_id == layer_id)
|
||||
return std::addressof(session);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Result SharedBufferManager::PresentSharedFrameBuffer(android::Fence fence,
|
||||
Common::Rectangle<s32> crop_region,
|
||||
u32 transform, s32 swap_interval, u64 layer_id,
|
||||
@@ -352,14 +479,20 @@ Result SharedBufferManager::PresentSharedFrameBuffer(android::Fence fence,
|
||||
std::shared_ptr<android::BufferQueueProducer> producer;
|
||||
R_TRY(m_container.GetLayerProducerHandle(std::addressof(producer), layer_id));
|
||||
|
||||
s32 producer_slot;
|
||||
{
|
||||
std::scoped_lock lk{m_guard};
|
||||
R_TRY(this->GetProducerSlotLocked(std::addressof(producer_slot), layer_id, slot));
|
||||
}
|
||||
|
||||
// Request to queue the buffer.
|
||||
std::shared_ptr<android::GraphicBuffer> buffer;
|
||||
R_UNLESS(producer->RequestBuffer(static_cast<s32>(slot), std::addressof(buffer)) ==
|
||||
R_UNLESS(producer->RequestBuffer(producer_slot, std::addressof(buffer)) ==
|
||||
android::Status::NoError,
|
||||
VI::ResultOperationFailed);
|
||||
|
||||
ON_RESULT_FAILURE {
|
||||
producer->CancelBuffer(static_cast<s32>(slot), fence);
|
||||
producer->CancelBuffer(producer_slot, fence);
|
||||
};
|
||||
|
||||
// Queue the buffer to the producer.
|
||||
@@ -369,12 +502,10 @@ Result SharedBufferManager::PresentSharedFrameBuffer(android::Fence fence,
|
||||
input.fence = fence;
|
||||
input.transform = static_cast<android::NativeWindowTransform>(transform);
|
||||
input.swap_interval = swap_interval;
|
||||
R_UNLESS(producer->QueueBuffer(static_cast<s32>(slot), input, std::addressof(output)) ==
|
||||
R_UNLESS(producer->QueueBuffer(producer_slot, input, std::addressof(output)) ==
|
||||
android::Status::NoError,
|
||||
VI::ResultOperationFailed);
|
||||
|
||||
(void)m_container.SetLayerZIndex(layer_id, 100000);
|
||||
|
||||
// We succeeded.
|
||||
R_SUCCEED();
|
||||
}
|
||||
@@ -384,8 +515,14 @@ Result SharedBufferManager::CancelSharedFrameBuffer(u64 layer_id, s64 slot) {
|
||||
std::shared_ptr<android::BufferQueueProducer> producer;
|
||||
R_TRY(m_container.GetLayerProducerHandle(std::addressof(producer), layer_id));
|
||||
|
||||
s32 producer_slot;
|
||||
{
|
||||
std::scoped_lock lk{m_guard};
|
||||
R_TRY(this->GetProducerSlotLocked(std::addressof(producer_slot), layer_id, slot));
|
||||
}
|
||||
|
||||
// Cancel.
|
||||
producer->CancelBuffer(static_cast<s32>(slot), android::Fence::NoFence());
|
||||
producer->CancelBuffer(producer_slot, android::Fence::NoFence());
|
||||
|
||||
// We succeeded.
|
||||
R_SUCCEED();
|
||||
@@ -404,31 +541,47 @@ Result SharedBufferManager::GetSharedFrameBufferAcquirableEvent(Kernel::KReadabl
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SharedBufferManager::WriteAppletCaptureBuffer(bool* out_was_written, s32* out_layer_index) {
|
||||
std::vector<u8> capture_buffer(m_system.GPU().GetAppletCaptureBuffer());
|
||||
Common::ScratchBuffer<u32> scratch;
|
||||
Result SharedBufferManager::WriteAppletCaptureBuffer(bool* out_was_written, s32* out_layer_index, CaptureKind kind) {
|
||||
std::scoped_lock lk{m_guard};
|
||||
R_UNLESS(m_buffer_page_group != nullptr, VI::ResultNotFound);
|
||||
|
||||
// TODO: this could be optimized
|
||||
s64 e = -1280 * 768 * 4;
|
||||
for (auto& block : *m_buffer_page_group) {
|
||||
u8* start = m_system.DeviceMemory().GetPointer<u8>(block.GetAddress());
|
||||
u8* end = m_system.DeviceMemory().GetPointer<u8>(block.GetAddress() + block.GetSize());
|
||||
const std::vector<u8> capture = m_system.GPU().GetAppletCaptureBuffer();
|
||||
const u32 slot = GetCaptureSlot(kind);
|
||||
|
||||
for (; start < end; start++) {
|
||||
*start = 0;
|
||||
if (e >= 0 && e < static_cast<s64>(capture_buffer.size())) {
|
||||
*start = capture_buffer[e];
|
||||
}
|
||||
e++;
|
||||
}
|
||||
|
||||
m_system.GPU().Host1x().MemoryManager().ApplyOpOnPointer(start, scratch, [&](DAddr addr) {
|
||||
m_system.GPU().InvalidateRegion(addr, end - start);
|
||||
});
|
||||
if (capture.size() < SharedBufferSlotSize) {
|
||||
//LOG_WARNING(Service_VI, "Capture buffer is {} bytes, expected at least {}; not writing",
|
||||
// capture.size(), SharedBufferSlotSize);
|
||||
*out_was_written = false;
|
||||
*out_layer_index = static_cast<s32>(slot);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
ForEachPoolChunk(m_system, *m_buffer_page_group, u64{slot} * SharedBufferSlotSize,
|
||||
SharedBufferSlotSize,
|
||||
[&](u8* dst, u64 src_offset, u64 length) {
|
||||
std::memcpy(dst, capture.data() + src_offset, length);
|
||||
});
|
||||
|
||||
*out_was_written = true;
|
||||
*out_layer_index = 1;
|
||||
*out_layer_index = static_cast<s32>(slot);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SharedBufferManager::ClearAppletCaptureBuffer(s32 layer_index, u32 color) {
|
||||
std::scoped_lock lk{m_guard};
|
||||
R_UNLESS(m_buffer_page_group != nullptr, VI::ResultNotFound);
|
||||
|
||||
if (layer_index < 0 || layer_index >= static_cast<s32>(SharedBufferNumCaptureSlots)) {
|
||||
LOG_WARNING(Service_VI, "Couldnt clear non-capture slot {}", layer_index);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
ForEachPoolChunk(m_system, *m_buffer_page_group, u64{static_cast<u32>(layer_index)} * SharedBufferSlotSize,
|
||||
SharedBufferSlotSize, [&](u8* dst, u64 src_offset, u64 length) {
|
||||
ASSERT(src_offset % sizeof(u32) == 0 && length % sizeof(u32) == 0);
|
||||
std::fill_n(reinterpret_cast<u32*>(dst), length / sizeof(u32), color);
|
||||
});
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
@@ -48,6 +48,12 @@ static_assert(sizeof(SharedMemoryPoolLayout) == 0x188, "SharedMemoryPoolLayout h
|
||||
|
||||
struct SharedBufferSession;
|
||||
|
||||
enum class CaptureKind : u32 {
|
||||
LastApplication,
|
||||
LastForeground,
|
||||
CallerApplet,
|
||||
};
|
||||
|
||||
class SharedBufferManager final {
|
||||
public:
|
||||
explicit SharedBufferManager(Core::System& system, Container& container,
|
||||
@@ -68,9 +74,15 @@ public:
|
||||
Result CancelSharedFrameBuffer(u64 layer_id, s64 slot);
|
||||
Result GetSharedFrameBufferAcquirableEvent(Kernel::KReadableEvent** out_event, u64 layer_id);
|
||||
|
||||
Result WriteAppletCaptureBuffer(bool* out_was_written, s32* out_layer_index);
|
||||
Result WriteAppletCaptureBuffer(bool* out_was_written, s32* out_layer_index, CaptureKind kind);
|
||||
Result ClearAppletCaptureBuffer(s32 layer_index, u32 color);
|
||||
|
||||
private:
|
||||
const SharedBufferSession* FindSessionByLayerIdLocked(u64 layer_id) const;
|
||||
|
||||
/// Converts a pool slot index, which is what the guest works in, back to the buffer queues slot index
|
||||
Result GetProducerSlotLocked(s32* out_producer_slot, u64 layer_id, s64 pool_slot) const;
|
||||
|
||||
u64 m_next_buffer_id = 1;
|
||||
u64 m_display_id = 0;
|
||||
u64 m_buffer_id = 0;
|
||||
@@ -89,6 +101,7 @@ struct SharedBufferSession {
|
||||
Nvidia::NvCore::SessionId session_id = {};
|
||||
u64 layer_id = {};
|
||||
u32 buffer_nvmap_handle = 0;
|
||||
u32 presentation_slot_base = 0;
|
||||
};
|
||||
|
||||
} // namespace Service::VI
|
||||
|
||||
Reference in New Issue
Block a user