views:

328

answers:

1

Hi,

I'm trying to read the output from a geometry shader which is using stream-output to output to a buffer.

The output buffer used by the geometry shader is described like this:

D3D10_BUFFER_DESC vbdesc = 
{ 
    numPoints * sizeof( MESH_VERTEX ), 
    D3D10_USAGE_DEFAULT, 
    D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_STREAM_OUTPUT, 
    0, 
    0 
};
V_RETURN( pd3dDevice->CreateBuffer( &vbdesc, NULL, &g_pDrawFrom ) );

The geometry shader creates a number of triangles based on a single point (at max 12 triangles per point), and if I understand the SDK correctly I have to create a staging resource in order to read the output from the geometry shader on the CPU.

I have declared another buffer resource (this time setting the STAGING flag) like this:

D3D10_BUFFER_DESC sbdesc = 
{ 
    (numPoints * (12*3)) * sizeof( VERTEX_STREAMOUT ), 
    D3D10_USAGE_STAGING, 
    NULL, 
    D3D10_CPU_ACCESS_READ, 
    0 
};
V_RETURN( pd3dDevice->CreateBuffer( &sbdesc, NULL, &g_pStaging ) );

After the first draw call of the application the geometry shader is done creating all triangles and can be drawn. However, after this first draw call I would like to be able to read the vertices output by the geometry shader.

Using the buffer staging resource I'm trying to do it like this (right after the first draw call):

pd3dDevice->CopyResource(g_pStaging, g_pDrawFrom]); 
pd3dDevice->Flush(); 

void *ptr = 0;   
HRESULT hr = g_pStaging->Map( D3D10_MAP_READ, NULL, &ptr ); 
if( FAILED( hr ) ) 
    return hr; 
VERTEX_STREAMOUT *mv = (VERTEX_STREAMOUT*)ptr; 
g_pStaging->Unmap();

This compiles and doesn't give any errors at runtime. However, I don't seem to be getting any output.

The geometry shader outputs the following:

struct VSSceneStreamOut 
{ 
    float4 Pos  : POS; 
    float3 Norm : NORM; 
    float2 Tex  : TEX;   
};

and the VERTEX_STREAMOUT is declared like this:

struct VERTEX_STREAMOUT 
{ 
    D3DXVECTOR4 Pos; 
    D3DXVECTOR3 Norm; 
    D3DXVECTOR2 Tex; 
};

Am I missing something here?

+1  A: 

Problem solved by creating the staging resource buffer like this:

D3D10_BUFFER_DESC sbdesc;
ZeroMemory( &sbdesc, sizeof(sbdesc) );
g_pDrawFrom->GetDesc( &sbdesc );
sbdesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
sbdesc.Usage = D3D10_USAGE_STAGING;
sbdesc.BindFlags = 0;
sbdesc.MiscFlags = 0;

V_RETURN( pd3dDevice->CreateBuffer( &sbdesc, NULL, &g_pStaging ) );

Problem was with the ByteWidth.

Tchami