1 /*
2 * Copyright (c) 2022-2023, 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 #include "vp_hal_ddi_utils.h"
24 #include "vp_utils.h"
25 #include "hal_kerneldll_next.h"
26 
ConvertVphalSurfaceToMosSurface(PVPHAL_SURFACE surface)27 MOS_SURFACE VpHalDDIUtils::ConvertVphalSurfaceToMosSurface(PVPHAL_SURFACE surface)
28 {
29     MOS_SURFACE outSurface = {};
30     MOS_ZeroMemory(&outSurface, sizeof(MOS_SURFACE));
31 
32     if (surface != nullptr)
33     {
34         outSurface.OsResource        = surface->OsResource;
35         outSurface.Format            = surface->Format;
36         outSurface.dwWidth           = surface->dwWidth;
37         outSurface.dwHeight          = surface->dwHeight;
38         outSurface.TileType          = surface->TileType;
39         outSurface.TileModeGMM       = surface->TileModeGMM;
40         outSurface.bGMMTileEnabled   = surface->bGMMTileEnabled;
41         outSurface.dwDepth           = surface->dwDepth;
42         outSurface.dwPitch           = surface->dwPitch;
43         outSurface.dwSlicePitch      = surface->dwSlicePitch;
44         outSurface.dwOffset          = surface->dwOffset;
45         outSurface.bCompressible     = surface->bCompressible;
46         outSurface.bIsCompressed     = surface->bIsCompressed;
47         outSurface.CompressionMode   = surface->CompressionMode;
48         outSurface.CompressionFormat = surface->CompressionFormat;
49     }
50 
51     return outSurface;
52 }
53 
GetSurfaceColorPack(MOS_FORMAT format)54 VPHAL_COLORPACK VpHalDDIUtils::GetSurfaceColorPack(
55     MOS_FORMAT format)
56 {
57     VP_FUNC_CALL();
58     VPHAL_COLORPACK colorPack = VPHAL_COLORPACK_UNKNOWN;
59 
60     static const std::map<const VPHAL_COLORPACK, const MosFormatArray> colorPackMap =
61     {
62         {VPHAL_COLORPACK_400, {Format_Y8,
63                                Format_Y16S,
64                                Format_Y16U,
65                                Format_400P}},
66         {VPHAL_COLORPACK_420, {Format_IMC1,
67                                Format_IMC2,
68                                Format_IMC3,
69                                Format_IMC4,
70                                Format_NV12,
71                                Format_NV21,
72                                Format_YV12,
73                                Format_I420,
74                                Format_IYUV,
75                                Format_P010,
76                                Format_P016}},
77         {VPHAL_COLORPACK_422, {Format_YUY2,
78                                Format_YUYV,
79                                Format_YVYU,
80                                Format_UYVY,
81                                Format_VYUY,
82                                Format_P208,
83                                Format_422H,
84                                Format_422V,
85                                Format_Y210,
86                                Format_Y216}},
87         {VPHAL_COLORPACK_444, {Format_A8R8G8B8,
88                                Format_X8R8G8B8,
89                                Format_A8B8G8R8,
90                                Format_X8B8G8R8,
91                                Format_A16B16G16R16,
92                                Format_A16R16G16B16,
93                                Format_R5G6B5,
94                                Format_R8G8B8,
95                                Format_RGBP,
96                                Format_BGRP,
97                                Format_Y416,
98                                Format_Y410,
99                                Format_AYUV,
100                                Format_AUYV,
101                                Format_444P,
102                                Format_R10G10B10A2,
103                                Format_B10G10R10A2,
104                                Format_A16B16G16R16F,
105                                Format_A16R16G16B16F}},
106         {VPHAL_COLORPACK_411, {Format_411P}}
107     };
108     for (auto mapIt = colorPackMap.begin(); mapIt != colorPackMap.end(); mapIt++)
109     {
110         auto &iFormatArray = mapIt->second;
111         auto  iter         = std::find(iFormatArray.begin(), iFormatArray.end(), format);
112         if (iter == iFormatArray.end())
113         {
114             continue;
115         }
116         return mapIt->first;
117     }
118 
119     VP_PUBLIC_ASSERTMESSAGE("Input format color pack unknown.");
120     return VPHAL_COLORPACK_UNKNOWN;
121 }
122 
GetSurfaceBitDepth(MOS_FORMAT format)123 uint32_t VpHalDDIUtils::GetSurfaceBitDepth(
124     MOS_FORMAT format)
125 {
126     uint32_t bitDepth = 0;
127 
128     VP_FUNC_CALL();
129 
130     static const std::map<const uint32_t, const MosFormatArray> bitDepthMap =
131     {
132         {8, {Format_IMC1,
133              Format_IMC2,
134              Format_IMC3,
135              Format_IMC4,
136              Format_NV12,
137              Format_NV21,
138              Format_YV12,
139              Format_I420,
140              Format_IYUV,
141              Format_YUY2,
142              Format_YUYV,
143              Format_YVYU,
144              Format_UYVY,
145              Format_VYUY,
146              Format_P208,
147              Format_422H,
148              Format_422V,
149              Format_R5G6B5,
150              Format_R8G8B8,
151              Format_A8R8G8B8,
152              Format_X8R8G8B8,
153              Format_A8B8G8R8,
154              Format_X8B8G8R8,
155              Format_444P,
156              Format_AYUV,
157              Format_AUYV,
158              Format_RGBP,
159              Format_BGRP}},
160         {10, {Format_P010,
161               Format_R10G10B10A2,
162               Format_B10G10R10A2,
163               Format_Y210,
164               Format_Y410,
165               Format_P210}},
166         {16, {Format_A16B16G16R16,
167               Format_A16R16G16B16,
168               Format_A16B16G16R16F,
169               Format_A16R16G16B16F,
170               Format_P016,
171               Format_Y416,
172               Format_Y216,
173               Format_P216}},
174     };
175     for (auto mapIt = bitDepthMap.begin(); mapIt != bitDepthMap.end(); mapIt++)
176     {
177         auto &iFormatArray = mapIt->second;
178         auto  iter         = std::find(iFormatArray.begin(), iFormatArray.end(), format);
179         if (iter == iFormatArray.end())
180         {
181             continue;
182         }
183         return mapIt->first;
184     }
185 
186     VP_PUBLIC_ASSERTMESSAGE("Unknown Input format for bit depth.");
187     return 0;
188 }