Shader Register B6 vs B5 - cross-talk?

Today, we were experiencing some crazy behavior in Shader, seeing the uniform variables being overwritten by some outside force. It would work for a while, but then would start messing up reliably after about 30 seconds of panning around our map.

After trying everything else, we finally figured out that changing “register(b6)” to “register(b5)” worked, miraculously (and we see no other side-effects yet from this).

#ifdef COMPILEPS
cbuffer CustomPS : register(b5) <== changing this from (b6) to (b5) FIXES the issue.
{
bool cShowRelief; <== this parameter alone GOES HAYWIRE, sporadically. (gets overwritten?)
float cAlpha;
float cOwnshipAltitudeFt;
float cAltThreshWarn;
float cAltThreshDanger;
}
#endif

Questions:

  1. Is there any reason why we can’t/shouldn’t use register b5?
  2. Does anyone have any clues as to why register b6 could have some sort of cross-talk/overwriting occurring?

Update, the following change ALSO fixes our issue, combining the final two uniforms into a float2, as follows:

#ifdef COMPILEPS
cbuffer CustomPS : register(b6)
{
bool cShowRelief;
float cAlpha;
float cOwnshipAltitudeFt;
float2 cThreshHolds; <=== combined cAltThreshWarn/Danger into a float2, also fixes this.
}
#endif

This is making no sense to us. Anyone got any clues?

Luckily this final workaround does work, so we’re going to “go with it”.

If we ignore a possibility of driver bug messing up with packing bool into uniform buffer… I don’t know. Perhaps Urho messes up parsing such layout, I dunno.
It’s hard to tell without actual GPU debugging (I prefer Visual Studio debugger, which is still quite trash)

Personally I would have just avoided using bool uniforms alltogether. You have floats and integers.

1 Like