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_encode_wp_g11.cpp
24 //! \brief    This file implements the weighted prediction feature for all codecs on Gen11 platform
25 //!
26 
27 #include "codechal_encoder_base.h"
28 #include "codechal_encode_wp_g11.h"
29 #include "codechal_kernel_header_g11.h"
30 
CodechalEncodeWPG11(CodechalEncoderState * encoder)31 CodechalEncodeWPG11::CodechalEncodeWPG11(CodechalEncoderState* encoder)
32     : CodechalEncodeWP(encoder)
33 {
34     m_kuidCommon = encoder->m_kuidCommon;
35 }
36 
InitKernelState()37 MOS_STATUS CodechalEncodeWPG11::InitKernelState()
38 {
39     CODECHAL_ENCODE_FUNCTION_ENTER;
40 
41     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
42 
43     if (!m_kernelState)
44     {
45         CODECHAL_ENCODE_CHK_NULL_RETURN(m_kernelState = MOS_New(MHW_KERNEL_STATE));
46     }
47 
48     uint8_t *binary;
49     auto kernelSize = m_combinedKernelSize;
50     CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalGetKernelBinaryAndSize(
51         m_kernelBase,
52         m_kuidCommon,
53         &binary,
54         &kernelSize));
55 
56     CODECHAL_KERNEL_HEADER currKrnHeader;
57     CODECHAL_ENCODE_CHK_STATUS_RETURN(GetCommonKernelHeaderAndSizeG11(
58         binary,
59         ENC_WP,
60         0,
61         &currKrnHeader,
62         &kernelSize));
63 
64     m_kernelState->KernelParams.iBTCount          = wpNumSurfaces;
65     m_kernelState->KernelParams.iThreadCount      = m_hwInterface->GetRenderInterface()->GetHwCaps()->dwMaxThreads;
66     m_kernelState->KernelParams.iCurbeLength      = m_curbeLength;
67     m_kernelState->KernelParams.iBlockWidth       = CODECHAL_MACROBLOCK_WIDTH;
68     m_kernelState->KernelParams.iBlockHeight      = CODECHAL_MACROBLOCK_HEIGHT;
69     m_kernelState->KernelParams.iIdCount          = 1;
70     m_kernelState->KernelParams.iInlineDataLength = 0;
71     m_kernelState->dwCurbeOffset                  = m_stateHeapInterface->GetSizeofCmdInterfaceDescriptorData();
72     m_kernelState->KernelParams.pBinary           =
73         binary + (currKrnHeader.KernelStartPointer << MHW_KERNEL_OFFSET_SHIFT);
74     m_kernelState->KernelParams.iSize             = kernelSize;
75 
76     CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->CalculateSshAndBtSizesRequested(
77         m_kernelState->KernelParams.iBTCount,
78         &m_kernelState->dwSshSize,
79         &m_kernelState->dwBindingTableSize));
80 
81     CODECHAL_ENCODE_CHK_NULL_RETURN(m_renderInterface->m_stateHeapInterface);
82     CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hwInterface->MhwInitISH(m_renderInterface->m_stateHeapInterface, m_kernelState));
83 
84     return eStatus;
85 }
86