You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(lambda-rs): buffers to default to DEVICE_LOCAL as opposed to CPU_VISIBLE (#180)
## Summary
This PR changes buffer allocation defaults to favor GPU-optimal
residency.
Previously, `Properties::default()` (and `BufferBuilder::new()`)
defaulted to `CPU_VISIBLE`, which biases buffers toward CPU-visible
memory and implicitly adds `COPY_DST`. That default is suboptimal for
static vertex/index buffers on discrete GPUs because the memory is being
allocated on the hosts RAM as opposed to the GPUs VRAM.
Now, buffers default to `DEVICE_LOCAL`, and callers must opt into
`CPU_VISIBLE` only when they intend to update the buffer from the CPU
via `Buffer::write_*`.
## Related Issues
- Resolves#104
## Changes
- Changed `Properties::default()` to return `Properties::DEVICE_LOCAL`.
- Updated `BufferBuilder::new()` to inherit the `Properties` default.
- Updated `BufferBuilder::build_from_mesh` to create vertex buffers as
`DEVICE_LOCAL`.
- Added unit tests covering the new default behavior.
## Type of Change
- [ ] Bug fix (non-breaking change that fixes an issue)
- [ ] Feature (non-breaking change that adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Documentation (updates to docs, specs, tutorials, or comments)
- [ ] Refactor (code change that neither fixes a bug nor adds a feature)
- [x] Performance (change that improves performance)
- [x] Test (adding or updating tests)
- [ ] Build/CI (changes to build process or CI configuration)
## Affected Crates
- [x] `lambda-rs`
- [ ] `lambda-rs-platform`
- [ ] `lambda-rs-args`
- [ ] `lambda-rs-logging`
- [ ] Other:
## Checklist
- [ ] Code follows the repository style guidelines (`cargo +nightly fmt
--all`)
- [ ] Code passes clippy (`cargo clippy --workspace --all-targets -- -D
warnings`)
- [ ] Tests pass (`cargo test --workspace`)
- [x] New code includes appropriate documentation
- [x] Public API changes are documented
- [x] Breaking changes are noted in this PR description
## Testing
**Commands run:**
```bash
cargo test -p lambda-rs
```
**Manual verification steps (if applicable):**
1. Run a render demo that uses `BufferBuilder::build_from_mesh` (static
geometry) and confirm it still renders correctly.
2. Run the uniform-buffer demo to verify CPU-updated buffers still
explicitly use `CPU_VISIBLE`.
## Screenshots/Recordings
N/A (no UI change).
## Platform Testing
- [x] macOS
- [ ] Windows
- [ ] Linux
## Additional Notes
- If you relied on implicit CPU visibility (e.g. build a buffer then
call `Buffer::write_value` / `write_slice` / `write_bytes`), add
`.with_properties(Properties::CPU_VISIBLE)` when constructing that
buffer.
.expect("Buffer::write_value requires a CPU-visible buffer. Create the buffer with `.with_properties(Properties::CPU_VISIBLE)` or use `try_write_value` to handle the error.");
170
+
}
171
+
172
+
/// Fallible variant of [`Buffer::write_value`].
173
+
///
174
+
/// Returns an error if the buffer was not created with
.expect("Buffer::write_bytes requires a CPU-visible buffer. Create the buffer with `.with_properties(Properties::CPU_VISIBLE)` or use `try_write_bytes` to handle the error.");
205
+
}
206
+
207
+
/// Fallible variant of [`Buffer::write_bytes`].
208
+
///
209
+
/// Returns an error if the buffer was not created with
"Buffer was not created with Properties::CPU_VISIBLE, so CPU writes are not supported. Recreate the buffer with `.with_properties(Properties::CPU_VISIBLE)`.",
0 commit comments