From 4206046f12b7f029ff95c6fda4fd5bfc81564131 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Tue, 28 Sep 2021 22:31:11 +0200 Subject: [PATCH] Re-enable proper gamma ramps with AMS Instead of downgrading everyone else to legacy gamma, only exclude the huge and buggy gamma ramp of Intel TIgerLake hardware. --- src/colordevice.cpp | 3 ++- src/plugins/platforms/drm/drm_object_crtc.cpp | 5 +++++ src/plugins/platforms/drm/drm_object_crtc.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/colordevice.cpp b/src/colordevice.cpp index f3e902b915..585b867dec 100644 --- a/src/colordevice.cpp +++ b/src/colordevice.cpp @@ -353,7 +353,8 @@ void ColorDevice::update() uint16_t *blueChannel = gammaRamp.blue(); for (uint32_t i = 0; i < gammaRamp.size(); ++i) { - const uint16_t index = (i * 0xffff) / (gammaRamp.size() - 1); + // ensure 64 bit calculation to prevent overflows + const uint16_t index = (static_cast(i) * 0xffff) / (gammaRamp.size() - 1); const uint16_t in[3] = { index, index, index }; uint16_t out[3] = { 0 }; diff --git a/src/plugins/platforms/drm/drm_object_crtc.cpp b/src/plugins/platforms/drm/drm_object_crtc.cpp index c6f3c73f7f..3979b0b4f1 100644 --- a/src/plugins/platforms/drm/drm_object_crtc.cpp +++ b/src/plugins/platforms/drm/drm_object_crtc.cpp @@ -24,6 +24,7 @@ DrmCrtc::DrmCrtc(DrmGpu *gpu, uint32_t crtcId, int pipeIndex, DrmPlane *primaryP PropertyDefinition(QByteArrayLiteral("ACTIVE"), Requirement::Required), PropertyDefinition(QByteArrayLiteral("VRR_ENABLED"), Requirement::Optional), PropertyDefinition(QByteArrayLiteral("GAMMA_LUT"), Requirement::Optional), + PropertyDefinition(QByteArrayLiteral("GAMMA_LUT_SIZE"), Requirement::Optional) }, DRM_MODE_OBJECT_CRTC) , m_crtc(drmModeGetCrtc(gpu->fd(), crtcId)) , m_pipeIndex(pipeIndex) @@ -81,6 +82,10 @@ void DrmCrtc::setNext(const QSharedPointer &buffer) int DrmCrtc::gammaRampSize() const { + // limit atomic gamma ramp to 4096 to work around https://gitlab.freedesktop.org/drm/intel/-/issues/3916 + if (auto prop = getProp(PropertyIndex::Gamma_LUT_Size); prop && prop->current() <= 4096) { + return prop->current(); + } return m_crtc->gamma_size; } diff --git a/src/plugins/platforms/drm/drm_object_crtc.h b/src/plugins/platforms/drm/drm_object_crtc.h index 1b31189fe6..ce285bd314 100644 --- a/src/plugins/platforms/drm/drm_object_crtc.h +++ b/src/plugins/platforms/drm/drm_object_crtc.h @@ -34,6 +34,7 @@ public: Active, VrrEnabled, Gamma_LUT, + Gamma_LUT_Size, Count };