1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
/*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file mos_commandbuffer_specific.cpp
//! \brief Container class for the specific command buffer
//!
#include "mos_commandbuffer_specific.h"
#include "mos_context_specific.h"
#include "mos_gpucontext_specific.h"
#include "mos_graphicsresource_specific.h"
MOS_STATUS CommandBufferSpecific::Allocate(OsContext *osContext, uint32_t size)
{
MOS_OS_FUNCTION_ENTER;
MOS_OS_CHK_NULL_RETURN(osContext);
if (osContext->GetOsContextValid() == false)
{
MOS_OS_ASSERTMESSAGE("The OS context got is not valid.");
return MOS_STATUS_INVALID_HANDLE;
}
m_osContext = osContext;
GraphicsResource::CreateParams params;
params.m_tileType = MOS_TILE_LINEAR;
params.m_type = MOS_GFXRES_BUFFER;
params.m_format = Format_Buffer;
params.m_width = size;
params.m_height = 1;
params.m_depth = 1;
params.m_arraySize = 1;
params.m_name = "MOS CmdBuf";
m_graphicsResource = GraphicsResource::CreateGraphicResource(GraphicsResource::osSpecificResource);
MOS_OS_CHK_NULL_RETURN(m_graphicsResource);
MOS_OS_CHK_STATUS_RETURN(m_graphicsResource->Allocate(osContext, params));
m_size = m_graphicsResource->GetSize(); // get real size after allocate
return MOS_STATUS_SUCCESS;
}
void CommandBufferSpecific::Free()
{
MOS_OS_FUNCTION_ENTER;
if (!m_graphicsResource)
{
MOS_OS_ASSERTMESSAGE("graphic resource back the commnd buffer need be allocated firstly.");
return;
}
m_graphicsResource->Free(m_osContext, 0);
MOS_Delete(m_graphicsResource);
}
MOS_STATUS CommandBufferSpecific::BindToGpuContext(GpuContext *gpuContext)
{
MOS_OS_FUNCTION_ENTER;
MOS_OS_CHK_NULL_RETURN(gpuContext);
MOS_OS_CHK_NULL_RETURN(m_graphicsResource);
GraphicsResource::LockParams params;
params.m_writeRequest = true;
m_lockAddr = static_cast<uint8_t *>(m_graphicsResource->Lock(m_osContext, params));
MOS_OS_CHK_NULL_RETURN(m_lockAddr);
m_gpuContext = gpuContext;
m_readyToUse = true;
return MOS_STATUS_SUCCESS;
}
int CommandBufferSpecific::isBusy()
{
MOS_OS_FUNCTION_ENTER;
if (m_graphicsResource == nullptr)
{
MOS_OS_ASSERTMESSAGE("Graphicresource is not initialized.");
// return not busy here to avoid dead lock
return 0;
}
GraphicsResourceSpecific * graphicsResourceSpecific = static_cast<GraphicsResourceSpecific *>(m_graphicsResource);
MOS_LINUX_BO* cmdBufBo = graphicsResourceSpecific->GetBufferObject();
if (cmdBufBo == nullptr)
{
MOS_OS_ASSERTMESSAGE("Failed to get the buffer object for the command buffer, check busy failed.");
// return not busy here to avoid dead lock
return 0;
}
return mos_bo_busy(cmdBufBo);
}
void CommandBufferSpecific::waitReady()
{
MOS_OS_FUNCTION_ENTER;
if (m_graphicsResource == nullptr)
{
MOS_OS_ASSERTMESSAGE("Graphicresource is not initialized.");
// return not busy here to avoid dead lock
return;
}
GraphicsResourceSpecific * graphicsResourceSpecific = static_cast<GraphicsResourceSpecific *>(m_graphicsResource);
MOS_LINUX_BO* cmdBufBo = graphicsResourceSpecific->GetBufferObject();
if (cmdBufBo == nullptr)
{
MOS_OS_ASSERTMESSAGE("Failed to get the buffer object for the command buffer, wait failed.");
return;
}
mos_bo_wait_rendering(cmdBufBo);
}
void CommandBufferSpecific::UnBindToGpuContext()
{
MOS_OS_FUNCTION_ENTER;
// Internal state validity check
if (m_osContext == nullptr) {
MOS_OS_ASSERTMESSAGE("m_osContext ptr should not be nullptr");
return ;
}
if (m_osContext->GetOsContextValid() == false)
{
MOS_OS_ASSERTMESSAGE("The OS context got is not valid.");
return ;
}
if (!m_graphicsResource)
{
MOS_OS_ASSERTMESSAGE("graphic resource back the commnd buffer need be allocated firstly.");
return;
}
m_graphicsResource->Unlock(m_osContext);
m_readyToUse = false;
}
MOS_STATUS CommandBufferSpecific:: ReSize(uint32_t newSize)
{
MOS_OS_FUNCTION_ENTER;
if (m_readyToUse)
{
// release old command buffer
UnBindToGpuContext();
Free();
m_readyToUse = false;
}
// re-allocate new buffer
MOS_OS_CHK_STATUS_RETURN(Allocate(m_osContext, newSize));
MOS_OS_CHK_STATUS_RETURN(BindToGpuContext(m_gpuContext));
return MOS_STATUS_SUCCESS;
}
|