UPLOAD
This commit is contained in:
parent
5cd703df01
commit
3e95395cb2
24
engine/3rdparty/co_context/include/co_context/io_context.h
vendored
Normal file
24
engine/3rdparty/co_context/include/co_context/io_context.h
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* A coroutine framework aimed at high-concurrency io with reasonable latency,
|
||||||
|
* based on liburingcxx.
|
||||||
|
*
|
||||||
|
* Copyright 2022 Zifeng Deng
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
namespace co_context {
|
||||||
|
|
||||||
|
} // namespace co_context
|
||||||
8
engine/3rdparty/co_context/src/co_context/io_context.cpp
vendored
Normal file
8
engine/3rdparty/co_context/src/co_context/io_context.cpp
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
namespace co_context {
|
||||||
|
class [[nodiscard]] io_context final {
|
||||||
|
|
||||||
|
};
|
||||||
|
} // namespace co_context
|
||||||
5
engine/3rdparty/co_context/xmake.lua
vendored
Normal file
5
engine/3rdparty/co_context/xmake.lua
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
target("co_context")
|
||||||
|
set_kind("static")
|
||||||
|
add_includedirs("include")
|
||||||
|
add_files("src/**.cpp")
|
||||||
|
add_headerfiles("include/**.h")
|
||||||
@ -1,22 +1,46 @@
|
|||||||
#include "forwardpass.h"
|
#include "forwardpass.h"
|
||||||
#include "engine/vulkanapi/renderpass/renderpass.h"
|
#include "engine/vulkanapi/renderpass/renderpass.h"
|
||||||
|
#include "engine/vulkanapi/image/image.h"
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
ForwardPass::ForwardPass(VkDevice device)
|
ForwardPass::ForwardPass(VkDevice device, GeometryBuffer& gBuffer)
|
||||||
:mPass(nullptr)
|
:mPass(nullptr)
|
||||||
{
|
{
|
||||||
VkAttachmentDescription depthAttachment{};
|
VkAttachmentDescription positionAttachment{};
|
||||||
//depthAttachment.format = findDepthFormat();
|
positionAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
positionAttachment.format = gBuffer.positions[0]->Format();
|
||||||
depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
positionAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
positionAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
positionAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
depthAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
positionAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
depthAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
positionAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
depthAttachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
positionAttachment.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
|
|
||||||
std::vector<VkAttachmentDescription> attachments = { depthAttachment };
|
VkAttachmentDescription normalAttachment{};
|
||||||
std::vector<VkSubpassDescription> subpasses;
|
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;
|
std::vector<VkSubpassDependency> dependencies;
|
||||||
mPass = new RenderPass(device,"forward",attachments, subpasses, dependencies);
|
mPass = new RenderPass(device,"forward",attachments, subpasses, dependencies);
|
||||||
}
|
}
|
||||||
|
void ForwardPass::Record()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,10 +1,15 @@
|
|||||||
#include "engine/vulkanapi/vulkan.h"
|
#include "engine/vulkanapi/vulkan.h"
|
||||||
|
#include "gbuffer.h"
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
class RenderPass;
|
class RenderPass;
|
||||||
|
class MaterialCache;
|
||||||
class ForwardPass {
|
class ForwardPass {
|
||||||
protected:
|
protected:
|
||||||
RenderPass* mPass;
|
RenderPass* mPass;
|
||||||
|
MaterialCache* mMaterials;
|
||||||
public:
|
public:
|
||||||
ForwardPass(VkDevice device);
|
ForwardPass(VkDevice device, GeometryBuffer& gBuffer);
|
||||||
|
|
||||||
|
void Record();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
19
engine/src/engine/render/pass/gbuffer.cpp
Normal file
19
engine/src/engine/render/pass/gbuffer.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
engine/src/engine/render/pass/gbuffer.h
Normal file
15
engine/src/engine/render/pass/gbuffer.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#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);
|
||||||
|
};
|
||||||
|
}
|
||||||
23
engine/src/engine/vulkanapi/cache/cache.cpp
vendored
Normal file
23
engine/src/engine/vulkanapi/cache/cache.cpp
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#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
Normal file
24
engine/src/engine/vulkanapi/cache/cache.h
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#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);
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
#include "thread_worker.h"
|
||||||
|
namespace vulkanapi {
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,10 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <thread>
|
||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
#include "engine/vulkanapi/vulkan.h"
|
#include "engine/vulkanapi/vulkan.h"
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
class Device;
|
typedef void(*CommandWorker)();
|
||||||
class CommandThreadWorker {
|
class CommandThreadWorker {
|
||||||
|
protected:
|
||||||
|
CommandWorker* mWorkChanels;
|
||||||
public:
|
public:
|
||||||
|
CommandThreadWorker(const char* name, int buffer) {};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,7 +1,27 @@
|
|||||||
#include "image.h"
|
#include "image.h"
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
Image::Image(VkImage img)
|
Image::Image(VkDevice device, const char* name, int width, int height, VkFormat format, VkImageUsageFlags usage)
|
||||||
:mPtr(img)
|
: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,12 +1,36 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "engine/vulkanapi/vulkan.h"
|
#include "engine/vulkanapi/vulkan.h"
|
||||||
|
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
class Image {
|
class Image {
|
||||||
protected:
|
|
||||||
VkImage mPtr;
|
|
||||||
public:
|
public:
|
||||||
Image(VkImage img);
|
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;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
12
engine/src/engine/vulkanapi/material/material.cpp
Normal file
12
engine/src/engine/vulkanapi/material/material.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "material.h"
|
||||||
|
#include "engine/vulkanapi/descriptor/pool.h"
|
||||||
|
namespace vulkanapi {
|
||||||
|
Material::Material(VkDevice device, const Args& args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Material::Instantiate(DescriptorPool* pool)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
17
engine/src/engine/vulkanapi/material/material.h
Normal file
17
engine/src/engine/vulkanapi/material/material.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#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);
|
||||||
|
};
|
||||||
|
};
|
||||||
0
engine/src/engine/vulkanapi/pipeline/layout.cpp
Normal file
0
engine/src/engine/vulkanapi/pipeline/layout.cpp
Normal file
0
engine/src/engine/vulkanapi/pipeline/layout.h
Normal file
0
engine/src/engine/vulkanapi/pipeline/layout.h
Normal file
@ -10,11 +10,11 @@ namespace vulkanapi {
|
|||||||
VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
|
VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
|
||||||
nullptr,
|
nullptr,
|
||||||
0,
|
0,
|
||||||
attachments.size(),
|
(uint32_t)attachments.size(),
|
||||||
attachments.data(),
|
attachments.data(),
|
||||||
subpasses.size(),
|
(uint32_t)subpasses.size(),
|
||||||
subpasses.data(),
|
subpasses.data(),
|
||||||
dependencies.size(),
|
(uint32_t)dependencies.size(),
|
||||||
dependencies.data()
|
dependencies.data()
|
||||||
};
|
};
|
||||||
vkCreateRenderPass(device, &create_info, nullptr, &mPtr);
|
vkCreateRenderPass(device, &create_info, nullptr, &mPtr);
|
||||||
|
|||||||
@ -23,16 +23,22 @@ 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;
|
||||||
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
|
||||||
, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR,
|
, imageUsage, VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR,VK_PRESENT_MODE_FIFO_KHR, old_swapchain, mPtr);
|
||||||
VK_PRESENT_MODE_FIFO_KHR, old_swapchain, mPtr);
|
|
||||||
|
|
||||||
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();
|
uint32_t image_count = swapchain_images.size();
|
||||||
for (auto img : swapchain_images) {
|
for (auto img : swapchain_images) {
|
||||||
mImages.push_back(new Image(img));
|
mImages.push_back(new Image(device->Ptr(), img, Image::Args{
|
||||||
|
1,
|
||||||
|
"",
|
||||||
|
width, height,
|
||||||
|
1, 1, 1,
|
||||||
|
image_format, imageUsage,
|
||||||
|
1, 1, 1, 1}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "engine/vulkanapi/vulkan/backend.h"
|
#include "engine/vulkanapi/vulkan/backend.h"
|
||||||
#include "engine/vulkanapi/vulkan/window.h"
|
#include "engine/vulkanapi/vulkan/window.h"
|
||||||
#include "engine/vulkanapi/renderpass/renderpass.h"
|
#include "engine/vulkanapi/device/device.h"
|
||||||
|
#include "engine/render/pass/forwardpass.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
@ -9,7 +10,8 @@ int main(int argc, char** argv)
|
|||||||
const char* name = "hello";
|
const char* name = "hello";
|
||||||
auto app = vulkanapi::Backend(name);
|
auto app = vulkanapi::Backend(name);
|
||||||
auto wnd = vulkanapi::Window(&app, 3, 640, 720, name);
|
auto wnd = vulkanapi::Window(&app, 3, 640, 720, name);
|
||||||
//auto pass = vulkanapi::RenderPass();
|
auto gBuffer = vulkanapi::GeometryBuffer(app.GetDevice()->Ptr(), 3, 640, 720);
|
||||||
|
auto pass = vulkanapi::ForwardPass(app.GetDevice()->Ptr(), gBuffer);
|
||||||
cout << name << endl;
|
cout << name << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ includes("test/**xmake.lua")
|
|||||||
|
|
||||||
target("zengine")
|
target("zengine")
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
add_packages("vulkansdk","glfw","glm","tinyobjloader")
|
add_deps("co_context")
|
||||||
add_includedirs("src")
|
add_includedirs("src")
|
||||||
add_files("src/*.cpp", "src/**.cpp")
|
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