diff --git a/.vscode/launch.json b/.vscode/launch.json index 79b4d89..1c92f67 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -27,7 +27,7 @@ }, { "name": "Editor (Linux)", - "type": "cppdbg", + "type": "lldb", "request": "launch", "program": "${workspaceRoot}/build/Editor", "args": [], diff --git a/res/shaders/fluid/SignedDistance.slang b/res/shaders/fluid/SignedDistance.slang index 0637dec..cbc847a 100644 --- a/res/shaders/fluid/SignedDistance.slang +++ b/res/shaders/fluid/SignedDistance.slang @@ -31,17 +31,17 @@ void reinitialize(uint3 dispatchThreadID : SV_DispatchThreadID) float dx = 1.0f; // Current value and original sign - float p = phi[x, y, z]; + float p = phi0[x, y, z]; float s = smoothSign(phi0[x, y, z], dx); - // Upwind finite differences for |grad phi| + // Upwind finite differences for |grad phi| — read from snapshot to avoid race // Forward and backward differences - float dxp = phi[x + 1, y, z] - p; - float dxm = p - phi[x - 1, y, z]; - float dyp = phi[x, y + 1, z] - p; - float dym = p - phi[x, y - 1, z]; - float dzp = phi[x, y, z + 1] - p; - float dzm = p - phi[x, y, z - 1]; + float dxp = phi0[x + 1, y, z] - p; + float dxm = p - phi0[x - 1, y, z]; + float dyp = phi0[x, y + 1, z] - p; + float dym = p - phi0[x, y - 1, z]; + float dzp = phi0[x, y, z + 1] - p; + float dzm = p - phi0[x, y, z - 1]; // Godunov upwind scheme float gradPhi; diff --git a/src/Engine/Graphics/RenderPass/SimulationComputePass.cpp b/src/Engine/Graphics/RenderPass/SimulationComputePass.cpp index 63fc77f..8661e33 100644 --- a/src/Engine/Graphics/RenderPass/SimulationComputePass.cpp +++ b/src/Engine/Graphics/RenderPass/SimulationComputePass.cpp @@ -350,6 +350,11 @@ void SimulationComputePass::render() { Gfx::PShaderBuffer pressureNext = data.velocityZBuffer; divergencePass(divergence, pressureCurrent, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, data.gridSize); + // Divergence/pressure buffers are aliased to velocity buffers whose boundary + // cells still contain stale velocity data. Zero the boundaries before solving. + setBoundsPass(divergence, 0, data.gridSize); + setBoundsPass(pressureCurrent, 0, data.gridSize); + for (int iteration = 0; iteration < pressureSolveIterations; ++iteration) { linearSolvePass(pressureNext, pressureCurrent, divergence, 1, 6, data.gridSize); @@ -388,6 +393,9 @@ void SimulationComputePass::render() { Gfx::PShaderBuffer advectedPressureCurrent = data.velocityYNextBuffer; Gfx::PShaderBuffer advectedPressureNext = data.velocityZNextBuffer; divergencePass(advectedDivergence, advectedPressureCurrent, data.velocityXBuffer, data.velocityYBuffer, data.velocityZBuffer, data.gridSize); + setBoundsPass(advectedDivergence, 0, data.gridSize); + setBoundsPass(advectedPressureCurrent, 0, data.gridSize); + for (int iteration = 0; iteration < pressureSolveIterations; ++iteration) { linearSolvePass(advectedPressureNext, advectedPressureCurrent, advectedDivergence, 1, 6, data.gridSize); setBoundsPass(advectedPressureNext, 0, data.gridSize); diff --git a/vcpkg.json b/vcpkg.json index e44e6aa..68f0d3f 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,5 +1,6 @@ { "dependencies": [ + "vulkan", { "name": "vulkan-memory-allocator" },