104 lines
4.9 KiB
C++
104 lines
4.9 KiB
C++
#pragma once
|
|
#include "Graphics/Buffer.h"
|
|
#include "Graphics/Descriptor.h"
|
|
#include "Graphics/Initializer.h"
|
|
#include "Graphics/RenderPass/RenderPass.h"
|
|
#include "Graphics/Resources.h"
|
|
#include "Math/Vector.h"
|
|
#include "Scene/Scene.h"
|
|
|
|
namespace Seele {
|
|
class SimulationComputePass : public RenderPass {
|
|
public:
|
|
SimulationComputePass(Gfx::PGraphics graphics, PScene scene);
|
|
virtual ~SimulationComputePass() override;
|
|
virtual void beginFrame(const Component::Camera& camera, const Seele::Component::Transform& transform) override;
|
|
virtual void render() override;
|
|
virtual void endFrame() override;
|
|
virtual void publishOutputs() override;
|
|
virtual void createRenderPass() override;
|
|
|
|
private:
|
|
UVector getDispatchSize(const UVector& gridSize, const UVector& threadGroupSize);
|
|
void setBoundsPass(Gfx::PShaderBuffer buffer, int b, UVector gridSize, Gfx::PShaderBuffer planeBuffer, uint32 numPlanes);
|
|
void linearSolvePass(Gfx::PShaderBuffer grid, Seele::Gfx::PShaderBuffer grid0, float a, float c, float omega, UVector gridSize);
|
|
void divergencePass(Gfx::PShaderBuffer divergence, Seele::Gfx::PShaderBuffer pressure, Seele::Gfx::PShaderBuffer velocityX,
|
|
Seele::Gfx::PShaderBuffer velocityY, Seele::Gfx::PShaderBuffer velocityZ, UVector gridSize);
|
|
void projectPass(Gfx::PShaderBuffer velocityX, Seele::Gfx::PShaderBuffer velocityY, Seele::Gfx::PShaderBuffer velocityZ,
|
|
Seele::Gfx::PShaderBuffer pressure, UVector gridSize);
|
|
void advectPass(Gfx::PShaderBuffer quantity, Seele::Gfx::PShaderBuffer quantity0, Seele::Gfx::PShaderBuffer velocityX,
|
|
Seele::Gfx::PShaderBuffer velocityY, Seele::Gfx::PShaderBuffer velocityZ, float dt, UVector gridSize);
|
|
void reinitializeLevelSetPass(Gfx::PShaderBuffer phi, Seele::Gfx::PShaderBuffer phi0, Seele::Gfx::PShaderBuffer phiSign, UVector gridSize, Gfx::PShaderBuffer planeBuffer, uint32 numPlanes);
|
|
struct SetBounds {
|
|
Gfx::OPipelineLayout pipelineLayout;
|
|
Gfx::ODescriptorLayout descriptorLayout;
|
|
Gfx::OComputeShader shader;
|
|
Gfx::PComputePipeline pipeline;
|
|
constexpr static UVector threadGroupSize = {4, 4, 4};
|
|
} setBounds;
|
|
struct LinearSolve {
|
|
Gfx::OPipelineLayout pipelineLayout;
|
|
Gfx::ODescriptorLayout descriptorLayout;
|
|
Gfx::OComputeShader shader;
|
|
Gfx::PComputePipeline pipeline;
|
|
constexpr static UVector threadGroupSize = {32, 8, 1};
|
|
} linearSolve;
|
|
struct ComputeDivergence {
|
|
Gfx::OPipelineLayout pipelineLayout;
|
|
Gfx::ODescriptorLayout descriptorLayout;
|
|
Gfx::OComputeShader shader;
|
|
Gfx::PComputePipeline pipeline;
|
|
constexpr static UVector threadGroupSize = {32, 8, 1};
|
|
} computeDivergence;
|
|
struct Project {
|
|
Gfx::OPipelineLayout pipelineLayout;
|
|
Gfx::ODescriptorLayout descriptorLayout;
|
|
Gfx::OComputeShader shader;
|
|
Gfx::PComputePipeline pipeline;
|
|
constexpr static UVector threadGroupSize = {32, 8, 1};
|
|
} project;
|
|
struct Advect {
|
|
Gfx::OPipelineLayout pipelineLayout;
|
|
Gfx::ODescriptorLayout descriptorLayout;
|
|
Gfx::OComputeShader shader;
|
|
Gfx::PComputePipeline pipeline;
|
|
constexpr static UVector threadGroupSize = {32, 8, 1};
|
|
} advect;
|
|
struct Reinitialize {
|
|
Gfx::OPipelineLayout pipelineLayout;
|
|
Gfx::ODescriptorLayout descriptorLayout;
|
|
Gfx::OComputeShader shader;
|
|
Gfx::PComputePipeline pipeline;
|
|
constexpr static UVector threadGroupSize = {32, 8, 1};
|
|
} reinitialize;
|
|
struct ApplyForces {
|
|
Gfx::OPipelineLayout pipelineLayout;
|
|
Gfx::ODescriptorLayout descriptorLayout;
|
|
Gfx::OComputeShader shader;
|
|
Gfx::PComputePipeline pipeline;
|
|
constexpr static UVector threadGroupSize = {32, 8, 1};
|
|
} applyForces;
|
|
void applyForcesPass(Gfx::PShaderBuffer velocityX, Gfx::PShaderBuffer velocityY, Gfx::PShaderBuffer velocityZ, Vector gravity, float dt, UVector gridSize);
|
|
// Diagnostics: sum interior fields and log to console. Not part of the simulation.
|
|
void massProbePass(Gfx::PShaderBuffer density, Gfx::PShaderBuffer phi, Gfx::PShaderBuffer velocityX, Gfx::PShaderBuffer velocityY,
|
|
Gfx::PShaderBuffer velocityZ, UVector gridSize);
|
|
struct MassProbe {
|
|
Gfx::OPipelineLayout pipelineLayout;
|
|
Gfx::ODescriptorLayout descriptorLayout;
|
|
Gfx::OComputeShader shader;
|
|
Gfx::PComputePipeline pipeline;
|
|
constexpr static UVector threadGroupSize = {32, 8, 1};
|
|
} massProbe;
|
|
Gfx::ODescriptorLayout gridSizeLayout;
|
|
Gfx::ODescriptorSet gridSizeSet;
|
|
// Diagnostics: 3 floats (density sum, phi sum, |velocity| sum), zeroed each frame.
|
|
Gfx::OShaderBuffer probeOutBuffer;
|
|
uint32 probeFrame = 0;
|
|
struct BoundaryPlane {
|
|
Vector normal;
|
|
float d;
|
|
};
|
|
PScene scene;
|
|
};
|
|
DEFINE_REF(SimulationComputePass)
|
|
} // namespace Seele
|