• Advertisement
Sign in to follow this  

D3D12 how to set shader constants (outside of cbuffer)

This topic is 987 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
Advertisement

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;
				}
			}
		}
Edited by mlfarrell00

Share this post


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

  • Advertisement