forked from pupbrained/vulkan-test
Ok cool we're back to where we were
This commit is contained in:
parent
ba46d3d834
commit
98bd5f7bc2
140
src/main.cpp
140
src/main.cpp
|
@ -47,6 +47,7 @@ class VulkanApp {
|
||||||
|
|
||||||
vk::DebugUtilsMessengerUnique mDebugMessenger;
|
vk::DebugUtilsMessengerUnique mDebugMessenger;
|
||||||
vk::DispatchLoaderDynamic mLoader;
|
vk::DispatchLoaderDynamic mLoader;
|
||||||
|
vk::UniqueSurfaceKHR mSurface;
|
||||||
|
|
||||||
vk::PhysicalDevice mPhysicalDevice;
|
vk::PhysicalDevice mPhysicalDevice;
|
||||||
vk::UniqueDevice mDevice;
|
vk::UniqueDevice mDevice;
|
||||||
|
@ -54,12 +55,11 @@ class VulkanApp {
|
||||||
vk::Queue mGraphicsQueue;
|
vk::Queue mGraphicsQueue;
|
||||||
vk::Queue mPresentQueue;
|
vk::Queue mPresentQueue;
|
||||||
|
|
||||||
vk::UniqueSurfaceKHR mSurface;
|
vk::UniqueSwapchainKHR mSwapChain;
|
||||||
|
std::vector<vk::Image> mSwapChainImages;
|
||||||
vk::UniqueSwapchainKHR mSwapChain;
|
vk::Format mSwapChainImageFormat;
|
||||||
std::vector<vk::Image> mSwapChainImages;
|
vk::Extent2D mSwapChainExtent;
|
||||||
vk::Format mSwapChainImageFormat;
|
std::vector<vk::UniqueImageView> mSwapChainImageViews;
|
||||||
vk::Extent2D mSwapChainExtent;
|
|
||||||
|
|
||||||
struct QueueFamilyIndices {
|
struct QueueFamilyIndices {
|
||||||
std::optional<u32> graphics_family;
|
std::optional<u32> graphics_family;
|
||||||
|
@ -92,6 +92,7 @@ class VulkanApp {
|
||||||
pickPhysicalDevice();
|
pickPhysicalDevice();
|
||||||
createLogicalDevice();
|
createLogicalDevice();
|
||||||
createSwapChain();
|
createSwapChain();
|
||||||
|
createImageViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mainLoop() -> void {
|
fn mainLoop() -> void {
|
||||||
|
@ -220,52 +221,6 @@ class VulkanApp {
|
||||||
mPresentQueue = mDevice->getQueue(indices.present_family.value(), 0);
|
mPresentQueue = mDevice->getQueue(indices.present_family.value(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn isDeviceSuitable(vk::PhysicalDevice device) -> bool {
|
|
||||||
QueueFamilyIndices indices = findQueueFamilies(device);
|
|
||||||
|
|
||||||
bool extensionsSupported = checkDeviceExtensionSupport(device);
|
|
||||||
|
|
||||||
bool swapChainAdequate = false;
|
|
||||||
|
|
||||||
if (extensionsSupported) {
|
|
||||||
SwapChainSupportDetails swapChainSupport = querySwapChainSupport(device);
|
|
||||||
swapChainAdequate = !swapChainSupport.formats.empty() && !swapChainSupport.present_modes.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
return indices.isComplete() && extensionsSupported && swapChainAdequate;
|
|
||||||
}
|
|
||||||
|
|
||||||
static fn checkDeviceExtensionSupport(vk::PhysicalDevice device) -> bool {
|
|
||||||
std::vector<vk::ExtensionProperties> availableExtensions = device.enumerateDeviceExtensionProperties();
|
|
||||||
|
|
||||||
std::set<string> requiredExtensions(deviceExtensions.begin(), deviceExtensions.end());
|
|
||||||
|
|
||||||
for (const auto& extension : availableExtensions) requiredExtensions.erase(extension.extensionName);
|
|
||||||
|
|
||||||
return requiredExtensions.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn findQueueFamilies(vk::PhysicalDevice device) -> QueueFamilyIndices {
|
|
||||||
QueueFamilyIndices indices;
|
|
||||||
|
|
||||||
std::vector<vk::QueueFamilyProperties> queueFamilies = device.getQueueFamilyProperties();
|
|
||||||
|
|
||||||
for (u32 i = 0; i < queueFamilies.size(); i++) {
|
|
||||||
if (queueFamilies[i].queueFlags & vk::QueueFlagBits::eGraphics)
|
|
||||||
indices.graphics_family = i;
|
|
||||||
|
|
||||||
vk::Bool32 presentSupport = device.getSurfaceSupportKHR(i, mSurface.get());
|
|
||||||
|
|
||||||
if (presentSupport)
|
|
||||||
indices.present_family = i;
|
|
||||||
|
|
||||||
if (indices.isComplete())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return indices;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn createSwapChain() -> void {
|
fn createSwapChain() -> void {
|
||||||
SwapChainSupportDetails swapChainSupport = querySwapChainSupport(mPhysicalDevice);
|
SwapChainSupportDetails swapChainSupport = querySwapChainSupport(mPhysicalDevice);
|
||||||
|
|
||||||
|
@ -310,14 +265,27 @@ class VulkanApp {
|
||||||
mSwapChainExtent = extent;
|
mSwapChainExtent = extent;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn querySwapChainSupport(vk::PhysicalDevice device) -> SwapChainSupportDetails {
|
fn createImageViews() -> void {
|
||||||
SwapChainSupportDetails details;
|
mSwapChainImageViews.resize(mSwapChainImages.size());
|
||||||
|
|
||||||
details.capabilities = device.getSurfaceCapabilitiesKHR(mSurface.get());
|
for (u32 i = 0; i < mSwapChainImages.size(); i++) {
|
||||||
details.formats = device.getSurfaceFormatsKHR(mSurface.get());
|
vk::ImageViewCreateInfo createInfo {
|
||||||
details.present_modes = device.getSurfacePresentModesKHR(mSurface.get());
|
.image = mSwapChainImages[i],
|
||||||
|
.viewType = vk::ImageViewType::e2D,
|
||||||
|
.format = mSwapChainImageFormat,
|
||||||
|
.components = { .r = vk::ComponentSwizzle::eIdentity,
|
||||||
|
.g = vk::ComponentSwizzle::eIdentity,
|
||||||
|
.b = vk::ComponentSwizzle::eIdentity,
|
||||||
|
.a = vk::ComponentSwizzle::eIdentity },
|
||||||
|
.subresourceRange = { .aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||||
|
.baseMipLevel = 0,
|
||||||
|
.levelCount = 1,
|
||||||
|
.baseArrayLayer = 0,
|
||||||
|
.layerCount = 1 },
|
||||||
|
};
|
||||||
|
|
||||||
return details;
|
mSwapChainImageViews[i] = mDevice->createImageViewUnique(createInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static fn chooseSwapSurfaceFormat(const std::vector<vk::SurfaceFormatKHR>& availableFormats
|
static fn chooseSwapSurfaceFormat(const std::vector<vk::SurfaceFormatKHR>& availableFormats
|
||||||
|
@ -356,6 +324,62 @@ class VulkanApp {
|
||||||
return actualExtent;
|
return actualExtent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn querySwapChainSupport(vk::PhysicalDevice device) -> SwapChainSupportDetails {
|
||||||
|
SwapChainSupportDetails details;
|
||||||
|
|
||||||
|
details.capabilities = device.getSurfaceCapabilitiesKHR(mSurface.get());
|
||||||
|
details.formats = device.getSurfaceFormatsKHR(mSurface.get());
|
||||||
|
details.present_modes = device.getSurfacePresentModesKHR(mSurface.get());
|
||||||
|
|
||||||
|
return details;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn isDeviceSuitable(vk::PhysicalDevice device) -> bool {
|
||||||
|
QueueFamilyIndices indices = findQueueFamilies(device);
|
||||||
|
|
||||||
|
bool extensionsSupported = checkDeviceExtensionSupport(device);
|
||||||
|
|
||||||
|
bool swapChainAdequate = false;
|
||||||
|
|
||||||
|
if (extensionsSupported) {
|
||||||
|
SwapChainSupportDetails swapChainSupport = querySwapChainSupport(device);
|
||||||
|
swapChainAdequate = !swapChainSupport.formats.empty() && !swapChainSupport.present_modes.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return indices.isComplete() && extensionsSupported && swapChainAdequate;
|
||||||
|
}
|
||||||
|
|
||||||
|
static fn checkDeviceExtensionSupport(vk::PhysicalDevice device) -> bool {
|
||||||
|
std::vector<vk::ExtensionProperties> availableExtensions = device.enumerateDeviceExtensionProperties();
|
||||||
|
|
||||||
|
std::set<string> requiredExtensions(deviceExtensions.begin(), deviceExtensions.end());
|
||||||
|
|
||||||
|
for (const auto& extension : availableExtensions) requiredExtensions.erase(extension.extensionName);
|
||||||
|
|
||||||
|
return requiredExtensions.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn findQueueFamilies(vk::PhysicalDevice device) -> QueueFamilyIndices {
|
||||||
|
QueueFamilyIndices indices;
|
||||||
|
|
||||||
|
std::vector<vk::QueueFamilyProperties> queueFamilies = device.getQueueFamilyProperties();
|
||||||
|
|
||||||
|
for (u32 i = 0; i < queueFamilies.size(); i++) {
|
||||||
|
if (queueFamilies[i].queueFlags & vk::QueueFlagBits::eGraphics)
|
||||||
|
indices.graphics_family = i;
|
||||||
|
|
||||||
|
vk::Bool32 presentSupport = device.getSurfaceSupportKHR(i, mSurface.get());
|
||||||
|
|
||||||
|
if (presentSupport)
|
||||||
|
indices.present_family = i;
|
||||||
|
|
||||||
|
if (indices.isComplete())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return indices;
|
||||||
|
}
|
||||||
|
|
||||||
static fn getRequiredExtensions() -> std::vector<const char*> {
|
static fn getRequiredExtensions() -> std::vector<const char*> {
|
||||||
std::span<const char*> extensionsSpan = vkfw::getRequiredInstanceExtensions();
|
std::span<const char*> extensionsSpan = vkfw::getRequiredInstanceExtensions();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue