我正在尝试使用着色器中的变量反映所有常量缓冲区,但是反射器给出了错误的名称。 着色器:
struct ModelViewProjection
{
matrix MVP;
float a;
};
struct SomeConstBuffer1
{
matrix MVP;
float a;
};
struct SomeConstBuffer2
{
matrix MVP;
float a;
};
ConstantBuffer<ModelViewProjection> cb3 : register(b3);
ConstantBuffer<SomeConstBuffer1> cb4 : register(b4);
ConstantBuffer<SomeConstBuffer2> cb6 : register(b6);
c ++代码:
void Dx12CoreShader::reflectShader(SubShader& shader)
{
ID3D12ShaderReflection* reflection;
ThrowIfFailed(D3DReflect(shader.blob->GetBufferPointer(), shader.blob->GetBufferSize(), IID_ID3D12ShaderReflection, (void**)& reflection));
D3D12_SHADER_DESC desc;
reflection->GetDesc(&desc);
// here ok. desc.ConstantBuffers == 3
for (unsigned int i = 0; i < desc.ConstantBuffers; ++i)
{
ID3D12ShaderReflectionConstantBuffer* buffer = reflection->GetConstantBufferByIndex(i);
D3D12_SHADER_BUFFER_DESC bufferDesc;
buffer->GetDesc(&bufferDesc);
// here ok. bufferDesc.Name == "cb3"
// here wrong! bufferDesc.Variables==1, I expected 2
for (UINT j = 0; j < bufferDesc.Variables; j++)
{
ID3D12ShaderReflectionVariable* var = buffer->GetVariableByIndex(j);
D3D12_SHADER_VARIABLE_DESC varDesc;
var->GetDesc(&varDesc);
// here also wrong.
// I expect "MVP" first but it returns also "cb3"
}
}
}
我的配置:AMD Ryzen 3 2200U和radeon Vega Mobile Gfx。 我究竟做错了什么?这可能是错误吗? 类似的情况也可以在DirectX 11上正常工作。
UPD:我使用所有变量来防止编译器进行优化。
答案 0 :(得分:0)
我固定了。
cbuffer ModelViewProjection : register(b3)
{
matrix MVP;
float a;
};
cbuffer SomeConstBuffer1 : register(b4)
{
matrix MVP1;
float a1;
};
cbuffer SomeConstBuffer2 : register(b6)
{
matrix MVP2;
float a2;
};