1 #ifndef DALI_GRAPHICS_VULKAN_SURFACE_H
2 #define DALI_GRAPHICS_VULKAN_SURFACE_H
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.
22 #include <dali/graphics/vulkan/vulkan-types.h>
32 * Vulkan surface is coupled with swapchain -> one swapchain per surface
33 * Swapchain won't exist until surface is used in a such way
41 using UniqueSurface = std::unique_ptr< Surface >;
42 using UniqueCommandBuffer = std::unique_ptr< CommandBuffer >;
43 using UniqueCommandPool = std::unique_ptr< CommandPool >;
45 // simple structure describing single image of swapchain
46 // non-copyable, only movable
51 SwapchainImage(const SwapchainImage&) = delete;
52 SwapchainImage(SwapchainImage&&) = default;
53 SwapchainImage& operator=(const SwapchainImage&) = delete;
54 SwapchainImage& operator=(SwapchainImage&&) = default;
57 UniqueImageView imageView;
58 vk::Framebuffer framebuffer;
59 vk::ImageLayout layout;
61 vk::Semaphore presentSem;
63 // layout transitions, prerecorded command buffers
64 UniqueCommandBuffer layoutToColorCmdBuf;
65 UniqueCommandBuffer mainCmdBuf;
71 Surface(Graphics& graphics, vk::SurfaceKHR surface, uint32_t bufferCount = 2,
72 bool hasDepthStencil = false);
76 * Prepares new swapchain image
78 void AcquireNextImage();
89 vk::RenderPass GetRenderPass() const;
96 vk::Framebuffer GetFramebuffer(uint32_t index = -1u) const;
103 ImageView& GetImageView(uint32_t index = -1u) const;
110 Image& GetImage(uint32_t index = -1u) const;
116 vk::SurfaceKHR GetSurfaceKHR() const;
119 void CreateSwapchain();
121 void CreateVulkanSwapchain();
123 void CreateImageView(SwapchainImage& swapImage);
124 void CreateFramebuffer(SwapchainImage& swapImage);
125 void CreateSemaphores(SwapchainImage& swapImage);
127 void DestroySwapchain();
129 void InitialiseSwapchain();
131 void InitialiseRenderPass();
133 void AddSwapchainImage(vk::Image image, std::vector< SwapchainImage >& swapchainImages);
135 void CreateCommandBuffers();
137 void CreateDepthStencil();
139 void DestroyDepthStencil();
141 void BeginRenderPass();
143 void EndRenderPass();
146 vk::SurfaceKHR mSurface;
147 vk::SwapchainKHR mSwapchain;
149 vk::Format mDepthStencilFormat{vk::Format::eD16UnormS8Uint};
150 vk::Image mDepthStencilImage;
151 vk::ImageView mDepthStencilImageView;
152 vk::DeviceMemory mDepthStencilMemory;
154 UniqueCommandPool mCommandPool;
157 vk::ColorSpaceKHR mColorSpace;
158 vk::Extent2D mExtent;
160 std::vector< SwapchainImage > mSwapImages;
161 std::unique_ptr< vk::SurfaceCapabilitiesKHR > mCapabilities;
163 UniqueFence mFrameFence;
165 vk::RenderPass mDefaultRenderPass;
166 uint32_t mBufferCount;
167 uint32_t mCurrentBufferIndex;
168 bool mHasDepthStencil;
171 } // namespace Vulkan
172 } // namespace Graphics
175 #endif // DALI_GRAPHICS_VULKAN_SURFACE_H