-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
I had the use case today where I wanted to build an "InstanceBuilder" where the user of this api incrementally added structs to this builder, and as I went along I wrote those structs into a staging buffer, which gets uploaded when this builder is finished. What I ended up with is two structs that don't compile as they're self referential.
struct InstanceBuilderOne {
instance_data_buffer: wgpu::Buffer,
instance_mapping: wgpu::QueueWriteBufferView<'self>
}
struct InstanceBuilderTwo {
instance_data_buffer: wgpu::Buffer,
instance_mapping: wgpu::BufferViewMut<'self>,
}
I think the usability increase from getting rid of these lifetimes (and cloning the underlying resources, now that that is an option) is worth the small cost of cloning the resources. The mapping functions themselves shouldn't be very hot.
Workaround
For those who want a workaround, I ended up splitting up my instance builder into two structs, where the user made the builder, then you made a writer, which included these references in them
struct InstanceBuilderThree {
instance_data_buffer: wgpu::Buffer,
}
impl InstanceBuilderThree {
fn write(&self) -> InstanceBuilderThreeWriter<'_>;
}
struct InstanceBuilderThreeWriter<'a> {
inner: &'a InstanceBuilderThree
instance_mapping: wgpu::BufferViewMut<'a>,
}