Debian Codegraph @

media_softlet/agnostic/common/vp/hal/bufferMgr/vp_allocator.cpp

raw
1 /*
2 * Copyright (c) 2019-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_allocator.cpp
24 //! \brief Defines the interface for vp resource allocate
25 //! \details vp allocator will allocate and destory buffers, the caller
26 //! can use directly
27 //!
28
29 #include "vp_allocator.h"
30 #include "vp_utils.h"
31 #include "mos_solo_generic.h"
32 #include "levelzero_npu_interface.h"
33
34 using namespace vp;
35
36 VpAllocator::VpAllocator(PMOS_INTERFACE osInterface, MediaMemComp *mmc) :
37 m_osInterface(osInterface),
38 m_mmc(mmc)
39 {
40 m_allocator = MOS_New(Allocator, m_osInterface);
41 VP_PUBLIC_CHK_NULL_NO_STATUS_RETURN(m_allocator);
42 }
43
44 VpAllocator::~VpAllocator()
45 {
46 if (m_allocator)
47 {
48 m_allocator->DestroyAllResources();
49 MOS_Delete(m_allocator);
50 }
51 }
52
53 //Paried with DestroyResource or DestroyAllResources
54 MOS_RESOURCE* VpAllocator::AllocateResource(MOS_ALLOC_GFXRES_PARAMS &param, bool zeroOnAllocate)
55 {
56 VP_FUNC_CALL();
57 if (!m_allocator)
58 return nullptr;
59
60 return m_allocator->AllocateResource(param, zeroOnAllocate, COMPONENT_VPCommon);
61 }
62
63 MOS_STATUS VpAllocator::DestroyResource(MOS_RESOURCE *resource)
64 {
65 VP_FUNC_CALL();
66 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
67
68 return m_allocator->DestroyResource(resource);
69 }
70
71 MOS_STATUS VpAllocator::DestroyAllResources()
72 {
73 VP_FUNC_CALL();
74 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
75
76 return m_allocator->DestroyAllResources();
77 }
78
79 //Paried with FreeResource
80 MOS_STATUS VpAllocator::AllocateResource(MOS_RESOURCE *res, MOS_ALLOC_GFXRES_PARAMS &param)
81 {
82 VP_FUNC_CALL();
83 if (!m_allocator)
84 return MOS_STATUS_NULL_POINTER;
85
86 return m_allocator->AllocateResource(res, param);
87 }
88
89 MOS_STATUS VpAllocator::FreeResource(MOS_RESOURCE *resource)
90 {
91 VP_FUNC_CALL();
92 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
93
94 return m_allocator->FreeResource(resource);
95 }
96
97 void VpAllocator::UpdateSurfacePlaneOffset(MOS_SURFACE &surf)
98 {
99 VP_FUNC_CALL();
100 // dwOffset/YPlaneOffset/UPlaneOffset/VPlaneOffset will not be initialized during GetSurfaceInfo.
101 // Initialize them with RenderOffset when needed.
102 if (IS_RGB32_FORMAT(surf.Format) ||
103 IS_RGB16_FORMAT(surf.Format) ||
104 IS_RGB64_FORMAT(surf.Format) ||
105 surf.Format == Format_RGB ||
106 surf.Format == Format_Y410)
107 {
108 surf.dwOffset = surf.RenderOffset.RGB.BaseOffset;
109 surf.YPlaneOffset.iSurfaceOffset = surf.RenderOffset.RGB.BaseOffset;
110 surf.YPlaneOffset.iXOffset = surf.RenderOffset.RGB.XOffset;
111 surf.YPlaneOffset.iYOffset = surf.RenderOffset.RGB.YOffset;
112 }
113 else // YUV or PL3_RGB
114 {
115 // Get Y plane information (plane offset, X/Y offset)
116 surf.dwOffset = surf.RenderOffset.YUV.Y.BaseOffset;
117 surf.YPlaneOffset.iSurfaceOffset = surf.RenderOffset.YUV.Y.BaseOffset;
118 surf.YPlaneOffset.iXOffset = surf.RenderOffset.YUV.Y.XOffset;
119 surf.YPlaneOffset.iYOffset = surf.RenderOffset.YUV.Y.YOffset;
120 surf.YPlaneOffset.iLockSurfaceOffset = surf.LockOffset.YUV.Y;
121
122 // Get U/UV plane information (plane offset, X/Y offset)
123 surf.UPlaneOffset.iSurfaceOffset = surf.RenderOffset.YUV.U.BaseOffset;
124 surf.UPlaneOffset.iXOffset = surf.RenderOffset.YUV.U.XOffset;
125 surf.UPlaneOffset.iYOffset = surf.RenderOffset.YUV.U.YOffset;
126 surf.UPlaneOffset.iLockSurfaceOffset = surf.LockOffset.YUV.U;
127
128 // Get V plane information (plane offset, X/Y offset)
129 surf.VPlaneOffset.iSurfaceOffset = surf.RenderOffset.YUV.V.BaseOffset;
130 surf.VPlaneOffset.iXOffset = surf.RenderOffset.YUV.V.XOffset;
131 surf.VPlaneOffset.iYOffset = surf.RenderOffset.YUV.V.YOffset;
132 surf.VPlaneOffset.iLockSurfaceOffset = surf.LockOffset.YUV.V;
133 }
134 }
135
136 //Paried with AllocateSurface
137 MOS_SURFACE* VpAllocator::AllocateSurface(MOS_ALLOC_GFXRES_PARAMS &param, bool zeroOnAllocate)
138 {
139 VP_FUNC_CALL();
140 if (!m_allocator)
141 return nullptr;
142
143 MOS_SURFACE* surf = m_allocator->AllocateSurface(param, zeroOnAllocate, COMPONENT_VPCommon);
144
145 if (surf)
146 {
147 // Format is not initialized in Allocator::AllocateSurface. Remove it after
148 // it being fixed in Allocator::AllocateSurface.
149 surf->Format = param.Format;
150
151 if (MOS_FAILED(SetMmcFlags(*surf)))
152 {
153 VP_PUBLIC_ASSERTMESSAGE("Set mmc flags failed during AllocateSurface!");
154 m_allocator->DestroySurface(surf);
155 return nullptr;
156 }
157
158 UpdateSurfacePlaneOffset(*surf);
159 }
160
161 return surf;
162 }
163
164 MOS_STATUS VpAllocator::DestroySurface(MOS_SURFACE *surface, MOS_GFXRES_FREE_FLAGS flags)
165 {
166 VP_FUNC_CALL();
167 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
168 MOS_GFXRES_FREE_FLAGS resFreeFlags = {0};
169 if (IsSyncFreeNeededForMMCSurface(surface))
170 {
171 resFreeFlags.SynchronousDestroy = 1;
172 }
173 return m_allocator->DestroySurface(surface, resFreeFlags);
174 }
175
176 VP_SURFACE* VpAllocator::AllocateVpSurface(MOS_ALLOC_GFXRES_PARAMS &param, bool zeroOnAllocate, VPHAL_CSPACE ColorSpace, uint32_t ChromaSiting)
177 {
178 VP_FUNC_CALL();
179 VP_SURFACE *surface = MOS_New(VP_SURFACE);
180 if (nullptr == surface)
181 {
182 return nullptr;
183 }
184 MOS_ZeroMemory(surface, sizeof(VP_SURFACE));
185
186 // Only used for Buffer surface
187 uint32_t bufferWidth = 0;
188 uint32_t bufferHeight = 0;
189
190
191 if (param.Format == Format_Buffer)
192 {
193 bufferWidth = param.dwWidth;
194 bufferHeight = param.dwHeight;
195 param.dwWidth = param.dwWidth * param.dwHeight;
196 param.dwHeight = 1;
197 }
198
199 surface->osSurface = AllocateSurface(param, zeroOnAllocate);
200
201 if (nullptr == surface->osSurface)
202 {
203 MOS_Delete(surface);
204 MT_ERR1(MT_VP_HAL_ALLOC_SURF, MT_CODE_LINE, __LINE__);
205 return nullptr;
206 }
207
208 surface->isResourceOwner = true;
209 surface->ColorSpace = ColorSpace;
210 surface->ChromaSiting = ChromaSiting;
211 surface->SampleType = SAMPLE_PROGRESSIVE; // Hardcode to SAMPLE_PROGRESSIVE for intermedia surface. Set to correct value for DI later.
212
213 surface->rcSrc.left = surface->rcSrc.top = 0;
214 surface->rcSrc.right = surface->osSurface->dwWidth;
215 surface->rcSrc.bottom = surface->osSurface->dwHeight;
216 surface->rcDst = surface->rcSrc;
217 surface->rcMaxSrc = surface->rcSrc;
218
219
220 if (param.Format == Format_Buffer)
221 {
222 surface->bufferWidth = bufferWidth;
223 surface->bufferHeight = bufferHeight;
224 }
225
226 return surface;
227 }
228
229 // Allocate vp surface from vphalSurf. Reuse the resource in vphalSurf.
230 VP_SURFACE *VpAllocator::AllocateVpSurface(VPHAL_SURFACE &vphalSurf)
231 {
232 VP_FUNC_CALL();
233 if (Mos_ResourceIsNull(&vphalSurf.OsResource))
234 {
235 if (vphalSurf.pPipeIntermediateSurface)
236 {
237 VP_SURFACE *surf = MOS_New(VP_SURFACE);
238 if (surf == nullptr)
239 {
240 return nullptr;
241 }
242 surf->osSurface = MOS_New(MOS_SURFACE);
243 if (MOS_FAILED(CopyVpSurface(*surf, *vphalSurf.pPipeIntermediateSurface)))
244 {
245 MOS_Delete(surf->osSurface);
246 MOS_Delete(surf);
247 return nullptr;
248 }
249 return surf;
250 }
251 return nullptr;
252 }
253 VP_SURFACE *surf = MOS_New(VP_SURFACE);
254
255 if (nullptr == surf)
256 {
257 return nullptr;
258 }
259
260 surf->osSurface = MOS_New(MOS_SURFACE);
261 if (nullptr == surf->osSurface)
262 {
263 MOS_Delete(surf);
264 return nullptr;
265 }
266
267 surf->isResourceOwner = false;
268 surf->Clean();
269
270 // Initialize the mos surface in vp surface structure.
271 MOS_SURFACE &osSurface = *surf->osSurface;
272 MOS_ZeroMemory(&osSurface, sizeof(MOS_SURFACE));
273
274 // Set input parameters dwArraySlice, dwMipSlice and S3dChannel if needed later.
275 osSurface.Format = vphalSurf.Format;
276 osSurface.OsResource = vphalSurf.OsResource;
277
278 if (MOS_FAILED(m_allocator->GetSurfaceInfo(&osSurface.OsResource, &osSurface)))
279 {
280 MOS_Delete(surf->osSurface);
281 MOS_Delete(surf);
282 return nullptr;
283 }
284
285 // Align the format with vphal surface. Some format need be remapped in vphal surface.
286 // For example, format_420O is mapped to Format_NV12 in VpHal.
287 // But it is mapped to several different Formats in CodecHal under different conditions.
288 osSurface.Format = vphalSurf.Format;
289
290 // Add offset info
291 osSurface.dwOffset = vphalSurf.dwOffset;
292 osSurface.YPlaneOffset.iSurfaceOffset = vphalSurf.YPlaneOffset.iSurfaceOffset;
293 osSurface.YPlaneOffset.iXOffset = vphalSurf.YPlaneOffset.iXOffset;
294 osSurface.YPlaneOffset.iYOffset = vphalSurf.YPlaneOffset.iYOffset;
295 if (IS_RGB32_FORMAT(osSurface.Format) ||
296 IS_RGB16_FORMAT(osSurface.Format) ||
297 IS_RGB64_FORMAT(osSurface.Format) ||
298 osSurface.Format == Format_RGB ||
299 osSurface.Format == Format_Y410)
300 {
301 osSurface.dwOffset = vphalSurf.dwOffset;
302 osSurface.YPlaneOffset.iSurfaceOffset = vphalSurf.YPlaneOffset.iSurfaceOffset;
303 osSurface.YPlaneOffset.iXOffset = vphalSurf.YPlaneOffset.iXOffset;
304 osSurface.YPlaneOffset.iYOffset = vphalSurf.YPlaneOffset.iYOffset;
305 }
306 else // YUV or PL3_RGB
307 {
308 // Get Y plane information (plane offset, X/Y offset)
309 osSurface.dwOffset = vphalSurf.dwOffset;
310 osSurface.YPlaneOffset.iSurfaceOffset = vphalSurf.YPlaneOffset.iSurfaceOffset;
311 osSurface.YPlaneOffset.iXOffset = vphalSurf.YPlaneOffset.iXOffset;
312 osSurface.YPlaneOffset.iYOffset = vphalSurf.YPlaneOffset.iYOffset;
313 osSurface.YPlaneOffset.iLockSurfaceOffset = vphalSurf.YPlaneOffset.iLockSurfaceOffset;
314
315 // Get U/UV plane information (plane offset, X/Y offset)
316 osSurface.UPlaneOffset.iSurfaceOffset = vphalSurf.UPlaneOffset.iSurfaceOffset;
317 osSurface.UPlaneOffset.iXOffset = vphalSurf.UPlaneOffset.iXOffset;
318 osSurface.UPlaneOffset.iYOffset = vphalSurf.UPlaneOffset.iYOffset;
319 osSurface.UPlaneOffset.iLockSurfaceOffset = vphalSurf.UPlaneOffset.iLockSurfaceOffset;
320
321 // Get V plane information (plane offset, X/Y offset)
322 osSurface.VPlaneOffset.iSurfaceOffset = vphalSurf.VPlaneOffset.iSurfaceOffset;
323 osSurface.VPlaneOffset.iXOffset = vphalSurf.VPlaneOffset.iXOffset;
324 osSurface.VPlaneOffset.iYOffset = vphalSurf.VPlaneOffset.iYOffset;
325 osSurface.VPlaneOffset.iLockSurfaceOffset = vphalSurf.VPlaneOffset.iLockSurfaceOffset;
326 }
327
328 // Initialize other parameters in vp surface according to vphal surface.
329 surf->ColorSpace = vphalSurf.ColorSpace;
330 surf->ExtendedGamut = vphalSurf.ExtendedGamut;
331 surf->Palette = vphalSurf.Palette;
332 surf->bQueryVariance = vphalSurf.bQueryVariance;
333 surf->FrameID = vphalSurf.FrameID;
334 surf->uFwdRefCount = vphalSurf.uFwdRefCount;
335 surf->uBwdRefCount = vphalSurf.uBwdRefCount;
336 surf->pFwdRef = vphalSurf.pFwdRef;
337 surf->pBwdRef = vphalSurf.pBwdRef;
338 surf->SurfType = vphalSurf.SurfType;
339 surf->SampleType = vphalSurf.SampleType;
340 surf->ChromaSiting = vphalSurf.ChromaSiting;
341 surf->rcSrc = vphalSurf.rcSrc;
342 surf->rcDst = vphalSurf.rcDst;
343 surf->rcMaxSrc = vphalSurf.rcMaxSrc;
344
345 if (MOS_FAILED(SetMmcFlags(osSurface)))
346 {
347 VP_PUBLIC_ASSERTMESSAGE("Set mmc flags failed during AllocateVpSurface!");
348 DestroyVpSurface(surf);
349 return nullptr;
350 }
351 return surf;
352 }
353
354 // Allocate vp surface from vpSurfSrc. Reuse the resource in vpSurfSrc.
355 VP_SURFACE *VpAllocator::AllocateVpSurface(VP_SURFACE &vpSurfSrc)
356 {
357 VP_FUNC_CALL();
358 if (nullptr == vpSurfSrc.osSurface || Mos_ResourceIsNull(&vpSurfSrc.osSurface->OsResource))
359 {
360 return nullptr;
361 }
362
363 VP_SURFACE *surf = MOS_New(VP_SURFACE);
364
365 if (nullptr == surf)
366 {
367 return nullptr;
368 }
369
370 MOS_SURFACE *osSurface = MOS_New(MOS_SURFACE);
371
372 if (nullptr == osSurface)
373 {
374 MOS_Delete(surf);
375 return nullptr;
376 }
377
378 *osSurface = *vpSurfSrc.osSurface;
379 *surf = vpSurfSrc;
380
381 surf->osSurface = osSurface;
382 surf->isResourceOwner = false;
383
384 return surf;
385 }
386
387 // Allocate vp surface from osSurf. Reuse the resource in osSurf.
388 VP_SURFACE *VpAllocator::AllocateVpSurface(MOS_SURFACE &osSurf,
389 VPHAL_CSPACE colorSpace, uint32_t chromaSiting, RECT rcSrc, RECT rcDst, VPHAL_SURFACE_TYPE SurfType, bool updatePlaneOffset)
390 {
391 VP_FUNC_CALL();
392 if (Mos_ResourceIsNull(&osSurf.OsResource))
393 {
394 return nullptr;
395 }
396
397 VP_SURFACE *surf = MOS_New(VP_SURFACE);
398
399 if (nullptr == surf)
400 {
401 return nullptr;
402 }
403
404 MOS_SURFACE *osSurface = MOS_New(MOS_SURFACE);
405
406 if (nullptr == osSurface)
407 {
408 MOS_Delete(surf);
409 return nullptr;
410 }
411
412 *osSurface = osSurf;
413 if (updatePlaneOffset)
414 {
415 UpdateSurfacePlaneOffset(*osSurface);
416 }
417
418 MOS_ZeroMemory(surf, sizeof(VP_SURFACE));
419 surf->osSurface = osSurface;
420 surf->isResourceOwner = false;
421 surf->ColorSpace = colorSpace; //!< Color Space
422 surf->ChromaSiting = chromaSiting; //!< ChromaSiting
423 surf->rcSrc = rcSrc; //!< Source rectangle
424 surf->rcDst = rcDst; //!< Destination rectangle
425 surf->rcMaxSrc = rcSrc; //!< Max source rectangle
426 surf->SurfType = SurfType; //!< Surface type (context). Not in use for internal surface
427 surf->SampleType = SAMPLE_PROGRESSIVE; //!< Interlaced/Progressive sample type.
428
429 return surf;
430 }
431
432 // Allocate empty vp surface.
433 VP_SURFACE *VpAllocator::AllocateVpSurface()
434 {
435 VP_FUNC_CALL();
436 // Allocate VpSurface without resource.
437 VP_SURFACE *surf = MOS_New(VP_SURFACE);
438
439 if (nullptr == surf)
440 {
441 return nullptr;
442 }
443
444 MOS_SURFACE *osSurface = MOS_New(MOS_SURFACE);
445
446 if (nullptr == osSurface)
447 {
448 MOS_Delete(surf);
449 return nullptr;
450 }
451
452 surf->osSurface = osSurface;
453 surf->isResourceOwner = false;
454 surf->Clean();
455
456 return surf;
457 }
458
459 VP_SURFACE *VpAllocator::AllocateVpSurface(MOS_RESOURCE &resource)
460 {
461 VP_FUNC_CALL();
462 if (Mos_ResourceIsNull(&resource))
463 {
464 return nullptr;
465 }
466
467 VP_SURFACE *surf = MOS_New(VP_SURFACE);
468
469 if (nullptr == surf)
470 {
471 return nullptr;
472 }
473
474 surf->osSurface = MOS_New(MOS_SURFACE);
475 if (nullptr == surf->osSurface)
476 {
477 MOS_Delete(surf);
478 return nullptr;
479 }
480
481 surf->isResourceOwner = false;
482 surf->Clean();
483
484 // Initialize the mos surface in vp surface structure.
485 MOS_SURFACE &osSurface = *surf->osSurface;
486 MOS_ZeroMemory(&osSurface, sizeof(MOS_SURFACE));
487
488 // Set input parameters dwArraySlice, dwMipSlice and S3dChannel if needed later.
489 osSurface.Format = Format_Invalid;
490 osSurface.OsResource = resource;
491
492 if (MOS_FAILED(m_allocator->GetSurfaceInfo(&osSurface.OsResource, &osSurface)))
493 {
494 MOS_Delete(surf->osSurface);
495 MOS_Delete(surf);
496 return nullptr;
497 }
498
499 if (MOS_FAILED(SetMmcFlags(osSurface)))
500 {
501 VP_PUBLIC_ASSERTMESSAGE("Set mmc flags failed during AllocateVpSurface!");
502 DestroyVpSurface(surf);
503 return nullptr;
504 }
505 return surf;
506 }
507
508 // Copy surface info from src to dst. dst shares the resource of src.
509 MOS_STATUS VpAllocator::CopyVpSurface(VP_SURFACE &dst, VP_SURFACE &src)
510 {
511 VP_FUNC_CALL();
512 if (nullptr == dst.osSurface || nullptr == src.osSurface || dst.isResourceOwner)
513 {
514 return MOS_STATUS_INVALID_PARAMETER;
515 }
516
517 MOS_SURFACE &osSurface = *dst.osSurface;
518 osSurface = *src.osSurface;
519 dst = src;
520
521 dst.osSurface = &osSurface;
522 dst.isResourceOwner = false;
523
524 return MOS_STATUS_SUCCESS;
525 }
526
527 MOS_STATUS VpAllocator::DestroyVpSurface(VP_SURFACE* &surface, bool deferredDestroyed, MOS_GFXRES_FREE_FLAGS flags)
528 {
529 VP_FUNC_CALL();
530 MOS_STATUS status = MOS_STATUS_SUCCESS;
531 if (nullptr == surface)
532 {
533 return status;
534 }
535
536 if (surface && nullptr == surface->osSurface)
537 {
538 // VP_SURFACE should always be allocated by interface in VpAllocator,
539 // which will ensure nullptr != surface->osSurface.
540 VP_PUBLIC_NORMALMESSAGE("Surfaces already been deleted, return status!");
541 return status;
542 }
543
544 if (deferredDestroyed)
545 {
546 m_recycler.push_back(surface);
547 surface = nullptr;
548 return MOS_STATUS_SUCCESS;
549 }
550
551 if (surface->isResourceOwner)
552 {
553 #if !EMUL
554 MT_LOG5(MT_VP_HAL_DESTROY_SURF, MT_NORMAL,
555 MT_VP_HAL_SURF_ALLOC_PARAM_PTR, (int64_t)surface,
556 MT_VP_HAL_SURF_ALLOC_PARAM_MOS_SURF_PTR, (int64_t)surface->osSurface,
557 MT_VP_HAL_SURF_ALLOC_PARAM_IS_RES_OWNER, surface->isResourceOwner,
558 MT_VP_HAL_SURF_ALLOC_PARAM_HANDLE, static_cast<int64_t>(surface->GetAllocationHandle(m_osInterface)),
559 MT_VP_HAL_SURF_ALLOC_PARAM_SIZE, static_cast<int64_t>(surface->osSurface->OsResource.pGmmResInfo ? surface->osSurface->OsResource.pGmmResInfo->GetSizeAllocation() : 0));
560 VP_PUBLIC_NORMALMESSAGE(
561 "VP_HAL_DESTROY_SURF. "
562 "VP_HAL_Surface: %p, "
563 "VP_HAL_OsSurface: %p, "
564 "VP_HAL_isResourceOwner: %d, "
565 "VP_HAL_Surface_Handle: 0x%llx, "
566 "VP_HAL_Surface_Size: 0x%llx",
567 surface,
568 surface->osSurface,
569 surface->isResourceOwner ? 1 : 0,
570 surface->GetAllocationHandle(m_osInterface),
571 surface->osSurface->OsResource.pGmmResInfo ? surface->osSurface->OsResource.pGmmResInfo->GetSizeAllocation() : 0);
572
573 int64_t currentSize = static_cast<int64_t>(surface->osSurface->OsResource.pGmmResInfo ? surface->osSurface->OsResource.pGmmResInfo->GetSizeAllocation() : 0);
574 m_totalSize = m_totalSize - currentSize;
575 #endif
576 status = DestroySurface(surface->osSurface, flags);
577 }
578 else
579 {
580 MOS_Delete(surface->osSurface);
581 }
582
583 MOS_Delete(surface);
584 return status;
585 }
586
587 void* VpAllocator::Lock(MOS_RESOURCE* resource, MOS_LOCK_PARAMS *lockFlag)
588 {
589 VP_FUNC_CALL();
590 if (!m_allocator)
591 return nullptr;
592
593 return m_allocator->Lock(resource, lockFlag);
594 }
595
596 void* VpAllocator::LockResourceForWrite(MOS_RESOURCE *resource)
597 {
598 VP_FUNC_CALL();
599 MOS_LOCK_PARAMS lockFlags;
600 MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS));
601 lockFlags.WriteOnly = 1;
602
603 if (!m_allocator)
604 return nullptr;
605
606 return m_allocator->Lock(resource, &lockFlags);
607 }
608
609 void* VpAllocator::LockResourceWithNoOverwrite(MOS_RESOURCE *resource)
610 {
611 VP_FUNC_CALL();
612 MOS_LOCK_PARAMS lockFlags;
613 MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS));
614 lockFlags.WriteOnly = 1;
615 lockFlags.NoOverWrite = 1;
616
617 if (!m_allocator)
618 return nullptr;
619
620 return m_allocator->Lock(resource, &lockFlags);
621 }
622
623 void* VpAllocator::LockResourceForRead(MOS_RESOURCE *resource)
624 {
625 VP_FUNC_CALL();
626 MOS_LOCK_PARAMS lockFlags;
627 MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS));
628 lockFlags.ReadOnly = 1;
629
630 if (!m_allocator)
631 return nullptr;
632
633 return m_allocator->Lock(resource, &lockFlags);
634 }
635
636 MOS_STATUS VpAllocator::UnLock(MOS_RESOURCE *resource)
637 {
638 VP_FUNC_CALL();
639 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
640
641 return m_allocator->UnLock(resource);
642 }
643
644 MOS_STATUS VpAllocator::SkipResourceSync(MOS_RESOURCE *resource)
645 {
646 VP_FUNC_CALL();
647 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
648
649 return m_allocator->SkipResourceSync(resource);
650 }
651
652 MOS_STATUS VpAllocator::GetSurfaceInfo(VPHAL_SURFACE *surface, VPHAL_GET_SURFACE_INFO &info)
653 {
654 VP_FUNC_CALL();
655 MOS_MEMCOMP_STATE mmcMode = MOS_MEMCOMP_DISABLED;
656 MOS_SURFACE resDetails;
657
658 VP_PUBLIC_CHK_NULL_RETURN(m_mmc);
659 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
660 VP_PUBLIC_CHK_NULL_RETURN(surface);
661
662 VP_PUBLIC_ASSERT(!Mos_ResourceIsNull(&surface->OsResource));
663
664 MOS_ZeroMemory(&resDetails, sizeof(MOS_SURFACE));
665 resDetails.dwArraySlice = info.ArraySlice;
666 resDetails.dwMipSlice = info.MipSlice;
667 resDetails.S3dChannel = info.S3dChannel;
668 resDetails.Format = surface->Format;
669
670 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator->GetSurfaceInfo(&surface->OsResource, &resDetails));
671
672 // Format_420O is mapped to Format_NV12 in VpHal here.
673 // But it is mapped to several different Formats in CodecHal under different conditions.
674 if (resDetails.Format == Format_420O)
675 {
676 resDetails.Format = Format_NV12;
677 }
678
679 // Get resource information
680 surface->dwWidth = resDetails.dwWidth;
681 surface->dwHeight = resDetails.dwHeight;
682 surface->dwPitch = resDetails.dwPitch;
683 surface->dwYPitch = resDetails.dwYPitch;
684 surface->dwUPitch = resDetails.dwUPitch;
685 surface->dwVPitch = resDetails.dwVPitch;
686 surface->dwSlicePitch = resDetails.dwSlicePitch;
687 surface->dwDepth = resDetails.dwDepth;
688 surface->TileType = resDetails.TileType;
689 surface->TileModeGMM = resDetails.TileModeGMM;
690 surface->bGMMTileEnabled = resDetails.bGMMTileEnabled;
691 surface->bOverlay = resDetails.bOverlay ? true : false;
692 surface->bFlipChain = resDetails.bFlipChain ? true : false;
693 surface->Format = resDetails.Format;
694 surface->bCompressible = resDetails.bCompressible ? true : false;
695 surface->bIsCompressed = resDetails.bIsCompressed ? true : false;
696 surface->CacheSetting = resDetails.CacheSetting;
697
698 if (IS_RGB32_FORMAT(surface->Format) ||
699 IS_RGB16_FORMAT(surface->Format) ||
700 IS_RGB64_FORMAT(surface->Format) ||
701 surface->Format == Format_RGB ||
702 surface->Format == Format_Y410)
703 {
704 surface->dwOffset = resDetails.RenderOffset.RGB.BaseOffset;
705 surface->YPlaneOffset.iSurfaceOffset = resDetails.RenderOffset.RGB.BaseOffset;
706 surface->YPlaneOffset.iXOffset = resDetails.RenderOffset.RGB.XOffset;
707 surface->YPlaneOffset.iYOffset = resDetails.RenderOffset.RGB.YOffset;
708 }
709 else // YUV or PL3_RGB
710 {
711 // Get Y plane information (plane offset, X/Y offset)
712 surface->dwOffset = resDetails.RenderOffset.YUV.Y.BaseOffset;
713 surface->YPlaneOffset.iSurfaceOffset = resDetails.RenderOffset.YUV.Y.BaseOffset;
714 surface->YPlaneOffset.iXOffset = resDetails.RenderOffset.YUV.Y.XOffset;
715 surface->YPlaneOffset.iYOffset = resDetails.RenderOffset.YUV.Y.YOffset;
716 surface->YPlaneOffset.iLockSurfaceOffset = resDetails.LockOffset.YUV.Y;
717
718 // Get U/UV plane information (plane offset, X/Y offset)
719 surface->UPlaneOffset.iSurfaceOffset = resDetails.RenderOffset.YUV.U.BaseOffset;
720 surface->UPlaneOffset.iXOffset = resDetails.RenderOffset.YUV.U.XOffset;
721 surface->UPlaneOffset.iYOffset = resDetails.RenderOffset.YUV.U.YOffset;
722 surface->UPlaneOffset.iLockSurfaceOffset = resDetails.LockOffset.YUV.U;
723
724 // Get V plane information (plane offset, X/Y offset)
725 surface->VPlaneOffset.iSurfaceOffset = resDetails.RenderOffset.YUV.V.BaseOffset;
726 surface->VPlaneOffset.iXOffset = resDetails.RenderOffset.YUV.V.XOffset;
727 surface->VPlaneOffset.iYOffset = resDetails.RenderOffset.YUV.V.YOffset;
728 surface->VPlaneOffset.iLockSurfaceOffset = resDetails.LockOffset.YUV.V;
729 }
730
731 VP_PUBLIC_CHK_STATUS_RETURN(m_mmc->GetResourceMmcState(&surface->OsResource, mmcMode));
732 if (mmcMode &&
733 (surface->TileType == MOS_TILE_Y ||
734 surface->TileType == MOS_TILE_YS))
735 {
736 surface->bCompressible = true;
737 surface->CompressionMode = (mmcMode == MOS_MEMCOMP_MC) ? MOS_MMC_MC :
738 (mmcMode == MOS_MEMCOMP_RC) ? MOS_MMC_RC : MOS_MMC_DISABLED;
739 }
740 else
741 {
742 surface->CompressionMode = MOS_MMC_DISABLED;
743 }
744
745 return MOS_STATUS_SUCCESS;
746 }
747
748 MOS_STATUS VpAllocator::GetSurfaceInfo(VP_SURFACE* surface, VPHAL_GET_SURFACE_INFO& info)
749 {
750 VP_FUNC_CALL();
751 MOS_MEMCOMP_STATE mmcMode = MOS_MEMCOMP_DISABLED;
752 MOS_SURFACE resDetails;
753
754 VP_PUBLIC_CHK_NULL_RETURN(m_mmc);
755 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
756 VP_PUBLIC_CHK_NULL_RETURN(surface);
757 VP_PUBLIC_CHK_NULL_RETURN(surface->osSurface);
758
759 if (Mos_ResourceIsNull(&surface->osSurface->OsResource))
760 {
761 VP_PUBLIC_NORMALMESSAGE("invalid resource handle");
762 return MOS_STATUS_INVALID_HANDLE;
763 }
764
765 MOS_ZeroMemory(&resDetails, sizeof(MOS_SURFACE));
766 resDetails.dwArraySlice = info.ArraySlice;
767 resDetails.dwMipSlice = info.MipSlice;
768 resDetails.S3dChannel = info.S3dChannel;
769 resDetails.Format = surface->osSurface->Format;
770
771 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator->GetSurfaceInfo(&surface->osSurface->OsResource, &resDetails));
772
773 // Format_420O is mapped to Format_NV12 in VpHal here.
774 // But it is mapped to several different Formats in CodecHal under different conditions.
775 if (resDetails.Format == Format_420O)
776 {
777 resDetails.Format = Format_NV12;
778 }
779
780 // Get resource information
781 surface->osSurface->dwWidth = resDetails.dwWidth;
782 surface->osSurface->dwHeight = resDetails.dwHeight;
783 surface->osSurface->dwPitch = resDetails.dwPitch;
784 surface->osSurface->dwSlicePitch = resDetails.dwSlicePitch;
785 surface->osSurface->dwDepth = resDetails.dwDepth;
786 surface->osSurface->TileType = resDetails.TileType;
787 surface->osSurface->TileModeGMM = resDetails.TileModeGMM;
788 surface->osSurface->bGMMTileEnabled = resDetails.bGMMTileEnabled;
789 surface->osSurface->bOverlay = resDetails.bOverlay ? true : false;
790 surface->osSurface->bFlipChain = resDetails.bFlipChain ? true : false;
791 surface->osSurface->Format = resDetails.Format;
792 surface->osSurface->bCompressible = resDetails.bCompressible ? true : false;
793 surface->osSurface->bIsCompressed = resDetails.bIsCompressed ? true : false;
794 surface->osSurface->CacheSetting = resDetails.CacheSetting;
795
796 return MOS_STATUS_SUCCESS;
797 }
798
799 MOS_STATUS VpAllocator::AllocParamsInitType(
800 MOS_ALLOC_GFXRES_PARAMS &allocParams,
801 PVPHAL_SURFACE surface,
802 MOS_GFXRES_TYPE defaultResType,
803 MOS_TILE_TYPE defaultTileType)
804 {
805 VP_FUNC_CALL();
806 VP_PUBLIC_CHK_NULL_RETURN(surface);
807
808 #if !EMUL && !LINUX && !ANDROID
809 // Need to reallocate surface according to expected tiletype instead of tiletype of the surface what we have
810 if ( surface != nullptr &&
811 surface->OsResource.pGmmResInfo != nullptr &&
812 surface->TileType == defaultTileType)
813 {
814 // Reallocate but use same tile type and resource type as current
815 allocParams.TileType = surface->OsResource.TileType;
816 allocParams.Type = surface->OsResource.ResType;
817 }
818 else
819 #endif
820 {
821 // First time allocation. Caller must specify default params
822 allocParams.Type = defaultResType;
823 allocParams.TileType = defaultTileType;
824 }
825
826 return MOS_STATUS_SUCCESS;
827 }
828
829 MOS_STATUS VpAllocator::AllocParamsInitType(
830 MOS_ALLOC_GFXRES_PARAMS &allocParams,
831 VP_SURFACE *surface,
832 MOS_GFXRES_TYPE defaultResType,
833 MOS_TILE_TYPE defaultTileType)
834 {
835 VP_FUNC_CALL();
836 // Need to reallocate surface according to expected tiletype instead of tiletype of the surface what we have
837 if (surface != nullptr &&
838 surface->osSurface != nullptr &&
839 !Mos_ResourceIsNull(&surface->osSurface->OsResource) &&
840 surface->osSurface->TileType == defaultTileType)
841 {
842 // Reallocate but use same tile type and resource type as current
843 allocParams.TileType = surface->osSurface->TileType;
844 allocParams.Type = surface->osSurface->Type;
845 }
846 else
847 {
848 // First time allocation. Caller must specify default params
849 allocParams.Type = defaultResType;
850 allocParams.TileType = defaultTileType;
851 }
852
853 return MOS_STATUS_SUCCESS;
854 }
855
856 MOS_STATUS VpAllocator::DestroyNpuBuffer(
857 VP_SURFACE*& surface)
858 {
859 VP_PUBLIC_CHK_NULL_RETURN(m_osInterface);
860 VP_PUBLIC_CHK_NULL_RETURN(m_osInterface->npuInterface);
861 VP_PUBLIC_CHK_NULL_RETURN(m_osInterface->npuInterface->pfnFreeHostMem);
862
863 MOS_GFXRES_FREE_FLAGS resFreeFlags = {0};
864 //if free the compressed surface, need set the sync dealloc flag as 1 for sync dealloc for aux table update
865 if (surface && IsSyncFreeNeededForMMCSurface(surface->osSurface))
866 {
867 resFreeFlags.SynchronousDestroy = 1;
868 VP_PUBLIC_NORMALMESSAGE("Set SynchronousDestroy flag for compressed resource");
869 }
870 void *npuHostMem = surface ? surface->zeNpuHostMem : nullptr;
871 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
872 eStatus = DestroyVpSurface(surface, false, resFreeFlags);
873 VP_PUBLIC_CHK_STATUS_RETURN(m_osInterface->npuInterface->pfnFreeHostMem(m_osInterface->npuInterface, npuHostMem));
874
875 return eStatus;
876 }
877
878 MOS_STATUS VpAllocator::ReAllocateNpuBuffer(
879 VP_SURFACE *&surface,
880 PCCHAR surfaceName,
881 uint32_t size,
882 bool &allocated)
883 {
884 VP_FUNC_CALL();
885
886 allocated = false;
887 VP_PUBLIC_CHK_NULL_RETURN(m_osInterface);
888 VP_PUBLIC_CHK_NULL_RETURN(m_osInterface->npuInterface);
889 VP_PUBLIC_CHK_NULL_RETURN(m_osInterface->npuInterface->pfnAllocateHostMem);
890 VP_PUBLIC_CHK_NULL_RETURN(m_osInterface->npuInterface->pfnFreeHostMem);
891
892 auto surfInfoCheck = [=](VP_SURFACE *&surface) -> bool {
893 return (surface->bufferWidth == size) && (Format_Buffer == surface->osSurface->Format);
894 };
895
896 if (surface &&
897 surface->osSurface &&
898 !Mos_ResourceIsNull(&surface->osSurface->OsResource) &&
899 surface->zeNpuHostMem != nullptr &&
900 surfInfoCheck(surface))
901 {
902 return MOS_STATUS_SUCCESS;
903 }
904
905 if (surface && nullptr == surface->osSurface)
906 {
907 // VP_SURFACE should always be allocated by interface in VpAllocator,
908 // which will ensure nullptr != surface->osSurface.
909 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
910 }
911
912 VP_PUBLIC_CHK_STATUS_RETURN(DestroyNpuBuffer(surface));
913
914 surface = AllocateVpSurface();
915 VP_PUBLIC_CHK_NULL_RETURN(surface);
916 if (surface->osSurface == nullptr)
917 {
918 VP_PUBLIC_CHK_STATUS_RETURN(DestroyVpSurface(surface));
919 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_NO_SPACE);
920 }
921
922 void *npuHostMem = nullptr;
923 VP_PUBLIC_CHK_STATUS_RETURN(m_osInterface->npuInterface->pfnAllocateHostMem(m_osInterface->npuInterface, size, npuHostMem));
924 VP_PUBLIC_CHK_NULL_RETURN(npuHostMem);
925
926 GMM_RESOURCE_FORMAT gmmFormat = {};
927 #if !EMUL
928 gmmFormat = GMM_FORMAT_GENERIC_8BIT;
929 #endif
930 if (MOS_STATUS_SUCCESS != AllocateCPUResource(&surface->osSurface->OsResource, (size_t)npuHostMem, size, 1, size, size, 0, gmmFormat))
931 {
932 VP_PUBLIC_CHK_STATUS_RETURN(m_osInterface->npuInterface->pfnFreeHostMem(m_osInterface->npuInterface, npuHostMem));
933 VP_PUBLIC_CHK_STATUS_RETURN(DestroyVpSurface(surface));
934 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_NO_SPACE);
935 }
936 surface->zeNpuHostMem = npuHostMem;
937 surface->isResourceOwner = true;
938 surface->osSurface->dwWidth = size;
939 surface->osSurface->dwHeight = 1;
940 surface->osSurface->dwSize = size;
941 surface->osSurface->TileType = MOS_TILE_LINEAR;
942 surface->osSurface->Format = Format_Buffer;
943
944 allocated = true;
945 return MOS_STATUS_SUCCESS;
946 }
947
948 MOS_STATUS VpAllocator::ReAllocateSurface(
949 VP_SURFACE *&surface,
950 PCCHAR surfaceName,
951 MOS_FORMAT format,
952 MOS_GFXRES_TYPE defaultResType,
953 MOS_TILE_TYPE defaultTileType,
954 uint32_t width,
955 uint32_t height,
956 bool compressible,
957 MOS_RESOURCE_MMC_MODE compressionMode,
958 bool &allocated,
959 bool zeroOnAllocate,
960 bool deferredDestroyed,
961 MOS_HW_RESOURCE_DEF resUsageType,
962 MOS_TILE_MODE_GMM tileModeByForce,
963 Mos_MemPool memType,
964 bool isNotLockable,
965 void * systemMemory,
966 uint32_t depth)
967 {
968 VP_FUNC_CALL();
969 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
970 MOS_ALLOC_GFXRES_PARAMS allocParams = {};
971 MOS_GFXRES_FREE_FLAGS resFreeFlags = {0};
972
973 allocated = false;
974
975 //---------------------------------
976 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
977
978 if (!m_mmc->IsMmcEnabled() ||
979 !m_mmc->IsCompressibelSurfaceSupported())
980 {
981 compressible = 0;
982 compressionMode = MOS_MMC_DISABLED;
983 }
984 //---------------------------------
985
986 auto surfInfoCheck = [=](VP_SURFACE *&surface) -> bool
987 {
988 return (surface->osSurface->Format == format) &&
989 ((surface->osSurface->bCompressible != 0) == compressible) &&
990 (surface->osSurface->CompressionMode == compressionMode) &&
991 (surface->osSurface->TileType == defaultTileType ||
992 MOS_TILE_Y == defaultTileType &&
993 IS_Y_MAJOR_TILE_FORMAT(surface->osSurface->TileType)) &&
994 ((Format_Buffer == format &&
995 surface->bufferWidth == width &&
996 surface->bufferHeight == height) ||
997 (Format_Buffer != format &&
998 surface->osSurface->dwWidth == width &&
999 surface->osSurface->dwHeight == height) );
1000 };
1001
1002 // compressible should be compared with bCompressible since it is inited by bCompressible in previous call
1003 // TileType of surface should be compared since we need to reallocate surface if TileType changes
1004 if (surface &&
1005 surface->osSurface &&
1006 !Mos_ResourceIsNull(&surface->osSurface->OsResource) &&
1007 surfInfoCheck(surface) )
1008 {
1009 return eStatus;
1010 }
1011
1012 // reuse the allocated buffer if the allocated size was larger than request size when OptimizeCpuTiming is enabled
1013 if (m_osInterface->bOptimizeCpuTiming &&
1014 surface &&
1015 surface->osSurface &&
1016 (!Mos_ResourceIsNull(&surface->osSurface->OsResource)) &&
1017 (Format_Buffer == format) &&
1018 (surface->bufferWidth * surface->bufferHeight >= width * height))
1019 {
1020 return eStatus;
1021 }
1022
1023 if (surface && nullptr == surface->osSurface)
1024 {
1025 // VP_SURFACE should always be allocated by interface in VpAllocator,
1026 // which will ensure nullptr != surface->osSurface.
1027 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
1028 }
1029
1030 //if free the compressed surface, need set the sync dealloc flag as 1 for sync dealloc for aux table update
1031 if (surface && IsSyncFreeNeededForMMCSurface(surface->osSurface))
1032 {
1033 resFreeFlags.SynchronousDestroy = 1;
1034 VP_PUBLIC_NORMALMESSAGE("Set SynchronousDestroy flag for compressed resource %s", surfaceName);
1035 }
1036 VP_PUBLIC_CHK_STATUS_RETURN(DestroyVpSurface(surface, deferredDestroyed, resFreeFlags));
1037
1038 AllocParamsInitType(allocParams, surface, defaultResType, defaultTileType);
1039
1040 allocParams.dwWidth = width;
1041 allocParams.dwHeight = height;
1042 allocParams.dwDepth = depth;
1043 allocParams.Format = format;
1044 allocParams.bIsCompressible = compressible;
1045 allocParams.CompressionMode = compressionMode;
1046 allocParams.pBufName = surfaceName;
1047 allocParams.dwArraySize = 1;
1048 allocParams.ResUsageType = resUsageType;
1049 allocParams.m_tileModeByForce = tileModeByForce;
1050 allocParams.dwMemType = memType;
1051 allocParams.Flags.bNotLockable = isNotLockable;
1052 allocParams.pSystemMemory = systemMemory;
1053
1054 #if (_DEBUG || _RELEASE_INTERNAL)
1055 // Set SubAllocation flag for Volume resources (3DLUT surfaces)
1056 if (allocParams.Type == MOS_GFXRES_VOLUME)
1057 {
1058 allocParams.Flags.bSubAllocation = true;
1059 }
1060 #endif
1061
1062 surface = AllocateVpSurface(allocParams, zeroOnAllocate);
1063 VP_PUBLIC_CHK_NULL_RETURN(surface);
1064 VP_PUBLIC_CHK_NULL_RETURN(surface->osSurface);
1065 if (Mos_ResourceIsNull(&surface->osSurface->OsResource))
1066 {
1067 VP_PUBLIC_CHK_NULL_RETURN(nullptr);
1068 }
1069
1070 if (!surfInfoCheck(surface))
1071 {
1072 VP_PUBLIC_ASSERTMESSAGE("Allocated surface is not matched with allocating parameter.");
1073 VP_PUBLIC_ASSERTMESSAGE("Allocated surface : format %d, compressible %d, compressionMode %d, tileType %d, bufferWidth %d, bufferHeight %d, width %d, height %d",
1074 surface->osSurface->Format,
1075 surface->osSurface->bCompressible,
1076 surface->osSurface->CompressionMode,
1077 surface->osSurface->TileType,
1078 surface->bufferWidth,
1079 surface->bufferHeight,
1080 surface->osSurface->dwWidth,
1081 surface->osSurface->dwHeight);
1082 VP_PUBLIC_ASSERTMESSAGE("Parameter to allocate : format %d, compressible %d, compressionMode %d, tileType %d, width %d, height %d",
1083 format,
1084 compressible,
1085 compressionMode,
1086 defaultTileType,
1087 width,
1088 height);
1089 }
1090
1091 MT_LOG7(MT_VP_HAL_REALLOC_SURF, MT_NORMAL, MT_VP_HAL_INTER_SURF_TYPE, surfaceName ? *((int64_t*)surfaceName) : 0,
1092 MT_SURF_WIDTH, width, MT_SURF_HEIGHT, height, MT_SURF_MOS_FORMAT, format, MT_SURF_TILE_MODE, surface->osSurface->TileModeGMM,
1093 MT_SURF_COMP_ABLE, surface->osSurface->bCompressible, MT_SURF_COMP_MODE, surface->osSurface->CompressionMode);
1094
1095 #if !EMUL
1096 MT_LOG6(MT_VP_HAL_REALLOC_SURF, MT_NORMAL,
1097 MT_VP_HAL_SURF_ALLOC_PARAM_PTR, (int64_t)surface,
1098 MT_VP_HAL_SURF_ALLOC_PARAM_MOS_SURF_PTR, (int64_t)surface->osSurface,
1099 MT_VP_HAL_SURF_ALLOC_PARAM_IS_RES_OWNER, surface->isResourceOwner,
1100 MT_VP_HAL_SURF_ALLOC_PARAM_HANDLE, static_cast<int64_t>(surface->GetAllocationHandle(m_osInterface)),
1101 MT_VP_HAL_SURF_ALLOC_PARAM_SIZE, static_cast<int64_t>(surface->osSurface->OsResource.pGmmResInfo ? surface->osSurface->OsResource.pGmmResInfo->GetSizeAllocation() : 0),
1102 MT_VP_HAL_SURF_ALLOC_PARAM_NAME, surfaceName ? *((int64_t *)surfaceName) : 0);
1103 VP_PUBLIC_NORMALMESSAGE(
1104 "VP_HAL_REALLOC_SURF. "
1105 "VP_HAL_Surface: %p, "
1106 "VP_HAL_OsSurface: %p, "
1107 "VP_HAL_isResourceOwner: %d, "
1108 "VP_HAL_Surface_Handle: 0x%llx, "
1109 "VP_HAL_Surface_Size: 0x%llx, "
1110 "VP_HAL_Surface_Name: %s",
1111 surface,
1112 surface->osSurface,
1113 surface->isResourceOwner ? 1 : 0,
1114 surface->GetAllocationHandle(m_osInterface),
1115 surface->osSurface->OsResource.pGmmResInfo ? surface->osSurface->OsResource.pGmmResInfo->GetSizeAllocation() : 0,
1116 surfaceName ? surfaceName : "");
1117 int64_t currentSize = static_cast<int64_t>(surface->osSurface->OsResource.pGmmResInfo ? surface->osSurface->OsResource.pGmmResInfo->GetSizeAllocation() : 0);
1118 m_totalSize = m_totalSize + currentSize;
1119 m_peakSize = m_peakSize > m_totalSize ? m_peakSize : m_totalSize;
1120 #endif
1121 allocated = true;
1122 return MOS_STATUS_SUCCESS;
1123 }
1124
1125 // for debug purpose
1126 #if (_DEBUG || _RELEASE_INTERNAL)
1127 MOS_STATUS VpAllocator::ReAllocateSurface(
1128 PVPHAL_SURFACE surface,
1129 PCCHAR surfaceName,
1130 MOS_FORMAT format,
1131 MOS_GFXRES_TYPE defaultResType,
1132 MOS_TILE_TYPE defaultTileType,
1133 uint32_t width,
1134 uint32_t height,
1135 bool compressible,
1136 MOS_RESOURCE_MMC_MODE compressionMode,
1137 bool * allocated,
1138 MOS_HW_RESOURCE_DEF resUsageType,
1139 MOS_TILE_MODE_GMM tileModeByForce)
1140 {
1141 VP_FUNC_CALL();
1142 MOS_STATUS eStatus;
1143 VPHAL_GET_SURFACE_INFO info;
1144 MOS_ALLOC_GFXRES_PARAMS allocParams;
1145 MOS_GFXRES_FREE_FLAGS resFreeFlags = {0};
1146
1147 //---------------------------------
1148 VP_PUBLIC_ASSERT(&surface->OsResource);
1149 //---------------------------------
1150
1151 eStatus = MOS_STATUS_SUCCESS;
1152 *allocated = false;
1153
1154 // compressible should be compared with compressible since it is inited by compressible in previous call
1155 // TileType of surface should be compared since we need to reallocate surface if TileType changes
1156 if (!Mos_ResourceIsNull(&surface->OsResource) &&
1157 (surface->dwWidth == width) &&
1158 (surface->dwHeight == height) &&
1159 (surface->Format == format) &&
1160 (surface->bCompressible == compressible) &&
1161 (surface->CompressionMode == compressionMode) &&
1162 (surface->TileType == defaultTileType))
1163 {
1164 return eStatus;
1165 }
1166
1167 // reuse the allocated buffer if the allocated size was larger than request size when OptimizeCpuTiming is enabled
1168 if (m_osInterface->bOptimizeCpuTiming &&
1169 (!Mos_ResourceIsNull(&surface->OsResource)) &&
1170 (Format_Buffer == format) &&
1171 (surface->dwWidth * surface->dwHeight >= width * height))
1172 {
1173 return eStatus;
1174 }
1175
1176 MOS_ZeroMemory(&allocParams, sizeof(MOS_ALLOC_GFXRES_PARAMS));
1177
1178 VpHal_AllocParamsInitType(&allocParams, surface, defaultResType, defaultTileType);
1179
1180 allocParams.dwWidth = width;
1181 allocParams.dwHeight = height;
1182 allocParams.Format = format;
1183 allocParams.bIsCompressible = compressible;
1184 allocParams.CompressionMode = compressionMode;
1185 allocParams.pBufName = surfaceName;
1186 allocParams.dwArraySize = 1;
1187 allocParams.ResUsageType = resUsageType;
1188 allocParams.m_tileModeByForce = tileModeByForce;
1189
1190 VP_PUBLIC_CHK_STATUS_RETURN(DestroyResource(&surface->OsResource));
1191
1192 // Allocate surface
1193 VP_PUBLIC_CHK_STATUS_RETURN(AllocateResource(&surface->OsResource, allocParams));
1194
1195 // Get surface information
1196 MOS_ZeroMemory(&info, sizeof(VPHAL_GET_SURFACE_INFO));
1197
1198 // Pre-set to get surface info
1199 surface->Format = format;
1200
1201 VP_PUBLIC_CHK_STATUS_RETURN(GetSurfaceInfo(surface, info));
1202
1203 *allocated = true;
1204
1205 VP_PUBLIC_ASSERT(eStatus == MOS_STATUS_SUCCESS);
1206 return eStatus;
1207 }
1208 #endif
1209
1210 MOS_STATUS VpAllocator::ReAllocateVpSurfaceWithSameConfigOfVphalSurface(
1211 VP_SURFACE *&surface,
1212 const PVPHAL_SURFACE &vphalSurface,
1213 PCCHAR surfaceName,
1214 bool &allocated)
1215 {
1216 VP_PUBLIC_CHK_NULL_RETURN(vphalSurface);
1217
1218 MOS_GFXRES_TYPE defaultResType = MOS_GFXRES_INVALID;
1219 MOS_TILE_TYPE defaultTileType = MOS_TILE_LINEAR;
1220 MOS_HW_RESOURCE_DEF resUsageType = MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER;
1221 MOS_TILE_MODE_GMM tileModeByForce = MOS_TILE_UNSET_GMM;
1222 if (Mos_ResourceIsNull(&vphalSurface->OsResource))
1223 {
1224 bool isBuffer = (vphalSurface->Format == Format_Buffer || vphalSurface->Format == Format_RAW);
1225 defaultResType = isBuffer ? MOS_GFXRES_BUFFER : MOS_GFXRES_2D;
1226 defaultTileType = isBuffer ? MOS_TILE_LINEAR : MOS_TILE_Y;
1227 }
1228 else
1229 {
1230 defaultResType = m_osInterface->pfnGetResType(&vphalSurface->OsResource);
1231 defaultTileType = vphalSurface->OsResource.TileType;
1232 resUsageType = MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER;
1233 tileModeByForce = MOS_TILE_UNSET_GMM;
1234 }
1235 VP_PUBLIC_CHK_STATUS_RETURN(ReAllocateSurface(
1236 surface,
1237 surfaceName,
1238 vphalSurface->Format,
1239 defaultResType,
1240 defaultTileType,
1241 vphalSurface->dwWidth,
1242 vphalSurface->dwHeight,
1243 vphalSurface->bCompressible,
1244 vphalSurface->CompressionMode,
1245 allocated,
1246 false,
1247 false,
1248 resUsageType,
1249 tileModeByForce));
1250
1251 // Initialize other parameters in vp surface according to vphal surface.
1252 surface->ColorSpace = vphalSurface->ColorSpace;
1253 surface->ExtendedGamut = vphalSurface->ExtendedGamut;
1254 surface->Palette = vphalSurface->Palette;
1255 surface->bQueryVariance = vphalSurface->bQueryVariance;
1256 surface->FrameID = vphalSurface->FrameID;
1257 surface->uFwdRefCount = vphalSurface->uFwdRefCount;
1258 surface->uBwdRefCount = vphalSurface->uBwdRefCount;
1259 surface->pFwdRef = vphalSurface->pFwdRef;
1260 surface->pBwdRef = vphalSurface->pBwdRef;
1261 surface->SurfType = vphalSurface->SurfType;
1262 surface->SampleType = vphalSurface->SampleType;
1263 surface->ChromaSiting = vphalSurface->ChromaSiting;
1264 surface->rcSrc = vphalSurface->rcSrc;
1265 surface->rcDst = vphalSurface->rcDst;
1266 surface->rcMaxSrc = vphalSurface->rcMaxSrc;
1267
1268 return MOS_STATUS_SUCCESS;
1269 }
1270
1271 MOS_STATUS VpAllocator::OsFillResource(
1272 PMOS_RESOURCE osResource,
1273 uint32_t size,
1274 uint8_t value)
1275 {
1276 VP_FUNC_CALL();
1277 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
1278 return m_allocator->OsFillResource(osResource, size, value);
1279 }
1280
1281 MOS_STATUS VpAllocator::ReadSurface (
1282 PVPHAL_SURFACE surface,
1283 uint32_t bpp,
1284 uint8_t *dst)
1285 {
1286 VP_FUNC_CALL();
1287 uint8_t *src = nullptr;
1288 uint8_t *tempSrc = nullptr;
1289 uint8_t *tempDst = nullptr;
1290 uint32_t size = 0;
1291 uint32_t widthInBytes = 0;
1292 uint32_t y = 0;
1293 uint32_t z = 0;
1294
1295 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
1296
1297 //----------------------------------------------
1298 VP_PUBLIC_ASSERT(surface);
1299 VP_PUBLIC_ASSERT(surface->dwWidth > 0);
1300 VP_PUBLIC_ASSERT(surface->dwHeight > 0);
1301 VP_PUBLIC_ASSERT(surface->dwDepth > 0);
1302 VP_PUBLIC_ASSERT(surface->dwPitch >= surface->dwWidth);
1303 VP_PUBLIC_ASSERT(bpp > 0);
1304 VP_PUBLIC_ASSERT(dst);
1305 VP_PUBLIC_ASSERT(!Mos_ResourceIsNull(&surface->OsResource));
1306 //----------------------------------------------
1307
1308 src = (uint8_t*)LockResourceForRead(&surface->OsResource);
1309 VP_PUBLIC_CHK_NULL_RETURN(src);
1310
1311 // Calculate Size in Bytes
1312 size = surface->dwWidth * surface->dwHeight * surface->dwDepth * bpp/8;
1313 widthInBytes = surface->dwWidth * bpp / 8;
1314 if (surface->dwPitch == widthInBytes)
1315 {
1316 MOS_SecureMemcpy(dst, size, src, size);
1317 }
1318 else
1319 {
1320 tempSrc = src;
1321 tempDst = dst;
1322
1323 for (z = 0; z < surface->dwDepth; z++)
1324 {
1325 for (y = 0; y < surface->dwHeight; y++)
1326 {
1327 MOS_SecureMemcpy(tempDst, widthInBytes, tempSrc, widthInBytes);
1328 tempSrc += surface->dwPitch;
1329 tempDst += widthInBytes;
1330 }
1331 }
1332 }
1333
1334 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator->UnLock(&surface->OsResource));
1335
1336 return MOS_STATUS_SUCCESS;
1337 }
1338
1339 MOS_STATUS VpAllocator::WriteSurface (
1340 PVPHAL_SURFACE surface,
1341 uint32_t bpp,
1342 const uint8_t *src)
1343 {
1344 VP_FUNC_CALL();
1345 uint8_t *dst = nullptr;
1346 uint8_t *tempSrc = nullptr;
1347 uint8_t *tempDst = nullptr;
1348 uint32_t widthInBytes = 0;
1349 uint32_t size = 0;
1350 uint32_t y = 0;
1351 uint32_t z = 0;
1352
1353 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
1354
1355 //----------------------------------------------
1356 VP_PUBLIC_ASSERT(surface);
1357 VP_PUBLIC_ASSERT(surface->dwWidth > 0);
1358 VP_PUBLIC_ASSERT(surface->dwHeight > 0);
1359 VP_PUBLIC_ASSERT(surface->dwDepth > 0);
1360 VP_PUBLIC_ASSERT(surface->dwPitch >= surface->dwWidth);
1361 VP_PUBLIC_ASSERT(bpp > 0);
1362 VP_PUBLIC_ASSERT(src);
1363 VP_PUBLIC_ASSERT(!Mos_ResourceIsNull(&surface->OsResource));
1364 //----------------------------------------------
1365
1366 dst = (uint8_t*)LockResourceForWrite(&surface->OsResource);
1367 VP_PUBLIC_CHK_NULL_RETURN(dst);
1368
1369 // Calculate Size in Bytes
1370 size = surface->dwWidth * surface->dwHeight * surface->dwDepth * bpp/8;
1371 widthInBytes = surface->dwWidth * bpp/8;
1372
1373 if (surface->dwPitch == widthInBytes)
1374 {
1375 MOS_SecureMemcpy(dst, size, src, size);
1376 }
1377 else
1378 {
1379 tempSrc = (uint8_t*)src;
1380 tempDst = dst;
1381
1382 for (z = 0; z < surface->dwDepth; z++)
1383 {
1384 for (y = 0; y < surface->dwHeight; y++)
1385 {
1386 MOS_SecureMemcpy(tempDst, widthInBytes, tempSrc, widthInBytes);
1387 tempSrc += widthInBytes;
1388 tempDst += surface->dwPitch;
1389 }
1390 }
1391 }
1392
1393 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator->UnLock(&surface->OsResource));
1394
1395 return MOS_STATUS_SUCCESS;
1396 }
1397
1398 MOS_STATUS VpAllocator::WriteSurface(VP_SURFACE* vpsurface, uint32_t bpp, const uint8_t* src)
1399 {
1400 VP_FUNC_CALL();
1401 uint8_t* dst = nullptr;
1402 uint8_t* tempSrc = nullptr;
1403 uint8_t* tempDst = nullptr;
1404 uint32_t widthInBytes = 0;
1405 uint32_t size = 0;
1406 uint32_t y = 0;
1407 uint32_t z = 0;
1408 MOS_SURFACE* surface;
1409
1410 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
1411
1412 //----------------------------------------------
1413 VP_PUBLIC_ASSERT(vpsurface);
1414
1415 surface = vpsurface->osSurface;
1416 VP_PUBLIC_ASSERT(surface);
1417
1418 VP_PUBLIC_ASSERT(surface->dwWidth > 0);
1419 VP_PUBLIC_ASSERT(surface->dwHeight > 0);
1420 VP_PUBLIC_ASSERT(surface->dwDepth > 0);
1421 VP_PUBLIC_ASSERT(surface->dwPitch >= surface->dwWidth);
1422 VP_PUBLIC_ASSERT(bpp > 0);
1423 VP_PUBLIC_ASSERT(src);
1424 VP_PUBLIC_ASSERT(!Mos_ResourceIsNull(&surface->OsResource));
1425 //----------------------------------------------
1426
1427 dst = (uint8_t*)LockResourceForWrite(&surface->OsResource);
1428 VP_PUBLIC_CHK_NULL_RETURN(dst);
1429
1430 // Calculate Size in Bytes
1431 size = surface->dwWidth * surface->dwHeight * surface->dwDepth * bpp / 8;
1432 widthInBytes = surface->dwWidth * bpp / 8;
1433
1434 if (surface->dwPitch == widthInBytes)
1435 {
1436 MOS_SecureMemcpy(dst, size, src, size);
1437 }
1438 else
1439 {
1440 tempSrc = (uint8_t*)src;
1441 tempDst = dst;
1442
1443 for (z = 0; z < surface->dwDepth; z++)
1444 {
1445 for (y = 0; y < surface->dwHeight; y++)
1446 {
1447 MOS_SecureMemcpy(tempDst, widthInBytes, tempSrc, widthInBytes);
1448 tempSrc += widthInBytes;
1449 tempDst += surface->dwPitch;
1450 }
1451 }
1452 }
1453
1454 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator->UnLock(&surface->OsResource));
1455
1456 return MOS_STATUS_SUCCESS;
1457 }
1458
1459 MOS_STATUS VpAllocator::Write1DSurface(VP_SURFACE* vpsurface, const uint8_t* src, uint32_t srcSize)
1460 {
1461 VP_FUNC_CALL();
1462 VP_PUBLIC_CHK_NULL_RETURN(vpsurface);
1463 VP_PUBLIC_CHK_NULL_RETURN(vpsurface->osSurface);
1464 VP_PUBLIC_CHK_NULL_RETURN(src);
1465 VP_PUBLIC_CHK_VALUE_RETURN(srcSize > 0, true);
1466 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
1467 VP_PUBLIC_CHK_VALUE_RETURN(vpsurface->osSurface->dwSize > 0, true);
1468
1469 #if MOS_MEDIASOLO_SUPPORTED
1470 if (!m_osInterface->bSoloInUse)
1471 #endif
1472 {
1473 VP_PUBLIC_CHK_VALUE_RETURN(vpsurface->osSurface->Type, MOS_GFXRES_BUFFER);
1474 }
1475
1476 VP_PUBLIC_ASSERT(!Mos_ResourceIsNull(&vpsurface->osSurface->OsResource));
1477
1478 MOS_SURFACE* surface = vpsurface->osSurface;
1479 uint8_t* dst = (uint8_t*)LockResourceForWrite(&surface->OsResource);
1480
1481 VP_PUBLIC_CHK_NULL_RETURN(dst);
1482
1483 MOS_STATUS status = MOS_SecureMemcpy(dst, surface->dwSize, src, srcSize);
1484
1485 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator->UnLock(&surface->OsResource));
1486
1487 return status;
1488 }
1489
1490 MOS_STATUS VpAllocator::SyncOnResource(
1491 PMOS_RESOURCE osResource,
1492 bool bWriteOperation)
1493 {
1494 VP_FUNC_CALL();
1495 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
1496
1497 return (m_allocator->SyncOnResource(osResource, bWriteOperation));
1498 }
1499
1500 MOS_STATUS VpAllocator::UpdateResourceUsageType(
1501 PMOS_RESOURCE osResource,
1502 MOS_HW_RESOURCE_DEF resUsageType)
1503 {
1504 VP_FUNC_CALL();
1505 VP_PUBLIC_CHK_NULL_RETURN(m_allocator);
1506
1507 return (m_allocator->UpdateResourceUsageType(osResource, resUsageType));
1508 }
1509
1510
1511 bool VpAllocator::IsSyncFreeNeededForMMCSurface(PMOS_SURFACE pOsSurface)
1512 {
1513 VP_FUNC_CALL();
1514 if (nullptr == pOsSurface)
1515 {
1516 return false;
1517 }
1518
1519 return (m_allocator->isSyncFreeNeededForMMCSurface(pOsSurface));
1520 }
1521
1522 void VpAllocator::CleanRecycler()
1523 {
1524 VP_FUNC_CALL();
1525 while (!m_recycler.empty())
1526 {
1527 MOS_GFXRES_FREE_FLAGS resFreeFlags = {};
1528 VP_SURFACE *surf = m_recycler.back();
1529 m_recycler.pop_back();
1530 //if free the compressed surface, need set the sync dealloc flag as 1 for sync dealloc for aux table update
1531 if (surf && IsSyncFreeNeededForMMCSurface(surf->osSurface))
1532 {
1533 resFreeFlags.SynchronousDestroy = 1;
1534 VP_PUBLIC_NORMALMESSAGE("Set SynchronousDestroy flag for compressed resource.");
1535 }
1536 DestroyVpSurface(surf, false, resFreeFlags);
1537 }
1538 }
1539
1540 MOS_STATUS VpAllocator::AllocateCPUResource(PMOS_RESOURCE osResource, size_t linearAddress, uint32_t dataSize, uint32_t height, uint64_t width, uint64_t planePitch, uint32_t CpTag, GMM_RESOURCE_FORMAT Format)
1541 {
1542 VP_FUNC_CALL();
1543 MOS_STATUS eStatusKey = MOS_STATUS_SUCCESS;
1544 //Create MOS_GFXRES_BUFFER type resource
1545
1546 size_t linearAddressAligned = 0;
1547 uint32_t addedShiftLeftOffset = 0;
1548 MOS_ALLOC_GFXRES_PARAMS sParams;
1549
1550 if ((linearAddress & 0xf) || (linearAddress == 0))
1551 {
1552 VP_PUBLIC_NORMALMESSAGE("Error: Start address of system memory is not 16-byte aligned!");
1553 return MOS_STATUS_UNKNOWN;
1554 }
1555 if (sizeof(void *) == 8) //64-bit
1556 {
1557 linearAddressAligned = linearAddress & ADDRESS_PAGE_ALIGNMENT_MASK_X64;
1558 }
1559 else //32-bit
1560 {
1561 linearAddressAligned = linearAddress & ADDRESS_PAGE_ALIGNMENT_MASK_X86;
1562 }
1563 //Calculate Left Shift offset
1564 addedShiftLeftOffset = (uint32_t)(linearAddress - linearAddressAligned);
1565 VP_PUBLIC_NORMALMESSAGE("System memory address: 0x%x, Aligned address: 0x%x, offset: %u", linearAddress, linearAddressAligned, addedShiftLeftOffset);
1566
1567 MOS_ZeroMemory(&sParams, sizeof(MOS_ALLOC_GFXRES_PARAMS));
1568 sParams.Type = MOS_GFXRES_BUFFER;
1569 sParams.dwBytes = dataSize + addedShiftLeftOffset;
1570 sParams.pSystemMemory = (void *)linearAddressAligned;
1571 sParams.TileType = MOS_TILE_LINEAR;
1572 sParams.Format = Format_Buffer;
1573 sParams.pBufName = "cpuResourceBuffer_1D";
1574 sParams.bBypassMODImpl = 1;
1575 sParams.bIsPersistent = 1;
1576
1577 eStatusKey = m_osInterface->pfnAllocateResource(m_osInterface, &sParams, osResource);
1578 if (eStatusKey != MOS_STATUS_SUCCESS)
1579 {
1580 VP_PUBLIC_NORMALMESSAGE("Error: m_osInterface.pfnAllocateResource failed!");
1581 return eStatusKey;
1582 }
1583 #if !EMUL
1584 osResource->pGmmResInfo->GetSetCpSurfTag(true, CpTag);
1585 osResource->pGmmResInfo->OverridePitch(planePitch);
1586
1587 osResource->pGmmResInfo->OverrideSurfaceFormat(Format);
1588 osResource->pGmmResInfo->OverrideSurfaceType(RESOURCE_2D);
1589 osResource->pGmmResInfo->OverrideBaseWidth(width);
1590 osResource->pGmmResInfo->OverrideBaseHeight(height);
1591
1592 osResource->pGmmResInfo->OverridePlanarXOffset(GMM_NO_PLANE, (GMM_GFX_SIZE_T)addedShiftLeftOffset);
1593 osResource->pGmmResInfo->OverridePlanarYOffset(GMM_NO_PLANE, 0);
1594 osResource->pGmmResInfo->OverridePlanarXOffset(GMM_PLANE_Y, (GMM_GFX_SIZE_T)addedShiftLeftOffset);
1595 osResource->pGmmResInfo->OverridePlanarYOffset(GMM_PLANE_Y, 0);
1596 #endif
1597
1598 return eStatusKey;
1599
1600 }
1601
1602 bool VP_SURFACE::IsEmpty()
1603 {
1604 VP_FUNC_CALL();
1605 return nullptr == osSurface || Mos_ResourceIsNull(&osSurface->OsResource);
1606 }
1607
1608 MOS_STATUS VP_SURFACE::Clean()
1609 {
1610 VP_FUNC_CALL();
1611 // The vp surface, which owns the resource, cannot be cleaned.
1612 if (isResourceOwner)
1613 {
1614 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
1615 }
1616 if (osSurface)
1617 {
1618 MOS_ZeroMemory(osSurface, sizeof(MOS_SURFACE));
1619 }
1620
1621 isResourceOwner = false;
1622 ColorSpace = CSpace_Any;
1623 ChromaSiting = 0;
1624 bQueryVariance = 0;
1625 FrameID = 0;
1626 ExtendedGamut = false;
1627 SurfType = SURF_NONE;
1628 uFwdRefCount = 0;
1629 uBwdRefCount = 0;
1630 pFwdRef = nullptr;
1631 pBwdRef = nullptr;
1632 SampleType = SAMPLE_PROGRESSIVE;
1633 MOS_ZeroMemory(&Palette, sizeof(Palette));
1634 MOS_ZeroMemory(&rcSrc, sizeof(rcSrc));
1635 MOS_ZeroMemory(&rcDst, sizeof(rcDst));
1636 MOS_ZeroMemory(&rcMaxSrc, sizeof(rcMaxSrc));
1637 bVEBOXCroppingUsed = false;
1638
1639 return MOS_STATUS_SUCCESS;
1640 }
1641
1642 uint64_t VP_SURFACE::GetAllocationHandle(MOS_INTERFACE* osIntf)
1643 {
1644 VP_FUNC_CALL();
1645 if (nullptr == osIntf)
1646 {
1647 return 0;
1648 }
1649 #if MOS_MEDIASOLO_SUPPORTED
1650 if (osIntf && osIntf->bSoloInUse)
1651 {
1652 uint64_t handle = osSurface ? (uint64_t)osSurface->OsResource.pData : 0;
1653 if (handle)
1654 {
1655 return handle;
1656 }
1657 // Media solo external surface will come here, in which case,
1658 // AllocationHandle or bo->handle should be valid.
1659 }
1660 #endif
1661
1662 if (nullptr == osSurface || nullptr == osIntf)
1663 {
1664 return 0;
1665 }
1666 return osIntf->pfnGetResourceHandle(osIntf->osStreamState, &osSurface->OsResource);
1667 }
1668
1669 MOS_STATUS VpAllocator::SetMmcFlags(MOS_SURFACE &osSurface)
1670 {
1671 VP_FUNC_CALL();
1672 VP_PUBLIC_CHK_NULL_RETURN(m_mmc);
1673
1674 // Init MMC related flags.
1675 m_mmc->SetSurfaceMmcMode(&osSurface);
1676 if (osSurface.CompressionMode &&
1677 (osSurface.TileType == MOS_TILE_Y ||
1678 osSurface.TileType == MOS_TILE_YS))
1679 {
1680 uint32_t mmcFormat = 0;
1681
1682 osSurface.bCompressible = true;
1683 osSurface.bIsCompressed = true;
1684 VP_PUBLIC_CHK_STATUS_RETURN(m_mmc->GetSurfaceMmcFormat(&osSurface, &mmcFormat));
1685 osSurface.CompressionFormat = mmcFormat;
1686 }
1687 else
1688 {
1689 // Do not modify the bCompressible flag even MmcMode is disable, since the surface size/pitch may be different
1690 // between Compressible and Uncompressible, which will affect the DN surface allocation.
1691 osSurface.bIsCompressed = false;
1692 osSurface.CompressionMode = MOS_MMC_DISABLED;
1693 osSurface.CompressionFormat = 0;
1694 }
1695
1696 return MOS_STATUS_SUCCESS;
1697 }
1698
1699 MOS_HW_RESOURCE_DEF VpAllocator::GetResourceCache(uint32_t feature, bool bOut, ENGINE_TYPE engineType, MOS_COMPONENT id)
1700 {
1701 VP_FUNC_CALL();
1702 MOS_CACHE_ELEMENT element(MOS_CODEC_RESOURCE_USAGE_BEGIN_CODEC, MOS_CODEC_RESOURCE_USAGE_BEGIN_CODEC);
1703 bool res = m_osInterface->pfnGetCacheSetting(id, SUFACE_TYPE_ASSIGNED(feature), bOut, engineType, element, false);
1704 if (res == false)
1705 {
1706 VP_PUBLIC_ASSERTMESSAGE("Resource %u was not found in cache manager, use default usage MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER!", feature);
1707 return MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER;
1708 }
1709
1710 VP_PUBLIC_NORMALMESSAGE("Resource %u was found in cache manager, use mocs usage %u!", feature, element.mocsUsageType);
1711 return element.mocsUsageType;
1712 }