|
9 | 9 | #include "runtime/helpers/array_count.h"
|
10 | 10 | #include "runtime/gmm_helper/gmm_lib.h"
|
11 | 11 | #include "runtime/api/cl_types.h"
|
| 12 | +#include "validators.h" |
| 13 | +#include "runtime/mem_obj/image.h" |
12 | 14 |
|
13 | 15 | namespace OCLRT {
|
14 | 16 |
|
15 | 17 | // clang-format off
|
16 | 18 |
|
17 | 19 | //Initialize this with the required formats first.
|
18 | 20 | //Append the optional one later
|
19 |
| -const SurfaceFormatInfo readOnlySurfaceFormats[] = { |
| 21 | +const SurfaceFormatInfo SurfaceFormats::readOnlySurfaceFormats[] = { |
20 | 22 | {{CL_RGBA, CL_UNORM_INT8}, GMM_FORMAT_R8G8B8A8_UNORM_TYPE, GFX3DSTATE_SURFACEFORMAT_R8G8B8A8_UNORM , 0, 4, 1, 4},
|
21 | 23 | {{CL_RGBA, CL_UNORM_INT16}, GMM_FORMAT_R16G16B16A16_UNORM_TYPE, GFX3DSTATE_SURFACEFORMAT_R16G16B16A16_UNORM , 0, 4, 2, 8},
|
22 | 24 | {{CL_RGBA, CL_SIGNED_INT8}, GMM_FORMAT_R8G8B8A8_SINT_TYPE, GFX3DSTATE_SURFACEFORMAT_R8G8B8A8_SINT , 0, 4, 1, 4},
|
@@ -72,7 +74,7 @@ const SurfaceFormatInfo readOnlySurfaceFormats[] = {
|
72 | 74 | {{CL_RGBA, CL_SNORM_INT16}, GMM_FORMAT_R16G16B16A16_SNORM_TYPE, GFX3DSTATE_SURFACEFORMAT_R16G16B16A16_SNORM , 0, 4, 2, 8},
|
73 | 75 | };
|
74 | 76 |
|
75 |
| -const SurfaceFormatInfo writeOnlySurfaceFormats[] = { |
| 77 | +const SurfaceFormatInfo SurfaceFormats::writeOnlySurfaceFormats[] = { |
76 | 78 | {{CL_RGBA, CL_UNORM_INT8}, GMM_FORMAT_R8G8B8A8_UNORM_TYPE, GFX3DSTATE_SURFACEFORMAT_R8G8B8A8_UNORM , 0, 4, 1, 4},
|
77 | 79 | {{CL_RGBA, CL_UNORM_INT16}, GMM_FORMAT_R16G16B16A16_UNORM_TYPE, GFX3DSTATE_SURFACEFORMAT_R16G16B16A16_UNORM , 0, 4, 2, 8},
|
78 | 80 | {{CL_RGBA, CL_SIGNED_INT8}, GMM_FORMAT_R8G8B8A8_SINT_TYPE, GFX3DSTATE_SURFACEFORMAT_R8G8B8A8_SINT , 0, 4, 1, 4},
|
@@ -119,7 +121,7 @@ const SurfaceFormatInfo writeOnlySurfaceFormats[] = {
|
119 | 121 | {{CL_RGBA, CL_SNORM_INT16}, GMM_FORMAT_R16G16B16A16_SNORM_TYPE, GFX3DSTATE_SURFACEFORMAT_R16G16B16A16_SNORM , 0, 4, 2, 8},
|
120 | 122 | };
|
121 | 123 |
|
122 |
| -const SurfaceFormatInfo readWriteSurfaceFormats[] = { |
| 124 | +const SurfaceFormatInfo SurfaceFormats::readWriteSurfaceFormats[] = { |
123 | 125 | {{CL_RGBA, CL_UNORM_INT8}, GMM_FORMAT_R8G8B8A8_UNORM_TYPE, GFX3DSTATE_SURFACEFORMAT_R8G8B8A8_UNORM , 0, 4, 1, 4},
|
124 | 126 | {{CL_RGBA, CL_UNORM_INT16}, GMM_FORMAT_R16G16B16A16_UNORM_TYPE, GFX3DSTATE_SURFACEFORMAT_R16G16B16A16_UNORM , 0, 4, 2, 8},
|
125 | 127 | {{CL_RGBA, CL_SIGNED_INT8}, GMM_FORMAT_R8G8B8A8_SINT_TYPE, GFX3DSTATE_SURFACEFORMAT_R8G8B8A8_SINT , 0, 4, 1, 4},
|
@@ -167,40 +169,105 @@ const SurfaceFormatInfo readWriteSurfaceFormats[] = {
|
167 | 169 | };
|
168 | 170 |
|
169 | 171 | #if SUPPORT_YUV
|
170 |
| -const SurfaceFormatInfo packedYuvSurfaceFormats[] = { |
| 172 | +const SurfaceFormatInfo SurfaceFormats::packedYuvSurfaceFormats[] = { |
171 | 173 | {{CL_YUYV_INTEL, CL_UNORM_INT8}, GMM_FORMAT_YUY2, GFX3DSTATE_SURFACEFORMAT_YCRCB_NORMAL , 0, 2, 1, 2},
|
172 | 174 | {{CL_UYVY_INTEL, CL_UNORM_INT8}, GMM_FORMAT_UYVY, GFX3DSTATE_SURFACEFORMAT_YCRCB_SWAPY , 0, 2, 1, 2},
|
173 | 175 | {{CL_YVYU_INTEL, CL_UNORM_INT8}, GMM_FORMAT_YVYU, GFX3DSTATE_SURFACEFORMAT_YCRCB_SWAPUV , 0, 2, 1, 2},
|
174 | 176 | {{CL_VYUY_INTEL, CL_UNORM_INT8}, GMM_FORMAT_VYUY, GFX3DSTATE_SURFACEFORMAT_YCRCB_SWAPUVY , 0, 2, 1, 2}
|
175 | 177 | };
|
176 | 178 |
|
177 |
| -const SurfaceFormatInfo planarYuvSurfaceFormats[] = { |
| 179 | +const SurfaceFormatInfo SurfaceFormats::planarYuvSurfaceFormats[] = { |
178 | 180 | {{CL_NV12_INTEL, CL_UNORM_INT8}, GMM_FORMAT_NV12, GFX3DSTATE_SURFACEFORMAT_NV12 , 0, 1, 1, 1}
|
179 | 181 | };
|
180 | 182 |
|
181 |
| -const size_t numPackedYuvSurfaceFormats = arrayCount(packedYuvSurfaceFormats); |
182 |
| -const size_t numPlanarYuvSurfaceFormats = arrayCount(planarYuvSurfaceFormats); |
| 183 | + |
183 | 184 | #endif
|
184 | 185 |
|
185 |
| -const SurfaceFormatInfo readOnlyDepthSurfaceFormats[] = { |
| 186 | +const SurfaceFormatInfo SurfaceFormats::readOnlyDepthSurfaceFormats[] = { |
186 | 187 | {{ CL_DEPTH, CL_FLOAT}, GMM_FORMAT_R32_FLOAT_TYPE, GFX3DSTATE_SURFACEFORMAT_R32_FLOAT , 0, 1, 4, 4},
|
187 | 188 | {{ CL_DEPTH, CL_UNORM_INT16}, GMM_FORMAT_R16_UNORM_TYPE, GFX3DSTATE_SURFACEFORMAT_R16_UNORM , 0, 1, 2, 2},
|
188 | 189 | {{ CL_DEPTH_STENCIL, CL_UNORM_INT24}, GMM_FORMAT_GENERIC_32BIT, GFX3DSTATE_SURFACEFORMAT_R24_UNORM_X8_TYPELESS , 0, 1, 4, 4},
|
189 | 190 | {{ CL_DEPTH_STENCIL, CL_FLOAT}, GMM_FORMAT_R32G32_FLOAT_TYPE, GFX3DSTATE_SURFACEFORMAT_R32_FLOAT_X8X24_TYPELESS, 0, 2, 4, 8}
|
190 | 191 | };
|
191 | 192 |
|
192 |
| -const SurfaceFormatInfo readWriteDepthSurfaceFormats[] = { |
| 193 | +const SurfaceFormatInfo SurfaceFormats::readWriteDepthSurfaceFormats[] = { |
193 | 194 | {{ CL_DEPTH, CL_FLOAT}, GMM_FORMAT_R32_FLOAT_TYPE, GFX3DSTATE_SURFACEFORMAT_R32_FLOAT , 0, 1, 4, 4},
|
194 | 195 | {{ CL_DEPTH, CL_UNORM_INT16}, GMM_FORMAT_R16_UNORM_TYPE, GFX3DSTATE_SURFACEFORMAT_R16_UNORM , 0, 1, 2, 2}
|
195 | 196 | };
|
196 | 197 |
|
197 |
| -const size_t numReadOnlyDepthSurfaceFormats = arrayCount(readOnlyDepthSurfaceFormats); |
198 |
| -const size_t numReadWriteDepthSurfaceFormats = arrayCount(readWriteDepthSurfaceFormats); |
| 198 | +ArrayRef<const SurfaceFormatInfo> SurfaceFormats::readOnly() noexcept { |
| 199 | + return ArrayRef<const SurfaceFormatInfo>(readOnlySurfaceFormats); |
| 200 | +} |
| 201 | + |
| 202 | +ArrayRef<const SurfaceFormatInfo> SurfaceFormats::writeOnly() noexcept { |
| 203 | + return ArrayRef<const SurfaceFormatInfo>(writeOnlySurfaceFormats); |
| 204 | +} |
| 205 | + |
| 206 | +ArrayRef<const SurfaceFormatInfo> SurfaceFormats::readWrite() noexcept { |
| 207 | + return ArrayRef<const SurfaceFormatInfo>(readWriteSurfaceFormats); |
| 208 | +} |
| 209 | + |
| 210 | +ArrayRef<const SurfaceFormatInfo> SurfaceFormats::packedYuv() noexcept { |
| 211 | +#if SUPPORT_YUV |
| 212 | + return ArrayRef<const SurfaceFormatInfo>(packedYuvSurfaceFormats); |
| 213 | +#else |
| 214 | + return ArrayRef<const SurfaceFormatInfo>(); |
| 215 | +#endif |
| 216 | +} |
| 217 | + |
| 218 | +ArrayRef<const SurfaceFormatInfo> SurfaceFormats::planarYuv() noexcept { |
| 219 | +#if SUPPORT_YUV |
| 220 | + return ArrayRef<const SurfaceFormatInfo>(planarYuvSurfaceFormats); |
| 221 | +#else |
| 222 | + return ArrayRef<const SurfaceFormatInfo>(); |
| 223 | +#endif |
| 224 | +} |
| 225 | + |
| 226 | +ArrayRef<const SurfaceFormatInfo> SurfaceFormats::readOnlyDepth() noexcept { |
| 227 | + return ArrayRef<const SurfaceFormatInfo>(readOnlyDepthSurfaceFormats); |
| 228 | +} |
| 229 | + |
| 230 | +ArrayRef<const SurfaceFormatInfo> SurfaceFormats::readWriteDepth() noexcept { |
| 231 | + return ArrayRef<const SurfaceFormatInfo>(readWriteDepthSurfaceFormats); |
| 232 | +} |
199 | 233 |
|
| 234 | +ArrayRef<const SurfaceFormatInfo> SurfaceFormats::surfaceFormats(cl_mem_flags flags) noexcept { |
| 235 | + if (flags & CL_MEM_READ_ONLY) { |
| 236 | + return readOnly(); |
| 237 | + } |
| 238 | + else if (flags & CL_MEM_WRITE_ONLY) { |
| 239 | + return writeOnly(); |
| 240 | + } |
| 241 | + else { |
| 242 | + return readWrite(); |
| 243 | + } |
| 244 | +} |
200 | 245 |
|
201 |
| -const size_t numReadOnlySurfaceFormats = arrayCount(readOnlySurfaceFormats); |
202 |
| -const size_t numWriteOnlySurfaceFormats = arrayCount(writeOnlySurfaceFormats); |
203 |
| -const size_t numReadWriteSurfaceFormats = arrayCount(readWriteSurfaceFormats); |
| 246 | +ArrayRef<const SurfaceFormatInfo> SurfaceFormats::surfaceFormats(cl_mem_flags flags, const cl_image_format *imageFormat) noexcept { |
| 247 | + if (OCLRT::IsNV12Image(imageFormat)) { |
| 248 | + return planarYuv(); |
| 249 | + } |
| 250 | + else if (IsPackedYuvImage(imageFormat)) { |
| 251 | + return packedYuv(); |
| 252 | + } |
| 253 | + else if (Image::isDepthFormat(*imageFormat)) { |
| 254 | + if (flags & CL_MEM_READ_ONLY) { |
| 255 | + return readOnlyDepth(); |
| 256 | + } |
| 257 | + else { |
| 258 | + return readWriteDepth(); |
| 259 | + } |
| 260 | + } |
| 261 | + else if (flags & CL_MEM_READ_ONLY) { |
| 262 | + return readOnly(); |
| 263 | + } |
| 264 | + else if (flags & CL_MEM_WRITE_ONLY) { |
| 265 | + return writeOnly(); |
| 266 | + } |
| 267 | + else { |
| 268 | + return readWrite(); |
| 269 | + } |
| 270 | +} |
204 | 271 |
|
205 | 272 | // clang-format on
|
206 | 273 | } // namespace OCLRT
|
0 commit comments