1 /*
2 * Copyright (c) 2021-2022, 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_render_cmd_packet.h
24 //! \brief    Defines the interface for media render workload cmd packet
25 //! \details  The media cmd packet is dedicated for command buffer sequenece submit
26 //!
27 #ifndef __MEDIA_RENDER_CMD_PACKET_H__
28 #define __MEDIA_RENDER_CMD_PACKET_H__
29 
30 #include <stdint.h>
31 #include <set>
32 #include "hal_kerneldll_next.h"
33 #include "media_cmd_packet.h"
34 #include "renderhal.h"
35 
36 class MediaFeatureManager;
37 class MediaTask;
38 class MhwCpInterface;
39 
40 #define RENDER_PACKET_CHK_NULL_RETURN(_ptr) \
41     MOS_CHK_NULL_RETURN(MOS_COMPONENT_HW, 0, _ptr)
42 
43 #define RENDER_PACKET_CHK_STATUS_RETURN(_stmt) \
44     MOS_CHK_STATUS_RETURN(MOS_COMPONENT_HW, 0, _stmt)
45 
46 #define RENDER_PACKET_CHK_STATUS_MESSAGE_RETURN(_stmt, _message, ...) \
47     MOS_CHK_STATUS_MESSAGE_RETURN(MOS_COMPONENT_HW, 0, _stmt, _message, ##__VA_ARGS__)
48 
49 #define RENDER_PACKET_ASSERTMESSAGE(_message, ...) \
50     MOS_ASSERTMESSAGE(MOS_COMPONENT_HW, 0, _message, ##__VA_ARGS__)
51 
52 #define RENDER_PACKET_NORMALMESSAGE(_message, ...) \
53     MOS_NORMALMESSAGE(MOS_COMPONENT_HW, 0, _message, ##__VA_ARGS__)
54 
55 #define RENDER_PACKET_VERBOSEMESSAGE(_message, ...) \
56     MOS_VERBOSEMESSAGE(MOS_COMPONENT_HW, 0, _message, ##__VA_ARGS__)
57 
58 #define RENDER_PACKET_ASSERT(_expr) \
59     MOS_ASSERT(MOS_COMPONENT_HW, 0, _expr)
60 
61 #define RENDER_PACKET_CHK_NULL_WITH_DESTROY_RETURN_VALUE(_ptr, destroyFunction) \
62     MOS_CHK_COND_WITH_DESTROY_RETURN_VALUE(MOS_COMPONENT_HW, 0, (nullptr == _ptr), destroyFunction, MOS_STATUS_NULL_POINTER, "error nullptr!")
63 
64 #define RENDER_PACKET_CHK_STATUS_WITH_DESTROY_RETURN_VALUE(_stmt, destroyFunction)                                                  \
65 {                                                                                                                                   \
66     MOS_STATUS sts = (MOS_STATUS)(_stmt);                                                                                           \
67     MOS_CHK_COND_WITH_DESTROY_RETURN_VALUE(MOS_COMPONENT_HW, 0, (MOS_STATUS_SUCCESS != sts), destroyFunction, sts, "error status!") \
68 }
69 
70 //!
71 //! \brief Initialize MHW Kernel Param struct for loading Kernel
72 //!
73 #define INIT_MHW_KERNEL_PARAM(MhwKernelParam, _pKernelEntry)                        \
74     do                                                                              \
75     {                                                                               \
76         MOS_ZeroMemory(&(MhwKernelParam), sizeof(MhwKernelParam));                  \
77         (MhwKernelParam).pBinary  = (_pKernelEntry)->pBinary;                       \
78         (MhwKernelParam).iSize    = (_pKernelEntry)->iSize;                         \
79         (MhwKernelParam).iKUID    = (_pKernelEntry)->iKUID;                         \
80         (MhwKernelParam).iKCID    = (_pKernelEntry)->iKCID;                         \
81     } while(0)
82 
83 typedef struct _PIPECONTRL_PARAMS
84 {
85     bool bUpdateNeeded;
86     bool bEnableDataPortFlush;
87     bool bUnTypedDataPortCacheFlush;
88     bool bFlushRenderTargetCache;
89     bool bInvalidateTextureCache;
90 } PIPECONTRL_PARAMS, *PPIPECONTRL_PARAMS;
91 
92 typedef struct _KERNEL_WALKER_PARAMS
93 {
94     int32_t                             iBindingTable;
95     int32_t                             iMediaID;
96     int32_t                             iCurbeOffset;
97     int32_t                             iCurbeLength;
98 
99     int32_t                             iBlocksX;
100     int32_t                             iBlocksY;
101     RECT                                alignedRect;
102     PIPECONTRL_PARAMS                   pipeControlParams;
103     bool                                isVerticalPattern;
104     bool                                bSyncFlag;
105     bool                                bFlushL1;
106     bool                                isGroupStartInvolvedInGroupSize;    // true if group start need be involved in the group size.
107     bool                                calculateBlockXYByAlignedRect;      // true if iBlocksX/iBlocksY is calculated by alignedRect in RenderCmdPacket instead of kernel object.
108     bool                                forcePreferredSLMZero;              // true if preferredSLM need force to 0.
109 
110     bool                                isEmitInlineParameter;
111     uint32_t                            inlineDataLength;
112     uint8_t*                            inlineData;
113 
114     uint32_t                            threadWidth;
115     uint32_t                            threadHeight;
116     uint32_t                            threadDepth;
117 
118     bool                                isGenerateLocalID;
119     MHW_EMIT_LOCAL_MODE                 emitLocal;
120 
121     bool                                hasBarrier;
122     uint32_t                            slmSize;
123     PMHW_INLINE_DATA_PARAMS             inlineDataParamBase;
124     uint32_t                            inlineDataParamSize;
125 }KERNEL_WALKER_PARAMS, * PKERNEL_WALKER_PARAMS;
126 
127 typedef struct _KERNEL_PACKET_RENDER_DATA
128 {
129     // Kernel Information
130     RENDERHAL_KERNEL_PARAM              KernelParam;
131     Kdll_CacheEntry                     KernelEntry;
132     int32_t                             iCurbeLength;
133     int32_t                             iInlineLength;
134     int32_t                             iCurbeOffset;
135 
136     MHW_SAMPLER_STATE_PARAM             SamplerStateParams;           //!< Sampler State
137     PMHW_AVS_PARAMS                     pAVSParameters;               //!< AVS parameters
138     MHW_SAMPLER_AVS_TABLE_PARAM         mhwSamplerAvsTableParam;      //!< params for AVS scaling 8x8 table
139 
140     // Media render state
141     PRENDERHAL_MEDIA_STATE              mediaState;
142 
143     int32_t                             bindingTable;
144     uint32_t                            bindingTableEntry;
145     int32_t                             mediaID;
146 
147     KERNEL_WALKER_PARAMS                walkerParam;
148     PMHW_VFE_SCOREBOARD                 scoreboardParams;
149 
150     int32_t                             kernelAllocationID;
151 
152     // Debug parameters
153     // Kernel Used for current rendering
154     char* pKernelName;
155 } KERNEL_PACKET_RENDER_DATA, * PKERNEL_PACKET_RENDER_DATA;
156 
157 typedef enum _WALKER_TYPE
158 {
159     WALKER_TYPE_DISABLED = 0,
160     WALKER_TYPE_MEDIA,
161     WALKER_TYPE_COMPUTE
162 }WALKER_TYPE;
163 
164 //!
165 //! \brief VPHAL SS/EU setting
166 //!
167 struct SseuSetting
168 {
169     uint8_t   numSlices;
170     uint8_t   numSubSlices;
171     uint8_t   numEUs;
172     uint8_t   reserved;       // Place holder for frequency setting
173 };
174 
175 typedef struct _RENDERHAL_SURFACE_NEXT : public _RENDERHAL_SURFACE
176 {
177     uint32_t Index;
178 }RENDERHAL_SURFACE_NEXT, * PRENDERHAL_SURFACE_NEXT;
179 
180 class RenderCmdPacket : virtual public CmdPacket, public mhw::mi::Itf::ParSetting
181 {
182 public:
183     RenderCmdPacket(MediaTask* task, PMOS_INTERFACE pOsInterface, RENDERHAL_INTERFACE* m_renderHal);
184 
185     virtual ~RenderCmdPacket();
186     virtual MOS_STATUS Init();
187     virtual MOS_STATUS Destroy();
188     virtual MOS_STATUS Submit(MOS_COMMAND_BUFFER* commandBuffer, uint8_t packetPhase = otherPacket);
189 
190     // Currently only support HDC read/write, for sampler enabling will be in next step
191     // Step1 : render engine set up
192     MOS_STATUS RenderEngineSetup();
193 
194     // Step2: Kernel State Set up
KernelStateSetup(void * kernel)195     virtual MOS_STATUS KernelStateSetup(
196         void *kernel)
197     {
198         return MOS_STATUS_SUCCESS;
199     }
200 
201     virtual uint32_t SetSurfaceForHwAccess(
202         PMOS_SURFACE                    surface,
203         PRENDERHAL_SURFACE_NEXT         pRenderSurface,
204         PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
205         bool                            bWrite,
206         std::set<uint32_t>             &stateOffsets);
207 
208     // Step3: RSS Setup, return index insert in binding table
209     virtual uint32_t SetSurfaceForHwAccess(
210         PMOS_SURFACE                    surface,
211         PRENDERHAL_SURFACE_NEXT         pRenderSurface,
212         PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
213         bool                            bWrite);
214 
215     // Step3: RSS Setup with fixed binding index, return index insert in binding table
216     virtual MOS_STATUS SetSurfaceForHwAccess(
217         PMOS_SURFACE                    surface,
218         PRENDERHAL_SURFACE_NEXT         pRenderSurface,
219         PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
220         uint32_t                        &bindingIndex,
221         bool                            bWrite,
222         PRENDERHAL_SURFACE_STATE_ENTRY *surfaceEntries      = nullptr,
223         uint32_t *                      numOfSurfaceEntries = nullptr);
224 
225     virtual MOS_STATUS SetSurfaceForHwAccess(
226         PMOS_SURFACE                    surface,
227         PRENDERHAL_SURFACE_NEXT         pRenderSurface,
228         PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
229         std::set<uint32_t>             &bindingIndexes,
230         bool                            bWrite,
231         std::set<uint32_t>             &stateOffsets,
232         uint32_t                        capcityOfSurfaceEntries = 0,
233         PRENDERHAL_SURFACE_STATE_ENTRY *surfaceEntries      = nullptr,
234         uint32_t                       *numOfSurfaceEntries = nullptr);
235 
236     virtual uint32_t SetBufferForHwAccess(
237         PMOS_SURFACE                    buffer,
238         PRENDERHAL_SURFACE_NEXT         pRenderSurface,
239         PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
240         bool                            bWrite,
241         std::set<uint32_t>             &stateOffsets);
242 
243     virtual uint32_t SetBufferForHwAccess(
244         PMOS_SURFACE                    buffer,
245         PRENDERHAL_SURFACE_NEXT         pRenderSurface,
246         PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
247         uint32_t                        bindingIndex,
248         bool                            bWrite);
249 
250     virtual MOS_STATUS SetBufferForHwAccess(
251         PMOS_SURFACE                    buffer,
252         PRENDERHAL_SURFACE_NEXT         pRenderSurface,
253         PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
254         std::set<uint32_t>             &bindingIndexes,
255         bool                            bWrite,
256         std::set<uint32_t>             &stateOffsets);
257 
258     virtual uint32_t SetBufferForHwAccess(
259         MOS_BUFFER                      buffer,
260         PRENDERHAL_SURFACE_NEXT         pRenderSurface,
261         PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams,
262         bool                            bWrite);
263 
264     // Step4: Packet to prepare the curbe data Setup, then call packet to set it up
265     // PData point to the Curbe prepared by packet
266     MOS_STATUS SetupCurbe(
267         void *   pData,
268         uint32_t curbeLength,
269         uint32_t maximumNumberofThreads = 0);
270 
271     // Step6: different kernel have different media walker settings
SetupMediaWalker()272     virtual MOS_STATUS SetupMediaWalker()
273     {
274         return MOS_STATUS_SUCCESS;
275     }
276 
277     MOS_STATUS PrepareMediaWalkerParams(KERNEL_WALKER_PARAMS params, MHW_WALKER_PARAMS &mediaWalker);
278 
279     MOS_STATUS PrepareComputeWalkerParams(KERNEL_WALKER_PARAMS params, MHW_GPGPU_WALKER_PARAMS &gpgpuWalker);
280 
281     bool m_isMultiBindingTables = false;
282 
283     bool m_isLargeSurfaceStateNeeded = false;
284 
285     bool m_isMultiKernelOneMediaState = false;
286 
287 #if (_DEBUG || _RELEASE_INTERNAL)
StallBatchBuffer(PMOS_COMMAND_BUFFER cmdBuffer)288     virtual MOS_STATUS StallBatchBuffer(
289         PMOS_COMMAND_BUFFER cmdBuffer)
290     {
291         return MOS_STATUS_SUCCESS;
292     }
293 #endif
294 
295 protected:
296     // Step5: Load Kernel
297     virtual MOS_STATUS LoadKernel();
298 
299     // for VPP usage, there are more data need to updated, create as virtual for future inplemention in VPP
300     virtual MOS_STATUS InitRenderHalSurface(
301         MOS_SURFACE        surface,
302         PRENDERHAL_SURFACE pRenderSurface);
303 
304     virtual MOS_STATUS InitRenderHalBuffer(
305         MOS_BUFFER         surface,
306         PRENDERHAL_SURFACE pRenderSurface);
307 
OcaDumpDbgInfo(MOS_COMMAND_BUFFER & cmdBuffer,MOS_CONTEXT & mosContext)308     virtual void OcaDumpDbgInfo(MOS_COMMAND_BUFFER &cmdBuffer, MOS_CONTEXT &mosContext)
309     {
310     }
311 
SetMediaFrameTracking(RENDERHAL_GENERIC_PROLOG_PARAMS & genericPrologParams)312     virtual MOS_STATUS SetMediaFrameTracking(RENDERHAL_GENERIC_PROLOG_PARAMS &genericPrologParams)
313     {
314         return MOS_STATUS_SUCCESS;
315     }
316 
317     MOS_STATUS InitKernelEntry();
318 
319     MOS_STATUS SetPowerMode(
320         uint32_t KernelID);
321 
IsMiBBEndNeeded(PMOS_INTERFACE pOsInterface)322     bool IsMiBBEndNeeded(
323         PMOS_INTERFACE pOsInterface)
324     {
325         // need to be remodify
326         bool needed = true;
327 
328         return needed;
329     }
330 
ResetBindingTableEntry()331     void ResetBindingTableEntry()
332     {
333         m_renderData.bindingTableEntry = 0;
334     }
335 
336     virtual void UpdateKernelConfigParam(RENDERHAL_KERNEL_PARAM &kernelParam);
337 
338 protected:
339     PRENDERHAL_INTERFACE        m_renderHal = nullptr;
340     MhwCpInterface*             m_cpInterface = nullptr;
341     MediaFeatureManager*        m_featureManager = nullptr;
342 
343     // Perf
344     VPHAL_PERFTAG               PerfTag = VPHAL_NONE; // need to check the perf setting in codec
345 
346     // Kernel Render Data
347     uint32_t                     m_kernelCount = 0;
348 
349     // Kernel Render Data
350     KERNEL_PACKET_RENDER_DATA   m_renderData = {};
351 
352     // object walker: media walker/compute walker
353     WALKER_TYPE                 m_walkerType = WALKER_TYPE_DISABLED;
354 
355     MHW_WALKER_PARAMS       m_mediaWalkerParams = {};
356 
357     MHW_GPGPU_WALKER_PARAMS m_gpgpuWalkerParams = {};
358 
359     PMHW_BATCH_BUFFER       pBatchBuffer = nullptr;
360 
361     MHW_PIPE_CONTROL_PARAMS m_pipeCtlParams = {};
362 
363     MHW_MEDIA_STATE_FLUSH_PARAM m_flushParam = {};
364     uint32_t                m_flushMode = 0;
365     PMOS_RESOURCE           m_presDest = nullptr;
366     uint32_t                m_postSyncOp = 0;
367     uint32_t                m_resourceOffset = 0;
368     uint32_t                m_dataDW1 = 0;
369     uint32_t                m_dataDW2 = 0;
370     uint32_t                m_genericMediaStateClear : 1;
371     uint32_t                m_IndirectStatePointersDisable : 1;
372     uint32_t                m_disableCSStall : 1;
373     uint32_t                m_bInvalidateTextureCache : 1;
374     uint32_t                m_bFlushRenderTargetCache : 1;
375     uint32_t                m_bInvalidateStateCache : 1;
376     uint32_t                m_bInvalidateConstantCache : 1;
377     uint32_t                m_bInvalidateVFECache : 1;
378     uint32_t                m_bInvalidateInstructionCache : 1;
379     uint32_t                m_bTlbInvalidate : 1;
380     uint32_t                m_bHdcPipelineFlush : 1;
381     uint32_t                m_bKernelFenceEnabled : 1;
382     bool                    m_bFlushToGo = true;
383     uint8_t                 m_ui8InterfaceDescriptorOffset = 0;
384 MEDIA_CLASS_DEFINE_END(RenderCmdPacket)
385 };
386 #endif // __MEDIA_RENDER_CMD_PACKET_H__
387