a73x

94f2d7b5

vk_sync: fail closed on unknown acquire result + comments

a73x   2026-04-18 12:32

Commit message
vk_sync: fail closed on unknown acquire result + comments

Fixes from code review of the prior vk_sync commit:
- acquireImageBounded returns error.VkAcquireTimeout on unknown
  VkResult values (fails closed instead of trusting image_index).
- Document benign TOCTOU in logVkTimeout rate-limit.
- Clarify why TimeoutKind.atlas exists (reserved for Task 3).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

src/vk_sync.zig
Old New
@@ -52,7 +52,10 @@ pub fn acquireImageBounded(
52 .timeout, .not_ready => return error.VkAcquireTimeout, 52 .timeout, .not_ready => return error.VkAcquireTimeout,
53 .suboptimal_khr => return error.OutOfDateKHR, 53 .suboptimal_khr => return error.OutOfDateKHR,
54 .success => return acquire.image_index, 54 .success => return acquire.image_index,
55 else => return acquire.image_index, // unexpected but non-error; trust the image_index 55 else => {
56 std.log.warn("acquireImageBounded: unexpected VkResult {s}", .{@tagName(acquire.result)});
57 return error.VkAcquireTimeout;
58 },
56 } 59 }
57 } 60 }
58 61
@@ -88,7 +91,11 @@ pub fn queueWaitIdleBounded(vkd: vk.DeviceWrapper, queue: vk.Queue, timeout_ns:
88 91
89 // --- logging --- 92 // --- logging ---
90 93
91 const TimeoutKind = enum { fence, acquire, atlas }; 94 const TimeoutKind = enum {
95 fence, // waitFenceBounded timeouts
96 acquire, // acquireImageBounded timeouts
97 atlas, // uploadAtlasRegion fence timeouts (used by renderer.zig, Task 3)
98 };
92 99
93 var vk_timeout_count: std.atomic.Value(u64) = .init(0); 100 var vk_timeout_count: std.atomic.Value(u64) = .init(0);
94 var last_log_ns: std.atomic.Value(i64) = .init(0); 101 var last_log_ns: std.atomic.Value(i64) = .init(0);
@@ -100,6 +107,7 @@ pub fn logVkTimeout(src: std.builtin.SourceLocation, kind: TimeoutKind) void {
100 const now: i64 = @truncate(std.time.nanoTimestamp()); 107 const now: i64 = @truncate(std.time.nanoTimestamp());
101 const last = last_log_ns.load(.monotonic); 108 const last = last_log_ns.load(.monotonic);
102 if (n == 1 or (now - last) > log_window_ns) { 109 if (n == 1 or (now - last) > log_window_ns) {
110 // Benign TOCTOU: two threads racing can fire twice in the same window.
103 last_log_ns.store(now, .monotonic); 111 last_log_ns.store(now, .monotonic);
104 std.log.warn( 112 std.log.warn(
105 "vk timeout #{} ({s}) at {s}:{d} — driver may be wedged", 113 "vk timeout #{} ({s}) at {s}:{d} — driver may be wedged",