| 1 |
/* |
| 2 |
* Copyright (c) 2018, 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 cm_surface_state.h |
| 24 |
//! \brief Contains Class CmSurfaceState definitions |
| 25 |
//! |
| 26 |
#pragma once |
| 27 |
|
| 28 |
#include "cm_def.h" |
| 29 |
#include "cm_hal.h" |
| 30 |
#include "cm_device_rt.h" |
| 31 |
|
| 32 |
class CmSSH; |
| 33 |
|
| 34 |
class CmSurfaceState |
| 35 |
{ |
| 36 |
public: |
| 37 |
CmSurfaceState(CM_HAL_STATE *cmhal); |
| 38 |
virtual ~CmSurfaceState() {} |
| 39 |
CM_RETURN_CODE Initialize(MOS_RESOURCE *resource); |
| 40 |
// Query apis for SSH |
| 41 |
virtual uint32_t GetNumBte() {return 1; } |
| 42 |
virtual uint32_t GetNumPlane() {return 1; } |
| 43 |
virtual int isAVS() {return 0; } |
| 44 |
virtual int isAVS(int surfIdx) {return 0; } |
| 45 |
virtual uint8_t *GetSurfaceState(int index) = 0; |
| 46 |
virtual uint32_t GetSurfaceOffset(int index) {return 0; } |
| 47 |
virtual bool IsRenderTarget() {return true; } |
| 48 |
virtual MOS_RESOURCE *GetResource(uint32_t index) |
| 49 |
{ |
| 50 |
if (m_resource == nullptr) |
| 51 |
return nullptr; |
| 52 |
m_resourceData = *m_resource; |
| 53 |
return &m_resourceData; |
| 54 |
} |
| 55 |
|
| 56 |
virtual MOS_MEMCOMP_STATE GetMmcState(int index) {return MOS_MEMCOMP_DISABLED; } |
| 57 |
|
| 58 |
inline void SetMemoryObjectControl(uint16_t moc) {m_memoryObjectControl = moc; } |
| 59 |
inline MOS_RESOURCE *GetResource() |
| 60 |
{ |
| 61 |
if (m_resource == nullptr) |
| 62 |
return nullptr; |
| 63 |
m_resourceData = *m_resource; |
| 64 |
return &m_resourceData; |
| 65 |
} |
| 66 |
inline void Recorded(CmSSH *ssh, uint32_t btIdx, uint32_t bteIdx, uint32_t ssIdx) |
| 67 |
{ |
| 68 |
m_ssh = ssh; |
| 69 |
m_btIdx = btIdx; |
| 70 |
m_bteIdx = bteIdx; |
| 71 |
m_ssIdx = ssIdx; |
| 72 |
} |
| 73 |
inline void GetRecordedInfo(CmSSH **ssh, int32_t *btIdx, int32_t *bteIdx, int32_t *ssIdx) |
| 74 |
{ |
| 75 |
*ssh = m_ssh; |
| 76 |
*btIdx = m_btIdx; |
| 77 |
*bteIdx = m_bteIdx; |
| 78 |
*ssIdx = m_ssIdx; |
| 79 |
} |
| 80 |
|
| 81 |
protected: |
| 82 |
uint32_t GetCacheabilityControl(); |
| 83 |
|
| 84 |
CM_HAL_STATE *m_cmhal; |
| 85 |
RENDERHAL_INTERFACE *m_renderhal; |
| 86 |
|
| 87 |
// resource |
| 88 |
MOS_RESOURCE *m_resource; |
| 89 |
MOS_RESOURCE m_resourceData; |
| 90 |
|
| 91 |
// surface state related parameters |
| 92 |
uint16_t m_memoryObjectControl; |
| 93 |
|
| 94 |
// record in ssh |
| 95 |
CmSSH *m_ssh; |
| 96 |
int m_btIdx; |
| 97 |
int m_bteIdx; |
| 98 |
int m_ssIdx; |
| 99 |
|
| 100 |
}; |
| 101 |
|
| 102 |
|
| 103 |
class CmSurfaceState2Dor3D : public CmSurfaceState |
| 104 |
{ |
| 105 |
public: |
| 106 |
CmSurfaceState2Dor3D(CM_HAL_STATE *cmhal); |
| 107 |
CM_RETURN_CODE Initialize(MOS_RESOURCE *resource, bool isAvs = false, bool isSampler = false); |
| 108 |
MOS_STATUS GenerateSurfaceState(CM_HAL_SURFACE2D_SURFACE_STATE_PARAM *param = nullptr); |
| 109 |
|
| 110 |
// global parameters to generate default surface state |
| 111 |
inline void SetRenderTarget(bool flag) {m_isRenderTarget = flag; } |
| 112 |
inline void SetFrameType(CM_FRAME_TYPE frameType) {m_frameType = frameType; } |
| 113 |
inline void SetFormat(MOS_FORMAT format) { m_format = format; } |
| 114 |
inline void SetUserDimension(uint32_t width, uint32_t height, uint32_t depth) |
| 115 |
{ |
| 116 |
m_userWidth = width; |
| 117 |
m_userHeight = height; |
| 118 |
m_userDepth = depth; |
| 119 |
} |
| 120 |
inline void SetRotationFlag(uint32_t rotation) { m_rotation = rotation; } |
| 121 |
inline void SetChromaSitting(int chromaSitting){ m_chromaSitting = chromaSitting; } |
| 122 |
|
| 123 |
// Query apis for SSH |
| 124 |
uint32_t GetNumPlane() {return m_numPlane; } |
| 125 |
uint32_t GetNumBte() {return m_numPlane; } |
| 126 |
int isAVS() {return m_avsUsed; } |
| 127 |
int isAVS(int surfIdx) {return m_planeParams[surfIdx].isAvs; } |
| 128 |
uint8_t *GetSurfaceState(int index) {return m_cmds + index * m_maxStateSize; } |
| 129 |
uint32_t GetSurfaceOffset(int index) {return m_surfOffsets[index]; } |
| 130 |
bool IsRenderTarget() {return m_isRenderTarget; } |
| 131 |
MOS_MEMCOMP_STATE GetMmcState(int index) {return m_mmcState; } |
| 132 |
|
| 133 |
protected: |
| 134 |
struct CmSurfaceParamsPerPlane |
| 135 |
{ |
| 136 |
uint32_t isAvs; |
| 137 |
uint32_t width; |
| 138 |
uint32_t height; |
| 139 |
uint32_t format; |
| 140 |
uint32_t pitch; |
| 141 |
uint32_t xoffset; |
| 142 |
uint32_t yoffset; |
| 143 |
uint8_t planeID; |
| 144 |
}; |
| 145 |
MOS_STATUS RefreshSurfaceInfo(CM_HAL_SURFACE2D_SURFACE_STATE_PARAM *param = nullptr); |
| 146 |
MOS_STATUS UpdateSurfaceState(); |
| 147 |
MOS_STATUS SetPerPlaneParam(); |
| 148 |
int GetPlaneDefinitionRender(); |
| 149 |
int GetPlaneDefinitionMedia(); |
| 150 |
void GetDIUVOffSet(); |
| 151 |
bool IsFormatMMCSupported(MOS_FORMAT format); |
| 152 |
uint8_t GetDirection(); |
| 153 |
|
| 154 |
// surface state related parameters |
| 155 |
MOS_FORMAT m_format; |
| 156 |
uint32_t m_width; |
| 157 |
uint32_t m_height; |
| 158 |
uint32_t m_depth; |
| 159 |
uint32_t m_pitch; |
| 160 |
uint32_t m_qPitch; |
| 161 |
uint32_t m_tile; |
| 162 |
MOS_TILE_MODE_GMM m_tileModeGMM; |
| 163 |
bool m_bGMMTileEnabled; |
| 164 |
uint32_t m_isCompressed; |
| 165 |
uint32_t m_compressionMode; |
| 166 |
MOS_MEMCOMP_STATE m_mmcState; |
| 167 |
uint32_t m_compressionFormat; |
| 168 |
uint32_t m_rotation; |
| 169 |
int m_chromaSitting; |
| 170 |
uint32_t m_surfaceXOffset; |
| 171 |
uint32_t m_surfaceYOffset; |
| 172 |
CM_FRAME_TYPE m_frameType; |
| 173 |
bool m_isRenderTarget; |
| 174 |
CmSurfaceParamsPerPlane m_planeParams[4]; |
| 175 |
uint32_t m_paletteID; |
| 176 |
|
| 177 |
// user defined dimension |
| 178 |
uint32_t m_userWidth; |
| 179 |
uint32_t m_userHeight; |
| 180 |
uint32_t m_userDepth; |
| 181 |
|
| 182 |
// offsets per plane |
| 183 |
uint32_t m_surfOffsets[4]; // these offsets shouldn't be changed by users, so not include them in CmSurfaceStateParamsPerPlane |
| 184 |
uint32_t m_xOffsets[4]; |
| 185 |
uint32_t m_yOffsets[4]; |
| 186 |
uint32_t m_lockOffsets[4]; |
| 187 |
|
| 188 |
// surface state commands |
| 189 |
uint32_t m_maxStateSize; |
| 190 |
uint32_t m_avsUsed; |
| 191 |
uint32_t m_numPlane; |
| 192 |
uint8_t m_cmds[256]; |
| 193 |
|
| 194 |
bool m_pixelPitch; |
| 195 |
bool m_isWidthInDWord; |
| 196 |
bool m_isVme; |
| 197 |
|
| 198 |
// avs parameters |
| 199 |
uint8_t m_direction; |
| 200 |
bool m_isHalfPitchChroma; |
| 201 |
bool m_isInterleaveChrome; |
| 202 |
uint16_t m_uXOffset; |
| 203 |
uint16_t m_uYOffset; |
| 204 |
uint16_t m_vXOffset; |
| 205 |
uint16_t m_vYOffset; |
| 206 |
bool m_isVaSurface; |
| 207 |
|
| 208 |
}; |
| 209 |
|
| 210 |
class CmSurfaceStateBuffer : public CmSurfaceState |
| 211 |
{ |
| 212 |
public: |
| 213 |
CmSurfaceStateBuffer(CM_HAL_STATE *cmhal); |
| 214 |
CM_RETURN_CODE Initialize(MOS_RESOURCE *resource, uint32_t size); |
| 215 |
MOS_STATUS GenerateSurfaceState(CM_HAL_BUFFER_SURFACE_STATE_ENTRY *param = nullptr); |
| 216 |
uint8_t *GetSurfaceState(int index) {return m_cmds; } |
| 217 |
uint32_t GetSurfaceOffset(int index) {return m_offset; } |
| 218 |
|
| 219 |
protected: |
| 220 |
uint32_t m_size; |
| 221 |
uint32_t m_offset; |
| 222 |
|
| 223 |
uint8_t m_cmds[64]; |
| 224 |
|
| 225 |
}; |
| 226 |
|
| 227 |
class CmSurfaceStateVME : public CmSurfaceState |
| 228 |
{ |
| 229 |
public: |
| 230 |
CmSurfaceStateVME(CM_HAL_STATE *cmhal); |
| 231 |
CM_RETURN_CODE Initialize(CM_HAL_VME_ARG_VALUE *vmeArg); |
| 232 |
uint8_t *GetSurfaceState(int index); |
| 233 |
uint32_t GetSurfaceOffset(int index) {return m_offsets[index]; } |
| 234 |
MOS_MEMCOMP_STATE GetMmcState(int index) {return m_mmcStates[index]; } |
| 235 |
MOS_RESOURCE *GetResource(uint32_t index) ; |
| 236 |
uint32_t GetNumPlane() {return m_forwardCount+m_backwardCount+1; } |
| 237 |
uint32_t GetNumBte() {return m_numBte; } |
| 238 |
int isAVS() {return 1; } |
| 239 |
int isAVS(int surfIdx) {return 1; } |
| 240 |
bool IsRenderTarget() {return false; } |
| 241 |
|
| 242 |
protected: |
| 243 |
int GetCmHalSurfaceIndex(uint32_t index); |
| 244 |
|
| 245 |
uint32_t m_numBte; |
| 246 |
uint32_t m_forwardCount; |
| 247 |
uint32_t m_backwardCount; |
| 248 |
uint32_t m_curIndex; |
| 249 |
uint32_t *m_forwardIndexes; |
| 250 |
uint32_t *m_backwardIndexes; |
| 251 |
CM_HAL_SURFACE2D_SURFACE_STATE_PARAM m_surf2DParam; |
| 252 |
uint32_t m_offsets[CM_VME_FORWARD_ARRAY_LENGTH + CM_VME_BACKWARD_ARRAY_LENGTH + 1]; |
| 253 |
MOS_MEMCOMP_STATE m_mmcStates[CM_VME_FORWARD_ARRAY_LENGTH + CM_VME_BACKWARD_ARRAY_LENGTH + 1]; |
| 254 |
}; |
| 255 |
|