Debian Codegraph @

media_softlet/agnostic/common/vp/hal/packet/vp_render_kernel_obj.cpp

raw
1 /*
2 * Copyright (c) 2020-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 vp_render_kernel_obj.cpp
24 //! \brief vp render kernel base object.
25 //! \details vp render kernel base object will provided interface where sub kernels processing ways
26 //!
27 #include <iomanip>
28 #include "vp_render_kernel_obj.h"
29 #include "vp_dumper.h"
30 #include "hal_oca_interface_next.h"
31
32 using namespace vp;
33
34 VpRenderKernelObj::VpRenderKernelObj(PVP_MHWINTERFACE hwInterface, PVpAllocator allocator) :
35 m_hwInterface(hwInterface),
36 m_allocator(allocator)
37 {
38 }
39
40 VpRenderKernelObj::VpRenderKernelObj(PVP_MHWINTERFACE hwInterface, VpKernelID kernelId, uint32_t kernelIndex, std::string kernelName, PVpAllocator allocator) :
41 m_hwInterface(hwInterface), m_allocator(allocator), m_kernelName(kernelName), m_kernelId(kernelId), m_kernelIndex(kernelIndex)
42 {
43 VP_RENDER_NORMALMESSAGE("kernel name is %s, kernel ID is %d", kernelName.c_str(), kernelId);
44 }
45
46 VpRenderKernelObj::~VpRenderKernelObj()
47 {
48 }
49
50 // For Adv kernel
51 MOS_STATUS VpRenderKernelObj::Init(VpRenderKernel& kernel)
52 {
53 VP_FUNC_CALL();
54 VP_RENDER_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED);
55 return MOS_STATUS_SUCCESS;
56 }
57
58 uint32_t VpRenderKernelObj::GetKernelBinaryID()
59 {
60 VP_FUNC_CALL();
61
62 return m_kernelBinaryID;
63 }
64
65 MOS_STATUS VpRenderKernelObj::GetKernelEntry(Kdll_CacheEntry &entry)
66 {
67 VP_FUNC_CALL();
68
69 // Set Parameters for Kernel Entry
70 entry.iKUID = m_kernelBinaryID;
71 entry.iKCID = -1;
72 entry.iFilterSize = 2;
73 entry.pFilter = nullptr;
74 entry.iSize = m_kernelSize;
75 entry.iPaddingSize = m_kernelPaddingSize;
76 entry.pBinary = (uint8_t *)m_kernelBinary;
77 return MOS_STATUS_SUCCESS;
78 }
79
80 uint32_t VpRenderKernelObj::GetKernelIndex()
81 {
82 VP_FUNC_CALL();
83
84 return m_kernelIndex;
85 }
86
87 MOS_STATUS VpRenderKernelObj::GetWalkerSetting(KERNEL_WALKER_PARAMS& walkerParam, KERNEL_PACKET_RENDER_DATA &renderData)
88 {
89 VP_FUNC_CALL();
90 walkerParam.iBindingTable = renderData.bindingTable;
91 walkerParam.iMediaID = renderData.mediaID;
92 walkerParam.iCurbeOffset = renderData.iCurbeOffset;
93 // Should use renderData.iCurbeLength instead of kernelSettings.CURBE_Length.
94 // kernelSettings.CURBE_Length is 32 aligned with 5 bits shift.
95 // renderData.iCurbeLength is RENDERHAL_CURBE_BLOCK_ALIGN(64) aligned.
96 walkerParam.iCurbeLength = renderData.iCurbeLength;
97
98 walkerParam.curbeResourceList = m_curbeResourceList.data();
99 walkerParam.curbeResourceListSize = m_curbeResourceList.size();
100 walkerParam.inlineResourceList = m_inlineResourceList.data();
101 walkerParam.inlineResourceListSize = m_inlineResourceList.size();
102
103 return MOS_STATUS_SUCCESS;
104 }
105
106 MOS_STATUS VpRenderKernelObj::SetSamplerStates(KERNEL_SAMPLER_STATE_GROUP& samplerStateGroup)
107 {
108 VP_FUNC_CALL();
109 return MOS_STATUS_SUCCESS;
110 }
111
112 void VpRenderKernelObj::OcaDumpKernelInfo(MOS_COMMAND_BUFFER &cmdBuffer, MOS_CONTEXT &mosContext)
113 {
114 HalOcaInterfaceNext::DumpVpKernelInfo(cmdBuffer, (MOS_CONTEXT_HANDLE)&mosContext, m_kernelId, 0, nullptr);
115 }
116
117 MOS_STATUS VpRenderKernelObj::InitRenderHalSurfaceCMF(MOS_SURFACE* src, PRENDERHAL_SURFACE renderHalSurface)
118 {
119 PMOS_INTERFACE osInterface = m_hwInterface->m_osInterface;
120 VP_RENDER_CHK_NULL_RETURN(osInterface);
121 #if !EMUL
122 PGMM_RESOURCE_INFO pGmmResourceInfo;
123 pGmmResourceInfo = (GMM_RESOURCE_INFO *)src->OsResource.pGmmResInfo;
124 MOS_OS_CHK_NULL_RETURN(pGmmResourceInfo);
125
126 GMM_RESOURCE_FORMAT gmmResFmt;
127 gmmResFmt = pGmmResourceInfo->GetResourceFormat();
128 uint32_t MmcFormat = 0;
129
130 MmcFormat = static_cast<uint32_t>(osInterface->pfnGetGmmClientContext(osInterface)->GetMediaSurfaceStateCompressionFormat(gmmResFmt));
131
132 if (MmcFormat > 0x1F)
133 {
134 MOS_OS_ASSERTMESSAGE("Get a incorrect Compression format(%d) from GMM", MmcFormat);
135 }
136 else
137 {
138 renderHalSurface->OsSurface.CompressionFormat = MmcFormat;
139 MOS_OS_VERBOSEMESSAGE("Render Enigien compression format %d", MmcFormat);
140 }
141 #endif
142 return MOS_STATUS_SUCCESS;
143 }
144
145 // Only for Adv kernels.
146 MOS_STATUS VpRenderKernelObj::SetWalkerSetting(KERNEL_THREAD_SPACE &threadSpace, bool bSyncFlag, bool flushL1)
147 {
148 VP_FUNC_CALL();
149 VP_RENDER_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED);
150 return MOS_STATUS_SUCCESS;
151 }
152
153 MOS_STATUS VpRenderKernelObj::SetTuningFlag(PKERNEL_TUNING_PARAMS tuningParams)
154 {
155 VP_FUNC_CALL();
156 m_kernelTuningParams = tuningParams;
157 return MOS_STATUS_SUCCESS;
158 }
159
160
161 MOS_STATUS VpRenderKernelObj::SetKernelArgs(KERNEL_ARGS &kernelArgs, VP_PACKET_SHARED_CONTEXT *sharedContext)
162 {
163 VP_FUNC_CALL();
164 VP_RENDER_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED);
165 return MOS_STATUS_SUCCESS;
166 }
167
168 MOS_STATUS VpRenderKernelObj::SetKernelStatefulSurfaces(KERNEL_ARG_INDEX_SURFACE_MAP &statefulSurfaces)
169 {
170 m_argIndexSurfMap = statefulSurfaces;
171 return MOS_STATUS_SUCCESS;
172 }
173
174 // Only for Adv kernels.
175 MOS_STATUS VpRenderKernelObj::SetKernelConfigs(
176 KERNEL_PARAMS& kernelParams,
177 VP_SURFACE_GROUP& surfaces,
178 KERNEL_SAMPLER_STATE_GROUP& samplerStateGroup,
179 KERNEL_CONFIGS& kernelConfigs,
180 VP_PACKET_SHARED_CONTEXT* sharedContext)
181 {
182 VP_FUNC_CALL();
183
184 VP_RENDER_CHK_STATUS_RETURN(SetKernelConfigs(kernelConfigs));
185
186 VP_RENDER_CHK_STATUS_RETURN(SetKernelArgs(kernelParams.kernelArgs, sharedContext));
187
188 VP_RENDER_CHK_STATUS_RETURN(SetKernelStatefulSurfaces(kernelParams.kernelStatefulSurfaces));
189
190 VP_RENDER_CHK_STATUS_RETURN(SetProcessSurfaceGroup(surfaces));
191
192 // when UseIndependentSamplerGroup is true, each kernel will set their own sampler state group in VpRenderCmdPacket::SetupSamplerStates()
193 if (!UseIndependentSamplerGroup())
194 {
195 VP_RENDER_CHK_STATUS_RETURN(SetSamplerStates(samplerStateGroup));
196 }
197
198 VP_RENDER_CHK_STATUS_RETURN(SetWalkerSetting(kernelParams.kernelThreadSpace, kernelParams.syncFlag,kernelParams.flushL1));
199
200 VP_RENDER_CHK_STATUS_RETURN(SetTuningFlag(&kernelParams.kernelTuningParams));
201
202 return MOS_STATUS_SUCCESS;
203 }
204
205 MOS_STATUS VpRenderKernelObj::SetKernelConfigs(KERNEL_CONFIGS& kernelConfigs)
206 {
207 VP_FUNC_CALL();
208
209 return MOS_STATUS_SUCCESS;
210 }
211
212 MOS_STATUS VpRenderKernelObj::InitKernel(void* binary, uint32_t size, KERNEL_CONFIGS& kernelConfigs,
213 VP_SURFACE_GROUP& surfacesGroup, VP_RENDER_CACHE_CNTL& surfMemCacheCtl)
214 {
215 VP_FUNC_CALL();
216
217 if (kernelCombinedFc != m_kernelId)
218 {
219 VP_RENDER_CHK_NULL_RETURN(binary);
220 }
221 // m_kernelBinary and m_kernelSize being nullptr and 0 for FC case.
222 m_kernelBinary = binary;
223 m_kernelSize = size;
224 m_curbeResourceList.clear();
225 m_inlineResourceList.clear();
226 m_curbeLocation = {};
227 SetCacheCntl(&surfMemCacheCtl);
228 VP_RENDER_CHK_STATUS_RETURN(SetKernelConfigs(kernelConfigs));
229 VP_RENDER_CHK_STATUS_RETURN(SetProcessSurfaceGroup(surfacesGroup));
230
231 VP_RENDER_NORMALMESSAGE("Kernel %d is in use.", m_kernelId);
232 MT_LOG1(MT_VP_KERNEL_Init, MT_NORMAL, MT_VP_KERNEL_ID, m_kernelId);
233
234 return MOS_STATUS_SUCCESS;
235 }
236
237 MOS_STATUS VpRenderKernelObj::CpPrepareResources()
238 {
239 VP_RENDER_NORMALMESSAGE("Not prepare reousces for CP in kernel %d.", m_kernelId);
240 return MOS_STATUS_SUCCESS;
241 }
242
243 MOS_STATUS VpRenderKernelObj::SetProcessSurfaceGroup(VP_SURFACE_GROUP &surfaces)
244 {
245 m_surfaceGroup = &surfaces;
246 VP_RENDER_CHK_STATUS_RETURN(InitBindlessResources());
247 VP_RENDER_CHK_STATUS_RETURN(SetupSurfaceState());
248 VP_RENDER_CHK_STATUS_RETURN(CpPrepareResources());
249 return MOS_STATUS_SUCCESS;
250 }
251
252 MOS_STATUS GetSurfaceSize(
253 VP_SURFACE *pSurface,
254 uint32_t iBpp,
255 uint32_t *piWidthInBytes,
256 uint32_t *piHeightInRows)
257 {
258 VP_FUNC_CALL();
259
260 MOS_STATUS eStatus;
261 uint32_t iWidthInBytes;
262 uint32_t iHeightInRows;
263
264 //-------------------------------------------
265 VP_DEBUG_ASSERT(pSurface->osSurface->dwWidth >= 1);
266 VP_DEBUG_ASSERT(pSurface->osSurface->dwHeight >= 1);
267 VP_DEBUG_ASSERT(pSurface->osSurface->dwPitch >= 1);
268 //-------------------------------------------
269
270 eStatus = MOS_STATUS_SUCCESS;
271
272 switch (pSurface->osSurface->Format)
273 {
274 // Packed Formats
275 case Format_A8R8G8B8:
276 case Format_X8R8G8B8:
277 case Format_A8B8G8R8:
278 case Format_X8B8G8R8:
279 case Format_R5G6B5:
280 case Format_R8G8B8:
281 case Format_R32U:
282 case Format_R32F:
283 case Format_AYUV:
284 case Format_YUY2:
285 case Format_YUYV:
286 case Format_YVYU:
287 case Format_UYVY:
288 case Format_VYUY:
289 case Format_AI44:
290 case Format_IA44:
291 case Format_P8:
292 case Format_A8P8:
293 case Format_A8:
294 case Format_L8:
295 case Format_A4L4:
296 case Format_A8L8:
297 case Format_V8U8:
298 case Format_R10G10B10A2:
299 case Format_B10G10R10A2:
300 case Format_Y410:
301 case Format_Y416:
302 case Format_Y210:
303 case Format_Y216:
304 case Format_R16F:
305 iWidthInBytes = pSurface->osSurface->dwWidth * iBpp / 8;
306 iHeightInRows = pSurface->osSurface->dwHeight;
307 break;
308
309 // 4:2:0 (12-bits per pixel)
310 // IMC1 // IMC3
311 // -----------------> // ----------------->
312 // ________________________ // ________________________
313 //|Y0|Y1| | //|Y0|Y1| |
314 //|__|__| | //|__|__| |
315 //| | //| |
316 //| | //| |
317 //| | //| |
318 //| | //| |
319 //| | //| |
320 //|________________________| //|________________________|
321 //|V0|V1| | | //|U0|U1| | |
322 //|__|__| | | //|__|__| | |
323 //| | | //| | |
324 //|____________| PAD | //|____________| PAD |
325 //|U0|U1| | | //|V0|V1| | |
326 //|__|__| | | //|__|__| | |
327 //| | | //| | |
328 //|____________|___________| //|____________|___________|
329 case Format_IMC1:
330 case Format_IMC3:
331 iWidthInBytes = pSurface->osSurface->dwWidth;
332 iHeightInRows = pSurface->osSurface->dwHeight * 2;
333 break;
334
335 // 4:0:0 (8-bits per pixel)
336 // 400P
337 // ----------------->
338 // ________________________
339 //|Y0|Y1| |
340 //|__|__| |
341 //| |
342 //| |
343 //| |
344 //| |
345 //| |
346 //|________________________|
347 case Format_400P:
348 case Format_Buffer:
349 case Format_RAW:
350 iWidthInBytes = pSurface->osSurface->dwWidth;
351 iHeightInRows = pSurface->osSurface->dwHeight;
352 break;
353
354 // 4:1:1 (12-bits per pixel) // 4:2:2 (16-bits per pixel)
355 // 411P // 422H
356 // -----------------> // ----------------->
357 // ________________________ // ________________________
358 //|Y0|Y1| | //|Y0|Y1| |
359 //|__|__| | //|__|__| |
360 //| | //| |
361 //| | //| |
362 //| | //| |
363 //| | //| |
364 //| | //| |
365 //|________________________| //|________________________|
366 //|U0|U1|| | //|U0|U1| | |
367 //|__|__|| | //|__|__| | |
368 //| | | //| | |
369 //| | PAD | //| | PAD |
370 //| | | //| | |
371 //| | | //| | |
372 //| | | //| | |
373 //|______|_________________| //|____________|___________|
374 //|V0|V1|| | //|V0|V1| | |
375 //|__|__|| | //|__|__| | |
376 //| | | //| | |
377 //| | PAD | //| | PAD |
378 //| | | //| | |
379 //| | | //| | |
380 //| | | //| | |
381 //|______|_________________| //|____________|___________|
382
383 // 4:4:4 (24-bits per pixel)
384 // 444P
385 // ----------------->
386 // ________________________
387 //|Y0|Y1| |
388 //|__|__| |
389 //| |
390 //| |
391 //| |
392 //| |
393 //| |
394 //|________________________|
395 //|U0|U1| |
396 //|__|__| |
397 //| |
398 //| |
399 //| |
400 //| |
401 //| |
402 //|________________________|
403 //|V0|V1| |
404 //|__|__| |
405 //| |
406 //| |
407 //| |
408 //| |
409 //| |
410 //|________________________|
411
412 // 4:4:4 (24-bits per pixel)
413 // RGBP
414 // ----------------->
415 // ________________________
416 //|R0|R1| |
417 //|__|__| |
418 //| |
419 //| |
420 //| |
421 //| |
422 //| |
423 //|________________________|
424 //|G0|G1| |
425 //|__|__| |
426 //| |
427 //| |
428 //| |
429 //| |
430 //| |
431 //|________________________|
432 //|B0|B1| |
433 //|__|__| |
434 //| |
435 //| |
436 //| |
437 //| |
438 //| |
439 //|________________________|
440 case Format_RGBP:
441
442 // 4:4:4 (24-bits per pixel)
443 // BGRP
444 // ----------------->
445 // ________________________
446 //|B0|B1| |
447 //|__|__| |
448 //| |
449 //| |
450 //| |
451 //| |
452 //| |
453 //|________________________|
454 //|G0|G1| |
455 //|__|__| |
456 //| |
457 //| |
458 //| |
459 //| |
460 //| |
461 //|________________________|
462 //|R0|R1| |
463 //|__|__| |
464 //| |
465 //| |
466 //| |
467 //| |
468 //| |
469 //|________________________|
470 case Format_BGRP:
471 case Format_411P:
472 case Format_422H:
473 case Format_444P:
474 iWidthInBytes = pSurface->osSurface->dwWidth;
475 iHeightInRows = pSurface->osSurface->dwHeight * 3;
476 break;
477
478 // 4:1:1 (12-bits per pixel)
479 // 411R
480 // ----------------->
481 // ________________________
482 //|Y0|Y1| |
483 //|__|__| |
484 //| |
485 //| |
486 //| |
487 //| |
488 //| |
489 //|________________________|
490 //|U0|U1| |
491 //|__|__| |
492 //|________________________|
493 //|V0|V1| |
494 //|__|__| |
495 //|________________________|
496 case Format_411R:
497 iWidthInBytes = pSurface->osSurface->dwWidth;
498 iHeightInRows = (pSurface->osSurface->dwHeight * 3) / 2;
499 break;
500
501 // 4:2:2V (16-bits per pixel)
502 // 422V
503 // ----------------->
504 // ________________________
505 //|Y0|Y1| |
506 //|__|__| |
507 //| |
508 //| |
509 //| |
510 //| |
511 //| |
512 //|________________________|
513 //|U0|U1| |
514 //|__|__| |
515 //| |
516 //|________________________|
517 //|V0|V1| |
518 //|__|__| |
519 //| |
520 //|________________________|
521 case Format_422V:
522 iWidthInBytes = pSurface->osSurface->dwWidth;
523 iHeightInRows = pSurface->osSurface->dwHeight * 2;
524 break;
525
526 // 4:2:0 (12-bits per pixel)
527 // IMC2 // IMC4
528 // -----------------> // ----------------->
529 // ________________________ // ________________________
530 //|Y0|Y1| | //|Y0|Y1| |
531 //|__|__| | //|__|__| |
532 //| | //| |
533 //| | //| |
534 //| | //| |
535 //| | //| |
536 //| | //| |
537 //|________________________| //|________________________|
538 //|V0|V1| |U0|U1| | //|U0|U1| |V0|V1| |
539 //|__|__| |__|__| | //|__|__| |__|__| |
540 //| | | //| | |
541 //|____________|___________| //|____________|___________|
542
543 // NV12 // YV12
544 // -----------------> // ----------------->
545 // ________________________ // ________________________
546 //|Y0|Y1| | //|Y0|Y1| |
547 //|__|__| | //|__|__| |
548 //| | //| |
549 //| | //| |
550 //| | //| |
551 //| | //| |
552 //| | //| |
553 //|________________________| //|________________________|
554 //|U0|V0|U1|V1| | //|V0|V1| |
555 //|__|__|__|__| | //|__|__|__________________|
556 //| | //|U0|U1| |
557 //|________________________| //|__|__|__________________|
558
559 case Format_IMC2:
560 case Format_IMC4:
561 case Format_NV12:
562 case Format_YV12:
563 case Format_I420:
564 case Format_IYUV:
565 case Format_YVU9:
566 iWidthInBytes = pSurface->osSurface->dwWidth;
567 iHeightInRows = pSurface->osSurface->dwHeight * iBpp / 8;
568 break;
569
570 case Format_P010:
571 case Format_P016:
572 iWidthInBytes = pSurface->osSurface->dwWidth * 2;
573 iHeightInRows = pSurface->osSurface->dwHeight * 3 / 2;
574 break;
575
576 case Format_A16R16G16B16:
577 case Format_A16B16G16R16:
578 iWidthInBytes = pSurface->osSurface->dwWidth * 8;
579 iHeightInRows = pSurface->osSurface->dwHeight;
580 break;
581
582 case Format_P210:
583 case Format_P216:
584 iWidthInBytes = pSurface->osSurface->dwWidth * 2;
585 iHeightInRows = pSurface->osSurface->dwHeight * 2;
586 break;
587 default:
588 VP_RENDER_ASSERTMESSAGE("Format %d not supported.", pSurface->osSurface->Format);
589 eStatus = MOS_STATUS_UNKNOWN;
590 goto finish;
591 }
592
593 *piWidthInBytes = iWidthInBytes;
594 *piHeightInRows = iHeightInRows;
595
596 finish:
597 return eStatus;
598 }
599
600 void VpRenderKernelObj::DumpSurface(VP_SURFACE* pSurface, PCCHAR fileName)
601 {
602 uint8_t* pData;
603 char sPath[MAX_PATH];
604 uint8_t* pDst;
605 uint8_t* pTmpDst;
606 uint8_t* pTmpSrc;
607 uint32_t iWidthInBytes = 0;
608 uint32_t iHeightInRows = 0;
609 uint32_t iBpp = 0;
610 uint32_t iSize = 0;
611 uint32_t iY = 0;
612 MOS_LOCK_PARAMS LockFlags;
613
614 VP_FUNC_CALL();
615 #if !EMUL
616 PMOS_INTERFACE pOsInterface = m_hwInterface->m_osInterface;
617
618 pDst = nullptr;
619 MOS_ZeroMemory(sPath, MAX_PATH);
620
621 // get bits per pixel for the format
622 pOsInterface->pfnGetBitsPerPixel(pOsInterface, pSurface->osSurface->Format, &iBpp);
623
624 GetSurfaceSize(
625 pSurface,
626 iBpp,
627 &iWidthInBytes,
628 &iHeightInRows);
629
630 iSize = iWidthInBytes * iHeightInRows;
631
632 // Write original image to file
633 MOS_ZeroMemory(&LockFlags, sizeof(MOS_LOCK_PARAMS));
634
635 LockFlags.ReadOnly = 1;
636
637 pData = (uint8_t*)m_allocator->Lock(
638 &pSurface->osSurface->OsResource,
639 &LockFlags);
640
641 if (pData == nullptr)
642 {
643 VP_RENDER_ASSERTMESSAGE("pData == nullptr");
644 return;
645 }
646
647 MOS_SecureStringPrint(
648 sPath,
649 MAX_PATH,
650 sizeof(sPath),
651 "c:\\dump\\f[%08d]_%s_w[%d]_h[%d]_p[%d].%s",
652 1,
653 fileName,
654 pSurface->osSurface->dwWidth,
655 pSurface->osSurface->dwHeight,
656 pSurface->osSurface->dwPitch,
657 VP_GET_FORMAT_STRING(pSurface->osSurface->Format));
658
659 // Write the data to file
660 if (pSurface->osSurface->dwPitch == iWidthInBytes)
661 {
662 MosUtilities::MosWriteFileFromPtr((const char*)sPath, pData, iSize);
663 }
664 else
665 {
666 pDst = (uint8_t*)MOS_AllocAndZeroMemory(iSize);
667 pTmpSrc = pData;
668 pTmpDst = pDst;
669
670 for (iY = 0; iY < iHeightInRows; iY++)
671 {
672 MOS_SecureMemcpy(pTmpDst, iSize, pTmpSrc, iWidthInBytes);
673 pTmpSrc += pSurface->osSurface->dwPitch;
674 pTmpDst += iWidthInBytes;
675 }
676
677 MosUtilities::MosWriteFileFromPtr((const char*)sPath, pDst, iSize);
678 }
679
680 if (pDst)
681 {
682 MOS_FreeMemory(pDst);
683 }
684
685 MOS_STATUS status = m_allocator->UnLock(&pSurface->osSurface->OsResource);
686 if (MOS_FAILED(status))
687 {
688 VP_RENDER_ASSERTMESSAGE("Unlock resource failed!");
689 }
690 #endif
691 }
692
693 MOS_STATUS VpRenderKernelObj::UpdateCurbeStateHeapInfo(PMOS_RESOURCE stateHeap, uint8_t *statePtr, uint32_t offset)
694 {
695 VP_RENDER_CHK_NULL_RETURN(stateHeap);
696 VP_RENDER_CHK_NULL_RETURN(statePtr);
697
698 m_curbeLocation.offset = offset;
699 m_curbeLocation.stateHeap = stateHeap;
700 m_curbeLocation.statePtr = statePtr;
701
702 for (MHW_INDIRECT_STATE_RESOURCE_PARAMS &resourceParam : m_curbeResourceList)
703 {
704 resourceParam.stateHeap = stateHeap;
705 resourceParam.stateBasePtr = statePtr;
706 resourceParam.stateOffset += offset;
707 }
708
709 return MOS_STATUS_SUCCESS;
710 }
711
712 MOS_STATUS VpRenderKernelObj::SetInlineDataParameter(KRN_ARG arg, uint8_t* inlineData)
713 {
714 VP_FUNC_CALL();
715 VP_RENDER_CHK_NULL_RETURN(inlineData);
716 if (arg.implicitArgType == IndirectDataPtr)
717 {
718 VP_RENDER_CHK_NULL_RETURN(m_curbeLocation.stateHeap);
719 MHW_INDIRECT_STATE_RESOURCE_PARAMS params = {};
720 params.isWrite = false;
721 params.resource = m_curbeLocation.stateHeap;
722 params.resourceOffset = m_curbeLocation.offset;
723 params.stateOffset = arg.uOffsetInPayload;
724 #if MOS_COMMAND_BUFFER_DUMP_SUPPORTED
725 params.dumpName = "KERNEL_CURBE";
726 params.needDump = true;
727 params.dumpSize = m_curbeLocation.size;
728 params.resourceBasePtr = m_curbeLocation.statePtr;
729 #endif
730 m_inlineResourceList.push_back(params);
731 VP_RENDER_NORMALMESSAGE("Setting Indirect State Data Inline Data KernelID %d, index %d , argKind %d", m_kernelId, arg.uIndex, arg.eArgKind);
732 }
733 else if (arg.implicitArgType == ValueType)
734 {
735 if (arg.pData != nullptr)
736 {
737 MOS_SecureMemcpy(inlineData + arg.uOffsetInPayload, arg.uSize, arg.pData, arg.uSize);
738 VP_RENDER_NORMALMESSAGE("Setting Inline Data KernelID %d, index %d , value %d, argKind %d", m_kernelId, arg.uIndex, *(uint32_t *)arg.pData, arg.eArgKind);
739 }
740 else
741 {
742 VP_RENDER_NORMALMESSAGE("KernelID %d, index %d, argKind %d is empty", m_kernelId, arg.uIndex, arg.eArgKind);
743 }
744 }
745
746 return MOS_STATUS_SUCCESS;
747 }
748
749 MOS_STATUS VpRenderKernelObj::SetBindlessSamplerToResourceList(KRN_ARG &arg, uint32_t samplerIndex)
750 {
751 auto it = m_bindlessSamperArray.find(samplerIndex);
752 VP_PUBLIC_CHK_NOT_FOUND_RETURN(it, &m_bindlessSamperArray);
753 RENDERHAL_STATE_LOCATION &samplerStateLocation = it->second;
754 VP_PUBLIC_CHK_NULL_RETURN(samplerStateLocation.stateHeap);
755
756 MHW_INDIRECT_STATE_RESOURCE_PARAMS params = {};
757 params.isWrite = false;
758 params.resource = samplerStateLocation.stateHeap;
759 params.resourceOffset = samplerStateLocation.offset;
760 params.stateOffset = arg.uOffsetInPayload;
761 #if MOS_COMMAND_BUFFER_DUMP_SUPPORTED
762 params.dumpName = "KERNEL_SAMPLER";
763 params.needDump = true;
764 params.dumpSize = samplerStateLocation.size;
765 params.resourceBasePtr = samplerStateLocation.statePtr;
766 #endif
767 m_curbeResourceList.push_back(params);
768
769 return MOS_STATUS_SUCCESS;
770 }
771
772 MOS_STATUS VpRenderKernelObj::SetBindlessSurfaceStateToResourceList(KRN_ARG &arg)
773 {
774 auto surfMapHandle = m_argIndexSurfMap.find(arg.uIndex);
775 VP_PUBLIC_CHK_NOT_FOUND_RETURN(surfMapHandle, &m_argIndexSurfMap);
776 if (surfMapHandle->second.surfType == SurfaceTypeInvalid)
777 {
778 //for invalid surface type, it means the surface in not used in this senario
779 return MOS_STATUS_SUCCESS;
780 }
781 auto bindlessAddressHandle = m_bindlessSurfaceArray.find(surfMapHandle->second.surfType);
782 VP_PUBLIC_CHK_NOT_FOUND_RETURN(bindlessAddressHandle, &m_bindlessSurfaceArray);
783 if (surfMapHandle->second.planeIndex >= bindlessAddressHandle->second.size())
784 {
785 //for those surfaces plane number less than kernel interface max, skip these sub planes
786 return MOS_STATUS_SUCCESS;
787 }
788 RENDERHAL_STATE_LOCATION& surfStateLocation = bindlessAddressHandle->second.at(surfMapHandle->second.planeIndex);
789 VP_PUBLIC_CHK_NULL_RETURN(surfStateLocation.stateHeap);
790
791 MHW_INDIRECT_STATE_RESOURCE_PARAMS params = {};
792 params.isWrite = false;
793 params.resource = surfStateLocation.stateHeap;
794 params.resourceOffset = surfStateLocation.offset; //this is the offset of surface state in SurfStateHep
795 params.stateOffset = arg.uOffsetInPayload; //this is the offset of curbe state in GSH
796 #if MOS_COMMAND_BUFFER_DUMP_SUPPORTED
797 params.dumpName = "BINDLESS_SURFACE_STATE";
798 params.needDump = true;
799 params.dumpSize = surfStateLocation.size;
800 params.resourceBasePtr = surfStateLocation.statePtr;
801 #endif
802 m_curbeResourceList.push_back(params);
803
804 return MOS_STATUS_SUCCESS;
805 }
806
807 bool VpRenderKernelObj::IsLocalIdGeneratedByRuntime(KRN_EXECUTE_ENV &krnEnv, KRN_PER_THREAD_ARG_INFO &perThreadInfo, uint32_t localWidth, uint32_t localHeight, uint32_t localDepth)
808 {
809 return (krnEnv.uiSlmSize > 0 &&
810 krnEnv.uSimdSize == 1 &&
811 perThreadInfo.packedLocalIdSize > 0 &&
812 (localWidth > 1 || localHeight > 1 || localDepth > 1));
813 }
814
815 MOS_STATUS VpRenderKernelObj::PaddingPerThreadCurbe(uint32_t& curbeSize, uint32_t localWidth, uint32_t localHeight, uint32_t localDepth)
816 {
817 VP_RENDER_CHK_NULL_RETURN(m_hwInterface);
818 VP_RENDER_CHK_NULL_RETURN(m_hwInterface->m_renderHal);
819 VP_PUBLIC_CHK_VALUE_RETURN(m_hwInterface->m_renderHal->grfSize > 0, true);
820
821 curbeSize = MOS_ALIGN_CEIL(curbeSize, 32);
822 uint32_t localSize = MOS_MAX(localWidth, 1) * MOS_MAX(localHeight, 1) * MOS_MAX(localDepth, 1); //this is the local thread number
823 curbeSize += localSize * m_hwInterface->m_renderHal->grfSize;
824
825 return MOS_STATUS_SUCCESS;
826 }
827
828 MOS_STATUS VpRenderKernelObj::SetPerThreadCurbe(uint8_t *curbe, uint32_t offset, uint32_t curbeSize, KRN_PER_THREAD_ARG_INFO &perThreadInfo, uint32_t localWidth, uint32_t localHeight, uint32_t localDepth)
829 {
830 VP_RENDER_CHK_NULL_RETURN(m_hwInterface);
831 VP_RENDER_CHK_NULL_RETURN(m_hwInterface->m_renderHal);
832 VP_PUBLIC_CHK_VALUE_RETURN(m_hwInterface->m_renderHal->grfSize > 0, true);
833
834 uint32_t totalSize = MOS_ALIGN_CEIL(offset, 32) + perThreadInfo.packedLocalIdOffset + perThreadInfo.packedLocalIdSize;
835 uint8_t *perThreadData = curbe + MOS_ALIGN_CEIL(offset, 32) + perThreadInfo.packedLocalIdOffset;
836
837 for (uint16_t threadX = 0; threadX < MOS_MAX(localWidth, 1); ++threadX)
838 {
839 for (uint16_t threadY = 0; threadY < MOS_MAX(localHeight, 1); ++threadY)
840 {
841 for (uint16_t threadZ = 0; threadZ < MOS_MAX(localDepth, 1); ++threadZ)
842 {
843 VP_PUBLIC_CHK_VALUE_RETURN(totalSize <= curbeSize, true);
844 reinterpret_cast<uint16_t *>(perThreadData)[0] = threadX;
845 reinterpret_cast<uint16_t *>(perThreadData)[1] = threadY;
846 reinterpret_cast<uint16_t *>(perThreadData)[2] = threadZ;
847 perThreadData += m_hwInterface->m_renderHal->grfSize;
848 totalSize += m_hwInterface->m_renderHal->grfSize;
849 VP_RENDER_NORMALMESSAGE("Setting Per Thread Data X %d, Y %d, Z %d", threadX, threadY, threadZ);
850 }
851 }
852 }
853 return MOS_STATUS_SUCCESS;
854 }