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>
37 using SurfaceFactory = Dali::Integration::Graphics::SurfaceFactory;
58 class GpuMemoryManager;
66 Graphics(std::unique_ptr< SurfaceFactory > surfaceFactory);
67 Graphics(const Graphics&) = delete;
68 Graphics& operator=(const Graphics&) = delete;
74 FBID CreateSurface(std::unique_ptr< SurfaceFactory > surfaceFactory);
76 Surface& GetSurface( FBID surfaceId );
80 /** Creates new command pool */
81 CommandPoolRef CreateCommandPool(const vk::CommandPoolCreateInfo& info);
83 vk::Device GetDevice() const;
85 vk::PhysicalDevice GetPhysicalDevice() const;
87 vk::Instance GetInstance() const;
89 const vk::AllocationCallbacks& GetAllocator() const;
91 GpuMemoryManager& GetDeviceMemoryManager() const
93 return *mDeviceMemoryManager;
96 const vk::PhysicalDeviceMemoryProperties& GetMemoryProperties() const
98 return *mPhysicalDeviceMemoryProperties;
101 Queue& GetGraphicsQueue(uint32_t index = 0u) const;
102 Queue& GetTransferQueue(uint32_t index = 0u) const;
103 Queue& GetComputeQueue(uint32_t index = 0u) const;
104 Queue& GetPresentQueue() const;
106 Platform GetDefaultPlatform() const;
108 Dali::Graphics::API::Controller& GetController();
112 void CreateInstance( const std::vector<const char*>& extensions, const std::vector<const char*>& validationLayers );
113 void DestroyInstance();
114 void PreparePhysicalDevice();
115 void GetPhysicalDeviceProperties();
116 void GetQueueFamilyProperties();
117 std::vector< vk::DeviceQueueCreateInfo > GetQueueCreateInfos();
118 std::vector<const char*> PrepareDefaultInstanceExtensions();
122 std::unique_ptr<GpuMemoryManager> mDeviceMemoryManager;
124 vk::Instance mInstance;
125 std::unique_ptr<vk::AllocationCallbacks> mAllocator{nullptr};
128 vk::PhysicalDevice mPhysicalDevice;
133 // physical device properites
134 std::unique_ptr< vk::PhysicalDeviceProperties > mPhysicalDeviceProperties;
135 std::unique_ptr< vk::PhysicalDeviceMemoryProperties > mPhysicalDeviceMemoryProperties;
136 std::unique_ptr< vk::PhysicalDeviceFeatures > mPhysicalDeviceFeatures;
138 // queue family properties
139 std::vector< vk::QueueFamilyProperties > mQueueFamilyProperties;
141 std::unordered_map< FBID, UniqueSurface > mSurfaceFBIDMap;
145 std::vector< std::unique_ptr<Queue> > mGraphicsQueues;
146 std::vector< std::unique_ptr<Queue> > mTransferQueues;
147 std::vector< std::unique_ptr<Queue> > mComputeQueues;
148 std::unique_ptr< Queue > mPresentQueue;
150 Platform mPlatform { Platform::UNDEFINED };
153 // TODO: all this stuff should go into some vulkan cache
155 void AddBuffer( Handle<Buffer> buffer );
156 void AddImage( Handle<Image> image );
157 void AddPipeline( Handle<Pipeline> pipeline );
158 void AddShader( Handle<Shader> shader );
159 void AddCommandPool( Handle<CommandPool> pool );
160 void AddDescriptorPool( Handle<DescriptorPool> pool );
161 void AddFramebuffer( Handle<Framebuffer> framebuffer );
163 ShaderRef FindShader( vk::ShaderModule shaderModule );
165 void RemoveBuffer( Buffer& buffer );
166 void RemoveShader( Shader& shader );
167 void RemoveCommandPool( CommandPool& commandPool );
168 void RemoveDescriptorPool( std::unique_ptr<DescriptorPool> pool );
171 std::vector<BufferRef> mBuffersCache;
172 std::vector<ImageRef> mImageCache;
173 std::vector<PipelineRef> mPipelineCache;
174 std::vector<ShaderRef> mShaderCache;
175 std::vector<CommandPoolRef> mCommandPoolCache;
176 std::vector<DescriptorPoolRef> mDescriptorPoolCache;
177 std::vector<FramebufferRef> mFramebufferCache;
180 std::unique_ptr<Dali::Graphics::Vulkan::Controller> mGfxController;
183 } // namespace Vulkan
184 } // namespace Graphics
187 #endif // DALI_GRAPHICS_VULKAN_GRAPHICS