Skip to content

Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.

C++

fix: support common native capture formats and preserve high-bit-depth SDR

Veyra Goal Agentbb0470dd9886
diff --git a/docs/CAPTURE_FORMATS_PLAN_2026-09-14.md b/docs/CAPTURE_FORMATS_PLAN_2026-09-14.md
new file mode 100644
index 00000000..7f0d16b6
--- /dev/null
+++ b/docs/CAPTURE_FORMATS_PLAN_2026-09-14.md
@@ -0,0 +1,33 @@
+# 采集格式扩展与显示修复
+
+用户要求补齐P010、RGB24及其他常见未支持格式。本轮本地修复,不发布、不改变Smooth Motion或驱动设置。基线236228c,分支codex/capture-formats-20260914,存档checkpoint/capture-formats-20260914。
+
+## 实现
+
+- 统一格式名称/原生接入表:RGB24/32、ARGB32、RGB555/565、YUY2/UYVY/YVYU、NV12/NV21、I420/IYUV/YV12、P010/P016。
+- 保留驱动索引;GUID不冒充乱码,已知格式显示名称。原生支持、需系统解码/转换、布局不支持分别说明。
+- 直接接入有界mailbox;packed RGB/YUV仅重排字节,不经过系统颜色转换或降为4:2:0;平面格式正确处理stride、UV顺序、短包和上下翻转。
+- P010/P016以16位纹理进入共享图,位深与HDR标记分离,SDR不经8位中转。现有PS5 HDR契约不改;采集HDR元数据不完整时不猜PQ,默认SDR需在列表说明,明确不支持的颜色信息拒绝。此任务不声称采集HDR已完成。
+- 压缩MJPEG及系统解码回退保留,私有/调色板/复杂10位422等未实现格式不宣称原生支持。
+
+## 验证
+
+构建产品;合成样本验证逐字节重排、边界、plane offset、未知GUID回退及动态格式拒绝;GPU验证RGB/YUV/P010/P016范围及10位阶梯,复核既有PS5 HDR回归。单次测试上限300秒。反馈者Live Gamer Ultra 2.1不在本机,真实设备仍由反馈者验收。结果和命令在本文件与WORKLOG补录。
+
+## 已完成与证据
+
+原生格式共15项(含原有三项):RGB24/RGB32/ARGB32/RGB555/RGB565、YUY2/UYVY/YVYU、NV12/NV21、I420/IYUV/YV12、P010/P016。统一CapturePixelFormat名称与packing,CaptureMediaType解析/复制,CaptureCardSource直接连接;RGB/YUV422重排为现有BGR0/YUY2内存合同,未颜色降采样。EnhanceGraphDesc.captureBitDepth与hdrInput分离,P010/P016在R16/R16G16纹理转换为FP16工作颜色;P016输入不是承诺16位最终显示,SDR最终显示仍为现有8位输出。
+
+P010/P016列表明确为SDR,缺少色彩元数据沿用有日志的SDR假设;已知但无法识别的颜色元数据拒绝,不隐式转RGB32掩盖。采集HDR、私有格式、调色板、Y210/P210等复杂格式未宣称原生支持;MJPEG和未知格式的系统解码/转换仍取决于系统filter。文件与PS5的原有HDR边界未全局修改。
+
+修改文件:include/veyra/source/CapturePixelFormat.h、CaptureMediaType.h,src/source/CaptureCardSource.cpp;include/veyra/pipeline/{FramePacket,ColorMetadata,EnhanceGraph}.h、src/pipeline/EnhanceGraph.cpp、src/engine/EngineController.cpp、shaders/YuvToLinearRgb.hlsl;相应CaptureFormatCases、CaptureColorContractTests、CaptureFormatGpuCases、HdrColorTests、CaptureSourceTests及capture_color_probe。诊断工具按实际plane/rowBytes导出,避免高位深样本被旧的4字节假设越界读取。测试专用FP16只读访问器无正常播放readback。
+
+- `cmd.exe /c out\gpu-dis-build-all.cmd`:首次159步构建遇到运行中veyra.exe占用导致LNK1104;用户关闭后完整62步重建通过,最后诊断工具4步增量通过。另有测试头缺少iostream导致编译失败,补include后通过;记录build.log/build2.log/build3.log/build-final.log。
+- `powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/run-short-test.ps1 -Exe out/remoteplay/product-repair/veyra_capture_color_tests.exe -Arguments contract -TimeoutSeconds 30 -LogPrefix logs/capture-formats-20260914/layout`:127 PASS,0 failures。首次未传Arguments触发现有runner空ArgumentList错误,未执行测试;本次传入测试不使用的contract参数,未修改runner。
+- `veyra_hdr_color_tests.exe`(Start-Process Hidden,WaitForExit上限120秒,无参数):30组采集GPU范围/精度检查和8组既有HDR检查全部通过,耗时约1.4秒。gpu2.stdout.log。首次测试误拿8位呈现资源当FP16资源,测试拒绝格式;改为读取真实FP16 ingress纹理、显式NON_PIXEL_SHADER_RESOURCE往返barrier后通过,保留gpu.stdout.log失败记录,未放宽精度断言。
+- `powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/gates/delivery.ps1 -Root . -BuildDirectory out/remoteplay/product-repair`:23/23 PASS,56.2209961秒;logs/delivery/544cd7222e404abcb7a760a63f1c546c/result.json。真实RTX5070执行NR Feature18 Create=0x1、handle非空、seh=0,原生4K NR Evaluate=12;播放器、控制、H.264/HEVC导出和取消回归通过。
+- 真实本机USB3 Video:`veyra_capture_tests.exe --list`枚举成功;`capture:0:0:-1`原生YUY2 1080p60 SetFormat/ConnectDirect=0,Run=0x800705AA,exit4,未通过。现场OBS正在运行,但没有证明其占用了设备,不断言根因。未复测反馈者Live Gamer Ultra 2.1,不把合成测试当实卡成功。旧probe控制台编码会损失中文,GUI使用wstring并无该转码;名称映射已由单元测试核对。
+
+所有日志位于logs/capture-formats-20260914。桌面快捷方式所指out/remoteplay/product-repair/veyra.exe已更新,版本资源仍为1.0.2,EXE SHA256 B62CA082176CE02D690D302236BEBC86ABD557CA18243CDD2000E21645A49BCC。avcodec仍为0710F0D87A7FFCC9F998F1A35D0500345F6C66EB9A5A39C51D60D293142BD84F。未改运行DLL、未push、未修改GitHub 1.0.2资产。下一步反馈者以P010 SDR/RGB24验证实卡。
+
+布局依据:[Microsoft RGB subtypes](https://learn.microsoft.com/en-us/windows/win32/directshow/uncompressed-rgb-video-subtypes)、[10/16-bit YUV](https://learn.microsoft.com/en-us/windows/win32/medfound/10-bit-and-16-bit-yuv-video-formats)、[8-bit YUV](https://learn.microsoft.com/en-us/windows/win32/medfound/recommended-8-bit-yuv-formats-for-video-rendering)。独立实现,未复制第三方项目代码。
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index 455ded93..b557ed5c 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -1900,3 +1900,11 @@ GitHub Release https://github.com/Likely7/Veyra-NRVideo/releases/tag/v1.0.0 于
七运行文件和patched FFmpeg不变;便携/两对应源码ZIP及SHA256共六资产,逐文件和源码排除检查通过,未放入SDK/用户媒体/凭据。更新双语README及Release Notes、组件和构建说明。详见docs/RELEASE_1.0.2_EXECUTION.md,证据logs/release-1.0.2。软件恢复改善不等于无线故障根治。
发布完成:main与v1.0.2(09c054c)已推送至nrvideo。六资产全部uploaded,服务端字节数及SHA256逐项匹配;2026-09-13T15:32:29Z正式公开为latest,非草稿/非预发布,Release ID 387942841,API复核通过。地址https://github.com/Likely7/Veyra-NRVideo/releases/tag/v1.0.2 。发布后只追加本记录,不移动标签、不修改旧资产。桌面快捷方式所指EXE已为1.0.2;下一步用户长时游玩验收。
+
+## 2026-09-14 采集格式名称与原生格式扩展(本地)
+
+用户要求修复P010/RGB24显示GUID并补齐常见格式。基线236228c,分支codex/capture-formats-20260914,checkpoint/capture-formats-20260914。原生格式从YUY2/NV12/RGB32扩至15项,包含RGB24/ARGB32/RGB555/565、UYVY/YVYU、NV21/I420/IYUV/YV12、P010/P016;按内存布局重排并保留高位深,独立于HDR开关,不全局放开采集HDR。名称、布局、色彩不支持和系统转换路径明确区分。
+
+构建曾因正在运行的EXE占用失败,用户关闭后62步及最终4步增量通过。127项布局/边界、30组GPU采集颜色/精度、8组既有HDR回归通过;GPU测试最初误选8位呈现资源,改取真实FP16 ingress后通过,失败日志保留。delivery 23/23、56.2209961秒,logs/delivery/544cd7222e404abcb7a760a63f1c546c/result.json;RTX5070原生4K NR Create=0x1/SEH0/Evaluate12。具体命令、文件与失败见docs/CAPTURE_FORMATS_PLAN_2026-09-14.md及logs/capture-formats-20260914。
+
+本机USB3 Video枚举/SetFormat/ConnectDirect成功,Run返回0x800705AA资源不足,未算实卡通过;当时OBS运行,未证明占用原因。反馈者Live Gamer Ultra 2.1不在本机。桌面EXE已更新,资源版本仍1.0.2、SHA256 B62CA082176CE02D690D302236BEBC86ABD557CA18243CDD2000E21645A49BCC,patched FFmpeg不变。源码不含SDK/二进制/日志/凭据,未发布;下一步反馈者新版实卡验收。用户正在剪辑,后续Smooth Motion本轮只写方案,不再跑GPU测试。
\ No newline at end of file
diff --git a/include/veyra/pipeline/ColorMetadata.h b/include/veyra/pipeline/ColorMetadata.h
index 6abbb6d3..92418b01 100644
--- a/include/veyra/pipeline/ColorMetadata.h
+++ b/include/veyra/pipeline/ColorMetadata.h
@@ -18,6 +18,7 @@ inline ColorDescription resolveFrameColor(const AVFrame& frame,ColorDescription
}
switch(frame.format){
case AV_PIX_FMT_NV12:c.pixelFormat=SourcePixelFormat::NV12;break;
+ case AV_PIX_FMT_P016:c.pixelFormat=SourcePixelFormat::P016;break;
case AV_PIX_FMT_YUV420P10LE:case AV_PIX_FMT_P010:c.pixelFormat=SourcePixelFormat::P010;break;
case AV_PIX_FMT_YUV420P:case AV_PIX_FMT_YUVJ420P:c.pixelFormat=SourcePixelFormat::Yuv420P;break;
case AV_PIX_FMT_YUYV422:c.pixelFormat=SourcePixelFormat::Yuy2;break;
diff --git a/include/veyra/pipeline/EnhanceGraph.h b/include/veyra/pipeline/EnhanceGraph.h
index 2ceb045c..6df5d74c 100644
--- a/include/veyra/pipeline/EnhanceGraph.h
+++ b/include/veyra/pipeline/EnhanceGraph.h
@@ -69,6 +69,8 @@ struct EnhanceGraphDesc {
bool noFeatures = false; // VEYRA_NO_FEATURES: NVOF/NGX objects skipped
bool noNgx = false; // VEYRA_NO_NGX: core/features skipped, NVOF only
bool hdrInput = false; // PS5 Main10 ingress; explicit SDR mapping unless hdrOutput.
+ unsigned captureBitDepth = 8; // SDR P010/P016 storage, independent of HDR transfer.
+ bool wideYuvInput() const { return hdrInput || captureBitDepth > 8; }
bool hdrOutput = false; // Native scRGB passthrough, no SDR-only enhancement.
bool highQualityPresentation = false; // PS5 ordinary scaling, no AI SR
bool rgbInput = false; // allocate direct RGBA ingestion before NGX creation
@@ -201,6 +203,8 @@ public:
// Guidance outputs (quality statistics; diagnostic readback only).
ID3D12Resource* flowResource() const { return flowTex_.Get(); }
ID3D12Resource* confidenceResource() const { return confTex_.Get(); }
+ // Test-only borrowed ingress output. Read after process, restore NON_PIXEL_SHADER_RESOURCE.
+ ID3D12Resource* diagnosticLinearInput() const { return srcRgba_.Get(); }
// Isolated diagnostics only: existing constant guidance, borrowed lifetime.
// A caller writing before the first real frame must restore COMMON state.
ID3D12Resource* diagnosticDepthResource(bool frameGeneration) const { return frameGeneration?depthTex_.Get():nrZeroDepth_.Get(); }
diff --git a/include/veyra/pipeline/FramePacket.h b/include/veyra/pipeline/FramePacket.h
index 24fba83d..08164ce6 100644
--- a/include/veyra/pipeline/FramePacket.h
+++ b/include/veyra/pipeline/FramePacket.h
@@ -64,6 +64,7 @@ enum class SourcePixelFormat : uint8_t {
Yuy2, // packed capture format
Bgra8, // 8-bit BGRA
Rgba16F, // canonical linear working format
+ P016, // 16-bit capture storage; does not imply HDR transfer
};
enum class ColorRange : uint8_t { Unknown = 0, Limited, Full };
diff --git a/include/veyra/source/CaptureMediaType.h b/include/veyra/source/CaptureMediaType.h
index db73a99a..96ca9875 100644
--- a/include/veyra/source/CaptureMediaType.h
+++ b/include/veyra/source/CaptureMediaType.h
@@ -1,5 +1,6 @@
#pragma once
#include "veyra/pipeline/ColorMetadata.h"
+#include "veyra/source/CapturePixelFormat.h"
#include <windows.h>
#include <dshow.h>
#include <dvdmedia.h>
@@ -17,6 +18,9 @@ struct CaptureMediaLayout {
AVPixelFormat format=AV_PIX_FMT_NONE;
REFERENCE_TIME duration=0;
pipeline::ColorDescription color;
+ CapturePacking packing=CapturePacking::Unknown;
+ unsigned planes=1,chromaStride=0,chromaRowBytes=0;
+ size_t chromaOffset=0,secondChromaOffset=0;
};
// Parse negotiated memory layout, not the UI's requested dimensions. YUV is
// top-down for either sign of biHeight; only RGB DIBs use bottom-up storage.
@@ -31,19 +35,40 @@ inline bool captureMediaLayout(const AM_MEDIA_TYPE& type,CaptureMediaLayout& out
const auto height=std::abs(int64_t(bm.biHeight));
if(bm.biWidth<=0||bm.biWidth>3840||height<1||height>2160)return false;
out.width=unsigned(bm.biWidth);out.height=unsigned(height);
- if(type.subtype==MEDIASUBTYPE_YUY2){if(out.width%2)return false;out.format=AV_PIX_FMT_YUYV422;out.rowBytes=out.width*2;}
- else if(type.subtype==MEDIASUBTYPE_NV12){if(out.width%2||out.height%2)return false;out.format=AV_PIX_FMT_NV12;out.rowBytes=out.width;}
- else if(type.subtype==MEDIASUBTYPE_RGB32){out.format=AV_PIX_FMT_BGR0;out.rowBytes=out.width*4;out.bottomUp=bm.biHeight>0;}
- else return false;
- const unsigned rows=out.format==AV_PIX_FMT_NV12?out.height*3/2:out.height;
+ out.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;
+ 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;
+ out.planes=(out.packing==CapturePacking::I420||out.packing==CapturePacking::Yv12)?3:2;
+ out.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.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;
out.stride=out.rowBytes;
+ if(out.format==AV_PIX_FMT_BGR0)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.rowBytes)return false;
+ 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((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){
+ out.chromaStride=out.planes==3?out.stride/2:out.stride;
+ out.chromaRowBytes=out.planes==3?out.width/2:out.rowBytes;
+ out.chromaOffset=size_t(out.stride)*out.height;
+ out.secondChromaOffset=out.chromaOffset+size_t(out.chromaStride)*(out.height/2);
+ if(out.packing==CapturePacking::Yv12)std::swap(out.chromaOffset,out.secondChromaOffset);
+ }
if(out.sampleBytes>size_t(std::numeric_limits<LONG>::max()))return false;
AVFrame frame{};frame.format=out.format;frame.width=int(out.width);frame.height=int(out.height);
out.color=pipeline::resolveFrameColor(frame);
@@ -67,14 +92,29 @@ inline bool captureMediaLayout(const AM_MEDIA_TYPE& type,CaptureMediaLayout& out
}
inline bool copyCaptureSample(const CaptureMediaLayout& layout,const uint8_t* src,size_t bytes,AVFrame& dst){
if(!src||bytes<layout.sampleBytes||dst.format!=layout.format||dst.width!=int(layout.width)||dst.height!=int(layout.height)||!dst.data[0]||dst.linesize[0]<int(layout.rowBytes))return false;
- if(layout.format==AV_PIX_FMT_NV12&&(!dst.data[1]||dst.linesize[1]<int(layout.width)))return false;
- for(unsigned y=0;y<layout.height;++y)std::memcpy(dst.data[0]+ptrdiff_t(y)*dst.linesize[0],src+size_t(layout.bottomUp?layout.height-1-y:y)*layout.stride,layout.rowBytes);
- if(layout.format==AV_PIX_FMT_NV12)for(unsigned y=0;y<layout.height/2;++y)std::memcpy(dst.data[1]+ptrdiff_t(y)*dst.linesize[1],src+size_t(layout.height+y)*layout.stride,layout.width);
+ if(layout.format==AV_PIX_FMT_BGR0&&dst.linesize[0]<int(layout.width*4))return false;
+ if(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;
+ for(unsigned y=0;y<layout.height;++y){
+ const auto* s=src+size_t(layout.bottomUp?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){
+ 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){
+ 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);
+ }
+ for(unsigned p=1;p<layout.planes;++p)for(unsigned y=0;y<layout.height/2;++y){
+ const auto* s=src+(p==1?layout.chromaOffset:layout.secondChromaOffset)+size_t(y)*layout.chromaStride;auto* d=dst.data[p]+ptrdiff_t(y)*dst.linesize[p];
+ if(layout.packing==CapturePacking::Nv21){for(unsigned x=0;x<layout.chromaRowBytes;x+=2){d[x]=s[x+1];d[x+1]=s[x];}}
+ else std::memcpy(d,s,layout.chromaRowBytes);
+ }
return true;
}
inline bool equivalentCaptureTypes(const AM_MEDIA_TYPE& a,const AM_MEDIA_TYPE& b){
CaptureMediaLayout x,y;if(!captureMediaLayout(a,x)||!captureMediaLayout(b,y))return false;
- return x.format==y.format&&x.width==y.width&&x.height==y.height&&x.stride==y.stride&&x.bottomUp==y.bottomUp&&x.duration==y.duration&&
+ return x.packing==y.packing&&x.format==y.format&&x.width==y.width&&x.height==y.height&&x.stride==y.stride&&x.bottomUp==y.bottomUp&&x.duration==y.duration&&
x.color.range==y.color.range&&x.color.matrix==y.color.matrix&&x.color.transfer==y.color.transfer&&
x.color.rangeAssumed==y.color.rangeAssumed&&x.color.matrixAssumed==y.color.matrixAssumed&&x.color.transferAssumed==y.color.transferAssumed;
}
diff --git a/include/veyra/source/CapturePixelFormat.h b/include/veyra/source/CapturePixelFormat.h
new file mode 100644
index 00000000..793bbaa6
--- /dev/null
+++ b/include/veyra/source/CapturePixelFormat.h
@@ -0,0 +1,42 @@
+#pragma once
+#include <cstdint>
+#include <windows.h>
+#include <dshow.h>
+#include <string>
+#include <format>
+
+namespace veyra::source {
+enum class CapturePacking { Unknown, Yuy2, Uyvy, Yvyu, Nv12, Nv21, I420, Yv12, P010, P016, Bgr32, Bgra32, Bgr24, Rgb555, Rgb565 };
+constexpr DWORD captureFourcc(char a,char b,char c,char d){return DWORD(uint8_t(a))|(DWORD(uint8_t(b))<<8)|(DWORD(uint8_t(c))<<16)|(DWORD(uint8_t(d))<<24);}
+inline bool captureIsFourcc(const GUID& id,DWORD code){
+ const GUID expected{code,0,0x10,{0x80,0,0,0xaa,0,0x38,0x9b,0x71}};return id==expected;
+}
+inline CapturePacking capturePacking(const GUID& id){
+ if(id==MEDIASUBTYPE_RGB32)return CapturePacking::Bgr32;
+ if(id==MEDIASUBTYPE_ARGB32)return CapturePacking::Bgra32;
+ if(id==MEDIASUBTYPE_RGB24)return CapturePacking::Bgr24;
+ if(id==MEDIASUBTYPE_RGB555)return CapturePacking::Rgb555;
+ if(id==MEDIASUBTYPE_RGB565)return CapturePacking::Rgb565;
+ struct Entry{DWORD code;CapturePacking packing;};
+ static constexpr Entry entries[]={
+ {captureFourcc('Y','U','Y','2'),CapturePacking::Yuy2},{captureFourcc('U','Y','V','Y'),CapturePacking::Uyvy},
+ {captureFourcc('Y','V','Y','U'),CapturePacking::Yvyu},{captureFourcc('N','V','1','2'),CapturePacking::Nv12},
+ {captureFourcc('N','V','2','1'),CapturePacking::Nv21},{captureFourcc('I','4','2','0'),CapturePacking::I420},
+ {captureFourcc('I','Y','U','V'),CapturePacking::I420},{captureFourcc('Y','V','1','2'),CapturePacking::Yv12},
+ {captureFourcc('P','0','1','0'),CapturePacking::P010},{captureFourcc('P','0','1','6'),CapturePacking::P016}};
+ for(const auto& e:entries)if(captureIsFourcc(id,e.code))return e.packing;
+ return CapturePacking::Unknown;
+}
+inline std::wstring capturePixelName(const GUID& id){
+ if(id==MEDIASUBTYPE_RGB32)return L"RGB32";
+ if(id==MEDIASUBTYPE_ARGB32)return L"ARGB32";
+ if(id==MEDIASUBTYPE_RGB24)return L"RGB24";
+ if(id==MEDIASUBTYPE_RGB555)return L"RGB555";
+ if(id==MEDIASUBTYPE_RGB565)return L"RGB565";
+ if(id==MEDIASUBTYPE_MJPG)return L"MJPEG";
+ if(captureIsFourcc(id,id.Data1)){
+ std::wstring name;for(unsigned i=0;i<4;++i){const unsigned ch=(id.Data1>>(8*i))&255;if(ch<32||ch>126){name.clear();break;}name+=wchar_t(ch);}if(!name.empty())return name;
+ }
+ wchar_t guid[40]{};StringFromGUID2(id,guid,40);return std::format(L"未知格式 {}",guid);
+}
+}
diff --git a/shaders/YuvToLinearRgb.hlsl b/shaders/YuvToLinearRgb.hlsl
index 1a3fcdfd..d5f6d64f 100644
--- a/shaders/YuvToLinearRgb.hlsl
+++ b/shaders/YuvToLinearRgb.hlsl
@@ -26,11 +26,11 @@ float3 YuvToRgb(float y, float2 uv)
{
// P010 is stored as 10 significant HIGH bits in 16-bit UNORM. Its
// normalization is not 8-bit /255: decode legal code values explicitly.
- bool ten=colorParams0.w>0.5;
- float scale=ten?65535.0/64.0:255.0;
- float black=ten?64.0:16.0,white=ten?940.0:235.0;
- float middle=ten?512.0:128.0,span=ten?896.0:224.0;
- float maximum=ten?1023.0:255.0;
+ bool sixteen=colorParams0.w>1.5,ten=colorParams0.w>0.5;
+ float scale=sixteen?65535.0:ten?65535.0/64.0:255.0;
+ float black=sixteen?4096.0:ten?64.0:16.0,white=sixteen?60160.0:ten?940.0:235.0;
+ float middle=sixteen?32768.0:ten?512.0:128.0,span=sixteen?57344.0:ten?896.0:224.0;
+ float maximum=sixteen?65535.0:ten?1023.0:255.0;
float yy=colorParams0.x>0.5?(y*scale-black)/(white-black):y*scale/maximum;
yy=saturate(yy);
float uu=(uv.x*scale-middle)/(colorParams0.x>0.5?span:maximum);
diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cpp
index 8dedcc7c..03a93e11 100644
--- a/src/engine/EngineController.cpp
+++ b/src/engine/EngineController.cpp
@@ -184,6 +184,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
pipeline::EnhanceGraphDesc gd;gd.sourceWidth=width;gd.sourceHeight=height;gd.hdrInput=isRemote&&activeSource->info().color.isHdrPath();
gd.highQualityPresentation=isRemote&&activeSource->info().color.reconstructChroma;
gd.rgbInput=isImage||(isCapture&&activeSource->info().color.pixelFormat==pipeline::SourcePixelFormat::Bgra8);
+ if(physicalCapture)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;
const auto resolution=pipeline::ResolutionPlan::make({width,height},options.sr,options.realtime?pipeline::NrSizePolicy::Realtime:pipeline::NrSizePolicy::Native,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;
diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cpp
index c64fc85d..8552a791 100644
--- a/src/pipeline/EnhanceGraph.cpp
+++ b/src/pipeline/EnhanceGraph.cpp
@@ -103,7 +103,7 @@ bool EnhanceGraph::initialize(const EnhanceGraphDesc& desc)
}
Status st = Status::Ok;
- lumaPitch_ = (static_cast<size_t>(srcW_)*(desc_.hdrInput?2:1) + 255) & ~size_t(255);
+ lumaPitch_ = (static_cast<size_t>(srcW_)*(desc_.wideYuvInput()?2:1) + 255) & ~size_t(255);
chromaPitch_ = lumaPitch_;
lumaSize_ = lumaPitch_ * srcH_;
chromaSize_ = chromaPitch_ * ((srcH_ + 1) / 2);
@@ -152,8 +152,8 @@ bool EnhanceGraph::createResources()
upDepth_ = makeUploadBuffer(context_.device(), dPitch_ * workH_);
upZeroDepth_ = makeUploadBuffer(context_.device(), dPitch_ * workH_);
upZeroMotion_ = makeUploadBuffer(context_.device(), dPitch_ * workH_);
- lumaTex_ = makeTexture(context_.device(), srcW_, srcH_, desc_.hdrInput?DXGI_FORMAT_R16_UNORM:DXGI_FORMAT_R8_UNORM, true);
- chromaTex_ = makeTexture(context_.device(), (srcW_+1) / 2, (srcH_+1) / 2, desc_.hdrInput?DXGI_FORMAT_R16G16_UNORM:DXGI_FORMAT_R8G8_UNORM, true);
+ 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_;
@@ -587,8 +587,8 @@ bool EnhanceGraph::createViews()
stagedSrv(rgbTex_.Get(),DXGI_FORMAT_R8G8B8A8_UNORM,rgbPass_,0);
makeUav(context_.device(),srcRgba_.Get(),DXGI_FORMAT_R16G16B16A16_FLOAT,cpu(rgbPass_,1));
}
- if (viewsTex) stagedSrv(lumaTex_.Get(), desc_.hdrInput?DXGI_FORMAT_R16_UNORM:DXGI_FORMAT_R8_UNORM, yuvPass_, 0);
- if (viewsTex) stagedSrv(chromaTex_.Get(), desc_.hdrInput?DXGI_FORMAT_R16G16_UNORM:DXGI_FORMAT_R8G8_UNORM, yuvPass_, 1);
+ if (viewsTex) stagedSrv(lumaTex_.Get(), desc_.wideYuvInput()?DXGI_FORMAT_R16_UNORM:DXGI_FORMAT_R8_UNORM, yuvPass_, 0);
+ if (viewsTex) stagedSrv(chromaTex_.Get(), desc_.wideYuvInput()?DXGI_FORMAT_R16G16_UNORM:DXGI_FORMAT_R8G8_UNORM, yuvPass_, 1);
if (viewsUav) makeUav(context_.device(), srcRgba_.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, cpu(yuvPass_, 2));
if (viewsTex) stagedSrv(nrInput_.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, encPass_, 0);
if (viewsUav) makeUav(context_.device(), proxyTex_.Get(), DXGI_FORMAT_R8G8B8A8_UNORM, cpu(encPass_, 1));
@@ -596,8 +596,8 @@ bool EnhanceGraph::createViews()
if (viewsTex) stagedSrv(proxyTex_.Get(), DXGI_FORMAT_R8G8B8A8_UNORM, decPass_, 1);
if (viewsTex) stagedSrv(neuralTex_.Get(), DXGI_FORMAT_R8G8B8A8_UNORM, decPass_, 2);
if (viewsUav) makeUav(context_.device(), finalRgba_.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, cpu(decPass_, 3));
- if (viewsUav) makeUav(context_.device(), lumaTex_.Get(), desc_.hdrInput?DXGI_FORMAT_R16_UNORM:DXGI_FORMAT_R8_UNORM, cpu(uploadPass_, 2));
- if (viewsUav) makeUav(context_.device(), chromaTex_.Get(), desc_.hdrInput?DXGI_FORMAT_R16G16_UNORM:DXGI_FORMAT_R8G8_UNORM, cpu(uploadPass_, 3));
+ if (viewsUav) makeUav(context_.device(), lumaTex_.Get(), desc_.wideYuvInput()?DXGI_FORMAT_R16_UNORM:DXGI_FORMAT_R8_UNORM, cpu(uploadPass_, 2));
+ if (viewsUav) makeUav(context_.device(), chromaTex_.Get(), desc_.wideYuvInput()?DXGI_FORMAT_R16G16_UNORM:DXGI_FORMAT_R8G8_UNORM, cpu(uploadPass_, 3));
// Software NV12 ingestion uses plane copies; no raw-SRV dispatch.
// Blit pass layout (all static; per-use offsets chosen at bind time):
// 0: srcRgba SRV 1: workRgba UAV (SR bypass / NR-off blit)
@@ -834,7 +834,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
} else {
nv12Ctx_ = sws_getCachedContext(nv12Ctx_, frame->width, frame->height,
static_cast<AVPixelFormat>(frame->format),
- frame->width, frame->height, desc_.hdrInput?AV_PIX_FMT_P010:AV_PIX_FMT_NV12, SWS_POINT,
+ frame->width, frame->height, desc_.captureBitDepth==16?AV_PIX_FMT_P016:desc_.wideYuvInput()?AV_PIX_FMT_P010:AV_PIX_FMT_NV12, SWS_POINT,
nullptr, nullptr, nullptr);
if (nv12Ctx_ == nullptr) { veyra::log::error("graph", "sws"); return false; }
const int colorSpace=resolved.matrix==YuvMatrix::BT2020NCL?SWS_CS_BT2020:resolved.matrix==YuvMatrix::BT601?SWS_CS_ITU601:SWS_CS_ITU709;
@@ -844,17 +844,17 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
// Planar 8-bit YUV already exposes CPU luma for cadence analysis.
// Convert directly into the fenced upload slot instead of writing and
// copying another full NV12 frame. Never sample write-combined memory.
- const bool directUpload=!desc_.hdrInput&&(frame->format==AV_PIX_FMT_YUV420P||frame->format==AV_PIX_FMT_YUVJ420P||frame->format==AV_PIX_FMT_NV12);
+ const bool directUpload=!desc_.wideYuvInput()&&(frame->format==AV_PIX_FMT_YUV420P||frame->format==AV_PIX_FMT_YUVJ420P||frame->format==AV_PIX_FMT_NV12);
uint8_t* planes[4] = { directUpload?mappedLuma_[parity]:nv12Buf_.data(), directUpload?mappedChroma_[parity]:nv12Buf_.data() + lumaSize_ };
const int strides[4] = { static_cast<int>(lumaPitch_), static_cast<int>(chromaPitch_) };
if(sws_scale(nv12Ctx_, frame->data, frame->linesize, 0, frame->height, planes, strides)!=frame->height){veyra::log::error("color","Software plane conversion failed");return false;}
std::vector<uint8_t> sample;sample.reserve(64*36);
- for(unsigned y=0;y<36;++y)for(unsigned x=0;x<64;++x){const uint8_t v=directUpload?frame->data[0][ptrdiff_t(y*srcH_/36)*frame->linesize[0]+x*srcW_/64]:planes[0][size_t(y*srcH_/36)*lumaPitch_+(x*srcW_/64)*(desc_.hdrInput?2:1)+(desc_.hdrInput?1:0)];sample.push_back(v);}
+ for(unsigned y=0;y<36;++y)for(unsigned x=0;x<64;++x){const uint8_t v=directUpload?frame->data[0][ptrdiff_t(y*srcH_/36)*frame->linesize[0]+x*srcW_/64]:planes[0][size_t(y*srcH_/36)*lumaPitch_+(x*srcW_/64)*(desc_.wideYuvInput()?2:1)+(desc_.wideYuvInput()?1:0)];sample.push_back(v);}
analyzeLuma(std::move(sample));
if(!directUpload){for (uint32_t y = 0; y < srcH_; ++y)
- std::memcpy(mappedLuma_[parity] + y * lumaPitch_, planes[0] + y * lumaPitch_, srcW_*(desc_.hdrInput?2:1));
+ std::memcpy(mappedLuma_[parity] + y * lumaPitch_, planes[0] + y * lumaPitch_, srcW_*(desc_.wideYuvInput()?2:1));
for (uint32_t y = 0; y < (srcH_+1) / 2; ++y)
- std::memcpy(mappedChroma_[parity] + y * chromaPitch_, planes[1] + y * chromaPitch_, ((srcW_+1)/2)*(desc_.hdrInput?4:2));}
+ std::memcpy(mappedChroma_[parity] + y * chromaPitch_, planes[1] + y * chromaPitch_, ((srcW_+1)/2)*(desc_.wideYuvInput()?4:2));}
auto copyPlane = [&](ID3D12Resource* texture, ID3D12Resource* upload,
DXGI_FORMAT format, UINT width, UINT height, UINT pitch) {
tracker_.transition(list, texture, D3D12_RESOURCE_STATE_COPY_DEST);
@@ -866,9 +866,9 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
src.PlacedFootprint.Footprint = {format, width, height, 1, pitch};
list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
};
- copyPlane(lumaTex_.Get(), upLuma_[parity].Get(), desc_.hdrInput?DXGI_FORMAT_R16_UNORM:DXGI_FORMAT_R8_UNORM,
+ copyPlane(lumaTex_.Get(), upLuma_[parity].Get(), desc_.wideYuvInput()?DXGI_FORMAT_R16_UNORM:DXGI_FORMAT_R8_UNORM,
srcW_, srcH_, static_cast<UINT>(lumaPitch_));
- copyPlane(chromaTex_.Get(), upChroma_[parity].Get(), desc_.hdrInput?DXGI_FORMAT_R16G16_UNORM:DXGI_FORMAT_R8G8_UNORM,
+ copyPlane(chromaTex_.Get(), upChroma_[parity].Get(), desc_.wideYuvInput()?DXGI_FORMAT_R16G16_UNORM:DXGI_FORMAT_R8G8_UNORM,
(srcW_+1)/2, (srcH_+1)/2, static_cast<UINT>(chromaPitch_));
tracker_.transition(list, lumaTex_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
tracker_.transition(list, chromaTex_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
@@ -885,7 +885,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
}else{
const float constants[8] = { resolved.range==ColorRange::Full?0.0f:1.0f,
resolved.matrix==YuvMatrix::BT2020NCL?2.0f:resolved.matrix==YuvMatrix::BT601?0.0f:1.0f,
- resolved.transfer==TransferFunction::PQ?4.0f:float(workingTransferCode(resolved)), (nv12Texture?nv12Texture->GetDesc().Format==DXGI_FORMAT_P010:desc_.hdrInput)?1.0f:0.0f,
+ resolved.transfer==TransferFunction::PQ?4.0f:float(workingTransferCode(resolved)), (nv12Texture?(nv12Texture->GetDesc().Format==DXGI_FORMAT_P010?1.0f:0.0f):(desc_.captureBitDepth==16?2.0f:desc_.wideYuvInput()?1.0f:0.0f)),
uintBits(srcW_), uintBits(srcH_), uintBits(desc_.hdrOutput?1u:0u),
uintBits(resolved.reconstructChroma?std::max(1u,unsigned(resolved.chromaLocation)):0u) };
yuvPass_.bind(list, constants, gpuHandleOf(yuvPass_, nv12Texture ? 3 + parity * 2 : 0).ptr, gpuHandleOf(yuvPass_, 2).ptr);
diff --git a/src/source/CaptureCardSource.cpp b/src/source/CaptureCardSource.cpp
index d0ba0e2c..75e59d0a 100644
--- a/src/source/CaptureCardSource.cpp
+++ b/src/source/CaptureCardSource.cpp
@@ -85,8 +85,9 @@ std::vector<CaptureFormat> CaptureCardSource::formats(unsigned device){ComPtr<IG
// Device capabilities, not a 1080p/2160p 30/60 preset list. Keep native
// indices so the selected row opens the exact driver media type.
if(bm&&bm->biWidth>0&&bm->biWidth<=3840&&std::abs(int64_t(bm->biHeight))>0&&std::abs(int64_t(bm->biHeight))<=2160&&duration>0){unsigned w=bm->biWidth,h=unsigned(std::abs(int64_t(bm->biHeight)));double fps=1e7/duration;
- wchar_t guid[40]{};StringFromGUID2(t->subtype,guid,40);const wchar_t* pixel=t->subtype==MEDIASUBTYPE_YUY2?L"YUY2":t->subtype==MEDIASUBTYPE_MJPG?L"MJPEG":t->subtype==MEDIASUBTYPE_NV12?L"NV12":t->subtype==MEDIASUBTYPE_RGB32?L"RGB32":guid;
- out.push_back({i,w,h,fps,std::format(L"{} x {} @ {:.2f} fps · {} [format {}]",w,h,fps,pixel,i)});}freeType(t);}return out;}
+ const auto pixel=capturePixelName(t->subtype);CaptureMediaLayout layout;const bool valid=captureMediaLayout(*t,layout);const bool knownRaw=capturePacking(t->subtype)!=CapturePacking::Unknown;
+ const wchar_t* support=valid?((layout.format==AV_PIX_FMT_P010||layout.format==AV_PIX_FMT_P016)?L"原生 · SDR":L"原生"):knownRaw?L"布局/颜色暂不支持":L"需系统解码/转换";
+ out.push_back({i,w,h,fps,std::format(L"{} x {} @ {:.2f} fps · {} · {} [format {}]",w,h,fps,pixel,support,i)});}freeType(t);}return out;}
const SourceInfo& CaptureCardSource::info()const{return p_->info;}
bool CaptureCardSource::setAudioGain(float gain){
auto& p=*p_;if(p.audioSession){p.audioSession->setGain(gain);return p.audioSession->snapshot().available;}if(!p.graph||!p.audioFilter)return false;
@@ -109,7 +110,9 @@ bool CaptureCardSource::configure(const SourceOpenDesc& desc){close();p_->lastAu
// Read the driver-negotiated type back. Native YUY2/NV12/RGB32 connects
// directly to our terminal filter: no intelligent-connect converter.
native=nullptr;hr=p.config->GetFormat(&native);if(FAILED(hr)||!native){freeType(native);return false;}
- const bool nativeSupported=native->subtype==MEDIASUBTYPE_YUY2||native->subtype==MEDIASUBTYPE_NV12||native->subtype==MEDIASUBTYPE_RGB32;
+ CaptureMediaLayout nativeLayout;const bool nativeSupported=captureMediaLayout(*native,nativeLayout);
+ if(!nativeSupported&&capturePacking(native->subtype)!=CapturePacking::Unknown){log::error("capture","Known raw format has unsupported layout/color metadata; refusing implicit RGB conversion");freeType(native);return false;}
+ if(nativeSupported&&(nativeLayout.format==AV_PIX_FMT_P010||nativeLayout.format==AV_PIX_FMT_P016)&&desc.legacyCaptureRgbForDiagnostic){log::error("capture","10/16-bit capture cannot use the legacy 8-bit RGB diagnostic converter");freeType(native);return false;}
const bool direct=nativeSupported&&!desc.legacyCaptureRgbForDiagnostic;
AM_MEDIA_TYPE connected{};
if(direct){
diff --git a/tests/integration/CaptureFormatGpuCases.h b/tests/integration/CaptureFormatGpuCases.h
new file mode 100644
index 00000000..3b044b70
--- /dev/null
+++ b/tests/integration/CaptureFormatGpuCases.h
@@ -0,0 +1,62 @@
+#pragma once
+#include "veyra/source/CaptureMediaType.h"
+#include <DirectXPackedVector.h>
+#include <iostream>
+
+// Test-only readback of the real FP16 output, so a hidden 8-bit conversion
+// cannot pass merely because black/white screenshots look correct.
+inline bool captureReadFp16(veyra::gfx::D3D12DeviceContext& ctx,veyra::gfx::CommandSlotRing& ring,ID3D12Resource* texture,std::vector<float>& pixels){
+ using namespace veyra;auto desc=texture->GetDesc();if(desc.Format!=DXGI_FORMAT_R16G16B16A16_FLOAT)return false;
+ D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{};UINT64 size=0;ctx.device()->GetCopyableFootprints(&desc,0,1,0,&fp,nullptr,nullptr,&size);
+ D3D12_HEAP_PROPERTIES hp{};hp.Type=D3D12_HEAP_TYPE_READBACK;D3D12_RESOURCE_DESC bd{};bd.Dimension=D3D12_RESOURCE_DIMENSION_BUFFER;bd.Width=size;bd.Height=1;bd.DepthOrArraySize=1;bd.MipLevels=1;bd.SampleDesc.Count=1;bd.Layout=D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
+ Microsoft::WRL::ComPtr<ID3D12Resource> read;if(FAILED(ctx.device()->CreateCommittedResource(&hp,D3D12_HEAP_FLAG_NONE,&bd,D3D12_RESOURCE_STATE_COPY_DEST,nullptr,IID_PPV_ARGS(&read))))return false;
+ Status st;uint32_t slot;auto* list=ring.acquireNext(slot,st);if(!list)return false;
+ D3D12_RESOURCE_BARRIER barrier{};barrier.Type=D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;barrier.Transition.pResource=texture;barrier.Transition.Subresource=D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;barrier.Transition.StateBefore=D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;barrier.Transition.StateAfter=D3D12_RESOURCE_STATE_COPY_SOURCE;list->ResourceBarrier(1,&barrier);
+ D3D12_TEXTURE_COPY_LOCATION a{},b{};a.pResource=texture;a.Type=D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;b.pResource=read.Get();b.Type=D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;b.PlacedFootprint=fp;list->CopyTextureRegion(&b,0,0,0,&a,nullptr);std::swap(barrier.Transition.StateBefore,barrier.Transition.StateAfter);list->ResourceBarrier(1,&barrier);
+ if(!ring.submitAndSignal(slot)||!ring.waitIdle())return false;void* ptr=nullptr;D3D12_RANGE range{0,size};if(FAILED(read->Map(0,&range,&ptr)))return false;
+ pixels.resize(size_t(desc.Width)*desc.Height*4);
+ for(unsigned y=0;y<desc.Height;++y){const auto* row=reinterpret_cast<const uint16_t*>(static_cast<const uint8_t*>(ptr)+fp.Offset+size_t(y)*fp.Footprint.RowPitch);for(size_t x=0;x<desc.Width*4;++x)pixels[(size_t(y)*desc.Width*4)+x]=DirectX::PackedVector::XMConvertHalfToFloat(row[x]);}
+ D3D12_RANGE written{};read->Unmap(0,&written);return true;
+}
+inline int captureGpuCases(veyra::gfx::D3D12DeviceContext& ctx,veyra::gfx::CommandSlotRing& ring){
+ using namespace veyra;using namespace veyra::source;int failures=0;
+ auto 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}};};
+ const GUID ids[]={MEDIASUBTYPE_RGB24,MEDIASUBTYPE_RGB32,MEDIASUBTYPE_ARGB32,MEDIASUBTYPE_RGB555,MEDIASUBTYPE_RGB565,fourcc("YUY2"),fourcc("UYVY"),fourcc("YVYU"),fourcc("NV12"),fourcc("NV21"),fourcc("I420"),fourcc("IYUV"),fourcc("YV12"),fourcc("P010"),fourcc("P016")};
+ for(const auto& id:ids)for(bool full:{false,true}){
+ VIDEOINFOHEADER2 vi{};vi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);vi.bmiHeader.biWidth=64;vi.bmiHeader.biHeight=32;vi.AvgTimePerFrame=166667;
+ DXVA2_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;
+ // RGB bitfield tests use full range (unit tests cover channel masks).
+ if(rgb){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;}
+ 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);
+ }
+ if(l.packing==CapturePacking::Uyvy)for(unsigned x=0;x<128;x+=2)std::swap(row[x],row[x+1]);
+ }
+ 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&&copyCaptureSample(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::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;}
+ bool precision=true;if(ok&&wide){
+ // 10-bit: single-code steps must remain distinct. P016 is retained
+ // through ingress; FP16 working storage can quantize 16-bit steps.
+ const unsigned step=bits==10?1:8;
+ for(unsigned x=19;x+step<45;x+=step)precision&=pixels[(x+step)*4]>pixels[x*4];
+ ok&=precision;
+ }
+ std::cout<<"CAPTURE_GPU subtype="<<std::hex<<id.Data1<<std::dec<<" bits="<<bits<<" full="<<full<<" error="<<error<<" precision="<<precision<<" pass="<<ok<<std::endl;
+ if(!ok)++failures;out={};ring.drainQueue();graph.shutdown();av_frame_free(&f);
+ }
+ return failures;
+}
diff --git a/tests/integration/CaptureSourceTests.cpp b/tests/integration/CaptureSourceTests.cpp
index ac7086d6..ab6d2c22 100644
--- a/tests/integration/CaptureSourceTests.cpp
+++ b/tests/integration/CaptureSourceTests.cpp
@@ -9,6 +9,7 @@
#include <cstring>
extern "C" {
#include <libavutil/frame.h>
+#include <libavutil/imgutils.h>
}
int wmain(int argc,wchar_t** argv){
if(argc==2&&wcscmp(argv[1],L"--list")==0){
@@ -29,7 +30,7 @@ int wmain(int argc,wchar_t** argv){
auto readFrame=[&](){while(std::chrono::steady_clock::now()<deadline){auto r=source.read(packet,&frame);if(r==veyra::source::SourceReadStatus::Frame)return true;if(r==veyra::source::SourceReadStatus::Error)return false;}return false;};
if(!readFrame()){printf("FAIL first frame\n");return 5;}
const auto initialPts=packet.pts.toDouble();const auto initialReceived=source.metrics().received;
- const int rowBytes=frame->width*(frame->format==AV_PIX_FMT_YUYV422?2:frame->format==AV_PIX_FMT_NV12?1:4);
+ const int rowBytes=av_image_get_linesize(AVPixelFormat(frame->format),frame->width,0);
std::vector<unsigned char> row(frame->data[0],frame->data[0]+rowBytes);
std::this_thread::sleep_for(std::chrono::milliseconds(300));
auto stalled=source.metrics();
diff --git a/tests/integration/HdrColorTests.cpp b/tests/integration/HdrColorTests.cpp
index 9bc2797e..74baefce 100644
--- a/tests/integration/HdrColorTests.cpp
+++ b/tests/integration/HdrColorTests.cpp
@@ -7,6 +7,7 @@
#include "veyra/engine/VideoPresenter.h"
#include "veyra/source/MediaFileSource.h"
#include "veyra/RuntimePaths.h"
+#include "CaptureFormatGpuCases.h"
#include <iostream>
#include <cmath>
extern "C" {
@@ -17,7 +18,7 @@ int wmain(int argc,wchar_t** argv){
CoInitializeEx(nullptr,COINIT_MULTITHREADED);
gfx::D3D12DeviceContext ctx;gfx::CommandSlotRing ring;Status st;gfx::DeviceContextDesc dd;
if(!ctx.initialize(dd,st)||!ring.initialize(ctx.device(),ctx.directQueue(),ctx.fence(),ctx.fenceEvent(),4,st))return 2;
- int failures=0;
+ int failures=captureGpuCases(ctx,ring);
for(bool native:{false,true})for(bool planar:{false,true})for(bool full:{false,true}){
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.hdrInput=true;gd.hdrOutput=native;
diff --git a/tests/unit/CaptureColorContractTests.cpp b/tests/unit/CaptureColorContractTests.cpp
index bb6cb5ae..0f91f9a4 100644
--- a/tests/unit/CaptureColorContractTests.cpp
+++ b/tests/unit/CaptureColorContractTests.cpp
@@ -1,5 +1,6 @@
#include "veyra/source/CaptureMediaType.h"
#include "veyra/source/NativeCaptureSink.h"
+#include "CaptureFormatCases.h"
#include <iostream>
#include <vector>
#include <atomic>
@@ -32,6 +33,7 @@ struct OutputPin final:IPin,IAMBufferNegotiation {
int main(){
CoInitializeEx(nullptr,COINIT_MULTITHREADED);int failures=0;
auto check=[&](bool pass,const char* name){std::cout<<(pass?"PASS ":"FAIL ")<<name<<'\n';if(!pass)++failures;};
+ captureFormatCases(check);
VIDEOINFOHEADER2 vi{};vi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);vi.bmiHeader.biWidth=4;vi.bmiHeader.biHeight=2;vi.bmiHeader.biBitCount=16;vi.bmiHeader.biSizeImage=24;vi.AvgTimePerFrame=166667;
AM_MEDIA_TYPE type{};type.majortype=MEDIATYPE_Video;type.subtype=MEDIASUBTYPE_YUY2;type.formattype=FORMAT_VideoInfo2;type.pbFormat=reinterpret_cast<BYTE*>(&vi);type.cbFormat=sizeof(vi);
source::CaptureMediaLayout layout;check(source::captureMediaLayout(type,layout)&&layout.stride==12&&layout.rowBytes==8&&!layout.bottomUp,"VideoInfo2 YUY2 padded row contract");
diff --git a/tests/unit/CaptureFormatCases.h b/tests/unit/CaptureFormatCases.h
new file mode 100644
index 00000000..27dad92b
--- /dev/null
+++ b/tests/unit/CaptureFormatCases.h
@@ -0,0 +1,57 @@
+#pragma once
+#include "veyra/source/CaptureMediaType.h"
+#include <vector>
+
+template<class Check> void captureFormatCases(Check check){
+ using namespace veyra::source;
+ auto 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}};};
+ VIDEOINFOHEADER2 vi{};vi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);vi.bmiHeader.biWidth=4;vi.bmiHeader.biHeight=4;vi.AvgTimePerFrame=166667;
+ AM_MEDIA_TYPE t{};t.majortype=MEDIATYPE_Video;t.formattype=FORMAT_VideoInfo2;t.pbFormat=reinterpret_cast<BYTE*>(&vi);t.cbFormat=sizeof(vi);
+ struct Case{GUID id;int bytes;};
+ const Case cases[]={
+ {MEDIASUBTYPE_RGB24,48},{MEDIASUBTYPE_RGB32,64},{MEDIASUBTYPE_ARGB32,64},{MEDIASUBTYPE_RGB555,32},{MEDIASUBTYPE_RGB565,32},
+ {fourcc("YUY2"),32},{fourcc("UYVY"),32},{fourcc("YVYU"),32},
+ {fourcc("NV12"),24},{fourcc("NV21"),24},{fourcc("I420"),24},{fourcc("IYUV"),24},{fourcc("YV12"),24},
+ {fourcc("P010"),48},{fourcc("P016"),48}};
+ for(const auto& item:cases){
+ t.subtype=item.id;CaptureMediaLayout l;
+ bool ok=captureMediaLayout(t,l);check(ok&&l.sampleBytes==size_t(item.bytes),"raw format negotiated layout/size");
+ check(capturePixelName(item.id).find(L'{')==std::wstring::npos,"known raw format has readable name");
+ if(!ok)continue;
+ std::vector<uint8_t> bytes(l.sampleBytes);for(size_t i=0;i<bytes.size();++i)bytes[i]=uint8_t(i+1);
+ AVFrame* f=av_frame_alloc();f->width=4;f->height=4;f->format=l.format;av_frame_get_buffer(f,32);
+ check(copyCaptureSample(l,bytes.data(),bytes.size(),*f),"raw sample copied into owned frame");
+ const auto previous=f->data[0][0];bytes[0]=199;
+ 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;
+ }
+ 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;}
+ check(exact,"raw plane order, channels and orientation match reference");
+ av_frame_free(&f);
+ }
+ t.subtype=MEDIASUBTYPE_RGB24;vi.bmiHeader.biWidth=3;vi.bmiHeader.biHeight=-2;CaptureMediaLayout l;
+ check(captureMediaLayout(t,l)&&l.rowBytes==9&&l.stride==12&&l.sampleBytes==24&&!l.bottomUp,"RGB24 odd width uses DWORD aligned top-down rows");
+ vi.bmiHeader.biSizeImage=18;check(!captureMediaLayout(t,l),"RGB24 rejects unaligned declared DIB rows");vi.bmiHeader.biSizeImage=0;
+ vi.bmiHeader.biWidth=4;vi.bmiHeader.biHeight=4;t.subtype=fourcc("P010");vi.bmiHeader.biSizeImage=72;
+ check(captureMediaLayout(t,l)&&l.stride==12&&l.chromaOffset==48&&l.chromaRowBytes==8,"P010 padded UV starts after full padded Y plane");
+ vi.bmiHeader.biSizeImage=66;check(!captureMediaLayout(t,l),"16-bit samples reject odd byte stride");vi.bmiHeader.biSizeImage=0;
+ auto other=t;other.subtype=fourcc("P016");check(!equivalentCaptureTypes(t,other),"P010 to P016 requires reconnect despite identical dimensions");
+ t.subtype=fourcc("NV12");other=t;other.subtype=fourcc("NV21");check(!equivalentCaptureTypes(t,other),"UV to VU change cannot silently reuse layout");
+ 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");
+ 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);
+ }
+ t.subtype=fourcc("P010");DXVA2_ExtendedFormat ext{};ext.VideoTransferFunction=16;vi.dwControlFlags=ext.value|AMCONTROL_COLORINFO_PRESENT;
+ check(!captureMediaLayout(t,l),"capture PQ metadata not silently interpreted as SDR");vi.dwControlFlags=0;
+ t.subtype=fourcc("ABCD");check(capturePixelName(t.subtype)==L"ABCD"&&!captureMediaLayout(t,l),"unknown FourCC readable but not advertised as native");
+ t.subtype.Data2=3;check(capturePixelName(t.subtype).find(L"未知格式")!=std::wstring::npos&&!captureMediaLayout(t,l),"private GUID cannot alias standard FourCC");
+}
diff --git a/tools/capture_color_probe/main.cpp b/tools/capture_color_probe/main.cpp
index 1feda6ed..3b51bc17 100644
--- a/tools/capture_color_probe/main.cpp
+++ b/tools/capture_color_probe/main.cpp
@@ -12,6 +12,8 @@
#include <chrono>
extern "C" {
#include <libavutil/frame.h>
+#include <libavutil/imgutils.h>
+#include <libavutil/pixdesc.h>
}
using namespace veyra;
int wmain(int argc,wchar_t**argv){
@@ -28,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.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);
engine::VideoPresenter presenter;
@@ -40,10 +43,15 @@ int wmain(int argc,wchar_t**argv){
if(result==source::SourceReadStatus::Frame)++frames;
}
if(frames<20||!frame)return 7;
- const unsigned rowBytes=info.width*(frame->format==AV_PIX_FMT_YUYV422?2:frame->format==AV_PIX_FMT_NV12?1:4);
+ const auto pixelFormat=AVPixelFormat(frame->format);
+ const unsigned rowBytes=unsigned(av_image_get_linesize(pixelFormat,int(info.width),0));
std::ofstream raw(dir/"source.raw",std::ios::binary);
- for(unsigned y=0;y<info.height;++y)raw.write(reinterpret_cast<const char*>(frame->data[0]+ptrdiff_t(y)*frame->linesize[0]),rowBytes);
- if(frame->format==AV_PIX_FMT_NV12)for(unsigned y=0;y<info.height/2;++y)raw.write(reinterpret_cast<const char*>(frame->data[1]+ptrdiff_t(y)*frame->linesize[1]),info.width);
+ const auto* pixelDesc=av_pix_fmt_desc_get(pixelFormat);
+ for(int plane=0;plane<av_pix_fmt_count_planes(pixelFormat);++plane){
+ const unsigned rows=plane?AV_CEIL_RSHIFT(info.height,pixelDesc->log2_chroma_h):info.height;
+ const int bytes=av_image_get_linesize(pixelFormat,int(info.width),plane);
+ for(unsigned y=0;y<rows;++y)raw.write(reinterpret_cast<const char*>(frame->data[plane]+ptrdiff_t(y)*frame->linesize[plane]),bytes);
+ }
raw.close();
pipeline::EnhanceGraph::FrameOutputs out;sink::RgbaImage gpu,display;
const bool ok=graph.process(frame,packet.pts.toDouble()*1000,true,out,packet.sequence,&packet.colorInfo)&&