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++
Port isolated experimental RTX30 VFG compatibility with scoped rollback
Veyra Goal Agentedad6e984cb9
diff --git a/AGENTS.md b/AGENTS.mdindex c3f7e1ac..408fb443 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -1,5 +1,7 @@# Veyra Agent 工作规则+> **2026-11-02 用户授权RTX30 VFG适配(当前施工)**:分支codex/vfg-ampere-20261102,基线4895549,保留全屏进度条修复。按docs/VFG_AMPERE_PLAN_2026-11-02.md移植Xchen991固定07536ab(MIT):仅VFG模块、SM86设备及当前CUDA上下文,命名导入/私有kernel副本/租约和可验回滚;40/50原生无补丁。复用207321712字节原VFG和模型,不改磁盘DLL/驱动/真实配置。合同/真实模块控制及RTX5070原生回归通过,30实卡未验,UI明确实验。产物test-packages/codex-vfg-ampere-20261102,回执reports/vfg-ampere-20261102/FINAL.json;不合main、不push/发布。后续打包必须带licenses/RTX30-Broadcast-FrameGen-MIT.txt和对应源码差异。+> **2026-11-02 全屏进度条修复(当前施工)**:隔离分支codex/fullscreen-seek-20261102,基线fedd7fc;只改CineBar/Main的焦点交互与隐藏/取消条件,修复按下7ms后被取消的回归。构建通过,QtQuick141/0/0,真实全屏前拖33.770s、后拖5.902s、点击20s正常,观察探针已移除,原用户配置保持。小补丁test-packages/codex-fullscreen-seek-20261102,记录docs/FULLSCREEN_SEEK_FIX_2026-11-02.md与reports/codex-fullscreen-seek-20261102/FINAL.json。本轮不合main、不push、不更新GitHub正式包。> **2026-11-02 交流群入口更新到8群(用户授权)**:7群已满,当前公开入口使用用户原图 `docs/images/community/group-8-20261102.png`,有效期11月9日前;README双语、RELEASE_SUPPORT、2.1.2更新说明及2.1.2/对应源码两个Release正文同步。原字节复制,不裁剪/重绘;两图仍并排各220,赞助图保持。发布标签/下载包保持原身份,不为换群码重打包。核验回执 `E:/项目/Veyra/reports/codex-group8-qr-20261102/FINAL.json`。下方7群记录仅作发布历史。diff --git a/CMakeLists.txt b/CMakeLists.txtindex fa5e9ee8..49b6ef7f 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -384,6 +384,7 @@ add_library(veyra_pipeline STATICsrc/pipeline/LmxxfNrBackend.cppsrc/pipeline/Rdna3NrBackend.cppsrc/pipeline/VfgBackend.cpp+ src/pipeline/VfgAmpereCompat.cpp)veyra_apply_warnings(veyra_pipeline)# FFmpeg/NVOF headers are third-party: /WX stays off for this target.@@ -476,6 +477,10 @@ target_link_libraries(veyra_pipeline_tests PRIVATE veyra_pipeline)add_executable(veyra_vfg_gpu_tests tests/integration/VfgGpuTests.cpp)target_compile_features(veyra_vfg_gpu_tests PRIVATE cxx_std_20)target_link_libraries(veyra_vfg_gpu_tests PRIVATE veyra_pipeline)+add_executable(veyra_vfg_ampere_tests tests/unit/VfgAmpereTests.cpp)+target_compile_features(veyra_vfg_ampere_tests PRIVATE cxx_std_20)+target_compile_options(veyra_vfg_ampere_tests PRIVATE /utf-8)+target_link_libraries(veyra_vfg_ampere_tests PRIVATE veyra_pipeline)add_executable(veyra_scene_teststests/unit/SceneCadenceTests.cppdiff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.mdindex e0ff6251..1bb383f4 100644--- a/THIRD_PARTY_NOTICES.md+++ b/THIRD_PARTY_NOTICES.md@@ -1048,3 +1048,11 @@ Local adaptations preserve the manual 25%–100% policies, AMD's input budget,invalid-value rejection, and shared per-layer export planning. Integration andverification are recorded in `docs/EXPORT_NR_SCALE_REPORT_2026-10-25.md`.+## RTX 30 Video Frame Generation compatibility (2026-11-02)++Source: [Xchen991/RTX30-Broadcast-FrameGen](https://github.com/Xchen991/RTX30-Broadcast-FrameGen), fixed commit `07536ab32a508b7daa714a4a9bda5b56f031bbc3`, MIT, Copyright (c) 2026. Full original permission notice: `licenses/RTX30-Broadcast-FrameGen-MIT.txt`.++Ported from `src/dllmain.cpp`: `Hook_cuDeviceGetAttribute`, `Hook_cuModuleLoadData` and the VFG import-redirection part of `InstallHooksOnVFG`. Adapted in `src/pipeline/VfgAmpereCompat.cpp` / `include/veyra/pipeline/VfgAmpereCompat.h` and connected to `VfgBackend.cpp`. Veyra replaces the fixed import offsets with bounded PE import parsing, rewrites the selected SM86 device's queried minor only within VFG calls, and gates private fatbin/ELF metadata copies on the current CUDA context's device. Kernel instructions are not translated. Original kernel storage and files are never modified. Reference-counted leases, retained module handles and checked IAT restoration cover model coexistence and teardown; uncertain restoration disables later VFG initialization while retaining callback storage. The Broadcast UI patch, version.dll proxy and polling thread are not ported.++Only the recognized VFG runtime receives this experimental SM86 adaptation. RTX 40/50 use their native path without installing these hooks. No SDK, model or proprietary runtime bytes are embedded in Veyra's source or executable, and the existing NVIDIA runtime/model set is reused. Source-level and RTX5070 native regression evidence is not a claim of RTX30 hardware inference, image quality or performance validation. NVIDIA's runtime remains proprietary and is governed separately by its supplied terms.+diff --git a/docs/VFG_AMPERE_PLAN_2026-11-02.md b/docs/VFG_AMPERE_PLAN_2026-11-02.mdnew file mode 100644index 00000000..fffdfe94--- /dev/null+++ b/docs/VFG_AMPERE_PLAN_2026-11-02.md@@ -0,0 +1,32 @@+# RTX 30 系 VFG 兼容接入++用户2026-11-02明确授权移植RTX30-Broadcast-FrameGen。隔离分支 `codex/vfg-ampere-20261102`,基线4895549,包含上一轮全屏进度条修复,不合main、不push/发布。本机RTX5070,不能宣称RTX30实卡已验证。++上游 Xchen991/RTX30-Broadcast-FrameGen,固定07536ab32a508b7daa714a4a9bda5b56f031bbc3,MIT。移植src/dllmain.cpp中VFG模块CUDA查询、fatbin/ELF架构重定向机制;不接Broadcast UI、version.dll代理、固定IAT偏移、1ms轮询或系统级驱动修改。对应来源/修改及原MIT全文写入产品源码与THIRD_PARTY_NOTICES。++沿用现有VFG模块/模型:nvVFXVideoFrameGeneration.dll,207321712字节,SHA256 270CF4FFF9329908F9770D306CB51B910EE04323AF5520CD02A98A2E22ABA795。新兼容只作用于30系SM86;40/50原路径不安装补丁。界面/能力检测允许30系并明确实验状态,真正初始化仍以匹配适配器、组件识别和SDK结果为准。未知组件不应用已知布局的兼容改写,不把用户替换的DLL作为普通播放器启动锁。++实现边界:限定VFG模块的导入表查询与修改,原驱动入口保持;只伪装选中SM86设备在VFG调用内的minor属性;CUDA内核架构标记在私有内存副本修改,原模块/磁盘字节不改;有界结构解析、生命周期租约、先销毁效果后恢复导入表再释放库;安装/回退失败拒绝对应实验增强并记录原因,不影响普通播放。无每帧轮询、无额外GPU像素回读/同步、无新模型或额外运行库。++验证:结构/截断/畸形/未知GPU与设备隔离合同、真实已审计模块的导入扫描与安装/恢复(本机控制测试,不冒充Ampere执行)、40/50不打补丁及原VFG输出GPU回归、相关UI/能力/设置和翻译;每进程≤300秒,构建并发2/≤900秒。依赖在E:/项目/Veyra/deps/vfg-ampere-20261102,临时/日志/报告/测试按同名任务目录。原用户进程/配置、DLL、驱动及SDK保持。++最终命令、结果、包体积差异、文件身份和未验边界追加在本文件,机器回执reports/vfg-ampere-20261102/FINAL.json。+++## 实现与验证记录++已实现:新VfgAmpereCompat负责真实PE按名称发现两个导入、SM86设备/当前CUDA上下文隔离、私有fatbin副本以及多实例引用租约。原CUDA入口和原kernel内容不改;API加载后私有输入副本可释放的生命周期按NVIDIA CUDA Driver API cuLinkComplete约定(先cuModuleLoadData再cuLinkDestroy)核对,见https://docs.nvidia.com/cuda/archive/13.0.2/cuda-driver-api/group__CUDA__MODULE.html。普通40/50初始化明确记录native-no-patches;20系及SM80数据中心卡未开放。界面/节点/能力检测/四语说明已同步,30系标实验。当前支持已审计的原VFG 207321712字节组件;未知版本仅拒绝该实验补丁,不限制40/50原生运行时替换。++构建:沿用scripts/acceptance/build-recording-handoff.py,task codex-vfg-ampere-20261102、build-dir E:/项目/Veyra/build/claude-screen-recording-20261022、label 2.1.2-test、jobs2;首次reconfigure后89.0s,后续5.4s,补充页保护读回检查后最终4.2s,均退出0。最终回执logs/codex-vfg-ampere-20261102/build-20261102-222307/receipt.json。目标veyra_qml_ui、veyra_vfg_ampere_tests、veyra_vfg_gpu_tests、veyra_effect_availability_tests、veyra_vfg_settings_tests、veyra_ui_i18n_tests、veyra_qml_quick_tests、veyra_repair_contract_tests。构建期间一次设备上下文隔离补充由后续顺序增量重建确认纳入最终程序。++新兼容合同180项通过;真实已审计模块的62个fatbin私有副本、导入发现、3轮双租约安装/解绑、跨设备拒绝、原指针与原页保护逐项恢复共342项通过;这里没有在RTX5070执行Ampere改写后的内核,不冒充30系推理。能力75项、VFG设置683项、repair300项、i18n0失败;QtQuick140通过、0失败、1既有条件跳过。真实程序独立配置中选择更新后的VFG菜单,2X输出统计60FPS、源时间4.3s并正常退出;无QML错误,原生路径没有安装兼容补丁。++原生GPU回归覆盖8/10位、各质量与2X–8X、独特插值位置、混合模型、切镜、异步状态与销毁,2425项0失败。最终重建后的同套回归结果由FINAL.json记录,不以提交FPS冒充物理显示或端到端延迟。测试命令和逐项结果保存在reports/vfg-ampere-20261102/run.py、ui.py与对应JSON,原始日志在logs/vfg-ampere-20261102。首次repair启动因测试子进程PATH缺少FFmpeg DLL退出0xC0000135,添加既有运行目录到该子进程PATH后通过;失败日志保留repair-missing-path.*,未改系统环境或驱动。++30系本机无实卡:尚不能证明模型在Ampere上实际执行、画质或实时性能;需要持卡运行验证。RTX5070原生回归不能代替该证据。暂不扩大到未知SDK版本/其他架构,不自动安装驱动或下载模型。++## 本地交付++提供2.1.2 NVIDIA便携包的小型覆盖补丁,不重新复制整包。包括新主程序、两份全屏进度条修复QML、翻译目录、第三方notice/原MIT与对应源码差异。运行库与模型全部沿用原包;原用户配置保持。正式2.1.2主EXE 21200896字节,准确新大小和增量见FINAL.json(首轮实测增加12800字节,最终以回执为准)。ZIP是包含整个新EXE的更新包,下载大小不等于功能增量。++补丁目录test-packages/codex-vfg-ampere-20261102。退出软件,解压到2.1.2 NVIDIA版EXE目录覆盖;在补帧模型选择NVIDIA VFG,30系自动走实验适配。默认效果/已有选择不强改。AMDGPU包缺VFG组件,不应只套此补丁就宣称具备VFG。含上一轮4895549全屏进度条修复。源码差异基于公开v2.1.2源码,随补丁提供;不含专有SDK/模型。无push、main合并或GitHub新发布授权。diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex 0b88daae..918f7208 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -478,3 +478,10 @@ PID61528,用户直接运行2.1.2 NVIDIA包;不激活窗口、不启动额外## 2026-11-02 全屏进度条修复在codex/fullscreen-seek-20261102隔离修复。旧版真实Windows按下7ms后MouseArea取消;进度条遗漏于interacting,焦点被交还主窗口。纳入scrubbing、窗口移动排除、预览mask及完整隐藏条件,取消/禁用时清理120ms延迟seek。构建2.2s/最终0.7s通过;新增用例在旧代码5失败;初版完整139/2/0暴露禁用不触发cancel,修复后141/0/0(35.819s)。真实全屏3次分别提交33.770/5.902/20s,无取消,退出全屏正常;原用户配置保留。首轮人工到EOF重开未算通过,日志保全。源QML观察探针逐字节去除,使用小型2.1.2通用补丁交付,不复制完整包,不修改GitHub资产/运行库/真实配置。命令、回执与验证边界见docs/FULLSCREEN_SEEK_FIX_2026-11-02.md,FINAL与日志在E:/项目/Veyra/reports及logs/codex-fullscreen-seek-20261102。无合并main/push/新发布。+++## 2026-11-02 RTX30 VFG实验兼容++用户授权移植,分支codex/vfg-ampere-20261102基于4895549。来源Xchen991/RTX30-Broadcast-FrameGen固定07536ab32a508b7daa714a4a9bda5b56f031bbc3/MIT,移植CUDA查询和内核元数据重定向,替换固定IAT地址/轮询为按名称发现和生命周期租约;私有副本不写原kernel,选中设备和当前CUDA上下文隔离,退场逐项读回指针与页保护;40/50原生无补丁。菜单、节点、硬件能力和四语提示同步,包含上一轮全屏修复。主程序增量和覆盖补丁按FINAL.json,VFG原DLL/模型不新增不改动。++构建最终4.2s通过;合同180、真实模块/62个fatbin/3轮共享租约342、能力75、VFG设置683、repair300、i18n0失败;QtQuick140/0/1。RTX5070原生GPU各质量/倍率/8与10位回归2425项0失败,最终结果和独立GUI 2X60FPS功能检查见FINAL.json。首次repair因子进程库路径缺失启动失败,补充子进程PATH后通过,失败日志保留。无30系实卡推理/画质/速度结论;不以本机50系代替。临时GUI Loader已去除,原7配置文件和5个VFG运行DLL逐摘要保护,未复制完整包。实际命令、日志、来源与局限见docs/VFG_AMPERE_PLAN_2026-11-02.md,E:/项目/Veyra/reports及logs/vfg-ampere-20261102。本轮不合main、不push/发布。diff --git a/i18n/catalog.json b/i18n/catalog.jsonindex 4e064f13..6a276125 100644--- a/i18n/catalog.json+++ b/i18n/catalog.json@@ -19027,6 +19027,34 @@"zh-TW": ";預設“即時”,同時執行遊戲或其他重負載程式變慢時可改為“高”或“普通”","en": "; Realtime by default. If a game or other heavy program running alongside slows down, choose High or Normal","ja": ";既定は「リアルタイム」。同時に動かすゲームや重い処理が遅くなる場合は「高」か「通常」に変更してください"+ },+ {+ "zh": "NVIDIA VFG · RTX 30(实验)/ 40 / 50",+ "src": "src/ui/bridge/FrameGeneration.cpp",+ "zh-TW": "NVIDIA VFG · RTX 30(實驗)/ 40 / 50",+ "en": "NVIDIA VFG · RTX 30 (experimental) / 40 / 50",+ "ja": "NVIDIA VFG · RTX 30(実験)/ 40 / 50"+ },+ {+ "zh": "VFG 需要 NVIDIA RTX 30 / 40 / 50(30 系为实验兼容)",+ "src": "src/ui/bridge/FrameGeneration.cpp",+ "zh-TW": "VFG 需要 NVIDIA RTX 30 / 40 / 50(30 系為實驗相容)",+ "en": "VFG requires NVIDIA RTX 30 / 40 / 50 (RTX 30 compatibility is experimental)",+ "ja": "VFG には NVIDIA RTX 30 / 40 / 50 が必要です(30 シリーズは実験的対応)"+ },+ {+ "zh": "需要 NVIDIA RTX 30 / 40 / 50(30 系为实验兼容)",+ "src": "src/ui/bridge/Hardware.cpp",+ "zh-TW": "需要 NVIDIA RTX 30 / 40 / 50(30 系為實驗相容)",+ "en": "Requires NVIDIA RTX 30 / 40 / 50 (RTX 30 compatibility is experimental)",+ "ja": "NVIDIA RTX 30 / 40 / 50 が必要です(30 シリーズは実験的対応)"+ },+ {+ "zh": "RTX 30 VFG 为实验兼容,复用现有模型;支持 2X~8X,实际画质与速度需实卡验证",+ "src": "src/ui/bridge/FrameGeneration.cpp",+ "zh-TW": "RTX 30 VFG 為實驗相容,重用現有模型;支援 2X~8X,實際畫質與速度需實卡驗證",+ "en": "RTX 30 VFG compatibility is experimental and reuses existing models; 2X–8X, with image quality and speed requiring hardware validation",+ "ja": "RTX 30 VFG は既存モデルを再利用する実験的対応です。2X~8X、画質と速度は実機での検証が必要です"}]}diff --git a/include/veyra/pipeline/VfgAmpereCompat.h b/include/veyra/pipeline/VfgAmpereCompat.hnew file mode 100644index 00000000..439eb4d9--- /dev/null+++ b/include/veyra/pipeline/VfgAmpereCompat.h@@ -0,0 +1,41 @@+// SPDX-License-Identifier: GPL-3.0-only+#pragma once+#include <Windows.h>+#include <cstddef>+#include <cstdint>+#include <array>+#include <memory>+#include <span>+#include <string>+#include <vector>++namespace veyra::pipeline {+constexpr bool vfgNativeArchitecture(int major,int minor) { return (major==8&&minor==9)||major==12; }+constexpr bool vfgAmpereArchitecture(int major,int minor) { return major==8&&minor==6; }+constexpr int vfgReportedAttribute(int value,int attribute,int device,int selectedDevice,int result) {+ return !result&&attribute==76&&device==selectedDevice&&value==6?9:value;+}+constexpr bool vfgRetargetContext(int currentDevice,int selectedDevice,int result) {return !result&¤tDevice==selectedDevice;}+struct VfgFatbinChanges { unsigned containers=0,elfFlags=0; };+// Bounded port of RTX30-Broadcast-FrameGen's SM89 -> SM86 container retarget.+// Writes a private copy, never the SDK's original bytes; false rejects malformed input.+bool retargetVfgFatbin(std::span<const std::byte>,std::vector<std::byte>&,VfgFatbinChanges&,std::string&);+// PE import discovery instead of the upstream hard-coded +0x3B000 IAT window.+bool findVfgCudaImports(std::span<const std::byte>,std::array<uint32_t,2>&,std::string&);+namespace detail { struct VfgAmpereState; }+class VfgAmpereCompat {+public:+ static constexpr uint64_t knownSize=207321712;+ static constexpr const char* knownSha256="270CF4FFF9329908F9770D306CB51B910EE04323AF5520CD02A98A2E22ABA795";+ VfgAmpereCompat()=default;+ ~VfgAmpereCompat();+ VfgAmpereCompat(const VfgAmpereCompat&)=delete;+ VfgAmpereCompat& operator=(const VfgAmpereCompat&)=delete;+ bool install(HMODULE vfg,HMODULE cuda,int selectedDevice,std::string& reason);+ bool reset(); // after SDK effects/worker are destroyed, before unloading libraries+ bool installed() const { return bool(state_); }+ static bool restoreUncertain();+private:+ std::shared_ptr<detail::VfgAmpereState> state_;+};+}diff --git a/include/veyra/ui/EffectAvailability.h b/include/veyra/ui/EffectAvailability.hindex 32ce34c8..4f26bd93 100644--- a/include/veyra/ui/EffectAvailability.h+++ b/include/veyra/ui/EffectAvailability.h@@ -11,13 +11,14 @@ struct EffectGpu {bool rtx = false, blackwell = false, ada = false, rx9000 = false;uint32_t deviceId = 0;bool rx7000 = false;+ bool ampere = false;};constexpr bool hardwareSupports(HardwareEffect effect, EffectGpu gpu) {switch (effect) {case HardwareEffect::Nvidia: return gpu.vendor == 0x10DE && gpu.rtx;case HardwareEffect::NvidiaNr50: return gpu.vendor == 0x10DE && gpu.blackwell;case HardwareEffect::NvidiaNrSf: return gpu.vendor == 0x10DE && gpu.rtx;- case HardwareEffect::Vfg: return gpu.vendor == 0x10DE && (gpu.ada || gpu.blackwell);+ case HardwareEffect::Vfg: return gpu.vendor == 0x10DE && (gpu.ada || gpu.blackwell || gpu.ampere);case HardwareEffect::AmdNr: return gpu.vendor == 0x1002 && (gpu.rx9000 || gpu.rx7000);case HardwareEffect::Fsr4: return gpu.vendor == 0x1002 && gpu.rx9000;case HardwareEffect::CrossVendor: return gpu.vendor == 0x10DE || gpu.vendor == 0x1002 || gpu.vendor == 0x8086;diff --git a/licenses/RTX30-Broadcast-FrameGen-MIT.txt b/licenses/RTX30-Broadcast-FrameGen-MIT.txtnew file mode 100644index 00000000..9d6dd3b4--- /dev/null+++ b/licenses/RTX30-Broadcast-FrameGen-MIT.txt@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2026++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.\ No newline at end of filediff --git a/src/pipeline/VfgAmpereCompat.cpp b/src/pipeline/VfgAmpereCompat.cppnew file mode 100644index 00000000..6df7ceae--- /dev/null+++ b/src/pipeline/VfgAmpereCompat.cpp@@ -0,0 +1,233 @@+// Derived from Xchen991/RTX30-Broadcast-FrameGen, MIT, Copyright (c) 2026.+// Fixed commit 07536ab32a508b7daa714a4a9bda5b56f031bbc3, src/dllmain.cpp:+// Hook_cuDeviceGetAttribute / Hook_cuModuleLoadData / InstallHooksOnVFG.+// Original permission text: licenses/RTX30-Broadcast-FrameGen-MIT.txt.+// Veyra changes: named PE imports; audited module identity; selected CUDA device+// only; structured, bounded fatbin parsing into private copies; reference-counted+// module/session ownership; checked IAT restoration. No Broadcast UI patch,+// proxy DLL, driver-wide hook, original-data write, or polling thread.+#include "veyra/pipeline/VfgAmpereCompat.h"+#include "veyra/FileIdentity.h"+#include "veyra/Log.h"+#include <algorithm>+#include <atomic>+#include <cstring>+#include <format>+#include <mutex>++namespace veyra::pipeline {+namespace {+constexpr size_t maxFatbin=32u*1024u*1024u;+template<class T> T get(std::span<const std::byte> s,size_t p) { T v{};std::memcpy(&v,s.data()+p,sizeof(v));return v; }+template<class T> void put(std::vector<std::byte>& s,size_t p,T v) {std::memcpy(s.data()+p,&v,sizeof(v));}+bool fits(size_t p,size_t n,size_t size) {return p<=size&&n<=size-p;}+bool bad(std::string& why,const char* text) {why=text;return false;}+bool cstring(std::span<const std::byte> s,size_t p,std::string& out) {+ if(!fits(p,1,s.size()))return false;+ const auto n=std::min(size_t(256),s.size()-p);+ const auto* start=reinterpret_cast<const char*>(s.data()+p);+ const auto* end=static_cast<const char*>(std::memchr(start,0,n));+ if(!end)return false;out.assign(start,end);return true;+}+// SEH is isolated from all C++ objects with destructors.+bool safeCopy(void* dst,const void* src,size_t bytes) {+ __try {std::memcpy(dst,src,bytes);return true;}+ __except(EXCEPTION_EXECUTE_HANDLER) {return false;}+}+}+bool retargetVfgFatbin(std::span<const std::byte> input,std::vector<std::byte>& output,VfgFatbinChanges& changed,std::string& why) {+ output.clear();changed={};why.clear();+ if(input.size()<16||input.size()>maxFatbin)return bad(why,"fatbin length outside bounded range");+ if(get<uint32_t>(input,0)!=0xBA55ED50||get<uint16_t>(input,4)!=1||get<uint16_t>(input,6)!=16)+ return bad(why,"unknown fatbin header");+ if(get<uint64_t>(input,8)!=input.size()-16)return bad(why,"fatbin payload length mismatch");+ std::vector<std::byte> copy(input.begin(),input.end());+ size_t p=16;unsigned entries=0;+ while(p<input.size()) {+ if(++entries>4096||!fits(p,64,input.size()))return bad(why,"truncated fatbin entry");+ const auto kind=get<uint16_t>(input,p),version=get<uint16_t>(input,p+2);+ const auto header=get<uint32_t>(input,p+4);+ const auto bytes=get<uint64_t>(input,p+8);+ if((kind!=1&&kind!=2)||version!=0x101||header<64||header>4096||header%8||+ !fits(p,header,input.size())||bytes>input.size()-p-header||!bytes)+ return bad(why,"invalid fatbin entry bounds or format");+ const auto sm=get<uint32_t>(input,p+28);const size_t payload=p+header;+ if(sm==89) {+ // Audited SDK: uncompressed ELF64 CUDA entry, header=64, e_flags=0x00590559.+ // Retargeting metadata does not translate the kernel's instructions.+ if(kind!=2||header!=64||bytes<64||get<uint32_t>(input,payload)!=0x464c457f||+ get<uint8_t>(input,payload+4)!=2||get<uint8_t>(input,payload+5)!=1||+ get<uint16_t>(input,payload+18)!=190||get<uint32_t>(input,payload+48)!=0x00590559)+ return bad(why,"unrecognized SM89 CUDA ELF layout");+ put<uint32_t>(copy,p+28,86);put<uint32_t>(copy,payload+48,0x00560556);+ ++changed.containers;++changed.elfFlags;+ }+ p=payload+size_t(bytes);+ }+ if(!entries)return bad(why,"empty fatbin");+ output=std::move(copy);return true;+}+bool findVfgCudaImports(std::span<const std::byte> image,std::array<uint32_t,2>& slots,std::string& why) {+ slots={};why.clear();+ if(image.size()<sizeof(IMAGE_DOS_HEADER)||get<uint16_t>(image,0)!=IMAGE_DOS_SIGNATURE)return bad(why,"invalid DOS header");+ const auto nt=get<uint32_t>(image,offsetof(IMAGE_DOS_HEADER,e_lfanew));+ if(!fits(nt,sizeof(IMAGE_NT_HEADERS64),image.size())||get<uint32_t>(image,nt)!=IMAGE_NT_SIGNATURE)return bad(why,"invalid PE header");+ const auto h=get<IMAGE_NT_HEADERS64>(image,nt);+ if(h.FileHeader.Machine!=IMAGE_FILE_MACHINE_AMD64||h.OptionalHeader.Magic!=IMAGE_NT_OPTIONAL_HDR64_MAGIC||+ h.OptionalHeader.SizeOfImage!=image.size()||h.OptionalHeader.NumberOfRvaAndSizes<=IMAGE_DIRECTORY_ENTRY_IMPORT)+ return bad(why,"unsupported mapped PE");+ const auto dir=h.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];+ if(dir.Size<sizeof(IMAGE_IMPORT_DESCRIPTOR)||!fits(dir.VirtualAddress,dir.Size,image.size()))return bad(why,"invalid import directory");+ bool terminated=false;+ for(size_t offset=0;fits(offset,sizeof(IMAGE_IMPORT_DESCRIPTOR),dir.Size);offset+=sizeof(IMAGE_IMPORT_DESCRIPTOR)) {+ const auto d=get<IMAGE_IMPORT_DESCRIPTOR>(image,dir.VirtualAddress+offset);+ if(!d.Name&&!d.FirstThunk&&!d.OriginalFirstThunk){terminated=true;break;}+ std::string name;if(!cstring(image,d.Name,name))return bad(why,"invalid import name");+ std::transform(name.begin(),name.end(),name.begin(),[](unsigned char c){return char(c>='A'&&c<='Z'?c+32:c);});+ if(name!="nvcuda.dll")continue;+ if(!d.OriginalFirstThunk||!d.FirstThunk||d.FirstThunk%alignof(void*))return bad(why,"missing or unaligned named CUDA thunks");+ bool end=false;+ for(size_t i=0;i<65536;++i) {+ const size_t original=size_t(d.OriginalFirstThunk)+i*8,iat=size_t(d.FirstThunk)+i*8;+ if(!fits(original,8,image.size())||!fits(iat,8,image.size()))return bad(why,"truncated CUDA thunks");+ const auto value=get<uint64_t>(image,original);if(!value){end=true;break;}+ if(value&IMAGE_ORDINAL_FLAG64)continue;+ if(value>UINT32_MAX||!cstring(image,size_t(value)+2,name))return bad(why,"invalid CUDA function name");+ int index=name=="cuDeviceGetAttribute"?0:name=="cuModuleLoadData"?1:-1;+ if(index<0)continue;+ if(slots[size_t(index)])return bad(why,"ambiguous CUDA import");+ slots[size_t(index)]=uint32_t(iat);+ }+ if(!end)return bad(why,"unterminated CUDA imports");+ }+ if(!terminated||!slots[0]||!slots[1])return bad(why,"required CUDA imports not unique");+ return true;+}+namespace detail {+struct VfgAmpereState {+ using Attribute=int(__stdcall*)(int*,int,int);+ using Load=int(__stdcall*)(void**,const void*);+ using ContextDevice=int(__stdcall*)(int*);+ HMODULE module=nullptr,driver=nullptr;+ Attribute attribute=nullptr;Load load=nullptr;ContextDevice contextDevice=nullptr;+ int device=-1;unsigned leases=0;+ struct Slot {void** pointer=nullptr;void* original=nullptr;void* hook=nullptr;DWORD protection=0;bool changed=false;};+ std::array<Slot,2> slots{};+ std::atomic<unsigned> patchedLoads{0},attributeSpoofs{0},rejectedLoads{0};+ ~VfgAmpereState(){if(module)FreeLibrary(module);if(driver)FreeLibrary(driver);}+};+}+namespace {+std::mutex leaseMutex;+std::atomic<std::shared_ptr<detail::VfgAmpereState>> activeState;+std::atomic<bool> poisoned=false;+int __stdcall Hook_cuDeviceGetAttribute(int* value,int attribute,int device) {+ auto state=activeState.load();if(!state)return 3; // CUDA_ERROR_NOT_INITIALIZED+ const int result=state->attribute(value,attribute,device);+ if(!result&&value){const int reported=vfgReportedAttribute(*value,attribute,device,state->device,result);if(reported!=*value){*value=reported;++state->attributeSpoofs;}}+ return result;+}+int __stdcall Hook_cuModuleLoadData(void** module,const void* image) {+ auto state=activeState.load();if(!state)return 3;+ int currentDevice=-1;+ const int contextResult=state->contextDevice(¤tDevice);+ if(!vfgRetargetContext(currentDevice,state->device,contextResult))return state->load(module,image);+ uint32_t magic=0;+ if(!image)return state->load(module,image);+ if(!safeCopy(&magic,image,4)){++state->rejectedLoads;return 200;}+ if(magic!=0xBA55ED50)return state->load(module,image);+ try {+ std::array<std::byte,16> header{};+ if(!safeCopy(header.data(),image,header.size()))return 200; // CUDA_ERROR_INVALID_IMAGE+ const auto payload=get<uint64_t>(header,8);+ if(payload>maxFatbin-16){++state->rejectedLoads;return 200;}+ std::vector<std::byte> original(size_t(payload)+16),copy;+ if(!safeCopy(original.data(),image,original.size())){++state->rejectedLoads;return 200;}+ VfgFatbinChanges changes;std::string why;+ if(!retargetVfgFatbin(original,copy,changes,why)){+ ++state->rejectedLoads;log::error("vfg-ampere","kernel rejected: "+why);return 200;+ }+ if(!changes.containers)return state->load(module,image);+ // CUDA takes ownership of its module storage during this synchronous call.+ const int result=state->load(module,copy.data());+ ++state->patchedLoads;+ log::info("vfg-ampere",std::format("private fatbin bytes={} containers={} elfFlags={} cuModuleLoadData={}",copy.size(),changes.containers,changes.elfFlags,result));+ return result;+ } catch(...) {++state->rejectedLoads;return 2;} // CUDA_ERROR_OUT_OF_MEMORY+}+bool changeSlot(detail::VfgAmpereState::Slot& slot,bool restore) {+ DWORD prior=0;if(!VirtualProtect(slot.pointer,sizeof(void*),PAGE_READWRITE,&prior))return false;+ if(!slot.protection)slot.protection=prior;+ void* expected=restore?slot.hook:slot.original;+ void* desired=restore?slot.original:slot.hook;+ const bool changed=InterlockedCompareExchangePointer(slot.pointer,desired,expected)==expected;+ if(changed)slot.changed=!restore;+ DWORD ignored=0;bool protectedAgain=false;+ for(unsigned attempt=0;attempt<3&&!protectedAgain;++attempt)+ protectedAgain=VirtualProtect(slot.pointer,sizeof(void*),slot.protection,&ignored)!=FALSE;+ MEMORY_BASIC_INFORMATION actual{};+ protectedAgain=protectedAgain&&VirtualQuery(slot.pointer,&actual,sizeof(actual))&&actual.Protect==slot.protection;+ const bool equal=*slot.pointer==desired;+ if(!protectedAgain)poisoned=true;+ if(!changed||!protectedAgain||!equal)log::error("vfg-ampere",std::format("IAT {} failed changed={} protected={} equal={} win32={}",restore?"restore":"install",changed,protectedAgain,equal,GetLastError()));+ return changed&&protectedAgain&&equal;+}+bool restoreSlots(detail::VfgAmpereState& state) {+ bool okay=true;+ for(auto it=state.slots.rbegin();it!=state.slots.rend();++it)if(it->changed&&!changeSlot(*it,true))okay=false;+ if(!okay)poisoned=true;+ return okay&&!poisoned;+}+}+VfgAmpereCompat::~VfgAmpereCompat(){reset();}+bool VfgAmpereCompat::restoreUncertain(){return poisoned.load();}+bool VfgAmpereCompat::install(HMODULE module,HMODULE cuda,int device,std::string& why) {+ if(state_)return bad(why,"compatibility lease already held");+ std::lock_guard lock(leaseMutex);+ if(poisoned)return bad(why,"previous VFG import restoration failed; restart required");+ if(auto existing=activeState.load()){+ if(existing->module!=module||existing->driver!=cuda||existing->device!=device)return bad(why,"another VFG device owns compatibility");+ ++existing->leases;state_=std::move(existing);return true;+ }+ std::array<wchar_t,32768> path{};+ if(!module||!cuda||!GetModuleFileNameW(module,path.data(),DWORD(path.size())))return bad(why,"VFG module path unavailable");+ FileIdentity identity;IdentityError error{};+ if(!computeFileIdentity(path.data(),identity,error)||identity.sizeBytes!=knownSize||identity.sha256Upper!=knownSha256)+ return bad(why,"RTX30 VFG compatibility does not recognize this runtime; native paths are unchanged");+ auto state=std::make_shared<detail::VfgAmpereState>();+ if(!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,reinterpret_cast<LPCWSTR>(module),&state->module)||+ !GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,reinterpret_cast<LPCWSTR>(cuda),&state->driver))+ return bad(why,"cannot retain VFG/CUDA module ownership");+ state->device=device;+ state->attribute=reinterpret_cast<detail::VfgAmpereState::Attribute>(GetProcAddress(cuda,"cuDeviceGetAttribute"));+ state->load=reinterpret_cast<detail::VfgAmpereState::Load>(GetProcAddress(cuda,"cuModuleLoadData"));+ state->contextDevice=reinterpret_cast<detail::VfgAmpereState::ContextDevice>(GetProcAddress(cuda,"cuCtxGetDevice"));+ if(!state->attribute||!state->load||!state->contextDevice)return bad(why,"required CUDA exports missing");+ auto* bytes=reinterpret_cast<const std::byte*>(module);+ const auto* dos=reinterpret_cast<const IMAGE_DOS_HEADER*>(module);+ const auto* nt=reinterpret_cast<const IMAGE_NT_HEADERS64*>(bytes+dos->e_lfanew);+ std::array<uint32_t,2> imports{};+ if(!findVfgCudaImports({bytes,nt->OptionalHeader.SizeOfImage},imports,why))return false;+ const std::array<void*,2> original={reinterpret_cast<void*>(state->attribute),reinterpret_cast<void*>(state->load)};+ const std::array<void*,2> hooks={reinterpret_cast<void*>(Hook_cuDeviceGetAttribute),reinterpret_cast<void*>(Hook_cuModuleLoadData)};+ for(size_t i=0;i<2;++i){auto& slot=state->slots[i];slot.pointer=reinterpret_cast<void**>(reinterpret_cast<std::byte*>(module)+imports[i]);slot.original=original[i];slot.hook=hooks[i];+ if(*slot.pointer!=slot.original)return bad(why,"VFG CUDA import already redirected by another component");}+ activeState.store(state);+ for(auto& slot:state->slots)if(!changeSlot(slot,false)){+ if(restoreSlots(*state))activeState.store({});+ return bad(why,"cannot install VFG compatibility imports");+ }+ state->leases=1;state_=std::move(state);+ log::info("vfg-ampere",std::format("installed selectedCudaDevice={} imports=2 identity={} (experimental SM86; private kernel copies; other driver callers unchanged)",device,identity.sha256Upper));+ return true;+}+bool VfgAmpereCompat::reset() {+ if(!state_)return !poisoned;+ std::lock_guard lock(leaseMutex);auto state=std::move(state_);+ if(--state->leases)return !poisoned;+ const bool okay=restoreSlots(*state);+ log::info("vfg-ampere",std::format("restored={} privateLoads={} attributeSpoofs={} rejectedLoads={}",okay,state->patchedLoads.load(),state->attributeSpoofs.load(),state->rejectedLoads.load()));+ if(okay)activeState.store({}); // Failed restoration intentionally pins callbacks/modules.+ return okay;+}+}diff --git a/src/pipeline/VfgBackend.cpp b/src/pipeline/VfgBackend.cppindex ac78c83b..7589d6e3 100644--- a/src/pipeline/VfgBackend.cpp+++ b/src/pipeline/VfgBackend.cpp@@ -1,4 +1,5 @@#include "veyra/pipeline/VfgBackend.h"+#include "veyra/pipeline/VfgAmpereCompat.h"#include "veyra/pipeline/FrameBatch.h"#include "veyra/pipeline/GpuPassUtils.h"#include "veyra/core/SceneCadenceAnalyzer.h"@@ -122,6 +123,7 @@ struct VfgBackend::Impl {std::array<Effect,2> effects{};bool mixed=false;std::vector<HMODULE> libraries;+ VfgAmpereCompat ampereCompat;D3D12_PLACED_SUBRESOURCE_FOOTPRINT footprint{};uint64_t bytes=0,signalValue=0;unsigned width=0,height=0,maxMultiplier=2;@@ -481,7 +483,9 @@ bool VfgBackend::initialize(gfx::D3D12DeviceContext& context,const std::wstring&int major=0,minor=0;if(!p.cu(p.cuDeviceGetAttributeFn(&major,CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR,p.device),"compute major")||!p.cu(p.cuDeviceGetAttributeFn(&minor,CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR,p.device),"compute minor"))return false;- if(!((major==8&&minor==9)||major==12)){log::error("vfg",std::format("Windows VFG requires Ada/Blackwell; compute={}.{}",major,minor));return false;}+ if(VfgAmpereCompat::restoreUncertain()){log::error("vfg","VFG import restoration uncertain; restart before using VFG");return false;}+ const bool ampere=vfgAmpereArchitecture(major,minor);+ if(!ampere&&!vfgNativeArchitecture(major,minor)){log::error("vfg",std::format("Windows VFG requires SM86 (experimental), Ada or Blackwell; compute={}.{}",major,minor));return false;}if(!p.cu(p.cuDevicePrimaryCtxRetainFn(&p.cudaContext,p.device),"cuDevicePrimaryCtxRetain"))return false;p.retained=true;Impl::Current current(p);if(!current.active)return false;if(!p.cu(p.cuStreamCreateFn(&p.stream,CU_STREAM_NON_BLOCKING),"cuStreamCreate"))return false;@@ -492,9 +496,15 @@ bool VfgBackend::initialize(gfx::D3D12DeviceContext& context,const std::wstring&// Keep the original core/plugin/CUDA bytes; unrelated SDK image-processing// DLLs are not dependencies of this path (native 8/10-bit tests cover it).const std::array<const wchar_t*,5> dependencies={L"cudart64_12.dll",L"NVCVImage.dll",L"nvngxruntime.dll",L"NVVideoEffects.dll",L"nvVFXVideoFrameGeneration.dll"};- HMODULE core=nullptr,image=nullptr;+ HMODULE core=nullptr,image=nullptr,vfg=nullptr;for(auto name:dependencies){auto dll=load(runtime/name);if(!dll)return false;p.libraries.push_back(dll);- if(std::wstring_view(name)==L"NVVideoEffects.dll")core=dll;if(std::wstring_view(name)==L"NVCVImage.dll")image=dll;}+ if(std::wstring_view(name)==L"NVVideoEffects.dll")core=dll;if(std::wstring_view(name)==L"NVCVImage.dll")image=dll;+ if(std::wstring_view(name)==L"nvVFXVideoFrameGeneration.dll")vfg=dll;}+ if(ampere){+ std::string why;+ if(!p.ampereCompat.install(vfg,driver,p.device,why)){log::error("vfg-ampere",why);return false;}+ }+ log::info("vfg",std::format("compatibility={} compute={}.{}",ampere?"SM86-experimental":"native-no-patches",major,minor));#define BIND_VFX(member,name) if(!bind(core,name,p.member))return falseBIND_VFX(create,"NvVFX_CreateEffect");BIND_VFX(destroy,"NvVFX_DestroyEffect");BIND_VFX(setU32,"NvVFX_SetU32");BIND_VFX(setImage,"NvVFX_SetImage");BIND_VFX(setStream,"NvVFX_SetCudaStream");BIND_VFX(loadEffect,"NvVFX_Load");BIND_VFX(run,"NvVFX_Run");BIND_VFX(getVersion,"NvVFX_GetVersion");@@ -678,6 +688,7 @@ void VfgBackend::shutdown(){}}if(p.retained)p.cu(p.cuDevicePrimaryCtxReleaseFn(p.device),"cuDevicePrimaryCtxRelease");+ if(!p.ampereCompat.reset())log::error("vfg-ampere","cannot prove restoration; compatibility modules retained until process exit");p.producer.Reset();p.completion.Reset();for(auto i=p.libraries.rbegin();i!=p.libraries.rend();++i)FreeLibrary(*i);impl_=std::make_unique<Impl>();diff --git a/src/ui/bridge/Chain.cpp b/src/ui/bridge/Chain.cppindex 88fe2edc..77000525 100644--- a/src/ui/bridge/Chain.cpp+++ b/src/ui/bridge/Chain.cpp@@ -365,7 +365,7 @@ int QmlPlayerBridge::addEffect(const QString& type) {const auto fgCeiling=engine::fsrFrameGeneration(fgBackend)?2u:fgBackend==engine::FrameGenerationBackend::XeSS?uint32_t(xessCeiling(impl_->snapshot)):fgBackend==engine::FrameGenerationBackend::Vfg?8u:6u;if(fgType&&fgBackend==engine::FrameGenerationBackend::Vfg&&(!vfgHardwarePossible()||!pipeline::VfgBackend::runtimeAvailable(runtime::localRuntimeDirectory().wstring()))){- emit notice(!vfgHardwarePossible()?tr("VFG 需要 NVIDIA Ada / Blackwell 显卡(RTX 40 / 50)"):tr("未找到 VFG 运行组件,请在组件页核对路径"),true);return -1;+ emit notice(!vfgHardwarePossible()?tr("VFG 需要 NVIDIA RTX 30 / 40 / 50(30 系为实验兼容)"):tr("未找到 VFG 运行组件,请在组件页核对路径"),true);return -1;}if (impl_->chain.mode == engine::ChainMode::Node) {const bool fg = fgType;diff --git a/src/ui/bridge/FrameGeneration.cpp b/src/ui/bridge/FrameGeneration.cppindex 74c4bbfa..02b5a5d8 100644--- a/src/ui/bridge/FrameGeneration.cpp+++ b/src/ui/bridge/FrameGeneration.cpp@@ -19,7 +19,7 @@ QVariantList QmlPlayerBridge::fgBackendChoices() const {QVariantMap{{"id","xess"},{"label",tr("Intel XeSS · 实验")}},QVariantMap{{"id","fsr3"},{"label",tr("FSR 3.1 · 2X")}},QVariantMap{{"id","fsr4"},{"label",tr("FSR 4 ML · RX 9000 · 实验")}},- QVariantMap{{"id","vfg"},{"label",tr("NVIDIA VFG · RTX 40 / 50")}}+ QVariantMap{{"id","vfg"},{"label",tr("NVIDIA VFG · RTX 30(实验)/ 40 / 50")}}};const auto caps = effectCapabilities();for (auto& choice : choices) {@@ -34,8 +34,9 @@ QVariantList QmlPlayerBridge::fgBackendChoices() const {QString QmlPlayerBridge::fgProviderText() const {const auto& s=impl_->snapshot;if(fgBackendName()==QLatin1String("vfg")){- if(!vfgHardwarePossible())return tr("VFG 需要 NVIDIA Ada / Blackwell 显卡(RTX 40 / 50)");+ if(!vfgHardwarePossible())return tr("VFG 需要 NVIDIA RTX 30 / 40 / 50(30 系为实验兼容)");if(!effectCapabilities().value("vfg").toMap().value("available").toBool())return tr("未找到 VFG 运行组件,请在组件页核对路径");+ if(effectGpu().ampere)return tr("RTX 30 VFG 为实验兼容,复用现有模型;支持 2X~8X,实际画质与速度需实卡验证");return tr("VFG 支持 2X~8X 和低 / 中 / 高质量;6X~8X 为实验档,高倍高质量会增加处理时间");}if(engine::fsrFrameGeneration(s.applied.frameGenerationBackend)&&s.applied.multiplier>1&&!s.fsrProviderVersion.empty())@@ -74,7 +75,7 @@ void QmlPlayerBridge::setFgBackendName(const QString& value) {: engine::FrameGenerationBackend::Dlss;if (s.frameGenerationBackend == want) return;if(want==engine::FrameGenerationBackend::Vfg&&(!vfgHardwarePossible()||!pipeline::VfgBackend::runtimeAvailable(runtime::localRuntimeDirectory().wstring()))){- emit notice(!vfgHardwarePossible()?tr("VFG 需要 NVIDIA Ada / Blackwell 显卡(RTX 40 / 50)"):tr("未找到 VFG 运行组件,请在组件页核对路径"),true);emit settingsChanged();return;+ emit notice(!vfgHardwarePossible()?tr("VFG 需要 NVIDIA RTX 30 / 40 / 50(30 系为实验兼容)"):tr("未找到 VFG 运行组件,请在组件页核对路径"),true);emit settingsChanged();return;}if (want == engine::FrameGenerationBackend::Fsr4 && !fsr4Possible()) {// Keep the previous choice; the menu snaps back to it.diff --git a/src/ui/bridge/Hardware.cpp b/src/ui/bridge/Hardware.cppindex d863cf0d..d7f4a70d 100644--- a/src/ui/bridge/Hardware.cpp+++ b/src/ui/bridge/Hardware.cpp@@ -42,7 +42,7 @@ bool vfgHardwarePossible(){const auto* d=engineAdapterDesc();if(!d)return false;const auto name=QString::fromWCharArray(d->Description);- return d->VendorId==0x10DE&&(name.contains(QStringLiteral("GeForce RTX 40"),Qt::CaseInsensitive)||+ return d->VendorId==0x10DE&&(name.contains(QStringLiteral("GeForce RTX 30"),Qt::CaseInsensitive)||name.contains(QStringLiteral("GeForce RTX 40"),Qt::CaseInsensitive)||name.contains(QStringLiteral("GeForce RTX 50"),Qt::CaseInsensitive)||name.contains(QStringLiteral("Ada"),Qt::CaseInsensitive)||name.contains(QStringLiteral("Blackwell"),Qt::CaseInsensitive));}unsigned normalizeFgMultiplier(unsigned value,engine::FrameGenerationBackend backend,unsigned cap){@@ -61,6 +61,7 @@ ui::EffectGpu effectGpu() {result.rtx = name.contains("RTX", Qt::CaseInsensitive);result.blackwell = name.contains("RTX 50", Qt::CaseInsensitive) || name.contains("Blackwell", Qt::CaseInsensitive);result.ada = name.contains("RTX 40", Qt::CaseInsensitive) || name.contains("Ada", Qt::CaseInsensitive);+ result.ampere = name.contains("GeForce RTX 30", Qt::CaseInsensitive);result.rx9000 = name.contains("RX 90", Qt::CaseInsensitive);result.rx7000 = pipeline::amdNrProvider(d->VendorId,d->Description)==pipeline::AmdNrProvider::RedDukeRdna3;return result;@@ -99,7 +100,7 @@ static QVariantMap scanEffectCapabilities() {for (int i = 1; i <= 4; ++i) add("sr" + QString::number(i), H::Nvidia, exists(nr / "nvngx_vsr.dll"), QObject::tr("需要 NVIDIA RTX 显卡"));add("sr5", H::CrossVendor, fsrLoader && exists(fsr / "amd_fidelityfx_upscaler_dx12.dll"), QObject::tr("需要支持 DirectX 12 的硬件显卡"));add("dlss", H::Nvidia, exists(nr / "nvngx_dlssg.dll"), QObject::tr("需要 NVIDIA RTX 显卡"));- add("vfg", H::Vfg, pipeline::VfgBackend::runtimeAvailable(nr.wstring()), QObject::tr("需要 NVIDIA RTX 40 / 50(Ada / Blackwell)"));+ add("vfg", H::Vfg, pipeline::VfgBackend::runtimeAvailable(nr.wstring()), QObject::tr("需要 NVIDIA RTX 30 / 40 / 50(30 系为实验兼容)"));add("xess", H::CrossVendor, exists(data / "intel/experimental/libxess_fg.dll") && exists(data / "intel/experimental/libxell.dll"), QObject::tr("需要支持 DirectX 12 的硬件显卡"));add("fsr3", H::CrossVendor, fsrLoader && exists(fsr / "amd_fidelityfx_framegeneration_dx12.dll"), QObject::tr("需要支持 DirectX 12 的硬件显卡"));add("fsr4", H::Fsr4, fsrLoader && exists(fsr / "amd_fidelityfx_framegeneration_dx12.dll"), QObject::tr("需要 AMD RX 9000"));diff --git a/tests/unit/EffectAvailabilityTests.cpp b/tests/unit/EffectAvailabilityTests.cppindex 35132f55..d165ea6d 100644--- a/tests/unit/EffectAvailabilityTests.cpp+++ b/tests/unit/EffectAvailabilityTests.cpp@@ -31,6 +31,10 @@ int main() {verify(hardwareSupports(HardwareEffect::AmdNr,rdna3Gpu));verify(!hardwareSupports(HardwareEffect::Fsr4,rdna3Gpu));verify(!hardwareSupports(HardwareEffect::NvidiaNrSf,rdna3Gpu));+ EffectGpu ampereGpu{};ampereGpu.vendor=0x10DE;ampereGpu.rtx=true;ampereGpu.ampere=true;+ verify(hardwareSupports(HardwareEffect::Vfg,ampereGpu));+ verify(!hardwareSupports(HardwareEffect::NvidiaNr50,ampereGpu));+ ampereGpu.vendor=0x1002;verify(!hardwareSupports(HardwareEffect::Vfg,ampereGpu));verify(rdna3::validExtent(1920,1080)&&rdna3::validExtent(2560,800));verify(!rdna3::validExtent(3840,2160)&&!rdna3::validExtent(2560,1080)&&!rdna3::validExtent(0,1080));rdna3::Evaluate packet;verify(rdna3::validHeader(packet.h,rdna3::Op::Evaluate,sizeof(packet)));diff --git a/tests/unit/VfgAmpereTests.cpp b/tests/unit/VfgAmpereTests.cppnew file mode 100644index 00000000..bd90dff9--- /dev/null+++ b/tests/unit/VfgAmpereTests.cpp@@ -0,0 +1,95 @@+// SPDX-License-Identifier: GPL-3.0-only+#include "veyra/pipeline/VfgAmpereCompat.h"+#include <cstdio>+#include <cstring>+#include <filesystem>+#include <algorithm>+using namespace veyra::pipeline;+template<class T> void set(std::vector<std::byte>& b,size_t p,T value){std::memcpy(b.data()+p,&value,sizeof(value));}+template<class T> T get(const std::byte* b,size_t p){T v{};std::memcpy(&v,b+p,sizeof(v));return v;}+std::vector<std::byte> fatbin(uint32_t sm=89,uint32_t flags=0x00590559){+ std::vector<std::byte> b(144);set<uint32_t>(b,0,0xBA55ED50);set<uint16_t>(b,4,1);set<uint16_t>(b,6,16);set<uint64_t>(b,8,128);+ set<uint16_t>(b,16,2);set<uint16_t>(b,18,0x101);set<uint32_t>(b,20,64);set<uint64_t>(b,24,64);set<uint32_t>(b,44,sm);+ set<uint32_t>(b,80,0x464c457f);set<uint8_t>(b,84,2);set<uint8_t>(b,85,1);set<uint16_t>(b,98,190);set<uint32_t>(b,128,flags);return b;+}+std::vector<std::byte> mappedPe(){+ std::vector<std::byte> b(4096);IMAGE_DOS_HEADER dos{};dos.e_magic=IMAGE_DOS_SIGNATURE;dos.e_lfanew=0x80;set(b,0,dos);+ IMAGE_NT_HEADERS64 nt{};nt.Signature=IMAGE_NT_SIGNATURE;nt.FileHeader.Machine=IMAGE_FILE_MACHINE_AMD64;+ nt.FileHeader.SizeOfOptionalHeader=sizeof(nt.OptionalHeader);nt.OptionalHeader.Magic=IMAGE_NT_OPTIONAL_HDR64_MAGIC;+ nt.OptionalHeader.SizeOfImage=4096;nt.OptionalHeader.NumberOfRvaAndSizes=IMAGE_NUMBEROF_DIRECTORY_ENTRIES;+ nt.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]={0x200,40};set(b,0x80,nt);+ IMAGE_IMPORT_DESCRIPTOR d{};d.OriginalFirstThunk=0x400;d.FirstThunk=0x500;d.Name=0x300;set(b,0x200,d);+ std::memcpy(b.data()+0x300,"nvcuda.dll",11);+ set<uint64_t>(b,0x400,0x600);set<uint64_t>(b,0x408,0x640);+ std::memcpy(b.data()+0x602,"cuDeviceGetAttribute",21);std::memcpy(b.data()+0x642,"cuModuleLoadData",17);return b;+}+int wmain(int argc,wchar_t** argv){+ unsigned checks=0,failed=0;auto check=[&](bool okay,const char* label){++checks;if(!okay){++failed;std::printf("FAIL %s\n",label);}};+ check(vfgAmpereArchitecture(8,6)&&!vfgNativeArchitecture(8,6),"SM86 gets compatibility only");+ check(vfgNativeArchitecture(8,9)&&vfgNativeArchitecture(12,0)&&vfgNativeArchitecture(12,1),"40/50 native paths preserved");+ check(!vfgAmpereArchitecture(8,0)&&!vfgNativeArchitecture(8,0)&&!vfgAmpereArchitecture(7,5),"unsupported GPU does not gain VFG");+ check(vfgReportedAttribute(6,76,2,2,0)==9,"selected SM86 minor reports9 only inside VFG");+ check(vfgReportedAttribute(6,76,1,2,0)==6,"other device retains its real attribute");+ check(vfgReportedAttribute(8,75,2,2,0)==8&&vfgReportedAttribute(6,76,2,2,1)==6,"major and failed calls untouched");+ check(vfgReportedAttribute(0,76,2,2,0)==0&&vfgReportedAttribute(9,76,2,2,0)==9,"native device minor unchanged");+ check(vfgRetargetContext(2,2,0)&&!vfgRetargetContext(1,2,0)&&!vfgRetargetContext(2,2,3),"only selected GPU current context may retarget kernels");+ std::vector<std::byte> out;VfgFatbinChanges stats;std::string why;+ const auto input=fatbin(),original=input;+ check(retargetVfgFatbin(input,out,stats,why)&&stats.containers==1&&stats.elfFlags==1,"retarget valid SM89 CUDA ELF");+ check(input==original&&get<uint32_t>(out.data(),44)==86&&get<uint32_t>(out.data(),128)==0x00560556,"source immutable, copy retargeted");+ bool exact=true;for(size_t i=0;i<input.size();++i)if(!(i>=44&&i<48)&&!(i>=128&&i<132)&&input[i]!=out[i])exact=false;+ check(exact,"kernel instructions and all unrelated bytes unchanged");+ for(auto sm:{86u,120u}){const auto native=fatbin(sm,0x00560556);check(retargetVfgFatbin(native,out,stats,why)&&!stats.containers&&out==native,"non-SM89 entries stay exact");}+ for(size_t n=0;n<input.size();++n)check(!retargetVfgFatbin({input.data(),n},out,stats,why)&&out.empty(),"truncated container rejected without output");+ for(size_t offset:{size_t(0),size_t(4),size_t(6),size_t(8),size_t(16),size_t(18),size_t(20),size_t(24),size_t(80),size_t(84),size_t(85),size_t(98),size_t(128)}){+ auto broken=input;broken[offset]^=std::byte{0xFF};check(!retargetVfgFatbin(broken,out,stats,why)&&out.empty(),"unknown header/size/ELF rejected");}+ auto image=mappedPe();std::array<uint32_t,2> imports{};+ check(findVfgCudaImports(image,imports,why)&&imports==std::array<uint32_t,2>{0x500,0x508},"named import discovery independent of address");+ for(size_t n:{size_t(0),size_t(63),size_t(127),size_t(512),size_t(2048)})check(!findVfgCudaImports({image.data(),n},imports,why),"truncated mapped PE rejected");+ auto broken=image;set<uint64_t>(broken,0x408,0x600);check(!findVfgCudaImports(broken,imports,why),"duplicate import rejected");+ broken=image;set<uint64_t>(broken,0x408,UINT64_MAX);check(!findVfgCudaImports(broken,imports,why),"missing required named import rejected");+ broken=image;set<uint32_t>(broken,0x200+offsetof(IMAGE_IMPORT_DESCRIPTOR,FirstThunk),0x501);check(!findVfgCudaImports(broken,imports,why),"unaligned pointer rejected");+ auto kernel=GetModuleHandleW(L"kernel32.dll");VfgAmpereCompat unknown;+ check(!unknown.install(kernel,kernel,0,why)&&!unknown.installed(),"unrecognized runtime never patched");+ if(argc==2){+ const std::filesystem::path file=argv[1];+ auto module=LoadLibraryExW(file.c_str(),nullptr,LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR|LOAD_LIBRARY_SEARCH_SYSTEM32);+ check(module!=nullptr,"load existing audited VFG runtime");if(!module)return 2;+ auto* base=reinterpret_cast<const std::byte*>(module);+ const auto* dos=reinterpret_cast<const IMAGE_DOS_HEADER*>(module);+ const auto* nt=reinterpret_cast<const IMAGE_NT_HEADERS64*>(base+dos->e_lfanew);+ check(findVfgCudaImports({base,nt->OptionalHeader.SizeOfImage},imports,why),"discover real SDK CUDA imports");+ std::array<void*,2> saved{};std::array<DWORD,2> protections{};+ for(size_t i=0;i<2;++i){saved[i]=*reinterpret_cast<void*const*>(base+imports[i]);MEMORY_BASIC_INFORMATION page{};VirtualQuery(base+imports[i],&page,sizeof(page));protections[i]=page.Protect;}+ const auto* section=IMAGE_FIRST_SECTION(nt);unsigned bins=0,patches=0;+ for(unsigned i=0;i<nt->FileHeader.NumberOfSections;++i){+ if(std::memcmp(section[i].Name,".data",5))continue;+ const size_t begin=section[i].VirtualAddress,end=begin+section[i].Misc.VirtualSize;+ for(size_t p=begin;p+16<end;++p)if(get<uint32_t>(base,p)==0xBA55ED50){+ const auto bytes=get<uint64_t>(base,p+8)+16;if(bytes>end-p)continue;+ std::vector<std::byte> snapshot(base+p,base+p+size_t(bytes));+ const bool okay=retargetVfgFatbin(snapshot,out,stats,why);+ check(okay&&stats.containers==1&&stats.elfFlags==1,"real kernel metadata copy validates");+ check(std::memcmp(base+p,snapshot.data(),snapshot.size())==0,"real mapped kernel original immutable");+ patches+=stats.containers;++bins;p+=size_t(bytes)-1;+ }+ }+ check(bins==62&&patches==62,"all62 existing VFG fatbins retarget in private copies");+ auto driver=GetModuleHandleW(L"nvcuda.dll");check(driver!=nullptr,"SDK imports system CUDA driver");+ for(unsigned round=0;round<3;++round){+ VfgAmpereCompat first,second,other;+ check(first.install(module,driver,0,why),"install exact module import lease (no SDK inference)");+ check(second.install(module,driver,0,why),"same device shares lease");+ check(!other.install(module,driver,1,why),"other device cannot replace active scope");+ check(*reinterpret_cast<void*const*>(base+imports[0])!=saved[0],"real IAT changed");+ check(first.reset(),"first lease releases without detaching shared hooks");+ check(*reinterpret_cast<void*const*>(base+imports[0])!=saved[0],"second lease retains hook");+ check(second.reset(),"final lease restores imports and protection");+ for(size_t i=0;i<2;++i){check(*reinterpret_cast<void*const*>(base+imports[i])==saved[i],"real import exactly restored");+ MEMORY_BASIC_INFORMATION page{};check(VirtualQuery(base+imports[i],&page,sizeof(page))&&page.Protect==protections[i],"real import page protection exactly restored");}+ }+ check(!VfgAmpereCompat::restoreUncertain(),"no uncertain restoration");FreeLibrary(module);+ std::printf("Real module metadata/IAT only, not Ampere GPU execution. fatbins=%u\n",bins);+ }+ std::printf("VFG Ampere: %u checks %u failures\n",checks,failed);return failed?1:0;+}