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(capture): N1 GPU unpack for packed capture formats (row-copy callback)
Veyra Goal Agent52c074594087
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 489fcee6..04637d74 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -221,6 +221,7 @@ endif()veyra_add_compute_shader(veyra_shader_yuv_to_rgb YuvToLinearRgb)veyra_add_compute_shader(veyra_shader_rgb_to_linear RgbToLinear)veyra_add_compute_shader(veyra_shader_yuy2_to_linear Yuy2ToLinear)+veyra_add_compute_shader(veyra_shader_packed_capture PackedCaptureToLinear)add_dependencies(veyra_shader_rgb_to_linear veyra_shader_yuy2_to_linear)# ScaleBlit: working frame -> swapchain backbuffer (Phase 6 present path).veyra_add_compute_shader(veyra_shader_scale_blit ScaleBlit)@@ -392,7 +393,7 @@ if(TARGET veyra_ngx AND TARGET veyra_nvof AND VEYRA_FFMPEG_ROOT)add_dependencies(veyra_pipelineveyra_shader_yuv_to_rgb veyra_shader_rgb_to_linear veyra_shader_parity_encodeveyra_shader_parity_decode veyra_shader_scale_blit- veyra_shader_nv12_upload veyra_shader_nvof_densify)+ veyra_shader_nv12_upload veyra_shader_nvof_densify veyra_shader_packed_capture)endif()# ---------------------------------------------------------------------------@@ -524,6 +525,11 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avformadd_executable(veyra_repair_parameter_tests tests/integration/RepairParameterTests.cpp)add_executable(veyra_image_dimension_tests tests/integration/ImageDimensionTests.cpp)add_executable(veyra_capture_color_probe tools/capture_color_probe/main.cpp)+ add_executable(veyra_capture_copy_bench tools/capture_copy_bench/main.cpp)+ target_compile_features(veyra_capture_copy_bench PRIVATE cxx_std_20)+ target_compile_options(veyra_capture_copy_bench PRIVATE /utf-8 /WX-)+ target_compile_definitions(veyra_capture_copy_bench PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)+ target_link_libraries(veyra_capture_copy_bench PRIVATE veyra_engine)add_executable(veyra_decode_profile_probe tools/decode_profile_probe/main.cpp)target_compile_features(veyra_decode_profile_probe PRIVATE cxx_std_20)target_compile_options(veyra_decode_profile_probe PRIVATE /utf-8 /WX-)diff --git a/apps/veyra/ui/AppShell.cpp b/apps/veyra/ui/AppShell.cppindex 3e51aa15..acbad247 100644--- a/apps/veyra/ui/AppShell.cpp+++ b/apps/veyra/ui/AppShell.cpp@@ -790,7 +790,7 @@ int argc=0;auto argv=CommandLineToArgvW(GetCommandLineW(),&argc);for(int i=1;i<a{// --capture-flip: diagnostics/smoke only; the interactive path uses the// capture panel checkbox and persists captureFlipVertical with presets.- {int flipArgc=0;auto flipArgv=CommandLineToArgvW(GetCommandLineW(),&flipArgc);for(int i=1;i<flipArgc;++i){if(!_wcsicmp(flipArgv[i],L"--capture-flip"))initialOptions.settings.captureFlipVertical=true;else if(!wcsncmp(flipArgv[i],L"--capture-buffer=",17)){const wchar_t* value=flipArgv[i]+17;if(!_wcsicmp(value,L"auto"))initialOptions.settings.captureBuffer=veyra::source::CaptureBufferMode::Auto;else if(!_wcsicmp(value,L"minimum"))initialOptions.settings.captureBuffer=veyra::source::CaptureBufferMode::Minimum;else if(!_wcsicmp(value,L"driver"))initialOptions.settings.captureBuffer=veyra::source::CaptureBufferMode::DriverDefault;}}LocalFree(flipArgv);}+ {int flipArgc=0;auto flipArgv=CommandLineToArgvW(GetCommandLineW(),&flipArgc);for(int i=1;i<flipArgc;++i){if(!_wcsicmp(flipArgv[i],L"--capture-flip"))initialOptions.settings.captureFlipVertical=true;else if(!wcsncmp(flipArgv[i],L"--capture-buffer=",17)){const wchar_t* value=flipArgv[i]+17;if(!_wcsicmp(value,L"auto"))initialOptions.settings.captureBuffer=veyra::source::CaptureBufferMode::Auto;else if(!_wcsicmp(value,L"minimum"))initialOptions.settings.captureBuffer=veyra::source::CaptureBufferMode::Minimum;else if(!_wcsicmp(value,L"driver"))initialOptions.settings.captureBuffer=veyra::source::CaptureBufferMode::DriverDefault;}else if(!_wcsicmp(flipArgv[i],L"--capture-cpu-unpack"))initialOptions.captureCpuUnpack=true;}LocalFree(flipArgv);}int positionalArgc=0;auto positionalArgv=CommandLineToArgvW(GetCommandLineW(),&positionalArgc);std::wstring positional;const wchar_t* valueFlags[]={L"--export-worker",L"--smoke-view",L"--smoke-dual-export",L"--smoke-seconds",L"--export-out",L"--max-frames",L"--cancel-after-ms",L"--smoke-save",L"--fg-multiplier",L"--capture-audio",L"--video-sr",L"--bitrate-mbps",L"--subtitle-primary",L"--subtitle-secondary",L"--subtitle-offset-ms",L"--subtitle-font-size"};for(int i=1;i<positionalArgc;++i){const std::wstring a=positionalArgv[i];diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex 30ea375f..9e2b31f8 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -1,5 +1,14 @@# 2026-09-11 继续修复目标模式执行中+## 2026-09-16 采集链路 N1:逐像素转换从 CPU 挪到 GPU++- 采集侧:`captureMediaLayout` 对 UYVY/YVYU/BGR24/RGB555/RGB565 保留驱动真实 packing(UYVY422/YVYU422/BGR24/RGB555LE/RGB565LE);`copyCaptureSample` 改为按行原样拷贝(保留 DIB 方向契约、手动翻转与 YUV 色度行跟随);新增 `captureLegacyCpuLayout` + `--capture-cpu-unpack` 诊断开关,旧 BGR0/YUY2 逐像素转换仍可回退。+- GPU 侧:`EnhanceGraphDesc::packedInput`(1 BGR24 / 2 RGB555 / 3 RGB565 / 4 UYVY / 5 YVYU);上传把驱动字节 1:1 放进 R8G8B8A8 纹理(纹素宽 = ceil(rowBytes/4));新增 `PackedCaptureToLinear.dxil` 统一 unpack(BGR24 取字节、RGB555/565 位扩展、UYVY/YVYU 双像素取样 + 既有颜色合同),`Yuy2ToLinear`/`RgbToLinear` 原路径不动。+- 拷贝优化:翻转时源正序读、目标倒序写(原来倒序读源把 4K RGB24 拖到 1.88ms);无翻转且行距相等时整平面一次 memcpy。+- 测试:构建 exit 0(含 dxc 编译新 shader);`veyra_capture_color_tests` failures=0;`veyra_hdr_color_tests` 全 15 格式 × full/limited GPU 用例 pass(新格式 error=0);修复合同 191/0;预设 66 组 exit 0。+- 微基准(新工具 `veyra_capture_copy_bench`,4K 3840×2160、30 次/帧,N1 行拷贝 vs 旧 CPU 拆包 ms/帧):YUY2 0.611;UYVY 0.640 vs 2.47;YVYU 0.595 vs 2.51;RGB24 1.120 vs 5.23;RGB555 0.791 vs 11.06;RGB565 0.828 vs 10.87;NV12 0.199。全部达到 N1 目标(YUY2≤1.0、BGR24≤1.5、UYVY/RGB555/565≤1.2)。+- 未执行(如实):真卡冒烟与 delivery 门禁本轮未跑——用户自己的 Veyra 实例(21:33 启动、GPU 71%)正占用采集卡与 GPU,待释放后补跑;"旧 CPU vs 新 GPU 全图逐像素平均/最大误差"未单独做(GPU 用例以黑白/10bit 阶梯验证 error=0)。+## 2026-09-16 采集链路 N3:格式排序与延迟标注- `include/veyra/source/CaptureFormatRank.h`(新):`captureFormatRank` / `captureFormatTier` / `captureFormatTierLabel` / `captureFormatNeedsCostHint`。推荐顺序:NV12/P010 → YUY2 → RGB24/RGB32/ARGB32 → UYVY/YVYU/RGB555/RGB565 → 压缩/需解码(rank 100)。diff --git a/include/veyra/engine/EngineController.h b/include/veyra/engine/EngineController.hindex b9678620..98f3864d 100644--- a/include/veyra/engine/EngineController.h+++ b/include/veyra/engine/EngineController.h@@ -20,6 +20,7 @@ class FrameFlowWindow;struct PlayerOptions { bool nr=false,sr=false,fg=false,realtime=true; uint32_t fgMultiplier=2; EnhancementSettings settings;bool captureReplayForTest=false; // file-backed live scheduler test; never enabled by UIbool captureReplayDisableFgAdmissionForTest=false; // controlled scheduler A/B only+ bool captureCpuUnpack=false; // N1 diagnostic: legacy per-pixel CPU unpackEnhancementSettings snapshot()const{auto s=settings;s.nr=nr;s.sr=sr;s.multiplier=fg?fgMultiplier:1;s.nrPolicy=realtime?(settings.nrPolicy==pipeline::NrSizePolicy::Native?pipeline::NrSizePolicy::Realtime:settings.nrPolicy):pipeline::NrSizePolicy::Native;return s;}static PlayerOptions from(EnhancementSettings s){PlayerOptions o;o.nr=s.nr;o.sr=s.sr;o.fg=s.multiplier>1;o.fgMultiplier=std::max(2u,s.multiplier);o.realtime=s.nrPolicy!=pipeline::NrSizePolicy::Native;o.settings=s;return o;}};diff --git a/include/veyra/pipeline/ColorMetadata.h b/include/veyra/pipeline/ColorMetadata.hindex 62585335..19fc488a 100644--- a/include/veyra/pipeline/ColorMetadata.h+++ b/include/veyra/pipeline/ColorMetadata.h@@ -32,6 +32,11 @@ inline ColorDescription resolveFrameColor(const AVFrame& frame,ColorDescriptioncase AV_PIX_FMT_YUV420P:case AV_PIX_FMT_YUVJ420P:c.pixelFormat=SourcePixelFormat::Yuv420P;break;case AV_PIX_FMT_YUYV422:c.pixelFormat=SourcePixelFormat::Yuy2;break;case AV_PIX_FMT_BGRA:case AV_PIX_FMT_BGR0:c.pixelFormat=SourcePixelFormat::Bgra8;break;+ case AV_PIX_FMT_BGR24:c.pixelFormat=SourcePixelFormat::Bgr24;break;+ case AV_PIX_FMT_RGB555LE:c.pixelFormat=SourcePixelFormat::Rgb555;break;+ case AV_PIX_FMT_RGB565LE:c.pixelFormat=SourcePixelFormat::Rgb565;break;+ case AV_PIX_FMT_UYVY422:c.pixelFormat=SourcePixelFormat::Uyvy;break;+ case AV_PIX_FMT_YVYU422:c.pixelFormat=SourcePixelFormat::Yvyu;break;default:break;}const auto* format=av_pix_fmt_desc_get(AVPixelFormat(frame.format));diff --git a/include/veyra/pipeline/EnhanceGraph.h b/include/veyra/pipeline/EnhanceGraph.hindex e4caba38..e4a33937 100644--- a/include/veyra/pipeline/EnhanceGraph.h+++ b/include/veyra/pipeline/EnhanceGraph.h@@ -81,6 +81,9 @@ struct EnhanceGraphDesc {bool highQualityPresentation = false; // PS5 ordinary scaling, no AI SRbool rgbInput = false; // allocate direct RGBA ingestion before NGX creationbool yuy2Input = false; // packed Y0 U Y1 V -> linear FP16; never subsample to NV12+ // N1: packed capture ingress (1 BGR24, 2 RGB555, 3 RGB565, 4 UYVY, 5 YVYU).+ // The driver's bytes are uploaded 1:1 and unpacked by the upload shader.+ uint32_t packedInput = 0;bool stillImage = false; // no temporal motion/FG history for a single imageuint32_t nrWidth=0,nrHeight=0; // zero preserves legacy native working extentuint32_t flowWidth=0,flowHeight=0; // zero preserves legacy source-space NVOF extentdiff --git a/include/veyra/pipeline/FramePacket.h b/include/veyra/pipeline/FramePacket.hindex 71e02bc5..e705904d 100644--- a/include/veyra/pipeline/FramePacket.h+++ b/include/veyra/pipeline/FramePacket.h@@ -65,7 +65,26 @@ enum class SourcePixelFormat : uint8_t {Bgra8, // 8-bit BGRARgba16F, // canonical linear working formatP016, // 16-bit capture storage; does not imply HDR transfer+ // N1 packed capture formats: the driver's bytes reach the GPU 1:1 and the+ // upload shader unpacks them (see EnhanceGraphDesc::packedInput).+ Bgr24, // RGB24 DIB, BGR byte order+ Rgb555, // 16-bit 5:5:5 DIB+ Rgb565, // 16-bit 5:6:5 DIB+ Uyvy, // UYVY 4:2:2+ Yvyu, // YVYU 4:2:2};+// Value carried in EnhanceGraphDesc::packedInput; 0 means "not a packed input".+constexpr uint32_t packedInputCode(SourcePixelFormat format) {+ switch (format) {+ case SourcePixelFormat::Bgr24: return 1;+ case SourcePixelFormat::Rgb555: return 2;+ case SourcePixelFormat::Rgb565: return 3;+ case SourcePixelFormat::Uyvy: return 4;+ case SourcePixelFormat::Yvyu: return 5;+ default: break;+ }+ return 0;+}enum class ColorRange : uint8_t { Unknown = 0, Limited, Full };enum class YuvMatrix : uint8_t { Unknown = 0, BT601, BT709, BT2020NCL, BT2020CL };diff --git a/include/veyra/source/CaptureCardSource.h b/include/veyra/source/CaptureCardSource.hindex e91319a5..d9fe8465 100644--- a/include/veyra/source/CaptureCardSource.h+++ b/include/veyra/source/CaptureCardSource.h@@ -52,6 +52,9 @@ public:// match the samples (RGB24 upside-down reports). Applies to the next// sample; works for RGB and YUV without touching the device.void setVerticalFlip(bool enabled);+ // N1 diagnostic: keep the legacy per-pixel CPU unpack (BGR0/YUY2 targets)+ // instead of the GPU unpack path. Applied on the next connect.+ void setCpuUnpack(bool enabled);CaptureMetrics metrics()const;void videoPresented(double ptsMs,int64_t host100ns,int64_t arrival100ns);void videoReset(bool resetAudio=true);diff --git a/include/veyra/source/CaptureMediaType.h b/include/veyra/source/CaptureMediaType.hindex d48345aa..41d21de5 100644--- a/include/veyra/source/CaptureMediaType.h+++ b/include/veyra/source/CaptureMediaType.h@@ -52,7 +52,11 @@ inline bool captureMediaLayout(const AM_MEDIA_TYPE& type,CaptureMediaLayout& outout.packing=capturePacking(type.subtype);switch(out.packing){case CapturePacking::Yuy2:case CapturePacking::Uyvy:case CapturePacking::Yvyu:- if(out.width%2)return false;out.format=AV_PIX_FMT_YUYV422;out.rowBytes=out.width*2;break;+ if(out.width%2)return false;+ // N1: keep the driver's true packing in the frame contract and unpack+ // on the GPU; only the legacy CPU-unpack diagnostic maps to YUY2.+ out.format=out.packing==CapturePacking::Uyvy?AV_PIX_FMT_UYVY422:out.packing==CapturePacking::Yvyu?AV_PIX_FMT_YVYU422:AV_PIX_FMT_YUYV422;+ out.rowBytes=out.width*2;break;case CapturePacking::Nv12:case CapturePacking::Nv21:case CapturePacking::I420:case CapturePacking::Yv12:case CapturePacking::P010:case CapturePacking::P016:if(out.width%2||out.height%2)return false;@@ -60,20 +64,22 @@ inline bool captureMediaLayout(const AM_MEDIA_TYPE& type,CaptureMediaLayout& outout.format=out.planes==3?AV_PIX_FMT_YUV420P:out.packing==CapturePacking::P010?AV_PIX_FMT_P010:out.packing==CapturePacking::P016?AV_PIX_FMT_P016:AV_PIX_FMT_NV12;out.rowBytes=out.width*((out.format==AV_PIX_FMT_P010||out.format==AV_PIX_FMT_P016)?2:1);break;case CapturePacking::Bgr32:case CapturePacking::Bgra32:case CapturePacking::Bgr24:case CapturePacking::Rgb555:case CapturePacking::Rgb565:- out.format=AV_PIX_FMT_BGR0;out.bottomUp=bm.biHeight>0;+ out.format=out.packing==CapturePacking::Bgr24?AV_PIX_FMT_BGR24:out.packing==CapturePacking::Rgb555?AV_PIX_FMT_RGB555LE:out.packing==CapturePacking::Rgb565?AV_PIX_FMT_RGB565LE:AV_PIX_FMT_BGR0;+ out.bottomUp=bm.biHeight>0;out.rowBytes=out.width*(out.packing==CapturePacking::Bgr24?3:(out.packing==CapturePacking::Rgb555||out.packing==CapturePacking::Rgb565)?2:4);break;default:return false;}const unsigned rows=out.planes>1?out.height*3/2:out.height;+ const bool rgbDib=out.format==AV_PIX_FMT_BGR0||out.format==AV_PIX_FMT_BGR24||out.format==AV_PIX_FMT_RGB555LE||out.format==AV_PIX_FMT_RGB565LE;out.stride=out.rowBytes;- if(out.format==AV_PIX_FMT_BGR0)out.stride=(out.stride+3)&~3u;+ if(rgbDib)out.stride=(out.stride+3)&~3u;if(bm.biSizeImage){// Fixed uncompressed allocation may include per-row padding. Reject// ambiguous/incomplete layouts instead of reading subsequent rows wrong.if(bm.biSizeImage%rows||bm.biSizeImage/rows<out.stride)return false;out.stride=bm.biSizeImage/rows;}- if(out.format==AV_PIX_FMT_BGR0&&out.stride%4)return false;+ if(rgbDib&&out.stride%4)return false;if((out.planes==3||out.format==AV_PIX_FMT_P010||out.format==AV_PIX_FMT_P016)&&out.stride%2)return false;out.sampleBytes=size_t(out.stride)*rows;if(out.planes>1){@@ -111,6 +117,17 @@ inline bool captureMediaLayout(const AM_MEDIA_TYPE& type,CaptureMediaLayout& out}return true;}+// N1 rollback switch (diagnostic): map a packed capture layout back to the+// legacy BGR0 / YUY2 target the old per-pixel CPU conversion produced. The+// device still delivers the packed bytes; copyCaptureSample then converts on+// the callback thread exactly as it did before N1.+inline bool captureLegacyCpuLayout(CaptureMediaLayout& layout){+ switch(layout.packing){+ case CapturePacking::Uyvy:case CapturePacking::Yvyu:layout.format=AV_PIX_FMT_YUYV422;return true;+ case CapturePacking::Bgr24:case CapturePacking::Rgb555:case CapturePacking::Rgb565:layout.format=AV_PIX_FMT_BGR0;return true;+ default:return false;+ }+}// flipVertical is the manual capture override: it inverts whatever the DIB// header claims (and reverses chroma rows for planar YUV), so a device whose// declared orientation does not match its samples can still be watched.@@ -120,13 +137,25 @@ inline bool copyCaptureSample(const CaptureMediaLayout& layout,const uint8_t* srif(layout.planes>1&&(!dst.data[1]||dst.linesize[1]<int(layout.chromaRowBytes)))return false;if(layout.planes>2&&(!dst.data[2]||dst.linesize[2]<int(layout.chromaRowBytes)))return false;const bool flip=layout.bottomUp!=flipVertical;- for(unsigned y=0;y<layout.height;++y){- const auto* s=src+size_t(flip?layout.height-1-y:y)*layout.stride;auto* d=dst.data[0]+ptrdiff_t(y)*dst.linesize[0];- if(layout.packing==CapturePacking::Bgr24){for(unsigned x=0;x<layout.width;++x){d[x*4]=s[x*3];d[x*4+1]=s[x*3+1];d[x*4+2]=s[x*3+2];d[x*4+3]=255;}}- else if(layout.packing==CapturePacking::Rgb555||layout.packing==CapturePacking::Rgb565){+ // Fast path: no row reorder and no per-pixel conversion, so the whole+ // plane is one contiguous copy (single-plane layouts only).+ const bool rowConvert=(layout.format==AV_PIX_FMT_BGR0&&(layout.packing==CapturePacking::Bgr24||layout.packing==CapturePacking::Rgb555||layout.packing==CapturePacking::Rgb565))||+ (layout.format==AV_PIX_FMT_YUYV422&&(layout.packing==CapturePacking::Uyvy||layout.packing==CapturePacking::Yvyu));+ if(!flip&&!rowConvert&&layout.planes==1&&size_t(dst.linesize[0])==size_t(layout.stride)){+ std::memcpy(dst.data[0],src,size_t(layout.stride)*layout.height);+ return true;+ }+ // When rows are flipped, read the source ascending and write the+ // destination descending: the read stream keeps the hardware prefetcher+ // (walking the source backwards cost ~2x on the 4K RGB24 case).+ for(unsigned sourceRow=0;sourceRow<layout.height;++sourceRow){+ const unsigned dstRow=flip?layout.height-1-sourceRow:sourceRow;+ const auto* s=src+size_t(sourceRow)*layout.stride;auto* d=dst.data[0]+ptrdiff_t(dstRow)*dst.linesize[0];+ if(layout.format==AV_PIX_FMT_BGR0&&layout.packing==CapturePacking::Bgr24){for(unsigned x=0;x<layout.width;++x){d[x*4]=s[x*3];d[x*4+1]=s[x*3+1];d[x*4+2]=s[x*3+2];d[x*4+3]=255;}}+ else if(layout.format==AV_PIX_FMT_BGR0&&(layout.packing==CapturePacking::Rgb555||layout.packing==CapturePacking::Rgb565)){const bool six=layout.packing==CapturePacking::Rgb565;for(unsigned x=0;x<layout.width;++x){const unsigned v=s[x*2]|(unsigned(s[x*2+1])<<8);const unsigned b=v&31,g=(v>>5)&(six?63:31),r=(v>>(six?11:10))&31;d[x*4]=uint8_t((b<<3)|(b>>2));d[x*4+1]=uint8_t(six?(g<<2)|(g>>4):(g<<3)|(g>>2));d[x*4+2]=uint8_t((r<<3)|(r>>2));d[x*4+3]=255;}- }else if(layout.packing==CapturePacking::Uyvy||layout.packing==CapturePacking::Yvyu){+ }else if(layout.format==AV_PIX_FMT_YUYV422&&(layout.packing==CapturePacking::Uyvy||layout.packing==CapturePacking::Yvyu)){const bool uy=layout.packing==CapturePacking::Uyvy;for(unsigned x=0;x<layout.rowBytes;x+=4){d[x]=s[x+(uy?1:0)];d[x+1]=s[x+(uy?0:3)];d[x+2]=s[x+(uy?3:2)];d[x+3]=s[x+(uy?2:1)];}}else std::memcpy(d,s,layout.rowBytes);}diff --git a/shaders/PackedCaptureToLinear.hlsl b/shaders/PackedCaptureToLinear.hlslnew file mode 100644index 00000000..97bd0b84--- /dev/null+++ b/shaders/PackedCaptureToLinear.hlsl@@ -0,0 +1,51 @@+// N1: packed capture ingress. The driver's bytes are uploaded 1:1 into an+// R8G8B8A8_UNORM texture; this shader unpacks BGR24 / RGB555 / RGB565 /+// UYVY / YVYU with the same color contract as RgbToLinear / Yuy2ToLinear.+// packing: 1 BGR24, 2 RGB555, 3 RGB565, 4 UYVY, 5 YVYU.+#include "HdrColor.hlsli"+cbuffer Params : register(b0) {+ uint width; uint height; uint transfer; uint limitedU;+ float limited; float matrix709; float primaries2020; uint packing;+};+Texture2D<float4> packedBytes : register(t0);+RWTexture2D<float4> linearRgb : register(u0);+float decode(float v) {+ if (transfer == 3) return pow(max(v, 0), 2.4);+ if (transfer == 2) return v < 0.081 ? v / 4.5 : pow((v + 0.099) / 1.099, 1.0 / 0.45);+ if (transfer == 0) return v;+ return v <= 0.04045 ? v / 12.92 : pow((v + 0.055) / 1.055, 2.4);+}+uint byteAt(uint y, uint index) {+ const float4 t = packedBytes[uint2(index >> 2, y)];+ return uint(round(saturate(t[index & 3]) * 255.0));+}+[numthreads(16,16,1)]+void main(uint3 p : SV_DispatchThreadID) {+ if (p.x >= width || p.y >= height) return;+ float3 rgb;+ if (packing == 4 || packing == 5) {+ const float4 pair = packedBytes[uint2(p.x / 2, p.y)];+ const bool second = (p.x & 1) != 0;+ float y, cb, cr;+ if (packing == 4) { y = second ? pair.w : pair.y; cb = pair.x; cr = pair.z; }+ else { y = second ? pair.z : pair.x; cb = pair.w; cr = pair.y; }+ float2 uv = float2(cb, cr) - 128.0 / 255.0;+ if (limited > 0.5) { y = (y - 16.0 / 255.0) * (255.0 / 219.0); uv *= 255.0 / 224.0; }+ rgb = matrix709 > 0.5 ? float3(y + 1.5748 * uv.y, y - 0.187324 * uv.x - 0.468124 * uv.y, y + 1.8556 * uv.x)+ : float3(y + 1.402 * uv.y, y - 0.344136 * uv.x - 0.714136 * uv.y, y + 1.772 * uv.x);+ if (matrix709 > 1.5) rgb = float3(y + 1.4746 * uv.y, y - 0.164553 * uv.x - 0.571353 * uv.y, y + 1.8814 * uv.x);+ rgb = saturate(rgb);+ } else if (packing == 1) {+ const uint base = p.x * 3;+ rgb = float3(byteAt(p.y, base + 2), byteAt(p.y, base + 1), byteAt(p.y, base)) / 255.0;+ } else {+ const uint base = p.x * 2;+ const uint v = byteAt(p.y, base) | (byteAt(p.y, base + 1) << 8);+ if (packing == 2) rgb = float3(((v >> 10) & 31) / 31.0, ((v >> 5) & 31) / 31.0, (v & 31) / 31.0);+ else rgb = float3(((v >> 11) & 31) / 31.0, ((v >> 5) & 63) / 63.0, (v & 31) / 31.0);+ }+ if (limitedU != 0 && packing <= 3) rgb = saturate((rgb - 16.0 / 255.0) * (255.0 / 219.0));+ float3 decoded = float3(decode(rgb.r), decode(rgb.g), decode(rgb.b));+ if (primaries2020 > 0.5) decoded = HdrTo709(decoded);+ linearRgb[p.xy] = float4(decoded, 1);+}diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cppindex b69764a1..a3e89c31 100644--- a/src/engine/EngineController.cpp+++ b/src/engine/EngineController.cpp@@ -203,6 +203,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sif(physicalCapture)captureSource.setAudioIngress(unsigned(options.settings.captureAudio));if(physicalCapture)captureSource.setVerticalFlip(options.settings.captureFlipVertical);if(physicalCapture)captureSource.setBufferMode(unsigned(options.settings.captureBuffer));+ if(physicalCapture)captureSource.setCpuUnpack(options.captureCpuUnpack);#ifdef VEYRA_ENABLE_REMOTEPLAYif(remote){status(L"正在连接 PS5…");@@ -251,6 +252,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sgd.rgbInput=isImage||(isCapture&&activeSource->info().color.pixelFormat==pipeline::SourcePixelFormat::Bgra8);gd.captureBitDepth=activeSource->info().color.pixelFormat==pipeline::SourcePixelFormat::P010?10:activeSource->info().color.pixelFormat==pipeline::SourcePixelFormat::P016?16:8;gd.yuy2Input=isCapture&&activeSource->info().color.pixelFormat==pipeline::SourcePixelFormat::Yuy2;gd.stillImage=isImage;+ gd.packedInput=isCapture?pipeline::packedInputCode(activeSource->info().color.pixelFormat):0;const auto resolution=pipeline::ResolutionPlan::make({width,height},options.sr,options.snapshot().nrPolicy,isImage,options.settings.revision,options.settings.srTarget,options.settings.lowLatency&&options.nr);gd.workWidth=resolution.base.width;gd.workHeight=resolution.base.height;gd.nrWidth=resolution.nr.width;gd.nrHeight=resolution.nr.height;gd.flowWidth=resolution.flow.width;gd.flowHeight=resolution.flow.height;const bool nvidiaAdapter=ctx.adapter().isNvidia;diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cppindex d94f71ed..2fe9a488 100644--- a/src/pipeline/EnhanceGraph.cpp+++ b/src/pipeline/EnhanceGraph.cpp@@ -49,6 +49,41 @@ namespace {constexpr int64_t usPerSecond = 1000000;float uintBits(uint32_t v) { return std::bit_cast<float>(v); }+// N1 packed capture ingress helpers. Codes match pipeline::packedInputCode:+// 1 BGR24, 2 RGB555, 3 RGB565, 4 UYVY, 5 YVYU.+unsigned packedIngressRowBytes(uint32_t code,unsigned width){+ return code==1?width*3:width*2;+}+unsigned packedIngressTexels(uint32_t code,unsigned width){+ return (packedIngressRowBytes(code,width)+3)/4;+}+AVPixelFormat packedIngressFormat(uint32_t code){+ switch(code){+ case 1:return AV_PIX_FMT_BGR24;+ case 2:return AV_PIX_FMT_RGB555LE;+ case 3:return AV_PIX_FMT_RGB565LE;+ case 4:return AV_PIX_FMT_UYVY422;+ case 5:return AV_PIX_FMT_YVYU422;+ default:break;+ }+ return AV_PIX_FMT_NONE;+}+// Coarse luma sample for scene analysis; mirrors the CPU luma weights.+uint8_t packedIngressLuma(const AVFrame& frame,uint32_t code,unsigned x,unsigned y){+ const auto* p=frame.data[0]+ptrdiff_t(y)*frame.linesize[0];+ switch(code){+ case 1:{const auto* q=p+x*3;return uint8_t((54*unsigned(q[2])+183*unsigned(q[1])+19*unsigned(q[0])+128)>>8);}+ case 2:{const unsigned w=unsigned(p[x*2])|(unsigned(p[x*2+1])<<8);+ const unsigned r=(w>>10)&31,g=(w>>5)&31,b=w&31;return uint8_t((54*(r<<3|r>>2)+183*(g<<3|g>>2)+19*(b<<3|b>>2)+128)>>8);}+ case 3:{const unsigned w=unsigned(p[x*2])|(unsigned(p[x*2+1])<<8);+ const unsigned r=(w>>11)&31,g=(w>>5)&63,b=w&31;return uint8_t((54*(r<<3|r>>2)+183*(g<<2|g>>4)+19*(b<<3|b>>2)+128)>>8);}+ case 4:return p[x*2+1]; // UYVY: Y0 follows U+ case 5:return p[x*2]; // YVYU: Y0 leads+ default:break;+ }+ return 0;+}+} // namespaceEnhanceGraph::EnhanceGraph(gfx::D3D12DeviceContext& context, gfx::CommandSlotRing& ring)@@ -167,9 +202,10 @@ bool EnhanceGraph::createResources()upZeroMotion_ = makeUploadBuffer(context_.device(), dPitch_ * workH_);lumaTex_ = makeTexture(context_.device(), srcW_, srcH_, desc_.wideYuvInput()?DXGI_FORMAT_R16_UNORM:DXGI_FORMAT_R8_UNORM, true);chromaTex_ = makeTexture(context_.device(), (srcW_+1) / 2, (srcH_+1) / 2, desc_.wideYuvInput()?DXGI_FORMAT_R16G16_UNORM:DXGI_FORMAT_R8G8_UNORM, true);- if(desc_.rgbInput||desc_.yuy2Input){- if(desc_.yuy2Input&&(srcW_%2||desc_.rgbInput))return false;- const unsigned packedWidth=desc_.yuy2Input?srcW_/2:srcW_;+ if(desc_.rgbInput||desc_.yuy2Input||desc_.packedInput){+ if((desc_.yuy2Input||desc_.packedInput==4||desc_.packedInput==5)&&srcW_%2)return false;+ if(desc_.rgbInput&&(desc_.yuy2Input||desc_.packedInput))return false;+ const unsigned packedWidth=desc_.packedInput?packedIngressTexels(desc_.packedInput,srcW_):desc_.yuy2Input?srcW_/2:srcW_;rgbPitch_=(size_t(packedWidth)*4+255)&~size_t(255);rgbTex_=makeTexture(context_.device(),packedWidth,srcH_,DXGI_FORMAT_R8G8B8A8_UNORM,false);if(!rgbTex_)return false;@@ -771,7 +807,8 @@ bool EnhanceGraph::createComputePasses()if(!residualPass_.loadShader("NrResidualComposite.dxil",cs)||!residualPass_.create(context_.device(),cs,4,3,1,24))return false;if(!flowAdaptPass_.loadShader("FlowAdapt.dxil",cs)||!flowAdaptPass_.create(context_.device(),cs,3,1,1))return false;if (!yuvPass_.loadShader("YuvToLinearRgb.dxil", cs) || !yuvPass_.create(context_.device(), cs, 8, 2, 1, 12)) return false;- if((desc_.rgbInput||desc_.yuy2Input)&&(!rgbPass_.loadShader(desc_.yuy2Input?"Yuy2ToLinear.dxil":"RgbToLinear.dxil",cs)||!rgbPass_.create(context_.device(),cs,8,1,1)))return false;+ const char* rgbShader=desc_.packedInput?"PackedCaptureToLinear.dxil":desc_.yuy2Input?"Yuy2ToLinear.dxil":"RgbToLinear.dxil";+ if((desc_.rgbInput||desc_.yuy2Input||desc_.packedInput)&&(!rgbPass_.loadShader(rgbShader,cs)||!rgbPass_.create(context_.device(),cs,8,1,1)))return false;if (!encPass_.loadShader("ParityEncode.dxil", cs) || !encPass_.create(context_.device(), cs, 8, 1, 1)) return false;if (!decPass_.loadShader("ParityDecode.dxil", cs) || !decPass_.create(context_.device(), cs, 8)) return false;if (!blitPass_.loadShader("ScaleBlit.dxil", cs) || !blitPass_.create(context_.device(), cs, 19, 1, 1)) return false;@@ -843,7 +880,7 @@ bool EnhanceGraph::createViews()stagedSrv(videoSrOutput_.Get(),DXGI_FORMAT_R8G8B8A8_UNORM,hdrVideoSrPass_,6);}// Immutable per-resource views.- if(desc_.rgbInput||desc_.yuy2Input){+ if(desc_.rgbInput||desc_.yuy2Input||desc_.packedInput){stagedSrv(rgbTex_.Get(),DXGI_FORMAT_R8G8B8A8_UNORM,rgbPass_,0);makeUav(context_.device(),srcRgba_.Get(),DXGI_FORMAT_R16G16B16A16_FLOAT,cpu(rgbPass_,1));}@@ -960,7 +997,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Framehdr10Output()?"PQ-BT2020-RGB10":desc_.hdrOutput?"scRGB-FP16":"sRGB-RGB8",desc_.hdrOutput?"none":"BT2390-luminance+neutral-ray-gamut-compression"));}- if (resolved.isHdrPath()&&(!desc_.hdrInput||desc_.rgbInput||desc_.yuy2Input)) {+ if (resolved.isHdrPath()&&(!desc_.hdrInput||desc_.rgbInput||desc_.yuy2Input||desc_.packedInput)) {veyra::log::error("graph", "HDR input requires an explicit YUV HDR contract; RGB/YUY2 HDR ingress is unsupported"); return false;}if(std::abs(ptsMs)>9e13){veyra::log::error("timeline","PTS outside representable range");return false;}@@ -1019,14 +1056,16 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, FramepreviousLuma_=std::move(sample);};- if(desc_.rgbInput||desc_.yuy2Input){- if(desc_.yuy2Input?frame->format!=AV_PIX_FMT_YUYV422:(frame->format!=AV_PIX_FMT_RGBA&&frame->format!=AV_PIX_FMT_BGRA&&frame->format!=AV_PIX_FMT_RGB0&&frame->format!=AV_PIX_FMT_BGR0)){- veyra::log::error("graph","direct RGB input contract requires packed RGBA/BGRA/RGB0/BGR0 frame");return false;+ if(desc_.rgbInput||desc_.yuy2Input||desc_.packedInput){+ const bool packed=desc_.packedInput!=0;+ if(packed?frame->format!=packedIngressFormat(desc_.packedInput):(desc_.yuy2Input?frame->format!=AV_PIX_FMT_YUYV422:(frame->format!=AV_PIX_FMT_RGBA&&frame->format!=AV_PIX_FMT_BGRA&&frame->format!=AV_PIX_FMT_RGB0&&frame->format!=AV_PIX_FMT_BGR0))){+ veyra::log::error("graph",std::format("direct capture input contract mismatch packing={} frameFormat={}",desc_.packedInput,int(frame->format)));return false;}- if(frame->width!=int(srcW_)||frame->height!=int(srcH_)||!frame->data[0]||std::abs(int64_t(frame->linesize[0]))<int64_t(srcW_)*(desc_.yuy2Input?2:4))return false;+ const unsigned ingressRowBytes=packed?packedIngressRowBytes(desc_.packedInput,srcW_):srcW_*(desc_.yuy2Input?2:4);+ if(frame->width!=int(srcW_)||frame->height!=int(srcH_)||!frame->data[0]||std::abs(int64_t(frame->linesize[0]))<int64_t(ingressRowBytes))return false;for(uint32_t y=0;y<srcH_;++y){auto* dst=mappedRgb_[parity]+y*rgbPitch_;const auto* src=frame->data[0]+ptrdiff_t(y)*frame->linesize[0];- if(desc_.yuy2Input||frame->format==AV_PIX_FMT_RGBA)std::memcpy(dst,src,size_t(srcW_)*(desc_.yuy2Input?2:4));+ if(packed||desc_.yuy2Input||frame->format==AV_PIX_FMT_RGBA)std::memcpy(dst,src,size_t(ingressRowBytes));else for(uint32_t x=0;x<srcW_;++x){const bool bgr=frame->format==AV_PIX_FMT_BGRA||frame->format==AV_PIX_FMT_BGR0;dst[x*4]=src[x*4+(bgr?2:0)];dst[x*4+1]=src[x*4+1];dst[x*4+2]=src[x*4+(bgr?0:2)];@@ -1037,15 +1076,17 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Framestd::vector<uint8_t> sample;sample.reserve(64*36);const bool bgr=frame->format==AV_PIX_FMT_BGRA||frame->format==AV_PIX_FMT_BGR0;for(unsigned y=0;y<36;++y)for(unsigned x=0;x<64;++x){- const auto* p=frame->data[0]+ptrdiff_t(y*srcH_/36)*frame->linesize[0]+(x*srcW_/64)*(desc_.yuy2Input?2:4);- sample.push_back(desc_.yuy2Input?p[0]:uint8_t((54*unsigned(p[bgr?2:0])+183*unsigned(p[1])+19*unsigned(p[bgr?0:2])+128)>>8));+ const unsigned sx=x*srcW_/64,sy=y*srcH_/36;+ if(packed)sample.push_back(packedIngressLuma(*frame,desc_.packedInput,sx,sy));+ else{const auto* p=frame->data[0]+ptrdiff_t(sy)*frame->linesize[0]+sx*(desc_.yuy2Input?2:4);+ sample.push_back(desc_.yuy2Input?p[0]:uint8_t((54*unsigned(p[bgr?2:0])+183*unsigned(p[1])+19*unsigned(p[bgr?0:2])+128)>>8));}}analyzeLuma(std::move(sample));}tracker_.transition(list,rgbTex_.Get(),D3D12_RESOURCE_STATE_COPY_DEST);D3D12_TEXTURE_COPY_LOCATION dst{},src{};dst.pResource=rgbTex_.Get();dst.Type=D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;src.pResource=upRgb_[parity].Get();src.Type=D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;- src.PlacedFootprint.Footprint={DXGI_FORMAT_R8G8B8A8_UNORM,desc_.yuy2Input?srcW_/2:srcW_,srcH_,1,UINT(rgbPitch_)};+ src.PlacedFootprint.Footprint={DXGI_FORMAT_R8G8B8A8_UNORM,packed?packedIngressTexels(desc_.packedInput,srcW_):desc_.yuy2Input?srcW_/2:srcW_,srcH_,1,UINT(rgbPitch_)};list->CopyTextureRegion(&dst,0,0,0,&src,nullptr);tracker_.transition(list,rgbTex_.Get(),D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);} else if (frame->format == AV_PIX_FMT_D3D12) {@@ -1153,9 +1194,9 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame// 2. YUV -> RGBA16F.tracker_.transition(list, srcRgba_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);- if(desc_.rgbInput||desc_.yuy2Input){+ if(desc_.rgbInput||desc_.yuy2Input||desc_.packedInput){const float c[8]={uintBits(srcW_),uintBits(srcH_),uintBits(workingTransferCode(resolved)),uintBits(resolved.range==ColorRange::Limited?1u:0u),- resolved.range==ColorRange::Full?0.0f:1.0f,resolved.matrix==YuvMatrix::BT2020NCL?2.0f:resolved.matrix==YuvMatrix::BT601?0.0f:1.0f,resolved.primaries==ColorPrimaries::BT2020?1.0f:0.0f,0};+ resolved.range==ColorRange::Full?0.0f:1.0f,resolved.matrix==YuvMatrix::BT2020NCL?2.0f:resolved.matrix==YuvMatrix::BT601?0.0f:1.0f,resolved.primaries==ColorPrimaries::BT2020?1.0f:0.0f,uintBits(desc_.packedInput)};rgbPass_.bind(list,c,gpuHandleOf(rgbPass_,0).ptr,gpuHandleOf(rgbPass_,1).ptr);list->Dispatch((srcW_+15)/16,(srcH_+15)/16,1);}else{diff --git a/src/source/CaptureCardSource.cpp b/src/source/CaptureCardSource.cppindex c12a3caa..cc5d5156 100644--- a/src/source/CaptureCardSource.cpp+++ b/src/source/CaptureCardSource.cpp@@ -146,6 +146,8 @@ struct CaptureCardSource::Impl:ISampleGrabberCB {// Video-pin allocator policy (0 auto, 1 minimum, 2 driver default); read// when the capture graph is built. See CaptureBuffer.h.unsigned bufferMode=0;+ // N1 diagnostic: legacy per-pixel CPU unpack instead of GPU unpack.+ bool cpuUnpack=false;// Manual capture flip; read by the DirectShow callback thread.std::atomic<bool> verticalFlip{false};std::unique_ptr<WasapiAudioInput> wasapi;@@ -256,6 +258,12 @@ void CaptureCardSource::setVerticalFlip(bool enabled){if(p.verticalFlip.exchange(enabled)==enabled)return;log::info("capture-flip",std::format("manual vertical flip={} (applies to the next sample; ingest only)",enabled?1:0));}+void CaptureCardSource::setCpuUnpack(bool enabled){+ auto& p=*p_;+ if(p.cpuUnpack==enabled)return;+ p.cpuUnpack=enabled;+ log::warn("capture-unpack",std::format("legacy CPU per-pixel unpack={} (diagnostic; takes effect on the next connect)",enabled?1:0));+}bool CaptureCardSource::setAudioGain(float gain){if(p_->wasapi){p_->wasapi->setGain(gain);return p_->wasapi->snapshot().available;}auto& p=*p_;if(p.audioSession){p.audioSession->setGain(gain);return p.audioSession->snapshot().available;}if(!p.graph||!p.audioFilter)return false;@@ -343,6 +351,7 @@ bool CaptureCardSource::configure(const SourceOpenDesc& desc){close();p_->lastAu}freeType(native);const bool layoutValid=SUCCEEDED(hr)&&captureMediaLayout(connected,p.layout);freeType(&connected,false);if(!layoutValid){log::error("capture",std::format("unsupported negotiated layout/connect failure hr=0x{:08X}",uint32_t(hr)));return false;}+ if(p.cpuUnpack&&captureLegacyCpuLayout(p.layout))log::warn("capture-unpack",std::format("legacy CPU unpack path active packing={} format={} (per-pixel conversion stays on the callback thread)",int(p.layout.packing),int(p.layout.format)));const unsigned colorOverride=selection.colorOverride;if(colorOverride>2)return false;if(colorOverride){diff --git a/tests/integration/CaptureFormatGpuCases.h b/tests/integration/CaptureFormatGpuCases.hindex 3b044b70..1c9862af 100644--- a/tests/integration/CaptureFormatGpuCases.h+++ b/tests/integration/CaptureFormatGpuCases.h@@ -27,16 +27,18 @@ inline int captureGpuCases(veyra::gfx::D3D12DeviceContext& ctx,veyra::gfx::CommaDXVA2_ExtendedFormat ext{};ext.NominalRange=full?DXVA2_NominalRange_0_255:DXVA2_NominalRange_16_235;ext.VideoTransferMatrix=DXVA2_VideoTransferMatrix_BT709;vi.dwControlFlags=ext.value|AMCONTROL_COLORINFO_PRESENT;AM_MEDIA_TYPE t{};t.majortype=MEDIATYPE_Video;t.subtype=id;t.formattype=FORMAT_VideoInfo2;t.pbFormat=reinterpret_cast<BYTE*>(&vi);t.cbFormat=sizeof(vi);CaptureMediaLayout l;if(!captureMediaLayout(t,l)){++failures;continue;}- const bool rgb=l.format==AV_PIX_FMT_BGR0,wide=l.format==AV_PIX_FMT_P010||l.format==AV_PIX_FMT_P016;const unsigned bits=l.format==AV_PIX_FMT_P016?16:wide?10:8;+ const bool rgbDib=l.format==AV_PIX_FMT_BGR0||l.format==AV_PIX_FMT_BGR24||l.format==AV_PIX_FMT_RGB555LE||l.format==AV_PIX_FMT_RGB565LE,wide=l.format==AV_PIX_FMT_P010||l.format==AV_PIX_FMT_P016;const unsigned bits=l.format==AV_PIX_FMT_P016?16:wide?10:8;// RGB bitfield tests use full range (unit tests cover channel masks).- if(rgb){l.color.range=pipeline::ColorRange::Full;}+ if(rgbDib){l.color.range=pipeline::ColorRange::Full;}std::vector<uint8_t> raw(l.sampleBytes,0);const unsigned max=bits==16?65535:bits==10?1023:255,black=full?0:16*(1u<<(bits-8)),white=full?max:235*(1u<<(bits-8));for(unsigned y=0;y<32;++y){auto* row=raw.data()+y*l.stride;for(unsigned x=0;x<64;++x){const unsigned code=x<16?black:x>=48?white:(wide?max/4+(x-16):black+(white-black)/2);- if(rgb){- const unsigned bytes=l.rowBytes/64;for(unsigned b=0;b<bytes;++b)row[x*bytes+b]=x<32?0:255;- }else if(l.format==AV_PIX_FMT_YUYV422){row[x*2]=uint8_t(code);row[x*2+1]=128;}+ if(l.format==AV_PIX_FMT_BGR0){for(unsigned b=0;b<3;++b)row[x*4+b]=x<32?0:255;row[x*4+3]=255;}+ else if(l.format==AV_PIX_FMT_BGR24){row[x*3]=row[x*3+1]=row[x*3+2]=x<32?0:255;}+ else if(l.format==AV_PIX_FMT_RGB555LE){const uint16_t v=x<32?0:0x7FFF;memcpy(row+x*2,&v,2);}+ else if(l.format==AV_PIX_FMT_RGB565LE){const uint16_t v=x<32?0:0xFFFF;memcpy(row+x*2,&v,2);}+ else if(l.format==AV_PIX_FMT_YUYV422||l.format==AV_PIX_FMT_UYVY422||l.format==AV_PIX_FMT_YVYU422){row[x*2]=uint8_t(code);row[x*2+1]=128;}else if(wide){const uint16_t v=uint16_t(bits==10?code<<6:code);memcpy(row+x*2,&v,2);}else row[x]=uint8_t(code);}@@ -44,7 +46,7 @@ inline int captureGpuCases(veyra::gfx::D3D12DeviceContext& ctx,veyra::gfx::Comma}if(l.planes>1)for(size_t i=size_t(l.stride)*32;i<raw.size();i+=wide?2:1){if(wide){raw[i]=0;raw[i+1]=128;}else raw[i]=128;}AVFrame* f=av_frame_alloc();f->width=64;f->height=32;f->format=l.format;bool ok=av_frame_get_buffer(f,32)>=0&©CaptureSample(l,raw.data(),raw.size(),*f);- pipeline::EnhanceGraph graph(ctx,ring);pipeline::EnhanceGraphDesc gd;gd.sourceWidth=gd.workWidth=64;gd.sourceHeight=gd.workHeight=32;gd.enableNr=gd.enableFg=gd.enableSr=false;gd.noFeatures=true;gd.rgbInput=rgb;gd.yuy2Input=l.format==AV_PIX_FMT_YUYV422;gd.captureBitDepth=bits;+ pipeline::EnhanceGraph graph(ctx,ring);pipeline::EnhanceGraphDesc gd;gd.sourceWidth=gd.workWidth=64;gd.sourceHeight=gd.workHeight=32;gd.enableNr=gd.enableFg=gd.enableSr=false;gd.noFeatures=true;gd.rgbInput=l.format==AV_PIX_FMT_BGR0;gd.yuy2Input=l.format==AV_PIX_FMT_YUYV422;gd.packedInput=pipeline::packedInputCode(l.color.pixelFormat);gd.captureBitDepth=bits;pipeline::EnhanceGraph::FrameOutputs out;std::vector<float> pixels;ok=ok&&graph.initialize(gd)&&graph.createViews()&&graph.process(f,0,true,out,1,&l.color)&&captureReadFp16(ctx,ring,graph.diagnosticLinearInput(),pixels);double error=0;if(ok){for(unsigned c=0;c<3;++c){error=std::max(error,std::abs(double(pixels[4*4+c])));error=std::max(error,std::abs(double(pixels[56*4+c])-1));}ok=error<.003;}diff --git a/tests/unit/CaptureFormatCases.h b/tests/unit/CaptureFormatCases.hindex 4b5989a4..585a7750 100644--- a/tests/unit/CaptureFormatCases.h+++ b/tests/unit/CaptureFormatCases.h@@ -25,10 +25,9 @@ template<class Check> void captureFormatCases(Check check){check(!copyCaptureSample(l,bytes.data(),bytes.size()-1,*f)&&f->data[0][0]==previous,"short sample rejected before writes");bytes[0]=1;bool exact=true;for(unsigned y=0;y<4;++y){const auto* s=bytes.data()+(l.bottomUp?3-y:y)*l.stride;const auto* d=f->data[0]+y*f->linesize[0];- if(l.packing==CapturePacking::Bgr24){for(unsigned x=0;x<4;++x)for(unsigned c=0;c<3;++c)exact&=d[x*4+c]==s[x*3+c];}- else if(l.packing==CapturePacking::Uyvy){for(unsigned x=0;x<8;x+=4)exact&=d[x]==s[x+1]&&d[x+1]==s[x]&&d[x+2]==s[x+3]&&d[x+3]==s[x+2];}- else if(l.packing==CapturePacking::Yvyu){for(unsigned x=0;x<8;x+=4)exact&=d[x]==s[x]&&d[x+1]==s[x+3]&&d[x+2]==s[x+2]&&d[x+3]==s[x+1];}- else if(l.packing!=CapturePacking::Rgb555&&l.packing!=CapturePacking::Rgb565)exact&=memcmp(d,s,l.rowBytes)==0;+ // N1: every packed capture format keeps the driver's bytes 1:1;+ // the GPU upload shader does the unpack, so rows compare raw.+ exact&=memcmp(d,s,l.rowBytes)==0;}for(unsigned p=1;p<l.planes;++p)for(unsigned y=0;y<2;++y){const auto* s=bytes.data()+(p==1?l.chromaOffset:l.secondChromaOffset)+y*l.chromaStride;const auto* d=f->data[p]+y*f->linesize[p];if(l.packing==CapturePacking::Nv21)for(unsigned x=0;x<l.chromaRowBytes;x+=2)exact&=d[x]==s[x+1]&&d[x+1]==s[x];else exact&=memcmp(d,s,l.chromaRowBytes)==0;}@@ -46,9 +45,19 @@ template<class Check> void captureFormatCases(Check check){t.subtype=fourcc("YV12");check(captureMediaLayout(t,l)&&l.chromaOffset==20&&l.secondChromaOffset==16,"YV12 V precedes U in incoming memory");for(const auto id:{MEDIASUBTYPE_RGB555,MEDIASUBTYPE_RGB565}){t.subtype=id;captureMediaLayout(t,l);std::vector<uint8_t> raw(l.sampleBytes,255);AVFrame* f=av_frame_alloc();f->width=4;f->height=4;f->format=l.format;av_frame_get_buffer(f,32);- check(copyCaptureSample(l,raw.data(),raw.size(),*f)&&f->data[0][0]==255&&f->data[0][1]==255&&f->data[0][2]==255,"RGB555/565 full-scale expands to white");+ check(copyCaptureSample(l,raw.data(),raw.size(),*f)&&f->data[0][0]==255&&f->data[0][1]==255,"RGB555/565 keep the driver's white word for the GPU unpack");for(unsigned y=0;y<4;++y){raw[y*l.stride]=0;raw[y*l.stride+1]=id==MEDIASUBTYPE_RGB565?0xf8:0x7c;}- check(copyCaptureSample(l,raw.data(),raw.size(),*f)&&f->data[0][0]==0&&f->data[0][1]==0&&f->data[0][2]==255,"RGB555/565 red channel masks");av_frame_free(&f);+ check(copyCaptureSample(l,raw.data(),raw.size(),*f)&&f->data[0][0]==0&&f->data[0][1]==(id==MEDIASUBTYPE_RGB565?0xf8:0x7c),"RGB555/565 red mask bytes are preserved for the GPU unpack");av_frame_free(&f);+ }+ // N1: the packed capture contract and the legacy CPU-unpack rollback.+ {+ vi.bmiHeader.biWidth=4;vi.bmiHeader.biHeight=4;vi.bmiHeader.biSizeImage=0;t.subtype=MEDIASUBTYPE_RGB565;+ CaptureMediaLayout packed;check(captureMediaLayout(t,packed)&&packed.format==AV_PIX_FMT_RGB565LE,"N1 keeps the driver packing in the frame contract");+ CaptureMediaLayout legacy=packed;check(captureLegacyCpuLayout(legacy)&&legacy.format==AV_PIX_FMT_BGR0,"legacy CPU-unpack maps RGB565 back to BGR0");+ std::vector<uint8_t> raw(legacy.sampleBytes,255);AVFrame* f=av_frame_alloc();f->width=4;f->height=4;f->format=legacy.format;av_frame_get_buffer(f,16);+ check(copyCaptureSample(legacy,raw.data(),raw.size(),*f)&&f->data[0][0]==255&&f->data[0][2]==255&&f->data[0][3]==255,"legacy CPU-unpack still expands RGB565 to opaque BGR0");av_frame_free(&f);+ t.subtype=fourcc("UYVY");CaptureMediaLayout uy;check(captureMediaLayout(t,uy)&&uy.format==AV_PIX_FMT_UYVY422,"N1 keeps UYVY packing in the frame contract");+ CaptureMediaLayout uyLegacy=uy;check(captureLegacyCpuLayout(uyLegacy)&&uyLegacy.format==AV_PIX_FMT_YUYV422,"legacy CPU-unpack maps UYVY back to YUY2");vi.bmiHeader.biWidth=4;}// Orientation contract: the DIB sign decides whether ingest flips, the// manual override inverts that decision, and planar chroma follows luma.diff --git a/tools/capture_color_probe/main.cpp b/tools/capture_color_probe/main.cppindex 3b51bc17..57bf2503 100644--- a/tools/capture_color_probe/main.cpp+++ b/tools/capture_color_probe/main.cpp@@ -30,6 +30,7 @@ int wmain(int argc,wchar_t**argv){gd.sourceWidth=gd.workWidth=info.width;gd.sourceHeight=gd.workHeight=info.height;gd.rgbInput=info.color.pixelFormat==pipeline::SourcePixelFormat::Bgra8;gd.yuy2Input=info.color.pixelFormat==pipeline::SourcePixelFormat::Yuy2;+ gd.packedInput=pipeline::packedInputCode(info.color.pixelFormat);gd.captureBitDepth=info.color.pixelFormat==pipeline::SourcePixelFormat::P010?10:info.color.pixelFormat==pipeline::SourcePixelFormat::P016?16:8;gd.enableNr=gd.enableFg=false;gd.noFeatures=true;const HWND window=CreateWindowExW(0,L"STATIC",L"Veyra color diagnostic",WS_POPUP,0,0,info.width,info.height,nullptr,nullptr,GetModuleHandleW(nullptr),nullptr);diff --git a/tools/capture_copy_bench/main.cpp b/tools/capture_copy_bench/main.cppnew file mode 100644index 00000000..5a67f6ad--- /dev/null+++ b/tools/capture_copy_bench/main.cpp@@ -0,0 +1,48 @@+// N1 microbenchmark: per-frame cost of the DirectShow callback copy for the+// 4K packed capture formats, with and without the legacy CPU per-pixel unpack.+// CPU only; no device or capture card required.+#include "veyra/source/CaptureMediaType.h"+#include <chrono>+#include <cstdio>+#include <vector>+extern "C" {+#include <libavutil/frame.h>+}+using namespace veyra::source;+namespace {+GUID fourcc(const char* n){+ return GUID{captureFourcc(n[0],n[1],n[2],n[3]),0,0x10,{0x80,0,0,0xaa,0,0x38,0x9b,0x71}};+}+double benchCopy(GUID id,bool legacy,int iterations){+ VIDEOINFOHEADER2 vi{};vi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);vi.bmiHeader.biWidth=3840;vi.bmiHeader.biHeight=2160;vi.AvgTimePerFrame=166667;+ AM_MEDIA_TYPE type{};type.majortype=MEDIATYPE_Video;type.subtype=id;type.formattype=FORMAT_VideoInfo2;type.pbFormat=reinterpret_cast<BYTE*>(&vi);type.cbFormat=sizeof(vi);+ CaptureMediaLayout layout;if(!captureMediaLayout(type,layout))return -1;+ if(legacy&&!captureLegacyCpuLayout(layout))return -1;+ AVFrame* frame=av_frame_alloc();frame->width=int(layout.width);frame->height=int(layout.height);frame->format=layout.format;+ if(av_frame_get_buffer(frame,32)<0){av_frame_free(&frame);return -1;}+ std::vector<uint8_t> source(layout.sampleBytes,7);+ for(int i=0;i<3;++i)copyCaptureSample(layout,source.data(),source.size(),*frame);+ const auto start=std::chrono::steady_clock::now();+ for(int i=0;i<iterations;++i)copyCaptureSample(layout,source.data(),source.size(),*frame);+ const auto elapsed=std::chrono::duration<double,std::milli>(std::chrono::steady_clock::now()-start).count();+ av_frame_free(&frame);+ return elapsed/iterations;+}+}+int wmain(){+ struct Case{const char* name;GUID id;};+ const Case cases[]={+ {"YUY2",fourcc("YUY2")},{"UYVY",fourcc("UYVY")},{"YVYU",fourcc("YVYU")},+ {"RGB24",MEDIASUBTYPE_RGB24},{"RGB32",MEDIASUBTYPE_RGB32},+ {"RGB555",MEDIASUBTYPE_RGB555},{"RGB565",MEDIASUBTYPE_RGB565},+ {"NV12",fourcc("NV12")}};+ constexpr int iterations=30;+ std::printf("capture copy benchmark 3840x2160, %d iterations/frame\n",iterations);+ for(const auto& item:cases){+ const double gpu=benchCopy(item.id,false,iterations);+ const double legacy=benchCopy(item.id,true,iterations);+ if(legacy>=0)std::printf("%-7s N1 row-copy %6.3f ms/frame legacy CPU-unpack %6.3f ms/frame\n",item.name,gpu,legacy);+ else std::printf("%-7s N1 row-copy %6.3f ms/frame\n",item.name,gpu);+ }+ return 0;+}