mirror of
https://github.com/Belobug/VIctory-Belobug-AMD.git
synced 2026-12-06 08:38:35 +00:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -100,6 +100,10 @@ For PC FSR 4.1.2, set `[paths].fidelityfx_dir` in `victory.toml` or
|
||||
the retail 1.0.2.1 Series X 4K SDR profile. `balanced` selects 2258×1270
|
||||
and `performance` selects 1920×1080. All three output 3840×2160. With
|
||||
`victory run` directly, set `VICTORY_FSR_4K` to the preset name.
|
||||
AMD's SDK offers FSR 4.1.2 for some cards only. Where it does not, the
|
||||
newest FSR 3.1 it offers is used in its place and the log says so; its
|
||||
picture differs from FSR 4's. Where it offers neither, the run stops
|
||||
before the title starts and names the versions that were offered.
|
||||
The log reports the provider at context creation and the actual input and
|
||||
output sizes at the first successful temporal dispatch. The title profile
|
||||
and PC FidelityFX bridge were ported from [DexNom/VIctory](https://github.com/DexNom/VIctory/commit/ab34a8b21477c94da2a6cf07249138e8bc84602e).
|
||||
|
||||
@ -77,7 +77,7 @@ pub fn run(
|
||||
// Select the provider before the first lookup builds the import registry.
|
||||
victory_hle::modules::fidelityfx::use_host_dir(dir)
|
||||
.map_err(anyhow::Error::msg)
|
||||
.with_context(|| format!("loading FSR 4.1.2 from {}", dir.display()))?;
|
||||
.with_context(|| format!("loading the PC FSR upscaler from {}", dir.display()))?;
|
||||
// SAFETY: Windows supports setting the environment across threads.
|
||||
// No title code has run or queried DXGI yet.
|
||||
unsafe { std::env::set_var("VICTORY_DISPLAY_MODE", "3840x2160") };
|
||||
|
||||
@ -157,6 +157,8 @@ struct Host {
|
||||
dispatch: Call,
|
||||
device: ID3D12Device,
|
||||
provider_id: u64,
|
||||
/// The provider's version as the SDK names it (`4.1.2`, `3.1.5`).
|
||||
provider_name: String,
|
||||
}
|
||||
|
||||
struct Library(windows_sys::Win32::Foundation::HMODULE);
|
||||
@ -235,6 +237,12 @@ pub fn use_host_dir(dir: &Path) -> Result<(), String> {
|
||||
let (host, version) = load(dir)?;
|
||||
HOST.set(host)
|
||||
.map_err(|_| String::from("FidelityFX provider already initialized"))?;
|
||||
if !is_fsr_4_1_2(&version) {
|
||||
tracing::warn!(
|
||||
version,
|
||||
"FidelityFX: the SDK offers this adapter no FSR 4.1.2; FSR 3.1 is used in its place (its picture differs from 4's)"
|
||||
);
|
||||
}
|
||||
tracing::info!(folder = %dir.display(), version, "FidelityFX: selected PC upscaler");
|
||||
Ok(())
|
||||
}
|
||||
@ -288,6 +296,7 @@ fn load(dir: &Path) -> Result<(Host, String), String> {
|
||||
_library: library,
|
||||
device,
|
||||
provider_id,
|
||||
provider_name: version.clone(),
|
||||
}
|
||||
};
|
||||
Ok((host, version))
|
||||
@ -330,23 +339,49 @@ fn select_version(query_fn: Call, device: &ID3D12Device) -> Result<(u64, String)
|
||||
"upscaler version names could not be queried (code {code})"
|
||||
));
|
||||
}
|
||||
let mut available = Vec::new();
|
||||
let mut offered = Vec::new();
|
||||
for (id, name) in ids.into_iter().zip(names).take(count as usize) {
|
||||
if !name.is_null() {
|
||||
// SAFETY: NUL-terminated name owned by the SDK.
|
||||
let name = unsafe { CStr::from_ptr(name) }
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
if is_fsr_4_1_2(&name) {
|
||||
return Ok((id, name));
|
||||
}
|
||||
available.push(name);
|
||||
offered.push((id, name));
|
||||
}
|
||||
}
|
||||
choose(offered)
|
||||
}
|
||||
|
||||
/// The patch number of an FSR 3.1 provider's name (`3.1.5` → 5); `None` for
|
||||
/// any other version (`3.10.0`, `2.3.4`, `4.1.2`).
|
||||
fn fsr_3_1_patch(name: &str) -> Option<u32> {
|
||||
let patch = name.strip_prefix("3.1.")?;
|
||||
let digits = patch.len() - patch.trim_start_matches(|c: char| c.is_ascii_digit()).len();
|
||||
patch[..digits].parse().ok()
|
||||
}
|
||||
|
||||
/// The provider to ask for, of those the SDK offers for the adapter: FSR
|
||||
/// 4.1.2 where there is one, otherwise the newest FSR 3.1 (which runs on any
|
||||
/// D3D12 card; AMD offers 4 on few). With neither, what was offered is said.
|
||||
fn choose(offered: Vec<(u64, String)>) -> Result<(u64, String), String> {
|
||||
if let Some(at) = offered.iter().position(|(_, name)| is_fsr_4_1_2(name)) {
|
||||
return Ok(offered.into_iter().nth(at).unwrap());
|
||||
}
|
||||
let newest = offered
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(at, (_, name))| fsr_3_1_patch(name).map(|patch| (patch, at)))
|
||||
.max_by_key(|&(patch, _)| patch);
|
||||
match newest {
|
||||
Some((_, at)) => Ok(offered.into_iter().nth(at).unwrap()),
|
||||
None => {
|
||||
let names: Vec<&str> = offered.iter().map(|(_, name)| name.as_str()).collect();
|
||||
Err(format!(
|
||||
"the SDK offers this adapter neither FSR 4.1.2 nor FSR 3.1 (offered: {}); run without -Fsr4K (VICTORY_FSR_4K)",
|
||||
if names.is_empty() { "nothing".into() } else { names.join(", ") }
|
||||
))
|
||||
}
|
||||
}
|
||||
Err(format!(
|
||||
"no FSR 4.1.2 provider for this adapter (available: {})",
|
||||
available.join(", ")
|
||||
))
|
||||
}
|
||||
|
||||
/// Puts the host backend after the title's upscaler description, in place
|
||||
@ -442,12 +477,13 @@ extern "C" fn ffxCreateContext(
|
||||
.then(|| unsafe { CStr::from_ptr(version.name) }.to_string_lossy());
|
||||
if query_code != OK
|
||||
|| version.id != host.provider_id
|
||||
|| !name.as_deref().is_some_and(is_fsr_4_1_2)
|
||||
|| name.as_deref() != Some(host.provider_name.as_str())
|
||||
{
|
||||
tracing::warn!(
|
||||
query_code,
|
||||
provider = name.as_deref().unwrap_or("?"),
|
||||
"FidelityFX created a different provider than the requested 4.1.2"
|
||||
requested = host.provider_name,
|
||||
"FidelityFX created a different provider than the one requested"
|
||||
);
|
||||
// SAFETY: the PC provider just created the context with this allocator.
|
||||
unsafe { (host.destroy)(context, memory) };
|
||||
@ -827,6 +863,30 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
fn offered(names: &[&str]) -> Vec<(u64, String)> {
|
||||
names.iter().zip(1..).map(|(name, id)| (id, name.to_string())).collect()
|
||||
}
|
||||
|
||||
/// FSR 4.1.2 where the SDK offers it; otherwise the newest 3.1, which
|
||||
/// is what a card without FSR 4 is offered; with neither, said so.
|
||||
#[test]
|
||||
fn the_provider_is_4_1_2_or_else_the_newest_3_1() {
|
||||
assert_eq!(choose(offered(&["3.1.5", "4.1.2", "2.3.4"])), Ok((2, "4.1.2".into())));
|
||||
assert_eq!(choose(offered(&["4.1.2 (ML)", "3.1.5"])), Ok((1, "4.1.2 (ML)".into())));
|
||||
assert_eq!(choose(offered(&["2.3.4", "3.1.4", "3.1.5"])), Ok((3, "3.1.5".into())));
|
||||
assert_eq!(choose(offered(&["3.1.10", "3.1.9"])), Ok((1, "3.1.10".into())));
|
||||
// Other versions are not taken for either.
|
||||
assert_eq!(choose(offered(&["4.1.20", "3.1.5", "3.10.0"])), Ok((2, "3.1.5".into())));
|
||||
let none = choose(offered(&["2.3.4", "4.0.3"])).unwrap_err();
|
||||
assert!(none.contains("2.3.4, 4.0.3") && none.contains("-Fsr4K"), "{none}");
|
||||
assert!(choose(Vec::new()).unwrap_err().contains("nothing"));
|
||||
assert_eq!(fsr_3_1_patch("3.1.5"), Some(5));
|
||||
assert_eq!(fsr_3_1_patch("3.1.5-beta"), Some(5));
|
||||
assert_eq!(fsr_3_1_patch("3.1."), None);
|
||||
assert_eq!(fsr_3_1_patch("3.10.0"), None);
|
||||
assert_eq!(fsr_3_1_patch("4.1.2"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resource_states_read_as_the_pc_backend_reads_them() {
|
||||
assert_eq!(host_state(0xc), Some(0xc0));
|
||||
|
||||
@ -490,11 +490,9 @@ fn the_titles_upscaler_runs_on_the_host() {
|
||||
eprintln!("provider {:#x} {:?}", provider.id, unsafe {
|
||||
std::ffi::CStr::from_ptr(provider.name)
|
||||
});
|
||||
assert!(
|
||||
unsafe { std::ffi::CStr::from_ptr(provider.name) }
|
||||
.to_bytes()
|
||||
.starts_with(b"4.1.2")
|
||||
);
|
||||
// FSR 4.1.2 where the SDK offers it for this card, FSR 3.1 otherwise.
|
||||
let name = unsafe { std::ffi::CStr::from_ptr(provider.name) }.to_bytes();
|
||||
assert!(name.starts_with(b"4.1.2") || name.starts_with(b"3.1."));
|
||||
// Two frames: the first resets the history.
|
||||
for reset in [1, 0] {
|
||||
upscaling.reset = reset;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
# scripts\play.ps1 -Exe <path of your own copy's executable>
|
||||
# -Safe without the newer, faster ways (the first thing to try when something is wrong)
|
||||
# -RayTracing the title's own ray-traced indirect light: lit interiors, about a third slower
|
||||
# -Fsr4K PC FidelityFX 4.1.2 at 3840x2160 (quality, balanced or performance)
|
||||
# -Fsr4K PC FidelityFX at 3840x2160 (quality, balanced or performance): FSR 4.1.2 where AMD's SDK offers it for the card, FSR 3.1 otherwise
|
||||
# -Build target\diag (the default, the build all measurements are of) or target\release
|
||||
# Light DRED is requested by default for diag and requires --features diagnostics.
|
||||
# -More other settings: -More @{VICTORY_PANEL='1'}
|
||||
|
||||
Reference in New Issue
Block a user