Commit Graph

20 Commits

Author SHA1 Message Date
69e62ee790 runtime: committed resources from the title's allocator (__XMemAllocationHooks__)
Ported from VIctory (GPL-3.0-or-later, Marvisak and contributors, DexNom
fork): victory-hle xmem.rs (hooks, XMemAlloc/XMemFree, XMemAllocDefault)
and victory-gpu resource.rs (use_allocator, Memory::for_resource,
resource_attributes).

- xmem: once the title is mapped, gta6rt reads the exe's export
  __XMemAllocationHooks__ (two routine pointers, read at every call).
  XMemAlloc/XMemFree call them; the Default variants never do. An
  XMemAlloc/XMemFree made from inside the routines takes the default
  allocator, and no lock is held across a hook call (the title's handlers
  call XMemAllocDefault, which announces GPU blocks to the D3D12 layer).
- XMemAllocDefault decodes the attribute word (title_memory.h): CPU blocks
  at the asked alignment; graphics memory types and 32-bit addresses get
  pages of their own in the GPU window, made visible to the D3D12 layer and
  taken off it before they are freed (stale visible ranges under a new
  block are dropped first).
- D3D12 layer (rt::d3d12::set_title_allocator): the title's committed
  resources (CreateCommittedResource*, console slots 76/127 through the
  proxy) take GetResourceAllocationInfo's size from the allocator with
  VIctory's attributes (graphics allocator 128, page size, alignment,
  memory type 1/3), zeroed. Buffers are bound to that memory's import, so
  their GPU virtual address is the title address; textures report it and
  keep their own image memory. Released resources go back through the free
  routine (a buffer after the GPU retired the work submitted so far).
  Without hooks nothing changes.
- Tests: xmem_test (hook routing with a stand-in export, re-entrancy,
  rewritten and null table entries, GPU blocks); d3d12_title_memory_test
  (a slot-127 texture and committed buffers at the allocator's addresses,
  a GPU copy landing in the title's pages, frees through the hook).

Retail title: its hook takes a 64 MiB render-target pool from
XMemAllocDefault (attributes 0x30808000) and hands both back buffers out of
it; the pool check passes. Next: XboxBvhBuilder.dll throws a C++ exception
right after the first slot 62 pipeline finds no translated shaders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 21:26:28 -05:00
af75a43dc9 xmem: judge a fault on a committed page by the protection at the faulting address
The handler queried the protection at the start of the 64 KiB page, so
a write to a 4 KiB part the title had made read-only looked allowed and
was resumed, faulting again forever instead of reaching the title's own
handler. It now looks the record up by the page and the protection up
by the faulting address. xmem_test writes to a read-only 4 KiB part of
a read-write page and expects the fault.
2026-11-23 12:48:20 -05:00
75c2b87a75 xmem: take the fault lock before reading or changing a mapped page's record
unmap_page moved the record out of g_mapped before taking the exclusive
lock, so a first-touch fault on that page could read a moved-from
section, and map_page made the view live before recording it, so a
fault in between was not recognised. unmap_page now holds the exclusive
lock from the lookup to the erase, and map_page holds it across mapping
the view and recording it. xmem_test adds four threads writing into a
window while 256 slices of pages are mapped and unmapped under them.
Reported by tupacfan04 in the review of #7556.
2026-11-23 12:37:42 -05:00
abd85df49f xmem: rt::xmem::commit_physical_pages commits pages by page number
A writer that copies into physical pages through its own view of their
section (a DirectStorage destination given as page numbers, #7652) sees
reserve-only memory for pages the title has not touched yet, and no
fault handler can resolve that address. commit_physical_pages commits
the given pages through each section's own view, one VirtualAlloc per
contiguous run, so such a writer can commit before it copies. Raised by
nurtrino in #7599.
2026-11-23 12:26:16 -05:00
a07c8c0e89 xmem: commit physical pages on first touch, not when they are allocated
XMemAllocatePhysicalPages backed each call with one SEC_COMMIT section, so
the title's ~6.1 GiB page-pool request after boot stop 17 was charged in
full at once and fails with ERROR_COMMITMENT_LIMIT on a 16 GB machine.
Mapping the pages right away (as the title does) would charge most of it
within seconds too, so the commit now follows first access.

The section is SEC_RESERVE. A vectored handler commits the faulting 64 KiB
page through a reserve-only view of the whole section when the address
lies in a live mapping, so every view of that page sees it. Faults on
committed pages whose protection forbids the access, and faults outside
the mapped pages, go on to the next handler, and a failed commit is not
swallowed. rt::xmem::commit_physical_range commits a range up front for
shims that hand guest memory to the kernel.

Reported by controldebils and rafaelpssz in #7333.
2026-11-23 12:01:49 -05:00
042c5f3783 xmem: physical pages, default allocators, XMemIsToolsMemAvailable; XMemVirtualAlloc takes 2 MiB pages and placeholders (#6919)
Squash-merged after diff review of PR #6919
2026-11-23 10:40:07 -06:00
695792de7a xmem: record XMemVirtualAlloc's attribute word and drop the PAGE_GRAPHICS_* protection bits (retail exe GPU pools) (#6908)
Squash-merged after diff review of PR #6908 - xmem: record XMemVirtualAlloc's attribute word and drop the PAGE_GRAPHICS_* protection bits (retail exe GPU pools)
2026-11-23 09:35:03 -06:00
085fe1efd4 xmem: serve XMemTransferMemory (RT-449) (#6351)
Squash-merged after review of PR #6351 - xmem: serve XMemTransferMemory (RT-449)
2026-11-23 08:06:21 -06:00
e2ac2238fa Runtime test clashes: typeless clears accept WARP's nearest-even tie (#521), three close-parity copies now match WARP, the source-size checks start from 300x200 again after ResizeTarget, one test_attribute_trace in xmem_test
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 04:41:22 -05:00
2750153ed1 Merge pull request #2401 from Sc4ros
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:05:35 -05:00
be8570ace1 Merge remote-tracking branch 'origin/main' into triage-r43
# Conflicts:
#	docs/runtime_imports.md
#	runtime/CMakeLists.txt
#	runtime/shims/xgameruntime.cpp
#	runtime/test/xmem_test.cpp
#	tools/rdna2spirv.py
2026-11-22 22:12:50 -05:00
cf82fc26fd Merge pull request #3401 from 0xTehuti 2026-11-22 17:01:52 -05:00
fdf73f6696 Runtime: record each distinct XMemAlloc/XMemFree attribute word in --trace
xmem.cpp ignores the attributes argument, and the bits of the Scarlett
XALLOC_ATTRIBUTES word are not known yet. With gta6rt --trace FILE, the first
XMemAlloc and the first XMemFree for each distinct raw attribute word now
write an "xmem_attributes" event (api, the word, the size for an allocation,
the caller as module+RVA), so the bits can be decoded from a real run without
logging every allocation. Off: one relaxed load per call.

xmem_test opens a trace and checks one event per word and API, the size of the
first call, a caller on every event, and nothing recorded while the trace is
off. README.md documents the event.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 23:01:17 +01:00
4c52ce27a6 Seven fixes from an outside contributor (sent as patches, applied without the author's name)
- rdna2spirv: declare each packed vertex input register once; a register whose elements disagree on the component
  type is refused (SHADER-644).
- runtime: a title's VirtualAlloc drops the console's MEM_GRAPHICS / MEM_TITLE type bits the host rejects (RT-217).
- runtime: XPersistentLocalStorageImpl is served from <overlay>\persistent with the package's 2048 MB quota
  (RT-219; layout from the public docs, not measured in a caller).
- runtime: G:\ names the package and T:\ a scratch folder in the overlay; paths under the configured folders and
  every path with no folders configured stay host paths (RT-218).
- winhttp_offline: header blocks and timeouts the host WinHTTP rejects are rejected the same way.
- cfg_structure.run: a limit of zero or less runs no blocks.
- shader_meta: an s_movk_i32 with a register operand and a float immediate beyond float32 are left unknown instead
  of raising.

Each comes with a test that fails on the old code. Conflicts with main resolved here (internal_dir() hides T:'s
folder; both file_system_test blocks kept).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 16:55:46 -05:00
c2ac1ea34f xmem: strengthen registry +0 test against ullTotalPhys and qualify telemetry evidence (RT-220) 2026-11-22 21:46:27 +01:00
77eb9cd726 xmem: write title memory limit at +0 in XMemGetWorkingSetStatistics (RT-220) 2026-11-22 21:25:23 +01:00
c92424d3f5 Runtime: record each distinct XMemAlloc/XMemFree attribute word in --trace
xmem.cpp ignores the attributes argument, and the bits of the Scarlett
XALLOC_ATTRIBUTES word are not known yet. With gta6rt --trace FILE, the first
XMemAlloc and the first XMemFree for each distinct raw attribute word now
write an "xmem_attributes" event (api, the word, the size for an allocation,
the caller as module+RVA), so the bits can be decoded from a real run without
logging every allocation. Off: one relaxed load per call.

xmem_test opens a trace and checks one event per word and API, the size of the
first call, a caller on every event, and nothing recorded while the trace is
off. README.md documents the event.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 21:18:43 +01:00
84f86c5a7d test: cover XMem virtual allocation APIs 2026-11-22 17:20:42 +00:00
3da355d290 FSR: Xbox backend descriptor, console command-list map, XMemGetWorkingSetStatistics and device slot 67
amd_fidelityfx_upscaler_xbox.dll, measured with Ghidra 12.2 (through REA)
and run by fsr_dispatch_test on PC devices (RTX 2000 Ada and WARP) behind
the Xbox-ABI proxy.

Backend descriptor: the provider's create walks the chain for type
0x01000002, {header, device} with the device at +0x10, and ends in
FFX_API_RETURN_ERROR without it (what RT-3 got with 0x0200000x). With it
the DLL creates its backend through the proxy: device slots 14, 15, 18, 19,
27, 38 and 76 and heap slot 9, at the shapes the PC order and the measured
overrides predict; slot 76 takes the seven CreateCommittedResource
arguments. No earlier test here reached slot 76 or heap slot 9.

Two runtime bugs it found:
- XMemGetWorkingSetStatistics takes (kind, stats*): all seven call sites
  pass kind 0x20000001 in ECX and a stack buffer in RDX. The one-argument
  shim wrote to address 0x20000001.
- Device slot 67 is a console-only compute-pipeline call (a code blob in its
  desc), not the PC CreateProtectedResourceSession1 the proxy forwarded it
  to. The proxy now refuses it (E_NOTIMPL).

The context: on the RTX 2000 Ada the create stops at the DLL's HRESULT
check, because the driver refuses its R9G9B9E5_SHAREDEXP texture with
ALLOW_UNORDERED_ACCESS (WARP takes it). The test reports that stop and
retries with one PC stand-in (that texture as R32_UINT). On the context it
records one ffxDispatch into a logging command list that is never executed.

The console command list, from that run and the DLL's recorder (RVA
0x59a0), the same 13 calls on both devices: slots 14, 15, 25 and 26 at
their PC positions, then SetDescriptorHeaps at 32 (PC 28, seen in the run),
SetComputeRootDescriptorTable at 35 (PC 31), ClearUnorderedAccessViewUint
at 53 (PC 49, seen in the run), ExecuteIndirect at 61 (PC 59), and
console-only methods at 85 and 141. 33 and 41 fit SetComputeRootSignature
and SetComputeRootConstantBufferView by shape; the docs mark them inferred.
The logging list forwards only measured slots. The list object also carries
a write cursor and limits (+0x18, +0x28, +0x30) the DLL writes root
arguments and dispatches through while there is room; with the cursor at
the limit every command takes the vtable. These are the fields docs section
3.4 measured in the BVH builder without a meaning.

The dispatch stops at the DLL's compute pipeline: its 29 shaders are DXBC
with an ACCC part (payload tag FSPX) and no DXIL, and the PC runtime
refuses them at slot 62; the dispatch goes on with the null pipeline and
faults, which the test reports as the documented PC limit. Its C++ `throw`
also shows the loader gap: _CxxThrowException finds no image base for a
manually mapped image.

The test's fault report gives the faulting module and RVA, the access, the
C++ throw's ThrowInfo, image base and unwound stack, and the HRESULT the
DLL formatted with the DLL frames that made the failing call.

Docs: d3d12_vulkan.md Appendix A.3 and open question 2,
d3d12_command_objects.md 3.4 and 3.5a, design.md and runtime/README.md.
2026-11-22 04:58:12 +01:00
ad7691790b Runtime: tests for the measured xmem shim ABI 2026-11-21 17:42:40 +00:00