Jump to content
  • Advertisement
Sign in to follow this  
MadrMan

DX11 HLSL semantics for d3d11 on cbuffers and resources

This topic is 3209 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 can't seem to be able to find out which semantics global variables and resources in D3D11 use. I'm looping trough all the variables in a shader by getting a list of all the cbuffers, and then checking each variable in it. D3D11_SHADER_VARIABLE_DESC is what i end up with eventually and it seems to have all kinds of info about the variables being used, except the semantic name. (same thing for the resources) For example:
cbuffer TransformCB
{
	matrix mWorld : World;
	matrix mView : View;
	matrix mProjection : Projection;
	matrix mWVP : WorldViewProjection;
};

Texture2D basetexture : Texture0;

Using the D3D11_SHADER_VARIABLE_DESC I can get the name of the cbuffer, the names of the variables (mWorld, mView, etc) but not World, View, Projection. Any ideas on how to get them? The only reference to semantics i see in the d3d11 reflection structures seems to be in D3D11_SIGNATURE_PARAMETER_DESC.SemanticName but that struct is for the shader input and can't be used for cbuffers/global variables/resources The effect framework (which I'm not using) has ID3DX11Effect::GetVariableBySemantic() so it has to be possible somehow..

Share this post


Link to post
Share on other sites
Advertisement
Semtantics are only attached to stream variables so that D3D can ensure alignment between shader stages. Constant inputs do not use semantics.

No semantics:
- cbuffers
- tbuffers
- textures
- samplers
- UAVs
- Global Variables

Semantics:
- Streamed data from the input assembler or from another shader stage.
- Accepted as an input or output parameter to a shader program.
- Cover data such as position, texture coords, colors, and other attributes.
- Located on per-vertex, per-patch, per-control point, per-primitive, or per-pixel data.

Share this post


Link to post
Share on other sites
Well yes, but it's possible to feed values into those 'No semantics' you listed by checking which semantic is has and manually putting values in.

That is exactly what ID3DX11Effect::GetVariableBySemantic() is for, but since i'm not using the effect framework (or is that something else?) i'd like to know how to do it with just the normal d3d11 functions.

Would i need to write my own shader preprocessor or something? any idea how ID3DX11Effect::GetVariableBySemantic() does it?

[Edited by - MadrMan on October 31, 2009 12:46:15 PM]

Share this post


Link to post
Share on other sites
If you go into the d3d sdk directory and go to:

\Utilities\Source\Effects11

you can see the entire source for the effects framework and see how they implemented it.

Share this post


Link to post
Share on other sites
Looks like that reads it directly from the binary blob.
Presumably d3dx does the exact same as d3dreflect does, but it gives more complete info, and you're stuck with using the effect framework.

Guess I should try to write my own reflect function to somewhat mimic the d3dx behaviour and read it directly from the binary blob. Not exactly pretty but theres a nice explanation in one of the effect headers (EffectBinaryFormat.h to be exact) so i guess its doable.

Would be nice if d3dreflect was a bit more 'complete' though and returned more than just the bare essentials of what it reflected..

Share this post


Link to post
Share on other sites
I found the same issues when I built my D3D11 renderer. Coming from D3D9, I used semantics as a linkage to my engine for all shader parameters, but I couldn't do it in D3D11. I was working with the beta version, and thought the reflection API would be built up a little more for the final release.

Instead of using the sematics I just use better variable names instead. It requires more work but still gets it done.

Share this post


Link to post
Share on other sites
D3D10 and D3D11 use semantics only for stream inputs. The constant inputs can be reflected directly by variable name, as can any other shader variable. Again, Semantics are just for D3D to validate stream inputs between shader stages, or to attach a shader variable to a specific hardware feature. A good question is, if you already have a named constant variable, why give it yet another name? Seems that it just adds an extra level of complications. I'm not as familiar with the D3D9 Effects system, but in this area there may well be more differences between D3D9, and D3D10+. I suggest looking over more of the API and reviewing the differences between the shader models as you will find that there is plenty of information available in reflection and in Effects to know everything about a constant input, including type, var var name, binding location, default value, etc.

If you need more, you can look at the annotation system which lets you attach arbitrary meta data to any reflectable variable.

Share this post


Link to post
Share on other sites
Jason Z:
Good idea that, using the variable names is probably what I'm gonna do too, as it requires barely any change and if the semantics are ever added to the reflection then it should be easy to change it back.

DieterVW:
It's nice to be able to call a texture a 'texNormal' in the shader to make it clear its used as a normal map and give it a semantic 'Texture2'.
Then the renderer can identify the texNormal using the semantic and you wouldn't need to name the texture 'Texture2', as 'texNormal' is a lot more clear to whoever reads the shader. Using 'texNormal' as an identifier wouldn't work so much because then the renderer would have to be written in a very specific way for the shaders.

Using annotations would be a possibility, but unless I've overlooked them it seems they also can't be reflected?..

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!