diff options
| author | 2024-01-26 16:10:21 -0500 | |
|---|---|---|
| committer | 2024-02-09 09:20:53 -0500 | |
| commit | 0cb413c3d31b93ce347e997b9674c304094dab09 (patch) | |
| tree | 959ef73963ea1e7975690d31eaf4ddc2f2ad6e19 /src | |
| parent | nvnflinger/gpu: implement blending (diff) | |
| download | yuzu-0cb413c3d31b93ce347e997b9674c304094dab09.tar.gz yuzu-0cb413c3d31b93ce347e997b9674c304094dab09.tar.xz yuzu-0cb413c3d31b93ce347e997b9674c304094dab09.zip | |
nvnflinger/gpu: implement applet capture
Diffstat (limited to 'src')
19 files changed, 288 insertions, 55 deletions
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) { | |||
| 68 | 68 | ||
| 69 | Result SystemBufferManager::WriteAppletCaptureBuffer(bool* out_was_written, | 69 | Result SystemBufferManager::WriteAppletCaptureBuffer(bool* out_was_written, |
| 70 | s32* out_fbshare_layer_index) { | 70 | s32* out_fbshare_layer_index) { |
| 71 | // TODO | 71 | if (!m_buffer_sharing_enabled) { |
| 72 | R_SUCCEED(); | 72 | return VI::ResultPermissionDenied; |
| 73 | } | ||
| 74 | |||
| 75 | return m_nvnflinger->GetSystemBufferManager().WriteAppletCaptureBuffer(out_was_written, | ||
| 76 | out_fbshare_layer_index); | ||
| 73 | } | 77 | } |
| 74 | 78 | ||
| 75 | } // namespace Service::AM | 79 | } // 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 @@ | |||
| 15 | #include "core/hle/service/vi/layer/vi_layer.h" | 15 | #include "core/hle/service/vi/layer/vi_layer.h" |
| 16 | #include "core/hle/service/vi/vi_results.h" | 16 | #include "core/hle/service/vi/vi_results.h" |
| 17 | #include "video_core/gpu.h" | 17 | #include "video_core/gpu.h" |
| 18 | #include "video_core/host1x/host1x.h" | ||
| 18 | 19 | ||
| 19 | namespace Service::Nvnflinger { | 20 | namespace Service::Nvnflinger { |
| 20 | 21 | ||
| @@ -414,9 +415,30 @@ Result FbShareBufferManager::GetSharedFrameBufferAcquirableEvent(Kernel::KReadab | |||
| 414 | R_SUCCEED(); | 415 | R_SUCCEED(); |
| 415 | } | 416 | } |
| 416 | 417 | ||
| 417 | Result FbShareBufferManager::WriteAppletCaptureBuffer(bool* out_was_written, | 418 | Result FbShareBufferManager::WriteAppletCaptureBuffer(bool* out_was_written, s32* out_layer_index) { |
| 418 | s32* out_layer_index) { | 419 | std::vector<u8> capture_buffer(m_system.GPU().GetAppletCaptureBuffer()); |
| 419 | // TODO | 420 | Common::ScratchBuffer<u32> scratch; |
| 421 | |||
| 422 | // TODO: this could be optimized | ||
| 423 | s64 e = -1280 * 768 * 4; | ||
| 424 | for (auto& block : *m_buffer_page_group) { | ||
| 425 | u8* start = m_system.DeviceMemory().GetPointer<u8>(block.GetAddress()); | ||
| 426 | u8* end = m_system.DeviceMemory().GetPointer<u8>(block.GetAddress() + block.GetSize()); | ||
| 427 | |||
| 428 | for (; start < end; start++) { | ||
| 429 | *start = 0; | ||
| 430 | |||
| 431 | if (e >= 0 && e < static_cast<s64>(capture_buffer.size())) { | ||
| 432 | *start = capture_buffer[e]; | ||
| 433 | } | ||
| 434 | e++; | ||
| 435 | } | ||
| 436 | |||
| 437 | m_system.GPU().Host1x().MemoryManager().ApplyOpOnPointer(start, scratch, [&](DAddr addr) { | ||
| 438 | m_system.GPU().InvalidateRegion(addr, end - start); | ||
| 439 | }); | ||
| 440 | } | ||
| 441 | |||
| 420 | *out_was_written = true; | 442 | *out_was_written = true; |
| 421 | *out_layer_index = 1; | 443 | *out_layer_index = 1; |
| 422 | R_SUCCEED(); | 444 | 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 | |||
| 18 | buffer_cache/usage_tracker.h | 18 | buffer_cache/usage_tracker.h |
| 19 | buffer_cache/word_manager.h | 19 | buffer_cache/word_manager.h |
| 20 | cache_types.h | 20 | cache_types.h |
| 21 | capture.h | ||
| 21 | cdma_pusher.cpp | 22 | cdma_pusher.cpp |
| 22 | cdma_pusher.h | 23 | cdma_pusher.h |
| 23 | compatible_formats.cpp | 24 | 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 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "common/alignment.h" | ||
| 7 | #include "common/bit_util.h" | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "core/frontend/framebuffer_layout.h" | ||
| 10 | #include "video_core/surface.h" | ||
| 11 | |||
| 12 | namespace VideoCore::Capture { | ||
| 13 | |||
| 14 | constexpr u32 BlockHeight = 4; | ||
| 15 | constexpr u32 BlockDepth = 0; | ||
| 16 | constexpr u32 BppLog2 = 2; | ||
| 17 | |||
| 18 | constexpr auto PixelFormat = Surface::PixelFormat::B8G8R8A8_UNORM; | ||
| 19 | |||
| 20 | constexpr auto LinearWidth = Layout::ScreenUndocked::Width; | ||
| 21 | constexpr auto LinearHeight = Layout::ScreenUndocked::Height; | ||
| 22 | constexpr auto LinearDepth = 1U; | ||
| 23 | constexpr auto BytesPerPixel = 4U; | ||
| 24 | |||
| 25 | constexpr auto TiledWidth = LinearWidth; | ||
| 26 | constexpr auto TiledHeight = Common::AlignUpLog2(LinearHeight, BlockHeight + BlockDepth + BppLog2); | ||
| 27 | constexpr auto TiledSize = TiledWidth * TiledHeight * (1 << BppLog2); | ||
| 28 | |||
| 29 | constexpr Layout::FramebufferLayout Layout{ | ||
| 30 | .width = LinearWidth, | ||
| 31 | .height = LinearHeight, | ||
| 32 | .screen = {0, 0, LinearWidth, LinearHeight}, | ||
| 33 | .is_srgb = false, | ||
| 34 | }; | ||
| 35 | |||
| 36 | } // 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 { | |||
| 347 | WaitForSyncOperation(wait_fence); | 347 | WaitForSyncOperation(wait_fence); |
| 348 | } | 348 | } |
| 349 | 349 | ||
| 350 | std::vector<u8> GetAppletCaptureBuffer() { | ||
| 351 | std::vector<u8> out; | ||
| 352 | |||
| 353 | const auto wait_fence = | ||
| 354 | RequestSyncOperation([&] { out = renderer->GetAppletCaptureBuffer(); }); | ||
| 355 | gpu_thread.TickGPU(); | ||
| 356 | WaitForSyncOperation(wait_fence); | ||
| 357 | |||
| 358 | return out; | ||
| 359 | } | ||
| 360 | |||
| 350 | GPU& gpu; | 361 | GPU& gpu; |
| 351 | Core::System& system; | 362 | Core::System& system; |
| 352 | Host1x::Host1x& host1x; | 363 | Host1x::Host1x& host1x; |
| @@ -505,6 +516,10 @@ void GPU::RequestComposite(std::vector<Tegra::FramebufferConfig>&& layers, | |||
| 505 | impl->RequestComposite(std::move(layers), std::move(fences)); | 516 | impl->RequestComposite(std::move(layers), std::move(fences)); |
| 506 | } | 517 | } |
| 507 | 518 | ||
| 519 | std::vector<u8> GPU::GetAppletCaptureBuffer() { | ||
| 520 | return impl->GetAppletCaptureBuffer(); | ||
| 521 | } | ||
| 522 | |||
| 508 | u64 GPU::GetTicks() const { | 523 | u64 GPU::GetTicks() const { |
| 509 | return impl->GetTicks(); | 524 | return impl->GetTicks(); |
| 510 | } | 525 | } |
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: | |||
| 215 | void RequestComposite(std::vector<Tegra::FramebufferConfig>&& layers, | 215 | void RequestComposite(std::vector<Tegra::FramebufferConfig>&& layers, |
| 216 | std::vector<Service::Nvidia::NvFence>&& fences); | 216 | std::vector<Service::Nvidia::NvFence>&& fences); |
| 217 | 217 | ||
| 218 | std::vector<u8> GetAppletCaptureBuffer(); | ||
| 219 | |||
| 218 | /// Performs any additional setup necessary in order to begin GPU emulation. | 220 | /// Performs any additional setup necessary in order to begin GPU emulation. |
| 219 | /// This can be used to launch any necessary threads and register any necessary | 221 | /// This can be used to launch any necessary threads and register any necessary |
| 220 | /// core timing events. | 222 | /// 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: | |||
| 40 | /// Finalize rendering the guest frame and draw into the presentation texture | 40 | /// Finalize rendering the guest frame and draw into the presentation texture |
| 41 | virtual void Composite(std::span<const Tegra::FramebufferConfig> layers) = 0; | 41 | virtual void Composite(std::span<const Tegra::FramebufferConfig> layers) = 0; |
| 42 | 42 | ||
| 43 | /// Get the tiled applet layer capture buffer | ||
| 44 | virtual std::vector<u8> GetAppletCaptureBuffer() = 0; | ||
| 45 | |||
| 43 | [[nodiscard]] virtual RasterizerInterface* ReadRasterizer() = 0; | 46 | [[nodiscard]] virtual RasterizerInterface* ReadRasterizer() = 0; |
| 44 | 47 | ||
| 45 | [[nodiscard]] virtual std::string GetDeviceVendor() const = 0; | 48 | [[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 @@ | |||
| 3 | 3 | ||
| 4 | #include "core/frontend/emu_window.h" | 4 | #include "core/frontend/emu_window.h" |
| 5 | #include "core/frontend/graphics_context.h" | 5 | #include "core/frontend/graphics_context.h" |
| 6 | #include "video_core/capture.h" | ||
| 6 | #include "video_core/renderer_null/renderer_null.h" | 7 | #include "video_core/renderer_null/renderer_null.h" |
| 7 | 8 | ||
| 8 | namespace Null { | 9 | namespace Null { |
| @@ -22,4 +23,8 @@ void RendererNull::Composite(std::span<const Tegra::FramebufferConfig> framebuff | |||
| 22 | render_window.OnFrameDisplayed(); | 23 | render_window.OnFrameDisplayed(); |
| 23 | } | 24 | } |
| 24 | 25 | ||
| 26 | std::vector<u8> RendererNull::GetAppletCaptureBuffer() { | ||
| 27 | return std::vector<u8>(VideoCore::Capture::TiledSize); | ||
| 28 | } | ||
| 29 | |||
| 25 | } // namespace Null | 30 | } // 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: | |||
| 19 | 19 | ||
| 20 | void Composite(std::span<const Tegra::FramebufferConfig> framebuffer) override; | 20 | void Composite(std::span<const Tegra::FramebufferConfig> framebuffer) override; |
| 21 | 21 | ||
| 22 | std::vector<u8> GetAppletCaptureBuffer() override; | ||
| 23 | |||
| 22 | VideoCore::RasterizerInterface* ReadRasterizer() override { | 24 | VideoCore::RasterizerInterface* ReadRasterizer() override { |
| 23 | return &m_rasterizer; | 25 | return &m_rasterizer; |
| 24 | } | 26 | } |
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_, | |||
| 20 | BlitScreen::~BlitScreen() = default; | 20 | BlitScreen::~BlitScreen() = default; |
| 21 | 21 | ||
| 22 | void BlitScreen::DrawScreen(std::span<const Tegra::FramebufferConfig> framebuffers, | 22 | void BlitScreen::DrawScreen(std::span<const Tegra::FramebufferConfig> framebuffers, |
| 23 | const Layout::FramebufferLayout& layout) { | 23 | const Layout::FramebufferLayout& layout, bool invert_y) { |
| 24 | // TODO: Signal state tracker about these changes | 24 | // TODO: Signal state tracker about these changes |
| 25 | state_tracker.NotifyScreenDrawVertexArray(); | 25 | state_tracker.NotifyScreenDrawVertexArray(); |
| 26 | state_tracker.NotifyPolygonModes(); | 26 | state_tracker.NotifyPolygonModes(); |
| @@ -60,7 +60,7 @@ void BlitScreen::DrawScreen(std::span<const Tegra::FramebufferConfig> framebuffe | |||
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | CreateWindowAdapt(); | 62 | CreateWindowAdapt(); |
| 63 | window_adapt->DrawToFramebuffer(program_manager, layers, framebuffers, layout); | 63 | window_adapt->DrawToFramebuffer(program_manager, layers, framebuffers, layout, invert_y); |
| 64 | 64 | ||
| 65 | // TODO | 65 | // TODO |
| 66 | // program_manager.RestoreGuestPipeline(); | 66 | // 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: | |||
| 51 | 51 | ||
| 52 | /// Draws the emulated screens to the emulator window. | 52 | /// Draws the emulated screens to the emulator window. |
| 53 | void DrawScreen(std::span<const Tegra::FramebufferConfig> framebuffers, | 53 | void DrawScreen(std::span<const Tegra::FramebufferConfig> framebuffers, |
| 54 | const Layout::FramebufferLayout& layout); | 54 | const Layout::FramebufferLayout& layout, bool invert_y); |
| 55 | 55 | ||
| 56 | private: | 56 | private: |
| 57 | void CreateWindowAdapt(); | 57 | 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<GLfloat, 3 * 2>& out_matrix, | |||
| 34 | std::array<ScreenRectVertex, 4>& out_vertices, | 34 | std::array<ScreenRectVertex, 4>& out_vertices, |
| 35 | ProgramManager& program_manager, | 35 | ProgramManager& program_manager, |
| 36 | const Tegra::FramebufferConfig& framebuffer, | 36 | const Tegra::FramebufferConfig& framebuffer, |
| 37 | const Layout::FramebufferLayout& layout) { | 37 | const Layout::FramebufferLayout& layout, bool invert_y) { |
| 38 | FramebufferTextureInfo info = PrepareRenderTarget(framebuffer); | 38 | FramebufferTextureInfo info = PrepareRenderTarget(framebuffer); |
| 39 | auto crop = Tegra::NormalizeCrop(framebuffer, info.width, info.height); | 39 | auto crop = Tegra::NormalizeCrop(framebuffer, info.width, info.height); |
| 40 | GLuint texture = info.display_texture; | 40 | GLuint texture = info.display_texture; |
| @@ -83,10 +83,15 @@ GLuint Layer::ConfigureDraw(std::array<GLfloat, 3 * 2>& out_matrix, | |||
| 83 | const auto w = screen.GetWidth(); | 83 | const auto w = screen.GetWidth(); |
| 84 | const auto h = screen.GetHeight(); | 84 | const auto h = screen.GetHeight(); |
| 85 | 85 | ||
| 86 | out_vertices[0] = ScreenRectVertex(x, y, crop.left, crop.top); | 86 | const auto left = crop.left; |
| 87 | out_vertices[1] = ScreenRectVertex(x + w, y, crop.right, crop.top); | 87 | const auto right = crop.right; |
| 88 | out_vertices[2] = ScreenRectVertex(x, y + h, crop.left, crop.bottom); | 88 | const auto top = invert_y ? crop.bottom : crop.top; |
| 89 | out_vertices[3] = ScreenRectVertex(x + w, y + h, crop.right, crop.bottom); | 89 | const auto bottom = invert_y ? crop.top : crop.bottom; |
| 90 | |||
| 91 | out_vertices[0] = ScreenRectVertex(x, y, left, top); | ||
| 92 | out_vertices[1] = ScreenRectVertex(x + w, y, right, top); | ||
| 93 | out_vertices[2] = ScreenRectVertex(x, y + h, left, bottom); | ||
| 94 | out_vertices[3] = ScreenRectVertex(x + w, y + h, right, bottom); | ||
| 90 | 95 | ||
| 91 | return texture; | 96 | return texture; |
| 92 | } | 97 | } |
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: | |||
| 51 | std::array<ScreenRectVertex, 4>& out_vertices, | 51 | std::array<ScreenRectVertex, 4>& out_vertices, |
| 52 | ProgramManager& program_manager, | 52 | ProgramManager& program_manager, |
| 53 | const Tegra::FramebufferConfig& framebuffer, | 53 | const Tegra::FramebufferConfig& framebuffer, |
| 54 | const Layout::FramebufferLayout& layout); | 54 | const Layout::FramebufferLayout& layout, bool invert_y); |
| 55 | 55 | ||
| 56 | private: | 56 | private: |
| 57 | /// Loads framebuffer from emulated memory into the active OpenGL texture. | 57 | /// 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; | |||
| 37 | 37 | ||
| 38 | void WindowAdaptPass::DrawToFramebuffer(ProgramManager& program_manager, std::list<Layer>& layers, | 38 | void WindowAdaptPass::DrawToFramebuffer(ProgramManager& program_manager, std::list<Layer>& layers, |
| 39 | std::span<const Tegra::FramebufferConfig> framebuffers, | 39 | std::span<const Tegra::FramebufferConfig> framebuffers, |
| 40 | const Layout::FramebufferLayout& layout) { | 40 | const Layout::FramebufferLayout& layout, bool invert_y) { |
| 41 | GLint old_read_fb; | 41 | GLint old_read_fb; |
| 42 | GLint old_draw_fb; | 42 | GLint old_draw_fb; |
| 43 | glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb); | 43 | glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb); |
| @@ -51,7 +51,7 @@ void WindowAdaptPass::DrawToFramebuffer(ProgramManager& program_manager, std::li | |||
| 51 | auto layer_it = layers.begin(); | 51 | auto layer_it = layers.begin(); |
| 52 | for (size_t i = 0; i < layer_count; i++) { | 52 | for (size_t i = 0; i < layer_count; i++) { |
| 53 | textures[i] = layer_it->ConfigureDraw(matrices[i], vertices[i], program_manager, | 53 | textures[i] = layer_it->ConfigureDraw(matrices[i], vertices[i], program_manager, |
| 54 | framebuffers[i], layout); | 54 | framebuffers[i], layout, invert_y); |
| 55 | layer_it++; | 55 | layer_it++; |
| 56 | } | 56 | } |
| 57 | 57 | ||
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: | |||
| 31 | 31 | ||
| 32 | void DrawToFramebuffer(ProgramManager& program_manager, std::list<Layer>& layers, | 32 | void DrawToFramebuffer(ProgramManager& program_manager, std::list<Layer>& layers, |
| 33 | std::span<const Tegra::FramebufferConfig> framebuffers, | 33 | std::span<const Tegra::FramebufferConfig> framebuffers, |
| 34 | const Layout::FramebufferLayout& layout); | 34 | const Layout::FramebufferLayout& layout, bool invert_y); |
| 35 | 35 | ||
| 36 | private: | 36 | private: |
| 37 | const Device& device; | 37 | 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 @@ | |||
| 16 | #include "core/core_timing.h" | 16 | #include "core/core_timing.h" |
| 17 | #include "core/frontend/emu_window.h" | 17 | #include "core/frontend/emu_window.h" |
| 18 | #include "core/telemetry_session.h" | 18 | #include "core/telemetry_session.h" |
| 19 | #include "video_core/capture.h" | ||
| 19 | #include "video_core/renderer_opengl/gl_blit_screen.h" | 20 | #include "video_core/renderer_opengl/gl_blit_screen.h" |
| 20 | #include "video_core/renderer_opengl/gl_rasterizer.h" | 21 | #include "video_core/renderer_opengl/gl_rasterizer.h" |
| 21 | #include "video_core/renderer_opengl/gl_shader_manager.h" | 22 | #include "video_core/renderer_opengl/gl_shader_manager.h" |
| @@ -121,6 +122,13 @@ RendererOpenGL::RendererOpenGL(Core::TelemetrySession& telemetry_session_, | |||
| 121 | } | 122 | } |
| 122 | blit_screen = std::make_unique<BlitScreen>(rasterizer, device_memory, state_tracker, | 123 | blit_screen = std::make_unique<BlitScreen>(rasterizer, device_memory, state_tracker, |
| 123 | program_manager, device); | 124 | program_manager, device); |
| 125 | blit_applet = std::make_unique<BlitScreen>(rasterizer, device_memory, state_tracker, | ||
| 126 | program_manager, device); | ||
| 127 | capture_framebuffer.Create(); | ||
| 128 | capture_renderbuffer.Create(); | ||
| 129 | glBindRenderbuffer(GL_RENDERBUFFER, capture_renderbuffer.handle); | ||
| 130 | glRenderbufferStorage(GL_RENDERBUFFER, GL_SRGB8, VideoCore::Capture::LinearWidth, | ||
| 131 | VideoCore::Capture::LinearHeight); | ||
| 124 | } | 132 | } |
| 125 | 133 | ||
| 126 | RendererOpenGL::~RendererOpenGL() = default; | 134 | RendererOpenGL::~RendererOpenGL() = default; |
| @@ -130,10 +138,11 @@ void RendererOpenGL::Composite(std::span<const Tegra::FramebufferConfig> framebu | |||
| 130 | return; | 138 | return; |
| 131 | } | 139 | } |
| 132 | 140 | ||
| 141 | RenderAppletCaptureLayer(framebuffers); | ||
| 133 | RenderScreenshot(framebuffers); | 142 | RenderScreenshot(framebuffers); |
| 134 | 143 | ||
| 135 | state_tracker.BindFramebuffer(0); | 144 | state_tracker.BindFramebuffer(0); |
| 136 | blit_screen->DrawScreen(framebuffers, emu_window.GetFramebufferLayout()); | 145 | blit_screen->DrawScreen(framebuffers, emu_window.GetFramebufferLayout(), false); |
| 137 | 146 | ||
| 138 | ++m_current_frame; | 147 | ++m_current_frame; |
| 139 | 148 | ||
| @@ -159,11 +168,8 @@ void RendererOpenGL::AddTelemetryFields() { | |||
| 159 | telemetry_session.AddField(user_system, "GPU_OpenGL_Version", std::string(gl_version)); | 168 | telemetry_session.AddField(user_system, "GPU_OpenGL_Version", std::string(gl_version)); |
| 160 | } | 169 | } |
| 161 | 170 | ||
| 162 | void RendererOpenGL::RenderScreenshot(std::span<const Tegra::FramebufferConfig> framebuffers) { | 171 | void RendererOpenGL::RenderToBuffer(std::span<const Tegra::FramebufferConfig> framebuffers, |
| 163 | if (!renderer_settings.screenshot_requested) { | 172 | const Layout::FramebufferLayout& layout, void* dst) { |
| 164 | return; | ||
| 165 | } | ||
| 166 | |||
| 167 | GLint old_read_fb; | 173 | GLint old_read_fb; |
| 168 | GLint old_draw_fb; | 174 | GLint old_draw_fb; |
| 169 | glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb); | 175 | glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb); |
| @@ -173,29 +179,86 @@ void RendererOpenGL::RenderScreenshot(std::span<const Tegra::FramebufferConfig> | |||
| 173 | screenshot_framebuffer.Create(); | 179 | screenshot_framebuffer.Create(); |
| 174 | glBindFramebuffer(GL_FRAMEBUFFER, screenshot_framebuffer.handle); | 180 | glBindFramebuffer(GL_FRAMEBUFFER, screenshot_framebuffer.handle); |
| 175 | 181 | ||
| 176 | const Layout::FramebufferLayout layout{renderer_settings.screenshot_framebuffer_layout}; | ||
| 177 | |||
| 178 | GLuint renderbuffer; | 182 | GLuint renderbuffer; |
| 179 | glGenRenderbuffers(1, &renderbuffer); | 183 | glGenRenderbuffers(1, &renderbuffer); |
| 180 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); | 184 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); |
| 181 | glRenderbufferStorage(GL_RENDERBUFFER, GL_SRGB8, layout.width, layout.height); | 185 | glRenderbufferStorage(GL_RENDERBUFFER, GL_SRGB8, layout.width, layout.height); |
| 182 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer); | 186 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer); |
| 183 | 187 | ||
| 184 | blit_screen->DrawScreen(framebuffers, layout); | 188 | blit_screen->DrawScreen(framebuffers, layout, false); |
| 185 | 189 | ||
| 186 | glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | 190 | glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); |
| 187 | glPixelStorei(GL_PACK_ROW_LENGTH, 0); | 191 | glPixelStorei(GL_PACK_ROW_LENGTH, 0); |
| 188 | glReadPixels(0, 0, layout.width, layout.height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, | 192 | glReadPixels(0, 0, layout.width, layout.height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, dst); |
| 189 | renderer_settings.screenshot_bits); | ||
| 190 | 193 | ||
| 191 | screenshot_framebuffer.Release(); | 194 | screenshot_framebuffer.Release(); |
| 192 | glDeleteRenderbuffers(1, &renderbuffer); | 195 | glDeleteRenderbuffers(1, &renderbuffer); |
| 193 | 196 | ||
| 194 | glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read_fb); | 197 | glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read_fb); |
| 195 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb); | 198 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb); |
| 199 | } | ||
| 200 | |||
| 201 | void RendererOpenGL::RenderScreenshot(std::span<const Tegra::FramebufferConfig> framebuffers) { | ||
| 202 | if (!renderer_settings.screenshot_requested) { | ||
| 203 | return; | ||
| 204 | } | ||
| 205 | |||
| 206 | RenderToBuffer(framebuffers, renderer_settings.screenshot_framebuffer_layout, | ||
| 207 | renderer_settings.screenshot_bits); | ||
| 196 | 208 | ||
| 197 | renderer_settings.screenshot_complete_callback(true); | 209 | renderer_settings.screenshot_complete_callback(true); |
| 198 | renderer_settings.screenshot_requested = false; | 210 | renderer_settings.screenshot_requested = false; |
| 199 | } | 211 | } |
| 200 | 212 | ||
| 213 | void RendererOpenGL::RenderAppletCaptureLayer( | ||
| 214 | std::span<const Tegra::FramebufferConfig> framebuffers) { | ||
| 215 | GLint old_read_fb; | ||
| 216 | GLint old_draw_fb; | ||
| 217 | glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb); | ||
| 218 | glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &old_draw_fb); | ||
| 219 | |||
| 220 | glBindFramebuffer(GL_FRAMEBUFFER, capture_framebuffer.handle); | ||
| 221 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, | ||
| 222 | capture_renderbuffer.handle); | ||
| 223 | |||
| 224 | blit_applet->DrawScreen(framebuffers, VideoCore::Capture::Layout, true); | ||
| 225 | |||
| 226 | glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read_fb); | ||
| 227 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb); | ||
| 228 | } | ||
| 229 | |||
| 230 | std::vector<u8> RendererOpenGL::GetAppletCaptureBuffer() { | ||
| 231 | using namespace VideoCore::Capture; | ||
| 232 | |||
| 233 | std::vector<u8> linear(TiledSize); | ||
| 234 | std::vector<u8> out(TiledSize); | ||
| 235 | |||
| 236 | GLint old_read_fb; | ||
| 237 | GLint old_draw_fb; | ||
| 238 | GLint old_pixel_pack_buffer; | ||
| 239 | GLint old_pack_row_length; | ||
| 240 | glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb); | ||
| 241 | glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &old_draw_fb); | ||
| 242 | glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &old_pixel_pack_buffer); | ||
| 243 | glGetIntegerv(GL_PACK_ROW_LENGTH, &old_pack_row_length); | ||
| 244 | |||
| 245 | glBindFramebuffer(GL_FRAMEBUFFER, capture_framebuffer.handle); | ||
| 246 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, | ||
| 247 | capture_renderbuffer.handle); | ||
| 248 | glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | ||
| 249 | glPixelStorei(GL_PACK_ROW_LENGTH, 0); | ||
| 250 | glReadPixels(0, 0, LinearWidth, LinearHeight, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, | ||
| 251 | linear.data()); | ||
| 252 | |||
| 253 | glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read_fb); | ||
| 254 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb); | ||
| 255 | glBindBuffer(GL_PIXEL_PACK_BUFFER, old_pixel_pack_buffer); | ||
| 256 | glPixelStorei(GL_PACK_ROW_LENGTH, old_pack_row_length); | ||
| 257 | |||
| 258 | Tegra::Texture::SwizzleTexture(out, linear, BytesPerPixel, LinearWidth, LinearHeight, | ||
| 259 | LinearDepth, BlockHeight, BlockDepth); | ||
| 260 | |||
| 261 | return out; | ||
| 262 | } | ||
| 263 | |||
| 201 | } // namespace OpenGL | 264 | } // 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: | |||
| 42 | 42 | ||
| 43 | void Composite(std::span<const Tegra::FramebufferConfig> framebuffers) override; | 43 | void Composite(std::span<const Tegra::FramebufferConfig> framebuffers) override; |
| 44 | 44 | ||
| 45 | std::vector<u8> GetAppletCaptureBuffer() override; | ||
| 46 | |||
| 45 | VideoCore::RasterizerInterface* ReadRasterizer() override { | 47 | VideoCore::RasterizerInterface* ReadRasterizer() override { |
| 46 | return &rasterizer; | 48 | return &rasterizer; |
| 47 | } | 49 | } |
| @@ -52,7 +54,11 @@ public: | |||
| 52 | 54 | ||
| 53 | private: | 55 | private: |
| 54 | void AddTelemetryFields(); | 56 | void AddTelemetryFields(); |
| 57 | |||
| 58 | void RenderToBuffer(std::span<const Tegra::FramebufferConfig> framebuffers, | ||
| 59 | const Layout::FramebufferLayout& layout, void* dst); | ||
| 55 | void RenderScreenshot(std::span<const Tegra::FramebufferConfig> framebuffers); | 60 | void RenderScreenshot(std::span<const Tegra::FramebufferConfig> framebuffers); |
| 61 | void RenderAppletCaptureLayer(std::span<const Tegra::FramebufferConfig> framebuffers); | ||
| 56 | 62 | ||
| 57 | Core::TelemetrySession& telemetry_session; | 63 | Core::TelemetrySession& telemetry_session; |
| 58 | Core::Frontend::EmuWindow& emu_window; | 64 | Core::Frontend::EmuWindow& emu_window; |
| @@ -64,8 +70,11 @@ private: | |||
| 64 | ProgramManager program_manager; | 70 | ProgramManager program_manager; |
| 65 | RasterizerOpenGL rasterizer; | 71 | RasterizerOpenGL rasterizer; |
| 66 | OGLFramebuffer screenshot_framebuffer; | 72 | OGLFramebuffer screenshot_framebuffer; |
| 73 | OGLFramebuffer capture_framebuffer; | ||
| 74 | OGLRenderbuffer capture_renderbuffer; | ||
| 67 | 75 | ||
| 68 | std::unique_ptr<BlitScreen> blit_screen; | 76 | std::unique_ptr<BlitScreen> blit_screen; |
| 77 | std::unique_ptr<BlitScreen> blit_applet; | ||
| 69 | }; | 78 | }; |
| 70 | 79 | ||
| 71 | } // namespace OpenGL | 80 | } // 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 @@ | |||
| 19 | #include "core/core_timing.h" | 19 | #include "core/core_timing.h" |
| 20 | #include "core/frontend/graphics_context.h" | 20 | #include "core/frontend/graphics_context.h" |
| 21 | #include "core/telemetry_session.h" | 21 | #include "core/telemetry_session.h" |
| 22 | #include "video_core/capture.h" | ||
| 22 | #include "video_core/gpu.h" | 23 | #include "video_core/gpu.h" |
| 23 | #include "video_core/renderer_vulkan/present/util.h" | 24 | #include "video_core/renderer_vulkan/present/util.h" |
| 24 | #include "video_core/renderer_vulkan/renderer_vulkan.h" | 25 | #include "video_core/renderer_vulkan/renderer_vulkan.h" |
| @@ -38,6 +39,20 @@ | |||
| 38 | 39 | ||
| 39 | namespace Vulkan { | 40 | namespace Vulkan { |
| 40 | namespace { | 41 | namespace { |
| 42 | |||
| 43 | constexpr VkExtent2D CaptureImageSize{ | ||
| 44 | .width = VideoCore::Capture::LinearWidth, | ||
| 45 | .height = VideoCore::Capture::LinearHeight, | ||
| 46 | }; | ||
| 47 | |||
| 48 | constexpr VkExtent3D CaptureImageExtent{ | ||
| 49 | .width = VideoCore::Capture::LinearWidth, | ||
| 50 | .height = VideoCore::Capture::LinearHeight, | ||
| 51 | .depth = VideoCore::Capture::LinearDepth, | ||
| 52 | }; | ||
| 53 | |||
| 54 | constexpr VkFormat CaptureFormat = VK_FORMAT_A8B8G8R8_UNORM_PACK32; | ||
| 55 | |||
| 41 | std::string GetReadableVersion(u32 version) { | 56 | std::string GetReadableVersion(u32 version) { |
| 42 | return fmt::format("{}.{}.{}", VK_VERSION_MAJOR(version), VK_VERSION_MINOR(version), | 57 | return fmt::format("{}.{}.{}", VK_VERSION_MAJOR(version), VK_VERSION_MINOR(version), |
| 43 | VK_VERSION_PATCH(version)); | 58 | VK_VERSION_PATCH(version)); |
| @@ -100,11 +115,11 @@ RendererVulkan::RendererVulkan(Core::TelemetrySession& telemetry_session_, | |||
| 100 | present_manager(instance, render_window, device, memory_allocator, scheduler, swapchain, | 115 | present_manager(instance, render_window, device, memory_allocator, scheduler, swapchain, |
| 101 | surface), | 116 | surface), |
| 102 | blit_swapchain(device_memory, device, memory_allocator, present_manager, scheduler), | 117 | blit_swapchain(device_memory, device, memory_allocator, present_manager, scheduler), |
| 103 | blit_screenshot(device_memory, device, memory_allocator, present_manager, scheduler), | 118 | blit_capture(device_memory, device, memory_allocator, present_manager, scheduler), |
| 104 | blit_application_layer(device_memory, device, memory_allocator, present_manager, scheduler), | 119 | blit_applet(device_memory, device, memory_allocator, present_manager, scheduler), |
| 105 | rasterizer(render_window, gpu, device_memory, device, memory_allocator, state_tracker, | 120 | rasterizer(render_window, gpu, device_memory, device, memory_allocator, state_tracker, |
| 106 | scheduler), | 121 | scheduler), |
| 107 | application_frame() { | 122 | applet_frame() { |
| 108 | if (Settings::values.renderer_force_max_clock.GetValue() && device.ShouldBoostClocks()) { | 123 | if (Settings::values.renderer_force_max_clock.GetValue() && device.ShouldBoostClocks()) { |
| 109 | turbo_mode.emplace(instance, dld); | 124 | turbo_mode.emplace(instance, dld); |
| 110 | scheduler.RegisterOnSubmit([this] { turbo_mode->QueueSubmitted(); }); | 125 | scheduler.RegisterOnSubmit([this] { turbo_mode->QueueSubmitted(); }); |
| @@ -127,6 +142,8 @@ void RendererVulkan::Composite(std::span<const Tegra::FramebufferConfig> framebu | |||
| 127 | 142 | ||
| 128 | SCOPE_EXIT({ render_window.OnFrameDisplayed(); }); | 143 | SCOPE_EXIT({ render_window.OnFrameDisplayed(); }); |
| 129 | 144 | ||
| 145 | RenderAppletCaptureLayer(framebuffers); | ||
| 146 | |||
| 130 | if (!render_window.IsShown()) { | 147 | if (!render_window.IsShown()) { |
| 131 | return; | 148 | return; |
| 132 | } | 149 | } |
| @@ -169,30 +186,20 @@ void RendererVulkan::Report() const { | |||
| 169 | telemetry_session.AddField(field, "GPU_Vulkan_Extensions", extensions); | 186 | telemetry_session.AddField(field, "GPU_Vulkan_Extensions", extensions); |
| 170 | } | 187 | } |
| 171 | 188 | ||
| 172 | void Vulkan::RendererVulkan::RenderScreenshot( | 189 | vk::Buffer RendererVulkan::RenderToBuffer(std::span<const Tegra::FramebufferConfig> framebuffers, |
| 173 | std::span<const Tegra::FramebufferConfig> framebuffers) { | 190 | const Layout::FramebufferLayout& layout, VkFormat format, |
| 174 | if (!renderer_settings.screenshot_requested) { | 191 | VkDeviceSize buffer_size) { |
| 175 | return; | ||
| 176 | } | ||
| 177 | |||
| 178 | constexpr VkFormat ScreenshotFormat{VK_FORMAT_B8G8R8A8_UNORM}; | ||
| 179 | const Layout::FramebufferLayout layout{renderer_settings.screenshot_framebuffer_layout}; | ||
| 180 | |||
| 181 | auto frame = [&]() { | 192 | auto frame = [&]() { |
| 182 | Frame f{}; | 193 | Frame f{}; |
| 183 | f.image = CreateWrappedImage(memory_allocator, VkExtent2D{layout.width, layout.height}, | 194 | f.image = |
| 184 | ScreenshotFormat); | 195 | CreateWrappedImage(memory_allocator, VkExtent2D{layout.width, layout.height}, format); |
| 185 | f.image_view = CreateWrappedImageView(device, f.image, ScreenshotFormat); | 196 | f.image_view = CreateWrappedImageView(device, f.image, format); |
| 186 | f.framebuffer = blit_screenshot.CreateFramebuffer(layout, *f.image_view, ScreenshotFormat); | 197 | f.framebuffer = blit_capture.CreateFramebuffer(layout, *f.image_view, format); |
| 187 | return f; | 198 | return f; |
| 188 | }(); | 199 | }(); |
| 189 | 200 | ||
| 190 | blit_screenshot.DrawToFrame(rasterizer, &frame, framebuffers, layout, 1, | 201 | auto dst_buffer = CreateWrappedBuffer(memory_allocator, buffer_size, MemoryUsage::Download); |
| 191 | VK_FORMAT_B8G8R8A8_UNORM); | 202 | blit_capture.DrawToFrame(rasterizer, &frame, framebuffers, layout, 1, format); |
| 192 | |||
| 193 | const auto dst_buffer = CreateWrappedBuffer( | ||
| 194 | memory_allocator, static_cast<VkDeviceSize>(layout.width * layout.height * 4), | ||
| 195 | MemoryUsage::Download); | ||
| 196 | 203 | ||
| 197 | scheduler.RequestOutsideRenderPassOperationContext(); | 204 | scheduler.RequestOutsideRenderPassOperationContext(); |
| 198 | scheduler.Record([&](vk::CommandBuffer cmdbuf) { | 205 | scheduler.Record([&](vk::CommandBuffer cmdbuf) { |
| @@ -200,15 +207,68 @@ void Vulkan::RendererVulkan::RenderScreenshot( | |||
| 200 | VkExtent3D{layout.width, layout.height, 1}); | 207 | VkExtent3D{layout.width, layout.height, 1}); |
| 201 | }); | 208 | }); |
| 202 | 209 | ||
| 203 | // Ensure the copy is fully completed before saving the screenshot | 210 | // Ensure the copy is fully completed before saving the capture |
| 204 | scheduler.Finish(); | 211 | scheduler.Finish(); |
| 205 | 212 | ||
| 206 | // Copy backing image data to the QImage screenshot buffer | 213 | // Copy backing image data to the capture buffer |
| 207 | dst_buffer.Invalidate(); | 214 | dst_buffer.Invalidate(); |
| 215 | return dst_buffer; | ||
| 216 | } | ||
| 217 | |||
| 218 | void RendererVulkan::RenderScreenshot(std::span<const Tegra::FramebufferConfig> framebuffers) { | ||
| 219 | if (!renderer_settings.screenshot_requested) { | ||
| 220 | return; | ||
| 221 | } | ||
| 222 | |||
| 223 | const auto& layout{renderer_settings.screenshot_framebuffer_layout}; | ||
| 224 | const auto dst_buffer = RenderToBuffer(framebuffers, layout, VK_FORMAT_B8G8R8A8_UNORM, | ||
| 225 | layout.width * layout.height * 4); | ||
| 226 | |||
| 208 | std::memcpy(renderer_settings.screenshot_bits, dst_buffer.Mapped().data(), | 227 | std::memcpy(renderer_settings.screenshot_bits, dst_buffer.Mapped().data(), |
| 209 | dst_buffer.Mapped().size()); | 228 | dst_buffer.Mapped().size()); |
| 210 | renderer_settings.screenshot_complete_callback(false); | 229 | renderer_settings.screenshot_complete_callback(false); |
| 211 | renderer_settings.screenshot_requested = false; | 230 | renderer_settings.screenshot_requested = false; |
| 212 | } | 231 | } |
| 213 | 232 | ||
| 233 | std::vector<u8> RendererVulkan::GetAppletCaptureBuffer() { | ||
| 234 | using namespace VideoCore::Capture; | ||
| 235 | |||
| 236 | std::vector<u8> out(VideoCore::Capture::TiledSize); | ||
| 237 | |||
| 238 | if (!applet_frame.image) { | ||
| 239 | return out; | ||
| 240 | } | ||
| 241 | |||
| 242 | const auto dst_buffer = | ||
| 243 | CreateWrappedBuffer(memory_allocator, VideoCore::Capture::TiledSize, MemoryUsage::Download); | ||
| 244 | |||
| 245 | scheduler.RequestOutsideRenderPassOperationContext(); | ||
| 246 | scheduler.Record([&](vk::CommandBuffer cmdbuf) { | ||
| 247 | DownloadColorImage(cmdbuf, *applet_frame.image, *dst_buffer, CaptureImageExtent); | ||
| 248 | }); | ||
| 249 | |||
| 250 | // Ensure the copy is fully completed before writing the capture | ||
| 251 | scheduler.Finish(); | ||
| 252 | |||
| 253 | // Swizzle image data to the capture buffer | ||
| 254 | dst_buffer.Invalidate(); | ||
| 255 | Tegra::Texture::SwizzleTexture(out, dst_buffer.Mapped(), BytesPerPixel, LinearWidth, | ||
| 256 | LinearHeight, LinearDepth, BlockHeight, BlockDepth); | ||
| 257 | |||
| 258 | return out; | ||
| 259 | } | ||
| 260 | |||
| 261 | void RendererVulkan::RenderAppletCaptureLayer( | ||
| 262 | std::span<const Tegra::FramebufferConfig> framebuffers) { | ||
| 263 | if (!applet_frame.image) { | ||
| 264 | applet_frame.image = CreateWrappedImage(memory_allocator, CaptureImageSize, CaptureFormat); | ||
| 265 | applet_frame.image_view = CreateWrappedImageView(device, applet_frame.image, CaptureFormat); | ||
| 266 | applet_frame.framebuffer = blit_applet.CreateFramebuffer( | ||
| 267 | VideoCore::Capture::Layout, *applet_frame.image_view, CaptureFormat); | ||
| 268 | } | ||
| 269 | |||
| 270 | blit_applet.DrawToFrame(rasterizer, &applet_frame, framebuffers, VideoCore::Capture::Layout, 1, | ||
| 271 | CaptureFormat); | ||
| 272 | } | ||
| 273 | |||
| 214 | } // namespace Vulkan | 274 | } // 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: | |||
| 48 | 48 | ||
| 49 | void Composite(std::span<const Tegra::FramebufferConfig> framebuffers) override; | 49 | void Composite(std::span<const Tegra::FramebufferConfig> framebuffers) override; |
| 50 | 50 | ||
| 51 | std::vector<u8> GetAppletCaptureBuffer() override; | ||
| 52 | |||
| 51 | VideoCore::RasterizerInterface* ReadRasterizer() override { | 53 | VideoCore::RasterizerInterface* ReadRasterizer() override { |
| 52 | return &rasterizer; | 54 | return &rasterizer; |
| 53 | } | 55 | } |
| @@ -59,7 +61,11 @@ public: | |||
| 59 | private: | 61 | private: |
| 60 | void Report() const; | 62 | void Report() const; |
| 61 | 63 | ||
| 64 | vk::Buffer RenderToBuffer(std::span<const Tegra::FramebufferConfig> framebuffers, | ||
| 65 | const Layout::FramebufferLayout& layout, VkFormat format, | ||
| 66 | VkDeviceSize buffer_size); | ||
| 62 | void RenderScreenshot(std::span<const Tegra::FramebufferConfig> framebuffers); | 67 | void RenderScreenshot(std::span<const Tegra::FramebufferConfig> framebuffers); |
| 68 | void RenderAppletCaptureLayer(std::span<const Tegra::FramebufferConfig> framebuffers); | ||
| 63 | 69 | ||
| 64 | Core::TelemetrySession& telemetry_session; | 70 | Core::TelemetrySession& telemetry_session; |
| 65 | Tegra::MaxwellDeviceMemoryManager& device_memory; | 71 | Tegra::MaxwellDeviceMemoryManager& device_memory; |
| @@ -79,12 +85,12 @@ private: | |||
| 79 | Swapchain swapchain; | 85 | Swapchain swapchain; |
| 80 | PresentManager present_manager; | 86 | PresentManager present_manager; |
| 81 | BlitScreen blit_swapchain; | 87 | BlitScreen blit_swapchain; |
| 82 | BlitScreen blit_screenshot; | 88 | BlitScreen blit_capture; |
| 83 | BlitScreen blit_application_layer; | 89 | BlitScreen blit_applet; |
| 84 | RasterizerVulkan rasterizer; | 90 | RasterizerVulkan rasterizer; |
| 85 | std::optional<TurboMode> turbo_mode; | 91 | std::optional<TurboMode> turbo_mode; |
| 86 | 92 | ||
| 87 | Frame application_frame; | 93 | Frame applet_frame; |
| 88 | }; | 94 | }; |
| 89 | 95 | ||
| 90 | } // namespace Vulkan | 96 | } // namespace Vulkan |