diff --git a/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp b/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp index 285f9d6b29..edc6a5f9d1 100644 --- a/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp +++ b/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp @@ -53,9 +53,7 @@ void GlobalDSManager::activate(gfx::Device *device) { }); setDescriptorSetLayout(); - CC_SAFE_DESTROY_NULL(_descriptorSetLayout) _descriptorSetLayout = device->createDescriptorSetLayout({globalDescriptorSetLayout.bindings}); - CC_SAFE_DESTROY_NULL(_globalDescriptorSet) _globalDescriptorSet = device->createDescriptorSet({_descriptorSetLayout}); } @@ -137,7 +135,7 @@ gfx::DescriptorSet *GlobalDSManager::getOrCreateDescriptorSet(uint32_t idx) { UBOShadow::SIZE, gfx::BufferFlagBit::NONE, }); - _shadowUBOs.push_back(shadowUBO); + _shadowUBOs.emplace_back(shadowUBO); descriptorSet->bindBuffer(UBOShadow::BINDING, shadowUBO); descriptorSet->update(); @@ -147,16 +145,12 @@ gfx::DescriptorSet *GlobalDSManager::getOrCreateDescriptorSet(uint32_t idx) { } void GlobalDSManager::destroy() { - for (auto *shadowUBO : _shadowUBOs) { - CC_SAFE_DELETE(shadowUBO) - } - for (auto &pair : _descriptorSetMap) { - CC_SAFE_DELETE(pair.second) - } + _shadowUBOs.clear(); _descriptorSetMap.clear(); - - CC_SAFE_DESTROY_NULL(_descriptorSetLayout) - CC_SAFE_DELETE(_globalDescriptorSet) + _descriptorSetLayout = nullptr; + _globalDescriptorSet = nullptr; + _linearSampler = nullptr; + _pointSampler = nullptr; } void GlobalDSManager::setDescriptorSetLayout() { diff --git a/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.h b/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.h index 2a4732fb04..21ed4240bc 100644 --- a/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.h +++ b/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.h @@ -46,7 +46,6 @@ public: GlobalDSManager() = default; ~GlobalDSManager() = default; - inline ccstd::unordered_map getDescriptorSetMap() const { return _descriptorSetMap; } inline gfx::Sampler *getLinearSampler() const { return _linearSampler; } inline gfx::Sampler *getPointSampler() const { return _pointSampler; } inline gfx::DescriptorSetLayout *getDescriptorSetLayout() const { return _descriptorSetLayout; } @@ -63,13 +62,17 @@ public: static void setDescriptorSetLayout(); private: + // weak reference gfx::Device *_device = nullptr; - gfx::Sampler *_linearSampler = nullptr; - gfx::Sampler *_pointSampler = nullptr; + + // Samplers are hold by device + gfx::Sampler *_linearSampler{nullptr}; + gfx::Sampler *_pointSampler{nullptr}; + IntrusivePtr _descriptorSetLayout; - gfx::DescriptorSet *_globalDescriptorSet = nullptr; - ccstd::unordered_map _descriptorSetMap{}; - ccstd::vector _shadowUBOs; + IntrusivePtr _globalDescriptorSet; + ccstd::vector> _shadowUBOs; + ccstd::unordered_map> _descriptorSetMap; }; } // namespace pipeline