This commit is contained in:
Bailey Harrison 2022-10-07 12:20:39 +01:00
parent a9b0918235
commit 04cc5fbcc9

View File

@ -48,6 +48,13 @@ namespace engine {
return surface; return surface;
} }
static VkFormat findSupportedFormat(const std::vector<VkFormat>& candidates, VkImageTiling tiling, VkFormatFeatureFlags features)
{
for (VkFormat format : candidates) {
}
}
class GFXDevice::Impl { class GFXDevice::Impl {
public: public:
@ -356,8 +363,6 @@ namespace engine {
VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SWAPCHAIN_EXTENSION_NAME,
}; };
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
for (const auto& dev : physicalDevices) { for (const auto& dev : physicalDevices) {
// first, check extension support // first, check extension support
@ -421,17 +426,17 @@ namespace engine {
continue; continue;
} }
physicalDevice = dev; m_physicalDevice = dev;
break; break;
} // end for() } // end for()
if (physicalDevice == VK_NULL_HANDLE) { if (m_physicalDevice == VK_NULL_HANDLE) {
throw std::runtime_error("No suitable Vulkan physical device found"); throw std::runtime_error("No suitable Vulkan physical device found");
} }
VkPhysicalDeviceProperties devProps; VkPhysicalDeviceProperties devProps;
vkGetPhysicalDeviceProperties(physicalDevice, &devProps); vkGetPhysicalDeviceProperties(m_physicalDevice, &devProps);
INFO("Selected physical device: {}", devProps.deviceName); INFO("Selected physical device: {}", devProps.deviceName);
TRACE("Supported present modes:"); TRACE("Supported present modes:");
@ -466,9 +471,9 @@ namespace engine {
// Get the queue families and find ones that support graphics, transfer, and compute // Get the queue families and find ones that support graphics, transfer, and compute
uint32_t queueFamilyCount = 0; uint32_t queueFamilyCount = 0;
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, nullptr); vkGetPhysicalDeviceQueueFamilyProperties(m_physicalDevice, &queueFamilyCount, nullptr);
std::vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount); std::vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount);
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, queueFamilies.data()); vkGetPhysicalDeviceQueueFamilyProperties(m_physicalDevice, &queueFamilyCount, queueFamilies.data());
std::optional<uint32_t> graphicsFamilyIndex; std::optional<uint32_t> graphicsFamilyIndex;
std::optional<uint32_t> transferFamilyIndex; std::optional<uint32_t> transferFamilyIndex;
@ -534,7 +539,7 @@ namespace engine {
// check the physical device is compatible with the surface // check the physical device is compatible with the surface
VkBool32 graphicsQueueCanPresent; VkBool32 graphicsQueueCanPresent;
res = vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, graphicsFamilyIndex.value(), m_surface->getHandle(), &graphicsQueueCanPresent); res = vkGetPhysicalDeviceSurfaceSupportKHR(m_physicalDevice, graphicsFamilyIndex.value(), m_surface->getHandle(), &graphicsQueueCanPresent);
assert(res == VK_SUCCESS); assert(res == VK_SUCCESS);
if (graphicsQueueCanPresent != VK_TRUE) { if (graphicsQueueCanPresent != VK_TRUE) {
throw std::runtime_error("The selected queue family does not support this surface"); throw std::runtime_error("The selected queue family does not support this surface");
@ -553,7 +558,7 @@ namespace engine {
.pEnabledFeatures = nullptr, .pEnabledFeatures = nullptr,
}; };
res = vkCreateDevice(physicalDevice, &deviceCreateInfo, nullptr, &m_handle); res = vkCreateDevice(m_physicalDevice, &deviceCreateInfo, nullptr, &m_handle);
if (res != VK_SUCCESS) { if (res != VK_SUCCESS) {
throw std::runtime_error("Unable to create Vulkan logical device, error code: " + std::to_string(res)); throw std::runtime_error("Unable to create Vulkan logical device, error code: " + std::to_string(res));
} }
@ -601,6 +606,11 @@ namespace engine {
return m_handle; return m_handle;
} }
VkPhysicalDevice getPhysicalDevice() const
{
return m_physicalDevice;
}
struct SwapchainSupportDetails { struct SwapchainSupportDetails {
VkSurfaceCapabilitiesKHR caps{}; VkSurfaceCapabilitiesKHR caps{};
std::vector<VkSurfaceFormatKHR> formats{}; std::vector<VkSurfaceFormatKHR> formats{};
@ -663,6 +673,8 @@ namespace engine {
VkDevice m_handle = VK_NULL_HANDLE; VkDevice m_handle = VK_NULL_HANDLE;
VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE;
std::vector<Queue> m_queues{}; std::vector<Queue> m_queues{};
VkCommandPool m_gfxCommandPool = VK_NULL_HANDLE; VkCommandPool m_gfxCommandPool = VK_NULL_HANDLE;
@ -672,8 +684,6 @@ namespace engine {
class Swapchain { class Swapchain {
// this class also creates a depth buffer image
public: public:
Swapchain(std::shared_ptr<Device> device) : m_device(device) Swapchain(std::shared_ptr<Device> device) : m_device(device)
{ {
@ -798,21 +808,8 @@ namespace engine {
m_imageViews.push_back(imageView); m_imageViews.push_back(imageView);
// create depth buffer // create depth buffer
VkImageCreateInfo depthImageInfo{ m_depthBuffer = std::make_unique<DepthBuffer>(m_currentExtent);
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
.flags = 0,
.imageType = VK_IMAGE_TYPE_2D,
.format = VK_FORMAT_D16_UNORM,
.extent = {
.width = chosenSwapExtent.width,
.height = chosenSwapExtent.height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 1,
.samples =
};
} }
@ -840,6 +837,26 @@ namespace engine {
VkFormat m_currentFormat{}; VkFormat m_currentFormat{};
VkExtent2D m_currentExtent{}; VkExtent2D m_currentExtent{};
class DepthBuffer {
public:
DepthBuffer(VkExtent2D bufferExtent)
{
VkImageCreateInfo depthImageInfo{
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
.flags = 0,
.imageType = VK_IMAGE_TYPE_2D,
};
}
DepthBuffer(const DepthBuffer&) = delete;
DepthBuffer& operator=(const DepthBuffer&) = delete;
~DepthBuffer()
{
}
};
std::unique_ptr<DepthBuffer> m_depthBuffer;
}; };