From f1e7a97d5628b3cf044254be76da406ec9d5aee2 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 5 Nov 2026 17:16:36 -0800 Subject: [PATCH] Give 64 threads count shards of their own What: shards::SHARDS goes from 16 to 64, the most the owners' bitmask holds, as the encoders' tallies have. Threads past the owned shards share one by an atomic add: the recorder's command counts and the counts made with no encoder's core at hand. Why: a process where more than 16 threads have counted (a consumer's walk threads beside its other encoding threads) put every later thread on the shared shard, each of their commands an atomic add the others contend for. Memory: 48 more shards of 512 bytes (24 KiB) a device for the core-less command counts, and 24 KiB more for each of the recorder's 8 slots (static). Verified: neutral in the lanes once the tallies took the per-draw counts: game_draws_threads beside 16 idle threads that drew, 5080 (pinned, 5 rounds) 589 -> 582 ns a draw, M3 703 -> 695, both within the rounds' spread; four threads alone 5080 538 -> 562, M3 684 -> 604, the same. tests::recorder_shards (at 64: 67 threads where some share) pass on the M3 (nextest), lavapipe and the 5080 (one process, one test at a time). (cherry picked from commit e7e0c189e7de72c9faba60df76a7e65400c5695c) (cherry picked from commit dec97514e41c7a430d2866be0e0ace5f45b1a853) --- crates/metal2vulkan-runtime/src/shards.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/metal2vulkan-runtime/src/shards.rs b/crates/metal2vulkan-runtime/src/shards.rs index c5dbd4cc0..7268a3a75 100644 --- a/crates/metal2vulkan-runtime/src/shards.rs +++ b/crates/metal2vulkan-runtime/src/shards.rs @@ -36,7 +36,7 @@ use std::cell::Cell; use std::sync::atomic::{AtomicU64, Ordering}; /// How many shards threads own; the threads past them share one more ([`SHARED`]). -pub(crate) const SHARDS: usize = 16; +pub(crate) const SHARDS: usize = 64; /// The index of the shard no thread owns, which the threads past the owned ones add into. pub(crate) const SHARED: usize = SHARDS;