1 #ifndef DALI_GRAPHICS_VULKAN_GRAPHICS
2 #define DALI_GRAPHICS_VULKAN_GRAPHICS
5 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #ifndef VULKAN_HPP_NO_EXCEPTIONS
22 #define VULKAN_HPP_NO_EXCEPTIONS
26 #include <dali/graphics/vulkan/vulkan-types.h>
27 #include <dali/integration-api/graphics/surface-factory.h>
28 #include <dali/graphics/vulkan/vulkan-swapchain.h>
67 class GpuMemoryManager;
73 using SurfaceFactory = Dali::Integration::Graphics::SurfaceFactory;
75 struct SwapchainSurfacePair
77 RefCountedSwapchain swapchain;
78 RefCountedSurface surface;
87 Graphics( const Graphics& ) = delete;
89 Graphics& operator=( const Graphics& ) = delete;
93 public: // Create methods
99 FBID CreateSurface( std::unique_ptr< SurfaceFactory > surfaceFactory );
101 RefCountedSwapchain CreateSwapchainForSurface( RefCountedSurface surface );
103 RefCountedShader CreateShader(); //will see if this will work
104 RefCountedPipeline CreatePipeline();
106 RefCountedFence CreateFence( const vk::FenceCreateInfo& fenceCreateInfo );
108 RefCountedBuffer CreateBuffer( size_t size, BufferType type );
110 RefCountedBuffer CreateBuffer( const vk::BufferCreateInfo& bufferCreateInfo );
112 RefCountedFramebuffer CreateFramebuffer();
114 RefCountedImage CreateImage( const vk::ImageCreateInfo& imageCreateInfo );
116 RefCountedImageView CreateImageView( const vk::ImageViewCreateFlags& flags,
117 const RefCountedImage& image,
118 vk::ImageViewType viewType,
120 vk::ComponentMapping components,
121 vk::ImageSubresourceRange subresourceRange );
123 RefCountedImageView CreateImageView( RefCountedImage image );
125 RefCountedDescriptorPool CreateDescriptorPool();
127 RefCountedCommandPool CreateCommandPool( const vk::CommandPoolCreateInfo& info );
129 RefCountedCommandBuffer CreateCommandBuffer();
131 std::vector< RefCountedCommandBuffer > CreateCommandBuffers();
133 RefCountedGpuMemoryBlock CreateGpuMemoryBlock();
135 RefCountedDescriptorSet CreateDescriptorSet();
137 RefCountedSampler CreateSampler();
140 vk::Result WaitForFence( RefCountedFence fence, uint32_t timeout = 0 );
142 vk::Result WaitForFences( const std::vector< RefCountedFence >& fences,
144 uint32_t timeout = std::numeric_limits< uint32_t >::max());
146 vk::Result ResetFence( RefCountedFence fence );
148 vk::Result ResetFences( const std::vector< RefCountedFence >& fences );
150 vk::Result BindImageMemory( RefCountedImage image, RefCountedGpuMemoryBlock memory, uint32_t offset);
153 RefCountedSurface GetSurface( FBID surfaceId );
155 RefCountedSwapchain GetSwapchainForSurface( RefCountedSurface surface );
157 RefCountedSwapchain GetSwapchainForFBID( FBID surfaceId );
159 vk::Device GetDevice() const;
161 vk::PhysicalDevice GetPhysicalDevice() const;
163 vk::Instance GetInstance() const;
165 const vk::AllocationCallbacks& GetAllocator() const;
167 GpuMemoryManager& GetDeviceMemoryManager() const;
169 const vk::PhysicalDeviceMemoryProperties& GetMemoryProperties() const;
171 Queue& GetGraphicsQueue( uint32_t index = 0u ) const;
173 Queue& GetTransferQueue( uint32_t index = 0u ) const;
175 Queue& GetComputeQueue( uint32_t index = 0u ) const;
177 Queue& GetPresentQueue() const;
179 Platform GetDefaultPlatform() const;
181 Dali::Graphics::API::Controller& GetController();
183 PipelineCache& GetPipelineCache();
185 public: //Cache management methods
187 void AddBuffer( RefCountedBuffer buffer );
189 void AddImage( RefCountedImage image );
191 void AddShader( RefCountedShader shader );
193 void AddCommandPool( RefCountedCommandPool pool );
195 void AddDescriptorPool( RefCountedDescriptorPool pool );
197 void AddFramebuffer( RefCountedFramebuffer framebuffer );
199 RefCountedShader FindShader( vk::ShaderModule shaderModule );
201 RefCountedImage FindImage( vk::Image image );
203 void RemoveBuffer( Buffer& buffer );
205 void RemoveImage( Image& image );
207 void RemoveShader( Shader& shader );
209 void RemoveCommandPool( CommandPool& commandPool );
211 void RemoveDescriptorPool( DescriptorPool& pool );
213 void RemoveFramebuffer( Framebuffer& framebuffer );
215 void RemoveSampler( Sampler& sampler );
217 void CollectGarbage();
219 void DiscardResource( std::function< void() > deleter );
223 void CreateInstance( const std::vector< const char* >& extensions,
224 const std::vector< const char* >& validationLayers );
226 void DestroyInstance();
228 void PreparePhysicalDevice();
230 void GetPhysicalDeviceProperties();
232 void GetQueueFamilyProperties();
234 std::vector< vk::DeviceQueueCreateInfo > GetQueueCreateInfos();
236 std::vector< const char* > PrepareDefaultInstanceExtensions();
240 std::unique_ptr< GpuMemoryManager > mDeviceMemoryManager;
242 vk::Instance mInstance;
243 std::unique_ptr< vk::AllocationCallbacks > mAllocator{ nullptr };
246 vk::PhysicalDevice mPhysicalDevice;
251 // physical device properties
252 std::unique_ptr< vk::PhysicalDeviceProperties > mPhysicalDeviceProperties;
253 std::unique_ptr< vk::PhysicalDeviceMemoryProperties > mPhysicalDeviceMemoryProperties;
254 std::unique_ptr< vk::PhysicalDeviceFeatures > mPhysicalDeviceFeatures;
256 // queue family properties
257 std::vector< vk::QueueFamilyProperties > mQueueFamilyProperties;
259 std::unordered_map< FBID, SwapchainSurfacePair > mSurfaceFBIDMap;
260 FBID mBaseFBID{ 0u };
263 std::vector< std::unique_ptr< Queue > > mGraphicsQueues;
264 std::vector< std::unique_ptr< Queue > > mTransferQueues;
265 std::vector< std::unique_ptr< Queue > > mComputeQueues;
266 //std::unique_ptr< Queue > mPresentQueue;
268 Platform mPlatform{ Platform::UNDEFINED };
270 std::unique_ptr< Dali::Graphics::VulkanAPI::Controller > mGfxController;
273 std::unique_ptr< PipelineCache > mPipelineDatabase;
276 std::unique_ptr< ResourceCache > mResourceCache;
280 } // namespace Vulkan
281 } // namespace Graphics
284 #endif // DALI_GRAPHICS_VULKAN_GRAPHICS