Skip to content

Commit efd8217

Browse files
committed
Simplify auto-spreading to use 2D square for all cases based on benchmark results
1 parent fad5960 commit efd8217

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

src/webgpu/p5.RendererWebGPU.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,21 +3827,16 @@ ${hookUniformFields}}
38273827
const isLarge1D = totalIterations > 1024 && y === 1 && z === 1;
38283828

38293829
if (exceedsLimits || isLarge1D) {
3830-
if (totalIterations > 1000000) {
3831-
// 3D cube type for extreme large counts
3832-
px = Math.ceil(Math.pow(totalIterations, 1 / 3));
3833-
py = Math.ceil(Math.pow(totalIterations, 1 / 3));
3834-
pz = Math.ceil(totalIterations / (px * py));
3835-
} else {
3836-
// 2D square type for moderate large counts
3837-
px = Math.ceil(Math.sqrt(totalIterations));
3838-
py = Math.ceil(totalIterations / px);
3839-
pz = 1;
3840-
}
3830+
// Always use 2D square spreading (√N × √N).
3831+
// Benchmarks showed 2D square equals or outperforms 3D cube at every
3832+
// scale tested, with simpler index reconstruction in the shader.
3833+
px = Math.ceil(Math.sqrt(totalIterations));
3834+
py = Math.ceil(totalIterations / px);
3835+
pz = 1;
38413836

38423837
if (p5.debug || exceedsLimits) {
38433838
console.warn(
3844-
`p5.js: Compute dispatch (${x}, ${y}, ${z}) auto-spread to (${px}, ${py}, ${pz}) ` +
3839+
`p5.js: Compute dispatch (${x}, ${y}, ${z}) auto-spread to (${px}, ${py}, 1) ` +
38453840
`to ${exceedsLimits ? 'stay within GPU limits' : 'optimize performance'}.`
38463841
);
38473842
}

0 commit comments

Comments
 (0)