update zlog
This commit is contained in:
parent
bbf493f860
commit
f7a8d64272
12
engine/3rdparty/zlog/include/zlog.h
vendored
Normal file
12
engine/3rdparty/zlog/include/zlog.h
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <mutex>
|
||||||
|
namespace zlog
|
||||||
|
{
|
||||||
|
static std::mutex _mutex;
|
||||||
|
static void Message(std::string info, bool logCondition);
|
||||||
|
static void Message(std::string info);
|
||||||
|
|
||||||
|
static void Exception(std::string info, bool logCondition);
|
||||||
|
static void Exception(std::string info);
|
||||||
|
}
|
||||||
38
engine/3rdparty/zlog/src/zlog.cpp
vendored
Normal file
38
engine/3rdparty/zlog/src/zlog.cpp
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include "zlog.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
std::mutex zlog::_mutex = std::mutex();
|
||||||
|
|
||||||
|
void zlog::Message(std::string info, bool logCondition)
|
||||||
|
{
|
||||||
|
if (logCondition)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(_mutex);
|
||||||
|
std::cout << "Message: " + info << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void zlog::Message(std::string info)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(_mutex);
|
||||||
|
std::cout << "Message: " + info << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void zlog::Exception(std::string info, bool logCondition)
|
||||||
|
{
|
||||||
|
if (logCondition)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(_mutex);
|
||||||
|
std::cout << "Exception: " + info << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void zlog::Exception(std::string info)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(_mutex);
|
||||||
|
std::cout << "Exception: " + info << std::endl;
|
||||||
|
}
|
||||||
6
engine/3rdparty/zlog/xmake.lua
vendored
Normal file
6
engine/3rdparty/zlog/xmake.lua
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
set_languages("cxx20")
|
||||||
|
target("zlog")
|
||||||
|
set_kind("static")
|
||||||
|
add_includedirs("include", {public = true})
|
||||||
|
add_files("src/*.cpp")
|
||||||
|
add_headerfiles("include/*.h")
|
||||||
@ -1,6 +1,4 @@
|
|||||||
#include "backend.h"
|
#include "backend.h"
|
||||||
#include "wrapper/instance.h"
|
|
||||||
#include "wrapper/device.h"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
@ -22,11 +20,9 @@ namespace vulkanapi {
|
|||||||
{
|
{
|
||||||
if (mInstance) {
|
if (mInstance) {
|
||||||
delete mInstance;
|
delete mInstance;
|
||||||
mInstance = nullptr;
|
|
||||||
}
|
}
|
||||||
if (mDevice) {
|
if (mDevice) {
|
||||||
delete mDevice;
|
delete mDevice;
|
||||||
mDevice = nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "wrapper/instance.h"
|
||||||
|
#include "wrapper/device.h"
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
class Instance;
|
|
||||||
class Device;
|
|
||||||
class Backend{
|
class Backend{
|
||||||
protected:
|
protected:
|
||||||
Instance* mInstance;
|
Instance* mInstance;
|
||||||
Device* mDevice;
|
Device* mDevice;
|
||||||
public:
|
public:
|
||||||
Instance* GetInstance() {
|
Instance& GetInstance() {
|
||||||
return mInstance;
|
return *mInstance;
|
||||||
}
|
}
|
||||||
Device* GetDevice() {
|
Device& GetDevice() {
|
||||||
return mDevice;
|
return *mDevice;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
Backend(const char* appName, int deviceIndex = 0);
|
Backend(const char* appName, int deviceIndex = 0);
|
||||||
|
|||||||
45
engine/src/engine/vulkanapi/pass/forwardpass.cpp
Normal file
45
engine/src/engine/vulkanapi/pass/forwardpass.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#include "forwardpass.h"
|
||||||
|
#include "../wrapper/renderpass.h"
|
||||||
|
#include "../wrapper/image.h"
|
||||||
|
namespace vulkanapi {
|
||||||
|
ForwardPass::ForwardPass(Device& device, GeometryBuffer& gBuffer)
|
||||||
|
{
|
||||||
|
VkAttachmentDescription positionAttachment{};
|
||||||
|
positionAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
positionAttachment.format = gBuffer.positions[0]->Format();
|
||||||
|
positionAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
|
positionAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
|
positionAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
|
positionAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
|
positionAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
positionAttachment.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
|
|
||||||
|
VkAttachmentDescription normalAttachment{};
|
||||||
|
normalAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
normalAttachment.format = gBuffer.normals[0]->Format();
|
||||||
|
normalAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
|
normalAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
|
normalAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
|
normalAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
|
normalAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
normalAttachment.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
|
|
||||||
|
VkAttachmentReference colorAttachmentRef{};
|
||||||
|
colorAttachmentRef.attachment = 0;
|
||||||
|
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
|
|
||||||
|
VkSubpassDescription subpass{};
|
||||||
|
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||||
|
subpass.colorAttachmentCount = 1;
|
||||||
|
subpass.pColorAttachments = &colorAttachmentRef;
|
||||||
|
|
||||||
|
std::vector<VkAttachmentDescription> attachments = {positionAttachment , normalAttachment};
|
||||||
|
std::vector<VkSubpassDescription> subpasses = { subpass };
|
||||||
|
std::vector<VkSubpassDependency> dependencies;
|
||||||
|
mPass = new RenderPass(device,"forward",attachments, subpasses, dependencies);
|
||||||
|
}
|
||||||
|
void ForwardPass::Record()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
17
engine/src/engine/vulkanapi/pass/forwardpass.h
Normal file
17
engine/src/engine/vulkanapi/pass/forwardpass.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../vulkan.h"
|
||||||
|
#include "gbuffer.h"
|
||||||
|
namespace vulkanapi {
|
||||||
|
class RenderPass;
|
||||||
|
class Device;
|
||||||
|
//class MaterialCache;
|
||||||
|
class ForwardPass {
|
||||||
|
protected:
|
||||||
|
RenderPass* mPass;
|
||||||
|
//MaterialCache mMaterials;
|
||||||
|
public:
|
||||||
|
ForwardPass(Device& device, GeometryBuffer& gBuffer);
|
||||||
|
|
||||||
|
void Record();
|
||||||
|
};
|
||||||
|
}
|
||||||
31
engine/src/engine/vulkanapi/pass/gbuffer.cpp
Normal file
31
engine/src/engine/vulkanapi/pass/gbuffer.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "gbuffer.h"
|
||||||
|
#include "../wrapper/image.h"
|
||||||
|
namespace vulkanapi {
|
||||||
|
GeometryBuffer::GeometryBuffer(Device& device,int frames, int width, int height)
|
||||||
|
:width(width),
|
||||||
|
height(height)
|
||||||
|
{
|
||||||
|
VkFormat positionFmt = VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||||
|
VkFormat normalFmt = VK_FORMAT_R8G8B8A8_UNORM;
|
||||||
|
VkFormat diffuseFmt = VK_FORMAT_R8G8B8A8_UNORM;
|
||||||
|
|
||||||
|
int usage = 1;
|
||||||
|
for (int i = 0; i < frames; i++) {
|
||||||
|
positions.push_back(new Image(device, "position", width , height, diffuseFmt, usage));
|
||||||
|
normals.push_back(new Image(device, "normal", width, height, diffuseFmt, usage));
|
||||||
|
diffuses.push_back(new Image(device, "diffuse", width, height, diffuseFmt, usage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GeometryBuffer::~GeometryBuffer()
|
||||||
|
{
|
||||||
|
int frames = positions.size();
|
||||||
|
for (int i = 0; i < frames; i++) {
|
||||||
|
delete positions[i];
|
||||||
|
delete normals[i];
|
||||||
|
delete diffuses[i];
|
||||||
|
}
|
||||||
|
positions.clear();
|
||||||
|
normals.clear();
|
||||||
|
diffuses.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
18
engine/src/engine/vulkanapi/pass/gbuffer.h
Normal file
18
engine/src/engine/vulkanapi/pass/gbuffer.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../vulkan.h"
|
||||||
|
#include <vector>
|
||||||
|
namespace vulkanapi {
|
||||||
|
class Image;
|
||||||
|
class Device;
|
||||||
|
struct GeometryBuffer {
|
||||||
|
public:
|
||||||
|
std::vector<Image*> positions;
|
||||||
|
std::vector<Image*> normals;
|
||||||
|
std::vector<Image*> diffuses;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
public:
|
||||||
|
GeometryBuffer(Device& device,int frames, int width, int height);
|
||||||
|
~GeometryBuffer();
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -10,6 +10,27 @@ namespace vulkanapi {
|
|||||||
#define LIBRARY_TYPE void*
|
#define LIBRARY_TYPE void*
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define _USE_GRAPHIC_DEBUG
|
||||||
|
|
||||||
|
#define assert_return(cond, info, result)\
|
||||||
|
if (cond) {\
|
||||||
|
zlog::Exception(info);\
|
||||||
|
return result;\
|
||||||
|
}
|
||||||
|
#define assert(cond,info)\
|
||||||
|
if (cond) {\
|
||||||
|
zlog::Exception(info);\
|
||||||
|
}
|
||||||
|
#define assert_vulkan_return(VkResult, info, result) \
|
||||||
|
if (VkResult != VK_SUCCESS) { \
|
||||||
|
zlog::Exception(info);\
|
||||||
|
return result;\
|
||||||
|
}
|
||||||
|
#define assert_vulkan(VkResult, info) \
|
||||||
|
if (VkResult != VK_SUCCESS) { \
|
||||||
|
zlog::Exception(info);\
|
||||||
|
}
|
||||||
|
|
||||||
using voidFn = std::function<void()>;
|
using voidFn = std::function<void()>;
|
||||||
using commandFn = std::function<void()>;
|
using commandFn = std::function<void()>;
|
||||||
|
|
||||||
|
|||||||
@ -5,12 +5,12 @@
|
|||||||
#include "wrapper/swapchain.h"
|
#include "wrapper/swapchain.h"
|
||||||
#include <vulkan/vulkan_win32.h>
|
#include <vulkan/vulkan_win32.h>
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
Window::Window(Backend* backend, int frames, uint32_t width, uint32_t height, const char* title)
|
Window::Window(Backend& backend, int frames, uint32_t width, uint32_t height, const char* title)
|
||||||
:renderapi::Window(width, height , title)
|
:renderapi::Window(width, height , title)
|
||||||
, mSurfaceKHR(nullptr)
|
, mSurfaceKHR(nullptr)
|
||||||
, mSwapchain(nullptr)
|
, mSwapchain(nullptr)
|
||||||
{
|
{
|
||||||
VkInstance instance = backend->GetInstance()->Ptr();
|
VkInstance instance = backend.GetInstance().Ptr();
|
||||||
VkWin32SurfaceCreateInfoKHR surface_create_info = {
|
VkWin32SurfaceCreateInfoKHR surface_create_info = {
|
||||||
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, // VkStructureType sType
|
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, // VkStructureType sType
|
||||||
nullptr, // const void * pNext
|
nullptr, // const void * pNext
|
||||||
@ -20,6 +20,6 @@ namespace vulkanapi {
|
|||||||
};
|
};
|
||||||
vkCreateWin32SurfaceKHR(instance, &surface_create_info, nullptr, &mSurfaceKHR);
|
vkCreateWin32SurfaceKHR(instance, &surface_create_info, nullptr, &mSurfaceKHR);
|
||||||
|
|
||||||
mSwapchain = new Swapchain(backend->GetDevice(), frames, width, height, mSurfaceKHR);
|
mSwapchain = new Swapchain(backend.GetDevice(), frames, width, height, mSurfaceKHR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8,9 +8,9 @@ namespace vulkanapi {
|
|||||||
class Swapchain;
|
class Swapchain;
|
||||||
class Window : public renderapi::Window {
|
class Window : public renderapi::Window {
|
||||||
protected:
|
protected:
|
||||||
VkSurfaceKHR mSurfaceKHR;
|
VkSurfaceKHR mSurfaceKHR{NULL};
|
||||||
Swapchain* mSwapchain;
|
Swapchain* mSwapchain;
|
||||||
public:
|
public:
|
||||||
Window(Backend* backend,int frames, uint32_t width, uint32_t height, const char* title);
|
Window(Backend& backend,int frames, uint32_t width, uint32_t height, const char* title);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -5,8 +5,8 @@
|
|||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
class Device{
|
class Device{
|
||||||
protected:
|
protected:
|
||||||
VkDevice mPtr;
|
VkDevice mPtr{ NULL };
|
||||||
VkPhysicalDevice mPhysical;
|
VkPhysicalDevice mPhysical{NULL};
|
||||||
public:
|
public:
|
||||||
VkDevice Ptr() {
|
VkDevice Ptr() {
|
||||||
return mPtr;
|
return mPtr;
|
||||||
@ -15,6 +15,7 @@ namespace vulkanapi {
|
|||||||
return mPhysical;
|
return mPhysical;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
Device(){};
|
||||||
Device(VkInstance ptr, VkPhysicalDevice physDevice);
|
Device(VkInstance ptr, VkPhysicalDevice physDevice);
|
||||||
|
|
||||||
uint32_t GetQueueFamilyIndex(VkQueueFlags flag);
|
uint32_t GetQueueFamilyIndex(VkQueueFlags flag);
|
||||||
|
|||||||
28
engine/src/engine/vulkanapi/wrapper/image.cpp
Normal file
28
engine/src/engine/vulkanapi/wrapper/image.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "image.h"
|
||||||
|
namespace vulkanapi {
|
||||||
|
Image::Image(const Device& device, const char* name, int width, int height, VkFormat format, VkImageUsageFlags usage)
|
||||||
|
:Image(device, Args{
|
||||||
|
1,
|
||||||
|
"",
|
||||||
|
width,height,
|
||||||
|
1,1,1,
|
||||||
|
format,usage,
|
||||||
|
1,1,1,1 })
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
Image::Image(const Device& device, const Args& args)
|
||||||
|
: mArgs(args)
|
||||||
|
, mDevice(device)
|
||||||
|
, mPtr(nullptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
Image::Image(const Device& device, VkImage ptr, const Args& args)
|
||||||
|
: mArgs(args)
|
||||||
|
, mDevice(device)
|
||||||
|
, mPtr(ptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
36
engine/src/engine/vulkanapi/wrapper/image.h
Normal file
36
engine/src/engine/vulkanapi/wrapper/image.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include "../vulkan.h"
|
||||||
|
namespace vulkanapi {
|
||||||
|
class Device;
|
||||||
|
class Image {
|
||||||
|
public:
|
||||||
|
struct Args {
|
||||||
|
int Type;
|
||||||
|
const char* Key;
|
||||||
|
int Width;
|
||||||
|
int Height;
|
||||||
|
int Depth;
|
||||||
|
int Layers;
|
||||||
|
int Levels;
|
||||||
|
VkFormat Format;
|
||||||
|
VkImageUsageFlags Usage;
|
||||||
|
int Tiling;
|
||||||
|
int Sharing;
|
||||||
|
int Layout;
|
||||||
|
int Memory;
|
||||||
|
};
|
||||||
|
protected:
|
||||||
|
VkImage mPtr;
|
||||||
|
Args mArgs;
|
||||||
|
const Device& mDevice;
|
||||||
|
public:
|
||||||
|
Image(const Device& device, const char* name, int width, int height, VkFormat format, VkImageUsageFlags usage);
|
||||||
|
Image(const Device& device, const Args& args);
|
||||||
|
Image(const Device& device, VkImage ptr, const Args& args);
|
||||||
|
|
||||||
|
VkFormat Format() {
|
||||||
|
return mArgs.Format;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
0
engine/src/engine/vulkanapi/wrapper/image_help.h
Normal file
0
engine/src/engine/vulkanapi/wrapper/image_help.h
Normal file
@ -1,21 +1,30 @@
|
|||||||
#include "instance.h"
|
#include "instance.h"
|
||||||
#include "instance_help.h"
|
#include "instance_help.h"
|
||||||
|
|
||||||
const char* vulkanapi::EngineName = "Vulkan";
|
|
||||||
std::vector<char const*> extensions = {
|
|
||||||
"VK_KHR_surface",
|
|
||||||
"VK_EXT_debug_utils",
|
|
||||||
"VK_KHR_get_physical_device_properties2",
|
|
||||||
"VK_KHR_win32_surface",
|
|
||||||
"VK_EXT_debug_report",
|
|
||||||
"VK_KHR_portability_enumeration",
|
|
||||||
};
|
|
||||||
std::vector<char const*> layers = {
|
|
||||||
"VK_LAYER_KHRONOS_validation",
|
|
||||||
//"VK_LAYER_LUNARG_api_dump",
|
|
||||||
};
|
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
Instance::Instance(const char* appName) {
|
Instance::InstanceCreator::InstanceCreator()
|
||||||
|
: appName("Vulkan Application")
|
||||||
|
, appVersion(VK_MAKE_VERSION(1, 0, 0))
|
||||||
|
, engineName("No Engine")
|
||||||
|
, engineVersion(VK_MAKE_VERSION(1, 0, 0))
|
||||||
|
, apiVersion(VK_API_VERSION_1_0)
|
||||||
|
#ifdef _USE_GRAPHIC_DEBUG
|
||||||
|
, messageSeverity(VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
|
||||||
|
, messageType(VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)
|
||||||
|
, debugCallback(Instance::DebugCallback)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Instance::InstanceCreator::~InstanceCreator()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void Instance::InstanceCreator::AddExtension(std::string extensionName)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void Instance::InstanceCreator::AddLayer(std::string layerName)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Instance::Instance(InstanceCreator& Creator) {
|
||||||
//加载dll
|
//加载dll
|
||||||
LIBRARY_TYPE vulkan_library;
|
LIBRARY_TYPE vulkan_library;
|
||||||
ConnectWithVulkanLoaderLibrary(vulkan_library);
|
ConnectWithVulkanLoaderLibrary(vulkan_library);
|
||||||
@ -28,14 +37,14 @@ namespace vulkanapi {
|
|||||||
VkApplicationInfo application_info = {
|
VkApplicationInfo application_info = {
|
||||||
VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType
|
VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType
|
||||||
nullptr, // const void * pNext
|
nullptr, // const void * pNext
|
||||||
appName, // const char * pApplicationName
|
Creator.appName.c_str(), // const char * pApplicationName
|
||||||
VK_MAKE_VERSION(1, 0, 0), // uint32_t applicationVersion
|
Creator.appVersion, // uint32_t applicationVersion
|
||||||
EngineName, // const char * pEngineName
|
Creator.engineName.c_str(), // const char * pEngineName
|
||||||
VK_MAKE_VERSION(1, 0, 0), // uint32_t engineVersion
|
Creator.engineVersion, // uint32_t engineVersion
|
||||||
VK_MAKE_VERSION(1, 0, 0) // uint32_t apiVersion
|
Creator.apiVersion // uint32_t apiVersion
|
||||||
};
|
};
|
||||||
extensions = _EnabledExtensionNames(extensions);
|
auto extensions = _EnabledExtensionNames(Creator._desiredExtensions);
|
||||||
layers = _EnabledLayerNames(layers);
|
auto layers = _EnabledLayerNames(Creator._desiredLayers);
|
||||||
VkDebugUtilsMessengerCreateInfoEXT createInfo = _DebugUtilsLayerNext();
|
VkDebugUtilsMessengerCreateInfoEXT createInfo = _DebugUtilsLayerNext();
|
||||||
VkInstanceCreateInfo instance_create_info = {
|
VkInstanceCreateInfo instance_create_info = {
|
||||||
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType
|
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType
|
||||||
@ -47,10 +56,7 @@ namespace vulkanapi {
|
|||||||
static_cast<uint32_t>(extensions.size()), // uint32_t enabledExtensionCount
|
static_cast<uint32_t>(extensions.size()), // uint32_t enabledExtensionCount
|
||||||
extensions.data() // const char * const * ppEnabledExtensionNames
|
extensions.data() // const char * const * ppEnabledExtensionNames
|
||||||
};
|
};
|
||||||
VkResult result = vkCreateInstance(&instance_create_info, nullptr, &mPtr);
|
zlog::Exception("Failed to create instance.", vkCreateInstance(&instance_create_info, nullptr, &mPtr));
|
||||||
if ((result != VK_SUCCESS) || (mPtr == VK_NULL_HANDLE)) {
|
|
||||||
std::cout << "Could not create Instance." << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
//调用vulkan接口,加载实例函数指针
|
//调用vulkan接口,加载实例函数指针
|
||||||
LoadInstanceLevelFunctions(mPtr, extensions);
|
LoadInstanceLevelFunctions(mPtr, extensions);
|
||||||
|
|||||||
@ -5,10 +5,34 @@
|
|||||||
|
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
class Instance{
|
class Instance{
|
||||||
|
public:
|
||||||
|
class InstanceCreator {
|
||||||
|
friend class Instance;
|
||||||
|
public:
|
||||||
|
std::string appName;
|
||||||
|
uint32_t appVersion;
|
||||||
|
std::string engineName;
|
||||||
|
uint32_t engineVersion;
|
||||||
|
uint32_t apiVersion;
|
||||||
|
#ifdef _USE_GRAPHIC_DEBUG
|
||||||
|
VkDebugUtilsMessageSeverityFlagsEXT messageSeverity;
|
||||||
|
VkDebugUtilsMessageTypeFlagsEXT messageType;
|
||||||
|
PFN_vkDebugUtilsMessengerCallbackEXT debugCallback;
|
||||||
|
#endif
|
||||||
|
private:
|
||||||
|
std::vector<std::string> _desiredExtensions;
|
||||||
|
std::vector<std::string> _desiredLayers;
|
||||||
|
|
||||||
|
public:
|
||||||
|
InstanceCreator();
|
||||||
|
~InstanceCreator();
|
||||||
|
void AddExtension(std::string extensionName);
|
||||||
|
void AddLayer(std::string layerName);
|
||||||
|
};
|
||||||
protected:
|
protected:
|
||||||
VkInstance mPtr;
|
VkInstance mPtr;
|
||||||
public:
|
public:
|
||||||
Instance(const char* appName);
|
Instance(InstanceCreator& Creator);
|
||||||
|
|
||||||
VkInstance Ptr() {
|
VkInstance Ptr() {
|
||||||
return mPtr;
|
return mPtr;
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "zlog.h"
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
bool ConnectWithVulkanLoaderLibrary(LIBRARY_TYPE& vulkan_library) {
|
bool ConnectWithVulkanLoaderLibrary(LIBRARY_TYPE& vulkan_library) {
|
||||||
#if defined _WIN32
|
#if defined _WIN32
|
||||||
@ -10,9 +11,8 @@ namespace vulkanapi {
|
|||||||
#elif defined __linux
|
#elif defined __linux
|
||||||
vulkan_library = dlopen("libvulkan.so.1", RTLD_NOW);
|
vulkan_library = dlopen("libvulkan.so.1", RTLD_NOW);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (vulkan_library == nullptr) {
|
if (vulkan_library == nullptr) {
|
||||||
std::cout << "Could not connect with a Vulkan Runtime library." << std::endl;
|
zlog::Exception("Could not connect with a Vulkan Runtime library.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -27,8 +27,7 @@ namespace vulkanapi {
|
|||||||
#define EXPORTED_VULKAN_FUNCTION( name ) \
|
#define EXPORTED_VULKAN_FUNCTION( name ) \
|
||||||
name = (PFN_##name)LoadFunction( vulkan_library, #name ); \
|
name = (PFN_##name)LoadFunction( vulkan_library, #name ); \
|
||||||
if( name == nullptr ) { \
|
if( name == nullptr ) { \
|
||||||
std::cout << "Could not load exported Vulkan function named: " \
|
zlog::Exception( "Could not load exported Vulkan function named:"#name);\
|
||||||
#name << std::endl; \
|
|
||||||
return false; \
|
return false; \
|
||||||
}
|
}
|
||||||
#include "engine/vulkanapi/vulkan_function_list.inl"
|
#include "engine/vulkanapi/vulkan_function_list.inl"
|
||||||
@ -39,8 +38,7 @@ namespace vulkanapi {
|
|||||||
#define GLOBAL_LEVEL_VULKAN_FUNCTION( name ) \
|
#define GLOBAL_LEVEL_VULKAN_FUNCTION( name ) \
|
||||||
name = (PFN_##name)vkGetInstanceProcAddr( nullptr, #name ); \
|
name = (PFN_##name)vkGetInstanceProcAddr( nullptr, #name ); \
|
||||||
if( name == nullptr ) { \
|
if( name == nullptr ) { \
|
||||||
std::cout << "Could not load global level Vulkan function named: " \
|
zlog::Exception( "Could not load global level Vulkan function named:"#name);\
|
||||||
#name << std::endl; \
|
|
||||||
return false; \
|
return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,8 +52,7 @@ namespace vulkanapi {
|
|||||||
#define INSTANCE_LEVEL_VULKAN_FUNCTION( name ) \
|
#define INSTANCE_LEVEL_VULKAN_FUNCTION( name ) \
|
||||||
name = (PFN_##name)vkGetInstanceProcAddr( instance, #name ); \
|
name = (PFN_##name)vkGetInstanceProcAddr( instance, #name ); \
|
||||||
if( name == nullptr ) { \
|
if( name == nullptr ) { \
|
||||||
std::cout << "Could not load instance-level Vulkan function named: " \
|
zlog::Exception( "Could not load instance-level Vulkan function named:"#name);\
|
||||||
#name << std::endl; \
|
|
||||||
return false; \
|
return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,8 +62,7 @@ namespace vulkanapi {
|
|||||||
if( std::string( enabled_extension ) == std::string( extension ) ) { \
|
if( std::string( enabled_extension ) == std::string( extension ) ) { \
|
||||||
name = (PFN_##name)vkGetInstanceProcAddr( instance, #name ); \
|
name = (PFN_##name)vkGetInstanceProcAddr( instance, #name ); \
|
||||||
if( name == nullptr ) { \
|
if( name == nullptr ) { \
|
||||||
std::cout << "Could not load instance-level Vulkan function named: " \
|
zlog::Exception( "Could not load instance-level Vulkan function named:"#name);\
|
||||||
#name << std::endl; \
|
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
@ -101,7 +97,7 @@ namespace vulkanapi {
|
|||||||
result = vkEnumerateInstanceLayerProperties(&extensions_count, nullptr);
|
result = vkEnumerateInstanceLayerProperties(&extensions_count, nullptr);
|
||||||
if ((result != VK_SUCCESS) ||
|
if ((result != VK_SUCCESS) ||
|
||||||
(extensions_count == 0)) {
|
(extensions_count == 0)) {
|
||||||
std::cout << "Could not get the number of instance layers." << std::endl;
|
zlog::Exception("Could not get the number of instance layers.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +105,7 @@ namespace vulkanapi {
|
|||||||
result = vkEnumerateInstanceLayerProperties(&extensions_count, available_layers.data());
|
result = vkEnumerateInstanceLayerProperties(&extensions_count, available_layers.data());
|
||||||
if ((result != VK_SUCCESS) ||
|
if ((result != VK_SUCCESS) ||
|
||||||
(extensions_count == 0)) {
|
(extensions_count == 0)) {
|
||||||
std::cout << "Could not enumerate instance layers." << std::endl;
|
zlog::Exception("Could not enumerate instance layers.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +118,7 @@ namespace vulkanapi {
|
|||||||
result = vkEnumerateInstanceExtensionProperties(nullptr, &extensions_count, nullptr);
|
result = vkEnumerateInstanceExtensionProperties(nullptr, &extensions_count, nullptr);
|
||||||
if ((result != VK_SUCCESS) ||
|
if ((result != VK_SUCCESS) ||
|
||||||
(extensions_count == 0)) {
|
(extensions_count == 0)) {
|
||||||
std::cout << "Could not get the number of instance extensions." << std::endl;
|
zlog::Exception("Could not get the number of instance extensions.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +126,7 @@ namespace vulkanapi {
|
|||||||
result = vkEnumerateInstanceExtensionProperties(nullptr, &extensions_count, available_extensions.data());
|
result = vkEnumerateInstanceExtensionProperties(nullptr, &extensions_count, available_extensions.data());
|
||||||
if ((result != VK_SUCCESS) ||
|
if ((result != VK_SUCCESS) ||
|
||||||
(extensions_count == 0)) {
|
(extensions_count == 0)) {
|
||||||
std::cout << "Could not enumerate instance extensions." << std::endl;
|
zlog::Exception("Could not enumerate instance extensions.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,6 +143,7 @@ namespace vulkanapi {
|
|||||||
_extension.push_back(extensions[i]);
|
_extension.push_back(extensions[i]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
zlog::Exception("cann't support extension: ");
|
||||||
std::cout << "cann't support extension: " << extensions[i] << std::endl;
|
std::cout << "cann't support extension: " << extensions[i] << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,6 +160,7 @@ namespace vulkanapi {
|
|||||||
_layers.push_back(layers[i]);
|
_layers.push_back(layers[i]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
zlog::Exception("Could not load instance-level Vulkan function named:"#name); \
|
||||||
std::cout << "cann't support layer: " << layers[i] << std::endl;
|
std::cout << "cann't support layer: " << layers[i] << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
engine/src/engine/vulkanapi/wrapper/renderpass.cpp
Normal file
23
engine/src/engine/vulkanapi/wrapper/renderpass.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "renderpass.h"
|
||||||
|
#include "device.h"
|
||||||
|
namespace vulkanapi {
|
||||||
|
RenderPass::RenderPass(Device& device, const char* name,
|
||||||
|
std::vector<VkAttachmentDescription>& attachments,
|
||||||
|
std::vector<VkSubpassDescription>& subpasses,
|
||||||
|
std::vector<VkSubpassDependency>& dependencies)
|
||||||
|
{
|
||||||
|
//pAttachments
|
||||||
|
VkRenderPassCreateInfo create_info{
|
||||||
|
VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
|
||||||
|
nullptr,
|
||||||
|
0,
|
||||||
|
(uint32_t)attachments.size(),
|
||||||
|
attachments.data(),
|
||||||
|
(uint32_t)subpasses.size(),
|
||||||
|
subpasses.data(),
|
||||||
|
(uint32_t)dependencies.size(),
|
||||||
|
dependencies.data()
|
||||||
|
};
|
||||||
|
vkCreateRenderPass(device.Ptr(), &create_info, nullptr, &mPtr);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
engine/src/engine/vulkanapi/wrapper/renderpass.h
Normal file
18
engine/src/engine/vulkanapi/wrapper/renderpass.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../vulkan.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace vulkanapi {
|
||||||
|
class Device;
|
||||||
|
class RenderPass {
|
||||||
|
protected:
|
||||||
|
VkRenderPass mPtr;
|
||||||
|
public:
|
||||||
|
RenderPass(Device& device, const char* name,
|
||||||
|
std::vector<VkAttachmentDescription>& attachments,
|
||||||
|
std::vector<VkSubpassDescription>& subpasses,
|
||||||
|
std::vector<VkSubpassDependency>& dependencies);
|
||||||
|
//colorAttachments, depthAttachment, subpasses, dependencies);
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -1,12 +1,13 @@
|
|||||||
#include "swapchain.h"
|
#include "swapchain.h"
|
||||||
#include "swapchain_help.h"
|
#include "swapchain_help.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
#include "image.h"
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
Swapchain::Swapchain(Device* device, int frames, int width, int height, VkSurfaceKHR presentation_surface)
|
Swapchain::Swapchain(Device& device, int frames, int width, int height, VkSurfaceKHR presentation_surface)
|
||||||
: mPtr(nullptr)
|
: mPtr(nullptr)
|
||||||
{
|
{
|
||||||
uint32_t queue_family_index;
|
uint32_t queue_family_index;
|
||||||
VkPhysicalDevice physical_device = device->GetPhysical();
|
VkPhysicalDevice physical_device = device.GetPhysical();
|
||||||
|
|
||||||
//选择交换链图像的格式与颜色空间
|
//选择交换链图像的格式与颜色空间
|
||||||
VkFormat image_format;
|
VkFormat image_format;
|
||||||
@ -23,11 +24,21 @@ namespace vulkanapi {
|
|||||||
//调用设备接口,创建交换链
|
//调用设备接口,创建交换链
|
||||||
VkSwapchainKHR old_swapchain = VK_NULL_HANDLE;
|
VkSwapchainKHR old_swapchain = VK_NULL_HANDLE;
|
||||||
VkImageUsageFlags imageUsage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
VkImageUsageFlags imageUsage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||||
CreateSwapchain(device->Ptr(), presentation_surface, frames, { image_format, image_color_space }, image_size
|
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);
|
, 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;
|
std::vector<VkImage> swapchain_images;
|
||||||
GetHandlesOfSwapchainImages(device->Ptr(), mPtr, swapchain_images);
|
GetHandlesOfSwapchainImages(device.Ptr(), mPtr, swapchain_images);
|
||||||
|
uint32_t image_count = swapchain_images.size();
|
||||||
|
for (auto img : swapchain_images) {
|
||||||
|
mImages.push_back(new Image(device, img, Image::Args{
|
||||||
|
1,
|
||||||
|
"",
|
||||||
|
width, height,
|
||||||
|
1, 1, 1,
|
||||||
|
image_format, imageUsage,
|
||||||
|
1, 1, 1, 1}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,6 @@ namespace vulkanapi {
|
|||||||
VkSwapchainKHR mPtr;
|
VkSwapchainKHR mPtr;
|
||||||
std::vector<Image*> mImages;
|
std::vector<Image*> mImages;
|
||||||
public:
|
public:
|
||||||
Swapchain(Device* device,int frames, int width, int height, VkSurfaceKHR presentation_surface);
|
Swapchain(Device& device,int frames, int width, int height, VkSurfaceKHR presentation_surface);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -2,13 +2,17 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include "engine/vulkanapi/backend.h"
|
#include "engine/vulkanapi/backend.h"
|
||||||
#include "engine/vulkanapi/window.h"
|
#include "engine/vulkanapi/window.h"
|
||||||
|
#include "engine/vulkanapi/pass/gbuffer.h"
|
||||||
|
#include "engine/vulkanapi/pass/forwardpass.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
const char* name = "hello";
|
const char* name = "hello";
|
||||||
cout << name << endl;
|
cout << name << endl;
|
||||||
auto vulkan = vulkanapi::Backend(name);
|
auto vulkan = vulkanapi::Backend(name);
|
||||||
auto wnd = vulkanapi::Window(&vulkan, 3, 640, 720, 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) {
|
while (true) {
|
||||||
this_thread::sleep_for(chrono::milliseconds(1000));
|
this_thread::sleep_for(chrono::milliseconds(1000));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,8 @@ includes("3rdparty/xmake.lua")
|
|||||||
|
|
||||||
target("zengine")
|
target("zengine")
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
add_deps("zcoro")
|
add_deps("zcoro","zlog")
|
||||||
add_packages("vulkansdk","tinyobjloader")
|
add_packages("vulkansdk","tinyobjloader","glm")
|
||||||
add_includedirs("src")
|
add_includedirs("src")
|
||||||
add_syslinks("user32")
|
add_syslinks("user32")
|
||||||
add_files("src/*.cpp", "src/**.cpp")
|
add_files("src/*.cpp", "src/**.cpp")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user