I'm using angle to automatically translate my GLSL shader code for use in a D3D12 engine.
I already know how to update constant buffers from the new API.
Where I am stuck is how to get at variables that look like this:
uniform float4 someVar : register c0;
From the D3D12 API
Does anybody know how I can do this? How do I populate "c" variables from DirectX 12?
Edit: am I right to believe these go into the "$global" c buffer following the same packing rules?
D3D12 how to set shader constants (outside of cbuffer)
Posting this to help others who land here with a similar problem
I was right in suspecting one global c buffer.
The following code allows me to reliably determine the cbuffer index of the global buffer.
if(shadersBuilt[0])
{
ID3D12ShaderReflection *reflector = nullptr;
ThrowIfFailed(D3DReflect(prog->vertexShader.blob->GetBufferPointer(), prog->vertexShader.blob->GetBufferSize(), IID_ID3D12ShaderReflection, (void **)&reflector));
D3D12_SHADER_DESC descShader;
ThrowIfFailed(reflector->GetDesc(&descShader));
for(int i = 0; i < descShader.ConstantBuffers; i++)
{
auto global = reflector->GetConstantBufferByIndex(i);
D3D12_SHADER_BUFFER_DESC desc;
ThrowIfFailed(global->GetDesc(&desc));
if(string(desc.Name).find("$Global") != string::npos)
{
vout << desc.Name << endl;
auto var = global->GetVariableByIndex(0);
D3D12_SHADER_VARIABLE_DESC descVar;
ThrowIfFailed(var->GetDesc(&descVar));
vout << descVar.Name << endl;
}
}
}
I am still wondering why you want your variable outside of the constant buffer, we have these cbuffers to efficiently update our constants?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement