1 /*
2 * Copyright (c) 2019-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 //!
24 //! \file decode_scalability_singlepipe.cpp
25 //! \brief Defines the common interface for media scalability singlepipe mode.
26 //! \details The media scalability singlepipe interface is further sub-divided by component,
27 //! this file is for the base interface which is shared by all components.
28 //!
29
30 #include "codec_hw_next.h"
31 #include "decode_scalability_defs.h"
32 #include "decode_scalability_singlepipe.h"
33
34 #include "media_context.h"
35 #include "media_status_report.h"
36 #include "mhw_utilities.h"
37 #include "decode_status_report_defs.h"
38 #include "codechal_hw.h"
39
40 namespace decode
41 {
42
DecodeScalabilitySinglePipe(void * hwInterface,MediaContext * mediaContext,uint8_t componentType)43 DecodeScalabilitySinglePipe::DecodeScalabilitySinglePipe(void *hwInterface, MediaContext *mediaContext, uint8_t componentType) :
44 DecodeScalabilitySinglePipeNext(hwInterface, mediaContext, componentType)
45 {
46 if (hwInterface == nullptr)
47 {
48 return;
49 }
50 m_hwInterface = (CodechalHwInterface*)(((CodechalHwInterfaceNext *)hwInterface)->legacyHwInterface);
51 m_osInterface = m_hwInterface->GetOsInterface();
52 }
53
Initialize(const MediaScalabilityOption & option)54 MOS_STATUS DecodeScalabilitySinglePipe::Initialize(const MediaScalabilityOption &option)
55 {
56 SCALABILITY_CHK_NULL_RETURN(m_osInterface);
57
58 DecodeScalabilityOption *decodeScalabilityOption = MOS_New(DecodeScalabilityOption, (const DecodeScalabilityOption &)option);
59 SCALABILITY_CHK_NULL_RETURN(decodeScalabilityOption);
60 m_scalabilityOption = decodeScalabilityOption;
61
62 m_frameTrackingEnabled = m_osInterface->bEnableKmdMediaFrameTracking ? true : false;
63
64 // !Don't check the return status here, because this function will return fail if there's no regist key in register.
65 // But it's normal that regist key not in register.
66 m_osInterface->pfnVirtualEngineSupported(m_osInterface, false, true);
67
68 SCALABILITY_CHK_STATUS_RETURN(MediaScalabilitySinglePipeNext::Initialize(option));
69 PMOS_GPUCTX_CREATOPTIONS_ENHANCED gpuCtxCreateOption = dynamic_cast<PMOS_GPUCTX_CREATOPTIONS_ENHANCED>(m_gpuCtxCreateOption);
70 SCALABILITY_CHK_NULL_RETURN(gpuCtxCreateOption);
71 gpuCtxCreateOption->UsingSFC = decodeScalabilityOption->IsUsingSFC();
72 if (decodeScalabilityOption->IsUsingSlimVdbox())
73 {
74 gpuCtxCreateOption->Flags |= (1 << 2);
75 }
76
77 return MOS_STATUS_SUCCESS;
78 }
79
VerifyCmdBuffer(uint32_t requestedSize,uint32_t requestedPatchListSize,bool & singleTaskPhaseSupportedInPak)80 MOS_STATUS DecodeScalabilitySinglePipe::VerifyCmdBuffer(uint32_t requestedSize, uint32_t requestedPatchListSize, bool &singleTaskPhaseSupportedInPak)
81 {
82 SCALABILITY_FUNCTION_ENTER;
83
84 return MediaScalabilitySinglePipeNext::VerifyCmdBuffer(requestedSize, requestedPatchListSize, singleTaskPhaseSupportedInPak);
85 }
86
SubmitCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer)87 MOS_STATUS DecodeScalabilitySinglePipe::SubmitCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer)
88 {
89 SCALABILITY_FUNCTION_ENTER;
90 SCALABILITY_CHK_NULL_RETURN(m_osInterface);
91 SCALABILITY_CHK_NULL_RETURN(cmdBuffer);
92
93 SCALABILITY_CHK_STATUS_RETURN(GetCmdBuffer(cmdBuffer));
94
95 if (!m_osInterface->pfnIsMismatchOrderProgrammingSupported())
96 {
97 SCALABILITY_CHK_STATUS_RETURN(m_hwInterface->GetMiInterface()->AddMiBatchBufferEnd(cmdBuffer, nullptr));
98 }
99
100 SCALABILITY_CHK_STATUS_RETURN(Oca1stLevelBBEnd(*cmdBuffer));
101
102 SCALABILITY_CHK_STATUS_RETURN(ReturnCmdBuffer(cmdBuffer));
103
104 if (MOS_VE_SUPPORTED(m_osInterface))
105 {
106 SCALABILITY_CHK_STATUS_RETURN(SetHintParams());
107 if (cmdBuffer && m_veHitParams)
108 {
109 SCALABILITY_CHK_STATUS_RETURN(PopulateHintParams(cmdBuffer));
110 }
111 }
112
113 m_attrReady = false;
114 return m_osInterface->pfnSubmitCommandBuffer(m_osInterface, cmdBuffer, false);
115 }
VerifySpaceAvailable(uint32_t requestedSize,uint32_t requestedPatchListSize,bool & singleTaskPhaseSupportedInPak)116 MOS_STATUS DecodeScalabilitySinglePipe::VerifySpaceAvailable(uint32_t requestedSize, uint32_t requestedPatchListSize, bool &singleTaskPhaseSupportedInPak)
117 {
118 SCALABILITY_FUNCTION_ENTER;
119
120 uint8_t looptimes = 3;
121 for(auto i = 0 ; i < looptimes ; i++)
122 {
123 bool bothPatchListAndCmdBufChkSuccess = false;
124 SCALABILITY_CHK_STATUS_RETURN(MediaScalability::VerifySpaceAvailable(
125 requestedSize, requestedPatchListSize, bothPatchListAndCmdBufChkSuccess));
126
127 if (bothPatchListAndCmdBufChkSuccess)
128 {
129 return MOS_STATUS_SUCCESS;
130 }
131
132 MOS_STATUS statusPatchList = MOS_STATUS_SUCCESS;
133 if (requestedPatchListSize > 0)
134 {
135 statusPatchList = (MOS_STATUS)m_osInterface->pfnVerifyPatchListSize(
136 m_osInterface,
137 requestedPatchListSize);
138 }
139
140 MOS_STATUS statusCmdBuf = (MOS_STATUS)m_osInterface->pfnVerifyCommandBufferSize(
141 m_osInterface,
142 requestedSize,
143 0);
144
145 if (statusCmdBuf == MOS_STATUS_SUCCESS && statusPatchList == MOS_STATUS_SUCCESS)
146 {
147 return MOS_STATUS_SUCCESS;
148 }
149 }
150
151 SCALABILITY_ASSERTMESSAGE("Resize Command buffer failed with no space!");
152 return MOS_STATUS_NO_SPACE;
153 }
154
UpdateState(void * statePars)155 MOS_STATUS DecodeScalabilitySinglePipe::UpdateState(void *statePars)
156 {
157 SCALABILITY_FUNCTION_ENTER;
158 SCALABILITY_CHK_NULL_RETURN(statePars);
159
160 SCALABILITY_CHK_STATUS_RETURN(MediaScalabilitySinglePipeNext::UpdateState(statePars));
161
162 StateParams *stateParams = (StateParams *)statePars;
163 m_singleTaskPhaseSupported = stateParams->singleTaskPhaseSupported;
164 m_statusReport = stateParams->statusReport;
165 m_currentPass = stateParams->currentPass;
166 m_componentState = stateParams->componentState;
167 SCALABILITY_CHK_NULL_RETURN(m_statusReport);
168
169 return MOS_STATUS_SUCCESS;
170 }
171
ResizeCommandBufferAndPatchList(uint32_t requestedCommandBufferSize,uint32_t requestedPatchListSize)172 MOS_STATUS DecodeScalabilitySinglePipe::ResizeCommandBufferAndPatchList(
173 uint32_t requestedCommandBufferSize,
174 uint32_t requestedPatchListSize)
175 {
176 SCALABILITY_FUNCTION_ENTER;
177 SCALABILITY_CHK_NULL_RETURN(m_hwInterface);
178
179 return m_hwInterface->ResizeCommandBufferAndPatchList(requestedCommandBufferSize, requestedPatchListSize);
180 }
181
SendAttrWithFrameTracking(MOS_COMMAND_BUFFER & cmdBuffer,bool frameTrackingRequested)182 MOS_STATUS DecodeScalabilitySinglePipe::SendAttrWithFrameTracking(
183 MOS_COMMAND_BUFFER &cmdBuffer,
184 bool frameTrackingRequested)
185 {
186 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
187
188 SCALABILITY_FUNCTION_ENTER;
189
190 bool renderEngineUsed = m_mediaContext->IsRenderEngineUsed();
191
192 // initialize command buffer attributes
193 cmdBuffer.Attributes.bTurboMode = m_hwInterface->m_turboMode;
194 cmdBuffer.Attributes.bMediaPreemptionEnabled = renderEngineUsed ? m_hwInterface->GetRenderInterface()->IsPreemptionEnabled() : 0;
195
196 if (frameTrackingRequested && m_frameTrackingEnabled)
197 {
198 PMOS_RESOURCE resource = nullptr;
199 uint32_t offset = 0;
200 m_statusReport->GetAddress(decode::statusReportGlobalCount, resource, offset);
201
202 cmdBuffer.Attributes.bEnableMediaFrameTracking = true;
203 cmdBuffer.Attributes.resMediaFrameTrackingSurface = resource;
204 cmdBuffer.Attributes.dwMediaFrameTrackingTag = m_statusReport->GetSubmittedCount() + 1;
205 // Set media frame tracking address offset(the offset from the decoder status buffer page)
206 cmdBuffer.Attributes.dwMediaFrameTrackingAddrOffset = offset;
207 }
208
209 return eStatus;
210 }
211
CreateDecodeSinglePipe(void * hwInterface,MediaContext * mediaContext,uint8_t componentType)212 MOS_STATUS DecodeScalabilitySinglePipe::CreateDecodeSinglePipe(void *hwInterface, MediaContext *mediaContext, uint8_t componentType)
213 {
214 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
215
216 SCALABILITY_FUNCTION_ENTER;
217
218 SCALABILITY_CHK_NULL_RETURN(hwInterface);
219 SCALABILITY_CHK_NULL_RETURN(mediaContext);
220
221 ((CodechalHwInterfaceNext *)hwInterface)->m_singlePipeScalability = MOS_New(DecodeScalabilitySinglePipe, hwInterface, mediaContext, scalabilityDecoder);
222 SCALABILITY_CHK_NULL_RETURN(((CodechalHwInterfaceNext *)hwInterface)->m_singlePipeScalability);
223
224 return eStatus;
225 }
226 }
227
228
229