[PATCH i-g-t v3 2/6] lib/igt_fb: make blt_compression_format function more readable

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Thu May 9 10:12:06 UTC 2024


On Tue, Apr 30, 2024 at 07:29:35PM +0300, Juha-Pekka Heikkila wrote:
> Intel blitter compression format getter sanitizing.
> 
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
>  lib/igt_fb.c | 63 ++++++++++++++++++++++++++++++----------------------
>  1 file changed, 37 insertions(+), 26 deletions(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index 5df5cb08f..707eb0a1e 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -2825,6 +2825,32 @@ static enum blt_color_depth blt_get_bpp(const struct igt_fb *fb)
>  #define BLT_TARGET_MC(x) (x.compression == COMPRESSION_ENABLED && \
>  			  x.compression_type == COMPRESSION_TYPE_MEDIA)
>  
> +const struct {
> +	uint32_t key;
> +	enum blt_compression_type type;
> +	uint32_t return_value;
> +} compression_mappings[] = {
> +	{ CD_32bit, COMPRESSION_TYPE_3D, 8 },
> +	{ DRM_FORMAT_XRGB8888, COMPRESSION_TYPE_MEDIA, 8 },
> +	{ DRM_FORMAT_XYUV8888, COMPRESSION_TYPE_MEDIA, 9 },
> +	{ DRM_FORMAT_NV12, COMPRESSION_TYPE_MEDIA, 9 },
> +	{ DRM_FORMAT_P010, COMPRESSION_TYPE_MEDIA, 8 },
> +	{ DRM_FORMAT_P012, COMPRESSION_TYPE_MEDIA, 8 },
> +	{ DRM_FORMAT_P016, COMPRESSION_TYPE_MEDIA, 8 },
> +};
> +
> +static uint32_t get_compression_return_value(uint32_t key, enum  blt_compression_type type)
> +{
> +	for (int i = 0; i < ARRAY_SIZE(compression_mappings); i++) {
> +		if (compression_mappings[i].key == key &&
> +		    compression_mappings[i].type == type) {
> +			return compression_mappings[i].return_value;
> +		}
> +	}
> +	igt_assert_f(0, "Unknown compression type or format\n");

I would add blank line here.

> +	return 0; // This line is to avoid compilation warnings, it will not be reached.

Please use /* */ style comment.

With those nits addressed:

Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>

--
Zbigniew

> +}
> +
>  static uint32_t blt_compression_format(struct blt_copy_data *blt,
>  				       const struct igt_fb *fb)
>  {
> @@ -2832,33 +2858,18 @@ static uint32_t blt_compression_format(struct blt_copy_data *blt,
>  	    blt->dst.compression == COMPRESSION_DISABLED)
>  		return 0;
>  
> -	if (BLT_TARGET_RC(blt->src) || BLT_TARGET_RC(blt->dst)) {
> -		switch (blt->color_depth) {
> -		case CD_32bit:
> -			return 8;
> -		default:
> -			igt_assert_f(0, "COMPRESSION_TYPE_3D unknown color depth\n");
> -		}
> -	} else if (BLT_TARGET_MC(blt->src)) {
> -		switch (fb->drm_format) {
> -		case DRM_FORMAT_XRGB8888:
> -			return 8;
> -		case DRM_FORMAT_XYUV8888:
> -			return 9;
> -		case DRM_FORMAT_NV12:
> -			return 9;
> -		case DRM_FORMAT_P010:
> -		case DRM_FORMAT_P012:
> -		case DRM_FORMAT_P016:
> -			return 8;
> -		default:
> -			igt_assert_f(0, "COMPRESSION_TYPE_MEDIA unknown format\n");
> -		}
> -	} else if (BLT_TARGET_MC(blt->dst)) {
> +	if (BLT_TARGET_RC(blt->src) || BLT_TARGET_RC(blt->dst))
> +		return get_compression_return_value(blt->color_depth,
> +						    COMPRESSION_TYPE_3D);
> +
> +	if (BLT_TARGET_MC(blt->src))
> +		return get_compression_return_value(fb->drm_format,
> +						    COMPRESSION_TYPE_MEDIA);
> +
> +	if (BLT_TARGET_MC(blt->dst))
>  		igt_assert_f(0, "Destination compression not supported on mc ccs\n");
> -	} else {
> -		igt_assert_f(0, "unknown compression\n");
> -	}
> +
> +	igt_assert_f(0, "unknown compression\n");
>  }
>  
>  static void blitcopy(const struct igt_fb *dst_fb,
> -- 
> 2.25.1
> 


More information about the igt-dev mailing list