Merge branch '1.5' into dotnet7

This commit is contained in:
Wojciech Figat
2022-12-21 10:35:58 +01:00
330 changed files with 3405 additions and 1555 deletions

View File

@@ -314,6 +314,17 @@ bool Asset::ShouldDeleteFileOnUnload() const
#endif
uint64 Asset::GetMemoryUsage() const
{
uint64 result = sizeof(Asset);
Locker.Lock();
if (_loadingTask)
result += sizeof(ContentLoadTask);
result += (OnLoaded.Capacity() + OnReloading.Capacity() + OnUnloaded.Capacity()) * sizeof(EventType::FunctionType);
Locker.Unlock();
return result;
}
void Asset::Reload()
{
// Virtual assets are memory-only so reloading them makes no sense

View File

@@ -128,14 +128,17 @@ public:
}
#if USE_EDITOR
/// <summary>
/// Determines whether this asset was marked to be deleted on unload.
/// </summary>
API_PROPERTY() bool ShouldDeleteFileOnUnload() const;
#endif
/// <summary>
/// Gets amount of CPU memory used by this resource (in bytes). It's a rough estimation. Memory may be fragmented, compressed or sub-allocated so the actual memory pressure from this resource may vary.
/// </summary>
API_PROPERTY() virtual uint64 GetMemoryUsage() const;
public:
/// <summary>
/// Reloads the asset.
@@ -160,7 +163,6 @@ public:
virtual void CancelStreaming();
#if USE_EDITOR
/// <summary>
/// Gets the asset references. Supported only in Editor.
/// </summary>
@@ -184,7 +186,6 @@ public:
/// </remarks>
/// <returns>The collection of the asset ids referenced by this asset.</returns>
API_FUNCTION() Array<Guid, HeapAllocation> GetReferences() const;
#endif
/// <summary>

View File

@@ -54,8 +54,5 @@ public:
/// Gets the string.
/// </summary>
/// <returns>The string.</returns>
String ToString() const
{
return String::Format(TEXT("ID: {0}, TypeName: {1}, Path: \'{2}\'"), ID, TypeName, Path);
}
String ToString() const;
};

View File

@@ -569,6 +569,23 @@ void Animation::OnSkinnedModelUnloaded(Asset* obj)
MappingCache.Remove(i);
}
uint64 Animation::GetMemoryUsage() const
{
Locker.Lock();
uint64 result = BinaryAsset::GetMemoryUsage();
result += sizeof(Animation) - sizeof(BinaryAsset);
result += Data.GetMemoryUsage();
result += Events.Capacity() * sizeof(Pair<String, StepCurve<AnimEventData>>);
for (const auto& e : Events)
result += e.First.Length() * sizeof(Char) + e.Second.GetMemoryUsage();
result += NestedAnims.Capacity() * sizeof(Pair<String, NestedAnimData>);
result += MappingCache.Capacity() * sizeof(Pair<String, StepCurve<AnimEventData>>);
for (const auto& e : MappingCache)
result += e.Value.Capacity() * sizeof(int32);
Locker.Unlock();
return result;
}
void Animation::OnScriptingDispose()
{
// Dispose any events to prevent crashes (scripting is released before content)

View File

@@ -152,7 +152,6 @@ public:
const NodeToChannel* GetMapping(SkinnedModel* obj);
#if USE_EDITOR
/// <summary>
/// Gets the animation as serialized timeline data. Used to show it in Editor.
/// </summary>
@@ -173,7 +172,6 @@ public:
/// <remarks>The cannot be used by virtual assets.</remarks>
/// <returns><c>true</c> failed to save data; otherwise, <c>false</c>.</returns>
bool Save(const StringView& path = StringView::Empty);
#endif
private:
@@ -181,6 +179,7 @@ private:
public:
// [BinaryAsset]
uint64 GetMemoryUsage() const override;
void OnScriptingDispose() override;
protected:

View File

@@ -482,7 +482,7 @@ void Material::InitCompilationOptions(ShaderCompilationOptions& options)
options.Macros.Add({ "MATERIAL_TESSELLATION", "MATERIAL_TESSELLATION_PHONG" });
break;
}
options.Macros.Add({ "MAX_TESSELLATION_FACTOR", Numbers[info.MaxTessellationFactor] });
options.Macros.Add({ "MAX_TESSELLATION_FACTOR", Numbers[Math::Min<int32>(info.MaxTessellationFactor, ARRAY_COUNT(Numbers) - 1)] });
}
// Helper macros (used by the parser)

View File

@@ -722,6 +722,7 @@ bool Model::Init(const Span<int32>& meshesCountPerLod)
{
auto& lod = LODs[lodIndex];
lod._model = this;
lod._lodIndex = lodIndex;
lod.ScreenSize = 1.0f;
const int32 meshesCount = meshesCountPerLod[lodIndex];
if (meshesCount <= 0 || meshesCount > MODEL_MAX_MESHES)
@@ -922,6 +923,7 @@ Asset::LoadResult Model::load()
{
auto& lod = LODs[lodIndex];
lod._model = this;
lod._lodIndex = lodIndex;
// Screen Size
stream->ReadFloat(&lod.ScreenSize);
@@ -977,7 +979,13 @@ Asset::LoadResult Model::load()
ModelSDFHeader data;
sdfStream.ReadBytes(&data, sizeof(data));
if (!SDF.Texture)
SDF.Texture = GPUTexture::New();
{
String name;
#if !BUILD_RELEASE
name = GetPath() + TEXT(".SDF");
#endif
SDF.Texture = GPUDevice::Instance->CreateTexture(name);
}
if (SDF.Texture->Init(GPUTextureDescription::New3D(data.Width, data.Height, data.Depth, data.Format, GPUTextureFlags::ShaderResource, data.MipLevels)))
return LoadResult::Failed;
SDF.LocalToUVWMul = data.LocalToUVWMul;

View File

@@ -64,6 +64,16 @@ bool RawDataAsset::Save(const StringView& path)
#endif
uint64 RawDataAsset::GetMemoryUsage() const
{
Locker.Lock();
uint64 result = BinaryAsset::GetMemoryUsage();
result += sizeof(RawDataAsset) - sizeof(BinaryAsset);
result += Data.Count();
Locker.Unlock();
return result;
}
Asset::LoadResult RawDataAsset::load()
{
auto chunk0 = GetChunk(0);

View File

@@ -28,6 +28,10 @@ public:
#endif
public:
// [BinaryAsset]
uint64 GetMemoryUsage() const override;
protected:
// [BinaryAsset]
LoadResult load() override;

View File

@@ -452,6 +452,22 @@ const String& BinaryAsset::GetPath() const
#endif
}
uint64 BinaryAsset::GetMemoryUsage() const
{
Locker.Lock();
uint64 result = Asset::GetMemoryUsage();
result += sizeof(BinaryAsset) - sizeof(Asset);
result += _dependantAssets.Capacity() * sizeof(BinaryAsset*);
for (int32 i = 0; i < ASSET_FILE_DATA_CHUNKS; i++)
{
auto chunk = _header.Chunks[i];
if (chunk != nullptr && chunk->IsLoaded())
result += chunk->Size();
}
Locker.Unlock();
return result;
}
/// <summary>
/// Helper task used to initialize binary asset and upgrade it if need to in background.
/// </summary>

View File

@@ -41,7 +41,6 @@ public:
FlaxStorage* Storage;
#if USE_EDITOR
/// <summary>
/// The asset metadata information. Stored in a Json format.
/// </summary>
@@ -51,14 +50,12 @@ public:
/// Asset dependencies list used by the asset for tracking (eg. material functions used by material asset). The pair of asset ID and cached file edit time (for tracking modification).
/// </summary>
Array<Pair<Guid, DateTime>> Dependencies;
#endif
public:
/// <summary>
/// Gets the asset serialized version.
/// </summary>
/// <returns>Version number.</returns>
virtual uint32 GetSerializedVersion() const = 0;
/// <summary>
@@ -84,14 +81,11 @@ public:
public:
#if USE_EDITOR
#if COMPILE_WITH_ASSETS_IMPORTER
/// <summary>
/// Reimports asset from the source file.
/// </summary>
API_FUNCTION() void Reimport() const;
#endif
/// <summary>
@@ -130,7 +124,6 @@ protected:
virtual void OnDependencyModified(BinaryAsset* asset)
{
}
#endif
protected:
@@ -255,7 +248,6 @@ public:
bool LoadChunks(AssetChunksFlag chunks);
#if USE_EDITOR
/// <summary>
/// Saves this asset to the storage container.
/// </summary>
@@ -281,7 +273,6 @@ public:
/// <param name="silentMode">In silent mode don't reload opened storage container that is using target file.</param>
/// <returns>True if failed, otherwise false.</returns>
static bool SaveToAsset(const StringView& path, AssetInitData& data, bool silentMode = false);
#endif
protected:
@@ -302,6 +293,7 @@ public:
void OnDeleteObject() override;
#endif
const String& GetPath() const final override;
uint64 GetMemoryUsage() const override;
protected:
// [Asset]

View File

@@ -34,6 +34,11 @@ TimeSpan Content::AssetsUnloadInterval = TimeSpan::FromSeconds(10);
Delegate<Asset*> Content::AssetDisposing;
Delegate<Asset*> Content::AssetReloading;
String AssetInfo::ToString() const
{
return String::Format(TEXT("ID: {0}, TypeName: {1}, Path: \'{2}\'"), ID, TypeName, Path);
}
namespace
{
// Assets

View File

@@ -93,6 +93,17 @@ const String& JsonAssetBase::GetPath() const
#endif
}
uint64 JsonAssetBase::GetMemoryUsage() const
{
Locker.Lock();
uint64 result = Asset::GetMemoryUsage();
result += sizeof(JsonAssetBase) - sizeof(Asset);
if (Data)
result += Document.GetAllocator().Capacity();
Locker.Unlock();
return result;
}
#if USE_EDITOR
void FindIds(ISerializable::DeserializeStream& node, Array<Guid>& output)
@@ -248,6 +259,17 @@ JsonAsset::JsonAsset(const SpawnParams& params, const AssetInfo* info)
{
}
uint64 JsonAsset::GetMemoryUsage() const
{
Locker.Lock();
uint64 result = JsonAssetBase::GetMemoryUsage();
result += sizeof(JsonAsset) - sizeof(JsonAssetBase);
if (Instance && InstanceType)
result += InstanceType.GetType().Size;
Locker.Unlock();
return result;
}
Asset::LoadResult JsonAsset::loadAsset()
{
const auto result = JsonAssetBase::loadAsset();

View File

@@ -77,6 +77,7 @@ public:
public:
// [Asset]
const String& GetPath() const override;
uint64 GetMemoryUsage() const override;
#if USE_EDITOR
void GetReferences(Array<Guid, HeapAllocation>& output) const override;
#endif
@@ -122,6 +123,10 @@ public:
return Instance && InstanceType.IsAssignableFrom(T::TypeInitializer) ? (T*)Instance : nullptr;
}
public:
// [JsonAssetBase]
uint64 GetMemoryUsage() const override;
protected:
// [JsonAssetBase]
LoadResult loadAsset() override;

View File

@@ -3,7 +3,6 @@
#pragma once
#include "Engine/Threading/Task.h"
#include "Engine/Core/Types/String.h"
class Asset;
class LoadingThread;
@@ -46,7 +45,6 @@ public:
/// <summary>
/// Gets a task type.
/// </summary>
/// <returns>The type.</returns>
FORCE_INLINE Type GetType() const
{
return _type;
@@ -68,13 +66,7 @@ protected:
public:
// [Task]
String ToString() const override
{
return String::Format(TEXT("Content Load Task {0} ({1})"),
ToString(GetType()),
::ToString(GetState())
);
}
String ToString() const override;
protected:
// [Task]

View File

@@ -211,6 +211,11 @@ void ContentLoadingManagerService::Dispose()
Tasks.CancelAll();
}
String ContentLoadTask::ToString() const
{
return String::Format(TEXT("Content Load Task {0} ({1})"), ToString(GetType()), (int32)GetState());
}
void ContentLoadTask::Enqueue()
{
Tasks.Add(this);

View File

@@ -0,0 +1,18 @@
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Core/Types/Guid.h"
/// <summary>
/// Represents the reference to the scene asset. Stores the unique ID of the scene to reference. Can be used to load the selected scene.
/// </summary>
API_STRUCT(NoDefault) struct FLAXENGINE_API SceneReference
{
DECLARE_SCRIPTING_TYPE_STRUCTURE(SceneReference);
/// <summary>
/// The identifier of the scene asset (and the scene object).
/// </summary>
API_FIELD() Guid ID;
};