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