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     decode_predication_packet.cpp
24 //! \brief    Defines the interface for decode predication sub packet
25 //!
26 #include "decode_predication_packet.h"
27 #include "decode_common_feature_defs.h"
28 
29 namespace decode
30 {
31 
DecodePredicationPkt(DecodePipeline * pipeline,CodechalHwInterface * hwInterface)32 DecodePredicationPkt::DecodePredicationPkt(DecodePipeline *pipeline, CodechalHwInterface *hwInterface)
33     : DecodeSubPacket(pipeline, hwInterface)
34 {}
35 
Init()36 MOS_STATUS DecodePredicationPkt::Init()
37 {
38     DECODE_CHK_NULL(m_pipeline);
39     DECODE_CHK_NULL(m_hwInterface);
40 
41     m_miInterface = m_hwInterface->GetMiInterface();
42     DECODE_CHK_NULL(m_miInterface);
43 
44     MediaFeatureManager *featureManager = m_pipeline->GetFeatureManager();
45     DECODE_CHK_NULL(featureManager);
46 
47     m_predication = dynamic_cast<DecodePredication*>(
48                     featureManager->GetFeature(DecodeFeatureIDs::decodePredication));
49     DECODE_CHK_NULL(m_predication);
50 
51     return MOS_STATUS_SUCCESS;
52 }
53 
Prepare()54 MOS_STATUS DecodePredicationPkt::Prepare()
55 {
56     return MOS_STATUS_SUCCESS;
57 }
58 
Execute(MOS_COMMAND_BUFFER & cmdBuffer)59 MOS_STATUS DecodePredicationPkt::Execute(MOS_COMMAND_BUFFER& cmdBuffer)
60 {
61     if (!m_predication->m_predicationEnabled)
62     {
63         return MOS_STATUS_SUCCESS;
64     }
65 
66     MHW_MI_CONDITIONAL_BATCH_BUFFER_END_PARAMS  condBBEndParams;
67     MOS_ZeroMemory(&condBBEndParams, sizeof(condBBEndParams));
68 
69     // Skip current frame if presPredication is not equal to zero
70     if (m_predication->m_predicationNotEqualZero)
71     {
72         auto mmioRegistersMfx = m_hwInterface->SelectVdboxAndGetMmioRegister(MHW_VDBOX_NODE_1, &cmdBuffer);
73         MHW_MI_FLUSH_DW_PARAMS  flushDwParams;
74         MOS_ZeroMemory(&flushDwParams, sizeof(flushDwParams));
75         DECODE_CHK_STATUS(m_miInterface->AddMiFlushDwCmd(&cmdBuffer, &flushDwParams));
76 
77         // load presPredication to general purpose register0
78         MHW_MI_STORE_REGISTER_MEM_PARAMS    loadRegisterMemParams;
79         MOS_ZeroMemory(&loadRegisterMemParams, sizeof(loadRegisterMemParams));
80         loadRegisterMemParams.presStoreBuffer = &m_predication->m_resPredication->OsResource;
81         loadRegisterMemParams.dwOffset = (uint32_t)m_predication->m_predicationResOffset;
82         loadRegisterMemParams.dwRegister = mmioRegistersMfx->generalPurposeRegister0LoOffset;
83         DECODE_CHK_STATUS(m_miInterface->AddMiLoadRegisterMemCmd(
84             &cmdBuffer,
85             &loadRegisterMemParams));
86         MHW_MI_LOAD_REGISTER_IMM_PARAMS     loadRegisterImmParams;
87         MOS_ZeroMemory(&loadRegisterImmParams, sizeof(loadRegisterImmParams));
88         loadRegisterImmParams.dwData = 0;
89         loadRegisterImmParams.dwRegister = mmioRegistersMfx->generalPurposeRegister0HiOffset;
90         DECODE_CHK_STATUS(m_miInterface->AddMiLoadRegisterImmCmd(
91             &cmdBuffer,
92             &loadRegisterImmParams));
93 
94         // load 0 to general purpose register4
95         MOS_ZeroMemory(&loadRegisterImmParams, sizeof(loadRegisterImmParams));
96         loadRegisterImmParams.dwData = 0;
97         loadRegisterImmParams.dwRegister = mmioRegistersMfx->generalPurposeRegister4LoOffset;
98         DECODE_CHK_STATUS(m_miInterface->AddMiLoadRegisterImmCmd(
99             &cmdBuffer,
100             &loadRegisterImmParams));
101         MOS_ZeroMemory(&loadRegisterImmParams, sizeof(loadRegisterImmParams));
102         loadRegisterImmParams.dwData = 0;
103         loadRegisterImmParams.dwRegister = mmioRegistersMfx->generalPurposeRegister4HiOffset;
104         DECODE_CHK_STATUS(m_miInterface->AddMiLoadRegisterImmCmd(
105             &cmdBuffer,
106             &loadRegisterImmParams));
107 
108         //perform the add operation
109         MHW_MI_MATH_PARAMS  miMathParams;
110         MHW_MI_ALU_PARAMS   miAluParams[4];
111         MOS_ZeroMemory(&miMathParams, sizeof(miMathParams));
112         MOS_ZeroMemory(&miAluParams, sizeof(miAluParams));
113         // load     srcA, reg0
114         miAluParams[0].AluOpcode = MHW_MI_ALU_LOAD;
115         miAluParams[0].Operand1 = MHW_MI_ALU_SRCA;
116         miAluParams[0].Operand2 = MHW_MI_ALU_GPREG0;
117         // load     srcB, reg4
118         miAluParams[1].AluOpcode = MHW_MI_ALU_LOAD;
119         miAluParams[1].Operand1 = MHW_MI_ALU_SRCB;
120         miAluParams[1].Operand2 = MHW_MI_ALU_GPREG4;
121         // add      srcA, srcB
122         miAluParams[2].AluOpcode = MHW_MI_ALU_ADD;
123         miAluParams[2].Operand1 = MHW_MI_ALU_SRCB;
124         miAluParams[2].Operand2 = MHW_MI_ALU_GPREG4;
125         // store      reg0, ZF
126         miAluParams[3].AluOpcode = MHW_MI_ALU_STORE;
127         miAluParams[3].Operand1 = MHW_MI_ALU_GPREG0;
128         miAluParams[3].Operand2 = MHW_MI_ALU_ZF;
129         miMathParams.pAluPayload = miAluParams;
130         miMathParams.dwNumAluParams = 4; // four ALU commands needed for this substract opertaion. see following ALU commands.
131         DECODE_CHK_STATUS(m_miInterface->AddMiMathCmd(
132             &cmdBuffer,
133             &miMathParams));
134 
135         // if zero, the zero flag will be 0xFFFFFFFF, else zero flag will be 0x0.
136         MHW_MI_STORE_REGISTER_MEM_PARAMS    storeRegParams;
137         MOS_ZeroMemory(&storeRegParams, sizeof(storeRegParams));
138         storeRegParams.presStoreBuffer = &m_predication->m_predicationBuffer->OsResource;
139         storeRegParams.dwOffset = 0;
140         storeRegParams.dwRegister = mmioRegistersMfx->generalPurposeRegister0LoOffset;
141         DECODE_CHK_STATUS(m_miInterface->AddMiStoreRegisterMemCmd(
142             &cmdBuffer,
143             &storeRegParams));
144 
145         condBBEndParams.presSemaphoreBuffer = &m_predication->m_predicationBuffer->OsResource;
146         condBBEndParams.dwOffset = 0;
147         condBBEndParams.dwValue = 0;
148         condBBEndParams.bDisableCompareMask = true;
149         DECODE_CHK_STATUS(m_miInterface->AddMiConditionalBatchBufferEndCmd(
150             &cmdBuffer,
151             &condBBEndParams));
152     }
153     else
154     {
155         // Skip current frame if presPredication is equal to zero
156         condBBEndParams.presSemaphoreBuffer = &m_predication->m_resPredication->OsResource;
157         condBBEndParams.dwOffset = (uint32_t)m_predication->m_predicationResOffset;
158         condBBEndParams.bDisableCompareMask = true;
159         condBBEndParams.dwValue = 0;
160         DECODE_CHK_STATUS(m_miInterface->AddMiConditionalBatchBufferEndCmd(
161             &cmdBuffer,
162             &condBBEndParams));
163     }
164 
165     return MOS_STATUS_SUCCESS;
166 }
167 
CalculateCommandSize(uint32_t & commandBufferSize,uint32_t & requestedPatchListSize)168 MOS_STATUS DecodePredicationPkt::CalculateCommandSize(uint32_t &commandBufferSize, uint32_t &requestedPatchListSize)
169 {
170     commandBufferSize = 0;
171     requestedPatchListSize = 0;
172     return MOS_STATUS_SUCCESS;
173 }
174 
175 }
176