| 1 |
/* |
| 2 |
* Copyright (c) 2018-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 |
//! \file mos_gpucontext_specific.h |
| 24 |
//! \brief Container class for the linux/Android specfic gpu context |
| 25 |
//! |
| 26 |
|
| 27 |
#ifndef __GPU_CONTEXT_SPECIFIC_H__ |
| 28 |
#define __GPU_CONTEXT_SPECIFIC_H__ |
| 29 |
|
| 30 |
#include "mos_gpucontext.h" |
| 31 |
#include "mos_graphicsresource_specific.h" |
| 32 |
#include "mos_oca_interface_specific.h" |
| 33 |
|
| 34 |
#define ENGINE_INSTANCE_SELECT_ENABLE_MASK 0xFF |
| 35 |
#define ENGINE_INSTANCE_SELECT_COMPUTE_INSTANCE_SHIFT 16 |
| 36 |
#define ENGINE_INSTANCE_SELECT_VEBOX_INSTANCE_SHIFT 8 |
| 37 |
#define ENGINE_INSTANCE_SELECT_VDBOX_INSTANCE_SHIFT 0 |
| 38 |
|
| 39 |
//! |
| 40 |
//! \class GpuContextSpecific |
| 41 |
//! \brief Linux/Android specific gpu context |
| 42 |
//! |
| 43 |
class GpuContextSpecific : public GpuContext |
| 44 |
{ |
| 45 |
public: |
| 46 |
//! |
| 47 |
//! \brief Constructor |
| 48 |
//! |
| 49 |
GpuContextSpecific( |
| 50 |
const MOS_GPU_NODE gpuNode, |
| 51 |
MOS_GPU_CONTEXT mosGpuCtx, |
| 52 |
CmdBufMgr *cmdBufMgr, |
| 53 |
GpuContext *reusedContext); |
| 54 |
|
| 55 |
//! |
| 56 |
//! \brief Destructor |
| 57 |
//! |
| 58 |
~GpuContextSpecific(); |
| 59 |
|
| 60 |
//! |
| 61 |
//! \brief Initialize gpu context |
| 62 |
//! \details Linux specific initialize for gpu context |
| 63 |
//! \param [out] osContext |
| 64 |
//! Os context pointer |
| 65 |
//! \param [in] osInterface |
| 66 |
//! OS interface |
| 67 |
//! \param [in] GpuNode |
| 68 |
//! GPU node |
| 69 |
//! \param [in] createOption |
| 70 |
//! Context option |
| 71 |
//! \return MOS_STATUS |
| 72 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 73 |
//! |
| 74 |
MOS_STATUS Init(OsContext *osContext, |
| 75 |
PMOS_INTERFACE osInterface, |
| 76 |
MOS_GPU_NODE GpuNode, |
| 77 |
PMOS_GPUCTX_CREATOPTIONS createOption); |
| 78 |
|
| 79 |
void Clear(void); |
| 80 |
|
| 81 |
//! |
| 82 |
//! \brief Register graphics resource |
| 83 |
//! \details Set the Allocation Index in OS resource structure |
| 84 |
//! \param [out] osContext |
| 85 |
//! Os context pointer |
| 86 |
//! \param [in] writeFlag |
| 87 |
//! Write Flag |
| 88 |
//! \return MOS_STATUS |
| 89 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 90 |
//! |
| 91 |
MOS_STATUS RegisterResource( |
| 92 |
PMOS_RESOURCE osResource, |
| 93 |
bool writeFlag); |
| 94 |
|
| 95 |
MOS_STATUS GetCommandBuffer( |
| 96 |
PMOS_COMMAND_BUFFER comamndBuffer, |
| 97 |
uint32_t flags); |
| 98 |
|
| 99 |
MOS_STATUS VerifyCommandBufferSize(const uint32_t requestedSize) |
| 100 |
{ |
| 101 |
return (m_commandBufferSize < requestedSize) ? MOS_STATUS_UNKNOWN:MOS_STATUS_SUCCESS; |
| 102 |
} |
| 103 |
|
| 104 |
MOS_STATUS GetIndirectState( |
| 105 |
uint32_t *offset, |
| 106 |
uint32_t *size); |
| 107 |
|
| 108 |
MOS_STATUS GetIndirectStatePointer( |
| 109 |
uint8_t **indirectState); |
| 110 |
|
| 111 |
MOS_STATUS SetIndirectStateSize(const uint32_t size); |
| 112 |
|
| 113 |
//! |
| 114 |
//! \brief Set patch entry |
| 115 |
//! \details Sets the patch entry in patch list |
| 116 |
//! \param [in] osInterface |
| 117 |
//! Pointer to OS interface structure |
| 118 |
//! \param [in] params |
| 119 |
//! patch entry params |
| 120 |
//! \return MOS_STATUS |
| 121 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 122 |
//! |
| 123 |
MOS_STATUS SetPatchEntry( |
| 124 |
PMOS_INTERFACE osInterface, |
| 125 |
PMOS_PATCH_ENTRY_PARAMS params); |
| 126 |
|
| 127 |
void ReturnCommandBuffer( |
| 128 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 129 |
uint32_t flags); |
| 130 |
|
| 131 |
//! |
| 132 |
//! \brief reset command buffer space |
| 133 |
//! \details resets the command buffer space |
| 134 |
//! \return MOS_STATUS |
| 135 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 136 |
//! |
| 137 |
MOS_STATUS ResetCommandBuffer(); |
| 138 |
|
| 139 |
//! |
| 140 |
//! \brief Verifys the patch list to be used for rendering GPU commands is large enough |
| 141 |
//! \param [in] requestedSize |
| 142 |
//! Patch list size to be verified |
| 143 |
//! \return MOS_STATUS |
| 144 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 145 |
//! |
| 146 |
MOS_STATUS VerifyPatchListSize(const uint32_t requestedSize) |
| 147 |
{ |
| 148 |
return (requestedSize > m_maxPatchLocationsize) ? MOS_STATUS_UNKNOWN : MOS_STATUS_SUCCESS; |
| 149 |
} |
| 150 |
|
| 151 |
MOS_STATUS SubmitCommandBuffer( |
| 152 |
PMOS_INTERFACE osInterface, |
| 153 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 154 |
bool nullRendering); |
| 155 |
|
| 156 |
MOS_STATUS ResizeCommandBufferAndPatchList( |
| 157 |
uint32_t requestedCommandBufferSize, |
| 158 |
uint32_t requestedPatchListSize, |
| 159 |
uint32_t flags); |
| 160 |
|
| 161 |
//! |
| 162 |
//! \brief Resizes the buffer to be used for rendering GPU commands |
| 163 |
//! \param [in] requestedSize |
| 164 |
//! Requested size |
| 165 |
//! \return MOS_STATUS |
| 166 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 167 |
//! |
| 168 |
MOS_STATUS ResizeCommandBuffer(uint32_t requestedSize); |
| 169 |
|
| 170 |
//! |
| 171 |
//! \brief Get GPU status tag |
| 172 |
//! \details Gets the status tag |
| 173 |
//! \return uint32_t |
| 174 |
//! Returns the tag |
| 175 |
//! |
| 176 |
uint32_t GetGpuStatusTag() { return m_GPUStatusTag; } |
| 177 |
|
| 178 |
//! |
| 179 |
//! \brief Get i915 ctx |
| 180 |
//! \param [in] ctxNodeIndex |
| 181 |
//! ctx index in array |
| 182 |
//! \return MOS_LINUX_CONTEXT |
| 183 |
//! mos linux ctx in array of ctxNodeIndex |
| 184 |
//! |
| 185 |
MOS_LINUX_CONTEXT* GetI915Context(uint32_t ctxNodeIndex){return ctxNodeIndex < (MAX_ENGINE_INSTANCE_NUM+1) ? m_i915Context[ctxNodeIndex] : nullptr;} |
| 186 |
|
| 187 |
//! |
| 188 |
//! \brief Increment GPU status tag |
| 189 |
//! |
| 190 |
void IncrementGpuStatusTag(); |
| 191 |
|
| 192 |
void ResetGpuContextStatus(); |
| 193 |
|
| 194 |
//! |
| 195 |
//! \brief Allocate gpu status buffer for gpu sync |
| 196 |
//! \return MOS_STATUS |
| 197 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 198 |
//! |
| 199 |
MOS_STATUS AllocateGPUStatusBuf(); |
| 200 |
|
| 201 |
#if MOS_COMMAND_RESINFO_DUMP_SUPPORTED |
| 202 |
void PushCmdResPtr(const void *p) { m_cmdResPtrs.push_back(p); } |
| 203 |
void ClearCmdResPtrs() { m_cmdResPtrs.clear(); } |
| 204 |
const std::vector<const void *> &GetCmdResPtrs() const { return m_cmdResPtrs; } |
| 205 |
#endif // MOS_COMMAND_RESINFO_DUMP_SUPPORTED |
| 206 |
protected: |
| 207 |
//! |
| 208 |
//! \brief Map resources with aux plane to aux table |
| 209 |
//! \return MOS_STATUS |
| 210 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 211 |
//! |
| 212 |
MOS_STATUS MapResourcesToAuxTable(mos_linux_bo *cmd_bo); |
| 213 |
|
| 214 |
//! |
| 215 |
//! \brief Submit command buffer for single pipe in scalability mode |
| 216 |
//! \return int32_t |
| 217 |
//! Return 0 if successful, otherwise error code |
| 218 |
//! |
| 219 |
int32_t SubmitPipeCommands(MOS_COMMAND_BUFFER *cmdBuffer, |
| 220 |
MOS_LINUX_BO *cmdBo, |
| 221 |
PMOS_CONTEXT osContext, |
| 222 |
const std::vector<MOS_LINUX_BO *> &skipSyncBoList, |
| 223 |
uint32_t execFlag, |
| 224 |
int32_t dr4); |
| 225 |
|
| 226 |
//! |
| 227 |
//! \brief Combin cmd buffer for each pipe and use one submission in scalability mode |
| 228 |
//! \return int32_t |
| 229 |
//! Return 0 if successful, otherwise error code |
| 230 |
//! |
| 231 |
int32_t ParallelSubmitCommands(std::map<uint32_t, PMOS_COMMAND_BUFFER> secondaryCmdBufs, |
| 232 |
PMOS_CONTEXT osContext, |
| 233 |
uint32_t execFlag, |
| 234 |
int32_t dr4); |
| 235 |
|
| 236 |
//! |
| 237 |
//! \brief Set the flags of engin quering according to create options |
| 238 |
//! \return void |
| 239 |
//! |
| 240 |
void SetEngineQueryFlags( |
| 241 |
PMOS_GPUCTX_CREATOPTIONS option, |
| 242 |
__u64 &caps); |
| 243 |
|
| 244 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 245 |
bool SelectEngineInstanceByUser(struct i915_engine_class_instance *engineMap, |
| 246 |
uint32_t *engineNum, uint32_t userEngineInstance, MOS_GPU_NODE gpuNode); |
| 247 |
#endif |
| 248 |
void UnlockPendingOcaBuffers(PMOS_COMMAND_BUFFER cmdBuffer, PMOS_CONTEXT mosContext); |
| 249 |
|
| 250 |
private: |
| 251 |
//! \brief internal command buffer pool per gpu context |
| 252 |
std::vector<CommandBuffer *> m_cmdBufPool; |
| 253 |
|
| 254 |
//! \brief internal command buffer pool per gpu context |
| 255 |
PMOS_MUTEX m_cmdBufPoolMutex = nullptr; |
| 256 |
|
| 257 |
//! \brief next fetch index of m_cmdBufPool |
| 258 |
uint32_t m_nextFetchIndex = 0; |
| 259 |
|
| 260 |
//! \brief initialized comamnd buffer size |
| 261 |
uint32_t m_commandBufferSize = 0; |
| 262 |
|
| 263 |
//! \brief Flag to indicate current command buffer flused or not, if not |
| 264 |
//! re-use it |
| 265 |
volatile bool m_cmdBufFlushed = false; |
| 266 |
|
| 267 |
//! \brief internal back up for in-use command buffer |
| 268 |
PMOS_COMMAND_BUFFER m_commandBuffer = nullptr; |
| 269 |
|
| 270 |
//! \brief secondary command buffers for scalability |
| 271 |
std::map<uint32_t, PMOS_COMMAND_BUFFER> m_secondaryCmdBufs; |
| 272 |
|
| 273 |
//! \brief Allcoation List related struct |
| 274 |
ALLOCATION_LIST *m_allocationList = nullptr; |
| 275 |
uint32_t m_numAllocations = 0; //!< number of registered allocation list |
| 276 |
uint32_t m_maxNumAllocations = 0; //!< max number of allocation list |
| 277 |
|
| 278 |
//! \brief Pathc List related struct |
| 279 |
PATCHLOCATIONLIST *m_patchLocationList = nullptr; |
| 280 |
uint32_t m_currentNumPatchLocations = 0; //!< number of registered patch list |
| 281 |
uint32_t m_maxPatchLocationsize; //!< max number of patch list |
| 282 |
|
| 283 |
//! \brief Resource registrations |
| 284 |
uint32_t m_resCount = 0; //!< number of resources registered |
| 285 |
PMOS_RESOURCE m_attachedResources = nullptr; //!< Pointer to resources list |
| 286 |
bool *m_writeModeList = nullptr; //!< Write mode |
| 287 |
|
| 288 |
//! \brief GPU Status tag |
| 289 |
uint32_t m_GPUStatusTag = 0; |
| 290 |
|
| 291 |
//! \brief Os context |
| 292 |
OsContext *m_osContext = nullptr; |
| 293 |
|
| 294 |
MOS_GPUCTX_CREATOPTIONS_ENHANCED *m_createOptionEnhanced = nullptr; |
| 295 |
MOS_LINUX_CONTEXT* m_i915Context[MAX_ENGINE_INSTANCE_NUM+1] = {}; |
| 296 |
uint32_t m_i915ExecFlag = 0; |
| 297 |
|
| 298 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 299 |
/*!\brief bits(23...16), (15...8), (7...0) are for Compute, VEbox and VDbox ; |
| 300 |
single or multi engine instance can be selected at same time(0x10103 to select Compute1, VE1, VD1&VD2 for example)*/ |
| 301 |
uint32_t m_engineInstanceSelect = 0x0; |
| 302 |
#endif |
| 303 |
|
| 304 |
#if MOS_COMMAND_RESINFO_DUMP_SUPPORTED |
| 305 |
std::vector<const void *> m_cmdResPtrs; //!< Command OS resource pointers registered by pfnRegisterResource |
| 306 |
#endif // MOS_COMMAND_RESINFO_DUMP_SUPPORTED |
| 307 |
}; |
| 308 |
#endif // __GPU_CONTEXT_SPECIFIC_H__ |