Skip to content

Commit

Permalink
Construct grid buffer in sim module as temporary allocation. Remove s…
Browse files Browse the repository at this point in the history
…tray log.
  • Loading branch information
Chris Lewin committed Aug 12, 2024
1 parent bb62c94 commit 2547972
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ function loadScene(json)
ui.setUIElementsToDefault();
if(json.version >= 2)
{
console.log(json.settings);
ui.setUIElements(json.settings)
}
}
Expand Down
17 changes: 14 additions & 3 deletions src/sim.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ export function update(gpuContext, inputs)
const shapeBuffer = constructShapeBuffer(gpuContext, inputs);
const bukkitSystem = constructBukkitSystem(gpuContext, inputs);

let gridBuffers = [];

for(let i = 0; i < 3; ++i)
{
gridBuffers.push(gpuContext.device.createBuffer({
label: `gridBuffer${i}`,
size: inputs.gridSize[0] * inputs.gridSize[1] * 4 * 4,
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
}));
}

const substepCount = time.doTimeRegulation(inputs);
for(let substepIdx = 0; substepIdx < substepCount; ++substepIdx)
{
Expand All @@ -182,9 +193,9 @@ export function update(gpuContext, inputs)
{
simUniformBuffer = constructSimUniformBuffer(gpuContext, inputs, bukkitSystem, iterationIdx);

const currentGrid = gpuContext.gridBuffers[bufferIdx]
const nextGrid = gpuContext.gridBuffers[(bufferIdx + 1)%3]
const nextNextGrid = gpuContext.gridBuffers[(bufferIdx + 2)%3]
const currentGrid = gridBuffers[bufferIdx]
const nextGrid = gridBuffers[(bufferIdx + 1)%3]
const nextNextGrid = gridBuffers[(bufferIdx + 2)%3]
bufferIdx = (bufferIdx + 1) % 3;

gpu.computeDispatch(Shaders.g2p2g, [simUniformBuffer, gpuContext.particleBuffer, currentGrid, nextGrid, nextNextGrid, bukkitSystem.threadData, bukkitSystem.particleData, shapeBuffer, gpuContext.particleFreeIndicesBuffer], bukkitSystem.dispatch)
Expand Down

0 comments on commit 2547972

Please sign in to comment.