cf38d76fd0
M1 — Memory Pool (内存池): - ObjectPool<T>: O(1) acquire/release with free-list, chunk-based expansion - ThreadSafeObjectPool<T>: per-thread local pools with global fallback - CowPtr<T>: copy-on-write smart pointer with shallow/deep copy - 10 tests: single/multi-thread, CoW detach, reuse rate M2 — Parallel Boolean (并行布尔): - parallel_face_face_intersection(): OpenMP face-pair dispatch with AABB culling - parallel_classify_faces(): thread-safe ray casting classification - parallel_mesh_union/intersection/difference + B-Rep variants - Thread count management API - 12 tests: coverage, empty cases, identity operations M3 — Parallel Marching Cubes (并行MC): - parallel_marching_cubes(): Z-slice parallel voxel processing - parallel_adaptive_mc(): octree-based adaptive resolution - Complete 256-entry edge table + Möller-Trumbore interpolation - 5 tests: sphere basic/high-res/empty/adaptive/threaded M4 — Parallel Surface Intersection (并行求交): - parallel_curve_intersections(): per-pair parallel dispatch - parallel_surface_intersection(): recursive subdivision + Newton refinement - AABB broad-phase culling before narrow-phase - 4 tests: curve pairs, surface batch M5 — GMP Exact Predicates (精确谓词): - exact_orient2d/3d: adaptive precision (double → GMP fallback) - exact_in_sphere: circumsphere test with degenerate handling - exact_point_in_polygon/polyhedron: robust ray casting - PrecisionMode: Fast/Adaptive/Exact with global toggle - 12 tests: all orientations, boundary cases, mode switching 21 files, +2263 lines
4.6 KiB
4.6 KiB
ViewDesignEngine v4.6 — 性能基建
制定: 2026-07-26 | 状态: 🚧 执行中
进度: 🚧 M1 内存池 | ⬜ M2 并行布尔 | ⬜ M3 并行MC | ⬜ M4 并行求交 | ⬜ M5 GMP精确算术
继 v4.5 实用增强后,v4.6 回归引擎底层,补齐性能短板。
1. 🧠 内存池 (Memory Pool)
CAD 引擎频繁创建/销毁小对象(顶点、边、面、三角形),malloc/free 成为瓶颈。
1.1 ObjectPool
ObjectPool<T>— 模板化对象池,chunk 分配 + free-list 回收acquire()/release()— O(1) 获取/归还- 线程安全版本
ThreadSafeObjectPool<T>(per-thread pool + global fallback) - 统计:allocations / reuses / waste %
1.2 Copy-on-Write
Cow<T>— 写时复制包装器,引用计数 + 修改时深拷贝CowPtr<T>— shared_ptr 风格的 CoW 指针- 用于 NurbsSurface、HalfedgeMesh 等大对象
测试 — ~15 项
- 单线程 acquire/release 正确性
- 多线程并发分配/回收
- CoW 浅拷贝验证
- CoW 修改触发深拷贝
- 引用计数正确性
2. ⚡ 并行布尔运算
v3.x 布尔运算为单线程,面-面求交和分类是主要瓶颈。
2.1 并行面-面求交
parallel_face_face_intersection()— OpenMP 并行- 工作窃取队列:大面分解为子任务
- 线程安全交线收集
2.2 并行分类
parallel_classify_faces()— 射线投射分类并行化- 每线程独立 AABB 缓存
- 合并阶段去重
2.3 性能对比
- 基准:单线程 vs 多线程
- 扩展性:2/4/8 线程加速比
测试 — ~8 项
- 并行结果与串行一致
- 线程安全性(TSan 通过)
- 加速比验证
3. 🔳 并行 Marching Cubes
SDF → Mesh 转换是 SDF 建模管线瓶颈。
3.1 并行体素处理
parallel_marching_cubes()— 分块并行- 每线程独立三角形缓冲区
- 合并去重(边界顶点索引重映射)
3.2 自适应分辨率
- 八叉树自适应 MC,平坦区域用大格子
测试 — ~6 项
- 并行结果与串行一致
- 多分辨率输出正确
- 加速比验证
4. 📐 并行曲面求交
NURBS 曲面-曲面求交是 B-Rep 布尔的核心。
4.1 并行边界盒预筛选
parallel_surface_intersection()— 候选面对并行求交- 每线程独立牛顿精化
4.2 曲线-曲线并行
parallel_curve_intersection()— 批量曲线对并行
测试 — ~6 项
- 并行结果与串行一致
- 退化情况处理
5. 🔢 GMP 精确算术集成
布尔运算关键路径使用精确算术消除浮点误差。
5.1 精确谓词
exact_orient3d()— GMP/MPFR 精确三点定向exact_in_sphere()— 精确球内测试exact_point_in_polyhedron()— 精确点在体内
5.2 混合精度
- 自适应精度:先用 double,检测到不确定性 → 升级到 GMP
ExactPredicate包装器统一接口
测试 — ~10 项
- 退化情况下 double 失败但 GMP 正确
- 共面/共线/共球边界情况
- 混合精度自动升级
里程碑
| 里程碑 | 内容 | 预计 |
|---|---|---|
| M1: 内存池 | ObjectPool + ThreadSafePool + CoW | — |
| M2: 并行布尔 | 并行面-面求交 + 并行分类 | — |
| M3: 并行MC | 并行体素 + 自适应分辨率 | — |
| M4: 并行求交 | 并行曲面/曲线求交 | — |
| M5: GMP | 精确谓词 + 混合精度 | — |
修改文件汇总
| 文件 | 操作 | 说明 |
|---|---|---|
include/vde/core/object_pool.h |
新建 | 对象池 + CoW |
src/core/object_pool.cpp |
新建 | 模板实例化 |
tests/core/test_object_pool.cpp |
新建 | 对象池测试 |
include/vde/brep/parallel_boolean.h |
新建 | 并行布尔 |
src/brep/parallel_boolean.cpp |
新建 | 并行布尔实现 |
tests/brep/test_parallel_boolean.cpp |
新建 | 并行布尔测试 |
include/vde/mesh/parallel_mc.h |
新建 | 并行MC |
src/mesh/parallel_mc.cpp |
新建 | 并行MC实现 |
tests/mesh/test_parallel_mc.cpp |
新建 | 并行MC测试 |
include/vde/curves/parallel_intersection.h |
新建 | 并行求交 |
src/curves/parallel_intersection.cpp |
新建 | 并行求交实现 |
tests/curves/test_parallel_intersection.cpp |
新建 | 并行求交测试 |
include/vde/core/exact_predicates.h |
新建 | 精确谓词 |
src/core/exact_predicates.cpp |
新建 | 精确谓词实现 |
tests/core/test_exact_predicates.cpp |
新建 | 精确谓词测试 |
docs/25-v4.6-开发计划.md |
新建 | 开发计划 |