1 /*
2 * Copyright (c) 2020-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     encode_vp9_hpu_packet.h
24 //! \brief    Defines the interface for HPU (header's probability update) packet for VP9
25 //!
26 
27 #ifndef __ENCODE_VP9_HPU_PACKET_H__
28 #define __ENCODE_VP9_HPU_PACKET_H__
29 
30 #include "encode_huc.h"
31 #include "encode_vp9_basic_feature.h"
32 #include "encode_vp9_brc.h"
33 
34 namespace encode
35 {
36 #define CODECHAL_ENCODE_VP9_HUC_SUPERFRAME_PASS 2
37 #define CODECHAL_ENCODE_VP9_BRC_SUPER_FRAME_BUFFER_SIZE MOS_ALIGN_CEIL(3 + 2 * sizeof(uint32_t), sizeof(uint32_t))
38 #define CODECHAL_ENCODE_VP9_REF_SEGMENT_DISABLED 0xFF
39 
40 class Vp9HpuPkt : public EncodeHucPkt
41 {
42 public:
43     //!
44     //! \brief  Vp9HucProbPkt constructor
45     //! \param  [in] pipeline
46     //!         Pointer to the media pipeline
47     //! \param  [in] task
48     //!         Pointer to media task
49     //! \param  [in] hwInterface
50     //!         Pointer to HW interface
51     //!
Vp9HpuPkt(MediaPipeline * pipeline,MediaTask * task,CodechalHwInterfaceNext * hwInterface)52     Vp9HpuPkt(MediaPipeline *pipeline, MediaTask *task, CodechalHwInterfaceNext *hwInterface)
53         : EncodeHucPkt(pipeline, task, hwInterface) {}
54 
55     //!
56     //! \brief  Vp9HucProbPkt destructor
57     //!
~Vp9HpuPkt()58     virtual ~Vp9HpuPkt() {}
59 
60     //!
61     //! \brief  Initialize the media packet, allocate required resources
62     //! \return MOS_STATUS
63     //!         MOS_STATUS_SUCCESS if success, else fail reason
64     //!
65     virtual MOS_STATUS Init() override;
66 
67     //!
68     //! \brief  Add the command sequence into the commandBuffer and
69     //!         and return to the caller task
70     //! \param  [in] commandBuffer
71     //!         Pointer to the command buffer which is allocated by caller
72     //! \param  [in] packetPhase
73     //!         Indicate packet phase stage
74     //! \return MOS_STATUS
75     //!         MOS_STATUS_SUCCESS if success, else fail reason
76     //!
77     MOS_STATUS Submit(MOS_COMMAND_BUFFER *commandBuffer, uint8_t packetPhase = otherPacket) override;
78 
79     //!
80     //! \brief  Patch hpu command sequence into the commandBuffer and
81     //!         and return to the caller task
82     //! \param  [in] commandBuffer
83     //!         Pointer to the command buffer which is allocated by caller
84     //! \param  [in] packetPhase
85     //!         Indicate packet phase stage
86     //! \return MOS_STATUS
87     //!         MOS_STATUS_SUCCESS if success, else fail reason
88     //!
89     MOS_STATUS PatchHucProbCommands(MOS_COMMAND_BUFFER *commandBuffer, uint8_t packetPhase = otherPacket);
90 
91     //!
92     //! \brief  Calculate Command Size
93     //! \param  [in, out] commandBufferSize
94     //!         requested size
95     //! \param  [in, out] requestedPatchListSize
96     //!         requested size
97     //! \return MOS_STATUS
98     //!         status
99     //!
100     virtual MOS_STATUS CalculateCommandSize(
101         uint32_t &commandBufferSize,
102         uint32_t &requestedPatchListSize) override;
103 
104     //!
105     //! \brief  Dump output resources or infomation after submit
106     //! \return MOS_STATUS
107     //!         MOS_STATUS_SUCCESS if success, else fail reason
108     //!
109     virtual MOS_STATUS DumpOutput() override;
110 
111     //!
112     //! \brief  Get Packet Name
113     //! \return std::string
114     //!
GetPacketName()115     virtual std::string GetPacketName() override
116     {
117         return (m_superFrameHucPass ? "HPU_SuperFramePass" : "HPU_Pass") + std::to_string((uint32_t)m_pipeline->GetCurrentPass());
118     }
119 
120     //!
121     //! \brief  Set super frame huc pass on/off
122     //! \param  [in, out] superFrameHucPass
123     //!         Super frame huc pass flag
124     //! \return MOS_STATUS
125     //!         MOS_STATUS_SUCCESS if success, else fail reason
126     //!
SetSuperFrameHucPass(bool superFrameHucPass)127     MOS_STATUS SetSuperFrameHucPass(bool superFrameHucPass)
128     {
129         m_superFrameHucPass = superFrameHucPass;
130         return MOS_STATUS_SUCCESS;
131     }
132 
133     MHW_SETPAR_DECL_HDR(HUC_IMEM_STATE);
134     MHW_SETPAR_DECL_HDR(HUC_DMEM_STATE);
135     MHW_SETPAR_DECL_HDR(HUC_VIRTUAL_ADDR_STATE);
136 
137 protected:
138     //!
139     //! \brief  Allocate resources
140     //! \return MOS_STATUS
141     //!         MOS_STATUS_SUCCESS if success, else fail reason
142     //!
143     virtual MOS_STATUS AllocateResources() override;
144 
145 public:
146     //!
147     //! \brief  Set huc dmem buffer
148     //! \return MOS_STATUS
149     //!         MOS_STATUS_SUCCESS if success, else fail reason
150     //!
151     virtual MOS_STATUS SetDmemBuffer() const;
152 
153     //!
154     //! \brief      Get reference buffer slot index
155     //! \param      [in] refreshFlags
156     //!             Refresh flags
157     //! \return     uint8_t
158     //!             Return 0 if call success, else -1 if fail
159     //!
160     uint8_t GetReferenceBufferSlotIndex(
161         uint8_t refreshFlags) const;
162 
163  protected:
164 
165  #if USE_CODECHAL_DEBUG_TOOL
166     //!
167     //! \brief  Dump input resources or infomation after submit
168     //! \return MOS_STATUS
169     //!         MOS_STATUS_SUCCESS if success, else fail reason
170     //!
171     virtual MOS_STATUS DumpInput() override;
172 #endif
173 
174     static constexpr uint32_t m_vdboxHucVp9VdencProbKernelDescriptor = 13;  //!< VDBox Huc VDEnc prob kernel descriptor
175 
176     Vp9BasicFeature *m_basicFeature = nullptr;  //!< VP9 Basic Feature used in each frame
177 
178     MOS_RESOURCE m_resHucDefaultProbBuffer = {};
179     bool         m_superFrameHucPass = false;  //!< Huc super frame pass enable/disabl flags
180 
181  MEDIA_CLASS_DEFINE_END(encode__Vp9HpuPkt)
182 };
183 
184 }  // namespace encode
185 
186 #endif
187