#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>
#include <dali/graphics/vulkan/vulkan-sampler.h>
#include <dali/graphics/vulkan/vulkan-resource-cache.h>
#include <dali/graphics/vulkan/vulkan-debug.h>
+#include <dali/graphics/vulkan/vulkan-fence.h>
+
#include <dali/graphics-api/graphics-api-controller.h>
#ifndef VK_KHR_XLIB_SURFACE_EXTENSION_NAME
#define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface"
#endif
+#include <iostream>
+#include <utility>
+
namespace Dali
{
namespace Graphics
};
Graphics::Graphics() = default;
+
Graphics::~Graphics() = default;
// Create methods -----------------------------------------------------------------------------------------------
auto extensions = PrepareDefaultInstanceExtensions();
auto layers = vk::enumerateInstanceLayerProperties();
- std::vector<const char*> validationLayers;
+ std::vector< const char* > validationLayers;
for( auto&& reqLayer : VALIDATION_LAYERS )
{
for( auto&& prop : layers.value )
DALI_LOG_STREAM( gVulkanFilter, Debug::General, prop.layerName );
if( std::string(prop.layerName) == reqLayer )
{
- validationLayers.push_back(reqLayer);
+ validationLayers.push_back( reqLayer );
}
}
}
- CreateInstance(extensions, validationLayers);
+ CreateInstance( extensions, validationLayers );
PreparePhysicalDevice();
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wframe-larger-than="
+
void Graphics::CreateDevice()
{
auto queueInfos = GetQueueCreateInfos();
maxQueueCountPerFamily = std::max( info.queueCount, maxQueueCountPerFamily );
}
- auto priorities = std::vector<float>( maxQueueCountPerFamily );
+ auto priorities = std::vector< float >( maxQueueCountPerFamily );
std::fill( priorities.begin(), priorities.end(), 1.0f );
for( auto& info : queueInfos )
{
- info.setPQueuePriorities( priorities.data() );
+ info.setPQueuePriorities( priorities.data());
}
- std::vector< const char* > extensions{VK_KHR_SWAPCHAIN_EXTENSION_NAME};
+ std::vector< const char* > extensions{ VK_KHR_SWAPCHAIN_EXTENSION_NAME };
auto info = vk::DeviceCreateInfo{};
- info.setEnabledExtensionCount(U32(extensions.size()))
- .setPpEnabledExtensionNames(extensions.data())
- .setPEnabledFeatures(&(*mPhysicalDeviceFeatures))
- .setPQueueCreateInfos(queueInfos.data())
- .setQueueCreateInfoCount(U32(queueInfos.size()));
+ info.setEnabledExtensionCount( U32( extensions.size()))
+ .setPpEnabledExtensionNames( extensions.data())
+ .setPEnabledFeatures( &( *mPhysicalDeviceFeatures ))
+ .setPQueueCreateInfos( queueInfos.data())
+ .setQueueCreateInfoCount( U32( queueInfos.size()));
- mDevice = VkAssert(mPhysicalDevice.createDevice(info, *mAllocator));
+ mDevice = VkAssert( mPhysicalDevice.createDevice( info, *mAllocator ));
}
// create Queue objects
- for(auto& queueInfo : queueInfos)
+ for( auto& queueInfo : queueInfos )
{
- for(auto i = 0u; i < queueInfo.queueCount; ++i)
+ for( auto i = 0u; i < queueInfo.queueCount; ++i )
{
- auto queue = mDevice.getQueue(queueInfo.queueFamilyIndex, i);
+ auto queue = mDevice.getQueue( queueInfo.queueFamilyIndex, i );
// based on family push queue instance into right array
auto flags = mQueueFamilyProperties[queueInfo.queueFamilyIndex].queueFlags;
- if(flags & vk::QueueFlagBits::eGraphics)
+ if( flags & vk::QueueFlagBits::eGraphics )
{
mGraphicsQueues.emplace_back(
- MakeUnique<Queue>(*this, queue, queueInfo.queueFamilyIndex, i, flags));
+ MakeUnique< Queue >( *this, queue, queueInfo.queueFamilyIndex, i, flags ));
}
- if(flags & vk::QueueFlagBits::eTransfer)
+ if( flags & vk::QueueFlagBits::eTransfer )
{
mTransferQueues.emplace_back(
- MakeUnique<Queue>(*this, queue, queueInfo.queueFamilyIndex, i, flags));
+ MakeUnique< Queue >( *this, queue, queueInfo.queueFamilyIndex, i, flags ));
}
- if(flags & vk::QueueFlagBits::eCompute)
+ if( flags & vk::QueueFlagBits::eCompute )
{
mComputeQueues.emplace_back(
- MakeUnique<Queue>(*this, queue, queueInfo.queueFamilyIndex, i, flags));
+ MakeUnique< Queue >( *this, queue, queueInfo.queueFamilyIndex, i, flags ));
}
// todo: present queue
}
}
- mPipelineDatabase = std::make_unique<PipelineCache>( *this );
- mResourceCacheMap[std::this_thread::get_id()] = MakeUnique<ResourceCache>();
-}
-#pragma GCC diagnostic pop
-
-void Graphics::GetPhysicalDeviceProperties()
-{
- // store data on heap to keep object smaller
- mPhysicalDeviceProperties =
- MakeUnique<vk::PhysicalDeviceProperties>(mPhysicalDevice.getProperties());
- mPhysicalDeviceMemoryProperties =
- MakeUnique<vk::PhysicalDeviceMemoryProperties>(mPhysicalDevice.getMemoryProperties());
- mPhysicalDeviceFeatures =
- MakeUnique<vk::PhysicalDeviceFeatures>(mPhysicalDevice.getFeatures());
+ mPipelineDatabase = std::make_unique< PipelineCache >( *this );
+ mResourceCache = MakeUnique< ResourceCache >();
}
-void Graphics::GetQueueFamilyProperties()
-{
- mQueueFamilyProperties = mPhysicalDevice.getQueueFamilyProperties();
-}
+#pragma GCC diagnostic pop
-FBID Graphics::CreateSurface(std::unique_ptr< SurfaceFactory > surfaceFactory)
+FBID Graphics::CreateSurface( std::unique_ptr< SurfaceFactory > surfaceFactory )
{
// create surface from the factory
- auto surfaceRef = Surface::New( *this, std::move(surfaceFactory) );
+ auto surfaceRef = Surface::New( *this, std::move( surfaceFactory ));
- if( surfaceRef->Create() )
+ if( surfaceRef->Create())
{
// map surface to FBID
RefCountedSwapchain Graphics::CreateSwapchainForSurface( RefCountedSurface surface )
{
auto swapchain = Swapchain::New( *this,
- GetGraphicsQueue(0u),
+ GetGraphicsQueue( 0u ),
surface, 4, 0 );
// store swapchain in the correct pair
for( auto&& val : mSurfaceFBIDMap )
{
- if( val.second.surface == surface )
+ if( val.second
+ .surface == surface )
{
- val.second.swapchain = swapchain;
+ val.second
+ .swapchain = swapchain;
break;
}
}
RefCountedFence Graphics::CreateFence( const vk::FenceCreateInfo& fenceCreateInfo )
{
- auto refCountedFence = Fence::New(*this);
+ auto refCountedFence = Fence::New( *this );
- VkAssert(mDevice.createFence(&fenceCreateInfo, mAllocator.get(), refCountedFence->Ref()));
+ VkAssert( mDevice.createFence( &fenceCreateInfo, mAllocator.get(), refCountedFence->Ref()));
return refCountedFence;
}
-RefCountedBuffer Graphics::CreateBuffer(size_t size, BufferType type)
+RefCountedBuffer Graphics::CreateBuffer( size_t size, BufferType type )
{
auto usageFlags = vk::BufferUsageFlags{};
- switch ( type ) {
- case BufferType::VERTEX: {
+ switch( type )
+ {
+ case BufferType::VERTEX:
+ {
usageFlags |= vk::BufferUsageFlagBits::eVertexBuffer;
break;
};
- case BufferType::INDEX: {
+ case BufferType::INDEX:
+ {
usageFlags |= vk::BufferUsageFlagBits::eIndexBuffer;
break;
};
- case BufferType::UNIFORM: {
+ case BufferType::UNIFORM:
+ {
usageFlags |= vk::BufferUsageFlagBits::eUniformBuffer;
break;
};
- case BufferType::SHADER_STORAGE: {
+ case BufferType::SHADER_STORAGE:
+ {
usageFlags |= vk::BufferUsageFlagBits::eStorageBuffer;
break;
};
}
auto info = vk::BufferCreateInfo{};
- info.setSharingMode(vk::SharingMode::eExclusive);
- info.setSize(size);
- info.setUsage(usageFlags | vk::BufferUsageFlagBits::eTransferDst);
+ info.setSharingMode( vk::SharingMode::eExclusive );
+ info.setSize( size );
+ info.setUsage( usageFlags | vk::BufferUsageFlagBits::eTransferDst );
- auto refCountedBuffer = Buffer::New(*this, info);
+ auto refCountedBuffer = Buffer::New( *this, info );
- VkAssert(mDevice.createBuffer(&info, mAllocator.get(), refCountedBuffer->Ref()));
+ VkAssert( mDevice.createBuffer( &info, mAllocator.get(), refCountedBuffer->Ref()));
- AddBuffer(refCountedBuffer);
+ AddBuffer( refCountedBuffer );
return refCountedBuffer;
}
RefCountedBuffer Graphics::CreateBuffer( const vk::BufferCreateInfo& bufferCreateInfo )
{
- auto refCountedBuffer = Buffer::New(*this, bufferCreateInfo);
+ auto refCountedBuffer = Buffer::New( *this, bufferCreateInfo );
- VkAssert(mDevice.createBuffer(&bufferCreateInfo, mAllocator.get(), refCountedBuffer->Ref()));
+ VkAssert( mDevice.createBuffer( &bufferCreateInfo, mAllocator.get(), refCountedBuffer->Ref()));
- AddBuffer(refCountedBuffer);
+ AddBuffer( refCountedBuffer );
return refCountedBuffer;
}
NotImplemented()
}
-RefCountedImageView Graphics::CreateImageView()
+RefCountedImageView Graphics::CreateImageView( const vk::ImageViewCreateFlags& flags,
+ const RefCountedImage& image,
+ vk::ImageViewType viewType,
+ vk::Format format,
+ vk::ComponentMapping components,
+ vk::ImageSubresourceRange subresourceRange )
{
- NotImplemented()
+ auto imageViewCreateInfo = vk::ImageViewCreateInfo{}
+ .setFlags( flags )
+ .setImage( image->GetVkHandle())
+ .setViewType( viewType )
+ .setFormat( format )
+ .setComponents( components )
+ .setSubresourceRange( std::move( subresourceRange ));
+
+ auto refCountedImageView = ImageView::New( *this, image, imageViewCreateInfo );
+
+ VkAssert( mDevice.createImageView( &imageViewCreateInfo, nullptr, refCountedImageView->Ref()));
+
+ return refCountedImageView;
+}
+
+RefCountedImageView Graphics::CreateImageView( RefCountedImage image )
+{
+ vk::ComponentMapping componentsMapping = { vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG,
+ vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eA };
+ vk::ImageAspectFlags aspectFlags{};
+ if( image->GetVkImageUsageFlags() & vk::ImageUsageFlagBits::eColorAttachment )
+ {
+ aspectFlags |= vk::ImageAspectFlagBits::eColor;
+ //componentsMapping = { vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eB,vk::ComponentSwizzle::eA };
+ }
+ if( image->GetVkImageUsageFlags() & vk::ImageUsageFlagBits::eDepthStencilAttachment )
+ {
+ aspectFlags |= ( vk::ImageAspectFlagBits::eDepth | vk::ImageAspectFlagBits::eStencil );
+ }
+ if( image->GetVkImageUsageFlags() & vk::ImageUsageFlagBits::eSampled )
+ {
+ aspectFlags |= ( vk::ImageAspectFlagBits::eColor );
+ //componentsMapping = { vk::ComponentSwizzle::eB, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eR,vk::ComponentSwizzle::eA };
+ }
+
+ auto subresourceRange = vk::ImageSubresourceRange{}
+ .setAspectMask( aspectFlags )
+ .setBaseArrayLayer( 0 )
+ .setBaseMipLevel( 0 )
+ .setLevelCount( image->GetMipLevelCount())
+ .setLayerCount( image->GetLayerCount());
+
+ return CreateImageView( {},
+ image,
+ vk::ImageViewType::e2D,
+ image->GetVkFormat(),
+ componentsMapping,
+ subresourceRange );
}
RefCountedDescriptorPool Graphics::CreateDescriptorPool()
NotImplemented()
}
-RefCountedCommandPool Graphics::CreateCommandPool(const vk::CommandPoolCreateInfo& info)
+RefCountedCommandPool Graphics::CreateCommandPool( const vk::CommandPoolCreateInfo& info )
{
+ //TODO: move the logic of creation here
+ //TODO: add the object to the cache
return CommandPool::New( *this,
vk::CommandPoolCreateInfo{}.setQueueFamilyIndex( 0u )
- .setFlags( vk::CommandPoolCreateFlagBits::eResetCommandBuffer ) );
+ .setFlags( vk::CommandPoolCreateFlagBits::eResetCommandBuffer ));
}
RefCountedCommandBuffer Graphics::CreateCommandBuffer()
NotImplemented()
}
-std::vector<RefCountedCommandBuffer> Graphics::CreateCommandBuffers()
+std::vector< RefCountedCommandBuffer > Graphics::CreateCommandBuffers()
{
NotImplemented()
}
// Actions ------------------------------------------------------------------------------------------------------
vk::Result Graphics::WaitForFence( RefCountedFence fence, uint32_t timeout )
{
- return mDevice.waitForFences(1, *fence, VK_TRUE, timeout);
+ return mDevice.waitForFences( 1, *fence, VK_TRUE, timeout );
}
-#pragma GCC diagnostic pop
-vk::Result Graphics::WaitForFences( const std::vector<RefCountedFence>& fences, bool waitAll, uint32_t timeout )
+vk::Result Graphics::WaitForFences( const std::vector< RefCountedFence >& fences, bool waitAll, uint32_t timeout )
{
- std::vector<vk::Fence> vkFenceHandles{};
- std::transform(fences.begin(),
- fences.end(),
- std::back_inserter(vkFenceHandles),
- [](RefCountedFence entry){ return entry->GetVkHandle(); });
+ std::vector< vk::Fence > vkFenceHandles{};
+ std::transform( fences.begin(),
+ fences.end(),
+ std::back_inserter( vkFenceHandles ),
+ []( RefCountedFence entry ) { return entry->GetVkHandle(); } );
- auto priorities = std::vector<float>( maxQueueCountPerFamily );
- std::fill( priorities.begin(), priorities.end(), 1.0f );
- return mDevice.waitForFences(vkFenceHandles, vk::Bool32(waitAll), timeout);
+ return mDevice.waitForFences( vkFenceHandles, vk::Bool32( waitAll ), timeout );
}
vk::Result Graphics::ResetFence( RefCountedFence fence )
{
- return mDevice.resetFences(1, *fence);
+ return mDevice.resetFences( 1, *fence );
}
-vk::Result Graphics::ResetFences( const std::vector<RefCountedFence>& fences )
+vk::Result Graphics::ResetFences( const std::vector< RefCountedFence >& fences )
{
- std::vector<vk::Fence> vkFenceHandles{};
- std::transform(fences.begin(),
- fences.end(),
- std::back_inserter(vkFenceHandles),
- [](RefCountedFence entry){ return entry->GetVkHandle(); });
+ std::vector< vk::Fence > vkFenceHandles{};
+ std::transform( fences.begin(),
+ fences.end(),
+ std::back_inserter( vkFenceHandles ),
+ []( RefCountedFence entry ) { return entry->GetVkHandle(); } );
- return mDevice.resetFences(vkFenceHandles);
+ return mDevice.resetFences( vkFenceHandles );
}
// --------------------------------------------------------------------------------------------------------------
// such thing as default framebuffer.
if( surfaceId == 0 )
{
- return mSurfaceFBIDMap.begin()->second.surface;
+ return mSurfaceFBIDMap.begin()
+ ->second
+ .surface;
}
return mSurfaceFBIDMap[surfaceId].surface;
}
{
for( auto&& val : mSurfaceFBIDMap )
{
- if( val.second.surface == surface )
+ if( val.second
+ .surface == surface )
{
return val.second
- .swapchain;
+ .swapchain;
}
}
return RefCountedSwapchain();
RefCountedSwapchain Graphics::GetSwapchainForFBID( FBID surfaceId )
{
- if(surfaceId == 0)
+ if( surfaceId == 0 )
{
- return mSurfaceFBIDMap.begin()->second.swapchain;
+ return mSurfaceFBIDMap.begin()
+ ->second
+ .swapchain;
}
return mSurfaceFBIDMap[surfaceId].swapchain;
}
-#pragma GCC diagnostic pop
vk::Device Graphics::GetDevice() const
{
return *mPhysicalDeviceMemoryProperties;
}
-Queue& Graphics::GetGraphicsQueue(uint32_t index) const
+Queue& Graphics::GetGraphicsQueue( uint32_t index ) const
{
// todo: at the moment each type of queue may use only one, indices greater than 0 are invalid
// this will change in the future
- assert(index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!");
+ assert( index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!" );
return *mGraphicsQueues[0]; // will be mGraphicsQueues[index]
}
-Queue& Graphics::GetTransferQueue(uint32_t index) const
+Queue& Graphics::GetTransferQueue( uint32_t index ) const
{
// todo: at the moment each type of queue may use only one, indices greater than 0 are invalid
// this will change in the future
- assert(index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!");
+ assert( index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!" );
return *mTransferQueues[0]; // will be mGraphicsQueues[index]
}
-Queue& Graphics::GetComputeQueue(uint32_t index) const
+Queue& Graphics::GetComputeQueue( uint32_t index ) const
{
// todo: at the moment each type of queue may use only one, indices greater than 0 are invalid
// this will change in the future
- assert(index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!");
+ assert( index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!" );
return *mComputeQueues[0]; // will be mGraphicsQueues[index]
}
Queue& Graphics::GetPresentQueue() const
{
// fixme: should be a dedicated presentation queue
- return GetGraphicsQueue(0);
+ return GetGraphicsQueue( 0 );
}
Platform Graphics::GetDefaultPlatform() const
Dali::Graphics::API::Controller& Graphics::GetController()
{
- if(!mGfxController)
+ if( !mGfxController )
{
- mGfxController = Dali::Graphics::VulkanAPI::Controller::New(*this);
+ mGfxController = Dali::Graphics::VulkanAPI::Controller::New( *this );
}
return *mGfxController;
// --------------------------------------------------------------------------------------------------------------
// Cache manipulation methods -----------------------------------------------------------------------------------
-void Graphics::AddBuffer( Handle<Buffer> buffer )
+void Graphics::AddBuffer( Handle< Buffer > buffer )
{
- GetResourceCache(std::this_thread::get_id())->AddBuffer(std::move(buffer));
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->AddBuffer( std::move( buffer ));
}
-void Graphics::AddImage( Handle<Image> image )
+void Graphics::AddImage( Handle< Image > image )
{
- GetResourceCache(std::this_thread::get_id())->AddImage(std::move(image));
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->AddImage( std::move( image ));
}
-void Graphics::AddShader( Handle<Shader> shader )
+void Graphics::AddShader( Handle< Shader > shader )
{
- GetResourceCache(std::this_thread::get_id())->AddShader(std::move(shader));
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->AddShader( std::move( shader ));
}
-void Graphics::AddCommandPool( Handle<CommandPool> pool )
+void Graphics::AddCommandPool( Handle< CommandPool > pool )
{
- GetResourceCache(std::this_thread::get_id())->AddCommandPool(std::move(pool));
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->AddCommandPool( std::move( pool ));
}
-void Graphics::AddDescriptorPool( Handle<DescriptorPool> pool )
+void Graphics::AddDescriptorPool( Handle< DescriptorPool > pool )
{
- GetResourceCache(std::this_thread::get_id())->AddDescriptorPool(std::move(pool));
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->AddDescriptorPool( std::move( pool ));
}
-void Graphics::AddFramebuffer( Handle<Framebuffer> framebuffer )
+void Graphics::AddFramebuffer( Handle< Framebuffer > framebuffer )
{
- GetResourceCache(std::this_thread::get_id())->AddFramebuffer(std::move(framebuffer));
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->AddFramebuffer( std::move( framebuffer ));
}
RefCountedShader Graphics::FindShader( vk::ShaderModule shaderModule )
{
- return GetResourceCache(std::this_thread::get_id())->FindShader(shaderModule);
+ std::lock_guard< std::mutex > lock{ mMutex };
+ return mResourceCache->FindShader( shaderModule );
}
RefCountedImage Graphics::FindImage( vk::Image image )
{
- return GetResourceCache(std::this_thread::get_id())->FindImage(image);
+ std::lock_guard< std::mutex > lock{ mMutex };
+ return mResourceCache->FindImage( image );
}
void Graphics::RemoveBuffer( Buffer& buffer )
{
- GetResourceCache(std::this_thread::get_id())->RemoveBuffer(buffer);
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->RemoveBuffer( buffer );
}
void Graphics::RemoveShader( Shader& shader )
{
- GetResourceCache(std::this_thread::get_id())->RemoveShader(shader);
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->RemoveShader( shader );
}
void Graphics::RemoveCommandPool( CommandPool& commandPool )
{
- GetResourceCache(std::this_thread::get_id())->RemoveCommandPool(commandPool);
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->RemoveCommandPool( commandPool );
}
void Graphics::RemoveDescriptorPool( DescriptorPool& pool )
{
- GetResourceCache(std::this_thread::get_id())->RemoveDescriptorPool(pool);
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->RemoveDescriptorPool( pool );
}
void Graphics::RemoveFramebuffer( Framebuffer& framebuffer )
{
- GetResourceCache(std::this_thread::get_id())->RemoveFramebuffer(framebuffer);
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->RemoveFramebuffer( framebuffer );
}
void Graphics::RemoveSampler( Sampler& sampler )
{
- GetResourceCache(std::this_thread::get_id())->RemoveSampler(sampler);
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->RemoveSampler( sampler );
}
void Graphics::CollectGarbage()
{
- GetResourceCache(std::this_thread::get_id())->CollectGarbage();
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->CollectGarbage();
}
-void Graphics::DiscardResource( std::function<void()> deleter )
+void Graphics::DiscardResource( std::function< void() > deleter )
{
- GetResourceCache(std::this_thread::get_id())->EnqueueDiscardOperation(std::move(deleter));
+ std::lock_guard< std::mutex > lock{ mMutex };
+ mResourceCache->EnqueueDiscardOperation( std::move( deleter ));
}
// --------------------------------------------------------------------------------------------------------------
-void Graphics::CreateInstance( const std::vector<const char*>& extensions, const std::vector<const char*>& validationLayers )
+void
+Graphics::CreateInstance( const std::vector< const char* >& extensions,
+ const std::vector< const char* >& validationLayers )
{
auto info = vk::InstanceCreateInfo{};
void Graphics::DestroyInstance()
{
- if(mInstance)
+ if( mInstance )
{
- mInstance.destroy(*mAllocator);
+ mInstance.destroy( *mAllocator );
mInstance = nullptr;
}
}
void Graphics::PreparePhysicalDevice()
{
- auto devices = VkAssert(mInstance.enumeratePhysicalDevices());
- assert(!devices.empty() && "No Vulkan supported device found!");
+ auto devices = VkAssert( mInstance.enumeratePhysicalDevices());
+ assert( !devices.empty() && "No Vulkan supported device found!" );
// if only one, pick first
mPhysicalDevice = nullptr;
- if(devices.size() == 1)
+ if( devices.size() == 1 )
{
mPhysicalDevice = devices[0];
- }
- else // otherwise look for one which is a graphics device
+ }else // otherwise look for one which is a graphics device
{
- for(auto& device : devices)
+ for( auto& device : devices )
{
- auto properties =device.getProperties();
- if(properties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu ||
- properties.deviceType == vk::PhysicalDeviceType::eIntegratedGpu)
+ auto properties = device.getProperties();
+ if( properties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu ||
+ properties.deviceType == vk::PhysicalDeviceType::eIntegratedGpu )
{
mPhysicalDevice = device;
break;
}
}
- assert(mPhysicalDevice && "No suitable Physical Device found!");
+ assert( mPhysicalDevice && "No suitable Physical Device found!" );
GetPhysicalDeviceProperties();
{
// store data on heap to keep object smaller
mPhysicalDeviceProperties =
- MakeUnique<vk::PhysicalDeviceProperties>(mPhysicalDevice.getProperties());
+ MakeUnique< vk::PhysicalDeviceProperties >( mPhysicalDevice.getProperties());
mPhysicalDeviceMemoryProperties =
- MakeUnique<vk::PhysicalDeviceMemoryProperties>(mPhysicalDevice.getMemoryProperties());
+ MakeUnique< vk::PhysicalDeviceMemoryProperties >( mPhysicalDevice.getMemoryProperties());
mPhysicalDeviceFeatures =
- MakeUnique<vk::PhysicalDeviceFeatures>(mPhysicalDevice.getFeatures());
+ MakeUnique< vk::PhysicalDeviceFeatures >( mPhysicalDevice.getFeatures());
}
void Graphics::GetQueueFamilyProperties()
mQueueFamilyProperties = mPhysicalDevice.getQueueFamilyProperties();
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wframe-larger-than="
std::vector< vk::DeviceQueueCreateInfo > Graphics::GetQueueCreateInfos()
{
// surface is needed in order to find a family that supports presentation to this surface
// fixme: assuming all surfaces will be compatible with the queue family
- assert(!mSurfaceFBIDMap.empty() &&
- "At least one surface has to be created before creating VkDevice!");
+ assert( !mSurfaceFBIDMap.empty() &&
+ "At least one surface has to be created before creating VkDevice!" );
std::vector< vk::DeviceQueueCreateInfo > queueInfos{};
constexpr uint8_t MAX_QUEUE_TYPES = 3;
// find suitable family for each type of queue
uint32_t familyIndexType[MAX_QUEUE_TYPES];
- std::fill(&familyIndexType[0], &familyIndexType[MAX_QUEUE_TYPES], -1u);
+ std::fill( &familyIndexType[0], &familyIndexType[MAX_QUEUE_TYPES], -1u );
// Graphics
auto& graphicsFamily = familyIndexType[0];
auto& presentFamily = familyIndexType[2];
auto queueFamilyIndex = 0u;
- for(auto& prop : mQueueFamilyProperties)
+ for( auto& prop : mQueueFamilyProperties )
{
- if((prop.queueFlags & vk::QueueFlagBits::eGraphics) && graphicsFamily == -1u)
+ if(( prop.queueFlags & vk::QueueFlagBits::eGraphics ) && graphicsFamily == -1u )
{
graphicsFamily = queueFamilyIndex;
}
- if((prop.queueFlags & vk::QueueFlagBits::eTransfer) && transferFamily == -1u)
+ if(( prop.queueFlags & vk::QueueFlagBits::eTransfer ) && transferFamily == -1u )
{
transferFamily = queueFamilyIndex;
}
- if(mPhysicalDevice.getSurfaceSupportKHR(queueFamilyIndex, mSurfaceFBIDMap.begin()->second.surface->GetSurfaceKHR())
- .value &&
- presentFamily == -1u)
+ if( mPhysicalDevice.getSurfaceSupportKHR( queueFamilyIndex, mSurfaceFBIDMap.begin()
+ ->second
+ .surface
+ ->GetSurfaceKHR())
+ .value &&
+ presentFamily == -1u )
{
presentFamily = queueFamilyIndex;
}
++queueFamilyIndex;
}
- assert(graphicsFamily != -1u && "No queue family that supports graphics operations!");
- assert(transferFamily != -1u && "No queue family that supports transfer operations!");
- assert(presentFamily != -1u && "No queue family that supports present operations!");
+ assert( graphicsFamily != -1u && "No queue family that supports graphics operations!" );
+ assert( transferFamily != -1u && "No queue family that supports transfer operations!" );
+ assert( presentFamily != -1u && "No queue family that supports present operations!" );
// todo: we may require that the family must be same for all types of operations, it makes
// easier to handle synchronisation related issues.
// sort queues
- std::sort(&familyIndexType[0], &familyIndexType[MAX_QUEUE_TYPES]);
+ std::sort( &familyIndexType[0], &familyIndexType[MAX_QUEUE_TYPES] );
// allocate all queues from graphics family
uint32_t prevQueueFamilyIndex = -1u;
- for(auto i = 0u; i < MAX_QUEUE_TYPES; ++i)
+ for( auto i = 0u; i < MAX_QUEUE_TYPES; ++i )
{
auto& familyIndex = familyIndexType[i];
- if(prevQueueFamilyIndex == familyIndex)
+ if( prevQueueFamilyIndex == familyIndex )
{
continue;
}
// note the priorities are not being set as local pointer will out of scope, this
// will be fixed by the caller function
auto info = vk::DeviceQueueCreateInfo{}
- .setPQueuePriorities(nullptr)
- .setQueueCount(queueCount)
- .setQueueFamilyIndex(familyIndex);
- queueInfos.push_back(info);
+ .setPQueuePriorities( nullptr )
+ .setQueueCount( queueCount )
+ .setQueueFamilyIndex( familyIndex );
+ queueInfos.push_back( info );
prevQueueFamilyIndex = familyIndex;
}
return queueInfos;
}
-#pragma GCC diagnostic pop
-std::vector<const char*> Graphics::PrepareDefaultInstanceExtensions()
+std::vector< const char* > Graphics::PrepareDefaultInstanceExtensions()
{
auto extensions = vk::enumerateInstanceExtensionProperties();
std::string extensionName;
- bool xlibAvailable { false };
- bool xcbAvailable { false };
- bool waylandAvailable { false };
+ bool xlibAvailable{ false };
+ bool xcbAvailable{ false };
+ bool waylandAvailable{ false };
for( auto&& ext : extensions.value )
{
}
}
- std::vector<const char*> retval{};
+ std::vector< const char* > retval{};
// depending on the platform validate extensions
auto platform = GetDefaultPlatform();
return retval;
}
-std::unique_ptr<ResourceCache>& Graphics::GetResourceCache(std::thread::id threadId)
-{
- if( mResourceCacheMap.count(threadId) == 0 )
- {
- std::lock_guard<std::mutex> lock{ mMutex };
- mResourceCacheMap[threadId] = MakeUnique< ResourceCache >();
- }
-
- return mResourceCacheMap[threadId];
-}
-
} // namespace Vulkan
} // namespace Graphics
} // namespace Dali