mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 21:01:37 +00:00
Playing around with thread priorities.
This commit is contained in:
parent
2c948cc5d2
commit
2f6e1c88d6
1 changed files with 29 additions and 5 deletions
|
|
@ -2216,8 +2216,6 @@ void Video::Present()
|
||||||
if (g_shouldPrecompilePipelines)
|
if (g_shouldPrecompilePipelines)
|
||||||
{
|
{
|
||||||
// This is all the model consumer thread needs to see.
|
// This is all the model consumer thread needs to see.
|
||||||
++g_compilingDataCount;
|
|
||||||
|
|
||||||
if ((++g_pendingDataCount) == 1)
|
if ((++g_pendingDataCount) == 1)
|
||||||
g_pendingDataCount.notify_all();
|
g_pendingDataCount.notify_all();
|
||||||
|
|
||||||
|
|
@ -4245,8 +4243,10 @@ static void ProcSetPixelShader(const RenderCommand& cmd)
|
||||||
static std::thread g_renderThread([]
|
static std::thread g_renderThread([]
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
|
||||||
GuestThread::SetThreadName(GetCurrentThreadId(), "Render Thread");
|
GuestThread::SetThreadName(GetCurrentThreadId(), "Render Thread");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RenderCommand commands[32];
|
RenderCommand commands[32];
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
|
@ -4289,6 +4289,8 @@ static std::thread g_renderThread([]
|
||||||
default: assert(false && "Unrecognized render command type."); break;
|
default: assert(false && "Unrecognized render command type."); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::this_thread::yield();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -5055,6 +5057,7 @@ struct PipelineStateQueueItem
|
||||||
#ifdef ASYNC_PSO_DEBUG
|
#ifdef ASYNC_PSO_DEBUG
|
||||||
std::string pipelineName;
|
std::string pipelineName;
|
||||||
#endif
|
#endif
|
||||||
|
bool precompiledPipeline{};
|
||||||
};
|
};
|
||||||
|
|
||||||
static moodycamel::BlockingConcurrentQueue<PipelineStateQueueItem> g_pipelineStateQueue;
|
static moodycamel::BlockingConcurrentQueue<PipelineStateQueueItem> g_pipelineStateQueue;
|
||||||
|
|
@ -5062,8 +5065,11 @@ static moodycamel::BlockingConcurrentQueue<PipelineStateQueueItem> g_pipelineSta
|
||||||
static void PipelineCompilerThread()
|
static void PipelineCompilerThread()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
int threadPriority = THREAD_PRIORITY_LOWEST;
|
||||||
|
SetThreadPriority(GetCurrentThread(), threadPriority);
|
||||||
GuestThread::SetThreadName(GetCurrentThreadId(), "Pipeline Compiler Thread");
|
GuestThread::SetThreadName(GetCurrentThreadId(), "Pipeline Compiler Thread");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::unique_ptr<GuestThreadContext> ctx;
|
std::unique_ptr<GuestThreadContext> ctx;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
|
@ -5074,6 +5080,24 @@ static void PipelineCompilerThread()
|
||||||
if (ctx == nullptr)
|
if (ctx == nullptr)
|
||||||
ctx = std::make_unique<GuestThreadContext>(0);
|
ctx = std::make_unique<GuestThreadContext>(0);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
int newThreadPriority = threadPriority;
|
||||||
|
|
||||||
|
bool loading = *reinterpret_cast<bool*>(g_memory.Translate(0x83367A4C));
|
||||||
|
if (queueItem.precompiledPipeline)
|
||||||
|
newThreadPriority = THREAD_PRIORITY_IDLE;
|
||||||
|
else if (loading)
|
||||||
|
newThreadPriority = THREAD_PRIORITY_HIGHEST;
|
||||||
|
else
|
||||||
|
newThreadPriority = THREAD_PRIORITY_LOWEST;
|
||||||
|
|
||||||
|
if (newThreadPriority != threadPriority)
|
||||||
|
{
|
||||||
|
SetThreadPriority(GetCurrentThread(), newThreadPriority);
|
||||||
|
threadPriority = newThreadPriority;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
auto pipeline = CreateGraphicsPipeline(queueItem.pipelineState);
|
auto pipeline = CreateGraphicsPipeline(queueItem.pipelineState);
|
||||||
#ifdef ASYNC_PSO_DEBUG
|
#ifdef ASYNC_PSO_DEBUG
|
||||||
pipeline->setName(queueItem.pipelineName);
|
pipeline->setName(queueItem.pipelineName);
|
||||||
|
|
@ -5134,6 +5158,7 @@ static void EnqueueGraphicsPipelineCompilation(const PipelineState& pipelineStat
|
||||||
#ifdef ASYNC_PSO_DEBUG
|
#ifdef ASYNC_PSO_DEBUG
|
||||||
queueItem.pipelineName = fmt::format("ASYNC {} {:X}", name, hash);
|
queueItem.pipelineName = fmt::format("ASYNC {} {:X}", name, hash);
|
||||||
#endif
|
#endif
|
||||||
|
queueItem.precompiledPipeline = g_pendingPipelineStateCache;
|
||||||
g_pipelineStateQueue.enqueue(queueItem);
|
g_pipelineStateQueue.enqueue(queueItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5748,8 +5773,10 @@ static std::atomic<uint32_t> g_pendingPipelineRecompilations;
|
||||||
static void ModelConsumerThread()
|
static void ModelConsumerThread()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE);
|
||||||
GuestThread::SetThreadName(GetCurrentThreadId(), "Model Consumer Thread");
|
GuestThread::SetThreadName(GetCurrentThreadId(), "Model Consumer Thread");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::vector<boost::shared_ptr<Hedgehog::Database::CDatabaseData>> localPendingDataQueue;
|
std::vector<boost::shared_ptr<Hedgehog::Database::CDatabaseData>> localPendingDataQueue;
|
||||||
std::unique_ptr<GuestThreadContext> ctx;
|
std::unique_ptr<GuestThreadContext> ctx;
|
||||||
|
|
||||||
|
|
@ -5849,9 +5876,6 @@ static void ModelConsumerThread()
|
||||||
|
|
||||||
g_pendingPipelineStateCache = false;
|
g_pendingPipelineStateCache = false;
|
||||||
--g_pendingDataCount;
|
--g_pendingDataCount;
|
||||||
|
|
||||||
if ((--g_compilingDataCount) == 0)
|
|
||||||
g_compilingDataCount.notify_all();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_pendingPipelineRecompilations != 0)
|
if (g_pendingPipelineRecompilations != 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue