1 /*
2 * Copyright (c) 2020, 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_filmgrain_gennoise_grv_packet_g12.h
24 //! \brief    Defines the implementation of av1 decode film grain get random values kernel packet
25 //!
26 
27 #ifndef __DECODE_FILMGRAIN_GENNOISE_GRV_PACKET_G12_H__
28 #define __DECODE_FILMGRAIN_GENNOISE_GRV_PACKET_G12_H__
29 
30 #include "media_render_cmd_packet.h"
31 #include "decode_av1_pipeline_g12_base.h"
32 #include "decode_av1_filmgrain_feature_g12.h"
33 
34 namespace decode
35 {
36 
37 //Curbe definitions
38 struct FilmGrainGetRandomValuesCurbe
39 {
40     // uint32_t 0
41     union
42     {
43         struct
44         {
45             uint32_t GaussianSeqSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
46         };
47         struct
48         {
49             uint32_t Value;
50         };
51     } DW0;
52 
53     // uint32_t 1
54     union
55     {
56         struct
57         {
58             uint32_t YRandomValuesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
59         };
60         struct
61         {
62             uint32_t Value;
63         };
64     } DW1;
65 
66     // uint32_t 2
67     union
68     {
69         struct
70         {
71             uint32_t URandomValuesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
72         };
73         struct
74         {
75             uint32_t Value;
76         };
77     } DW2;
78 
79     // uint32_t 3
80     union
81     {
82         struct
83         {
84             uint32_t VRandomValuesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);
85         };
86         struct
87         {
88             uint32_t Value;
89         };
90     } DW3;
91 
92     // uint32_t 4
93     union
94     {
95         struct
96         {
97             uint32_t CoordinatesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31);  //Random values for coordinates surface index
98         };
99         struct
100         {
101             uint32_t Value;
102         };
103     } DW4;
104 
105     // uint32_t 5
106     union
107     {
108         struct
109         {
110             uint32_t NoiseShiftAmount : MOS_BITFIELD_RANGE(0, 15);
111             uint32_t Reserved : MOS_BITFIELD_RANGE(16, 31);
112         };
113         struct
114         {
115             uint32_t Value;
116         };
117     } DW5;
118 
119     // uint32_t 6
120     union
121     {
122         struct
123         {
124             uint32_t GrainSeed : MOS_BITFIELD_RANGE(0, 31);  //Random number generation initializer
125         };
126         struct
127         {
128             uint32_t Value;
129         };
130     } DW6;
131 
132     // uint32_t 7
133     union
134     {
135         struct
136         {
137             uint32_t CoordinatesWidth : MOS_BITFIELD_RANGE(0, 15);    //RoundUp(ImageHeight/64)
138             uint32_t CoordinatesHeight : MOS_BITFIELD_RANGE(16, 31);  //RoundUp(ImageWidth/64)
139         };
140         struct
141         {
142             uint32_t Value;
143         };
144     } DW7;
145 
146     static const size_t m_size     = 8;
147     static const size_t m_byteSize = 32;
148 };
149 C_ASSERT(sizeof(FilmGrainGetRandomValuesCurbe) == 32);
150 
151 // Binding Table Definitions
152 //!
153 //! \enum     FilmGrainGetRandomValuesBindingTableOffset
154 //! \brief    Binding table offset for GetRandomValues kernel
155 //!
156 enum FilmGrainGetRandomValuesBindingTableOffset
157 {
158     grvInputGaussianSeq = 0,
159     grvOutputYRandomValue,
160     grvOutputURandomValue,
161     grvOutputVRandomValue,
162     grvOutputCoordinates,
163     grvNumSurfaces
164 };
165 
166 enum FilmGrainKernelStateIdx;
167 
168 class FilmGrainGrvPacket : public RenderCmdPacket
169 {
170 public:
171     FilmGrainGrvPacket(MediaPipeline *pipeline, MediaTask *task, CodechalHwInterface *hwInterface);
172 
~FilmGrainGrvPacket()173     virtual ~FilmGrainGrvPacket(){};
174 
175     MOS_STATUS Prepare() override;
176     MOS_STATUS Submit(MOS_COMMAND_BUFFER *commandBuffer, uint8_t packetPhase) override;
177     MOS_STATUS Initilize();
178 
179     virtual MOS_STATUS Init() override;
180 
GetPacketName()181     virtual std::string GetPacketName() override
182     {
183         return "AV1_DECODE_FilmGrainGrv";
184     }
185 
186     //!
187     //! \brief  Calculate Command Size
188     //!
189     //! \param  [in, out] commandBufferSize
190     //!         requested size
191     //! \param  [in, out] requestedPatchListSize
192     //!         requested size
193     //! \return MOS_STATUS
194     //!         status
195     //!
196     MOS_STATUS CalculateCommandSize(uint32_t &commandBufferSize, uint32_t &requestedPatchListSize) override;
197     MOS_STATUS SetCurbeGetRandomValues();
198 
199 protected:
200     MOS_STATUS KernelStateSetup();
201     MOS_STATUS SetUpSurfaceState();
202     virtual MOS_STATUS SetupMediaWalker() override;
203 
204 protected:
205     int32_t             m_kernelIndex   = getRandomValues;
206     Kdll_FilterEntry*   m_filter        = nullptr;          // Kernel Filter (points to base of filter array)
207 
208     MediaFeatureManager    *m_featureManager   = nullptr;
209     Av1PipelineG12_Base    *m_av1Pipeline      = nullptr;
210     DecodeAllocator        *m_allocator        = nullptr;
211     PMOS_INTERFACE          m_osInterface      = nullptr;
212     Av1BasicFeatureG12     *m_av1BasicFeature  = nullptr;
213     Av1DecodeFilmGrainG12  *m_filmGrainFeature = nullptr;
214     MhwVdboxVdencInterface *m_vdencInterface   = nullptr;
215     CodechalHwInterface    *m_hwInterface      = nullptr;
216     DecodeMemComp          *m_mmcState         = nullptr;
217     const CodecAv1PicParams *m_picParams = nullptr;  //!< Pointer to picture parameter
218 
219     uint32_t m_bindingTableIndex[grvNumSurfaces] = {
220         grvInputGaussianSeq,
221         grvOutputYRandomValue,
222         grvOutputURandomValue,
223         grvOutputVRandomValue,
224         grvOutputCoordinates
225     };
226 MEDIA_CLASS_DEFINE_END(decode__FilmGrainGrvPacket)
227 };
228 }
229 
230 #endif
231