Advertisement Jump to content
Sign in to follow this  

D3D12 how to set shader constants (outside of cbuffer)

This topic is 1262 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post

Link to post
Share on other sites

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.

			ID3D12ShaderReflection *reflector = nullptr;
			ThrowIfFailed(D3DReflect(prog->vertexShader.blob->GetBufferPointer(), prog->vertexShader.blob->GetBufferSize(), IID_ID3D12ShaderReflection, (void **)&reflector));

			D3D12_SHADER_DESC descShader;

			for(int i = 0; i < descShader.ConstantBuffers; i++)
				auto global = reflector->GetConstantBufferByIndex(i);

				if(string(desc.Name).find("$Global") != string::npos)
					vout << desc.Name << endl;

					auto var = global->GetVariableByIndex(0);
					vout << descVar.Name << endl;
Edited by mlfarrell00

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!