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_slice_packet.h
24 //! \brief    Defines the implementation of VVC decode slice packet
25 //!
26 
27 #ifndef __DECODE_VVC_TILE_PACKET_H__
28 #define __DECODE_VVC_TILE_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 "mhw_vdbox_vvcp_itf.h"
35 
36 using namespace mhw::vdbox::vvcp;
37 
38 namespace decode
39 {
40 class VvcDecodeSlicePkt : public DecodeSubPacket, public Itf::ParSetting
41 {
42 public:
VvcDecodeSlicePkt(VvcPipeline * pipeline,CodechalHwInterfaceNext * hwInterface)43     VvcDecodeSlicePkt(VvcPipeline *pipeline, CodechalHwInterfaceNext *hwInterface)
44         : DecodeSubPacket(pipeline, hwInterface), m_vvcPipeline(pipeline)
45     {
46         if (hwInterface != nullptr)
47         {
48             m_hwInterface = dynamic_cast<CodechalHwInterfaceNext *>(hwInterface);
49             if (m_hwInterface != nullptr)
50             {
51                 m_vvcpItf     = std::static_pointer_cast<mhw::vdbox::vvcp::Itf>(m_hwInterface->GetVvcpInterfaceNext());
52             }
53         }
54     }
~VvcDecodeSlicePkt()55     virtual ~VvcDecodeSlicePkt(){};
56 
57     //!
58     //! \brief  Initialize the media packet, allocate required resources
59     //! \return MOS_STATUS
60     //!         MOS_STATUS_SUCCESS if success, else fail reason
61     //!
62     virtual MOS_STATUS Init() override;
63 
64     //!
65     //! \brief  Prepare interal parameters, should be invoked for each frame
66     //! \return MOS_STATUS
67     //!         MOS_STATUS_SUCCESS if success, else fail reason
68     //!
69     virtual MOS_STATUS Prepare() override;
70 
71     //!
72     //! \brief  Execute VVC tile packet
73     //! \return MOS_STATUS
74     //!         MOS_STATUS_SUCCESS if success, else fail reason
75     //!
76     MOS_STATUS Execute(MOS_COMMAND_BUFFER& cmdBuffer, uint16_t tileIdx);
77 
78     //!
79     //! \brief  Calculate Command Size
80     //!
81     //! \param  [in, out] commandBufferSize
82     //!         requested size
83     //! \param  [in, out] requestedPatchListSize
84     //!         requested size
85     //! \return MOS_STATUS
86     //!         status
87     //!
88     MOS_STATUS CalculateCommandSize(
89         uint32_t &commandBufferSize,
90         uint32_t &requestedPatchListSize) override;
91 
92     //!
93     //! \brief  Calculate Command Size
94     //!
95     //! \param  [in, out] commandBufferSize
96     //!         requested size
97     //! \param  [in, out] requestedPatchListSize
98     //!         requested size
99     //! \return MOS_STATUS
100     //!         status
101     //!
102     MOS_STATUS CalculateTileCommandSize(
103         uint32_t &commandBufferSize,
104         uint32_t &requestedPatchListSize);
105 
106 protected:
107     virtual MOS_STATUS CalcRefIdxSymLx(int8_t& RefIdxSymL0, int8_t& RefIdxSymL1);
108     virtual MOS_STATUS ConstructLmcsReshaper() const;
109     virtual MOS_STATUS SetRefIdxStateParams();
110 
111     bool IsTileInRasterSlice(const uint32_t tileRow, const uint32_t tileCol) const;
112 
113     //!
114     //! \brief  Calculate tile level command Buffer Size
115     //!
116     //! \return uint32_t
117     //!         Command buffer size calculated
118     //!
119     virtual MOS_STATUS CalculateSliceStateCommandSize();
120 
121     //!
122     //! \brief  Get partition info for the current slice
123     //!
124     //! \return MOS_STATUS
125     //!         status
126     //!
127     MOS_STATUS GetPartitionInfo(uint16_t sliceIdx);
128 
129     // VVCP MHW functions
130     MOS_STATUS AddAllCmds_VVCP_REF_IDX_STATE(MOS_COMMAND_BUFFER &cmdBuffer);
131     MOS_STATUS AddAllCmds_VVCP_WEIGHTOFFSET_STATE(MOS_COMMAND_BUFFER &cmdBuffer);
132     MOS_STATUS AddAllCmds_VVCP_TILE_CODING(MOS_COMMAND_BUFFER &cmdBuffer);
133 
134     MHW_SETPAR_DECL_HDR(VVCP_SLICE_STATE);
135     MHW_SETPAR_DECL_HDR(VVCP_BSD_OBJECT);
136     MHW_SETPAR_DECL_HDR(VVCP_TILE_CODING);
137 
138     VvcPipeline *            m_vvcPipeline     = nullptr;
139     std::shared_ptr<Itf>     m_vvcpItf         = nullptr;
140     VvcBasicFeature *        m_vvcBasicFeature = nullptr;
141     DecodeAllocator *        m_allocator       = nullptr;
142     DecodeSubPacket *        m_vvcCpSubPkt     = nullptr;       //!< Pointer to VVC CP packet
143     CodechalHwInterfaceNext  *m_hwInterface     = nullptr;
144 
145     // Parameters passed from application
146     CodecVvcPicParams               *m_vvcPicParams   = nullptr;      //!< Pointer to VVC picture parameter
147     CodecVvcSliceParams             *m_curSliceParams = nullptr;      //!< Pointer to current VVC slice parameter
148     int16_t                         m_numTilesInSlice = 0;            //!< Number of tiles in the current slice
149 
150     //Internal params
151     //Current Slice params
152     SliceDescriptor                 *m_sliceDesc     = nullptr;       //slice descriptor for the current slice
153     bool                            m_lastSliceOfPic = false;
154 
155     //Current SubPic
156     CodecVvcSubpicParam             *m_subPicParams  = nullptr;
157 
158     uint32_t m_sliceStatesSize      = 0;  //!< Slice state command size
159     uint32_t m_slicePatchListSize   = 0;  //!< Slice patch list size
160     uint32_t m_tileStateSize        = 0;  //!< Tile state command size
161     uint32_t m_tilePatchListSize    = 0;  //!< Tile patch list size
162     int16_t  m_curTileIdx           = 0;  //!< Current tile idx
163 
164 
165 MEDIA_CLASS_DEFINE_END(decode__VvcDecodeSlicePkt)
166 };
167 
168 }  // namespace decode
169 
170 #endif
171