| 1 |
/* |
| 2 |
* Copyright (c) 2020-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_legacy.cpp |
| 24 |
//! \brief MHW interface for constructing commands for the BLT |
| 25 |
//! |
| 26 |
#include "mhw_blt_legacy.h" |
| 27 |
|
| 28 |
MhwBltInterface::MhwBltInterface(PMOS_INTERFACE pOsInterface) |
| 29 |
{ |
| 30 |
MHW_FUNCTION_ENTER; |
| 31 |
|
| 32 |
pfnAddResourceToCmd = nullptr; |
| 33 |
|
| 34 |
if (pOsInterface == nullptr) |
| 35 |
{ |
| 36 |
MHW_ASSERTMESSAGE("Invalid OsInterface pointers provided"); |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
m_osInterface = pOsInterface; |
| 41 |
if (m_osInterface->bUsesGfxAddress) |
| 42 |
{ |
| 43 |
pfnAddResourceToCmd = Mhw_AddResourceToCmd_GfxAddress; |
| 44 |
} |
| 45 |
else //PatchList |
| 46 |
{ |
| 47 |
pfnAddResourceToCmd = Mhw_AddResourceToCmd_PatchList; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
MOS_STATUS MhwBltInterface::AddFastCopyBlt( |
| 52 |
PMOS_COMMAND_BUFFER pCmdBuffer, |
| 53 |
PMHW_FAST_COPY_BLT_PARAM pFastCopyBltParam, |
| 54 |
uint32_t srcOffset, |
| 55 |
uint32_t dstOffset) |
| 56 |
{ |
| 57 |
MHW_FUNCTION_ENTER; |
| 58 |
|
| 59 |
MHW_RESOURCE_PARAMS ResourceParams; |
| 60 |
MOS_STATUS eStatus; |
| 61 |
|
| 62 |
eStatus = MOS_STATUS_SUCCESS; |
| 63 |
|
| 64 |
MHW_CHK_NULL_RETURN(m_osInterface); |
| 65 |
MHW_CHK_NULL_RETURN(pFastCopyBltParam); |
| 66 |
MHW_CHK_NULL_RETURN(pFastCopyBltParam->pDstOsResource); |
| 67 |
MHW_CHK_NULL_RETURN(pFastCopyBltParam->pSrcOsResource); |
| 68 |
MHW_CHK_NULL_RETURN(pFastCopyBltParam->pDstOsResource->pGmmResInfo); |
| 69 |
MHW_CHK_NULL_RETURN(pFastCopyBltParam->pSrcOsResource->pGmmResInfo); |
| 70 |
|
| 71 |
mhw_blt_state::XY_FAST_COPY_BLT_CMD cmd; |
| 72 |
|
| 73 |
BLT_TILE_TYPE dstTiledMode = static_cast<BLT_TILE_TYPE>(pFastCopyBltParam->pDstOsResource->pGmmResInfo->GetTileType()); |
| 74 |
BLT_TILE_TYPE srcTiledMode = static_cast<BLT_TILE_TYPE>(pFastCopyBltParam->pSrcOsResource->pGmmResInfo->GetTileType()); |
| 75 |
|
| 76 |
cmd.DW0.SourceTilingMethod = GetFastTilingMode(srcTiledMode); |
| 77 |
cmd.DW0.DestinationTilingMethod = GetFastTilingMode(dstTiledMode); |
| 78 |
cmd.DW1.TileYTypeForSource = (srcTiledMode == BLT_NOT_TILED) ? 0 : 1; |
| 79 |
cmd.DW1.TileYTypeForDestination = (dstTiledMode == BLT_NOT_TILED) ? 0 : 1; |
| 80 |
cmd.DW1.ColorDepth = pFastCopyBltParam->dwColorDepth; |
| 81 |
cmd.DW1.DestinationPitch = pFastCopyBltParam->dwDstPitch; |
| 82 |
cmd.DW2.DestinationX1CoordinateLeft = pFastCopyBltParam->dwDstLeft; |
| 83 |
cmd.DW2.DestinationY1CoordinateTop = pFastCopyBltParam->dwDstTop; |
| 84 |
cmd.DW3.DestinationX2CoordinateRight = pFastCopyBltParam->dwDstRight; |
| 85 |
cmd.DW3.DestinationY2CoordinateBottom = pFastCopyBltParam->dwDstBottom; |
| 86 |
cmd.DW6.SourceX1CoordinateLeft = pFastCopyBltParam->dwSrcLeft; |
| 87 |
cmd.DW6.SourceY1CoordinateTop = pFastCopyBltParam->dwSrcTop; |
| 88 |
cmd.DW7.SourcePitch = pFastCopyBltParam->dwSrcPitch; |
| 89 |
|
| 90 |
// add source address |
| 91 |
MOS_ZeroMemory(&ResourceParams, sizeof(ResourceParams)); |
| 92 |
ResourceParams.dwLsbNum = MHW_BLT_ENGINE_STATE_BASE_ADDRESS_SHIFT; |
| 93 |
ResourceParams.dwOffset = srcOffset; |
| 94 |
ResourceParams.presResource = pFastCopyBltParam->pSrcOsResource; |
| 95 |
ResourceParams.pdwCmd = &(cmd.DW8_9.Value[0]); |
| 96 |
ResourceParams.dwLocationInCmd = 8; |
| 97 |
ResourceParams.bIsWritable = false; |
| 98 |
|
| 99 |
MHW_CHK_STATUS(pfnAddResourceToCmd( |
| 100 |
m_osInterface, |
| 101 |
pCmdBuffer, |
| 102 |
&ResourceParams)); |
| 103 |
|
| 104 |
// add destination address |
| 105 |
MOS_ZeroMemory(&ResourceParams, sizeof(ResourceParams)); |
| 106 |
ResourceParams.dwLsbNum = MHW_BLT_ENGINE_STATE_BASE_ADDRESS_SHIFT; |
| 107 |
ResourceParams.dwOffset = dstOffset; |
| 108 |
ResourceParams.presResource = pFastCopyBltParam->pDstOsResource; |
| 109 |
ResourceParams.pdwCmd = &(cmd.DW4_5.Value[0]); |
| 110 |
ResourceParams.dwLocationInCmd = 4; |
| 111 |
ResourceParams.bIsWritable = true; |
| 112 |
|
| 113 |
MHW_CHK_STATUS(pfnAddResourceToCmd( |
| 114 |
m_osInterface, |
| 115 |
pCmdBuffer, |
| 116 |
&ResourceParams)); |
| 117 |
|
| 118 |
m_osInterface->pfnAddCommand(pCmdBuffer, &cmd, cmd.byteSize); |
| 119 |
|
| 120 |
finish: |
| 121 |
return eStatus; |
| 122 |
} |
| 123 |
|
| 124 |
MOS_STATUS MhwBltInterface::AddBlockCopyBlt( |
| 125 |
PMOS_COMMAND_BUFFER pCmdBuffer, |
| 126 |
PMHW_FAST_COPY_BLT_PARAM pFastCopyBltParam, |
| 127 |
uint32_t srcOffset, |
| 128 |
uint32_t dstOffset) |
| 129 |
{ |
| 130 |
MHW_FUNCTION_ENTER; |
| 131 |
|
| 132 |
MHW_RESOURCE_PARAMS ResourceParams; |
| 133 |
MOS_STATUS eStatus; |
| 134 |
|
| 135 |
eStatus = MOS_STATUS_SUCCESS; |
| 136 |
|
| 137 |
mhw_blt_state::XY_BLOCK_COPY_BLT_CMD cmd; |
| 138 |
MHW_CHK_NULL(m_osInterface); |
| 139 |
cmd.DW0.ColorDepth = pFastCopyBltParam->dwColorDepth; |
| 140 |
cmd.DW1.DestinationPitch = pFastCopyBltParam->dwDstPitch -1; |
| 141 |
cmd.DW1.DestinationMocsValue = |
| 142 |
m_osInterface->pfnGetGmmClientContext(m_osInterface)->CachePolicyGetMemoryObject(nullptr, GMM_RESOURCE_USAGE_BLT_DESTINATION).DwordValue; |
| 143 |
|
| 144 |
cmd.DW1.DestinationTiling = (pFastCopyBltParam->pDstOsResource->TileType == MOS_TILE_LINEAR) ? 0:1; |
| 145 |
cmd.DW8.SourceTiling = (pFastCopyBltParam->pSrcOsResource->TileType == MOS_TILE_LINEAR) ? 0:1; |
| 146 |
cmd.DW8.SourceMocs = |
| 147 |
m_osInterface->pfnGetGmmClientContext(m_osInterface)->CachePolicyGetMemoryObject(nullptr, GMM_RESOURCE_USAGE_BLT_SOURCE).DwordValue; |
| 148 |
|
| 149 |
cmd.DW2.DestinationX1CoordinateLeft = 0; |
| 150 |
cmd.DW2.DestinationY1CoordinateTop = 0; |
| 151 |
cmd.DW3.DestinationX2CoordinateRight = pFastCopyBltParam->dwDstRight; |
| 152 |
cmd.DW3.DestinationY2CoordinateBottom = pFastCopyBltParam->dwDstBottom; |
| 153 |
cmd.DW7.SourceX1CoordinateLeft = pFastCopyBltParam->dwSrcLeft; |
| 154 |
cmd.DW7.SourceY1CoordinateTop = pFastCopyBltParam->dwSrcTop; |
| 155 |
cmd.DW8.SourcePitch = pFastCopyBltParam->dwSrcPitch -1; |
| 156 |
|
| 157 |
// add source address |
| 158 |
MOS_ZeroMemory(&ResourceParams, sizeof(ResourceParams)); |
| 159 |
ResourceParams.dwLsbNum = 12; |
| 160 |
ResourceParams.dwOffset = srcOffset; |
| 161 |
ResourceParams.presResource = pFastCopyBltParam->pSrcOsResource; |
| 162 |
ResourceParams.pdwCmd = &(cmd.DW9_10.Value[0]); |
| 163 |
ResourceParams.dwLocationInCmd = 9; |
| 164 |
ResourceParams.bIsWritable = false; |
| 165 |
|
| 166 |
MHW_CHK_STATUS(pfnAddResourceToCmd( |
| 167 |
m_osInterface, |
| 168 |
pCmdBuffer, |
| 169 |
&ResourceParams)); |
| 170 |
|
| 171 |
// add destination address |
| 172 |
MOS_ZeroMemory(&ResourceParams, sizeof(ResourceParams)); |
| 173 |
ResourceParams.dwLsbNum = 12; |
| 174 |
ResourceParams.dwOffset = dstOffset; |
| 175 |
ResourceParams.presResource = pFastCopyBltParam->pDstOsResource; |
| 176 |
ResourceParams.pdwCmd = &(cmd.DW4_5.Value[0]); |
| 177 |
ResourceParams.dwLocationInCmd = 4; |
| 178 |
ResourceParams.bIsWritable = true; |
| 179 |
|
| 180 |
MHW_CHK_STATUS(pfnAddResourceToCmd( |
| 181 |
m_osInterface, |
| 182 |
pCmdBuffer, |
| 183 |
&ResourceParams)); |
| 184 |
|
| 185 |
m_osInterface->pfnAddCommand(pCmdBuffer, &cmd, cmd.byteSize); |
| 186 |
|
| 187 |
finish: |
| 188 |
return eStatus; |
| 189 |
} |
| 190 |
|
| 191 |
uint32_t MhwBltInterface::GetFastTilingMode(BLT_TILE_TYPE TileType) |
| 192 |
{ |
| 193 |
switch(TileType) |
| 194 |
{ |
| 195 |
case BLT_NOT_TILED: |
| 196 |
return mhw_blt_state::XY_FAST_COPY_BLT_CMD::DESTINATION_TILING_METHOD_LINEAR_TILINGDISABLED; |
| 197 |
case BLT_TILED_Y: |
| 198 |
case BLT_TILED_4: |
| 199 |
return mhw_blt_state::XY_FAST_COPY_BLT_CMD::DESTINATION_TILING_METHOD_TILE_Y; |
| 200 |
case BLT_TILED_64: |
| 201 |
return mhw_blt_state::XY_FAST_COPY_BLT_CMD::DESTINATION_TILING_METHOD_64KBTILING; |
| 202 |
default: |
| 203 |
MHW_ASSERTMESSAGE("BLT: Can't support GMM TileType %d.", TileType); |
| 204 |
} |
| 205 |
return mhw_blt_state::XY_FAST_COPY_BLT_CMD::DESTINATION_TILING_METHOD_LINEAR_TILINGDISABLED; |
| 206 |
} |