Repository navigation
Conversation
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
|
Correction on the Tested section. Over SSH, |
|
Tested Setup: MSVC 19.44.35230 (VS 2022 Build Tools, CMake 3.31.6 + Ninja through
Host check on Windows 11. A standalone probe (no Leonida code; source below) creates a 64×64, 2-buffer flip-discard swap chain with
That matches the rule in this PR on every case, including present_probe.cpp (cl /EHsc /std:c++20 present_probe.cpp d3d12.lib dxgi.lib user32.lib)// Host DXGI probe: which Present flags does the real dxgi.dll refuse on a flip-discard window swap chain over a D3D12
// queue (unrestricted, non-stereo)? For each flag set: HRESULT, and whether a frame was presented (present count or
// back buffer index changed). Standalone, no Leonida code.
#include <windows.h>
#include <d3d12.h>
#include <dxgi1_6.h>
#include <cstdio>
static LRESULT CALLBACK wndproc(HWND h, UINT m, WPARAM w, LPARAM l) { return DefWindowProcW(h, m, w, l); }
static void pump() {
MSG msg;
while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessageW(&msg); }
}
int main() {
WNDCLASSW wc{};
wc.lpfnWndProc = wndproc;
wc.hInstance = GetModuleHandleW(nullptr);
wc.lpszClassName = L"present_probe";
RegisterClassW(&wc);
HWND hwnd = CreateWindowExW(0, wc.lpszClassName, L"present_probe", WS_OVERLAPPEDWINDOW, 40, 40, 160, 160, nullptr,
nullptr, wc.hInstance, nullptr);
if (!hwnd) { std::printf("CreateWindow failed\n"); return 2; }
ShowWindow(hwnd, SW_SHOWNOACTIVATE);
pump();
ID3D12Device* device = nullptr;
if (FAILED(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device)))) {
std::printf("D3D12CreateDevice failed\n");
return 2;
}
D3D12_COMMAND_QUEUE_DESC qd{};
qd.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
ID3D12CommandQueue* queue = nullptr;
device->CreateCommandQueue(&qd, IID_PPV_ARGS(&queue));
IDXGIFactory4* factory = nullptr;
CreateDXGIFactory2(0, IID_PPV_ARGS(&factory));
IDXGIAdapter1* adapter = nullptr;
DXGI_ADAPTER_DESC1 ad{};
if (SUCCEEDED(factory->EnumAdapterByLuid(device->GetAdapterLuid(), IID_PPV_ARGS(&adapter)))) adapter->GetDesc1(&ad);
DXGI_SWAP_CHAIN_DESC1 sd{};
sd.Width = 64;
sd.Height = 64;
sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.SampleDesc.Count = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = 2;
sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
IDXGISwapChain1* sc1 = nullptr;
HRESULT hr = factory->CreateSwapChainForHwnd(queue, hwnd, &sd, nullptr, nullptr, &sc1);
if (FAILED(hr)) { std::printf("CreateSwapChainForHwnd failed 0x%08lx\n", hr); return 2; }
IDXGISwapChain3* sc = nullptr;
sc1->QueryInterface(IID_PPV_ARGS(&sc));
OSVERSIONINFOW ov{sizeof(ov)};
using RtlGetVersionFn = LONG(WINAPI*)(OSVERSIONINFOW*);
auto rtl = reinterpret_cast<RtlGetVersionFn>(GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion"));
if (rtl) rtl(&ov);
std::printf("host: Windows %lu.%lu.%lu, adapter %ls\n", ov.dwMajorVersion, ov.dwMinorVersion, ov.dwBuildNumber,
ad.Description);
for (int i = 0; i < 3; ++i) { sc->Present(0, 0); pump(); Sleep(20); }
struct Case { UINT flags; const char* name; };
const Case cases[] = {
{0x0, "0 (control)"},
{0x1, "TEST alone"},
{0x10, "STEREO_PREFER_RIGHT"},
{0x20, "STEREO_TEMPORARY_MONO"},
{0x40, "RESTRICT_TO_OUTPUT (unrestricted chain)"},
{0x80, "undefined 0x80"},
{0x400, "undefined 0x400"},
{0x80000000u, "undefined 0x80000000"},
{0x1 | 0x2, "TEST|DO_NOT_SEQUENCE"},
{0x1 | 0x4, "TEST|RESTART"},
{0x1 | 0x100, "TEST|USE_DURATION"},
{0x1 | 0x8, "TEST|DO_NOT_WAIT"},
{0x2, "DO_NOT_SEQUENCE"},
{0x4, "RESTART"},
{0x8, "DO_NOT_WAIT"},
{0x100, "USE_DURATION"},
};
std::printf("%-12s %-42s %-12s %s\n", "flags", "case", "HRESULT", "presented");
for (const Case& c : cases) {
Sleep(30);
pump();
UINT count0 = 0, count1 = 0;
sc->GetLastPresentCount(&count0);
const UINT idx0 = sc->GetCurrentBackBufferIndex();
hr = sc->Present(0, c.flags);
pump();
sc->GetLastPresentCount(&count1);
const UINT idx1 = sc->GetCurrentBackBufferIndex();
const bool presented = count1 != count0 || idx1 != idx0;
const char* label = hr == DXGI_ERROR_INVALID_CALL ? " INVALID_CALL"
: hr == S_OK ? " S_OK"
: hr == DXGI_STATUS_OCCLUDED ? " OCCLUDED"
: hr == DXGI_ERROR_WAS_STILL_DRAWING ? " STILL_DRAWING" : "";
std::printf("0x%08x %-42s 0x%08lx%s %s\n", c.flags, c.name, static_cast<unsigned long>(hr), label,
presented ? "yes" : "no");
}
sc->Release();
sc1->Release();
queue->Release();
device->Release();
DestroyWindow(hwnd);
return 0;
}AI-assisted (Claude Code). |
|
Tested
AI-assisted. |
Claimed in the coordination issue as: new RT item (claim)
What and why
SwapChain::Presentonly checked the sync interval andDXGI_PRESENT_ALLOW_TEARING, so it presented a frame for flags the host refuses, andDXGI_PRESENT_TESTcombined with another flag answered S_OK. Measured on the host dxgi.dll with a flip-discard window swap chain over a D3D12 queue: the two stereo flags, any bit outside the documentedDXGI_PRESENT_*values (0x80, 0x400 and up),DXGI_PRESENT_TESTtogether with any other flag, andDXGI_PRESENT_RESTRICT_TO_OUTPUTon a chain created without a restrict-to output are allDXGI_ERROR_INVALID_CALL, and nothing is presented (present count and back buffer index unchanged).DO_NOT_SEQUENCE,RESTART,DO_NOT_WAIT,USE_DURATIONandRESTRICT_TO_OUTPUTon a restricted chain still present.Presentnow refuses the same set;Present1goes through it too.#4826 moves the body of
Presentinto a helper; whichever lands second rebases, the hunk is seven lines at the top ofPresent.Tested
Windows 10 22H2 (19045), RTX 2060 / NVIDIA 566.14, clang-cl 23.1.6 + lld-link, Windows SDK 10.0.26100, Ninja, on
668f70b28, run from the interactive desktop session (the swap chain test skips without one):dxgi_swapchain_test: pass. The new checks send each refused flag set toPresent(0, flags)and expectDXGI_ERROR_INVALID_CALLwith nothing presented. Withdxgi_com.cppfrommainit fails atPresent(0, 0x10).dxgi_device,dxgi_swapchain_count: pass.d3d12_vulkan_devicefails attiles == 1(line 6564,GetResourceTilingon a reserved texture), code this change does not touch.No game files. AI-assisted (Claude Code).
@ItsNotRexed: an exe/recomp PR, as you asked.
Checklist
docs/design.md, with how it was confirmed. (no translator change)