diff --git a/crates/xcl/src/config.rs b/crates/xcl/src/config.rs index 7769726..0f5f4e8 100644 --- a/crates/xcl/src/config.rs +++ b/crates/xcl/src/config.rs @@ -203,6 +203,9 @@ impl Config { } Ok(c) } + // only a missing file gets the defaults written: an unreadable one (locked, not UTF-8) + // must not be replaced by them (issue #106) + Err(e) if e.kind() != std::io::ErrorKind::NotFound => Err(format!("{}: {e}", path.display())), Err(_) => { let c = Config::default(); let body = toml::to_string_pretty(&c).map_err(|e| e.to_string())?; diff --git a/crates/xcl/src/hle/d3d12x/frame.rs b/crates/xcl/src/hle/d3d12x/frame.rs index 91d0272..249f5eb 100644 --- a/crates/xcl/src/hle/d3d12x/frame.rs +++ b/crates/xcl/src/hle/d3d12x/frame.rs @@ -45,7 +45,8 @@ const FLIPPED_KEEP: usize = 64; /// Frame intervals the console accepts (µs, with the rounding a title may use); the 120 Hz /// ones (8 333, 25 000) only on a display that runs at 120 Hz. pub fn interval_valid(len_us: u32, high_refresh: bool) -> bool { - let near = |base: u32, span: u32| len_us >= base && len_us - base <= span; + // either side of the nominal length: 1_000_000 / 60 = 16 666 and 16 667 are both 60 Hz + let near = |base: u32, span: u32| len_us.abs_diff(base) <= span; if near(8333, 9) || near(25000, 25) { return high_refresh; } @@ -434,6 +435,7 @@ mod tests { fn console_intervals_and_deadlines() { assert!(interval_valid(16667, false) && interval_valid(16666 + 16, false) && interval_valid(33333, false)); assert!(!interval_valid(16000, false) && !interval_valid(8333, false) && interval_valid(8333, true)); + assert!(interval_valid(16666, false) && interval_valid(66666, false) && interval_valid(33333 - 34, false)); assert_eq!(next_deadline(100, 10, 3, 50), 103); assert_eq!(next_deadline(100, 10, 3, 103), 113); assert_eq!(next_deadline(100, 10, 3, 120), 123); diff --git a/crates/xcl/src/hle/d3d12x/present.rs b/crates/xcl/src/hle/d3d12x/present.rs index 30e9dad..68e2d6c 100644 --- a/crates/xcl/src/hle/d3d12x/present.rs +++ b/crates/xcl/src/hle/d3d12x/present.rs @@ -573,6 +573,16 @@ unsafe fn present_now(min_interval: Duration, frame: Option<(usize, usize)>) { let Some(src) = ID3D12Resource::from_raw_borrowed(&raw) else { return }; (queue, src.clone(), guard) }; + // PresentX on another queue than the presenter was made for (the fallback presented once from + // a queue before the title's first PresentX, issue #103): the swap chain belongs to a queue – + // a new presenter for the title's present queue, after the old one's copy is done + if frame.is_some() && guard.as_ref().is_some_and(|p| p.queue != queue) { + if let Some(old) = guard.as_ref() { + let _ = fence::wait(&old.fence, old.value, &old.dev, Some(old.event), 1000); + } + crate::xlog_info!("D3D12.X: PresentX from another queue ({queue:#x}) – the XCL window's swap chain moves to it"); + *guard = None; + } if guard.is_none() { *guard = new_presenter(queue); }