diff --git a/Source/Engine/Graphics/GPUBuffer.cpp b/Source/Engine/Graphics/GPUBuffer.cpp index 6e400bbdd..6d1ceea41 100644 --- a/Source/Engine/Graphics/GPUBuffer.cpp +++ b/Source/Engine/Graphics/GPUBuffer.cpp @@ -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")); diff --git a/Source/Engine/Graphics/Textures/GPUTexture.cpp b/Source/Engine/Graphics/Textures/GPUTexture.cpp index 403f545ba..93642f00a 100644 --- a/Source/Engine/Graphics/Textures/GPUTexture.cpp +++ b/Source/Engine/Graphics/Textures/GPUTexture.cpp @@ -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()) diff --git a/Source/Engine/Scripting/Enums.h b/Source/Engine/Scripting/Enums.h index dd605d303..7c8d36f24 100644 --- a/Source/Engine/Scripting/Enums.h +++ b/Source/Engine/Scripting/Enums.h @@ -68,4 +68,30 @@ public: { return FromString(StringAnsi(name)); } + + // Gets the name of the enum value as separated flags + template + static String ToStringFlags(EnumType value, Char separator = '|') + { + String result; + if (const auto items = GetItems()) + { + for (int32 i = 0; items[i].Name; i++) + { + const uint64 itemValue = items[i].Value; + if ((uint64)value == 0 && itemValue == 0) + { + result = items[i].Name; + break; + } + if (itemValue != 0 && EnumHasAllFlags(value, (EnumType)itemValue)) + { + if (result.HasChars()) + result += separator; + result += items[i].Name; + } + } + } + return result; + } };