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
VpRenderKernelObj(PVP_MHWINTERFACE hwInterface,PVpAllocator allocator)34 VpRenderKernelObj::VpRenderKernelObj(PVP_MHWINTERFACE hwInterface, PVpAllocator allocator) :
35 m_hwInterface(hwInterface),
36 m_allocator(allocator)
37 {
38 }
39
VpRenderKernelObj(PVP_MHWINTERFACE hwInterface,VpKernelID kernelId,uint32_t kernelIndex,std::string kernelName,PVpAllocator allocator)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
~VpRenderKernelObj()46 VpRenderKernelObj::~VpRenderKernelObj()
47 {
48 }
49
50 // For Adv kernel
Init(VpRenderKernel & 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
GetKernelBinaryID()58 uint32_t VpRenderKernelObj::GetKernelBinaryID()
59 {
60 VP_FUNC_CALL();
61
62 return m_kernelBinaryID;
63 }
64
GetKernelEntry(Kdll_CacheEntry & entry)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.pBinary = (uint8_t *)m_kernelBinary;
76 return MOS_STATUS_SUCCESS;
77 }
78
GetKernelIndex()79 uint32_t VpRenderKernelObj::GetKernelIndex()
80 {
81 VP_FUNC_CALL();
82
83 return m_kernelIndex;
84 }
85
GetWalkerSetting(KERNEL_WALKER_PARAMS & walkerParam,KERNEL_PACKET_RENDER_DATA & renderData)86 MOS_STATUS VpRenderKernelObj::GetWalkerSetting(KERNEL_WALKER_PARAMS& walkerParam, KERNEL_PACKET_RENDER_DATA &renderData)
87 {
88 VP_FUNC_CALL();
89 walkerParam.iBindingTable = renderData.bindingTable;
90 walkerParam.iMediaID = renderData.mediaID;
91 walkerParam.iCurbeOffset = renderData.iCurbeOffset;
92 // Should use renderData.iCurbeLength instead of kernelSettings.CURBE_Length.
93 // kernelSettings.CURBE_Length is 32 aligned with 5 bits shift.
94 // renderData.iCurbeLength is RENDERHAL_CURBE_BLOCK_ALIGN(64) aligned.
95 walkerParam.iCurbeLength = renderData.iCurbeLength;
96 return MOS_STATUS_SUCCESS;
97 }
98
SetSamplerStates(KERNEL_SAMPLER_STATE_GROUP & samplerStateGroup)99 MOS_STATUS VpRenderKernelObj::SetSamplerStates(KERNEL_SAMPLER_STATE_GROUP& samplerStateGroup)
100 {
101 VP_FUNC_CALL();
102 return MOS_STATUS_SUCCESS;
103 }
104
OcaDumpKernelInfo(MOS_COMMAND_BUFFER & cmdBuffer,MOS_CONTEXT & mosContext)105 void VpRenderKernelObj::OcaDumpKernelInfo(MOS_COMMAND_BUFFER &cmdBuffer, MOS_CONTEXT &mosContext)
106 {
107 HalOcaInterfaceNext::DumpVpKernelInfo(cmdBuffer, (MOS_CONTEXT_HANDLE)&mosContext, m_kernelId, 0, nullptr);
108 }
109
InitRenderHalSurfaceCMF(MOS_SURFACE * src,PRENDERHAL_SURFACE renderHalSurface)110 MOS_STATUS VpRenderKernelObj::InitRenderHalSurfaceCMF(MOS_SURFACE* src, PRENDERHAL_SURFACE renderHalSurface)
111 {
112 PMOS_INTERFACE osInterface = m_hwInterface->m_osInterface;
113 VP_RENDER_CHK_NULL_RETURN(osInterface);
114 #if !EMUL
115 PGMM_RESOURCE_INFO pGmmResourceInfo;
116 pGmmResourceInfo = (GMM_RESOURCE_INFO *)src->OsResource.pGmmResInfo;
117 MOS_OS_CHK_NULL_RETURN(pGmmResourceInfo);
118
119 GMM_RESOURCE_FORMAT gmmResFmt;
120 gmmResFmt = pGmmResourceInfo->GetResourceFormat();
121 uint32_t MmcFormat = 0;
122
123 MmcFormat = static_cast<uint32_t>(osInterface->pfnGetGmmClientContext(osInterface)->GetMediaSurfaceStateCompressionFormat(gmmResFmt));
124
125 if (MmcFormat > 0x1F)
126 {
127 MOS_OS_ASSERTMESSAGE("Get a incorrect Compression format(%d) from GMM", MmcFormat);
128 }
129 else
130 {
131 renderHalSurface->OsSurface.CompressionFormat = MmcFormat;
132 MOS_OS_VERBOSEMESSAGE("Render Enigien compression format %d", MmcFormat);
133 }
134 #endif
135 return MOS_STATUS_SUCCESS;
136 }
137
138 // Only for Adv kernels.
SetWalkerSetting(KERNEL_THREAD_SPACE & threadSpace,bool bSyncFlag,bool flushL1)139 MOS_STATUS VpRenderKernelObj::SetWalkerSetting(KERNEL_THREAD_SPACE &threadSpace, bool bSyncFlag, bool flushL1)
140 {
141 VP_FUNC_CALL();
142 VP_RENDER_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED);
143 return MOS_STATUS_SUCCESS;
144 }
145
SetTuningFlag(PKERNEL_TUNING_PARAMS tuningParams)146 MOS_STATUS VpRenderKernelObj::SetTuningFlag(PKERNEL_TUNING_PARAMS tuningParams)
147 {
148 VP_FUNC_CALL();
149 m_kernelTuningParams = tuningParams;
150 return MOS_STATUS_SUCCESS;
151 }
152
153
SetKernelArgs(KERNEL_ARGS & kernelArgs,VP_PACKET_SHARED_CONTEXT * sharedContext)154 MOS_STATUS VpRenderKernelObj::SetKernelArgs(KERNEL_ARGS &kernelArgs, VP_PACKET_SHARED_CONTEXT *sharedContext)
155 {
156 VP_FUNC_CALL();
157 VP_RENDER_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED);
158 return MOS_STATUS_SUCCESS;
159 }
160
SetKernelStatefulSurfaces(KERNEL_ARG_INDEX_SURFACE_MAP & statefulSurfaces)161 MOS_STATUS VpRenderKernelObj::SetKernelStatefulSurfaces(KERNEL_ARG_INDEX_SURFACE_MAP& statefulSurfaces)
162 {
163 VP_FUNC_CALL();
164 return MOS_STATUS_SUCCESS;
165 }
166
167 // Only for Adv kernels.
SetKernelConfigs(KERNEL_PARAMS & kernelParams,VP_SURFACE_GROUP & surfaces,KERNEL_SAMPLER_STATE_GROUP & samplerStateGroup,KERNEL_CONFIGS & kernelConfigs,VP_PACKET_SHARED_CONTEXT * sharedContext)168 MOS_STATUS VpRenderKernelObj::SetKernelConfigs(
169 KERNEL_PARAMS& kernelParams,
170 VP_SURFACE_GROUP& surfaces,
171 KERNEL_SAMPLER_STATE_GROUP& samplerStateGroup,
172 KERNEL_CONFIGS& kernelConfigs,
173 VP_PACKET_SHARED_CONTEXT* sharedContext)
174 {
175 VP_FUNC_CALL();
176
177 VP_RENDER_CHK_STATUS_RETURN(SetKernelConfigs(kernelConfigs));
178
179 VP_RENDER_CHK_STATUS_RETURN(SetKernelArgs(kernelParams.kernelArgs, sharedContext));
180
181 VP_RENDER_CHK_STATUS_RETURN(SetKernelStatefulSurfaces(kernelParams.kernelStatefulSurfaces));
182
183 VP_RENDER_CHK_STATUS_RETURN(SetProcessSurfaceGroup(surfaces));
184
185 // when UseIndependentSamplerGroup is true, each kernel will set their own sampler state group in VpRenderCmdPacket::SetupSamplerStates()
186 if (!UseIndependentSamplerGroup())
187 {
188 VP_RENDER_CHK_STATUS_RETURN(SetSamplerStates(samplerStateGroup));
189 }
190
191 VP_RENDER_CHK_STATUS_RETURN(SetWalkerSetting(kernelParams.kernelThreadSpace, kernelParams.syncFlag,kernelParams.flushL1));
192
193 VP_RENDER_CHK_STATUS_RETURN(SetTuningFlag(&kernelParams.kernelTuningParams));
194
195 return MOS_STATUS_SUCCESS;
196 }
197
SetKernelConfigs(KERNEL_CONFIGS & kernelConfigs)198 MOS_STATUS VpRenderKernelObj::SetKernelConfigs(KERNEL_CONFIGS& kernelConfigs)
199 {
200 VP_FUNC_CALL();
201
202 return MOS_STATUS_SUCCESS;
203 }
204
InitKernel(void * binary,uint32_t size,KERNEL_CONFIGS & kernelConfigs,VP_SURFACE_GROUP & surfacesGroup,VP_RENDER_CACHE_CNTL & surfMemCacheCtl)205 MOS_STATUS VpRenderKernelObj::InitKernel(void* binary, uint32_t size, KERNEL_CONFIGS& kernelConfigs,
206 VP_SURFACE_GROUP& surfacesGroup, VP_RENDER_CACHE_CNTL& surfMemCacheCtl)
207 {
208 VP_FUNC_CALL();
209
210 if (kernelCombinedFc != m_kernelId)
211 {
212 VP_RENDER_CHK_NULL_RETURN(binary);
213 }
214 // m_kernelBinary and m_kernelSize being nullptr and 0 for FC case.
215 m_kernelBinary = binary;
216 m_kernelSize = size;
217 SetCacheCntl(&surfMemCacheCtl);
218 VP_RENDER_CHK_STATUS_RETURN(SetKernelConfigs(kernelConfigs));
219 VP_RENDER_CHK_STATUS_RETURN(SetProcessSurfaceGroup(surfacesGroup));
220
221 VP_RENDER_NORMALMESSAGE("Kernel %d is in use.", m_kernelId);
222 MT_LOG1(MT_VP_KERNEL_Init, MT_NORMAL, MT_VP_KERNEL_ID, m_kernelId);
223
224 return MOS_STATUS_SUCCESS;
225 }
226
CpPrepareResources()227 MOS_STATUS VpRenderKernelObj::CpPrepareResources()
228 {
229 VP_RENDER_NORMALMESSAGE("Not prepare reousces for CP in kernel %d.", m_kernelId);
230 return MOS_STATUS_SUCCESS;
231 }
232
SetupStatelessBuffer()233 MOS_STATUS VpRenderKernelObj::SetupStatelessBuffer()
234 {
235 m_statelessArray.clear();
236 VP_RENDER_NORMALMESSAGE("Not prepare stateless buffer in kernel %d.", m_kernelId);
237 return MOS_STATUS_SUCCESS;
238 }
239
SetupStatelessBufferResource(SurfaceType surf)240 MOS_STATUS VpRenderKernelObj::SetupStatelessBufferResource(SurfaceType surf)
241 {
242 VP_RENDER_CHK_NULL_RETURN(m_surfaceGroup);
243 VP_RENDER_CHK_NULL_RETURN(m_hwInterface);
244 if (surf != SurfaceTypeInvalid)
245 {
246 PMOS_INTERFACE osInterface = m_hwInterface->m_osInterface;
247 VP_RENDER_CHK_NULL_RETURN(osInterface);
248 auto it = m_surfaceGroup->find(surf);
249 VP_SURFACE *curSurf = (m_surfaceGroup->end() != it) ? it->second : nullptr;
250 VP_RENDER_CHK_NULL_RETURN(curSurf);
251 uint64_t ui64GfxAddress = osInterface->pfnGetResourceGfxAddress(osInterface, &curSurf->osSurface->OsResource);
252
253 VP_RENDER_CHK_STATUS_RETURN(osInterface->pfnRegisterResource(
254 osInterface,
255 &curSurf->osSurface->OsResource,
256 false,
257 true));
258 m_statelessArray.insert(std::make_pair(surf, ui64GfxAddress));
259 }
260
261 return MOS_STATUS_SUCCESS;
262 }
263
SetProcessSurfaceGroup(VP_SURFACE_GROUP & surfaces)264 MOS_STATUS VpRenderKernelObj::SetProcessSurfaceGroup(VP_SURFACE_GROUP &surfaces)
265 {
266 m_surfaceGroup = &surfaces;
267 VP_RENDER_CHK_STATUS_RETURN(InitBindlessResources());
268 VP_RENDER_CHK_STATUS_RETURN(SetupSurfaceState());
269 VP_RENDER_CHK_STATUS_RETURN(CpPrepareResources());
270 VP_RENDER_CHK_STATUS_RETURN(SetupStatelessBuffer());
271 return MOS_STATUS_SUCCESS;
272 }
273
GetSurfaceSize(VP_SURFACE * pSurface,uint32_t iBpp,uint32_t * piWidthInBytes,uint32_t * piHeightInRows)274 MOS_STATUS GetSurfaceSize(
275 VP_SURFACE *pSurface,
276 uint32_t iBpp,
277 uint32_t *piWidthInBytes,
278 uint32_t *piHeightInRows)
279 {
280 VP_FUNC_CALL();
281
282 MOS_STATUS eStatus;
283 uint32_t iWidthInBytes;
284 uint32_t iHeightInRows;
285
286 //-------------------------------------------
287 VP_DEBUG_ASSERT(pSurface->osSurface->dwWidth >= 1);
288 VP_DEBUG_ASSERT(pSurface->osSurface->dwHeight >= 1);
289 VP_DEBUG_ASSERT(pSurface->osSurface->dwPitch >= 1);
290 //-------------------------------------------
291
292 eStatus = MOS_STATUS_SUCCESS;
293
294 switch (pSurface->osSurface->Format)
295 {
296 // Packed Formats
297 case Format_A8R8G8B8:
298 case Format_X8R8G8B8:
299 case Format_A8B8G8R8:
300 case Format_X8B8G8R8:
301 case Format_R5G6B5:
302 case Format_R8G8B8:
303 case Format_R32U:
304 case Format_R32F:
305 case Format_AYUV:
306 case Format_YUY2:
307 case Format_YUYV:
308 case Format_YVYU:
309 case Format_UYVY:
310 case Format_VYUY:
311 case Format_AI44:
312 case Format_IA44:
313 case Format_P8:
314 case Format_A8P8:
315 case Format_A8:
316 case Format_L8:
317 case Format_A4L4:
318 case Format_A8L8:
319 case Format_V8U8:
320 case Format_R10G10B10A2:
321 case Format_B10G10R10A2:
322 case Format_Y410:
323 case Format_Y416:
324 case Format_Y210:
325 case Format_Y216:
326 case Format_R16F:
327 iWidthInBytes = pSurface->osSurface->dwWidth * iBpp / 8;
328 iHeightInRows = pSurface->osSurface->dwHeight;
329 break;
330
331 // 4:2:0 (12-bits per pixel)
332 // IMC1 // IMC3
333 // -----------------> // ----------------->
334 // ________________________ // ________________________
335 //|Y0|Y1| | //|Y0|Y1| |
336 //|__|__| | //|__|__| |
337 //| | //| |
338 //| | //| |
339 //| | //| |
340 //| | //| |
341 //| | //| |
342 //|________________________| //|________________________|
343 //|V0|V1| | | //|U0|U1| | |
344 //|__|__| | | //|__|__| | |
345 //| | | //| | |
346 //|____________| PAD | //|____________| PAD |
347 //|U0|U1| | | //|V0|V1| | |
348 //|__|__| | | //|__|__| | |
349 //| | | //| | |
350 //|____________|___________| //|____________|___________|
351 case Format_IMC1:
352 case Format_IMC3:
353 iWidthInBytes = pSurface->osSurface->dwWidth;
354 iHeightInRows = pSurface->osSurface->dwHeight * 2;
355 break;
356
357 // 4:0:0 (8-bits per pixel)
358 // 400P
359 // ----------------->
360 // ________________________
361 //|Y0|Y1| |
362 //|__|__| |
363 //| |
364 //| |
365 //| |
366 //| |
367 //| |
368 //|________________________|
369 case Format_400P:
370 case Format_Buffer:
371 case Format_RAW:
372 iWidthInBytes = pSurface->osSurface->dwWidth;
373 iHeightInRows = pSurface->osSurface->dwHeight;
374 break;
375
376 // 4:1:1 (12-bits per pixel) // 4:2:2 (16-bits per pixel)
377 // 411P // 422H
378 // -----------------> // ----------------->
379 // ________________________ // ________________________
380 //|Y0|Y1| | //|Y0|Y1| |
381 //|__|__| | //|__|__| |
382 //| | //| |
383 //| | //| |
384 //| | //| |
385 //| | //| |
386 //| | //| |
387 //|________________________| //|________________________|
388 //|U0|U1|| | //|U0|U1| | |
389 //|__|__|| | //|__|__| | |
390 //| | | //| | |
391 //| | PAD | //| | PAD |
392 //| | | //| | |
393 //| | | //| | |
394 //| | | //| | |
395 //|______|_________________| //|____________|___________|
396 //|V0|V1|| | //|V0|V1| | |
397 //|__|__|| | //|__|__| | |
398 //| | | //| | |
399 //| | PAD | //| | PAD |
400 //| | | //| | |
401 //| | | //| | |
402 //| | | //| | |
403 //|______|_________________| //|____________|___________|
404
405 // 4:4:4 (24-bits per pixel)
406 // 444P
407 // ----------------->
408 // ________________________
409 //|Y0|Y1| |
410 //|__|__| |
411 //| |
412 //| |
413 //| |
414 //| |
415 //| |
416 //|________________________|
417 //|U0|U1| |
418 //|__|__| |
419 //| |
420 //| |
421 //| |
422 //| |
423 //| |
424 //|________________________|
425 //|V0|V1| |
426 //|__|__| |
427 //| |
428 //| |
429 //| |
430 //| |
431 //| |
432 //|________________________|
433
434 // 4:4:4 (24-bits per pixel)
435 // RGBP
436 // ----------------->
437 // ________________________
438 //|R0|R1| |
439 //|__|__| |
440 //| |
441 //| |
442 //| |
443 //| |
444 //| |
445 //|________________________|
446 //|G0|G1| |
447 //|__|__| |
448 //| |
449 //| |
450 //| |
451 //| |
452 //| |
453 //|________________________|
454 //|B0|B1| |
455 //|__|__| |
456 //| |
457 //| |
458 //| |
459 //| |
460 //| |
461 //|________________________|
462 case Format_RGBP:
463
464 // 4:4:4 (24-bits per pixel)
465 // BGRP
466 // ----------------->
467 // ________________________
468 //|B0|B1| |
469 //|__|__| |
470 //| |
471 //| |
472 //| |
473 //| |
474 //| |
475 //|________________________|
476 //|G0|G1| |
477 //|__|__| |
478 //| |
479 //| |
480 //| |
481 //| |
482 //| |
483 //|________________________|
484 //|R0|R1| |
485 //|__|__| |
486 //| |
487 //| |
488 //| |
489 //| |
490 //| |
491 //|________________________|
492 case Format_BGRP:
493 case Format_411P:
494 case Format_422H:
495 case Format_444P:
496 iWidthInBytes = pSurface->osSurface->dwWidth;
497 iHeightInRows = pSurface->osSurface->dwHeight * 3;
498 break;
499
500 // 4:1:1 (12-bits per pixel)
501 // 411R
502 // ----------------->
503 // ________________________
504 //|Y0|Y1| |
505 //|__|__| |
506 //| |
507 //| |
508 //| |
509 //| |
510 //| |
511 //|________________________|
512 //|U0|U1| |
513 //|__|__| |
514 //|________________________|
515 //|V0|V1| |
516 //|__|__| |
517 //|________________________|
518 case Format_411R:
519 iWidthInBytes = pSurface->osSurface->dwWidth;
520 iHeightInRows = (pSurface->osSurface->dwHeight * 3) / 2;
521 break;
522
523 // 4:2:2V (16-bits per pixel)
524 // 422V
525 // ----------------->
526 // ________________________
527 //|Y0|Y1| |
528 //|__|__| |
529 //| |
530 //| |
531 //| |
532 //| |
533 //| |
534 //|________________________|
535 //|U0|U1| |
536 //|__|__| |
537 //| |
538 //|________________________|
539 //|V0|V1| |
540 //|__|__| |
541 //| |
542 //|________________________|
543 case Format_422V:
544 iWidthInBytes = pSurface->osSurface->dwWidth;
545 iHeightInRows = pSurface->osSurface->dwHeight * 2;
546 break;
547
548 // 4:2:0 (12-bits per pixel)
549 // IMC2 // IMC4
550 // -----------------> // ----------------->
551 // ________________________ // ________________________
552 //|Y0|Y1| | //|Y0|Y1| |
553 //|__|__| | //|__|__| |
554 //| | //| |
555 //| | //| |
556 //| | //| |
557 //| | //| |
558 //| | //| |
559 //|________________________| //|________________________|
560 //|V0|V1| |U0|U1| | //|U0|U1| |V0|V1| |
561 //|__|__| |__|__| | //|__|__| |__|__| |
562 //| | | //| | |
563 //|____________|___________| //|____________|___________|
564
565 // NV12 // YV12
566 // -----------------> // ----------------->
567 // ________________________ // ________________________
568 //|Y0|Y1| | //|Y0|Y1| |
569 //|__|__| | //|__|__| |
570 //| | //| |
571 //| | //| |
572 //| | //| |
573 //| | //| |
574 //| | //| |
575 //|________________________| //|________________________|
576 //|U0|V0|U1|V1| | //|V0|V1| |
577 //|__|__|__|__| | //|__|__|__________________|
578 //| | //|U0|U1| |
579 //|________________________| //|__|__|__________________|
580
581 case Format_IMC2:
582 case Format_IMC4:
583 case Format_NV12:
584 case Format_YV12:
585 case Format_I420:
586 case Format_IYUV:
587 case Format_YVU9:
588 iWidthInBytes = pSurface->osSurface->dwWidth;
589 iHeightInRows = pSurface->osSurface->dwHeight * iBpp / 8;
590 break;
591
592 case Format_P010:
593 case Format_P016:
594 iWidthInBytes = pSurface->osSurface->dwWidth * 2;
595 iHeightInRows = pSurface->osSurface->dwHeight * 3 / 2;
596 break;
597
598 case Format_A16R16G16B16:
599 case Format_A16B16G16R16:
600 iWidthInBytes = pSurface->osSurface->dwWidth * 8;
601 iHeightInRows = pSurface->osSurface->dwHeight;
602 break;
603
604 case Format_P210:
605 case Format_P216:
606 iWidthInBytes = pSurface->osSurface->dwWidth * 2;
607 iHeightInRows = pSurface->osSurface->dwHeight * 2;
608 break;
609 default:
610 VP_RENDER_ASSERTMESSAGE("Format %d not supported.", pSurface->osSurface->Format);
611 eStatus = MOS_STATUS_UNKNOWN;
612 goto finish;
613 }
614
615 *piWidthInBytes = iWidthInBytes;
616 *piHeightInRows = iHeightInRows;
617
618 finish:
619 return eStatus;
620 }
621
DumpSurface(VP_SURFACE * pSurface,PCCHAR fileName)622 void VpRenderKernelObj::DumpSurface(VP_SURFACE* pSurface, PCCHAR fileName)
623 {
624 uint8_t* pData;
625 char sPath[MAX_PATH];
626 uint8_t* pDst;
627 uint8_t* pTmpDst;
628 uint8_t* pTmpSrc;
629 uint32_t iWidthInBytes = 0;
630 uint32_t iHeightInRows = 0;
631 uint32_t iBpp = 0;
632 uint32_t iSize = 0;
633 uint32_t iY = 0;
634 MOS_LOCK_PARAMS LockFlags;
635
636 VP_FUNC_CALL();
637 #if !EMUL
638 PMOS_INTERFACE pOsInterface = m_hwInterface->m_osInterface;
639
640 pDst = nullptr;
641 MOS_ZeroMemory(sPath, MAX_PATH);
642
643 // get bits per pixel for the format
644 pOsInterface->pfnGetBitsPerPixel(pOsInterface, pSurface->osSurface->Format, &iBpp);
645
646 GetSurfaceSize(
647 pSurface,
648 iBpp,
649 &iWidthInBytes,
650 &iHeightInRows);
651
652 iSize = iWidthInBytes * iHeightInRows;
653
654 // Write original image to file
655 MOS_ZeroMemory(&LockFlags, sizeof(MOS_LOCK_PARAMS));
656
657 LockFlags.ReadOnly = 1;
658
659 pData = (uint8_t*)m_allocator->Lock(
660 &pSurface->osSurface->OsResource,
661 &LockFlags);
662
663 if (pData == nullptr)
664 {
665 VP_RENDER_ASSERTMESSAGE("pData == nullptr");
666 return;
667 }
668
669 MOS_SecureStringPrint(
670 sPath,
671 MAX_PATH,
672 sizeof(sPath),
673 "c:\\dump\\f[%08d]_%s_w[%d]_h[%d]_p[%d].%s",
674 1,
675 fileName,
676 pSurface->osSurface->dwWidth,
677 pSurface->osSurface->dwHeight,
678 pSurface->osSurface->dwPitch,
679 VP_GET_FORMAT_STRING(pSurface->osSurface->Format));
680
681 // Write the data to file
682 if (pSurface->osSurface->dwPitch == iWidthInBytes)
683 {
684 MosUtilities::MosWriteFileFromPtr((const char*)sPath, pData, iSize);
685 }
686 else
687 {
688 pDst = (uint8_t*)MOS_AllocAndZeroMemory(iSize);
689 pTmpSrc = pData;
690 pTmpDst = pDst;
691
692 for (iY = 0; iY < iHeightInRows; iY++)
693 {
694 MOS_SecureMemcpy(pTmpDst, iSize, pTmpSrc, iWidthInBytes);
695 pTmpSrc += pSurface->osSurface->dwPitch;
696 pTmpDst += iWidthInBytes;
697 }
698
699 MosUtilities::MosWriteFileFromPtr((const char*)sPath, pDst, iSize);
700 }
701
702 if (pDst)
703 {
704 MOS_FreeMemory(pDst);
705 }
706
707 MOS_STATUS status = m_allocator->UnLock(&pSurface->osSurface->OsResource);
708 if (MOS_FAILED(status))
709 {
710 VP_RENDER_ASSERTMESSAGE("Unlock resource failed!");
711 }
712 #endif
713 }
714
SetInlineDataParameter(KRN_ARG args,RENDERHAL_INTERFACE * renderhal)715 MOS_STATUS VpRenderKernelObj::SetInlineDataParameter(KRN_ARG args, RENDERHAL_INTERFACE *renderhal)
716 {
717 VP_FUNC_CALL();
718 MHW_INLINE_DATA_PARAMS inlineDataPar = {};
719 VP_RENDER_CHK_NULL_RETURN(renderhal);
720 MHW_STATE_BASE_ADDR_PARAMS *pStateBaseParams = &renderhal->StateBaseAddressParams;
721 inlineDataPar.dwOffset = args.uOffsetInPayload;
722 inlineDataPar.dwSize = args.uSize;
723 if (args.implicitArgType == IndirectDataPtr || args.implicitArgType == SamplerStateBasePtr)
724 {
725 inlineDataPar.resource = pStateBaseParams->presGeneralState;
726 inlineDataPar.isPtrType = true;
727 }
728 else if (args.implicitArgType == SurfaceStateBasePtr)
729 {
730 // New Heaps
731 inlineDataPar.isPtrType = true;
732 }
733 else if (args.implicitArgType == ValueType)
734 {
735 inlineDataPar.isPtrType = false;
736 }
737
738 // walkerParam.inlineDataParamBase will add m_inlineDataParams.data() in each kernel
739 // walkerParam.inlineDataParamSize will add m_inlineDataParams.size() in each kernel
740 m_inlineDataParams.push_back(inlineDataPar);
741
742 return MOS_STATUS_SUCCESS;
743 }