1 /*
2 * Copyright (c) 2020-2023, 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 decode_mem_compression.cpp
25 //! \brief Defines the common interface for decode mmc
26 //! \details The mmc is to handle mmc operations,
27 //! including compression and decompressin of decode
28 //!
29
30 #include "mos_defs.h"
31 #include "decode_mem_compression.h"
32 #include "decode_utils.h"
33
DecodeMemComp(CodechalHwInterfaceNext * hwInterface,PMOS_INTERFACE osInterface)34 DecodeMemComp::DecodeMemComp(CodechalHwInterfaceNext *hwInterface, PMOS_INTERFACE osInterface) :
35 MediaMemComp(osInterface ? osInterface : hwInterface->GetOsInterface())
36 {
37 m_mmcEnabledKey = __MEDIA_USER_FEATURE_VALUE_CODEC_MMC_ENABLE;
38 m_mmcInUseKey = __MEDIA_USER_FEATURE_VALUE_CODEC_MMC_IN_USE;
39 m_miItf = hwInterface ? hwInterface->GetMiInterfaceNext() : nullptr;
40
41 if (hwInterface == nullptr)
42 {
43 CODEC_HW_ASSERT(hwInterface);
44 return;
45 }
46 else
47 {
48 m_bComponentMmcEnabled = hwInterface->m_enableCodecMmc ? true : false;
49 }
50
51 InitMmcEnabled();
52 InitDecodeMmc(hwInterface);
53 #if (_DEBUG || _RELEASE_INTERNAL)
54 m_userFeatureUpdated = false;
55 #endif
56 }
57
58 #if (_DEBUG || _RELEASE_INTERNAL)
UpdateUserFeatureKey(PMOS_SURFACE surface)59 MOS_STATUS DecodeMemComp::UpdateUserFeatureKey(PMOS_SURFACE surface)
60 {
61 if (!surface)
62 return MOS_STATUS_NULL_POINTER;
63
64 if (m_userFeatureUpdated)
65 {
66 return MOS_STATUS_SUCCESS;
67 }
68 m_userFeatureUpdated = true;
69
70 ReportUserSetting(m_userSettingPtr, "Decode RT Compressible", surface->bCompressible, MediaUserSetting::Group::Sequence);
71 ReportUserSetting(m_userSettingPtr, "Decode RT Compress Mode", surface->MmcState, MediaUserSetting::Group::Sequence);
72
73 return MOS_STATUS_SUCCESS;
74 }
75
ReportSurfaceMmcMode(PMOS_SURFACE surface)76 MOS_STATUS DecodeMemComp::ReportSurfaceMmcMode(PMOS_SURFACE surface)
77 {
78 if (!surface)
79 return MOS_STATUS_NULL_POINTER;
80
81 MOS_MEMCOMP_STATE mmcMode = MOS_MEMCOMP_DISABLED;
82 MediaMemComp::GetSurfaceMmcState(surface, &mmcMode);
83
84 DECODE_NORMALMESSAGE("Decode RT Compress Mode is: %d", mmcMode);
85
86 return MOS_STATUS_SUCCESS;
87 }
88 #endif
89
InitDecodeMmc(CodechalHwInterfaceNext * hwInterface)90 void DecodeMemComp::InitDecodeMmc(CodechalHwInterfaceNext *hwInterface)
91 {
92 CODEC_HW_ASSERT(hwInterface);
93 CODEC_HW_ASSERT(hwInterface->GetSkuTable());
94 if (MEDIA_IS_SKU(hwInterface->GetSkuTable(), FtrE2ECompression))
95 {
96 MediaUserSetting::Value outValue;
97 ReadUserSetting(
98 m_userSettingPtr,
99 outValue,
100 "Enable Decode MMC",
101 MediaUserSetting::Group::Sequence,
102 true, // Custom value is true as default
103 true);
104 bool decodeMmcEnabled = outValue.Get<bool>();
105
106 m_mmcEnabledForDecode = m_mmcEnabled && decodeMmcEnabled;
107
108 MOS_USER_FEATURE_VALUE_WRITE_DATA userFeatureWriteData;
109 MOS_ZeroMemory(&userFeatureWriteData, sizeof(userFeatureWriteData));
110 userFeatureWriteData.Value.i32Data = m_mmcEnabledForDecode;
111 userFeatureWriteData.ValueID = __MEDIA_USER_FEATURE_VALUE_DECODE_MMC_IN_USE_ID;
112 MOS_UserFeature_WriteValues_ID(nullptr, &userFeatureWriteData, 1, m_osInterface->pOsContext);
113 }
114
115 #if (_DEBUG || _RELEASE_INTERNAL)
116 m_compressibleId = __MEDIA_USER_FEATURE_VALUE_MMC_DEC_RT_COMPRESSIBLE_ID;
117 m_compressModeId = __MEDIA_USER_FEATURE_VALUE_MMC_DEC_RT_COMPRESSMODE_ID;
118 #endif
119 }
120
IsMmcEnabled()121 bool DecodeMemComp::IsMmcEnabled()
122 {
123 if (!m_mmcEnabledForDecode)
124 {
125 m_mmcEnabled = false;
126 }
127
128 return m_mmcEnabledForDecode;
129 }
130