1 /* 2 * Copyright (c) 2019-2020, 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 decode_scalability_multipipe.h 25 //! \brief Defines the common interface for decode scalability mulitpipe mode. 26 //! \details The decode scalability mulitpipe interface is further sub-divided by codecs, 27 //! this file is for the base interface which is shared by all codecs. 28 //! 29 30 #ifndef __DECODE_SCALABILITY_MULTIPIPE_H__ 31 #define __DECODE_SCALABILITY_MULTIPIPE_H__ 32 #include "mos_defs.h" 33 #include "mos_os.h" 34 #include "codechal_hw.h" 35 #include "decode_scalability_multipipe_next.h" 36 #include "decode_scalability_option.h" 37 #include "mos_os_virtualengine_scalability.h" 38 #include "decode_phase.h" 39 40 namespace decode 41 { 42 class DecodeScalabilityMultiPipe : public DecodeScalabilityMultiPipeNext 43 { 44 public: 45 //! 46 //! \brief Decode scalability mulitipipe constructor 47 //! \param [in] hwInterface 48 //! Pointer to HwInterface 49 //! \param [in] mediaContext 50 //! Pointer to MediaContext 51 //! \param [in] componentType 52 //! Component type 53 //! 54 DecodeScalabilityMultiPipe(void *hwInterface, MediaContext *mediaContext, uint8_t componentType); 55 56 //! 57 //! \brief Decode scalability mulitipipe destructor 58 //! 59 ~DecodeScalabilityMultiPipe(); 60 61 //! 62 //! \brief Copy constructor 63 //! 64 DecodeScalabilityMultiPipe(const DecodeScalabilityMultiPipe &) = delete; 65 66 //! 67 //! \brief Copy assignment operator 68 //! 69 DecodeScalabilityMultiPipe &operator=(const DecodeScalabilityMultiPipe &) = delete; 70 71 //! 72 //! \brief Initialize the media scalability 73 //! \details It will prepare the resources needed in scalability 74 //! and initialize the state of scalability 75 //! \param [in] option 76 //! Input scalability option 77 //! \return MOS_STATUS 78 //! MOS_STATUS_SUCCESS if success, else fail reason 79 //! 80 MOS_STATUS Initialize(const MediaScalabilityOption &option) override; 81 82 //! 83 //! \brief Construct parameters for GPU context create. 84 //! \param [in, out] gpuCtxCreateOption 85 //! Pointer to the GPU Context Create Option 86 //! \return MOS_STATUS 87 //! MOS_STATUS_SUCCESS if success, else fail reason 88 //! 89 MOS_STATUS GetGpuCtxCreationOption(MOS_GPUCTX_CREATOPTIONS *gpuCtxCreateOption) override; 90 91 //! 92 //! \brief Destroy the media scalability 93 //! \return MOS_STATUS 94 //! MOS_STATUS_SUCCESS if success, else fail reason 95 //! 96 virtual MOS_STATUS Destroy() override; 97 98 //! 99 //! \brief Update the media scalability state 100 //! \param [in] statePars 101 //! parameters to update the state 102 //! \return MOS_STATUS 103 //! MOS_STATUS_SUCCESS if success, else fail reason 104 //! 105 MOS_STATUS UpdateState(void *statePars) override; 106 107 //! 108 //! \brief Verify command buffer 109 //! \param [in] requestedSize 110 //! requested size for command buffer 111 //! \param [in] requestedPatchListSize 112 //! requested size for patched list 113 //! \param [out] singleTaskPhaseSupportedInPak 114 //! Inidcate if to use single task phase in pak. 115 //! \return MOS_STATUS 116 //! MOS_STATUS_SUCCESS if success, else fail reason 117 //! 118 MOS_STATUS VerifyCmdBuffer(uint32_t requestedSize, uint32_t requestedPatchListSize, bool &singleTaskPhaseSupportedInPak) override; 119 120 //! 121 //! \brief Get command buffer 122 //! \param [in, out] cmdBuffer 123 //! Pointer to command buffer 124 //! \return MOS_STATUS 125 //! MOS_STATUS_SUCCESS if success, else fail reason 126 //! 127 MOS_STATUS GetCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer, bool frameTrackingRequested = true) override; 128 129 //! 130 //! \brief Return command buffer 131 //! \param [in, out] cmdBuffer 132 //! Pointer to command buffer 133 //! \return MOS_STATUS 134 //! MOS_STATUS_SUCCESS if success, else fail reason 135 //! 136 MOS_STATUS ReturnCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer) override; 137 138 //! 139 //! \brief Submit command buffer 140 //! \param [in, out] cmdBuffer 141 //! Pointer to command buffer 142 //! \return MOS_STATUS 143 //! MOS_STATUS_SUCCESS if success, else fail reason 144 //! 145 MOS_STATUS SubmitCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer) override; 146 147 //! 148 //! \brief Add synchronization for pipes. 149 //! \param [in] syncType 150 //! type of pipe sync 151 //! \param [in] semaphoreId 152 //! Id of the semaphore used for this sync 153 //! \param [in, out] cmdBuffer 154 //! Pointer to command buffer 155 //! \return MOS_STATUS 156 //! MOS_STATUS_SUCCESS if success, else fail reason 157 //! 158 MOS_STATUS SyncPipe(uint32_t syncType, uint32_t semaphoreId, PMOS_COMMAND_BUFFER cmdBuffer) override; 159 160 //! 161 //! \brief Reset semaphore 162 //! \param [in] syncType 163 //! type of pipe sync to find the related semaphore 164 //! \param [in] semaphoreId 165 //! Id of the semaphore for reset 166 //! \param [in, out] cmdBuffer 167 //! \return MOS_STATUS 168 //! MOS_STATUS_SUCCESS if success, else fail reason 169 //! 170 MOS_STATUS ResetSemaphore(uint32_t syncType, uint32_t semaphoreId, PMOS_COMMAND_BUFFER cmdBuffer) override; 171 //! 172 //! \brief Create decode multi pipe 173 //! \param [in] hwInterface 174 //! void type hw interface 175 //! \param [in] mediaContext 176 //! required media context to create multi pipe 177 //! \param [in] componentType 178 //! Inidcate component. 179 //! \return MOS_STATUS 180 //! MOS_STATUS_SUCCESS if success, else fail reason 181 //! 182 static MOS_STATUS CreateDecodeMultiPipe(void *hwInterface, MediaContext *mediaContext, uint8_t componentType); 183 184 protected: 185 186 //! 187 //! \brief Resizes the cmd buffer and patch list with cmd buffer header 188 //! 189 //! \param [in] requestedCommandBufferSize 190 //! Requested resize command buffer size 191 //! \param [in] requestedPatchListSize 192 //! Requested resize patchlist size 193 //! 194 //! \return MOS_STATUS 195 //! MOS_STATUS_SUCCESS if success, else fail reason 196 //! 197 virtual MOS_STATUS ResizeCommandBufferAndPatchList( 198 uint32_t requestedCommandBufferSize, 199 uint32_t requestedPatchListSize) override; 200 201 //! 202 //! \brief Verify primary command buffer 203 //! \param [in] requestedSize 204 //! requested size for command buffer 205 //! \param [in] requestedPatchListSize 206 //! requested size for patched list 207 //! \param [out] singleTaskPhaseSupportedInPak 208 //! Inidcate if to use single task phase in pak. 209 //! \return MOS_STATUS 210 //! MOS_STATUS_SUCCESS if success, else fail reason 211 //! 212 virtual MOS_STATUS VerifySpaceAvailable(uint32_t requestedSize, uint32_t requestedPatchListSize, bool &singleTaskPhaseSupportedInPak) override; 213 214 //! 215 //! \brief Set hint parameters 216 //! \return MOS_STATUS 217 //! MOS_STATUS_SUCCESS if success, else fail reason 218 //! 219 MOS_STATUS SetHintParams(); 220 221 //! 222 //! \brief Populate hint parameters 223 //! \param [in] cmdBuffer 224 //! Pointer to command buffer 225 //! \return MOS_STATUS 226 //! MOS_STATUS_SUCCESS if success, else fail reason 227 //! 228 MOS_STATUS PopulateHintParams(PMOS_COMMAND_BUFFER cmdBuffer); 229 230 //! 231 //! \brief Sync all pipes 232 //! \param [in] cmdBuffer 233 //! Pointer to command buffer 234 //! \return MOS_STATUS 235 //! MOS_STATUS_SUCCESS if success, else fail reason 236 //! 237 MOS_STATUS SyncAllPipes(PMOS_COMMAND_BUFFER cmdBuffer); 238 239 //! 240 //! \brief Sync pipes with first pipe wait for others 241 //! \detials Only support to use this sync once per frame. 242 //! \param [in] cmdBuffer 243 //! Pointer to command buffer 244 //! \param [in] pipeIdx 245 //! The index of pipeline which wait for others 246 //! \return MOS_STATUS 247 //! MOS_STATUS_SUCCESS if success, else fail reason 248 //! 249 MOS_STATUS SyncOnePipeWaitOthers(PMOS_COMMAND_BUFFER cmdBuffer, uint32_t pipeIdx); 250 251 //! \brief Allocate resources for semaphore 252 //! \return MOS_STATUS 253 //! MOS_STATUS_SUCCESS if success, else fail reason 254 //! 255 MOS_STATUS AllocateSemaphore(); 256 257 //! 258 //! \brief Send Cmd buffer Attributes with frame tracking info 259 //! 260 //! \param [in] cmdBuffer 261 //! Reference to command buffer 262 //! \param [in] frameTrackingRequested 263 //! Indicate if frame tracking is requested 264 //! 265 //! \return MOS_STATUS 266 //! MOS_STATUS_SUCCESS if success, else fail reason 267 //! 268 virtual MOS_STATUS SendAttrWithFrameTracking(MOS_COMMAND_BUFFER &cmdBuffer, bool frameTrackingRequested) override; 269 270 static const uint8_t m_initSecondaryCmdBufNum = 8; //!< The initial secondary command buffer size 271 static const uint8_t m_maxCmdBufferSetsNum = 16; //!< The max number of command buffer sets 272 273 CodechalHwInterface *m_hwInterface = nullptr; 274 MOS_COMMAND_BUFFER m_primaryCmdBuffer = {}; 275 std::vector<MOS_COMMAND_BUFFER> m_secondaryCmdBuffers; 276 277 std::vector<std::vector<MOS_RESOURCE>> m_resSemaphoreAllPipes; //!< The sync semaphore between all pipes 278 std::vector<std::vector<MOS_RESOURCE>> m_resSemaphoreOnePipeWait; //!< The sync semaphore between main pipe and other pipes 279 uint8_t m_semaphoreIndex = 0; //!< The index for semaphore using by current frame 280 281 DecodePhase *m_phase = nullptr; 282 283 MEDIA_CLASS_DEFINE_END(decode__DecodeScalabilityMultiPipe) 284 }; 285 } // namespace decode 286 #endif // !__DECODE_SCALABILITY_MULTIPIPE_H__ 287