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(capture): Elgato HDR colour and tonemapper parity with Nitlink and OBS beyond the MK.2

Veyra Goal Agent94cbabd94048
diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md
index b9b1d6b3..df059dbe 100644
--- a/THIRD_PARTY_NOTICES.md
+++ b/THIRD_PARTY_NOTICES.md
@@ -98,14 +98,22 @@ MIT adaptations in `src/source/ElgatoHdrControl.cpp` and its header:
- https://github.com/nitlink-dev/nitlink at
`4f8a723406f63c6e92832488a6022fcf25233871`,
`src/capture/elgato_hdr_control.cpp` and `elgato_device_identity.h`:
- exact MK.2 aliases, packet read size checks and hardware/native HDR pairing.
+ exact MK.2 aliases, packet read size checks and hardware/native HDR pairing;
+ `IsElgatoDevice` identity rule; `src/renderer/dx11_renderer.cpp`
+ `yuv2020ToRgb_Limited`: limited-range luma with full-range chroma for HDR
+ P010 from Elgato cards other than the MK.2 (MK.2 keeps 64..960 chroma).
Copyright (c) 2026 NitLink Contributors.
Veyra changes: use the already selected DirectShow filter instead of opening
-another device; scope to MK.2/P010; validate packet length/type/checksum;
-retain manual overrides; log HRESULT/readback and restore a readable initial
-tonemap value on close. No vendor shader, SDK header or binary is vendored.
-No global color/chroma formula change. Full license:
+another device; validate packet length/type/checksum; retain manual overrides;
+log HRESULT/readback and restore a readable initial tonemap value on close.
+2026-10-11: the vendor tonemap control covers every Elgato filter name (strict
+only for MK.2 P010; other models may lack the property set); 8-bit formats
+request the card's hardware tonemapper as OBS libdshowcapture
+(`SetVendorTonemapperUsage`, behaviour only, no code copied) does; the
+non-MK.2 P010 chroma rule is a per-source flag (`fullRangeChroma`) honoured by
+`YuvToLinearRgb.hlsl`, applied only when the user leaves range on auto. No
+vendor shader, SDK header or binary is vendored. Full license:
`licenses/capture/ELGATO_NITLINK_MIT.txt`.
## NVENC API declarations
diff --git a/include/veyra/pipeline/FramePacket.h b/include/veyra/pipeline/FramePacket.h
index 68985257..c58beb50 100644
--- a/include/veyra/pipeline/FramePacket.h
+++ b/include/veyra/pipeline/FramePacket.h
@@ -138,6 +138,10 @@ struct ColorDescription {
// declarations, not measured frame peaks or dynamic Dolby Vision metadata.
float hdrMaxCllNits = 0, hdrMaxFallNits = 0, hdrMasteringPeakNits = 0;
bool scRgb = false; // Explicit WGC FP16 linear BT.709, 1.0 = 80 nits.
+ // Limited-range luma with full-range chroma: Elgato cards other than the
+ // 4K60 Pro MK.2 encode HDR P010 this way (Nitlink, measured against the
+ // console on the TV). Decoding that chroma as limited over-saturates it.
+ bool fullRangeChroma = false;
bool isHdrPath() const {
return scRgb || transfer == TransferFunction::PQ || transfer == TransferFunction::HLG;
diff --git a/include/veyra/source/ElgatoHdrControl.h b/include/veyra/source/ElgatoHdrControl.h
index ba809e5c..e375b0fc 100644
--- a/include/veyra/source/ElgatoHdrControl.h
+++ b/include/veyra/source/ElgatoHdrControl.h
@@ -12,6 +12,8 @@ struct ElgatoHdrPacket {
float peak=0, maxCll=0, maxFall=0;
};
bool isElgatoMk2(std::wstring_view name);
+// Any Elgato capture filter: "Elgato ..." names and the "Game Capture ..." family.
+bool isElgatoDevice(std::wstring_view name);
ElgatoHdrPacket parseElgatoHdrPacket(const std::array<unsigned char,32>& bytes);
// Session-scoped device control; release it after Stop and before the filter.
@@ -21,9 +23,12 @@ public:
ElgatoHdrControl()=default;
ElgatoHdrControl(const ElgatoHdrControl&)=delete;
ElgatoHdrControl& operator=(const ElgatoHdrControl&)=delete;
+ // p010=true for the 10-bit HDR format, false for 8-bit formats (NV12, YUY2, RGB).
bool configure(IUnknown* filter,std::wstring_view name,bool p010,
unsigned overrideValue,pipeline::ColorDescription& color);
private:
+ // strict: a failed or contradicted write fails the connection (MK.2 P010).
+ bool setTonemap(DWORD desired,bool strict);
Microsoft::WRL::ComPtr<IKsPropertySet> properties_;
DWORD original_=0;
bool restore_=false;
diff --git a/shaders/YuvToLinearRgb.hlsl b/shaders/YuvToLinearRgb.hlsl
index 5f14d749..bf58c01a 100644
--- a/shaders/YuvToLinearRgb.hlsl
+++ b/shaders/YuvToLinearRgb.hlsl
@@ -8,7 +8,7 @@
cbuffer YuvParams : register(b0)
{
- float4 colorParams0; // x=limitedRange y=matrix709 z=transferSRGB w=padding
+ float4 colorParams0; // x=range (0 full, 1 limited, 2 limited luma/full chroma) y=matrix z=transfer w=bit depth class
uint4 yuvDimensions; // x=width y=height z=bit0 nativeHDR, bit1 BT2020 primaries; w=chroma location
float4 toneMapParams; // x=validated source peak nits, y=SDR target peak nits
// Colour grade (plan v4): appended after the existing constants, packed by
@@ -38,10 +38,13 @@ float3 YuvToRgb(float y, float2 uv)
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;
+ // colorParams0.x: 0 full range, 1 limited, 2 limited luma + full-range
+ // chroma (Elgato cards other than the MK.2 send HDR P010 that way).
+ bool limitedLuma=colorParams0.x>0.5,limitedChroma=limitedLuma&&colorParams0.x<1.5;
+ float yy=limitedLuma?(y*scale-black)/(white-black):y*scale/maximum;
yy=saturate(yy);
- float uu=(uv.x*scale-middle)/(colorParams0.x>0.5?span:maximum);
- float vv=(uv.y*scale-middle)/(colorParams0.x>0.5?span:maximum);
+ float uu=(uv.x*scale-middle)/(limitedChroma?span:maximum);
+ float vv=(uv.y*scale-middle)/(limitedChroma?span:maximum);
if(colorParams0.y>1.5){
// BT.2020 non-constant-luminance coefficients.
diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cpp
index 29fe057f..694a2bb0 100644
--- a/src/pipeline/EnhanceGraph.cpp
+++ b/src/pipeline/EnhanceGraph.cpp
@@ -2226,7 +2226,8 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
rgbPass_.bind(list,c,gpuHandleOf(rgbPass_,gpuRgb?3+parity:0).ptr,gpuHandleOf(rgbPass_,1+uavSlot).ptr,gpuHandleOf(rgbPass_,8).ptr);
list->Dispatch((srcW_+15)/16,(srcH_+15)/16,1);
}else{
- float constants[12+kColorGradeConstantCount] = { resolved.range==ColorRange::Full?0.0f:1.0f,
+ // 0 full range, 1 limited, 2 limited luma with full-range chroma (Elgato non-MK.2 P010).
+ float constants[12+kColorGradeConstantCount] = { resolved.range==ColorRange::Full?0.0f:resolved.fullRangeChroma?2.0f:1.0f,
resolved.matrix==YuvMatrix::BT2020NCL?2.0f:resolved.matrix==YuvMatrix::BT601?0.0f:1.0f,
resolved.transfer==TransferFunction::HLG?5.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_.hdrWorking()?1u:0u)|(resolved.primaries==ColorPrimaries::BT2020?2u:0u)),
diff --git a/src/source/CaptureCardSource.cpp b/src/source/CaptureCardSource.cpp
index d4033430..218c3011 100644
--- a/src/source/CaptureCardSource.cpp
+++ b/src/source/CaptureCardSource.cpp
@@ -1089,13 +1089,16 @@ bool CaptureCardSource::configure(const SourceOpenDesc& desc){close();error_.cle
log::info("capture-color",std::format("driver controlFlags=0x{:08X} colorInfoPresent={} transfer={} matrix={} primaries={} chroma={} override={}",p.layout.colorControlFlags,bool(p.layout.colorControlFlags&AMCONTROL_COLORINFO_PRESENT),int(p.layout.color.transfer),int(p.layout.color.matrix),int(p.layout.color.primaries),int(p.layout.color.chromaLocation),colorOverride));
if(!validCaptureColorOverride(colorOverride))return false;
auto elgatoHdr=std::make_unique<ElgatoHdrControl>();
- if(!compressedPath&&p.layout.format==AV_PIX_FMT_P010){
+ // Elgato cards: P010 takes the HDR path, 8-bit native formats ask the card
+ // to tone map (OBS parity). Other wide formats leave the card state alone.
+ const bool otherWide=p.layout.format==AV_PIX_FMT_P016||p.layout.packing==CapturePacking::V210||p.layout.packing==CapturePacking::Rgb10xLE;
+ if(!compressedPath&&!otherWide){
std::wstring deviceName;
const auto devices=monikers(false);
for(size_t i=0;i<devices.size();++i){
if(selection.stable?monikerPath(devices[i].Get())==selection.videoPath:i==index){deviceName=propertyString(devices[i].Get(),L"FriendlyName");break;}
}
- if(!elgatoHdr->configure(p.device.Get(),deviceName,true,colorOverride,p.layout.color)){
+ if(!elgatoHdr->configure(p.device.Get(),deviceName,p.layout.format==AV_PIX_FMT_P010,colorOverride,p.layout.color)){
error_=L"Elgato HDR 输出模式设置失败,请关闭其他采集程序后重新连接,并检查日志中的 capture-elgato。";
return false;
}
diff --git a/src/source/ElgatoHdrControl.cpp b/src/source/ElgatoHdrControl.cpp
index cbbbf74e..19f9804e 100644
--- a/src/source/ElgatoHdrControl.cpp
+++ b/src/source/ElgatoHdrControl.cpp
@@ -10,6 +10,12 @@ namespace veyra::source {
namespace {
constexpr GUID propertySet{0xD1E5209F,0x68FD,0x4529,{0xBE,0xE0,0x5E,0x7A,0x1F,0x47,0x92,0x26}};
constexpr DWORD packetLow=720,packetHigh=721,tonemap=722;
+std::string narrowForLog(std::wstring_view value) {
+ const int size=value.empty()?0:WideCharToMultiByte(CP_UTF8,0,value.data(),int(value.size()),nullptr,0,nullptr,nullptr);
+ std::string out(size_t(std::max(size,0)),'\0');
+ if(size>0)WideCharToMultiByte(CP_UTF8,0,value.data(),int(value.size()),out.data(),size,nullptr,nullptr);
+ return out;
+}
void record(const char* op,DWORD id,HRESULT hr,DWORD size) {
log::info("capture-elgato",std::format("{} property={} hr=0x{:08X} bytesOrFlags={}",op,id,uint32_t(hr),size));
}
@@ -25,6 +31,13 @@ bool isElgatoMk2(std::wstring_view name) {
if(CompareStringOrdinal(name.data(),int(name.size()),alias,-1,TRUE)==CSTR_EQUAL)return true;
return false;
}
+bool isElgatoDevice(std::wstring_view name) {
+ // Same identity rule as Nitlink plus the vendor's "Game Capture ..." filter
+ // names (HD60 X/S+, 4K60 Pro/S+). Generic names never enter this path.
+ std::wstring lower(name);
+ std::transform(lower.begin(),lower.end(),lower.begin(),[](wchar_t c){return wchar_t(towlower(c));});
+ return isElgatoMk2(name)||lower.find(L"elgato")!=std::wstring::npos||lower.rfind(L"game capture ",0)==0;
+}
ElgatoHdrPacket parseElgatoHdrPacket(const std::array<unsigned char,32>& b) {
// Unlike an absent/failed read, an all-zero packet is the driver's SDR report.
if(std::all_of(b.begin(),b.end(),[](auto v){return v==0;}))return {true};
@@ -34,14 +47,56 @@ ElgatoHdrPacket parseElgatoHdrPacket(const std::array<unsigned char,32>& b) {
const auto u16=[&](unsigned i){return float(unsigned(b[i])|(unsigned(b[i+1])<<8));};
return {true,b[4],u16(22),u16(26),u16(28)};
}
+bool ElgatoHdrControl::setTonemap(DWORD desired,bool strict) {
+ const bool originalKnown=SUCCEEDED(read(properties_.Get(),tonemap,&original_,sizeof(original_)))&&original_<=1;
+ if(originalKnown&&original_==desired)return true;
+ DWORD flags=0;auto hr=properties_->QuerySupported(propertySet,tonemap,&flags);
+ record("QuerySupported",tonemap,hr,flags);
+ // Official SDK issues Set directly. QuerySupported is advisory because
+ // installed MK.2 drivers need not advertise every private property.
+ DWORD value=desired;
+ hr=properties_->Set(propertySet,tonemap,nullptr,0,&value,sizeof(value));
+ record("Set",tonemap,hr,sizeof(value));
+ if(FAILED(hr)) {
+ // Cards without the vendor set (4K X/4K S answer E_PROP_SET_UNSUPPORTED)
+ // keep their own state; only the MK.2 HDR contract depends on it.
+ if(!strict)log::info("capture-elgato",std::format("hardware tonemap control not available on this card (hr=0x{:08X}); card state unchanged",uint32_t(hr)));
+ return !strict;
+ }
+ restore_=originalKnown;
+ DWORD actual=0;
+ const auto readback=read(properties_.Get(),tonemap,&actual,sizeof(actual));
+ if(SUCCEEDED(readback)&&actual!=desired) {
+ log::error("capture-elgato","Tonemap readback disagrees; refusing a mislabeled color contract");
+ return !strict;
+ }
+ if(!originalKnown)log::warn("capture-elgato","Tonemap original state unreadable; Set succeeded but close cannot restore an unknown value");
+ return true;
+}
bool ElgatoHdrControl::configure(IUnknown* filter,std::wstring_view name,bool p010,
unsigned overrideValue,pipeline::ColorDescription& color) {
- if(!filter||!p010||!isElgatoMk2(name))return true;
+ if(!filter||!isElgatoDevice(name))return true;
if(!validCaptureColorOverride(overrideValue))return false;
+ const bool mk2=isElgatoMk2(name);
+ const unsigned space=captureColorSpace(overrideValue);
+ // Nitlink: Elgato cards other than the MK.2 send HDR P010 with limited luma
+ // and full-range chroma (MK.2 uses standard 64..960 chroma). An explicit
+ // range choice by the user stays authoritative.
+ if(p010&&!mk2&&!captureColorRange(overrideValue)&&color.range!=pipeline::ColorRange::Full) {
+ color.fullRangeChroma=true;
+ log::info("capture-elgato",std::format("non-MK.2 Elgato P010: limited luma, full-range chroma (Nitlink policy) device={}",narrowForLog(name)));
+ }
auto hr=filter->QueryInterface(IID_PPV_ARGS(&properties_));
record("QueryInterface",0,hr,0);
if(FAILED(hr)) {
- log::warn("capture-elgato","MK.2 private control unavailable; keeping existing color contract");
+ log::warn("capture-elgato","Elgato private control unavailable; keeping existing color contract");
+ return true;
+ }
+ if(!p010) {
+ // OBS libdshowcapture parity: an 8-bit format asks the card to tone map
+ // an HDR source to SDR itself; without it HDR code values arrive as SDR.
+ const bool ok=setTonemap(1,false);
+ log::info("capture-elgato",std::format("8-bit format hardwareTonemap=1 requested (OBS parity) mk2={} applied={}",mk2,ok&&restore_));
return true;
}
std::array<unsigned char,32> bytes{};
@@ -49,32 +104,14 @@ bool ElgatoHdrControl::configure(IUnknown* filter,std::wstring_view name,bool p0
const auto high=read(properties_.Get(),packetHigh,bytes.data()+16,16);
const auto packet=SUCCEEDED(low)&&SUCCEEDED(high)?parseElgatoHdrPacket(bytes):ElgatoHdrPacket{};
log::info("capture-elgato",std::format("HDR InfoFrame valid={} header={:02X}/{:02X}/{:02X} eotf={} peak={} maxCLL={} maxFALL={}",packet.valid,bytes[0],bytes[1],bytes[2],packet.eotf,packet.peak,packet.maxCll,packet.maxFall));
- const unsigned space=captureColorSpace(overrideValue);
const bool sourceHdr=packet.valid&&(packet.eotf==2||packet.eotf==3);
// A bit depth alone never triggers HDR or a hardware write. Explicit space
// is authoritative; auto only adopts a validated source InfoFrame.
const bool wantHdr=space==1||space==2||(!space&&(sourceHdr||color.isHdrPath()));
if(!wantHdr&&space!=3)return true;
const DWORD desired=wantHdr?0:1;
- const bool originalKnown=SUCCEEDED(read(properties_.Get(),tonemap,&original_,sizeof(original_)))&&original_<=1;
- if(!originalKnown||original_!=desired) {
- DWORD flags=0;hr=properties_->QuerySupported(propertySet,tonemap,&flags);
- record("QuerySupported",tonemap,hr,flags);
- // Official SDK issues Set directly. QuerySupported is advisory because
- // installed MK.2 drivers need not advertise every private property.
- DWORD value=desired;
- hr=properties_->Set(propertySet,tonemap,nullptr,0,&value,sizeof(value));
- record("Set",tonemap,hr,sizeof(value));
- if(FAILED(hr))return false;
- restore_=originalKnown;
- DWORD actual=0;
- const auto readback=read(properties_.Get(),tonemap,&actual,sizeof(actual));
- if(SUCCEEDED(readback)&&actual!=desired) {
- log::error("capture-elgato","Tonemap readback disagrees; refusing a mislabeled color contract");
- return false;
- }
- if(!originalKnown)log::warn("capture-elgato","Tonemap original state unreadable; Set succeeded but close cannot restore an unknown value");
- }
+ // Only the MK.2 contract is strict: other models may lack the vendor set.
+ if(!setTonemap(desired,mk2))return false;
if(!space&&sourceHdr) {
const auto previous=color;
applyCaptureColorOverride(color,packet.eotf==2?1:2);
@@ -89,7 +126,7 @@ bool ElgatoHdrControl::configure(IUnknown* filter,std::wstring_view name,bool p0
color.hdrMaxCllNits=packet.maxCll;
color.hdrMaxFallNits=packet.maxFall;
}
- log::info("capture-elgato",std::format("MK.2 P010 hardwareTonemap={} manualSpace={} sourceEotf={} nativeHdrRequested={}",desired,space,packet.eotf,wantHdr));
+ log::info("capture-elgato",std::format("P010 hardwareTonemap={} mk2={} manualSpace={} sourceEotf={} nativeHdrRequested={} fullRangeChroma={}",desired,mk2,space,packet.eotf,wantHdr,color.fullRangeChroma));
return true;
}
ElgatoHdrControl::~ElgatoHdrControl() {
diff --git a/tests/integration/HdrColorTests.cpp b/tests/integration/HdrColorTests.cpp
index 264f40fe..e8d769c3 100644
--- a/tests/integration/HdrColorTests.cpp
+++ b/tests/integration/HdrColorTests.cpp
@@ -100,6 +100,45 @@ int wmain(int argc,wchar_t** argv){
std::cout<<"HDR_COLOR hlg="<<hlg<<" native="<<native<<" planar="<<planar<<" full="<<full<<" error="<<error<<" pass="<<ok<<std::endl;if(!ok)++failures;
out={};ring.drainQueue();graph.shutdown();av_frame_free(&f);
}
+ {
+ // Elgato non-MK.2 P010 (limited luma, full-range chroma): chroma code c decoded
+ // as full range must equal the standard limited decode of 512+(c-512)*896/1023,
+ // and must be less saturated than decoding the same code as limited.
+ const auto decode=[&](unsigned vCode,bool fullChroma,float rgb[3])->bool{
+ 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=true;
+ gd.hdrOutputMode=engine::HdrOutputMode::ScRgb;
+ if(!graph.initialize(gd)||!graph.createViews())return false;
+ AVFrame* f=av_frame_alloc();f->width=64;f->height=32;f->format=AV_PIX_FMT_P010;f->color_range=AVCOL_RANGE_MPEG;f->colorspace=AVCOL_SPC_BT2020_NCL;f->color_trc=AVCOL_TRC_SMPTE2084;f->color_primaries=AVCOL_PRI_BT2020;
+ if(av_frame_get_buffer(f,32)<0){av_frame_free(&f);return false;}
+ for(unsigned y=0;y<32;++y)for(unsigned x=0;x<64;++x)reinterpret_cast<uint16_t*>(f->data[0]+y*f->linesize[0])[x]=uint16_t(509u<<6); // ~100 cd/m2
+ for(unsigned y=0;y<16;++y)for(unsigned x=0;x<32;++x){auto* row=reinterpret_cast<uint16_t*>(f->data[1]+y*f->linesize[1]);row[x*2]=uint16_t(512u<<6);row[x*2+1]=uint16_t(vCode<<6);}
+ pipeline::ColorDescription color;color.pixelFormat=pipeline::SourcePixelFormat::P010;color.transfer=pipeline::TransferFunction::PQ;color.matrix=pipeline::YuvMatrix::BT2020NCL;
+ color.range=pipeline::ColorRange::Limited;color.fullRangeChroma=fullChroma;
+ pipeline::EnhanceGraph::FrameOutputs out;bool ok=graph.process(f,0,true,out,1,&color);
+ if(ok){
+ auto* texture=graph.videoFrameResource(out.videoSlot);auto desc=texture->GetDesc();D3D12_PLACED_SUBRESOURCE_FOOTPRINT footprint{};UINT64 size=0;ctx.device()->GetCopyableFootprints(&desc,0,1,0,&footprint,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;ok=SUCCEEDED(ctx.device()->CreateCommittedResource(&hp,D3D12_HEAP_FLAG_NONE,&bd,D3D12_RESOURCE_STATE_COPY_DEST,nullptr,IID_PPV_ARGS(&read)));
+ uint32_t slot=0;auto* list=ok?ring.acquireNext(slot,st):nullptr;ok=list!=nullptr;
+ if(ok){pipeline::StateTracker states;states.transition(list,texture,D3D12_RESOURCE_STATE_COPY_SOURCE);
+ 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=footprint;list->CopyTextureRegion(&b,0,0,0,&a,nullptr);states.transition(list,texture,D3D12_RESOURCE_STATE_COMMON);
+ ok=ring.submitAndSignal(slot)&&ring.waitIdle();}
+ void* ptr=nullptr;D3D12_RANGE range{0,size};
+ if(ok&&SUCCEEDED(read->Map(0,&range,&ptr))){const auto* values=reinterpret_cast<uint16_t*>(static_cast<uint8_t*>(ptr)+footprint.Offset+footprint.Footprint.RowPitch*16);
+ for(unsigned c=0;c<3;++c)rgb[c]=DirectX::PackedVector::XMConvertHalfToFloat(values[32*4+c]);D3D12_RANGE written{};read->Unmap(0,&written);}
+ else ok=false;
+ }
+ out={};ring.drainQueue();graph.shutdown();av_frame_free(&f);return ok;
+ };
+ float fullChroma[3]{},equivalent[3]{},limited[3]{};
+ const unsigned code=512+120,equivalentCode=512+unsigned(std::lround(120*896.0/1023.0)); // keeps red below the PQ ceiling
+ bool ok=decode(code,true,fullChroma)&&decode(equivalentCode,false,equivalent)&&decode(code,false,limited);
+ double sameError=0;for(unsigned c=0;c<3;++c)sameError=std::max(sameError,double(std::abs(fullChroma[c]-equivalent[c]))/std::max(.05,double(std::abs(equivalent[c]))));
+ ok=ok&&sameError<.02&&limited[0]>fullChroma[0]*1.05;
+ std::cout<<"HDR_P010_FULL_CHROMA full="<<fullChroma[0]<<","<<fullChroma[1]<<","<<fullChroma[2]<<" equivalentLimited="<<equivalent[0]<<","<<equivalent[1]<<","<<equivalent[2]
+ <<" sameCodeLimited="<<limited[0]<<","<<limited[1]<<","<<limited[2]<<" relativeError="<<sameError<<" pass="<<ok<<std::endl;if(!ok)++failures;
+ }
if(argc>1)for(unsigned mode=0;mode<3;++mode)for(bool hardware:{false,true}){
source::MediaFileSource source;source::SourceOpenDesc sd;sd.path=argv[1];sd.preferHardwareDecode=hardware;sd.d3d12Device=ctx.device();sd.d3d12Queue=ctx.directQueue();
if(!source.open(sd))return 8;
diff --git a/tests/unit/ElgatoHdrCases.h b/tests/unit/ElgatoHdrCases.h
index 4fd75f9f..f5099563 100644
--- a/tests/unit/ElgatoHdrCases.h
+++ b/tests/unit/ElgatoHdrCases.h
@@ -39,6 +39,8 @@ template<class Check> void elgatoHdrCases(Check check) {
constexpr auto name=L"Game Capture 4K60 Pro MK.2";
const auto defaults=[] {pipeline::ColorDescription c;c.matrixAssumed=c.primariesAssumed=c.transferAssumed=true;c.transfer=pipeline::TransferFunction::SRGB;c.range=pipeline::ColorRange::Limited;return c;};
check(source::isElgatoMk2(name)&&source::isElgatoMk2(L"elgato game capture 4k60 pro mk.2")&&!source::isElgatoMk2(L"Elgato 4K Pro"),"MK.2 exact device aliases only");
+ check(source::isElgatoDevice(name)&&source::isElgatoDevice(L"Elgato 4K X")&&source::isElgatoDevice(L"Game Capture HD60 X")&&
+ !source::isElgatoDevice(L"Other Capture")&&!source::isElgatoDevice(L"USB Video")&&!source::isElgatoDevice(L"AVerMedia Live Gamer 4K"),"Elgato identity: vendor names and the Game Capture family only");
ElgatoProperties ps;ps.hdr();
auto parsed=source::parseElgatoHdrPacket(ps.packet);
check(parsed.valid&&parsed.eotf==2&&parsed.peak==1000&&parsed.maxCll==400&&parsed.maxFall==100,"HDR InfoFrame PQ and little endian mastering metadata");
@@ -50,7 +52,7 @@ template<class Check> void elgatoHdrCases(Check check) {
ps.hdr();auto color=defaults();
{
source::ElgatoHdrControl control;
- check(control.configure(&ps,name,true,0,color)&&ps.mode==0&&color.transfer==pipeline::TransferFunction::PQ&&color.range==pipeline::ColorRange::Limited&&color.hdrMaxCllNits==400,"auto HDR disables card tonemap and propagates metadata without changing range");
+ check(control.configure(&ps,name,true,0,color)&&ps.mode==0&&color.transfer==pipeline::TransferFunction::PQ&&color.range==pipeline::ColorRange::Limited&&color.hdrMaxCllNits==400&&!color.fullRangeChroma,"auto HDR disables card tonemap and propagates metadata without changing range (MK.2 keeps standard chroma)");
}
check(ps.mode==1&&ps.sets==2,"close restores readable initial hardware state");
ps={};ps.hdr();ps.mode=0;color=defaults();
@@ -73,9 +75,41 @@ template<class Check> void elgatoHdrCases(Check check) {
source::ElgatoHdrControl control;
check(control.configure(&ps,L"Other Capture",true,1,color)&&ps.gets==0&&ps.sets==0,"other devices receive zero vendor calls");
}
- {
+ ps={};ps.hdr();ps.mode=0;color=defaults();{
+ // OBS libdshowcapture parity: 8-bit formats ask the card to tone map HDR.
+ source::ElgatoHdrControl control;
+ check(control.configure(&ps,name,false,0,color)&&ps.mode==1&&!color.isHdrPath()&&!color.fullRangeChroma,"8-bit format enables the hardware tonemapper");
+ }
+ check(ps.mode==0,"8-bit close restores the original tonemapper state");
+ ps={};ps.mode=1;color=defaults();{
+ source::ElgatoHdrControl control;
+ check(control.configure(&ps,name,false,0,color)&&ps.sets==0,"8-bit with tonemapper already on writes nothing");
+ }
+ ps={};ps.hdr();ps.rejectSet=true;ps.readableMode=false;color=defaults();{
+ source::ElgatoHdrControl control;
+ check(control.configure(&ps,L"Elgato 4K X",false,0,color),"8-bit on a card without the vendor set still connects");
+ }
+ constexpr auto x4k=L"Elgato 4K X";
+ ps={};ps.hdr();color=defaults();{
+ source::ElgatoHdrControl control;
+ check(control.configure(&ps,x4k,true,0,color)&&ps.mode==0&&color.transfer==pipeline::TransferFunction::PQ&&color.range==pipeline::ColorRange::Limited&&color.fullRangeChroma,
+ "non-MK.2 P010: tonemapper off and limited luma with full-range chroma (Nitlink)");
+ }
+ ps={};ps.hdr();color=defaults();{
+ source::ElgatoHdrControl control;
+ check(control.configure(&ps,x4k,true,4,color)&&!color.fullRangeChroma,"explicit limited range keeps standard chroma on non-MK.2");
+ }
+ ps={};ps.hdr();color=defaults();color.range=pipeline::ColorRange::Full;color.rangeAssumed=false;{
+ source::ElgatoHdrControl control;
+ check(control.configure(&ps,x4k,true,0,color)&&!color.fullRangeChroma,"driver-declared full range is left as full");
+ }
+ ps={};ps.rejectSet=true;ps.readableMode=false;color=defaults();{
+ source::ElgatoHdrControl control;
+ check(control.configure(&ps,x4k,true,1,color)&&color.fullRangeChroma,"non-MK.2 without the vendor set connects with explicit PQ (control unavailable is not fatal)");
+ }
+ ps={};ps.hdr();color=defaults();{
source::ElgatoHdrControl control;
- check(control.configure(&ps,name,false,0,color)&&ps.gets==0,"non-P010 receives zero vendor calls");
+ check(control.configure(&ps,L"Other Capture",false,0,color)&&ps.gets==0&&ps.sets==0&&!color.fullRangeChroma,"other devices receive zero vendor calls for 8-bit formats");
}
ps={};color=defaults();{
source::ElgatoHdrControl control;