feat(lambda-rs): Add write_slice and write_bytes to Buffer#108
Merged
feat(lambda-rs): Add write_slice and write_bytes to Buffer#108
write_slice and write_bytes to Buffer#108Conversation
There was a problem hiding this comment.
Pull request overview
Adds higher-level buffer upload APIs to lambda-rs by introducing Buffer::write_bytes and Buffer::write_slice, and refactors write_value to use shared byte-conversion helpers with accompanying unit tests.
Changes:
- Added
Buffer::write_bytesfor uploading raw&[u8]directly to GPU buffers - Added
Buffer::write_slice<T>plusvalue_as_bytes/slice_as_byteshelpers for uploading typed data as bytes - Added unit tests validating byte conversion for single values and slices (including empty slices)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
write_sliceandwrite_bytesmethods toBufferinlambda-rs, providing more flexible ways to upload data to GPU buffers. These complement the existingwrite_valuemethod by supporting raw byte slices and typed slices of plain-old-data values.Related Issues
Changes
write_bytes(&self, gpu: &Gpu, offset: u64, data: &[u8])for writing raw byte slices directly to a bufferwrite_slice<T: Copy>(&self, gpu: &Gpu, offset: u64, data: &[T])for writing slices of POD values (vertices, indices, instance data, uniform blocks)value_as_bytesandslice_as_byteshelper functions to convert typed data to byte sliceswrite_valueto use the newwrite_bytesinternally for consistencyslice_as_byteswith a debug assertion for byte length overflowvalue_as_bytes_matches_native_bytes,slice_as_bytes_matches_native_bytes, andslice_as_bytes_empty_is_emptyType of Change
Affected Crates
lambda-rslambda-rs-platformlambda-rs-argslambda-rs-loggingChecklist
cargo +nightly fmt --all)cargo clippy --workspace --all-targets -- -D warnings)cargo test --workspace)Testing
Commands run:
Manual verification steps (if applicable):
write_valuecontinue to workScreenshots/Recordings
N/A - No visual changes.
Platform Testing
Additional Notes
T: Copybound ensures only trivially copyable types can be written, which is required for safe byte reinterpretationslice_as_bytesfunction includes overflow protection that returns an empty slice and triggers a debug assertion if the byte length calculation would overflow