[PR #1798] [MERGED] d3d12_vulkan: a title texture destroyed inside the registry is removed after the registry lets go (RT-TITLE-TEXTURE-GONE) #1812

Closed
opened 2026-11-26 21:19:03 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1798
Author: @ImLele69
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @QemmHD

Base: main ← Head: rt-title-texture-gone


📝 Commits (2)

  • 5f549cf d3d12_vulkan: a title texture destroyed inside the registry is removed after the registry lets go
  • 152cee2 d3d12_vulkan: a texture destroyed inside the registry leaves gpu_placements at once

📊 Changes

1 file changed (+43 additions, -6 deletions)

View changed files

📝 runtime/shims/d3d12_vulkan_device.cpp (+43 -6)

📄 Description

Claimed in the coordination issue as: RT-TITLE-TEXTURE-GONE — https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162151750

What and why

~Resource calls DeviceState::title_texture_gone, which takes title_texture_mutex. The comment above the registry already says the caller of a removal holds that mutex while the resource is destroyed. But the last reference to a slot-70 texture can be a descriptor that write_placed_texture_view overwrites while it holds the mutex: place_title_view → write_title_srv → CreateShaderResourceView releases the old view's resource, its destructor runs, and the same thread takes the same std::mutex again.

MSVC's std::mutex detects that and throws std::system_error (resource_deadlock_would_occur). Under Wine, msvcp140.dll does not implement std::_Throw_Cpp_error, so the process aborts instead:

wine: Unimplemented function msvcp140.dll.?_Throw_Cpp_error@std@@YAXH@Z called at address ... (thread 0190), starting debugger...

Startup trace exception record, with a linker map of that build: kernelbase < MSVCP140 < … < ~Resource < Device::CreateShaderResourceView < write_title_srv < write_placed_texture_view < proxy_create_placed_view_x < proxy_slot<70>, on a title thread during the story load (16,808 registered images).

Change

title_texture_gone checks t_in_title_textures, which is set exactly while a thread is inside the registry holding title_texture_mutex (InTitleTextures). There, the entry only stops naming the resource (resource = nullptr, no erase, so no iterator of a caller walking title_textures is touched), and (resource, address) goes to titles_gone. drain_titles_gone removes those entries and their GPU placements with the mutex taken normally, right after write_placed_texture_view's registry block and after refresh_title_textures unlocks. place_title_view treats an entry without a resource as absent.

Outside the registry nothing changes.

Tested

  • gta6rt.exe cross-built (clang-cl 20 + xwin) from this branch's commit on main 0d80bc5df.
  • Retail 1.0.2.1 under Wine 11.21 (Fedora 44, RTX 2070 SUPER 8 GB, i9-9900KF, 16 GB RAM), counts only: the abort above, once, without the change; with it, six story-load boots on two bases (c7e82e26e with local changes, and 0d80bc5df exactly as in this branch) ran to the world start (36,000-40,480 registered images) without it. They end on the known world-start device loss, which is unrelated. The race needs a slot-70 view overwritten while it holds the last reference, so one run without the abort proves little on its own; six do not prove it either, but the abort did not come back.
  • I have not reproduced it on native Windows, where the same recursion would surface as a std::system_error out of CreateShaderResourceView rather than an abort.

AI-assisted: yes (Claude Code).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1798 **Author:** [@ImLele69](https://github.com/ImLele69) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `rt-title-texture-gone` --- ### 📝 Commits (2) - [`5f549cf`](https://github.com/ubiquitarianism/leonida/commit/5f549cf5f3d6437e868b530fcdbae0a8406b47c8) d3d12_vulkan: a title texture destroyed inside the registry is removed after the registry lets go - [`152cee2`](https://github.com/ubiquitarianism/leonida/commit/152cee255030f953e63a10dcdf12b5f0d8ca0e69) d3d12_vulkan: a texture destroyed inside the registry leaves gpu_placements at once ### 📊 Changes **1 file changed** (+43 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+43 -6) </details> ### 📄 Description Claimed in the coordination issue as: RT-TITLE-TEXTURE-GONE — https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162151750 ### What and why `~Resource` calls `DeviceState::title_texture_gone`, which takes `title_texture_mutex`. The comment above the registry already says the caller of a removal holds that mutex while the resource is destroyed. But the last reference to a slot-70 texture can be a descriptor that `write_placed_texture_view` overwrites while it holds the mutex: `place_title_view` → `write_title_srv` → `CreateShaderResourceView` releases the old view's resource, its destructor runs, and the same thread takes the same `std::mutex` again. MSVC's `std::mutex` detects that and throws `std::system_error` (`resource_deadlock_would_occur`). Under Wine, `msvcp140.dll` does not implement `std::_Throw_Cpp_error`, so the process aborts instead: ``` wine: Unimplemented function msvcp140.dll.?_Throw_Cpp_error@std@@YAXH@Z called at address ... (thread 0190), starting debugger... ``` Startup trace exception record, with a linker map of that build: `kernelbase` < `MSVCP140` < … < `~Resource` < `Device::CreateShaderResourceView` < `write_title_srv` < `write_placed_texture_view` < `proxy_create_placed_view_x` < `proxy_slot<70>`, on a title thread during the story load (16,808 registered images). ### Change `title_texture_gone` checks `t_in_title_textures`, which is set exactly while a thread is inside the registry holding `title_texture_mutex` (`InTitleTextures`). There, the entry only stops naming the resource (`resource = nullptr`, no erase, so no iterator of a caller walking `title_textures` is touched), and `(resource, address)` goes to `titles_gone`. `drain_titles_gone` removes those entries and their GPU placements with the mutex taken normally, right after `write_placed_texture_view`'s registry block and after `refresh_title_textures` unlocks. `place_title_view` treats an entry without a resource as absent. Outside the registry nothing changes. ### Tested - `gta6rt.exe` cross-built (clang-cl 20 + xwin) from this branch's commit on `main` `0d80bc5df`. - Retail 1.0.2.1 under Wine 11.21 (Fedora 44, RTX 2070 SUPER 8 GB, i9-9900KF, 16 GB RAM), counts only: the abort above, once, without the change; with it, six story-load boots on two bases (`c7e82e26e` with local changes, and `0d80bc5df` exactly as in this branch) ran to the world start (36,000-40,480 registered images) without it. They end on the known world-start device loss, which is unrelated. The race needs a slot-70 view overwritten while it holds the last reference, so one run without the abort proves little on its own; six do not prove it either, but the abort did not come back. - I have not reproduced it on native Windows, where the same recursion would surface as a `std::system_error` out of `CreateShaderResourceView` rather than an abort. AI-assisted: yes (Claude Code). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:19:03 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1812
No description provided.