// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
#pragma once
#if COMPILE_WITH_SHADER_CACHE_MANAGER
#include "../Config.h"
#include "Engine/Serialization/MemoryWriteStream.h"
#include "Engine/Platform/FileSystem.h"
#include "Engine/Core/Types/DataContainer.h"
#include "Engine/Core/Types/String.h"
#include "Engine/Core/Types/Guid.h"
#include "Engine/Core/Types/DateTime.h"
///
/// Shaders cache manager.
///
class ShaderCacheManager
{
public:
struct CachedEntryHandle
{
Guid ID = Guid::Empty;
String Path;
bool IsValid() const;
bool Exists() const;
DateTime GetModificationDate() const;
};
public:
///
/// Tries to get cached shader entry for a given shader
///
/// Shader Profile
/// Shader ID
/// Result entry if success
/// False if cannot get it, otherwise true
static bool TryGetEntry(const ShaderProfile profile, const Guid& id, CachedEntryHandle& cachedEntry);
///
/// Gets shader cache
///
/// Shader Profile
/// Cached entry handle
/// Output data
/// True if cannot set cache data, otherwise false
static bool GetCache(const ShaderProfile profile, const CachedEntryHandle& cachedEntry, BytesContainer& outputShaderCache);
///
/// Sets shader cache
///
/// Shader Profile
/// Cached entry handle
/// Input data
/// True if cannot set cache data, otherwise false
static bool SetCache(const ShaderProfile profile, const CachedEntryHandle& cachedEntry, MemoryWriteStream& inputShaderCache);
///
/// Removes shader cache.
///
/// Shader Profile
/// Shader ID
static void RemoveCache(const ShaderProfile profile, const Guid& id);
///
/// Removes shader cache.
///
/// Shader ID
static void RemoveCache(const Guid& id);
///
/// Copies shader cache.
///
/// Destination shader ID
/// Source shader ID
static void CopyCache(const Guid& dstId, const Guid& srcId);
};
#endif