2

I have completely re-written this first post to better show what the problem is.

I am using ps v1.4 (highest version I have support for) and keep getting an error.
It happens any time I use any type of function such as cos, dot, distance, sqrt, normalize etc. on something that was passed into the pixelshader.
For example, I need to do "normalize(LightPosition - PixelPosition)" to use a point light in my pixelshader, but normalize gives me an error.
Some things to note-
I can use things like pow, abs, and radians with no error.
There is only an error if it is done on something passed from the vertex shader. (For example I could take the sqrt of a local pixelshader variable with no error)
I get the error from doing a function on ANY variable passed in, even text coords, color, etc.
Inside the vertex shader I can do all of these functions on any variables passed in with no errors, it's only in the pixelshader that I get an error
All the values passing from the vertex to pixel shader are correct, because if I use software processing rather than hardware I get no error and a perfectly lit scene.
Since normalizing the vector is essentially where my error comes form I tried creating my own normalizing function.
I call Norm(LightPosition - PixelPosition) and "Norm" looks like this -

float3 Norm(float3 v)
{
    return v / sqrt(dot(v, v));
}

I still get the error because I guess technically I'm still trying to take a sqrt inside the pixelshader.

The error isn't anything specific, it just says "error in application" on the line where I load my .fx file in C#
I'm thinking it could actually be a compiling error because I have to use such old versions (vs 1.1 and ps 1.4)
When debugged using fxc.exe it tells me "can not map instruction to pixel shader instruction set"

Frobot
  • 1,224
  • 3
  • 16
  • 33
  • What's the error? Is this in the pixel or vertexshader? Are you sure your GPU is 10 years old and only supports 1.1? I don't think these old platforms get tested very much, so it may very well be a compiler error. – Tobias Schlegel Nov 08 '11 at 21:44
  • Every bit of it can be found here http://www.riemers.net/eng/Tutorials/DirectX/Csharp/Series3/The_first_light.php I don't think my GPU is 10 years old but I checked in the DevCaps.VertexShaderVersion and it gives me 1.1. About the error, it is int the pixelshader and it gives me an error on the line where I load my .fx file (in c#) – Frobot Nov 08 '11 at 21:50
  • The error doesn't seem to be anything specific it just says "error in application". After quite a bit more experimenting it seems as though when using v1.1 you can't do sqrt() in a method on a variable that was passed in by that method. Even when using a new variable that you assign the value of the variable in the parameter to, it gives an error. – Frobot Nov 09 '11 at 00:46
  • The reason that `sqrt(dot(a, a))` (for a constant `a`) works is that the compiler precalculates it during the build (constant folding). For a non-constant `v` it would seem the compiler can't convert `sqrt(dot(v, v))` to a valid shader. Shader methods are inlined, so technically the problem is that `v` maps to a register, rather than it being a parameter. You could try using the command-line shader compiler (fxc in the DirectX SDK) to see if you can get a more descriptive error message. – Andrew Russell Nov 09 '11 at 06:07
  • Ok I got the fxc to debug it after a while (the normal fxc doesn't support ps1.x) and it tells me "can not map instruction to pixel shader instruction set" – Frobot Nov 13 '11 at 01:04

1 Answers1

1

Old GPU:s didn't always support any instruction, especially in the pixel shader.

You might get away with a sqrt in the vertex shader but for a so old version (1.1 !!) the fragment shader might be extremely limited.

I.e this might not be a bug.

The work around could be to skip the hlsl and write your own assembler (but you might stumble onto the same problem there) and simulate the sqrt (say with a texture lookup and / or interpolations if you can have 2 textures in 1.0 :-p )

You can of course try to write a sqrt-lookup/interpolation in hlsl but it might be too big too (I don't remember but IIRC 1.1 don't let you write very long shaders).

Valmond
  • 2,897
  • 8
  • 29
  • 49
  • After some more research I do believe it's just not supported. It just seemed hard to believe, because this leaves the pixel shader nearly useless in older versions. – Frobot Nov 22 '11 at 17:27
  • +1 thanks :-) (BTW, a GPU accepting at least 2.0 or 3.0 should be really cheap if you can change yours, ie. not a notebook/laptop) – Valmond Nov 23 '11 at 10:46