mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-15 23:40:29 +02:00
The core and the headless tools no longer use mutexes, condition variables, spinlocks, std::atomic, std::thread or volatile flags. Threads hand off through libretro-common's retro_atomic and rthreads plus a few small pieces on top of them in Common/Thread: Thread, MpscQueue, EventCounter, ParkingLot waits and ReaderGate. Every wait blocks until it's woken; nothing polls on a timer. State that only one thread touches just loses its lock. The PSP filesystem, sceIo and the savedata dialog now belong to the emulation thread: async reads and writes run when they're queued and complete later in emulated time, and the IO and savedata threads are gone. The friend finder only talks to the adhoc server and hands what it gets to the emulation thread. GPU init always runs on the thread that starts the game. The Vulkan render and compile queues, pipeline and render pass caches, delete list and SPIR-V cache, the GL render queue, the software renderer's jit caches, the file loader caches, the web debugger, UPnP, input, savestates, logging and the GE debugger all hand off through queues and atomics. The IR jit's spinning profiler thread goes. A CPU thread with nothing to run now sleeps until work is queued instead of spinning. Headless with --debugger waits for a client while stopped, and ends the run once every client that connected has left. Web server shutdown keeps servicing the CPU queue until the server has finished.
76 lines
3.1 KiB
C++
76 lines
3.1 KiB
C++
#pragma once
|
|
|
|
#include <vector>
|
|
|
|
#include <retro_atomic.h>
|
|
|
|
// Must come before <libretro_vulkan.h>: this is what defines VK_USE_PLATFORM_WIN32_KHR (etc.) before
|
|
// the first inclusion of ext/vulkan/vulkan.h - since that header is include-guarded, whichever include
|
|
// reaches it first determines whether the platform-specific declarations (e.g.
|
|
// PFN_vkCreateWin32SurfaceKHR) exist for the rest of this translation unit.
|
|
#include "Common/GPU/Vulkan/VulkanPresentation.h"
|
|
|
|
#define VK_NO_PROTOTYPES
|
|
#include <libretro_vulkan.h>
|
|
|
|
// Implements VulkanContext's pluggable presentation backend (see VulkanPresentation.h) against
|
|
// libretro's retro_hw_render_interface_vulkan: instead of a real VK_KHR_swapchain (which doesn't exist in
|
|
// this model - RetroArch owns the real presentation surface itself), PPSSPP renders into its own rotating
|
|
// set of VkImages, sized to match RetroArch's sync index mask, and hands each finished frame back via
|
|
// set_image() rather than vkQueuePresentKHR.
|
|
class LibretroVulkanPresentation : public VulkanPresentation {
|
|
public:
|
|
// vulkan must remain valid for the lifetime of this object - it's owned by RetroArch, not us.
|
|
LibretroVulkanPresentation(retro_hw_render_interface_vulkan *vulkan, VkFormat format, VkExtent2D extent);
|
|
|
|
bool Create(VulkanContext *context);
|
|
void Destroy(VulkanContext *context) override;
|
|
bool NeedsRecreate() const override;
|
|
bool Recreate(VulkanContext *context) override;
|
|
|
|
VkResult AcquireNextImage(VulkanContext *vulkan, VkSemaphore signalSemaphore, uint32_t *imageIndex) override;
|
|
VkResult QueuePresent(VulkanContext *vulkan, VkQueue queue, uint32_t imageIndex, VkSemaphore waitSemaphore) override;
|
|
void BeginPresent() override;
|
|
void EndPresent() override;
|
|
|
|
uint32_t GetImageCount() const override { return (uint32_t)images_.size(); }
|
|
VkImage GetImage(uint32_t index) const override { return images_[index].image; }
|
|
VkExtent2D GetExtent() const override { return extent_; }
|
|
VkFormat GetFormat() const override { return format_; }
|
|
|
|
VkImageLayout GetPresentLayout() const override { return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; }
|
|
|
|
void LockQueue() override;
|
|
void UnlockQueue() override;
|
|
// RetroArch's shared VkQueue model doesn't let semaphores cross the frontend/core boundary
|
|
// meaningfully - strip them before the real vkQueueSubmit.
|
|
void PrepareSubmit(VkSubmitInfo &submitInfo) override;
|
|
|
|
// Called from LibretroVulkanContext::SwapBuffers(), mirroring the old free-function
|
|
// vk_libretro_wait_for_presentation().
|
|
void WaitForPresentation();
|
|
|
|
private:
|
|
struct Image {
|
|
VkImage image = VK_NULL_HANDLE;
|
|
VkDeviceMemory memory = VK_NULL_HANDLE;
|
|
retro_vulkan_image retroImage{};
|
|
};
|
|
|
|
retro_hw_render_interface_vulkan *vulkan_;
|
|
VkFormat format_;
|
|
VkExtent2D extent_;
|
|
bool dedicatedAllocation_ = false;
|
|
uint32_t syncIndexMask_ = 0;
|
|
|
|
std::vector<Image> images_;
|
|
|
|
// Set by BeginPresent on the emu thread, cleared by EndPresent on the render thread once
|
|
// set_image has been called. WaitForPresentation parks on it.
|
|
retro_atomic_int_t presentPending_{ 0 };
|
|
void SetPresentPending(bool pending);
|
|
|
|
static uint32_t ImageCountFromMask(uint32_t mask);
|
|
bool IsValidImageIndex(uint32_t imageIndex) const;
|
|
};
|