The LUT_3D_FORMATS entry of the DMA 3D LUT colorop hard-codes a 256-byte
row pitch. The required pitch depends on the row alignment of the DCN
generation, which DC now reports through the 3D LUT pitch_alignment cap.

Build the advertised mode when the DMA 3D LUT pipeline is created and
compute its pitch by aligning one LUT row to the reported alignment.
Only expose the DMA 3D LUT pipeline when DC reports a pitch alignment.

For the 17x17x17 XBGR16161616 LUT the pitch remains 256 bytes for both
128- and 256-byte alignment, so this has no functional effect on
current hardware.

Signed-off-by: Harry Wentland <[email protected]>
---
 .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 33 +++++++++----------
 .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h |  3 +-
 .../amd/display/amdgpu_dm/amdgpu_dm_plane.c   |  1 +
 .../amdgpu_dm/tests/amdgpu_dm_colorop_test.c  |  4 +--
 4 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c
index 5e6e40b5fd7d..b737b45fb2f4 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c
@@ -72,17 +72,6 @@ const u64 amdgpu_dm_supported_fm =
 
 #define LUT3D_SIZE             17
 
-static const struct drm_mode_3dlut_mode amdgpu_dm_3dlut_dma_modes[] = {
-       {
-               .lut_size = LUT3D_SIZE,
-               .format = DRM_FORMAT_XBGR16161616,
-               .modifier = DRM_FORMAT_MOD_LINEAR,
-               .pitch = 256,
-               .traversal_order = DRM_COLOROP_LUT3D_TRAVERSAL_RGB,
-               .interpolation = DRM_COLOROP_LUT3D_INTERPOLATION_TETRAHEDRAL,
-       },
-};
-
 static const struct drm_colorop_funcs dm_colorop_funcs = {
        .destroy = drm_colorop_destroy,
 };
@@ -210,7 +199,8 @@ static const struct drm_colorop_helper_funcs 
dm_colorop_helper_funcs = {
 
 STATIC_IFN_KUNIT int
 amdgpu_dm_build_default_pipeline(struct drm_device *dev, struct drm_plane 
*plane,
-                                 bool hw_3d_lut, bool dma_3d_lut,
+                                 bool hw_3d_lut,
+                                 const struct drm_mode_3dlut_mode 
*dma_3dlut_mode,
                                  struct drm_prop_enum_list *list)
 {
        struct drm_colorop *ops[MAX_COLOR_PIPELINE_OPS];
@@ -328,10 +318,9 @@ amdgpu_dm_build_default_pipeline(struct drm_device *dev, 
struct drm_plane *plane
                        goto cleanup;
                }
 
-               if (dma_3d_lut) {
+               if (dma_3dlut_mode) {
                        ret = drm_plane_colorop_3dlut_dma_init(dev, ops[i], 
plane,
-                                       &dm_colorop_funcs, 
amdgpu_dm_3dlut_dma_modes,
-                                       ARRAY_SIZE(amdgpu_dm_3dlut_dma_modes),
+                                       &dm_colorop_funcs, dma_3dlut_mode, 1,
                                        DRM_COLOROP_FLAG_ALLOW_BYPASS);
                        drm_colorop_helper_add(ops[i], 
&dm_colorop_helper_funcs);
                } else {
@@ -402,7 +391,7 @@ int amdgpu_dm_initialize_default_pipeline(struct drm_plane 
*plane, struct drm_pr
        bool hw_3d_lut = adev->dm.dc->caps.color.dpp.hw_3d_lut ||
                         adev->dm.dc->caps.color.mpc.preblend;
 
-       return amdgpu_dm_build_default_pipeline(dev, plane, hw_3d_lut, false, 
list);
+       return amdgpu_dm_build_default_pipeline(dev, plane, hw_3d_lut, NULL, 
list);
 }
 EXPORT_IF_KUNIT(amdgpu_dm_initialize_default_pipeline);
 
@@ -412,6 +401,16 @@ int amdgpu_dm_initialize_dma_3dlut_pipeline(struct 
drm_plane *plane, struct drm_
        struct amdgpu_device *adev = drm_to_adev(dev);
        bool hw_3d_lut = adev->dm.dc->caps.color.dpp.hw_3d_lut ||
                         adev->dm.dc->caps.color.mpc.preblend;
+       struct drm_mode_3dlut_mode mode = {
+               .lut_size = LUT3D_SIZE,
+               .format = DRM_FORMAT_XBGR16161616,
+               .modifier = DRM_FORMAT_MOD_LINEAR,
+               .traversal_order = DRM_COLOROP_LUT3D_TRAVERSAL_RGB,
+               .interpolation = DRM_COLOROP_LUT3D_INTERPOLATION_TETRAHEDRAL,
+       };
 
-       return amdgpu_dm_build_default_pipeline(dev, plane, hw_3d_lut, true, 
list);
+       mode.pitch = ALIGN(mode.lut_size * drm_format_info(mode.format)->cpp[0],
+                          
adev->dm.dc->caps.color.mpc.mcm_3d_lut_caps.pitch_alignment);
+
+       return amdgpu_dm_build_default_pipeline(dev, plane, hw_3d_lut, &mode, 
list);
 }
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h
index 58604773db75..ac0f26ffef32 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h
@@ -67,7 +67,8 @@ struct amdgpu_dm_colorop_kunit_ops {
 };
 
 int amdgpu_dm_build_default_pipeline(struct drm_device *dev, struct drm_plane 
*plane,
-                                     bool hw_3d_lut, bool dma_3d_lut,
+                                     bool hw_3d_lut,
+                                     const struct drm_mode_3dlut_mode 
*dma_3dlut_mode,
                                      struct drm_prop_enum_list *list);
 void amdgpu_dm_colorop_kunit_set_ops(const struct amdgpu_dm_colorop_kunit_ops 
*ops);
 #endif
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
index 469041145196..aad146d9c6a7 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
@@ -2217,6 +2217,7 @@ dm_plane_init_colorops(struct drm_plane *plane)
                 */
                if (IS_ENABLED(CONFIG_DRM_AMD_DC_3DLUT_DMA) &&
                    dc->caps.color.mpc.mcm_3d_lut_caps.dma_3d_lut &&
+                   dc->caps.color.mpc.mcm_3d_lut_caps.pitch_alignment &&
                    (dc->caps.color.dpp.hw_3d_lut || 
dc->caps.color.mpc.preblend)) {
                        ret = amdgpu_dm_initialize_dma_3dlut_pipeline(plane, 
&pipelines[len]);
                        if (ret) {
diff --git 
a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_colorop_test.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_colorop_test.c
index 49d1d252a67d..fda30c29a81f 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_colorop_test.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_colorop_test.c
@@ -208,7 +208,7 @@ static void dm_test_initialize_default_pipeline(struct 
kunit *test)
 
        plane = dm_colorop_alloc_plane(test, &drm);
 
-       ret = amdgpu_dm_build_default_pipeline(drm, plane, true, false, &list);
+       ret = amdgpu_dm_build_default_pipeline(drm, plane, true, NULL, &list);
        KUNIT_ASSERT_EQ(test, ret, 0);
        kfree(list.name);
 
@@ -430,7 +430,7 @@ static int dm_colorop_build_with_fault(struct kunit *test, 
struct drm_device **d
        amdgpu_dm_colorop_kunit_set_ops(&dm_colorop_test_ops);
        KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, 
dm_colorop_test_reset_ops, NULL), 0);
 
-       ret = amdgpu_dm_build_default_pipeline(*drm, plane, true, false, &list);
+       ret = amdgpu_dm_build_default_pipeline(*drm, plane, true, NULL, &list);
        kfree(list.name);
 
        return ret;
-- 
2.56.0

Reply via email to