Debian Codegraph @

media_softlet/agnostic/common/shared/mediacopy/media_copy.cpp

raw
1 /*
2 * Copyright (c) 2020-2021, 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 media_copy.cpp
24 //! \brief Common interface and structure used in media copy
25 //! \details Common interface and structure used in media copy which are platform independent
26 //!
27
28 #include "media_copy.h"
29 #include "media_copy_common.h"
30 #include "media_debug_dumper.h"
31 #include "mhw_cp_interface.h"
32 #include "mos_utilities.h"
33 #include "mos_util_debug.h"
34
35 #define BLT_MAX_WIDTH (1 << 16) - 1
36 #define BLT_MAX_HEIGHT (1 << 16) - 1
37 #define BLT_MAX_PITCH (1 << 18) - 1
38
39 #define VE_MIN_WIDTH 64
40 #define VE_MIN_HEIGHT 32
41
42 #define RENDER_MIN_WIDTH 16
43 #define RENDER_MIN_HEIGHT 16
44
45 MediaCopyBaseState::MediaCopyBaseState():
46 m_osInterface(nullptr)
47 {
48
49 }
50
51 MediaCopyBaseState::~MediaCopyBaseState()
52 {
53 if (m_osInterface)
54 {
55 m_osInterface->pfnDestroy(m_osInterface, false);
56 MOS_FreeMemory(m_osInterface);
57 m_osInterface = nullptr;
58 }
59
60 if (m_inUseGPUMutex)
61 {
62 MosUtilities::MosDestroyMutex(m_inUseGPUMutex);
63 m_inUseGPUMutex = nullptr;
64 }
65
66 #if (_DEBUG || _RELEASE_INTERNAL)
67 if (m_surfaceDumper != nullptr)
68 {
69 MOS_Delete(m_surfaceDumper);
70 m_surfaceDumper = nullptr;
71 }
72 #endif
73 }
74
75 //!
76 //! \brief init Media copy
77 //! \details init func.
78 //! \param none
79 //! \return MOS_STATUS
80 //! Return MOS_STATUS_SUCCESS if success, otherwise return failed.
81 //!
82 MOS_STATUS MediaCopyBaseState::Initialize(PMOS_INTERFACE osInterface)
83 {
84 if (m_inUseGPUMutex == nullptr)
85 {
86 m_inUseGPUMutex = MosUtilities::MosCreateMutex();
87 MCPY_CHK_NULL_RETURN(m_inUseGPUMutex);
88 }
89 MCPY_CHK_NULL_RETURN(m_osInterface);
90 Mos_SetVirtualEngineSupported(m_osInterface, true);
91 m_osInterface->pfnVirtualEngineSupported(m_osInterface, true, true);
92
93 #if (_DEBUG || _RELEASE_INTERNAL)
94 if (m_surfaceDumper == nullptr)
95 {
96 m_surfaceDumper = MOS_New(CommonSurfaceDumper, osInterface);
97 MOS_OS_CHK_NULL_RETURN(m_surfaceDumper);
98 }
99 MediaUserSettingSharedPtr userSettingPtr = nullptr;
100
101 m_surfaceDumper->GetSurfaceDumpLocation(m_dumpLocation_in, mcpy_in);
102 m_surfaceDumper->GetSurfaceDumpLocation(m_dumpLocation_out, mcpy_out);
103 if (m_osInterface)
104 {
105 userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface);
106 ReadUserSettingForDebug(
107 userSettingPtr,
108 m_MCPYForceMode,
109 __MEDIA_USER_FEATURE_SET_MCPY_FORCE_MODE,
110 MediaUserSetting::Group::Device);
111
112 ReadUserSettingForDebug(
113 userSettingPtr,
114 m_enableVeCopySmallRes,
115 __MEDIA_USER_FEATURE_ENABLE_VECOPY_SMALL_RESOLUTION,
116 MediaUserSetting::Group::Device);
117 }
118 #endif
119 return MOS_STATUS_SUCCESS;
120 }
121
122 //!
123 //! \brief check copy capability.
124 //! \details to determine surface copy is supported or not.
125 //! \param none
126 //! \return MOS_STATUS
127 //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort.
128 //!
129 MOS_STATUS MediaCopyBaseState::CapabilityCheck(
130 MOS_FORMAT format,
131 MCPY_STATE_PARAMS &mcpySrc,
132 MCPY_STATE_PARAMS &mcpyDst,
133 MCPY_ENGINE_CAPS &caps,
134 MCPY_METHOD preferMethod)
135 {
136 // derivate class specific check. include HW engine avaliable check.
137 MCPY_CHK_STATUS_RETURN(FeatureSupport(mcpySrc.OsRes, mcpyDst.OsRes, mcpySrc, mcpyDst, caps));
138
139 // common policy check
140 // legal check
141 // Blt engine does not support protection, allow the copy if dst is staging buffer in system mem
142 if (preferMethod == MCPY_METHOD_POWERSAVING &&
143 (mcpySrc.CpMode == MCPY_CPMODE_CP || mcpyDst.CpMode == MCPY_CPMODE_CP))
144 {
145 MCPY_ASSERTMESSAGE("illegal usage");
146 return MOS_STATUS_INVALID_PARAMETER;
147 }
148
149 if (MCPY_METHOD_PERFORMANCE == preferMethod && !caps.engineRender)
150 {
151 MCPY_ASSERTMESSAGE("No cap support for render copy, so app could not prefer to use EU copy");
152 return MOS_STATUS_INVALID_PARAMETER; // Bypass media copy, and let APP handle it.
153 }
154 // vebox cap check.
155 if (!IsVeboxCopySupported(mcpySrc.OsRes, mcpyDst.OsRes) || // format check, implemented on Gen derivate class.
156 mcpySrc.bAuxSuface)
157 {
158 caps.engineVebox = false;
159 // temp solution for FP16 enabling on new platform
160 if (format == Format_A16B16G16R16F || format == Format_A16R16G16B16F)
161 {
162 return MOS_STATUS_UNIMPLEMENTED;
163 }
164 }
165
166 // Eu cap check.
167 if (!RenderFormatSupportCheck(mcpySrc.OsRes, mcpyDst.OsRes) || // format check, implemented on Gen derivate class.
168 mcpySrc.bAuxSuface)
169 {
170 caps.engineRender = false;
171 }
172
173 if (!caps.engineVebox && !caps.engineBlt && !caps.engineRender)
174 {
175 return MOS_STATUS_INVALID_PARAMETER; // unsupport copy on each hw engine.
176 }
177
178 MEDIA_WA_TABLE *pWaTable = m_osInterface->pfnGetWaTable(m_osInterface);
179 if ((format == Format_Y210 || format == Format_Y216) &&
180 MEDIA_IS_WA(pWaTable, Wa_16024792527_OptionB))
181 {
182 caps.engineRender = false;
183 m_bRenderFallbackToBlt = true;
184 }
185
186 return MOS_STATUS_SUCCESS;
187 }
188
189 //!
190 //! \brief surface copy pre process.
191 //! \details pre process before doing surface copy.
192 //! \param none
193 //! \return MOS_STATUS
194 //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort.
195 //!
196 MOS_STATUS MediaCopyBaseState::PreCheckCpCopy(
197 MCPY_STATE_PARAMS src, MCPY_STATE_PARAMS dest, MCPY_METHOD preferMethod)
198 {
199 if (preferMethod == MCPY_METHOD_POWERSAVING &&
200 (src.CpMode == MCPY_CPMODE_CP || dest.CpMode == MCPY_CPMODE_CP))
201 {
202 MCPY_ASSERTMESSAGE("BLT Copy with CP is not supported");
203 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
204 }
205
206 return MOS_STATUS_SUCCESS;
207 }
208
209 //!
210 //! \brief dispatch copy task if support.
211 //! \details dispatch copy task to HW engine (vebox, EU, Blt) based on customer and default.
212 //! \param src
213 //! [in] Pointer to source surface
214 //! \param dst
215 //! [in] Pointer to destination surface
216 //! \return MOS_STATUS
217 //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort.
218 //!
219 MOS_STATUS MediaCopyBaseState::CopyEnigneSelect(MCPY_METHOD& preferMethod, MCPY_ENGINE& mcpyEngine, MCPY_ENGINE_CAPS& caps)
220 {
221 // driver should make sure there is at least one he can process copy even customer choice doesn't match caps.
222 switch (preferMethod)
223 {
224 case MCPY_METHOD_PERFORMANCE:
225 mcpyEngine = caps.engineRender?MCPY_ENGINE_RENDER:(caps.engineBlt ? MCPY_ENGINE_BLT : MCPY_ENGINE_VEBOX);
226 break;
227 case MCPY_METHOD_BALANCE:
228 mcpyEngine = caps.engineVebox?MCPY_ENGINE_VEBOX:(caps.engineBlt?MCPY_ENGINE_BLT:MCPY_ENGINE_RENDER);
229 break;
230 case MCPY_METHOD_POWERSAVING:
231 case MCPY_METHOD_DEFAULT:
232 mcpyEngine = caps.engineBlt?MCPY_ENGINE_BLT:(caps.engineVebox?MCPY_ENGINE_VEBOX:MCPY_ENGINE_RENDER);
233 break;
234 default:
235 break;
236 }
237 #if (_DEBUG || _RELEASE_INTERNAL)
238 if (MCPY_METHOD_PERFORMANCE == m_MCPYForceMode)
239 {
240 mcpyEngine = MCPY_ENGINE_RENDER;
241 }
242 else if (MCPY_METHOD_POWERSAVING == m_MCPYForceMode)
243 {
244 mcpyEngine = MCPY_ENGINE_BLT;
245 }
246 else if (MCPY_METHOD_BALANCE == m_MCPYForceMode)
247 {
248 mcpyEngine = MCPY_ENGINE_VEBOX;
249 }
250 else if (MCPY_METHOD_DEFAULT != m_MCPYForceMode)
251 {
252 return MOS_STATUS_INVALID_PARAMETER; // bypass copy engine, just let APP handle it.
253 }
254 #endif
255 return MOS_STATUS_SUCCESS;
256 }
257
258 uint32_t GetMinRequiredSurfaceSizeInBytes(uint32_t pitch, uint32_t height, MOS_FORMAT format)
259 {
260 uint32_t nBytes = 0;
261 switch (format)
262 {
263 case Format_NV12:
264 case Format_YV12:
265 case Format_I420:
266 case Format_P010:
267 case Format_P016:
268 nBytes = pitch * height + (pitch >> 1) * (height >> 1) + (pitch >> 1) * (height >> 1);
269 break;
270 case Format_RGBP:
271 case Format_BGRP:
272 nBytes = pitch * height + pitch * height + pitch * height;
273 break;
274 case Format_Y410:
275 case Format_Y416:
276 case Format_Y210:
277 case Format_Y216:
278 case Format_YUY2:
279 case Format_R5G6B5:
280 case Format_R8G8B8:
281 case Format_A8R8G8B8:
282 case Format_A8B8G8R8:
283 case Format_X8R8G8B8:
284 case Format_X8B8G8R8:
285 case Format_AYUV:
286 case Format_R10G10B10A2:
287 case Format_B10G10R10A2:
288 case Format_P8:
289 case Format_L8:
290 case Format_A8:
291 case Format_Y16U:
292 case Format_A16B16G16R16F:
293 case Format_A16R16G16B16F:
294 case Format_A16B16G16R16:
295 case Format_A16R16G16B16:
296 case Format_IRW0:
297 case Format_IRW1:
298 case Format_IRW2:
299 case Format_IRW3:
300 case Format_R16UN:
301 nBytes = pitch * height;
302 break;
303 default:
304 MCPY_ASSERTMESSAGE("Unsupported format!");
305 break;
306 }
307 return nBytes;
308 }
309
310 MOS_STATUS MediaCopyBaseState::CheckResourceSizeValidForCopy(const MOS_SURFACE &res, const MCPY_ENGINE method)
311 {
312 if (res.TileType != MOS_TILE_LINEAR)
313 {
314 return MOS_STATUS_SUCCESS;
315 }
316
317 uint32_t nBytes = GetMinRequiredSurfaceSizeInBytes(res.dwPitch, res.dwHeight, res.Format);
318 if (nBytes == 0)
319 {
320 return MOS_STATUS_INVALID_PARAMETER;
321 }
322 if (res.dwSize < nBytes)
323 {
324 MT_ERR2(MT_MEDIA_COPY,
325 MT_MEDIA_COPY_DATASIZE, nBytes,
326 MT_MEDIA_COPY_DATASIZE, res.dwSize);
327
328 return MOS_STATUS_INVALID_PARAMETER;
329 }
330
331 if (method == MCPY_ENGINE_BLT)
332 {
333 if (res.dwPitch > BLT_MAX_PITCH || res.dwHeight > BLT_MAX_HEIGHT || res.dwWidth > BLT_MAX_WIDTH)
334 {
335 MT_ERR3(MT_MEDIA_COPY,
336 MT_SURF_WIDTH, res.dwWidth,
337 MT_SURF_HEIGHT, res.dwHeight,
338 MT_SURF_PITCH, res.dwPitch);
339 MCPY_ASSERTMESSAGE("Surface size overflow! pitch %d, height %d, width %d", res.dwPitch, res.dwHeight, res.dwWidth);
340 return MOS_STATUS_INVALID_PARAMETER;
341 }
342 }
343
344 if (method == MCPY_ENGINE_RENDER)
345 {
346 if (res.dwHeight < RENDER_MIN_HEIGHT || res.dwWidth < RENDER_MIN_WIDTH)
347 {
348 MT_ERR2(MT_MEDIA_COPY,
349 MT_SURF_WIDTH, res.dwWidth,
350 MT_SURF_HEIGHT, res.dwHeight);
351 MCPY_ASSERTMESSAGE("Surface size not meet min requirement! height %d, width %d", res.dwHeight, res.dwWidth);
352 return MOS_STATUS_INVALID_PARAMETER;
353 }
354 }
355
356 if (method == MCPY_ENGINE_VEBOX)
357 {
358 #if (_DEBUG || _RELEASE_INTERNAL)
359 if (!m_enableVeCopySmallRes)
360 #endif
361 {
362 if (res.dwHeight < VE_MIN_HEIGHT || res.dwWidth < VE_MIN_WIDTH)
363 {
364 MT_ERR2(MT_MEDIA_COPY,
365 MT_SURF_WIDTH, res.dwWidth,
366 MT_SURF_HEIGHT, res.dwHeight);
367 MCPY_ASSERTMESSAGE("Surface size not meet min requirement! height %d, width %d", res.dwHeight, res.dwWidth);
368 return MOS_STATUS_INVALID_PARAMETER;
369 }
370 }
371 }
372
373 return MOS_STATUS_SUCCESS;
374 }
375
376 MOS_STATUS MediaCopyBaseState::ValidateResource(const MOS_SURFACE &src, const MOS_SURFACE &dst, MCPY_ENGINE method)
377 {
378 // For CP buffer copy, CP will handle the overflown size, skip size check
379 if (src.OsResource.pGmmResInfo->GetResourceType() == RESOURCE_BUFFER &&
380 dst.OsResource.pGmmResInfo->GetResourceType() == RESOURCE_BUFFER &&
381 method == MCPY_ENGINE_BLT)
382 {
383 return MOS_STATUS_SUCCESS;
384 }
385
386 MCPY_CHK_STATUS_RETURN(CheckResourceSizeValidForCopy(src, method));
387 MCPY_CHK_STATUS_RETURN(CheckResourceSizeValidForCopy(dst, method));
388
389 return MOS_STATUS_SUCCESS;
390 }
391
392 //!
393 //! \brief surface copy func.
394 //! \details copy surface.
395 //! \param src
396 //! [in] Pointer to source surface
397 //! \param dst
398 //! [in] Pointer to destination surface
399 //! \return MOS_STATUS
400 //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort.
401 //!
402 MOS_STATUS MediaCopyBaseState::SurfaceCopy(PMOS_RESOURCE src, PMOS_RESOURCE dst, MCPY_METHOD preferMethod)
403 {
404 MOS_TraceEventExt(EVENT_MEDIA_COPY, EVENT_TYPE_START, nullptr, 0, nullptr, 0);
405 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
406
407 MOS_SURFACE SrcResDetails, DstResDetails;
408 MOS_ZeroMemory(&SrcResDetails, sizeof(MOS_SURFACE));
409 MOS_ZeroMemory(&DstResDetails, sizeof(MOS_SURFACE));
410 SrcResDetails.Format = Format_Invalid;
411 SrcResDetails.OsResource = *src;
412 DstResDetails.Format = Format_Invalid;
413 DstResDetails.OsResource = *dst;
414
415 MCPY_STATE_PARAMS mcpySrc = {nullptr, MOS_MMC_DISABLED, MOS_TILE_LINEAR, MCPY_CPMODE_CLEAR, false};
416 MCPY_STATE_PARAMS mcpyDst = {nullptr, MOS_MMC_DISABLED, MOS_TILE_LINEAR, MCPY_CPMODE_CLEAR, false};
417 MCPY_ENGINE mcpyEngine = MCPY_ENGINE_BLT;
418 MCPY_ENGINE_CAPS mcpyEngineCaps = {1, 1, 1, 1};
419
420 MCPY_CHK_STATUS_RETURN(m_osInterface->pfnGetResourceInfo(m_osInterface, src, &SrcResDetails));
421 MCPY_CHK_STATUS_RETURN(m_osInterface->pfnGetMemoryCompressionMode(m_osInterface, src, (PMOS_MEMCOMP_STATE)&(mcpySrc.CompressionMode)));
422 mcpySrc.CpMode = src->pGmmResInfo->GetSetCpSurfTag(false, 0)?MCPY_CPMODE_CP:MCPY_CPMODE_CLEAR;
423 mcpySrc.TileMode = SrcResDetails.TileType;
424 mcpySrc.OsRes = src;
425 MCPY_NORMALMESSAGE("input surface's format %d, width %d; hight %d, pitch %d, tiledmode %d, mmc mode %d, cp mode %d, ResType %d, preferMethod %d",
426 SrcResDetails.Format,
427 SrcResDetails.dwWidth,
428 SrcResDetails.dwHeight,
429 SrcResDetails.dwPitch,
430 mcpySrc.TileMode,
431 mcpySrc.CompressionMode,
432 mcpySrc.CpMode,
433 src->pGmmResInfo->GetResourceType(),
434 preferMethod);
435 MT_LOG7(MT_MEDIA_COPY, MT_NORMAL,
436 MT_SURF_PITCH, SrcResDetails.dwPitch,
437 MT_SURF_HEIGHT, SrcResDetails.dwHeight,
438 MT_SURF_WIDTH, SrcResDetails.dwWidth,
439 MT_SURF_MOS_FORMAT, SrcResDetails.Format,
440 MT_MEDIA_COPY_DATASIZE, SrcResDetails.dwSize,
441 MT_SURF_TILE_TYPE, SrcResDetails.TileType,
442 MT_SURF_COMP_MODE, mcpySrc.CompressionMode);
443
444 MCPY_CHK_STATUS_RETURN(m_osInterface->pfnGetResourceInfo(m_osInterface, dst, &DstResDetails));
445 MCPY_CHK_STATUS_RETURN(m_osInterface->pfnGetMemoryCompressionMode(m_osInterface,dst, (PMOS_MEMCOMP_STATE) &(mcpyDst.CompressionMode)));
446 mcpyDst.CpMode = dst->pGmmResInfo->GetSetCpSurfTag(false, 0)?MCPY_CPMODE_CP:MCPY_CPMODE_CLEAR;
447 mcpyDst.TileMode = DstResDetails.TileType;
448 mcpyDst.OsRes = dst;
449 MCPY_NORMALMESSAGE("Output surface's format %d, width %d; hight %d, pitch %d, tiledmode %d, mmc mode %d,cp mode %d, ResType %d",
450 DstResDetails.Format,
451 DstResDetails.dwWidth,
452 DstResDetails.dwHeight,
453 DstResDetails.dwPitch,
454 mcpyDst.TileMode,
455 mcpyDst.CompressionMode,
456 mcpyDst.CpMode,
457 dst->pGmmResInfo->GetResourceType());
458 MT_LOG7(MT_MEDIA_COPY, MT_NORMAL,
459 MT_SURF_PITCH, DstResDetails.dwPitch,
460 MT_SURF_HEIGHT, DstResDetails.dwHeight,
461 MT_SURF_WIDTH, DstResDetails.dwWidth,
462 MT_SURF_MOS_FORMAT, DstResDetails.Format,
463 MT_MEDIA_COPY_DATASIZE, DstResDetails.dwSize,
464 MT_SURF_TILE_TYPE, DstResDetails.TileType,
465 MT_SURF_COMP_MODE, mcpyDst.CompressionMode);
466
467 #if (_DEBUG || _RELEASE_INTERNAL) && !defined(LINUX)
468 TRACEDATA_MEDIACOPY eventData = {0};
469 TRACEDATA_MEDIACOPY_INIT(
470 eventData,
471 src->AllocationInfo.m_AllocationHandle,
472 SrcResDetails.dwWidth,
473 SrcResDetails.dwHeight,
474 SrcResDetails.Format,
475 *((int64_t *)&src->pGmmResInfo->GetResFlags().Gpu),
476 *((int64_t *)&src->pGmmResInfo->GetResFlags().Info),
477 src->pGmmResInfo->GetSetCpSurfTag(0, 0),
478 dst->AllocationInfo.m_AllocationHandle,
479 DstResDetails.dwWidth,
480 DstResDetails.dwHeight,
481 DstResDetails.Format,
482 *((int64_t *)&dst->pGmmResInfo->GetResFlags().Gpu),
483 *((int64_t *)&dst->pGmmResInfo->GetResFlags().Info),
484 dst->pGmmResInfo->GetSetCpSurfTag(0, 0)
485 );
486
487 MOS_TraceEventExt(EVENT_MEDIA_COPY, EVENT_TYPE_INFO, &eventData, sizeof(eventData), nullptr, 0);
488 #endif
489
490 MCPY_CHK_STATUS_RETURN(PreCheckCpCopy(mcpySrc, mcpyDst, preferMethod));
491
492 MCPY_CHK_STATUS_RETURN(CapabilityCheck(SrcResDetails.Format,
493 mcpySrc, mcpyDst,
494 mcpyEngineCaps, preferMethod));
495
496 MCPY_CHK_STATUS_RETURN(CopyEnigneSelect(preferMethod, mcpyEngine, mcpyEngineCaps));
497
498 MCPY_CHK_STATUS_RETURN(ValidateResource(SrcResDetails, DstResDetails, mcpyEngine));
499
500 MCPY_CHK_STATUS_RETURN(TaskDispatch(mcpySrc, mcpyDst, mcpyEngine));
501
502 MOS_TraceEventExt(EVENT_MEDIA_COPY, EVENT_TYPE_END, nullptr, 0, nullptr, 0);
503 return eStatus;
504 }
505
506 MOS_STATUS MediaCopyBaseState::TaskDispatch(MCPY_STATE_PARAMS mcpySrc, MCPY_STATE_PARAMS mcpyDst, MCPY_ENGINE mcpyEngine)
507 {
508 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
509
510
511 #if (_DEBUG || _RELEASE_INTERNAL)
512 MOS_SURFACE sourceSurface = {};
513 MOS_SURFACE targetSurface = {};
514
515 targetSurface.Format = Format_Invalid;
516 targetSurface.OsResource = *mcpyDst.OsRes;
517
518 #if !defined(LINUX) && !defined(ANDROID) && !EMUL
519 MOS_ZeroMemory(&targetSurface.OsResource.AllocationInfo, sizeof(SResidencyInfo));
520 #endif
521
522 sourceSurface.Format = Format_Invalid;
523 sourceSurface.OsResource = *mcpySrc.OsRes;
524
525 m_osInterface->pfnGetResourceInfo(m_osInterface, &sourceSurface.OsResource, &sourceSurface);
526 m_osInterface->pfnGetResourceInfo(m_osInterface, &targetSurface.OsResource, &targetSurface);
527
528 // Set the dump location like "dumpLocation before MCPY=path_to_dump_folder" in user feature configure file
529 // Otherwise, the surface may not be dumped
530 // Only dump linear surface
531 if (m_surfaceDumper && mcpySrc.TileMode == MOS_TILE_LINEAR)
532 {
533 if ((*m_dumpLocation_in == '\0') || (*m_dumpLocation_in == ' '))
534 {
535 MCPY_NORMALMESSAGE("Invalid dump location set, the surface will not be dumped");
536 }
537 else
538 {
539 m_surfaceDumper->DumpSurfaceToFile(m_osInterface, &sourceSurface, m_dumpLocation_in, m_surfaceDumper->m_frameNum, true, false, nullptr);
540 }
541 }
542 #endif
543
544 MosUtilities::MosLockMutex(m_inUseGPUMutex);
545 switch(mcpyEngine)
546 {
547 case MCPY_ENGINE_VEBOX:
548 eStatus = MediaVeboxCopy(mcpySrc.OsRes, mcpyDst.OsRes);
549 break;
550 case MCPY_ENGINE_BLT:
551 if ((mcpyDst.TileMode != MOS_TILE_LINEAR) && (mcpyDst.CompressionMode == MOS_MMC_RC))
552 {
553 MCPY_NORMALMESSAGE("mmc on, mcpyDst.TileMode= %d, mcpyDst.CompressionMode = %d", mcpyDst.TileMode, mcpyDst.CompressionMode);
554 eStatus = m_osInterface->pfnDecompResource(m_osInterface, mcpyDst.OsRes);
555 if (MOS_STATUS_SUCCESS != eStatus)
556 {
557 MosUtilities::MosUnlockMutex(m_inUseGPUMutex);
558 MCPY_CHK_STATUS_RETURN(eStatus);
559 }
560 }
561 eStatus = MediaBltCopy(mcpySrc.OsRes, mcpyDst.OsRes);
562 break;
563 case MCPY_ENGINE_RENDER:
564 eStatus = MediaRenderCopy(mcpySrc.OsRes, mcpyDst.OsRes);
565 break;
566 default:
567 break;
568 }
569 MosUtilities::MosUnlockMutex(m_inUseGPUMutex);
570
571 #if (_DEBUG || _RELEASE_INTERNAL)
572 if (m_bRegReport)
573 {
574 std::string copyEngine = mcpyEngine ?(mcpyEngine == MCPY_ENGINE_BLT?"BLT":"Render"):"VeBox";
575 if (m_bRenderFallbackToBlt)
576 {
577 copyEngine = "Render";
578 }
579 MediaUserSettingSharedPtr userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface);
580 ReportUserSettingForDebug(
581 userSettingPtr,
582 __MEDIA_USER_FEATURE_MCPY_MODE,
583 copyEngine,
584 MediaUserSetting::Group::Device);
585 }
586
587 // Set the dump location like "dumpLocation after MCPY=path_to_dump_folder" in user feature configure file
588 // Otherwise, the surface may not be dumped
589 // Only dump linear surface
590 if (m_surfaceDumper && mcpyDst.TileMode == MOS_TILE_LINEAR)
591 {
592 if ((*m_dumpLocation_out == '\0') || (*m_dumpLocation_out == ' '))
593 {
594 MCPY_NORMALMESSAGE("Invalid dump location set, the surface will not be dumped");
595 }
596 else
597 {
598 m_surfaceDumper->DumpSurfaceToFile(m_osInterface, &targetSurface, m_dumpLocation_out, m_surfaceDumper->m_frameNum, true, false, nullptr);
599 }
600 m_surfaceDumper->m_frameNum++;
601 }
602 #endif
603 MCPY_NORMALMESSAGE("Media Copy works on %s Engine", mcpyEngine ?(mcpyEngine == MCPY_ENGINE_BLT?"BLT":"Render"):"VeBox");
604
605 return eStatus;
606 }
607
608 //!
609 //! \brief aux surface copy.
610 //! \details copy surface.
611 //! \param src
612 //! [in] Pointer to source surface
613 //! \param dst
614 //! [in] Pointer to destination surface
615 //! \return MOS_STATUS
616 //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort.
617 //!
618 MOS_STATUS MediaCopyBaseState::AuxCopy(PMOS_RESOURCE src, PMOS_RESOURCE dst)
619 {
620 // only support form Gen12+, will implement on deriavete class.
621 MCPY_ASSERTMESSAGE("doesn't support");
622 return MOS_STATUS_INVALID_HANDLE;
623 }
624
625 PMOS_INTERFACE MediaCopyBaseState::GetMosInterface()
626 {
627 return m_osInterface;
628 }