From df82a0f5d045895c46a33847f573f4abb8696c28 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Thu, 8 Dec 2022 16:30:37 +0100 Subject: [PATCH] Add **GPU Memory profiler** to Editor --- Source/Editor/GUI/Row.cs | 71 +++++ Source/Editor/Windows/Profiler/MemoryGPU.cs | 280 ++++++++++++++++++ .../Editor/Windows/Profiler/ProfilerWindow.cs | 1 + .../Engine/Content/Loading/ContentLoadTask.h | 10 +- .../Content/Loading/ContentLoadingManager.cpp | 5 + Source/Engine/Engine/Base/GameBase.h | 2 - Source/Engine/Graphics/Async/GPUTask.h | 33 +-- .../Engine/Graphics/Async/GPUTasksContext.cpp | 1 + .../Engine/Graphics/Async/GPUTasksManager.cpp | 34 +++ Source/Engine/Graphics/GPUBuffer.cpp | 9 +- Source/Engine/Graphics/GPUBuffer.h | 3 +- Source/Engine/Graphics/GPUDevice.cpp | 18 +- Source/Engine/Graphics/GPUDevice.h | 11 +- Source/Engine/Graphics/GPUPipelineState.h | 2 +- Source/Engine/Graphics/GPUResource.h | 52 ++-- Source/Engine/Graphics/GPUSwapChain.cpp | 4 +- Source/Engine/Graphics/GPUSwapChain.h | 2 +- Source/Engine/Graphics/GPUTimerQuery.h | 10 +- Source/Engine/Graphics/Models/Mesh.cpp | 2 +- Source/Engine/Graphics/Models/Types.h | 11 +- .../Graphics/Shaders/Cache/ShaderStorage.h | 8 +- .../Graphics/Shaders/GPUConstantBuffer.h | 4 +- Source/Engine/Graphics/Shaders/GPUShader.cpp | 4 +- Source/Engine/Graphics/Shaders/GPUShader.h | 2 +- .../Engine/Graphics/Textures/GPUSampler.cpp | 9 +- Source/Engine/Graphics/Textures/GPUSampler.h | 3 +- .../Engine/Graphics/Textures/GPUTexture.cpp | 13 +- Source/Engine/Graphics/Textures/GPUTexture.h | 3 +- .../Graphics/Textures/StreamingTexture.cpp | 1 + .../DirectX/DX12/CommandSignatureDX12.h | 4 +- .../DirectX/DX12/DescriptorHeapDX12.cpp | 4 +- .../DirectX/DX12/DescriptorHeapDX12.h | 6 +- .../DirectX/DX12/GPUContextDX12.cpp | 46 ++- .../DirectX/DX12/UploadBufferDX12.h | 4 +- .../Vulkan/DescriptorSetVulkan.h | 2 +- .../GraphicsDevice/Vulkan/GPUBufferVulkan.cpp | 1 + .../Vulkan/GPUContextVulkan.cpp | 32 +- .../GraphicsDevice/Vulkan/GPUShaderVulkan.h | 4 +- Source/Engine/Level/Types.h | 2 +- Source/Engine/Physics/Types.h | 1 - .../ShadersCompilation/Parser/ShaderMeta.h | 3 +- Source/Engine/Terrain/TerrainPatch.cpp | 1 + Source/Engine/Threading/MainThreadTask.cpp | 2 +- Source/Engine/Threading/Task.h | 10 +- Source/Engine/Threading/ThreadPool.cpp | 6 + Source/Engine/Threading/ThreadPoolTask.h | 6 +- Source/Engine/Utilities/Screenshot.cpp | 1 + 47 files changed, 548 insertions(+), 195 deletions(-) create mode 100644 Source/Editor/Windows/Profiler/MemoryGPU.cs diff --git a/Source/Editor/GUI/Row.cs b/Source/Editor/GUI/Row.cs index 5bec5d1f1..2e672ac49 100644 --- a/Source/Editor/GUI/Row.cs +++ b/Source/Editor/GUI/Row.cs @@ -1,5 +1,6 @@ // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. +using System; using FlaxEngine; using FlaxEngine.GUI; @@ -192,4 +193,74 @@ namespace FlaxEditor.GUI } } } + + /// + /// The table row that contains events for mouse interaction. + /// + [HideInEditor] + public class ClickableRow : Row + { + private bool _leftClick; + private bool _isRightDown; + + /// + /// The double click event. + /// + public Action DoubleClick; + + /// + /// The left mouse button click event. + /// + public Action LeftClick; + + /// + /// The right mouse button click event. + /// + public Action RightClick; + + /// + public override bool OnMouseDoubleClick(Float2 location, MouseButton button) + { + DoubleClick?.Invoke(); + + return base.OnMouseDoubleClick(location, button); + } + + /// + public override bool OnMouseDown(Float2 location, MouseButton button) + { + if (button == MouseButton.Left) + _leftClick = true; + else if (button == MouseButton.Right) + _isRightDown = true; + + return base.OnMouseDown(location, button); + } + + /// + public override bool OnMouseUp(Float2 location, MouseButton button) + { + if (button == MouseButton.Left && _leftClick) + { + _leftClick = false; + LeftClick?.Invoke(); + } + else if (button == MouseButton.Right && _isRightDown) + { + _isRightDown = false; + RightClick?.Invoke(); + } + + return base.OnMouseUp(location, button); + } + + /// + public override void OnMouseLeave() + { + _leftClick = false; + _isRightDown = false; + + base.OnMouseLeave(); + } + } } diff --git a/Source/Editor/Windows/Profiler/MemoryGPU.cs b/Source/Editor/Windows/Profiler/MemoryGPU.cs new file mode 100644 index 000000000..b288819da --- /dev/null +++ b/Source/Editor/Windows/Profiler/MemoryGPU.cs @@ -0,0 +1,280 @@ +// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. + +using System; +using System.Collections.Generic; +using FlaxEditor.GUI; +using FlaxEngine; +using FlaxEngine.GUI; + +namespace FlaxEditor.Windows.Profiler +{ + /// + /// The GPU Memory profiling mode. + /// + /// + internal sealed class MemoryGPU : ProfilerMode + { + private struct Resource + { + public string Name; + public GPUResourceType Type; + public ulong MemoryUsage; + public Guid AssetId; + } + + private readonly SingleChart _memoryUsageChart; + private readonly Table _table; + private SamplesBuffer _resources; + private List _tableRowsCache; + private string[] _resourceTypesNames; + private Dictionary _assetPathToId; + private Dictionary _resourceCache; + + public MemoryGPU() + : base("GPU Memory") + { + // Layout + var panel = new Panel(ScrollBars.Vertical) + { + AnchorPreset = AnchorPresets.StretchAll, + Offsets = Margin.Zero, + Parent = this, + }; + var layout = new VerticalPanel + { + AnchorPreset = AnchorPresets.HorizontalStretchTop, + Offsets = Margin.Zero, + IsScrollable = true, + Parent = panel, + }; + + // Chart + _memoryUsageChart = new SingleChart + { + Title = "GPU Memory Usage", + FormatSample = v => Utilities.Utils.FormatBytesCount((int)v), + Parent = layout, + }; + _memoryUsageChart.SelectedSampleChanged += OnSelectedSampleChanged; + + // Table + var headerColor = Style.Current.LightBackground; + _table = new Table + { + Columns = new[] + { + new ColumnDefinition + { + UseExpandCollapseMode = true, + CellAlignment = TextAlignment.Near, + Title = "Resource", + TitleBackgroundColor = headerColor, + }, + new ColumnDefinition + { + Title = "Type", + CellAlignment = TextAlignment.Center, + TitleBackgroundColor = headerColor, + }, + new ColumnDefinition + { + Title = "Memory Usage", + TitleBackgroundColor = headerColor, + FormatValue = v => Utilities.Utils.FormatBytesCount((ulong)v), + }, + }, + Parent = layout, + }; + _table.Splits = new[] + { + 0.6f, + 0.2f, + 0.2f, + }; + } + + /// + public override void Clear() + { + _memoryUsageChart.Clear(); + _resources?.Clear(); + _assetPathToId?.Clear(); + _resourceCache?.Clear(); + } + + /// + public override void Update(ref SharedUpdateData sharedData) + { + _memoryUsageChart.AddSample(sharedData.Stats.MemoryGPU.Used); + + if (_resourceCache == null) + _resourceCache = new Dictionary(); + if (_assetPathToId == null) + _assetPathToId = new Dictionary(); + + // Capture current GPU resources usage info + var gpuResources = GPUDevice.Instance.Resources; + var resources = new Resource[gpuResources.Length]; + for (int i = 0; i < resources.Length; i++) + { + var gpuResource = gpuResources[i]; + + // Try to reuse cached resource info + var gpuResourceId = gpuResource.ID; + if (!_resourceCache.TryGetValue(gpuResourceId, out var resource)) + { + resource = new Resource + { + Name = gpuResource.Name, + Type = gpuResource.ResourceType, + }; + + // Detect asset path in the resource name + int ext = resource.Name.LastIndexOf(".flax", StringComparison.OrdinalIgnoreCase); + if (ext != -1) + { + var assetPath = resource.Name.Substring(0, ext + 5); + if (!_assetPathToId.TryGetValue(assetPath, out resource.AssetId)) + { + var asset = FlaxEngine.Content.GetAsset(assetPath); + if (asset != null) + resource.AssetId = asset.ID; + _assetPathToId.Add(assetPath, resource.AssetId); + } + } + + _resourceCache.Add(gpuResourceId, resource); + } + + resource.MemoryUsage = gpuResource.MemoryUsage; + if (resource.MemoryUsage == 1) + resource.MemoryUsage = 0; // Sometimes GPU backend fakes memory usage as 1 to mark as allocated but not resided in actual GPU memory + resources[i] = resource; + } + Array.Sort(resources, SortResources); + if (_resources == null) + _resources = new SamplesBuffer(); + _resources.Add(resources); + } + + /// + public override void UpdateView(int selectedFrame, bool showOnlyLastUpdateEvents) + { + _memoryUsageChart.SelectedSampleIndex = selectedFrame; + + if (_resources == null) + return; + if (_tableRowsCache == null) + _tableRowsCache = new List(); + if (_resourceTypesNames == null) + _resourceTypesNames = new string[(int)GPUResourceType.MAX] + { + "Render Target", + "Texture", + "Cube Texture", + "Volume Texture", + "Buffer", + "Shader", + "Pipeline State", + "Descriptor", + "Query", + "Sampler", + }; + UpdateTable(); + } + + /// + public override void OnDestroy() + { + _resources?.Clear(); + _resourceCache?.Clear(); + _assetPathToId?.Clear(); + _tableRowsCache?.Clear(); + + base.OnDestroy(); + } + + private static int SortResources(Resource a, Resource b) + { + return (int)(b.MemoryUsage - a.MemoryUsage); + } + + private void UpdateTable() + { + _table.IsLayoutLocked = true; + int idx = 0; + while (_table.Children.Count > idx) + { + var child = _table.Children[idx]; + if (child is ClickableRow row) + { + _tableRowsCache.Add(row); + child.Parent = null; + } + else + { + idx++; + } + } + _table.LockChildrenRecursive(); + + UpdateTableInner(); + + _table.UnlockChildrenRecursive(); + _table.PerformLayout(); + } + + private void UpdateTableInner() + { + if (_resources.Count == 0) + return; + var resources = _resources.Get(_memoryUsageChart.SelectedSampleIndex); + if (resources == null || resources.Length == 0) + return; + + // Add rows + var rowColor2 = Style.Current.Background * 1.4f; + var contentDatabase = Editor.Instance.ContentDatabase; + for (int i = 0; i < resources.Length; i++) + { + ref var e = ref resources[i]; + + ClickableRow row; + if (_tableRowsCache.Count != 0) + { + // Reuse row + var last = _tableRowsCache.Count - 1; + row = _tableRowsCache[last]; + _tableRowsCache.RemoveAt(last); + } + else + { + // Allocate new row + row = new ClickableRow { Values = new object[3] }; + } + + // Setup row data + row.Values[0] = e.Name; + row.Values[1] = _resourceTypesNames[(int)e.Type]; + row.Values[2] = e.MemoryUsage; + + // Setup row interactions + row.TooltipText = null; + row.DoubleClick = null; + var assetItem = contentDatabase.FindAsset(e.AssetId); + if (assetItem != null) + { + row.Values[0] = assetItem.NamePath; + assetItem.UpdateTooltipText(); + row.TooltipText = assetItem.TooltipText; + row.DoubleClick = () => { Editor.Instance.ContentEditing.Open(assetItem); }; + } + + // Add row to the table + row.Width = _table.Width; + row.BackgroundColor = i % 2 == 0 ? rowColor2 : Color.Transparent; + row.Parent = _table; + } + } + } +} diff --git a/Source/Editor/Windows/Profiler/ProfilerWindow.cs b/Source/Editor/Windows/Profiler/ProfilerWindow.cs index d85cc159a..1bf7fc7f4 100644 --- a/Source/Editor/Windows/Profiler/ProfilerWindow.cs +++ b/Source/Editor/Windows/Profiler/ProfilerWindow.cs @@ -181,6 +181,7 @@ namespace FlaxEditor.Windows.Profiler AddMode(new Overall()); AddMode(new CPU()); AddMode(new GPU()); + AddMode(new MemoryGPU()); AddMode(new Memory()); AddMode(new Network()); diff --git a/Source/Engine/Content/Loading/ContentLoadTask.h b/Source/Engine/Content/Loading/ContentLoadTask.h index c36438ccc..d7f0e32d4 100644 --- a/Source/Engine/Content/Loading/ContentLoadTask.h +++ b/Source/Engine/Content/Loading/ContentLoadTask.h @@ -3,7 +3,6 @@ #pragma once #include "Engine/Threading/Task.h" -#include "Engine/Core/Types/String.h" class Asset; class LoadingThread; @@ -46,7 +45,6 @@ public: /// /// Gets a task type. /// - /// The type. FORCE_INLINE Type GetType() const { return _type; @@ -68,13 +66,7 @@ protected: public: // [Task] - String ToString() const override - { - return String::Format(TEXT("Content Load Task {0} ({1})"), - ToString(GetType()), - ::ToString(GetState()) - ); - } + String ToString() const override; protected: // [Task] diff --git a/Source/Engine/Content/Loading/ContentLoadingManager.cpp b/Source/Engine/Content/Loading/ContentLoadingManager.cpp index dedb2761f..000177c7e 100644 --- a/Source/Engine/Content/Loading/ContentLoadingManager.cpp +++ b/Source/Engine/Content/Loading/ContentLoadingManager.cpp @@ -211,6 +211,11 @@ void ContentLoadingManagerService::Dispose() Tasks.CancelAll(); } +String ContentLoadTask::ToString() const +{ + return String::Format(TEXT("Content Load Task {0} ({1})"), ToString(GetType()), (int32)GetState()); +} + void ContentLoadTask::Enqueue() { Tasks.Add(this); diff --git a/Source/Engine/Engine/Base/GameBase.h b/Source/Engine/Engine/Base/GameBase.h index 1e927a1cb..31396490b 100644 --- a/Source/Engine/Engine/Base/GameBase.h +++ b/Source/Engine/Engine/Base/GameBase.h @@ -2,8 +2,6 @@ #pragma once -#include "Engine/Core/Enums.h" - /// /// Build game header flags. /// diff --git a/Source/Engine/Graphics/Async/GPUTask.h b/Source/Engine/Graphics/Async/GPUTask.h index e4fa29864..38bfae056 100644 --- a/Source/Engine/Graphics/Async/GPUTask.h +++ b/Source/Engine/Graphics/Async/GPUTask.h @@ -4,7 +4,6 @@ #include "Engine/Threading/Task.h" #include "Engine/Platform/Platform.h" -#include "Engine/Core/Log.h" #include "GPUTasksContext.h" class GPUResource; @@ -89,32 +88,7 @@ public: /// Executes this task. /// /// The context. - void Execute(GPUTasksContext* context) - { - // Begin - ASSERT(IsQueued() && _context == nullptr); - _state = TaskState::Running; - - // Perform an operation - const auto result = run(context); - - // Process result - if (IsCancelRequested()) - { - _state = TaskState::Canceled; - } - else if (result != Result::Ok) - { - LOG(Warning, "\'{0}\' failed with result: {1}", ToString(), ToString(result)); - OnFail(); - } - else - { - // Save task completion point (for synchronization) - _syncPoint = context->GetCurrentSyncPoint(); - _context = context; - } - } + void Execute(GPUTasksContext* context); /// /// Action fired when asynchronous operation has been synchronized with a GPU @@ -154,10 +128,7 @@ protected: public: // [Task] - String ToString() const override - { - return String::Format(TEXT("GPU Async Task {0} ({1})"), ToString(GetType()), ::ToString(GetState())); - } + String ToString() const override; protected: // [Task] diff --git a/Source/Engine/Graphics/Async/GPUTasksContext.cpp b/Source/Engine/Graphics/Async/GPUTasksContext.cpp index 0800e5a22..75355f6de 100644 --- a/Source/Engine/Graphics/Async/GPUTasksContext.cpp +++ b/Source/Engine/Graphics/Async/GPUTasksContext.cpp @@ -2,6 +2,7 @@ #include "GPUTasksContext.h" #include "GPUTask.h" +#include "Engine/Core/Log.h" #include "Engine/Graphics/GPUDevice.h" #include "Engine/Threading/Threading.h" diff --git a/Source/Engine/Graphics/Async/GPUTasksManager.cpp b/Source/Engine/Graphics/Async/GPUTasksManager.cpp index 2cbe31f47..a81b1f14d 100644 --- a/Source/Engine/Graphics/Async/GPUTasksManager.cpp +++ b/Source/Engine/Graphics/Async/GPUTasksManager.cpp @@ -3,8 +3,42 @@ #include "GPUTasksManager.h" #include "GPUTask.h" #include "GPUTasksExecutor.h" +#include "Engine/Core/Log.h" +#include "Engine/Core/Types/String.h" #include "Engine/Graphics/GPUDevice.h" +void GPUTask::Execute(GPUTasksContext* context) +{ + // Begin + ASSERT(IsQueued() && _context == nullptr); + _state = TaskState::Running; + + // Perform an operation + const auto result = run(context); + + // Process result + if (IsCancelRequested()) + { + _state = TaskState::Canceled; + } + else if (result != Result::Ok) + { + LOG(Warning, "\'{0}\' failed with result: {1}", ToString(), ToString(result)); + OnFail(); + } + else + { + // Save task completion point (for synchronization) + _syncPoint = context->GetCurrentSyncPoint(); + _context = context; + } +} + +String GPUTask::ToString() const +{ + return String::Format(TEXT("GPU Async Task {0} ({1})"), ToString(GetType()), (int32)GetState()); +} + void GPUTask::Enqueue() { GPUDevice::Instance->GetTasksManager()->_tasks.Add(this); diff --git a/Source/Engine/Graphics/GPUBuffer.cpp b/Source/Engine/Graphics/GPUBuffer.cpp index 3aae13789..4900e73e2 100644 --- a/Source/Engine/Graphics/GPUBuffer.cpp +++ b/Source/Engine/Graphics/GPUBuffer.cpp @@ -395,14 +395,9 @@ String GPUBuffer::ToString() const #endif } -GPUResource::ResourceType GPUBuffer::GetResourceType() const +GPUResourceType GPUBuffer::GetResourceType() const { - return ResourceType::Buffer; -} - -GPUResource::ObjectType GPUBuffer::GetObjectType() const -{ - return ObjectType::Buffer; + return GPUResourceType::Buffer; } void GPUBuffer::OnReleaseGPU() diff --git a/Source/Engine/Graphics/GPUBuffer.h b/Source/Engine/Graphics/GPUBuffer.h index 785be2cc3..9af530e9c 100644 --- a/Source/Engine/Graphics/GPUBuffer.h +++ b/Source/Engine/Graphics/GPUBuffer.h @@ -205,8 +205,7 @@ protected: public: // [GPUResource] String ToString() const override; - ResourceType GetResourceType() const final override; - ObjectType GetObjectType() const final override; + GPUResourceType GetResourceType() const final override; protected: // [GPUResource] diff --git a/Source/Engine/Graphics/GPUDevice.cpp b/Source/Engine/Graphics/GPUDevice.cpp index 22b0c84fd..14d8ff63a 100644 --- a/Source/Engine/Graphics/GPUDevice.cpp +++ b/Source/Engine/Graphics/GPUDevice.cpp @@ -23,6 +23,7 @@ #include "Engine/Engine/EngineService.h" #include "Engine/Profiler/Profiler.h" #include "Engine/Renderer/RenderList.h" +#include "Engine/Scripting/Enums.h" GPUPipelineState* GPUPipelineState::Spawn(const SpawnParams& params) { @@ -79,9 +80,9 @@ bool GPUPipelineState::Init(const Description& desc) return false; } -GPUResource::ResourceType GPUPipelineState::GetResourceType() const +GPUResourceType GPUPipelineState::GetResourceType() const { - return ResourceType::PipelineState; + return GPUResourceType::PipelineState; } GPUPipelineState::Description GPUPipelineState::Description::Default = @@ -193,16 +194,13 @@ GPUResource::~GPUResource() #endif } -GPUResource::ObjectType GPUResource::GetObjectType() const -{ - return ObjectType::Other; -} - uint64 GPUResource::GetMemoryUsage() const { return _memoryUsage; } +static_assert((GPU_ENABLE_RESOURCE_NAMING) == (!BUILD_RELEASE), "Update build condition on around GPUResource Name property getter/setter."); + #if GPU_ENABLE_RESOURCE_NAMING String GPUResource::GetName() const @@ -394,11 +392,11 @@ void GPUDevice::DumpResourcesToLog() const output.AppendLine(); output.AppendLine(); - for (int32 typeIndex = 0; typeIndex < GPUResource::ResourceType_Count; typeIndex++) + for (int32 typeIndex = 0; typeIndex < (int32)GPUResourceType::MAX; typeIndex++) { - const auto type = static_cast(typeIndex); + const auto type = static_cast(typeIndex); - output.AppendFormat(TEXT("Group: {0}s"), GPUResource::ToString(type)); + output.AppendFormat(TEXT("Group: {0}s"), ScriptingEnum::ToString(type)); output.AppendLine(); int32 count = 0; diff --git a/Source/Engine/Graphics/GPUDevice.h b/Source/Engine/Graphics/GPUDevice.h index 890770683..ca63d233a 100644 --- a/Source/Engine/Graphics/GPUDevice.h +++ b/Source/Engine/Graphics/GPUDevice.h @@ -4,7 +4,6 @@ #include "Engine/Platform/Platform.h" #include "Engine/Platform/CriticalSection.h" -#include "Engine/Core/Enums.h" #include "Engine/Core/NonCopyable.h" #include "Engine/Core/Collections/Array.h" #include "Engine/Scripting/ScriptingObject.h" @@ -43,7 +42,15 @@ public: /// /// Graphics Device states that describe its lifetime. /// - DECLARE_ENUM_6(DeviceState, Missing, Created, Ready, Removed, Disposing, Disposed); + enum class DeviceState + { + Missing = 0, + Created, + Ready, + Removed, + Disposing, + Disposed + }; /// /// Describes a video output display mode. diff --git a/Source/Engine/Graphics/GPUPipelineState.h b/Source/Engine/Graphics/GPUPipelineState.h index 497548e00..538c83a10 100644 --- a/Source/Engine/Graphics/GPUPipelineState.h +++ b/Source/Engine/Graphics/GPUPipelineState.h @@ -160,5 +160,5 @@ public: public: // [GPUResource] - ResourceType GetResourceType() const final override; + GPUResourceType GetResourceType() const final override; }; diff --git a/Source/Engine/Graphics/GPUResource.h b/Source/Engine/Graphics/GPUResource.h index e07b3e7bd..05f409b9c 100644 --- a/Source/Engine/Graphics/GPUResource.h +++ b/Source/Engine/Graphics/GPUResource.h @@ -2,7 +2,6 @@ #pragma once -#include "Engine/Core/Enums.h" #include "Engine/Scripting/ScriptingObject.h" #include "Config.h" @@ -12,23 +11,41 @@ #define SAFE_DELETE_GPU_RESOURCE(x) if (x) { (x)->DeleteObjectNow(); (x) = nullptr; } #define SAFE_DELETE_GPU_RESOURCES(x) for (auto& e : (x)) if (e) { e->DeleteObjectNow(); e = nullptr; } +/// +/// GPU resources types. +/// +API_ENUM() enum class GPUResourceType +{ + // GPU render target texture + RenderTarget = 0, + // GPU texture + Texture, + // GPU cube texture (cubemap) + CubeTexture, + // GPU volume texture (3D) + VolumeTexture, + // GPU buffer + Buffer, + // GPU shader + Shader, + // GPU pipeline state object (PSO) + PipelineState, + // GPU binding descriptor + Descriptor, + // GPU timer query + Query, + // GPU texture sampler + Sampler, + + MAX +}; + /// /// The base class for all GPU resources. /// API_CLASS(Abstract, NoSpawn) class FLAXENGINE_API GPUResource : public ScriptingObject { DECLARE_SCRIPTING_TYPE_NO_SPAWN(GPUResource); -public: - /// - /// GPU Resources types. - /// - DECLARE_ENUM_10(ResourceType, RenderTarget, Texture, CubeTexture, VolumeTexture, Buffer, Shader, PipelineState, Descriptor, Query, Sampler); - - /// - /// GPU Resources object types. Used to detect Texture objects from subset of Types: RenderTarget, Texture, CubeTexture, VolumeTexture which use the same API object. - /// - DECLARE_ENUM_3(ObjectType, Texture, Buffer, Other); - protected: uint64 _memoryUsage = 0; #if GPU_ENABLE_RESOURCE_NAMING @@ -65,21 +82,16 @@ public: public: /// - /// Gets the resource type. + /// Gets the GPU resource type. /// - virtual ResourceType GetResourceType() const = 0; - - /// - /// Gets resource object type. - /// - virtual ObjectType GetObjectType() const; + API_PROPERTY() virtual GPUResourceType GetResourceType() const = 0; /// /// Gets amount of GPU memory used by this resource (in bytes). It's a rough estimation. GPU memory may be fragmented, compressed or sub-allocated so the actual memory pressure from this resource may vary (also depends on the current graphics backend). /// API_PROPERTY() uint64 GetMemoryUsage() const; -#if GPU_ENABLE_RESOURCE_NAMING +#if !BUILD_RELEASE /// /// Gets the resource name. /// diff --git a/Source/Engine/Graphics/GPUSwapChain.cpp b/Source/Engine/Graphics/GPUSwapChain.cpp index 4d33db407..bd2ac858b 100644 --- a/Source/Engine/Graphics/GPUSwapChain.cpp +++ b/Source/Engine/Graphics/GPUSwapChain.cpp @@ -95,7 +95,7 @@ String GPUSwapChain::ToString() const #endif } -GPUResource::ResourceType GPUSwapChain::GetResourceType() const +GPUResourceType GPUSwapChain::GetResourceType() const { - return ResourceType::Texture; + return GPUResourceType::Texture; } diff --git a/Source/Engine/Graphics/GPUSwapChain.h b/Source/Engine/Graphics/GPUSwapChain.h index 97777cd6e..738aeaf40 100644 --- a/Source/Engine/Graphics/GPUSwapChain.h +++ b/Source/Engine/Graphics/GPUSwapChain.h @@ -160,5 +160,5 @@ public: public: // [GPUResource] String ToString() const override; - ResourceType GetResourceType() const final override; + GPUResourceType GetResourceType() const final override; }; diff --git a/Source/Engine/Graphics/GPUTimerQuery.h b/Source/Engine/Graphics/GPUTimerQuery.h index e4763ac4f..75fa06738 100644 --- a/Source/Engine/Graphics/GPUTimerQuery.h +++ b/Source/Engine/Graphics/GPUTimerQuery.h @@ -48,14 +48,8 @@ public: { return TEXT("TimerQuery"); } - - ResourceType GetResourceType() const final override + GPUResourceType GetResourceType() const final override { - return ResourceType::Query; - } - - ObjectType GetObjectType() const final override - { - return ObjectType::Other; + return GPUResourceType::Query; } }; diff --git a/Source/Engine/Graphics/Models/Mesh.cpp b/Source/Engine/Graphics/Models/Mesh.cpp index ee2ed5de6..b75db1949 100644 --- a/Source/Engine/Graphics/Models/Mesh.cpp +++ b/Source/Engine/Graphics/Models/Mesh.cpp @@ -251,7 +251,7 @@ bool Mesh::Load(uint32 vertices, uint32 triangles, void* vb0, void* vb1, void* v // Create GPU buffers #if GPU_ENABLE_RESOURCE_NAMING -#define MESH_BUFFER_NAME(postfix) GetModel()->ToString() + TEXT(postfix) +#define MESH_BUFFER_NAME(postfix) GetModel()->GetPath() + TEXT(postfix) #else #define MESH_BUFFER_NAME(postfix) String::Empty #endif diff --git a/Source/Engine/Graphics/Models/Types.h b/Source/Engine/Graphics/Models/Types.h index 2272a3a08..a8492b999 100644 --- a/Source/Engine/Graphics/Models/Types.h +++ b/Source/Engine/Graphics/Models/Types.h @@ -2,7 +2,6 @@ #pragma once -#include "Engine/Core/Enums.h" #include "Engine/Core/Math/Packed.h" #include "Engine/Core/Math/Vector2.h" #include "Engine/Core/Math/Vector3.h" @@ -23,7 +22,15 @@ struct RenderView; /// /// Importing model lightmap UVs source /// -DECLARE_ENUM_6(ModelLightmapUVsSource, Disable, Generate, Channel0, Channel1, Channel2, Channel3); +enum class ModelLightmapUVsSource +{ + Disable = 0, + Generate, + Channel0, + Channel1, + Channel2, + Channel3 +}; /// /// The mesh buffer types. diff --git a/Source/Engine/Graphics/Shaders/Cache/ShaderStorage.h b/Source/Engine/Graphics/Shaders/Cache/ShaderStorage.h index 3fabbb5b7..b4660c8d1 100644 --- a/Source/Engine/Graphics/Shaders/Cache/ShaderStorage.h +++ b/Source/Engine/Graphics/Shaders/Cache/ShaderStorage.h @@ -3,7 +3,6 @@ #pragma once #include "Engine/Core/Types/BaseTypes.h" -#include "Engine/Core/Enums.h" #include "Engine/Graphics/Config.h" #include "Engine/Graphics/Materials/MaterialInfo.h" #include "../Config.h" @@ -31,7 +30,12 @@ public: /// /// Different shader cache storage modes (disabled, inside asset and in project cache) /// - DECLARE_ENUM_3(CachingMode, Disabled, AssetInternal, ProjectCache); + enum class CachingMode + { + Disabled = 0, + AssetInternal, + ProjectCache + }; /// /// Current shaders caching mode to use diff --git a/Source/Engine/Graphics/Shaders/GPUConstantBuffer.h b/Source/Engine/Graphics/Shaders/GPUConstantBuffer.h index 0c63ac6f5..9376a3ab9 100644 --- a/Source/Engine/Graphics/Shaders/GPUConstantBuffer.h +++ b/Source/Engine/Graphics/Shaders/GPUConstantBuffer.h @@ -23,8 +23,8 @@ public: public: // [GPUResource] - ResourceType GetResourceType() const override + GPUResourceType GetResourceType() const override { - return ResourceType::Buffer; + return GPUResourceType::Buffer; } }; diff --git a/Source/Engine/Graphics/Shaders/GPUShader.cpp b/Source/Engine/Graphics/Shaders/GPUShader.cpp index 7e50b0009..4f3428510 100644 --- a/Source/Engine/Graphics/Shaders/GPUShader.cpp +++ b/Source/Engine/Graphics/Shaders/GPUShader.cpp @@ -190,9 +190,9 @@ GPUShaderProgram* GPUShader::GetShader(ShaderStage stage, const StringAnsiView& return shader; } -GPUResource::ResourceType GPUShader::GetResourceType() const +GPUResourceType GPUShader::GetResourceType() const { - return ResourceType::Shader; + return GPUResourceType::Shader; } void GPUShader::OnReleaseGPU() diff --git a/Source/Engine/Graphics/Shaders/GPUShader.h b/Source/Engine/Graphics/Shaders/GPUShader.h index bbc9c4dad..610f09d18 100644 --- a/Source/Engine/Graphics/Shaders/GPUShader.h +++ b/Source/Engine/Graphics/Shaders/GPUShader.h @@ -182,7 +182,7 @@ protected: public: // [GPUResource] - ResourceType GetResourceType() const final override; + GPUResourceType GetResourceType() const final override; protected: // [GPUResource] diff --git a/Source/Engine/Graphics/Textures/GPUSampler.cpp b/Source/Engine/Graphics/Textures/GPUSampler.cpp index 8541a447e..6eb61ec33 100644 --- a/Source/Engine/Graphics/Textures/GPUSampler.cpp +++ b/Source/Engine/Graphics/Textures/GPUSampler.cpp @@ -101,14 +101,9 @@ String GPUSampler::ToString() const #endif } -GPUResource::ResourceType GPUSampler::GetResourceType() const +GPUResourceType GPUSampler::GetResourceType() const { - return ResourceType::Sampler; -} - -GPUResource::ObjectType GPUSampler::GetObjectType() const -{ - return ObjectType::Other; + return GPUResourceType::Sampler; } void GPUSampler::OnReleaseGPU() diff --git a/Source/Engine/Graphics/Textures/GPUSampler.h b/Source/Engine/Graphics/Textures/GPUSampler.h index 6f5760320..010f4f339 100644 --- a/Source/Engine/Graphics/Textures/GPUSampler.h +++ b/Source/Engine/Graphics/Textures/GPUSampler.h @@ -43,8 +43,7 @@ protected: public: // [GPUResource] String ToString() const override; - ResourceType GetResourceType() const final override; - ObjectType GetObjectType() const final override; + GPUResourceType GetResourceType() const final override; protected: // [GPUResource] diff --git a/Source/Engine/Graphics/Textures/GPUTexture.cpp b/Source/Engine/Graphics/Textures/GPUTexture.cpp index 167dfab60..d9112ffc6 100644 --- a/Source/Engine/Graphics/Textures/GPUTexture.cpp +++ b/Source/Engine/Graphics/Textures/GPUTexture.cpp @@ -575,18 +575,13 @@ String GPUTexture::ToString() const #endif } -GPUResource::ResourceType GPUTexture::GetResourceType() const +GPUResourceType GPUTexture::GetResourceType() const { if (IsVolume()) - return ResourceType::VolumeTexture; + return GPUResourceType::VolumeTexture; if (IsCubeMap()) - return ResourceType::CubeTexture; - return IsRegularTexture() ? ResourceType::Texture : ResourceType::RenderTarget; -} - -GPUResource::ObjectType GPUTexture::GetObjectType() const -{ - return ObjectType::Texture; + return GPUResourceType::CubeTexture; + return IsRegularTexture() ? GPUResourceType::Texture : GPUResourceType::RenderTarget; } void GPUTexture::OnReleaseGPU() diff --git a/Source/Engine/Graphics/Textures/GPUTexture.h b/Source/Engine/Graphics/Textures/GPUTexture.h index bb1aa1eb2..f15607567 100644 --- a/Source/Engine/Graphics/Textures/GPUTexture.h +++ b/Source/Engine/Graphics/Textures/GPUTexture.h @@ -573,8 +573,7 @@ protected: public: // [GPUResource] String ToString() const override; - ResourceType GetResourceType() const final override; - ObjectType GetObjectType() const final override; + GPUResourceType GetResourceType() const final override; protected: // [GPUResource] diff --git a/Source/Engine/Graphics/Textures/StreamingTexture.cpp b/Source/Engine/Graphics/Textures/StreamingTexture.cpp index 5af397dbe..4aca9a04d 100644 --- a/Source/Engine/Graphics/Textures/StreamingTexture.cpp +++ b/Source/Engine/Graphics/Textures/StreamingTexture.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. #include "StreamingTexture.h" +#include "Engine/Core/Log.h" #include "Engine/Threading/Threading.h" #include "Engine/Streaming/StreamingGroup.h" #include "Engine/Content/Loading/ContentLoadingManager.h" diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/CommandSignatureDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/CommandSignatureDX12.h index 757779d28..5c366edad 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/CommandSignatureDX12.h +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/CommandSignatureDX12.h @@ -190,9 +190,9 @@ public: public: // [GPUResourceDX12] - ResourceType GetResourceType() const override + GPUResourceType GetResourceType() const override { - return ResourceType::Descriptor; + return GPUResourceType::Descriptor; } protected: diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.cpp b/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.cpp index 0f117029d..ad494f468 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.cpp @@ -128,9 +128,9 @@ void DescriptorHeapWithSlotsDX12::ReleaseSlot(uint32 index) value &= ~mask; } -GPUResource::ResourceType DescriptorHeapWithSlotsDX12::GetResourceType() const +GPUResourceType DescriptorHeapWithSlotsDX12::GetResourceType() const { - return ResourceType::Descriptor; + return GPUResourceType::Descriptor; } DescriptorHeapPoolDX12::DescriptorHeapPoolDX12(GPUDeviceDX12* device, D3D12_DESCRIPTOR_HEAP_TYPE type, uint32 descriptorsCountPerHeap, bool shaderVisible) diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.h index 24610ea19..5a0c1bb01 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.h +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.h @@ -87,7 +87,7 @@ public: public: // [GPUResourceDX12] - ResourceType GetResourceType() const final override; + GPUResourceType GetResourceType() const final override; protected: @@ -170,9 +170,9 @@ public: public: // [GPUResourceDX12] - ResourceType GetResourceType() const final override + GPUResourceType GetResourceType() const final override { - return ResourceType::Descriptor; + return GPUResourceType::Descriptor; } protected: diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp index 2f189af5a..9cad9a636 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp @@ -1299,25 +1299,23 @@ void GPUContextDX12::CopyResource(GPUResource* dstResource, GPUResource* srcReso auto dstResourceDX12 = dynamic_cast(dstResource); auto srcResourceDX12 = dynamic_cast(srcResource); + auto dstBufferDX12 = dynamic_cast(dstResource); + auto srcBufferDX12 = dynamic_cast(srcResource); + auto dstTextureDX12 = dynamic_cast(dstResource); + auto srcTextureDX12 = dynamic_cast(srcResource); SetResourceState(dstResourceDX12, D3D12_RESOURCE_STATE_COPY_DEST); SetResourceState(srcResourceDX12, D3D12_RESOURCE_STATE_COPY_SOURCE); flushRBs(); - auto srcType = srcResource->GetObjectType(); - auto dstType = dstResource->GetObjectType(); - // Buffer -> Buffer - if (srcType == GPUResource::ObjectType::Buffer && dstType == GPUResource::ObjectType::Buffer) + if (srcBufferDX12 && dstBufferDX12) { _commandList->CopyResource(dstResourceDX12->GetResource(), srcResourceDX12->GetResource()); } // Texture -> Texture - else if (srcType == GPUResource::ObjectType::Texture && dstType == GPUResource::ObjectType::Texture) + else if (srcTextureDX12 && dstTextureDX12) { - auto dstTextureDX12 = static_cast(dstResource); - auto srcTextureDX12 = static_cast(srcResource); - if (dstTextureDX12->IsStaging()) { // Staging Texture -> Staging Texture @@ -1388,32 +1386,26 @@ void GPUContextDX12::CopySubresource(GPUResource* dstResource, uint32 dstSubreso { ASSERT(dstResource && srcResource); - auto srcType = srcResource->GetObjectType(); - auto dstType = dstResource->GetObjectType(); - + auto dstResourceDX12 = dynamic_cast(dstResource); + auto srcResourceDX12 = dynamic_cast(srcResource); + auto dstBufferDX12 = dynamic_cast(dstResource); + auto srcBufferDX12 = dynamic_cast(srcResource); + auto dstTextureDX12 = dynamic_cast(dstResource); + auto srcTextureDX12 = dynamic_cast(srcResource); + + SetResourceState(dstResourceDX12, D3D12_RESOURCE_STATE_COPY_DEST); + SetResourceState(srcResourceDX12, D3D12_RESOURCE_STATE_COPY_SOURCE); + flushRBs(); + // Buffer -> Buffer - if (srcType == GPUResource::ObjectType::Buffer && dstType == GPUResource::ObjectType::Buffer) + if (srcBufferDX12 && dstBufferDX12) { - auto dstBufferDX12 = dynamic_cast(dstResource); - auto srcBufferDX12 = dynamic_cast(srcResource); - - SetResourceState(dstBufferDX12, D3D12_RESOURCE_STATE_COPY_DEST); - SetResourceState(srcBufferDX12, D3D12_RESOURCE_STATE_COPY_SOURCE); - flushRBs(); - uint64 bytesCount = srcResource->GetMemoryUsage(); _commandList->CopyBufferRegion(dstBufferDX12->GetResource(), 0, srcBufferDX12->GetResource(), 0, bytesCount); } // Texture -> Texture - else if (srcType == GPUResource::ObjectType::Texture && dstType == GPUResource::ObjectType::Texture) + else if (srcTextureDX12 && dstTextureDX12) { - auto dstTextureDX12 = static_cast(dstResource); - auto srcTextureDX12 = static_cast(srcResource); - - SetResourceState(dstTextureDX12, D3D12_RESOURCE_STATE_COPY_DEST); - SetResourceState(srcTextureDX12, D3D12_RESOURCE_STATE_COPY_SOURCE); - flushRBs(); - if (srcTextureDX12->IsStaging() || dstTextureDX12->IsStaging()) { Log::NotImplementedException(TEXT("Copy region of staging resources is not supported yet.")); diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/UploadBufferDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/UploadBufferDX12.h index dfff8b203..13963c43e 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/UploadBufferDX12.h +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/UploadBufferDX12.h @@ -56,9 +56,9 @@ public: public: // [GPUResourceDX12] - ResourceType GetResourceType() const final override + GPUResourceType GetResourceType() const final override { - return ResourceType::Buffer; + return GPUResourceType::Buffer; } // [ResourceOwnerDX12] diff --git a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h index 695da1be9..832bee851 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h @@ -87,7 +87,7 @@ namespace DescriptorSet return ShaderStage::Geometry; default: CRASH; - return static_cast(ShaderStage_Count); + return (ShaderStage)ShaderStage_Count; } } diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUBufferVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUBufferVulkan.cpp index 6e4301c39..e4e432f98 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUBufferVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUBufferVulkan.cpp @@ -5,6 +5,7 @@ #include "GPUBufferVulkan.h" #include "GPUContextVulkan.h" #include "RenderToolsVulkan.h" +#include "Engine/Core/Log.h" #include "Engine/Threading/Threading.h" #include "Engine/Graphics/Async/Tasks/GPUUploadBufferTask.h" diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp index bc768f64c..546f3d59e 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp @@ -1493,17 +1493,13 @@ void GPUContextVulkan::CopyResource(GPUResource* dstResource, GPUResource* srcRe if (cmdBuffer->IsInsideRenderPass()) EndRenderPass(); - auto dstTextureVulkan = static_cast(dstResource); - auto srcTextureVulkan = static_cast(srcResource); - - auto dstBufferVulkan = static_cast(dstResource); - auto srcBufferVulkan = static_cast(srcResource); - - const auto srcType = srcResource->GetObjectType(); - const auto dstType = dstResource->GetObjectType(); + auto dstTextureVulkan = dynamic_cast(dstResource); + auto srcTextureVulkan = dynamic_cast(srcResource); + auto dstBufferVulkan = dynamic_cast(dstResource); + auto srcBufferVulkan = dynamic_cast(srcResource); // Buffer -> Buffer - if (srcType == GPUResource::ObjectType::Buffer && dstType == GPUResource::ObjectType::Buffer) + if (srcBufferVulkan && dstBufferVulkan) { // Transition resources AddBufferBarrier(dstBufferVulkan, VK_ACCESS_TRANSFER_WRITE_BIT); @@ -1519,7 +1515,7 @@ void GPUContextVulkan::CopyResource(GPUResource* dstResource, GPUResource* srcRe vkCmdCopyBuffer(cmdBuffer->GetHandle(), srcBufferVulkan->GetHandle(), dstBufferVulkan->GetHandle(), 1, &bufferCopy); } // Texture -> Texture - else if (srcType == GPUResource::ObjectType::Texture && dstType == GPUResource::ObjectType::Texture) + else if (srcTextureVulkan && dstTextureVulkan) { if (dstTextureVulkan->IsStaging()) { @@ -1632,17 +1628,13 @@ void GPUContextVulkan::CopySubresource(GPUResource* dstResource, uint32 dstSubre if (cmdBuffer->IsInsideRenderPass()) EndRenderPass(); - auto dstTextureVulkan = static_cast(dstResource); - auto srcTextureVulkan = static_cast(srcResource); - - auto dstBufferVulkan = static_cast(dstResource); - auto srcBufferVulkan = static_cast(srcResource); - - auto srcType = srcResource->GetObjectType(); - auto dstType = dstResource->GetObjectType(); + auto dstTextureVulkan = dynamic_cast(dstResource); + auto srcTextureVulkan = dynamic_cast(srcResource); + auto dstBufferVulkan = dynamic_cast(dstResource); + auto srcBufferVulkan = dynamic_cast(srcResource); // Buffer -> Buffer - if (srcType == GPUResource::ObjectType::Buffer && dstType == GPUResource::ObjectType::Buffer) + if (srcBufferVulkan && dstBufferVulkan) { ASSERT(dstSubresource == 0 && srcSubresource == 0); @@ -1660,7 +1652,7 @@ void GPUContextVulkan::CopySubresource(GPUResource* dstResource, uint32 dstSubre vkCmdCopyBuffer(cmdBuffer->GetHandle(), srcBufferVulkan->GetHandle(), dstBufferVulkan->GetHandle(), 1, &bufferCopy); } // Texture -> Texture - else if (srcType == GPUResource::ObjectType::Texture && dstType == GPUResource::ObjectType::Texture) + else if (srcTextureVulkan && dstTextureVulkan) { const int32 dstMipMaps = dstTextureVulkan->MipLevels(); const int32 dstMipIndex = dstSubresource % dstMipMaps; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUShaderVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUShaderVulkan.h index 06bf21bda..42731d5d3 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUShaderVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUShaderVulkan.h @@ -67,9 +67,9 @@ public: public: // [GPUResourceVulkan] - ResourceType GetResourceType() const final override + GPUResourceType GetResourceType() const final override { - return ResourceType::Buffer; + return GPUResourceType::Buffer; } // [ResourceOwnerVulkan] diff --git a/Source/Engine/Level/Types.h b/Source/Engine/Level/Types.h index 559646236..c07eabf4f 100644 --- a/Source/Engine/Level/Types.h +++ b/Source/Engine/Level/Types.h @@ -3,7 +3,7 @@ #pragma once #include "Engine/Core/Config.h" -#include "Engine/Core/Enums.h" +#include "Engine/Core/Types/BaseTypes.h" // Level system types class SceneObject; diff --git a/Source/Engine/Physics/Types.h b/Source/Engine/Physics/Types.h index f2f3f7621..9e9e9a127 100644 --- a/Source/Engine/Physics/Types.h +++ b/Source/Engine/Physics/Types.h @@ -2,7 +2,6 @@ #pragma once -#include "Engine/Core/Enums.h" #include "Engine/Core/Config.h" #include "Engine/Core/Math/Vector2.h" #include "Engine/Core/Math/Vector3.h" diff --git a/Source/Engine/ShadersCompilation/Parser/ShaderMeta.h b/Source/Engine/ShadersCompilation/Parser/ShaderMeta.h index 2ef7ca171..462c06432 100644 --- a/Source/Engine/ShadersCompilation/Parser/ShaderMeta.h +++ b/Source/Engine/ShadersCompilation/Parser/ShaderMeta.h @@ -119,9 +119,8 @@ public: public: /// - /// Gets shader function meta stage type + /// Gets shader function meta stage type. /// - /// Shader Stage type virtual ShaderStage GetStage() const = 0; }; diff --git a/Source/Engine/Terrain/TerrainPatch.cpp b/Source/Engine/Terrain/TerrainPatch.cpp index 9b104c489..51a6d9610 100644 --- a/Source/Engine/Terrain/TerrainPatch.cpp +++ b/Source/Engine/Terrain/TerrainPatch.cpp @@ -3,6 +3,7 @@ #include "TerrainPatch.h" #include "Terrain.h" #include "Engine/Serialization/Serialization.h" +#include "Engine/Core/Log.h" #include "Engine/Core/Math/Color32.h" #include "Engine/Profiler/ProfilerCPU.h" #include "Engine/Physics/Physics.h" diff --git a/Source/Engine/Threading/MainThreadTask.cpp b/Source/Engine/Threading/MainThreadTask.cpp index 0febc8bc4..2cda99834 100644 --- a/Source/Engine/Threading/MainThreadTask.cpp +++ b/Source/Engine/Threading/MainThreadTask.cpp @@ -35,7 +35,7 @@ void MainThreadTask::RunAll(float dt) String MainThreadTask::ToString() const { - return String::Format(TEXT("Main Thread Task ({0})"), ::ToString(GetState())); + return String::Format(TEXT("Main Thread Task ({0})"), (int32)GetState()); } void MainThreadTask::Enqueue() diff --git a/Source/Engine/Threading/Task.h b/Source/Engine/Threading/Task.h index 8f12696d7..a464ae52f 100644 --- a/Source/Engine/Threading/Task.h +++ b/Source/Engine/Threading/Task.h @@ -13,7 +13,15 @@ /// /// Represents the current stage in the lifecycle of a Task. /// -DECLARE_ENUM_EX_6(TaskState, int64, 0, Created, Failed, Canceled, Queued, Running, Finished); +enum class TaskState : int64 +{ + Created = 0, + Failed, + Canceled, + Queued, + Running, + Finished +}; /// /// Represents an asynchronous operation. diff --git a/Source/Engine/Threading/ThreadPool.cpp b/Source/Engine/Threading/ThreadPool.cpp index 30a89cf00..1d61c6eff 100644 --- a/Source/Engine/Threading/ThreadPool.cpp +++ b/Source/Engine/Threading/ThreadPool.cpp @@ -7,6 +7,7 @@ #include "ConcurrentTaskQueue.h" #include "Engine/Core/Log.h" #include "Engine/Core/Math/Math.h" +#include "Engine/Core/Types/String.h" #include "Engine/Engine/Globals.h" #include "Engine/Engine/EngineService.h" #include "Engine/Platform/ConditionVariable.h" @@ -27,6 +28,11 @@ namespace ThreadPoolImpl CriticalSection JobsMutex; } +String ThreadPoolTask::ToString() const +{ + return String::Format(TEXT("Thread Pool Task ({0})"), (int32)GetState()); +} + void ThreadPoolTask::Enqueue() { ThreadPoolImpl::Jobs.Add(this); diff --git a/Source/Engine/Threading/ThreadPoolTask.h b/Source/Engine/Threading/ThreadPoolTask.h index 179615f7f..c7a9156c7 100644 --- a/Source/Engine/Threading/ThreadPoolTask.h +++ b/Source/Engine/Threading/ThreadPoolTask.h @@ -3,7 +3,6 @@ #pragma once #include "Task.h" -#include "Engine/Core/Types/String.h" class ThreadPool; @@ -28,10 +27,7 @@ protected: public: // [Task] - String ToString() const override - { - return String::Format(TEXT("Thread Pool Task ({0})"), ::ToString(GetState())); - } + String ToString() const override; protected: diff --git a/Source/Engine/Utilities/Screenshot.cpp b/Source/Engine/Utilities/Screenshot.cpp index e7e9c12ad..e69506b5f 100644 --- a/Source/Engine/Utilities/Screenshot.cpp +++ b/Source/Engine/Utilities/Screenshot.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. #include "Screenshot.h" +#include "Engine/Core/Log.h" #include "Engine/Core/Math/Math.h" #include "Engine/Graphics/RenderTask.h" #include "Engine/Platform/FileSystem.h"