Skip to content

D3D12.X: GetGPUVirtualAddress of a placed texture is its title address - #168

Closed
ShyVortex wants to merge 1 commit into
ivall:mainfrom
ShyVortex:d3d12x/texture-gpu-va
Closed

ShyVortex wants to merge 1 commit into
ivall:mainfrom
ShyVortex:d3d12x/texture-gpu-va

Conversation

@ShyVortex

Copy link
Copy Markdown

Summary

On the console every resource has a GPU address, textures included. On the PC, GetGPUVirtualAddress of a texture is 0.

A retail game turns a 256×256 R32_FLOAT texture's address into the CPU pointer it clears it through. The chain, from its code:

  1. 0x2913410 creates the texture.
  2. [tex + 0x10] = 0x4fd2940(tex), which is GetGPUVirtualAddress (vtable +0x58) mapped through the title's unified-memory window.
  3. memset([tex + 0x10], 0, w * h * 4).

With the PC's 0 it wrote 256 KB at address 0 (vcruntime140!memset, access violation).

The texture is one the title placed at its own address (CreatePlacedResourceX → video-memory arena), so XCL already knows that address: title_address(), which Map uses. res_gpu_va_x only consulted console_buffer(). Now, when the PC answers 0, it returns the resource's title address if there is one. Buffers, and anything that has a PC address, are unchanged.

Testing

  • cargo test --release --workspace: all pass.
  • On an RTX 3080 Ti Laptop GPU (with other local changes needed to get that far on NVIDIA / Intel): the game crashed at the memset on two runs without this change, and ran past it with it.

Draft until one more run confirms nothing later trips on the addresses this now returns.

🤖 Generated with Claude Code

On the console a texture has a GPU address like any resource. A retail game
turns a 256x256 R32_FLOAT texture's address into the CPU pointer it clears
it through; on the PC GetGPUVirtualAddress of a texture is 0, so it wrote
256 KB at address 0.

For a resource the title placed at its own address, the PC's answer 0
becomes that address (title_address); buffers and everything with a PC
address are unchanged.

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

ryosen0 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

RTX 3060 Ti (wave32), Windows 11 host, XCL_NETWORK=0, this branch (070a737): 600 presents, ~26 fps, then the title's own int3 at +0x344196 (33 s, warm shader cache) — the same assert site as main @ 956a476 without this change. No new failure before that point attributable to the returned title addresses. The memset null-write this PR fixes does not occur on this machine on either build, so this is a no-regression data point rather than a confirmation of the fix itself.

@ShyVortex

Copy link
Copy Markdown
Author

Thanks for testing! +0x344196 is the assertion after GetResourceAllocationInfo for a 2560×1440 depth buffer in the console's D16_UNORM_S8_UINT (118): XG has no model for 118, and the PC driver answers UINT64_MAX for it. On main that stops the game before it reaches this PR's memset, which comes later in loading. #150 maps 118 for the driver; on my side the memset only appeared once 118 was handled (including an XG layout for it, suggested on #150). So this PR is confirmed on my machine with those in place; on main alone it can't be reached yet.

gbuyssens added a commit to gbuyssens/xcl that referenced this pull request Nov 23, 2026
gbuyssens added a commit to gbuyssens/xcl that referenced this pull request Nov 23, 2026
theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 23, 2026
…-target and texture-address fixes

Open upstream pull requests applied as they are (their authors' work):
- ivall#151 (gbuyssens): clzero / clwb / rdpru / monitorx / mwaitx / rdpid emulated
  on CPUs that lack them (HANDOFF.md hunk left out, it did not apply).
- ivall#163, ivall#170 (Sr-0w): Xbox D16S8 depth formats, depth + UAV buffers, console
  mesh pipeline streams, null stand-in shaders.
- ivall#168 (ShyVortex): GetGPUVirtualAddress of a placed texture.

Local changes:
- xg: XGTextureAddressComputer ivall#10 as GetResourceTiling, from the layout model
  (not checked against the console's library).
- d3d12x: a UAV of a texture made without ALLOW_UNORDERED_ACCESS is a null UAV
  (the real call removed the device); a committed texture gets memory when the
  title asks for its address; clear values and view descriptions get pc_format;
  formats 86 / 115 -> R8G8B8A8, 116 / 117 -> R16G16B16A16_FLOAT.
- Debug layer log: 8 messages per id instead of 200 in all.
- The earlier "AS slot ignored" workaround stays but is no longer reached (ivall#170).
- CHANGES.txt, README status and installer version for build 3.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Sr-0w

Sr-0w commented Nov 23, 2026

Copy link
Copy Markdown

Tested on AMD (RX, GTA VI retail). One gap: in create_placed_resource_x, a texture that title_textures::register accepts returns before real::note_title_address, so it never gets a title address and GetGPUVirtualAddress still answers 0. That is where the 256x256 R32_FLOAT texture came from in my runs: the memset crash happened at 35–50 s. Noting the title address in the Ok(()) arm too fixed it. The game then ran past it to ~63 s (a device removal there, which I am still investigating).

🤖 Generated with Claude Code

@Sr-0w

Sr-0w commented Nov 23, 2026

Copy link
Copy Markdown

Second spot, same crash: textures that vram::place takes (render target / UAV textures, e.g. GTA VI's 256x256 R32G32_FLOAT RT+UAV) return from create_placed_resource_x before note_title_address as well, so GetGPUVirtualAddress still gives 0 and the title memsets 512 KB at address 0. Noting the title address on that Some(hr) path too fixed it here.

🤖 Generated with Claude Code

@gw1337x

gw1337x commented Nov 23, 2026

Copy link
Copy Markdown

Setup: AMD Radeon RX 7800 XT (RDNA3, 16 GB), driver 32.0.32015.7029, 32 GB RAM, Windows 11 Pro 26200, GTA VI retail, XCL_NETWORK=0, release build.
Test branch: main 956a476 + #170 (incl. #163 @ 634c423) + #162 @ 641f551 + #168 @ 070a737 + xg.rs of #169 + #176 + #164.

Confirming @Sr-0w's gap (the title_textures::register Ok(()) arm). With that fixed, the game cleared the 256 KB R32_FLOAT texture and then crashed the same way on the next one: memset of 0x80000 bytes at address 0 (+0x5ebea38).

That's the texture the same init function (+0x1d957b0) creates right after, through the same helper (+0x2913410): DXGI format 0x10 (R32G32_FLOAT), 256x256, object at 0x1476b42f0. It is GPU-owned (UAV flag), so create_placed_resource_x returns from the vram::place arm before note_title_address. Noting the title address there too fixed it, and the game got past both:

         if let Some(hr) = super::vram::place(this, va as usize, &pc, state, clear, riid, ppv) {
+            if hr >= 0 && !(*ppv).is_null() {
+                real::note_title_address(*ppv as usize, va as usize);
+            }
             return hr;
         }

Caveat: for arena textures the title's CPU writes then land in title memory, not in the PC texture. That's harmless for this clear-to-zero, but content written on the CPU wouldn't reach the GPU.

🤖 Generated with Claude Code

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Confirmed the slot-11 fallback on an actual placed texture with a registered title address. I tested PR head 070a7378543b8efac3496e6a344393efadbe30b7 directly against its parent 956a476bf738a098f39df4f4c8acef682e43030f. Windows x64 MSVC, Rust 1.99.0, RTX 5070 Ti, NVIDIA 610.74, D3D12 debug layer enabled for the native probe.

Synthetic input main PR head
Placed 16×16 R32_FLOAT texture with a registered title address 0 (fail) Exact registered address (pass)
Slot-11 stub returning 0, registered address 0x123450000 0 (fail) 0x123450000 (pass)
Same stub with no registered address 0 0
Nonzero native VA and a different registered address Native VA Native VA
Existing hle::d3d12x:: tests 54 pass 54 pass

The native check created a real D3D12 heap and placed texture, adopted the resource, called note_title_address with a live CPU allocation, then invoked res_gpu_va_x directly. On both builds the debug layer recorded message 745 for the native texture VA query. Only the PR head returned the CPU address afterward.

The PR adds no test of its own. This checks address selection once registration succeeds. The two creation paths already discussed above, CPU-to-GPU write visibility, retail execution and merge-onto-main were outside this run. AI-assisted review.

puffnfresh added a commit to puffnfresh/rebox that referenced this pull request Nov 23, 2026
After xcl (ivall/xcl#168): a title clears a texture through the CPU pointer
its address is.

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

Copy link
Copy Markdown
Author

Superseded by 38b05b7 on main: res_gpu_va_x there falls back to the title address, and create_placed_resource_x notes it in the vram::place and title_textures::register arms too (the two paths Sr-0w and gw1337x found, thanks to both). Committed textures also get an address on request. Closing.

Thanks to everyone who tested this: ryosen0, Sr-0w, gw1337x and Kalmarv.

@ShyVortex ShyVortex closed this Nov 23, 2026
@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Closing: on main a texture's GetGPUVirtualAddress gives its title address when the PC answers 0, and the address is noted on both creation paths named in the review (vram::place and title_textures::register). A committed texture with no title address gets lazily committed memory at one (from #195). Thanks!

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.

6 participants