[PATCH i-g-t v4 1/5] lib/igt_fb: make blt_compression_format function more readable

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Tue Jun 4 07:48:33 UTC 2024


On Thu, May 30, 2024 at 05:23:42PM +0300, Juha-Pekka Heikkila wrote:
> Intel blitter compression format getter sanitizing.
> 
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.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");
> +	return 0; // This line is to avoid compilation warnings, it will not be reached.

Keep r-b but please change comment to /* */ style.

--
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.43.2
> 


More information about the igt-dev mailing list