mirror of
https://github.com/ivall/xcl.git
synced 2026-11-24 05:14:57 +01:00
Fortnite's console imports: xmem statistics and physical pages, IID data, DXC
From the list of the 31 console-library functions Fortnite (Series)
imports:
- XMemGetWorkingSetStatistics fills the 0x78-byte statistics (+0 title
limit, +8 used) instead of failing; XMemTransferMemory succeeds
- XMem{Allocate,Map,Free}PhysicalPages on the title physical pages
- IID_ID3D12Device as a data export of d3d12_xs
- dxcompiler_xs.dll / dxcompiler_x.dll: the PC DXC
Nested occlusion queries: Fortnite nests its per-object queries in a
dummy outer one, so the inner ones are now the real queries and the outer
one ends early and resolves as visible.
Test title: xmem imports from xmem.dll; the nested query check expects
the inner query's real count.
This commit is contained in:
+23
-5
@@ -587,12 +587,30 @@ Console GPU addresses in unified memory are the title's own: memory operations g
|
||||
- Not modelled (logged, no-op): Wait32 / 64BitValueX #71 / #72, GDS #76 / #77, KickoffX #93 (TomBox splits the list
|
||||
and submits the first part), depth bias X #94 (needs pipelines with dynamic depth bias), hints (HiStencil, MSAA,
|
||||
compression, limits, prefetch).
|
||||
- **Nested occlusion queries** (#28 / #29 / #30; the console allows them, the PC one active per list): one begun while
|
||||
another is active is not sent to the PC – the outer one counts on (exact: the inner range lies in it), the inner one
|
||||
resolves as visible (0x10000 samples, binary 1; written over the resolved data, MARKER_OUT). TomBox ends the outer
|
||||
one early instead – its count can then be 0 and the object culled. List Reset (#10) forgets the active queries.
|
||||
- **Nested occlusion queries** (#28 / #29 / #30; the console allows them, the PC one active per list): when one begins
|
||||
while another is active, the outer one ends there on the PC and resolves as visible (0x10000 samples, binary 1;
|
||||
written over the resolved data, MARKER_OUT); the inner one is a real query – Fortnite nests its per-object queries in
|
||||
a dummy outer one. List Reset (#10) forgets the active queries.
|
||||
- The test title writes / fills / copies its own graphics memory through #60–#89, takes a GPU timestamp, draws
|
||||
through DrawIndexedX and #47 with indices in its memory, and nests occlusion queries (outer = 2 × a single draw's).
|
||||
through DrawIndexedX and #47 with indices in its memory, and nests occlusion queries (inner = a single draw's).
|
||||
|
||||
## Fortnite's console imports (session 5, 2026-11-21; from TomBox's library map, Fortnite XSX 2.0.1461.7919)
|
||||
The EXE (+ EOSSDK) imports 31 functions from console libraries: MFPlat `MFResetDXGIDeviceManagerX`; xmem `XMemAlloc`,
|
||||
`XMemFree`, `XMemAllocDefault`, `XMemFreeDefault`, `XMemVirtualAlloc`, `XMemGetWorkingSetStatistics`,
|
||||
`XMemTransferMemory`, `XMemAllocatePhysicalPages`, `XMemMapPhysicalPages`, `XMemFreePhysicalPages`; xg_xs
|
||||
`XGCreateTextureComputer`; d3d12_xs `D3D12XboxCreateDevice`, `D3D12CreateDevice`, `IID_ID3D12Device` (data),
|
||||
`D3D12SerializeRootSignature`, `D3D12SerializeVersionedRootSignature`, `D3D12XboxSetProcessDebugFlags`; XCRDAPI
|
||||
`DStorageGetFactory`; dxcompiler_xs `DxcCreateInstance`; AcpHal `AcpHalCreate`, `ApuAlloc`, `ApuFree`, `ApuCreateHeap`,
|
||||
`ApuHeapGetState`, `AcpHalAllocateShapeContexts`.
|
||||
- Now in XCL: `XMemGetWorkingSetStatistics` (0x78 bytes, +0 title limit, +8 used – Fortnite sizes its pools from them;
|
||||
it returned FALSE), `XMemTransferMemory` (TRUE), `XMem{Allocate,Map,Free}PhysicalPages` on the title physical pages
|
||||
(64 KiB, contiguous; a chosen address / scattered pages are still refused – Fortnite's texture streaming maps pages
|
||||
into reserved address space, so that is next), `IID_ID3D12Device` as data, `dxcompiler_xs.dll` = the PC DXC.
|
||||
- Missing (each a project): `XGCreateTextureComputer` (the console texture layout computer – TomBox reimplements
|
||||
`xg_xs`), `DStorageGetFactory` (console DirectStorage – Fortnite's IO), AcpHal / SHAPE / xapu / XMA (the hardware audio
|
||||
path Fortnite plays through).
|
||||
- Nested occlusion queries: Fortnite nests its per-object queries in a dummy outer one, so the inner ones are now the
|
||||
real queries and the outer one ends early and resolves as visible (it was the other way round).
|
||||
|
||||
## Device as IDXGIDevice, XMemVirtualAlloc (session 5, 2026-11-21)
|
||||
- The console D3D12 device is also an IDXGIDevice / 1 / 2: Microsoft's public GDK samples (ATG DeviceResources) take the
|
||||
|
||||
@@ -71,6 +71,11 @@ fn load() -> Result<&'static (PathBuf, usize), String> {
|
||||
.map_err(|e| e.clone())
|
||||
}
|
||||
|
||||
/// The PC compiler's DxcCreateInstance (for titles that use the console's `dxcompiler_xs.dll`).
|
||||
pub fn create_instance() -> Option<usize> {
|
||||
load().ok().map(|&(_, f)| f)
|
||||
}
|
||||
|
||||
fn create_fn() -> Result<CreateInstance, String> {
|
||||
let &(_, f) = load()?;
|
||||
Ok(unsafe { std::mem::transmute::<usize, CreateInstance>(f) })
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
//! Write32BitValueBottomOfShaderX #90. A title call of any other extension (waits on memory,
|
||||
//! GDS, KickoffX, depth bias, hints…) is logged and does nothing (`real::class_for`).
|
||||
//!
|
||||
//! Occlusion queries may nest on the console; the PC allows one active per list. One begun
|
||||
//! while another is active is not sent to the PC: the outer one counts on (its result is
|
||||
//! exact – the inner range lies in it), the inner one resolves as visible.
|
||||
//! Occlusion queries may nest on the console; the PC allows one active per list. When one
|
||||
//! begins while another is active, the outer one ends there on the PC and resolves as visible;
|
||||
//! the inner one is a real query (Fortnite nests its per-object queries in a dummy outer one).
|
||||
//!
|
||||
//! Console GPU addresses in unified memory are the title's own addresses; memory operations
|
||||
//! go to that window's buffer (`real::uma_window_buffer`), which is in COMMON between them.
|
||||
@@ -380,34 +380,32 @@ pub(super) unsafe extern "system" fn draw_indexed_x(this: *mut c_void, va: u64,
|
||||
/// a query: (heap, index)
|
||||
type Query = (usize, u32);
|
||||
|
||||
/// One list's occlusion queries: the active one and those begun while it was (not sent to
|
||||
/// the PC).
|
||||
/// One list's occlusion queries: the one active on the PC and the outer ones it ended early.
|
||||
#[derive(Default)]
|
||||
struct Occlusion {
|
||||
active: Option<Query>,
|
||||
inner: Vec<Query>,
|
||||
ended_early: Vec<Query>,
|
||||
}
|
||||
|
||||
impl Occlusion {
|
||||
/// Whether the PC begins `q`.
|
||||
fn begin(&mut self, q: Query) -> bool {
|
||||
if self.active.is_none() {
|
||||
self.active = Some(q);
|
||||
return true;
|
||||
/// Begin `q` on the PC; Some(outer): end that one on the PC first.
|
||||
fn begin(&mut self, q: Query) -> Option<Query> {
|
||||
let outer = self.active.replace(q);
|
||||
if let Some(o) = outer {
|
||||
self.ended_early.push(o);
|
||||
}
|
||||
self.inner.push(q);
|
||||
false
|
||||
outer
|
||||
}
|
||||
|
||||
/// Whether the PC ends `q` (not: an inner one).
|
||||
/// Whether the PC ends `q` (not: an outer one already ended – it resolves as visible).
|
||||
fn end(&mut self, q: Query) -> bool {
|
||||
if self.active == Some(q) {
|
||||
self.active = None;
|
||||
return true;
|
||||
}
|
||||
match self.inner.iter().position(|e| *e == q) {
|
||||
match self.ended_early.iter().position(|e| *e == q) {
|
||||
Some(i) => {
|
||||
self.inner.swap_remove(i);
|
||||
self.ended_early.swap_remove(i);
|
||||
false
|
||||
}
|
||||
None => true,
|
||||
@@ -416,9 +414,9 @@ impl Occlusion {
|
||||
}
|
||||
|
||||
static OCCLUSION: Mutex<Option<HashMap<usize, Occlusion>>> = Mutex::new(None);
|
||||
/// inner queries since ended, and the result they resolve to
|
||||
/// outer queries ended early, and the result they resolve to
|
||||
static VISIBLE: Mutex<Option<HashMap<Query, u64>>> = Mutex::new(None);
|
||||
/// what an inner OCCLUSION query reports (BINARY_OCCLUSION: 1)
|
||||
/// what such an OCCLUSION query reports (BINARY_OCCLUSION: 1)
|
||||
const VISIBLE_SAMPLES: u64 = 0x1_0000;
|
||||
|
||||
fn is_occlusion(ty: D3D12_QUERY_TYPE) -> bool {
|
||||
@@ -439,12 +437,12 @@ pub(super) unsafe extern "system" fn reset_x(this: *mut c_void, alloc: usize, ps
|
||||
pub(super) unsafe extern "system" fn begin_query_x(this: *mut c_void, heap: usize, ty: D3D12_QUERY_TYPE, index: u32) {
|
||||
static N: AtomicU64 = AtomicU64::new(0);
|
||||
if is_occlusion(ty) {
|
||||
let forward = OCCLUSION.lock().unwrap().get_or_insert_with(HashMap::new).entry(this as usize).or_default().begin((heap, index));
|
||||
if !forward {
|
||||
let outer = OCCLUSION.lock().unwrap().get_or_insert_with(HashMap::new).entry(this as usize).or_default().begin((heap, index));
|
||||
if let Some((h, i)) = outer {
|
||||
if once(&N, 1) {
|
||||
crate::xlog_info!("D3D12.X: nested occlusion query – the outer one counts on, the inner one reports visible");
|
||||
crate::xlog_info!("D3D12.X: nested occlusion query – the outer one ends there and reports visible, the inner one counts");
|
||||
}
|
||||
return;
|
||||
pc::<QueryFn>(this, PC_END_QUERY)(this, h, ty, i);
|
||||
}
|
||||
if let Some(m) = VISIBLE.lock().unwrap().as_mut() {
|
||||
m.remove(&(heap, index));
|
||||
@@ -467,7 +465,7 @@ pub(super) unsafe extern "system" fn end_query_x(this: *mut c_void, heap: usize,
|
||||
}
|
||||
|
||||
/// command list #30 ResolveQueryData(heap, type, first, count, destination, offset) (PC #54):
|
||||
/// inner occlusion queries are written over the resolved data (after it, in COPY_DEST as
|
||||
/// outer occlusion queries ended early are written over the resolved data (after it, in COPY_DEST as
|
||||
/// ResolveQueryData wants the destination)
|
||||
pub(super) unsafe extern "system" fn resolve_query_data_x(this: *mut c_void, heap: usize, ty: D3D12_QUERY_TYPE, first: u32, count: u32, dest: usize, offset: u64) {
|
||||
type F = unsafe extern "system" fn(*mut c_void, usize, D3D12_QUERY_TYPE, u32, u32, usize, u64);
|
||||
@@ -497,16 +495,20 @@ pub(super) unsafe extern "system" fn resolve_query_data_x(this: *mut c_void, hea
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn nested_occlusion_queries_leave_the_outer_one_on_the_pc() {
|
||||
fn nested_occlusion_queries_end_the_outer_one_early() {
|
||||
let mut o = super::Occlusion::default();
|
||||
assert!(o.begin((1, 0)));
|
||||
assert!(!o.begin((1, 1)), "inner: not begun on the PC");
|
||||
assert!(!o.end((1, 1)), "inner: not ended on the PC");
|
||||
assert!(o.end((1, 0)));
|
||||
// overlapping, not nested: A, B, end A, C, end B, end C
|
||||
assert!(o.begin((1, 2)) && !o.begin((1, 3)) && o.end((1, 2)));
|
||||
assert!(o.begin((1, 4)) && !o.end((1, 3)) && o.end((1, 4)));
|
||||
assert!(o.active.is_none() && o.inner.is_empty());
|
||||
assert_eq!(o.begin((1, 0)), None);
|
||||
assert_eq!(o.begin((1, 1)), Some((1, 0)), "the outer one ends on the PC");
|
||||
assert!(o.end((1, 1)), "inner: a real query");
|
||||
// more per-object queries inside the same outer one
|
||||
assert_eq!(o.begin((1, 2)), None);
|
||||
assert!(o.end((1, 2)));
|
||||
assert!(!o.end((1, 0)), "outer: already ended");
|
||||
// overlapping, not nested: A, B, end A, end B
|
||||
assert_eq!(o.begin((1, 3)), None);
|
||||
assert_eq!(o.begin((1, 4)), Some((1, 3)));
|
||||
assert!(!o.end((1, 3)) && o.end((1, 4)));
|
||||
assert!(o.active.is_none() && o.ended_early.is_empty());
|
||||
assert!(o.end((1, 9)), "a query not begun here: the PC's call");
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,16 @@ use std::sync::OnceLock;
|
||||
|
||||
use crate::util::{HRESULT, S_OK};
|
||||
|
||||
/// data export: titles pass `&IID_ID3D12Device` to D3D12XboxCreateDevice / QueryInterface
|
||||
static IID_ID3D12_DEVICE: windows::core::GUID = windows::core::GUID::from_u128(0x189819f1_1db6_4b57_be54_1821339b85f7);
|
||||
|
||||
pub fn exports() -> Vec<(&'static str, usize)> {
|
||||
let mut v = exports_fns();
|
||||
v.push(("IID_ID3D12Device", &IID_ID3D12_DEVICE as *const _ as usize));
|
||||
v
|
||||
}
|
||||
|
||||
fn exports_fns() -> Vec<(&'static str, usize)> {
|
||||
crate::hle_exports![
|
||||
D3D12CreateDevice,
|
||||
D3D12XboxCreateDevice,
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
//! `dxcompiler_xs.dll`: the console's DXC. Its factory is the public one, so titles get the PC
|
||||
//! compiler XCL uses for its own translations (DXIL out; pipelines from PC shaders pass through).
|
||||
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use std::ffi::c_void;
|
||||
|
||||
use crate::util::HRESULT;
|
||||
|
||||
const E_FAIL: HRESULT = 0x8000_4005u32 as i32;
|
||||
|
||||
type CreateInstance = unsafe extern "system" fn(*const c_void, *const c_void, *mut *mut c_void) -> HRESULT;
|
||||
|
||||
pub fn exports() -> Vec<(&'static str, usize)> {
|
||||
crate::hle_exports![DxcCreateInstance, DxcCreateInstance2]
|
||||
}
|
||||
|
||||
pub unsafe extern "system" fn DxcCreateInstance(clsid: *const c_void, iid: *const c_void, out: *mut *mut c_void) -> HRESULT {
|
||||
match crate::gpu::recomp::dxc::create_instance() {
|
||||
Some(f) => std::mem::transmute::<usize, CreateInstance>(f)(clsid, iid, out),
|
||||
None => {
|
||||
if !out.is_null() {
|
||||
*out = std::ptr::null_mut();
|
||||
}
|
||||
crate::xlog_warn!("dxcompiler_xs: DxcCreateInstance – no DXC on this PC (XCL_DXC_DIR)");
|
||||
E_FAIL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `DxcCreateInstance2(IMalloc*, clsid, iid, out)`: the allocator is the PC compiler's own
|
||||
pub unsafe extern "system" fn DxcCreateInstance2(_malloc: *mut c_void, clsid: *const c_void, iid: *const c_void, out: *mut *mut c_void) -> HRESULT {
|
||||
DxcCreateInstance(clsid, iid, out)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn the_console_compiler_is_the_pc_one() {
|
||||
use windows::core::Interface;
|
||||
use windows::Win32::Graphics::Direct3D::Dxc::{IDxcCompiler3, CLSID_DxcCompiler};
|
||||
if crate::gpu::recomp::dxc::location().is_err() {
|
||||
return;
|
||||
}
|
||||
let mut p = std::ptr::null_mut();
|
||||
let hr = unsafe { super::DxcCreateInstance(&CLSID_DxcCompiler as *const _ as _, &IDxcCompiler3::IID as *const _ as _, &mut p) };
|
||||
assert!(hr >= 0 && !p.is_null(), "{hr:#x}");
|
||||
drop(unsafe { IDxcCompiler3::from_raw(p) });
|
||||
let (m, _) = crate::hle::registry().find_any("DxcCreateInstance").unwrap();
|
||||
assert_eq!(m.name, crate::hle::DXCOMPILER);
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,10 @@ pub fn exports() -> Vec<(&'static str, usize)> {
|
||||
XMemSetAllocationHooks,
|
||||
XMemVirtualQuery,
|
||||
XMemVirtualAlloc,
|
||||
XMemAllocatePhysicalPages,
|
||||
XMemMapPhysicalPages,
|
||||
XMemFreePhysicalPages,
|
||||
XMemTransferMemory,
|
||||
XMemGetWorkingSetStatistics,
|
||||
TitleMemoryStatus,
|
||||
JobTitleMemoryStatus,
|
||||
@@ -267,8 +271,25 @@ pub unsafe extern "system" fn XMemVirtualQuery(process: HANDLE, address: *const
|
||||
/// `BOOL XMemGetWorkingSetStatistics(UINT32 allocator, void* stats)` (as FSR's upscaler calls
|
||||
/// it: allocator 0x20000001, 128-byte buffer, reads +8 only on success). No statistics:
|
||||
/// FALSE, which the caller reports as 0 bytes.
|
||||
pub unsafe extern "system" fn XMemGetWorkingSetStatistics(_allocator: u32, _stats: *mut c_void) -> BOOL {
|
||||
0
|
||||
/// `BOOL XMemGetWorkingSetStatistics(DWORD flags, XMEM_WORKING_SET_STATISTICS* stats)`
|
||||
/// (0x78 bytes): +0 the title's memory limit, +8 what it uses – engines size their pools and
|
||||
/// texture streaming from these (Fortnite: flags 0x10000001). The rest is left zero.
|
||||
pub unsafe extern "system" fn XMemGetWorkingSetStatistics(_flags: u32, stats: *mut u8) -> BOOL {
|
||||
if stats.is_null() {
|
||||
fnd::SetLastError(fnd::ERROR_INVALID_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
let limit = crate::state::config().title_memory_budget_mb() * 1024 * 1024;
|
||||
std::ptr::write_bytes(stats, 0, 0x78);
|
||||
(stats as *mut u64).write_unaligned(limit);
|
||||
(stats.add(8) as *mut u64).write_unaligned(process_private_bytes().min(limit));
|
||||
1
|
||||
}
|
||||
|
||||
/// `BOOL XMemTransferMemory(direction, size)`: moving budget between the title and the tools
|
||||
/// pools – there is one budget here
|
||||
pub unsafe extern "system" fn XMemTransferMemory(_direction: u32, _size: usize) -> BOOL {
|
||||
1
|
||||
}
|
||||
|
||||
/// The title's debug output (console builds print a lot there) goes to XCL's log as well.
|
||||
@@ -446,6 +467,22 @@ pub unsafe extern "system" fn MapTitlePhysicalPages(va: *mut c_void, n: usize, _
|
||||
std::ptr::null_mut()
|
||||
}
|
||||
|
||||
/// `BOOL XMemAllocatePhysicalPages(XALLOC_ATTRIBUTES, SIZE_T* count, ULONG64* pages)`: the
|
||||
/// title physical pages above (64 KiB)
|
||||
pub unsafe extern "system" fn XMemAllocatePhysicalPages(_attrs: u64, num: *mut usize, arr: *mut u64) -> BOOL {
|
||||
AllocateTitlePhysicalPages(std::mem::zeroed(), 0, num, arr as *mut usize)
|
||||
}
|
||||
|
||||
/// `void* XMemMapPhysicalPages(void* address, SIZE_T count, ULONG64* pages)`
|
||||
pub unsafe extern "system" fn XMemMapPhysicalPages(va: *mut c_void, n: usize, arr: *mut u64) -> *mut c_void {
|
||||
MapTitlePhysicalPages(va, n, 0, 0, arr as *mut usize)
|
||||
}
|
||||
|
||||
/// `BOOL XMemFreePhysicalPages(SIZE_T count, ULONG64* pages)`
|
||||
pub unsafe extern "system" fn XMemFreePhysicalPages(n: usize, arr: *mut u64) -> BOOL {
|
||||
FreeTitlePhysicalPages(std::mem::zeroed(), n, arr as *mut usize)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// Threads / system info
|
||||
// ---------------------------------------------------------------------------------------
|
||||
|
||||
@@ -12,6 +12,7 @@ use crate::util::glob_match;
|
||||
|
||||
pub mod d3d12_layout;
|
||||
pub mod d3d12x;
|
||||
pub mod dxcompiler;
|
||||
pub mod kernelx;
|
||||
pub mod opus;
|
||||
pub mod xaudio2;
|
||||
@@ -71,6 +72,7 @@ pub const KERNELX: &str = "kernelx.dll";
|
||||
pub const XGAMERUNTIME: &str = "xgameruntime.dll";
|
||||
pub const D3D12X: &str = "d3d12_xs.dll";
|
||||
pub const XAUDIO2: &str = "xaudio2_9.dll";
|
||||
pub const DXCOMPILER: &str = "dxcompiler_xs.dll";
|
||||
|
||||
fn build(config: &Config) -> Registry {
|
||||
let modules = vec![
|
||||
@@ -78,6 +80,7 @@ fn build(config: &Config) -> Registry {
|
||||
HleModule::new(XGAMERUNTIME, xgameruntime::exports(), &[]),
|
||||
HleModule::new(D3D12X, d3d12x::exports(), &[]),
|
||||
HleModule::new(XAUDIO2, xaudio2::exports(), &["xaudio2_9.dll"]),
|
||||
HleModule::new(DXCOMPILER, dxcompiler::exports(), &[]),
|
||||
];
|
||||
let idx = |n: &str| modules.iter().position(|m| m.name == n).unwrap();
|
||||
let mut routes: Vec<(String, Route)> = Vec::new();
|
||||
@@ -113,6 +116,10 @@ fn build(config: &Config) -> Registry {
|
||||
for p in ["xaudio2_9.dll", "xaudio2_9redist.dll"] {
|
||||
routes.push((p.into(), Route::Hle(a)));
|
||||
}
|
||||
let c = idx(DXCOMPILER);
|
||||
for p in ["dxcompiler_xs.dll", "dxcompiler_x.dll"] {
|
||||
routes.push((p.into(), Route::Hle(c)));
|
||||
}
|
||||
Registry { modules, routes }
|
||||
}
|
||||
|
||||
|
||||
@@ -678,7 +678,7 @@ pub fn render_triangle() -> Result<(), String> {
|
||||
results.Map(0, None, Some(&mut r)).map_err(e)?;
|
||||
let counts = std::slice::from_raw_parts(r as *const u64, 3).to_vec();
|
||||
results.Unmap(0, None);
|
||||
ensure!(counts[2] > 0 && counts[0] == 2 * counts[2] && counts[1] > 0, "occlusion queries (outer, inner, single) = {counts:?}: expected 2 × single and a visible inner one");
|
||||
ensure!(counts[2] > 0 && counts[1] == counts[2] && counts[0] > 0, "occlusion queries (outer, inner, single) = {counts:?}: expected the inner one = single and a visible outer one");
|
||||
ensure!(top_right == [0, 255, 0, 255], "top-right quadrant {top_right:?} (expected green: DrawIndexedX)");
|
||||
ensure!(bottom_left == [0, 255, 0, 255], "bottom-left quadrant {bottom_left:?} (expected green: the title's index buffer, bound again)");
|
||||
ensure!(center == [0, 255, 0, 255], "centre pixel {center:?} (expected green triangle)");
|
||||
|
||||
@@ -26,6 +26,15 @@ struct SystemOsVersionInfo {
|
||||
revision: u16,
|
||||
}
|
||||
|
||||
// Fortnite imports these from xmem.dll (XCL finds console functions by name)
|
||||
#[link(name = "xmem", kind = "raw-dylib")]
|
||||
extern "system" {
|
||||
fn XMemGetWorkingSetStatistics(flags: u32, stats: *mut u64) -> i32;
|
||||
fn XMemAllocatePhysicalPages(attrs: u64, count: *mut usize, pages: *mut u64) -> i32;
|
||||
fn XMemMapPhysicalPages(va: *mut c_void, count: usize, pages: *mut u64) -> *mut c_void;
|
||||
fn XMemFreePhysicalPages(count: usize, pages: *mut u64) -> i32;
|
||||
}
|
||||
|
||||
#[link(name = "kernelx", kind = "raw-dylib")]
|
||||
extern "system" {
|
||||
fn XMemAlloc(size: usize, attrs: u64) -> *mut c_void;
|
||||
@@ -225,6 +234,19 @@ fn main() {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
check("xmem: working-set statistics, physical pages mapped and freed", || unsafe {
|
||||
let mut ws = [u64::MAX; 15];
|
||||
ensure!(XMemGetWorkingSetStatistics(0x1000_0001, ws.as_mut_ptr()) != 0, "XMemGetWorkingSetStatistics");
|
||||
ensure!(ws[0] >= 8 << 30 && ws[1] > 0 && ws[1] <= ws[0] && ws[2..].iter().all(|&x| x == 0), "limit / used {:#x} / {:#x}", ws[0], ws[1]);
|
||||
let (mut n, mut pages) = (4usize, [0u64; 4]);
|
||||
ensure!(XMemAllocatePhysicalPages(0, &mut n, pages.as_mut_ptr()) != 0 && n == 4, "XMemAllocatePhysicalPages");
|
||||
let p = XMemMapPhysicalPages(std::ptr::null_mut(), 4, pages.as_mut_ptr()) as *mut u32;
|
||||
ensure!(!p.is_null() && p as usize >> 32 >= 4, "XMemMapPhysicalPages: {p:?}");
|
||||
*p.add(0x1_0000) = 7; // second page
|
||||
ensure!(XMemFreePhysicalPages(4, pages.as_mut_ptr()) != 0, "XMemFreePhysicalPages");
|
||||
Ok(())
|
||||
});
|
||||
|
||||
check("kernelx: graphics memory lives in the GPU-visible 4 GiB-aligned region (UMA)", || unsafe {
|
||||
let attrs = 1u64 << 29; // memory type 1: graphics
|
||||
let a = XMemAlloc(0x20000, attrs);
|
||||
|
||||
Reference in New Issue
Block a user