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

Provide a way to fetch whether a ShaderType is runtime sized or not #37

Open
james7132 opened this issue Apr 10, 2023 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@james7132
Copy link
Contributor

It's currently not possible to check if a type T: ShaderType is runtime sized or not. This makes it difficult, in generic code, to tell if one can assume that the T::min_size can be used to accurately estimate how large a preallocated buffer needs to be to fit N elements of T. This mandates the use of dynamic allocation

The motivation here is to support use cases that directly use wgpu::Queue::write_buffer_with to avoid extra copies, but it requires a preallocated non-expandable buffer. To preallocate, a maximum capacity for the buffer must be known, and this requires summing the size of all elements (padding for alignment), or computing the capacity assuming the size is fixed. This is doable in non-generic contexts where we know a type is not runtime sized, but not possible in generic contexts without T::is_runtime_sized or something similar.

@james7132
Copy link
Contributor Author

I see that ShaderSize provides this functionality, but without specialization this isn't very usable in generic contexts.

@teoxoy teoxoy added the enhancement New feature or request label Apr 10, 2023
@teoxoy
Copy link
Owner

teoxoy commented Apr 10, 2023

Wouldn't https://docs.rs/encase/latest/encase/trait.CalculateSizeFor.html work for your usecase?

Although I imagine it would be tricky to use in a generic context since it's only implemented for runtime-sized arrays.

ShaderType::max_size(nr_of_el) sounds like something that would be nice to have but I don't know how it should behave for things that are not runtime-sized arrays. Does it just ignore the arg?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants