| 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 |
//! |
| 42 |
CommandBufferNext(CmdBufMgrNext *cmdBufMgr) |
| 43 |
{ |
| 44 |
m_cmdBufMgr = cmdBufMgr; |
| 45 |
} |
| 46 |
|
| 47 |
//! |
| 48 |
//! \brief Destructor |
| 49 |
//! |
| 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 |
//! |
| 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 |
//! |
| 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 |
//! |
| 125 |
bool IsReadyToUse() { return m_readyToUse; } |
| 126 |
|
| 127 |
//! |
| 128 |
//! \brief Get command buffer size |
| 129 |
//! \return uint32_t |
| 130 |
//! Command buffer size |
| 131 |
//! |
| 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 |
//! |
| 139 |
GraphicsResourceNext* GetResource() { return m_graphicsResource; } |
| 140 |
|
| 141 |
//! |
| 142 |
//! \brief Get last native gpu context |
| 143 |
//! \return GpuContextNext* |
| 144 |
//! Pointer to the last native gpu context |
| 145 |
//! |
| 146 |
GpuContextNext *GetLastNativeGpuContext() |
| 147 |
{ |
| 148 |
return m_lastNativeGpuContextHandle == MOS_GPU_CONTEXT_INVALID_HANDLE ? |
| 149 |
nullptr : m_lastNativeGpuContext; |
| 150 |
} |
| 151 |
|
| 152 |
//! |
| 153 |
//! \brief Get last native gpu context handle |
| 154 |
//! \return GPU_CONTEXT_HANDLE |
| 155 |
//! Pointer to the last native gpu context handle |
| 156 |
//! |
| 157 |
GPU_CONTEXT_HANDLE GetLastNativeGpuContextHandle() |
| 158 |
{ |
| 159 |
return m_lastNativeGpuContextHandle; |
| 160 |
} |
| 161 |
|
| 162 |
//! |
| 163 |
//! \brief Reset last native gpu context |
| 164 |
//! \return void |
| 165 |
//! |
| 166 |
void ResetLastNativeGpuContext() |
| 167 |
{ |
| 168 |
m_lastNativeGpuContextHandle = MOS_GPU_CONTEXT_INVALID_HANDLE; |
| 169 |
m_lastNativeGpuContext = nullptr; |
| 170 |
return; |
| 171 |
} |
| 172 |
|
| 173 |
//! |
| 174 |
//! \brief Get last gpu context |
| 175 |
//! \return GpuContextNext* |
| 176 |
//! Pointer to the last gpu context |
| 177 |
//! |
| 178 |
GpuContextNext *GetGpuContext() |
| 179 |
{ |
| 180 |
return m_gpuContext; |
| 181 |
} |
| 182 |
|
| 183 |
//! |
| 184 |
//! \brief Get last gpu context handle |
| 185 |
//! \return GPU_CONTEXT_HANDLE |
| 186 |
//! Pointer to the last gpu context handle |
| 187 |
//! |
| 188 |
GPU_CONTEXT_HANDLE GetGpuContextHandle() |
| 189 |
{ |
| 190 |
return m_gpuContextHandle; |
| 191 |
} |
| 192 |
|
| 193 |
//! |
| 194 |
//! \brief Reset gpu context |
| 195 |
//! \return void |
| 196 |
//! |
| 197 |
void ResetGpuContext() |
| 198 |
{ |
| 199 |
m_gpuContextHandle = MOS_GPU_CONTEXT_INVALID_HANDLE; |
| 200 |
m_gpuContext = nullptr; |
| 201 |
return; |
| 202 |
} |
| 203 |
|
| 204 |
//! |
| 205 |
//! \brief Get cmd buffer manager current cmd buffer belong to |
| 206 |
//! \return CmdBufMgrNext * |
| 207 |
//! Pointer to the command buffer manager |
| 208 |
//! |
| 209 |
CmdBufMgrNext *GetCmdBufferMgr() |
| 210 |
{ |
| 211 |
return m_cmdBufMgr; |
| 212 |
} |
| 213 |
|
| 214 |
protected: |
| 215 |
//! |
| 216 |
//! \brief Set ready to use |
| 217 |
//! \params [in] readyToUse |
| 218 |
//! |
| 219 |
void SetReadyToUse(bool readyToUse) { m_readyToUse = readyToUse; } |
| 220 |
|
| 221 |
//! \brief Os context |
| 222 |
OsContextNext* m_osContext = nullptr; |
| 223 |
|
| 224 |
//! \brief Gpu context binded to |
| 225 |
GpuContextNext* m_gpuContext = nullptr; |
| 226 |
|
| 227 |
//! \brief Gpu context handle |
| 228 |
GPU_CONTEXT_HANDLE m_gpuContextHandle = MOS_GPU_CONTEXT_INVALID_HANDLE; |
| 229 |
|
| 230 |
//! \brief Last executed native Gpu context in async mode (Should not be used in normal mode) |
| 231 |
GpuContextNext *m_lastNativeGpuContext = nullptr; |
| 232 |
|
| 233 |
//! \brief the cmd buf manager it belongs to |
| 234 |
CmdBufMgrNext *m_cmdBufMgr = nullptr; |
| 235 |
|
| 236 |
//! \brief Last native Gpu context handle |
| 237 |
GPU_CONTEXT_HANDLE m_lastNativeGpuContextHandle = MOS_GPU_CONTEXT_INVALID_HANDLE; |
| 238 |
|
| 239 |
//! \brief Graphics resource for command buffer |
| 240 |
GraphicsResourceNext* m_graphicsResource = nullptr; |
| 241 |
|
| 242 |
//! \brief Indicate if ready to use |
| 243 |
bool m_readyToUse = false; |
| 244 |
|
| 245 |
//! \brief Command buffer size |
| 246 |
uint32_t m_size = 0; |
| 247 |
MEDIA_CLASS_DEFINE_END(CommandBufferNext) |
| 248 |
}; |
| 249 |
#endif // __MOS_COMMANDBUFFERNext_NEXT_H__ |