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++

feat: integrate RTX Video HDR in shared graph and Main10 export

Veyra Goal Agent3477ed2757e9
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7120fa3f..94c27d08 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -127,7 +127,8 @@ add_library(veyra_ngx STATIC
src/ngx/NgxCoreHost.cpp
src/ngx/DlssNrRuntimeAdapter.cpp
src/ngx/DlssSrBackend.cpp
- src/ngx/VideoSrBackend.cpp
+ src/ngx/VideoSrBackend.cpp
+ src/ngx/TrueHdrBackend.cpp
src/ngx/DlssFgBackend.cpp
src/ngx/FgCompatibilitySession.cpp
src/ngx/compat/hde/hde64.c
@@ -784,6 +785,10 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avform
target_compile_definitions(veyra_multichannel_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
target_link_libraries(veyra_multichannel_tests PRIVATE veyra_engine)
add_executable(veyra_hdr_enhancement_tests tests/integration/HdrEnhancementTests.cpp)
+ add_executable(veyra_video_hdr_tests tests/integration/VideoHdrTests.cpp)
+ target_compile_features(veyra_video_hdr_tests PRIVATE cxx_std_20)
+ target_compile_definitions(veyra_video_hdr_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
+ target_link_libraries(veyra_video_hdr_tests PRIVATE veyra_engine)
target_compile_features(veyra_hdr_enhancement_tests PRIVATE cxx_std_20)
target_compile_definitions(veyra_hdr_enhancement_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
target_link_libraries(veyra_hdr_enhancement_tests PRIVATE veyra_engine)
@@ -907,6 +912,8 @@ endif()
# Layered child subtitle windows require a modern-Windows compatibility manifest.
configure_file(apps/veyra/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/veyra-version.rc @ONLY)
+configure_file(apps/veyra/resource.h ${CMAKE_CURRENT_BINARY_DIR}/veyra-resource.h COPYONLY)
+configure_file(assets/veyra.ico ${CMAKE_CURRENT_BINARY_DIR}/veyra.ico COPYONLY)
target_sources(veyra PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/veyra-version.rc)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/veyra-version.rc PROPERTIES
OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/assets/veyra.ico;${CMAKE_CURRENT_SOURCE_DIR}/apps/veyra/resource.h")
diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md
index a3d634fa..984be2dd 100644
--- a/THIRD_PARTY_NOTICES.md
+++ b/THIRD_PARTY_NOTICES.md
@@ -301,6 +301,20 @@ Veyra 的差异(非上游代码):输入不是 AVFrame,而是 Veyra 自
MP4 封装路径。MFT 本身属于 Windows 与显卡驱动,不随包分发。FFmpeg 采用
LGPL-2.1-or-later,与 Veyra 的 GPLv3 兼容;上游作者归属见上。
+## RTX Video HDR (local integration, 2026-09-18)
+
+`src/ngx/TrueHdrBackend.cpp` independently implements the NVIDIA RTX Video SDK
+1.1.0 D3D12 parameter contract. Parameter defaults and behavior were compared with
+rigaya/NVEnc, MIT, commit `4cb3101f451e3f932334c994323e743808502995`:
+https://github.com/rigaya/NVEnc/tree/4cb3101f451e3f932334c994323e743808502995 .
+No NVEnc CUDA implementation or NVIDIA SDK source is vendored here.
+
+Local runtime: `nvngx_truehdr.dll`, 1.1.0.0, 3955752 bytes, NVIDIA Authenticode
+Valid, SHA256 `9A80575F247190C05FE80EAC0C4BAA1D0D4D932348F26808310B5EC4BF9EEB4B`.
+This runtime retains the NVIDIA RTX Video SDK license; it is not relicensed under
+Veyra's GPL. SDK/license and runtime remain external. This change does not publish
+or grant redistribution of a new runtime pack.
+
## dav1d (1.3.0 AV1 playback)
FFmpeg dynamically links dav1d 1.5.4 from the pinned local vcpkg build. The portable package includes its complete aggregated copyright/license text in `licenses/DAV1D-COPYRIGHT.txt` and provenance in `licenses/DAV1D-SPDX.json`. The FFmpeg corresponding-source ZIP includes dav1d source and its vcpkg port. Upstream: https://code.videolan.org/videolan/dav1d . License set recorded by the build: Apache-2.0, BSD-2-Clause, ISC and MIT; retain all notices supplied with the source.
diff --git a/apps/veyra/SettingsWindow.cpp b/apps/veyra/SettingsWindow.cpp
index b52802e5..4e4b873b 100644
--- a/apps/veyra/SettingsWindow.cpp
+++ b/apps/veyra/SettingsWindow.cpp
@@ -912,6 +912,9 @@ void populate(engine::EnhancementSettings s){
send(508,CB_SETCURSEL,int(engine::exportBitrateIndex(s.exportBitrateMbps)),0);
send(218,CB_SETCURSEL,int(s.nrRuntime));
check(219,s.captureCompatible?BST_CHECKED:BST_UNCHECKED);check(220,s.lowLatency?BST_CHECKED:BST_UNCHECKED);
+ check(230,enhancementEnabled&&s.videoHdr.enabled?BST_CHECKED:BST_UNCHECKED);
+ const unsigned hdrValues[]={s.videoHdr.contrast,s.videoHdr.saturation,s.videoHdr.middleGray,s.videoHdr.peakNits};
+ for(int i=0;i<4;++i){send(631+i,TBM_SETPOS,TRUE,hdrValues[i]);putText(1131+i,(std::to_wstring(hdrValues[i])+(i==3?L" nit":L"")).c_str());}
send(204,CB_SETCURSEL,int(s.flow),0);send(205,CB_SETCURSEL,int(s.content),0);
send(209,CB_SETCURSEL,int(s.opticalFlowBackend),0);
check(215,s.amdFlowHalfResolution?BST_CHECKED:BST_UNCHECKED);
@@ -968,6 +971,10 @@ bool liveField(int id){
case 208:{s.frameGenerationBackend=static_cast<engine::FrameGenerationBackend>(send(id,CB_GETCURSEL));if(engine::presentSinkFrameGeneration(s.frameGenerationBackend)){const int choices=multiplierChoiceCount(s.frameGenerationBackend);const size_t index=size_t(std::clamp(choices-1,1,int(engine::kFgMultiplierChoiceCount)-1));s.multiplier=std::min(s.multiplier,engine::kFgMultiplierChoices[index]);}break;}
case 209:s.opticalFlowBackend=static_cast<engine::OpticalFlowBackend>(send(id,CB_GETCURSEL));break;
case 220:s.lowLatency=checked(id)==BST_CHECKED;break;
+ case 631:s.videoHdr.contrast=unsigned(send(id,TBM_GETPOS));break;
+ case 632:s.videoHdr.saturation=unsigned(send(id,TBM_GETPOS));break;
+ case 633:s.videoHdr.middleGray=unsigned(send(id,TBM_GETPOS));break;
+ case 634:s.videoHdr.peakNits=unsigned(send(id,TBM_GETPOS));break;
case 215:s.amdFlowHalfResolution=checked(id)==BST_CHECKED;break;
case 216:s.audioSync=static_cast<engine::AudioSyncMode>(send(id,CB_GETCURSEL));break;
case 217:{wchar_t value[32]{};GetWindowTextW(item(id),value,32);wchar_t* end=nullptr;const auto parsed=wcstol(value,&end,10);if(end==value||*end||parsed<-250||parsed>250){message(L"声音偏移须为 -250 至 250 ms");return false;}s.audioOffsetMs=int(parsed);break;}
@@ -1105,6 +1112,8 @@ void combo(int id,int group,int y,std::initializer_list<const wchar_t*> names){a
LRESULT CALLBACK proc(HWND h,UINT msg,WPARAM wp,LPARAM lp){
if(msg==WM_COMMAND&&LOWORD(wp)==221&&HIWORD(wp)==BN_CLICKED){smoothMotionHelpExpanded=!smoothMotionHelpExpanded;putText(221,smoothMotionHelpExpanded?L"Smooth Motion · 收起说明 ▴":L"Smooth Motion · 开启方法 ▾");arrange();return 0;}
if(msg==WM_COMMAND&&!populating&&LOWORD(wp)==220&&HIWORD(wp)==BN_CLICKED){liveField(220);return 0;}
+ if(msg==WM_COMMAND&&!populating&&LOWORD(wp)==230&&HIWORD(wp)==BN_CLICKED){SendMessageW(GetParent(window),WM_APP+44,230,checked(230));return 0;}
+ if(msg==WM_HSCROLL&&!populating&&lp){const auto id=GetDlgCtrlID(reinterpret_cast<HWND>(lp));if(id>=631&&id<=634){liveField(id);return 0;}}
if(msg==WM_COMMAND&&!populating&&LOWORD(wp)==219&&HIWORD(wp)==BN_CLICKED){liveField(219);return 0;}
if(msg==WM_COMMAND&&!populating&&LOWORD(wp)==218&&HIWORD(wp)==CBN_SELCHANGE){liveField(218);return 0;}
if(msg==WM_COMMAND&&!populating&&((LOWORD(wp)==216&&HIWORD(wp)==CBN_SELCHANGE)||(LOWORD(wp)==217&&HIWORD(wp)==EN_CHANGE))){liveField(LOWORD(wp));return 0;}
@@ -1512,6 +1521,18 @@ case WM_CREATE:{window=h;font=makeFont(h);items.clear();displayedBackendWarning.
SendMessageW(featherSlider,TBM_SETPOS,TRUE,12);
SetPropW(item(222),L"veyra.tip",HANDLE(L"剔除区边缘的过渡宽度,单位是工作分辨率像素。0 就是硬边;4K 上 12 px 约等于画面高度的 0.5%,越大边缘越柔和。"));
for(const auto& entry:items)if(auto help=settingHelp(GetDlgCtrlID(entry.h)))SetPropW(entry.h,L"veyra.tip",HANDLE(help));
+ int hdrTop=0;for(const auto& entry:items)if(entry.page==0)hdrTop=std::max(hdrTop,entry.y+entry.height);
+ hdrTop+=24;
+ add(L"BUTTON",L"RTX Video HDR",230,BS_AUTOCHECKBOX|WS_TABSTOP,0,12,hdrTop,-1,32);
+ SetPropW(item(230),L"veyra.tip",HANDLE(L"将 SDR 视频转换成 HDR;预览需要 Windows HDR 显示,导出不受显示模式影响。原生 HDR 不重复转换。"));
+ const wchar_t* hdrLabels[]={L"对比度",L"饱和度",L"中间灰",L"峰值亮度"};
+ const int hdrMin[]={0,0,10,400},hdrMax[]={200,200,100,2000};
+ for(int i=0;i<4;++i){const int y=hdrTop+40+i*58;
+ add(L"STATIC",hdrLabels[i],1141+i,0,0,12,y,160,24);
+ add(L"STATIC",L"",1131+i,SS_RIGHT,0,182,y,-1,24);
+ auto slider=add(TRACKBAR_CLASSW,L"",631+i,TBS_HORZ|TBS_NOTICKS|WS_TABSTOP,0,12,y+26,-1,24);
+ SendMessageW(slider,TBM_SETRANGE,TRUE,MAKELPARAM(hdrMin[i],hdrMax[i]));
+ }
loadStore();populate(controller->snapshot().desired);message(store.error());SetTimer(h,1,250,nullptr);arrange();
// Layout evidence for UI work: VEYRA_DUMP_SETTINGS_LAYOUT=1 prints the
// resolved position of every control once, in DIP units.
diff --git a/apps/veyra/ui/AppShell.cpp b/apps/veyra/ui/AppShell.cpp
index b8cb8b49..a3e915bd 100644
--- a/apps/veyra/ui/AppShell.cpp
+++ b/apps/veyra/ui/AppShell.cpp
@@ -516,7 +516,7 @@ case WM_SYSCOMMAND:
const auto s=engine.snapshot();
if(s.running&&!s.failed&&!s.image&&s.transport==veyra::engine::TransportState::Playing)return 0;
}break;
-case WM_CREATE:{mainWindow=hwnd;backdrop.attach(hwnd);font=veyra::ui::makeFont(hwnd);veyra::ui::titleTheme(hwnd);uiState.configured=initialOptions.snapshot();uiState.enhanced=uiPreferences.enhancementEnabled<0?(initialOptions.nr||initialOptions.sr||initialOptions.fg):uiPreferences.enhancementEnabled!=0;
+case WM_CREATE:{mainWindow=hwnd;backdrop.attach(hwnd);font=veyra::ui::makeFont(hwnd);veyra::ui::titleTheme(hwnd);uiState.configured=initialOptions.snapshot();uiState.enhanced=uiPreferences.enhancementEnabled<0?(initialOptions.nr||initialOptions.sr||initialOptions.fg||initialOptions.settings.videoHdr.enabled):uiPreferences.enhancementEnabled!=0;
engine.requestSettings(uiState.effective());
#ifdef VEYRA_ENABLE_REMOTEPLAY
control(L"BUTTON",L"PS5",RemotePlay,BS_PUSHBUTTON,0,0,56,28);veyra::ui::ghost(GetDlgItem(hwnd,RemotePlay));SetPropW(GetDlgItem(hwnd,RemotePlay),L"veyra.tip",HANDLE(L"PS5 串流 · 配对与连接"));
@@ -592,8 +592,8 @@ case WM_APP+45:{if(masterPendingRevision)return 0;auto settings=uiState.enhanced
if(wp==213){auto current=engine.snapshot();if(uiState.mode!=veyra::ui::Mode::Professional||!current.running||!current.frames)return 0;bool space=false;for(auto q:settings.protection.regions)space|=q.empty();if(!space)return 0;cancelProtection();protectionArmed=true;SetFocus(video);return 1;}
if(wp==214){cancelProtection();settings.protection={};}else if(wp==206)settings.protection.enabled=lp==BST_CHECKED;else if(wp==222)settings.protection.featherPixels=float(std::clamp(int(lp),0,64));else return 0;
return applySettings(settings)?1:0;}
-case WM_APP+44:{if(masterPendingRevision)return 0;auto setting=uiState.enhanced?engine.snapshot().desired:uiState.configured;const bool enabled=wp==202?lp>1:lp==BST_CHECKED;if(wp==200)setting.nr=enabled;else if(wp==201)setting.sr=enabled;else if(wp==202){bool allowed=false;for(auto m:veyra::engine::kFgMultiplierChoices)if(uint32_t(lp)==m)allowed=true;if(!allowed)return 0;setting.multiplier=uint32_t(lp);if(!setting.validate().empty())return 0;}else return 0;
- const bool enablesMaster=enabled&&!uiState.enhanced;if(enablesMaster){masterPreviousEnabled=false;uiState.enhanced=true;}applySettings(setting);if(auto pending=engine.snapshot();enablesMaster&&pending.running){masterPendingRevision=pending.desired.revision;masterPendingSession=pending.sessionId;}veyra::log::info("ui-feature",std::format("click={} enabled={} requestedRevision={} draft-independent=true",wp==200?"NR":wp==201?"SR":"FG",enabled,engine.snapshot().desired.revision));return 1;}
+case WM_APP+44:{if(masterPendingRevision)return 0;auto setting=uiState.enhanced?engine.snapshot().desired:uiState.configured;const bool enabled=wp==202?lp>1:lp==BST_CHECKED;if(wp==200)setting.nr=enabled;else if(wp==201)setting.sr=enabled;else if(wp==230)setting.videoHdr.enabled=enabled;else if(wp==202){bool allowed=false;for(auto m:veyra::engine::kFgMultiplierChoices)if(uint32_t(lp)==m)allowed=true;if(!allowed)return 0;setting.multiplier=uint32_t(lp);if(!setting.validate().empty())return 0;}else return 0;
+ const bool enablesMaster=enabled&&!uiState.enhanced;if(enablesMaster){masterPreviousEnabled=false;uiState.enhanced=true;}applySettings(setting);if(auto pending=engine.snapshot();enablesMaster&&pending.running){masterPendingRevision=pending.desired.revision;masterPendingSession=pending.sessionId;}veyra::log::info("ui-feature",std::format("click={} enabled={} requestedRevision={} draft-independent=true",wp==200?"NR":wp==201?"SR":wp==230?"VideoHDR":"FG",enabled,engine.snapshot().desired.revision));return 1;}
case WM_APP+43:showDiagnostics=false;layout();return 0;
case WM_APP+41:switch(wp){case 501:startVideoExport(lp!=0);break;case 502:{auto path=fileDialog(true);if(!path.empty())engine.saveFrame(path);break;}case 503:jobPaused=!jobPaused;exportJob.pause(jobPaused);break;case 504:exportJob.cancel();break;case 505:preferWatching=lp==BST_CHECKED;break;}return 0;
case WM_SIZE:cancelProtection();if(wp!=SIZE_MINIMIZED){endTransition();layout();}return 0;
@@ -1090,7 +1090,7 @@ SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);INITCO
CoInitializeEx(nullptr,COINIT_APARTMENTTHREADED);
initialOptions=veyra::engine::PlayerOptions::from(veyra::ui::defaultSettings());
-int argc=0;auto argv=CommandLineToArgvW(GetCommandLineW(),&argc);for(int i=1;i<argc;++i){const std::wstring arg=argv[i];if(arg==L"--export-worker"&&i+1<argc)workerMapping=reinterpret_cast<HANDLE>(_wcstoui64(argv[++i],nullptr,10));else if(arg==L"--smoke-view"&&i+1<argc)smokeView=argv[++i];else if(arg==L"--smoke-fg-only")smokeFgOnly=true;else if(arg==L"--smoke-transport")smokeTransport=true;else if(arg==L"--smoke-repair-ui")smokeRepair=true;else if(arg==L"--smoke-repair-ui-reject")smokeRepair=smokeRepairReject=true;else if(arg==L"--smoke-hover")smokeZoom=smokeHover=true;else if(arg==L"--smoke-protection")smokeProtection=true;else if(arg==L"--smoke-zoom")smokeZoom=true;else if(arg==L"--smoke-empty")smokeEmpty=true;else if(arg==L"--smoke-dual")smokeDual=true;else if(arg==L"--smoke-dual-pause"){smokeDual=smokeDualPause=true;}else if(arg==L"--smoke-master-reject")smokeMaster=smokeMasterReject=true;else if(arg==L"--smoke-master")smokeMaster=true;else if(arg==L"--smoke-audio")smokeAudio=true;else if(arg==L"--smoke-job-cancel")smokeJobCancel=true;else if(arg==L"--smoke-job-exit")smokeJobExit=true;else if(arg==L"--smoke-job")smokeJob=true;else if(arg==L"--smoke-dual-export"&&i+1<argc)smokeDualOutput=argv[++i];else if(arg==L"--smoke-seconds"&&i+1<argc)smokeSeconds=std::clamp(_wtoi(argv[++i]),1,240);else if(arg==L"--export-out"&&i+1<argc)exportOutput=argv[++i];else if(arg==L"--max-frames"&&i+1<argc)exportFrames=std::max(1,_wtoi(argv[++i]));else if(arg==L"--cancel-after-ms"&&i+1<argc)cancelAfterMs=std::clamp(_wtoi(argv[++i]),1,240000);else if(arg==L"--hevc")exportHevc=true;else if(arg==L"--bitrate-mbps"&&i+1<argc)initialOptions.settings.exportBitrateMbps=uint32_t(std::clamp(_wtoi(argv[++i]),0,300));else if(arg==L"--subtitle-primary"&&i+1<argc)subtitleRequestPrimary=std::clamp(_wtoi(argv[++i]),-1,64);else if(arg==L"--subtitle-secondary"&&i+1<argc)subtitleRequestSecondary=std::clamp(_wtoi(argv[++i]),-1,64);else if(arg==L"--subtitle-offset-ms"&&i+1<argc)subtitleRequestOffsetMs=std::clamp(_wtoi(argv[++i]),-30000,30000);else if(arg==L"--subtitle-font-size"&&i+1<argc)subtitlePixels=std::clamp(_wtoi(argv[++i]),16,56);else if(arg==L"--subtitle-no-outline")uiState.subtitleOutline=false;else if(arg==L"--subtitle-background")uiState.subtitleBackground=true;else if(arg==L"--subtitle-auto-align")subtitleRequestAutoAlign=true;else if(arg==L"--smoke-rollback-flow"){smokeRollback=true;smokeRollbackFlow=true;}else if(arg==L"--smoke-rollback")smokeRollback=true;else if(arg==L"--smoke-ui")smokeUi=true;else if(arg==L"--no-fg")initialOptions.fg=false;else if(arg==L"--smoke-settings")smokeSettings=true;else if(arg==L"--smoke-color")smokeColor=true;else if(arg==L"--smoke-screenshot")smokeScreenshot=true;else if(arg==L"--smoke-controls")smokeControls=true;else if(arg==L"--smoke-save"&&i+1<argc)smokeSave=argv[++i];else if(arg==L"--native")initialOptions.realtime=false;else if(arg==L"--realtime")initialOptions.realtime=true;else if(arg==L"--fg")initialOptions.fg=true;else if(arg==L"--fg-multiplier"&&i+1<argc){initialOptions.fgMultiplier=std::clamp(_wtoi(argv[++i]),2,6);initialOptions.fg=true;}else if(arg==L"--capture-audio"&&i+1<argc)initialOptions.settings.captureAudio=static_cast<veyra::engine::CaptureAudioIngress>(std::clamp(_wtoi(argv[++i]),0,2));else if(arg==L"--flow-amd")initialOptions.settings.opticalFlowBackend=veyra::engine::OpticalFlowBackend::AmdFidelityFx;else if(arg==L"--flow-gpudis")initialOptions.settings.opticalFlowBackend=veyra::engine::OpticalFlowBackend::GpuDis;else if(arg==L"--video-sr"&&i+1<argc){initialOptions.settings.videoSrQuality=std::clamp(_wtoi(argv[++i]),1,5);initialOptions.sr=true;}else if(arg==L"--nr-ampere")initialOptions.settings.nrRuntime=veyra::engine::NrRuntime::Ampere;else if(arg==L"--nr-community")initialOptions.settings.nrRuntime=veyra::engine::NrRuntime::Community;else if(arg==L"--nr-original")initialOptions.settings.nrRuntime=veyra::engine::NrRuntime::Original;else if(arg==L"--sr")initialOptions.sr=true;else if(arg==L"--no-nr")initialOptions.nr=false;else if(arg==L"--nr")initialOptions.nr=true;else if(arg==L"--no-sr")initialOptions.sr=false;else autoInput=arg;}LocalFree(argv);
+int argc=0;auto argv=CommandLineToArgvW(GetCommandLineW(),&argc);for(int i=1;i<argc;++i){const std::wstring arg=argv[i];if(arg==L"--export-worker"&&i+1<argc)workerMapping=reinterpret_cast<HANDLE>(_wcstoui64(argv[++i],nullptr,10));else if(arg==L"--smoke-view"&&i+1<argc)smokeView=argv[++i];else if(arg==L"--smoke-fg-only")smokeFgOnly=true;else if(arg==L"--smoke-transport")smokeTransport=true;else if(arg==L"--smoke-repair-ui")smokeRepair=true;else if(arg==L"--smoke-repair-ui-reject")smokeRepair=smokeRepairReject=true;else if(arg==L"--smoke-hover")smokeZoom=smokeHover=true;else if(arg==L"--smoke-protection")smokeProtection=true;else if(arg==L"--smoke-zoom")smokeZoom=true;else if(arg==L"--smoke-empty")smokeEmpty=true;else if(arg==L"--smoke-dual")smokeDual=true;else if(arg==L"--smoke-dual-pause"){smokeDual=smokeDualPause=true;}else if(arg==L"--smoke-master-reject")smokeMaster=smokeMasterReject=true;else if(arg==L"--smoke-master")smokeMaster=true;else if(arg==L"--smoke-audio")smokeAudio=true;else if(arg==L"--smoke-job-cancel")smokeJobCancel=true;else if(arg==L"--smoke-job-exit")smokeJobExit=true;else if(arg==L"--smoke-job")smokeJob=true;else if(arg==L"--smoke-dual-export"&&i+1<argc)smokeDualOutput=argv[++i];else if(arg==L"--smoke-seconds"&&i+1<argc)smokeSeconds=std::clamp(_wtoi(argv[++i]),1,240);else if(arg==L"--export-out"&&i+1<argc)exportOutput=argv[++i];else if(arg==L"--max-frames"&&i+1<argc)exportFrames=std::max(1,_wtoi(argv[++i]));else if(arg==L"--cancel-after-ms"&&i+1<argc)cancelAfterMs=std::clamp(_wtoi(argv[++i]),1,240000);else if(arg==L"--hevc")exportHevc=true;else if(arg==L"--bitrate-mbps"&&i+1<argc)initialOptions.settings.exportBitrateMbps=uint32_t(std::clamp(_wtoi(argv[++i]),0,300));else if(arg==L"--subtitle-primary"&&i+1<argc)subtitleRequestPrimary=std::clamp(_wtoi(argv[++i]),-1,64);else if(arg==L"--subtitle-secondary"&&i+1<argc)subtitleRequestSecondary=std::clamp(_wtoi(argv[++i]),-1,64);else if(arg==L"--subtitle-offset-ms"&&i+1<argc)subtitleRequestOffsetMs=std::clamp(_wtoi(argv[++i]),-30000,30000);else if(arg==L"--subtitle-font-size"&&i+1<argc)subtitlePixels=std::clamp(_wtoi(argv[++i]),16,56);else if(arg==L"--subtitle-no-outline")uiState.subtitleOutline=false;else if(arg==L"--subtitle-background")uiState.subtitleBackground=true;else if(arg==L"--subtitle-auto-align")subtitleRequestAutoAlign=true;else if(arg==L"--smoke-rollback-flow"){smokeRollback=true;smokeRollbackFlow=true;}else if(arg==L"--smoke-rollback")smokeRollback=true;else if(arg==L"--smoke-ui")smokeUi=true;else if(arg==L"--video-hdr")initialOptions.settings.videoHdr.enabled=true;else if(arg==L"--no-fg")initialOptions.fg=false;else if(arg==L"--smoke-settings")smokeSettings=true;else if(arg==L"--smoke-color")smokeColor=true;else if(arg==L"--smoke-screenshot")smokeScreenshot=true;else if(arg==L"--smoke-controls")smokeControls=true;else if(arg==L"--smoke-save"&&i+1<argc)smokeSave=argv[++i];else if(arg==L"--native")initialOptions.realtime=false;else if(arg==L"--realtime")initialOptions.realtime=true;else if(arg==L"--fg")initialOptions.fg=true;else if(arg==L"--fg-multiplier"&&i+1<argc){initialOptions.fgMultiplier=std::clamp(_wtoi(argv[++i]),2,6);initialOptions.fg=true;}else if(arg==L"--capture-audio"&&i+1<argc)initialOptions.settings.captureAudio=static_cast<veyra::engine::CaptureAudioIngress>(std::clamp(_wtoi(argv[++i]),0,2));else if(arg==L"--flow-amd")initialOptions.settings.opticalFlowBackend=veyra::engine::OpticalFlowBackend::AmdFidelityFx;else if(arg==L"--flow-gpudis")initialOptions.settings.opticalFlowBackend=veyra::engine::OpticalFlowBackend::GpuDis;else if(arg==L"--video-sr"&&i+1<argc){initialOptions.settings.videoSrQuality=std::clamp(_wtoi(argv[++i]),1,5);initialOptions.sr=true;}else if(arg==L"--nr-ampere")initialOptions.settings.nrRuntime=veyra::engine::NrRuntime::Ampere;else if(arg==L"--nr-community")initialOptions.settings.nrRuntime=veyra::engine::NrRuntime::Community;else if(arg==L"--nr-original")initialOptions.settings.nrRuntime=veyra::engine::NrRuntime::Original;else if(arg==L"--sr")initialOptions.sr=true;else if(arg==L"--no-nr")initialOptions.nr=false;else if(arg==L"--nr")initialOptions.nr=true;else if(arg==L"--no-sr")initialOptions.sr=false;else autoInput=arg;}LocalFree(argv);
// Diagnostic: force the colour grade on with a fixed exposure (EV). The grade is
// fused into the ingest dispatch, so this flag is how the graded cost is measured
// against the grade-off baseline on the same clip.
diff --git a/apps/veyra/ui/UiSessionState.h b/apps/veyra/ui/UiSessionState.h
index c2f36677..478ca304 100644
--- a/apps/veyra/ui/UiSessionState.h
+++ b/apps/veyra/ui/UiSessionState.h
@@ -12,7 +12,7 @@ struct UiSessionState {
engine::EnhancementSettings configured;
// An explicit user toggle creates a settings transaction. Mode changes do
// not call this function and cannot change enhancement configuration.
- engine::EnhancementSettings effective()const{auto result=configured;if(!enhanced){result.nr=false;result.sr=false;result.multiplier=1;}return result;}
+ engine::EnhancementSettings effective()const{auto result=configured;if(!enhanced){result.nr=false;result.sr=false;result.multiplier=1;result.videoHdr.enabled=false;}return result;}
};
struct WorkspaceGeometry {
int width,height,header=52,bottom=96,rail=0,inspector=0,diagnostics=0;
diff --git a/apps/veyra/version.rc.in b/apps/veyra/version.rc.in
index e2c55ca9..78fba979 100644
--- a/apps/veyra/version.rc.in
+++ b/apps/veyra/version.rc.in
@@ -1,6 +1,6 @@
#include <windows.h>
-#include "@CMAKE_CURRENT_SOURCE_DIR@/apps/veyra/resource.h"
-IDI_VEYRA ICON "@CMAKE_CURRENT_SOURCE_DIR@/assets/veyra.ico"
+#include "veyra-resource.h"
+IDI_VEYRA ICON "veyra.ico"
VS_VERSION_INFO VERSIONINFO
FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,0
PRODUCTVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,0
diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md
index 14e48db0..7c8bfbae 100644
--- a/docs/CURRENT_STATUS.md
+++ b/docs/CURRENT_STATUS.md
@@ -20,8 +20,8 @@
- 存档提交 `0e3d4ac`,标签 `checkpoint/pre-video-hdr-fsr41-20260918`。
- 隔离分支 `codex/video-hdr-20260918`;工作区 `E:/项目/Veyra/worktrees/video-hdr-20260918`。
-- RTX Video HDR 使用官方本地 SDK 1.1.0;新功能尚未通过 Create/Evaluate、颜色及导出验证。
-- NVIDIA FSR 4.1.1 使用固定提交的 INT8 研究 provider,尚未构建验证;不是 AMD 官方 NVIDIA 支持,不默认开放 UI。
+- RTX Video HDR 已接入共享图、设置和 Main10 导出;RTX 5070 / 616.56 上 Create/Evaluate、2X/4X/6X、NR+SR+6X、原生 HDR 回归、HDR 导出与缺库 SDR 回退通过。显示器 HDR 当前未开启,实际 HDR 显示、采集卡、PS5 与 RTX 30/40 未执行。
+- NVIDIA FSR 4.1.1 固定提交的 INT8 研究 provider 已构建,五个导出符号与 CPU 查询通过;GPU 接入尚未执行。上游三槽资源复用及私有队列 reset 需要适配,不默认开放 UI。
- 本轮无 push、Release 或新增运行库发布授权。
所有新产物放 `E:/项目/Veyra/`,源码/文档留在隔离工作区;逐项结果以 [WORKLOG](WORKLOG.md) 为准。
diff --git a/docs/VIDEO_HDR_FSR41_EXECUTION_PLAN_2026-09-18.md b/docs/VIDEO_HDR_FSR41_EXECUTION_PLAN_2026-09-18.md
index 71b021b3..7208157c 100644
--- a/docs/VIDEO_HDR_FSR41_EXECUTION_PLAN_2026-09-18.md
+++ b/docs/VIDEO_HDR_FSR41_EXECUTION_PLAN_2026-09-18.md
@@ -176,4 +176,8 @@ FSR 4.1 实验不修改 NVAPI 伪装、DLSS MFG 解锁或现有 FG 调度;这
## 执行记录
-2026-09-18:已建立存档、隔离分支与 Goal,先刷新文档。尚未修改运行代码、加载 `nvngx_truehdr.dll`、构建 TrueHDR/FSR4 provider 或执行 Create/Evaluate、画质、性能、导出及硬件验证。下一步为 A1/A2。
+2026-09-18:已完成文档刷新及 Video HDR 首轮实现。最终颜色路线选择 RGBA8 SDR -> TrueHDR FP16 scRGB(1=80 nit)-> 既有 HDR sink,非直接 PQ 输出。共用图、live 参数、schema 20 保存、请求/生效状态、SDR 显示回退、HEVC Main10 导出已接入。
+
+RTX 5070 / 616.56:Create/Evaluate/Release 0x1、SEH 0;HDR 独立、2X/4X/6X、NR+DLSS SR+6X、原生 HDR 回归通过。90 帧导出为 Main10/P010 等价编码、BT.2020/PQ,开发期 ffprobe/解码通过;移走 TrueHDR 后导出 SDR 通过。预设 roundtrip/迁移通过。实际 HDR 显示(当前 Windows HDR 未开启)、跨屏、物理采集、PS5 和 RTX 30/40 未执行,不据离屏测试宣称全链路实卡验收。
+
+FSR provider 已从固定上游提交在外部目录生成/构建,CPU smoke 通过,尚无 GPU 结果。发现三组 CBV/descriptor 的生命周期不能覆盖 Veyra command ring,以及 reset 使用私有队列;B 阶段先修这些合同。命令、数据和路径见 WORKLOG。
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index e79de712..5ffbaf6b 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -1,5 +1,26 @@
# Veyra 工作记录
+## 2026-09-18 Video HDR 共享图实现与 RTX 5070 验证
+
+新增 TrueHdrBackend、VideoHdrSettings、VideoHdrTests 与 build-isolated.ps1;更新 EnhanceGraph 的输入/工作/输出 HDR 合同、共享 graph/恢复/状态、Presenter SDR 对比白位、设置页与 schema 20、Main10 导出、CMake/资源脚本和导出探针。TrueHDR 在 SDR NR/SR/调色后、FG 前执行,原生 HDR 跳过;默认关闭。数值调整不重建图,开关按现有生命周期重建。新 DLL 仅在外部构建目录,未入 Git。
+
+构建命令:`./scripts/build-isolated.ps1 -Root . -BuildDirectory E:/项目/Veyra/build/video-hdr-20260918 -DependencyCache 'C:/Users/123/Desktop/Veyra DLSS Video Player/out/build/scheduling-audit-20260918/CMakeCache.txt' -TempDirectory E:/项目/Veyra/tmp/video-hdr-20260918 -Targets veyra,veyra_video_hdr_tests,veyra_hdr_enhancement_tests,veyra_export_probe`。MSVC 2022 / SDK 26100,patched FFmpeg 沿用;build-final.log exit 0。中间编译错误(AVFrame 完整类型/测试设置/回读格式)已修正后重建。
+
+硬件 RTX 5070 / 驱动 32.0.16.1656。以下命令均 exit 0,日志目录 `E:/项目/Veyra/logs/video-hdr-20260918/`:
+
+- `veyra_repair_preset_tests.exe <tests>/presets-test.txt`:新参数 roundtrip、边界及 66 个旧格式迁移通过。
+- `veyra_video_hdr_tests.exe 1`:Available=1、NeedsUpdatedDriver=0、最低 550.0;Create/Evaluate/Release=0x1,SEH=0;参数调整后峰值 400 nit、像素变化 0.448683(gpu-hdr-only.log)。
+- `veyra_video_hdr_tests.exe 2` / `4`:生成批次与像素验证通过(gpu-hdr-fg2.log / gpu-hdr-fg4.log)。
+- `veyra_video_hdr_tests.exe 6 1 0`:NR=12、DLSS SR=12、生成批次=10;峰值 397.862 nit(gpu-hdr-nr-sr-fg6.log)。
+- `veyra_hdr_enhancement_tests.exe 2`:原生 HDR 1024 像素合同、高光与增强回归通过(native-hdr-regression.log)。
+- `veyra_export_probe.exe <tests>/sdr-pattern.mp4 <tests>/hdr-export.mp4 --video-hdr`:90 帧导出;ffprobe=HEVC Main10/yuv420p10le/limited/BT2020nc/SMPTE2084/BT2020;开发期 ffmpeg 解码 exit 0。没有加入产品导出后扫描。
+- 临时将构建目录 TrueHDR DLL 移至本任务 tmp,重复导出为 missing-hdr-fallback.mp4:exit 0、SDR 回退;finally 恢复原 DLL(export-missing-hdr.log)。
+- `veyra.exe --video-hdr --smoke-seconds 8 --smoke-view professional <source>`:90 帧,failed=false。当前显示器 HDR 未开启,此次 GUI 是 SDR 显示回退,不证明屏幕 HDR 生效(player-hdr.log)。
+
+测试图与输出在 `E:/项目/Veyra/tests/video-hdr-20260918`,临时目录仅进程 TEMP/TMP 重定向到同任务 tmp。未执行:HDR 显示器实看/跨屏、物理采集/PS5、RTX 30/40。剩余 UI 视觉、更多格式/分辨率和交互需要专项验证。下一步建立 FSR 实验分支并修正 provider 调度合同。没有 push/Release。
+
+FSR 外部预备:上游 `int3rrobang/fsr4-int8-reverse-engineering@88635b94083965a7c3b5f64e099808b8ba2ce576` 在 `E:/项目/Veyra/deps/fsr41-nvidia-20260918`。本地 AMD SDK 2.3.0 / 官方 4.1.1.2740 DLL SHA256 `D0DCCCC74A43C44BA435B7A369B456E0970D8A4464E4BD683119B374F2C9FB46`。`bench/tools/build_411_dll.py --codegen-only`、VS2022 CMake Release 构建与 `ffx411_smoke.exe <provider>` 均 exit 0;产物在 `build/fsr41-provider-20260918`,日志在 `logs/fsr41-nvidia-20260918/provider-{codegen,configure,build}.log`。这只是构建及 CPU API 检查,尚未 GPU dispatch。
+
## 2026-09-18 Video HDR / NVIDIA FSR4 隔离施工启动
用户授权存档、隔离、先更新文档并启动目标模式。main 研究文档提交 `0e3d4ac`,附注标签 `checkpoint/pre-video-hdr-fsr41-20260918`;`git worktree add` 建立 `codex/video-hdr-20260918`,路径 `E:/项目/Veyra/worktrees/video-hdr-20260918`,初始工作区干净。Goal 已启动,无推送/发布。
diff --git a/include/veyra/diagnostics/FrameMetrics.h b/include/veyra/diagnostics/FrameMetrics.h
index 5956f8d6..320b09d0 100644
--- a/include/veyra/diagnostics/FrameMetrics.h
+++ b/include/veyra/diagnostics/FrameMetrics.h
@@ -5,7 +5,7 @@
#include "veyra/pipeline/FrameBatch.h"
#include "veyra/pipeline/ResolutionPlan.h"
namespace veyra::diagnostics {
-enum class GpuStage { Color, Sr, Flow, Nr, Residual, Fg1, Fg2, Fg3, Fg4, Fg5, FgBatch, Blit, Count };
+enum class GpuStage { Color, Sr, Flow, Nr, Residual, Fg1, Fg2, Fg3, Fg4, Fg5, FgBatch, Blit, VideoHdr, Count };
static_assert(unsigned(GpuStage::Fg5)-unsigned(GpuStage::Fg1)==4);
static_assert(unsigned(GpuStage::FgBatch)>unsigned(GpuStage::Fg5));
enum class SampleState { NotExecuted, Pending, Measured, Unavailable };
diff --git a/include/veyra/engine/BackendRecovery.h b/include/veyra/engine/BackendRecovery.h
index 5290ab7b..b0d554a7 100644
--- a/include/veyra/engine/BackendRecovery.h
+++ b/include/veyra/engine/BackendRecovery.h
@@ -2,11 +2,12 @@
#include "veyra/engine/EnhancementSettings.h"
namespace veyra::engine {
-enum class FailedBackend { None, Infrastructure, OpticalFlow, NgxCore, Nr, Sr, Fg };
+enum class FailedBackend { None, Infrastructure, OpticalFlow, NgxCore, Nr, Sr, Fg, VideoHdr };
inline bool disableUnsupportedNvidiaEffects(EnhancementSettings& settings,bool nvidia){
if(nvidia)return false;
const auto before=settings;
settings.nr=false;
+ settings.videoHdr.enabled=false;
// AMD FSR upscaling is vendor neutral and must survive the NVIDIA-only
// normalization; every other SR backend is NGX-only.
settings.sr=settings.videoSrQuality==kVideoSrFsr;
@@ -20,6 +21,7 @@ inline const wchar_t* backendFailureName(FailedBackend backend) {
case FailedBackend::Nr:return L"NR";
case FailedBackend::Sr:return L"超分";
case FailedBackend::Fg:return L"帧生成";
+ case FailedBackend::VideoHdr:return L"RTX Video HDR";
default:return L"GPU / 输入 / 显示资源";
}
}
@@ -28,10 +30,12 @@ inline const wchar_t* backendFailureName(FailedBackend backend) {
inline bool disableFailedBackend(EnhancementSettings& settings,FailedBackend backend){
const auto before=settings;
switch(backend){
+ case FailedBackend::VideoHdr:settings.videoHdr.enabled=false;break;
case FailedBackend::Nr:settings.nr=false;break;
case FailedBackend::Sr:settings.sr=false;break;
case FailedBackend::Fg:settings.multiplier=1;break;
case FailedBackend::NgxCore:
+ settings.videoHdr.enabled=false;
settings.nr=settings.sr=false;
if(settings.frameGenerationBackend==FrameGenerationBackend::Dlss)settings.multiplier=1;
break;
diff --git a/include/veyra/engine/EnhancementSettings.h b/include/veyra/engine/EnhancementSettings.h
index d85c3ed5..ec9e9c30 100644
--- a/include/veyra/engine/EnhancementSettings.h
+++ b/include/veyra/engine/EnhancementSettings.h
@@ -1,4 +1,5 @@
#pragma once
+#include "veyra/engine/VideoHdrSettings.h"
#include <cmath>
#include <array>
#include <cstdint>
@@ -119,7 +120,8 @@ struct EnhancementSettings {
// the next sample, so it is a live edit, not a graph rebuild.
bool captureFlipVertical=false;
bool forceSdrPreview=false; // display only; retain actual HDR source metadata
- bool useHdrPreview(bool hdrInput,bool hdrDisplayActive)const{return hdrInput&&hdrDisplayActive&&!forceSdrPreview;}
+ VideoHdrSettings videoHdr;
+ bool useHdrPreview(bool hdrInput,bool hdrDisplayActive)const{return (hdrInput||videoHdr.enabled)&&hdrDisplayActive&&!forceSdrPreview;}
pipeline::SrTarget srTarget=pipeline::SrTarget::Uhd4K;
uint32_t videoSrQuality=0; // 0 DLSS SR; 1–4 RTX Video SR
uint32_t multiplier=1;
@@ -154,6 +156,8 @@ struct EnhancementSettings {
// master switch changes the graph shape, so it stays in the comparison.
video.color=other.color;
video.color.enabled=color.enabled;
+ video.videoHdr=other.videoHdr;
+ video.videoHdr.enabled=videoHdr.enabled;
return video==other;
}
void rejectVideoRequest(const EnhancementSettings& attempted,const EnhancementSettings& previous) {
@@ -165,6 +169,7 @@ struct EnhancementSettings {
*this=restored;
}
std::string validate() const {
+ if(!videoHdr.valid())return "invalid RTX Video HDR parameters";
auto range=[](float v,float hi){return std::isfinite(v)&&v>=0&&v<=hi;};
if(auto error=protection.validate();!error.empty())return error;
if(!revision)return "settingsRevision must be nonzero";
diff --git a/include/veyra/engine/VideoHdrSettings.h b/include/veyra/engine/VideoHdrSettings.h
new file mode 100644
index 00000000..df77dd01
--- /dev/null
+++ b/include/veyra/engine/VideoHdrSettings.h
@@ -0,0 +1,13 @@
+#pragma once
+
+namespace veyra::engine {
+struct VideoHdrSettings {
+ bool enabled=false;
+ unsigned contrast=125, saturation=75, middleGray=44, peakNits=1000;
+ bool operator==(const VideoHdrSettings&) const = default;
+ bool valid() const {
+ return contrast<=200 && saturation<=200 && middleGray>=10 &&
+ middleGray<=100 && peakNits>=400 && peakNits<=2000;
+ }
+};
+}
diff --git a/include/veyra/ngx/TrueHdrBackend.h b/include/veyra/ngx/TrueHdrBackend.h
new file mode 100644
index 00000000..2845ff7b
--- /dev/null
+++ b/include/veyra/ngx/TrueHdrBackend.h
@@ -0,0 +1,22 @@
+#pragma once
+#include "veyra/ngx/NgxCoreHost.h"
+#include "veyra/engine/VideoHdrSettings.h"
+#include <windows.h>
+
+namespace veyra::ngx {
+// RTX Video SDK 1.1 public ABI, independent implementation. The shared NGX
+// core owns initialization; the pinned module reference outlives the feature.
+class TrueHdrBackend {
+public:
+ ~TrueHdrBackend(){release();}
+ bool create(NgxCoreHost&,ID3D12GraphicsCommandList*,const std::wstring& runtimeDirectory);
+ bool evaluate(ID3D12GraphicsCommandList*,ID3D12Resource* sdr,ID3D12Resource* scrgb,const engine::VideoHdrSettings&);
+ void release();
+private:
+ NgxCoreHost* core_=nullptr;
+ NVSDK_NGX_Parameter* params_=nullptr;
+ NVSDK_NGX_Handle* handle_=nullptr;
+ HMODULE module_=nullptr;
+ bool first_=true;
+};
+}
diff --git a/include/veyra/pipeline/EnhanceGraph.h b/include/veyra/pipeline/EnhanceGraph.h
index 026929d7..19c10dd8 100644
--- a/include/veyra/pipeline/EnhanceGraph.h
+++ b/include/veyra/pipeline/EnhanceGraph.h
@@ -48,6 +48,7 @@ namespace veyra::ngx {
class NgxCoreHost;
class DlssSrBackend;
class VideoSrBackend;
+class TrueHdrBackend;
class DlssFgBackend;
class FgCompatibilitySession;
class DlssNrRuntimeAdapter;
@@ -83,6 +84,9 @@ struct EnhanceGraphDesc {
unsigned captureBitDepth = 8; // SDR P010/P016 storage, independent of HDR transfer.
bool wideYuvInput() const { return hdrInput || captureBitDepth > 8; }
bool hdrOutput = false; // HDR-preserving output: scRGB without FG; RGB10/PQ with FG.
+ engine::VideoHdrSettings videoHdr;
+ bool hdrWorking() const {return hdrInput&&hdrOutput;}
+ bool convertVideoHdr() const {return videoHdr.enabled&&!hdrInput&&hdrOutput;}
bool highQualityPresentation = false; // PS5 ordinary scaling, no AI SR
bool rgbInput = false; // allocate direct RGBA ingestion before NGX creation
bool yuy2Input = false; // packed Y0 U Y1 V -> linear FP16; never subsample to NV12
@@ -233,6 +237,7 @@ public:
bool nrEnabled() const { return nrEnabled_; }
bool fgEnabled() const { return fgEnabled_; }
bool hdrOutput() const { return desc_.hdrOutput; }
+ bool videoHdrActive() const {return desc_.convertVideoHdr();}
bool hdr10Output() const { return desc_.hdrOutput && desc_.enableFg; }
DXGI_FORMAT outputFormat() const { return hdr10Output()?DXGI_FORMAT_R10G10B10A2_UNORM:desc_.hdrOutput?DXGI_FORMAT_R16G16B16A16_FLOAT:DXGI_FORMAT_R8G8B8A8_UNORM; }
bool highQualityPresentation() const { return desc_.highQualityPresentation; }
@@ -338,6 +343,7 @@ private:
size_t rgbPitch_=0;
ComPtr<ID3D12Resource> workRgba_;
ComPtr<ID3D12Resource> videoSrInput_,videoSrOutput_;
+ ComPtr<ID3D12Resource> videoHdrInput_,videoHdrOutput_;
ComPtr<ID3D12Resource> nrInput_,residualRgba_,nrFlow_,baseFlow_;
ComPtr<ID3D12Resource> presentMotion_[2];
bool presentMotionValid_[2]={};
@@ -400,6 +406,7 @@ private:
std::unique_ptr<guidance::AmdOpticalFlow> amdOf_;
std::unique_ptr<guidance::GpuDisOpticalFlow> gpuDis_;
std::unique_ptr<ngx::VideoSrBackend> videoSrBackend_;
+ std::unique_ptr<ngx::TrueHdrBackend> videoHdrBackend_;
std::unique_ptr<ngx::DlssFgBackend> fgBackend_;
std::unique_ptr<gfx::FsrSrBackend> fsrSrBackend_;
ComPtr<ID3D12Resource> fsrSrDepth_, upFsrSrDepth_;
diff --git a/scripts/build-isolated.ps1 b/scripts/build-isolated.ps1
new file mode 100644
index 00000000..8933f53f
--- /dev/null
+++ b/scripts/build-isolated.ps1
@@ -0,0 +1,42 @@
+[CmdletBinding()]
+param(
+ [Parameter(Mandatory)][string]$Root,
+ [Parameter(Mandatory)][string]$BuildDirectory,
+ [Parameter(Mandatory)][string]$DependencyCache,
+ [Parameter(Mandatory)][string]$TempDirectory,
+ [string[]]$Targets=@('veyra'),
+ [switch]$ConfigureOnly
+)
+$ErrorActionPreference='Stop'
+Set-StrictMode -Version Latest
+# Reuse only explicit dependency locations, never another tree's build state.
+$cache=Get-Content -LiteralPath $DependencyCache
+$vswhere=Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio/Installer/vswhere.exe'
+$vs=(& $vswhere -latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath | Select-Object -First 1)
+if(!$vs){throw 'MSVC not found'}
+$vcvars=Join-Path $vs 'VC/Auxiliary/Build/vcvars64.bat'
+$savedTemp=$env:TEMP;$savedTmp=$env:TMP
+New-Item -ItemType Directory -Force -Path $BuildDirectory,$TempDirectory | Out-Null
+try {
+ $env:TEMP=$TempDirectory;$env:TMP=$TempDirectory
+ $vcEnvironment=& cmd.exe /d /c "call `"$vcvars`" >nul && set"
+ if($LASTEXITCODE){throw 'vcvars failed'}
+ foreach($line in $vcEnvironment){if($line -match '^([^=]+)=(.*)$'){[Environment]::SetEnvironmentVariable($matches[1],$matches[2],'Process')}}
+ $cmake=Join-Path $vs 'Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe'
+ $ninja=Join-Path $vs 'Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe'
+ $argsList=@('-S',$Root,'-B',$BuildDirectory,'-G','Ninja','-DCMAKE_BUILD_TYPE=Release',"-DCMAKE_MAKE_PROGRAM=$ninja",'-DVEYRA_ENABLE_EXPERIMENTAL_DLSSNR=ON','-DVEYRA_ENABLE_REMOTEPLAY=ON')
+ foreach($line in $cache){
+ if($line -match '^(VEYRA_[A-Z0-9_]+_ROOT|VEYRA_RP_CHIAKI_SOURCE_DIR|VEYRA_RP_CHIAKI_VERIFY_DIR|CMAKE_PREFIX_PATH|PROTOC|Protobuf_PROTOC_EXECUTABLE|PKG_CONFIG_EXECUTABLE):[^=]+=(.+)$'){
+ $argsList+="-D$($matches[1])=$($matches[2])"
+ }
+ }
+ $dlss=($cache | Select-String '^VEYRA_DLSS_SDK_ROOT:PATH=(.+)$').Matches[0].Groups[1].Value
+ $nvidia=Split-Path $dlss -Parent
+ $argsList+="-DVEYRA_NVOF_SDK_ROOT=$nvidia/Optical_Flow_SDK_5.0.7"
+ & $cmake @argsList
+ if($LASTEXITCODE){throw "Configure failed: $LASTEXITCODE"}
+ if(!$ConfigureOnly){
+ & $cmake --build $BuildDirectory --parallel 8 --target @Targets
+ if($LASTEXITCODE){throw "Build failed: $LASTEXITCODE"}
+ }
+} finally {$env:TEMP=$savedTemp;$env:TMP=$savedTmp}
diff --git a/shaders/PresentBlit.hlsl b/shaders/PresentBlit.hlsl
index 224a527f..f9b7229a 100644
--- a/shaders/PresentBlit.hlsl
+++ b/shaders/PresentBlit.hlsl
@@ -75,6 +75,7 @@ float4 psMain(VSOut input) : SV_Target
}
uint flags=uint(srcDims.z+0.5);
float4 color=(flags&2)?FineSample(uv):sourceTex.SampleLevel(linearClamp,uv,0);
+ if(flags&8)color.rgb*=203.0/80.0; // SDR comparison white in an HDR output.
if(flags&1){float3 c=max(color.rgb,0);color.rgb=lerp(1.055*pow(c,1.0/2.4)-0.055,c*12.92,step(c,0.0031308));}
if(flags&4)color.rgb=HdrEncodePq(color.rgb);
return color;
diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cpp
index 08fbed39..861f6ab0 100644
--- a/src/engine/EngineController.cpp
+++ b/src/engine/EngineController.cpp
@@ -279,6 +279,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
gd.nrBeforeSr=!isImage&&options.settings.lowLatency&&options.nr&&resolution.srApplied;gd.enableSr=resolution.srApplied&&(nvidiaAdapter||options.settings.videoSrQuality==kVideoSrFsr);gd.videoSrQuality=options.settings.videoSrQuality;gd.enableNr=options.nr&&nvidiaAdapter;gd.nrRuntime=options.settings.nrRuntime;gd.enableFg=options.fg&&(nvidiaAdapter||xessFg);gd.fgMultiplier=options.fgMultiplier;gd.frameGenerationBackend=options.settings.frameGenerationBackend;gd.enableNvofStandalone=gd.enableNr;
gd.noFeatures=false;gd.model=options.settings.model;gd.residual=options.settings.residual;gd.protection=options.settings.protection;gd.color=options.settings.color;gd.settingsRevision=options.settings.revision;gd.flowQuality=options.settings.flow;gd.contentRate=options.settings.content;
gd.opticalFlowBackend=options.settings.opticalFlowBackend;gd.amdFlowHalfResolution=options.settings.amdFlowHalfResolution;
+ gd.videoHdr=options.settings.videoHdr;
gd.hdrOutput=options.settings.useHdrPreview(gd.hdrInput,gfx::PresentSink::hdrDisplayActive(window));
veyra::log::info("display-color",std::format("hdrInput={} hdrOutput={} forceSdrPreview={}",gd.hdrInput,gd.hdrOutput,options.settings.forceSdrPreview));
gd.runtimeAbsPath=runtime::localRuntimeDirectory().wstring();
@@ -295,7 +296,9 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
backendRecoveryWarning=L"当前 GPU 不支持 NVIDIA 增强;NR、超分及 DLSS 已关闭,XeSS选择保留";
veyra::log::warn("capability","normalized requested NVIDIA effects before graph creation; applied settings reflect actual disabled stages");
}
- for(unsigned attempt=0;attempt<5;++attempt){
+ for(unsigned attempt=0;attempt<6;++attempt){
+ desc.videoHdr=selected.settings.videoHdr;
+ desc.hdrOutput=selected.settings.useHdrPreview(desc.hdrInput,gfx::PresentSink::hdrDisplayActive(window));
bool opened=graph.initialize(desc);
auto failure=graph.failedBackend();
if(opened){
@@ -636,7 +639,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
continue;
}
}
- if(gd.hdrInput&&GetTickCount64()-hdrDisplayCheck>2000){
+ if((gd.hdrInput||options.settings.videoHdr.enabled)&&GetTickCount64()-hdrDisplayCheck>2000){
hdrDisplayCheck=GetTickCount64();
const bool native=options.settings.useHdrPreview(gd.hdrInput,gfx::PresentSink::hdrDisplayActive(window));
if(native!=gd.hdrOutput){std::lock_guard lock(mutex_);if(desired_.revision==options.settings.revision){desired_.revision=++nextRevision_;snapshot_.desired=desired_;snapshot_.applying=true;}}
@@ -724,8 +727,9 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
nextDesc.nrBeforeSr=!isImage&&requested.lowLatency&&requested.nr&&plan.srApplied;nextDesc.enableSr=plan.srApplied&&(nvidiaAdapter||next.settings.videoSrQuality==kVideoSrFsr);nextDesc.videoSrQuality=next.settings.videoSrQuality;nextDesc.enableNr=next.nr&&nvidiaAdapter;nextDesc.nrRuntime=next.settings.nrRuntime;nextDesc.enableFg=next.fg&&(nvidiaAdapter||xessFg);nextDesc.fgMultiplier=next.fgMultiplier;nextDesc.frameGenerationBackend=next.settings.frameGenerationBackend;nextDesc.enableNvofStandalone=nextDesc.enableNr;
nextDesc.model=requested.model;nextDesc.residual=requested.residual;nextDesc.protection=requested.protection;nextDesc.color=requested.color;nextDesc.settingsRevision=requested.revision;nextDesc.flowQuality=requested.flow;nextDesc.contentRate=requested.content;
nextDesc.opticalFlowBackend=requested.opticalFlowBackend;nextDesc.amdFlowHalfResolution=requested.amdFlowHalfResolution;
+ nextDesc.videoHdr=requested.videoHdr;
nextDesc.hdrOutput=requested.useHdrPreview(nextDesc.hdrInput,gfx::PresentSink::hdrDisplayActive(window));
- const bool rebuild=(!nvidiaAdapter&&(next.nr||next.sr||(next.fg&&!xessFg)))||gd.hdrOutput!=nextDesc.hdrOutput||previous.captureCompatible!=requested.captureCompatible||gd.nrRuntime!=nextDesc.nrRuntime||gd.opticalFlowBackend!=nextDesc.opticalFlowBackend||gd.amdFlowHalfResolution!=nextDesc.amdFlowHalfResolution||gd.enableNr!=nextDesc.enableNr||gd.color.enabled!=nextDesc.color.enabled||gd.color.lutNameString()!=nextDesc.color.lutNameString()||gd.enableFg!=nextDesc.enableFg||gd.frameGenerationBackend!=nextDesc.frameGenerationBackend||gd.fgMultiplier!=nextDesc.fgMultiplier||gd.videoSrQuality!=nextDesc.videoSrQuality||gd.flowQuality!=nextDesc.flowQuality||gd.nrBeforeSr!=nextDesc.nrBeforeSr||gd.workWidth!=nextDesc.workWidth||gd.workHeight!=nextDesc.workHeight||gd.nrWidth!=nextDesc.nrWidth||gd.nrHeight!=nextDesc.nrHeight||gd.flowWidth!=nextDesc.flowWidth||gd.flowHeight!=nextDesc.flowHeight;
+ const bool rebuild=gd.videoHdr.enabled!=nextDesc.videoHdr.enabled||(!nvidiaAdapter&&(next.nr||next.sr||(next.fg&&!xessFg)))||gd.hdrOutput!=nextDesc.hdrOutput||previous.captureCompatible!=requested.captureCompatible||gd.nrRuntime!=nextDesc.nrRuntime||gd.opticalFlowBackend!=nextDesc.opticalFlowBackend||gd.amdFlowHalfResolution!=nextDesc.amdFlowHalfResolution||gd.enableNr!=nextDesc.enableNr||gd.color.enabled!=nextDesc.color.enabled||gd.color.lutNameString()!=nextDesc.color.lutNameString()||gd.enableFg!=nextDesc.enableFg||gd.frameGenerationBackend!=nextDesc.frameGenerationBackend||gd.fgMultiplier!=nextDesc.fgMultiplier||gd.videoSrQuality!=nextDesc.videoSrQuality||gd.flowQuality!=nextDesc.flowQuality||gd.nrBeforeSr!=nextDesc.nrBeforeSr||gd.workWidth!=nextDesc.workWidth||gd.workHeight!=nextDesc.workHeight||gd.nrWidth!=nextDesc.nrWidth||gd.nrHeight!=nextDesc.nrHeight||gd.flowWidth!=nextDesc.flowWidth||gd.flowHeight!=nextDesc.flowHeight;
bool accepted=ring.drainQueue();out={};hasOutput=false;
resetRecord->rebuilt=rebuild;
markResetStage(diagnostics::ResetStage::Drain);
@@ -1333,7 +1337,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
measured.flow=frameFlow->snapshot(host100ns());
measured.sourceFrames=measured.flow.counters.sourceAccepted;measured.validGenerated=measured.flow.counters.fgReadyValid;measured.submitted=measured.flow.counters.realPresented+measured.flow.counters.generatedPresented;measured.expired=measured.flow.counters.generatedExpiredAfterEval;
const double ageP95=liveScheduler?completed.ageP95:captureAges.p95(),waitP95=liveScheduler?completed.waitP95:scheduleWaits.p95(),presentP95=liveScheduler?completed.presentP95:presentTimes.p95();
- ++frames;{std::lock_guard lock(mutex_);snapshot_.metrics=measured;snapshot_.colorStatus=gd.hdrOutput?(graph.hdr10Output()?L"HDR → HDR10 / PQ":L"HDR → scRGB / 浮点"):gd.hdrInput?L"HDR → SDR色调映射":L"SDR → SDR";snapshot_.position=(isCapture||isImage?pts:lastFilePresentedMs)/1000;snapshot_.frames=sourceFrames;snapshot_.generated=graphStats.fgGeneratedFrames;snapshot_.lateMs=lateness;snapshot_.lateP95Ms=sorted.empty()?0:sorted[size_t((sorted.size()-1)*0.95)];
+ ++frames;{std::lock_guard lock(mutex_);snapshot_.metrics=measured;snapshot_.colorStatus=graph.videoHdrActive()?L"SDR → RTX Video HDR":options.settings.videoHdr.enabled&&!gd.hdrInput?L"SDR → SDR(HDR显示未启用)":gd.hdrOutput?(graph.hdr10Output()?L"HDR → HDR10 / PQ":L"HDR → scRGB / 浮点"):gd.hdrInput?L"HDR → SDR色调映射":L"SDR → SDR";snapshot_.position=(isCapture||isImage?pts:lastFilePresentedMs)/1000;snapshot_.frames=sourceFrames;snapshot_.generated=graphStats.fgGeneratedFrames;snapshot_.lateMs=lateness;snapshot_.lateP95Ms=sorted.empty()?0:sorted[size_t((sorted.size()-1)*0.95)];
// Measured playback speed: media-PTS advance per wall time
// over ~1s windows (1.0 = normal speed), resampled on seek.
// A rejected LUT input space must be visible, not only logged
diff --git a/src/engine/PresetStore.cpp b/src/engine/PresetStore.cpp
index 5edf1284..4655a2ae 100644
--- a/src/engine/PresetStore.cpp
+++ b/src/engine/PresetStore.cpp
@@ -13,12 +13,12 @@ bool nameOk(const std::wstring& s){return !s.empty()&&s.size()<=48&&s.front()!=L
std::wstring trim(std::wstring s){auto a=s.find_first_not_of(L" \t\r\n");if(a==s.npos)return {};auto b=s.find_last_not_of(L" \t\r\n");return s.substr(a,b-a+1);}
}
std::string PresetStore::serialize()const{
- std::ostringstream o;o.imbue(std::locale::classic());o<<std::setprecision(std::numeric_limits<float>::max_digits10)<<"VEYRA_PRESETS 19\n"<<std::quoted(utf8(default_))<<' '<<entries_.size()<<'\n';
- for(auto& p:entries_){const auto& s=p.settings;const auto& m=s.model;const auto& r=s.residual;o<<std::quoted(utf8(p.name))<<' '<<m.intensity<<' '<<m.tone<<' '<<m.structure<<' '<<m.skin<<' '<<m.style<<' '<<m.autoMask<<' '<<m.uiCorrection<<' '<<r.total<<' '<<r.darken<<' '<<r.brighten<<' '<<r.color<<' '<<r.luminance<<' '<<s.nr<<' '<<s.sr<<' '<<s.multiplier<<' '<<int(s.nrPolicy)<<' '<<int(s.flow)<<' '<<int(s.content)<<' '<<s.protection.enabled<<' '<<s.protection.featherPixels;for(auto q:s.protection.regions)o<<' '<<q.left<<' '<<q.top<<' '<<q.right<<' '<<q.bottom;o<<' '<<s.videoSrQuality<<' '<<int(s.frameGenerationBackend)<<' '<<int(s.srTarget)<<' '<<int(s.opticalFlowBackend)<<' '<<s.amdFlowHalfResolution<<' '<<int(s.audioSync)<<' '<<s.audioOffsetMs<<' '<<int(s.nrRuntime)<<' '<<s.captureCompatible<<' '<<s.lowLatency<<' '<<s.forceSdrPreview<<' '<<int(s.captureAudio)<<' '<<s.exportBitrateMbps<<' '<<s.captureFlipVertical<<' '<<int(s.captureBuffer)<<' ';writeColorSettings(o,s.color,utf8(s.color.lutNameString()));o<<'\n';}return o.str();
+ std::ostringstream o;o.imbue(std::locale::classic());o<<std::setprecision(std::numeric_limits<float>::max_digits10)<<"VEYRA_PRESETS 20\n"<<std::quoted(utf8(default_))<<' '<<entries_.size()<<'\n';
+ for(auto& p:entries_){const auto& s=p.settings;const auto& m=s.model;const auto& r=s.residual;o<<std::quoted(utf8(p.name))<<' '<<m.intensity<<' '<<m.tone<<' '<<m.structure<<' '<<m.skin<<' '<<m.style<<' '<<m.autoMask<<' '<<m.uiCorrection<<' '<<r.total<<' '<<r.darken<<' '<<r.brighten<<' '<<r.color<<' '<<r.luminance<<' '<<s.nr<<' '<<s.sr<<' '<<s.multiplier<<' '<<int(s.nrPolicy)<<' '<<int(s.flow)<<' '<<int(s.content)<<' '<<s.protection.enabled<<' '<<s.protection.featherPixels;for(auto q:s.protection.regions)o<<' '<<q.left<<' '<<q.top<<' '<<q.right<<' '<<q.bottom;o<<' '<<s.videoSrQuality<<' '<<int(s.frameGenerationBackend)<<' '<<int(s.srTarget)<<' '<<int(s.opticalFlowBackend)<<' '<<s.amdFlowHalfResolution<<' '<<int(s.audioSync)<<' '<<s.audioOffsetMs<<' '<<int(s.nrRuntime)<<' '<<s.captureCompatible<<' '<<s.lowLatency<<' '<<s.forceSdrPreview<<' '<<int(s.captureAudio)<<' '<<s.exportBitrateMbps<<' '<<s.captureFlipVertical<<' '<<int(s.captureBuffer)<<' ';writeColorSettings(o,s.color,utf8(s.color.lutNameString()));o<<' '<<s.videoHdr.enabled<<' '<<s.videoHdr.contrast<<' '<<s.videoHdr.saturation<<' '<<s.videoHdr.middleGray<<' '<<s.videoHdr.peakNits<<'\n';}return o.str();
}
bool PresetStore::parse(const std::string& data,std::vector<UserPreset>& out,std::wstring& def){
if(data.size()>65536)return false;std::istringstream in(data);in.imbue(std::locale::classic());std::string magic,d;int version=0;size_t count=0;
- if(!(in>>magic>>version)||magic!="VEYRA_PRESETS"||(version<1||version>19)||!(in>>std::quoted(d)>>count)||count>64)return false;def=wide(d);if(!d.empty()&&def.empty())return false;
+ if(!(in>>magic>>version)||magic!="VEYRA_PRESETS"||(version<1||version>20)||!(in>>std::quoted(d)>>count)||count>64)return false;def=wide(d);if(!d.empty()&&def.empty())return false;
for(size_t i=0;i<count;++i){UserPreset p;std::string n;int policy,flow,content,nr,sr;auto& s=p.settings;auto& m=s.model;auto& r=s.residual;
if(!(in>>std::quoted(n)>>m.intensity>>m.tone>>m.structure>>m.skin>>m.style>>m.autoMask>>m.uiCorrection>>r.total>>r.darken>>r.brighten>>r.color>>r.luminance>>nr>>sr>>s.multiplier>>policy>>flow>>content))return false;
if(version>=2){int enabled;if(!(in>>enabled>>s.protection.featherPixels)||enabled<0||enabled>1)return false;s.protection.enabled=enabled!=0;
@@ -45,6 +45,7 @@ bool PresetStore::parse(const std::string& data,std::vector<UserPreset>& out,std
if(version>=17){int buffer;if(!(in>>buffer)||buffer<0||buffer>2)return false;s.captureBuffer=static_cast<veyra::source::CaptureBufferMode>(buffer);}
// v18 appends the full colour grade block (see ColorSettings.h).
if(version>=18){std::string lut;if(!readColorSettings(in,s.color,lut,version))return false;if(!lut.empty()&&!s.color.setLutName(wide(lut)))return false;}
+ if(version>=20){int enabled;if(!(in>>enabled>>s.videoHdr.contrast>>s.videoHdr.saturation>>s.videoHdr.middleGray>>s.videoHdr.peakNits)||enabled<0||enabled>1)return false;s.videoHdr.enabled=enabled!=0;}
p.name=wide(n);if(!nameOk(p.name)||std::any_of(out.begin(),out.end(),[&](auto& a){return a.name==p.name;})||nr<0||nr>1||sr<0||sr>1)return false;
s.nr=nr;s.sr=sr;s.nrPolicy=static_cast<pipeline::NrSizePolicy>(policy);s.flow=static_cast<FlowQuality>(flow);s.content=static_cast<ContentRate>(content);
if(!s.validate().empty())return false;out.push_back(std::move(p));
diff --git a/src/engine/VideoExportJob.cpp b/src/engine/VideoExportJob.cpp
index aade2590..8c8bf9e6 100644
--- a/src/engine/VideoExportJob.cpp
+++ b/src/engine/VideoExportJob.cpp
@@ -72,14 +72,16 @@ bool exportVideo(const std::wstring& input,const std::wstring& output,PlayerOpti
const double sourceInterval=double(rateDen)/rateNum;
const auto resolution=pipeline::ResolutionPlan::make({info.width,info.height},options.sr,pipeline::NrSizePolicy::Native,true,options.settings.revision,options.settings.srTarget);
pipeline::EnhanceGraphDesc gd;gd.hdrInput=gd.hdrOutput=info.color.isHdrPath();
+ gd.videoHdr=options.settings.videoHdr;
+ gd.videoHdr.enabled=gd.videoHdr.enabled&&nvidiaAdapter;
+ gd.hdrOutput=gd.hdrInput||gd.videoHdr.enabled;
// Plan v5.3: the grade changes the peak and the content light distribution.
// Recomputing MaxCLL/MaxFALL needs a full pre-pass before the header is
// written, which this exporter does not do yet, so say so instead of
// letting the user assume the static metadata tracks the graded output.
- if(gd.hdrOutput&&options.settings.color.enabled&&!options.settings.color.neutral())
+ if(gd.hdrInput&&gd.hdrOutput&&options.settings.color.enabled&&!options.settings.color.neutral())
veyra::log::warn("color-export","HDR export with the colour grade active: MaxCLL/MaxFALL are carried over from the source and NOT recomputed for the graded output (marked as not updated)");
gd.captureBitDepth=info.color.pixelFormat==pipeline::SourcePixelFormat::P010?10:info.color.pixelFormat==pipeline::SourcePixelFormat::P016?16:8;
- if(gd.hdrOutput&&!hevc){hevc=true;fgNote+=fgNote.empty()?L"HDR 视频自动使用 HEVC Main10 编码":L";HDR 视频自动使用 HEVC Main10 编码";}
// Adapter gate mirrors the preview rules (EngineController): DLSS NR,
// DLSS SR and the NVOF guidance need an NVIDIA device; AMD FSR
// upscaling is the only vendor-neutral video SR we ship. Requesting an
@@ -96,6 +98,12 @@ bool exportVideo(const std::wstring& input,const std::wstring& output,PlayerOpti
auto startGraph=[&](bool fg,uint32_t multiplier){
gd.enableFg=fg;gd.fgMultiplier=fg?multiplier:1;
if(graph.initialize(gd)&&graph.createViews()){graphReady=true;return;}
+ if(graph.failedBackend()==FailedBackend::VideoHdr||(gd.convertVideoHdr()&&!gd.enableNr&&!gd.enableSr&&!gd.enableFg&&graph.failedBackend()==FailedBackend::NgxCore)){
+ graph.shutdown();
+ gd.videoHdr.enabled=false;gd.hdrOutput=gd.hdrInput;
+ fgNote+=L";RTX Video HDR 初始化失败,本次保留 SDR(错误码见日志)";
+ if(graph.initialize(gd)&&graph.createViews()){graphReady=true;return;}
+ }
fgFailure=graph.failedBackend()==FailedBackend::Fg;
graph.shutdown();
};
@@ -107,6 +115,7 @@ bool exportVideo(const std::wstring& input,const std::wstring& output,PlayerOpti
}
} else startGraph(false,1);
if(!graphReady){if(failureReason.empty())failureReason=L"增强管线初始化失败,请查看诊断";break;}
+ if(gd.hdrOutput&&!hevc){hevc=true;fgNote+=fgNote.empty()?L"HDR 视频自动使用 HEVC Main10 编码":L";HDR 视频自动使用 HEVC Main10 编码";}
if(!fgNote.empty())progress(0,fgNote);
const AVRational rate=av_mul_q({rateNum,rateDen},{int(options.fg?options.fgMultiplier:1),1});
constexpr AVRational mediaTimeBase{1,1000000};
@@ -119,7 +128,7 @@ bool exportVideo(const std::wstring& input,const std::wstring& output,PlayerOpti
// needs a full pre-pass before the header is written), so the source
// declaration is carried into the 'clli' box verbatim and the graded case
// is flagged as "not updated" instead of silently changing meaning.
- if(gd.hdrOutput&&info.color.hdrMaxCllNits>0.0f){
+ if(gd.hdrInput&&gd.hdrOutput&&info.color.hdrMaxCllNits>0.0f){
if(auto* side=av_packet_side_data_new(&cp->coded_side_data,&cp->nb_coded_side_data,AV_PKT_DATA_CONTENT_LIGHT_LEVEL,sizeof(AVContentLightMetadata),0)){
auto* cll=reinterpret_cast<AVContentLightMetadata*>(side->data);
cll->MaxCLL=unsigned(info.color.hdrMaxCllNits);
diff --git a/src/engine/VideoPresenter.cpp b/src/engine/VideoPresenter.cpp
index 5e1cbb96..85c03482 100644
--- a/src/engine/VideoPresenter.cpp
+++ b/src/engine/VideoPresenter.cpp
@@ -78,7 +78,7 @@ bool VideoPresenter::present(gfx::D3D12DeviceContext& ctx,gfx::CommandSlotRing&
if(comparison&&!generated&&referencesValid){
auto* reference=baseReference?graph.baseReference(slot):graph.sourceReference(slot);
D3D12_RESOURCE_BARRIER b{};b.Type=D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;b.Transition.pResource=reference;b.Transition.Subresource=D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;b.Transition.StateBefore=D3D12_RESOURCE_STATE_COMMON;b.Transition.StateAfter=D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;list->ResourceBarrier(1,&b);
- dims[2]=samplingFlags+(graph.hdr10Output()?4:graph.hdrOutput()?0:1);list->SetGraphicsRoot32BitConstants(0,8,dims,0);list->SetGraphicsRootDescriptorTable(1,{pass_.heap->GetGPUDescriptorHandleForHeapStart().ptr+size_t(12+slot+(baseReference?2:0))*pass_.increment});
+ dims[2]=samplingFlags+(graph.hdr10Output()?4:graph.hdrOutput()?0:1)+(graph.videoHdrActive()?8:0);list->SetGraphicsRoot32BitConstants(0,8,dims,0);list->SetGraphicsRootDescriptorTable(1,{pass_.heap->GetGPUDescriptorHandleForHeapStart().ptr+size_t(12+slot+(baseReference?2:0))*pass_.increment});
if(comparison==2)rect.right=LONG(std::clamp((rc.right*.5f+(std::clamp(split,0.0f,1.0f)-view.centerX)*graph.workWidth()*scale*view.zoom)*sink_.bufferWidth()/rc.right,0.0f,float(sink_.bufferWidth())));list->RSSetScissorRects(1,&rect);list->DrawInstanced(3,1,0,0);
std::swap(b.Transition.StateBefore,b.Transition.StateAfter);list->ResourceBarrier(1,&b);
if(veyra::log::verboseFrameLogs())veyra::log::info("comparison",std::format("real-frame source={} epoch={} revision={} reference={} mode={} split={} (same leased frame)",identity.sourceFrameId,identity.epoch,identity.settingsRevision,baseReference?"base":"input",comparison,split));
diff --git a/src/ngx/TrueHdrBackend.cpp b/src/ngx/TrueHdrBackend.cpp
new file mode 100644
index 00000000..388b31ab
--- /dev/null
+++ b/src/ngx/TrueHdrBackend.cpp
@@ -0,0 +1,81 @@
+#include "veyra/ngx/TrueHdrBackend.h"
+#include "veyra/Log.h"
+#include <filesystem>
+#include <format>
+
+namespace veyra::ngx {
+namespace {
+NVSDK_NGX_Result invoke(int op,ID3D12GraphicsCommandList* list,NVSDK_NGX_Parameter* p,NVSDK_NGX_Handle** h,unsigned& seh){
+ seh=0;
+ __try {
+ if(op==0)return NVSDK_NGX_D3D12_CreateFeature(list,NVSDK_NGX_Feature_Reserved14,p,h);
+ if(op==1)return NVSDK_NGX_D3D12_EvaluateFeature(list,*h,p);
+ return NVSDK_NGX_D3D12_ReleaseFeature(*h);
+ } __except(EXCEPTION_EXECUTE_HANDLER){seh=GetExceptionCode();return NVSDK_NGX_Result_FAIL_PlatformError;}
+}
+bool report(int op,NVSDK_NGX_Result r,unsigned seh,bool always=true){
+ const bool ok=NVSDK_NGX_SUCCEED(r)&&!seh;
+ const auto message=std::format("op={} result=0x{:X} seh=0x{:X}",op,unsigned(r),seh);
+ if(!ok)log::error("video-hdr",message);
+ else if(always||log::verboseFrameLogs())log::info("video-hdr",message);
+ return ok;
+}
+NVSDK_NGX_Result getCapabilities(NVSDK_NGX_Parameter** caps,unsigned& seh){
+ __try {
+ return NVSDK_NGX_D3D12_GetCapabilityParameters(caps);
+ } __except(EXCEPTION_EXECUTE_HANDLER){seh=GetExceptionCode();return NVSDK_NGX_Result_FAIL_PlatformError;}
+}
+NVSDK_NGX_Result getCapability(NVSDK_NGX_Parameter* caps,const char* key,int* value,unsigned& seh){
+ __try {return caps->Get(key,value);}
+ __except(EXCEPTION_EXECUTE_HANDLER){seh=GetExceptionCode();return NVSDK_NGX_Result_FAIL_PlatformError;}
+}
+void capability(NgxCoreHost& core){
+ NVSDK_NGX_Parameter* caps=nullptr;unsigned seh=0;
+ const auto r=getCapabilities(&caps,seh);
+ report(3,r,seh);
+ if(!caps||seh)return;
+ // Query results are logged individually: missing keys are not driver errors.
+ for(const auto* key:{"TrueHDR.Available","TrueHDR.NeedsUpdatedDriver","TrueHDR.MinDriverVersionMajor","TrueHDR.MinDriverVersionMinor","TrueHDR.FeatureInitResult"}){
+ int value=0;const auto result=getCapability(caps,key,&value,seh);
+ log::info("video-hdr",std::format("capability {}={} result=0x{:X} seh=0x{:X}",key,value,unsigned(result),seh));
+ if(seh)break;
+ }
+ core.destroyParameters(caps);
+}
+}
+bool TrueHdrBackend::create(NgxCoreHost& core,ID3D12GraphicsCommandList* list,const std::wstring& directory){
+ release();
+ const auto path=std::filesystem::path(directory)/L"nvngx_truehdr.dll";
+ if(!path.is_absolute())return false;
+ module_=LoadLibraryExW(path.c_str(),nullptr,LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR|LOAD_LIBRARY_SEARCH_SYSTEM32);
+ if(!module_){log::error("video-hdr",std::format("absolute runtime load failed win32={}",GetLastError()));return false;}
+ log::info("video-hdr","loaded nvngx_truehdr.dll from explicit runtime directory; input=sRGB/RGBA8 output=linear-BT709/scRGB-FP16 (1=80nits)");
+ capability(core);
+ core_=&core;Status st=Status::Ok;params_=core.allocateParameters(st);if(!params_)return false;
+ params_->Set("CreationNodeMask",1u);params_->Set("VisibilityNodeMask",1u);
+ unsigned seh=0;const auto result=invoke(0,list,params_,&handle_,seh);
+ return report(0,result,seh)&&handle_;
+}
+bool TrueHdrBackend::evaluate(ID3D12GraphicsCommandList* list,ID3D12Resource* input,ID3D12Resource* output,const engine::VideoHdrSettings& s){
+ if(!handle_||!input||!output||!s.valid())return false;
+ const auto a=input->GetDesc(),b=output->GetDesc();
+ if(a.Format!=DXGI_FORMAT_R8G8B8A8_UNORM||b.Format!=DXGI_FORMAT_R16G16B16A16_FLOAT||a.Width!=b.Width||a.Height!=b.Height){
+ log::error("video-hdr",std::format("invalid resource contract input={}x{}/{} output={}x{}/{}",a.Width,a.Height,unsigned(a.Format),b.Width,b.Height,unsigned(b.Format)));return false;
+ }
+ params_->Set("Input1",input);params_->Set("Output",output);
+ params_->Set("TrueHDR.InLeft",0u);params_->Set("TrueHDR.InTop",0u);
+ params_->Set("TrueHDR.InRight",unsigned(a.Width));params_->Set("TrueHDR.InBottom",a.Height);
+ params_->Set("TrueHDR.OutLeft",0u);params_->Set("TrueHDR.OutTop",0u);
+ params_->Set("TrueHDR.OutRight",unsigned(b.Width));params_->Set("TrueHDR.OutBottom",b.Height);
+ params_->Set("TrueHDR.Contrast",s.contrast);params_->Set("TrueHDR.Saturation",s.saturation);
+ params_->Set("TrueHDR.MiddleGray",s.middleGray);params_->Set("TrueHDR.MaxLuminance",s.peakNits);
+ if(first_||log::verboseFrameLogs())log::info("video-hdr",std::format("evaluate {}x{} contrast={} saturation={} middleGray={} peakNits={}",a.Width,a.Height,s.contrast,s.saturation,s.middleGray,s.peakNits));
+ unsigned seh=0;const auto result=invoke(1,list,params_,&handle_,seh);
+ const bool ok=report(1,result,seh,first_);first_=false;return ok;
+}
+void TrueHdrBackend::release(){
+ if(handle_){unsigned seh=0;const auto r=invoke(2,nullptr,params_,&handle_,seh);report(2,r,seh);handle_=nullptr;}
+ if(params_&&core_)core_->destroyParameters(params_);params_=nullptr;core_=nullptr;
+ if(module_)FreeLibrary(module_);module_=nullptr;first_=true;
+}
+}
diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cpp
index 26d51701..109b312b 100644
--- a/src/pipeline/EnhanceGraph.cpp
+++ b/src/pipeline/EnhanceGraph.cpp
@@ -31,6 +31,7 @@
#include "veyra/ngx/DlssNrRuntimeAdapter.h"
#include "veyra/ngx/DlssSrBackend.h"
#include "veyra/ngx/VideoSrBackend.h"
+#include "veyra/ngx/TrueHdrBackend.h"
#include "veyra/ngx/NgxCoreHost.h"
#include "veyra/ngx/NgxParameters.h"
#include "veyra/ngx/NvOfSession.h"
@@ -286,7 +287,7 @@ bool EnhanceGraph::initialize(const EnhanceGraphDesc& desc)
diagnostics::DiagnosticEvent initDiagnostic;initDiagnostic.stage="initialize";initDiagnostic.identity={epoch_+1,desc.settingsRevision,0};initDiagnostic.resolution.source={srcW_,srcH_};initDiagnostic.resolution.base=initDiagnostic.resolution.fg=initDiagnostic.resolution.output={workW_,workH_};initDiagnostic.resolution.nr={nrW_,nrH_};initDiagnostic.resolution.flow={nvofW_,nvofH_};initDiagnostic.flowApplied=std::to_string(unsigned(desc.flowQuality));initDiagnostic.runtimeHash="unverified-user-replaceable";Logger::diagnosticContext(initDiagnostic);
veyra::log::info("resolution",std::format("source={}x{} base={}x{} nr={}x{} flow={}x{} fg={}x{} output={}x{}",srcW_,srcH_,workW_,workH_,nrW_,nrH_,nvofW_,nvofH_,workW_,workH_,workW_,workH_));
veyra::log::info("pipeline-order",desc.nrBeforeSr?"NR -> residual(source) -> SR -> FG (experimental preview)":"SR -> NR -> residual -> FG");
- if(desc.hdrOutput&&!desc.hdrInput){veyra::log::error("hdr","HDR output requires an explicit HDR input contract");return false;}
+ if(!desc.videoHdr.valid()||(desc.hdrOutput&&!desc.hdrInput&&!desc.convertVideoHdr())){veyra::log::error("hdr","HDR output requires native HDR input or explicit Video HDR conversion");return false;}
srEnabled_ = desc.enableSr && (srcW_ != workW_ || srcH_ != workH_);
nrEnabled_ = desc.enableNr && !desc.noFeatures && !desc.noNgx;
fgEnabled_ = desc.enableFg && !desc.noNgx && !desc.stillImage && desc.frameGenerationBackend!=engine::FrameGenerationBackend::XeSS
@@ -371,6 +372,11 @@ bool EnhanceGraph::createResources()
}
}
srcRgba_ = makeTexture(context_.device(), srcW_, srcH_, DXGI_FORMAT_R16G16B16A16_FLOAT, true);
+ if(desc_.convertVideoHdr()){
+ videoHdrInput_=makeTexture(context_.device(),workW_,workH_,DXGI_FORMAT_R8G8B8A8_UNORM,true);
+ videoHdrOutput_=makeTexture(context_.device(),workW_,workH_,DXGI_FORMAT_R16G16B16A16_FLOAT,true);
+ if(!videoHdrInput_||!videoHdrOutput_)return false;
+ }
if(srEnabled_&&desc_.videoSrQuality&&desc_.videoSrQuality!=engine::kVideoSrFsr){videoSrInput_=makeTexture(context_.device(),srcW_,srcH_,DXGI_FORMAT_R8G8B8A8_UNORM,true);videoSrOutput_=makeTexture(context_.device(),workW_,workH_,DXGI_FORMAT_R8G8B8A8_UNORM,true);if(!videoSrInput_||!videoSrOutput_)return false;}
// FSR upscaling needs a render-extent depth; Veyra has no source-resolution
// depth source, so this is the same explicit constant far depth the
@@ -789,7 +795,7 @@ bool EnhanceGraph::initFsrSr()
veyra::log::warn("fsr-sr", "feature-disabled configuration: AMD FSR upscaling skipped");
return true;
}
- if (desc_.hdrOutput) {
+ if (desc_.hdrWorking()) {
// The working color here is linear FP16 with Veyra's own HDR contract;
// feeding that to the FSR HDR path without a verified transfer contract
// would be a guess. Refuse the stage instead of shipping a wrong image.
@@ -816,13 +822,14 @@ bool EnhanceGraph::initFsrSr()
bool EnhanceGraph::initNgxFeatures()
{
failedBackend_=engine::FailedBackend::NgxCore;
- if (desc_.noNgx || desc_.noFeatures || (!nrEnabled_&&!srEnabled_&&!fgEnabled_)) {
+ if(desc_.convertVideoHdr()&&(desc_.noNgx||desc_.noFeatures)){failedBackend_=engine::FailedBackend::VideoHdr;return false;}
+ if (desc_.noNgx || desc_.noFeatures || (!nrEnabled_&&!srEnabled_&&!fgEnabled_&&!desc_.convertVideoHdr())) {
veyra::log::info("graph", "NGX core/features skipped by disabled-feature configuration");
return true;
}
// FSR upscaling is a FidelityFX effect: a session whose only feature is
// FSR SR must not require (or fail on) the NGX core.
- const bool needNgxCore = nrEnabled_ || fgEnabled_ ||
+ const bool needNgxCore = nrEnabled_ || fgEnabled_ || desc_.convertVideoHdr() ||
(srEnabled_ && desc_.videoSrQuality!=engine::kVideoSrFsr);
if (!needNgxCore) {
veyra::log::info("graph", "NGX core skipped: AMD FSR upscaling is the only enabled stage");
@@ -952,6 +959,14 @@ bool EnhanceGraph::initNgxFeatures()
if (ngxParams_ == nullptr) return false;
srBackend_ = std::make_unique<ngx::DlssSrBackend>();
+ if(desc_.convertVideoHdr()){
+ auto* list=ring_.acquire(0,st);if(!list)return false;
+ failedBackend_=engine::FailedBackend::VideoHdr;
+ videoHdrBackend_=std::make_unique<ngx::TrueHdrBackend>();
+ if(!videoHdrBackend_->create(*coreHost_,list,desc_.runtimeAbsPath))return false;
+ failedBackend_=engine::FailedBackend::Infrastructure;
+ if(!ring_.submitAndSignal(0)||!ring_.waitIdle())return false;
+ }
// NR feature create (8.5 create parameter contract).
if(nrEnabled_) {
@@ -1074,14 +1089,14 @@ bool EnhanceGraph::createComputePasses()
if((desc_.rgbInput||desc_.yuy2Input||desc_.packedInput)&&(!rgbPass_.loadShader(rgbShader,cs)||!rgbPass_.create(context_.device(),cs,12,1,1,8+kColorGradeConstantCount,4)))return false;
if (!encPass_.loadShader("ParityEncode.dxil", cs) || !encPass_.create(context_.device(), cs, 8, 1, 1)) return false;
if (!decPass_.loadShader("ParityDecode.dxil", cs) || !decPass_.create(context_.device(), cs, 8)) return false;
- if (!blitPass_.loadShader("ScaleBlit.dxil", cs) || !blitPass_.create(context_.device(), cs, 19, 1, 1)) return false;
+ if (!blitPass_.loadShader("ScaleBlit.dxil", cs) || !blitPass_.create(context_.device(), cs, 21, 1, 1)) return false;
// Nv12Upload stays: frame-time CopyTextureRegion is poisoned by the
// injected layer (SEH in NGX evaluate, r33-final3 evidence); the compute
// upload is the proven frame-path ingestion on this system.
if (!uploadPass_.loadShader("Nv12Upload.dxil", cs) || !uploadPass_.create(context_.device(), cs, 4, 1, 2)) return false;
if (!densifyPass_.loadShader("NvofDensify.dxil", cs) ||
!densifyPass_.create(context_.device(), cs, 7, 5, 2)) return false;
- if(desc_.hdrOutput&&videoSrInput_&&(!hdrVideoSrPass_.loadShader("HdrVideoSrRestore.dxil",cs)||!hdrVideoSrPass_.create(context_.device(),cs,7,3,1)))return false;
+ if(desc_.hdrWorking()&&videoSrInput_&&(!hdrVideoSrPass_.loadShader("HdrVideoSrRestore.dxil",cs)||!hdrVideoSrPass_.create(context_.device(),cs,7,3,1)))return false;
if (!stager_.initialize(context_.device(), 80)) {
veyra::log::error("graph", "descriptor stager init failed");
return false;
@@ -1133,7 +1148,7 @@ bool EnhanceGraph::createViews()
stagedSrv(flowTex_.Get(),DXGI_FORMAT_R16G16_FLOAT,flowAdaptPass_,0);
makeUav(context_.device(),nrFlow_.Get(),DXGI_FORMAT_R16G16_FLOAT,cpu(flowAdaptPass_,1));
makeUav(context_.device(),baseFlow_.Get(),DXGI_FORMAT_R16G16_FLOAT,cpu(flowAdaptPass_,2));
- if(desc_.hdrOutput&&videoSrInput_){
+ if(desc_.hdrWorking()&&videoSrInput_){
stagedSrv(srcRgba_.Get(),DXGI_FORMAT_R16G16B16A16_FLOAT,hdrVideoSrPass_,0);
stagedSrv(videoSrInput_.Get(),DXGI_FORMAT_R8G8B8A8_UNORM,hdrVideoSrPass_,1);
stagedSrv(videoSrOutput_.Get(),DXGI_FORMAT_R8G8B8A8_UNORM,hdrVideoSrPass_,2);
@@ -1169,6 +1184,8 @@ bool EnhanceGraph::createViews()
if(videoSrInput_&&viewsUav)makeUav(context_.device(),videoSrInput_.Get(),DXGI_FORMAT_R8G8B8A8_UNORM,cpu(blitPass_,16));
if(videoSrOutput_&&viewsTex)stagedSrv(videoSrOutput_.Get(),DXGI_FORMAT_R8G8B8A8_UNORM,blitPass_,17);
if (viewsTex) stagedSrv(residualRgba_.Get(),DXGI_FORMAT_R16G16B16A16_FLOAT,blitPass_,18);
+ if(videoHdrInput_&&viewsUav)makeUav(context_.device(),videoHdrInput_.Get(),DXGI_FORMAT_R8G8B8A8_UNORM,cpu(blitPass_,19));
+ if(videoHdrOutput_&&viewsTex)stagedSrv(videoHdrOutput_.Get(),DXGI_FORMAT_R16G16B16A16_FLOAT,blitPass_,20);
if (viewsTex) stagedSrv(srcRgba_.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, blitPass_, 0);
// Colour-grade tables: four SRVs at the extra table's fixed register base.
if(colorActive_){
@@ -1271,7 +1288,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
veyra::log::info("hdr-route",std::format("input={} range={} matrix=BT2020-NCL primaries=BT2020 decode={} working={} output={} toneMap={} hdrReferenceWhiteNits=203 hlgReferencePeakNits=1000; SDR workingTransfer field is unused for PQ/HLG",
resolved.transfer==TransferFunction::HLG?"HLG":"PQ",resolved.range==ColorRange::Full?"full":"limited",
resolved.transfer==TransferFunction::HLG?"inverse-OETF+OOTF-gamma1.2":"ST2084-EOTF-absolute-nits",
- desc_.hdrOutput?"linear-BT709-scRGB-1=80nits":"linear-BT709-SDR-relative",
+ desc_.hdrWorking()?"linear-BT709-scRGB-1=80nits":"linear-BT709-SDR-relative",
hdr10Output()?"PQ-BT2020-RGB10":desc_.hdrOutput?"scRGB-FP16":"sRGB-RGB8",
desc_.hdrOutput?"none":"BT2390-luminance+neutral-ray-gamut-compression"));
}
@@ -1509,7 +1526,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
float constants[12+kColorGradeConstantCount] = { resolved.range==ColorRange::Full?0.0f:1.0f,
resolved.matrix==YuvMatrix::BT2020NCL?2.0f:resolved.matrix==YuvMatrix::BT601?0.0f:1.0f,
resolved.transfer==TransferFunction::HLG?5.0f:resolved.transfer==TransferFunction::PQ?4.0f:float(workingTransferCode(resolved)), (nv12Texture?(nv12Texture->GetDesc().Format==DXGI_FORMAT_P010?1.0f:0.0f):(desc_.captureBitDepth==16?2.0f:desc_.wideYuvInput()?1.0f:0.0f)),
- uintBits(srcW_), uintBits(srcH_), uintBits((desc_.hdrOutput?1u:0u)|(resolved.primaries==ColorPrimaries::BT2020?2u:0u)),
+ uintBits(srcW_), uintBits(srcH_), uintBits((desc_.hdrWorking()?1u:0u)|(resolved.primaries==ColorPrimaries::BT2020?2u:0u)),
uintBits(resolved.reconstructChroma?std::max(1u,unsigned(resolved.chromaLocation)):0u),toneMapPeakNits_,203.0f,0,0 };
if(colorActive_)packColorGradeConstants(colorTables_,constants+12);
yuvPass_.bind(list, constants, gpuHandleOf(yuvPass_, nv12Texture ? 3 + parity * 2 : 0).ptr, gpuHandleOf(yuvPass_, 2).ptr,gpuHandleOf(yuvPass_,8).ptr);
@@ -1537,7 +1554,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
tracker_.transition(list,nvofInA_.Get(),D3D12_RESOURCE_STATE_COMMON);
}
tracker_.transition(list,nvofInB_.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- const float encodedDims[8] = {uintBits(srcW_),uintBits(srcH_),uintBits(nvofW_),uintBits(nvofH_),desc_.hdrOutput?3.0f:1.0f,0,0,0};
+ const float encodedDims[8] = {uintBits(srcW_),uintBits(srcH_),uintBits(nvofW_),uintBits(nvofH_),desc_.hdrWorking()?3.0f:1.0f,0,0,0};
blitPass_.bind(list,encodedDims,gpuHandleOf(blitPass_,15).ptr,gpuHandleOf(blitPass_,9).ptr);
list->Dispatch((nvofW_+15)/16,(nvofH_+15)/16,1);
tracker_.uavBarrier(list,nvofInB_.Get());
@@ -1635,13 +1652,13 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
} else if(srEnabled_&&videoSrBackend_){
gpuTimer_.mark(list,GpuStage::Sr);
tracker_.transition(list,videoSrInput_.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- const float enc[8]={uintBits(srcW_),uintBits(srcH_),uintBits(srcW_),uintBits(srcH_),desc_.hdrOutput?3.0f:1.0f,0,0,0};
+ const float enc[8]={uintBits(srcW_),uintBits(srcH_),uintBits(srcW_),uintBits(srcH_),desc_.hdrWorking()?3.0f:1.0f,0,0,0};
blitPass_.bind(list,enc,gpuHandleOf(blitPass_,desc_.nrBeforeSr?18:0).ptr,gpuHandleOf(blitPass_,16).ptr);list->Dispatch((srcW_+15)/16,(srcH_+15)/16,1);tracker_.uavBarrier(list,videoSrInput_.Get());
tracker_.transition(list,videoSrInput_.Get(),D3D12_RESOURCE_STATE_COMMON);tracker_.transition(list,videoSrOutput_.Get(),D3D12_RESOURCE_STATE_COMMON);
if(!videoSrBackend_->evaluate(list,videoSrInput_.Get(),videoSrOutput_.Get(),desc_.videoSrQuality)){failedBackend_=engine::FailedBackend::Sr;return false;}
tracker_.uavBarrier(list,videoSrOutput_.Get());tracker_.transition(list,videoSrOutput_.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);tracker_.transition(list,workRgba_.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
const float dec[8]={uintBits(workW_),uintBits(workH_),uintBits(workW_),uintBits(workH_),-1,0,0,0};
- if(desc_.hdrOutput){
+ if(desc_.hdrWorking()){
tracker_.transition(list,videoSrInput_.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
hdrVideoSrPass_.bind(list,dec,gpuHandleOf(hdrVideoSrPass_,desc_.nrBeforeSr?4:0).ptr,gpuHandleOf(hdrVideoSrPass_,3).ptr);
}else blitPass_.bind(list,dec,gpuHandleOf(blitPass_,17).ptr,gpuHandleOf(blitPass_,1).ptr);list->Dispatch((workW_+15)/16,(workH_+15)/16,1);tracker_.uavBarrier(list,workRgba_.Get());tracker_.transition(list,workRgba_.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
@@ -1700,7 +1717,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
list->Dispatch((nrW_+15)/16,(nrH_+15)/16,1);tracker_.uavBarrier(list,nrInput_.Get());tracker_.transition(list,nrInput_.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
}
tracker_.transition(list, proxyTex_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- const float constants[8] = { 1.0f, 1.0f, 1.0f, desc_.hdrOutput?1.0f:0.0f,
+ const float constants[8] = { 1.0f, 1.0f, 1.0f, desc_.hdrWorking()?1.0f:0.0f,
uintBits(nrW_), uintBits(nrH_), 0.0f, 0.0f };
encPass_.bind(list, constants, gpuHandleOf(encPass_, 0).ptr, gpuHandleOf(encPass_, 1).ptr);
list->Dispatch((nrW_ + 15) / 16, (nrH_ + 15) / 16, 1);
@@ -1768,7 +1785,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
}
// 4c. Parity decode.
tracker_.transition(nlist, finalRgba_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- const float constants[8] = { 1.0f, 1.0f, 1.0f, desc_.hdrOutput?1.0f:0.0f,
+ const float constants[8] = { 1.0f, 1.0f, 1.0f, desc_.hdrWorking()?1.0f:0.0f,
uintBits(nrW_), uintBits(nrH_), 0.0f, 0.0f };
decPass_.bind(nlist, constants, gpuHandleOf(decPass_, 0).ptr, gpuHandleOf(decPass_, 3).ptr);
nlist->Dispatch((nrW_ + 15) / 16, (nrH_ + 15) / 16, 1);
@@ -1782,16 +1799,31 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
if(nrEnabled_&&nrHandle_){
gpuTimer_.mark(list,GpuStage::Residual);
tracker_.transition(list,residualRgba_.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- const auto& r=desc_.residual;float c[24]={r.total,r.darken,r.brighten,r.color,r.luminance,desc_.protection.enabled?1.0f:0.0f,desc_.protection.featherPixels,desc_.hdrOutput?1.0f:0.0f};
+ const auto& r=desc_.residual;float c[24]={r.total,r.darken,r.brighten,r.color,r.luminance,desc_.protection.enabled?1.0f:0.0f,desc_.protection.featherPixels,desc_.hdrWorking()?1.0f:0.0f};
for(size_t i=0;i<4;++i){const auto q=desc_.protection.regions[i];c[8+i*4]=q.left;c[9+i*4]=q.top;c[10+i*4]=q.right;c[11+i*4]=q.bottom;}
residualPass_.bind(list,c,gpuHandleOf(residualPass_,0).ptr,gpuHandleOf(residualPass_,3).ptr);
list->Dispatch(((desc_.nrBeforeSr?srcW_:workW_)+15)/16,((desc_.nrBeforeSr?srcH_:workH_)+15)/16,1);tracker_.uavBarrier(list,residualRgba_.Get());tracker_.transition(list,residualRgba_.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);gpuTimer_.mark(list,GpuStage::Residual,true);
}
if(desc_.nrBeforeSr&&!runSr())return false;
+ if(videoHdrBackend_){
+ gpuTimer_.mark(list,GpuStage::VideoHdr);
+ tracker_.transition(list,videoHdrInput_.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ const float encode[8]={uintBits(workW_),uintBits(workH_),uintBits(workW_),uintBits(workH_),1,0,0,0};
+ blitPass_.bind(list,encode,gpuHandleOf(blitPass_,2).ptr,gpuHandleOf(blitPass_,19).ptr);
+ list->Dispatch((workW_+15)/16,(workH_+15)/16,1);tracker_.uavBarrier(list,videoHdrInput_.Get());
+ tracker_.transition(list,videoHdrInput_.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ tracker_.transition(list,videoHdrOutput_.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ if(!videoHdrBackend_->evaluate(list,videoHdrInput_.Get(),videoHdrOutput_.Get(),desc_.videoHdr)){
+ failedBackend_=engine::FailedBackend::VideoHdr;return false;
+ }
+ tracker_.uavBarrier(list,videoHdrOutput_.Get());
+ tracker_.transition(list,videoHdrOutput_.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ gpuTimer_.mark(list,GpuStage::VideoHdr,true);
+ }
// 5. Working frame -> SDR RGBA8 videoFrame[parity] + NVOF chain.
{
- const UINT srcSlot = 2;
+ const UINT srcSlot = videoHdrBackend_?20:2;
const UINT uavSlot = 3 + parity;
tracker_.transition(list, (nrEnabled_ && nrHandle_ != nullptr && !desc_.nrBeforeSr) ? residualRgba_.Get() : workRgba_.Get(),
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
@@ -1939,6 +1971,8 @@ bool EnhanceGraph::applySettings(const engine::EnhancementSettings& s){
// The colour master switch changes the graph shape (tables + shader branch)
// and must rebuild; every other colour field is a live uniform update.
if(s.color.enabled!=desc_.color.enabled)return false;
+ if(s.videoHdr.enabled!=desc_.videoHdr.enabled)return false;
+ desc_.videoHdr=s.videoHdr;
// Switching the referenced .cube re-stages a descriptor, which needs the
// queue drained: treat it as a rebuild (parameters stay live).
if(s.color.lutNameString()!=desc_.color.lutNameString())return false;
@@ -2022,6 +2056,7 @@ void EnhanceGraph::shutdown()
upFsrSrDepth_.Reset();
if (fgBackend_) fgBackend_->release();
if(videoSrBackend_){videoSrBackend_->release();videoSrBackend_.reset();}
+ videoHdrBackend_.reset();videoHdrInput_.Reset();videoHdrOutput_.Reset();
if (srBackend_) srBackend_->release();
// NVOF teardown in THREE phases (ownership rule proven by t10-L0-r2):
diff --git a/tests/integration/VideoHdrTests.cpp b/tests/integration/VideoHdrTests.cpp
new file mode 100644
index 00000000..c6d3a999
--- /dev/null
+++ b/tests/integration/VideoHdrTests.cpp
@@ -0,0 +1,77 @@
+#include "veyra/pipeline/EnhanceGraph.h"
+#include "veyra/RuntimePaths.h"
+#include "veyra/gfx/D3D12DeviceContext.h"
+#include "veyra/gfx/CommandSlotRing.h"
+#include "veyra/source/MediaFileSource.h"
+#include "veyra/sink/ImageExportSink.h"
+#include <DirectXPackedVector.h>
+#include <algorithm>
+#include <cmath>
+#include <iostream>
+extern "C" {
+#include <libavutil/frame.h>
+}
+using namespace veyra;
+using namespace veyra::pipeline;
+
+// Diagnostic readback only. The product conversion stays on the GPU.
+static bool pixels(gfx::D3D12DeviceContext& ctx,gfx::CommandSlotRing& ring,ID3D12Resource* texture,std::vector<float>& result){
+ const auto d=texture->GetDesc();D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{};UINT64 bytes=0;
+ ctx.device()->GetCopyableFootprints(&d,0,1,0,&fp,nullptr,nullptr,&bytes);
+ D3D12_HEAP_PROPERTIES hp{};hp.Type=D3D12_HEAP_TYPE_READBACK;
+ D3D12_RESOURCE_DESC bd{};bd.Dimension=D3D12_RESOURCE_DIMENSION_BUFFER;bd.Width=bytes;bd.Height=1;bd.DepthOrArraySize=bd.MipLevels=1;bd.SampleDesc.Count=1;bd.Layout=D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
+ ComPtr<ID3D12Resource> buffer;if(FAILED(ctx.device()->CreateCommittedResource(&hp,D3D12_HEAP_FLAG_NONE,&bd,D3D12_RESOURCE_STATE_COPY_DEST,nullptr,IID_PPV_ARGS(&buffer))))return false;
+ unsigned slot=0;Status status;auto* list=ring.acquireNext(slot,status);if(!list)return false;
+ StateTracker states;states.transition(list,texture,D3D12_RESOURCE_STATE_COPY_SOURCE);
+ D3D12_TEXTURE_COPY_LOCATION src{},dst{};src.pResource=texture;src.Type=D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
+ dst.pResource=buffer.Get();dst.Type=D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;dst.PlacedFootprint=fp;
+ list->CopyTextureRegion(&dst,0,0,0,&src,nullptr);states.transition(list,texture,D3D12_RESOURCE_STATE_COMMON);
+ if(!ring.submitAndSignal(slot)||!ring.waitIdle())return false;
+ void* p=nullptr;D3D12_RANGE range{0,size_t(bytes)};if(FAILED(buffer->Map(0,&range,&p)))return false;
+ result.resize(size_t(d.Width)*d.Height*3);
+ for(unsigned y=0;y<d.Height;++y)for(unsigned x=0;x<d.Width;++x)for(unsigned c=0;c<3;++c){
+ const auto* row=static_cast<const uint8_t*>(p)+fp.Offset+y*fp.Footprint.RowPitch;
+ float value=0;
+ if(d.Format==DXGI_FORMAT_R16G16B16A16_FLOAT)value=DirectX::PackedVector::XMConvertHalfToFloat(reinterpret_cast<const uint16_t*>(row)[x*4+c]);
+ else if(d.Format==DXGI_FORMAT_R10G10B10A2_UNORM){const double coded=double((reinterpret_cast<const uint32_t*>(row)[x]>>(10*c))&1023)/1023;const double t=pow(coded,32.0/2523);value=float(125*pow(std::max(t-3424.0/4096,0.0)/(2413.0/128-2392.0/128*t),16384.0/2610));}
+ else {buffer->Unmap(0,nullptr);return false;}
+ result[(size_t(y)*d.Width+x)*3+c]=value;
+ }
+ D3D12_RANGE none{};buffer->Unmap(0,&none);return true;
+}
+int wmain(int argc,wchar_t** argv){
+ CoInitializeEx(nullptr,COINIT_MULTITHREADED);
+ gfx::D3D12DeviceContext ctx;gfx::CommandSlotRing ring;Status status;gfx::DeviceContextDesc dd;
+ if(!ctx.initialize(dd,status)||!ring.initialize(ctx.device(),ctx.directQueue(),ctx.fence(),ctx.fenceEvent(),4,status))return 2;
+ EnhanceGraph graph(ctx,ring);EnhanceGraphDesc gd;
+ gd.sourceWidth=gd.workWidth=gd.nrWidth=1280;gd.sourceHeight=gd.workHeight=gd.nrHeight=720;
+ gd.rgbInput=true;gd.enableNr=gd.enableSr=gd.enableFg=gd.enableNvofStandalone=false;
+ gd.videoHdr.enabled=true;gd.hdrOutput=true;gd.runtimeAbsPath=runtime::localRuntimeDirectory().wstring();
+ if(argc>1){const auto multiplier=unsigned(_wtoi(argv[1]));gd.fgMultiplier=std::max(2u,multiplier);gd.enableFg=multiplier>1;}
+ if(argc>2){gd.enableNr=_wtoi(argv[2])!=0;gd.enableNvofStandalone=gd.enableNr;}
+ if(argc>3){gd.enableSr=true;gd.workWidth=1920;gd.workHeight=1080;gd.videoSrQuality=unsigned(_wtoi(argv[3]));}
+ if(!graph.initialize(gd)||!graph.createViews()||!graph.videoHdrActive())return 3;
+ AVFrame* frame=av_frame_alloc();frame->format=AV_PIX_FMT_BGRA;frame->width=1280;frame->height=720;
+ frame->color_range=AVCOL_RANGE_JPEG;frame->color_primaries=AVCOL_PRI_BT709;frame->color_trc=AVCOL_TRC_IEC61966_2_1;
+ if(av_frame_get_buffer(frame,32)<0)return 4;
+ for(int y=0;y<720;++y)for(int x=0;x<1280;++x){auto* p=frame->data[0]+y*frame->linesize[0]+x*4;const uint8_t v=uint8_t(x*255/1279);p[0]=p[1]=p[2]=v;p[3]=255;}
+ bool ok=true;double peak=0,changed=0;std::vector<float> baseline;
+ unsigned generated=0;
+ for(unsigned n=0;n<12&&ok;++n){
+ if(n==6){engine::EnhancementSettings s;s.nr=gd.enableNr;s.sr=gd.enableSr;s.multiplier=gd.enableFg?gd.fgMultiplier:1;s.videoSrQuality=gd.videoSrQuality;s.videoHdr=gd.videoHdr;s.videoHdr.peakNits=400;ok=graph.applySettings(s);}
+ EnhanceGraph::FrameOutputs out;ok=ok&&graph.process(frame,n*1000.0/30,n==0||n==8,out,n+1);
+ if(!ok)break;
+ std::vector<float> data;ok=pixels(ctx,ring,graph.videoFrameResource(out.videoSlot),data);
+ if(!ok)break;
+ ok=std::all_of(data.begin(),data.end(),[](float v){return std::isfinite(v)&&v>=-.5f&&v<100;});
+ peak=*std::max_element(data.begin(),data.end())*80;
+ ok=ok&&peak>100&&peak<2100;
+ if(n==5)baseline=data;
+ if(n==11){for(size_t i=0;i<data.size();++i)changed+=std::abs(data[i]-baseline[i]);changed/=data.size();
+ ok=ok&&changed>.001&&sink::saveHdrScreenshot(L"video-hdr.jxr",ctx,ring,graph.videoFrameResource(out.videoSlot));}
+ if(gd.enableFg){ok=ok&&graph.resolveGeneration(out);if(out.hasGenerated)++generated;}
+ }
+ ok=ok&&(!gd.enableFg||generated>0);
+ std::cout<<"VIDEO_HDR pass="<<ok<<" peakNits="<<peak<<" parameterChange="<<changed<<" generatedBatches="<<generated<<" nr="<<graph.metrics().nrEvaluateCount<<" sr="<<graph.metrics().srEvaluateCount<<std::endl;
+ ring.drainQueue();graph.shutdown();av_frame_free(&frame);ring.shutdown();ctx.shutdown();CoUninitialize();return ok?0:5;
+}
diff --git a/tests/unit/RepairPresetTests.cpp b/tests/unit/RepairPresetTests.cpp
index 5e9019bc..0eac9ac3 100644
--- a/tests/unit/RepairPresetTests.cpp
+++ b/tests/unit/RepairPresetTests.cpp
@@ -42,7 +42,7 @@ bool legacyBackends(const std::filesystem::path& path) {
if(version>=7&&(value.audioSync!=AudioSyncMode::Manual||value.audioOffsetMs!=137))return false;
if(!store.put(L"legacy",value,true))return false;
std::ifstream file(path);std::string magic;int savedVersion=0;file>>magic>>savedVersion;
- if(magic!="VEYRA_PRESETS"||savedVersion!=19)return false; // schema v19 adds the per-section colour bypass
+ if(magic!="VEYRA_PRESETS"||savedVersion!=20||value.videoHdr.enabled)return false;
PresetStore reloaded(path);
if(!reloaded.load()||reloaded.defaultSettings()!=value)return false;
}else{
@@ -64,6 +64,7 @@ int main(int argc,char** argv){if(argc!=2)return 2;using namespace veyra::engine
s.srTarget=veyra::pipeline::SrTarget::Uhd8K;
s.audioSync=AudioSyncMode::Manual;s.audioOffsetMs=137;
s.nrRuntime=NrRuntime::Community;s.captureCompatible=true;s.lowLatency=true;s.forceSdrPreview=true;
+s.videoHdr={true,110,80,45,800};
// Colour grade round-trips through schema v18 (plan P1: named colour presets).
s.color.temperature=-40;s.color.tint=7.5f;s.color.exposure=1.25f;s.color.contrast=-12.5f;s.color.highlights=18;s.color.shadows=-22;
s.color.whites=9;s.color.blacks=-4;s.color.vibrance=33;s.color.saturation=-8;
@@ -81,6 +82,7 @@ auto badGrading=s;badGrading.color.grading[2].hue=400;ok=ok&&!b.put(L"invalid gr
auto badCurve=s;badCurve.color.curves[1].count=3;badCurve.color.curves[1].points[1]={0.6f,0.5f};badCurve.color.curves[1].points[2]={0.2f,0.7f};ok=ok&&!b.put(L"unsorted curve",badCurve);
auto badLut=s;badLut.color.lutInputSpace=3;ok=ok&&!b.put(L"invalid lut space",badLut);
auto badExposure=s;badExposure.color.exposure=6;ok=ok&&!b.put(L"invalid exposure",badExposure);
+auto badHdr=s;badHdr.videoHdr.peakNits=2001;ok=ok&&!b.put(L"invalid HDR peak",badHdr);
ok=ok&&b.entries().size()==1&&b.defaultSettings()==s;
auto badTarget=s;badTarget.srTarget=static_cast<veyra::pipeline::SrTarget>(3);ok=ok&&!b.put(L"invalid target",badTarget);
diff --git a/tools/export_probe/main.cpp b/tools/export_probe/main.cpp
index f87820ce..d0af2e6a 100644
--- a/tools/export_probe/main.cpp
+++ b/tools/export_probe/main.cpp
@@ -16,17 +16,19 @@
int wmain(int argc, wchar_t** argv)
{
if (argc < 3) {
- std::fwprintf(stderr, L"usage: veyra_export_probe <input> <output> [--hevc] [--max-frames N]\n");
+ std::fwprintf(stderr, L"usage: veyra_export_probe <input> <output> [--hevc] [--video-hdr] [--max-frames N]\n");
return 2;
}
const std::wstring input = argv[1];
const std::wstring output = argv[2];
- bool hevc = false;
+ bool hevc = false, videoHdr = false;
unsigned maxFrames = 0;
for (int i = 3; i < argc; ++i) {
const std::wstring arg = argv[i];
if (arg == L"--hevc") {
hevc = true;
+ } else if (arg == L"--video-hdr") {
+ videoHdr = true;
} else if (arg == L"--max-frames" && i + 1 < argc) {
maxFrames = unsigned(std::wcstoul(argv[++i], nullptr, 10));
} else {
@@ -36,6 +38,7 @@ int wmain(int argc, wchar_t** argv)
}
veyra::engine::PlayerOptions options; // nr/sr/fg all off: decode -> encode only
+ options.settings.videoHdr.enabled = videoHdr;
std::atomic<bool> cancel{false};
const bool ok = veyra::engine::exportVideo(input, output, options, hevc, cancel,
[](double progress, const std::wstring& message) {