From b5bd580f5a42f303b30456364d8626eb27b90671 Mon Sep 17 00:00:00 2001 From: yunimoo Date: Tue, 16 Jul 2024 18:36:37 -0400 Subject: [PATCH 1/5] Refactor constructors to use initialization list The purpose of this commit is to move parameters that otherwise would be assigned in the constructor to the initialization list. This could increase performance by avoiding a call to the default constructor. --- src/Effect/CubismPose.cpp | 3 +-- src/Id/CubismId.cpp | 5 ++--- src/Math/CubismModelMatrix.cpp | 5 ++--- src/Physics/CubismPhysics.cpp | 2 +- src/Rendering/CubismRenderer.cpp | 21 +++++++------------- src/Rendering/D3D11/CubismRenderer_D3D11.cpp | 5 ++--- src/Rendering/D3D9/CubismRenderer_D3D9.cpp | 5 ++--- 7 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/Effect/CubismPose.cpp b/src/Effect/CubismPose.cpp index 38a6ddf..ae2115c 100644 --- a/src/Effect/CubismPose.cpp +++ b/src/Effect/CubismPose.cpp @@ -32,9 +32,8 @@ CubismPose::PartData::~PartData() CubismPose::PartData::PartData(const PartData& v) : ParameterIndex(0) , PartIndex(0) + , PartId(v.PartId) { - PartId = v.PartId; - for (csmVector::const_iterator ite = v.Link.Begin(); ite != v.Link.End(); ++ite) { Link.PushBack(*ite); diff --git a/src/Id/CubismId.cpp b/src/Id/CubismId.cpp index f8088ac..b6b6265 100644 --- a/src/Id/CubismId.cpp +++ b/src/Id/CubismId.cpp @@ -18,9 +18,8 @@ CubismId::CubismId(const CubismId& c) { } CubismId::CubismId(const csmChar* id) -{ - _id = id; -} + : _id(id) +{ } CubismId::~CubismId() { } diff --git a/src/Math/CubismModelMatrix.cpp b/src/Math/CubismModelMatrix.cpp index b437312..5b1433f 100644 --- a/src/Math/CubismModelMatrix.cpp +++ b/src/Math/CubismModelMatrix.cpp @@ -16,10 +16,9 @@ CubismModelMatrix::CubismModelMatrix() { } CubismModelMatrix::CubismModelMatrix(csmFloat32 w, csmFloat32 h) + : _width(w) + , _height(h) { - _width = w; - _height = h; - SetHeight(2.0f); } diff --git a/src/Physics/CubismPhysics.cpp b/src/Physics/CubismPhysics.cpp index 5cb4424..0fa446a 100644 --- a/src/Physics/CubismPhysics.cpp +++ b/src/Physics/CubismPhysics.cpp @@ -442,13 +442,13 @@ void UpdateOutputParameterValue(csmFloat32* parameterValue, csmFloat32 parameter CubismPhysics::CubismPhysics() : _physicsRig(NULL) + , _currentRemainTime(0.0f) { // set default options. _options.Gravity.Y = -1.0f; _options.Gravity.X = 0; _options.Wind.X = 0; _options.Wind.Y = 0; - _currentRemainTime = 0.0f; } CubismPhysics::~CubismPhysics() diff --git a/src/Rendering/CubismRenderer.cpp b/src/Rendering/CubismRenderer.cpp index bf89a77..201060f 100644 --- a/src/Rendering/CubismRenderer.cpp +++ b/src/Rendering/CubismRenderer.cpp @@ -157,20 +157,13 @@ csmBool CubismRenderer::IsUsingHighPrecisionMask() * CubismClippingContext ********************************************************************************************************************/ CubismClippingContext::CubismClippingContext(const csmInt32* clippingDrawableIndices, csmInt32 clipCount) -{ - // クリップしている(=マスク用の)Drawableのインデックスリスト - _clippingIdList = clippingDrawableIndices; - - // マスクの数 - _clippingIdCount = clipCount; - - _layoutChannelIndex = 0; - - _allClippedDrawRect = CSM_NEW csmRectF(); - _layoutBounds = CSM_NEW csmRectF(); - - _clippedDrawableIndexList = CSM_NEW csmVector(); -} + : _clippingIdList(clippingDrawableIndices) + , _clippingIdCount(clipCount) + , _layoutChannelIndex(0) + , _allClippedDrawRect(CSM_NEW csmRectF()) + , _layoutBounds(CSM_NEW csmRectF()) + , _clippedDrawableIndexList(CSM_NEW csmVector()) +{ } CubismClippingContext::~CubismClippingContext() { diff --git a/src/Rendering/D3D11/CubismRenderer_D3D11.cpp b/src/Rendering/D3D11/CubismRenderer_D3D11.cpp index c60237a..d1523ee 100644 --- a/src/Rendering/D3D11/CubismRenderer_D3D11.cpp +++ b/src/Rendering/D3D11/CubismRenderer_D3D11.cpp @@ -305,10 +305,9 @@ CubismRenderer_D3D11::CubismRenderer_D3D11() , _clippingManager(NULL) , _clippingContextBufferForMask(NULL) , _clippingContextBufferForDraw(NULL) + , _commandBufferNum(0) + , _commandBufferCurrent(0) { - _commandBufferNum = 0; - _commandBufferCurrent = 0; - // テクスチャ対応マップの容量を確保しておく. _textures.PrepareCapacity(32, true); } diff --git a/src/Rendering/D3D9/CubismRenderer_D3D9.cpp b/src/Rendering/D3D9/CubismRenderer_D3D9.cpp index b3b313d..6699269 100644 --- a/src/Rendering/D3D9/CubismRenderer_D3D9.cpp +++ b/src/Rendering/D3D9/CubismRenderer_D3D9.cpp @@ -294,10 +294,9 @@ CubismRenderer_D3D9::CubismRenderer_D3D9() , _clippingManager(NULL) , _clippingContextBufferForMask(NULL) , _clippingContextBufferForDraw(NULL) + , _commandBufferNum(0) + , _commandBufferCurrent(0) { - _commandBufferNum = 0; - _commandBufferCurrent = 0; - // テクスチャ対応マップの容量を確保しておく. _textures.PrepareCapacity(32, true); } From fc69c70710431fc493ffbe5474aa356d208218e3 Mon Sep 17 00:00:00 2001 From: yunimoo Date: Tue, 16 Jul 2024 18:41:19 -0400 Subject: [PATCH 2/5] Refactor to remove unnecessary lines The purpose of this commit is to remove lines that are never referenced again. --- src/Motion/CubismExpressionMotionManager.cpp | 3 --- src/Rendering/Vulkan/CubismClass_Vulkan.cpp | 1 - 2 files changed, 4 deletions(-) diff --git a/src/Motion/CubismExpressionMotionManager.cpp b/src/Motion/CubismExpressionMotionManager.cpp index d0d5616..fbca8ee 100644 --- a/src/Motion/CubismExpressionMotionManager.cpp +++ b/src/Motion/CubismExpressionMotionManager.cpp @@ -153,9 +153,6 @@ csmBool CubismExpressionMotionManager::UpdateMotion(CubismModel* model, csmFloat // ----- 最新のExpressionのフェードが完了していればそれ以前を削除する ------ if (motions->GetSize() > 1) { - CubismExpressionMotion* expressionMotion = - (CubismExpressionMotion*)(motions->At(motions->GetSize() - 1))->GetCubismMotion(); - csmFloat32 latestFadeWeight = _fadeWeights[_fadeWeights.GetSize() - 1]; if (latestFadeWeight >= 1.0f) { diff --git a/src/Rendering/Vulkan/CubismClass_Vulkan.cpp b/src/Rendering/Vulkan/CubismClass_Vulkan.cpp index 9b470fe..d4b445f 100644 --- a/src/Rendering/Vulkan/CubismClass_Vulkan.cpp +++ b/src/Rendering/Vulkan/CubismClass_Vulkan.cpp @@ -264,7 +264,6 @@ void CubismImageVulkan::SetImageLayout(VkCommandBuffer commandBuffer, VkImageLay case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; - destinationStage = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; destinationStage = VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR; break; From 4b39ba3a832b3ee8d1112a4d9c8e936c83dd1860 Mon Sep 17 00:00:00 2001 From: yunimoo Date: Tue, 16 Jul 2024 18:45:24 -0400 Subject: [PATCH 3/5] Refactor to use pre-increment on iterator The changes proposed in this commit are to improve the performance of an iterator by pre-increment style. --- src/Motion/CubismMotionQueueManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Motion/CubismMotionQueueManager.cpp b/src/Motion/CubismMotionQueueManager.cpp index 3db6cf0..7801610 100644 --- a/src/Motion/CubismMotionQueueManager.cpp +++ b/src/Motion/CubismMotionQueueManager.cpp @@ -229,7 +229,7 @@ csmBool CubismMotionQueueManager::IsFinished(CubismMotionQueueEntryHandle motion { // 既にモーションがあれば終了フラグを立てる - for (csmVector::iterator ite = _motions.Begin(); ite != _motions.End(); ite++) + for (csmVector::iterator ite = _motions.Begin(); ite != _motions.End(); ++ite) { CubismMotionQueueEntry* motionQueueEntry = *ite; From 1c96da0db37d914428112911420fec1427ab4b88 Mon Sep 17 00:00:00 2001 From: yunimoo Date: Tue, 16 Jul 2024 18:46:09 -0400 Subject: [PATCH 4/5] Prevent potential memory leak This commit aims to prevent a potential memory leak given that memory could be referenced by the pointer. Freeing the pointer first, then assigning to new memory space should prevent this. --- src/Rendering/Vulkan/CubismOffscreenSurface_Vulkan.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Rendering/Vulkan/CubismOffscreenSurface_Vulkan.cpp b/src/Rendering/Vulkan/CubismOffscreenSurface_Vulkan.cpp index 121f1ab..b422873 100644 --- a/src/Rendering/Vulkan/CubismOffscreenSurface_Vulkan.cpp +++ b/src/Rendering/Vulkan/CubismOffscreenSurface_Vulkan.cpp @@ -80,6 +80,10 @@ void CubismOffscreenSurface_Vulkan::CreateOffscreenSurface( csmUint32 displayBufferWidth, csmUint32 displayBufferHeight, VkFormat surfaceFormat, VkFormat depthFormat) { + if (_colorImage != nullptr) { + vkFreeMemory(device, _colorImage, nullptr); + } + _colorImage = new CubismImageVulkan; _colorImage->CreateImage(device, physicalDevice, displayBufferWidth, displayBufferHeight, 1, surfaceFormat, VK_IMAGE_TILING_OPTIMAL, From c38c91d2db436454336315bcad955c5c9ea1781a Mon Sep 17 00:00:00 2001 From: yunimoo Date: Tue, 16 Jul 2024 18:48:07 -0400 Subject: [PATCH 5/5] Add const qualifiers for safety --- src/Rendering/Vulkan/CubismRenderer_Vulkan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rendering/Vulkan/CubismRenderer_Vulkan.cpp b/src/Rendering/Vulkan/CubismRenderer_Vulkan.cpp index ae3dbdc..13f33df 100644 --- a/src/Rendering/Vulkan/CubismRenderer_Vulkan.cpp +++ b/src/Rendering/Vulkan/CubismRenderer_Vulkan.cpp @@ -271,7 +271,7 @@ VkShaderModule CubismPipeline_Vulkan::PipelineResource::CreateShaderModule(VkDev return shaderModule; } -void CubismPipeline_Vulkan::PipelineResource::CreateGraphicsPipeline(std::string vertFileName, std::string fragFileName, +void CubismPipeline_Vulkan::PipelineResource::CreateGraphicsPipeline(const std::string vertFileName, const std::string fragFileName, VkDescriptorSetLayout descriptorSetLayout) { VkShaderModule vertShaderModule = CreateShaderModule(s_device, vertFileName);