1 /* Copyright (c) 2018-2020, Intel Corporation
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included
11 * in all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
17 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19 * OTHER DEALINGS IN THE SOFTWARE.
20 */
21 //!
22 //! \file     vp_render_sfc_base.h
23 //! \brief    The header file of the base class of SFC rendering component
24 //! \details  The SFC renderer supports Scaling, IEF, CSC/ColorFill and Rotation.
25 //!           It's responsible for setting up HW states and generating the SFC
26 //!           commands.
27 //!
28 
29 #ifndef __VP_RENDER_SFC_BASE_H__
30 #define __VP_RENDER_SFC_BASE_H__
31 
32 #include "vp_sfc_common.h"
33 #include "vp_vebox_common.h"
34 #include "mhw_sfc_g12_X.h"
35 #include "vp_allocator.h"
36 #include "codec_def_decode_jpeg.h"
37 
38 namespace vp {
39 
40 class VpIef;
41 
42 class SfcRenderBase
43 {
44 
45 public:
46     SfcRenderBase(VP_MHWINTERFACE &vpMhwinterface, PVpAllocator &allocator);
47     virtual ~SfcRenderBase();
48 
49     //!
50     //! \brief    Initialize the object
51     //! \return   MOS_STATUS
52     //!
53     virtual MOS_STATUS Init();
54 
55     virtual MOS_STATUS Init(VIDEO_PARAMS &videoParams);
56 
57     //!
58     //! \brief    Setup CSC parameters of the SFC State
59     //! \param    [in,out] pSfcStateParams
60     //!           Pointer to SFC_STATE params
61     //! \param    [out] pIEFStateParams
62     //!           Pointer to MHW IEF state params
63     //! \return   void
64     //!
65     virtual MOS_STATUS SetIefStateCscParams(
66         PMHW_SFC_STATE_PARAMS           pSfcStateParams,
67         PMHW_SFC_IEF_STATE_PARAMS       pIEFStateParams);
68 
69     //!
70     //! \brief    Setup parameters related to SFC_IEF State
71     //! \details  Setup the IEF and CSC params of the SFC_IEF State
72     //! \param    [in,out] sfcStateParams
73     //!           Pointer to SFC_STATE params
74     //! \param    [in] inputSurface
75     //!           Pointer to Input Surface
76     //! \return   void
77     //!
78     virtual MOS_STATUS SetIefStateParams(
79         PMHW_SFC_STATE_PARAMS           sfcStateParams);
80 
81     //!
82     //! \brief    Setup parameters related to SFC_AVS State
83     //! \details  Setup the 8x8 table of SFC sampler
84     //! \return   MOS_STATUS
85     //!
86     virtual MOS_STATUS SetAvsStateParams();
87 
88     //!
89     //! \brief    Send SFC pipe commands
90     //! \details  Register the surfaces and send the commands needed by SFC pipe
91     //! \param    [in] pRenderData
92     //!           Pointer to Vebox Render data
93     //! \param    [in,out] pCmdBuffer
94     //!           Pointer to command buffer
95     //! \return   MOS_STATUS_SUCCESS if successful, otherwise failed
96     //!
97     virtual MOS_STATUS SendSfcCmd(
98         bool                            bOutputToMemory,
99         PMOS_COMMAND_BUFFER             pCmdBuffer);
100 
101     //!
102     //! \brief    Setup SFC states and parameters
103     //! \details  Setup SFC states and parameters including SFC State, AVS
104     //!           and IEF parameters
105     //! \param    [in] targetSurface
106     //!           Pointer to Output Surface
107     //! \return   Return MOS_STATUS_SUCCESS if successful, otherwise failed
108     //!
109     virtual MOS_STATUS SetupSfcState(PVP_SURFACE targetSurface);
110 
111     //!
112     //! \brief    Set scaling parameters
113     //! \details  Set scaling parameters
114     //! \param    [in] scalingParams
115     //!           Scaling parameters
116     //! \return   MOS_STATUS_SUCCESS if successful, otherwise failed
117     //!
118     virtual MOS_STATUS SetScalingParams(PSFC_SCALING_PARAMS scalingParams);
119 
120     //!
121     //! \brief    Set csc parameters
122     //! \details  Set csc parameters
123     //! \param    [in] cscParams
124     //!           Csc parameters
125     //! \return   MOS_STATUS_SUCCESS if successful, otherwise failed
126     //!
127     virtual MOS_STATUS SetCSCParams(PSFC_CSC_PARAMS cscParams);
128 
129     //!
130     //! \brief    Set rotation and mirror parameters
131     //! \details  Set rotation and mirror parameters
132     //! \param    [in] rotMirParams
133     //!           rotation and mirror parameters
134     //! \return   MOS_STATUS_SUCCESS if successful, otherwise failed
135     //!
136     virtual MOS_STATUS SetRotMirParams(PSFC_ROT_MIR_PARAMS rotMirParams);
137 
138     //!
139     //! \brief    Set mmc parameters
140     //! \details  Set mmc parameters
141     //! \param    [in] renderTarget
142     //!           render target surface
143     //! \param    [in] isFormalMmcSupported
144     //!           Is format supported by mmc
145     //! \param    [in] isMmcEnabled
146     //!           Is mmc enabled
147     //! \return   MOS_STATUS_SUCCESS if successful, otherwise failed
148     //!
149     virtual MOS_STATUS SetMmcParams(PMOS_SURFACE renderTarget, bool isFormatMmcSupported, bool isMmcEnabled);
150 
151     //!
152     //! \brief    Check whether VDBOX-SFC Input Format Supported
153     //! \details  Check whether VDBOX-SFC Input Format Supported.
154     //! \param    codecStandard
155     //!           [in] Codec Standard.
156     //! \param    inputFormat
157     //!           [in] Format of Input Frame
158     //! \return   bool
159     //!           Return true if supported, otherwise failed
160     //!
161     virtual bool IsVdboxSfcInputFormatSupported(
162     CODECHAL_STANDARD           codecStandard,
163     MOS_FORMAT                  inputFormat);
164 
165     //!
166     //! \brief    Check whether VDBOX-SFC Output Format Supported
167     //! \details  Check whether VDBOX-SFC Output Format Supported.
168     //! \param    codecStandard
169     //!           [in] Codec Standard.
170     //! \param    outputFormat
171     //!           [in] Format of Output Frame
172     //! \return   bool
173     //!           Return true if supported, otherwise failed
174     //!
175     virtual bool IsVdboxSfcOutputFormatSupported(
176         CODECHAL_STANDARD           codecStandard,
177         MOS_FORMAT                  outputFormat,
178         MOS_TILE_TYPE               tileType);
179 
IsCSC()180     bool IsCSC() { return m_renderData.bCSC; }
IsScaling()181     bool IsScaling() { return m_renderData.bScaling; }
182 
183     //!
184     //! \brief    Get Sfc's input format
185     //! \return   MOS_FORMAT
186     //!
GetInputFormat()187     MOS_FORMAT GetInputFormat()
188     {
189         return m_renderData.SfcInputFormat;
190     }
191 
SetIefObj(VpIef * iefObj)192     MOS_STATUS SetIefObj(VpIef *iefObj)
193     {
194         VP_PUBLIC_CHK_NULL_RETURN(iefObj);
195         m_iefObj = iefObj;
196         return MOS_STATUS_SUCCESS;
197     }
198 
GetIefParams()199     PVPHAL_IEF_PARAMS GetIefParams()
200     {
201         return m_renderData.pIefParams;
202     }
203 
204     MOS_STATUS SetHistogramBuf(PMOS_BUFFER histogramBuf);
205 
206     //!
207     //! \brief    Set sfc pipe selected with vebox
208     //! \details  Set sfc pipe selected with vebox
209     //! \param    [in] dwSfcPipe
210     //!           Sfc pipe selected with vebox
211     //! \param    [in] dwSfcNum
212     //!           Sfc pipe num in total
213     //! \return   MOS_STATUS
214     //!           MOS_STATUS_SUCCESS if success, else fail reason
SetSfcPipe(uint32_t dwSfcPipe,uint32_t dwSfcNum)215     virtual MOS_STATUS SetSfcPipe(uint32_t dwSfcPipe, uint32_t dwSfcNum)
216     {
217         MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
218         MOS_UNUSED(dwSfcPipe);
219         MOS_UNUSED(dwSfcNum);
220         return eStatus;
221     }
222 
223 protected:
224     //!
225     //! \brief    Initialize SfcState parameters
226     //! \return   MOS_STATUS_SUCCESS if successful, otherwise failed
227     //!
228     virtual MOS_STATUS InitSfcStateParams() = 0;
229 
230     //!
231     //! \brief    Set SFC input chroma subsampling
232     //! \details  Set SFC input chroma subsampling according to
233     //!           pipe mode
234     //! \param    [out] sfcStateParams
235     //!           Pointer to SFC state params
236     //! \return   MOS_STATUS
237     //!
238     virtual MOS_STATUS SetSfcStateInputChromaSubSampling(
239         PMHW_SFC_STATE_PARAMS       sfcStateParams);
240 
241     //!
242     //! \brief    Set SFC input ordering mode
243     //! \details  SFC input ordering mode according to
244     //!           pipe mode
245     //! \param    [out] sfcStateParams
246     //!           Pointer to SFC state params
247     //! \return   MOS_STATUS
248     //!
249     virtual MOS_STATUS SetSfcStateInputOrderingMode(
250         PMHW_SFC_STATE_PARAMS       sfcStateParams);
251     virtual MOS_STATUS SetSfcStateInputOrderingModeJpeg(
252         PMHW_SFC_STATE_PARAMS       sfcStateParams);
253     virtual MOS_STATUS SetSfcStateInputOrderingModeVdbox(
254         PMHW_SFC_STATE_PARAMS       sfcStateParams);
255     virtual MOS_STATUS SetSfcStateInputOrderingModeHcp(
256         PMHW_SFC_STATE_PARAMS       sfcStateParams) = 0;
257 
258     //!
259     //! \brief    Set codec pipe mode
260     //! \details  Set codec pipe mode
261     //! \param    [in] codecStandard
262     //!           codec standard
263     //! \return   MOS_STATUS
264     virtual MOS_STATUS SetCodecPipeMode(CODECHAL_STANDARD codecStandard);
265     //!
266     //! \brief    Setup ColorFill parameters
267     //! \details  Setup ColorFill parameters
268     //! \param    [in] sfcStateParams
269     //!           Pointer to SFC_STATE params
270     //! \return   void
271     void SetColorFillParams(
272         PMHW_SFC_STATE_PARAMS       pSfcStateParams);
273 
274     //!
275     //! \brief    Setup Rotation and Mirrow params
276     //! \details  Setup Rotation and Mirrow params
277     //! \param    [in,out] sfcStateParams
278     //!           Pointer to SFC_STATE params
279     //! \return   void
280     //!
281     void SetRotationAndMirrowParams(
282         PMHW_SFC_STATE_PARAMS       pSfcStateParams);
283 
284     //!
285     //! \brief    Setup Chromasting params
286     //! \details  Setup Chromasting params
287     //! \param    [in,out] sfcStateParams
288     //!           Pointer to SFC_STATE params
289     //! \return   void
290     //!
291     void SetChromasitingParams(
292         PMHW_SFC_STATE_PARAMS       pSfcStateParams);
293 
294     //!
295     //! \brief    Setup Bypass X & Y AdaptiveFilter params
296     //! \details  Setup Bypass X & Y AdaptiveFilter params
297     //! \param    [in,out] sfcStateParams
298     //!           Pointer to SFC_STATE params
299     //! \return   void
300     //!
301     void SetXYAdaptiveFilter(
302         PMHW_SFC_STATE_PARAMS       pSfcStateParams);
303 
304     //!
305     //! \brief    Setup RGB Adaptive params
306     //! \details  Setup RGB Adaptive params
307     //! \param    [in,out] sfcStateParams
308     //!           Pointer to SFC_STATE params
309     //! \return   void
310     //!
311     void SetRGBAdaptive(
312         PMHW_SFC_STATE_PARAMS       pSfcStateParams);
313 
314 
315     //!
316     //! \brief    Initialize SFC Output Surface Command parameters
317     //! \details  Initialize MHW SFC Output Surface Command parameters from SFC Pipe output Surface
318     //! \param    [in] pSfcPipeOutSurface
319     //!           pointer to SFC Pipe output Surface
320     //! \param    [out] pMhwOutSurfParams
321     //!           pointer to SFC Output Surface Command parameters
322     //! \return   MOS_STATUS
323     //!
324     MOS_STATUS InitMhwOutSurfParams(
325         PVP_SURFACE                     pSfcPipeOutSurface,
326         PMHW_SFC_OUT_SURFACE_PARAMS     pMhwOutSurfParams);
327 
328     //!
329     //! \brief    Initialize AVS parameters shared by Renderers
330     //! \details  Initialize the members of the AVS parameter and allocate memory for its coefficient tables
331     //! \param    [in,out] pAVS_Params
332     //!           Pointer to MHW AVS parameter
333     //! \param    [in] uiYCoeffTableSize
334     //!           Size of the Y coefficient table
335     //! \param    [in] uiUVCoeffTableSize
336     //!           Size of the UV coefficient table
337     //! \return   void
338     //!
339     //!
340     void InitAVSParams(
341         PMHW_AVS_PARAMS     pAVS_Params,
342         uint32_t            uiYCoeffTableSize,
343         uint32_t            uiUVCoeffTableSize);
344 
345     //!
346     //! \brief    Destroy AVS parameters shared by Renderers
347     //! \details  Free the memory of AVS parameter's coefficient tables
348     //! \param    [in,out] pAVS_Params
349     //!           Pointer to VPHAL AVS parameter
350     //! \return   void
351     //!
352     void DestroyAVSParams(
353         PMHW_AVS_PARAMS   pAVS_Params);
354 
355     //!
356     //! \brief    Get Avs line buffer size
357     //! \details  Get Avs line buffer size according to height of input surface
358     //! \param    [in] lineTiledBuffer
359     //!           ture if avs line tile buffer, otherwise, avs line buffer.
360     //! \param    [in] b8tapChromafiltering
361     //!           ture if 8-tap UV, otherwise, 4-tap UV.
362     //! \param    [in] width
363     //!           The width of input surface
364     //! \param    [in] height
365     //!           The height of input surface
366     //! \return   uint32_t
367     //!
368     uint32_t GetAvsLineBufferSize(bool lineTiledBuffer, bool b8tapChromafiltering, uint32_t width, uint32_t height);
369 
370     //!
371     //! \brief    Get Ief line buffer size
372     //! \details  Get Ief line buffer size according to height of scaled surface
373     //! \param    [in] lineTiledBuffer
374     //!           ture if ief line tile buffer, otherwise, ief line buffer.
375     //! \param    [in] heightOutput
376     //!           The height of output surface
377     //! \return   uint32_t
378     //!
379     uint32_t GetIefLineBufferSize(bool lineTiledBuffer, uint32_t heightOutput);
380 
381     //!
382     //! \brief    Get Sfd line buffer size
383     //! \details  Get Sfd line buffer size according to height of scaled surface
384     //! \param    [in] lineTiledBuffer
385     //!           ture if sdf line tile buffer, otherwise, sdf line buffer.
386     //! \param    [in] formatOutput
387     //!           format of output surface.
388     //! \param    [in] widthOutput
389     //!           The width of input surface
390     //! \param    [in] heightOutput
391     //!           The height of input surface
392     //! \return   uint32_t
393     //!
394     virtual uint32_t GetSfdLineBufferSize(bool lineTiledBuffer, MOS_FORMAT formatOutput, uint32_t widthOutput, uint32_t heightOutput);
395 
396     //!
397     //! \brief    Allocate line buffer
398     //! \details  Allocate line buffer
399     //! \param    [in/out] lineBuffer
400     //!           pointer to line buffer.
401     //! \param    [in] size
402     //!           size of line buffer.
403     //! \param    [in] bufName
404     //!           name of line buffer.
405     //! \return   MOS_STATUS
406     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
407     //!
408     MOS_STATUS AllocateLineBuffer(VP_SURFACE *&lineBuffer, uint32_t size, const char *bufName);
409 
410     //!
411     //! \brief    Allocate line buffer array
412     //! \details  Allocate line buffer
413     //! \param    [in/out] lineBufferArray
414     //!           pointer to line buffer.
415     //! \param    [in] size
416     //!           size of line buffer.
417     //! \param    [in] bufName
418     //!           name of line buffer.
419     //! \return   MOS_STATUS
420     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
421     //!
422     MOS_STATUS AllocateLineBufferArray(VP_SURFACE **&lineBufferArray, uint32_t size, const char *bufName);
423 
424     //!
425     //! \brief    Destroy line buffer array
426     //! \details  Allocate line buffer
427     //! \param    [in/out] lineBufferArray
428     //!           pointer to line buffer.
429     //! \param    [in] numPipe
430     //!           size of pipe.
431     //! \param    [in] size
432     //!           size of line buffer.
433     //! \param    [in] bufName
434     //!           name of line buffer.
435     //! \return   MOS_STATUS
436     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
437     //!
438     MOS_STATUS DestroyLineBufferArray(VP_SURFACE **&lineBufferArray);
439 
440     //!
441     //! \brief    Allocate Resources for SFC Pipe
442     //! \details  Allocate the AVS and IEF line buffer surfaces for SFC
443     //! \return   Return MOS_STATUS_SUCCESS if successful, otherwise failed
444     //!
445     virtual MOS_STATUS AllocateResources();
446 
447     //!
448     //! \brief    SFC free resources
449     //! \details  Free resources that are used in Vebox
450     //! \return   MOS_STATUS
451     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
452     //!
453     virtual MOS_STATUS FreeResources();
454 
455     virtual MOS_STATUS AddSfcLock(
456         PMOS_COMMAND_BUFFER     pCmdBuffer,
457         PMHW_SFC_LOCK_PARAMS    pSfcLockParams);
458 
459     //!
460     //! \brief    Set resource of line buffer
461     //! \details  Set resource of line buffer
462     //! \param    [out] osResLineBuffer
463     //!           resource to be set
464     //! \param    [in] lineBuffer
465     //!           pointer to line buffer
466     //! \return   MOS_STATUS
467     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
468     //!
469     MOS_STATUS SetLineBuffer(PMOS_RESOURCE &osResLineBuffer, VP_SURFACE *lineBuffer);
470 
471     virtual MOS_STATUS SetupScalabilityParams() = 0;
472     virtual bool IsInputChannelSwapNeeded(MOS_FORMAT inputFormat);
473     virtual bool IsOutputChannelSwapNeeded(MOS_FORMAT outputFormat) = 0;
474     virtual bool IsCscNeeded(SFC_CSC_PARAMS &cscParams) = 0;
475 
476 protected:
477 
478     // HW intface to access MHW
479     PMOS_INTERFACE                  m_osInterface  = nullptr;
480     PMHW_SFC_INTERFACE              m_sfcInterface = nullptr;
481     PMHW_MI_INTERFACE               m_miInterface = nullptr;
482     MEDIA_FEATURE_TABLE             *m_skuTable = nullptr;
483     MEDIA_WA_TABLE                  *m_waTable = nullptr;
484 
485     // AVS related params
486     MHW_AVS_PARAMS                  m_AvsParameters = {};                     //!< AVS parameters
487     VPHAL_SFC_AVS_STATE             m_avsState = {};                          //!< AVS State and Coeff. table
488     static const uint32_t           k_YCoefficientTableSize = 256 * sizeof(int32_t);
489     static const uint32_t           k_UVCoefficientTableSize = 128 * sizeof(int32_t);
490 
491     PMHW_SFC_STATE_PARAMS           m_sfcStateParams = nullptr;               //!< Pointer to sfc state parameters
492     VP_SFC_RENDER_DATA              m_renderData = {};                        //!< Transient Render data populated for every BLT call
493 
494     VPHAL_CSPACE                    m_cscRTCspace = {};                       //!< Cspace of Render Target
495     VPHAL_CSPACE                    m_cscInputCspace = {};                    //!< Cspace of input frame
496 
497     MHW_SFC_IEF_STATE_PARAMS        m_IefStateParams = {};                    //!< IEF Params state
498     float                           m_cscCoeff[9] = {};                       //!< [3x3] Coeff matrix
499     float                           m_cscInOffset[3] = {};                    //!< [3x1] Input Offset matrix
500     float                           m_cscOutOffset[3] = {};                   //!< [3x1] Output Offset matrix
501     uint32_t                        m_currentChannel = 0;                     //!< 0=StereoLeft or nonStereo, 1=StereoRight. N/A in nonStereo
502 
503     VP_SURFACE                      **m_AVSLineBufferSurfaceArray = nullptr;  //!< AVS Line Buffer Surface for SFC
504     VP_SURFACE                      **m_IEFLineBufferSurfaceArray = nullptr;  //!< IEF Line Buffer Surface for SFC
505     VP_SURFACE **                     m_SFDLineBufferSurfaceArray = nullptr;  //!< SFD Line Buffer Surface for SFC
506 
507     VP_SURFACE                      *m_AVSLineTileBufferSurface = nullptr;    //!< AVS Line Tile Buffer Surface for SFC
508     VP_SURFACE                      *m_IEFLineTileBufferSurface = nullptr;    //!< IEF Line Tile Buffer Surface for SFC
509     VP_SURFACE                      *m_SFDLineTileBufferSurface = nullptr;    //!< SFD Line Tile Buffer Surface for SFC
510 
511     // Allocator interface
512     PVpAllocator                    m_allocator = nullptr;                                //!< vp pipeline allocator
513     VpIef                           *m_iefObj = nullptr;
514     uint8_t                         m_pipeMode = MhwSfcInterface::SFC_PIPE_MODE_VEBOX; //!< which FE engine pipe used
515 
516     bool                            m_bVdboxToSfc = false;
517     VIDEO_PARAMS                    m_videoConfig = {};
518 
519     int                             m_lineBufferAllocatedInArray    = 1;        //!< Line buffer allocated in array
520 
521     SCALABILITY_PARAMS              m_scalabilityParams             = {};
522 
523     MOS_SURFACE                     m_histogramSurf = {};   //!< Histogram buffer
524 
525 MEDIA_CLASS_DEFINE_END(SfcRenderBase)
526 };
527 
528 }
529 #endif // !__VP_RENDER_SFC_BASE_H__
530