从 CPU 上的几何着色器读取输出

发布于 2024-08-04 03:00:50 字数 1527 浏览 7 评论 0原文

我正在尝试从使用流输出输出到缓冲区的几何着色器读取输出。

几何着色器使用的输出缓冲区是这样描述的:

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 ) );

几何着色器基于单个点创建许多三角形(每个点最多 12 个三角形),如果我正确理解 SDK,我必须在为了读取 CPU 上几何着色器的输出。

我已经声明了另一个缓冲区资源(这次设置了 STAGING 标志),如下所示:

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 ) );

在应用程序的第一次绘制调用之后,几何着色器已完成创建所有三角形并可以绘制。但是,在第一次绘制调用之后,我希望能够读取几何着色器输出的顶点。

使用缓冲区暂存资源,我尝试这样做(在第一次绘制调用之后):

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(); 

这会编译并且在运行时不会给出任何错误。但是,我似乎没有得到任何输出。

几何着色器输出以下内容:

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

VERTEX_STREAMOUT 声明如下:

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

我在这里遗漏了什么吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听闻余生 2024-08-11 03:00:50

通过创建如下所示的暂存资源缓冲区解决了问题:

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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文