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: add experimental GPU DIS optical flow with shared graph integration
Veyra Goal Agent2c45419360d0
diff --git a/CMakeLists.txt b/CMakeLists.txtindex b5cdeef4..e06850eb 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -545,7 +545,13 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avform# Headless quality-core runner (Playbook R3.3): the phase5 gate's qualityadd_library(veyra_engine STATIC src/engine/EngineController.cpp src/engine/EngineControllerImage.cpp src/engine/TiledImageProcessor.cpp src/engine/PresetStore.cpp src/engine/VideoPresenter.cpp src/engine/VideoExportJob.cpp src/engine/ExportJobManager.cpp src/engine/Subtitles.cpp)- target_sources(veyra_pipeline PRIVATE src/guidance/AmdOpticalFlow.cpp)+ target_sources(veyra_pipeline PRIVATE src/guidance/AmdOpticalFlow.cpp+ src/guidance/GpuDisOpticalFlow.cpp third_party/gpu-dis/src/gpu/native_strict_dis_provider.cpp)+ target_include_directories(veyra_pipeline PRIVATE third_party/gpu-dis/src/gpu)+ include(cmake/VeyraGpuDis.cmake)+ veyra_add_compute_shader(veyra_shader_gpu_dis_luma GpuDisLuma)+ veyra_add_compute_shader(veyra_shader_gpu_dis_validate GpuDisValidate)+ add_dependencies(veyra_pipeline veyra_shader_gpu_dis veyra_shader_gpu_dis_luma veyra_shader_gpu_dis_validate)if(EXISTS "${VEYRA_FIDELITYFX_ROOT}/bin/ffx_sdk/ffx_opticalflow_x64.lib")target_compile_definitions(veyra_pipeline PRIVATE VEYRA_HAS_AMD_OF=1)target_include_directories(veyra_pipeline PRIVATE "${VEYRA_FIDELITYFX_ROOT}/include")diff --git a/README.md b/README.mdindex 07cbac6d..ff464645 100644--- a/README.md+++ b/README.md@@ -72,6 +72,8 @@ Windows 视频播放器与采集卡增强工具。支持视频、图片、采集### 增强与补帧+当前源码开发版另提供 **GPU DIS 光流 · FAST 实验**,在“光流·运动估算”中选择;默认仍是 NVOF。它不一定更快,本机 1080p 合成测试明显慢于 NVOF,适合比较效果。未包含在已发布的 0.0.5 包中。+专业模式中分别开启 NR、超分和补帧。超分下方选择算法及目标尺寸;补帧页选择 DLSS 或 XeSS 及可用倍率。建议从实时 NR、较低 RTX Video SR 档位和2X补帧开始,结合对比画面与实时状态调整。处理跟不上时降低画质、倍率或目标尺寸。四个阶段卡显示光流、NR、超分、补帧的 GPU 耗时;曲线显示相对无增强播放的额外延迟估计,不能简单相加,也不是按键到屏幕实测延迟。视频可提前处理,因此处理耗时不一定变成额外等待。diff --git a/README_EN.md b/README_EN.mdindex d8849637..34a74862 100644--- a/README_EN.md+++ b/README_EN.md@@ -110,3 +110,11 @@ NR and DLSS frame generation are **community-experimental integrations**, not NVOriginal Veyra source is [GPLv3](LICENSE); the combined streaming program also falls under [AGPLv3 and the upstream OpenSSL exception](licenses/remoteplay/CHIAKI_AGPL3_OPENSSL.txt). Application source matches the release tag. The RemotePlay-source and FFmpeg-source assets provide dependency source and are not needed to run the player. SDKs, models, and runtimes are excluded from this source repository. Release components retain their separate licenses and experimental distribution boundaries.Stage cards report GPU processing times. The chart estimates additional delay versus unenhanced playback, not their sum or measured button-to-screen latency. Files can be processed ahead. Sustained overload skips expired preview frame opportunities to keep media time advancing and audio continuous; export retains complete processing.++### Unreleased: experimental GPU DIS motion++The current source build adds **GPU DIS · FAST experimental** to the optical-flow+selector. NVOF remains the default. DIS is not necessarily faster; on our RTX 5070+1080p synthetic translation test it was substantially slower than NVOF. Use it+for comparisons with fixed enhancement settings. This option is not in the+published 0.0.5 portable package.diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.mdindex eb81ebda..0323aa8b 100644--- a/THIRD_PARTY_NOTICES.md+++ b/THIRD_PARTY_NOTICES.md@@ -65,3 +65,15 @@ Veyra calls the pinned Chiaki orientation tracker API (AGPL-3.0-only with OpenSS`src/remoteplay/PsnAuth.cpp` adapts the OAuth request contract and public client identifiers from chiaki-ng, commit `0e16950165f06e5c3291537c2eeba6e852be7120`, `gui/src/psnaccountid.cpp`, `gui/include/psnaccountid.h`, and `gui/src/psntoken.cpp`. Upstream credits the Account ID script to grill2010. License: AGPL-3.0-only with the upstream OpenSSL exception. The Windows HTTP, protected storage and UI integration are Veyra code. This is an unofficial client, not Sony endorsement. json-c remains an existing Chiaki dependency; its license/notice must remain in binary distributions.Static dependency notices and installed SPDX records: licenses/remoteplay/{json-c,libevent,miniupnpc,openssl,opus,sdl3}/. Upstream curl, nanopb, Jerasure and gf-complete notices are in the same directory. Their corresponding sources and port recipes accompany the RemotePlay-source release asset.++## GPU DIS optical flow (experimental)++Source: https://github.com/gggz114514-oss/XeSS-GPU-Motion , commit+`cb7523b5104fc914dc501767c3139b43c2067af7` (public R4.2 snapshot).+The DIS provider and its shader closure are included under `third_party/gpu-dis/`.+Owned additions use Apache-2.0; OpenCV-derived portions retain their BSD/Apache+terms and Intel/Willow Garage/other upstream attribution. See that directory's+LICENSE, NOTICE, PROVENANCE.md, VEYRA_INTEGRATION.md, and licenses/.+Veyra adds GPU input/consumer adapters and descriptor staging; no Intel SDK,+worker dependencies or proprietary runtime is included in this source subset.+This is a motion-estimation option, not Intel XeSS frame generation itself.diff --git a/apps/veyra/SettingsWindow.cpp b/apps/veyra/SettingsWindow.cppindex 7dcfa5c6..be81d58f 100644--- a/apps/veyra/SettingsWindow.cpp+++ b/apps/veyra/SettingsWindow.cpp@@ -167,7 +167,7 @@ case WM_CREATE:{window=h;font=makeFont(h);items.clear();displayedBackendWarning.add(L"STATIC",L"补帧倍率",1112,0,1,12,122,-1,24);combo(202,1,150,{L"关闭补帧",L"2X · 一张中间帧",L"3X · 两张中间帧",L"4X · 三张中间帧"});add(L"STATIC",L"运动估算",1113,0,1,12,194,-1,24);- combo(209,1,222,{L"NVIDIA NVOF 光流",L"AMD FidelityFX 光流 · 实验"});+ combo(209,1,222,{L"NVIDIA NVOF 光流",L"AMD FidelityFX 光流 · 实验",L"GPU DIS 光流 · FAST 实验"});add(L"BUTTON",L"AMD 性能档 · 光流宽高各减半",215,BS_AUTOCHECKBOX|WS_TABSTOP,1,12,266,-1,36);combo(204,1,310,{L"NR / DLSS光流 · 性能",L"NR / DLSS光流 · 平衡",L"NR / DLSS光流 · 质量"});add(L"STATIC",L"内容节奏",1114,0,1,12,354,-1,24);diff --git a/apps/veyra/ui/SettingHelp.h b/apps/veyra/ui/SettingHelp.hindex 082e2660..5beba497 100644--- a/apps/veyra/ui/SettingHelp.h+++ b/apps/veyra/ui/SettingHelp.h@@ -36,7 +36,7 @@ inline const wchar_t* settingHelp(int id){case 206:return L"让框选区域少受NR改动,最多4块。只管NR,不给超分和补帧当保镖。";case 207:return L"选择DLSS SR或RTX视频超分,以及视频超分质量。两条路线各有脾气,试着看画质和耗时。";case 208:return L"选择DLSS或实验XeSS补帧。XeSS目前为预览2X,不支持视频导出;别只看名字,看实际效果。";- case 209:return L"选择运动估算后端。NVOF和AMD FidelityFX负责看出物体怎么动;选择AMD光流不等于获得AMD NR。";+ case 209:return L"选择运动估算后端。NVOF、FidelityFX、GPU DIS负责看出物体怎么动。DIS是实验算法,走通用计算单元,可能和NR抢活干,不保证更快;选它不会换掉你的补帧方式,也不会解锁AMD NR。";case 211:return L"把增强参数恢复为内建默认。调迷路了就走这里,保存的用户预设不会被删。";case 213:return L"在画面上拖框添加NR保护区域,Esc取消。把不想被改的地方圈出来。";case 214:return L"清空当前NR保护框。只是撤掉围栏,不会删除视频。";diff --git a/cmake/VeyraGpuDis.cmake b/cmake/VeyraGpuDis.cmakenew file mode 100644index 00000000..fe28bc59--- /dev/null+++ b/cmake/VeyraGpuDis.cmake@@ -0,0 +1,136 @@+veyra_find_dxc(DIS_DXC)+set(dis_outputs "")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_native_gray.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_native_gray.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_native_gray.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_native_gray.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_native_gray.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_native_rgba_gray.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_native_rgba_gray.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_native_rgba_gray.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_native_rgba_gray.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_native_rgba_gray.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_native_luma.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_native_luma.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_native_luma.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_native_luma.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_native_luma.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_area.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_area.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_area.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_area.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_area.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d2_gradient.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d2_gradient.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_d2_gradient.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_d2_gradient.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d2_gradient.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d3_structure_hor.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d3_structure_hor.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_hor.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_hor.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d3_structure_hor.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d3_structure_ver.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d3_structure_ver.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_ver.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_ver.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d3_structure_ver.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_deriv2.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_deriv2.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_deriv2.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_deriv2.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_deriv2.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_update.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_update.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_update.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_update.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_update.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_zero.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_zero.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_zero.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_zero.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_zero.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d3_structure_hor_stride3.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -D DIS_TENSOR_STRIDE=3 -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d3_structure_hor_stride3.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_hor.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_hor.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d3_structure_hor_stride3.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d3_structure_ver_stride3.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -D DIS_TENSOR_STRIDE=3 -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d3_structure_ver_stride3.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_ver.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_ver.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_d3_structure_ver_stride3.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_patch_parallel.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -D DIS_SINGLE_PATCH_GROUP=1 -D DIS_ROUNDED_DIVIDE=1 -D DIS_PARALLEL_STRIPES=1 -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_patch_parallel.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_patch_exact.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_patch_exact.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_patch_parallel.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_densify_exact.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -D DIS_DENSE_EXACT=1 -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_densify_exact.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_densify.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_densify.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_densify_exact.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_deriv1_cpu.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Gis -D DIS_VR_CPU_WARP=1 -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_deriv1_cpu.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_deriv1.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_deriv1.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_deriv1_cpu.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_system_exact.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Gis -D DIS_VR_EXACT=1 -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_system_exact.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_system.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_system.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_system_exact.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_sor_exact.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Gis -D DIS_VR_EXACT=1 -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_sor_exact.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_sor.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_sor.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_vr_sor_exact.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_upsample_ipp.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -D DIS_IPP_UPSAMPLE=1 -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_upsample_ipp.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_upsample.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_upsample.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_upsample_ipp.dxil")+add_custom_command(+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_final.dxil"+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis"+ COMMAND "${DIS_DXC}" -nologo -T cs_6_0 -E main -Gis -Fo "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_final.dxil" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_final.hlsl"+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_perfect_final.hlsl" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli"+ VERBATIM)+list(APPEND dis_outputs "${CMAKE_CURRENT_BINARY_DIR}/shaders/dis/dis_perfect_final.dxil")+add_custom_target(veyra_shader_gpu_dis DEPENDS ${dis_outputs})diff --git a/docs/BUILD.md b/docs/BUILD.mdindex b9441136..2073a6a7 100644--- a/docs/BUILD.md+++ b/docs/BUILD.md@@ -60,3 +60,12 @@ The packager accepts `-BuildDirectory` for an isolated build, checks the publish## PS5 in 0.0.5The release enables Remote Play; the default non-RemotePlay command above is a reduced build. Follow [REMOTEPLAY_BUILD_0.0.5.md](REMOTEPLAY_BUILD_0.0.5.md) for the full build, dependency source, patches and licensing.++## GPU DIS (current source build)++The open-source subset in `third_party/gpu-dis` compiles with the existing Windows+SDK DXC; no additional GPU vendor SDK is required for DIS. `cmake/VeyraGpuDis.cmake`+retains the shader variants and compiler flags from `shader-recipes.json`.+Keep `shaders/dis/*.dxil`, `GpuDisLuma.dxil`, and `GpuDisValidate.dxil` when moving+an executable. Runtime requires D3D12 double-precision shader operations.+See `docs/GPU_DIS_INTEGRATION_PLAN_2026-09-13.md` for tests and limitations.diff --git a/docs/GPU_DIS_INTEGRATION_PLAN_2026-09-13.md b/docs/GPU_DIS_INTEGRATION_PLAN_2026-09-13.mdnew file mode 100644index 00000000..23b4395b--- /dev/null+++ b/docs/GPU_DIS_INTEGRATION_PLAN_2026-09-13.md@@ -0,0 +1,56 @@+# GPU DIS 实验光流接入与验收记录++## 范围与存档++用户确认 PS5 清晰度已基本与 chiaki-ng 相当,本轮接入之前讨论的 GPU DIS 光流供切换比较,不继续改 PS5 码率/采样,也不虚构官方高质量模式接口。不加音频缓冲设置,不关机,不发布。++开工前将另一轮已完成、尚未提交的三个 P1 修复存档为 `3ae4d5c`,tag `checkpoint/gpu-dis-preintegration-2026-09-13`。这些修复不是本轮 GPU DIS 工作。施工分支 `codex/gpu-dis-integration`。++完成门槛:可在专业设置选择/恢复原后端,预设可保存,复用现有图与时序,构建通过;真实 GPU 方向、重置和下游 NR/FG 测试通过;许可与打包依赖完整。效果与性能不作先验承诺。++## 实现++1. 光流选择增加 `GPU DIS 光流 · FAST 实验`,枚举追加为 2;NVOF 默认、FidelityFX 和原预设含义不变。NVOF 档位、AMD 半分辨率仍只作用于各自后端。悬停说明解释计算资源竞争及实验边界。+2. 仅引入公开 DIS 源码子集,固定上游 `cb7523b5104fc914dc501767c3139b43c2067af7`。FAST、双向、两个槽;不引入整个工具箱、SDK、模型或 GPU Block。保留 Apache/BSD 许可与来源。着色器严格沿用上游宏及编译参数,未简化计算冒充原算法。+3. 现有源空间编码 RGB → GPU BT.709 R8 亮度 → DIS 双向运动 → 越界/非有限值拒绝、亮度匹配/往返一致性置信度 → 原共享 FlowAdapt → NR、SR、DLSSG/XeSS 消费者。矢量为 current→previous,单位为光流输入像素,消费者分别按目标尺寸缩放一次。+4. 不改变显示颜色、PS5 解码、音频、队列容量或播放循环。光流计时沿用 GpuStage::Flow,进入当前耗时卡和总增强处理耗时。DIS 单独记录实际执行计数,不冒充 NVOF 调用。+5. 共用图的首帧/seek/丢帧/切源/尺寸与设置切换 reset。reset 帧不复用旧运动。provider 不跨帧积累运动历史,只接收当前图的相邻 A/B。所有描述符按两个 parity 槽隔离,在原 upload fence 退休后重写;provider completion 指向下一次 ring 提交,关闭前排空队列。无额外逐 pass CPU 等待、常规 GPU→CPU 回读。+6. 通用 D3D12 计算,但此公开实现要求 DoublePrecisionFloatShaderOps;不支持时初始化明确失败,使用既有设置回滚。输入每轴暂限 32–4096(这是 DIS 光流输入限制,不是导入图片/视频上限)。未实测 AMD/Intel 显卡,不声称全卡验证完成。+7. 包脚本递归复制着色器子目录,保留此开源子集的许可。未运行发布/上传;NVIDIA 白名单不变。++## 本轮文件++- 后端:`include/veyra/guidance/GpuDisOpticalFlow.h`、`src/guidance/GpuDisOpticalFlow.cpp`。+- 图接法:`include/veyra/pipeline/EnhanceGraph.h`、`src/pipeline/EnhanceGraph.cpp`。+- 设置:`include/veyra/engine/EnhancementSettings.h`、`apps/veyra/SettingsWindow.cpp`、`apps/veyra/ui/SettingHelp.h`。+- 构建/着色器:`CMakeLists.txt`、`cmake/VeyraGpuDis.cmake`、`shaders/GpuDisLuma.hlsl`、`shaders/GpuDisValidate.hlsl`、`third_party/gpu-dis/`。+- 测试:`ExperimentalBackendTests.cpp`、`RepairFgTests.cpp`、`RepairPresetTests.cpp`。+- 文档/打包:本记录、WORKLOG、双语 README、BUILD、THIRD_PARTY_NOTICES、`scripts/package-portable.ps1`。++## 验证证据++构建目录 `out/remoteplay/product-repair`;本机 RTX 5070 / 616.56。日志目录 `logs/gpu-dis-20260913/`,构建日志 `out/gpu-dis-*-build*.log`。单次测试限 240 秒。++在 vcvars64 环境运行:++```text+cmake --build out/remoteplay/product-repair --target veyra veyra_experimental_backend_tests veyra_repair_preset_tests veyra_repair_fg_tests --parallel 6+veyra_experimental_backend_tests.exe dis <logs>/dis+veyra_experimental_backend_tests.exe dis1080 <logs>/dis1080+veyra_experimental_backend_tests.exe dis-xess <logs>/dis-xess+veyra_experimental_backend_tests.exe nvof1080 <logs>/nvof1080+veyra_repair_fg_tests.exe dis+veyra_repair_fg_tests.exe dis-sr+veyra_repair_preset_tests.exe <logs>/preset-fixed.v1+```++- DIS 640×360 与 1920×1080:48 个源帧,46 次双向计算;首帧和方向切换 reset 不运行旧帧光流,窗口 resize 包含在测试中;D3D12 debug error=0。640 样本运动中位数右移=(-1.97559,-0.01671)、左移=(1.90723,-0.00354),符合 current→previous 方向。+- DIS+XeSS:43 个 SDK 报告的生成帧,46 次 DIS,debug error=0。不是屏幕扫描帧率或视觉质量验收。+- DIS+NR+DLSS FG:12 源帧、11 生成帧全部通过非重复、非线性混合、位置与 PTS 检查,保留 lease 时拒绝覆盖。NR/DLSSG Create/Release result=0x1,seh=0。+- 再加入 RTX Video SR 到 3840×2160、NR 1920×1080:12 源帧、11 生成帧全部 contentValid=11;末帧位置误差约 1.32 像素。非真实 PS5 画质验收。+- 预设 roundtrip 最终通过(42 项既有迁移案例也通过)。初次失败是新增测试保存 DIS 后未清理,破坏后续旧断言的条目数;已修正测试清理并确认恢复读取仍等于保存的 DIS 设置。原失败日志与 results.json 保留;最终 additional-results.json 中 preset-fixed=0。+- 同一 1080p 随机纹理平移、同一设备、各 45 个已完成 GPU 光流计时:DIS 中位数 17.2824ms / 均值 17.2826ms;NVOF 中位数 1.15165ms / 均值 1.21748ms。**本公开 DIS 实现在该负载明显更慢,不应改为默认,也不能宣传提升性能。**这是单个合成用例,不能外推所有 GPU、游戏画质或整机延迟。++完整增量构建 `cmake --build out/remoteplay/product-repair --parallel 6` 115/115 完成。`powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/gates/delivery.ps1 -Root . -BuildDirectory out/remoteplay/product-repair` 23/23 通过,47.156 秒,证据 `logs/delivery/ca204954e1e64ee4aeddf7a41cf5f1e6/result.json`。该 gate 主要覆盖既有默认 NVOF 与媒体/导出路径;DIS 证据以以上专门测试为准。`git diff --check` 通过;包脚本 PowerShell 语法检查无错误。最终 exe SHA256=`114E00EDD266182BD2556FD1150C487FE3C4B6348112A63AA7706BFCE554BCFA`。patched avcodec-63.dll SHA256=`0710F0D87A7FFCC9F998F1A35D0500345F6C66EB9A5A39C51D60D293142BD84F`,未退回旧 FFmpeg。桌面“Veyra PS5 测试版”快捷方式指向此构建。无独立 Reviewer;代码自查。尚未执行:真实 PS5/采集卡使用新后端、游戏视觉对比、长时压力、多 GPU、HDR 屏幕验收、正式便携包安装与上传。++用户操作:关闭并重新启动桌面 PS5 测试版 → 专业模式 → 光流与补帧 → 光流·运动估算 → GPU DIS。切换走原有图重建及回滚,可能短暂停顿;不需要重新配对 PS5。比较时固定 NR/SR/FG 参数及场景,结束可选回 NVIDIA NVOF。diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex 6b156aff..22f6a411 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -1820,3 +1820,20 @@ cross runner 调用 scripts/gates/delivery.ps1 -Root . -BuildDirectory out/relea新程序 out/release-p1-20260913/build/veyra.exe,SHA256=B116AB6855D69CDEB29927AB3AD80422D54051339FCE47D7EE5939CAA987519D。patched avcodec-63.dll SHA256=0710F0D87A7FFCC9F998F1A35D0500345F6C66EB9A5A39C51D60D293142BD84F,与开工一致,未退回未打补丁的 FFmpeg;原版/社区 NR 身份符合已批准记录。未修改运行时、SDK、模型、凭据、个人配置或既有发布资产;未推送、打包上传或发布。限制:变分辨率文件明确停止;全片 CPU 解码验证会增加导出收尾时间,但可取消,不是增强路径 GPU→CPU 回读。实机 PS5/PSN、HDR 显示器、长时稳定性、多 GPU、4K60 采集卡端到端验收未执行,本轮回放不代表实卡通过。下一项唯一任务:用户试用本轮新构建;正在运行的旧程序不会自动更新。两个 P2 按用户范围保留。+++## 2026-09-13 GPU DIS 光流可切换实验接入++用户确认 PS5 清晰度基本与 chiaki-ng 相当,授权接入此前讨论的 GPU DIS 作为可选实验后端。开工存档 3ae4d5c 保留另一轮已完成的三个 P1 修复;tag checkpoint/gpu-dis-preintegration-2026-09-13,施工分支 codex/gpu-dis-integration。完整实施/测试/修改文件与边界见 docs/GPU_DIS_INTEGRATION_PLAN_2026-09-13.md。++专业光流选择增加 GPU DIS FAST,NVOF 默认及 FidelityFX 保留,预设枚举追加兼容;公开上游 cb7523b5104fc914dc501767c3139b43c2067af7 的 DIS source/shader 子集放 third_party/gpu-dis,保留 Apache/BSD 许可、来源及实际修改记录。只使用公共 D3D12 provider;没带工具箱 worker、SDK 或模型。图复用现有 A/B、parity fence、FlowAdapt、GPU 计时、reset 和 NR/SR/FG 消费者;增加 GPU 亮度适配、双向一致性与亮度置信度,未改变源显示颜色、音频、PS5、播放队列。不引入逐 pass CPU 等待或正常路径 GPU 回读。上游 shader 可见 SRV 写法按现有驱动 workaround 改为 staging;算法未改。包脚本递归带 DIS DXIL 子目录和开源 notices,未执行新发布。++vcvars64 下 cmake --build out/remoteplay/product-repair --parallel 6,完整增量 115 步通过;定向目标编译也通过,日志 out/gpu-dis-build.log、out/gpu-dis-rebuild.log、out/gpu-dis-final-build.log、out/gpu-dis-build-all.log。真实 RTX5070/616.56:veyra_experimental_backend_tests dis/dis1080/dis-xess/nvof1080;veyra_repair_fg_tests dis/dis-sr;veyra_repair_preset_tests logs/gpu-dis-20260913/preset-fixed.v1。每次进程 240 秒上限,实际各约 0.1–5.6 秒。640/1080 双向 DIS 46 次、方向/重置/resize 数值通过、D3D12 debug error=0;DIS+XeSS generated=43;DIS+NR+DLSSG 12 源/11 生成全部 contentValid,进一步 RTX Video SR 到4K同样11/11。NR CreateFeature18 result=0x1/seh=0,FG warm-up result=0x1,VSR op=0/2 result=0x1。不是屏幕扫描/真实 PS5 画质验收。++原预设测试新增后初次失败:测试没有删除刚加的 DIS 条目,导致旧条目数量断言失败。修复测试清理后,DIS 保存/重载相等与原有42项迁移测试均通过。保留原 results.json preset=1,最终 additional-results.json preset-fixed=0。详见 logs/gpu-dis-20260913/。++同一1080合成平移数据,各45个已完成GPU计时,DIS 光流中位17.2824ms、均值17.2826ms;NVOF中位1.15165ms、均值1.21748ms。此公开实现本机明显更慢,因此保留实验选项,不能宣传性能提升或默认替换。双向计算与其变分迭代走通用计算单元,其他硬件/素材未推断。用户肉眼比较游戏画质仍待执行。++powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/gates/delivery.ps1 -Root . -BuildDirectory out/remoteplay/product-repair,23/23 PASS,47.156秒,logs/delivery/ca204954e1e64ee4aeddf7a41cf5f1e6/result.json。git diff --check及package-portable.ps1语法检查通过。最终veyra.exe SHA256=114E00EDD266182BD2556FD1150C487FE3C4B6348112A63AA7706BFCE554BCFA;patched avcodec SHA256=0710F0D87A7FFCC9F998F1A35D0500345F6C66EB9A5A39C51D60D293142BD84F,保持硬解slice修复。桌面PS5测试版快捷方式已核对指向out/remoteplay/product-repair/veyra.exe。++未测试真实PS5/采集卡新后端、多GPU、HDR屏幕、长时稳定性、Windows UI实际鼠标切换和新便携包部署;代码走既有后端切换重建/回滚,不能将静态接法当这些场景实测。仅本地构建与存档,没有push/Release/运行时修改,没有关机。下一项:用户重启桌面测试版,在专业模式的光流·运动估算选择GPU DIS,固定NR/SR/FG参数比较;速度/效果不满意即可切回NVOF。diff --git a/include/veyra/engine/EnhancementSettings.h b/include/veyra/engine/EnhancementSettings.hindex 0130dffb..91801d2a 100644--- a/include/veyra/engine/EnhancementSettings.h+++ b/include/veyra/engine/EnhancementSettings.h@@ -16,7 +16,7 @@ constexpr std::string_view nrRuntimeName(NrRuntime runtime) {return "unknown";}enum class FlowQuality { Performance, Balanced, Quality };-enum class OpticalFlowBackend { Nvidia, AmdFidelityFx };+enum class OpticalFlowBackend { Nvidia, AmdFidelityFx, GpuDis };enum class ContentRate { Transport, Auto, Fps30, Fps50, Fps60, Capture60To30 };enum class AudioSyncMode { Automatic, Manual, Off };constexpr std::string_view frameGenerationBackendName(FrameGenerationBackend backend) {@@ -30,6 +30,7 @@ constexpr std::string_view opticalFlowBackendName(OpticalFlowBackend backend) {switch(backend) {case OpticalFlowBackend::Nvidia: return "NVIDIA_NVOF";case OpticalFlowBackend::AmdFidelityFx: return "AMD_FIDELITYFX_OF";+ case OpticalFlowBackend::GpuDis: return "GPU_DIS_FAST";}return "unknown";}@@ -109,7 +110,7 @@ struct EnhancementSettings {if(frameGenerationBackend==FrameGenerationBackend::XeSS&&multiplier>2)return "XeSS preview currently supports 2X only";if(videoSrQuality>4)return "invalid video SR quality";if(!pipeline::validSrTarget(srTarget))return "invalid SR target";- if(opticalFlowBackend!=OpticalFlowBackend::Nvidia&&opticalFlowBackend!=OpticalFlowBackend::AmdFidelityFx)return "invalid optical flow backend";+ if(opticalFlowBackend!=OpticalFlowBackend::Nvidia&&opticalFlowBackend!=OpticalFlowBackend::AmdFidelityFx&&opticalFlowBackend!=OpticalFlowBackend::GpuDis)return "invalid optical flow backend";if(multiplier<1||multiplier>4)return "unsupported multiplier";if(nrPolicy!=pipeline::NrSizePolicy::Realtime&&nrPolicy!=pipeline::NrSizePolicy::Native)return "invalid NR size policy";if(flow<FlowQuality::Performance||flow>FlowQuality::Quality||content<ContentRate::Transport||content>ContentRate::Capture60To30)return "invalid flow/content mode";diff --git a/include/veyra/guidance/GpuDisOpticalFlow.h b/include/veyra/guidance/GpuDisOpticalFlow.hnew file mode 100644index 00000000..51c588eb--- /dev/null+++ b/include/veyra/guidance/GpuDisOpticalFlow.h@@ -0,0 +1,22 @@+#pragma once+#include <d3d12.h>+#include <cstdint>+#include <memory>++namespace veyra::guidance {+// GPU-only adapter. Two slots are retired by EnhanceGraph's upload fences.+// Caller supplies COMMON inputs/outputs and signals completion after submission.+class GpuDisOpticalFlow {+public:+ GpuDisOpticalFlow();+ ~GpuDisOpticalFlow();+ bool initialize(ID3D12Device*, uint32_t width, uint32_t height);+ bool dispatch(ID3D12GraphicsCommandList*, ID3D12CommandQueue*, ID3D12Fence*,+ uint64_t completion, uint32_t slot, ID3D12Resource* previous,+ ID3D12Resource* current, ID3D12Resource* motion, ID3D12Resource* confidence,+ uint64_t previousId, uint64_t currentId);+private:+ struct Impl;+ std::unique_ptr<Impl> p_;+};+}diff --git a/include/veyra/pipeline/EnhanceGraph.h b/include/veyra/pipeline/EnhanceGraph.hindex 5952f6d0..2ceb045c 100644--- a/include/veyra/pipeline/EnhanceGraph.h+++ b/include/veyra/pipeline/EnhanceGraph.h@@ -34,7 +34,7 @@ struct AVFrame;struct SwsContext;struct NVSDK_NGX_Parameter;struct NVSDK_NGX_Handle;-namespace veyra::guidance { class AmdOpticalFlow; }+namespace veyra::guidance { class AmdOpticalFlow; class GpuDisOpticalFlow; }namespace veyra::gfx {class D3D12DeviceContext;@@ -158,6 +158,7 @@ public:uint64_t srEvaluateCount = 0;uint64_t nvofExecuteCount = 0;uint64_t amdOfExecuteCount = 0;+ uint64_t gpuDisExecuteCount = 0;uint64_t nvofFrameFailures = 0;uint64_t fgGeneratedFrames = 0;uint64_t fgSubmittedCandidates = 0, fgDisabledFrames = 0;@@ -295,6 +296,7 @@ private:std::unique_ptr<ngx::DlssNrRuntimeAdapter> nrAdapter_;std::unique_ptr<ngx::DlssSrBackend> srBackend_;std::unique_ptr<guidance::AmdOpticalFlow> amdOf_;+ std::unique_ptr<guidance::GpuDisOpticalFlow> gpuDis_;std::unique_ptr<ngx::VideoSrBackend> videoSrBackend_;std::unique_ptr<ngx::DlssFgBackend> fgBackend_;NVSDK_NGX_Parameter* ngxParams_ = nullptr;diff --git a/scripts/package-portable.ps1 b/scripts/package-portable.ps1index ca439046..c3dc8771 100644--- a/scripts/package-portable.ps1+++ b/scripts/package-portable.ps1@@ -68,7 +68,16 @@ foreach ($notice in Get-ChildItem -LiteralPath (Join-Path $resolvedRoot 'licenseCopy-Payload $notice.FullName "licenses/$relative"}Copy-Payload (Join-Path $resolvedRoot 'docs/REMOTEPLAY_BUILD_0.0.5.md') 'docs/REMOTEPLAY_BUILD_0.0.5.md'-foreach ($shader in Get-ChildItem -LiteralPath (Join-Path $bin 'shaders') -File -Filter '*.dxil') { Copy-Payload $shader.FullName "shaders/$($shader.Name)" }+foreach ($shader in Get-ChildItem -LiteralPath (Join-Path $bin 'shaders') -Recurse -File -Filter '*.dxil') {+ $relative=$shader.FullName.Substring((Join-Path $bin 'shaders').Length+1).Replace('\','/')+ Copy-Payload $shader.FullName "shaders/$relative"+}+foreach ($name in @('LICENSE','NOTICE','PROVENANCE.md','VEYRA_INTEGRATION.md')) {+ Copy-Payload (Join-Path $resolvedRoot "third_party/gpu-dis/$name") "licenses/gpu-dis/$name"+}+foreach ($notice in Get-ChildItem -LiteralPath (Join-Path $resolvedRoot 'third_party/gpu-dis/licenses') -File) {+ Copy-Payload $notice.FullName "licenses/gpu-dis/licenses/$($notice.Name)"+}Copy-Payload (Join-Path $resolvedRoot 'runtime_local/config/ngx-local.json') 'runtime/config/ngx-local.json'Copy-Payload 'C:/veyra-deps/installed/x64-windows/share/ffmpeg/copyright' 'licenses/FFMPEG-COPYRIGHT.txt'Copy-Payload 'C:/veyra-deps/installed/x64-windows/share/ffmpeg/vcpkg.spdx.json' 'licenses/FFMPEG-SPDX.json'diff --git a/shaders/GpuDisLuma.hlsl b/shaders/GpuDisLuma.hlslnew file mode 100644index 00000000..bfc40fc4--- /dev/null+++ b/shaders/GpuDisLuma.hlsl@@ -0,0 +1,10 @@+// Encoded RGB from the existing flow ingress -> full-range 8-bit BT.709 luma.+// Guidance only; this conversion never alters the displayed image.+Texture2D<float4> color : register(t0);+RWTexture2D<float> luma : register(u0);+cbuffer Dims : register(b0) { uint width; uint height; uint2 padding; uint4 reserved; };+[numthreads(16,16,1)]+void main(uint3 id : SV_DispatchThreadID) {+ if(id.x>=width || id.y>=height)return;+ luma[id.xy]=dot(color[id.xy].rgb,float3(.2126,.7152,.0722));+}diff --git a/shaders/GpuDisValidate.hlsl b/shaders/GpuDisValidate.hlslnew file mode 100644index 00000000..2e3d342d--- /dev/null+++ b/shaders/GpuDisValidate.hlsl@@ -0,0 +1,25 @@+Texture2D<float2> backwardFlow : register(t0);+Texture2D<float2> forwardFlow : register(t1);+Texture2D<float> previousLuma : register(t2);+Texture2D<float> currentLuma : register(t3);+RWTexture2D<float2> motion : register(u0);+RWTexture2D<float> confidence : register(u1);+cbuffer Dims : register(b0) { uint width; uint height; uint2 padding; uint4 reserved; };+[numthreads(16,16,1)]+void main(uint3 id : SV_DispatchThreadID) {+ if(id.x>=width || id.y>=height)return;+ float2 v=backwardFlow[id.xy], q=float2(id.xy)+v;+ float trust=0;+ if(all(isfinite(v)) && all(q>=0) && all(q<=float2(width-1,height-1))) {+ int2 a=int2(floor(q)), lim=int2(width-1,height-1); float2 t=frac(q);+ int2 b=min(a+int2(1,0),lim), c=min(a+int2(0,1),lim), d=min(a+1,lim);+ float2 reverse=lerp(lerp(forwardFlow[a],forwardFlow[b],t.x),lerp(forwardFlow[c],forwardFlow[d],t.x),t.y);+ float luma=lerp(lerp(previousLuma[a],previousLuma[b],t.x),lerp(previousLuma[c],previousLuma[d],t.x),t.y);+ float error=abs(currentLuma[id.xy]-luma);+ float consistency=length(v+reverse);+ trust=(1-smoothstep(.03,.15,error))*(1-smoothstep(.5,2.5,consistency));+ if(!isfinite(trust))trust=0;+ }+ motion[id.xy]=trust>0?v*trust:0;+ confidence[id.xy]=trust;+}diff --git a/src/guidance/GpuDisOpticalFlow.cpp b/src/guidance/GpuDisOpticalFlow.cppnew file mode 100644index 00000000..a58f9a58--- /dev/null+++ b/src/guidance/GpuDisOpticalFlow.cpp@@ -0,0 +1,91 @@+#include "veyra/guidance/GpuDisOpticalFlow.h"+#include "veyra/pipeline/GpuPassUtils.h"+#include "gpu_frame_contract.h"+#include "native_strict_dis_provider.h"++namespace veyra::guidance {+using namespace pipeline;+struct GpuDisOpticalFlow::Impl {+ ID3D12Device* device=nullptr;+ uint32_t w=0,h=0;+ std::unique_ptr<xess_gpu::MotionProvider> provider;+ struct Slot {+ ComPtr<ID3D12Resource> luma[2];+ ComputePass convert,validate;+ xess_gpu::FencePoint completion;+ } slots[2];+ DescriptorStager stager;+ void srv(ComputePass& pass,UINT offset,ID3D12Resource* r) {+ D3D12_SHADER_RESOURCE_VIEW_DESC d{};d.Format=r->GetDesc().Format;+ d.ViewDimension=D3D12_SRV_DIMENSION_TEXTURE2D;d.Texture2D.MipLevels=1;+ d.Shader4ComponentMapping=D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;+ stager.stageSrv(r,&d,pass.heap.Get(),offset);+ }+ static D3D12_CPU_DESCRIPTOR_HANDLE cpu(ComputePass& p,UINT i){return {p.heap->GetCPUDescriptorHandleForHeapStart().ptr+SIZE_T(i)*p.increment};}+ static uint64_t gpu(ComputePass& p,UINT i){return p.heap->GetGPUDescriptorHandleForHeapStart().ptr+UINT64(i)*p.increment;}+};+GpuDisOpticalFlow::GpuDisOpticalFlow():p_(std::make_unique<Impl>()){}+GpuDisOpticalFlow::~GpuDisOpticalFlow()=default;+bool GpuDisOpticalFlow::initialize(ID3D12Device* device,uint32_t w,uint32_t h){+ auto& p=*p_;p.device=device;p.w=w;p.h=h;+ if(!device||w<32||h<32||w>4096||h>4096){log::error("gpu-dis","unsupported flow extent (32..4096 each axis)");return false;}+ p.provider=xess_gpu::make_strict_dis_provider((runtime::shaderDirectory()/"dis").string(),xess_gpu::StrictDisPreset::Fast);+ xess_gpu::ProviderConfig config;config.source={w,h};config.slots=2;config.bidirectional=true;+ std::string error;+ if(!p.provider->initialize(device,config,error)){log::error("gpu-dis",error);return false;}+ if(!p.stager.initialize(device,8))return false;+ std::vector<uint8_t> convert,validate;+ if(!loadShaderBytes("GpuDisLuma.dxil",convert)||!loadShaderBytes("GpuDisValidate.dxil",validate))return false;+ for(auto& s:p.slots){+ for(auto& r:s.luma){r=makeTexture(device,w,h,DXGI_FORMAT_R8_UNORM,true);if(!r)return false;}+ if(!s.convert.create(device,convert,4,1,1)||!s.validate.create(device,validate,6,4,2))return false;+ for(UINT i=0;i<2;++i)makeUav(device,s.luma[i].Get(),DXGI_FORMAT_R8_UNORM,Impl::cpu(s.convert,2+i));+ }+ log::info("gpu-dis",std::format("initialized FAST bidirectional {}x{} slots=2; photometric/forward-backward confidence; experimental",w,h));return true;+}+bool GpuDisOpticalFlow::dispatch(ID3D12GraphicsCommandList* list,ID3D12CommandQueue* queue,ID3D12Fence* fence,+ uint64_t completion,uint32_t slot,ID3D12Resource* previous,ID3D12Resource* current,ID3D12Resource* motion,+ ID3D12Resource* confidence,uint64_t previousId,uint64_t currentId){+ auto& p=*p_;+ if(!p.provider||!list||!queue||!fence||!completion||slot>=2||!previous||!current||!motion||!confidence)return false;+ auto& s=p.slots[slot];+ if(!s.completion.complete()){log::error("gpu-dis","attempted in-flight descriptor reuse");return false;}+ StateTracker states;+ const uint32_t dims[8]={p.w,p.h};+ ID3D12Resource* inputs[]={previous,current};+ for(UINT i=0;i<2;++i){+ const auto d=inputs[i]->GetDesc();+ if(d.Width!=p.w||d.Height!=p.h||d.Format!=DXGI_FORMAT_B8G8R8A8_UNORM){log::error("gpu-dis","BGRA input geometry/format mismatch");return false;}+ p.srv(s.convert,i,inputs[i]);+ states.transition(list,inputs[i],D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);+ states.transition(list,s.luma[i].Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS);+ s.convert.bind(list,reinterpret_cast<const float*>(dims),Impl::gpu(s.convert,i),Impl::gpu(s.convert,2+i));+ list->Dispatch((p.w+15)/16,(p.h+15)/16,1);+ states.transition(list,s.luma[i].Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);+ states.transition(list,inputs[i],D3D12_RESOURCE_STATE_COMMON);+ }+ xess_gpu::FrameLease frames[2];+ for(UINT i=0;i<2;++i){+ frames[i].color={s.luma[i],DXGI_FORMAT_R8_UNORM,{p.w,p.h},{0,0,p.w,p.h},D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE};+ frames[i].metadata.adapter_luid=p.device->GetAdapterLuid();+ frames[i].metadata.source_frame_id=i?currentId:previousId;+ frames[i].metadata.previous_source_frame_id=previousId;+ }+ xess_gpu::RecordContext context;context.device=p.device;context.list=list;context.queue=queue;+ context.adapter_luid=p.device->GetAdapterLuid();context.completion={fence,completion};+ xess_gpu::MotionPacket packet;xess_gpu::Counters counters;std::string error;+ if(!p.provider->record(&frames[0],frames[1],slot,context,packet,counters,error)){log::error("gpu-dis",error);return false;}+ p.srv(s.validate,0,packet.current_to_previous.resource.Get());p.srv(s.validate,1,packet.previous_to_current.resource.Get());+ p.srv(s.validate,2,s.luma[0].Get());p.srv(s.validate,3,s.luma[1].Get());+ makeUav(p.device,motion,motion->GetDesc().Format,Impl::cpu(s.validate,4));+ makeUav(p.device,confidence,confidence->GetDesc().Format,Impl::cpu(s.validate,5));+ states.transition(list,motion,D3D12_RESOURCE_STATE_UNORDERED_ACCESS);states.transition(list,confidence,D3D12_RESOURCE_STATE_UNORDERED_ACCESS);+ s.validate.bind(list,reinterpret_cast<const float*>(dims),Impl::gpu(s.validate,0),Impl::gpu(s.validate,4));+ list->Dispatch((p.w+15)/16,(p.h+15)/16,1);+ states.transition(list,motion,D3D12_RESOURCE_STATE_COMMON);states.transition(list,confidence,D3D12_RESOURCE_STATE_COMMON);+ for(auto& r:s.luma)states.transition(list,r.Get(),D3D12_RESOURCE_STATE_COMMON);+ s.completion=context.completion;+ if(log::verboseFrameLogs())log::info("gpu-dis",std::format("record previous={} current={} slot={} completion={} dispatches={}",previousId,currentId,slot,completion,xess_gpu::strict_dis_shader_dispatches(*p.provider)));+ return true;+}+}diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cppindex 5d028d8d..c64fc85d 100644--- a/src/pipeline/EnhanceGraph.cpp+++ b/src/pipeline/EnhanceGraph.cpp@@ -28,6 +28,7 @@#include "veyra/ngx/NgxParameters.h"#include "veyra/ngx/NvOfSession.h"#include "veyra/guidance/AmdOpticalFlow.h"+#include "veyra/guidance/GpuDisOpticalFlow.h"extern "C" {#include <libavutil/frame.h>@@ -295,6 +296,12 @@ bool EnhanceGraph::initNvof()veyra::log::info("graph", "VEYRA_NO_FEATURES: NVOF session skipped");return true;}+ if(desc_.opticalFlowBackend==engine::OpticalFlowBackend::GpuDis){+ gpuDis_=std::make_unique<guidance::GpuDisOpticalFlow>();+ if(!gpuDis_->initialize(context_.device(),nvofW_,nvofH_))return false;+ mvecSource_="gpu-dis FAST + bidirectional/photometric confidence";+ return true;+ }if(desc_.opticalFlowBackend==engine::OpticalFlowBackend::AmdFidelityFx){amdOf_=std::make_unique<guidance::AmdOpticalFlow>();if(!amdOf_->initialize(context_.device(),nvofW_,nvofH_))return false;@@ -895,7 +902,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame// Guidance from original source-space color before SR/NR. Queue waits are GPU-side.bool haveFlow = false;const bool runMotion = nvofStandalone_ || xessEnabled() || fgEnabled_ || (srEnabled_ && !desc_.videoSrQuality);- if (runMotion && (amdOf_ || (nvof_ && nvof_->initialized()))) {+ if (runMotion && (gpuDis_ || amdOf_ || (nvof_ && nvof_->initialized()))) {const float dims[8] = {uintBits(nvofW_),uintBits(nvofH_),uintBits(nvofW_),uintBits(nvofH_),0,0,0,0};if (prevValid_) {tracker_.transition(list,nvofInB_.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);@@ -917,7 +924,19 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame++metrics_.amdOfExecuteCount;haveFlow=prevValid_;gpuTimer_.mark(list,GpuStage::Flow,true);}- if (prevValid_) {+ if(gpuDis_ && prevValid_){+ gpuTimer_.mark(list,GpuStage::Flow);+ tracker_.transition(list,flowTex_.Get(),D3D12_RESOURCE_STATE_COMMON);+ tracker_.transition(list,confTex_.Get(),D3D12_RESOURCE_STATE_COMMON);+ // The next ring submission signals this value; the parity upload+ // fence above retires all uses before these descriptors are reused.+ if(!gpuDis_->dispatch(list,context_.directQueue(),context_.fence(),ring_.lastSignaledValue()+1,parity,+ nvofInA_.Get(),nvofInB_.Get(),flowTex_.Get(),confTex_.Get(),previousSource_,sourceFrameId))return false;+ tracker_.transition(list,flowTex_.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);+ ++metrics_.gpuDisExecuteCount;haveFlow=true;+ gpuTimer_.mark(list,GpuStage::Flow,true);+ }+ if (prevValid_ && !gpuDis_) {if(!amdOf_){gpuTimer_.mark(list,GpuStage::Flow);if(!ring_.submitAndSignal(slot))return false;@@ -1323,6 +1342,7 @@ void EnhanceGraph::shutdown()(void)nrAdapter_->snippetReleaseFeature(nrHandle_, rr, rs);nrHandle_ = nullptr;}+ gpuDis_.reset();amdOf_.reset();for(auto& motion:presentMotion_)motion.Reset();if (fgBackend_) fgBackend_->release();diff --git a/tests/integration/ExperimentalBackendTests.cpp b/tests/integration/ExperimentalBackendTests.cppindex 60da7890..afede69d 100644--- a/tests/integration/ExperimentalBackendTests.cpp+++ b/tests/integration/ExperimentalBackendTests.cpp@@ -125,11 +125,13 @@ bool readCanonicalFlow(gfx::D3D12DeviceContext& ctx, gfx::CommandSlotRing& ring,int wmain(int argc,wchar_t** argv){if(argc!=3)return 2;- const bool xess=wcscmp(argv[1],L"xess")==0;+ const bool dis=std::wstring(argv[1]).find(L"dis")==0;+ const bool xess=wcscmp(argv[1],L"xess")==0||wcscmp(argv[1],L"dis-xess")==0;const bool amd=wcscmp(argv[1],L"amd")==0;const bool sr=std::wstring(argv[1]).find(L"sr")==0;- if(!xess&&!amd&&!sr)return 2;- const unsigned width=sr?1920:640,height=sr?1080:360,frames=sr?3:48;+ if(!xess&&!amd&&!sr&&!dis&&wcscmp(argv[1],L"nvof1080")!=0)return 2;+ const bool full=std::wstring(argv[1]).find(L"1080")!=std::wstring::npos;+ const unsigned width=(sr||full)?1920:640,height=(sr||full)?1080:360,frames=sr?3:48;CoInitializeEx(nullptr,COINIT_MULTITHREADED);std::filesystem::create_directories(argv[2]);Logger::instance().openFile((std::filesystem::path(argv[2])/"engine.log").wstring());@@ -143,11 +145,11 @@ int wmain(int argc,wchar_t** argv){Microsoft::WRL::ComPtr<ID3D12InfoQueue> info;ctx.device()->QueryInterface(IID_PPV_ARGS(&info));pipeline::EnhanceGraph graph(ctx,ring);engine::VideoPresenter presenter;pipeline::EnhanceGraphDesc desc;- desc.sourceWidth=desc.workWidth=640;desc.sourceHeight=desc.workHeight=360;+ desc.sourceWidth=desc.workWidth=width;desc.sourceHeight=desc.workHeight=height;desc.rgbInput=true;desc.enableNr=false;desc.enableFg=xess;desc.noNgx=true;desc.enableNvofStandalone=true;desc.frameGenerationBackend=engine::FrameGenerationBackend::XeSS;- desc.opticalFlowBackend=amd?engine::OpticalFlowBackend::AmdFidelityFx:engine::OpticalFlowBackend::Nvidia;+ desc.opticalFlowBackend=dis?engine::OpticalFlowBackend::GpuDis:amd?engine::OpticalFlowBackend::AmdFidelityFx:engine::OpticalFlowBackend::Nvidia;if(sr){desc.sourceWidth=width;desc.sourceHeight=height;desc.workWidth=std::wstring(argv[1]).find(L"8k")!=std::wstring::npos?7680:2560;@@ -183,7 +185,7 @@ int wmain(int argc,wchar_t** argv){if(xess)ok=ok&&presenter.xessGeneratedCount()==before;}if(i==24)SetWindowPos(window,nullptr,0,0,800,600,SWP_NOACTIVATE|SWP_NOZORDER);- if(amd&&(i==23||i==47)){+ if((amd||dis)&&(i==23||i==47)){ok=ring.drainQueue()&&ok;FlowSample& sample=i==23?rightward:leftward;ok=ok&&readCanonicalFlow(ctx,ring,graph.flowResource(),sample);@@ -192,7 +194,7 @@ int wmain(int argc,wchar_t** argv){}ok=ring.drainQueue()&&ok;const auto generated=presenter.xessGeneratedCount();- const auto dispatches=graph.metrics().amdOfExecuteCount;+ const auto dispatches=dis?graph.metrics().gpuDisExecuteCount:graph.metrics().amdOfExecuteCount;if(sr&&ok){sink::RgbaImage image;ok=graph.metrics().srEvaluateCount==frames&&sink::readRgba8(ctx,ring,graph.videoFrameResource(out.videoSlot),image);@@ -201,13 +203,13 @@ int wmain(int argc,wchar_t** argv){std::cout<<"SR extent="<<image.width<<"x"<<image.height<<" evaluate="<<graph.metrics().srEvaluateCount<<" nonblack="<<nonblack<<" pass="<<ok<<std::endl;}if(xess)ok=ok&&generated>10;- if(amd){+ if(amd||dis){// The source moves right then left. Canonical current->previous motion// must therefore point left then right with no material vertical drift.const bool directionOk=rightward.count>0&&leftward.count>0&&rightward.x<-0.5f&&leftward.x>0.5f&&std::abs(rightward.y)<0.5f&&std::abs(leftward.y)<0.5f;- std::cout<<"AMD flow rightward=("<<rightward.x<<","<<rightward.y<<") leftward=("<<leftward.x<<","<<leftward.y<<") samples="<<rightward.count<<"/"<<leftward.count<<" directionPass="<<directionOk<<std::endl;- ok=ok&&dispatches==48&&directionOk;+ std::cout<<(dis?"GPU DIS flow rightward=(":"AMD flow rightward=(")<<rightward.x<<","<<rightward.y<<") leftward=("<<leftward.x<<","<<leftward.y<<") samples="<<rightward.count<<"/"<<leftward.count<<" directionPass="<<directionOk<<std::endl;+ ok=ok&&dispatches==(dis?46u:48u)&&directionOk;}out={};presenter.close();graph.shutdown();av_frame_free(&frame);uint64_t errors=0;@@ -217,6 +219,6 @@ int wmain(int argc,wchar_t** argv){if(SUCCEEDED(info->GetMessage(i,message,&size))&&message->Severity<=D3D12_MESSAGE_SEVERITY_ERROR){++errors;log::error("debug",message->pDescription);}}ok=ok&&errors==0;- std::cout<<"BACKEND "<<(xess?"xess":amd?"amd-of":"sr")<<" generated="<<generated<<" amdDispatches="<<dispatches<<" debugErrors="<<errors<<" pass="<<ok<<" (SDK submissions, not scanout or visual quality)\n";+ std::cout<<"BACKEND "<<(dis?(xess?"gpu-dis-xess":"gpu-dis"):xess?"xess":amd?"amd-of":"sr")<<" generated="<<generated<<" amdDispatches="<<dispatches<<" debugErrors="<<errors<<" pass="<<ok<<" (SDK submissions, not scanout or visual quality)\n";info.Reset();ring.shutdown();ctx.shutdown();DestroyWindow(window);CoUninitialize();return ok?0:1;}diff --git a/tests/integration/RepairFgTests.cpp b/tests/integration/RepairFgTests.cppindex d445a3f8..d1b8547a 100644--- a/tests/integration/RepairFgTests.cpp+++ b/tests/integration/RepairFgTests.cpp@@ -22,8 +22,10 @@ int main(int argc,char** argv){pipeline::EnhanceGraphDesc gd;gd.sourceWidth=gd.workWidth=1920;gd.sourceHeight=gd.workHeight=1080;gd.enableNr=false;gd.enableSr=false;gd.enableFg=true;gd.runtimeAbsPath=(std::filesystem::path(VEYRA_PROJECT_ROOT)/"runtime_local/nvidia").wstring();const std::string mode=argc>1?argv[1]:"off";gd.enableNr=mode!="off";gd.enableNvofStandalone=gd.enableNr;+ if(mode.starts_with("dis"))gd.opticalFlowBackend=engine::OpticalFlowBackend::GpuDis;if(mode=="flowP")gd.flowQuality=engine::FlowQuality::Performance;if(mode=="flowQ")gd.flowQuality=engine::FlowQuality::Quality;+ if(mode=="dis-sr"){gd.workWidth=3840;gd.workHeight=2160;gd.nrWidth=1920;gd.nrHeight=1080;gd.enableSr=true;gd.videoSrQuality=2;}if(mode=="sr"){gd.workWidth=3840;gd.workHeight=2160;gd.nrWidth=1920;gd.nrHeight=1080;gd.enableSr=true;}if(mode=="mfg3"||mode=="mfg4"){gd.fgMultiplier=mode=="mfg3"?3:4;gd.enableNr=false;gd.enableNvofStandalone=false;}if(ok)ok=graph.initialize(gd)&&graph.createViews();@@ -48,7 +50,7 @@ int main(int argc,char** argv){previous=std::move(real);if(i==10)retained=out.batch;}- std::cout<<"RESULT source="<<graph.metrics().nvofExecuteCount+1<<" generated="<<generated<<" contentValid="<<valid<<" display=unmeasured"<<std::endl;+ std::cout<<"RESULT source="<<graph.metrics().nvofExecuteCount+graph.metrics().gpuDisExecuteCount+1<<" generated="<<generated<<" contentValid="<<valid<<" display=unmeasured"<<std::endl;pipeline::EnhanceGraph::FrameOutputs rejected;const bool protectedLease=ok&&!graph.process(f,240,false,rejected);std::cout<<"LEASE retained-slot-overwrite-rejected="<<protectedLease<<std::endl;diff --git a/tests/unit/RepairPresetTests.cpp b/tests/unit/RepairPresetTests.cppindex 53ddff86..d4dd4ec6 100644--- a/tests/unit/RepairPresetTests.cpp+++ b/tests/unit/RepairPresetTests.cpp@@ -56,7 +56,8 @@ int main(int argc,char** argv){if(argc!=2)return 2;using namespace veyra::engineauto xess=s;xess.frameGenerationBackend=FrameGenerationBackend::XeSS;ok=ok&&!b.put(L"XeSS 4X rejected",xess);xess.multiplier=2;ok=ok&&b.put(L"XeSS 2X",xess);PresetStore xessReload(p);ok=ok&&xessReload.load()&&xessReload.entries().back().settings==xess&&b.erase(1);auto badBackend=s;badBackend.frameGenerationBackend=static_cast<FrameGenerationBackend>(3);ok=ok&&!b.put(L"invalid backend",badBackend);- auto badFlow=s;badFlow.opticalFlowBackend=static_cast<OpticalFlowBackend>(2);ok=ok&&!b.put(L"invalid flow backend",badFlow);+ auto dis=s;dis.opticalFlowBackend=OpticalFlowBackend::GpuDis;ok=ok&&b.put(L"GPU DIS",dis)&&b.save();PresetStore disReload(p);ok=ok&&disReload.load()&&disReload.entries().back().settings==dis&&b.erase(1);+ auto badFlow=s;badFlow.opticalFlowBackend=static_cast<OpticalFlowBackend>(3);ok=ok&&!b.put(L"invalid flow backend",badFlow);auto badNr=s;badNr.nrRuntime=static_cast<NrRuntime>(2);ok=ok&&!b.put(L"invalid NR runtime",badNr);auto half=s;half.content=ContentRate::Capture60To30;ok=ok&&b.put(L"capture half rate",half);PresetStore halfReload(p);ok=ok&&halfReload.load()&&halfReload.entries().back().settings.content==ContentRate::Capture60To30&&b.erase(1);auto badSr=s;badSr.videoSrQuality=5;ok=ok&&!b.put(L"invalid video SR",badSr);diff --git a/third_party/gpu-dis/LICENSE b/third_party/gpu-dis/LICENSEnew file mode 100644index 00000000..d6456956--- /dev/null+++ b/third_party/gpu-dis/LICENSE@@ -0,0 +1,202 @@++ Apache License+ Version 2.0, January 2004+ http://www.apache.org/licenses/++ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION++ 1. Definitions.++ "License" shall mean the terms and conditions for use, reproduction,+ and distribution as defined by Sections 1 through 9 of this document.++ "Licensor" shall mean the copyright owner or entity authorized by+ the copyright owner that is granting the License.++ "Legal Entity" shall mean the union of the acting entity and all+ other entities that control, are controlled by, or are under common+ control with that entity. For the purposes of this definition,+ "control" means (i) the power, direct or indirect, to cause the+ direction or management of such entity, whether by contract or+ otherwise, or (ii) ownership of fifty percent (50%) or more of the+ outstanding shares, or (iii) beneficial ownership of such entity.++ "You" (or "Your") shall mean an individual or Legal Entity+ exercising permissions granted by this License.++ "Source" form shall mean the preferred form for making modifications,+ including but not limited to software source code, documentation+ source, and configuration files.++ "Object" form shall mean any form resulting from mechanical+ transformation or translation of a Source form, including but+ not limited to compiled object code, generated documentation,+ and conversions to other media types.++ "Work" shall mean the work of authorship, whether in Source or+ Object form, made available under the License, as indicated by a+ copyright notice that is included in or attached to the work+ (an example is provided in the Appendix below).++ "Derivative Works" shall mean any work, whether in Source or Object+ form, that is based on (or derived from) the Work and for which the+ editorial revisions, annotations, elaborations, or other modifications+ represent, as a whole, an original work of authorship. For the purposes+ of this License, Derivative Works shall not include works that remain+ separable from, or merely link (or bind by name) to the interfaces of,+ the Work and Derivative Works thereof.++ "Contribution" shall mean any work of authorship, including+ the original version of the Work and any modifications or additions+ to that Work or Derivative Works thereof, that is intentionally+ submitted to Licensor for inclusion in the Work by the copyright owner+ or by an individual or Legal Entity authorized to submit on behalf of+ the copyright owner. For the purposes of this definition, "submitted"+ means any form of electronic, verbal, or written communication sent+ to the Licensor or its representatives, including but not limited to+ communication on electronic mailing lists, source code control systems,+ and issue tracking systems that are managed by, or on behalf of, the+ Licensor for the purpose of discussing and improving the Work, but+ excluding communication that is conspicuously marked or otherwise+ designated in writing by the copyright owner as "Not a Contribution."++ "Contributor" shall mean Licensor and any individual or Legal Entity+ on behalf of whom a Contribution has been received by Licensor and+ subsequently incorporated within the Work.++ 2. Grant of Copyright License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ copyright license to reproduce, prepare Derivative Works of,+ publicly display, publicly perform, sublicense, and distribute the+ Work and such Derivative Works in Source or Object form.++ 3. Grant of Patent License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ (except as stated in this section) patent license to make, have made,+ use, offer to sell, sell, import, and otherwise transfer the Work,+ where such license applies only to those patent claims licensable+ by such Contributor that are necessarily infringed by their+ Contribution(s) alone or by combination of their Contribution(s)+ with the Work to which such Contribution(s) was submitted. If You+ institute patent litigation against any entity (including a+ cross-claim or counterclaim in a lawsuit) alleging that the Work+ or a Contribution incorporated within the Work constitutes direct+ or contributory patent infringement, then any patent licenses+ granted to You under this License for that Work shall terminate+ as of the date such litigation is filed.++ 4. Redistribution. You may reproduce and distribute copies of the+ Work or Derivative Works thereof in any medium, with or without+ modifications, and in Source or Object form, provided that You+ meet the following conditions:++ (a) You must give any other recipients of the Work or+ Derivative Works a copy of this License; and++ (b) You must cause any modified files to carry prominent notices+ stating that You changed the files; and++ (c) You must retain, in the Source form of any Derivative Works+ that You distribute, all copyright, patent, trademark, and+ attribution notices from the Source form of the Work,+ excluding those notices that do not pertain to any part of+ the Derivative Works; and++ (d) If the Work includes a "NOTICE" text file as part of its+ distribution, then any Derivative Works that You distribute must+ include a readable copy of the attribution notices contained+ within such NOTICE file, excluding those notices that do not+ pertain to any part of the Derivative Works, in at least one+ of the following places: within a NOTICE text file distributed+ as part of the Derivative Works; within the Source form or+ documentation, if provided along with the Derivative Works; or,+ within a display generated by the Derivative Works, if and+ wherever such third-party notices normally appear. The contents+ of the NOTICE file are for informational purposes only and+ do not modify the License. You may add Your own attribution+ notices within Derivative Works that You distribute, alongside+ or as an addendum to the NOTICE text from the Work, provided+ that such additional attribution notices cannot be construed+ as modifying the License.++ You may add Your own copyright statement to Your modifications and+ may provide additional or different license terms and conditions+ for use, reproduction, or distribution of Your modifications, or+ for any such Derivative Works as a whole, provided Your use,+ reproduction, and distribution of the Work otherwise complies with+ the conditions stated in this License.++ 5. Submission of Contributions. Unless You explicitly state otherwise,+ any Contribution intentionally submitted for inclusion in the Work+ by You to the Licensor shall be under the terms and conditions of+ this License, without any additional terms or conditions.+ Notwithstanding the above, nothing herein shall supersede or modify+ the terms of any separate license agreement you may have executed+ with Licensor regarding such Contributions.++ 6. Trademarks. This License does not grant permission to use the trade+ names, trademarks, service marks, or product names of the Licensor,+ except as required for reasonable and customary use in describing the+ origin of the Work and reproducing the content of the NOTICE file.++ 7. Disclaimer of Warranty. Unless required by applicable law or+ agreed to in writing, Licensor provides the Work (and each+ Contributor provides its Contributions) on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or+ implied, including, without limitation, any warranties or conditions+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A+ PARTICULAR PURPOSE. You are solely responsible for determining the+ appropriateness of using or redistributing the Work and assume any+ risks associated with Your exercise of permissions under this License.++ 8. Limitation of Liability. In no event and under no legal theory,+ whether in tort (including negligence), contract, or otherwise,+ unless required by applicable law (such as deliberate and grossly+ negligent acts) or agreed to in writing, shall any Contributor be+ liable to You for damages, including any direct, indirect, special,+ incidental, or consequential damages of any character arising as a+ result of this License or out of the use or inability to use the+ Work (including but not limited to damages for loss of goodwill,+ work stoppage, computer failure or malfunction, or any and all+ other commercial damages or losses), even if such Contributor+ has been advised of the possibility of such damages.++ 9. Accepting Warranty or Additional Liability. While redistributing+ the Work or Derivative Works thereof, You may choose to offer,+ and charge a fee for, acceptance of support, warranty, indemnity,+ or other liability obligations and/or rights consistent with this+ License. However, in accepting such obligations, You may act only+ on Your own behalf and on Your sole responsibility, not on behalf+ of any other Contributor, and only if You agree to indemnify,+ defend, and hold each Contributor harmless for any liability+ incurred by, or claims asserted against, such Contributor by reason+ of your accepting any such warranty or additional liability.++ END OF TERMS AND CONDITIONS++ APPENDIX: How to apply the Apache License to your work.++ To apply the Apache License to your work, attach the following+ boilerplate notice, with the fields enclosed by brackets "[]"+ replaced with your own identifying information. (Don't include+ the brackets!) The text should be enclosed in the appropriate+ comment syntax for the file format. We also recommend that a+ file or class name and description of purpose be included on the+ same "printed page" as the copyright notice for easier+ identification within third-party archives.++ Copyright [yyyy] [name of copyright owner]++ Licensed under the Apache License, Version 2.0 (the "License");+ you may not use this file except in compliance with the License.+ You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing, software+ distributed under the License is distributed on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ See the License for the specific language governing permissions and+ limitations under the License.diff --git a/third_party/gpu-dis/NOTICE b/third_party/gpu-dis/NOTICEnew file mode 100644index 00000000..b466335e--- /dev/null+++ b/third_party/gpu-dis/NOTICE@@ -0,0 +1,20 @@+XeSS GPU Motion — GPU Block / GPU DIS R4.2 source snapshot++The project's own additions and modifications are licensed under Apache-2.0.+This statement does not replace upstream licenses or assert ownership of+third-party contributions. See PROVENANCE.md and licenses/.++OpenCV DIS and related reference/ported code:+Copyright (C) 2000-2008, Intel Corporation, all rights reserved.+Copyright (C) 2009, Willow Garage Inc., all rights reserved.+Third party copyrights are property of their respective owners.+The retained BSD file-header terms are in licenses/OPENCV_DIS_BSD_HEADER.txt.+The OpenCV project Apache-2.0 text is in licenses/OPENCV_APACHE_LICENSE.txt.+Sources include OpenCV modules/video/src/dis_flow.cpp,+variational_refinement.cpp, and related DIS, interpolation and image-conversion+implementations. The D3D12/HLSL port and integration are modifications.++Intel XeSS, XeFG and XeLL are Intel technologies used through documented APIs.+Intel SDK binaries and headers are not licensed by this repository's LICENSE.+oneVPL, OpenVINO, OpenCL, Microsoft Windows SDK and build tools retain their+respective upstream terms. No vendor endorsement is implied.diff --git a/third_party/gpu-dis/PROVENANCE.md b/third_party/gpu-dis/PROVENANCE.mdnew file mode 100644index 00000000..ba1f4cbd--- /dev/null+++ b/third_party/gpu-dis/PROVENANCE.md@@ -0,0 +1,15 @@+# 来源、版本与改动++这是 R4.2 离线原生引擎的干净文件快照;source-manifest.json 记录每个原始文件的 SHA256 和编译配方。它不含旧 Git 历史。两个目标共用一套必需的离线基础代码。++GPU DIS 参考/移植 OpenCV 5.0 系列 CPU DIS,包括 modules/video/src/dis_flow.cpp、variational_refinement.cpp 以及 DIS OpenCL/插值、梯度与灰度相关实现。来源:https://github.com/opencv/opencv 。项目根 Apache-2.0 与具体文件的 BSD 版权/免责条款并存;本项目保留这些原许可,不替上游重新署名。++移植改动包括 D3D12 资源/描述符/命令组织、HLSL shader、并行 patch 排程、精确浮点/整数语义选择、FFmpeg7.1 limited RGB24→OpenCV GRAY 输入适配、R4.2 RGBA 共享表面入口、每槽独立 binding、GPU fence/所有权检查以及集成 worker。源码中提到的 OpenCV/FFmpeg 行为是明确的来源或兼容性目标;不保证与任意其他版本或后端相同。++GPU Block 的当前估计器采用 17×17 整数候选搜索和 3×3 SAD,与严格 DIS 的 inverse search/VR 组织不同。两路线的开发均参考 CPU DIS,因此不能将实现差异描述成无上游来源的证明。上游归属和原许可同时适用于相关借用部分。++共享基础设施通过公开 API 使用 oneVPL、OpenVINO、OpenCL、XeSS/XeFG/XeLL 与 Windows 图形接口。第三方 SDK、模型、运行库和工具链不在这里发布,按原厂条款另行获取。这里没有 NVIDIA SDK 源码。++部分共享源文件沿用 probe 命名,这是历史文件组织;本导出已移除四处不用的独立诊断 main,保留正式 worker 必需的共享库/兼容路径。严格 DIS 正式入口与 Block 正式入口以 README/BUILDING 所述为准。source-manifest.json 同时保留整理前 original_sha256 和整理后 sha256,以记录来源与删除边界。++自有新增和修改部分经权利人授权采用 Apache-2.0,上游代码原有权利不变;未断言拥有第三方部分的独占版权。原许可副本见 licenses。diff --git a/third_party/gpu-dis/VEYRA_INTEGRATION.md b/third_party/gpu-dis/VEYRA_INTEGRATION.mdnew file mode 100644index 00000000..31ffb7b6--- /dev/null+++ b/third_party/gpu-dis/VEYRA_INTEGRATION.md@@ -0,0 +1,36 @@+# GPU DIS subset used by Veyra++Source: https://github.com/gggz114514-oss/XeSS-GPU-Motion++Pinned Git commit: `cb7523b5104fc914dc501767c3139b43c2067af7`.+The upstream export labels itself R4.2 and records its pre-export snapshot separately as `ed27d62ad7ce17f67f4db936ed2fc5d48e6b0f87`.++Only the public D3D12 DIS provider, GPU frame contract and DIS shader closure+are included. No Intel SDK headers, runtime binaries, oneVPL/OpenVINO worker,+models, GPU Block provider or other application implementation is included.+The native provider and shaders retain upstream license headers. See LICENSE,+NOTICE, PROVENANCE.md, and licenses/ for Apache-2.0 and OpenCV BSD terms.+References in the original PROVENANCE.md to other components describe the full+upstream project, not the contents of this subset.++Veyra modifications, 2026-09-13:++- `native_strict_dis_provider.cpp`: stage SRV creation in a non-visible heap+ before copying into the visible heap, following Veyra's existing driver workaround.+- Removed an extra trailing blank line from the BSD license file; its text is unchanged.+- Algorithm and shader math are unchanged. `shader-recipes.json` contains the+ DIS entries selected from upstream source-manifest.json. The CMake recipe+ retains their entry points, macros and strict floating-point flags.+- Veyra selects FAST with two slots and both directions. This is not a claim+ of parity with the author's newer real-time toolbox or its default preset.+- The adapter outside this directory converts existing encoded flow RGB to+ full-range BT.709 R8 luma on GPU. RawLuma8 avoids a second limited-range+ expansion. Output is current-to-previous in flow-input pixel units, with+ photometric and roundtrip confidence; the shared FlowAdapt scales once for+ each consumer. Source pictures themselves are unchanged.+- Veyra supplies the queue and completion fence, retires slots before descriptor+ reuse, and drains before destruction. No new CPU pixel readback or per-pass wait.++Future binary packages must include this file, LICENSE, NOTICE, PROVENANCE.md,+licenses/* and all compiled `shaders/dis/*.dxil` alongside Veyra's adapter shaders.+The source subset and build recipes remain in the matching Veyra source revision.diff --git a/third_party/gpu-dis/licenses/OPENCV_APACHE_LICENSE.txt b/third_party/gpu-dis/licenses/OPENCV_APACHE_LICENSE.txtnew file mode 100644index 00000000..d6456956--- /dev/null+++ b/third_party/gpu-dis/licenses/OPENCV_APACHE_LICENSE.txt@@ -0,0 +1,202 @@++ Apache License+ Version 2.0, January 2004+ http://www.apache.org/licenses/++ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION++ 1. Definitions.++ "License" shall mean the terms and conditions for use, reproduction,+ and distribution as defined by Sections 1 through 9 of this document.++ "Licensor" shall mean the copyright owner or entity authorized by+ the copyright owner that is granting the License.++ "Legal Entity" shall mean the union of the acting entity and all+ other entities that control, are controlled by, or are under common+ control with that entity. For the purposes of this definition,+ "control" means (i) the power, direct or indirect, to cause the+ direction or management of such entity, whether by contract or+ otherwise, or (ii) ownership of fifty percent (50%) or more of the+ outstanding shares, or (iii) beneficial ownership of such entity.++ "You" (or "Your") shall mean an individual or Legal Entity+ exercising permissions granted by this License.++ "Source" form shall mean the preferred form for making modifications,+ including but not limited to software source code, documentation+ source, and configuration files.++ "Object" form shall mean any form resulting from mechanical+ transformation or translation of a Source form, including but+ not limited to compiled object code, generated documentation,+ and conversions to other media types.++ "Work" shall mean the work of authorship, whether in Source or+ Object form, made available under the License, as indicated by a+ copyright notice that is included in or attached to the work+ (an example is provided in the Appendix below).++ "Derivative Works" shall mean any work, whether in Source or Object+ form, that is based on (or derived from) the Work and for which the+ editorial revisions, annotations, elaborations, or other modifications+ represent, as a whole, an original work of authorship. For the purposes+ of this License, Derivative Works shall not include works that remain+ separable from, or merely link (or bind by name) to the interfaces of,+ the Work and Derivative Works thereof.++ "Contribution" shall mean any work of authorship, including+ the original version of the Work and any modifications or additions+ to that Work or Derivative Works thereof, that is intentionally+ submitted to Licensor for inclusion in the Work by the copyright owner+ or by an individual or Legal Entity authorized to submit on behalf of+ the copyright owner. For the purposes of this definition, "submitted"+ means any form of electronic, verbal, or written communication sent+ to the Licensor or its representatives, including but not limited to+ communication on electronic mailing lists, source code control systems,+ and issue tracking systems that are managed by, or on behalf of, the+ Licensor for the purpose of discussing and improving the Work, but+ excluding communication that is conspicuously marked or otherwise+ designated in writing by the copyright owner as "Not a Contribution."++ "Contributor" shall mean Licensor and any individual or Legal Entity+ on behalf of whom a Contribution has been received by Licensor and+ subsequently incorporated within the Work.++ 2. Grant of Copyright License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ copyright license to reproduce, prepare Derivative Works of,+ publicly display, publicly perform, sublicense, and distribute the+ Work and such Derivative Works in Source or Object form.++ 3. Grant of Patent License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ (except as stated in this section) patent license to make, have made,+ use, offer to sell, sell, import, and otherwise transfer the Work,+ where such license applies only to those patent claims licensable+ by such Contributor that are necessarily infringed by their+ Contribution(s) alone or by combination of their Contribution(s)+ with the Work to which such Contribution(s) was submitted. If You+ institute patent litigation against any entity (including a+ cross-claim or counterclaim in a lawsuit) alleging that the Work+ or a Contribution incorporated within the Work constitutes direct+ or contributory patent infringement, then any patent licenses+ granted to You under this License for that Work shall terminate+ as of the date such litigation is filed.++ 4. Redistribution. You may reproduce and distribute copies of the+ Work or Derivative Works thereof in any medium, with or without+ modifications, and in Source or Object form, provided that You+ meet the following conditions:++ (a) You must give any other recipients of the Work or+ Derivative Works a copy of this License; and++ (b) You must cause any modified files to carry prominent notices+ stating that You changed the files; and++ (c) You must retain, in the Source form of any Derivative Works+ that You distribute, all copyright, patent, trademark, and+ attribution notices from the Source form of the Work,+ excluding those notices that do not pertain to any part of+ the Derivative Works; and++ (d) If the Work includes a "NOTICE" text file as part of its+ distribution, then any Derivative Works that You distribute must+ include a readable copy of the attribution notices contained+ within such NOTICE file, excluding those notices that do not+ pertain to any part of the Derivative Works, in at least one+ of the following places: within a NOTICE text file distributed+ as part of the Derivative Works; within the Source form or+ documentation, if provided along with the Derivative Works; or,+ within a display generated by the Derivative Works, if and+ wherever such third-party notices normally appear. The contents+ of the NOTICE file are for informational purposes only and+ do not modify the License. You may add Your own attribution+ notices within Derivative Works that You distribute, alongside+ or as an addendum to the NOTICE text from the Work, provided+ that such additional attribution notices cannot be construed+ as modifying the License.++ You may add Your own copyright statement to Your modifications and+ may provide additional or different license terms and conditions+ for use, reproduction, or distribution of Your modifications, or+ for any such Derivative Works as a whole, provided Your use,+ reproduction, and distribution of the Work otherwise complies with+ the conditions stated in this License.++ 5. Submission of Contributions. Unless You explicitly state otherwise,+ any Contribution intentionally submitted for inclusion in the Work+ by You to the Licensor shall be under the terms and conditions of+ this License, without any additional terms or conditions.+ Notwithstanding the above, nothing herein shall supersede or modify+ the terms of any separate license agreement you may have executed+ with Licensor regarding such Contributions.++ 6. Trademarks. This License does not grant permission to use the trade+ names, trademarks, service marks, or product names of the Licensor,+ except as required for reasonable and customary use in describing the+ origin of the Work and reproducing the content of the NOTICE file.++ 7. Disclaimer of Warranty. Unless required by applicable law or+ agreed to in writing, Licensor provides the Work (and each+ Contributor provides its Contributions) on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or+ implied, including, without limitation, any warranties or conditions+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A+ PARTICULAR PURPOSE. You are solely responsible for determining the+ appropriateness of using or redistributing the Work and assume any+ risks associated with Your exercise of permissions under this License.++ 8. Limitation of Liability. In no event and under no legal theory,+ whether in tort (including negligence), contract, or otherwise,+ unless required by applicable law (such as deliberate and grossly+ negligent acts) or agreed to in writing, shall any Contributor be+ liable to You for damages, including any direct, indirect, special,+ incidental, or consequential damages of any character arising as a+ result of this License or out of the use or inability to use the+ Work (including but not limited to damages for loss of goodwill,+ work stoppage, computer failure or malfunction, or any and all+ other commercial damages or losses), even if such Contributor+ has been advised of the possibility of such damages.++ 9. Accepting Warranty or Additional Liability. While redistributing+ the Work or Derivative Works thereof, You may choose to offer,+ and charge a fee for, acceptance of support, warranty, indemnity,+ or other liability obligations and/or rights consistent with this+ License. However, in accepting such obligations, You may act only+ on Your own behalf and on Your sole responsibility, not on behalf+ of any other Contributor, and only if You agree to indemnify,+ defend, and hold each Contributor harmless for any liability+ incurred by, or claims asserted against, such Contributor by reason+ of your accepting any such warranty or additional liability.++ END OF TERMS AND CONDITIONS++ APPENDIX: How to apply the Apache License to your work.++ To apply the Apache License to your work, attach the following+ boilerplate notice, with the fields enclosed by brackets "[]"+ replaced with your own identifying information. (Don't include+ the brackets!) The text should be enclosed in the appropriate+ comment syntax for the file format. We also recommend that a+ file or class name and description of purpose be included on the+ same "printed page" as the copyright notice for easier+ identification within third-party archives.++ Copyright [yyyy] [name of copyright owner]++ Licensed under the Apache License, Version 2.0 (the "License");+ you may not use this file except in compliance with the License.+ You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing, software+ distributed under the License is distributed on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ See the License for the specific language governing permissions and+ limitations under the License.diff --git a/third_party/gpu-dis/licenses/OPENCV_DIS_BSD_HEADER.txt b/third_party/gpu-dis/licenses/OPENCV_DIS_BSD_HEADER.txtnew file mode 100644index 00000000..37c87ba7--- /dev/null+++ b/third_party/gpu-dis/licenses/OPENCV_DIS_BSD_HEADER.txt@@ -0,0 +1,41 @@+/*M///////////////////////////////////////////////////////////////////////////////////////+//+// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.+//+// By downloading, copying, installing or using the software you agree to this license.+// If you do not agree to this license, do not download, install,+// copy or use the software.+//+//+// License Agreement+// For Open Source Computer Vision Library+//+// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.+// Copyright (C) 2009, Willow Garage Inc., all rights reserved.+// Third party copyrights are property of their respective owners.+//+// Redistribution and use in source and binary forms, with or without modification,+// are permitted provided that the following conditions are met:+//+// * Redistribution's of source code must retain the above copyright notice,+// this list of conditions and the following disclaimer.+//+// * Redistribution's in binary form must reproduce the above copyright notice,+// this list of conditions and the following disclaimer in the documentation+// and/or other materials provided with the distribution.+//+// * The name of the copyright holders may not be used to endorse or promote products+// derived from this software without specific prior written permission.+//+// This software is provided by the copyright holders and contributors "as is" and+// any express or implied warranties, including, but not limited to, the implied+// warranties of merchantability and fitness for a particular purpose are disclaimed.+// In no event shall the Intel Corporation or contributors be liable for any direct,+// indirect, incidental, special, exemplary, or consequential damages+// (including, but not limited to, procurement of substitute goods or services;+// loss of use, data, or profits; or business interruption) however caused+// and on any theory of liability, whether in contract, strict liability,+// or tort (including negligence or otherwise) arising in any way out of+// the use of this software, even if advised of the possibility of such damage.+//+//M*/diff --git a/third_party/gpu-dis/shader-recipes.json b/third_party/gpu-dis/shader-recipes.jsonnew file mode 100644index 00000000..974fd1fd--- /dev/null+++ b/third_party/gpu-dis/shader-recipes.json@@ -0,0 +1,254 @@+[+ {+ "source": "src/gpu/shaders/dis_native_gray.hlsl",+ "output": "shaders/dis/dis_native_gray.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_native_rgba_gray.hlsl",+ "output": "shaders/dis/dis_native_rgba_gray.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_native_luma.hlsl",+ "output": "shaders/dis/dis_native_luma.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_perfect_area.hlsl",+ "output": "shaders/dis/dis_perfect_area.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_d2_gradient.hlsl",+ "output": "shaders/dis/dis_d2_gradient.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_d3_structure_hor.hlsl",+ "output": "shaders/dis/dis_d3_structure_hor.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_d3_structure_ver.hlsl",+ "output": "shaders/dis/dis_d3_structure_ver.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_perfect_vr_deriv2.hlsl",+ "output": "shaders/dis/dis_perfect_vr_deriv2.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_perfect_vr_update.hlsl",+ "output": "shaders/dis/dis_perfect_vr_update.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_perfect_vr_zero.hlsl",+ "output": "shaders/dis/dis_perfect_vr_zero.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_d3_structure_hor.hlsl",+ "output": "shaders/dis/dis_d3_structure_hor_stride3.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main",+ "-D",+ "DIS_TENSOR_STRIDE=3"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_d3_structure_ver.hlsl",+ "output": "shaders/dis/dis_d3_structure_ver_stride3.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main",+ "-D",+ "DIS_TENSOR_STRIDE=3"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_perfect_patch_exact.hlsl",+ "output": "shaders/dis/dis_perfect_patch_parallel.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main",+ "-D",+ "DIS_SINGLE_PATCH_GROUP=1",+ "-D",+ "DIS_ROUNDED_DIVIDE=1",+ "-D",+ "DIS_PARALLEL_STRIPES=1"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_perfect_densify.hlsl",+ "output": "shaders/dis/dis_perfect_densify_exact.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main",+ "-D",+ "DIS_DENSE_EXACT=1"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_perfect_vr_deriv1.hlsl",+ "output": "shaders/dis/dis_perfect_vr_deriv1_cpu.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main",+ "-Gis",+ "-D",+ "DIS_VR_CPU_WARP=1"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_perfect_vr_system.hlsl",+ "output": "shaders/dis/dis_perfect_vr_system_exact.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main",+ "-Gis",+ "-D",+ "DIS_VR_EXACT=1"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_perfect_vr_sor.hlsl",+ "output": "shaders/dis/dis_perfect_vr_sor_exact.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main",+ "-Gis",+ "-D",+ "DIS_VR_EXACT=1"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_perfect_upsample.hlsl",+ "output": "shaders/dis/dis_perfect_upsample_ipp.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main",+ "-D",+ "DIS_IPP_UPSAMPLE=1"+ ]+ },+ {+ "source": "src/gpu/shaders/dis_perfect_final.hlsl",+ "output": "shaders/dis/dis_perfect_final.dxil",+ "compiler": "dxc",+ "arguments": [+ "-nologo",+ "-T",+ "cs_6_0",+ "-E",+ "main",+ "-Gis"+ ]+ }+]diff --git a/third_party/gpu-dis/src/gpu/gpu_frame_contract.h b/third_party/gpu-dis/src/gpu/gpu_frame_contract.hnew file mode 100644index 00000000..ac9ffdb8--- /dev/null+++ b/third_party/gpu-dis/src/gpu/gpu_frame_contract.h@@ -0,0 +1,173 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.++#pragma once++// Native GPU provider contract v1. No SDK-specific resource tags or CPU pixel+// arrays cross this boundary. Recording never submits or waits the caller queue.+#include <d3d12.h>+#include <wrl/client.h>+#include <cstdint>+#include <string>+#include <vector>++namespace xess_gpu {+using Microsoft::WRL::ComPtr;+constexpr uint32_t kContractVersion = 1;+constexpr uint64_t kNoFrame = UINT64_MAX;++struct Rational { int64_t numerator = 0; int64_t denominator = 1; };+struct Extent { uint32_t width = 0, height = 0; };+struct Crop { uint32_t x = 0, y = 0, width = 0, height = 0; };+enum class Matrix : uint8_t { Unknown, Rgb, Bt601, Bt709, Bt2020 };+enum class Range : uint8_t { Unknown, Full, Limited };+enum class Transfer : uint8_t { Unknown, Linear, Srgb, Bt709, Pq, Hlg };+enum class ResetReason : uint32_t {+ None = 0, FirstFrame = 1, SceneCut = 2, InputDrop = 4,+ GeometryChange = 8, TimestampDiscontinuity = 16, DeviceChange = 32,+ Explicit = 64+};+enum class Consumer : uint8_t { Motion, Depth, Sr, Fg, Post, Encode, Display };++struct FencePoint {+ ComPtr<ID3D12Fence> fence;+ uint64_t value = 0;+ bool complete() const noexcept {+ return !value || (fence && fence->GetCompletedValue() != UINT64_MAX &&+ fence->GetCompletedValue() >= value);+ }+};+struct ConsumerRelease { Consumer consumer; FencePoint completion; };++// Owner pins both the texture and any producer pool lease. A decoder's surface+// lease must remain live until every consumer has actually completed, including+// use as the next pair's previous frame. CPU-ready does not mean releasable.+struct TextureView {+ ComPtr<ID3D12Resource> resource;+ DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;+ Extent allocation;+ Crop valid;+ D3D12_RESOURCE_STATES state = D3D12_RESOURCE_STATE_COMMON;+};+struct FrameMetadata {+ uint64_t source_frame_id = kNoFrame;+ uint64_t previous_source_frame_id = kNoFrame;+ uint64_t next_source_frame_id = kNoFrame;+ int64_t original_pts = 0;+ Rational original_time_base;+ Rational duration;+ bool pts_known = false;+ bool pts_synthesized = false;+ Matrix matrix = Matrix::Unknown;+ Range range = Range::Unknown;+ Transfer transfer = Transfer::Unknown;+ LUID adapter_luid{};+ ResetReason reset = ResetReason::None;+};+struct FrameLease {+ FrameMetadata metadata;+ TextureView color;+ ComPtr<IUnknown> producer_pool_owner;+ ComPtr<ID3D12CommandQueue> producer_queue;+ FencePoint produced;+ std::vector<ConsumerRelease> consumers;+ bool consumers_registered = false;+ bool releasable() const noexcept {+ if (!consumers_registered || !produced.complete()) return false;+ for (const auto& item : consumers)+ if (!item.completion.complete()) return false;+ return true;+ }+};++enum class ConfidenceDefinition : uint8_t {+ Unavailable, BlockMatchPhotometricAndUniqueness,+ ForwardBackwardPhotometricReliability, ProviderDocumented+};+struct MotionPacket {+ uint32_t contract_version = kContractVersion;+ uint64_t previous_source_frame_id = kNoFrame;+ uint64_t current_source_frame_id = kNoFrame;+ FrameMetadata current_metadata;+ // Integer texel p represents source pixel center p+0.5. xy is displacement+ // in SOURCE valid-region pixels. Primary direction is current -> previous.+ TextureView current_to_previous;+ TextureView previous_to_current;+ TextureView confidence;+ TextureView reliability;+ ConfidenceDefinition confidence_definition = ConfidenceDefinition::Unavailable;+ std::string confidence_semantics;+ bool has_reverse = false;+ bool first_frame_self = false;+ FencePoint produced;+};+struct DepthPacket {+ uint64_t current_source_frame_id = kNoFrame;+ TextureView inverse_depth; // normalized [0,1], larger means nearer+ std::string model_sha256;+ std::string preprocessing;+ std::string normalization;+ std::string temporal_stabilization;+ uint32_t cadence = 1;+ bool online = false;+ bool gpu_remote_output = false;+ FencePoint produced;+};+struct Counters {+ uint64_t source_pair_analysis_count = 0;+ uint64_t directional_dispatch_count = 0;+ uint64_t first_frame_self_analysis_count = 0;+ uint64_t sr_consume_count = 0;+ uint64_t fg_consume_count = 0;+ uint64_t motion_geometry_dispatch_count = 0;+ uint64_t depth_inference_count = 0;+ uint64_t depth_buffer_to_texture_count = 0;+ uint64_t gpu_copy_count = 0;+ uint64_t vpp_import_copy_count = 0;+ uint64_t full_frame_cpu_readback_bytes = 0;+ uint64_t full_frame_cpu_upload_bytes = 0;+ uint64_t statistics_readback_bytes = 0;+ bool fg_mask_tagged = false; // public XeFG has no responsive-mask tag+};+struct RecordContext {+ ID3D12Device* device = nullptr;+ ID3D12GraphicsCommandList* list = nullptr;+ ID3D12CommandQueue* queue = nullptr;+ LUID adapter_luid{};+ // The caller signals this fence AFTER submitting the recorded command list.+ FencePoint completion;+ // Optional read-only views of the core's existing converted source planes.+ // Valid only during record(); providers must not retain these pointers.+ // Their source IDs/color metadata are current/previous FrameLease metadata;+ // ownership stays with the frame slots and their registered consumer fences.+ const TextureView* current_rgba = nullptr;+ const TextureView* previous_rgba = nullptr;+};+struct ProviderConfig { Extent source; uint32_t slots = 4; bool bidirectional = true; };+class MotionProvider {+public:+ virtual ~MotionProvider() = default;+ virtual const char* backend_name() const noexcept = 0;+ virtual bool initialize(ID3D12Device*, const ProviderConfig&, std::string&) = 0;+ virtual bool record(const FrameLease* previous, const FrameLease& current,+ uint32_t slot, RecordContext&, MotionPacket&,+ Counters&, std::string&) = 0;+};++inline bool same_adapter(LUID a, LUID b) noexcept {+ return a.HighPart == b.HighPart && a.LowPart == b.LowPart;+}+inline bool matches(const FrameLease& frame, const MotionPacket& packet) noexcept {+ return frame.metadata.source_frame_id == packet.current_source_frame_id &&+ frame.metadata.previous_source_frame_id == packet.previous_source_frame_id;+}+// Apply x/y scales independently at the consumer adapter, once. Do not run a+// provider on SR output. Color and adapted packet retain current_source_frame_id.+inline bool geometry_scale(Extent source, Extent target, float& x, float& y) noexcept {+ if (!source.width || !source.height || !target.width || !target.height) return false;+ x = static_cast<float>(target.width) / source.width;+ y = static_cast<float>(target.height) / source.height;+ return true;+}+} // namespace xess_gpudiff --git a/third_party/gpu-dis/src/gpu/native_strict_dis_provider.cpp b/third_party/gpu-dis/src/gpu/native_strict_dis_provider.cppnew file mode 100644index 00000000..2e377234--- /dev/null+++ b/third_party/gpu-dis/src/gpu/native_strict_dis_provider.cpp@@ -0,0 +1,399 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++#ifndef NOMINMAX+#define NOMINMAX+#endif+#include "gpu_frame_contract.h"+#include "native_strict_dis_provider.h"+#include <algorithm>+#include <array>+#include <cmath>+#include <cstdio>+#include <fstream>+#include <stdexcept>+#include <utility>++namespace xess_gpu { namespace {+constexpr auto kRead = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;+constexpr auto kWrite = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;+void checked(HRESULT hr, const char* where) {+ if (FAILED(hr)) { char text[128]; std::snprintf(text,sizeof(text),"%s: HRESULT 0x%08lX",where,(unsigned long)hr); throw std::runtime_error(text); }+}+struct Texture {+ ComPtr<ID3D12Resource> resource;+ D3D12_RESOURCE_STATES state = kWrite;+ DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;+ uint32_t w=0,h=0;+ void create(ID3D12Device* device, uint32_t width, uint32_t height, DXGI_FORMAT fmt) {+ w=width; h=height; format=fmt;+ D3D12_HEAP_PROPERTIES heap{}; heap.Type=D3D12_HEAP_TYPE_DEFAULT;+ D3D12_RESOURCE_DESC d{}; d.Dimension=D3D12_RESOURCE_DIMENSION_TEXTURE2D;+ d.Width=w; d.Height=h; d.DepthOrArraySize=1; d.MipLevels=1; d.Format=fmt;+ d.SampleDesc.Count=1; d.Flags=D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;+ checked(device->CreateCommittedResource(&heap,D3D12_HEAP_FLAG_NONE,&d,state,nullptr,IID_PPV_ARGS(&resource)),"DIS texture");+ }+ void to(ID3D12GraphicsCommandList* list, D3D12_RESOURCE_STATES next) {+ if(state==next) return;+ D3D12_RESOURCE_BARRIER b{}; b.Type=D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;+ b.Transition.pResource=resource.Get(); b.Transition.Subresource=D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;+ b.Transition.StateBefore=state; b.Transition.StateAfter=next;+ list->ResourceBarrier(1,&b); state=next;+ }+};+struct Pipeline {+ ComPtr<ID3D12RootSignature> root;+ ComPtr<ID3D12PipelineState> state;+ uint32_t srvs=0,uavs=0,constants=0;+ void create(ID3D12Device* d,const std::string& file,uint32_t s,uint32_t u,uint32_t n) {+ srvs=s; uavs=u; constants=n;+ D3D12_DESCRIPTOR_RANGE ranges[2]{};+ ranges[0].RangeType=D3D12_DESCRIPTOR_RANGE_TYPE_SRV; ranges[0].NumDescriptors=s;+ ranges[1].RangeType=D3D12_DESCRIPTOR_RANGE_TYPE_UAV; ranges[1].NumDescriptors=u;+ D3D12_ROOT_PARAMETER params[3]{};+ for(uint32_t i=0;i<2;++i) { params[i].ParameterType=D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;+ params[i].DescriptorTable.NumDescriptorRanges=1; params[i].DescriptorTable.pDescriptorRanges=&ranges[i]; }+ params[2].ParameterType=D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;+ params[2].Constants.Num32BitValues=n;+ D3D12_ROOT_SIGNATURE_DESC desc{}; desc.NumParameters=3; desc.pParameters=params;+ ComPtr<ID3DBlob> blob,errors;+ checked(D3D12SerializeRootSignature(&desc,D3D_ROOT_SIGNATURE_VERSION_1,&blob,&errors),"DIS root serialize");+ checked(d->CreateRootSignature(0,blob->GetBufferPointer(),blob->GetBufferSize(),IID_PPV_ARGS(&root)),"DIS root");+ std::ifstream input(file,std::ios::binary|std::ios::ate);+ if(!input) throw std::runtime_error("Cannot open DIS shader: "+file);+ const auto length=input.tellg(); if(length<=0) throw std::runtime_error("Empty DIS shader: "+file);+ std::vector<char> bytes((size_t)length); input.seekg(0); input.read(bytes.data(),(std::streamsize)bytes.size());+ if(!input) throw std::runtime_error("Cannot read DIS shader: "+file);+ D3D12_COMPUTE_PIPELINE_STATE_DESC ps{}; ps.pRootSignature=root.Get(); ps.CS={bytes.data(),bytes.size()};+ checked(d->CreateComputePipelineState(&ps,IID_PPV_ARGS(&state)),"DIS pipeline");+ }+};+struct Binding {+ ComPtr<ID3D12DescriptorHeap> heap, staging;+ uint32_t increment=0;+ D3D12_CPU_DESCRIPTOR_HANDLE cpu(uint32_t offset) const {+ auto h=heap->GetCPUDescriptorHandleForHeapStart(); h.ptr+=SIZE_T(offset)*increment; return h;+ }+ D3D12_GPU_DESCRIPTOR_HANDLE gpu(uint32_t offset) const {+ auto h=heap->GetGPUDescriptorHandleForHeapStart(); h.ptr+=UINT64(offset)*increment; return h;+ }+ void initialize(ID3D12Device* d, const Pipeline& p,+ std::initializer_list<Texture*> inputs,std::initializer_list<Texture*> outputs) {+ D3D12_DESCRIPTOR_HEAP_DESC hd{}; hd.Type=D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;+ hd.NumDescriptors=p.srvs+p.uavs; hd.Flags=D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;+ checked(d->CreateDescriptorHeap(&hd,IID_PPV_ARGS(&heap)),"DIS descriptors");+ hd.Flags=D3D12_DESCRIPTOR_HEAP_FLAG_NONE;+ checked(d->CreateDescriptorHeap(&hd,IID_PPV_ARGS(&staging)),"DIS staging descriptors");+ increment=d->GetDescriptorHandleIncrementSize(hd.Type);+ uint32_t i=0;+ for(auto* t:inputs) { set_input(d,i,t?t->resource.Get():nullptr,t?t->format:DXGI_FORMAT_R32_FLOAT); ++i; }+ i=p.srvs;+ for(auto* t:outputs) {+ D3D12_UNORDERED_ACCESS_VIEW_DESC v{}; v.ViewDimension=D3D12_UAV_DIMENSION_TEXTURE2D; v.Format=t->format;+ d->CreateUnorderedAccessView(t->resource.Get(),nullptr,&v,cpu(i++));+ }+ }+ void set_input(ID3D12Device* d,uint32_t index,ID3D12Resource* resource,DXGI_FORMAT format,uint32_t plane=0) {+ D3D12_SHADER_RESOURCE_VIEW_DESC v{}; v.ViewDimension=D3D12_SRV_DIMENSION_TEXTURE2D; v.Format=format;+ v.Shader4ComponentMapping=D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; v.Texture2D.MipLevels=1;+ v.Texture2D.PlaneSlice=plane;+ auto target=staging->GetCPUDescriptorHandleForHeapStart();target.ptr+=SIZE_T(index)*increment;+ d->CreateShaderResourceView(resource,&v,target);+ d->CopyDescriptorsSimple(1,cpu(index),target,D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);+ }+ void bind(ID3D12GraphicsCommandList* list,const Pipeline& p,const void* constants) const {+ ID3D12DescriptorHeap* heaps[]={heap.Get()}; list->SetDescriptorHeaps(1,heaps);+ list->SetComputeRootSignature(p.root.Get()); list->SetPipelineState(p.state.Get());+ list->SetComputeRootDescriptorTable(0,gpu(0)); list->SetComputeRootDescriptorTable(1,gpu(p.srvs));+ list->SetComputeRoot32BitConstants(2,p.constants,constants,0);+ }+};+struct ImageLevel {+ Texture image,gradient;+ std::array<Texture,5> tensors,aux;+ Binding area,grad,hor,ver;+};+struct WorkLevel {+ Texture sparse,dense,initial,work,du,dv;+ std::array<Texture,8> deriv;+ std::array<Texture,6> coeff;+ std::array<Binding,2> patch,dens,deriv1;+ Binding deriv2,system,sor0,sor1,update,zero,up;+};+struct Slot {+ std::array<std::vector<ImageLevel>,2> image;+ std::vector<WorkLevel> work;+ std::array<Texture,2> output;+ std::array<Binding,2> input,rgba_input,final;+ FencePoint completion;+ Texture unused_trace;+};+class StrictDis final : public MotionProvider {+ std::string shader_directory_;+ ComPtr<ID3D12Device> device_;+ ProviderConfig config_;+ StrictDisPreset preset_;+ StrictDisInput input_profile_;+ uint32_t stride_=4,gd_inner_=8;+ uint32_t finest_=2,coarsest_=0;+ Pipeline luma_,rgba_gray_,area_,gradient_,hor_,ver_,patch_,dense_,up_,v1_,v2_,system_,sor_,update_,zero_,final_;+ std::vector<Slot> slots_;+ uint64_t shader_dispatches_=0;+ void dispatch(ID3D12GraphicsCommandList* list,const Pipeline& p,const Binding& b,+ const void* constants,uint32_t x,uint32_t y=1) {+ b.bind(list,p,constants); list->Dispatch(x,y,1); ++shader_dispatches_;+ }+ void allocate(Slot& s);+ void record_image(Slot& s,uint32_t index,const FrameLease& frame,ID3D12GraphicsCommandList* list);+ void record_direction(Slot& s,uint32_t direction,ID3D12GraphicsCommandList* list);+public:+ explicit StrictDis(std::string directory,StrictDisPreset preset,StrictDisInput input):shader_directory_(std::move(directory)),preset_(preset),input_profile_(input) {}+ const char* backend_name() const noexcept override { return preset_==StrictDisPreset::Medium?"gpu-dis-cpu-medium-strict-v1":"gpu-dis-cpu-fast-strict-v1"; }+ uint64_t shader_dispatches() const noexcept { return shader_dispatches_; }+ bool initialize(ID3D12Device* device,const ProviderConfig& config,std::string& error) override;+ bool record(const FrameLease* previous,const FrameLease& current,uint32_t slot,+ RecordContext& context,MotionPacket& packet,Counters& counters,std::string& error) override;+};++bool StrictDis::initialize(ID3D12Device* device,const ProviderConfig& config,std::string& error) {+ try {+ if(!device || config.source.width<32 || config.source.height<32 || !config.slots || config.slots>8)+ throw std::runtime_error("Strict DIS requires source >=32x32 and 1..8 slots");+ D3D12_FEATURE_DATA_D3D12_OPTIONS options{};+ checked(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS,&options,sizeof(options)),"DIS double feature");+ if(!options.DoublePrecisionFloatShaderOps) throw std::runtime_error("Strict DIS CPU rounding requires GPU double shader operations");+ device_=device; config_=config;+ finest_=preset_==StrictDisPreset::Medium?1:2;+ stride_=preset_==StrictDisPreset::Medium?3:4;+ gd_inner_=preset_==StrictDisPreset::Medium?12:8; // CPU floor(GD / 2): 25 -> 12 per sweep.+ auto w=config.source.width,h=config.source.height;+ int level=std::min((int)(std::log(std::max(w,h)/32.0)/std::log(2.0)+.5),+ (int)(std::log(std::min(w,h)/8.0)/std::log(2.0)));+ if(level<(int)finest_) { level=std::max(0,(int)std::floor(std::log2(2.0f*w/40.0f))); finest_=(uint32_t)std::max(level-2,0); }+ coarsest_=(uint32_t)level;+ auto pipe=[&](Pipeline& p,const char* name,uint32_t s,uint32_t u,uint32_t n) {+ p.create(device,shader_directory_+"/"+name+".dxil",s,u,n);+ };+ if(input_profile_==StrictDisInput::Ffmpeg71RgbGrayLimited) {+ pipe(luma_,"dis_native_gray",2,1,6);+ pipe(rgba_gray_,"dis_native_rgba_gray",1,1,4);+ }+ else pipe(luma_,"dis_native_luma",1,1,4);+ pipe(area_,"dis_perfect_area",1,1,4);+ pipe(gradient_,"dis_d2_gradient",1,1,4);+ pipe(hor_,stride_==3?"dis_d3_structure_hor_stride3":"dis_d3_structure_hor",1,5,4);+ pipe(ver_,stride_==3?"dis_d3_structure_ver_stride3":"dis_d3_structure_ver",5,5,4);+ pipe(patch_,"dis_perfect_patch_parallel",9,2,14); pipe(dense_,"dis_perfect_densify_exact",3,1,6);+ pipe(up_,"dis_perfect_upsample_ipp",1,1,4); pipe(v1_,"dis_perfect_vr_deriv1_cpu",3,5,2);+ pipe(v2_,"dis_perfect_vr_deriv2",2,3,2); pipe(system_,"dis_perfect_vr_system_exact",11,6,6);+ pipe(sor_,"dis_perfect_vr_sor_exact",7,1,4); pipe(update_,"dis_perfect_vr_update",2,1,2);+ pipe(zero_,"dis_perfect_vr_zero",1,1,2); pipe(final_,"dis_perfect_final",1,1,5);+ slots_.clear(); slots_.resize(config.slots);+ for(auto& s:slots_) allocate(s);+ return true;+ } catch(const std::exception& ex) { error=ex.what(); return false; }+}++void StrictDis::allocate(Slot& s) {+ auto tex=[&](Texture& t,uint32_t w,uint32_t h,DXGI_FORMAT format) { t.create(device_.Get(),w,h,format); };+ for(auto& image:s.image) {+ image.resize(coarsest_+1);+ for(uint32_t l=0;l<=coarsest_;++l) {+ auto& p=image[l]; uint32_t w=config_.source.width>>l,h=config_.source.height>>l;+ tex(p.image,w,h,DXGI_FORMAT_R32_FLOAT);+ if(l<finest_) continue;+ tex(p.gradient,w,h,DXGI_FORMAT_R32G32_SINT);+ for(auto& t:p.tensors) tex(t,1+(w-8)/stride_,1+(h-8)/stride_,DXGI_FORMAT_R32_FLOAT);+ for(auto& t:p.aux) tex(t,w/stride_,h,DXGI_FORMAT_R32_FLOAT);+ }+ }+ s.work.resize(coarsest_+1);+ for(uint32_t l=finest_;l<=coarsest_;++l) {+ auto& p=s.work[l]; uint32_t w=config_.source.width>>l,h=config_.source.height>>l;+ tex(p.sparse,1+(w-8)/stride_,1+(h-8)/stride_,DXGI_FORMAT_R32G32_FLOAT);+ for(auto* t:{&p.dense,&p.initial,&p.work,&p.du,&p.dv}) tex(*t,w,h,DXGI_FORMAT_R32G32_FLOAT);+ for(auto& t:p.deriv) tex(t,w,h,DXGI_FORMAT_R32_FLOAT);+ for(auto& t:p.coeff) tex(t,w,h,DXGI_FORMAT_R32_FLOAT);+ }+ for(auto& t:s.output) tex(t,config_.source.width,config_.source.height,DXGI_FORMAT_R32G32_FLOAT);+ tex(s.unused_trace,1,1,DXGI_FORMAT_R32G32_FLOAT);+ auto bind=[&](Binding& b,const Pipeline& p,std::initializer_list<Texture*> a,std::initializer_list<Texture*> o) {+ b.initialize(device_.Get(),p,a,o);+ };+ for(uint32_t d=0;d<2;++d) {+ if(input_profile_==StrictDisInput::Ffmpeg71RgbGrayLimited) {+ bind(s.input[d],luma_,{nullptr,nullptr},{&s.image[d][0].image});+ bind(s.rgba_input[d],rgba_gray_,{nullptr},{&s.image[d][0].image});+ }+ else bind(s.input[d],luma_,{nullptr},{&s.image[d][0].image});+ bind(s.final[d],final_,{&s.work[finest_].work},{&s.output[d]});+ for(uint32_t l=finest_;l<=coarsest_;++l) {+ auto& i=s.image[d][l]; auto& j=s.image[1-d][l]; auto& w=s.work[l];+ auto& t=i.tensors; auto& a=i.aux;+ if(l) bind(i.area,area_,{&s.image[d][l==finest_?0:l-1].image},{&i.image});+ bind(i.grad,gradient_,{&i.image},{&i.gradient});+ bind(i.hor,hor_,{&i.gradient},{&a[0],&a[1],&a[2],&a[3],&a[4]});+ bind(i.ver,ver_,{&a[0],&a[1],&a[2],&a[3],&a[4]},{&t[0],&t[1],&t[2],&t[3],&t[4]});+ // u1 trace slot is a valid unused view, never written by strict patch.+ bind(w.patch[d],patch_,{&i.image,&j.image,&i.gradient,&t[0],&t[1],&t[2],&t[3],&t[4],&w.initial},{&w.sparse,&s.unused_trace});+ bind(w.dens[d],dense_,{&i.image,&j.image,&w.sparse},{&w.dense});+ bind(w.deriv1[d],v1_,{&i.image,&j.image,&w.work},{&w.deriv[0],&w.deriv[1],&w.deriv[2],&w.deriv[3],&w.deriv[4]});+ }+ }+ for(uint32_t l=finest_;l<=coarsest_;++l) {+ auto& w=s.work[l]; auto& d=w.deriv; auto& c=w.coeff;+ bind(w.deriv2,v2_,{&d[0],&d[1]},{&d[5],&d[6],&d[7]});+ bind(w.system,system_,{&d[0],&d[1],&d[2],&d[5],&d[6],&d[7],&d[3],&d[4],&w.du,&w.dense,&w.work},+ {&c[0],&c[1],&c[2],&c[3],&c[4],&c[5]});+ bind(w.sor0,sor_,{&c[0],&c[1],&c[2],&c[3],&c[4],&c[5],&w.du},{&w.dv});+ bind(w.sor1,sor_,{&c[0],&c[1],&c[2],&c[3],&c[4],&c[5],&w.dv},{&w.du});+ bind(w.update,update_,{&w.dense,&w.du},{&w.work});+ bind(w.zero,zero_,{nullptr},{&w.du});+ if(l>finest_) bind(w.up,up_,{&w.work},{&s.work[l-1].initial});+ }+}++void StrictDis::record_image(Slot& s,uint32_t index,const FrameLease& frame,ID3D12GraphicsCommandList* list) {+ auto& levels=s.image[index];+ const bool rgba=frame.color.resource->GetDesc().Format==DXGI_FORMAT_R8G8B8A8_UNORM;+ auto& input=rgba?s.rgba_input[index]:s.input[index];+ input.set_input(device_.Get(),0,frame.color.resource.Get(),rgba?DXGI_FORMAT_R8G8B8A8_UNORM:DXGI_FORMAT_R8_UNORM);+ if(!rgba && input_profile_==StrictDisInput::Ffmpeg71RgbGrayLimited)+ s.input[index].set_input(device_.Get(),1,frame.color.resource.Get(),DXGI_FORMAT_R8G8_UNORM,1);+ Texture borrowed; borrowed.resource=frame.color.resource; borrowed.state=frame.color.state;+ borrowed.to(list,kRead);+ levels[0].image.to(list,kWrite);+ const uint32_t base[6]={config_.source.width,config_.source.height,frame.color.valid.x,frame.color.valid.y,frame.metadata.matrix==Matrix::Bt709?1u:0u,0};+ dispatch(list,rgba?rgba_gray_:luma_,input,base,(base[0]+7)/8,(base[1]+7)/8);+ levels[0].image.to(list,kRead); borrowed.to(list,frame.color.state);+ for(uint32_t l=finest_;l<=coarsest_;++l) {+ auto& i=levels[l]; auto w=i.image.w,h=i.image.h;+ if(l) {+ const auto& from=levels[l==finest_?0:l-1].image;+ const uint32_t dims[4]={from.w,from.h,w,h};+ i.image.to(list,kWrite); dispatch(list,area_,i.area,dims,(w+7)/8,(h+7)/8); i.image.to(list,kRead);+ }+ const uint32_t dims[4]={w,h,w,h}, shape[4]={w,h,i.tensors[0].w,i.tensors[0].h};+ i.gradient.to(list,kWrite); dispatch(list,gradient_,i.grad,dims,(w+7)/8,(h+7)/8); i.gradient.to(list,kRead);+ for(auto& t:i.aux) t.to(list,kWrite);+ dispatch(list,hor_,i.hor,shape,(h+63)/64);+ for(auto& t:i.aux) t.to(list,kRead);+ for(auto& t:i.tensors) t.to(list,kWrite);+ dispatch(list,ver_,i.ver,shape,(shape[2]+63)/64);+ for(auto& t:i.tensors) t.to(list,kRead);+ }+}++void StrictDis::record_direction(Slot& s,uint32_t direction,ID3D12GraphicsCommandList* list) {+ for(int level=(int)coarsest_;level>=(int)finest_;--level) {+ const auto l=(uint32_t)level; auto& w=s.work[l];+ auto width=w.dense.w,height=w.dense.h,sw=w.sparse.w,sh=w.sparse.h;+ const uint32_t wh[2]={width,height};+ w.sparse.to(list,kWrite); w.initial.to(list,kRead);+ const uint32_t stripe_h=(sh+7)/8,diagonals=sw+stripe_h-1;+ for(uint32_t d=0;d<2;++d) for(uint32_t diagonal=0;diagonal<diagonals;++diagonal) {+ uint32_t first=diagonal+1>sw?diagonal+1-sw:0,last=std::min(diagonal,stripe_h-1);+ uint32_t count=last>=first?last-first+1:0;+ const uint32_t args[14]={width,height,sw,sh,8,stride_,gd_inner_,d,diagonal,l<coarsest_?1u:0u,0,0,0,0};+ dispatch(list,patch_,w.patch[direction],args,count*8);+ D3D12_RESOURCE_BARRIER b{}; b.Type=D3D12_RESOURCE_BARRIER_TYPE_UAV; b.UAV.pResource=w.sparse.resource.Get();+ list->ResourceBarrier(1,&b);+ }+ w.sparse.to(list,kRead); w.dense.to(list,kWrite);+ const uint32_t den[6]={width,height,sw,sh,8,stride_};+ dispatch(list,dense_,w.dens[direction],den,(width+7)/8,(height+7)/8); w.dense.to(list,kRead);+ w.du.to(list,kWrite); dispatch(list,zero_,w.zero,wh,(width+7)/8,(height+7)/8); w.du.to(list,kRead);+ w.work.to(list,kWrite); dispatch(list,update_,w.update,wh,(width+7)/8,(height+7)/8); w.work.to(list,kRead);+ for(auto& t:w.deriv) t.to(list,kWrite);+ dispatch(list,v1_,w.deriv1[direction],wh,(width+7)/8,(height+7)/8);+ for(uint32_t k=0;k<5;++k) w.deriv[k].to(list,kRead);+ dispatch(list,v2_,w.deriv2,wh,(width+7)/8,(height+7)/8);+ for(uint32_t k=5;k<8;++k) w.deriv[k].to(list,kRead);+ struct VR { uint32_t w,h; float a,d,g,e; } vr{width,height,20,5,10,.01f};+ for(uint32_t fixed=0;fixed<5;++fixed) {+ for(auto& t:w.coeff) t.to(list,kWrite);+ dispatch(list,system_,w.system,&vr,(width+7)/8,(height+7)/8);+ for(auto& t:w.coeff) t.to(list,kRead);+ for(uint32_t sor=0;sor<5;++sor) for(uint32_t parity=0;parity<2;++parity) {+ auto& output=parity==0?w.dv:w.du; output.to(list,kWrite);+ const uint32_t args[4]={width,height,0x3FCCCCCDu,parity};+ dispatch(list,sor_,parity==0?w.sor0:w.sor1,args,(width+7)/8,(height+7)/8);+ output.to(list,kRead);+ }+ w.work.to(list,kWrite); dispatch(list,update_,w.update,wh,(width+7)/8,(height+7)/8); w.work.to(list,kRead);+ }+ if(l>finest_) {+ auto& next=s.work[l-1].initial; next.to(list,kWrite);+ const uint32_t args[4]={width,height,next.w,next.h};+ dispatch(list,up_,w.up,args,(next.w+7)/8,(next.h+7)/8); next.to(list,kRead);+ }+ }+ auto& output=s.output[direction]; output.to(list,kWrite);+ const auto& work=s.work[finest_].work;+ const uint32_t final[5]={work.w,work.h,output.w,output.h,1u<<finest_};+ dispatch(list,final_,s.final[direction],final,(output.w+7)/8,(output.h+7)/8); output.to(list,kRead);+}++bool StrictDis::record(const FrameLease* previous,const FrameLease& current,uint32_t slot,+ RecordContext& context,MotionPacket& packet,Counters& counters,std::string& error) {+ try {+ if(!context.list || context.device!=device_.Get() || slot>=slots_.size())+ throw std::runtime_error("Strict DIS record context or slot mismatch");+ if(!context.completion.fence || !context.completion.value)+ throw std::runtime_error("Strict DIS requires caller completion fence/value");+ auto& s=slots_[slot];+ if(!s.completion.complete()) throw std::runtime_error("Strict DIS output slot still in flight; host must retire it");+ auto validate=[&](const FrameLease& f) {+ if(!f.color.resource || !same_adapter(context.adapter_luid,f.metadata.adapter_luid))+ throw std::runtime_error("Strict DIS source texture/adapter mismatch");+ auto desc=f.color.resource->GetDesc(); auto crop=f.color.valid;+ if(desc.Dimension!=D3D12_RESOURCE_DIMENSION_TEXTURE2D || desc.DepthOrArraySize!=1 || desc.SampleDesc.Count!=1 ||+ (desc.Format!=DXGI_FORMAT_NV12 && desc.Format!=DXGI_FORMAT_R8_UNORM &&+ !(input_profile_==StrictDisInput::Ffmpeg71RgbGrayLimited && desc.Format==DXGI_FORMAT_R8G8B8A8_UNORM)))+ throw std::runtime_error("Strict DIS input requires NV12, R8, or limited RGB-gray RGBA8");+ if(crop.width!=config_.source.width || crop.height!=config_.source.height ||+ uint64_t(crop.x)+crop.width>desc.Width || uint64_t(crop.y)+crop.height>desc.Height)+ throw std::runtime_error("Strict DIS source crop/geometry mismatch");+ if(input_profile_==StrictDisInput::Ffmpeg71RgbGrayLimited &&+ ((desc.Format!=DXGI_FORMAT_NV12 && desc.Format!=DXGI_FORMAT_R8G8B8A8_UNORM) || f.metadata.range!=Range::Limited ||+ (f.metadata.matrix!=Matrix::Bt601 && f.metadata.matrix!=Matrix::Bt709)))+ throw std::runtime_error("Strict DIS FFmpeg RGB-gray requires limited BT.601/709 NV12 or compatibility RGBA8");+ ComPtr<ID3D12Device> owner; checked(f.color.resource->GetDevice(IID_PPV_ARGS(&owner)),"DIS input device");+ if(owner.Get()!=device_.Get()) throw std::runtime_error("Strict DIS source belongs to another D3D12 device");+ };+ validate(current); if(previous) validate(*previous);+ if(previous && current.metadata.previous_source_frame_id!=previous->metadata.source_frame_id)+ throw std::runtime_error("Strict DIS adjacent source-frame ID mismatch");+ // All validation precedes recording; the host supplies producer GPU waits.+ record_image(s,0,current,context.list);+ record_image(s,1,previous?*previous:current,context.list);+ record_direction(s,0,context.list);+ if(previous && config_.bidirectional) record_direction(s,1,context.list);+ packet={}; packet.current_source_frame_id=current.metadata.source_frame_id;+ packet.previous_source_frame_id=current.metadata.previous_source_frame_id;+ packet.current_metadata=current.metadata; packet.first_frame_self=previous==nullptr;+ auto view=[&](Texture& t) { TextureView v; v.resource=t.resource; v.format=t.format;+ v.allocation={t.w,t.h}; v.valid={0,0,t.w,t.h}; v.state=kRead; return v; };+ packet.current_to_previous=view(s.output[0]); packet.has_reverse=config_.bidirectional;+ if(config_.bidirectional) packet.previous_to_current=view(s.output[previous?1:0]);+ packet.confidence_definition=ConfidenceDefinition::Unavailable;+ packet.confidence_semantics="DIS has no native confidence; host derives photometric/roundtrip reliability from raw source flows";+ packet.produced=context.completion; s.completion=context.completion;+ if(previous) { ++counters.source_pair_analysis_count; counters.directional_dispatch_count+=config_.bidirectional?2:1; }+ else { ++counters.first_frame_self_analysis_count; ++counters.directional_dispatch_count; }+ return true;+ } catch(const std::exception& ex) { error=ex.what(); return false; }+}+} // namespace+std::unique_ptr<MotionProvider> make_strict_dis_provider(const std::string& shader_directory,StrictDisPreset preset,StrictDisInput input) {+ return std::make_unique<StrictDis>(shader_directory,preset,input);+}+uint64_t strict_dis_shader_dispatches(const MotionProvider& provider) noexcept {+ auto* strict=dynamic_cast<const StrictDis*>(&provider);+ return strict?strict->shader_dispatches():0;+}+} // namespace xess_gpudiff --git a/third_party/gpu-dis/src/gpu/native_strict_dis_provider.h b/third_party/gpu-dis/src/gpu/native_strict_dis_provider.hnew file mode 100644index 00000000..9571c3ff--- /dev/null+++ b/third_party/gpu-dis/src/gpu/native_strict_dis_provider.h@@ -0,0 +1,24 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++#pragma once+#include <memory>+#include <string>+#include <cstdint>++namespace xess_gpu {+class MotionProvider;+enum class StrictDisPreset { Fast, Medium };+enum class StrictDisInput { RawLuma8, Ffmpeg71RgbGrayLimited };+// Frozen CPU FAST/MEDIUM semantics, no caller-provided temporal initial flow.+// The caller owns producer waits, command submission, completion signaling,+// and source pool leases. NV12 Y and R8_UNORM crop views are supported.+std::unique_ptr<MotionProvider> make_strict_dis_provider(+ const std::string& shader_directory, StrictDisPreset preset=StrictDisPreset::Fast,+ StrictDisInput input=StrictDisInput::RawLuma8);+uint64_t strict_dis_shader_dispatches(const MotionProvider& provider) noexcept;+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli b/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlslinew file mode 100644index 00000000..b1eb3963--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_cpu_rounding.hlsli@@ -0,0 +1,24 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// Diagnostic CPU round-to-nearest emulation. FP64 residual corrections preserve+// the CPU FP32 operator contract; they are not lower-precision approximations.+// Product performance and hardware support must be measured before promotion.+float cpu_divide(float a, float b)+{+ precise float estimate = a / b;+ precise double residual = (double)a - (double)estimate * (double)b;+ precise double corrected = (double)estimate + residual / (double)b;+ return (float)corrected;+}+float cpu_sqrt(float a)+{+ precise float estimate = sqrt(a);+ precise double residual = (double)a - (double)estimate * (double)estimate;+ precise double corrected = (double)estimate + residual / (2.0 * (double)estimate);+ return (float)corrected;+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_d2_gradient.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_d2_gradient.hlslnew file mode 100644index 00000000..dfdfd9db--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_d2_gradient.hlsl@@ -0,0 +1,42 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// Gate D2 diagnostic only. This is OpenCV spatialGradient's 3x3 Sobel+// derivative, with the documented zero border and signed 32-bit output. The+// production port may pack to R16G16_SINT only after a precision gate.+Texture2D<float> Source : register(t0);+RWTexture2D<int2> Destination : register(u0);+cbuffer Params : register(b0) { uint srcWidth; uint srcHeight; uint dstWidth; uint dstHeight; };++int reflect101(int p, int extent)+{+ if (extent <= 1) return 0;+ if (p < 0) return -p;+ if (p >= extent) return 2 * extent - p - 2;+ return p;+}++float sample_reflect101(int x, int y)+{+ return Source.Load(int3(reflect101(x, int(srcWidth)), reflect101(y, int(srcHeight)), 0));+}++[numthreads(8, 8, 1)]+void main(uint3 id : SV_DispatchThreadID)+{+ if (id.x >= dstWidth || id.y >= dstHeight) return;+ int x = int(id.x), y = int(id.y);+ float gx = -sample_reflect101(x - 1, y - 1) - 2.0 * sample_reflect101(x - 1, y) - sample_reflect101(x - 1, y + 1)+ + sample_reflect101(x + 1, y - 1) + 2.0 * sample_reflect101(x + 1, y) + sample_reflect101(x + 1, y + 1);+ float gy = -sample_reflect101(x - 1, y - 1) - 2.0 * sample_reflect101(x, y - 1) - sample_reflect101(x + 1, y - 1)+ + sample_reflect101(x - 1, y + 1) + 2.0 * sample_reflect101(x, y + 1) + sample_reflect101(x + 1, y + 1);+ // spatialGradient uses a reflected border in the perpendicular axis,+ // while the derivative at the edge along its own axis is zero.+ if (x == 0 || x + 1 >= srcWidth) gx = 0.0;+ if (y == 0 || y + 1 >= srcHeight) gy = 0.0;+ Destination[id.xy] = int2((int)round(gx), (int)round(gy));+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_hor.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_hor.hlslnew file mode 100644index 00000000..27f62278--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_hor.hlsl@@ -0,0 +1,68 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// Z2 exact OpenCV precomputeStructureTensor, horizontal pass.+// One thread per image row: running sums over [j-7..j] windows with exact+// integer products/deltas (short*short in int32) added to float accumulators+// sequentially, stored at sparse columns every patch_stride in cv2 order.+Texture2D<int2> Gradient : register(t0);+#ifndef DIS_TENSOR_STRIDE+#define DIS_TENSOR_STRIDE 4+#endif+RWTexture2D<float> XX : register(u0);+RWTexture2D<float> YY : register(u1);+RWTexture2D<float> XY : register(u2);+RWTexture2D<float> XS : register(u3);+RWTexture2D<float> YS : register(u4);+cbuffer Params : register(b0) { uint width; uint height; uint ws; uint hs; };++[numthreads(64, 1, 1)]+void main(uint3 id : SV_DispatchThreadID)+{+ uint i = id.x;+ if (i >= height) return;+ int outputOffset = 0;+ float sxx = 0.0, syy = 0.0, sxy = 0.0, sx = 0.0, sy = 0.0;+ uint js = 1;+ // initial window [0, 7]: exact int products converted to float, sequential+ for (uint j = 0; j < 8; ++j)+ {+ int2 g = Gradient.Load(int3(j, i, 0));+ int x = g.x, y = g.y;+ sxx += (float)(x * x);+ syy += (float)(y * y);+ sxy += (float)(x * y);+ sx += (float)x;+ sy += (float)y;+ }+ XX[uint2(0, i)] = sxx;+ YY[uint2(0, i)] = syy;+ XY[uint2(0, i)] = sxy;+ XS[uint2(0, i)] = sx;+ YS[uint2(0, i)] = sy;+ // sliding windows with int-exact deltas, cv2 store condition (j-7)%4==0+ for (uint j = 8; j < width; ++j)+ {+ int2 g = Gradient.Load(int3(j, i, 0));+ int2 gp = Gradient.Load(int3(j - 8, i, 0));+ int x = g.x, y = g.y, xp = gp.x, yp = gp.y;+ sxx += (float)(x * x - xp * xp);+ syy += (float)(y * y - yp * yp);+ sxy += (float)(x * y - xp * yp);+ sx += (float)(x - xp);+ sy += (float)(y - yp);+ if ((j - 7) % DIS_TENSOR_STRIDE == 0)+ {+ XX[uint2(js, i)] = sxx;+ YY[uint2(js, i)] = syy;+ XY[uint2(js, i)] = sxy;+ XS[uint2(js, i)] = sx;+ YS[uint2(js, i)] = sy;+ js++;+ }+ }+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_ver.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_ver.hlslnew file mode 100644index 00000000..7fa23b62--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_d3_structure_ver.hlsl@@ -0,0 +1,63 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// Z2 exact OpenCV precomputeStructureTensor, vertical pass.+// One thread per sparse column: running sums over aux rows with float+// deltas, stored at every patch_stride in cv2 order.+Texture2D<float> XX : register(t0);+#ifndef DIS_TENSOR_STRIDE+#define DIS_TENSOR_STRIDE 4+#endif+Texture2D<float> YY : register(t1);+Texture2D<float> XY : register(t2);+Texture2D<float> XS : register(t3);+Texture2D<float> YS : register(t4);+RWTexture2D<float> OutXX : register(u0);+RWTexture2D<float> OutYY : register(u1);+RWTexture2D<float> OutXY : register(u2);+RWTexture2D<float> OutXS : register(u3);+RWTexture2D<float> OutYS : register(u4);+cbuffer Params : register(b0) { uint width; uint height; uint ws; uint hs; };++[numthreads(64, 1, 1)]+void main(uint3 id : SV_DispatchThreadID)+{+ uint j = id.x;+ if (j >= ws) return;+ float sxx = 0.0, syy = 0.0, sxy = 0.0, sx = 0.0, sy = 0.0;+ for (uint i = 0; i < 8; ++i)+ {+ sxx += XX.Load(int3(j, i, 0));+ syy += YY.Load(int3(j, i, 0));+ sxy += XY.Load(int3(j, i, 0));+ sx += XS.Load(int3(j, i, 0));+ sy += YS.Load(int3(j, i, 0));+ }+ OutXX[uint2(j, 0)] = sxx;+ OutYY[uint2(j, 0)] = syy;+ OutXY[uint2(j, 0)] = sxy;+ OutXS[uint2(j, 0)] = sx;+ OutYS[uint2(j, 0)] = sy;+ uint is = 1;+ for (uint i = 8; i < height; ++i)+ {+ sxx += (XX.Load(int3(j, i, 0)) - XX.Load(int3(j, i - 8, 0)));+ syy += (YY.Load(int3(j, i, 0)) - YY.Load(int3(j, i - 8, 0)));+ sxy += (XY.Load(int3(j, i, 0)) - XY.Load(int3(j, i - 8, 0)));+ sx += (XS.Load(int3(j, i, 0)) - XS.Load(int3(j, i - 8, 0)));+ sy += (YS.Load(int3(j, i, 0)) - YS.Load(int3(j, i - 8, 0)));+ if ((i - 7) % DIS_TENSOR_STRIDE == 0)+ {+ OutXX[uint2(j, is)] = sxx;+ OutYY[uint2(j, is)] = syy;+ OutXY[uint2(j, is)] = sxy;+ OutXS[uint2(j, is)] = sx;+ OutYS[uint2(j, is)] = sy;+ is++;+ }+ }+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_native_gray.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_native_gray.hlslnew file mode 100644index 00000000..df4ee945--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_native_gray.hlsl@@ -0,0 +1,29 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// Motion-input adapter, not a decoder. Reuses A's surface_nv12_color.hlsl+// FFmpeg 7.1 SSSE3 integer organization, followed by OpenCV RGB2GRAY.+// Only 8-bit limited BT.601/709 is accepted by the host. No full-range guess.+Texture2D<float> Luma : register(t0);+Texture2D<float2> Chroma : register(t1);+RWTexture2D<float> Gray : register(u0);+cbuffer Params : register(b0) {+ uint width; uint height; uint cropX; uint cropY; uint matrix709; uint reserved;+};+[numthreads(8,8,1)]+void main(uint3 id : SV_DispatchThreadID) {+ if(id.x>=width || id.y>=height) return;+ uint2 p=id.xy+uint2(cropX,cropY);+ int y=(int)(Luma.Load(int3(p,0))*255.0+0.5);+ int2 uv=(int2)(Chroma.Load(int3(p>>1,0))*255.0+0.5);+ int yc=(((y<<3)-128)*9539)>>16;+ int u=(uv.x<<3)-1024,v=(uv.y<<3)-1024;+ uint r=(uint)clamp(yc+((v*(matrix709?14686:13075))>>16),0,255);+ uint g=(uint)clamp(yc+((u*(matrix709?-1747:-3209))>>16)+((v*(matrix709?-4366:-6660))>>16),0,255);+ uint b=(uint)clamp(yc+((u*(matrix709?17305:16525))>>16),0,255);+ Gray[id.xy]=(float)((9798u*r+19235u*g+3735u*b+16384u)>>15);+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_native_luma.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_native_luma.hlslnew file mode 100644index 00000000..c7956f8c--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_native_luma.hlsl@@ -0,0 +1,16 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// Preserve original 8-bit Y bytes; do not range-expand limited Y or convert RGB.+Texture2D<float> Source : register(t0);+RWTexture2D<float> Destination : register(u0);+cbuffer Params : register(b0) { uint width; uint height; uint cropX; uint cropY; };+[numthreads(8,8,1)]+void main(uint3 id : SV_DispatchThreadID) {+ if (id.x >= width || id.y >= height) return;+ Destination[id.xy] = floor(Source.Load(int3(id.xy + uint2(cropX,cropY),0))*255.0+0.5);+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_native_rgba_gray.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_native_rgba_gray.hlslnew file mode 100644index 00000000..d431f185--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_native_rgba_gray.hlsl@@ -0,0 +1,20 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// Compatibility ingress: D3D11 already produced exact FFmpeg 7.1 RGB bytes.+// Match dis_native_gray's OpenCV integer RGB2GRAY, not floating video luma.+Texture2D<float4> Color : register(t0);+RWTexture2D<float> Gray : register(u0);+cbuffer Params : register(b0) {+ uint width; uint height; uint cropX; uint cropY;+};+[numthreads(8,8,1)]+void main(uint3 id : SV_DispatchThreadID) {+ if(id.x>=width || id.y>=height) return;+ uint3 rgb=(uint3)(Color.Load(int3(id.xy+uint2(cropX,cropY),0)).rgb*255.0+0.5);+ Gray[id.xy]=(float)((9798u*rgb.r+19235u*rgb.g+3735u*rgb.b+16384u)>>15);+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_perfect_area.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_area.hlslnew file mode 100644index 00000000..8245e510--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_area.hlsl@@ -0,0 +1,145 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// OpenCV INTER_AREA-compatible downsample for the CV_8U DIS pyramid, exact+// semantics (Z2):+//+// - Integer-ratio paths (srcW % dstW == 0 and srcH % dstH == 0) accumulate+// the block sum in 32-bit integer and apply the empirically verified cv2+// rules:+// * exact 2x (src == 2*dst): round-half-up (sum + 2) >> 2+// * other integer ratios (4x, 8x, ...): round-to-nearest-even on the+// exact average (measured on cv2 5.0.0 at 4176 and 864x480 content:+// sum%area == area/2 rounds to the even quotient; the 2x fast path+// differs and is half-up).+// - Non-integer ratios (odd inputs): the generic cv2 resizeArea path with+// float32 weights, sequential float accumulation and cvRound (half-away,+// positive domain) on sum/area.+//+// The float fast-math hazards of the predecessor (midpoint truncation from+// ULPs) are gone because the integer paths never round a float.+Texture2D<float> Source : register(t0);+RWTexture2D<float> Destination : register(u0);+cbuffer Params : register(b0) { uint srcWidth; uint srcHeight; uint dstWidth; uint dstHeight; };++[numthreads(8, 8, 1)]+void main(uint3 id : SV_DispatchThreadID)+{+ if (id.x >= dstWidth || id.y >= dstHeight) return;+ uint x = id.x, y = id.y;+ if (srcWidth % dstWidth == 0 && srcHeight % dstHeight == 0)+ {+ uint sx = srcWidth / dstWidth, sy = srcHeight / dstHeight;+ uint x0 = x * sx, y0 = y * sy;+ int sum = 0;+ for (uint yy = 0; yy < sy; ++yy)+ for (uint xx = 0; xx < sx; ++xx)+ sum += (int)Source.Load(int3(x0 + xx, y0 + yy, 0));+ uint area = sx * sy;+ int value;+ if (sx == 1 && sy == 1)+ {+ value = sum;+ }+ else if (sx == 2 && sy == 2)+ {+ // cv2 two-pixel shrink fast path: positive half-up.+ value = (sum + 2) >> 2;+ }+ else+ {+ // generic integer ratio: round-to-nearest-even of sum/area+ uint rem = (uint)sum % area;+ uint q = (uint)sum / area;+ if (rem * 2 > area) q += 1;+ else if (rem * 2 == area) q = (q & 1u) ? q + 1u : q;+ value = (int)q;+ }+ Destination[id.xy] = (float)value;+ return;+ }+ // Generic (non-integer ratio) path: exact cv2 computeResizeAreaTab taps+ // (tab geometry computed in double like cv2's computeResizeAreaTab; per-tap+ // alpha cast to float; accumulation and final v_round in float).+ double xscale = (double)srcWidth / (double)dstWidth;+ double yscale = (double)srcHeight / (double)dstHeight;+ double fsx1 = (double)x * xscale;+ double fsx2 = fsx1 + xscale;+ double cellW = min(xscale, (double)srcWidth - fsx1);+ int sx1 = (int)ceil(fsx1), sx2 = (int)floor(fsx2);+ sx2 = min(sx2, (int)srcWidth - 1);+ sx1 = min(sx1, sx2);+ // per-tap alpha table for this destination column (tab order) and taps+ const int kMaxTaps = 16;+ int tapCols[kMaxTaps];+ precise float tapAlphas[kMaxTaps];+ int nTaps = 0;+ if ((double)sx1 - fsx1 > 1e-3)+ {+ tapCols[nTaps] = max(sx1 - 1, 0);+ tapAlphas[nTaps] = (float)(((double)sx1 - fsx1) / cellW);+ nTaps++;+ }+ for (int sx = sx1; sx < sx2; ++sx)+ {+ tapCols[nTaps] = clamp(sx, 0, (int)srcWidth - 1);+ tapAlphas[nTaps] = (float)(1.0 / cellW);+ nTaps++;+ }+ if (fsx2 - (double)sx2 > 1e-3)+ {+ tapCols[nTaps] = clamp(sx2, 0, (int)srcWidth - 1);+ tapAlphas[nTaps] = (float)(min(min(fsx2 - (double)sx2, 1.0), cellW) / cellW);+ nTaps++;+ }+ double fsy1 = (double)y * yscale;+ double fsy2 = fsy1 + yscale;+ double cellH = min(yscale, (double)srcHeight - fsy1);+ int sy1 = (int)ceil(fsy1), sy2 = (int)floor(fsy2);+ sy2 = min(sy2, (int)srcHeight - 1);+ sy1 = min(sy1, sy2);+ precise float sum = 0.0;+ bool first = true;+ // y-tap rows in tab order; rowsum per source row in float32 tab order.+ if ((double)sy1 - fsy1 > 1e-3)+ {+ int sy = max(sy1 - 1, 0);+ precise float beta = (float)(((double)sy1 - fsy1) / cellH);+ precise float r = 0.0;+ for (int k = 0; k < nTaps; ++k)+ r += Source.Load(int3((uint)tapCols[k], (uint)clamp(sy, 0, (int)srcHeight - 1), 0)) * tapAlphas[k];+ sum = beta * r;+ first = false;+ }+ for (int sy = sy1; sy < sy2; ++sy)+ {+ precise float beta = (float)(1.0 / cellH);+ precise float r = 0.0;+ for (int k = 0; k < nTaps; ++k)+ r += Source.Load(int3((uint)tapCols[k], (uint)clamp(sy, 0, (int)srcHeight - 1), 0)) * tapAlphas[k];+ if (first) { sum = beta * r; first = false; }+ else sum += beta * r;+ }+ if (fsy2 - (double)sy2 > 1e-3)+ {+ int sy = clamp(sy2, 0, (int)srcHeight - 1);+ precise float beta = (float)(min(min(fsy2 - (double)sy2, 1.0), cellH) / cellH);+ precise float r = 0.0;+ for (int k = 0; k < nTaps; ++k)+ r += Source.Load(int3((uint)tapCols[k], (uint)clamp(sy, 0, (int)srcHeight - 1), 0)) * tapAlphas[k];+ if (first) sum = beta * r;+ else sum += beta * r;+ }+ // v_round: round-half-to-even, saturate to [0,255]+ float lo = floor(sum);+ float frac = sum - lo;+ float rv;+ if (frac < 0.5) rv = lo;+ else if (frac > 0.5) rv = lo + 1.0;+ else rv = (fmod(lo, 2.0) == 0.0) ? lo : lo + 1.0;+ Destination[id.xy] = clamp(rv, 0.0, 255.0);+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_perfect_densify.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_densify.hlslnew file mode 100644index 00000000..bff06c1e--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_densify.hlsl@@ -0,0 +1,118 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// GPU DIS perfect-port P3: tiled OpenCV weighted patch densification.+// One 8x8 output tile is a workgroup. The sparse vectors covering the tile's+// expanded 8-pixel halo are staged in groupshared memory; every lane then+// performs the exact bounded overlap/photometric weighting for one output+// pixel. No overlap contribution or 1/max(1,abs(diff)) weight is dropped.+Texture2D<float> Current : register(t0);+Texture2D<float> Previous : register(t1);+Texture2D<float2> Sparse : register(t2);+RWTexture2D<float2> Dense : register(u0);+cbuffer Params : register(b0) { uint width; uint height; uint sparseWidth; uint sparseHeight; uint patch; uint stride; };++groupshared float2 gSparse[6][6];+groupshared uint gBaseX;+groupshared uint gBaseY;+groupshared uint gCountX;+groupshared uint gCountY;++float density_divide(float a, float b)+{+ precise float estimate = a / b;+#ifdef DIS_DENSE_EXACT+ precise double residual = (double)a - (double)estimate * (double)b;+ precise double corrected = (double)estimate + residual / (double)b;+ return (float)corrected;+#else+ return estimate;+#endif+}++float bilinear_previous(float x, float y)+{+ x = clamp(x, 0.0, (float)width - 1.001);+ y = clamp(y, 0.0, (float)height - 1.001);+ uint2 lo = uint2(floor(float2(x, y)));+ uint2 hi = min(lo + 1, uint2(width - 1, height - 1));+ float2 f = float2(x, y) - float2(lo);+ float a = Previous.Load(int3(lo, 0));+ float b = Previous.Load(int3(uint2(hi.x, lo.y), 0));+ float c = Previous.Load(int3(uint2(lo.x, hi.y), 0));+ float d = Previous.Load(int3(hi, 0));+ // CPU cv 4-term product order (matches the float-exact model path);+ // precise guards FMA/reassociation in the shader compiler.+ precise float t = (x - (float)lo.x) * (y - (float)lo.y) * d;+ // b is the upper-right texel and c is the lower-left texel. The CPU+ // cv::DIS code's four products use b for the lower-left coefficient and c+ // for the upper-right coefficient; keep the sample names conventional and+ // pair the cross terms explicitly.+ t = t + ((float)hi.x - x) * (y - (float)lo.y) * c;+ t = t + (x - (float)lo.x) * ((float)hi.y - y) * b;+ t = t + ((float)hi.x - x) * ((float)hi.y - y) * a;+ return t;+}++[numthreads(8, 8, 1)]+void main(uint3 tid : SV_GroupThreadID, uint3 gid : SV_GroupID)+{+ uint lane = tid.y * 8 + tid.x;+ uint tileX = gid.x * 8, tileY = gid.y * 8;+ if (lane == 0)+ {+ // Sparse patches whose [js*stride, js*stride+patch-1] interval can+ // overlap any pixel in this tile have top-left coordinates in the+ // expanded tile interval [tile- patch+1, tile+7].+ int bx = max(0, (int)tileX - (int)patch + 1);+ int by = max(0, (int)tileY - (int)patch + 1);+ gBaseX = (uint)((bx + (int)stride - 1) / (int)stride);+ gBaseY = (uint)((by + (int)stride - 1) / (int)stride);+ // A partial tile can begin beyond the last valid sparse patch (for+ // example h=33, tileY=32). cv's sliding window retains that final+ // patch; clamp the staged base before deriving the count so the tile+ // does not become an all-zero early return.+ gBaseX = min(gBaseX, sparseWidth - 1);+ gBaseY = min(gBaseY, sparseHeight - 1);+ uint ex = min(sparseWidth - 1, (tileX + 7) / stride);+ uint ey = min(sparseHeight - 1, (tileY + 7) / stride);+ gCountX = ex >= gBaseX ? ex - gBaseX + 1 : 0;+ gCountY = ey >= gBaseY ? ey - gBaseY + 1 : 0;+ }+ GroupMemoryBarrierWithGroupSync();+ uint count = gCountX * gCountY;+ if (lane < count && lane < 36)+ {+ uint localY = lane / gCountX, localX = lane - localY * gCountX;+ gSparse[localY][localX] = Sparse.Load(int3(gBaseX + localX, gBaseY + localY, 0)).xy;+ }+ GroupMemoryBarrierWithGroupSync();+ uint x = tileX + tid.x, y = tileY + tid.y;+ if (x >= width || y >= height || gCountX == 0 || gCountY == 0) return;+ // cv sliding-window semantics: the start index never passes end+ // (start_is < end_is guard), so the direct formula must be clamped to+ // last - otherwise the windows collapse on the right/bottom edges.+ uint lastX = min(gBaseX + gCountX - 1, x / stride);+ uint lastY = min(gBaseY + gCountY - 1, y / stride);+ uint firstX = (x + 1 <= patch) ? 0 : (x - patch + stride) / stride;+ uint firstY = (y + 1 <= patch) ? 0 : (y - patch + stride) / stride;+ firstX = min(firstX, lastX);+ firstY = min(firstY, lastY);+ precise float2 sumFlow = 0.0;+ precise float sumWeight = 0.0;+ for (uint sy = firstY; sy <= lastY; ++sy)+ for (uint sx = firstX; sx <= lastX; ++sx)+ {+ float2 flow = gSparse[sy - gBaseY][sx - gBaseX];+ precise float diff = bilinear_previous((float)x + flow.x, (float)y + flow.y) - Current.Load(int3(x, y, 0));+ precise float weight = density_divide(1.0, max(1.0, abs(diff)));+ sumFlow += weight * flow;+ sumWeight += weight;+ }+ Dense[uint2(x, y)] = float2(density_divide(sumFlow.x, max(sumWeight, 1e-20)),+ density_divide(sumFlow.y, max(sumWeight, 1e-20)));+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_perfect_final.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_final.hlslnew file mode 100644index 00000000..817a4612--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_final.hlsl@@ -0,0 +1,30 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// OpenCV generic CV_32FC2 INTER_LINEAR: float coordinate table, separable+// unfused weighted sums. Different from IPP C1 inter-level interpolation.+Texture2D<float2> Source : register(t0);+RWTexture2D<float2> Destination : register(u0);+cbuffer Params : register(b0) { uint srcWidth; uint srcHeight; uint dstWidth; uint dstHeight; uint scale; };+[numthreads(8,8,1)]+void main(uint3 id : SV_DispatchThreadID)+{+ if (id.x >= dstWidth || id.y >= dstHeight) return;+ precise double dx = ((double)id.x + 0.5) * (double)srcWidth / (double)dstWidth - 0.5;+ precise double dy = ((double)id.y + 0.5) * (double)srcHeight / (double)dstHeight - 0.5;+ precise float px = (float)dx, py = (float)dy;+ int ix = (int)floor(px), iy = (int)floor(py);+ precise float fx = px - (float)ix, fy = py - (float)iy;+ if (ix < 0 || ix >= (int)srcWidth - 1) fx = 0;+ int x0 = clamp(ix,0,(int)srcWidth-1), x1 = clamp(ix+1,0,(int)srcWidth-1);+ int y0 = clamp(iy,0,(int)srcHeight-1), y1 = clamp(iy+1,0,(int)srcHeight-1);+ float2 a=Source.Load(int3(x0,y0,0)), b=Source.Load(int3(x1,y0,0));+ float2 c=Source.Load(int3(x0,y1,0)), d=Source.Load(int3(x1,y1,0));+ precise float2 top=a*(1-fx)+b*fx, bottom=c*(1-fx)+d*fx;+ precise float2 value=top*(1-fy)+bottom*fy;+ Destination[id.xy]=value*(float)scale;+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_perfect_patch_exact.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_patch_exact.hlslnew file mode 100644index 00000000..d5a88ddb--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_patch_exact.hlsl@@ -0,0 +1,363 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// GPU DIS exact patch inverse search (Z2c).+//+// Exact OpenCV 5.0.0 semantics per candidate and per gradient-descent step:+// - bilinear patch diff ((w00*a + w01*b) + w10*c) + w11*d - i0, strictly+// left-associative float32 (precise guards reassociation/FMA);+// - mean-normalization sums accumulated in 4 lanes (lane k over samples+// (r, k) and (r, k+4) for r = 0..7, sequential float32 adds), reduced as+// (v0+v2) + (v1+v3) (OpenCV shift-tree v_reduce_sum);+// - candidate evaluation order: seed, side (scan-order neighbor), perp;+// strict '<' replaces the best;+// - gradient descent: invH from the separable structure tensor, 8 inner+// iterations, break when SSD >= previous SSD (after the update), final+// acceptance |delta|^2 <= 64;+// - warp coordinate clamp on the patch top-left, replicate border for the+// patch samples (equivalent to OpenCV's I1_ext access).+//+// Scheduling: one workgroup processes 16 patches (64 threads, 4 lanes each);+// the host dispatches one anti-diagonal per dispatch as before (wavefront+// same-pass propagation semantics).+Texture2D<float> I0 : register(t0);+Texture2D<float> I1 : register(t1);+Texture2D<int2> Gradient : register(t2);+Texture2D<float> XX : register(t3);+Texture2D<float> YY : register(t4);+Texture2D<float> XY : register(t5);+Texture2D<float> XSum : register(t6);+Texture2D<float> YSum : register(t7);+Texture2D<float2> InitialFlow : register(t8);+RWTexture2D<float2> Sparse : register(u0);++cbuffer Params : register(b0)+{+ uint width;+ uint height;+ uint sparseWidth;+ uint sparseHeight;+ uint patchSize;+ uint patchStride;+ uint gdIterations;+ uint direction; // 0 = forward (left/up), 1 = backward (right/down)+ uint diagonal;+ uint useInitialFlow;+};++groupshared float gShare[16][4]; // per-patch reduced lane scalars++#ifdef DIS_ROUNDED_DIVIDE+float rounded_divide(float a, float b)+{+ precise float estimate = a / b;+ // A bare (float)((double)a/b) is folded back into float division by DXC.+ // Preserve the double residual correction so the final float is rounded+ // from the quotient, rather than a hardware reciprocal approximation.+ precise double residual = (double)a - (double)estimate * (double)b;+ precise double corrected = (double)estimate + residual / (double)b;+ return (float)corrected;+}+#endif++// Exact mean-normalized patch residual for one candidate position.+// Returns reduced scalars (sd, sq, gx, gy) for the four lanes.+void patch_residual(uint px, uint py, float ux, float uy, uint lane,+ out float out_sd, out float out_sq,+ out float out_gx, out float out_gy)+{+ precise float i_I1 = min(max((float)py + uy + 16.0, 9.0), (float)height + 15.0);+ precise float j_I1 = min(max((float)px + ux + 16.0, 9.0), (float)width + 15.0);+ precise float di = i_I1 - floor(i_I1);+ precise float dj = j_I1 - floor(j_I1);+ precise float w11 = di * dj;+ precise float w10 = di * (1.0 - dj);+ precise float w01 = (1.0 - di) * dj;+ precise float w00 = (1.0 - di) * (1.0 - dj);+ int base_row = (int)floor(i_I1);+ int base_col = (int)floor(j_I1);++ precise float sd = 0.0;+ precise float sq = 0.0;+ precise float gx = 0.0;+ precise float gy = 0.0;+ uint k = lane;+ for (uint r = 0; r < 8; ++r)+ {+ precise float d_l = 0.0;+ precise float d_r = 0.0;+ // two samples per row per lane: k and k+4+ for (uint q = 0; q < 2; ++q)+ {+ uint c = k + q * 4;+ // replicate-border taps of I1 (I1_ext equivalent)+ int er = base_row + (int)r;+ int ec = base_col + (int)c;+ int r0 = min(max(er - 16, 0), (int)height - 1);+ int r1 = min(max(er + 1 - 16, 0), (int)height - 1);+ int c0 = min(max(ec - 16, 0), (int)width - 1);+ int c1 = min(max(ec + 1 - 16, 0), (int)width - 1);+ float a = I1.Load(int3(c0, r0, 0));+ float b = I1.Load(int3(c1, r0, 0));+ float cc = I1.Load(int3(c0, r1, 0));+ float d = I1.Load(int3(c1, r1, 0));+ precise float t = w00 * a;+ t = t + w01 * b;+ t = t + w10 * cc;+ t = t + w11 * d;+ precise float diff = t - I0.Load(int3(px + c, py + (int)r, 0));+ if (q == 0)+ d_l = diff;+ else+ d_r = diff;+ }+ precise float t_sd = d_l + d_r;+ sd = sd + t_sd;+ precise float t_sq = d_l * d_l + d_r * d_r;+ sq = sq + t_sq;+ int2 g0 = Gradient.Load(int3(px + k, py + (int)r, 0));+ int2 g1 = Gradient.Load(int3(px + k + 4, py + (int)r, 0));+ precise float t_gx = d_l * (float)g0.x + d_r * (float)g1.x;+ gx = gx + t_gx;+ precise float t_gy = d_l * (float)g0.y + d_r * (float)g1.y;+ gy = gy + t_gy;+ }+ out_sd = sd;+ out_sq = sq;+ out_gx = gx;+ out_gy = gy;+}++// (v0+v2) + (v1+v3) across the four lanes of one patch; result on lane 0.+// gs_index must be float: a uint signature silently truncated negative lane+// sums (hardware fptoui clamps them to 0), corrupting every sd reduction.+// Callers insert a GroupMemoryBarrier after reading gShare so the phase-1+// writes of the next reduce_lanes call cannot race the previous read.+void reduce_lanes(uint patch, uint lane, float gs_index)+{+ gShare[patch][lane] = gs_index;+ GroupMemoryBarrierWithGroupSync();+ if (lane < 2)+ {+ gShare[patch][lane] = gShare[patch][lane] + gShare[patch][lane + 2];+ }+ GroupMemoryBarrierWithGroupSync();+ if (lane == 0)+ {+ gShare[patch][2] = gShare[patch][0] + gShare[patch][1];+ }+ GroupMemoryBarrierWithGroupSync();+}++float candidate_ssd(uint px, uint py, float2 u, uint patch, uint lane)+{+ float sd, sq, gx, gy;+ patch_residual(px, py, u.x, u.y, lane, sd, sq, gx, gy);+ reduce_lanes(patch, lane, sd);+ float s_diff = gShare[patch][2];+ GroupMemoryBarrierWithGroupSync();+ reduce_lanes(patch, lane, sq);+ float s_sq = gShare[patch][2];+ GroupMemoryBarrierWithGroupSync();+ float n = 64.0;+ precise float ssd = s_sq - s_diff * s_diff / n;+ return ssd;+}++void candidate_gd(uint px, uint py, float2 seed, uint si, uint sj, uint patch, uint lane,+ out float2 out_flow, out bool out_ok)+{+ float xx = XX.Load(int3(sj, si, 0));+ float yy = YY.Load(int3(sj, si, 0));+ float xy = XY.Load(int3(sj, si, 0));+ precise float detH = xx * yy - xy * xy;+ if (abs(detH) < 0.001) detH = 0.001;+#ifdef DIS_ROUNDED_DIVIDE+ // Diagnostic: isolate hardware float division rounding from all other ops.+ precise float inv11 = rounded_divide(yy, detH);+ precise float inv12 = rounded_divide(-xy, detH);+ precise float inv22 = rounded_divide(xx, detH);+#else+ precise float inv11 = yy / detH;+ precise float inv12 = -xy / detH;+ precise float inv22 = xx / detH;+#endif+ float x_grad = XSum.Load(int3(sj, si, 0));+ float y_grad = YSum.Load(int3(sj, si, 0));+ float2 cur = seed;+ float prev_ssd = 1e10;+ [loop]+ for (uint t = 0; t < gdIterations; ++t)+ {+ float sd, sq, gx, gy;+ patch_residual(px, py, cur.x, cur.y, lane, sd, sq, gx, gy);+ reduce_lanes(patch, lane, sd);+ float s_diff = gShare[patch][2];+ GroupMemoryBarrierWithGroupSync();+ reduce_lanes(patch, lane, sq);+ float s_sq = gShare[patch][2];+ GroupMemoryBarrierWithGroupSync();+ reduce_lanes(patch, lane, gx);+ float s_gx = gShare[patch][2];+ GroupMemoryBarrierWithGroupSync();+ reduce_lanes(patch, lane, gy);+ float s_gy = gShare[patch][2];+ GroupMemoryBarrierWithGroupSync();+ float n = 64.0;+ precise float ssd = s_sq - s_diff * s_diff / n;+ precise float dUx = s_gx - s_diff * x_grad / n;+ precise float dUy = s_gy - s_diff * y_grad / n;+ precise float dx = inv11 * dUx + inv12 * dUy;+ precise float dy = inv12 * dUx + inv22 * dUy;+ cur.x = cur.x - dx;+ cur.y = cur.y - dy;+ if (ssd >= prev_ssd) break;+ prev_ssd = ssd;+ }+ float2 delta = cur - seed;+ out_ok = (delta.x * delta.x + delta.y * delta.y) <= (float)(patchSize * patchSize);+ out_flow = cur;+}++uint2 patch_coordinate(uint ordinal)+{+ uint first = max(0, (int)diagonal - (int)sparseWidth + 1);+ if (ordinal >= sparseHeight - first && diagonal - first < sparseWidth) {}+ uint is = max(0, (int)diagonal - (int)sparseWidth + 1);+ uint js = diagonal - is;+ if (direction != 0)+ {+ uint ris = is;+ uint rjs = js;+ is = sparseHeight - 1 - ris;+ js = sparseWidth - 1 - rjs;+ }+ if (ordinal != 0)+ {+ if (direction == 0)+ {+ is += ordinal;+ js -= ordinal;+ }+ else+ {+ is -= ordinal;+ js += ordinal;+ }+ }+ return uint2(js, is);+}++#ifdef DIS_SINGLE_PATCH_GROUP+[numthreads(4, 1, 1)]+#else+[numthreads(64, 1, 1)]+#endif+void main(uint3 groupThread : SV_GroupThreadID, uint3 group : SV_GroupID)+{+ uint lane = groupThread.x & 3;+ uint patch = groupThread.x >> 2;+#ifdef DIS_PARALLEL_STRIPES+ // CPU's eight propagation stripes have no inter-stripe candidates.+ // Run one local diagonal of every stripe in the same GPU dispatch.+ uint stripeHeight = (sparseHeight + 7) / 8;+ uint first = max(0, (int)diagonal - (int)sparseWidth + 1);+ uint last = min(diagonal, stripeHeight - 1);+ uint count = last >= first ? last - first + 1 : 0;+ if (count == 0) return;+ uint stripe = group.x / count;+ uint localRow = first + group.x % count;+ uint baseRow = stripe * stripeHeight;+ if (baseRow >= sparseHeight) return;+ uint actualHeight = min(stripeHeight, sparseHeight - baseRow);+ if (localRow >= actualHeight) return;+ uint si = direction == 0 ? baseRow + localRow : baseRow + actualHeight - 1 - localRow;+ uint localCol = diagonal - localRow;+ uint sj = direction == 0 ? localCol : sparseWidth - 1 - localCol;+#else+ uint first = max(0, (int)diagonal - (int)sparseWidth + 1);+ uint last = min(diagonal, sparseHeight - 1);+ uint count = (last >= first) ? last - first + 1 : 0;+ if (count == 0) return;+#ifdef DIS_SINGLE_PATCH_GROUP+ // One patch owns all threads and therefore every group barrier. Different+ // patches may take different candidates or terminate GD independently.+ uint ordinal0 = first + group.x;+#else+ uint ordinal0 = first + group.x * 16;+#endif+ uint ordinal = ordinal0 + patch;+ if (ordinal > last) return;+ uint2 coord = patch_coordinate(ordinal - first);+ uint sj = coord.x, si = coord.y;+#endif+ if (sj >= sparseWidth || si >= sparseHeight) return;+ uint px = sj * patchStride, py = si * patchStride;++ float2 seed = float2(0.0, 0.0);+ if (direction == 0)+ {+ if (useInitialFlow != 0)+ seed = InitialFlow.Load(int3(px + patchSize / 2, py + patchSize / 2, 0));+ else+ seed = float2(0.0, 0.0);+ }+ else+ {+ seed = Sparse.Load(int3(sj, si, 0));+ }++ float best = candidate_ssd(px, py, seed, patch, lane);+ float2 best_flow = seed;+ GroupMemoryBarrierWithGroupSync();+ if (direction == 0)+ {+ if (sj > 0)+ {+ float2 cand = Sparse.Load(int3(sj - 1, si, 0));+ float score = candidate_ssd(px, py, cand, patch, lane);+ if (score < best) { best = score; best_flow = cand; seed = cand; }+ GroupMemoryBarrierWithGroupSync();+ }+ // cv 8-stripe boundary: the perp candidate is only read inside the+ // stripe (si % stripe_sz != 0); stripes are ceil(sparseHeight/8) rows.+ if (si % ((sparseHeight + 7) / 8) != 0)+ {+ float2 cand = Sparse.Load(int3(sj, si - 1, 0));+ float score = candidate_ssd(px, py, cand, patch, lane);+ if (score < best) { best = score; best_flow = cand; seed = cand; }+ GroupMemoryBarrierWithGroupSync();+ }+ }+ else+ {+ if (sj + 1 < sparseWidth)+ {+ float2 cand = Sparse.Load(int3(sj + 1, si, 0));+ float score = candidate_ssd(px, py, cand, patch, lane);+ if (score < best) { best = score; best_flow = cand; seed = cand; }+ GroupMemoryBarrierWithGroupSync();+ }+ // cv 8-stripe boundary for the backward pass (si+1 inside the stripe)+ if ((si + 1) % ((sparseHeight + 7) / 8) != 0 && si + 1 < sparseHeight)+ {+ float2 cand = Sparse.Load(int3(sj, si + 1, 0));+ float score = candidate_ssd(px, py, cand, patch, lane);+ if (score < best) { best = score; best_flow = cand; seed = cand; }+ GroupMemoryBarrierWithGroupSync();+ }+ }++ float2 flow;+ bool ok;+ GroupMemoryBarrierWithGroupSync();+ candidate_gd(px, py, seed, si, sj, patch, lane, flow, ok);+ GroupMemoryBarrierWithGroupSync();+ float2 result = ok ? flow : seed;+ if (lane == 0)+ Sparse[uint2(sj, si)] = result;+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_perfect_upsample.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_upsample.hlslnew file mode 100644index 00000000..c6b76391--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_upsample.hlsl@@ -0,0 +1,55 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// Coarse-to-fine DIS flow initialization. OpenCV resizes each component+// linearly and multiplies by two when moving to the next finer pyramid level.+Texture2D<float2> Source : register(t0);+RWTexture2D<float2> Destination : register(u0);+cbuffer Params : register(b0) { uint srcWidth; uint srcHeight; uint dstWidth; uint dstHeight; };++float2 sample_linear(float2 p)+{+ p.x = clamp(p.x, 0.0, (float)srcWidth - 1.0);+ p.y = clamp(p.y, 0.0, (float)srcHeight - 1.0);+ uint2 lo = uint2(floor(p));+ uint2 hi = min(lo + 1, uint2(srcWidth - 1, srcHeight - 1));+ float2 f = p - (float2)lo;+ float2 a = Source.Load(int3(lo, 0));+ float2 b = Source.Load(int3(uint2(hi.x, lo.y), 0));+ float2 c = Source.Load(int3(uint2(lo.x, hi.y), 0));+ float2 d = Source.Load(int3(hi, 0));+ return lerp(lerp(a, b, f.x), lerp(c, d, f.x), f.y) * 2.0;+}++[numthreads(8, 8, 1)]+void main(uint3 id : SV_DispatchThreadID)+{+ if (id.x >= dstWidth || id.y >= dstHeight) return;+#ifdef DIS_IPP_UPSAMPLE+ // Frozen OpenCV wheel's IPP single-component INTER_LINEAR path. Keep+ // coordinate construction in binary64 until the fractional weight cast,+ // and match the three explicit FP32 fused lerps (see C oracle evidence).+ precise double px = ((double)id.x + 0.5) * (double)srcWidth / (double)dstWidth - 0.5;+ precise double py = ((double)id.y + 0.5) * (double)srcHeight / (double)dstHeight - 0.5;+ int ix = (int)px, iy = (int)py;+ if (px < (double)ix) --ix;+ if (py < (double)iy) --iy;+ precise float fx = (float)(px - (double)ix), fy = (float)(py - (double)iy);+ int x0 = clamp(ix, 0, (int)srcWidth - 1), x1 = clamp(ix + 1, 0, (int)srcWidth - 1);+ int y0 = clamp(iy, 0, (int)srcHeight - 1), y1 = clamp(iy + 1, 0, (int)srcHeight - 1);+ float2 a = Source.Load(int3(x0,y0,0)), b = Source.Load(int3(x1,y0,0));+ float2 c = Source.Load(int3(x0,y1,0)), d = Source.Load(int3(x1,y1,0));+ precise float2 ab = b - a, cd = d - c;+ precise float2 top = mad(ab, fx, a), bottom = mad(cd, fx, c);+ precise float2 span = bottom - top;+ precise float2 value = mad(span, fy, top);+ Destination[id.xy] = value * 2.0;+#else+ float2 p = (float2(id.xy) + 0.5) * float2(srcWidth, srcHeight) / float2(dstWidth, dstHeight) - 0.5;+ Destination[id.xy] = sample_linear(p);+#endif+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_deriv1.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_deriv1.hlslnew file mode 100644index 00000000..4ca31c0b--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_deriv1.hlsl@@ -0,0 +1,83 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// OpenCV 5.0.0 VariationalRefinement prepareBuffers, first derivative pass.+// The reference calls Sobel(..., ksize=1, BORDER_REPLICATE), which is the+// plain central difference [-1, 0, 1] (no 3x3 smoothing kernel), and warps+// with remap(INTER_LINEAR, BORDER_REPLICATE) on a CV_32F source, whose float+// path uses unquantized bilinear fractions (the 5-bit INTER_TAB_SIZE table+// only applies to the CV_8U fixed-point remap path).+Texture2D<float> Current : register(t0);+Texture2D<float> Previous : register(t1);+Texture2D<float2> Flow : register(t2);+RWTexture2D<float> Ix : register(u0);+RWTexture2D<float> Iy : register(u1);+RWTexture2D<float> Iz : register(u2);+RWTexture2D<float> Ixz : register(u3);+RWTexture2D<float> Iyz : register(u4);+cbuffer Params : register(b0) { uint width; uint height; };+#ifdef DIS_VR_CPU_WARP+float cpu_float_fma(float x, float y, float z) {+ precise double value = (double)x * (double)y + (double)z;+ return (float)value;+}+#endif++int2 clamp_xy(int2 p) { return clamp(p, int2(0, 0), int2(width - 1, height - 1)); }+float cur_at(int2 p) { p = clamp_xy(p); return Current.Load(int3(p, 0)); }+float2 flow_at(int2 p) { p = clamp_xy(p); return Flow.Load(int3(p, 0)); }+float prev_linear(float2 p, uint output_x)+{+ // BORDER_REPLICATE: clamp the coordinate to the last valid sample and let+ // the +1 tap clamp again; both the interior bilinear case and every+ // out-of-range side then reproduce cv::remap exactly.+ p = clamp(p, 0.0, float2(width - 1, height - 1));+ int2 q = int2(floor(p)); int2 r = min(q + 1, int2(width - 1, height - 1));+ float2 f = p - q;+ float a = Previous.Load(int3(q, 0)), b = Previous.Load(int3(int2(r.x, q.y), 0));+ float c = Previous.Load(int3(int2(q.x, r.y), 0)), d = Previous.Load(int3(r, 0));+#ifdef DIS_VR_CPU_WARP+ // OpenCV 5.0.0 warp_common.vector.hpp uses FMA in AVX2 blocks of 16+ // output pixels, then ordinary scalar multiply/add for the row tail.+ precise float ab = b - a, cd = d - c;+ if (output_x < (width / 16) * 16) {+ precise float top = cpu_float_fma(f.x, ab, a);+ precise float bottom = cpu_float_fma(f.x, cd, c);+ precise float span = bottom - top;+ return cpu_float_fma(f.y, span, top);+ }+ precise float top = a + f.x * ab;+ precise float bottom = c + f.x * cd;+ precise float value = top + f.y * (bottom - top);+ return value;+#else+ return lerp(lerp(a, b, f.x), lerp(c, d, f.x), f.y);+#endif+}+float warped_at(int2 p)+{+ p = clamp_xy(p); float2 f = flow_at(p); return prev_linear(float2(p) + f, p.x);+}+float avg_at(int2 p) {+ p = clamp_xy(p);+ precise float averaged = 0.5 * (cur_at(p) + warped_at(p));+ return averaged;+}+float iz_at(int2 p) { p = clamp_xy(p); return warped_at(p) - cur_at(p); }+float diff_x(float at[3][3]) { return at[1][2] - at[1][0]; }+float diff_y(float at[3][3]) { return at[2][1] - at[0][1]; }+[numthreads(8, 8, 1)]+void main(uint3 id : SV_DispatchThreadID)+{+ if (id.x >= width || id.y >= height) return;+ int2 p = int2(id.xy); float a[3][3]; float z[3][3];+ [unroll] for (int yy = 0; yy < 3; ++yy) [unroll] for (int xx = 0; xx < 3; ++xx) {+ int2 q = p + int2(xx - 1, yy - 1); a[yy][xx] = avg_at(q); z[yy][xx] = iz_at(q);+ }+ Ix[p] = diff_x(a); Iy[p] = diff_y(a); Iz[p] = z[1][1];+ Ixz[p] = diff_x(z); Iyz[p] = diff_y(z);+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_deriv2.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_deriv2.hlslnew file mode 100644index 00000000..c483ed38--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_deriv2.hlsl@@ -0,0 +1,29 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// OpenCV 5.0.0 VariationalRefinement second derivative pass. The reference+// calls Sobel(..., ksize=1, BORDER_REPLICATE) on the first-order maps, so+// every second derivative is the plain central difference [-1, 0, 1]:+// Ixx = dIx/dx, Ixy = dIx/dy, Iyy = dIy/dy.+Texture2D<float> Ix : register(t0);+Texture2D<float> Iy : register(t1);+RWTexture2D<float> Ixx : register(u0);+RWTexture2D<float> Ixy : register(u1);+RWTexture2D<float> Iyy : register(u2);+cbuffer Params : register(b0) { uint width; uint height; };+int2 clamp_xy(int2 p) { return clamp(p, int2(0, 0), int2(width - 1, height - 1)); }+float load_x(int2 p) { return Ix.Load(int3(clamp_xy(p), 0)); }+float load_y(int2 p) { return Iy.Load(int3(clamp_xy(p), 0)); }+float diff_x_x(int2 p) { return load_x(p + int2(1, 0)) - load_x(p - int2(1, 0)); }+float diff_y_x(int2 p) { return load_x(p + int2(0, 1)) - load_x(p - int2(0, 1)); }+float diff_y_y(int2 p) { return load_y(p + int2(0, 1)) - load_y(p - int2(0, 1)); }+[numthreads(8, 8, 1)]+void main(uint3 id : SV_DispatchThreadID)+{+ if (id.x >= width || id.y >= height) return;+ int2 p = int2(id.xy); Ixx[p] = diff_x_x(p); Ixy[p] = diff_y_x(p); Iyy[p] = diff_y_y(p);+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_sor.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_sor.hlslnew file mode 100644index 00000000..5aba440a--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_sor.hlsl@@ -0,0 +1,51 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// OpenCV 5.0.0 VariationalRefinement red/black SOR solve.+// Dispatches are serialized by parity. Consequently every read below sees+// the latest opposite-colour value, unlike a Jacobi ping-pong approximation.+Texture2D<float> A11 : register(t0);+Texture2D<float> A12 : register(t1);+Texture2D<float> A22 : register(t2);+Texture2D<float> B1 : register(t3);+Texture2D<float> B2 : register(t4);+Texture2D<float> Weights : register(t5);+Texture2D<float2> DFlow : register(t6);+RWTexture2D<float2> DFlowOut : register(u0);+cbuffer Params : register(b0) { uint width; uint height; float omega; uint parity; };+#ifdef DIS_VR_EXACT+#include "dis_cpu_rounding.hlsli"+#else+float cpu_divide(float a, float b) { return a / b; }+#endif+int2 clamp_xy(int2 p) { return clamp(p, int2(0, 0), int2(width - 1, height - 1)); }+float2 d_at(int2 p) { return DFlow.Load(int3(clamp_xy(p), 0)); }+float w_at(int2 p) { return Weights.Load(int3(clamp_xy(p), 0)); }+[numthreads(8, 8, 1)]+void main(uint3 id : SV_DispatchThreadID)+{+ if (id.x >= width || id.y >= height) return;+ // The host ping-pongs the increment texture on every parity pass. Copy+ // the opposite colour unchanged so the output is a complete state and+ // no SRV/UAV aliasing is needed for in-place checkerboard updates.+ int2 p = int2(id.xy); float2 d = d_at(p), left = d_at(p-int2(1,0)), right = d_at(p+int2(1,0));+ float2 up = d_at(p-int2(0,1)), down = d_at(p+int2(0,1));+ // The host ping-pongs the increment texture on every parity pass. Copy+ // the opposite colour unchanged so the output is a complete state and+ // no SRV/UAV aliasing is needed for in-place checkerboard updates.+ if (((id.x + id.y) & 1u) != parity) { DFlowOut[p] = d; return; }+ float wl = p.x > 0 ? w_at(p-int2(1,0)) : 0.0;+ float wr = p.x + 1 < (int)width ? w_at(p) : 0.0;+ float wu = p.y > 0 ? w_at(p-int2(0,1)) : 0.0;+ float wd = p.y + 1 < (int)height ? w_at(p) : 0.0;+ float su = wl * left.x + wr * right.x + wu * up.x + wd * down.x;+ float sv = wl * left.y + wr * right.y + wu * up.y + wd * down.y;+ float a11 = max(A11.Load(int3(p,0)), 1e-12), a12 = A12.Load(int3(p,0)), a22 = max(A22.Load(int3(p,0)), 1e-12);+ d.x += omega * (cpu_divide(su + B1.Load(int3(p,0)) - d.y * a12, a11) - d.x);+ d.y += omega * (cpu_divide(sv + B2.Load(int3(p,0)) - d.x * a12, a22) - d.y);+ DFlowOut[p] = d;+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_system.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_system.hlslnew file mode 100644index 00000000..983cc2c9--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_system.hlsl@@ -0,0 +1,122 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++// OpenCV 5.0.0 VariationalRefinement data + smoothness system assembly.+// One invocation owns one pixel, so edge terms are accumulated without the+// write races of a scatter implementation. The equations are the CPU+// ComputeDataTerm + horizontal/vertical smoothness passes, with the same+// alpha/delta/gamma/epsilon contract used by DIS Fast.+Texture2D<float> Ix : register(t0);+Texture2D<float> Iy : register(t1);+Texture2D<float> Iz : register(t2);+Texture2D<float> Ixx : register(t3);+Texture2D<float> Ixy : register(t4);+Texture2D<float> Iyy : register(t5);+Texture2D<float> Ixz : register(t6);+Texture2D<float> Iyz : register(t7);+Texture2D<float2> DFlow : register(t8);+Texture2D<float2> BaseFlow : register(t9);+Texture2D<float2> WorkFlow : register(t10);+RWTexture2D<float> A11 : register(u0);+RWTexture2D<float> A12 : register(u1);+RWTexture2D<float> A22 : register(u2);+RWTexture2D<float> B1 : register(u3);+RWTexture2D<float> B2 : register(u4);+RWTexture2D<float> Weights : register(u5);+cbuffer Params : register(b0) { uint width; uint height; float alpha; float delta; float gamma; float epsilon; };+#ifdef DIS_VR_EXACT+#include "dis_cpu_rounding.hlsli"+#else+float cpu_divide(float a, float b) { return a / b; }+float cpu_sqrt(float a) { return sqrt(a); }+#endif++int2 clamp_xy(int2 p) { return clamp(p, int2(0, 0), int2(width - 1, height - 1)); }+float2 flow_at(Texture2D<float2> f, int2 p) { return f.Load(int3(clamp_xy(p), 0)); }+// OpenCV's horizontal pass stores one forward-gradient weight per pixel and+// reuses it for both the right and down edges. Left/up edges use the source+// pixel's corresponding stored weight. The sum keeps OpenCV's sequential+// association: ux*ux + vx*vx + uy*uy + vy*vy + epsilon^2.+float forward_weight(float2 work, float2 right_work, float2 down_work)+{+ float ux = right_work.x - work.x, vx = right_work.y - work.y;+ float uy = down_work.x - work.x, vy = down_work.y - work.y;+ return cpu_divide(alpha * 0.5, cpu_sqrt(ux * ux + vx * vx + uy * uy + vy * vy + epsilon * epsilon));+}++[numthreads(8, 8, 1)]+void main(uint3 id : SV_DispatchThreadID)+{+ if (id.x >= width || id.y >= height) return;+ int2 p = int2(id.xy); float2 dw = DFlow.Load(int3(p, 0));+ float ix = Ix.Load(int3(p,0)), iy = Iy.Load(int3(p,0)), iz = Iz.Load(int3(p,0));+ float zeta2 = 0.010000000707805157f, eps2 = epsilon * epsilon;+ float deriv = ix * ix + iy * iy + zeta2;+ float residual = iz + ix * dw.x + iy * dw.y;+ float w = cpu_divide(cpu_divide(delta * 0.5, cpu_sqrt(cpu_divide(residual * residual, deriv) + eps2)), deriv);+ // Parenthesization follows OpenCV exactly: weight * (Ix*Ix) + zeta^2.+ float a11 = w * (ix * ix) + zeta2, a12 = w * (ix * iy);+ float a22 = w * (iy * iy) + zeta2;+ float b1 = -(w * (iz * ix)), b2 = -(w * (iz * iy));++ float ixx = Ixx.Load(int3(p,0)), ixy = Ixy.Load(int3(p,0)), iyy = Iyy.Load(int3(p,0));+ float ixz = Ixz.Load(int3(p,0)), iyz = Iyz.Load(int3(p,0));+ float n1 = ixx * ixx + ixy * ixy + zeta2, n2 = iyy * iyy + ixy * ixy + zeta2;+ float qx = ixz + ixx * dw.x + ixy * dw.y, qy = iyz + ixy * dw.x + iyy * dw.y;+ float gw = cpu_divide(gamma * 0.5, cpu_sqrt(cpu_divide(qx * qx, n1) + cpu_divide(qy * qy, n2) + eps2));+ a11 += gw * (cpu_divide(ixx * ixx, n1) + cpu_divide(ixy * ixy, n2));+ a12 += gw * (cpu_divide(ixx * ixy, n1) + cpu_divide(ixy * iyy, n2));+ a22 += gw * (cpu_divide(ixy * ixy, n1) + cpu_divide(iyy * iyy, n2));+ b1 -= gw * (cpu_divide(ixx * ixz, n1) + cpu_divide(ixy * iyz, n2));+ b2 -= gw * (cpu_divide(ixy * ixz, n1) + cpu_divide(iyy * iyz, n2));++ float2 work = WorkFlow.Load(int3(p,0)), base = BaseFlow.Load(int3(p,0));+ // OpenCV's implementation stores one horizontal weight per pixel and+ // deliberately reuses that array for the vertical pass.+ float2 right_work = flow_at(WorkFlow,p+int2(1,0));+ float2 down_work = flow_at(WorkFlow,p+int2(0,1));+ float wcur = forward_weight(work, right_work, down_work);+ float edge;+ // OpenCV HorPass edge (p, p+right): b1[p] += w*(W[right]-W[p]) and the+ // symmetric b1[right] -= w*(W[right]-W[p]); the receiving pixel therefore+ // accumulates the NEGATED difference for its left/up edges. The original+ // port added the negated form with a positive sign, flipping the+ // smoothness contribution of every left/up edge.+ // CPU scatters red edges before black edges. Thus black destinations+ // receive left/up contributions before their own right/down contributions.+ // A gather may reorder ownership, but must retain that FP32 association.+ uint colour = 0;+#ifdef DIS_VR_EXACT+ colour = (id.x + id.y) & 1u;+#endif+ [unroll] for (uint pass = 0; pass < 2; ++pass) {+ bool forward = ((pass + colour) & 1u) == 0;+ if (forward && p.x + 1 < (int)width) {+ edge = wcur; a11 += edge; a22 += edge;+ float2 d = edge * (flow_at(BaseFlow,p+int2(1,0)) - base); b1 += d.x; b2 += d.y;+ } else if (!forward && p.x > 0) {+ int2 left_p = p - int2(1, 0);+ edge = forward_weight(flow_at(WorkFlow,left_p), work, flow_at(WorkFlow,left_p+int2(0,1)));+ a11 += edge; a22 += edge;+ float2 d = edge * (base - flow_at(BaseFlow,left_p)); b1 -= d.x; b2 -= d.y;+ }+ }+ [unroll] for (uint pass = 0; pass < 2; ++pass) {+ bool forward = ((pass + colour) & 1u) == 0;+ if (forward && p.y + 1 < (int)height) {+ edge = wcur; a11 += edge; a22 += edge;+ float2 d = edge * (flow_at(BaseFlow,p+int2(0,1)) - base); b1 += d.x; b2 += d.y;+ } else if (!forward && p.y > 0) {+ int2 up = p - int2(0, 1);+ edge = forward_weight(flow_at(WorkFlow,up), flow_at(WorkFlow,up+int2(1,0)), work);+ a11 += edge; a22 += edge;+ float2 d = edge * (base - flow_at(BaseFlow,up)); b1 -= d.x; b2 -= d.y;+ }+ }+ A11[p] = a11; A12[p] = a12; A22[p] = a22; B1[p] = b1; B2[p] = b2;+ Weights[p] = wcur;+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_update.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_update.hlslnew file mode 100644index 00000000..37cdd894--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_update.hlsl@@ -0,0 +1,17 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++Texture2D<float2> BaseFlow : register(t0);+Texture2D<float2> DFlow : register(t1);+RWTexture2D<float2> WorkFlow : register(u0);+cbuffer Params : register(b0) { uint width; uint height; };+[numthreads(8, 8, 1)]+void main(uint3 id : SV_DispatchThreadID)+{+ if (id.x >= width || id.y >= height) return;+ int2 p = int2(id.xy); WorkFlow[p] = BaseFlow.Load(int3(p,0)) + DFlow.Load(int3(p,0));+}diff --git a/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_zero.hlsl b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_zero.hlslnew file mode 100644index 00000000..08bd72c4--- /dev/null+++ b/third_party/gpu-dis/src/gpu/shaders/dis_perfect_vr_zero.hlsl@@ -0,0 +1,11 @@+// Distribution note (2026-09-09): project-owned additions and modifications+// are licensed under Apache-2.0. Upstream portions retain their original+// licenses and attribution; see NOTICE, PROVENANCE.md and licenses/.+// OpenCV DIS/reference-derived portions retain Intel (2000-2008), Willow+// Garage (2009) and other upstream copyrights and BSD/Apache terms.+// See licenses/OPENCV_DIS_BSD_HEADER.txt and OPENCV_APACHE_LICENSE.txt.++RWTexture2D<float2> DFlow : register(u0);+cbuffer Params : register(b0) { uint width; uint height; };+[numthreads(8, 8, 1)]+void main(uint3 id : SV_DispatchThreadID) { if (id.x < width && id.y < height) DFlow[id.xy] = 0.0.xx; }