void FShaderType::Initialize(const TMap<FString, TArray<const TCHAR*> >& ShaderFileToUniformBufferVariables) { if (!FPlatformProperties::RequiresCookedData()) { for(TLinkedList<FShaderType*>::TIterator It(FShaderType::GetTypeList()); It; It.Next()) { FShaderType* Type = *It; GenerateReferencedUniformBuffers(Type->SourceFilename, Type->Name, ShaderFileToUniformBufferVariables, Type->ReferencedUniformBufferStructsCache); // Cache serialization history for each shader type // This history is used to detect when shader serialization changes without a corresponding .usf change { // Construct a temporary shader, which is initialized to safe values for serialization FShader* TempShader = Type->ConstructForDeserialization(); check(TempShader != NULL); TempShader->Type = Type; // Serialize the temp shader to memory and record the number and sizes of serializations TArray<uint8> TempData; FMemoryWriter Ar(TempData, true); FShaderSaveArchive SaveArchive(Ar, Type->SerializationHistory); TempShader->SerializeBase(SaveArchive, false); // Destroy the temporary shader delete TempShader; } } } bInitializedSerializationHistory = true; }
TArray<FShaderType*> FShaderType::GetShaderTypesByFilename(const TCHAR* Filename) { TArray<FShaderType*> OutShaders; for(TLinkedList<FShaderType*>::TIterator It(GetTypeList()); It; It.Next()) { FShaderType* Type = *It; if (FPlatformString::Strcmp(Filename, Type->GetShaderFilename()) == 0) { OutShaders.Add(Type); } } return OutShaders; }
FShaderType* FShaderType::GetShaderTypeByName(const TCHAR* Name) { for(TLinkedList<FShaderType*>::TIterator It(GetTypeList()); It; It.Next()) { FShaderType* Type = *It; if (FPlatformString::Strcmp(Name, Type->GetName()) == 0) { return Type; } } return NULL; }
void FShaderType::GetOutdatedTypes(TArray<FShaderType*>& OutdatedShaderTypes, TArray<const FVertexFactoryType*>& OutdatedFactoryTypes) { for(TLinkedList<FShaderType*>::TIterator It(GetTypeList()); It; It.Next()) { FShaderType* Type = *It; Type->GetOutdatedCurrentType(OutdatedShaderTypes, OutdatedFactoryTypes); } for (int32 TypeIndex = 0; TypeIndex < OutdatedShaderTypes.Num(); TypeIndex++) { UE_LOG(LogShaders, Warning, TEXT(" Recompiling %s"), OutdatedShaderTypes[TypeIndex]->GetName()); } for (int32 TypeIndex = 0; TypeIndex < OutdatedFactoryTypes.Num(); TypeIndex++) { UE_LOG(LogShaders, Warning, TEXT(" Recompiling %s"), OutdatedFactoryTypes[TypeIndex]->GetName()); } }
void FShaderType::GetOutdatedTypes(TArray<FShaderType*>& OutdatedShaderTypes, TArray<const FVertexFactoryType*>& OutdatedFactoryTypes) { for(TLinkedList<FShaderType*>::TIterator It(GetTypeList()); It; It.Next()) { FShaderType* Type = *It; for(TMap<FShaderId,FShader*>::TConstIterator ShaderIt(Type->ShaderIdMap);ShaderIt;++ShaderIt) { FShader* Shader = ShaderIt.Value(); const FVertexFactoryParameterRef* VFParameterRef = Shader->GetVertexFactoryParameterRef(); const FSHAHash& SavedHash = Shader->GetHash(); const FSHAHash& CurrentHash = Type->GetSourceHash(); const bool bOutdatedShader = SavedHash != CurrentHash; const bool bOutdatedVertexFactory = VFParameterRef && VFParameterRef->GetVertexFactoryType() && VFParameterRef->GetVertexFactoryType()->GetSourceHash() != VFParameterRef->GetHash(); if (bOutdatedShader) { OutdatedShaderTypes.AddUnique(Shader->Type); } if (bOutdatedVertexFactory) { OutdatedFactoryTypes.AddUnique(VFParameterRef->GetVertexFactoryType()); } } } for (int32 TypeIndex = 0; TypeIndex < OutdatedShaderTypes.Num(); TypeIndex++) { UE_LOG(LogShaders, Warning, TEXT(" Recompiling %s"), OutdatedShaderTypes[TypeIndex]->GetName()); } for (int32 TypeIndex = 0; TypeIndex < OutdatedFactoryTypes.Num(); TypeIndex++) { UE_LOG(LogShaders, Warning, TEXT(" Recompiling %s"), OutdatedFactoryTypes[TypeIndex]->GetName()); } }
/** Clears and optionally backs up all references to renderer module classes in other modules, particularly engine. */ void ClearReferencesToRendererModuleClasses( TMap<UWorld*, bool>& WorldsToUpdate, TMap<FMaterialShaderMap*, TScopedPointer<TArray<uint8> > >& ShaderMapToSerializedShaderData, TScopedPointer<TArray<uint8> >& GlobalShaderData, TMap<FShaderType*, FString>& ShaderTypeNames, TMap<FVertexFactoryType*, FString>& VertexFactoryTypeNames) { // Destroy all renderer scenes for (TObjectIterator<UWorld> WorldIt; WorldIt; ++WorldIt) { UWorld* World = *WorldIt; if (World->Scene) { WorldsToUpdate.Add(World, World->FXSystem != NULL); for (int32 LevelIndex = 0; LevelIndex < World->GetNumLevels(); LevelIndex++) { ULevel* Level = World->GetLevel(LevelIndex); Level->ReleaseRenderingResources(); } if (World->FXSystem != NULL) { FFXSystemInterface::Destroy(World->FXSystem); World->FXSystem = NULL; } World->Scene->Release(); World->Scene = NULL; } } // Save off shaders by serializing them into memory, and remove all shader map references to FShaders GlobalShaderData = TScopedPointer<TArray<uint8> >(BackupGlobalShaderMap(GRHIShaderPlatform_DEPRECATED)); UMaterial::BackupMaterialShadersToMemory(ShaderMapToSerializedShaderData); // Verify no FShaders still in memory for(TLinkedList<FShaderType*>::TIterator It(FShaderType::GetTypeList()); It; It.Next()) { FShaderType* ShaderType = *It; check(ShaderType->GetNumShaders() == 0); ShaderTypeNames.Add(ShaderType, ShaderType->GetName()); } for(TLinkedList<FVertexFactoryType*>::TIterator It(FVertexFactoryType::GetTypeList()); It; It.Next()) { FVertexFactoryType* VertexFactoryType = *It; VertexFactoryTypeNames.Add(VertexFactoryType, VertexFactoryType->GetName()); } // Destroy misc renderer module classes and remove references FSceneViewStateReference::DestroyAll(); FSlateApplication::Get().InvalidateAllViewports(); // Invalidate cached shader type data UninitializeShaderTypes(); // Delete pending cleanup objects to remove those references, which are potentially renderer module classes FPendingCleanupObjects* PendingCleanupObjects = GetPendingCleanupObjects(); delete PendingCleanupObjects; GEngine->EngineLoop->ClearPendingCleanupObjects(); ResetCachedRendererModule(); }