1 /* 2 * Copyright (c) 2013-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 //! \file mos_defs.h 24 //! \brief 25 //! 26 //! 27 //! \file mos_defs.h 28 //! \brief Defines common types and macros across different platform 29 //! \details Defines common types and macros across different platform 30 //! 31 #ifndef __MOS_DEFS_H__ 32 #define __MOS_DEFS_H__ 33 34 // The below definitions will prevent other files from redefining types. 35 #define BASIC_TYPES_DEFINED 1 36 #define BOOL_DEF 1 37 38 #include <cstdio> // FILE 39 #include <cstdint> 40 #include <string> 41 #include <map> 42 #include <algorithm> 43 #include <memory> 44 #include "mos_defs_specific.h" 45 46 //! 47 //! \brief Macros for enabling / disabling debug prints and asserts 48 //! 49 50 //! Asserts are only enabled for debug drivers: 51 #define MOS_ASSERT_ENABLED (_DEBUG) 52 53 //! Debug messages are only enabled for debug or release-internal drivers. 54 //! If Asserts have been enabled manually, Messages should be enabled to: 55 #define MOS_MESSAGES_ENABLED (_DEBUG || _RELEASE_INTERNAL || MOS_ASSERT_ENABLED) 56 57 //! 58 //! \brief Macros for enabling / disabling development features in MOS 59 //! 60 61 //! Event Trace Logging a debug feature so should not be enabled in release builds 62 #if (_DEBUG || _RELEASE_INTERNAL) 63 #define MOS_EVENT_TRACE_DUMP_SUPPORTED 1 64 #else 65 #define MOS_EVENT_TRACE_DUMP_SUPPORTED 0 66 #endif 67 68 //! Command buffer dumps are a debug feature so should not be enabled in release builds 69 #define MOS_COMMAND_BUFFER_DUMP_SUPPORTED (_DEBUG || _RELEASE_INTERNAL) 70 71 //! Command res info dumps are a debug feature so should not be enabled in release builds 72 #define MOS_COMMAND_RESINFO_DUMP_SUPPORTED (_DEBUG || _RELEASE_INTERNAL) 73 74 typedef FILE* PFILE; //!< Pointer to a File 75 typedef FILE** PPFILE; //!< Pointer to a PFILE 76 typedef HMODULE* PHMODULE; //!< Pointer to an HMODULE 77 typedef const void* PCVOID; //!< Pointer to opaque const handle 78 typedef void** PPVOID; //!< Pointer to PVOID 79 typedef const char* PCCHAR; //!< Pointer to 8 bit signed const value 80 typedef char** PPCHAR; //!< Pointer to a PCHAR 81 82 using MOS_CONTEXT_HANDLE = void *; 83 84 //------------------------------------------------------------------------------ 85 // SECTION: Macros 86 // 87 // ABSTRACT: Provides basic helper utilities like mask bits, min, max, floor, 88 // ceil, align, etc. 89 //------------------------------------------------------------------------------ 90 91 //! 92 //! \brief Page Size 93 //! 94 #define MOS_PAGE_SIZE 4096 95 96 //! 97 //! \brief PI 98 //! 99 #define MOS_PI 3.14159265358979324f 100 101 //! 102 //! \def MOS_BYTES_TO_DWORDS(_b) 103 //! Convert \a b Bytes -> DWORDs 104 //! 105 #define MOS_BYTES_TO_DWORDS(_b) (((_b) + sizeof(uint32_t) - 1) / sizeof(uint32_t)) 106 107 //! 108 //! \def MOS_BYTES_TO_PAGES(_b) 109 //! Convert \a b Bytes -> Pages 110 //! 111 #define MOS_BYTES_TO_PAGES(_b) (((_b) + MOS_PAGE_SIZE - 1)/(MOS_PAGE_SIZE)) 112 113 //! 114 //! \def MOS_PAGES_TO_BYTES(_p) 115 //! Convert \a _p Pages -> Bytes 116 //! 117 #define MOS_PAGES_TO_BYTES(_p) ((_p) * MOS_PAGE_SIZE) 118 119 //! 120 //! \def MOS_KB_TO_BYTES(_kb) 121 //! Convert \a _kb Kilobyte -> Bytes 122 //! 123 #define MOS_KB_TO_BYTES(_kb) ((_kb) * 1024) 124 125 //! 126 //! \def MOS_MB_TO_BYTES(_mb) 127 //! Convert \a _mb Megabyte -> Bytes 128 //! 129 #define MOS_MB_TO_BYTES(_mb) (( _mb) * 1024 * 1024) 130 131 //! 132 //! \def MOS_IS_ALIGNED(_a, _alignment) 133 //! Is \a _a aligned to \a _alignment already? 134 //! 135 #define MOS_IS_ALIGNED(_a, _alignment) ((((_a) & ((_alignment)-1)) == 0) ? 1 : 0) 136 137 //! 138 //! \def MOS_ALIGN_CEIL(_a, _alignment) 139 //! Ceiling Align \a _a to \a _alignment 140 //! 141 #define MOS_ALIGN_CEIL(_a, _alignment) (((_a) + ((_alignment)-1)) & (~((_alignment)-1))) 142 143 //! 144 //! \def MOS_ALIGN_OFFSET(_a, _alignment) 145 //! Offset to align \a _a to \a _alignment 146 //! 147 #define MOS_ALIGN_OFFSET(_a, _alignment) ((~(_a) + 1) & (_alignment-1)) 148 149 //! 150 //! \def MOS_ALIGN_FLOOR(_a, _alignment) 151 //! Floor align \a _a to \a _alignment 152 //! 153 #define MOS_ALIGN_FLOOR(_a, _alignment) ((_a) & (~((_alignment)-1))) 154 155 //! 156 //! \def MOS_ROUNDUP_SHIFT(_a, _shift) 157 //! Roundup-shift \a _a by \a _shift 158 //! 159 #define MOS_ROUNDUP_SHIFT(_a, _shift) (((_a) + (1 << (_shift)) - 1) >> (_shift)) 160 161 //! 162 //! \def MOS_ROUNDUP_DIVIDE(_x, _divide) 163 //! Returns the \a x / \a divide rounded up 164 //! 165 #define MOS_ROUNDUP_DIVIDE(_x, _divide) (((_x) + (_divide) - 1) / (_divide)) 166 167 //! 168 //! \def MOS_NUMBER_OF_ELEMENTS(_A) 169 //! Returns the number of elements in array \a _A 170 //! 171 #define MOS_NUMBER_OF_ELEMENTS(_A) (sizeof(_A) / sizeof((_A)[0])) 172 173 //! 174 //! \def MOS_MIN(_a, _b) 175 //! Returns the lesser of \a _a and \a _b 176 //! 177 #define MOS_MIN(_a, _b) (((_a) < (_b)) ? (_a) : (_b)) 178 179 //! 180 //! \def MOS_MIN3(_a, _b, _c) 181 //! Returns the lesser of \a _a, \a _b and \a _c 182 //! 183 #define MOS_MIN3(_a, _b, _c) MOS_MIN(MOS_MIN(_a, _b), _c) 184 185 //! 186 //! \def MOS_MAX(_a, _b) 187 //! Returns the greater of \a a and \a _b 188 //! 189 #define MOS_MAX(_a, _b) (((_a) > (_b)) ? (_a) : (_b)) 190 191 //! 192 //! \def MOS_MAX3(_a, _b, _c) 193 //! Returns the greater of \a _a, \a _b and \a _c 194 //! 195 #define MOS_MAX3(_a, _b, _c) MOS_MAX(MOS_MAX(_a, _b), _c) 196 197 //! 198 //! \def MOS_CLAMP_MIN_MAX(_a, min, max) 199 //! Return value between min and max (either _a, min or max) 200 //! 201 #define MOS_CLAMP_MIN_MAX(_a, min, max) ((_a) < (min) ? (min) : MOS_MIN ((_a), (max))) 202 203 //! 204 //! \def MOS_UF_ROUND(a) 205 //! Rounds float \a a to an uint32_t 206 //! 207 #define MOS_UF_ROUND(a) ((uint32_t) ((a) + 0.5F)) 208 209 //! 210 //! \def MOS_F_ROUND(a) 211 //! Rounds float \a a to a int32_t 212 //! 213 #define MOS_F_ROUND(a) ((int32_t) ((a) + ((a) < 0 ? -0.5F : 0.5F))) 214 215 //! 216 //! \def MOS_MASK(_low, _high) 217 //! Returns a mask of bits set in the range from \a _low to \a _high 218 //! 219 #define MOS_MASK(_low, _high) ((((uint32_t)1) << (_high)) | \ 220 ((((uint32_t)1) << (_high)) - \ 221 (((uint32_t)1) << (_low)))) 222 //! 223 //! \def MOS_MASKBITS32(_low, _high) 224 //! Returns a mask of bits set in the range from \a _low to \a _high 225 //! 226 #define MOS_MASKBITS32(_low, _high) ((((((uint32_t)1) << (_high+1)) - 1) >> _low) << _low) 227 228 //! 229 //! \def MOS_MASKBITS64(_low, _high) 230 //! Returns a mask of bits set in the range from \a _low to \a _high 231 //! 232 #define MOS_MASKBITS64(_low, _high) ((((((uint64_t)1) << (_high+1)) - 1) >> _low) << _low) 233 234 //! 235 //! \def MOS_BITFIELD_BIT_N(n) 236 //! Returns an uint32_t with bit n set to 1 237 //! 238 #define MOS_BITFIELD_BIT_N(n) ((uint32_t)1 << (n)) 239 240 //! 241 //! \def MOS_BITFIELD_RANGE(_startbit, _endbit) 242 //! Calculates the number of bits between the startbit and the endbit (0 based). 243 //! 244 #define MOS_BITFIELD_RANGE(_startbit, _endbit) ((_endbit) - (_startbit) + 1) 245 246 //! 247 //! \def MOS_BITFIELD_BIT(_bit) 248 //! Definition declared for clarity when creating structs. 249 //! 250 #define MOS_BITFIELD_BIT(_bit) 1 251 252 //! 253 //! \def MOS_BIT_ON(_a, _bit) 254 //! Sets \a _bit in \a _a 255 //! 256 #define MOS_BIT_ON(_a, _bit) ((_a) |= (_bit)) 257 258 //! 259 //! \def MOS_BIT_OFF(_a, _bit) 260 //! Unsets \a _bit in \a _a 261 //! 262 #define MOS_BIT_OFF(_a, _bit) ((_a) &= ~(_bit)) 263 264 //! 265 //! \def MOS_IS_BIT_SET(_a, _bit) 266 //! Determines if \a _bit in \a _a is 1 267 //! 268 #define MOS_IS_BIT_SET(_a, _bit) ((_a) & (_bit)) 269 270 //! 271 //! \def MOS_ABS(_x) 272 //! Calculate the Absolute value of \a _x. 273 //! 274 #define MOS_ABS(_x) (((_x) > 0) ? (_x) : -(_x)) 275 276 //! 277 //! \def MOS_WITHIN_RANGE(_x, _min, _max) 278 //! Check that value within provided (_min, _max) range 279 //! 280 #define MOS_WITHIN_RANGE(_x, _min, _max) (((_x >= _min) && (_x <= _max)) ? (true) : (false)) 281 282 //! 283 //! \def MOS_ALIGNED(_alignment) 284 //! Structure Align to \a _alignment 285 //! 286 #if defined(_MSC_VER) 287 #define MOS_ALIGNED(_alignment) __declspec(align(_alignment)) 288 #else 289 #define MOS_ALIGNED(_alignment) __attribute__ ((aligned(_alignment))) 290 #endif 291 292 //! 293 //! \def MOS_UNUSED(param) 294 //! Fix compiling warning for unused parameter 295 //! 296 #ifndef MOS_UNUSED 297 #define MOS_UNUSED(param) (void)(param) 298 #endif 299 300 #define MOS_BITFIELD_VALUE(_x, _bits) ((_x) & ((1 << (_bits)) - 1)) 301 302 //------------------------------------------------------------------------------ 303 // 304 // Structures and enumerations 305 // 306 //------------------------------------------------------------------------------ 307 308 //! 309 //! \brief Function return codes. 310 //! 311 typedef enum _MOS_STATUS 312 { 313 MOS_STATUS_SUCCESS = 0, 314 MOS_STATUS_NO_SPACE = 1, 315 MOS_STATUS_INVALID_PARAMETER = 2, 316 MOS_STATUS_INVALID_HANDLE = 3, 317 MOS_STATUS_INVALID_FILE_SIZE = 4, 318 MOS_STATUS_NULL_POINTER = 5, 319 MOS_STATUS_FILE_EXISTS = 6, 320 MOS_STATUS_FILE_NOT_FOUND = 7, 321 MOS_STATUS_FILE_OPEN_FAILED = 8, 322 MOS_STATUS_FILE_READ_ONLY = 9, 323 MOS_STATUS_FILE_READ_FAILED = 10, 324 MOS_STATUS_FILE_WRITE_FAILED = 11, 325 MOS_STATUS_DIR_CREATE_FAILED = 12, 326 MOS_STATUS_SET_FILE_POINTER_FAILED = 13, 327 MOS_STATUS_LOAD_LIBRARY_FAILED = 14, 328 MOS_STATUS_MORE_DATA = 15, 329 MOS_STATUS_USER_CONTROL_MAX_NAME_SIZE = 16, 330 MOS_STATUS_USER_CONTROL_MIN_DATA_SIZE = 17, 331 MOS_STATUS_USER_CONTROL_MAX_DATA_SIZE = 18, 332 MOS_STATUS_USER_FEATURE_KEY_READ_FAILED = 19, 333 MOS_STATUS_USER_FEATURE_KEY_WRITE_FAILED = 20, 334 MOS_STATUS_EVENT_WAIT_REGISTER_FAILED = 21, 335 MOS_STATUS_EVENT_WAIT_UNREGISTER_FAILED = 22, 336 MOS_STATUS_USER_FEATURE_KEY_OPEN_FAILED = 23, 337 MOS_STATUS_HLT_INIT_FAILED = 24, 338 MOS_STATUS_UNIMPLEMENTED = 25, 339 MOS_STATUS_EXCEED_MAX_BB_SIZE = 26, 340 MOS_STATUS_PLATFORM_NOT_SUPPORTED = 27, 341 MOS_STATUS_CLIENT_AR_NO_SPACE = 28, 342 MOS_STATUS_HUC_KERNEL_FAILED = 29, 343 MOS_STATUS_NOT_ENOUGH_BUFFER = 30, 344 MOS_STATUS_UNINITIALIZED = 31, 345 MOS_STATUS_GPU_CONTEXT_ERROR = 32, 346 MOS_STATUS_STILL_DRAWING = 33, 347 MOS_STATUS_USER_FEATURE_READ_FAILED = 34, 348 MOS_STATUS_UNKNOWN = 35 349 } MOS_STATUS; 350 351 //! 352 //! \def MOS_SUCCEEDED(_status) 353 //! Generic test for success on any MOS_STATUS value 354 //! Currently only MOS_STATUS_SUCCESS indicates success 355 //! 356 #define MOS_SUCCEEDED(_status) \ 357 (_status == MOS_STATUS_SUCCESS) 358 359 //! 360 //! \def MOS_FAILED(_status) 361 //! Generic test for failure on any MOS_STATUS value 362 //! Currently any non MOS_STATUS_SUCCESS value indicates failure 363 //! 364 #define MOS_FAILED(_status) \ 365 (_status != MOS_STATUS_SUCCESS) 366 367 //! 368 //! \brief Feature Null Rendering Control Flags 369 //! 370 typedef struct _MOS_NULL_RENDERING_FLAGS { 371 union 372 { 373 struct 374 { 375 uint32_t CodecGlobal : 1; 376 uint32_t CtxRender : 1; 377 uint32_t CtxRender2 : 1; 378 uint32_t CtxVideo : 1; 379 uint32_t CtxVideo2 : 1; 380 uint32_t CtxVideo3 : 1; 381 uint32_t CtxVDBox2Video : 1; 382 uint32_t CtxVDBox2Video2 : 1; 383 uint32_t CtxVDBox2Video3 : 1; 384 uint32_t Reserved1 : 3; 385 uint32_t VPBitCopy : 1; 386 uint32_t VPDnDi : 1; 387 uint32_t VPDrDb : 1; 388 uint32_t VPFrc : 1; 389 uint32_t VPIs : 1; 390 uint32_t VPComp : 1; 391 uint32_t VP3P : 1; 392 uint32_t VPLgca : 1; 393 uint32_t VPGobal : 1; 394 uint32_t VPDpRotation : 1; 395 uint32_t VPFDFB : 1; 396 uint32_t VPEu3dLut : 1; 397 uint32_t Cm : 1; 398 uint32_t Mmc : 1; 399 uint32_t Reserved3 : 6; 400 }; 401 uint32_t Value; 402 }; 403 } MOS_NULL_RENDERING_FLAGS; 404 405 //! 406 //! \brief GPU Context definitions 407 //! 408 409 typedef enum _MOS_GPU_CONTEXT 410 { 411 MOS_GPU_CONTEXT_RENDER = 0, 412 MOS_GPU_CONTEXT_RENDER2 = 1, 413 MOS_GPU_CONTEXT_VIDEO = 2, 414 MOS_GPU_CONTEXT_VIDEO2 = 3, 415 MOS_GPU_CONTEXT_VIDEO3 = 4, 416 MOS_GPU_CONTEXT_VIDEO4 = 5, 417 MOS_GPU_CONTEXT_VEBOX = 6, 418 MOS_GPU_OVERLAY_CONTEXT = 7, 419 MOS_GPU_CONTEXT_VDBOX2_VIDEO = 8, // VDBox2 Decode 420 MOS_GPU_CONTEXT_VDBOX2_VIDEO2 = 9, // VDBox2 Decode Was 421 MOS_GPU_CONTEXT_VDBOX2_VIDEO3 = 10, // VDBox2 PAK 422 MOS_GPU_CONTEXT_RENDER3 = 11, // MDF(aka. CM) 423 MOS_GPU_CONTEXT_RENDER4 = 12, // MDF Custom context 424 MOS_GPU_CONTEXT_VEBOX2 = 13, // Vebox2 425 MOS_GPU_CONTEXT_COMPUTE = 14, //Compute Context 426 MOS_GPU_CONTEXT_CM_COMPUTE = 15, // MDF Compute 427 MOS_GPU_CONTEXT_RENDER_RA = 16, // render context for RA mode 428 MOS_GPU_CONTEXT_COMPUTE_RA = 17, // compute context for RA mode 429 MOS_GPU_CONTEXT_VIDEO5 = 18, // Decode Node 0 Split 2 430 MOS_GPU_CONTEXT_VIDEO6 = 19, // Encode Node 0 Split 2 431 MOS_GPU_CONTEXT_VIDEO7 = 20, // Decode Node 0 Split 3 432 MOS_GPU_CONTEXT_BLT = 21, 433 MOS_GPU_CONTEXT_TEE = 22, // TEE context 434 MOS_GPU_CONTEXT_MAX = 23, 435 MOS_GPU_CONTEXT_INVALID_HANDLE = 0xFFFFA 436 } MOS_GPU_CONTEXT, *PMOS_GPU_CONTEXT; 437 438 /*****************************************************************************\ 439 ENUM: MOS_GPU_COMPONENT_ID 440 \*****************************************************************************/ 441 typedef enum _MOS_GPU_COMPONENT_ID 442 { 443 MOS_GPU_COMPONENT_VP, 444 MOS_GPU_COMPONENT_CM, 445 MOS_GPU_COMPONENT_DECODE, 446 MOS_GPU_COMPONENT_ENCODE, 447 MOS_GPU_COMPONENT_MCPY, 448 MOS_GPU_COMPONENT_DEFAULT, 449 MOS_GPU_COMPONENT_ID_MAX 450 } MOS_GPU_COMPONENT_ID; 451 452 //! 453 //! \brief Enum for Stereoscopic 3D channel 454 //! 455 enum MOS_S3D_CHANNEL 456 { 457 MOS_S3D_NONE, 458 MOS_S3D_LEFT, 459 MOS_S3D_RIGHT 460 }; 461 462 //! 463 //! \brief Structure to OS plane offset 464 //! 465 struct MOS_PLANE_OFFSET 466 { 467 int iSurfaceOffset; //!< Plane surface offset 468 int iXOffset; //!< X offset - horizontal offset in pixels 469 int iYOffset; //!< Y offset - vertical offset in pixels 470 int iLockSurfaceOffset;//!< Locked surface offset 471 }; 472 typedef struct MOS_PLANE_OFFSET *PMOS_PLANE_OFFSET; 473 474 //! 475 //! \brief Structure to Resource offsets 476 //! 477 struct MOS_RESOURCE_OFFSETS 478 { 479 uint32_t BaseOffset; //!< Nearest page aligned byte offset to surface origin 480 uint32_t XOffset; //!< X coordinate to surface origin. In Bytes 481 uint32_t YOffset; //!< Y coordinate to surface origin. In rows. 482 }; 483 484 //! 485 //! \brief Enum for Memory Compression states 486 //! 487 enum MOS_MEMCOMP_STATE 488 { 489 MOS_MEMCOMP_DISABLED = 0, 490 MOS_MEMCOMP_HORIZONTAL, 491 MOS_MEMCOMP_VERTICAL, 492 MOS_MEMCOMP_MC, 493 MOS_MEMCOMP_RC 494 }; 495 typedef enum MOS_MEMCOMP_STATE *PMOS_MEMCOMP_STATE; 496 typedef uint32_t GPU_CONTEXT_HANDLE; 497 498 //! 499 //! \brief Enum for OS component 500 //! 501 enum MOS_COMPONENT 502 { 503 COMPONENT_UNKNOWN = 0, 504 COMPONENT_LibVA, 505 COMPONENT_EMULATION, 506 COMPONENT_CM, 507 COMPONENT_Encode, 508 COMPONENT_Decode, 509 COMPONENT_VPCommon, 510 COMPONENT_VPreP, 511 COMPONENT_CP, 512 COMPONENT_MEMDECOMP, 513 COMPONENT_MCPY, 514 COMPONENT_OCA, 515 }; 516 C_ASSERT(COMPONENT_OCA == 11); // When adding, update assert 517 518 #define MOS_MAX_ENGINE_INSTANCE_PER_CLASS 8 519 #define MOS_BUF_NAME_LENGTH 64 520 521 #define MOS_INVALID_HANDLE 0 522 #define MOS_DUMMY_FENCE (uint64_t)(-1) 523 524 525 namespace MediaUserSetting { 526 class MediaUserSetting; 527 class Value; 528 }; 529 530 typedef enum _NATIVE_FENCE_MODE 531 { 532 NATIVE_FENCE_MODE_DISABLE = 0, 533 NATIVE_FENCE_MODE_GPU_SYNC_BY_API = 1, 534 NATIVE_FENCE_MODE_GPU_SYNC_BY_CMD = 2 535 } NATIVE_FENCE_MODE; 536 537 using MediaUserSettingSharedPtr = std::shared_ptr<MediaUserSetting::MediaUserSetting>; 538 539 const unsigned int BITS_PER_BYTE = 8; 540 541 class OsContextNext; 542 typedef OsContextNext OsDeviceContext; 543 typedef OsDeviceContext *MOS_DEVICE_HANDLE; 544 545 struct MOS_CONTEXT_INTERFACE; 546 #endif // __MOS_DEFS_H__ 547