Fix some engine API to be exposed for C++ scripting

This commit is contained in:
Wojtek Figat
2021-09-04 18:07:08 +02:00
parent 53022ff013
commit e1d9fbb742
11 changed files with 44 additions and 59 deletions

View File

@@ -36,7 +36,7 @@ bool PreviewsCache::FlushTask::Run()
return true; return true;
} }
auto mipData = _data.GetData(0, 0); auto mipData = _data.GetData(0, 0);
ASSERT(mipData->DepthPitch == CalculateTextureMemoryUsage(_cache->GetTexture()->Format(), _cache->Width(), _cache->Height(), 1)); ASSERT(mipData->DepthPitch == RenderTools::CalculateTextureMemoryUsage(_cache->GetTexture()->Format(), _cache->Width(), _cache->Height(), 1));
ScopeLock lock(_cache->Locker); ScopeLock lock(_cache->Locker);
@@ -250,7 +250,7 @@ CreateAssetResult PreviewsCache::create(CreateAssetContext& context)
context.Data.CustomData.Copy(&textureHeader); context.Data.CustomData.Copy(&textureHeader);
// Create blank image (chunk 0) // Create blank image (chunk 0)
uint64 imageSize = CalculateTextureMemoryUsage(ASSETS_ICONS_ATLAS_FORMAT, ASSETS_ICONS_ATLAS_SIZE, ASSETS_ICONS_ATLAS_SIZE, 1); uint64 imageSize = RenderTools::CalculateTextureMemoryUsage(ASSETS_ICONS_ATLAS_FORMAT, ASSETS_ICONS_ATLAS_SIZE, ASSETS_ICONS_ATLAS_SIZE, 1);
ASSERT(imageSize <= MAX_int32); ASSERT(imageSize <= MAX_int32);
if (context.AllocateChunk(0)) if (context.AllocateChunk(0))
return CreateAssetResult::CannotAllocateChunk; return CreateAssetResult::CannotAllocateChunk;

View File

@@ -10,7 +10,7 @@
/// <summary> /// <summary>
/// Foliage instanced mesh instance. Packed data with very little of logic. Managed by the foliage chunks and foliage actor itself. /// Foliage instanced mesh instance. Packed data with very little of logic. Managed by the foliage chunks and foliage actor itself.
/// </summary> /// </summary>
API_STRUCT(NoPod) struct FoliageInstance API_STRUCT(NoPod) struct FLAXENGINE_API FoliageInstance
{ {
DECLARE_SCRIPTING_TYPE_NO_SPAWN(FoliageInstance); DECLARE_SCRIPTING_TYPE_NO_SPAWN(FoliageInstance);

View File

@@ -395,6 +395,35 @@ void RenderTools::UpdateModelLODTransition(byte& lodTransition)
lodTransition = static_cast<byte>(Math::Min<int32>(newProgress, 255)); lodTransition = static_cast<byte>(Math::Min<int32>(newProgress, 255));
} }
uint64 RenderTools::CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 mipLevels)
{
uint64 result = 0;
if (mipLevels == 0)
mipLevels = 69;
uint32 rowPitch, slicePitch;
while (mipLevels > 0 && (width >= 1 || height >= 1))
{
ComputePitch(format, width, height, rowPitch, slicePitch);
result += slicePitch;
if (width > 1)
width >>= 1;
if (height > 1)
height >>= 1;
mipLevels--;
}
return result;
}
uint64 RenderTools::CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 depth, int32 mipLevels)
{
return CalculateTextureMemoryUsage(format, width, height, mipLevels) * depth;
}
float RenderTools::ComputeBoundsScreenRadiusSquared(const Vector3& origin, float radius, const Vector3& viewOrigin, const Matrix& projectionMatrix) float RenderTools::ComputeBoundsScreenRadiusSquared(const Vector3& origin, float radius, const Vector3& viewOrigin, const Matrix& projectionMatrix)
{ {
const float screenMultiple = 0.5f * Math::Max(projectionMatrix.Values[0][0], projectionMatrix.Values[1][1]); const float screenMultiple = 0.5f * Math::Max(projectionMatrix.Values[0][0], projectionMatrix.Values[1][1]);
@@ -452,35 +481,6 @@ int32 RenderTools::ComputeSkinnedModelLOD(const SkinnedModel* model, const Vecto
return 0; return 0;
} }
uint64 CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 mipLevels)
{
uint64 result = 0;
if (mipLevels == 0)
mipLevels = 69;
uint32 rowPitch, slicePitch;
while (mipLevels > 0 && (width >= 1 || height >= 1))
{
RenderTools::ComputePitch(format, width, height, rowPitch, slicePitch);
result += slicePitch;
if (width > 1)
width >>= 1;
if (height > 1)
height >>= 1;
mipLevels--;
}
return result;
}
uint64 CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 depth, int32 mipLevels)
{
return CalculateTextureMemoryUsage(format, width, height, mipLevels) * depth;
}
int32 MipLevelsCount(int32 width, bool useMipLevels) int32 MipLevelsCount(int32 width, bool useMipLevels)
{ {
if (!useMipLevels) if (!useMipLevels)

View File

@@ -18,7 +18,7 @@ PACK_STRUCT(struct QuadShaderData
/// <summary> /// <summary>
/// Set of utilities for rendering. /// Set of utilities for rendering.
/// </summary> /// </summary>
API_CLASS(Static) class RenderTools API_CLASS(Static) class FLAXENGINE_API RenderTools
{ {
DECLARE_SCRIPTING_TYPE_NO_SPAWN(RenderTools); DECLARE_SCRIPTING_TYPE_NO_SPAWN(RenderTools);
public: public:
@@ -56,6 +56,8 @@ public:
public: public:
static void UpdateModelLODTransition(byte& lodTransition); static void UpdateModelLODTransition(byte& lodTransition);
static uint64 CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 mipLevels);
static uint64 CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 depth, int32 mipLevels);
/// <summary> /// <summary>
/// Computes the bounds screen radius squared. /// Computes the bounds screen radius squared.
@@ -110,23 +112,6 @@ public:
} }
}; };
// Get texture memory usage
// @param format Surface pixels format type
// @param width Width in pixels
// @param height Height in pixels
// @param mipLevels Amount of mip levels
// @returns Memory usage in bytes
extern uint64 CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 mipLevels);
// Get texture memory usage
// @param format Surface pixels format type
// @param width Width in pixels
// @param height Height in pixels
// @param depth Depth in pixels
// @param mipLevels Amount of mip levels
// @returns Memory usage in bytes
extern uint64 CalculateTextureMemoryUsage(PixelFormat format, int32 width, int32 height, int32 depth, int32 mipLevels);
// Calculate mip levels count for a texture 1D // Calculate mip levels count for a texture 1D
// @param width Most detailed mip width // @param width Most detailed mip width
// @param useMipLevels True if use mip levels, otherwise false (use only 1 mip) // @param useMipLevels True if use mip levels, otherwise false (use only 1 mip)

View File

@@ -561,7 +561,7 @@ bool GPUTexture::Resize(int32 width, int32 height, int32 depth)
uint64 GPUTexture::calculateMemoryUsage() const uint64 GPUTexture::calculateMemoryUsage() const
{ {
return CalculateTextureMemoryUsage(Format(), Width(), Height(), Depth(), MipLevels()) * ArraySize(); return RenderTools::CalculateTextureMemoryUsage(Format(), Width(), Height(), Depth(), MipLevels()) * ArraySize();
} }
String GPUTexture::ToString() const String GPUTexture::ToString() const

View File

@@ -144,7 +144,7 @@ void StreamingTexture::UnloadTexture()
uint64 StreamingTexture::GetTotalMemoryUsage() const uint64 StreamingTexture::GetTotalMemoryUsage() const
{ {
const uint64 arraySize = _header.IsCubeMap ? 6 : 1; const uint64 arraySize = _header.IsCubeMap ? 6 : 1;
return CalculateTextureMemoryUsage(_header.Format, _header.Width, _header.Height, _header.MipLevels) * arraySize; return RenderTools::CalculateTextureMemoryUsage(_header.Format, _header.Width, _header.Height, _header.MipLevels) * arraySize;
} }
String StreamingTexture::ToString() const String StreamingTexture::ToString() const

View File

@@ -231,9 +231,9 @@ bool GPUSwapChainDX11::Resize(int32 width, int32 height)
_width = width; _width = width;
_height = height; _height = height;
#if PLATFORM_WINDOWS #if PLATFORM_WINDOWS
_memoryUsage = CalculateTextureMemoryUsage(RenderToolsDX::ToPixelFormat(swapChainDesc.BufferDesc.Format), _width, _height, 1) * swapChainDesc.BufferCount; _memoryUsage = RenderTools::CalculateTextureMemoryUsage(RenderToolsDX::ToPixelFormat(swapChainDesc.BufferDesc.Format), _width, _height, 1) * swapChainDesc.BufferCount;
#else #else
_memoryUsage = CalculateTextureMemoryUsage(RenderToolsDX::ToPixelFormat(swapChainDesc.Format), _width, _height, 1) * swapChainDesc.BufferCount; _memoryUsage = RenderTools::CalculateTextureMemoryUsage(RenderToolsDX::ToPixelFormat(swapChainDesc.Format), _width, _height, 1) * swapChainDesc.BufferCount;
#endif #endif
getBackBuffer(); getBackBuffer();

View File

@@ -231,7 +231,7 @@ bool GPUSwapChainDX12::Resize(int32 width, int32 height)
_currentFrameIndex = _swapChain->GetCurrentBackBufferIndex(); _currentFrameIndex = _swapChain->GetCurrentBackBufferIndex();
_width = width; _width = width;
_height = height; _height = height;
_memoryUsage = CalculateTextureMemoryUsage(_format, _width, _height, 1) * swapChainDesc.BufferCount; _memoryUsage = RenderTools::CalculateTextureMemoryUsage(_format, _width, _height, 1) * swapChainDesc.BufferCount;
getBackBuffer(); getBackBuffer();
#endif #endif

View File

@@ -415,7 +415,7 @@ bool GPUSwapChainVulkan::CreateSwapChain(int32 width, int32 height)
} }
// Calculate memory usage // Calculate memory usage
_memoryUsage = CalculateTextureMemoryUsage(_format, _width, _height, 1) * _backBuffers.Count(); _memoryUsage = RenderTools::CalculateTextureMemoryUsage(_format, _width, _height, 1) * _backBuffers.Count();
return false; return false;
} }

View File

@@ -52,7 +52,7 @@ public:
/// </summary> /// </summary>
/// <param name="index">Lightmap index</param> /// <param name="index">Lightmap index</param>
/// <returns>Lightmap or null if missing or not ready</returns> /// <returns>Lightmap or null if missing or not ready</returns>
Lightmap* GetReadyLightmap(int32 index); FLAXENGINE_API Lightmap* GetReadyLightmap(int32 index);
/// <summary> /// <summary>
/// Gets lightmaps array /// Gets lightmaps array

View File

@@ -207,8 +207,8 @@ class RenderListAllocation
{ {
public: public:
static void* Allocate(uintptr size); static FLAXENGINE_API void* Allocate(uintptr size);
static void Free(void* ptr, uintptr size); static FLAXENGINE_API void Free(void* ptr, uintptr size);
template<typename T> template<typename T>
class Data class Data