Debian Codegraph @

media_driver/agnostic/common/codec/hal/codechal_decode_downsampling.h

raw
1 /*
2 * Copyright (c) 2014-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 codechal_decode_downsampling.h
24 //! \brief Defines the decode interface extension for field downsampling.
25 //! \details Downsampling in this case is supported by EU kernels.
26 //!
27
28 #ifndef __CODECHAL_DECODER_DOWNSAMPLING_H__
29 #define __CODECHAL_DECODER_DOWNSAMPLING_H__
30
31 #include "mos_os.h"
32 #include "mhw_state_heap.h"
33 #include "codechal_mmc.h"
34
35 struct DecodeProcessingParams;
36
37 //!
38 //! \class MediaWalkerFieldScalingStaticData
39 //! \brief This class defines the member fields, functions etc. for Media Walker Static Data used by Field Downscaling Kernel.
40 //!
41 class MediaWalkerFieldScalingStaticData
42 {
43 public:
44 //!
45 //! \brief Constructor
46 //!
47 MediaWalkerFieldScalingStaticData();
48
49 //!
50 //! \brief Destructor
51 //!
52 ~MediaWalkerFieldScalingStaticData() {};
53
54 //!
55 //! \struct MediaWalkerData
56 //! \brief Media Walker Data bit definitions
57 //!
58 struct MediaWalkerData
59 {
60 // uint32_t 0 - GRF R1.0
61 union
62 {
63 // CSC
64 struct
65 {
66 uint32_t m_cscConstantC0 : 16;
67 uint32_t m_cscConstantC1 : 16;
68 };
69
70 uint32_t m_value;
71 } m_dword00;
72
73 // uint32_t 1 - GRF R1.1
74 union
75 {
76 // CSC
77 struct
78 {
79 uint32_t m_cscConstantC2 : 16;
80 uint32_t m_cscConstantC3 : 16;
81 };
82
83 uint32_t m_value;
84 } m_dword01;
85
86 // uint32_t 2 - GRF R1.2
87 union
88 {
89 // CSC
90 struct
91 {
92 uint32_t m_cscConstantC4 : 16;
93 uint32_t m_cscConstantC5 : 16;
94 };
95
96 uint32_t m_value;
97 } m_dword02;
98
99 // uint32_t 3 - GRF R1.3
100 union
101 {
102 // CSC
103 struct
104 {
105 uint32_t m_cscConstantC6 : 16;
106 uint32_t m_cscConstantC7 : 16;
107 };
108
109 uint32_t m_value;
110 } m_dword03;
111
112 // uint32_t 4 - GRF R1.4
113 union
114 {
115 // CSC
116 struct
117 {
118 uint32_t m_cscConstantC8 : 16;
119 uint32_t m_cscConstantC9 : 16;
120 };
121
122 uint32_t m_value;
123 } m_dword04;
124
125 // uint32_t 5 - GRF R1.5
126 union
127 {
128 // CSC
129 struct
130 {
131 uint32_t m_cscConstantC10 : 16;
132 uint32_t m_cscConstantC11 : 16;
133 };
134
135 uint32_t m_value;
136 } m_dword05;
137
138 // uint32_t 6 - GRF R1.6
139 uint32_t m_padConstantBlend;
140
141 // uint32_t 7 - GRF R1.7
142 union
143 {
144 struct
145 {
146 uint32_t m_reserved : 24;
147 uint32_t m_pointerToInlineParameters : 8;
148 };
149
150 uint32_t m_value;
151 } m_dword07;
152
153 // uint32_t 8 - GRF R2.0
154 union
155 {
156 struct
157 {
158 uint32_t m_destinationRectangleWidth : 16;
159 uint32_t m_destinationRectangleHeight : 16;
160 };
161
162 uint32_t m_value;
163 } m_dword08;
164
165 // uint32_t 9 - GRF R2.1
166 union
167 {
168 struct
169 {
170 uint32_t m_reserved0 : 27;
171 uint32_t m_iefByPassEnable : 1;
172 uint32_t m_reserved1 : 4;
173 };
174
175 uint32_t m_value;
176 } m_dword09;
177
178 // uint32_t 10 - GRF R2.2
179 union
180 {
181 struct
182 {
183 uint32_t m_reserved0 : 24;
184 uint32_t m_chromaSitingLocation : 3;
185 uint32_t m_reserved1 : 5;
186 };
187
188 uint32_t m_value;
189 } m_dword10;
190
191 // uint32_t 11 - 13 - GRF R2.3 - 2.5
192 uint32_t m_pad0[3];
193
194 // uint32_t 14 - GRF R2.6
195 union
196 {
197 // Lumakey, NLAS
198 struct
199 {
200 uint32_t m_lumakeyLowThreshold : 8;
201 uint32_t m_lumakeyHighThreshold : 8;
202 uint32_t m_nlasEnable : 8;
203 uint32_t m_reserved : 8;
204 };
205
206 uint32_t m_value;
207 } m_dword14;
208
209 // uint32_t 15 - GRF R2.7
210 union
211 {
212 // Save
213 struct
214 {
215 uint8_t m_destinationPackedYOffset;
216 uint8_t m_destinationPackedUOffset;
217 uint8_t m_destinationPackedVOffset;
218 uint8_t m_destinationRGBFormat;
219 };
220
221 uint32_t m_value;
222 } m_dword15;
223
224 // uint32_t 16 - GRF R3.0
225 union
226 {
227 // Sampler Load
228 struct
229 {
230 float m_horizontalScalingStepRatioLayer0;
231 };
232
233 uint32_t m_value;
234 } m_dword16;
235
236 // uint32_t 17 - 23 - GRF R3.1 - R3.7
237 uint32_t m_pad1[7];
238
239 // uint32_t 24 - GRF R4.0
240 union
241 {
242 // Sampler Load
243 struct
244 {
245 float m_verticalScalingStepRatioLayer0;
246 };
247
248 // Dataport Load
249 struct
250 {
251 uint8_t m_sourcePackedYOffset;
252 uint8_t m_sourcePackedUOffset;
253 uint8_t m_sourcePackedVOffset;
254 uint8_t m_reserved;
255 };
256
257 uint32_t m_value;
258 } m_dword24;
259
260 // uint32_t 25 - 31 - GRF R4.1 - R4.7
261 uint32_t m_pad2[7];
262
263 // uint32_t 32 - GRF R5.0
264 union
265 {
266 // Sampler Load
267 struct
268 {
269 float m_verticalFrameOriginLayer0;
270 };
271
272 uint32_t m_value;
273 } m_dword32;
274
275 // uint32_t 33 - 39 - GRF R5.1 - R5.7
276 uint32_t m_pad3[7];
277
278 // uint32_t 40 - GRF R6.0
279 union
280 {
281 // Sampler Load
282 struct
283 {
284 float m_horizontalFrameOriginLayer0;
285 };
286
287 uint32_t m_value;
288 } m_dword40;
289
290 // uint32_t 41 - 47 - GRF R6.1 - R6.7
291 uint32_t m_pad4[7];
292
293 // uint32_t 48 - GRF R7.0
294 union
295 {
296 struct
297 {
298 uint32_t m_destXTopLeftLayer0 : 16;
299 uint32_t m_destYTopLeftLayer0 : 16;
300 };
301
302 uint32_t m_value;
303 } m_dword48;
304
305 // uint32_t 49 - 55 - GRF R7.1 - R7.7
306 uint32_t m_pad5[7];
307
308 // uint32_t 56 - GRF R8.0
309 union
310 {
311 struct
312 {
313 uint32_t m_destXBottomRightLayer0 : 16;
314 uint32_t m_destYBottomRightLayer0 : 16;
315 };
316
317 uint32_t m_value;
318 } m_dword56;
319
320 // uint32_t 57 - 63 - GRF R8.1
321 uint32_t m_pad6[7];
322
323 // uint32_t 64 - GRF R9.0
324 union
325 {
326 struct
327 {
328 float m_mainVideoXScalingStepLeft;
329 };
330
331 uint32_t m_value;
332 } m_dword64;
333
334 // DWORD65 - GRF R9.1
335 union
336 {
337 struct
338 {
339 float m_videoStepDeltaForNonLinearRegion;
340 };
341
342 uint32_t m_value;
343 } m_dword65;
344
345 // DWORD66 - GRF R9.2
346 union
347 {
348 struct
349 {
350 uint32_t m_startofLinearScalingInPixelPositionC0 : 16;
351 uint32_t m_startofRHSNonLinearScalingInPixelPositionC1 : 16;
352 };
353
354 uint32_t m_value;
355 } m_dword66;
356
357 // uint32_t 67 - GRF R9.3
358 union
359 {
360 // Sampler Load
361 struct
362 {
363 float m_mainVideoXScalingStepCenter;
364 };
365
366 uint32_t m_value;
367 } m_dword67;
368
369 // uint32_t 68 - GRF R9.4
370 union
371 {
372 // Sampler Load
373 struct
374 {
375 float m_mainVideoXScalingStepRight;
376 };
377
378 uint32_t m_value;
379 } m_dword68;
380
381 // uint32_t 69-71 - Padding is needed as we program ConstantURBEntryReadLength = iCurbeLength >> 5
382 uint32_t m_pad[3];
383 } m_mediaWalkerData; //!< media walker data
384
385 static const size_t m_byteSize = sizeof(MediaWalkerData); //!< byte size of media walker data
386 };
387
388 //!
389 //! \class FieldScalingInterface
390 //! \brief This class defines the member fields, functions etc used by Field Downscaling interface.
391 //!
392 class FieldScalingInterface
393 {
394 public:
395 //!
396 //! \brief Copy constructor
397 //!
398 FieldScalingInterface(const FieldScalingInterface&) = delete;
399
400 //!
401 //! \brief Copy assignment operator
402 //!
403 FieldScalingInterface& operator=(const FieldScalingInterface&) = delete;
404
405 //!
406 //! \brief Destructor
407 //!
408 virtual ~FieldScalingInterface();
409
410 //!
411 //! \brief Check Field Scaling Supported
412 //! \details Check parameter legitimacy for field scaling
413 //! \param [in] procParams
414 //! Pointer to decode processing paramters #CODECHAL_DECODE_PROCESSING_PARAMS
415 //! \return bool
416 //! true if support, else false
417 //!
418 bool IsFieldScalingSupported(DecodeProcessingParams *procParams);
419
420 //!
421 //! \brief Initialize Field Scaling Kernel State
422 //! \details Initialize Field Scaling Kernel State & Params
423 //! \param [in] decoder
424 //! Pointer to decode interface
425 //! \param [in] hwInterface
426 //! Pointer to hardware interface
427 //! \param [in] osInterface
428 //! Pointer to OS interface
429 //! \return MOS_STATUS
430 //! MOS_STATUS_SUCCESS if success, else fail reason
431 //!
432 virtual MOS_STATUS InitializeKernelState(
433 CodechalDecode *decoder,
434 CodechalHwInterface *hwInterface,
435 PMOS_INTERFACE osInterface);
436
437 //!
438 //! \brief Send Media VFE cmds
439 //! \details Send Media VFE cmds to setup VFE for media kernel
440 //! \param [in] cmdBuffer
441 //! Pointer to command buffer
442 //! \param [in] kernelState
443 //! Pointer to MHW kernel state
444 //! \return MOS_STATUS
445 //! MOS_STATUS_SUCCESS if success, else fail reason
446 //!
447 virtual MOS_STATUS SetupMediaVfe(
448 PMOS_COMMAND_BUFFER cmdBuffer,
449 MHW_KERNEL_STATE *kernelState);
450
451 //!
452 //! \brief Initialize MMC state for specified downsampling device
453 //!
454 //! \return MOS_STATUS
455 //! MOS_STATUS_SUCCESS if success, else fail reason
456 //!
457 virtual MOS_STATUS InitMmcState();
458
459 //!
460 //! \brief Perform Field Scaling
461 //! \details Configure kernel regions to do field scaling
462 //! \param [in] procParams
463 //! Pointer to decode processing paramters #CODECHAL_DECODE_PROCESSING_PARAMS
464 //! \param [in] renderContext
465 //! The render context using for decode
466 //! \param [in] disableDecodeSyncLock
467 //! Disable decode sync lock
468 //! \param [in] disableLockForTranscode
469 //! Disable lock for transcode
470 //! \return MOS_STATUS
471 //! MOS_STATUS_SUCCESS if success, else fail reason
472 //!
473 virtual MOS_STATUS DoFieldScaling(
474 DecodeProcessingParams *procParams,
475 MOS_GPU_CONTEXT renderContext,
476 bool disableDecodeSyncLock,
477 bool disableLockForTranscode);
478
479 protected:
480 //!
481 //! \brief Constructor
482 //!
483 FieldScalingInterface();
484
485 //!
486 //! \enum FieldScalingKernelStateIdx
487 //! \brief Field scaling kernel state index
488 //!
489 enum FieldScalingKernelStateIdx
490 {
491 stateNv12 = 0, //!< Field scaling kernel index for NV12
492 stateYuy2, //!< Field scaling kernel index for YUY2
493 stateMax //!< Max kernel index for Field scaling
494 };
495
496 enum
497 {
498 fieldTopSrcY = 0, //!< Binding table offset for Top field input Y
499 fieldTopSrcUV = 1, //!< Binding table offset for Top field input UV
500 fieldBotSrcY = 48, //!< Binding table offset for Bottom field input Y
501 fieldBotSrcUV = 49, //!< Binding table offset for Bottom field input UV
502 dstY = 24, //!< Binding table offset for output Y
503 dstUV = 25, //!< Binding table offset for output UV
504 numSurfaces = 50 //!< Number of BT entries for Field scaling
505 };
506
507 static const uint32_t m_maxInputWidth = 4096; //!< Max input width supported by Field Scaling
508 static const uint32_t m_minInputWidth = 128; //!< Min input width supported by Field Scaling
509 static const uint32_t m_maxInputHeight = 4096; //!< Max input height supported by Field Scaling
510 static const uint32_t m_minInputHeight = 128; //!< Min input height supported by Field Scaling
511
512 static const uint32_t m_initDshSize = MHW_PAGE_SIZE; //!< Init DSH size for Field Downscailng kernel
513 static const uint32_t m_samplerNum = 4; //!< Sampler count for Field Downscaling kernel
514 static const uint32_t m_numSyncTags = 16; //!< Sync tags num of state heap settings
515 static const float m_maxScaleRatio; //!< Maximum scaling ratio for both X and Y directions
516 static const float m_minScaleRatio; //!< Minimum scaling ratio for both X and Y directions
517
518 CodechalDecode *m_decoder = nullptr; //!< Pointer to Decode Interface
519 MOS_INTERFACE *m_osInterface = nullptr; //!< Pointer to OS Interface
520 CodechalHwInterface *m_hwInterface = nullptr; //!< Pointer to HW Interface
521 MhwRenderInterface *m_renderInterface = nullptr; //!< Pointer to Render Interface
522 MHW_STATE_HEAP_INTERFACE *m_stateHeapInterface = nullptr; //!< Pointer to State Heap Interface
523 MhwMiInterface *m_miInterface = nullptr; //!< Pointer to MI interface.
524 uint8_t *m_kernelBase = nullptr; //!< Pointer to kernel base address
525 CodecHalMmcState *m_mmcState = nullptr; //!< Pointer to MMC state
526 uint8_t *m_kernelBinary[stateMax]; //!< Kernel binary
527 uint32_t m_kernelUID[stateMax]; //!< Kernel unique ID
528 uint32_t m_kernelSize[stateMax]; //!< Kernel size
529 MHW_KERNEL_STATE m_kernelStates[stateMax]; //!< Kernel state
530 uint32_t m_dshSize[stateMax]; //!< DSH size
531 MOS_RESOURCE m_syncObject; //!< Sync Object
532 uint32_t m_curbeLength; //!< Media Data struct Length
533
534 //!
535 //! \brief Initialize state heap settings and kernel params
536 //! \details Initialize Field Scaling Kernel State heap settings & params
537 //! \param [in] hwInterface
538 //! Pointer to HW Interface
539 //! \return MOS_STATUS
540 //! MOS_STATUS_SUCCESS if success, else fail reason
541 //!
542 virtual MOS_STATUS InitInterfaceStateHeapSetting(
543 CodechalHwInterface *hwInterface);
544
545 protected:
546 //!
547 //! \brief Set Field Scaling Curbe
548 //! \details Set curbe for field scaling kernel
549 //! \param MHW_KERNEL_STATE *kernelState
550 //! [in] Pointer to kernel state
551 //! \param CODECHAL_DECODE_PROCESSING_PARAMS *procParams
552 //! [in] Pointer to decode processing paramters
553 //! \return MOS_STATUS
554 //! MOS_STATUS_SUCCESS if success, else fail reason
555 //!
556 MOS_STATUS SetCurbeFieldScaling(
557 MHW_KERNEL_STATE *kernelState,
558 DecodeProcessingParams *procParams);
559 };
560 #endif // __CODECHAL_DECODER_DOWNSAMPLING_H__