Rasterize works again

This commit is contained in:
Dynamitos
2024-05-22 19:20:30 +02:00
parent 520d327c1a
commit f6f45cbd6e
10 changed files with 64 additions and 38 deletions
+4 -1
View File
@@ -3,4 +3,7 @@
url = https://github.com/d-bahr/CRCpp.git url = https://github.com/d-bahr/CRCpp.git
[submodule "external/vcpkg"] [submodule "external/vcpkg"]
path = external/vcpkg path = external/vcpkg
url = https://github.com/Microsoft/vcpkg.git url = https://github.com/Microsoft/vcpkg.git
[submodule "external/slang"]
path = external/slang
url = https://github.com/shader-slang/slang.git
+1 -1
View File
@@ -95,7 +95,7 @@ target_compile_definitions(Editor PRIVATE EDITOR=1)
add_executable(AssetViewer "") add_executable(AssetViewer "")
target_link_libraries(AssetViewer PRIVATE Engine) target_link_libraries(AssetViewer PRIVATE Engine)
target_include_directories(AssetViewer PRIVATE src/AssetViewer) target_include_directories(AssetViewer PRIVATE src/AssetViewer)
if(MSVC) if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_WARNINGS)
target_compile_options(Engine PUBLIC /std:c++20 /Zi /MP14 /W4 /wd4505) target_compile_options(Engine PUBLIC /std:c++20 /Zi /MP14 /W4 /wd4505)
Vendored Submodule
+1
Submodule external/slang added at 52b5bb43fd
+1 -1
View File
@@ -7,7 +7,7 @@ import Scene;
FragmentParameter vertexMain( FragmentParameter vertexMain(
VertexInput input VertexInput input
){ ){
InstanceData inst = pScene.instances[pOffsets.instanceOffset + input.instanceId]; InstanceData inst = pScene.instances[input.instanceId];
VertexAttributes attr = pVertexData.getAttributes(input.vertexId); VertexAttributes attr = pVertexData.getAttributes(input.vertexId);
return attr.getParameter(inst.transformMatrix); return attr.getParameter(inst.transformMatrix);
} }
+2 -2
View File
@@ -18,8 +18,8 @@ void meshMain(
out vertices FragmentParameter vertices[MAX_VERTICES], out vertices FragmentParameter vertices[MAX_VERTICES],
out indices uint3 indices[MAX_PRIMITIVES] out indices uint3 indices[MAX_PRIMITIVES]
){ ){
InstanceData inst = meshPayload.instanceData; InstanceData inst = pScene.instanceData[meshPayload.instanceId];
MeshData data = meshPayload.meshData; MeshData data = pScene.meshData[meshPayload.instanceId];
MeshletDescription m = pScene.meshletInfos[data.meshletOffset + groupID]; MeshletDescription m = pScene.meshletInfos[data.meshletOffset + groupID];
SetMeshOutputCounts(m.vertexCount, m.primitiveCount); SetMeshOutputCounts(m.vertexCount, m.primitiveCount);
+1 -1
View File
@@ -9,7 +9,7 @@ groupshared Frustum viewFrustum;
[shader("amplification")] [shader("amplification")]
void taskMain( void taskMain(
uint threadID: SV_GroupIndex, uint threadID: SV_GroupIndex,
uint groupID: SV_GroupThreadID 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];
+1 -2
View File
@@ -53,8 +53,7 @@ ParameterBlock<Scene> pScene;
struct MeshPayload struct MeshPayload
{ {
InstanceData instanceData; uint instanceId;
MeshData meshData;
uint culledMeshlets[2048]; uint culledMeshlets[2048];
}; };
+34 -19
View File
@@ -124,28 +124,42 @@ void BasePass::render()
assert(collection != nullptr); assert(collection != nullptr);
if (graphics->supportMeshShading()) if (graphics->supportMeshShading())
{ {
Gfx::MeshPipelineCreateInfo pipelineInfo; Gfx::MeshPipelineCreateInfo pipelineInfo = {
pipelineInfo.taskShader = collection->taskShader; .taskShader = collection->taskShader,
pipelineInfo.meshShader = collection->meshShader; .meshShader = collection->meshShader,
pipelineInfo.fragmentShader = collection->fragmentShader; .fragmentShader = collection->fragmentShader,
pipelineInfo.pipelineLayout = collection->pipelineLayout; .renderPass = renderPass,
pipelineInfo.renderPass = renderPass; .pipelineLayout = collection->pipelineLayout,
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL; .multisampleState = {
pipelineInfo.multisampleState.samples = viewport->getSamples(); .samples = viewport->getSamples(),
pipelineInfo.colorBlend.attachmentCount = 2; },
.depthStencilState = {
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL,
},
.colorBlend = {
.attachmentCount = 2,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo)); Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline); command->bindPipeline(pipeline);
} }
else else
{ {
Gfx::LegacyPipelineCreateInfo pipelineInfo; Gfx::LegacyPipelineCreateInfo pipelineInfo = {
pipelineInfo.vertexShader = collection->vertexShader; .vertexShader = collection->vertexShader,
pipelineInfo.fragmentShader = collection->fragmentShader; .fragmentShader = collection->fragmentShader,
pipelineInfo.pipelineLayout = collection->pipelineLayout; .renderPass = renderPass,
pipelineInfo.renderPass = renderPass; .pipelineLayout = collection->pipelineLayout,
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL; .multisampleState = {
pipelineInfo.multisampleState.samples = viewport->getSamples(); .samples = viewport->getSamples(),
pipelineInfo.colorBlend.attachmentCount = 2; },
.depthStencilState = {
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL,
},
.colorBlend = {
.attachmentCount = 2,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo)); Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline); command->bindPipeline(pipeline);
} }
@@ -154,9 +168,9 @@ void BasePass::render()
command->bindDescriptor(scene->getLightEnvironment()->getDescriptorSet()); command->bindDescriptor(scene->getLightEnvironment()->getDescriptorSet());
command->bindDescriptor(opaqueCulling); command->bindDescriptor(opaqueCulling);
command->bindDescriptor(vertexData->getInstanceDataSet()); command->bindDescriptor(vertexData->getInstanceDataSet());
command->bindDescriptor(vertexData->getInstanceDataSet());
for (const auto& drawCall : materialData.instances) for (const auto& drawCall : materialData.instances)
{ {
command->bindDescriptor(vertexData->getInstanceDataSet());
command->bindDescriptor(drawCall.materialInstance->getDescriptorSet()); command->bindDescriptor(drawCall.materialInstance->getDescriptorSet());
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets), &drawCall.offsets); 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())
@@ -166,10 +180,11 @@ 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), 0); command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, vertexData->getIndicesOffset(meshData.meshletOffset), inst++);
} }
} }
} }
+18 -10
View File
@@ -101,22 +101,29 @@ void DepthPrepass::render()
} }
else else
{ {
Gfx::LegacyPipelineCreateInfo pipelineInfo; Gfx::LegacyPipelineCreateInfo pipelineInfo = {
pipelineInfo.vertexShader = collection->vertexShader; .vertexShader = collection->vertexShader,
pipelineInfo.fragmentShader = collection->fragmentShader; .fragmentShader = collection->fragmentShader,
pipelineInfo.pipelineLayout = collection->pipelineLayout; .renderPass = renderPass,
pipelineInfo.renderPass = renderPass; .pipelineLayout = collection->pipelineLayout,
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER; .multisampleState = {
pipelineInfo.multisampleState.samples = viewport->getSamples(); .samples = viewport->getSamples(),
pipelineInfo.colorBlend.attachmentCount = 1; },
.depthStencilState = {
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
},
.colorBlend = {
.attachmentCount = 1,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo)); Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline); command->bindPipeline(pipeline);
} }
command->bindDescriptor(vertexData->getVertexDataSet()); command->bindDescriptor(vertexData->getVertexDataSet());
command->bindDescriptor(viewParamsSet); command->bindDescriptor(viewParamsSet);
command->bindDescriptor(vertexData->getInstanceDataSet());
for (const auto& drawCall : materialData.instances) for (const auto& drawCall : materialData.instances)
{ {
command->bindDescriptor(vertexData->getInstanceDataSet());
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets), &drawCall.offsets); 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())
{ {
@@ -125,10 +132,11 @@ void DepthPrepass::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), 0); command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, vertexData->getIndicesOffset(meshData.meshletOffset), inst++);
} }
} }
} }
+1 -1
View File
@@ -60,6 +60,7 @@ void VertexData::updateMesh(PMesh mesh, Component::Transform& transform)
}); });
const auto& data = meshData[mesh->id]; const auto& data = meshData[mesh->id];
matInstanceData.instanceMeshData.add(data); matInstanceData.instanceMeshData.add(data);
referencedInstance->updateDescriptor();
for (size_t i = 0; i < 0; ++i) for (size_t i = 0; i < 0; ++i)
{ {
auto bounding = meshlets[data.meshletOffset + i].bounding; auto bounding = meshlets[data.meshletOffset + i].bounding;
@@ -100,7 +101,6 @@ void VertexData::updateMesh(PMesh mesh, Component::Transform& transform)
addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color }); addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color });
} }
referencedInstance->updateDescriptor();
} }
void VertexData::createDescriptors() void VertexData::createDescriptors()