Optimize C++ compilation time
This commit is contained in:
@@ -18,8 +18,7 @@ public:
|
||||
/// <summary>
|
||||
/// Gets the texture owner mutex used to synchronize texture logic.
|
||||
/// </summary>
|
||||
/// <returns>The mutex.</returns>
|
||||
virtual CriticalSection* GetOwnerLocker() const = 0;
|
||||
virtual CriticalSection& GetOwnerLocker() const = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Get texture mip map data
|
||||
|
||||
@@ -33,6 +33,23 @@ StreamingTexture::~StreamingTexture()
|
||||
ASSERT(_streamingTasksCount == 0);
|
||||
}
|
||||
|
||||
Vector2 StreamingTexture::Size() const
|
||||
{
|
||||
return _texture->Size();
|
||||
}
|
||||
|
||||
int32 StreamingTexture::TextureMipIndexToTotalIndex(int32 textureMipIndex) const
|
||||
{
|
||||
const int32 missingMips = TotalMipLevels() - _texture->MipLevels();
|
||||
return textureMipIndex + missingMips;
|
||||
}
|
||||
|
||||
int32 StreamingTexture::TotalIndexToTextureMipIndex(int32 mipIndex) const
|
||||
{
|
||||
const int32 missingMips = TotalMipLevels() - _texture->MipLevels();
|
||||
return mipIndex - missingMips;
|
||||
}
|
||||
|
||||
bool StreamingTexture::Create(const TextureHeader& header)
|
||||
{
|
||||
// Validate header (further validation is performed by the Texture.Init)
|
||||
@@ -90,13 +107,27 @@ uint64 StreamingTexture::GetTotalMemoryUsage() const
|
||||
return CalculateTextureMemoryUsage(_header.Format, _header.Width, _header.Height, _header.MipLevels) * arraySize;
|
||||
}
|
||||
|
||||
String StreamingTexture::ToString() const
|
||||
{
|
||||
return _texture->ToString();
|
||||
}
|
||||
|
||||
int32 StreamingTexture::GetCurrentResidency() const
|
||||
{
|
||||
return _texture->ResidentMipLevels();
|
||||
}
|
||||
|
||||
int32 StreamingTexture::GetAllocatedResidency() const
|
||||
{
|
||||
return _texture->MipLevels();
|
||||
}
|
||||
|
||||
bool StreamingTexture::CanBeUpdated() const
|
||||
{
|
||||
// Streaming Texture cannot be updated if:
|
||||
// - is not initialized
|
||||
// - mip data uploading job running
|
||||
// - resize texture job running
|
||||
|
||||
return IsInitialized() && Platform::AtomicRead(&_streamingTasksCount) == 0;
|
||||
}
|
||||
|
||||
@@ -146,7 +177,6 @@ protected:
|
||||
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
void OnEnd() override
|
||||
{
|
||||
Platform::InterlockedDecrement(&_streamingTexture->_streamingTasksCount);
|
||||
@@ -154,7 +184,6 @@ protected:
|
||||
// Base
|
||||
GPUTask::OnEnd();
|
||||
}
|
||||
|
||||
void OnSync() override
|
||||
{
|
||||
Swap(_streamingTexture->_texture, _newTexture);
|
||||
@@ -298,7 +327,6 @@ protected:
|
||||
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
void OnEnd() override
|
||||
{
|
||||
_dataLock.Release();
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GPUTexture.h"
|
||||
#include "ITextureOwner.h"
|
||||
#include "Engine/Streaming/StreamableResource.h"
|
||||
#include "Types.h"
|
||||
@@ -14,7 +13,6 @@ class FLAXENGINE_API StreamingTexture : public Object, public StreamableResource
|
||||
{
|
||||
friend class StreamTextureMipTask;
|
||||
friend class StreamTextureResizeTask;
|
||||
|
||||
protected:
|
||||
|
||||
ITextureOwner* _owner;
|
||||
@@ -25,16 +23,7 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Init
|
||||
/// </summary>
|
||||
/// <param name="owner">Parent object</param>
|
||||
/// <param name="name">Texture object name</param>
|
||||
StreamingTexture(ITextureOwner* owner, const String& name);
|
||||
|
||||
/// <summary>
|
||||
/// Destructor
|
||||
/// </summary>
|
||||
~StreamingTexture();
|
||||
|
||||
public:
|
||||
@@ -42,31 +31,23 @@ public:
|
||||
/// <summary>
|
||||
/// Gets the owner.
|
||||
/// </summary>
|
||||
/// <returns>The owner.</returns>
|
||||
FORCE_INLINE ITextureOwner* GetOwner() const
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets texture object handle
|
||||
/// Gets texture object handle.
|
||||
/// </summary>
|
||||
/// <returns>Texture object</returns>
|
||||
FORCE_INLINE GPUTexture* GetTexture() const
|
||||
{
|
||||
return _texture;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets texture size of Vector2::Zero if not loaded
|
||||
/// Gets texture size of Vector2::Zero if not loaded.
|
||||
/// </summary>
|
||||
/// <returns>Texture size</returns>
|
||||
FORCE_INLINE Vector2 Size() const
|
||||
{
|
||||
return _texture->Size();
|
||||
}
|
||||
|
||||
public:
|
||||
Vector2 Size() const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this instance is initialized.
|
||||
@@ -88,7 +69,6 @@ public:
|
||||
/// <summary>
|
||||
/// Gets total texture height (in texels)
|
||||
/// </summary>
|
||||
/// <returns>Texture width</returns>
|
||||
FORCE_INLINE int32 TotalHeight() const
|
||||
{
|
||||
return _header.Height;
|
||||
@@ -97,7 +77,6 @@ public:
|
||||
/// <summary>
|
||||
/// Gets total texture array size
|
||||
/// </summary>
|
||||
/// <returns>Texture array size</returns>
|
||||
FORCE_INLINE int32 TotalArraySize() const
|
||||
{
|
||||
return IsCubeMap() ? 6 : 1;
|
||||
@@ -106,7 +85,6 @@ public:
|
||||
/// <summary>
|
||||
/// Gets total texture mip levels count
|
||||
/// </summary>
|
||||
/// <returns>Texture mip levels</returns>
|
||||
FORCE_INLINE int32 TotalMipLevels() const
|
||||
{
|
||||
return _header.MipLevels;
|
||||
@@ -115,7 +93,6 @@ public:
|
||||
/// <summary>
|
||||
/// Returns texture format type
|
||||
/// </summary>
|
||||
/// <returns>Texture format type</returns>
|
||||
FORCE_INLINE TextureFormatType GetFormatType() const
|
||||
{
|
||||
return _header.Type;
|
||||
@@ -124,7 +101,6 @@ public:
|
||||
/// <summary>
|
||||
/// Returns true if it's a cube map texture
|
||||
/// </summary>
|
||||
/// <returns>True if i's a cubemap</returns>
|
||||
FORCE_INLINE bool IsCubeMap() const
|
||||
{
|
||||
return _header.IsCubeMap;
|
||||
@@ -133,7 +109,6 @@ public:
|
||||
/// <summary>
|
||||
/// Returns true if texture cannot be used during GPU resources streaming system
|
||||
/// </summary>
|
||||
/// <returns>True if texture cannot be used during GPU resources streaming system</returns>
|
||||
FORCE_INLINE bool NeverStream() const
|
||||
{
|
||||
return _header.NeverStream;
|
||||
@@ -142,7 +117,6 @@ public:
|
||||
/// <summary>
|
||||
/// Gets the texture header.
|
||||
/// </summary>
|
||||
/// <returns>Header</returns>
|
||||
FORCE_INLINE const TextureHeader* GetHeader() const
|
||||
{
|
||||
return &_header;
|
||||
@@ -163,22 +137,14 @@ public:
|
||||
/// </summary>
|
||||
/// <param name="textureMipIndex">Index of the texture mip.</param>
|
||||
/// <returns>The index of the mip map.</returns>
|
||||
FORCE_INLINE int32 TextureMipIndexToTotalIndex(int32 textureMipIndex) const
|
||||
{
|
||||
const int32 missingMips = TotalMipLevels() - _texture->MipLevels();
|
||||
return textureMipIndex + missingMips;
|
||||
}
|
||||
int32 TextureMipIndexToTotalIndex(int32 textureMipIndex) const;
|
||||
|
||||
/// <summary>
|
||||
/// Converts absolute mip map index to the allocated texture mip index.
|
||||
/// </summary>
|
||||
/// <param name="mipIndex">Index of the texture mip.</param>
|
||||
/// <returns>The index of the mip map.</returns>
|
||||
FORCE_INLINE int32 TotalIndexToTextureMipIndex(int32 mipIndex) const
|
||||
{
|
||||
const int32 missingMips = TotalMipLevels() - _texture->MipLevels();
|
||||
return mipIndex - missingMips;
|
||||
}
|
||||
int32 TotalIndexToTextureMipIndex(int32 mipIndex) const;
|
||||
|
||||
public:
|
||||
|
||||
@@ -211,27 +177,15 @@ public:
|
||||
public:
|
||||
|
||||
// [Object]
|
||||
String ToString() const override
|
||||
{
|
||||
return _texture->ToString();
|
||||
}
|
||||
String ToString() const override;
|
||||
|
||||
// [StreamableResource]
|
||||
int32 GetMaxResidency() const override
|
||||
{
|
||||
return _header.MipLevels;
|
||||
}
|
||||
|
||||
int32 GetCurrentResidency() const override
|
||||
{
|
||||
return _texture->ResidentMipLevels();
|
||||
}
|
||||
|
||||
int32 GetAllocatedResidency() const override
|
||||
{
|
||||
return _texture->MipLevels();
|
||||
}
|
||||
|
||||
int32 GetCurrentResidency() const override;
|
||||
int32 GetAllocatedResidency() const override;
|
||||
bool CanBeUpdated() const override;
|
||||
Task* UpdateAllocation(int32 residency) override;
|
||||
Task* CreateStreamingTask(int32 residency) override;
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
#include "TextureBase.h"
|
||||
#include "TextureData.h"
|
||||
#include "Engine/Graphics/GPUDevice.h"
|
||||
#include "Engine/Debug/Exceptions/ArgumentOutOfRangeException.h"
|
||||
#include "Engine/Debug/Exceptions/InvalidOperationException.h"
|
||||
#include "Engine/Graphics/Textures/GPUTexture.h"
|
||||
#include "Engine/Graphics/RenderTools.h"
|
||||
#include "Engine/Graphics/PixelFormatExtensions.h"
|
||||
#include "Engine/Debug/Exceptions/ArgumentOutOfRangeException.h"
|
||||
#include "Engine/Debug/Exceptions/InvalidOperationException.h"
|
||||
#include "Engine/Core/Math/Color32.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Content/Factories/BinaryAssetFactory.h"
|
||||
@@ -22,6 +23,36 @@ TextureBase::TextureBase(const SpawnParams& params, const AssetInfo* info)
|
||||
{
|
||||
}
|
||||
|
||||
Vector2 TextureBase::Size() const
|
||||
{
|
||||
return Vector2(static_cast<float>(_texture.TotalWidth()), static_cast<float>(_texture.TotalHeight()));
|
||||
}
|
||||
|
||||
int32 TextureBase::GetArraySize() const
|
||||
{
|
||||
return StreamingTexture()->TotalArraySize();
|
||||
}
|
||||
|
||||
int32 TextureBase::GetMipLevels() const
|
||||
{
|
||||
return StreamingTexture()->TotalMipLevels();
|
||||
}
|
||||
|
||||
int32 TextureBase::GetResidentMipLevels() const
|
||||
{
|
||||
return GetTexture()->ResidentMipLevels();
|
||||
}
|
||||
|
||||
uint64 TextureBase::GetCurrentMemoryUsage() const
|
||||
{
|
||||
return GetTexture()->GetMemoryUsage();
|
||||
}
|
||||
|
||||
uint64 TextureBase::GetTotalMemoryUsage() const
|
||||
{
|
||||
return StreamingTexture()->GetTotalMemoryUsage();
|
||||
}
|
||||
|
||||
BytesContainer TextureBase::GetMipData(int32 mipIndex, int32& rowPitch, int32& slicePitch)
|
||||
{
|
||||
BytesContainer result;
|
||||
@@ -193,9 +224,9 @@ int32 TextureBase::calculateChunkIndex(int32 mipIndex) const
|
||||
return mipIndex;
|
||||
}
|
||||
|
||||
CriticalSection* TextureBase::GetOwnerLocker() const
|
||||
CriticalSection& TextureBase::GetOwnerLocker() const
|
||||
{
|
||||
return &_parent->Locker;
|
||||
return _parent->Locker;
|
||||
}
|
||||
|
||||
void TextureBase::unload(bool isReloading)
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "StreamingTexture.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
|
||||
class TextureData;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for <see cref="Texture"/>, <see cref="SpriteAtlas"/>, <see cref="IESProfile"/> and other assets that can contain texture data.
|
||||
/// </summary>
|
||||
@@ -103,50 +105,32 @@ public:
|
||||
/// <summary>
|
||||
/// Gets the total size of the texture. Actual resident size may be different due to dynamic content streaming. Returns Vector2::Zero if texture is not loaded.
|
||||
/// </summary>
|
||||
API_PROPERTY() FORCE_INLINE Vector2 Size() const
|
||||
{
|
||||
return Vector2(static_cast<float>(_texture.TotalWidth()), static_cast<float>(_texture.TotalHeight()));
|
||||
}
|
||||
API_PROPERTY() Vector2 Size() const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total array size of the texture.
|
||||
/// </summary>
|
||||
API_PROPERTY() int32 GetArraySize() const
|
||||
{
|
||||
return StreamingTexture()->TotalArraySize();
|
||||
}
|
||||
API_PROPERTY() int32 GetArraySize() const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total mip levels count of the texture. Actual resident mipmaps count may be different due to dynamic content streaming.
|
||||
/// </summary>
|
||||
API_PROPERTY() int32 GetMipLevels() const
|
||||
{
|
||||
return StreamingTexture()->TotalMipLevels();
|
||||
}
|
||||
API_PROPERTY() int32 GetMipLevels() const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current mip levels count of the texture that are on GPU ready to use.
|
||||
/// </summary>
|
||||
API_PROPERTY() int32 GetResidentMipLevels() const
|
||||
{
|
||||
return GetTexture()->ResidentMipLevels();
|
||||
}
|
||||
API_PROPERTY() int32 GetResidentMipLevels() const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount of the memory used by this resource. Exact value may differ due to memory alignment and resource allocation policy.
|
||||
/// </summary>
|
||||
API_PROPERTY() uint64 GetCurrentMemoryUsage() const
|
||||
{
|
||||
return GetTexture()->GetMemoryUsage();
|
||||
}
|
||||
API_PROPERTY() uint64 GetCurrentMemoryUsage() const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total memory usage that texture may have in use (if loaded to the maximum quality). Exact value may differ due to memory alignment and resource allocation policy.
|
||||
/// </summary>
|
||||
API_PROPERTY() uint64 GetTotalMemoryUsage() const
|
||||
{
|
||||
return StreamingTexture()->GetTotalMemoryUsage();
|
||||
}
|
||||
API_PROPERTY() uint64 GetTotalMemoryUsage() const;
|
||||
|
||||
public:
|
||||
|
||||
@@ -186,7 +170,7 @@ private:
|
||||
public:
|
||||
|
||||
// [ITextureOwner]
|
||||
CriticalSection* GetOwnerLocker() const override;
|
||||
CriticalSection& GetOwnerLocker() const override;
|
||||
Task* RequestMipDataAsync(int32 mipIndex) override;
|
||||
FlaxStorage::LockData LockData() override;
|
||||
void GetMipData(int32 mipIndex, BytesContainer& data) const override;
|
||||
|
||||
Reference in New Issue
Block a user