radeon/vce: use switch to convert profile idc

Submitted by Zhang, Boyuan on Sept. 26, 2018, 2:40 p.m.

Details

Message ID 20180926144009.2495-1-boyuan.zhang@amd.com
State New
Headers show
Series "radeon/vce: use switch to convert profile idc" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Zhang, Boyuan Sept. 26, 2018, 2:40 p.m.
From: Boyuan Zhang <boyuan.zhang@amd.com>

The previous array logic for converting pipe video profile to profile idc
relies on the order of pipe_video_profile enum defines. Adding new profile
to enum defines may break the logic. Therefore, it's better to use switch
helper function to acheive the same goal.

Signed-off-by: Boyuan Zhang <boyuan.zhang@amd.com>
---
 src/gallium/drivers/radeon/radeon_vce.c       | 24 +++++++++++++++++++
 src/gallium/drivers/radeon/radeon_vce.h       |  3 +++
 .../drivers/radeon/radeon_vce_40_2_2.c        |  5 +---
 src/gallium/drivers/radeon/radeon_vce_52.c    |  5 +---
 4 files changed, 29 insertions(+), 8 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/gallium/drivers/radeon/radeon_vce.c b/src/gallium/drivers/radeon/radeon_vce.c
index 8972253c7c..6b9f2ab37b 100644
--- a/src/gallium/drivers/radeon/radeon_vce.c
+++ b/src/gallium/drivers/radeon/radeon_vce.c
@@ -572,3 +572,27 @@  void si_vce_add_buffer(struct rvce_encoder *enc, struct pb_buffer *buf,
 		RVCE_CS(offset);
 	}
 }
+
+unsigned si_vce_get_profile_idc(enum pipe_video_profile profile)
+{
+	switch (profile) {
+		case PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE:
+		case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
+			return 66;
+		case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
+			return 77;
+		case PIPE_VIDEO_PROFILE_MPEG4_AVC_EXTENDED:
+			return 88;
+		case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
+			return 100;
+		case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH10:
+			return 110;
+		case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH422:
+			return 122;
+		case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH444:
+			return 244;
+		default:
+			RVID_ERR("Unsupported profile! Use baseline profile instead.\n");
+			return 66;
+	}
+}
diff --git a/src/gallium/drivers/radeon/radeon_vce.h b/src/gallium/drivers/radeon/radeon_vce.h
index cf625e6fed..255a3bf200 100644
--- a/src/gallium/drivers/radeon/radeon_vce.h
+++ b/src/gallium/drivers/radeon/radeon_vce.h
@@ -453,4 +453,7 @@  void si_vce_50_get_param(struct rvce_encoder *enc,
 void si_vce_52_get_param(struct rvce_encoder *enc,
 			 struct pipe_h264_enc_picture_desc *pic);
 
+/* convert pipe video profile to profile idc */
+unsigned si_vce_get_profile_idc(enum pipe_video_profile profile);
+
 #endif
diff --git a/src/gallium/drivers/radeon/radeon_vce_40_2_2.c b/src/gallium/drivers/radeon/radeon_vce_40_2_2.c
index 66b54dab25..925480e4af 100644
--- a/src/gallium/drivers/radeon/radeon_vce_40_2_2.c
+++ b/src/gallium/drivers/radeon/radeon_vce_40_2_2.c
@@ -38,8 +38,6 @@ 
 #include "radeon_video.h"
 #include "radeon_vce.h"
 
-static const unsigned profiles[7] = { 66, 77, 88, 100, 110, 122, 244 };
-
 static void session(struct rvce_encoder *enc)
 {
 	RVCE_BEGIN(0x00000001); // session cmd
@@ -82,8 +80,7 @@  static void create(struct rvce_encoder *enc)
 
 	RVCE_BEGIN(0x01000001); // create cmd
 	RVCE_CS(0x00000000); // encUseCircularBuffer
-	RVCE_CS(profiles[enc->base.profile -
-		PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE]); // encProfile
+	RVCE_CS(si_vce_get_profile_idc(enc->base.profile)); // encProfile
 	RVCE_CS(enc->base.level); // encLevel
 	RVCE_CS(0x00000000); // encPicStructRestriction
 	RVCE_CS(enc->base.width); // encImageWidth
diff --git a/src/gallium/drivers/radeon/radeon_vce_52.c b/src/gallium/drivers/radeon/radeon_vce_52.c
index 421539c4bd..bf7c5d6ff2 100644
--- a/src/gallium/drivers/radeon/radeon_vce_52.c
+++ b/src/gallium/drivers/radeon/radeon_vce_52.c
@@ -38,8 +38,6 @@ 
 #include "radeon_video.h"
 #include "radeon_vce.h"
 
-static const unsigned profiles[7] = { 66, 77, 88, 100, 110, 122, 244 };
-
 static void get_rate_control_param(struct rvce_encoder *enc, struct pipe_h264_enc_picture_desc *pic)
 {
 	enc->enc_pic.rc.rc_method = pic->rate_ctrl.rate_ctrl_method;
@@ -172,8 +170,7 @@  static void create(struct rvce_encoder *enc)
 
 	RVCE_BEGIN(0x01000001); // create cmd
 	RVCE_CS(enc->enc_pic.ec.enc_use_circular_buffer);
-	RVCE_CS(profiles[enc->base.profile -
-		PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE]); // encProfile
+	RVCE_CS(si_vce_get_profile_idc(enc->base.profile)); // encProfile
 	RVCE_CS(enc->base.level); // encLevel
 	RVCE_CS(enc->enc_pic.ec.enc_pic_struct_restriction);
 	RVCE_CS(enc->base.width); // encImageWidth

Comments

On 2018-09-26 10:40 AM, boyuan.zhang@amd.com wrote:
> From: Boyuan Zhang <boyuan.zhang@amd.com>
>
> The previous array logic for converting pipe video profile to profile idc
> relies on the order of pipe_video_profile enum defines. Adding new profile
> to enum defines may break the logic. Therefore, it's better to use switch
> helper function to acheive the same goal.
>
> Signed-off-by: Boyuan Zhang <boyuan.zhang@amd.com>
> ---
>   src/gallium/drivers/radeon/radeon_vce.c       | 24 +++++++++++++++++++
>   src/gallium/drivers/radeon/radeon_vce.h       |  3 +++
>   .../drivers/radeon/radeon_vce_40_2_2.c        |  5 +---
>   src/gallium/drivers/radeon/radeon_vce_52.c    |  5 +---
>   4 files changed, 29 insertions(+), 8 deletions(-)
>
> diff --git a/src/gallium/drivers/radeon/radeon_vce.c b/src/gallium/drivers/radeon/radeon_vce.c
> index 8972253c7c..6b9f2ab37b 100644
> --- a/src/gallium/drivers/radeon/radeon_vce.c
> +++ b/src/gallium/drivers/radeon/radeon_vce.c
> @@ -572,3 +572,27 @@ void si_vce_add_buffer(struct rvce_encoder *enc, struct pb_buffer *buf,
>   		RVCE_CS(offset);
>   	}
>   }
> +
> +unsigned si_vce_get_profile_idc(enum pipe_video_profile profile)
Is it better to move to "u_video.h" and rename to "u_get_avc_profile_idc"?

Regards,
Leo

> +{
> +	switch (profile) {
> +		case PIPE_VIDEO_PROFILE_MPEG4_AVC_CONSTRAINED_BASELINE:
> +		case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
> +			return 66;
> +		case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
> +			return 77;
> +		case PIPE_VIDEO_PROFILE_MPEG4_AVC_EXTENDED:
> +			return 88;
> +		case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
> +			return 100;
> +		case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH10:
> +			return 110;
> +		case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH422:
> +			return 122;
> +		case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH444:
> +			return 244;
> +		default:
> +			RVID_ERR("Unsupported profile! Use baseline profile instead.\n");
> +			return 66;
> +	}
> +}
> diff --git a/src/gallium/drivers/radeon/radeon_vce.h b/src/gallium/drivers/radeon/radeon_vce.h
> index cf625e6fed..255a3bf200 100644
> --- a/src/gallium/drivers/radeon/radeon_vce.h
> +++ b/src/gallium/drivers/radeon/radeon_vce.h
> @@ -453,4 +453,7 @@ void si_vce_50_get_param(struct rvce_encoder *enc,
>   void si_vce_52_get_param(struct rvce_encoder *enc,
>   			 struct pipe_h264_enc_picture_desc *pic);
>   
> +/* convert pipe video profile to profile idc */
> +unsigned si_vce_get_profile_idc(enum pipe_video_profile profile);
> +
>   #endif
> diff --git a/src/gallium/drivers/radeon/radeon_vce_40_2_2.c b/src/gallium/drivers/radeon/radeon_vce_40_2_2.c
> index 66b54dab25..925480e4af 100644
> --- a/src/gallium/drivers/radeon/radeon_vce_40_2_2.c
> +++ b/src/gallium/drivers/radeon/radeon_vce_40_2_2.c
> @@ -38,8 +38,6 @@
>   #include "radeon_video.h"
>   #include "radeon_vce.h"
>   
> -static const unsigned profiles[7] = { 66, 77, 88, 100, 110, 122, 244 };
> -
>   static void session(struct rvce_encoder *enc)
>   {
>   	RVCE_BEGIN(0x00000001); // session cmd
> @@ -82,8 +80,7 @@ static void create(struct rvce_encoder *enc)
>   
>   	RVCE_BEGIN(0x01000001); // create cmd
>   	RVCE_CS(0x00000000); // encUseCircularBuffer
> -	RVCE_CS(profiles[enc->base.profile -
> -		PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE]); // encProfile
> +	RVCE_CS(si_vce_get_profile_idc(enc->base.profile)); // encProfile
>   	RVCE_CS(enc->base.level); // encLevel
>   	RVCE_CS(0x00000000); // encPicStructRestriction
>   	RVCE_CS(enc->base.width); // encImageWidth
> diff --git a/src/gallium/drivers/radeon/radeon_vce_52.c b/src/gallium/drivers/radeon/radeon_vce_52.c
> index 421539c4bd..bf7c5d6ff2 100644
> --- a/src/gallium/drivers/radeon/radeon_vce_52.c
> +++ b/src/gallium/drivers/radeon/radeon_vce_52.c
> @@ -38,8 +38,6 @@
>   #include "radeon_video.h"
>   #include "radeon_vce.h"
>   
> -static const unsigned profiles[7] = { 66, 77, 88, 100, 110, 122, 244 };
> -
>   static void get_rate_control_param(struct rvce_encoder *enc, struct pipe_h264_enc_picture_desc *pic)
>   {
>   	enc->enc_pic.rc.rc_method = pic->rate_ctrl.rate_ctrl_method;
> @@ -172,8 +170,7 @@ static void create(struct rvce_encoder *enc)
>   
>   	RVCE_BEGIN(0x01000001); // create cmd
>   	RVCE_CS(enc->enc_pic.ec.enc_use_circular_buffer);
> -	RVCE_CS(profiles[enc->base.profile -
> -		PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE]); // encProfile
> +	RVCE_CS(si_vce_get_profile_idc(enc->base.profile)); // encProfile
>   	RVCE_CS(enc->base.level); // encLevel
>   	RVCE_CS(enc->enc_pic.ec.enc_pic_struct_restriction);
>   	RVCE_CS(enc->base.width); // encImageWidth