Skip to content

Commit f24fefe

Browse files
peiyigu-intelintel-mediadev
authored andcommitted
[VP] Enable Bindless Surface State Dump
add bindless surface dump
1 parent 3ee1567 commit f24fefe

File tree

7 files changed

+127
-19
lines changed

7 files changed

+127
-19
lines changed

media_common/agnostic/common/os/mos_os.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,8 @@ struct MosStreamState
559559
bool dumpCommandBufferAsMessages = false; //!< Indicates that the command buffer should be dumped via MOS normal messages
560560
char sDirName[MOS_MAX_HLT_FILENAME_LEN] = {0}; //!< Dump Directory name - maximum 260 bytes length
561561
std::vector<INDIRECT_STATE_INFO> indirectStateInfo = {};
562+
std::vector<uint8_t *> bindlessSurfaceStateInfo = {};
563+
uint32_t bindlessSurfaceStateSize = 0;
562564
#endif // MOS_COMMAND_BUFFER_DUMP_SUPPORTED
563565

564566
#if _DEBUG || _RELEASE_INTERNAL
@@ -969,6 +971,11 @@ typedef struct _MOS_INTERFACE
969971
uint32_t *gfxAddressTop,
970972
const char *stateName);
971973

974+
void (*pfnAddBindlessSurfaceStateInfo)(
975+
PMOS_INTERFACE pOsInterface,
976+
std::vector<uint8_t *> &bindlessSurfaceState,
977+
uint32_t surfaceStateSize);
978+
972979
#define pfnFreeResource(pOsInterface, pResource) \
973980
pfnFreeResource(pOsInterface, __FUNCTION__, __FILE__, __LINE__, pResource)
974981

media_common/agnostic/common/renderhal/surface_state_heap_mgr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ class SurfaceStateHeapManager
8383

8484
MOS_STATUS DestroyHeap();
8585

86-
MOS_STATUS AssignSurfaceState();
86+
MOS_STATUS AssignSurfaceState(uint32_t surfaceStateEntryIndex, uint32_t &offset, uint8_t *&curSurfaceStatePtr, PMOS_RESOURCE &stateHeap, int32_t &surfaceStateIndex);
8787

88-
MOS_STATUS AssignUsedSurfaceState(int32_t surfaceStateEntryIndex);
88+
MOS_STATUS GetSurfaceStateDump(std::vector<uint8_t *> &dump);
8989

9090
~SurfaceStateHeapManager();
9191

media_softlet/agnostic/common/os/mos_interface.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,24 @@ class MosInterface
525525
MOS_GPU_NODE gpuNode,
526526
const char *filePathPrefix);
527527

528+
//!
529+
//! \brief Dump Bindless Surface State
530+
//!
531+
//! \param [in] streamState
532+
//! Handle of Os Stream State
533+
//! \param [in] gpuNode
534+
//! Gpu node.
535+
//! \param [in] filePathPrefix
536+
//! The prefix for indirect state dump file.
537+
//!
538+
//! \return MOS_STATUS
539+
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed
540+
//!
541+
static MOS_STATUS DumpBindlessSurfaceState(
542+
MOS_STREAM_HANDLE streamState,
543+
MOS_GPU_NODE gpuNode,
544+
const char *filePathPrefix);
545+
528546
//!
529547
//! \brief Dump Command Buffer
530548
//! \details [Cmd Buffer Interface] Dump an existing cmd buffer

media_softlet/agnostic/common/os/mos_os.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,21 @@ MOS_STATUS Mos_GetPlatformName(
461461
return MOS_STATUS_SUCCESS;
462462
}
463463

464+
void Mos_AddBindlessSurfaceStateInfo(
465+
PMOS_INTERFACE pOsInterface,
466+
std::vector<uint8_t *> &bindlessSurfaceState,
467+
uint32_t surfaceStateSize)
468+
{
469+
MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsInterface);
470+
if (pOsInterface->apoMosEnabled)
471+
{
472+
MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsInterface->osStreamState);
473+
pOsInterface->osStreamState->bindlessSurfaceStateInfo = std::move(bindlessSurfaceState);
474+
pOsInterface->osStreamState->bindlessSurfaceStateSize = surfaceStateSize;
475+
}
476+
return;
477+
}
478+
464479
void Mos_AddIndirectState(
465480
PMOS_INTERFACE pOsInterface,
466481
uint32_t stateSize,
@@ -672,6 +687,7 @@ MOS_STATUS Mos_DumpCommandBufferInit(
672687
// Setup member function and variable.
673688
pOsInterface->pfnDumpCommandBuffer = Mos_DumpCommandBuffer;
674689
pOsInterface->pfnAddIndirectState = Mos_AddIndirectState;
690+
pOsInterface->pfnAddBindlessSurfaceStateInfo = Mos_AddBindlessSurfaceStateInfo;
675691

676692
// Check if command buffer dump was enabled in user feature.
677693
ReadUserSetting(

media_softlet/agnostic/common/renderhal/renderhal.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3068,16 +3068,7 @@ MOS_STATUS RenderHal_AssignSurfaceState(
30683068
return eStatus;
30693069
}
30703070
MHW_RENDERHAL_CHK_NULL_RETURN(pStateHeap->surfaceStateMgr);
3071-
MHW_RENDERHAL_CHK_STATUS_RETURN(pStateHeap->surfaceStateMgr->AssignSurfaceState());
3072-
SURFACE_STATES_HEAP_OBJ *sufStateHeap = pStateHeap->surfaceStateMgr->m_surfStateHeap;
3073-
MHW_RENDERHAL_CHK_NULL_RETURN(sufStateHeap);
3074-
MHW_RENDERHAL_CHK_NULL_RETURN(sufStateHeap->pLockedOsResourceMem);
3075-
MHW_RENDERHAL_CHK_VALUE_RETURN(Mos_ResourceIsNull(&sufStateHeap->osResource), false);
3076-
dwOffset = sufStateHeap->uiCurState * sufStateHeap->uiInstanceSize;
3077-
pCurSurfaceState = sufStateHeap->pLockedOsResourceMem + dwOffset;
3078-
stateHeap = &sufStateHeap->osResource;
3079-
surfaceStateIndex = sufStateHeap->uiCurState;
3080-
MHW_RENDERHAL_CHK_STATUS_RETURN(pStateHeap->surfaceStateMgr->AssignUsedSurfaceState(pStateHeap->iCurrentSurfaceState));
3071+
MHW_RENDERHAL_CHK_STATUS_RETURN(pStateHeap->surfaceStateMgr->AssignSurfaceState(pStateHeap->iCurrentSurfaceState, dwOffset, pCurSurfaceState, stateHeap, surfaceStateIndex));
30813072
// Obtain new surface entry and initialize
30823073
iSurfaceEntry = pStateHeap->iCurrentSurfaceState;
30833074
++pStateHeap->iCurrentSurfaceState;
@@ -5766,7 +5757,7 @@ MOS_STATUS RenderHal_SendBindlessSurfaces(
57665757

57675758
MHW_RENDERHAL_CHK_VALUE_RETURN(pStateHeap->surfaceStateMgr->m_heapStatus, SURFACE_STATE_USED_HEAP_INITIALIZED);
57685759

5769-
for (const auto &pair : pStateHeap->surfaceStateMgr->m_usedStates)
5760+
for (const auto &pair : pStateHeap->surfaceStateMgr->m_usedStates)
57705761
{
57715762
uint32_t surfaceStateIndex = pair.first;
57725763
uint32_t surfaceStateEntryIndex = pair.second;
@@ -5784,6 +5775,21 @@ MOS_STATUS RenderHal_SendBindlessSurfaces(
57845775

57855776
pStateHeap->surfaceStateMgr->m_heapStatus = SURFACE_STATE_USED_HEAP_SENT;
57865777

5778+
#if MOS_COMMAND_BUFFER_DUMP_SUPPORTED
5779+
if (pOsInterface->pfnAddBindlessSurfaceStateInfo)
5780+
{
5781+
std::vector<uint8_t *> dumpInfo;
5782+
if (pStateHeap->surfaceStateMgr->GetSurfaceStateDump(dumpInfo) == MOS_STATUS_SUCCESS)
5783+
{
5784+
pOsInterface->pfnAddBindlessSurfaceStateInfo(pOsInterface, dumpInfo, pStateHeap->surfaceStateMgr->m_surfStateHeap->uiInstanceSize);
5785+
}
5786+
else
5787+
{
5788+
MHW_RENDERHAL_ASSERTMESSAGE("Dump Bindless Surface State Fail");
5789+
}
5790+
}
5791+
#endif
5792+
57875793
return eStatus;
57885794
}
57895795

media_softlet/agnostic/common/renderhal/surface_state_heap_mgr.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ MOS_STATUS SurfaceStateHeapManager::DestroyHeap()
113113
m_osInterface->pfnUnlockResource(
114114
m_osInterface,
115115
&m_surfStateHeap->osResource);
116+
m_surfStateHeap->pLockedOsResourceMem = nullptr;
116117
}
117118

118119
m_osInterface->pfnFreeResource(
@@ -184,7 +185,7 @@ void SurfaceStateHeapManager::RefreshSync()
184185
m_surfHeapInUse = iInstanceInUse;
185186
}
186187

187-
MOS_STATUS SurfaceStateHeapManager::AssignSurfaceState()
188+
MOS_STATUS SurfaceStateHeapManager::AssignSurfaceState(uint32_t surfaceStateEntryIndex, uint32_t &offset, uint8_t *&curSurfaceStatePtr, PMOS_RESOURCE &stateHeap, int32_t &surfaceStateIndex)
188189
{
189190
VP_FUNC_CALL();
190191

@@ -193,7 +194,6 @@ MOS_STATUS SurfaceStateHeapManager::AssignSurfaceState()
193194

194195
SURFACE_STATES_OBJ *pSurfStateCurObj;
195196
SURFACE_STATES_HEAP_OBJ *pSurfStateHeap;
196-
uint32_t uiOffset;
197197

198198
MHW_FUNCTION_ENTER;
199199
MHW_CHK_NULL_RETURN(m_surfStateHeap);
@@ -264,15 +264,29 @@ MOS_STATUS SurfaceStateHeapManager::AssignSurfaceState()
264264
pSurfStateHeap->uiNextState = (pSurfStateHeap->uiNextState + 1) % MAX_SURFACE_STATES;
265265

266266
//Clean the memory of current veboxheap to avoid the history states
267-
uiOffset = pSurfStateHeap->uiCurState * pSurfStateHeap->uiInstanceSize;
268-
MOS_ZeroMemory(pSurfStateHeap->pLockedOsResourceMem + uiOffset, pSurfStateHeap->uiInstanceSize);
267+
offset = pSurfStateHeap->uiCurState * pSurfStateHeap->uiInstanceSize;
268+
MOS_ZeroMemory(pSurfStateHeap->pLockedOsResourceMem + offset, pSurfStateHeap->uiInstanceSize);
269+
270+
curSurfaceStatePtr = pSurfStateHeap->pLockedOsResourceMem + offset;
271+
stateHeap = &pSurfStateHeap->osResource;
272+
surfaceStateIndex = pSurfStateHeap->uiCurState;
273+
274+
m_usedStates.insert(std::make_pair(surfaceStateIndex, surfaceStateEntryIndex));
269275

270276
return eStatus;
271277
}
272278

273-
MOS_STATUS SurfaceStateHeapManager::AssignUsedSurfaceState(int32_t surfaceStateEntryIndex)
279+
MOS_STATUS SurfaceStateHeapManager::GetSurfaceStateDump(std::vector<uint8_t *> &dump)
274280
{
281+
std::stringstream ss;
282+
dump.clear();
275283
MHW_CHK_NULL_RETURN(m_surfStateHeap);
276-
m_usedStates.insert(std::make_pair(m_surfStateHeap->uiCurState, surfaceStateEntryIndex));
284+
MHW_CHK_NULL_RETURN(m_surfStateHeap->pLockedOsResourceMem);
285+
for (const auto &pair : m_usedStates)
286+
{
287+
uint32_t surfaceIndex = pair.first;
288+
uint8_t *data = m_surfStateHeap->pLockedOsResourceMem + m_surfStateHeap->uiInstanceSize * surfaceIndex;
289+
dump.push_back(data);
290+
}
277291
return MOS_STATUS_SUCCESS;
278292
}

media_softlet/linux/common/os/mos_interface.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,48 @@ MOS_STATUS MosInterface::DumpIndirectStates(MOS_STREAM_HANDLE streamState, const
773773
return eStatus;
774774
}
775775

776+
MOS_STATUS MosInterface::DumpBindlessSurfaceState(
777+
MOS_STREAM_HANDLE streamState,
778+
MOS_GPU_NODE gpuNode,
779+
const char *filePathPrefix)
780+
{
781+
MOS_OS_CHK_NULL_RETURN(filePathPrefix);
782+
783+
if (streamState &&
784+
!streamState->bindlessSurfaceStateInfo.empty() &&
785+
(MOS_GPU_NODE_COMPUTE == gpuNode || MOS_GPU_NODE_3D == gpuNode))
786+
{
787+
std::stringstream fileName;
788+
fileName << filePathPrefix << "_bindless_surface_state.txt";
789+
std::fstream fs;
790+
fs.open(fileName.str(), std::ios_base::out | std::ios_base::app);
791+
uint32_t dwordCount = streamState->bindlessSurfaceStateSize / 4;
792+
for (uint8_t *&ptr : streamState->bindlessSurfaceStateInfo)
793+
{
794+
uint32_t *data = (uint32_t *)ptr;
795+
for (uint32_t i = 0; i < dwordCount; ++i)
796+
{
797+
if (0 == i % 4)
798+
{
799+
if (0 != i)
800+
{
801+
fs << std::endl;
802+
}
803+
fs << "#0 #0";
804+
}
805+
fs << " " << std::hex << std::setw(8) << std::setfill('0') << data[i];
806+
}
807+
fs << std::endl
808+
<< std::endl;
809+
}
810+
fs.close();
811+
streamState->bindlessSurfaceStateInfo.clear();
812+
streamState->bindlessSurfaceStateSize = 0;
813+
}
814+
815+
return MOS_STATUS_SUCCESS;
816+
}
817+
776818
MOS_STATUS MosInterface::DumpBindingTable(
777819
MOS_STREAM_HANDLE streamState,
778820
COMMAND_BUFFER_HANDLE cmdBuffer,
@@ -963,6 +1005,11 @@ MOS_STATUS MosInterface::DumpCommandBuffer(
9631005
MOS_FreeMemory(pOutputBuffer);
9641006
return eStatus;
9651007
}
1008+
if ((eStatus = DumpBindlessSurfaceState(streamState, gpuNode, sFileName)) != MOS_STATUS_SUCCESS)
1009+
{
1010+
MOS_FreeMemory(pOutputBuffer);
1011+
return eStatus;
1012+
}
9661013
if ((eStatus = DumpIndirectStates(streamState, sFileName, currentTime)) != MOS_STATUS_SUCCESS)
9671014
{
9681015
MOS_FreeMemory(pOutputBuffer);

0 commit comments

Comments
 (0)