Debian Codegraph @

media_driver/agnostic/common/hw/mhw_render_legacy.h

raw
1 /*
2 * Copyright (c) 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 mhw_render_legacy.h
24 //! \brief MHW interface for constructing commands for the render engine
25 //! \details Impelements the functionalities common across all platforms for MHW_RENDER
26 //!
27
28 #ifndef __MHW_RENDER_LEGACY_H__
29 #define __MHW_RENDER_LEGACY_H__
30
31 #include "mhw_render.h"
32 #include "mhw_utilities.h"
33 #include "mhw_mi.h"
34 #include "mhw_state_heap_legacy.h"
35
36 class MhwRenderInterface
37 {
38 public:
39 PMHW_STATE_HEAP_INTERFACE m_stateHeapInterface = nullptr;
40
41 virtual ~MhwRenderInterface()
42 {
43 if (m_stateHeapInterface)
44 {
45 m_stateHeapInterface->pfnDestroy(m_stateHeapInterface);
46 }
47 }
48
49 //!
50 //! \brief Allocates the MHW render interface internal parameters
51 //! \details Internal MHW function to allocate all parameters needed for the
52 //! render interface including the state heap interface
53 //! \param MHW_STATE_HEAP_SETTINGS stateHeapSettings
54 //! [in] Setting used to initialize the state heap interface
55 //! \return MOS_STATUS
56 //! MOS_STATUS_SUCCESS if success, else fail reason
57 //!
58 MOS_STATUS AllocateHeaps(
59 MHW_STATE_HEAP_SETTINGS stateHeapSettings);
60
61 //!
62 //! \brief Adds PIPELINE_SELECT to the command buffer
63 //! \param cmdBuffer
64 //! [in] Command buffer to which commands are added
65 //! \param gpGpuPipe
66 //! [in] false: MEDIA pipe; true: GPGPU pipe
67 //! \return MOS_STATUS
68 //! MOS_STATUS_SUCCESS if success, else fail reason
69 //!
70 virtual MOS_STATUS AddPipelineSelectCmd (
71 PMOS_COMMAND_BUFFER cmdBuffer,
72 bool gpGpuPipe) = 0;
73
74 //!
75 //! \brief Adds STATE_BASE_ADDRESS to the command buffer
76 //! \param cmdBuffer
77 //! [in] Command buffer to which HW command is added
78 //! \param params
79 //! [in] Params structure used to populate the HW command
80 //! \return MOS_STATUS
81 //! MOS_STATUS_SUCCESS if success, else fail reason
82 //!
83 virtual MOS_STATUS AddStateBaseAddrCmd(
84 PMOS_COMMAND_BUFFER cmdBuffer,
85 PMHW_STATE_BASE_ADDR_PARAMS params) = 0;
86
87 //!
88 //! \brief Adds MEDIA_VFE_STATE to the command buffer
89 //! \param cmdBuffer
90 //! [in] Command buffer to which HW command is added
91 //! \param params
92 //! [in] Params structure used to populate the HW command
93 //! \return MOS_STATUS
94 //! MOS_STATUS_SUCCESS if success, else fail reason
95 //!
96 virtual MOS_STATUS AddMediaVfeCmd (
97 PMOS_COMMAND_BUFFER cmdBuffer,
98 PMHW_VFE_PARAMS params) = 0;
99
100 //!
101 //! \brief Adds CFE_STATE to the command buffer
102 //! \param cmdBuffer
103 //! [in] Command buffer to which HW command is added
104 //! \param params
105 //! [in] Params structure used to populate the HW command
106 //! \return MOS_STATUS
107 //! MOS_STATUS_SUCCESS if success, else fail reason
108 //!
109 virtual MOS_STATUS AddCfeStateCmd(
110 PMOS_COMMAND_BUFFER cmdBuffer,
111 PMHW_VFE_PARAMS params)
112 {
113 MOS_UNUSED(cmdBuffer);
114 MOS_UNUSED(params);
115
116 // CFE_STATE will replace the MEDIA_VFE_STATE on some platform; Just keep the
117 // platform which really uses CFE to implement it on inheriting class .
118 MHW_ASSERTMESSAGE("Don't support it on this platform");
119 return MOS_STATUS_SUCCESS;
120 }
121
122 //!
123 //! \brief Adds MEDIA_CURBE_LOAD to the command buffer
124 //! \param cmdBuffer
125 //! [in] Command buffer to which HW command is added
126 //! \param params
127 //! [in] Params structure used to populate the HW command
128 //! \return MOS_STATUS
129 //! MOS_STATUS_SUCCESS if success, else fail reason
130 //!
131 virtual MOS_STATUS AddMediaCurbeLoadCmd(
132 PMOS_COMMAND_BUFFER cmdBuffer,
133 PMHW_CURBE_LOAD_PARAMS params) = 0;
134
135 //!
136 //! \brief Adds MEDIA_INTERFACE_DESCRIPTOR_LOAD to the command buffer
137 //! \param cmdBuffer
138 //! [in] Command buffer to which HW command is added
139 //! \param params
140 //! [in] Params structure used to populate the HW command
141 //! \return MOS_STATUS
142 //! MOS_STATUS_SUCCESS if success, else fail reason
143 //!
144 virtual MOS_STATUS AddMediaIDLoadCmd(
145 PMOS_COMMAND_BUFFER cmdBuffer,
146 PMHW_ID_LOAD_PARAMS params) = 0;
147
148 //!
149 //! \brief Adds MEDIA_OBJECT to the buffer provided
150 //! \details MEDIA_OBJCET is added to either the command buffer or
151 //! batch buffer (whichever is valid)
152 //! \param cmdBuffer
153 //! [in] If valid, command buffer to which HW command is added
154 //! \param batchBuffer
155 //! [in] If valid, Batch buffer to which HW command is added
156 //! \param params
157 //! [in] Params structure used to populate the HW command
158 //! \return MOS_STATUS
159 //! MOS_STATUS_SUCCESS if success, else fail reason
160 //!
161 virtual MOS_STATUS AddMediaObject(
162 PMOS_COMMAND_BUFFER cmdBuffer,
163 PMHW_BATCH_BUFFER batchBuffer,
164 PMHW_MEDIA_OBJECT_PARAMS params) = 0;
165
166 //!
167 //! \brief Adds MEDIA_OBJECT_WALKER to the command buffer
168 //! \param cmdBuffer
169 //! [in] Command buffer to which HW command is added
170 //! \param params
171 //! [in] Params structure used to populate the HW command
172 //! \return MOS_STATUS
173 //! MOS_STATUS_SUCCESS if success, else fail reason
174 //!
175 virtual MOS_STATUS AddMediaObjectWalkerCmd(
176 PMOS_COMMAND_BUFFER cmdBuffer,
177 PMHW_WALKER_PARAMS params) = 0;
178
179 //!
180 //! \brief Adds GPGPU_WALKER to the command buffer
181 //! \param cmdBuffer
182 //! [in] Command buffer to which HW command is added
183 //! \param params
184 //! [in] Params structure used to populate the HW command
185 //! \return MOS_STATUS
186 //! MOS_STATUS_SUCCESS if success, else fail reason
187 //!
188 virtual MOS_STATUS AddGpGpuWalkerStateCmd(
189 PMOS_COMMAND_BUFFER cmdBuffer,
190 PMHW_GPGPU_WALKER_PARAMS params) = 0;
191
192 //!
193 //! \brief Adds 3DSTATE_CHROMA_KEY to the command buffer
194 //! \param cmdBuffer
195 //! [in] Command buffer to which HW command is added
196 //! \param params
197 //! [in] Params structure used to populate the HW command
198 //! \return MOS_STATUS
199 //! MOS_STATUS_SUCCESS if success, else fail reason
200 //!
201 virtual MOS_STATUS AddChromaKeyCmd(
202 PMOS_COMMAND_BUFFER cmdBuffer,
203 PMHW_CHROMAKEY_PARAMS params) = 0;
204
205 //!
206 //! \brief Adds 3DSTATE_SAMPLER_PALETTE_LOADX to the command buffer
207 //! \param cmdBuffer
208 //! [in] Command buffer to which HW command is added
209 //! \param params
210 //! [in] Params structure used to populate the HW command
211 //! \return MOS_STATUS
212 //! MOS_STATUS_SUCCESS if success, else fail reason
213 //!
214 virtual MOS_STATUS AddPaletteLoadCmd(
215 PMOS_COMMAND_BUFFER cmdBuffer,
216 PMHW_PALETTE_PARAMS params) = 0;
217
218 //!
219 //! \brief Adds STATE_SIP to the command buffer
220 //! \param cmdBuffer
221 //! [in] Command buffer to which HW command is added
222 //! \param params
223 //! [in] Params structure used to populate the HW command
224 //! \return MOS_STATUS
225 //! MOS_STATUS_SUCCESS if success, else fail reason
226 //!
227 virtual MOS_STATUS AddSipStateCmd(
228 PMOS_COMMAND_BUFFER cmdBuffer,
229 PMHW_SIP_STATE_PARAMS params) = 0;
230
231 //!
232 //! \brief Adds GPGPU_CSR_BASE_ADDRESS to the command buffer
233 //! \param cmdBuffer
234 //! [in] Command buffer to which HW command is added
235 //! \param csrResource
236 //! [in] Resource to be used for GPGPU CSR
237 //! \return MOS_STATUS
238 //! MOS_STATUS_SUCCESS if success, else fail reason
239 //!
240 virtual MOS_STATUS AddGpgpuCsrBaseAddrCmd(
241 PMOS_COMMAND_BUFFER cmdBuffer,
242 PMOS_RESOURCE csrResource) = 0;
243
244 //!
245 //! \brief get the size of hw command
246 //! \details Internal function to get the size of MEDIA_OBJECT_CMD
247 //! \return commandSize
248 //! The command size
249 //!
250 virtual uint32_t GetMediaObjectCmdSize() = 0;
251
252 //!
253 //! \brief Enables L3 cacheing flag and sets related registers/values
254 //! \param cacheSettings
255 //! [in] L3 Cache Configurations, if a null pointer is passed
256 //! in, it will use default settings.
257 //! \return MOS_STATUS
258 //! MOS_STATUS_SUCCESS if success, else fail reason
259 //!
260 virtual MOS_STATUS EnableL3Caching(
261 PMHW_RENDER_ENGINE_L3_CACHE_SETTINGS cacheSettings) = 0;
262
263 //!
264 //! \brief Setup L3 cache configuration for kernel workload
265 //! \details Enable L3 cacheing in kernel workload by configuring the
266 //! appropriate MMIO registers.
267 //! \param cmdBuffer
268 //! [in] Command buffer to which HW commands is added
269 //! \return MOS_STATUS
270 //! MOS_STATUS_SUCCESS if success, else fail reason
271 //!
272 virtual MOS_STATUS SetL3Cache(
273 PMOS_COMMAND_BUFFER cmdBuffer) = 0;
274
275 //!
276 //! \brief Enables preemption for media workloads on render engine
277 //! \details Sets the MMIO register for preemption so that HW can preempt
278 //! the submitted workload if required
279 //! \param cmdBuffer
280 //! [in] Command buffer to which HW commands is added
281 //! \return MOS_STATUS
282 //! MOS_STATUS_SUCCESS if success, else fail reason
283 //!
284 MOS_STATUS EnablePreemption(
285 PMOS_COMMAND_BUFFER cmdBuffer);
286
287 //!
288 //! \brief Accessor for m_l3CacheConfig
289 //! \return L3 cache configuration information
290 //!
291 virtual MHW_RENDER_ENGINE_L3_CACHE_CONFIG* GetL3CacheConfig() = 0;
292
293 //!
294 //! \brief Accessor for m_hwCaps, temporarily returns pointer to m_hwCaps until clients move to using not a pointer
295 //! \return Pointer to HW capabilities
296 //!
297 MHW_RENDER_ENGINE_CAPS *GetHwCaps() { return &m_hwCaps; }
298
299 //!
300 //! \brief Accessor for m_preemptionEnabled
301 //! \return true if preemption is enabled, false otherwise
302 //!
303 bool IsPreemptionEnabled() { return m_preemptionEnabled; }
304
305 //!
306 //! \brief Setter for os interface, used in MFE scenario
307 //! \return void
308 //!
309 void SetOsInterface(PMOS_INTERFACE osInterface) { m_osInterface = osInterface;}
310
311 //!
312 //! \brief Get mmio registers address
313 //! \details Get mmio registers address
314 //! \return [out] PMHW_MI_MMIOREGISTERS*
315 //! mmio registers got.
316 //!
317 virtual PMHW_MI_MMIOREGISTERS GetMmioRegisters() = 0;
318
319 //!
320 //! \brief Get AVS sampler state Inc unit
321 //! \details Get AVS sampler state Inc unit
322 //! \return [out] uint32_t
323 //! AVS sampler unit.
324 virtual uint32_t GetSamplerStateAVSIncUnit() = 0;
325
326 //!
327 //! \brief Get Conv sampler state Inc unit
328 //! \details Get Conv sampler state Inc unit
329 //! \return [out] uint32_t
330 //! Conv sampler unit.
331 virtual uint32_t GetSamplerStateConvIncUnit() = 0;
332
333 //!
334 //! \brief Get the sampler height and width align unit
335 //! \details NV12 format needs the width and height to be a multiple of some unit
336 //! \param [in] bool
337 //! true if AVS sampler, false otherwise
338 //! \param [in, out] uint32_t
339 //! weight align unit
340 //! \param [in, out] uint32_t
341 //! height align unit
342 virtual void GetSamplerResolutionAlignUnit(bool isAVSSampler, uint32_t &widthAlignUnit, uint32_t &heightAlignUnit) = 0;
343
344 //!
345 //! \brief Get new render interface, temporal solution before switching from
346 //! old interface to new one
347 //!
348 //! \return pointer to new render interface
349 //!
350 virtual std::shared_ptr<mhw::render::Itf> GetNewRenderInterface() { return nullptr; }
351
352 protected:
353 //!
354 //! \brief Initializes the Render interface
355 //! \details Internal MHW function to initialize all function pointers and some parameters
356 //! Assumes that the caller has checked pointer validity and whether or not an
357 //! addressing method has been selected in the OS interface (bUsesGfxAddress or
358 //! bUsesPatchList).
359 //! \param [in] miInterface
360 //! MI interface, must be valid
361 //! \param [in] osInterface
362 //! OS interface, must be valid
363 //! \param [in] gtSystemInfo
364 //! System information, must be valid
365 //! \param [in] newStateHeapManagerRequested
366 //! A new state heap manager was implemented for MDF, will be adapted for codec & VP,
367 //! migrated to C++, rolled into the existing state heap interface and removed.
368 //! Ultimately this parameter will no longer be necessary as the state heap interface
369 //! will be unified.
370 //!
371 MhwRenderInterface(
372 MhwMiInterface *miInterface,
373 PMOS_INTERFACE osInterface,
374 MEDIA_SYSTEM_INFO *gtSystemInfo,
375 uint8_t newStateHeapManagerRequested)
376 {
377 MHW_FUNCTION_ENTER;
378
379 if (miInterface == nullptr ||
380 osInterface == nullptr ||
381 gtSystemInfo == nullptr)
382 {
383 MHW_ASSERTMESSAGE("Invalid input pointers provided");
384 return;
385 }
386
387 if (!osInterface->bUsesGfxAddress && !osInterface->bUsesPatchList)
388 {
389 MHW_ASSERTMESSAGE("No valid addressing mode indicated");
390 return;
391 }
392
393 m_osInterface = osInterface;
394 m_miInterface = miInterface;
395 m_stateHeapInterface = nullptr;
396
397 memset(&m_hwCaps, 0, sizeof(m_hwCaps));
398
399 if (m_osInterface->bUsesGfxAddress)
400 {
401 AddResourceToCmd = Mhw_AddResourceToCmd_GfxAddress;
402 }
403 else // if (m_osInterface->bUsesPatchList)
404 {
405 AddResourceToCmd = Mhw_AddResourceToCmd_PatchList;
406 }
407
408 InitPlatformCaps(gtSystemInfo);
409
410 InitPreemption();
411
412 if (Mhw_StateHeapInterface_InitInterface_Legacy(
413 &m_stateHeapInterface,
414 m_osInterface,
415 newStateHeapManagerRequested) != MOS_STATUS_SUCCESS)
416 {
417 MHW_ASSERTMESSAGE("State heap initialization failed!");
418 return;
419 }
420 }
421
422 PMOS_INTERFACE m_osInterface = nullptr;
423 MEDIA_FEATURE_TABLE *m_skuTable = nullptr;
424 MhwMiInterface *m_miInterface = nullptr;
425
426 MHW_RENDER_ENGINE_L3_CACHE_CONFIG m_l3CacheConfig = {};
427 MHW_RENDER_ENGINE_CAPS m_hwCaps = {};
428
429 bool m_preemptionEnabled = false;
430 uint32_t m_preemptionCntlRegisterOffset = 0;
431 uint32_t m_preemptionCntlRegisterValue = 0;
432
433 uint32_t m_l3CacheCntlRegisterOffset = M_L3_CACHE_CNTL_REG_OFFSET;
434 uint32_t m_l3CacheCntlRegisterValueDefault = M_L3_CACHE_CNTL_REG_VALUE_DEFAULT;
435 std::shared_ptr <mhw::render::Itf> m_renderItfNew = nullptr;
436
437 //!
438 //! \brief Adds a resource to the command buffer or indirect state (SSH)
439 //! \details Internal MHW function to add either a graphics address of a resource or
440 //! add the resource to the patch list for the requested buffer or state
441 //! \param [in] osInterface
442 //! OS interface
443 //! \param [in] cmdBuffer
444 //! If adding a resource to the command buffer, the buffer to which the resource
445 //! is added
446 //! \param [in] params
447 //! Parameters necessary to add the graphics address
448 //! \return MOS_STATUS
449 //! MOS_STATUS_SUCCESS if success, else fail reason
450 //!
451 MOS_STATUS(*AddResourceToCmd) (
452 PMOS_INTERFACE osInterface,
453 PMOS_COMMAND_BUFFER cmdBuffer,
454 PMHW_RESOURCE_PARAMS params) = nullptr;
455
456 //!
457 //! \brief Initializes platform related capabilities for the render engine
458 //! \details Assumes the caller checked the pointers for validity.
459 //! \param gtSystemInfo
460 //! [in] Information concerning the GPU
461 //! \return void
462 //!
463 void InitPlatformCaps(
464 MEDIA_SYSTEM_INFO *gtSystemInfo);
465
466 //!
467 //! \brief Initializes preemption related registers/values
468 //! \details Initializes the MMIO register for preemption so that HW can preempt
469 //! the submitted workload if required.
470 //! \return void
471 //! If invalid SKU\WA tables detected, does not do anything
472 //!
473 void InitPreemption();
474 };
475
476 #endif // __MHW_RENDER_LEGACY_H__