2016-12-08 08:52:44 -05:00
|
|
|
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
2015-06-10 03:14:50 -04:00
|
|
|
|
|
|
|
|
#pragma once
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
|
#include "UObject/NameTypes.h"
|
|
|
|
|
#include "Delegates/Delegate.h"
|
|
|
|
|
#include "UObject/ObjectMacros.h"
|
|
|
|
|
#include "UObject/WeakObjectPtr.h"
|
|
|
|
|
#include "UObject/Object.h"
|
2015-06-29 21:12:06 -04:00
|
|
|
#include "RuntimeAssetCacheInterface.generated.h"
|
2015-06-10 03:14:50 -04:00
|
|
|
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
class IRuntimeAssetCacheBuilder;
|
|
|
|
|
|
2015-06-10 03:14:50 -04:00
|
|
|
/** Forward declarations */
|
2015-06-19 03:13:33 -04:00
|
|
|
class IRuntimeAssetCacheBuilder;
|
2015-06-10 03:14:50 -04:00
|
|
|
|
2015-06-29 21:12:06 -04:00
|
|
|
/**
|
|
|
|
|
* Useful for passing around void* data and size
|
|
|
|
|
*/
|
|
|
|
|
USTRUCT()
|
|
|
|
|
struct FVoidPtrParam
|
|
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
FVoidPtrParam(void* InData, int64 InDataSize)
|
|
|
|
|
: Data(InData)
|
|
|
|
|
, DataSize(InDataSize)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
FVoidPtrParam()
|
|
|
|
|
: Data(nullptr)
|
|
|
|
|
, DataSize(0)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
static FVoidPtrParam NullPtr()
|
|
|
|
|
{
|
|
|
|
|
return FVoidPtrParam();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FORCEINLINE bool operator!() const
|
|
|
|
|
{
|
|
|
|
|
return (!Data || DataSize <= 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FORCEINLINE operator bool() const
|
|
|
|
|
{
|
|
|
|
|
return (Data && DataSize > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void* Data;
|
|
|
|
|
int64 DataSize;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-06-29 23:13:34 -04:00
|
|
|
/** Delegates. */
|
|
|
|
|
DECLARE_DYNAMIC_DELEGATE_TwoParams(FOnRuntimeAssetCacheAsyncComplete, int32, Handle, FVoidPtrParam, Data);
|
|
|
|
|
|
2015-06-10 03:14:50 -04:00
|
|
|
/**
|
|
|
|
|
* Interface for the Runtime Asset Cache. Cache is split into buckets to cache various assets separately.
|
|
|
|
|
* Bucket names and maximum sizes are configure via Engine.ini config file using the following syntax
|
|
|
|
|
* [RuntimeAssetCache]
|
|
|
|
|
* +BucketConfigs=(Name="<Plugin name>", Size=<Maximum bucket size in bytes>)
|
|
|
|
|
* This API is fully thread safe.
|
|
|
|
|
**/
|
|
|
|
|
class FRuntimeAssetCacheInterface
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Synchronously gets value from cache. If value is not found, builds entry using CacheBuilder and updates cache.
|
|
|
|
|
* @param CacheBuilder Builder to produce cache key and in the event of a miss.
|
2015-06-19 03:13:33 -04:00
|
|
|
* @return Pointer to retrieved cache entry, nullptr on fail. Fail occurs only when
|
|
|
|
|
* - there's no entry in cache and CacheBuilder is nullptr or
|
|
|
|
|
* - CacheBuilder returned nullptr
|
2015-06-10 03:14:50 -04:00
|
|
|
**/
|
2015-06-29 21:12:06 -04:00
|
|
|
virtual FVoidPtrParam GetSynchronous(IRuntimeAssetCacheBuilder* CacheBuilder) = 0;
|
2015-06-19 03:13:33 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Asynchronously checks the cache. If value is not found, builds entry using CacheBuilder and updates cache.
|
|
|
|
|
* @param CacheBuilder Builder to produce cache key and in the event of a miss, return the data.
|
|
|
|
|
* @param OnCompletionDelegate Delegate to call when cache is ready. Delegate is called on main thread.
|
|
|
|
|
* @return Handle to worker.
|
|
|
|
|
**/
|
|
|
|
|
virtual int32 GetAsynchronous(IRuntimeAssetCacheBuilder* CacheBuilder, const FOnRuntimeAssetCacheAsyncComplete& OnCompletionDelegate) = 0;
|
2015-06-10 03:14:50 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Asynchronously checks the cache. If value is not found, builds entry using CacheBuilder and updates cache.
|
|
|
|
|
* @param CacheBuilder Builder to produce cache key and in the event of a miss, return the data.
|
|
|
|
|
* @return Handle to worker.
|
|
|
|
|
**/
|
2015-06-19 03:13:33 -04:00
|
|
|
virtual int32 GetAsynchronous(IRuntimeAssetCacheBuilder* CacheBuilder) = 0;
|
2015-06-10 03:14:50 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets cache size.
|
|
|
|
|
* @param Bucket to check.
|
|
|
|
|
* @return Maximum allowed bucket size.
|
|
|
|
|
**/
|
|
|
|
|
virtual int32 GetCacheSize(FName Bucket) const = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes all cache entries.
|
|
|
|
|
* @return true if cache was successfully cleaned.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool ClearCache() = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes all cache from given bucket.
|
|
|
|
|
* @param Bucket Bucket to clean.
|
|
|
|
|
* @return true if cache was successfully cleaned.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool ClearCache(FName Bucket) = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Waits until worker finishes execution.
|
|
|
|
|
* @param Handle Worker handle to wait for.
|
|
|
|
|
*/
|
2015-06-19 03:13:33 -04:00
|
|
|
virtual void WaitAsynchronousCompletion(int32 Handle) = 0;
|
2015-06-10 03:14:50 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets asynchronous query results.
|
|
|
|
|
* @param Handle Worker handle to check.
|
2015-06-19 03:13:33 -04:00
|
|
|
* @return Pointer to retrieved cache entry, nullptr on fail. Fail occurs only when
|
|
|
|
|
* - there's no entry in cache and CacheBuilder is nullptr or
|
|
|
|
|
* - CacheBuilder returned nullptr
|
2015-06-10 03:14:50 -04:00
|
|
|
*/
|
2015-06-29 21:12:06 -04:00
|
|
|
virtual FVoidPtrParam GetAsynchronousResults(int32 Handle) = 0;
|
2015-06-10 03:14:50 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if worker finished execution.
|
|
|
|
|
* @param Handle Worker handle to check.
|
|
|
|
|
* @return True if execution finished, false otherwise.
|
|
|
|
|
*/
|
2015-06-19 03:13:33 -04:00
|
|
|
virtual bool PollAsynchronousCompletion(int32 Handle) = 0;
|
2015-06-10 03:14:50 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds a number from the thread safe counter which tracks outstanding async requests. This is used to ensure everything is complete prior to shutdown.
|
|
|
|
|
* @param Value to add to counter. Can be negative.
|
|
|
|
|
*/
|
|
|
|
|
virtual void AddToAsyncCompletionCounter(int32 Addend) = 0;
|
2015-06-19 03:13:33 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ticks async thread.
|
|
|
|
|
*/
|
|
|
|
|
virtual void Tick() = 0;
|
2015-06-10 03:14:50 -04:00
|
|
|
};
|