citra/src/video_core/renderer_opengl/frame_dumper_opengl.h
zhupengfei 06a0d86e9c
video_core, core: Move pixel download to its own thread
This uses the mailbox model to move pixel downloading to its own thread, eliminating Nvidia's warnings and (possibly) making use of GPU copy engine.

To achieve this, we created a new mailbox type that is different from the presentation mailbox in that it never discards a rendered frame.

Also, I tweaked the projection matrix thing so that it can just draw the frame upside down instead of having the CPU flip it.
2020-02-27 16:55:08 +08:00

58 lines
1.4 KiB
C++

// Copyright 2020 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <atomic>
#include <memory>
#include <thread>
#include "core/dumping/backend.h"
#include "core/frontend/framebuffer_layout.h"
#include "video_core/renderer_opengl/gl_resource_manager.h"
namespace Frontend {
class EmuWindow;
class GraphicsContext;
class TextureMailbox;
} // namespace Frontend
namespace OpenGL {
class RendererOpenGL;
/**
* This is the 'presentation' part in frame dumping.
* Processes frames/textures sent to its mailbox, downloads the pixels and sends the data
* to the video encoding backend.
*/
class FrameDumperOpenGL {
public:
explicit FrameDumperOpenGL(VideoDumper::Backend& video_dumper, Frontend::EmuWindow& emu_window);
~FrameDumperOpenGL();
bool IsDumping() const;
Layout::FramebufferLayout GetLayout() const;
void StartDumping();
void StopDumping();
std::unique_ptr<Frontend::TextureMailbox> mailbox;
private:
void InitializeOpenGLObjects();
void CleanupOpenGLObjects();
void PresentLoop();
VideoDumper::Backend& video_dumper;
std::unique_ptr<Frontend::GraphicsContext> context;
std::thread present_thread;
std::atomic_bool stop_requested{false};
// PBOs used to dump frames faster
std::array<OGLBuffer, 2> pbos;
GLuint current_pbo = 1;
GLuint next_pbo = 0;
};
} // namespace OpenGL