xref: /aosp_15_r20/external/deqp/external/vulkancts/framework/vulkan/vkWsiUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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     uint32_t features;
58     SwapchainExtent swapchainExtent;
59     uint32_t maxDisplays;
60     uint32_t 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, VkInstance instance, Type wsiType, const Display &nativeDisplay,
69                        const Window &nativeWindow, const tcu::CommandLine &cmdLine,
70                        const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface);
71 
72 Move<VkSurfaceKHR> createSurface(const InstanceInterface &vki, VkInstance instance, Type wsiType,
73                                  const Display &nativeDisplay, const Window &nativeWindow,
74                                  const tcu::CommandLine &cmdLine, const VkAllocationCallbacks *pAllocator = DE_NULL);
75 
76 VkBool32 getPhysicalDeviceSurfaceSupport(const InstanceInterface &vki, VkPhysicalDevice physicalDevice,
77                                          uint32_t queueFamilyIndex, VkSurfaceKHR surface);
78 
79 VkBool32 getPhysicalDevicePresentationSupport(const InstanceInterface &vki, VkPhysicalDevice physicalDevice,
80                                               uint32_t queueFamilyIndex, Type wsiType, const Display &nativeDisplay);
81 
82 VkSurfaceCapabilitiesKHR getPhysicalDeviceSurfaceCapabilities(const InstanceInterface &vki,
83                                                               VkPhysicalDevice physicalDevice, VkSurfaceKHR surface);
84 
85 VkSurfaceCapabilities2EXT getPhysicalDeviceSurfaceCapabilities2EXT(const InstanceInterface &vki,
86                                                                    VkPhysicalDevice physicalDevice,
87                                                                    VkSurfaceKHR surface);
88 
89 bool sameSurfaceCapabilities(const VkSurfaceCapabilitiesKHR &khr, const VkSurfaceCapabilities2EXT &ext);
90 
91 std::vector<VkSurfaceFormatKHR> getPhysicalDeviceSurfaceFormats(const InstanceInterface &vki,
92                                                                 VkPhysicalDevice physicalDevice, VkSurfaceKHR surface);
93 
94 std::vector<VkPresentModeKHR> getPhysicalDeviceSurfacePresentModes(const InstanceInterface &vki,
95                                                                    VkPhysicalDevice physicalDevice,
96                                                                    VkSurfaceKHR surface);
97 
98 std::vector<VkImage> getSwapchainImages(const DeviceInterface &vkd, VkDevice device, VkSwapchainKHR swapchain);
99 
100 uint32_t chooseQueueFamilyIndex(const InstanceInterface &vki, VkPhysicalDevice physicalDevice,
101                                 const std::vector<VkSurfaceKHR> &surfaces);
102 
103 uint32_t chooseQueueFamilyIndex(const InstanceInterface &vki, VkPhysicalDevice physicalDevice, VkSurfaceKHR surface);
104 
105 std::vector<uint32_t> getCompatibleQueueFamilyIndices(const InstanceInterface &vki, VkPhysicalDevice physicalDevice,
106                                                       const std::vector<VkSurfaceKHR> &surface);
107 
108 tcu::UVec2 getFullScreenSize(const vk::wsi::Type wsiType, const vk::wsi::Display &display,
109                              const tcu::UVec2 &fallbackSize);
110 
111 VkBool32 isDisplaySurface(Type wsiType);
112 
113 class WsiTriangleRenderer
114 {
115 public:
116     WsiTriangleRenderer(const DeviceInterface &vkd, const VkDevice device, Allocator &allocator,
117                         const BinaryCollection &binaryRegistry, bool explicitLayoutTransitions,
118                         const std::vector<VkImage> swapchainImages, const std::vector<VkImage> aliasImages,
119                         const VkFormat framebufferFormat, const tcu::UVec2 &renderSize);
120 
121     WsiTriangleRenderer(WsiTriangleRenderer &&other);
122 
123     ~WsiTriangleRenderer(void);
124 
125     void recordFrame(VkCommandBuffer cmdBuffer, uint32_t imageNdx, uint32_t frameNdx) const;
126 
127     void recordDeviceGroupFrame(VkCommandBuffer cmdBuffer, uint32_t imageNdx, uint32_t firstDeviceID,
128                                 uint32_t secondDeviceID, uint32_t devicesCount, uint32_t frameNdx) const;
129 
130     static void getPrograms(SourceCollections &dst);
131 
132 private:
133     static Move<VkRenderPass> createRenderPass(const DeviceInterface &vkd, const VkDevice device,
134                                                const VkFormat colorAttachmentFormat,
135                                                const bool explicitLayoutTransitions);
136 
137     static Move<VkPipelineLayout> createPipelineLayout(const DeviceInterface &vkd, VkDevice device);
138 
139     static Move<VkPipeline> createPipeline(const DeviceInterface &vkd, const VkDevice device,
140                                            const VkRenderPass renderPass, const VkPipelineLayout pipelineLayout,
141                                            const BinaryCollection &binaryCollection, const tcu::UVec2 &renderSize);
142 
143     static Move<VkImageView> createAttachmentView(const DeviceInterface &vkd, const VkDevice device,
144                                                   const VkImage image, const VkFormat format);
145 
146     static Move<VkFramebuffer> createFramebuffer(const DeviceInterface &vkd, const VkDevice device,
147                                                  const VkRenderPass renderPass, const VkImageView colorAttachment,
148                                                  const tcu::UVec2 &renderSize);
149 
150     static Move<VkBuffer> createBuffer(const DeviceInterface &vkd, VkDevice device, VkDeviceSize size,
151                                        VkBufferUsageFlags usage);
152 
153     const DeviceInterface &m_vkd;
154 
155     bool m_explicitLayoutTransitions;
156     std::vector<VkImage> m_swapchainImages;
157     std::vector<VkImage> m_aliasImages;
158     tcu::UVec2 m_renderSize;
159 
160     Move<VkRenderPass> m_renderPass;
161     Move<VkPipelineLayout> m_pipelineLayout;
162     Move<VkPipeline> m_pipeline;
163 
164     Move<VkBuffer> m_vertexBuffer;
165     de::MovePtr<Allocation> m_vertexBufferMemory;
166 
167     using ImageViewSp   = de::SharedPtr<Unique<VkImageView>>;
168     using FramebufferSp = de::SharedPtr<Unique<VkFramebuffer>>;
169 
170     std::vector<ImageViewSp> m_attachmentViews;
171     mutable std::vector<VkImageLayout> m_attachmentLayouts;
172     std::vector<FramebufferSp> m_framebuffers;
173 };
174 
175 } // namespace wsi
176 } // namespace vk
177 
178 #endif // _VKWSIUTIL_HPP
179