Path: blob/21.2-virgl/src/gallium/drivers/radeon/radeon_vce_50.c
4570 views
/**************************************************************************1*2* Copyright 2013 Advanced Micro Devices, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#include "pipe/p_video_codec.h"28#include "radeon_vce.h"29#include "radeon_video.h"30#include "si_pipe.h"31#include "util/u_memory.h"32#include "util/u_video.h"33#include "vl/vl_video_buffer.h"3435#include <stdio.h>3637static void rate_control(struct rvce_encoder *enc)38{39RVCE_BEGIN(0x04000005); // rate control40RVCE_CS(enc->pic.rate_ctrl.rate_ctrl_method); // encRateControlMethod41RVCE_CS(enc->pic.rate_ctrl.target_bitrate); // encRateControlTargetBitRate42RVCE_CS(enc->pic.rate_ctrl.peak_bitrate); // encRateControlPeakBitRate43RVCE_CS(enc->pic.rate_ctrl.frame_rate_num); // encRateControlFrameRateNum44RVCE_CS(0x00000000); // encGOPSize45RVCE_CS(enc->pic.quant_i_frames); // encQP_I46RVCE_CS(enc->pic.quant_p_frames); // encQP_P47RVCE_CS(enc->pic.quant_b_frames); // encQP_B48RVCE_CS(enc->pic.rate_ctrl.vbv_buffer_size); // encVBVBufferSize49RVCE_CS(enc->pic.rate_ctrl.frame_rate_den); // encRateControlFrameRateDen50RVCE_CS(0x00000000); // encVBVBufferLevel51RVCE_CS(0x00000000); // encMaxAUSize52RVCE_CS(0x00000000); // encQPInitialMode53RVCE_CS(enc->pic.rate_ctrl.target_bits_picture); // encTargetBitsPerPicture54RVCE_CS(enc->pic.rate_ctrl.peak_bits_picture_integer); // encPeakBitsPerPictureInteger55RVCE_CS(enc->pic.rate_ctrl.peak_bits_picture_fraction); // encPeakBitsPerPictureFractional56RVCE_CS(0x00000000); // encMinQP57RVCE_CS(0x00000033); // encMaxQP58RVCE_CS(0x00000000); // encSkipFrameEnable59RVCE_CS(0x00000000); // encFillerDataEnable60RVCE_CS(0x00000000); // encEnforceHRD61RVCE_CS(0x00000000); // encBPicsDeltaQP62RVCE_CS(0x00000000); // encReferenceBPicsDeltaQP63RVCE_CS(0x00000000); // encRateControlReInitDisable64RVCE_CS(0x00000000); // encLCVBRInitQPFlag65RVCE_CS(0x00000000); // encLCVBRSATDBasedNonlinearBitBudgetFlag66RVCE_END();67}6869static void encode(struct rvce_encoder *enc)70{71signed luma_offset, chroma_offset, bs_offset;72unsigned dep, bs_idx = enc->bs_idx++;73int i;7475if (enc->dual_inst) {76if (bs_idx == 0)77dep = 1;78else if (enc->pic.picture_type == PIPE_H2645_ENC_PICTURE_TYPE_IDR)79dep = 0;80else81dep = 2;82} else83dep = 0;8485enc->task_info(enc, 0x00000003, dep, 0, bs_idx);8687RVCE_BEGIN(0x05000001); // context buffer88RVCE_READWRITE(enc->cpb.res->buf, enc->cpb.res->domains, 0); // encodeContextAddressHi/Lo89RVCE_END();9091bs_offset = -(signed)(bs_idx * enc->bs_size);9293RVCE_BEGIN(0x05000004); // video bitstream buffer94RVCE_WRITE(enc->bs_handle, RADEON_DOMAIN_GTT, bs_offset); // videoBitstreamRingAddressHi/Lo95RVCE_CS(enc->bs_size); // videoBitstreamRingSize96RVCE_END();9798if (enc->dual_pipe) {99unsigned aux_offset =100enc->cpb.res->buf->size - RVCE_MAX_AUX_BUFFER_NUM * RVCE_MAX_BITSTREAM_OUTPUT_ROW_SIZE * 2;101RVCE_BEGIN(0x05000002); // auxiliary buffer102for (i = 0; i < 8; ++i) {103RVCE_CS(aux_offset);104aux_offset += RVCE_MAX_BITSTREAM_OUTPUT_ROW_SIZE;105}106for (i = 0; i < 8; ++i)107RVCE_CS(RVCE_MAX_BITSTREAM_OUTPUT_ROW_SIZE);108RVCE_END();109}110111RVCE_BEGIN(0x03000001); // encode112RVCE_CS(enc->pic.frame_num ? 0x0 : 0x11); // insertHeaders113RVCE_CS(0x00000000); // pictureStructure114RVCE_CS(enc->bs_size); // allowedMaxBitstreamSize115RVCE_CS(0x00000000); // forceRefreshMap116RVCE_CS(0x00000000); // insertAUD117RVCE_CS(0x00000000); // endOfSequence118RVCE_CS(0x00000000); // endOfStream119RVCE_READ(enc->handle, RADEON_DOMAIN_VRAM,120(uint64_t)enc->luma->u.legacy.level[0].offset_256B * 256); // inputPictureLumaAddressHi/Lo121RVCE_READ(enc->handle, RADEON_DOMAIN_VRAM,122(uint64_t)enc->chroma->u.legacy.level[0].offset_256B * 256); // inputPictureChromaAddressHi/Lo123RVCE_CS(align(enc->luma->u.legacy.level[0].nblk_y, 16)); // encInputFrameYPitch124RVCE_CS(enc->luma->u.legacy.level[0].nblk_x * enc->luma->bpe); // encInputPicLumaPitch125RVCE_CS(enc->chroma->u.legacy.level[0].nblk_x * enc->chroma->bpe); // encInputPicChromaPitch126if (enc->dual_pipe)127RVCE_CS(0x00000000); // encInputPic(Addr|Array)Mode,encDisable(TwoPipeMode|MBOffloading)128else129RVCE_CS(0x00010000); // encInputPic(Addr|Array)Mode,encDisable(TwoPipeMode|MBOffloading)130RVCE_CS(0x00000000); // encInputPicTileConfig131RVCE_CS(enc->pic.picture_type); // encPicType132RVCE_CS(enc->pic.picture_type == PIPE_H2645_ENC_PICTURE_TYPE_IDR);// encIdrFlag133RVCE_CS(0x00000000); // encIdrPicId134RVCE_CS(0x00000000); // encMGSKeyPic135RVCE_CS(!enc->pic.not_referenced); // encReferenceFlag136RVCE_CS(0x00000000); // encTemporalLayerIndex137RVCE_CS(0x00000000); // num_ref_idx_active_override_flag138RVCE_CS(0x00000000); // num_ref_idx_l0_active_minus1139RVCE_CS(0x00000000); // num_ref_idx_l1_active_minus1140141i = enc->pic.frame_num - enc->pic.ref_idx_l0;142if (i > 1 && enc->pic.picture_type == PIPE_H2645_ENC_PICTURE_TYPE_P) {143RVCE_CS(0x00000001); // encRefListModificationOp144RVCE_CS(i - 1); // encRefListModificationNum145} else {146RVCE_CS(0x00000000); // encRefListModificationOp147RVCE_CS(0x00000000); // encRefListModificationNum148}149150for (i = 0; i < 3; ++i) {151RVCE_CS(0x00000000); // encRefListModificationOp152RVCE_CS(0x00000000); // encRefListModificationNum153}154for (i = 0; i < 4; ++i) {155RVCE_CS(0x00000000); // encDecodedPictureMarkingOp156RVCE_CS(0x00000000); // encDecodedPictureMarkingNum157RVCE_CS(0x00000000); // encDecodedPictureMarkingIdx158RVCE_CS(0x00000000); // encDecodedRefBasePictureMarkingOp159RVCE_CS(0x00000000); // encDecodedRefBasePictureMarkingNum160}161162// encReferencePictureL0[0]163RVCE_CS(0x00000000); // pictureStructure164if (enc->pic.picture_type == PIPE_H2645_ENC_PICTURE_TYPE_P ||165enc->pic.picture_type == PIPE_H2645_ENC_PICTURE_TYPE_B) {166struct rvce_cpb_slot *l0 = si_l0_slot(enc);167si_vce_frame_offset(enc, l0, &luma_offset, &chroma_offset);168RVCE_CS(l0->picture_type); // encPicType169RVCE_CS(l0->frame_num); // frameNumber170RVCE_CS(l0->pic_order_cnt); // pictureOrderCount171RVCE_CS(luma_offset); // lumaOffset172RVCE_CS(chroma_offset); // chromaOffset173} else {174RVCE_CS(0x00000000); // encPicType175RVCE_CS(0x00000000); // frameNumber176RVCE_CS(0x00000000); // pictureOrderCount177RVCE_CS(0xffffffff); // lumaOffset178RVCE_CS(0xffffffff); // chromaOffset179}180181// encReferencePictureL0[1]182RVCE_CS(0x00000000); // pictureStructure183RVCE_CS(0x00000000); // encPicType184RVCE_CS(0x00000000); // frameNumber185RVCE_CS(0x00000000); // pictureOrderCount186RVCE_CS(0xffffffff); // lumaOffset187RVCE_CS(0xffffffff); // chromaOffset188189// encReferencePictureL1[0]190RVCE_CS(0x00000000); // pictureStructure191if (enc->pic.picture_type == PIPE_H2645_ENC_PICTURE_TYPE_B) {192struct rvce_cpb_slot *l1 = si_l1_slot(enc);193si_vce_frame_offset(enc, l1, &luma_offset, &chroma_offset);194RVCE_CS(l1->picture_type); // encPicType195RVCE_CS(l1->frame_num); // frameNumber196RVCE_CS(l1->pic_order_cnt); // pictureOrderCount197RVCE_CS(luma_offset); // lumaOffset198RVCE_CS(chroma_offset); // chromaOffset199} else {200RVCE_CS(0x00000000); // encPicType201RVCE_CS(0x00000000); // frameNumber202RVCE_CS(0x00000000); // pictureOrderCount203RVCE_CS(0xffffffff); // lumaOffset204RVCE_CS(0xffffffff); // chromaOffset205}206207si_vce_frame_offset(enc, si_current_slot(enc), &luma_offset, &chroma_offset);208RVCE_CS(luma_offset); // encReconstructedLumaOffset209RVCE_CS(chroma_offset); // encReconstructedChromaOffset210RVCE_CS(0x00000000); // encColocBufferOffset211RVCE_CS(0x00000000); // encReconstructedRefBasePictureLumaOffset212RVCE_CS(0x00000000); // encReconstructedRefBasePictureChromaOffset213RVCE_CS(0x00000000); // encReferenceRefBasePictureLumaOffset214RVCE_CS(0x00000000); // encReferenceRefBasePictureChromaOffset215RVCE_CS(0x00000000); // pictureCount216RVCE_CS(enc->pic.frame_num); // frameNumber217RVCE_CS(enc->pic.pic_order_cnt); // pictureOrderCount218RVCE_CS(0x00000000); // numIPicRemainInRCGOP219RVCE_CS(0x00000000); // numPPicRemainInRCGOP220RVCE_CS(0x00000000); // numBPicRemainInRCGOP221RVCE_CS(0x00000000); // numIRPicRemainInRCGOP222RVCE_CS(0x00000000); // enableIntraRefresh223RVCE_END();224}225226void si_vce_50_get_param(struct rvce_encoder *enc, struct pipe_h264_enc_picture_desc *pic)227{228}229230void si_vce_50_init(struct rvce_encoder *enc)231{232si_vce_40_2_2_init(enc);233234/* only the two below are different */235enc->rate_control = rate_control;236enc->encode = encode;237enc->si_get_pic_param = si_vce_50_get_param;238}239240241