mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-22 07:01:30 +00:00
[idd] postprocess: centralize color transform state
This commit is contained in:
@@ -241,13 +241,14 @@ NTSTATUS LGIddMonitorSetGammaRamp(IDDCX_MONITOR monitor, const IDARG_IN_SET_GAMM
|
|||||||
transform->lut[i][3] = 1.0f;
|
transform->lut[i][3] = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsIdentityColorTransform(*transform))
|
auto active = D12::Transform(transform);
|
||||||
|
if (!active)
|
||||||
{
|
{
|
||||||
control.SetColorTransform(nullptr);
|
control.SetColorTransform(nullptr);
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
control.SetColorTransform(std::move(transform));
|
control.SetColorTransform(std::move(active));
|
||||||
DEBUG_INFO("Display color transform updated (matrix:%d lut:%d)",
|
DEBUG_INFO("Display color transform updated (matrix:%d lut:%d)",
|
||||||
input->MatrixEnabled, input->LutEnabled);
|
input->MatrixEnabled, input->LutEnabled);
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
|
|||||||
@@ -30,46 +30,6 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
bool NearlyEqual(float a, float b, float tolerance)
|
|
||||||
{
|
|
||||||
const float delta = a - b;
|
|
||||||
return delta >= -tolerance && delta <= tolerance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsIdentityColorTransform(const D12ColorTransform& transform)
|
|
||||||
{
|
|
||||||
static const float matrixTolerance = 1.0f / 1048576.0f;
|
|
||||||
static const float lutTolerance = 1.0f / 65535.0f;
|
|
||||||
|
|
||||||
if (transform.matrixEnabled)
|
|
||||||
{
|
|
||||||
for (unsigned row = 0; row < 3; ++row)
|
|
||||||
for (unsigned column = 0; column < 4; ++column)
|
|
||||||
{
|
|
||||||
const float expected = row == column ? 1.0f : 0.0f;
|
|
||||||
const float effective =
|
|
||||||
transform.matrix[row][column] * transform.scalar;
|
|
||||||
if (!NearlyEqual(effective, expected, matrixTolerance))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transform.lutEnabled)
|
|
||||||
for (unsigned i = 0; i < 4096; ++i)
|
|
||||||
{
|
|
||||||
const float expected = (float)i / 4095.0f;
|
|
||||||
if (!NearlyEqual(transform.lut[i][0], expected, lutTolerance) ||
|
|
||||||
!NearlyEqual(transform.lut[i][1], expected, lutTolerance) ||
|
|
||||||
!NearlyEqual(transform.lut[i][2], expected, lutTolerance))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CPostProcessor::Init(std::shared_ptr<CD3D12Device> dx12Device,
|
bool CPostProcessor::Init(std::shared_ptr<CD3D12Device> dx12Device,
|
||||||
bool enableEffects)
|
bool enableEffects)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,6 +22,55 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
bool NearlyEqual(float a, float b, float tolerance)
|
||||||
|
{
|
||||||
|
const float delta = a - b;
|
||||||
|
return delta >= -tolerance && delta <= tolerance;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Identity(const D12ColorTransform& transform)
|
||||||
|
{
|
||||||
|
static const float matrixTolerance = 1.0f / 1048576.0f;
|
||||||
|
static const float lutTolerance = 1.0f / 65535.0f;
|
||||||
|
|
||||||
|
if (transform.matrixEnabled)
|
||||||
|
{
|
||||||
|
for (unsigned row = 0; row < 3; ++row)
|
||||||
|
for (unsigned column = 0; column < 4; ++column)
|
||||||
|
{
|
||||||
|
const float expected = row == column ? 1.0f : 0.0f;
|
||||||
|
const float effective =
|
||||||
|
transform.matrix[row][column] * transform.scalar;
|
||||||
|
if (!NearlyEqual(effective, expected, matrixTolerance))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transform.lutEnabled)
|
||||||
|
for (unsigned i = 0; i < 4096; ++i)
|
||||||
|
{
|
||||||
|
const float expected = static_cast<float>(i) / 4095.0f;
|
||||||
|
if (!NearlyEqual(transform.lut[i][0], expected, lutTolerance) ||
|
||||||
|
!NearlyEqual(transform.lut[i][1], expected, lutTolerance) ||
|
||||||
|
!NearlyEqual(transform.lut[i][2], expected, lutTolerance))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<const D12ColorTransform> D12::Transform(
|
||||||
|
const std::shared_ptr<const D12ColorTransform>& transform)
|
||||||
|
{
|
||||||
|
if (!transform || (!transform->matrixEnabled && !transform->lutEnabled) ||
|
||||||
|
Identity(*transform))
|
||||||
|
return nullptr;
|
||||||
|
return transform;
|
||||||
|
}
|
||||||
|
|
||||||
FrameType D12::Type(DXGI_FORMAT format)
|
FrameType D12::Type(DXGI_FORMAT format)
|
||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ struct D12ColorTransform
|
|||||||
float lut[4096][4] = {};
|
float lut[4096][4] = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
bool IsIdentityColorTransform(const D12ColorTransform& transform);
|
|
||||||
|
|
||||||
struct D12FrameFormat
|
struct D12FrameFormat
|
||||||
{
|
{
|
||||||
D3D12_RESOURCE_DESC desc = {};
|
D3D12_RESOURCE_DESC desc = {};
|
||||||
@@ -89,6 +87,8 @@ namespace D12
|
|||||||
|
|
||||||
FrameType Type(DXGI_FORMAT format);
|
FrameType Type(DXGI_FORMAT format);
|
||||||
void CopyHdr(D12FrameFormat& dst, const D12FrameFormat& src);
|
void CopyHdr(D12FrameFormat& dst, const D12FrameFormat& src);
|
||||||
|
std::shared_ptr<const D12ColorTransform> Transform(
|
||||||
|
const std::shared_ptr<const D12ColorTransform>& transform);
|
||||||
bool Same(const D3D12_RESOURCE_DESC& left,
|
bool Same(const D3D12_RESOURCE_DESC& left,
|
||||||
const D3D12_RESOURCE_DESC& right,
|
const D3D12_RESOURCE_DESC& right,
|
||||||
DescCmp cmp = DescCmp::EXACT);
|
DescCmp cmp = DescCmp::EXACT);
|
||||||
|
|||||||
@@ -208,8 +208,8 @@ PostProcessStatus CColorTransformEffect::SetFormat(
|
|||||||
const ComPtr<ID3D12Device3>& device,
|
const ComPtr<ID3D12Device3>& device,
|
||||||
const D12FrameFormat& src, D12FrameFormat& dst)
|
const D12FrameFormat& src, D12FrameFormat& dst)
|
||||||
{
|
{
|
||||||
if (!src.colorTransform || IsIdentityColorTransform(*src.colorTransform) ||
|
const auto transform = D12::Transform(src.colorTransform);
|
||||||
(!src.colorTransform->matrixEnabled && !src.colorTransform->lutEnabled))
|
if (!transform)
|
||||||
return PostProcessStatus::BYPASS_EFFECT;
|
return PostProcessStatus::BYPASS_EFFECT;
|
||||||
|
|
||||||
DXGI_FORMAT dstFormat;
|
DXGI_FORMAT dstFormat;
|
||||||
@@ -247,16 +247,16 @@ PostProcessStatus CColorTransformEffect::SetFormat(
|
|||||||
return PostProcessStatus::FAILED;
|
return PostProcessStatus::FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::memcpy(m_consts.matrix, src.colorTransform->matrix,
|
std::memcpy(m_consts.matrix, transform->matrix,
|
||||||
sizeof(m_consts.matrix));
|
sizeof(m_consts.matrix));
|
||||||
m_consts.scalar = src.colorTransform->scalar;
|
m_consts.scalar = transform->scalar;
|
||||||
m_consts.matrixEnabled = src.colorTransform->matrixEnabled;
|
m_consts.matrixEnabled = transform->matrixEnabled;
|
||||||
m_consts.lutEnabled = src.colorTransform->lutEnabled;
|
m_consts.lutEnabled = transform->lutEnabled;
|
||||||
m_consts.inputTransfer = src.hdrPQ ? TRANSFER_PQ :
|
m_consts.inputTransfer = src.hdrPQ ? TRANSFER_PQ :
|
||||||
(src.hdr ? TRANSFER_LINEAR : TRANSFER_SRGB);
|
(src.hdr ? TRANSFER_LINEAR : TRANSFER_SRGB);
|
||||||
m_consts.outputTransfer = src.hdr ? TRANSFER_PQ : TRANSFER_SRGB;
|
m_consts.outputTransfer = src.hdr ? TRANSFER_PQ : TRANSFER_SRGB;
|
||||||
|
|
||||||
std::memcpy(m_lut, src.colorTransform->lut, sizeof(m_lut));
|
std::memcpy(m_lut, transform->lut, sizeof(m_lut));
|
||||||
m_uploadPending = true;
|
m_uploadPending = true;
|
||||||
|
|
||||||
m_srcFormat = src.desc.Format;
|
m_srcFormat = src.desc.Format;
|
||||||
|
|||||||
@@ -83,12 +83,7 @@ struct CRGB24Effect::State
|
|||||||
format.desc.Format != DXGI_FORMAT_B8G8R8A8_UNORM)
|
format.desc.Format != DXGI_FORMAT_B8G8R8A8_UNORM)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!format.colorTransform ||
|
return !D12::Transform(format.colorTransform);
|
||||||
(!format.colorTransform->matrixEnabled &&
|
|
||||||
!format.colorTransform->lutEnabled))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return IsIdentityColorTransform(*format.colorTransform);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WantsPackedLocked() const
|
bool WantsPackedLocked() const
|
||||||
|
|||||||
Reference in New Issue
Block a user