Debian Codegraph @

media_softlet/agnostic/common/shared/mediacontext/media_context.h

raw
1 /*
2 * Copyright (c) 2018-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 //!
24 //! \file media_context.h
25 //! \brief Defines the common interface for media context
26 //! \details The media context interface is further sub-divided by component,
27 //! this file is for the base interface which is shared by all components.
28 //!
29
30 #ifndef __MEDIA_CONTEXT_H__
31 #define __MEDIA_CONTEXT_H__
32
33 #include "mos_os.h"
34 #include "media_scalability_factory.h"
35
36 struct _MHW_VDBOX_GPUNODE_LIMIT;
37 typedef struct _MHW_VDBOX_GPUNODE_LIMIT MHW_VDBOX_GPUNODE_LIMIT, *PMHW_VDBOX_GPUNODE_LIMIT;
38
39 enum MediaFunction
40 {
41 RenderGenericFunc,
42 VdboxDecodeFunc,
43 VdboxEncodeFunc,
44 VdboxCpFunc,
45 VeboxVppFunc,
46 ComputeMdfFunc,
47 ComputeVppFunc,
48 VdboxDecodeWaFunc,
49 VdboxDecrpytFunc,
50 VdboxDecodeVirtualNode0Func,
51 VdboxDecodeVirtualNode1Func,
52 MediaFuncMax
53 };
54 // Be compatible to legacy MOS and re-define the name
55 #define INVALID_MEDIA_FUNCTION MediaFuncMax
56 #define IS_RENDER_ENGINE_FUNCTION(func) ( func == RenderGenericFunc || func == ComputeMdfFunc || func == ComputeVppFunc )
57
58 struct GpuContextAttribute
59 {
60 MediaFunction func = INVALID_MEDIA_FUNCTION;
61 MediaScalability * scalabilityState = nullptr;
62
63 MOS_GPU_CONTEXT ctxForLegacyMos = MOS_GPU_CONTEXT_MAX;
64 GPU_CONTEXT_HANDLE gpuContext = MOS_GPU_CONTEXT_INVALID_HANDLE;
65 };
66
67 class MediaContext
68 {
69 public:
70 //!
71 //! \brief Media context constructor
72 //!
73 MediaContext(uint8_t componentType, void *hwInterface, PMOS_INTERFACE osInterface);
74
75 //!
76 //! \brief Media context destructor
77 //!
78 virtual ~MediaContext();
79
80 //!
81 //! \brief Interface to pipeline to switch media context and get corresponding scalabilityState for programming
82 //! \param [in] func
83 //! Indicate the media function of the context to switch
84 //! \param [in] requirement
85 //! Pointer to the context requirement
86 //! \param [out] scalabilityState
87 //! Pointer to the pointer of output scalability state.
88 //! Pipeline can only use this scalabilityState until next time calling SwitchContext
89 //! \return MOS_STATUS
90 //! MOS_STATUS_SUCCESS if success, else fail reason
91 //!
92 MOS_STATUS SwitchContext(MediaFunction func, ContextRequirement *requirement, MediaScalability **scalabilityState, uint64_t gpuCtxOnHybridCmd = 0);
93
94 //!
95 //! \brief Interface to pipeline to switch media context and get corresponding scalabilityState for programming
96 //! \param [in] func
97 //! Indicate the media function of the context to switch
98 //! \param [in] scalabilityOption
99 //! The intialzed scalability option
100 //! \param [out] scalabilityState
101 //! Pointer to the pointer of output scalability state.
102 //! Pipeline can only use this scalabilityState until next time calling SwitchContext
103 //! \param [in] isEnc
104 //! Indicate if this is Enc stage
105 //! \param [in] isPak
106 //! Indicate if this is Pak stage
107 //! \return MOS_STATUS
108 //! MOS_STATUS_SUCCESS if success, else fail reason
109 //!
110 MOS_STATUS SwitchContext(MediaFunction func, MediaScalabilityOption &scalabilityOption, MediaScalability **scalabilityState, bool isEnc = false, bool isPak = false);
111
112 //!
113 //! \brief Check if in current media context render engine is used
114 //! \return bool
115 //! True if render engine used, else false.
116 //!
117 bool IsRenderEngineUsed()
118 {
119 auto gpuContext = m_osInterface->pfnGetGpuContext(m_osInterface);
120 // Be compatiable to legacy MOS
121 return MOS_RCS_ENGINE_USED(gpuContext);
122 }
123
124 uint8_t GetNumVdbox()
125 {
126 return m_numVdbox;
127 }
128
129 //!
130 //! \brief Set latest decoder virtual node
131 //!
132 void SetLatestDecoderVirtualNode();
133
134 //!
135 //! \brief Reassgine virtual node for decoder
136 //! \param [in] frameNum
137 //! The current decoding frame number
138 //! \param [in] scalabilityOption
139 //! The intialzed scalability option
140 //! \param [out] scalabilityState
141 //! Pointer to the pointer of output scalability state.
142 //! Pipeline can only use this scalabilityState until next time calling SwitchContext
143 //! \return MOS_STATUS
144 //! MOS_STATUS_SUCCESS if success, else fail reason
145 //!
146 MOS_STATUS ReassignContextForDecoder(uint32_t frameNum, MediaScalabilityOption &scalabilityOption, MediaScalability **scalabilityState);
147
148 //!
149 //! \brief Reassgine virtual node for decoder
150 //! \param [in] frameNum
151 //! The current decoding frame number
152 //! \param [in] scalabilityOption
153 //! The intialzed scalability option
154 //! \param [out] scalabilityState
155 //! Pointer to the pointer of output scalability state.
156 //! Pipeline can only use this scalabilityState until next time calling SwitchContext
157 //! \return MOS_STATUS
158 //! MOS_STATUS_SUCCESS if success, else fail reason
159 //!
160 MOS_STATUS ReassignContextForDecoder(uint32_t frameNum, ContextRequirement *requirement, MediaScalability **scalabilityState);
161
162 protected:
163 PMOS_INTERFACE m_osInterface = nullptr; //!< OS interface
164 void *m_hwInterface = nullptr; //!< HW interface
165 uint8_t m_componentType = scalabilityTotal; //!< Media component
166 uint32_t m_streamId = m_invalidStreamId; //!< Stream id of this media context
167
168 std::vector<GpuContextAttribute> m_gpuContextAttributeTable; //!< Gpu Context Attribute Table to store the contexts to reuse
169
170 static const uint32_t m_invalidContextAttribute = 0xffffffdf; //!< Index value to indicate invalid Context Attribute
171 static const uint32_t m_invalidStreamId = 0xffffffcb; //!< Id to indicate invalid Stream
172 static const uint32_t m_maxContextAttribute = 4096; //!< Max number of entries supported in gpuContextAttributeTable in one media context
173 uint8_t m_numVdbox = 1;
174 bool m_scalabilitySupported = false;
175 MOS_GPU_NODE m_curNodeOrdinal = MOS_GPU_NODE_MAX; //!< Current virtual node for codec gpu context
176 MediaUserSettingSharedPtr m_userSettingPtr = nullptr; //!< Shared pointer to user setting instance
177
178 //!
179 //! \brief Search the ContextAttributeTable to reuse or create gpu Context and scalabilty state meeting the requirements
180 //! \param [in] func
181 //! Indicate the media function of the context
182 //! \param [in] params
183 //! The params for context searching
184 //! \param [out] indexFound
185 //! The index of the ContextAttributeTable which is found to match the requirements
186 //! \return MOS_STATUS
187 //! MOS_STATUS_SUCCESS if success, else fail reason
188 //!
189 template<typename T>
190 MOS_STATUS SearchContext(MediaFunction func, T params, uint32_t& indexFound);
191
192 //!
193 //! \brief Creat the context for new requirement
194 //! \param [in] func
195 //! Indicate the media function of the context
196 //! \param [in] params
197 //! Pointer to the context requirement
198 //! \param [out] indexReturn
199 //! Return index for new ContextAttributeTable
200 //! \return MOS_STATUS
201 //! MOS_STATUS_SUCCESS if success, else fail reason
202 //!
203 template<typename T>
204 MOS_STATUS CreateContext(MediaFunction func, T params, uint32_t& indexReturn);
205
206 //!
207 //! \brief Get the GPU node of the Media Function
208 //! \detail Usually there is a corresponding GPU node to implement the specific media function
209 //! \param [in] func
210 //! Media function to get GPU node
211 //! \param [in] option
212 //! Media GPU create option
213 //! \param [out] node
214 //! GPU node of the media function
215 //! \return MOS_STATUS
216 //! MOS_STATUS_SUCCESS if success, else fail reason
217 //!
218 MOS_STATUS FunctionToNode(MediaFunction func, const MOS_GPUCTX_CREATOPTIONS_ENHANCED &option, MOS_GPU_NODE& node);
219 MOS_STATUS FunctionToNodeCodec(MediaFunction func, MOS_GPU_NODE &node);
220 MOS_STATUS FindGpuNodeToUse(MediaFunction func, PMHW_VDBOX_GPUNODE_LIMIT gpuNodeLimit);
221
222 // Be compatible to Legacy MOS
223 MOS_STATUS FunctionToGpuContext(MediaFunction func, const MOS_GPUCTX_CREATOPTIONS_ENHANCED &option, const MOS_GPU_NODE &node, MOS_GPU_CONTEXT &ctx);
224 MOS_STATUS FunctionToGpuContextDecode(const MOS_GPUCTX_CREATOPTIONS_ENHANCED &option, const MOS_GPU_NODE &node, MOS_GPU_CONTEXT &ctx);
225 MOS_STATUS FunctionToGpuContextEncode(const MOS_GPUCTX_CREATOPTIONS_ENHANCED &option, MOS_GPU_CONTEXT &ctx);
226
227 #if (_DEBUG || _RELEASE_INTERNAL)
228 MOS_STATUS CheckScalabilityOverrideValidity();
229 #endif
230
231 MEDIA_CLASS_DEFINE_END(MediaContext)
232 };
233 #endif // !__MEDIA_CONTEXT_H__