xref: /aosp_15_r20/external/intel-media-driver/media_softlet/agnostic/common/vp/hal/bufferMgr/vp_allocator.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
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.h
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 #ifndef __VP_ALLOCATOR_H__
30 #define __VP_ALLOCATOR_H__
31 
32 #include "media_allocator.h"
33 #include "vp_mem_compression.h"
34 #include "vp_vebox_common.h"
35 #include "vp_pipeline_common.h"
36 
37 namespace vp {
38 
39 class VpAllocator
40 {
41 public:
42     //!
43     //! \brief  Constructor
44     //! \param  [in] osInterface
45     //!         Pointer to MOS_INTERFACE
46     //!
47     VpAllocator(PMOS_INTERFACE osInterface, MediaMemComp *mmc);
48 
49     //!
50     //! \brief  vpAllocator Destructor
51     //!
52     ~VpAllocator();
53 
54     //!
55     //! \brief  New MOS_RESOURCE and Allocate Resource, add the resource in the resource pool, using DestroyResource or DestroyAllResources to free resource.
56     //! \param  [in] component
57     //!         component type to track the buffer
58     //! \param  [in] param
59     //!         reference to MOS_ALLOC_GFXRES_PARAMS
60     //! \param  [in] zeroOnAllocate
61     //!         zero the memory if true
62     //! \return MOS_RESOURCE*
63     //!         return the pointer to MOS_RESOURCE
64     //!
65     MOS_RESOURCE* AllocateResource(MOS_ALLOC_GFXRES_PARAMS &param, bool zeroOnAllocate);
66 
67     //!
68     //! \brief  Destroy a resource registered on the resource pool and free its MOS_RESOURCE struct
69     //! \param  [in] resource
70     //!         Pointer to MOS_RESOURCE
71     //! \return MOS_STATUS
72     //!         MOS_STATUS_SUCCESS if success, else fail reason
73     //!
74     MOS_STATUS DestroyResource(MOS_RESOURCE* resource);
75 
76     //!
77     //! \brief  Destroy all resources registered on the resource pool and free the MOS_RESOURCE struct
78     //! \param  [in] resource
79     //!         Pointer to MOS_RESOURCE
80     //! \return MOS_STATUS
81     //!         MOS_STATUS_SUCCESS if success, else fail reason
82     //!
83     MOS_STATUS DestroyAllResources();
84 
85     //!
86     //! \brief  Allocate Resource but not register the resource to the resource pool, using FreeResource to free the resource
87     //! \param  [in] component
88     //!         component type to track the buffer
89     //! \param  [in] param
90     //!         reference to MOS_ALLOC_GFXRES_PARAMS
91     //! \return MOS_RESOURCE*
92     //!         return the pointer to MOS_RESOURCE
93     //!
94     MOS_STATUS AllocateResource(MOS_RESOURCE *res, MOS_ALLOC_GFXRES_PARAMS &param);
95 
96     //!
97     //! \brief  Free Resource
98     //! \param  [in] resource
99     //!         Pointer to MOS_RESOURCE
100     //! \return MOS_STATUS
101     //!         MOS_STATUS_SUCCESS if success, else fail reason
102     //!
103     MOS_STATUS FreeResource(MOS_RESOURCE *resource);
104 
105     //!
106     //! \brief  Allocate vp surface
107     //! \param  [in] component
108     //!         component type to track the buffer
109     //! \param  [in] param
110     //!         reference to MOS_ALLOC_GFXRES_PARAMS
111     //! \param  [in] zeroOnAllocate
112     //!         zero the memory if true
113     //! \param  [in] ColorSpace
114     //!         Surface color space config
115     //! \param  [in] ChromaSiting
116     //!         Surface chromasiting config
117     //! \param  [in] ChromaSiting
118     //!         Surface rotation config
119     //! \return VP_SURFACE*
120     //!         return the pointer to VP_SURFACE
121     //!
122     VP_SURFACE* AllocateVpSurface(MOS_ALLOC_GFXRES_PARAMS &param, bool zeroOnAllocate = false, VPHAL_CSPACE ColorSpace = CSpace_None, uint32_t ChromaSiting = 0);
123 
124     //!
125     //! \brief  Allocate vp surface
126     //! \param  [in] vphalSurf
127     //!         The vphal surface that vp surface created from. The resource will be reused in vp surface.
128     //! \return VP_SURFACE*
129     //!         return the pointer to VP_SURFACE
130     //!
131     VP_SURFACE* AllocateVpSurface(VPHAL_SURFACE &vphalSurf);
132 
133     //!
134     //! \brief  Allocate vp surface
135     //! \param  [in] vpSurf
136     //!         The surface that vp surface created from. The resource will be reused in vp surface.
137     //! \return VP_SURFACE*
138     //!         return the pointer to VP_SURFACE
139     //!
140     VP_SURFACE* AllocateVpSurface(VP_SURFACE &vphalSurf);
141 
142     //!
143     //! \brief  Allocate vp surface
144     //! \param  [in] osSurf
145     //!         The surface that vp surface created from. The resource will be reused in vp surface.
146     //! \param  [in] colorSpace
147     //!         colorSpace of vp surface.
148     //! \param  [in] chromaSiting
149     //!         chromaSiting of vp surface.
150     //! \param  [in] rcSrc
151     //!         rcSrc of vp surface.
152     //! \param  [in] rcDst
153     //!         rcDst of vp surface.
154     //! \param  [in] SurfType
155     //!         SurfType of vp surface.
156     //! \param  [in] updatePlaneOffset
157     //!         true, update plane offset of vp surface, otherwise, use the one in osSurf.
158     //! \return VP_SURFACE*
159     //!         return the pointer to VP_SURFACE
160     //!
161     VP_SURFACE *AllocateVpSurface(
162         MOS_SURFACE &osSurf,
163         VPHAL_CSPACE colorSpace,
164         uint32_t chromaSiting,
165         RECT rcSrc,
166         RECT rcDst,
167         VPHAL_SURFACE_TYPE SurfType,
168         bool updatePlaneOffset = false);
169 
170     //!
171     //! \brief  Allocate vp surface without resource
172     //! \return VP_SURFACE*
173     //!         return the pointer to VP_SURFACE
174     //!
175     VP_SURFACE *AllocateVpSurface();
176 
177     //!
178     //! \brief  Copy vp surface from src to dst
179     //! \param  [in] dst
180     //!         The target vp surface for copy. The isResourceOwner flag should be false.
181     //! \param  [in] src
182     //!         The source vp surface for copy. The resource will be reused in dst.
183     //! \return MOS_STATUS
184     //!         return MOS_STATUS_SUCCESS if no error occur.
185     //!
186     MOS_STATUS CopyVpSurface(VP_SURFACE &dst, VP_SURFACE &src);
187 
188     //!
189     //! \brief  Destroy Surface
190     //! \param  [in] surface
191     //!         Pointer to VP_SURFACE
192     //! \param  [in] deferredDestroyed
193     //!         Deferred destroy the resource until CleanRecycler being called.
194     //! \param  [in] flags
195     //!         flags for vp surface destroy
196     //! \return MOS_STATUS
197     //!         MOS_STATUS_SUCCESS if success, else fail reason
198     //!
199     MOS_STATUS DestroyVpSurface(VP_SURFACE *&surface, bool deferredDestroyed = false, MOS_GFXRES_FREE_FLAGS flags = {0});
200 
201     //!
202     //! \brief  Allocate Surface
203     //! \param  [in] component
204     //!         component type to track the buffer
205     //! \param  [in] param
206     //!         reference to MOS_ALLOC_GFXRES_PARAMS
207     //! \param  [in] zeroOnAllocate
208     //!         zero the memory if true
209     //! \return MOS_SURFACE*
210     //!         return the pointer to MOS_SURFACE
211     //!
212     MOS_SURFACE* AllocateSurface(MOS_ALLOC_GFXRES_PARAMS &param, bool zeroOnAllocate);
213 
214     //!
215     //! \brief  Destroy Surface
216     //! \param  [in] surface
217     //!         Pointer to MOS_SURFACE
218     //! \param  [in] flags
219     //!         flags for surface destroy
220     //! \return MOS_STATUS
221     //!         MOS_STATUS_SUCCESS if success, else fail reason
222     //!
223     MOS_STATUS DestroySurface(MOS_SURFACE* surface, MOS_GFXRES_FREE_FLAGS flags = {0});
224 
225     //!
226     //! \brief  Lock resource
227     //! \param  [in] resource
228     //!         Pointer to MOS_RESOURCE
229     //! \param  [in] lockFlag
230     //!         Pointer to MOS_LOCK_PARAMS
231     //! \return void*
232     //!         a poniter to data
233     //!
234     void* Lock(MOS_RESOURCE *resource, MOS_LOCK_PARAMS *lockFlag);
235 
236     //!
237     //! \brief  Lock resource only for writing
238     //! \param  [in] resource
239     //!         Pointer to MOS_RESOURCE
240     //! \return void*
241     //!         a poniter to data
242     //!
243     void* LockResourceForWrite(MOS_RESOURCE *resource);
244 
245     //!
246     //! \brief  Lock resource with no overwrite flag
247     //! \param  [in] resource
248     //!         Pointer to MOS_RESOURCE
249     //! \return void*
250     //!         a poniter to data
251     //!
252     void* LockResourceWithNoOverwrite(MOS_RESOURCE *resource);
253 
254     //!
255     //! \brief  Lock resource only for reading
256     //! \param  [in] resource
257     //!         Pointer to MOS_RESOURCE
258     //! \return void*
259     //!         a poniter to data
260     //!
261     void* LockResourceForRead(MOS_RESOURCE *resource);
262 
263     //!
264     //! \brief  UnLock resource
265     //! \param  [in] resource
266     //!         Pointer to MOS_RESOURCE
267     //! \return MOS_STATUS
268     //!         MOS_STATUS_SUCCESS if success, else fail reason
269     //!
270     MOS_STATUS UnLock(MOS_RESOURCE *resource);
271 
272     //!
273     //! \brief  Skip sync resource
274     //! \param  [in] resource
275     //!         Pointer to MOS_RESOURCE
276     //! \return MOS_STATUS
277     //!         MOS_STATUS_SUCCESS if success, else fail reason
278     //!
279     MOS_STATUS SkipResourceSync(MOS_RESOURCE* resource);
280 
281     //!
282     //! \brief  get surface info from resource
283     //! \param  [in, out] surface
284     //!         Pointer to VPHAL_SURFACE
285     //! \param  [in] info
286     //!         Reference to PVPHAL_GET_SURFACE_INFO
287     //! \return MOS_STATUS
288     //!         MOS_STATUS_SUCCESS if success, else fail reason
289     //!
290     MOS_STATUS GetSurfaceInfo(VPHAL_SURFACE *surface, VPHAL_GET_SURFACE_INFO &info);
291 
292     MOS_STATUS GetSurfaceInfo(VP_SURFACE* surface, VPHAL_GET_SURFACE_INFO& info);
293 
294     //!
295     //! \brief    Initial the Type/TileType fields in Alloc Params structure
296     //! \details  Initial the Type/TileType fields in Alloc Params structure
297     //!           - Use the last type from GMM resource
298     //! \param    [in, out] allocParams
299     //!           Reference to MOS_ALLOC_GFXRES_PARAMS
300     //! \param    [in] surface
301     //!           Pointer to VPHAL_SURFACE
302     //! \param    [in] defaultResType
303     //!           Expected Resource Type
304     //! \param    [in] defaultTileType
305     //!           Expected Surface Tile Type
306     //! \return MOS_STATUS
307     //!         MOS_STATUS_SUCCESS if success, else fail reason
308     //!
309     MOS_STATUS AllocParamsInitType(
310         MOS_ALLOC_GFXRES_PARAMS     &allocParams,
311         PVPHAL_SURFACE              surface,
312         MOS_GFXRES_TYPE             defaultResType,
313         MOS_TILE_TYPE               defaultTileType);
314 
315     //!
316     //! \brief    Initial the Type/TileType fields in Alloc Params structure
317     //! \details  Initial the Type/TileType fields in Alloc Params structure
318     //!           - Use the last type from GMM resource
319     //! \param    [in, out] allocParams
320     //!           Reference to MOS_ALLOC_GFXRES_PARAMS
321     //! \param    [in] surface
322     //!           Pointer to VP_SURFACE
323     //! \param    [in] defaultResType
324     //!           Expected Resource Type
325     //! \param    [in] defaultTileType
326     //!           Expected Surface Tile Type
327     //! \return MOS_STATUS
328     //!         MOS_STATUS_SUCCESS if success, else fail reason
329     //!
330     MOS_STATUS AllocParamsInitType(
331         MOS_ALLOC_GFXRES_PARAMS     &allocParams,
332         VP_SURFACE                  *surface,
333         MOS_GFXRES_TYPE             defaultResType,
334         MOS_TILE_TYPE               defaultTileType);
335 
336     //!
337     //! \brief    Reallocates the VP Surface
338     //! \details  Reallocates the VP Surface
339     //!           - if the surface is not already allocated OR
340     //!           - resource dimenisions OR format changed
341     //! \param    [in,out] surface
342     //!           Pointer to VP_SURFACE
343     //! \param    [in] surfaceName
344     //!           Pointer to surface name
345     //! \param    [in] format
346     //!           Expected MOS_FORMAT
347     //! \param    [in] defaultResType
348     //!           Expected Resource Type
349     //! \param    [in] defaultTileType
350     //!           Expected Surface Tile Type
351     //! \param    [in] width
352     //!           Expected Surface Width
353     //! \param    [in] height
354     //!           Expected Surface Height
355     //! \param    [in] compressible
356     //!           Surface compressible or not
357     //! \param    [in] compressionMode
358     //!           Compression Mode
359     //! \param    [out] allocated
360     //!           true if allocated, false for not
361     //! \param    [in] zeroOnAllocate
362     //!           zero when surface allocated
363     //! \param    [in] deferredDestroyed
364     //!           Deferred destroy the resource until CleanRecycler being called.
365     //! \param    [in] resUsageType
366     //!           resource usage type for cache policy
367     //! \param    [in] Flag to indicate whether resource being lockable
368     //!           resource usage type for cache policy
369     //! \return   MOS_STATUS
370     //!           MOS_STATUS_SUCCESS if success. Error code otherwise
371     //!
372     MOS_STATUS ReAllocateSurface(
373         VP_SURFACE             *&surface,
374         PCCHAR                  surfaceName,
375         MOS_FORMAT              format,
376         MOS_GFXRES_TYPE         defaultResType,
377         MOS_TILE_TYPE           defaultTileType,
378         uint32_t                width,
379         uint32_t                height,
380         bool                    compressible,
381         MOS_RESOURCE_MMC_MODE   compressionMode,
382         bool                    &allocated,
383         bool                    zeroOnAllocate = 0,
384         bool                    deferredDestroyed = false,
385         MOS_HW_RESOURCE_DEF     resUsageType   = MOS_HW_RESOURCE_DEF_MAX,
386         MOS_TILE_MODE_GMM       tileModeByForce = MOS_TILE_UNSET_GMM,
387         Mos_MemPool             memType = MOS_MEMPOOL_VIDEOMEMORY,
388         bool                    isNotLockable = false,
389         void                    *systemMemory = nullptr,
390         uint32_t                depth = 0);
391 
392     //!
393     //! \brief    Allocates the Surface
394     //! \details  Allocates the Surface
395     //!           - if the surface is not already allocated OR
396     //!           - resource dimenisions OR format changed
397     //! \param    [in,out] pSurface
398     //!           Pointer to VPHAL_SURFACE
399     //! \param    [in] pSurfaceName
400     //!           Pointer to surface name
401     //! \param    [in] Format
402     //!           Expected MOS_FORMAT
403     //! \param    [in] DefaultResType
404     //!           Expected Resource Type
405     //! \param    [in] DefaultTileType
406     //!           Expected Surface Tile Type
407     //! \param    [in] dwWidth
408     //!           Expected Surface Width
409     //! \param    [in] dwHeight
410     //!           Expected Surface Height
411     //! \param    [in] bCompressible
412     //!           Surface being compressible or not
413     //! \param    [in] CompressionMode
414     //!           Compression Mode
415     //! \param    [out] pbAllocated
416     //!           true if allocated, false for not
417     //! \param    [in] resUsageType
418     //!           resource usage type for caching
419     //! \return   MOS_STATUS
420     //!           MOS_STATUS_SUCCESS if success. Error code otherwise
421     //!
422     // for debug purpose
423 #if (_DEBUG || _RELEASE_INTERNAL)
424     MOS_STATUS ReAllocateSurface(
425         PVPHAL_SURFACE        surface,                                   // [in/out]Pointer to surface
426         PCCHAR                surfaceName,                               // [in]    Pointer to surface name
427         MOS_FORMAT            format,                                    // [in]    Surface Format
428         MOS_GFXRES_TYPE       defaultResType,                            // [in]    Default Resource Type to use if resource has not be allocated yet
429         MOS_TILE_TYPE         defaultTileType,                           // [in]    Default Resource Tile Type to use if resource has not be allocated yet
430         uint32_t              width,                                     // [in]    Resource Width
431         uint32_t              height,                                    // [in]    Resource Height
432         bool                  compressible,                              // [in]    Flag indaicated reource is compressible or not
433         MOS_RESOURCE_MMC_MODE compressionMode,                           // [in]    Compression mode
434         bool *                allocated,                                 // [out]   Flag indicating new allocation
435         MOS_HW_RESOURCE_DEF   resUsageType    = MOS_HW_RESOURCE_DEF_MAX, // [in]    resource usage type
436         MOS_TILE_MODE_GMM     tileModeByForce = MOS_TILE_UNSET_GMM);     // [in]    Flag to indicate if GMM flag tile64 need set
437 #endif
438     //!
439     //! \brief    Unified OS fill Resource
440     //! \details  Locks the surface and fills the resource with data
441     //! \param    PMOS_RESOURCE pOsResource
442     //!           [in] Pointer to OS Resource
443     //! \param    uint32_t dwSize
444     //!           [in] Size of the Buffer
445     //! \param    uint8_t iValue
446     //!           [in] Value to be filled
447     //! \return   MOS_STATUS
448     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
449     //!
450     MOS_STATUS OsFillResource(
451         PMOS_RESOURCE     osResource,
452         uint32_t          size,
453         uint8_t           value);
454 
455     //!
456     //! \brief    Reads the Surface contents and copy to the Dst Buffer
457     //! \details  Reads the Surface contents and copy to the Dst Buffer
458     //!           - 1 lock surface
459     //!           - 2 copy surface data to pDst
460     //!           - 3 unlock surface
461     //! \param    [in] surface
462     //!           Pointer to VPHAL_SURFACE
463     //! \param    [in] bpp
464     //!           bit per pixel of surface contents
465     //! \param    [out] dst
466     //!           output buffer to store Surface contents
467     //! \return   MOS_STATUS
468     //!           MOS_STATUS_SUCCESS if success. Error code otherwise
469     //!
470     MOS_STATUS ReadSurface(
471         PVPHAL_SURFACE      surface,
472         uint32_t            bpp,
473         uint8_t             *dst);
474 
475     //!
476     //! \brief    Copy Data from input Buffer to the Surface contents
477     //! \details  Copy Data from input Buffer to the Surface contents
478     //!           - 1 lock surface
479     //!           - 2 copy data from pSrc to Surface
480     //!           - 3 unlock surface
481     //! \param    [out] Surface
482     //!           Pointer to VPHAL_SURFACE
483     //! \param    [in] Bpp
484     //!           bit per pixel of input buffer
485     //! \param    [in] Src
486     //!           Input buffer to store Surface contents
487     //! \return   MOS_STATUS
488     //!           MOS_STATUS_SUCCESS if success. Error code otherwise
489     //!
490     MOS_STATUS WriteSurface(
491         PVPHAL_SURFACE      surface,
492         uint32_t            bpp,
493         const uint8_t       *src);
494 
495     //!
496     //! \brief    Copy Data from input Buffer to the Surface contents
497     //! \details  Copy Data from input Buffer to the Surface contents
498     //!           - 1 lock surface
499     //!           - 2 copy data from pSrc to Surface
500     //!           - 3 unlock surface
501     //! \param    [out] Surface
502     //!           Pointer to VP_SURFACE
503     //! \param    [in] Bpp
504     //!           bit per pixel of input buffer
505     //! \param    [in] Src
506     //!           Input buffer to store Surface contents
507     //! \return   MOS_STATUS
508     //!           MOS_STATUS_SUCCESS if success. Error code otherwise
509     //!
510     MOS_STATUS WriteSurface(
511         VP_SURFACE         *surface,
512         uint32_t            bpp,
513         const uint8_t      *src);
514 
515     //!
516     //! \brief    Copy Data from input Buffer to the Surface contents
517     //! \details  Copy Data from input Buffer to the Surface contents
518     //!           - 1 lock surface
519     //!           - 2 copy data from pSrc to Surface
520     //!           - 3 unlock surface
521     //! \param    [out] Surface
522     //!           Pointer to VP_SURFACE
523     //! \param    [in] Src
524     //!           Input buffer to store Surface contents
525     //! \param    [in] srcSize
526     //!           size of Src to be copied.
527     //! \return   MOS_STATUS
528     //!           MOS_STATUS_SUCCESS if success. Error code otherwise
529     //!
530     MOS_STATUS Write1DSurface(
531         VP_SURFACE         *surface,
532         const uint8_t      *src,
533         uint32_t            srcSize);
534 
535     //!
536     //! \brief    Tag based synchronization at the resource level
537     //! \details  Tag based synchronization at the resource level
538     //! \param    PMOS_RESOURCE OsResource
539     //!           [in] OS resource sturcture
540     //! \param    BOOL bWriteOperation
541     //!           [in] Indicate if it is a write operation
542     //! \return   VOID
543     //!
544     MOS_STATUS SyncOnResource(
545         PMOS_RESOURCE         osResource,
546         bool                  bWriteOperation);
547 
548     //!
549     //! \brief    Update the usage type of resource for cache policy
550     //! \details  Update the usage type of resource for cache policy
551     //! \param    PMOS_RESOURCE OsResource
552     //!           [in] OS resource sturcture
553     //! \param    MOS_HW_RESOURCE_DEF resUsageType
554     //!           [in] MOS_HW_RESOURCE_DEF to be set
555     //! \return   VOID
556     //!
557     MOS_STATUS UpdateResourceUsageType(
558         PMOS_RESOURCE           osResource,
559         MOS_HW_RESOURCE_DEF     resUsageType);
560 
561     //!
562     //! \brief    Check if sync free needed for compressed surface
563     //! \param    PMOS_SURFACE pOsSurface
564     //!           [in] os surface pointer
565     //! \return   bool
566     //!           true if success, otherwise failed reason
567     //!
568     bool IsSyncFreeNeededForMMCSurface(PMOS_SURFACE pOsSurface);
569     void CleanRecycler();
570 
571     //!
572     //! \brief    Allocate resource from cpu buffer
573     //! \details  Allocate resource from cpu buffer
574     //! \param    PMOS_RESOURCE pOsResource
575     //!           [in/out] Pointer to OS resource
576     //! \param    size_t linearAddress
577     //!           [in]    CPU address
578     //! \param    uint32_t dataSize
579     //!           [in]    data size of CPU buffer
580     //! \param    uint32_t height
581     //!           [in]    height of resource
582     //! \param    uint64_t width
583     //!           [in]    width of resource
584     //! \param    uint64_t planePitch
585     //!           [in]    pitch of resource
586     //! \param    uint32_t CpTag
587     //!           [in]    Cp surface tag value
588     //! \param    GMM_RESOURCE_FORMAT Format
589     //!           [in]    resouce format
590     //! \return   MOS_STATUS
591     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
592     //!
593     MOS_STATUS AllocateCPUResource(
594         PMOS_RESOURCE osResource,           // [in/out]Pointer to OS resource
595         size_t linearAddress,               // [in]    CPU address
596         uint32_t dataSize,                  // [in]    data size of CPU buffer
597         uint32_t height,                    // [in]    height of resource
598         uint64_t width,                     // [in]    width of resource
599         uint64_t planePitch,                // [in]    pitch of resource
600         uint32_t CpTag,                     // [in]    Cp surface tag value
601         GMM_RESOURCE_FORMAT Format          // [in]    resouce format
602     );
603 
604     MOS_HW_RESOURCE_DEF GetResourceCache(uint32_t feature, bool bOut, ENGINE_TYPE engineType, MOS_COMPONENT id = COMPONENT_VPCommon);
605 
GetTotalSize()606     int64_t GetTotalSize()
607     {
608         return m_totalSize;
609     }
610 
GetPeakSize()611     int64_t GetPeakSize()
612     {
613         return m_peakSize;
614     }
615 
616 protected:
617     //!
618     //! \brief    Set mmc flags to surface
619     //! \details  Set mmc flags to surface
620     //! \param    MOS_SURFACE &osSurface
621     //!           [in, out] OS surface sturcture
622     //! \return   MOS_STATUS
623     //!
624     MOS_STATUS SetMmcFlags(MOS_SURFACE &osSurface);
625 
626     //!
627     //! \brief    Update surface plane offset
628     //! \details  Update surface plane offset with render offset
629     //! \param    surf
630     //!           [in, out] surface to be updated.
631     //! \return   VOID
632     //!
633     void UpdateSurfacePlaneOffset(MOS_SURFACE &surf);
634 
635     PMOS_INTERFACE  m_osInterface   = nullptr;
636     Allocator       *m_allocator    = nullptr;
637     MediaMemComp    *m_mmc          = nullptr;
638     std::vector<VP_SURFACE *> m_recycler;   // Container for delayed destroyed surface.
639     int64_t         m_totalSize     = 0; // current total memory size.
640     int64_t         m_peakSize      = 0;  // the peak value of memory size.
641 
642 MEDIA_CLASS_DEFINE_END(vp__VpAllocator)
643 };
644 
645 typedef VpAllocator* PVpAllocator;
646 }
647 #endif // !__vp_ALLOCATOR_H__
648