1 #ifndef _VKWSIUTIL_HPP 2 #define _VKWSIUTIL_HPP 3 /*------------------------------------------------------------------------- 4 * Vulkan CTS Framework 5 * -------------------- 6 * 7 * Copyright (c) 2016 Google Inc. 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief Windowing System Integration (WSI) Utilities. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "tcuCommandLine.hpp" 27 #include "vkDefs.hpp" 28 #include "vkWsiPlatform.hpp" 29 #include "vkRef.hpp" 30 #include "vkMemUtil.hpp" 31 #include "vkPrograms.hpp" 32 33 #include <vector> 34 35 namespace vk 36 { 37 namespace wsi 38 { 39 40 struct PlatformProperties 41 { 42 enum FeatureFlags 43 { 44 FEATURE_INITIAL_WINDOW_SIZE = (1<<0), //!< Platform honors initial window size request 45 FEATURE_RESIZE_WINDOW = (1<<1), //!< Platform supports resizing window 46 }; 47 48 enum SwapchainExtent 49 { 50 SWAPCHAIN_EXTENT_MUST_MATCH_WINDOW_SIZE = 0, //!< Swapchain extent must match window size 51 SWAPCHAIN_EXTENT_SETS_WINDOW_SIZE, //!< Window will be resized to swapchain size when first image is presented 52 SWAPCHAIN_EXTENT_SCALED_TO_WINDOW_SIZE, //!< Presented image contents will be scaled to window size 53 54 SWAPCHAIN_EXTENT_LAST 55 }; 56 57 deUint32 features; 58 SwapchainExtent swapchainExtent; 59 deUint32 maxDisplays; 60 deUint32 maxWindowsPerDisplay; 61 }; 62 63 const char* getName (Type wsiType); 64 const char* getExtensionName (Type wsiType); 65 66 const PlatformProperties& getPlatformProperties (Type wsiType); 67 68 VkResult createSurface (const InstanceInterface& vki, 69 VkInstance instance, 70 Type wsiType, 71 const Display& nativeDisplay, 72 const Window& nativeWindow, 73 const tcu::CommandLine& cmdLine, 74 const VkAllocationCallbacks* pAllocator, 75 VkSurfaceKHR* pSurface); 76 77 Move<VkSurfaceKHR> createSurface (const InstanceInterface& vki, 78 VkInstance instance, 79 Type wsiType, 80 const Display& nativeDisplay, 81 const Window& nativeWindow, 82 const tcu::CommandLine& cmdLine, 83 const VkAllocationCallbacks* pAllocator = DE_NULL); 84 85 VkBool32 getPhysicalDeviceSurfaceSupport (const InstanceInterface& vki, 86 VkPhysicalDevice physicalDevice, 87 deUint32 queueFamilyIndex, 88 VkSurfaceKHR surface); 89 90 VkBool32 getPhysicalDevicePresentationSupport (const InstanceInterface& vki, 91 VkPhysicalDevice physicalDevice, 92 deUint32 queueFamilyIndex, 93 Type wsiType, 94 const Display& nativeDisplay); 95 96 VkSurfaceCapabilitiesKHR getPhysicalDeviceSurfaceCapabilities (const InstanceInterface& vki, 97 VkPhysicalDevice physicalDevice, 98 VkSurfaceKHR surface); 99 100 VkSurfaceCapabilities2EXT getPhysicalDeviceSurfaceCapabilities2EXT(const InstanceInterface& vki, 101 VkPhysicalDevice physicalDevice, 102 VkSurfaceKHR surface); 103 104 bool sameSurfaceCapabilities (const VkSurfaceCapabilitiesKHR& khr, 105 const VkSurfaceCapabilities2EXT& ext); 106 107 std::vector<VkSurfaceFormatKHR> getPhysicalDeviceSurfaceFormats (const InstanceInterface& vki, 108 VkPhysicalDevice physicalDevice, 109 VkSurfaceKHR surface); 110 111 std::vector<VkPresentModeKHR> getPhysicalDeviceSurfacePresentModes (const InstanceInterface& vki, 112 VkPhysicalDevice physicalDevice, 113 VkSurfaceKHR surface); 114 115 std::vector<VkImage> getSwapchainImages (const DeviceInterface& vkd, 116 VkDevice device, 117 VkSwapchainKHR swapchain); 118 119 deUint32 chooseQueueFamilyIndex (const InstanceInterface& vki, 120 VkPhysicalDevice physicalDevice, 121 const std::vector<VkSurfaceKHR>& surfaces); 122 123 deUint32 chooseQueueFamilyIndex (const InstanceInterface& vki, 124 VkPhysicalDevice physicalDevice, 125 VkSurfaceKHR surface); 126 127 std::vector<deUint32> getCompatibleQueueFamilyIndices (const InstanceInterface& vki, 128 VkPhysicalDevice physicalDevice, 129 const std::vector<VkSurfaceKHR>& surface); 130 131 tcu::UVec2 getFullScreenSize (const vk::wsi::Type wsiType, 132 const vk::wsi::Display& display, 133 const tcu::UVec2& fallbackSize); 134 135 136 VkBool32 isDisplaySurface (Type wsiType); 137 138 class WsiTriangleRenderer 139 { 140 public: 141 WsiTriangleRenderer (const DeviceInterface& vkd, 142 const VkDevice device, 143 Allocator& allocator, 144 const BinaryCollection& binaryRegistry, 145 bool explicitLayoutTransitions, 146 const std::vector<VkImage> swapchainImages, 147 const std::vector<VkImage> aliasImages, 148 const VkFormat framebufferFormat, 149 const tcu::UVec2& renderSize); 150 151 WsiTriangleRenderer (WsiTriangleRenderer&& other); 152 153 ~WsiTriangleRenderer(void); 154 155 void recordFrame (VkCommandBuffer cmdBuffer, 156 deUint32 imageNdx, 157 deUint32 frameNdx) const; 158 159 void recordDeviceGroupFrame (VkCommandBuffer cmdBuffer, 160 deUint32 imageNdx, 161 deUint32 firstDeviceID, 162 deUint32 secondDeviceID, 163 deUint32 devicesCount, 164 deUint32 frameNdx) const; 165 166 static void getPrograms (SourceCollections& dst); 167 168 private: 169 static Move<VkRenderPass> createRenderPass (const DeviceInterface& vkd, 170 const VkDevice device, 171 const VkFormat colorAttachmentFormat, 172 const bool explicitLayoutTransitions); 173 174 static Move<VkPipelineLayout> createPipelineLayout(const DeviceInterface& vkd, 175 VkDevice device); 176 177 static Move<VkPipeline> createPipeline (const DeviceInterface& vkd, 178 const VkDevice device, 179 const VkRenderPass renderPass, 180 const VkPipelineLayout pipelineLayout, 181 const BinaryCollection& binaryCollection, 182 const tcu::UVec2& renderSize); 183 184 static Move<VkImageView> createAttachmentView(const DeviceInterface& vkd, 185 const VkDevice device, 186 const VkImage image, 187 const VkFormat format); 188 189 static Move<VkFramebuffer> createFramebuffer (const DeviceInterface& vkd, 190 const VkDevice device, 191 const VkRenderPass renderPass, 192 const VkImageView colorAttachment, 193 const tcu::UVec2& renderSize); 194 195 static Move<VkBuffer> createBuffer (const DeviceInterface& vkd, 196 VkDevice device, 197 VkDeviceSize size, 198 VkBufferUsageFlags usage); 199 200 const DeviceInterface& m_vkd; 201 202 bool m_explicitLayoutTransitions; 203 std::vector<VkImage> m_swapchainImages; 204 std::vector<VkImage> m_aliasImages; 205 tcu::UVec2 m_renderSize; 206 207 Move<VkRenderPass> m_renderPass; 208 Move<VkPipelineLayout> m_pipelineLayout; 209 Move<VkPipeline> m_pipeline; 210 211 Move<VkBuffer> m_vertexBuffer; 212 de::MovePtr<Allocation> m_vertexBufferMemory; 213 214 using ImageViewSp = de::SharedPtr<Unique<VkImageView>>; 215 using FramebufferSp = de::SharedPtr<Unique<VkFramebuffer>>; 216 217 std::vector<ImageViewSp> m_attachmentViews; 218 mutable std::vector<VkImageLayout> m_attachmentLayouts; 219 std::vector<FramebufferSp> m_framebuffers; 220 }; 221 222 } // wsi 223 } // vk 224 225 #endif // _VKWSIUTIL_HPP 226