Commit ab6f5d9
authored
feat(lambda-rs): Add anisotropic clamping to texture samplers (#187)
## Summary
Expose anisotropic filtering on samplers so users can opt into
higher-quality texture sampling at oblique viewing angles (with a
configurable quality/perf tradeoff).
## Related Issues
- Resolves #103
## Changes
- Add `anisotropy_clamp: u16` (default `1`) +
`with_anisotropy_clamp(u16)` to `lambda-rs-platform` `SamplerBuilder`,
plumbed to `wgpu::SamplerDescriptor::anisotropy_clamp`.
- Clamp requested anisotropy to `[1, 16]` and disable anisotropy when
unsupported by the adapter (or when filters are not all linear, per wgpu
validation rules).
- Document the quality/performance tradeoff and include example usage.
- Add unit tests verifying default + clamping behavior.
- Add a high-level `lambda-rs`
`SamplerBuilder::with_anisotropy_clamp(u16)` that forwards to the
platform builder.
## Type of Change
- [ ] Bug fix (non-breaking change that fixes an issue)
- [x] Feature (non-breaking change that adds functionality)
- [ ] 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)
- [ ] 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`
- [x] `lambda-rs-platform`
- [ ] `lambda-rs-args`
- [ ] `lambda-rs-logging`
- [ ] Other:
## Checklist
- [x] 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
- [ ] Breaking changes are noted in this PR description
## Testing
**Commands run:**
```bash
cargo +nightly fmt --all
cargo test -p lambda-rs-platform
cargo test -p lambda-rs
```
**Manual verification steps (if applicable):**
1. (Optional) Run a textured demo and confirm angled surfaces show
reduced shimmering/blurring when using `with_anisotropy_clamp(8)` with
linear + mipmapped sampling.
## Screenshots/Recordings
N/A
## Platform Testing
- [x] macOS
- [ ] Windows
- [ ] Linux
## Additional Notes
- wgpu requires all filter modes to be linear when anisotropy is
enabled; the builder disables anisotropy if this constraint is not met
to avoid runtime validation errors.
- On adapters without `ANISOTROPIC_FILTERING` downlevel support,
anisotropy is forced to `1` (disabled).
- wgpu 28 does not expose a per-device `Limits::max_sampler_anisotropy`;
this change clamps to `[1, 16]` and gates on downlevel capability.2 files changed
Lines changed: 146 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
528 | 528 | | |
529 | 529 | | |
530 | 530 | | |
| 531 | + | |
531 | 532 | | |
532 | 533 | | |
533 | 534 | | |
| |||
549 | 550 | | |
550 | 551 | | |
551 | 552 | | |
| 553 | + | |
552 | 554 | | |
553 | 555 | | |
554 | 556 | | |
| |||
621 | 623 | | |
622 | 624 | | |
623 | 625 | | |
624 | | - | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
625 | 683 | | |
626 | 684 | | |
627 | 685 | | |
| |||
632 | 690 | | |
633 | 691 | | |
634 | 692 | | |
| 693 | + | |
635 | 694 | | |
636 | 695 | | |
637 | 696 | | |
638 | 697 | | |
639 | 698 | | |
640 | 699 | | |
641 | | - | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
642 | 715 | | |
643 | 716 | | |
644 | 717 | | |
| |||
1051 | 1124 | | |
1052 | 1125 | | |
1053 | 1126 | | |
1054 | | - | |
| 1127 | + | |
1055 | 1128 | | |
1056 | 1129 | | |
1057 | 1130 | | |
| |||
1060 | 1133 | | |
1061 | 1134 | | |
1062 | 1135 | | |
| 1136 | + | |
1063 | 1137 | | |
1064 | 1138 | | |
1065 | 1139 | | |
1066 | 1140 | | |
1067 | 1141 | | |
1068 | 1142 | | |
1069 | 1143 | | |
1070 | | - | |
| 1144 | + | |
1071 | 1145 | | |
1072 | 1146 | | |
1073 | 1147 | | |
1074 | 1148 | | |
1075 | 1149 | | |
1076 | 1150 | | |
1077 | 1151 | | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
1078 | 1207 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
627 | 627 | | |
628 | 628 | | |
629 | 629 | | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
630 | 643 | | |
631 | 644 | | |
632 | 645 | | |
| |||
0 commit comments