| 1 |
/* |
| 2 |
* Copyright (c) 2018, 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 |
//! |
| 24 |
//! \file media_scalability_multipipe.cpp |
| 25 |
//! \brief Defines the common interface for media scalability multipipe mode. |
| 26 |
//! \details The media scalability multipipe interface is further sub-divided by component, |
| 27 |
//! this file is for the base interface which is shared by all components. |
| 28 |
//! |
| 29 |
|
| 30 |
#include "media_scalability_multipipe.h" |
| 31 |
#include "media_scalability_defs.h" |
| 32 |
#include "mos_os.h" |
| 33 |
|
| 34 |
MOS_STATUS MediaScalabilityMultiPipe::AllocateNativeFenceCounters() |
| 35 |
{ |
| 36 |
SCALABILITY_FUNCTION_ENTER; |
| 37 |
SCALABILITY_CHK_NULL_RETURN(m_osInterface); |
| 38 |
|
| 39 |
// Check if FtrNativeFence is enabled |
| 40 |
// Check if FtrNativeFence is enabled |
| 41 |
if (!MEDIA_IS_SKU(m_osInterface->pfnGetSkuTable(m_osInterface), FtrNativeFence)) |
| 42 |
{ |
| 43 |
SCALABILITY_NORMALMESSAGE("NativeFence disabled, skipping counter allocation"); |
| 44 |
return MOS_STATUS_SUCCESS; |
| 45 |
} |
| 46 |
|
| 47 |
SCALABILITY_NORMALMESSAGE("NativeFence enabled, allocating barrier counters"); |
| 48 |
// Setup allocation parameters for GPU memory buffers |
| 49 |
MOS_ALLOC_GFXRES_PARAMS allocParams; |
| 50 |
MOS_ZeroMemory(&allocParams, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 51 |
allocParams.TileType = MOS_TILE_LINEAR; |
| 52 |
allocParams.Format = Format_Buffer; |
| 53 |
allocParams.Type = MOS_GFXRES_BUFFER; |
| 54 |
allocParams.dwBytes = sizeof(uint32_t); |
| 55 |
allocParams.pBufName = "NativeFence Child Counter"; |
| 56 |
|
| 57 |
// Allocate m_counterChild |
| 58 |
SCALABILITY_CHK_STATUS_MESSAGE_RETURN( |
| 59 |
m_osInterface->pfnAllocateResource(m_osInterface, &allocParams, &m_counterChild), |
| 60 |
"Failed to allocate NativeFence child counter"); |
| 61 |
|
| 62 |
// Initialize m_counterChild to 0 |
| 63 |
MOS_LOCK_PARAMS lockFlagsWriteOnly; |
| 64 |
MOS_ZeroMemory(&lockFlagsWriteOnly, sizeof(MOS_LOCK_PARAMS)); |
| 65 |
lockFlagsWriteOnly.WriteOnly = 1; |
| 66 |
uint32_t *data = (uint32_t *)m_osInterface->pfnLockResource(m_osInterface, &m_counterChild, &lockFlagsWriteOnly); |
| 67 |
SCALABILITY_CHK_NULL_RETURN(data); |
| 68 |
*data = 0; |
| 69 |
SCALABILITY_CHK_STATUS_RETURN(m_osInterface->pfnUnlockResource(m_osInterface, &m_counterChild)); |
| 70 |
|
| 71 |
SCALABILITY_NORMALMESSAGE("NativeFence child counter allocated and initialized"); |
| 72 |
|
| 73 |
// Allocate m_counterParent |
| 74 |
allocParams.pBufName = "NativeFence Parent Counter"; |
| 75 |
SCALABILITY_CHK_STATUS_MESSAGE_RETURN( |
| 76 |
m_osInterface->pfnAllocateResource(m_osInterface, &allocParams, &m_counterParent), |
| 77 |
"Failed to allocate NativeFence parent counter"); |
| 78 |
|
| 79 |
// Initialize m_counterParent to 0 |
| 80 |
data = (uint32_t *)m_osInterface->pfnLockResource(m_osInterface, &m_counterParent, &lockFlagsWriteOnly); |
| 81 |
SCALABILITY_CHK_NULL_RETURN(data); |
| 82 |
*data = 0; |
| 83 |
SCALABILITY_CHK_STATUS_RETURN(m_osInterface->pfnUnlockResource(m_osInterface, &m_counterParent)); |
| 84 |
|
| 85 |
SCALABILITY_NORMALMESSAGE("NativeFence parent counter allocated and initialized"); |
| 86 |
|
| 87 |
return MOS_STATUS_SUCCESS; |
| 88 |
} |
| 89 |
|
| 90 |
MOS_STATUS MediaScalabilityMultiPipe::SyncPipesWithNativeFence(PMOS_COMMAND_BUFFER cmdBuffer) |
| 91 |
{ |
| 92 |
SCALABILITY_FUNCTION_ENTER; |
| 93 |
SCALABILITY_CHK_NULL_RETURN(cmdBuffer); |
| 94 |
SCALABILITY_CHK_NULL_RETURN(m_osInterface); |
| 95 |
|
| 96 |
if (m_pipeNum > 2) |
| 97 |
{ |
| 98 |
SCALABILITY_ASSERTMESSAGE("Should not reach here. m_counterParent cleanup logic needs to be adjusted to cover the corner case of one parent with multiple children. m_pipeNum=%d", m_pipeNum); |
| 99 |
} |
| 100 |
|
| 101 |
bool isParent = (m_currentPipe == 0); |
| 102 |
|
| 103 |
if (isParent) |
| 104 |
{ |
| 105 |
SCALABILITY_NORMALMESSAGE("NativeFence: Parent pipe (0) entering barrier sync, waiting for %d child signals", m_pipeNum - 1); |
| 106 |
|
| 107 |
// Parent: WAIT on m_counterChild until value equals (m_pipeNum - 1) |
| 108 |
SCALABILITY_CHK_STATUS_RETURN(SendMiSemaphoreWaitCmd( |
| 109 |
&m_counterChild, |
| 110 |
0, |
| 111 |
m_pipeNum - 1, |
| 112 |
MHW_MI_SAD_EQUAL_SDD, |
| 113 |
cmdBuffer)); |
| 114 |
SCALABILITY_NORMALMESSAGE("NativeFence: Parent collected all %d child signals", m_pipeNum - 1); |
| 115 |
|
| 116 |
// Parent: STORE 0 to m_counterChild to reset accumulator |
| 117 |
SCALABILITY_CHK_STATUS_RETURN(SendMiStoreDataImmCmd( |
| 118 |
&m_counterChild, |
| 119 |
0, |
| 120 |
0, |
| 121 |
cmdBuffer)); |
| 122 |
SCALABILITY_NORMALMESSAGE("NativeFence: Parent reset child counter to 0"); |
| 123 |
|
| 124 |
// Parent: INCREMENT m_counterParent |
| 125 |
SCALABILITY_CHK_STATUS_RETURN(SendMiAtomicCmd( |
| 126 |
&m_counterParent, |
| 127 |
0, |
| 128 |
1, |
| 129 |
MHW_MI_ATOMIC_INC, |
| 130 |
cmdBuffer)); |
| 131 |
SCALABILITY_NORMALMESSAGE("NativeFence: Parent signaled go to all children"); |
| 132 |
} |
| 133 |
else |
| 134 |
{ |
| 135 |
SCALABILITY_NORMALMESSAGE("NativeFence: Child pipe (%d) entering barrier sync", m_currentPipe); |
| 136 |
|
| 137 |
// Child: INCREMENT m_counterChild |
| 138 |
SCALABILITY_CHK_STATUS_RETURN(SendMiAtomicCmd( |
| 139 |
&m_counterChild, |
| 140 |
0, |
| 141 |
1, |
| 142 |
MHW_MI_ATOMIC_INC, |
| 143 |
cmdBuffer)); |
| 144 |
SCALABILITY_NORMALMESSAGE("NativeFence: Child pipe (%d) signaled completion to parent", m_currentPipe); |
| 145 |
|
| 146 |
// Child: WAIT on m_counterParent until value equals 1 |
| 147 |
SCALABILITY_CHK_STATUS_RETURN(SendMiSemaphoreWaitCmd( |
| 148 |
&m_counterParent, |
| 149 |
0, |
| 150 |
1, |
| 151 |
MHW_MI_SAD_EQUAL_SDD, |
| 152 |
cmdBuffer)); |
| 153 |
SCALABILITY_NORMALMESSAGE("NativeFence: Child pipe (%d) received parent go signal", m_currentPipe); |
| 154 |
|
| 155 |
// Child #1 responsible for cleanup |
| 156 |
if (m_currentPipe == 1) |
| 157 |
{ |
| 158 |
SCALABILITY_CHK_STATUS_RETURN(SendMiStoreDataImmCmd( |
| 159 |
&m_counterParent, |
| 160 |
0, |
| 161 |
0, |
| 162 |
cmdBuffer)); |
| 163 |
SCALABILITY_NORMALMESSAGE("NativeFence: Child pipe 1 reset parent counter to 0"); |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
SCALABILITY_VERBOSEMESSAGE("NativeFence: Pipe (%d) exiting barrier sync", m_currentPipe); |
| 168 |
return MOS_STATUS_SUCCESS; |
| 169 |
} |
| 170 |
|
| 171 |
MOS_STATUS MediaScalabilityMultiPipe::Destroy() |
| 172 |
{ |
| 173 |
SCALABILITY_FUNCTION_ENTER; |
| 174 |
SCALABILITY_NORMALMESSAGE("MediaScalabilityMultiPipe::Destroy() - Cleaning up NativeFence resources"); |
| 175 |
|
| 176 |
if (m_osInterface) |
| 177 |
{ |
| 178 |
// Free m_counterChild if allocated |
| 179 |
if (!Mos_ResourceIsNull(&m_counterChild)) |
| 180 |
{ |
| 181 |
m_osInterface->pfnFreeResource(m_osInterface, &m_counterChild); |
| 182 |
SCALABILITY_NORMALMESSAGE("MediaScalabilityMultiPipe::Destroy() - Freed m_counterChild"); |
| 183 |
} |
| 184 |
|
| 185 |
// Free m_counterParent if allocated |
| 186 |
if (!Mos_ResourceIsNull(&m_counterParent)) |
| 187 |
{ |
| 188 |
m_osInterface->pfnFreeResource(m_osInterface, &m_counterParent); |
| 189 |
SCALABILITY_NORMALMESSAGE("MediaScalabilityMultiPipe::Destroy() - Freed m_counterParent"); |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
// Call base class Destroy() to maintain cleanup chain |
| 194 |
SCALABILITY_CHK_STATUS_RETURN(MediaScalability::Destroy()); |
| 195 |
|
| 196 |
SCALABILITY_NORMALMESSAGE("MediaScalabilityMultiPipe::Destroy() - Cleanup complete"); |
| 197 |
return MOS_STATUS_SUCCESS; |
| 198 |
} |
| 199 |
|
| 200 |
MOS_STATUS MediaScalabilityMultiPipe::UpdateState(void *statePars) |
| 201 |
{ |
| 202 |
return MOS_STATUS_SUCCESS; |
| 203 |
} |
| 204 |
|