Refactor Streaming with new settings and textures streaming configuration
This commit is contained in:
@@ -9,6 +9,38 @@
|
||||
#include "Engine/Graphics/RenderTools.h"
|
||||
#include "Engine/Graphics/Async/Tasks/GPUUploadTextureMipTask.h"
|
||||
|
||||
TextureHeader_Deprecated::TextureHeader_Deprecated()
|
||||
{
|
||||
Platform::MemoryClear(this, sizeof(*this));
|
||||
}
|
||||
|
||||
TextureHeader::TextureHeader()
|
||||
{
|
||||
Platform::MemoryClear(this, sizeof(*this));
|
||||
TextureGroup = -1;
|
||||
}
|
||||
|
||||
TextureHeader::TextureHeader(TextureHeader_Deprecated& old)
|
||||
{
|
||||
Platform::MemoryClear(this, sizeof(*this));
|
||||
Width = old.Width;;
|
||||
Height = old.Height;
|
||||
MipLevels = old.MipLevels;
|
||||
Format = old.Format;
|
||||
Type = old.Type;
|
||||
if (old.IsCubeMap)
|
||||
IsCubeMap = 1;
|
||||
if (old.IsSRGB)
|
||||
IsSRGB = 1;
|
||||
if (old.NeverStream)
|
||||
NeverStream = 1;
|
||||
TextureGroup = -1;
|
||||
Platform::MemoryCopy(CustomData, old.CustomData, sizeof(CustomData));
|
||||
}
|
||||
|
||||
static_assert(sizeof(TextureHeader_Deprecated) == 10 * sizeof(int32), "Invalid TextureHeader size.");
|
||||
static_assert(sizeof(TextureHeader) == 36, "Invalid TextureHeader size.");
|
||||
|
||||
StreamingTexture::StreamingTexture(ITextureOwner* parent, const String& name)
|
||||
: StreamableResource(StreamingGroups::Instance()->Textures())
|
||||
, _owner(parent)
|
||||
@@ -112,6 +144,11 @@ String StreamingTexture::ToString() const
|
||||
return _texture->ToString();
|
||||
}
|
||||
|
||||
int32 StreamingTexture::GetMaxResidency() const
|
||||
{
|
||||
return _header.MipLevels;
|
||||
}
|
||||
|
||||
int32 StreamingTexture::GetCurrentResidency() const
|
||||
{
|
||||
return _texture->ResidentMipLevels();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "Types.h"
|
||||
|
||||
/// <summary>
|
||||
/// GPU texture object which can change it's resolution (quality) at runtime
|
||||
/// GPU texture object which can change it's resolution (quality) at runtime.
|
||||
/// </summary>
|
||||
class FLAXENGINE_API StreamingTexture : public Object, public StreamableResource
|
||||
{
|
||||
@@ -180,10 +180,7 @@ public:
|
||||
String ToString() const override;
|
||||
|
||||
// [StreamableResource]
|
||||
int32 GetMaxResidency() const override
|
||||
{
|
||||
return _header.MipLevels;
|
||||
}
|
||||
int32 GetMaxResidency() const override;
|
||||
int32 GetCurrentResidency() const override;
|
||||
int32 GetAllocatedResidency() const override;
|
||||
bool CanBeUpdated() const override;
|
||||
|
||||
@@ -29,27 +29,27 @@ Vector2 TextureBase::Size() const
|
||||
|
||||
int32 TextureBase::GetArraySize() const
|
||||
{
|
||||
return StreamingTexture()->TotalArraySize();
|
||||
return _texture.TotalArraySize();
|
||||
}
|
||||
|
||||
int32 TextureBase::GetMipLevels() const
|
||||
{
|
||||
return StreamingTexture()->TotalMipLevels();
|
||||
return _texture.TotalMipLevels();
|
||||
}
|
||||
|
||||
int32 TextureBase::GetResidentMipLevels() const
|
||||
{
|
||||
return GetTexture()->ResidentMipLevels();
|
||||
return _texture.GetTexture()->ResidentMipLevels();
|
||||
}
|
||||
|
||||
uint64 TextureBase::GetCurrentMemoryUsage() const
|
||||
{
|
||||
return GetTexture()->GetMemoryUsage();
|
||||
return _texture.GetTexture()->GetMemoryUsage();
|
||||
}
|
||||
|
||||
uint64 TextureBase::GetTotalMemoryUsage() const
|
||||
{
|
||||
return StreamingTexture()->GetTotalMemoryUsage();
|
||||
return _texture.GetTotalMemoryUsage();
|
||||
}
|
||||
|
||||
BytesContainer TextureBase::GetMipData(int32 mipIndex, int32& rowPitch, int32& slicePitch)
|
||||
@@ -166,16 +166,15 @@ bool TextureBase::Init(InitData* initData)
|
||||
_customData = initData;
|
||||
|
||||
// Create texture
|
||||
TextureHeader header;
|
||||
header.Format = initData->Format;
|
||||
header.Width = initData->Width;
|
||||
header.Height = initData->Height;
|
||||
header.IsCubeMap = initData->ArraySize == 6;
|
||||
header.MipLevels = initData->Mips.Count();
|
||||
header.IsSRGB = false;
|
||||
header.Type = TextureFormatType::ColorRGBA;
|
||||
header.NeverStream = true;
|
||||
if (_texture.Create(header))
|
||||
TextureHeader textureHeader;
|
||||
textureHeader.Format = initData->Format;
|
||||
textureHeader.Width = initData->Width;
|
||||
textureHeader.Height = initData->Height;
|
||||
textureHeader.IsCubeMap = initData->ArraySize == 6;
|
||||
textureHeader.MipLevels = initData->Mips.Count();
|
||||
textureHeader.Type = TextureFormatType::ColorRGBA;
|
||||
textureHeader.NeverStream = true;
|
||||
if (_texture.Create(textureHeader))
|
||||
{
|
||||
LOG(Warning, "Cannot initialize texture.");
|
||||
return true;
|
||||
@@ -289,6 +288,41 @@ bool TextureBase::GetMipDataCustomPitch(int32 mipIndex, uint32& rowPitch, uint32
|
||||
return result;
|
||||
}
|
||||
|
||||
bool TextureBase::init(AssetInitData& initData)
|
||||
{
|
||||
if (IsVirtual())
|
||||
return false;
|
||||
if (initData.SerializedVersion != TexturesSerializedVersion)
|
||||
{
|
||||
LOG(Error, "Invalid serialized texture version.");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get texture header for asset custom data (fast access)
|
||||
TextureHeader textureHeader;
|
||||
if (initData.CustomData.Length() == sizeof(TextureHeader))
|
||||
{
|
||||
Platform::MemoryCopy(&textureHeader, initData.CustomData.Get(), sizeof(textureHeader));
|
||||
}
|
||||
else if (initData.CustomData.Length() == sizeof(TextureHeader_Deprecated))
|
||||
{
|
||||
textureHeader = TextureHeader(*(TextureHeader_Deprecated*)initData.CustomData.Get());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(Error, "Missing texture header.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return _texture.Create(textureHeader);
|
||||
}
|
||||
|
||||
Asset::LoadResult TextureBase::load()
|
||||
{
|
||||
// Loading textures is very fast xD
|
||||
return LoadResult::Ok;
|
||||
}
|
||||
|
||||
bool TextureBase::InitData::GenerateMip(int32 mipIndex, bool linear)
|
||||
{
|
||||
// Validate input
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "Engine/Content/BinaryAsset.h"
|
||||
#include "StreamingTexture.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
|
||||
class TextureData;
|
||||
|
||||
@@ -15,12 +14,8 @@ class TextureData;
|
||||
API_CLASS(Abstract, NoSpawn) class FLAXENGINE_API TextureBase : public BinaryAsset, public ITextureOwner
|
||||
{
|
||||
DECLARE_ASSET_HEADER(TextureBase);
|
||||
public:
|
||||
|
||||
static const uint32 TexturesSerializedVersion = 4;
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// The texture init data (external source).
|
||||
/// </summary>
|
||||
@@ -180,43 +175,7 @@ public:
|
||||
protected:
|
||||
|
||||
// [BinaryAsset]
|
||||
bool init(AssetInitData& initData) override
|
||||
{
|
||||
// Skip for virtual assets
|
||||
if (IsVirtual())
|
||||
return false;
|
||||
|
||||
// Validate
|
||||
if (initData.SerializedVersion != 4)
|
||||
{
|
||||
LOG(Error, "Invalid serialized texture version.");
|
||||
return true;
|
||||
}
|
||||
if (initData.CustomData.Length() != sizeof(TextureHeader))
|
||||
{
|
||||
LOG(Error, "Missing texture header.");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Load header
|
||||
TextureHeader header;
|
||||
Platform::MemoryCopy(&header, initData.CustomData.Get(), sizeof(TextureHeader));
|
||||
|
||||
// Create texture
|
||||
if (_texture.Create(header))
|
||||
{
|
||||
LOG(Error, "Cannot initialize texture.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
LoadResult load() override
|
||||
{
|
||||
// Loading textures is very fast xD
|
||||
return LoadResult::Ok;
|
||||
}
|
||||
|
||||
bool init(AssetInitData& initData) override;
|
||||
LoadResult load() override;
|
||||
void unload(bool isReloading) override;
|
||||
};
|
||||
|
||||
@@ -12,25 +12,53 @@
|
||||
DECLARE_ENUM_EX_7(TextureFormatType, byte, 0, Unknown, ColorRGB, ColorRGBA, NormalMap, GrayScale, HdrRGBA, HdrRGB);
|
||||
|
||||
/// <summary>
|
||||
/// Texture header structure
|
||||
/// Old texture header structure (was not fully initialized to zero).
|
||||
/// </summary>
|
||||
struct TextureHeader_Deprecated
|
||||
{
|
||||
int32 Width;
|
||||
int32 Height;
|
||||
int32 MipLevels;
|
||||
PixelFormat Format;
|
||||
TextureFormatType Type;
|
||||
bool IsCubeMap;
|
||||
bool NeverStream;
|
||||
bool IsSRGB;
|
||||
byte CustomData[17];
|
||||
|
||||
TextureHeader_Deprecated();
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Texture header structure.
|
||||
/// </summary>
|
||||
struct FLAXENGINE_API TextureHeader
|
||||
{
|
||||
/// <summary>
|
||||
/// Top mip width in pixels
|
||||
/// Width in pixels
|
||||
/// </summary>
|
||||
int32 Width;
|
||||
|
||||
/// <summary>
|
||||
/// Top mip height in pixels
|
||||
/// Height in pixels
|
||||
/// </summary>
|
||||
int32 Height;
|
||||
|
||||
/// <summary>
|
||||
/// Depth in pixels
|
||||
/// </summary>
|
||||
int32 Depth;
|
||||
|
||||
/// <summary>
|
||||
/// Amount of mip levels
|
||||
/// </summary>
|
||||
int32 MipLevels;
|
||||
|
||||
/// <summary>
|
||||
/// Texture group for streaming (negative if unused).
|
||||
/// </summary>
|
||||
int32 TextureGroup;
|
||||
|
||||
/// <summary>
|
||||
/// Texture pixels format
|
||||
/// </summary>
|
||||
@@ -44,22 +72,23 @@ struct FLAXENGINE_API TextureHeader
|
||||
/// <summary>
|
||||
/// True if texture is a cubemap (has 6 array slices per mip).
|
||||
/// </summary>
|
||||
bool IsCubeMap;
|
||||
|
||||
/// <summary>
|
||||
/// True if disable dynamic texture streaming
|
||||
/// </summary>
|
||||
bool NeverStream;
|
||||
byte IsCubeMap : 1;
|
||||
|
||||
/// <summary>
|
||||
/// True if texture contains sRGB colors data
|
||||
/// </summary>
|
||||
bool IsSRGB;
|
||||
byte IsSRGB : 1;
|
||||
|
||||
/// <summary>
|
||||
/// True if disable dynamic texture streaming
|
||||
/// </summary>
|
||||
byte NeverStream : 1;
|
||||
|
||||
/// <summary>
|
||||
/// The custom data to be used per texture storage layer (faster access).
|
||||
/// </summary>
|
||||
byte CustomData[17];
|
||||
};
|
||||
byte CustomData[10];
|
||||
|
||||
static_assert(sizeof(TextureHeader) == 10 * sizeof(int32), "Invalid TextureHeader size.");
|
||||
TextureHeader();
|
||||
TextureHeader(TextureHeader_Deprecated& old);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user