xref: /aosp_15_r20/external/intel-media-driver/media_driver/agnostic/common/cm/cm_hal_vebox.cpp (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2017, 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      cm_hal_vebox.cpp
24 //! \brief     HAL CM Vebox functions
25 //!
26 
27 #include "cm_hal.h"
28 #include "cm_hal_vebox.h"
29 
30 //!
31 //! \brief      build up vebox command sequence
32 //! \details     based on passed vebox param to build command sequence and
33 //!             put it into command buffer
34 //! \param       [in] state --- CM_HAL_STATE
35 //! \param       [in] veboxTaskParam -- vebox setup params
36 //!
HalCm_ExecuteVeboxTask(PCM_HAL_STATE state,PCM_HAL_EXEC_VEBOX_TASK_PARAM veboxTaskParam)37 MOS_STATUS HalCm_ExecuteVeboxTask(
38     PCM_HAL_STATE                   state,           // [in] Pointer to CM State
39     PCM_HAL_EXEC_VEBOX_TASK_PARAM   veboxTaskParam)  // [in] Pointer to Vebox Task Param
40 {
41     CM_VEBOX_STATE                      cmVeboxState;
42     PMOS_INTERFACE                      osInterface;
43     MOS_COMMAND_BUFFER                  cmdBuffer;
44     MhwVeboxInterface                   *veboxInterface;
45     PMHW_VEBOX_HEAP                     veboxHeap;
46     MHW_VEBOX_STATE_CMD_PARAMS          veboxStateCmdParams;
47     MHW_VEBOX_SURFACE_STATE_CMD_PARAMS  veboxSurfaceStateCmdParams;
48     MHW_VEBOX_DI_IECP_CMD_PARAMS        veboxDiIecpCmdParams;
49     MHW_MI_FLUSH_DW_PARAMS              miFlushDwParams;
50     MOS_STATUS                          eStatus = MOS_STATUS_SUCCESS;
51     uint32_t                            index;
52     int32_t                             taskId, i, remaining, syncOffset;
53     int64_t                             *taskSyncLocation;
54     uint32_t                            tag;
55 
56     RENDERHAL_GENERIC_PROLOG_PARAMS     genericPrologParams = {};
57     MOS_RESOURCE                        osResource;
58     CM_VEBOX_SURFACE_DATA               cmVeboxSurfaceData;
59     PRENDERHAL_INTERFACE                renderHal = state->renderHal;
60 
61     //-----------------------------------
62     CM_CHK_NULL_RETURN_MOSERROR(state);
63     CM_CHK_NULL_RETURN_MOSERROR(state->osInterface);
64     CM_CHK_NULL_RETURN_MOSERROR(state->veboxInterface);
65     CM_CHK_NULL_RETURN_MOSERROR(veboxTaskParam);
66     //-----------------------------------
67 
68     // initialize
69     MOS_ZeroMemory(&cmdBuffer, sizeof(MOS_COMMAND_BUFFER));
70 
71     veboxInterface = state->veboxInterface;
72 
73     veboxHeap = veboxInterface->m_veboxHeap;
74     osInterface = state->osInterface;
75     remaining = 0;
76 
77     // update Cm state settings
78 
79     state->cmVeboxSettings.dndiFirstFrame = veboxTaskParam->cmVeboxState.DNDIFirstFrame;
80     state->cmVeboxSettings.iecpEnabled = veboxTaskParam->cmVeboxState.GlobalIECPEnable;
81     state->cmVeboxSettings.diEnabled = veboxTaskParam->cmVeboxState.DIEnable;
82     state->cmVeboxSettings.dnEnabled = veboxTaskParam->cmVeboxState.DNEnable;
83     state->cmVeboxSettings.demosaicEnabled = veboxTaskParam->cmVeboxState.DemosaicEnable;
84     state->cmVeboxSettings.vignetteEnabled = veboxTaskParam->cmVeboxState.VignetteEnable;
85     state->cmVeboxSettings.hotPixelFilterEnabled = veboxTaskParam->cmVeboxState.HotPixelFilteringEnable;
86     state->cmVeboxSettings.diOutputFrames = veboxTaskParam->cmVeboxState.DIOutputFrames;
87 
88     cmVeboxSurfaceData = veboxTaskParam->veboxSurfaceData;
89 
90     // reset states before execute
91     // (clear allocations, get GSH allocation index + any additional housekeeping)
92     osInterface->pfnResetOsStates(osInterface);
93 
94     // reset HW
95     CM_CHK_MOSSTATUS_GOTOFINISH(state->renderHal->pfnReset(state->renderHal));
96 
97     // get the Task Id
98     CM_CHK_MOSSTATUS_GOTOFINISH(HalCm_GetNewTaskId(state, &taskId));
99 
100     // get the task sync offset
101     syncOffset = state->pfnGetTaskSyncLocation(state, taskId);
102 
103     // set Perf Tag
104     osInterface->pfnResetPerfBufferID(osInterface);
105     if (!(osInterface->pfnIsPerfTagSet(osInterface)))
106     {
107         osInterface->pfnSetPerfTag(osInterface, VPHAL_NONE);
108     }
109 
110     // initialize the location
111     taskSyncLocation = (int64_t*)(state->veboxTimeStampResource.data + syncOffset);
112     *taskSyncLocation = CM_INVALID_INDEX;
113     *(taskSyncLocation + 1) = CM_INVALID_INDEX;
114     if (state->cbbEnabled)
115     {
116         *(taskSyncLocation + 2) = state->renderHal->veBoxTrackerRes.currentTrackerId;
117     }
118 
119     // register Timestamp Buffer
120     CM_CHK_MOSSTATUS_GOTOFINISH(osInterface->pfnRegisterResource(
121         osInterface,
122         &state->veboxTimeStampResource.osResource,
123         true,
124         true));
125 
126     // get details of the surfaces on VPHAL Surface
127     for (index = 0; index < VEBOX_SURFACE_NUMBER; index++)
128     {
129         if (veboxTaskParam->veboxSurfaceData.surfaceEntry[index].surfaceIndex == 0xffff)
130         {
131             continue;
132         }
133 
134         CM_CHK_MOSSTATUS_GOTOFINISH(HalCm_GetSurfaceAndRegister(
135             state,
136             &state->cmVeboxSurfaces[index],
137             CM_ARGUMENT_SURFACE2D,
138             veboxTaskParam->veboxSurfaceData.surfaceEntry[index].surfaceIndex,
139             0));
140         state->cmVeboxSurfaces[index].rcMaxSrc = state->cmVeboxSurfaces[index].rcSrc;
141     }
142 
143     //----------------------------------
144     // initialize STMM input surface
145     //----------------------------------
146     if ((veboxTaskParam->cmVeboxState.DNDIFirstFrame) && ((veboxTaskParam->cmVeboxState.DIEnable) || (veboxTaskParam->cmVeboxState.DNEnable)))
147     {
148         CM_CHK_MOSSTATUS_GOTOFINISH(HalCm_VeboxInitSTMMHistory(
149             osInterface,
150             &state->cmVeboxSurfaces[VEBOX_STMM_INPUT_SURF]));
151     }
152 
153     //----------------------------------
154     // Allocate and reset VEBOX state
155     //----------------------------------
156     CM_CHK_MOSSTATUS_GOTOFINISH(veboxInterface->AssignVeboxState());
157 
158     //----------------------------------
159     // set vebox state heap and vebox cmd parameters
160     //----------------------------------
161     MOS_ZeroMemory(&veboxStateCmdParams, sizeof(MHW_VEBOX_STATE_CMD_PARAMS));
162 
163     //set vebox param buffer
164     CM_CHK_MOSSTATUS_GOTOFINISH(HalCm_GetSurfaceAndRegister(
165         state,
166         &state->cmVebeboxParamSurf,
167         CM_ARGUMENT_SURFACEBUFFER,
168         veboxTaskParam->veboxParamIndex,
169         0));
170 
171     veboxStateCmdParams.VeboxMode.AlphaPlaneEnable = veboxTaskParam->cmVeboxState.AlphaPlaneEnable;
172     veboxStateCmdParams.VeboxMode.ColorGamutCompressionEnable = veboxTaskParam->cmVeboxState.ColorGamutCompressionEnable;
173     veboxStateCmdParams.VeboxMode.ColorGamutExpansionEnable = veboxTaskParam->cmVeboxState.ColorGamutExpansionEnable;
174     veboxStateCmdParams.VeboxMode.DemosaicEnable = veboxTaskParam->cmVeboxState.DemosaicEnable;
175     veboxStateCmdParams.VeboxMode.DIEnable = veboxTaskParam->cmVeboxState.DIEnable;
176     veboxStateCmdParams.VeboxMode.DIOutputFrames = veboxTaskParam->cmVeboxState.DIOutputFrames;
177     veboxStateCmdParams.VeboxMode.DisableEncoderStatistics = veboxTaskParam->cmVeboxState.DisableEncoderStatistics;
178     veboxStateCmdParams.VeboxMode.DisableTemporalDenoiseFilter = veboxTaskParam->cmVeboxState.DisableTemporalDenoiseFilter;
179     veboxStateCmdParams.VeboxMode.DNDIFirstFrame = veboxTaskParam->cmVeboxState.DNDIFirstFrame;
180     veboxStateCmdParams.VeboxMode.DNEnable = veboxTaskParam->cmVeboxState.DNEnable;
181     veboxStateCmdParams.VeboxMode.ForwardGammaCorrectionEnable = veboxTaskParam->cmVeboxState.ForwardGammaCorrectionEnable;
182     veboxStateCmdParams.VeboxMode.GlobalIECPEnable = veboxTaskParam->cmVeboxState.GlobalIECPEnable;
183     veboxStateCmdParams.VeboxMode.HotPixelFilteringEnable = veboxTaskParam->cmVeboxState.HotPixelFilteringEnable;
184     veboxStateCmdParams.VeboxMode.SingleSliceVeboxEnable = veboxTaskParam->cmVeboxState.SingleSliceVeboxEnable;
185     veboxStateCmdParams.VeboxMode.VignetteEnable = veboxTaskParam->cmVeboxState.VignetteEnable;
186     veboxStateCmdParams.pVeboxParamSurf = (PMOS_RESOURCE)&((state->cmVebeboxParamSurf).OsSurface);
187     //----------------------------------
188     // get vebox command buffer
189     //----------------------------------
190     CM_CHK_MOSSTATUS_GOTOFINISH(osInterface->pfnGetCommandBuffer(osInterface, &cmdBuffer, 0));
191     remaining = cmdBuffer.iRemaining;
192 
193     //---------------------------------
194     // Get the OS resource
195     //---------------------------------
196     osResource = state->renderHal->veBoxTrackerRes.osResource;
197     tag = state->renderHal->veBoxTrackerRes.currentTrackerId;
198     state->renderHal->pfnSetupPrologParams(state->renderHal, &genericPrologParams, &osResource, 0, tag);
199 
200     //---------------------------------
201     // send command buffer header at the beginning (OS dependent)
202     //---------------------------------
203     CM_CHK_MOSSTATUS_GOTOFINISH(state->renderHal->pfnInitCommandBuffer(
204         state->renderHal,
205         &cmdBuffer,
206         &genericPrologParams));
207 
208     //---------------------------------
209     // the beginning of execution
210     // issue MI_FLUSH_DW cmd to write timestamp
211     //---------------------------------
212     MOS_ZeroMemory(&miFlushDwParams, sizeof(miFlushDwParams));
213     miFlushDwParams.pOsResource          = &state->veboxTimeStampResource.osResource;
214     miFlushDwParams.dwResourceOffset     = syncOffset;
215     miFlushDwParams.postSyncOperation    = MHW_FLUSH_WRITE_TIMESTAMP_REG;
216     miFlushDwParams.bQWordEnable         = 1;
217 
218     CM_CHK_MOSSTATUS_GOTOFINISH(renderHal->pMhwMiInterface->AddMiFlushDwCmd(
219         &cmdBuffer,
220         &miFlushDwParams));
221 
222     //---------------------------------
223     // update tracker tag
224     //---------------------------------
225     renderHal->veBoxTrackerRes.currentTrackerId++;
226 
227     //---------------------------------
228     // send vebox state commands
229     //---------------------------------
230     CM_CHK_MOSSTATUS_GOTOFINISH(veboxInterface->AddVeboxState(
231         &cmdBuffer,
232         &veboxStateCmdParams, 1));
233 
234     //---------------------------------
235     // send Vebox_Surface_State cmd
236     //---------------------------------
237     MOS_ZeroMemory(&veboxSurfaceStateCmdParams, sizeof(MHW_VEBOX_SURFACE_STATE_CMD_PARAMS));
238     CM_CHK_MOSSTATUS_GOTOFINISH(HalCm_SetVeboxSurfaceStateCmdParams(state, &veboxSurfaceStateCmdParams));
239     CM_CHK_MOSSTATUS_GOTOFINISH(veboxInterface->AddVeboxSurfaces(
240         &cmdBuffer,
241         &veboxSurfaceStateCmdParams));
242     //---------------------------------
243     // send Vebox_DI_IECP cmd
244     //---------------------------------
245     MOS_ZeroMemory(&veboxDiIecpCmdParams, sizeof(MHW_VEBOX_DI_IECP_CMD_PARAMS));
246     CM_CHK_MOSSTATUS_GOTOFINISH(HalCm_SetVeboxDiIecpCmdParams(state, &veboxDiIecpCmdParams, (PCM_VEBOX_SURFACE_DATA)&cmVeboxSurfaceData));
247     CM_CHK_MOSSTATUS_GOTOFINISH(veboxInterface->AddVeboxDiIecp(
248         &cmdBuffer,
249         &veboxDiIecpCmdParams));
250 
251     //---------------------------------
252     // issue MI_FLUSH_DW cmd to write timestamp, end of execution
253     //---------------------------------
254     MOS_ZeroMemory(&miFlushDwParams, sizeof(miFlushDwParams));
255     miFlushDwParams.pOsResource        = &state->veboxTimeStampResource.osResource;
256     miFlushDwParams.dwResourceOffset   = syncOffset + sizeof(uint64_t);
257     miFlushDwParams.postSyncOperation  = MHW_FLUSH_WRITE_TIMESTAMP_REG;
258     miFlushDwParams.bQWordEnable       = 1;
259 
260     CM_CHK_MOSSTATUS_GOTOFINISH(renderHal->pMhwMiInterface->AddMiFlushDwCmd(
261         &cmdBuffer,
262         &miFlushDwParams));
263 
264     //---------------------------------
265     // Write Sync tag for Vebox Heap Synchronization
266     //---------------------------------
267     MOS_ZeroMemory(&miFlushDwParams, sizeof(miFlushDwParams));
268     miFlushDwParams.pOsResource       = &veboxHeap->DriverResource;
269     miFlushDwParams.dwResourceOffset  = veboxHeap->uiOffsetSync;
270     miFlushDwParams.dwDataDW1         = veboxHeap->dwNextTag;
271     miFlushDwParams.bQWordEnable      = 1;
272     CM_CHK_MOSSTATUS_GOTOFINISH(renderHal->pMhwMiInterface->AddMiFlushDwCmd(
273         &cmdBuffer,
274         &miFlushDwParams));
275 
276     // Update tracker resource
277     CM_CHK_MOSSTATUS_GOTOFINISH(state->pfnUpdateTrackerResource(state, &cmdBuffer, tag));
278 
279     //---------------------------------
280     // Make sure copy kernel and update kernels are finished before submitting
281     // VEBOX commands
282     //---------------------------------
283     if ((MOS_GPU_CONTEXT)veboxTaskParam->queueOption.GPUContext != MOS_GPU_CONTEXT_CM_COMPUTE)
284     {
285         osInterface->pfnSyncGpuContext(
286             osInterface,
287             (MOS_GPU_CONTEXT)veboxTaskParam->queueOption.GPUContext,
288             MOS_GPU_CONTEXT_VEBOX);
289     }
290 
291     osInterface->pfnResetPerfBufferID(osInterface);
292     if (!(osInterface->pfnIsPerfTagSet(osInterface)))
293     {
294         osInterface->pfnIncPerfFrameID(osInterface);
295         osInterface->pfnSetPerfTag(osInterface, VEBOX_TASK_PERFTAG_INDEX);
296     }
297 
298     //Couple to the BB_START , otherwise GPU Hang without it in KMD.
299     CM_CHK_MOSSTATUS_GOTOFINISH(renderHal->pMhwMiInterface->AddMiBatchBufferEnd(&cmdBuffer, nullptr));
300 
301     //---------------------------------
302     // Return unused command buffer space to OS
303     //---------------------------------
304     osInterface->pfnReturnCommandBuffer(
305         osInterface,
306         &cmdBuffer, 0);
307 
308     //---------------------------------
309     // submit the command buffer
310     //---------------------------------
311     CM_CHK_MOSSTATUS_GOTOFINISH(osInterface->pfnSubmitCommandBuffer(
312         osInterface,
313         &cmdBuffer,
314         state->nullHwRenderCm));
315 
316     // Set the Task ID
317     veboxTaskParam->taskIdOut = taskId;
318 
319     // pass back the Command Buffer
320     state->pfnReferenceCommandBuffer(&cmdBuffer.OsResource, &veboxTaskParam->osData);
321 
322     // Update the task ID table
323     state->taskStatusTable[taskId] = (char)taskId;
324 
325     if (!(state->nullHwRenderCm))
326     {
327         // Update Vebox Sync tag info
328         veboxHeap->pStates[veboxHeap->uiCurState].dwSyncTag = veboxHeap->dwNextTag++;
329         veboxHeap->pStates[veboxHeap->uiCurState].bBusy = true;
330     }
331 
332     eStatus = MOS_STATUS_SUCCESS;
333 
334 finish:
335 
336     // Failed -> discard all changes in Command Buffer
337     if (eStatus != MOS_STATUS_SUCCESS)
338     {
339         // Buffer overflow - display overflow size
340         if (cmdBuffer.iRemaining < 0)
341         {
342             CM_ASSERTMESSAGE("Command Buffer overflow by %d bytes", cmdBuffer.iRemaining);
343         }
344 
345         // Move command buffer back to beginning
346         i = remaining - cmdBuffer.iRemaining;
347         cmdBuffer.iRemaining = remaining;
348         cmdBuffer.iOffset -= i;
349         cmdBuffer.pCmdPtr = cmdBuffer.pCmdBase + cmdBuffer.iOffset / sizeof(uint32_t);
350 
351         // Return unused command buffer space to OS
352         osInterface->pfnReturnCommandBuffer(osInterface, &cmdBuffer, 0);
353     }
354 
355     return eStatus;
356 }
357 
358 //!
359 //! \brief      Set up vebox surface Param
360 //! \details    set up vebox surface state based on parameter based from application
361 //!
362 //! \param     [in]state  -- CM_HAL_STATE
363 //! \param     [in]veboxSurfaceStateCmdParams  -- surface state param struct
364 //!
HalCm_SetVeboxSurfaceStateCmdParams(PCM_HAL_STATE state,PMHW_VEBOX_SURFACE_STATE_CMD_PARAMS veboxSurfaceStateCmdParams)365 MOS_STATUS HalCm_SetVeboxSurfaceStateCmdParams(
366     PCM_HAL_STATE                           state,
367     PMHW_VEBOX_SURFACE_STATE_CMD_PARAMS   veboxSurfaceStateCmdParams)
368 {
369     if ((state->cmVeboxSettings.iecpEnabled) && !((state->cmVeboxSettings.diEnabled) || (state->cmVeboxSettings.dnEnabled)))
370     {
371         // IECP only
372         HalCm_Convert_RENDERHAL_SURFACE_To_MHW_VEBOX_SURFACE(&state->cmVeboxSurfaces[VEBOX_CURRENT_FRAME_INPUT_SURF], &veboxSurfaceStateCmdParams->SurfInput);
373         HalCm_Convert_RENDERHAL_SURFACE_To_MHW_VEBOX_SURFACE(&state->cmVeboxSurfaces[VEBOX_CURRENT_FRAME_OUTPUT_SURF], &veboxSurfaceStateCmdParams->SurfOutput);
374         veboxSurfaceStateCmdParams->bDIEnable = false;
375         veboxSurfaceStateCmdParams->bOutputValid = true;
376     }
377     else
378     {
379         // DN only, will add other support later
380 
381         HalCm_Convert_RENDERHAL_SURFACE_To_MHW_VEBOX_SURFACE(&state->cmVeboxSurfaces[VEBOX_CURRENT_FRAME_INPUT_SURF], &veboxSurfaceStateCmdParams->SurfInput);
382         HalCm_Convert_RENDERHAL_SURFACE_To_MHW_VEBOX_SURFACE(&state->cmVeboxSurfaces[VEBOX_DN_CURRENT_FRAME_OUTPUT_SURF], &veboxSurfaceStateCmdParams->SurfOutput);
383         HalCm_Convert_RENDERHAL_SURFACE_To_MHW_VEBOX_SURFACE(&state->cmVeboxSurfaces[VEBOX_STMM_INPUT_SURF], &veboxSurfaceStateCmdParams->SurfSTMM);
384         HalCm_Convert_RENDERHAL_SURFACE_To_MHW_VEBOX_SURFACE(&state->cmVeboxSurfaces[VEBOX_STMM_OUTPUT_SURF], &veboxSurfaceStateCmdParams->SurfDNOutput);
385 
386         veboxSurfaceStateCmdParams->bDIEnable = false;
387         veboxSurfaceStateCmdParams->bOutputValid = true;
388     }
389 
390     return MOS_STATUS_SUCCESS;
391 }
392 
393 //!
394 //! \brief    set vebox DiIecp Command
395 //! \details  build up command to start processing the frames specified by
396 //!           VEB_SURFACE_STATE using the parameters specified by VEB_DI_STATE
397 //!           and VEB_IECP_STATE.
398 //!  \param   [in] state -- HAL_CM_STATE
399 //!  \param   [in] veboxDiIecpCmdParams  -- DIECP command parameter
400 //!  \param   [in] cmVeboxSurfaceDataInput  -- surface data such as index and control bits
401 //!
HalCm_SetVeboxDiIecpCmdParams(PCM_HAL_STATE state,PMHW_VEBOX_DI_IECP_CMD_PARAMS veboxDiIecpCmdParams,PCM_VEBOX_SURFACE_DATA cmVeboxSurfaceDataInput)402 MOS_STATUS HalCm_SetVeboxDiIecpCmdParams(
403     PCM_HAL_STATE                   state,
404     PMHW_VEBOX_DI_IECP_CMD_PARAMS   veboxDiIecpCmdParams,
405     PCM_VEBOX_SURFACE_DATA       cmVeboxSurfaceDataInput)
406 {
407     uint32_t                 width;
408     uint32_t                 height;
409     bool                     dienable;
410     MHW_VEBOX_SURFACE_PARAMS surfInput;
411 
412     CM_CHK_NULL_RETURN_MOSERROR(state->veboxInterface);
413 
414     // DN only, will add other support later
415     dienable = false;
416 
417     // Align dwEndingX with surface state
418     HalCm_Convert_RENDERHAL_SURFACE_To_MHW_VEBOX_SURFACE(&state->cmVeboxSurfaces[VEBOX_CURRENT_FRAME_INPUT_SURF], &surfInput);
419     CM_CHK_MOSSTATUS_RETURN(state->veboxInterface->VeboxAdjustBoundary(
420                             &surfInput,
421                             &width,
422                             &height,
423                             dienable));
424 
425     veboxDiIecpCmdParams->dwStartingX = 0;
426     veboxDiIecpCmdParams->dwEndingX = width - 1;
427 
428     if (!state->cmVeboxSettings.dndiFirstFrame)
429     {
430         veboxDiIecpCmdParams->pOsResPrevInput = &state->cmVeboxSurfaces[VEBOX_PREVIOUS_FRAME_INPUT_SURF].OsSurface.OsResource;
431         veboxDiIecpCmdParams->PrevInputSurfCtrl.Value = cmVeboxSurfaceDataInput->surfaceEntry[VEBOX_PREVIOUS_FRAME_INPUT_SURF].surfaceCtrlBits;
432     }
433 
434     veboxDiIecpCmdParams->pOsResCurrInput = &state->cmVeboxSurfaces[VEBOX_CURRENT_FRAME_INPUT_SURF].OsSurface.OsResource;
435     veboxDiIecpCmdParams->CurrInputSurfCtrl.Value = cmVeboxSurfaceDataInput->surfaceEntry[VEBOX_CURRENT_FRAME_INPUT_SURF].surfaceCtrlBits;
436 
437     if ((state->cmVeboxSettings.diEnabled) || (state->cmVeboxSettings.dnEnabled))
438     {
439         veboxDiIecpCmdParams->pOsResStmmInput = &state->cmVeboxSurfaces[VEBOX_STMM_INPUT_SURF].OsSurface.OsResource;
440         veboxDiIecpCmdParams->StmmInputSurfCtrl.Value = cmVeboxSurfaceDataInput->surfaceEntry[VEBOX_STMM_INPUT_SURF].surfaceCtrlBits;
441 
442         veboxDiIecpCmdParams->pOsResStmmOutput = &state->cmVeboxSurfaces[VEBOX_STMM_OUTPUT_SURF].OsSurface.OsResource;
443         veboxDiIecpCmdParams->StmmOutputSurfCtrl.Value = cmVeboxSurfaceDataInput->surfaceEntry[VEBOX_STMM_OUTPUT_SURF].surfaceCtrlBits;
444     }
445 
446     if ((state->cmVeboxSettings.iecpEnabled) && !((state->cmVeboxSettings.diEnabled) || (state->cmVeboxSettings.dnEnabled)))
447     {
448         veboxDiIecpCmdParams->pOsResCurrOutput = &state->cmVeboxSurfaces[VEBOX_CURRENT_FRAME_OUTPUT_SURF].OsSurface.OsResource;
449         veboxDiIecpCmdParams->CurrOutputSurfCtrl.Value = cmVeboxSurfaceDataInput->surfaceEntry[VEBOX_CURRENT_FRAME_OUTPUT_SURF].surfaceCtrlBits;
450         veboxDiIecpCmdParams->pOsResLaceOrAceOrRgbHistogram = &state->cmVeboxSurfaces[VEBOX_LACE_ACE_RGB_HISTOGRAM_OUTPUT_SURF].OsSurface.OsResource;
451         veboxDiIecpCmdParams->LaceOrAceOrRgbHistogramSurfCtrl.Value = cmVeboxSurfaceDataInput->surfaceEntry[VEBOX_LACE_ACE_RGB_HISTOGRAM_OUTPUT_SURF].surfaceCtrlBits;
452     }
453 
454     if (state->cmVeboxSettings.dnEnabled)
455     {
456         veboxDiIecpCmdParams->pOsResDenoisedCurrOutput = &state->cmVeboxSurfaces[VEBOX_DN_CURRENT_FRAME_OUTPUT_SURF].OsSurface.OsResource;
457         veboxDiIecpCmdParams->DenoisedCurrOutputSurfCtrl.Value = cmVeboxSurfaceDataInput->surfaceEntry[VEBOX_DN_CURRENT_FRAME_OUTPUT_SURF].surfaceCtrlBits;
458     }
459 
460     if (state->cmVeboxSettings.vignetteEnabled)
461     {
462         veboxDiIecpCmdParams->pOsResAlphaOrVignette = &state->cmVeboxSurfaces[VEBOX_ALPHA_VIGNETTE_CORRECTION_SURF].OsSurface.OsResource;
463         veboxDiIecpCmdParams->DenoisedCurrOutputSurfCtrl.Value = cmVeboxSurfaceDataInput->surfaceEntry[VEBOX_DN_CURRENT_FRAME_OUTPUT_SURF].surfaceCtrlBits;
464     }
465 
466     veboxDiIecpCmdParams->pOsResStatisticsOutput = &state->cmVeboxSurfaces[VEBOX_STATISTICS_OUTPUT_SURF].OsSurface.OsResource;
467     veboxDiIecpCmdParams->StatisticsOutputSurfCtrl.Value = cmVeboxSurfaceDataInput->surfaceEntry[VEBOX_STATISTICS_OUTPUT_SURF].surfaceCtrlBits;
468 
469     return MOS_STATUS_SUCCESS;
470 }
471 
472 //| Name   : HalCm_VeboxInitSTMMHistory()
473 //| Purpose: Resets the portion of the Vebox STMM surface associated with
474 //|              motion history for temporal filtering.
475 //|
476 //| Description:
477 //|   This function is used by VEBox for initializing
478 //|   the STMM surface.  The STMM / Denoise history is a custom surface used
479 //|   for both input and output. Each cache line contains data for 4 4x4s.
480 //|   The STMM for each 4x4 is 8 bytes, while the denoise history is 1 byte
481 //|   and the chroma denoise history is 1 byte for each U and V.
482 //|   Byte    Data
483 //|   0       STMM for 2 luma values at luma Y=0, X=0 to 1
484 //|   1       STMM for 2 luma values at luma Y=0, X=2 to 3
485 //|   2       Luma Denoise History for 4x4 at 0,0
486 //|   3       Not Used
487 //|   4-5     STMM for luma from X=4 to 7
488 //|   6       Luma Denoise History for 4x4 at 0,4
489 //|   7       Not Used
490 //|   8-15    Repeat for 4x4s at 0,8 and 0,12
491 //|   16      STMM for 2 luma values at luma Y=1,X=0 to 1
492 //|   17      STMM for 2 luma values at luma Y=1, X=2 to 3
493 //|   18      U Chroma Denoise History
494 //|   19      Not Used
495 //|   20-31   Repeat for 3 4x4s at 1,4, 1,8 and 1,12
496 //|   32      STMM for 2 luma values at luma Y=2,X=0 to 1
497 //|   33      STMM for 2 luma values at luma Y=2, X=2 to 3
498 //|   34      V Chroma Denoise History
499 //|   35      Not Used
500 //|   36-47   Repeat for 3 4x4s at 2,4, 2,8 and 2,12
501 //|   48      STMM for 2 luma values at luma Y=3,X=0 to 1
502 //|   49      STMM for 2 luma values at luma Y=3, X=2 to 3
503 //|   50-51   Not Used
504 //|   36-47   Repeat for 3 4x4s at 3,4, 3,8 and 3,12
505 //|
506 //| Returns: MOS_STATUS_SUCCESS if success. Error code otherwise;
507 //!
HalCm_VeboxInitSTMMHistory(PMOS_INTERFACE osInterface,PRENDERHAL_SURFACE renderHalSTMMSurface)508 MOS_STATUS HalCm_VeboxInitSTMMHistory(
509     PMOS_INTERFACE          osInterface,
510     PRENDERHAL_SURFACE      renderHalSTMMSurface)
511 {
512     MOS_STATUS          eStatus = MOS_STATUS_SUCCESS;
513     uint32_t            size;
514     int32_t             x, y;
515     uint8_t             *bytes;
516     MOS_LOCK_PARAMS     lockFlags;
517 
518     PMOS_SURFACE stmmSurface = &renderHalSTMMSurface->OsSurface;
519 
520     MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS));
521 
522     lockFlags.WriteOnly = 1;
523 
524     // Lock the surface for writing
525     bytes = (uint8_t*)osInterface->pfnLockResource(
526         osInterface,
527         &stmmSurface->OsResource,
528         &lockFlags);
529 
530     CM_CHK_NULL_GOTOFINISH_MOSERROR(bytes);
531 
532     size = stmmSurface->dwWidth >> 2;
533 
534     // Fill STMM surface with DN history init values.
535     for (y = 0; y < (int32_t)stmmSurface->dwHeight; y++)
536     {
537         for (x = 0; x < (int32_t)size; x++)
538         {
539             MOS_FillMemory(bytes, 2, DNDI_HISTORY_INITVALUE);
540             // skip denoise history init.
541             bytes += 4;
542         }
543 
544         bytes += stmmSurface->dwPitch - stmmSurface->dwWidth;
545     }
546 
547     // Unlock the surface
548     CM_CHK_HRESULT_GOTOFINISH_MOSERROR(osInterface->pfnUnlockResource(
549         osInterface,
550         &stmmSurface->OsResource));
551 
552 finish:
553     return eStatus;
554 }
555