Skip to content

Commit

Permalink
rsx: implemented internal tasks queue (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
DHrpcs3 committed Jan 20, 2016
1 parent 7523d01 commit 2e58f31
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
48 changes: 47 additions & 1 deletion rpcs3/Emu/RSX/RSXThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ namespace rsx

if (put == get || !Emu.IsRunning())
{
std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack
do_internal_task();
continue;
}

Expand Down Expand Up @@ -519,6 +519,52 @@ namespace rsx
return get_system_time() * 1000;
}

void thread::do_internal_task()
{
if (m_internal_tasks.empty())
{
std::this_thread::sleep_for(1ms);
}
else
{
std::lock_guard<std::mutex> lock{ m_mtx_task };

internal_task_entry &front = m_internal_tasks.front();

if (front.callback())
{
front.promise.set_value();
m_internal_tasks.pop_front();
}
}
}

std::future<void> thread::add_internal_task(std::function<bool()> callback)
{
std::lock_guard<std::mutex> lock{ m_mtx_task };
m_internal_tasks.emplace_back(callback);

return m_internal_tasks.back().promise.get_future();
}

void thread::invoke(std::function<bool()> callback)
{
if (get_thread_ctrl() == thread_ctrl::get_current())
{
while (true)
{
if (callback())
{
break;
}
}
}
else
{
add_internal_task(callback).wait();
}
}

std::array<u32, 4> thread::get_color_surface_addresses() const
{
u32 offset_color[] =
Expand Down
20 changes: 20 additions & 0 deletions rpcs3/Emu/RSX/RSXThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,26 @@ namespace rsx
virtual u64 timestamp() const;
virtual bool on_access_violation(u32 address, bool is_writing) { return false; }

private:
std::mutex m_mtx_task;

struct internal_task_entry
{
std::function<bool()> callback;
std::promise<void> promise;

internal_task_entry(std::function<bool()> callback) : callback(callback)
{
}
};

std::deque<internal_task_entry> m_internal_tasks;
void do_internal_task();

public:
std::future<void> add_internal_task(std::function<bool()> callback);
void invoke(std::function<bool()> callback);

/**
* Fill buffer with 4x4 scale offset matrix.
* Vertex shader's position is to be multiplied by this matrix.
Expand Down

0 comments on commit 2e58f31

Please sign in to comment.