Hopefully fixed culling now

This commit is contained in:
Dynamitos
2024-08-31 13:29:33 +02:00
parent 88eacd067e
commit d7aefc07f3
7 changed files with 24 additions and 65 deletions
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

-2
View File
@@ -26,9 +26,7 @@ void taskMain(
uint cull = p.cullingOffset + i; uint cull = p.cullingOffset + i;
MeshletDescription meshlet = pScene.meshletInfos[m]; MeshletDescription meshlet = pScene.meshletInfos[m];
MeshletCullingInfo culling = pScene.cullingInfos[cull]; MeshletCullingInfo culling = pScene.cullingInfos[cull];
#ifdef DEPTH_CULLING
if(culling.wasVisible()) if(culling.wasVisible())
#endif
{ {
uint index; uint index;
InterlockedAdd(head, 1, index); InterlockedAdd(head, 1, index);
+1 -1
View File
@@ -70,7 +70,7 @@ struct AABB
int2 screenCoords = int2(clamp(int(screenCorner.x), 0, int(pViewParams.screenDimensions.x)), clamp(int(screenCorner.y), 0, int(pViewParams.screenDimensions.y))); int2 screenCoords = int2(clamp(int(screenCorner.x), 0, int(pViewParams.screenDimensions.x)), clamp(int(screenCorner.y), 0, int(pViewParams.screenDimensions.y)));
screenCornerMin = int2(min(screenCornerMin.x, screenCoords.x), min(screenCornerMin.y, screenCoords.y)); screenCornerMin = int2(min(screenCornerMin.x, screenCoords.x), min(screenCornerMin.y, screenCoords.y));
screenCornerMax = int2(max(screenCornerMax.x, screenCoords.x), max(screenCornerMax.y, screenCoords.y)); screenCornerMax = int2(max(screenCornerMax.x, screenCoords.x), max(screenCornerMax.y, screenCoords.y));
maxDepth = max(maxDepth, screenCorner.z); maxDepth = max(maxDepth, 1/screenCorner.z);
} }
return maxDepth; return maxDepth;
} }
+2 -2
View File
@@ -72,10 +72,10 @@ int main() {
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb", .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
.importPath = "Whitechapel", .importPath = "Whitechapel",
}); });
// AssetImporter::importMesh(MeshImportArgs{ //AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj", // .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
// .importPath = "suburbs", // .importPath = "suburbs",
// }); //});
getThreadPool().waitIdle(); getThreadPool().waitIdle();
vd->commitMeshes(); vd->commitMeshes();
WindowCreateInfo mainWindowInfo = { WindowCreateInfo mainWindowInfo = {
@@ -87,47 +87,41 @@ void DepthCullingPass::render() {
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
//uint32 reset = 0; depthMipBuffer->rotateBuffer(depthMipBuffer->getNumElements() * sizeof(uint32));
//debugHead->updateContents(0, sizeof(uint32), &reset);
Gfx::PDescriptorSet set = depthAttachmentLayout->allocateDescriptorSet(); Gfx::PDescriptorSet set = depthAttachmentLayout->allocateDescriptorSet();
//set->updateBuffer(0, debugUniform);
set->updateTexture(0, Gfx::PTexture2D(depthAttachment.getTexture())); set->updateTexture(0, Gfx::PTexture2D(depthAttachment.getTexture()));
set->updateBuffer(1, depthMipBuffer); set->updateBuffer(1, depthMipBuffer);
//set->updateBuffer(3, debugHead);
//set->updateBuffer(4, debugData);
set->writeChanges(); set->writeChanges();
timestamps->begin(); timestamps->begin();
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "MipBegin"); timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "MipBegin");
Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("DepthMipGenCommand"); Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("InitialReduce");
computeCommand->bindPipeline(depthInitialReduce); computeCommand->bindPipeline(depthInitialReduce);
computeCommand->bindDescriptor({viewParamsSet, set}); computeCommand->bindDescriptor({viewParamsSet, set});
UVector2 reduceDimensions = UVector2(viewport->getOwner()->getFramebufferWidth() + BLOCK_SIZE - 1, UVector2 reduceDimensions = UVector2(viewport->getOwner()->getFramebufferWidth() + BLOCK_SIZE - 1,
viewport->getOwner()->getFramebufferHeight() + BLOCK_SIZE - 1) / viewport->getOwner()->getFramebufferHeight() + BLOCK_SIZE - 1) /
uint32(BLOCK_SIZE); uint32(BLOCK_SIZE);
computeCommand->dispatch(reduceDimensions.x, reduceDimensions.y, 1); computeCommand->dispatch(reduceDimensions.x, reduceDimensions.y, 1);
graphics->executeCommands(std::move(computeCommand));
computeCommand->bindPipeline(depthMipGen);
computeCommand->bindDescriptor({viewParamsSet, set});
for (uint32 i = 0; i < mipOffsets.size() - 1; ++i) { for (uint32 i = 0; i < mipOffsets.size() - 1; ++i) {
depthMipBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, depthMipBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
Gfx::OComputeCommand mipCommand = graphics->createComputeCommand(fmt::format("MipGenLevel{0}", i));
mipCommand->bindPipeline(depthMipGen);
mipCommand->bindDescriptor({viewParamsSet, set});
MipParam params = { MipParam params = {
.srcMipOffset = mipOffsets[i], .srcMipOffset = mipOffsets[i],
.dstMipOffset = mipOffsets[i + 1], .dstMipOffset = mipOffsets[i + 1],
.srcMipDim = mipDims[i], .srcMipDim = mipDims[i],
.dstMipDim = mipDims[i + 1], .dstMipDim = mipDims[i + 1],
}; };
computeCommand->pushConstants(Gfx::SE_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(MipParam), &params); mipCommand->pushConstants(Gfx::SE_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(MipParam), &params);
UVector2 threadGroups = (((mipDims[i] + UVector2(1, 1)) / 2u) + UVector2(BLOCK_SIZE - 1, BLOCK_SIZE - 1)) / uint32(BLOCK_SIZE); UVector2 threadGroups = (reduceDimensions + 1u) / 2u;
computeCommand->dispatch(threadGroups.x, threadGroups.y, 1); mipCommand->dispatch(threadGroups.x, threadGroups.y, 1);
graphics->executeCommands(std::move(mipCommand));
} }
Array<Gfx::OComputeCommand> computeCommands;
computeCommands.add(std::move(computeCommand));
graphics->executeCommands(std::move(computeCommands));
depthMipBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, depthMipBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT); Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT);
@@ -141,7 +135,7 @@ void DepthCullingPass::render() {
Array<Gfx::ORenderCommand> commands; Array<Gfx::ORenderCommand> commands;
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("DepthPass"); Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("DepthPass");
permutation.setPositionOnly(getGlobals().usePositionOnly); permutation.setPositionOnly(true);
permutation.setDepthCulling(getGlobals().useDepthCulling); permutation.setDepthCulling(getGlobals().useDepthCulling);
for (VertexData* vertexData : VertexData::getList()) { for (VertexData* vertexData : VertexData::getList()) {
permutation.setVertexData(vertexData->getTypeName()); permutation.setVertexData(vertexData->getTypeName());
@@ -238,35 +232,10 @@ void DepthCullingPass::publishOutputs() {
mipOffsets.add(bufferSize); mipOffsets.add(bufferSize);
mipDims.add(UVector2(width, height)); mipDims.add(UVector2(width, height));
bufferSize += width * height; bufferSize += width * height;
width = std::max((width + 1) / 2, 1u); width = (width + 1) / 2;
height = std::max((height + 1) / 2, 1u); height = (height + 1) / 2;
} }
//debugUniform = graphics->createUniformBuffer(UniformBufferCreateInfo{
// .sourceData =
// {
// .size = sizeof(uint32),
// .data = (uint8*)&bufferSize,
// },
//});
//uint32 reset = 0;
//debugHead = graphics->createShaderBuffer(ShaderBufferCreateInfo{
// .sourceData =
// {
// .size = sizeof(uint32),
// .data = (uint8*)&reset,
// },
//
//});
//debugData = graphics->createShaderBuffer(ShaderBufferCreateInfo{
// .sourceData =
// {
// .size = sizeof(DepthDebugData) * 10000,
// .data = nullptr,
// },
//});
//graphics->waitDeviceIdle();
depthMipBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ depthMipBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = .sourceData =
{ {
@@ -274,6 +243,9 @@ void DepthCullingPass::publishOutputs() {
.data = nullptr, .data = nullptr,
}, },
.numElements = bufferSize, .numElements = bufferSize,
.clearValue = 0,
.createCleared = true,
.dynamic = true,
.name = "DepthMipBuffer", .name = "DepthMipBuffer",
}); });
@@ -26,16 +26,9 @@ class DepthCullingPass : public RenderPass {
UVector2 dstMipDim; UVector2 dstMipDim;
}; };
struct DepthDebugData {
uint32 mipLevel;
uint32 mipOffset;
UVector2 mipDimensions;
UVector2 screenCornerMin;
UVector2 screenCornerMax;
};
Array<uint32> mipOffsets; Array<uint32> mipOffsets;
Array<UVector2> mipDims; Array<UVector2> mipDims;
Gfx::OShaderBuffer depthMipBuffer; Gfx::OShaderBuffer depthMipBuffer;
Gfx::RenderTargetAttachment depthAttachment; Gfx::RenderTargetAttachment depthAttachment;
Gfx::RenderTargetAttachment visibilityAttachment; Gfx::RenderTargetAttachment visibilityAttachment;
@@ -50,10 +43,6 @@ class DepthCullingPass : public RenderPass {
Gfx::OComputeShader depthMipGenShader; Gfx::OComputeShader depthMipGenShader;
Gfx::PComputePipeline depthMipGen; Gfx::PComputePipeline depthMipGen;
//Gfx::OUniformBuffer debugUniform;
//Gfx::OShaderBuffer debugHead;
//Gfx::OShaderBuffer debugData;
Gfx::PShaderBuffer cullingBuffer; Gfx::PShaderBuffer cullingBuffer;
}; };
DEFINE_REF(DepthCullingPass) DEFINE_REF(DepthCullingPass)
@@ -174,7 +174,7 @@ WaterRenderer::WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescri
{"CS_AssembleMaps", "WaterCompute"}, {"CS_AssembleMaps", "WaterCompute"},
}, },
.rootSignature = pipelineLayout, .rootSignature = pipelineLayout,
.dumpIntermediate = true, .dumpIntermediate = false,
}; };
graphics->beginShaderCompilation(info); graphics->beginShaderCompilation(info);
initSpectrumCS = graphics->createComputeShader({0}); initSpectrumCS = graphics->createComputeShader({0});