简体   繁体   English

DirectX11-几何着色器流输出流未定义

[英]DirectX11 - Geometry Shader Stream Output Stream Undefined

I'm trying to create a geometry shader which uses the stream output stage following the outline provided on MSDN: Link 我试图创建一个几何着色器,该几何着色器使用遵循MSDN提供的概述的流输出阶段: 链接

However when trying to do this I get the following error: 但是,当尝试执行此操作时,出现以下错误:

ID3D11Device::CreateGeometryShaderWithStreamOutput: Stream (=3435973836) must be less than or equal to 3.

As far as I'm aware, the only point at which I can define the stream is in the stream output declaration entry, but I've already done this (code below). 据我所知,唯一可以定义流的点是在流输出声明条目中,但是我已经做到了(下面的代码)。

// Reads compiled shader into a buffer
HRESULT result = D3DReadFileToBlob(filename, &geometryShaderBuffer);

D3D11_SO_DECLARATION_ENTRY SODeclarationEntry[3] =
{

    { 0, "POSITION", 0, 0, 3, 0 },
    { 0, "NORMAL", 0, 0, 3, 0 },
    { 0, "TEXCOORD", 0, 0, 3, 0 }

};

// Create the geometry shader from the buffer & SO declaration
result = renderer->CreateGeometryShaderWithStreamOutput(geometryShaderBuffer->GetBufferPointer(), geometryShaderBuffer->GetBufferSize(), SODeclarationEntry, sizeof(SODeclarationEntry),
        NULL, 0, 0, NULL, &streamOutputGeometryShader);

Is there somewhere else where I'm supposed to be defining an output stream? 还有其他我应该定义输出流的地方吗?

The problem here is that you have provided far too large a number for NumEntries so it's reading a bunch of junk entries after the 3 you have defined for pSODeclaration . 这里的问题是,您为NumEntries提供的数字太大了,因此在为pSODeclaration定义了3个之后,它将读取一堆垃圾条目。 That's why the validation error debug output is reporting nonsense values like "Stream (=3435973836)". 这就是为什么验证错误调试输出会报告诸如“流(= 3435973836)”之类的废话值的原因。

result = renderer->CreateGeometryShaderWithStreamOutput(
    geometryShaderBuffer->GetBufferPointer(), geometryShaderBuffer->GetBufferSize(),
    SODeclarationEntry, sizeof(SODeclarationEntry),
    nullptr, 0, 0, nullptr, &streamOutputGeometryShader);

should be: 应该:

result = renderer->CreateGeometryShaderWithStreamOutput(
    geometryShaderBuffer->GetBufferPointer(), geometryShaderBuffer->GetBufferSize(),
    SODeclarationEntry, _countof(SODeclarationEntry),
    nullptr, 0, 0, nullptr, &streamOutputGeometryShader);

Note that if you are working with a different compiler than Microsoft Visual C++, _countof is: 请注意,如果使用的是与Microsoft Visual C ++不同的编译器,则_countof为:

#define _countof(array) (sizeof(array) / sizeof(array[0]))

BTW, this is the kind of bug that static code analysis ( /analyze ) and the SAL annotations that are used for the Windows system headers can find for you: 顺便说一句,这是一种静态代码分析( /analyze )和用于Windows系统标头的SAL批注可以为您找到的错误:

warning C6385: Reading invalid data from 'SODeclarationEntry':  the readable
size is '48' bytes, but '768' bytes may be read.

See Microsoft Docs for more information. 有关更多信息,请参见Microsoft Docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM