From 94f50ce8cbd0c7e5979fc37d4c04cb4b4afa0359 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 18 Jun 2021 16:38:44 +0200 Subject: [PATCH] Cleanup some headers in Graphics module --- Source/Engine/Graphics/DynamicBuffer.h | 6 +-- Source/Engine/Graphics/GPUDevice.cpp | 36 +++++++++++++ Source/Engine/Graphics/GPUResource.h | 50 ++++--------------- .../Graphics/Materials/MaterialShader.h | 1 + Source/Engine/Graphics/RenderBuffers.h | 1 + Source/Engine/Graphics/Shaders/GPUShader.cpp | 1 + Source/Engine/Graphics/Shaders/GPUShader.h | 2 +- .../DirectX/DX12/DescriptorHeapDX12.h | 1 + Source/Engine/Render2D/FontTextureAtlas.h | 9 +--- Source/Engine/Terrain/TerrainManager.cpp | 3 +- .../Engine/Tools/TextureTool/TextureTool.cpp | 1 + 11 files changed, 58 insertions(+), 53 deletions(-) diff --git a/Source/Engine/Graphics/DynamicBuffer.h b/Source/Engine/Graphics/DynamicBuffer.h index eb8e9fb5f..e33a3420d 100644 --- a/Source/Engine/Graphics/DynamicBuffer.h +++ b/Source/Engine/Graphics/DynamicBuffer.h @@ -2,12 +2,13 @@ #pragma once +#include "Engine/Core/Collections/Array.h" #include "GPUBuffer.h" /// /// Dynamic GPU buffer that allows to update and use GPU data (index/vertex/other) during single frame (supports dynamic resizing) /// -class FLAXENGINE_API DynamicBuffer : public NonCopyable +class FLAXENGINE_API DynamicBuffer { protected: @@ -16,6 +17,7 @@ protected: uint32 _stride; public: + NON_COPYABLE(DynamicBuffer); /// /// Init @@ -45,8 +47,6 @@ public: return _buffer; } -public: - /// /// Clear data (begin for writing) /// diff --git a/Source/Engine/Graphics/GPUDevice.cpp b/Source/Engine/Graphics/GPUDevice.cpp index e3f6542b5..18c1b5da0 100644 --- a/Source/Engine/Graphics/GPUDevice.cpp +++ b/Source/Engine/Graphics/GPUDevice.cpp @@ -155,6 +155,42 @@ GPUPipelineState::Description GPUPipelineState::Description::DefaultFullscreenTr BlendingMode::Opaque, }; +GPUResource::GPUResource() + : PersistentScriptingObject(SpawnParams(Guid::New(), GPUResource::TypeInitializer)) +{ +} + +GPUResource::GPUResource(const SpawnParams& params) + : PersistentScriptingObject(params) +{ +} + +GPUResource::~GPUResource() +{ +#if !BUILD_RELEASE + ASSERT(_memoryUsage == 0); +#endif +} + +GPUResource::ObjectType GPUResource::GetObjectType() const +{ + return ObjectType::Other; +} + +uint64 GPUResource::GetMemoryUsage() const +{ + return _memoryUsage; +} + +#if GPU_ENABLE_RESOURCE_NAMING + +String GPUResource::GetName() const +{ + return String::Empty; +} + +#endif + void GPUResource::ReleaseGPU() { if (_memoryUsage != 0) diff --git a/Source/Engine/Graphics/GPUResource.h b/Source/Engine/Graphics/GPUResource.h index 4f7d09c63..5d4eff81c 100644 --- a/Source/Engine/Graphics/GPUResource.h +++ b/Source/Engine/Graphics/GPUResource.h @@ -2,8 +2,7 @@ #pragma once -#include "Engine/Core/Common.h" -#include "Engine/Core/NonCopyable.h" +#include "Engine/Core/Enums.h" #include "Engine/Scripting/ScriptingObject.h" #include "Config.h" @@ -15,7 +14,7 @@ /// /// The base class for all GPU resources. /// -API_CLASS(Abstract, NoSpawn) class FLAXENGINE_API GPUResource : public PersistentScriptingObject, public NonCopyable +API_CLASS(Abstract, NoSpawn) class FLAXENGINE_API GPUResource : public PersistentScriptingObject { DECLARE_SCRIPTING_TYPE_NO_SPAWN(GPUResource); public: @@ -35,33 +34,23 @@ protected: uint64 _memoryUsage = 0; public: + NON_COPYABLE(GPUResource); /// /// Initializes a new instance of the class. /// - GPUResource() - : PersistentScriptingObject(SpawnParams(Guid::New(), GPUResource::TypeInitializer)) - { - } + GPUResource(); /// /// Initializes a new instance of the class. /// /// The object initialization parameters. - GPUResource(const SpawnParams& params) - : PersistentScriptingObject(params) - { - } + GPUResource(const SpawnParams& params); /// /// Finalizes an instance of the class. /// - virtual ~GPUResource() - { -#if !BUILD_RELEASE - ASSERT(_memoryUsage == 0); -#endif - } + virtual ~GPUResource(); public: @@ -83,29 +72,19 @@ public: /// /// Gets resource object type. /// - virtual ObjectType GetObjectType() const - { - return ObjectType::Other; - } + virtual ObjectType GetObjectType() const; /// - /// 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). + /// 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() FORCE_INLINE uint64 GetMemoryUsage() const - { - return _memoryUsage; - } + API_PROPERTY() uint64 GetMemoryUsage() const; #if GPU_ENABLE_RESOURCE_NAMING /// /// Gets the resource name. /// - virtual String GetName() const - { - return String::Empty; - } + virtual String GetName() const; #endif @@ -165,9 +144,6 @@ public: , _name(name.Get(), name.Length()) #endif { - ASSERT(device); - - // Register device->Resources.Add(this); } @@ -176,7 +152,6 @@ public: /// virtual ~GPUResourceBase() { - // Unregister if (_device) _device->Resources.Remove(this); } @@ -186,7 +161,6 @@ public: /// /// Gets the graphics device. /// - /// The device. FORCE_INLINE DeviceType* GetDevice() const { return _device; @@ -203,10 +177,7 @@ public: #endif void OnDeviceDispose() override { - // Base GPUResource::OnDeviceDispose(); - - // Unlink device handle _device = nullptr; } }; @@ -234,6 +205,5 @@ public: /// /// Gets the native pointer to the underlying view. It's a platform-specific handle. /// - /// The pointer. virtual void* GetNativePtr() const = 0; }; diff --git a/Source/Engine/Graphics/Materials/MaterialShader.h b/Source/Engine/Graphics/Materials/MaterialShader.h index 9879c87ec..4196b6de4 100644 --- a/Source/Engine/Graphics/Materials/MaterialShader.h +++ b/Source/Engine/Graphics/Materials/MaterialShader.h @@ -3,6 +3,7 @@ #pragma once #include "IMaterial.h" +#include "Engine/Core/Collections/Array.h" #include "Engine/Graphics/GPUPipelineState.h" #include "Engine/Renderer/Config.h" diff --git a/Source/Engine/Graphics/RenderBuffers.h b/Source/Engine/Graphics/RenderBuffers.h index 76ef50a05..6815d8d0c 100644 --- a/Source/Engine/Graphics/RenderBuffers.h +++ b/Source/Engine/Graphics/RenderBuffers.h @@ -3,6 +3,7 @@ #pragma once #include "Engine/Core/Math/Viewport.h" +#include "Engine/Core/Collections/Array.h" #include "Engine/Scripting/ScriptingObject.h" #include "Engine/Graphics/Textures/GPUTexture.h" diff --git a/Source/Engine/Graphics/Shaders/GPUShader.cpp b/Source/Engine/Graphics/Shaders/GPUShader.cpp index d14a204a5..c57d825d3 100644 --- a/Source/Engine/Graphics/Shaders/GPUShader.cpp +++ b/Source/Engine/Graphics/Shaders/GPUShader.cpp @@ -3,6 +3,7 @@ #include "GPUShader.h" #include "GPUConstantBuffer.h" #include "Engine/Core/Log.h" +#include "Engine/Core/Math/Math.h" #include "Engine/Serialization/MemoryReadStream.h" GPUShaderProgramsContainer::GPUShaderProgramsContainer() diff --git a/Source/Engine/Graphics/Shaders/GPUShader.h b/Source/Engine/Graphics/Shaders/GPUShader.h index 66f57b207..cc9ee8eb9 100644 --- a/Source/Engine/Graphics/Shaders/GPUShader.h +++ b/Source/Engine/Graphics/Shaders/GPUShader.h @@ -167,7 +167,7 @@ public: /// The Constant Buffer object. API_FUNCTION() FORCE_INLINE GPUConstantBuffer* GetCB(int32 slot) const { - ASSERT_LOW_LAYER(Math::IsInRange(slot, 0, ARRAY_COUNT(_constantBuffers) - 1)); + ASSERT_LOW_LAYER(slot >= 0 && slot < ARRAY_COUNT(_constantBuffers)); return _constantBuffers[slot]; } diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.h index 7b9bf20a2..262457e9c 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.h +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.h @@ -4,6 +4,7 @@ #if GRAPHICS_API_DIRECTX12 +#include "Engine/Core/Collections/Array.h" #include "Engine/Graphics/GPUResource.h" #include "../IncludeDirectXHeaders.h" diff --git a/Source/Engine/Render2D/FontTextureAtlas.h b/Source/Engine/Render2D/FontTextureAtlas.h index 5f622ada0..f9cca5530 100644 --- a/Source/Engine/Render2D/FontTextureAtlas.h +++ b/Source/Engine/Render2D/FontTextureAtlas.h @@ -3,6 +3,7 @@ #pragma once #include "Engine/Core/Collections/Array.h" +#include "Engine/Core/Math/Vector2.h" #include "Engine/Content/Assets/Texture.h" #include "Engine/Graphics/Textures/GPUTexture.h" #include "Engine/Utilities/RectPack.h" @@ -91,7 +92,6 @@ public: /// /// Gets the atlas width. /// - /// The width. FORCE_INLINE uint32 GetWidth() const { return _width; @@ -100,7 +100,6 @@ public: /// /// Gets the atlas height. /// - /// The height. FORCE_INLINE uint32 GetHeight() const { return _height; @@ -109,7 +108,6 @@ public: /// /// Gets the atlas size. /// - /// The size. FORCE_INLINE Vector2 GetSize() const { return Vector2(static_cast(_width), static_cast(_height)); @@ -118,9 +116,6 @@ public: /// /// Determines whether this atlas is dirty and data need to be flushed. /// - /// - /// true if this atlas is dirty; otherwise, false. - /// FORCE_INLINE bool IsDirty() const { return _isDirty; @@ -129,7 +124,6 @@ public: /// /// Gets padding style for textures in the atlas. /// - /// The padding style. FORCE_INLINE PaddingStyle GetPaddingStyle() const { return _paddingStyle; @@ -138,7 +132,6 @@ public: /// /// Gets amount of pixels to pad textures inside an atlas. /// - /// The padding amount. uint32 GetPaddingAmount() const; public: diff --git a/Source/Engine/Terrain/TerrainManager.cpp b/Source/Engine/Terrain/TerrainManager.cpp index caf620ff0..e0a27d50d 100644 --- a/Source/Engine/Terrain/TerrainManager.cpp +++ b/Source/Engine/Terrain/TerrainManager.cpp @@ -6,12 +6,13 @@ #include "Engine/Graphics/GPUDevice.h" #include "Engine/Graphics/GPUBuffer.h" #include "Engine/Core/Math/Color32.h" +#include "Engine/Core/Collections/ChunkedArray.h" +#include "Engine/Core/Collections/Dictionary.h" #include "Engine/Content/Content.h" #include "Engine/Engine/EngineService.h" #include "Engine/Content/Assets/MaterialBase.h" #include "Engine/Content/AssetReference.h" #include "Engine/Renderer/DrawCall.h" -#include "Engine/Core/Collections/ChunkedArray.h" // Must match structure defined in Terrain.shader struct TerrainVertex diff --git a/Source/Engine/Tools/TextureTool/TextureTool.cpp b/Source/Engine/Tools/TextureTool/TextureTool.cpp index e607a862e..be85b502d 100644 --- a/Source/Engine/Tools/TextureTool/TextureTool.cpp +++ b/Source/Engine/Tools/TextureTool/TextureTool.cpp @@ -16,6 +16,7 @@ #include "Engine/Graphics/PixelFormatExtensions.h" #if USE_EDITOR +#include "Engine/Core/Collections/Dictionary.h" namespace { Dictionary TexturesHasAlphaCache;