From 02a1eb0f55faa8e483af94fccada65d8f1681a91 Mon Sep 17 00:00:00 2001 From: minggo Date: Mon, 4 Jul 2022 10:20:07 +0800 Subject: [PATCH] Use raw pointer (#11804) * Revert "use IntrusivePtr to share object (#11729)" This reverts commit 8caec597116a0980704e90520105da0fd4d923f3. * Framebuffer uses weak reference * make doDestroy reentency --- native/cocos/base/Agent.h | 3 +- native/cocos/engine/Engine.cpp | 2 +- .../cocos/renderer/gfx-agent/BufferAgent.cpp | 2 +- .../renderer/gfx-agent/CommandBufferAgent.cpp | 2 +- .../renderer/gfx-agent/DescriptorSetAgent.cpp | 2 +- .../gfx-agent/DescriptorSetLayoutAgent.cpp | 2 +- .../cocos/renderer/gfx-agent/DeviceAgent.cpp | 31 ++++++++++------ .../renderer/gfx-agent/FramebufferAgent.cpp | 2 +- .../gfx-agent/InputAssemblerAgent.cpp | 2 +- .../gfx-agent/PipelineLayoutAgent.cpp | 2 +- .../renderer/gfx-agent/PipelineStateAgent.cpp | 2 +- .../renderer/gfx-agent/QueryPoolAgent.cpp | 2 +- .../cocos/renderer/gfx-agent/QueueAgent.cpp | 2 +- .../renderer/gfx-agent/RenderPassAgent.cpp | 2 +- .../cocos/renderer/gfx-agent/ShaderAgent.cpp | 2 +- .../renderer/gfx-agent/SwapchainAgent.cpp | 2 +- .../cocos/renderer/gfx-agent/TextureAgent.cpp | 2 +- native/cocos/renderer/gfx-base/GFXDevice.cpp | 6 ++- native/cocos/renderer/gfx-base/GFXDevice.h | 6 +-- .../cocos/renderer/gfx-base/GFXFramebuffer.h | 12 +++--- native/cocos/renderer/gfx-base/GFXQueryPool.h | 3 +- native/cocos/renderer/gfx-base/GFXSwapchain.h | 3 +- .../cocos/renderer/gfx-gles2/GLES2Device.cpp | 9 ++--- .../renderer/gfx-gles2/GLES2Framebuffer.cpp | 6 +-- .../cocos/renderer/gfx-gles3/GLES3Device.cpp | 8 ++-- .../renderer/gfx-gles3/GLES3Framebuffer.cpp | 6 +-- native/cocos/renderer/gfx-metal/MTLDevice.mm | 14 +++---- .../renderer/gfx-metal/MTLFramebuffer.mm | 2 +- .../gfx-validator/BufferValidator.cpp | 1 + .../gfx-validator/CommandBufferValidator.cpp | 1 + .../DescriptorSetLayoutValidator.cpp | 1 + .../gfx-validator/DescriptorSetValidator.cpp | 1 + .../gfx-validator/DeviceValidator.cpp | 37 +++++++++++-------- .../gfx-validator/FramebufferValidator.cpp | 1 + .../gfx-validator/InputAssemblerValidator.cpp | 1 + .../gfx-validator/PipelineLayoutValidator.cpp | 1 + .../gfx-validator/PipelineStateValidator.cpp | 1 + .../gfx-validator/QueryPoolValidator.cpp | 1 + .../renderer/gfx-validator/QueueValidator.cpp | 1 + .../gfx-validator/RenderPassValidator.cpp | 1 + .../gfx-validator/ShaderValidator.cpp | 1 + .../gfx-validator/SwapchainValidator.cpp | 1 + .../gfx-validator/TextureValidator.cpp | 1 + native/cocos/renderer/gfx-vulkan/VKDevice.cpp | 13 +++---- .../renderer/gfx-vulkan/VKFramebuffer.cpp | 6 +-- 45 files changed, 119 insertions(+), 90 deletions(-) diff --git a/native/cocos/base/Agent.h b/native/cocos/base/Agent.h index e2fa55a5a79..8afe77b53a6 100644 --- a/native/cocos/base/Agent.h +++ b/native/cocos/base/Agent.h @@ -27,7 +27,6 @@ #include #include "Macros.h" -#include "base/Ptr.h" namespace cc { @@ -52,7 +51,7 @@ class CC_DLL Agent : public Actor { inline Actor *getActor() const noexcept { return _actor; } protected: - IntrusivePtr _actor; + Actor *_actor{nullptr}; }; } // namespace cc diff --git a/native/cocos/engine/Engine.cpp b/native/cocos/engine/Engine.cpp index 856ba86c3c6..0e0049aff0c 100644 --- a/native/cocos/engine/Engine.cpp +++ b/native/cocos/engine/Engine.cpp @@ -180,7 +180,7 @@ void Engine::destroy() { delete _builtinResMgr; delete _programLib; - CC_SAFE_DELETE(_gfxDevice); + CC_SAFE_DESTROY_AND_DELETE(_gfxDevice); delete _fs; _scheduler.reset(); diff --git a/native/cocos/renderer/gfx-agent/BufferAgent.cpp b/native/cocos/renderer/gfx-agent/BufferAgent.cpp index 6ddeb98456a..3f8ef822826 100644 --- a/native/cocos/renderer/gfx-agent/BufferAgent.cpp +++ b/native/cocos/renderer/gfx-agent/BufferAgent.cpp @@ -43,7 +43,7 @@ BufferAgent::~BufferAgent() { BufferDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } diff --git a/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp b/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp index 5649e5c180e..930db339d42 100644 --- a/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp +++ b/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp @@ -83,7 +83,7 @@ CommandBufferAgent::~CommandBufferAgent() { DeviceAgent::getInstance()->getMessageQueue(), CommandBufferDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } diff --git a/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp b/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp index ccfff612110..a02a5cb265d 100644 --- a/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp +++ b/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp @@ -45,7 +45,7 @@ DescriptorSetAgent::~DescriptorSetAgent() { DescriptorSetDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } diff --git a/native/cocos/renderer/gfx-agent/DescriptorSetLayoutAgent.cpp b/native/cocos/renderer/gfx-agent/DescriptorSetLayoutAgent.cpp index ada925a7027..88031d0b0e0 100644 --- a/native/cocos/renderer/gfx-agent/DescriptorSetLayoutAgent.cpp +++ b/native/cocos/renderer/gfx-agent/DescriptorSetLayoutAgent.cpp @@ -42,7 +42,7 @@ DescriptorSetLayoutAgent::~DescriptorSetLayoutAgent() { DescriptorSetLayoutDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } diff --git a/native/cocos/renderer/gfx-agent/DeviceAgent.cpp b/native/cocos/renderer/gfx-agent/DeviceAgent.cpp index 75e594fdda1..f1f54fd5230 100644 --- a/native/cocos/renderer/gfx-agent/DeviceAgent.cpp +++ b/native/cocos/renderer/gfx-agent/DeviceAgent.cpp @@ -59,7 +59,7 @@ DeviceAgent::DeviceAgent(Device *device) : Agent(device) { } DeviceAgent::~DeviceAgent() { - destroy(); + CC_SAFE_DELETE(_actor); DeviceAgent::instance = nullptr; } @@ -83,8 +83,8 @@ bool DeviceAgent::doInit(const DeviceInfo &info) { // TODO(PatriceJiang): replace with: _mainMessageQueue = ccnew MessageQueue; _mainMessageQueue = ccnew_placement(CC_MALLOC_ALIGN(sizeof(MessageQueue), alignof(MessageQueue))) MessageQueue; // NOLINT - static_cast(_cmdBuff.get())->_queue = _queue; - static_cast(_cmdBuff.get())->initAgent(); + static_cast(_cmdBuff)->_queue = _queue; + static_cast(_cmdBuff)->initAgent(); setMultithreaded(true); @@ -96,18 +96,25 @@ void DeviceAgent::doDestroy() { _mainMessageQueue, DeviceDestroy, actor, _actor, { - if (actor) { - actor->destroy(); - } + actor->destroy(); }); if (_cmdBuff) { - static_cast(_cmdBuff.get())->destroyAgent(); + static_cast(_cmdBuff)->destroyAgent(); + static_cast(_cmdBuff)->_actor = nullptr; + delete _cmdBuff; _cmdBuff = nullptr; } - - _queryPool = nullptr; - _queue = nullptr; + if (_queryPool) { + static_cast(_queryPool)->_actor = nullptr; + delete _queryPool; + _queryPool = nullptr; + } + if (_queue) { + static_cast(_queue)->_actor = nullptr; + delete _queue; + _queue = nullptr; + } if (_mainMessageQueue) { _mainMessageQueue->terminateConsumerThread(); @@ -352,11 +359,11 @@ void doBufferTextureCopy(const uint8_t *const *buffers, Texture *texture, const } void DeviceAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) { - doBufferTextureCopy(buffers, dst, regions, count, _mainMessageQueue, _actor.get()); + doBufferTextureCopy(buffers, dst, regions, count, _mainMessageQueue, _actor); } void CommandBufferAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) { - doBufferTextureCopy(buffers, texture, regions, count, _messageQueue, _actor.get()); + doBufferTextureCopy(buffers, texture, regions, count, _messageQueue, _actor); } void DeviceAgent::copyTextureToBuffers(Texture *srcTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint32_t count) { diff --git a/native/cocos/renderer/gfx-agent/FramebufferAgent.cpp b/native/cocos/renderer/gfx-agent/FramebufferAgent.cpp index c715a4debec..4f5ad304e63 100644 --- a/native/cocos/renderer/gfx-agent/FramebufferAgent.cpp +++ b/native/cocos/renderer/gfx-agent/FramebufferAgent.cpp @@ -44,7 +44,7 @@ FramebufferAgent::~FramebufferAgent() { FramebufferDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } diff --git a/native/cocos/renderer/gfx-agent/InputAssemblerAgent.cpp b/native/cocos/renderer/gfx-agent/InputAssemblerAgent.cpp index 8b81f23da3a..88e8913317a 100644 --- a/native/cocos/renderer/gfx-agent/InputAssemblerAgent.cpp +++ b/native/cocos/renderer/gfx-agent/InputAssemblerAgent.cpp @@ -43,7 +43,7 @@ InputAssemblerAgent::~InputAssemblerAgent() { InputAssemblerDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } diff --git a/native/cocos/renderer/gfx-agent/PipelineLayoutAgent.cpp b/native/cocos/renderer/gfx-agent/PipelineLayoutAgent.cpp index 7351e28f315..0bc89d59c84 100644 --- a/native/cocos/renderer/gfx-agent/PipelineLayoutAgent.cpp +++ b/native/cocos/renderer/gfx-agent/PipelineLayoutAgent.cpp @@ -43,7 +43,7 @@ PipelineLayoutAgent::~PipelineLayoutAgent() { PipelineLayoutDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } diff --git a/native/cocos/renderer/gfx-agent/PipelineStateAgent.cpp b/native/cocos/renderer/gfx-agent/PipelineStateAgent.cpp index 3f4db17f2e4..5478014b4ce 100644 --- a/native/cocos/renderer/gfx-agent/PipelineStateAgent.cpp +++ b/native/cocos/renderer/gfx-agent/PipelineStateAgent.cpp @@ -45,7 +45,7 @@ PipelineStateAgent::~PipelineStateAgent() { PipelineStateDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } diff --git a/native/cocos/renderer/gfx-agent/QueryPoolAgent.cpp b/native/cocos/renderer/gfx-agent/QueryPoolAgent.cpp index 69eca3c8ae1..928972c2afe 100644 --- a/native/cocos/renderer/gfx-agent/QueryPoolAgent.cpp +++ b/native/cocos/renderer/gfx-agent/QueryPoolAgent.cpp @@ -46,7 +46,7 @@ QueryPoolAgent::~QueryPoolAgent() { QueryDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } diff --git a/native/cocos/renderer/gfx-agent/QueueAgent.cpp b/native/cocos/renderer/gfx-agent/QueueAgent.cpp index d049b6ca4c0..79372e08e0f 100644 --- a/native/cocos/renderer/gfx-agent/QueueAgent.cpp +++ b/native/cocos/renderer/gfx-agent/QueueAgent.cpp @@ -44,7 +44,7 @@ QueueAgent::~QueueAgent() { QueueDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } diff --git a/native/cocos/renderer/gfx-agent/RenderPassAgent.cpp b/native/cocos/renderer/gfx-agent/RenderPassAgent.cpp index c764a82e45c..a181692804b 100644 --- a/native/cocos/renderer/gfx-agent/RenderPassAgent.cpp +++ b/native/cocos/renderer/gfx-agent/RenderPassAgent.cpp @@ -42,7 +42,7 @@ RenderPassAgent::~RenderPassAgent() { RenderPassDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } diff --git a/native/cocos/renderer/gfx-agent/ShaderAgent.cpp b/native/cocos/renderer/gfx-agent/ShaderAgent.cpp index 9f6071618e3..37910b4afa4 100644 --- a/native/cocos/renderer/gfx-agent/ShaderAgent.cpp +++ b/native/cocos/renderer/gfx-agent/ShaderAgent.cpp @@ -42,7 +42,7 @@ ShaderAgent::~ShaderAgent() { ShaderDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } diff --git a/native/cocos/renderer/gfx-agent/SwapchainAgent.cpp b/native/cocos/renderer/gfx-agent/SwapchainAgent.cpp index 5ea054981d5..794e72b12f2 100644 --- a/native/cocos/renderer/gfx-agent/SwapchainAgent.cpp +++ b/native/cocos/renderer/gfx-agent/SwapchainAgent.cpp @@ -43,7 +43,7 @@ SwapchainAgent::~SwapchainAgent() { DeviceAgent::getInstance()->getMessageQueue(), SwapchainDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } diff --git a/native/cocos/renderer/gfx-agent/TextureAgent.cpp b/native/cocos/renderer/gfx-agent/TextureAgent.cpp index 9ec7ece0105..15faaae43e9 100644 --- a/native/cocos/renderer/gfx-agent/TextureAgent.cpp +++ b/native/cocos/renderer/gfx-agent/TextureAgent.cpp @@ -45,7 +45,7 @@ TextureAgent::~TextureAgent() { TextureDestruct, actor, _actor, { - actor = nullptr; + CC_SAFE_DELETE(actor); }); } } diff --git a/native/cocos/renderer/gfx-base/GFXDevice.cpp b/native/cocos/renderer/gfx-base/GFXDevice.cpp index ea67b5b2b80..415da620c94 100644 --- a/native/cocos/renderer/gfx-base/GFXDevice.cpp +++ b/native/cocos/renderer/gfx-base/GFXDevice.cpp @@ -61,7 +61,11 @@ bool Device::initialize(const DeviceInfo &info) { static_assert(sizeof(void *) == 8, "pointer size assumption broken"); #endif - return doInit(info); + bool result = doInit(info); + _cmdBuff->addRef(); + _queue->addRef(); + + return result; } void Device::destroy() { diff --git a/native/cocos/renderer/gfx-base/GFXDevice.h b/native/cocos/renderer/gfx-base/GFXDevice.h index c42bcd5cf7d..cb74d477d5d 100644 --- a/native/cocos/renderer/gfx-base/GFXDevice.h +++ b/native/cocos/renderer/gfx-base/GFXDevice.h @@ -173,9 +173,9 @@ class CC_DLL Device : public RefCounted { ccstd::array(Feature::COUNT)> _features; ccstd::array(Format::COUNT)> _formatFeatures; - IntrusivePtr _queue; - IntrusivePtr _queryPool; - IntrusivePtr _cmdBuff; + Queue *_queue{nullptr}; + QueryPool *_queryPool{nullptr}; + CommandBuffer *_cmdBuff{nullptr}; Executable *_onAcquire{nullptr}; uint32_t _numDrawCalls{0U}; diff --git a/native/cocos/renderer/gfx-base/GFXFramebuffer.h b/native/cocos/renderer/gfx-base/GFXFramebuffer.h index 0c9968c9d0e..1c74c07005a 100644 --- a/native/cocos/renderer/gfx-base/GFXFramebuffer.h +++ b/native/cocos/renderer/gfx-base/GFXFramebuffer.h @@ -44,17 +44,19 @@ class CC_DLL Framebuffer : public GFXObject, public RefCounted { void destroy(); inline RenderPass *getRenderPass() const { return _renderPass; } - inline const TextureList &getColorTextures() const { return _colorTextures.get(); } + inline const TextureList &getColorTextures() const { return _colorTextures; } inline Texture *getDepthStencilTexture() const { return _depthStencilTexture; } protected: virtual void doInit(const FramebufferInfo &info) = 0; virtual void doDestroy() = 0; - IntrusivePtr _renderPass; - // To keep compatibility, so don't use IntrusivePtr. - RefVector _colorTextures; - IntrusivePtr _depthStencilTexture; + // weak reference + RenderPass *_renderPass{nullptr}; + // weak reference + TextureList _colorTextures; + // weak reference + Texture *_depthStencilTexture{nullptr}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-base/GFXQueryPool.h b/native/cocos/renderer/gfx-base/GFXQueryPool.h index 801774b08a6..adbba028098 100644 --- a/native/cocos/renderer/gfx-base/GFXQueryPool.h +++ b/native/cocos/renderer/gfx-base/GFXQueryPool.h @@ -28,7 +28,6 @@ #include #include #include "GFXObject.h" -#include "base/RefCounted.h" #include "base/std/container/unordered_map.h" namespace cc { @@ -47,7 +46,7 @@ namespace gfx { * completeQueryPool */ -class CC_DLL QueryPool : public GFXObject, public RefCounted { +class CC_DLL QueryPool : public GFXObject { public: QueryPool(); ~QueryPool() override; diff --git a/native/cocos/renderer/gfx-base/GFXSwapchain.h b/native/cocos/renderer/gfx-base/GFXSwapchain.h index b7bd06d17e7..a6fa56de2df 100644 --- a/native/cocos/renderer/gfx-base/GFXSwapchain.h +++ b/native/cocos/renderer/gfx-base/GFXSwapchain.h @@ -27,13 +27,12 @@ #include "GFXTexture.h" #include "base/Ptr.h" -#include "base/RefCounted.h" #include "gfx-base/GFXDef-common.h" namespace cc { namespace gfx { -class CC_DLL Swapchain : public GFXObject, public RefCounted { +class CC_DLL Swapchain : public GFXObject { public: Swapchain(); ~Swapchain() override; diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp index 33325492d8f..ff2f3d6433a 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp @@ -228,10 +228,9 @@ void GLES2Device::doDestroy() { CC_ASSERT(!_memoryStatus.bufferSize); // Buffer memory leaked. CC_ASSERT(!_memoryStatus.textureSize); // Texture memory leaked. - _queryPool = nullptr; - _queue = nullptr; - _cmdBuff = nullptr; - + CC_SAFE_DESTROY_AND_DELETE(_cmdBuff) + CC_SAFE_DESTROY_AND_DELETE(_queryPool) + CC_SAFE_DESTROY_AND_DELETE(_queue) CC_SAFE_DESTROY_AND_DELETE(_gpuContext) } @@ -246,7 +245,7 @@ void GLES2Device::acquire(Swapchain *const *swapchains, uint32_t count) { void GLES2Device::present() { CC_PROFILE(GLES2DevicePresent); - auto *queue = static_cast(_queue.get()); + auto *queue = static_cast(_queue); _numDrawCalls = queue->_numDrawCalls; _numInstances = queue->_numInstances; _numTriangles = queue->_numTriangles; diff --git a/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp index a9ab512c030..ae3649cc64c 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp @@ -44,7 +44,7 @@ GLES2Framebuffer::~GLES2Framebuffer() { void GLES2Framebuffer::doInit(const FramebufferInfo & /*info*/) { _gpuFBO = ccnew GLES2GPUFramebuffer; - _gpuFBO->gpuRenderPass = static_cast(_renderPass.get())->gpuRenderPass(); + _gpuFBO->gpuRenderPass = static_cast(_renderPass)->gpuRenderPass(); _gpuFBO->gpuColorTextures.resize(_colorTextures.size()); for (size_t i = 0; i < _colorTextures.size(); ++i) { @@ -55,7 +55,7 @@ void GLES2Framebuffer::doInit(const FramebufferInfo & /*info*/) { } if (_depthStencilTexture) { - auto *depthTexture = static_cast(_depthStencilTexture.get()); + auto *depthTexture = static_cast(_depthStencilTexture); _gpuFBO->gpuDepthStencilTexture = depthTexture->gpuTexture(); _gpuFBO->lodLevel = depthTexture->getViewInfo().baseLevel; GLES2Device::getInstance()->framebufferHub()->connect(depthTexture->gpuTexture(), _gpuFBO); @@ -73,7 +73,7 @@ void GLES2Framebuffer::doDestroy() { GLES2Device::getInstance()->framebufferHub()->disengage(colorTexture->gpuTexture(), _gpuFBO); } if (_depthStencilTexture) { - auto *depthTexture = static_cast(_depthStencilTexture.get()); + auto *depthTexture = static_cast(_depthStencilTexture); GLES2Device::getInstance()->framebufferHub()->disengage(depthTexture->gpuTexture(), _gpuFBO); } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp index c0df9910ee5..1ed8e04628f 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp @@ -236,9 +236,9 @@ void GLES3Device::doDestroy() { CC_ASSERT(!_memoryStatus.bufferSize); // Buffer memory leaked CC_ASSERT(!_memoryStatus.textureSize); // Texture memory leaked - _cmdBuff = nullptr; - _queryPool = nullptr; - _queue = nullptr; + CC_SAFE_DESTROY_AND_DELETE(_cmdBuff) + CC_SAFE_DESTROY_AND_DELETE(_queryPool) + CC_SAFE_DESTROY_AND_DELETE(_queue) CC_SAFE_DESTROY_AND_DELETE(_gpuContext) } @@ -253,7 +253,7 @@ void GLES3Device::acquire(Swapchain *const *swapchains, uint32_t count) { void GLES3Device::present() { CC_PROFILE(GLES3DevicePresent); - auto *queue = static_cast(_queue.get()); + auto *queue = static_cast(_queue); _numDrawCalls = queue->_numDrawCalls; _numInstances = queue->_numInstances; _numTriangles = queue->_numTriangles; diff --git a/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp index e24c5f7fa12..a229c61f99f 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp @@ -44,7 +44,7 @@ GLES3Framebuffer::~GLES3Framebuffer() { void GLES3Framebuffer::doInit(const FramebufferInfo & /*info*/) { _gpuFBO = ccnew GLES3GPUFramebuffer; - _gpuFBO->gpuRenderPass = static_cast(_renderPass.get())->gpuRenderPass(); + _gpuFBO->gpuRenderPass = static_cast(_renderPass)->gpuRenderPass(); _gpuFBO->gpuColorViews.resize(_colorTextures.size()); for (size_t i = 0; i < _colorTextures.size(); ++i) { @@ -54,7 +54,7 @@ void GLES3Framebuffer::doInit(const FramebufferInfo & /*info*/) { } if (_depthStencilTexture) { - auto *depthTexture = static_cast(_depthStencilTexture.get()); + auto *depthTexture = static_cast(_depthStencilTexture); _gpuFBO->gpuDepthStencilView = depthTexture->gpuTextureView(); GLES3Device::getInstance()->framebufferHub()->connect(depthTexture->gpuTexture(), _gpuFBO); } @@ -71,7 +71,7 @@ void GLES3Framebuffer::doDestroy() { GLES3Device::getInstance()->framebufferHub()->disengage(colorTexture->gpuTexture(), _gpuFBO); } if (_depthStencilTexture) { - auto *depthTexture = static_cast(_depthStencilTexture.get()); + auto *depthTexture = static_cast(_depthStencilTexture); GLES3Device::getInstance()->framebufferHub()->disengage(depthTexture->gpuTexture(), _gpuFBO); } diff --git a/native/cocos/renderer/gfx-metal/MTLDevice.mm b/native/cocos/renderer/gfx-metal/MTLDevice.mm index 9bb69e26ef2..59622144c87 100644 --- a/native/cocos/renderer/gfx-metal/MTLDevice.mm +++ b/native/cocos/renderer/gfx-metal/MTLDevice.mm @@ -156,9 +156,9 @@ of this software and associated engine source code (the "Software"), a limited, CC_SAFE_DELETE(_gpuDeviceObj); - _queryPool = nullptr; - _queue = nullptr; - _cmdBuff = nullptr; + CC_SAFE_DESTROY_AND_DELETE(_queryPool) + CC_SAFE_DESTROY_AND_DELETE(_queue); + CC_SAFE_DESTROY_AND_DELETE(_cmdBuff); CCMTLGPUGarbageCollectionPool::getInstance()->flush(); @@ -193,7 +193,7 @@ of this software and associated engine source code (the "Software"), a limited, } // Clear queue stats - CCMTLQueue *queue = static_cast(_queue.get()); + CCMTLQueue *queue = static_cast(_queue); queue->gpuQueueObj()->numDrawCalls = 0; queue->gpuQueueObj()->numInstances = 0; queue->gpuQueueObj()->numTriangles = 0; @@ -201,7 +201,7 @@ of this software and associated engine source code (the "Software"), a limited, void CCMTLDevice::present() { CC_PROFILE(CCMTLDevicePresent); - CCMTLQueue *queue = static_cast(_queue.get()); + CCMTLQueue *queue = (CCMTLQueue *)_queue; _numDrawCalls = queue->gpuQueueObj()->numDrawCalls; _numInstances = queue->gpuQueueObj()->numInstances; _numTriangles = queue->gpuQueueObj()->numTriangles; @@ -313,12 +313,12 @@ of this software and associated engine source code (the "Software"), a limited, // the wiggle room to leverage immediate update vs. copy-upload strategies without // breaking compatibilities. When we reached some conclusion on this subject, // getting rid of this interface all together may become a better option. - static_cast(_cmdBuff.get())->copyBuffersToTexture(buffers, texture, regions, count); + static_cast(_cmdBuff)->copyBuffersToTexture(buffers, texture, regions, count); } void CCMTLDevice::copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) { CC_PROFILE(CCMTLDeviceCopyTextureToBuffers); - static_cast(_cmdBuff.get())->copyTextureToBuffers(src, buffers, region, count); + static_cast(_cmdBuff)->copyTextureToBuffers(src, buffers, region, count); } void CCMTLDevice::getQueryPoolResults(QueryPool *queryPool) { diff --git a/native/cocos/renderer/gfx-metal/MTLFramebuffer.mm b/native/cocos/renderer/gfx-metal/MTLFramebuffer.mm index 9da798dbc20..bc2d40b280c 100644 --- a/native/cocos/renderer/gfx-metal/MTLFramebuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLFramebuffer.mm @@ -50,7 +50,7 @@ of this software and associated engine source code (the "Software"), a limited, } if (_depthStencilTexture) { - auto* ccTex = static_cast(_depthStencilTexture.get()); + auto* ccTex = static_cast(_depthStencilTexture); if (ccTex->swapChain()) { _swapChain = ccTex->swapChain(); _isOffscreen = false; diff --git a/native/cocos/renderer/gfx-validator/BufferValidator.cpp b/native/cocos/renderer/gfx-validator/BufferValidator.cpp index 425823260f4..bdc9f9f8bc0 100644 --- a/native/cocos/renderer/gfx-validator/BufferValidator.cpp +++ b/native/cocos/renderer/gfx-validator/BufferValidator.cpp @@ -39,6 +39,7 @@ BufferValidator::BufferValidator(Buffer *actor) BufferValidator::~BufferValidator() { DeviceResourceTracker::erase(this); + CC_SAFE_DELETE(_actor); uint64_t lifeTime = DeviceValidator::getInstance()->currentFrame() - _creationFrame; // skip those that have never been updated diff --git a/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp b/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp index 26c9c887a42..df0b19a71d9 100644 --- a/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp +++ b/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp @@ -50,6 +50,7 @@ CommandBufferValidator::CommandBufferValidator(CommandBuffer *actor) CommandBufferValidator::~CommandBufferValidator() { DeviceResourceTracker::erase(this); + CC_SAFE_DELETE(_actor); } void CommandBufferValidator::initValidator() { diff --git a/native/cocos/renderer/gfx-validator/DescriptorSetLayoutValidator.cpp b/native/cocos/renderer/gfx-validator/DescriptorSetLayoutValidator.cpp index 6f2081b5d39..de32db9a9e7 100644 --- a/native/cocos/renderer/gfx-validator/DescriptorSetLayoutValidator.cpp +++ b/native/cocos/renderer/gfx-validator/DescriptorSetLayoutValidator.cpp @@ -41,6 +41,7 @@ DescriptorSetLayoutValidator::DescriptorSetLayoutValidator(DescriptorSetLayout * DescriptorSetLayoutValidator::~DescriptorSetLayoutValidator() { DeviceResourceTracker::erase(this); + CC_SAFE_DELETE(_actor); } void DescriptorSetLayoutValidator::doInit(const DescriptorSetLayoutInfo &info) { diff --git a/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp b/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp index 8ba346b9193..38b1018ce6a 100644 --- a/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp +++ b/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp @@ -43,6 +43,7 @@ DescriptorSetValidator::DescriptorSetValidator(DescriptorSet *actor) DescriptorSetValidator::~DescriptorSetValidator() { DeviceResourceTracker::erase(this); + CC_SAFE_DELETE(_actor); } void DescriptorSetValidator::doInit(const DescriptorSetInfo &info) { diff --git a/native/cocos/renderer/gfx-validator/DeviceValidator.cpp b/native/cocos/renderer/gfx-validator/DeviceValidator.cpp index 3807ccf3a8a..84a0da97120 100644 --- a/native/cocos/renderer/gfx-validator/DeviceValidator.cpp +++ b/native/cocos/renderer/gfx-validator/DeviceValidator.cpp @@ -60,7 +60,7 @@ DeviceValidator::DeviceValidator(Device *device) : Agent(device) { } DeviceValidator::~DeviceValidator() { - destroy(); + CC_SAFE_DELETE(_actor); DeviceValidator::instance = nullptr; } @@ -89,14 +89,14 @@ bool DeviceValidator::doInit(const DeviceInfo &info) { memcpy(_features.data(), _actor->_features.data(), static_cast(Feature::COUNT) * sizeof(bool)); memcpy(_formatFeatures.data(), _actor->_formatFeatures.data(), static_cast(Format::COUNT) * sizeof(FormatFeatureBit)); - static_cast(_queue.get())->_inited = true; - static_cast(_queryPool.get())->_inited = true; - static_cast(_cmdBuff.get())->_queue = _queue; - static_cast(_cmdBuff.get())->initValidator(); + static_cast(_queue)->_inited = true; + static_cast(_queryPool)->_inited = true; + static_cast(_cmdBuff)->_queue = _queue; + static_cast(_cmdBuff)->initValidator(); - DeviceResourceTracker::push(_cmdBuff.get()); - DeviceResourceTracker::push(_queryPool.get()); - DeviceResourceTracker::push(_queue.get()); + DeviceResourceTracker::push(_cmdBuff); + DeviceResourceTracker::push(_queryPool); + DeviceResourceTracker::push(_queue); CC_LOG_INFO("Device validator enabled."); @@ -105,12 +105,21 @@ bool DeviceValidator::doInit(const DeviceInfo &info) { void DeviceValidator::doDestroy() { if (_cmdBuff) { - static_cast(_cmdBuff.get())->destroyValidator(); + static_cast(_cmdBuff)->destroyValidator(); + static_cast(_cmdBuff)->_actor = nullptr; + delete _cmdBuff; _cmdBuff = nullptr; } - - _queryPool = nullptr; - _queue = nullptr; + if (_queryPool) { + static_cast(_queryPool)->_actor = nullptr; + delete _queryPool; + _queryPool = nullptr; + } + if (_queue) { + static_cast(_queue)->_actor = nullptr; + delete _queue; + _queue = nullptr; + } DeviceResourceTracker::checkEmpty(); DeviceResourceTracker::checkEmpty(); @@ -128,9 +137,7 @@ void DeviceValidator::doDestroy() { DeviceResourceTracker::checkEmpty(); DeviceResourceTracker::checkEmpty(); - if (_actor) { - _actor->destroy(); - } + _actor->destroy(); } void DeviceValidator::acquire(Swapchain *const *swapchains, uint32_t count) { diff --git a/native/cocos/renderer/gfx-validator/FramebufferValidator.cpp b/native/cocos/renderer/gfx-validator/FramebufferValidator.cpp index 4693869bc8f..9ca0815658a 100644 --- a/native/cocos/renderer/gfx-validator/FramebufferValidator.cpp +++ b/native/cocos/renderer/gfx-validator/FramebufferValidator.cpp @@ -42,6 +42,7 @@ FramebufferValidator::FramebufferValidator(Framebuffer *actor) FramebufferValidator::~FramebufferValidator() { DeviceResourceTracker::erase(this); + CC_SAFE_DELETE(_actor); } void FramebufferValidator::doInit(const FramebufferInfo &info) { diff --git a/native/cocos/renderer/gfx-validator/InputAssemblerValidator.cpp b/native/cocos/renderer/gfx-validator/InputAssemblerValidator.cpp index fac7d2450fb..7b9cbdbc5d8 100644 --- a/native/cocos/renderer/gfx-validator/InputAssemblerValidator.cpp +++ b/native/cocos/renderer/gfx-validator/InputAssemblerValidator.cpp @@ -40,6 +40,7 @@ InputAssemblerValidator::InputAssemblerValidator(InputAssembler *actor) InputAssemblerValidator::~InputAssemblerValidator() { DeviceResourceTracker::erase(this); + CC_SAFE_DELETE(_actor); } void InputAssemblerValidator::doInit(const InputAssemblerInfo &info) { diff --git a/native/cocos/renderer/gfx-validator/PipelineLayoutValidator.cpp b/native/cocos/renderer/gfx-validator/PipelineLayoutValidator.cpp index 1a6cc15297c..2273fbd48d8 100644 --- a/native/cocos/renderer/gfx-validator/PipelineLayoutValidator.cpp +++ b/native/cocos/renderer/gfx-validator/PipelineLayoutValidator.cpp @@ -41,6 +41,7 @@ PipelineLayoutValidator::PipelineLayoutValidator(PipelineLayout *actor) PipelineLayoutValidator::~PipelineLayoutValidator() { DeviceResourceTracker::erase(this); + CC_SAFE_DELETE(_actor); } void PipelineLayoutValidator::doInit(const PipelineLayoutInfo &info) { diff --git a/native/cocos/renderer/gfx-validator/PipelineStateValidator.cpp b/native/cocos/renderer/gfx-validator/PipelineStateValidator.cpp index 8a29b3992e8..46c01aedcd7 100644 --- a/native/cocos/renderer/gfx-validator/PipelineStateValidator.cpp +++ b/native/cocos/renderer/gfx-validator/PipelineStateValidator.cpp @@ -42,6 +42,7 @@ PipelineStateValidator::PipelineStateValidator(PipelineState *actor) PipelineStateValidator::~PipelineStateValidator() { DeviceResourceTracker::erase(this); + CC_SAFE_DELETE(_actor); } void PipelineStateValidator::doInit(const PipelineStateInfo &info) { diff --git a/native/cocos/renderer/gfx-validator/QueryPoolValidator.cpp b/native/cocos/renderer/gfx-validator/QueryPoolValidator.cpp index 1f3508803b1..3e49eb2f87b 100644 --- a/native/cocos/renderer/gfx-validator/QueryPoolValidator.cpp +++ b/native/cocos/renderer/gfx-validator/QueryPoolValidator.cpp @@ -40,6 +40,7 @@ QueryPoolValidator::QueryPoolValidator(QueryPool *actor) QueryPoolValidator::~QueryPoolValidator() { DeviceResourceTracker::erase(this); + CC_SAFE_DELETE(_actor); } void QueryPoolValidator::doInit(const QueryPoolInfo &info) { diff --git a/native/cocos/renderer/gfx-validator/QueueValidator.cpp b/native/cocos/renderer/gfx-validator/QueueValidator.cpp index 4010ea2c0a2..f01089ea4cc 100644 --- a/native/cocos/renderer/gfx-validator/QueueValidator.cpp +++ b/native/cocos/renderer/gfx-validator/QueueValidator.cpp @@ -38,6 +38,7 @@ QueueValidator::QueueValidator(Queue *actor) QueueValidator::~QueueValidator() { DeviceResourceTracker::erase(this); + CC_SAFE_DELETE(_actor); } void QueueValidator::doInit(const QueueInfo &info) { diff --git a/native/cocos/renderer/gfx-validator/RenderPassValidator.cpp b/native/cocos/renderer/gfx-validator/RenderPassValidator.cpp index 46339ec7f2b..718967e5762 100644 --- a/native/cocos/renderer/gfx-validator/RenderPassValidator.cpp +++ b/native/cocos/renderer/gfx-validator/RenderPassValidator.cpp @@ -39,6 +39,7 @@ RenderPassValidator::RenderPassValidator(RenderPass *actor) RenderPassValidator::~RenderPassValidator() { DeviceResourceTracker::erase(this); + CC_SAFE_DELETE(_actor); } void RenderPassValidator::doInit(const RenderPassInfo &info) { diff --git a/native/cocos/renderer/gfx-validator/ShaderValidator.cpp b/native/cocos/renderer/gfx-validator/ShaderValidator.cpp index 91bef262013..f7c0db8d4e4 100644 --- a/native/cocos/renderer/gfx-validator/ShaderValidator.cpp +++ b/native/cocos/renderer/gfx-validator/ShaderValidator.cpp @@ -39,6 +39,7 @@ ShaderValidator::ShaderValidator(Shader *actor) ShaderValidator::~ShaderValidator() { DeviceResourceTracker::erase(this); + CC_SAFE_DELETE(_actor); } void ShaderValidator::doInit(const ShaderInfo &info) { diff --git a/native/cocos/renderer/gfx-validator/SwapchainValidator.cpp b/native/cocos/renderer/gfx-validator/SwapchainValidator.cpp index c744176a293..286d29444b8 100644 --- a/native/cocos/renderer/gfx-validator/SwapchainValidator.cpp +++ b/native/cocos/renderer/gfx-validator/SwapchainValidator.cpp @@ -40,6 +40,7 @@ SwapchainValidator::SwapchainValidator(Swapchain *actor) SwapchainValidator::~SwapchainValidator() { DeviceResourceTracker::erase(this); + CC_SAFE_DELETE(_actor); } void SwapchainValidator::doInit(const SwapchainInfo &info) { diff --git a/native/cocos/renderer/gfx-validator/TextureValidator.cpp b/native/cocos/renderer/gfx-validator/TextureValidator.cpp index 4f35f0b2974..727cd98e479 100644 --- a/native/cocos/renderer/gfx-validator/TextureValidator.cpp +++ b/native/cocos/renderer/gfx-validator/TextureValidator.cpp @@ -50,6 +50,7 @@ TextureValidator::TextureValidator(Texture *actor) TextureValidator::~TextureValidator() { DeviceResourceTracker::erase(this); + if (_ownTheActor) CC_SAFE_DELETE(_actor); } void TextureValidator::doInit(const TextureInfo &info) { diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp index d17d44ed561..332f512bdd6 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp @@ -391,7 +391,7 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { } _gpuBufferHub = ccnew CCVKGPUBufferHub(_gpuDevice); - _gpuTransportHub = ccnew CCVKGPUTransportHub(_gpuDevice, static_cast(_queue.get())->gpuQueue()); + _gpuTransportHub = ccnew CCVKGPUTransportHub(_gpuDevice, static_cast(_queue)->gpuQueue()); _gpuDescriptorHub = ccnew CCVKGPUDescriptorHub(_gpuDevice); _gpuSemaphorePool = ccnew CCVKGPUSemaphorePool(_gpuDevice); _gpuBarrierManager = ccnew CCVKGPUBarrierManager(_gpuDevice); @@ -490,10 +490,9 @@ void CCVKDevice::doDestroy() { } _depthStencilTextures.clear(); - _queryPool = nullptr; - _queue = nullptr; - _cmdBuff = nullptr; - + CC_SAFE_DESTROY_AND_DELETE(_queryPool) + CC_SAFE_DESTROY_AND_DELETE(_queue) + CC_SAFE_DESTROY_AND_DELETE(_cmdBuff) CC_SAFE_DELETE(_gpuBufferHub) CC_SAFE_DELETE(_gpuTransportHub) CC_SAFE_DELETE(_gpuSemaphorePool) @@ -604,7 +603,7 @@ VkImageMemoryBarrier presentBarrier{ void CCVKDevice::acquire(Swapchain *const *swapchains, uint32_t count) { if (_onAcquire) _onAcquire->execute(); - auto *queue = static_cast(_queue.get()); + auto *queue = static_cast(_queue); queue->gpuQueue()->lastSignaledSemaphores.clear(); vkSwapchainIndices.clear(); gpuSwapchains.clear(); @@ -654,7 +653,7 @@ void CCVKDevice::acquire(Swapchain *const *swapchains, uint32_t count) { void CCVKDevice::present() { CC_PROFILE(CCVKDevicePresent); - auto *queue = static_cast(_queue.get()); + auto *queue = static_cast(_queue); _numDrawCalls = queue->_numDrawCalls; _numInstances = queue->_numInstances; _numTriangles = queue->_numTriangles; diff --git a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp index b49e64b87cb..e4114d5e861 100644 --- a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp @@ -42,7 +42,7 @@ CCVKFramebuffer::~CCVKFramebuffer() { void CCVKFramebuffer::doInit(const FramebufferInfo & /*info*/) { _gpuFBO = ccnew CCVKGPUFramebuffer; - _gpuFBO->gpuRenderPass = static_cast(_renderPass.get())->gpuRenderPass(); + _gpuFBO->gpuRenderPass = static_cast(_renderPass)->gpuRenderPass(); _gpuFBO->gpuColorViews.resize(_colorTextures.size()); for (size_t i = 0; i < _colorTextures.size(); ++i) { @@ -52,7 +52,7 @@ void CCVKFramebuffer::doInit(const FramebufferInfo & /*info*/) { } if (_depthStencilTexture) { - auto *depthTex = static_cast(_depthStencilTexture.get()); + auto *depthTex = static_cast(_depthStencilTexture); _gpuFBO->gpuDepthStencilView = depthTex->gpuTextureView(); CCVKDevice::getInstance()->gpuFramebufferHub()->connect(depthTex->gpuTexture(), _gpuFBO); } @@ -68,7 +68,7 @@ void CCVKFramebuffer::doDestroy() { } if (_depthStencilTexture) { - auto *depthTex = static_cast(_depthStencilTexture.get()); + auto *depthTex = static_cast(_depthStencilTexture); CCVKDevice::getInstance()->gpuFramebufferHub()->disengage(depthTex->gpuTexture(), _gpuFBO); }