We also cache pipeline cache the Render::Geometry by the raw pointer.
If someone use duplicated pointer, it might return invalid pipeline
with unmatched vertexInputState.
To avoid this issue, let we erase cache if Render::Geometry destroyed,
same as Render::Program
Change-Id: Ia1dec43dbed3fdccc5ebd3279dc0b4466a9ce43f
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
~Impl()
{
- rendererContainer.Clear(); // clear now before the pipeline cache is deleted
+ geometryContainer.Clear(); // clear now before the pipeline cache is deleted
+ rendererContainer.Clear(); // clear now before the program contoller and the pipeline cache are deleted
+ pipelineCache.reset(); // clear now before the program contoller is deleted
}
void AddRenderTracker(Render::RenderTracker* renderTracker)
/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
level0.geometry = geometry;
level0.inputState = vertexInputState;
+ // Observer geometry lifecycle
+ geometry->AddLifecycleObserver(*this);
+
it = level0nodes.insert(level0nodes.end(), std::move(level0));
if(attrNotFound)
CleanLatestUsedCache();
}
+PipelineCache::~PipelineCache()
+{
+ // Stop observer lifecycle
+ for(auto&& level0node : level0nodes)
+ {
+ level0node.geometry->RemoveLifecycleObserver(*this);
+ }
+}
+
PipelineResult PipelineCache::GetPipeline(const PipelineCacheQueryInfo& queryInfo, bool createNewIfNotFound)
{
// Seperate branch whether query use blending or not.
if(iter->level1nodes.empty())
{
+ // Stop observer lifecycle
+ iter->geometry->RemoveLifecycleObserver(*this);
iter = level0nodes.erase(iter);
}
else
pipelineCache->referenceCount--;
}
+void PipelineCache::GeometryDestroyed(const Geometry* geometry)
+{
+ // Remove cached items what cache hold now.
+ for(auto iter = level0nodes.begin(); iter != level0nodes.end();)
+ {
+ if(iter->geometry == geometry)
+ {
+ iter = level0nodes.erase(iter);
+ }
+ else
+ {
+ iter++;
+ }
+ }
+}
+
} // namespace Dali::Internal::Render
#define DALI_INTERNAL_RENDER_PIPELINE_CACHE_H
/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/graphics-api/graphics-types.h>
#include <dali/internal/common/blending-options.h>
#include <dali/public-api/common/list-wrapper.h>
+#include <dali/internal/render/renderers/render-geometry.h> ///< For Geometry::LifecycleObserver
namespace Dali::Internal
{
namespace Render
{
class Renderer;
-class Geometry;
struct PipelineCacheL2;
struct PipelineCacheL1;
/**
* Pipeline cache
*/
-class PipelineCache
+class PipelineCache : public Geometry::LifecycleObserver
{
public:
/**
*/
explicit PipelineCache(Graphics::Controller& controller);
+ /**
+ * Destructor
+ */
+ ~PipelineCache();
+
/**
* Retrieves next cache level
*/
*/
void ResetPipeline(PipelineCachePtr pipelineCache);
+public: // From Geometry::LifecycleObserver
+ /**
+ * @copydoc Dali::Internal::Geometry::LifecycleObserver::GeometryDestroyed()
+ */
+ void GeometryDestroyed(const Geometry* geometry);
+
private:
/**
* @brief Clear latest bound result.
}
} // unnamed namespace
Geometry::Geometry()
-: mIndices(),
+: mLifecycleObservers(),
+ mIndices(),
mIndexBuffer(nullptr),
mIndexType(Dali::Graphics::Format::R16_UINT),
mGeometryType(Dali::Geometry::TRIANGLES),
mIndicesChanged(false),
mHasBeenUploaded(false),
- mUpdated(true)
+ mUpdated(true),
+ mObserverNotifying(false)
{
}
-Geometry::~Geometry() = default;
+Geometry::~Geometry()
+{
+ mObserverNotifying = true;
+ for(auto&& iter : mLifecycleObservers)
+ {
+ auto* observer = iter.first;
+ observer->GeometryDestroyed(this);
+ }
+ mLifecycleObservers.clear();
+
+ // Note : We don't need to restore mObserverNotifying to false as we are in delete the object.
+ // If someone call AddObserver / RemoveObserver after this, assert.
+}
void Geometry::AddVertexBuffer(Render::VertexBuffer* vertexBuffer)
{
* limitations under the License.
*/
+// EXTERNAL INCLUDES
+#include <unordered_map>
+
// INTERNAL INCLUDES
#include <dali/devel-api/common/owner-container.h>
#include <dali/graphics-api/graphics-controller.h>
using Uint16ContainerType = Dali::Vector<uint16_t>;
using Uint32ContainerType = Dali::Vector<uint32_t>;
+ /**
+ * Observer to determine when the geometry is no longer present
+ */
+ class LifecycleObserver
+ {
+ public:
+ /**
+ * Called shortly before the program is destroyed.
+ */
+ virtual void GeometryDestroyed(const Geometry* program) = 0;
+
+ protected:
+ /**
+ * Virtual destructor, no deletion through this interface
+ */
+ virtual ~LifecycleObserver() = default;
+ };
+
Geometry();
/**
*/
bool BindVertexAttributes(Graphics::CommandBuffer& commandBuffer);
+ /**
+ * Allows Geometry to track the life-cycle of this object.
+ * Note that we allow to observe lifecycle multiple times.
+ * But GeometryDestroyed callback will be called only one time.
+ * @param[in] observer The observer to add.
+ */
+ void AddLifecycleObserver(LifecycleObserver& observer)
+ {
+ DALI_ASSERT_ALWAYS(!mObserverNotifying && "Cannot add observer while notifying Geometry::LifecycleObservers");
+
+ auto iter = mLifecycleObservers.find(&observer);
+ if(iter != mLifecycleObservers.end())
+ {
+ // Increase the number of observer count
+ ++(iter->second);
+ }
+ else
+ {
+ mLifecycleObservers.insert({&observer, 1u});
+ }
+ }
+
+ /**
+ * The Geometry no longer needs to track the life-cycle of this object.
+ * @param[in] observer The observer that to remove.
+ */
+ void RemoveLifecycleObserver(LifecycleObserver& observer)
+ {
+ DALI_ASSERT_ALWAYS(!mObserverNotifying && "Cannot remove observer while notifying Geometry::LifecycleObservers");
+
+ auto iter = mLifecycleObservers.find(&observer);
+ DALI_ASSERT_ALWAYS(iter != mLifecycleObservers.end());
+
+ if(--(iter->second) == 0u)
+ {
+ mLifecycleObservers.erase(iter);
+ }
+ }
+
private:
+ using LifecycleObserverContainer = std::unordered_map<LifecycleObserver*, uint32_t>; ///< Lifecycle observers container. We allow to add same observer multiple times.
+ ///< Key is a pointer to observer, value is the number of observer added.
+ LifecycleObserverContainer mLifecycleObservers;
+
// VertexBuffers
Vector<Render::VertexBuffer*> mVertexBuffers;
bool mIndicesChanged : 1;
bool mHasBeenUploaded : 1;
bool mUpdated : 1; ///< Flag to know if data has changed in a frame. Value fixed after Upload() call, and reset as false after OnRenderFinished
+
+ bool mObserverNotifying : 1; ///< Safety guard flag to ensure that the LifecycleObserver not be added or deleted while observing.
};
} // namespace Render
void Renderer::SetGeometry(Render::Geometry* geometry)
{
mGeometry = geometry;
+
+ // Reset old pipeline
+ if(DALI_LIKELY(mPipelineCached))
+ {
+ mPipelineCache->ResetPipeline(mPipeline);
+ mPipelineCached = false;
+ }
}
void Renderer::SetDrawCommands(Dali::DevelRenderer::DrawCommand* pDrawCommands, uint32_t size)