1 /*
2 * Copyright (c) 2020-2024, 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     vp_scalability_multipipe_next.h
25 //! \brief    Defines the common interface for vp scalability mulitpipe mode.
26 //! \details  The vp scalability mulitpipe interface is further sub-divided by codecs,
27 //!           this file is for the base interface which is shared by all codecs.
28 //!
29 
30 #ifndef __VP_SCALABILITY_MULTIPIPE_NEXT_H__
31 #define __VP_SCALABILITY_MULTIPIPE_NEXT_H__
32 #include "mos_defs.h"
33 #include "mos_os.h"
34 #include "media_scalability_multipipe.h"
35 #include "vp_scalability_option.h"
36 #include "mos_os_virtualengine_scalability_next.h"
37 #include "vp_phase.h"
38 #include "mhw_mi_itf.h"
39 
40 namespace vp
41 {
42 class VpScalabilityMultiPipeNext : public MediaScalabilityMultiPipe
43 {
44 public:
45     //!
46     //! \brief  Vp scalability mulitipipe constructor
47     //! \param  [in] hwInterface
48     //!         Pointer to HwInterface
49     //! \param  [in] mediaContext
50     //!         Pointer to MediaContext
51     //! \param  [in] componentType
52     //!         Component type
53     //!
54     VpScalabilityMultiPipeNext(void *hwInterface, MediaContext *mediaContext, uint8_t componentType);
55 
56     //!
57     //! \brief  Vp scalability mulitipipe destructor
58     //!
59     ~VpScalabilityMultiPipeNext();
60 
61     //!
62     //! \brief    Copy constructor
63     //!
64     VpScalabilityMultiPipeNext(const VpScalabilityMultiPipeNext &) = delete;
65 
66     //!
67     //! \brief    Copy assignment operator
68     //!
69     VpScalabilityMultiPipeNext &operator=(const VpScalabilityMultiPipeNext &) = delete;
70 
71     //!
72     //! \brief   Initialize the media scalability
73     //! \details It will prepare the resources needed in scalability
74     //!          and initialize the state of scalability
75     //! \param   [in] option
76     //!          Input scalability option
77     //! \return  MOS_STATUS
78     //!          MOS_STATUS_SUCCESS if success, else fail reason
79     //!
80     MOS_STATUS Initialize(const MediaScalabilityOption &option) override;
81 
82     //!
83     //! \brief  Construct parameters for GPU context create.
84     //! \param   [in, out] gpuCtxCreateOption
85     //!          Pointer to the GPU Context Create Option
86     //! \return  MOS_STATUS
87     //!          MOS_STATUS_SUCCESS if success, else fail reason
88     //!
89     MOS_STATUS GetGpuCtxCreationOption(MOS_GPUCTX_CREATOPTIONS *gpuCtxCreateOption) override;
90 
91     //!
92     //! \brief  Destroy the media scalability
93     //! \return MOS_STATUS
94     //!         MOS_STATUS_SUCCESS if success, else fail reason
95     //!
96     virtual MOS_STATUS Destroy() override;
97 
98     //!
99     //! \brief  Update the media scalability state
100     //! \param  [in] statePars
101     //!         parameters to update the state
102     //! \return MOS_STATUS
103     //!         MOS_STATUS_SUCCESS if success, else fail reason
104     //!
105     MOS_STATUS UpdateState(void *statePars) override;
106 
107     //!
108     //! \brief  Verify command buffer
109     //! \param  [in] requestedSize
110     //!         requested size for command buffer
111     //! \param  [in] requestedPatchListSize
112     //!         requested size for patched list
113     //! \param  [out] singleTaskPhaseSupportedInPak
114     //!         Inidcate if to use single task phase in pak.
115     //! \return MOS_STATUS
116     //!         MOS_STATUS_SUCCESS if success, else fail reason
117     //!
118     MOS_STATUS VerifyCmdBuffer(uint32_t requestedSize, uint32_t requestedPatchListSize, bool &singleTaskPhaseSupportedInPak) override;
119 
120     //!
121     //! \brief  Get command buffer
122     //! \param  [in, out] cmdBuffer
123     //!         Pointer to command buffer
124     //! \return MOS_STATUS
125     //!         MOS_STATUS_SUCCESS if success, else fail reason
126     //!
127     MOS_STATUS GetCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer, bool frameTrackingRequested = true) override;
128 
129     //!
130     //! \brief  Return command buffer
131     //! \param  [in, out] cmdBuffer
132     //!         Pointer to command buffer
133     //! \return MOS_STATUS
134     //!         MOS_STATUS_SUCCESS if success, else fail reason
135     //!
136     MOS_STATUS ReturnCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer) override;
137 
138     //!
139     //! \brief  Submit command buffer
140     //! \param  [in, out] cmdBuffer
141     //!         Pointer to command buffer
142     //! \return MOS_STATUS
143     //!         MOS_STATUS_SUCCESS if success, else fail reason
144     //!
145     MOS_STATUS SubmitCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer) override;
146 
147     //!
148     //! \brief  Add synchronization for pipes.
149     //! \param  [in] syncType
150     //!         type of pipe sync
151     //! \param  [in] semaphoreId
152     //!         Id of the semaphore used for this sync
153     //! \param  [in, out] cmdBuffer
154     //!         Pointer to command buffer
155     //! \return MOS_STATUS
156     //!         MOS_STATUS_SUCCESS if success, else fail reason
157     //!
158     MOS_STATUS SyncPipe(uint32_t syncType, uint32_t semaphoreId, PMOS_COMMAND_BUFFER cmdBuffer) override;
159 
160     //!
161     //! \brief  Reset semaphore
162     //! \param  [in] syncType
163     //!         type of pipe sync to find the related semaphore
164     //! \param  [in] semaphoreId
165     //!         Id of the semaphore for reset
166     //! \param  [in, out] cmdBuffer
167     //! \return MOS_STATUS
168     //!         MOS_STATUS_SUCCESS if success, else fail reason
169     //!
170     MOS_STATUS ResetSemaphore(uint32_t syncType, uint32_t semaphoreId, PMOS_COMMAND_BUFFER cmdBuffer) override;
171 
172     //!
173     //! \brief    Resizes the cmd buffer and patch list with cmd buffer header
174     //!
175     //! \param    [in] requestedCommandBufferSize
176     //!           Requested resize command buffer size
177     //! \param    [in] requestedPatchListSize
178     //!           Requested resize patchlist size
179     //!
180     //! \return   MOS_STATUS
181     //!           MOS_STATUS_SUCCESS if success, else fail reason
182     //!
183     virtual MOS_STATUS ResizeCommandBufferAndPatchList(
184         uint32_t                    requestedCommandBufferSize,
185         uint32_t                    requestedPatchListSize) override;
186 
187     //!
188     //! \brief  Verify primary command buffer
189     //! \param  [in] requestedSize
190     //!         requested size for command buffer
191     //! \param  [in] requestedPatchListSize
192     //!         requested size for patched list
193     //! \param  [out] singleTaskPhaseSupportedInPak
194     //!         Inidcate if to use single task phase in pak.
195     //! \return MOS_STATUS
196     //!         MOS_STATUS_SUCCESS if success, else fail reason
197     //!
198     virtual MOS_STATUS VerifySpaceAvailable(uint32_t requestedSize, uint32_t requestedPatchListSize, bool &singleTaskPhaseSupportedInPak) override;
199 
200     //!
201     //! \brief  Set hint parameters
202     //! \return MOS_STATUS
203     //!         MOS_STATUS_SUCCESS if success, else fail reason
204     //!
205     virtual MOS_STATUS SetHintParams();
206 
207     //!
208     //! \brief  Populate hint parameters
209     //! \param  [in] cmdBuffer
210     //!         Pointer to command buffer
211     //! \return MOS_STATUS
212     //!         MOS_STATUS_SUCCESS if success, else fail reason
213     //!
214     MOS_STATUS PopulateHintParams(PMOS_COMMAND_BUFFER cmdBuffer);
215 
216     //!
217     //! \brief  Sync all pipes
218     //! \param  [in] cmdBuffer
219     //!         Pointer to command buffer
220     //! \return MOS_STATUS
221     //!         MOS_STATUS_SUCCESS if success, else fail reason
222     //!
223     MOS_STATUS SyncAllPipes(PMOS_COMMAND_BUFFER cmdBuffer);
224 
225     //!
226     //! \brief  Sync pipes with first pipe wait for others
227     //! \detials Only support to use this sync once per frame.
228     //! \param  [in] cmdBuffer
229     //!         Pointer to command buffer
230     //! \param  [in] pipeIdx
231     //!         The index of pipeline which wait for others
232     //! \return MOS_STATUS
233     //!         MOS_STATUS_SUCCESS if success, else fail reason
234     //!
235     virtual MOS_STATUS SyncOnePipeWaitOthers(PMOS_COMMAND_BUFFER cmdBuffer, uint32_t pipeIdx);
236 
237     //! \brief  Allocate resources for semaphore
238     //! \return MOS_STATUS
239     //!         MOS_STATUS_SUCCESS if success, else fail reason
240     //!
241     MOS_STATUS AllocateSemaphore();
242 
243     //!
244     //! \brief  Send Cmd buffer Attributes with frame tracking info
245     //!
246     //! \param  [in] cmdBuffer
247     //!         Reference to command buffer
248     //! \param  [in] frameTrackingRequested
249     //!         Indicate if frame tracking is requested
250     //!
251     //! \return MOS_STATUS
252     //!         MOS_STATUS_SUCCESS if success, else fail reason
253     //!
254     MOS_STATUS SendAttrWithFrameTracking(MOS_COMMAND_BUFFER &cmdBuffer, bool frameTrackingRequested) override;
255 
256     //!
257     //! \brief    Send hw semphore wait cmd
258     //! \details  Send hw semphore wait cmd for sync perpose
259     //!
260     //! \param    [in] semaMem
261     //!           Reource of Hw semphore
262     //! \param    [in] offset
263     //!           offset of semMem
264     //! \param    [in] semaData
265     //!           Data of Hw semphore
266     //! \param    [in] opCode
267     //!           Operation code
268     //! \param    [in,out] cmdBuffer
269     //!           command buffer
270     //!
271     //! \return   MOS_STATUS
272     //!           MOS_STATUS_SUCCESS if success, else fail reason
273     //!
274     virtual MOS_STATUS SendHwSemaphoreWaitCmd(
275         PMOS_RESOURCE                             semaMem,
276         uint32_t                                  offset,
277         uint32_t                                  semaData,
278         MHW_COMMON_MI_SEMAPHORE_COMPARE_OPERATION opCode,
279         PMOS_COMMAND_BUFFER                       cmdBuffer);
280 
281     //!
282     //! \brief    Send mi atomic dword cmd
283     //! \details  Send mi atomic dword cmd for sync perpose
284     //!
285     //! \param    [in] resource
286     //!           Reource used in mi atomic dword cmd
287     //! \param    [in] offset
288     //!           offset of resource
289     //! \param    [in] immData
290     //!           Immediate data
291     //! \param    [in] opCode
292     //!           Operation code
293     //! \param    [in,out] cmdBuffer
294     //!           command buffer
295     //!
296     //! \return   MOS_STATUS
297     //!           MOS_STATUS_SUCCESS if success, else fail reason
298     //!
299     virtual MOS_STATUS SendMiAtomicDwordCmd(
300         PMOS_RESOURCE               resource,
301         uint32_t                    offset,
302         uint32_t                    immData,
303         MHW_COMMON_MI_ATOMIC_OPCODE opCode,
304         PMOS_COMMAND_BUFFER         cmdBuffer);
305 
306     //!
307     //! \brief    Send mi flush dword cmd
308     //! \details  Send mi flush dword cmd for sync perpose
309     //!
310     //! \param    [in] semMem
311     //!           Reource used in mi flush dword cmd
312     //! \param    [in] semaData
313     //!           Immediate data
314     //! \param    [in,out] cmdBuffer
315     //!           command buffer
316     //!
317     //! \return   MOS_STATUS
318     //!           MOS_STATUS_SUCCESS if success, else fail reason
319     //!
320     virtual MOS_STATUS AddMiFlushDwCmd(
321         PMOS_RESOURCE                             semaMem,
322         uint32_t                                  semaData,
323         PMOS_COMMAND_BUFFER                       cmdBuffer);
324 
325     //!
326     //! \brief    Send mi store data dword cmd
327     //! \details  Send mi store dat dword cmd for sync perpose
328     //!
329     //! \param    [in] resource
330     //!           Reource used in mi store dat dword cmd
331     //! \param    [in] offset
332     //!           offset of semMem
333     //! \param    [in,out] cmdBuffer
334     //!           command buffer
335     //!
336     //! \return   MOS_STATUS
337     //!           MOS_STATUS_SUCCESS if success, else fail reason
338     //!
339     virtual MOS_STATUS AddMiStoreDataImmCmd(
340         PMOS_RESOURCE               resource,
341         uint32_t                    offset,
342         PMOS_COMMAND_BUFFER         cmdBuffer);
343 
344     static MOS_STATUS CreateMultiPipe(void *hwInterface, MediaContext *mediaContext, uint8_t componentType);
345 
346     PVP_MHWINTERFACE                m_hwInterface      = nullptr;
347     MOS_COMMAND_BUFFER              m_primaryCmdBuffer = {};            //!< The primary command buffer
348     std::vector<MOS_COMMAND_BUFFER> m_secondaryCmdBuffers;              //!< The secondary command buffer
349     std::vector<bool>               m_secondaryCmdBuffersReturned;      //!< The secondary command buffer returned
350     static const uint8_t            m_initSecondaryCmdBufNum = 4;       //!< The initial secondary command buffer size
351     static const uint8_t            m_maxCmdBufferSetsNum    = 16;       //!< The max number of command buffer sets
352     static const uint32_t           m_CmdBufferSize          = 0x4000;  //!< The command buffer size
353 
354     MOS_RESOURCE                    m_resSemaphoreAllPipes[2] = {};     //!< The sync semaphore between all pipes
355     MOS_RESOURCE                    m_resSemaphoreOnePipeWait = {};     //!< The sync semaphore between main pipe and other pipes
356     uint32_t                        m_semaphoreAllPipesIndex = 0;       //!< The index for semaphore using by current frame
357     uint32_t                        m_semaphoreAllPipesPhase = 0;       //!< The count for semaphore using by current frame
358 
359     VpPhase                               *m_phase = nullptr;
360     std::shared_ptr<mhw::mi::Itf>          m_miItf = nullptr;
361 
362 MEDIA_CLASS_DEFINE_END(vp__VpScalabilityMultiPipeNext)
363 };
364 }  // namespace vp
365 #endif  // !__VP_SCALABILITY_MULTIPIPE_NEXT_H__
366