diff --git a/combined.png b/combined.png deleted file mode 100644 index d2cf431..0000000 Binary files a/combined.png and /dev/null differ diff --git a/res/shaders/DrawListTask.slang b/res/shaders/DrawListTask.slang index a9ea9a9..f3b10d6 100644 --- a/res/shaders/DrawListTask.slang +++ b/res/shaders/DrawListTask.slang @@ -26,9 +26,7 @@ void taskMain( uint cull = p.cullingOffset + i; MeshletDescription meshlet = pScene.meshletInfos[m]; MeshletCullingInfo culling = pScene.cullingInfos[cull]; -#ifdef DEPTH_CULLING if(culling.wasVisible()) -#endif { uint index; InterlockedAdd(head, 1, index); diff --git a/res/shaders/lib/Bounding.slang b/res/shaders/lib/Bounding.slang index b849cc3..2567001 100644 --- a/res/shaders/lib/Bounding.slang +++ b/res/shaders/lib/Bounding.slang @@ -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))); screenCornerMin = int2(min(screenCornerMin.x, screenCoords.x), min(screenCornerMin.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; } diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index 2c88337..d22754b 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -72,10 +72,10 @@ int main() { .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb", .importPath = "Whitechapel", }); - // AssetImporter::importMesh(MeshImportArgs{ - // .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj", - // .importPath = "suburbs", - // }); + //AssetImporter::importMesh(MeshImportArgs{ + // .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj", + // .importPath = "suburbs", + //}); getThreadPool().waitIdle(); vd->commitMeshes(); WindowCreateInfo mainWindowInfo = { diff --git a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp index fabaf19..7aaffff 100644 --- a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp @@ -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_COMPUTE_SHADER_BIT); - //uint32 reset = 0; - //debugHead->updateContents(0, sizeof(uint32), &reset); - + depthMipBuffer->rotateBuffer(depthMipBuffer->getNumElements() * sizeof(uint32)); Gfx::PDescriptorSet set = depthAttachmentLayout->allocateDescriptorSet(); - //set->updateBuffer(0, debugUniform); set->updateTexture(0, Gfx::PTexture2D(depthAttachment.getTexture())); set->updateBuffer(1, depthMipBuffer); - //set->updateBuffer(3, debugHead); - //set->updateBuffer(4, debugData); set->writeChanges(); timestamps->begin(); 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->bindDescriptor({viewParamsSet, set}); UVector2 reduceDimensions = UVector2(viewport->getOwner()->getFramebufferWidth() + BLOCK_SIZE - 1, viewport->getOwner()->getFramebufferHeight() + BLOCK_SIZE - 1) / uint32(BLOCK_SIZE); computeCommand->dispatch(reduceDimensions.x, reduceDimensions.y, 1); - - computeCommand->bindPipeline(depthMipGen); - computeCommand->bindDescriptor({viewParamsSet, set}); + graphics->executeCommands(std::move(computeCommand)); for (uint32 i = 0; i < mipOffsets.size() - 1; ++i) { 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_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + Gfx::OComputeCommand mipCommand = graphics->createComputeCommand(fmt::format("MipGenLevel{0}", i)); + mipCommand->bindPipeline(depthMipGen); + mipCommand->bindDescriptor({viewParamsSet, set}); MipParam params = { .srcMipOffset = mipOffsets[i], .dstMipOffset = mipOffsets[i + 1], .srcMipDim = mipDims[i], .dstMipDim = mipDims[i + 1], }; - computeCommand->pushConstants(Gfx::SE_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(MipParam), ¶ms); - UVector2 threadGroups = (((mipDims[i] + UVector2(1, 1)) / 2u) + UVector2(BLOCK_SIZE - 1, BLOCK_SIZE - 1)) / uint32(BLOCK_SIZE); - computeCommand->dispatch(threadGroups.x, threadGroups.y, 1); + mipCommand->pushConstants(Gfx::SE_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(MipParam), ¶ms); + UVector2 threadGroups = (reduceDimensions + 1u) / 2u; + mipCommand->dispatch(threadGroups.x, threadGroups.y, 1); + graphics->executeCommands(std::move(mipCommand)); } - Array 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, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT); @@ -141,7 +135,7 @@ void DepthCullingPass::render() { Array commands; Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("DepthPass"); - permutation.setPositionOnly(getGlobals().usePositionOnly); + permutation.setPositionOnly(true); permutation.setDepthCulling(getGlobals().useDepthCulling); for (VertexData* vertexData : VertexData::getList()) { permutation.setVertexData(vertexData->getTypeName()); @@ -238,35 +232,10 @@ void DepthCullingPass::publishOutputs() { mipOffsets.add(bufferSize); mipDims.add(UVector2(width, height)); bufferSize += width * height; - width = std::max((width + 1) / 2, 1u); - height = std::max((height + 1) / 2, 1u); + width = (width + 1) / 2; + 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{ .sourceData = { @@ -274,6 +243,9 @@ void DepthCullingPass::publishOutputs() { .data = nullptr, }, .numElements = bufferSize, + .clearValue = 0, + .createCleared = true, + .dynamic = true, .name = "DepthMipBuffer", }); diff --git a/src/Engine/Graphics/RenderPass/DepthCullingPass.h b/src/Engine/Graphics/RenderPass/DepthCullingPass.h index 518cf2f..a0f94a4 100644 --- a/src/Engine/Graphics/RenderPass/DepthCullingPass.h +++ b/src/Engine/Graphics/RenderPass/DepthCullingPass.h @@ -26,16 +26,9 @@ class DepthCullingPass : public RenderPass { UVector2 dstMipDim; }; - struct DepthDebugData { - uint32 mipLevel; - uint32 mipOffset; - UVector2 mipDimensions; - UVector2 screenCornerMin; - UVector2 screenCornerMax; - }; - Array mipOffsets; Array mipDims; + Gfx::OShaderBuffer depthMipBuffer; Gfx::RenderTargetAttachment depthAttachment; Gfx::RenderTargetAttachment visibilityAttachment; @@ -49,11 +42,7 @@ class DepthCullingPass : public RenderPass { Gfx::PComputePipeline depthInitialReduce; Gfx::OComputeShader depthMipGenShader; Gfx::PComputePipeline depthMipGen; - - //Gfx::OUniformBuffer debugUniform; - //Gfx::OShaderBuffer debugHead; - //Gfx::OShaderBuffer debugData; - + Gfx::PShaderBuffer cullingBuffer; }; DEFINE_REF(DepthCullingPass) diff --git a/src/Engine/Graphics/RenderPass/WaterRenderer.cpp b/src/Engine/Graphics/RenderPass/WaterRenderer.cpp index 5e2c711..d89233e 100644 --- a/src/Engine/Graphics/RenderPass/WaterRenderer.cpp +++ b/src/Engine/Graphics/RenderPass/WaterRenderer.cpp @@ -174,7 +174,7 @@ WaterRenderer::WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescri {"CS_AssembleMaps", "WaterCompute"}, }, .rootSignature = pipelineLayout, - .dumpIntermediate = true, + .dumpIntermediate = false, }; graphics->beginShaderCompilation(info); initSpectrumCS = graphics->createComputeShader({0});