| 1 | /* |
| 2 | * Copyright (c) 2019-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 | //! \file mos_gpucontext_next.h |
| 24 | //! \brief Container class for the basic gpu context |
| 25 | //! |
| 26 | |
| 27 | #ifndef __MOS_GPU_CONTEXT_NEXT_H__ |
| 28 | #define __MOS_GPU_CONTEXT_NEXT_H__ |
| 29 | |
| 30 | #include "mos_os.h" |
| 31 | |
| 32 | class CmdBufMgrNext; |
| 33 | class CommandBufferNext; |
| 34 | class CommandBufferSpecificNext; |
| 35 | class GraphicsResourceNext; |
| 36 | |
| 37 | //! |
| 38 | //! \class GpuContext |
| 39 | //! |
| 40 | class GpuContextNext |
| 41 | { |
| 42 | public: |
| 43 | //! |
| 44 | //! \brief Constructor |
| 45 | //! |
| 46 | GpuContextNext(){} |
| 47 | |
| 48 | //! |
| 49 | //! \brief Destructor |
| 50 | //! |
| 51 | virtual ~GpuContextNext(){} |
| 52 | |
| 53 | //! |
| 54 | //! \brief Clear gpu context |
| 55 | //! |
| 56 | virtual void Clear() = 0; |
| 57 | |
| 58 | //! |
| 59 | //! \brief Partial clear for deferred destroy - cleans resources but |
| 60 | //! leaves gpu context virtual destroy to the destructor. |
| 61 | //! |
| 62 | virtual void ClearForDeferredDestroy() {} |
| 63 | |
| 64 | //! |
| 65 | //! \brief Verify command buffer size |
| 66 | //! \details Verifys the buffer to be used for rendering GPU commands is large enough |
| 67 | //! \param [in] requestedSize |
| 68 | //! Buffer size requested |
| 69 | //! \return MOS_STATUS |
| 70 | //! Return MOS_STATUS_SUCCESS if successful (command buffer will be large enough) |
| 71 | //! otherwise failed reason |
| 72 | //! |
| 73 | virtual MOS_STATUS VerifyCommandBufferSize( |
| 74 | const uint32_t requestedSize) = 0; |
| 75 | |
| 76 | //! |
| 77 | //! \brief Get indirect state size |
| 78 | //! \details Retrieves indirect state to be used for rendering purposes |
| 79 | //! \param [out] offset |
| 80 | //! Reference to indirect buffer offset |
| 81 | //! \param [out] size |
| 82 | //! Reference to indirect buffer size |
| 83 | //! \return MOS_STATUS |
| 84 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 85 | //! |
| 86 | virtual MOS_STATUS GetIndirectState( |
| 87 | uint32_t &offset, |
| 88 | uint32_t &size) = 0; |
| 89 | |
| 90 | //! |
| 91 | //! \brief Get Indirect State Pointer |
| 92 | //! \param [out] indirectState |
| 93 | //! Pointer to Indirect State Buffer |
| 94 | //! \return MOS_STATUS |
| 95 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 96 | //! |
| 97 | virtual MOS_STATUS GetIndirectStatePointer( |
| 98 | uint8_t **indirectState) = 0; |
| 99 | |
| 100 | //! |
| 101 | //! \brief Get command buffer |
| 102 | //! \details Retrieves buffer to be used for rendering GPU commands |
| 103 | //! \param [in/out] cmdBuffer |
| 104 | //! Pointer to Command Buffer control structure |
| 105 | //! \param [in] flags |
| 106 | //! Flags to indicate command buffer property |
| 107 | //! \return MOS_STATUS |
| 108 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 109 | //! |
| 110 | virtual MOS_STATUS GetCommandBuffer( |
| 111 | PMOS_COMMAND_BUFFER cmdBuffer, |
| 112 | uint32_t flags) = 0; |
| 113 | |
| 114 | //! |
| 115 | //! \brief Return command buffer space |
| 116 | //! \details Return unused command buffer space |
| 117 | //! \param [in/out] cmdBuffer |
| 118 | //! Pointer to Command Buffer control structure |
| 119 | //! \param [in] flags |
| 120 | //! Flags to indicate command buffer property |
| 121 | //! |
| 122 | virtual void ReturnCommandBuffer( |
| 123 | PMOS_COMMAND_BUFFER cmdBuffer, |
| 124 | uint32_t flags) = 0; |
| 125 | |
| 126 | //! |
| 127 | //! \brief Submit command buffer |
| 128 | //! \details Submit the command buffer |
| 129 | //! \param [in] streamState |
| 130 | //! OS stream state |
| 131 | //! \param [in] cmdBuffer |
| 132 | //! Pointer to Command Buffer control structure |
| 133 | //! \param [in] nullRendering |
| 134 | //! boolean null rendering |
| 135 | //! \return MOS_STATUS |
| 136 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 137 | //! |
| 138 | virtual MOS_STATUS SubmitCommandBuffer( |
| 139 | MOS_STREAM_HANDLE streamState, |
| 140 | PMOS_COMMAND_BUFFER cmdBuffer, |
| 141 | bool nullRendering) = 0; |
| 142 | |
| 143 | //! |
| 144 | //! \brief Resizes the buffer to be used for rendering GPU commands |
| 145 | //! \param [in] requestedCommandBufferSize |
| 146 | //! requested command buffer size |
| 147 | //! \param [in] requestedPatchListSize |
| 148 | //! requested patch list size |
| 149 | //! \param [in] flags |
| 150 | //! Flags to indicate command buffer property |
| 151 | //! \return MOS_STATUS |
| 152 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 153 | //! |
| 154 | virtual MOS_STATUS ResizeCommandBufferAndPatchList( |
| 155 | uint32_t requestedCommandBufferSize, |
| 156 | uint32_t requestedPatchListSize, |
| 157 | uint32_t flags) = 0; |
| 158 | |
| 159 | //! |
| 160 | //! \brief Resets Gpu context States |
| 161 | //! \details Resets all status in current gpu status |
| 162 | //! |
| 163 | virtual void ResetGpuContextStatus() = 0; |
| 164 | |
| 165 | //! |
| 166 | //! \brief Get Gpu context handle |
| 167 | //! \details return the index in gpucontextNext mgr pool for current gpu context |
| 168 | //! |
| 169 | GPU_CONTEXT_HANDLE GetGpuContextHandle() { return m_gpuContextHandle; } |
| 170 | |
| 171 | //! |
| 172 | //! \brief Set Gpu context handle |
| 173 | //! \details Register the index in gpucontextNext mgr pool for current gpu context |
| 174 | //! |
| 175 | void SetGpuContextHandle(GPU_CONTEXT_HANDLE gpuContextHandle) |
| 176 | { |
| 177 | m_gpuContextHandle = gpuContextHandle; |
| 178 | } |
| 179 | |
| 180 | //! |
| 181 | //! \brief Set Gpu context |
| 182 | //! \details Set MOS Gpu context |
| 183 | //! |
| 184 | void SetGpuContext(MOS_GPU_CONTEXT gpuContext) |
| 185 | { |
| 186 | m_gpuContext = gpuContext; |
| 187 | } |
| 188 | |
| 189 | //! |
| 190 | //! \brief Get Gpu context Node |
| 191 | //! \details Return the hardware node for current gpu context |
| 192 | //! |
| 193 | MOS_GPU_NODE GetContextNode() { return m_nodeOrdinal; } |
| 194 | |
| 195 | //! |
| 196 | //! \brief Set Gpu context Node |
| 197 | //! \details Set the hardware node for current gpu context |
| 198 | //! |
| 199 | void SetContextNode(MOS_GPU_NODE nodeOrdinal) { m_nodeOrdinal = nodeOrdinal; } |
| 200 | |
| 201 | //! |
| 202 | //! \brief Get Gpu context ID |
| 203 | //! \details Return the umd side gpu context id for current gpu context |
| 204 | //! |
| 205 | MOS_GPU_CONTEXT GetGpuContextID() { return m_gpuContext; } |
| 206 | |
| 207 | //! |
| 208 | //! \brief Get indirect state size |
| 209 | //! |
| 210 | uint32_t GetIndirectStateSize() { return m_IndirectHeapSize; } |
| 211 | |
| 212 | //! |
| 213 | //! \brief Set indirect state size |
| 214 | //! |
| 215 | virtual MOS_STATUS SetIndirectStateSize(const uint32_t size) = 0; |
| 216 | |
| 217 | //! |
| 218 | //! \brief Get status buffer resource for current gpu context |
| 219 | //! \return MOS_RESOURCE_HANDLE |
| 220 | //! |
| 221 | MOS_RESOURCE_HANDLE GetStatusBufferResource() |
| 222 | { |
| 223 | return m_statusBufferResource; |
| 224 | } |
| 225 | |
| 226 | //! |
| 227 | //! \brief Get VE attribute buffer for current gpu context |
| 228 | //! \return MOS_CMD_BUF_ATTRI_VE* |
| 229 | //! |
| 230 | MOS_CMD_BUF_ATTRI_VE *GetAttributeVeBuffer() |
| 231 | { |
| 232 | return &m_bufAttriVe; |
| 233 | } |
| 234 | |
| 235 | virtual MOS_STATUS ResetCmdBuffer() |
| 236 | { |
| 237 | return MOS_STATUS_SUCCESS; |
| 238 | } |
| 239 | |
| 240 | virtual MOS_GPU_COMPONENT_ID GetGpuComponentId() = 0; |
| 241 | |
| 242 | virtual MOS_STATUS SetHybridCmdMgr(HybridCmdMgr *hybridCmdMgr) |
| 243 | { |
| 244 | m_hybridCmdMgr = hybridCmdMgr; |
| 245 | return MOS_STATUS_SUCCESS; |
| 246 | } |
| 247 | |
| 248 | virtual HybridCmdMgr* GetHybridCmdMgr() |
| 249 | { |
| 250 | return m_hybridCmdMgr; |
| 251 | } |
| 252 | |
| 253 | bool IsSubmitToHybridMgr() |
| 254 | { |
| 255 | return (m_hybridCmdMgr != nullptr); |
| 256 | } |
| 257 | |
| 258 | protected: |
| 259 | //! \brief Hardware node for current gpu context |
| 260 | MOS_GPU_NODE m_nodeOrdinal = {}; |
| 261 | |
| 262 | //! \brief Indirect heap size (SSH area in DMA buffer) |
| 263 | uint32_t m_IndirectHeapSize = 0; |
| 264 | |
| 265 | //! \brief Related command buffer manager |
| 266 | CmdBufMgrNext *m_cmdBufMgr = nullptr; |
| 267 | |
| 268 | //! \brief Related command buffer manager |
| 269 | uint64_t m_cmdBufMgrHandle = UINT64_MAX; |
| 270 | |
| 271 | //! \brief Index in gpucontextNext mgr pool for current gpu context |
| 272 | GPU_CONTEXT_HANDLE m_gpuContextHandle = 0; |
| 273 | |
| 274 | //! \brief Gpu status report buffer |
| 275 | MOS_RESOURCE_HANDLE m_statusBufferResource = nullptr; |
| 276 | |
| 277 | //! \brief Track the GPU Context Client Info |
| 278 | MOS_GPU_CONTEXT m_gpuContext = MOS_GPU_CONTEXT_INVALID_HANDLE; |
| 279 | |
| 280 | //! \brief VE attribute buffer |
| 281 | MOS_CMD_BUF_ATTRI_VE m_bufAttriVe = {}; |
| 282 | |
| 283 | HybridCmdMgr *m_hybridCmdMgr = nullptr; |
| 284 | |
| 285 | MEDIA_CLASS_DEFINE_END(GpuContextNext) |
| 286 | }; |
| 287 | #endif // #ifndef __MOS_GPU_CONTEXT_NEXT_H__ |