mirror of
https://github.com/ivall/xcl.git
synced 2026-11-24 05:14:57 +01:00
FSR4 context on XCL's device: console resource creation and descriptor heap ABI
- console device #76 = CreateCommittedResource (PC #27); console texture layouts (0x101, extra field at +52) become UNKNOWN on PC - descriptor heap #9/#10 return the start handle in rax for console code - probe: ffxCreateContext of the console FSR4 upscaler succeeds (only its shipped configuration: 1280x720 -> 1920x1080, HDR | inverted depth | auto exposure)
This commit is contained in:
+13
@@ -439,6 +439,19 @@ nieznanych rekordów), wynik czytany `bvh::Bvh::trace` = brute force na 500 prom
|
||||
brak pamięci); shader z wczorajszej awarii (1 589 instr.) – 0,3 s, 48 KB (wcześniej ~6 min i > 30 GB).
|
||||
**DXC znów optymalizuje wszystko** (`-O0` tylko > 8 MB HLSL). Próbka 64 shaderów gry: 0 błędów; mediana 0,29 s, p90 ~11 s.
|
||||
|
||||
### FSR4 do nauki tekstur (sesja 5, w toku)
|
||||
- Sonda `fsr4_console_upscaler_creates_a_context_probe` (`XCL_PROBE_FSR=1`): `ffxCreateContext` z
|
||||
`ffxCreateContextDescUpscale` (typ 0x10000) + opis backendu (typ **0x1000002**, urządzenie pod +0x10) – **kontekst
|
||||
powstaje na urządzeniu XCL**. Jedyna konfiguracja w paczce (FSR sam to mówi przez OutputDebugString): render 1280×720
|
||||
(albo 1920×1080), wyjście 1920×1080, flagi HDR | DEPTH_INVERTED | AUTO_EXPOSURE (1 | 8 | 32).
|
||||
- Kolejne różnice konsoli (tabela `real::console_slots`):
|
||||
- urządzenie **#76 = CreateCommittedResource** (jak PC #27); **konsolowy opis zasobu**: Layout (+44) = **0x101** (tekstura
|
||||
2D 1920×1080 R8G8B8A8, RT|UAV), +52 = 3, opis ≥ 64 B – układy konsoli → na PC UNKNOWN (log w
|
||||
`dev_create_committed_resource_x`);
|
||||
- sterta deskryptorów **#9 / #10 (GetCPU/GPUDescriptorHandleForHeapStart) zwracają uchwyt w rax** (PC: ukryty wskaźnik).
|
||||
- Tworzenie kontekstu: 14 zasobów, 16 UAV, 10 SRV, Map/Unmap, GetCopyableFootprints – wszystko przez metody (bez inline).
|
||||
- Następny krok: `ffxDispatch` z teksturami wejściowymi (FfxApiResource) na liście konsolowej → rekordy tabel deskryptorów.
|
||||
|
||||
### (archiwum) TLAS na GPU – blokada rozmiarem jednego shadera
|
||||
- Test `xbox_bvh_builder_builds_a_tlas_on_the_gpu` (`XCL_CONSOLE_LISTS=1 XCL_PROBE_BVH_TLAS=1`): 2 BLAS + 16 instancji
|
||||
(część tylko przesunięta), `trace_scene` vs brute force w świecie. BLAS-y budują się, TLAS wychodzi pusty: 1 dispatch
|
||||
|
||||
@@ -449,21 +449,85 @@ unsafe fn class_for(obj: *mut c_void, orig: usize, kind: Kind) -> usize {
|
||||
/// Console vtable slots that differ from the PC layout (found on console code calling them):
|
||||
/// * device #62: `CreateComputePipelineState` with two extra arguments (XboxBvhBuilder.dll
|
||||
/// passes a D3D12_COMPUTE_PIPELINE_STATE_DESC, NULL, NULL, riid, ppv); PC #62 = CreateStateObject.
|
||||
/// * device #76: `CreateCommittedResource` (heap properties, flags, desc, state, clear value,
|
||||
/// riid, ppv) as on PC #27 (PC #76 = CreateCommittedResource3); the console resource desc
|
||||
/// carries more after the 52 PC bytes (amd_fidelityfx_upscaler_xbox.dll writes 3 at +52).
|
||||
/// * descriptor heap #9 / #10: the heap start handles come back in rax on the console.
|
||||
/// * device #12 `CreateCommandList` (only with console lists on): console code gets a
|
||||
/// console-shaped list (D3D12.X inline code writes into it), XCL's own code a PC one.
|
||||
fn console_slots(kind: Kind) -> Vec<(usize, usize)> {
|
||||
match kind {
|
||||
Kind::Device => {
|
||||
let mut v = vec![(62, dev_create_compute_pso_x as usize)];
|
||||
let mut v = vec![(62, dev_create_compute_pso_x as usize), (76, dev_create_committed_resource_x as usize)];
|
||||
if super::console_list::enabled() {
|
||||
v.push((12, dev_create_command_list_x as usize));
|
||||
}
|
||||
v
|
||||
}
|
||||
Kind::DescriptorHeap => vec![(9, heap_cpu_start_x as usize), (10, heap_gpu_start_x as usize)],
|
||||
_ => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
/// descriptor heap #9 / #10 GetCPU / GetGPUDescriptorHandleForHeapStart: console code
|
||||
/// takes the handle in rax (only `this` passed); the PC methods return it through a hidden
|
||||
/// pointer
|
||||
unsafe extern "system" fn heap_cpu_start_x(this: *mut c_void) -> u64 {
|
||||
let f: unsafe extern "system" fn(*mut c_void, *mut u64) -> *mut u64 = std::mem::transmute(orig_fn(this, 9));
|
||||
let mut h = 0u64;
|
||||
f(this, &mut h);
|
||||
h
|
||||
}
|
||||
|
||||
unsafe extern "system" fn heap_gpu_start_x(this: *mut c_void) -> u64 {
|
||||
let f: unsafe extern "system" fn(*mut c_void, *mut u64) -> *mut u64 = std::mem::transmute(orig_fn(this, 10));
|
||||
let mut h = 0u64;
|
||||
f(this, &mut h);
|
||||
h
|
||||
}
|
||||
|
||||
unsafe extern "system" fn dev_create_committed_resource_x(this: *mut c_void, props: usize, flags: usize, desc: usize, state: usize, clear: usize, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT {
|
||||
static SEEN: AtomicU64 = AtomicU64::new(0);
|
||||
if desc != 0 && SEEN.fetch_add(1, Ordering::Relaxed) < 8 {
|
||||
let w = |o: usize| *((desc + o) as *const u32);
|
||||
crate::xlog_info!(
|
||||
"CreateCommittedResource (konsola, slot 76): wymiar {} {}x{} format {} flagi {:#x}; pola konsoli za opisem PC: +52 {:#x} +56 {:#x}",
|
||||
w(0),
|
||||
*((desc + 16) as *const u64),
|
||||
w(24),
|
||||
w(32),
|
||||
w(48),
|
||||
w(52),
|
||||
w(56)
|
||||
);
|
||||
crate::xlog_info!(" opis (dwordy): {:x?}", (0..16).map(|k| w(4 * k)).collect::<Vec<_>>());
|
||||
}
|
||||
// console texture layouts (seen: 0x101, with 3 at +52) are not PC ones: the driver picks
|
||||
// its own (UNKNOWN); the console layout matters only where console code reads the memory
|
||||
let mut pc_desc = [0u8; 56];
|
||||
let mut desc = desc;
|
||||
if desc != 0 {
|
||||
std::ptr::copy_nonoverlapping(desc as *const u8, pc_desc.as_mut_ptr(), 56);
|
||||
let layout = u32::from_le_bytes(pc_desc[44..48].try_into().unwrap());
|
||||
if layout > 3 {
|
||||
pc_desc[44..48].copy_from_slice(&0u32.to_le_bytes());
|
||||
pc_desc[52..56].copy_from_slice(&0u32.to_le_bytes());
|
||||
desc = pc_desc.as_ptr() as usize;
|
||||
}
|
||||
}
|
||||
let hr = dev_create_committed_resource(this, props, flags, desc, state, clear, riid, ppv);
|
||||
if hr < 0 && SEEN.load(Ordering::Relaxed) <= 8 {
|
||||
let pw = |o: usize| if props == 0 { 0 } else { *((props + o) as *const u32) };
|
||||
crate::xlog_warn!(
|
||||
"CreateCommittedResource (konsola): {hr:#x}; sterta typ {} cpu {} pula {}, flagi sterty {flags:#x}, stan {state:#x}",
|
||||
pw(0),
|
||||
pw(4),
|
||||
pw(8)
|
||||
);
|
||||
}
|
||||
hr
|
||||
}
|
||||
|
||||
unsafe extern "system" fn dev_create_command_list_x(this: *mut c_void, mask: usize, ty: usize, alloc: usize, pso: usize, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT {
|
||||
let pc_pso = super::console_list::pc_pso(pso as *mut c_void) as usize;
|
||||
let hr = dev_create_command_list(this, mask, ty, alloc, pc_pso, riid, ppv);
|
||||
|
||||
@@ -851,3 +851,58 @@ fn xbox_bvh_builder_builds_a_tlas_on_the_gpu() {
|
||||
assert!(hits > 30);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// FSR4 (console upscaler) for learning how console code binds textures / descriptor tables
|
||||
// ---------------------------------------------------------------------------------------
|
||||
|
||||
#[repr(C)]
|
||||
struct FfxHeader {
|
||||
ty: u64,
|
||||
next: *mut FfxHeader,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct FfxCreateUpscale {
|
||||
header: FfxHeader,
|
||||
flags: u32,
|
||||
max_render: [u32; 2],
|
||||
max_upscale: [u32; 2],
|
||||
message: usize,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct FfxBackend {
|
||||
header: FfxHeader,
|
||||
device: *mut std::ffi::c_void,
|
||||
}
|
||||
|
||||
/// Probe: the console FSR4 upscaler creates its context on XCL's device. With
|
||||
/// XCL_D3D12_TRACE=1 the device methods it calls are logged. `XCL_PROBE_FSR=1` runs it.
|
||||
#[test]
|
||||
fn fsr4_console_upscaler_creates_a_context_probe() {
|
||||
let Some(dir) = setup() else { return };
|
||||
if std::env::var_os("XCL_PROBE_FSR").is_none() {
|
||||
return;
|
||||
}
|
||||
let m = load(dir, "amd_fidelityfx_upscaler_xbox.dll");
|
||||
unsafe {
|
||||
let iid: [u8; 16] = [0xf1, 0x19, 0x98, 0x18, 0xb6, 0x1d, 0x57, 0x4b, 0xbe, 0x54, 0x18, 0x21, 0x33, 0x9b, 0x85, 0xf7];
|
||||
let mut dev: *mut std::ffi::c_void = std::ptr::null_mut();
|
||||
assert!(xcl::hle::d3d12x::D3D12XboxCreateDevice(std::ptr::null_mut(), std::ptr::null(), iid.as_ptr() as _, &mut dev) >= 0);
|
||||
let mut backend = FfxBackend { header: FfxHeader { ty: 0x0100_0002, next: std::ptr::null_mut() }, device: dev };
|
||||
let mut desc = FfxCreateUpscale {
|
||||
header: FfxHeader { ty: 0x0001_0000, next: &mut backend.header },
|
||||
// the only configuration in the game's package (the DLL says so on its debug output):
|
||||
// HDR | inverted depth | auto exposure, 1280x720 -> 1920x1080
|
||||
flags: 1 | 1 << 3 | 1 << 5,
|
||||
max_render: [1280, 720],
|
||||
max_upscale: [1920, 1080],
|
||||
message: 0,
|
||||
};
|
||||
let create: extern "C" fn(*mut usize, *mut FfxHeader, *const u8) -> u32 = std::mem::transmute(proc(&m, "ffxCreateContext"));
|
||||
let mut ctx = 0usize;
|
||||
let rc = create(&mut ctx, &mut desc.header, std::ptr::null());
|
||||
println!("ffxCreateContext: kod {rc:#x}, kontekst {ctx:#x}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user