Still dont know
This commit is contained in:
1 parent
bedeb8f059
commit
b1004d5c80
11 files changed
+334
-265
No files matched your search
Vendored
+9
-32
@@ -31,39 +31,16 @@
|
|||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceRoot}/build/Editor",
|
"program": "${workspaceRoot}/build/Editor",
|
||||||
"args": [],
|
"args": [],
|
||||||
"environment": [
|
"env": {
|
||||||
{
|
"ASAN_OPTIONS": "detect_leaks=0",
|
||||||
"name": "ASAN_OPTIONS",
|
"DISABLE_VK_LAYER_VALVE_steam_overlay_1": "1",
|
||||||
"value": "detect_leaks=0",
|
"DISABLE_VK_LAYER_VALVE_steam_fossilize_1": "1",
|
||||||
},
|
"MANGOHUD": "0"
|
||||||
{
|
},
|
||||||
"name": "DISABLE_VK_LAYER_VALVE_steam_overlay_1",
|
|
||||||
"value": "1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "DISABLE_VK_LAYER_VALVE_steam_fossilize_1",
|
|
||||||
"value": "1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "MANGOHUD",
|
|
||||||
"value": "0",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"cwd": "${workspaceRoot}/build",
|
"cwd": "${workspaceRoot}/build",
|
||||||
"MIMode": "gdb",
|
"initCommands": [
|
||||||
"miDebuggerPath": "/usr/bin/gdb",
|
"command script import ${workspaceFolder}/Seele/gdb/Seele_lldb.py"
|
||||||
"setupCommands": [
|
]
|
||||||
{
|
|
||||||
"description": "Enable pretty-printing for gdb",
|
|
||||||
"text": "-enable-pretty-printing",
|
|
||||||
"ignoreFailures": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Import Seele pretty-printers",
|
|
||||||
"text": "python exec(open('${workspaceFolder}/Seele/gdb/Seele.py').read())",
|
|
||||||
"ignoreFailures": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -2,14 +2,14 @@ import FluidGridData;
|
|||||||
|
|
||||||
struct Params
|
struct Params
|
||||||
{
|
{
|
||||||
// read-write
|
// read-write (in-place update)
|
||||||
FluidGridData<float> next;
|
FluidGridData<float> grid;
|
||||||
// read-only
|
// read-only (right-hand side)
|
||||||
FluidGridData<float> current;
|
|
||||||
// read-only
|
|
||||||
FluidGridData<float> grid0;
|
FluidGridData<float> grid0;
|
||||||
float a;
|
float a;
|
||||||
float c;
|
float c;
|
||||||
|
float omega;
|
||||||
|
int color;
|
||||||
};
|
};
|
||||||
ParameterBlock<Params> params;
|
ParameterBlock<Params> params;
|
||||||
|
|
||||||
@@ -17,16 +17,22 @@ ParameterBlock<Params> params;
|
|||||||
[numthreads(32, 8, 1)]
|
[numthreads(32, 8, 1)]
|
||||||
void linearSolve(uint3 dispatchThreadID : SV_DispatchThreadID)
|
void linearSolve(uint3 dispatchThreadID : SV_DispatchThreadID)
|
||||||
{
|
{
|
||||||
FluidGridData<float> next = params.next;
|
FluidGridData<float> grid = params.grid;
|
||||||
FluidGridData<float> current = params.current;
|
|
||||||
FluidGridData<float> grid0 = params.grid0;
|
FluidGridData<float> grid0 = params.grid0;
|
||||||
float a = params.a;
|
float a = params.a;
|
||||||
float cRecip = 1.0f / params.c;
|
float cRecip = 1.0f / params.c;
|
||||||
|
float omega = params.omega;
|
||||||
|
int color = params.color;
|
||||||
|
|
||||||
int x = dispatchThreadID.x + 1;
|
int x = dispatchThreadID.x + 1;
|
||||||
int y = dispatchThreadID.y + 1;
|
int y = dispatchThreadID.y + 1;
|
||||||
int z = dispatchThreadID.z + 1;
|
int z = dispatchThreadID.z + 1;
|
||||||
if(x >= gridParams.gridSize.x - 1 || y >= gridParams.gridSize.y - 1 || z >= gridParams.gridSize.z - 1) return;
|
if(x >= gridParams.gridSize.x - 1 || y >= gridParams.gridSize.y - 1 || z >= gridParams.gridSize.z - 1) return;
|
||||||
|
|
||||||
next[x, y, z] = (grid0[x, y, z] + a * (current[x + 1, y, z] + current[x - 1, y, z] + current[x, y + 1, z] + current[x, y - 1, z] + current[x, y, z + 1] + current[x, y, z - 1])) * cRecip;
|
// Red-Black Gauss-Seidel: only update cells matching the current color
|
||||||
|
if((x + y + z) % 2 != color) return;
|
||||||
|
|
||||||
|
float oldVal = grid[x, y, z];
|
||||||
|
float gs = (grid0[x, y, z] + a * (grid[x + 1, y, z] + grid[x - 1, y, z] + grid[x, y + 1, z] + grid[x, y - 1, z] + grid[x, y, z + 1] + grid[x, y, z - 1])) * cRecip;
|
||||||
|
grid[x, y, z] = lerp(oldVal, gs, omega);
|
||||||
}
|
}
|
||||||
@@ -1,93 +1,81 @@
|
|||||||
import FluidGridData;
|
import FluidGridData;
|
||||||
|
|
||||||
|
struct BoundaryPlane
|
||||||
|
{
|
||||||
|
float3 normal; // inward normal (points from solid toward fluid)
|
||||||
|
float d; // plane offset: dot(normal, cellPos) + d < 0 means solid
|
||||||
|
};
|
||||||
|
|
||||||
struct Params
|
struct Params
|
||||||
{
|
{
|
||||||
int b;
|
int b;
|
||||||
|
uint numPlanes;
|
||||||
|
StructuredBuffer<BoundaryPlane> planes;
|
||||||
// read-write
|
// read-write
|
||||||
FluidGridData<float> grid;
|
FluidGridData<float> grid;
|
||||||
};
|
};
|
||||||
ParameterBlock<Params> params;
|
ParameterBlock<Params> params;
|
||||||
|
|
||||||
|
// Find the interior (fluid) neighbor of a solid cell by stepping along the
|
||||||
|
// dominant axis of the plane inward normal.
|
||||||
|
int3 getInteriorNeighbor(int3 pos, float3 normal)
|
||||||
|
{
|
||||||
|
float3 absN = abs(normal);
|
||||||
|
int3 step;
|
||||||
|
if (absN.x >= absN.y && absN.x >= absN.z)
|
||||||
|
step = int3(normal.x > 0 ? 1 : -1, 0, 0);
|
||||||
|
else if (absN.y >= absN.z)
|
||||||
|
step = int3(0, normal.y > 0 ? 1 : -1, 0);
|
||||||
|
else
|
||||||
|
step = int3(0, 0, normal.z > 0 ? 1 : -1);
|
||||||
|
|
||||||
|
return clamp(pos + step, int3(0), int3(gridParams.gridSize) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute the boundary value scaling factor for velocity component b.
|
||||||
|
// For b=0 (scalar): factor = 1 (Neumann / copy).
|
||||||
|
// For b=1,2,3 (velocity x,y,z): reflects the normal component so that
|
||||||
|
// velocity normal to the plane is negated while tangential parts are preserved.
|
||||||
|
float getBoundaryFactor(int b, float3 normal)
|
||||||
|
{
|
||||||
|
if (b == 0) return 1.0f;
|
||||||
|
float nComp = (b == 1) ? normal.x : ((b == 2) ? normal.y : normal.z);
|
||||||
|
return 1.0f - 2.0f * nComp * nComp;
|
||||||
|
}
|
||||||
|
|
||||||
[shader("compute")]
|
[shader("compute")]
|
||||||
[numthreads(32, 8, 1)]
|
[numthreads(4, 4, 4)]
|
||||||
void setBound(uint3 dispatchThreadID : SV_DispatchThreadID)
|
void setBound(uint3 dispatchThreadID : SV_DispatchThreadID)
|
||||||
{
|
{
|
||||||
|
int3 pos = int3(dispatchThreadID);
|
||||||
|
if (any(uint3(pos) >= gridParams.gridSize))
|
||||||
|
return;
|
||||||
|
|
||||||
int b = params.b;
|
int b = params.b;
|
||||||
FluidGridData<float> grid = params.grid;
|
FluidGridData<float> grid = params.grid;
|
||||||
int i = dispatchThreadID.x + 1;
|
float3 cellPos = float3(pos);
|
||||||
int j = dispatchThreadID.y + 1;
|
|
||||||
|
|
||||||
// X-faces: indices range over (gridSize.y, gridSize.z)
|
int numAffecting = 0;
|
||||||
if(i < gridParams.gridSize.y - 1 && j < gridParams.gridSize.z - 1)
|
float valueSum = 0.0f;
|
||||||
|
|
||||||
|
for (uint p = 0; p < params.numPlanes; p++)
|
||||||
{
|
{
|
||||||
grid[0, i, j] = b == 1 ? -grid[1, i, j] : grid[1, i, j];
|
BoundaryPlane plane = params.planes[p];
|
||||||
grid[gridParams.gridSize.x - 1, i, j] = b == 1 ? -grid[gridParams.gridSize.x - 2, i, j] : grid[gridParams.gridSize.x - 2, i, j];
|
float dist = dot(plane.normal, cellPos) + plane.d;
|
||||||
|
|
||||||
|
if (dist < 0.0f) // cell is on the solid side
|
||||||
|
{
|
||||||
|
int3 neighbor = getInteriorNeighbor(pos, plane.normal);
|
||||||
|
float neighborVal = grid[uint3(neighbor)];
|
||||||
|
float factor = getBoundaryFactor(b, plane.normal);
|
||||||
|
|
||||||
|
valueSum += factor * neighborVal;
|
||||||
|
numAffecting++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Y-faces: indices range over (gridSize.x, gridSize.z)
|
if (numAffecting > 0)
|
||||||
if(i < gridParams.gridSize.x - 1 && j < gridParams.gridSize.z - 1)
|
|
||||||
{
|
{
|
||||||
grid[i, 0, j] = b == 2 ? -grid[i, 1, j] : grid[i, 1, j];
|
grid[uint3(pos)] = valueSum / float(numAffecting);
|
||||||
grid[i, gridParams.gridSize.y - 1, j] = b == 2 ? -grid[i, gridParams.gridSize.y - 2, j] : grid[i, gridParams.gridSize.y - 2, j];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Z-faces: indices range over (gridSize.x, gridSize.y)
|
|
||||||
if(i < gridParams.gridSize.x - 1 && j < gridParams.gridSize.y - 1)
|
|
||||||
{
|
|
||||||
grid[i, j, 0] = b == 3 ? -grid[i, j, 1] : grid[i, j, 1];
|
|
||||||
grid[i, j, gridParams.gridSize.z - 1] = b == 3 ? -grid[i, j, gridParams.gridSize.z - 2] : grid[i, j, gridParams.gridSize.z - 2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[shader("compute")]
|
|
||||||
[numthreads(128, 1, 1)]
|
|
||||||
void setBoundEdges(uint3 dispatchThreadID : SV_DispatchThreadID)
|
|
||||||
{
|
|
||||||
FluidGridData<float> grid = params.grid;
|
|
||||||
int x = dispatchThreadID.x + 1;
|
|
||||||
|
|
||||||
// X-axis edges: x ranges [1, gridSize.x-2]
|
|
||||||
if(x < gridParams.gridSize.x - 1)
|
|
||||||
{
|
|
||||||
grid[x, 0, 0] = 0.5f * (grid[x, 1, 0] + grid[x, 0, 1]);
|
|
||||||
grid[x, gridParams.gridSize.y - 1, 0] = 0.5f * (grid[x, gridParams.gridSize.y - 2, 0] + grid[x, gridParams.gridSize.y - 1, 1]);
|
|
||||||
grid[x, 0, gridParams.gridSize.z - 1] = 0.5f * (grid[x, 1, gridParams.gridSize.z - 1] + grid[x, 0, gridParams.gridSize.z - 2]);
|
|
||||||
grid[x, gridParams.gridSize.y - 1, gridParams.gridSize.z - 1] = 0.5f * (grid[x, gridParams.gridSize.y - 2, gridParams.gridSize.z - 1] + grid[x, gridParams.gridSize.y - 1, gridParams.gridSize.z - 2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Y-axis edges: x ranges [1, gridSize.y-2]
|
|
||||||
if(x < gridParams.gridSize.y - 1)
|
|
||||||
{
|
|
||||||
grid[0, x, 0] = 0.5f * (grid[1, x, 0] + grid[0, x, 1]);
|
|
||||||
grid[0, x, gridParams.gridSize.z - 1] = 0.5f * (grid[1, x, gridParams.gridSize.z - 1] + grid[0, x, gridParams.gridSize.z - 2]);
|
|
||||||
grid[gridParams.gridSize.x - 1, x, 0] = 0.5f * (grid[gridParams.gridSize.x - 2, x, 0] + grid[gridParams.gridSize.x - 1, x, 1]);
|
|
||||||
grid[gridParams.gridSize.x - 1, x, gridParams.gridSize.z - 1] = 0.5f * (grid[gridParams.gridSize.x - 2, x, gridParams.gridSize.z - 1] + grid[gridParams.gridSize.x - 1, x, gridParams.gridSize.z - 2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Z-axis edges: x ranges [1, gridSize.z-2]
|
|
||||||
if(x < gridParams.gridSize.z - 1)
|
|
||||||
{
|
|
||||||
grid[0, 0, x] = 0.5f * (grid[1, 0, x] + grid[0, 1, x]);
|
|
||||||
grid[0, gridParams.gridSize.y - 1, x] = 0.5f * (grid[1, gridParams.gridSize.y - 1, x] + grid[0, gridParams.gridSize.y - 2, x]);
|
|
||||||
grid[gridParams.gridSize.x - 1, 0, x] = 0.5f * (grid[gridParams.gridSize.x - 2, 0, x] + grid[gridParams.gridSize.x - 1, 1, x]);
|
|
||||||
grid[gridParams.gridSize.x - 1, gridParams.gridSize.y - 1, x] = 0.5f * (grid[gridParams.gridSize.x - 2, gridParams.gridSize.y - 1, x] + grid[gridParams.gridSize.x - 1, gridParams.gridSize.y - 2, x]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[shader("compute")]
|
|
||||||
[numthreads(8, 1, 1)]
|
|
||||||
void setBoundCorners(uint3 dispatchThreadID : SV_DispatchThreadID)
|
|
||||||
{
|
|
||||||
FluidGridData<float> grid = params.grid;
|
|
||||||
uint threadIdx = dispatchThreadID.x;
|
|
||||||
|
|
||||||
uint x = ((threadIdx & 1) == 0) ? 0 : (gridParams.gridSize.x - 1);
|
|
||||||
uint y = ((threadIdx & 2) == 0) ? 0 : (gridParams.gridSize.y - 1);
|
|
||||||
uint z = ((threadIdx & 4) == 0) ? 0 : (gridParams.gridSize.z - 1);
|
|
||||||
|
|
||||||
uint nx = (x == 0) ? 1 : (gridParams.gridSize.x - 2);
|
|
||||||
uint ny = (y == 0) ? 1 : (gridParams.gridSize.y - 2);
|
|
||||||
uint nz = (z == 0) ? 1 : (gridParams.gridSize.z - 2);
|
|
||||||
|
|
||||||
grid[x, y, z] = (1.0f / 3.0f) * (grid[nx, y, z] + grid[x, ny, z] + grid[x, y, nz]);
|
|
||||||
}
|
}
|
||||||
@@ -3,10 +3,12 @@ import FluidGridData;
|
|||||||
struct Params
|
struct Params
|
||||||
{
|
{
|
||||||
float dtau;
|
float dtau;
|
||||||
// read-write: phi being reinitialized
|
// read-write: phi being updated (output)
|
||||||
FluidGridData<float> phi;
|
FluidGridData<float> phi;
|
||||||
// read-only: snapshot of phi before reinitialization (for sign)
|
// read-only: phi from previous iteration (for gradient computation)
|
||||||
FluidGridData<float> phi0;
|
FluidGridData<float> phiPrev;
|
||||||
|
// read-only: phi snapshot from before reinitialization (for sign function)
|
||||||
|
FluidGridData<float> phiSign;
|
||||||
};
|
};
|
||||||
ParameterBlock<Params> params;
|
ParameterBlock<Params> params;
|
||||||
|
|
||||||
@@ -24,24 +26,24 @@ void reinitialize(uint3 dispatchThreadID : SV_DispatchThreadID)
|
|||||||
uint y = dispatchThreadID.y + 1;
|
uint y = dispatchThreadID.y + 1;
|
||||||
uint z = dispatchThreadID.z + 1;
|
uint z = dispatchThreadID.z + 1;
|
||||||
FluidGridData<float> phi = params.phi;
|
FluidGridData<float> phi = params.phi;
|
||||||
FluidGridData<float> phi0 = params.phi0;
|
FluidGridData<float> phiPrev = params.phiPrev;
|
||||||
|
FluidGridData<float> phiSign = params.phiSign;
|
||||||
if(x >= gridParams.gridSize.x - 1 || y >= gridParams.gridSize.y - 1 || z >= gridParams.gridSize.z - 1) return;
|
if(x >= gridParams.gridSize.x - 1 || y >= gridParams.gridSize.y - 1 || z >= gridParams.gridSize.z - 1) return;
|
||||||
|
|
||||||
float dtau = params.dtau;
|
float dtau = params.dtau;
|
||||||
float dx = 1.0f;
|
float dx = 1.0f;
|
||||||
|
|
||||||
// Current value and original sign
|
// Current value from previous iteration, sign from original snapshot
|
||||||
float p = phi0[x, y, z];
|
float p = phiPrev[x, y, z];
|
||||||
float s = smoothSign(phi0[x, y, z], dx);
|
float s = smoothSign(phiSign[x, y, z], dx);
|
||||||
|
|
||||||
// Upwind finite differences for |grad phi| — read from snapshot to avoid race
|
// Upwind finite differences for |grad phi| from previous iteration
|
||||||
// Forward and backward differences
|
float dxp = phiPrev[x + 1, y, z] - p;
|
||||||
float dxp = phi0[x + 1, y, z] - p;
|
float dxm = p - phiPrev[x - 1, y, z];
|
||||||
float dxm = p - phi0[x - 1, y, z];
|
float dyp = phiPrev[x, y + 1, z] - p;
|
||||||
float dyp = phi0[x, y + 1, z] - p;
|
float dym = p - phiPrev[x, y - 1, z];
|
||||||
float dym = p - phi0[x, y - 1, z];
|
float dzp = phiPrev[x, y, z + 1] - p;
|
||||||
float dzp = phi0[x, y, z + 1] - p;
|
float dzm = p - phiPrev[x, y, z - 1];
|
||||||
float dzm = p - phi0[x, y, z - 1];
|
|
||||||
|
|
||||||
// Godunov upwind scheme
|
// Godunov upwind scheme
|
||||||
float gradPhi;
|
float gradPhi;
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Containers/Array.h"
|
||||||
#include "Math/Vector.h"
|
#include "Math/Vector.h"
|
||||||
|
|
||||||
namespace Seele {
|
namespace Seele {
|
||||||
namespace Component {
|
namespace Component {
|
||||||
|
struct BoundaryPlane {
|
||||||
|
Vector normal; // inward normal (from solid toward fluid)
|
||||||
|
float d; // plane offset: dot(normal, pos) + d < 0 means solid
|
||||||
|
};
|
||||||
struct FluidGrid {
|
struct FluidGrid {
|
||||||
bool paused = true;
|
bool paused = true;
|
||||||
float dt = 0.1f;
|
float dt = 0.1f;
|
||||||
@@ -11,6 +16,7 @@ struct FluidGrid {
|
|||||||
UVector gridSize = {128, 128, 128};
|
UVector gridSize = {128, 128, 128};
|
||||||
Vector gravity = {0.0f, -9.81f, 0.0f};
|
Vector gravity = {0.0f, -9.81f, 0.0f};
|
||||||
bool enableGravity = true;
|
bool enableGravity = true;
|
||||||
|
Array<BoundaryPlane> extraPlanes;
|
||||||
};
|
};
|
||||||
} // namespace Component
|
} // namespace Component
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
@@ -13,12 +13,14 @@
|
|||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
|
|
||||||
// Reinitialization is in pseudo-time; keep it gentle to avoid eroding the interface each frame.
|
// Reinitialization is in pseudo-time; keep it gentle to avoid eroding the interface each frame.
|
||||||
constexpr static int reinitInterval = 20;
|
constexpr static int reinitInterval = 5;
|
||||||
constexpr static int reinitIterations = 1;
|
constexpr static int reinitIterations = 5;
|
||||||
constexpr static float reinitDtau = 0.05f;
|
constexpr static float reinitDtau = 0.5f;
|
||||||
constexpr static int velocityDiffuseIterations = 8;
|
constexpr static int velocityDiffuseIterations = 8;
|
||||||
constexpr static int pressureSolveIterations = 24;
|
constexpr static int pressureSolveIterations = 100;
|
||||||
constexpr static int densityDiffuseIterations = 8;
|
constexpr static int densityDiffuseIterations = 8;
|
||||||
|
constexpr static float pressureSORomega = 1.95f;
|
||||||
|
constexpr static float diffusionSORomega = 1.0f;
|
||||||
|
|
||||||
#define SWAP(a, b) \
|
#define SWAP(a, b) \
|
||||||
{ \
|
{ \
|
||||||
@@ -41,6 +43,14 @@ SimulationComputePass::SimulationComputePass(Gfx::PGraphics graphics, PScene sce
|
|||||||
.name = "b",
|
.name = "b",
|
||||||
.uniformLength = sizeof(int),
|
.uniformLength = sizeof(int),
|
||||||
});
|
});
|
||||||
|
setBounds.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||||
|
.name = "numPlanes",
|
||||||
|
.uniformLength = sizeof(uint32),
|
||||||
|
});
|
||||||
|
setBounds.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||||
|
.name = "planes",
|
||||||
|
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||||
|
});
|
||||||
setBounds.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
setBounds.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||||
.name = "grid",
|
.name = "grid",
|
||||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||||
@@ -51,29 +61,27 @@ SimulationComputePass::SimulationComputePass(Gfx::PGraphics graphics, PScene sce
|
|||||||
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
||||||
.name = "SetBound",
|
.name = "SetBound",
|
||||||
.modules = {"SetBound"},
|
.modules = {"SetBound"},
|
||||||
.entryPoints = {{"setBound", "SetBound"}, {"setBoundEdges", "SetBound"}, {"setBoundCorners", "SetBound"}},
|
.entryPoints = {{"setBound", "SetBound"}},
|
||||||
.rootSignature = setBounds.pipelineLayout,
|
.rootSignature = setBounds.pipelineLayout,
|
||||||
});
|
});
|
||||||
setBounds.pipelineLayout->create();
|
setBounds.pipelineLayout->create();
|
||||||
setBounds.shader = graphics->createComputeShader({0});
|
setBounds.shader = graphics->createComputeShader({0});
|
||||||
setBounds.shaderEdges = graphics->createComputeShader({1});
|
|
||||||
setBounds.shaderCorners = graphics->createComputeShader({2});
|
|
||||||
setBounds.pipeline = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
|
setBounds.pipeline = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
|
||||||
.computeShader = setBounds.shader,
|
.computeShader = setBounds.shader,
|
||||||
.pipelineLayout = setBounds.pipelineLayout,
|
.pipelineLayout = setBounds.pipelineLayout,
|
||||||
});
|
});
|
||||||
setBounds.pipelineEdges = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
|
|
||||||
.computeShader = setBounds.shaderEdges,
|
|
||||||
.pipelineLayout = setBounds.pipelineLayout,
|
|
||||||
});
|
|
||||||
setBounds.pipelineCorners = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
|
|
||||||
.computeShader = setBounds.shaderCorners,
|
|
||||||
.pipelineLayout = setBounds.pipelineLayout,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
linearSolve.pipelineLayout = graphics->createPipelineLayout("LinearSolvePipelineLayout");
|
linearSolve.pipelineLayout = graphics->createPipelineLayout("LinearSolvePipelineLayout");
|
||||||
linearSolve.descriptorLayout = graphics->createDescriptorLayout("params");
|
linearSolve.descriptorLayout = graphics->createDescriptorLayout("params");
|
||||||
|
linearSolve.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||||
|
.name = "grid",
|
||||||
|
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||||
|
});
|
||||||
|
linearSolve.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||||
|
.name = "grid0",
|
||||||
|
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||||
|
});
|
||||||
linearSolve.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
linearSolve.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||||
.name = "a",
|
.name = "a",
|
||||||
.uniformLength = sizeof(float),
|
.uniformLength = sizeof(float),
|
||||||
@@ -83,16 +91,12 @@ SimulationComputePass::SimulationComputePass(Gfx::PGraphics graphics, PScene sce
|
|||||||
.uniformLength = sizeof(float),
|
.uniformLength = sizeof(float),
|
||||||
});
|
});
|
||||||
linearSolve.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
linearSolve.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||||
.name = "next",
|
.name = "omega",
|
||||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
.uniformLength = sizeof(float),
|
||||||
});
|
});
|
||||||
linearSolve.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
linearSolve.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||||
.name = "current",
|
.name = "color",
|
||||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
.uniformLength = sizeof(int),
|
||||||
});
|
|
||||||
linearSolve.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
|
||||||
.name = "grid0",
|
|
||||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
|
||||||
});
|
});
|
||||||
linearSolve.descriptorLayout->create();
|
linearSolve.descriptorLayout->create();
|
||||||
linearSolve.pipelineLayout->addDescriptorLayout(linearSolve.descriptorLayout);
|
linearSolve.pipelineLayout->addDescriptorLayout(linearSolve.descriptorLayout);
|
||||||
@@ -241,7 +245,11 @@ SimulationComputePass::SimulationComputePass(Gfx::PGraphics graphics, PScene sce
|
|||||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||||
});
|
});
|
||||||
reinitialize.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
reinitialize.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||||
.name = "phi0",
|
.name = "phiPrev",
|
||||||
|
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||||
|
});
|
||||||
|
reinitialize.descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||||
|
.name = "phiSign",
|
||||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||||
});
|
});
|
||||||
reinitialize.descriptorLayout->create();
|
reinitialize.descriptorLayout->create();
|
||||||
@@ -326,17 +334,13 @@ void SimulationComputePass::render() {
|
|||||||
for (int iteration = 0; iteration < velocityDiffuseIterations; ++iteration) {
|
for (int iteration = 0; iteration < velocityDiffuseIterations; ++iteration) {
|
||||||
float a = data.dt * data.viscosity * (data.gridSize.x - 2) * (data.gridSize.x - 2);
|
float a = data.dt * data.viscosity * (data.gridSize.x - 2) * (data.gridSize.x - 2);
|
||||||
float c = 1 + 6 * a;
|
float c = 1 + 6 * a;
|
||||||
linearSolvePass(data.velocityXNextBuffer, data.velocityXBuffer, data.velocityX0Buffer, a, c, data.gridSize);
|
linearSolvePass(data.velocityXBuffer, data.velocityX0Buffer, a, c, diffusionSORomega, data.gridSize);
|
||||||
linearSolvePass(data.velocityYNextBuffer, data.velocityYBuffer, data.velocityY0Buffer, a, c, data.gridSize);
|
linearSolvePass(data.velocityYBuffer, data.velocityY0Buffer, a, c, diffusionSORomega, data.gridSize);
|
||||||
linearSolvePass(data.velocityZNextBuffer, data.velocityZBuffer, data.velocityZ0Buffer, a, c, data.gridSize);
|
linearSolvePass(data.velocityZBuffer, data.velocityZ0Buffer, a, c, diffusionSORomega, data.gridSize);
|
||||||
|
|
||||||
setBoundsPass(data.velocityXNextBuffer, 1, data.gridSize);
|
setBoundsPass(data.velocityXBuffer, 1, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
setBoundsPass(data.velocityYNextBuffer, 2, data.gridSize);
|
setBoundsPass(data.velocityYBuffer, 2, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
setBoundsPass(data.velocityZNextBuffer, 3, data.gridSize);
|
setBoundsPass(data.velocityZBuffer, 3, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
|
|
||||||
SWAP(data.velocityXBuffer, data.velocityXNextBuffer);
|
|
||||||
SWAP(data.velocityYBuffer, data.velocityYNextBuffer);
|
|
||||||
SWAP(data.velocityZBuffer, data.velocityZNextBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SWAP(data.velocityX0Buffer, data.velocityXBuffer);
|
SWAP(data.velocityX0Buffer, data.velocityXBuffer);
|
||||||
@@ -346,29 +350,22 @@ void SimulationComputePass::render() {
|
|||||||
|
|
||||||
graphics->beginDebugRegion("Project");
|
graphics->beginDebugRegion("Project");
|
||||||
Gfx::PShaderBuffer divergence = data.velocityXBuffer;
|
Gfx::PShaderBuffer divergence = data.velocityXBuffer;
|
||||||
Gfx::PShaderBuffer pressureCurrent = data.velocityYBuffer;
|
Gfx::PShaderBuffer pressure = data.velocityYBuffer;
|
||||||
Gfx::PShaderBuffer pressureNext = data.velocityZBuffer;
|
divergencePass(divergence, pressure, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, data.gridSize);
|
||||||
divergencePass(divergence, pressureCurrent, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, data.gridSize);
|
|
||||||
|
|
||||||
// Divergence/pressure buffers are aliased to velocity buffers whose boundary
|
setBoundsPass(divergence, 0, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
// cells still contain stale velocity data. Zero the boundaries before solving.
|
setBoundsPass(pressure, 0, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
setBoundsPass(divergence, 0, data.gridSize);
|
|
||||||
setBoundsPass(pressureCurrent, 0, data.gridSize);
|
|
||||||
|
|
||||||
for (int iteration = 0; iteration < pressureSolveIterations; ++iteration) {
|
for (int iteration = 0; iteration < pressureSolveIterations; ++iteration) {
|
||||||
linearSolvePass(pressureNext, pressureCurrent, divergence, 1, 6, data.gridSize);
|
linearSolvePass(pressure, divergence, 1, 6, pressureSORomega, data.gridSize);
|
||||||
|
setBoundsPass(pressure, 0, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
setBoundsPass(pressureNext, 0, data.gridSize);
|
|
||||||
|
|
||||||
// swap pressure buffers
|
|
||||||
SWAP(pressureCurrent, pressureNext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
projectPass(data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, pressureCurrent, data.gridSize);
|
projectPass(data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, pressure, data.gridSize);
|
||||||
|
|
||||||
setBoundsPass(data.velocityX0Buffer, 1, data.gridSize);
|
setBoundsPass(data.velocityX0Buffer, 1, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
setBoundsPass(data.velocityY0Buffer, 2, data.gridSize);
|
setBoundsPass(data.velocityY0Buffer, 2, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
setBoundsPass(data.velocityZ0Buffer, 3, data.gridSize);
|
setBoundsPass(data.velocityZ0Buffer, 3, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
graphics->endDebugRegion();
|
graphics->endDebugRegion();
|
||||||
|
|
||||||
graphics->beginDebugRegion("Advect");
|
graphics->beginDebugRegion("Advect");
|
||||||
@@ -384,28 +381,26 @@ void SimulationComputePass::render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set boundary conditions after advection/forces so the divergence sees correct wall values
|
// Set boundary conditions after advection/forces so the divergence sees correct wall values
|
||||||
setBoundsPass(data.velocityXBuffer, 1, data.gridSize);
|
setBoundsPass(data.velocityXBuffer, 1, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
setBoundsPass(data.velocityYBuffer, 2, data.gridSize);
|
setBoundsPass(data.velocityYBuffer, 2, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
setBoundsPass(data.velocityZBuffer, 3, data.gridSize);
|
setBoundsPass(data.velocityZBuffer, 3, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
|
|
||||||
// Re-project after advection/forces to keep the final velocity field divergence-free.
|
// Re-project after advection/forces to keep the final velocity field divergence-free.
|
||||||
Gfx::PShaderBuffer advectedDivergence = data.velocityXNextBuffer;
|
Gfx::PShaderBuffer advectedDivergence = data.velocityXNextBuffer;
|
||||||
Gfx::PShaderBuffer advectedPressureCurrent = data.velocityYNextBuffer;
|
Gfx::PShaderBuffer advectedPressure = data.velocityYNextBuffer;
|
||||||
Gfx::PShaderBuffer advectedPressureNext = data.velocityZNextBuffer;
|
divergencePass(advectedDivergence, advectedPressure, data.velocityXBuffer, data.velocityYBuffer, data.velocityZBuffer, data.gridSize);
|
||||||
divergencePass(advectedDivergence, advectedPressureCurrent, data.velocityXBuffer, data.velocityYBuffer, data.velocityZBuffer, data.gridSize);
|
setBoundsPass(advectedDivergence, 0, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
setBoundsPass(advectedDivergence, 0, data.gridSize);
|
setBoundsPass(advectedPressure, 0, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
setBoundsPass(advectedPressureCurrent, 0, data.gridSize);
|
|
||||||
|
|
||||||
for (int iteration = 0; iteration < pressureSolveIterations; ++iteration) {
|
for (int iteration = 0; iteration < pressureSolveIterations; ++iteration) {
|
||||||
linearSolvePass(advectedPressureNext, advectedPressureCurrent, advectedDivergence, 1, 6, data.gridSize);
|
linearSolvePass(advectedPressure, advectedDivergence, 1, 6, pressureSORomega, data.gridSize);
|
||||||
setBoundsPass(advectedPressureNext, 0, data.gridSize);
|
setBoundsPass(advectedPressure, 0, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
SWAP(advectedPressureCurrent, advectedPressureNext);
|
|
||||||
}
|
}
|
||||||
projectPass(data.velocityXBuffer, data.velocityYBuffer, data.velocityZBuffer, advectedPressureCurrent, data.gridSize);
|
projectPass(data.velocityXBuffer, data.velocityYBuffer, data.velocityZBuffer, advectedPressure, data.gridSize);
|
||||||
|
|
||||||
setBoundsPass(data.velocityXBuffer, 1, data.gridSize);
|
setBoundsPass(data.velocityXBuffer, 1, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
setBoundsPass(data.velocityYBuffer, 2, data.gridSize);
|
setBoundsPass(data.velocityYBuffer, 2, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
setBoundsPass(data.velocityZBuffer, 3, data.gridSize);
|
setBoundsPass(data.velocityZBuffer, 3, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
graphics->endDebugRegion();
|
graphics->endDebugRegion();
|
||||||
// swap velocity buffers
|
// swap velocity buffers
|
||||||
SWAP(data.velocityX0Buffer, data.velocityXBuffer);
|
SWAP(data.velocityX0Buffer, data.velocityXBuffer);
|
||||||
@@ -415,7 +410,6 @@ void SimulationComputePass::render() {
|
|||||||
// diffuse density
|
// diffuse density
|
||||||
graphics->beginDebugRegion("DiffuseDensity");
|
graphics->beginDebugRegion("DiffuseDensity");
|
||||||
Gfx::PShaderBuffer densityCurrent = data.densityBuffer;
|
Gfx::PShaderBuffer densityCurrent = data.densityBuffer;
|
||||||
Gfx::PShaderBuffer densityNext = data.scratchBuffer;
|
|
||||||
Gfx::PShaderBuffer density0 = data.density0Buffer;
|
Gfx::PShaderBuffer density0 = data.density0Buffer;
|
||||||
graphics->copyBuffer(density0, densityCurrent);
|
graphics->copyBuffer(density0, densityCurrent);
|
||||||
densityCurrent->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
|
densityCurrent->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
|
||||||
@@ -423,24 +417,23 @@ void SimulationComputePass::render() {
|
|||||||
for (int iteration = 0; iteration < densityDiffuseIterations; ++iteration) {
|
for (int iteration = 0; iteration < densityDiffuseIterations; ++iteration) {
|
||||||
float a = data.dt * data.diffusion * (data.gridSize.x - 2) * (data.gridSize.x - 2);
|
float a = data.dt * data.diffusion * (data.gridSize.x - 2) * (data.gridSize.x - 2);
|
||||||
float c = 1 + 6 * a;
|
float c = 1 + 6 * a;
|
||||||
linearSolvePass(densityNext, densityCurrent, density0, a, c, data.gridSize);
|
linearSolvePass(densityCurrent, density0, a, c, diffusionSORomega, data.gridSize);
|
||||||
setBoundsPass(densityNext, 0, data.gridSize);
|
setBoundsPass(densityCurrent, 0, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
SWAP(densityCurrent, densityNext);
|
|
||||||
}
|
}
|
||||||
graphics->endDebugRegion();
|
graphics->endDebugRegion();
|
||||||
graphics->beginDebugRegion("AdvectDensity");
|
graphics->beginDebugRegion("AdvectDensity");
|
||||||
advectPass(data.density0Buffer, densityCurrent, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, data.dt,
|
advectPass(data.density0Buffer, densityCurrent, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, data.dt,
|
||||||
data.gridSize);
|
data.gridSize);
|
||||||
setBoundsPass(data.density0Buffer, 0, data.gridSize);
|
setBoundsPass(data.density0Buffer, 0, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
graphics->endDebugRegion();
|
graphics->endDebugRegion();
|
||||||
|
|
||||||
graphics->beginDebugRegion("AdvectLevelSet");
|
graphics->beginDebugRegion("AdvectLevelSet");
|
||||||
advectPass(data.phiBuffer, data.phi0Buffer, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, data.dt, data.gridSize);
|
advectPass(data.phiBuffer, data.phi0Buffer, data.velocityX0Buffer, data.velocityY0Buffer, data.velocityZ0Buffer, data.dt, data.gridSize);
|
||||||
setBoundsPass(data.phiBuffer, 0, data.gridSize);
|
setBoundsPass(data.phiBuffer, 0, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
|
|
||||||
// Reinitialize level set every N frames to restore |grad phi| = 1
|
// Reinitialize level set every N frames to restore |grad phi| = 1
|
||||||
if (data.frameCounter % reinitInterval == 0) {
|
if (data.frameCounter % reinitInterval == 0) {
|
||||||
reinitializeLevelSetPass(data.phiBuffer, data.phi0Buffer, data.gridSize);
|
reinitializeLevelSetPass(data.phiBuffer, data.phi0Buffer, data.scratchBuffer, data.gridSize, data.planeBuffer, data.numPlanes);
|
||||||
}
|
}
|
||||||
++data.frameCounter;
|
++data.frameCounter;
|
||||||
|
|
||||||
@@ -467,65 +460,46 @@ UVector SimulationComputePass::getDispatchSize(const UVector& gridSize, const UV
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulationComputePass::setBoundsPass(Gfx::PShaderBuffer grid, int b, UVector gridSize) {
|
void SimulationComputePass::setBoundsPass(Gfx::PShaderBuffer grid, int b, UVector gridSize, Gfx::PShaderBuffer planeBuffer, uint32 numPlanes) {
|
||||||
Gfx::ODescriptorSet bounds = setBounds.descriptorLayout->allocateDescriptorSet();
|
Gfx::ODescriptorSet bounds = setBounds.descriptorLayout->allocateDescriptorSet();
|
||||||
bounds->updateConstants("b", 0, &b);
|
bounds->updateConstants("b", 0, &b);
|
||||||
|
bounds->updateConstants("numPlanes", 0, &numPlanes);
|
||||||
|
bounds->updateBuffer("planes", 0, planeBuffer);
|
||||||
bounds->updateBuffer("grid", 0, grid);
|
bounds->updateBuffer("grid", 0, grid);
|
||||||
bounds->writeChanges();
|
bounds->writeChanges();
|
||||||
Gfx::OComputeCommand boundsCommand = graphics->createComputeCommand();
|
Gfx::OComputeCommand boundsCommand = graphics->createComputeCommand();
|
||||||
boundsCommand->bindPipeline(setBounds.pipeline);
|
boundsCommand->bindPipeline(setBounds.pipeline);
|
||||||
boundsCommand->bindDescriptor(bounds);
|
boundsCommand->bindDescriptor(bounds);
|
||||||
boundsCommand->bindDescriptor(gridSizeSet);
|
boundsCommand->bindDescriptor(gridSizeSet);
|
||||||
// Dispatch covers max(gridSize.x, gridSize.y) x max(gridSize.y, gridSize.z) to handle all faces on non-cubic grids
|
auto dispatchSize = getDispatchSize(gridSize, setBounds.threadGroupSize);
|
||||||
UVector faceDispatchGrid = {std::max(gridSize.x, gridSize.y), std::max(gridSize.y, gridSize.z), 1};
|
boundsCommand->dispatch(dispatchSize.x, dispatchSize.y, dispatchSize.z);
|
||||||
auto dispatchSize = getDispatchSize(faceDispatchGrid, setBounds.threadGroupSize);
|
|
||||||
boundsCommand->dispatch(dispatchSize.x, dispatchSize.y, 1);
|
|
||||||
graphics->executeCommands(std::move(boundsCommand));
|
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,
|
|
||||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
|
||||||
|
|
||||||
Gfx::OComputeCommand edgesCommand = graphics->createComputeCommand();
|
|
||||||
edgesCommand->bindPipeline(setBounds.pipelineEdges);
|
|
||||||
edgesCommand->bindDescriptor(bounds);
|
|
||||||
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,
|
|
||||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
grid->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
|
grid->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);
|
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulationComputePass::linearSolvePass(Gfx::PShaderBuffer next, Gfx::PShaderBuffer current, Gfx::PShaderBuffer grid0, float a, float c,
|
void SimulationComputePass::linearSolvePass(Gfx::PShaderBuffer grid, Gfx::PShaderBuffer grid0, float a, float c, float omega,
|
||||||
UVector gridSize) {
|
UVector gridSize) {
|
||||||
Gfx::ODescriptorSet solve = linearSolve.descriptorLayout->allocateDescriptorSet();
|
for (int color = 0; color < 2; ++color) {
|
||||||
solve->updateBuffer("next", 0, next);
|
Gfx::ODescriptorSet solve = linearSolve.descriptorLayout->allocateDescriptorSet();
|
||||||
solve->updateBuffer("current", 0, current);
|
solve->updateBuffer("grid", 0, grid);
|
||||||
solve->updateBuffer("grid0", 0, grid0);
|
solve->updateBuffer("grid0", 0, grid0);
|
||||||
solve->updateConstants("a", 0, &a);
|
solve->updateConstants("a", 0, &a);
|
||||||
solve->updateConstants("c", 0, &c);
|
solve->updateConstants("c", 0, &c);
|
||||||
solve->writeChanges();
|
solve->updateConstants("omega", 0, &omega);
|
||||||
Gfx::OComputeCommand solveCommand = graphics->createComputeCommand();
|
solve->updateConstants("color", 0, &color);
|
||||||
solveCommand->bindPipeline(linearSolve.pipeline);
|
solve->writeChanges();
|
||||||
solveCommand->bindDescriptor(solve);
|
Gfx::OComputeCommand solveCommand = graphics->createComputeCommand();
|
||||||
solveCommand->bindDescriptor(gridSizeSet);
|
solveCommand->bindPipeline(linearSolve.pipeline);
|
||||||
solveCommand->dispatch(getDispatchSize(gridSize, linearSolve.threadGroupSize));
|
solveCommand->bindDescriptor(solve);
|
||||||
graphics->executeCommands(std::move(solveCommand));
|
solveCommand->bindDescriptor(gridSizeSet);
|
||||||
|
solveCommand->dispatch(getDispatchSize(gridSize, linearSolve.threadGroupSize));
|
||||||
|
graphics->executeCommands(std::move(solveCommand));
|
||||||
|
|
||||||
next->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
|
grid->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);
|
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void SimulationComputePass::divergencePass(Seele::Gfx::PShaderBuffer divergence, Seele::Gfx::PShaderBuffer pressure,
|
void SimulationComputePass::divergencePass(Seele::Gfx::PShaderBuffer divergence, Seele::Gfx::PShaderBuffer pressure,
|
||||||
Seele::Gfx::PShaderBuffer velocityX, Seele::Gfx::PShaderBuffer velocityY,
|
Seele::Gfx::PShaderBuffer velocityX, Seele::Gfx::PShaderBuffer velocityY,
|
||||||
@@ -617,11 +591,15 @@ void SimulationComputePass::applyForcesPass(Gfx::PShaderBuffer velocityX, Gfx::P
|
|||||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulationComputePass::reinitializeLevelSetPass(Seele::Gfx::PShaderBuffer phi, Seele::Gfx::PShaderBuffer phi0, UVector gridSize) {
|
void SimulationComputePass::reinitializeLevelSetPass(Seele::Gfx::PShaderBuffer phi, Seele::Gfx::PShaderBuffer phi0, Seele::Gfx::PShaderBuffer phiSign, UVector gridSize, Gfx::PShaderBuffer planeBuffer, uint32 numPlanes) {
|
||||||
graphics->beginDebugRegion("ReinitializeLevelSet");
|
graphics->beginDebugRegion("ReinitializeLevelSet");
|
||||||
// Snapshot current phi into phi0 for the sign function
|
// Snapshot current phi into phiSign for the sign function (preserved across all iterations)
|
||||||
phi->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_TRANSFER_READ_BIT,
|
phi->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_TRANSFER_READ_BIT,
|
||||||
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
|
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
|
||||||
|
graphics->copyBuffer(phi, phiSign);
|
||||||
|
phiSign->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);
|
||||||
|
// Also copy phi into phi0 as the "previous iteration" input for iteration 0
|
||||||
graphics->copyBuffer(phi, phi0);
|
graphics->copyBuffer(phi, phi0);
|
||||||
phi0->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
|
phi0->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);
|
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||||
@@ -633,7 +611,8 @@ void SimulationComputePass::reinitializeLevelSetPass(Seele::Gfx::PShaderBuffer p
|
|||||||
Gfx::ODescriptorSet reinitSet = reinitialize.descriptorLayout->allocateDescriptorSet();
|
Gfx::ODescriptorSet reinitSet = reinitialize.descriptorLayout->allocateDescriptorSet();
|
||||||
reinitSet->updateConstants("dtau", 0, &dtau);
|
reinitSet->updateConstants("dtau", 0, &dtau);
|
||||||
reinitSet->updateBuffer("phi", 0, phi);
|
reinitSet->updateBuffer("phi", 0, phi);
|
||||||
reinitSet->updateBuffer("phi0", 0, phi0);
|
reinitSet->updateBuffer("phiPrev", 0, phi0);
|
||||||
|
reinitSet->updateBuffer("phiSign", 0, phiSign);
|
||||||
reinitSet->writeChanges();
|
reinitSet->writeChanges();
|
||||||
Gfx::OComputeCommand reinitCommand = graphics->createComputeCommand();
|
Gfx::OComputeCommand reinitCommand = graphics->createComputeCommand();
|
||||||
reinitCommand->bindPipeline(reinitialize.pipeline);
|
reinitCommand->bindPipeline(reinitialize.pipeline);
|
||||||
@@ -644,8 +623,15 @@ void SimulationComputePass::reinitializeLevelSetPass(Seele::Gfx::PShaderBuffer p
|
|||||||
|
|
||||||
phi->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
|
phi->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);
|
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||||
setBoundsPass(phi, 0, gridSize);
|
setBoundsPass(phi, 0, gridSize, planeBuffer, numPlanes);
|
||||||
SWAP(phi, phi0);
|
// Copy result to phi0 for the next iteration's gradient reads
|
||||||
|
phi->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_TRANSFER_READ_BIT,
|
||||||
|
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
|
||||||
|
graphics->copyBuffer(phi, phi0);
|
||||||
|
phi0->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);
|
||||||
|
phi->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_READ_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
|
||||||
|
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||||
}
|
}
|
||||||
graphics->endDebugRegion();
|
graphics->endDebugRegion();
|
||||||
}
|
}
|
||||||
@@ -20,25 +20,21 @@ class SimulationComputePass : public RenderPass {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
UVector getDispatchSize(const UVector& gridSize, const UVector& threadGroupSize);
|
UVector getDispatchSize(const UVector& gridSize, const UVector& threadGroupSize);
|
||||||
void setBoundsPass(Gfx::PShaderBuffer buffer, int b, UVector gridSize);
|
void setBoundsPass(Gfx::PShaderBuffer buffer, int b, UVector gridSize, Gfx::PShaderBuffer planeBuffer, uint32 numPlanes);
|
||||||
void linearSolvePass(Gfx::PShaderBuffer next, Seele::Gfx::PShaderBuffer current, Seele::Gfx::PShaderBuffer grid0, float a, float c, UVector gridSize);
|
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,
|
void divergencePass(Gfx::PShaderBuffer divergence, Seele::Gfx::PShaderBuffer pressure, Seele::Gfx::PShaderBuffer velocityX,
|
||||||
Seele::Gfx::PShaderBuffer velocityY, Seele::Gfx::PShaderBuffer velocityZ, UVector gridSize);
|
Seele::Gfx::PShaderBuffer velocityY, Seele::Gfx::PShaderBuffer velocityZ, UVector gridSize);
|
||||||
void projectPass(Gfx::PShaderBuffer velocityX, Seele::Gfx::PShaderBuffer velocityY, Seele::Gfx::PShaderBuffer velocityZ,
|
void projectPass(Gfx::PShaderBuffer velocityX, Seele::Gfx::PShaderBuffer velocityY, Seele::Gfx::PShaderBuffer velocityZ,
|
||||||
Seele::Gfx::PShaderBuffer pressure, UVector gridSize);
|
Seele::Gfx::PShaderBuffer pressure, UVector gridSize);
|
||||||
void advectPass(Gfx::PShaderBuffer quantity, Seele::Gfx::PShaderBuffer quantity0, Seele::Gfx::PShaderBuffer velocityX,
|
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);
|
Seele::Gfx::PShaderBuffer velocityY, Seele::Gfx::PShaderBuffer velocityZ, float dt, UVector gridSize);
|
||||||
void reinitializeLevelSetPass(Gfx::PShaderBuffer phi, Seele::Gfx::PShaderBuffer phi0, UVector gridSize);
|
void reinitializeLevelSetPass(Gfx::PShaderBuffer phi, Seele::Gfx::PShaderBuffer phi0, Seele::Gfx::PShaderBuffer phiSign, UVector gridSize, Gfx::PShaderBuffer planeBuffer, uint32 numPlanes);
|
||||||
struct SetBounds {
|
struct SetBounds {
|
||||||
Gfx::OPipelineLayout pipelineLayout;
|
Gfx::OPipelineLayout pipelineLayout;
|
||||||
Gfx::ODescriptorLayout descriptorLayout;
|
Gfx::ODescriptorLayout descriptorLayout;
|
||||||
Gfx::OComputeShader shader;
|
Gfx::OComputeShader shader;
|
||||||
Gfx::PComputePipeline pipeline;
|
Gfx::PComputePipeline pipeline;
|
||||||
Gfx::OComputeShader shaderEdges;
|
constexpr static UVector threadGroupSize = {4, 4, 4};
|
||||||
Gfx::PComputePipeline pipelineEdges;
|
|
||||||
Gfx::OComputeShader shaderCorners;
|
|
||||||
Gfx::PComputePipeline pipelineCorners;
|
|
||||||
constexpr static UVector threadGroupSize = {32, 8, 1};
|
|
||||||
} setBounds;
|
} setBounds;
|
||||||
struct LinearSolve {
|
struct LinearSolve {
|
||||||
Gfx::OPipelineLayout pipelineLayout;
|
Gfx::OPipelineLayout pipelineLayout;
|
||||||
@@ -85,6 +81,10 @@ class SimulationComputePass : public RenderPass {
|
|||||||
void applyForcesPass(Gfx::PShaderBuffer velocityX, Gfx::PShaderBuffer velocityY, Gfx::PShaderBuffer velocityZ, Vector gravity, float dt, UVector gridSize);
|
void applyForcesPass(Gfx::PShaderBuffer velocityX, Gfx::PShaderBuffer velocityY, Gfx::PShaderBuffer velocityZ, Vector gravity, float dt, UVector gridSize);
|
||||||
Gfx::ODescriptorLayout gridSizeLayout;
|
Gfx::ODescriptorLayout gridSizeLayout;
|
||||||
Gfx::ODescriptorSet gridSizeSet;
|
Gfx::ODescriptorSet gridSizeSet;
|
||||||
|
struct BoundaryPlane {
|
||||||
|
Vector normal;
|
||||||
|
float d;
|
||||||
|
};
|
||||||
PScene scene;
|
PScene scene;
|
||||||
};
|
};
|
||||||
DEFINE_REF(SimulationComputePass)
|
DEFINE_REF(SimulationComputePass)
|
||||||
|
|||||||
@@ -722,6 +722,11 @@ PDestructionManager Graphics::getDestructionManager() { return destructionManage
|
|||||||
|
|
||||||
Array<const char*> Graphics::getRequiredExtensions() {
|
Array<const char*> Graphics::getRequiredExtensions() {
|
||||||
Array<const char*> extensions;
|
Array<const char*> extensions;
|
||||||
|
const auto availableExtensions = enumerateInstanceExtensions();
|
||||||
|
|
||||||
|
auto supportsExtension = [&](const char* extensionName) {
|
||||||
|
return hasInstanceExtension(availableExtensions, extensionName);
|
||||||
|
};
|
||||||
|
|
||||||
unsigned int glfwExtensionCount = 0;
|
unsigned int glfwExtensionCount = 0;
|
||||||
const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
|
const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
|
||||||
@@ -741,22 +746,41 @@ Array<const char*> Graphics::getRequiredExtensions() {
|
|||||||
#if defined(GLFW_PLATFORM_WAYLAND) && defined(GLFW_PLATFORM_X11)
|
#if defined(GLFW_PLATFORM_WAYLAND) && defined(GLFW_PLATFORM_X11)
|
||||||
const int platform = glfwGetPlatform();
|
const int platform = glfwGetPlatform();
|
||||||
if (platform == GLFW_PLATFORM_WAYLAND) {
|
if (platform == GLFW_PLATFORM_WAYLAND) {
|
||||||
extensions.addUnique("VK_KHR_wayland_surface");
|
if (supportsExtension("VK_KHR_wayland_surface")) {
|
||||||
|
extensions.addUnique("VK_KHR_wayland_surface");
|
||||||
|
}
|
||||||
} else if (platform == GLFW_PLATFORM_X11) {
|
} else if (platform == GLFW_PLATFORM_X11) {
|
||||||
extensions.addUnique("VK_KHR_xlib_surface");
|
if (supportsExtension("VK_KHR_xlib_surface")) {
|
||||||
extensions.addUnique("VK_KHR_xcb_surface");
|
extensions.addUnique("VK_KHR_xlib_surface");
|
||||||
|
}
|
||||||
|
if (supportsExtension("VK_KHR_xcb_surface")) {
|
||||||
|
extensions.addUnique("VK_KHR_xcb_surface");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
extensions.addUnique("VK_KHR_wayland_surface");
|
if (supportsExtension("VK_KHR_wayland_surface")) {
|
||||||
extensions.addUnique("VK_KHR_xlib_surface");
|
extensions.addUnique("VK_KHR_wayland_surface");
|
||||||
extensions.addUnique("VK_KHR_xcb_surface");
|
}
|
||||||
|
if (supportsExtension("VK_KHR_xlib_surface")) {
|
||||||
|
extensions.addUnique("VK_KHR_xlib_surface");
|
||||||
|
}
|
||||||
|
if (supportsExtension("VK_KHR_xcb_surface")) {
|
||||||
|
extensions.addUnique("VK_KHR_xcb_surface");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
bool isWayland = std::getenv("WAYLAND_DISPLAY") != nullptr;
|
bool isWayland = std::getenv("WAYLAND_DISPLAY") != nullptr;
|
||||||
if (isWayland) {
|
if (isWayland && supportsExtension("VK_KHR_wayland_surface")) {
|
||||||
extensions.addUnique("VK_KHR_wayland_surface");
|
extensions.addUnique("VK_KHR_wayland_surface");
|
||||||
} else {
|
} else {
|
||||||
extensions.addUnique("VK_KHR_xlib_surface");
|
if (supportsExtension("VK_KHR_xlib_surface")) {
|
||||||
extensions.addUnique("VK_KHR_xcb_surface");
|
extensions.addUnique("VK_KHR_xlib_surface");
|
||||||
|
}
|
||||||
|
if (supportsExtension("VK_KHR_xcb_surface")) {
|
||||||
|
extensions.addUnique("VK_KHR_xcb_surface");
|
||||||
|
}
|
||||||
|
if (extensions.size() == 1 && supportsExtension("VK_KHR_wayland_surface")) {
|
||||||
|
extensions.addUnique("VK_KHR_wayland_surface");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
@@ -769,7 +793,39 @@ Array<const char*> Graphics::getRequiredExtensions() {
|
|||||||
#ifdef ENABLE_VALIDATION
|
#ifdef ENABLE_VALIDATION
|
||||||
extensions.addUnique(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
extensions.addUnique(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||||
#endif
|
#endif
|
||||||
return extensions;
|
|
||||||
|
Array<const char*> validatedExtensions;
|
||||||
|
for (uint32 i = 0; i < extensions.size(); ++i) {
|
||||||
|
const char* extensionName = extensions[i];
|
||||||
|
if (supportsExtension(extensionName)) {
|
||||||
|
validatedExtensions.addUnique(extensionName);
|
||||||
|
} else {
|
||||||
|
std::cerr << "Warning: Vulkan instance extension not exposed by loader, skipping: " << extensionName << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto hasValidatedExtension = [&](const char* extensionName) {
|
||||||
|
for (uint32 i = 0; i < validatedExtensions.size(); ++i) {
|
||||||
|
if (std::strcmp(validatedExtensions[i], extensionName) == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// VK_KHR_surface is required for GLFW window surface creation.
|
||||||
|
if (!hasValidatedExtension(VK_KHR_SURFACE_EXTENSION_NAME)) {
|
||||||
|
throw std::runtime_error("Missing required Vulkan instance extension VK_KHR_surface");
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool hasWayland = hasValidatedExtension("VK_KHR_wayland_surface");
|
||||||
|
const bool hasXlib = hasValidatedExtension("VK_KHR_xlib_surface");
|
||||||
|
const bool hasXcb = hasValidatedExtension("VK_KHR_xcb_surface");
|
||||||
|
if (!hasWayland && !hasXlib && !hasXcb) {
|
||||||
|
throw std::runtime_error("Missing required Vulkan WSI instance extensions (need one of VK_KHR_wayland_surface, VK_KHR_xlib_surface, VK_KHR_xcb_surface)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return validatedExtensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::initInstance(GraphicsInitializer initInfo) {
|
void Graphics::initInstance(GraphicsInitializer initInfo) {
|
||||||
@@ -804,6 +860,12 @@ void Graphics::initInstance(GraphicsInitializer initInfo) {
|
|||||||
.enabledExtensionCount = (uint32)extensions.size(),
|
.enabledExtensionCount = (uint32)extensions.size(),
|
||||||
.ppEnabledExtensionNames = extensions.data(),
|
.ppEnabledExtensionNames = extensions.data(),
|
||||||
};
|
};
|
||||||
|
std::cout << "Enabled Extensions: ";
|
||||||
|
for(uint i = 0; i < extensions.size(); ++i)
|
||||||
|
{
|
||||||
|
std::cout << extensions[i] << " ";
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
VK_CHECK(vkCreateInstance(&info, nullptr, &instance));
|
VK_CHECK(vkCreateInstance(&info, nullptr, &instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -210,6 +210,30 @@ void FluidScene::updateFluidData(uint32 entityID, const Component::Transform& tr
|
|||||||
data.gridSize = grid.gridSize;
|
data.gridSize = grid.gridSize;
|
||||||
data.gravity = grid.gravity;
|
data.gravity = grid.gravity;
|
||||||
data.enableGravity = grid.enableGravity;
|
data.enableGravity = grid.enableGravity;
|
||||||
|
|
||||||
|
// Build plane list: 6 cube walls + user-defined extra planes
|
||||||
|
struct GPUPlane { Vector normal; float d; };
|
||||||
|
Array<GPUPlane> planes;
|
||||||
|
// Cube wall planes (inward normal, solid when dot(n,p)+d < 0)
|
||||||
|
planes.add({{1, 0, 0}, -0.5f});
|
||||||
|
planes.add({{-1, 0, 0}, static_cast<float>(grid.gridSize.x) - 1.5f});
|
||||||
|
planes.add({{0, 1, 0}, -0.5f});
|
||||||
|
planes.add({{0, -1, 0}, static_cast<float>(grid.gridSize.y) - 1.5f});
|
||||||
|
planes.add({{0, 0, 1}, -0.5f});
|
||||||
|
planes.add({{0, 0, -1}, static_cast<float>(grid.gridSize.z) - 1.5f});
|
||||||
|
for (const auto& ep : grid.extraPlanes) {
|
||||||
|
planes.add({ep.normal, ep.d});
|
||||||
|
}
|
||||||
|
data.numPlanes = static_cast<uint32>(planes.size());
|
||||||
|
data.planeBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||||
|
.sourceData =
|
||||||
|
{
|
||||||
|
.size = static_cast<uint64>(planes.size() * sizeof(GPUPlane)),
|
||||||
|
.data = reinterpret_cast<uint8*>(planes.data()),
|
||||||
|
},
|
||||||
|
.numElements = static_cast<uint64>(planes.size()),
|
||||||
|
.name = "PlaneBuffer",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluidScene::addSource() {
|
void FluidScene::addSource() {
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ class FluidScene {
|
|||||||
Gfx::OShaderBuffer normalBuffer;
|
Gfx::OShaderBuffer normalBuffer;
|
||||||
Gfx::OShaderBuffer indexBuffer;
|
Gfx::OShaderBuffer indexBuffer;
|
||||||
Gfx::OShaderBuffer surfaceCountBuffer;
|
Gfx::OShaderBuffer surfaceCountBuffer;
|
||||||
|
Gfx::OShaderBuffer planeBuffer;
|
||||||
|
uint32 numPlanes = 0;
|
||||||
uint32 frameCounter = 0;
|
uint32 frameCounter = 0;
|
||||||
constexpr uint getVertexBufferSize() {
|
constexpr uint getVertexBufferSize() {
|
||||||
// Max 5 triangles per cell, 3 vertices per triangle
|
// Max 5 triangles per cell, 3 vertices per triangle
|
||||||
|
|||||||
+16
@@ -1,5 +1,21 @@
|
|||||||
{
|
{
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
|
{
|
||||||
|
"name": "vulkan-loader",
|
||||||
|
"features": [
|
||||||
|
"xlib",
|
||||||
|
"xcb",
|
||||||
|
"wayland"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "vulkan-loader",
|
||||||
|
"features": [
|
||||||
|
"xlib",
|
||||||
|
"xcb",
|
||||||
|
"wayland"
|
||||||
|
]
|
||||||
|
},
|
||||||
"vulkan",
|
"vulkan",
|
||||||
{
|
{
|
||||||
"name": "vulkan-memory-allocator"
|
"name": "vulkan-memory-allocator"
|
||||||
|
|||||||
Reference in new issue
Block a user