8000 Add facility to run tasks on dedicated threads using the ThreadManager interface by hrydgard · Pull Request #16873 · hrydgard/ppsspp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add facility to run tasks on dedicated threads using the ThreadManager interface #16873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Common/GPU/Vulkan/thin3d_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class VKShaderModule : public ShaderModule {
}

private:
VulkanContext *vulkan_;
VulkanContext *vulkan_ = nullptr;
Promise<VkShaderModule> *module_ = nullptr;
VkShaderStageFlagBits vkstage_;
bool ok_ = false;
Expand Down
5 changes: 3 additions & 2 deletions Common/Net/HTTPHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ class RequestHeader {
// Public variables since it doesn't make sense
// to bother with accessors for all these.
int status = 100;
// Intentional misspelling.
char *referer = nullptr;

char *referer = nullptr; // Intentional misspelling.
char *user_agent = nullptr;
char *resource = nullptr;
char *params = nullptr;

int content_length = -1;
std::unordered_map<std::string, std::string> other;
enum RequestType {
Expand Down
2 changes: 1 addition & 1 deletion Common/Net/HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Request::~Request() {
}
delete in_;
if (!out_->Empty()) {
ERROR_LOG(IO, "Output not empty - connection abort?");
ERROR_LOG(IO, "Output not empty - connection abort? (%s)", this->header_.resource);
}
delete out_;
}
Expand Down
12 changes: 12 additions & 0 deletions Common/Thread/ThreadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ void ThreadManager::Init(int numRealCores, int numLogicalCoresPerCpu) {
}

void ThreadManager::EnqueueTask(Task *task) {
if (task->Type() == TaskType::DEDICATED_THREAD) {
std::thread th([=](Task *task) {
SetCurrentThreadName("DedicatedThreadTask");
task->Run();
task->Release();
}, task);
th.detach();
return;
}

_assert_msg_(IsInitialized(), "ThreadManager not initialized");

int minThread;
Expand Down Expand Up @@ -270,6 +280,8 @@ void ThreadManager::EnqueueTask(Task *task) {
}

void ThreadManager::EnqueueTaskOnThread(int threadNum, Task *task) {
_assert_msg_(task->Type() != TaskType::DEDICATED_THREAD, "Dedicated thread tasks can't be put on specific threads");

_assert_msg_(threadNum >= 0 && threadNum < (int)global_->threads_.size(), "Bad threadnum or not initialized");
ThreadContext *thread = global_->threads_[threadNum];

Expand Down
1 change: 1 addition & 0 deletions Common/Thread/ThreadManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
enum class TaskType {
CPU_COMPUTE,
IO_BLOCKING,
DEDICATED_THREAD, // These can never get stuck in queue behind others, but are more expensive to launch. Cannot use I/O.
};

// Implement this to make something that you can run on the thread manager.
Expand Down
11 changes: 8 additions & 3 deletions GPU/Vulkan/ShaderManagerVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,17 @@ static Promise<VkShaderModule> *CompileShaderModuleAsync(VulkanContext *vulkan,

#if defined(_DEBUG)
// Don't parallelize in debug mode, pathological behavior due to mutex locks in allocator which is HEAVILY used by glslang.
return Promise<VkShaderModule>::AlreadyDone(compile());
bool singleThreaded = true;
#else
return Promise<VkShaderModule>::Spawn(&g_threadManager, compile, TaskType::CPU_COMPUTE);
bool singleThreaded = false;
#endif
}

if (singleThreaded) {
return Promise<VkShaderModule>::AlreadyDone(compile());
} else {
return Promise<VkShaderModule>::Spawn(&g_threadManager, compile, TaskType::CPU_COMPUTE);
}
}

VulkanFragmentShader::VulkanFragmentShader(VulkanContext *vulkan, FShaderID id, FragmentShaderFlags flags, const char *code)
: vulkan_(vulkan), id_(id), flags_(flags) {
Expand Down
0