From 8045b8ba04aae39a4cf9733e72413f648b6ebe2b Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Sun, 18 Sep 2022 21:20:51 -0400 Subject: stanford dragon rendering --- engine/xe_device.hpp | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100755 engine/xe_device.hpp (limited to 'engine/xe_device.hpp') diff --git a/engine/xe_device.hpp b/engine/xe_device.hpp new file mode 100755 index 0000000..0906123 --- /dev/null +++ b/engine/xe_device.hpp @@ -0,0 +1,105 @@ +#pragma once + +#include "xe_window.hpp" + +#include +#include + +namespace xe { + +struct SwapChainSupportDetails { + VkSurfaceCapabilitiesKHR capabilities; + std::vector formats; + std::vector presentModes; +}; + +struct QueueFamilyIndices { + uint32_t graphicsFamily; + uint32_t presentFamily; + bool graphicsFamilyHasValue = false; + bool presentFamilyHasValue = false; + bool isComplete() { return graphicsFamilyHasValue && presentFamilyHasValue; } +}; + +class XeDevice { + public: +#ifdef NDEBUG + const bool enableValidationLayers = false; +#else + const bool enableValidationLayers = true; +#endif + + XeDevice(XeWindow &window); + ~XeDevice(); + + XeDevice(const XeDevice &) = delete; + void operator=(const XeDevice &) = delete; + XeDevice(XeDevice &&) = delete; + XeDevice &operator=(XeDevice &&) = delete; + + VkCommandPool getCommandPool() { return commandPool; } + VkDevice device() { return device_; } + VkSurfaceKHR surface() { return surface_; } + VkQueue graphicsQueue() { return graphicsQueue_; } + VkQueue presentQueue() { return presentQueue_; } + + SwapChainSupportDetails getSwapChainSupport() { return querySwapChainSupport(physicalDevice); } + uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties); + QueueFamilyIndices findPhysicalQueueFamilies() { return findQueueFamilies(physicalDevice); } + VkFormat findSupportedFormat( + const std::vector &candidates, VkImageTiling tiling, VkFormatFeatureFlags features); + + + void createBuffer( + VkDeviceSize size, + VkBufferUsageFlags usage, + VkMemoryPropertyFlags properties, + VkBuffer &buffer, + VkDeviceMemory &bufferMemory); + VkCommandBuffer beginSingleTimeCommands(); + void endSingleTimeCommands(VkCommandBuffer commandBuffer); + void copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size); + void copyBufferToImage( + VkBuffer buffer, VkImage image, uint32_t width, uint32_t height, uint32_t layerCount); + + void createImageWithInfo( + const VkImageCreateInfo &imageInfo, + VkMemoryPropertyFlags properties, + VkImage &image, + VkDeviceMemory &imageMemory); + + VkPhysicalDeviceProperties properties; + + private: + void createInstance(); + void setupDebugMessenger(); + void createSurface(); + void pickPhysicalDevice(); + void createLogicalDevice(); + void createCommandPool(); + + bool isDeviceSuitable(VkPhysicalDevice device); + std::vector getRequiredExtensions(); + bool checkValidationLayerSupport(); + QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device); + void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT &createInfo); + void hasGflwRequiredInstanceExtensions(); + bool checkDeviceExtensionSupport(VkPhysicalDevice device); + SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device); + + VkInstance instance; + VkDebugUtilsMessengerEXT debugMessenger; + VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; + XeWindow &window; + VkCommandPool commandPool; + + VkDevice device_; + VkSurfaceKHR surface_; + VkQueue graphicsQueue_; + VkQueue presentQueue_; + + const std::vector validationLayers = {"VK_LAYER_KHRONOS_validation"}; + const std::vector deviceExtensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_MAINTENANCE1_EXTENSION_NAME}; +}; + +} \ No newline at end of file -- cgit v1.2.3-freya