Pipeline strategy (#72)

* Attempt to aid the driver when creating ubershader pipelines.

* Second attempt.

* Missing include.

* Change the index in the condition.
This commit is contained in:
Darío 2024-08-08 00:06:14 -03:00 committed by GitHub
parent b91d6a7441
commit 8e8588df56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 2 deletions

View File

@ -531,9 +531,28 @@ namespace RT64 {
} }
void RasterShaderUber::threadCreatePipelines(uint32_t threadIndex) { void RasterShaderUber::threadCreatePipelines(uint32_t threadIndex) {
// Delay the creation of all other pipelines until the first pipeline is created. This can help the
// driver reuse its shader cache between pipelines and achieve a much lower creation time than if
// all threads started at the same time.
if (threadIndex > 0) {
std::unique_lock<std::mutex> lock(firstPipelineMutex);
firstPipelineCondition.wait(lock, [this]() {
return (pipelines[0] != nullptr);
});
}
for (const PipelineCreation &creation : pipelineThreadCreations[threadIndex]) { for (const PipelineCreation &creation : pipelineThreadCreations[threadIndex]) {
uint32_t pipelineIndex = pipelineStateIndex(creation.zCmp, creation.zUpd, creation.cvgAdd); uint32_t pipelineIndex = pipelineStateIndex(creation.zCmp, creation.zUpd, creation.cvgAdd);
pipelines[pipelineIndex] = RasterShader::createPipeline(creation);
if (pipelineIndex == 0) {
firstPipelineMutex.lock();
pipelines[pipelineIndex] = RasterShader::createPipeline(creation);
firstPipelineMutex.unlock();
firstPipelineCondition.notify_all();
}
else {
pipelines[pipelineIndex] = RasterShader::createPipeline(creation);
}
} }
} }

View File

@ -6,6 +6,7 @@
#include "rt64_shader_common.h" #include "rt64_shader_common.h"
#include <condition_variable>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
@ -78,7 +79,8 @@ namespace RT64 {
std::unique_ptr<RenderPipeline> pipelines[8]; std::unique_ptr<RenderPipeline> pipelines[8];
std::unique_ptr<RenderPipeline> postBlendDitherNoiseAddPipeline; std::unique_ptr<RenderPipeline> postBlendDitherNoiseAddPipeline;
std::unique_ptr<RenderPipeline> postBlendDitherNoiseSubPipeline; std::unique_ptr<RenderPipeline> postBlendDitherNoiseSubPipeline;
std::mutex pipelinesMutex; std::mutex firstPipelineMutex;
std::condition_variable firstPipelineCondition;
bool pipelinesCreated = false; bool pipelinesCreated = false;
std::unique_ptr<RenderPipelineLayout> pipelineLayout; std::unique_ptr<RenderPipelineLayout> pipelineLayout;
std::vector<std::vector<PipelineCreation>> pipelineThreadCreations; std::vector<std::vector<PipelineCreation>> pipelineThreadCreations;
@ -88,6 +90,7 @@ namespace RT64 {
RasterShaderUber(RenderDevice *device, RenderShaderFormat shaderFormat, const RenderMultisampling &multisampling, const ShaderLibrary *shaderLibrary, uint32_t threadCount); RasterShaderUber(RenderDevice *device, RenderShaderFormat shaderFormat, const RenderMultisampling &multisampling, const ShaderLibrary *shaderLibrary, uint32_t threadCount);
~RasterShaderUber(); ~RasterShaderUber();
void threadCreatePipeline(const PipelineCreation &creation);
void threadCreatePipelines(uint32_t threadIndex); void threadCreatePipelines(uint32_t threadIndex);
void waitForPipelineCreation(); void waitForPipelineCreation();
uint32_t pipelineStateIndex(bool zCmp, bool zUpd, bool cvgAdd) const; uint32_t pipelineStateIndex(bool zCmp, bool zUpd, bool cvgAdd) const;