xref: /aosp_15_r20/external/intel-media-driver/media_driver/agnostic/common/cm/cm_kernel_ex.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2018-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      cm_kernel_ex.h
24 //! \brief     Contains Class CmKernelEx  definitions
25 //!
26 #pragma once
27 
28 #include "cm_kernel_rt.h"
29 #include "cm_group_space.h"
30 
31 class CmSurfaceState;
32 class CmSSH;
33 class CmISHBase;
34 class CmMediaState;
35 namespace CMRT_UMD
36 {
37 class CmThreadSpaceRT;
38 class CmThreadGroupSpace;
39 };
40 class CmKernelEx : public CMRT_UMD::CmKernelRT
41 {
42 public:
CmKernelEx(CMRT_UMD::CmDeviceRT * device,CMRT_UMD::CmProgramRT * program,uint32_t kernelIndex,uint32_t kernelSeqNum)43     CmKernelEx(CMRT_UMD::CmDeviceRT *device,
44                CMRT_UMD::CmProgramRT *program,
45                uint32_t kernelIndex,
46                uint32_t kernelSeqNum):
47         CMRT_UMD::CmKernelRT(device, program, kernelIndex, kernelSeqNum),
48         m_indexMap(nullptr),
49         m_flatArgs(nullptr),
50         m_flatArgCount(0),
51         m_data(nullptr),
52         m_surfaceInArg(nullptr),
53         m_curbe(nullptr),
54         m_explicitCurbeSize(0),
55         m_curbeSize(0),
56         m_curbeSizePerThread(0),
57         m_curbeSizeCrossThread(0),
58         m_propertyIndexes(nullptr),
59         m_cmSurfIndexes(nullptr),
60         m_hashValue(0),
61         m_dummyThreadSpace(nullptr),
62         m_dummyThreadGroupSpace(nullptr),
63         m_ish(nullptr),
64         m_indexInIsh(-1),
65         m_offsetInIsh(0)
66     {
67     }
68 
69     virtual ~CmKernelEx();
70 
71     int32_t SetKernelArg(uint32_t index, size_t size, const void * value);
72 
73     int32_t SetSurfaceBTI(CMRT_UMD::SurfaceIndex *surfIndex, uint32_t bti);
74 
75     int32_t SetSamplerBTI(CMRT_UMD::SamplerIndex* sampler, uint32_t nIndex);
76 
77     int32_t SetStaticBuffer(uint32_t index, const void *value);
78 
GetCurbeSize()79     inline uint32_t GetCurbeSize() {return m_curbeSize; }
80 
GetCurbeSizePerThread()81     inline uint32_t GetCurbeSizePerThread() {return m_curbeSizePerThread; }
82 
GetCurbeSizeCrossThread()83     inline uint32_t GetCurbeSizeCrossThread() {return m_curbeSizeCrossThread; }
84 
GetCurbe()85     inline uint8_t* GetCurbe() {return m_curbe; }
86 
87     uint32_t GetMaxBteNum();
88 
89     MOS_STATUS AllocateCurbe(); // for media walker
90 
91     MOS_STATUS AllocateCurbeAndFillImplicitArgs(CMRT_UMD::CmThreadGroupSpace *globalGroupSpace); // for gpgpu/compute walker
92 
93     MOS_STATUS UpdateCurbe(CmSSH *ssh, CmMediaState *mediaState, uint32_t kernelIdx);
94 
95     MOS_STATUS UpdateSWSBArgs(CMRT_UMD::CmThreadSpaceRT *threadSpace);
96 
97     MOS_STATUS UpdateFastTracker(uint32_t trackerIndex, uint32_t tracker);
98 
99     MOS_STATUS LoadReservedSurfaces(CmSSH *ssh);
100 
101     MOS_STATUS LoadReservedSamplers(CmMediaState *mediaState, uint32_t kernelIdx);
102 
103     MOS_STATUS GetSamplerCount(uint32_t *count3D, uint32_t *countAVS);
104 
105     CMRT_UMD::CmThreadSpaceRT* GetThreadSpaceEx();
106 
107     CMRT_UMD::CmThreadGroupSpace* GetThreadGroupSpaceEx();
108 
109     void SurfaceDumpEx(uint32_t kernelNumber, int32_t taskId);
110 
111     bool IsFastPathSupported();
112 
113     // interfaces with ISH
Recorded(CmISHBase * ish,int index,uint32_t offset)114     inline void Recorded(CmISHBase *ish, int index, uint32_t offset)
115     {
116         m_ish = ish;
117         m_indexInIsh = index;
118         m_offsetInIsh = offset;
119     }
120 
GetRecordedInfo(CmISHBase ** ish,int * index)121     inline void GetRecordedInfo(CmISHBase **ish, int *index)
122     {
123         *ish = m_ish;
124         *index = m_indexInIsh;
125     }
126 
GetOffsetInIsh()127     inline uint32_t GetOffsetInIsh() {return m_offsetInIsh; }
128 
GetNativeKernel(uint8_t ** kernel,uint32_t * size)129     inline void GetNativeKernel(uint8_t **kernel, uint32_t *size)
130     {
131         *kernel = (uint8_t *)m_binary;
132         *size = m_binarySize;
133     }
134 
GetBarrierMode()135     inline uint32_t GetBarrierMode() {return m_barrierMode; }
136 
GetReservedSurfaceBteIndex()137     inline std::map<int, CmSurfaceState *>& GetReservedSurfaceBteIndex() {return m_reservedSurfaceBteIndexes; }
138 
GetReservedSamplerBteIndex()139     inline std::map<int, void *>& GetReservedSamplerBteIndex() {return m_reservedSamplerBteIndexes; }
140 
GetHashValue()141     inline uint64_t GetHashValue() {return m_hashValue; }
142 
143 protected:
144     int32_t Initialize(const char *kernelName, const char *options);
145 
146     bool IsSurface(uint16_t kind);
147 
148     CM_ARG_KIND ToArgKind(CMRT_UMD::CmSurface *surface);
149 
ArgArraySupported(uint16_t kind)150     inline bool ArgArraySupported(uint16_t kind) {return IsSurface(kind) || kind == ARG_KIND_SAMPLER; }
151 
152     CmSurfaceState* GetSurfaceState(CMRT_UMD::CmSurface *surface, uint32_t index);
153 
154     void* GetSamplerParam(uint32_t index);
155 
156     struct _CmArg
157     {
158         uint32_t offset;
159         uint16_t kind;
160         uint16_t isaKind;
161         uint16_t unitSize;
162         uint16_t payloadOffset;
163         uint16_t sizeInCurbe;
164         bool isSet;
165     };
166 
167     uint32_t *m_indexMap;
168     _CmArg *m_flatArgs;
169     uint32_t m_flatArgCount;
170     uint8_t *m_data;
171     uint8_t *m_surfaceInArg;
172 
173     uint8_t *m_curbe;
174     uint32_t m_explicitCurbeSize;
175     uint32_t m_curbeSize;
176     uint32_t m_curbeSizePerThread;
177     uint32_t m_curbeSizeCrossThread;
178 
179     uint8_t *m_propertyIndexes;
180     uint32_t *m_cmSurfIndexes;
181 
182     uint64_t m_hashValue;
183 
184     // reserved an internal space for setThreadCount
185     CMRT_UMD::CmThreadSpace *m_dummyThreadSpace;
186     CMRT_UMD::CmThreadGroupSpace *m_dummyThreadGroupSpace;
187 
188     //recorded info in ish
189     CmISHBase *m_ish;
190     int m_indexInIsh;
191     uint32_t m_offsetInIsh;
192 
193     // reserved surface bte index
194     std::map<int, CmSurfaceState *>m_reservedSurfaceBteIndexes;
195 
196     // reserved sampler bte index
197     std::map<int, void *>m_reservedSamplerBteIndexes;
198 };
199