• 15
• 15
• 11
• 9
• 10

# [solved] [dx10] weird StageTexture-Map() failure

This topic is 3815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, [dx10 Aug2007, hlsl fx_4_0, vs2005, vista 32bit, geforce6800gtx with driver 7.15.11.6369 at Sept.11th 2007] I use GS to stream out to a buffer. I initialize the buffer as -1s. I draw multiple times, each time SO results are appended to the buffer. At last, i copy back results to the cpu. But when i step debug to the last line in below code, it stops for about 2 seconds, then the screen blackout for 2 seconds, then vista pops up a msg "display driver stopped responding and has recovered". Then i can go on step down, but now I got all-0s in pBits, not as it should be. The SO amount is not big, < 1M Bytes. What are possible reasons? Thanks for guesses!
	//////////////////////////////////////////////////////////////////////////output SO buf
ID3D10Buffer* pBuf = NULL;
D3D10_BUFFER_DESC descBuf;
descBuf.ByteWidth = N;
descBuf.Usage = D3D10_USAGE_DEFAULT;
descBuf.BindFlags = D3D10_BIND_STREAM_OUTPUT;
descBuf.CPUAccessFlags = 0;
descBuf.MiscFlags = 0;
V(g_pd3dDevice->CreateBuffer(&descBuf, NULL, &pBuf));
/////////////////////////////////////////////////////////////////////////for preset and readback
ID3D10Buffer* pStagingTest = NULL;
D3D10_BUFFER_DESC stageDesc = descBuf;
stageDesc.Usage = D3D10_USAGE_STAGING;
stageDesc.BindFlags = 0;
stageDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;
V(g_pd3dDevice->CreateBuffer(&stageDesc, NULL, &pStagingTest));
//reset buf as -1
void* pFoo;
V(pStagingTest->Map(D3D10_MAP_WRITE, 0, &pFoo));
UCHAR* pFooo = (UCHAR*)pFoo;
memset(pFooo, 0xff, descBuf.ByteWidth);	//set -1
pStagingTest->Unmap();
g_pd3dDevice->CopyResource(pBuf, pStagingTest);
//////////////////////////////////////////////////////////////////////////draw
UINT offset = 0;
g_pd3dDevice->SOSetTargets( 1, &pBuf, &offset);
for(int blockIdx = 0; blockIdx < nBlock; ++blockIdx)
{
//...
D3D10_TECHNIQUE_DESC techDesc;
g_pTechnique->GetDesc( &techDesc );
for( UINT p = 0; p < techDesc.Passes; ++p )
{
g_pTechnique->GetPassByIndex(p)->Apply(0);
g_pd3dDevice->Draw(n, 0);
}
}
//////////////////////////////////////////////////////////////////////////copy back
ID3D10Buffer  *const pNullBuf[1] = {NULL};
g_pd3dDevice->SOSetTargets( 1, pNullBuf, &offset);

g_pd3dDevice->CopyResource(pStagingTest, pBuf);	//if we don't reSetSOTarget,  then SO will continuously append to it
void* pBits;
pStagingTest->Map(D3D10_MAP_READ, 0, &pBits);	//here we got blackout!

[Edited by - yk_cadcg on October 14, 2007 9:05:05 AM]

##### Share on other sites
After a driver reset your buffers are cleared and the device is lost. Therefore the 0 filled memory is normal in this case.

Am not sure why your driver runs in a timeout but everything you do is queue able up to the Map call of the staging buffer. The Map force a sync and if the GPU need to long to reach the sync point in the queue the call will timeout and force the driver to reset. Adding some querys could improve the situation.

##### Share on other sites
Thanks Demirug,
i waited and waited before stepping through the last line, i thought the time i waited was long enough for the GPU to finalize anything...
i used queries, either D3D10_QUERY_SO_STATISTICS or D3D10_QUERY_SO_OVERFLOW_PREDICATE would fail on pQuery->End();, with the same problem description.
I find that if the workset is small enough, which means less and smaller cbuffers (i SCAN cbuffer aggressively in GS, then SO matched ones out to pBuf), then then won't fail. I don't know why GS SO + cbuffer would cause failure, since I have succeeded on render-to-texture + cbuffer on the same workset. i.e., once i changed PS render2texture to GS SO, it wouldn't work.

thanks.
Quote:
 Original post by DemirugAfter a driver reset your buffers are cleared and the device is lost. Therefore the 0 filled memory is normal in this case.Am not sure why your driver runs in a timeout but everything you do is queue able up to the Map call of the staging buffer. The Map force a sync and if the GPU need to long to reach the sync point in the queue the call will timeout and force the driver to reset. Adding some querys could improve the situation.

[Edited by - yk_cadcg on October 14, 2007 1:01:01 AM]

##### Share on other sites
AFAIK the time out check is done per command buffer. You can try adding a Flush after each draw to force the driver to fill one command buffer per draw call.

##### Share on other sites
the flush also hangs, thanks!
and I'm sorry that i find the problem may lie in my aggressive scanning cbuffer in GS, which is still developing, not as developed as PS.

Quote:
 Original post by DemirugAFAIK the time out check is done per command buffer. You can try adding a Flush after each draw to force the driver to fill one command buffer per draw call.