Debian Codegraph @

media_softlet/agnostic/Xe_R/Xe2_HPG/renderhal/renderhal_xe2_hpg_next.cpp

raw
1 /*===================== begin_copyright_notice ==================================
2
3 * Copyright (c) 2024, Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22
23 ======================= end_copyright_notice ==================================*/
24 //!
25 //! \file renderhal_xe2_hpg_next.cpp
26 //! \details Render functions
27 //!
28
29 #include "renderhal.h"
30 #include "renderhal_xe2_hpg_next.h"
31 #include "vp_utils.h"
32 #include "media_feature.h"
33 #include "media_packet.h"
34
35 //!
36 //! \brief GSH settings for Xe2_hpg
37 //!
38 #define RENDERHAL_SAMPLERS_AVS_XE2_HPG 0
39 #define RENDERHAL_SSH_SURFACES_PER_BT_XE2_HPG 80
40 #define ENLARGE_KERNEL_COUNT_XE2_HPG RENDERHAL_KERNEL_COUNT * 3
41 #define ENLARGE_KERNEL_HEAP_XE2_HPG RENDERHAL_KERNEL_HEAP * 3
42 #define ENLARGE_CURBE_SIZE_XE2_HPG RENDERHAL_CURBE_SIZE * 16
43 #define ENLARGED_SSH_BINDING_TABLES_XE2_HPG 16
44
45 extern const RENDERHAL_STATE_HEAP_SETTINGS g_cRenderHal_State_Heap_Settings_xe2_hpg =
46 {
47 // Global GSH Allocation parameters
48 RENDERHAL_SYNC_SIZE, //!< iSyncSize
49
50 // Media State Allocation parameters
51 RENDERHAL_MEDIA_STATES, //!< iMediaStateHeaps - Set by Initialize
52 RENDERHAL_MEDIA_IDS, //!< iMediaIDs
53 RENDERHAL_CURBE_SIZE, //!< iCurbeSize
54 RENDERHAL_SAMPLERS, //!< iSamplers
55 RENDERHAL_SAMPLERS_AVS_XE2_HPG, //!< iSamplersAVS
56 RENDERHAL_SAMPLERS_VA, //!< iSamplersVA
57 RENDERHAL_KERNEL_COUNT, //!< iKernelCount
58 RENDERHAL_KERNEL_HEAP, //!< iKernelHeapSize
59 RENDERHAL_KERNEL_BLOCK_SIZE, //!< iKernelBlockSize
60
61 // Media VFE/ID configuration, limits
62 0, //!< iPerThreadScratchSize
63 RENDERHAL_MAX_SIP_SIZE, //!< iSipSize
64
65 // Surface State Heap Settings
66 RENDERHAL_SSH_INSTANCES, //!< iSurfaceStateHeaps
67 RENDERHAL_SSH_BINDING_TABLES, //!< iBindingTables
68 RENDERHAL_SSH_SURFACE_STATES, //!< iSurfaceStates
69 RENDERHAL_SSH_SURFACES_PER_BT, //!< iSurfacesPerBT
70 RENDERHAL_SSH_BINDING_TABLE_ALIGN, //!< iBTAlignment
71 MOS_CODEC_RESOURCE_USAGE_BEGIN_CODEC //!< heapUsageType
72 };
73
74 extern const RENDERHAL_ENLARGE_PARAMS g_cRenderHal_Enlarge_State_Heap_Settings_Adv_xe2_hpg =
75 {
76 ENLARGED_SSH_BINDING_TABLES_XE2_HPG, //!< iBindingTables
77 RENDERHAL_SSH_SURFACE_STATES_MAX, //!< iSurfaceStates
78 RENDERHAL_SSH_SURFACES_PER_BT_XE2_HPG, //!< iSurfacesPerBT
79 ENLARGE_KERNEL_COUNT_XE2_HPG, //!< iKernelCount
80 ENLARGE_KERNEL_HEAP_XE2_HPG, //!< iKernelHeapSize
81 ENLARGE_CURBE_SIZE_XE2_HPG, //!< iCurbeSize
82 RENDERHAL_MEDIA_IDS //!< iMediaIDs
83 };
84
85 MOS_STATUS XRenderHal_Interface_Xe2_Hpg_Next::IsRenderHalMMCEnabled(
86 PRENDERHAL_INTERFACE pRenderHal)
87 {
88 VP_FUNC_CALL();
89
90 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
91 bool isMMCEnabled = false;
92
93 MHW_RENDERHAL_CHK_NULL_RETURN(pRenderHal);
94
95 // Read user feature key to set MMC for Fast Composition surfaces
96 #if defined(LINUX) && (!defined(WDDM_LINUX))
97 isMMCEnabled = !MEDIA_IS_WA(pRenderHal->pWaTable, WaDisableVPMmc) || !MEDIA_IS_WA(pRenderHal->pWaTable, WaDisableCodecMmc);
98 #else
99 isMMCEnabled = true; // turn on MMC
100 #endif
101
102 #if (_DEBUG || _RELEASE_INTERNAL)
103 if (pRenderHal->userSettingPtr != nullptr)
104 {
105 // Read reg key to set MMC for Fast Composition surfaces
106 ReadUserSettingForDebug(
107 pRenderHal->userSettingPtr,
108 isMMCEnabled,
109 __MEDIA_USER_FEATURE_ENABLE_RENDER_ENGINE_MMC,
110 MediaUserSetting::Group::Device,
111 isMMCEnabled,
112 true);
113 }
114 #endif
115 m_renderHalMMCEnabled = isMMCEnabled && MEDIA_IS_SKU(pRenderHal->pSkuTable, FtrE2ECompression);
116 pRenderHal->isMMCEnabled = m_renderHalMMCEnabled;
117
118 return eStatus;
119 }
120
121 //! \brief Send To 3DState Binding Table Pool Alloc
122 //! \details Send To 3DState Binding Table Pool Alloc
123 //! \param PRENDERHAL_INTERFACE pRenderHal
124 //! [in] Pointer to RenderHal Interface Structure
125 //! \param PMOS_COMMAND_BUFFER pCmdBuffer
126 //! [in] Pointer to Command Buffer
127 //! \return MOS_STATUS
128 MOS_STATUS XRenderHal_Interface_Xe2_Hpg_Next::SendTo3DStateBindingTablePoolAlloc(
129 PRENDERHAL_INTERFACE pRenderHal,
130 PMOS_COMMAND_BUFFER pCmdBuffer)
131 {
132 VP_FUNC_CALL();
133
134 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
135
136 MHW_RENDERHAL_CHK_NULL_RETURN(pRenderHal);
137 MHW_RENDERHAL_CHK_NULL_RETURN(pCmdBuffer);
138 MHW_RENDERHAL_CHK_NULL_RETURN(m_renderItf);
139
140 auto &computerModeParams = m_renderItf->MHW_GETPAR_F(STATE_COMPUTE_MODE)();
141 computerModeParams = {};
142 computerModeParams.enableLargeGrf = pRenderHal->largeGrfMode;
143 computerModeParams.forceEuThreadSchedulingMode = pRenderHal->euThreadSchedulingMode;
144 computerModeParams.enableVariableRegisterSizeAllocationVrt = pRenderHal->enableVariableRegisterSizeAllocationVrt;
145 m_renderItf->MHW_ADDCMD_F(STATE_COMPUTE_MODE)(pCmdBuffer);
146
147 SETPAR_AND_ADDCMD(_3DSTATE_BINDING_TABLE_POOL_ALLOC, m_renderItf, pCmdBuffer);
148
149 return eStatus;
150 }
151
152 //!
153 //! \brief Initialize the State Heap Settings per platform
154 //! \param PRENDERHAL_STATE_HEAP_SETTINGS pSettings
155 //! [out] Pointer to PRENDERHAL_STATE_HEAP_SETTINGSStructure
156 //! \return void
157 //!
158 void XRenderHal_Interface_Xe2_Hpg_Next::InitStateHeapSettings(
159 PRENDERHAL_INTERFACE pRenderHal)
160 {
161 MHW_RENDERHAL_CHK_NULL_NO_STATUS_RETURN(pRenderHal);
162 // Set State Heap settings for hpg_base
163 pRenderHal->StateHeapSettings = g_cRenderHal_State_Heap_Settings_xe2_hpg;
164 pRenderHal->defaultStateHeapSettings = g_cRenderHal_State_Heap_Settings_xe2_hpg;
165 pRenderHal->enlargeStateHeapSettingsForAdv = g_cRenderHal_Enlarge_State_Heap_Settings_Adv_xe2_hpg;
166 }
167
168 //!
169 //! \brief Setup Surface State
170 //! \details Setup Surface State for Gen11
171 //! \param PRENDERHAL_INTERFACE pRenderHal
172 //! [in] Pointer to Hardware Interface Structure
173 //! \param PRENDERHAL_SURFACE pRenderHalSurface
174 //! [in] Pointer to Render Hal Surface
175 //! \param PRENDERHAL_SURFACE_STATE_PARAMS pParams
176 //! [in] Pointer to Surface State Params
177 //! \param int32_t *piNumEntries
178 //! [out] Pointer to Number of Surface State Entries (Num Planes)
179 //! \param PRENDERHAL_SURFACE_STATE_ENTRY * ppSurfaceEntries
180 //! [out] Array of Surface State Entries
181 //! \param PRENDERHAL_OFFSET_OVERRIDE pOffsetOverride
182 //! [in] Ignored (not used in Gen11)
183 //! \return MOS_STATUS
184 //!
185 MOS_STATUS XRenderHal_Interface_Xe2_Hpg_Next::SetupSurfaceState(
186 PRENDERHAL_INTERFACE pRenderHal,
187 PRENDERHAL_SURFACE pRenderHalSurface,
188 PRENDERHAL_SURFACE_STATE_PARAMS pParams,
189 int32_t *piNumEntries,
190 PRENDERHAL_SURFACE_STATE_ENTRY *ppSurfaceEntries,
191 PRENDERHAL_OFFSET_OVERRIDE pOffsetOverride)
192 {
193 VP_FUNC_CALL();
194
195 PRENDERHAL_SURFACE_STATE_ENTRY pSurfaceEntry;
196 PMOS_PLANE_OFFSET pPlaneOffset;
197 MHW_SURFACE_STATE_PARAMS SurfStateParams;
198 PMOS_SURFACE pSurface;
199 int32_t i;
200 uint32_t dwPixelsPerSampleUV;
201 uint32_t dwSurfaceSize;
202 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
203
204 //-----------------------------------------
205 MHW_RENDERHAL_UNUSED(pOffsetOverride);
206 MHW_RENDERHAL_CHK_NULL_RETURN(pRenderHal);
207 MHW_RENDERHAL_CHK_NULL_RETURN(pRenderHalSurface);
208 MHW_RENDERHAL_CHK_NULL_RETURN(pParams);
209 MHW_RENDERHAL_CHK_NULL_RETURN(ppSurfaceEntries);
210 MHW_RENDERHAL_CHK_NULL_RETURN(pRenderHal->pStateHeap);
211 MHW_RENDERHAL_CHK_NULL_RETURN(pRenderHal->pHwSizes);
212 MHW_RENDERHAL_CHK_NULL_RETURN(pRenderHal->pMhwStateHeap);
213
214 int32_t index = pRenderHalSurface->Rotation;
215 if (!(index >= 0 && index < 8))
216 {
217 MHW_RENDERHAL_ASSERTMESSAGE("Invalid Rotation");
218 }
219
220 dwSurfaceSize = pRenderHal->pHwSizes->dwSizeSurfaceState;
221
222 MOS_ZeroMemory(&SurfStateParams, sizeof(SurfStateParams));
223
224 // Get the Surface State Entries
225 MHW_RENDERHAL_CHK_STATUS_RETURN(pRenderHal->pfnGetSurfaceStateEntries(
226 pRenderHal,
227 pRenderHalSurface,
228 pParams,
229 piNumEntries,
230 ppSurfaceEntries));
231
232 for (i = 0; i < *piNumEntries; i++)
233 {
234 // Pointer to surface state entry for current plane
235 pSurfaceEntry = ppSurfaceEntries[i];
236
237 pSurface = pSurfaceEntry->pSurface;
238 MHW_RENDERHAL_CHK_NULL_RETURN(pSurface);
239
240 // Set the Surface State Offset from base of SSH
241 pSurfaceEntry->dwSurfStateOffset = pRenderHal->pStateHeap->iSurfaceStateOffset + // Offset to Base Of Current Surface State Area
242 pSurfaceEntry->iSurfStateID * dwSurfaceSize; // Offset to Surface State within the area
243
244 // Obtain the Pointer to the Surface state from SSH Buffer
245 if (pSurfaceEntry->dwFormat == MHW_GFX3DSTATE_SURFACEFORMAT_L8_UNORM && !IsL8FormatSupported())
246 {
247 pSurfaceEntry->dwFormat = MHW_GFX3DSTATE_SURFACEFORMAT_R8_UNORM;
248 }
249 SurfStateParams.pSurfaceState = pSurfaceEntry->pSurfaceState;
250 SurfStateParams.bUseAdvState = pSurfaceEntry->bAVS;
251 SurfStateParams.dwWidth = pSurfaceEntry->dwWidth;
252 SurfStateParams.dwHeight = pSurfaceEntry->dwHeight;
253 SurfStateParams.dwFormat = pSurfaceEntry->dwFormat;
254 SurfStateParams.dwPitch = pSurfaceEntry->dwPitch;
255 SurfStateParams.dwQPitch = pSurfaceEntry->dwQPitch;
256 SurfStateParams.bTiledSurface = pSurfaceEntry->bTiledSurface;
257 SurfStateParams.bTileWalk = pSurfaceEntry->bTileWalk;
258 SurfStateParams.dwCacheabilityControl = pRenderHal->pfnGetSurfaceMemoryObjectControl(pRenderHal, pParams);
259 SurfStateParams.RotationMode = g_cLookup_RotationMode_hpg_base[pRenderHalSurface->Rotation];
260 SurfStateParams.TileModeGMM = pSurface->TileModeGMM;
261 SurfStateParams.bGMMTileEnabled = pSurface->bGMMTileEnabled;
262
263 if (pSurface->MmcState == MOS_MEMCOMP_RC)
264 {
265 m_renderHalMMCEnabled = MEDIA_IS_SKU(pRenderHal->pSkuTable, FtrE2ECompression);
266 pRenderHal->isMMCEnabled = m_renderHalMMCEnabled;
267 }
268
269 if (IsFormatMMCSupported(pSurface->Format) &&
270 m_renderHalMMCEnabled)
271 {
272 if (pSurface->MmcState == MOS_MEMCOMP_MC ||
273 pSurface->MmcState == MOS_MEMCOMP_RC)
274 {
275 SurfStateParams.MmcState = pSurface->MmcState;
276
277 if (pSurfaceEntry->YUVPlane == MHW_U_PLANE &&
278 (pSurface->Format == Format_NV12 ||
279 pSurface->Format == Format_P010 ||
280 pSurface->Format == Format_P016))
281 {
282 SurfStateParams.dwCompressionFormat = (uint32_t)(0x00000010) | (pSurface->CompressionFormat & 0x0f);
283 }
284 else if ((pSurface->Format == Format_R8G8UN) &&
285 (pSurface->MmcState == MOS_MEMCOMP_MC))
286 {
287 /* it will be an issue if the R8G8UN surface with MC enable
288 is not chroma plane from NV12 surface, so far there is no
289 such case
290 */
291 SurfStateParams.dwCompressionFormat = (uint32_t)(0x00000010) | (pSurface->CompressionFormat & 0x0f);
292 }
293 else
294 {
295 SurfStateParams.dwCompressionFormat = pSurface->CompressionFormat & 0x1f;
296 }
297 }
298 else
299 {
300 MHW_RENDERHAL_NORMALMESSAGE("Unsupported Compression Mode for Render Engine.");
301 SurfStateParams.MmcState = MOS_MEMCOMP_DISABLED;
302 SurfStateParams.dwCompressionFormat = 0;
303 }
304
305 if (pParams->isOutput &&
306 pSurface->MmcState == MOS_MEMCOMP_RC &&
307 pSurface->OsResource.bUncompressedWriteNeeded)
308 {
309 MHW_RENDERHAL_NORMALMESSAGE("force uncompressed write if requested from resources");
310 SurfStateParams.MmcState = MOS_MEMCOMP_MC;
311 SurfStateParams.dwCompressionFormat = 0;
312 }
313
314 if (!pParams->isOutput &&
315 pSurface->MmcState != MOS_MEMCOMP_DISABLED &&
316 pSurfaceEntry->bVertStride)
317 {
318 // If input surface is interlaced, then surface should be uncompressed
319 // Remove compression setting for such surface
320 MHW_RENDERHAL_NORMALMESSAGE("interlaced input for Render Engine.");
321 SurfStateParams.MmcState = MOS_MEMCOMP_DISABLED;
322 SurfStateParams.dwCompressionFormat = 0;
323 }
324 }
325
326 // 2D/3D Surface (non-AVS)
327 SurfStateParams.SurfaceType3D = (pSurface->dwDepth > 1) ? GFX3DSTATE_SURFACETYPE_3D : GFX3DSTATE_SURFACETYPE_2D;
328 SurfStateParams.dwDepth = MOS_MAX(1, pSurface->dwDepth);
329 SurfStateParams.bVerticalLineStrideOffset = pSurfaceEntry->bVertStrideOffs;
330 SurfStateParams.bVerticalLineStride = pSurfaceEntry->bVertStride;
331 SurfStateParams.bHalfPitchChroma = pSurfaceEntry->bHalfPitchChroma;
332 SurfStateParams.bBoardColorOGL = pParams->bWidthInDword_UV ? false : true; //sampler surface
333
334 // Setup surface state
335 if (pSurfaceEntry->YUVPlane == MHW_U_PLANE ||
336 pSurfaceEntry->YUVPlane == MHW_V_PLANE)
337 {
338 pPlaneOffset = (pSurfaceEntry->YUVPlane == MHW_U_PLANE) ? &pSurface->UPlaneOffset : &pSurface->VPlaneOffset;
339
340 // Get Pixels Per Sample if we use dataport read
341 if (pParams->bWidthInDword_UV)
342 {
343 RenderHal_GetPixelsPerSample(pSurface->Format, &dwPixelsPerSampleUV);
344 }
345 else
346 {
347 // If the kernel uses sampler - do not change width (it affects coordinates)
348 dwPixelsPerSampleUV = 1;
349 }
350
351 if (dwPixelsPerSampleUV == 1)
352 {
353 SurfStateParams.iXOffset = pPlaneOffset->iXOffset;
354 }
355 else
356 {
357 SurfStateParams.iXOffset = pPlaneOffset->iXOffset / sizeof(uint32_t);
358 }
359
360 SurfStateParams.iYOffset = pPlaneOffset->iYOffset;
361 }
362 else // Y plane
363 {
364 pPlaneOffset = &pSurface->YPlaneOffset;
365 SurfStateParams.iXOffset = pPlaneOffset->iXOffset / sizeof(uint32_t);
366 SurfStateParams.iYOffset = pPlaneOffset->iYOffset;
367
368 if (MEDIA_IS_SKU(pRenderHal->pSkuTable, FtrVpFP16))
369 {
370 if (pSurfaceEntry->dwFormat == MHW_GFX3DSTATE_SURFACEFORMAT_R16G16B16A16_FLOAT)
371 {
372 if (SurfStateParams.iXOffset > 0 && pSurface->MipTailStartLOD < 15)
373 {
374 SurfStateParams.iXOffset = 0;
375 SurfStateParams.MipTailStartLOD = MHW_MIP_TAIL_START_LOD_ENABLED_MASK | pSurface->MipTailStartLOD;
376 }
377 }
378 }
379
380 if ((pSurfaceEntry->YUVPlane == MHW_Y_PLANE) &&
381 (pSurfaceEntry->dwFormat == MHW_GFX3DSTATE_SURFACEFORMAT_PLANAR_420_8))
382 {
383 if (pSurface->Format == Format_YV12)
384 {
385 SurfStateParams.bSeperateUVPlane = true;
386 SurfStateParams.dwXOffsetForU = 0;
387 SurfStateParams.dwYOffsetForU = pSurface->dwHeight * 2 + pSurface->dwHeight / 2;
388 SurfStateParams.dwXOffsetForV = 0;
389 SurfStateParams.dwYOffsetForV = pSurface->dwHeight * 2;
390 }
391 else
392 {
393 SurfStateParams.bSeperateUVPlane = false;
394 SurfStateParams.dwXOffsetForU = 0;
395 SurfStateParams.dwYOffsetForU = (uint32_t)((pSurface->UPlaneOffset.iSurfaceOffset - pSurface->YPlaneOffset.iSurfaceOffset) / pSurface->dwPitch) + pSurface->UPlaneOffset.iYOffset;
396 SurfStateParams.dwXOffsetForV = 0;
397 SurfStateParams.dwYOffsetForV = 0;
398 }
399 }
400
401 if ((pSurfaceEntry->YUVPlane == MHW_Y_PLANE) &&
402 (pSurfaceEntry->dwFormat == MHW_GFX3DSTATE_SURFACEFORMAT_PLANAR_420_16))
403 {
404 SurfStateParams.bSeperateUVPlane = false;
405 SurfStateParams.dwXOffsetForU = 0;
406 SurfStateParams.dwYOffsetForU = (uint32_t)((pSurface->UPlaneOffset.iSurfaceOffset - pSurface->YPlaneOffset.iSurfaceOffset) / pSurface->dwPitch) + pSurface->UPlaneOffset.iYOffset;
407 SurfStateParams.dwXOffsetForV = 0;
408 SurfStateParams.dwYOffsetForV = 0;
409 }
410 }
411
412 // Call MHW to setup the Surface State Heap entry
413 MHW_RENDERHAL_CHK_STATUS_RETURN(pRenderHal->pMhwStateHeap->SetSurfaceStateEntry(&SurfStateParams));
414
415 // Setup OS specific states
416 MHW_RENDERHAL_CHK_STATUS_RETURN(pRenderHal->pfnSetupSurfaceStatesOs(pRenderHal, pParams, pSurfaceEntry));
417 }
418
419 eStatus = MOS_STATUS_SUCCESS;
420
421 return eStatus;
422 }