Fixes from the audits in #103 / #106: PresentX on another queue, frame intervals either side, xcl.toml kept when unreadable

- PresentX from a queue other than the one the fallback presenter was made for (a fallback
  present before the title's first PresentX) dropped every frame: the presenter now moves to
  the PresentX queue, after the old one's copy (#103 item 2).
- SetFrameIntervalX: the tolerance is either side of the nominal length – 16 666 and 66 666 us
  (1 000 000 / 60, / 15) were refused (#103 item 4).
- xcl.toml is rewritten with the defaults only when it does not exist; an unreadable one (locked,
  not UTF-8) is an error instead of being replaced (#106).
This commit is contained in:
ivall
2026-11-23 12:42:08 +01:00
parent f90e644ad4
commit ea4bd628ba
3 changed files with 16 additions and 1 deletions
+3
View File
@@ -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())?;
+3 -1
View File
@@ -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);
+10
View File
@@ -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);
}