[HLSL] Invalid const register num

Started by
3 comments, last by Silicon Munky 15 years, 5 months ago
Hi guys, I'm trying to play with arrays for dynamic lights in HLSL but am coming across this problem in my HLSL:
Quote: Error (209): error X5589: Invalid const register num: 32. Max allowed is 31.
this is my HLSL
Quote: PixelToFrame MeshPixelShader(VS_OUTPUT PSIn) { PixelToFrame Output = (PixelToFrame)0; float DiffuseLightingFactor = 0; for (int i=0; i<xNumLights; i++) { DiffuseLightingFactor += DotProduct(xLightPos, PSIn.Pos3D, PSIn.Normal); } float4 OutColor; OutColor = tex2D(ColoredTextureSampler, PSIn.Tex0) * DiffuseLightingFactor; Output.Color = OutColor; return Output; }
the strange thing is that the error is coming up for line:
Quote: OutColor = tex2D(ColoredTextureSampler, PSIn.Tex0) * DiffuseLightingFactor;
this is how I am registering my light variables at the top of my HLSL
Quote: static const int MAX_LIGHTS = 26; float4 xLightPos[MAX_LIGHTS]; int xNumLights = 0;
I don't understand where it's getting 32 from and why that line instead of my for loop which is obviously where it's falling down because that's where the array is, it's quite obviously something stupid that I'm doing through my lack of understanding of HLSL. Thanks guys, Andy
Advertisement
Wow same thing just happened to me but the error i get is

error X5589: Invalid const register num: 34. Max allowed is 31.

Does it have something to do with the number of instructions you can have?

I'm trying to run different lights at the same time through my fx file.
Yeah i think it is something to do with the number of commands you run in HLSL. I changed from version 2 to version 3 and now the error doesn't appear.

if you look on wiki it says that in shader version 2 max number of constant registers is 32 while in shader version 3 it is 224.

What the constant registers is something i'm not so clear on.
Sounds like you are compiling your shader to too low of a version. Pixel and Vertex shader model 3 support 256 constant registers I believe. Pixel shader model 2 only has 32 constant registers I believe.
Quote:Original post by hotpixel
Quote:
static const int MAX_LIGHTS = 26;
float4 xLightPos[MAX_LIGHTS];
int xNumLights = 0;


This array is taking up 26 of the constants. Temp variables used in the shader code also take up your constant registers too.

This topic is closed to new replies.

Advertisement