Skip to content

Conversation

@lursz
Copy link
Contributor

@lursz lursz commented Jan 8, 2026

New example, ported from threejs

@lursz lursz changed the title Docs: ducks docs: ducks Jan 8, 2026
@github-actions
Copy link

github-actions bot commented Jan 8, 2026

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@95ad4ee68b472da48848c295a3836ec3513b2ffc
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@95ad4ee68b472da48848c295a3836ec3513b2ffc
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@95ad4ee68b472da48848c295a3836ec3513b2ffc

benchmark
view benchmark

commit
view commit

@github-actions
Copy link

github-actions bot commented Jan 13, 2026

📊 Bundle Size Comparison

📈 Summary

  • 📈 Increased: 0 bundles

  • 📉 Decreased: 0 bundles

  • Unchanged: 24 bundles

  • Unknown: 0 bundles

📋 Bundle Size Comparison

Test tsdown webpack
dataImportEverything.ts 80.03 kB (➖) 85.34 kB (➖)
dataImportOneDirect.ts 40.28 kB (➖) 40.75 kB (➖)
dataImportOneStar.ts 40.28 kB (➖) 40.75 kB (➖)
functionWithUseGpu.ts 268 B (➖) 276 B (➖)
functionWithoutUseGpu.ts 24 B (➖) 59 B (➖)
importEntireLibrary.ts 256.73 kB (➖) 283.79 kB (➖)
importEntireLibraryUnused.ts 0 B (➖) 0 B (➖)
stdImportEverything.ts 113.10 kB (➖) 117.60 kB (➖)
stdImportOneDirect.ts 61.97 kB (➖) 62.92 kB (➖)
stdImportOneStar.ts 61.97 kB (➖) 62.92 kB (➖)
tgpuImportEverything.ts 237.74 kB (➖) 264.42 kB (➖)
tgpuImportOne.ts 237.75 kB (➖) 264.43 kB (➖)

@lursz
Copy link
Contributor Author

lursz commented Jan 13, 2026

Comments in the code resemble comments in the og code, so it's easier to understand where something came from.

@lursz lursz marked this pull request as ready for review January 13, 2026 09:04
Copy link
Contributor

@reczkok reczkok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple of problems with this PR:

  • The TGSL functions wouldn’t want to make me use TypeGPU - please move to normal operators and go through the logic to eliminate useless casts, etc.
  • Take advantage of TypeGPU mechanics (like slots) to make the logic nicer. computeHeightBtoA and computeHeightAtoB are basically the same, so you could halve the code using slots (I’m pretty sure).
  • Separating gpuHelpers into a separate file makes no sense to me if you need to create them using a function. I would either figure out a way to make the helpers top‑level (which I’m pretty sure is possible using accessors/slots) or not do it at all.

Comment on lines +12 to +29
const getNeighborIndices = (index: number) => {
'use gpu';
const width = d.u32(WIDTH);
const x = d.i32(std.mod(index, WIDTH));
const y = d.i32(std.div(index, WIDTH));

const leftX = std.max(0, std.sub(x, 1));
const rightX = std.min(std.add(x, 1), std.sub(d.i32(width), 1));
const bottomY = std.max(0, std.sub(y, 1));
const topY = std.min(std.add(y, 1), std.sub(d.i32(width), 1));

const westIndex = d.u32(std.add(std.mul(y, d.i32(width)), leftX));
const eastIndex = d.u32(std.add(std.mul(y, d.i32(width)), rightX));
const southIndex = d.u32(std.add(std.mul(bottomY, d.i32(width)), x));
const northIndex = d.u32(std.add(std.mul(topY, d.i32(width)), x));

return NeighborIndices({ northIndex, southIndex, eastIndex, westIndex });
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Suggested change
const getNeighborIndices = (index: number) => {
'use gpu';
const width = d.u32(WIDTH);
const x = d.i32(std.mod(index, WIDTH));
const y = d.i32(std.div(index, WIDTH));
const leftX = std.max(0, std.sub(x, 1));
const rightX = std.min(std.add(x, 1), std.sub(d.i32(width), 1));
const bottomY = std.max(0, std.sub(y, 1));
const topY = std.min(std.add(y, 1), std.sub(d.i32(width), 1));
const westIndex = d.u32(std.add(std.mul(y, d.i32(width)), leftX));
const eastIndex = d.u32(std.add(std.mul(y, d.i32(width)), rightX));
const southIndex = d.u32(std.add(std.mul(bottomY, d.i32(width)), x));
const northIndex = d.u32(std.add(std.mul(topY, d.i32(width)), x));
return NeighborIndices({ northIndex, southIndex, eastIndex, westIndex });
};
const getNeighborIndices = (index: number) => {
'use gpu';
const width = d.u32(WIDTH);
const x = index % WIDTH;
const y = d.u32(index / WIDTH);
const leftX = std.max(0, x - 1);
const rightX = std.min(x + 1, width - 1);
const bottomY = std.max(0, y - 1);
const topY = std.min(y + 1, width - 1);
const westIndex = y * width + leftX;
const eastIndex = y * width + rightX;
const southIndex = bottomY * width + x;
const northIndex = topY * width + x;
return NeighborIndices({ northIndex, southIndex, eastIndex, westIndex });
};

@lursz lursz marked this pull request as draft January 23, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants