From 962c82540c304f909957776908aabcd261f2a7ba Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 22 Jan 2024 12:40:50 -0500 Subject: nvnflinger/gpu: implement blending --- src/core/hle/service/am/am_types.h | 6 +++--- .../hle/service/am/frontend/applet_software_keyboard.cpp | 12 ++++++------ src/core/hle/service/am/frontend/applet_software_keyboard.h | 2 +- src/core/hle/service/am/library_applet_creator.cpp | 6 +++--- src/core/hle/service/am/self_controller.cpp | 3 ++- src/core/hle/service/am/system_buffer_manager.cpp | 10 ++++++++-- src/core/hle/service/am/system_buffer_manager.h | 3 ++- 7 files changed, 25 insertions(+), 17 deletions(-) (limited to 'src/core/hle/service/am') diff --git a/src/core/hle/service/am/am_types.h b/src/core/hle/service/am/am_types.h index a2b852b12..8c33feb15 100644 --- a/src/core/hle/service/am/am_types.h +++ b/src/core/hle/service/am/am_types.h @@ -130,9 +130,9 @@ enum class AppletProgramId : u64 { enum class LibraryAppletMode : u32 { AllForeground = 0, - Background = 1, - NoUI = 2, - BackgroundIndirectDisplay = 3, + PartialForeground = 1, + NoUi = 2, + PartialForegroundIndirectDisplay = 3, AllForegroundInitiallyHidden = 4, }; diff --git a/src/core/hle/service/am/frontend/applet_software_keyboard.cpp b/src/core/hle/service/am/frontend/applet_software_keyboard.cpp index fbf75d379..034c62f32 100644 --- a/src/core/hle/service/am/frontend/applet_software_keyboard.cpp +++ b/src/core/hle/service/am/frontend/applet_software_keyboard.cpp @@ -68,9 +68,9 @@ void SoftwareKeyboard::Initialize() { case LibraryAppletMode::AllForeground: InitializeForeground(); break; - case LibraryAppletMode::Background: - case LibraryAppletMode::BackgroundIndirectDisplay: - InitializeBackground(applet_mode); + case LibraryAppletMode::PartialForeground: + case LibraryAppletMode::PartialForegroundIndirectDisplay: + InitializePartialForeground(applet_mode); break; default: ASSERT_MSG(false, "Invalid LibraryAppletMode={}", applet_mode); @@ -243,7 +243,7 @@ void SoftwareKeyboard::InitializeForeground() { InitializeFrontendNormalKeyboard(); } -void SoftwareKeyboard::InitializeBackground(LibraryAppletMode library_applet_mode) { +void SoftwareKeyboard::InitializePartialForeground(LibraryAppletMode library_applet_mode) { LOG_INFO(Service_AM, "Initializing Inline Software Keyboard Applet."); is_background = true; @@ -258,9 +258,9 @@ void SoftwareKeyboard::InitializeBackground(LibraryAppletMode library_applet_mod swkbd_inline_initialize_arg.size()); if (swkbd_initialize_arg.library_applet_mode_flag) { - ASSERT(library_applet_mode == LibraryAppletMode::Background); + ASSERT(library_applet_mode == LibraryAppletMode::PartialForeground); } else { - ASSERT(library_applet_mode == LibraryAppletMode::BackgroundIndirectDisplay); + ASSERT(library_applet_mode == LibraryAppletMode::PartialForegroundIndirectDisplay); } } diff --git a/src/core/hle/service/am/frontend/applet_software_keyboard.h b/src/core/hle/service/am/frontend/applet_software_keyboard.h index f464b7e15..2a7d01b96 100644 --- a/src/core/hle/service/am/frontend/applet_software_keyboard.h +++ b/src/core/hle/service/am/frontend/applet_software_keyboard.h @@ -62,7 +62,7 @@ private: void InitializeForeground(); /// Initializes the inline software keyboard. - void InitializeBackground(LibraryAppletMode library_applet_mode); + void InitializePartialForeground(LibraryAppletMode library_applet_mode); /// Processes the text check sent by the application. void ProcessTextCheck(); diff --git a/src/core/hle/service/am/library_applet_creator.cpp b/src/core/hle/service/am/library_applet_creator.cpp index 47bab7528..ee646bea5 100644 --- a/src/core/hle/service/am/library_applet_creator.cpp +++ b/src/core/hle/service/am/library_applet_creator.cpp @@ -87,7 +87,7 @@ AppletProgramId AppletIdToProgramId(AppletId applet_id) { // Set focus state switch (mode) { case LibraryAppletMode::AllForeground: - case LibraryAppletMode::NoUI: + case LibraryAppletMode::NoUi: applet->focus_state = FocusState::InFocus; applet->hid_registration.EnableAppletToGetInput(true); applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground); @@ -99,8 +99,8 @@ AppletProgramId AppletIdToProgramId(AppletId applet_id) { applet->hid_registration.EnableAppletToGetInput(false); applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); break; - case LibraryAppletMode::Background: - case LibraryAppletMode::BackgroundIndirectDisplay: + case LibraryAppletMode::PartialForeground: + case LibraryAppletMode::PartialForegroundIndirectDisplay: default: applet->focus_state = FocusState::Background; applet->hid_registration.EnableAppletToGetInput(true); diff --git a/src/core/hle/service/am/self_controller.cpp b/src/core/hle/service/am/self_controller.cpp index 0289f5cf1..b92663b2b 100644 --- a/src/core/hle/service/am/self_controller.cpp +++ b/src/core/hle/service/am/self_controller.cpp @@ -288,7 +288,8 @@ void ISelfController::GetSystemSharedBufferHandle(HLERequestContext& ctx) { } Result ISelfController::EnsureBufferSharingEnabled(Kernel::KProcess* process) { - if (applet->system_buffer_manager.Initialize(&nvnflinger, process, applet->applet_id)) { + if (applet->system_buffer_manager.Initialize(&nvnflinger, process, applet->applet_id, + applet->library_applet_mode)) { return ResultSuccess; } diff --git a/src/core/hle/service/am/system_buffer_manager.cpp b/src/core/hle/service/am/system_buffer_manager.cpp index 60a9afc9d..3cccc5388 100644 --- a/src/core/hle/service/am/system_buffer_manager.cpp +++ b/src/core/hle/service/am/system_buffer_manager.cpp @@ -17,11 +17,12 @@ SystemBufferManager::~SystemBufferManager() { // Clean up shared layers. if (m_buffer_sharing_enabled) { + m_nvnflinger->GetSystemBufferManager().Finalize(m_process); } } bool SystemBufferManager::Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel::KProcess* process, - AppletId applet_id) { + AppletId applet_id, LibraryAppletMode mode) { if (m_nvnflinger) { return m_buffer_sharing_enabled; } @@ -36,9 +37,14 @@ bool SystemBufferManager::Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel: return false; } + Nvnflinger::LayerBlending blending = Nvnflinger::LayerBlending::None; + if (mode == LibraryAppletMode::PartialForeground) { + blending = Nvnflinger::LayerBlending::Coverage; + } + const auto display_id = m_nvnflinger->OpenDisplay("Default").value(); const auto res = m_nvnflinger->GetSystemBufferManager().Initialize( - &m_system_shared_buffer_id, &m_system_shared_layer_id, display_id); + m_process, &m_system_shared_buffer_id, &m_system_shared_layer_id, display_id, blending); if (res.IsSuccess()) { m_buffer_sharing_enabled = true; diff --git a/src/core/hle/service/am/system_buffer_manager.h b/src/core/hle/service/am/system_buffer_manager.h index 98c3cf055..0690f68b6 100644 --- a/src/core/hle/service/am/system_buffer_manager.h +++ b/src/core/hle/service/am/system_buffer_manager.h @@ -27,7 +27,8 @@ public: SystemBufferManager(); ~SystemBufferManager(); - bool Initialize(Nvnflinger::Nvnflinger* flinger, Kernel::KProcess* process, AppletId applet_id); + bool Initialize(Nvnflinger::Nvnflinger* flinger, Kernel::KProcess* process, AppletId applet_id, + LibraryAppletMode mode); void GetSystemSharedLayerHandle(u64* out_system_shared_buffer_id, u64* out_system_shared_layer_id) { -- cgit v1.2.3 From 0cb413c3d31b93ce347e997b9674c304094dab09 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 26 Jan 2024 16:10:21 -0500 Subject: nvnflinger/gpu: implement applet capture --- src/core/hle/service/am/system_buffer_manager.cpp | 8 +- .../service/nvnflinger/fb_share_buffer_manager.cpp | 28 +++++- src/video_core/CMakeLists.txt | 1 + src/video_core/capture.h | 36 +++++++ src/video_core/gpu.cpp | 15 +++ src/video_core/gpu.h | 2 + src/video_core/renderer_base.h | 3 + src/video_core/renderer_null/renderer_null.cpp | 5 + src/video_core/renderer_null/renderer_null.h | 2 + src/video_core/renderer_opengl/gl_blit_screen.cpp | 4 +- src/video_core/renderer_opengl/gl_blit_screen.h | 2 +- src/video_core/renderer_opengl/present/layer.cpp | 15 ++- src/video_core/renderer_opengl/present/layer.h | 2 +- .../renderer_opengl/present/window_adapt_pass.cpp | 4 +- .../renderer_opengl/present/window_adapt_pass.h | 2 +- src/video_core/renderer_opengl/renderer_opengl.cpp | 85 +++++++++++++--- src/video_core/renderer_opengl/renderer_opengl.h | 9 ++ src/video_core/renderer_vulkan/renderer_vulkan.cpp | 108 ++++++++++++++++----- src/video_core/renderer_vulkan/renderer_vulkan.h | 12 ++- 19 files changed, 288 insertions(+), 55 deletions(-) create mode 100644 src/video_core/capture.h (limited to 'src/core/hle/service/am') diff --git a/src/core/hle/service/am/system_buffer_manager.cpp b/src/core/hle/service/am/system_buffer_manager.cpp index 3cccc5388..7fb9e3a75 100644 --- a/src/core/hle/service/am/system_buffer_manager.cpp +++ b/src/core/hle/service/am/system_buffer_manager.cpp @@ -68,8 +68,12 @@ void SystemBufferManager::SetWindowVisibility(bool visible) { Result SystemBufferManager::WriteAppletCaptureBuffer(bool* out_was_written, s32* out_fbshare_layer_index) { - // TODO - R_SUCCEED(); + if (!m_buffer_sharing_enabled) { + return VI::ResultPermissionDenied; + } + + return m_nvnflinger->GetSystemBufferManager().WriteAppletCaptureBuffer(out_was_written, + out_fbshare_layer_index); } } // namespace Service::AM diff --git a/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp b/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp index 6a7da0cae..90f7248a0 100644 --- a/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp +++ b/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp @@ -15,6 +15,7 @@ #include "core/hle/service/vi/layer/vi_layer.h" #include "core/hle/service/vi/vi_results.h" #include "video_core/gpu.h" +#include "video_core/host1x/host1x.h" namespace Service::Nvnflinger { @@ -414,9 +415,30 @@ Result FbShareBufferManager::GetSharedFrameBufferAcquirableEvent(Kernel::KReadab R_SUCCEED(); } -Result FbShareBufferManager::WriteAppletCaptureBuffer(bool* out_was_written, - s32* out_layer_index) { - // TODO +Result FbShareBufferManager::WriteAppletCaptureBuffer(bool* out_was_written, s32* out_layer_index) { + std::vector capture_buffer(m_system.GPU().GetAppletCaptureBuffer()); + Common::ScratchBuffer scratch; + + // TODO: this could be optimized + s64 e = -1280 * 768 * 4; + for (auto& block : *m_buffer_page_group) { + u8* start = m_system.DeviceMemory().GetPointer(block.GetAddress()); + u8* end = m_system.DeviceMemory().GetPointer(block.GetAddress() + block.GetSize()); + + for (; start < end; start++) { + *start = 0; + + if (e >= 0 && e < static_cast(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); + }); + } + *out_was_written = true; *out_layer_index = 1; R_SUCCEED(); diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 55180f4b5..dbed976ad 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -18,6 +18,7 @@ add_library(video_core STATIC buffer_cache/usage_tracker.h buffer_cache/word_manager.h cache_types.h + capture.h cdma_pusher.cpp cdma_pusher.h compatible_formats.cpp diff --git a/src/video_core/capture.h b/src/video_core/capture.h new file mode 100644 index 000000000..8db14a8ec --- /dev/null +++ b/src/video_core/capture.h @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "common/alignment.h" +#include "common/bit_util.h" +#include "common/common_types.h" +#include "core/frontend/framebuffer_layout.h" +#include "video_core/surface.h" + +namespace VideoCore::Capture { + +constexpr u32 BlockHeight = 4; +constexpr u32 BlockDepth = 0; +constexpr u32 BppLog2 = 2; + +constexpr auto PixelFormat = Surface::PixelFormat::B8G8R8A8_UNORM; + +constexpr auto LinearWidth = Layout::ScreenUndocked::Width; +constexpr auto LinearHeight = Layout::ScreenUndocked::Height; +constexpr auto LinearDepth = 1U; +constexpr auto BytesPerPixel = 4U; + +constexpr auto TiledWidth = LinearWidth; +constexpr auto TiledHeight = Common::AlignUpLog2(LinearHeight, BlockHeight + BlockDepth + BppLog2); +constexpr auto TiledSize = TiledWidth * TiledHeight * (1 << BppLog2); + +constexpr Layout::FramebufferLayout Layout{ + .width = LinearWidth, + .height = LinearHeight, + .screen = {0, 0, LinearWidth, LinearHeight}, + .is_srgb = false, +}; + +} // namespace VideoCore::Capture diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index f4a5d831c..8e663f2a8 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp @@ -347,6 +347,17 @@ struct GPU::Impl { WaitForSyncOperation(wait_fence); } + std::vector GetAppletCaptureBuffer() { + std::vector out; + + const auto wait_fence = + RequestSyncOperation([&] { out = renderer->GetAppletCaptureBuffer(); }); + gpu_thread.TickGPU(); + WaitForSyncOperation(wait_fence); + + return out; + } + GPU& gpu; Core::System& system; Host1x::Host1x& host1x; @@ -505,6 +516,10 @@ void GPU::RequestComposite(std::vector&& layers, impl->RequestComposite(std::move(layers), std::move(fences)); } +std::vector GPU::GetAppletCaptureBuffer() { + return impl->GetAppletCaptureBuffer(); +} + u64 GPU::GetTicks() const { return impl->GetTicks(); } diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h index c4602ca37..ad535512c 100644 --- a/src/video_core/gpu.h +++ b/src/video_core/gpu.h @@ -215,6 +215,8 @@ public: void RequestComposite(std::vector&& layers, std::vector&& fences); + std::vector GetAppletCaptureBuffer(); + /// Performs any additional setup necessary in order to begin GPU emulation. /// This can be used to launch any necessary threads and register any necessary /// core timing events. diff --git a/src/video_core/renderer_base.h b/src/video_core/renderer_base.h index 3ad180f67..67427f937 100644 --- a/src/video_core/renderer_base.h +++ b/src/video_core/renderer_base.h @@ -40,6 +40,9 @@ public: /// Finalize rendering the guest frame and draw into the presentation texture virtual void Composite(std::span layers) = 0; + /// Get the tiled applet layer capture buffer + virtual std::vector GetAppletCaptureBuffer() = 0; + [[nodiscard]] virtual RasterizerInterface* ReadRasterizer() = 0; [[nodiscard]] virtual std::string GetDeviceVendor() const = 0; diff --git a/src/video_core/renderer_null/renderer_null.cpp b/src/video_core/renderer_null/renderer_null.cpp index c89daff53..e6147d66c 100644 --- a/src/video_core/renderer_null/renderer_null.cpp +++ b/src/video_core/renderer_null/renderer_null.cpp @@ -3,6 +3,7 @@ #include "core/frontend/emu_window.h" #include "core/frontend/graphics_context.h" +#include "video_core/capture.h" #include "video_core/renderer_null/renderer_null.h" namespace Null { @@ -22,4 +23,8 @@ void RendererNull::Composite(std::span framebuff render_window.OnFrameDisplayed(); } +std::vector RendererNull::GetAppletCaptureBuffer() { + return std::vector(VideoCore::Capture::TiledSize); +} + } // namespace Null diff --git a/src/video_core/renderer_null/renderer_null.h b/src/video_core/renderer_null/renderer_null.h index 063b476bb..34dbe1e4f 100644 --- a/src/video_core/renderer_null/renderer_null.h +++ b/src/video_core/renderer_null/renderer_null.h @@ -19,6 +19,8 @@ public: void Composite(std::span framebuffer) override; + std::vector GetAppletCaptureBuffer() override; + VideoCore::RasterizerInterface* ReadRasterizer() override { return &m_rasterizer; } diff --git a/src/video_core/renderer_opengl/gl_blit_screen.cpp b/src/video_core/renderer_opengl/gl_blit_screen.cpp index 6ba8b214b..0282905ee 100644 --- a/src/video_core/renderer_opengl/gl_blit_screen.cpp +++ b/src/video_core/renderer_opengl/gl_blit_screen.cpp @@ -20,7 +20,7 @@ BlitScreen::BlitScreen(RasterizerOpenGL& rasterizer_, BlitScreen::~BlitScreen() = default; void BlitScreen::DrawScreen(std::span framebuffers, - const Layout::FramebufferLayout& layout) { + const Layout::FramebufferLayout& layout, bool invert_y) { // TODO: Signal state tracker about these changes state_tracker.NotifyScreenDrawVertexArray(); state_tracker.NotifyPolygonModes(); @@ -60,7 +60,7 @@ void BlitScreen::DrawScreen(std::span framebuffe } CreateWindowAdapt(); - window_adapt->DrawToFramebuffer(program_manager, layers, framebuffers, layout); + window_adapt->DrawToFramebuffer(program_manager, layers, framebuffers, layout, invert_y); // TODO // program_manager.RestoreGuestPipeline(); diff --git a/src/video_core/renderer_opengl/gl_blit_screen.h b/src/video_core/renderer_opengl/gl_blit_screen.h index 0c3d838f1..4e261d333 100644 --- a/src/video_core/renderer_opengl/gl_blit_screen.h +++ b/src/video_core/renderer_opengl/gl_blit_screen.h @@ -51,7 +51,7 @@ public: /// Draws the emulated screens to the emulator window. void DrawScreen(std::span framebuffers, - const Layout::FramebufferLayout& layout); + const Layout::FramebufferLayout& layout, bool invert_y); private: void CreateWindowAdapt(); diff --git a/src/video_core/renderer_opengl/present/layer.cpp b/src/video_core/renderer_opengl/present/layer.cpp index e3fffaa06..3e4377db4 100644 --- a/src/video_core/renderer_opengl/present/layer.cpp +++ b/src/video_core/renderer_opengl/present/layer.cpp @@ -34,7 +34,7 @@ GLuint Layer::ConfigureDraw(std::array& out_matrix, std::array& out_vertices, ProgramManager& program_manager, const Tegra::FramebufferConfig& framebuffer, - const Layout::FramebufferLayout& layout) { + const Layout::FramebufferLayout& layout, bool invert_y) { FramebufferTextureInfo info = PrepareRenderTarget(framebuffer); auto crop = Tegra::NormalizeCrop(framebuffer, info.width, info.height); GLuint texture = info.display_texture; @@ -83,10 +83,15 @@ GLuint Layer::ConfigureDraw(std::array& out_matrix, const auto w = screen.GetWidth(); const auto h = screen.GetHeight(); - out_vertices[0] = ScreenRectVertex(x, y, crop.left, crop.top); - out_vertices[1] = ScreenRectVertex(x + w, y, crop.right, crop.top); - out_vertices[2] = ScreenRectVertex(x, y + h, crop.left, crop.bottom); - out_vertices[3] = ScreenRectVertex(x + w, y + h, crop.right, crop.bottom); + const auto left = crop.left; + const auto right = crop.right; + const auto top = invert_y ? crop.bottom : crop.top; + const auto bottom = invert_y ? crop.top : crop.bottom; + + out_vertices[0] = ScreenRectVertex(x, y, left, top); + out_vertices[1] = ScreenRectVertex(x + w, y, right, top); + out_vertices[2] = ScreenRectVertex(x, y + h, left, bottom); + out_vertices[3] = ScreenRectVertex(x + w, y + h, right, bottom); return texture; } diff --git a/src/video_core/renderer_opengl/present/layer.h b/src/video_core/renderer_opengl/present/layer.h index ef1055abf..77bb97f4f 100644 --- a/src/video_core/renderer_opengl/present/layer.h +++ b/src/video_core/renderer_opengl/present/layer.h @@ -51,7 +51,7 @@ public: std::array& out_vertices, ProgramManager& program_manager, const Tegra::FramebufferConfig& framebuffer, - const Layout::FramebufferLayout& layout); + const Layout::FramebufferLayout& layout, bool invert_y); private: /// Loads framebuffer from emulated memory into the active OpenGL texture. diff --git a/src/video_core/renderer_opengl/present/window_adapt_pass.cpp b/src/video_core/renderer_opengl/present/window_adapt_pass.cpp index 0328abd70..d8b6a11cb 100644 --- a/src/video_core/renderer_opengl/present/window_adapt_pass.cpp +++ b/src/video_core/renderer_opengl/present/window_adapt_pass.cpp @@ -37,7 +37,7 @@ WindowAdaptPass::~WindowAdaptPass() = default; void WindowAdaptPass::DrawToFramebuffer(ProgramManager& program_manager, std::list& layers, std::span framebuffers, - const Layout::FramebufferLayout& layout) { + const Layout::FramebufferLayout& layout, bool invert_y) { GLint old_read_fb; GLint old_draw_fb; glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb); @@ -51,7 +51,7 @@ void WindowAdaptPass::DrawToFramebuffer(ProgramManager& program_manager, std::li auto layer_it = layers.begin(); for (size_t i = 0; i < layer_count; i++) { textures[i] = layer_it->ConfigureDraw(matrices[i], vertices[i], program_manager, - framebuffers[i], layout); + framebuffers[i], layout, invert_y); layer_it++; } diff --git a/src/video_core/renderer_opengl/present/window_adapt_pass.h b/src/video_core/renderer_opengl/present/window_adapt_pass.h index 00975a9c6..0a8bcef2f 100644 --- a/src/video_core/renderer_opengl/present/window_adapt_pass.h +++ b/src/video_core/renderer_opengl/present/window_adapt_pass.h @@ -31,7 +31,7 @@ public: void DrawToFramebuffer(ProgramManager& program_manager, std::list& layers, std::span framebuffers, - const Layout::FramebufferLayout& layout); + const Layout::FramebufferLayout& layout, bool invert_y); private: const Device& device; diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index e33a32592..a1a8491e5 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -16,6 +16,7 @@ #include "core/core_timing.h" #include "core/frontend/emu_window.h" #include "core/telemetry_session.h" +#include "video_core/capture.h" #include "video_core/renderer_opengl/gl_blit_screen.h" #include "video_core/renderer_opengl/gl_rasterizer.h" #include "video_core/renderer_opengl/gl_shader_manager.h" @@ -121,6 +122,13 @@ RendererOpenGL::RendererOpenGL(Core::TelemetrySession& telemetry_session_, } blit_screen = std::make_unique(rasterizer, device_memory, state_tracker, program_manager, device); + blit_applet = std::make_unique(rasterizer, device_memory, state_tracker, + program_manager, device); + capture_framebuffer.Create(); + capture_renderbuffer.Create(); + glBindRenderbuffer(GL_RENDERBUFFER, capture_renderbuffer.handle); + glRenderbufferStorage(GL_RENDERBUFFER, GL_SRGB8, VideoCore::Capture::LinearWidth, + VideoCore::Capture::LinearHeight); } RendererOpenGL::~RendererOpenGL() = default; @@ -130,10 +138,11 @@ void RendererOpenGL::Composite(std::span framebu return; } + RenderAppletCaptureLayer(framebuffers); RenderScreenshot(framebuffers); state_tracker.BindFramebuffer(0); - blit_screen->DrawScreen(framebuffers, emu_window.GetFramebufferLayout()); + blit_screen->DrawScreen(framebuffers, emu_window.GetFramebufferLayout(), false); ++m_current_frame; @@ -159,11 +168,8 @@ void RendererOpenGL::AddTelemetryFields() { telemetry_session.AddField(user_system, "GPU_OpenGL_Version", std::string(gl_version)); } -void RendererOpenGL::RenderScreenshot(std::span framebuffers) { - if (!renderer_settings.screenshot_requested) { - return; - } - +void RendererOpenGL::RenderToBuffer(std::span framebuffers, + const Layout::FramebufferLayout& layout, void* dst) { GLint old_read_fb; GLint old_draw_fb; glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb); @@ -173,29 +179,86 @@ void RendererOpenGL::RenderScreenshot(std::span screenshot_framebuffer.Create(); glBindFramebuffer(GL_FRAMEBUFFER, screenshot_framebuffer.handle); - const Layout::FramebufferLayout layout{renderer_settings.screenshot_framebuffer_layout}; - GLuint renderbuffer; glGenRenderbuffers(1, &renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); glRenderbufferStorage(GL_RENDERBUFFER, GL_SRGB8, layout.width, layout.height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer); - blit_screen->DrawScreen(framebuffers, layout); + blit_screen->DrawScreen(framebuffers, layout, false); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); glPixelStorei(GL_PACK_ROW_LENGTH, 0); - glReadPixels(0, 0, layout.width, layout.height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, - renderer_settings.screenshot_bits); + glReadPixels(0, 0, layout.width, layout.height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, dst); screenshot_framebuffer.Release(); glDeleteRenderbuffers(1, &renderbuffer); glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read_fb); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb); +} + +void RendererOpenGL::RenderScreenshot(std::span framebuffers) { + if (!renderer_settings.screenshot_requested) { + return; + } + + RenderToBuffer(framebuffers, renderer_settings.screenshot_framebuffer_layout, + renderer_settings.screenshot_bits); renderer_settings.screenshot_complete_callback(true); renderer_settings.screenshot_requested = false; } +void RendererOpenGL::RenderAppletCaptureLayer( + std::span framebuffers) { + GLint old_read_fb; + GLint old_draw_fb; + glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb); + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &old_draw_fb); + + glBindFramebuffer(GL_FRAMEBUFFER, capture_framebuffer.handle); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, + capture_renderbuffer.handle); + + blit_applet->DrawScreen(framebuffers, VideoCore::Capture::Layout, true); + + glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read_fb); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb); +} + +std::vector RendererOpenGL::GetAppletCaptureBuffer() { + using namespace VideoCore::Capture; + + std::vector linear(TiledSize); + std::vector out(TiledSize); + + GLint old_read_fb; + GLint old_draw_fb; + GLint old_pixel_pack_buffer; + GLint old_pack_row_length; + glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb); + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &old_draw_fb); + glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &old_pixel_pack_buffer); + glGetIntegerv(GL_PACK_ROW_LENGTH, &old_pack_row_length); + + glBindFramebuffer(GL_FRAMEBUFFER, capture_framebuffer.handle); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, + capture_renderbuffer.handle); + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + glPixelStorei(GL_PACK_ROW_LENGTH, 0); + glReadPixels(0, 0, LinearWidth, LinearHeight, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, + linear.data()); + + glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read_fb); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb); + glBindBuffer(GL_PIXEL_PACK_BUFFER, old_pixel_pack_buffer); + glPixelStorei(GL_PACK_ROW_LENGTH, old_pack_row_length); + + Tegra::Texture::SwizzleTexture(out, linear, BytesPerPixel, LinearWidth, LinearHeight, + LinearDepth, BlockHeight, BlockDepth); + + return out; +} + } // namespace OpenGL diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index c4625c96e..60d6a1477 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h @@ -42,6 +42,8 @@ public: void Composite(std::span framebuffers) override; + std::vector GetAppletCaptureBuffer() override; + VideoCore::RasterizerInterface* ReadRasterizer() override { return &rasterizer; } @@ -52,7 +54,11 @@ public: private: void AddTelemetryFields(); + + void RenderToBuffer(std::span framebuffers, + const Layout::FramebufferLayout& layout, void* dst); void RenderScreenshot(std::span framebuffers); + void RenderAppletCaptureLayer(std::span framebuffers); Core::TelemetrySession& telemetry_session; Core::Frontend::EmuWindow& emu_window; @@ -64,8 +70,11 @@ private: ProgramManager program_manager; RasterizerOpenGL rasterizer; OGLFramebuffer screenshot_framebuffer; + OGLFramebuffer capture_framebuffer; + OGLRenderbuffer capture_renderbuffer; std::unique_ptr blit_screen; + std::unique_ptr blit_applet; }; } // namespace OpenGL diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index c7c234fd8..c148efef2 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp @@ -19,6 +19,7 @@ #include "core/core_timing.h" #include "core/frontend/graphics_context.h" #include "core/telemetry_session.h" +#include "video_core/capture.h" #include "video_core/gpu.h" #include "video_core/renderer_vulkan/present/util.h" #include "video_core/renderer_vulkan/renderer_vulkan.h" @@ -38,6 +39,20 @@ namespace Vulkan { namespace { + +constexpr VkExtent2D CaptureImageSize{ + .width = VideoCore::Capture::LinearWidth, + .height = VideoCore::Capture::LinearHeight, +}; + +constexpr VkExtent3D CaptureImageExtent{ + .width = VideoCore::Capture::LinearWidth, + .height = VideoCore::Capture::LinearHeight, + .depth = VideoCore::Capture::LinearDepth, +}; + +constexpr VkFormat CaptureFormat = VK_FORMAT_A8B8G8R8_UNORM_PACK32; + std::string GetReadableVersion(u32 version) { return fmt::format("{}.{}.{}", VK_VERSION_MAJOR(version), VK_VERSION_MINOR(version), VK_VERSION_PATCH(version)); @@ -100,11 +115,11 @@ RendererVulkan::RendererVulkan(Core::TelemetrySession& telemetry_session_, present_manager(instance, render_window, device, memory_allocator, scheduler, swapchain, surface), blit_swapchain(device_memory, device, memory_allocator, present_manager, scheduler), - blit_screenshot(device_memory, device, memory_allocator, present_manager, scheduler), - blit_application_layer(device_memory, device, memory_allocator, present_manager, scheduler), + blit_capture(device_memory, device, memory_allocator, present_manager, scheduler), + blit_applet(device_memory, device, memory_allocator, present_manager, scheduler), rasterizer(render_window, gpu, device_memory, device, memory_allocator, state_tracker, scheduler), - application_frame() { + applet_frame() { if (Settings::values.renderer_force_max_clock.GetValue() && device.ShouldBoostClocks()) { turbo_mode.emplace(instance, dld); scheduler.RegisterOnSubmit([this] { turbo_mode->QueueSubmitted(); }); @@ -127,6 +142,8 @@ void RendererVulkan::Composite(std::span framebu SCOPE_EXIT({ render_window.OnFrameDisplayed(); }); + RenderAppletCaptureLayer(framebuffers); + if (!render_window.IsShown()) { return; } @@ -169,30 +186,20 @@ void RendererVulkan::Report() const { telemetry_session.AddField(field, "GPU_Vulkan_Extensions", extensions); } -void Vulkan::RendererVulkan::RenderScreenshot( - std::span framebuffers) { - if (!renderer_settings.screenshot_requested) { - return; - } - - constexpr VkFormat ScreenshotFormat{VK_FORMAT_B8G8R8A8_UNORM}; - const Layout::FramebufferLayout layout{renderer_settings.screenshot_framebuffer_layout}; - +vk::Buffer RendererVulkan::RenderToBuffer(std::span framebuffers, + const Layout::FramebufferLayout& layout, VkFormat format, + VkDeviceSize buffer_size) { auto frame = [&]() { Frame f{}; - f.image = CreateWrappedImage(memory_allocator, VkExtent2D{layout.width, layout.height}, - ScreenshotFormat); - f.image_view = CreateWrappedImageView(device, f.image, ScreenshotFormat); - f.framebuffer = blit_screenshot.CreateFramebuffer(layout, *f.image_view, ScreenshotFormat); + f.image = + CreateWrappedImage(memory_allocator, VkExtent2D{layout.width, layout.height}, format); + f.image_view = CreateWrappedImageView(device, f.image, format); + f.framebuffer = blit_capture.CreateFramebuffer(layout, *f.image_view, format); return f; }(); - blit_screenshot.DrawToFrame(rasterizer, &frame, framebuffers, layout, 1, - VK_FORMAT_B8G8R8A8_UNORM); - - const auto dst_buffer = CreateWrappedBuffer( - memory_allocator, static_cast(layout.width * layout.height * 4), - MemoryUsage::Download); + auto dst_buffer = CreateWrappedBuffer(memory_allocator, buffer_size, MemoryUsage::Download); + blit_capture.DrawToFrame(rasterizer, &frame, framebuffers, layout, 1, format); scheduler.RequestOutsideRenderPassOperationContext(); scheduler.Record([&](vk::CommandBuffer cmdbuf) { @@ -200,15 +207,68 @@ void Vulkan::RendererVulkan::RenderScreenshot( VkExtent3D{layout.width, layout.height, 1}); }); - // Ensure the copy is fully completed before saving the screenshot + // Ensure the copy is fully completed before saving the capture scheduler.Finish(); - // Copy backing image data to the QImage screenshot buffer + // Copy backing image data to the capture buffer dst_buffer.Invalidate(); + return dst_buffer; +} + +void RendererVulkan::RenderScreenshot(std::span framebuffers) { + if (!renderer_settings.screenshot_requested) { + return; + } + + const auto& layout{renderer_settings.screenshot_framebuffer_layout}; + const auto dst_buffer = RenderToBuffer(framebuffers, layout, VK_FORMAT_B8G8R8A8_UNORM, + layout.width * layout.height * 4); + std::memcpy(renderer_settings.screenshot_bits, dst_buffer.Mapped().data(), dst_buffer.Mapped().size()); renderer_settings.screenshot_complete_callback(false); renderer_settings.screenshot_requested = false; } +std::vector RendererVulkan::GetAppletCaptureBuffer() { + using namespace VideoCore::Capture; + + std::vector out(VideoCore::Capture::TiledSize); + + if (!applet_frame.image) { + return out; + } + + const auto dst_buffer = + CreateWrappedBuffer(memory_allocator, VideoCore::Capture::TiledSize, MemoryUsage::Download); + + scheduler.RequestOutsideRenderPassOperationContext(); + scheduler.Record([&](vk::CommandBuffer cmdbuf) { + DownloadColorImage(cmdbuf, *applet_frame.image, *dst_buffer, CaptureImageExtent); + }); + + // Ensure the copy is fully completed before writing the capture + scheduler.Finish(); + + // Swizzle image data to the capture buffer + dst_buffer.Invalidate(); + Tegra::Texture::SwizzleTexture(out, dst_buffer.Mapped(), BytesPerPixel, LinearWidth, + LinearHeight, LinearDepth, BlockHeight, BlockDepth); + + return out; +} + +void RendererVulkan::RenderAppletCaptureLayer( + std::span framebuffers) { + if (!applet_frame.image) { + applet_frame.image = CreateWrappedImage(memory_allocator, CaptureImageSize, CaptureFormat); + applet_frame.image_view = CreateWrappedImageView(device, applet_frame.image, CaptureFormat); + applet_frame.framebuffer = blit_applet.CreateFramebuffer( + VideoCore::Capture::Layout, *applet_frame.image_view, CaptureFormat); + } + + blit_applet.DrawToFrame(rasterizer, &applet_frame, framebuffers, VideoCore::Capture::Layout, 1, + CaptureFormat); +} + } // namespace Vulkan diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.h b/src/video_core/renderer_vulkan/renderer_vulkan.h index ed9c7af7f..fb9d83412 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.h +++ b/src/video_core/renderer_vulkan/renderer_vulkan.h @@ -48,6 +48,8 @@ public: void Composite(std::span framebuffers) override; + std::vector GetAppletCaptureBuffer() override; + VideoCore::RasterizerInterface* ReadRasterizer() override { return &rasterizer; } @@ -59,7 +61,11 @@ public: private: void Report() const; + vk::Buffer RenderToBuffer(std::span framebuffers, + const Layout::FramebufferLayout& layout, VkFormat format, + VkDeviceSize buffer_size); void RenderScreenshot(std::span framebuffers); + void RenderAppletCaptureLayer(std::span framebuffers); Core::TelemetrySession& telemetry_session; Tegra::MaxwellDeviceMemoryManager& device_memory; @@ -79,12 +85,12 @@ private: Swapchain swapchain; PresentManager present_manager; BlitScreen blit_swapchain; - BlitScreen blit_screenshot; - BlitScreen blit_application_layer; + BlitScreen blit_capture; + BlitScreen blit_applet; RasterizerVulkan rasterizer; std::optional turbo_mode; - Frame application_frame; + Frame applet_frame; }; } // namespace Vulkan -- cgit v1.2.3 From fa123843506ee748bf4d220253bc52e58cf36fe6 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 26 Jan 2024 23:28:24 -0500 Subject: general: add default configurations for applet mode --- src/common/settings.cpp | 3 + src/common/settings.h | 32 ++++++++ src/common/settings_common.h | 1 + src/common/settings_enums.h | 2 + src/core/hle/service/am/library_applet_creator.cpp | 51 +++++++++++-- src/frontend_common/config.cpp | 18 +++++ src/frontend_common/config.h | 2 + src/yuzu/CMakeLists.txt | 3 + src/yuzu/configuration/configure_applets.cpp | 86 ++++++++++++++++++++++ src/yuzu/configuration/configure_applets.h | 48 ++++++++++++ src/yuzu/configuration/configure_applets.ui | 65 ++++++++++++++++ src/yuzu/configuration/configure_dialog.cpp | 7 +- src/yuzu/configuration/configure_dialog.h | 2 + src/yuzu/configuration/shared_translation.cpp | 22 ++++++ 14 files changed, 334 insertions(+), 8 deletions(-) create mode 100644 src/yuzu/configuration/configure_applets.cpp create mode 100644 src/yuzu/configuration/configure_applets.h create mode 100644 src/yuzu/configuration/configure_applets.ui (limited to 'src/core/hle/service/am') diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 07709d4e5..80d388fe8 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -30,6 +30,7 @@ namespace Settings { #define SETTING(TYPE, RANGED) template class Setting #define SWITCHABLE(TYPE, RANGED) template class SwitchableSetting +SETTING(AppletMode, false); SETTING(AudioEngine, false); SETTING(bool, false); SETTING(int, false); @@ -215,6 +216,8 @@ const char* TranslateCategory(Category category) { return "Debugging"; case Category::GpuDriver: return "GpuDriver"; + case Category::LibraryApplet: + return "LibraryApplet"; case Category::Miscellaneous: return "Miscellaneous"; case Category::Network: diff --git a/src/common/settings.h b/src/common/settings.h index f1b1add56..aa054dc24 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -133,6 +133,38 @@ struct TouchFromButtonMap { struct Values { Linkage linkage{}; + // Applet + Setting cabinet_applet_mode{linkage, AppletMode::LLE, "cabinet_applet_mode", + Category::LibraryApplet}; + Setting controller_applet_mode{linkage, AppletMode::HLE, "controller_applet_mode", + Category::LibraryApplet}; + Setting data_erase_applet_mode{linkage, AppletMode::HLE, "data_erase_applet_mode", + Category::LibraryApplet}; + Setting error_applet_mode{linkage, AppletMode::HLE, "error_applet_mode", + Category::LibraryApplet}; + Setting net_connect_applet_mode{linkage, AppletMode::HLE, "net_connect_applet_mode", + Category::LibraryApplet}; + Setting player_select_applet_mode{ + linkage, AppletMode::HLE, "player_select_applet_mode", Category::LibraryApplet}; + Setting swkbd_applet_mode{linkage, AppletMode::LLE, "swkbd_applet_mode", + Category::LibraryApplet}; + Setting mii_edit_applet_mode{linkage, AppletMode::LLE, "mii_edit_applet_mode", + Category::LibraryApplet}; + Setting web_applet_mode{linkage, AppletMode::HLE, "web_applet_mode", + Category::LibraryApplet}; + Setting shop_applet_mode{linkage, AppletMode::HLE, "shop_applet_mode", + Category::LibraryApplet}; + Setting photo_viewer_applet_mode{ + linkage, AppletMode::LLE, "photo_viewer_applet_mode", Category::LibraryApplet}; + Setting offline_web_applet_mode{linkage, AppletMode::LLE, "offline_web_applet_mode", + Category::LibraryApplet}; + Setting login_share_applet_mode{linkage, AppletMode::HLE, "login_share_applet_mode", + Category::LibraryApplet}; + Setting wifi_web_auth_applet_mode{ + linkage, AppletMode::HLE, "wifi_web_auth_applet_mode", Category::LibraryApplet}; + Setting my_page_applet_mode{linkage, AppletMode::LLE, "my_page_applet_mode", + Category::LibraryApplet}; + // Audio SwitchableSetting sink_id{linkage, AudioEngine::Auto, "output_engine", Category::Audio, Specialization::RuntimeList}; diff --git a/src/common/settings_common.h b/src/common/settings_common.h index 987489e8a..2df3f0809 100644 --- a/src/common/settings_common.h +++ b/src/common/settings_common.h @@ -44,6 +44,7 @@ enum class Category : u32 { Services, Paths, Linux, + LibraryApplet, MaxEnum, }; diff --git a/src/common/settings_enums.h b/src/common/settings_enums.h index 617036588..f42367e67 100644 --- a/src/common/settings_enums.h +++ b/src/common/settings_enums.h @@ -151,6 +151,8 @@ ENUM(AspectRatio, R16_9, R4_3, R21_9, R16_10, Stretch); ENUM(ConsoleMode, Handheld, Docked); +ENUM(AppletMode, HLE, LLE); + template inline std::string CanonicalizeEnum(Type id) { const auto group = EnumMetadata::Canonicalizations(); diff --git a/src/core/hle/service/am/library_applet_creator.cpp b/src/core/hle/service/am/library_applet_creator.cpp index ee646bea5..a883a021e 100644 --- a/src/core/hle/service/am/library_applet_creator.cpp +++ b/src/core/hle/service/am/library_applet_creator.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "common/settings.h" #include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/service/am/applet_data_broker.h" #include "core/hle/service/am/applet_manager.h" @@ -16,6 +17,34 @@ namespace Service::AM { namespace { +bool ShouldCreateGuestApplet(AppletId applet_id) { +#define X(Name, name) \ + if (applet_id == AppletId::Name && \ + Settings::values.name##_applet_mode.GetValue() != Settings::AppletMode::LLE) { \ + return false; \ + } + + X(Cabinet, cabinet) + X(Controller, controller) + X(DataErase, data_erase) + X(Error, error) + X(NetConnect, net_connect) + X(ProfileSelect, player_select) + X(SoftwareKeyboard, swkbd) + X(MiiEdit, mii_edit) + X(Web, web) + X(Shop, shop) + X(PhotoViewer, photo_viewer) + X(OfflineWeb, offline_web) + X(LoginShare, login_share) + X(WebAuth, wifi_web_auth) + X(MyPage, my_page) + +#undef X + + return true; +} + AppletProgramId AppletIdToProgramId(AppletId applet_id) { switch (applet_id) { case AppletId::OverlayDisplay: @@ -63,9 +92,10 @@ AppletProgramId AppletIdToProgramId(AppletId applet_id) { } } -[[maybe_unused]] std::shared_ptr CreateGuestApplet( - Core::System& system, std::shared_ptr caller_applet, AppletId applet_id, - LibraryAppletMode mode) { +std::shared_ptr CreateGuestApplet(Core::System& system, + std::shared_ptr caller_applet, + AppletId applet_id, + LibraryAppletMode mode) { const auto program_id = static_cast(AppletIdToProgramId(applet_id)); if (program_id == 0) { // Unknown applet @@ -117,9 +147,10 @@ AppletProgramId AppletIdToProgramId(AppletId applet_id) { return std::make_shared(system, broker, applet); } -[[maybe_unused]] std::shared_ptr CreateFrontendApplet( - Core::System& system, std::shared_ptr caller_applet, AppletId applet_id, - LibraryAppletMode mode) { +std::shared_ptr CreateFrontendApplet(Core::System& system, + std::shared_ptr caller_applet, + AppletId applet_id, + LibraryAppletMode mode) { const auto program_id = static_cast(AppletIdToProgramId(applet_id)); auto process = std::make_unique(system); @@ -163,7 +194,13 @@ void ILibraryAppletCreator::CreateLibraryApplet(HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called with applet_id={:08X}, applet_mode={:08X}", applet_id, applet_mode); - auto library_applet = CreateFrontendApplet(system, applet, applet_id, applet_mode); + std::shared_ptr library_applet; + if (ShouldCreateGuestApplet(applet_id)) { + library_applet = CreateGuestApplet(system, applet, applet_id, applet_mode); + } + if (!library_applet) { + library_applet = CreateFrontendApplet(system, applet, applet_id, applet_mode); + } if (!library_applet) { LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", applet_id); diff --git a/src/frontend_common/config.cpp b/src/frontend_common/config.cpp index d34624d28..cbbb07ac7 100644 --- a/src/frontend_common/config.cpp +++ b/src/frontend_common/config.cpp @@ -401,6 +401,14 @@ void Config::ReadNetworkValues() { EndGroup(); } +void Config::ReadLibraryAppletValues() { + BeginGroup(Settings::TranslateCategory(Settings::Category::LibraryApplet)); + + ReadCategory(Settings::Category::LibraryApplet); + + EndGroup(); +} + void Config::ReadValues() { if (global) { ReadDataStorageValues(); @@ -410,6 +418,7 @@ void Config::ReadValues() { ReadServiceValues(); ReadWebServiceValues(); ReadMiscellaneousValues(); + ReadLibraryAppletValues(); } ReadControlValues(); ReadCoreValues(); @@ -511,6 +520,7 @@ void Config::SaveValues() { SaveNetworkValues(); SaveWebServiceValues(); SaveMiscellaneousValues(); + SaveLibraryAppletValues(); } else { LOG_DEBUG(Config, "Saving only generic configuration values"); } @@ -691,6 +701,14 @@ void Config::SaveWebServiceValues() { EndGroup(); } +void Config::SaveLibraryAppletValues() { + BeginGroup(Settings::TranslateCategory(Settings::Category::LibraryApplet)); + + WriteCategory(Settings::Category::LibraryApplet); + + EndGroup(); +} + bool Config::ReadBooleanSetting(const std::string& key, const std::optional default_value) { std::string full_key = GetFullKey(key, false); if (!default_value.has_value()) { diff --git a/src/frontend_common/config.h b/src/frontend_common/config.h index 4ecb97044..8b0599cc3 100644 --- a/src/frontend_common/config.h +++ b/src/frontend_common/config.h @@ -88,6 +88,7 @@ protected: void ReadSystemValues(); void ReadWebServiceValues(); void ReadNetworkValues(); + void ReadLibraryAppletValues(); // Read platform specific sections virtual void ReadHidbusValues() = 0; @@ -121,6 +122,7 @@ protected: void SaveScreenshotValues(); void SaveSystemValues(); void SaveWebServiceValues(); + void SaveLibraryAppletValues(); // Save platform specific sections virtual void SaveHidbusValues() = 0; diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 76f06da12..0259a8c29 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -41,6 +41,9 @@ add_executable(yuzu configuration/configuration_shared.cpp configuration/configuration_shared.h configuration/configure.ui + configuration/configure_applets.cpp + configuration/configure_applets.h + configuration/configure_applets.ui configuration/configure_audio.cpp configuration/configure_audio.h configuration/configure_audio.ui diff --git a/src/yuzu/configuration/configure_applets.cpp b/src/yuzu/configuration/configure_applets.cpp new file mode 100644 index 000000000..513ecb548 --- /dev/null +++ b/src/yuzu/configuration/configure_applets.cpp @@ -0,0 +1,86 @@ +// SPDX-FileCopyrightText: 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "common/settings.h" +#include "core/core.h" +#include "ui_configure_applets.h" +#include "yuzu/configuration/configuration_shared.h" +#include "yuzu/configuration/configure_applets.h" +#include "yuzu/configuration/shared_widget.h" + +ConfigureApplets::ConfigureApplets(Core::System& system_, + std::shared_ptr> group_, + const ConfigurationShared::Builder& builder, QWidget* parent) + : Tab(group_, parent), ui{std::make_unique()}, system{system_} { + ui->setupUi(this); + + Setup(builder); + + SetConfiguration(); +} + +ConfigureApplets::~ConfigureApplets() = default; + +void ConfigureApplets::changeEvent(QEvent* event) { + if (event->type() == QEvent::LanguageChange) { + RetranslateUI(); + } + + QWidget::changeEvent(event); +} + +void ConfigureApplets::RetranslateUI() { + ui->retranslateUi(this); +} + +void ConfigureApplets::Setup(const ConfigurationShared::Builder& builder) { + auto& library_applets_layout = *ui->group_library_applet_modes->layout(); + std::map applets_hold{}; + + std::vector settings; + auto push = [&settings](auto& list) { + for (auto setting : list) { + settings.push_back(setting); + } + }; + + push(Settings::values.linkage.by_category[Settings::Category::LibraryApplet]); + + for (auto setting : settings) { + ConfigurationShared::Widget* widget = builder.BuildWidget(setting, apply_funcs); + + if (widget == nullptr) { + continue; + } + if (!widget->Valid()) { + widget->deleteLater(); + continue; + } + + // Untested applets + if (setting->Id() == Settings::values.data_erase_applet_mode.Id() || + setting->Id() == Settings::values.error_applet_mode.Id() || + setting->Id() == Settings::values.net_connect_applet_mode.Id() || + setting->Id() == Settings::values.web_applet_mode.Id() || + setting->Id() == Settings::values.shop_applet_mode.Id() || + setting->Id() == Settings::values.login_share_applet_mode.Id() || + setting->Id() == Settings::values.wifi_web_auth_applet_mode.Id() || + setting->Id() == Settings::values.my_page_applet_mode.Id()) { + widget->setHidden(true); + } + + applets_hold.emplace(setting->Id(), widget); + } + for (const auto& [label, widget] : applets_hold) { + library_applets_layout.addWidget(widget); + } +} + +void ConfigureApplets::SetConfiguration() {} + +void ConfigureApplets::ApplyConfiguration() { + const bool powered_on = system.IsPoweredOn(); + for (const auto& func : apply_funcs) { + func(powered_on); + } +} diff --git a/src/yuzu/configuration/configure_applets.h b/src/yuzu/configuration/configure_applets.h new file mode 100644 index 000000000..54f494d2f --- /dev/null +++ b/src/yuzu/configuration/configure_applets.h @@ -0,0 +1,48 @@ +// SPDX-FileCopyrightText: 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include "yuzu/configuration/configuration_shared.h" + +class QCheckBox; +class QLineEdit; +class QComboBox; +class QDateTimeEdit; +namespace Core { +class System; +} + +namespace Ui { +class ConfigureApplets; +} + +namespace ConfigurationShared { +class Builder; +} + +class ConfigureApplets : public ConfigurationShared::Tab { +public: + explicit ConfigureApplets(Core::System& system_, + std::shared_ptr> group, + const ConfigurationShared::Builder& builder, + QWidget* parent = nullptr); + ~ConfigureApplets() override; + + void ApplyConfiguration() override; + void SetConfiguration() override; + +private: + void changeEvent(QEvent* event) override; + void RetranslateUI(); + + void Setup(const ConfigurationShared::Builder& builder); + + std::vector> apply_funcs{}; + + std::unique_ptr ui; + bool enabled = false; + + Core::System& system; +}; diff --git a/src/yuzu/configuration/configure_applets.ui b/src/yuzu/configuration/configure_applets.ui new file mode 100644 index 000000000..6f2ca66bd --- /dev/null +++ b/src/yuzu/configuration/configure_applets.ui @@ -0,0 +1,65 @@ + + + ConfigureApplets + + + + 0 + 0 + 605 + 300 + + + + Form + + + Applets + + + + + + + + Applet mode preference + + + + + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index aab54a1cc..37f23388e 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -8,6 +8,7 @@ #include "core/core.h" #include "ui_configure.h" #include "vk_device_info.h" +#include "yuzu/configuration/configure_applets.h" #include "yuzu/configuration/configure_audio.h" #include "yuzu/configuration/configure_cpu.h" #include "yuzu/configuration/configure_debug_tab.h" @@ -34,6 +35,7 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, : QDialog(parent), ui{std::make_unique()}, registry(registry_), system{system_}, builder{std::make_unique( this, !system_.IsPoweredOn())}, + applets_tab{std::make_unique(system_, nullptr, *builder, this)}, audio_tab{std::make_unique(system_, nullptr, *builder, this)}, cpu_tab{std::make_unique(system_, nullptr, *builder, this)}, debug_tab_tab{std::make_unique(system_, this)}, @@ -58,6 +60,7 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, ui->setupUi(this); + ui->tabWidget->addTab(applets_tab.get(), tr("Applets")); ui->tabWidget->addTab(audio_tab.get(), tr("Audio")); ui->tabWidget->addTab(cpu_tab.get(), tr("CPU")); ui->tabWidget->addTab(debug_tab_tab.get(), tr("Debug")); @@ -124,6 +127,7 @@ void ConfigureDialog::ApplyConfiguration() { debug_tab_tab->ApplyConfiguration(); web_tab->ApplyConfiguration(); network_tab->ApplyConfiguration(); + applets_tab->ApplyConfiguration(); system.ApplySettings(); Settings::LogSettings(); } @@ -161,7 +165,8 @@ void ConfigureDialog::PopulateSelectionList() { {{tr("General"), {general_tab.get(), hotkeys_tab.get(), ui_tab.get(), web_tab.get(), debug_tab_tab.get()}}, {tr("System"), - {system_tab.get(), profile_tab.get(), network_tab.get(), filesystem_tab.get()}}, + {system_tab.get(), profile_tab.get(), network_tab.get(), filesystem_tab.get(), + applets_tab.get()}}, {tr("CPU"), {cpu_tab.get()}}, {tr("Graphics"), {graphics_tab.get(), graphics_advanced_tab.get()}}, {tr("Audio"), {audio_tab.get()}}, diff --git a/src/yuzu/configuration/configure_dialog.h b/src/yuzu/configuration/configure_dialog.h index b28ce288c..d0a24a07b 100644 --- a/src/yuzu/configuration/configure_dialog.h +++ b/src/yuzu/configuration/configure_dialog.h @@ -15,6 +15,7 @@ namespace Core { class System; } +class ConfigureApplets; class ConfigureAudio; class ConfigureCpu; class ConfigureDebugTab; @@ -75,6 +76,7 @@ private: std::unique_ptr builder; std::vector tab_group; + std::unique_ptr applets_tab; std::unique_ptr audio_tab; std::unique_ptr cpu_tab; std::unique_ptr debug_tab_tab; diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp index ed9c7d859..ce65b2bf1 100644 --- a/src/yuzu/configuration/shared_translation.cpp +++ b/src/yuzu/configuration/shared_translation.cpp @@ -26,6 +26,23 @@ std::unique_ptr InitializeTranslations(QWidget* parent) { // A setting can be ignored by giving it a blank name + // Applets + INSERT(Settings, cabinet_applet_mode, tr("Amiibo editor"), QStringLiteral()); + INSERT(Settings, controller_applet_mode, tr("Controller configuration"), QStringLiteral()); + INSERT(Settings, data_erase_applet_mode, tr("Data erase"), QStringLiteral()); + INSERT(Settings, error_applet_mode, tr("Error"), QStringLiteral()); + INSERT(Settings, net_connect_applet_mode, tr("Net connect"), QStringLiteral()); + INSERT(Settings, player_select_applet_mode, tr("Player select"), QStringLiteral()); + INSERT(Settings, swkbd_applet_mode, tr("Software keyboard"), QStringLiteral()); + INSERT(Settings, mii_edit_applet_mode, tr("Mii Edit"), QStringLiteral()); + INSERT(Settings, web_applet_mode, tr("Online web"), QStringLiteral()); + INSERT(Settings, shop_applet_mode, tr("Shop"), QStringLiteral()); + INSERT(Settings, photo_viewer_applet_mode, tr("Photo viewer"), QStringLiteral()); + INSERT(Settings, offline_web_applet_mode, tr("Offline web"), QStringLiteral()); + INSERT(Settings, login_share_applet_mode, tr("Login share"), QStringLiteral()); + INSERT(Settings, wifi_web_auth_applet_mode, tr("Wifi web auth"), QStringLiteral()); + INSERT(Settings, my_page_applet_mode, tr("My page"), QStringLiteral()); + // Audio INSERT(Settings, sink_id, tr("Output Engine:"), QStringLiteral()); INSERT(Settings, audio_output_device_id, tr("Output Device:"), QStringLiteral()); @@ -203,6 +220,11 @@ std::unique_ptr ComboboxEnumeration(QWidget* parent) { #define PAIR(ENUM, VALUE, TRANSLATION) {static_cast(Settings::ENUM::VALUE), (TRANSLATION)} // Intentionally skipping VSyncMode to let the UI fill that one out + translations->insert({Settings::EnumMetadata::Index(), + { + PAIR(AppletMode, HLE, tr("Custom frontend")), + PAIR(AppletMode, LLE, tr("Real applet")), + }}); translations->insert({Settings::EnumMetadata::Index(), { -- cgit v1.2.3 From 70590f79f8fd26d10274dca0b9a3f05f3c0ebd9e Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 3 Feb 2024 00:48:35 -0500 Subject: am: stub SetMediaPlaybackState for self controller --- src/core/hle/service/am/self_controller.cpp | 15 ++++++++++++++- src/core/hle/service/am/self_controller.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/core/hle/service/am') diff --git a/src/core/hle/service/am/self_controller.cpp b/src/core/hle/service/am/self_controller.cpp index b92663b2b..65e249c0c 100644 --- a/src/core/hle/service/am/self_controller.cpp +++ b/src/core/hle/service/am/self_controller.cpp @@ -1,10 +1,13 @@ // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "common/logging/log.h" +#include "core/hle/result.h" #include "core/hle/service/am/am_results.h" #include "core/hle/service/am/frontend/applets.h" #include "core/hle/service/am/self_controller.h" #include "core/hle/service/caps/caps_su.h" +#include "core/hle/service/hle_ipc.h" #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nvnflinger/fb_share_buffer_manager.h" #include "core/hle/service/nvnflinger/nvnflinger.h" @@ -47,7 +50,7 @@ ISelfController::ISelfController(Core::System& system_, std::shared_ptr {50, &ISelfController::SetHandlesRequestToDisplay, "SetHandlesRequestToDisplay"}, {51, &ISelfController::ApproveToDisplay, "ApproveToDisplay"}, {60, nullptr, "OverrideAutoSleepTimeAndDimmingTime"}, - {61, nullptr, "SetMediaPlaybackState"}, + {61, &ISelfController::SetMediaPlaybackState, "SetMediaPlaybackState"}, {62, &ISelfController::SetIdleTimeDetectionExtension, "SetIdleTimeDetectionExtension"}, {63, &ISelfController::GetIdleTimeDetectionExtension, "GetIdleTimeDetectionExtension"}, {64, nullptr, "SetInputDetectionSourceSet"}, @@ -324,6 +327,16 @@ void ISelfController::ApproveToDisplay(HLERequestContext& ctx) { rb.Push(ResultSuccess); } +void ISelfController::SetMediaPlaybackState(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const u8 state = rp.Pop(); + + LOG_WARNING(Service_AM, "(STUBBED) called, state={}", state); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); +} + void ISelfController::SetIdleTimeDetectionExtension(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; diff --git a/src/core/hle/service/am/self_controller.h b/src/core/hle/service/am/self_controller.h index a63bc2e74..ab21a1881 100644 --- a/src/core/hle/service/am/self_controller.h +++ b/src/core/hle/service/am/self_controller.h @@ -3,6 +3,7 @@ #pragma once +#include "core/hle/service/hle_ipc.h" #include "core/hle/service/kernel_helpers.h" #include "core/hle/service/service.h" @@ -38,6 +39,7 @@ private: void CreateManagedDisplaySeparableLayer(HLERequestContext& ctx); void SetHandlesRequestToDisplay(HLERequestContext& ctx); void ApproveToDisplay(HLERequestContext& ctx); + void SetMediaPlaybackState(HLERequestContext& ctx); void SetIdleTimeDetectionExtension(HLERequestContext& ctx); void GetIdleTimeDetectionExtension(HLERequestContext& ctx); void ReportUserIsActive(HLERequestContext& ctx); -- cgit v1.2.3 From b206ea5cfe90bca01b48e44a0cf93cb51f4877d1 Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 4 Feb 2024 16:05:44 -0500 Subject: am: fix focus states and display of indirect keyboard --- src/core/hle/service/am/library_applet_creator.cpp | 18 ++++++------------ src/core/hle/service/am/system_buffer_manager.cpp | 3 ++- src/core/hle/service/am/window_controller.cpp | 4 ++-- 3 files changed, 10 insertions(+), 15 deletions(-) (limited to 'src/core/hle/service/am') diff --git a/src/core/hle/service/am/library_applet_creator.cpp b/src/core/hle/service/am/library_applet_creator.cpp index a883a021e..c48ed29bc 100644 --- a/src/core/hle/service/am/library_applet_creator.cpp +++ b/src/core/hle/service/am/library_applet_creator.cpp @@ -118,23 +118,17 @@ std::shared_ptr CreateGuestApplet(Core::System& system, switch (mode) { case LibraryAppletMode::AllForeground: case LibraryAppletMode::NoUi: - applet->focus_state = FocusState::InFocus; + case LibraryAppletMode::PartialForeground: + case LibraryAppletMode::PartialForegroundIndirectDisplay: applet->hid_registration.EnableAppletToGetInput(true); + applet->focus_state = FocusState::InFocus; applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground); - applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); break; case LibraryAppletMode::AllForegroundInitiallyHidden: - applet->system_buffer_manager.SetWindowVisibility(false); - applet->focus_state = FocusState::NotInFocus; applet->hid_registration.EnableAppletToGetInput(false); - applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); - break; - case LibraryAppletMode::PartialForeground: - case LibraryAppletMode::PartialForegroundIndirectDisplay: - default: - applet->focus_state = FocusState::Background; - applet->hid_registration.EnableAppletToGetInput(true); - applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); + applet->focus_state = FocusState::NotInFocus; + applet->system_buffer_manager.SetWindowVisibility(false); + applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoBackground); break; } diff --git a/src/core/hle/service/am/system_buffer_manager.cpp b/src/core/hle/service/am/system_buffer_manager.cpp index 7fb9e3a75..48923fe41 100644 --- a/src/core/hle/service/am/system_buffer_manager.cpp +++ b/src/core/hle/service/am/system_buffer_manager.cpp @@ -38,7 +38,8 @@ bool SystemBufferManager::Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel: } Nvnflinger::LayerBlending blending = Nvnflinger::LayerBlending::None; - if (mode == LibraryAppletMode::PartialForeground) { + if (mode == LibraryAppletMode::PartialForeground || + mode == LibraryAppletMode::PartialForegroundIndirectDisplay) { blending = Nvnflinger::LayerBlending::Coverage; } diff --git a/src/core/hle/service/am/window_controller.cpp b/src/core/hle/service/am/window_controller.cpp index f00957f83..c07ef228b 100644 --- a/src/core/hle/service/am/window_controller.cpp +++ b/src/core/hle/service/am/window_controller.cpp @@ -62,12 +62,12 @@ void IWindowController::SetAppletWindowVisibility(HLERequestContext& ctx) { applet->hid_registration.EnableAppletToGetInput(visible); if (visible) { - applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground); applet->focus_state = FocusState::InFocus; + applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground); } else { applet->focus_state = FocusState::NotInFocus; + applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoBackground); } - applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); -- cgit v1.2.3 From 4677fd3f64dd51c7419e0268df9fe10f8f6ce0fd Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 9 Feb 2024 11:36:40 -0500 Subject: am: use applet program loading for tested versions --- src/core/file_sys/content_archive.cpp | 4 ++++ src/core/file_sys/content_archive.h | 1 + src/core/hle/service/am/library_applet_creator.cpp | 10 +++++++++- src/core/hle/service/am/process.cpp | 23 +++++++++++++++++----- src/core/hle/service/am/process.h | 2 +- 5 files changed, 33 insertions(+), 7 deletions(-) (limited to 'src/core/hle/service/am') diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index 285fe4db6..665252358 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -172,6 +172,10 @@ u32 NCA::GetSDKVersion() const { return reader->GetSdkAddonVersion(); } +u8 NCA::GetKeyGeneration() const { + return reader->GetKeyGeneration(); +} + bool NCA::IsUpdate() const { return is_update; } diff --git a/src/core/file_sys/content_archive.h b/src/core/file_sys/content_archive.h index f68464eb0..8560617f5 100644 --- a/src/core/file_sys/content_archive.h +++ b/src/core/file_sys/content_archive.h @@ -77,6 +77,7 @@ public: u64 GetTitleId() const; RightsId GetRightsId() const; u32 GetSDKVersion() const; + u8 GetKeyGeneration() const; bool IsUpdate() const; VirtualFile GetRomFS() const; diff --git a/src/core/hle/service/am/library_applet_creator.cpp b/src/core/hle/service/am/library_applet_creator.cpp index c48ed29bc..00d5a0705 100644 --- a/src/core/hle/service/am/library_applet_creator.cpp +++ b/src/core/hle/service/am/library_applet_creator.cpp @@ -102,8 +102,16 @@ std::shared_ptr CreateGuestApplet(Core::System& system, return {}; } + // TODO: enable other versions of applets + enum : u8 { + Firmware1400 = 14, + Firmware1500 = 15, + Firmware1600 = 16, + Firmware1700 = 17, + }; + auto process = std::make_unique(system); - if (!process->Initialize(program_id)) { + if (!process->Initialize(program_id, Firmware1400, Firmware1700)) { // Couldn't initialize the guest process return {}; } diff --git a/src/core/hle/service/am/process.cpp b/src/core/hle/service/am/process.cpp index 16b685f86..992c50713 100644 --- a/src/core/hle/service/am/process.cpp +++ b/src/core/hle/service/am/process.cpp @@ -3,6 +3,7 @@ #include "common/scope_exit.h" +#include "core/file_sys/content_archive.h" #include "core/file_sys/nca_metadata.h" #include "core/file_sys/registered_cache.h" #include "core/hle/kernel/k_process.h" @@ -20,7 +21,7 @@ Process::~Process() { this->Finalize(); } -bool Process::Initialize(u64 program_id) { +bool Process::Initialize(u64 program_id, u8 minimum_key_generation, u8 maximum_key_generation) { // First, ensure we are not holding another process. this->Finalize(); @@ -29,21 +30,33 @@ bool Process::Initialize(u64 program_id) { // Attempt to load program NCA. const FileSys::RegisteredCache* bis_system{}; - FileSys::VirtualFile nca{}; + FileSys::VirtualFile nca_raw{}; // Get the program NCA from built-in storage. bis_system = fsc.GetSystemNANDContents(); if (bis_system) { - nca = bis_system->GetEntryRaw(program_id, FileSys::ContentRecordType::Program); + nca_raw = bis_system->GetEntryRaw(program_id, FileSys::ContentRecordType::Program); } // Ensure we retrieved a program NCA. - if (!nca) { + if (!nca_raw) { return false; } + // Ensure we have a suitable version. + if (minimum_key_generation > 0) { + FileSys::NCA nca(nca_raw); + if (nca.GetStatus() == Loader::ResultStatus::Success && + (nca.GetKeyGeneration() < minimum_key_generation || + nca.GetKeyGeneration() > maximum_key_generation)) { + LOG_WARNING(Service_LDR, "Skipping program {:016X} with generation {}", program_id, + nca.GetKeyGeneration()); + return false; + } + } + // Get the appropriate loader to parse this NCA. - auto app_loader = Loader::GetLoader(m_system, nca, program_id, 0); + auto app_loader = Loader::GetLoader(m_system, nca_raw, program_id, 0); // Ensure we have a loader which can parse the NCA. if (!app_loader) { diff --git a/src/core/hle/service/am/process.h b/src/core/hle/service/am/process.h index 4b908ade4..4b8102fb6 100644 --- a/src/core/hle/service/am/process.h +++ b/src/core/hle/service/am/process.h @@ -21,7 +21,7 @@ public: explicit Process(Core::System& system); ~Process(); - bool Initialize(u64 program_id); + bool Initialize(u64 program_id, u8 minimum_key_generation, u8 maximum_key_generation); void Finalize(); bool Run(); -- cgit v1.2.3