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 //!
24 //! \file     encode_scalability_multipipe.h
25 //! \brief    Defines the common interface for media scalability mulitpipe mode.
26 //! \details  The media scalability mulitpipe 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 __ENCODE_SCALABILITY_MULTIPIPE_H__
31 #define __ENCODE_SCALABILITY_MULTIPIPE_H__
32 #include "mos_defs.h"
33 #include "mos_os.h"
34 #include "codec_hw_next.h"
35 #include "media_scalability_multipipe.h"
36 #include "encode_scalability_option.h"
37 #include "mos_os_virtualengine_scalability_next.h"
38 
39 namespace encode
40 {
41 class EncodeScalabilityMultiPipe : public MediaScalabilityMultiPipe
42 {
43 public:
44     //!
45     //! \brief  Encode scalability mulitipipe constructor
46     //! \param  [in] hwInterface
47     //!         Pointer to HwInterface
48     //! \param  [in] componentType
49     //!         Component type
50     //!
51     EncodeScalabilityMultiPipe(void *hwInterface, MediaContext *mediaContext, uint8_t componentType);
52 
53     //!
54     //! \brief  Encode scalability mulitipipe destructor
55     //!
56     ~EncodeScalabilityMultiPipe();
57 
58     //!
59     //! \brief    Copy constructor
60     //!
61     EncodeScalabilityMultiPipe(const EncodeScalabilityMultiPipe &) = delete;
62 
63     //!
64     //! \brief    Copy assignment operator
65     //!
66     EncodeScalabilityMultiPipe &operator=(const EncodeScalabilityMultiPipe &) = delete;
67 
68     //!
69     //! \brief   Initialize the media scalability
70     //! \details It will prepare the resources needed in scalability
71     //!          and initialize the state of scalability
72     //! \param   [in] option
73     //!          Input scalability option
74     //! \return  MOS_STATUS
75     //!          MOS_STATUS_SUCCESS if success, else fail reason
76     //!
77     MOS_STATUS Initialize(const MediaScalabilityOption &option) override;
78 
79     //!
80     //! \brief  Construct parameters for GPU context create.
81     //! \param   [in, out] gpuCtxCreateOption
82     //!          Pointer to the GPU Context Create Option
83     //! \return  MOS_STATUS
84     //!          MOS_STATUS_SUCCESS if success, else fail reason
85     //!
86     MOS_STATUS GetGpuCtxCreationOption(MOS_GPUCTX_CREATOPTIONS *gpuCtxCreateOption) override;
87 
88     //!
89     //! \brief  Destroy the media scalability
90     //! \return MOS_STATUS
91     //!         MOS_STATUS_SUCCESS if success, else fail reason
92     //!
93     virtual MOS_STATUS Destroy() override;
94 
95     //!
96     //! \brief  Update the media scalability state
97     //! \param  [in] statePars
98     //!         parameters to update the state
99     //! \return MOS_STATUS
100     //!         MOS_STATUS_SUCCESS if success, else fail reason
101     //!
102     MOS_STATUS UpdateState(void *statePars) override;
103 
104     //!
105     //! \brief  Verify command buffer
106     //! \param  [in] requestedSize
107     //!         requested size for command buffer
108     //! \param  [in] requestedPatchListSize
109     //!         requested size for patched list
110     //! \param  [out] singleTaskPhaseSupportedInPak
111     //!         Inidcate if to use single task phase in pak.
112     //! \return MOS_STATUS
113     //!         MOS_STATUS_SUCCESS if success, else fail reason
114     //!
115     MOS_STATUS VerifyCmdBuffer(uint32_t requestedSize, uint32_t requestedPatchListSize, bool &singleTaskPhaseSupportedInPak) override;
116 
117     //!
118     //! \brief  Get command buffer
119     //! \param  [in, out] cmdBuffer
120     //!         Pointer to command buffer
121     //! \return MOS_STATUS
122     //!         MOS_STATUS_SUCCESS if success, else fail reason
123     //!
124     MOS_STATUS GetCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer, bool frameTrackingRequested = true) override;
125 
126     //!
127     //! \brief  Return command buffer
128     //! \param  [in, out] cmdBuffer
129     //!         Pointer to command buffer
130     //! \return MOS_STATUS
131     //!         MOS_STATUS_SUCCESS if success, else fail reason
132     //!
133     MOS_STATUS ReturnCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer) override;
134 
135     //!
136     //! \brief  Submit command buffer
137     //! \param  [in, out] cmdBuffer
138     //!         Pointer to command buffer
139     //! \return MOS_STATUS
140     //!         MOS_STATUS_SUCCESS if success, else fail reason
141     //!
142     MOS_STATUS SubmitCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer) override;
143 
144     //!
145     //! \brief  Add synchronization for pipes.
146     //! \param  [in] syncType
147     //!         type of pipe sync
148     //! \param  [in] semaphoreId
149     //!         Id of the semaphore used for this sync
150     //! \param  [in, out] cmdBuffer
151     //!         Pointer to command buffer
152     //! \return MOS_STATUS
153     //!         MOS_STATUS_SUCCESS if success, else fail reason
154     //!
155     MOS_STATUS SyncPipe(uint32_t syncType, uint32_t semaphoreId, PMOS_COMMAND_BUFFER cmdBuffer) override;
156 
157     //!
158     //! \brief  Reset semaphore
159     //! \param  [in] syncType
160     //!         type of pipe sync to find the related semaphore
161     //! \param  [in] semaphoreId
162     //!         Id of the semaphore for reset
163     //! \param  [in, out] cmdBuffer
164     //! \return MOS_STATUS
165     //!         MOS_STATUS_SUCCESS if success, else fail reason
166     //!
167     MOS_STATUS ResetSemaphore(uint32_t syncType, uint32_t semaphoreId, PMOS_COMMAND_BUFFER cmdBuffer) override;
168 
169     //!
170     //! \brief  Oca 1st Level BB Start
171     //! \param  [in, out] cmdBuffer
172     //!         Reference to command buffer
173     //! \return MOS_STATUS
174     //!         MOS_STATUS_SUCCESS if success, else fail reason
175     //!
176     MOS_STATUS Oca1stLevelBBStart(MOS_COMMAND_BUFFER &cmdBuffer) override;
177 
178     //!
179     //! \brief  Oca 1st Level BB End
180     //! \param  [in, out] cmdBuffer
181     //!         Reference to command buffer
182     //! \return MOS_STATUS
183     //!         MOS_STATUS_SUCCESS if success, else fail reason
184     //!
185     MOS_STATUS Oca1stLevelBBEnd(MOS_COMMAND_BUFFER &cmdBuffer) override;
186 
187 protected:
188 
189     //!
190     //! \brief    Resizes the cmd buffer and patch list with cmd buffer header
191     //!
192     //! \param    [in] requestedCommandBufferSize
193     //!           Requested resize command buffer size
194     //! \param    [in] requestedPatchListSize
195     //!           Requested resize patchlist size
196     //!
197     //! \return   MOS_STATUS
198     //!           MOS_STATUS_SUCCESS if success, else fail reason
199     //!
200     virtual MOS_STATUS ResizeCommandBufferAndPatchList(
201         uint32_t                    requestedCommandBufferSize,
202         uint32_t                    requestedPatchListSize) override;
203 
204     //!
205     //! \brief  Verify primary command buffer
206     //! \param  [in] requestedSize
207     //!         requested size for command buffer
208     //! \param  [in] requestedPatchListSize
209     //!         requested size for patched list
210     //! \param  [out] singleTaskPhaseSupportedInPak
211     //!         Inidcate if to use single task phase in pak.
212     //! \return MOS_STATUS
213     //!         MOS_STATUS_SUCCESS if success, else fail reason
214     //!
215     virtual MOS_STATUS VerifySpaceAvailable(uint32_t requestedSize, uint32_t requestedPatchListSize, bool &singleTaskPhaseSupportedInPak) override;
216 
217     //!
218     //! \brief  Set hint parameters
219     //! \return MOS_STATUS
220     //!         MOS_STATUS_SUCCESS if success, else fail reason
221     //!
222     MOS_STATUS SetHintParams();
223     //!
224     //! \brief  Populate hint parameters
225     //! \param  [in] cmdBuffer
226     //!         Pointer to command buffer
227     //! \return MOS_STATUS
228     //!         MOS_STATUS_SUCCESS if success, else fail reason
229     //!
230     MOS_STATUS PopulateHintParams(PMOS_COMMAND_BUFFER cmdBuffer);
231     //!
232     //! \brief  Sync all pipes
233     //! \param  [in] semaphoreId
234     //!         Id of the semaphore for this sync
235     //! \param  [in] cmdBuffer
236     //!         Pointer to command buffer
237     //! \return MOS_STATUS
238     //!         MOS_STATUS_SUCCESS if success, else fail reason
239     //!
240     MOS_STATUS SyncAllPipes(uint32_t semaphoreId, PMOS_COMMAND_BUFFER cmdBuffer);
241     //!
242     //! \brief  Sync pipes with first pipe wait for others
243     //! \detials Only support to use this sync once per frame.
244     //! \param  [in] cmdBuffer
245     //!         Pointer to command buffer
246     //! \return MOS_STATUS
247     //!         MOS_STATUS_SUCCESS if success, else fail reason
248     //!
249     MOS_STATUS SyncOnePipeWaitOthers(PMOS_COMMAND_BUFFER cmdBuffer);
250     //!
251     //! \brief  Sync pipes with second pipe wait for first pipe
252     //! \detials Only support to use this sync once per frame.
253     //! \param  [in] cmdBuffer
254     //!         Pointer to command buffer
255     //! \return MOS_STATUS
256     //!         MOS_STATUS_SUCCESS if success, else fail reason
257     //!
258     MOS_STATUS SyncOnePipeForAnother(PMOS_COMMAND_BUFFER cmdBuffer);
259     //!
260     //! \brief  Sync pipes with other pipes wait for first pipe
261     //! \detials Only support to use this sync once per frame.
262     //! \param  [in] cmdBuffer
263     //!         Pointer to command buffer
264     //! \return MOS_STATUS
265     //!         MOS_STATUS_SUCCESS if success, else fail reason
266     //!
267     MOS_STATUS SyncOtherPipesForOne(PMOS_COMMAND_BUFFER cmdBuffer);
268     //! \brief  Allocate resources for semaphore
269     //! \return MOS_STATUS
270     //!         MOS_STATUS_SUCCESS if success, else fail reason
271     //!
272     MOS_STATUS AllocateSemaphore();
273 
274     virtual MOS_STATUS SendAttrWithFrameTracking(MOS_COMMAND_BUFFER &cmdBuffer, bool frameTrackingRequested) override;
275 
276     static const uint8_t m_maxPassNum      = 4;
277     static const uint8_t m_maxNumBRCPasses = 4;
278 
279     static const uint8_t m_maxPipeNum      = 4;
280     static const uint8_t m_maxSemaphoreNum = 16;
281 
282     CodechalHwInterfaceNext *      m_hwInterface = nullptr;
283     MOS_COMMAND_BUFFER             m_primaryCmdBuffer = {};
284     MOS_COMMAND_BUFFER             m_secondaryCmdBuffer[m_maxPipeNum * m_maxPassNum] = {};
285     MOS_RESOURCE                   m_resSemaphoreAllPipes[m_maxSemaphoreNum] = {};
286     MOS_RESOURCE                   m_resSemaphoreOnePipeWait[m_maxPipeNum] = {};
287     MOS_RESOURCE                   m_resSemaphoreOnePipeForAnother = {};
288     MOS_RESOURCE                   m_resSemaphoreOtherPipesForOne = {};
289     uint32_t                       m_numDelay = 15;
290     MOS_RESOURCE                   m_resDelayMinus = {0};
291     MediaUserSettingSharedPtr      m_userSettingPtr = nullptr;
292 
293 MEDIA_CLASS_DEFINE_END(encode__EncodeScalabilityMultiPipe)
294 };
295 }  // namespace encode
296 #endif  // !__ENCODE_SCALABILITY_MULTIPIPE_H__
297