dfa2fd0e0d
* code: Prepare frontend for vulkan support * citra_qt: Add vulkan options to the GUI * vk_instance: Collect tooling info * renderer_vulkan: Add vulkan backend * qt: Fix fullscreen and resize issues on macOS. (#47) * qt: Fix bugged macOS full screen transition. * renderer/vulkan: Fix swapchain recreation destroying in-use semaphore. * renderer/vulkan: Make gl_Position invariant. (#48) This fixes an issue with black artifacts in Pokemon games on Apple GPUs. If the vertex calculations differ slightly between render passes, it can cause parts of model faces to fail depth test. * vk_renderpass_cache: Bump pixel format count * android: Custom driver code * vk_instance: Set moltenvk configuration * rasterizer_cache: Proper surface unregister * citra_qt: Fix invalid characters * vk_rasterizer: Correct special unbind * android: Allow async presentation toggle * vk_graphics_pipeline: Fix async shader compilation * We were actually waiting for the pipelines regardless of the setting, oops * vk_rasterizer: More robust attribute loading * android: Move PollEvents to OpenGL window * Vulkan does not need this and it causes problems * vk_instance: Enable robust buffer access * Improves stability on mali devices * vk_renderpass_cache: Bring back renderpass flushing * externals: Update vulkan-headers * gl_rasterizer: Separable shaders for everyone * vk_blit_helper: Corect depth to color convertion * renderer_vulkan: Implement reinterpretation with copy * Allows reinterpreteration with simply copy on AMD * vk_graphics_pipeline: Only fast compile if no shaders are pending * With this shaders weren't being compiled in parallel * vk_swapchain: Ensure vsync doesn't lock framerate * vk_present_window: Match guest swapchain size to vulkan image count * Less latency and fixes crashes that were caused by images being deleted before free * vk_instance: Blacklist VK_EXT_pipeline_creation_cache_control with nvidia gpus * Resolves crashes when async shader compilation is enabled * vk_rasterizer: Bump async threshold to 6 * Many games have fullscreen quads with 6 vertices. Fixes pokemon textures missing with async shaders * android: More robust surface recreation * renderer_vulkan: Fix dynamic state being lost * vk_pipeline_cache: Skip cache save when no pipeline cache exists * This is the cache when loading a save state * sdl: Fix surface initialization on macOS. (#49) * sdl: Fix surface initialization on macOS. * sdl: Fix render window events not being handled under Vulkan. * renderer/vulkan: Fix binding/unbinding of shadow rendering buffer. * vk_stream_buffer: Respect non coherent access alignment * Required by nvidia GPUs on MacOS * renderer/vulkan: Support VK_EXT_fragment_shader_interlock for shadow rendering. (#51) * renderer_vulkan: Port some recent shader fixes * vk_pipeline_cache: Improve shadow detection * vk_swapchain: Add missing check * renderer_vulkan: Fix hybrid screen * Revert "gl_rasterizer: Separable shaders for everyone" Causes crashes on mali GPUs, will need separate PR This reverts commit d22d556d30ff641b62dfece85738c96b7fbf7061. * renderer_vulkan: Fix flipped screenshot --------- Co-authored-by: Steveice10 <1269164+Steveice10@users.noreply.github.com>
213 lines
5.8 KiB
C++
213 lines
5.8 KiB
C++
// Copyright 2014 Citra Emulator Project
|
|
// Licensed under GPLv2 or any later version
|
|
// Refer to the license.txt file included.
|
|
|
|
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <condition_variable>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <QThread>
|
|
#include <QWidget>
|
|
#include "core/core.h"
|
|
#include "core/frontend/emu_window.h"
|
|
|
|
class QKeyEvent;
|
|
class QTouchEvent;
|
|
|
|
class GRenderWindow;
|
|
|
|
namespace Core {
|
|
class System;
|
|
}
|
|
|
|
namespace VideoCore {
|
|
enum class LoadCallbackStage;
|
|
}
|
|
|
|
class EmuThread final : public QThread {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit EmuThread(Core::System& system_, Frontend::GraphicsContext& context);
|
|
~EmuThread() override;
|
|
|
|
/**
|
|
* Start emulation (on new thread)
|
|
* @warning Only call when not running!
|
|
*/
|
|
void run() override;
|
|
|
|
/**
|
|
* Steps the emulation thread by a single CPU instruction (if the CPU is not already running)
|
|
* @note This function is thread-safe
|
|
*/
|
|
void ExecStep() {
|
|
exec_step = true;
|
|
running_cv.notify_all();
|
|
}
|
|
|
|
/**
|
|
* Sets whether the emulation thread is running or not
|
|
* @param running Boolean value, set the emulation thread to running if true
|
|
* @note This function is thread-safe
|
|
*/
|
|
void SetRunning(bool running) {
|
|
std::unique_lock lock{running_mutex};
|
|
this->running = running;
|
|
lock.unlock();
|
|
running_cv.notify_all();
|
|
}
|
|
|
|
/**
|
|
* Check if the emulation thread is running or not
|
|
* @return True if the emulation thread is running, otherwise false
|
|
* @note This function is thread-safe
|
|
*/
|
|
bool IsRunning() const {
|
|
return running;
|
|
}
|
|
|
|
/**
|
|
* Requests for the emulation thread to stop running
|
|
*/
|
|
void RequestStop() {
|
|
stop_run = true;
|
|
SetRunning(false);
|
|
};
|
|
|
|
private:
|
|
bool exec_step = false;
|
|
bool running = false;
|
|
std::atomic<bool> stop_run{false};
|
|
std::mutex running_mutex;
|
|
std::condition_variable running_cv;
|
|
|
|
Core::System& system;
|
|
Frontend::GraphicsContext& core_context;
|
|
|
|
signals:
|
|
/**
|
|
* Emitted when the CPU has halted execution
|
|
*
|
|
* @warning When connecting to this signal from other threads, make sure to specify either
|
|
* Qt::QueuedConnection (invoke slot within the destination object's message thread) or even
|
|
* Qt::BlockingQueuedConnection (additionally block source thread until slot returns)
|
|
*/
|
|
void DebugModeEntered();
|
|
|
|
/**
|
|
* Emitted right before the CPU continues execution
|
|
*
|
|
* @warning When connecting to this signal from other threads, make sure to specify either
|
|
* Qt::QueuedConnection (invoke slot within the destination object's message thread) or even
|
|
* Qt::BlockingQueuedConnection (additionally block source thread until slot returns)
|
|
*/
|
|
void DebugModeLeft();
|
|
|
|
void ErrorThrown(Core::System::ResultStatus, std::string);
|
|
|
|
void LoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total);
|
|
|
|
void HideLoadingScreen();
|
|
};
|
|
|
|
class GRenderWindow : public QWidget, public Frontend::EmuWindow {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
GRenderWindow(QWidget* parent, EmuThread* emu_thread, Core::System& system, bool is_secondary);
|
|
~GRenderWindow() override;
|
|
|
|
// EmuWindow implementation.
|
|
void MakeCurrent() override;
|
|
void DoneCurrent() override;
|
|
void PollEvents() override;
|
|
std::unique_ptr<Frontend::GraphicsContext> CreateSharedContext() const override;
|
|
|
|
void BackupGeometry();
|
|
void RestoreGeometry();
|
|
void restoreGeometry(const QByteArray& geometry); // overridden
|
|
QByteArray saveGeometry(); // overridden
|
|
|
|
qreal windowPixelRatio() const;
|
|
|
|
void closeEvent(QCloseEvent* event) override;
|
|
|
|
void resizeEvent(QResizeEvent* event) override;
|
|
|
|
void keyPressEvent(QKeyEvent* event) override;
|
|
void keyReleaseEvent(QKeyEvent* event) override;
|
|
|
|
void mousePressEvent(QMouseEvent* event) override;
|
|
void mouseMoveEvent(QMouseEvent* event) override;
|
|
void mouseReleaseEvent(QMouseEvent* event) override;
|
|
|
|
bool event(QEvent* event) override;
|
|
|
|
void focusOutEvent(QFocusEvent* event) override;
|
|
void focusInEvent(QFocusEvent* event) override;
|
|
bool HasFocus() const {
|
|
return has_focus;
|
|
}
|
|
|
|
bool InitRenderTarget();
|
|
|
|
/// Destroy the previous run's child_widget which should also destroy the child_window
|
|
void ReleaseRenderTarget();
|
|
|
|
void CaptureScreenshot(u32 res_scale, const QString& screenshot_path);
|
|
|
|
std::pair<u32, u32> ScaleTouch(const QPointF pos) const;
|
|
|
|
public slots:
|
|
|
|
void OnEmulationStarting(EmuThread* emu_thread);
|
|
void OnEmulationStopping();
|
|
void OnFramebufferSizeChanged();
|
|
|
|
signals:
|
|
/// Emitted when the window is closed
|
|
void Closed();
|
|
|
|
/**
|
|
* Emitted when the guest first calls SwapBuffers. This is used to hide the loading screen
|
|
*/
|
|
void FirstFrameDisplayed();
|
|
|
|
/// Emitted on mouse activity. Used to signal that the mouse should be shown if it's hidden
|
|
void MouseActivity();
|
|
|
|
private:
|
|
void TouchBeginEvent(const QTouchEvent* event);
|
|
void TouchUpdateEvent(const QTouchEvent* event);
|
|
void TouchEndEvent();
|
|
|
|
void OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) override;
|
|
|
|
bool InitializeOpenGL();
|
|
void InitializeVulkan();
|
|
void InitializeSoftware();
|
|
bool LoadOpenGL();
|
|
|
|
QWidget* child_widget = nullptr;
|
|
|
|
EmuThread* emu_thread;
|
|
Core::System& system;
|
|
|
|
/// Main context that will be shared with all other contexts that are requested.
|
|
/// If this is used in a shared context setting, then this should not be used directly, but
|
|
/// should instead be shared from
|
|
static std::unique_ptr<Frontend::GraphicsContext> main_context;
|
|
|
|
/// Temporary storage of the screenshot taken
|
|
QImage screenshot_image;
|
|
QByteArray geometry;
|
|
bool first_frame = false;
|
|
bool has_focus = false;
|
|
|
|
protected:
|
|
void showEvent(QShowEvent* event) override;
|
|
};
|