| 1 |
/* |
| 2 |
* Copyright (c) 2024, 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 surface_state_heap_mgr.h |
| 24 |
//! \brief Render Engine Interfaces shared across platforms |
| 25 |
//! \details Platform Independent Hardware Interfaces |
| 26 |
//! |
| 27 |
#ifndef __SURFACE_STATE_HEAP_MGR_H__ |
| 28 |
#define __SURFACE_STATE_HEAP_MGR_H__ |
| 29 |
|
| 30 |
#include <iostream> |
| 31 |
#include "mos_os.h" |
| 32 |
#include "mhw_utilities.h" |
| 33 |
#include "mos_os_specific.h" |
| 34 |
#include "mos_interface.h" |
| 35 |
#include<map> |
| 36 |
|
| 37 |
#define MAX_SURFACE_STATES 512 |
| 38 |
using SURF_STATES_MAP = std::map<int32_t, uint32_t>; // key: SurfaceStateIndex(uiCurState), value: SurfaceStateEntryIndex(iCurrentSurfaceState) |
| 39 |
//! |
| 40 |
//! \brief Default size of area for sync, debugging, performance collecting |
| 41 |
//! |
| 42 |
#define SYNC_SIZE 128 // range: (128 ... 4096) |
| 43 |
|
| 44 |
//! |
| 45 |
//! \brief VEBOX Heap State Structure |
| 46 |
//! |
| 47 |
typedef struct _SURFACE_STATES_OBJ |
| 48 |
{ |
| 49 |
bool bBusy; // true if the state is in use (must sync before use) |
| 50 |
uint32_t dwSyncTag; // surface heap state sync tag |
| 51 |
} SURFACE_STATES_OBJ, *PSURFACE_STATES_OBJ; |
| 52 |
|
| 53 |
typedef struct _SURFACE_STATES_HEAP_OBJ |
| 54 |
{ |
| 55 |
uint32_t uiCurState; // Current surface State |
| 56 |
uint32_t uiNextState; // Next surface State |
| 57 |
uint32_t uiOffsetSync; // Offset of sync data in Heap |
| 58 |
uint32_t uiInstanceSize; // Size of single instance |
| 59 |
uint32_t uiStateHeapSize; // Total size of Surface States heap |
| 60 |
PSURFACE_STATES_OBJ pSurfStateObj; // Array of SURFACE_STATES_SYNC_OBJ |
| 61 |
MOS_RESOURCE osResource; // Graphics memory |
| 62 |
uint8_t *pLockedOsResourceMem; // Locked resource memory |
| 63 |
|
| 64 |
// Synchronization |
| 65 |
volatile uint32_t *pSync; // Pointer to sync area (when locked) |
| 66 |
uint32_t dwNextTag; // Next sync tag value to use |
| 67 |
uint32_t dwSyncTag; // Last sync tag completed |
| 68 |
} SURFACE_STATES_HEAP_OBJ, *PSURFACE_STATES_HEAP_OBJ; |
| 69 |
|
| 70 |
enum SURFACE_STATE_USED_HEAP_STATUS |
| 71 |
{ |
| 72 |
SURFACE_STATE_USED_HEAP_INITIALIZED, |
| 73 |
SURFACE_STATE_USED_HEAP_SENT |
| 74 |
}; |
| 75 |
|
| 76 |
class SurfaceStateHeapManager |
| 77 |
{ |
| 78 |
public: |
| 79 |
SurfaceStateHeapManager(PMOS_INTERFACE pOsInterface); |
| 80 |
MOS_STATUS CreateHeap(size_t surfStateSize); |
| 81 |
|
| 82 |
void RefreshSync(); |
| 83 |
|
| 84 |
MOS_STATUS DestroyHeap(); |
| 85 |
|
| 86 |
MOS_STATUS AssignSurfaceState(uint32_t surfaceStateEntryIndex, uint32_t &offset, uint8_t *&curSurfaceStatePtr, PMOS_RESOURCE &stateHeap, int32_t &surfaceStateIndex); |
| 87 |
|
| 88 |
MOS_STATUS GetSurfaceStateSize(uint32_t &size); |
| 89 |
MOS_STATUS GetSurfaceStateBasePtr(uint8_t *&ptr); |
| 90 |
|
| 91 |
~SurfaceStateHeapManager(); |
| 92 |
|
| 93 |
public: |
| 94 |
PMOS_INTERFACE m_osInterface = nullptr; |
| 95 |
SURFACE_STATES_HEAP_OBJ *m_surfStateHeap = nullptr; |
| 96 |
int m_surfHeapInUse = 0; |
| 97 |
SURF_STATES_MAP m_usedStates = {}; |
| 98 |
SURFACE_STATE_USED_HEAP_STATUS m_heapStatus = SURFACE_STATE_USED_HEAP_INITIALIZED; |
| 99 |
}; |
| 100 |
|
| 101 |
#endif // __SURFACE_STATE_HEAP_MGR_H__ |