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 CMRTKernel_DownScaling.cpp
24 //! \brief HEVC FEI 2xScaling class for GEN9 SKL.
25 //!
26
27 #include "CMRTKernel_DownScaling.h"
28 #include "CMRTKernel_DS_Kernel_def.h"
29
CMRTKernelDownScaling()30 CMRTKernelDownScaling::CMRTKernelDownScaling()
31 {
32
33 m_isaName = HME_DOWNSCALE_GEN9;
34 m_isaSize = HME_DOWNSCALE_GEN9_SIZE;
35 m_kernelName = HEVCENCKERNELNAME_2xDS_FRAME;
36
37 m_cmSurface2DCount = 2;
38 m_cmBufferCount = 1;
39 m_cmVmeSurfCount = 0;
40
41 if (m_cmSurface2DCount > 0)
42 {
43 m_cmSurface2D = (CmSurface2D **)malloc(sizeof(CmSurface2D *) * m_cmSurface2DCount);
44 if (m_cmSurface2D != NULL)
45 {
46 memset(m_cmSurface2D, 0, sizeof(CmSurface2D *) * m_cmSurface2DCount);
47 }
48 }
49
50 if (m_cmBufferCount > 0)
51 {
52 m_cmBuffer = (CmBuffer **)malloc(sizeof(CmBuffer *) * m_cmBufferCount);
53 if (m_cmBuffer != NULL)
54 {
55 memset(m_cmBuffer, 0, sizeof(CmBuffer *) * m_cmBufferCount);
56 }
57 }
58
59 if (m_cmVmeSurfCount > 0)
60 {
61 m_cmVmeSurf = (SurfaceIndex **)malloc(sizeof(SurfaceIndex *) * m_cmVmeSurfCount);
62 if (m_cmVmeSurf != NULL)
63 {
64 memset(m_cmVmeSurf, 0, sizeof(SurfaceIndex *) * m_cmVmeSurfCount);
65 }
66 }
67
68 m_surfIndex = (SurfaceIndex **)malloc(sizeof(SurfaceIndex *) * (m_cmSurface2DCount + m_cmBufferCount + m_cmVmeSurfCount));
69 if (m_surfIndex != NULL)
70 {
71 memset(m_surfIndex, 0, sizeof(SurfaceIndex *) * (m_cmSurface2DCount + m_cmBufferCount + m_cmVmeSurfCount));
72 }
73 }
74
~CMRTKernelDownScaling()75 CMRTKernelDownScaling::~CMRTKernelDownScaling()
76 {
77 if (m_cmSurface2D != nullptr)
78 {
79 free(m_cmSurface2D);
80 }
81
82 if (m_cmBuffer != nullptr)
83 {
84 free(m_cmBuffer);
85 }
86
87 if (m_cmVmeSurf != nullptr)
88 {
89 free(m_cmVmeSurf);
90 }
91
92 if (m_surfIndex != nullptr)
93 {
94 free(m_surfIndex);
95 }
96 }
97
SetupCurbe(void * curbe)98 CM_RETURN_CODE CMRTKernelDownScaling::SetupCurbe(void *curbe)
99 {
100 m_curbe = curbe;
101 return CM_SUCCESS;
102 }
103
CreateAndDispatchKernel(CmEvent * & cmEvent,bool destroyEvent,bool isEnqueue)104 CM_RETURN_CODE CMRTKernelDownScaling::CreateAndDispatchKernel(CmEvent *&cmEvent, bool destroyEvent, bool isEnqueue)
105 {
106 CM_RETURN_CODE r = CM_SUCCESS;
107 int32_t result;
108 uint32_t *curbe = (uint32_t *)m_curbe;
109 uint32_t reserved[7];
110 uint32_t width, height, scaling2xWidth, scaling2xHeight, threadSpaceWidth, threadSpaceHeight;
111
112 width = curbe[0] & 0x0FFFF;
113 height = (curbe[0] >> 16) & 0x0FFFF;
114
115 scaling2xWidth = (16 * MOS_ROUNDUP_DIVIDE(width , 32));
116 scaling2xHeight = (16 * MOS_ROUNDUP_DIVIDE(height , 32));
117
118 if (scaling2xWidth < 48)
119 {
120 scaling2xWidth = 48;
121 }
122
123 if (scaling2xHeight < 48)
124 {
125 scaling2xHeight = 48;
126 }
127
128 threadSpaceWidth = MOS_ROUNDUP_DIVIDE(scaling2xWidth, 16); // Each 16x16 pixel output is completed by 1 thread
129 threadSpaceHeight = MOS_ROUNDUP_DIVIDE(scaling2xHeight, 16); // Each 16x16 pixel output is completed by 1 thread
130
131 m_cmKernel->SetKernelArg(0, sizeof(uint16_t), &width); // DW0
132 m_cmKernel->SetKernelArg(1, sizeof(uint16_t), &height); // DW0
133 m_cmKernel->SetKernelArg(2, 7 * sizeof(uint32_t), reserved);
134 m_cmKernel->SetKernelArg(3, sizeof(SurfaceIndex), m_surfIndex[0]); // DW8
135 m_cmKernel->SetKernelArg(4, sizeof(SurfaceIndex), m_surfIndex[1]); // DW9
136
137 CM_CHK_STATUS_RETURN(m_cmKernel->SetThreadCount(threadSpaceWidth * threadSpaceHeight));
138 //create Thread Space
139 result = CreateThreadSpace(threadSpaceWidth, threadSpaceHeight);
140 if (result != CM_SUCCESS)
141 {
142 printf("CM Create ThreadSpace error : %d", result);
143 return (CM_RETURN_CODE)result;
144 }
145
146 r = AddKernel(cmEvent, destroyEvent, isEnqueue);
147 return r;
148 }
149
AllocateSurfaces(void * params)150 CM_RETURN_CODE CMRTKernelDownScalingUMD::AllocateSurfaces(void *params)
151 {
152 DownScalingKernelParams *scalingParams=(DownScalingKernelParams *)params;
153
154 CM_CHK_STATUS_RETURN(m_cmDev->CreateSurface2D((MOS_RESOURCE *)scalingParams->m_cmSurfDS_TopIn, m_cmSurface2D[0]));
155 CM_CHK_STATUS_RETURN(m_cmSurface2D[0]->GetIndex(m_surfIndex[0]));
156
157 CM_CHK_STATUS_RETURN(m_cmDev->CreateSurface2D((MOS_RESOURCE *)scalingParams->m_cmSurfDS_TopOut, m_cmSurface2D[1]));
158 CM_CHK_STATUS_RETURN(m_cmSurface2D[1]->GetIndex(m_surfIndex[1]));
159
160 if (scalingParams->m_cmSurfTopVProc != nullptr)
161 {
162 CM_CHK_STATUS_RETURN(m_cmDev->CreateBuffer((MOS_RESOURCE *)scalingParams->m_cmSurfTopVProc, m_cmBuffer[0]));
163 CM_CHK_STATUS_RETURN(m_cmBuffer[0]->GetIndex(m_surfIndex[2]));
164 }
165 else
166 {
167 m_surfIndex[2] = nullptr;
168 }
169
170 return CM_SUCCESS;
171 }
172
173