| 1 |
/* Copyright (c) 2024, Intel Corporation |
| 2 |
* |
| 3 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 4 |
* copy of this software and associated documentation files (the "Software"), |
| 5 |
* to deal in the Software without restriction, including without limitation |
| 6 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 7 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 8 |
* Software is furnished to do so, subject to the following conditions: |
| 9 |
* |
| 10 |
* The above copyright notice and this permission notice shall be included |
| 11 |
* in all copies or substantial portions of the Software. |
| 12 |
* |
| 13 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 14 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 16 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 17 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 18 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 19 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 20 |
*/ |
| 21 |
//! |
| 22 |
//! \file mos_cache_manager.cpp |
| 23 |
//! \brief Defines the common classes for cache management |
| 24 |
//! this file is for the base interface which is shared by all features. |
| 25 |
//! |
| 26 |
|
| 27 |
#include "mos_cache_manager.h" |
| 28 |
#include "media_class_trace.h" |
| 29 |
#include "mos_util_debug.h" |
| 30 |
|
| 31 |
class MosCacheManager |
| 32 |
{ |
| 33 |
public: |
| 34 |
MosCacheManager(); |
| 35 |
virtual ~MosCacheManager(); |
| 36 |
|
| 37 |
static bool GetCacheSetting(MOS_COMPONENT id, uint32_t feature, bool bOut, ENGINE_TYPE engineType, MOS_CACHE_ELEMENT &element, bool isHeapSurf); |
| 38 |
|
| 39 |
static bool Register(CACHE_COMPONENTS id, std::map<uint64_t, MOS_CACHE_ELEMENT> *cacheTablesPtr) |
| 40 |
{ |
| 41 |
if (GetInst().m_dataSet[id] == nullptr) |
| 42 |
{ |
| 43 |
GetInst().m_dataSet[id] = cacheTablesPtr; |
| 44 |
} |
| 45 |
return true; |
| 46 |
} |
| 47 |
|
| 48 |
private: |
| 49 |
static MosCacheManager &GetInst() |
| 50 |
{ |
| 51 |
static MosCacheManager inst; |
| 52 |
return inst; |
| 53 |
} |
| 54 |
|
| 55 |
std::map<uint64_t, MOS_CACHE_ELEMENT> *m_dataSet[MAX_CACHE_COMPONENTS] = {}; |
| 56 |
|
| 57 |
MEDIA_CLASS_DEFINE_END(MosCacheManager) |
| 58 |
}; |
| 59 |
|
| 60 |
MosCacheManager::MosCacheManager() |
| 61 |
{ |
| 62 |
} |
| 63 |
|
| 64 |
MosCacheManager::~MosCacheManager() |
| 65 |
{ |
| 66 |
} |
| 67 |
|
| 68 |
bool MosCacheManager::GetCacheSetting(MOS_COMPONENT id, uint32_t feature, bool bOut, ENGINE_TYPE engineType, MOS_CACHE_ELEMENT &element, bool isHeapSurf) |
| 69 |
{ |
| 70 |
auto &inst = GetInst(); |
| 71 |
uint64_t usage = MOS_CACHE_OBJECT(id, feature, isHeapSurf, bOut, engineType).value; |
| 72 |
for (int i = 0; i < MAX_CACHE_COMPONENTS; i++) |
| 73 |
{ |
| 74 |
if (inst.m_dataSet[i]) |
| 75 |
{ |
| 76 |
std::map<uint64_t, MOS_CACHE_ELEMENT> *cacheMap = static_cast<std::map<uint64_t, MOS_CACHE_ELEMENT> *>(GetInst().m_dataSet[i]); |
| 77 |
auto it = cacheMap->find(usage); |
| 78 |
if (it != cacheMap->end()) |
| 79 |
{ |
| 80 |
element = it->second; |
| 81 |
return true; |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
MOS_OS_ASSERTMESSAGE("Cache Element was not found for component %d, feature %d, bOut %d, engineType %d, isHeapSurf %d!", id, feature, bOut, engineType, isHeapSurf); |
| 86 |
return false; |
| 87 |
} |
| 88 |
|
| 89 |
bool RegisterCacheSettings(CACHE_COMPONENTS id, std::map<uint64_t, MOS_CACHE_ELEMENT> *cacheTablesPtr) |
| 90 |
{ |
| 91 |
return MosCacheManager::Register(id, cacheTablesPtr); |
| 92 |
} |
| 93 |
|
| 94 |
bool LoadCacheSettings(MOS_COMPONENT id, uint32_t feature, bool bOut, ENGINE_TYPE engineType, MOS_CACHE_ELEMENT &element, bool isHeapSurf) |
| 95 |
{ |
| 96 |
return MosCacheManager::GetCacheSetting(id, feature, bOut, engineType, element, isHeapSurf); |
| 97 |
} |