xref: /aosp_15_r20/external/intel-media-driver/media_driver/agnostic/common/codec/hal/codechal_mmc.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2017-2018, 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     codechal_mmc.h
24 //! \brief    Defines the public interface for CodecHal Media Memory Compression
25 //!
26 #ifndef __CODECHAL_MMC_H__
27 #define __CODECHAL_MMC_H__
28 
29 #include "codechal_utilities.h"
30 
31 //!
32 //! \brief Forward declarations
33 //!
34 typedef struct _MHW_PIPE_CONTROL_PARAMS        *PMHW_PIPE_CONTROL_PARAMS;
35 typedef struct _MHW_VDBOX_SURFACE_PARAMS       *PMHW_VDBOX_SURFACE_PARAMS;
36 using PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS = MHW_VDBOX_PIPE_BUF_ADDR_PARAMS * ;
37 //! \class CodecHalMmcState
38 //! \brief Media memory compression state. This class defines the member fields
39 //!        functions etc used by memory compression.
40 //!
41 class CodecHalMmcState
42 {
43 public:
44     //!
45     //! \brief    Constructor
46     //!
47     CodecHalMmcState(CodechalHwInterface  *hwInterface);
48 
49     //!
50     //! \brief    Destructor
51     //!
~CodecHalMmcState()52     virtual ~CodecHalMmcState() {};
53 
54     //!
55     //! \brief    Check if MMC is enabled
56     //!
57     //! \return   bool
58     //!           true if mmc is enabled, else false
59     //!
60     bool IsMmcEnabled();
61 
62     //!
63     //! \brief    Disable MMC state
64     //!
65     //! \return   void
66     //!
67     void SetMmcDisabled();
68 
69     //!
70     //! \brief    Get surface memory compression state
71     //! \param    [out] surface
72     //!           Pointer to PMOS_SURFACE
73     //!
74     //! \return   MOS_STATUS
75     //!           MOS_STATUS_SUCCESS if success, else fail reason
76     //!
77     MOS_STATUS GetSurfaceMmcState(PMOS_SURFACE surface);
78 
79     //!
80     //! \brief    Get surface memory compression state
81     //! \param    [out] surface
82     //!           Pointer to PMOS_SURFACE
83     //! \param    [in, out] mmcState
84     //!           Pointer to MOS_MEMCOMP_STATE
85     //!
86     //! \return   MOS_STATUS
87     //!           MOS_STATUS_SUCCESS if success, else fail reason
88     //!
89     MOS_STATUS GetSurfaceMmcState(PMOS_SURFACE surface, MOS_MEMCOMP_STATE *mmcState);
90 
91     //!
92     //! \brief    Get surface memory compression state
93     //! \param    [out] surface
94     //!           Pointer to PMOS_SURFACE
95     //! \param    [in, out] mmcFormat
96     //!           Pointer to MMC Format
97     //!
98     //! \return   MOS_STATUS
99     //!           MOS_STATUS_SUCCESS if success, else fail reason
100     //!
101     MOS_STATUS GetSurfaceMmcFormat(PMOS_SURFACE surface, uint32_t *mmcFormat);
102 
103     //!
104     //! \brief    Disable surface memory compression state
105     //! \param    [in,out] surface
106     //!           Pointer to PMOS_SURFACE
107     //!
108     //! \return   MOS_STATUS
109     //!           MOS_STATUS_SUCCESS if success, else fail reason
110     //!
111     MOS_STATUS DisableSurfaceMmcState(PMOS_SURFACE surface);
112 
113     //!
114     //! \brief    Set destinate surface memory compression state by source surface
115     //! \param    [out] dstSurface
116     //!           Pointer to PMOS_SURFACE
117     //! \param    [in] srcSurface
118     //!           Pointer to PMOS_SURFACE
119     //!
120     //! \return   MOS_STATUS
121     //!           MOS_STATUS_SUCCESS if success, else fail reason
122     //!
123     MOS_STATUS SetSurfaceMmcMode(
124         PMOS_SURFACE dstSurface,
125         PMOS_SURFACE srcSurface);
126 
127     //!
128     //! \brief    Set surface paramter
129     //! \param    [in,out] surfaceParams
130     //!           Pointer to PCODECHAL_SURFACE_CODEC_PARAMS
131     //!
132     //! \return   MOS_STATUS
133     //!           MOS_STATUS_SUCCESS if success, else fail reason
134     //!
135     virtual MOS_STATUS SetSurfaceParams(
136         PCODECHAL_SURFACE_CODEC_PARAMS surfaceParams);
137 
138     //!
139     //! \brief    Set pipe buffer address parameter
140     //! \details  Set pipe buffer address parameter in MMC case
141     //!
142     //! \param    [in,out] pipeBufAddrParams
143     //!           Pointer to PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS
144     //! \param    [in] cmdBuffer
145     //!           Pointer to MOS command buffer
146     //!
147     //! \return   MOS_STATUS
148     //!           MOS_STATUS_SUCCESS if success, else fail reason
149     //!
150     virtual MOS_STATUS SetPipeBufAddr(
151         PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS pipeBufAddrParams,
152         PMOS_COMMAND_BUFFER cmdBuffer = nullptr)
153     {
154         return MOS_STATUS_SUCCESS;
155     };
156 
157     //!
158     //! \brief    Set Surface State MMC state parameter
159     //! \details  Set MMC state for speficied SurfaceState cmd parameters
160     //!
161     //! \param    [in,out] surfaceStateParams
162     //!           Pointer to PMHW_VDBOX_SURFACE_PARAMS
163     //! \param    [in] cmdBuffer
164     //!           Pointer to MOS command buffer
165     //!
166     //! \return   MOS_STATUS
167     //!           MOS_STATUS_SUCCESS if success, else fail reason
168     //!
169     virtual MOS_STATUS SetSurfaceState(
170         PMHW_VDBOX_SURFACE_PARAMS surfaceStateParams,
171         PMOS_COMMAND_BUFFER cmdBuffer = nullptr)
172     {
173         return MOS_STATUS_SUCCESS;
174     };
175 
176     //!
177     //! \brief    Send prolog MI cmds used to control MMC state
178     //! \details  Send H/W MMIO cmds used to initialze MMC related states
179     //!
180     //! \param    [in] miInterface
181     //!           Pointer to MhwMiInterface
182     //! \param    [in] cmdBuffer
183     //!           Command buffer pointer
184     //! \param    [in] gpuContext
185     //!           Current pipe of the cmd buffer
186     //!
187     //! \return   MOS_STATUS
188     //!           Return status of sending register MMIOs
SendPrologCmd(MhwMiInterface * miInterface,MOS_COMMAND_BUFFER * cmdBuffer,MOS_GPU_CONTEXT gpuContext)189     virtual MOS_STATUS SendPrologCmd(
190         MhwMiInterface      *miInterface,
191         MOS_COMMAND_BUFFER  *cmdBuffer,
192         MOS_GPU_CONTEXT     gpuContext)
193     {
194         return MOS_STATUS_SUCCESS;
195     }
196 
197     //!
198     //! \brief    Set reference sync
199     //! \details  Set reference sync, check if reference surface needs to be synchronized in MMC case
200     //!
201     //! \param    [in] disableDecodeSyncLock
202     //!           Indicates if decode sync lock is disabled
203     //! \param    [in] disableLockForTranscode
204     //!           Indicates if transcoe lock is disabled
205     //!
206     //! \return   MOS_STATUS
207     //!           MOS_STATUS_SUCCESS if success, else fail reason
208     //!
SetRefrenceSync(bool disableDecodeSyncLock,bool disableLockForTranscode)209     virtual MOS_STATUS SetRefrenceSync(
210         bool disableDecodeSyncLock,
211         bool disableLockForTranscode)
212     {
213         MOS_UNUSED(disableDecodeSyncLock);
214         MOS_UNUSED(disableLockForTranscode);
215         return MOS_STATUS_SUCCESS;
216     };
217 
218     //!
219     //! \brief    Check reference list
220     //! \details  Check reference list, including self-reference detection and mmc state consistence detection
221     //!
222     //! \param    [in,out] pipeBufAddrParams
223     //!           Pointer to PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS
224     //!
225     //! \return   MOS_STATUS
226     //!           MOS_STATUS_SUCCESS if success, else fail reason
227     //!
CheckReferenceList(PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS pipeBufAddrParams)228     virtual MOS_STATUS CheckReferenceList(
229         PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS pipeBufAddrParams)
230     {
231         return MOS_STATUS_SUCCESS;
232     };
233 
234 #if (_DEBUG || _RELEASE_INTERNAL)
235     //!
236     //! \brief    Update mmc user feature key
237     //! \details  Report out the memory compression state for render target surface
238     //!
239     //! \param    [in] surface
240     //!           Pointer to PMOS_SURFACE
241     //!
242     //! \return   MOS_STATUS
243     //!           MOS_STATUS_SUCCESS if success, else fail reason
244     //!
245     MOS_STATUS UpdateUserFeatureKey(PMOS_SURFACE surface);
246 #endif
247 
248     //!
249     //! \brief    Is extension MMC
250     //! \details  Report if is extension MMC
251     //!
252     //! \return   bool
253     //!
IsMmcExtensionEnabled()254     bool IsMmcExtensionEnabled()
255     {
256         return m_mmcExtensionEnabled;
257     }
258 
259 protected:
260 
261     bool                    m_mmcEnabled = false;                   //!< Indicate if media memory compression is enabled
262     PMOS_INTERFACE          m_osInterface = nullptr;                //!< Os Inteface
263     CodechalHwInterface     *m_hwInterface = nullptr;               //!< Pointer to HW Interface
264     bool                    m_hcpMmcEnabled = false;                //!< Inidate if hcp mmc is enabled
265     bool                    m_10bitMmcEnabled = false;              //!< Inidate if 10bit mmc is enabled
266     bool                    m_gpuMmuPageFaultEnabled = false;       //!< Inidate if page fault is enabled
267 #if (_DEBUG || _RELEASE_INTERNAL)
268     bool                    m_userFeatureUpdated = false;              //!< Inidate if mmc user feature key is updated
269     uint32_t                m_compressibleId  = 0;
270     uint32_t                m_compressModeId  = 0;
271 #endif
272     bool                    m_mmcExtensionEnabled = false;          //!< Indicate if extension MMC
273 };
274 
275 #endif  // __CODECHAL_MMC_H__
276