1 /*
2 * Copyright (c) 2020-2021, 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_avc_vdenc_stream_in_feature.h
24 //! \brief    Defines the common feature interface for encode AVC VDEnc Stream-in
25 //!
26 #ifndef __ENCODE_AVC_VDENC_STREAM_IN_FEATURE_H__
27 #define __ENCODE_AVC_VDENC_STREAM_IN_FEATURE_H__
28 
29 #include "codechal_debug.h"
30 #include "encode_allocator.h"
31 #include "encode_avc_basic_feature.h"
32 #include "mhw_vdbox_vdenc_itf.h"
33 
34 namespace encode
35 {
36 struct AvcVdencStreamInState
37 {
38     union
39     {
40         //!< DWORD 0
41         struct
42         {
43             uint32_t RegionOfInterestSelection : MOS_BITFIELD_RANGE(0, 7);   //!< Region of Interest (ROI) Selection
44             uint32_t ForceIntra                : MOS_BITFIELD_RANGE(8, 8);   //!< ForceIntra
45             uint32_t ForceSkip                 : MOS_BITFIELD_RANGE(9, 9);   //!< ForceSkip
46             uint32_t Reserved22                : MOS_BITFIELD_RANGE(10, 31); //!< Reserved
47         };
48         uint32_t Value;
49     } DW0;
50     union
51     {
52         //!< DWORD 1
53         struct
54         {
55             uint32_t QpPrimeY         : MOS_BITFIELD_RANGE(0, 7);   //!< QpPrimeY
56             uint32_t TargetSizeInWord : MOS_BITFIELD_RANGE(8, 15);  //!< TargetSizeInWord
57             uint32_t MaxSizeInWord    : MOS_BITFIELD_RANGE(16, 23); //!< MaxSizeInWord
58             uint32_t Reserved8        : MOS_BITFIELD_RANGE(24, 31); //!< Reserved
59         };
60         uint32_t Value;
61     } DW1;
62     union
63     {
64         //!< DWORD 2
65         struct
66         {
67             uint32_t FwdPredictorX : MOS_BITFIELD_RANGE(0, 15);  //!< Fwd Predictor.X
68             uint32_t FwdPredictorY : MOS_BITFIELD_RANGE(16, 31); //!< Fwd Predictor.Y
69         };
70         uint32_t Value;
71     } DW2;
72     union
73     {
74         //!< DWORD 3
75         struct
76         {
77             uint32_t BwdPredictorX : MOS_BITFIELD_RANGE(0, 15);  //!< Bwd Predictor.X
78             uint32_t BwdPredictorY : MOS_BITFIELD_RANGE(16, 31); //!< Bwd Predictor.Y
79         };
80         uint32_t Value;
81     } DW3;
82     union
83     {
84         //!< DWORD 4
85         struct
86         {
87             uint32_t FwdRefId0   : MOS_BITFIELD_RANGE(0, 3);  //!< Fwd RefID0
88             uint32_t BwdRefId0   : MOS_BITFIELD_RANGE(4, 7);  //!< Bwd RefID0
89             uint32_t Reserved24  : MOS_BITFIELD_RANGE(8, 31); //!< Reserved
90         };
91         uint32_t Value;
92     } DW4;
93 
94     uint32_t Reserved11[11];  //!< Reserved
95 
AvcVdencStreamInStateAvcVdencStreamInState96     AvcVdencStreamInState()
97     {
98         ENCODE_ASSERT(AvcVdencStreamInState::byteSize == CODECHAL_CACHELINE_SIZE);
99 
100         DW0.Value = 0;
101         DW1.Value = 0;
102         DW2.Value = 0;
103         DW3.Value = 0;
104         DW4.Value = 0;
105         MOS_ZeroMemory(&Reserved11, sizeof(Reserved11));
106     }
107 
108     static const size_t byteSize;
109 };
110 
111 
112 class AvcVdencStreamInFeature : public MediaFeature, public mhw::vdbox::vdenc::Itf::ParSetting, public mhw::vdbox::huc::Itf::ParSetting
113 {
114 public:
115     //!
116     //! \brief  AvcVDEncStreamIn constructor
117     //!
118     AvcVdencStreamInFeature(
119         MediaFeatureManager* featureManager,
120         EncodeAllocator* allocator,
121         CodechalHwInterfaceNext *hwInterface,
122         void* constSettings);
123 
124     //!
125     //! \brief  AvcVDEncStreamIn destructor
126     //!
127     virtual ~AvcVdencStreamInFeature();
128 
129     //!
130     //! \brief  Init AVC VDEnc Stream-in instance
131     //! \param  [in] basicFeature
132     //!         Pointer to basic feature
133     //! \param  [in] allocator
134     //!         Pointer to allocator
135     //! \return MOS_STATUS
136     //!         MOS_STATUS_SUCCESS if success, else fail reason
137     //!
138     virtual MOS_STATUS Init(void* setting) override;
139 
140     //!
141     //! \brief  Update VDEnc Stream-in buffer for each frame
142     //! \return MOS_STATUS
143     //!         MOS_STATUS_SUCCESS if success, else fail reason
144     //!
145     virtual MOS_STATUS Update(void* setting) override;
146 
147     //!
148     //! \brief  Get VDEnc Stream-in buffer base locked addrress
149     //! \return AvcVdencStreamInState*
150     //!         pointer to stream in buffer locked address
151     //!
152     virtual AvcVdencStreamInState* Lock();
153 
154     //!
155     //! \brief  Unlock VDEnc Stream-in buffer base locked addrress
156     //! \return MOS_STATUS
157     //!         MOS_STATUS_SUCCESS if success, else fail reason
158     //!
159     virtual MOS_STATUS Unlock();
160 
161     //!
162     //! \brief  Enable VDEnc Stream-in feature
163     //!         Should be called only if VDEnc Stream-in will be used
164     //!
165     MOS_STATUS Enable();
166 
167     //!
168     //! \brief  Reset VDEnc Stream-in after frame programming is done
169     //!
170     void Reset();
171 
172     //!
173     //! \brief  Clear VDEnc Stream-in buffer data
174     //!
175     MOS_STATUS Clear();
176 
177 #if USE_CODECHAL_DEBUG_TOOL
178     MOS_STATUS Dump(CodechalDebugInterface *itf, const char* bufName);
179 #endif
180 
181     MHW_SETPAR_DECL_HDR(VDENC_PIPE_BUF_ADDR_STATE);
182 
183     MHW_SETPAR_DECL_HDR(VDENC_PIPE_MODE_SELECT);
184 
185     MHW_SETPAR_DECL_HDR(VDENC_AVC_IMG_STATE);
186 
187     MHW_SETPAR_DECL_HDR(HUC_VIRTUAL_ADDR_STATE);
188 
189 protected:
190 
191     CodechalHwInterfaceNext *m_hwInterface    = nullptr;
192     AvcBasicFeature     *m_basicFeature   = nullptr;  //!< AVC paramter
193     EncodeAllocator     *m_allocator      = nullptr;  //!< Encode allocator
194     PMOS_RESOURCE        m_streamInBuffer = nullptr;  //!< Stream in buffer
195 
196     bool     m_updated     = false;  //!< Indicate stream in buffer updated
197     bool     m_enabled     = false;  //!< Indicate stream in enabled for current frame or not
198     uint32_t m_widthInMb   = 0;
199     uint32_t m_heightInMb  = 0;
200 
201 MEDIA_CLASS_DEFINE_END(encode__AvcVdencStreamInFeature)
202 };
203 
204 }  // namespace encode
205 
206 #endif  // !__ENCODE_AVC_VDENC_STREAM_IN_FEATURE_H__
207