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 //!
24 //! \file     vphal_common_specific_next.c
25 //! \brief    Definition common utilities for vphal
26 //! \details  Definition common utilities for vphal including:
27 //!           some macro, enum, union, structure, function
28 
29 #include "vp_utils.h"
30 #include "mos_interface.h"
VpHal_GetSurfaceInfo(PMOS_INTERFACE osInterface,PVPHAL_GET_SURFACE_INFO info,PVPHAL_SURFACE surface)31 MOS_STATUS VpHal_GetSurfaceInfo(
32     PMOS_INTERFACE          osInterface,
33     PVPHAL_GET_SURFACE_INFO info,
34     PVPHAL_SURFACE          surface)
35 {
36     MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
37 
38     VP_PUBLIC_ASSERT(osInterface);
39     VP_PUBLIC_ASSERT(info);
40     VP_PUBLIC_ASSERT(surface);
41 
42     PMOS_RESOURCE     resource   = &surface->OsResource;
43     MOS_SURFACE       resDetails = {};
44     MOS_MEMCOMP_STATE mmcMode    = MOS_MEMCOMP_DISABLED;
45 
46     VP_PUBLIC_ASSERT(!Mos_ResourceIsNull(&surface->OsResource));
47     MOS_ZeroMemory(&resDetails, sizeof(MOS_SURFACE));
48     resDetails.dwArraySlice = info->ArraySlice;
49     resDetails.dwMipSlice   = info->MipSlice;
50     resDetails.S3dChannel   = info->S3dChannel;
51     resDetails.Format       = surface->Format;
52     VP_PUBLIC_CHK_STATUS(osInterface->pfnGetResourceInfo(osInterface, &surface->OsResource, &resDetails));
53 
54     if (resDetails.Format == Format_420O)
55     {
56         resDetails.Format = Format_NV12;
57     }
58 
59     // Get resource information
60     surface->dwWidth         = resDetails.dwWidth;
61     surface->dwHeight        = resDetails.dwHeight;
62     surface->dwPitch         = resDetails.dwPitch;
63     surface->dwSlicePitch    = resDetails.dwSlicePitch;
64     surface->dwDepth         = resDetails.dwDepth;
65     surface->TileType        = resDetails.TileType;
66     surface->TileModeGMM     = resDetails.TileModeGMM;
67     surface->bGMMTileEnabled = resDetails.bGMMTileEnabled;
68     surface->bOverlay        = resDetails.bOverlay;
69     surface->bFlipChain      = resDetails.bFlipChain;
70     surface->Format          = resDetails.Format;
71     surface->bCompressible   = resDetails.bCompressible;
72     surface->bIsCompressed   = resDetails.bIsCompressed;
73 
74     MOS_ZeroMemory(&mmcMode, sizeof(mmcMode));
75     osInterface->pfnGetMemoryCompressionMode(osInterface, &surface->OsResource, &mmcMode);
76 
77     if (mmcMode &&
78         (surface->TileType == MOS_TILE_Y ||
79             surface->TileType == MOS_TILE_YS))
80     {
81         surface->bCompressible   = true;
82         surface->bIsCompressed   = true;
83         surface->CompressionMode = (MOS_RESOURCE_MMC_MODE)mmcMode;
84 
85         osInterface->pfnGetMemoryCompressionFormat(osInterface, &surface->OsResource, &surface->CompressionFormat);
86     }
87     else
88     {
89         // Do not modify the bCompressible flag even MmcMode is disable, since the surface size/pitch may be different
90         // between Compressible and Uncompressible, which will affect the DN surface allocation.
91         surface->bIsCompressed     = false;
92         surface->CompressionMode   = MOS_MMC_DISABLED;
93         surface->CompressionFormat = 0;
94     }
95 
96     if (IS_RGB32_FORMAT(surface->Format) ||
97         IS_RGB16_FORMAT(surface->Format) ||
98         surface->Format == Format_RGB ||
99         surface->Format == Format_Y410)
100     {
101         surface->dwOffset                    = resDetails.RenderOffset.RGB.BaseOffset;
102         surface->YPlaneOffset.iSurfaceOffset = resDetails.RenderOffset.RGB.BaseOffset;
103         surface->YPlaneOffset.iXOffset       = resDetails.RenderOffset.RGB.XOffset;
104         surface->YPlaneOffset.iYOffset       = resDetails.RenderOffset.RGB.YOffset;
105     }
106     else  // YUV or PL3_RGB
107     {
108         // Get Y plane information (plane offset, X/Y offset)
109         surface->dwOffset                        = resDetails.RenderOffset.YUV.Y.BaseOffset;
110         surface->YPlaneOffset.iSurfaceOffset     = resDetails.RenderOffset.YUV.Y.BaseOffset;
111         surface->YPlaneOffset.iXOffset           = resDetails.RenderOffset.YUV.Y.XOffset;
112         surface->YPlaneOffset.iYOffset           = resDetails.RenderOffset.YUV.Y.YOffset;
113         surface->YPlaneOffset.iLockSurfaceOffset = resDetails.LockOffset.YUV.Y;
114 
115         // Get U/UV plane information (plane offset, X/Y offset)
116         surface->UPlaneOffset.iSurfaceOffset     = resDetails.RenderOffset.YUV.U.BaseOffset;
117         surface->UPlaneOffset.iXOffset           = resDetails.RenderOffset.YUV.U.XOffset;
118         surface->UPlaneOffset.iYOffset           = resDetails.RenderOffset.YUV.U.YOffset;
119         surface->UPlaneOffset.iLockSurfaceOffset = resDetails.LockOffset.YUV.U;
120 
121         // Get V plane information (plane offset, X/Y offset)
122         surface->VPlaneOffset.iSurfaceOffset     = resDetails.RenderOffset.YUV.V.BaseOffset;
123         surface->VPlaneOffset.iXOffset           = resDetails.RenderOffset.YUV.V.XOffset;
124         surface->VPlaneOffset.iYOffset           = resDetails.RenderOffset.YUV.V.YOffset;
125         surface->VPlaneOffset.iLockSurfaceOffset = resDetails.LockOffset.YUV.V;
126     }
127 
128     eStatus = MOS_STATUS_SUCCESS;
129     goto finish;
130 
131 finish:
132     return eStatus;
133 }
134 
VpHal_AllocParamsInitType(PMOS_ALLOC_GFXRES_PARAMS allocParams,PVPHAL_SURFACE surface,MOS_GFXRES_TYPE defaultResType,MOS_TILE_TYPE defaultTileType)135 void VpHal_AllocParamsInitType(
136     PMOS_ALLOC_GFXRES_PARAMS allocParams,
137     PVPHAL_SURFACE           surface,
138     MOS_GFXRES_TYPE          defaultResType,
139     MOS_TILE_TYPE            defaultTileType)
140 {
141     VP_PUBLIC_ASSERT(allocParams);
142     VP_PUBLIC_ASSERT(surface);
143 
144     // First time allocation. Caller must specify default params
145     allocParams->Type     = defaultResType;
146     allocParams->TileType = defaultTileType;
147 }