• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_commandbuffer_specific_next.cpp
24 //! \brief   Container class for the specific command buffer
25 //!
26 
27 #include "mos_commandbuffer_specific_next.h"
28 #include "mos_context_specific_next.h"
29 #include "mos_gpucontext_specific_next.h"
30 #include "mos_graphicsresource_specific_next.h"
31 
Allocate(OsContextNext * osContext,uint32_t size)32 MOS_STATUS  CommandBufferSpecificNext::Allocate(OsContextNext *osContext, uint32_t size)
33 {
34     MOS_OS_FUNCTION_ENTER;
35 
36     MOS_OS_CHK_NULL_RETURN(osContext);
37 
38     if (osContext->GetOsContextValid() == false)
39     {
40         MOS_OS_ASSERTMESSAGE("The OS context got is not valid.");
41         return MOS_STATUS_INVALID_HANDLE;
42     }
43 
44     m_osContext = osContext;
45 
46     GraphicsResourceNext::CreateParams params;
47     params.m_tileType  = MOS_TILE_LINEAR;
48     params.m_type      = MOS_GFXRES_BUFFER;
49     params.m_format    = Format_Buffer;
50     params.m_width     = size;
51     params.m_height    = 1;
52     params.m_depth     = 1;
53     params.m_arraySize = 1;
54     params.m_name      = "MOS CmdBuf";
55 
56     m_graphicsResource = GraphicsResourceNext::CreateGraphicResource(GraphicsResourceNext::osSpecificResource);
57     MOS_OS_CHK_NULL_RETURN(m_graphicsResource);
58 
59     MOS_OS_CHK_STATUS_RETURN(m_graphicsResource->Allocate(osContext, params));
60 
61     m_size = m_graphicsResource->GetSize(); // get real size after allocate
62 
63     return MOS_STATUS_SUCCESS;
64 }
65 
Free()66 void  CommandBufferSpecificNext::Free()
67 {
68     MOS_OS_FUNCTION_ENTER;
69 
70     if (!m_graphicsResource)
71     {
72         MOS_OS_ASSERTMESSAGE("graphic resource back the commnd buffer need be allocated firstly.");
73         return;
74     }
75 
76     m_graphicsResource->Free(m_osContext, 0);
77     MOS_Delete(m_graphicsResource);
78 }
79 
BindToGpuContext(GpuContextNext * gpuContext)80 MOS_STATUS CommandBufferSpecificNext::BindToGpuContext(GpuContextNext *gpuContext)
81 {
82     MOS_OS_FUNCTION_ENTER;
83 
84     MOS_OS_CHK_NULL_RETURN(gpuContext);
85     MOS_OS_CHK_NULL_RETURN(m_graphicsResource);
86 
87     GraphicsResourceNext::LockParams params;
88     params.m_writeRequest = true;
89     m_lockAddr = static_cast<uint8_t *>(m_graphicsResource->Lock(m_osContext, params));
90     MOS_OS_CHK_NULL_RETURN(m_lockAddr);
91 
92     m_gpuContext        = gpuContext;
93     m_gpuContextHandle  = gpuContext->GetGpuContextHandle();
94 
95     m_readyToUse = true;
96     return MOS_STATUS_SUCCESS;
97 
98 }
99 
isBusy()100 int CommandBufferSpecificNext::isBusy()
101 {
102     MOS_OS_FUNCTION_ENTER;
103 
104     if (m_graphicsResource == nullptr)
105     {
106          MOS_OS_ASSERTMESSAGE("Graphicresource is not initialized.");
107             // return not busy here to avoid dead lock
108          return 0;
109     }
110 
111     GraphicsResourceSpecificNext * graphicsResourceSpecific = static_cast<GraphicsResourceSpecificNext *>(m_graphicsResource);
112     MOS_LINUX_BO* cmdBufBo = graphicsResourceSpecific->GetBufferObject();
113     if (cmdBufBo == nullptr)
114     {
115         MOS_OS_ASSERTMESSAGE("Failed to get the buffer object for the command buffer, check busy failed.");
116         // return not busy here to avoid dead lock
117         return 0;
118     }
119 
120     return mos_bo_busy(cmdBufBo);
121 }
122 
waitReady()123 void CommandBufferSpecificNext::waitReady()
124 {
125     MOS_OS_FUNCTION_ENTER;
126 
127     if (m_graphicsResource == nullptr)
128     {
129         MOS_OS_ASSERTMESSAGE("Graphicresource is not initialized.");
130         // return not busy here to avoid dead lock
131         return;
132     }
133 
134     GraphicsResourceSpecificNext * graphicsResourceSpecific = static_cast<GraphicsResourceSpecificNext *>(m_graphicsResource);
135     MOS_LINUX_BO* cmdBufBo = graphicsResourceSpecific->GetBufferObject();
136     if (cmdBufBo == nullptr)
137     {
138         MOS_OS_ASSERTMESSAGE("Failed to get the buffer object for the command buffer, wait failed.");
139         return;
140     }
141 
142     mos_bo_wait_rendering(cmdBufBo);
143 }
144 
UnBindToGpuContext(bool isNative)145 void CommandBufferSpecificNext::UnBindToGpuContext(bool isNative)
146 {
147     MOS_OS_FUNCTION_ENTER;
148 
149     // Internal state validity check
150     if (m_osContext == nullptr) {
151         MOS_OS_ASSERTMESSAGE("m_osContext ptr should not  be nullptr");
152         return ;
153     }
154 
155     if (m_osContext->GetOsContextValid() == false)
156     {
157         MOS_OS_ASSERTMESSAGE("The OS context got is not valid.");
158         return ;
159     }
160 
161     if (!m_graphicsResource)
162     {
163         MOS_OS_ASSERTMESSAGE("graphic resource back the commnd buffer need be allocated firstly.");
164         return;
165     }
166 
167     m_graphicsResource->Unlock(m_osContext);
168 
169     m_readyToUse = false;
170 }
171 
ReSize(uint32_t newSize)172 MOS_STATUS CommandBufferSpecificNext:: ReSize(uint32_t newSize)
173 {
174     MOS_OS_FUNCTION_ENTER;
175 
176     if (m_readyToUse)
177     {
178         // release old command buffer
179         UnBindToGpuContext();
180         Free();
181         m_readyToUse = false;
182     }
183 
184     // re-allocate new buffer
185     MOS_OS_CHK_STATUS_RETURN(Allocate(m_osContext, newSize));
186 
187     MOS_OS_CHK_STATUS_RETURN(BindToGpuContext(m_gpuContext));
188 
189     return MOS_STATUS_SUCCESS;
190 }
191 
192