03-shader-vin-keepalive.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --- a/data/lib/sysresource/shader/include/v2_vpcommon.cgh
  2. +++ b/data/lib/sysresource/shader/include/v2_vpcommon.cgh
  3. @@ -12,7 +12,7 @@
  4. #ifdef _USE_GPROGRAM
  5. #define END_VP_MAIN VOUT_VALUE(instanceID) = gl_InstanceID;}
  6. #else
  7. -#define END_VP_MAIN gl_Position = vfio_position;VOUT_VALUE(instanceID) = gl_InstanceID;}
  8. +#define END_VP_MAIN gl_Position = vfio_position + VIN_KEEPALIVE;VOUT_VALUE(instanceID) = gl_InstanceID;}
  9. #endif
  10. #extension GL_ARB_explicit_attrib_location : enable
  11. @@ -47,6 +47,44 @@
  12. layout(location = 6) in vec4 vin_weights;
  13. #endif
  14. +/* Keep vin_* attributes alive so Mesa's cross-stage DCE cannot mark them
  15. + * inactive (glGetAttribLocation would return -1 -> engine "Vertex Attribute
  16. + * Problem" -> white screen). Each term is scaled by float(drawCount == -9999),
  17. + * a uniform Mesa cannot constant-fold; drawCount is always >= 0 at runtime so
  18. + * the terms are exactly 0.0 and rendering is unaffected. Guarded by the same
  19. + * #ifdefs as the declarations so only declared attributes are referenced. */
  20. +#ifdef _USE_NORMAL
  21. +#define _VKA_N + vin_normal.x
  22. +#else
  23. +#define _VKA_N
  24. +#endif
  25. +#ifdef _USE_NORMALMAP
  26. +#define _VKA_T + vin_tangent.x
  27. +#else
  28. +#define _VKA_T
  29. +#endif
  30. +#ifdef _USE_VP_TEXCOORD0
  31. +#define _VKA_U0 + vin_uv0.x
  32. +#else
  33. +#define _VKA_U0
  34. +#endif
  35. +#ifdef _USE_VP_TEXCOORD1
  36. +#define _VKA_U1 + vin_uv1.x
  37. +#else
  38. +#define _VKA_U1
  39. +#endif
  40. +#ifdef _USE_VP_COLOR
  41. +#define _VKA_C + vin_color.x
  42. +#else
  43. +#define _VKA_C
  44. +#endif
  45. +#ifdef _USE_SKINNING
  46. +#define _VKA_W + vin_weights.x
  47. +#else
  48. +#define _VKA_W
  49. +#endif
  50. +#define VIN_KEEPALIVE vec4((vin_position.x _VKA_N _VKA_T _VKA_U0 _VKA_U1 _VKA_C _VKA_W) * float(drawCount == -9999), 0.0, 0.0, 0.0)
  51. +
  52. /*----------- Outpt --------------*/
  53. #ifdef _USE_GPROGRAM