• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef BENCHMARKS_SWAPCHAIN_HPP_
16 #define BENCHMARKS_SWAPCHAIN_HPP_
17 
18 #include "VulkanHeaders.hpp"
19 #include <vector>
20 
21 class Window;
22 
23 class Swapchain
24 {
25 public:
26 	Swapchain(vk::PhysicalDevice physicalDevice, vk::Device device, Window &window);
27 	~Swapchain();
28 
29 	void acquireNextImage(vk::Semaphore presentCompleteSemaphore, uint32_t &imageIndex);
30 	void queuePresent(vk::Queue queue, uint32_t imageIndex, vk::Semaphore waitSemaphore);
31 
imageCount() const32 	size_t imageCount() const
33 	{
34 		return images.size();
35 	}
36 
getImageView(size_t i) const37 	vk::ImageView getImageView(size_t i) const
38 	{
39 		return imageViews[i];
40 	}
41 
getExtent() const42 	vk::Extent2D getExtent() const
43 	{
44 		return extent;
45 	}
46 
47 	const vk::Format colorFormat = vk::Format::eB8G8R8A8Unorm;
48 
49 private:
50 	const vk::Device device;
51 
52 	vk::SwapchainKHR swapchain;  // Owning handle
53 	vk::Extent2D extent;
54 
55 	std::vector<vk::Image> images;          // Weak pointers. Presentable images owned by swapchain object.
56 	std::vector<vk::ImageView> imageViews;  // Owning handles
57 };
58 
59 #endif  // BENCHMARKS_SWAPCHAIN_HPP_
60