Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Love the better 4.5 shader error reporting EXCEPT in this special case...

Discussion in 'Shaders' started by metaleap, Jul 7, 2014.

  1. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Always did all shader work in OpenGL so far and thought I should begin sometimes switching over to D3D now I'm seeing some good progress.

    Which gives me a super-cryptical error message that doesn't really immediately forward me to the problematic Cg line in my .shader source file --- here's what I copied from Console:

    Code (csharp):
    1.  
    2. Shader error in ' azSurf_Terra': D3D shader assembly failed
    3. with: (57): error X6077: texld/texldb/texldp/dsx/dsy instructions
    4. with r# as source cannot be used inside dynamic conditional 'if' blocks,
    5. dynamic conditional subroutine calls, or loop/rep with break*.
    6.  
    7. Shader Assembly: ps_3_0
    8. dcl_2d s0
    9. dcl_2d s1
    10. dcl_2d s2
    11. dcl_2d s3
    12. def c9, 0.50000000, 0.00000000, 2.00000000, -1.00000000
    13. def c10, 8.00000000, 2.95000005, 0.00000000, 1.00000000
    14. def c11, 1.95000005, 0.94999999, 0.09997559, 0.00000000
    15. dcl_color0 v0.xyzw
    16. mul r0.xy, v0.xzzw, c6.x
    17. add r0.xy, r0, c9.x
    18. mul r0.xy, r0, c4.w
    19. add r0.xy, r0, c9.x
    20. mul r1.xy, r0, c5.x
    21. texld r1.xyz, r1, s2
    22. mad r1.xyz, r1.xzyw, c9.z, c9.w
    23. mul r2.xyz, r1, c5.y
    24. mov r0.w, c9.y
    25. texldl r1.xyz, r0, s0
    26. mad r1.xyz, r1, c9.z, r2
    27. add r2.xyz, r1, c9.w
    28. dp3 r1.z, r2, c2
    29. dp3 r1.x, r2, c0
    30. dp3 r1.y, r2, c1
    31. dp3 r0.z, r1, r1
    32. rsq r0.z, r0.z
    33. mul r1.xyz, r0.z, r1
    34. mad_pp r0.z, r1, c10.x, c10.x
    35. rsq_pp r0.z, r0.z
    36. mad_pp r0.zw, r0.z, r1.xyxy, c9.x
    37. texld r1.xyz, r0, s1
    38. mov r0.x, c9.y
    39. mov r2.xyz, r1
    40. if_gt c8.z, r0.x
    41. add r0.x, -v0.w, c10.y
    42. cmp r0.x, r0, c10.z, c10.w
    43. add r0.y, -v0.w, c11.x
    44. abs_pp r0.x, r0
    45. add r2.x, -v0.w, c11.y
    46. cmp r0.y, r0, c10.z, c10.w
    47. cmp_pp r0.x, -r0, c10.w, c10.z
    48. mul_pp r1.x, r0, r0.y
    49. abs_pp r0.y, r0
    50. cmp_pp r0.y, -r0, c10.w, c10.z
    51. mul_pp r0.x, r0, r0.y
    52. cmp r2.x, r2, c10.z, c10.w
    53. abs_pp r0.y, r2.x
    54. mul_pp r2.x, r0, r2
    55. cmp_pp r1.xyz, -r1.x, c11.zwzw, c11.wwzw
    56. cmp_pp r0.y, -r0, c10.w, c10.z
    57. cmp_pp r1.xyz, -r2.x, r1, c11.wzww
    58. mul_pp r0.x, r0, r0.y
    59. cmp_pp r1.xyz, -r0.x, r1, c11.zwww
    60. else
    61. rcp r0.x, c8.w
    62. mul r0.xy, v0.xzzw, r0.x
    63. texld r1.xyz, r0, s3
    64. mul r1.xyz, r2, r1
    65. endif
    66. mov_pp r2.y, c7.w
    67. cmp_pp r0.y, -c7.z, r1.w, c7.z
    68. cmp_pp r0.x, -c7.w, r1.w, c7.w
    69. add_pp r0.x, r0, -r0.y
    70. mad_pp r0.x, r1.w, r0, r0.y
    71. add_pp r0.y, r0.x, c10.w
    72. rcp_pp r2.x, r0.y
    73. add_pp r0.y, -r0.x, c10.w
    74. mul_pp r0.y, r0, r2.x
    75. mov_pp r2.x, c7.z
    76. cmp_pp r2.y, -r2, c10.z, c10.w
    77. cmp_pp r2.x, -r2, c10.z, c10.w
    78. mul_pp r2.x, r2, r2.y
    79. cmp_pp r0.x, -r2, r0, -r0.y
    80. mul_pp r0.y, r0.x, r0.x
    81. cmp_pp r2.z, -c7.x, r1.w, c7.x
    82. cmp_pp r2.y, -c7, r1.w, c7
    83. add_pp r2.y, r2, -r2.z
    84. cmp_pp oC2.y, -r2.x, r0.x, r0
    85. mad_pp oC2.x, r1.w, r2.y, r2.z
    86. mov_pp oC0.xyz, r1
    87. mov_pp oC1.xy, r0.zwzw
    88. mov_pp oC0.w, c10
    89. mov_pp oC1.w, c10
    90. mov_pp oC2.w, c10
    91.  
    Looks scary... how am I to know which part of my code does the problematic "texld/texldb/texldp/dsx/dsy" call?

    All my shaders have #pragma target 3.0 and #pragma glsl although this will be ignored in D3D of course.

    Unity editor isn't set to DX11 as this gave weird issues last time I had it on when I worked exclusively in -force-opengl mode (which I still do 90% of the time, other than occasionally checking how D3D works out).

    This might be due to the vertex shader doing a texture fetch but I always use tex2Dlod in there, knowing that normal tex2D isn't recommended/allowed in the vertex shader in D3D.
     
    Last edited: Jul 7, 2014
  2. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Probably not due to my vertex texture fetch, now I get a similarly cryptic message for another Post-Processing shader I wrote in Cg and only tested in GL so far:

    Code (csharp):
    1.  
    2. Shader error in ' azPost_CamDeferred': D3D shader assembly failed
    3. with: (77): error X6077: texld/texldb/texldp/dsx/dsy instructions
    4. with r# as source cannot be used inside dynamic conditional 'if' blocks,
    5.  
     
  3. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    And here's another one! What IS this insanity, does D3D not handle even simple if statements that Cg-as-GLSL can handle or what?

    Code (csharp):
    1.  
    2. Shader error in ' azPost_CamFx': D3D shader assembly failed
    3. with: (78): error X6077: texld/texldb/texldp/dsx/dsy instructions
    4. with r# as source cannot be used inside dynamic conditional 'if'
    5. blocks, dynamic conditional subroutine calls, or loop/rep with break*.
    6. (81): error X6077: texld/texldb/texldp/dsx/dsy instructions with r# as
    7. source cannot be used inside dynamic conditional 'if' blocks, dynamic
    8. conditional subroutine calls, or loop/rep with break*.
    9. (84): error X6077: texld/texldb/texldp/dsx/dsy instructions with r# as
    10. source cannot be used inside dynamic conditional 'if' blocks, dynamic
    11. conditional subroutine calls, or loop/rep with break*.
    12. (199): error X6077: texld/texldb/texldp/dsx/dsy instructions with r# as
    13. source cannot be used inside dynamic conditional 'if' blocks, dynamic
    14. conditional subroutine calls, or loop/rep with break*.
    15. (202): error X6077: texld/texldb/texldp/dsx/dsy instructions with r# as
    16. source cannot be used inside dynamic conditional 'if' blocks, dynamic
    17. conditional subroutine calls, or loop/rep with break*.
    18. (205): error X6077: texld/texldb/texldp/dsx/dsy instructions with r# as
    19. source cannot be used inside dynamic conditional 'if'
     
  4. braaad

    braaad

    Joined:
    Oct 4, 2012
    Posts:
    102
  5. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Thanks @braaad you're definitely onto something.

    Guess I could now wonder why D3D9-HLSL cannot accommodate what GLSL can accommodate.... but then I won't be able to change it anyway. Let's see how I can refactor those shaders..
     
  6. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Problem doesn't occur in DX11 mode though so I guess I'll stick to 11+ in the D3D world. GL is primary platform anyway, DX is only the occasional "let's take a peek just-in-case"...
     
  7. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    This is not 4.5 specific, as far as I can tell.

    What you're seeing is Cg compiler (which we use for d3d9) generating broken code. It does that in some cases, yeah, and we can't really fix that easily (Cg being closed source and not really updated anymore).

    This particular error means that you're doing texture sampling (without explicit derivatives or LOD level) inside a loop or a branch, and that is a hard error on D3D, and undefined behavior on OpenGL. Cg should really report this as an actual compile error, but it chooses to generate broken d3d9 assembly instead :(
     
  8. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Uh-oh and I went back to GL "because it works so well in there". Suppose there's no way to enforce some compiler warnings for GL? I don't loop so it's definitely my ifs. So tricky to determine whether it's dynamic or static branching sometimes (error message implies only dynamic ifs are causing this?) but I'll go over it a few more times...