source: opengl-game/vulkan-utils.hpp@ 603b5bc

feature/imgui-sdl points-test
Last change on this file since 603b5bc was 603b5bc, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 5 years ago

In vulkangame, add code to create the frame buffers and command buffers

  • Property mode set to 100644
File size: 4.1 KB
Line 
1#ifndef _VULKAN_UTILS_H
2#define _VULKAN_UTILS_H
3
4#include <optional>
5#include <string>
6#include <vector>
7
8#include <vulkan/vulkan.h>
9
10#include <SDL2/SDL.h>
11#include <SDL2/SDL_image.h>
12#include <SDL2/SDL_vulkan.h>
13
14using namespace std;
15
16struct QueueFamilyIndices {
17 optional<uint32_t> graphicsFamily;
18 optional<uint32_t> presentFamily;
19
20 bool isComplete() {
21 return graphicsFamily.has_value() && presentFamily.has_value();
22 }
23};
24
25struct SwapChainSupportDetails {
26 VkSurfaceCapabilitiesKHR capabilities;
27 vector<VkSurfaceFormatKHR> formats;
28 vector<VkPresentModeKHR> presentModes;
29};
30
31struct VulkanImage {
32 VkImage image;
33 VkDeviceMemory imageMemory;
34 VkImageView imageView;
35};
36
37class VulkanUtils {
38 public:
39 static bool checkValidationLayerSupport(const vector<const char*> &validationLayers);
40
41 static VkResult createDebugUtilsMessengerEXT(VkInstance instance,
42 const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
43 const VkAllocationCallbacks* pAllocator,
44 VkDebugUtilsMessengerEXT* pDebugMessenger);
45
46 static void destroyDebugUtilsMessengerEXT(VkInstance instance,
47 VkDebugUtilsMessengerEXT debugMessenger,
48 const VkAllocationCallbacks* pAllocator);
49
50 static QueueFamilyIndices findQueueFamilies(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface);
51 static bool checkDeviceExtensionSupport(VkPhysicalDevice physicalDevice,
52 const vector<const char*>& deviceExtensions);
53 static SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice physicalDevice,
54 VkSurfaceKHR surface);
55 static VkSurfaceFormatKHR chooseSwapSurfaceFormat(const vector<VkSurfaceFormatKHR>& availableFormats);
56 static VkPresentModeKHR chooseSwapPresentMode(const vector<VkPresentModeKHR>& availablePresentModes);
57 static VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, int width, int height);
58 static VkImageView createImageView(VkDevice device, VkImage image, VkFormat format,
59 VkImageAspectFlags aspectFlags);
60 static VkFormat findSupportedFormat(VkPhysicalDevice physicalDevice, const vector<VkFormat>& candidates,
61 VkImageTiling tiling, VkFormatFeatureFlags features);
62 static void createBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkDeviceSize size,
63 VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer,
64 VkDeviceMemory& bufferMemory);
65 static uint32_t findMemoryType(VkPhysicalDevice physicalDevice, uint32_t typeFilter,
66 VkMemoryPropertyFlags properties);
67
68 static void createVulkanImageFromFile(VkDevice device, VkPhysicalDevice physicalDevice,
69 VkCommandPool commandPool, string filename, VulkanImage& image, VkQueue graphicsQueue);
70 static void createVulkanImageFromSDLTexture(VkDevice device, VkPhysicalDevice physicalDevice,
71 SDL_Texture* texture, VulkanImage& image);
72 static void createDepthImage(VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool,
73 VkFormat depthFormat, VkExtent2D extent, VulkanImage& image, VkQueue graphicsQueue);
74 static void createImage(VkDevice device, VkPhysicalDevice physicalDevice, uint32_t width, uint32_t height,
75 VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties,
76 VulkanImage& image);
77
78 static void transitionImageLayout(VkDevice device, VkCommandPool commandPool, VkImage image,
79 VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, VkQueue graphicsQueue);
80 static VkCommandBuffer beginSingleTimeCommands(VkDevice device, VkCommandPool commandPool);
81 static void endSingleTimeCommands(VkDevice device, VkCommandPool commandPool,
82 VkCommandBuffer commandBuffer, VkQueue graphicsQueue);
83 static void copyBufferToImage(VkDevice device, VkCommandPool commandPool, VkBuffer buffer, VkImage image,
84 uint32_t width, uint32_t height, VkQueue graphicsQueue);
85
86 static bool hasStencilComponent(VkFormat format);
87
88 static void destroyVulkanImage(VkDevice& device, VulkanImage& image);
89};
90
91#endif // _VULKAN_UTILS_H
Note: See TracBrowser for help on using the repository browser.