minor fixes
This commit is contained in:
parent
d926d29dfa
commit
8aa57b4187
|
|
@ -4,7 +4,6 @@ project(Dyn)
|
||||||
set(CMAKE_CXX_STANDARD 26)
|
set(CMAKE_CXX_STANDARD 26)
|
||||||
|
|
||||||
file(GLOB_RECURSE sourceFiles "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/inc/*.h")
|
file(GLOB_RECURSE sourceFiles "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/inc/*.h")
|
||||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/inc")
|
|
||||||
|
|
||||||
find_package(Vulkan REQUIRED)
|
find_package(Vulkan REQUIRED)
|
||||||
find_package(glfw3 CONFIG REQUIRED)
|
find_package(glfw3 CONFIG REQUIRED)
|
||||||
|
|
@ -16,6 +15,8 @@ endforeach ()
|
||||||
|
|
||||||
add_executable(Dyn ${sourceFiles})
|
add_executable(Dyn ${sourceFiles})
|
||||||
|
|
||||||
|
target_include_directories(Dyn PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc")
|
||||||
|
|
||||||
target_link_libraries(Dyn PRIVATE Vulkan::Vulkan)
|
target_link_libraries(Dyn PRIVATE Vulkan::Vulkan)
|
||||||
target_link_libraries(Dyn PRIVATE glfw)
|
target_link_libraries(Dyn PRIVATE glfw)
|
||||||
target_link_libraries(Dyn PRIVATE Vulkan::SafeStruct Vulkan::LayerSettings Vulkan::UtilityHeaders Vulkan::CompilerConfiguration)
|
target_link_libraries(Dyn PRIVATE Vulkan::SafeStruct Vulkan::LayerSettings Vulkan::UtilityHeaders Vulkan::CompilerConfiguration)
|
||||||
|
|
@ -16,6 +16,10 @@
|
||||||
#define DYN_ERROR_LOG(...) ::dyn::core::errorln(__VA_ARGS__)
|
#define DYN_ERROR_LOG(...) ::dyn::core::errorln(__VA_ARGS__)
|
||||||
#define DYN_INFO_LOG(...) ::dyn::core::logln(__VA_ARGS__)
|
#define DYN_INFO_LOG(...) ::dyn::core::logln(__VA_ARGS__)
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define _WIN_VER
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN_VER
|
#ifdef _WIN_VER
|
||||||
#define DYN_BREAKPOINT __debugbreak()
|
#define DYN_BREAKPOINT __debugbreak()
|
||||||
#elif __has_builtin(__builtin_debugtrap)
|
#elif __has_builtin(__builtin_debugtrap)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
namespace dyn::core {
|
namespace dyn::core {
|
||||||
class logger {
|
class logger {
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,15 @@
|
||||||
#include <dyn/core/window.h>
|
#include <dyn/core/window.h>
|
||||||
|
|
||||||
namespace dyn {
|
namespace dyn {
|
||||||
|
using namespace core;
|
||||||
|
|
||||||
struct app_spec {
|
struct app_spec {
|
||||||
window_spec* window;
|
window_spec* window;
|
||||||
};
|
};
|
||||||
|
|
||||||
class application {
|
class application {
|
||||||
public:
|
public:
|
||||||
dyn_application();
|
application() {
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#include <dyn/core/debug.h>
|
#include <dyn/core/debug.h>
|
||||||
#include <vulkan/vk_enum_string_helper.h>
|
#include <vulkan/vk_enum_string_helper.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace dyn::utils {
|
namespace dyn::utils {
|
||||||
VkResult vkCreateDebugUtilsMessengerEXT(VkInstance instance,
|
VkResult vkCreateDebugUtilsMessengerEXT(VkInstance instance,
|
||||||
|
|
@ -22,8 +23,13 @@ namespace dyn::utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace dyn::utils {
|
namespace dyn::utils {
|
||||||
extern const std::vector<const char*> vk_validation_layers;
|
inline static std::vector vk_validation_layers = {
|
||||||
extern const std::vector<const char*> vk_device_extensions;
|
"VK_LAYER_KHRONOS_validation"
|
||||||
|
};
|
||||||
|
|
||||||
|
inline static std::vector vk_device_extensions = {
|
||||||
|
VK_KHR_SWAPCHAIN_EXTENSION_NAME
|
||||||
|
};
|
||||||
|
|
||||||
VkBool32 vk_debug_message_callback(
|
VkBool32 vk_debug_message_callback(
|
||||||
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ namespace dyn::core {
|
||||||
ref<vulkan_physical_device> _physical_device;
|
ref<vulkan_physical_device> _physical_device;
|
||||||
ref<vulkan_device> _device;
|
ref<vulkan_device> _device;
|
||||||
|
|
||||||
VkCommandPool _command_pool;
|
VkCommandPool _command_pool = nullptr;
|
||||||
|
|
||||||
VkDebugUtilsMessengerEXT _debug_messenger = nullptr;
|
VkDebugUtilsMessengerEXT _debug_messenger = nullptr;
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ namespace dyn::core {
|
||||||
|
|
||||||
ref<window> _window;
|
ref<window> _window;
|
||||||
|
|
||||||
static ref<vulkan_device> s_current_device;
|
inline static ref<vulkan_device> s_current_device = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#include <dyn/core/debug.h>
|
#include <dyn/core/debug.h>
|
||||||
#include <dyn/core/base.h>
|
#include <dyn/core/base.h>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace dyn::core {
|
namespace dyn::core {
|
||||||
class vulkan_context;
|
class vulkan_context;
|
||||||
|
|
||||||
|
|
@ -32,6 +34,7 @@ namespace dyn::core {
|
||||||
|
|
||||||
static VkPhysicalDevice determine_suitable_device(const std::vector<VkPhysicalDevice>& available_devices, const VkSurfaceKHR& surface);
|
static VkPhysicalDevice determine_suitable_device(const std::vector<VkPhysicalDevice>& available_devices, const VkSurfaceKHR& surface);
|
||||||
static uint32_t score_device(const VkPhysicalDevice& device);
|
static uint32_t score_device(const VkPhysicalDevice& device);
|
||||||
|
static bool check_extension_support(const VkPhysicalDevice& device);
|
||||||
|
|
||||||
static ref<vulkan_physical_device> create(const ref<vulkan_context>& ctx);
|
static ref<vulkan_physical_device> create(const ref<vulkan_context>& ctx);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,6 @@
|
||||||
#include <dyn/platform/vulkan/vulkan.h>
|
#include <dyn/platform/vulkan/vulkan.h>
|
||||||
|
|
||||||
namespace dyn::utils {
|
namespace dyn::utils {
|
||||||
const std::vector<const char*> vk_validation_layers = {
|
|
||||||
"VK_LAYER_KHRONOS_validation"
|
|
||||||
};
|
|
||||||
|
|
||||||
const std::vector<const char*> vk_device_extensions = {
|
|
||||||
VK_KHR_SWAPCHAIN_EXTENSION_NAME
|
|
||||||
};
|
|
||||||
|
|
||||||
VkResult vkCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT *pMessenger) {
|
VkResult vkCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT *pMessenger) {
|
||||||
auto func = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
|
auto func = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
|
||||||
if (func != nullptr) {
|
if (func != nullptr) {
|
||||||
|
|
@ -37,8 +29,8 @@ namespace dyn::utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
VkBool32 vk_debug_message_callback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
VkBool32 vk_debug_message_callback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||||
VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
|
VkDebugUtilsMessageTypeFlagsEXT, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
|
||||||
void *pUserData) {
|
void*) {
|
||||||
|
|
||||||
switch (messageSeverity) {
|
switch (messageSeverity) {
|
||||||
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT:
|
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT:
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@
|
||||||
|
|
||||||
namespace dyn::core {
|
namespace dyn::core {
|
||||||
|
|
||||||
vulkan_context::vulkan_context(const ref<window>& window) : _window(window) {}
|
vulkan_context::vulkan_context(const ref<window>& window) : _window(window) {
|
||||||
|
}
|
||||||
|
|
||||||
vulkan_context::~vulkan_context() {
|
vulkan_context::~vulkan_context() {
|
||||||
DYN_DEBUG_LOG("vulkan_context::~vulkan_context()");
|
DYN_DEBUG_LOG("vulkan_context::~vulkan_context()");
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ namespace dyn::core {
|
||||||
uint32_t prev_score = 0;
|
uint32_t prev_score = 0;
|
||||||
VkPhysicalDevice current_device = VK_NULL_HANDLE;
|
VkPhysicalDevice current_device = VK_NULL_HANDLE;
|
||||||
for (const auto& device : available_devices) {
|
for (const auto& device : available_devices) {
|
||||||
if (queue_families::find(device, surface).is_complete()) {
|
if (queue_families::find(device, surface).is_complete() && check_extension_support(device)) {
|
||||||
auto score = score_device(device);
|
auto score = score_device(device);
|
||||||
if (prev_score < score) {
|
if (prev_score < score) {
|
||||||
prev_score = score;
|
prev_score = score;
|
||||||
|
|
@ -106,7 +106,7 @@ namespace dyn::core {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (features.geometryShader == VK_TRUE) {
|
if (features.geometryShader == VK_TRUE) {
|
||||||
score = 100;
|
score += 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
DYN_DEBUG_LOG("Device Name:", std::string_view{properties.deviceName});
|
DYN_DEBUG_LOG("Device Name:", std::string_view{properties.deviceName});
|
||||||
|
|
@ -115,6 +115,21 @@ namespace dyn::core {
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool vulkan_physical_device::check_extension_support(const VkPhysicalDevice &device) {
|
||||||
|
uint32_t extension_count = 0;
|
||||||
|
vkEnumerateDeviceExtensionProperties(device, nullptr, &extension_count, nullptr);
|
||||||
|
std::vector<VkExtensionProperties> available_extensions{extension_count};
|
||||||
|
vkEnumerateDeviceExtensionProperties(device, nullptr, &extension_count, available_extensions.data());
|
||||||
|
|
||||||
|
auto device_extensions = utils::vk_device_extensions;
|
||||||
|
std::set<std::string> exts{device_extensions.begin(), device_extensions.end()};
|
||||||
|
for (const auto &required_extension : exts) {
|
||||||
|
exts.erase(required_extension);
|
||||||
|
}
|
||||||
|
|
||||||
|
return exts.empty();
|
||||||
|
}
|
||||||
|
|
||||||
ref<vulkan_physical_device> vulkan_physical_device::create(const ref<vulkan_context>& ctx) {
|
ref<vulkan_physical_device> vulkan_physical_device::create(const ref<vulkan_context>& ctx) {
|
||||||
return create_ref<vulkan_physical_device>(ctx);
|
return create_ref<vulkan_physical_device>(ctx);
|
||||||
}
|
}
|
||||||
|
|
@ -122,7 +137,7 @@ namespace dyn::core {
|
||||||
vulkan_device::vulkan_device(const ref<vulkan_physical_device> &physical_device, VkPhysicalDeviceFeatures device_Features) {
|
vulkan_device::vulkan_device(const ref<vulkan_physical_device> &physical_device, VkPhysicalDeviceFeatures device_Features) {
|
||||||
vulkan_physical_device::queue_families families = physical_device->get_queue_families();
|
vulkan_physical_device::queue_families families = physical_device->get_queue_families();
|
||||||
|
|
||||||
std::set<uint32_t> queue_family_indices = {families.graphics_family.value(), families.present_family.value()};
|
std::set queue_family_indices = {families.graphics_family.value(), families.present_family.value()};
|
||||||
std::vector<VkDeviceQueueCreateInfo> queue_create_infos;
|
std::vector<VkDeviceQueueCreateInfo> queue_create_infos;
|
||||||
|
|
||||||
float queue_priorities = 1.0f;
|
float queue_priorities = 1.0f;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user