a49da033
Add instance upload planning helpers
a73x 2026-04-08 18:44
Commit message
src/renderer.zig
| Old | New | ||
|---|---|---|---|
| @@ -313,6 +313,28 @@ fn nextInstanceCapacity(current: u32, needed: u32) u32 { | |||
| 313 | return capacity; | 313 | return capacity; |
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | const InstanceUploadRequest = struct { | ||
| 317 | current_capacity: u32, | ||
| 318 | offset_instances: u32, | ||
| 319 | write_len: u32, | ||
| 320 | }; | ||
| 321 | |||
| 322 | const InstanceUploadDecision = struct { | ||
| 323 | needed_capacity: u32, | ||
| 324 | needs_growth: bool, | ||
| 325 | force_full_upload: bool, | ||
| 326 | }; | ||
| 327 | |||
| 328 | fn planInstanceUpload(req: InstanceUploadRequest) InstanceUploadDecision { | ||
| 329 | const needed_capacity = std.math.add(u32, req.offset_instances, req.write_len) catch std.math.maxInt(u32); | ||
| 330 | const needs_growth = needed_capacity > req.current_capacity; | ||
| 331 | return .{ | ||
| 332 | .needed_capacity = needed_capacity, | ||
| 333 | .needs_growth = needs_growth, | ||
| 334 | .force_full_upload = needs_growth, | ||
| 335 | }; | ||
| 336 | } | ||
| 337 | |||
| 316 | fn swapchainNeedsRebuild(result: vk.Result) bool { | 338 | fn swapchainNeedsRebuild(result: vk.Result) bool { |
| 317 | return result == .suboptimal_khr; | 339 | return result == .suboptimal_khr; |
| 318 | } | 340 | } |
| @@ -1345,3 +1367,25 @@ test "swapchainNeedsRebuild flags suboptimal result" { | |||
| 1345 | try std.testing.expect(swapchainNeedsRebuild(.suboptimal_khr)); | 1367 | try std.testing.expect(swapchainNeedsRebuild(.suboptimal_khr)); |
| 1346 | try std.testing.expect(!swapchainNeedsRebuild(.success)); | 1368 | try std.testing.expect(!swapchainNeedsRebuild(.success)); |
| 1347 | } | 1369 | } |
| 1370 | |||
| 1371 | test "range upload falls back to full upload when capacity must grow" { | ||
| 1372 | const decision = planInstanceUpload(.{ | ||
| 1373 | .current_capacity = 8, | ||
| 1374 | .offset_instances = 6, | ||
| 1375 | .write_len = 4, | ||
| 1376 | }); | ||
| 1377 | |||
| 1378 | try std.testing.expect(decision.needs_growth); | ||
| 1379 | try std.testing.expect(decision.force_full_upload); | ||
| 1380 | } | ||
| 1381 | |||
| 1382 | test "range upload stays partial when capacity is sufficient" { | ||
| 1383 | const decision = planInstanceUpload(.{ | ||
| 1384 | .current_capacity = 16, | ||
| 1385 | .offset_instances = 4, | ||
| 1386 | .write_len = 3, | ||
| 1387 | }); | ||
| 1388 | |||
| 1389 | try std.testing.expect(!decision.needs_growth); | ||
| 1390 | try std.testing.expect(!decision.force_full_upload); | ||
| 1391 | } | ||