| 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 ¶m, 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 ¶m); |
| 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 ¶m, 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 | VP_SURFACE *AllocateVpSurface(MOS_RESOURCE &resource); |
| 178 | |
| 179 | //! |
| 180 | //! \brief Copy vp surface from src to dst |
| 181 | //! \param [in] dst |
| 182 | //! The target vp surface for copy. The isResourceOwner flag should be false. |
| 183 | //! \param [in] src |
| 184 | //! The source vp surface for copy. The resource will be reused in dst. |
| 185 | //! \return MOS_STATUS |
| 186 | //! return MOS_STATUS_SUCCESS if no error occur. |
| 187 | //! |
| 188 | MOS_STATUS CopyVpSurface(VP_SURFACE &dst, VP_SURFACE &src); |
| 189 | |
| 190 | //! |
| 191 | //! \brief Destroy Surface |
| 192 | //! \param [in] surface |
| 193 | //! Pointer to VP_SURFACE |
| 194 | //! \param [in] deferredDestroyed |
| 195 | //! Deferred destroy the resource until CleanRecycler being called. |
| 196 | //! \param [in] flags |
| 197 | //! flags for vp surface destroy |
| 198 | //! \return MOS_STATUS |
| 199 | //! MOS_STATUS_SUCCESS if success, else fail reason |
| 200 | //! |
| 201 | MOS_STATUS DestroyVpSurface(VP_SURFACE *&surface, bool deferredDestroyed = false, MOS_GFXRES_FREE_FLAGS flags = {0}); |
| 202 | |
| 203 | //! |
| 204 | //! \brief Allocate Surface |
| 205 | //! \param [in] component |
| 206 | //! component type to track the buffer |
| 207 | //! \param [in] param |
| 208 | //! reference to MOS_ALLOC_GFXRES_PARAMS |
| 209 | //! \param [in] zeroOnAllocate |
| 210 | //! zero the memory if true |
| 211 | //! \return MOS_SURFACE* |
| 212 | //! return the pointer to MOS_SURFACE |
| 213 | //! |
| 214 | MOS_SURFACE* AllocateSurface(MOS_ALLOC_GFXRES_PARAMS ¶m, bool zeroOnAllocate); |
| 215 | |
| 216 | //! |
| 217 | //! \brief Destroy Surface |
| 218 | //! \param [in] surface |
| 219 | //! Pointer to MOS_SURFACE |
| 220 | //! \param [in] flags |
| 221 | //! flags for surface destroy |
| 222 | //! \return MOS_STATUS |
| 223 | //! MOS_STATUS_SUCCESS if success, else fail reason |
| 224 | //! |
| 225 | MOS_STATUS DestroySurface(MOS_SURFACE* surface, MOS_GFXRES_FREE_FLAGS flags = {0}); |
| 226 | |
| 227 | //! |
| 228 | //! \brief Lock resource |
| 229 | //! \param [in] resource |
| 230 | //! Pointer to MOS_RESOURCE |
| 231 | //! \param [in] lockFlag |
| 232 | //! Pointer to MOS_LOCK_PARAMS |
| 233 | //! \return void* |
| 234 | //! a poniter to data |
| 235 | //! |
| 236 | void* Lock(MOS_RESOURCE *resource, MOS_LOCK_PARAMS *lockFlag); |
| 237 | |
| 238 | //! |
| 239 | //! \brief Lock resource only for writing |
| 240 | //! \param [in] resource |
| 241 | //! Pointer to MOS_RESOURCE |
| 242 | //! \return void* |
| 243 | //! a poniter to data |
| 244 | //! |
| 245 | void* LockResourceForWrite(MOS_RESOURCE *resource); |
| 246 | |
| 247 | //! |
| 248 | //! \brief Lock resource with no overwrite flag |
| 249 | //! \param [in] resource |
| 250 | //! Pointer to MOS_RESOURCE |
| 251 | //! \return void* |
| 252 | //! a poniter to data |
| 253 | //! |
| 254 | void* LockResourceWithNoOverwrite(MOS_RESOURCE *resource); |
| 255 | |
| 256 | //! |
| 257 | //! \brief Lock resource only for reading |
| 258 | //! \param [in] resource |
| 259 | //! Pointer to MOS_RESOURCE |
| 260 | //! \return void* |
| 261 | //! a poniter to data |
| 262 | //! |
| 263 | void* LockResourceForRead(MOS_RESOURCE *resource); |
| 264 | |
| 265 | //! |
| 266 | //! \brief UnLock resource |
| 267 | //! \param [in] resource |
| 268 | //! Pointer to MOS_RESOURCE |
| 269 | //! \return MOS_STATUS |
| 270 | //! MOS_STATUS_SUCCESS if success, else fail reason |
| 271 | //! |
| 272 | MOS_STATUS UnLock(MOS_RESOURCE *resource); |
| 273 | |
| 274 | //! |
| 275 | //! \brief Skip sync resource |
| 276 | //! \param [in] resource |
| 277 | //! Pointer to MOS_RESOURCE |
| 278 | //! \return MOS_STATUS |
| 279 | //! MOS_STATUS_SUCCESS if success, else fail reason |
| 280 | //! |
| 281 | MOS_STATUS SkipResourceSync(MOS_RESOURCE* resource); |
| 282 | |
| 283 | //! |
| 284 | //! \brief get surface info from resource |
| 285 | //! \param [in, out] surface |
| 286 | //! Pointer to VPHAL_SURFACE |
| 287 | //! \param [in] info |
| 288 | //! Reference to PVPHAL_GET_SURFACE_INFO |
| 289 | //! \return MOS_STATUS |
| 290 | //! MOS_STATUS_SUCCESS if success, else fail reason |
| 291 | //! |
| 292 | MOS_STATUS GetSurfaceInfo(VPHAL_SURFACE *surface, VPHAL_GET_SURFACE_INFO &info); |
| 293 | |
| 294 | MOS_STATUS GetSurfaceInfo(VP_SURFACE* surface, VPHAL_GET_SURFACE_INFO& info); |
| 295 | |
| 296 | //! |
| 297 | //! \brief Initial the Type/TileType fields in Alloc Params structure |
| 298 | //! \details Initial the Type/TileType fields in Alloc Params structure |
| 299 | //! - Use the last type from GMM resource |
| 300 | //! \param [in, out] allocParams |
| 301 | //! Reference to MOS_ALLOC_GFXRES_PARAMS |
| 302 | //! \param [in] surface |
| 303 | //! Pointer to VPHAL_SURFACE |
| 304 | //! \param [in] defaultResType |
| 305 | //! Expected Resource Type |
| 306 | //! \param [in] defaultTileType |
| 307 | //! Expected Surface Tile Type |
| 308 | //! \return MOS_STATUS |
| 309 | //! MOS_STATUS_SUCCESS if success, else fail reason |
| 310 | //! |
| 311 | MOS_STATUS AllocParamsInitType( |
| 312 | MOS_ALLOC_GFXRES_PARAMS &allocParams, |
| 313 | PVPHAL_SURFACE surface, |
| 314 | MOS_GFXRES_TYPE defaultResType, |
| 315 | MOS_TILE_TYPE defaultTileType); |
| 316 | |
| 317 | //! |
| 318 | //! \brief Initial the Type/TileType fields in Alloc Params structure |
| 319 | //! \details Initial the Type/TileType fields in Alloc Params structure |
| 320 | //! - Use the last type from GMM resource |
| 321 | //! \param [in, out] allocParams |
| 322 | //! Reference to MOS_ALLOC_GFXRES_PARAMS |
| 323 | //! \param [in] surface |
| 324 | //! Pointer to VP_SURFACE |
| 325 | //! \param [in] defaultResType |
| 326 | //! Expected Resource Type |
| 327 | //! \param [in] defaultTileType |
| 328 | //! Expected Surface Tile Type |
| 329 | //! \return MOS_STATUS |
| 330 | //! MOS_STATUS_SUCCESS if success, else fail reason |
| 331 | //! |
| 332 | MOS_STATUS AllocParamsInitType( |
| 333 | MOS_ALLOC_GFXRES_PARAMS &allocParams, |
| 334 | VP_SURFACE *surface, |
| 335 | MOS_GFXRES_TYPE defaultResType, |
| 336 | MOS_TILE_TYPE defaultTileType); |
| 337 | |
| 338 | //! |
| 339 | //! \brief Reallocates the VP Surface |
| 340 | //! \details Reallocates the VP Surface |
| 341 | //! - if the surface is not already allocated OR |
| 342 | //! - resource dimenisions OR format changed |
| 343 | //! \param [in,out] surface |
| 344 | //! Pointer to VP_SURFACE |
| 345 | //! \param [in] surfaceName |
| 346 | //! Pointer to surface name |
| 347 | //! \param [in] format |
| 348 | //! Expected MOS_FORMAT |
| 349 | //! \param [in] defaultResType |
| 350 | //! Expected Resource Type |
| 351 | //! \param [in] defaultTileType |
| 352 | //! Expected Surface Tile Type |
| 353 | //! \param [in] width |
| 354 | //! Expected Surface Width |
| 355 | //! \param [in] height |
| 356 | //! Expected Surface Height |
| 357 | //! \param [in] compressible |
| 358 | //! Surface compressible or not |
| 359 | //! \param [in] compressionMode |
| 360 | //! Compression Mode |
| 361 | //! \param [out] allocated |
| 362 | //! true if allocated, false for not |
| 363 | //! \param [in] zeroOnAllocate |
| 364 | //! zero when surface allocated |
| 365 | //! \param [in] deferredDestroyed |
| 366 | //! Deferred destroy the resource until CleanRecycler being called. |
| 367 | //! \param [in] resUsageType |
| 368 | //! resource usage type for cache policy |
| 369 | //! \param [in] Flag to indicate whether resource being lockable |
| 370 | //! resource usage type for cache policy |
| 371 | //! \return MOS_STATUS |
| 372 | //! MOS_STATUS_SUCCESS if success. Error code otherwise |
| 373 | //! |
| 374 | MOS_STATUS ReAllocateSurface( |
| 375 | VP_SURFACE *&surface, |
| 376 | PCCHAR surfaceName, |
| 377 | MOS_FORMAT format, |
| 378 | MOS_GFXRES_TYPE defaultResType, |
| 379 | MOS_TILE_TYPE defaultTileType, |
| 380 | uint32_t width, |
| 381 | uint32_t height, |
| 382 | bool compressible, |
| 383 | MOS_RESOURCE_MMC_MODE compressionMode, |
| 384 | bool &allocated, |
| 385 | bool zeroOnAllocate = 0, |
| 386 | bool deferredDestroyed = false, |
| 387 | MOS_HW_RESOURCE_DEF resUsageType = MOS_HW_RESOURCE_DEF_MAX, |
| 388 | MOS_TILE_MODE_GMM tileModeByForce = MOS_TILE_UNSET_GMM, |
| 389 | Mos_MemPool memType = MOS_MEMPOOL_VIDEOMEMORY, |
| 390 | bool isNotLockable = false, |
| 391 | void *systemMemory = nullptr, |
| 392 | uint32_t depth = 0); |
| 393 | |
| 394 | //! |
| 395 | //! \brief Reallocates the VP Surface |
| 396 | //! \details Reallocates the VP Surface |
| 397 | //! - if the surface is not already allocated OR |
| 398 | //! - resource dimenisions OR format changed |
| 399 | //! \param [in,out] surface |
| 400 | //! Pointer to VP_SURFACE |
| 401 | //! \param [in] surfaceName |
| 402 | //! Pointer to surface name |
| 403 | //! \param [in] size |
| 404 | //! Expected Buffer Size |
| 405 | //! \param [out] allocated |
| 406 | //! true if allocated, false for not |
| 407 | //! \return MOS_STATUS |
| 408 | //! MOS_STATUS_SUCCESS if success. Error code otherwise |
| 409 | //! |
| 410 | MOS_STATUS ReAllocateNpuBuffer( |
| 411 | VP_SURFACE *&surface, |
| 412 | PCCHAR surfaceName, |
| 413 | uint32_t size, |
| 414 | bool &allocated); |
| 415 | |
| 416 | //! |
| 417 | //! \brief Destroy the VP Surface |
| 418 | //! \details Destroy the VP Surface |
| 419 | //! - if the surface is not already allocated OR |
| 420 | //! - resource dimenisions OR format changed |
| 421 | //! \param [in,out] surface |
| 422 | //! Pointer to VP_SURFACE |
| 423 | //! \return MOS_STATUS |
| 424 | //! MOS_STATUS_SUCCESS if success. Error code otherwise |
| 425 | //! |
| 426 | MOS_STATUS DestroyNpuBuffer( |
| 427 | VP_SURFACE *&surface); |
| 428 | |
| 429 | //! |
| 430 | //! \brief Allocates the Surface |
| 431 | //! \details Allocates the Surface |
| 432 | //! - if the surface is not already allocated OR |
| 433 | //! - resource dimenisions OR format changed |
| 434 | //! \param [in,out] pSurface |
| 435 | //! Pointer to VPHAL_SURFACE |
| 436 | //! \param [in] pSurfaceName |
| 437 | //! Pointer to surface name |
| 438 | //! \param [in] Format |
| 439 | //! Expected MOS_FORMAT |
| 440 | //! \param [in] DefaultResType |
| 441 | //! Expected Resource Type |
| 442 | //! \param [in] DefaultTileType |
| 443 | //! Expected Surface Tile Type |
| 444 | //! \param [in] dwWidth |
| 445 | //! Expected Surface Width |
| 446 | //! \param [in] dwHeight |
| 447 | //! Expected Surface Height |
| 448 | //! \param [in] bCompressible |
| 449 | //! Surface being compressible or not |
| 450 | //! \param [in] CompressionMode |
| 451 | //! Compression Mode |
| 452 | //! \param [out] pbAllocated |
| 453 | //! true if allocated, false for not |
| 454 | //! \param [in] resUsageType |
| 455 | //! resource usage type for caching |
| 456 | //! \return MOS_STATUS |
| 457 | //! MOS_STATUS_SUCCESS if success. Error code otherwise |
| 458 | //! |
| 459 | // for debug purpose |
| 460 | #if (_DEBUG || _RELEASE_INTERNAL) |
| 461 | MOS_STATUS ReAllocateSurface( |
| 462 | PVPHAL_SURFACE surface, // [in/out]Pointer to surface |
| 463 | PCCHAR surfaceName, // [in] Pointer to surface name |
| 464 | MOS_FORMAT format, // [in] Surface Format |
| 465 | MOS_GFXRES_TYPE defaultResType, // [in] Default Resource Type to use if resource has not be allocated yet |
| 466 | MOS_TILE_TYPE defaultTileType, // [in] Default Resource Tile Type to use if resource has not be allocated yet |
| 467 | uint32_t width, // [in] Resource Width |
| 468 | uint32_t height, // [in] Resource Height |
| 469 | bool compressible, // [in] Flag indaicated reource is compressible or not |
| 470 | MOS_RESOURCE_MMC_MODE compressionMode, // [in] Compression mode |
| 471 | bool * allocated, // [out] Flag indicating new allocation |
| 472 | MOS_HW_RESOURCE_DEF resUsageType = MOS_HW_RESOURCE_DEF_MAX, // [in] resource usage type |
| 473 | MOS_TILE_MODE_GMM tileModeByForce = MOS_TILE_UNSET_GMM); // [in] Flag to indicate if GMM flag tile64 need set |
| 474 | #endif |
| 475 | |
| 476 | //! |
| 477 | //! \brief Reallocates the VP Surface w/ the same config of a Vphal Surface |
| 478 | //! \details Reallocates the VP Surface w/ the same config of a Vphal Surface |
| 479 | //! - if the surface is not already allocated OR |
| 480 | //! - resource dimenisions OR format changed |
| 481 | //! \param [in,out] surface |
| 482 | //! Pointer to VP_SURFACE |
| 483 | //! \param [in] surfaceName |
| 484 | //! Pointer to surface name |
| 485 | //! \param [in] vphalSurface |
| 486 | //! Pointer to vphal surface which is the source config of allocated vp surface |
| 487 | //! \param [out] allocated |
| 488 | //! true if allocated, false for not |
| 489 | |
| 490 | //! \return MOS_STATUS |
| 491 | //! MOS_STATUS_SUCCESS if success. Error code otherwise |
| 492 | //! |
| 493 | MOS_STATUS ReAllocateVpSurfaceWithSameConfigOfVphalSurface( |
| 494 | VP_SURFACE *&surface, |
| 495 | const PVPHAL_SURFACE &vphalSurface, |
| 496 | PCCHAR surfaceName, |
| 497 | bool &allocated); |
| 498 | |
| 499 | //! |
| 500 | //! \brief Unified OS fill Resource |
| 501 | //! \details Locks the surface and fills the resource with data |
| 502 | //! \param PMOS_RESOURCE pOsResource |
| 503 | //! [in] Pointer to OS Resource |
| 504 | //! \param uint32_t dwSize |
| 505 | //! [in] Size of the Buffer |
| 506 | //! \param uint8_t iValue |
| 507 | //! [in] Value to be filled |
| 508 | //! \return MOS_STATUS |
| 509 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 510 | //! |
| 511 | MOS_STATUS OsFillResource( |
| 512 | PMOS_RESOURCE osResource, |
| 513 | uint32_t size, |
| 514 | uint8_t value); |
| 515 | |
| 516 | //! |
| 517 | //! \brief Reads the Surface contents and copy to the Dst Buffer |
| 518 | //! \details Reads the Surface contents and copy to the Dst Buffer |
| 519 | //! - 1 lock surface |
| 520 | //! - 2 copy surface data to pDst |
| 521 | //! - 3 unlock surface |
| 522 | //! \param [in] surface |
| 523 | //! Pointer to VPHAL_SURFACE |
| 524 | //! \param [in] bpp |
| 525 | //! bit per pixel of surface contents |
| 526 | //! \param [out] dst |
| 527 | //! output buffer to store Surface contents |
| 528 | //! \return MOS_STATUS |
| 529 | //! MOS_STATUS_SUCCESS if success. Error code otherwise |
| 530 | //! |
| 531 | MOS_STATUS ReadSurface( |
| 532 | PVPHAL_SURFACE surface, |
| 533 | uint32_t bpp, |
| 534 | uint8_t *dst); |
| 535 | |
| 536 | //! |
| 537 | //! \brief Copy Data from input Buffer to the Surface contents |
| 538 | //! \details Copy Data from input Buffer to the Surface contents |
| 539 | //! - 1 lock surface |
| 540 | //! - 2 copy data from pSrc to Surface |
| 541 | //! - 3 unlock surface |
| 542 | //! \param [out] Surface |
| 543 | //! Pointer to VPHAL_SURFACE |
| 544 | //! \param [in] Bpp |
| 545 | //! bit per pixel of input buffer |
| 546 | //! \param [in] Src |
| 547 | //! Input buffer to store Surface contents |
| 548 | //! \return MOS_STATUS |
| 549 | //! MOS_STATUS_SUCCESS if success. Error code otherwise |
| 550 | //! |
| 551 | MOS_STATUS WriteSurface( |
| 552 | PVPHAL_SURFACE surface, |
| 553 | uint32_t bpp, |
| 554 | const uint8_t *src); |
| 555 | |
| 556 | //! |
| 557 | //! \brief Copy Data from input Buffer to the Surface contents |
| 558 | //! \details Copy Data from input Buffer to the Surface contents |
| 559 | //! - 1 lock surface |
| 560 | //! - 2 copy data from pSrc to Surface |
| 561 | //! - 3 unlock surface |
| 562 | //! \param [out] Surface |
| 563 | //! Pointer to VP_SURFACE |
| 564 | //! \param [in] Bpp |
| 565 | //! bit per pixel of input buffer |
| 566 | //! \param [in] Src |
| 567 | //! Input buffer to store Surface contents |
| 568 | //! \return MOS_STATUS |
| 569 | //! MOS_STATUS_SUCCESS if success. Error code otherwise |
| 570 | //! |
| 571 | MOS_STATUS WriteSurface( |
| 572 | VP_SURFACE *surface, |
| 573 | uint32_t bpp, |
| 574 | const uint8_t *src); |
| 575 | |
| 576 | //! |
| 577 | //! \brief Copy Data from input Buffer to the Surface contents |
| 578 | //! \details Copy Data from input Buffer to the Surface contents |
| 579 | //! - 1 lock surface |
| 580 | //! - 2 copy data from pSrc to Surface |
| 581 | //! - 3 unlock surface |
| 582 | //! \param [out] Surface |
| 583 | //! Pointer to VP_SURFACE |
| 584 | //! \param [in] Src |
| 585 | //! Input buffer to store Surface contents |
| 586 | //! \param [in] srcSize |
| 587 | //! size of Src to be copied. |
| 588 | //! \return MOS_STATUS |
| 589 | //! MOS_STATUS_SUCCESS if success. Error code otherwise |
| 590 | //! |
| 591 | MOS_STATUS Write1DSurface( |
| 592 | VP_SURFACE *surface, |
| 593 | const uint8_t *src, |
| 594 | uint32_t srcSize); |
| 595 | |
| 596 | //! |
| 597 | //! \brief Tag based synchronization at the resource level |
| 598 | //! \details Tag based synchronization at the resource level |
| 599 | //! \param PMOS_RESOURCE OsResource |
| 600 | //! [in] OS resource sturcture |
| 601 | //! \param BOOL bWriteOperation |
| 602 | //! [in] Indicate if it is a write operation |
| 603 | //! \return VOID |
| 604 | //! |
| 605 | MOS_STATUS SyncOnResource( |
| 606 | PMOS_RESOURCE osResource, |
| 607 | bool bWriteOperation); |
| 608 | |
| 609 | //! |
| 610 | //! \brief Update the usage type of resource for cache policy |
| 611 | //! \details Update the usage type of resource for cache policy |
| 612 | //! \param PMOS_RESOURCE OsResource |
| 613 | //! [in] OS resource sturcture |
| 614 | //! \param MOS_HW_RESOURCE_DEF resUsageType |
| 615 | //! [in] MOS_HW_RESOURCE_DEF to be set |
| 616 | //! \return VOID |
| 617 | //! |
| 618 | MOS_STATUS UpdateResourceUsageType( |
| 619 | PMOS_RESOURCE osResource, |
| 620 | MOS_HW_RESOURCE_DEF resUsageType); |
| 621 | |
| 622 | //! |
| 623 | //! \brief Check if sync free needed for compressed surface |
| 624 | //! \param PMOS_SURFACE pOsSurface |
| 625 | //! [in] os surface pointer |
| 626 | //! \return bool |
| 627 | //! true if success, otherwise failed reason |
| 628 | //! |
| 629 | bool IsSyncFreeNeededForMMCSurface(PMOS_SURFACE pOsSurface); |
| 630 | void CleanRecycler(); |
| 631 | |
| 632 | //! |
| 633 | //! \brief Allocate resource from cpu buffer |
| 634 | //! \details Allocate resource from cpu buffer |
| 635 | //! \param PMOS_RESOURCE pOsResource |
| 636 | //! [in/out] Pointer to OS resource |
| 637 | //! \param size_t linearAddress |
| 638 | //! [in] CPU address |
| 639 | //! \param uint32_t dataSize |
| 640 | //! [in] data size of CPU buffer |
| 641 | //! \param uint32_t height |
| 642 | //! [in] height of resource |
| 643 | //! \param uint64_t width |
| 644 | //! [in] width of resource |
| 645 | //! \param uint64_t planePitch |
| 646 | //! [in] pitch of resource |
| 647 | //! \param uint32_t CpTag |
| 648 | //! [in] Cp surface tag value |
| 649 | //! \param GMM_RESOURCE_FORMAT Format |
| 650 | //! [in] resouce format |
| 651 | //! \return MOS_STATUS |
| 652 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 653 | //! |
| 654 | MOS_STATUS AllocateCPUResource( |
| 655 | PMOS_RESOURCE osResource, // [in/out]Pointer to OS resource |
| 656 | size_t linearAddress, // [in] CPU address |
| 657 | uint32_t dataSize, // [in] data size of CPU buffer |
| 658 | uint32_t height, // [in] height of resource |
| 659 | uint64_t width, // [in] width of resource |
| 660 | uint64_t planePitch, // [in] pitch of resource |
| 661 | uint32_t CpTag, // [in] Cp surface tag value |
| 662 | GMM_RESOURCE_FORMAT Format // [in] resouce format |
| 663 | ); |
| 664 | |
| 665 | MOS_HW_RESOURCE_DEF GetResourceCache(uint32_t feature, bool bOut, ENGINE_TYPE engineType, MOS_COMPONENT id = COMPONENT_VPCommon); |
| 666 | |
| 667 | int64_t GetTotalSize() |
| 668 | { |
| 669 | return m_totalSize; |
| 670 | } |
| 671 | |
| 672 | int64_t GetPeakSize() |
| 673 | { |
| 674 | return m_peakSize; |
| 675 | } |
| 676 | |
| 677 | protected: |
| 678 | //! |
| 679 | //! \brief Set mmc flags to surface |
| 680 | //! \details Set mmc flags to surface |
| 681 | //! \param MOS_SURFACE &osSurface |
| 682 | //! [in, out] OS surface sturcture |
| 683 | //! \return MOS_STATUS |
| 684 | //! |
| 685 | MOS_STATUS SetMmcFlags(MOS_SURFACE &osSurface); |
| 686 | |
| 687 | //! |
| 688 | //! \brief Update surface plane offset |
| 689 | //! \details Update surface plane offset with render offset |
| 690 | //! \param surf |
| 691 | //! [in, out] surface to be updated. |
| 692 | //! \return VOID |
| 693 | //! |
| 694 | void UpdateSurfacePlaneOffset(MOS_SURFACE &surf); |
| 695 | |
| 696 | PMOS_INTERFACE m_osInterface = nullptr; |
| 697 | Allocator *m_allocator = nullptr; |
| 698 | MediaMemComp *m_mmc = nullptr; |
| 699 | std::vector<VP_SURFACE *> m_recycler; // Container for delayed destroyed surface. |
| 700 | int64_t m_totalSize = 0; // current total memory size. |
| 701 | int64_t m_peakSize = 0; // the peak value of memory size. |
| 702 | |
| 703 | MEDIA_CLASS_DEFINE_END(vp__VpAllocator) |
| 704 | }; |
| 705 | |
| 706 | typedef VpAllocator* PVpAllocator; |
| 707 | } |
| 708 | #endif // !__vp_ALLOCATOR_H__ |