Skip to content

Commit

Permalink
Emu/overlay: ingame native overlay PPU compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Mar 31, 2021
1 parent e557c96 commit 870224c
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 21 deletions.
47 changes: 40 additions & 7 deletions rpcs3/Emu/Cell/PPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const bool s_use_ssse3 = utils::has_ssse3();
extern atomic_t<u64> g_watchdog_hold_ctr;

extern atomic_t<const char*> g_progr;
extern atomic_t<bool> g_progr_show;
extern atomic_t<u32> g_progr_ftotal;
extern atomic_t<u32> g_progr_fdone;
extern atomic_t<u32> g_progr_ptotal;
Expand Down Expand Up @@ -2400,9 +2401,9 @@ extern void ppu_precompile(std::vector<std::string>& dir_queue, std::vector<lv2_
}
}

g_progr = "Compiling PPU modules";

g_progr = "Compiling PPU modules...";
g_progr_ftotal += file_queue.size();
g_progr_show = true;

atomic_t<usz> fnext = 0;

Expand Down Expand Up @@ -2519,6 +2520,8 @@ extern void ppu_precompile(std::vector<std::string>& dir_queue, std::vector<lv2_
// Join every thread
workers.join();

g_progr_show = false;

// Revert changes

if (!had_ovl)
Expand All @@ -2543,6 +2546,17 @@ extern void ppu_initialize()
return;
}

g_progr = "Scanning PPU modules...";
g_progr_show = true;

struct scoped_dialog_control
{
~scoped_dialog_control()
{
g_progr_show = false;
}
} dialog_control;

bool compile_main = false;

// Check main module cache
Expand Down Expand Up @@ -2715,8 +2729,12 @@ bool ppu_initialize(const ppu_module& info, bool check_only)
}

#ifdef LLVM_AVAILABLE
// Initialize progress dialog
g_progr = "Compiling PPU modules...";
if (!check_only)
{
// Initialize progress dialog
g_progr = "Loading PPU modules...";
g_progr_show = true;
}

struct jit_core_allocator
{
Expand Down Expand Up @@ -2945,6 +2963,9 @@ bool ppu_initialize(const ppu_module& info, bool check_only)

if (!check_only)
{
// Update progress dialog
g_progr_ptotal++;

link_workload.emplace_back(obj_name, false);
}

Expand Down Expand Up @@ -2972,16 +2993,18 @@ bool ppu_initialize(const ppu_module& info, bool check_only)

// Fill workload list for compilation
workload.emplace_back(std::move(obj_name), std::move(part));

// Update progress dialog
g_progr_ptotal++;
}

if (check_only)
{
return false;
}

if (!workload.empty())
{
g_progr = "Compiling PPU modules...";
}

// Create worker threads for compilation (TODO: how many threads)
{
u32 thread_count = Emu.GetMaxThreads();
Expand Down Expand Up @@ -3033,9 +3056,16 @@ bool ppu_initialize(const ppu_module& info, bool check_only)

if (Emu.IsStopped() || !get_current_cpu_thread())
{
g_progr_show = false;
return compiled_new;
}

if (workload.size() < link_workload.size())
{
// Only show this message if this task is relevant
g_progr = "Linking PPU modules...";
}

for (auto [obj_name, is_compiled] : link_workload)
{
if (Emu.IsStopped())
Expand All @@ -3048,10 +3078,13 @@ bool ppu_initialize(const ppu_module& info, bool check_only)
if (!is_compiled)
{
ppu_log.success("LLVM: Loaded module %s", obj_name);
g_progr_pdone++;
}
}
}

g_progr_show = false;

if (Emu.IsStopped() || !get_current_cpu_thread())
{
return compiled_new;
Expand Down
7 changes: 7 additions & 0 deletions rpcs3/Emu/Cell/SPURecompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "util/sysinfo.hpp"

extern atomic_t<const char*> g_progr;
extern atomic_t<bool> g_progr_show;
extern atomic_t<u32> g_progr_ptotal;
extern atomic_t<u32> g_progr_pdone;

Expand Down Expand Up @@ -426,6 +427,7 @@ void spu_cache::initialize()

g_progr = "Building SPU cache...";
g_progr_ptotal += ::size32(func_list);
g_progr_show = true;

worker_count = Emu.GetMaxThreads();
}
Expand Down Expand Up @@ -525,6 +527,11 @@ void spu_cache::initialize()
spu_log.notice("SPU Runtime: Worker %u built %u programs.", i + 1, workers[i]);
}

if (g_cfg.core.spu_decoder == spu_decoder_type::asmjit || g_cfg.core.spu_decoder == spu_decoder_type::llvm)
{
g_progr_show = false;
}

if (Emu.IsStopped())
{
spu_log.error("SPU Runtime: Cache building aborted.");
Expand Down
15 changes: 10 additions & 5 deletions rpcs3/Emu/RSX/Overlays/overlay_message_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,7 @@ namespace rsx
btn_cancel.translate(0, offset);
}

text_display.set_text(text);

u16 text_w, text_h;
text_display.measure_text(text_w, text_h);
text_display.translate(0, -(text_h - 16));
set_text(text);

switch (type.button_type.unshifted())
{
Expand Down Expand Up @@ -306,6 +302,15 @@ namespace rsx
return CELL_OK;
}

void message_dialog::set_text(const std::string& text)
{
u16 text_w, text_h;
text_display.set_pos(90, 364);
text_display.set_text(text);
text_display.measure_text(text_w, text_h);
text_display.translate(0, -(text_h - 16));
}

u32 message_dialog::progress_bar_count()
{
return num_progress_bars;
Expand Down
2 changes: 2 additions & 0 deletions rpcs3/Emu/RSX/Overlays/overlay_message_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace rsx

error_code show(bool is_blocking, const std::string& text, const MsgDialogType& type, std::function<void(s32 status)> on_close);

void set_text(const std::string& text);

u32 progress_bar_count();
void progress_bar_set_taskbar_index(s32 index);
error_code progress_bar_set_message(u32 index, const std::string& msg);
Expand Down
52 changes: 43 additions & 9 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "Emu/title.h"
#include "Emu/IdManager.h"
#include "Emu/RSX/Capture/rsx_replay.h"
#include "Emu/RSX/Overlays/overlay_message_dialog.h"

#include "Loader/PSF.h"
#include "Loader/ELF.h"
Expand Down Expand Up @@ -82,6 +83,7 @@ std::mutex g_tty_mutex;

// Progress display server synchronization variables
atomic_t<const char*> g_progr{""};
atomic_t<bool> g_progr_show{false};
atomic_t<u32> g_progr_ftotal{0};
atomic_t<u32> g_progr_fdone{0};
atomic_t<u32> g_progr_ptotal{0};
Expand Down Expand Up @@ -341,7 +343,7 @@ namespace
while (thread_ctrl::state() != thread_state::aborting)
{
// Wait for the start condition
while (!g_progr_ftotal && !g_progr_ptotal)
while (!g_progr_show)
{
if (thread_ctrl::state() == thread_state::aborting)
{
Expand All @@ -357,9 +359,29 @@ namespace
}

// Initialize message dialog
std::shared_ptr<MsgDialogBase> dlg = Emu.GetCallbacks().get_msg_dialog();
if (dlg)
std::shared_ptr<MsgDialogBase> dlg;
std::shared_ptr<rsx::overlays::message_dialog> native_dlg;

if (const auto renderer = rsx::get_current_renderer();
renderer && renderer->is_inited)
{
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
MsgDialogType type{};
type.se_normal = true;
type.bg_invisible = true;
type.disable_cancel = true;
type.progress_bar_count = 1;

native_dlg = manager->create<rsx::overlays::message_dialog>(!!g_cfg.video.shader_preloading_dialog.use_custom_background);
native_dlg->show(false, +g_progr, type, nullptr);
native_dlg->progress_bar_set_message(0, "Please wait");
}
}

if (!native_dlg)
{
dlg = Emu.GetCallbacks().get_msg_dialog();
dlg->type.se_normal = true;
dlg->type.bg_invisible = true;
dlg->type.progress_bar_count = 1;
Expand Down Expand Up @@ -414,7 +436,13 @@ namespace
if (ptotal)
fmt::append(progr, " module %u of %u", pdone, ptotal);

if (dlg)
if (native_dlg)
{
native_dlg->set_text(+g_progr);
native_dlg->progress_bar_set_message(0, progr);
native_dlg->progress_bar_set_value(0, std::floor(value));
}
else if (dlg)
{
dlg->SetMsg(+g_progr);
dlg->ProgressBarSetMsg(0, progr);
Expand All @@ -423,7 +451,7 @@ namespace
});
}

if (fdone >= ftotal && pdone >= ptotal)
if (!g_progr_show)
{
// Close dialog
break;
Expand All @@ -442,14 +470,19 @@ namespace
g_progr_fdone -= fdone;
g_progr_ptotal -= ptotal;
g_progr_pdone -= pdone;
g_progr_show = false;

if (dlg)
Emu.CallAfter([=]()
{
Emu.CallAfter([=]()
if (native_dlg)
{
native_dlg->close(false, false);
}
else if (dlg)
{
dlg->Close(true);
});
}
}
});
}
}

Expand All @@ -459,6 +492,7 @@ namespace
g_progr_fdone.release(0);
g_progr_ptotal.release(0);
g_progr_pdone.release(0);
g_progr_show.release(false);
}

static auto constexpr thread_name = "Progress Dialog Server"sv;
Expand Down

0 comments on commit 870224c

Please sign in to comment.