1 /*
2 * Copyright (c) 2020, 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 //!
24 //! \file     encode_mem_compression.cpp
25 //! \brief    Defines the common interface for encode mmc
26 //! \details  The mmc is to handle mmc operations,
27 //! including compression and decompressin of encode
28 //!
29 
30 #include "mos_defs.h"
31 #include "encode_mem_compression.h"
32 
EncodeMemComp(CodechalHwInterfaceNext * hwInterface)33 EncodeMemComp::EncodeMemComp(CodechalHwInterfaceNext *hwInterface) :
34     MediaMemComp(hwInterface->GetOsInterface()),
35     m_miItf(std::static_pointer_cast<mhw::mi::Itf>(hwInterface->GetMiInterfaceNext()))
36 {
37     m_mmcEnabledKey     = __MEDIA_USER_FEATURE_VALUE_CODEC_MMC_ENABLE;
38     m_mmcInUseKey       = __MEDIA_USER_FEATURE_VALUE_CODEC_MMC_IN_USE;
39 
40     m_bComponentMmcEnabled = hwInterface->m_enableCodecMmc;
41 
42     InitMmcEnabled();
43     InitEncodeMmc(hwInterface);
44 #if (_DEBUG || _RELEASE_INTERNAL)
45     m_userFeatureUpdated = false;
46 #endif
47 }
48 
49 #if (_DEBUG || _RELEASE_INTERNAL)
UpdateUserFeatureKey(PMOS_SURFACE surface)50 MOS_STATUS EncodeMemComp::UpdateUserFeatureKey(PMOS_SURFACE surface)
51 {
52     if (!surface)
53         return MOS_STATUS_NULL_POINTER;
54 
55     if (m_userFeatureUpdated)
56     {
57         return MOS_STATUS_SUCCESS;
58     }
59 
60     m_userFeatureUpdated = true;
61 
62     ReportUserSetting(
63         m_userSettingPtr,
64         "Encode Recon Compressible",
65         surface->bCompressible,
66         MediaUserSetting::Group::Sequence);
67 
68     ReportUserSetting(
69         m_userSettingPtr,
70         "Encode Recon Compress Mode",
71         surface->MmcState,
72         MediaUserSetting::Group::Sequence);
73 
74     return MOS_STATUS_SUCCESS;
75 }
76 #endif
77 
InitEncodeMmc(CodechalHwInterfaceNext * hwInterface)78 void EncodeMemComp::InitEncodeMmc(CodechalHwInterfaceNext *hwInterface)
79 {
80     CODEC_HW_ASSERT(hwInterface);
81     CODEC_HW_ASSERT(hwInterface->GetSkuTable());
82     if (MEDIA_IS_SKU(hwInterface->GetSkuTable(), FtrE2ECompression))
83     {
84         //read encode mmc if available, then report encode mmc in use
85         bool encodeMmcEnabled = true;
86         MediaUserSetting::Value outValue;
87         ReadUserSetting(
88             m_userSettingPtr,
89             outValue,
90             "Enable Encode MMC",
91             MediaUserSetting::Group::Sequence,
92             m_osInterface->pOsContext,
93             encodeMmcEnabled, true);
94         encodeMmcEnabled = outValue.Get<bool>();
95 
96         m_mmcEnabledForEncode = m_mmcEnabled && encodeMmcEnabled;
97 
98         ReportUserSetting(
99             m_userSettingPtr,
100             "Encode MMC In Use",
101             m_mmcEnabledForEncode,
102             MediaUserSetting::Group::Sequence);
103     }
104 }
105