Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix alignment on ios simulator #10178

Merged
merged 5 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions crates/bevy_render/src/render_resource/uniform_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,16 @@ impl<T: ShaderType + WriteInto> DynamicUniformBuffer<T> {
device: &RenderDevice,
queue: &'a RenderQueue,
) -> Option<DynamicUniformBufferWriter<'a, T>> {
let alignment =
AlignmentValue::new(device.limits().min_uniform_buffer_offset_alignment as u64);
let alignment = if cfg!(ios_simulator) {
// On iOS simulator on silicon macs, metal validation check that the host OS alignment
// is respected, but the device reports the correct value for iOS, which is smaller.
// Use the larger value.
// See https://github.com/bevyengine/bevy/pull/10178 - remove if it's not needed anymore.
AlignmentValue::new(256)
} else {
AlignmentValue::new(device.limits().min_uniform_buffer_offset_alignment as u64)
};

let mut capacity = self.buffer.as_deref().map(wgpu::Buffer::size).unwrap_or(0);
let size = alignment
.round_up(T::min_size().get())
Expand Down
5 changes: 5 additions & 0 deletions examples/mobile/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Flag to notify the compiler we're building for the iOS simulator from an Apple silicon mac
# This needs some workarounds for now
# See https://github.com/bevyengine/bevy/pull/10178 - remove if it's not needed anymore.
[target.aarch64-apple-ios-sim]
rustflags = ["--cfg=ios_simulator"]
2 changes: 1 addition & 1 deletion examples/mobile/build_rust_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ for arch in $ARCHS; do
# Hardware iOS targets
cargo rustc --crate-type staticlib --lib $RELFLAG --target aarch64-apple-ios
else
# M1 iOS simulator -- currently in Nightly only and requires to build `libstd`
# M1 iOS simulator
cargo rustc --crate-type staticlib --lib $RELFLAG --target aarch64-apple-ios-sim
fi
esac
Expand Down