1 /*
2 * Copyright (c) 2012-2019, 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_g9.cpp
24 //! \brief      implementation of Gen9 hardware functions
25 //! \details    Render functions
26 //!
27 
28 #include "mos_os.h"
29 #include "renderhal.h"
30 #include "renderhal_g9.h"
31 
32 #define RENDERHAL_NS_PER_TICK_RENDER_G9        (83.333)                                  // For SKL, 83.333 nano seconds per tick in render engine
33 #define RENDERHAL_NS_PER_TICK_RENDER_G9LP        (52.083)                               //For BXT, 52.083 nano seconds per tick in render engine
34 
35 //!
36 //! \brief      GSH settings for G9
37 //!
38 const RENDERHAL_STATE_HEAP_SETTINGS g_cRenderHal_State_Heap_Settings_g9 =
39 {
40     // Global GSH Allocation parameters
41     RENDERHAL_SYNC_SIZE,                        //!< iSyncSize
42 
43     // Media State Allocation parameters
44     RENDERHAL_MEDIA_STATES,                     //!< iMediaStateHeaps - Set by Initialize
45     RENDERHAL_MEDIA_IDS,                        //!< iMediaIDs
46     RENDERHAL_CURBE_SIZE,                       //!< iCurbeSize
47     RENDERHAL_SAMPLERS,                         //!< iSamplers
48     RENDERHAL_SAMPLERS_AVS_G9,                  //!< iSamplersAVS
49     RENDERHAL_SAMPLERS_VA,                      //!< iSamplersVA
50     RENDERHAL_KERNEL_COUNT,                     //!< iKernelCount
51     RENDERHAL_KERNEL_HEAP,                      //!< iKernelHeapSize
52     RENDERHAL_KERNEL_BLOCK_SIZE,                //!< iKernelBlockSize
53 
54     // Media VFE/ID configuration, limits
55     0,                                          //!< iPerThreadScratchSize
56     RENDERHAL_MAX_SIP_SIZE,                     //!< iSipSize
57 
58     // Surface State Heap Settings
59     RENDERHAL_SSH_INSTANCES,                    //!< iSurfaceStateHeaps
60     RENDERHAL_SSH_BINDING_TABLES,               //!< iBindingTables
61     RENDERHAL_SSH_SURFACE_STATES,               //!< iSurfaceStates
62     RENDERHAL_SSH_SURFACES_PER_BT,              //!< iSurfacesPerBT
63     RENDERHAL_SSH_BINDING_TABLE_ALIGN           //!< iBTAlignment
64 };
65 
66 const uint32_t g_cLookup_RotationMode_g9[8] =
67 {
68     ROTATION_IDENTITY,  // 0 - MHW_ROTATION_IDENTITY
69     ROTATION_90,        // 1 - MHW_ROTATION_90
70     ROTATION_180,       // 2 - MHW_ROTATION_180
71     ROTATION_270,       // 3 - MHW_ROTATION_270
72     ROTATION_IDENTITY,  // 4 - MHW_MIRROR_HORIZONTAL
73     ROTATION_180,       // 5 - MHW_MIRROR_VERTICAL
74     ROTATION_270,       // 6 - MHW_ROTATE_90_MIRROR_VERTICAL
75     ROTATION_90         // 7 - MHW_ROTATE_90_MIRROR_HORIZONTAL
76 };
77 
78 //!
79 //! DSH State Heap settings for G9
80 //!
81 const RENDERHAL_DYN_HEAP_SETTINGS g_cRenderHal_DSH_Settings_g9 =
82 {
83     0x0080000,  // dwDshInitialSize    = 512kB
84     0x0080000,  // dwDshSizeIncrement  = 512kB
85     0x8000000,  // dwDshMaximumSize    = 128MB
86     0x0040000,  // dwIshInitialSize    = 256kB
87     0x0040000,  // dwIshSizeIncrement  = 256kB
88     0x0400000,  // dwIshMaximumSize    = 4MB
89     16,         // iMinMediaStates
90     1024,       // iMaxMediaStates
91     16,         // iMinKernels
92     1024        // iMaxKernels
93 };
94 
95 //!
96 //! \brief    Setup Surface State
97 //! \details  Setup Surface State for Gen9
98 //! \param    PRENDERHAL_INTERFACE pRenderHal
99 //!           [in] Pointer to Hardware Interface Structure
100 //! \param    PRENDERHAL_SURFACE pRenderHalSurface
101 //!           [in] Pointer to Render Hal Surface
102 //! \param    PRENDERHAL_SURFACE_STATE_PARAMS pParams
103 //!           [in]  Pointer to Surface State Params
104 //! \param    int32_t *piNumEntries
105 //!           [out] Pointer to Number of Surface State Entries (Num Planes)
106 //! \param    PRENDERHAL_SURFACE_STATE_ENTRY * ppSurfaceEntries
107 //!           [out] Array of Surface State Entries
108 //! \param    PRENDERHAL_OFFSET_OVERRIDE pOffsetOverride
109 //!           [in] Ignored (not used in Gen9)
110 //! \return   MOS_STATUS
111 //!
SetupSurfaceState(PRENDERHAL_INTERFACE pRenderHal,PRENDERHAL_SURFACE pRenderHalSurface,PRENDERHAL_SURFACE_STATE_PARAMS pParams,int32_t * piNumEntries,PRENDERHAL_SURFACE_STATE_ENTRY * ppSurfaceEntries,PRENDERHAL_OFFSET_OVERRIDE pOffsetOverride)112 MOS_STATUS XRenderHal_Interface_g9::SetupSurfaceState (
113     PRENDERHAL_INTERFACE             pRenderHal,
114     PRENDERHAL_SURFACE               pRenderHalSurface,
115     PRENDERHAL_SURFACE_STATE_PARAMS  pParams,
116     int32_t                          *piNumEntries,
117     PRENDERHAL_SURFACE_STATE_ENTRY  *ppSurfaceEntries,
118     PRENDERHAL_OFFSET_OVERRIDE       pOffsetOverride)
119 {
120     PRENDERHAL_SURFACE_STATE_ENTRY  pSurfaceEntry;
121     PMOS_PLANE_OFFSET               pPlaneOffset;
122     MHW_SURFACE_STATE_PARAMS        SurfStateParams;
123     PMOS_SURFACE                    pSurface;
124     int32_t                         i;
125     uint32_t                        dwPixelsPerSampleUV;
126     uint32_t                        dwSurfaceSize;
127     MOS_STATUS                      eStatus = MOS_STATUS_UNKNOWN;
128 
129     //-----------------------------------------
130     MHW_RENDERHAL_UNUSED(pOffsetOverride);
131     MHW_RENDERHAL_CHK_NULL(pRenderHal);
132     MHW_RENDERHAL_CHK_NULL(pRenderHalSurface);
133     MHW_RENDERHAL_CHK_NULL(pParams);
134     MHW_RENDERHAL_CHK_NULL(ppSurfaceEntries);
135     MHW_RENDERHAL_CHK_NULL(pRenderHal->pStateHeap);
136     MHW_RENDERHAL_CHK_NULL(pRenderHal->pHwSizes);
137     MHW_RENDERHAL_CHK_NULL(pRenderHal->pMhwStateHeap);
138     MHW_RENDERHAL_ASSERT(pRenderHalSurface->Rotation >= 0 && pRenderHalSurface->Rotation < 8);
139     //-----------------------------------------
140 
141     dwSurfaceSize = pRenderHal->pHwSizes->dwSizeSurfaceState;
142 
143     MOS_ZeroMemory(&SurfStateParams, sizeof(SurfStateParams));
144 
145     // Get the Surface State Entries
146     MHW_RENDERHAL_CHK_STATUS(pRenderHal->pfnGetSurfaceStateEntries(
147             pRenderHal,
148             pRenderHalSurface,
149             pParams,
150             piNumEntries,
151             ppSurfaceEntries));
152 
153     for (i = 0; i < *piNumEntries; i++)
154     {
155         // Pointer to surface state entry for current plane
156         pSurfaceEntry = ppSurfaceEntries[i];
157 
158         pSurface = pSurfaceEntry->pSurface;
159 
160         // Set the Surface State Offset from base of SSH
161         pSurfaceEntry->dwSurfStateOffset = pRenderHal->pStateHeap->iSurfaceStateOffset +                // Offset to Base Of Current Surface State Area
162                                            pSurfaceEntry->iSurfStateID * dwSurfaceSize;                 // Offset  to Surface State within the area
163 
164         // Obtain the Pointer to the Surface state from SSH Buffer
165         SurfStateParams.pSurfaceState         = pSurfaceEntry->pSurfaceState;
166         SurfStateParams.bUseAdvState          = pSurfaceEntry->bAVS;
167         SurfStateParams.dwWidth               = pSurfaceEntry->dwWidth;
168         SurfStateParams.dwHeight              = pSurfaceEntry->dwHeight;
169         SurfStateParams.dwFormat              = pSurfaceEntry->dwFormat;
170         SurfStateParams.dwPitch               = pSurfaceEntry->dwPitch;
171         SurfStateParams.dwQPitch              = pSurfaceEntry->dwQPitch;
172         SurfStateParams.bTiledSurface         = pSurfaceEntry->bTiledSurface;
173         SurfStateParams.bTileWalk             = pSurfaceEntry->bTileWalk;
174         SurfStateParams.dwCacheabilityControl = pRenderHal->pfnGetSurfaceMemoryObjectControl(pRenderHal, pParams);
175         SurfStateParams.bCompressionEnabled   = pSurface->bIsCompressed;
176         SurfStateParams.bCompressionMode      = (pSurface->CompressionMode == MOS_MMC_VERTICAL) ? 1 : 0;
177         SurfStateParams.RotationMode          = g_cLookup_RotationMode_g9[pRenderHalSurface->Rotation];
178 
179         if (pSurfaceEntry->bAVS)
180         {
181             SurfStateParams.bHalfPitchChroma        = pSurfaceEntry->bHalfPitchChroma;
182             SurfStateParams.bInterleaveChroma       = pSurfaceEntry->bInterleaveChroma;
183             SurfStateParams.UVPixelOffsetUDirection = pSurfaceEntry->DirectionU;
184             SurfStateParams.UVPixelOffsetVDirection = pSurfaceEntry->DirectionV;
185 
186             // On SNB+, when VDI Walker is enabled, Input surface width should be 16 pixel aligned
187             if (pParams->bWidth16Align)
188             {
189                 SurfStateParams.dwWidth = MOS_ALIGN_CEIL(pSurfaceEntry->dwWidth, 16);
190             }
191 
192             if (pSurfaceEntry->YUVPlane == MHW_U_PLANE)         // AVS U plane
193             {
194                 // Lockoffset is the offset from base address of Y plane to the origin of U/V plane.
195                 // So, We can get XOffsetforU by Lockoffset % pSurface->dwPitch, and get YOffsetForU by Lockoffset / pSurface->dwPitch
196                 SurfStateParams.dwXOffsetForU = (uint32_t)pSurface->UPlaneOffset.iLockSurfaceOffset % pSurface->dwPitch;
197                 SurfStateParams.dwYOffsetForU = (uint32_t)pSurface->UPlaneOffset.iLockSurfaceOffset / pSurface->dwPitch;
198                 SurfStateParams.dwXOffsetForV = 0;
199                 SurfStateParams.dwYOffsetForV = 0;
200                 SurfStateParams.iXOffset      = pSurface->UPlaneOffset.iXOffset;
201                 SurfStateParams.iYOffset      = pSurface->UPlaneOffset.iYOffset;
202             }
203             else if (pSurfaceEntry->YUVPlane == MHW_V_PLANE)    // AVS V plane
204             {
205                 SurfStateParams.dwXOffsetForU = 0;
206                 SurfStateParams.dwYOffsetForU = 0;
207                 SurfStateParams.dwXOffsetForV = (uint32_t)pSurface->VPlaneOffset.iLockSurfaceOffset % pSurface->dwPitch;
208                 SurfStateParams.dwYOffsetForV = (uint32_t)pSurface->VPlaneOffset.iLockSurfaceOffset / pSurface->dwPitch;
209                 SurfStateParams.iXOffset      = pSurface->VPlaneOffset.iXOffset;
210                 SurfStateParams.iYOffset      = pSurface->VPlaneOffset.iYOffset;
211             }
212             else // AVS/DNDI Y plane
213             {
214                 SurfStateParams.dwXOffsetForU = pSurfaceEntry->wUXOffset;
215                 SurfStateParams.dwYOffsetForU = pSurfaceEntry->wUYOffset;
216                 SurfStateParams.dwXOffsetForV = pSurfaceEntry->wVXOffset;
217                 SurfStateParams.dwYOffsetForV = pSurfaceEntry->wVYOffset;
218                 SurfStateParams.iXOffset      = 0;
219                 SurfStateParams.iYOffset      = pSurface->YPlaneOffset.iYOffset;
220             }
221             if (pRenderHalSurface->bInterlacedScaling)
222             {
223                 SurfStateParams.bVerticalLineStrideOffset = pSurfaceEntry->bVertStrideOffs;
224                 SurfStateParams.bVerticalLineStride       = pSurfaceEntry->bVertStride;
225             }
226         }
227         else // 2D/3D Surface (non-AVS)
228         {
229             SurfStateParams.SurfaceType3D             = (pSurface->dwDepth > 1) ?
230                                                            GFX3DSTATE_SURFACETYPE_3D :
231                                                            GFX3DSTATE_SURFACETYPE_2D;
232             SurfStateParams.dwDepth                   = MOS_MAX(1, pSurface->dwDepth);
233             SurfStateParams.bVerticalLineStrideOffset = pSurfaceEntry->bVertStrideOffs;
234             SurfStateParams.bVerticalLineStride       = pSurfaceEntry->bVertStride;
235             SurfStateParams.bHalfPitchChroma          = pSurfaceEntry->bHalfPitchChroma;
236 
237             // Setup surface g9 surface state
238             if (pSurfaceEntry->YUVPlane == MHW_U_PLANE ||
239                 pSurfaceEntry->YUVPlane == MHW_V_PLANE)
240             {
241                 pPlaneOffset = (pSurfaceEntry->YUVPlane == MHW_U_PLANE) ?
242                                 &pSurface->UPlaneOffset : &pSurface->VPlaneOffset;
243 
244                 // Get Pixels Per Sample if we use dataport read
245                 if(pParams->bWidthInDword_UV)
246                 {
247                     RenderHal_GetPixelsPerSample(pSurface->Format, &dwPixelsPerSampleUV);
248                 }
249                 else
250                 {
251                     // If the kernel uses sampler - do not change width (it affects coordinates)
252                     dwPixelsPerSampleUV = 1;
253                 }
254 
255                 if(dwPixelsPerSampleUV == 1)
256                 {
257                     SurfStateParams.iXOffset = pPlaneOffset->iXOffset;
258                 }
259                 else
260                 {
261                     SurfStateParams.iXOffset = pPlaneOffset->iXOffset/sizeof(uint32_t);
262                 }
263 
264                 SurfStateParams.iYOffset = pPlaneOffset->iYOffset;
265             }
266             else // Y plane
267             {
268                 pPlaneOffset = &pSurface->YPlaneOffset;
269 
270                 SurfStateParams.iXOffset = pPlaneOffset->iXOffset/sizeof(uint32_t);
271                 SurfStateParams.iYOffset = pPlaneOffset->iYOffset;
272 
273                 if((pSurfaceEntry->YUVPlane == MHW_Y_PLANE) &&
274                    (pSurfaceEntry->dwFormat == MHW_GFX3DSTATE_SURFACEFORMAT_PLANAR_420_8))
275                 {
276                     if (pSurface->Format == Format_YV12)
277                     {
278                         SurfStateParams.bSeperateUVPlane = true;
279                         SurfStateParams.dwXOffsetForU    = 0;
280                         SurfStateParams.dwYOffsetForU    = pSurface->dwHeight * 2 + pSurface->dwHeight / 2;
281                         SurfStateParams.dwXOffsetForV    = 0;
282                         SurfStateParams.dwYOffsetForV    = pSurface->dwHeight * 2;
283                     }
284                     else
285                     {
286                         SurfStateParams.bSeperateUVPlane = false;
287                         SurfStateParams.dwXOffsetForU    = 0;
288                         SurfStateParams.dwYOffsetForU    = (uint32_t)((pSurface->UPlaneOffset.iSurfaceOffset - pSurface->YPlaneOffset.iSurfaceOffset) / pSurface->dwPitch) + pSurface->UPlaneOffset.iYOffset;
289                         SurfStateParams.dwXOffsetForV    = 0;
290                         SurfStateParams.dwYOffsetForV    = 0;
291                     }
292                 }
293             }
294         }
295 
296         // Call MHW to setup the Surface State Heap entry
297         MHW_RENDERHAL_CHK_STATUS(pRenderHal->pMhwStateHeap->SetSurfaceStateEntry(&SurfStateParams));
298 
299         // Setup OS specific states
300         MHW_RENDERHAL_CHK_STATUS(pRenderHal->pfnSetupSurfaceStatesOs(pRenderHal, pParams, pSurfaceEntry));
301     }
302 
303     eStatus = MOS_STATUS_SUCCESS;
304 
305 finish:
306     return eStatus;
307 }
308 
309 //!
310 //! \brief    Encode SLM Size for Interface Descriptor
311 //! \details  Setup SLM size
312 //! \param    uint32_t SLMSize
313 //!           [in] SLM size in 1K
314 //! \return   encoded output
315 //!
EncodeSLMSize(uint32_t SLMSize)316 uint32_t XRenderHal_Interface_g9::EncodeSLMSize(uint32_t SLMSize)
317 {
318     uint32_t EncodedValue;
319     if (SLMSize <= 2)
320         EncodedValue = SLMSize;
321     else
322     {
323         EncodedValue = 0;
324         do
325         {
326             SLMSize >>= 1;
327             EncodedValue++;
328         } while (SLMSize);
329     }
330     return EncodedValue;
331 }
332 
333 //!
334 //! \brief      Setup Chroma direction for Gen9
335 //! \details    Setup Chroma direction
336 //! \param      PRENDERHAL_INTERFACE pRenderHal
337 //!             [in]    Pointer to RenderHal Interface
338 //! \param      PRENDERHAL_SURFACE pRenderHalSurface
339 //!             [in]    Pointer to RenderHal Surface
340 //! \return     uint8_t
341 //!
SetChromaDirection(PRENDERHAL_INTERFACE pRenderHal,PRENDERHAL_SURFACE pRenderHalSurface)342 uint8_t XRenderHal_Interface_g9::SetChromaDirection(
343     PRENDERHAL_INTERFACE pRenderHal,
344     PRENDERHAL_SURFACE   pRenderHalSurface)
345 {
346     MHW_RENDERHAL_UNUSED(pRenderHal);
347     uint8_t Direction;
348 
349     MHW_RENDERHAL_ASSERT(pRenderHal);
350     MHW_RENDERHAL_ASSERT(pRenderHalSurface);
351 
352     Direction = 0;
353 
354     if (pRenderHalSurface->ChromaSiting & MHW_CHROMA_SITING_HORZ_CENTER)
355     {
356         Direction = CHROMA_SITING_UDIRECTION_CENTER;
357     }
358     else
359     {
360         Direction = CHROMA_SITING_UDIRECTION_LEFT;
361     }
362 
363     // Combined U/V direction together in one uint8_t, 1 bit for U direction, 3 bits for V direction.
364     Direction = Direction << 3;
365 
366     if (pRenderHalSurface->pDeinterlaceParams || pRenderHalSurface->bQueryVariance)
367     {
368         if ((pRenderHalSurface->SampleType == RENDERHAL_SAMPLE_INTERLEAVED_EVEN_FIRST_BOTTOM_FIELD) ||
369             (pRenderHalSurface->SampleType == RENDERHAL_SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD))
370         {
371             if (pRenderHalSurface->ChromaSiting & MHW_CHROMA_SITING_VERT_TOP)
372             {
373                 Direction |= CHROMA_SITING_VDIRECTION_1_2;
374             }
375             else if (pRenderHalSurface->ChromaSiting & MHW_CHROMA_SITING_VERT_BOTTOM)
376             {
377                 Direction |= CHROMA_SITING_VDIRECTION_1;
378             }
379             else
380             {
381                 Direction |= CHROMA_SITING_VDIRECTION_3_4;
382             }
383         }
384         else if ((pRenderHalSurface->SampleType == RENDERHAL_SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD) ||
385             (pRenderHalSurface->SampleType == RENDERHAL_SAMPLE_INTERLEAVED_ODD_FIRST_TOP_FIELD))
386         {
387             if (pRenderHalSurface->ChromaSiting & MHW_CHROMA_SITING_VERT_TOP)
388             {
389                 Direction |= CHROMA_SITING_VDIRECTION_0;
390             }
391             else if (pRenderHalSurface->ChromaSiting & MHW_CHROMA_SITING_VERT_BOTTOM)
392             {
393                 Direction |= CHROMA_SITING_VDIRECTION_1_2;
394             }
395             else
396             {
397                 Direction |= CHROMA_SITING_VDIRECTION_1_4;
398             }
399         }
400     }
401     else
402     {
403         if (pRenderHalSurface->ChromaSiting & MHW_CHROMA_SITING_VERT_TOP)
404         {
405             Direction |= CHROMA_SITING_VDIRECTION_0;
406         }
407         else if (pRenderHalSurface->ChromaSiting & MHW_CHROMA_SITING_VERT_BOTTOM)
408         {
409             Direction |= CHROMA_SITING_VDIRECTION_1;
410         }
411         else
412         {
413             Direction |= CHROMA_SITING_VDIRECTION_1_2;
414         }
415     }
416 
417     return Direction;
418 }
419 
420 //!
421 //! \brief    Convert To Nano Seconds
422 //! \details  Convert to Nano Seconds
423 //! \param    PRENDERHAL_INTERFACE pRenderHal
424 //!           [in] Pointer to Hardware Interface Structure
425 //! \param    uint64_t iTicks
426 //!           [in] Ticks
427 //! \param    uint64_t *piNs
428 //!           [in] Nano Seconds
429 //! \return   void
430 //!
ConvertToNanoSeconds(PRENDERHAL_INTERFACE pRenderHal,uint64_t iTicks,uint64_t * piNs)431 void XRenderHal_Interface_g9::ConvertToNanoSeconds(
432     PRENDERHAL_INTERFACE                 pRenderHal,
433     uint64_t                            iTicks,
434     uint64_t                            *piNs)
435 {
436     //-----------------------------
437     MHW_RENDERHAL_UNUSED(pRenderHal);
438     MHW_RENDERHAL_CHK_NULL_NO_STATUS_RETURN(pRenderHal);
439     MHW_RENDERHAL_CHK_NULL_NO_STATUS_RETURN(piNs);
440     //-----------------------------
441     if (GFX_IS_PRODUCT(pRenderHal->Platform, IGFX_BROXTON))
442     {
443         *piNs = (uint64_t)(iTicks * RENDERHAL_NS_PER_TICK_RENDER_G9LP);
444     }
445     else
446     {
447         *piNs = (uint64_t)(iTicks * RENDERHAL_NS_PER_TICK_RENDER_G9);
448     }
449 }
450 
451 //!
452 //! \brief    Initialize the State Heap Settings per platform
453 //! \param    PRENDERHAL_STATE_HEAP_SETTINGS pSettings
454 //!           [out] Pointer to PRENDERHAL_STATE_HEAP_SETTINGSStructure
455 //! \return   void
456 //!
InitStateHeapSettings(PRENDERHAL_INTERFACE pRenderHal)457 void XRenderHal_Interface_g9::InitStateHeapSettings(
458     PRENDERHAL_INTERFACE    pRenderHal)
459 {
460     MHW_RENDERHAL_CHK_NULL_NO_STATUS_RETURN(pRenderHal);
461     // Set State Heap settings for g9
462     pRenderHal->StateHeapSettings = g_cRenderHal_State_Heap_Settings_g9;
463 }
464 
465 //!
466 //! \brief    Initialize the default surface type and advanced surface type  per platform
467 //! \param    PRENDERHAL_INTERFACE    pRenderHal
468 //!           [out] Pointer to PRENDERHAL_INTERFACE
469 //! \return   void
470 //!
InitSurfaceTypes(PRENDERHAL_INTERFACE pRenderHal)471 void XRenderHal_Interface_g9::InitSurfaceTypes(
472     PRENDERHAL_INTERFACE    pRenderHal)
473 {
474     MHW_RENDERHAL_CHK_NULL_NO_STATUS_RETURN(pRenderHal);
475     // Set default / advanced surface types
476     pRenderHal->SurfaceTypeDefault            = RENDERHAL_SURFACE_TYPE_G9;
477     pRenderHal->SurfaceTypeAdvanced           = RENDERHAL_SURFACE_TYPE_ADV_G9;
478 }
479 
480 //!
481 //! \brief    Enables L3 cacheing flag and sets related registers/values
482 //! \param    PRENDERHAL_INTERFACE    pRenderHal
483 //!           [in]  Pointer to Hardware Interface
484 //! \param    pCacheSettings
485 //!           [in] L3 Cache Configurations
486 //! \return   MOS_STATUS
487 //!           MOS_STATUS_SUCCESS if success, else fail reason
488 //!
EnableL3Caching(PRENDERHAL_INTERFACE pRenderHal,PRENDERHAL_L3_CACHE_SETTINGS pCacheSettings)489 MOS_STATUS XRenderHal_Interface_g9::EnableL3Caching(
490     PRENDERHAL_INTERFACE         pRenderHal,
491     PRENDERHAL_L3_CACHE_SETTINGS pCacheSettings)
492 {
493     MOS_STATUS                           eStatus;
494     MHW_RENDER_ENGINE_L3_CACHE_SETTINGS  mHwL3CacheConfig = {};
495     PMHW_RENDER_ENGINE_L3_CACHE_SETTINGS pCacheConfig;
496     MhwRenderInterface                   *pMhwRender;
497 
498     MHW_RENDERHAL_CHK_NULL(pRenderHal);
499     pMhwRender = pRenderHal->pMhwRenderInterface;
500     MHW_RENDERHAL_CHK_NULL(pMhwRender);
501 
502     if (nullptr == pCacheSettings)
503     {
504         MHW_RENDERHAL_CHK_STATUS(pMhwRender->EnableL3Caching(nullptr));
505         goto finish;
506     }
507 
508     // customize the cache config for renderhal and let mhw_render overwrite it
509     pCacheConfig = &mHwL3CacheConfig;
510 
511     if (pCacheSettings->bEnableSLM)
512         pCacheConfig->dwCntlReg = RENDERHAL_L3_CACHE_SLM_CONFIG_CNTLREG_VALUE_G9_RENDERHAL;
513     else
514         pCacheConfig->dwCntlReg = RENDERHAL_L3_CACHE_CONFIG_CNTLREG_VALUE_G9_RENDERHAL;
515 
516     // Override L3 cache configuration
517     if (pCacheSettings->bOverride)
518     {
519         if (pCacheSettings->bCntlRegOverride)
520         {
521             pCacheConfig->dwCntlReg = pCacheSettings->dwCntlReg;
522         }
523     }
524     MHW_RENDERHAL_CHK_STATUS(pMhwRender->EnableL3Caching(pCacheConfig));
525 
526 finish:
527     return eStatus;
528 }
529 
530 //!
531 //! \brief    Get offset and/or pointer to sampler state
532 //! \details  Get offset and/or pointer to sampler state in General State Heap
533 //! \param    PRENDERHAL_INTERFACE pRenderHal
534 //!           [in] Pointer to RenderHal Interface
535 //! \param    int32_t iMediaID
536 //!           [in] Media ID associated with sampler
537 //! \param    int32_t iSamplerID
538 //!           [in] Sampler ID
539 //! \param    uint32_t *pdwSamplerOffset
540 //!           [out] optional; offset of sampler state from GSH base
541 //! \param    void  **ppSampler
542 //!           [out] optional; pointer to sampler state in GSH
543 //! \return   MOS_STATUS
544 //!
GetSamplerOffsetAndPtr_DSH(PRENDERHAL_INTERFACE pRenderHal,int32_t iMediaID,int32_t iSamplerID,PMHW_SAMPLER_STATE_PARAM pSamplerParams,uint32_t * pdwSamplerOffset,void ** ppSampler)545 MOS_STATUS XRenderHal_Interface_g9::GetSamplerOffsetAndPtr_DSH(
546     PRENDERHAL_INTERFACE     pRenderHal,
547     int32_t                  iMediaID,
548     int32_t                  iSamplerID,
549     PMHW_SAMPLER_STATE_PARAM pSamplerParams,
550     uint32_t                 *pdwSamplerOffset,
551     void                    **ppSampler)
552 {
553     PRENDERHAL_STATE_HEAP       pStateHeap;
554     PRENDERHAL_DYNAMIC_STATE    pDynamicState;
555     MOS_STATUS                  eStatus = MOS_STATUS_SUCCESS;
556     uint32_t                    dwSamplerIndirect;
557     uint32_t                    dwOffset;
558     MHW_SAMPLER_TYPE            SamplerType;
559 
560     MHW_RENDERHAL_CHK_NULL(pRenderHal);
561     MHW_RENDERHAL_CHK_NULL(pRenderHal->pStateHeap);
562     MHW_RENDERHAL_CHK_NULL(pRenderHal->pStateHeap->pCurMediaState);
563     MHW_RENDERHAL_CHK_NULL(pRenderHal->pHwSizes);
564 
565     pStateHeap    = pRenderHal->pStateHeap;
566     pDynamicState = pStateHeap->pCurMediaState->pDynamicState;
567 
568     MHW_RENDERHAL_CHK_NULL(pDynamicState);
569 
570     MHW_RENDERHAL_ASSERT(iMediaID   < pDynamicState->MediaID.iCount);
571 
572     dwOffset    = iMediaID * pDynamicState->dwSizeSamplers;                    // Go to Media ID sampler offset
573 
574     SamplerType = (pSamplerParams) ? pSamplerParams->SamplerType : MHW_SAMPLER_TYPE_3D;
575 
576     switch (SamplerType)
577     {
578         case MHW_SAMPLER_TYPE_AVS:
579             MHW_RENDERHAL_ASSERT(iSamplerID < pDynamicState->SamplerAVS.iCount);
580             dwOffset += pDynamicState->SamplerAVS.dwOffset +                    // Go to AVS sampler area
581                         iSamplerID * MHW_SAMPLER_STATE_AVS_INC_G9;              // 16: size of one element, 128 elements for SKL
582             break;
583 
584         case MHW_SAMPLER_TYPE_CONV:
585             MHW_RENDERHAL_ASSERT(iSamplerID < pDynamicState->SamplerConv.iCount);
586             dwOffset = pDynamicState->SamplerConv.dwOffset;                     // Goto Conv sampler base
587             if ( pSamplerParams->Convolve.ui8ConvolveType == 0 && pSamplerParams->Convolve.skl_mode )
588             {   // 2D convolve
589                 dwOffset += iSamplerID * MHW_SAMPLER_STATE_CONV_INC_G9;         // 16: size of one element, 128 elements for SKL
590             }
591             else if ( pSamplerParams->Convolve.ui8ConvolveType == 1 )
592             {   // 1D convolve
593                 dwOffset += iSamplerID * MHW_SAMPLER_STATE_CONV_1D_INC_G9;      // 16: size of one element, 8 elements for SKL
594             }
595             else
596             {   // 1P convolve (same as gen8) and 2D convolve BDW mode
597                 dwOffset += iSamplerID * MHW_SAMPLER_STATE_CONV_INC_G8;         // 16: size of one element, 32: 32 entry
598             }
599             break;
600 
601         case MHW_SAMPLER_TYPE_MISC:
602             MHW_RENDERHAL_ASSERT(iSamplerID < pDynamicState->SamplerMisc.iCount);
603             dwOffset += pDynamicState->Sampler3D.dwOffset          +             // Goto sampler base
604                         iSamplerID * MHW_SAMPLER_STATE_VA_INC;                   // 16: size of one element, 2: 2 entries
605             break;
606 
607         case MHW_SAMPLER_TYPE_3D:
608         case MHW_SAMPLER_TYPE_VME:
609         default:
610             MHW_RENDERHAL_ASSERT(iSamplerID < pDynamicState->Sampler3D.iCount);
611             dwSamplerIndirect = dwOffset;
612             dwOffset += pDynamicState->Sampler3D.dwOffset          +             // Go 3D Sampler base
613                         iSamplerID * pRenderHal->pHwSizes->dwSizeSamplerState;   // Goto to "samplerID" sampler state
614 
615             if (pSamplerParams)
616             {
617                 dwSamplerIndirect += pDynamicState->SamplerInd.dwOffset +                              // offset to indirect sampler area
618                                      iSamplerID * pRenderHal->pHwSizes->dwSizeSamplerIndirectState;   // Goto to "samplerID" indirect state
619                 pSamplerParams->Unorm.IndirectStateOffset = dwSamplerIndirect;
620             }
621 
622             break;
623     }
624 
625     if (pdwSamplerOffset)
626     {
627         *pdwSamplerOffset = dwOffset;
628     }
629 
630 finish:
631     return eStatus;
632 }
633 
634 //!
635 //! \brief      Initialize the DSH Settings
636 //! \details    Initialize the structure DynamicHeapSettings in pRenderHal
637 //! \param      PRENDERHAL_INTERFACE pRenderHal
638 //!             [in]    Pointer to HW interface
639 //! \return     void
640 //!
InitDynamicHeapSettings(PRENDERHAL_INTERFACE pRenderHal)641 void XRenderHal_Interface_g9::InitDynamicHeapSettings(
642     PRENDERHAL_INTERFACE  pRenderHal)
643 {
644     MHW_RENDERHAL_CHK_NULL_NO_STATUS_RETURN(pRenderHal);
645 
646     // Additional Dynamic State Heap settings for g9
647     pRenderHal->DynamicHeapSettings           = g_cRenderHal_DSH_Settings_g9;
648 }
649 
650 //!
651 //! \brief    Set Power Option Status
652 //! \param    [in] pRenderHal
653 //!           Pointer to Hardware Interface
654 //! \param    [in,out] pCmdBuffer
655 //!           Pointer to Command Buffer
656 //! \return   MOS_STATUS
657 //!           MOS_STATUS_SUCCESS if success, else fail reason
658 //!
SetPowerOptionStatus(PRENDERHAL_INTERFACE pRenderHal,PMOS_COMMAND_BUFFER pCmdBuffer)659 MOS_STATUS XRenderHal_Interface_g9::SetPowerOptionStatus(
660     PRENDERHAL_INTERFACE         pRenderHal,
661     PMOS_COMMAND_BUFFER          pCmdBuffer)
662 {
663     PMOS_INTERFACE              pOsInterface;
664     MOS_STATUS                  eStatus;
665     MEDIA_SYSTEM_INFO           *pGtSystemInfo;
666 
667     MHW_RENDERHAL_CHK_NULL(pRenderHal);
668     MHW_RENDERHAL_CHK_NULL(pCmdBuffer);
669     MHW_RENDERHAL_CHK_NULL(pRenderHal->pOsInterface);
670 
671     eStatus         = MOS_STATUS_SUCCESS;
672     pOsInterface    = pRenderHal->pOsInterface;
673     pGtSystemInfo   = pOsInterface->pfnGetGtSystemInfo(pOsInterface);
674     MHW_RENDERHAL_CHK_NULL(pGtSystemInfo);
675 
676     // Check if Slice Shutdown can be enabled
677     if (pRenderHal->bRequestSingleSlice)
678     {
679         pCmdBuffer->Attributes.dwNumRequestedEUSlices = 1;
680     }
681     else if (pRenderHal->bEUSaturationNoSSD)
682     {
683         pCmdBuffer->Attributes.dwNumRequestedEUSlices = 2;
684     }
685 
686     if ((pRenderHal->pSkuTable) && MEDIA_IS_SKU(pRenderHal->pSkuTable, FtrSSEUPowerGating))
687     {
688         // VP does not request subslice shutdown according to the array VpHalDefaultSSEUTableGxx
689         if (((pRenderHal->PowerOption.nSlice != 0) || (pRenderHal->PowerOption.nSubSlice != 0) || (pRenderHal->PowerOption.nEU != 0)) &&
690             ((pGtSystemInfo->SliceCount != 0) && (pGtSystemInfo->SubSliceCount != 0)))
691         {
692             pCmdBuffer->Attributes.dwNumRequestedEUSlices    = MOS_MIN(pRenderHal->PowerOption.nSlice, pGtSystemInfo->SliceCount);
693             pCmdBuffer->Attributes.dwNumRequestedSubSlices   = MOS_MIN(pRenderHal->PowerOption.nSubSlice, (pGtSystemInfo->SubSliceCount / pGtSystemInfo->SliceCount));
694             pCmdBuffer->Attributes.dwNumRequestedEUs         = MOS_MIN(pRenderHal->PowerOption.nEU, (pGtSystemInfo->EUCount / pGtSystemInfo->SubSliceCount));
695             pCmdBuffer->Attributes.bValidPowerGatingRequest  = true;
696 
697             if (GFX_IS_PRODUCT(pRenderHal->Platform, IGFX_SKYLAKE) && pOsInterface->pfnSetSliceCount)
698             {
699                 uint32_t sliceCount = pCmdBuffer->Attributes.dwNumRequestedEUSlices;
700                 pOsInterface->pfnSetSliceCount(pOsInterface, &sliceCount);
701             }
702         }
703     }
704 
705 finish:
706     return eStatus;
707 }
708 
709 //!
710 //! \brief      Set L3 cache override config parameters
711 //! \param      [in] pRenderHal
712 //!             Pointer to RenderHal Interface Structure
713 //! \param      [in,out] pCacheSettings
714 //!             Pointer to pCacheSettings
715 //! \param      [in] bEnableSLM
716 //!             Flag to enable SLM
717 //! \return     MOS_STATUS
718 //!             MOS_STATUS_SUCCESS if success. Error code otherwise
719 //!
SetCacheOverrideParams(PRENDERHAL_INTERFACE pRenderHal,PRENDERHAL_L3_CACHE_SETTINGS pCacheSettings,bool bEnableSLM)720 MOS_STATUS XRenderHal_Interface_g9::SetCacheOverrideParams(
721     PRENDERHAL_INTERFACE            pRenderHal,
722     PRENDERHAL_L3_CACHE_SETTINGS    pCacheSettings,
723     bool                            bEnableSLM)
724 {
725     MOS_STATUS      eStatus = MOS_STATUS_SUCCESS;
726 
727     MHW_RENDERHAL_CHK_NULL(pRenderHal);
728     MHW_RENDERHAL_CHK_NULL(pCacheSettings);
729 
730     if (bEnableSLM)
731     {
732         pCacheSettings->dwCntlReg = RENDERHAL_L3_CACHE_CNTL_REG_SLM_ENABLE_G9;
733     }
734     else
735     {
736         pCacheSettings->dwCntlReg = RENDERHAL_L3_CACHE_CNTL_REG_SLM_DISABLE_ALL_L3_512K_G9;
737     }
738     pCacheSettings->bCntlRegOverride = true;
739 
740 finish:
741     return eStatus;
742 }
743 
744 //! \brief      Get the size of Render Surface State Command
745 //! \return     size_t
746 //!             the size of render surface state command
GetSurfaceStateCmdSize()747 size_t XRenderHal_Interface_g9::GetSurfaceStateCmdSize()
748 {
749     return MOS_ALIGN_CEIL( MOS_MAX(mhw_state_heap_g9_X::RENDER_SURFACE_STATE_CMD::byteSize,
750                    mhw_state_heap_g9_X::MEDIA_SURFACE_STATE_CMD::byteSize), MHW_SURFACE_STATE_ALIGN);
751 }
752 
753