Debian Codegraph @

media_softlet/agnostic/common/shared/task/media_cmd_task.cpp

raw
1 /*
2 * Copyright (c) 2018, 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_cmd_task.cpp
25 //! \brief Defines the interface for media cmd task
26 //! \details The media cmd task is dedicated for command buffer submission
27 //!
28 #include <stdint.h>
29 #include <memory>
30 #include <vector>
31 #include "media_scalability.h"
32 #include "media_scalability_defs.h"
33 #include "mos_utilities.h"
34 #include "media_cmd_task.h"
35 #include "media_packet.h"
36 #include "media_utils.h"
37
38 CmdTask::CmdTask(PMOS_INTERFACE osInterface)
39 : m_osInterface(osInterface)
40 {
41
42 }
43
44 MOS_STATUS CmdTask::CalculateCmdBufferSizeFromActivePackets()
45 {
46 uint32_t curCommandBufferSize = 0;
47 uint32_t curRequestedPatchListSize = 0;
48
49 m_cmdBufSize = 0;
50 m_patchListSize = 0;
51 for (auto prop : m_packets)
52 {
53 // Calculate total size based on pipe 0
54 if (prop.stateProperty.currentPipe == 0)
55 {
56 auto packetId = prop.packetId;
57 auto packet = prop.packet;
58
59 MEDIA_CHK_NULL_RETURN(packet);
60
61 curCommandBufferSize = 0;
62 curRequestedPatchListSize = 0;
63
64 packet->CalculateCommandSize(curCommandBufferSize, curRequestedPatchListSize);
65 m_cmdBufSize += curCommandBufferSize;
66 m_patchListSize += curRequestedPatchListSize;
67 }
68 }
69
70 return MOS_STATUS_SUCCESS;
71 }
72
73 MOS_STATUS CmdTask::SubmitToLevelzeroRuntime()
74 {
75 for (auto &prop : m_packets)
76 {
77 auto packet = prop.packet;
78 uint8_t packetPhase = MediaPacket::otherPacket;
79 MEDIA_CHK_NULL_RETURN(packet);
80
81 MEDIA_CHK_STATUS_RETURN(packet->Prepare());
82 MEDIA_CHK_STATUS_RETURN(packet->Submit(nullptr, packetPhase));
83 }
84
85 #if (_DEBUG || _RELEASE_INTERNAL)
86 for (auto prop : m_packets)
87 {
88 auto packet = prop.packet;
89 MEDIA_CHK_NULL_RETURN(packet);
90 MEDIA_CHK_STATUS_RETURN(packet->DumpOutput());
91 }
92 #endif // _DEBUG || _RELEASE_INTERNAL
93
94 // clear the packet lists since all commands are submitted
95 m_packets.clear();
96
97 return MOS_STATUS_SUCCESS;
98 }
99
100 MOS_STATUS CmdTask::Submit(bool immediateSubmit, MediaScalability *scalability, CodechalDebugInterface *debugInterface, bool levelzeroRuntimeInUse)
101 {
102 if (levelzeroRuntimeInUse)
103 {
104 return SubmitToLevelzeroRuntime();
105 }
106 else
107 {
108 return Submit(immediateSubmit, scalability, debugInterface);
109 }
110 }
111
112 MOS_STATUS CmdTask::Submit(bool immediateSubmit, MediaScalability *scalability, CodechalDebugInterface *debugInterface)
113 {
114 MEDIA_CHK_NULL_RETURN(scalability);
115
116 // Algin this variable in pipeline, packet and scalability.
117 bool singleTaskPhaseSupportedInPak = false;
118 MEDIA_CHK_STATUS_RETURN(CalculateCmdBufferSizeFromActivePackets());
119
120 // prepare cmd buffer
121 MOS_COMMAND_BUFFER cmdBuffer;
122 // initialize the command buffer struct
123 MOS_ZeroMemory(&cmdBuffer, sizeof(MOS_COMMAND_BUFFER));
124
125 if (m_packets.size() > 0)
126 {
127 MEDIA_CHK_STATUS_RETURN(scalability->UpdateState(&m_packets[0].stateProperty));
128
129 // VerifyCmdBuffer could be called for duplicated times for singleTaskPhase mult-pass cases
130 // Each task submit verify only once
131 MEDIA_CHK_STATUS_RETURN(scalability->VerifyCmdBuffer(m_cmdBufSize, m_patchListSize, singleTaskPhaseSupportedInPak));
132 }
133 else
134 {
135 SCALABILITY_ASSERTMESSAGE("No packets to execute in the task!");
136 return MOS_STATUS_INVALID_PARAMETER;
137 }
138
139 int8_t curPipe = -1;
140
141 for (auto& prop : m_packets)
142 {
143 MEDIA_CHK_STATUS_RETURN(scalability->UpdateState(&prop.stateProperty));
144
145 auto packet = prop.packet;
146 uint8_t packetPhase = MediaPacket::otherPacket;
147 MEDIA_CHK_NULL_RETURN(packet);
148
149 MEDIA_CHK_STATUS_RETURN(packet->Prepare());
150
151 MEDIA_CHK_STATUS_RETURN(scalability->GetCmdBuffer(&cmdBuffer, prop.frameTrackingRequested));
152 //Set first packet for each pipe in the first pass, used for prolog & forcewakeup insertion
153 bool isFirstPacket = scalability->GetCurrentPass() == 0 && curPipe < scalability->GetCurrentPipe();
154 if (isFirstPacket)
155 {
156 packetPhase = MediaPacket::firstPacket;
157 }
158
159 if (!prop.skipOcaBBStartInCmdTask && (isFirstPacket || !prop.stateProperty.singleTaskPhaseSupported))
160 {
161 scalability->Oca1stLevelBBStart(cmdBuffer);
162 }
163
164 curPipe = scalability->GetCurrentPipe();
165
166 MEDIA_CHK_STATUS_RETURN(packet->Submit(&cmdBuffer, packetPhase));
167
168 MEDIA_CHK_STATUS_RETURN(scalability->ReturnCmdBuffer(&cmdBuffer));
169 }
170
171 #if (_DEBUG || _RELEASE_INTERNAL) && !EMUL
172 MEDIA_CHK_STATUS_RETURN(DumpCmdBufferAllPipes(&cmdBuffer, debugInterface, scalability));
173 #endif // _DEBUG || _RELEASE_INTERNAL
174
175 // submit cmd buffer
176 MEDIA_CHK_STATUS_RETURN(scalability->SubmitCmdBuffer(&cmdBuffer));
177
178 #if (_DEBUG || _RELEASE_INTERNAL)
179 for (auto prop : m_packets)
180 {
181 MEDIA_CHK_STATUS_RETURN(scalability->UpdateState(&prop.stateProperty));
182
183 auto packet = prop.packet;
184 MEDIA_CHK_NULL_RETURN(packet);
185 MEDIA_CHK_STATUS_RETURN(packet->DumpOutput());
186 }
187 #endif // _DEBUG || _RELEASE_INTERNAL
188
189 // clear the packet lists since all commands are composed into command buffer
190 m_packets.clear();
191
192 return MOS_STATUS_SUCCESS;
193 }
194
195 #if ((_DEBUG || _RELEASE_INTERNAL) && !EMUL)
196 MOS_STATUS CmdTask::DumpCmdBuffer(PMOS_COMMAND_BUFFER cmdBuffer, CodechalDebugInterface *debugInterface, uint8_t pipeIdx)
197 {
198 MEDIA_CHK_NULL_RETURN(cmdBuffer);
199
200 if (debugInterface)
201 {
202 std::string packetName = "";
203 for (auto prop : m_packets)
204 {
205 // Construct cmd buffer dump name only from packets in pipe 0
206 if (prop.stateProperty.currentPipe == 0)
207 {
208 packetName += prop.packet->GetPacketName();
209 break;
210 }
211 }
212
213 // Put pipe index to file name
214 std::stringstream pipeIdxStrStream;
215 pipeIdxStrStream << "_" << uint32_t(pipeIdx);
216 packetName += pipeIdxStrStream.str();
217
218 MEDIA_CHK_STATUS_RETURN(debugInterface->DumpCmdBuffer(
219 cmdBuffer,
220 CODECHAL_NUM_MEDIA_STATES,
221 packetName.data()));
222 }
223
224 return MOS_STATUS_SUCCESS;
225 }
226
227 MOS_STATUS CmdTask::DumpCmdBufferAllPipes(PMOS_COMMAND_BUFFER cmdBuffer, CodechalDebugInterface *debugInterface, MediaScalability *scalability)
228 {
229 MEDIA_CHK_NULL_RETURN(cmdBuffer);
230 MEDIA_CHK_NULL_RETURN(scalability);
231
232 if (debugInterface)
233 {
234 auto pipeNum = scalability->GetPipeNumber();
235 auto lastPipeIndex = scalability->GetCurrentPipe();
236 for (uint8_t pipeIdx = 0; pipeIdx < pipeNum; pipeIdx++)
237 {
238 scalability->SetCurrentPipeIndex(pipeIdx);
239 MEDIA_CHK_STATUS_RETURN(scalability->GetCmdBuffer(cmdBuffer));
240 MEDIA_CHK_STATUS_RETURN(DumpCmdBuffer(cmdBuffer, debugInterface, pipeIdx));
241 MEDIA_CHK_STATUS_RETURN(scalability->ReturnCmdBuffer(cmdBuffer));
242 }
243
244 // Recover scalability current pipe index after dump
245 scalability->SetCurrentPipeIndex(lastPipeIndex);
246 }
247
248 return MOS_STATUS_SUCCESS;
249 }
250 #endif // _DEBUG || _RELEASE_INTERNAL