0
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
5
  • \$\begingroup\$ 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 :) \$\endgroup\$
    – Notabene
    Sep 2 '11 at 11:22
  • \$\begingroup\$ @Notabene, oh well, what about using D3DXSHADER_PREFER_FLOW_CONTROL in your D3DXCreateEffect() call, maybe that will stop unrolling? \$\endgroup\$
    – EnoughTea
    Sep 2 '11 at 11:35
  • \$\begingroup\$ Thank for your help. But yes, i'm using it, does not help. \$\endgroup\$
    – Notabene
    Sep 2 '11 at 11:43
  • \$\begingroup\$ @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? \$\endgroup\$
    – EnoughTea
    Sep 2 '11 at 12:18
  • \$\begingroup\$ 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) \$\endgroup\$
    – Notabene
    Sep 4 '11 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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