Add ScriptingEnum::ToStringFlags for printing flag enums into readable text

This commit is contained in:
Wojtek Figat
2024-02-16 12:46:35 +01:00
parent f0f8da3c09
commit f04f1cc90e
3 changed files with 38 additions and 51 deletions

View File

@@ -12,6 +12,7 @@
#include "Engine/Debug/Exceptions/InvalidOperationException.h"
#include "Engine/Debug/Exceptions/ArgumentNullException.h"
#include "Engine/Debug/Exceptions/ArgumentOutOfRangeException.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Scripting/Enums.h"
#include "Engine/Threading/ThreadPoolTask.h"
#include "Engine/Threading/Threading.h"
@@ -81,33 +82,10 @@ bool GPUBufferDescription::Equals(const GPUBufferDescription& other) const
String GPUBufferDescription::ToString() const
{
// TODO: add tool to Format to string
String flags;
if (Flags == GPUBufferFlags::None)
{
flags = TEXT("None");
}
else
{
// TODO: create tool to auto convert flag enums to string
#define CONVERT_FLAGS_FLAGS_2_STR(value) if (EnumHasAnyFlags(Flags, GPUBufferFlags::value)) { if (flags.HasChars()) flags += TEXT('|'); flags += TEXT(#value); }
CONVERT_FLAGS_FLAGS_2_STR(ShaderResource);
CONVERT_FLAGS_FLAGS_2_STR(VertexBuffer);
CONVERT_FLAGS_FLAGS_2_STR(IndexBuffer);
CONVERT_FLAGS_FLAGS_2_STR(UnorderedAccess);
CONVERT_FLAGS_FLAGS_2_STR(Append);
CONVERT_FLAGS_FLAGS_2_STR(Counter);
CONVERT_FLAGS_FLAGS_2_STR(Argument);
CONVERT_FLAGS_FLAGS_2_STR(Structured);
#undef CONVERT_FLAGS_FLAGS_2_STR
}
return String::Format(TEXT("Size: {0}, Stride: {1}, Flags: {2}, Format: {3}, Usage: {4}"),
Size,
Stride,
flags,
ScriptingEnum::ToStringFlags(Flags),
ScriptingEnum::ToString(Format),
(int32)Usage);
}
@@ -212,7 +190,7 @@ GPUBuffer* GPUBuffer::ToStagingUpload() const
bool GPUBuffer::Resize(uint32 newSize)
{
// Validate input
PROFILE_CPU();
if (!IsAllocated())
{
Log::InvalidOperationException(TEXT("Buffer.Resize"));
@@ -236,12 +214,12 @@ bool GPUBuffer::DownloadData(BytesContainer& result)
LOG(Warning, "Cannot download GPU buffer data from an empty buffer.");
return true;
}
if (_desc.Usage == GPUResourceUsage::StagingReadback || _desc.Usage == GPUResourceUsage::Dynamic)
{
// Use faster path for staging resources
return GetData(result);
}
PROFILE_CPU();
// Ensure not running on main thread
if (IsInMainThread())
@@ -358,6 +336,7 @@ Task* GPUBuffer::DownloadDataAsync(BytesContainer& result)
bool GPUBuffer::GetData(BytesContainer& output)
{
PROFILE_CPU();
void* mapped = Map(GPUResourceMapMode::Read);
if (!mapped)
return true;
@@ -368,6 +347,7 @@ bool GPUBuffer::GetData(BytesContainer& output)
void GPUBuffer::SetData(const void* data, uint32 size)
{
PROFILE_CPU();
if (size == 0 || data == nullptr)
{
Log::ArgumentNullException(TEXT("Buffer.SetData"));

View File

@@ -15,6 +15,7 @@
#include "Engine/Graphics/GPULimits.h"
#include "Engine/Threading/ThreadPoolTask.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Scripting/Enums.h"
namespace
@@ -158,29 +159,6 @@ bool GPUTextureDescription::Equals(const GPUTextureDescription& other) const
String GPUTextureDescription::ToString() const
{
// TODO: add tool to Format to string
String flags;
if (Flags == GPUTextureFlags::None)
{
flags = TEXT("None");
}
else
{
// TODO: create tool to auto convert flag enums to string
#define CONVERT_FLAGS_FLAGS_2_STR(value) if (EnumHasAnyFlags(Flags, GPUTextureFlags::value)) { if (flags.HasChars()) flags += TEXT('|'); flags += TEXT(#value); }
CONVERT_FLAGS_FLAGS_2_STR(ShaderResource);
CONVERT_FLAGS_FLAGS_2_STR(RenderTarget);
CONVERT_FLAGS_FLAGS_2_STR(UnorderedAccess);
CONVERT_FLAGS_FLAGS_2_STR(DepthStencil);
CONVERT_FLAGS_FLAGS_2_STR(PerMipViews);
CONVERT_FLAGS_FLAGS_2_STR(PerSliceViews);
CONVERT_FLAGS_FLAGS_2_STR(ReadOnlyDepthView);
CONVERT_FLAGS_FLAGS_2_STR(BackBuffer);
#undef CONVERT_FLAGS_FLAGS_2_STR
}
return String::Format(TEXT("Size: {0}x{1}x{2}[{3}], Type: {4}, Mips: {5}, Format: {6}, MSAA: {7}, Flags: {8}, Usage: {9}"),
Width,
Height,
@@ -190,7 +168,7 @@ String GPUTextureDescription::ToString() const
MipLevels,
ScriptingEnum::ToString(Format),
::ToString(MultiSampleLevel),
flags,
ScriptingEnum::ToStringFlags(Flags),
(int32)Usage);
}
@@ -544,7 +522,7 @@ GPUTexture* GPUTexture::ToStagingUpload() const
bool GPUTexture::Resize(int32 width, int32 height, int32 depth, PixelFormat format)
{
// Validate texture is created
PROFILE_CPU();
if (!IsAllocated())
{
LOG(Warning, "Cannot resize not created textures.");
@@ -608,6 +586,7 @@ GPUTask* GPUTexture::UploadMipMapAsync(const BytesContainer& data, int32 mipInde
GPUTask* GPUTexture::UploadMipMapAsync(const BytesContainer& data, int32 mipIndex, int32 rowPitch, int32 slicePitch, bool copyData)
{
PROFILE_CPU();
ASSERT(IsAllocated());
ASSERT(mipIndex < MipLevels() && data.IsValid());
ASSERT(data.Length() >= slicePitch);
@@ -699,6 +678,7 @@ bool GPUTexture::DownloadData(TextureData& result)
{
MISSING_CODE("support volume texture data downloading.");
}
PROFILE_CPU();
// Use faster path for staging resources
if (IsStaging())
@@ -780,6 +760,7 @@ Task* GPUTexture::DownloadDataAsync(TextureData& result)
{
MISSING_CODE("support volume texture data downloading.");
}
PROFILE_CPU();
// Use faster path for staging resources
if (IsStaging())