• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     decode_filmgrain_applynoise_packet_g12.cpp
24 //! \brief    film grain apply noise kernel render packet which used in by mediapipline.
25 //! \details  film grain apply noise kernel render packet provide the structures and generate the cmd buffer which mediapipline will used.
26 //!
27 
28 #include "decode_filmgrain_applynoise_packet_g12.h"
29 #include "decode_av1_filmgrain_feature_g12.h"
30 #include "decode_av1_feature_defs_g12.h"
31 #include "mos_defs.h"
32 #include "hal_oca_interface.h"
33 #include "codechal_utilities.h"
34 
35 namespace decode
36 {
37 
FilmGrainAppNoisePkt(MediaPipeline * pipeline,MediaTask * task,CodechalHwInterface * hwInterface)38 FilmGrainAppNoisePkt::FilmGrainAppNoisePkt(MediaPipeline *pipeline, MediaTask *task, CodechalHwInterface *hwInterface):
39     CmdPacket(task),
40     RenderCmdPacket(task, hwInterface->GetOsInterface(), hwInterface->GetRenderHalInterface())
41 {
42         if (pipeline != nullptr)
43         {
44             m_statusReport   = pipeline->GetStatusReportInstance();
45             m_featureManager = pipeline->GetFeatureManager();
46             m_av1Pipeline    = dynamic_cast<Av1PipelineG12_Base *>(pipeline);
47         }
48         if (hwInterface != nullptr)
49         {
50             m_hwInterface    = hwInterface;
51             m_miInterface    = hwInterface->GetMiInterface();
52             m_osInterface    = hwInterface->GetOsInterface();
53             m_vdencInterface = hwInterface->GetVdencInterface();
54             m_renderHal      = hwInterface->GetRenderHalInterface();
55         }
56     }
57 
Init()58 MOS_STATUS FilmGrainAppNoisePkt::Init()
59 {
60     DECODE_FUNC_CALL();
61     DECODE_CHK_NULL(m_miInterface);
62     DECODE_CHK_NULL(m_statusReport);
63     DECODE_CHK_NULL(m_featureManager);
64     DECODE_CHK_NULL(m_av1Pipeline);
65     DECODE_CHK_NULL(m_osInterface);
66     DECODE_CHK_NULL(m_vdencInterface);
67 
68     DECODE_CHK_STATUS(RenderCmdPacket::Init());
69 
70     m_av1BasicFeature = dynamic_cast<Av1BasicFeatureG12 *>(m_featureManager->GetFeature(FeatureIDs::basicFeature));
71     DECODE_CHK_NULL(m_av1BasicFeature);
72 
73     m_filmGrainFeature = dynamic_cast<Av1DecodeFilmGrainG12 *>(m_featureManager->GetFeature(Av1FeatureIDs::av1SwFilmGrain));
74     DECODE_CHK_NULL(m_filmGrainFeature);
75 
76     m_allocator = m_av1Pipeline->GetDecodeAllocator();
77     DECODE_CHK_NULL(m_allocator);
78 
79     DECODE_CHK_STATUS(Initilize());
80 
81     return MOS_STATUS_SUCCESS;
82 }
83 
Prepare()84 MOS_STATUS FilmGrainAppNoisePkt::Prepare()
85 {
86     DECODE_FUNC_CALL();
87 
88     DECODE_CHK_NULL(m_hwInterface);
89 
90     m_picParams = m_av1BasicFeature->m_av1PicParams;
91 
92     ResetBindingTableEntry();
93 
94     m_filmGrainProcParams = m_av1BasicFeature->m_filmGrainProcParams;
95 
96     DECODE_CHK_STATUS(RenderEngineSetup());
97     DECODE_CHK_STATUS(KernelStateSetup());
98     DECODE_CHK_STATUS(SetUpSurfaceState());
99     DECODE_CHK_STATUS(SetCurbeApplyNoise(m_filmGrainProcParams));
100     DECODE_CHK_STATUS(LoadKernel());
101 
102     if (m_walkerType == WALKER_TYPE_MEDIA)
103     {
104         DECODE_CHK_STATUS(SetupMediaWalker());
105     }
106     else if (m_walkerType == WALKER_TYPE_COMPUTE)
107     {
108         m_renderData.walkerParam.alignedRect.left   = 0;
109         m_renderData.walkerParam.alignedRect.top    = 0;
110         m_renderData.walkerParam.alignedRect.right  = m_av1BasicFeature->m_filmGrainProcParams->m_outputSurface->dwWidth;
111         m_renderData.walkerParam.alignedRect.bottom = m_av1BasicFeature->m_filmGrainProcParams->m_outputSurface->dwHeight;
112         m_renderData.walkerParam.iCurbeLength       = m_renderData.iCurbeLength;
113         m_renderData.walkerParam.iCurbeOffset       = m_renderData.iCurbeOffset;
114         m_renderData.walkerParam.iBindingTable      = m_renderData.bindingTable;
115         m_renderData.walkerParam.iMediaID           = m_renderData.mediaID;
116         m_renderData.walkerParam.iBlocksX           = m_renderData.KernelParam.blocks_x;
117         m_renderData.walkerParam.iBlocksY           = m_renderData.KernelParam.blocks_y;
118         DECODE_CHK_STATUS(PrepareComputeWalkerParams(m_renderData.walkerParam, m_gpgpuWalkerParams));
119     }
120     else
121     {
122         DECODE_ASSERTMESSAGE("Walker is disabled!");
123         return MOS_STATUS_UNKNOWN;
124     }
125 
126     return MOS_STATUS_SUCCESS;
127 }
128 
Submit(MOS_COMMAND_BUFFER * commandBuffer,uint8_t packetPhase)129 MOS_STATUS FilmGrainAppNoisePkt::Submit(MOS_COMMAND_BUFFER *commandBuffer, uint8_t packetPhase)
130 {
131     PMOS_INTERFACE                  pOsInterface = nullptr;
132     MOS_STATUS                      eStatus      = MOS_STATUS_SUCCESS;
133     uint32_t                        dwSyncTag    = 0;
134     int32_t                         i = 0, iRemaining = 0;
135     PMHW_MI_INTERFACE               pMhwMiInterface     = nullptr;
136     MhwRenderInterface *            pMhwRender          = nullptr;
137     MHW_MEDIA_STATE_FLUSH_PARAM     FlushParam          = {};
138     bool                            bEnableSLM          = false;
139     RENDERHAL_GENERIC_PROLOG_PARAMS GenericPrologParams = {};
140     MOS_RESOURCE                    GpuStatusBuffer     = {};
141     MediaPerfProfiler *             pPerfProfiler       = nullptr;
142     MOS_CONTEXT *                   pOsContext          = nullptr;
143     PMHW_MI_MMIOREGISTERS           pMmioRegisters      = nullptr;
144     PRENDERHAL_INTERFACE_LEGACY     pRenderHalLegacy    = (PRENDERHAL_INTERFACE_LEGACY)m_renderHal;
145 
146     RENDER_PACKET_CHK_NULL_RETURN(pRenderHalLegacy);
147     RENDER_PACKET_CHK_NULL_RETURN(pRenderHalLegacy->pMhwRenderInterface);
148     RENDER_PACKET_CHK_NULL_RETURN(pRenderHalLegacy->pMhwMiInterface);
149     RENDER_PACKET_CHK_NULL_RETURN(pRenderHalLegacy->pMhwRenderInterface->GetMmioRegisters());
150     RENDER_PACKET_CHK_NULL_RETURN(pRenderHalLegacy->pOsInterface);
151     RENDER_PACKET_CHK_NULL_RETURN(pRenderHalLegacy->pOsInterface->pOsContext);
152 
153     eStatus         = MOS_STATUS_UNKNOWN;
154     pOsInterface    = pRenderHalLegacy->pOsInterface;
155     pMhwMiInterface = pRenderHalLegacy->pMhwMiInterface;
156     pMhwRender      = pRenderHalLegacy->pMhwRenderInterface;
157     iRemaining      = 0;
158     FlushParam      = g_cRenderHal_InitMediaStateFlushParams;
159     pPerfProfiler   = pRenderHalLegacy->pPerfProfiler;
160     pOsContext      = pOsInterface->pOsContext;
161     pMmioRegisters  = pMhwRender->GetMmioRegisters();
162 
163     RENDER_PACKET_CHK_STATUS_RETURN(SetPowerMode(CODECHAl_MEDIA_STATE_AV1_FILM_GRAIN_AN));
164 
165     PMOS_RESOURCE resource = nullptr;
166     uint32_t      offset   = 0;
167     DECODE_CHK_STATUS(m_statusReport->GetAddress(decode::statusReportGlobalCount, resource, offset));
168 
169     GenericPrologParams.bEnableMediaFrameTracking     = true;
170     GenericPrologParams.presMediaFrameTrackingSurface = resource;
171     GenericPrologParams.dwMediaFrameTrackingTag       = m_statusReport->GetSubmittedCount() + 1;
172     // Set media frame tracking address offset(the offset from the decoder status buffer page)
173     GenericPrologParams.dwMediaFrameTrackingAddrOffset = offset;
174     // Initialize command buffer and insert prolog
175     RENDER_PACKET_CHK_STATUS_RETURN(pRenderHalLegacy->pfnInitCommandBuffer(pRenderHalLegacy, commandBuffer, &GenericPrologParams));
176     RENDER_PACKET_CHK_STATUS_RETURN(StartStatusReport(statusReportRcs, commandBuffer));
177 
178     HalOcaInterface::On1stLevelBBStart(*commandBuffer, *m_osInterface->pOsContext, m_osInterface->CurrentGpuContextHandle,
179         *m_hwInterface->GetMiInterface(), *m_hwInterface->GetMiInterface()->GetMmioRegisters());
180     HalOcaInterface::TraceMessage(*commandBuffer, (MOS_CONTEXT_HANDLE)m_osInterface->pOsContext, __FUNCTION__, sizeof(__FUNCTION__));
181 
182     if (pOsInterface && !m_av1BasicFeature->m_singleKernelPerfFlag)
183     {
184         RENDER_PACKET_CHK_STATUS_RETURN(pPerfProfiler->AddPerfCollectStartCmd((void *)pRenderHalLegacy, pOsInterface, pMhwMiInterface, commandBuffer));
185     }
186 
187     // Write timing data for 3P budget
188     RENDER_PACKET_CHK_STATUS_RETURN(pRenderHalLegacy->pfnSendTimingData(pRenderHalLegacy, commandBuffer, true));
189 
190     bEnableSLM = false;  // Media walker first
191     RENDER_PACKET_CHK_STATUS_RETURN(pRenderHalLegacy->pfnSetCacheOverrideParams(
192         pRenderHalLegacy,
193         &pRenderHalLegacy->L3CacheSettings,
194         bEnableSLM));
195 
196     // Flush media states
197     RENDER_PACKET_CHK_STATUS_RETURN(pRenderHalLegacy->pfnSendMediaStates(
198         pRenderHalLegacy,
199         commandBuffer,
200         m_walkerType == WALKER_TYPE_MEDIA ? &m_mediaWalkerParams : nullptr,
201         m_walkerType == WALKER_TYPE_MEDIA ? nullptr : &m_gpgpuWalkerParams));
202 
203     // Write back GPU Status tag
204     if (!pOsInterface->bEnableKmdMediaFrameTracking)
205     {
206         RENDER_PACKET_CHK_STATUS_RETURN(pRenderHalLegacy->pfnSendRcsStatusTag(pRenderHalLegacy, commandBuffer));
207     }
208 
209     RENDER_PACKET_CHK_STATUS_RETURN(pPerfProfiler->AddPerfCollectEndCmd((void *)pRenderHalLegacy, pOsInterface, pMhwMiInterface, commandBuffer));
210 
211     // Write timing data for 3P budget
212     RENDER_PACKET_CHK_STATUS_RETURN(pRenderHalLegacy->pfnSendTimingData(pRenderHalLegacy, commandBuffer, false));
213 
214     MHW_PIPE_CONTROL_PARAMS PipeControlParams;
215 
216     MOS_ZeroMemory(&PipeControlParams, sizeof(PipeControlParams));
217     PipeControlParams.dwFlushMode                   = MHW_FLUSH_WRITE_CACHE;
218     PipeControlParams.bGenericMediaStateClear       = false;
219     PipeControlParams.bIndirectStatePointersDisable = true;
220     PipeControlParams.bDisableCSStall               = false;
221     RENDER_PACKET_CHK_STATUS_RETURN(pMhwMiInterface->AddPipeControl(commandBuffer, nullptr, &PipeControlParams));
222 
223     if (MEDIA_IS_WA(pRenderHalLegacy->pWaTable, WaSendDummyVFEafterPipelineSelect))
224     {
225         MHW_VFE_PARAMS VfeStateParams       = {};
226         VfeStateParams.dwNumberofURBEntries = 1;
227         RENDER_PACKET_CHK_STATUS_RETURN(pMhwRender->AddMediaVfeCmd(commandBuffer, &VfeStateParams));
228     }
229 
230     // Add media flush command in case HW not cleaning the media state
231     if (MEDIA_IS_WA(pRenderHalLegacy->pWaTable, WaMSFWithNoWatermarkTSGHang))
232     {
233         FlushParam.bFlushToGo = true;
234         if (m_walkerType == WALKER_TYPE_MEDIA)
235         {
236             FlushParam.ui8InterfaceDescriptorOffset = m_mediaWalkerParams.InterfaceDescriptorOffset;
237         }
238         else
239         {
240             RENDER_PACKET_ASSERTMESSAGE("ERROR, pWalkerParams is nullptr and cannot get InterfaceDescriptorOffset.");
241         }
242         RENDER_PACKET_CHK_STATUS_RETURN(pMhwMiInterface->AddMediaStateFlush(commandBuffer, nullptr, &FlushParam));
243     }
244     else if (MEDIA_IS_WA(pRenderHalLegacy->pWaTable, WaAddMediaStateFlushCmd))
245     {
246         RENDER_PACKET_CHK_STATUS_RETURN(pMhwMiInterface->AddMediaStateFlush(commandBuffer, nullptr, &FlushParam));
247     }
248 
249     //Status report
250     DECODE_CHK_STATUS(EndStatusReport(statusReportRcs, commandBuffer));
251     DECODE_CHK_STATUS(UpdateStatusReport(statusReportGlobalCount, commandBuffer));
252 
253     HalOcaInterface::On1stLevelBBEnd(*commandBuffer, *m_osInterface);
254 
255     if (pBatchBuffer)
256     {
257         // Send Batch Buffer end command (HW/OS dependent)
258         RENDER_PACKET_CHK_STATUS_RETURN(pMhwMiInterface->AddMiBatchBufferEnd(commandBuffer, nullptr));
259     }
260     else if (IsMiBBEndNeeded(pOsInterface))
261     {
262         // Send Batch Buffer end command for 1st level Batch Buffer
263         RENDER_PACKET_CHK_STATUS_RETURN(pMhwMiInterface->AddMiBatchBufferEnd(commandBuffer, nullptr));
264     }
265     else if (pRenderHalLegacy->pOsInterface->bNoParsingAssistanceInKmd)
266     {
267         RENDER_PACKET_CHK_STATUS_RETURN(pMhwMiInterface->AddMiBatchBufferEnd(commandBuffer, nullptr));
268     }
269 
270     // Return unused command buffer space to OS
271     pOsInterface->pfnReturnCommandBuffer(pOsInterface, commandBuffer, 0);
272 
273     MOS_NULL_RENDERING_FLAGS NullRenderingFlags = pOsInterface->pfnGetNullHWRenderFlags(pOsInterface);
274 
275     if ((NullRenderingFlags.VPLgca ||
276             NullRenderingFlags.VPGobal) == false)
277     {
278         dwSyncTag = pRenderHalLegacy->pStateHeap->dwNextTag++;
279 
280         // Set media state and batch buffer as busy
281         pRenderHalLegacy->pStateHeap->pCurMediaState->bBusy = true;
282         if (pBatchBuffer)
283         {
284             pBatchBuffer->bBusy     = true;
285             pBatchBuffer->dwSyncTag = dwSyncTag;
286         }
287     }
288 
289     return MOS_STATUS_SUCCESS;
290 }
291 
SetupMediaWalker()292 MOS_STATUS FilmGrainAppNoisePkt::SetupMediaWalker()
293 {
294     DECODE_FUNC_CALL();
295 
296     DECODE_CHK_NULL(m_hwInterface);
297 
298     // Current only add Media Walker Support in film Grain
299     m_walkerType = WALKER_TYPE_MEDIA;
300 
301     uint32_t resolutionX = MOS_ROUNDUP_DIVIDE(m_picParams->m_superResUpscaledWidthMinus1 + 1, 32);
302     uint32_t resolutionY = MOS_ROUNDUP_DIVIDE(m_picParams->m_superResUpscaledHeightMinus1 + 1, 8);
303 
304     CODECHAL_WALKER_CODEC_PARAMS walkerCodecParams;
305     memset(&walkerCodecParams, 0, sizeof(walkerCodecParams));
306     walkerCodecParams.WalkerMode    = MHW_WALKER_MODE_DUAL;
307     walkerCodecParams.dwResolutionX = resolutionX;
308     walkerCodecParams.dwResolutionY = resolutionY;
309     walkerCodecParams.bNoDependency = true;  // raster scan mode
310 
311     DECODE_CHK_STATUS(CodecHalInitMediaObjectWalkerParams(m_hwInterface, &m_mediaWalkerParams, &walkerCodecParams));
312 
313     return MOS_STATUS_SUCCESS;
314 }
315 
Initilize()316 MOS_STATUS FilmGrainAppNoisePkt::Initilize()
317 {
318     m_kernelIndex = applyNoise;
319 
320     return MOS_STATUS_SUCCESS;
321 }
322 
KernelStateSetup()323 MOS_STATUS FilmGrainAppNoisePkt::KernelStateSetup()
324 {
325     MHW_KERNEL_STATE *kernelState = &m_filmGrainFeature->m_kernelStates[m_kernelIndex];
326     uint32_t          btCount     = m_filmGrainFeature->m_filmGrainBindingTableCount[m_kernelIndex];
327     int32_t           curbeLength = m_filmGrainFeature->m_filmGrainCurbeSize[m_kernelIndex];
328     m_kernelCount                 = 1;
329 
330     PRENDERHAL_INTERFACE_LEGACY pRenderHalLegacy = (PRENDERHAL_INTERFACE_LEGACY)m_renderHal;
331     // Initialize States
332     MOS_ZeroMemory(m_filter, sizeof(Kdll_FilterEntry));
333     MOS_ZeroMemory(&m_renderData.KernelEntry, sizeof(Kdll_CacheEntry));
334 
335     // Set Kernel Parameter
336     m_renderData.KernelParam.GRF_Count          = 0;
337     m_renderData.KernelParam.BT_Count           = btCount;
338     m_renderData.KernelParam.Sampler_Count      = 0;
339     m_renderData.KernelParam.Thread_Count       = pRenderHalLegacy->pMhwRenderInterface->GetHwCaps()->dwMaxThreads;
340     m_renderData.KernelParam.GRF_Start_Register = 0;
341     m_renderData.KernelParam.CURBE_Length       = curbeLength;
342     m_renderData.KernelParam.block_width        = CODECHAL_MACROBLOCK_WIDTH;
343     m_renderData.KernelParam.block_height       = CODECHAL_MACROBLOCK_HEIGHT;
344 
345     //Set per kernel
346     uint32_t resolutionX              = MOS_ROUNDUP_DIVIDE(m_picParams->m_superResUpscaledWidthMinus1 + 1, 32);
347     uint32_t resolutionY              = MOS_ROUNDUP_DIVIDE(m_picParams->m_superResUpscaledHeightMinus1 + 1, 8);
348     m_renderData.KernelParam.blocks_x = resolutionX;
349     m_renderData.KernelParam.blocks_y = resolutionY;
350 
351     m_renderData.iCurbeOffset = pRenderHalLegacy->pMhwStateHeap->GetSizeofCmdInterfaceDescriptorData();
352 
353     // Set Parameters for Kernel Entry
354     m_renderData.KernelEntry.iKUID       = 0;
355     m_renderData.KernelEntry.iKCID       = m_kernelIndex;
356     m_renderData.KernelEntry.iFilterSize = 2;
357     m_renderData.KernelEntry.pFilter     = m_filter;
358     m_renderData.KernelEntry.iSize       = kernelState->KernelParams.iSize;
359     m_renderData.KernelEntry.pBinary     = kernelState->KernelParams.pBinary;
360 
361     // Set Curbe/Inline Data length
362     m_renderData.iInlineLength  = 0;
363     m_renderData.iCurbeLength   = 0;
364 
365     return MOS_STATUS_SUCCESS;
366 }
367 
SetUpSurfaceState()368 MOS_STATUS FilmGrainAppNoisePkt::SetUpSurfaceState()
369 {
370     DECODE_FUNC_CALL();
371 
372     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
373 
374     // Input YUV surface
375     RENDERHAL_SURFACE_NEXT renderHalSurfaceNext;
376     MOS_ZeroMemory(&renderHalSurfaceNext, sizeof(RENDERHAL_SURFACE_NEXT));
377 
378     bool                           isWritable = false;
379     RENDERHAL_SURFACE_STATE_PARAMS surfaceParams;
380     MOS_ZeroMemory(&surfaceParams, sizeof(RENDERHAL_SURFACE_STATE_PARAMS));
381     surfaceParams.MemObjCtl         = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_ELLC_LLC_L3].Value;
382     surfaceParams.isOutput     = true;
383     surfaceParams.Boundary          = RENDERHAL_SS_BOUNDARY_ORIGINAL;
384     if (m_hwInterface->Uses2PlanesInputSurfaceFilmGrain())
385     {
386         surfaceParams.b2PlaneNV12NeededByKernel = true;
387     }
388     else
389     {
390         surfaceParams.bUseSinglePlane      = true;
391         renderHalSurfaceNext.dwHeightInUse = (m_filmGrainProcParams->m_inputSurface->UPlaneOffset.iYOffset * 3) / 2;
392         renderHalSurfaceNext.dwWidthInUse  = 0;
393     }
394 
395     m_bindingTableIndex[anInputYOrYuv] = SetSurfaceForHwAccess(
396         m_filmGrainProcParams->m_inputSurface,
397         &renderHalSurfaceNext,
398         &surfaceParams,
399         isWritable);
400 
401     if (m_hwInterface->Uses2PlanesInputSurfaceFilmGrain())
402     {
403         m_bindingTableIndex[anInputUv] = m_bindingTableIndex[anInputYOrYuv] + 1;
404         DECODE_VERBOSEMESSAGE("AN:surface[%d] Input Y surface index: %d\n", anInputYOrYuv, m_bindingTableIndex[anInputYOrYuv]);
405         DECODE_VERBOSEMESSAGE("AN:surface[%d] Input UV surface index: %d\n", anInputUv, m_bindingTableIndex[anInputUv]);
406     }
407     else
408     {
409         DECODE_VERBOSEMESSAGE("AN:surface[%d] Input YUV surface index: %d\n", anInputYOrYuv, m_bindingTableIndex[anInputYOrYuv]);
410     }
411 
412     // Output Y/UV surface
413     isWritable                  = true;
414     MOS_ZeroMemory(&surfaceParams, sizeof(surfaceParams));
415     surfaceParams.MemObjCtl     = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_ELLC_LLC_L3].Value;
416     surfaceParams.isOutput = true;
417     surfaceParams.Boundary      = RENDERHAL_SS_BOUNDARY_ORIGINAL;
418     surfaceParams.bWidthInDword_Y = true;
419     surfaceParams.bWidthInDword_UV = true;
420 
421     MOS_ZeroMemory(&renderHalSurfaceNext, sizeof(RENDERHAL_SURFACE_NEXT));
422     m_bindingTableIndex[anOutputY] = SetSurfaceForHwAccess(
423         m_filmGrainProcParams->m_outputSurface,
424         &renderHalSurfaceNext,
425         &surfaceParams,
426         isWritable);
427     m_bindingTableIndex[anOutputUv] = m_bindingTableIndex[anOutputY] + 1;
428     DECODE_VERBOSEMESSAGE("AN:surface[%d] Output Y surface index: %d\n", anOutputY, m_bindingTableIndex[anOutputY]);
429     DECODE_VERBOSEMESSAGE("AN:surface[%d] Output UV surface index: %d\n", anOutputUv, m_bindingTableIndex[anOutputUv]);
430 
431     //Y dithering surface - input
432     isWritable                  = true;
433     MOS_ZeroMemory(&surfaceParams, sizeof(RENDERHAL_SURFACE_STATE_PARAMS));
434     surfaceParams.MemObjCtl     = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_ELLC_LLC_L3].Value;
435     surfaceParams.isOutput = true;
436     surfaceParams.Boundary      = RENDERHAL_SS_BOUNDARY_ORIGINAL;
437     MOS_ZeroMemory(&renderHalSurfaceNext, sizeof(RENDERHAL_SURFACE_NEXT));
438     m_bindingTableIndex[anInputYDithering] = SetSurfaceForHwAccess(
439         m_filmGrainFeature->m_yDitheringSurface,
440         &renderHalSurfaceNext,
441         &surfaceParams,
442         isWritable);
443     DECODE_VERBOSEMESSAGE("AN:surface[%d] Input Y dithering surface BT index: %d\n", anInputYDithering, m_bindingTableIndex[anInputYDithering]);
444 
445     //U dithering surface - input
446     isWritable                  = true;
447     MOS_ZeroMemory(&surfaceParams, sizeof(RENDERHAL_SURFACE_STATE_PARAMS));
448     surfaceParams.MemObjCtl     = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_ELLC_LLC_L3].Value;
449     surfaceParams.isOutput = true;
450     surfaceParams.Boundary      = RENDERHAL_SS_BOUNDARY_ORIGINAL;
451     MOS_ZeroMemory(&renderHalSurfaceNext, sizeof(RENDERHAL_SURFACE_NEXT));
452     m_bindingTableIndex[anInputUDithering] = SetSurfaceForHwAccess(
453         m_filmGrainFeature->m_uDitheringSurface,
454         &renderHalSurfaceNext,
455         &surfaceParams,
456         isWritable);
457     DECODE_VERBOSEMESSAGE("AN:surface[%d] Input U dithering surface BT index: %d\n", anInputUDithering, m_bindingTableIndex[anInputUDithering]);
458 
459     //V dithering surface - input
460     isWritable                  = true;
461     MOS_ZeroMemory(&surfaceParams, sizeof(RENDERHAL_SURFACE_STATE_PARAMS));
462     surfaceParams.MemObjCtl     = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_ELLC_LLC_L3].Value;
463     surfaceParams.isOutput = true;
464     surfaceParams.Boundary      = RENDERHAL_SS_BOUNDARY_ORIGINAL;
465     MOS_ZeroMemory(&renderHalSurfaceNext, sizeof(RENDERHAL_SURFACE_NEXT));
466     m_bindingTableIndex[anInputVDithering] = SetSurfaceForHwAccess(
467         m_filmGrainFeature->m_vDitheringSurface,
468         &renderHalSurfaceNext,
469         &surfaceParams,
470         isWritable);
471     DECODE_VERBOSEMESSAGE("AN:surface[%d] Input V dithering surface BT index: %d\n", anInputVDithering, m_bindingTableIndex[anInputVDithering]);
472 
473     //Coordinates random values - input
474     isWritable = true;
475     MOS_ZeroMemory(&surfaceParams, sizeof(RENDERHAL_SURFACE_STATE_PARAMS));
476     surfaceParams.MemObjCtl     = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_ELLC_LLC_L3].Value;
477     surfaceParams.isOutput = true;
478     surfaceParams.Boundary      = RENDERHAL_SS_BOUNDARY_ORIGINAL;
479     surfaceParams.bBufferUse    = true;
480     MOS_ZeroMemory(&renderHalSurfaceNext, sizeof(RENDERHAL_SURFACE_NEXT));
481     m_bindingTableIndex[anInputRandomValuesCoordinates] = SetBufferForHwAccess(
482         *m_filmGrainFeature->m_coordinatesRandomValuesSurface,
483         &renderHalSurfaceNext,
484         &surfaceParams,
485         isWritable);
486     DECODE_VERBOSEMESSAGE("AN:surface[%d] Coordinate random values BT index: %d\n", anInputRandomValuesCoordinates, m_bindingTableIndex[anInputRandomValuesCoordinates]);
487 
488     //Y Gamma LUT surface - input
489     isWritable                 = false;
490     m_filmGrainFeature->m_yGammaLUTSurface->size   = MOS_ALIGN_CEIL(257 * sizeof(int16_t), CODECHAL_PAGE_SIZE);
491 
492     MOS_ZeroMemory(&surfaceParams, sizeof(RENDERHAL_SURFACE_STATE_PARAMS));
493     surfaceParams.MemObjCtl     = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_ELLC_LLC_L3].Value;
494     surfaceParams.isOutput = false;
495     surfaceParams.Boundary      = RENDERHAL_SS_BOUNDARY_ORIGINAL;
496     surfaceParams.bBufferUse    = true;
497 
498     MOS_ZeroMemory(&renderHalSurfaceNext, sizeof(RENDERHAL_SURFACE_NEXT));
499     m_bindingTableIndex[anInputYGammaLut] = SetBufferForHwAccess(
500         *m_filmGrainFeature->m_yGammaLUTSurface,
501         &renderHalSurfaceNext,
502         &surfaceParams,
503         isWritable);
504     DECODE_VERBOSEMESSAGE("AN:surface[%d] Input Y Gamma LUT BT index: %d\n", anInputYGammaLut, m_bindingTableIndex[anInputYGammaLut]);
505 
506     //U Gamma LUT surface - input
507     isWritable               = false;
508     m_filmGrainFeature->m_uGammaLUTSurface->size = MOS_ALIGN_CEIL(257 * sizeof(int16_t), CODECHAL_PAGE_SIZE);
509 
510     MOS_ZeroMemory(&surfaceParams, sizeof(RENDERHAL_SURFACE_STATE_PARAMS));
511     surfaceParams.MemObjCtl     = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_ELLC_LLC_L3].Value;
512     surfaceParams.isOutput = false;
513     surfaceParams.Boundary      = RENDERHAL_SS_BOUNDARY_ORIGINAL;
514     surfaceParams.bBufferUse    = true;
515 
516     MOS_ZeroMemory(&renderHalSurfaceNext, sizeof(RENDERHAL_SURFACE_NEXT));
517     m_bindingTableIndex[anInputUGammaLut] = SetBufferForHwAccess(
518         *m_filmGrainFeature->m_uGammaLUTSurface,
519         &renderHalSurfaceNext,
520         &surfaceParams,
521         isWritable);
522     DECODE_VERBOSEMESSAGE("AN:surface[%d] Input U Gamma LUT BT index: %d\n", anInputUGammaLut, m_bindingTableIndex[anInputUGammaLut]);
523 
524     //V Gamma LUT surface - input
525     isWritable               = false;
526     m_filmGrainFeature->m_vGammaLUTSurface->size = MOS_ALIGN_CEIL(257 * sizeof(int16_t), CODECHAL_PAGE_SIZE);
527 
528     MOS_ZeroMemory(&surfaceParams, sizeof(RENDERHAL_SURFACE_STATE_PARAMS));
529     surfaceParams.MemObjCtl     = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_ELLC_LLC_L3].Value;
530     surfaceParams.isOutput = false;
531     surfaceParams.Boundary      = RENDERHAL_SS_BOUNDARY_ORIGINAL;
532     surfaceParams.bBufferUse    = true;
533 
534     MOS_ZeroMemory(&renderHalSurfaceNext, sizeof(RENDERHAL_SURFACE_NEXT));
535     m_bindingTableIndex[anInputVGammaLut] = SetBufferForHwAccess(
536         *m_filmGrainFeature->m_vGammaLUTSurface,
537         &renderHalSurfaceNext,
538         &surfaceParams,
539         isWritable);
540     DECODE_VERBOSEMESSAGE("AN:surface[%d] Input V Gamma LUT BT index: %d\n", anInputVGammaLut, m_bindingTableIndex[anInputVGammaLut]);
541 
542     return MOS_STATUS_SUCCESS;
543 }
544 
SetCurbeApplyNoise(FilmGrainProcParams * procParams)545 MOS_STATUS FilmGrainAppNoisePkt::SetCurbeApplyNoise(
546     FilmGrainProcParams *procParams)
547 {
548     DECODE_FUNC_CALL();
549 
550     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
551 
552     CodecAv1FilmGrainParams *filmGrainParams = (CodecAv1FilmGrainParams *)&m_picParams->m_filmGrainParams;
553 
554     DECODE_CHK_NULL(procParams);
555     DECODE_CHK_NULL(procParams->m_inputSurface);
556     DECODE_CHK_NULL(procParams->m_outputSurface);
557 
558     MOS_SURFACE *inputSurface  = procParams->m_inputSurface;
559     MOS_SURFACE *outputSurface = procParams->m_outputSurface;
560 
561     FilmGrainApplyNoiseCurbe curbe;
562 
563     curbe.DW0.InputYuvSurfaceIndex                   = m_bindingTableIndex[anInputYOrYuv];
564     curbe.DW1.OutputYSurfaceIndex                    = m_bindingTableIndex[anOutputY];
565     curbe.DW2.OutputUvSurfaceIndex                   = m_bindingTableIndex[anOutputUv];
566     curbe.DW3.YDitheringSurfaceIndex                 = m_bindingTableIndex[anInputYDithering];
567     curbe.DW4.UDitheringSurfaceIndex                 = m_bindingTableIndex[anInputUDithering];
568     curbe.DW5.VDitheringSurfaceIndex                 = m_bindingTableIndex[anInputVDithering];
569     curbe.DW6.RandomValuesForCoordinatesSurfaceIndex = m_bindingTableIndex[anInputRandomValuesCoordinates];
570     curbe.DW7.YGammaCorrectionLutSurfaceIndex        = m_bindingTableIndex[anInputYGammaLut];
571     curbe.DW8.UGammaCorrectionLutSurfaceIndex        = m_bindingTableIndex[anInputUGammaLut];
572     curbe.DW9.VGammaCorrectionLutSurfaceIndex        = m_bindingTableIndex[anInputVGammaLut];
573 
574     int apply_y  = (m_picParams->m_filmGrainParams.m_numYPoints > 0) ? 1 : 0;
575     int apply_cb = (m_picParams->m_filmGrainParams.m_numCbPoints > 0 || m_picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_chromaScalingFromLuma) ? 1 : 0;
576     int apply_cr = (m_picParams->m_filmGrainParams.m_numCrPoints > 0 || m_picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_chromaScalingFromLuma) ? 1 : 0;
577 
578     curbe.DW10.EnableYFilmGrain                     = apply_y;
579     curbe.DW10.EnableUFilmGrain                     = apply_cb;
580     curbe.DW11.EnableVFilmGrain                     = apply_cr;
581     curbe.DW11.RandomValuesForCoordinatesTableWidth = MOS_ROUNDUP_SHIFT(m_picParams->m_superResUpscaledWidthMinus1 + 1, 6);
582     curbe.DW12.ImageHeight                          = inputSurface->UPlaneOffset.iYOffset;  //specify UV vertical offset
583     curbe.DW12.ScalingShiftValue                    = m_picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_grainScalingMinus8 + 8;
584 
585     int32_t minLuma, maxLuma, minChroma, maxChroma;
586     int32_t bitDepth = m_picParams->m_bitDepthIdx? 10:8;//m_bitDepthIndicator ? 10 : 8;
587     if (m_picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_clipToRestrictedRange)
588     {
589         minLuma = m_minLumaLegalRange << (bitDepth - 8);
590         maxLuma = m_maxLumaLegalRange << (bitDepth - 8);
591 
592         if (m_picParams->m_matrixCoefficients == mcIdentity)
593         {
594             minChroma = m_minLumaLegalRange << (bitDepth - 8);
595             maxChroma = m_maxLumaLegalRange << (bitDepth - 8);
596         }
597         else
598         {
599             minChroma = m_minChromaLegalRange << (bitDepth - 8);
600             maxChroma = m_maxChromaLegalRange << (bitDepth - 8);
601         }
602     }
603     else
604     {
605         minLuma = minChroma = 0;
606         maxLuma = maxChroma = (256 << (bitDepth - 8)) - 1;
607     }
608 
609     curbe.DW13.MaximumYClippingValue  = maxLuma;
610     curbe.DW13.MinimumYClippingValue  = minLuma;
611     curbe.DW14.MaximumUvClippingValue = maxChroma;
612     curbe.DW14.MinimumUvClippingValue = minChroma;
613 
614     int32_t cbMult     = m_picParams->m_filmGrainParams.m_cbMult - 128;
615     int32_t cbLumaMult = m_picParams->m_filmGrainParams.m_cbLumaMult - 128;
616     int32_t cbOffset   = (m_picParams->m_filmGrainParams.m_cbOffset << (bitDepth - 8)) - (1 << bitDepth);
617     int32_t crMult     = m_picParams->m_filmGrainParams.m_crMult - 128;
618     int32_t crLumaMult = m_picParams->m_filmGrainParams.m_crLumaMult - 128;
619     int32_t crOffset   = (m_picParams->m_filmGrainParams.m_crOffset << (bitDepth - 8)) - (1 << bitDepth);
620 
621     if (m_picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_chromaScalingFromLuma)
622     {
623         cbMult     = 0;
624         cbLumaMult = 64;
625         cbOffset   = 0;
626 
627         crMult     = 0;
628         crLumaMult = 64;
629         crOffset   = 0;
630     }
631     curbe.DW15.CbLumaMultiplier = cbLumaMult;
632     curbe.DW15.CbMultiplier     = cbMult;
633     curbe.DW16.CbOffset         = cbOffset;
634     curbe.DW16.CrLumaMultiplier = crLumaMult;
635     curbe.DW17.CrMultiplier     = crMult;
636     curbe.DW17.CrOffset         = crOffset;
637 
638     DECODE_CHK_STATUS(SetupCurbe(
639         &curbe,
640         sizeof(FilmGrainApplyNoiseCurbe),
641         m_renderData.KernelParam.Thread_Count));
642 
643     return eStatus;
644 }
645 
CalculateCommandSize(uint32_t & commandBufferSize,uint32_t & requestedPatchListSize)646 MOS_STATUS FilmGrainAppNoisePkt::CalculateCommandSize(uint32_t &commandBufferSize, uint32_t &requestedPatchListSize)
647 {
648     DECODE_FUNC_CALL();
649 
650     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
651 
652     commandBufferSize      = m_hwInterface->GetKernelLoadCommandSize(m_renderData.KernelParam.BT_Count);
653     requestedPatchListSize = 0;
654 
655     return MOS_STATUS_SUCCESS;
656 }
657 
658 }
659