Closed charles-r-earp closed 1 year ago
While it's easy to see some utility in this, with the way we are using rust-gpu so far, the explicit-ness of the current syntax is not a problem for us, and with limited resources, that's our focus right now.
We do have some early thoughts in a similar direction but it's still pretty far off and the design is likely to be different to this, so for the time being you're probably best off with a wrapper proc macro, unfortunately.
I just wanna chip in here and say that what I would love love love is a descriptor-sets-as-structs system, e.g. something like:
struct DescriptorSet<'a> {
#[spirv(binding = 0, storage_buffer)] prime_indices: &'a mut [u32]
}
#[spirv(compute(threads(64)))]
pub fn main_cs(
#[spirv(global_invocation_id)] id: UVec3,
#[spirv(descriptor_set = 0)] descriptor_set: DescriptorSet,
) {
let index = id.x as usize;
prime_indices[index] = collatz(descriptor_set.prime_indices[index]).unwrap_or(u32::MAX);
}
I'm not especially opinionated as to whether binding IDs should be allowed to be inferred or not. With this above system it should be possible to have a macro tag that you put on structs to autogenerate the binding IDs anyway.
I just wanna chip in here and say that what I would love love love is a descriptor-sets-as-structs system
This is mentioned here: https://embarkstudios.github.io/rust-gpu/book/rfcs/001-resource-binding-syntax.html but I'm not sure if there's an associated issue.
I'm closing this as a won't fix for now, we have other priorities.
shaderc has a compiler option set_autobind_uniforms which allows bindings to be omitted.
This would look like this:
Descriptor set would be 0. Bindings would be generated in order, starting with 0. Handling of mixing the two could be implemented, or the macro could error if either the set or binding is specified.
Potentially, this could be opted into either via an option to SpirvBuilder, or the spirv macro itself. Like: `#[spirv(compute(threads(64)), descriptor_set=0, autobind_uniforms)]"
Saving the explicit descriptor set and bindings is mostly for clarity and ease of use, since at the moment it is fairly verbose.
However, particular motivation for automatically generating bindings is for use in macros / generated definitions. For example, optional arguments:
The full gemm impl can be found here Essentially, bias is an optional argument, and the macro allows for this argument to be added to the generated entry definition. But this requires some gymnastics to redefine the binding of c from 2 to 3, requiring it to be redeclared. And regardless, it's extremely noisy and tedious to write
#[spirv(descriptor_set = 0, binding = 0)]
for every argument, when this can be inferred from argument order.I understand there is some effort towards automatic generation of resource bindings, which may somehow conflict with defaulting to descriptor set = 0 and binding = 0.. when not specified, but this can be mitigated by explicitly opting in.
I can probably implement a workaround for my use case but it does seem like it would be very nice to remove the noise and improve the ergonomics for this. I would like to generate shader code via macros, both for simplicity and potentially for inline shader code, and that is made a lot easier if fewer things have to be specified, especially when working with a list of arguments, adding additional arguments, etc.
I'm happy to work on implementing this if it is a possibility. Otherwise I plan to implement this via a wrapper proc macro, but it would be nicer to standardize this natively.
Thoughts?