Overview
Extend the high-level Buffer API with methods for writing raw bytes and typed slices, complementing the existing single-value write_value<T>
Current State
Buffer currently only exposes write_value<T> for uploading a single piece of data value:
// crates/lambda-rs/src/render/buffer.rsimplBuffer{/// Write a single plain-old-data value into this buffer at the specified/// byte offset.pubfnwrite_value<T:Copy>(&self,render_context:&RenderContext,offset:u64,data:&T,){let bytes = unsafe{
std::slice::from_raw_parts((data as*constT)as*constu8,
std::mem::size_of::<T>(),)};self.buffer.write_bytes(render_context.gpu(), offset, bytes);}}Common use cases however require writing arrays of vertices, instance data, or raw byte buffers.
Scope
- Add write_bytes(&self, ctx, offset, &[u8]) for raw byte uploads
- Add write_slice<T: Copy>(&self, ctx, offset, &[T]) for typed array uploads
Proposed API
implBuffer{/// Write raw bytes into this buffer at the specified byte offset.pubfnwrite_bytes(&self,render_context:&RenderContext,offset:u64,data:&[u8],);/// Write a slice of plain-old-data values into this buffer at the/// specified byte offset.pubfnwrite_slice<T:Copy>(&self,render_context:&RenderContext,offset:u64,data:&[T],);}Example Usage
// Update instance transforms each framelet transforms:Vec<InstanceTransform> = compute_transforms();
instance_buffer.write_slice(&render_context,0,&transforms);// Or raw bytes from an external sourcelet raw_data:&[u8] = load_binary_data();
buffer.write_bytes(&render_context,0, raw_data);
Acceptance criteria
Overview
Extend the high-level Buffer API with methods for writing raw bytes and typed slices, complementing the existing single-value
write_value<T>Current State
Buffercurrently only exposeswrite_value<T>for uploading a single piece of data value:Common use cases however require writing arrays of vertices, instance data, or raw byte buffers.
Scope
Proposed API
Example Usage
Acceptance criteria
Buffer::write_bytesmethodBuffer::write_slice<T>method