Files
d4r/tools/d4r_win32_wait.h
T
woutermans 87365077e0 Add experimental packed and in-place DLSS output
- Tag redirected surfaces as R10G10B10A2 ('R3') as well as RGBA16F ('R2'), and
  let the native output kernel store the game's R10G10B10A2 texels itself.
- Import linear, exportable game textures (vkd3d-proton patch 0003) into HIP
  so the output kernel writes the game's output texture with no game-side copy.
- Add ID3D12DXVKInteropDeviceD4R3 with GetVulkanLinearImageInfo.
- Gate both paths behind D4R_SHIM_OUTPUT_PACKED and D4R_SHIM_INPLACE, and use
  them only for split frames of preset M whose output kernel honours the redirect.
- Convert on the host when a recorded packed frame finds the wrong kernel.
- Give the harness an R10G10B10A2 output, and add D4R_SHIM_SPIN_POLL so
  frame timing is not quantised to the poll sleep.
- Document the measured removal of the output copies in performance.md.
2026-10-07 11:00:26 +02:00

27 lines
1.2 KiB
C++

#pragma once
#include <windows.h>
#include <cstdint>
// MinGW's Win32 std::sleep_for can truncate submillisecond durations to zero.
// NtDelayExecution retains 100 ns precision and actually sleeps under Wine.
inline void d4r_sleep_us(unsigned int microseconds)
{
using Delay = LONG(WINAPI*)(BOOLEAN, LARGE_INTEGER*);
static const auto delay = reinterpret_cast<Delay>(reinterpret_cast<void*>(
GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "NtDelayExecution")));
// D4R_SHIM_SPIN_POLL=1 (measurement only): every poll yields instead of sleeping, so frame timings are
// not quantised to the ~250 us a 200 us sleep takes. Costs a CPU core per waiting thread.
static const bool spin = GetEnvironmentVariableA("D4R_SHIM_SPIN_POLL", nullptr, 0) > 1;
if (microseconds == 0 || spin)
{
SwitchToThread();
return;
}
LARGE_INTEGER interval;
interval.QuadPart = -static_cast<LONGLONG>(microseconds) * 10;
if (delay != nullptr && delay(FALSE, &interval) >= 0)
return;
// A rounded-up millisecond wait still releases the CPU if ntdll is absent.
Sleep(static_cast<DWORD>((static_cast<uint64_t>(microseconds) + 999) / 1000));
}