-
-
Notifications
You must be signed in to change notification settings - Fork 48
docs: ducks #2018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
docs: ducks #2018
Conversation
|
pkg.pr.new packages benchmark commit |
📊 Bundle Size Comparison📈 Summary
📋 Bundle Size Comparison
|
|
Comments in the code resemble comments in the og code, so it's easier to understand where something came from. |
reczkok
left a comment
There was a problem hiding this 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.
| 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 }); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
| 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 }); | |
| }; |
New example, ported from threejs