所以我试图通过反射从我编译的着色器中获取常量缓冲区的数量。可悲的是它没有按预期工作,我不知道为什么。
以下是我如何在 ID3DBlob
中加载着色器代码:
ID3DBlob* vertexBlob;
HRESULT result = D3DReadFileToBlob(vertexShader.c_str(), &vertexBlob);
这就是我得到反射的方式:
ComPtr<ID3D11ShaderReflection> reflection;
HRESULT hr = D3DReflect(shader.code->GetBufferPointer(), shader.code->GetBufferSize(), IID_ID3D11ShaderReflection, reinterpret_cast<void**>(reflection.GetAddressOf()));
if (FAILED(hr)) {
// SOMETHING WENT WRONG;
return (nullptr);
}
D3D11_SHADER_DESC shaderDesc;
reflection->GetDesc(&shaderDesc);
如果我在 Debug 中检查 shaderDesc
,则 ConstantBuffers
变量为 0。
我已经确保对着色器所做的更改得到识别。我添加了另一个输入变量,并且描述中的输入参数数量增加了。
最后是我如何定义常量缓冲区,但我不认为这是问题所在:
cbuffer perObject
{
matrix worldViewProj;
};
struct vertexInput
{
float3 position : POSITION;
float3 color : COLOR;
};
float4 main(vertexInput input) : SV_POSITION
{
return float4(input.position, 1.0f);
}
有没有人知道哪里出了问题?
最佳答案
由于您不在着色器中使用常量缓冲区,因此它可能在编译期间被优化掉了。
暂时改变你的着色器,确保它被使用,然后看看你在反射中得到了什么:
float4 main(vertexInput input) : SV_POSITION
{
return mul(float4(input.position, 1.0f), worldViewProj);
}
关于c++ - D3DReflect 不检测常量缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23878016/