Skip to content

Runtime: swapchain back buffers keep names and private data (D3D-451) - #4317

Open
omar-akermi wants to merge 1 commit into
ItsNotRexed:mainfrom
omar-akermi:d3d-451-backbuffer-private-data
Open

omar-akermi wants to merge 1 commit into
ItsNotRexed:mainfrom
omar-akermi:d3d-451-backbuffer-private-data

Conversation

@omar-akermi

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D-451 (#4257 (comment))

Depends on: none. Overlaps textually with #4068 (BackBufferResource::GetDevice and Map errors), which changes the top of the same class: a small rebase either way. Once both land, GetDevice could move onto the shared Child base, which holds the device the same way.

What and why

Swapchain back buffers (BackBufferResource, runtime/shims/dxgi_com.cpp) kept no private data: SetName returned S_OK and stored nothing, and GetPrivateData, SetPrivateData and SetPrivateDataInterface returned E_NOTIMPL. On the host a back buffer is an ordinary ID3D12Object. Tools and titles that name or tag back buffers got errors the host never returns.

  • Layer: BackBufferResource now derives from the shared rt::d3d12::Object base (d3d12_com_object.h). That base already holds the host-measured private-data rules (D3D-24) for every other object. It also takes over reference counting and QueryInterface, with a kTag of its own. Object gets a protected references() so held_by_app() (the ResizeBuffers check) keeps working.
  • Test: d3d12_private_data_test now also runs its whole script on both back buffers of a host DXGI swapchain and of the layer's (a hidden 64×64 window, a flip-discard swapchain with 2 buffers), and compares every HRESULT, size, byte and reference count. It also checks that a name and private data set on buffer 0 are still there when GetBuffer(0) hands it out again, and not on buffer 1. Without presentation or a window it prints that and skips only this part.
  • On main the back-buffer part has 223 mismatches in 276 steps, for example GetPrivateData on a missing key: ours E_NOTIMPL, host DXGI_ERROR_NOT_FOUND. With this change all 276 match.
  • docs/d3d12_vulkan.md §3 (DXGI swapchain) and §4.10 (private data) say so.

Tested

Windows 11 Pro 26200, MSVC 14.44 (VS 2022 Build Tools), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo.

  • Vulkan device and host D3D12/DXGI: AMD Radeon RX 9070 XT, driver 32.0.31044.16.
  • d3d12_private_data_test with and without LEONIDA_VK_VALIDATION=1: exit 0, zero validation messages. Private data: 667 steps compared, 0 mismatches. Back buffers: 276 steps compared, 0 mismatches. In both, SetName(nullptr) is left out because the host faults on it.
  • ctest: 147/147 pass (including dxgi_swapchain).
  • No game files used or needed.

AI-assisted (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

BackBufferResource now uses the shared ID3D12Object base (d3d12_com_object.h)
for reference counting, SetName and private data. Before, SetName stored
nothing and GetPrivateData, SetPrivateData and SetPrivateDataInterface
answered E_NOTIMPL, where the host runtime treats a back buffer like any
other ID3D12Object.

d3d12_private_data_test now also runs its script on both back buffers of a
host DXGI swapchain and of the layer's, and checks that a name and private
data set on a buffer are still there when GetBuffer hands it out again, and
not on the other buffer. On main that is 223 mismatches in 276 steps; with
this change all 276 match on an RX 9070 XT.

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

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Built dxgi_swapchain_test at 06b086bf and ran it on Windows 11, RTX 5070 Ti: PASS (all swapchain cases, 0 validation errors); ctest -R dxgi_swapchain -> 1/1 passed (0.53 s).

The back buffers now keep their SetName/private data like the host objects, and the swapchain test passes. No blocking issue.

@molodayamama

Copy link
Copy Markdown

Independent NVIDIA check of 06b086bff08cd8174cb04087764564ba21a6a6f3 on Windows 10 22H2 (19045.7058), RTX 4060 (driver 32.0.16.1088), MSVC 19.40/Ninja RelWithDebInfo. Vulkan validation was enabled and both tests confirmed validation on.

  • d3d12_private_data: 667 ordinary-object steps and 276 back-buffer steps matched Windows D3D12/DXGI, 0 mismatches. The back-buffer section ran on both buffers. The seven null-name calls excluded by the test remained outside the comparison.
  • dxgi_swapchain: passed creation, buffer retrieval, clear/readback, Present and ResizeBuffers, with 0 validation errors.

Focused CTest result: 2/2 passed. Synthetic fixtures only. AI-assisted (Codex).

@ricardotanaka

Copy link
Copy Markdown

Also tested 06b086bf on AMD Radeon RX 7600 (RDNA3, AMD driver 26.11.2), Windows 11 26200, MSVC 19.44, merged on main 03b09a08: same result as the NVIDIA checks above. d3d12_private_data: 667 + 276 back-buffer steps, 0 mismatches; dxgi_swapchain PASS, 0 validation errors; 2/2, and 3/3 with LEONIDA_VK_VALIDATION=1. AI-assisted (Claude Code).

@Exopus-0x65f7ad0

Copy link
Copy Markdown

Tested this head on Windows 11 (26300), RTX 5060 Ti / 621.14, MSVC 14.51, Vulkan SDK 1.4.363.0, built from an empty folder with -DLEONIDA_LLVM_MC. This is the finding: I posted (back buffers measured on host DXGI), so I checked it against those numbers too.

  • d3d12_private_data_test: 276 back-buffer steps compared with the host, 0 mismatches, OK. That covers what I'd measured (NOT_FOUND/size 0 before SetName, 24 bytes after, MORE_DATA with the needed size, removal, SetPrivateDataInterface(null)).
  • dxgi_swapchain_test, d3d12_present_test (70 frames): PASS with LEONIDA_VK_VALIDATION=1. Full ctest -j4: 145/145.

One side effect worth a look: a new unknown IID log line per back-buffer view. Object::QueryInterface logs every IID it refuses, and the old BackBufferResource refused silently. The layer asks every resource for Resource::kTag ({9b3e5f12-…}, d3d12_vulkan_device.cpp:1444) through Resource::from<Resource>, in CreateRenderTargetView (~5018), CreateDepthStencilView, CreateShaderResourceView, CreateUnorderedAccessView and GetResourceTiling. A back buffer refuses it, so dxgi_swapchain_test now prints [rt] d3d12: QueryInterface: unknown IID {9b3e5f12-7c48-4d0e-a6b1-2f8d4c7e9a35} 3 times; main prints it 0 times (the other two unknown IIDs there are the same as on main). Plenty of engines create the back buffer's RTV every frame, so a title would get one stderr line per frame.

Possible fixes, any of them:

  • keep the log for interfaces but stay quiet for the layer's own private tags (a refused kTag of another class is an expected "not mine", not an unknown interface);
  • or log each unknown IID once (a small set under the lock);
  • or have BackBufferResource answer Resource::kTag with E_NOINTERFACE before the logging branch.

AI-assisted (Claude Code).

@tupacfan04

Copy link
Copy Markdown
Contributor

Approved, with two notes.

Names/private data survive GetBuffer (runtime/shims/dxgi_com.cpp:209-214), and held_by_app() via references() keeps the resize guard (:99,255-256). compileall is clean and the merge is clean.

  • The branch conflicts textually with open dxgi: implement BackBufferResource::GetDevice and default-heap Map/Subresource errors #4068 in runtime/shims/dxgi_com.cpp (confirmed), so it needs a rebase; the body already says so.
  • They do not survive ResizeBuffers: :262,271 re-register and create new BackBufferResources (:455). That matches host DXGI (which also recreates buffers), so parity holds, but runtime/test/d3d12_private_data_test.cpp:313-337 never resizes, so it is unverified.
  • Minor: the test only checks buffer 1's name (:336), while docs/d3d12_vulkan.md:2828 says name and private data are "not on the other buffer".

AI-assisted review, no game files, no GPU.

@FZNull

FZNull commented Nov 23, 2026

Copy link
Copy Markdown

Tested 06b086bf on NVIDIA GeForce RTX 4060 (Windows driver 32.0.16.2124 / 621.24, Vulkan 1.4.357), Windows 11 build 26300: pass.

Clean worktree at 06b086bf on main 03b09a08. MSVC 19.50.35726 + CMake/Ninja, RelWithDebInfo; cmake --build runtime/build --parallel 6 -> rc 0, 785.3 s.

  • runtime/build/d3d12_private_data_test.exe: exit 0 in 2.9 s. Private data on the Vulkan-backed device: 667 steps compared with the host D3D12 device, 0 mismatches (5 SetName(nullptr) calls excluded because the host faults). Swapchain back buffers: 276 steps compared with the host DXGI swapchain, 0 mismatches (2 excluded); the back-buffer part really ran (hidden 64x64 window, flip-discard swapchain with two buffers), it did not skip.
  • LEONIDA_VK_VALIDATION=1 is not runnable on this machine: VK_LAYER_KHRONOS_validation is not installed, exit 1 before device creation. That is an environment limit, not a failure of the change; the non-validation comparison above is the decisive one.
  • ctest --test-dir runtime/build --no-tests=error --output-on-failure: 100% tests passed out of 155, 0 failed (156 registered: 8 environment skips, 1 disabled), 301.7 s, exit 0. d3d12_private_data and dxgi_swapchain both pass.

No game files and no shaders are involved.

AI-assisted.

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.

7 participants