From patchwork Wed Jun 1 09:03:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [V4,1/3] lib/igt_kms: Add helper functions to sort drm modes From: Bhanuprakash Modem X-Patchwork-Id: 487932 Message-Id: <20220601090302.3947338-2-bhanuprakash.modem@intel.com> To: intel-gfx-trybot@lists.freedesktop.org Date: Wed, 1 Jun 2022 14:33:00 +0530 Add helper function to sort drm modes based on the clock, resolution in both ascending & descending order. V2: * Minor changes V3: * Added documentaion for helper functions Signed-off-by: Bhanuprakash Modem Reviewed-by: Ankit Nautiyal --- lib/igt_kms.c | 90 ++++++++++++++++++++++++++++++++++++++++++--------- lib/igt_kms.h | 10 ++++++ 2 files changed, 85 insertions(+), 15 deletions(-) diff --git a/lib/igt_kms.c b/lib/igt_kms.c index a25fac74..af4fb85b 100644 --- a/lib/igt_kms.c +++ b/lib/igt_kms.c @@ -1477,6 +1477,78 @@ void kmstest_force_edid(int drm_fd, drmModeConnector *connector, igt_assert(ret != -1); } +/** + * sort_drm_modes_by_clk_dsc: + * @a: first element + * @b: second element + * + * Comparator function for sorting DRM modes in descending order by clock. + */ +int sort_drm_modes_by_clk_dsc(const void *a, const void *b) +{ + const drmModeModeInfo *mode1 = a, *mode2 = b; + + return (mode1->clock < mode2->clock) - (mode2->clock < mode1->clock); +} + +/** + * sort_drm_modes_by_clk_asc: + * @a: first element + * @b: second element + * + * Comparator function for sorting DRM modes in ascending order by clock. + */ +int sort_drm_modes_by_clk_asc(const void *a, const void *b) +{ + const drmModeModeInfo *mode1 = a, *mode2 = b; + + return (mode1->clock > mode2->clock) - (mode2->clock > mode1->clock); +} + +/** + * sort_drm_modes_by_res_dsc: + * @a: first element + * @b: second element + * + * Comparator function for sorting DRM modes in descending order by resolution. + */ +int sort_drm_modes_by_res_dsc(const void *a, const void *b) +{ + const drmModeModeInfo *mode1 = a, *mode2 = b; + + return (mode1->hdisplay < mode2->hdisplay) - (mode2->hdisplay < mode1->hdisplay); +} + +/** + * sort_drm_modes_by_res_asc: + * @a: first element + * @b: second element + * + * Comparator function for sorting DRM modes in ascending order by resolution. + */ +int sort_drm_modes_by_res_asc(const void *a, const void *b) +{ + const drmModeModeInfo *mode1 = a, *mode2 = b; + + return (mode1->hdisplay > mode2->hdisplay) - (mode2->hdisplay > mode1->hdisplay); +} + +/** + * igt_sort_connector_modes: + * @connector: libdrm connector + * @comparator: comparison function to compare two elements + * + * Sorts connector modes based on the @comparator. + */ +void igt_sort_connector_modes(drmModeConnector *connector, + int (*comparator)(const void *, const void*)) +{ + qsort(connector->modes, + connector->count_modes, + sizeof(drmModeModeInfo), + comparator); +} + /** * kmstest_get_connector_default_mode: * @drm_fd: DRM fd @@ -4204,16 +4276,6 @@ void igt_output_set_pipe(igt_output_t *output, enum pipe pipe) } } -#define for_each_connector_mode(output) \ - for (int i__ = 0; i__ < output->config.connector->count_modes; i__++) - -static int sort_drm_modes(const void *a, const void *b) -{ - const drmModeModeInfo *mode1 = a, *mode2 = b; - - return (mode1->clock < mode2->clock) - (mode2->clock < mode1->clock); -} - static bool __override_all_active_output_modes_to_fit_bw(igt_display_t *display, igt_output_t *outputs[IGT_MAX_PIPES], @@ -4230,7 +4292,7 @@ bool __override_all_active_output_modes_to_fit_bw(igt_display_t *display, for_each_connector_mode(output) { int ret; - igt_output_override_mode(output, &output->config.connector->modes[i__]); + igt_output_override_mode(output, &output->config.connector->modes[j__]); if (__override_all_active_output_modes_to_fit_bw(display, outputs, n_outputs, base + 1)) return true; @@ -4271,10 +4333,8 @@ bool igt_override_all_active_output_modes_to_fit_bw(igt_display_t *display) continue; /* Sort the modes in descending order by clock freq. */ - qsort(output->config.connector->modes, - output->config.connector->count_modes, - sizeof(drmModeModeInfo), - sort_drm_modes); + igt_sort_connector_modes(output->config.connector, + sort_drm_modes_by_clk_dsc); outputs[n_outputs++] = output; } diff --git a/lib/igt_kms.h b/lib/igt_kms.h index ba0bf4d6..0f12d825 100644 --- a/lib/igt_kms.h +++ b/lib/igt_kms.h @@ -637,6 +637,9 @@ igt_output_t **__igt_pipe_populate_outputs(igt_display_t *display, for (int j__ = 0; assert(igt_can_fail()), (plane) = &(display)->pipes[(pipe)].planes[j__], \ j__ < (display)->pipes[(pipe)].n_planes; j__++) +#define for_each_connector_mode(output) \ + for (int j__ = 0; j__ < output->config.connector->count_modes; j__++) + #define IGT_FIXED(i,f) ((i) << 16 | (f)) /** @@ -957,4 +960,11 @@ void igt_assert_output_bpc_equal(int drmfd, enum pipe pipe, bool igt_check_output_bpc_equal(int drmfd, enum pipe pipe, char *output_name, unsigned int bpc); +int sort_drm_modes_by_clk_dsc(const void *a, const void *b); +int sort_drm_modes_by_clk_asc(const void *a, const void *b); +int sort_drm_modes_by_res_dsc(const void *a, const void *b); +int sort_drm_modes_by_res_asc(const void *a, const void *b); +void igt_sort_connector_modes(drmModeConnector *connector, + int (*comparator)(const void *, const void*)); + #endif /* __IGT_KMS_H__ */ From patchwork Wed Jun 1 09:03:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [V4,2/3] tests/kms_hdr: Skip if current & requested BPC doesn't match From: Bhanuprakash Modem X-Patchwork-Id: 487931 Message-Id: <20220601090302.3947338-3-bhanuprakash.modem@intel.com> To: intel-gfx-trybot@lists.freedesktop.org Date: Wed, 1 Jun 2022 14:33:01 +0530 The "max bpc" property only ensures that the bpc will not go beyond the value set through this property. It does not guarantee that the same bpc will be used for the given mode. If clock/bandwidth constraints permit, the max bpc will be used to show the mode, otherwise the bpc will be reduced. So, if we really want a particular bpc set, we can try reducing the resolution, till we get the bpc that we set in max bpc property. This patch will skip the test, if there is no valid resolution to get the same bpc as set by max_bpc property. V2: * Refactor the logic V3: * Minor changes V4: * Drop 4K restriction check Cc: Swati Sharma CC: Ankit Nautiyal Cc: Ville Syrjälä Signed-off-by: Bhanuprakash Modem Reviewed-by: Ankit Nautiyal --- tests/kms_hdr.c | 56 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/tests/kms_hdr.c b/tests/kms_hdr.c index fb2e0790..d6b30f6d 100644 --- a/tests/kms_hdr.c +++ b/tests/kms_hdr.c @@ -144,8 +144,6 @@ static void test_bpc_switch_on_output(data_t *data, enum pipe pipe, igt_fb_t afb; int afb_id, ret; - prepare_test(data, output, pipe); - /* 10-bit formats are slow, so limit the size. */ afb_id = igt_create_fb(data->fd, 512, 512, DRM_FORMAT_XRGB2101010, 0, &afb); igt_assert(afb_id); @@ -187,14 +185,13 @@ static void test_bpc_switch_on_output(data_t *data, enum pipe pipe, test_cycle_flags(data, flags); igt_pipe_crc_collect_crc(data->pipe_crc, &new_crc); + igt_assert_crc_equal(&ref_crc, &new_crc); + /* Drop back to 8bpc. */ igt_output_set_prop_value(data->output, IGT_CONNECTOR_MAX_BPC, 8); igt_display_commit_atomic(display, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL); igt_assert_output_bpc_equal(data->fd, pipe, output->name, 8); - /* CRC capture is clamped to 8bpc, so capture should match. */ - igt_assert_crc_equal(&ref_crc, &new_crc); - test_fini(data); igt_remove_fb(data->fd, &afb); } @@ -206,6 +203,33 @@ static bool has_max_bpc(igt_output_t *output) igt_output_get_prop(output, IGT_CONNECTOR_MAX_BPC); } +static bool i915_clock_constraint(data_t *data, int bpc) +{ + igt_output_t *output = data->output; + drmModeConnector *connector = output->config.connector; + + igt_output_set_prop_value(data->output, IGT_CONNECTOR_MAX_BPC, bpc); + igt_sort_connector_modes(connector, sort_drm_modes_by_clk_dsc); + + for_each_connector_mode(output) { + igt_output_override_mode(output, &connector->modes[j__]); + igt_display_commit_atomic(&data->display, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL); + + if (!igt_check_output_bpc_equal(data->fd, data->pipe_id, + data->output->name, bpc)) + continue; + + data->mode = igt_output_get_mode(output); + data->w = data->mode->hdisplay; + data->h = data->mode->vdisplay; + + return true; + } + + test_fini(data); + return false; +} + static void test_bpc_switch(data_t *data, uint32_t flags) { igt_display_t *display = &data->display; @@ -217,8 +241,17 @@ static void test_bpc_switch(data_t *data, uint32_t flags) if (!has_max_bpc(output)) continue; + if (igt_get_output_max_bpc(data->fd, output->name) < 10) + continue; + for_each_pipe(display, pipe) { if (igt_pipe_connector_valid(pipe, output)) { + prepare_test(data, output, pipe); + + if (is_i915_device(data->fd) && + !i915_clock_constraint(data, 10)) + break; + igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe), output->name) test_bpc_switch_on_output(data, pipe, output, flags); @@ -367,8 +400,6 @@ static void test_static_toggle(data_t *data, enum pipe pipe, igt_fb_t afb; int afb_id; - prepare_test(data, output, pipe); - /* 10-bit formats are slow, so limit the size. */ afb_id = igt_create_fb(data->fd, 512, 512, DRM_FORMAT_XRGB2101010, 0, &afb); igt_assert(afb_id); @@ -446,8 +477,6 @@ static void test_static_swap(data_t *data, enum pipe pipe, igt_output_t *output) int afb_id; struct hdr_output_metadata hdr; - prepare_test(data, output, pipe); - /* 10-bit formats are slow, so limit the size. */ afb_id = igt_create_fb(data->fd, 512, 512, DRM_FORMAT_XRGB2101010, 0, &afb); igt_assert(afb_id); @@ -532,8 +561,17 @@ static void test_hdr(data_t *data, uint32_t flags) if (!is_panel_hdr(data, output)) continue; + if (igt_get_output_max_bpc(data->fd, output->name) < 10) + continue; + for_each_pipe(display, pipe) { if (igt_pipe_connector_valid(pipe, output)) { + prepare_test(data, output, pipe); + + if (is_i915_device(data->fd) && + !i915_clock_constraint(data, 10)) + break; + igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe), output->name) { if (flags & TEST_NONE || flags & TEST_DPMS || flags & TEST_SUSPEND) From patchwork Wed Jun 1 09:03:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [V4,3/3] tests/kms_color: Skip if current & requested BPC doesn't match From: Bhanuprakash Modem X-Patchwork-Id: 487933 Message-Id: <20220601090302.3947338-4-bhanuprakash.modem@intel.com> To: intel-gfx-trybot@lists.freedesktop.org Date: Wed, 1 Jun 2022 14:33:02 +0530 The "max bpc" property only ensures that the bpc will not go beyond the value set through this property. It does not guarantee that the same bpc will be used for the given mode. If clock/bandwidth constraints permit, the max bpc will be used to show the mode, otherwise the bpc will be reduced. So, if we really want a particular bpc set, we can try reducing the resolution, till we get the bpc that we set in max bpc property. This patch will skip the test, if there is no valid resolution to get the same bpc as set by max_bpc property. V2: * Refactor the logic V3: * Minor changes V4: * Set output to pipe (igt_output_set_pipe) Cc: Swati Sharma CC: Ankit Nautiyal Cc: Ville Syrjälä Signed-off-by: Bhanuprakash Modem Reviewed-by: Ankit Nautiyal --- tests/kms_color.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/tests/kms_color.c b/tests/kms_color.c index 93957f50..ba06947b 100644 --- a/tests/kms_color.c +++ b/tests/kms_color.c @@ -635,6 +635,28 @@ static void test_pipe_limited_range_ctm(data_t *data, } #endif +static bool i915_clock_constraint(data_t *data, enum pipe pipe, int bpc) +{ + igt_output_t *output = data->output; + drmModeConnector *connector = output->config.connector; + + igt_sort_connector_modes(connector, sort_drm_modes_by_clk_dsc); + + for_each_connector_mode(output) { + igt_output_override_mode(output, &connector->modes[j__]); + igt_display_commit_atomic(&data->display, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL); + + if (!igt_check_output_bpc_equal(data->drm_fd, pipe, + data->output->name, bpc)) + continue; + + return true; + } + + igt_output_override_mode(output, NULL); + return false; +} + static void prep_pipe(data_t *data, enum pipe p) { @@ -866,6 +888,9 @@ run_tests_for_pipe(data_t *data, enum pipe p) igt_subtest_f("pipe-%s-legacy-gamma-reset", kmstest_pipe_name(p)) test_pipe_legacy_gamma_reset(data, primary); + igt_fixture + igt_require(data->display.is_atomic); + igt_describe("Verify that deep color works correctly"); igt_subtest_with_dynamic_f("pipe-%s-deep-color", kmstest_pipe_name(p)) { igt_output_t *output; @@ -896,12 +921,12 @@ run_tests_for_pipe(data_t *data, enum pipe p) data->drm_format = DRM_FORMAT_XRGB2101010; data->output = output; igt_output_set_prop_value(output, IGT_CONNECTOR_MAX_BPC, 10); - igt_display_commit(&data->display); + igt_output_set_pipe(output, p); + igt_display_commit_atomic(&data->display, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL); - if (!igt_check_output_bpc_equal(data->drm_fd, p, output->name, 10)) { - igt_output_set_prop_value(output, IGT_CONNECTOR_MAX_BPC, max_bpc); - igt_fail_on_f(true, "Failed to set max_bpc as: 10\n"); - } + if (is_i915_device(data->drm_fd) && + !i915_clock_constraint(data, p, 10)) + continue; igt_dynamic_f("gamma-%s", output->name) { ret = test_pipe_gamma(data, primary);