Initialize render_creator in headless mode

This commit is contained in:
Megamouse 2026-06-02 07:55:40 +02:00
parent 62747bb40d
commit 3fa1241ac0
11 changed files with 73 additions and 99 deletions

View File

@ -475,7 +475,6 @@ void Emulator::Init()
g_cfg.name.clear();
// Not all renderers are known at compile time, so set a provided default if possible
// TODO: Also initialize render_creator in headless mode
ensure(m_supported_renderers.contains(m_default_renderer));
ensure(!(m_default_renderer == video_renderer::vulkan && m_default_graphics_adapter.empty()));
g_cfg.video.renderer.set(m_default_renderer);

View File

@ -45,6 +45,7 @@
#include <thread>
LOG_CHANNEL(sys_log, "SYS");
LOG_CHANNEL(cfg_log, "CFG");
namespace audio
{
@ -60,6 +61,36 @@ namespace rsx::overlays
extern void qt_events_aware_op(int repeat_duration_ms, std::function<bool()> wrapped_op);
main_application::main_application()
: m_render_creator(std::make_shared<render_creator>())
{
std::set<video_renderer> supported_renderers;
supported_renderers.insert(video_renderer::null);
if (m_render_creator->OpenGL.supported)
{
supported_renderers.insert(video_renderer::opengl);
}
// Make Vulkan default setting if it is supported
if (m_render_creator->Vulkan.supported && !m_render_creator->Vulkan.adapters.empty())
{
const std::string adapter = ::at32(m_render_creator->Vulkan.adapters, 0).toStdString();
cfg_log.notice("Setting the default renderer to Vulkan. Default GPU: '%s'", adapter);
Emu.SetDefaultRenderer(video_renderer::vulkan);
Emu.SetDefaultGraphicsAdapter(adapter);
supported_renderers.insert(video_renderer::vulkan);
}
else if (m_render_creator->OpenGL.supported)
{
cfg_log.notice("Setting the default renderer to OpenGl");
Emu.SetDefaultRenderer(video_renderer::opengl);
}
Emu.SetSupportedRenderers(supported_renderers);
}
/** Emu.Init() wrapper for user management */
void main_application::InitializeEmulator(const std::string& user, bool show_gui, bool headless)
{

View File

@ -1,5 +1,7 @@
#pragma once
#include "rpcs3qt/render_creator.h"
#include <string>
#include <QThread>
@ -9,6 +11,8 @@ class gs_frame;
class main_application
{
public:
main_application();
virtual bool Init() = 0;
static void InitializeEmulator(const std::string& user, bool show_gui, bool headless);
@ -25,6 +29,7 @@ protected:
EmuCallbacks CreateCallbacks();
std::shared_ptr<render_creator> m_render_creator;
std::string m_active_user;
gs_frame* m_game_window = nullptr;
};

View File

@ -425,9 +425,6 @@
<ClCompile Include="QTGeneratedFiles\Debug\moc_register_editor_dialog.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Debug\moc_render_creator.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Debug\moc_clans_settings_dialog.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
@ -737,9 +734,6 @@
<ClCompile Include="QTGeneratedFiles\Release\moc_register_editor_dialog.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Release\moc_render_creator.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Release\moc_clans_settings_dialog.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
@ -1471,16 +1465,7 @@
</CustomBuild>
<ClInclude Include="rpcs3qt\custom_tree_widget.h" />
<ClInclude Include="rpcs3qt\emu_settings_type.h" />
<CustomBuild Include="rpcs3qt\render_creator.h">
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Moc%27ing %(Identity)...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -DWIN32 -DWIN64 -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_CONCURRENT_LIB -D%(PreprocessorDefinitions) "-I.\..\3rdparty\wolfssl\wolfssl" "-I.\..\3rdparty\curl\curl\include" "-I.\..\3rdparty\libusb\libusb\libusb" "-I$(VULKAN_SDK)\Include" "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtCore" "-I.\debug" "-I.\QTGeneratedFiles\$(ConfigurationName)" "-I.\QTGeneratedFiles" "-I$(QTDIR)\include\QtConcurrent"</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Moc%27ing %(Identity)...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -DWIN32 -DWIN64 -DWITH_DISCORD_RPC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -DQT_CONCURRENT_LIB -D%(PreprocessorDefinitions) "-I.\..\3rdparty\wolfssl\wolfssl" "-I.\..\3rdparty\curl\curl\include" "-I.\..\3rdparty\libusb\libusb\libusb" "-I$(VULKAN_SDK)\Include" "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtCore" "-I.\release" "-I.\QTGeneratedFiles\$(ConfigurationName)" "-I.\QTGeneratedFiles" "-I$(QTDIR)\include\QtConcurrent"</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
</CustomBuild>
<ClInclude Include="rpcs3qt\render_creator.h" />
<ClInclude Include="rpcs3qt\flow_layout.h" />
<CustomBuild Include="rpcs3qt\flow_widget.h">
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Moc%27ing %(Identity)...</Message>

View File

@ -858,12 +858,6 @@
<ClCompile Include="rpcs3qt\render_creator.cpp">
<Filter>Gui\settings</Filter>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Debug\moc_render_creator.cpp">
<Filter>Generated Files\Debug</Filter>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Release\moc_render_creator.cpp">
<Filter>Generated Files\Release</Filter>
</ClCompile>
<ClCompile Include="rpcs3qt\config_adapter.cpp">
<Filter>Gui\settings</Filter>
</ClCompile>

View File

@ -91,44 +91,12 @@ namespace
}
}
emu_settings::emu_settings()
emu_settings::emu_settings(std::shared_ptr<render_creator> r_creator)
: QObject()
, m_render_creator(ensure(r_creator))
{
}
bool emu_settings::Init()
{
m_render_creator = new render_creator(this);
std::set<video_renderer> supported_renderers;
supported_renderers.insert(video_renderer::null);
if (m_render_creator->OpenGL.supported)
{
supported_renderers.insert(video_renderer::opengl);
}
// Make Vulkan default setting if it is supported
if (!m_render_creator->abort_requested && m_render_creator->Vulkan.supported && !m_render_creator->Vulkan.adapters.empty())
{
const std::string adapter = ::at32(m_render_creator->Vulkan.adapters, 0).toStdString();
cfg_log.notice("Setting the default renderer to Vulkan. Default GPU: '%s'", adapter);
Emu.SetDefaultRenderer(video_renderer::vulkan);
Emu.SetDefaultGraphicsAdapter(adapter);
supported_renderers.insert(video_renderer::vulkan);
}
else if (m_render_creator->OpenGL.supported)
{
cfg_log.notice("Setting the default renderer to OpenGl");
Emu.SetDefaultRenderer(video_renderer::opengl);
}
Emu.SetSupportedRenderers(supported_renderers);
return !m_render_creator->abort_requested;
}
void emu_settings::LoadSettings(const std::string& title_id, bool create_config_from_global, const std::string& db_config)
{
m_title_id = title_id;

View File

@ -35,9 +35,7 @@ public:
/** Creates a settings object which reads in the config.yml file at rpcs3/bin/%path%/config.yml
* Settings are only written when SaveSettings is called.
*/
emu_settings();
bool Init();
emu_settings(std::shared_ptr<render_creator> r_creator);
/** Connects a combo box with the target settings type*/
void EnhanceComboBox(QComboBox* combobox, emu_settings_type type, bool is_ranged = false, bool use_max = false, int max = 0, bool sorted = false, bool strict = true);
@ -94,7 +92,7 @@ public:
emu_settings_type FindSettingsType(const cfg::_base* node) const;
/** Gets all the renderer info for gpu settings.*/
render_creator* m_render_creator = nullptr;
std::shared_ptr<render_creator> m_render_creator;
/** Gets a list of all the microphones available.*/
microphone_creator m_microphone_creator;

View File

@ -126,15 +126,35 @@ bool gui_application::Init()
}
}
m_emu_settings = std::make_shared<emu_settings>();
if (m_render_creator->vulkan_timed_out)
{
gui_log.error("Vulkan device enumeration timed out");
const auto button = QMessageBox::critical(nullptr, tr("Vulkan Check Timeout"),
tr("Querying for Vulkan-compatible devices is taking too long. This is usually caused by malfunctioning "
"graphics drivers, reinstalling them could fix the issue.\n\n"
"Selecting ignore starts the emulator without Vulkan support."),
QMessageBox::Ignore | QMessageBox::Abort, QMessageBox::Abort);
if (button != QMessageBox::Ignore)
{
return false;
}
}
#ifdef __APPLE__
if (!m_render_creator->Vulkan.supported)
{
QMessageBox::warning(nullptr,
tr("Warning"),
tr("Vulkan is not supported on this Mac.\n"
"No graphics will be rendered."));
}
#endif
m_emu_settings = std::make_shared<emu_settings>(m_render_creator);
m_gui_settings = std::make_shared<gui_settings>();
m_persistent_settings = std::make_shared<persistent_settings>();
if (!m_emu_settings->Init())
{
return false;
}
if (m_gui_settings->GetValue(gui::m_attachCommandLine).toBool())
{
utils::attach_console(utils::console_stream::std_err, true);

View File

@ -1,7 +1,5 @@
#include "render_creator.h"
#include <QMessageBox>
#include "Utilities/Thread.h"
#if defined(HAVE_VULKAN)
@ -15,7 +13,7 @@
LOG_CHANNEL(cfg_log, "CFG");
render_creator::render_creator(QObject *parent) : QObject(parent)
render_creator::render_creator()
{
#if defined(HAVE_VULKAN)
// Some drivers can get stuck when checking for vulkan-compatible gpus, f.ex. if they're waiting for one to get
@ -73,21 +71,8 @@ render_creator::render_creator(QObject *parent) : QObject(parent)
}())
{
enum_thread.release(); // Detach thread (destructor is not called)
cfg_log.error("Vulkan device enumeration timed out");
const auto button = QMessageBox::critical(nullptr, tr("Vulkan Check Timeout"),
tr("Querying for Vulkan-compatible devices is taking too long. This is usually caused by malfunctioning "
"graphics drivers, reinstalling them could fix the issue.\n\n"
"Selecting ignore starts the emulator without Vulkan support."),
QMessageBox::Ignore | QMessageBox::Abort, QMessageBox::Abort);
if (button != QMessageBox::Ignore)
{
abort_requested = true;
return;
}
supports_vulkan = false;
vulkan_timed_out = true;
}
else
{
@ -103,14 +88,6 @@ render_creator::render_creator(QObject *parent) : QObject(parent)
#ifdef __APPLE__
OpenGL.supported = false;
if (!Vulkan.supported)
{
QMessageBox::warning(nullptr,
tr("Warning"),
tr("Vulkan is not supported on this Mac.\n"
"No graphics will be rendered."));
}
#endif
renderers = { &Vulkan, &OpenGL, &NullRender };

View File

@ -2,16 +2,13 @@
#include "emu_settings_type.h"
#include <QObject>
#include <QString>
#include <QStringList>
class render_creator : public QObject
class render_creator
{
Q_OBJECT
public:
render_creator(QObject* parent);
render_creator();
void update_names(const QStringList& names);
@ -33,7 +30,7 @@ public:
, supported(supported) {}
};
bool abort_requested = false;
bool vulkan_timed_out = false;
bool supports_vulkan = false;
QStringList vulkan_adapters;
render_info Vulkan;

View File

@ -370,7 +370,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std
// | |__| | | | |__| | | | (_| | |_) |
// \_____|_| \____/ |_|\__,_|_.__/
render_creator* r_creator = m_emu_settings->m_render_creator;
std::shared_ptr<render_creator> r_creator = m_emu_settings->m_render_creator;
if (!r_creator)
{