radeon/vce: use util function to get h264 profile idc
[mesa.git] / src / gallium / drivers / radeon / radeon_vce_52.c
index 0922f13bf3678b5d3150d7981f332debee82619b..fc7ddc62a90b4f3795a1b16440ceecf3c396dd21 100644 (file)
 
 #include "vl/vl_video_buffer.h"
 
-#include "r600_pipe_common.h"
+#include "radeonsi/si_pipe.h"
 #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;
@@ -138,7 +136,7 @@ static void get_vui_param(struct rvce_encoder *enc, struct pipe_h264_enc_picture
        enc->enc_pic.vui.max_dec_frame_buffering = 0x00000003;
 }
 
-void radeon_vce_52_get_param(struct rvce_encoder *enc, struct pipe_h264_enc_picture_desc *pic)
+void si_vce_52_get_param(struct rvce_encoder *enc, struct pipe_h264_enc_picture_desc *pic)
 {
        get_rate_control_param(enc, pic);
        get_motion_estimation_param(enc, pic);
@@ -162,24 +160,32 @@ void radeon_vce_52_get_param(struct rvce_encoder *enc, struct pipe_h264_enc_pict
                enc->enc_pic.addrmode_arraymode_disrdo_distwoinstants = 0x00000201;
        else
                enc->enc_pic.addrmode_arraymode_disrdo_distwoinstants = 0x01000201;
-       enc->enc_pic.is_idr = pic->is_idr;
+       enc->enc_pic.is_idr = (pic->picture_type == PIPE_H264_ENC_PICTURE_TYPE_IDR);
 }
 
 static void create(struct rvce_encoder *enc)
 {
+       struct si_screen *sscreen = (struct si_screen *)enc->screen;
        enc->task_info(enc, 0x00000000, 0, 0, 0);
 
        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(u_get_h264_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
        RVCE_CS(enc->base.height); // encImageHeight
-       RVCE_CS(enc->luma->level[0].pitch_bytes); // encRefPicLumaPitch
-       RVCE_CS(enc->chroma->level[0].pitch_bytes); // encRefPicChromaPitch
-       RVCE_CS(align(enc->luma->level[0].nblk_y, 16) / 8); // encRefYHeightInQw
+
+       if (sscreen->info.chip_class < GFX9) {
+               RVCE_CS(enc->luma->u.legacy.level[0].nblk_x * enc->luma->bpe); // encRefPicLumaPitch
+               RVCE_CS(enc->chroma->u.legacy.level[0].nblk_x * enc->chroma->bpe); // encRefPicChromaPitch
+               RVCE_CS(align(enc->luma->u.legacy.level[0].nblk_y, 16) / 8); // encRefYHeightInQw
+       } else {
+               RVCE_CS(enc->luma->u.gfx9.surf_pitch * enc->luma->bpe); // encRefPicLumaPitch
+               RVCE_CS(enc->chroma->u.gfx9.surf_pitch * enc->chroma->bpe); // encRefPicChromaPitch
+               RVCE_CS(align(enc->luma->u.gfx9.surf_height, 16) / 8); // encRefYHeightInQw
+       }
+
        RVCE_CS(enc->enc_pic.addrmode_arraymode_disrdo_distwoinstants);
 
        RVCE_CS(enc->enc_pic.ec.enc_pre_encode_context_buffer_offset);
@@ -191,6 +197,7 @@ static void create(struct rvce_encoder *enc)
 
 static void encode(struct rvce_encoder *enc)
 {
+       struct si_screen *sscreen = (struct si_screen *)enc->screen;
        signed luma_offset, chroma_offset, bs_offset;
        unsigned dep, bs_idx = enc->bs_idx++;
        int i;
@@ -239,13 +246,25 @@ static void encode(struct rvce_encoder *enc)
        RVCE_CS(enc->enc_pic.eo.insert_aud);
        RVCE_CS(enc->enc_pic.eo.end_of_sequence);
        RVCE_CS(enc->enc_pic.eo.end_of_stream);
-       RVCE_READ(enc->handle, RADEON_DOMAIN_VRAM,
-               enc->luma->level[0].offset); // inputPictureLumaAddressHi/Lo
-       RVCE_READ(enc->handle, RADEON_DOMAIN_VRAM,
-               enc->chroma->level[0].offset); // inputPictureChromaAddressHi/Lo
-       RVCE_CS(align(enc->luma->level[0].nblk_y, 16)); // encInputFrameYPitch
-       RVCE_CS(enc->luma->level[0].pitch_bytes); // encInputPicLumaPitch
-       RVCE_CS(enc->chroma->level[0].pitch_bytes); // encInputPicChromaPitch
+
+       if (sscreen->info.chip_class < GFX9) {
+               RVCE_READ(enc->handle, RADEON_DOMAIN_VRAM,
+                       enc->luma->u.legacy.level[0].offset); // inputPictureLumaAddressHi/Lo
+               RVCE_READ(enc->handle, RADEON_DOMAIN_VRAM,
+                       enc->chroma->u.legacy.level[0].offset); // inputPictureChromaAddressHi/Lo
+               RVCE_CS(align(enc->luma->u.legacy.level[0].nblk_y, 16)); // encInputFrameYPitch
+               RVCE_CS(enc->luma->u.legacy.level[0].nblk_x * enc->luma->bpe); // encInputPicLumaPitch
+               RVCE_CS(enc->chroma->u.legacy.level[0].nblk_x * enc->chroma->bpe); // encInputPicChromaPitch
+       } else {
+               RVCE_READ(enc->handle, RADEON_DOMAIN_VRAM,
+                       enc->luma->u.gfx9.surf_offset); // inputPictureLumaAddressHi/Lo
+               RVCE_READ(enc->handle, RADEON_DOMAIN_VRAM,
+                       enc->chroma->u.gfx9.surf_offset); // inputPictureChromaAddressHi/Lo
+               RVCE_CS(align(enc->luma->u.gfx9.surf_height, 16)); // encInputFrameYPitch
+               RVCE_CS(enc->luma->u.gfx9.surf_pitch * enc->luma->bpe); // encInputPicLumaPitch
+               RVCE_CS(enc->chroma->u.gfx9.surf_pitch * enc->chroma->bpe); // encInputPicChromaPitch
+       }
+
        if (enc->dual_pipe)
                enc->enc_pic.eo.enc_input_pic_addr_array_disable2pipe_disablemboffload = 0x00000000;
        else
@@ -297,8 +316,8 @@ static void encode(struct rvce_encoder *enc)
        RVCE_CS(0x00000000); // pictureStructure
        if(enc->enc_pic.picture_type == PIPE_H264_ENC_PICTURE_TYPE_P ||
                enc->enc_pic.picture_type == PIPE_H264_ENC_PICTURE_TYPE_B) {
-               struct rvce_cpb_slot *l0 = l0_slot(enc);
-               rvce_frame_offset(enc, l0, &luma_offset, &chroma_offset);
+               struct rvce_cpb_slot *l0 = si_l0_slot(enc);
+               si_vce_frame_offset(enc, l0, &luma_offset, &chroma_offset);
                RVCE_CS(l0->picture_type);
                RVCE_CS(l0->frame_num);
                RVCE_CS(l0->pic_order_cnt);
@@ -334,8 +353,8 @@ static void encode(struct rvce_encoder *enc)
        // encReferencePictureL1[0]
        RVCE_CS(0x00000000); // pictureStructure
        if(enc->enc_pic.picture_type == PIPE_H264_ENC_PICTURE_TYPE_B) {
-               struct rvce_cpb_slot *l1 = l1_slot(enc);
-               rvce_frame_offset(enc, l1, &luma_offset, &chroma_offset);
+               struct rvce_cpb_slot *l1 = si_l1_slot(enc);
+               si_vce_frame_offset(enc, l1, &luma_offset, &chroma_offset);
                RVCE_CS(l1->picture_type);
                RVCE_CS(l1->frame_num);
                RVCE_CS(l1->pic_order_cnt);
@@ -354,7 +373,7 @@ static void encode(struct rvce_encoder *enc)
                RVCE_CS(enc->enc_pic.eo.l1_chroma_offset);
        }
 
-       rvce_frame_offset(enc, current_slot(enc), &luma_offset, &chroma_offset);
+       si_vce_frame_offset(enc, si_current_slot(enc), &luma_offset, &chroma_offset);
        RVCE_CS(luma_offset);
        RVCE_CS(chroma_offset);
        RVCE_CS(enc->enc_pic.eo.enc_coloc_buffer_offset);
@@ -436,14 +455,6 @@ static void config_extension(struct rvce_encoder *enc)
        RVCE_END();
 }
 
-static void destroy(struct rvce_encoder *enc)
-{
-       enc->task_info(enc, 0x00000001, 0, 0, 0);
-
-       RVCE_BEGIN(0x02000001); // destroy
-       RVCE_END();
-}
-
 static void feedback(struct rvce_encoder *enc)
 {
        RVCE_BEGIN(0x05000005); // feedback buffer
@@ -452,6 +463,16 @@ static void feedback(struct rvce_encoder *enc)
        RVCE_END();
 }
 
+static void destroy(struct rvce_encoder *enc)
+{
+       enc->task_info(enc, 0x00000001, 0, 0, 0);
+
+       feedback(enc);
+
+       RVCE_BEGIN(0x02000001); // destroy
+       RVCE_END();
+}
+
 static void motion_estimation(struct rvce_encoder *enc)
 {
        RVCE_BEGIN(0x04000007); // motion estimation
@@ -624,7 +645,7 @@ static void vui(struct rvce_encoder *enc)
        RVCE_END();
 }
 
-void radeon_vce_52_init(struct rvce_encoder *enc)
+void si_vce_52_init(struct rvce_encoder *enc)
 {
        enc->session = session;
        enc->task_info = task_info;