update glsl
This commit is contained in:
parent
c39c997c8d
commit
c6e986bb69
20
engine/assets/shader/gen_glsl.bat
Normal file
20
engine/assets/shader/gen_glsl.bat
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal EnableDelayedExpansion
|
||||||
|
set /p=<nul>exec.bat
|
||||||
|
set destPath=%2cpp/
|
||||||
|
ECHO @echo on >>exec.bat
|
||||||
|
for %%i in (*.vs.glsl) do (
|
||||||
|
set "s=%%i"
|
||||||
|
echo !s:vs.glsl=vert.spv!
|
||||||
|
set /p="glslc -fshader-stage=vertex %%i -o !s:vs.glsl=vert.spv!"<nul >> exec.bat
|
||||||
|
ECHO.>> exec.bat
|
||||||
|
)
|
||||||
|
for %%i in (*.ps.glsl) do (
|
||||||
|
set "s=%%i"
|
||||||
|
echo !s:ps.glsl=frag.spv!
|
||||||
|
set /p="glslc -fshader-stage=fragment %%i -o !s:ps.glsl=frag.spv!"<nul >> exec.bat
|
||||||
|
ECHO.>> exec.bat
|
||||||
|
)
|
||||||
|
ECHO @echo off>> exec.bat
|
||||||
|
call exec.bat
|
||||||
|
del exec.bat
|
||||||
Binary file not shown.
@ -1,11 +1,8 @@
|
|||||||
#version 450
|
#version 450
|
||||||
|
#extension GL_ARB_separate_shader_objects : enable
|
||||||
|
|
||||||
layout(location = 0) in vec4 inColor;
|
layout(location = 0) out vec4 outColor;
|
||||||
|
|
||||||
layout(location = 0) out vec4 outFragColor;
|
void main() {
|
||||||
|
outColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
outFragColor = inColor;
|
|
||||||
}
|
}
|
||||||
Binary file not shown.
@ -9,14 +9,19 @@ layout (location = 3) in vec3 tangent;
|
|||||||
layout (location = 4) in vec4 weights;
|
layout (location = 4) in vec4 weights;
|
||||||
layout (location = 5) in uvec4 bones;
|
layout (location = 5) in uvec4 bones;
|
||||||
|
|
||||||
// 在这里声明输出变量
|
|
||||||
layout(location = 0) out vec4 outColor;
|
|
||||||
|
|
||||||
// 顶点位置输出变量
|
// 顶点位置输出变量
|
||||||
//out vec4 outPosition;
|
//out vec4 outPosition;
|
||||||
|
out gl_PerVertex {
|
||||||
|
vec4 gl_Position;
|
||||||
|
};
|
||||||
|
|
||||||
void main()
|
vec2 positions[3] = vec2[](
|
||||||
{
|
vec2(0.0, -0.5),
|
||||||
gl_Position = vec4(position, 1);
|
vec2(0.5, 0.5),
|
||||||
outColor = vec4(texture, 0, 1);
|
vec2(-0.5, 0.5)
|
||||||
|
);
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
|
||||||
}
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "asset_render.h"
|
#include "asset_render.h"
|
||||||
|
#include "../wrapper/vertex.h"
|
||||||
namespace engineapi {
|
namespace engineapi {
|
||||||
class Texture;
|
class Texture;
|
||||||
class Material;
|
class Material;
|
||||||
|
|||||||
0
engine/src/engine/render/wrapper/vertex.cpp
Normal file
0
engine/src/engine/render/wrapper/vertex.cpp
Normal file
8
engine/src/engine/render/wrapper/vertex.h
Normal file
8
engine/src/engine/render/wrapper/vertex.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "math/vector3.h"
|
||||||
|
|
||||||
|
namespace engineapi {
|
||||||
|
struct VertexBase{
|
||||||
|
virtual Vector3& GetPosition() = 0;
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -1,6 +1,7 @@
|
|||||||
#include "backend.h"
|
#include "backend.h"
|
||||||
#include "wrapper/queue.h"
|
#include "wrapper/queue.h"
|
||||||
#include "thread/worker.h"
|
#include "thread/worker.h"
|
||||||
|
#include "wrapper/descriptorpool.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "zlog.h"
|
#include "zlog.h"
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
@ -28,6 +29,9 @@ namespace vulkanapi {
|
|||||||
Backend::TransferWorker = GetWorker(Queue::TransferQueue);
|
Backend::TransferWorker = GetWorker(Queue::TransferQueue);
|
||||||
Backend::RenderWorker = GetWorker(Queue::RenderQueue);
|
Backend::RenderWorker = GetWorker(Queue::RenderQueue);
|
||||||
Backend::PresentWorker = GetWorker(Queue::PresentQueue);
|
Backend::PresentWorker = GetWorker(Queue::PresentQueue);
|
||||||
|
|
||||||
|
auto poolSizes = DescriptorPool::DefaultDescriptorPoolSize();
|
||||||
|
mPool = new DescriptorPool(*mDevice, poolSizes, 1000);
|
||||||
}
|
}
|
||||||
Backend::~Backend()
|
Backend::~Backend()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,10 +5,12 @@
|
|||||||
#include "wrapper/device_creator.h"
|
#include "wrapper/device_creator.h"
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
class CommandWorker;
|
class CommandWorker;
|
||||||
|
class DescriptorPool;
|
||||||
class Backend{
|
class Backend{
|
||||||
protected:
|
protected:
|
||||||
Instance* mInstance;
|
Instance* mInstance;
|
||||||
Device* mDevice;
|
Device* mDevice;
|
||||||
|
DescriptorPool* mPool;
|
||||||
map<const string*, CommandWorker*> mWorkerMap;
|
map<const string*, CommandWorker*> mWorkerMap;
|
||||||
public:
|
public:
|
||||||
Instance& GetInstance() {
|
Instance& GetInstance() {
|
||||||
@ -17,6 +19,9 @@ namespace vulkanapi {
|
|||||||
Device& GetDevice() {
|
Device& GetDevice() {
|
||||||
return *mDevice;
|
return *mDevice;
|
||||||
}
|
}
|
||||||
|
DescriptorPool& GetPool() {
|
||||||
|
return *mPool;
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
Backend(const string appName);
|
Backend(const string appName);
|
||||||
~Backend();
|
~Backend();
|
||||||
|
|||||||
@ -176,6 +176,7 @@ namespace vulkanapi
|
|||||||
{
|
{
|
||||||
string name; // For debug
|
string name; // For debug
|
||||||
VkPipeline pipeline = VK_NULL_HANDLE;
|
VkPipeline pipeline = VK_NULL_HANDLE;
|
||||||
|
VkDescriptorSet descriptorSet = VK_NULL_HANDLE;
|
||||||
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
|
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
|
||||||
VkDescriptorSetLayout descriptorSetLayout = VK_NULL_HANDLE;
|
VkDescriptorSetLayout descriptorSetLayout = VK_NULL_HANDLE;
|
||||||
VkDescriptorSetLayout sceneDescriptorSetLayout = VK_NULL_HANDLE; // For ray tracing
|
VkDescriptorSetLayout sceneDescriptorSetLayout = VK_NULL_HANDLE; // For ray tracing
|
||||||
|
|||||||
@ -9,7 +9,9 @@
|
|||||||
#include "pass/target.h"
|
#include "pass/target.h"
|
||||||
#include "wrapper/swapchain.h"
|
#include "wrapper/swapchain.h"
|
||||||
#include "render/asset/mesh.h"
|
#include "render/asset/mesh.h"
|
||||||
|
#include "wrapper/descriptorpool.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#include "zlog.h"
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
RenderVulkanAPI::RenderVulkanAPI()
|
RenderVulkanAPI::RenderVulkanAPI()
|
||||||
:backend("vulkan")
|
:backend("vulkan")
|
||||||
@ -135,8 +137,8 @@ namespace vulkanapi {
|
|||||||
vkCmdBindVertexBuffers(ptr, 0, 1, vertexBuffers, offsets);
|
vkCmdBindVertexBuffers(ptr, 0, 1, vertexBuffers, offsets);
|
||||||
vkCmdBindIndexBuffer(ptr, vulkanVAO->indexBuffer, 0, VK_INDEX_TYPE_UINT32);
|
vkCmdBindIndexBuffer(ptr, vulkanVAO->indexBuffer, 0, VK_INDEX_TYPE_UINT32);
|
||||||
vkCmdBindPipeline(ptr, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipeline);
|
vkCmdBindPipeline(ptr, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipeline);
|
||||||
//vkCmdBindDescriptorSets(ptr, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipelineLayout, 0, 1, &pipeline->descriptorSet, 0, VK_NULL_HANDLE);
|
vkCmdBindDescriptorSets(ptr, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipelineLayout, 0, 1, &pipeline->descriptorSet, 0, VK_NULL_HANDLE);
|
||||||
vkCmdDrawIndexed(ptr, vulkanVAO->indexCount, 1, 0, 0, 0);
|
vkCmdDrawIndexed(ptr, 3, 1, 0, 0, 0);
|
||||||
context.Pass->EndPass(cmd);
|
context.Pass->EndPass(cmd);
|
||||||
});
|
});
|
||||||
Backend::RenderWorker->Flush();
|
Backend::RenderWorker->Flush();
|
||||||
@ -166,6 +168,7 @@ namespace vulkanapi {
|
|||||||
bindingDescription.binding = 0;
|
bindingDescription.binding = 0;
|
||||||
bindingDescription.stride = sizeof(Vertex);
|
bindingDescription.stride = sizeof(Vertex);
|
||||||
bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||||
|
|
||||||
array<VkVertexInputAttributeDescription, 6> attributeDescriptions = { };
|
array<VkVertexInputAttributeDescription, 6> attributeDescriptions = { };
|
||||||
attributeDescriptions[0].binding = 0;
|
attributeDescriptions[0].binding = 0;
|
||||||
attributeDescriptions[0].location = 0;
|
attributeDescriptions[0].location = 0;
|
||||||
@ -296,7 +299,7 @@ namespace vulkanapi {
|
|||||||
pipelineInfo.pRasterizationState = &rasterizationInfo;
|
pipelineInfo.pRasterizationState = &rasterizationInfo;
|
||||||
pipelineInfo.pMultisampleState = &multisampleInfo;
|
pipelineInfo.pMultisampleState = &multisampleInfo;
|
||||||
pipelineInfo.pColorBlendState = &colorBlending;
|
pipelineInfo.pColorBlendState = &colorBlending;
|
||||||
pipelineInfo.pDepthStencilState = &depthStencilInfo;
|
pipelineInfo.pDepthStencilState = nullptr; &depthStencilInfo;
|
||||||
pipelineInfo.layout = pipelineLayout;
|
pipelineInfo.layout = pipelineLayout;
|
||||||
pipelineInfo.renderPass = PassList[RENDER_FORWARD_RENDERING]->Ptr();
|
pipelineInfo.renderPass = PassList[RENDER_FORWARD_RENDERING]->Ptr();
|
||||||
pipelineInfo.subpass = 0;
|
pipelineInfo.subpass = 0;
|
||||||
@ -316,6 +319,7 @@ namespace vulkanapi {
|
|||||||
vulkan_pipeline->inUse = true;
|
vulkan_pipeline->inUse = true;
|
||||||
vulkan_pipeline->pipelineLayout = pipelineLayout;
|
vulkan_pipeline->pipelineLayout = pipelineLayout;
|
||||||
vulkan_pipeline->descriptorSetLayout = descriptorSetLayout;
|
vulkan_pipeline->descriptorSetLayout = descriptorSetLayout;
|
||||||
|
vulkan_pipeline->descriptorSet = backend.GetPool().Allocate(descriptorSetLayout);
|
||||||
}
|
}
|
||||||
VulkanVAO* RenderVulkanAPI::GetNextVAO(uint32_t& index)
|
VulkanVAO* RenderVulkanAPI::GetNextVAO(uint32_t& index)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../vulkan.h"
|
#include "../vulkan.h"
|
||||||
#include "zstd/pool.h"
|
#include "zstd/pool.h"
|
||||||
#include "zlog.h"
|
|
||||||
#include "commandbuffer.h"
|
#include "commandbuffer.h"
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
class Device;
|
class Device;
|
||||||
|
|||||||
30
engine/src/engine/vulkanapi/wrapper/descriptorpool.cpp
Normal file
30
engine/src/engine/vulkanapi/wrapper/descriptorpool.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include "descriptorpool.h"
|
||||||
|
#include "device.h"
|
||||||
|
namespace vulkanapi {
|
||||||
|
DescriptorPool::DescriptorPool(Device& device, vector<VkDescriptorPoolSize>& PoolSizes, uint32_t maxSets)
|
||||||
|
: mPtr(nullptr)
|
||||||
|
, mDevice(device)
|
||||||
|
{
|
||||||
|
VkDescriptorPoolCreateInfo descriptorPoolInfo{};
|
||||||
|
descriptorPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||||
|
descriptorPoolInfo.poolSizeCount = PoolSizes.size();
|
||||||
|
descriptorPoolInfo.pPoolSizes = PoolSizes.data();
|
||||||
|
descriptorPoolInfo.maxSets = maxSets;
|
||||||
|
|
||||||
|
vkCreateDescriptorPool(mDevice.Ptr(), &descriptorPoolInfo, nullptr, &mPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
VkDescriptorSet DescriptorPool::Allocate(VkDescriptorSetLayout& descriptorSetLayout)
|
||||||
|
{
|
||||||
|
|
||||||
|
VkDescriptorSet descriptorSet;
|
||||||
|
VkDescriptorSetAllocateInfo allocInfo{};
|
||||||
|
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||||
|
allocInfo.descriptorPool = mPtr;
|
||||||
|
allocInfo.descriptorSetCount = 1;
|
||||||
|
allocInfo.pSetLayouts = &descriptorSetLayout;
|
||||||
|
vkAllocateDescriptorSets(mDevice.Ptr(), &allocInfo, &descriptorSet);
|
||||||
|
return descriptorSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
26
engine/src/engine/vulkanapi/wrapper/descriptorpool.h
Normal file
26
engine/src/engine/vulkanapi/wrapper/descriptorpool.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../vulkan.h"
|
||||||
|
#include "zstd/pool.h"
|
||||||
|
#include "commandbuffer.h"
|
||||||
|
namespace vulkanapi {
|
||||||
|
class Device;
|
||||||
|
class Queue;
|
||||||
|
class DescriptorPool {
|
||||||
|
protected:
|
||||||
|
VkDescriptorPool mPtr;
|
||||||
|
Device& mDevice;
|
||||||
|
public:
|
||||||
|
DescriptorPool(Device& device, vector<VkDescriptorPoolSize>& pPoolSizes,uint32_t maxSets);
|
||||||
|
|
||||||
|
VkDescriptorSet Allocate(VkDescriptorSetLayout& descriptorSetLayout);
|
||||||
|
public:
|
||||||
|
static vector<VkDescriptorPoolSize> DefaultDescriptorPoolSize() {
|
||||||
|
return vector<VkDescriptorPoolSize>{
|
||||||
|
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 10000},
|
||||||
|
{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 10000},
|
||||||
|
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 10000},
|
||||||
|
{VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 10000}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -4,7 +4,7 @@ includes("xmake/**xmake.lua")
|
|||||||
target("zengine")
|
target("zengine")
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
set_rundir(".")
|
set_rundir(".")
|
||||||
add_rules("volk.env")
|
add_rules("volk.env", "glsl.env")
|
||||||
add_deps("zlib","zlog")
|
add_deps("zlib","zlog")
|
||||||
add_defines("VULKAN_API")
|
add_defines("VULKAN_API")
|
||||||
add_packages("vulkansdk","tinyobjloader","assimp","nlohmann_json")
|
add_packages("vulkansdk","tinyobjloader","assimp","nlohmann_json")
|
||||||
|
|||||||
6
engine/xmake/glsl/xmake.lua
Normal file
6
engine/xmake/glsl/xmake.lua
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
rule("glsl.env")
|
||||||
|
-- before load
|
||||||
|
before_build(function (target)
|
||||||
|
os.cd("$(projectdir)/engine/assets/shader")
|
||||||
|
os.execv("gen_glsl.bat")
|
||||||
|
end )
|
||||||
Loading…
Reference in New Issue
Block a user