mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-11 17:04:33 +00:00
FullscreenUI: Defer more resource loads
That way we're not compiling the background shader (if any) when we're just using the pause menu.
This commit is contained in:
@@ -90,7 +90,6 @@ static void DrawShaderBackgroundCallback(const ImDrawList* parent_list, const Im
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Resources
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
static void LoadResources();
|
||||
static void DestroyResources();
|
||||
static GPUTexture* GetUserThemeableTexture(
|
||||
const std::string_view png_name, const std::string_view svg_name, bool* is_colorable = nullptr,
|
||||
@@ -167,12 +166,10 @@ struct ALIGN_TO_CACHE_LINE WidgetsState
|
||||
PauseSubMenu current_pause_submenu = PauseSubMenu::None;
|
||||
MainWindowType previous_main_window = MainWindowType::None;
|
||||
bool initialized = false;
|
||||
bool background_loaded = false;
|
||||
bool pause_menu_was_open = false;
|
||||
bool was_paused_on_quick_menu_open = false;
|
||||
|
||||
// Resources
|
||||
std::shared_ptr<GPUTexture> app_icon_texture;
|
||||
|
||||
// Background
|
||||
std::unique_ptr<GPUTexture> app_background_texture;
|
||||
std::unique_ptr<GPUPipeline> app_background_shader;
|
||||
@@ -205,9 +202,6 @@ void FullscreenUI::Initialize()
|
||||
|
||||
s_state.initialized = true;
|
||||
|
||||
LoadResources();
|
||||
LoadBackground();
|
||||
|
||||
// in case we open the pause menu while the game is running
|
||||
if (s_state.current_main_window == MainWindowType::None && !GPUThread::HasGPUBackend() &&
|
||||
!GPUThread::IsGPUBackendRequested())
|
||||
@@ -572,26 +566,10 @@ void FullscreenUI::Render()
|
||||
UpdateTransitionState();
|
||||
}
|
||||
|
||||
void FullscreenUI::InvalidateCoverCache()
|
||||
{
|
||||
if (!GPUThread::IsFullscreenUIRequested())
|
||||
return;
|
||||
|
||||
GPUThread::RunOnThread(&FullscreenUI::ClearCoverCache);
|
||||
}
|
||||
|
||||
void FullscreenUI::LoadResources()
|
||||
{
|
||||
s_state.app_icon_texture = LoadTexture("images/duck.png");
|
||||
|
||||
InitializeHotkeyList();
|
||||
}
|
||||
|
||||
void FullscreenUI::DestroyResources()
|
||||
{
|
||||
s_state.app_background_texture.reset();
|
||||
s_state.app_background_shader.reset();
|
||||
s_state.app_icon_texture.reset();
|
||||
}
|
||||
|
||||
GPUTexture* FullscreenUI::GetUserThemeableTexture(const std::string_view png_name, const std::string_view svg_name,
|
||||
@@ -661,7 +639,6 @@ void FullscreenUI::UpdateCurrentTimeString()
|
||||
// Utility
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void FullscreenUI::DoStartPath(std::string path, std::string state, std::optional<bool> fast_boot)
|
||||
{
|
||||
if (GPUThread::HasGPUBackend())
|
||||
@@ -1018,13 +995,14 @@ bool FullscreenUI::HasBackground()
|
||||
return static_cast<bool>(s_state.app_background_texture || s_state.app_background_shader);
|
||||
}
|
||||
|
||||
void FullscreenUI::LoadBackground()
|
||||
void FullscreenUI::UpdateBackground()
|
||||
{
|
||||
if (!IsInitialized())
|
||||
return;
|
||||
|
||||
g_gpu_device->RecycleTexture(std::move(s_state.app_background_texture));
|
||||
s_state.app_background_shader.reset();
|
||||
s_state.background_loaded = true;
|
||||
|
||||
const TinyString background_name =
|
||||
Host::GetBaseTinyStringSettingValue("Main", "FullscreenUIBackground", DEFAULT_BACKGROUND_NAME);
|
||||
@@ -1199,6 +1177,9 @@ bool FullscreenUI::LoadBackgroundImage(const std::string& path, Error* error)
|
||||
|
||||
void FullscreenUI::DrawBackground()
|
||||
{
|
||||
if (!s_state.background_loaded)
|
||||
UpdateBackground();
|
||||
|
||||
if (s_state.app_background_shader)
|
||||
{
|
||||
ImDrawList* dl = ImGui::GetBackgroundDrawList();
|
||||
@@ -1251,7 +1232,9 @@ void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size)
|
||||
{
|
||||
const ImVec2 logo_pos = LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING);
|
||||
const ImVec2 logo_size = ImVec2(UIStyle.LargeFontSize, UIStyle.LargeFontSize);
|
||||
dl->AddImage(s_state.app_icon_texture.get(), logo_pos, logo_pos + logo_size);
|
||||
GPUTexture* const logo_texture =
|
||||
GetUserThemeableTexture("images/duck.png", "images/duck.svg", nullptr, logo_size);
|
||||
dl->AddImage(logo_texture, logo_pos, logo_pos + logo_size);
|
||||
|
||||
const std::string_view heading_text = "DuckStation";
|
||||
const ImVec2 text_size = heading_font->CalcTextSizeA(heading_font_size, heading_font_weight, FLT_MAX, 0.0f,
|
||||
@@ -2270,7 +2253,6 @@ void FullscreenUI::DrawResumeStateSelector()
|
||||
EndFixedPopupDialog();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Overlays
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -2303,7 +2285,8 @@ void FullscreenUI::DrawAboutWindow()
|
||||
|
||||
const ImVec2 image_size = LayoutScale(64.0f, 64.0f);
|
||||
const float indent = image_size.x + LayoutScale(8.0f);
|
||||
ImGui::GetWindowDrawList()->AddImage(s_state.app_icon_texture.get(), ImGui::GetCursorScreenPos(),
|
||||
GPUTexture* const logo_texture = GetUserThemeableTexture("images/duck.png", "images/duck.svg", nullptr, image_size);
|
||||
ImGui::GetWindowDrawList()->AddImage(logo_texture, ImGui::GetCursorScreenPos(),
|
||||
ImGui::GetCursorScreenPos() + image_size);
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + indent);
|
||||
ImGui::PushFont(nullptr, 0.0f, UIStyle.BoldFontWeight);
|
||||
|
||||
@@ -48,6 +48,10 @@ enum class SettingsPage : u8
|
||||
Count
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Utility
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SwitchToMainWindow(MainWindowType type);
|
||||
void ReturnToMainWindow();
|
||||
void ReturnToMainWindow(float transition_time);
|
||||
@@ -56,12 +60,20 @@ bool AreAnyDialogsOpen();
|
||||
void ExitFullscreenAndOpenURL(std::string_view url);
|
||||
void CopyTextToClipboard(std::string title, std::string_view text);
|
||||
|
||||
FileSelectorFilters GetDiscImageFilters();
|
||||
FileSelectorFilters GetImageFilters();
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Landing
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline constexpr const char* DEFAULT_BACKGROUND_NAME = "StaticGray";
|
||||
inline constexpr const char* NONE_BACKGROUND_NAME = "None";
|
||||
ImVec4 GetTransparentBackgroundColor(const ImVec4& no_background_color = UIStyle.BackgroundColor);
|
||||
ChoiceDialogOptions GetBackgroundOptions(const TinyString& current_value);
|
||||
void UpdateBackground();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Save State List
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool OpenLoadStateSelectorForGameResume(const GameList::Entry* entry);
|
||||
void OpenSaveStateSelector(const std::string& serial, const std::string& path, bool is_loading);
|
||||
void DoResume();
|
||||
@@ -71,6 +83,8 @@ void DoResume();
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool ShouldOpenToGameList();
|
||||
FileSelectorFilters GetDiscImageFilters();
|
||||
FileSelectorFilters GetImageFilters();
|
||||
|
||||
void ClearGameListState();
|
||||
void SwitchToGameList();
|
||||
@@ -87,7 +101,6 @@ void ClearCoverCache();
|
||||
// Settings
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void InitializeHotkeyList();
|
||||
void ClearSettingsState();
|
||||
void SwitchToSettings();
|
||||
bool SwitchToGameSettings(SettingsPage page = SettingsPage::Summary);
|
||||
@@ -98,11 +111,4 @@ void DrawSettingsWindow();
|
||||
SettingsPage GetCurrentSettingsPage();
|
||||
bool IsInputBindingDialogOpen();
|
||||
|
||||
// TODO: Move to widgets or something
|
||||
inline constexpr const char* DEFAULT_BACKGROUND_NAME = "StaticGray";
|
||||
inline constexpr const char* NONE_BACKGROUND_NAME = "None";
|
||||
ImVec4 GetTransparentBackgroundColor(const ImVec4& no_background_color = UIStyle.BackgroundColor);
|
||||
ChoiceDialogOptions GetBackgroundOptions(const TinyString& current_value);
|
||||
void LoadBackground();
|
||||
|
||||
} // namespace FullscreenUI
|
||||
|
||||
@@ -73,6 +73,8 @@ struct PostProcessingStageInfo
|
||||
|
||||
} // namespace
|
||||
|
||||
static void PopulateHotkeyList();
|
||||
|
||||
static void DrawSummarySettingsPage(bool show_localized_titles);
|
||||
static void DrawInterfaceSettingsPage();
|
||||
static void DrawGameListSettingsPage();
|
||||
@@ -1519,8 +1521,11 @@ void FullscreenUI::StartClearBindingsForPort(u32 port)
|
||||
});
|
||||
}
|
||||
|
||||
void FullscreenUI::InitializeHotkeyList()
|
||||
void FullscreenUI::PopulateHotkeyList()
|
||||
{
|
||||
if (!s_settings_locals.hotkey_list_cache.empty())
|
||||
return;
|
||||
|
||||
// sort hotkeys by category so we don't duplicate the groups
|
||||
const auto hotkeys = InputManager::GetHotkeyList();
|
||||
s_settings_locals.hotkey_list_cache.reserve(hotkeys.size());
|
||||
@@ -1589,6 +1594,7 @@ void FullscreenUI::SwitchToSettings()
|
||||
|
||||
PopulateGraphicsAdapterList();
|
||||
PopulatePostProcessingChain(GetEditingSettingsInterface(), PostProcessing::Config::DISPLAY_CHAIN_SECTION);
|
||||
PopulateHotkeyList();
|
||||
|
||||
if (!IsEditingGameSettings(GetEditingSettingsInterface()))
|
||||
{
|
||||
@@ -2137,7 +2143,7 @@ void FullscreenUI::DrawInterfaceSettingsPage()
|
||||
|
||||
// Have to defer the reload, because we've already drawn the bg for this frame.
|
||||
BeginTransition(LONG_TRANSITION_TIME, {});
|
||||
Host::RunOnCPUThread([]() { GPUThread::RunOnThread(&FullscreenUI::LoadBackground); });
|
||||
Host::RunOnCPUThread([]() { GPUThread::RunOnThread(&FullscreenUI::UpdateBackground); });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user