bool Buffer::OnDestroy()
{
- mGraphics->RemoveBuffer(*this);
+ mGraphics->RemoveBuffer( *this );
- mGraphics->DiscardResource([this]() {
+ mGraphics->DiscardResource( [this]() {
mGraphics->GetDevice().destroyBuffer(mBuffer, mGraphics->GetAllocator());
- });
+ } );
return false;
}
VkAssert( mDevice.createImage( &imageCreateInfo, mAllocator.get(), refCountedImage->Ref() ) );
+ AddImage( refCountedImage );
+
return refCountedImage;
}
VkAssert( mDevice.createImageView( &imageViewCreateInfo, nullptr, refCountedImageView->Ref()));
+ AddImageView( refCountedImageView );
+
return refCountedImageView;
}
.setLevelCount( image->GetMipLevelCount())
.setLayerCount( image->GetLayerCount());
- return CreateImageView( {},
- image,
- vk::ImageViewType::e2D,
- image->GetFormat(),
- componentsMapping,
- subresourceRange );
+ auto refCountedImageView = CreateImageView( {},
+ image,
+ vk::ImageViewType::e2D,
+ image->GetFormat(),
+ componentsMapping,
+ subresourceRange );
+
+ AddImageView( refCountedImageView );
+
+ return refCountedImageView;
}
RefCountedDescriptorPool Graphics::CreateDescriptorPool()
mResourceCache->AddImage( std::move( image ));
}
+void Graphics::AddImageView( RefCountedImageView imageView )
+{
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->AddImageView( std::move( imageView ));
+}
+
void Graphics::AddShader( Handle< Shader > shader )
{
std::lock_guard< std::mutex > lock{ mMutex };
mResourceCache->RemoveImage( image );
}
+void Graphics::RemoveImageView( ImageView& imageView )
+{
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->RemoveImageView( imageView );
+}
+
void Graphics::RemoveShader( Shader& shader )
{
std::lock_guard< std::mutex > lock{ mMutex };
void AddImage( RefCountedImage image );
+ void AddImageView( RefCountedImageView imageView );
+
void AddShader( RefCountedShader shader );
void AddCommandPool( RefCountedCommandPool pool );
void RemoveImage( Image& image );
+ void RemoveImageView( ImageView& imageView );
+
void RemoveShader( Shader& shader );
void RemoveCommandPool( CommandPool& commandPool );
return &mImageView;
}
+bool ImageView::OnDestroy()
+{
+ mGraphics->RemoveImageView( *this );
+
+ mGraphics->DiscardResource( [this]() {
+ mGraphics->GetDevice().destroyImageView(mImageView, mGraphics->GetAllocator());
+ } );
+
+ return VkManaged::OnDestroy();
+}
+
} // namespace Vulkan
} // namespace Graphics
} // namespace Dali
operator vk::ImageView*();
- //TODO: Use the graphics class to manage lifetime.
+ bool OnDestroy() override;
+//TODO: Use the graphics class to manage lifetime.
private:
ImageView( Graphics& graphics,
#include <dali/graphics/vulkan/vulkan-buffer.h>
#include <dali/graphics/vulkan/vulkan-image.h>
+#include <dali/graphics/vulkan/vulkan-image-view.h>
#include <dali/graphics/vulkan/vulkan-pipeline.h>
#include <dali/graphics/vulkan/vulkan-shader.h>
#include <dali/graphics/vulkan/vulkan-descriptor-set.h>
return *this;
}
+ResourceCache& ResourceCache::AddImageView( RefCountedImageView imageView )
+{
+ mImageViews.push_back( imageView );
+ return *this;
+}
+
ResourceCache& ResourceCache::AddShader( RefCountedShader shader )
{
mShaders.push_back( shader );
return iterator == mImages.end() ? RefCountedImage() : RefCountedImage(&**iterator);
}
+RefCountedImageView ResourceCache::FindImageView( vk::ImageView imageView )
+{
+ auto iterator = std::find_if(mImageViews.begin(),
+ mImageViews.end(),
+ [&](const RefCountedImageView entry) { return entry->GetVkHandle() == imageView; });
+
+ return iterator == mImageViews.end() ? RefCountedImageView() : RefCountedImageView(&**iterator);
+}
+
ResourceCache& ResourceCache::RemoveBuffer( Buffer& buffer )
{
if( !mBuffers.empty() )
return *this;
}
+ResourceCache& ResourceCache::RemoveImageView( ImageView& imageView )
+{
+ if( !mImageViews.empty() )
+ {
+ auto found = std::find_if(mImageViews.begin(),
+ mImageViews.end(),
+ [&](const RefCountedImageView entry) { return &(*entry) == &imageView; });
+
+ std::iter_swap(found, std::prev(mImageViews.end()));
+ mImageViews.back().Reset();
+ mImageViews.pop_back();
+ }
+ return *this;
+}
+
ResourceCache& ResourceCache::RemoveShader( Shader& shader )
{
if( !mShaders.empty() )
ResourceCache& AddImage( RefCountedImage image );
/**
+ * Adds the provided image view object to the image view cache
+ * @param imageView The image view object to be added to the cache
+ * @return A reference to the ResourceCache
+ */
+ ResourceCache& AddImageView( RefCountedImageView imageView );
+
+ /**
* Adds the provided shader object to the pipeline cache
* @param shader The shader object to be added to the cache
* @return A reference to the ResourceCache
RefCountedImage FindImage( vk::Image image);
/**
- * Finds the shader module using the specified Vulkan handle in the cache
+ * Finds the image view object using the specified Vulkan handle
+ * @param imageView The Vulkan handle of the image view object to be found
+ * @return A handle to the ImageView object if found. An empty Handle otherwise
+ */
+ RefCountedImageView FindImageView( vk::ImageView imageView );
+
+ /**
+ * Finds the shader module using the specified Vulkan handle
* @param shaderModule The Vulkan handle of the shader module to be found
* @return A Handle to the Shader module if found. An empty Handle otherwise
*/
RefCountedShader FindShader( vk::ShaderModule shaderModule );
/**
- * Finds the CommandPool object using the specified Vulkan handle in the cache
+ * Finds the CommandPool object using the specified Vulkan handle
* @param commandPool The Vulkan handle of the CommandPool object to be found
* @return A Handle to the CommandPool object if found. An empty Handle otherwise
*/
RefCountedCommandPool FindCommandPool( vk::CommandPool commandPool );
/**
- * Finds the DescriptorPool object using the specified Vulkan handle in the cache
+ * Finds the DescriptorPool object using the specified Vulkan handle
* @param descriptorPool The Vulkan handle of the DescriptorPool object to be found
* @return A Handle to the DescriptorPool object if found. An empty Handle otherwise
*/
RefCountedDescriptorPool FindDescriptorPool( vk::DescriptorPool descriptorPool );
/**
- * Finds the Framebuffer object using the specified Vulkan handle in the cache
+ * Finds the Framebuffer object using the specified Vulkan handle
* @param framebuffer The Vulkan handle of the Framebuffer object to be found
* @return A Handle to the Framebuffer object if found. An empty Handle otherwise
*/
RefCountedFramebuffer FindFramebuffer( vk::Framebuffer framebuffer );
/**
- * Finds the Sampler object using the specified Vulkan handle in the cache.
+ * Finds the Sampler object using the specified Vulkan handle
* @param sampler The Vulkan handle of the Sampler object to be found
* @return A Handle to the Sampler object if found. An empty Handle otherwise
*/
ResourceCache& RemoveImage( Image& image );
/**
+ * Removes the specified ImageView from the cache
+ * @param imageView The ImageView to be removed
+ * @return A reference to the ResourceCache
+ */
+ ResourceCache& RemoveImageView( ImageView& imageView );
+
+ /**
* Removes the specified Shader from the cache
* @param shader The Shader to be removed
* @return A reference to the ResourceCache
private:
std::vector< RefCountedBuffer > mBuffers;
std::vector< RefCountedImage > mImages;
- //TODO: add storage for ImageViews
+ std::vector< RefCountedImageView > mImageViews;
std::vector< RefCountedShader > mShaders;
std::vector< RefCountedCommandPool > mCommandPools;
std::vector< RefCountedDescriptorPool > mDescriptorPools;