| 1 |
/* |
| 2 |
* Copyright (c) 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 mhw_blt_impl.h |
| 24 |
//! \brief MHW BLT interface common base |
| 25 |
//! \details |
| 26 |
//! |
| 27 |
|
| 28 |
#ifndef __MHW_BLT_IMPL_H__ |
| 29 |
#define __MHW_BLT_IMPL_H__ |
| 30 |
|
| 31 |
#include "mhw_blt_itf.h" |
| 32 |
#include "mhw_impl.h" |
| 33 |
#include "media_copy_common.h" |
| 34 |
|
| 35 |
namespace mhw |
| 36 |
{ |
| 37 |
namespace blt |
| 38 |
{ |
| 39 |
|
| 40 |
template <typename cmd_t> |
| 41 |
class Impl : public Itf, public mhw::Impl |
| 42 |
{ |
| 43 |
_BLT_CMD_DEF(_MHW_CMD_ALL_DEF_FOR_IMPL); |
| 44 |
|
| 45 |
public: |
| 46 |
Impl(PMOS_INTERFACE osItf) : mhw::Impl(osItf) |
| 47 |
{ |
| 48 |
MHW_FUNCTION_ENTER; |
| 49 |
} |
| 50 |
|
| 51 |
//! |
| 52 |
//! \brief Get Fast Tiling Mode |
| 53 |
//! \details BLT function to get the tiling mode for fast copy |
| 54 |
//! \param [in] TileType |
| 55 |
//! Tile type from BLT_TILE_TYPE enum |
| 56 |
//! \return uint32_t |
| 57 |
//! return the tiling mode value |
| 58 |
//! |
| 59 |
uint32_t GetFastTilingMode(BLT_TILE_TYPE TileType) override |
| 60 |
{ |
| 61 |
MHW_FUNCTION_ENTER; |
| 62 |
switch (TileType) |
| 63 |
{ |
| 64 |
case BLT_NOT_TILED: |
| 65 |
return cmd_t::XY_FAST_COPY_BLT_CMD::DESTINATION_TILING_METHOD_LINEAR_TILINGDISABLED; |
| 66 |
case BLT_TILED_Y: |
| 67 |
case BLT_TILED_4: |
| 68 |
return cmd_t::XY_FAST_COPY_BLT_CMD::DESTINATION_TILING_METHOD_TILE_Y; |
| 69 |
case BLT_TILED_64: |
| 70 |
return cmd_t::XY_FAST_COPY_BLT_CMD::DESTINATION_TILING_METHOD_64KBTILING; |
| 71 |
default: |
| 72 |
MHW_ASSERTMESSAGE("BLT: Can't support GMM TileType %d.", TileType); |
| 73 |
} |
| 74 |
return cmd_t::XY_FAST_COPY_BLT_CMD::DESTINATION_TILING_METHOD_LINEAR_TILINGDISABLED; |
| 75 |
} |
| 76 |
|
| 77 |
//! |
| 78 |
//! \brief Add Block copy Command |
| 79 |
//! \details BLT function to add block copy command |
| 80 |
//! \param [in] pCmdBuffer |
| 81 |
//! Pointer to Command buffer |
| 82 |
//! \param [in] pFastCopyBltParam |
| 83 |
//! Pointer to MHW_FAST_COPY_BLT_PARAM |
| 84 |
//! \param [in] srcOffset |
| 85 |
//! input surface's soruce offset |
| 86 |
//! \param [in] outOffset |
| 87 |
//! output surface's soruce offset |
| 88 |
//! \return MOS_STATUS |
| 89 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 90 |
//! |
| 91 |
MOS_STATUS AddBlockCopyBlt( |
| 92 |
PMOS_COMMAND_BUFFER pCmdBuffer, |
| 93 |
PMHW_FAST_COPY_BLT_PARAM pBlockCopyBltParam, |
| 94 |
uint32_t srcOffset, |
| 95 |
uint32_t dstOffset) override |
| 96 |
{ |
| 97 |
MHW_CHK_NULL_RETURN(pCmdBuffer); |
| 98 |
MHW_CHK_NULL_RETURN(pBlockCopyBltParam); |
| 99 |
|
| 100 |
auto& par = MHW_GETPAR_F(XY_BLOCK_COPY_BLT)(); |
| 101 |
par = {}; |
| 102 |
par.dwColorDepth = pBlockCopyBltParam->dwColorDepth; |
| 103 |
par.dwSrcPitch = pBlockCopyBltParam->dwSrcPitch; |
| 104 |
par.dwDstPitch = pBlockCopyBltParam->dwDstPitch; |
| 105 |
par.dwSrcTop = pBlockCopyBltParam->dwSrcTop; |
| 106 |
par.dwSrcLeft = pBlockCopyBltParam->dwSrcLeft; |
| 107 |
par.dwDstTop = pBlockCopyBltParam->dwDstTop; |
| 108 |
par.dwDstBottom = pBlockCopyBltParam->dwDstBottom; |
| 109 |
par.dwDstLeft = pBlockCopyBltParam->dwDstLeft; |
| 110 |
par.dwDstRight = pBlockCopyBltParam->dwDstRight; |
| 111 |
par.dwSrcOffset = srcOffset; |
| 112 |
par.dwDstOffset = dstOffset; |
| 113 |
par.dwPlaneIndex = pBlockCopyBltParam->dwPlaneIndex; |
| 114 |
par.dwPlaneNum = pBlockCopyBltParam->dwPlaneNum; |
| 115 |
par.pSrcOsResource = pBlockCopyBltParam->pSrcOsResource; |
| 116 |
par.pDstOsResource = pBlockCopyBltParam->pDstOsResource; |
| 117 |
|
| 118 |
MHW_CHK_STATUS_RETURN(MHW_ADDCMD_F(XY_BLOCK_COPY_BLT)(pCmdBuffer)); |
| 119 |
|
| 120 |
return MOS_STATUS_SUCCESS; |
| 121 |
} |
| 122 |
|
| 123 |
_MHW_SETCMD_OVERRIDE_DECL(XY_BLOCK_COPY_BLT) |
| 124 |
{ |
| 125 |
MHW_FUNCTION_ENTER; |
| 126 |
|
| 127 |
_MHW_SETCMD_CALLBASE(XY_BLOCK_COPY_BLT); |
| 128 |
MHW_CHK_NULL_RETURN(params.pSrcOsResource); |
| 129 |
MHW_CHK_NULL_RETURN(params.pDstOsResource); |
| 130 |
|
| 131 |
MHW_RESOURCE_PARAMS ResourceParams; |
| 132 |
PGMM_RESOURCE_INFO pSrcGmmResInfo = params.pSrcOsResource->pGmmResInfo; |
| 133 |
PGMM_RESOURCE_INFO pDstGmmResInfo = params.pDstOsResource->pGmmResInfo; |
| 134 |
MHW_CHK_NULL_RETURN(pSrcGmmResInfo); |
| 135 |
MHW_CHK_NULL_RETURN(pDstGmmResInfo); |
| 136 |
|
| 137 |
BLT_TILE_TYPE dstTiledMode = static_cast<BLT_TILE_TYPE>(pDstGmmResInfo->GetTileType()); |
| 138 |
BLT_TILE_TYPE srcTiledMode = static_cast<BLT_TILE_TYPE>(pSrcGmmResInfo->GetTileType()); |
| 139 |
|
| 140 |
uint32_t sourceResourceWidth = (uint32_t)pSrcGmmResInfo->GetBaseWidth(); |
| 141 |
uint32_t sourceResourceHeight = (uint32_t)pSrcGmmResInfo->GetBaseHeight(); |
| 142 |
uint32_t dstResourceWidth = (uint32_t)pDstGmmResInfo->GetBaseWidth(); |
| 143 |
uint32_t dstResourceHeight = (uint32_t)pDstGmmResInfo->GetBaseHeight(); |
| 144 |
|
| 145 |
MHW_CHK_NULL_RETURN(this->m_currentCmdBuf); |
| 146 |
MHW_CHK_NULL_RETURN(this->m_osItf); |
| 147 |
|
| 148 |
// mmc |
| 149 |
MOS_MEMCOMP_STATE srcMmcModel = MOS_MEMCOMP_DISABLED; |
| 150 |
MOS_MEMCOMP_STATE dstMmcModel = MOS_MEMCOMP_DISABLED; |
| 151 |
GMM_RESOURCE_FLAG inputFlags = pSrcGmmResInfo->GetResFlags(); |
| 152 |
GMM_RESOURCE_FLAG outFlags = pDstGmmResInfo->GetResFlags(); |
| 153 |
MCPY_CHK_STATUS_RETURN(this->m_osItf->pfnGetMemoryCompressionMode(this->m_osItf, params.pSrcOsResource, (PMOS_MEMCOMP_STATE) & (srcMmcModel))); |
| 154 |
MCPY_CHK_STATUS_RETURN(this->m_osItf->pfnGetMemoryCompressionMode(this->m_osItf, params.pDstOsResource, (PMOS_MEMCOMP_STATE) & (dstMmcModel))); |
| 155 |
|
| 156 |
uint32_t srcQPitch = pSrcGmmResInfo->GetQPitch(); |
| 157 |
uint32_t dstQPitch = pDstGmmResInfo->GetQPitch(); |
| 158 |
GMM_RESOURCE_TYPE dstResType = pDstGmmResInfo->GetResourceType(); |
| 159 |
GMM_RESOURCE_TYPE srcResType = pSrcGmmResInfo->GetResourceType(); |
| 160 |
|
| 161 |
uint32_t dstSampleNum = pDstGmmResInfo->GetNumSamples(); |
| 162 |
|
| 163 |
cmd.DW0.InstructionTargetOpcode = 0x41; |
| 164 |
cmd.DW0.ColorDepth = params.dwColorDepth; |
| 165 |
cmd.DW1.DestinationPitch = params.dwDstPitch - 1; |
| 166 |
cmd.DW1.DestinationMocsValue = GetBlockCopyBltMOCS(MOS_GMM_RESOURCE_USAGE_BLT_DESTINATION); |
| 167 |
|
| 168 |
cmd.DW1.DestinationTiling = GetFastTilingMode(dstTiledMode); |
| 169 |
cmd.DW8.SourceTiling = GetFastTilingMode(srcTiledMode); |
| 170 |
cmd.DW8.SourceMocs = GetBlockCopyBltMOCS(MOS_GMM_RESOURCE_USAGE_BLT_SOURCE); |
| 171 |
|
| 172 |
cmd.DW2.DestinationX1CoordinateLeft = 0; |
| 173 |
cmd.DW2.DestinationY1CoordinateTop = 0; |
| 174 |
cmd.DW3.DestinationX2CoordinateRight = params.dwDstRight; |
| 175 |
cmd.DW3.DestinationY2CoordinateBottom = params.dwDstBottom; |
| 176 |
cmd.DW7.SourceX1CoordinateLeft = params.dwSrcLeft; |
| 177 |
cmd.DW7.SourceY1CoordinateTop = params.dwSrcTop; |
| 178 |
cmd.DW8.SourcePitch = params.dwSrcPitch - 1; |
| 179 |
|
| 180 |
if (!outFlags.Info.LocalOnly) |
| 181 |
{ |
| 182 |
cmd.DW6.DestinationTargetMemory = 1;//DESTINATION_TARGET_MEMORY::DESTINATION_TARGET_MEMORY_SYSTEM_MEM; |
| 183 |
} |
| 184 |
if (!inputFlags.Info.LocalOnly) |
| 185 |
{ |
| 186 |
cmd.DW11.SourceTargetMemory = 1;// SOURCE_TARGET_MEMORY::SOURCE_TARGET_MEMORY_SYSTEM_MEM; |
| 187 |
} |
| 188 |
|
| 189 |
cmd.DW16.DestinationSurfaceHeight = dstResourceHeight -1; |
| 190 |
cmd.DW16.DestinationSurfaceWidth = dstResourceWidth -1; |
| 191 |
cmd.DW16.DestinationSurfaceType = 1; // 0 is 1D, 1 is 2D |
| 192 |
cmd.DW19.SourceSurfaceHeight = sourceResourceHeight - 1; |
| 193 |
cmd.DW19.SourceSurfaceWidth = sourceResourceWidth - 1; |
| 194 |
cmd.DW19.SourceSurfaceType = 1; |
| 195 |
|
| 196 |
MCPY_NORMALMESSAGE("Src type %d, dst type %d, srcTiledMode %d, dstTiledMode %d", |
| 197 |
srcResType, dstResType, srcTiledMode, dstTiledMode); |
| 198 |
|
| 199 |
cmd.DW17.DestinationSurfaceQpitch = dstQPitch >> 2; |
| 200 |
cmd.DW20.SourceSurfaceQpitch = srcQPitch >> 2; |
| 201 |
|
| 202 |
cmd.DW18.DestinationHorizontalAlign = pDstGmmResInfo->GetVAlign();; |
| 203 |
cmd.DW18.DestinationVerticalAlign = pDstGmmResInfo->GetHAlign(); |
| 204 |
cmd.DW18.DestinationMipTailStartLOD = 0xf; |
| 205 |
|
| 206 |
cmd.DW21.SourceHorizontalAlign = pSrcGmmResInfo->GetVAlign(); |
| 207 |
cmd.DW21.SourceVerticalAlign = pSrcGmmResInfo->GetHAlign(); |
| 208 |
cmd.DW21.SourceMipTailStartLOD = 0xf; |
| 209 |
|
| 210 |
// add source address |
| 211 |
MOS_ZeroMemory(&ResourceParams, sizeof(ResourceParams)); |
| 212 |
ResourceParams.dwLsbNum = 0; |
| 213 |
ResourceParams.dwOffset = params.dwSrcOffset; |
| 214 |
ResourceParams.presResource = params.pSrcOsResource; |
| 215 |
ResourceParams.pdwCmd = &(cmd.DW9_10.Value[0]); |
| 216 |
ResourceParams.dwLocationInCmd = 9; |
| 217 |
ResourceParams.bIsWritable = false; |
| 218 |
|
| 219 |
MHW_CHK_STATUS_RETURN(AddResourceToCmd( |
| 220 |
this->m_osItf, |
| 221 |
this->m_currentCmdBuf, |
| 222 |
&ResourceParams)); |
| 223 |
|
| 224 |
// add destination address |
| 225 |
MOS_ZeroMemory(&ResourceParams, sizeof(ResourceParams)); |
| 226 |
ResourceParams.dwLsbNum = 0; |
| 227 |
ResourceParams.dwOffset = params.dwDstOffset; |
| 228 |
ResourceParams.presResource = params.pDstOsResource; |
| 229 |
ResourceParams.pdwCmd = &(cmd.DW4_5.Value[0]); |
| 230 |
ResourceParams.dwLocationInCmd = 4; |
| 231 |
ResourceParams.bIsWritable = true; |
| 232 |
|
| 233 |
MHW_CHK_STATUS_RETURN(AddResourceToCmd( |
| 234 |
this->m_osItf, |
| 235 |
this->m_currentCmdBuf, |
| 236 |
&ResourceParams)); |
| 237 |
|
| 238 |
MCPY_NORMALMESSAGE("Block BLT cmd:dstSampleNum = %d; width = %d, hieght = %d, ColorDepth = %d, Source Pitch %d, mocs = %d,tiled %d," |
| 239 |
"mmc model % d, dst Pitch %d, mocs = %d,tiled %d, mmc model %d", |
| 240 |
dstSampleNum, params.dwDstRight, params.dwDstBottom, |
| 241 |
cmd.DW0.ColorDepth, cmd.DW8.SourcePitch, cmd.DW8.SourceMocs, cmd.DW8.SourceTiling, srcMmcModel, |
| 242 |
cmd.DW1.DestinationPitch, cmd.DW1.DestinationMocsValue, cmd.DW1.DestinationTiling, dstMmcModel); |
| 243 |
|
| 244 |
MT_LOG7(MT_MEDIA_COPY, MT_NORMAL, MT_GENERIC_VALUE, cmd.DW0.ColorDepth, MT_GENERIC_VALUE, cmd.DW1.Value, MT_GENERIC_VALUE, cmd.DW2.Value, MT_GENERIC_VALUE, cmd.DW3.Value, |
| 245 |
MT_GENERIC_VALUE, cmd.DW6.Value, MT_GENERIC_VALUE, cmd.DW7.Value, MT_GENERIC_VALUE, cmd.DW8.Value); |
| 246 |
MT_LOG7(MT_MEDIA_COPY, MT_NORMAL, MT_GENERIC_VALUE, cmd.DW11.Value, MT_GENERIC_VALUE, cmd.DW16.Value, MT_GENERIC_VALUE, cmd.DW17.Value, |
| 247 |
MT_GENERIC_VALUE, cmd.DW18.Value, MT_GENERIC_VALUE, cmd.DW19.Value, MT_GENERIC_VALUE, cmd.DW20.Value, MT_GENERIC_VALUE, cmd.DW21.Value); |
| 248 |
return MOS_STATUS_SUCCESS; |
| 249 |
} |
| 250 |
|
| 251 |
protected: |
| 252 |
//! |
| 253 |
//! \brief Get Block copy MOCS |
| 254 |
//! \details BLT function to get the MOCS |
| 255 |
//! \param [in] MOS_HW_RESOURCE_DEF |
| 256 |
//! Pointer to UsageDef |
| 257 |
//! \return uint32_t |
| 258 |
//! return the MOCS value |
| 259 |
//! |
| 260 |
virtual uint32_t GetBlockCopyBltMOCS(MOS_HW_RESOURCE_DEF UsageDef) |
| 261 |
{ |
| 262 |
// MemoryObject will get 7 bits data. only bits[1-7] save MOCS, while some |
| 263 |
// platoforms only use 4 bits mocs. |
| 264 |
return (m_osItf->pfnCachePolicyGetMemoryObject(UsageDef, |
| 265 |
m_osItf->pfnGetGmmClientContext(m_osItf)).DwordValue & 0x1E) >>1; |
| 266 |
} |
| 267 |
|
| 268 |
using base_t = Itf; |
| 269 |
MEDIA_CLASS_DEFINE_END(mhw__blt__Impl) |
| 270 |
}; |
| 271 |
} // namespace blt |
| 272 |
} // namespace mhw |
| 273 |
|
| 274 |
#endif // __MHW_BLT_IMPL_H__ |