minecraftvulkan/engine/xe_device.hpp

111 lines
3.5 KiB
C++
Raw Normal View History

2022-09-19 01:20:51 +00:00
#pragma once
#include "xe_window.hpp"
#include <string>
#include <vector>
namespace xe {
struct SwapChainSupportDetails {
VkSurfaceCapabilitiesKHR capabilities;
std::vector<VkSurfaceFormatKHR> formats;
std::vector<VkPresentModeKHR> presentModes;
};
struct QueueFamilyIndices {
uint32_t graphicsFamily;
uint32_t presentFamily;
bool graphicsFamilyHasValue = false;
bool presentFamilyHasValue = false;
bool isComplete() { return graphicsFamilyHasValue && presentFamilyHasValue; }
};
2022-09-25 01:16:13 +00:00
class Device {
2022-09-19 01:20:51 +00:00
public:
#ifdef NDEBUG
const bool enableValidationLayers = false;
#else
const bool enableValidationLayers = true;
#endif
2022-09-25 01:16:13 +00:00
Device(Window &window);
~Device();
2022-09-19 01:20:51 +00:00
2022-09-25 01:16:13 +00:00
Device(const Device &) = delete;
void operator=(const Device &) = delete;
Device(Device &&) = delete;
Device &operator=(Device &&) = delete;
2022-09-19 01:20:51 +00:00
VkCommandPool getCommandPool() { return commandPool; }
VkDevice device() { return device_; }
VkSurfaceKHR surface() { return surface_; }
VkQueue graphicsQueue() { return graphicsQueue_; }
VkQueue presentQueue() { return presentQueue_; }
2022-09-26 04:06:51 +00:00
VkSampleCountFlagBits getSamples() { return msaaSamples; }
float getAnisotropy() { return samplerAnisotropy; }
2022-09-19 01:20:51 +00:00
SwapChainSupportDetails getSwapChainSupport() { return querySwapChainSupport(physicalDevice); }
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
QueueFamilyIndices findPhysicalQueueFamilies() { return findQueueFamilies(physicalDevice); }
VkFormat findSupportedFormat(
const std::vector<VkFormat> &candidates, VkImageTiling tiling, VkFormatFeatureFlags features);
void createBuffer(
VkDeviceSize size,
VkBufferUsageFlags usage,
VkMemoryPropertyFlags properties,
VkBuffer &buffer,
VkDeviceMemory &bufferMemory);
2022-09-26 03:08:03 +00:00
2022-09-19 01:20:51 +00:00
VkCommandBuffer beginSingleTimeCommands();
void endSingleTimeCommands(VkCommandBuffer commandBuffer);
void copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size);
2022-09-26 03:08:03 +00:00
void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height, uint32_t layerCount);
2022-09-19 01:20:51 +00:00
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<const char *> getRequiredExtensions();
bool checkValidationLayerSupport();
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device);
void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT &createInfo);
void hasGflwRequiredInstanceExtensions();
bool checkDeviceExtensionSupport(VkPhysicalDevice device);
SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device);
2022-09-26 03:08:03 +00:00
VkSampleCountFlagBits getMaxUsableSampleCount();
2022-09-19 01:20:51 +00:00
VkInstance instance;
VkDebugUtilsMessengerEXT debugMessenger;
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
2022-09-25 01:16:13 +00:00
Window &window;
2022-09-19 01:20:51 +00:00
VkCommandPool commandPool;
VkDevice device_;
VkSurfaceKHR surface_;
VkQueue graphicsQueue_;
VkQueue presentQueue_;
2022-09-26 03:08:03 +00:00
VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT;
2022-09-26 04:06:51 +00:00
float samplerAnisotropy = 1;
2022-09-26 03:08:03 +00:00
2022-09-19 01:20:51 +00:00
const std::vector<const char *> validationLayers = {"VK_LAYER_KHRONOS_validation"};
const std::vector<const char *> deviceExtensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_MAINTENANCE1_EXTENSION_NAME};
};
}