Build hook omits Box2D's -ffp-contract=off, so arm64 and x64 simulate differently
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 74/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- cmake, dart
- Lĩnh vực
- backend, build-system
Hướng nghiên cứu
Bắt đầu với packages/forge2d/hook/build.dart và kiểm tra cách tệp truyền các cờ trình biên dịch cho CBuilder.library ở từng target. So sánh các thiết lập của hook với tùy chọn toán học xác định của Box2D v3.1.1 trong CMakeLists.txt ở thư mục gốc; issue cho biết các hash mô phỏng trên arm64 và x86_64 khớp nhau khi tắt phép co dấu phẩy động. Hoàn thành khi hook áp dụng cờ phù hợp cho các target clang và GCC, đồng thời kết quả mô phỏng khớp nhau trên các kiến trúc đó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Box2D v3 is deterministic across platforms only when compiled without floating-point contraction. Upstream sets this in its root CMakeLists.txt under "Deterministic math" (v3.1.1):
add_compile_options(-ffp-contract=off)
The reasoning is in Erin Catto's determinism post. Forge2D's build hook (packages/forge2d/hook/build.dart) compiles the vendored sources without this flag, so clang's default contraction applies.
What I measured
forge2d 0.15.2 (Box2D v3.1.1), Dart 3.13.5, Apple M1 Pro. The x64 runs used the x64 Dart SDK under Rosetta, so the hook built an x86_64 library.
- The arm64
libbox2d.dylibcontains 1,552 fused multiply-add instructions (otool -tv | grep -cE 'fmadd|fmsub|fnmadd|fnmsub|fmla|fmls'). Built with-ffp-contract=off, it contains none. - A test world of 12 dynamic circles among static circles and walls, zero gravity, stepped 600 times at 0.1 s, hashed over every body's position and rotation:
| Build | arm64 | x86_64 |
|---|---|---|
| forge2d 0.15.2 as published | 8957222861739655168 |
1316962272182009856 |
hook patched with -ffp-contract=off |
1316962272182009856 |
1316962272182009856 |
With the flag, arm64 and x86_64 agree bit for bit. Without it, they diverge.
Suggested change
Pass the flag to CBuilder.library for clang and GCC targets, for example:
flags: os == OS.windows ? const [] : const ['-ffp-contract=off'],
I did not test Windows with MSVC, so I can't say which MSVC option, if any, is needed there.
Test world
import 'dart:typed_data';
import 'package:forge2d/forge2d.dart';
void main() {
final world = World(gravity: Vector2.zero());
final walls = world.createBody();
final c = [Vector2(-8, -5), Vector2(8, -5), Vector2(8, 5), Vector2(-8, 5)];
for (var i = 0; i < 4; i++) {
walls.createShape(Segment(point1: c[i], point2: c[(i + 1) % 4]));
}
world.createBody(BodyDef(position: Vector2(1, 0.3))).createShape(Circle(radius: 0.6));
world.createBody(BodyDef(position: Vector2(-2, -1))).createShape(Circle(radius: 0.35));
final bodies = [
for (var i = 0; i < 12; i++)
world.createBody(BodyDef(type: BodyType.dynamic,
position: Vector2(-6.0 + i, 2.0 - (i % 3)),
linearVelocity: Vector2(3.0 - i * 0.41, 1.3 + i * 0.17),
angularVelocity: 0.3 * i))
..createShape(Circle(radius: 0.5),
ShapeDef(material: SurfaceMaterial(friction: 0.2, restitution: 0.5)))
];
final b = ByteData(8);
var h = 0;
for (var t = 0; t < 600; t++) {
world.step(0.1);
for (final body in bodies) {
for (final v in [body.position.x, body.position.y, body.rotation.cos, body.rotation.sin]) {
b.setFloat64(0, v);
h = (h * 31 + b.getInt64(0)) & 0x7FFFFFFFFFFFFFFF;
}
}
}
print(h);
world.destroy();
}
- Ngôn ngữ chính
- Dart
- Star
- 203
- Fork
- 31
- Merge trung bình
- 27 phút
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue tương tự
-
[feat]: 截图挑选时希望能双击缩略图直接选中/取消Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[体验问题] 新建下载任务时重命名会丢失原文件后缀Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Timer with tickCount stays finished after start() or reset()Có thể đã có người làm @matthewalberto đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
flame-engine/flame#4240 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
spotiflacapp/SpotiFLAC-Mobile#935 ·
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
chriskelly/wish-together#193 ·
Maintainer thường phản hồi trong vòng 1 ngày