Skip to content

Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.

C++

phase-0 work: P0.7 full runtime probe, DLL load + 5/5 exports + 3s window loop + JSON pass

Veyra Goal Agent639fd48d1df8
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5846f87d..42f7cb00 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -43,6 +43,9 @@ add_library(veyra_gfx STATIC
veyra_apply_warnings(veyra_gfx)
target_compile_features(veyra_gfx PUBLIC cxx_std_20)
target_link_libraries(veyra_gfx PUBLIC veyra_base d3d12 dxgi dxguid)
+if(VEYRA_ENABLE_D3D12_DEBUG)
+ target_compile_definitions(veyra_gfx PUBLIC VEYRA_D3D12_DEBUG=1)
+endif()
add_executable(veyra_runtime_probe
tools/runtime_probe/main.cpp
diff --git a/loop/BACKLOG.md b/loop/BACKLOG.md
index a0dd286c..d4d31ed6 100644
--- a/loop/BACKLOG.md
+++ b/loop/BACKLOG.md
@@ -10,7 +10,7 @@
- [x] P0.4 建立最小 CMake/C++20 Win32 x64 工程与 Debug/Release presets,不引入 FFmpeg/UI。(2026-09-02:Ninja presets 双配置构建 exit 0,stub 运行 exit 0,build.ps1 解析 vswhere/vcvars,presets 无机器路径。)
- [x] P0.5 实现结构化 logger、HRESULT/NGX result 字符串、文件 size/hash/signature 检查。(2026-09-02:--self-test 实测 BCrypt SHA256、WinVerifyTrust、CryptQueryObject 签名者、版本提取;staged DLL 身份与固定契约全匹配;双 preset 构建 exit 0。)
- [x] P0.6 实现 D3D12DeviceContext:RTX adapter、device、direct queue、debug layer、4-slot command allocator/list/fence/event ring。(2026-09-02:--device-info 实测 RTX 5070/0x10DE/FL 12_2/4-slot ring + timestamp query 全通过;debug layer 缺失记 INBOX。)
-- [ ] P0.7 实现 veyra_runtime_probe:受限绝对路径加载本地复制的 nvngx_dlssnr.dll,验证 required exports;不得加载 addon。
+- [x] P0.7 实现 veyra_runtime_probe:受限绝对路径加载本地复制的 nvngx_dlssnr.dll,验证 required exports;不得加载 addon。(2026-09-02:LoadLibraryExW 受限 flags 成功,exports 5/5 实测,3s 冒烟 PASS;addon 从未被加载。)
- [ ] P0.8 Debug/Release 构建并实际运行 probe;D3D12 窗口循环 5 分钟无 device removed;记录命令、exit code、GPU/driver、hash/signature/exports、日志路径。
- [ ] P0.9 当前 gate 通过、只读 Reviewer 通过、修完 P0/P1、写 checkpoint。
diff --git a/loop/JOURNAL.md b/loop/JOURNAL.md
index c2a05d17..1a532289 100644
--- a/loop/JOURNAL.md
+++ b/loop/JOURNAL.md
@@ -197,6 +197,33 @@ Result:
---
+## Cycle 007 — P0.7 完整 runtime probe
+
+### Before
+
+- Phase: 0
+- 唯一任务: 实现 veyra_runtime_probe 完整模式:--runtime-dir 绝对路径校验、staged DLL 身份核验、LoadLibraryExW(LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR|SYSTEM32) 加载、5 个 required exports 逐项 GetProcAddress、System32 nvofapi64 版本探测、固定尺寸 Win32 窗口 + flip-model swapchain + 4-slot ring 每帧 clear/present 循环、结构化 log 文件与 JSON summary 输出(含 runId/exeSha256 防陈旧产物)。
+- 可证伪假设: 若 DLL 加载失败、任一 export 缺失、窗口循环 device removed、或 JSON 字段与 gate 契约不符,probe 将非零退出且不写 JSON。
+- 预计修改文件: tools/runtime_probe/main.cpp(完整重写)、CMakeLists.txt(VEYRA_ENABLE_D3D12_DEBUG→编译宏)。
+- 快速检查命令: `scripts/build.ps1 -Preset x64-debug` → 0;`veyra_runtime_probe.exe --runtime-dir <abs> --window-seconds 3 --run-id test --log-file logs/tmp/probe.log --json-file logs/tmp/probe.json` → exit 0 且 JSON 字段齐全。
+- 预期新增证据: 短窗口真实运行:exports 5/5、窗口 N 秒 M 帧、deviceRemoved=false、JSON 完整。
+
+### After
+
+- 实际修改: tools/runtime_probe/main.cpp 完整实现(约 700 行);CMakeLists 把 VEYRA_ENABLE_D3D12_DEBUG 管道为 VEYRA_D3D12_DEBUG 编译宏。
+- 实际命令与 exit code:
+ - `scripts/build.ps1 -Preset x64-debug` → 修复 2 轮(GetCurrentBackBufferIndex 需 IDXGISwapChain3 + CreateSwapChainForHwnd 需先拿 swapchain1 再 QI)后 exit 0;x64-release exit 0。
+ - `veyra_runtime_probe.exe --runtime-dir <abs> --window-seconds 3 --run-id smoke-test-001 --log-file logs/tmp/probe-smoke.log --json-file logs/tmp/probe-smoke.json` → exit 0(PASS)。
+ - JSON 由 PowerShell ConvertFrom-Json 解析验证(JSON-PARSE-OK)。
+- 新证据/日志路径: logs/tmp/probe-smoke.{log,json}(ignored);关键实测值——LoadLibraryExW(LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR|SYSTEM32) 成功;exports 5/5(含真实地址 0x7FF9…);nvofapi64 present=true version=32.0.16.1656(System32);RTX 5070/0x10DE/FL 12_2/driver 32.0.16.1656;窗口循环 3 秒 302 帧 deviceRemoved=false;JSON 含 runId+exeSha256 防陈旧契约。
+- 失败 fingerprint: 无遗留。
+- 本 fingerprint 第几次不同尝试: 不适用。
+- 是否有进展,依据: 是——Phase 0 完整 probe 链(身份→受限加载→exports→nvofapi→device→窗口/swapchain/4-slot 循环→清理→JSON)端到端真实运行成功。
+- STATE/BACKLOG 更新: cycle.completed=7、currentTask 指向 P0.8;BACKLOG P0.7 → DONE。
+- 下一唯一动作: P0.8 用 scripts/loop-gate.ps1 -Gate phase0 实跑(含 Debug 3s + Release 300s 窗口),登记 EVIDENCE。
+
+---
+
复制下面模板开始每个新 cycle。必须先填 Before,再改代码;完成后填 After。
## Cycle NNN — 简短任务名
diff --git a/loop/STATE.json b/loop/STATE.json
index b00679ec..53b0e148 100644
--- a/loop/STATE.json
+++ b/loop/STATE.json
@@ -76,14 +76,14 @@
}
],
"cycle": {
- "completed": 6,
+ "completed": 7,
"maximum": 80,
"sameFailureAttempts": 0,
"maximumSameFailureAttempts": 3,
"noProgressCycles": 0,
"maximumNoProgressCycles": 5
},
- "currentTask": "P0.7: implement the full veyra_runtime_probe (restricted LoadLibraryExW of the staged DLL, five required exports, System32 nvofapi64 probe, Win32 window + flip-model swapchain loop, structured log + JSON summary output).",
+ "currentTask": "P0.8: run the phase0 gate for real (Debug 3s smoke + Release 300s window loop) and register the evidence.",
"lastGate": {
"name": "phase0",
"status": "failed",
@@ -96,6 +96,6 @@
"lastGoodCommit": null,
"openP0P1Findings": [],
"blockers": [],
- "nextAction": "Implement P0.7 full probe, then P0.8 real gate runs (Debug 3s + Release 300s window).",
- "updatedAt": "2026-09-02T21:50:00+08:00"
+ "nextAction": "Run phase0 gate via loop-gate.ps1 (Release 300s window), register EVIDENCE, then P0.9 reviewer.",
+ "updatedAt": "2026-09-02T22:00:00+08:00"
}
diff --git a/tools/runtime_probe/main.cpp b/tools/runtime_probe/main.cpp
index 3238fca6..edd88979 100644
--- a/tools/runtime_probe/main.cpp
+++ b/tools/runtime_probe/main.cpp
@@ -1,9 +1,21 @@
-// veyra_runtime_probe - Phase 0 runtime/D3D12 probe.
-// Modes (added phase by phase):
-// --self-test [--runtime-dir <abs>] verify veyra_base file identity + strings
-// full probe mode arrives with P0.6/P0.7 (device context + runtime loading)
+// veyra_runtime_probe - Phase 0 runtime/D3D12 probe (Playbook section 16).
+//
+// Modes:
+// --self-test [--runtime-dir <abs>] verify veyra_base primitives
+// --device-info [--debug-layer] adapter/device/slot-ring report
+// --runtime-dir <abs> [--window-seconds N] [--run-id id]
+// [--log-file <abs>] [--json-file <abs>]
+// full probe: staged DLL identity + restricted load + exports +
+// System32 nvofapi64 probe + fixed-size window with flip-model swapchain
+// loop on the 4-slot command ring. Writes a JSON summary consumed by
+// scripts/gates/phase0.ps1; the JSON embeds runId and the probe exe's own
+// SHA-256 so stale artifacts cannot pass the gate.
#include <windows.h>
+#include <d3d12.h>
+#include <dxgi1_6.h>
+#include <chrono>
+#include <cstdint>
#include <format>
#include <string>
#include <vector>
@@ -12,12 +24,61 @@
#include "veyra/Log.h"
#include "veyra/NgxResult.h"
#include "veyra/Result.h"
+#include "veyra/gfx/CommandSlotRing.h"
#include "veyra/gfx/D3D12DeviceContext.h"
namespace {
constexpr uint64_t kExpectedDllSize = 165840496ull;
const char* kExpectedDllSha256 = "E16BCF15E16E13F527491CDF7845B2FE6521A738D8F7C9C721866A8496E1FC8E";
+const wchar_t* kExpectedDllFileVersion = L"310.8.0.0";
+
+const char* kRequiredExports[] = {
+ "NVSDK_NGX_D3D12_Init_Ext",
+ "NVSDK_NGX_D3D12_CreateFeature",
+ "NVSDK_NGX_D3D12_EvaluateFeature",
+ "NVSDK_NGX_D3D12_ReleaseFeature",
+ "NVSDK_NGX_D3D12_Shutdown1",
+};
+constexpr size_t kRequiredExportCount = 5;
+
+std::string narrow(const std::wstring& text)
+{
+ if (text.empty()) {
+ return {};
+ }
+ const int length = WideCharToMultiByte(CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), nullptr, 0, nullptr, nullptr);
+ if (length <= 0) {
+ return {};
+ }
+ std::string converted(static_cast<size_t>(length), '\0');
+ WideCharToMultiByte(CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), converted.data(), length, nullptr, nullptr);
+ return converted;
+}
+
+std::string jsonEscape(const std::string& text)
+{
+ std::string escaped;
+ escaped.reserve(text.size() + 8);
+ for (const char c : text) {
+ switch (c) {
+ case '"': escaped += "\\\""; break;
+ case '\\': escaped += "\\\\"; break;
+ case '\n': escaped += "\\n"; break;
+ case '\r': escaped += "\\r"; break;
+ case '\t': escaped += "\\t"; break;
+ default:
+ if (static_cast<unsigned char>(c) < 0x20) {
+ escaped += std::format("\\u{:04x}", static_cast<unsigned char>(c));
+ }
+ else {
+ escaped.push_back(c);
+ }
+ break;
+ }
+ }
+ return escaped;
+}
std::wstring ownExePath()
{
@@ -29,21 +90,563 @@ std::wstring ownExePath()
return std::wstring(buffer, length);
}
-// Narrow copy for logging; only used for non-critical display strings.
-std::string narrow(const std::wstring& text)
+std::string osBuildString()
{
- if (text.empty()) {
+ const HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");
+ if (ntdll == nullptr) {
return {};
}
- const int length = WideCharToMultiByte(CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), nullptr, 0, nullptr, nullptr);
- if (length <= 0) {
+ using RtlGetVersionFn = LONG(WINAPI*)(PRTL_OSVERSIONINFOW);
+ const auto rtlGetVersion = reinterpret_cast<RtlGetVersionFn>(reinterpret_cast<void*>(GetProcAddress(ntdll, "RtlGetVersion")));
+ if (rtlGetVersion == nullptr) {
return {};
}
- std::string converted(static_cast<size_t>(length), '\0');
- WideCharToMultiByte(CP_UTF8, 0, text.c_str(), static_cast<int>(text.size()), converted.data(), length, nullptr, nullptr);
- return converted;
+ RTL_OSVERSIONINFOW info{};
+ info.dwOSVersionInfoSize = sizeof(info);
+ if (rtlGetVersion(&info) != 0) {
+ return {};
+ }
+ return std::format("{}.{}.{}", info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber);
+}
+
+std::wstring fileVersionOf(const std::wstring& path, bool& present)
+{
+ present = false;
+ const DWORD attributes = GetFileAttributesW(path.c_str());
+ if (attributes == INVALID_FILE_ATTRIBUTES || (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
+ return {};
+ }
+ present = true;
+ DWORD handle = 0;
+ const DWORD size = GetFileVersionInfoSizeW(path.c_str(), &handle);
+ if (size == 0) {
+ return {};
+ }
+ std::vector<unsigned char> buffer(size);
+ if (!GetFileVersionInfoW(path.c_str(), 0, size, buffer.data())) {
+ return {};
+ }
+ VS_FIXEDFILEINFO* fixedInfo = nullptr;
+ UINT length = 0;
+ if (VerQueryValueW(buffer.data(), L"\\", reinterpret_cast<void**>(&fixedInfo), &length) && length >= sizeof(VS_FIXEDFILEINFO)) {
+ return std::format(L"{}.{}.{}.{}",
+ HIWORD(fixedInfo->dwFileVersionMS), LOWORD(fixedInfo->dwFileVersionMS),
+ HIWORD(fixedInfo->dwFileVersionLS), LOWORD(fixedInfo->dwFileVersionLS));
+ }
+ return {};
+}
+
+std::wstring nvofapi64Path()
+{
+ wchar_t systemDir[MAX_PATH]{};
+ const UINT length = GetSystemDirectoryW(systemDir, MAX_PATH);
+ if (length == 0 || length >= MAX_PATH) {
+ return {};
+ }
+ return std::wstring(systemDir, length) + L"\\nvofapi64.dll";
+}
+
+bool writeTextFile(const std::wstring& path, const std::string& content)
+{
+ HANDLE file = CreateFileW(path.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (file == INVALID_HANDLE_VALUE) {
+ return false;
+ }
+ DWORD written = 0;
+ const BOOL ok = WriteFile(file, content.data(), static_cast<DWORD>(content.size()), &written, nullptr);
+ CloseHandle(file);
+ return ok && written == content.size();
+}
+
+struct ProbeArgs {
+ std::wstring runtimeDir;
+ uint32_t windowSeconds = 3;
+ std::wstring runId;
+ std::wstring logFile;
+ std::wstring jsonFile;
+};
+
+struct ProbeSummary {
+ std::string runId;
+ std::string exeSha256;
+ std::string osBuild;
+ // adapter
+ std::string adapterName;
+ std::string adapterVendorId;
+ std::string adapterLuid;
+ uint64_t adapterDedicatedVideoMemoryMiB = 0;
+ bool adapterIsNvidia = false;
+ std::string driverVersion;
+ std::string featureLevel;
+ uint32_t commandSlots = 0;
+ // runtime
+ std::string runtimePath;
+ uint64_t runtimeSizeBytes = 0;
+ std::string runtimeSha256;
+ std::string runtimeFileVersion;
+ std::string runtimeSignature;
+ std::string runtimeSigner;
+ bool exports[kRequiredExportCount] = {};
+ // nvofapi
+ std::string nvofapiPath;
+ std::string nvofapiFileVersion;
+ bool nvofapiPresent = false;
+ bool experimentalDlssnr = false;
+ // window loop
+ uint32_t windowDurationSeconds = 0;
+ uint64_t windowFramesPresented = 0;
+ bool windowDeviceRemoved = false;
+ uint32_t windowDeviceRemovedReason = 0;
+};
+
+std::string buildJson(const ProbeSummary& s)
+{
+ std::string json;
+ json += "{\n";
+ json += std::format(" \"probe\": \"veyra_runtime_probe\",\n");
+ json += std::format(" \"runId\": \"{}\",\n", jsonEscape(s.runId));
+ json += std::format(" \"exeSha256\": \"{}\",\n", jsonEscape(s.exeSha256));
+ json += std::format(" \"osBuild\": \"{}\",\n", jsonEscape(s.osBuild));
+ json += " \"adapter\": {\n";
+ json += std::format(" \"name\": \"{}\",\n", jsonEscape(s.adapterName));
+ json += std::format(" \"vendorId\": \"{}\",\n", jsonEscape(s.adapterVendorId));
+ json += std::format(" \"luid\": \"{}\",\n", jsonEscape(s.adapterLuid));
+ json += std::format(" \"dedicatedVideoMemoryMiB\": {},\n", s.adapterDedicatedVideoMemoryMiB);
+ json += std::format(" \"isNvidia\": {}\n", s.adapterIsNvidia ? "true" : "false");
+ json += " },\n";
+ json += std::format(" \"driverVersion\": \"{}\",\n", jsonEscape(s.driverVersion));
+ json += std::format(" \"featureLevel\": \"{}\",\n", jsonEscape(s.featureLevel));
+ json += std::format(" \"commandSlots\": {},\n", s.commandSlots);
+ json += " \"runtime\": {\n";
+ json += std::format(" \"path\": \"{}\",\n", jsonEscape(s.runtimePath));
+ json += std::format(" \"sizeBytes\": {},\n", s.runtimeSizeBytes);
+ json += std::format(" \"sha256\": \"{}\",\n", jsonEscape(s.runtimeSha256));
+ json += std::format(" \"fileVersion\": \"{}\",\n", jsonEscape(s.runtimeFileVersion));
+ json += std::format(" \"signature\": \"{}\",\n", jsonEscape(s.runtimeSignature));
+ json += std::format(" \"signer\": \"{}\"\n", jsonEscape(s.runtimeSigner));
+ json += " },\n";
+ json += " \"exports\": {\n";
+ for (size_t i = 0; i < kRequiredExportCount; ++i) {
+ json += std::format(" \"{}\": {}{}\n", kRequiredExports[i], s.exports[i] ? "true" : "false",
+ i + 1 < kRequiredExportCount ? "," : "");
+ }
+ json += " },\n";
+ json += " \"nvofapi\": {\n";
+ json += std::format(" \"path\": \"{}\",\n", jsonEscape(s.nvofapiPath));
+ json += std::format(" \"fileVersion\": \"{}\",\n", jsonEscape(s.nvofapiFileVersion));
+ json += std::format(" \"present\": {}\n", s.nvofapiPresent ? "true" : "false");
+ json += " },\n";
+ json += std::format(" \"experimentalDlssnr\": {},\n", s.experimentalDlssnr ? "true" : "false");
+ json += " \"windowLoop\": {\n";
+ json += std::format(" \"durationSeconds\": {},\n", s.windowDurationSeconds);
+ json += std::format(" \"framesPresented\": {},\n", s.windowFramesPresented);
+ json += std::format(" \"deviceRemoved\": {},\n", s.windowDeviceRemoved ? "true" : "false");
+ json += std::format(" \"deviceRemovedReason\": {}\n", s.windowDeviceRemovedReason);
+ json += " }\n";
+ json += "}\n";
+ return json;
+}
+
+// ---------------------------------------------------------------------------
+// Window plumbing (fixed-size window; no resize => no ResizeBuffers needed)
+// ---------------------------------------------------------------------------
+constexpr wchar_t kWindowClassName[] = L"VeyraRuntimeProbeWindow";
+bool gCloseRequested = false;
+
+LRESULT CALLBACK probeWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ switch (message) {
+ case WM_CLOSE:
+ case WM_DESTROY:
+ gCloseRequested = true;
+ return 0;
+ case WM_KEYDOWN:
+ if (wParam == VK_ESCAPE) {
+ gCloseRequested = true;
+ }
+ return 0;
+ default:
+ return DefWindowProcW(hwnd, message, wParam, lParam);
+ }
+}
+
+int runSelfTest(const std::wstring& runtimeDir);
+int runDeviceInfo(bool debugLayer);
+
+int runFullProbe(const ProbeArgs& args)
+{
+ const std::string runIdNarrow = narrow(args.runId.empty() ? std::wstring(L"<generated>") : args.runId);
+
+ // --- Resolve and validate the absolute runtime directory.
+ wchar_t resolved[MAX_PATH * 2]{};
+ if (GetFullPathNameW(args.runtimeDir.c_str(), static_cast<DWORD>(std::size(resolved)), resolved, nullptr) == 0) {
+ veyra::log::error("probe", "full: GetFullPathNameW failed for runtime dir");
+ return 2;
+ }
+ if (_wcsnicmp(resolved, args.runtimeDir.c_str(), args.runtimeDir.size()) != 0) {
+ veyra::log::error("probe", std::format("full: runtime dir must be absolute/canonical given={} resolved={}",
+ narrow(args.runtimeDir), narrow(resolved)));
+ return 2;
+ }
+ const std::wstring runtimeDir(resolved);
+ const std::wstring dllPath = runtimeDir + L"\\nvngx_dlssnr.dll";
+ veyra::log::info("probe", std::format("full: runtimeDir={} dll={}", narrow(runtimeDir), narrow(dllPath)));
+
+ ProbeSummary summary{};
+ summary.runId = runIdNarrow;
+ summary.osBuild = osBuildString();
+
+ // --- Probe exe self-hash (stale-artifact guard).
+ const std::wstring exe = ownExePath();
+ if (exe.empty()) {
+ veyra::log::error("probe", "full: GetModuleFileNameW failed");
+ return 2;
+ }
+ veyra::FileIdentity exeIdentity{};
+ veyra::IdentityError exeError = veyra::IdentityError::None;
+ if (!veyra::computeFileIdentity(exe, exeIdentity, exeError)) {
+ veyra::log::error("probe", std::format("full: exe identity failed error={}", veyra::identityErrorString(exeError)));
+ return 3;
+ }
+ summary.exeSha256 = exeIdentity.sha256Upper;
+ veyra::log::info("probe", std::format("full: exe sha256={} size={}", summary.exeSha256, exeIdentity.sizeBytes));
+
+ // --- Staged runtime identity (pinned contract).
+ veyra::FileIdentity dllIdentity{};
+ veyra::IdentityError dllError = veyra::IdentityError::None;
+ if (!veyra::computeFileIdentity(dllPath, dllIdentity, dllError)) {
+ veyra::log::error("probe", std::format("full: runtime identity failed error={}", veyra::identityErrorString(dllError)));
+ return 3;
+ }
+ if (dllIdentity.sizeBytes != kExpectedDllSize ||
+ dllIdentity.sha256Upper != kExpectedDllSha256 ||
+ !dllIdentity.signatureValid ||
+ !dllIdentity.signerIsNvidia ||
+ dllIdentity.fileVersion != kExpectedDllFileVersion) {
+ veyra::log::error("probe", std::format("full: runtime identity mismatch size={} sha256={} valid={} nvidia={} version={}",
+ dllIdentity.sizeBytes, dllIdentity.sha256Upper, dllIdentity.signatureValid, dllIdentity.signerIsNvidia,
+ narrow(dllIdentity.fileVersion)));
+ return 3;
+ }
+ summary.runtimePath = narrow(dllPath);
+ summary.runtimeSizeBytes = dllIdentity.sizeBytes;
+ summary.runtimeSha256 = dllIdentity.sha256Upper;
+ summary.runtimeFileVersion = narrow(dllIdentity.fileVersion);
+ summary.runtimeSignature = dllIdentity.signatureValid ? "Valid" : "Invalid";
+ summary.runtimeSigner = narrow(dllIdentity.signerSubject);
+ veyra::log::info("probe", "full: staged runtime identity matches the pinned contract");
+
+ // --- System32 nvofapi64 presence/version (no load).
+ const std::wstring nvofPath = nvofapi64Path();
+ summary.nvofapiPath = narrow(nvofPath);
+ summary.nvofapiFileVersion = narrow(fileVersionOf(nvofPath, summary.nvofapiPresent));
+ veyra::log::info("probe", std::format("full: nvofapi64 present={} version={} path={}",
+ summary.nvofapiPresent, summary.nvofapiFileVersion, summary.nvofapiPath));
+
+ // --- Restricted load of the staged DLSSNR runtime + required exports.
+ HMODULE runtimeModule = LoadLibraryExW(dllPath.c_str(), nullptr,
+ LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32);
+ if (runtimeModule == nullptr) {
+ const DWORD lastError = GetLastError();
+ veyra::log::error("probe", std::format("full: LoadLibraryExW failed lastError={} path={}", lastError, narrow(dllPath)));
+ return 4;
+ }
+ veyra::log::info("probe", "full: LoadLibraryExW ok flags=LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR|LOAD_LIBRARY_SEARCH_SYSTEM32");
+
+ size_t exportsPresent = 0;
+ for (size_t i = 0; i < kRequiredExportCount; ++i) {
+ const FARPROC address = GetProcAddress(runtimeModule, kRequiredExports[i]);
+ summary.exports[i] = address != nullptr;
+ if (address != nullptr) {
+ ++exportsPresent;
+ }
+ veyra::log::info("probe", std::format("full: export {} {} address=0x{:016X}",
+ kRequiredExports[i], address != nullptr ? "present" : "MISSING",
+ reinterpret_cast<uintptr_t>(address)));
+ }
+ if (exportsPresent != kRequiredExportCount) {
+ FreeLibrary(runtimeModule);
+ return 5;
+ }
+ summary.experimentalDlssnr = true;
+ veyra::log::info("probe", std::format("full: required exports {}/{}", exportsPresent, kRequiredExportCount));
+
+ // --- D3D12 device context (debug layer follows the build configuration).
+#if defined(VEYRA_D3D12_DEBUG)
+ constexpr bool kDebugLayerByBuild = true;
+#else
+ constexpr bool kDebugLayerByBuild = false;
+#endif
+ veyra::gfx::D3D12DeviceContext context;
+ veyra::gfx::DeviceContextDesc contextDesc{};
+ contextDesc.enableDebugLayer = kDebugLayerByBuild;
+ contextDesc.commandSlotCount = 4;
+ veyra::Status status = veyra::Status::Ok;
+ if (!context.initialize(contextDesc, status)) {
+ veyra::log::error("probe", std::format("full: device context failed status={}", veyra::statusString(status)));
+ FreeLibrary(runtimeModule);
+ return 6;
+ }
+ const veyra::gfx::AdapterInfo& adapter = context.adapter();
+ summary.adapterName = narrow(adapter.description);
+ summary.adapterVendorId = adapter.vendorIdHex;
+ summary.adapterLuid = adapter.luidString;
+ summary.adapterDedicatedVideoMemoryMiB = adapter.dedicatedVideoMemoryBytes / (1024 * 1024);
+ summary.adapterIsNvidia = adapter.isNvidia;
+ summary.driverVersion = narrow(adapter.driverVersion);
+ summary.featureLevel = context.featureLevelString();
+ summary.commandSlots = context.commandSlotCount();
+
+ // --- Fixed-size Win32 window + flip-model swapchain on the direct queue.
+ WNDCLASSEXW windowClass{};
+ windowClass.cbSize = sizeof(windowClass);
+ windowClass.style = CS_HREDRAW | CS_VREDRAW;
+ windowClass.lpfnWndProc = probeWndProc;
+ windowClass.hInstance = GetModuleHandleW(nullptr);
+ windowClass.hCursor = LoadCursorW(nullptr, IDC_ARROW);
+ windowClass.lpszClassName = kWindowClassName;
+ if (RegisterClassExW(&windowClass) == 0) {
+ veyra::log::error("probe", std::format("full: RegisterClassExW failed lastError={}", GetLastError()));
+ context.shutdown();
+ FreeLibrary(runtimeModule);
+ return 7;
+ }
+ constexpr LONG kWindowWidth = 1280;
+ constexpr LONG kWindowHeight = 720;
+ RECT windowRect{ 0, 0, kWindowWidth, kWindowHeight };
+ if (!AdjustWindowRect(&windowRect, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, FALSE)) {
+ veyra::log::error("probe", std::format("full: AdjustWindowRect failed lastError={}", GetLastError()));
+ context.shutdown();
+ FreeLibrary(runtimeModule);
+ return 7;
+ }
+ HWND window = CreateWindowExW(0, kWindowClassName, L"Veyra runtime probe (Phase 0)",
+ WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ windowRect.right - windowRect.left, windowRect.bottom - windowRect.top,
+ nullptr, nullptr, GetModuleHandleW(nullptr), nullptr);
+ if (window == nullptr) {
+ veyra::log::error("probe", std::format("full: CreateWindowExW failed lastError={}", GetLastError()));
+ context.shutdown();
+ FreeLibrary(runtimeModule);
+ return 7;
+ }
+
+ veyra::gfx::ComPtr<IDXGIFactory2> swapFactory;
+ HRESULT result = CreateDXGIFactory2(0, IID_PPV_ARGS(&swapFactory));
+ if (FAILED(result)) {
+ veyra::log::error("probe", std::format("full: swapchain CreateDXGIFactory2 failed hr={}", veyra::hresultString(result)));
+ DestroyWindow(window);
+ context.shutdown();
+ FreeLibrary(runtimeModule);
+ return 7;
+ }
+ DXGI_SWAP_CHAIN_DESC1 swapDesc{};
+ swapDesc.Width = kWindowWidth;
+ swapDesc.Height = kWindowHeight;
+ swapDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
+ swapDesc.Stereo = FALSE;
+ swapDesc.SampleDesc.Count = 1;
+ swapDesc.SampleDesc.Quality = 0;
+ swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+ swapDesc.BufferCount = 3;
+ swapDesc.Scaling = DXGI_SCALING_NONE;
+ swapDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
+ swapDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
+ veyra::gfx::ComPtr<IDXGISwapChain3> swapchain;
+ veyra::gfx::ComPtr<IDXGISwapChain1> swapchain1;
+ result = swapFactory->CreateSwapChainForHwnd(context.directQueue(), window, &swapDesc, nullptr, nullptr, &swapchain1);
+ if (SUCCEEDED(result)) {
+ const HRESULT qiResult = swapchain1.As(&swapchain);
+ if (FAILED(qiResult)) {
+ veyra::log::error("probe", std::format("full: swapchain QI to IDXGISwapChain3 failed hr={}", veyra::hresultString(qiResult)));
+ result = qiResult;
+ }
+ }
+ if (FAILED(result)) {
+ veyra::log::error("probe", std::format("full: CreateSwapChainForHwnd failed hr={}", veyra::hresultString(result)));
+ DestroyWindow(window);
+ context.shutdown();
+ FreeLibrary(runtimeModule);
+ return 7;
+ }
+ (void)swapFactory->MakeWindowAssociation(window, DXGI_MWA_NO_ALT_ENTER);
+
+ constexpr UINT kBufferCount = 3;
+ veyra::gfx::ComPtr<ID3D12Resource> backBuffers[kBufferCount];
+ D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc{};
+ rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
+ rtvHeapDesc.NumDescriptors = kBufferCount;
+ veyra::gfx::ComPtr<ID3D12DescriptorHeap> rtvHeap;
+ result = context.device()->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(&rtvHeap));
+ if (FAILED(result)) {
+ veyra::log::error("probe", std::format("full: CreateDescriptorHeap failed hr={}", veyra::hresultString(result)));
+ DestroyWindow(window);
+ context.shutdown();
+ FreeLibrary(runtimeModule);
+ return 7;
+ }
+ const UINT rtvHandleSize = context.device()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
+ D3D12_CPU_DESCRIPTOR_HANDLE rtvBase = rtvHeap->GetCPUDescriptorHandleForHeapStart();
+ for (UINT i = 0; i < kBufferCount; ++i) {
+ result = swapchain->GetBuffer(i, IID_PPV_ARGS(&backBuffers[i]));
+ if (FAILED(result)) {
+ veyra::log::error("probe", std::format("full: GetBuffer {} failed hr={}", i, veyra::hresultString(result)));
+ DestroyWindow(window);
+ context.shutdown();
+ FreeLibrary(runtimeModule);
+ return 7;
+ }
+ D3D12_CPU_DESCRIPTOR_HANDLE rtv = rtvBase;
+ rtv.ptr += static_cast<SIZE_T>(rtvHandleSize) * i;
+ context.device()->CreateRenderTargetView(backBuffers[i].Get(), nullptr, rtv);
+ }
+
+ veyra::gfx::CommandSlotRing ring;
+ status = veyra::Status::Ok;
+ if (!ring.initialize(context.device(), context.directQueue(), context.fence(), context.fenceEvent(), 4, status)) {
+ veyra::log::error("probe", std::format("full: slot ring init failed status={}", veyra::statusString(status)));
+ DestroyWindow(window);
+ context.shutdown();
+ FreeLibrary(runtimeModule);
+ return 7;
+ }
+
+ // --- Window loop: per-frame clear via the slot ring + vsync present.
+ ShowWindow(window, SW_SHOWNORMAL);
+ UpdateWindow(window);
+ gCloseRequested = false;
+
+ LARGE_INTEGER qpcFrequency{};
+ QueryPerformanceFrequency(&qpcFrequency);
+ LARGE_INTEGER qpcStart{};
+ QueryPerformanceCounter(&qpcStart);
+
+ const float clearColors[2][4] = {
+ { 0.043f, 0.043f, 0.086f, 1.0f },
+ { 0.545f, 0.267f, 0.071f, 1.0f },
+ };
+ uint64_t frameIndex = 0;
+ uint64_t framesPresented = 0;
+ bool deviceRemoved = false;
+ uint32_t deviceRemovedReason = 0;
+ double elapsedSeconds = 0.0;
+
+ while (!gCloseRequested) {
+ MSG message{};
+ while (PeekMessageW(&message, nullptr, 0, 0, PM_REMOVE)) {
+ TranslateMessage(&message);
+ DispatchMessageW(&message);
+ }
+
+ LARGE_INTEGER qpcNow{};
+ QueryPerformanceCounter(&qpcNow);
+ elapsedSeconds = static_cast<double>(qpcNow.QuadPart - qpcStart.QuadPart) / static_cast<double>(qpcFrequency.QuadPart);
+ if (elapsedSeconds >= static_cast<double>(args.windowSeconds)) {
+ break;
+ }
+
+ const UINT backBufferIndex = swapchain->GetCurrentBackBufferIndex();
+ const uint32_t slot = static_cast<uint32_t>(frameIndex % 4);
+ ID3D12GraphicsCommandList* list = ring.acquire(slot, status);
+ if (list == nullptr) {
+ veyra::log::error("probe", std::format("full: slot acquire failed frame={} status={}", frameIndex, veyra::statusString(status)));
+ break;
+ }
+
+ D3D12_RESOURCE_BARRIER barriers[2]{};
+ barriers[0].Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
+ barriers[0].Transition.pResource = backBuffers[backBufferIndex].Get();
+ barriers[0].Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
+ barriers[0].Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
+ barriers[0].Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
+ list->ResourceBarrier(1, &barriers[0]);
+
+ D3D12_CPU_DESCRIPTOR_HANDLE rtv = rtvBase;
+ rtv.ptr += static_cast<SIZE_T>(rtvHandleSize) * backBufferIndex;
+ list->ClearRenderTargetView(rtv, clearColors[frameIndex & 1], 0, nullptr);
+
+ barriers[1].Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
+ barriers[1].Transition.pResource = backBuffers[backBufferIndex].Get();
+ barriers[1].Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
+ barriers[1].Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
+ barriers[1].Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
+ list->ResourceBarrier(1, &barriers[1]);
+
+ if (!ring.submitAndSignal(slot)) {
+ veyra::log::error("probe", std::format("full: slot submit failed frame={}", frameIndex));
+ break;
+ }
+
+ const HRESULT presentResult = swapchain->Present(1, 0);
+ if (SUCCEEDED(presentResult)) {
+ ++framesPresented;
+ }
+ else {
+ veyra::log::error("probe", std::format("full: Present failed hr={} frame={}", veyra::hresultString(presentResult), frameIndex));
+ deviceRemovedReason = static_cast<uint32_t>(presentResult);
+ deviceRemoved = true;
+ break;
+ }
+
+ if ((frameIndex % 128) == 0) {
+ uint32_t reason = 0;
+ if (!context.checkDeviceAlive(reason)) {
+ deviceRemoved = true;
+ deviceRemovedReason = reason;
+ break;
+ }
+ }
+ ++frameIndex;
+ }
+
+ LARGE_INTEGER qpcEnd{};
+ QueryPerformanceCounter(&qpcEnd);
+ const double totalSeconds = static_cast<double>(qpcEnd.QuadPart - qpcStart.QuadPart) / static_cast<double>(qpcFrequency.QuadPart);
+ summary.windowDurationSeconds = static_cast<uint32_t>(totalSeconds);
+ summary.windowFramesPresented = framesPresented;
+ summary.windowDeviceRemoved = deviceRemoved;
+ summary.windowDeviceRemovedReason = deviceRemovedReason;
+ veyra::log::info("probe", std::format("full: window loop finished seconds={:.3} requested={} frames={} deviceRemoved={} reason=0x{:08X} closeRequested={}",
+ totalSeconds, args.windowSeconds, framesPresented, deviceRemoved, deviceRemovedReason, gCloseRequested));
+
+ // --- Reverse-order cleanup.
+ (void)ring.waitIdle();
+ ring.shutdown();
+ for (UINT i = 0; i < kBufferCount; ++i) {
+ backBuffers[i].Reset();
+ }
+ rtvHeap.Reset();
+ swapchain.Reset();
+ swapFactory.Reset();
+ DestroyWindow(window);
+ (void)UnregisterClassW(kWindowClassName, GetModuleHandleW(nullptr));
+ context.shutdown();
+ FreeLibrary(runtimeModule);
+
+ if (deviceRemoved) {
+ veyra::log::error("probe", std::format("full: device removed reason={}", veyra::hresultString(static_cast<long>(deviceRemovedReason))));
+ return 8;
+ }
+ if (gCloseRequested && totalSeconds < static_cast<double>(args.windowSeconds)) {
+ veyra::log::error("probe", "full: window closed before the requested duration");
+ return 9;
+ }
+
+ if (!args.jsonFile.empty()) {
+ if (!writeTextFile(args.jsonFile, buildJson(summary))) {
+ veyra::log::error("probe", std::format("full: json write failed path={}", narrow(args.jsonFile)));
+ return 10;
+ }
+ veyra::log::info("probe", std::format("full: json written path={}", narrow(args.jsonFile)));
+ }
+ veyra::log::info("probe", "full: PASS");
+ return 0;
}
+// ---------------------------------------------------------------------------
+// --self-test: veyra_base primitive verification
+// ---------------------------------------------------------------------------
int runSelfTest(const std::wstring& runtimeDir)
{
const std::wstring exe = ownExePath();
@@ -52,7 +655,6 @@ int runSelfTest(const std::wstring& runtimeDir)
return 2;
}
- // 1. HRESULT / NGX result string sanity.
const std::string hrOk = veyra::hresultString(0);
const std::string hrRemoved = veyra::hresultString(0x887A0005L);
const std::string hrUnknown = veyra::hresultString(0x8000FFFFL);
@@ -67,7 +669,6 @@ int runSelfTest(const std::wstring& runtimeDir)
}
veyra::log::info("probe", std::format("self-test: result-strings ok ({}, {}, {})", hrOk, hrRemoved, ngxOk));
- // 2. File identity of the running exe (SHA256 + version + signature state).
veyra::FileIdentity exeIdentity{};
veyra::IdentityError exeError = veyra::IdentityError::None;
if (!veyra::computeFileIdentity(exe, exeIdentity, exeError)) {
@@ -80,7 +681,6 @@ int runSelfTest(const std::wstring& runtimeDir)
}
veyra::log::info("probe", std::format("self-test: exe identity ok size={} sha256={}", exeIdentity.sizeBytes, exeIdentity.sha256Upper));
- // 3. Staged DLSSNR runtime identity against the pinned contract.
if (!runtimeDir.empty()) {
std::wstring dllPath = runtimeDir;
if (!dllPath.empty() && dllPath.back() != L'\\' && dllPath.back() != L'/') {
@@ -99,7 +699,7 @@ int runSelfTest(const std::wstring& runtimeDir)
dllIdentity.sha256Upper != kExpectedDllSha256 ||
!dllIdentity.signatureValid ||
!dllIdentity.signerIsNvidia ||
- dllIdentity.fileVersion != L"310.8.0.0") {
+ dllIdentity.fileVersion != kExpectedDllFileVersion) {
veyra::log::error("probe", std::format("self-test: runtime identity mismatch size={} sha256={} valid={} nvidia={} version={}",
dllIdentity.sizeBytes, dllIdentity.sha256Upper, dllIdentity.signatureValid, dllIdentity.signerIsNvidia,
narrow(dllIdentity.fileVersion)));
@@ -112,6 +712,9 @@ int runSelfTest(const std::wstring& runtimeDir)
return 0;
}
+// ---------------------------------------------------------------------------
+// --device-info: adapter/device/slot-ring report
+// ---------------------------------------------------------------------------
int runDeviceInfo(bool debugLayer)
{
veyra::gfx::D3D12DeviceContext context;
@@ -126,11 +729,10 @@ int runDeviceInfo(bool debugLayer)
}
const veyra::gfx::AdapterInfo& adapter = context.adapter();
- veyra::log::info("probe", std::format("device-info: adapter={} vendor={} nvidia={} luid={} vramMiB={} driver={} ({})",
+ veyra::log::info("probe", std::format("device-info: adapter={} vendor={} nvidia={} luid={} vramMiB={} driver={}",
narrow(adapter.description), adapter.vendorIdHex, adapter.isNvidia, adapter.luidString,
adapter.dedicatedVideoMemoryBytes / (1024 * 1024),
- narrow(adapter.driverVersion.empty() ? std::wstring(L"<none>") : adapter.driverVersion),
- narrow(adapter.driverVersionSource)));
+ narrow(adapter.driverVersion.empty() ? std::wstring(L"<none>") : adapter.driverVersion)));
veyra::log::info("probe", std::format("device-info: featureLevel={} debugLayer={} slots={}",
context.featureLevelString(), context.debugLayerEnabled(), context.commandSlotCount()));
@@ -154,7 +756,7 @@ int runDeviceInfo(bool debugLayer)
int wmain(int argc, wchar_t** argv)
{
- std::wstring runtimeDir;
+ ProbeArgs args{};
bool selfTest = false;
bool deviceInfo = false;
bool debugLayer = false;
@@ -170,17 +772,43 @@ int wmain(int argc, wchar_t** argv)
debugLayer = true;
}
else if (arg == L"--runtime-dir" && i + 1 < argc) {
- runtimeDir = argv[++i];
+ args.runtimeDir = argv[++i];
+ }
+ else if (arg == L"--window-seconds" && i + 1 < argc) {
+ args.windowSeconds = static_cast<uint32_t>(wcstoul(argv[++i], nullptr, 10));
+ }
+ else if (arg == L"--run-id" && i + 1 < argc) {
+ args.runId = argv[++i];
+ }
+ else if (arg == L"--log-file" && i + 1 < argc) {
+ args.logFile = argv[++i];
+ }
+ else if (arg == L"--json-file" && i + 1 < argc) {
+ args.jsonFile = argv[++i];
}
}
if (selfTest) {
- return runSelfTest(runtimeDir);
+ return runSelfTest(args.runtimeDir);
}
if (deviceInfo) {
return runDeviceInfo(debugLayer);
}
+ if (!args.runtimeDir.empty()) {
+ if (!args.logFile.empty()) {
+ (void)veyra::Logger::instance().openFile(args.logFile);
+ }
+ if (args.runId.empty()) {
+ LARGE_INTEGER qpc{};
+ QueryPerformanceCounter(&qpc);
+ args.runId = std::format(L"veyra-{:016X}-{:08X}",
+ static_cast<uint64_t>(qpc.QuadPart), GetCurrentProcessId());
+ }
+ const int exitCode = runFullProbe(args);
+ veyra::Logger::instance().closeFile();
+ return exitCode;
+ }
- veyra::log::info("probe", "no mode selected; use --self-test or --device-info (full probe arrives in P0.7)");
+ veyra::log::info("probe", "no mode selected; use --self-test, --device-info, or --runtime-dir <abs> (full probe)");
return 0;
}