1 /*
2 * Copyright (c) 2016-2021, 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       renderhal_g12_base.h
24 //! \brief      header file of Gen12 hardware functions
25 //! \details    Gen12 hardware functions declare
26 //!
27 #ifndef __RENDERHAL_G12_BASE_H__
28 #define __RENDERHAL_G12_BASE_H__
29 
30 #include <stddef.h>
31 #include <stdint.h>
32 #include "media_class_trace.h"
33 #include "mhw_state_heap.h"
34 #include "mos_defs.h"
35 #include "mos_os_specific.h"
36 #include "mos_os_virtualengine_specific.h"
37 #include "mos_resource_defs.h"
38 #include "renderhal.h"
39 #include "renderhal_platform_interface_legacy.h"
40 #include "mhw_render_g12_X.h"
41 #include "mhw_render_hwcmd_g12_X.h"
42 #include "mhw_state_heap_hwcmd_g12_X.h"
43 
44 struct MHW_VFE_PARAMS;
45 extern const uint32_t g_cLookup_RotationMode_g12[8];
46 
47 typedef struct _RENDERHAL_GENERIC_PROLOG_PARAMS_G12 : _RENDERHAL_GENERIC_PROLOG_PARAMS
48 {
49     MOS_VIRTUALENGINE_HINT_PARAMS          VEngineHintParams = {{0}, 0, {{0},{0},{0},{0}}, {0,0,0,0}};
50 }RENDERHAL_GENERIC_PROLOG_PARAMS_G12, *PRENDERHAL_GENERIC_PROLOG_PARAMS_G12;
51 
52 //! \brief      for Gen12LP VP and MDF
53 //!              SLM     URB     DC      RO      Rest/L3 Client Pool
54 //!               0      64      0       0       416 (KB chunks based on GT2)
55 #define RENDERHAL_L3_CACHE_CONFIG_CNTLREG_VALUE_G12LP_RENDERHAL (0xD0000020)
56 class XRenderHal_Interface_G12_Base : public XRenderHal_Platform_Interface_Legacy
57 {
58 public:
59     XRenderHal_Interface_G12_Base();
~XRenderHal_Interface_G12_Base()60     virtual ~XRenderHal_Interface_G12_Base() {}
61 
62     //!
63     //! \brief    Setup Surface State
64     //! \details  Setup Surface States for Gen12
65     //! \param    PRENDERHAL_INTERFACE pRenderHal
66     //!           [in] Pointer to Hardware Interface Structure
67     //! \param    PRENDERHAL_SURFACE pRenderHalSurface
68     //!           [in] Pointer to Render Hal Surface
69     //! \param    PRENDERHAL_SURFACE_STATE_PARAMS pParams
70     //!           [in] Pointer to Surface State Params
71     //! \param    int32_t *piNumEntries
72     //!           [out] Pointer to Number of Surface State Entries (Num Planes)
73     //! \param    PRENDERHAL_SURFACE_STATE_ENTRY * ppSurfaceEntries
74     //!           [out] Array of Surface State Entries
75     //! \param    PRENDERHAL_OFFSET_OVERRIDE pOffsetOverride
76     //!           [in] If not nullptr, provides adjustments to Y, UV plane offsets,
77     //!           used for kernel WA in a few cases. nullptr is the most common usage.
78     //! \return   MOS_STATUS
79     //!
80     MOS_STATUS SetupSurfaceState(
81         PRENDERHAL_INTERFACE            pRenderHal,
82         PRENDERHAL_SURFACE              pRenderHalSurface,
83         PRENDERHAL_SURFACE_STATE_PARAMS pParams,
84         int32_t                         *piNumEntries,
85         PRENDERHAL_SURFACE_STATE_ENTRY  *ppSurfaceEntries,
86         PRENDERHAL_OFFSET_OVERRIDE      pOffsetOverride);
87 
88     //!
89     //! \brief    Check if Sampler128Elements is supported
90     //! \return   true of false
91     //!
IsSampler128ElementsSupported()92     virtual inline bool IsSampler128ElementsSupported() { return true; }
93 
94     //!
95     //! \brief      Checks how per thread scratch space size bits in VFE state are interpreted by HW
96     //! \details    For BDW GT1/2/3 A0 steppings, per thread scratch space size in VFE state
97     //!             is 11 bits indicating [2k bytes, 2 Mbytes]: 0=2k, 1=4k, 2=8k ... 10=2M
98     //!             BDW+ excluding A0 step is 12 bits indicating [1k bytes, 2 Mbytes]: 0=1k, 1=2k, 2=4k, 3=8k ... 11=2M
99     //! \param      PRENDERHAL_INTERFACE pRenderHal
100     //!             [in]    Pointer to RenderHal interface
101     //! \return     true if BDW A0 stepping, false otherwise
102     //!
PerThreadScratchSpaceStart2K(PRENDERHAL_INTERFACE pRenderHal)103     bool PerThreadScratchSpaceStart2K(PRENDERHAL_INTERFACE pRenderHal)
104     {
105         MOS_UNUSED(pRenderHal);
106         return false;
107     }
108 
109     //!
110     //! \brief      Checks how per thread scratch space size bits in VFE state are interpreted by HW.
111     //! \details    per thread scratch space size can be 2^n (n >= 6) bytes.
112     //! \param      PRENDERHAL_INTERFACE pRenderHal
113     //!             [in]    Pointer to RenderHal interface
114     //! \return     bool.
115     //!
PerThreadScratchSpaceStart64Byte(RENDERHAL_INTERFACE * renderHal)116     virtual bool PerThreadScratchSpaceStart64Byte(
117         RENDERHAL_INTERFACE *renderHal)
118     {
119         return false;
120     }
121 
122 
123     //!
124     //! \brief    Encode SLM Size for Interface Descriptor
125     //! \details  Setup SLM size
126     //! \param    uint32_t SLMSize
127     //!           [in] SLM size in 1K
128     //! \return   encoded output
129     //!
130     uint32_t EncodeSLMSize(uint32_t SLMSize);
131 
132     //!
133     //! \brief    Set Chroma Direction
134     //! \details  Setup Chroma Direction for G12
135     //! \param    PRENDERHAL_INTERFACE pRenderHal
136     //!           [in]  Pointer to Hardware Interface
137     //! \param    PRENDERHAL_SURFACE pRenderHalSurface
138     //!           [in]  Pointer to Render Hal Surface
139     //! \return   uint8_t
140     //!
141     uint8_t SetChromaDirection(
142         PRENDERHAL_INTERFACE pRenderHal,
143         PRENDERHAL_SURFACE   pRenderHalSurface);
144 
145     //!
146     //! \brief    Convert To Nano Seconds
147     //! \details  Convert to Nano Seconds
148     //! \param    PRENDERHAL_INTERFACE pRenderHal
149     //!           [in] Pointer to Hardware Interface Structure
150     //! \param    uint64_t iTicks
151     //!           [in] Ticks
152     //! \param    uint64_t *piNs
153     //!           [in] Nano Seconds
154     //! \return   void
155     //!
156     void ConvertToNanoSeconds(
157         PRENDERHAL_INTERFACE    pRenderHal,
158         uint64_t                iTicks,
159         uint64_t                *piNs);
160 
161     //!
162     //! \brief    Initialize the State Heap Settings per platform
163     //! \param    PRENDERHAL_INTERFACE    pRenderHal
164     //!           [out] Pointer to PRENDERHAL_INTERFACE
165     //! \return   void
166     //!
167     void InitStateHeapSettings(
168         PRENDERHAL_INTERFACE    pRenderHal);
169 
170     //!
171     //! \brief    Initialize the default surface type and advanced surface type  per platform
172     //! \param    PRENDERHAL_INTERFACE    pRenderHal
173     //!           [out] Pointer to PRENDERHAL_INTERFACE
174     //! \return   void
175     //!
176     void InitSurfaceTypes(
177         PRENDERHAL_INTERFACE    pRenderHal);
178 
179     //!
180     //! \brief    Check if YV12 Single Pass is supported
181     //! \param    PRENDERHAL_INTERFACE pRenderHal
182     //!           [in]  Pointer to Hardware Interface
183     //! \return   true of false
184     //!
IsEnableYV12SinglePass(PRENDERHAL_INTERFACE pRenderHal)185     inline bool IsEnableYV12SinglePass(
186         PRENDERHAL_INTERFACE    pRenderHal)
187     {
188         MOS_UNUSED(pRenderHal);
189         return true;
190     }
191 
192     //!
193     //! \brief     Get the Size of AVS Sampler State
194     //! \param    PRENDERHAL_INTERFACE pRenderHal
195     //!           [in]  Pointer to Hardware Interface
196     //! \return   size
197     //!
GetSizeSamplerStateAvs(PRENDERHAL_INTERFACE pRenderHal)198     inline uint32_t GetSizeSamplerStateAvs(
199         PRENDERHAL_INTERFACE    pRenderHal)
200     {
201         if (pRenderHal && pRenderHal->pHwSizes)
202         {
203             return 2 * pRenderHal->pHwSizes->dwSizeSamplerStateAvs;  // Kernel using 1,3,5 sampler index for AVS sampler state.
204         }
205         else
206         {
207             MHW_RENDERHAL_ASSERTMESSAGE("Failed to get SizeSamplerStateAvs");
208             return 0;
209         }
210     }
211 
212     //!
213     //! \brief    Enables L3 cacheing flag and sets related registers/values
214     //! \param    PRENDERHAL_INTERFACE    pRenderHal
215     //!           [in]  Pointer to Hardware Interface
216     //! \param    pCacheSettings
217     //!           [in] L3 Cache Configurations
218     //! \return   MOS_STATUS
219     //!           MOS_STATUS_SUCCESS if success, else fail reason
220     //!
221     virtual MOS_STATUS EnableL3Caching(
222         PRENDERHAL_INTERFACE         pRenderHal,
223         PRENDERHAL_L3_CACHE_SETTINGS pCacheSettings);
224 
225     //!
226     //! \brief    Get offset and/or pointer to sampler state
227     //! \details  Get offset and/or pointer to sampler state in General State Heap
228     //! \param    PRENDERHAL_INTERFACE pRenderHal
229     //!           [in] Pointer to RenderHal Interface
230     //! \param    int32_t iMediaID
231     //!           [in] Media ID associated with sampler
232     //! \param    int32_t iSamplerID
233     //!           [in] Sampler ID
234     //! \param    uint32_t *pdwSamplerOffset
235     //!           [out] optional; offset of sampler state from GSH base
236     //! \param    void  **ppSampler
237     //!           [out] optional; pointer to sampler state in GSH
238     //! \return   MOS_STATUS
239     //!
240     virtual MOS_STATUS GetSamplerOffsetAndPtr_DSH(
241         PRENDERHAL_INTERFACE     pRenderHal,
242         int32_t                  iMediaID,
243         int32_t                  iSamplerID,
244         PMHW_SAMPLER_STATE_PARAM pSamplerParams,
245         uint32_t                 *pdwSamplerOffset,
246         void                    **ppSampler);
247 
248     //!
249     //! \brief      Initialize the DSH Settings
250     //! \details    Initialize the structure DynamicHeapSettings in pRenderHal
251     //! \param      PRENDERHAL_INTERFACE pRenderHal
252     //!             [in]    Pointer to HW interface
253     //! \return     void
254     //!
255     virtual void InitDynamicHeapSettings(
256         PRENDERHAL_INTERFACE  pRenderHal);
257 
258     //!
259     //! \brief      Get the pointer to the MHW_VFE_PARAMS
260     //! \return     MHW_VFE_PARAMS*
261     //!             pointer to the MHW_VFE_PARAMS
262     //!
GetVfeStateParameters()263     virtual MHW_VFE_PARAMS* GetVfeStateParameters() { return &m_vfeStateParams; }
264 
265     //!
266     //! \brief      enable/disable the fusedEUDispatch flag in the VFE_PARAMS
267     //! \return     no return value
268     //!
269     virtual void SetFusedEUDispatch(bool enable);
270 
271     //!
272     //! \brief      set the number of walkers in the VFE_PARAMS
273     //! \return     MOS_STATUS_SUCCESS
274     //!
275     MOS_STATUS SetNumOfWalkers(uint32_t numOfWalkers);
276 
277     //!
278     //! \brief      enable/disable the single slice dispatch flag in the VFE_PARAMS
279     //! \return     no return value
280     //!
SetSingleSliceDispatchCcsMode(bool enable)281     void SetSingleSliceDispatchCcsMode(bool enable)
282     {
283         m_vfeStateParams.enableSingleSliceDispatchCcsMode = enable;
284     };
285 
286     //!
287     //! \brief    Set Power Option Status
288     //! \param    [in] pRenderHal
289     //!           Pointer to Hardware Interface
290     //! \param    [in,out] pCmdBuffer
291     //!           Pointer to Command Buffer
292     //! \return   MOS_STATUS
293     //!           MOS_STATUS_SUCCESS if success, else fail reason
294     //!
295     virtual MOS_STATUS SetPowerOptionStatus(
296         PRENDERHAL_INTERFACE         pRenderHal,
297         PMOS_COMMAND_BUFFER          pCmdBuffer);
298 
299     //!
300     //! \brief    Set Composite Prolog CMD
301     //! \param    [in] pRenderHal
302     //!           Pointer to Hardware Interface
303     //! \param    [in,out] pCmdBuffer
304     //!           Pointer to Command Buffer
305     //! \return   MOS_STATUS
306     //!           MOS_STATUS_SUCCESS if success, else fail reason
307     //!
308     virtual MOS_STATUS SetCompositePrologCmd(
309         PRENDERHAL_INTERFACE         pRenderHal,
310         PMOS_COMMAND_BUFFER          pCmdBuffer);
311 
312     //!
313     //! \brief    Get Render Engine MMC Enable/Disable Flag
314     //! \param    [in] pRenderHal
315     //!           Pointer to Hardware Interface
316     //! \return   MOS_STATUS
317     //!           MOS_STATUS_SUCCESS if success, else fail reason
318     //!
319     virtual MOS_STATUS IsRenderHalMMCEnabled(
320         PRENDERHAL_INTERFACE         pRenderHal);
321 
322     //!
323     //! \brief    Check if Over ride is needed or not
324     //! \param    [in] pRenderHal
325     //!           Pointer to Hardware Interface
326     //! \param    [in,out] pCmdBuffer
327     //!           Pointer to Command Buffer
328     //! \param    [in] pGenericPrologParam
329     //!           Pointer to MHW generic prolog parameters
330     //! \return   MOS_STATUS
331     //!           MOS_STATUS_SUCCESS if success, else fail reason
332     //!
333     virtual MOS_STATUS IsOvrdNeeded(
334         PRENDERHAL_INTERFACE              pRenderHal,
335         PMOS_COMMAND_BUFFER               pCmdBuffer,
336         PRENDERHAL_GENERIC_PROLOG_PARAMS  pGenericPrologParams);
337 
338     //! \brief      Set L3 cache override config parameters
339     //! \param      [in] pRenderHal
340     //!             Pointer to RenderHal Interface Structure
341     //! \param      [in,out] pCacheSettings
342     //!             Pointer to pCacheSettings
343     //! \param      [in] bEnableSLM
344     //!             Flag to enable SLM
345     //! \return     MOS_STATUS
346     //!             MOS_STATUS_SUCCESS if success. Error code otherwise
347     //!
348     virtual MOS_STATUS SetCacheOverrideParams(
349         PRENDERHAL_INTERFACE            pRenderHal,
350         PRENDERHAL_L3_CACHE_SETTINGS    pCacheSettings,
351         bool                            bEnableSLM);
352 
353     //! \brief      Get the size of Render Surface State Command
354     //! \return     size_t
355     //!             the size of render surface state command
356     virtual size_t GetSurfaceStateCmdSize();
357 
358     //! \brief      Get the address of the ith Palette Data
359     //! \param      [in] i
360     //!             Index of the palette data
361     //! \return     void *
362     //!             address of the ith palette data table
GetPaletteDataAddress(int i)363     virtual void* GetPaletteDataAddress(int i) {return &m_paletteData[i];}
364 
365     //! \brief      Get the size of Binding Table State Command
366     //! \return     size_t
367     //!             the size of binding table state command
GetBTStateCmdSize()368     virtual size_t GetBTStateCmdSize() {return mhw_state_heap_g12_X::BINDING_TABLE_STATE_CMD::byteSize;}
369 
370     //! \brief      Get Surface Compression support caps
371     //! \param      [in] format
372     //!             surface format
373     //! \return     bool
374     //!             true or false
375     bool IsFormatMMCSupported(MOS_FORMAT format);
376 
377     //! \brief    Check if compute context in use
378     //! \param    PRENDERHAL_INTERFACE    pRenderHal
379     //!           [in]  Pointer to Hardware Interface
380     //! \return   true of false
IsComputeContextInUse(PRENDERHAL_INTERFACE pRenderHal)381     virtual bool IsComputeContextInUse(PRENDERHAL_INTERFACE pRenderHal)
382     {
383         return false;
384     }
385 
386     //! \brief    Allocates scratch space buffer.
387     //! \details  A single scratch space buffer is allocated and used for all threads.
388     virtual MOS_STATUS AllocateScratchSpaceBuffer(
389         uint32_t perThreadScratchSpace,
390         RENDERHAL_INTERFACE *renderHal);
391 
392     //! \brief    Sets states of scratch space buffer.
393     //! \param    Pointer to RENDERHAL_INTERFACE renderHal
394     //!           [in] Pointer to render HAL Interface.
395     //! \param    indexOfBindingTable
396     //!           [in] Index of the binding table in use.
397     //! \return   MOS_STATUS
398     MOS_STATUS SetScratchSpaceBufferState(
399         RENDERHAL_INTERFACE *renderHal,
400         uint32_t indexOfBindingTable);
401 
402     //! \brief    Frees scratch space buffer.
403     //! \details  A single scratch space buffer is allocated and used for all threads.
404     virtual MOS_STATUS FreeScratchSpaceBuffer(
405         RENDERHAL_INTERFACE *renderHal);
406 
407 protected:
408     MHW_VFE_PARAMS_G12 m_vfeStateParams;
409 
410     mhw_render_g12_X::PALETTE_ENTRY_CMD
411     m_paletteData[RENDERHAL_PALETTE_MAX][RENDERHAL_PALETTE_ENTRIES_MAX];
412 
413     bool m_renderHalMMCEnabled = false;
414 
415     MOS_RESOURCE m_scratchSpaceResource;
416 MEDIA_CLASS_DEFINE_END(XRenderHal_Interface_G12_Base)
417 };
418 
419 #endif // __RENDERHAL_G12_BASE_H__
420