查看DX10中Buffer数据
简单来说需要先copyResources至新Buffer中,再Map,文档详见:Copying and Accessing Resource Data (Direct3D 10).
新Buffer的创建如下:(其中RainVertex为自定义的顶点格式)
// 测试CPU读取Streamoutput结果 [2/2/2012 dell] D3D10_BUFFER_DESC staginDESC; ZeroMemory(&staginDESC, sizeof(staginDESC)); staginDESC.ByteWidth = sizeof(RainVertex) * g_numRainVertices;; staginDESC.CPUAccessFlags = D3D10_CPU_ACCESS_READ; staginDESC.Usage = D3D10_USAGE_STAGING; staginDESC.BindFlags = 0; staginDESC.MiscFlags = 0; V_RETURN(pd3dDevice->CreateBuffer(&staginDESC, NULL, &g_pCPUAccess));
拷贝操作如下:
// 测试streamOutput结果 [2/2/2012 dell] pd3dDevice->CopyResource(g_pCPUAccess, g_pParticleStreamTo); void* mapSubData; HRESULT hr; hr = g_pCPUAccess->Map(D3D10_MAP_READ,0, (void**)&mapSubData); RainVertex *pBoolArr=(RainVertex*)mapSubData; g_pCPUAccess->Unmap();
DirectX SDK BasicComputer11 demo中也有示例:
//-------------------------------------------------------------------------------------- // Create a CPU accessible buffer and download the content of a GPU buffer into it // This function is very useful for debugging CS programs //-------------------------------------------------------------------------------------- ID3D11Buffer* CreateAndCopyToDebugBuf( ID3D11Device* pDevice, ID3D11DeviceContext* pd3dImmediateContext, ID3D11Buffer* pBuffer ) { ID3D11Buffer* debugbuf = NULL; D3D11_BUFFER_DESC desc; ZeroMemory( &desc, sizeof(desc) ); pBuffer->GetDesc( &desc ); desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.Usage = D3D11_USAGE_STAGING; desc.BindFlags = 0; desc.MiscFlags = 0; if ( SUCCEEDED(pDevice->CreateBuffer(&desc, NULL, &debugbuf)) ) { #if defined(DEBUG) || defined(PROFILE) debugbuf->SetPrivateData( WKPDID_D3DDebugObjectName, sizeof( "Debug" ) - 1, "Debug" ); #endif pd3dImmediateContext->CopyResource( debugbuf, pBuffer ); } return debugbuf; }
浙公网安备 33010602011771号