| 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 cm_surface_vme.cpp |
| 24 |
//! \brief Contains Class CmSurfaceVme definitions |
| 25 |
//! |
| 26 |
|
| 27 |
#include "cm_surface_vme.h" |
| 28 |
#include "cm_mem.h" |
| 29 |
#include "cm_hal.h" |
| 30 |
#include "cm_execution_adv.h" |
| 31 |
#include "cm_surface_2d_rt.h" |
| 32 |
#include <string> |
| 33 |
#include <iostream> |
| 34 |
#include <sstream> |
| 35 |
|
| 36 |
namespace CMRT_UMD |
| 37 |
{ |
| 38 |
int32_t CmSurfaceVme::Create( |
| 39 |
uint32_t index, |
| 40 |
uint32_t indexFor2DCurrent, |
| 41 |
uint32_t indexFor2DForward, |
| 42 |
uint32_t indexFor2DBackward, |
| 43 |
uint32_t indexForCurrent, |
| 44 |
uint32_t indexForForward, |
| 45 |
uint32_t indexForBackward, |
| 46 |
CmSurfaceManager* surfaceManager, |
| 47 |
CmSurfaceVme* &surface ) |
| 48 |
{ |
| 49 |
int32_t result = CM_SUCCESS; |
| 50 |
|
| 51 |
surface = new (std::nothrow) CmSurfaceVme( indexFor2DCurrent, indexFor2DForward, indexFor2DBackward, indexForCurrent, indexForForward, indexForBackward, surfaceManager ); |
| 52 |
if( surface ) |
| 53 |
{ |
| 54 |
result = surface->Initialize( index ); |
| 55 |
if( result != CM_SUCCESS ) |
| 56 |
{ |
| 57 |
CmSurface* baseSurface = surface; |
| 58 |
CmSurface::Destroy( baseSurface ); |
| 59 |
} |
| 60 |
} |
| 61 |
else |
| 62 |
{ |
| 63 |
CM_ASSERTMESSAGE("Error: Failed to create CmSurfaceVme due to out of system memory."); |
| 64 |
result = CM_OUT_OF_HOST_MEMORY; |
| 65 |
} |
| 66 |
|
| 67 |
return result; |
| 68 |
} |
| 69 |
|
| 70 |
int32_t CmSurfaceVme::Create( uint32_t index, |
| 71 |
uint32_t indexFor2DCurSurface, |
| 72 |
uint32_t *forwardSurface, |
| 73 |
uint32_t *backwardSurface, |
| 74 |
uint32_t currentIndex, |
| 75 |
uint32_t *forwardCmIndex, |
| 76 |
uint32_t *backwardCmIndex, |
| 77 |
const uint32_t surfaceFCount, |
| 78 |
const uint32_t surfaceBCount, |
| 79 |
CmSurfaceManager* surfaceManager, |
| 80 |
CmSurfaceVme* &surface ) |
| 81 |
{ |
| 82 |
int32_t result = CM_SUCCESS; |
| 83 |
|
| 84 |
surface = new (std::nothrow) CmSurfaceVme(surfaceFCount, surfaceBCount, indexFor2DCurSurface, forwardSurface, backwardSurface, currentIndex, forwardCmIndex, backwardCmIndex, surfaceManager); |
| 85 |
if( surface ) |
| 86 |
{ |
| 87 |
result = surface->Initialize(index); |
| 88 |
if( result != CM_SUCCESS ) |
| 89 |
{ |
| 90 |
CmSurface* baseSurface = surface; |
| 91 |
CmSurface::Destroy( baseSurface ); |
| 92 |
} |
| 93 |
} |
| 94 |
else |
| 95 |
{ |
| 96 |
CM_ASSERTMESSAGE("Error: Failed to create CmSurfaceVme due to out of system memory."); |
| 97 |
result = CM_OUT_OF_HOST_MEMORY; |
| 98 |
} |
| 99 |
|
| 100 |
return result; |
| 101 |
} |
| 102 |
|
| 103 |
CmSurfaceVme::CmSurfaceVme( |
| 104 |
uint32_t indexFor2DCurrent, |
| 105 |
uint32_t indexFor2DForward, |
| 106 |
uint32_t indexFor2DBackward, |
| 107 |
uint32_t indexForCurrent, |
| 108 |
uint32_t indexForForward, |
| 109 |
uint32_t indexForBackward, |
| 110 |
CmSurfaceManager* surfaceManager ): |
| 111 |
CmSurface( surfaceManager,true ), |
| 112 |
m_indexFor2DCurrent( indexFor2DCurrent ), |
| 113 |
m_indexFor2DForward( indexFor2DForward ), |
| 114 |
m_indexFor2DBackward( indexFor2DBackward ), |
| 115 |
m_forwardSurfaceArray(nullptr), |
| 116 |
m_backwardSurfaceArray(nullptr), |
| 117 |
m_cmIndexForCurrent( indexForCurrent ), |
| 118 |
m_cmIndexForForward( indexForForward ), |
| 119 |
m_cmIndexForBackward( indexForBackward ), |
| 120 |
m_forwardCmIndexArray(nullptr), |
| 121 |
m_backwardCmIndexArray(nullptr), |
| 122 |
m_surfStateWidth(0), |
| 123 |
m_surfStateHeight(0), |
| 124 |
m_argValue(nullptr), |
| 125 |
m_surfState(nullptr), |
| 126 |
m_advExec(nullptr), |
| 127 |
m_isGen75(false) |
| 128 |
{ |
| 129 |
if (indexForForward != CM_INVALID_VME_SURFACE) |
| 130 |
{ |
| 131 |
m_surfaceFCount = 1; |
| 132 |
} |
| 133 |
else |
| 134 |
{ |
| 135 |
m_surfaceFCount = 0; |
| 136 |
} |
| 137 |
|
| 138 |
if (indexForBackward != CM_INVALID_VME_SURFACE) |
| 139 |
{ |
| 140 |
m_surfaceBCount = 1; |
| 141 |
} |
| 142 |
else |
| 143 |
{ |
| 144 |
m_surfaceBCount = 0; |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
CmSurfaceVme::CmSurfaceVme( |
| 149 |
const uint32_t surfaceFCount, |
| 150 |
const uint32_t surfaceBCount, |
| 151 |
uint32_t indexFor2DCurSurface, |
| 152 |
uint32_t *forwardSurface, |
| 153 |
uint32_t *backwardSurface, |
| 154 |
uint32_t currentIndex, |
| 155 |
uint32_t *forwardCmIndex, |
| 156 |
uint32_t *backwardCmIndex, |
| 157 |
CmSurfaceManager* surfaceManager): |
| 158 |
CmSurface( surfaceManager, false), |
| 159 |
m_indexFor2DCurrent(indexFor2DCurSurface), |
| 160 |
m_indexFor2DForward(0), |
| 161 |
m_indexFor2DBackward(0), |
| 162 |
m_forwardSurfaceArray(forwardSurface), |
| 163 |
m_backwardSurfaceArray(backwardSurface), |
| 164 |
m_cmIndexForCurrent( currentIndex ), |
| 165 |
m_cmIndexForForward(0), |
| 166 |
m_cmIndexForBackward(0), |
| 167 |
m_forwardCmIndexArray(forwardCmIndex), |
| 168 |
m_backwardCmIndexArray(backwardCmIndex), |
| 169 |
m_surfaceFCount(surfaceFCount), |
| 170 |
m_surfaceBCount(surfaceBCount), |
| 171 |
m_surfStateWidth(0), |
| 172 |
m_surfStateHeight(0), |
| 173 |
m_argValue(nullptr), |
| 174 |
m_surfState(nullptr), |
| 175 |
m_advExec(nullptr), |
| 176 |
m_isGen75(true) |
| 177 |
{ |
| 178 |
} |
| 179 |
|
| 180 |
CmSurfaceVme::~CmSurfaceVme( void ) |
| 181 |
{ |
| 182 |
MosSafeDeleteArray(m_forwardSurfaceArray); |
| 183 |
MosSafeDeleteArray(m_backwardSurfaceArray); |
| 184 |
MosSafeDeleteArray(m_forwardCmIndexArray); |
| 185 |
MosSafeDeleteArray(m_backwardCmIndexArray); |
| 186 |
MosSafeDeleteArray(m_argValue); |
| 187 |
if (m_advExec) |
| 188 |
{ |
| 189 |
m_advExec->DeleteSurfStateVme(m_surfState); |
| 190 |
} |
| 191 |
|
| 192 |
} |
| 193 |
|
| 194 |
int32_t CmSurfaceVme::Initialize( uint32_t index ) |
| 195 |
{ |
| 196 |
return CmSurface::Initialize( index ); |
| 197 |
} |
| 198 |
|
| 199 |
int32_t CmSurfaceVme::GetIndex( SurfaceIndex*& index ) |
| 200 |
{ |
| 201 |
index = m_index; |
| 202 |
return CM_SUCCESS; |
| 203 |
} |
| 204 |
|
| 205 |
int32_t CmSurfaceVme::GetIndexCurrent( uint32_t& index ) |
| 206 |
{ |
| 207 |
index = m_indexFor2DCurrent; |
| 208 |
return CM_SUCCESS; |
| 209 |
} |
| 210 |
|
| 211 |
int32_t CmSurfaceVme::GetIndexForward( uint32_t& index ) |
| 212 |
{ |
| 213 |
index = m_indexFor2DForward; |
| 214 |
return CM_SUCCESS; |
| 215 |
} |
| 216 |
|
| 217 |
int32_t CmSurfaceVme::GetIndexBackward( uint32_t& index ) |
| 218 |
{ |
| 219 |
index = m_indexFor2DBackward; |
| 220 |
return CM_SUCCESS; |
| 221 |
} |
| 222 |
|
| 223 |
int32_t CmSurfaceVme::GetIndexForwardArray( uint32_t *&indexArray) |
| 224 |
{ |
| 225 |
indexArray = m_forwardSurfaceArray; |
| 226 |
return CM_SUCCESS; |
| 227 |
} |
| 228 |
|
| 229 |
int32_t CmSurfaceVme::GetIndexBackwardArray( uint32_t *& indexArray) |
| 230 |
{ |
| 231 |
indexArray = m_backwardSurfaceArray; |
| 232 |
return CM_SUCCESS; |
| 233 |
} |
| 234 |
|
| 235 |
int32_t CmSurfaceVme::GetIndexForwardCount( uint32_t &count) |
| 236 |
{ |
| 237 |
count= m_surfaceFCount; |
| 238 |
return CM_SUCCESS; |
| 239 |
} |
| 240 |
|
| 241 |
///////////// |
| 242 |
int32_t CmSurfaceVme::GetCmIndexCurrent( uint16_t & index ) |
| 243 |
{ |
| 244 |
index = (uint16_t)m_cmIndexForCurrent; |
| 245 |
return CM_SUCCESS; |
| 246 |
} |
| 247 |
|
| 248 |
int32_t CmSurfaceVme::GetCmIndexForward( uint16_t& index ) |
| 249 |
{ |
| 250 |
index = (uint16_t)m_cmIndexForForward; |
| 251 |
return CM_SUCCESS; |
| 252 |
} |
| 253 |
|
| 254 |
int32_t CmSurfaceVme::GetCmIndexBackward( uint16_t& index ) |
| 255 |
{ |
| 256 |
index = (uint16_t)m_cmIndexForBackward; |
| 257 |
return CM_SUCCESS; |
| 258 |
} |
| 259 |
|
| 260 |
int32_t CmSurfaceVme::GetCmIndexForwardArray( uint32_t *&indexArray) |
| 261 |
{ |
| 262 |
indexArray = m_forwardCmIndexArray; |
| 263 |
return CM_SUCCESS; |
| 264 |
} |
| 265 |
|
| 266 |
int32_t CmSurfaceVme::GetCmIndexBackwardArray( uint32_t *& indexArray) |
| 267 |
{ |
| 268 |
indexArray = m_backwardCmIndexArray; |
| 269 |
return CM_SUCCESS; |
| 270 |
} |
| 271 |
///////////// |
| 272 |
|
| 273 |
int32_t CmSurfaceVme::GetIndexBackwardCount( uint32_t & count) |
| 274 |
{ |
| 275 |
count = m_surfaceBCount; |
| 276 |
return CM_SUCCESS; |
| 277 |
} |
| 278 |
|
| 279 |
bool CmSurfaceVme::IsVmeSurfaceGen7_5() |
| 280 |
{ |
| 281 |
return m_isGen75; |
| 282 |
} |
| 283 |
|
| 284 |
int32_t CmSurfaceVme::GetSurfaceStateResolution(uint32_t& width, uint32_t& height) |
| 285 |
{ |
| 286 |
width = m_surfStateWidth; |
| 287 |
height = m_surfStateHeight; |
| 288 |
return CM_SUCCESS; |
| 289 |
} |
| 290 |
|
| 291 |
int32_t CmSurfaceVme::SetSurfaceStateResolution(uint32_t width, uint32_t height) |
| 292 |
{ |
| 293 |
m_surfStateWidth = width; |
| 294 |
m_surfStateHeight = height; |
| 295 |
return CM_SUCCESS; |
| 296 |
} |
| 297 |
|
| 298 |
int32_t CmSurfaceVme::GetTotalSurfacesCount() |
| 299 |
{ |
| 300 |
return m_surfaceFCount + m_surfaceBCount + 1; |
| 301 |
} |
| 302 |
|
| 303 |
int32_t CmSurfaceVme::GetVmeCmArgSize() |
| 304 |
{ |
| 305 |
return sizeof(CM_HAL_VME_ARG_VALUE) + (m_surfaceFCount + m_surfaceBCount) * sizeof(uint32_t); |
| 306 |
} |
| 307 |
|
| 308 |
void CmSurfaceVme::SetSurfState(CmExecutionAdv *advExec, uint8_t *argValue, CmSurfaceStateVME *surfState) |
| 309 |
{ |
| 310 |
MosSafeDeleteArray(m_argValue); |
| 311 |
if (advExec) |
| 312 |
{ |
| 313 |
advExec->DeleteSurfStateVme(m_surfState); |
| 314 |
} |
| 315 |
|
| 316 |
m_advExec = advExec; |
| 317 |
m_argValue = argValue; |
| 318 |
m_surfState = surfState; |
| 319 |
} |
| 320 |
|
| 321 |
void CmSurfaceVme::DumpContent(uint32_t kernelNumber, char *kernelName, int32_t taskId, uint32_t argIndex, uint32_t vectorIndex) |
| 322 |
{ |
| 323 |
// dump current surface |
| 324 |
#if MDF_SURFACE_CONTENT_DUMP |
| 325 |
std::ostringstream outputFileName; |
| 326 |
|
| 327 |
outputFileName << "t_" << taskId |
| 328 |
<< "_k_" << kernelNumber |
| 329 |
<< "_" << kernelName |
| 330 |
<< "_argi_" << argIndex |
| 331 |
<< "_vector_index_" << vectorIndex |
| 332 |
<< "vme_cur"; |
| 333 |
|
| 334 |
CmSurface *surface = nullptr; |
| 335 |
m_surfaceMgr->GetSurface(m_cmIndexForCurrent, surface); |
| 336 |
|
| 337 |
CmSurface2DRT *surface2DRT = dynamic_cast<CmSurface2DRT *>(surface); |
| 338 |
if (surface2DRT) |
| 339 |
{ |
| 340 |
surface2DRT->DumpContentToFile(outputFileName.str().c_str()); |
| 341 |
} |
| 342 |
|
| 343 |
for (uint32_t i = 0; i < m_surfaceFCount; i ++) |
| 344 |
{ |
| 345 |
outputFileName.str(std::string()); // clear the stream |
| 346 |
outputFileName << "t_" << taskId |
| 347 |
<< "_k_" << kernelNumber |
| 348 |
<< "_" << kernelName |
| 349 |
<< "_argi_" << argIndex |
| 350 |
<< "_vector_index_" << vectorIndex |
| 351 |
<< "vme_fw" << i; |
| 352 |
|
| 353 |
CmSurface *surface = nullptr; |
| 354 |
m_surfaceMgr->GetSurface(m_forwardCmIndexArray[i], surface); |
| 355 |
|
| 356 |
CmSurface2DRT *surface2DRT = dynamic_cast<CmSurface2DRT *>(surface); |
| 357 |
if (surface2DRT) |
| 358 |
{ |
| 359 |
surface2DRT->DumpContentToFile(outputFileName.str().c_str()); |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
for (uint32_t i = 0; i < m_surfaceBCount; i ++) |
| 364 |
{ |
| 365 |
outputFileName.str(std::string()); // clear the stream |
| 366 |
outputFileName << "t_" << taskId |
| 367 |
<< "_k_" << kernelNumber |
| 368 |
<< "_" << kernelName |
| 369 |
<< "_argi_" << argIndex |
| 370 |
<< "_vector_index_" << vectorIndex |
| 371 |
<< "vme_bw" << i; |
| 372 |
|
| 373 |
CmSurface *surface = nullptr; |
| 374 |
m_surfaceMgr->GetSurface(m_backwardCmIndexArray[i], surface); |
| 375 |
|
| 376 |
CmSurface2DRT *surface2DRT = dynamic_cast<CmSurface2DRT *>(surface); |
| 377 |
if (surface2DRT) |
| 378 |
{ |
| 379 |
surface2DRT->DumpContentToFile(outputFileName.str().c_str()); |
| 380 |
} |
| 381 |
} |
| 382 |
#endif |
| 383 |
} |
| 384 |
|
| 385 |
} |
| 386 |
|