1 /*
2 * Copyright (c) 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 //!
24 //! \file     decode_filmgrain_surf_init_g12.cpp
25 //! \brief    Defines the preSubpipeline for film grain surface init
26 //! \details  Defines the preSubpipeline for film grain surface init, initialize coordinate surface with 0 per kernel requirement.
27 //!
28 #include "decode_filmgrain_surf_init_g12.h"
29 #include "decode_av1_feature_defs_g12.h"
30 #include "decode_pipeline.h"
31 #include "decode_av1_filmgrain_feature_g12.h"
32 
33 namespace decode {
34 
FilmGrainSurfaceInit(DecodePipeline * pipeline,MediaTask * task,uint8_t numVdbox,CodechalHwInterface * hwInterface)35 FilmGrainSurfaceInit::FilmGrainSurfaceInit(DecodePipeline *pipeline, MediaTask *task, uint8_t numVdbox, CodechalHwInterface *hwInterface)
36     : DecodeSubPipeline(pipeline, task, numVdbox)
37 {
38     m_hwInterface = hwInterface;
39 }
40 
~FilmGrainSurfaceInit()41 FilmGrainSurfaceInit::~FilmGrainSurfaceInit()
42 {
43     m_allocator->Destroy(m_tmpInitBuf);
44 }
45 
Init(CodechalSetting & settings)46 MOS_STATUS FilmGrainSurfaceInit::Init(CodechalSetting &settings)
47 {
48     DECODE_CHK_NULL(m_pipeline);
49 
50     CodechalHwInterface* hwInterface = m_hwInterface;
51     DECODE_CHK_NULL(hwInterface);
52     PMOS_INTERFACE osInterface = hwInterface->GetOsInterface();
53     DECODE_CHK_NULL(osInterface);
54     InitScalabilityPars(osInterface);
55 
56     m_allocator = m_pipeline->GetDecodeAllocator();
57     DECODE_CHK_NULL(m_allocator);
58 
59     MediaFeatureManager* featureManager = m_pipeline->GetFeatureManager();
60     DECODE_CHK_NULL(featureManager);
61     m_filmGrainFeature = dynamic_cast<Av1DecodeFilmGrainG12 *>(featureManager->GetFeature(Av1FeatureIDs::av1SwFilmGrain));
62     DECODE_CHK_NULL(m_filmGrainFeature);
63 
64     m_surfInitPkt             = MOS_New(HucCopyPktG12, m_pipeline, m_task, hwInterface);
65     DECODE_CHK_NULL(m_surfInitPkt);
66     Av1PipelineG12 *pipeline = dynamic_cast<Av1PipelineG12 *>(m_pipeline);
67     DECODE_CHK_NULL(pipeline);
68     DECODE_CHK_STATUS(RegisterPacket(DecodePacketId(pipeline, hucCopyPacketId), *m_surfInitPkt));
69     DECODE_CHK_STATUS(m_surfInitPkt->Init());
70 
71     return MOS_STATUS_SUCCESS;
72 }
73 
Prepare(DecodePipelineParams & params)74 MOS_STATUS FilmGrainSurfaceInit::Prepare(DecodePipelineParams &params)
75 {
76     if (params.m_pipeMode == decodePipeModeBegin)
77     {
78         DECODE_CHK_STATUS(Begin());
79     }
80     else if (params.m_pipeMode == decodePipeModeProcess)
81     {
82         /*DON't use m_filmGrainFeature->m_filmGrainEnabled*/
83         if (m_filmGrainFeature->m_picParams->m_filmGrainParams.m_filmGrainInfoFlags.m_fields.m_applyGrain)
84         {
85             InitCoordinateSurface();
86         }
87     }
88 
89     return MOS_STATUS_SUCCESS;
90 }
91 
Begin()92 MOS_STATUS FilmGrainSurfaceInit::Begin()
93 {
94     DECODE_CHK_STATUS(DecodeSubPipeline::Reset());
95     return MOS_STATUS_SUCCESS;
96 }
97 
InitCoordinateSurface()98 MOS_STATUS FilmGrainSurfaceInit::InitCoordinateSurface()
99 {
100     if (m_filmGrainFeature->m_coordinatesRandomValuesSurface)
101     {
102         uint32_t allocSize = m_filmGrainFeature->m_coordinateSurfaceSize;
103         if (m_tmpInitBuf == nullptr)
104         {
105             m_tmpInitBuf = m_allocator->AllocateBuffer(
106                 allocSize, "tempInitializationBuffer", resourceInternalReadWriteCache, lockableVideoMem, true, 0);
107             DECODE_CHK_NULL(m_tmpInitBuf);
108         }
109         else
110         {
111             DECODE_CHK_STATUS(m_allocator->Resize(m_tmpInitBuf, allocSize, lockableVideoMem, false, true));
112         }
113 
114         HucCopyPktG12::HucCopyParams copyParams;
115         copyParams.srcBuffer  = &(m_tmpInitBuf->OsResource);
116         copyParams.srcOffset  = 0;
117         copyParams.destBuffer = &(m_filmGrainFeature->m_coordinatesRandomValuesSurface->OsResource);
118         copyParams.destOffset = 0;
119         copyParams.copyLength = allocSize;
120         m_surfInitPkt->PushCopyParams(copyParams);
121 
122         Av1PipelineG12 *pipeline = dynamic_cast<Av1PipelineG12 *>(m_pipeline);
123         DECODE_CHK_NULL(pipeline);
124         DECODE_CHK_STATUS(ActivatePacket(DecodePacketId(pipeline, hucCopyPacketId), true, 0, 0));
125     }
126 
127     return MOS_STATUS_SUCCESS;
128 }
129 
GetMediaFunction()130 MediaFunction FilmGrainSurfaceInit::GetMediaFunction()
131 {
132     return VdboxDecodeWaFunc;
133 }
134 
InitScalabilityPars(PMOS_INTERFACE osInterface)135 void FilmGrainSurfaceInit::InitScalabilityPars(PMOS_INTERFACE osInterface)
136 {
137     m_decodeScalabilityPars.disableScalability = true;
138     m_decodeScalabilityPars.disableRealTile    = true;
139     m_decodeScalabilityPars.enableVE           = MOS_VE_SUPPORTED(osInterface);
140     m_decodeScalabilityPars.numVdbox           = m_numVdbox;
141 }
142 
143 }
144