xref: /aosp_15_r20/external/intel-media-driver/media_softlet/agnostic/common/os/mos_gpucontext_next.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2019-2021, 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    mos_gpucontext_next.h
24 //! \brief   Container class for the basic gpu context
25 //!
26 
27 #ifndef __MOS_GPU_CONTEXT_NEXT_H__
28 #define __MOS_GPU_CONTEXT_NEXT_H__
29 
30 #include "mos_os.h"
31 
32 class CmdBufMgrNext;
33 class CommandBufferNext;
34 class CommandBufferSpecificNext;
35 class GraphicsResourceNext;
36 
37 //!
38 //! \class  GpuContext
39 //!
40 class GpuContextNext
41 {
42 public:
43     //!
44     //! \brief  Constructor
45     //!
GpuContextNext()46     GpuContextNext(){}
47 
48     //!
49     //! \brief  Destructor
50     //!
~GpuContextNext()51     virtual ~GpuContextNext(){}
52 
53     //!
54     //! \brief    Clear gpu context
55     //!
56     virtual void Clear() = 0;
57 
58     //!
59     //! \brief    Verify command buffer size
60     //! \details  Verifys the buffer to be used for rendering GPU commands is large enough
61     //! \param    [in] requestedSize
62     //!           Buffer size requested
63     //! \return   MOS_STATUS
64     //!           Return MOS_STATUS_SUCCESS if successful (command buffer will be large enough)
65     //!           otherwise failed reason
66     //!
67     virtual MOS_STATUS VerifyCommandBufferSize(
68         const uint32_t requestedSize) = 0;
69 
70     //!
71     //! \brief    Get indirect state size
72     //! \details  Retrieves indirect state to be used for rendering purposes
73     //! \param    [out] offset
74     //!           Reference to indirect buffer offset
75     //! \param    [out] size
76     //!           Reference to indirect buffer size
77     //! \return   MOS_STATUS
78     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
79     //!
80     virtual MOS_STATUS GetIndirectState(
81         uint32_t &offset,
82         uint32_t &size) = 0;
83 
84     //!
85     //! \brief    Get Indirect State Pointer
86     //! \param    [out] indirectState
87     //!           Pointer to Indirect State Buffer
88     //! \return   MOS_STATUS
89     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
90     //!
91     virtual MOS_STATUS GetIndirectStatePointer(
92         uint8_t **indirectState) = 0;
93 
94     //!
95     //! \brief    Get command buffer
96     //! \details  Retrieves buffer to be used for rendering GPU commands
97     //! \param    [in/out] cmdBuffer
98     //!           Pointer to Command Buffer control structure
99     //! \param    [in] flags
100     //!           Flags to indicate command buffer property
101     //! \return   MOS_STATUS
102     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
103     //!
104     virtual MOS_STATUS GetCommandBuffer(
105         PMOS_COMMAND_BUFFER cmdBuffer,
106         uint32_t            flags) = 0;
107 
108     //!
109     //! \brief    Return command buffer space
110     //! \details  Return unused command buffer space
111     //! \param    [in/out] cmdBuffer
112     //!           Pointer to Command Buffer control structure
113     //! \param    [in] flags
114     //!           Flags to indicate command buffer property
115     //!
116     virtual void ReturnCommandBuffer(
117         PMOS_COMMAND_BUFFER cmdBuffer,
118         uint32_t            flags) = 0;
119 
120     //!
121     //! \brief    Submit command buffer
122     //! \details  Submit the command buffer
123     //! \param    [in] streamState
124     //!           OS stream state
125     //! \param    [in] cmdBuffer
126     //!           Pointer to Command Buffer control structure
127     //! \param    [in] nullRendering
128     //!           boolean null rendering
129     //! \return   MOS_STATUS
130     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
131     //!
132     virtual MOS_STATUS SubmitCommandBuffer(
133         MOS_STREAM_HANDLE   streamState,
134         PMOS_COMMAND_BUFFER cmdBuffer,
135         bool                nullRendering) = 0;
136 
137     //!
138     //! \brief    Resizes the buffer to be used for rendering GPU commands
139     //! \param    [in] requestedCommandBufferSize
140     //!           requested command buffer size
141     //! \param    [in] requestedPatchListSize
142     //!           requested patch list size
143     //! \param    [in] flags
144     //!           Flags to indicate command buffer property
145     //! \return   MOS_STATUS
146     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
147     //!
148     virtual MOS_STATUS ResizeCommandBufferAndPatchList(
149         uint32_t requestedCommandBufferSize,
150         uint32_t requestedPatchListSize,
151         uint32_t flags) = 0;
152 
153     //!
154     //! \brief    Resets Gpu context States
155     //! \details  Resets all status in current gpu status
156     //!
157     virtual void ResetGpuContextStatus() = 0;
158 
159     //!
160     //! \brief    Get Gpu context handle
161     //! \details  return the index in gpucontextNext mgr pool for current gpu context
162     //!
GetGpuContextHandle()163     GPU_CONTEXT_HANDLE GetGpuContextHandle() { return m_gpuContextHandle; }
164 
165     //!
166     //! \brief    Set Gpu context handle
167     //! \details  Register the index in gpucontextNext mgr pool for current gpu context
168     //!
SetGpuContextHandle(GPU_CONTEXT_HANDLE gpuContextHandle)169     void SetGpuContextHandle(GPU_CONTEXT_HANDLE gpuContextHandle)
170     {
171         m_gpuContextHandle = gpuContextHandle;
172     }
173 
174     //!
175     //! \brief    Set Gpu context
176     //! \details  Set MOS Gpu context
177     //!
SetGpuContext(MOS_GPU_CONTEXT gpuContext)178     void SetGpuContext(MOS_GPU_CONTEXT gpuContext)
179     {
180         m_gpuContext = gpuContext;
181     }
182 
183     //!
184     //! \brief    Get Gpu context Node
185     //! \details  Return the hardware node for current gpu context
186     //!
GetContextNode()187     MOS_GPU_NODE GetContextNode() { return m_nodeOrdinal; }
188 
189     //!
190     //! \brief    Set Gpu context Node
191     //! \details  Set the hardware node for current gpu context
192     //!
SetContextNode(MOS_GPU_NODE nodeOrdinal)193     void SetContextNode(MOS_GPU_NODE nodeOrdinal) { m_nodeOrdinal = nodeOrdinal; }
194 
195     //!
196     //! \brief    Get Gpu context ID
197     //! \details  Return the umd side gpu context id for current gpu context
198     //!
GetCpuContextID()199     MOS_GPU_CONTEXT GetCpuContextID() { return m_gpuContext; }
200 
201     //!
202     //! \brief    Get indirect state size
203     //!
GetIndirectStateSize()204     uint32_t GetIndirectStateSize() { return m_IndirectHeapSize; }
205 
206     //!
207     //! \brief    Set indirect state size
208     //!
209     virtual MOS_STATUS SetIndirectStateSize(const uint32_t size) = 0;
210 
211     //!
212     //! \brief    Get status buffer resource for current gpu context
213     //! \return   MOS_RESOURCE_HANDLE
214     //!
GetStatusBufferResource()215     MOS_RESOURCE_HANDLE GetStatusBufferResource()
216     {
217         return m_statusBufferResource;
218     }
219 
220     //!
221     //! \brief    Get VE attribute buffer for current gpu context
222     //! \return   MOS_CMD_BUF_ATTRI_VE*
223     //!
GetAttributeVeBuffer()224     MOS_CMD_BUF_ATTRI_VE *GetAttributeVeBuffer()
225     {
226         return &m_bufAttriVe;
227     }
228 
ResetCmdBuffer()229     virtual MOS_STATUS ResetCmdBuffer()
230     {
231         return MOS_STATUS_SUCCESS;
232     }
233 
234 protected:
235     //! \brief    Hardware node for current gpu context
236     MOS_GPU_NODE m_nodeOrdinal = {};
237 
238     //! \brief    Indirect heap size (SSH area in DMA buffer)
239     uint32_t m_IndirectHeapSize = 0;
240 
241     //! \brief    Related command buffer manager
242     CmdBufMgrNext *m_cmdBufMgr = nullptr;
243 
244     //! \brief    Related command buffer manager
245     uint64_t      m_cmdBufMgrHandle = UINT64_MAX;
246 
247     //! \brief    Index in gpucontextNext mgr pool for current gpu context
248     GPU_CONTEXT_HANDLE m_gpuContextHandle = 0;
249 
250     //! \brief    Gpu status report buffer
251     MOS_RESOURCE_HANDLE m_statusBufferResource = nullptr;
252 
253     //! \brief    Track the GPU Context Client Info
254     MOS_GPU_CONTEXT m_gpuContext = MOS_GPU_CONTEXT_INVALID_HANDLE;
255 
256     //! \brief    VE attribute buffer
257     MOS_CMD_BUF_ATTRI_VE m_bufAttriVe = {};
258 MEDIA_CLASS_DEFINE_END(GpuContextNext)
259 };
260 #endif  // #ifndef __MOS_GPU_CONTEXT_NEXT_H__
261