CrossCompileOptions.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. namespace Veldrid.SPIRV
  3. {
  4. /// <summary>
  5. /// An object used to control the parameters of shader translation from SPIR-V to some target language.
  6. /// </summary>
  7. public class CrossCompileOptions
  8. {
  9. /// <summary>
  10. /// Indicates whether or not the compiled shader output should include a clip-space Z-range fixup at the end of the
  11. /// vertex shader.
  12. /// If true, then the shader will include code that assumes the clip space needs to be corrected from the
  13. /// "wrong" range into the "right" range for the particular type of shader. For example, if an OpenGL shader is being
  14. /// generated, then the vertex shader will include a fixup that converts the depth range from [0, 1] to [-1, 1].
  15. /// If a Direct3D shader is being generated, then the vertex shader will include a fixup that converts the depth range
  16. /// from [-1, 1] to [0, 1].
  17. /// </summary>
  18. public bool FixClipSpaceZ { get; set; }
  19. /// <summary>
  20. /// Indicates whether or not the compiled shader output should include a fixup at the end of the vertex shader which
  21. /// inverts the clip-space Y value.
  22. /// </summary>
  23. public bool InvertVertexOutputY { get; set; }
  24. /// <summary>
  25. /// Indicates whether all resource names should be forced into a normalized form. This has functional impact
  26. /// on compilation targets where resource names are meaningful, like GLSL.
  27. /// </summary>
  28. public bool NormalizeResourceNames { get; set; }
  29. /// <summary>
  30. /// An array of <see cref="SpecializationConstant"/> which will be substituted into the shader as new constants. Each
  31. /// element in the array will be matched by ID with the SPIR-V specialization constants defined in the shader.
  32. /// </summary>
  33. public SpecializationConstant[] Specializations { get; set; }
  34. /// <summary>
  35. /// Constructs a new <see cref="CrossCompileOptions"/> with default values.
  36. /// </summary>
  37. public CrossCompileOptions()
  38. {
  39. Specializations = Array.Empty<SpecializationConstant>();
  40. }
  41. /// <summary>
  42. /// Constructs a new <see cref="CrossCompileOptions"/>, used to control the parameters of shader translation.
  43. /// </summary>
  44. /// <param name="fixClipSpaceZ">Indicates whether or not the compiled shader output should include a clip-space Z-range
  45. /// fixup at the end of the vertex shader.</param>
  46. /// <param name="invertVertexOutputY">Indicates whether or not the compiled shader output should include a fixup at the
  47. /// end of the vertex shader which inverts the clip-space Y value.</param>
  48. public CrossCompileOptions(bool fixClipSpaceZ, bool invertVertexOutputY)
  49. : this(fixClipSpaceZ, invertVertexOutputY, Array.Empty<SpecializationConstant>())
  50. {
  51. }
  52. /// <summary>
  53. /// Constructs a new <see cref="CrossCompileOptions"/>, used to control the parameters of shader translation.
  54. /// </summary>
  55. /// <param name="fixClipSpaceZ">Indicates whether or not the compiled shader output should include a clip-space Z-range
  56. /// fixup at the end of the vertex shader.</param>
  57. /// <param name="invertVertexOutputY">Indicates whether or not the compiled shader output should include a fixup at the
  58. /// end of the vertex shader which inverts the clip-space Y value.</param>
  59. /// <param name="normalizeResourceNames">Indicates whether all resource names should be forced into a normalized form.
  60. /// This has functional impact on compilation targets where resource names are meaningful, like GLSL.</param>
  61. public CrossCompileOptions(bool fixClipSpaceZ, bool invertVertexOutputY, bool normalizeResourceNames)
  62. : this(fixClipSpaceZ, invertVertexOutputY, normalizeResourceNames, Array.Empty<SpecializationConstant>())
  63. {
  64. }
  65. /// <summary>
  66. /// Constructs a new <see cref="CrossCompileOptions"/>, used to control the parameters of shader translation.
  67. /// </summary>
  68. /// <param name="fixClipSpaceZ">Indicates whether or not the compiled shader output should include a clip-space Z-range
  69. /// fixup at the end of the vertex shader.</param>
  70. /// <param name="invertVertexOutputY">Indicates whether or not the compiled shader output should include a fixup at the
  71. /// end of the vertex shader which inverts the clip-space Y value.</param>
  72. /// <param name="specializations">An array of <see cref="SpecializationConstant"/> which will be substituted into the
  73. /// shader as new constants.</param>
  74. public CrossCompileOptions(bool fixClipSpaceZ, bool invertVertexOutputY, params SpecializationConstant[] specializations)
  75. {
  76. FixClipSpaceZ = fixClipSpaceZ;
  77. InvertVertexOutputY = invertVertexOutputY;
  78. Specializations = specializations;
  79. }
  80. /// <summary>
  81. /// Constructs a new <see cref="CrossCompileOptions"/>, used to control the parameters of shader translation.
  82. /// </summary>
  83. /// <param name="fixClipSpaceZ">Indicates whether or not the compiled shader output should include a clip-space Z-range
  84. /// fixup at the end of the vertex shader.</param>
  85. /// <param name="invertVertexOutputY">Indicates whether or not the compiled shader output should include a fixup at the
  86. /// end of the vertex shader which inverts the clip-space Y value.</param>
  87. /// <param name="normalizeResourceNames">Indicates whether all resource names should be forced into a normalized form.
  88. /// This has functional impact on compilation targets where resource names are meaningful, like GLSL.</param>
  89. /// <param name="specializations">An array of <see cref="SpecializationConstant"/> which will be substituted into the
  90. /// shader as new constants.</param>
  91. public CrossCompileOptions(
  92. bool fixClipSpaceZ,
  93. bool invertVertexOutputY,
  94. bool normalizeResourceNames,
  95. params SpecializationConstant[] specializations)
  96. {
  97. FixClipSpaceZ = fixClipSpaceZ;
  98. InvertVertexOutputY = invertVertexOutputY;
  99. NormalizeResourceNames = normalizeResourceNames;
  100. Specializations = specializations;
  101. }
  102. }
  103. }