I am trying to share this across multiple effect files:

matrix worldMatrix : register(vs_4_0, b0);
  1. If I set this from one effect file, will it effect every effect file which has the same type of variable assigned to that specific register?
  2. What is the difference between this and the cbuffer struct?

If you bind a constant to one register, it will be there until something binds at the same place or if you bind that spot with null.

My approach of having constant buffer i want to "share" is to have a constant buffer struct in a include file. and then including that file into all the shaders im using. It's convenient and simple.

The difference with a single value and a cbuffer is how you bind the data and how you have to allocate the buffers. if you have a cbuffer, with 128 floats, you have to create a buffer thats equal of that size. while a single value wont let you create a register spot thats of a difference size than that type. Regularly, it's good to have a cbuffer with specific meanings. In other words, having a cbuffer that gets updated every frame, one that gets updated for each material and maybe one that contains some sort of Per second data.

  • \$\begingroup\$ Out of curiosity, will the method above by binding a matrix to a single register work in practice? In other words, if I bind a matrix to a single register will it get updated across multiple shader files? \$\endgroup\$ – bluejamesbond Jan 21 '14 at 14:08
  • \$\begingroup\$ Maybe, Maybe not. it´s hard to tell when it comes to thees things with out proper code and profiling. ( assuming you are reffering to peformance losses ) \$\endgroup\$ – Tordin Jan 21 '14 at 14:09
  • \$\begingroup\$ not necessarily performance, just whether it the bonded matrix will be available in all Effect files. I tried binding the matrix to a register and accessing them from a different effect to no avail. That's why I am wondering if this is actually propagating through all effects. \$\endgroup\$ – bluejamesbond Jan 21 '14 at 16:10
  • \$\begingroup\$ the register slot have to be the same \$\endgroup\$ – Tordin Jan 21 '14 at 16:33
  • \$\begingroup\$ They are and its being set from a different Effect but not working. Does the set need to be different? i.e. do I need to specify what register from c++ code? All I am doing is ID3D10EffectMatrixVariable#SetMatrix from one HLSL. \$\endgroup\$ – bluejamesbond Jan 21 '14 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.