Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm working on raycaster in HLSL, unfortunately it have to be in DX9. But it cannot be compiled

I did similar raycaster in DX11 and i know that there is always problem with FXC compiler that it tries to unroll loops, this problem can be solved in DX11 by [loop] command before loop, which tells to compile to not unroll loops. Can i do something similar in DX9? I'm using february 2010 compiler.

My loop is not doing any divergent flow control stuff. And i would like to have it to be able to do early out.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I've never had this problem, but I guess you can just make the loop bounds dynamic, so compiler won't be smart enough to unroll it :) Then pass the loop bounds as shader constant when binding.

share|improve this answer
    
No :). It is not smart enough, it is one of biggest problems of fxc compiler, it tries to unroll dynamic loops. At the moment, i solving it by changing compiled assembly by hand, not very productive way :) –  Notabene Sep 2 '11 at 11:22
    
@Notabene, oh well, what about using D3DXSHADER_PREFER_FLOW_CONTROL in your D3DXCreateEffect() call, maybe that will stop unrolling? –  Vigil Sep 2 '11 at 11:35
    
Thank for your help. But yes, i'm using it, does not help. –  Notabene Sep 2 '11 at 11:43
    
@Notabene If you set your loop bound as a static number, maybe lower then your current dynamic variable, will it still unroll? Maybe within your loop you're using something like someTexture.Sample(..., ...) or other gradient calculations which will be moved out of a flow control by compiler? –  Vigil Sep 2 '11 at 12:18
    
Your advices was valid and very on topic. So i +1 and accept the answer. Solution which worked was to compute number of samples on CPU and send it to the shader and use this variable as (for) loop boundary. Touching this variable in shader caused compiler to unroll. D3DXSHADER_PREFER_FLOW_CONTROL is also good advice for anybody trying to solve this problem. (Still it doesn't support early out) –  Notabene Sep 4 '11 at 20:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.