虚幻4 编译Shader 5
发布时间
阅读量:
阅读量
解决上一个文档的问题,哪里相应了Shader编译完成的消息。
Engine 的LOOP里面调用了这个:
if (GShaderCompilingManager)
{
// Process any asynchronous shader compile results that are ready, limit execution time
QUICK_SCOPE_CYCLE_COUNTER(STAT_FEngineLoop_Tick_GShaderCompilingManager);
GShaderCompilingManager->ProcessAsyncResults(true, false);
}
ShaderCompilingManage管理了一个编译的线程,那个线程是用来和Worker通信的。
/** * Manager of asynchronous and parallel shader compilation.
* This class contains an interface to enqueue and retreive asynchronous shader jobs, and manages a FShaderCompileThreadRunnable.
*/
class FShaderCompilingManager
{
void FShaderCompilingManager::ProcessAsyncResults(bool bLimitExecutionTime, bool bBlockOnGlobalShaderCompletion)
{
if (bAllowAsynchronousShaderCompiling)
{
Thread->CheckHealth();
{
const double StartTime = FPlatformTime::Seconds();
// Block on global shaders before checking for shader maps to finalize
// So if we block on global shaders for a long time, we will get a chance to finalize all the non-global shader maps completed during that time.
if (bBlockOnGlobalShaderCompletion)
{
TArray<int32> ShaderMapId;
ShaderMapId.Add(GlobalShaderMapId);
// Block until the global shader map jobs are complete
GShaderCompilingManager->BlockOnShaderMapCompletion(ShaderMapId, PendingFinalizeShaderMaps);
}
int32 NumCompilingShaderMaps = 0;
{
// Lock CompileQueueSection so we can access the input and output queues
FScopeLock Lock(&CompileQueueSection);
if (!bBlockOnGlobalShaderCompletion)
{
bCompilingDuringGame = true;
}
TArray<int32> ShaderMapsToRemove;
for (TMap<int32, FShaderMapCompileResults>::TIterator It(ShaderMapJobs); It; ++It)
{
const FShaderMapCompileResults& Results = It.Value();
if (GetNumTotalJobs(Results.FinishedJobs) == Results.NumJobsQueued)
{
PendingFinalizeShaderMaps.Add(It.Key(), FShaderMapFinalizeResults(Results));
ShaderMapsToRemove.Add(It.Key());
}
}
for (int32 RemoveIndex = 0; RemoveIndex < ShaderMapsToRemove.Num(); RemoveIndex++)
{
ShaderMapJobs.Remove(ShaderMapsToRemove[RemoveIndex]);
}
NumCompilingShaderMaps = ShaderMapJobs.Num();
}
int32 NumPendingShaderMaps = PendingFinalizeShaderMaps.Num();
if (PendingFinalizeShaderMaps.Num() > 0)
{
bool bRetry = false;
do
{
bRetry = HandlePotentialRetryOnError(PendingFinalizeShaderMaps);
}
while (bRetry);
const float TimeBudget = bLimitExecutionTime ? ProcessGameThreadTargetTime : FLT_MAX;
ProcessCompiledShaderMaps(PendingFinalizeShaderMaps, TimeBudget);
check(bLimitExecutionTime || PendingFinalizeShaderMaps.Num() == 0);
}
if (bBlockOnGlobalShaderCompletion)
{
check(PendingFinalizeShaderMaps.Num() == 0);
if (NumPendingShaderMaps - PendingFinalizeShaderMaps.Num() > 0)
{
UE_LOG(LogShaders, Warning, TEXT("Blocking ProcessAsyncResults for %.1fs, processed %u shader maps, %u being compiled"),
(float)(FPlatformTime::Seconds() - StartTime),
NumPendingShaderMaps - PendingFinalizeShaderMaps.Num(),
NumCompilingShaderMaps);
}
}
else if (NumPendingShaderMaps - PendingFinalizeShaderMaps.Num() > 0)
{
UE_LOG(LogShaders, Log, TEXT("Completed %u async shader maps, %u more pending, %u being compiled"),
NumPendingShaderMaps - PendingFinalizeShaderMaps.Num(),
PendingFinalizeShaderMaps.Num(),
NumCompilingShaderMaps);
}
}
}
else
{
check(CompileQueue.Num() == 0);
}
}
中间可以看到ProcessCompiledShaderMaps,明显是编译完成Shader后会执行的代码。
全部评论 (0)
还没有任何评论哟~
