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: seal measured baseline and add Feature18 dynamic-size experiment
Veyra Goal Agenteb47ed6928fa
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 0dd4e9f1..b5c1eb2c 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -1001,6 +1001,10 @@ add_executable(veyra_sr_reconstruction_tests tests/integration/SrReconstructionTadd_executable(veyra_nr_video_quality_probe tests/integration/NrVideoQualityProbe.cpp)target_compile_features(veyra_nr_video_quality_probe PRIVATE cxx_std_20)target_link_libraries(veyra_nr_video_quality_probe PRIVATE veyra_engine)+ add_executable(veyra_nr_dynamic_size_experiment tests/perf/NrDynamicSizeExperiment.cpp)+ target_compile_features(veyra_nr_dynamic_size_experiment PRIVATE cxx_std_20)+ target_compile_options(veyra_nr_dynamic_size_experiment PRIVATE /utf-8)+ target_link_libraries(veyra_nr_dynamic_size_experiment PRIVATE veyra_ngx)target_compile_features(veyra_nr_temporal_gpu_tests PRIVATE cxx_std_20)target_link_libraries(veyra_nr_temporal_gpu_tests PRIVATE veyra_pipeline)add_executable(veyra_gpu_timing_tests tests/integration/GpuTimingTests.cpp)diff --git a/docs/PERF_BASELINE_NR_2026-10-04.md b/docs/PERF_BASELINE_NR_2026-10-04.mdnew file mode 100644index 00000000..5c48107e--- /dev/null+++ b/docs/PERF_BASELINE_NR_2026-10-04.md@@ -0,0 +1,35 @@+# 优化前基线 A(2026-10-04,持续补齐)++## 固定身份与方法++产品源码 `8cdc612120cbf23ba116a33c3cb0a53e2043f718`,含尚未公开的RTSS重启、字幕、自定义倍速、UI热路径和专业布局/全屏恢复修复。全新构建时文档提交 `37bc0c090918566f7ebebc9f5edb24ba60c5f5a3`;未改产品C++/QML。RTX5070,实际驱动 **616.56**,与用户另一台机器的616.92不混同。窗口1280×800、GPU界面;NR时域抗闪关闭,低延迟关闭,各轮设置一致。++- EXE SHA256:`b7081f0e6045bc791105bc80de364247e169e3522891ef50cf9f62bbbfc10eb4`。+- NR默认Lecram310.8.3.0、HashMismatch社区原字节:`f95feb54137ea11979f9b4ec4f00afd84b5c98a5624d3388fbf6a87714a39fcc`。+- M1 GTA6 1920×1080/30、60秒源:`03b2a0dc7f682a2c70ae65809d4db69c725a95f49e60116b6e9da2e2ae4610c8`。+- 构建:`nr-build.py A build-A-v1 veyra_qml_ui veyra_nr_video_quality_probe veyra_export_probe`,476步exit0。+- 测量:`nr-series.py A`,五组各三轮真实产品正常退出/PASS,50秒稳态请求,统计位置10–48秒的滚动日志观测。每组报告“每轮滚动观测中位数”的三轮中位数及范围,**不是全部帧的总体P95**。软件提交/GPU timestamp/CPU Timer都不是物理显示刷新或端到端延迟。++## M1 三轮基线++单位ms;括号为三轮最小–最大。这里记录现有设置差异,**没有本轮优化收益**。++| 设置 | enhancementProcessingMs | 日志gpuNrP95Ms | 日志gpuSrP95Ms | 日志gpuResidualP95Ms |+|---|---:|---:|---:|---:|+| S1 单NR,1920×1080 | 7.7145(7.6845–7.723) | 7.0645(7.036–7.086) | 0 | 0.057 |+| S2-720 单NR,1280×720 | 4.6975(4.683–4.707) | 4.246(4.1805–4.269) | 0 | 0.057 |+| S3 NR实时1080+DLSS SR 4K | 11.3565(11.347–11.377) | 7.156(7.135–7.281) | 3.634(3.629–3.652) | 0.536 |+| S4 两NR实时1080+DLSS SR 4K+DLSS FG2X | 21.192(21.173–21.204) | 7.202(7.188–7.212) | 3.692(3.667–3.783) | 0.895 |+| S5 现有三层480/720/原生组合 | 14.372(13.59–14.377) | 7.233(6.626–7.257) | 0 | 0.262 |++现有gpuNrP95字段不能直接当多层NR总耗时;后续按独立层计时与整链ready时间判断。全部previewSkipped滚动计数中位0;S4 expiredGenerated中位2,不能声称补帧没有过期。S5第二轮约5.4%较快,保留全部原始数据和频率记录,后续小于该量级的S5收益不能凭单次测试确认。不同设置GPU自动频率不同(约2370–2880MHz),不强行锁频或修改用户驱动。++原UI没有精确50%档位,720p为输入维度66.7%、像素44.4%。各层不同尺寸已经实现,S5不计作新增功能。++## 原始证据与封存++`E:/项目/Veyra/logs/perf-nr-20261004/baseline-M1-summary.json` 保存所有15轮路径和SHA;各目录含player.log、console.log、meters.json、timing.csv、result.json和driver.log,全部通过退出/效果生效检查。++完整A目录:`E:/项目/Veyra/test-packages/perf-nr-20261004/Veyra-2.0.3-perf-baseline-A-NVIDIA-win64-portable`,1542载荷,独立manifest核对SHA;新EXE/QML独立、依赖仅硬链接不可变原字节。所有QML与起点8cdc逐文件文本一致,没有测试Loader。该目录与带测试Loader的`tests/perf-nr-20261004/app-A`分开。++当前M1基线已完成;4K、黑边、节奏、8K导出、切换/暂停基线会在对应节点产品改动前补齐。真实主机、其他GPU、物理显示事件与外部Magpie参照尚未测;不得将合成素材或当前M1结论冒充这些验收。diff --git a/docs/PERF_EXECUTION_NR_2026-10-04.md b/docs/PERF_EXECUTION_NR_2026-10-04.mdindex fd5011f3..464bb3bd 100644--- a/docs/PERF_EXECUTION_NR_2026-10-04.md+++ b/docs/PERF_EXECUTION_NR_2026-10-04.md@@ -24,7 +24,7 @@| 节点 | 内容 | 状态 | 证据 / 下一步 ||---|---|---|---|| D0 | 项目文档对齐与存档 | accepted | 37bc0c0 / initial-docs完整bundle verify,桌面/main保持 |-| A0 | 当前版本基线及矩阵驱动 | in-progress | A全新476步构建通过;M1五种现有设置各三轮真实播放器计时中 |+| A0 | 当前版本基线及矩阵驱动 | in-progress | A完整包封存;M1五组各三轮15/15通过,PERF_BASELINE_NR;其余素材/切换基线在各节点前补齐 || E1 | Feature18动态输入尺寸 | pending | 原版/Lecram分别测返回值、画面、历史 || E2 | 并行Evaluate/CreateFeature | pending | 独立command list、压力/反复切换 || E3 | 真实来源精确重复比例 | pending | 屏幕/实卡可用性与合成节奏分开 |diff --git a/scripts/perf/nr-baseline-report.py b/scripts/perf/nr-baseline-report.pynew file mode 100644index 00000000..da1c5d39--- /dev/null+++ b/scripts/perf/nr-baseline-report.py@@ -0,0 +1,68 @@+"""Seal the unchanged product baseline and summarize three repeated GPU runs."""+from pathlib import Path+import importlib.util+import json+import shutil+import statistics+import subprocess+import sys++ROOT = Path(__file__).resolve().parents[2]+BASE = Path('E:/项目/Veyra')+TASK = 'perf-nr-20261004'+spec = importlib.util.spec_from_file_location('perf_matrix', ROOT / 'scripts/perf/nr-matrix.py')+matrix = importlib.util.module_from_spec(spec)+spec.loader.exec_module(matrix)+subprocess.run([sys.executable, '-B', str(ROOT / 'scripts/perf/nr-control.py'), 'guard'], check=True)+runs = []+for setting in matrix.CONFIGS:+ for repeat in range(1, 4):+ path = BASE / 'logs' / TASK / f'A-M1-{setting}-r{repeat}' / 'result.json'+ result = json.loads(path.read_text(encoding='utf-8'))+ assert result['passed'], path+ runs.append((path, result))+assert len({r['exeSha256'] for _, r in runs}) == 1+assert len({r['runtimeSha256'] for _, r in runs}) == 1+assert len({r['sourceSha256'] for _, r in runs}) == 1+columns = ('enhancementProcessingMs', 'gpuNrP95Ms', 'gpuSrP95Ms', 'gpuFlowP95Ms',+ 'gpuResidualP95Ms', 'gpuReadyP95Ms', 'presentP95Ms', 'vramUsageMiB',+ 'previewSkipped', 'expiredGenerated', 'slotWaits')+summary = []+for setting in matrix.CONFIGS:+ group = [r for _, r in runs if r['setting'] == setting]+ data = {}+ for key in columns:+ values = [r['summary'][key]['medianOfRollingObservations'] for r in group if key in r['summary']]+ if values:+ data[key] = {'medianOfThreeRuns': statistics.median(values), 'min': min(values), 'max': max(values), 'runValues': values}+ summary.append({'setting': setting, 'actualConfig': matrix.CONFIGS[setting], 'metrics': data})+package = BASE / 'test-packages' / TASK / 'Veyra-2.0.3-perf-baseline-A-NVIDIA-win64-portable'+assert not package.exists()+shutil.copytree(matrix.PACKAGE, package, copy_function=matrix.copy_dependency,+ ignore=shutil.ignore_patterns('*.log', 'logs', 'user-data-2.0.0', '*.dmp'))+shutil.copy2(BASE / 'build' / TASK / 'A/veyra_qml_ui.exe', package / 'veyra_qml_ui.exe')+assert matrix.digest(package / 'veyra_qml_ui.exe') == runs[0][1]['exeSha256']+main = (package / 'qml/Veyra/Main.qml').read_text(encoding='utf-8')+assert 'NrPerfProbe' not in main and not (package / 'qml/Veyra/NrPerfProbe.qml').exists()+for path in (package / 'qml/Veyra').glob('*.qml'):+ relative = path.relative_to(package).as_posix()+ before = subprocess.check_output(['git', '-C', str(ROOT), 'show', '8cdc612120cbf23ba116a33c3cb0a53e2043f718:' + relative])+ assert path.read_text(encoding='utf-8').replace('\r\n', '\n') == before.decode('utf-8').replace('\r\n', '\n'), relative+files = [{'path': p.relative_to(package).as_posix(), 'size': p.stat().st_size, 'sha256': matrix.digest(p)}+ for p in sorted(package.rglob('*')) if p.is_file() and p.name != 'local-package-manifest.json']+manifest = {'purpose': 'Unchanged product baseline A; local-only',+ 'productSource': '8cdc612120cbf23ba116a33c3cb0a53e2043f718',+ 'buildSourceWithDocs': '37bc0c090918566f7ebebc9f5edb24ba60c5f5a3',+ 'exeSha256': runs[0][1]['exeSha256'], 'files': files}+(package / 'local-package-manifest.json').write_text(json.dumps(manifest, ensure_ascii=False, indent=2), encoding='utf-8')+receipt = {'productSource': manifest['productSource'], 'buildSourceWithDocs': manifest['buildSourceWithDocs'],+ 'package': str(package), 'payloadFiles': len(files), 'source': str(matrix.SOURCES['M1']),+ 'sourceSha256': runs[0][1]['sourceSha256'], 'runtimeSha256': runs[0][1]['runtimeSha256'],+ 'exeSha256': manifest['exeSha256'], 'driver': runs[0][1]['beforeGpu']['driver'],+ 'measurement': 'Median/range of each run median of rolling observations; not global percentiles or scanout',+ 'window': '1280x800', 'groups': summary,+ 'rawResults': [{'path': str(p), 'sha256': matrix.digest(p)} for p, _ in runs]}+path = BASE / 'logs' / TASK / 'baseline-M1-summary.json'+with path.open('x', encoding='utf-8') as out:+ json.dump(receipt, out, ensure_ascii=False, indent=2)+print(json.dumps({k: receipt[k] for k in ('package', 'payloadFiles', 'driver', 'groups')}, ensure_ascii=False))diff --git a/tests/perf/NrDynamicSizeExperiment.cpp b/tests/perf/NrDynamicSizeExperiment.cppnew file mode 100644index 00000000..6660af5c--- /dev/null+++ b/tests/perf/NrDynamicSizeExperiment.cpp@@ -0,0 +1,57 @@+#include "NrExperimentalFixture.h"+#include "veyra/Log.h"+#include <d3d12sdklayers.h>++// E1: maximum-created feature vs independently-created exact-size feature.+// CLI: runtime-dir output-dir subrect|dimensions full|small+int wmain(int argc,wchar_t** argv) {+ using namespace nrperf;+ if(argc!=5)return 2;+ const bool dimensions=std::wstring_view(argv[3])==L"dimensions";+ const bool full=std::wstring_view(argv[4])==L"full";+ const std::filesystem::path out=argv[2];std::filesystem::create_directories(out);+ Logger::instance().openFile((out/L"engine.log").wstring());+ Session s;if(!s.init(argv[1]))return 2;+ bool pass=true;std::ofstream csv(out/L"observations.csv");+ csv<<"step,w,h,evaluateOK,changedActivePixels,unchangedSentinelPixels,outsideWrites,referenceDifferentBytes,referenceMeanAbsoluteError\n";+ {+ Feature dynamic(s);if(!dynamic.create(s.ring,1920,1080))return 2;+ const uint32_t widths[]={1920,1632,1344,1056,768,1920};+ for(unsigned step=0;step<std::size(widths);++step){+ const uint32_t w=widths[step],h=(w*9/16)&~1u,tw=full?1920:w,th=full?1080:h;+ const bool setup=dynamic.textures(s.ring,tw,th,w,h);+ bool evaluated=setup;+ for(unsigned frame=0;frame<5&&evaluated;++frame)evaluated=dynamic.evaluate(s.ring,w,h,frame==0,dimensions);+ const auto actual=setup?dynamic.read(s.ring):std::vector<uint8_t>{};+ Feature reference(s);bool refOK=reference.create(s.ring,w,h)&&reference.textures(s.ring,w,h,w,h);+ for(unsigned frame=0;frame<5&&refOK;++frame)refOK=reference.evaluate(s.ring,w,h,frame==0);+ const auto expected=refOK?reference.read(s.ring):std::vector<uint8_t>{};+ uint64_t changed=0,sentinel=0,outside=0,different=0,totalError=0;+ if(actual.size()==size_t(tw)*th*4&&expected.size()==size_t(w)*h*4){+ for(uint32_t y=0;y<th;++y)for(uint32_t x=0;x<tw;++x){const auto i=(size_t(y)*tw+x)*4;+ const bool untouched=actual[i]==17&&actual[i+1]==23&&actual[i+2]==29&&actual[i+3]==255;+ if(x<w&&y<h){changed+=!untouched;sentinel+=untouched;const auto j=(size_t(y)*w+x)*4;+ for(unsigned c=0;c<4;++c){different+=actual[i+c]!=expected[j+c];totalError+=unsigned(std::abs(int(actual[i+c])-int(expected[j+c])));}}+ else outside+=!untouched;+ }+ }+ const double error=double(totalError)/(double(w)*h*4);+ csv<<step<<','<<w<<','<<h<<','<<evaluated<<','<<changed<<','<<sentinel<<','<<outside<<','<<different<<','<<error<<'\n';csv.flush();+ auto dump=[&](const std::wstring& name,const auto& data){std::ofstream f(out/name,std::ios::binary);f.write(reinterpret_cast<const char*>(data.data()),std::streamsize(data.size()));};+ dump(L"dynamic-"+std::to_wstring(step)+L".rgba",actual);dump(L"reference-"+std::to_wstring(step)+L".rgba",expected);+ std::printf("STEP step=%u extent=%ux%u textures=%ux%u evaluated=%d reference=%d changed=%llu sentinel=%llu outside=%llu differentBytes=%llu mae=%.6f\n",+ step,w,h,tw,th,evaluated,refOK,changed,sentinel,outside,different,error);+ pass=pass&&evaluated&&refOK&&changed>size_t(w)*h/2&&sentinel==0&&outside==0&&different==0;+ if(!evaluated)break;+ }+ }+ s.ring.drainQueue();+ Microsoft::WRL::ComPtr<ID3D12InfoQueue> debug;unsigned errors=0;+ if(!hrOK(s.device.device()->QueryInterface(IID_PPV_ARGS(&debug)),"Debug.Query"))return 2;+ for(UINT64 i=0;i<debug->GetNumStoredMessages();++i){SIZE_T n=0;debug->GetMessage(i,nullptr,&n);+ std::vector<uint8_t> data(n);auto* m=reinterpret_cast<D3D12_MESSAGE*>(data.data());+ if(!hrOK(debug->GetMessage(i,m,&n),"Debug.Read"))return 2;+ if(m->Severity<=D3D12_MESSAGE_SEVERITY_ERROR){++errors;std::printf("DEBUG_ERROR %s\n",m->pDescription);}}+ std::printf("RESULT pass=%d debugErrors=%u deviceRemoved=0x%08X\n",pass,errors,unsigned(s.device.device()->GetDeviceRemovedReason()));+ return pass&&errors==0?0:1;+}diff --git a/tests/perf/NrExperimentalFixture.h b/tests/perf/NrExperimentalFixture.hnew file mode 100644index 00000000..a9f38b75--- /dev/null+++ b/tests/perf/NrExperimentalFixture.h@@ -0,0 +1,167 @@+#pragma once+// Test-only Feature-18 fixture. Uses product adapter/parameter contracts.+// All readbacks and waits belong to these experiments, never the player.+#include "veyra/gfx/D3D12DeviceContext.h"+#include "veyra/gfx/CommandSlotRing.h"+#include "veyra/pipeline/GpuPassUtils.h"+#include "veyra/ngx/NgxCoreHost.h"+#include "veyra/ngx/DlssNrRuntimeAdapter.h"+#include "veyra/ngx/NgxParameters.h"+#include "veyra/ngx/DlssNrParameters.h"+#include <chrono>+#include <cstdio>+#include <cstring>+#include <filesystem>+#include <fstream>+#include <iterator>+#include <memory>+#include <vector>++namespace nrperf {+using namespace veyra;+namespace p = ngx::dlssnr;+using pipeline::ComPtr;+inline double nowMs() { return std::chrono::duration<double,std::milli>(+ std::chrono::steady_clock::now().time_since_epoch()).count(); }+inline bool hrOK(HRESULT hr,const char* where) {+ if(SUCCEEDED(hr))return true;+ std::printf("HRESULT where=%s value=0x%08X\n",where,unsigned(hr));return false;+}+inline bool ngxOK(bool safe,uint64_t result,uint32_t seh,const char* where) {+ std::printf("NGX where=%s result=0x%llX seh=0x%X safe=%d\n",where,+ static_cast<unsigned long long>(result),seh,safe);+ return safe&&result==uint64_t(NVSDK_NGX_Result_Success)&&seh==0;+}+struct Session {+ gfx::D3D12DeviceContext device;+ gfx::CommandSlotRing ring;+ ngx::NgxCoreHost core;+ ngx::DlssNrRuntimeAdapter adapter;+ std::wstring root;+ bool init(const std::wstring& directory) {+ root=directory;Status s=Status::Ok;gfx::DeviceContextDesc d;d.enableDebugLayer=true;+ if(!device.initialize(d,s)||!ring.initialize(device.device(),device.directQueue(),+ device.fence(),device.fenceEvent(),4,s))return false;+ auto coreDirectory=std::filesystem::path(root);+ for(unsigned n=0;n<3&&!std::filesystem::exists(coreDirectory/L"../config/ngx-local.json");++n)+ coreDirectory=coreDirectory.parent_path();+ std::ifstream input(coreDirectory/L"../config/ngx-local.json");+ const std::string text((std::istreambuf_iterator<char>(input)),{});+ auto field=[&](const char* name){const auto a=text.find(std::string("\"")+name+'"');+ if(a==std::string::npos)return std::string{};const auto b=text.find('"',a+std::strlen(name)+2);+ const auto c=text.find('"',b+1);return b==std::string::npos||c==std::string::npos?std::string{}:text.substr(b+1,c-b-1);};+ const auto id=field("ngxProjectId"),ver=field("engineVersion");+ if(id.empty()||ver.empty()||!core.initialize(device.device(),coreDirectory.wstring(),id.c_str(),ver.c_str(),s)||+ !adapter.load(root,s)||!adapter.installCallerCompatibility(s))return false;+ uint64_t r=0;uint32_t e=0;const bool safe=adapter.snippetInitExt(device.device(),root,r,e);+ return ngxOK(safe,r,e,"InitExt");+ }+ ~Session(){if(ring.initialized())ring.drainQueue();adapter.unload();core.shutdown();ring.shutdown();device.shutdown();}+};++struct Feature {+ Session& session;+ NVSDK_NGX_Parameter* params=nullptr;+ NVSDK_NGX_Handle* handle=nullptr;+ ComPtr<ID3D12Resource> color,output,motion,depth;+ pipeline::StateTracker states;+ uint32_t textureWidth=0,textureHeight=0;+ explicit Feature(Session& s):session(s) {Status status;params=s.core.allocateParameters(status);}+ ~Feature(){release();if(params)session.core.destroyParameters(params);}+ bool release() {if(!handle)return true;uint64_t r=0;uint32_t e=0;+ const bool safe=session.adapter.snippetReleaseFeature(handle,r,e);handle=nullptr;+ return ngxOK(safe,r,e,"Release");}+ void dimensions(uint32_t w,uint32_t h) {+ ngx::ParameterBlock b(params);+ for(auto key:{p::kWidth,p::kInputWidth,p::kOutputWidth,p::kOutputDotWidth,p::kStdWidth})b.setU32(key,w);+ for(auto key:{p::kHeight,p::kInputHeight,p::kOutputHeight,p::kOutputDotHeight,p::kStdHeight})b.setU32(key,h);+ }+ bool create(gfx::CommandSlotRing& ring,uint32_t w,uint32_t h) {+ if(!params)return false;dimensions(w,h);ngx::ParameterBlock b(params);+ b.setU32(p::kUpscaling,0);b.setF32(p::kScale,1);b.setF32(p::kScalingRatio,1);+ b.setVoid(p::kComputeScalingRatioCallback,reinterpret_cast<void*>(&ngx::DlssNrRuntimeAdapter::scalingRatioCallback));+ b.setI32(p::kHintRenderPreset,0);b.setI32(p::kPerfQualityValue,1);+ b.setU32(p::kCreationNodeMask,1);b.setU32(p::kVisibilityNodeMask,1);+ Status s;uint32_t slot;auto* list=ring.acquireNext(slot,s);if(!list)return false;+ uint64_t r=0;uint32_t e=0;const auto start=nowMs();+ const bool safe=session.adapter.snippetCreateFeature(list,params,&handle,r,e);+ const bool ok=ngxOK(safe,r,e,"Create")&&handle;+ const bool submitted=ring.submitAndSignal(slot)&&ring.waitIdle();+ std::printf("CREATE width=%u height=%u cpuWithWaitMs=%.6f pass=%d\n",w,h,nowMs()-start,ok&&submitted);+ return ok&&submitted;+ }+ bool upload(gfx::CommandSlotRing& ring,ID3D12Resource* target,const std::vector<uint8_t>& pixels) {+ const auto desc=target->GetDesc();D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{};+ UINT rows=0;UINT64 rowBytes=0,total=0;+ session.device.device()->GetCopyableFootprints(&desc,0,1,0,&fp,&rows,&rowBytes,&total);+ if(pixels.size()!=rowBytes*rows)return false;+ auto buffer=pipeline::makeUploadBuffer(session.device.device(),total);if(!buffer)return false;+ void* data=nullptr;D3D12_RANGE empty{};if(!hrOK(buffer->Map(0,&empty,&data),"Upload.Map"))return false;+ for(UINT y=0;y<rows;++y)std::memcpy(static_cast<uint8_t*>(data)+fp.Offset+size_t(y)*fp.Footprint.RowPitch,+ pixels.data()+size_t(y)*rowBytes,size_t(rowBytes));buffer->Unmap(0,nullptr);+ Status s;uint32_t slot;auto* list=ring.acquireNext(slot,s);if(!list)return false;+ states.transition(list,target,D3D12_RESOURCE_STATE_COPY_DEST);+ D3D12_TEXTURE_COPY_LOCATION a{},b{};a.pResource=target;a.Type=D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;+ b.pResource=buffer.Get();b.Type=D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;b.PlacedFootprint=fp;+ list->CopyTextureRegion(&a,0,0,0,&b,nullptr);+ states.transition(list,target,D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);+ return ring.submitAndSignal(slot)&&ring.waitIdle();+ }+ bool textures(gfx::CommandSlotRing& ring,uint32_t tw,uint32_t th,uint32_t activeW,uint32_t activeH) {+ color=pipeline::makeTexture(session.device.device(),tw,th,DXGI_FORMAT_R8G8B8A8_UNORM,true);+ output=pipeline::makeTexture(session.device.device(),tw,th,DXGI_FORMAT_R8G8B8A8_UNORM,true);+ motion=pipeline::makeTexture(session.device.device(),tw,th,DXGI_FORMAT_R16G16_FLOAT,true);+ depth=pipeline::makeTexture(session.device.device(),tw,th,DXGI_FORMAT_R32_FLOAT,true);+ if(!color||!output||!motion||!depth)return false;+ textureWidth=tw;textureHeight=th;states={};std::vector<uint8_t> image(size_t(tw)*th*4,0),sentinel(image.size());+ for(uint32_t y=0;y<th;++y)for(uint32_t x=0;x<tw;++x){const auto i=(size_t(y)*tw+x)*4;+ image[i]=uint8_t(40+(x%activeW)*150/activeW);image[i+1]=uint8_t(50+(y%activeH)*140/activeH);+ image[i+2]=uint8_t((((x/31)^(y/23))&1)?190:60);image[i+3]=255;+ sentinel[i]=17;sentinel[i+1]=23;sentinel[i+2]=29;sentinel[i+3]=255;}+ const std::vector<uint8_t> zero(image.size(),0);+ return upload(ring,color.Get(),image)&&upload(ring,output.Get(),sentinel)&&+ upload(ring,motion.Get(),zero)&&upload(ring,depth.Get(),zero);+ }+ bool evaluate(gfx::CommandSlotRing& ring,uint32_t w,uint32_t h,bool reset,bool changeDimensions=false) {+ if(changeDimensions)dimensions(w,h);ngx::ParameterBlock b(params);+ b.setD3D12Resource(p::kColor,color.Get());b.setD3D12Resource(p::kOutput,output.Get());+ b.setD3D12Resource(p::kMVec,motion.Get());b.setD3D12Resource(p::kDepth,depth.Get());+ for(auto key:{p::kColorSubrectWidth,p::kOutputSubrectWidth,p::kMVecSubrectWidth,p::kDepthSubrectWidth})b.setU32(key,w);+ for(auto key:{p::kColorSubrectHeight,p::kOutputSubrectHeight,p::kMVecSubrectHeight,p::kDepthSubrectHeight})b.setU32(key,h);+ for(auto key:{p::kColorSubrectBaseX,p::kOutputSubrectBaseX,p::kMVecSubrectBaseX,p::kDepthSubrectBaseX,+ p::kColorSubrectBaseY,p::kOutputSubrectBaseY,p::kMVecSubrectBaseY,p::kDepthSubrectBaseY})b.setU32(key,0);+ b.setF32(p::kMVecScaleX,1);b.setF32(p::kMVecScaleY,1);b.setI32(p::kDepthInverted,1);+ b.setI32(p::kIndicatorInvertX,0);b.setI32(p::kIndicatorInvertY,0);b.setI32(p::kEnabled,1);+ b.setI32(p::kReset,reset?1:0);b.setI32(p::kStyle,0);b.setF32(p::kIntensity,1);+ b.setF32(p::kLocalToneStrength,1);b.setF32(p::kLocalStructureStrength,1);+ b.setF32(p::kSkinStructureStrength,-1);b.setI32(p::kUseAutoMask,0);b.setI32(p::kUICorrection,0);+ Status s;uint32_t slot;auto* list=ring.acquireNext(slot,s);if(!list)return false;+ states.transition(list,color.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);+ states.transition(list,output.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS);+ uint64_t r=0;uint32_t e=0;const bool safe=session.adapter.snippetEvaluateFeature(list,handle,params,r,e);+ const bool ok=ngxOK(safe,r,e,"Evaluate");+ states.uavBarrier(list,output.Get());states.transition(list,output.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);+ return ring.submitAndSignal(slot)&&ring.waitIdle()&&ok;+ }+ std::vector<uint8_t> read(gfx::CommandSlotRing& ring) {+ const auto desc=output->GetDesc();D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{};+ UINT rows=0;UINT64 rowBytes=0,total=0;session.device.device()->GetCopyableFootprints(&desc,0,1,0,&fp,&rows,&rowBytes,&total);+ D3D12_HEAP_PROPERTIES hp{};hp.Type=D3D12_HEAP_TYPE_READBACK;D3D12_RESOURCE_DESC bd{};+ bd.Dimension=D3D12_RESOURCE_DIMENSION_BUFFER;bd.Width=total;bd.Height=1;bd.DepthOrArraySize=1;+ bd.MipLevels=1;bd.SampleDesc.Count=1;bd.Layout=D3D12_TEXTURE_LAYOUT_ROW_MAJOR;+ ComPtr<ID3D12Resource> buffer;if(!hrOK(session.device.device()->CreateCommittedResource(&hp,D3D12_HEAP_FLAG_NONE,&bd,+ D3D12_RESOURCE_STATE_COPY_DEST,nullptr,IID_PPV_ARGS(&buffer)),"Readback.Create"))return {};+ Status s;uint32_t slot;auto* list=ring.acquireNext(slot,s);if(!list)return {};+ states.transition(list,output.Get(),D3D12_RESOURCE_STATE_COPY_SOURCE);+ D3D12_TEXTURE_COPY_LOCATION a{},b{};a.pResource=buffer.Get();a.Type=D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;a.PlacedFootprint=fp;+ b.pResource=output.Get();b.Type=D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;list->CopyTextureRegion(&a,0,0,0,&b,nullptr);+ states.transition(list,output.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);+ if(!ring.submitAndSignal(slot)||!ring.waitIdle())return {};+ void* data=nullptr;D3D12_RANGE range{0,SIZE_T(total)};if(!hrOK(buffer->Map(0,&range,&data),"Readback.Map"))return {};+ std::vector<uint8_t> result(size_t(rowBytes)*rows);+ for(UINT y=0;y<rows;++y)std::memcpy(result.data()+size_t(y)*rowBytes,+ static_cast<uint8_t*>(data)+fp.Offset+size_t(y)*fp.Footprint.RowPitch,size_t(rowBytes));+ D3D12_RANGE empty{};buffer->Unmap(0,&empty);return result;+ }+};+}