로깅과 vulkan validation layer 설정 끝
This commit is contained in:
@@ -13,6 +13,14 @@ FetchContent_Declare(
|
|||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(glm)
|
FetchContent_MakeAvailable(glm)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
spdlog
|
||||||
|
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
|
||||||
|
GIT_TAG "v1.15.2"
|
||||||
|
GIT_SHALLOW ON
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(spdlog)
|
||||||
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
glfw
|
glfw
|
||||||
GIT_REPOSITORY "https://github.com/glfw/glfw.git"
|
GIT_REPOSITORY "https://github.com/glfw/glfw.git"
|
||||||
@@ -40,6 +48,7 @@ target_link_libraries(VulkanEngine PRIVATE Vulkan::Vulkan)
|
|||||||
target_link_libraries(VulkanEngine PRIVATE glm)
|
target_link_libraries(VulkanEngine PRIVATE glm)
|
||||||
target_link_libraries(VulkanEngine PRIVATE glfw)
|
target_link_libraries(VulkanEngine PRIVATE glfw)
|
||||||
target_link_libraries(VulkanEngine PRIVATE Microsoft.GSL::GSL)
|
target_link_libraries(VulkanEngine PRIVATE Microsoft.GSL::GSL)
|
||||||
|
target_link_libraries(VulkanEngine PRIVATE spdlog)
|
||||||
|
|
||||||
target_include_directories(VulkanEngine PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
target_include_directories(VulkanEngine PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||||
target_compile_features(VulkanEngine PRIVATE cxx_std_20)
|
target_compile_features(VulkanEngine PRIVATE cxx_std_20)
|
||||||
|
|||||||
@@ -10,3 +10,4 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class Graphics final {
|
|||||||
|
|
||||||
void InitializeVulkan();
|
void InitializeVulkan();
|
||||||
void CreateInstance();
|
void CreateInstance();
|
||||||
|
void SetupDebugMessenger();
|
||||||
|
|
||||||
std::vector<gsl::czstring> GetRequiredInstanceExtentions();
|
std::vector<gsl::czstring> GetRequiredInstanceExtentions();
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ class Graphics final {
|
|||||||
static bool AreAllLayersSupported(gsl::span<gsl::czstring> extensions);
|
static bool AreAllLayersSupported(gsl::span<gsl::czstring> extensions);
|
||||||
|
|
||||||
VkInstance instance_ = nullptr;
|
VkInstance instance_ = nullptr;
|
||||||
|
VkDebugUtilsMessengerEXT debug_messenger_;
|
||||||
gsl::not_null<Window *> window_;
|
gsl::not_null<Window *> window_;
|
||||||
bool validation_enabled_ = false;
|
bool validation_enabled_ = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,8 +7,15 @@
|
|||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
|
||||||
namespace veng {
|
namespace veng {
|
||||||
|
void glfw_error_callback(std::int32_t error_code, gsl::czstring message) {
|
||||||
|
spdlog::error("Glfw Validation: {}", message);
|
||||||
|
}
|
||||||
|
|
||||||
GlfwInitialization::GlfwInitialization() {
|
GlfwInitialization::GlfwInitialization() {
|
||||||
|
glfwSetErrorCallback(glfw_error_callback);
|
||||||
if (glfwInit() != GLFW_TRUE) std::exit(EXIT_FAILURE);
|
if (glfwInit() != GLFW_TRUE) std::exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlfwInitialization::~GlfwInitialization() { glfwTerminate(); }
|
GlfwInitialization::~GlfwInitialization() { glfwTerminate(); }
|
||||||
|
|
||||||
} // namespace veng
|
} // namespace veng
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ std::int32_t main(std::int32_t argc, gsl::zstring* argv) {
|
|||||||
veng::Graphics graphics(&window);
|
veng::Graphics graphics(&window);
|
||||||
|
|
||||||
while (!window.ShouldClose()) {
|
while (!window.ShouldClose()) {
|
||||||
glfwSwapBuffers(window.GetHandle());
|
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,29 @@
|
|||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
|
||||||
|
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(
|
||||||
|
VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
|
||||||
|
const VkAllocationCallbacks* pAllocator,
|
||||||
|
VkDebugUtilsMessengerEXT* pMessenger) {
|
||||||
|
PFN_vkCreateDebugUtilsMessengerEXT function =
|
||||||
|
reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(
|
||||||
|
vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT"));
|
||||||
|
if (function != nullptr) {
|
||||||
|
return function(instance, pCreateInfo, pAllocator, pMessenger);
|
||||||
|
} else {
|
||||||
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(
|
||||||
|
VkInstance instance, VkDebugUtilsMessengerEXT messenger,
|
||||||
|
const VkAllocationCallbacks* pAllocator) {
|
||||||
|
PFN_vkDestroyDebugUtilsMessengerEXT function =
|
||||||
|
reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(
|
||||||
|
vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT"));
|
||||||
|
if (function != nullptr) function(instance, messenger, pAllocator);
|
||||||
|
}
|
||||||
|
|
||||||
namespace veng {
|
namespace veng {
|
||||||
|
|
||||||
static VKAPI_ATTR VkBool32 VKAPI_CALL
|
static VKAPI_ATTR VkBool32 VKAPI_CALL
|
||||||
@@ -13,11 +36,10 @@ ValidationCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
|||||||
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
|
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||||
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
||||||
void* pUserData) {
|
void* pUserData) {
|
||||||
if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
|
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
|
||||||
std::cerr << "Validation Error : " << pCallbackData->pMessage << std::endl;
|
spdlog::warn("Vulkan Validation: {}", pCallbackData->pMessage);
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Validation Message : " << pCallbackData->pMessage
|
spdlog::error("Vulkan Validation: {}", pCallbackData->pMessage);
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
return VK_FALSE;
|
return VK_FALSE;
|
||||||
}
|
}
|
||||||
@@ -27,8 +49,7 @@ static VkDebugUtilsMessengerCreateInfoEXT GetCreateMessengerInfo() {
|
|||||||
creation_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
|
creation_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
|
||||||
creation_info.messageSeverity =
|
creation_info.messageSeverity =
|
||||||
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
|
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
|
||||||
VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT |
|
VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
|
||||||
VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT;
|
|
||||||
creation_info.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
|
creation_info.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
|
||||||
VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
|
VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
|
||||||
creation_info.pfnUserCallback = ValidationCallback;
|
creation_info.pfnUserCallback = ValidationCallback;
|
||||||
@@ -45,10 +66,18 @@ Graphics::Graphics(gsl::not_null<Window*> window) : window_(window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Graphics::~Graphics() {
|
Graphics::~Graphics() {
|
||||||
if (instance_ != nullptr) vkDestroyInstance(instance_, nullptr);
|
if (instance_ != nullptr) {
|
||||||
|
if (debug_messenger_ != nullptr) {
|
||||||
|
vkDestroyDebugUtilsMessengerEXT(instance_, debug_messenger_, nullptr);
|
||||||
|
}
|
||||||
|
vkDestroyInstance(instance_, nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::InitializeVulkan() { CreateInstance(); }
|
void Graphics::InitializeVulkan() {
|
||||||
|
CreateInstance();
|
||||||
|
SetupDebugMessenger();
|
||||||
|
}
|
||||||
|
|
||||||
void Graphics::CreateInstance() {
|
void Graphics::CreateInstance() {
|
||||||
std::array<gsl::czstring, 1> validation_layers = {
|
std::array<gsl::czstring, 1> validation_layers = {
|
||||||
@@ -91,6 +120,18 @@ void Graphics::CreateInstance() {
|
|||||||
if (result != VK_SUCCESS) std::exit(EXIT_FAILURE);
|
if (result != VK_SUCCESS) std::exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Graphics::SetupDebugMessenger() {
|
||||||
|
if (!validation_enabled_) return;
|
||||||
|
|
||||||
|
VkDebugUtilsMessengerCreateInfoEXT info = GetCreateMessengerInfo();
|
||||||
|
VkResult result = vkCreateDebugUtilsMessengerEXT(instance_, &info, nullptr,
|
||||||
|
&debug_messenger_);
|
||||||
|
if (result != VK_SUCCESS) {
|
||||||
|
spdlog::error("Cannot create debug messenger");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gsl::span<gsl::czstring> Graphics::GetSuggestedInstanceExtentions() {
|
gsl::span<gsl::czstring> Graphics::GetSuggestedInstanceExtentions() {
|
||||||
std::uint32_t glfw_extention_count = 0;
|
std::uint32_t glfw_extention_count = 0;
|
||||||
gsl::czstring* glfw_extentions =
|
gsl::czstring* glfw_extentions =
|
||||||
|
|||||||
Reference in New Issue
Block a user