radeon/vce: implement B-frame support
authorChristian König <christian.koenig@amd.com>
Fri, 4 Apr 2014 15:14:26 +0000 (17:14 +0200)
committerChristian König <christian.koenig@amd.com>
Fri, 11 Apr 2014 09:35:03 +0000 (11:35 +0200)
Signed-off-by: Slava Grigorev <slava.grigorev@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
src/gallium/drivers/radeon/radeon_vce.h
src/gallium/drivers/radeon/radeon_vce_40_2_2.c

index f815cad38aaa326f66a34de7db215afcd0e34a7a..7cc87be37f33bcba0cac1e5db38e93e1e0da7fb1 100644 (file)
@@ -45,7 +45,7 @@
 #define RVCE_READWRITE(buf, domain) RVCE_CS(RVCE_RELOC(buf, RADEON_USAGE_READWRITE, domain) * 4)
 #define RVCE_END() *begin = (&enc->cs->buf[enc->cs->cdw] - begin) * 4; }
 
-#define RVCE_NUM_CPB_FRAMES 2
+#define RVCE_NUM_CPB_FRAMES 3
 
 struct r600_common_screen;
 
index 1327d64f983a178a3c53e9f61d43819090dd9a8f..3b67b31fdf86a8c6b257d30b0cec02907bbf3cd1 100644 (file)
@@ -54,6 +54,11 @@ static struct rvce_cpb_slot *l0_slot(struct rvce_encoder *enc)
        return LIST_ENTRY(struct rvce_cpb_slot, enc->cpb_slots.next, list);
 }
 
+static struct rvce_cpb_slot *l1_slot(struct rvce_encoder *enc)
+{
+       return LIST_ENTRY(struct rvce_cpb_slot, enc->cpb_slots.next->next, list);
+}
+
 static void frame_offset(struct rvce_encoder *enc, struct rvce_cpb_slot *slot,
                         unsigned *luma_offset, unsigned *chroma_offset)
 {
@@ -99,8 +104,8 @@ static void create(struct rvce_encoder *enc)
 
        RVCE_BEGIN(0x01000001); // create cmd
        RVCE_CS(0x00000000); // encUseCircularBuffer
-       RVCE_CS(0x00000041); // encProfile
-       RVCE_CS(0x0000000a); // encLevel
+       RVCE_CS(0x0000004d); // encProfile: Main
+       RVCE_CS(0x0000002a); // encLevel: 4.2
        RVCE_CS(0x00000000); // encPicStructRestriction
        RVCE_CS(enc->base.width); // encImageWidth
        RVCE_CS(enc->base.height); // encImageHeight
@@ -175,12 +180,12 @@ static void pic_control(struct rvce_encoder *enc)
        RVCE_CS(0x00000000); // encSPSID
        RVCE_CS(0x00000000); // encPPSID
        RVCE_CS(0x00000040); // encConstraintSetFlags
-       RVCE_CS(0x00000000); // encBPicPattern
+       RVCE_CS(MAX2(enc->base.max_references, 1) - 1); // encBPicPattern
        RVCE_CS(0x00000000); // weightPredModeBPicture
        RVCE_CS(MIN2(enc->base.max_references, 2)); // encNumberOfReferenceFrames
        RVCE_CS(enc->base.max_references + 1); // encMaxNumRefFrames
-       RVCE_CS(0x00000000); // encNumDefaultActiveRefL0
-       RVCE_CS(0x00000000); // encNumDefaultActiveRefL1
+       RVCE_CS(0x00000001); // encNumDefaultActiveRefL0
+       RVCE_CS(0x00000001); // encNumDefaultActiveRefL1
        RVCE_CS(0x00000000); // encSliceMode
        RVCE_CS(0x00000000); // encMaxSliceSize
        RVCE_END();
@@ -275,7 +280,7 @@ static void encode(struct rvce_encoder *enc)
        RVCE_CS(0x00000000); // encInputPic(Addr|Array)Mode
        RVCE_CS(0x00000000); // encInputPicTileConfig
        RVCE_CS(enc->pic.picture_type); // encPicType
-       RVCE_CS(enc->pic.picture_type == 3); // encIdrFlag
+       RVCE_CS(enc->pic.picture_type == PIPE_H264_ENC_PICTURE_TYPE_IDR); // encIdrFlag
        RVCE_CS(0x00000000); // encIdrPicId
        RVCE_CS(0x00000000); // encMGSKeyPic
        RVCE_CS(0x00000001); // encReferenceFlag
@@ -283,7 +288,17 @@ static void encode(struct rvce_encoder *enc)
        RVCE_CS(0x00000000); // num_ref_idx_active_override_flag
        RVCE_CS(0x00000000); // num_ref_idx_l0_active_minus1
        RVCE_CS(0x00000000); // num_ref_idx_l1_active_minus1
-       for (i = 0; i < 4; ++i) {
+
+       i = enc->pic.frame_num - enc->pic.ref_idx_l0;
+       if (i > 1 && enc->pic.picture_type == PIPE_H264_ENC_PICTURE_TYPE_P) {
+               RVCE_CS(0x00000001); // encRefListModificationOp
+               RVCE_CS(i - 1);      // encRefListModificationNum
+       } else {
+               RVCE_CS(0x00000000); // encRefListModificationOp
+               RVCE_CS(0x00000000); // encRefListModificationNum
+       }
+
+       for (i = 0; i < 3; ++i) {
                RVCE_CS(0x00000000); // encRefListModificationOp
                RVCE_CS(0x00000000); // encRefListModificationNum
        }
@@ -291,22 +306,14 @@ static void encode(struct rvce_encoder *enc)
                RVCE_CS(0x00000000); // encDecodedPictureMarkingOp
                RVCE_CS(0x00000000); // encDecodedPictureMarkingNum
                RVCE_CS(0x00000000); // encDecodedPictureMarkingIdx
-       }
-       for (i = 0; i < 4; ++i) {
                RVCE_CS(0x00000000); // encDecodedRefBasePictureMarkingOp
                RVCE_CS(0x00000000); // encDecodedRefBasePictureMarkingNum
        }
 
+       // encReferencePictureL0[0]
        RVCE_CS(0x00000000); // pictureStructure
-
-       if (enc->pic.picture_type == PIPE_H264_ENC_PICTURE_TYPE_IDR) { 
-               RVCE_CS(0x00000000); // encPicType
-               RVCE_CS(0x00000000); // frameNumber
-               RVCE_CS(0x00000000); // pictureOrderCount
-               RVCE_CS(0xffffffff); // lumaOffset
-               RVCE_CS(0xffffffff); // chromaOffset
-       }
-       else if(enc->pic.picture_type == PIPE_H264_ENC_PICTURE_TYPE_P) {
+       if(enc->pic.picture_type == PIPE_H264_ENC_PICTURE_TYPE_P ||
+          enc->pic.picture_type == PIPE_H264_ENC_PICTURE_TYPE_B) {
                struct rvce_cpb_slot *l0 = l0_slot(enc);
                frame_offset(enc, l0, &luma_offset, &chroma_offset);
                RVCE_CS(l0->picture_type); // encPicType
@@ -314,16 +321,40 @@ static void encode(struct rvce_encoder *enc)
                RVCE_CS(l0->pic_order_cnt); // pictureOrderCount
                RVCE_CS(luma_offset); // lumaOffset
                RVCE_CS(chroma_offset); // chromaOffset
+       } else {
+               RVCE_CS(0x00000000); // encPicType
+               RVCE_CS(0x00000000); // frameNumber
+               RVCE_CS(0x00000000); // pictureOrderCount
+               RVCE_CS(0xffffffff); // lumaOffset
+               RVCE_CS(0xffffffff); // chromaOffset
        }
-       for (i = 0; i < 2; ++i) {
-               RVCE_CS(0x00000000); // pictureStructure
+
+       // encReferencePictureL0[1]
+       RVCE_CS(0x00000000); // pictureStructure
+       RVCE_CS(0x00000000); // encPicType
+       RVCE_CS(0x00000000); // frameNumber
+       RVCE_CS(0x00000000); // pictureOrderCount
+       RVCE_CS(0xffffffff); // lumaOffset
+       RVCE_CS(0xffffffff); // chromaOffset
+
+       // encReferencePictureL1[0]
+       RVCE_CS(0x00000000); // pictureStructure
+       if(enc->pic.picture_type == PIPE_H264_ENC_PICTURE_TYPE_B) {
+               struct rvce_cpb_slot *l1 = l1_slot(enc);
+               frame_offset(enc, l1, &luma_offset, &chroma_offset);
+               RVCE_CS(l1->picture_type); // encPicType
+               RVCE_CS(l1->frame_num); // frameNumber
+               RVCE_CS(l1->pic_order_cnt); // pictureOrderCount
+               RVCE_CS(luma_offset); // lumaOffset
+               RVCE_CS(chroma_offset); // chromaOffset
+       } else {
                RVCE_CS(0x00000000); // encPicType
                RVCE_CS(0x00000000); // frameNumber
                RVCE_CS(0x00000000); // pictureOrderCount
                RVCE_CS(0xffffffff); // lumaOffset
                RVCE_CS(0xffffffff); // chromaOffset
        }
-       
+
        frame_offset(enc, current_slot(enc), &luma_offset, &chroma_offset);
        RVCE_CS(luma_offset); // encReconstructedLumaOffset
        RVCE_CS(chroma_offset); // encReconstructedChromaOffset