Reworking VertexData
This commit is contained in:
@@ -10,8 +10,6 @@ target_sources(Engine
|
||||
Graphics.cpp
|
||||
Mesh.h
|
||||
Mesh.cpp
|
||||
MeshBatch.h
|
||||
MeshBatch.cpp
|
||||
ShaderCompiler.h
|
||||
ShaderCompiler.cpp
|
||||
StaticMeshVertexData.h
|
||||
@@ -28,7 +26,6 @@ target_sources(Engine
|
||||
GraphicsEnums.h
|
||||
Graphics.h
|
||||
Mesh.h
|
||||
MeshBatch.h
|
||||
ShaderCompiler.h
|
||||
StaticMeshVertexData.h
|
||||
VertexData.h)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "MinimalEngine.h"
|
||||
#include "GraphicsResources.h"
|
||||
#include "Containers/Array.h"
|
||||
#include "VertexShaderInput.h"
|
||||
#include "ShaderCompiler.h"
|
||||
|
||||
namespace Seele
|
||||
|
||||
@@ -165,24 +165,10 @@ namespace Gfx
|
||||
{
|
||||
static constexpr bool useAsyncCompute = true;
|
||||
static constexpr bool waitIdleOnSubmit = true;
|
||||
static constexpr bool useMeshShading = true;
|
||||
static constexpr uint32 numFramesBuffered = 8;
|
||||
double getCurrentFrameDelta();
|
||||
|
||||
enum class MaterialShadingModel
|
||||
{
|
||||
Unlit,
|
||||
DefaultLit,
|
||||
Subsurface,
|
||||
PreintegratedSkin,
|
||||
ClearCoat,
|
||||
SubsurfaceProfile,
|
||||
TwoSidedFoliage,
|
||||
Hair,
|
||||
Cloth,
|
||||
Eye,
|
||||
Max
|
||||
};
|
||||
|
||||
enum class RenderPassType : uint8
|
||||
{
|
||||
DepthPrepass,
|
||||
@@ -196,14 +182,6 @@ enum class QueueType
|
||||
TRANSFER = 3,
|
||||
DEDICATED_TRANSFER = 4
|
||||
};
|
||||
enum class VertexAttribute
|
||||
{
|
||||
POSITION,
|
||||
TEXCOORD,
|
||||
NORMAL,
|
||||
TANGENT,
|
||||
BITANGENT
|
||||
};
|
||||
|
||||
typedef uint32_t SeFlags;
|
||||
typedef uint32_t SeBool32;
|
||||
|
||||
@@ -644,8 +644,8 @@ public:
|
||||
virtual void bindVertexBuffer(const Array<VertexInputStream>& streams) = 0;
|
||||
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) = 0;
|
||||
virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) = 0;
|
||||
virtual void draw(const MeshBatchElement& data) = 0;
|
||||
virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) = 0;
|
||||
virtual void dispatch(uint32 groupX, uint32 groupY, uint32 groupZ);
|
||||
std::string name;
|
||||
};
|
||||
DEFINE_REF(RenderCommand)
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include "TopologyData.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class IndexBufferTopologyData : public TopologyData
|
||||
{
|
||||
public:
|
||||
IndexBufferTopologyData();
|
||||
virtual ~IndexBufferTopologyData();
|
||||
private:
|
||||
Gfx::PIndexBuffer indices;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -1,20 +1,19 @@
|
||||
#pragma once
|
||||
#include "GraphicsResources.h"
|
||||
#include "Asset/MaterialAsset.h"
|
||||
#include "Asset/MaterialInstanceAsset.h"
|
||||
#include "VertexData.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(TopologyData)
|
||||
DECLARE_REF(VertexData)
|
||||
class Mesh
|
||||
{
|
||||
public:
|
||||
Mesh();
|
||||
~Mesh();
|
||||
|
||||
PTopologyData meshlets;
|
||||
PVertexData vertexData;
|
||||
PMaterialAsset referencedMaterial;
|
||||
VertexData* vertexData;
|
||||
MeshId id;
|
||||
PMaterialInstanceAsset referencedMaterial;
|
||||
private:
|
||||
};
|
||||
DEFINE_REF(Mesh)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#include "MeshBatch.h"
|
||||
#include "GraphicsResources.h"
|
||||
#include "VertexShaderInput.h"
|
||||
#include "Material/MaterialInterface.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
MeshBatchElement::MeshBatchElement()
|
||||
: indexBuffer(nullptr)
|
||||
, firstIndex(0)
|
||||
, numPrimitives(0)
|
||||
, numInstances(1)
|
||||
, baseVertexIndex(0)
|
||||
, minVertexIndex(0)
|
||||
, maxVertexIndex(0)
|
||||
, indirectArgsBuffer(nullptr)
|
||||
{}
|
||||
MeshBatch::MeshBatch()
|
||||
: elements()
|
||||
, useReverseCulling(false)
|
||||
, isBackfaceCullingDisabled(false)
|
||||
, isCastingShadow(true)
|
||||
, useWireframe(false)
|
||||
, topology(Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
|
||||
, vertexInput(nullptr)
|
||||
, material(nullptr)
|
||||
{
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
#pragma once
|
||||
#include "GraphicsEnums.h"
|
||||
#include "Containers/Array.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(VertexShaderInput)
|
||||
DECLARE_REF(MaterialInterface)
|
||||
DECLARE_NAME_REF(Gfx, VertexBuffer)
|
||||
DECLARE_NAME_REF(Gfx, IndexBuffer)
|
||||
DECLARE_NAME_REF(Gfx, UniformBuffer)
|
||||
struct MeshBatchElement
|
||||
{
|
||||
public:
|
||||
Gfx::PIndexBuffer indexBuffer;
|
||||
|
||||
uint32 sceneDataIndex;
|
||||
uint32 firstIndex;
|
||||
uint32 numPrimitives;
|
||||
|
||||
uint32 numInstances;
|
||||
uint32 baseVertexIndex;
|
||||
uint32 minVertexIndex;
|
||||
uint32 maxVertexIndex;
|
||||
|
||||
uint8 isInstanced : 1;
|
||||
Gfx::PVertexBuffer indirectArgsBuffer;
|
||||
MeshBatchElement();
|
||||
};
|
||||
struct MeshBatch
|
||||
{
|
||||
Array<MeshBatchElement> elements;
|
||||
|
||||
uint8 useReverseCulling : 1;
|
||||
uint8 isBackfaceCullingDisabled : 1;
|
||||
uint8 isCastingShadow : 1;
|
||||
uint8 useWireframe : 1;
|
||||
|
||||
Gfx::SePrimitiveTopology topology;
|
||||
|
||||
PVertexShaderInput vertexInput;
|
||||
|
||||
PMaterialInterface material;
|
||||
|
||||
MeshBatch();
|
||||
MeshBatch(const MeshBatch& other) = default;
|
||||
MeshBatch(MeshBatch&& other) = default;
|
||||
MeshBatch& operator=(const MeshBatch& other) = default;
|
||||
MeshBatch& operator=(MeshBatch&& other) = default;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -1 +0,0 @@
|
||||
#include "MeshletTopologyData.h"
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
#include "TopologyData.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class MeshletTopologyData : public TopologyData
|
||||
{
|
||||
public:
|
||||
private:
|
||||
};
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Window/Window.h"
|
||||
#include "Component/Camera.h"
|
||||
#include "Component/Mesh.h"
|
||||
#include "Actor/CameraActor.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "RenderGraph.h"
|
||||
@@ -9,69 +10,8 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
BasePassMeshProcessor::BasePassMeshProcessor(Gfx::PGraphics graphics)
|
||||
: MeshProcessor(graphics)
|
||||
// , translucentBasePass(translucentBasePass)
|
||||
//, cachedPrimitiveIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
BasePassMeshProcessor::~BasePassMeshProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
void BasePassMeshProcessor::processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout baseLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 /*staticMeshId*/)
|
||||
{
|
||||
PMaterialInterface material = batch.material;
|
||||
//const Gfx::MaterialShadingModel shadingModel = material->getShadingModel();
|
||||
|
||||
const PVertexShaderInput vertexInput = batch.vertexInput;
|
||||
|
||||
const Gfx::ShaderCollection* collection = material->getShaders(Gfx::RenderPassType::BasePass, vertexInput->getType());
|
||||
if(collection == nullptr)
|
||||
{
|
||||
material->createShaders(graphics, Gfx::RenderPassType::BasePass, vertexInput->getType());
|
||||
collection = material->getShaders(Gfx::RenderPassType::BasePass, vertexInput->getType());
|
||||
}
|
||||
assert(collection != nullptr);
|
||||
|
||||
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand();
|
||||
renderCommand->setViewport(target);
|
||||
|
||||
Gfx::PPipelineLayout pipelineLayout = graphics->createPipelineLayout(baseLayout);
|
||||
pipelineLayout->addDescriptorLayout(BasePass::INDEX_MATERIAL, material->getDescriptorLayout());
|
||||
pipelineLayout->create();
|
||||
Gfx::PDescriptorSet materialSet = material->createDescriptorSet();
|
||||
descriptorSets[BasePass::INDEX_MATERIAL] = materialSet;
|
||||
for(uint32 i = 0; i < batch.elements.size(); ++i)
|
||||
{
|
||||
buildMeshDrawCommand(batch,
|
||||
renderPass,
|
||||
pipelineLayout,
|
||||
renderCommand,
|
||||
descriptorSets,
|
||||
collection->vertexShader,
|
||||
collection->controlShader,
|
||||
collection->evalutionShader,
|
||||
collection->geometryShader,
|
||||
collection->fragmentShader,
|
||||
false);
|
||||
}
|
||||
std::scoped_lock lock(commandLock);
|
||||
renderCommands.add(renderCommand);
|
||||
//co_return;
|
||||
}
|
||||
|
||||
BasePass::BasePass(Gfx::PGraphics graphics)
|
||||
: RenderPass(graphics)
|
||||
, processor(new BasePassMeshProcessor(graphics))
|
||||
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
|
||||
: RenderPass(graphics, scene)
|
||||
, descriptorSets(4)
|
||||
{
|
||||
UniformBufferCreateInfo uniformInitializer;
|
||||
@@ -80,11 +20,11 @@ BasePass::BasePass(Gfx::PGraphics graphics)
|
||||
lightLayout = graphics->createDescriptorLayout("LightLayout");
|
||||
|
||||
// Directional Lights
|
||||
lightLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
lightLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
// Point Lights
|
||||
lightLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
lightLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
// Point Lights
|
||||
lightLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
lightLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
lightLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
// Light Index List
|
||||
lightLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
// Light Grid
|
||||
@@ -103,25 +43,32 @@ BasePass::BasePass(Gfx::PGraphics graphics)
|
||||
basePassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewLayout);
|
||||
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
|
||||
|
||||
primitiveLayout = graphics->createDescriptorLayout("PrimitiveLayout");
|
||||
primitiveLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
primitiveLayout->create();
|
||||
basePassLayout->addDescriptorLayout(INDEX_SCENE_DATA, primitiveLayout);
|
||||
basePassLayout->addPushConstants(Gfx::SePushConstantRange{
|
||||
.stageFlags = (Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT),
|
||||
.offset = 0,
|
||||
.size = sizeof(uint32),
|
||||
});
|
||||
sceneLayout = graphics->createDescriptorLayout("SceneLayout");
|
||||
sceneLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
sceneLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
sceneLayout->create();
|
||||
basePassLayout->addDescriptorLayout(INDEX_SCENE_DATA, sceneLayout);
|
||||
//basePassLayout->addPushConstants(Gfx::SePushConstantRange{
|
||||
// .stageFlags = (Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT),
|
||||
// .offset = 0,
|
||||
// .size = sizeof(uint32),
|
||||
//});
|
||||
}
|
||||
|
||||
BasePass::~BasePass()
|
||||
{
|
||||
{
|
||||
}
|
||||
|
||||
void BasePass::readScene()
|
||||
{
|
||||
Array<InstanceData> instances;
|
||||
scene->view<Component::Transform, Component::Mesh>([]
|
||||
(const Component::Transform& transform, const Component::Mesh& mesh) {
|
||||
});
|
||||
}
|
||||
|
||||
void BasePass::beginFrame(const Component::Camera& cam)
|
||||
{
|
||||
processor->clearCommands();
|
||||
primitiveLayout->reset();
|
||||
BulkResourceData uniformUpdate;
|
||||
|
||||
viewParams.viewMatrix = cam.getViewMatrix();
|
||||
@@ -134,7 +81,7 @@ void BasePass::beginFrame(const Component::Camera& cam)
|
||||
viewLayout->reset();
|
||||
lightLayout->reset();
|
||||
|
||||
descriptorSets[INDEX_SCENE_DATA] = primitiveLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_SCENE_DATA] = sceneLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_SCENE_DATA]->updateBuffer(0, passData.sceneDataBuffer);
|
||||
descriptorSets[INDEX_SCENE_DATA]->writeChanges();
|
||||
descriptorSets[INDEX_LIGHT_ENV] = lightLayout->allocateDescriptorSet();
|
||||
|
||||
@@ -1,44 +1,16 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "MeshProcessor.h"
|
||||
#include "RenderPass.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class BasePassMeshProcessor : public MeshProcessor
|
||||
{
|
||||
public:
|
||||
BasePassMeshProcessor(Gfx::PGraphics graphics);
|
||||
virtual ~BasePassMeshProcessor();
|
||||
|
||||
virtual void processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 staticMeshId = -1) override;
|
||||
private:
|
||||
//Array<Gfx::PDescriptorSet> cachedPrimitiveSets;
|
||||
//uint8 translucentBasePass;
|
||||
//uint32 cachedPrimitiveIndex;
|
||||
};
|
||||
DEFINE_REF(BasePassMeshProcessor)
|
||||
DECLARE_REF(CameraActor)
|
||||
struct BasePassData
|
||||
{
|
||||
Array<MeshBatch> staticDrawList;
|
||||
Gfx::PShaderBuffer sceneDataBuffer;
|
||||
LightEnv lightEnv;
|
||||
};
|
||||
class BasePass : public RenderPass<BasePassData>
|
||||
class BasePass : public RenderPass
|
||||
{
|
||||
public:
|
||||
BasePass(Gfx::PGraphics graphics);
|
||||
BasePass(BasePass&& other) = default;
|
||||
BasePass(Gfx::PGraphics graphics, PScene scene);
|
||||
virtual ~BasePass();
|
||||
BasePass& operator=(BasePass&& other) = default;
|
||||
virtual void readScene() override;
|
||||
virtual void beginFrame(const Component::Camera& cam) override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
@@ -48,7 +20,6 @@ public:
|
||||
private:
|
||||
Gfx::PRenderTargetAttachment colorAttachment;
|
||||
Gfx::PTexture2D depthBuffer;
|
||||
UPBasePassMeshProcessor processor;
|
||||
|
||||
Array<Gfx::PDescriptorSet> descriptorSets;
|
||||
PCameraActor source;
|
||||
@@ -66,9 +37,7 @@ private:
|
||||
static constexpr uint32 INDEX_MATERIAL = 2;
|
||||
// Set 3: primitive scene data
|
||||
static constexpr uint32 INDEX_SCENE_DATA = 3;
|
||||
Gfx::PDescriptorLayout primitiveLayout;
|
||||
Gfx::PUniformBuffer primitiveUniformBuffer;
|
||||
friend class BasePassMeshProcessor;
|
||||
Gfx::PDescriptorLayout sceneLayout;
|
||||
};
|
||||
DEFINE_REF(BasePass)
|
||||
} // namespace Seele
|
||||
|
||||
@@ -8,8 +8,6 @@ target_sources(Engine
|
||||
DepthPrepass.cpp
|
||||
LightCullingPass.h
|
||||
LightCullingPass.cpp
|
||||
MeshProcessor.h
|
||||
MeshProcessor.cpp
|
||||
RenderGraph.h
|
||||
RenderGraphResources.h
|
||||
RenderGraphResources.cpp
|
||||
@@ -28,7 +26,6 @@ target_sources(Engine
|
||||
DebugPass.h
|
||||
DepthPrepass.h
|
||||
LightCullingPass.h
|
||||
MeshProcessor.h
|
||||
RenderGraph.h
|
||||
RenderGraphResources.h
|
||||
RenderPass.h
|
||||
|
||||
@@ -9,11 +9,7 @@ namespace Seele
|
||||
DECLARE_REF(CameraActor)
|
||||
DECLARE_REF(Scene)
|
||||
DECLARE_REF(Viewport)
|
||||
struct DebugPassData
|
||||
{
|
||||
Array<DebugVertex> vertices;
|
||||
};
|
||||
class DebugPass : public RenderPass<DebugPassData>
|
||||
class DebugPass : public RenderPass
|
||||
{
|
||||
public:
|
||||
DebugPass(Gfx::PGraphics graphics);
|
||||
|
||||
@@ -2,77 +2,16 @@
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Window/Window.h"
|
||||
#include "Component/Camera.h"
|
||||
#include "Component/Mesh.h"
|
||||
#include "Actor/CameraActor.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "RenderGraph.h"
|
||||
#include "Material/MaterialInterface.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
DepthPrepassMeshProcessor::DepthPrepassMeshProcessor(Gfx::PGraphics graphics)
|
||||
: MeshProcessor(graphics)
|
||||
{
|
||||
}
|
||||
|
||||
DepthPrepassMeshProcessor::~DepthPrepassMeshProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
void DepthPrepassMeshProcessor::processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout baseLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 /*staticMeshId*/)
|
||||
{
|
||||
//std::cout << "Depth void started" << std::endl;
|
||||
PMaterialInterface material = batch.material;
|
||||
//const Gfx::MaterialShadingModel shadingModel = material->getShadingModel();
|
||||
|
||||
const PVertexShaderInput vertexInput = batch.vertexInput;
|
||||
|
||||
const Gfx::ShaderCollection* collection = material->getShaders(Gfx::RenderPassType::DepthPrepass, vertexInput->getType());
|
||||
if (collection == nullptr)
|
||||
{
|
||||
material->createShaders(graphics, Gfx::RenderPassType::DepthPrepass, vertexInput->getType());
|
||||
collection = material->getShaders(Gfx::RenderPassType::DepthPrepass, vertexInput->getType());
|
||||
}
|
||||
assert(collection != nullptr);
|
||||
|
||||
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand();
|
||||
renderCommand->setViewport(target);
|
||||
Gfx::PPipelineLayout pipelineLayout = graphics->createPipelineLayout(baseLayout);
|
||||
pipelineLayout->addDescriptorLayout(DepthPrepass::INDEX_MATERIAL, material->getDescriptorLayout());
|
||||
pipelineLayout->create();
|
||||
Gfx::PDescriptorSet materialSet = material->createDescriptorSet();
|
||||
descriptorSets[DepthPrepass::INDEX_MATERIAL] = materialSet;
|
||||
for(uint32 i = 0; i < batch.elements.size(); ++i)
|
||||
{
|
||||
buildMeshDrawCommand(batch,
|
||||
// primitiveComponent,
|
||||
renderPass,
|
||||
pipelineLayout,
|
||||
renderCommand,
|
||||
descriptorSets,
|
||||
collection->vertexShader,
|
||||
collection->controlShader,
|
||||
collection->evalutionShader,
|
||||
collection->geometryShader,
|
||||
collection->fragmentShader,
|
||||
true);
|
||||
}
|
||||
std::scoped_lock lock(commandLock);
|
||||
renderCommands.add(renderCommand);
|
||||
//std::cout << "Finished depth job" << std::endl;
|
||||
//co_return;
|
||||
}
|
||||
|
||||
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics)
|
||||
: RenderPass(graphics)
|
||||
, processor(new DepthPrepassMeshProcessor(graphics))
|
||||
, descriptorSets(3)
|
||||
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
|
||||
: RenderPass(graphics, scene)
|
||||
, descriptorSets(4)
|
||||
{
|
||||
UniformBufferCreateInfo uniformInitializer;
|
||||
|
||||
@@ -86,16 +25,6 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics)
|
||||
viewParamBuffer = graphics->createUniformBuffer(uniformInitializer);
|
||||
viewLayout->create();
|
||||
depthPrepassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewLayout);
|
||||
|
||||
primitiveLayout = graphics->createDescriptorLayout("PrimitiveLayout");
|
||||
primitiveLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
primitiveLayout->create();
|
||||
depthPrepassLayout->addDescriptorLayout(INDEX_SCENE_DATA, primitiveLayout);
|
||||
depthPrepassLayout->addPushConstants(Gfx::SePushConstantRange{
|
||||
.stageFlags = (Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT),
|
||||
.offset = 0,
|
||||
.size = sizeof(uint32),
|
||||
});
|
||||
}
|
||||
|
||||
DepthPrepass::~DepthPrepass()
|
||||
@@ -104,8 +33,6 @@ DepthPrepass::~DepthPrepass()
|
||||
|
||||
void DepthPrepass::beginFrame(const Component::Camera& cam)
|
||||
{
|
||||
processor->clearCommands();
|
||||
primitiveLayout->reset();
|
||||
BulkResourceData uniformUpdate;
|
||||
|
||||
viewParams.viewMatrix = cam.getViewMatrix();
|
||||
@@ -116,12 +43,10 @@ void DepthPrepass::beginFrame(const Component::Camera& cam)
|
||||
uniformUpdate.data = (uint8*)&viewParams;
|
||||
viewParamBuffer->updateContents(uniformUpdate);
|
||||
viewLayout->reset();
|
||||
descriptorSets[INDEX_SCENE_DATA] = primitiveLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_SCENE_DATA]->updateBuffer(0, passData.sceneDataBuffer);
|
||||
descriptorSets[INDEX_SCENE_DATA]->writeChanges();
|
||||
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
|
||||
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
|
||||
|
||||
//std::cout << "DepthPrepass beginFrame()" << std::endl;
|
||||
//co_return;
|
||||
}
|
||||
@@ -133,11 +58,39 @@ void DepthPrepass::render()
|
||||
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
|
||||
depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS);
|
||||
graphics->beginRenderPass(renderPass);
|
||||
for (const auto& meshBatch : passData.staticDrawList)
|
||||
for (VertexData* vertexData : VertexData::getList())
|
||||
{
|
||||
processor->processMeshBatch(meshBatch, viewport, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets);
|
||||
const auto& materials = vertexData->getMaterialData();
|
||||
for (const auto& [_, materialData] : materials)
|
||||
{
|
||||
// Create Pipeline(Material, VertexData)
|
||||
// Descriptors:
|
||||
// ViewData => global, static
|
||||
// Material => per material
|
||||
// VertexData => per meshtype
|
||||
// SceneData => per topology
|
||||
Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender");
|
||||
Gfx::PPipelineLayout layout = graphics->createPipelineLayout(depthPrepassLayout);
|
||||
layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout());
|
||||
layout->addDescriptorLayout(INDEX_VERTEX_DATA, vertexData->getVertexDataLayout());
|
||||
layout->addDescriptorLayout(INDEX_SCENE_DATA, vertexData->getInstanceDataLayout());
|
||||
layout->create();
|
||||
|
||||
GraphicsPipelineCreateInfo pipelineInfo;
|
||||
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(pipelineInfo);
|
||||
command->bindPipeline(pipeline);
|
||||
|
||||
vertexData->bindBuffers(command);
|
||||
descriptorSets[INDEX_VERTEX_DATA] = vertexData->getVertexDataSet();
|
||||
for (const auto&[_, instance]: materialData.instances)
|
||||
{
|
||||
descriptorSets[INDEX_MATERIAL] = instance.materialInstance->getDescriptorSet();
|
||||
descriptorSets[INDEX_SCENE_DATA] = instance.descriptorSet;
|
||||
command->bindDescriptor(descriptorSets);
|
||||
command->dispatch(instance.numMeshes, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
graphics->executeCommands(processor->getRenderCommands());
|
||||
graphics->endRenderPass();
|
||||
//std::cout << "DepthPrepass render()" << std::endl;
|
||||
//co_return;
|
||||
@@ -175,5 +128,6 @@ void DepthPrepass::modifyRenderPassMacros(Map<const char*, const char*>& defines
|
||||
{
|
||||
defines["INDEX_VIEW_PARAMS"] = "0";
|
||||
defines["INDEX_MATERIAL"] = "1";
|
||||
defines["INDEX_SCENE_DATA"] = "2";
|
||||
defines["INDEX_VERTEX_DATA"] = "2";
|
||||
defines["INDEX_SCENE_DATA"] = "3";
|
||||
}
|
||||
|
||||
@@ -1,40 +1,14 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "MeshProcessor.h"
|
||||
#include "RenderPass.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class DepthPrepassMeshProcessor : public MeshProcessor
|
||||
class DepthPrepass : public RenderPass
|
||||
{
|
||||
public:
|
||||
DepthPrepassMeshProcessor(Gfx::PGraphics graphics);
|
||||
virtual ~DepthPrepassMeshProcessor();
|
||||
|
||||
virtual void processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 staticMeshId = -1) override;
|
||||
|
||||
private:
|
||||
};
|
||||
DEFINE_REF(DepthPrepassMeshProcessor)
|
||||
struct DepthPrepassData
|
||||
{
|
||||
Array<MeshBatch> staticDrawList;
|
||||
Gfx::PShaderBuffer sceneDataBuffer;
|
||||
};
|
||||
class DepthPrepass : public RenderPass<DepthPrepassData>
|
||||
{
|
||||
public:
|
||||
DepthPrepass(Gfx::PGraphics graphics);
|
||||
DepthPrepass(DepthPrepass&& other) = default;
|
||||
DepthPrepass(Gfx::PGraphics graphics, PScene scene);
|
||||
~DepthPrepass();
|
||||
DepthPrepass& operator=(DepthPrepass& other) = default;
|
||||
virtual void beginFrame(const Component::Camera& cam) override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
@@ -44,9 +18,9 @@ public:
|
||||
private:
|
||||
Gfx::PRenderTargetAttachment depthAttachment;
|
||||
Gfx::PTexture2D depthBuffer;
|
||||
UPDepthPrepassMeshProcessor processor;
|
||||
|
||||
|
||||
Array<Gfx::PDescriptorSet> descriptorSets;
|
||||
|
||||
Gfx::PPipelineLayout depthPrepassLayout;
|
||||
// Set 0: viewParameter
|
||||
static constexpr uint32 INDEX_VIEW_PARAMS = 0;
|
||||
@@ -54,11 +28,11 @@ private:
|
||||
Gfx::PUniformBuffer viewParamBuffer;
|
||||
// Set 1: materials, generated
|
||||
static constexpr uint32 INDEX_MATERIAL = 1;
|
||||
// Set 2: primitive scene data
|
||||
static constexpr uint32 INDEX_SCENE_DATA = 2;
|
||||
Gfx::PDescriptorLayout primitiveLayout;
|
||||
Gfx::PUniformBuffer primitiveUniformBuffer;
|
||||
friend class DepthPrepassMeshProcessor;
|
||||
// Set 2: vertices, from VertexData
|
||||
static constexpr uint32 INDEX_VERTEX_DATA = 2;
|
||||
// Set 3: mesh data, either index buffer or meshlet data
|
||||
static constexpr uint32 INDEX_SCENE_DATA = 3;
|
||||
Gfx::PDescriptorLayout sceneDataLayout;
|
||||
};
|
||||
DEFINE_REF(DepthPrepass)
|
||||
} // namespace Seele
|
||||
|
||||
@@ -12,7 +12,7 @@ struct LightCullingPassData
|
||||
{
|
||||
LightEnv lightEnv;
|
||||
};
|
||||
class LightCullingPass : public RenderPass<LightCullingPassData>
|
||||
class LightCullingPass : public RenderPass
|
||||
{
|
||||
public:
|
||||
LightCullingPass(Gfx::PGraphics graphics);
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
#include "MeshProcessor.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/VertexShaderInput.h"
|
||||
#include "Graphics/Vulkan/VulkanGraphicsResources.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
MeshProcessor::MeshProcessor(Gfx::PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MeshProcessor::~MeshProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
void MeshProcessor::buildMeshDrawCommand(
|
||||
const MeshBatch& meshBatch,
|
||||
// const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PRenderCommand drawCommand,
|
||||
const Array<Gfx::PDescriptorSet>& descriptors,
|
||||
Gfx::PVertexShader vertexShader,
|
||||
Gfx::PControlShader controlShader,
|
||||
Gfx::PEvaluationShader evaluationShader,
|
||||
Gfx::PGeometryShader geometryShader,
|
||||
Gfx::PFragmentShader fragmentShader,
|
||||
bool positionOnly)
|
||||
{
|
||||
const PVertexShaderInput vertexInput = meshBatch.vertexInput;
|
||||
|
||||
GraphicsPipelineCreateInfo pipelineInitializer;
|
||||
pipelineInitializer.topology = meshBatch.topology;
|
||||
pipelineInitializer.vertexShader = vertexShader;
|
||||
pipelineInitializer.controlShader = controlShader;
|
||||
pipelineInitializer.evalShader = evaluationShader;
|
||||
pipelineInitializer.geometryShader = geometryShader;
|
||||
pipelineInitializer.fragmentShader = fragmentShader;
|
||||
pipelineInitializer.renderPass = renderPass;
|
||||
pipelineInitializer.pipelineLayout = pipelineLayout;
|
||||
|
||||
VertexInputStreamArray vertexStreams;
|
||||
if(positionOnly)
|
||||
{
|
||||
vertexInput->getPositionOnlyStream(vertexStreams);
|
||||
pipelineInitializer.vertexDeclaration = vertexInput->getPositionDeclaration();
|
||||
}
|
||||
else
|
||||
{
|
||||
vertexInput->getStreams(vertexStreams);
|
||||
pipelineInitializer.vertexDeclaration = vertexInput->getDeclaration();
|
||||
}
|
||||
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(pipelineInitializer);
|
||||
drawCommand->bindPipeline(pipeline);
|
||||
drawCommand->bindVertexBuffer(vertexStreams);
|
||||
drawCommand->bindDescriptor(descriptors);
|
||||
for(const auto& element : meshBatch.elements)
|
||||
{
|
||||
drawCommand->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(uint32), &element.sceneDataIndex);
|
||||
if(element.indexBuffer != nullptr)
|
||||
{
|
||||
drawCommand->bindIndexBuffer(element.indexBuffer);
|
||||
drawCommand->draw(element);
|
||||
}
|
||||
else
|
||||
{
|
||||
drawCommand->draw(vertexStreams[0].vertexBuffer->getNumVertices(), 1, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Array<Gfx::PRenderCommand> MeshProcessor::getRenderCommands()
|
||||
{
|
||||
return renderCommands;
|
||||
}
|
||||
|
||||
void MeshProcessor::clearCommands()
|
||||
{
|
||||
renderCommands.clear();
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
#include "Graphics/MeshBatch.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class MeshProcessor
|
||||
{
|
||||
public:
|
||||
MeshProcessor(Gfx::PGraphics graphics);
|
||||
virtual ~MeshProcessor();
|
||||
Array<Gfx::PRenderCommand> getRenderCommands();
|
||||
void clearCommands();
|
||||
protected:
|
||||
PScene scene;
|
||||
Gfx::PGraphics graphics;
|
||||
virtual void processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 staticMeshId = -1) = 0;
|
||||
void buildMeshDrawCommand(
|
||||
const MeshBatch& meshBatch,
|
||||
// const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PRenderCommand drawCommand,
|
||||
const Array<Gfx::PDescriptorSet>& descriptors,
|
||||
Gfx::PVertexShader vertexShader,
|
||||
Gfx::PControlShader controlShader,
|
||||
Gfx::PEvaluationShader evaluationShader,
|
||||
Gfx::PGeometryShader geometryShader,
|
||||
Gfx::PFragmentShader fragmentShader,
|
||||
bool positionOnly);
|
||||
std::mutex commandLock;
|
||||
Array<Gfx::PRenderCommand> renderCommands;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -3,24 +3,25 @@
|
||||
#include "Math/Math.h"
|
||||
#include "RenderGraphResources.h"
|
||||
#include "Component/Camera.h"
|
||||
#include "Graphics/TopologyData.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Material/MaterialInstance.h"
|
||||
#include "Graphics/VertexData.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_NAME_REF(Gfx, Viewport)
|
||||
DECLARE_NAME_REF(Gfx, Graphics)
|
||||
DECLARE_NAME_REF(Gfx, RenderPass)
|
||||
template<typename RenderPassDataType>
|
||||
class RenderPass
|
||||
{
|
||||
public:
|
||||
RenderPass(Gfx::PGraphics graphics)
|
||||
RenderPass(Gfx::PGraphics graphics, PScene scene)
|
||||
: graphics(graphics)
|
||||
, scene(scene)
|
||||
{}
|
||||
virtual ~RenderPass()
|
||||
{}
|
||||
void updateViewFrame(RenderPassDataType viewFrame) {
|
||||
passData = std::move(viewFrame);
|
||||
}
|
||||
virtual void beginFrame(const Component::Camera& cam) = 0;
|
||||
virtual void render() = 0;
|
||||
virtual void endFrame() = 0;
|
||||
@@ -41,13 +42,26 @@ protected:
|
||||
Vector2 screenDimensions;
|
||||
Vector2 pad0;
|
||||
} viewParams;
|
||||
struct DrawListId
|
||||
{
|
||||
DrawListId(PMaterialInstance mat, PVertexData vertex)
|
||||
{
|
||||
id = mat->getBaseMaterial()->getName();
|
||||
}
|
||||
std::strong_ordering operator<=>(const DrawListId& other) const
|
||||
{
|
||||
return id <=> other.id;
|
||||
}
|
||||
std::string id;
|
||||
};
|
||||
Map<DrawListId, DrawListInfo> drawList;
|
||||
PRenderGraphResources resources;
|
||||
RenderPassDataType passData;
|
||||
Gfx::PRenderPass renderPass;
|
||||
Gfx::PGraphics graphics;
|
||||
Gfx::PViewport viewport;
|
||||
PScene scene;
|
||||
};
|
||||
template<typename RP, typename T>
|
||||
concept RenderPassType = std::derived_from<RP, RenderPass<T>>;
|
||||
template<typename RP>
|
||||
concept RenderPassType = std::derived_from<RP, RenderPass>;
|
||||
|
||||
} // namespace Seele
|
||||
|
||||
@@ -8,11 +8,7 @@ namespace Seele
|
||||
DECLARE_REF(CameraActor)
|
||||
DECLARE_REF(Scene)
|
||||
DECLARE_REF(Viewport)
|
||||
struct SkyboxPassData
|
||||
{
|
||||
Component::Skybox skybox;
|
||||
};
|
||||
class SkyboxRenderPass : public RenderPass<SkyboxPassData>
|
||||
class SkyboxRenderPass : public RenderPass
|
||||
{
|
||||
public:
|
||||
SkyboxRenderPass(Gfx::PGraphics graphics);
|
||||
|
||||
@@ -17,12 +17,7 @@ struct TextRender
|
||||
Vector2 position;
|
||||
float scale;
|
||||
};
|
||||
struct TextPassData
|
||||
{
|
||||
Array<TextRender> texts;
|
||||
};
|
||||
|
||||
class TextPass : public RenderPass<TextPassData>
|
||||
class TextPass : public RenderPass
|
||||
{
|
||||
public:
|
||||
TextPass(Gfx::PGraphics graphics);
|
||||
|
||||
@@ -8,7 +8,5 @@ public:
|
||||
StaticMeshVertexData();
|
||||
virtual ~StaticMeshVertexData();
|
||||
private:
|
||||
Gfx::PShaderBuffer texCoords;
|
||||
Gfx::PShaderBuffer normals;
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "GraphicsResources.h"
|
||||
#include "VertexData.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -9,6 +10,8 @@ public:
|
||||
TopologyData();
|
||||
virtual ~TopologyData();
|
||||
virtual void bind() = 0;
|
||||
private:
|
||||
protected:
|
||||
VertexData* vertexData;
|
||||
};
|
||||
DEFINE_REF(TopologyData)
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,95 @@
|
||||
#include "VertexData.h"
|
||||
#include "Material/Material.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
void VertexData::resetMeshData()
|
||||
{
|
||||
materialData.clear();
|
||||
}
|
||||
|
||||
void VertexData::updateMesh(const Component::Transform& transform, const Component::Mesh& mesh)
|
||||
{
|
||||
PMaterial mat = mesh.instance->getBaseMaterial();
|
||||
MaterialData& matData = materialData[mat->getName()];
|
||||
MaterialInstanceData& matInstanceData = matData.instances[mesh.instance->getId()];
|
||||
matInstanceData.meshes.add(MeshInstanceData{
|
||||
.id = mesh.id,
|
||||
.instance = InstanceData {
|
||||
.transformMatrix = transform.toMatrix(),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void VertexData::createDescriptors()
|
||||
{
|
||||
for (const auto& [_, mat] : materialData)
|
||||
{
|
||||
for (auto& [_, matInst] : mat.instances)
|
||||
{
|
||||
Array<InstanceData> instanceData;
|
||||
Array<MeshData> meshes;
|
||||
for (const auto& inst : matInst.meshes)
|
||||
{
|
||||
for (const auto& mesh : meshData[inst.id])
|
||||
{
|
||||
instanceData.add(inst.instance);
|
||||
meshes.add(mesh);
|
||||
}
|
||||
}
|
||||
Gfx::PShaderBuffer instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.resourceData = {
|
||||
.size = sizeof(InstanceData) * instanceData.size(),
|
||||
.data = (uint8*)instanceData.data(),
|
||||
},
|
||||
.stride = sizeof(InstanceData)
|
||||
});
|
||||
Gfx::PShaderBuffer meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.resourceData = {
|
||||
.size = sizeof(MeshData) * meshes.size(),
|
||||
.data = (uint8*)meshes.data(),
|
||||
},
|
||||
.stride = sizeof(MeshData)
|
||||
});
|
||||
matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet();
|
||||
matInst.descriptorSet->updateBuffer(0, instanceBuffer);
|
||||
if (Gfx::useMeshShading)
|
||||
{
|
||||
matInst.descriptorSet->updateBuffer(1, meshDataBuffer);
|
||||
matInst.descriptorSet->updateBuffer(2, meshletBuffer);
|
||||
}
|
||||
matInst.descriptorSet->writeChanges();
|
||||
matInst.numMeshes = meshes.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<VertexData*> vertexDataList;
|
||||
|
||||
List<VertexData*> VertexData::getList()
|
||||
{
|
||||
return vertexDataList;
|
||||
}
|
||||
|
||||
VertexData::VertexData(Gfx::PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
{
|
||||
instanceDataLayout = graphics->createDescriptorLayout("VertexDataInstanceLayout");
|
||||
instanceDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
if (Gfx::useMeshShading)
|
||||
{
|
||||
// meshData
|
||||
instanceDataLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
// meshletData
|
||||
instanceDataLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
meshletBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.resourceData = {
|
||||
.size = sizeof(MeshletData),
|
||||
.data = nullptr,
|
||||
},
|
||||
.bDynamic = true,
|
||||
});
|
||||
}
|
||||
instanceDataLayout->create();
|
||||
}
|
||||
@@ -1,13 +1,80 @@
|
||||
#pragma once
|
||||
#include "GraphicsResources.h"
|
||||
#include "Material/MaterialInstance.h"
|
||||
#include "Component/Mesh.h"
|
||||
#include "Component/Transform.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
struct MeshId
|
||||
{
|
||||
uint64 id;
|
||||
};
|
||||
class VertexData
|
||||
{
|
||||
public:
|
||||
private:
|
||||
Gfx::PShaderBuffer positions;
|
||||
struct InstanceData
|
||||
{
|
||||
Matrix4 transformMatrix;
|
||||
};
|
||||
struct MeshInstanceData
|
||||
{
|
||||
MeshId id;
|
||||
InstanceData instance;
|
||||
};
|
||||
struct MaterialInstanceData
|
||||
{
|
||||
PMaterialInstance materialInstance;
|
||||
Gfx::PDescriptorSet descriptorSet;
|
||||
uint32_t numMeshes; // not necessarily equal to meshes.size() if a MeshId has multiple meshes
|
||||
Array<MeshInstanceData> meshes;
|
||||
};
|
||||
struct MaterialData
|
||||
{
|
||||
PMaterial material;
|
||||
Map<uint64, MaterialInstanceData> instances;
|
||||
};
|
||||
struct MeshData
|
||||
{
|
||||
uint32 numMeshlets;
|
||||
uint32 meshletOffset;
|
||||
};
|
||||
void resetMeshData();
|
||||
void updateMesh(const Component::Transform& transform, const Component::Mesh& mesh);
|
||||
void createDescriptors();
|
||||
virtual void bindBuffers(Gfx::PRenderCommand command) = 0;
|
||||
virtual Gfx::PDescriptorLayout getVertexDataLayout() = 0;
|
||||
virtual Gfx::PDescriptorSet getVertexDataSet() = 0;
|
||||
virtual Gfx::PDescriptorLayout getInstanceDataLayout() = 0;
|
||||
virtual std::string getTypeName() const = 0;
|
||||
const Map<std::string, MaterialData>& getMaterialData() const { return materialData; }
|
||||
const Array<MeshData>& getMeshData(MeshId id) { return meshData[id]; }
|
||||
static List<VertexData*> getList();
|
||||
protected:
|
||||
struct MeshletAABB
|
||||
{
|
||||
Vector min;
|
||||
float pad0;
|
||||
Vector max;
|
||||
float pad1;
|
||||
};
|
||||
struct MeshletData
|
||||
{
|
||||
MeshletAABB boundingBox;
|
||||
uint32_t vertexCount;
|
||||
uint32_t primiticeCount;
|
||||
uint32_t vertexOffset;
|
||||
uint32_t primitiveOffset;
|
||||
};
|
||||
Map<std::string, MaterialData> materialData;
|
||||
Map<MeshId, Array<MeshData>> meshData;
|
||||
Array<MeshletData> meshlets;
|
||||
Gfx::PDescriptorLayout instanceDataLayout;
|
||||
Gfx::PGraphics graphics;
|
||||
// for mesh shading
|
||||
Gfx::PShaderBuffer meshletBuffer;
|
||||
// for legacy pipeline
|
||||
Gfx::PIndexBuffer indexBuffer;
|
||||
VertexData(Gfx::PGraphics graphics);
|
||||
};
|
||||
DEFINE_REF(VertexData)
|
||||
}
|
||||
@@ -304,18 +304,18 @@ void RenderCommand::pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStag
|
||||
vkCmdPushConstants(handle, layout.cast<PipelineLayout>()->getHandle(), stage, offset, size, data);
|
||||
}
|
||||
|
||||
void RenderCommand::draw(const MeshBatchElement& data)
|
||||
{
|
||||
assert(threadId == std::this_thread::get_id());
|
||||
vkCmdDrawIndexed(handle, static_cast<uint32>(data.indexBuffer->getNumIndices()), data.numInstances, data.minVertexIndex, data.baseVertexIndex, 0);
|
||||
}
|
||||
|
||||
void RenderCommand::draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance)
|
||||
{
|
||||
assert(threadId == std::this_thread::get_id());
|
||||
vkCmdDraw(handle, vertexCount, instanceCount, firstVertex, firstInstance);
|
||||
}
|
||||
|
||||
void RenderCommand::dispatch(uint32 groupX, uint32 groupY, uint32 groupZ)
|
||||
{
|
||||
assert(threadId == std::this_thread::get_id());
|
||||
vkCmdDrawMeshTasksEXT(handle, groupX, groupY, groupZ);
|
||||
}
|
||||
|
||||
ComputeCommand::ComputeCommand(PGraphics graphics, VkCommandPool cmdPool)
|
||||
: graphics(graphics)
|
||||
, owner(cmdPool)
|
||||
|
||||
@@ -90,8 +90,8 @@ public:
|
||||
virtual void bindVertexBuffer(const Array<VertexInputStream>& streams) override;
|
||||
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
|
||||
virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
|
||||
virtual void draw(const MeshBatchElement& data) override;
|
||||
virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override;
|
||||
virtual void dispatch(uint32 groupX, uint32 groupY, uint32 groupZ) override;
|
||||
private:
|
||||
PGraphicsPipeline pipeline;
|
||||
bool ready;
|
||||
|
||||
Reference in New Issue
Block a user