1 /* 2 * Copyright (c) 2018-2021, Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23 //! 24 //! \file encode_huc.h 25 //! \brief Defines the common interface for media huc usage 26 //! \details The media huc interface is further sub-divided by different huc usages, 27 //! this file is for the base interface which is shared by all components. 28 //! 29 30 #ifndef __ENCODE_HUC_H__ 31 #define __ENCODE_HUC_H__ 32 33 #include "codec_hw_next.h" 34 #include "mos_defs.h" 35 #include "media_cmd_packet.h" 36 #include "encode_pipeline.h" 37 #include "mhw_vdbox_vdenc_itf.h" 38 #include "mhw_vdbox_huc_itf.h" 39 #include "mhw_vdbox_avp_itf.h" 40 #include "mhw_vdbox_mfx_itf.h" 41 #include "mhw_mi_itf.h" 42 43 #if (_SW_BRC) 44 #include "encode_sw_brc.h" 45 #endif // !_SW_BRC 46 47 #include "encode_status_report.h" 48 #include "encode_status_report_defs.h" 49 50 #define HUC_CHK_STATUS_RETURN(_stmt) \ 51 MOS_CHK_STATUS_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_HW, _stmt) 52 53 #define HUC_CHK_NULL_RETURN(_stmt) \ 54 MOS_CHK_NULL_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_HW, _stmt) 55 56 namespace encode 57 { 58 class EncodeHucPkt : public CmdPacket, 59 public MediaStatusReportObserver, 60 public mhw::vdbox::vdenc::Itf::ParSetting, 61 public mhw::vdbox::huc::Itf::ParSetting, 62 public mhw::vdbox::avp::Itf::ParSetting, 63 public mhw::vdbox::mfx::Itf::ParSetting, 64 public mhw::mi::Itf::ParSetting 65 { 66 public: EncodeHucPkt(MediaPipeline * pipeline,MediaTask * task,CodechalHwInterfaceNext * hwInterface)67 EncodeHucPkt(MediaPipeline *pipeline, MediaTask *task, CodechalHwInterfaceNext *hwInterface) : 68 CmdPacket(task), 69 m_pipeline(dynamic_cast<EncodePipeline *>(pipeline)) 70 { 71 ENCODE_CHK_NULL_NO_STATUS_RETURN(hwInterface); 72 ENCODE_CHK_NULL_NO_STATUS_RETURN(m_pipeline); 73 74 m_hwInterface = hwInterface; 75 m_osInterface = hwInterface->GetOsInterface(); 76 m_featureManager = m_pipeline->GetFeatureManager(); 77 m_statusReport = m_pipeline->GetStatusReportInstance(); 78 79 m_miItf = std::static_pointer_cast<mhw::mi::Itf>(hwInterface->GetMiInterfaceNext()); 80 if(m_osInterface) 81 { 82 m_userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface); 83 } 84 if (!m_userSettingPtr) 85 { 86 ENCODE_NORMALMESSAGE("Initialize m_userSettingPtr instance failed!"); 87 } 88 89 m_hucItf = std::static_pointer_cast<mhw::vdbox::huc::Itf>(hwInterface->GetHucInterfaceNext()); 90 m_vdencItf = std::static_pointer_cast<mhw::vdbox::vdenc::Itf>(m_hwInterface->GetVdencInterfaceNext()); 91 m_avpItf = std::static_pointer_cast<mhw::vdbox::avp::Itf>((hwInterface->GetAvpInterfaceNext())); 92 m_mfxItf = std::static_pointer_cast<mhw::vdbox::mfx::Itf>(hwInterface->GetMfxInterfaceNext()); 93 } 94 ~EncodeHucPkt()95 virtual ~EncodeHucPkt() {} 96 97 virtual MOS_STATUS Init() override; 98 99 virtual MOS_STATUS AllocateResources(); 100 101 virtual MOS_STATUS Execute(PMOS_COMMAND_BUFFER cmdBuffer, bool storeHucStatus2Needed, bool prologNeeded, HuCFunction function = NONE_BRC); 102 103 protected: 104 105 //! 106 //! \brief Add HUC_PIPE_MODE_SELECT command 107 //! \param [in] cmdBuffer 108 //! Pointer to command buffer 109 //! \return MOS_STATUS 110 //! MOS_STATUS_SUCCESS if success, else fail reason 111 //! 112 MOS_STATUS AddAllCmds_HUC_PIPE_MODE_SELECT(PMOS_COMMAND_BUFFER cmdBuffer) const; 113 114 //! 115 //! \brief Add HUC_IMEM_STATE command 116 //! \param [in] cmdBuffer 117 //! Pointer to command buffer 118 //! \return MOS_STATUS 119 //! MOS_STATUS_SUCCESS if success, else fail reason 120 //! 121 MOS_STATUS AddAllCmds_HUC_IMEM_STATE(PMOS_COMMAND_BUFFER cmdBuffer) const; 122 123 MHW_SETPAR_DECL_HDR(VD_PIPELINE_FLUSH); 124 125 //! 126 //! \brief Store HuCStatus2 127 //! \param [in] cmdBuffer 128 //! Pointer to command buffer 129 //! \param [in] storeHucStatus2Needed 130 //! inditect if sstore huc status2 register needed 131 //! \return MOS_STATUS 132 //! MOS_STATUS_SUCCESS if success, else fail reason 133 //! 134 virtual MOS_STATUS StoreHuCStatus2Register(PMOS_COMMAND_BUFFER cmdBuffer, bool storeHucStatus2Needed); 135 136 //! 137 //! \brief Store HuCStatus 138 //! \param [in] cmdBuffer 139 //! Pointer to command buffer 140 //! \return MOS_STATUS 141 //! MOS_STATUS_SUCCESS if success, else fail reason 142 //! 143 virtual MOS_STATUS StoreHuCStatusRegister(PMOS_COMMAND_BUFFER cmdBuffer); 144 145 //! 146 //! \brief One frame is completed 147 //! \param [in] mfxStatus 148 //! pointer to status buffer which for MFX 149 //! \param [in] rcsStatus 150 //! pointer to status buffer which for RCS 151 //! \param [in, out] statusReport 152 //! pointer of EncoderStatusReport 153 //! \return MOS_STATUS 154 //! MOS_STATUS_SUCCESS if success, else fail reason 155 //! 156 virtual MOS_STATUS Completed(void *mfxStatus, void *rcsStatus, void *statusReport) override; 157 158 bool IsHuCStsUpdNeeded(); 159 160 MOS_STATUS SendPrologCmds( 161 MOS_COMMAND_BUFFER &cmdBuffer); 162 163 virtual MOS_STATUS AddForceWakeup(MOS_COMMAND_BUFFER &cmdBuffer); 164 165 void SetPerfTag(uint16_t type, uint16_t mode, uint16_t picCodingType); 166 167 MOS_STATUS StartPerfCollect(MOS_COMMAND_BUFFER &cmdBuffer); 168 169 MOS_STATUS EndPerfCollect(MOS_COMMAND_BUFFER &cmdBuffer); 170 171 #if USE_CODECHAL_DEBUG_TOOL 172 DumpInput()173 virtual MOS_STATUS DumpInput() { return MOS_STATUS_SUCCESS; }; 174 175 virtual MOS_STATUS DumpRegion( 176 uint32_t regionNum, 177 const char *regionName, 178 bool inputBuffer, 179 CodechalHucRegionDumpType dumpType, 180 uint32_t size = 0); 181 #endif 182 #if _SW_BRC 183 virtual MOS_STATUS InitSwBrc(HuCFunction function); 184 std::shared_ptr<EncodeSwBrc> m_swBrc = nullptr; 185 #endif // !_SW_BRC 186 187 EncodePipeline *m_pipeline = nullptr; 188 EncodeAllocator *m_allocator = nullptr; 189 MediaFeatureManager *m_featureManager = nullptr; 190 CodechalHwInterfaceNext *m_hwInterface = nullptr; 191 192 std::shared_ptr<mhw::vdbox::vdenc::Itf> m_vdencItf = nullptr; 193 std::shared_ptr<mhw::vdbox::huc::Itf> m_hucItf = nullptr; 194 std::shared_ptr<mhw::vdbox::avp::Itf> m_avpItf = nullptr; 195 std::shared_ptr<mhw::vdbox::mfx::Itf> m_mfxItf = nullptr; 196 197 PMOS_RESOURCE m_resHucStatus2Buffer = nullptr; 198 MHW_VDBOX_NODE_IND m_vdboxIndex = MHW_VDBOX_NODE_1; 199 bool m_skuFtrEnableMediaKernels = true; 200 uint32_t m_hucStatus2ImemLoadedMask = 0x40; 201 bool m_enableHucStatusReport = false; 202 203 MEDIA_CLASS_DEFINE_END(encode__EncodeHucPkt) 204 }; 205 } 206 #endif // !__ENCODE_HUC_H__ 207