Archived

This topic is now archived and is closed to further replies.

HLSL comparison expression problem

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

float4 pow; coords = tex2D(Sampler, Tex); pow = tex2D(Sampler_Power, coords.ar); if(pow.a == 1.0) // error here { // do something } when doing the comparison shown above in dx effect editor, the editor registers an error in the effect file and doesn''t compile. however when using variables that are explicitly assigned (ex: pow.a = 1.0) and then using these variables within a comparison expression, no error occurs. does anybody know why this is so? I ran the code using Microsoft''s Effect Editor version 4.09.00.0900 which is included in the DirectX 9.0 SDK and compiled using ps_2_0. My Video Card is a Geforce FX 5200. cheers!

Share this post


Link to post
Share on other sites
I know nought about HLSL, but could it be the compiler being clever and telling you that (pow.a == 1.0) will almost never be true due to floating point imprecisions?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think this is dynamic branching, which isn''t supported in shader 2.0, but will be in 3.0.

This is why your explicitly assigned value does work, since the compiler can see it is a non-changing value, so not dynamic.

Cheers,
- John

Share this post


Link to post
Share on other sites
quote:
Original post by superpig
How about telling us what the error is?


effect edit does not say what the error is..
it only displays a red message on the render window saying that there is an 'ERROR IN EFFECT FILE'


dynamic branching.. so is there any way i could go around the problem using ps_2_0?

[edited by - mir88i on February 20, 2004 10:53:20 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
I think this is dynamic branching, which isn''t supported in shader 2.0, but will be in 3.0.

This is why your explicitly assigned value does work, since the compiler can see it is a non-changing value, so not dynamic.

Cheers,
- John

This code would be better implemented on a GPU that had dynamic branching, but that is not required.

The shader compiler will translate this into a "cmp" instruction. What will happen is that both paths (in and outside the "if" statement) will be executed. Then the final result will be chosen by using the "cmp" instruction.

To get a better idea of what the error actually is, use the command-line shader compiler "fxc" that comes with the DX SDK. If you''re using the Summer Update, you can find the fxc compiler in C:\DX90SDK\Utilities

neneboricua

Share this post


Link to post
Share on other sites