Skip to content

Commit 6afffbc

Browse files
committed
drm: add shaper LUT and 3D LUT colorops
Instead of struct drm_color_lut, shaper and 3D LUTs follow struct drm_color_lut32, which means 32-bit for each channel, not 16-bit anymore. Create a helper to make possible reuse LUTs already created for AMD driver-specific color properties. Assisted-by: Claude Code <Sonnet 4.6> Signed-off-by: Melissa Wen <mwen@igalia.com>
1 parent e28eb23 commit 6afffbc

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/Backends/DRMBackend.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ struct drm_t {
134134
uint32_t color_mgmt_serial;
135135
std::shared_ptr<gamescope::BackendBlob> lut3d_id[ EOTF_Count ];
136136
std::shared_ptr<gamescope::BackendBlob> shaperlut_id[ EOTF_Count ];
137+
std::shared_ptr<gamescope::BackendBlob> lut3d_colorop_id[ EOTF_Count ];
138+
std::shared_ptr<gamescope::BackendBlob> shaperlut_colorop_id[ EOTF_Count ];
137139
amdgpu_transfer_function output_tf = AMDGPU_TRANSFER_FUNCTION_DEFAULT;
138140
} current, pending;
139141

@@ -3042,6 +3044,20 @@ drm_prepare_liftoff( struct drm_t *drm, const struct FrameInfo_t *frameInfo, boo
30423044
p->shaper->GetProperties().BYPASS->SetPendingValue( drm->req, 1, true );
30433045
}
30443046

3047+
if ( bUseShaperAnd3DLUT )
3048+
{
3049+
p->shaperLut->GetProperties().BYPASS->SetPendingValue( drm->req, 0, true );
3050+
p->shaperLut->GetProperties().DATA->SetPendingValue( drm->req, drm->pending.shaperlut_colorop_id[ ColorSpaceToEOTFIndex( colorspace ) ]->GetBlobValue(), true );
3051+
3052+
p->lut3D->GetProperties().BYPASS->SetPendingValue( drm->req, 0, true );
3053+
p->lut3D->GetProperties().DATA->SetPendingValue( drm->req, drm->pending.lut3d_colorop_id[ ColorSpaceToEOTFIndex( colorspace ) ]->GetBlobValue(), true );
3054+
}
3055+
else
3056+
{
3057+
p->shaperLut->GetProperties().BYPASS->SetPendingValue( drm->req, 1, true );
3058+
p->lut3D->GetProperties().BYPASS->SetPendingValue( drm->req, 1, true );
3059+
}
3060+
30453061
std::optional<drm_colorop_curve_1d_type> blend_tf = amd_tf_to_drm_curve(drm->pending.output_tf);
30463062
if (!cv_drm_debug_disable_blend_tf && !bSinglePlane && blend_tf.has_value() )
30473063
{
@@ -3460,6 +3476,15 @@ gamescope::GamescopeScreenType drm_get_screen_type(struct drm_t *drm)
34603476
return drm->pConnector->GetScreenType();
34613477
}
34623478

3479+
template <size_t N>
3480+
static std::array<uint32_t, N> lut_convert_16bit_to_32bit( const uint16_t (&lut)[N] )
3481+
{
3482+
std::array<uint32_t, N> out;
3483+
for ( size_t i = 0; i < N; i++ )
3484+
out[i] = (uint32_t)lut[i] * 0x10001u;
3485+
return out;
3486+
}
3487+
34633488
bool drm_update_color_mgmt(struct drm_t *drm)
34643489
{
34653490
if ( !drm_supports_color_mgmt( drm ) && !drm_supports_color_pipeline ( &g_DRM ) )
@@ -3474,6 +3499,8 @@ bool drm_update_color_mgmt(struct drm_t *drm)
34743499
{
34753500
drm->pending.shaperlut_id[ i ] = 0;
34763501
drm->pending.lut3d_id[ i ] = 0;
3502+
drm->pending.shaperlut_colorop_id[ i ] = 0;
3503+
drm->pending.lut3d_colorop_id[ i ] = 0;
34773504
}
34783505

34793506
for ( uint32_t i = 0; i < EOTF_Count; i++ )
@@ -3483,6 +3510,9 @@ bool drm_update_color_mgmt(struct drm_t *drm)
34833510

34843511
drm->pending.shaperlut_id[ i ] = GetBackend()->CreateBackendBlob( g_ColorMgmtLuts[i].lut1d );
34853512
drm->pending.lut3d_id[ i ] = GetBackend()->CreateBackendBlob( g_ColorMgmtLuts[i].lut3d );
3513+
3514+
drm->pending.shaperlut_colorop_id[ i ] = GetBackend()->CreateBackendBlob( lut_convert_16bit_to_32bit( g_ColorMgmtLuts[i].lut1d ) );
3515+
drm->pending.lut3d_colorop_id[ i ] = GetBackend()->CreateBackendBlob( lut_convert_16bit_to_32bit( g_ColorMgmtLuts[i].lut3d ) );
34863516
}
34873517

34883518
return true;

0 commit comments

Comments
 (0)