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 //! \file     encode_huc_la_init_packet.cpp
24 //! \brief    Defines the implementation of Huc Lookahead init packet
25 //!
26 
27 #include "encode_huc_la_init_packet.h"
28 #include "encode_vdenc_lpla_analysis.h"
29 
30 namespace encode
31 {
Init()32     MOS_STATUS HucLaInitPkt::Init()
33     {
34         ENCODE_FUNC_CALL();
35         MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
36 
37         HUC_CHK_STATUS_RETURN(EncodeHucPkt::Init());
38         ENCODE_CHK_NULL_RETURN(m_featureManager);
39         m_basicFeature = dynamic_cast<HevcBasicFeature *>(m_featureManager->GetFeature(HevcFeatureIDs::basicFeature));
40         ENCODE_CHK_NULL_RETURN(m_basicFeature);
41 
42         return eStatus;
43     }
44 
AllocateResources()45     MOS_STATUS HucLaInitPkt::AllocateResources()
46     {
47         ENCODE_FUNC_CALL();
48         MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
49 
50         ENCODE_CHK_STATUS_RETURN(EncodeHucPkt::AllocateResources());
51 
52         return eStatus;
53     }
54 
Submit(MOS_COMMAND_BUFFER * commandBuffer,uint8_t packetPhase)55     MOS_STATUS HucLaInitPkt::Submit(MOS_COMMAND_BUFFER *commandBuffer, uint8_t packetPhase)
56     {
57         ENCODE_FUNC_CALL();
58         MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
59 
60         bool firstTaskInPhase = packetPhase & firstPacket;
61         bool requestProlog    = false;
62 
63         if (!m_pipeline->IsSingleTaskPhaseSupported() || firstTaskInPhase)
64         {
65             // Send command buffer header at the beginning (OS dependent)
66             requestProlog = true;
67         }
68 
69         ENCODE_CHK_STATUS_RETURN(Execute(commandBuffer, true, requestProlog, LA_INIT));
70 
71         return eStatus;
72     }
73 
CalculateCommandSize(uint32_t & commandBufferSize,uint32_t & requestedPatchListSize)74     MOS_STATUS HucLaInitPkt::CalculateCommandSize(uint32_t &commandBufferSize, uint32_t &requestedPatchListSize)
75     {
76         ENCODE_FUNC_CALL();
77 
78         auto osInterface = m_hwInterface->GetOsInterface();
79         ENCODE_CHK_NULL_RETURN(osInterface);
80 
81         uint32_t hucCommandsSize  = 0;
82         uint32_t hucPatchListSize = 0;
83         MHW_VDBOX_STATE_CMDSIZE_PARAMS stateCmdSizeParams;
84 
85         ENCODE_CHK_STATUS_RETURN(m_hwInterface->GetHucStateCommandSize(
86             m_basicFeature->m_mode, (uint32_t *)&hucCommandsSize, (uint32_t *)&hucPatchListSize, &stateCmdSizeParams));
87 
88         commandBufferSize      = hucCommandsSize;
89         requestedPatchListSize = osInterface->bUsesPatchList ? hucPatchListSize : 0;
90 
91         if (m_pipeline->IsSingleTaskPhaseSupported())
92         {
93             commandBufferSize *= m_pipeline->GetPassNum();
94         }
95 
96         // 4K align since allocation is in chunks of 4K bytes.
97         commandBufferSize = MOS_ALIGN_CEIL(commandBufferSize, CODECHAL_PAGE_SIZE);
98 
99         return MOS_STATUS_SUCCESS;
100     }
101 
MHW_SETPAR_DECL_SRC(HUC_IMEM_STATE,HucLaInitPkt)102     MHW_SETPAR_DECL_SRC(HUC_IMEM_STATE, HucLaInitPkt)
103     {
104         params.kernelDescriptor = VDBOX_HUC_LA_ANALYSIS_KERNEL_DESCRIPTOR;
105         return MOS_STATUS_SUCCESS;
106     }
107 
MHW_SETPAR_DECL_SRC(HUC_DMEM_STATE,HucLaInitPkt)108     MHW_SETPAR_DECL_SRC(HUC_DMEM_STATE, HucLaInitPkt)
109     {
110         params.function = LA_INIT;
111         return MOS_STATUS_SUCCESS;
112     }
113 
MHW_SETPAR_DECL_SRC(HUC_VIRTUAL_ADDR_STATE,HucLaInitPkt)114     MHW_SETPAR_DECL_SRC(HUC_VIRTUAL_ADDR_STATE, HucLaInitPkt)
115     {
116         params.function = LA_INIT;
117         return MOS_STATUS_SUCCESS;
118     }
119 
120 } //encode
121