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_commandbuffer.h 24 //! \brief Container for comamnd buffer 25 //! 26 27 #ifndef __MOS_COMMANDBUFFER_H__ 28 #define __MOS_COMMANDBUFFER_H__ 29 30 #include "mos_graphicsresource.h" 31 #include "mos_gpucontext.h" 32 33 //! 34 //! \class CommandBuffer 35 //! 36 class CommandBuffer 37 { 38 public: 39 //! 40 //! \brief Constructor 41 //! CommandBuffer()42 CommandBuffer(){} 43 44 //! 45 //! \brief Destructor 46 //! ~CommandBuffer()47 virtual ~CommandBuffer(){} 48 49 //! 50 //! \brief Create Os specific command buffer 51 //! \return CommandBuffer* 52 //! Os specific command buffer 53 //! 54 static class CommandBuffer* CreateCmdBuf(); 55 56 //! 57 //! \brief Destroy Os specific command buffer 58 //! \return CommandBuffer* 59 //! Os specific command buffer 60 //! 61 static void DestroyCmdBuf(CommandBuffer *&cmdBuf); 62 63 //! 64 //! \brief Allocate graphics resource for current command buffer 65 //! \param [in] osContext 66 //! Related os context 67 //! \param [in] size 68 //! Required size 69 //! \return MOS_STATUS 70 //! MOS_STATUS_SUCCESS if success, otherwise fail reason 71 //! 72 virtual MOS_STATUS Allocate(OsContext* osContext, uint32_t size) = 0; 73 74 //! 75 //! \brief Free allocated graphics resource for current command buffer 76 //! 77 virtual void Free() = 0; 78 79 //! 80 //! \brief Bind current command buffer to gived gpu context 81 //! \param [in] gpuContext 82 //! Gpu context to be binded 83 //! \return MOS_STATUS 84 //! MOS_STATUS_SUCCESS if success, otherwise fail reason 85 //! 86 virtual MOS_STATUS BindToGpuContext(GpuContext* gpuContext) = 0; 87 88 //! 89 //! \brief Unbind current command buffer from gpu context 90 //! \return MOS_STATUS 91 //! MOS_STATUS_SUCCESS if success, otherwise fail reason 92 //! 93 virtual void UnBindToGpuContext() = 0; 94 95 //! 96 //! \brief Resize command buffer 97 //! \param [in] newSize 98 //! Required size 99 //! \return MOS_STATUS 100 //! MOS_STATUS_SUCCESS if success, otherwise fail reason 101 //! 102 virtual MOS_STATUS ReSize(uint32_t newSize) = 0; 103 104 //! 105 //! \brief Query command buffer ready to use 106 //! \return bool 107 //! True if ready, false if not ready 108 //! IsReadyToUse()109 bool IsReadyToUse() { return m_readyToUse; } 110 111 //! 112 //! \brief Get command buffer size 113 //! \return uint32_t 114 //! Command buffer size 115 //! GetCmdBufSize()116 uint32_t GetCmdBufSize() { return m_size; } 117 118 //! 119 //! \brief Get current command buffer attached resource 120 //! \return GraphicsResource* 121 //! Attached graphics resource 122 //! GetResource()123 GraphicsResource* GetResource() { return m_graphicsResource; } 124 125 //! 126 //! \brief Get current command buffer's lock address for cpu side usage 127 //! \return uint8_t* 128 //! Current command buffer's lock address for cpu side usage 129 //! GetLockAddr()130 uint8_t* GetLockAddr() { return m_lockAddr; } 131 132 protected: 133 //! 134 //! \brief Set ready to use 135 //! \params [in] readyToUse 136 //! SetReadyToUse(bool readyToUse)137 void SetReadyToUse(bool readyToUse) { m_readyToUse = readyToUse; } 138 139 //! \brief Os context 140 OsContext* m_osContext = nullptr; 141 142 //! \brief Gpu context binded to 143 GpuContext* m_gpuContext = nullptr; 144 145 //! \brief Graphics resource for command buffer 146 GraphicsResource* m_graphicsResource = nullptr; 147 148 //! \brief Lock address for cpu side usage 149 uint8_t* m_lockAddr = nullptr; 150 151 //! \brief Indicate if ready to use 152 bool m_readyToUse = false; 153 154 //! \brief Command buffer size 155 uint32_t m_size = 0; 156 }; 157 #endif // __MOS_COMMANDBUFFER_H__ 158