clear engine
This commit is contained in:
parent
60042334a3
commit
9948ab2358
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,5 +4,6 @@
|
||||
.xmake/
|
||||
build/
|
||||
vsxmake*/
|
||||
engine/
|
||||
|
||||
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
class Object {
|
||||
public:
|
||||
|
||||
};
|
||||
@ -1,31 +0,0 @@
|
||||
#include "graph.h"
|
||||
namespace render {
|
||||
Graph::~Graph()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Graph::Graph(renderapi::Backend* backend, renderapi::Target* target)
|
||||
:mBackend(backend)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Graph::Recreate(bool recursive)
|
||||
{
|
||||
Destroy(recursive);
|
||||
if (!recursive) return;
|
||||
mBackend->Recreate();
|
||||
}
|
||||
|
||||
void Graph::Destroy(bool recursive)
|
||||
{
|
||||
if (!recursive) return;
|
||||
mBackend->Destroy();
|
||||
}
|
||||
|
||||
void Graph::Draw(Object* scene)
|
||||
{
|
||||
//auto worker = mBackend->Worker(0);
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
#include "engine/renderapi/render/backend.h"
|
||||
#include "engine/renderapi/render/target.h"
|
||||
#include "engine/object/object.h"
|
||||
namespace render {
|
||||
class Graph {
|
||||
protected:
|
||||
renderapi::Backend* mBackend;
|
||||
public:
|
||||
~Graph();
|
||||
Graph(renderapi::Backend* backend, renderapi::Target* target );
|
||||
virtual void Recreate(bool recursive = false);
|
||||
virtual void Destroy(bool recursive = false);
|
||||
virtual void Draw(Object* scene);
|
||||
};
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
#include "forwardpass.h"
|
||||
#include "engine/vulkanapi/renderpass/renderpass.h"
|
||||
#include "engine/vulkanapi/image/image.h"
|
||||
namespace vulkanapi {
|
||||
ForwardPass::ForwardPass(VkDevice device, GeometryBuffer& gBuffer)
|
||||
:mPass(nullptr)
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
#include "gbuffer.h"
|
||||
namespace vulkanapi {
|
||||
class RenderPass;
|
||||
class MaterialCache;
|
||||
class ForwardPass {
|
||||
protected:
|
||||
RenderPass* mPass;
|
||||
MaterialCache* mMaterials;
|
||||
public:
|
||||
ForwardPass(VkDevice device, GeometryBuffer& gBuffer);
|
||||
|
||||
void Record();
|
||||
};
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
#include "gbuffer.h"
|
||||
#include "engine/vulkanapi/image/image.h"
|
||||
namespace vulkanapi {
|
||||
GeometryBuffer::GeometryBuffer(VkDevice 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
#include <vector>
|
||||
namespace vulkanapi {
|
||||
class Image;
|
||||
struct GeometryBuffer {
|
||||
public:
|
||||
std::vector<Image*> positions;
|
||||
std::vector<Image*> normals;
|
||||
std::vector<Image*> diffuses;
|
||||
int width;
|
||||
int height;
|
||||
public:
|
||||
GeometryBuffer(VkDevice device,int frames, int width, int height);
|
||||
};
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
namespace renderapi {
|
||||
class CommandWorker {
|
||||
public:
|
||||
|
||||
};
|
||||
};
|
||||
@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
#include "engine/renderapi/command/worker.h"
|
||||
namespace renderapi {
|
||||
class Backend {
|
||||
public:
|
||||
virtual void Recreate(bool recursive = false) = 0;
|
||||
virtual void Destroy(bool recursive = false) = 0;
|
||||
virtual void Flush() = 0;
|
||||
|
||||
virtual CommandWorker* Worker(int frame) = 0;
|
||||
};
|
||||
};
|
||||
@ -1,7 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
namespace renderapi {
|
||||
class Target {
|
||||
};
|
||||
};
|
||||
@ -1,100 +0,0 @@
|
||||
#include "window.h"
|
||||
namespace renderapi {
|
||||
Window::WindowClass Window::WindowClass::wndClass;
|
||||
|
||||
Window::WindowClass::WindowClass() noexcept
|
||||
:
|
||||
hInst(GetModuleHandle(nullptr))
|
||||
{
|
||||
WNDCLASSEX wc = { 0 };
|
||||
wc.cbSize = sizeof(wc);
|
||||
wc.style = CS_OWNDC;
|
||||
wc.lpfnWndProc = HandleMsgSetup;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = GetInstance();
|
||||
wc.hCursor = nullptr;
|
||||
wc.hbrBackground = nullptr;
|
||||
wc.lpszMenuName = nullptr;
|
||||
wc.lpszClassName = GetName();
|
||||
RegisterClassEx(&wc);
|
||||
}
|
||||
Window::Window(int width, int height, const char* title)
|
||||
:mWidth(width), mHeight(height)
|
||||
{
|
||||
RECT wr{};
|
||||
wr.left = 100;
|
||||
wr.right = width + wr.left;
|
||||
wr.top = 100;
|
||||
wr.bottom = height + wr.top;
|
||||
mPtr = CreateWindow(
|
||||
WindowClass::GetName(), title,
|
||||
WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, wr.right - wr.left, wr.bottom - wr.top,
|
||||
nullptr, nullptr, WindowClass::GetInstance(), this
|
||||
);
|
||||
}
|
||||
bool Window::ProcessMessages(int& code)
|
||||
{
|
||||
MSG msg;
|
||||
// while queue has messages, remove and dispatch them (but do not block on empty queue)
|
||||
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
|
||||
{
|
||||
// check for quit because peekmessage does not signal this via return val
|
||||
if (msg.message == WM_QUIT)
|
||||
{
|
||||
// return optional wrapping int (arg to PostQuitMessage is in wparam) signals quit
|
||||
code = (int)msg.wParam;
|
||||
return true;
|
||||
}
|
||||
|
||||
// TranslateMessage will post auxilliary WM_CHAR messages from key msgs
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
LRESULT CALLBACK Window::HandleMsgSetup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept
|
||||
{
|
||||
// use create parameter passed in from CreateWindow() to store window class pointer at WinAPI side
|
||||
if (msg == WM_NCCREATE)
|
||||
{
|
||||
// extract ptr to window class from creation data
|
||||
const CREATESTRUCTW* const pCreate = reinterpret_cast<CREATESTRUCTW*>(lParam);
|
||||
Window* const pWnd = static_cast<Window*>(pCreate->lpCreateParams);
|
||||
// set WinAPI-managed user data to store ptr to window instance
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pWnd));
|
||||
// set message proc to normal (non-setup) handler now that setup is finished
|
||||
SetWindowLongPtr(hWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&Window::HandleMsgThunk));
|
||||
// forward message to window instance handler
|
||||
return pWnd->HandleMsg(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
// if we get a message before the WM_NCCREATE message, handle with default handler
|
||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK Window::HandleMsgThunk(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept
|
||||
{
|
||||
// retrieve ptr to window instance
|
||||
Window* const pWnd = reinterpret_cast<Window*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
|
||||
// forward message to window instance handler
|
||||
return pWnd->HandleMsg(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
LRESULT Window::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
// we don't want the DefProc to handle this message because
|
||||
// we want our destructor to destroy the window, so return 0 instead of break
|
||||
case WM_CLOSE:
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
// clear keystate when window loses focus to prevent input getting "stuck"
|
||||
/************** END MOUSE MESSAGES **************/
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
#include <Windows.h>
|
||||
namespace renderapi {
|
||||
class Window {
|
||||
protected:
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
HWND mPtr;
|
||||
protected:
|
||||
class WindowClass
|
||||
{
|
||||
public:
|
||||
static const char* GetName() noexcept {
|
||||
return wndClassName;
|
||||
}
|
||||
static HINSTANCE GetInstance() noexcept {
|
||||
return wndClass.hInst;
|
||||
}
|
||||
private:
|
||||
WindowClass() noexcept;
|
||||
WindowClass(const WindowClass&) = delete;
|
||||
WindowClass& operator=(const WindowClass&) = delete;
|
||||
static constexpr const char* wndClassName = "MainWnd";
|
||||
static WindowClass wndClass;
|
||||
HINSTANCE hInst;
|
||||
};
|
||||
static LRESULT CALLBACK HandleMsgSetup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept;
|
||||
static LRESULT CALLBACK HandleMsgThunk(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept;
|
||||
LRESULT HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept;
|
||||
public:
|
||||
Window(int width, int height, const char* title);
|
||||
HWND Ptr() {
|
||||
return mPtr;
|
||||
}
|
||||
static bool ProcessMessages(int& code);
|
||||
};
|
||||
};
|
||||
23
engine/src/engine/vulkanapi/cache/cache.cpp
vendored
23
engine/src/engine/vulkanapi/cache/cache.cpp
vendored
@ -1,23 +0,0 @@
|
||||
#include "cache.h"
|
||||
|
||||
namespace vulkanapi {
|
||||
CachePool::CachePool()
|
||||
{
|
||||
|
||||
}
|
||||
CacheValue* CachePool::Fetch(uint32_t id)
|
||||
{
|
||||
CacheValue* v = get(id);
|
||||
if (v != nullptr)
|
||||
return v;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
CacheValue* CachePool::get(uint32_t id)
|
||||
{
|
||||
auto res = mData.find(id);
|
||||
if(res == mData.end())
|
||||
return nullptr;
|
||||
return res->second;
|
||||
}
|
||||
}
|
||||
24
engine/src/engine/vulkanapi/cache/cache.h
vendored
24
engine/src/engine/vulkanapi/cache/cache.h
vendored
@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
namespace vulkanapi {
|
||||
class CacheValue {
|
||||
protected:
|
||||
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
class CachePool {
|
||||
protected:
|
||||
std::map<uint32_t, CacheValue*> mData;
|
||||
bool mAsync = false;
|
||||
int mMaxAge = 100;
|
||||
protected:
|
||||
CacheValue* get(uint32_t id);
|
||||
public:
|
||||
CachePool();
|
||||
CacheValue* Fetch(uint32_t id);
|
||||
};
|
||||
};
|
||||
@ -1,9 +0,0 @@
|
||||
#include "buffer.h"
|
||||
#include <iostream>
|
||||
#include <engine/vulkanapi/device/device.h>
|
||||
namespace vulkanapi {
|
||||
CommandBuffer::CommandBuffer()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
namespace vulkanapi {
|
||||
class CommandBuffer {
|
||||
protected:
|
||||
|
||||
public:
|
||||
CommandBuffer();
|
||||
};
|
||||
};
|
||||
@ -1,24 +0,0 @@
|
||||
#include "pool.h"
|
||||
#include <iostream>
|
||||
#include <engine/vulkanapi/device/device.h>
|
||||
namespace vulkanapi {
|
||||
CommandPool::CommandPool(Device* device, VkCommandPoolCreateFlags queueFlags, uint32_t queueIndex)
|
||||
{
|
||||
uint32_t idx = device->GetQueueFamilyIndex(queueFlags);
|
||||
if (queueIndex != idx) {
|
||||
std::cout << "GetQueueFamilyIndex Warning " << queueIndex << idx << std::endl;
|
||||
queueIndex = idx;
|
||||
}
|
||||
VkCommandPoolCreateInfo pCreateInfo{
|
||||
VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
||||
nullptr,
|
||||
queueFlags,
|
||||
queueIndex
|
||||
};
|
||||
mPtr = device->CreateCommandPool(&pCreateInfo, nullptr);
|
||||
}
|
||||
CommandBuffer& CommandPool::Allocate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
namespace vulkanapi {
|
||||
class Device;
|
||||
class CommandBuffer;
|
||||
class CommandPool {
|
||||
protected:
|
||||
VkCommandPool mPtr;
|
||||
public:
|
||||
CommandPool(Device *device, VkCommandPoolCreateFlags queueFlags, uint32_t queueIndex);
|
||||
|
||||
CommandBuffer& Allocate();
|
||||
};
|
||||
};
|
||||
@ -1,19 +0,0 @@
|
||||
#include "record.h"
|
||||
#include <iostream>
|
||||
#include <engine/vulkanapi/device/device.h>
|
||||
namespace vulkanapi {
|
||||
CommandRecord::CommandRecord()
|
||||
{
|
||||
mParts.reserve(64);
|
||||
}
|
||||
void CommandRecord::Apply(CommandBuffer* buf)
|
||||
{
|
||||
for (auto cmd : mParts) {
|
||||
cmd(buf);
|
||||
}
|
||||
}
|
||||
void CommandRecord::Record(CommandFn cmd)
|
||||
{
|
||||
mParts.push_back(cmd);
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
namespace vulkanapi {
|
||||
class CommandBuffer;
|
||||
typedef void (*CommandFn)(CommandBuffer* buf);
|
||||
class CommandRecord {
|
||||
protected:
|
||||
std::vector<CommandFn> mParts;
|
||||
public:
|
||||
CommandRecord();
|
||||
void Apply(CommandBuffer* buf);
|
||||
void Record(CommandFn cmd);
|
||||
};
|
||||
};
|
||||
@ -1,31 +0,0 @@
|
||||
#include "thread_worker.h"
|
||||
namespace vulkanapi {
|
||||
CommandThreadWorker::CommandThreadWorker(const char* name, int buffer)
|
||||
: mName(name)
|
||||
, mChannel(buffer)
|
||||
, mSemaphore(0)
|
||||
{
|
||||
mThread = std::thread(&CommandThreadWorker::workloop, this);
|
||||
}
|
||||
void CommandThreadWorker::workloop()
|
||||
{
|
||||
mThread.detach();
|
||||
while(true){
|
||||
voidFn fn = mChannel.acquire();
|
||||
fn();
|
||||
}
|
||||
}
|
||||
void CommandThreadWorker::Invoke(voidFn fn)
|
||||
{
|
||||
mChannel.release(fn);
|
||||
}
|
||||
|
||||
void CommandThreadWorker::SyncInvoke(voidFn fn)
|
||||
{
|
||||
Invoke([&]() {
|
||||
fn();
|
||||
mSemaphore.release();
|
||||
});
|
||||
mSemaphore.acquire();
|
||||
}
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include "pool.h"
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
#include "zthread/channel.h"
|
||||
namespace vulkanapi {
|
||||
class CommandThreadWorker {
|
||||
protected:
|
||||
std::thread mThread;
|
||||
std::string mName;
|
||||
zstd::channel<voidFn> mChannel;
|
||||
std::binary_semaphore mSemaphore;
|
||||
protected:
|
||||
void workloop();
|
||||
public:
|
||||
CommandThreadWorker(const char* name, int buffer);
|
||||
|
||||
void Invoke(voidFn fn);
|
||||
void SyncInvoke(voidFn fn);
|
||||
};
|
||||
};
|
||||
@ -1,37 +0,0 @@
|
||||
#include "worker.h"
|
||||
#include <iostream>
|
||||
#include "buffer.h"
|
||||
#include "pool.h"
|
||||
#include "thread_worker.h"
|
||||
#include <engine/vulkanapi/device/device.h>
|
||||
namespace vulkanapi {
|
||||
CommandWorker::CommandWorker(Device* device, const char* name, uint32_t queueFlags, uint32_t queueIndex)
|
||||
{
|
||||
uint32_t idx = device->GetQueueFamilyIndex(queueFlags);
|
||||
if (queueIndex != idx) {
|
||||
std::cout << "GetQueueFamilyIndex Warning " << queueIndex << idx << std::endl;
|
||||
queueIndex = idx;
|
||||
}
|
||||
char str[256];
|
||||
sprintf(str, "%s:%d:%p", name, queueIndex, mQueue);
|
||||
mName = str;
|
||||
mCommandPool = new CommandPool(device, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queueIndex);
|
||||
mQueue = device->GetQueue(queueIndex, 0);
|
||||
mWork = new CommandThreadWorker(mName.c_str(), 100);
|
||||
}
|
||||
void CommandWorker::Invoke(voidFn fn)
|
||||
{
|
||||
mWork->Invoke(fn);
|
||||
}
|
||||
void CommandWorker::Queue(commandFn fn)
|
||||
{
|
||||
mWork->Invoke([&]() {
|
||||
this->enqueue(fn);
|
||||
});
|
||||
}
|
||||
void CommandWorker::enqueue(commandFn fn)
|
||||
{
|
||||
auto buf = mCommandPool->Allocate();
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "engine/renderapi/command/worker.h"
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
namespace vulkanapi {
|
||||
class Device;
|
||||
class CommandThreadWorker;
|
||||
class CommandPool;
|
||||
class CommandWorker : public renderapi::CommandWorker {
|
||||
protected:
|
||||
CommandThreadWorker* mWork;
|
||||
CommandPool* mCommandPool;
|
||||
VkQueue mQueue;
|
||||
std::string mName;
|
||||
|
||||
protected:
|
||||
void enqueue(commandFn fn);
|
||||
public:
|
||||
CommandWorker(Device *device,const char* name, uint32_t queueFlags, uint32_t queueIndex);
|
||||
|
||||
void Invoke(voidFn fn);
|
||||
void Queue(commandFn fn);
|
||||
};
|
||||
};
|
||||
@ -1,19 +0,0 @@
|
||||
#include "pool.h"
|
||||
#include <iostream>
|
||||
#include <engine/vulkanapi/device/device.h>
|
||||
namespace vulkanapi {
|
||||
DescriptorPool::DescriptorPool(Device* device, uint32_t sets, std::vector<VkDescriptorPoolSize>& sizeList)
|
||||
:mMaxSets(sets)
|
||||
,mSizeList(sizeList)
|
||||
{
|
||||
VkDescriptorPoolCreateInfo pCreateInfo{
|
||||
VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
||||
nullptr,
|
||||
VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT,
|
||||
mMaxSets,
|
||||
(uint32_t)mSizeList.size(),
|
||||
mSizeList.data()
|
||||
};
|
||||
mPtr = device->CreateDescriptorPool(&pCreateInfo, nullptr);
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
namespace vulkanapi {
|
||||
class Device;
|
||||
class DescriptorPool {
|
||||
protected:
|
||||
VkDescriptorPool mPtr;
|
||||
std::vector<VkDescriptorPoolSize> mSizeList;
|
||||
uint32_t mMaxSets;
|
||||
public:
|
||||
DescriptorPool(Device *device, uint32_t sets, std::vector<VkDescriptorPoolSize>& sizeList);
|
||||
};
|
||||
};
|
||||
@ -1,65 +0,0 @@
|
||||
#include "device.h"
|
||||
#include "device_help.h"
|
||||
namespace vulkanapi {
|
||||
Device::Device(VkInstance instance, VkPhysicalDevice physDevice):mPhysical(physDevice)
|
||||
{
|
||||
std::vector<VkQueueFamilyProperties> queue_families;
|
||||
CheckAvailableQueueFamiliesAndTheirProperties(physDevice, queue_families);
|
||||
|
||||
std::vector<VkDeviceQueueCreateInfo> queue_create_infos;
|
||||
_QueueCreateInfos(queue_create_infos, queue_families);
|
||||
std::vector<char const*> desired_extensions = {
|
||||
"VK_KHR_swapchain",
|
||||
};
|
||||
|
||||
//调用实例接口,检查物理设备功能
|
||||
VkPhysicalDeviceFeatures device_features{};
|
||||
_EnabledFeatures(device_features);
|
||||
VkDeviceCreateInfo device_create_info = {
|
||||
VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void * pNext
|
||||
0, // VkDeviceCreateFlags flags
|
||||
static_cast<uint32_t>(queue_create_infos.size()), // uint32_t queueCreateInfoCount
|
||||
queue_create_infos.data(), // const VkDeviceQueueCreateInfo * pQueueCreateInfos
|
||||
0, // uint32_t enabledLayerCount
|
||||
nullptr, // const char * const * ppEnabledLayerNames
|
||||
static_cast<uint32_t>(desired_extensions.size()), // uint32_t enabledExtensionCount
|
||||
desired_extensions.data(), // const char * const * ppEnabledExtensionNames
|
||||
&device_features // const VkPhysicalDeviceFeatures * pEnabledFeatures
|
||||
};
|
||||
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;
|
||||
}
|
||||
}
|
||||
uint32_t Device::GetQueueFamilyIndex(VkQueueFlags flag)
|
||||
{
|
||||
std::vector<VkQueueFamilyProperties> queue_families;
|
||||
CheckAvailableQueueFamiliesAndTheirProperties(mPhysical, queue_families);
|
||||
for (uint32_t i = 0, l = queue_families.size(); i < l; i++) {
|
||||
if ((queue_families[i].queueFlags & flag) == flag) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
VkCommandPool Device::CreateCommandPool(const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
|
||||
{
|
||||
VkCommandPool pCommandPool;
|
||||
vkCreateCommandPool(mPtr, pCreateInfo, pAllocator, &pCommandPool);
|
||||
return pCommandPool;
|
||||
}
|
||||
VkQueue Device::GetQueue(uint32_t familyIndex, uint32_t queueIndex)
|
||||
{
|
||||
VkQueue pQueue;
|
||||
vkGetDeviceQueue(mPtr, familyIndex, queueIndex, &pQueue);
|
||||
return pQueue;
|
||||
}
|
||||
VkDescriptorPool Device::CreateDescriptorPool(const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator)
|
||||
{
|
||||
VkDescriptorPool pDescriptorPool;
|
||||
vkCreateDescriptorPool(mPtr, pCreateInfo, pAllocator, &pDescriptorPool);
|
||||
return pDescriptorPool;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
|
||||
namespace vulkanapi {
|
||||
class Device{
|
||||
protected:
|
||||
VkDevice mPtr;
|
||||
VkPhysicalDevice mPhysical;
|
||||
public:
|
||||
VkDevice Ptr() {
|
||||
return mPtr;
|
||||
}
|
||||
VkPhysicalDevice GetPhysical() {
|
||||
return mPhysical;
|
||||
}
|
||||
public:
|
||||
Device(VkInstance ptr, VkPhysicalDevice physDevice);
|
||||
|
||||
uint32_t GetQueueFamilyIndex(VkQueueFlags flag);
|
||||
VkCommandPool CreateCommandPool(const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator);
|
||||
VkQueue GetQueue(uint32_t familyIndex, uint32_t queueIndex);
|
||||
VkDescriptorPool CreateDescriptorPool(const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator);
|
||||
};
|
||||
};
|
||||
@ -1,50 +0,0 @@
|
||||
#pragma once
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
namespace vulkanapi {
|
||||
struct QueueInfo {
|
||||
uint32_t FamilyIndex;
|
||||
std::vector<float> Priorities;
|
||||
};
|
||||
bool CheckAvailableQueueFamiliesAndTheirProperties(VkPhysicalDevice physical_device,std::vector<VkQueueFamilyProperties>& queue_families) {
|
||||
uint32_t queue_families_count = 0;
|
||||
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &queue_families_count, nullptr);
|
||||
if (queue_families_count == 0) {
|
||||
std::cout << "Could not get the number of queue families." << std::endl;
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
void _QueueCreateInfos(std::vector<VkDeviceQueueCreateInfo>& queue_create_infos, std::vector<VkQueueFamilyProperties>& queue_families) {
|
||||
std::vector<QueueInfo> queue_infos;
|
||||
for (uint32_t i = 0, l = queue_families.size(); i < l; i++) {
|
||||
queue_infos.push_back({ i, { 1.0f } });
|
||||
}
|
||||
for (auto& info : queue_infos) {
|
||||
queue_create_infos.push_back({
|
||||
VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void * pNext
|
||||
0, // VkDeviceQueueCreateFlags flags
|
||||
info.FamilyIndex, // uint32_t queueFamilyIndex
|
||||
static_cast<uint32_t>(info.Priorities.size()), // uint32_t queueCount
|
||||
info.Priorities.data() // const float * pQueuePriorities
|
||||
});
|
||||
};
|
||||
}
|
||||
void _EnabledFeatures(VkPhysicalDeviceFeatures& device_features) {
|
||||
device_features.independentBlend = true;
|
||||
device_features.depthClamp = true;
|
||||
//device_features.protectedMemory = true;
|
||||
}
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
#include "image.h"
|
||||
namespace vulkanapi {
|
||||
Image::Image(VkDevice 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(VkDevice device, const Args& args)
|
||||
: mArgs(args)
|
||||
, mDevice(device)
|
||||
, mPtr(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
Image::Image(VkDevice device, VkImage ptr, const Args& args)
|
||||
: mArgs(args)
|
||||
, mDevice(device)
|
||||
, mPtr(ptr)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
namespace vulkanapi {
|
||||
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:
|
||||
Args mArgs;
|
||||
VkImage mPtr;
|
||||
VkDevice mDevice;
|
||||
|
||||
public:
|
||||
Image(VkDevice device, const char* name, int width, int height, VkFormat format, VkImageUsageFlags usage);
|
||||
Image(VkDevice device, const Args& args);
|
||||
Image(VkDevice device, VkImage ptr, const Args& args);
|
||||
|
||||
VkFormat Format() {
|
||||
return mArgs.Format;
|
||||
};
|
||||
};
|
||||
};
|
||||
@ -1,12 +0,0 @@
|
||||
#include "material.h"
|
||||
#include "engine/vulkanapi/descriptor/pool.h"
|
||||
namespace vulkanapi {
|
||||
Material::Material(VkDevice device, const Args& args) {
|
||||
|
||||
}
|
||||
|
||||
void Material::Instantiate(DescriptorPool* pool)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
namespace vulkanapi {
|
||||
class DescriptorPool;
|
||||
class Material {
|
||||
public:
|
||||
struct Args {
|
||||
|
||||
};
|
||||
protected:
|
||||
|
||||
public:
|
||||
Material(VkDevice device, const Args& args);
|
||||
void Instantiate(DescriptorPool* pool);
|
||||
};
|
||||
};
|
||||
@ -1,22 +0,0 @@
|
||||
#include "renderpass.h"
|
||||
namespace vulkanapi {
|
||||
RenderPass::RenderPass(VkDevice 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, &create_info, nullptr, &mPtr);
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
#include <vector>
|
||||
|
||||
namespace vulkanapi {
|
||||
class RenderPass {
|
||||
protected:
|
||||
VkRenderPass mPtr;
|
||||
public:
|
||||
RenderPass(VkDevice device, const char* name,
|
||||
std::vector<VkAttachmentDescription>& attachments,
|
||||
std::vector<VkSubpassDescription>& subpasses,
|
||||
std::vector<VkSubpassDependency>& dependencies);
|
||||
//colorAttachments, depthAttachment, subpasses, dependencies);
|
||||
};
|
||||
};
|
||||
@ -1,44 +0,0 @@
|
||||
#include "swapchain.h"
|
||||
#include "engine/vulkanapi/device/device.h"
|
||||
#include "engine/vulkanapi/image/image.h"
|
||||
#include "swapchain_help.h"
|
||||
namespace vulkanapi {
|
||||
Swapchain::Swapchain(Device* device, int frames, int width, int height, VkSurfaceKHR presentation_surface)
|
||||
: mPtr(nullptr)
|
||||
{
|
||||
uint32_t queue_family_index;
|
||||
VkPhysicalDevice physical_device = device->GetPhysical();
|
||||
|
||||
//选择交换链图像的格式与颜色空间
|
||||
VkFormat image_format;
|
||||
VkColorSpaceKHR image_color_space;
|
||||
SelectFormatOfSwapchainImages(physical_device, presentation_surface, { VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR },
|
||||
image_format, image_color_space);
|
||||
|
||||
VkSurfaceCapabilitiesKHR surface_capabilities;
|
||||
GetCapabilitiesOfPresentationSurface(physical_device, presentation_surface, surface_capabilities);
|
||||
|
||||
VkExtent2D image_size{ (uint32_t)width ,(uint32_t)height };
|
||||
ChooseSizeOfSwapchainImages(surface_capabilities, image_size);
|
||||
|
||||
//调用设备接口,创建交换链
|
||||
VkSwapchainKHR old_swapchain = VK_NULL_HANDLE;
|
||||
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
|
||||
, imageUsage, VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR,VK_PRESENT_MODE_FIFO_KHR, old_swapchain, mPtr);
|
||||
|
||||
std::vector<VkImage> 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->Ptr(), img, Image::Args{
|
||||
1,
|
||||
"",
|
||||
width, height,
|
||||
1, 1, 1,
|
||||
image_format, imageUsage,
|
||||
1, 1, 1, 1}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
|
||||
namespace vulkanapi {
|
||||
class Device;
|
||||
class Image;
|
||||
class Swapchain {
|
||||
protected:
|
||||
VkSwapchainKHR mPtr;
|
||||
std::vector<Image*> mImages;
|
||||
public:
|
||||
Swapchain(Device* device,int frames, int width, int height, VkSurfaceKHR presentation_surface);
|
||||
};
|
||||
};
|
||||
@ -1,160 +0,0 @@
|
||||
#include "engine/vulkanapi/vulkan/instance/instance.h"
|
||||
#include <iostream>
|
||||
namespace vulkanapi {
|
||||
bool GetCapabilitiesOfPresentationSurface(VkPhysicalDevice physical_device,
|
||||
VkSurfaceKHR presentation_surface,
|
||||
VkSurfaceCapabilitiesKHR& surface_capabilities) {
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool ChooseSizeOfSwapchainImages(VkSurfaceCapabilitiesKHR const& surface_capabilities,
|
||||
VkExtent2D& size_of_images) {
|
||||
if (0xFFFFFFFF == surface_capabilities.currentExtent.width) {
|
||||
if (size_of_images.width < surface_capabilities.minImageExtent.width) {
|
||||
size_of_images.width = surface_capabilities.minImageExtent.width;
|
||||
}
|
||||
else if (size_of_images.width > surface_capabilities.maxImageExtent.width) {
|
||||
size_of_images.width = surface_capabilities.maxImageExtent.width;
|
||||
}
|
||||
|
||||
if (size_of_images.height < surface_capabilities.minImageExtent.height) {
|
||||
size_of_images.height = surface_capabilities.minImageExtent.height;
|
||||
}
|
||||
else if (size_of_images.height > surface_capabilities.maxImageExtent.height) {
|
||||
size_of_images.height = surface_capabilities.maxImageExtent.height;
|
||||
}
|
||||
}
|
||||
else {
|
||||
size_of_images = surface_capabilities.currentExtent;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool SelectFormatOfSwapchainImages(VkPhysicalDevice physical_device,
|
||||
VkSurfaceKHR presentation_surface,
|
||||
VkSurfaceFormatKHR desired_surface_format,
|
||||
VkFormat& image_format,
|
||||
VkColorSpaceKHR& image_color_space) {
|
||||
// Enumerate supported formats
|
||||
uint32_t formats_count = 0;
|
||||
VkResult result = VK_SUCCESS;
|
||||
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<VkSurfaceFormatKHR> surface_formats(formats_count);
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Select surface format
|
||||
if ((1 == surface_formats.size()) &&
|
||||
(VK_FORMAT_UNDEFINED == surface_formats[0].format)) {
|
||||
image_format = desired_surface_format.format;
|
||||
image_color_space = desired_surface_format.colorSpace;
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto& surface_format : surface_formats) {
|
||||
if ((desired_surface_format.format == surface_format.format) &&
|
||||
(desired_surface_format.colorSpace == surface_format.colorSpace)) {
|
||||
image_format = desired_surface_format.format;
|
||||
image_color_space = desired_surface_format.colorSpace;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& surface_format : surface_formats) {
|
||||
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;
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
bool CreateSwapchain(VkDevice logical_device,
|
||||
VkSurfaceKHR presentation_surface,
|
||||
uint32_t image_count,
|
||||
VkSurfaceFormatKHR surface_format,
|
||||
VkExtent2D image_size,
|
||||
VkImageUsageFlags image_usage,
|
||||
VkSurfaceTransformFlagBitsKHR surface_transform,
|
||||
VkPresentModeKHR present_mode,
|
||||
VkSwapchainKHR& old_swapchain,
|
||||
VkSwapchainKHR& swapchain) {
|
||||
VkSwapchainCreateInfoKHR swapchain_create_info = {
|
||||
VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, // VkStructureType sType
|
||||
nullptr, // const void * pNext
|
||||
0, // VkSwapchainCreateFlagsKHR flags
|
||||
presentation_surface, // VkSurfaceKHR surface
|
||||
image_count, // uint32_t minImageCount
|
||||
surface_format.format, // VkFormat imageFormat
|
||||
surface_format.colorSpace, // VkColorSpaceKHR imageColorSpace
|
||||
image_size, // VkExtent2D imageExtent
|
||||
1, // uint32_t imageArrayLayers
|
||||
image_usage, // VkImageUsageFlags imageUsage
|
||||
VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode imageSharingMode
|
||||
0, // uint32_t queueFamilyIndexCount
|
||||
nullptr, // const uint32_t * pQueueFamilyIndices
|
||||
surface_transform, // VkSurfaceTransformFlagBitsKHR preTransform
|
||||
VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, // VkCompositeAlphaFlagBitsKHR compositeAlpha
|
||||
present_mode, // VkPresentModeKHR presentMode
|
||||
VK_TRUE, // VkBool32 clipped
|
||||
old_swapchain // VkSwapchainKHR oldSwapchain
|
||||
};
|
||||
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (VK_NULL_HANDLE != old_swapchain) {
|
||||
vkDestroySwapchainKHR(logical_device, old_swapchain, nullptr);
|
||||
old_swapchain = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool GetHandlesOfSwapchainImages(VkDevice logical_device,
|
||||
VkSwapchainKHR swapchain,
|
||||
std::vector<VkImage>& swapchain_images) {
|
||||
uint32_t images_count = 0;
|
||||
VkResult result = VK_SUCCESS;
|
||||
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
swapchain_images.resize(images_count);
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
#include "vulkan.h"
|
||||
|
||||
namespace vulkanapi {
|
||||
|
||||
#define EXPORTED_VULKAN_FUNCTION( name ) PFN_##name name;
|
||||
#define GLOBAL_LEVEL_VULKAN_FUNCTION( name ) PFN_##name name;
|
||||
#define INSTANCE_LEVEL_VULKAN_FUNCTION( name ) PFN_##name name;
|
||||
#define INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION( name, extension ) PFN_##name name;
|
||||
#define DEVICE_LEVEL_VULKAN_FUNCTION( name ) PFN_##name name;
|
||||
#define DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION( name, extension ) PFN_##name name;
|
||||
|
||||
#include "vulkan_function_list.inl"
|
||||
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
//#pragma once
|
||||
#include <Windows.h>
|
||||
#include <functional>
|
||||
#include <vulkan/vulkan.h>
|
||||
namespace vulkanapi {
|
||||
// Vulkan library type
|
||||
#ifdef _WIN32
|
||||
#define LIBRARY_TYPE HMODULE
|
||||
#elif defined __linux
|
||||
#define LIBRARY_TYPE void*
|
||||
#endif
|
||||
|
||||
using voidFn = std::function<void()>;
|
||||
using commandFn = std::function<void()>;
|
||||
|
||||
//Vulkan Function Addr Variable lg:PFN_##name name;
|
||||
#define EXPORTED_VULKAN_FUNCTION( name ) extern PFN_##name name;
|
||||
#define GLOBAL_LEVEL_VULKAN_FUNCTION( name ) extern PFN_##name name;
|
||||
#define INSTANCE_LEVEL_VULKAN_FUNCTION( name ) extern PFN_##name name;
|
||||
#define INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION( name, extension ) extern PFN_##name name;
|
||||
#define DEVICE_LEVEL_VULKAN_FUNCTION( name ) extern PFN_##name name;
|
||||
#define DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION( name, extension ) extern PFN_##name name;
|
||||
|
||||
#include "vulkan_function_list.inl"
|
||||
extern const char* EngineName;
|
||||
}
|
||||
@ -1,80 +0,0 @@
|
||||
#include "backend.h"
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
#include "engine/vulkanapi/device/device.h"
|
||||
#include "engine/vulkanapi/command/worker.h"
|
||||
#include "engine/vulkanapi/descriptor/pool.h"
|
||||
#include "engine/vulkanapi/vulkan/instance/instance.h"
|
||||
#include <iostream>
|
||||
namespace vulkanapi {
|
||||
|
||||
Backend::Backend(const char* appName, int deviceIndex)
|
||||
{
|
||||
mInstance = new Instance(appName);
|
||||
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;
|
||||
if (device_count == 0) {
|
||||
return;
|
||||
}
|
||||
deviceIndex = 0;
|
||||
}
|
||||
mDevice = new Device(mInstance->Ptr(), available_devices[deviceIndex]);
|
||||
|
||||
mTransfer = new CommandWorker(mDevice, "xfer", VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT, 0);
|
||||
|
||||
int workerCount = 1;
|
||||
mWorkerList.reserve(workerCount);
|
||||
for (int i = 0; i < workerCount; i++) {
|
||||
char str[10];
|
||||
sprintf(str, "frame%d", i);
|
||||
mWorkerList.push_back(new CommandWorker(mDevice, str, VK_QUEUE_GRAPHICS_BIT, 0));
|
||||
}
|
||||
std::vector<VkDescriptorPoolSize> sizeList;
|
||||
sizeList.push_back({ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,10000 });
|
||||
sizeList.push_back({ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,10000 });
|
||||
sizeList.push_back({ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,100000 });
|
||||
sizeList.push_back({ VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,1000 });
|
||||
mDescriptorPool = new DescriptorPool(mDevice, 1000 , sizeList);
|
||||
}
|
||||
Backend::~Backend()
|
||||
{
|
||||
if (mInstance) {
|
||||
delete mInstance;
|
||||
mInstance = nullptr;
|
||||
}
|
||||
if (mDevice) {
|
||||
delete mDevice;
|
||||
mDevice = nullptr;
|
||||
}
|
||||
if (mTransfer) {
|
||||
delete mTransfer;
|
||||
mTransfer = nullptr;
|
||||
}
|
||||
for (auto &worker : mWorkerList) {
|
||||
delete worker;
|
||||
}
|
||||
mWorkerList.clear();
|
||||
if (mDescriptorPool) {
|
||||
delete mDescriptorPool;
|
||||
mDescriptorPool = nullptr;
|
||||
}
|
||||
}
|
||||
void Backend::Recreate(bool recursive)
|
||||
{
|
||||
if (!recursive) return;
|
||||
}
|
||||
void Backend::Destroy(bool recursive)
|
||||
{
|
||||
if (!recursive) return;
|
||||
}
|
||||
void Backend::Flush()
|
||||
{
|
||||
|
||||
}
|
||||
renderapi::CommandWorker* Backend::Worker(int frame)
|
||||
{
|
||||
return mWorkerList[frame];
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "engine/renderapi/render/backend.h"
|
||||
namespace vulkanapi {
|
||||
class Instance;
|
||||
class Device;
|
||||
class CommandWorker;
|
||||
class DescriptorPool;
|
||||
class Backend : public renderapi::Backend{
|
||||
protected:
|
||||
Instance* mInstance;
|
||||
Device* mDevice;
|
||||
CommandWorker* mTransfer;
|
||||
std::vector<CommandWorker*> mWorkerList;
|
||||
DescriptorPool* mDescriptorPool;
|
||||
public:
|
||||
Instance* GetInstance() {
|
||||
return mInstance;
|
||||
}
|
||||
Device* GetDevice() {
|
||||
return mDevice;
|
||||
}
|
||||
public:
|
||||
Backend(const char* appName, int deviceIndex = 0);
|
||||
~Backend();
|
||||
|
||||
virtual void Recreate(bool recursive = false) override;
|
||||
virtual void Destroy(bool recursive = false) override;
|
||||
virtual void Flush() override;
|
||||
|
||||
virtual renderapi::CommandWorker* Worker(int frame) override;
|
||||
};
|
||||
};
|
||||
@ -1,80 +0,0 @@
|
||||
#include "instance.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 {
|
||||
Instance::Instance(const char* appName) {
|
||||
//加载dll
|
||||
LIBRARY_TYPE vulkan_library;
|
||||
ConnectWithVulkanLoaderLibrary(vulkan_library);
|
||||
|
||||
//加载vulkan接口
|
||||
LoadFunctionExportedFromVulkanLoaderLibrary(vulkan_library);
|
||||
|
||||
//调用vulkan接口,加载全局函数指针
|
||||
LoadGlobalLevelFunctions();
|
||||
VkApplicationInfo application_info = {
|
||||
VK_STRUCTURE_TYPE_APPLICATION_INFO, // VkStructureType sType
|
||||
nullptr, // const void * pNext
|
||||
appName, // const char * pApplicationName
|
||||
VK_MAKE_VERSION(1, 0, 0), // uint32_t applicationVersion
|
||||
EngineName, // const char * pEngineName
|
||||
VK_MAKE_VERSION(1, 0, 0), // uint32_t engineVersion
|
||||
VK_MAKE_VERSION(1, 0, 0) // uint32_t apiVersion
|
||||
};
|
||||
extensions = _EnabledExtensionNames(extensions);
|
||||
layers = _EnabledLayerNames(layers);
|
||||
VkDebugUtilsMessengerCreateInfoEXT createInfo = _DebugUtilsLayerNext();
|
||||
VkInstanceCreateInfo instance_create_info = {
|
||||
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType
|
||||
&createInfo, // const void * pNext
|
||||
0, // VkInstanceCreateFlags flags
|
||||
&application_info, // const VkApplicationInfo * pApplicationInfo
|
||||
static_cast<uint32_t>(layers.size()), // uint32_t enabledLayerCount
|
||||
layers.data(), // const char * const * ppEnabledLayerNames
|
||||
static_cast<uint32_t>(extensions.size()), // uint32_t enabledExtensionCount
|
||||
extensions.data() // const char * const * ppEnabledExtensionNames
|
||||
};
|
||||
VkResult result = vkCreateInstance(&instance_create_info, nullptr, &mPtr);
|
||||
if ((result != VK_SUCCESS) || (mPtr == VK_NULL_HANDLE)) {
|
||||
std::cout << "Could not create Instance." << std::endl;
|
||||
}
|
||||
|
||||
//调用vulkan接口,加载实例函数指针
|
||||
LoadInstanceLevelFunctions(mPtr, extensions);
|
||||
}
|
||||
bool Instance::EnumerateAvailablePhysicalDevices(std::vector<VkPhysicalDevice>& available_devices)
|
||||
{
|
||||
uint32_t devices_count = 0;
|
||||
VkResult result = VK_SUCCESS;
|
||||
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
available_devices.resize(devices_count);
|
||||
result = vkEnumeratePhysicalDevices(mPtr, &devices_count, available_devices.data());
|
||||
if ((result != VK_SUCCESS) ||
|
||||
(devices_count == 0)) {
|
||||
std::cout << "Could not enumerate physical devices." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
|
||||
namespace vulkanapi {
|
||||
class Instance{
|
||||
protected:
|
||||
VkInstance mPtr;
|
||||
public:
|
||||
Instance(const char* appName);
|
||||
|
||||
VkInstance Ptr() {
|
||||
return mPtr;
|
||||
}
|
||||
bool EnumerateAvailablePhysicalDevices(std::vector<VkPhysicalDevice>& available_devices);
|
||||
};
|
||||
};
|
||||
@ -1,190 +0,0 @@
|
||||
#pragma once
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
namespace vulkanapi {
|
||||
bool ConnectWithVulkanLoaderLibrary(LIBRARY_TYPE& vulkan_library) {
|
||||
#if defined _WIN32
|
||||
vulkan_library = LoadLibrary("vulkan-1.dll");
|
||||
#elif defined __linux
|
||||
vulkan_library = dlopen("libvulkan.so.1", RTLD_NOW);
|
||||
#endif
|
||||
|
||||
if (vulkan_library == nullptr) {
|
||||
std::cout << "Could not connect with a Vulkan Runtime library." << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool LoadFunctionExportedFromVulkanLoaderLibrary(LIBRARY_TYPE const& vulkan_library) {
|
||||
#if defined _WIN32
|
||||
#define LoadFunction GetProcAddress
|
||||
#elif defined __linux
|
||||
#define LoadFunction dlsym
|
||||
#endif
|
||||
|
||||
#define EXPORTED_VULKAN_FUNCTION( name ) \
|
||||
name = (PFN_##name)LoadFunction( vulkan_library, #name ); \
|
||||
if( name == nullptr ) { \
|
||||
std::cout << "Could not load exported Vulkan function named: " \
|
||||
#name << std::endl; \
|
||||
return false; \
|
||||
}
|
||||
#include "engine/vulkanapi/vulkan_function_list.inl"
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LoadGlobalLevelFunctions() {
|
||||
#define GLOBAL_LEVEL_VULKAN_FUNCTION( name ) \
|
||||
name = (PFN_##name)vkGetInstanceProcAddr( nullptr, #name ); \
|
||||
if( name == nullptr ) { \
|
||||
std::cout << "Could not load global level Vulkan function named: " \
|
||||
#name << std::endl; \
|
||||
return false; \
|
||||
}
|
||||
|
||||
#include "engine/vulkanapi/vulkan_function_list.inl"
|
||||
|
||||
return true;
|
||||
}
|
||||
bool LoadInstanceLevelFunctions(VkInstance instance,
|
||||
std::vector<char const*> const& enabled_extensions) {
|
||||
// Load core Vulkan API instance-level functions
|
||||
#define INSTANCE_LEVEL_VULKAN_FUNCTION( name ) \
|
||||
name = (PFN_##name)vkGetInstanceProcAddr( instance, #name ); \
|
||||
if( name == nullptr ) { \
|
||||
std::cout << "Could not load instance-level Vulkan function named: " \
|
||||
#name << std::endl; \
|
||||
return false; \
|
||||
}
|
||||
|
||||
// Load instance-level functions from enabled extensions
|
||||
#define INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION( name, extension ) \
|
||||
for( auto & enabled_extension : enabled_extensions ) { \
|
||||
if( std::string( enabled_extension ) == std::string( extension ) ) { \
|
||||
name = (PFN_##name)vkGetInstanceProcAddr( instance, #name ); \
|
||||
if( name == nullptr ) { \
|
||||
std::cout << "Could not load instance-level Vulkan function named: " \
|
||||
#name << std::endl; \
|
||||
return false; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#include "engine/vulkanapi/vulkan_function_list.inl"
|
||||
|
||||
return true;
|
||||
}
|
||||
bool IsExtensionSupported(std::vector<VkExtensionProperties> const& available_extensions,
|
||||
char const* const extension) {
|
||||
for (auto& available_extension : available_extensions) {
|
||||
if (strstr(available_extension.extensionName, extension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool IsLayerSupported(std::vector<VkLayerProperties> const& available_layers,
|
||||
char const* const layer) {
|
||||
for (auto& available_layer : available_layers) {
|
||||
if (strstr(available_layer.layerName, layer)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool CheckAvailableInstanceLayers(std::vector<VkLayerProperties>& available_layers) {
|
||||
uint32_t extensions_count = 0;
|
||||
VkResult result = VK_SUCCESS;
|
||||
|
||||
result = vkEnumerateInstanceLayerProperties(&extensions_count, nullptr);
|
||||
if ((result != VK_SUCCESS) ||
|
||||
(extensions_count == 0)) {
|
||||
std::cout << "Could not get the number of instance layers." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
available_layers.resize(extensions_count);
|
||||
result = vkEnumerateInstanceLayerProperties(&extensions_count, available_layers.data());
|
||||
if ((result != VK_SUCCESS) ||
|
||||
(extensions_count == 0)) {
|
||||
std::cout << "Could not enumerate instance layers." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool CheckAvailableInstanceExtensions(std::vector<VkExtensionProperties>& available_extensions) {
|
||||
uint32_t extensions_count = 0;
|
||||
VkResult result = VK_SUCCESS;
|
||||
|
||||
result = vkEnumerateInstanceExtensionProperties(nullptr, &extensions_count, nullptr);
|
||||
if ((result != VK_SUCCESS) ||
|
||||
(extensions_count == 0)) {
|
||||
std::cout << "Could not get the number of instance extensions." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
available_extensions.resize(extensions_count);
|
||||
result = vkEnumerateInstanceExtensionProperties(nullptr, &extensions_count, available_extensions.data());
|
||||
if ((result != VK_SUCCESS) ||
|
||||
(extensions_count == 0)) {
|
||||
std::cout << "Could not enumerate instance extensions." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
std::vector<char const*> _EnabledExtensionNames(std::vector<char const*>& extensions) {
|
||||
std::vector<VkExtensionProperties> available_extensions;
|
||||
std::vector<char const*> _extension;
|
||||
if (!CheckAvailableInstanceExtensions(available_extensions)) {
|
||||
return _extension;
|
||||
}
|
||||
for (int i = 0, l = extensions.size(); i < l; i++) {
|
||||
if (IsExtensionSupported(available_extensions, extensions[i])) {
|
||||
_extension.push_back(extensions[i]);
|
||||
}
|
||||
else {
|
||||
std::cout << "cann't support extension: " << extensions[i] << std::endl;
|
||||
}
|
||||
}
|
||||
return _extension;
|
||||
}
|
||||
std::vector<char const*> _EnabledLayerNames(std::vector<char const*>& layers) {
|
||||
std::vector<VkLayerProperties> available_layers;
|
||||
std::vector<char const*> _layers;
|
||||
if (!CheckAvailableInstanceLayers(available_layers)) {
|
||||
return _layers;
|
||||
}
|
||||
for (int i = 0, l = layers.size(); i < l; i++) {
|
||||
if (IsLayerSupported(available_layers, layers[i])) {
|
||||
_layers.push_back(layers[i]);
|
||||
}
|
||||
else {
|
||||
std::cout << "cann't support layer: " << layers[i] << std::endl;
|
||||
}
|
||||
}
|
||||
return _layers;
|
||||
}
|
||||
// debug callback
|
||||
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT,
|
||||
VkDebugUtilsMessageTypeFlagsEXT,
|
||||
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
||||
void*)
|
||||
{
|
||||
std::cerr << "validation layer: " << pCallbackData->pMessage << std::endl;
|
||||
return VK_FALSE;
|
||||
}
|
||||
VkDebugUtilsMessengerCreateInfoEXT _DebugUtilsLayerNext() {
|
||||
VkDebugUtilsMessengerCreateInfoEXT createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
|
||||
createInfo.messageSeverity =
|
||||
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
|
||||
createInfo.messageType =
|
||||
VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
|
||||
createInfo.pfnUserCallback = debugCallback;
|
||||
return createInfo;
|
||||
}
|
||||
};
|
||||
@ -1,25 +0,0 @@
|
||||
#include "window.h"
|
||||
#include "backend.h"
|
||||
#include "instance/instance.h"
|
||||
#include "engine/vulkanapi/swapchain/swapchain.h"
|
||||
#include "engine/vulkanapi/device/device.h"
|
||||
#include <vulkan/vulkan_win32.h>
|
||||
namespace vulkanapi {
|
||||
Window::Window(Backend* backend, int frames, uint32_t width, uint32_t height, const char* title)
|
||||
:renderapi::Window(width, height , title)
|
||||
, mSurfaceKHR(nullptr)
|
||||
, mSwapchain(nullptr)
|
||||
{
|
||||
VkInstance instance = backend->GetInstance()->Ptr();
|
||||
VkWin32SurfaceCreateInfoKHR surface_create_info = {
|
||||
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, // VkStructureType sType
|
||||
nullptr, // const void * pNext
|
||||
0, // VkWin32SurfaceCreateFlagsKHR flags
|
||||
WindowClass::GetInstance(), // HINSTANCE hinstance
|
||||
mPtr // HWND hwnd
|
||||
};
|
||||
vkCreateWin32SurfaceKHR(instance, &surface_create_info, nullptr, &mSurfaceKHR);
|
||||
|
||||
mSwapchain = new Swapchain(backend->GetDevice(), frames, width, height, mSurfaceKHR);
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
#include "engine/renderapi/render/window.h"
|
||||
namespace vulkanapi {
|
||||
class Backend;
|
||||
class Swapchain;
|
||||
class Window : public renderapi::Window {
|
||||
protected:
|
||||
VkSurfaceKHR mSurfaceKHR;
|
||||
Swapchain* mSwapchain;
|
||||
public:
|
||||
Window(Backend* backend,int frames, uint32_t width, uint32_t height, const char* title);
|
||||
};
|
||||
};
|
||||
@ -1,205 +0,0 @@
|
||||
|
||||
// MIT License
|
||||
//
|
||||
// Copyright( c ) 2017 Packt
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files( the "Software" ), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions :
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// Vulkan Cookbook
|
||||
// ISBN: 9781786468154
|
||||
// ?Packt Publishing Limited
|
||||
//
|
||||
// Author: Pawel Lapinski
|
||||
// LinkedIn: https://www.linkedin.com/in/pawel-lapinski-84522329
|
||||
//
|
||||
// List of Vulkan Functions
|
||||
|
||||
//
|
||||
|
||||
#ifndef EXPORTED_VULKAN_FUNCTION
|
||||
#define EXPORTED_VULKAN_FUNCTION( function )
|
||||
#endif
|
||||
|
||||
//EXPORTED_VULKAN_FUNCTION(vkGetInstanceProcAddr)
|
||||
|
||||
#undef EXPORTED_VULKAN_FUNCTION
|
||||
|
||||
//
|
||||
|
||||
#ifndef GLOBAL_LEVEL_VULKAN_FUNCTION
|
||||
#define GLOBAL_LEVEL_VULKAN_FUNCTION( function )
|
||||
#endif
|
||||
|
||||
//GLOBAL_LEVEL_VULKAN_FUNCTION(vkEnumerateInstanceExtensionProperties)
|
||||
//GLOBAL_LEVEL_VULKAN_FUNCTION(vkEnumerateInstanceLayerProperties)
|
||||
//GLOBAL_LEVEL_VULKAN_FUNCTION(vkCreateInstance)
|
||||
|
||||
#undef GLOBAL_LEVEL_VULKAN_FUNCTION
|
||||
|
||||
//
|
||||
|
||||
#ifndef INSTANCE_LEVEL_VULKAN_FUNCTION
|
||||
#define INSTANCE_LEVEL_VULKAN_FUNCTION( function )
|
||||
#endif
|
||||
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION(vkEnumeratePhysicalDevices)
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION(vkEnumerateDeviceExtensionProperties)
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION(vkGetPhysicalDeviceFeatures)
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION(vkGetPhysicalDeviceProperties)
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION(vkGetPhysicalDeviceQueueFamilyProperties)
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION(vkGetPhysicalDeviceMemoryProperties)
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION(vkGetPhysicalDeviceFormatProperties)
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION(vkCreateDevice)
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION(vkGetDeviceProcAddr)
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION(vkDestroyInstance)
|
||||
|
||||
#undef INSTANCE_LEVEL_VULKAN_FUNCTION
|
||||
|
||||
//
|
||||
|
||||
#ifndef INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION
|
||||
#define INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION( function, extension )
|
||||
#endif
|
||||
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION(vkGetPhysicalDeviceSurfaceSupportKHR, VK_KHR_SURFACE_EXTENSION_NAME)
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION(vkGetPhysicalDeviceSurfaceCapabilitiesKHR, VK_KHR_SURFACE_EXTENSION_NAME)
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION(vkGetPhysicalDeviceSurfaceFormatsKHR, VK_KHR_SURFACE_EXTENSION_NAME)
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION(vkGetPhysicalDeviceSurfacePresentModesKHR, VK_KHR_SURFACE_EXTENSION_NAME)
|
||||
//INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION(vkDestroySurfaceKHR, VK_KHR_SURFACE_EXTENSION_NAME)
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION(vkCreateWin32SurfaceKHR, VK_KHR_WIN32_SURFACE_EXTENSION_NAME)
|
||||
#elif defined VK_USE_PLATFORM_XCB_KHR
|
||||
INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION(vkCreateXcbSurfaceKHR, VK_KHR_XCB_SURFACE_EXTENSION_NAME)
|
||||
#elif defined VK_USE_PLATFORM_XLIB_KHR
|
||||
INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION(vkCreateXlibSurfaceKHR, VK_KHR_XLIB_SURFACE_EXTENSION_NAME)
|
||||
#endif
|
||||
|
||||
#undef INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION
|
||||
|
||||
//
|
||||
|
||||
#ifndef DEVICE_LEVEL_VULKAN_FUNCTION
|
||||
#define DEVICE_LEVEL_VULKAN_FUNCTION( function )
|
||||
#endif
|
||||
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkGetDeviceQueue)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDeviceWaitIdle)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyDevice)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateBuffer)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkGetBufferMemoryRequirements)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkAllocateMemory)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkBindBufferMemory)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdPipelineBarrier)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateImage)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkGetImageMemoryRequirements)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkBindImageMemory)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateImageView)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkMapMemory)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkFlushMappedMemoryRanges)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkUnmapMemory)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdCopyBuffer)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdCopyBufferToImage)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdCopyImageToBuffer)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkBeginCommandBuffer)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkEndCommandBuffer)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkQueueSubmit)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyImageView)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyImage)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyBuffer)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkFreeMemory)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateCommandPool)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkAllocateCommandBuffers)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateSemaphore)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateFence)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkWaitForFences)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkResetFences)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyFence)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroySemaphore)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkResetCommandBuffer)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkFreeCommandBuffers)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkResetCommandPool)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyCommandPool)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateBufferView)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyBufferView)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkQueueWaitIdle)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateSampler)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateDescriptorSetLayout)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateDescriptorPool)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkAllocateDescriptorSets)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkUpdateDescriptorSets)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdBindDescriptorSets)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkFreeDescriptorSets)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkResetDescriptorPool)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyDescriptorPool)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyDescriptorSetLayout)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroySampler)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateRenderPass)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateFramebuffer)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyFramebuffer)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyRenderPass)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdBeginRenderPass)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdNextSubpass)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdEndRenderPass)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreatePipelineCache)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkGetPipelineCacheData)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkMergePipelineCaches)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyPipelineCache)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateGraphicsPipelines)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateComputePipelines)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyPipeline)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyEvent)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyQueryPool)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreateShaderModule)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyShaderModule)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCreatePipelineLayout)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkDestroyPipelineLayout)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdBindPipeline)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdSetViewport)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdSetScissor)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdBindVertexBuffers)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdDraw)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdDrawIndexed)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdDispatch)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdCopyImage)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdPushConstants)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdClearColorImage)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdClearDepthStencilImage)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdBindIndexBuffer)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdSetLineWidth)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdSetDepthBias)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdSetBlendConstants)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdExecuteCommands)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION(vkCmdClearAttachments)
|
||||
|
||||
#undef DEVICE_LEVEL_VULKAN_FUNCTION
|
||||
|
||||
//
|
||||
|
||||
#ifndef DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION
|
||||
#define DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION( function, extension )
|
||||
#endif
|
||||
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION(vkCreateSwapchainKHR, VK_KHR_SWAPCHAIN_EXTENSION_NAME)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION(vkGetSwapchainImagesKHR, VK_KHR_SWAPCHAIN_EXTENSION_NAME)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION(vkAcquireNextImageKHR, VK_KHR_SWAPCHAIN_EXTENSION_NAME)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION(vkQueuePresentKHR, VK_KHR_SWAPCHAIN_EXTENSION_NAME)
|
||||
//DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION(vkDestroySwapchainKHR, VK_KHR_SWAPCHAIN_EXTENSION_NAME)
|
||||
|
||||
#undef DEVICE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION
|
||||
@ -1,17 +1,9 @@
|
||||
#include <iostream>
|
||||
#include "engine/vulkanapi/vulkan/backend.h"
|
||||
#include "engine/vulkanapi/vulkan/window.h"
|
||||
#include "engine/vulkanapi/device/device.h"
|
||||
#include "engine/render/pass/forwardpass.h"
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
const char* name = "hello";
|
||||
auto app = vulkanapi::Backend(name);
|
||||
auto wnd = vulkanapi::Window(&app, 3, 640, 720, name);
|
||||
auto gBuffer = vulkanapi::GeometryBuffer(app.GetDevice()->Ptr(), 3, 640, 720);
|
||||
auto pass = vulkanapi::ForwardPass(app.GetDevice()->Ptr(), gBuffer);
|
||||
cout << name << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -8,4 +8,4 @@ target("zengine")
|
||||
add_includedirs("src")
|
||||
add_syslinks("user32")
|
||||
add_files("src/*.cpp", "src/**.cpp")
|
||||
add_headerfiles("src/**.h", "src/**.inl")
|
||||
--add_headerfiles("src/**.h", "src/**.inl")
|
||||
Loading…
Reference in New Issue
Block a user