using new logger zlog
This commit is contained in:
parent
e27b1aeda9
commit
9192d2bfe7
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ vsxmake*/
|
||||
.engine/
|
||||
|
||||
|
||||
engine/logs/zengine.log
|
||||
|
||||
2
engine/3rdparty/zlog/src/zlog.cpp
vendored
2
engine/3rdparty/zlog/src/zlog.cpp
vendored
@ -11,7 +11,7 @@ namespace zlog {
|
||||
console_sink->set_level(spdlog::level::trace);
|
||||
console_sink->set_pattern("[%Y-%m-%d %H:%M:%S][%s:%#] %-8l %^%v%$");
|
||||
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("test.log", true);
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/zengine.log", true);
|
||||
file_sink->set_level(spdlog::level::trace);
|
||||
//file_sink->set_pattern("[%Y-%m-%d %H:%M:%S][%s:%#] %-8l %^%v%$");
|
||||
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
#include "backend.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "zlog.h"
|
||||
namespace vulkanapi {
|
||||
Backend::Backend(const char* appName, int deviceIndex) {
|
||||
Backend::Backend(const char* appName, int deviceIndex)
|
||||
{
|
||||
auto instanceCreator = Instance::InstanceCreator();
|
||||
mInstance = new Instance(instanceCreator);
|
||||
std::vector<VkPhysicalDevice> available_devices;
|
||||
mInstance->EnumerateAvailablePhysicalDevices(available_devices);
|
||||
int device_count = available_devices.size();
|
||||
if (device_count <= deviceIndex) {
|
||||
std::cout << "Could not get the number of available physical devices." << deviceIndex << device_count << std::endl;
|
||||
zlog::error("Could not get the number of available physical devices. out of boundry. {} > {}", deviceIndex, device_count);
|
||||
if (device_count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -12,11 +12,6 @@ namespace vulkanapi {
|
||||
|
||||
#define _USE_GRAPHIC_DEBUG
|
||||
|
||||
#define LOG_VULKAN(VkResult, info, ...) \
|
||||
if (VkResult != VK_SUCCESS) { \
|
||||
LOG_ERROR(info,##__VA_ARGS__)\
|
||||
}
|
||||
|
||||
using voidFn = std::function<void()>;
|
||||
using commandFn = std::function<void()>;
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ namespace vulkanapi {
|
||||
};
|
||||
VkResult result = vkCreateDevice(physDevice, &device_create_info, nullptr, &mPtr);
|
||||
if((result != VK_SUCCESS) || (mPtr == VK_NULL_HANDLE)) {
|
||||
std::cout << "Could not create logical device." << std::endl;
|
||||
zlog::error("Could not create logical device.");
|
||||
}
|
||||
}
|
||||
uint32_t Device::GetQueueFamilyIndex(VkQueueFlags flag)
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "zlog.h"
|
||||
namespace vulkanapi {
|
||||
constexpr float DEFAULT_QUEUE_PRIORITY = 1.0f;
|
||||
bool CheckAvailableQueueFamiliesAndTheirProperties(VkPhysicalDevice physical_device,std::vector<VkQueueFamilyProperties>& queue_families) {
|
||||
@ -10,14 +11,14 @@ namespace vulkanapi {
|
||||
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &queue_families_count, nullptr);
|
||||
if (queue_families_count == 0) {
|
||||
std::cout << "Could not get the number of queue families." << std::endl;
|
||||
zlog::error("Could not get the number of queue families.");
|
||||
return false;
|
||||
}
|
||||
|
||||
queue_families.resize(queue_families_count);
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &queue_families_count, queue_families.data());
|
||||
if (queue_families_count == 0) {
|
||||
std::cout << "Could not acquire properties of queue families." << std::endl;
|
||||
zlog::error("Could not acquire properties of queue families.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -56,7 +56,10 @@ namespace vulkanapi {
|
||||
static_cast<uint32_t>(extensions.size()), // uint32_t enabledExtensionCount
|
||||
extensions.data() // const char * const * ppEnabledExtensionNames
|
||||
};
|
||||
//LOG_VULKAN(vkCreateInstance(&instance_create_info, nullptr, &mPtr), "Failed to create instance.");
|
||||
VkResult result = vkCreateInstance(&instance_create_info, nullptr, &mPtr);
|
||||
if (result != VK_SUCCESS) {
|
||||
zlog::error("Failed to create instance.");
|
||||
}
|
||||
|
||||
//调用vulkan接口,加载实例函数指针
|
||||
LoadInstanceLevelFunctions(mPtr, extensions);
|
||||
@ -69,7 +72,7 @@ namespace vulkanapi {
|
||||
result = vkEnumeratePhysicalDevices(mPtr, &devices_count, nullptr);
|
||||
if ((result != VK_SUCCESS) ||
|
||||
(devices_count == 0)) {
|
||||
std::cout << "Could not get the number of available physical devices." << std::endl;
|
||||
zlog::error("Could not get the number of available physical devices.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -77,7 +80,7 @@ namespace vulkanapi {
|
||||
result = vkEnumeratePhysicalDevices(mPtr, &devices_count, available_devices.data());
|
||||
if ((result != VK_SUCCESS) ||
|
||||
(devices_count == 0)) {
|
||||
std::cout << "Could not enumerate physical devices." << std::endl;
|
||||
zlog::error("Could not enumerate physical devices.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ namespace vulkanapi {
|
||||
vulkan_library = dlopen("libvulkan.so.1", RTLD_NOW);
|
||||
#endif
|
||||
if (vulkan_library == nullptr) {
|
||||
LOG_INFO("Could not connect with a Vulkan Runtime library.");
|
||||
zlog::error("Could not connect with a Vulkan Runtime library.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -27,7 +27,7 @@ namespace vulkanapi {
|
||||
#define EXPORTED_VULKAN_FUNCTION( name ) \
|
||||
name = (PFN_##name)LoadFunction( vulkan_library, #name ); \
|
||||
if( name == nullptr ) { \
|
||||
LOG_ERROR( "Could not load exported Vulkan function named:"#name);\
|
||||
zlog::error( "Could not load exported Vulkan function named:"#name);\
|
||||
return false; \
|
||||
}
|
||||
#include "engine/vulkanapi/vulkan_function_list.inl"
|
||||
@ -38,7 +38,7 @@ namespace vulkanapi {
|
||||
#define GLOBAL_LEVEL_VULKAN_FUNCTION( name ) \
|
||||
name = (PFN_##name)vkGetInstanceProcAddr( nullptr, #name ); \
|
||||
if( name == nullptr ) { \
|
||||
LOG_ERROR( "Could not load global level Vulkan function named:"#name);\
|
||||
zlog::error( "Could not load global level Vulkan function named:"#name);\
|
||||
return false; \
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ namespace vulkanapi {
|
||||
#define INSTANCE_LEVEL_VULKAN_FUNCTION( name ) \
|
||||
name = (PFN_##name)vkGetInstanceProcAddr( instance, #name ); \
|
||||
if( name == nullptr ) { \
|
||||
LOG_ERROR( "Could not load instance-level Vulkan function named:"#name);\
|
||||
zlog::error( "Could not load instance-level Vulkan function named:"#name);\
|
||||
return false; \
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ namespace vulkanapi {
|
||||
if( std::string( enabled_extension ) == std::string( extension ) ) { \
|
||||
name = (PFN_##name)vkGetInstanceProcAddr( instance, #name ); \
|
||||
if( name == nullptr ) { \
|
||||
LOG_ERROR( "Could not load instance-level Vulkan function named:"#name);\
|
||||
zlog::error( "Could not load instance-level Vulkan function named:"#name);\
|
||||
return false; \
|
||||
} \
|
||||
} \
|
||||
@ -97,7 +97,7 @@ namespace vulkanapi {
|
||||
result = vkEnumerateInstanceLayerProperties(&extensions_count, nullptr);
|
||||
if ((result != VK_SUCCESS) ||
|
||||
(extensions_count == 0)) {
|
||||
LOG_ERROR("Could not get the number of instance layers.");
|
||||
zlog::error("Could not get the number of instance layers.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ namespace vulkanapi {
|
||||
result = vkEnumerateInstanceLayerProperties(&extensions_count, available_layers.data());
|
||||
if ((result != VK_SUCCESS) ||
|
||||
(extensions_count == 0)) {
|
||||
LOG_ERROR("Could not enumerate instance layers.");
|
||||
zlog::error("Could not enumerate instance layers.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ namespace vulkanapi {
|
||||
result = vkEnumerateInstanceExtensionProperties(nullptr, &extensions_count, nullptr);
|
||||
if ((result != VK_SUCCESS) ||
|
||||
(extensions_count == 0)) {
|
||||
LOG_ERROR("Could not get the number of instance extensions.");
|
||||
zlog::error("Could not get the number of instance extensions.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ namespace vulkanapi {
|
||||
result = vkEnumerateInstanceExtensionProperties(nullptr, &extensions_count, available_extensions.data());
|
||||
if ((result != VK_SUCCESS) ||
|
||||
(extensions_count == 0)) {
|
||||
LOG_ERROR("Could not enumerate instance extensions.");
|
||||
zlog::error("Could not enumerate instance extensions.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ namespace vulkanapi {
|
||||
_extension.push_back(extensions[i].c_str());
|
||||
}
|
||||
else {
|
||||
LOG_ERROR("cann't support extension: {}", extensions[i].c_str());
|
||||
zlog::error("cann't support extension: {}", extensions[i].c_str());
|
||||
}
|
||||
}
|
||||
return _extension;
|
||||
@ -159,7 +159,7 @@ namespace vulkanapi {
|
||||
_layers.push_back(layers[i].c_str());
|
||||
}
|
||||
else {
|
||||
LOG_ERROR("Could not load instance-level Vulkan function named: {}", layers[i].c_str());
|
||||
zlog::error("Could not load instance-level Vulkan function named: {}", layers[i].c_str());
|
||||
}
|
||||
}
|
||||
return _layers;
|
||||
@ -170,7 +170,7 @@ namespace vulkanapi {
|
||||
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
||||
void*)
|
||||
{
|
||||
std::cerr << "validation layer: " << pCallbackData->pMessage << std::endl;
|
||||
zlog::error("validation layer: {}", pCallbackData->pMessage);
|
||||
return VK_FALSE;
|
||||
}
|
||||
VkDebugUtilsMessengerCreateInfoEXT _DebugUtilsLayerNext() {
|
||||
|
||||
@ -27,7 +27,6 @@ namespace vulkanapi {
|
||||
CreateSwapchain(device.Ptr(), presentation_surface, frames, { image_format, image_color_space }, image_size
|
||||
, imageUsage, VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR,VK_PRESENT_MODE_FIFO_KHR, old_swapchain, mPtr);
|
||||
|
||||
std::cout << "sizeof image" << sizeof(Image);
|
||||
std::vector<VkImage> swapchain_images;
|
||||
GetHandlesOfSwapchainImages(device.Ptr(), mPtr, swapchain_images);
|
||||
uint32_t image_count = swapchain_images.size();
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "instance.h"
|
||||
#include <iostream>
|
||||
#include "zlog.h"
|
||||
namespace vulkanapi {
|
||||
bool GetCapabilitiesOfPresentationSurface(VkPhysicalDevice physical_device,
|
||||
VkSurfaceKHR presentation_surface,
|
||||
@ -7,7 +8,7 @@ namespace vulkanapi {
|
||||
VkResult result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, presentation_surface, &surface_capabilities);
|
||||
|
||||
if (VK_SUCCESS != result) {
|
||||
std::cout << "Could not get the capabilities of a presentation surface." << std::endl;
|
||||
zlog::error("Could not get the capabilities of a presentation surface.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -46,7 +47,7 @@ namespace vulkanapi {
|
||||
result = vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, presentation_surface, &formats_count, nullptr);
|
||||
if ((VK_SUCCESS != result) ||
|
||||
(0 == formats_count)) {
|
||||
std::cout << "Could not get the number of supported surface formats." << std::endl;
|
||||
zlog::error("Could not get the number of supported surface formats.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -54,7 +55,7 @@ namespace vulkanapi {
|
||||
result = vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, presentation_surface, &formats_count, surface_formats.data());
|
||||
if ((VK_SUCCESS != result) ||
|
||||
(0 == formats_count)) {
|
||||
std::cout << "Could not enumerate supported surface formats." << std::endl;
|
||||
zlog::error("Could not enumerate supported surface formats.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -79,14 +80,14 @@ namespace vulkanapi {
|
||||
if (desired_surface_format.format == surface_format.format) {
|
||||
image_format = desired_surface_format.format;
|
||||
image_color_space = surface_format.colorSpace;
|
||||
std::cout << "Desired combination of format and colorspace is not supported. Selecting other colorspace." << std::endl;
|
||||
zlog::error("Desired combination of format and colorspace is not supported. Selecting other colorspace.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
image_format = surface_formats[0].format;
|
||||
image_color_space = surface_formats[0].colorSpace;
|
||||
std::cout << "Desired format is not supported. Selecting available format - colorspace combination." << std::endl;
|
||||
zlog::error("Desired format is not supported. Selecting available format - colorspace combination.");
|
||||
return true;
|
||||
}
|
||||
bool CreateSwapchain(VkDevice logical_device,
|
||||
@ -123,7 +124,7 @@ namespace vulkanapi {
|
||||
VkResult result = vkCreateSwapchainKHR(logical_device, &swapchain_create_info, nullptr, &swapchain);
|
||||
if ((VK_SUCCESS != result) ||
|
||||
(VK_NULL_HANDLE == swapchain)) {
|
||||
std::cout << "Could not create a swapchain." << std::endl;
|
||||
zlog::error("Could not create a swapchain.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -143,7 +144,7 @@ namespace vulkanapi {
|
||||
result = vkGetSwapchainImagesKHR(logical_device, swapchain, &images_count, nullptr);
|
||||
if ((VK_SUCCESS != result) ||
|
||||
(0 == images_count)) {
|
||||
std::cout << "Could not get the number of swapchain images." << std::endl;
|
||||
zlog::error("Could not get the number of swapchain images.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -151,7 +152,7 @@ namespace vulkanapi {
|
||||
result = vkGetSwapchainImagesKHR(logical_device, swapchain, &images_count, swapchain_images.data());
|
||||
if ((VK_SUCCESS != result) ||
|
||||
(0 == images_count)) {
|
||||
std::cout << "Could not enumerate swapchain images." << std::endl;
|
||||
zlog::error("Could not enumerate swapchain images.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -4,17 +4,18 @@
|
||||
#include "engine/vulkanapi/window.h"
|
||||
#include "engine/vulkanapi/pass/gbuffer.h"
|
||||
#include "engine/vulkanapi/pass/forwardpass.h"
|
||||
using namespace std;
|
||||
#include "zlog.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
const char* name = "hello";
|
||||
cout << name << endl;
|
||||
const char* name = "zengine";
|
||||
zlog::info("hello {}", name);
|
||||
auto vulkan = vulkanapi::Backend(name);
|
||||
auto wnd = vulkanapi::Window(vulkan, 3, 640, 720, name);
|
||||
auto gbuffer = vulkanapi::GeometryBuffer(vulkan.GetDevice(), 3, 640, 720);
|
||||
auto forardpass = vulkanapi::ForwardPass(vulkan.GetDevice(), gbuffer);
|
||||
while (true) {
|
||||
this_thread::sleep_for(chrono::milliseconds(1000));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ includes("3rdparty/xmake.lua")
|
||||
|
||||
target("zengine")
|
||||
set_kind("binary")
|
||||
set_rundir(".")
|
||||
add_deps("zcoro","zlog")
|
||||
add_packages("vulkansdk","tinyobjloader","glm")
|
||||
add_includedirs("src")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user