|
|
@@ -12,9 +12,8 @@
|
|
|
//! bake) are there at once as before; past the budget a draw or dispatch
|
|
|
//! whose pipeline is not ready is dropped, as an untranslated one is.
|
|
|
//!
|
|
|
-//! shortcut: the budget (half a second of waiting per title frame) is a
|
|
|
-//! guess; a pass the title runs only once and whose pipeline takes longer
|
|
|
-//! is lost.
|
|
|
+//! The default budget is half a second per title frame. A pass the title
|
|
|
+//! runs only once and whose pipeline takes longer is lost.
|
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
use std::sync::atomic::{AtomicBool, AtomicU8, AtomicU64, Ordering};
|
|
|
@@ -31,7 +30,7 @@ pub(crate) struct Pending {
|
|
|
queue_state: AtomicU8,
|
|
|
made: OnceLock<Option<HostPipeline>>,
|
|
|
/// What identifies it across runs (shader containers and state), and
|
|
|
- /// whether a draw has used it yet.
|
|
|
+ /// whether a draw or dispatch has requested it yet.
|
|
|
key: String,
|
|
|
used: AtomicBool,
|
|
|
}
|
|
|
@@ -96,7 +95,17 @@ pub(crate) fn missing(p: &Pending) -> Option<String> {
|
|
|
static DONE: (Mutex<()>, Condvar) = (Mutex::new(()), Condvar::new());
|
|
|
|
|
|
/// Waiting allowed per title frame, over all threads.
|
|
|
-const BUDGET: Duration = Duration::from_millis(500);
|
|
|
+fn wait_budget() -> Duration {
|
|
|
+ static BUDGET: OnceLock<Duration> = OnceLock::new();
|
|
|
+ *BUDGET.get_or_init(|| {
|
|
|
+ let millis = std::env::var("VICTORY_PIPELINE_WAIT_MS")
|
|
|
+ .ok()
|
|
|
+ .and_then(|value| value.trim().parse::<u64>().ok())
|
|
|
+ .unwrap_or(500);
|
|
|
+ tracing::info!(millis, "host pipeline wait budget per frame");
|
|
|
+ Duration::from_millis(millis)
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
/// Pipelines queued and not made yet.
|
|
|
static WAITING: AtomicU64 = AtomicU64::new(0);
|
|
|
@@ -109,19 +118,16 @@ pub(crate) fn waiting() -> u64 {
|
|
|
/// The host pipeline if it is made (or is made within the frame's budget);
|
|
|
/// queues it on first use.
|
|
|
pub(crate) fn ready(p: &Arc<Pending>) -> Option<&HostPipeline> {
|
|
|
+ // A still-pending pipeline was requested by the title too. Prewarm it
|
|
|
+ // on the next launch, even if this run never got to use it.
|
|
|
+ if !p.used.load(Ordering::Relaxed) && !p.used.swap(true, Ordering::Relaxed) {
|
|
|
+ super::library::note_used(&p.key);
|
|
|
+ }
|
|
|
if p.made.get().is_none() {
|
|
|
start(p, REQUESTED);
|
|
|
wait(p, crate::frame::current());
|
|
|
}
|
|
|
- let made = p.made.get()?.as_ref();
|
|
|
- // Also one that could not be made (a shader that does not translate):
|
|
|
- // the next run then finds that out while loading, like the others,
|
|
|
- // instead of in the world's frames, where each first use of such a
|
|
|
- // pipeline waits on the frame's budget for nothing.
|
|
|
- if !p.used.swap(true, Ordering::Relaxed) {
|
|
|
- super::library::note_used(&p.key);
|
|
|
- }
|
|
|
- made
|
|
|
+ p.made.get()?.as_ref()
|
|
|
}
|
|
|
|
|
|
/// Makes `p` on this thread if it is not made yet (waiting for a worker
|
|
|
@@ -155,6 +161,10 @@ fn shared_budget() -> bool {
|
|
|
|
|
|
/// Waits for `p` while frame `frame` has budget left.
|
|
|
fn wait(p: &Pending, frame: u64) {
|
|
|
+ let budget = wait_budget();
|
|
|
+ if budget.is_zero() {
|
|
|
+ return;
|
|
|
+ }
|
|
|
// The frame the budget belongs to, and what was waited of it (or is
|
|
|
// taken by a thread waiting now).
|
|
|
static SPENT: Mutex<(u64, Duration)> = Mutex::new((u64::MAX, Duration::ZERO));
|
|
|
@@ -164,7 +174,7 @@ fn wait(p: &Pending, frame: u64) {
|
|
|
if spent.0 != frame {
|
|
|
*spent = (frame, Duration::ZERO);
|
|
|
}
|
|
|
- let left = BUDGET.saturating_sub(spent.1);
|
|
|
+ let left = budget.saturating_sub(spent.1);
|
|
|
if shared {
|
|
|
spent.1 += left;
|
|
|
}
|
|
|
@@ -353,6 +363,20 @@ mod tests {
|
|
|
assert!(matches!(p.made.get(), Some(None)));
|
|
|
}
|
|
|
|
|
|
+ #[test]
|
|
|
+ fn pending_pipeline_is_recorded_for_the_next_launch() {
|
|
|
+ let mut p = Pending::new(Vec::new(), None);
|
|
|
+ p.key = "pending-pipeline-test".to_owned();
|
|
|
+ // Simulate a worker that has taken the job but cannot finish it yet.
|
|
|
+ p.queue_state.store(MAKING, Ordering::Relaxed);
|
|
|
+ let p = Arc::new(p);
|
|
|
+
|
|
|
+ assert!(!super::super::library::wanted_early(&p.key));
|
|
|
+ assert!(ready(&p).is_none());
|
|
|
+ assert!(p.made.get().is_none());
|
|
|
+ assert!(super::super::library::wanted_early(&p.key));
|
|
|
+ }
|
|
|
+
|
|
|
#[test]
|
|
|
fn draws_promote_early_pipelines_without_claiming_them_twice() {
|
|
|
let earlier = Arc::new(Pending::new(Vec::new(), None));
|