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::DispatchLoaderDynamic mLoader;
|
||||
vk::UniqueSurfaceKHR mSurface;
|
||||
|
||||
vk::PhysicalDevice mPhysicalDevice;
|
||||
vk::UniqueDevice mDevice;
|
||||
|
@ -54,12 +55,11 @@ class VulkanApp {
|
|||
vk::Queue mGraphicsQueue;
|
||||
vk::Queue mPresentQueue;
|
||||
|
||||
vk::UniqueSurfaceKHR mSurface;
|
||||
|
||||
vk::UniqueSwapchainKHR mSwapChain;
|
||||
std::vector<vk::Image> mSwapChainImages;
|
||||
vk::Format mSwapChainImageFormat;
|
||||
vk::Extent2D mSwapChainExtent;
|
||||
vk::UniqueSwapchainKHR mSwapChain;
|
||||
std::vector<vk::Image> mSwapChainImages;
|
||||
vk::Format mSwapChainImageFormat;
|
||||
vk::Extent2D mSwapChainExtent;
|
||||
std::vector<vk::UniqueImageView> mSwapChainImageViews;
|
||||
|
||||
struct QueueFamilyIndices {
|
||||
std::optional<u32> graphics_family;
|
||||
|
@ -92,6 +92,7 @@ class VulkanApp {
|
|||
pickPhysicalDevice();
|
||||
createLogicalDevice();
|
||||
createSwapChain();
|
||||
createImageViews();
|
||||
}
|
||||
|
||||
fn mainLoop() -> void {
|
||||
|
@ -220,52 +221,6 @@ class VulkanApp {
|
|||
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 {
|
||||
SwapChainSupportDetails swapChainSupport = querySwapChainSupport(mPhysicalDevice);
|
||||
|
||||
|
@ -310,14 +265,27 @@ class VulkanApp {
|
|||
mSwapChainExtent = extent;
|
||||
}
|
||||
|
||||
fn querySwapChainSupport(vk::PhysicalDevice device) -> SwapChainSupportDetails {
|
||||
SwapChainSupportDetails details;
|
||||
fn createImageViews() -> void {
|
||||
mSwapChainImageViews.resize(mSwapChainImages.size());
|
||||
|
||||
details.capabilities = device.getSurfaceCapabilitiesKHR(mSurface.get());
|
||||
details.formats = device.getSurfaceFormatsKHR(mSurface.get());
|
||||
details.present_modes = device.getSurfacePresentModesKHR(mSurface.get());
|
||||
for (u32 i = 0; i < mSwapChainImages.size(); i++) {
|
||||
vk::ImageViewCreateInfo createInfo {
|
||||
.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
|
||||
|
@ -356,6 +324,62 @@ class VulkanApp {
|
|||
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*> {
|
||||
std::span<const char*> extensionsSpan = vkfw::getRequiredInstanceExtensions();
|
||||
|
||||
|
|
Loading…
Reference in a new issue