1 /*
2 * Copyright (c) 2018-2022, 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 media_pipeline.cpp
25 //! \brief Defines the common interface for media pipeline
26 //! \details The media pipeline 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 "media_pipeline.h"
31 #include "media_cmd_task.h"
32 #include "media_packet.h"
33 #include "media_interfaces_mcpy_next.h"
34 #include "media_debug_interface.h"
35
MediaPipeline(PMOS_INTERFACE osInterface)36 MediaPipeline::MediaPipeline(PMOS_INTERFACE osInterface) : m_osInterface(osInterface)
37 {
38 if (m_osInterface)
39 {
40 m_userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface);
41 }
42 if (!m_userSettingPtr)
43 {
44 MOS_OS_NORMALMESSAGE("Initialize m_userSettingPtr instance failed!");
45 }
46 MediaPerfProfiler *perfProfiler = MediaPerfProfiler::Instance();
47 if (!perfProfiler)
48 {
49 MOS_OS_ASSERTMESSAGE("Initialize MediaPerfProfiler failed!");
50 }
51 else
52 {
53 MOS_STATUS status = perfProfiler->Initialize((void *)this, m_osInterface);
54 if (status != MOS_STATUS_SUCCESS)
55 {
56 MOS_OS_ASSERTMESSAGE("Initialize perfProfiler failed!");
57 }
58 }
59 }
60
~MediaPipeline()61 MediaPipeline::~MediaPipeline()
62 {
63 DeletePackets();
64 DeleteTasks();
65
66 MOS_Delete(m_mediaCopyWrapper);
67 #if !EMUL
68 MEDIA_DEBUG_TOOL(MOS_Delete(m_debugInterface));
69 #endif
70 MediaPerfProfiler *perfProfiler = MediaPerfProfiler::Instance();
71
72 if (!perfProfiler)
73 {
74 MOS_OS_ASSERTMESSAGE("Destroy MediaPerfProfiler failed!");
75 }
76 else
77 {
78 MediaPerfProfiler::Destroy(perfProfiler, (void *)this, m_osInterface);
79 }
80
81 #if MHW_HWCMDPARSER_ENABLED
82 mhw::HwcmdParser::DestroyInstance();
83 #endif
84 }
85
DeletePackets()86 MOS_STATUS MediaPipeline::DeletePackets()
87 {
88 for (auto pair : m_packetList)
89 {
90 MOS_Delete(pair.second);
91 }
92
93 m_packetList.clear();
94 return MOS_STATUS_SUCCESS;
95 }
96
DeleteTasks()97 MOS_STATUS MediaPipeline::DeleteTasks()
98 {
99 for (auto pair : m_taskList)
100 {
101 MOS_Delete(pair.second);
102 }
103
104 m_taskList.clear();
105 return MOS_STATUS_SUCCESS;
106 }
107
InitPlatform()108 MOS_STATUS MediaPipeline::InitPlatform()
109 {
110 m_osInterface->pfnGetPlatform(m_osInterface, &m_platform);
111 m_skuTable = m_osInterface->pfnGetSkuTable(m_osInterface);
112 m_waTable = m_osInterface->pfnGetWaTable(m_osInterface);
113 m_gtSystemInfo = m_osInterface->pfnGetGtSystemInfo(m_osInterface);
114
115 return MOS_STATUS_SUCCESS;
116 }
117
UserFeatureReport()118 MOS_STATUS MediaPipeline::UserFeatureReport()
119 {
120 #if (_DEBUG || _RELEASE_INTERNAL)
121 ReportUserSetting(m_userSettingPtr,
122 __MEDIA_USER_FEATURE_VALUE_APOGEIOS_ENABLE,
123 uint32_t(1),
124 MediaUserSetting::Group::Device);
125 #endif
126 return MOS_STATUS_SUCCESS;
127 }
128
RegisterPacket(uint32_t packetId,MediaPacket * packet)129 MOS_STATUS MediaPipeline::RegisterPacket(uint32_t packetId, MediaPacket *packet)
130 {
131 if (nullptr == packet)
132 {
133 return MOS_STATUS_INVALID_PARAMETER;
134 }
135
136 auto iter = m_packetList.find(packetId);
137 if (iter != m_packetList.end())
138 {
139 m_packetList.erase(iter);
140 }
141 m_packetList.insert(std::make_pair(packetId, packet));
142
143 return MOS_STATUS_SUCCESS;
144 }
145
GetOrCreate(uint32_t packetId)146 MediaPacket *MediaPipeline::GetOrCreate(uint32_t packetId)
147 {
148 auto iter = m_packetList.find(packetId);
149 if (iter != m_packetList.end())
150 {
151 return iter->second;
152 }
153
154 auto iterCreator = m_packetCreators.find(packetId);
155 if (iterCreator != m_packetCreators.end())
156 {
157 MOS_STATUS registStatus = RegisterPacket(packetId, iterCreator->second());
158 if (MOS_FAILED(registStatus))
159 {
160 MOS_OS_ASSERTMESSAGE("Media register packets into packet pool failed!");
161 }
162
163 iter = m_packetList.find(packetId);
164 if (iter != m_packetList.end())
165 {
166 MOS_STATUS status = iter->second->Init();
167 if (MOS_FAILED(status))
168 {
169 MOS_OS_ASSERTMESSAGE("Media packet init failed!");
170 }
171 return iter->second;
172 }
173 }
174
175 return nullptr;
176 }
177
ActivatePacket(uint32_t packetId,bool immediateSubmit,uint16_t pass,uint8_t pipe,uint8_t pipeNum,uint8_t subPass,uint8_t rowNum)178 MOS_STATUS MediaPipeline::ActivatePacket(uint32_t packetId, bool immediateSubmit, uint16_t pass, uint8_t pipe, uint8_t pipeNum, uint8_t subPass, uint8_t rowNum)
179 {
180 auto packet = GetOrCreate(packetId);
181 if (packet == nullptr)
182 {
183 return MOS_STATUS_NULL_POINTER;
184 }
185
186 PacketProperty prop;
187 prop.packetId = packetId;
188 prop.packet = packet;
189 prop.immediateSubmit = immediateSubmit;
190
191 prop.stateProperty.currentPass = pass;
192 prop.stateProperty.currentPipe = pipe;
193 prop.stateProperty.pipeIndexForSubmit = pipeNum;
194 prop.stateProperty.currentSubPass = subPass;
195 prop.stateProperty.currentRow = rowNum;
196 MOS_TraceEventExt(EVENT_PIPE_PACKET, EVENT_TYPE_INFO, &packetId, sizeof(packetId), &prop.stateProperty, sizeof(StateParams));
197
198 m_activePacketList.push_back(prop);
199 return MOS_STATUS_SUCCESS;
200 }
201
ActivatePacket(uint32_t packetId,bool immediateSubmit,StateParams & stateProperty)202 MOS_STATUS MediaPipeline::ActivatePacket(uint32_t packetId, bool immediateSubmit, StateParams &stateProperty)
203 {
204 auto iter = m_packetList.find(packetId);
205 if (iter == m_packetList.end())
206 {
207 return MOS_STATUS_INVALID_PARAMETER;
208 }
209
210 PacketProperty prop;
211 prop.packetId = iter->first;
212 prop.packet = iter->second;
213 prop.immediateSubmit = immediateSubmit;
214 prop.stateProperty = stateProperty;
215 MOS_TraceEventExt(EVENT_PIPE_PACKET, EVENT_TYPE_INFO, &packetId, sizeof(packetId), &stateProperty, sizeof(StateParams));
216
217 m_activePacketList.push_back(prop);
218 return MOS_STATUS_SUCCESS;
219 }
220
ExecuteActivePackets()221 MOS_STATUS MediaPipeline::ExecuteActivePackets()
222 {
223 MOS_TraceEventExt(EVENT_PIPE_EXE, EVENT_TYPE_START, nullptr, 0, nullptr, 0);
224 for (auto prop : m_activePacketList)
225 {
226 prop.stateProperty.statusReport = m_statusReport;
227 MOS_TraceEventExt(EVENT_PIPE_EXE, EVENT_TYPE_INFO, &prop.packetId, sizeof(uint32_t), nullptr, 0);
228
229 MediaTask *task = prop.packet->GetActiveTask();
230
231 if (task)
232 {
233 task->AddPacket(&prop);
234 if (prop.immediateSubmit)
235 {
236 task->Submit(true, m_scalability, m_debugInterface);
237 }
238 }
239 }
240
241 m_activePacketList.clear();
242
243 MOS_TraceEventExt(EVENT_PIPE_EXE, EVENT_TYPE_END, nullptr, 0, nullptr, 0);
244 return MOS_STATUS_SUCCESS;
245 }
246
CreateTask(MediaTask::TaskType type)247 MediaTask *MediaPipeline::CreateTask(MediaTask::TaskType type)
248 {
249 MediaTask *task = nullptr;
250 switch (type)
251 {
252 case MediaTask::TaskType::cmdTask:
253 task = MOS_New(CmdTask, m_osInterface);
254 break;
255 default:
256 break;
257 }
258 if (nullptr != task)
259 {
260 m_taskList.insert(std::make_pair(type, task));
261 }
262 return task;
263 }
264
GetTask(MediaTask::TaskType type)265 MediaTask *MediaPipeline::GetTask(MediaTask::TaskType type)
266 {
267 auto iter = m_taskList.find(type);
268 if (iter != m_taskList.end())
269 {
270 return iter->second;
271 }
272 else
273 {
274 MediaTask *task = CreateTask(type);
275 return task;
276 }
277 }
278
CreateFeatureManager()279 MOS_STATUS MediaPipeline::CreateFeatureManager()
280 {
281 m_featureManager = MOS_New(MediaFeatureManager);
282 if (nullptr != m_featureManager)
283 {
284 return MOS_STATUS_SUCCESS;
285 }
286 else
287 {
288 return MOS_STATUS_UNKNOWN;
289 }
290 }
291
CreateMediaCopyWrapper()292 MOS_STATUS MediaPipeline::CreateMediaCopyWrapper()
293 {
294 if (nullptr == m_mediaCopyWrapper)
295 {
296 m_mediaCopyWrapper = MOS_New(MediaCopyWrapper, m_osInterface);
297 }
298 if (nullptr != m_mediaCopyWrapper)
299 {
300 return MOS_STATUS_SUCCESS;
301 }
302 else
303 {
304 return MOS_STATUS_NO_SPACE;
305 }
306 }
307
IsFrameTrackingEnabled()308 bool MediaPipeline::IsFrameTrackingEnabled()
309 {
310 if (nullptr == m_scalability)
311 return false;
312
313 return m_scalability->IsFrameTrackingEnabled();
314 }
315
316