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++
test: record 8100 identical export frames and add bounded fallback checks
Veyra Goal Agentf94d0bca121e
diff --git a/docs/PERF_5B_CROSS_FRAME_2026-10-05.md b/docs/PERF_5B_CROSS_FRAME_2026-10-05.mdindex 533ff95b..845991f9 100644--- a/docs/PERF_5B_CROSS_FRAME_2026-10-05.md+++ b/docs/PERF_5B_CROSS_FRAME_2026-10-05.md@@ -21,3 +21,21 @@ build-export-baseline-v1 UI/probe构建成功,编译产品源码86e0458;只基线完整软件解码15/15、1620帧,三轮A-A全图/PTS/尺寸/轨道/时长完全一致;核实SR8K实际7680×4320,NR+SR实际3840×2160。review在E:/项目/Veyra/logs/perf-nr-20261004/B5b-serial-v2-decoded-review.json,framemd5每帧覆盖完整重建图。后续复用这些不可变源与已核验hash,避免无依据重复解码。候选实现:每个pending持有完整FrameOutputs/lease与NVENC转换consumerFence,最多两帧;在第3帧进入Graph前确认最旧producer+consumer完成并释放lease,末尾全部收齐再encoder.finish。Graph上传/allocator和NVENC4槽依赖不变。fence事件仅同一fence对象上的值取max,FG status仍完成后resolve;50ms有界wait、250ms健康检查和30s超时保留,事件注册失败记HRESULT并回退轮询。两个测试ENV分别启用,默认关闭,未测不标产品通过。++## 候选普通对照与完整输出++`nr-export-pipeline.py B2d B5b-candidate-v1 all none4k nr nr2 nrsr4k sr8k`60/60实际导出通过,五配置×四策略×三轮交错,同EXE/组件载荷前后SHA一致,无压力。`nr-export-report.py`核实每组策略实际生效、maxInFlight1/2、NR真实创建数与无ERROR,再输出comparison.json;初次报表因运行库写入非UTF8字节读失败,改errors=replace(仅ASCII字段解析),未删改raw日志。++| 三轮中位 | 串行总ms | 组合总ms | 总耗时降幅 | 串行处理ms | 组合处理ms | 处理降幅 |+|---|---:|---:|---:|---:|---:|---:|+| 普通4K / 120帧 | 2488.830 | 1384.420 | 44.37% | 1892.387 | 801.251 | 57.66% |+| 自然1080单NR / 120帧 | 4338.210 | 3314.370 | 23.60% | 1881.085 | 860.843 | 54.24% |+| 自然1080双NR / 120帧 | 5492.240 | 4712.150 | 14.20% | 1941.885 | 1614.626 | 16.85% |+| NR+SR4K / 120帧 | 7189.020 | 6727.860 | 6.41% | 3796.911 | 3226.199 | 15.03% |+| 4K→SR8K / 60帧 | 4649.890 | 4467.930 | 3.91% | 1901.832 | 1703.155 | 10.45% |++总耗时含初始化/最终保存;处理区间不含创建但含encoder.finish,不能将后二列当作整次导出改善。双NR初始化波动较大,组合总耗时范围4648.730–5127.380ms,完整范围在comparison.json。多数普通4K改善来自改变等待方式:仅fence事件处理814.877ms,组合801.251ms;单NR仅事件946.126ms,组合860.843ms,可见两帧并行的额外收益。8K仅事件1704.953ms,组合1703.155ms,不能宣称8K跨帧本身明显收益。++`nr-export-verify.py B5b-serial-v2 B5b-candidate-v1`75/75通过、8100完整decoded帧与PTS/尺寸/轨道/时长全部一致;所有策略生成的整个封装文件SHA也与各自A一致。收据B5b-candidate-v1-decoded-review.json,各原始framemd5/ffprobe保留。该验证覆盖当前本机/运行库/素材,不代表其他GPU、HDR或直播通过。++下一步单独验证GPU debug、取消、单帧、FG保持串行和事件API失败回退。只模拟API错误分支,不制造GPU压力或设备重置;候选继续默认关闭。diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex acc23dbe..ff51abc7 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -8302,3 +8302,5 @@ B4a-native-v2 20/20通过、800 PNG及逐图SHA/PTS保留;debug/设备移除05b serial-v2五组各三轮15/15实际完成,最终帧数/encoder drain通过,payload SHA全同。总耗时中位普通4K2.484s、单NR4.306s、双NR4.544s、NR+SR4K6.341s、SR8K4.400s。pipeline多组15.8ms/帧与Sleep(1)轮询有关联但根因待验证;下一候选独立测fence事件、两帧在途和组合,不能将两者混算。原全部导出/日志及基线EXE在B5b-serial-v2对应E盘目录。新增导出后全decoded frame/PTS/mux核对工具,当前先执行A-A。5b基线A-A完整1620 decoded帧及PTS/尺寸/轨道/时长15/15全同,8K实为7680×4320,收据B5b-serial-v2-decoded-review.json。新增默认关闭候选:两帧pending lease/producer/consumer fence严格有界、复用前GPU完成、NVENC独立inputFence;独立fence事件等待、失败回轮询、取消/健康/30秒保留。源码审查修正std::move(out)之后取real.lease的潜在空指针,改先保存consumerFence再move,未构建/执行有缺陷版本。两个机制分组计时,尚未标收益。++5b build-export-candidate-v1通过;60组普通同EXE串行/事件/两帧/组合三轮通过,payload全SHA保持,源帧/最终编码足量,maxInFlight1/2及真实NR数核实。组合总耗时普通4K降44.37%、单NR23.60%、双NR14.20%、NR+SR4K6.41%、SR8K3.91%;处理区间各降57.66/54.24/16.85/15.03/10.45%,明确不混算。完整75文件/8100decoded帧/PTS/尺寸/轨道/时长全同,连整个文件SHA也全同。E:/项目/Veyra/logs/perf-nr-20261004/B5b-candidate-v1-summary/comparison.json及B5b-candidate-v1-decoded-review.json。报表初读日志遇运行库非UTF8字节,errors=replace仅解析ASCII字段,raw未改。下一步仅必要debug/取消/单帧/FG串行/事件失败回退,不造GPU压力/设备重置;测试hook默认关闭。diff --git a/scripts/perf/nr-export-report.py b/scripts/perf/nr-export-report.pynew file mode 100644index 00000000..786b926b--- /dev/null+++ b/scripts/perf/nr-export-report.py@@ -0,0 +1,33 @@+"""Summarize matched ordinary exports, separating complete job and processing costs."""+from pathlib import Path+import json,re,statistics,sys+BASE=Path('E:/项目/Veyra');TASK='perf-nr-20261004';label=sys.argv[1]+folder=BASE/'logs'/TASK/(label+'-summary');data=json.loads((folder/'summary.json').read_text(encoding='utf-8'));rows=[]+for run in data['runs']:+ assert run['passed'];line=run['pipeline'][-1];values=dict(re.findall(r'(\w+)=([-\w.]+)',line))+ expectedMode='async' if run['mode'] in ('async','async-events') and run['group']!='fg2' else 'serial'+ assert values['mode']==expectedMode,(run['name'],values)+ assert values['fenceEvents']==('true' if run['mode'] in ('events','async-events') else 'false'),(run['name'],values)+ assert int(values['maxInFlight'])==(2 if expectedMode=='async' else 1)+ log=(BASE/'logs'/TASK/run['name']/'engine.log').read_text(encoding='utf-8',errors='replace')+ layers=2 if run['group']=='nr2' else 1 if run['group'] in ('nr','nrsr4k') else 0+ assert log.count('snippet CreateFeature id=18 result=0x1')==layers,(run['name'],'NR creation count')+ assert '[ERROR]' not in log,run['name']+ rows.append({'name':run['name'],'group':run['group'],'mode':run['mode'],'repeat':run['repeat'],'totalMs':run['metrics']['totalMs'],+ 'pipelineMs':float(values['pipelineMs']),'completionWaitMs':float(values['completionWaitMs']),'maxInFlight':int(values['maxInFlight']),+ 'outputSha256':run['outputSha256'],'beforeGpu':run['beforeGpu'],'afterGpu':run['afterGpu']})+summary={}+for group in dict.fromkeys(r['group'] for r in rows):+ summary[group]={}+ for mode in dict.fromkeys(r['mode'] for r in rows if r['group']==group):+ current=[r for r in rows if r['group']==group and r['mode']==mode];summary[group][mode]={}+ for key in ('totalMs','pipelineMs','completionWaitMs'):+ values=[r[key] for r in current];summary[group][mode][key]={'median':statistics.median(values),'min':min(values),'max':max(values),'runs':values}+ for mode in summary[group]:+ if mode!='serial':+ for key in ('totalMs','pipelineMs'):+ summary[group][mode][key]['reductionPercent']=100*(1-summary[group][mode][key]['median']/summary[group]['serial'][key]['median'])+path=folder/'comparison.json';assert not path.exists();path.write_text(json.dumps({'runs':rows,'summary':summary,'payloadUnchanged':data['payloadUnchanged'],'extraGpuLoad':False,+ 'note':'Whole export includes initialization/mux save. Pipeline starts after encoder/header and includes final drain. Fence events and two-in-flight are independent.'},ensure_ascii=False,indent=2),encoding='utf-8')+for group,modes in summary.items():+ for mode,v in modes.items():print(group,mode,'totalMs=',round(v['totalMs']['median'],3),'pipelineMs=',round(v['pipelineMs']['median'],3),'totalReduction=',round(v['totalMs'].get('reductionPercent',0),2),'pipelineReduction=',round(v['pipelineMs'].get('reductionPercent',0),2))diff --git a/src/engine/VideoExportJob.cpp b/src/engine/VideoExportJob.cppindex 499352ef..8a62d8cf 100644--- a/src/engine/VideoExportJob.cpp+++ b/src/engine/VideoExportJob.cpp@@ -18,6 +18,7 @@#include <cstring>#include <vector>#include <wrl/client.h>+#include <d3d12sdklayers.h>extern "C" {#include <libavformat/avformat.h>#include <libavcodec/avcodec.h>@@ -60,6 +61,7 @@ bool exportVideo(const std::wstring& input,const std::wstring& output,PlayerOptiif(partial.empty()){progress(0,failureReason);return false;}try { do {Status st=Status::Ok;gfx::DeviceContextDesc dd;dd.commandSlotCount=6;+ dd.enableDebugLayer=GetEnvironmentVariableW(L"VEYRA_TEST_EXPORT_DEBUG",nullptr,0)>0;if(!ctx.initialize(dd,st)||!ring.initialize(ctx.device(),ctx.directQueue(),ctx.fence(),ctx.fenceEvent(),6,st))break;// Export runs on every adapter now: NVIDIA uses NVENC (D3D12,// zero-copy) and everything else uses the driver's Media Foundation@@ -224,8 +226,9 @@ bool exportVideo(const std::wstring& input,const std::wstring& output,PlayerOpti!options.fg&&encoder->backend()==sink::EncoderBackend::Nvenc&&slowFrameIndex<0;bool fenceEvents=GetEnvironmentVariableW(L"VEYRA_TEST_EXPORT_FENCE_EVENTS",nullptr,0)>0;if(fenceEvents){- completionEvent.value=CreateEventW(nullptr,FALSE,FALSE,nullptr);- if(!completionEvent.value){veyra::log::warn("export-pipeline",std::format("completion event create failed error={}; keeping polling",GetLastError()));fenceEvents=false;}+ const bool injected=GetEnvironmentVariableW(L"VEYRA_TEST_EXPORT_EVENT_CREATE_FAIL",nullptr,0)>0;+ if(!injected)completionEvent.value=CreateEventW(nullptr,FALSE,FALSE,nullptr);+ if(!completionEvent.value){veyra::log::warn("export-pipeline",std::format("completion event create failed error={} injected={}; keeping polling",injected?ERROR_INVALID_HANDLE:GetLastError(),injected));fenceEvents=false;}}struct PendingFrame {pipeline::EnhanceGraph::FrameOutputs output;uint64_t consumerFence=0,source=0;std::chrono::steady_clock::time_point submitted;};std::deque<PendingFrame> pendingFrames;unsigned maxInFlight=1;@@ -255,9 +258,10 @@ bool exportVideo(const std::wstring& input,const std::wstring& output,PlayerOptiveyra::log::error("export","frame GPU completion timed out after 30s");break;}if(fenceEvents&&commonFence&&!injectedStall&&!eventRegistered){- const HRESULT hr=ctx.fence()->SetEventOnCompletion(waitFence,completionEvent.value);+ const bool injected=GetEnvironmentVariableW(L"VEYRA_TEST_EXPORT_EVENT_REGISTER_FAIL",nullptr,0)>0;+ const HRESULT hr=injected?E_FAIL:ctx.fence()->SetEventOnCompletion(waitFence,completionEvent.value);if(SUCCEEDED(hr))eventRegistered=true;- else {veyra::log::warn("export-pipeline",std::format("completion event registration failed hr=0x{:X}; keeping polling",unsigned(hr)));fenceEvents=false;}+ else {veyra::log::warn("export-pipeline",std::format("completion event registration failed hr=0x{:X} injected={}; keeping polling",unsigned(hr),injected));fenceEvents=false;}}if(eventRegistered){const DWORD result=WaitForSingleObject(completionEvent.value,50);@@ -367,7 +371,18 @@ bool exportVideo(const std::wstring& input,const std::wstring& output,PlayerOptiok=written>0;if(counts)counts({sourceCount,generatedCount,holdCount,uint64_t(written)});}while(false); }catch(const std::exception& e){veyra::log::error("export",std::format("exception: {}",e.what()));failureReason=L"导出异常,请查看诊断";ok=false;}encoder.reset();if(mux){if(mux->pb){const int rc=avio_closep(&mux->pb);if(rc<0){failAv(L"刷新并关闭输出文件",rc);ok=false;}}avformat_free_context(mux);}- ring.drainQueue();graph.shutdown();source.close();ring.shutdown();ctx.shutdown();+ ring.drainQueue();graph.shutdown();source.close();ring.shutdown();+ if(GetEnvironmentVariableW(L"VEYRA_TEST_EXPORT_DEBUG",nullptr,0)>0&&ctx.device()){+ Microsoft::WRL::ComPtr<ID3D12InfoQueue> debug;const HRESULT hr=ctx.device()->QueryInterface(IID_PPV_ARGS(&debug));unsigned errors=0;+ if(FAILED(hr)){ok=false;veyra::log::error("export-debug",std::format("InfoQueue query failed hr=0x{:X}",unsigned(hr)));}+ else for(UINT64 i=0;i<debug->GetNumStoredMessages();++i){+ SIZE_T bytes=0;debug->GetMessage(i,nullptr,&bytes);std::vector<unsigned char> storage(bytes);auto* message=reinterpret_cast<D3D12_MESSAGE*>(storage.data());+ if(FAILED(debug->GetMessage(i,message,&bytes))){ok=false;++errors;continue;}+ if(message->Severity<=D3D12_MESSAGE_SEVERITY_ERROR){++errors;veyra::log::error("export-debug",message->pDescription);}+ }+ if(errors)ok=false;veyra::log::info("export-debug",std::format("errors={} removedReason=0x{:X}",errors,unsigned(ctx.device()->GetDeviceRemovedReason())));+ }+ ctx.shutdown();// Earlier processes of this job stopped at a GPU reset: join their parts and this// one into the output. The parts are removed only once the joined file is complete.std::wstring finished=partial;