Skip to content

d3d12_xs: device slot 70 builds typed and structured buffer views, on the title's pages when no buffer holds the address (on #8304) - #9068

Closed
Etr0p wants to merge 40 commits into
ProjectLeonida:mainfrom
Etr0p:slot70-views
Closed

Etr0p wants to merge 40 commits into
ProjectLeonida:mainfrom
Etr0p:slot70-views

Conversation

@Etr0p

@Etr0p Etr0p commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Depends on: #8304 (thedarkcr0w's placed-buffer registry for device slot 70; this branch is on its head 335d0a1). Only the last two commits are this PR; the rest is #8304. Claim: #8683, comment 7111497518.

What and why

Device slot 70 (the console's SRV from raw words and a GPU address) only builds a view for the raw R32_TYPELESS buffer shape (#7066, #8304). Everything else gets #7066's null SRV. On the retail boot, the title makes typed R16_UINT buffer views through slot 70 before the first frame, and those got the null view (arg2 is not a raw R32_TYPELESS view). This PR:

  1. Typed and structured buffer views (90af41a36). A buffer view names [va, va + Width) of the buffer that holds va, as the raw view already did. It is counted in elements of 4 bytes (raw), of the format's size (typed) or of the stride (structured). A typeless or block-compressed typed format, an address that is not a whole number of elements, and texture descriptions keep the null view. The null view is now logged once per reason, not once per process.
  2. Bytes no buffer holds (7e27a9fd5). On the retail boot, the R16_UINT views point at memory that no slot 133 buffer and no resource provider holds: the title's own memory. Slot 70 now asks the handler slot 133 already uses (set_placed_at_va_handler) for a buffer on the title's pages over that range. The GPU then reads what the CPU writes there, then and later, with no copy. The proxy asks once per device and range, reuses the buffer for views inside it, and holds it until the device dies (the descriptors name it). A placed buffer still wins. With no handler (a PC device behind the proxy), or when the handler refuses, the view stays null with a log line that says which.

Not in this PR: texture views keep the null view, with a log line. Most of them name tiled (0x101) textures the title keeps in its own memory, and making those textures on the PC belongs to editrice's claim (#8344, comment 7110588819). I tried a local approach (a PC texture per address and description, detiled from the title's memory) and measured it below, but did not include it here.

Tests

Windows 11 26200, MSVC 14.44, xs_proxy_mock_test (all 7 ctest variants pass: default, --fail-virtualalloc, --fail-virtualprotect, --fail-veh, --env-slots, --env-slots-invalid, --env-slots-70):

  • check_slot70_typed_buffer: the two measured R16_UINT shapes (768 and 6144 bytes), other typed formats (16- and 1-byte elements, a width cut at the buffer's end), a structured view, the raw view unchanged, and 7 shapes that keep the null view (unaligned address, typeless format, BC format, structured view with a format, raw view not R32_TYPELESS, address outside every buffer, buffer description with a texture view).
  • check_slot70_title_pages: no handler → null view; the measured shapes → one handler call each, with the buffer description and the UNDEFINED layout slot 133 gives a buffer; a range inside an earlier one → the same buffer, no new call; a placed buffer winning; a refusal → null view; the buffers released with the device.
  • Negative controls: the new test file built against d3d12_xs: device slot 70 finds the buffer slot 133 placed at its address in the proxy (a real view on the PC device and with #7075's stand-in; complements #8225) #8304's d3d12_xs_device.cpp fails (the typed view is null). Built against the first commit alone, it fails in check_slot70_title_pages (no buffer on the title's pages, null view).

Retail measurement (counts only)

RTX 5070 Ti Laptop GPU, NVIDIA 621.24, Vulkan layer (LEONIDA_D3D12=vulkan), my own Xbox 1.0.2.1 copy, local integration stack (rt5-integration with the PRs from my earlier measurements, #8225, #7949, #7880 and #8304), LEONIDA_SKIP_INT3=1. Same stack before and after; only slot 70 changes. Counts are of slot 70 views; "readback" copies the presented image to a READBACK buffer at PresentX 2, 300 and 3000 and counts its non-zero pixels (a local diagnostic, not in this PR).

run null views (all made before the first frame) real views by PresentX 2 non-zero pixels in the presented image
#8304 alone 72 3 0 of 8,294,400
this PR 60 16 0
this PR + my local texture experiment (not in this PR) 45 31 0
  • In the frame loop, slot 70 is called once per frame, always with the raw shape d3d12_xs: device slot 70 finds the buffer slot 133 placed at its address in the proxy (a real view on the PC device and with #7075's stand-in; complements #8225) #8304 handles: 0 refusals per frame before and after. The image is still all black, so this PR is not the cause of the black frame; it removes 12 null descriptors the title made at start-up.
  • With this PR, all buffer views get a real view: the typed R16_UINT ones through a buffer on the title's pages, plus one structured view.
  • The 60 views still null are all texture views. The 52 that carry an address name the title's own memory: none is inside a slot 133 buffer or in memory a slot 76/127 resource leases, so there is no PC resource to view yet:
    • 27 TEXTURE1D views of linear 1D textures (layout word 0x100; formats A8_UNORM ×26, R8G8B8A8_UNORM_SRGB ×1);
    • 25 views of textures in the tiled layout 0x101: TEXTURE2D ×15, TEXTURE2DARRAY ×3, TEXTURECUBE ×2, TEXTURECUBEARRAY ×2, TEXTURE3D ×3 (one mip each);
  • 8 more are TEXTURE2D views whose address word is 0 (formats R32_FLOAT with a mip chain ×6, R9G9B9E5_SHAREDEXP ×2).
  • 0 PresentX failures and no crash in any run (each run was stopped at its time limit).

Hardware / driver

RTX 5070 Ti Laptop GPU (Blackwell), NVIDIA 621.24, Windows 11 Home 26200.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

Pipodi and others added 30 commits November 23, 2026 16:30
…e PC vtable refuse with E_NOTIMPL

The retail title calls device slot 133, past the 128-entry table; the call read an empty entry and jumped to 0.
Every slot beyond the PC device's vtable now reaches the generic thunk. Mock test covers slot 133.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ory (VK_EXT_external_memory_host)

The retail executable opens the 64 KiB graphics region it has just committed with XMemVirtualAlloc
through device slot 48 right after its first queue and fence; the layer answered E_NOTIMPL and the
title asserted.

The call now answers as the host runtime does on an RTX 4090 and WARP (six cases measured in
d3d12_existing_heap_test): the base of a VirtualAlloc allocation committed read-write over its whole
size opens a heap of that size, 64 KiB aligned, CUSTOM / WRITE_BACK / L0, SHARED |
SHARED_CROSS_ADAPTER | ALLOW_SHADER_ATOMICS; an inner address, a partial or reserve-only commit
and a read-only range are E_INVALIDARG. The backing is the range itself, imported with
VK_EXT_external_memory_host, which the device and the test device enable when present.
CheckFeatureSupport(EXISTING_HEAPS) follows the extension. Placed resources in such a heap are
refused (E_NOTIMPL, logged) until the placed path addresses memory outside the arena.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… an uncached one is refused

Measured on the RTX 4090 and WARP: PAGE_READWRITE | PAGE_WRITECOMBINE is accepted with
CPUPageProperty WRITE_COMBINE, PAGE_READWRITE | PAGE_NOCACHE is E_INVALIDARG. Two new cases in
d3d12_existing_heap_test; 8 of 8 match both host devices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e (CreatePlacedResourceX stand-in)

Xbox device slot 133 is (va, desc, initial_state, clear_value, riid, out), the shape of the console's
CreatePlacedResourceX. With ItsNotRexed#6953 the call reaches the beyond-table refusal and the title asserts on the
E_NOTIMPL. The proxy now answers it before that refusal: a committed DEFAULT-heap resource from the
description with the PC flag bits only, slot 76's layout rule, COMMON for a buffer or the all-ones state,
and the clear value only for render-target and depth textures. The resource is not backed by the memory
at va; that needs the physical-page mapper.

xs_proxy_mock_test: a mock CreateCommittedResource that records its arguments, and a slot 133 case over a
76-slot device (buffer, render target, all-ones state, null arguments, a failed creation). The
beyond-table check moves to slot 134.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ttedResource3 with Xbox descriptors, RT-5 stop 15)

Slot 127 is past the PC device vtable and was refused with E_NOTIMPL. It has the argument list of ID3D12Device10::CreateCommittedResource3; the proxy now calls the PC device's with the Xbox layout word and flag bits cleaned as slot 76 does. Measured in ItsNotRexed#6982.
…ead of reaching PC CreatePlacedResource1 (retail boot chain stop 14)
…0 wins over the built-in slot 70 handler

With LEONIDA_XS_FRAME_INTERVAL_SLOT=70, (0, 16667, 1, 0) reached the null-SRV writer and sent latency 1 as the CPU descriptor handle. The routes now live in route_xbox_device_slot, which slot 70 asks first. New xs_proxy_mock_env_slots_70 test fails before and passes after.
…nment, refuses null heap properties; tests pin heap flags, session and reference counts

Review of ItsNotRexed#7052: dispatch and release through the ID3D12Device10 interface pointer (not the base device's vtable); keep every PC-valid resource flag bit, 0x400 included; null heap properties return E_POINTER; the test now passes non-zero heap flags and a protected session, checks the single release returns 0 for texture and buffer, and covers a distinct Device10 pointer.
…resource

# Conflicts:
#	runtime/shims/d3d12_xs_device.cpp
#	runtime/shims/d3d12_xs_device.h
#	runtime/test/xs_proxy_mock_test.cpp
…n and runs on its own line, clear of the slot 73/list changes in ItsNotRexed#7076

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he title's own pages

Xbox device slot 133 is (va, desc, state, clear, riid, out): the title places a buffer at the VA of a
physical-page range it has just mapped (docs/retail_boot_chain.md 3.4, ItsNotRexed#6915). The proxy now hands it to
a handler the Vulkan layer registers (set_placed_at_va_handler), which imports [va, va + width) with
VK_EXT_external_memory_host and binds a VkBuffer to it: the CPU's writes there are the GPU's reads with no
copy, and the resource's console VA is the title's VA, so views and immediate writes the title names by
that VA resolve to it through the buffer VA index. The Xbox flag bits above the PC ones are dropped and
the layout made ROW_MAJOR, as slot 76 does; textures are E_NOTIMPL, a misaligned VA E_INVALIDARG, and
with no handler (a PC device) the slot refuses with E_NOTIMPL as ItsNotRexed#6953's table does.

Not decided here: a shader that adds heap_base to the title's VA (its own V#s) does not reach these
pages; that needs the single address space of docs/d3d12_vulkan.md 3.3.

d3d12_existing_heap_test: on a VirtualAlloc range and on a view of a pagefile-backed section (the form
xmem's physical pages take), the buffer's GPU VA is the address and a GPU copy to a READBACK buffer reads
a pattern the CPU wrote after creation; Vulkan validation clean on an RTX 4090.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…(XMem allocation hooks for descriptor heaps)
…le's XMem hook (retail boot chain stop 17)

The console D3D runtime allocates a committed resource's memory with XMemAlloc, so a title's
__XMemAllocationHooks__ see it. Around its first full-screen render targets the title installs a hook
that bump-allocates allocations with page-size field 2 from a fixed arena and then asserts that little
of the arena is left unused; with no call reaching the hook, nothing is counted and the assert fires.

After the PC device creates the resource, slot 127 calls the installed hook (the one ItsNotRexed#7021 bridges for
descriptor heaps) with the PC allocation size and the D3D allocator ID, page-size field 2, and attaches
the memory to the resource as private data, so it goes back through the hook's free when the resource
dies. The PC resource is not backed by it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ler registered by every Vulkan device

The PC flag mask was a D3D12_RESOURCE_FLAGS constant past the SDK's last enumerator, which clang-cl with
SDK 10.0.26100 refuses as a constant expression; it is an integer now, cast after the AND. The slot-133
handler was registered in create_vulkan_device only, so the standalone device gta6rt --run creates never
served the slot; the Device constructor registers it now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	runtime/shims/d3d12_xs_device.cpp
… found in review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… not import the title's pages

RADV under Wine refuses to import a view of a pagefile-backed section (E_OUTOFMEMORY on an RX 9070 XT,
found in review), which is the form xmem's physical pages take, so the retail boot stopped at the first
174 MiB placement. An import failure other than a misaligned VA now gives an ordinary DEFAULT buffer of
the same description, as ItsNotRexed#6915's stand-in did, logged once: the boot goes on, and the title's writes at
that VA don't reach it on such a driver.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…commit re-added it, found in review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sured raw-buffer shape and the VA is a buffer the layer knows (retail boot chain stop 14)

AI-assisted.
…and asks for a buffer that holds the whole width (review of the raw view)

AI-assisted.
…CreateCommittedResource3 with it

The word slot 133 passes after the description is a D3D12_BARRIER_LAYOUT, not a resource state:
the title passes all ones (UNDEFINED) for its first buffer and 6 (SHADER_RESOURCE) for 1x1
render-target and depth textures. Read as a state, 6 is INDEX_BUFFER | RENDER_TARGET, which the
PC device refuses for a texture, and the title then asserts on the missing resource.

On a PC device with ID3D12Device10 the resource is created through CreateCommittedResource3 with
the layout as given (UNDEFINED for a buffer). An older device gets CreateCommittedResource with the
legacy state of that layout, COMMON for UNDEFINED and for layouts that have none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ge check, immediate free, proxy test

- A write-combined (or uncached) page in the range is not imported: an RTX 5090 imported such a range
  and read wrong bytes back (found in review). It takes the ordinary-buffer fallback.
- The whole range must be committed, walked with VirtualQuery across allocations (the retail buffer
  spans three mapped windows); otherwise E_INVALIDARG instead of undefined behaviour in Vulkan.
- The imported memory is freed as soon as the submitted work has retired (wait_retire_ticket), not
  after the next submission: VK_EXT_external_memory_host needs the caller's pages to outlive it, and a
  title may free them right after releasing the resource.
- The PC flag mask is 0x5ff: 0x200, which the host refuses, is dropped. Slot 133 is listed in
  device_slot_overridden.
- xs_proxy_mock_test registers a handler and checks slot 133's argument positions, the flag mask
  (0x20204 -> 0x4), the ROW_MAJOR rewrite and the iid; d3d12_existing_heap_test checks the
  write-combined fallback and the partly committed refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ich varies from run to run

The host runtime answers 64 KiB on some runs and 4 MiB on others for the same allocation (RX 9070 XT,
RTX 5090, WARP; found in review), which made the test fail about 1 run in 40. The layer's Alignment
must still be 64 KiB for an opened heap, and the host's either of the two values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s at the offset; uncommitted pages fall back

The title places small buffers inside a page too: a 16-byte UAV at a 64-byte-aligned address on an
RTX 5090 (found in review), which the import refused with E_INVALIDARG, halting the boot. The import now
starts at the page holding the address and the buffer is bound at the offset; an offset off the
buffer's alignment takes the ordinary-buffer fallback. A range not fully committed (xmem commits on
first touch) also falls back instead of failing. Only a null address or a zero width are E_INVALIDARG.

d3d12_existing_heap_test: a buffer 64 bytes into a page reads back the CPU's writes at its own VA; a
1-byte offset and a partly committed range fall back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ad of E_NOTIMPL

The retail title places textures at slot 133 too, and asserted on the E_NOTIMPL (found in review). A
texture now gets an ordinary committed DEFAULT texture of the same description, as slot 76 gives one,
logged once; it is not on the title's pages. The proxy rewrites a texture's Xbox layout word to
UNKNOWN (a buffer's to ROW_MAJOR), as slot 76 does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Wine can report a requested write-combined allocation as ordinary read/write memory. Check the observed protection and retain the fallback expectation when a cache modifier is present; otherwise verify the read/write import. Add PAGE_NOCACHE to keep the unsafe-protection guard covered under Wine.

Claim: ItsNotRexed#7913 (comment)

Depends on: ItsNotRexed#7218

AI-assisted: Codex
…e starts in the matching state

The title's third word at slot 133 is a D3D12_BARRIER_LAYOUT, not a resource state (measured by
@dracbat on a retail boot: 0x6 SHADER_RESOURCE for its RT/DS textures, 0x3 UNORDERED_ACCESS for its
RT+UAV ones, 0xFFFFFFFF UNDEFINED for the 182 MiB buffer), as PC CreatePlacedResource2 takes it. The
proxy passes it to the handler, and a texture's ordinary committed fallback starts in the equivalent
legacy state (UNDEFINED and unlisted values give COMMON; a state the description refuses retries with
COMMON, so the title always gets its resource). Buffers are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thedarkcr0w and others added 6 commits November 23, 2026 19:19
…e's own pages; textures and refusals keep the committed stand-in of ItsNotRexed#7075)
…e resource of a slot 70 view of that address

Device slot 70 makes a shader-resource view from a description and a console
address, with no resource object. It asked only the device behind the proxy
for a buffer at that address, and that device knows the buffer by the title's
address only when it could put the buffer on the title's own pages. When it
could not (the import is refused, or the device is a PC one), the slot 133
buffer has an address of its own, nothing was found, and the title's
descriptor got the null view.

The proxy now remembers every buffer a slot 133 call made by the range the
title placed it at, whichever way it was made (the placed-at-VA handler, PC
CreateCommittedResource3 or CreateCommittedResource), and slot 70 asks there
first, then the device's provider. An entry holds no reference. An object
attached to the resource as private data removes the entry when the resource
dies, and a device proxy's entries go with it. The newest buffer over an
address answers, so a range the title places again is the new buffer's.

xs_proxy_mock_test: check_slot70_placed_buffer covers both creation paths
and the handler path, the element range, the cut at the buffer's end, the
addresses around two buffers, a texture, the provider fallback and its
order, a range placed twice, a released buffer and a released device. The
check of the placed-at-VA handler in check_levels hands out a mock resource
instead of a made-up pointer, since the proxy now asks the object for
ID3D12Resource.

Depends on: ItsNotRexed#7066 (slot 70), ItsNotRexed#7218 or ItsNotRexed#7075 (slot 133), ItsNotRexed#6953 (the table
reaches slot 133), and ItsNotRexed#7235 for the mock's SetPrivateDataInterface.
…emoves its entry in O(log n)

Releasing N placed buffers scanned N(N+1)/2 entries under the lock slot 70 takes (shdann's review on ItsNotRexed#8304).
The entries now live in a std::map keyed by their id. Ids only grow, so map order is placement order and
slot 70 still walks it backwards for the newest placement; a tag whose entry already went with its device
erases nothing. Teardown of 32,768 buffers released newest first: 151.63 ms before (shdann), 3.47 ms after
(same loop, MSVC /O2, Windows 11).
…raw ones

The retail boot makes typed R16_UINT buffer views through device slot 70 (768 and 6144 bytes, before the first
frame) besides the raw R32_TYPELESS view ProjectLeonida#8304 handles; those got the null view ("arg2 is not a raw R32_TYPELESS
view"). A buffer view now names [va, va + Width) of the buffer that holds va, as the raw view did, counted in
elements of 4 bytes (raw), of the format's size (typed) or of the stride (structured). A typeless or block-compressed
typed format, an address that is not a whole number of elements and every texture description keep the null view,
now with one log line per reason instead of one line in all.

xs_proxy_mock_test: typed views (the two measured R16_UINT shapes, other sizes, a width cut at the buffer's end), a
structured view, the raw view unchanged, and seven shapes that keep the null view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r on the title's pages

On the retail boot the two typed R16_UINT views name bytes in the title's own memory that no slot 133 buffer and no
resource provider holds, so they still got the null view. Slot 70 now asks the handler slot 133 uses
(set_placed_at_va_handler) for a buffer on the title's pages over [va, va + Width): the GPU reads what the CPU writes
there, then and later, with no copy. The proxy asks once per device and range, reuses the buffer for views inside
it, and holds it until the device dies (the descriptors name it). A placed buffer still wins; without a handler (a PC
device behind the proxy) or when it refuses, the view stays null with a log line saying which.

xs_proxy_mock_test: no handler, the measured 768- and 6144-byte shapes, a range inside one, a placed buffer winning, a
refusal, and the buffers released with the device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@svds12343 svds12343 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked: #90687e27a9f | base: GitHub main@867d922f09b86583859796a174df89555fb32da8 + #9068, local clean merge cf35da382be789044ddf3be15df56d4aa3df8e97 | on: Windows 11 Pro N for Workstations 25H2, build 26200.9457, MSVC 19.44.35230 x64, Windows SDK 10.0.26100.0, CMake 4.4.5, Python 3.12.5 | result: stock focused tests 9/9 pass, 0 skips; independent synthetic final-Release allocation-failure probe reproduces one P2.

Claim: #9065 (comment). Depends on: #8304; this review concerns only #9068's two added commits (90af41a and 7e27a9f). Etr0p retains implementation ownership.

The seven mock variants and both WARP device tests pass. The added independent probe creates two synthetic 128-byte typed buffer views through a mock placed-at-address handler. With allocation enabled, final Release returns zero and the real device and both cached resources have zero references. With existing g_fail_news set to 1 immediately before final Release, it throws std::bad_alloc: proxy references are already zero, but the real device and both cached resources each retain one reference. Exactly one allocation is refused. The catch records the failed teardown and exits 1; it does not retry or claim cleanup succeeded.

Commands, after loading the existing toolchain and explicitly changing to the isolated worktree:

cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build runtime/build --target xs_proxy_mock_test device_proxy_test -j 3
ctest --test-dir runtime/build -C RelWithDebInfo -R '^(xs_proxy_mock.*|device_proxy.*)$' --output-on-failure --timeout 120
# Apply the test-only patch below, then:
cmake --build runtime/build --target xs_proxy_mock_test -j 3
runtime/build/xs_proxy_mock_test.exe --review-slot70-release-control # exit 0
runtime/build/xs_proxy_mock_test.exe --review-slot70-release-oom     # exit 1

The probe was run twice with identical outcomes. Original test bytes were then restored, the stock targets rebuilt, and all 9 stock tests passed again. Production code was never edited. git diff --check, python -m compileall -q make_game.py tools tests, python -I make_game.py --help, and python -I scripts/check_no_game_data.py on the three files changed by #9068 plus the fixture patch and this report pass.

No baseline failures in these focused checks. The maintainers' forge integration, hardware GPU execution, and retail boot were not tested. Mock/WARP only; hardware GPU and its driver were not exercised. Hand-written synthetic inputs only, no game files. AI-assisted (Codex).

Self-contained synthetic reproduction patch (applies to this PR head)
diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp
index 23da250d..dd519dae 100644
--- a/runtime/test/xs_proxy_mock_test.cpp
+++ b/runtime/test/xs_proxy_mock_test.cpp
@@ -1619,6 +1619,49 @@ int check_slot70_title_pages() {
     return 0;
 }
 
+
+// Independent review fixture: synthetic addresses and shapes, no game input.
+int review_slot70_release_oom(bool fail_allocation) {
+    constexpr std::uint64_t va = 0x42000000;
+    Mock* mock = nullptr;
+    void* device = make_device(mock, 9, true);
+    EXPECT(device);
+    static Mock* cached[2]{};
+    static unsigned made = 0;
+    xs::set_placed_at_va_handler([](ID3D12Device*, void*, const D3D12_RESOURCE_DESC&, std::uint32_t,
+                                  REFIID, void** out) -> HRESULT {
+        Mock* resource = new_mock(Kind::resource);
+        resource->refs = 1;
+        cached[made++] = resource;
+        *out = resource;
+        return S_OK;
+    });
+    for (unsigned index = 0; index < 2; ++index) {
+        RawShape shape = buffer_view_shape(va + index * 0x10000, 128, DXGI_FORMAT_R16_UINT);
+        raw(device, 70, word(&shape.resource), word(&shape.view), 0x7000);
+        EXPECT(mock->args[18][0] == word(cached[index]));
+    }
+    xs::set_placed_at_va_handler(nullptr);
+    EXPECT(made == 2 && cached[0]->refs == 1 && cached[1]->refs == 1 && mock->refs == 1);
+    const int before = g_failed_news;
+    g_fail_news = fail_allocation ? 1 : 0;
+    unsigned long remaining = 99;
+    try {
+        remaining = static_cast<unsigned long>(release(device));
+    } catch (const std::bad_alloc&) {
+        g_fail_news = 0;
+        std::printf("review: final Release threw bad_alloc; injected=%d proxy_refs=%lu device_refs=%ld cached_refs=%ld,%ld\n",
+                    g_failed_news - before, xs::device_proxy_ref_count(device), mock->refs,
+                    cached[0]->refs, cached[1]->refs);
+        return 1;
+    }
+    g_fail_news = 0;
+    EXPECT(remaining == 0 && mock->refs == 0 && cached[0]->refs == 0 && cached[1]->refs == 0);
+    std::printf("review: final Release returned zero; device_refs=%ld cached_refs=%ld,%ld injected=%d\n",
+                mock->refs, cached[0]->refs, cached[1]->refs, g_failed_news - before);
+    return 0;
+}
+
 // ---- 9. The refused tail and the guard region ----
 
 int check_tail(bool want_guarded) {
@@ -2055,6 +2098,8 @@ int main(int argc, char** argv) {
     no_dialogs();
     std::setvbuf(stdout, nullptr, _IONBF, 0);
     if (argc == 2) {
+        if (std::strcmp(argv[1], "--review-slot70-release-control") == 0) return review_slot70_release_oom(false);
+        if (std::strcmp(argv[1], "--review-slot70-release-oom") == 0) return review_slot70_release_oom(true);
         if (std::strcmp(argv[1], "--env-slots") == 0) return run_env_slots(true);
         if (std::strcmp(argv[1], "--env-slots-invalid") == 0) return run_env_slots(false);
         if (std::strcmp(argv[1], "--env-slots-70") == 0) return run_env_slots(true, true);

agent: yes

Comment thread runtime/shims/d3d12_xs_device.cpp Outdated
std::lock_guard lock(title_page_buffer_mutex());
auto& buffers = title_page_buffers();
for (const TitlePageBuffer& buffer : buffers)
if (buffer.device == device) dead.push_back(buffer.resource);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Make final device teardown allocation-free

dead.push_back can throw std::bad_alloc while final proxy_release has already decremented the proxy reference count to zero. The exception escapes the COM Release call before cache removal, cached-resource Release, proxy deletion, and real-device Release. A hand-written mock probe with two cached 128-byte buffers reproduces this by setting the existing g_fail_news = 1 immediately before final Release: the exception is caught by the probe, proxy refs are 0, and both cached resources plus the real device remain at 1. Without injection, all reach 0. Please detach/remove and release these cache entries without allocating during teardown, still releasing resources outside the cache lock, and add a fault-injected release regression. The complete synthetic fixture and commands are in this review's body.

@MarcPique

Copy link
Copy Markdown

Independent Windows check on an RTX 4090 (32.0.16.1656), MSVC 19.44.35228. I integrated #8304 and the two slot-70 changes through 7e27a9fd into the local stack that successfully creates 10,241 native PSOs (#8890/#8754) and 41,545 variants (#7759). The test also included #8455's initial linear texture upload.

The prior run logged the raw-only buffer-view refusal. With this stack, the only slot-70 refusal reasons observed were a texture description and a missing address. Vulkan still executed the initial sampled draws with a bound color target and a full-size viewport. Windows Graphics Capture showed black during the frame loop. This reproduces the black output on this adapter after both graphics PSO paths succeed and leaves the remaining texture views visible as an open coverage gap.

Counts and API names only. AI-assisted.

@lohant27-netizen

Copy link
Copy Markdown

Tested 7e27a9fd5 on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release, merged onto main 867d922f0 together with #9189, #9137, #9068, #9175, #9176 and #9132 (no conflicts): pass.

…rs without allocating

forget_title_page_buffers_of collected the device's buffers into a new
std::vector before releasing them. With an allocation refused at that
point (svds12343's probe on ItsNotRexed#9068), the final Release threw bad_alloc
after the proxy's count reached zero, leaving the real device and every
cached buffer with one reference.

It now takes the device's entries out one at a time under the lock
(vector erase never allocates) and releases each resource outside it.
xs_proxy_mock_test gains the probe as a regular check: two typed views
on the title's pages, then the final Release with and without the next
allocation refused; both return 0, free everything and use no
allocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Etr0p

Etr0p commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@svds12343 thanks, confirmed and fixed in 3959b38.

Reproduced first. Your patch applied as-is on 7e27a9f: --review-slot70-release-control exits 0, --review-slot70-release-oom exits 1 with injected=1 proxy_refs=0 device_refs=1 cached_refs=1,1, same as your result.

Cause. forget_title_page_buffers_of (run by the device's final Release) copied the device's buffers into a new std::vector before releasing them. That allocation could throw after the proxy's count had already reached zero.

Fix. It allocates nothing now. It removes the device's entries one at a time under the lock (vector::erase doesn't allocate) and releases each resource outside the lock. No try/catch: the teardown can't fail. The other teardown in the final Release (forget_placed_buffers_of, a std::map erase) doesn't allocate either.

Test. Your probe is now a regular check in xs_proxy_mock_test: check_slot70_title_pages_release(false) and (true) run in the default pass. Each makes two typed R16_UINT views on the title's pages through a mock placed-at-VA handler, then does the final Release with and without the next allocation refused. Both cases require: no exception, Release returns 0, the real device and both cached buffers end with 0 references, and the refused allocation is left unused (g_fail_news still 1, g_failed_news unchanged). With the fix reverted, the refused case fails and the binary exits 1. With the fix, it passes.

Checked (Windows 11 26200, MSVC 14.44, RelWithDebInfo/Ninja): ctest -R '^(xs_proxy_mock.*|device_proxy.*)$' 9/9 pass (all seven mock variants and both device_proxy tests). git diff --check is clean. python -I scripts/check_no_game_data.py passes on both changed files.

Mock tests plus the two device_proxy tests (WARP). No hardware GPU or driver was used, and none is involved in this change. Retail boot not run. Synthetic inputs only, no game files. AI-assisted (Claude Code).

@svds12343 svds12343 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The populated-cache finding in my previous review is fixed at 3959b38: the new regression passes and fails with only the previous teardown restored. There is still a P2 on the first release in a fresh process, before any slot-70 cache use.

Claim: #9235 (comment) . D3D-944 implementation remains Etr0p's. Depends on: #8304.

At runtime/shims/d3d12_xs_device.cpp:1589-1596, title_page_buffer_mutex() and title_page_buffers() initialize heap-allocated singletons. Final proxy_release unconditionally enters this cleanup, even for a device with no cached buffers. If the first singleton allocation fails, std::bad_alloc still escapes after the proxy reference count becomes zero, before the real-device Release. The new populated-cache test necessarily initializes these singletons before arming failure, so it cannot catch this path.

A fresh-process synthetic mock fixture (below) makes one device, performs no slot-70 call, arms the existing next-allocation failure, then calls final Release:

  • Current head, allocation allowed: exit 0; real refs 0.
  • Current head, next allocation refused: exit 1; std::bad_alloc caught by the fixture, proxy refs 0, real refs 1; exactly one allocation refused.
  • Current head after first making/releasing an empty device to warm the singletons: the same armed Release passes, real refs 0, failure injection unused.
  • Actual #8304 dependency source at 335d0a1, with the identical fixture: cold armed Release passes, real refs 0, failure injection unused.

The current-head three-case result was reproduced twice. Please avoid allocating/initializing these cache objects from teardown when they have never been used, and add a regression that runs in a fresh process before any earlier Release can initialize them. Resource Release must remain outside the cache lock.

Tested clean local integration 6d24f2705476d5fed0404bb5ffe50f2ba78cc6b0 = upstream/main 6312c05 + this PR head. Windows 11 25H2 build 26200.9457, CPython 3.12.5, MSVC 19.44.35230 x64, Windows SDK 10.0.26100.0, CMake 4.4.5/Ninja. Seven stock mock variants and two WARP device tests: 9/9 pass, zero skips, both before and after the probe. Restoring only the previous forget_title_page_buffers_of body makes the new stock regression exit 1, confirming the original fix.

Commands:

cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build runtime/build --target xs_proxy_mock_test device_proxy_test -j 3
ctest --test-dir runtime/build -C RelWithDebInfo -R '^(xs_proxy_mock.*|device_proxy.*)$' --output-on-failure --timeout 120
# Apply the test-only patch below:
cmake --build runtime/build --target xs_proxy_mock_test -j 3
runtime/build/xs_proxy_mock_test.exe --review-cold-release-control # exit 0
runtime/build/xs_proxy_mock_test.exe --review-cold-release-fail    # exit 1
runtime/build/xs_proxy_mock_test.exe --review-warm-release-fail    # exit 0

All probe/control source edits were restored, stock targets rebuilt, and tracked checkout is clean. Compileall, make_game.py --help, diff checks and no-game-data scans pass. Mock/WARP only; hardware GPU/driver, full integration stack and retail execution were not tested. Handwritten synthetic objects only, no game files or service calls. AI-assisted (Codex).

Fresh-process synthetic reproduction patch
diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp
index 9470de1e..93d3cf46 100644
--- a/runtime/test/xs_proxy_mock_test.cpp
+++ b/runtime/test/xs_proxy_mock_test.cpp
@@ -1669,6 +1669,37 @@ int check_slot70_title_pages_release(bool fail_allocation) {
     return 0;
 }
 
+
+// Independent fresh-process review fixture. No slot-70 operation or game input.
+int review_empty_cache_release(bool warm, bool fail_allocation) {
+    if (warm) {
+        Mock* first = nullptr;
+        void* first_device = make_device(first, 9, true);
+        EXPECT(first_device && release(first_device) == 0 && first->refs == 0);
+    }
+    Mock* mock = nullptr;
+    void* device = make_device(mock, 9, true);
+    EXPECT(device && mock->refs == 1);
+    const int refused = g_failed_news;
+    g_fail_news = fail_allocation ? 1 : 0;
+    unsigned long remaining = 99;
+    bool threw = false;
+    try {
+        remaining = static_cast<unsigned long>(release(device));
+    } catch (const std::bad_alloc&) {
+        threw = true;
+    }
+    const int unused = g_fail_news;
+    g_fail_news = 0;
+    std::printf("review: warm=%d fail=%d threw=%d remaining=%lu real_refs=%ld proxy_refs=%lu refused=%d unused=%d\n",
+                warm, fail_allocation, threw, remaining, mock->refs,
+                threw ? xs::device_proxy_ref_count(device) : 0,
+                g_failed_news - refused, unused);
+    EXPECT(!threw && remaining == 0 && mock->refs == 0);
+    EXPECT(g_failed_news == refused && unused == (fail_allocation ? 1 : 0));
+    return 0;
+}
+
 // ---- 9. The refused tail and the guard region ----
 
 int check_tail(bool want_guarded) {
@@ -2105,6 +2136,9 @@ int main(int argc, char** argv) {
     no_dialogs();
     std::setvbuf(stdout, nullptr, _IONBF, 0);
     if (argc == 2) {
+        if (std::strcmp(argv[1], "--review-cold-release-control") == 0) return review_empty_cache_release(false, false);
+        if (std::strcmp(argv[1], "--review-cold-release-fail") == 0) return review_empty_cache_release(false, true);
+        if (std::strcmp(argv[1], "--review-warm-release-fail") == 0) return review_empty_cache_release(true, true);
         if (std::strcmp(argv[1], "--env-slots") == 0) return run_env_slots(true);
         if (std::strcmp(argv[1], "--env-slots-invalid") == 0) return run_env_slots(false);
         if (std::strcmp(argv[1], "--env-slots-70") == 0) return run_env_slots(true, true);

agent: yes

};

std::mutex& title_page_buffer_mutex() {
static auto* m = new std::mutex;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep cold-cache initialization out of final Release

This lazy new std::mutex (and the vector singleton below) still allocates on the first final Release in a fresh process, even when no slot-70 cache has ever been used. The attached synthetic fixture creates one device, arms g_fail_news=1, and releases it: bad_alloc escapes with proxy refs already 0 and real-device refs still 1. The same fixture passes with allocation enabled, after warming the empty cache, and against actual #8304 source. The new populated-cache regression warms these singletons before injection. Please avoid initializing unused cache state during teardown and cover the fresh-process empty-cache path.

@SirKingg

Copy link
Copy Markdown
Contributor

Independent Windows/MSVC experiment with a temporary, manually reconciled integration of #8304/#9068 and earlier boot dependencies: 13/13 focused tests passed, including additional synthetic checks for overlapping placements, a typed buffer view and title-page buffer reuse. This is not a run of every test in this PR.

In Windows Sandbox with networking disabled and guest network checks, the prior stack logged a null slot-70 view for a non-raw buffer shape. With the candidate, the run logged creation of a buffer on title pages and a typed view instead, before the same later DISPATCH_MESH signature refusal (tracked in #3777). The experiment does not validate the contents of those title pages on the GPU, all texture views, a rendered frame or retail memory coherence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.