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_intra_dist.cpp
24 //! \brief Defines the intra distortion kernel base
25 //! \details Intra distortion base includes all common functions and definitions for intra distortion
26 //!
27 #include "codechal_kernel_intra_dist.h"
28
CodechalKernelIntraDist(CodechalEncoderState * encoder)29 CodechalKernelIntraDist::CodechalKernelIntraDist(CodechalEncoderState *encoder) :
30 CodechalKernelBase(encoder)
31 {
32
33 }
34
~CodechalKernelIntraDist()35 CodechalKernelIntraDist::~CodechalKernelIntraDist()
36 {
37 ReleaseResources();
38 }
39
AllocateResources()40 MOS_STATUS CodechalKernelIntraDist::AllocateResources()
41 {
42 // no resource need to allocate
43 return MOS_STATUS_SUCCESS;
44 }
45
ReleaseResources()46 MOS_STATUS CodechalKernelIntraDist::ReleaseResources()
47 {
48 // no resource need to release
49 return MOS_STATUS_SUCCESS;
50 }
51
SetCurbe(MHW_KERNEL_STATE * kernelState)52 MOS_STATUS CodechalKernelIntraDist::SetCurbe(MHW_KERNEL_STATE *kernelState)
53 {
54 CODECHAL_ENCODE_CHK_NULL_RETURN(kernelState);
55
56 Curbe curbe;
57
58 curbe.m_data.DW0.picWidthInLumaSamples = m_curbeParam.downScaledWidthInMb4x << 4;
59 curbe.m_data.DW0.picHeightInLumaSamples = m_curbeParam.downScaledHeightInMb4x << 4;
60 curbe.m_data.DW8.currPic4xBTI = BindingTableOffset::intraDistCurrent4xY;
61 curbe.m_data.DW9.intraDistSurfaceBTI = BindingTableOffset::intraDistOutputSurf;
62 curbe.m_data.DW10.vmeIntraPredSurfaceBTI = BindingTableOffset::intraDistVmeIntraPred;
63
64 CODECHAL_ENCODE_CHK_STATUS_RETURN(kernelState->m_dshRegion.AddData(&curbe.m_data, kernelState->dwCurbeOffset, Curbe::m_curbeSize));
65
66 return MOS_STATUS_SUCCESS;
67 }
68
SendSurfaces(PMOS_COMMAND_BUFFER cmd,MHW_KERNEL_STATE * kernelState)69 MOS_STATUS CodechalKernelIntraDist::SendSurfaces(PMOS_COMMAND_BUFFER cmd, MHW_KERNEL_STATE *kernelState)
70 {
71 CODECHAL_SURFACE_CODEC_PARAMS surfaceParams;
72 // 4X DS Surface
73 MOS_ZeroMemory(&surfaceParams, sizeof(CODECHAL_SURFACE_CODEC_PARAMS));
74 surfaceParams.bIs2DSurface = true;
75 surfaceParams.bIsWritable = false;
76 surfaceParams.bMediaBlockRW = true;
77 surfaceParams.psSurface = m_surfaceParam.input4xDsSurface;
78 surfaceParams.dwVerticalLineStride = m_verticalLineStride;
79 surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_HME_DOWNSAMPLED_ENCODE].Value;
80 surfaceParams.dwBindingTableOffset = BindingTableOffset::intraDistCurrent4xY;
81
82 CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState(
83 m_hwInterface,
84 cmd,
85 &surfaceParams,
86 kernelState));
87
88 //Intra Dist Surface
89 MOS_ZeroMemory(&surfaceParams, sizeof(CODECHAL_SURFACE_CODEC_PARAMS));
90 surfaceParams.bIs2DSurface = true;
91 surfaceParams.bIsWritable = true;
92 surfaceParams.bMediaBlockRW = true;
93 surfaceParams.psSurface = m_surfaceParam.intraDistSurface;
94 surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_INTRA_DISTORTION_ENCODE].Value;
95 surfaceParams.dwBindingTableOffset = BindingTableOffset::intraDistOutputSurf;
96
97 CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState(
98 m_hwInterface,
99 cmd,
100 &surfaceParams,
101 kernelState));
102
103 // 4X DS VME Surface
104 MOS_ZeroMemory(&surfaceParams, sizeof(CODECHAL_SURFACE_CODEC_PARAMS));
105 surfaceParams.bUseAdvState = true;
106 surfaceParams.psSurface = m_surfaceParam.input4xDsVmeSurface;
107 surfaceParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_HME_DOWNSAMPLED_ENCODE].Value;
108 surfaceParams.dwBindingTableOffset = BindingTableOffset::intraDistVmeIntraPred;
109 surfaceParams.ucVDirection = CODECHAL_VDIRECTION_FRAME;
110
111 CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState(
112 m_hwInterface,
113 cmd,
114 &surfaceParams,
115 kernelState));
116
117 return MOS_STATUS_SUCCESS;
118 }
119
AddPerfTag()120 MOS_STATUS CodechalKernelIntraDist::AddPerfTag()
121 {
122 PerfTagSetting perfTag;
123
124 perfTag.Value = 0;
125 perfTag.Mode = (uint16_t)m_mode & CODECHAL_ENCODE_MODE_BIT_MASK;
126 perfTag.CallType = CODECHAL_ENCODE_PERFTAG_CALL_INTRA_DIST;
127 perfTag.PictureCodingType = m_pictureCodingType > 3 ? 0 : m_pictureCodingType;
128 m_osInterface->pfnSetPerfTag(m_osInterface, perfTag.Value);
129 m_osInterface->pfnResetPerfBufferID(m_osInterface);
130
131 return MOS_STATUS_SUCCESS;
132 }
133
GetActiveKernelState()134 MHW_KERNEL_STATE *CodechalKernelIntraDist::GetActiveKernelState()
135 {
136 auto it = m_kernelStatePool.find(KernelIndex::intraDistortion);
137 if (it != m_kernelStatePool.end())
138 {
139 return it->second;
140 }
141 MHW_KERNEL_STATE *kernelState = nullptr;
142 CreateKernelState(&kernelState, KernelIndex::intraDistortion, ENC_INTRA_DISTORTION, 0);
143
144 return kernelState;
145 }
146
InitWalkerCodecParams(CODECHAL_WALKER_CODEC_PARAMS & walkerParam)147 MOS_STATUS CodechalKernelIntraDist::InitWalkerCodecParams(CODECHAL_WALKER_CODEC_PARAMS &walkerParam)
148 {
149 walkerParam.WalkerMode = m_walkerMode;
150 walkerParam.dwResolutionX = m_curbeParam.downScaledWidthInMb4x;
151 walkerParam.dwResolutionY = m_curbeParam.downScaledHeightInMb4x;
152 walkerParam.bNoDependency = true;
153
154 return MOS_STATUS_SUCCESS;
155 }
156
GetMediaStateType()157 CODECHAL_MEDIA_STATE_TYPE CodechalKernelIntraDist::GetMediaStateType()
158 {
159 return CODECHAL_MEDIA_STATE_ENC_I_FRAME_DIST;
160 }
161
Execute(CurbeParam & curbeParam,SurfaceParams & surfaceParam)162 MOS_STATUS CodechalKernelIntraDist::Execute( CurbeParam &curbeParam, SurfaceParams &surfaceParam )
163 {
164 MOS_SecureMemcpy(&m_curbeParam, sizeof(m_curbeParam), &curbeParam, sizeof(m_curbeParam));
165 MOS_SecureMemcpy(&m_surfaceParam, sizeof(m_surfaceParam), &surfaceParam, sizeof(m_surfaceParam));
166
167 return Run();
168 }
169