1 /*
2 * Copyright (c) 2018-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_scalability_g12.h
24 //! \brief Impelements the public interface for Gen12 Scalability Decode
25 //!
26 #ifndef __CODECHAL_DECODE_SCALABILITY_G12_H__
27 #define __CODECHAL_DECODE_SCALABILITY_G12_H__
28
29
30 #include "codechal.h"
31 #include "codechal_hw.h"
32 #include "codechal_hw_g12_X.h"
33 #include "codechal_decoder.h"
34 #include "mos_os_virtualengine_scalability.h"
35 #include "codechal_decode_scalability.h"
36
37 #define CODECHAL_HCP_DECODE_PHASE_REAL_TILE 0xFF
38
39 #define CODECHAL_SCALABILITY_SLICE_STATE_CACHELINES_PER_SLICE_TGL 9
40
41 #define CODECHAL_SCALABILITY_ADDITIONAL_BES_MEMORY_OF_TWO_PIPE 2
42
43 #define CODECHAL_SCALABILITY_MAX_PIPE_INDEX_OF_TWO_PIPE 1
44
CodecHalDecodeMaxNumPipesInUseG12(uint8_t vdboxNum)45 inline static uint8_t CodecHalDecodeMaxNumPipesInUseG12(uint8_t vdboxNum)
46 {
47 uint8_t maxNumPipesInUs = 1;
48 if (vdboxNum == 2)
49 {
50 maxNumPipesInUs = 2;
51 }
52 else
53 {
54 maxNumPipesInUs = vdboxNum - 1;
55 }
56 return maxNumPipesInUs;
57 }
58
59 typedef struct _CODECHAL_DECODE_SCALABILITY_INIT_PARAMS_G12 : public _CODECHAL_DECODE_SCALABILITY_INIT_PARAMS
60 {
61 bool bIsTileEnabled; //!< The picture can be partitioned into tiles
62 bool bIsSccDecoding; //!< Codec is HEVC SCC decoding
63 bool bHasSubsetParams; //!< Whether it has subset parameters
64 }CODECHAL_DECODE_SCALABILITY_INIT_PARAMS_G12, *PCODECHAL_DECODE_SCALABILITY_INIT_PARAMS_G12;
65
66 typedef struct _CODECHAL_DECODE_SFC_SCALABILITY_PARAMS
67 {
68 // HCP-SFC pipe only for scalability and more input/output color format
69 uint32_t engineMode; //!< 0 - single, 1 - left most column, 2 - right most column, 3 - middle column
70 uint32_t tileType; //!< Real tile = 0, virtual tile = 1
71 uint32_t srcStartX; //!< Source surface column horizontal start position in pixel
72 uint32_t srcEndX; //!< Source surface column horizontal end position in pixel
73 uint32_t dstStartX; //!< Output surface column horizontal start position in pixel
74 uint32_t dstEndX; //!< Output surface column horizontal end position in pixel
75 }CODECHAL_DECODE_SFC_SCALABILITY_PARAMS, *PCODECHAL_DECODE_SFC_SCALABILITY_PARAMS;
76
77 typedef struct _CODECHAL_DECODE_SCALABILITY_STATE_G12 : public _CODECHAL_DECODE_SCALABILITY_STATE
78 {
79 // For hevc real tile decoding
80 bool bIsRtMode;
81 uint8_t u8RtCurPipe;
82 uint8_t u8RtCurPhase;
83 uint8_t u8RtPhaseNum;
84 uint8_t u8RtPipeInLastPhase;
85 MOS_RESOURCE resSemaMemBEsAdditional[CODECHAL_SCALABILITY_ADDITIONAL_BES_MEMORY_OF_TWO_PIPE]; //!< Additional BEs sync for two pipes
86
87 #if (_DEBUG || _RELEASE_INTERNAL)
88 bool bDisableRtMode;
89 bool bEnableRtMultiPhase;
90 uint8_t dbgOverUserPipeNum;
91 #endif
92 }CODECHAL_DECODE_SCALABILITY_STATE_G12, *PCODECHAL_DECODE_SCALABILITY_STATE_G12;
93
94 #define CodecHalDecodeScalablity_SetPhaseIndicator(PhaseIndicator)\
95 { \
96 if (m_scalabilityState->u8RtCurPhase == 0) \
97 { \
98 PhaseIndicator = MHW_VDBOX_HCP_RT_FIRST_PHASE; \
99 } \
100 else if (m_scalabilityState->u8RtCurPhase == m_scalabilityState->u8RtPhaseNum - 1) \
101 { \
102 PhaseIndicator = MHW_VDBOX_HCP_RT_LAST_PHASE; \
103 } \
104 else \
105 { \
106 PhaseIndicator = MHW_VDBOX_HCP_RT_MIDDLE_PHASE; \
107 } \
108 }while (0)
109
110 #define CodecHalDecodeScalabilityIsRealTileMode(pScalabilityState) \
111 (pScalabilityState ? (pScalabilityState->bScalableDecodeMode && pScalabilityState->bIsRtMode): false)
112
113 #define CodecHalDecodeScalabilityIsVirtualTileMode(pScalabilityState) \
114 (pScalabilityState ? (pScalabilityState->bScalableDecodeMode && !pScalabilityState->bIsRtMode): false)
115
116 #define CodecHalDecodeScalabilityIsRealTilePhase(pScalabilityState) \
117 (pScalabilityState && pScalabilityState->bScalableDecodeMode && \
118 (pScalabilityState->HcpDecPhase == CODECHAL_HCP_DECODE_PHASE_REAL_TILE))
119
120 #define CodecHalDecodeScalabilityIsFirstRealTilePhase(pScalabilityState) \
121 (CodecHalDecodeScalabilityIsRealTilePhase(pScalabilityState) && \
122 (pScalabilityState->u8RtCurPhase == 0))
123
124 #define CodecHalDecodeScalabilityIsLastRealTilePhase(pScalabilityState) \
125 (CodecHalDecodeScalabilityIsRealTilePhase(pScalabilityState) && \
126 ((pScalabilityState->u8RtCurPhase == pScalabilityState->u8RtPhaseNum - 1) || \
127 ((pScalabilityState->u8RtCurPipe >= pScalabilityState->u8RtPipeInLastPhase) && \
128 (pScalabilityState->u8RtCurPhase == pScalabilityState->u8RtPhaseNum - 2))))
129
130 #define CodecHalDecodeScalabilityIsLastRealTilePass(pScalabilityState) \
131 (CodecHalDecodeScalabilityIsRealTilePhase(pScalabilityState) && \
132 (pScalabilityState->u8RtCurPhase == pScalabilityState->u8RtPhaseNum - 1) && \
133 (pScalabilityState->u8RtCurPipe == pScalabilityState->u8RtPipeInLastPhase - 1))
134
135 #define CodecHalDecodeScalabilityIsBEPhaseG12(pScalabilityState) \
136 (pScalabilityState && pScalabilityState->bScalableDecodeMode && \
137 ((pScalabilityState->HcpDecPhase >= CODECHAL_HCP_DECODE_PHASE_BE0) && \
138 (pScalabilityState->HcpDecPhase != CODECHAL_HCP_DECODE_PHASE_REAL_TILE)))
139
140 #define CodecHalDecodeScalabilityIsFinalBEPhaseG12(pScalabilityState) \
141 (pScalabilityState && pScalabilityState->bScalableDecodeMode && \
142 ((pScalabilityState->HcpDecPhase >= CODECHAL_HCP_DECODE_PHASE_BE0) && \
143 (pScalabilityState->HcpDecPhase != CODECHAL_HCP_DECODE_PHASE_REAL_TILE)) && \
144 (pScalabilityState->ucScalablePipeNum == pScalabilityState->HcpDecPhase - CODECHAL_HCP_DECODE_PHASE_FE))
145
146 #define CodecHalDecodeScalablity_DecPhaseToHwWorkMode_G12(EngineMode, PipeWorkMode)\
147 do \
148 { \
149 if (m_hcpDecPhase == CODECHAL_HCP_DECODE_PHASE_REAL_TILE) \
150 { \
151 PipeWorkMode = MHW_VDBOX_HCP_PIPE_WORK_MODE_CABAC_REAL_TILE; \
152 if (m_scalabilityState->u8RtCurPipe == 0) \
153 { \
154 if ((m_scalabilityState->u8RtCurPhase == m_scalabilityState->u8RtPhaseNum - 1) && \
155 (m_scalabilityState->u8RtPipeInLastPhase == 1)) \
156 EngineMode = MHW_VDBOX_HCP_MULTI_ENGINE_MODE_FE_LEGACY; \
157 else \
158 EngineMode = MHW_VDBOX_HCP_MULTI_ENGINE_MODE_LEFT; \
159 } \
160 else if (m_scalabilityState->u8RtCurPipe == m_scalabilityState->ucScalablePipeNum - 1) \
161 EngineMode = MHW_VDBOX_HCP_MULTI_ENGINE_MODE_RIGHT; \
162 else \
163 EngineMode = MHW_VDBOX_HCP_MULTI_ENGINE_MODE_MIDDLE; \
164 } \
165 else if (m_hcpDecPhase == CODECHAL_HCP_DECODE_PHASE_FE) \
166 { \
167 EngineMode = MHW_VDBOX_HCP_MULTI_ENGINE_MODE_FE_LEGACY; \
168 PipeWorkMode = MHW_VDBOX_HCP_PIPE_WORK_MODE_CABAC_FE; \
169 } \
170 else if (m_hcpDecPhase == CODECHAL_HCP_DECODE_PHASE_BE0) \
171 { \
172 EngineMode = MHW_VDBOX_HCP_MULTI_ENGINE_MODE_LEFT; \
173 PipeWorkMode = MHW_VDBOX_HCP_PIPE_WORK_MODE_CODEC_BE; \
174 } \
175 else \
176 { \
177 if(((m_hcpDecPhase - CODECHAL_HCP_DECODE_PHASE_FE) <= m_scalabilityState->ucScalablePipeNum) && \
178 (m_hcpDecPhase > CODECHAL_HCP_DECODE_PHASE_BE0)) \
179 { \
180 CODECHAL_DECODE_ASSERT(m_scalabilityState->ucScalablePipeNum >= 2); \
181 EngineMode = (m_scalabilityState->ucScalablePipeNum == (m_hcpDecPhase - CODECHAL_HCP_DECODE_PHASE_FE)) ? \
182 MHW_VDBOX_HCP_MULTI_ENGINE_MODE_RIGHT : MHW_VDBOX_HCP_MULTI_ENGINE_MODE_MIDDLE; \
183 PipeWorkMode = MHW_VDBOX_HCP_PIPE_WORK_MODE_CODEC_BE; \
184 } \
185 } \
186 }while (0)
187
188 //!
189 //! \brief Get secondary cmd buffer
190 //! \param [in] pScalabilityState
191 //! Scalability decode state
192 //! \param [in] pSdryCmdBuf
193 //! secondary cmd buffer address
194 //! \return MOS_STATUS
195 //! MOS_STATUS_SUCCESS if success, else fail reason
196 //!
197 MOS_STATUS CodecHalDecodeScalability_GetVESecondaryCmdBuffer_G12(
198 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState,
199 PMOS_COMMAND_BUFFER pSdryCmdBuf);
200
201 //!
202 //! \brief get command buffer to use
203 //! \details decide and get command buffer to add cmds. it is for decoder which can support both scalability and single pipe
204 //! \param [in] pScalabilityState
205 //! Scalability decode state
206 //! \param [in] pScdryCmdBuf
207 //! pointer to secondary cmd buffer
208 //! \param [in] ppCmdBufToUse
209 //! pointer to cmd buffer to use
210 //! \return MOS_STATUS
211 //! MOS_STATUS_SUCCESS if success, else fail reason
212 //!
213 MOS_STATUS CodecHalDecodeScalability_GetCmdBufferToUse_G12(
214 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState,
215 PMOS_COMMAND_BUFFER pScdryCmdBuf,
216 PMOS_COMMAND_BUFFER *ppCmdBufToUse);
217
218 //!
219 //! \brief return secondary cmd buffer
220 //! \param [in] pScalabilityState
221 //! Scalability decode state
222 //! \param [in] pScdryCmdBuf
223 //! pointer to secondary cmd buffer
224 //! \return MOS_STATUS
225 //! MOS_STATUS_SUCCESS if success, else fail reason
226 //!
227 MOS_STATUS CodecHalDecodeScalability_ReturnSdryCmdBuffer_G12(
228 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState,
229 PMOS_COMMAND_BUFFER pSdryCmdBuf);
230
231 #if (_DEBUG || _RELEASE_INTERNAL)
232 //!
233 //! \brief dump command buffer in scalability mode
234 //! \param [in] pDecoder
235 //! Decoder device
236 //! \param [in] pScalabilityState
237 //! Scalability decode state
238 //! \return MOS_STATUS
239 //! MOS_STATUS_SUCCESS if success, else fail reason
240 //!
241 MOS_STATUS CodecHalDecodeScalability_DbgDumpCmdBuffer_G12(
242 CodechalDecode *pDecoder,
243 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState,
244 CodechalDebugInterface *debugInterface,
245 PMOS_COMMAND_BUFFER pPrimCmdBuf);
246 #endif
247
248 //!
249 //! \brief Determine decode phase
250 //! \details determine decode phase for decoder supporting scalability mode but not necessarily always running in scalable mode
251 //! \param [in] pScalabilityState
252 //! Scalability decode state
253 //! \param [in] pHcpDecPhase
254 //! Address of hcp decode phase
255 //! \return MOS_STATUS
256 //! MOS_STATUS_SUCCESS if success, else fail reason
257 //!
258 MOS_STATUS CodecHalDecodeScalability_DetermineDecodePhase_G12(
259 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState,
260 uint32_t *pHcpDecPhase);
261
262 //!
263 //! \brief Initiliaze Decode Parameters for virtual engine decode
264 //! \details Initiliaze decode parameters for virtual engine decode. this is for decoder supporting scalability but not necessarily always running in scalable mode
265 //! \param [in] pScalabilityState
266 //! Scalability decode state
267 //! \param [in] pInitParams
268 //! pointer to parameters to initialize decode scalability
269 //! \param [in] pucDecPassNum
270 //! pointer to decode pass number
271 //! \return MOS_STATUS
272 //! MOS_STATUS_SUCCESS if success, else fail reason
273 //!
274 MOS_STATUS CodecHalDecodeScalability_InitScalableParams_G12(
275 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState,
276 PCODECHAL_DECODE_SCALABILITY_INIT_PARAMS pInitParams,
277 uint16_t *pucDecPassNum);
278
279 //!
280 //! \brief Set virtual engine hint parameters for scalable decode
281 //! \param [in] pScalabilityState
282 //! Scalability decode state
283 //! \param [in] pSetHintParms
284 //! pointer to set hint parameter
285 //! \return MOS_STATUS
286 //! MOS_STATUS_SUCCESS if success, else fail reason
287 //!
288 MOS_STATUS CodecHalDecodeScalability_SetHintParams_G12(
289 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState,
290 PCODECHAL_DECODE_SCALABILITY_SETHINT_PARMS pSetHintParms);
291
292 //!
293 //! \brief Sync between FE and BE
294 //! \details This function does 3 major things
295 //! 1) send hw or sw semaphore wait at start of BE0 cmd.
296 //! 2) use HW semaphore wait and MI ATOMIC cmd to make all BEs start running at the same time
297 //! 3) add COND BB END cmd to check if CABAC stream out buffer overflow.
298 //! \param [in] pScalabilityState
299 //! Scalability decode state
300 //! \param [in] pCmdBufferInUse
301 //! address of command buffer
302 //! \return MOS_STATUS
303 //! MOS_STATUS_SUCCESS if success, else fail reason
304 //!
305 MOS_STATUS CodecHalDecodeScalability_FEBESync_G12(
306 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState,
307 PMOS_COMMAND_BUFFER pCmdBufferInUse,
308 bool phasedSubmission);
309
310 //!
311 //! \brief To judge if command buffer should be submitted.
312 //! \param [in] pScalabilityState
313 //! Scalability decode state
314 //! \return bool
315 //! True means to submit command buffer, False means not to submit.
316 //!
317 bool CodecHalDecodeScalabilityIsToSubmitCmdBuffer_G12(
318 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState);
319
320 //!
321 //! \brief Read CS ENGINEID register to know which engine is in use for current workload
322 //! \param [in] pDecodeStatusBuf
323 //! Decode status buffer
324 //! \param [in] pCmdBufferInUse
325 //! address of command buffer
326 //! \return MOS_STATUS
327 //! MOS_STATUS_SUCCESS if success, else fail reason
328 //!
329 MOS_STATUS CodecHalDecodeScalability_ReadCSEngineIDReg_G12(
330 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState,
331 CodechalDecodeStatusBuffer *pDecodeStatusBuf,
332 PMOS_COMMAND_BUFFER pCmdBufferInUse);
333
334 //!
335 //! \brief State initialization for virtual engine decode supporting scalable and single pipe mode
336 //! \param [in] pDecoder
337 //! Decoder device
338 //! \param [in] pScalabilityState
339 //! Scalability decode state
340 //! \param [in] bShortFormat
341 //! short format decode flag
342 //! \return MOS_STATUS
343 //! MOS_STATUS_SUCCESS if success, else fail reason
344 //!
345 MOS_STATUS CodecHalDecodeScalability_InitializeState_G12(
346 CodechalDecode *pDecoder,
347 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState,
348 CodechalHwInterface *hwInterface,
349 bool bShortFormat,
350 CodechalSetting *settings);
351
352
353 //! \brief construct gpu context creation options when scalability supported
354 //! \param [in] scalabilityState
355 //! Scalability decode state
356 //! \param [in] gpuCtxCreatOptions
357 //! pointer to gpu context creation options
358 //! \param [in] codechalSetting
359 //! Pointer to codechal setting
360 //! \return MOS_STATUS
361 //! MOS_STATUS_SUCCESS if success, else fail reason
362 //!
363 MOS_STATUS CodechalDecodeScalability_ConstructParmsForGpuCtxCreation_g12(
364 PCODECHAL_DECODE_SCALABILITY_STATE pScalState,
365 PMOS_GPUCTX_CREATOPTIONS_ENHANCED gpuCtxCreatOpts,
366 CodechalSetting * codecHalSetting);
367
368
369 //!
370 //! \brief State initialization for virtual engine decode supporting scalable and single pipe mode
371 //! \param [in] pScalabilityState
372 //! Scalability decode state
373 //! \return MOS_STATUS
374 //! MOS_STATUS_SUCCESS if success, else fail reason
375 //!
376 MOS_STATUS CodecHalDecodeScalability_AdvanceRealTilePass(
377 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState);
378
379 //!
380 //! \brief Get curent tile column index in real tile decoding
381 //! \param [in] pScalabilityState
382 //! Scalability decode state
383 //! \param [out] col
384 //! reference to column id
385 //! \return MOS_STATUS
386 //! MOS_STATUS_SUCCESS if success, else fail reason
387 //!
388 MOS_STATUS CodecHalDecodeScalability_GetCurrentRealTileColumnId(
389 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState,
390 uint8_t &col);
391
392 //! \brief Set scalability parameters in SFC state
393 //! \param [in] scalabilityState
394 //! Scalability decode state
395 //! \param [in] picParams
396 //! Picture parameters for HEVC or VP9
397 //! \param [in] srcRegion
398 //! SFC input surface region
399 //! \param [in] dstRegion
400 //! SFC output surface region
401 //! \param [out] sfcScalabilityParams
402 //! Pointer to SFC Scalability state parameters
403 //! \return MOS_STATUS
404 //! MOS_STATUS_SUCCESS if success, else fail reason
405 //!
406 MOS_STATUS CodecHalDecodeScalability_SetSfcState(
407 PCODECHAL_DECODE_SCALABILITY_STATE scalabilityState,
408 void *picParams,
409 CodecRectangle *srcRegion,
410 CodecRectangle *dstRegion,
411 PCODECHAL_DECODE_SFC_SCALABILITY_PARAMS sfcScalabilityParams);
412
413 MOS_STATUS CodecHalDecodeScalability_AllocateResources_VariableSizes_G12(
414 PCODECHAL_DECODE_SCALABILITY_STATE pScalabilityState,
415 PMHW_VDBOX_HCP_BUFFER_SIZE_PARAMS pHcpBufSizeParam,
416 PMHW_VDBOX_HCP_BUFFER_REALLOC_PARAMS pAllocParam);
417
418 MOS_STATUS CodecHalDecodeScalability_AllocateResources_FixedSizes_G12(
419 PCODECHAL_DECODE_SCALABILITY_STATE_G12 pScalabilityState);
420
421 bool CodecHalDecodeScalability_DecideEnableScala_G12(
422 PCODECHAL_DECODE_SCALABILITY_STATE pScalState,
423 PCODECHAL_DECODE_SCALABILITY_INIT_PARAMS pInitParams,
424 bool bCanEnableRealTile);
425
426 MOS_STATUS CodecHalDecodeScalability_DecidePipeNum_G12(
427 PCODECHAL_DECODE_SCALABILITY_STATE pScalState,
428 PCODECHAL_DECODE_SCALABILITY_INIT_PARAMS pInitParams);
429
430 MOS_STATUS CodechalDecodeScalability_MapPipeNumToLRCACount_G12(
431 PCODECHAL_DECODE_SCALABILITY_STATE pScalState,
432 uint32_t *LRCACount);
433
434 #if (_DEBUG || _RELEASE_INTERNAL)
435 MOS_STATUS CodechalDecodeScalability_DebugOvrdDecidePipeNum_G12(
436 PCODECHAL_DECODE_SCALABILITY_STATE pScalState);
437 #endif
438
439 void CodecHalDecodeScalability_DecPhaseToSubmissionType_G12(
440 PCODECHAL_DECODE_SCALABILITY_STATE_G12 pScalabilityState,
441 PMOS_COMMAND_BUFFER pCmdBuffer);
442
443 void CodecHalDecodeScalability_Destroy_G12(
444 PCODECHAL_DECODE_SCALABILITY_STATE_G12 pScalabilityState);
445
446 #endif // __CODECHAL_DECODE_SCALABILITY_G12_H__
447