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

Closed
github-bot wants to merge 1 commit from gh-pr/168/head into gh-pr/168/base
Owner

@⁠ShyVortex on GitHub · 2026-11-23 18:31 UTC · original
ShyVortex:d3d12x/texture-gpu-va → main · +8 −2 · 1 files · 1 commits · closed without merging

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

**@⁠ShyVortex** on GitHub · 2026-11-23 18:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/168) `ShyVortex:d3d12x/texture-gpu-va` → `main` · +8 −2 · 1 files · 1 commits · closed without merging ## 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](https://claude.com/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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:27 +00:00
github-bot closed this pull request 2026-11-26 04:13:27 +00:00
Author
Owner

@⁠ryosen0 on GitHub · 2026-11-23 18:40 UTC · original

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.

**@⁠ryosen0** on GitHub · 2026-11-23 18:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/168#issuecomment-7110504167) 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.
Author
Owner

@⁠ShyVortex on GitHub · 2026-11-23 18:44 UTC · original

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.

**@⁠ShyVortex** on GitHub · 2026-11-23 18:44 UTC · [original](https://github.com/xcl-dev/xcl/pull/168#issuecomment-7110584575) 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.
Author
Owner

@⁠Sr-0w on GitHub · 2026-11-23 19:36 UTC · original

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** on GitHub · 2026-11-23 19:36 UTC · [original](https://github.com/xcl-dev/xcl/pull/168#issuecomment-7111842755) 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](https://claude.com/claude-code)
Author
Owner

@⁠Sr-0w on GitHub · 2026-11-23 20:00 UTC · original

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

**@⁠Sr-0w** on GitHub · 2026-11-23 20:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/168#issuecomment-7112425803) 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 `memset`s 512 KB at address 0. Noting the title address on that `Some(hr)` path too fixed it here. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠gw1337x on GitHub · 2026-11-23 20:19 UTC · original

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

**@⁠gw1337x** on GitHub · 2026-11-23 20:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/168#issuecomment-7112911781) **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: ```diff 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](https://claude.com/claude-code)
Author
Owner

@⁠Kalmarv on GitHub · 2026-11-23 20:28 UTC · original

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.

**@⁠Kalmarv** on GitHub · 2026-11-23 20:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/168#issuecomment-7113110836) **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.
Author
Owner

@⁠ShyVortex on GitHub · 2026-11-23 20:52 UTC · original

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** on GitHub · 2026-11-23 20:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/168#issuecomment-7113677826) 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.
Author
Owner

@⁠ivall on GitHub · 2026-11-23 20:57 UTC · original

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!

**@⁠ivall** on GitHub · 2026-11-23 20:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/168#issuecomment-7113793236) 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!
Author
Owner

@⁠ExCorvus on GitHub · 2026-11-24 10:47 UTC · original

Independent confirmation from the Leonida static-recompilation side (Windows 11, RX 9070 XT, driver 32.0.32029.2010): the same 1.0.2.1 title places a 256x256 R32_FLOAT texture through device slot 133 and clears it through the value GetGPUVirtualAddress returns; with a PC-style 0 answer the clear writes 256 KB at address 0. Leonida folded in the title-address answer for slot-133 placed textures (ubiquitarianism/leonida PR #2, merged), with a committed fallback image and no pixel aliasing yet — the same limitation noted here. Confirming the measurement and the fix direction on RDNA4 as well.

AI-assisted (Qwen4 Max Preview, Alibaba Token Plan); verified and posted by ExCorvus.

**@⁠ExCorvus** on GitHub · 2026-11-24 10:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/168#issuecomment-7129249588) Independent confirmation from the Leonida static-recompilation side (Windows 11, RX 9070 XT, driver 32.0.32029.2010): the same 1.0.2.1 title places a 256x256 R32_FLOAT texture through device slot 133 and clears it through the value GetGPUVirtualAddress returns; with a PC-style 0 answer the clear writes 256 KB at address 0. Leonida folded in the title-address answer for slot-133 placed textures (ubiquitarianism/leonida PR #2, merged), with a committed fallback image and no pixel aliasing yet — the same limitation noted here. Confirming the measurement and the fix direction on RDNA4 as well. AI-assisted (Qwen4 Max Preview, Alibaba Token Plan); verified and posted by ExCorvus.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.