White exposure blowout fixed: loose-LDS fallback off by default; LEONIDA_KEYS_FILE

- emit/mod.rs: the approximate loose-LDS lowering is opt-in
  (LEONIDA_WAVE_LDS_LOOSE=1). On, it also let the exposure histogram's
  programs through, computed wrong: the picture blew out to white for hundreds
  of frames at a time (every-frame recordings run3 and ab3: 0 of 1,064 frames
  blown out with it off). The water volumetrics it was meant for still pass
  D3D12's 32 KiB of group-shared memory (8,192 + 33 dwords of our exchange).
- emit/shader.rs: such programs are named on stderr (LDS-OVER-32K).
- gameinput.rs: LEONIDA_KEYS_FILE holds the keys named in a file, with or
  without focus (diagnostics builds), so test scripts can move around.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NotRexed
2026-11-26 18:43:44 -05:00
parent db723a4c43
commit 2441991ca8
3 changed files with 59 additions and 6 deletions

View File

@ -1387,10 +1387,54 @@ mod host {
});
let (start, keys) = &*SCRIPT;
let now = start.elapsed();
keys.iter()
let mut down: Vec<u8> = keys
.iter()
.filter(|&&(from, to, _)| (from..to).contains(&now))
.map(|&(_, _, vk)| vk)
.collect()
.collect();
down.extend(held_from_file());
down
}
/// Leonida: `LEONIDA_KEYS_FILE=<path>`: the keys named in that file are
/// held for as long as they are named there, with or without focus (a
/// test script writes `W D`, then an empty line). Names as in
/// `LEONIDA_KEYS`, plus `Shift` (left shift) and `Space`. Read again at
/// most every 50 ms.
#[cfg(feature = "diagnostics")]
fn held_from_file() -> Vec<u8> {
use std::sync::Mutex;
static PATH: LazyLock<Option<std::path::PathBuf>> =
LazyLock::new(|| std::env::var_os("LEONIDA_KEYS_FILE").map(Into::into));
static LAST: Mutex<Option<(Instant, Vec<u8>)>> = Mutex::new(None);
let Some(path) = PATH.as_ref() else { return Vec::new() };
let mut last = LAST.lock().unwrap_or_else(|e| e.into_inner());
if let Some((at, keys)) = last.as_ref()
&& at.elapsed() < Duration::from_millis(50)
{
return keys.clone();
}
let text = std::fs::read_to_string(path).unwrap_or_default();
let keys: Vec<u8> = text
.split(|c: char| c.is_whitespace() || c == ',' || c == '+')
.filter_map(|key| match key {
"" => None,
"Enter" => Some(0x0D),
"Esc" => Some(0x1B),
"Tab" => Some(0x09),
"Back" => Some(0x08),
"Space" => Some(0x20),
"Shift" => Some(0xA0),
"Up" => Some(0x26),
"Down" => Some(0x28),
"Left" => Some(0x25),
"Right" => Some(0x27),
k if k.len() == 1 && k.as_bytes()[0].is_ascii_alphanumeric() => Some(k.as_bytes()[0].to_ascii_uppercase()),
_ => None,
})
.collect();
*last = Some((Instant::now(), keys.clone()));
keys
}
/// The foreground window is one of ours (the title's or our fallback).

View File

@ -608,10 +608,14 @@ pub fn emit(
}
}
}
// Leonida, last of all (`LEONIDA_WAVE_LDS_LOOSE=0`: not tried): LDS read and
// written inside one lane-branch region, the host waves meeting only around it
// (`lower::with_lds_loose`, approximate). Refused, every dispatch is dropped.
if !strict && std::env::var_os("LEONIDA_WAVE_LDS_LOOSE").is_none_or(|v| v != "0") {
// Leonida, last of all, only with `LEONIDA_WAVE_LDS_LOOSE=1`: LDS read and written
// inside one lane-branch region, the host waves meeting only around it
// (`lower::with_lds_loose`, approximate). Off by default: on, it also let the
// exposure histogram's programs through, computed wrong - the picture blew out to
// white for hundreds of frames at a time (runs run3 against ab3: 0 of 1,064 frames
// blown out with it off). The water programs it was for still pass D3D12's 32 KiB
// of group-shared memory (`LDS-OVER-32K`), so it gained nothing visible.
if !strict && std::env::var_os("LEONIDA_WAVE_LDS_LOOSE").is_some_and(|v| v == "1") {
let loose = lower::with_lds_loose(|| emit_program(c, native, p, st, io, res));
report("loose LDS (APPROXIMATE)", &loose);
if done(&loose) {

View File

@ -310,6 +310,11 @@ impl Shader {
if let Some(g) = self.lds {
return g;
}
if self.lds_dwords > 8192 {
// Leonida: D3D12 takes at most 32 KiB of group-shared memory; more makes the host
// refuse the pipeline with E_INVALIDARG.
eprintln!("LDS-OVER-32K dwords={} threads={:?}", self.lds_dwords, self.threads);
}
let arr = self.m.array(self.lds_dwords, self.t.i32);
let g = self.m.global("lds", arr, 3);
self.lds = Some(g);