1 /*
2 * Copyright (c) 2021-2023, 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     decode_vvc_picture_packet.h
24 //! \brief    Defines the implementation of VVC decode picture packet
25 //!
26 
27 #ifndef __DECODE_VVC_PICTURE_PACKET_H__
28 #define __DECODE_VVC_PICTURE_PACKET_H__
29 
30 #include "media_cmd_packet.h"
31 #include "decode_vvc_pipeline.h"
32 #include "decode_utils.h"
33 #include "decode_vvc_basic_feature.h"
34 #include "decode_common_feature_defs.h"
35 #include "mhw_vdbox_vvcp_itf.h"
36 
37 using namespace mhw::vdbox::vvcp;
38 
39 namespace decode
40 {
41     class VvcDecodePicPkt : public DecodeSubPacket, public Itf::ParSetting
42     {
43     public:
44         //!
45         //! \brief  VvcDecodePicPkt constructor
46         //!
VvcDecodePicPkt(VvcPipeline * pipeline,CodechalHwInterfaceNext * hwInterface)47         VvcDecodePicPkt(VvcPipeline *pipeline, CodechalHwInterfaceNext *hwInterface)
48             : DecodeSubPacket(pipeline, hwInterface), m_vvcPipeline(pipeline)
49         {
50             if (hwInterface != nullptr)
51             {
52                 m_hwInterface = dynamic_cast<CodechalHwInterfaceNext *>(hwInterface);
53                 if (m_hwInterface != nullptr)
54                 {
55                     m_vvcpItf     = std::static_pointer_cast<mhw::vdbox::vvcp::Itf>(m_hwInterface->GetVvcpInterfaceNext());
56                 }
57                 m_miItf       = std::static_pointer_cast<mhw::mi::Itf>(hwInterface->GetMiInterfaceNext());
58             }
59         }
60 
61         //!
62         //! \brief  VvcDecodePicPkt deconstructor
63         //!
64         virtual ~VvcDecodePicPkt();
65 
66         //!
67         //! \brief  Initialize the media packet, allocate required resources
68         //! \return MOS_STATUS
69         //!         MOS_STATUS_SUCCESS if success, else fail reason
70         //!
71         virtual MOS_STATUS Init() override;
72 
73         //!
74         //! \brief  Prepare interal parameters, should be invoked for each frame
75         //! \return MOS_STATUS
76         //!         MOS_STATUS_SUCCESS if success, else fail reason
77         //!
78         virtual MOS_STATUS Prepare() override;
79 
80         //!
81         //! \brief  Execute VVC picture packet
82         //! \return MOS_STATUS
83         //!         MOS_STATUS_SUCCESS if success, else fail reason
84         //!
85         MOS_STATUS Execute(MOS_COMMAND_BUFFER& cmdBuffer);
86 
87         //!
88         //! \brief  Init VVC state commands
89         //! \return MOS_STATUS
90         //!         MOS_STATUS_SUCCESS if success, else fail reason
91         //!
92         MOS_STATUS InitVvcState(MOS_COMMAND_BUFFER& cmdBuffer);
93 
94         //!
95         //! \brief  Calculate Command Size
96         //!
97         //! \param  [in, out] commandBufferSize
98         //!         requested size
99         //! \param  [in, out] requestedPatchListSize
100         //!         requested size
101         //! \return MOS_STATUS
102         //!         status
103         //!
104         MOS_STATUS CalculateCommandSize(
105             uint32_t &commandBufferSize,
106             uint32_t &requestedPatchListSize) override;
107 
GetPicLvlBB()108         PMHW_BATCH_BUFFER GetPicLvlBB()
109         {
110             return m_curPicLvlBatchBuffer;
111         }
112 
113         static const uint32_t m_alfBufferSize               = 4608;         // Max 8*144DWs, size in Bytes
114         static const uint32_t m_chromaQpBufferSize          = 256;          // Max 4*16DWs, size in Bytes
115         static const uint32_t m_scalingListBufferSize       = 1400;         // Max 350DWs, size in Bytes
116 
117     protected:
118         virtual MOS_STATUS AllocateFixedResources();
119         virtual MOS_STATUS AllocateVariableResources();
120         virtual MOS_STATUS AllocatePicLvlBB();
121 
122         MOS_STATUS SetDataBuffers() const;
123         MOS_STATUS SetScalingListDataBuffer(uint8_t* buffer, uint32_t size) const;
124         MOS_STATUS FixVvcpPipeBufAddrParams() const;
125 
126         //! \brief    Set Rowstore Cache offset
127         //!
128         //! \return   MOS_STATUS
129         //!           MOS_STATUS_SUCCESS if success, else fail reason
130         //!
131         virtual MOS_STATUS SetRowstoreCachingOffsets();
132 
133         //!
134         //! \brief  Free resources
135         //! \return MOS_STATUS
136         //!         MOS_STATUS_SUCCESS if success, else fail reason
137         //!
138         MOS_STATUS FreeResources();
139 
140 #if USE_CODECHAL_DEBUG_TOOL
141         //!
142         //! \brief  Dump resources
143         //! \return MOS_STATUS
144         //!         MOS_STATUS_SUCCESS if success, else fail reason
145         //!
146         MOS_STATUS DumpResources() const;
147 #endif
148 
149         //!
150         //! \brief    Calculate picture state command size
151         //!
152         //! \return   MOS_STATUS
153         //!           MOS_STATUS_SUCCESS if success, else fail reason
154         //!
155         MOS_STATUS CalculatePictureStateCommandSize();
156 
157         // VVCP MHW functions
158         MOS_STATUS AddAllCmds_VVCP_PIPE_MODE_SELECT(MOS_COMMAND_BUFFER &cmdBuffer);
159         MOS_STATUS AddAllCmds_VVCP_SURFACE_STATE(MOS_COMMAND_BUFFER &cmdBuffer);
160 
161         MHW_SETPAR_DECL_HDR(VVCP_VD_CONTROL_STATE);
162         MHW_SETPAR_DECL_HDR(VVCP_PIPE_MODE_SELECT);
163         MHW_SETPAR_DECL_HDR(VVCP_SURFACE_STATE);
164         MHW_SETPAR_DECL_HDR(VVCP_PIPE_BUF_ADDR_STATE);
165         MHW_SETPAR_DECL_HDR(VVCP_IND_OBJ_BASE_ADDR_STATE);
166         MHW_SETPAR_DECL_HDR(VVCP_PIC_STATE);
167         MHW_SETPAR_DECL_HDR(VVCP_DPB_STATE);
168 
169         //Interfaces
170         VvcPipeline             *m_vvcPipeline     = nullptr;
171         VvcBasicFeature         *m_vvcBasicFeature = nullptr;
172         DecodeAllocator         *m_allocator       = nullptr;
173         DecodeMemComp           *m_mmcState        = nullptr;
174         CodecVvcPicParams       *m_vvcPicParams    = nullptr;
175         MOS_SURFACE             m_refSurface[vvcMaxNumRefFrame];
176         std::shared_ptr<Itf>    m_vvcpItf          = nullptr;
177         CodechalHwInterfaceNext* m_hwInterface      = nullptr;
178 
179         //Internal buffers
180         BufferArray             *m_alfBufferArray           = nullptr;
181         BufferArray             *m_scalingListBufferArray   = nullptr;
182         PMOS_BUFFER             m_apsAlfBuffer              = nullptr;
183         PMOS_BUFFER             m_apsScalingListBuffer      = nullptr;
184         BufferArray             *m_chromaQpBufferArray      = nullptr;
185         PMOS_BUFFER             m_chromaQpBuffer            = nullptr;
186         PMOS_BUFFER             m_vcedLineBuffer            = nullptr;
187         PMOS_BUFFER             m_vcmvLineBuffer            = nullptr;
188         PMOS_BUFFER             m_vcprLineBuffer            = nullptr;
189         PMOS_BUFFER             m_vclfYLineBuffer           = nullptr;
190         PMOS_BUFFER             m_vclfYTileRowBuffer        = nullptr;
191         PMOS_BUFFER             m_vclfYTileColumnBuffer     = nullptr;
192         PMOS_BUFFER             m_vclfULineBuffer           = nullptr;
193         PMOS_BUFFER             m_vclfUTileRowBuffer        = nullptr;
194         PMOS_BUFFER             m_vclfUTileColumnBuffer     = nullptr;
195         PMOS_BUFFER             m_vclfVLineBuffer           = nullptr;
196         PMOS_BUFFER             m_vclfVTileRowBuffer        = nullptr;
197         PMOS_BUFFER             m_vclfVTileColumnBuffer     = nullptr;
198         PMOS_BUFFER             m_vcSaoYLineBuffer          = nullptr;
199         PMOS_BUFFER             m_vcSaoYTileRowBuffer       = nullptr;
200         PMOS_BUFFER             m_vcSaoYTileColumnBuffer    = nullptr;
201         PMOS_BUFFER             m_vcSaoULineBuffer          = nullptr;
202         PMOS_BUFFER             m_vcSaoUTileRowBuffer       = nullptr;
203         PMOS_BUFFER             m_vcSaoUTileColumnBuffer    = nullptr;
204         PMOS_BUFFER             m_vcSaoVLineBuffer          = nullptr;
205         PMOS_BUFFER             m_vcSaoVTileRowBuffer       = nullptr;
206         PMOS_BUFFER             m_vcSaoVTileColumnBuffer    = nullptr;
207         PMOS_BUFFER             m_vcAlfLineBuffer           = nullptr;
208         PMOS_BUFFER             m_vcAlfTileRowBuffer        = nullptr;
209         PMOS_BUFFER             m_vcAlfYTileColumnBuffer    = nullptr;
210         PMOS_BUFFER             m_vcAlfUTileColumnBuffer    = nullptr;
211         PMOS_BUFFER             m_vcAlfVTileColumnBuffer    = nullptr;
212 
213         uint32_t                m_prevFrmWidth              = 0;    //!< Frame width of the previous frame
214         uint32_t                m_prevFrmHeight             = 0;    //!< Frame height of the previous frame
215         uint32_t                m_pictureStatesSize         = 0;    //!< Picture states size
216         uint32_t                m_picturePatchListSize      = 0;    //!< Picture patch list size
217         mutable uint8_t         m_curVvcpSurfStateId        = 0;
218 
219         BatchBufferArray        *m_picLevelBBArray     = nullptr;   //!< Point to picture level batch buffer
220         PMHW_BATCH_BUFFER       m_curPicLvlBatchBuffer = nullptr;
221 
222     MEDIA_CLASS_DEFINE_END(decode__VvcDecodePicPkt)
223     };
224 
225 }  // namespace decode
226 
227 #endif
228