Debian Codegraph @

media_softlet/agnostic/common/shared/packet/media_render_cmd_packet.cpp

raw
1 /*
2 * Copyright (c) 2021-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 //! \file media_render_cmd_packet.cpp
24 //! \brief Defines the interface for media render workload cmd packet
25 //! \details The media cmd packet is dedicated for command buffer sequenece submit
26 //!
27
28 #include "media_render_cmd_packet.h"
29 #include "renderhal_platform_interface.h"
30 #include "hal_oca_interface_next.h"
31 #include "mos_os_cp_interface_specific.h"
32
33 #define COMPUTE_WALKER_THREAD_SPACE_WIDTH 1
34 #define COMPUTE_WALKER_THREAD_SPACE_HEIGHT 1
35 #define COMPUTE_WALKER_THREAD_SPACE_DEPTH 1
36
37 RenderCmdPacket::RenderCmdPacket(MediaTask* task, PMOS_INTERFACE pOsInterface, RENDERHAL_INTERFACE* renderHal) : CmdPacket(task),
38 m_renderHal(renderHal),
39 m_cpInterface(nullptr)
40 {
41 m_osInterface = pOsInterface;
42 }
43
44 RenderCmdPacket::~RenderCmdPacket()
45 {
46 Destroy();
47 }
48
49 MOS_STATUS RenderCmdPacket::Init()
50 {
51 bool mediaWalkerUsed = false;
52 bool computeWalkerUsed = false;
53
54 if (nullptr == m_renderHal)
55 {
56 // Could not allocate renderhal in packet class
57 // Because we need to share renderhal for many Packets to reduce memory
58 RENDER_PACKET_ASSERTMESSAGE("renderHal should be passed When doing construction");
59 return MOS_STATUS_INVALID_PARAMETER;
60 }
61 mediaWalkerUsed = m_renderHal->pfnGetMediaWalkerStatus(m_renderHal) ? true : false;
62 computeWalkerUsed = m_renderHal->pRenderHalPltInterface->IsComputeContextInUse(m_renderHal);
63
64 if (mediaWalkerUsed && !computeWalkerUsed)
65 {
66 m_walkerType = WALKER_TYPE_MEDIA;
67 }
68 else if (computeWalkerUsed)
69 {
70 m_walkerType = WALKER_TYPE_COMPUTE;
71 }
72 else
73 {
74 m_walkerType = WALKER_TYPE_DISABLED;
75 }
76
77 if (m_renderHal->pRenderHalPltInterface)
78 {
79 m_miItf = m_renderHal->pRenderHalPltInterface->GetMhwMiItf();
80 }
81
82 return MOS_STATUS_SUCCESS;
83 }
84
85 MOS_STATUS RenderCmdPacket::Destroy()
86 {
87 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
88
89 return MOS_STATUS_SUCCESS;
90 }
91
92 MOS_STATUS RenderCmdPacket::Submit(MOS_COMMAND_BUFFER *commandBuffer, uint8_t packetPhase)
93 {
94 PMOS_INTERFACE pOsInterface = nullptr;
95 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
96 uint32_t dwSyncTag = 0;
97 int32_t i = 0, iRemaining = 0;
98 MHW_MEDIA_STATE_FLUSH_PARAM FlushParam = {};
99 bool bEnableSLM = false;
100 RENDERHAL_GENERIC_PROLOG_PARAMS GenericPrologParams = {};
101 MOS_RESOURCE GpuStatusBuffer = {};
102 MOS_CONTEXT* pOsContext = nullptr;
103 PMHW_MI_MMIOREGISTERS pMmioRegisters = nullptr;
104
105 RENDER_PACKET_CHK_NULL_RETURN(m_renderHal);
106 RENDER_PACKET_CHK_NULL_RETURN(m_renderHal->pRenderHalPltInterface);
107 RENDER_PACKET_CHK_NULL_RETURN(m_renderHal->pRenderHalPltInterface->GetMmioRegisters(m_renderHal));
108 RENDER_PACKET_CHK_NULL_RETURN(m_renderHal->pOsInterface);
109 RENDER_PACKET_CHK_NULL_RETURN(m_renderHal->pOsInterface->pOsContext);
110 RENDER_PACKET_CHK_NULL_RETURN(commandBuffer);
111
112 eStatus = MOS_STATUS_UNKNOWN;
113 pOsInterface = m_renderHal->pOsInterface;
114 iRemaining = 0;
115 FlushParam = g_cRenderHal_InitMediaStateFlushParams;
116 pOsContext = pOsInterface->pOsContext;
117 pMmioRegisters = m_renderHal->pRenderHalPltInterface->GetMmioRegisters(m_renderHal);
118
119 RENDER_PACKET_CHK_STATUS_RETURN(SetPowerMode(0));
120
121 m_renderHal->pRenderHalPltInterface->On1stLevelBBStart(m_renderHal, commandBuffer, pOsContext, pOsInterface->CurrentGpuContextHandle, pMmioRegisters);
122
123 OcaDumpDbgInfo(*commandBuffer, *pOsContext);
124
125 RENDER_PACKET_CHK_STATUS_RETURN(SetMediaFrameTracking(GenericPrologParams));
126
127 // Initialize command buffer and insert prolog
128 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnInitCommandBuffer(m_renderHal, commandBuffer, &GenericPrologParams));
129
130 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pRenderHalPltInterface->AddPerfCollectStartCmd(m_renderHal, pOsInterface, commandBuffer));
131
132 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pRenderHalPltInterface->StartPredicate(m_renderHal, commandBuffer));
133
134 // Write timing data for 3P budget
135 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSendTimingData(m_renderHal, commandBuffer, true));
136
137 bEnableSLM = false; // Media walker first
138 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSetCacheOverrideParams(
139 m_renderHal,
140 &m_renderHal->L3CacheSettings,
141 bEnableSLM));
142
143 if (m_renderHal->bCmfcCoeffUpdate)
144 {
145 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSendCscCoeffSurface(m_renderHal,
146 commandBuffer,
147 m_renderHal->pCmfcCoeffSurface,
148 m_renderHal->pStateHeap->pKernelAllocation[m_renderHal->iKernelAllocationID].pKernelEntry));
149 }
150
151 // Flush media states
152 if (m_isMultiKernelOneMediaState)
153 {
154 RENDER_PACKET_CHK_STATUS_RETURN(SendMultiKernelMediaStates(
155 m_renderHal,
156 commandBuffer));
157 }
158 else
159 {
160 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSendMediaStates(
161 m_renderHal,
162 commandBuffer,
163 (m_walkerType == WALKER_TYPE_MEDIA) ? &m_mediaWalkerParams : nullptr,
164 &m_gpgpuWalkerParams));
165 }
166
167 // Write back GPU Status tag
168 if (!pOsInterface->bEnableKmdMediaFrameTracking)
169 {
170 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSendRcsStatusTag(m_renderHal, commandBuffer));
171 }
172
173 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pRenderHalPltInterface->StopPredicate(m_renderHal, commandBuffer));
174
175 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pRenderHalPltInterface->AddPerfCollectEndCmd(m_renderHal, pOsInterface, commandBuffer));
176
177 // Write timing data for 3P budget
178 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSendTimingData(m_renderHal, commandBuffer, false));
179
180 MHW_PIPE_CONTROL_PARAMS PipeControlParams;
181
182 MOS_ZeroMemory(&PipeControlParams, sizeof(PipeControlParams));
183 PipeControlParams.dwFlushMode = MHW_FLUSH_WRITE_CACHE;
184 PipeControlParams.bGenericMediaStateClear = true;
185 PipeControlParams.bIndirectStatePointersDisable = true;
186 PipeControlParams.bDisableCSStall = false;
187
188 RENDER_PACKET_CHK_NULL_RETURN(pOsInterface->pfnGetSkuTable);
189 auto *skuTable = pOsInterface->pfnGetSkuTable(pOsInterface);
190 if (skuTable && MEDIA_IS_SKU(skuTable, FtrEnablePPCFlush))
191 {
192 // Add PPC fulsh
193 PipeControlParams.bPPCFlush = true;
194 }
195 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pRenderHalPltInterface->AddMiPipeControl(m_renderHal, commandBuffer, &PipeControlParams));
196
197 if (MEDIA_IS_WA(m_renderHal->pWaTable, WaSendDummyVFEafterPipelineSelect))
198 {
199 MHW_VFE_PARAMS VfeStateParams = {};
200 VfeStateParams.dwNumberofURBEntries = 1;
201 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pRenderHalPltInterface->AddMediaVfeCmd(m_renderHal, commandBuffer, &VfeStateParams));
202 }
203
204 // Add media flush command in case HW not cleaning the media state
205 if (MEDIA_IS_WA(m_renderHal->pWaTable, WaMSFWithNoWatermarkTSGHang))
206 {
207 FlushParam.bFlushToGo = true;
208 if (m_walkerType == WALKER_TYPE_MEDIA)
209 {
210 FlushParam.ui8InterfaceDescriptorOffset = m_mediaWalkerParams.InterfaceDescriptorOffset;
211 }
212 else
213 {
214 RENDER_PACKET_ASSERTMESSAGE("ERROR, pWalkerParams is nullptr and cannot get InterfaceDescriptorOffset.");
215 }
216
217 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pRenderHalPltInterface->AddMediaStateFlush(m_renderHal, commandBuffer, &FlushParam));
218 }
219 else if (MEDIA_IS_WA(m_renderHal->pWaTable, WaAddMediaStateFlushCmd))
220 {
221 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pRenderHalPltInterface->AddMediaStateFlush(m_renderHal, commandBuffer, &FlushParam));
222 }
223
224 #if (_DEBUG || _RELEASE_INTERNAL)
225 RENDER_PACKET_CHK_STATUS_RETURN(StallBatchBuffer(commandBuffer));
226 #endif
227
228 HalOcaInterfaceNext::On1stLevelBBEnd(*commandBuffer, *pOsInterface);
229
230 if (pBatchBuffer)
231 {
232 // Send Batch Buffer end command (HW/OS dependent)
233 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pRenderHalPltInterface->AddMiBatchBufferEnd(m_renderHal, commandBuffer, nullptr));
234 }
235 else if (IsMiBBEndNeeded(pOsInterface))
236 {
237 // Send Batch Buffer end command for 1st level Batch Buffer
238 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pRenderHalPltInterface->AddMiBatchBufferEnd(m_renderHal, commandBuffer, nullptr));
239 }
240 else if (m_renderHal->pOsInterface->bNoParsingAssistanceInKmd)
241 {
242 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pRenderHalPltInterface->AddMiBatchBufferEnd(m_renderHal, commandBuffer, nullptr));
243 }
244
245 // No need return command buffer here, which will be done in CmdTask::Submit.
246 MOS_NULL_RENDERING_FLAGS NullRenderingFlags;
247
248 NullRenderingFlags =
249 pOsInterface->pfnGetNullHWRenderFlags(pOsInterface);
250
251 if ((NullRenderingFlags.VPLgca ||
252 NullRenderingFlags.VPGobal) == false)
253 {
254 dwSyncTag = m_renderHal->pStateHeap->dwNextTag++;
255
256 // Set media state and batch buffer as busy
257 m_renderHal->pStateHeap->pCurMediaState->bBusy = true;
258 if (pBatchBuffer)
259 {
260 pBatchBuffer->bBusy = true;
261 pBatchBuffer->dwSyncTag = dwSyncTag;
262 }
263 }
264
265 return MOS_STATUS_SUCCESS;
266 }
267
268 MOS_STATUS RenderCmdPacket::RenderEngineSetup()
269 {
270 // pls make sure the context already switched to render/compute engine before submit
271 RENDER_PACKET_CHK_NULL_RETURN(m_renderHal);
272
273 // Register the resource of GSH
274 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnReset(m_renderHal));
275
276 // Assign media state
277 m_renderData.mediaState = m_renderHal->pfnAssignMediaState(m_renderHal, RENDERHAL_COMPONENT_PACKET);
278 RENDER_PACKET_CHK_NULL_RETURN(m_renderData.mediaState);
279 RENDER_PACKET_CHK_NULL_RETURN(m_renderHal->pStateHeap);
280
281 // Allocate and reset SSH instance
282 if ((m_isMultiBindingTables == false) || (m_renderHal->pStateHeap->iCurrentBindingTable >= m_renderHal->StateHeapSettings.iBindingTables) ||
283 (m_renderHal->pStateHeap->iCurrentSurfaceState >= m_renderHal->StateHeapSettings.iSurfaceStates) || m_isMultiKernelOneMediaState ||
284 m_renderHal->isBindlessHeapInUse)
285 {
286 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnAssignSshInstance(m_renderHal));
287 }
288
289 // Assign and Reset binding table
290 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnAssignBindingTable(
291 m_renderHal,
292 &m_renderData.bindingTable));
293
294 // Reset a new Binding index from start
295 m_renderData.bindingTableEntry = 0;
296
297 // load kernels before packet submit PipeLine to load kernel
298
299 return MOS_STATUS_SUCCESS;
300 }
301
302
303 MOS_STATUS RenderCmdPacket::InitKernelEntry()
304 {
305 if (m_kernelCount == 0)
306 {
307 RENDER_PACKET_NORMALMESSAGE("no kernel set up");
308 return MOS_STATUS_LOAD_LIBRARY_FAILED;
309 }
310
311 return MOS_STATUS_SUCCESS;
312 }
313
314 MOS_STATUS RenderCmdPacket::SetPowerMode(uint32_t KernelID)
315 {
316 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
317 uint16_t wNumRequestedEUSlices = 1; // Default to 1 slice
318 uint16_t wNumRequestedSubSlices = 3; // Default to 3 subslice
319 uint16_t wNumRequestedEUs = 8; // Default to 8 EUs
320 RENDERHAL_POWEROPTION PowerOption;
321 bool bSetRequestedSlices = false;
322 const SseuSetting * pcSSEUTable = nullptr;
323 MediaUserSettingSharedPtr userSettingPtr = nullptr;
324
325 RENDER_PACKET_CHK_NULL_RETURN(m_renderHal);
326
327 if ((m_renderHal->bRequestSingleSlice) || (m_renderHal->bEUSaturationNoSSD))
328 {
329 bSetRequestedSlices = true;
330 // bEUSaturationNoSSD: No slice shutdown, must request 2 slices [CM EU saturation on].
331 // bRequestSingleSlice: Always single slice.
332 wNumRequestedEUSlices = (m_renderHal->bEUSaturationNoSSD) ? 2 : 1;
333 }
334 else
335 {
336 bSetRequestedSlices = false;
337 }
338
339 if (m_renderHal->sseuTable)
340 {
341 pcSSEUTable = (const SseuSetting *)m_renderHal->sseuTable;
342 }
343 else
344 {
345 RENDER_PACKET_ASSERTMESSAGE("SSEU Table not valid.");
346 return MOS_STATUS_UNKNOWN;
347 }
348
349 RENDER_PACKET_CHK_NULL_RETURN(pcSSEUTable);
350 pcSSEUTable += KernelID;
351 if (!bSetRequestedSlices) // If num Slices is already programmed, then don't change it
352 {
353 if (wNumRequestedEUSlices < pcSSEUTable->numSlices)
354 {
355 wNumRequestedEUSlices = pcSSEUTable->numSlices;
356 }
357 }
358
359 wNumRequestedSubSlices = pcSSEUTable->numSubSlices;
360 wNumRequestedEUs = pcSSEUTable->numEUs;
361
362 #if (_DEBUG || _RELEASE_INTERNAL)
363 // User feature key reads
364 userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface);
365
366 uint32_t value = 0;
367 ReadUserSettingForDebug(
368 userSettingPtr,
369 value,
370 __MEDIA_USER_FEATURE_VALUE_SSEU_SETTING_OVERRIDE,
371 MediaUserSetting::Group::Device);
372 if (value != 0xDEADC0DE)
373 {
374 wNumRequestedEUSlices = value & 0xFF; // Bits 0-7
375 wNumRequestedSubSlices = (value >> 8) & 0xFF; // Bits 8-15
376 wNumRequestedEUs = (value >> 16) & 0xFFFF; // Bits 16-31
377 }
378 #endif
379
380 PowerOption.nSlice = wNumRequestedEUSlices;
381 PowerOption.nSubSlice = wNumRequestedSubSlices;
382 PowerOption.nEU = wNumRequestedEUs;
383 m_renderHal->pfnSetPowerOptionMode(m_renderHal, &PowerOption);
384
385 return eStatus;
386 }
387
388 uint32_t RenderCmdPacket::SetSurfaceForHwAccess(
389 PMOS_SURFACE surface,
390 PRENDERHAL_SURFACE_NEXT pRenderSurface,
391 PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
392 bool bWrite)
393 {
394 PMOS_INTERFACE pOsInterface;
395 PRENDERHAL_SURFACE_STATE_ENTRY pSurfaceEntries[MHW_MAX_SURFACE_PLANES];
396 int32_t iSurfaceEntries;
397 int32_t i;
398 MOS_STATUS eStatus;
399 RENDERHAL_SURFACE_STATE_PARAMS surfaceParams;
400
401 // Initialize Variables
402 eStatus = MOS_STATUS_SUCCESS;
403 pOsInterface = m_osInterface;
404
405 RENDER_PACKET_CHK_NULL_RETURN(pRenderSurface);
406 RENDER_PACKET_CHK_NULL_RETURN(pOsInterface);
407
408 // Register surfaces for rendering (GfxAddress/Allocation index)
409 // Register resource
410 RENDER_PACKET_CHK_STATUS_RETURN(m_osInterface->pfnRegisterResource(
411 m_osInterface,
412 &surface->OsResource,
413 bWrite,
414 true));
415
416 if (!pSurfaceParams)
417 {
418 MOS_ZeroMemory(&surfaceParams, sizeof(RENDERHAL_SURFACE_STATE_PARAMS));
419
420 //set mem object control for cache
421 surfaceParams.MemObjCtl = (m_renderHal->pOsInterface->pfnCachePolicyGetMemoryObject(
422 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER,
423 m_renderHal->pOsInterface->pfnGetGmmClientContext(m_renderHal->pOsInterface))).DwordValue;
424
425 pSurfaceParams = &surfaceParams;
426 }
427
428 if (pSurfaceParams->bAVS)
429 {
430 pSurfaceParams->Type = m_renderHal->SurfaceTypeAdvanced;
431 }
432 else
433 {
434 pSurfaceParams->Type = m_renderHal->SurfaceTypeDefault;
435 }
436
437 RENDER_PACKET_CHK_STATUS_RETURN(InitRenderHalSurface(
438 *surface,
439 pRenderSurface));
440
441 if (bWrite)
442 {
443 pRenderSurface->SurfType = RENDERHAL_SURF_OUT_RENDERTARGET;
444 }
445
446 // Setup surface states-----------------------------------------------------
447 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSetupSurfaceState(
448 m_renderHal,
449 pRenderSurface,
450 pSurfaceParams,
451 &iSurfaceEntries, // for most cases, surface entry should only take 1 entry, need align with kerenl design
452 pSurfaceEntries,
453 nullptr));
454
455 if (!m_isLargeSurfaceStateNeeded)
456 {
457 if (m_renderData.bindingTableEntry > 15)
458 {
459 RENDER_PACKET_ASSERTMESSAGE("input surface support up to 16 RSS");
460 m_renderData.bindingTableEntry = 0;
461 }
462 }
463 else
464 {
465 if (m_renderData.bindingTableEntry > 255)
466 {
467 RENDER_PACKET_ASSERTMESSAGE("input surface support up to 256 RSS");
468 m_renderData.bindingTableEntry = 0;
469 }
470 }
471
472 uint32_t iBTEntry = m_renderData.bindingTableEntry;
473 // Bind surface states------------------------------------------------------
474 for (i = 0; i < iSurfaceEntries; i++, m_renderData.bindingTableEntry++)
475 {
476 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnBindSurfaceState(
477 m_renderHal,
478 m_renderData.bindingTable,
479 m_renderData.bindingTableEntry,
480 pSurfaceEntries[i]));
481
482 pRenderSurface->Index = m_renderData.bindingTableEntry;
483 }
484
485 return iBTEntry;
486 }
487
488
489 uint32_t RenderCmdPacket::SetSurfaceForHwAccess(
490 PMOS_SURFACE surface,
491 PRENDERHAL_SURFACE_NEXT pRenderSurface,
492 PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
493 bool bWrite,
494 std::vector<RENDERHAL_STATE_LOCATION> &stateLocations)
495 {
496 PMOS_INTERFACE pOsInterface;
497 PRENDERHAL_SURFACE_STATE_ENTRY pSurfaceEntries[MHW_MAX_SURFACE_PLANES];
498 int32_t iSurfaceEntries;
499 int32_t i;
500 MOS_STATUS eStatus;
501 RENDERHAL_SURFACE_STATE_PARAMS surfaceParams;
502
503 // Initialize Variables
504 eStatus = MOS_STATUS_SUCCESS;
505 pOsInterface = m_osInterface;
506
507 RENDER_PACKET_CHK_NULL_RETURN(pRenderSurface);
508 RENDER_PACKET_CHK_NULL_RETURN(pOsInterface);
509
510 // Register surfaces for rendering (GfxAddress/Allocation index)
511 // Register resource
512 RENDER_PACKET_CHK_STATUS_RETURN(m_osInterface->pfnRegisterResource(
513 m_osInterface,
514 &surface->OsResource,
515 bWrite,
516 true));
517
518 if (!pSurfaceParams)
519 {
520 MOS_ZeroMemory(&surfaceParams, sizeof(RENDERHAL_SURFACE_STATE_PARAMS));
521
522 //set mem object control for cache
523 surfaceParams.MemObjCtl = (m_renderHal->pOsInterface->pfnCachePolicyGetMemoryObject(
524 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER,
525 m_renderHal->pOsInterface->pfnGetGmmClientContext(m_renderHal->pOsInterface))).DwordValue;
526
527 pSurfaceParams = &surfaceParams;
528 }
529
530 if (pSurfaceParams->bAVS)
531 {
532 pSurfaceParams->Type = m_renderHal->SurfaceTypeAdvanced;
533 }
534 else
535 {
536 pSurfaceParams->Type = m_renderHal->SurfaceTypeDefault;
537 }
538
539 RENDER_PACKET_CHK_STATUS_RETURN(InitRenderHalSurface(
540 *surface,
541 pRenderSurface));
542
543 if (bWrite)
544 {
545 pRenderSurface->SurfType = RENDERHAL_SURF_OUT_RENDERTARGET;
546 }
547
548 // Setup surface states-----------------------------------------------------
549 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSetupSurfaceState(
550 m_renderHal,
551 pRenderSurface,
552 pSurfaceParams,
553 &iSurfaceEntries, // for most cases, surface entry should only take 1 entry, need align with kerenl design
554 pSurfaceEntries,
555 nullptr));
556
557 if (!m_isLargeSurfaceStateNeeded)
558 {
559 if (m_renderData.bindingTableEntry > 15)
560 {
561 RENDER_PACKET_ASSERTMESSAGE("input surface support up to 16 RSS");
562 m_renderData.bindingTableEntry = 0;
563 }
564 }
565 else
566 {
567 if (m_renderData.bindingTableEntry > 255)
568 {
569 RENDER_PACKET_ASSERTMESSAGE("input surface support up to 256 RSS");
570 m_renderData.bindingTableEntry = 0;
571 }
572 }
573
574 uint32_t iBTEntry = m_renderData.bindingTableEntry;
575 if (m_renderHal->isBindlessHeapInUse == false)
576 {
577 // Bind surface states------------------------------------------------------
578 for (i = 0; i < iSurfaceEntries; i++, m_renderData.bindingTableEntry++)
579 {
580 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnBindSurfaceState(
581 m_renderHal,
582 m_renderData.bindingTable,
583 m_renderData.bindingTableEntry,
584 pSurfaceEntries[i]));
585
586 pRenderSurface->Index = m_renderData.bindingTableEntry;
587 }
588 }
589 else
590 {
591 for (i = 0; i < iSurfaceEntries; i++)
592 {
593 stateLocations.push_back(pSurfaceEntries[i]->stateLocation);
594 }
595 }
596
597 return iBTEntry;
598 }
599
600 MOS_STATUS RenderCmdPacket::SetSurfaceForHwAccess(
601 PMOS_SURFACE surface,
602 PRENDERHAL_SURFACE_NEXT pRenderSurface,
603 PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
604 uint32_t &bindingIndex,
605 bool bWrite,
606 PRENDERHAL_SURFACE_STATE_ENTRY *surfaceEntries,
607 uint32_t * numOfSurfaceEntries)
608 {
609 PMOS_INTERFACE pOsInterface = nullptr;
610 PRENDERHAL_SURFACE_STATE_ENTRY surfaceEntriesTmp[MHW_MAX_SURFACE_PLANES] = {};
611 PRENDERHAL_SURFACE_STATE_ENTRY *pSurfaceEntries = nullptr;
612 int32_t iSurfaceEntries = 0;
613 int32_t i = 0;
614 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
615 RENDERHAL_SURFACE_STATE_PARAMS surfaceParams = {};
616
617 if (nullptr == surfaceEntries || nullptr == numOfSurfaceEntries)
618 {
619 pSurfaceEntries = surfaceEntriesTmp;
620 }
621 else
622 {
623 pSurfaceEntries = surfaceEntries;
624 }
625
626 // Initialize Variables
627 eStatus = MOS_STATUS_SUCCESS;
628 pOsInterface = m_osInterface;
629
630 RENDER_PACKET_CHK_NULL_RETURN(pRenderSurface);
631 RENDER_PACKET_CHK_NULL_RETURN(pOsInterface);
632
633 // Register surfaces for rendering (GfxAddress/Allocation index)
634 // Register resource
635 RENDER_PACKET_CHK_STATUS_RETURN(m_osInterface->pfnRegisterResource(
636 m_osInterface,
637 &surface->OsResource,
638 bWrite,
639 true));
640
641 if (!pSurfaceParams)
642 {
643 MOS_ZeroMemory(&surfaceParams, sizeof(RENDERHAL_SURFACE_STATE_PARAMS));
644
645 //set mem object control for cache
646 surfaceParams.MemObjCtl = (m_renderHal->pOsInterface->pfnCachePolicyGetMemoryObject(
647 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER,
648 m_renderHal->pOsInterface->pfnGetGmmClientContext(m_renderHal->pOsInterface))).DwordValue;
649
650 pSurfaceParams = &surfaceParams;
651 }
652
653 if (pSurfaceParams->bAVS)
654 {
655 pSurfaceParams->Type = m_renderHal->SurfaceTypeAdvanced;
656 }
657 else
658 {
659 pSurfaceParams->Type = m_renderHal->SurfaceTypeDefault;
660 }
661
662 RENDER_PACKET_CHK_STATUS_RETURN(InitRenderHalSurface(
663 *surface,
664 pRenderSurface));
665
666 if (bWrite)
667 {
668 pRenderSurface->SurfType = RENDERHAL_SURF_OUT_RENDERTARGET;
669 }
670
671 // Setup surface states-----------------------------------------------------
672 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSetupSurfaceState(
673 m_renderHal,
674 pRenderSurface,
675 pSurfaceParams,
676 &iSurfaceEntries, // for most cases, surface entry should only take 1 entry, need align with kerenl design
677 pSurfaceEntries,
678 nullptr));
679
680 uint32_t iBTEntry = bindingIndex;
681 // Bind surface states------------------------------------------------------
682 for (i = 0; i < iSurfaceEntries; i++, iBTEntry++)
683 {
684 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnBindSurfaceState(
685 m_renderHal,
686 m_renderData.bindingTable,
687 iBTEntry,
688 pSurfaceEntries[i]));
689
690 pRenderSurface->Index = iBTEntry;
691 }
692
693 if (numOfSurfaceEntries)
694 {
695 *numOfSurfaceEntries = iSurfaceEntries;
696 }
697
698 return eStatus;
699 }
700
701 MOS_STATUS RenderCmdPacket::SetSurfaceForHwAccess(
702 PMOS_SURFACE surface,
703 PRENDERHAL_SURFACE_NEXT pRenderSurface,
704 PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
705 std::set<uint32_t> &bindingIndexes,
706 bool bWrite,
707 std::vector<RENDERHAL_STATE_LOCATION> &stateLocations,
708 uint32_t capcityOfSurfaceEntries,
709 PRENDERHAL_SURFACE_STATE_ENTRY *surfaceEntries,
710 uint32_t *numOfSurfaceEntries)
711 {
712 PMOS_INTERFACE pOsInterface = nullptr;
713 PRENDERHAL_SURFACE_STATE_ENTRY pSurfaceEntries[MHW_MAX_SURFACE_PLANES] = {};
714 int32_t iSurfaceEntries = 0;
715 int32_t i = 0;
716 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
717 RENDERHAL_SURFACE_STATE_PARAMS surfaceParams = {};
718
719 // Initialize Variables
720 eStatus = MOS_STATUS_SUCCESS;
721 pOsInterface = m_osInterface;
722
723 RENDER_PACKET_CHK_NULL_RETURN(pRenderSurface);
724 RENDER_PACKET_CHK_NULL_RETURN(pOsInterface);
725
726 // Register surfaces for rendering (GfxAddress/Allocation index)
727 // Register resource
728 RENDER_PACKET_CHK_STATUS_RETURN(m_osInterface->pfnRegisterResource(
729 m_osInterface,
730 &surface->OsResource,
731 bWrite,
732 true));
733
734 if (!pSurfaceParams)
735 {
736 MOS_ZeroMemory(&surfaceParams, sizeof(RENDERHAL_SURFACE_STATE_PARAMS));
737
738 //set mem object control for cache
739 surfaceParams.MemObjCtl = (m_renderHal->pOsInterface->pfnCachePolicyGetMemoryObject(
740 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER,
741 m_renderHal->pOsInterface->pfnGetGmmClientContext(m_renderHal->pOsInterface)))
742 .DwordValue;
743
744 pSurfaceParams = &surfaceParams;
745 }
746
747 if (pSurfaceParams->bAVS)
748 {
749 pSurfaceParams->Type = m_renderHal->SurfaceTypeAdvanced;
750 }
751 else
752 {
753 pSurfaceParams->Type = m_renderHal->SurfaceTypeDefault;
754 }
755
756 RENDER_PACKET_CHK_STATUS_RETURN(InitRenderHalSurface(
757 *surface,
758 pRenderSurface));
759
760 if (bWrite)
761 {
762 pRenderSurface->SurfType = RENDERHAL_SURF_OUT_RENDERTARGET;
763 }
764
765 // Setup surface states-----------------------------------------------------
766 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSetupSurfaceState(
767 m_renderHal,
768 pRenderSurface,
769 pSurfaceParams,
770 &iSurfaceEntries, // for most cases, surface entry should only take 1 entry, need align with kerenl design
771 pSurfaceEntries,
772 nullptr));
773
774 if (iSurfaceEntries > MHW_MAX_SURFACE_PLANES)
775 {
776 RENDER_PACKET_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
777 }
778 if (static_cast<uint32_t>(iSurfaceEntries) <= capcityOfSurfaceEntries && surfaceEntries != nullptr)
779 {
780 for (int32_t i = 0; i < iSurfaceEntries; ++i)
781 {
782 surfaceEntries[i] = pSurfaceEntries[i];
783 }
784 }
785
786 if (m_renderHal->isBindlessHeapInUse == false)
787 {
788 for (uint32_t const &bindingIndex : bindingIndexes)
789 {
790 uint32_t iBTEntry = bindingIndex;
791 // Bind surface states------------------------------------------------------
792 for (i = 0; i < iSurfaceEntries; i++, iBTEntry++)
793 {
794 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnBindSurfaceState(
795 m_renderHal,
796 m_renderData.bindingTable,
797 iBTEntry,
798 pSurfaceEntries[i]));
799
800 pRenderSurface->Index = iBTEntry;
801 }
802 }
803 }
804 else
805 {
806 for (i = 0; i < iSurfaceEntries; i++)
807 {
808 stateLocations.push_back(pSurfaceEntries[i]->stateLocation);
809 }
810 }
811
812 if (numOfSurfaceEntries)
813 {
814 *numOfSurfaceEntries = iSurfaceEntries;
815 }
816
817 return eStatus;
818 }
819
820
821 uint32_t RenderCmdPacket::SetBufferForHwAccess(
822 PMOS_SURFACE buffer,
823 PRENDERHAL_SURFACE_NEXT pRenderSurface,
824 PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
825 bool bWrite,
826 std::vector<RENDERHAL_STATE_LOCATION> &stateLocations)
827 {
828 RENDERHAL_SURFACE RenderHalSurface;
829 RENDERHAL_SURFACE_STATE_PARAMS SurfaceParam;
830 PRENDERHAL_SURFACE_STATE_ENTRY pSurfaceEntry;
831
832 RENDER_PACKET_CHK_NULL_RETURN(m_osInterface);
833 RENDER_PACKET_CHK_NULL_RETURN(m_osInterface->osCpInterface);
834 RENDER_PACKET_CHK_NULL_RETURN(buffer);
835
836 MOS_ZeroMemory(&RenderHalSurface, sizeof(RenderHalSurface));
837
838 // Register surfaces for rendering (GfxAddress/Allocation index)
839 // Register resource
840 RENDER_PACKET_CHK_STATUS_RETURN(m_osInterface->pfnRegisterResource(
841 m_osInterface,
842 &buffer->OsResource,
843 bWrite,
844 true));
845
846 // Setup Buffer surface-----------------------------------------------------
847 if (pSurfaceParams == nullptr)
848 {
849 MOS_ZeroMemory(&SurfaceParam, sizeof(SurfaceParam));
850
851 auto memObjCtrlState = m_osInterface->pfnGetResourceCachePolicyMemoryObject(m_renderHal->pOsInterface, &buffer->OsResource);
852 SurfaceParam.MemObjCtl = memObjCtrlState.DwordValue;
853
854 pSurfaceParams = &SurfaceParam;
855 }
856
857 RENDER_PACKET_CHK_STATUS_RETURN(InitRenderHalSurface(
858 *buffer,
859 &RenderHalSurface));
860
861 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSetupBufferSurfaceState(
862 m_renderHal,
863 &RenderHalSurface,
864 pSurfaceParams,
865 &pSurfaceEntry));
866
867 if (m_renderHal->isBindlessHeapInUse == false)
868 {
869 // Bind surface state-------------------------------------------------------
870 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnBindSurfaceState(
871 m_renderHal,
872 m_renderData.bindingTable,
873 m_renderData.bindingTableEntry,
874 pSurfaceEntry));
875
876 pRenderSurface->Index = m_renderData.bindingTableEntry;
877
878 m_renderData.bindingTableEntry++;
879 }
880 else
881 {
882 stateLocations.push_back(pSurfaceEntry->stateLocation);
883 }
884 return pRenderSurface->Index;
885 }
886
887 uint32_t RenderCmdPacket::SetBufferForHwAccess(PMOS_SURFACE buffer, PRENDERHAL_SURFACE_NEXT pRenderSurface, PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams, uint32_t bindingIndex, bool bWrite)
888 {
889 RENDERHAL_SURFACE RenderHalSurface;
890 RENDERHAL_SURFACE_STATE_PARAMS SurfaceParam;
891 PRENDERHAL_SURFACE_STATE_ENTRY pSurfaceEntry;
892
893 RENDER_PACKET_CHK_NULL_RETURN(m_osInterface);
894 RENDER_PACKET_CHK_NULL_RETURN(m_osInterface->osCpInterface);
895 RENDER_PACKET_CHK_NULL_RETURN(buffer);
896
897 MOS_ZeroMemory(&RenderHalSurface, sizeof(RenderHalSurface));
898
899 // Register surfaces for rendering (GfxAddress/Allocation index)
900 // Register resource
901 RENDER_PACKET_CHK_STATUS_RETURN(m_osInterface->pfnRegisterResource(
902 m_osInterface,
903 &buffer->OsResource,
904 bWrite,
905 true));
906
907 // Setup Buffer surface-----------------------------------------------------
908 if (pSurfaceParams == nullptr)
909 {
910 MOS_ZeroMemory(&SurfaceParam, sizeof(SurfaceParam));
911
912 //set mem object control for cache
913 SurfaceParam.MemObjCtl = (m_renderHal->pOsInterface->pfnCachePolicyGetMemoryObject(
914 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER,
915 m_renderHal->pOsInterface->pfnGetGmmClientContext(m_renderHal->pOsInterface))).DwordValue;
916
917 pSurfaceParams = &SurfaceParam;
918 }
919
920 RENDER_PACKET_CHK_STATUS_RETURN(InitRenderHalSurface(
921 *buffer,
922 &RenderHalSurface));
923
924 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSetupBufferSurfaceState(
925 m_renderHal,
926 &RenderHalSurface,
927 pSurfaceParams,
928 &pSurfaceEntry));
929
930 uint32_t iBTEntry = bindingIndex;
931 // Bind surface state-------------------------------------------------------
932 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnBindSurfaceState(
933 m_renderHal,
934 m_renderData.bindingTable,
935 iBTEntry,
936 pSurfaceEntry));
937
938 pRenderSurface->Index = bindingIndex;
939
940 return bindingIndex;
941 }
942
943 MOS_STATUS RenderCmdPacket::SetBufferForHwAccess(
944 PMOS_SURFACE buffer,
945 PRENDERHAL_SURFACE_NEXT pRenderSurface,
946 PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
947 std::set<uint32_t> &bindingIndexes,
948 bool bWrite,
949 std::vector<RENDERHAL_STATE_LOCATION> &stateLocations)
950 {
951 RENDERHAL_SURFACE RenderHalSurface = {};
952 RENDERHAL_SURFACE_STATE_PARAMS SurfaceParam = {};
953 PRENDERHAL_SURFACE_STATE_ENTRY pSurfaceEntry = {};
954 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
955
956 RENDER_PACKET_CHK_NULL_RETURN(m_osInterface);
957 RENDER_PACKET_CHK_NULL_RETURN(m_osInterface->osCpInterface);
958 RENDER_PACKET_CHK_NULL_RETURN(buffer);
959
960 MOS_ZeroMemory(&RenderHalSurface, sizeof(RenderHalSurface));
961
962 // Register surfaces for rendering (GfxAddress/Allocation index)
963 // Register resource
964 RENDER_PACKET_CHK_STATUS_RETURN(m_osInterface->pfnRegisterResource(
965 m_osInterface,
966 &buffer->OsResource,
967 bWrite,
968 true));
969
970 // Setup Buffer surface-----------------------------------------------------
971 if (pSurfaceParams == nullptr)
972 {
973 MOS_ZeroMemory(&SurfaceParam, sizeof(SurfaceParam));
974
975 //set mem object control for cache
976 SurfaceParam.MemObjCtl = (m_renderHal->pOsInterface->pfnCachePolicyGetMemoryObject(
977 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER,
978 m_renderHal->pOsInterface->pfnGetGmmClientContext(m_renderHal->pOsInterface)))
979 .DwordValue;
980
981 pSurfaceParams = &SurfaceParam;
982 }
983
984 RENDER_PACKET_CHK_STATUS_RETURN(InitRenderHalSurface(
985 *buffer,
986 &RenderHalSurface));
987
988 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSetupBufferSurfaceState(
989 m_renderHal,
990 &RenderHalSurface,
991 pSurfaceParams,
992 &pSurfaceEntry));
993
994 if (m_renderHal->isBindlessHeapInUse == false)
995 {
996 for (uint32_t const &bindingIndex : bindingIndexes)
997 {
998 uint32_t iBTEntry = bindingIndex;
999 // Bind surface state-------------------------------------------------------
1000 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnBindSurfaceState(
1001 m_renderHal,
1002 m_renderData.bindingTable,
1003 iBTEntry,
1004 pSurfaceEntry));
1005
1006 pRenderSurface->Index = bindingIndex;
1007 }
1008 }
1009 else
1010 {
1011 stateLocations.push_back(pSurfaceEntry->stateLocation);
1012 }
1013
1014 return eStatus;
1015 }
1016
1017 uint32_t RenderCmdPacket::SetBufferForHwAccess(MOS_BUFFER buffer, PRENDERHAL_SURFACE_NEXT pRenderSurface, PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams, bool bWrite)
1018 {
1019 RENDERHAL_SURFACE RenderHalSurface;
1020 RENDERHAL_SURFACE_STATE_PARAMS SurfaceParam;
1021 PRENDERHAL_SURFACE_STATE_ENTRY pSurfaceEntry;
1022
1023 RENDER_PACKET_CHK_NULL_RETURN(m_osInterface);
1024 RENDER_PACKET_CHK_NULL_RETURN(m_osInterface->osCpInterface);
1025
1026 MOS_ZeroMemory(&RenderHalSurface, sizeof(RenderHalSurface));
1027
1028 // not support CP yet
1029 if (m_osInterface->osCpInterface->IsHMEnabled())
1030 {
1031 RENDER_PACKET_ASSERTMESSAGE("ERROR, need to use VpHal_CommonSetBufferSurfaceForHwAccess if under CP HM.");
1032 }
1033
1034 // Register surfaces for rendering (GfxAddress/Allocation index)
1035 // Register resource
1036 RENDER_PACKET_CHK_STATUS_RETURN(m_osInterface->pfnRegisterResource(
1037 m_osInterface,
1038 &buffer.OsResource,
1039 bWrite,
1040 true));
1041
1042 // Setup Buffer surface-----------------------------------------------------
1043 if (pSurfaceParams == nullptr)
1044 {
1045 MOS_ZeroMemory(&SurfaceParam, sizeof(SurfaceParam));
1046
1047 //set mem object control for cache
1048 SurfaceParam.MemObjCtl = (m_renderHal->pOsInterface->pfnCachePolicyGetMemoryObject(
1049 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER,
1050 m_renderHal->pOsInterface->pfnGetGmmClientContext(m_renderHal->pOsInterface))).DwordValue;
1051
1052 pSurfaceParams = &SurfaceParam;
1053 }
1054
1055 RENDER_PACKET_CHK_STATUS_RETURN(InitRenderHalBuffer(
1056 buffer,
1057 &RenderHalSurface));
1058
1059 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSetupBufferSurfaceState(
1060 m_renderHal,
1061 &RenderHalSurface,
1062 pSurfaceParams,
1063 &pSurfaceEntry));
1064
1065 // Bind surface state-------------------------------------------------------
1066 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnBindSurfaceState(
1067 m_renderHal,
1068 m_renderData.bindingTable,
1069 m_renderData.bindingTableEntry,
1070 pSurfaceEntry));
1071
1072 pRenderSurface->Index = m_renderData.bindingTableEntry;
1073
1074 m_renderData.bindingTableEntry++;
1075 return pRenderSurface->Index;
1076 }
1077
1078 MOS_STATUS RenderCmdPacket::SetupCurbe(void *pData, uint32_t curbeLength, uint32_t maximumNumberofThreads)
1079 {
1080 m_renderData.iCurbeOffset = m_renderHal->pfnLoadCurbeData(
1081 m_renderHal,
1082 m_renderData.mediaState,
1083 pData,
1084 curbeLength);
1085
1086 if (m_renderData.iCurbeOffset < 0)
1087 {
1088 RENDER_PACKET_ASSERTMESSAGE("Curbe Set Fail, return error");
1089 return MOS_STATUS_UNKNOWN;
1090 }
1091
1092 m_renderData.iCurbeLength = curbeLength;
1093
1094 RENDER_PACKET_CHK_STATUS_RETURN(m_renderHal->pfnSetVfeStateParams(
1095 m_renderHal,
1096 MEDIASTATE_DEBUG_COUNTER_FREE_RUNNING,
1097 maximumNumberofThreads,
1098 m_renderData.iCurbeLength,
1099 m_renderData.iInlineLength,
1100 nullptr));
1101
1102 return MOS_STATUS_SUCCESS;
1103 }
1104
1105 MOS_STATUS RenderCmdPacket::PrepareMediaWalkerParams(KERNEL_WALKER_PARAMS params, MHW_WALKER_PARAMS &mediaWalker)
1106 {
1107 uint32_t uiMediaWalkerBlockSize;
1108 RECT alignedRect = {};
1109 bool bVerticalPattern = false;
1110
1111 uiMediaWalkerBlockSize = m_renderHal->pHwSizes->dwSizeMediaWalkerBlock;
1112 alignedRect = params.alignedRect;
1113 bVerticalPattern = params.isVerticalPattern;
1114
1115 // Calculate aligned output area in order to determine the total # blocks
1116 // to process in case of non-16x16 aligned target.
1117 alignedRect.right += uiMediaWalkerBlockSize - 1;
1118 alignedRect.bottom += uiMediaWalkerBlockSize - 1;
1119 alignedRect.left -= alignedRect.left % uiMediaWalkerBlockSize;
1120 alignedRect.top -= alignedRect.top % uiMediaWalkerBlockSize;
1121 alignedRect.right -= alignedRect.right % uiMediaWalkerBlockSize;
1122 alignedRect.bottom -= alignedRect.bottom % uiMediaWalkerBlockSize;
1123
1124 if (params.calculateBlockXYByAlignedRect)
1125 {
1126 // Set number of blocks
1127 params.iBlocksX = (alignedRect.right - alignedRect.left) / uiMediaWalkerBlockSize;
1128 params.iBlocksY = (alignedRect.bottom - alignedRect.top) / uiMediaWalkerBlockSize;
1129 }
1130
1131 // Set walker cmd params - Rasterscan
1132 mediaWalker.InterfaceDescriptorOffset = params.iMediaID;
1133
1134 mediaWalker.dwGlobalLoopExecCount = 1;
1135
1136 if (uiMediaWalkerBlockSize == 32)
1137 {
1138 mediaWalker.ColorCountMinusOne = 3;
1139 }
1140 else
1141 {
1142 mediaWalker.ColorCountMinusOne = 0;
1143 }
1144
1145 if (alignedRect.left != 0 || alignedRect.top != 0)
1146 {
1147 // if the rect starts from any other macro block other than the first
1148 // then the global resolution should be the whole frame and the global
1149 // start should be the rect start.
1150 mediaWalker.GlobalResolution.x =
1151 (alignedRect.right / uiMediaWalkerBlockSize);
1152 mediaWalker.GlobalResolution.y =
1153 (alignedRect.bottom / uiMediaWalkerBlockSize);
1154 }
1155 else
1156 {
1157 mediaWalker.GlobalResolution.x = params.iBlocksX;
1158 mediaWalker.GlobalResolution.y = params.iBlocksY;
1159 }
1160
1161 mediaWalker.GlobalStart.x =
1162 (alignedRect.left / uiMediaWalkerBlockSize);
1163 mediaWalker.GlobalStart.y =
1164 (alignedRect.top / uiMediaWalkerBlockSize);
1165
1166 mediaWalker.GlobalOutlerLoopStride.x = params.iBlocksX;
1167 mediaWalker.GlobalOutlerLoopStride.y = 0;
1168
1169 mediaWalker.GlobalInnerLoopUnit.x = 0;
1170 mediaWalker.GlobalInnerLoopUnit.y = params.iBlocksY;
1171
1172 mediaWalker.BlockResolution.x = params.iBlocksX;
1173 mediaWalker.BlockResolution.y = params.iBlocksY;
1174
1175 mediaWalker.LocalStart.x = 0;
1176 mediaWalker.LocalStart.y = 0;
1177
1178 if (bVerticalPattern)
1179 {
1180 mediaWalker.LocalOutLoopStride.x = 1;
1181 mediaWalker.LocalOutLoopStride.y = 0;
1182
1183 mediaWalker.LocalInnerLoopUnit.x = 0;
1184 mediaWalker.LocalInnerLoopUnit.y = 1;
1185
1186 mediaWalker.dwLocalLoopExecCount = params.iBlocksX - 1;
1187 mediaWalker.LocalEnd.x = 0;
1188 mediaWalker.LocalEnd.y = params.iBlocksY - 1;
1189 }
1190 else
1191 {
1192 mediaWalker.LocalOutLoopStride.x = 0;
1193 mediaWalker.LocalOutLoopStride.y = 1;
1194
1195 mediaWalker.LocalInnerLoopUnit.x = 1;
1196 mediaWalker.LocalInnerLoopUnit.y = 0;
1197
1198 mediaWalker.dwLocalLoopExecCount = params.iBlocksY - 1;
1199 mediaWalker.LocalEnd.x = params.iBlocksX - 1;
1200 mediaWalker.LocalEnd.y = 0;
1201 }
1202
1203 mediaWalker.UseScoreboard = m_renderHal->VfeScoreboard.ScoreboardEnable;
1204 mediaWalker.ScoreboardMask = m_renderHal->VfeScoreboard.ScoreboardMask;
1205
1206 return MOS_STATUS_SUCCESS;
1207 }
1208
1209 MOS_STATUS RenderCmdPacket::PrepareComputeWalkerParams(KERNEL_WALKER_PARAMS params, MHW_GPGPU_WALKER_PARAMS &gpgpuWalker)
1210 {
1211 uint32_t uiMediaWalkerBlockSize;
1212 RECT alignedRect = {};
1213 // Get media walker kernel block size
1214 uiMediaWalkerBlockSize = m_renderHal->pHwSizes->dwSizeMediaWalkerBlock;
1215 alignedRect = params.alignedRect;
1216
1217 // Calculate aligned output area in order to determine the total # blocks
1218 // to process in case of non-16x16 aligned target.
1219 alignedRect.right += uiMediaWalkerBlockSize - 1;
1220 alignedRect.bottom += uiMediaWalkerBlockSize - 1;
1221 alignedRect.left -= alignedRect.left % uiMediaWalkerBlockSize;
1222 alignedRect.top -= alignedRect.top % uiMediaWalkerBlockSize;
1223 alignedRect.right -= alignedRect.right % uiMediaWalkerBlockSize;
1224 alignedRect.bottom -= alignedRect.bottom % uiMediaWalkerBlockSize;
1225
1226 if (params.calculateBlockXYByAlignedRect)
1227 {
1228 // Set number of blocks
1229 params.iBlocksX = (alignedRect.right - alignedRect.left) / uiMediaWalkerBlockSize;
1230 params.iBlocksY = (alignedRect.bottom - alignedRect.top) / uiMediaWalkerBlockSize;
1231 }
1232
1233 // Set walker cmd params - Rasterscan
1234 gpgpuWalker.InterfaceDescriptorOffset = params.iMediaID;
1235
1236 // Specifies the initial value of the X component of the thread group when walker is started.
1237 // During the walker operation, when X is incremented to the X Dimension limit, on the next step
1238 // it is re-loaded with theStarting Xvalue. Same as GroupStartingY.
1239 gpgpuWalker.GroupStartingX = (alignedRect.left / uiMediaWalkerBlockSize);
1240 gpgpuWalker.GroupStartingY = (alignedRect.top / uiMediaWalkerBlockSize);
1241 // The X dimension of the thread group (maximum X is dimension -1), same as GroupHeight.
1242 gpgpuWalker.GroupWidth = params.iBlocksX;
1243 gpgpuWalker.GroupHeight = params.iBlocksY;
1244 gpgpuWalker.GroupDepth = params.iBlocksZ;
1245 if (params.isGroupStartInvolvedInGroupSize)
1246 {
1247 gpgpuWalker.GroupWidth += gpgpuWalker.GroupStartingX;
1248 gpgpuWalker.GroupHeight += gpgpuWalker.GroupStartingY;
1249 }
1250
1251 if (params.threadDepth && params.threadWidth && params.threadHeight &&
1252 ((params.isGenerateLocalID && params.emitLocal != MHW_EMIT_LOCAL_NONE) || params.slmSize > 0))
1253 {
1254 gpgpuWalker.ThreadWidth = params.threadWidth;
1255 gpgpuWalker.ThreadHeight = params.threadHeight;
1256 gpgpuWalker.ThreadDepth = params.threadDepth;
1257 }
1258 else
1259 {
1260 gpgpuWalker.ThreadWidth = COMPUTE_WALKER_THREAD_SPACE_WIDTH;
1261 gpgpuWalker.ThreadHeight = COMPUTE_WALKER_THREAD_SPACE_HEIGHT;
1262 gpgpuWalker.ThreadDepth = COMPUTE_WALKER_THREAD_SPACE_DEPTH;
1263 }
1264 gpgpuWalker.simdSize = params.simdSize;
1265 gpgpuWalker.IndirectDataStartAddress = params.iCurbeOffset;
1266 // Indirect Data Length is a multiple of 64 bytes (size of L3 cacheline). Bits [5:0] are zero.
1267 gpgpuWalker.IndirectDataLength = MOS_ALIGN_CEIL(params.iCurbeLength, 1 << MHW_COMPUTE_INDIRECT_SHIFT);
1268 gpgpuWalker.BindingTableID = params.iBindingTable;
1269 gpgpuWalker.ForcePreferredSLMZero = params.forcePreferredSLMZero;
1270
1271 gpgpuWalker.isEmitInlineParameter = params.isEmitInlineParameter;
1272 gpgpuWalker.inlineDataLength = params.inlineDataLength;
1273 gpgpuWalker.inlineData = params.inlineData;
1274
1275 gpgpuWalker.isGenerateLocalID = params.isGenerateLocalID;
1276 gpgpuWalker.emitLocal = params.emitLocal;
1277
1278 gpgpuWalker.SLMSize = params.slmSize;
1279 gpgpuWalker.hasBarrier = params.hasBarrier;
1280
1281 gpgpuWalker.registersPerThread = params.registersPerThread;
1282
1283 gpgpuWalker.curbeResourceList = params.curbeResourceList;
1284 gpgpuWalker.curbeResourceListSize = params.curbeResourceListSize;
1285
1286 gpgpuWalker.inlineResourceList = params.inlineResourceList;
1287 gpgpuWalker.inlineResourceListSize = params.inlineResourceListSize;
1288
1289 return MOS_STATUS_SUCCESS;
1290 }
1291
1292 void RenderCmdPacket::UpdateKernelConfigParam(RENDERHAL_KERNEL_PARAM &kernelParam)
1293 {
1294 // CURBE_Length is set as the size of curbe buffer. 32 alignment with 5 bits right shift need be done before it being used.
1295 kernelParam.CURBE_Length = (kernelParam.CURBE_Length + 31) >> 5;
1296 }
1297
1298 MOS_STATUS RenderCmdPacket::LoadKernel()
1299 {
1300 int32_t iKrnAllocation = 0;
1301 MHW_KERNEL_PARAM MhwKernelParam = {};
1302 RENDERHAL_KERNEL_PARAM KernelParam = m_renderData.KernelParam;
1303 // Load kernel to GSH
1304 INIT_MHW_KERNEL_PARAM(MhwKernelParam, &m_renderData.KernelEntry);
1305 UpdateKernelConfigParam(KernelParam);
1306 iKrnAllocation = m_renderHal->pfnLoadKernel(
1307 m_renderHal,
1308 &KernelParam,
1309 &MhwKernelParam,
1310 nullptr);
1311
1312 if (iKrnAllocation < 0)
1313 {
1314 RENDER_PACKET_ASSERTMESSAGE("kernel load failed");
1315 return MOS_STATUS_UNKNOWN;
1316 }
1317
1318 m_renderData.kernelAllocationID = iKrnAllocation;
1319
1320 if (m_renderData.iCurbeOffset < 0)
1321 {
1322 RENDER_PACKET_ASSERTMESSAGE("Curbe Set Fail, return error");
1323 return MOS_STATUS_UNKNOWN;
1324 }
1325 // Allocate Media ID, link to kernel
1326 m_renderData.mediaID = m_renderHal->pfnAllocateMediaID(
1327 m_renderHal,
1328 iKrnAllocation,
1329 m_renderData.bindingTable,
1330 m_renderData.iCurbeOffset,
1331 (m_renderData.iCurbeLength),
1332 0,
1333 nullptr);
1334
1335 if (m_renderData.mediaID < 0)
1336 {
1337 RENDER_PACKET_ASSERTMESSAGE("Allocate Media ID failed, return error");
1338 return MOS_STATUS_UNKNOWN;
1339 }
1340
1341 return MOS_STATUS_SUCCESS;
1342 }
1343
1344 MOS_STATUS RenderCmdPacket::InitRenderHalSurface(MOS_SURFACE surface, PRENDERHAL_SURFACE pRenderSurface)
1345 {
1346 RENDER_PACKET_CHK_NULL_RETURN(pRenderSurface);
1347
1348 RENDERHAL_GET_SURFACE_INFO info;
1349 MOS_ZeroMemory(&info, sizeof(info));
1350 RENDER_PACKET_CHK_STATUS_RETURN(RenderHal_GetSurfaceInfo(
1351 m_renderHal->pOsInterface,
1352 &info,
1353 &surface));
1354
1355 if (Mos_ResourceIsNull(&pRenderSurface->OsSurface.OsResource))
1356 {
1357 pRenderSurface->OsSurface = surface;
1358 }
1359
1360 return MOS_STATUS_SUCCESS;
1361 }
1362
1363 MOS_STATUS RenderCmdPacket::InitRenderHalBuffer(MOS_BUFFER surface, PRENDERHAL_SURFACE pRenderSurface)
1364 {
1365 RENDER_PACKET_CHK_NULL_RETURN(pRenderSurface);
1366 pRenderSurface->OsSurface.OsResource = surface.OsResource;
1367 pRenderSurface->OsSurface.dwWidth = surface.size;
1368 pRenderSurface->OsSurface.dwHeight = 1;
1369 pRenderSurface->OsSurface.dwPitch = surface.size;
1370 pRenderSurface->OsSurface.Format = Format_RAW;
1371
1372 return MOS_STATUS_SUCCESS;
1373 }
1374
1375 MOS_STATUS RenderCmdPacket::SendMultiKernelMediaStates(
1376 PRENDERHAL_INTERFACE pRenderHal,
1377 PMOS_COMMAND_BUFFER pCmdBuffer)
1378 {
1379 PMOS_INTERFACE pOsInterface = nullptr;
1380 PRENDERHAL_STATE_HEAP pStateHeap = nullptr;
1381 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
1382 MHW_VFE_PARAMS *pVfeStateParams = nullptr;
1383 MOS_CONTEXT *pOsContext = nullptr;
1384 MHW_MI_LOAD_REGISTER_IMM_PARAMS loadRegisterImmParams = {};
1385 PMHW_MI_MMIOREGISTERS pMmioRegisters = nullptr;
1386 MOS_OCA_BUFFER_HANDLE hOcaBuf = 0;
1387 bool flushL1 = false;
1388 //---------------------------------------
1389 MHW_RENDERHAL_CHK_NULL(pRenderHal);
1390 MHW_RENDERHAL_CHK_NULL(pRenderHal->pStateHeap);
1391 MHW_RENDERHAL_CHK_NULL(pRenderHal->pRenderHalPltInterface);
1392 MHW_RENDERHAL_ASSERT(pRenderHal->pStateHeap->bGshLocked);
1393 RENDER_PACKET_CHK_NULL_RETURN(pRenderHal->pRenderHalPltInterface);
1394 RENDER_PACKET_CHK_NULL_RETURN(pRenderHal->pRenderHalPltInterface->GetMmioRegisters(pRenderHal));
1395
1396 //---------------------------------------
1397 pOsInterface = pRenderHal->pOsInterface;
1398 pStateHeap = pRenderHal->pStateHeap;
1399 pOsContext = pOsInterface->pOsContext;
1400 pMmioRegisters = pRenderHal->pRenderHalPltInterface->GetMmioRegisters(pRenderHal);
1401
1402 // Setup L3$ Config, LRI commands used here & hence must be launched from a secure bb
1403 pRenderHal->L3CacheSettings.bEnableSLM = (m_walkerType == WALKER_TYPE_COMPUTE && m_slmSize > 0) ? true : false;
1404 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pfnEnableL3Caching(pRenderHal, &pRenderHal->L3CacheSettings));
1405
1406 // Send L3 Cache Configuration
1407 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pRenderHalPltInterface->SetL3Cache(pRenderHal, pCmdBuffer));
1408
1409 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pRenderHalPltInterface->EnablePreemption(pRenderHal, pCmdBuffer));
1410
1411 // Send Pipeline Select command
1412 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pRenderHalPltInterface->AddPipelineSelectCmd(pRenderHal, pCmdBuffer, (m_walkerType == WALKER_TYPE_COMPUTE) ? true : false));
1413
1414 // The binding table for surface states is at end of command buffer. No need to add it to indirect state heap.
1415 HalOcaInterfaceNext::OnIndirectState(*pCmdBuffer, (MOS_CONTEXT_HANDLE)pOsContext, pRenderHal->StateBaseAddressParams.presInstructionBuffer, pStateHeap->CurIDEntryParams.dwKernelOffset, false, pStateHeap->iKernelUsedForDump);
1416
1417 // Send State Base Address command
1418 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pfnSendStateBaseAddress(pRenderHal, pCmdBuffer));
1419
1420 if (pRenderHal->bComputeContextInUse && !pRenderHal->isBindlessHeapInUse)
1421 {
1422 pRenderHal->pRenderHalPltInterface->SendTo3DStateBindingTablePoolAlloc(pRenderHal, pCmdBuffer);
1423 }
1424
1425 // Send Surface States
1426 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pfnSendSurfaces(pRenderHal, pCmdBuffer));
1427
1428 // Send SIP State if ASM debug enabled
1429 if (pRenderHal->bIsaAsmDebugEnable)
1430 {
1431 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pRenderHalPltInterface->AddSipStateCmd(pRenderHal, pCmdBuffer));
1432 }
1433
1434 pVfeStateParams = pRenderHal->pRenderHalPltInterface->GetVfeStateParameters();
1435 if (!pRenderHal->bComputeContextInUse)
1436 {
1437 // set VFE State
1438 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pRenderHalPltInterface->AddMediaVfeCmd(pRenderHal, pCmdBuffer, pVfeStateParams));
1439 }
1440 else
1441 {
1442 if (!pRenderHal->isBindlessHeapInUse)
1443 {
1444 // set CFE State
1445 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pRenderHalPltInterface->AddCfeStateCmd(pRenderHal, pCmdBuffer, pVfeStateParams));
1446 }
1447 }
1448
1449 // Send CURBE Load
1450 if (!pRenderHal->bComputeContextInUse)
1451 {
1452 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pfnSendCurbeLoad(pRenderHal, pCmdBuffer));
1453 }
1454
1455 // Send Interface Desc Load
1456 if (!pRenderHal->bComputeContextInUse)
1457 {
1458 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pfnSendMediaIdLoad(pRenderHal, pCmdBuffer));
1459 }
1460
1461 // Send Chroma Keys
1462 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pfnSendChromaKey(pRenderHal, pCmdBuffer));
1463
1464 // Send Palettes in use
1465 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pfnSendPalette(pRenderHal, pCmdBuffer));
1466
1467 pRenderHal->pRenderHalPltInterface->OnDispatch(pRenderHal, pCmdBuffer, pOsInterface, pMmioRegisters);
1468
1469 for (uint32_t kernelIndex = 0; kernelIndex < m_kernelRenderData.size(); kernelIndex++)
1470 {
1471 auto it = m_kernelRenderData.find(kernelIndex);
1472 if (it == m_kernelRenderData.end())
1473 {
1474 eStatus = MOS_STATUS_INVALID_PARAMETER;
1475 goto finish;
1476 }
1477
1478 if (kernelIndex > 0 && it->second.walkerParam.bSyncFlag)
1479 {
1480 MHW_PIPE_CONTROL_PARAMS pipeCtlParams = g_cRenderHal_InitPipeControlParams;
1481 pipeCtlParams.dwPostSyncOp = MHW_FLUSH_NOWRITE;
1482 pipeCtlParams.dwFlushMode = MHW_FLUSH_CUSTOM;
1483 pipeCtlParams.bInvalidateTextureCache = true;
1484 pipeCtlParams.bFlushRenderTargetCache = true;
1485
1486 if (it->second.walkerParam.pipeControlParams.bUpdateNeeded)
1487 {
1488 pipeCtlParams.bHdcPipelineFlush = it->second.walkerParam.pipeControlParams.bEnableDataPortFlush;
1489 pipeCtlParams.bUnTypedDataPortCacheFlush = it->second.walkerParam.pipeControlParams.bUnTypedDataPortCacheFlush;
1490 pipeCtlParams.bFlushRenderTargetCache = it->second.walkerParam.pipeControlParams.bFlushRenderTargetCache;
1491 pipeCtlParams.bInvalidateTextureCache = it->second.walkerParam.pipeControlParams.bInvalidateTextureCache;
1492 }
1493
1494 if (flushL1)
1495 { //Flush L1 cache after consumer walker when there is a producer-consumer relationship walker.
1496 pipeCtlParams.bUnTypedDataPortCacheFlush = true;
1497 pipeCtlParams.bHdcPipelineFlush = true;
1498 }
1499 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pRenderHalPltInterface->AddMiPipeControl(pRenderHal,
1500 pCmdBuffer,
1501 &pipeCtlParams));
1502 }
1503
1504 if (m_walkerType == WALKER_TYPE_MEDIA)
1505 {
1506 MOS_ZeroMemory(&m_mediaWalkerParams, sizeof(m_mediaWalkerParams));
1507
1508 MHW_RENDERHAL_CHK_STATUS(PrepareMediaWalkerParams(it->second.walkerParam, m_mediaWalkerParams));
1509
1510 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pRenderHalPltInterface->AddMediaObjectWalkerCmd(pRenderHal,
1511 pCmdBuffer,
1512 &m_mediaWalkerParams));
1513 }
1514 else if (m_walkerType == WALKER_TYPE_COMPUTE)
1515 {
1516 MOS_ZeroMemory(&m_gpgpuWalkerParams, sizeof(m_gpgpuWalkerParams));
1517
1518 MHW_RENDERHAL_CHK_STATUS(PrepareComputeWalkerParams(it->second.walkerParam, m_gpgpuWalkerParams));
1519
1520 pRenderHal->iKernelAllocationID = it->second.kernelAllocationID;
1521 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pRenderHalPltInterface->SendComputeWalker(
1522 pRenderHal,
1523 pCmdBuffer,
1524 &m_gpgpuWalkerParams));
1525
1526 flushL1 = it->second.walkerParam.bFlushL1;
1527 }
1528 else
1529 {
1530 eStatus = MOS_STATUS_UNIMPLEMENTED;
1531 goto finish;
1532 }
1533 }
1534
1535 // This need not be secure, since PPGTT will be used here. But moving this after
1536 // L3 cache configuration will delay UMD from fetching another media state.
1537 // Send Sync Tag
1538 MHW_RENDERHAL_CHK_STATUS(pRenderHal->pfnSendSyncTag(pRenderHal, pCmdBuffer));
1539
1540 m_kernelRenderData.clear();
1541
1542 finish:
1543 return eStatus;
1544 }