• Advertisement
Sign in to follow this  

HLSL shader, constant float register limitation?

This topic is 3292 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

Hi, In a shader i have a big array (81 values :D) of 3x4 bone matrices in uniform variable (for hardware skinning). The shader compiles with fxc without errors (fxc /Tvs_3_0 /Emain_vp /Epr shader.hlsl But when i try to use it with Ogre, it crashes. I have changed the number values of the big array from 81 to 80 and it works with 80 values in Ogre. That is the begin of the fxc output :
// Parameters:
//
//   float4 $eye_position;
//   row_major float4x4 $invworldmatrix;
//   float4 $light_position;
//   row_major float4x4 $viewProjectionMatrix;
//   row_major float3x4 $worldMatrix3x4Array[81];
//
//
// Registers:
//
//   Name                  Reg   Size
//   --------------------- ----- ----
//   $worldMatrix3x4Array  c0     243
//   $viewProjectionMatrix c249     4
//   $invworldmatrix       c253     3
//   $light_position       c256     1
//   $eye_position         c257     1
//

    vs_3_0
    def c243, 1, 0, 0, 0
    def c244, 0, 1, 0, 0
    def c245, 0, 0, 1, 0
    def c246, 0, 0, 0, 1
    def c247, 4, 0, 1, 81
    def c248, 3, 0, 0, 0
    defi i0, 4, 0, 1, 0
    dcl_position v0

I know that there is a limitation in constant float registers. When you add all constant float register, you obtain a total of 255 in case of 80 bones and a total of 258 in case of 81 bones. In documentation, for vs3.0 model, number of constant float register >= 256 FXC doesn't notify errors. Is it normal?

Share this post


Link to post
Share on other sites
Advertisement
The number of available constants could be more than 256 (the actual number is in the caps). However the minimum for SM3 cards is 256, and I don't know of any cards that actually support more.

The compiler is just allowing any number of constants because you could be making a shader for hardware that does support that many (maybe some new one will support more than 256).

There is a way to make it work for 81 matrices for your code though. Somewhere you have 4 constants:

def c243, 1, 0, 0, 0
def c244, 0, 1, 0, 0
def c245, 0, 0, 1, 0
def c246, 0, 0, 0, 1

If you set up one constant that is 1, 0, 0, 0 and use the appropriate masks (.xyyy, .yxyy, .yyxy, .yyyx) you can get all four values from one constant. That saves 3 constants and means that 81 matrices will fit. It may or may not be easy to persuade the compiler to do things that way, depending on what your hlsl code looks like.

Share this post


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

  • Advertisement