Adding cached depth renderpass

This commit is contained in:
Dynamitos
2024-05-30 16:56:22 +02:00
parent 4b6022237b
commit f278afad66
20 changed files with 908 additions and 677 deletions
+13 -1
View File
@@ -6,12 +6,24 @@
"configurations": [ "configurations": [
{ {
"name": "Editor", "name": "Editor",
"type": "lldb", "type": "cppvsdbg",
"request": "launch", "request": "launch",
"program": "${workspaceRoot}/build/Editor.exe", "program": "${workspaceRoot}/build/Editor.exe",
"args": [], "args": [],
"cwd": "${workspaceRoot}/build", "cwd": "${workspaceRoot}/build",
"console": "internalConsole", "console": "internalConsole",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}, },
{ {
"name": "Editor (Mac)", "name": "Editor (Mac)",
+5
View File
@@ -22,6 +22,11 @@
"short": "RelWithDebInfo", "short": "RelWithDebInfo",
"long": "Release with debug symbols", "long": "Release with debug symbols",
"buildType": "RelWithDebInfo" "buildType": "RelWithDebInfo"
},
"minsizerel": {
"short": "MinSizeRel",
"long": "Minimal size Release",
"buildType": "MinSizeRel"
} }
} }
}, },
+17 -35
View File
@@ -3,47 +3,29 @@ import Scene;
groupshared MeshPayload p; groupshared MeshPayload p;
groupshared uint head; groupshared uint head;
groupshared Frustum viewFrustum;
[numthreads(TASK_GROUP_SIZE, 1, 1)] [numthreads(TASK_GROUP_SIZE, 1, 1)]
[outputtopology("triangle")]
[shader("amplification")] [shader("amplification")]
void taskMain( void taskMain(
uint threadID: SV_GroupIndex, uint threadID: SV_GroupIndex,
uint groupID: SV_GroupID uint groupID: SV_GroupID,
){ ){
InstanceData instance = pScene.instances[pOffsets.instanceOffset + groupID]; InstanceData instance = pScene.instances[pOffsets.instanceOffset + groupID];
MeshData mesh = pScene.meshData[pOffsets.instanceOffset + groupID]; MeshData mesh = pScene.meshData[pOffsets.instanceOffset + groupID];
if(threadID == 0) //head = 0;
{ //GroupMemoryBarrierWithGroupSync();
head = 0; //for(uint i = threadID; i < mesh.numMeshlets; i += TASK_GROUP_SIZE)
float3 origin = viewToModel(instance.inverseTransformMatrix, float4(0, 0, 0, 1)).xyz; //{
const float offset = 0.0f; // uint m = mesh.meshletOffset + i;
float3 corners[4] = { // MeshletDescription meshlet = pScene.meshletInfos[m];
screenToModel(instance.inverseTransformMatrix, float4(offset, offset, -1.0f, 1.0f)).xyz, // MeshletCullingInfo culling = pScene.culledMeshlets[instance.meshletCullingOffset];
screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions.x - offset, offset, -1.0f, 1.0f)).xyz, // if(culling.anyVisible())
screenToModel(instance.inverseTransformMatrix, float4(offset, pViewParams.screenDimensions.y - offset, -1.0f, 1.0f)).xyz, // {
screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions - float2(offset, offset), -1.0f, 1.0f)).xyz // uint index;
}; // InterlockedAdd(head, 1, index);
viewFrustum.sides[0] = computePlane(origin, corners[2], corners[0]); // p.culledMeshlets[index] = m;
viewFrustum.sides[1] = computePlane(origin, corners[1], corners[3]); // }
viewFrustum.sides[2] = computePlane(origin, corners[0], corners[1]); //}
viewFrustum.sides[3] = computePlane(origin, corners[3], corners[2]); //GroupMemoryBarrierWithGroupSync();
p.instanceId = pOffsets.instanceOffset + groupID; //DispatchMesh(head, 1, 1, p);
p.cullingOffset = pScene.cullingOffsets[pOffsets.cullingCounterOffset + groupID];
}
GroupMemoryBarrierWithGroupSync();
for(uint i = threadID; i < mesh.numMeshlets; i += TASK_GROUP_SIZE)
{
uint m = mesh.meshletOffset + i;
MeshletDescription meshlet = pScene.meshletInfos[m];
if(meshlet.bounding.insideFrustum(viewFrustum))
{
uint index;
InterlockedAdd(head, 1, index);
pScene.culledMeshlets[p.cullingOffset + index] = m;
}
}
GroupMemoryBarrierWithGroupSync();
DispatchMesh(head, 1, 1, p);
} }
+34
View File
@@ -0,0 +1,34 @@
import Common;
import Scene;
groupshared MeshPayload p;
groupshared uint head;
[numthreads(TASK_GROUP_SIZE, 1, 1)]
[shader("amplification")]
void taskMain(
uint threadID: SV_GroupIndex,
uint groupID: SV_GroupID, )
{
if (threadID == 0)
{
head = 0;
p.instanceId = pOffsets.instanceOffset + groupID;
}
GroupMemoryBarrierWithGroupSync();
MeshData mesh = pScene.meshData[p.instanceId];
for (uint i = threadID; i < mesh.numMeshlets; i += TASK_GROUP_SIZE)
{
uint m = mesh.meshletOffset + i;
//MeshletDescription meshlet = pScene.meshletInfos[m];
//MeshletCullingInfo culling = pScene.culledMeshlets[pScene.cullingOffsets[p.instanceId] + i];
//if(culling.anyVisible())
{
uint index;
InterlockedAdd(head, 1, index);
p.culledMeshlets[i] = m;
}
}
GroupMemoryBarrierWithGroupSync();
DispatchMesh(mesh.numMeshlets, 1, 1, p);
}
-51
View File
@@ -1,51 +0,0 @@
import Common;
import BRDF;
import Scene;
import VertexData;
import MaterialParameter;
struct PrimitiveAttributes
{
uint cull: SV_CullPrimitive;
};
struct CulledMeshletList
{
StructuredBuffer<uint> meshletIndices;
};
ParameterBlock<CulledMeshletList> pCullingList;
[numthreads(MESH_GROUP_SIZE, 1, 1)]
[outputtopology("triangle")]
[shader("mesh")]
void meshMain(
in uint threadID: SV_GroupIndex,
in uint groupID: SV_GroupID,
out vertices FragmentParameter vertices[MAX_VERTICES],
out indices uint3 indices[MAX_PRIMITIVES]
){
uint meshletIndex = pCullingList.meshletIndices[groupID];
MeshletDescription m = pScene.meshletInfos[meshletIndex];
SetMeshOutputCounts(m.vertexCount, m.primitiveCount);
for(uint i = threadID; i < MAX_PRIMITIVES; i += MESH_GROUP_SIZE)
{
uint p = min(i, m.primitiveCount - 1);
{
uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
indices[p] = uint3(local_idx0, local_idx1, local_idx2);
}
}
for(uint i = threadID; i < MAX_VERTICES; i+=MESH_GROUP_SIZE)
{
uint v = min(i, m.vertexCount - 1);
{
uint vertexIndex = pScene.vertexIndices[m.vertexOffset + v];
VertexAttributes attr = pVertexData.getAttributes(m.indicesOffset + vertexIndex);
attr.meshletId = meshletIndex;
vertices[v] = attr.getParameter(float4x4(1.0));
}
}
}
-2
View File
@@ -29,7 +29,6 @@ void taskMain(
viewFrustum.sides[2] = computePlane(origin, corners[0], corners[1]); viewFrustum.sides[2] = computePlane(origin, corners[0], corners[1]);
viewFrustum.sides[3] = computePlane(origin, corners[3], corners[2]); viewFrustum.sides[3] = computePlane(origin, corners[3], corners[2]);
p.instanceId = pOffsets.instanceOffset + groupID; p.instanceId = pOffsets.instanceOffset + groupID;
//p.cullingOffset = pScene.cullingOffsets[pOffsets.cullingCounterOffset + groupID];
} }
GroupMemoryBarrierWithGroupSync(); GroupMemoryBarrierWithGroupSync();
for(uint i = threadID; i < mesh.numMeshlets; i += TASK_GROUP_SIZE) for(uint i = threadID; i < mesh.numMeshlets; i += TASK_GROUP_SIZE)
@@ -43,7 +42,6 @@ void taskMain(
uint index; uint index;
InterlockedAdd(head, 1, index); InterlockedAdd(head, 1, index);
p.culledMeshlets[index] = m; p.culledMeshlets[index] = m;
//pScene.culledMeshlets[p.cullingOffset + index] = m;
} }
} }
GroupMemoryBarrierWithGroupSync(); GroupMemoryBarrierWithGroupSync();
+18 -2
View File
@@ -31,6 +31,22 @@ struct InstanceData
float4x4 inverseTransformMatrix; float4x4 inverseTransformMatrix;
}; };
struct MeshletCullingInfo
{
uint64_t cull[MAX_PRIMITIVES / 64];
// lookup if a specific triangle is visible
bool triangleVisible(uint32_t primIndex)
{
uint32_t arrIdx = primIndex / 64;
uint32_t cullIdx = primIndex % 64;
return (cull[arrIdx] & (1 << cullIdx)) != 0;
}
bool anyVisible()
{
return (cull[0] | cull[1] | cull[2] | cull[3]) != 0;
}
};
struct DrawCallOffsets struct DrawCallOffsets
{ {
uint32_t instanceOffset; uint32_t instanceOffset;
@@ -45,8 +61,8 @@ struct Scene
StructuredBuffer<MeshletDescription> meshletInfos; StructuredBuffer<MeshletDescription> meshletInfos;
StructuredBuffer<uint8_t> primitiveIndices; StructuredBuffer<uint8_t> primitiveIndices;
StructuredBuffer<uint32_t> vertexIndices; StructuredBuffer<uint32_t> vertexIndices;
// StructuredBuffer<uint32_t> cullingOffsets; StructuredBuffer<MeshletCullingInfo> culledMeshlets;
// RWStructuredBuffer<uint32_t> culledMeshlets; StructuredBuffer<uint32_t> cullingOffsets;
}; };
layout(set=2) layout(set=2)
ParameterBlock<Scene> pScene; ParameterBlock<Scene> pScene;
+8 -20
View File
@@ -42,7 +42,7 @@ BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
if (graphics->supportMeshShading()) if (graphics->supportMeshShading())
{ {
graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "MeshletPass", true, true, "BasePass", true, true, "ViewCullingTask"); graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "MeshletPass", true, true, "BasePass", true, true, "DrawListTask");
} }
else else
{ {
@@ -91,7 +91,7 @@ void BasePass::render()
Gfx::ShaderPermutation permutation; Gfx::ShaderPermutation permutation;
if (graphics->supportMeshShading()) if (graphics->supportMeshShading())
{ {
permutation.setTaskFile("ViewCullingTask"); permutation.setTaskFile("DrawListTask");
permutation.setMeshFile("MeshletPass"); permutation.setMeshFile("MeshletPass");
} }
else else
@@ -140,7 +140,7 @@ void BasePass::render()
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL, .depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL,
}, },
.colorBlend = { .colorBlend = {
.attachmentCount = 2, .attachmentCount = 1,
}, },
}; };
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo)); Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
@@ -160,7 +160,7 @@ void BasePass::render()
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL, .depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL,
}, },
.colorBlend = { .colorBlend = {
.attachmentCount = 2, .attachmentCount = 1,
}, },
}; };
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo)); Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
@@ -182,11 +182,10 @@ void BasePass::render()
else else
{ {
command->bindIndexBuffer(vertexData->getIndexBuffer()); command->bindIndexBuffer(vertexData->getIndexBuffer());
uint32 inst = drawCall.offsets.instanceOffset;
for (const auto& meshData : drawCall.instanceMeshData) for (const auto& meshData : drawCall.instanceMeshData)
{ {
// all meshlets of a mesh share the same indices offset // all meshlets of a mesh share the same indices offset
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, vertexData->getIndicesOffset(meshData.meshletOffset), inst++); command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, vertexData->getIndicesOffset(meshData.meshletOffset), 0);
} }
} }
} }
@@ -208,17 +207,6 @@ void BasePass::publishOutputs()
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE); Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment); resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
meshletIdTexture = graphics->createTexture2D(TextureCreateInfo{
.format = Gfx::SE_FORMAT_R32_UINT,
.width = viewport->getWidth(),
.height = viewport->getHeight(),
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
});
meshletIdAttachment = Gfx::RenderTargetAttachment(meshletIdTexture,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("BASEPASS_MESHLETID", meshletIdAttachment);
} }
void BasePass::createRenderPass() void BasePass::createRenderPass()
@@ -228,7 +216,7 @@ void BasePass::createRenderPass()
depthAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL); depthAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL);
depthAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); depthAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{ Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = { colorAttachment, meshletIdAttachment }, .colorAttachments = { colorAttachment },
.depthAttachment = depthAttachment, .depthAttachment = depthAttachment,
}; };
Array<Gfx::SubPassDependency> dependency = { Array<Gfx::SubPassDependency> dependency = {
@@ -245,7 +233,7 @@ void BasePass::createRenderPass()
.dstSubpass = 0, .dstSubpass = 0,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, .srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, .dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.srcAccess = Gfx::SE_ACCESS_NONE, .srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, .dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
}, },
{ {
@@ -262,7 +250,7 @@ void BasePass::createRenderPass()
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, .srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, .dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, .srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_NONE, .dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
}, },
}; };
renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport); renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport);
+1 -2
View File
@@ -20,12 +20,11 @@ public:
private: private:
Gfx::RenderTargetAttachment colorAttachment; Gfx::RenderTargetAttachment colorAttachment;
Gfx::RenderTargetAttachment depthAttachment; Gfx::RenderTargetAttachment depthAttachment;
Gfx::RenderTargetAttachment meshletIdAttachment; Gfx::RenderTargetAttachment visibilityAttachment;
Gfx::PShaderBuffer oLightIndexList; Gfx::PShaderBuffer oLightIndexList;
Gfx::PShaderBuffer tLightIndexList; Gfx::PShaderBuffer tLightIndexList;
Gfx::PTexture2D oLightGrid; Gfx::PTexture2D oLightGrid;
Gfx::PTexture2D tLightGrid; Gfx::PTexture2D tLightGrid;
Gfx::OTexture2D meshletIdTexture;
Gfx::PDescriptorSet opaqueCulling; Gfx::PDescriptorSet opaqueCulling;
Gfx::PDescriptorSet transparentCulling; Gfx::PDescriptorSet transparentCulling;
@@ -2,6 +2,8 @@ target_sources(Engine
PRIVATE PRIVATE
BasePass.h BasePass.h
BasePass.cpp BasePass.cpp
CachedDepthPass.h
CachedDepthPass.cpp
DebugPass.h DebugPass.h
DebugPass.cpp DebugPass.cpp
DepthPrepass.h DepthPrepass.h
@@ -15,10 +17,6 @@ target_sources(Engine
RenderPass.cpp RenderPass.cpp
SkyboxRenderPass.h SkyboxRenderPass.h
SkyboxRenderPass.cpp SkyboxRenderPass.cpp
#StaticDepthPrepass.h
#StaticDepthPrepass.cpp
#StaticBasePass.h
#StaticBasePass.cpp
TextPass.h TextPass.h
TextPass.cpp TextPass.cpp
UIPass.h UIPass.h
@@ -28,6 +26,7 @@ target_sources(Engine
PUBLIC FILE_SET HEADERS PUBLIC FILE_SET HEADERS
FILES FILES
BasePass.h BasePass.h
CachedDepthPass.h
DebugPass.h DebugPass.h
DepthPrepass.h DepthPrepass.h
LightCullingPass.h LightCullingPass.h
@@ -35,7 +34,5 @@ target_sources(Engine
RenderGraphResources.h RenderGraphResources.h
RenderPass.h RenderPass.h
SkyboxRenderPass.h SkyboxRenderPass.h
#StaticDepthPrepass.h
#StaticBasePass.h
TextPass.h TextPass.h
UIPass.h) UIPass.h)
@@ -0,0 +1,222 @@
#include "CachedDepthPass.h"
#include "Graphics/Shader.h"
using namespace Seele;
extern bool usePositionOnly;
extern bool useViewCulling;
CachedDepthPass::CachedDepthPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
depthPrepassLayout = graphics->createPipelineLayout("CachedDepthLayout");
depthPrepassLayout->addDescriptorLayout(viewParamsLayout);
depthPrepassLayout->addPushConstants(Gfx::SePushConstantRange{
.stageFlags = Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT,
.offset = 0,
.size = sizeof(VertexData::DrawCallOffsets),
});
if (graphics->supportMeshShading())
{
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "CachedDepthPass", "MeshletPass", false, false, "", true, true, "DrawListTask");
}
else
{
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "CachedDepthPass", "LegacyPass");
}
}
CachedDepthPass::~CachedDepthPass()
{
}
void CachedDepthPass::beginFrame(const Component::Camera &cam)
{
RenderPass::beginFrame(cam);
}
void CachedDepthPass::render()
{
graphics->beginRenderPass(renderPass);
Array<Gfx::ORenderCommand> commands;
Gfx::ShaderPermutation permutation;
permutation.setPositionOnly(usePositionOnly);
permutation.setViewCulling(useViewCulling);
if (graphics->supportMeshShading())
{
permutation.setTaskFile("DrawListTask");
permutation.setMeshFile("MeshletPass");
}
else
{
permutation.setVertexFile("LegacyPass");
}
for (VertexData *vertexData : VertexData::getList())
{
permutation.setVertexData(vertexData->getTypeName());
// Create Pipeline(VertexData)
// Descriptors:
// ViewData => global, static
// VertexData => per meshtype
// SceneData => per meshtype
Gfx::PermutationId id(permutation);
Gfx::ORenderCommand command = graphics->createRenderCommand("DepthRender");
command->setViewport(viewport);
const Gfx::ShaderCollection *collection = graphics->getShaderCompiler()->findShaders(id);
assert(collection != nullptr);
if (graphics->supportMeshShading())
{
Gfx::MeshPipelineCreateInfo pipelineInfo = {
.taskShader = collection->taskShader,
.meshShader = collection->meshShader,
.fragmentShader = collection->fragmentShader,
.renderPass = renderPass,
.pipelineLayout = collection->pipelineLayout,
.multisampleState = {
.samples = viewport->getSamples(),
},
.depthStencilState = {
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
},
.colorBlend = {
.attachmentCount = 1,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
else
{
Gfx::LegacyPipelineCreateInfo pipelineInfo = {
.vertexShader = collection->vertexShader,
.fragmentShader = collection->fragmentShader,
.renderPass = renderPass,
.pipelineLayout = collection->pipelineLayout,
.multisampleState = {
.samples = viewport->getSamples(),
},
.depthStencilState = {
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
},
.colorBlend = {
.attachmentCount = 1,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
command->bindDescriptor(vertexData->getVertexDataSet());
command->bindDescriptor(viewParamsSet);
command->bindDescriptor(vertexData->getInstanceDataSet());
uint32 offset = 0;
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets), &offset);
if (graphics->supportMeshShading())
{
command->drawMesh(vertexData->getNumInstances(), 1, 1);
}
else
{
const auto &materials = vertexData->getMaterialData();
for (const auto &materialData : materials)
{
// material not used for any active meshes, skip
if (materialData.instances.size() == 0)
continue;
for (const auto &drawCall : materialData.instances)
{
command->bindIndexBuffer(vertexData->getIndexBuffer());
uint32 inst = drawCall.offsets.instanceOffset;
for (const auto &meshData : drawCall.instanceMeshData)
{
// all meshlets of a mesh share the same indices offset
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, vertexData->getIndicesOffset(meshData.meshletOffset), inst++);
}
}
}
}
commands.add(std::move(command));
}
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
}
void CachedDepthPass::endFrame()
{
}
void CachedDepthPass::publishOutputs()
{
// If we render to a part of an image, the depth buffer itself must
// still match the size of the whole image or their coordinate systems go out of sync
TextureCreateInfo depthBufferInfo = {
.format = Gfx::SE_FORMAT_D32_SFLOAT,
.width = viewport->getOwner()->getFramebufferWidth(),
.height = viewport->getOwner()->getFramebufferHeight(),
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
};
depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment =
Gfx::RenderTargetAttachment(depthBuffer,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("DEPTHPREPASS_DEPTH", depthAttachment);
TextureCreateInfo visibilityInfo = {
.format = Gfx::SE_FORMAT_R32G32_UINT,
.width = viewport->getOwner()->getFramebufferWidth(),
.height = viewport->getOwner()->getFramebufferHeight(),
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
};
visibilityBuffer = graphics->createTexture2D(visibilityInfo);
visibilityAttachment =
Gfx::RenderTargetAttachment(visibilityBuffer,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("VISIBILITY", visibilityAttachment);
}
void CachedDepthPass::createRenderPass()
{
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.depthAttachment = depthAttachment,
};
Array<Gfx::SubPassDependency> dependency = {
{
.srcSubpass = ~0U,
.dstSubpass = 0,
.srcStage = Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
.srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
},
{
.srcSubpass = 0,
.dstSubpass = ~0U,
.srcStage = Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
.srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_SHADER_READ_BIT,
},
{
.srcSubpass = 0,
.dstSubpass = ~0U,
.srcStage = Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
.srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT,
},
{
.srcSubpass = 0,
.dstSubpass = ~0U,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
}};
renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport);
}
@@ -0,0 +1,26 @@
#pragma once
#include "RenderPass.h"
namespace Seele
{
class CachedDepthPass : public RenderPass
{
public:
CachedDepthPass(Gfx::PGraphics graphics, PScene scene);
CachedDepthPass(CachedDepthPass&&) = default;
CachedDepthPass& operator=(CachedDepthPass&&) = default;
virtual ~CachedDepthPass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
Gfx::RenderTargetAttachment depthAttachment;
Gfx::RenderTargetAttachment visibilityAttachment;
Gfx::OTexture2D depthBuffer;
Gfx::OTexture2D visibilityBuffer;
Gfx::OPipelineLayout depthPrepassLayout;
};
DEFINE_REF(CachedDepthPass)
}
+41 -38
View File
@@ -1,15 +1,5 @@
#include "DepthPrepass.h" #include "DepthPrepass.h"
#include "Graphics/Enums.h"
#include "Graphics/Graphics.h"
#include "Graphics/Shader.h" #include "Graphics/Shader.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 "Graphics/Command.h"
#include "Graphics/StaticMeshVertexData.h"
using namespace Seele; using namespace Seele;
@@ -65,12 +55,6 @@ void DepthPrepass::render()
for (VertexData *vertexData : VertexData::getList()) for (VertexData *vertexData : VertexData::getList())
{ {
permutation.setVertexData(vertexData->getTypeName()); permutation.setVertexData(vertexData->getTypeName());
const auto& materials = vertexData->getMaterialData();
for (const auto& materialData : materials)
{
// material not used for any active meshes, skip
if (materialData.instances.size() == 0)
continue;
// Create Pipeline(VertexData) // Create Pipeline(VertexData)
// Descriptors: // Descriptors:
// ViewData => global, static // ViewData => global, static
@@ -92,7 +76,8 @@ void DepthPrepass::render()
.renderPass = renderPass, .renderPass = renderPass,
.pipelineLayout = collection->pipelineLayout, .pipelineLayout = collection->pipelineLayout,
.multisampleState = { .multisampleState = {
.samples = viewport->getSamples(),}, .samples = viewport->getSamples(),
},
.depthStencilState = { .depthStencilState = {
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER, .depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
}, },
@@ -126,15 +111,22 @@ void DepthPrepass::render()
command->bindDescriptor(vertexData->getVertexDataSet()); command->bindDescriptor(vertexData->getVertexDataSet());
command->bindDescriptor(viewParamsSet); command->bindDescriptor(viewParamsSet);
command->bindDescriptor(vertexData->getInstanceDataSet()); command->bindDescriptor(vertexData->getInstanceDataSet());
for (const auto& drawCall : materialData.instances) uint32 offset = 0;
{ command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets), &offset);
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets), &drawCall.offsets);
if (graphics->supportMeshShading()) if (graphics->supportMeshShading())
{ {
command->drawMesh(drawCall.instanceMeshData.size(), 1, 1); command->drawMesh(vertexData->getNumInstances(), 1, 1);
} }
else else
{ {
const auto &materials = vertexData->getMaterialData();
for (const auto &materialData : materials)
{
for (const auto &drawCall : materialData.instances)
{
// material not used for any active meshes, skip
if (materialData.instances.size() == 0)
continue;
command->bindIndexBuffer(vertexData->getIndexBuffer()); command->bindIndexBuffer(vertexData->getIndexBuffer());
uint32 inst = drawCall.offsets.instanceOffset; uint32 inst = drawCall.offsets.instanceOffset;
for (const auto &meshData : drawCall.instanceMeshData) for (const auto &meshData : drawCall.instanceMeshData)
@@ -144,8 +136,8 @@ void DepthPrepass::render()
} }
} }
} }
commands.add(std::move(command));
} }
commands.add(std::move(command));
} }
graphics->executeCommands(std::move(commands)); graphics->executeCommands(std::move(commands));
@@ -158,25 +150,21 @@ void DepthPrepass::endFrame()
void DepthPrepass::publishOutputs() void DepthPrepass::publishOutputs()
{ {
// If we render to a part of an image, the depth buffer itself must
// still match the size of the whole image or their coordinate systems go out of sync
TextureCreateInfo depthBufferInfo = {
.format = Gfx::SE_FORMAT_D32_SFLOAT,
.width = viewport->getOwner()->getFramebufferWidth(),
.height = viewport->getOwner()->getFramebufferHeight(),
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
};
depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment =
Gfx::RenderTargetAttachment(depthBuffer,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_GENERAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("DEPTHPREPASS_DEPTH", depthAttachment);
} }
void DepthPrepass::createRenderPass() void DepthPrepass::createRenderPass()
{ {
auto depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
depthAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL);
depthAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
auto visibilityAttachment = resources->requestRenderTarget("VISIBILITY");
visibilityAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
visibilityAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
visibilityAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{ Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = {visibilityAttachment},
.depthAttachment = depthAttachment, .depthAttachment = depthAttachment,
}; };
Array<Gfx::SubPassDependency> dependency = { Array<Gfx::SubPassDependency> dependency = {
@@ -188,6 +176,14 @@ void DepthPrepass::createRenderPass()
.srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, .srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, .dstAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
}, },
{
.srcSubpass = ~0U,
.dstSubpass = 0,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
},
{ {
.srcSubpass = 0, .srcSubpass = 0,
.dstSubpass = ~0U, .dstSubpass = ~0U,
@@ -203,7 +199,14 @@ void DepthPrepass::createRenderPass()
.dstStage = Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, .dstStage = Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
.srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, .srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, .dstAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT,
} },
}; {
.srcSubpass = 0,
.dstSubpass = ~0U,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_SHADER_READ_BIT,
}};
renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport); renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport);
} }
@@ -18,9 +18,6 @@ public:
virtual void createRenderPass() override; virtual void createRenderPass() override;
private: private:
Gfx::RenderTargetAttachment depthAttachment; Gfx::RenderTargetAttachment depthAttachment;
Gfx::OTexture2D depthBuffer;
Gfx::OPipelineLayout depthPrepassLayout; Gfx::OPipelineLayout depthPrepassLayout;
}; };
DEFINE_REF(DepthPrepass) DEFINE_REF(DepthPrepass)
+61 -64
View File
@@ -100,7 +100,6 @@ void VertexData::updateMesh(PMesh mesh, Component::Transform& transform)
addDebugVertex(DebugVertex{.position = corners[5], .color = meshlets[data.meshletOffset + i].color}); addDebugVertex(DebugVertex{.position = corners[5], .color = meshlets[data.meshletOffset + i].color});
addDebugVertex(DebugVertex{.position = corners[7], .color = meshlets[data.meshletOffset + i].color}); addDebugVertex(DebugVertex{.position = corners[7], .color = meshlets[data.meshletOffset + i].color});
} }
} }
void VertexData::createDescriptors() void VertexData::createDescriptors()
@@ -110,8 +109,8 @@ void VertexData::createDescriptors()
instanceData.clear(); instanceData.clear();
instanceMeshData.clear(); instanceMeshData.clear();
//uint32 numMeshlets = 0; uint32 numMeshlets = 0;
//Array<uint32> cullingOffsets; Array<uint32> cullingOffsets;
for (auto &mat : materialData) for (auto &mat : materialData)
{ {
for (auto &instance : mat.instances) for (auto &instance : mat.instances)
@@ -121,55 +120,54 @@ void VertexData::createDescriptors()
// instance.numMeshlets = 0; // instance.numMeshlets = 0;
for (size_t i = 0; i < instance.instanceData.size(); ++i) for (size_t i = 0; i < instance.instanceData.size(); ++i)
{ {
cullingOffsets.add(numMeshlets);
instanceData.add(instance.instanceData[i]); instanceData.add(instance.instanceData[i]);
instanceMeshData.add(instance.instanceMeshData[i]); instanceMeshData.add(instance.instanceMeshData[i]);
// instance.numMeshlets += instance.instanceMeshData[i].numMeshlets; // instance.numMeshlets += instance.instanceMeshData[i].numMeshlets;
// cullingOffsets.add(numMeshlets); // cullingOffsets.add(numMeshlets);
//numMeshlets += instance.numMeshlets; numMeshlets += instance.instanceMeshData[i].numMeshlets;
} }
} }
} }
//cullingOffsetBuffer->rotateBuffer(cullingOffsets.size() * sizeof(uint32)); Array<MeshletCullingInfo> cullingData(numMeshlets);
//cullingOffsetBuffer->updateContents(ShaderBufferCreateInfo{ std::memset(cullingData.data(), 0xff, cullingData.size());
// .sourceData = { cullingOffsetBuffer->rotateBuffer(cullingOffsets.size() * sizeof(uint32));
// .size = cullingOffsets.size() * sizeof(uint32), cullingOffsetBuffer->updateContents(ShaderBufferCreateInfo{
// .data = (uint8*)cullingOffsets.data(), .sourceData = {
// }, .size = cullingOffsets.size() * sizeof(uint32),
// .numElements = cullingOffsets.size() .data = (uint8 *)cullingOffsets.data(),
// }); },
//cullingOffsetBuffer->pipelineBarrier( .numElements = cullingOffsets.size()});
// Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, cullingOffsetBuffer->pipelineBarrier(
// Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
// Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
// Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT Gfx::SE_ACCESS_MEMORY_READ_BIT,
//); Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
//cullingBuffer->rotateBuffer(numMeshlets * sizeof(uint32));
//cullingBuffer->updateContents(ShaderBufferCreateInfo{ cullingBuffer->rotateBuffer(numMeshlets * sizeof(MeshletCullingInfo));
// .sourceData = { cullingBuffer->updateContents(ShaderBufferCreateInfo{
// .size = numMeshlets * sizeof(uint32), .sourceData = {
// }, .size = numMeshlets * sizeof(MeshletCullingInfo),
// .numElements = numMeshlets .data = (uint8 *)cullingData.data(),
// }); },
//cullingBuffer->pipelineBarrier( .numElements = numMeshlets});
// Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, cullingBuffer->pipelineBarrier(
// Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
// Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
// Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT Gfx::SE_ACCESS_MEMORY_WRITE_BIT,
//); Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
instanceBuffer->rotateBuffer(instanceData.size() * sizeof(InstanceData)); instanceBuffer->rotateBuffer(instanceData.size() * sizeof(InstanceData));
instanceBuffer->updateContents(ShaderBufferCreateInfo{ instanceBuffer->updateContents(ShaderBufferCreateInfo{
.sourceData = { .sourceData = {
.size = instanceData.size() * sizeof(InstanceData), .size = instanceData.size() * sizeof(InstanceData),
.data = (uint8 *)instanceData.data(), .data = (uint8 *)instanceData.data(),
}, },
.numElements = instanceData.size() .numElements = instanceData.size()});
});
instanceBuffer->pipelineBarrier( instanceBuffer->pipelineBarrier(
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_ACCESS_MEMORY_READ_BIT,
Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
);
instanceMeshDataBuffer->rotateBuffer(sizeof(MeshData) * instanceMeshData.size()); instanceMeshDataBuffer->rotateBuffer(sizeof(MeshData) * instanceMeshData.size());
instanceMeshDataBuffer->updateContents(ShaderBufferCreateInfo{ instanceMeshDataBuffer->updateContents(ShaderBufferCreateInfo{
@@ -177,14 +175,12 @@ void VertexData::createDescriptors()
.size = sizeof(MeshData) * instanceMeshData.size(), .size = sizeof(MeshData) * instanceMeshData.size(),
.data = (uint8 *)instanceMeshData.data(), .data = (uint8 *)instanceMeshData.data(),
}, },
.numElements = instanceMeshData.size() .numElements = instanceMeshData.size()});
});
instanceMeshDataBuffer->pipelineBarrier( instanceMeshDataBuffer->pipelineBarrier(
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_ACCESS_MEMORY_READ_BIT,
Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
);
instanceDataLayout->reset(); instanceDataLayout->reset();
descriptorSet = instanceDataLayout->allocateDescriptorSet(); descriptorSet = instanceDataLayout->allocateDescriptorSet();
descriptorSet->updateBuffer(0, instanceBuffer); descriptorSet->updateBuffer(0, instanceBuffer);
@@ -192,8 +188,8 @@ void VertexData::createDescriptors()
descriptorSet->updateBuffer(2, meshletBuffer); descriptorSet->updateBuffer(2, meshletBuffer);
descriptorSet->updateBuffer(3, primitiveIndicesBuffer); descriptorSet->updateBuffer(3, primitiveIndicesBuffer);
descriptorSet->updateBuffer(4, vertexIndicesBuffer); descriptorSet->updateBuffer(4, vertexIndicesBuffer);
//descriptorSet->updateBuffer(5, cullingOffsetBuffer); descriptorSet->updateBuffer(5, cullingBuffer);
//descriptorSet->updateBuffer(6, cullingBuffer); descriptorSet->updateBuffer(6, cullingOffsetBuffer);
descriptorSet->writeChanges(); descriptorSet->writeChanges();
} }
@@ -247,17 +243,15 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
.indexType = Gfx::SE_INDEX_TYPE_UINT32, .indexType = Gfx::SE_INDEX_TYPE_UINT32,
.name = "IndexBuffer", .name = "IndexBuffer",
}); });
} }
meshletBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ meshletBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = { .sourceData = {
.size = sizeof(MeshletDescription) * meshlets.size(), .size = sizeof(MeshletDescription) * meshlets.size(),
.data = (uint8*)meshlets.data() .data = (uint8 *)meshlets.data()},
},
.numElements = meshlets.size(), .numElements = meshlets.size(),
.dynamic = false, .dynamic = false,
.name = "MeshletBuffer" .name = "MeshletBuffer"});
});
vertexIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ vertexIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = { .sourceData = {
.size = sizeof(uint32) * vertexIndices.size(), .size = sizeof(uint32) * vertexIndices.size(),
@@ -265,8 +259,8 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
}, },
.numElements = vertexIndices.size(), .numElements = vertexIndices.size(),
.dynamic = false, .dynamic = false,
.name = "VertexIndicesBuffer" .name = "VertexIndicesBuffer"});
});
primitiveIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ primitiveIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = { .sourceData = {
.size = sizeof(uint8) * primitiveIndices.size(), .size = sizeof(uint8) * primitiveIndices.size(),
@@ -329,9 +323,15 @@ void VertexData::init(Gfx::PGraphics _graphics)
instanceDataLayout = graphics->createDescriptorLayout("pScene"); instanceDataLayout = graphics->createDescriptorLayout("pScene");
// instanceData // instanceData
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, }); instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
// meshData // meshData
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, }); instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
// meshletData // meshletData
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
// primitiveIndices // primitiveIndices
@@ -339,18 +339,18 @@ void VertexData::init(Gfx::PGraphics _graphics)
// vertexIndices // vertexIndices
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
// cullingList // cullingList
//instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 5, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER }); instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 5, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
// cullingOffset // cullingOffset
//instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 6, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER }); instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 6, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
//cullingOffsetBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ cullingOffsetBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
// .dynamic = true, .dynamic = true,
// .name = "MeshletOffset", .name = "MeshletOffset",
// }); });
//cullingBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ cullingBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
// .dynamic = true, .dynamic = true,
// .name = "MeshletCulling", .name = "MeshletCulling",
// }); });
instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.dynamic = true, .dynamic = true,
.name = "InstanceBuffer", .name = "InstanceBuffer",
@@ -378,9 +378,6 @@ void VertexData::destroy()
} }
VertexData::VertexData() VertexData::VertexData()
: idCounter(0) : idCounter(0), head(0), verticesAllocated(0), dirty(false)
, head(0)
, verticesAllocated(0)
, dirty(false)
{ {
} }
+10 -3
View File
@@ -45,6 +45,11 @@ public:
{ {
uint32 instanceOffset = 0; uint32 instanceOffset = 0;
}; };
struct MeshletCullingInfo
{
uint64_t cull[256 / 64];
};
struct BatchedDrawCall struct BatchedDrawCall
{ {
PMaterialInstance materialInstance; PMaterialInstance materialInstance;
@@ -76,10 +81,12 @@ public:
const Array<MaterialData> &getMaterialData() const { return materialData; } const Array<MaterialData> &getMaterialData() const { return materialData; }
const MeshData &getMeshData(MeshId id) { return meshData[id]; } const MeshData &getMeshData(MeshId id) { return meshData[id]; }
uint64 getIndicesOffset(uint32 meshletIndex) { return meshlets[meshletIndex].indicesOffset; } uint64 getIndicesOffset(uint32 meshletIndex) { return meshlets[meshletIndex].indicesOffset; }
uint64 getNumInstances() const { return instanceData.size(); }
static List<VertexData *> getList(); static List<VertexData *> getList();
static VertexData *findByTypeName(std::string name); static VertexData *findByTypeName(std::string name);
virtual void init(Gfx::PGraphics graphics); virtual void init(Gfx::PGraphics graphics);
virtual void destroy(); virtual void destroy();
protected: protected:
virtual void resizeBuffers() = 0; virtual void resizeBuffers() = 0;
virtual void updateBuffers() = 0; virtual void updateBuffers() = 0;
@@ -110,9 +117,9 @@ protected:
Gfx::OShaderBuffer meshletBuffer; Gfx::OShaderBuffer meshletBuffer;
Gfx::OShaderBuffer vertexIndicesBuffer; Gfx::OShaderBuffer vertexIndicesBuffer;
Gfx::OShaderBuffer primitiveIndicesBuffer; Gfx::OShaderBuffer primitiveIndicesBuffer;
// temporary meshlet culling buffer, passed from task to mesh shader // Holds culling information for every meshlet for each instance
//Gfx::OShaderBuffer cullingBuffer; Gfx::OShaderBuffer cullingBuffer;
//Gfx::OShaderBuffer cullingOffsetBuffer; Gfx::OShaderBuffer cullingOffsetBuffer;
// for legacy pipeline // for legacy pipeline
Gfx::OIndexBuffer indexBuffer; Gfx::OIndexBuffer indexBuffer;
// Material data // Material data
+1 -1
View File
@@ -75,7 +75,7 @@ void Fence::reset()
} }
} }
void Fence::wait(uint32 timeout) void Fence::wait(uint64 timeout)
{ {
VkFence fences[] = {fence}; VkFence fences[] = {fence};
VkResult r = vkWaitForFences(graphics->getDevice(), 1, fences, true, timeout); VkResult r = vkWaitForFences(graphics->getDevice(), 1, fences, true, timeout);
+1 -1
View File
@@ -38,7 +38,7 @@ public:
{ {
return fence; return fence;
} }
void wait(uint32 timeout); void wait(uint64 timeout);
bool operator<(const Fence &other) const bool operator<(const Fence &other) const
{ {
return fence < other.fence; return fence < other.fence;
+7 -4
View File
@@ -7,8 +7,12 @@
#include "System/LightGather.h" #include "System/LightGather.h"
#include "System/MeshUpdater.h" #include "System/MeshUpdater.h"
#include "System/CameraUpdater.h" #include "System/CameraUpdater.h"
#include "Graphics/Vulkan/Graphics.h" #include "Graphics/RenderPass/CachedDepthPass.h"
#include "Graphics/Vulkan/Allocator.h" #include "Graphics/RenderPass/DepthPrepass.h"
#include "Graphics/RenderPass/LightCullingPass.h"
#include "Graphics/RenderPass/BasePass.h"
#include "Graphics/RenderPass/SkyboxRenderPass.h"
#include "Graphics/RenderPass/DebugPass.h"
using namespace Seele; using namespace Seele;
@@ -22,10 +26,9 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
, gameInterface(dllPath) , gameInterface(dllPath)
{ {
reloadGame(); reloadGame();
//renderGraph.addPass(new StaticDepthPrepass(graphics, scene)); renderGraph.addPass(new CachedDepthPass(graphics, scene));
renderGraph.addPass(new DepthPrepass(graphics, scene)); renderGraph.addPass(new DepthPrepass(graphics, scene));
renderGraph.addPass(new LightCullingPass(graphics, scene)); renderGraph.addPass(new LightCullingPass(graphics, scene));
//renderGraph.addPass(new StaticBasePass(graphics, scene));
renderGraph.addPass(new BasePass(graphics, scene)); renderGraph.addPass(new BasePass(graphics, scene));
renderGraph.addPass(new DebugPass(graphics, scene)); renderGraph.addPass(new DebugPass(graphics, scene));
//renderGraph.addPass(new SkyboxRenderPass(graphics, scene)); //renderGraph.addPass(new SkyboxRenderPass(graphics, scene));
+1 -5
View File
@@ -1,11 +1,6 @@
#pragma once #pragma once
#include "Window/View.h" #include "Window/View.h"
#include "Scene/Scene.h" #include "Scene/Scene.h"
#include "Graphics/RenderPass/DepthPrepass.h"
#include "Graphics/RenderPass/LightCullingPass.h"
#include "Graphics/RenderPass/BasePass.h"
#include "Graphics/RenderPass/SkyboxRenderPass.h"
#include "Graphics/RenderPass/DebugPass.h"
#include "System/KeyboardInput.h" #include "System/KeyboardInput.h"
#ifdef WIN32 #ifdef WIN32
#include "Platform/Windows/GameInterface.h" // TODO #include "Platform/Windows/GameInterface.h" // TODO
@@ -28,6 +23,7 @@ public:
virtual void render() override; virtual void render() override;
void reloadGame(); void reloadGame();
protected: protected:
virtual void applyArea(URect rect) override; virtual void applyArea(URect rect) override;
OScene scene; OScene scene;