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_commandbuffer_next.h 24 //! \brief Container for comamnd buffer 25 //! 26 27 #ifndef __MOS_COMMANDBUFFER_NEXT_H__ 28 #define __MOS_COMMANDBUFFER_NEXT_H__ 29 30 #include "mos_graphicsresource_next.h" 31 #include "mos_gpucontext_next.h" 32 33 //! 34 //! \class CommandBuffer 35 //! 36 class CommandBufferNext 37 { 38 public: 39 //! 40 //! \brief Constructor 41 //! CommandBufferNext(CmdBufMgrNext * cmdBufMgr)42 CommandBufferNext(CmdBufMgrNext *cmdBufMgr) 43 { 44 m_cmdBufMgr = cmdBufMgr; 45 } 46 47 //! 48 //! \brief Destructor 49 //! ~CommandBufferNext()50 virtual ~CommandBufferNext(){} 51 52 //! 53 //! \brief Create Os specific command buffer 54 //! \return CommandBufferNext* 55 //! Os specific command buffer 56 //! 57 static class CommandBufferNext *CreateCmdBuf(CmdBufMgrNext *cmdBufMgr); 58 59 //! 60 //! \brief Allocate graphics resource for current command buffer 61 //! \param [in] osContext 62 //! Related os context 63 //! \param [in] size 64 //! Required size 65 //! \return MOS_STATUS 66 //! MOS_STATUS_SUCCESS if success, otherwise fail reason 67 //! 68 virtual MOS_STATUS Allocate(OsContextNext* osContext, uint32_t size) = 0; 69 70 //! 71 //! \brief Free allocated graphics resource for current command buffer 72 //! 73 virtual void Free() = 0; 74 75 //! 76 //! \brief Bind current command buffer to gived gpu context 77 //! \param [in] gpuContext 78 //! Gpu context to be binded 79 //! \return MOS_STATUS 80 //! MOS_STATUS_SUCCESS if success, otherwise fail reason 81 //! 82 virtual MOS_STATUS BindToGpuContext(GpuContextNext* gpuContext) = 0; 83 84 //! 85 //! \brief Unbind current command buffer from gpu context 86 //! \param [in] isNative 87 //! Indicate it is unbinded from dummy or native gpu context in async mode 88 //! \return MOS_STATUS 89 //! MOS_STATUS_SUCCESS if success, otherwise fail reason 90 //! 91 virtual void UnBindToGpuContext(bool isNative = true) = 0; 92 93 //! 94 //! \brief Resize command buffer 95 //! \param [in] newSize 96 //! Required size 97 //! \return MOS_STATUS 98 //! MOS_STATUS_SUCCESS if success, otherwise fail reason 99 //! 100 virtual MOS_STATUS ReSize(uint32_t newSize) = 0; 101 102 //! 103 //! \brief Query command buffer if it is in HW execution 104 //! Always return false in normal mode, only return true in aync mode 105 //! when cmd buffer still in use by HW 106 //! \return bool 107 //! True if is used by HW, false if not 108 //! IsUsedByHw()109 virtual bool IsUsedByHw() { return false; } 110 111 //! 112 //! \brief Query command buffer if it is in Cmd List 113 //! Always return false in normal mode, only return true in aync mode 114 //! when cmd buffer still in one or multiple cmd Lists 115 //! \return bool 116 //! True if is in cmdlist, false if not 117 //! IsInCmdList()118 virtual bool IsInCmdList() { return false; } 119 120 //! 121 //! \brief Query command buffer ready to use 122 //! \return bool 123 //! True if ready, false if not ready 124 //! IsReadyToUse()125 bool IsReadyToUse() { return m_readyToUse; } 126 127 //! 128 //! \brief Get command buffer size 129 //! \return uint32_t 130 //! Command buffer size 131 //! GetCmdBufSize()132 uint32_t GetCmdBufSize() { return m_size; } 133 134 //! 135 //! \brief Get current command buffer attached resource 136 //! \return GraphicsResource* 137 //! Attached graphics resource 138 //! GetResource()139 GraphicsResourceNext* GetResource() { return m_graphicsResource; } 140 141 //! 142 //! \brief Get current command buffer's lock address for cpu side usage 143 //! \return uint8_t* 144 //! Current command buffer's lock address for cpu side usage 145 //! GetLockAddr()146 uint8_t* GetLockAddr() { return m_lockAddr; } 147 148 //! 149 //! \brief Get last native gpu context 150 //! \return GpuContextNext* 151 //! Pointer to the last native gpu context 152 //! GetLastNativeGpuContext()153 GpuContextNext *GetLastNativeGpuContext() 154 { 155 return m_lastNativeGpuContextHandle == MOS_GPU_CONTEXT_INVALID_HANDLE ? 156 nullptr : m_lastNativeGpuContext; 157 } 158 159 //! 160 //! \brief Get last native gpu context handle 161 //! \return GPU_CONTEXT_HANDLE 162 //! Pointer to the last native gpu context handle 163 //! GetLastNativeGpuContextHandle()164 GPU_CONTEXT_HANDLE GetLastNativeGpuContextHandle() 165 { 166 return m_lastNativeGpuContextHandle; 167 } 168 169 //! 170 //! \brief Reset last native gpu context 171 //! \return void 172 //! ResetLastNativeGpuContext()173 void ResetLastNativeGpuContext() 174 { 175 m_lastNativeGpuContextHandle = MOS_GPU_CONTEXT_INVALID_HANDLE; 176 m_lastNativeGpuContext = nullptr; 177 return; 178 } 179 180 //! 181 //! \brief Get last gpu context 182 //! \return GpuContextNext* 183 //! Pointer to the last gpu context 184 //! GetGpuContext()185 GpuContextNext *GetGpuContext() 186 { 187 return m_gpuContext; 188 } 189 190 //! 191 //! \brief Get last gpu context handle 192 //! \return GPU_CONTEXT_HANDLE 193 //! Pointer to the last gpu context handle 194 //! GetGpuContextHandle()195 GPU_CONTEXT_HANDLE GetGpuContextHandle() 196 { 197 return m_gpuContextHandle; 198 } 199 200 //! 201 //! \brief Reset gpu context 202 //! \return void 203 //! ResetGpuContext()204 void ResetGpuContext() 205 { 206 m_gpuContextHandle = MOS_GPU_CONTEXT_INVALID_HANDLE; 207 m_gpuContext = nullptr; 208 return; 209 } 210 211 //! 212 //! \brief Get cmd buffer manager current cmd buffer belong to 213 //! \return CmdBufMgrNext * 214 //! Pointer to the command buffer manager 215 //! GetCmdBufferMgr()216 CmdBufMgrNext *GetCmdBufferMgr() 217 { 218 return m_cmdBufMgr; 219 } 220 221 protected: 222 //! 223 //! \brief Set ready to use 224 //! \params [in] readyToUse 225 //! SetReadyToUse(bool readyToUse)226 void SetReadyToUse(bool readyToUse) { m_readyToUse = readyToUse; } 227 228 //! \brief Os context 229 OsContextNext* m_osContext = nullptr; 230 231 //! \brief Gpu context binded to 232 GpuContextNext* m_gpuContext = nullptr; 233 234 //! \brief Gpu context handle 235 GPU_CONTEXT_HANDLE m_gpuContextHandle = MOS_GPU_CONTEXT_INVALID_HANDLE; 236 237 //! \brief Last executed native Gpu context in async mode (Should not be used in normal mode) 238 GpuContextNext *m_lastNativeGpuContext = nullptr; 239 240 //! \brief the cmd buf manager it belongs to 241 CmdBufMgrNext *m_cmdBufMgr = nullptr; 242 243 //! \brief Last native Gpu context handle 244 GPU_CONTEXT_HANDLE m_lastNativeGpuContextHandle = MOS_GPU_CONTEXT_INVALID_HANDLE; 245 246 //! \brief Graphics resource for command buffer 247 GraphicsResourceNext* m_graphicsResource = nullptr; 248 249 //! \brief Lock address for cpu side usage 250 uint8_t* m_lockAddr = nullptr; 251 252 //! \brief Indicate if ready to use 253 bool m_readyToUse = false; 254 255 //! \brief Command buffer size 256 uint32_t m_size = 0; 257 MEDIA_CLASS_DEFINE_END(CommandBufferNext) 258 }; 259 #endif // __MOS_COMMANDBUFFERNext_NEXT_H__ 260