Skip to content
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

FR: add expression evaluation in defines #14

Open
munrocket opened this issue Oct 7, 2023 · 2 comments
Open

FR: add expression evaluation in defines #14

munrocket opened this issue Oct 7, 2023 · 2 comments

Comments

@munrocket
Copy link
Contributor

Add WIN_WIDTH / WIN_HEIGHT in prelude with ability to write expressions in defines

// usual case
#define GROUP_COUNT_X WIN_WIDTH/16
#define GROUP_COUNT_Y WIN_HEIGHT/16

// example 1
struct Data {
  foo: array<array<u32, GROUP_COUNT_Y>, GROUP_COUNT_X>
}
#storage data Data

// example 2 (this calculated automatically somehow)
#workgroup_count bar GROUP_COUNT_X GROUP_COUNT_Y 1
@compute @workgroup_size(16, 16)
fn bar(@builtin(global_invocation_id) gid: vec3u) {
  //...
}
@munrocket
Copy link
Contributor Author

Basically it Is the same as @Builtin(num_workgroups) but in top level. Without this code become not portable or slow.

@davidar
Copy link
Contributor

davidar commented Oct 13, 2023

The preprocessor already defines SCREEN_WIDTH and SCREEN_HEIGHT https://github.com/compute-toys/wgpu-compute-toy/blob/master/src/lib.rs#L470-L471

Perhaps that could be documented better.

Evaluating constant expressions in the preprocessor would be handy, ideally we could use some library for that to avoid adding too much ad hoc complexity.

@munrocket munrocket changed the title FR: add WIN_WIDTH / WIN_HEIGHT in prelude + expressions in defines FR: add expression evaluation in defines Oct 19, 2023
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

No branches or pull requests

2 participants