mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 10:56:58 +02:00
graphics: fix initialization
This commit is contained in:
@@ -1104,8 +1104,6 @@ static int RegisterBuffersInternal(VideoOutConfig& ctx, int set_id, int start_in
|
||||
if (set_id < 0 || set_id >= VIDEO_OUT_BUFFER_ATTRIBUTE_NUM_MAX) {
|
||||
EXIT("internal video-out buffer set identifier is out of range\n");
|
||||
}
|
||||
Graphics::WindowWaitForGraphicInitialized();
|
||||
Graphics::GraphicsRenderCreateContext();
|
||||
Common::LockGuard lock(ctx.mutex);
|
||||
if (ctx.closing) {
|
||||
EXIT("cannot register buffers on a closing video-out handle\n");
|
||||
|
||||
@@ -3,22 +3,15 @@
|
||||
|
||||
#include "common/abi.h"
|
||||
#include "common/common.h"
|
||||
#include "graphics/host_gpu/vulkanCommon.h"
|
||||
|
||||
namespace Libs::Graphics {
|
||||
|
||||
struct GraphicContext;
|
||||
class CommandBuffer;
|
||||
struct VideoOutVulkanImage;
|
||||
struct PreparedFrame;
|
||||
|
||||
vk::SurfaceCapabilitiesKHR* VulkanGetSurfaceCapabilities();
|
||||
|
||||
GraphicContext& WindowGetGraphicContext();
|
||||
|
||||
void WindowInit(uint32_t width, uint32_t height);
|
||||
void WindowRun();
|
||||
void WindowWaitForGraphicInitialized();
|
||||
PreparedFrame& WindowPrepareFrame(CommandBuffer& buffer, VideoOutVulkanImage& image);
|
||||
PreparedFrame& WindowPrepareBlankFrame(CommandBuffer& buffer, uint32_t width, uint32_t height,
|
||||
bool opaque);
|
||||
|
||||
@@ -139,7 +139,6 @@ static PreparedFramePool* GetPreparedFramePool() {
|
||||
}
|
||||
|
||||
static void ConfigurePreparedFrame(PreparedFrame& frame, vk::Extent2D extent, vk::Format format) {
|
||||
EXIT_IF(g_window_ctx == nullptr);
|
||||
if (extent.width == 0 || extent.height == 0 || format == vk::Format::eUndefined) {
|
||||
EXIT("unsupported prepared frame, extent=%ux%u format=%d\n", extent.width, extent.height,
|
||||
static_cast<int>(format));
|
||||
@@ -284,7 +283,6 @@ VulkanSwapchain::~VulkanSwapchain() = default;
|
||||
}
|
||||
|
||||
VulkanSwapchain* VulkanCreateSwapchain(uint32_t image_count) {
|
||||
EXIT_IF(g_window_ctx == nullptr);
|
||||
auto& graphics = g_window_ctx->graphic_ctx;
|
||||
EXIT_IF(graphics.screen_width == 0);
|
||||
EXIT_IF(graphics.screen_height == 0);
|
||||
@@ -363,10 +361,6 @@ static void VulkanDeleteSwapchain(VulkanSwapchain* s) {
|
||||
}
|
||||
|
||||
static void VulkanRefreshSurfaceSize() {
|
||||
EXIT_IF(g_window_ctx == nullptr);
|
||||
EXIT_IF(g_window_ctx->window == nullptr);
|
||||
EXIT_IF(g_window_ctx->surface_capabilities == nullptr);
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
SDL_Vulkan_GetDrawableSize(g_window_ctx->window, &width, &height);
|
||||
@@ -380,8 +374,6 @@ static void VulkanRefreshSurfaceSize() {
|
||||
}
|
||||
|
||||
static void VulkanRecreateSwapchain() {
|
||||
EXIT_IF(g_window_ctx == nullptr);
|
||||
|
||||
LOGF("Recreating Vulkan swapchain\n");
|
||||
VulkanRefreshSurfaceSize();
|
||||
VulkanDeleteSwapchain(g_window_ctx->swapchain);
|
||||
@@ -431,8 +423,6 @@ PreparedFrame& WindowPrepareBlankFrame(CommandBuffer& buffer, uint32_t width, ui
|
||||
void WindowPresentFrame(PreparedFrame& frame) {
|
||||
KYTY_PROFILER_FUNCTION();
|
||||
|
||||
EXIT_IF(g_window_ctx == nullptr);
|
||||
EXIT_IF(g_window_ctx->swapchain == nullptr);
|
||||
struct ReleaseScope {
|
||||
PreparedFrame* frame;
|
||||
~ReleaseScope() { GetPreparedFramePool()->Release(frame); }
|
||||
|
||||
@@ -242,6 +242,7 @@ struct WindowGamePrivate {
|
||||
};
|
||||
|
||||
WindowContext* g_window_ctx = nullptr;
|
||||
static WindowGame g_window_game;
|
||||
|
||||
constexpr const char* KYTY_SDL_WINDOW_CAPTION = "Game";
|
||||
constexpr uint32_t KYTY_SDL_WINDOW_FLAGS =
|
||||
@@ -309,7 +310,7 @@ static bool RenderAndUpdate(WindowGame& game) {
|
||||
|
||||
bool GameInit(WindowGame& game, const Common::Timer& timer) {
|
||||
EXIT_IF(game.private_data || game.event);
|
||||
auto& graphics = WindowGetGraphicContext();
|
||||
auto& graphics = g_window_ctx->graphic_ctx;
|
||||
|
||||
EXIT_IF(graphics.screen_width == 0 || graphics.screen_height == 0);
|
||||
|
||||
@@ -956,44 +957,16 @@ void WindowInit(uint32_t width, uint32_t height) {
|
||||
|
||||
g_window_ctx->graphic_ctx.screen_width = width;
|
||||
g_window_ctx->graphic_ctx.screen_height = height;
|
||||
}
|
||||
|
||||
void WindowWaitForGraphicInitialized() {
|
||||
EXIT_IF(g_window_ctx == nullptr);
|
||||
|
||||
Common::LockGuard lock(g_window_ctx->mutex);
|
||||
|
||||
while (!g_window_ctx->graphic_initialized) {
|
||||
g_window_ctx->graphic_initialized_condvar.Wait(&g_window_ctx->mutex);
|
||||
}
|
||||
WindowCreate(*g_window_ctx);
|
||||
VulkanCreate(*g_window_ctx);
|
||||
GraphicsRenderInit(g_window_ctx->graphic_ctx);
|
||||
}
|
||||
|
||||
void WindowRun() {
|
||||
EXIT_IF(g_window_ctx == nullptr);
|
||||
|
||||
KYTY_PROFILER_THREAD("Thread_Window");
|
||||
|
||||
WindowGame game;
|
||||
|
||||
g_window_ctx->mutex.Lock();
|
||||
{
|
||||
EXIT_IF(g_window_ctx->graphic_initialized);
|
||||
|
||||
WindowCreate(*g_window_ctx);
|
||||
VulkanCreate(*g_window_ctx);
|
||||
|
||||
g_window_ctx->game = &game;
|
||||
}
|
||||
g_window_ctx->mutex.Unlock();
|
||||
|
||||
GraphicsRenderCreateContext();
|
||||
|
||||
g_window_ctx->mutex.Lock();
|
||||
g_window_ctx->graphic_initialized = true;
|
||||
g_window_ctx->graphic_initialized_condvar.Signal();
|
||||
g_window_ctx->mutex.Unlock();
|
||||
|
||||
GameMainLoop(game);
|
||||
GameMainLoop(g_window_game);
|
||||
|
||||
// TODO: replace std::_Exit shutdown with full Vulkan teardown, then destroy
|
||||
// the VMA allocator immediately before vkDestroyDevice.
|
||||
@@ -1001,22 +974,6 @@ void WindowRun() {
|
||||
std::_Exit(0);
|
||||
}
|
||||
|
||||
vk::SurfaceCapabilitiesKHR* VulkanGetSurfaceCapabilities() {
|
||||
EXIT_IF(g_window_ctx == nullptr);
|
||||
|
||||
Common::LockGuard lock(g_window_ctx->mutex);
|
||||
|
||||
return &g_window_ctx->surface_capabilities->capabilities;
|
||||
}
|
||||
|
||||
GraphicContext& WindowGetGraphicContext() {
|
||||
EXIT_IF(g_window_ctx == nullptr);
|
||||
|
||||
Common::LockGuard lock(g_window_ctx->mutex);
|
||||
|
||||
return g_window_ctx->graphic_ctx;
|
||||
}
|
||||
|
||||
static int WindowIconRead(void* user, char* data, int size) {
|
||||
auto* src = static_cast<Common::File*>(user);
|
||||
uint32_t bytes_read = 0;
|
||||
@@ -1077,8 +1034,6 @@ static void WindowLoadPngIcon(const std::string& path, WindowIcon* icon) {
|
||||
}
|
||||
|
||||
void WindowUpdateIcon() {
|
||||
EXIT_IF(g_window_ctx == nullptr);
|
||||
|
||||
static WindowIcon icon;
|
||||
static bool icon_loaded = false;
|
||||
|
||||
@@ -1096,9 +1051,6 @@ void WindowUpdateIcon() {
|
||||
}
|
||||
|
||||
void WindowUpdateTitle() {
|
||||
EXIT_IF(g_window_ctx == nullptr);
|
||||
EXIT_IF(g_window_ctx->game == nullptr);
|
||||
|
||||
static char title[128];
|
||||
static char title_id[12];
|
||||
static char app_ver[12];
|
||||
@@ -1112,8 +1064,8 @@ void WindowUpdateTitle() {
|
||||
(has_title ? ", " : ""), (has_title_id ? title_id : ""),
|
||||
(has_title_id ? ", " : ""), (has_app_ver ? app_ver : ""),
|
||||
(has_app_ver ? " " : ""), g_window_ctx->device_name,
|
||||
g_window_ctx->processor_name, g_window_ctx->game->m_frame_num,
|
||||
g_window_ctx->game->m_current_fps);
|
||||
g_window_ctx->processor_name, g_window_game.m_frame_num,
|
||||
g_window_game.m_current_fps);
|
||||
|
||||
SDL_SetWindowTitle(g_window_ctx->window, fps.c_str());
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
|
||||
namespace Libs::Graphics {
|
||||
|
||||
struct WindowGame;
|
||||
|
||||
struct SurfaceCapabilities {
|
||||
vk::SurfaceCapabilitiesKHR capabilities {};
|
||||
std::vector<vk::SurfaceFormatKHR> formats;
|
||||
@@ -28,14 +26,11 @@ struct WindowContext {
|
||||
bool window_hidden = true;
|
||||
vk::SurfaceKHR surface = nullptr;
|
||||
SurfaceCapabilities* surface_capabilities = nullptr;
|
||||
WindowGame* game = nullptr;
|
||||
|
||||
char device_name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE] = {0};
|
||||
char processor_name[64] = {0};
|
||||
|
||||
Common::Mutex mutex;
|
||||
bool graphic_initialized = false;
|
||||
Common::CondVar graphic_initialized_condvar;
|
||||
Common::Mutex mutex;
|
||||
};
|
||||
|
||||
extern WindowContext* g_window_ctx;
|
||||
|
||||
Reference in New Issue
Block a user