|
|
|
@@ -7,13 +7,18 @@
|
|
|
|
|
#include "Graphics/Initializer.h"
|
|
|
|
|
#include "Graphics/Shader.h"
|
|
|
|
|
#include "Math/Vector.h"
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include "Scene/FluidScene.h"
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
|
|
|
|
constexpr static int reinitInterval = 5;
|
|
|
|
|
constexpr static int reinitIterations = 5;
|
|
|
|
|
constexpr static float reinitDtau = 0.5f;
|
|
|
|
|
// Reinitialization is in pseudo-time; keep it gentle to avoid eroding the interface each frame.
|
|
|
|
|
constexpr static int reinitInterval = 20;
|
|
|
|
|
constexpr static int reinitIterations = 1;
|
|
|
|
|
constexpr static float reinitDtau = 0.05f;
|
|
|
|
|
constexpr static int velocityDiffuseIterations = 8;
|
|
|
|
|
constexpr static int pressureSolveIterations = 24;
|
|
|
|
|
constexpr static int densityDiffuseIterations = 8;
|
|
|
|
|
|
|
|
|
|
#define SWAP(a, b) \
|
|
|
|
|
{ \
|
|
|
|
@@ -23,6 +28,12 @@ constexpr static float reinitDtau = 0.5f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SimulationComputePass::SimulationComputePass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics), scene(scene) {
|
|
|
|
|
gridSizeLayout = graphics->createDescriptorLayout("gridParams");
|
|
|
|
|
gridSizeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
|
|
|
|
.name = "gridSize",
|
|
|
|
|
.uniformLength = sizeof(UVector),
|
|
|
|
|
});
|
|
|
|
|
gridSizeLayout->create();
|
|
|
|
|
{
|
|
|
|
|
setBounds.pipelineLayout = graphics->createPipelineLayout("SetBoundsPipelineLayout");
|
|
|
|
|
setBounds.descriptorLayout = graphics->createDescriptorLayout("params");
|
|
|
|
@@ -36,6 +47,7 @@ SimulationComputePass::SimulationComputePass(Gfx::PGraphics graphics, PScene sce
|
|
|
|
|
});
|
|
|
|
|
setBounds.descriptorLayout->create();
|
|
|
|
|
setBounds.pipelineLayout->addDescriptorLayout(setBounds.descriptorLayout);
|
|
|
|
|
setBounds.pipelineLayout->addDescriptorLayout(gridSizeLayout);
|
|
|
|
|
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
|
|
|
|
.name = "SetBound",
|
|
|
|
|
.modules = {"SetBound"},
|
|
|
|
@@ -84,6 +96,7 @@ SimulationComputePass::SimulationComputePass(Gfx::PGraphics graphics, PScene sce
|
|
|
|
|
});
|
|
|
|
|
linearSolve.descriptorLayout->create();
|
|
|
|
|
linearSolve.pipelineLayout->addDescriptorLayout(linearSolve.descriptorLayout);
|
|
|
|
|
linearSolve.pipelineLayout->addDescriptorLayout(gridSizeLayout);
|
|
|
|
|
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
|
|
|
|
.name = "LinearSolve",
|
|
|
|
|
.modules = {"LinearSolve"},
|
|
|
|
@@ -122,6 +135,7 @@ SimulationComputePass::SimulationComputePass(Gfx::PGraphics graphics, PScene sce
|
|
|
|
|
});
|
|
|
|
|
computeDivergence.descriptorLayout->create();
|
|
|
|
|
computeDivergence.pipelineLayout->addDescriptorLayout(computeDivergence.descriptorLayout);
|
|
|
|
|
computeDivergence.pipelineLayout->addDescriptorLayout(gridSizeLayout);
|
|
|
|
|
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
|
|
|
|
.name = "Divergence",
|
|
|
|
|
.modules = {"Divergence"},
|
|
|
|
@@ -157,6 +171,7 @@ SimulationComputePass::SimulationComputePass(Gfx::PGraphics graphics, PScene sce
|
|
|
|
|
});
|
|
|
|
|
project.descriptorLayout->create();
|
|
|
|
|
project.pipelineLayout->addDescriptorLayout(project.descriptorLayout);
|
|
|
|
|
project.pipelineLayout->addDescriptorLayout(gridSizeLayout);
|
|
|
|
|
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
|
|
|
|
.name = "Project",
|
|
|
|
|
.modules = {"Project"},
|
|
|
|
@@ -199,6 +214,7 @@ SimulationComputePass::SimulationComputePass(Gfx::PGraphics graphics, PScene sce
|
|
|
|
|
});
|
|
|
|
|
advect.descriptorLayout->create();
|
|
|
|
|
advect.pipelineLayout->addDescriptorLayout(advect.descriptorLayout);
|
|
|
|
|
advect.pipelineLayout->addDescriptorLayout(gridSizeLayout);
|
|
|
|
|
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
|
|
|
|
.name = "Advect",
|
|
|
|
|
.modules = {"Advect"},
|
|
|
|
@@ -230,7 +246,7 @@ SimulationComputePass::SimulationComputePass(Gfx::PGraphics graphics, PScene sce
|
|
|
|
|
});
|
|
|
|
|
reinitialize.descriptorLayout->create();
|
|
|
|
|
reinitialize.pipelineLayout->addDescriptorLayout(reinitialize.descriptorLayout);
|
|
|
|
|
|
|
|
|
|
reinitialize.pipelineLayout->addDescriptorLayout(gridSizeLayout);
|
|
|
|
|
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
|
|
|
|
.name = "SignedDistance",
|
|
|
|
|
.modules = {"SignedDistance"},
|
|
|
|
@@ -244,6 +260,45 @@ SimulationComputePass::SimulationComputePass(Gfx::PGraphics graphics, PScene sce
|
|
|
|
|
.pipelineLayout = reinitialize.pipelineLayout,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
applyForces.pipelineLayout = graphics->createPipelineLayout("ApplyForcesPipelineLayout");
|
|
|
|
|
applyForces.descriptorLayout = graphics->createDescriptorLayout("params");
|
|
|
|
|
applyForces.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
|
|
|
|
.name = "velocityX",
|
|
|
|
|
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
|
|
|
|
});
|
|
|
|
|
applyForces.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
|
|
|
|
.name = "velocityY",
|
|
|
|
|
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
|
|
|
|
});
|
|
|
|
|
applyForces.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
|
|
|
|
.name = "velocityZ",
|
|
|
|
|
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
|
|
|
|
});
|
|
|
|
|
applyForces.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
|
|
|
|
.name = "force",
|
|
|
|
|
.uniformLength = sizeof(Vector),
|
|
|
|
|
});
|
|
|
|
|
applyForces.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
|
|
|
|
.name = "dt",
|
|
|
|
|
.uniformLength = sizeof(float),
|
|
|
|
|
});
|
|
|
|
|
applyForces.descriptorLayout->create();
|
|
|
|
|
applyForces.pipelineLayout->addDescriptorLayout(applyForces.descriptorLayout);
|
|
|
|
|
applyForces.pipelineLayout->addDescriptorLayout(gridSizeLayout);
|
|
|
|
|
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
|
|
|
|
.name = "ApplyForces",
|
|
|
|
|
.modules = {"ApplyForces"},
|
|
|
|
|
.entryPoints = {{"applyForces", "ApplyForces"}},
|
|
|
|
|
.rootSignature = applyForces.pipelineLayout,
|
|
|
|
|
});
|
|
|
|
|
applyForces.pipelineLayout->create();
|
|
|
|
|
applyForces.shader = graphics->createComputeShader({0});
|
|
|
|
|
applyForces.pipeline = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
|
|
|
|
|
.computeShader = applyForces.shader,
|
|
|
|
|
.pipelineLayout = applyForces.pipelineLayout,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SimulationComputePass::~SimulationComputePass() {}
|
|
|
|
@@ -255,13 +310,21 @@ void SimulationComputePass::beginFrame(const Seele::Component::Camera&, const Se
|
|
|
|
|
project.descriptorLayout->reset();
|
|
|
|
|
advect.descriptorLayout->reset();
|
|
|
|
|
reinitialize.descriptorLayout->reset();
|
|
|
|
|
applyForces.descriptorLayout->reset();
|
|
|
|
|
gridSizeLayout->reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SimulationComputePass::render() {
|
|
|
|
|
for (auto& [entityID, data] : scene->getFluidScene()->getFluidDataMap()) {
|
|
|
|
|
if (data.paused) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
gridSizeSet = gridSizeLayout->allocateDescriptorSet();
|
|
|
|
|
gridSizeSet->updateConstants("gridSize", 0, &data.gridSize);
|
|
|
|
|
gridSizeSet->writeChanges();
|
|
|
|
|
graphics->beginDebugRegion("Diffuse");
|
|
|
|
|
for (uint iteration = 0; iteration < 4; ++iteration) {
|
|
|
|
|
float a = dt * data.viscosity * (data.gridSize.x - 2) * (data.gridSize.y - 2) * (data.gridSize.z - 2);
|
|
|
|
|
for (int iteration = 0; iteration < velocityDiffuseIterations; ++iteration) {
|
|
|
|
|
float a = data.dt * data.viscosity * (data.gridSize.x - 2) * (data.gridSize.x - 2);
|
|
|
|
|
float c = 1 + 6 * a;
|
|
|
|
|
linearSolvePass(data.velocityXNextBuffer, data.velocityXBuffer, data.velocityX0Buffer, a, c, data.gridSize);
|
|
|
|
|
linearSolvePass(data.velocityYNextBuffer, data.velocityYBuffer, data.velocityY0Buffer, a, c, data.gridSize);
|
|
|
|
@@ -287,7 +350,7 @@ void SimulationComputePass::render() {
|
|
|
|
|
Gfx::PShaderBuffer pressureNext = data.velocityZBuffer;
|
|
|
|
|
divergencePass(divergence, pressureCurrent, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, data.gridSize);
|
|
|
|
|
|
|
|
|
|
for (int iteration = 0; iteration < 4; ++iteration) {
|
|
|
|
|
for (int iteration = 0; iteration < pressureSolveIterations; ++iteration) {
|
|
|
|
|
linearSolvePass(pressureNext, pressureCurrent, divergence, 1, 6, data.gridSize);
|
|
|
|
|
|
|
|
|
|
setBoundsPass(pressureNext, 0, data.gridSize);
|
|
|
|
@@ -304,15 +367,38 @@ void SimulationComputePass::render() {
|
|
|
|
|
graphics->endDebugRegion();
|
|
|
|
|
|
|
|
|
|
graphics->beginDebugRegion("Advect");
|
|
|
|
|
advectPass(data.velocityXBuffer, data.velocityX0Buffer, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, dt, data.gridSize);
|
|
|
|
|
advectPass(data.velocityYBuffer, data.velocityY0Buffer, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, dt, data.gridSize);
|
|
|
|
|
advectPass(data.velocityZBuffer, data.velocityZ0Buffer, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, dt, data.gridSize);
|
|
|
|
|
advectPass(data.velocityXBuffer, data.velocityX0Buffer, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, data.dt,
|
|
|
|
|
data.gridSize);
|
|
|
|
|
advectPass(data.velocityYBuffer, data.velocityY0Buffer, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, data.dt,
|
|
|
|
|
data.gridSize);
|
|
|
|
|
advectPass(data.velocityZBuffer, data.velocityZ0Buffer, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, data.dt,
|
|
|
|
|
data.gridSize);
|
|
|
|
|
|
|
|
|
|
if (data.enableGravity) {
|
|
|
|
|
applyForcesPass(data.velocityXBuffer, data.velocityYBuffer, data.velocityZBuffer, data.gravity, data.dt, data.gridSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set boundary conditions after advection/forces so the divergence sees correct wall values
|
|
|
|
|
setBoundsPass(data.velocityXBuffer, 1, data.gridSize);
|
|
|
|
|
setBoundsPass(data.velocityYBuffer, 2, data.gridSize);
|
|
|
|
|
setBoundsPass(data.velocityZBuffer, 3, data.gridSize);
|
|
|
|
|
|
|
|
|
|
// Re-project after advection/forces to keep the final velocity field divergence-free.
|
|
|
|
|
Gfx::PShaderBuffer advectedDivergence = data.velocityXNextBuffer;
|
|
|
|
|
Gfx::PShaderBuffer advectedPressureCurrent = data.velocityYNextBuffer;
|
|
|
|
|
Gfx::PShaderBuffer advectedPressureNext = data.velocityZNextBuffer;
|
|
|
|
|
divergencePass(advectedDivergence, advectedPressureCurrent, data.velocityXBuffer, data.velocityYBuffer, data.velocityZBuffer, data.gridSize);
|
|
|
|
|
for (int iteration = 0; iteration < pressureSolveIterations; ++iteration) {
|
|
|
|
|
linearSolvePass(advectedPressureNext, advectedPressureCurrent, advectedDivergence, 1, 6, data.gridSize);
|
|
|
|
|
setBoundsPass(advectedPressureNext, 0, data.gridSize);
|
|
|
|
|
SWAP(advectedPressureCurrent, advectedPressureNext);
|
|
|
|
|
}
|
|
|
|
|
projectPass(data.velocityXBuffer, data.velocityYBuffer, data.velocityZBuffer, advectedPressureCurrent, data.gridSize);
|
|
|
|
|
|
|
|
|
|
setBoundsPass(data.velocityXBuffer, 1, data.gridSize);
|
|
|
|
|
setBoundsPass(data.velocityYBuffer, 2, data.gridSize);
|
|
|
|
|
setBoundsPass(data.velocityZBuffer, 3, data.gridSize);
|
|
|
|
|
graphics->endDebugRegion();
|
|
|
|
|
|
|
|
|
|
// swap velocity buffers
|
|
|
|
|
SWAP(data.velocityX0Buffer, data.velocityXBuffer);
|
|
|
|
|
SWAP(data.velocityY0Buffer, data.velocityYBuffer);
|
|
|
|
@@ -326,8 +412,8 @@ void SimulationComputePass::render() {
|
|
|
|
|
graphics->copyBuffer(density0, densityCurrent);
|
|
|
|
|
densityCurrent->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
|
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
|
|
|
|
for (int iteration = 0; iteration < 4; ++iteration) {
|
|
|
|
|
float a = dt * data.diffusion * (data.gridSize.x - 2) * (data.gridSize.y - 2) * (data.gridSize.z - 2);
|
|
|
|
|
for (int iteration = 0; iteration < densityDiffuseIterations; ++iteration) {
|
|
|
|
|
float a = data.dt * data.diffusion * (data.gridSize.x - 2) * (data.gridSize.x - 2);
|
|
|
|
|
float c = 1 + 6 * a;
|
|
|
|
|
linearSolvePass(densityNext, densityCurrent, density0, a, c, data.gridSize);
|
|
|
|
|
setBoundsPass(densityNext, 0, data.gridSize);
|
|
|
|
@@ -335,12 +421,13 @@ void SimulationComputePass::render() {
|
|
|
|
|
}
|
|
|
|
|
graphics->endDebugRegion();
|
|
|
|
|
graphics->beginDebugRegion("AdvectDensity");
|
|
|
|
|
advectPass(data.density0Buffer, densityCurrent, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, dt, data.gridSize);
|
|
|
|
|
advectPass(data.density0Buffer, densityCurrent, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, data.dt,
|
|
|
|
|
data.gridSize);
|
|
|
|
|
setBoundsPass(data.density0Buffer, 0, data.gridSize);
|
|
|
|
|
graphics->endDebugRegion();
|
|
|
|
|
|
|
|
|
|
graphics->beginDebugRegion("AdvectLevelSet");
|
|
|
|
|
advectPass(data.phiBuffer, data.phi0Buffer, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, dt, data.gridSize);
|
|
|
|
|
advectPass(data.phiBuffer, data.phi0Buffer, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, data.dt, data.gridSize);
|
|
|
|
|
setBoundsPass(data.phiBuffer, 0, data.gridSize);
|
|
|
|
|
|
|
|
|
|
// Reinitialize level set every N frames to restore |grad phi| = 1
|
|
|
|
@@ -380,7 +467,11 @@ void SimulationComputePass::setBoundsPass(Gfx::PShaderBuffer grid, int b, UVecto
|
|
|
|
|
Gfx::OComputeCommand boundsCommand = graphics->createComputeCommand();
|
|
|
|
|
boundsCommand->bindPipeline(setBounds.pipeline);
|
|
|
|
|
boundsCommand->bindDescriptor(bounds);
|
|
|
|
|
boundsCommand->dispatch(getDispatchSize(gridSize, setBounds.threadGroupSize));
|
|
|
|
|
boundsCommand->bindDescriptor(gridSizeSet);
|
|
|
|
|
// Dispatch covers max(gridSize.x, gridSize.y) x max(gridSize.y, gridSize.z) to handle all faces on non-cubic grids
|
|
|
|
|
UVector faceDispatchGrid = {std::max(gridSize.x, gridSize.y), std::max(gridSize.y, gridSize.z), 1};
|
|
|
|
|
auto dispatchSize = getDispatchSize(faceDispatchGrid, setBounds.threadGroupSize);
|
|
|
|
|
boundsCommand->dispatch(dispatchSize.x, dispatchSize.y, 1);
|
|
|
|
|
graphics->executeCommands(std::move(boundsCommand));
|
|
|
|
|
|
|
|
|
|
grid->pipelineBarrier(Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
|
|
|
@@ -389,7 +480,10 @@ void SimulationComputePass::setBoundsPass(Gfx::PShaderBuffer grid, int b, UVecto
|
|
|
|
|
Gfx::OComputeCommand edgesCommand = graphics->createComputeCommand();
|
|
|
|
|
edgesCommand->bindPipeline(setBounds.pipelineEdges);
|
|
|
|
|
edgesCommand->bindDescriptor(bounds);
|
|
|
|
|
edgesCommand->dispatch(getDispatchSize(gridSize, setBounds.threadGroupSize).x, 1, 1);
|
|
|
|
|
edgesCommand->bindDescriptor(gridSizeSet);
|
|
|
|
|
// Dispatch covers max dimension to handle all 12 edges on non-cubic grids; edge shader uses numthreads(128,1,1)
|
|
|
|
|
uint32_t maxDim = std::max({gridSize.x, gridSize.y, gridSize.z});
|
|
|
|
|
edgesCommand->dispatch((maxDim + 127) / 128, 1, 1);
|
|
|
|
|
graphics->executeCommands(std::move(edgesCommand));
|
|
|
|
|
|
|
|
|
|
grid->pipelineBarrier(Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
|
|
|
@@ -398,6 +492,7 @@ void SimulationComputePass::setBoundsPass(Gfx::PShaderBuffer grid, int b, UVecto
|
|
|
|
|
Gfx::OComputeCommand cornersCommand = graphics->createComputeCommand();
|
|
|
|
|
cornersCommand->bindPipeline(setBounds.pipelineCorners);
|
|
|
|
|
cornersCommand->bindDescriptor(bounds);
|
|
|
|
|
cornersCommand->bindDescriptor(gridSizeSet);
|
|
|
|
|
cornersCommand->dispatch(1, 1, 1);
|
|
|
|
|
graphics->executeCommands(std::move(cornersCommand));
|
|
|
|
|
|
|
|
|
@@ -405,7 +500,8 @@ void SimulationComputePass::setBoundsPass(Gfx::PShaderBuffer grid, int b, UVecto
|
|
|
|
|
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SimulationComputePass::linearSolvePass(Gfx::PShaderBuffer next, Gfx::PShaderBuffer current, Gfx::PShaderBuffer grid0, float a, float c, UVector gridSize) {
|
|
|
|
|
void SimulationComputePass::linearSolvePass(Gfx::PShaderBuffer next, Gfx::PShaderBuffer current, Gfx::PShaderBuffer grid0, float a, float c,
|
|
|
|
|
UVector gridSize) {
|
|
|
|
|
Gfx::ODescriptorSet solve = linearSolve.descriptorLayout->allocateDescriptorSet();
|
|
|
|
|
solve->updateBuffer("next", 0, next);
|
|
|
|
|
solve->updateBuffer("current", 0, current);
|
|
|
|
@@ -416,6 +512,7 @@ void SimulationComputePass::linearSolvePass(Gfx::PShaderBuffer next, Gfx::PShade
|
|
|
|
|
Gfx::OComputeCommand solveCommand = graphics->createComputeCommand();
|
|
|
|
|
solveCommand->bindPipeline(linearSolve.pipeline);
|
|
|
|
|
solveCommand->bindDescriptor(solve);
|
|
|
|
|
solveCommand->bindDescriptor(gridSizeSet);
|
|
|
|
|
solveCommand->dispatch(getDispatchSize(gridSize, linearSolve.threadGroupSize));
|
|
|
|
|
graphics->executeCommands(std::move(solveCommand));
|
|
|
|
|
|
|
|
|
@@ -435,6 +532,7 @@ void SimulationComputePass::divergencePass(Seele::Gfx::PShaderBuffer divergence,
|
|
|
|
|
Gfx::OComputeCommand divergenceCommand = graphics->createComputeCommand();
|
|
|
|
|
divergenceCommand->bindPipeline(computeDivergence.pipeline);
|
|
|
|
|
divergenceCommand->bindDescriptor(divergenceSet);
|
|
|
|
|
divergenceCommand->bindDescriptor(gridSizeSet);
|
|
|
|
|
divergenceCommand->dispatch(getDispatchSize(gridSize, computeDivergence.threadGroupSize));
|
|
|
|
|
graphics->executeCommands(std::move(divergenceCommand));
|
|
|
|
|
// divergence is now in velocityXBuffer, pressure is in velocityYBuffer
|
|
|
|
@@ -455,6 +553,7 @@ void SimulationComputePass::projectPass(Seele::Gfx::PShaderBuffer velocityX, See
|
|
|
|
|
Gfx::OComputeCommand projectCommand = graphics->createComputeCommand();
|
|
|
|
|
projectCommand->bindPipeline(project.pipeline);
|
|
|
|
|
projectCommand->bindDescriptor(projectSet);
|
|
|
|
|
projectCommand->bindDescriptor(gridSizeSet);
|
|
|
|
|
projectCommand->dispatch(getDispatchSize(gridSize, project.threadGroupSize));
|
|
|
|
|
graphics->executeCommands(std::move(projectCommand));
|
|
|
|
|
|
|
|
|
@@ -479,6 +578,7 @@ void SimulationComputePass::advectPass(Gfx::PShaderBuffer quantity, Gfx::PShader
|
|
|
|
|
Gfx::OComputeCommand advectCommand = graphics->createComputeCommand();
|
|
|
|
|
advectCommand->bindPipeline(advect.pipeline);
|
|
|
|
|
advectCommand->bindDescriptor(advectSet);
|
|
|
|
|
advectCommand->bindDescriptor(gridSizeSet);
|
|
|
|
|
advectCommand->dispatch(getDispatchSize(gridSize, advect.threadGroupSize));
|
|
|
|
|
graphics->executeCommands(std::move(advectCommand));
|
|
|
|
|
|
|
|
|
@@ -486,6 +586,29 @@ void SimulationComputePass::advectPass(Gfx::PShaderBuffer quantity, Gfx::PShader
|
|
|
|
|
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SimulationComputePass::applyForcesPass(Gfx::PShaderBuffer velocityX, Gfx::PShaderBuffer velocityY, Gfx::PShaderBuffer velocityZ, Vector gravity, float dt, UVector gridSize) {
|
|
|
|
|
Gfx::ODescriptorSet forcesSet = applyForces.descriptorLayout->allocateDescriptorSet();
|
|
|
|
|
forcesSet->updateBuffer("velocityX", 0, velocityX);
|
|
|
|
|
forcesSet->updateBuffer("velocityY", 0, velocityY);
|
|
|
|
|
forcesSet->updateBuffer("velocityZ", 0, velocityZ);
|
|
|
|
|
forcesSet->updateConstants("force", 0, &gravity);
|
|
|
|
|
forcesSet->updateConstants("dt", 0, &dt);
|
|
|
|
|
forcesSet->writeChanges();
|
|
|
|
|
Gfx::OComputeCommand forcesCommand = graphics->createComputeCommand();
|
|
|
|
|
forcesCommand->bindPipeline(applyForces.pipeline);
|
|
|
|
|
forcesCommand->bindDescriptor(forcesSet);
|
|
|
|
|
forcesCommand->bindDescriptor(gridSizeSet);
|
|
|
|
|
forcesCommand->dispatch(getDispatchSize(gridSize, applyForces.threadGroupSize));
|
|
|
|
|
graphics->executeCommands(std::move(forcesCommand));
|
|
|
|
|
|
|
|
|
|
velocityX->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
|
|
|
|
|
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
|
|
|
|
velocityY->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
|
|
|
|
|
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
|
|
|
|
velocityZ->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
|
|
|
|
|
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SimulationComputePass::reinitializeLevelSetPass(Seele::Gfx::PShaderBuffer phi, Seele::Gfx::PShaderBuffer phi0, UVector gridSize) {
|
|
|
|
|
graphics->beginDebugRegion("ReinitializeLevelSet");
|
|
|
|
|
// Snapshot current phi into phi0 for the sign function
|
|
|
|
@@ -507,6 +630,7 @@ void SimulationComputePass::reinitializeLevelSetPass(Seele::Gfx::PShaderBuffer p
|
|
|
|
|
Gfx::OComputeCommand reinitCommand = graphics->createComputeCommand();
|
|
|
|
|
reinitCommand->bindPipeline(reinitialize.pipeline);
|
|
|
|
|
reinitCommand->bindDescriptor(reinitSet);
|
|
|
|
|
reinitCommand->bindDescriptor(gridSizeSet);
|
|
|
|
|
reinitCommand->dispatch(getDispatchSize(gridSize, reinitialize.threadGroupSize));
|
|
|
|
|
graphics->executeCommands(std::move(reinitCommand));
|
|
|
|
|
|
|
|
|
|