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>
59 class GpuMemoryManager;
63 using SurfaceFactory = Dali::Integration::Graphics::SurfaceFactory;
65 struct SwapchainSurfacePair
67 RefCountedSwapchain swapchain;
68 RefCountedSurface surface;
76 Graphics(const Graphics&) = delete;
77 Graphics& operator=(const Graphics&) = delete;
80 public: // Create methods
84 FBID CreateSurface(std::unique_ptr< SurfaceFactory > surfaceFactory);
85 RefCountedSwapchain CreateSwapchainForSurface( RefCountedSurface surface );
86 RefCountedShader CreateShader(); //will see if this will work
87 RefCountedPipeline CreatePipeline();
88 RefCountedFence CreateFence( const vk::FenceCreateInfo& fenceCreateInfo );
89 RefCountedBuffer CreateBuffer( size_t size, BufferType type );
90 RefCountedBuffer CreateBuffer( const vk::BufferCreateInfo& bufferCreateInfo );
91 RefCountedFramebuffer CreateFramebuffer();
92 RefCountedImage CreateImage();
93 RefCountedImageView CreateImageView(const vk::ImageViewCreateFlags& flags,
94 const RefCountedImage& image,
95 vk::ImageViewType viewType,
97 vk::ComponentMapping components,
98 vk::ImageSubresourceRange subresourceRange);
99 RefCountedImageView CreateImageView(RefCountedImage image);
100 RefCountedDescriptorPool CreateDescriptorPool();
101 RefCountedCommandPool CreateCommandPool(const vk::CommandPoolCreateInfo& info);
102 RefCountedCommandBuffer CreateCommandBuffer();
103 std::vector< RefCountedCommandBuffer > CreateCommandBuffers();
104 RefCountedGpuMemoryBlock CreateGpuMemoryBlock();
105 RefCountedDescriptorSet CreateDescriptorSet();
106 RefCountedSampler CreateSampler();
109 vk::Result WaitForFence( RefCountedFence fence, uint32_t timeout = 0 );
110 vk::Result WaitForFences( const std::vector< RefCountedFence >& fences,
112 uint32_t timeout = std::numeric_limits< uint32_t >::max() );
113 vk::Result ResetFence( RefCountedFence fence );
114 vk::Result ResetFences( const std::vector< RefCountedFence >& fences );
117 RefCountedSurface GetSurface( FBID surfaceId );
119 RefCountedSwapchain GetSwapchainForSurface( RefCountedSurface surface );
121 RefCountedSwapchain GetSwapchainForFBID( FBID surfaceId );
123 vk::Device GetDevice() const;
125 vk::PhysicalDevice GetPhysicalDevice() const;
127 vk::Instance GetInstance() const;
129 const vk::AllocationCallbacks& GetAllocator() const;
131 GpuMemoryManager& GetDeviceMemoryManager() const;
133 const vk::PhysicalDeviceMemoryProperties& GetMemoryProperties() const;
135 Queue& GetGraphicsQueue(uint32_t index = 0u) const;
136 Queue& GetTransferQueue(uint32_t index = 0u) const;
137 Queue& GetComputeQueue(uint32_t index = 0u) const;
138 Queue& GetPresentQueue() const;
140 Platform GetDefaultPlatform() const;
142 Dali::Graphics::API::Controller& GetController();
144 PipelineCache& GetPipelineCache();
146 public: //Cache management methods
148 void AddBuffer( RefCountedBuffer buffer );
149 void AddImage( RefCountedImage image );
150 void AddShader( RefCountedShader shader );
151 void AddCommandPool( RefCountedCommandPool pool );
152 void AddDescriptorPool( RefCountedDescriptorPool pool );
153 void AddFramebuffer( RefCountedFramebuffer framebuffer );
155 RefCountedShader FindShader( vk::ShaderModule shaderModule );
156 RefCountedImage FindImage( vk::Image image );
158 void RemoveBuffer( Buffer& buffer );
159 void RemoveShader( Shader& shader );
160 void RemoveCommandPool( CommandPool& commandPool );
161 void RemoveDescriptorPool( DescriptorPool& pool );
162 void RemoveFramebuffer( Framebuffer& framebuffer );
163 void RemoveSampler( Sampler& sampler );
165 void CollectGarbage();
167 void DiscardResource(std::function<void()> deleter);
171 void CreateInstance( const std::vector<const char*>& extensions,
172 const std::vector<const char*>& validationLayers );
173 void DestroyInstance();
174 void PreparePhysicalDevice();
175 void GetPhysicalDeviceProperties();
176 void GetQueueFamilyProperties();
177 std::vector< vk::DeviceQueueCreateInfo > GetQueueCreateInfos();
178 std::vector<const char*> PrepareDefaultInstanceExtensions();
182 std::unique_ptr<GpuMemoryManager> mDeviceMemoryManager;
184 vk::Instance mInstance;
185 std::unique_ptr<vk::AllocationCallbacks> mAllocator{nullptr};
188 vk::PhysicalDevice mPhysicalDevice;
193 // physical device properties
194 std::unique_ptr< vk::PhysicalDeviceProperties > mPhysicalDeviceProperties;
195 std::unique_ptr< vk::PhysicalDeviceMemoryProperties > mPhysicalDeviceMemoryProperties;
196 std::unique_ptr< vk::PhysicalDeviceFeatures > mPhysicalDeviceFeatures;
198 // queue family properties
199 std::vector< vk::QueueFamilyProperties > mQueueFamilyProperties;
201 std::unordered_map< FBID, SwapchainSurfacePair > mSurfaceFBIDMap;
205 std::vector< std::unique_ptr<Queue> > mGraphicsQueues;
206 std::vector< std::unique_ptr<Queue> > mTransferQueues;
207 std::vector< std::unique_ptr<Queue> > mComputeQueues;
208 //std::unique_ptr< Queue > mPresentQueue;
210 Platform mPlatform { Platform::UNDEFINED };
212 std::unique_ptr<Dali::Graphics::VulkanAPI::Controller> mGfxController;
215 std::unique_ptr<PipelineCache> mPipelineDatabase;
218 std::unique_ptr< ResourceCache > mResourceCache;
222 } // namespace Vulkan
223 } // namespace Graphics
226 #endif // DALI_GRAPHICS_VULKAN_GRAPHICS