1 /*
2 * Copyright (c) 2019, 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 vp_status_report.cpp
24 //! \brief Defines the interface for vp status report
25 //! \details vp status will allocate and destory buffers, the caller
26 //! can use directly
27 //!
28
29 #include <stdint.h>
30 #include "vp_status_report.h"
31 #include "mos_utilities.h"
32 #include "vp_common.h"
33 #include "vp_utils.h"
34
35 namespace vp
36 {
VPStatusReport(PMOS_INTERFACE pOsInterface)37 VPStatusReport::VPStatusReport(PMOS_INTERFACE pOsInterface) :
38 m_osInterface(pOsInterface)
39 {
40 MOS_ZeroMemory(&m_StatusTableUpdateParams, sizeof(m_StatusTableUpdateParams));
41 }
42
SetPipeStatusReportParams(PVP_PIPELINE_PARAMS pVpParams,PVPHAL_STATUS_TABLE pStatusTable)43 void VPStatusReport::SetPipeStatusReportParams(PVP_PIPELINE_PARAMS pVpParams, PVPHAL_STATUS_TABLE pStatusTable)
44 {
45 bool bSurfIsRenderTarget = (pVpParams->pTarget[0]->SurfType == SURF_OUT_RENDERTARGET);
46 m_StatusTableUpdateParams.bReportStatus = (pVpParams->bReportStatus);
47 m_StatusTableUpdateParams.bSurfIsRenderTarget = bSurfIsRenderTarget;
48 m_StatusTableUpdateParams.pStatusTable = pStatusTable;
49 m_StatusTableUpdateParams.StatusFeedBackID = pVpParams->StatusFeedBackID;
50 }
51
UpdateStatusTableAfterSubmit(MOS_STATUS eLastStatus)52 MOS_STATUS VPStatusReport::UpdateStatusTableAfterSubmit(
53 MOS_STATUS eLastStatus)
54 {
55 PVPHAL_STATUS_ENTRY pStatusEntry;
56 bool bEmptyTable;
57 MOS_STATUS eStatus;
58 uint32_t dwLastTag;
59 PVPHAL_STATUS_TABLE pStatusTable;
60 uint32_t dwStatusFeedBackID;
61
62 eStatus = MOS_STATUS_SUCCESS;
63
64 MOS_GPU_CONTEXT eMosGpuContext = m_osInterface->pfnGetGpuContext(m_osInterface);
65
66 if (!m_StatusTableUpdateParams.bReportStatus ||
67 !m_StatusTableUpdateParams.bSurfIsRenderTarget)
68 {
69 goto finish;
70 }
71
72 VP_PUBLIC_CHK_NULL(m_StatusTableUpdateParams.pStatusTable);
73 VP_PUBLIC_CHK_NULL(m_osInterface);
74
75 pStatusTable = m_StatusTableUpdateParams.pStatusTable;
76 dwStatusFeedBackID = m_StatusTableUpdateParams.StatusFeedBackID;
77
78 VP_PUBLIC_ASSERT(pStatusTable->uiHead < VPHAL_STATUS_TABLE_MAX_SIZE);
79 VP_PUBLIC_ASSERT(pStatusTable->uiCurrent < VPHAL_STATUS_TABLE_MAX_SIZE);
80
81 bEmptyTable = (pStatusTable->uiCurrent == pStatusTable->uiHead);
82 if (!bEmptyTable)
83 {
84 uint32_t uiLast = (pStatusTable->uiCurrent - 1) & (VPHAL_STATUS_TABLE_MAX_SIZE - 1);
85 bool bSameFrameIdWithLastRender = (pStatusTable->aTableEntries[uiLast].StatusFeedBackID == dwStatusFeedBackID);
86 if (bSameFrameIdWithLastRender)
87 {
88 pStatusTable->uiCurrent = uiLast;
89 }
90 }
91
92 pStatusEntry = &pStatusTable->aTableEntries[pStatusTable->uiCurrent];
93 pStatusEntry->StatusFeedBackID = dwStatusFeedBackID;
94 pStatusEntry->GpuContextOrdinal = eMosGpuContext;
95 dwLastTag = m_osInterface->pfnGetGpuStatusTag(m_osInterface, eMosGpuContext) - 1;
96 pStatusEntry->dwTag = dwLastTag;
97 pStatusEntry->dwStatus = (eLastStatus == MOS_STATUS_SUCCESS)? VPREP_NOTREADY : VPREP_ERROR;
98 pStatusTable->uiCurrent = (pStatusTable->uiCurrent + 1) & (VPHAL_STATUS_TABLE_MAX_SIZE - 1);
99 if (pStatusTable->uiCurrent == pStatusTable->uiHead)
100 {
101 pStatusTable->uiHead = (pStatusTable->uiHead + 1) & (VPHAL_STATUS_TABLE_MAX_SIZE - 1);
102 }
103
104 finish:
105 return eStatus;
106 }
107 } // namespace vp
108