forked from pupbrained/vulkan-test
yes i will change those value calls to something else later
This commit is contained in:
parent
83631f940e
commit
daad4cc907
83
src/main.cpp
83
src/main.cpp
|
@ -5,6 +5,7 @@
|
|||
|
||||
#define VK_ENABLE_BETA_EXTENSIONS
|
||||
#define VULKAN_HPP_NO_CONSTRUCTORS
|
||||
#define VULKAN_HPP_NO_EXCEPTIONS
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
#include "util/types.h"
|
||||
|
@ -152,7 +153,10 @@ class VulkanApp {
|
|||
drawFrame();
|
||||
}
|
||||
|
||||
mDevice->waitIdle();
|
||||
auto result = mDevice->waitIdle();
|
||||
|
||||
if (result != vk::Result::eSuccess)
|
||||
throw std::runtime_error("Failed to wait for idle!");
|
||||
}
|
||||
|
||||
fn cleanupSwapChain() -> void {
|
||||
|
@ -177,7 +181,10 @@ class VulkanApp {
|
|||
vkfw::waitEvents();
|
||||
}
|
||||
|
||||
mDevice->waitIdle();
|
||||
auto result = mDevice->waitIdle();
|
||||
|
||||
if (result != vk::Result::eSuccess)
|
||||
throw std::runtime_error("Failed to wait for idle!");
|
||||
|
||||
cleanupSwapChain();
|
||||
|
||||
|
@ -225,12 +232,8 @@ class VulkanApp {
|
|||
for (const char* extension : extensions) fmt::println("\t{}", extension);
|
||||
#endif
|
||||
|
||||
try {
|
||||
mInstance = vk::createInstanceUnique(createInfo);
|
||||
mInstance = vk::createInstanceUnique(createInfo).value;
|
||||
mLoader = vk::DispatchLoaderDynamic(mInstance.get(), vkGetInstanceProcAddr);
|
||||
} catch (const vk::SystemError& err) {
|
||||
throw std::runtime_error("Failed to create instance: " + std::string(err.what()));
|
||||
}
|
||||
}
|
||||
|
||||
fn setupDebugMessenger() -> void {
|
||||
|
@ -247,13 +250,14 @@ class VulkanApp {
|
|||
.pfnUserCallback = debugCallback,
|
||||
};
|
||||
|
||||
mDebugMessenger = mInstance->createDebugUtilsMessengerEXTUnique(messengerCreateInfo, nullptr, mLoader);
|
||||
mDebugMessenger =
|
||||
mInstance->createDebugUtilsMessengerEXTUnique(messengerCreateInfo, nullptr, mLoader).value;
|
||||
}
|
||||
|
||||
fn createSurface() -> void { mSurface = vkfw::createWindowSurfaceUnique(mInstance.get(), mWindow.get()); }
|
||||
|
||||
fn pickPhysicalDevice() -> void {
|
||||
std::vector<vk::PhysicalDevice> devices = mInstance->enumeratePhysicalDevices();
|
||||
std::vector<vk::PhysicalDevice> devices = mInstance->enumeratePhysicalDevices().value;
|
||||
|
||||
if (devices.empty())
|
||||
throw std::runtime_error("Failed to find GPUs with Vulkan support!");
|
||||
|
@ -302,7 +306,7 @@ class VulkanApp {
|
|||
.ppEnabledExtensionNames = deviceExtensions.data(),
|
||||
.pEnabledFeatures = &deviceFeatures };
|
||||
|
||||
mDevice = mPhysicalDevice.createDeviceUnique(createInfo);
|
||||
mDevice = mPhysicalDevice.createDeviceUnique(createInfo).value;
|
||||
|
||||
mGraphicsQueue = mDevice->getQueue(indices.graphics_family.value(), 0);
|
||||
mPresentQueue = mDevice->getQueue(indices.present_family.value(), 0);
|
||||
|
@ -345,9 +349,9 @@ class VulkanApp {
|
|||
.oldSwapchain = nullptr,
|
||||
};
|
||||
|
||||
mSwapChain = mDevice->createSwapchainKHRUnique(createInfo);
|
||||
mSwapChain = mDevice->createSwapchainKHRUnique(createInfo).value;
|
||||
|
||||
mSwapChainImages = mDevice->getSwapchainImagesKHR(mSwapChain.get());
|
||||
mSwapChainImages = mDevice->getSwapchainImagesKHR(mSwapChain.get()).value;
|
||||
mSwapChainImageFormat = surfaceFormat.format;
|
||||
mSwapChainExtent = extent;
|
||||
}
|
||||
|
@ -371,7 +375,7 @@ class VulkanApp {
|
|||
.layerCount = 1 },
|
||||
};
|
||||
|
||||
mSwapChainImageViews[i] = mDevice->createImageViewUnique(createInfo);
|
||||
mSwapChainImageViews[i] = mDevice->createImageViewUnique(createInfo).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -405,7 +409,7 @@ class VulkanApp {
|
|||
.pSubpasses = &subpass,
|
||||
};
|
||||
|
||||
mRenderPass = mDevice->createRenderPassUnique(renderPassInfo);
|
||||
mRenderPass = mDevice->createRenderPassUnique(renderPassInfo).value;
|
||||
}
|
||||
|
||||
fn createGraphicsPipeline() -> void {
|
||||
|
@ -487,7 +491,7 @@ class VulkanApp {
|
|||
.pushConstantRangeCount = 0,
|
||||
};
|
||||
|
||||
mPipelineLayout = mDevice->createPipelineLayoutUnique(pipelineLayoutInfo);
|
||||
mPipelineLayout = mDevice->createPipelineLayoutUnique(pipelineLayoutInfo).value;
|
||||
|
||||
vk::GraphicsPipelineCreateInfo pipelineInfo {
|
||||
.stageCount = static_cast<u32>(shaderStages.size()),
|
||||
|
@ -520,7 +524,7 @@ class VulkanApp {
|
|||
.layers = 1,
|
||||
};
|
||||
|
||||
mSwapChainFramebuffers[i] = mDevice->createFramebufferUnique(framebufferInfo);
|
||||
mSwapChainFramebuffers[i] = mDevice->createFramebufferUnique(framebufferInfo).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -532,7 +536,7 @@ class VulkanApp {
|
|||
.queueFamilyIndex = queueFamilyIndices.graphics_family.value(),
|
||||
};
|
||||
|
||||
mCommandPool = mDevice->createCommandPoolUnique(poolInfo);
|
||||
mCommandPool = mDevice->createCommandPoolUnique(poolInfo).value;
|
||||
}
|
||||
|
||||
fn createCommandBuffers() -> void {
|
||||
|
@ -543,13 +547,16 @@ class VulkanApp {
|
|||
.commandBufferCount =
|
||||
static_cast<u32>(mCommandBuffers.size()) };
|
||||
|
||||
mCommandBuffers = mDevice->allocateCommandBuffersUnique(allocInfo);
|
||||
mCommandBuffers = mDevice->allocateCommandBuffersUnique(allocInfo).value;
|
||||
}
|
||||
|
||||
fn recordCommandBuffer(vk::CommandBuffer commandBuffer, u32 imageIndex) -> void {
|
||||
vk::CommandBufferBeginInfo beginInfo {};
|
||||
|
||||
commandBuffer.begin(beginInfo);
|
||||
vk::Result beginResult = commandBuffer.begin(beginInfo);
|
||||
|
||||
if (beginResult != vk::Result::eSuccess)
|
||||
throw std::runtime_error("Failed to begin command buffer!");
|
||||
|
||||
vk::ClearValue clearColor { .color = { .float32 = std::array<float, 4> { 0.0F, 0.0F, 0.0F, 1.0F } } };
|
||||
|
||||
|
@ -583,7 +590,11 @@ class VulkanApp {
|
|||
commandBuffer.draw(3, 1, 0, 0);
|
||||
|
||||
commandBuffer.endRenderPass();
|
||||
commandBuffer.end();
|
||||
|
||||
vk::Result endResult = commandBuffer.end();
|
||||
|
||||
if (endResult != vk::Result::eSuccess)
|
||||
throw std::runtime_error("Failed to end command buffer!");
|
||||
}
|
||||
|
||||
fn createSyncObjects() -> void {
|
||||
|
@ -595,9 +606,9 @@ class VulkanApp {
|
|||
vk::FenceCreateInfo fenceInfo { .flags = vk::FenceCreateFlagBits::eSignaled };
|
||||
|
||||
for (usize idx = 0; idx < MAX_FRAMES_IN_FLIGHT; idx++) {
|
||||
mImageAvailableSemaphores[idx] = mDevice->createSemaphoreUnique(semaphoreInfo);
|
||||
mRenderFinishedSemaphores[idx] = mDevice->createSemaphoreUnique(semaphoreInfo);
|
||||
mInFlightFences[idx] = mDevice->createFenceUnique(fenceInfo);
|
||||
mImageAvailableSemaphores[idx] = mDevice->createSemaphoreUnique(semaphoreInfo).value;
|
||||
mRenderFinishedSemaphores[idx] = mDevice->createSemaphoreUnique(semaphoreInfo).value;
|
||||
mInFlightFences[idx] = mDevice->createFenceUnique(fenceInfo).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -637,7 +648,10 @@ class VulkanApp {
|
|||
.pSignalSemaphores = &mRenderFinishedSemaphores[mCurrentFrame].get(),
|
||||
};
|
||||
|
||||
mGraphicsQueue.submit(submitInfo, mInFlightFences[mCurrentFrame].get());
|
||||
vk::Result submitResult = mGraphicsQueue.submit(submitInfo, mInFlightFences[mCurrentFrame].get());
|
||||
|
||||
if (submitResult != vk::Result::eSuccess)
|
||||
throw std::runtime_error("Failed to submit draw command buffer!");
|
||||
|
||||
vk::PresentInfoKHR presentInfo {
|
||||
.waitSemaphoreCount = 1,
|
||||
|
@ -649,11 +663,11 @@ class VulkanApp {
|
|||
|
||||
vk::Result presentResult = mPresentQueue.presentKHR(presentInfo);
|
||||
|
||||
if (presentResult == vk::Result::eErrorOutOfDateKHR || presentResult == vk::Result::eSuboptimalKHR || mFramebufferResized) {
|
||||
if (presentResult == vk::Result::eErrorOutOfDateKHR || presentResult == vk::Result::eSuboptimalKHR ||
|
||||
mFramebufferResized) {
|
||||
mFramebufferResized = false;
|
||||
recreateSwapChain();
|
||||
} else if (presentResult != vk::Result::eSuccess){
|
||||
std::cout << presentResult << '\n';
|
||||
} else if (presentResult != vk::Result::eSuccess) {
|
||||
throw std::runtime_error("Failed to present swap chain image!");
|
||||
}
|
||||
|
||||
|
@ -664,7 +678,7 @@ class VulkanApp {
|
|||
vk::ShaderModuleCreateInfo createInfo { .codeSize = code.size(),
|
||||
.pCode = std::bit_cast<const u32*>(code.data()) };
|
||||
|
||||
return mDevice->createShaderModuleUnique(createInfo);
|
||||
return mDevice->createShaderModuleUnique(createInfo).value;
|
||||
}
|
||||
|
||||
static fn chooseSwapSurfaceFormat(const std::vector<vk::SurfaceFormatKHR>& availableFormats
|
||||
|
@ -706,9 +720,9 @@ class VulkanApp {
|
|||
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());
|
||||
details.capabilities = device.getSurfaceCapabilitiesKHR(mSurface.get()).value;
|
||||
details.formats = device.getSurfaceFormatsKHR(mSurface.get()).value;
|
||||
details.present_modes = device.getSurfacePresentModesKHR(mSurface.get()).value;
|
||||
|
||||
return details;
|
||||
}
|
||||
|
@ -729,7 +743,8 @@ class VulkanApp {
|
|||
}
|
||||
|
||||
static fn checkDeviceExtensionSupport(vk::PhysicalDevice device) -> bool {
|
||||
std::vector<vk::ExtensionProperties> availableExtensions = device.enumerateDeviceExtensionProperties();
|
||||
std::vector<vk::ExtensionProperties> availableExtensions =
|
||||
device.enumerateDeviceExtensionProperties().value;
|
||||
|
||||
std::set<string> requiredExtensions(deviceExtensions.begin(), deviceExtensions.end());
|
||||
|
||||
|
@ -747,7 +762,7 @@ class VulkanApp {
|
|||
if (queueFamilies[i].queueFlags & vk::QueueFlagBits::eGraphics)
|
||||
indices.graphics_family = i;
|
||||
|
||||
vk::Bool32 presentSupport = device.getSurfaceSupportKHR(i, mSurface.get());
|
||||
vk::Bool32 presentSupport = device.getSurfaceSupportKHR(i, mSurface.get()).value;
|
||||
|
||||
if (presentSupport)
|
||||
indices.present_family = i;
|
||||
|
@ -771,7 +786,7 @@ class VulkanApp {
|
|||
}
|
||||
|
||||
static fn checkValidationLayerSupport() -> bool {
|
||||
std::vector<vk::LayerProperties> availableLayers = vk::enumerateInstanceLayerProperties();
|
||||
std::vector<vk::LayerProperties> availableLayers = vk::enumerateInstanceLayerProperties().value;
|
||||
|
||||
for (const char* layerName : validationLayers) {
|
||||
bool layerFound = false;
|
||||
|
|
Loading…
Reference in a new issue