1 /* 2 * Copyright (c) 2018, 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 media_packet.h 25 //! \brief Defines the common interface for media packet 26 //! \details The media packet is further sub-divided into mdf and cmd type 27 //! this file is for the base interface which is shared by all packet. 28 //! 29 30 #ifndef __MEDIA_PACKET_H__ 31 #define __MEDIA_PACKET_H__ 32 #include <stdint.h> 33 #include <memory> 34 #include <string> 35 #include "media_user_setting.h" 36 #include "mhw_itf.h" 37 #include "mhw_utilities_next.h" 38 #include "mos_defs.h" 39 #include "mos_os_specific.h" 40 #include "mos_os.h" 41 #include "mhw_cmdpar.h" 42 #include "mhw_mi_itf.h" 43 class MediaStatusReport; 44 class MhwMiInterface; 45 namespace mhw{namespace mi{class Itf;}} // namespace mhw 46 47 #define __SETPAR(CMD, itf) \ 48 \ 49 auto &par = itf->MHW_GETPAR_F(CMD)(); \ 50 par = {}; \ 51 using setting_t = typename std::remove_reference<decltype(*itf)>::type::ParSetting; \ 52 auto p = dynamic_cast<const setting_t *>(this); \ 53 if (p) \ 54 { \ 55 MHW_CHK_STATUS_RETURN(p->MHW_SETPAR_F(CMD)(par)); \ 56 } \ 57 if (m_featureManager) \ 58 { \ 59 for (auto feature : *m_featureManager) \ 60 { \ 61 p = dynamic_cast<const setting_t *>(feature); \ 62 if (p) \ 63 { \ 64 MHW_CHK_STATUS_RETURN(p->MHW_SETPAR_F(CMD)(par)); \ 65 } \ 66 } \ 67 } 68 69 #define SETPAR(CMD, itf) \ 70 { \ 71 __SETPAR(CMD, itf) \ 72 } 73 74 #define SETPAR_AND_ADDCMD(CMD, itf, ...) \ 75 { \ 76 __SETPAR(CMD, itf) \ 77 MHW_CHK_STATUS_RETURN(itf->MHW_ADDCMD_F(CMD)(__VA_ARGS__)); \ 78 } 79 80 namespace CMRT_UMD 81 { 82 class CmTask; 83 } 84 class MediaTask; 85 class MediaPacket 86 { 87 public: 88 enum PacketPhaseFlag 89 { 90 firstPacket = 0x01, 91 lastPacket = 0x02, 92 otherPacket = 0x04 93 }; 94 ~MediaPacket()95 virtual ~MediaPacket() { } 96 //! 97 //! \brief MediaPacket constructor 98 //! \param [in] task 99 //! Pointer to MediaTask, it's assigned when create the packet, 100 //! the task is associated with current packet for future submit 101 //! MediaPacket(MediaTask * task)102 MediaPacket(MediaTask* task) : m_task(task) { } 103 104 //! 105 //! \brief Initialize the media packet, allocate required resources 106 //! \return MOS_STATUS 107 //! MOS_STATUS_SUCCESS if success, else fail reason 108 //! 109 virtual MOS_STATUS Init() = 0; 110 111 //! 112 //! \brief Destroy the media packet and release the resources 113 //! \return MOS_STATUS 114 //! MOS_STATUS_SUCCESS if success, else fail reason 115 //! 116 virtual MOS_STATUS Destroy() = 0; 117 118 //! 119 //! \brief Prepare the parameters for command submission 120 //! \return MOS_STATUS 121 //! MOS_STATUS_SUCCESS if success, else fail reason 122 //! 123 virtual MOS_STATUS Prepare() = 0; 124 125 //! 126 //! \brief Add the command sequence into the commandBuffer and 127 //! and return to the caller task 128 //! \param [in] commandBuffer 129 //! Pointer to the command buffer which is allocated by caller 130 //! \return MOS_STATUS 131 //! MOS_STATUS_SUCCESS if success, else fail reason 132 //! 133 virtual MOS_STATUS Submit(MOS_COMMAND_BUFFER* commandBuffer, uint8_t packetPhase = otherPacket) 134 { 135 return MOS_STATUS_SUCCESS; 136 } 137 138 //! 139 //! \brief Add CmKernel into CmTask and return to the caller task 140 //! \param [in] cmTask 141 //! Pointer to the CmTask which is created by caller 142 //! \return MOS_STATUS 143 //! MOS_STATUS_SUCCESS if success, else fail reason 144 //! Submit(CMRT_UMD::CmTask * cmTask)145 virtual MOS_STATUS Submit(CMRT_UMD::CmTask* cmTask) 146 { 147 return MOS_STATUS_SUCCESS; 148 } 149 150 //! \brief Calculate Command Size 151 //! 152 //! \param [in, out] commandBufferSize 153 //! requested size 154 //! \param [in, out] requestedPatchListSize 155 //! requested size 156 //! \return uint32_t 157 //! Command size calculated 158 //! CalculateCommandSize(uint32_t & commandBufferSize,uint32_t & requestedPatchListSize)159 virtual MOS_STATUS CalculateCommandSize( 160 uint32_t &commandBufferSize, 161 uint32_t &requestedPatchListSize) 162 { 163 return MOS_STATUS_SUCCESS; 164 } 165 166 //! 167 //! \brief Get current associated media task 168 //! \return MediaTask* 169 //! return the media task pointer 170 //! GetActiveTask()171 MediaTask* GetActiveTask() 172 { 173 return m_task; 174 } 175 176 177 //! 178 //! \brief Dump output resources or infomation after submit 179 //! \return MOS_STATUS 180 //! MOS_STATUS_SUCCESS if success, else fail reason 181 //! DumpOutput()182 virtual MOS_STATUS DumpOutput() 183 { 184 return MOS_STATUS_SUCCESS; 185 } 186 187 //! 188 //! \brief Get Packet Name 189 //! \return std::string 190 //! GetPacketName()191 virtual std::string GetPacketName() 192 { 193 return ""; 194 } 195 196 protected: 197 198 //! 199 //! \brief Start Status Report 200 //! \param [in] srType 201 //! status report type for send cmds 202 //! \param [in, out] cmdBuffer 203 //! cmdbuffer to send cmds 204 //! \return MOS_STATUS 205 //! MOS_STATUS_SUCCESS if success, else fail reason 206 //! 207 virtual MOS_STATUS StartStatusReport( 208 uint32_t srType, 209 MOS_COMMAND_BUFFER *cmdBuffer); 210 211 //! 212 //! \brief Start Status Report - Refactor Version 213 //! \param [in] srType 214 //! status report type for send cmds 215 //! \param [in, out] cmdBuffer 216 //! cmdbuffer to send cmds 217 //! \return MOS_STATUS 218 //! MOS_STATUS_SUCCESS if success, else fail reason 219 //! 220 virtual MOS_STATUS StartStatusReportNext( 221 uint32_t srType, 222 MOS_COMMAND_BUFFER *cmdBuffer); 223 224 virtual MOS_STATUS UpdateStatusReport( 225 uint32_t srType, 226 MOS_COMMAND_BUFFER *cmdBuffer); 227 228 //! 229 //! \brief Update Status Report - Refactor Version 230 //! \param [in] srType 231 //! status report type for send cmds 232 //! \param [in, out] cmdBuffer 233 //! cmdbuffer to send cmds 234 //! \return MOS_STATUS 235 //! MOS_STATUS_SUCCESS if success, else fail reason 236 //! 237 virtual MOS_STATUS UpdateStatusReportNext( 238 uint32_t srType, 239 MOS_COMMAND_BUFFER *cmdBuffer); 240 241 //! 242 //! \brief End Status Report 243 //! \param [in] srType 244 //! status report type for send cmds 245 //! \param [in, out] cmdBuffer 246 //! cmdbuffer to send cmds 247 //! \return MOS_STATUS 248 //! MOS_STATUS_SUCCESS if success, else fail reason 249 //! 250 virtual MOS_STATUS EndStatusReport( 251 uint32_t srType, 252 MOS_COMMAND_BUFFER *cmdBuffer); 253 254 //! 255 //! \brief End Status Report - Refactor Version 256 //! \param [in] srType 257 //! status report type for send cmds 258 //! \param [in, out] cmdBuffer 259 //! cmdbuffer to send cmds 260 //! \return MOS_STATUS 261 //! MOS_STATUS_SUCCESS if success, else fail reason 262 //! 263 virtual MOS_STATUS EndStatusReportNext( 264 uint32_t srType, 265 MOS_COMMAND_BUFFER *cmdBuffer); 266 267 //! 268 //! \brief Set the start tag in the command buffer 269 //! \param [in] osResource 270 //! reource used in the cmd 271 //! \param [in] offset 272 //! reource offset used the cmd 273 //! \param [in] srType 274 //! status report type 275 //! \param [in, out] cmdBuffer 276 //! cmdbuffer to send cmds 277 //! \return MOS_STATUS 278 //! MOS_STATUS_SUCCESS if success, else fail reason 279 //! 280 virtual MOS_STATUS SetStartTag( 281 MOS_RESOURCE *osResource, 282 uint32_t offset, 283 uint32_t srType, 284 MOS_COMMAND_BUFFER *cmdBuffer); 285 286 //! 287 //! \brief Set the start tag in the command buffer - Refactor Version 288 //! \param [in] osResource 289 //! reource used in the cmd 290 //! \param [in] offset 291 //! reource offset used the cmd 292 //! \param [in] srType 293 //! status report type 294 //! \param [in, out] cmdBuffer 295 //! cmdbuffer to send cmds 296 //! \return MOS_STATUS 297 //! MOS_STATUS_SUCCESS if success, else fail reason 298 //! 299 virtual MOS_STATUS SetStartTagNext( 300 MOS_RESOURCE *osResource, 301 uint32_t offset, 302 uint32_t srType, 303 MOS_COMMAND_BUFFER *cmdBuffer); 304 305 //! 306 //! \brief Set the end tag in the command buffer 307 //! \param [in] osResource 308 //! reource used in the cmd 309 //! \param [in] offset 310 //! reource offset used the cmd 311 //! \param [in] srType 312 //! status report type 313 //! \param [in, out] cmdBuffer 314 //! cmdbuffer to send cmds 315 //! \return MOS_STATUS 316 //! MOS_STATUS_SUCCESS if success, else fail reason 317 //! 318 virtual MOS_STATUS SetEndTag( 319 MOS_RESOURCE *osResource, 320 uint32_t offset, 321 uint32_t srType, 322 MOS_COMMAND_BUFFER *cmdBuffer); 323 324 //! 325 //! \brief Set the end tag in the command buffer - Refactor Version 326 //! \param [in] osResource 327 //! reource used in the cmd 328 //! \param [in] offset 329 //! reource offset used the cmd 330 //! \param [in] srType 331 //! status report type 332 //! \param [in, out] cmdBuffer 333 //! cmdbuffer to send cmds 334 //! \return MOS_STATUS 335 //! MOS_STATUS_SUCCESS if success, else fail reason 336 //! 337 virtual MOS_STATUS SetEndTagNext( 338 MOS_RESOURCE *osResource, 339 uint32_t offset, 340 uint32_t srType, 341 MOS_COMMAND_BUFFER *cmdBuffer); 342 343 protected: 344 MediaTask *m_task = nullptr; //!< MediaTask associated with current packet 345 PMOS_INTERFACE m_osInterface = nullptr; 346 MhwMiInterface *m_miInterface = nullptr; 347 MediaStatusReport *m_statusReport = nullptr; 348 std::shared_ptr<mhw::mi::Itf> m_miItf = nullptr; 349 MediaUserSettingSharedPtr m_userSettingPtr = nullptr; //!< usersettingInstance 350 MEDIA_CLASS_DEFINE_END(MediaPacket) 351 }; 352 353 #endif // !__MEDIA_PACKET_H__ 354