Skip to content

DXGI: return INVALID_CALL for an out-of-range GetBuffer index - #2876

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Ryderadzeee:fix/dxgi-getbuffer-invalid-index
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Ryderadzeee:fix/dxgi-getbuffer-invalid-index

Conversation

@Ryderadzeee

Copy link
Copy Markdown
Contributor

Claimed as a new D3D item in the coordination thread. This follows the GetBuffer discrepancy noted in #1128.

Return DXGI_ERROR_INVALID_CALL from IDXGISwapChain::GetBuffer when the buffer index is outside the chain. The path clears the output pointer, matching native DXGI.

On native WARP and the RX 9070 XT, the last valid index returned a resource. The buffer count, count plus one, and UINT_MAX each returned DXGI_ERROR_INVALID_CALL and cleared a non-null sentinel. The new shim regression checks the same boundary using the chain's reported count. It failed on upstream ec8ec4c9 because the first out-of-range index returned E_INVALIDARG.

dxgi_swapchain and d3d12_present passed on Windows 11 Pro build 26300, MSVC 19.51, RX 9070 XT driver 32.0.32029.2010, and Vulkan-Headers 1.4.363. Vulkan validation was off. The foreground-window check skipped, and the presented-image color check passed. Synthetic inputs only.

AI-assisted.

@tupacfan04

Copy link
Copy Markdown
Contributor

Code read of 4f4cc860. Looks right. An out-of-range GetBuffer index now returns DXGI_ERROR_INVALID_CALL, as the host does, with *surface still nulled first and a null surface still E_POINTER.

AI-assisted review (Claude Code).

@Yourrespawn

Copy link
Copy Markdown
Contributor

Independently reproduced the native measurement on a different GPU vendor (standalone probe against the system dxgi/d3d12, Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 4080, driver 617.14): the D3D12 case matches the PR exactly.

Native D3D12 FLIP_DISCARD, BufferCount=3, sentinel pointer passed to GetBuffer:

  • 0, 1, 2 → S_OK, resource returned — including the last valid index, as claimed
  • 3 (count) → DXGI_ERROR_INVALID_CALL (0x887A0001), sentinel cleared
  • 0xFFFFFFFF → DXGI_ERROR_INVALID_CALL, sentinel cleared

So the shim's new rule (INVALID_CALL for index ≥ count, output pointer cleared, matching native) is right, and the old E_INVALIDARG was measurably wrong.

One detour worth documenting for anyone probing later: the same probe through D3D11 flip-discard on this NVIDIA machine returns DXGI_ERROR_INVALID_CALL + cleared pointer for every index except 0 (n=2 and n=3 chains alike), while SEQUENTIAL exposes all indices — that's the D3D11 runtime's flip emulation, not dxgi-level validation, and it does not match the PR's "last valid index returns a resource" premise. The D3D12 path is the one the shim models and it behaves as the PR says.

AI-assisted (ZCode agent): the probes were written and run by a coding agent on this machine.

@zzEmmazz

Copy link
Copy Markdown
Contributor

Tested 4f4cc860, applied alone on main 77444fa0: pass. Windows 11 (26200), MSVC 14.50 (VS 2026), Ninja RelWithDebInfo. Two GPUs: Ryzen 7 9700X iGPU (RDNA2, AMD 32.0.21042.62) and RTX 3070 (NVIDIA 610.74), picked with LEONIDA_VK_DEVICE.

  • Only the test change: dxgi_swapchain_test fails on both GPUs with "GetBuffer(2) returned 0x80070057, expected DXGI_ERROR_INVALID_CALL and null", so the new check catches the old behaviour.
  • The whole PR: exit 0 on both GPUs.

The host side, measured here with a two-buffer flip-model swap chain on the RTX 3070, the Radeon iGPU and WARP, the same on all three: GetBuffer with index 2, 3 and 0xffffffff gives DXGI_ERROR_INVALID_CALL (0x887a0001) and a null pointer; 0 and 1 succeed. That matches the PR.

@FaKL-Code

Copy link
Copy Markdown
Contributor

Tested 4f4cc86 (merged onto main 77444fa) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0: pass

  • Clean merge; RelWithDebInfo build with no warnings that main doesn't have.
  • ctest -j 4 (all but loader): 120/120 pass, including dxgi_swapchain, with the same 8 skips as main.
  • loader run on its own: pass.
  • With LEONIDA_VK_VALIDATION=1, every d3d12_* and dxgi_* test plus command_list and xbox_present (48 tests): no validation errors, the same as main.
  • I checked the host rule on this PC. A local probe (not committed) made a real 3-buffer FLIP_DISCARD D3D12 swap chain and called GetBuffer(i, __uuidof(ID3D12Resource), &out) with out preset to non-null:
    • indices 0 and 2: S_OK with a resource;
    • indices 3, 4 and 0xFFFFFFFF: DXGI_ERROR_INVALID_CALL (0x887a0001) with out set to null.
    • That matches the new test exactly.
  • This PR merges cleanly with dxgi: MakeWindowAssociation refuses unknown flag bits (host-measured) #2822, which edits the same two files.

AI-assisted (Claude).

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 4f4cc86 merged onto main 1628210 on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 130/130.
  • dxgi_swapchain: passes 20 of 20 runs, and passes under LEONIDA_VK_VALIDATION=1 with 0 validation messages.
  • Warnings: none new in the files this PR changes.

AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit cb32d2d into ItsNotRexed:main Nov 22, 2026
2 of 4 checks passed
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