1 /* 2 * Copyright (c) 2018, 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.h 24 //! \brief Container class for the basic gpu context 25 //! 26 27 #ifndef __MOS_GPU_CONTEXT_H__ 28 #define __MOS_GPU_CONTEXT_H__ 29 30 #include "mos_os.h" 31 32 class CmdBufMgr; 33 class CommandBuffer; 34 class CommandBufferSpecific; 35 class GraphicsResource; 36 37 //! 38 //! \class GpuContext 39 //! 40 class GpuContext 41 { 42 public: 43 //! 44 //! \brief Constructor 45 //! GpuContext()46 GpuContext() 47 { 48 m_nodeOrdinal = MOS_GPU_NODE_MAX; 49 m_gpuContextHandle = 0; 50 m_gpuContext = MOS_GPU_CONTEXT_RENDER; 51 } 52 53 //! 54 //! \brief Destructor 55 //! ~GpuContext()56 virtual ~GpuContext(){} 57 58 //! 59 //! \brief Static entrypoint, get the gpu context object 60 //! \param [in] gpuNode 61 //! Gpu node 62 //! \param [in] mosGpuCtx 63 //! Mos gpu context 64 //! \param [in] cmdBufMgr 65 //! Command buffer manager 66 //! \param [in] reusedContext 67 //! Reused gpu context 68 //! \return GpuContext* 69 //! the os specific object for gpu context 70 //! 71 static class GpuContext* Create( 72 const MOS_GPU_NODE gpuNode, 73 MOS_GPU_CONTEXT mosGpuCtx, 74 CmdBufMgr *cmdBufMgr, 75 GpuContext *reusedContext); 76 77 //! 78 //! \brief Clear gpu context 79 //! 80 virtual void Clear() = 0; 81 82 //! 83 //! \brief Verify command buffer size 84 //! \details Verifys the buffer to be used for rendering GPU commands is large enough 85 //! \param [in] requestedSize 86 //! Buffer size requested 87 //! \return MOS_STATUS 88 //! Return MOS_STATUS_SUCCESS if successful (command buffer will be large enough) 89 //! otherwise failed reason 90 //! 91 virtual MOS_STATUS VerifyCommandBufferSize( 92 const uint32_t requestedSize) = 0; 93 94 //! 95 //! \brief Get indirect state size 96 //! \details Retrieves indirect state to be used for rendering purposes 97 //! \param [out] offset 98 //! Pointer to indirect buffer offset 99 //! \param [out] size 100 //! Pointer to indirect buffer size 101 //! \return MOS_STATUS 102 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 103 //! 104 virtual MOS_STATUS GetIndirectState( 105 uint32_t *offset, 106 uint32_t *size) = 0; 107 108 //! 109 //! \brief Get Indirect State Pointer 110 //! \param [out] indirectState 111 //! Pointer to Indirect State Buffer 112 //! \return MOS_STATUS 113 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 114 //! 115 virtual MOS_STATUS GetIndirectStatePointer( 116 uint8_t **indirectState) = 0; 117 118 //! 119 //! \brief Get command buffer 120 //! \details Retrieves buffer to be used for rendering GPU commands 121 //! \param [in/out] cmdBuffer 122 //! Pointer to Command Buffer control structure 123 //! \param [in] flags 124 //! Flags to indicate command buffer property 125 //! \return MOS_STATUS 126 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 127 //! 128 virtual MOS_STATUS GetCommandBuffer( 129 PMOS_COMMAND_BUFFER cmdBuffer, 130 uint32_t flags) = 0; 131 132 //! 133 //! \brief Return command buffer space 134 //! \details Return unused command buffer space 135 //! \param [in/out] cmdBuffer 136 //! Pointer to Command Buffer control structure 137 //! \param [in] flags 138 //! Flags to indicate command buffer property 139 //! 140 virtual void ReturnCommandBuffer( 141 PMOS_COMMAND_BUFFER cmdBuffer, 142 uint32_t flags) = 0; 143 144 //! 145 //! \brief Submit command buffer 146 //! \details Submit the command buffer 147 //! \param [in] osInterface 148 //! Pointer to OS interface structure 149 //! \param [in] cmdBuffer 150 //! Pointer to Command Buffer control structure 151 //! \param [in] nullRendering 152 //! boolean null rendering 153 //! \return MOS_STATUS 154 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 155 //! 156 virtual MOS_STATUS SubmitCommandBuffer( 157 PMOS_INTERFACE osInterface, 158 PMOS_COMMAND_BUFFER cmdBuffer, 159 bool nullRendering) = 0; 160 161 //! 162 //! \brief Resizes the buffer to be used for rendering GPU commands 163 //! \param [in] requestedCommandBufferSize 164 //! requested command buffer size 165 //! \param [in] requestedPatchListSize 166 //! requested patch list size 167 //! \param [in] flags 168 //! Flags to indicate command buffer property 169 //! \return MOS_STATUS 170 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 171 //! 172 virtual MOS_STATUS ResizeCommandBufferAndPatchList( 173 uint32_t requestedCommandBufferSize, 174 uint32_t requestedPatchListSize, 175 uint32_t flags) = 0; 176 177 //! 178 //! \brief Resets Gpu context States 179 //! \details Resets all status in current gpu status 180 //! 181 virtual void ResetGpuContextStatus() = 0; 182 183 //! 184 //! \brief Get Gpu context handle 185 //! \details return the index in gpucontext mgr pool for current gpu context 186 //! GetGpuContextHandle()187 GPU_CONTEXT_HANDLE GetGpuContextHandle() { return m_gpuContextHandle; } 188 189 //! 190 //! \brief Set Gpu context handle 191 //! \details Register the index in gpucontext mgr pool for current gpu context 192 //! SetGpuContextHandle(GPU_CONTEXT_HANDLE gpuContextHandle)193 void SetGpuContextHandle(GPU_CONTEXT_HANDLE gpuContextHandle) 194 { 195 m_gpuContextHandle = gpuContextHandle; 196 } 197 198 //! 199 //! \brief Get Gpu context Node 200 //! \details Return the hardware node for current gpu context 201 //! GetContextNode()202 MOS_GPU_NODE GetContextNode() { return m_nodeOrdinal; } 203 204 //! 205 //! \brief Set Gpu context Node 206 //! \details Set the hardware node for current gpu context 207 //! SetContextNode(MOS_GPU_NODE nodeOrdinal)208 void SetContextNode(MOS_GPU_NODE nodeOrdinal) { m_nodeOrdinal = nodeOrdinal; } 209 210 //! 211 //! \brief Get Gpu context ID 212 //! \details Return the umd side gpu context id for current gpu context 213 //! GetCpuContextID()214 MOS_GPU_CONTEXT GetCpuContextID() { return m_gpuContext; } 215 216 //! 217 //! \brief Get indirect state size 218 //! GetIndirectStateSize()219 uint32_t GetIndirectStateSize() { return m_IndirectHeapSize; } 220 221 //! 222 //! \brief Set indirect state size 223 //! 224 virtual MOS_STATUS SetIndirectStateSize(const uint32_t size) = 0; 225 226 //! 227 //! \brief Get status buffer resource for current gpu context 228 //! \return GraphicsResource* 229 //! GetStatusBufferResource()230 GraphicsResource* GetStatusBufferResource() { return m_statusBufferResource; } 231 232 //! 233 //! \brief Get status buffer mos resource for current gpu context 234 //! \return GraphicsResource* 235 //! GetStatusBufferMosResource()236 MOS_RESOURCE_HANDLE GetStatusBufferMosResource() { return m_statusBufferMosResource; } 237 238 protected: 239 //! \brief Hardware node for current gpu context 240 MOS_GPU_NODE m_nodeOrdinal; 241 242 //! \brief Indirect heap size (SSH area in DMA buffer) 243 uint32_t m_IndirectHeapSize = 0; 244 245 //! \brief Related command buffer manager 246 CmdBufMgr *m_cmdBufMgr = nullptr; 247 248 //! \brief Index in gpucontext mgr pool for current gpu context 249 GPU_CONTEXT_HANDLE m_gpuContextHandle; 250 251 //! \brief Gpu status report buffer 252 GraphicsResource *m_statusBufferResource = nullptr; 253 //! \brief GPU status mos resource 254 MOS_RESOURCE_HANDLE m_statusBufferMosResource = nullptr; 255 256 //! \brief Track the GPU Context Client Info 257 MOS_GPU_CONTEXT m_gpuContext; 258 }; 259 #endif // #ifndef __MOS_GPU_CONTEXT_H__ 260