Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
6.9 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) Microsoft Corporation, 2000.
  3. //
  4. // rtdmon.cpp
  5. //
  6. // RunTime Debug Monitor
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #include "pch.cpp"
  10. #pragma hdrstop
  11. #include "rtdmon.hpp"
  12. #include "fe.h"
  13. //-----------------------------------------------------------------------------
  14. //
  15. //-----------------------------------------------------------------------------
  16. RTDebugMonitor::RTDebugMonitor( CD3DBase* pD3DBase, BOOL bDbgMonConnectionEnabled )
  17. {
  18. m_pD3DBase = pD3DBase;
  19. m_bDbgMonConnectionEnabled = bDbgMonConnectionEnabled;
  20. }
  21. //-----------------------------------------------------------------------------
  22. RTDebugMonitor::~RTDebugMonitor( void )
  23. {
  24. }
  25. //-----------------------------------------------------------------------------
  26. void
  27. RTDebugMonitor::NextEvent( UINT32 EventType )
  28. {
  29. CheckLostMonitorConnection();
  30. BOOL bBreakpoint = D3DDebugMonitor::IsEventBreak( EventType );
  31. // do event-specific stuff (state update; actions; check for breakpoints)
  32. UINT i;
  33. switch ( EventType )
  34. {
  35. case D3DDM_EVENT_RSTOKEN:
  36. switch( ((CD3DHal*)m_pD3DBase)->rstates[D3DRS_DEBUGMONITORTOKEN] )
  37. {
  38. case D3DDMT_ENABLE:
  39. m_bDbgMonConnectionEnabled = TRUE;
  40. break;
  41. case D3DDMT_DISABLE:
  42. if( m_pTgtCtx )
  43. {
  44. DetachMonitorConnection();
  45. }
  46. D3D_INFO(0, "D3DDebugTarget - debug monitor connection disabled by target");
  47. m_bDbgMonConnectionEnabled = FALSE;
  48. break;
  49. }
  50. break;
  51. case D3DDM_EVENT_BEGINSCENE:
  52. // try to attach if not attached
  53. if (!MonitorConnected()) AttachToMonitor(1);
  54. break;
  55. case D3DDM_EVENT_ENDSCENE:
  56. m_pTgtCtx->SceneCount++;
  57. break;
  58. case D3DDM_EVENT_PRIMITIVE:
  59. m_pTgtCtx->PrimitiveCount++;
  60. if (m_pMonCtx && m_pMonCtx->PrimitiveCountBP)
  61. {
  62. if ( m_pTgtCtx->PrimitiveCount == m_pMonCtx->PrimitiveCountBP )
  63. bBreakpoint = TRUE;
  64. }
  65. break;
  66. }
  67. // invoke base class to talk to monitor and issue commands
  68. if (bBreakpoint)
  69. {
  70. m_pTgtCtx->EventStatus = EventType;
  71. D3DDebugMonitor::MonitorBreakpoint();
  72. m_pTgtCtx->EventStatus = 0x0;
  73. }
  74. return;
  75. }
  76. HRESULT
  77. RTDebugMonitor::ProcessMonitorCommand( void )
  78. {
  79. UINT32 Command = m_pMonCtx->Command;
  80. UINT i;
  81. // default case - no data return
  82. m_pTgtCtx->CommandBufferSize = 0;
  83. CD3DHal* pHal = (CD3DHal*)m_pD3DBase;
  84. D3DFE_PVFUNCSI* pPVF = (D3DFE_PVFUNCSI*)pHal->m_pv->pGeometryFuncs;
  85. CVertexVM* pVVM = &(pPVF->m_VertexVM);
  86. switch ( Command & D3DDM_CMD_MASK )
  87. {
  88. case D3DDM_CMD_GETVERTEXSTATE:
  89. {
  90. D3DDMVertexState* pVSS = (D3DDMVertexState*)m_pCmdData;
  91. pVVM->GetData( D3DSPR_INPUT, 0, D3DDM_MAX_VSINPUTREG, (void*)(pVSS->InputRegs) );
  92. m_pTgtCtx->CommandBufferSize = sizeof(D3DDMVertexState);
  93. }
  94. break;
  95. case D3DDM_CMD_GETVERTEXSHADERSTATE:
  96. {
  97. D3DDMVertexShaderState* pVSS = (D3DDMVertexShaderState*)m_pCmdData;
  98. if (!m_pD3DBase->m_dwCurrentShaderHandle) break;
  99. pVSS->CurrentInst = pVVM->GetCurInstIndex();
  100. pVVM->GetData( D3DSPR_TEMP, 0, D3DDM_MAX_VSTEMPREG, (void*)(pVSS->TempRegs) );
  101. pVVM->GetData( D3DSPR_RASTOUT, 0, D3DDM_MAX_VSRASTOUTREG, (void*)(pVSS->RastOutRegs) );
  102. pVVM->GetData( D3DSPR_ATTROUT, 0, D3DDM_MAX_VSATTROUTREG, (void*)(pVSS->AttrOutRegs) );
  103. pVVM->GetData( D3DSPR_TEXCRDOUT, 0, D3DDM_MAX_VSTEXCRDOUTREG, (void*)(pVSS->TexCrdOutRegs) );
  104. pVVM->GetData( D3DSPR_ADDR, 0, 1, (void*)(pVSS->AddressReg) );
  105. m_pTgtCtx->CommandBufferSize = sizeof(D3DDMVertexShaderState);
  106. }
  107. break;
  108. case D3DDM_CMD_GETVERTEXSHADERCONST:
  109. {
  110. D3DDMVertexShaderConst* pVSC = (D3DDMVertexShaderConst*)m_pCmdData;
  111. pVVM->GetData( D3DSPR_CONST, 0, 96, (void*)(pVSC->ConstRegs) );
  112. m_pTgtCtx->CommandBufferSize = 96*4*sizeof(FLOAT);
  113. }
  114. break;
  115. case D3DDM_CMD_GETVERTEXSHADER:
  116. {
  117. DWORD Handle = *(DWORD*)m_pCmdData;
  118. if (D3DVSD_ISLEGACY(Handle)) break;
  119. CVShader* pShader = (CVShader*)(pHal->m_pVShaderArray->GetObject(Handle));
  120. if ( NULL == pShader ) break;
  121. D3DDMVertexShader* pVS = (D3DDMVertexShader*)m_pCmdData;
  122. DXGASSERT( pShader->m_OrgDeclSize <= (D3DDM_MAX_VSDECL*4) );
  123. memcpy( pVS->Decl, pShader->m_pOrgDeclaration, pShader->m_OrgDeclSize );
  124. char* pUserData = (char*)(pVS+1);
  125. m_pTgtCtx->CommandBufferSize = sizeof(D3DDMVertexShader);
  126. }
  127. break;
  128. case D3DDM_CMD_GETVERTEXSHADERINST:
  129. {
  130. DWORD Handle = *(DWORD*)m_pCmdData;
  131. if (D3DVSD_ISLEGACY(Handle)) break;
  132. UINT Inst = (Command & 0xffff);
  133. CVShader* pShader = (CVShader*)(pHal->m_pVShaderArray->GetObject(Handle));
  134. if ( NULL == pShader ) break;
  135. CVShaderCode* pSC = pShader->m_pCode;
  136. if (pSC && (Inst < pSC->InstCount()))
  137. {
  138. D3DDMVertexShaderInst* pVSI = (D3DDMVertexShaderInst*)m_pCmdData;
  139. memcpy( pVSI->Inst, pSC->InstTokens(Inst), D3DDM_MAX_VSINSTDWORD*4 );
  140. memcpy( pVSI->InstString, pSC->InstDisasm(Inst), D3DDM_MAX_VSINSTSTRING );
  141. m_pTgtCtx->CommandBufferSize = sizeof(D3DDMVertexShaderInst);
  142. if ( pSC->InstCommentSize(Inst) )
  143. {
  144. memcpy( (void*)(pVSI+1), pSC->InstComment(Inst), 4*pSC->InstCommentSize(Inst) );
  145. m_pTgtCtx->CommandBufferSize += 4*pSC->InstCommentSize(Inst);
  146. }
  147. }
  148. }
  149. break;
  150. case D3DDM_CMD_GETDEVICESTATE:
  151. {
  152. D3DDMDeviceState* pDS = (D3DDMDeviceState*)m_pCmdData;
  153. memcpy( pDS->RenderState, pHal->rstates, 4*D3DHAL_MAX_RSTATES );
  154. for (i=0; i<D3DHAL_TSS_MAXSTAGES; i++)
  155. {
  156. memcpy( pDS->TextureStageState[i],
  157. pHal->tsstates[i], 4*D3DHAL_TSS_STATESPERSTAGE );
  158. }
  159. pDS->VertexShaderHandle = m_pD3DBase->m_dwCurrentShaderHandle;
  160. pDS->PixelShaderHandle = m_pD3DBase->m_dwCurrentPixelShaderHandle;
  161. pDS->MaxVShaderHandle = (UINT)(pHal->m_pVShaderArray->GetSize());
  162. while ( ( pDS->MaxVShaderHandle > 0 ) &&
  163. ( NULL == pHal->m_pVShaderArray->GetObject(pDS->MaxVShaderHandle) ) )
  164. {
  165. pDS->MaxVShaderHandle--;
  166. }
  167. pDS->MaxPShaderHandle = 0;
  168. m_pTgtCtx->CommandBufferSize = sizeof(D3DDMDeviceState);
  169. }
  170. break;
  171. }
  172. return S_OK;
  173. }
  174. ///////////////////////////////////////////////////////////////////////////////
  175. // end