This commit is contained in:
Mars 2024-10-06 12:26:44 -04:00
parent df0e12a783
commit 0d77992e67
Signed by untrusted user: pupbrained
GPG key ID: 874E22DF2F9DFCB5

View file

@ -3,20 +3,19 @@
#include <iostream> #include <iostream>
#include <set> #include <set>
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
#define VK_ENABLE_BETA_EXTENSIONS #define VK_ENABLE_BETA_EXTENSIONS
#define VULKAN_HPP_NO_CONSTRUCTORS #define VULKAN_HPP_NO_CONSTRUCTORS
#define VULKAN_HPP_NO_EXCEPTIONS #define VULKAN_HPP_NO_EXCEPTIONS
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE
#include "util/types.h" #include "util/types.h"
#define VKFW_NO_STD_FUNCTION_CALLBACKS #define VKFW_NO_STD_FUNCTION_CALLBACKS
#include "vkfw.hpp" #include "vkfw.hpp"
namespace vk {
using DebugUtilsMessengerUnique = vk::UniqueHandle<vk::DebugUtilsMessengerEXT, vk::DispatchLoaderDynamic>;
}
constexpr i32 WIDTH = 800; constexpr i32 WIDTH = 800;
constexpr i32 HEIGHT = 600; constexpr i32 HEIGHT = 600;
@ -51,8 +50,7 @@ class VulkanApp {
vk::UniqueInstance mInstance; vk::UniqueInstance mInstance;
vk::DebugUtilsMessengerUnique mDebugMessenger; vk::UniqueDebugUtilsMessengerEXT mDebugMessenger;
vk::DispatchLoaderDynamic mLoader;
vk::UniqueSurfaceKHR mSurface; vk::UniqueSurfaceKHR mSurface;
vk::PhysicalDevice mPhysicalDevice; vk::PhysicalDevice mPhysicalDevice;
@ -160,14 +158,10 @@ class VulkanApp {
} }
fn cleanupSwapChain() -> void { fn cleanupSwapChain() -> void {
for (vk::UniqueHandle<vk::Framebuffer, vk::DispatchLoaderStatic>& mSwapChainFramebuffer : for (vk::UniqueFramebuffer& mSwapChainFramebuffer : mSwapChainFramebuffers) {
mSwapChainFramebuffers) {
mSwapChainFramebuffer.reset(); mSwapChainFramebuffer.reset();
} }
for (vk::UniqueHandle<vk::ImageView, vk::DispatchLoaderStatic>& mSwapChainImageView : for (vk::UniqueImageView& mSwapChainImageView : mSwapChainImageViews) { mSwapChainImageView.reset(); }
mSwapChainImageViews) {
mSwapChainImageView.reset();
}
mSwapChain.reset(); mSwapChain.reset();
} }
@ -201,7 +195,7 @@ class VulkanApp {
.applicationVersion = 1, .applicationVersion = 1,
.pEngineName = "No Engine", .pEngineName = "No Engine",
.engineVersion = 1, .engineVersion = 1,
.apiVersion = vk::ApiVersion10 }; .apiVersion = vk::ApiVersion12 };
// Retrieve extensions using custom function // Retrieve extensions using custom function
std::vector<const char*> extensions = getRequiredExtensions(); std::vector<const char*> extensions = getRequiredExtensions();
@ -233,7 +227,7 @@ class VulkanApp {
#endif #endif
mInstance = vk::createInstanceUnique(createInfo).value; mInstance = vk::createInstanceUnique(createInfo).value;
mLoader = vk::DispatchLoaderDynamic(mInstance.get(), vkGetInstanceProcAddr); VULKAN_HPP_DEFAULT_DISPATCHER.init(mInstance.get());
} }
fn setupDebugMessenger() -> void { fn setupDebugMessenger() -> void {
@ -251,7 +245,9 @@ class VulkanApp {
}; };
mDebugMessenger = mDebugMessenger =
mInstance->createDebugUtilsMessengerEXTUnique(messengerCreateInfo, nullptr, mLoader).value; mInstance
->createDebugUtilsMessengerEXTUnique(messengerCreateInfo, nullptr, VULKAN_HPP_DEFAULT_DISPATCHER)
.value;
} }
fn createSurface() -> void { mSurface = vkfw::createWindowSurfaceUnique(mInstance.get(), mWindow.get()); } fn createSurface() -> void { mSurface = vkfw::createWindowSurfaceUnique(mInstance.get(), mWindow.get()); }
@ -817,6 +813,11 @@ class VulkanApp {
}; };
fn main() -> i32 { fn main() -> i32 {
vk::DynamicLoader dynamicLoader;
auto vkGetInstanceProcAddr =
dynamicLoader.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
VulkanApp app; VulkanApp app;
try { try {