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>
33 using SurfaceFactory = Dali::Integration::Graphics::SurfaceFactory;
57 class GpuMemoryManager;
60 struct SwapchainSurfacePair
62 SwapchainRef swapchain;
71 Graphics(std::unique_ptr< SurfaceFactory > surfaceFactory);
72 Graphics(const Graphics&) = delete;
73 Graphics& operator=(const Graphics&) = delete;
79 FBID CreateSurface(std::unique_ptr< SurfaceFactory > surfaceFactory);
81 SwapchainRef CreateSwapchainForSurface( SurfaceRef surface );
83 SurfaceRef GetSurface( FBID surfaceId );
85 SwapchainRef GetSwapchainForSurface( SurfaceRef surface );
87 SwapchainRef GetSwapchainForFBID( FBID surfaceId );
91 /** Creates new command pool */
92 CommandPoolRef CreateCommandPool(const vk::CommandPoolCreateInfo& info);
94 vk::Device GetDevice() const;
96 vk::PhysicalDevice GetPhysicalDevice() const;
98 vk::Instance GetInstance() const;
100 const vk::AllocationCallbacks& GetAllocator() const;
102 GpuMemoryManager& GetDeviceMemoryManager() const
104 return *mDeviceMemoryManager;
107 const vk::PhysicalDeviceMemoryProperties& GetMemoryProperties() const
109 return *mPhysicalDeviceMemoryProperties;
112 Queue& GetGraphicsQueue(uint32_t index = 0u) const;
113 Queue& GetTransferQueue(uint32_t index = 0u) const;
114 Queue& GetComputeQueue(uint32_t index = 0u) const;
115 Queue& GetPresentQueue() const;
117 Platform GetDefaultPlatform() const;
119 Dali::Graphics::API::Controller& GetController();
123 void CreateInstance( const std::vector<const char*>& extensions, const std::vector<const char*>& validationLayers );
124 void DestroyInstance();
125 void PreparePhysicalDevice();
126 void GetPhysicalDeviceProperties();
127 void GetQueueFamilyProperties();
128 std::vector< vk::DeviceQueueCreateInfo > GetQueueCreateInfos();
129 std::vector<const char*> PrepareDefaultInstanceExtensions();
133 std::unique_ptr<GpuMemoryManager> mDeviceMemoryManager;
135 vk::Instance mInstance;
136 std::unique_ptr<vk::AllocationCallbacks> mAllocator{nullptr};
139 vk::PhysicalDevice mPhysicalDevice;
144 // physical device properites
145 std::unique_ptr< vk::PhysicalDeviceProperties > mPhysicalDeviceProperties;
146 std::unique_ptr< vk::PhysicalDeviceMemoryProperties > mPhysicalDeviceMemoryProperties;
147 std::unique_ptr< vk::PhysicalDeviceFeatures > mPhysicalDeviceFeatures;
149 // queue family properties
150 std::vector< vk::QueueFamilyProperties > mQueueFamilyProperties;
152 std::unordered_map< FBID, SwapchainSurfacePair > mSurfaceFBIDMap;
156 std::vector< std::unique_ptr<Queue> > mGraphicsQueues;
157 std::vector< std::unique_ptr<Queue> > mTransferQueues;
158 std::vector< std::unique_ptr<Queue> > mComputeQueues;
159 //std::unique_ptr< Queue > mPresentQueue;
161 Platform mPlatform { Platform::UNDEFINED };
164 // TODO: all this stuff should go into some vulkan cache
166 void AddBuffer( BufferRef buffer );
167 void AddImage( ImageRef image );
168 void AddPipeline( PipelineRef pipeline );
169 void AddShader( ShaderRef shader );
170 void AddCommandPool( CommandPoolRef pool );
171 void AddDescriptorPool( DescriptorPoolRef pool );
172 void AddFramebuffer( FramebufferRef framebuffer );
174 ShaderRef FindShader( vk::ShaderModule shaderModule );
175 ImageRef FindImage( vk::Image image );
177 void RemoveBuffer( Buffer& buffer );
178 void RemoveShader( Shader& shader );
179 void RemoveCommandPool( CommandPool& commandPool );
180 void RemoveDescriptorPool( std::unique_ptr<DescriptorPool> pool );
183 std::vector<BufferRef> mBuffersCache;
184 std::vector<ImageRef> mImageCache;
185 std::vector<PipelineRef> mPipelineCache;
186 std::vector<ShaderRef> mShaderCache;
187 std::vector<CommandPoolRef> mCommandPoolCache;
188 std::vector<DescriptorPoolRef> mDescriptorPoolCache;
189 std::vector<FramebufferRef> mFramebufferCache;
192 std::unique_ptr<Dali::Graphics::API::Controller> mGfxController;
195 std::unique_ptr<PipelineCache> mPipelineDatabase;
198 PipelineCache& GetPipelineCache()
200 return *mPipelineDatabase.get();
204 } // namespace Vulkan
205 } // namespace Graphics
208 #endif // DALI_GRAPHICS_VULKAN_GRAPHICS