Files
UnrealEngineUWP/Engine/Source/Developer/DerivedDataCache/Private/HierarchicalDerivedDataBackend.h
Andrew Grant a572d8e23f Copying //UE4/Orion-Staging to //UE4/Main (Origin //Orion/Dev-General @ 2870388)
#lockdown Nick.Penwarden

==========================
MAJOR FEATURES + CHANGES
==========================

Change 2870336 on 2016/02/17 by Marc.Audy

	Continued splitting up Orion Build
	* Restructure from platform based MakeBuild steps in to a PS4, Server, and Windows Client MakeBuild
	* Cook server data only once for both Windows and Linux (windows reuses Linux server data)
	* Split compilation of Win64 Client and Server such that MakeBuild_Server only builds Server and MakeBuild_WindowsClient only builds Client
	#jira UEB-580
	#rb Ben.Marsh
	#tests Preflight and generated Windows Client and Server work to play game

Change 2870026 on 2016/02/17 by Wes.Hunt

	Don't allow array shrinking when removing the corruption wrapper trailer.
	#rb none
	Updating CIS Counter

Change 2869725 on 2016/02/17 by Dmitry.Rekman

	More analytics and QoS stats added for 0.19.

	#rb none
	#tests Ran Windows client and Linux server on compatible content.

Change 2869705 on 2016/02/16 by Ryan.Gerleve

	Fix replicated properties and call RepNotifies of startup actors when scrubbing in replays.
	This is the engine support for fixing OR-6817, towers not respawning when rewinding replays.

	#rb john.pollard
	#tests golden path, replays, ps4 nomcp

Change 2869644 on 2016/02/16 by Jason.Bestimt

	#ORION_DEV - Merge MAIN (0.18) at CL# 2869635

	#Tests:none
	#RB:none

Change 2869586 on 2016/02/16 by Marcus.Wassmer

	Fix texturestreaming RHI flushes.
	#rb none
	#test goldenpath
	#codereview Gil.Gribb

Change 2869279 on 2016/02/16 by Lukasz.Furman

	fixed minion hit reaction directions
	#orion OR-13953
	#rb Mieszko.Zielinski
	#tests PIE: hit minions with various abilities from different angles, checked velocity of death particles when killed by abilities and towers
	#codereview Dan.Youhon

Change 2869277 on 2016/02/16 by Wes.Hunt

	During cook, when a package is not ready to save, actually early out of the saving code. Saves somewhere in the 130s to 200s range for cooks.
	#rb daniel.lamb
	#tests local windows cooks, preflight PS4 cooks

Change 2869132 on 2016/02/16 by Mieszko.Zielinski

	Added a function to AISenseConfig allowing native-code MaxAge configuration #UE4

	#rb Lukasz.Furman
	#test none required

Change 2868981 on 2016/02/16 by Wes.Hunt

	remove -LogCookStats cmdline check, always log cook stats. -SendCookAnalytics flag is still used.
	This was requested by NickP.
	#rb none
	#tests local windows cooks

Change 2868975 on 2016/02/16 by Wes.Hunt

	Don't submit DDC usage stats for zero-sized events.
	#rb none
	#tests local windows cook

Change 2868956 on 2016/02/16 by Jason.Bestimt

	#ORION_DEV - Merge MAIN (0.18) at CL# 2868926

	#RB:none
	#Tests:none

Change 2868889 on 2016/02/16 by Max.Chen

	Sequencer: Only allow transport control binding when editing level editor sequencers.

	#rb none
	#tests none

Change 2868663 on 2016/02/16 by David.Ratti

	downgrade warning to display

	#rb none
	#tests compile

Change 2868624 on 2016/02/16 by Marcus.Wassmer

	Re-Enable Defrag validation for devgeneral
	#rb none
	#test none

Change 2868493 on 2016/02/16 by Benn.Gallagher

	Added a few more stats to morph target updates to try and narrow down hitches
	#rb Bruce.Nesbit
	#tests pie, -game Win64

Change 2868445 on 2016/02/16 by Dmitry.Rekman

	Linux: report crashes due to stack overflow (OR-14519).

	- Reserve memory for alternative stack for signal handlers. Adds about 128KB memory per thread.
	- Force process spawning to use vfork() when no pipes are needed.
	- Ignore all signals except explicitly handled.
	- Prevent signals from being raised while another one is handled.
	- Added "debug threadrecurse" and "debug threadstackoverflow" to test that.

[CL 2873763 by Andrew Grant in Main branch]
2016-02-19 12:03:17 -05:00

218 lines
7.3 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "DerivedDataCacheUsageStats.h"
/**
* A backend wrapper that implements a cache hierarchy of backends.
**/
class FHierarchicalDerivedDataBackend : public FDerivedDataBackendInterface
{
public:
/**
* Constructor
* @param InInnerBackends Backends to call into for actual storage of the cache, first item is the "fastest cache"
*/
FHierarchicalDerivedDataBackend(const TArray<FDerivedDataBackendInterface*>& InInnerBackends)
: InnerBackends(InInnerBackends)
, bIsWritable(false)
{
check(InnerBackends.Num() > 1); // if it is just one, then you don't need this wrapper
for (int32 CacheIndex = 0; CacheIndex < InnerBackends.Num(); CacheIndex++)
{
if (InnerBackends[CacheIndex]->IsWritable())
{
bIsWritable = true;
}
}
if (bIsWritable)
{
for (int32 CacheIndex = 0; CacheIndex < InnerBackends.Num(); CacheIndex++)
{
// async puts to allow us to fill all levels without holding up the engine
new (AsyncPutInnerBackends) TScopedPointer<FDerivedDataBackendInterface>(new FDerivedDataBackendAsyncPutWrapper(InnerBackends[CacheIndex], false));
}
}
}
/** Adds inner backend. */
void AddInnerBackend(FDerivedDataBackendInterface* InInner)
{
InnerBackends.Add(InInner);
}
/** Removes inner backend. */
bool RemoveInnerBackend(FDerivedDataBackendInterface* InInner)
{
const int32 NumRemoved = InnerBackends.Remove(InInner);
return NumRemoved != 0;
}
/** return true if this cache is writable **/
virtual bool IsWritable() override
{
return bIsWritable;
}
/**
* Synchronous test for the existence of a cache item
*
* @param CacheKey Alphanumeric+underscore key of this cache item
* @return true if the data probably will be found, this can't be guaranteed because of concurrency in the backends, corruption, etc
*/
virtual bool CachedDataProbablyExists(const TCHAR* CacheKey) override
{
COOK_STAT(auto Timer = UsageStats.TimeProbablyExists());
for (int32 CacheIndex = 0; CacheIndex < InnerBackends.Num(); CacheIndex++)
{
if (InnerBackends[CacheIndex]->CachedDataProbablyExists(CacheKey))
{
COOK_STAT(Timer.AddHit(0));
return true;
}
}
return false;
}
/**
* Synchronous retrieve of a cache item
*
* @param CacheKey Alphanumeric+underscore key of this cache item
* @param OutData Buffer to receive the results, if any were found
* @return true if any data was found, and in this case OutData is non-empty
*/
virtual bool GetCachedData(const TCHAR* CacheKey, TArray<uint8>& OutData) override
{
COOK_STAT(auto Timer = UsageStats.TimeGet());
for (int32 CacheIndex = 0; CacheIndex < InnerBackends.Num(); CacheIndex++)
{
if (InnerBackends[CacheIndex]->CachedDataProbablyExists(CacheKey) && InnerBackends[CacheIndex]->GetCachedData(CacheKey, OutData))
{
if (bIsWritable)
{
// fill in the higher level caches
for (int32 PutCacheIndex = CacheIndex - 1; PutCacheIndex >= 0; PutCacheIndex--)
{
if (InnerBackends[PutCacheIndex]->IsWritable())
{
if (InnerBackends[PutCacheIndex]->BackfillLowerCacheLevels() &&
InnerBackends[PutCacheIndex]->CachedDataProbablyExists(CacheKey))
{
InnerBackends[PutCacheIndex]->RemoveCachedData(CacheKey, /*bTransient=*/ false); // it apparently failed, so lets delete what is there
AsyncPutInnerBackends[PutCacheIndex]->PutCachedData(CacheKey, OutData, true); // we force a put here because it must have failed
}
else
{
AsyncPutInnerBackends[PutCacheIndex]->PutCachedData(CacheKey, OutData, false);
}
}
}
if (InnerBackends[CacheIndex]->BackfillLowerCacheLevels())
{
// fill in the lower level caches
for (int32 PutCacheIndex = CacheIndex + 1; PutCacheIndex < AsyncPutInnerBackends.Num(); PutCacheIndex++)
{
if (!InnerBackends[PutCacheIndex]->IsWritable() && !InnerBackends[PutCacheIndex]->BackfillLowerCacheLevels() && InnerBackends[PutCacheIndex]->CachedDataProbablyExists(CacheKey))
{
break; //do not write things that are already in the read only pak file
}
if (InnerBackends[PutCacheIndex]->IsWritable())
{
AsyncPutInnerBackends[PutCacheIndex]->PutCachedData(CacheKey, OutData, false); // we do not need to force a put here
}
}
}
}
COOK_STAT(Timer.AddHit(OutData.Num()));
return true;
}
}
return false;
}
/**
* Asynchronous, fire-and-forget placement of a cache item
*
* @param CacheKey Alphanumeric+underscore key of this cache item
* @param InData Buffer containing the data to cache, can be destroyed after the call returns, immediately
* @param bPutEvenIfExists If true, then do not attempt skip the put even if CachedDataProbablyExists returns true
*/
virtual void PutCachedData(const TCHAR* CacheKey, TArray<uint8>& InData, bool bPutEvenIfExists) override
{
COOK_STAT(auto Timer = UsageStats.TimePut());
if (!bIsWritable)
{
return; // no point in continuing down the chain
}
bool bSynchronousPutPeformed = false; // we must do at least one synchronous put to a writable cache before we return
for (int32 PutCacheIndex = 0; PutCacheIndex < InnerBackends.Num(); PutCacheIndex++)
{
if (!InnerBackends[PutCacheIndex]->IsWritable() && !InnerBackends[PutCacheIndex]->BackfillLowerCacheLevels() && InnerBackends[PutCacheIndex]->CachedDataProbablyExists(CacheKey))
{
break; //do not write things that are already in the read only pak file
}
if (InnerBackends[PutCacheIndex]->IsWritable())
{
COOK_STAT(Timer.AddHit(InData.Num()));
if (!bSynchronousPutPeformed)
{
InnerBackends[PutCacheIndex]->PutCachedData(CacheKey, InData, bPutEvenIfExists);
bSynchronousPutPeformed = true;
}
else
{
AsyncPutInnerBackends[PutCacheIndex]->PutCachedData(CacheKey, InData, bPutEvenIfExists);
}
}
}
}
virtual void RemoveCachedData(const TCHAR* CacheKey, bool bTransient) override
{
if (!bIsWritable)
{
return; // no point in continuing down the chain
}
for (int32 PutCacheIndex = 0; PutCacheIndex < InnerBackends.Num(); PutCacheIndex++)
{
InnerBackends[PutCacheIndex]->RemoveCachedData(CacheKey, bTransient);
}
}
virtual void GatherUsageStats(TMap<FString, FDerivedDataCacheUsageStats>& UsageStatsMap, FString&& GraphPath) override
{
COOK_STAT(
{
UsageStatsMap.Add(GraphPath + TEXT(": Hierarchical"), UsageStats);
// All the inner backends are actually wrapped by AsyncPut backends in writable cases (most cases in practice)
if (AsyncPutInnerBackends.Num() > 0)
{
int Ndx = 0;
for (const auto& InnerBackend : AsyncPutInnerBackends)
{
InnerBackend->GatherUsageStats(UsageStatsMap, GraphPath + FString::Printf(TEXT(".%2d"), Ndx++));
}
}
else
{
int Ndx = 0;
for (auto InnerBackend : InnerBackends)
{
InnerBackend->GatherUsageStats(UsageStatsMap, GraphPath + FString::Printf(TEXT(".%2d"), Ndx++));
}
}
});
}
private:
FDerivedDataCacheUsageStats UsageStats;
/** Array of backends forming the hierarchical cache...the first element is the fastest cache. **/
TArray<FDerivedDataBackendInterface*> InnerBackends;
/** Each of the backends wrapped with an async put **/
TArray<TScopedPointer<FDerivedDataBackendInterface> > AsyncPutInnerBackends;
/** As an optimization, we check our writable status at contruction **/
bool bIsWritable;
};