Skip to content

Commit

Permalink
[host] dxgi: fix HDR content downsampling
Browse files Browse the repository at this point in the history
  • Loading branch information
gnif committed Nov 7, 2023
1 parent 073220e commit 9b44b85
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
29 changes: 15 additions & 14 deletions host/platform/Windows/capture/DXGI/src/dxgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,28 +739,29 @@ static bool dxgi_init(void)
if (!initVertexShader())
goto fail;

if (!ppInit(&DXGIPP_Downsample,
this->backend != &copyBackendD3D11 && !this->hdr))
{
DEBUG_ERROR("Failed to intiailize the downsample post processor");
goto fail;
}

// if HDR add the SDRWhiteLevel post processor to correct the output
bool shareable = this->backend != &copyBackendD3D11;
if (this->hdr)
{
if (!ppInit(&DXGIPP_SDRWhiteLevel, this->backend != &copyBackendD3D11))
//HDR content needs to be corrected and converted to HDR10
if (!ppInit(&DXGIPP_SDRWhiteLevel, shareable))
{
DEBUG_ERROR("Failed to initialize the SDRWhiteLevel post processor");
goto fail;
}
}
else

//Downsampling must happen before conversion to RGB24
if (!ppInit(&DXGIPP_Downsample, shareable))
{
DEBUG_ERROR("Failed to intiailize the downsample post processor");
goto fail;
}

//If not HDR, pack to RGB24
if (!this->hdr)
{
// only support DX11 for this atm
if (this->backend == &copyBackendD3D11)
if (!ppInit(&DXGIPP_RGB24, false))
DEBUG_WARN("Failed to initialize the RGB24 post processor");
if (!ppInit(&DXGIPP_RGB24, shareable))
DEBUG_WARN("Failed to initialize the RGB24 post processor");
}

for (int i = 0; i < LGMP_Q_FRAME_LEN; ++i)
Expand Down
2 changes: 1 addition & 1 deletion host/platform/Windows/capture/DXGI/src/pp/downsample.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static bool downsample_configure(void * opaque,
.SampleDesc.Count = 1,
.SampleDesc.Quality = 0,
.Usage = D3D11_USAGE_DEFAULT,
.Format = DXGI_FORMAT_B8G8R8A8_UNORM,
.Format = getDXGIFormat(*format),
.BindFlags = D3D11_BIND_RENDER_TARGET |
D3D11_BIND_SHADER_RESOURCE,
.CPUAccessFlags = 0,
Expand Down
28 changes: 28 additions & 0 deletions host/platform/Windows/capture/DXGI/src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "util.h"
#include "common/debug.h"

#include <d3d11.h>
Expand Down Expand Up @@ -320,3 +321,30 @@ float getSDRWhiteLevel(const DISPLAYCONFIG_PATH_INFO * displayPathInfo)

return nits;
}

DXGI_FORMAT getDXGIFormat(CaptureFormat format)
{
switch(format)
{
case CAPTURE_FMT_RGBA:
return DXGI_FORMAT_R8G8B8A8_UNORM;

case CAPTURE_FMT_BGRA:
return DXGI_FORMAT_B8G8R8A8_UNORM;

case CAPTURE_FMT_RGBA10:
return DXGI_FORMAT_R10G10B10A2_UNORM;

case CAPTURE_FMT_RGBA16F:
return DXGI_FORMAT_R16G16B16A16_FLOAT;

case CAPTURE_FMT_BGR:
return DXGI_FORMAT_B8G8R8A8_UNORM;

default:
break;
}

DEBUG_ASSERT("Invalid capture format for DXGI");
return 0;
}
5 changes: 5 additions & 0 deletions host/platform/Windows/capture/DXGI/src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
*/

#include <windows.h>
#include <d3dcommon.h>
#include <dxgi.h>

#include "interface/capture.h"

const char * getDXGIFormatStr(DXGI_FORMAT format);
const char * getDXGIColorSpaceTypeStr(DXGI_COLOR_SPACE_TYPE type);

Expand All @@ -30,3 +33,5 @@ bool compileShader(ID3DBlob ** dst, const char * entry, const char * target,
bool getDisplayPathInfo(HMONITOR monitor, DISPLAYCONFIG_PATH_INFO * info);

float getSDRWhiteLevel(const DISPLAYCONFIG_PATH_INFO * displayPathInfo);

DXGI_FORMAT getDXGIFormat(CaptureFormat format);

0 comments on commit 9b44b85

Please sign in to comment.