| 1 |
/* |
| 2 |
* Copyright (c) 2017, 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 codechal_kernel_hme_g8.cpp |
| 24 |
//! \brief Hme kernel implementation for Gen8 platform |
| 25 |
//! |
| 26 |
#include "codechal_kernel_hme_g8.h" |
| 27 |
|
| 28 |
// clang-format off |
| 29 |
const uint32_t CodechalKernelHmeG8::Curbe::m_initCurbe[39] = |
| 30 |
{ |
| 31 |
0x00000000, 0x00200010, 0x00003939, 0x77a43000, 0x00000000, 0x28300000, 0x00000000, 0x00000000, |
| 32 |
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| 33 |
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| 34 |
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| 35 |
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff |
| 36 |
}; |
| 37 |
// clang-format on |
| 38 |
|
| 39 |
CodechalKernelHmeG8::CodechalKernelHmeG8( |
| 40 |
CodechalEncoderState *encoder, |
| 41 |
bool me4xDistBufferSupported) |
| 42 |
: CodechalKernelHme(encoder, me4xDistBufferSupported) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
MOS_STATUS CodechalKernelHmeG8::SetCurbe(MHW_KERNEL_STATE *kernelState) |
| 47 |
{ |
| 48 |
CODECHAL_ENCODE_CHK_NULL_RETURN(kernelState); |
| 49 |
|
| 50 |
Curbe curbe; |
| 51 |
uint32_t mvShiftFactor = 0; |
| 52 |
uint32_t prevMvReadPosFactor = 0; |
| 53 |
uint32_t scaleFactor; |
| 54 |
bool useMvFromPrevStep; |
| 55 |
bool writeDistortions; |
| 56 |
|
| 57 |
if (m_32xMeInUse) |
| 58 |
{ |
| 59 |
useMvFromPrevStep = false; |
| 60 |
writeDistortions = false; |
| 61 |
scaleFactor = scalingFactor32X; |
| 62 |
mvShiftFactor = 1; |
| 63 |
prevMvReadPosFactor = 0; |
| 64 |
} |
| 65 |
else if (m_16xMeInUse) |
| 66 |
{ |
| 67 |
useMvFromPrevStep = Is32xMeEnabled() ? true : false; |
| 68 |
writeDistortions = false; |
| 69 |
scaleFactor = scalingFactor16X; |
| 70 |
mvShiftFactor = 2; |
| 71 |
prevMvReadPosFactor = 1; |
| 72 |
} |
| 73 |
else if (m_4xMeInUse) |
| 74 |
{ |
| 75 |
useMvFromPrevStep = Is16xMeEnabled() ? true : false; |
| 76 |
writeDistortions = true; |
| 77 |
scaleFactor = scalingFactor4X; |
| 78 |
mvShiftFactor = 2; |
| 79 |
prevMvReadPosFactor = 0; |
| 80 |
} |
| 81 |
else |
| 82 |
{ |
| 83 |
return MOS_STATUS_INVALID_PARAMETER; |
| 84 |
} |
| 85 |
|
| 86 |
curbe.m_data.DW3.SubPelMode = m_curbeParam.subPelMode; |
| 87 |
|
| 88 |
if (m_fieldScalingOutputInterleaved) |
| 89 |
{ |
| 90 |
curbe.m_data.DW3.SrcAccess = curbe.m_data.DW3.RefAccess = CodecHal_PictureIsField(m_curbeParam.currOriginalPic); |
| 91 |
curbe.m_data.DW7.SrcFieldPolarity = CodecHal_PictureIsBottomField(m_curbeParam.currOriginalPic); |
| 92 |
} |
| 93 |
curbe.m_data.DW4.PictureHeightMinus1 = CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_frameFieldHeight / scaleFactor) - 1; |
| 94 |
curbe.m_data.DW4.PictureWidth = CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_frameWidth / scaleFactor); |
| 95 |
curbe.m_data.DW5.QpPrimeY = m_curbeParam.qpPrimeY; |
| 96 |
curbe.m_data.DW6.WriteDistortions = writeDistortions; |
| 97 |
curbe.m_data.DW6.UseMvFromPrevStep = useMvFromPrevStep; |
| 98 |
curbe.m_data.DW6.SuperCombineDist = SuperCombineDist[m_curbeParam.targetUsage]; |
| 99 |
curbe.m_data.DW6.MaxVmvR = CodecHal_PictureIsFrame(m_curbeParam.currOriginalPic) ? m_curbeParam.maxMvLen * 4 : (m_curbeParam.maxMvLen >> 1) * 4; |
| 100 |
|
| 101 |
if (m_pictureCodingType == B_TYPE) |
| 102 |
{ |
| 103 |
curbe.m_data.DW1.BiWeight = 32; |
| 104 |
curbe.m_data.DW13.NumRefIdxL1MinusOne = m_curbeParam.numRefIdxL1Minus1; |
| 105 |
} |
| 106 |
|
| 107 |
if (m_pictureCodingType == B_TYPE || |
| 108 |
m_pictureCodingType == P_TYPE) |
| 109 |
{ |
| 110 |
curbe.m_data.DW13.NumRefIdxL0MinusOne = m_curbeParam.numRefIdxL0Minus1; |
| 111 |
} |
| 112 |
|
| 113 |
if (!CodecHal_PictureIsFrame(m_curbeParam.currOriginalPic)) |
| 114 |
{ |
| 115 |
if (m_pictureCodingType != I_TYPE) |
| 116 |
{ |
| 117 |
curbe.m_data.DW14.List0RefID0FieldParity = m_curbeParam.list0RefID0FieldParity; |
| 118 |
curbe.m_data.DW14.List0RefID1FieldParity = m_curbeParam.list0RefID1FieldParity; |
| 119 |
curbe.m_data.DW14.List0RefID2FieldParity = m_curbeParam.list0RefID2FieldParity; |
| 120 |
curbe.m_data.DW14.List0RefID3FieldParity = m_curbeParam.list0RefID3FieldParity; |
| 121 |
curbe.m_data.DW14.List0RefID4FieldParity = m_curbeParam.list0RefID4FieldParity; |
| 122 |
curbe.m_data.DW14.List0RefID5FieldParity = m_curbeParam.list0RefID5FieldParity; |
| 123 |
curbe.m_data.DW14.List0RefID6FieldParity = m_curbeParam.list0RefID6FieldParity; |
| 124 |
curbe.m_data.DW14.List0RefID7FieldParity = m_curbeParam.list0RefID7FieldParity; |
| 125 |
} |
| 126 |
if (m_pictureCodingType == B_TYPE) |
| 127 |
{ |
| 128 |
curbe.m_data.DW14.List1RefID0FieldParity = m_curbeParam.list1RefID0FieldParity; |
| 129 |
curbe.m_data.DW14.List1RefID1FieldParity = m_curbeParam.list1RefID1FieldParity; |
| 130 |
} |
| 131 |
} |
| 132 |
curbe.m_data.DW15.MvShiftFactor = mvShiftFactor; |
| 133 |
curbe.m_data.DW15.PrevMvReadPosFactor = prevMvReadPosFactor; |
| 134 |
|
| 135 |
// r3 & r4 |
| 136 |
uint8_t methodIndex; |
| 137 |
if (m_pictureCodingType == B_TYPE) |
| 138 |
{ |
| 139 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_bmeMethodTable); |
| 140 |
methodIndex = m_curbeParam.bmeMethodTable ? |
| 141 |
m_curbeParam.bmeMethodTable[m_curbeParam.targetUsage] : m_bmeMethodTable[m_curbeParam.targetUsage]; |
| 142 |
} |
| 143 |
else |
| 144 |
{ |
| 145 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_meMethodTable); |
| 146 |
methodIndex = m_curbeParam.meMethodTable ? |
| 147 |
m_curbeParam.meMethodTable[m_curbeParam.targetUsage] : m_meMethodTable[m_curbeParam.targetUsage]; |
| 148 |
} |
| 149 |
|
| 150 |
uint8_t tableIndex = (m_pictureCodingType == B_TYPE) ? 1 : 0; |
| 151 |
MOS_SecureMemcpy(&curbe.m_data.SpDelta, 14 * sizeof(uint32_t), codechalEncodeSearchPath[tableIndex][methodIndex], 14 * sizeof(uint32_t)); |
| 152 |
|
| 153 |
//r5 |
| 154 |
curbe.m_data.DW32._4xMeMvOutputDataSurfIndex = BindingTableOffset::meOutputMvDataSurface; |
| 155 |
curbe.m_data.DW33._16xOr32xMeMvInputDataSurfIndex = BindingTableOffset::meInputMvDataSurface; |
| 156 |
curbe.m_data.DW34._4xMeOutputDistSurfIndex = BindingTableOffset::meDistortionSurface; |
| 157 |
curbe.m_data.DW35._4xMeOutputBrcDistSurfIndex = BindingTableOffset::meBrcDistortion; |
| 158 |
curbe.m_data.DW36.VMEFwdInterPredictionSurfIndex = BindingTableOffset::meCurrForFwdRef; |
| 159 |
curbe.m_data.DW37.VMEBwdInterPredictionSurfIndex = BindingTableOffset::meCurrForBwdRef; |
| 160 |
|
| 161 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(kernelState->m_dshRegion.AddData(&curbe.m_data, kernelState->dwCurbeOffset, Curbe::m_curbeSize)); |
| 162 |
|
| 163 |
return MOS_STATUS_SUCCESS; |
| 164 |
} |