[host] d12: implement hdr16 to hdr10 conversion

This commit is contained in:
Geoffrey McRae
2024-02-28 11:59:58 +11:00
parent 0184ddeedd
commit ad7ac6540f
11 changed files with 670 additions and 117 deletions

View File

@@ -24,6 +24,7 @@
#include "common/debug.h"
#include "common/windebug.h"
#include "common/display.h"
#include <dxgi1_6.h>
@@ -92,7 +93,7 @@ static bool sdrWhiteLevel_setup(
DXGI_OUTPUT_DESC1 desc1;
IDXGIOutput6_GetDesc1(*output6, &desc1);
if (!getDisplayPathInfo(desc1.Monitor, &this.displayPathInfo))
if (!display_getPathInfo(desc1.Monitor, &this.displayPathInfo))
{
DEBUG_ERROR("Failed to get the display path info");
goto exit;
@@ -214,7 +215,7 @@ static void sdrWhiteLevel_free(void * opaque)
static void updateConsts(void)
{
float nits = getSDRWhiteLevel(&this.displayPathInfo);
float nits = display_getSDRWhiteLevel(&this.displayPathInfo);
if (nits == this.sdrWhiteLevel)
return;

View File

@@ -224,104 +224,6 @@ bool compileShader(ID3DBlob ** dst, const char * entry, const char * target,
return true;
}
bool getDisplayPathInfo(HMONITOR monitor, DISPLAYCONFIG_PATH_INFO * info)
{
bool result = false;
UINT32 numPath, numMode;
MONITORINFOEXW viewInfo = { .cbSize = sizeof(viewInfo) };
if (!GetMonitorInfoW(monitor, (MONITORINFO*)&viewInfo))
{
DEBUG_ERROR("Failed to get the monitor info");
goto err;
}
err_retry:
if (FAILED(GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &numPath, &numMode)))
goto err;
DISPLAYCONFIG_PATH_INFO * pathInfo = calloc(sizeof(*pathInfo), numPath);
if (!pathInfo)
goto err_mem_pathInfo;
DISPLAYCONFIG_MODE_INFO * modeInfo = calloc(sizeof(*modeInfo), numMode);
if (!modeInfo)
goto err_mem_modeInfo;
LONG status = QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS,
&numPath, pathInfo,
&numMode, modeInfo,
NULL);
if (status != ERROR_SUCCESS)
{
if (status == ERROR_INSUFFICIENT_BUFFER)
{
free(modeInfo);
free(pathInfo);
goto err_retry;
}
DEBUG_ERROR("QueryDisplayConfig failed with 0x%lx", status);
goto err_queryDisplay;
}
for(unsigned i = 0; i < numPath; ++i)
{
DISPLAYCONFIG_SOURCE_DEVICE_NAME sourceName =
{
.header =
{
.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME,
.size = sizeof(sourceName),
.adapterId = pathInfo[i].sourceInfo.adapterId,
.id = pathInfo[i].sourceInfo.id,
}
};
if (FAILED(DisplayConfigGetDeviceInfo(&sourceName.header)))
continue;
if (wcscmp(viewInfo.szDevice, sourceName.viewGdiDeviceName) != 0)
continue;
*info = pathInfo[i];
result = true;
break;
}
err_queryDisplay:
free(modeInfo);
err_mem_modeInfo:
free(pathInfo);
err_mem_pathInfo:
err:
return result;
}
float getSDRWhiteLevel(const DISPLAYCONFIG_PATH_INFO * displayPathInfo)
{
float nits = 80.0f;
DISPLAYCONFIG_SDR_WHITE_LEVEL level =
{
.header =
{
.type = DISPLAYCONFIG_DEVICE_INFO_GET_SDR_WHITE_LEVEL,
.size = sizeof(level),
.adapterId = displayPathInfo->targetInfo.adapterId,
.id = displayPathInfo->targetInfo.id,
}
};
if (SUCCEEDED(DisplayConfigGetDeviceInfo(&level.header)))
nits = level.SDRWhiteLevel / 1000.0f * 80.0f;
return nits;
}
DXGI_FORMAT getDXGIFormat(CaptureFormat format)
{
switch(format)

View File

@@ -30,8 +30,4 @@ const char * getDXGIColorSpaceTypeStr(DXGI_COLOR_SPACE_TYPE type);
bool compileShader(ID3DBlob ** dst, const char * entry, const char * target,
const char * code, const D3D_SHADER_MACRO * defines);
bool getDisplayPathInfo(HMONITOR monitor, DISPLAYCONFIG_PATH_INFO * info);
float getSDRWhiteLevel(const DISPLAYCONFIG_PATH_INFO * displayPathInfo);
DXGI_FORMAT getDXGIFormat(CaptureFormat format);