DxilInterpolationMode.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilInterpolationMode.cpp //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #include "dxc/DXIL/DxilInterpolationMode.h"
  10. #include "dxc/Support/Global.h"
  11. namespace hlsl {
  12. //------------------------------------------------------------------------------
  13. //
  14. // InterpolationMode class methods.
  15. //
  16. InterpolationMode::InterpolationMode()
  17. : m_Kind(Kind::Undefined) {
  18. }
  19. InterpolationMode::InterpolationMode(Kind Kind)
  20. : m_Kind(Kind) {
  21. }
  22. InterpolationMode::InterpolationMode(unsigned long long kind) {
  23. m_Kind = (Kind)kind;
  24. if (m_Kind >= Kind::Invalid) {
  25. m_Kind = Kind::Invalid;
  26. }
  27. }
  28. // NoInterpolation, bLinear, bNoperspective, bCentroid, bSample
  29. static const DXIL::InterpolationMode interpModeTab[] = {
  30. DXIL::InterpolationMode::Undefined, // 0 , False , False , False , False , False
  31. DXIL::InterpolationMode::LinearSample, // 1 , False , False , False , False , True
  32. DXIL::InterpolationMode::LinearCentroid, // 2 , False , False , False , True , False
  33. DXIL::InterpolationMode::LinearSample, // 3 , False , False , False , True , True
  34. DXIL::InterpolationMode::LinearNoperspective, // 4 , False , False , True , False , False
  35. DXIL::InterpolationMode::LinearNoperspectiveSample, // 5 , False , False , True , False , True
  36. DXIL::InterpolationMode::LinearNoperspectiveCentroid, // 6 , False , False , True , True , False
  37. DXIL::InterpolationMode::LinearNoperspectiveSample, // 7 , False , False , True , True , True
  38. DXIL::InterpolationMode::Linear, // 8 , False , True , False , False , False
  39. DXIL::InterpolationMode::LinearSample, // 9 , False , True , False , False , True
  40. DXIL::InterpolationMode::LinearCentroid, // 10 , False , True , False , True , False
  41. DXIL::InterpolationMode::LinearSample, // 11 , False , True , False , True , True
  42. DXIL::InterpolationMode::LinearNoperspective, // 12 , False , True , True , False , False
  43. DXIL::InterpolationMode::LinearNoperspectiveSample, // 13 , False , True , True , False , True
  44. DXIL::InterpolationMode::LinearNoperspectiveCentroid, // 14 , False , True , True , True , False
  45. DXIL::InterpolationMode::LinearNoperspectiveSample, // 15 , False , True , True , True , True
  46. DXIL::InterpolationMode::Constant, // 16 , True , False , False , False , False
  47. DXIL::InterpolationMode::Invalid, // 17 , True , False , False , False , True
  48. DXIL::InterpolationMode::Invalid, // 18 , True , False , False , True , False
  49. DXIL::InterpolationMode::Invalid, // 19 , True , False , False , True , True
  50. DXIL::InterpolationMode::Invalid, // 20 , True , False , True , False , False
  51. DXIL::InterpolationMode::Invalid, // 21 , True , False , True , False , True
  52. DXIL::InterpolationMode::Invalid, // 22 , True , False , True , True , False
  53. DXIL::InterpolationMode::Invalid, // 23 , True , False , True , True , True
  54. DXIL::InterpolationMode::Invalid, // 24 , True , True , False , False , False
  55. DXIL::InterpolationMode::Invalid, // 25 , True , True , False , False , True
  56. DXIL::InterpolationMode::Invalid, // 26 , True , True , False , True , False
  57. DXIL::InterpolationMode::Invalid, // 27 , True , True , False , True , True
  58. DXIL::InterpolationMode::Invalid, // 28 , True , True , True , False , False
  59. DXIL::InterpolationMode::Invalid, // 29 , True , True , True , False , True
  60. DXIL::InterpolationMode::Invalid, // 30 , True , True , True , True , False
  61. DXIL::InterpolationMode::Invalid, // 31 , True , True , True , True , True
  62. };
  63. InterpolationMode::InterpolationMode(bool bNoInterpolation, bool bLinear, bool bNoperspective, bool bCentroid, bool bSample) {
  64. unsigned mask = (unsigned)bNoInterpolation << 4;
  65. mask |= ((unsigned)bLinear) << 3;
  66. mask |= ((unsigned)bNoperspective) << 2;
  67. mask |= ((unsigned)bCentroid) << 1;
  68. mask |= ((unsigned)bSample);
  69. m_Kind = interpModeTab[mask];
  70. // interpModeTab is generate from following code.
  71. //m_Kind = Kind::Invalid; // Cases not set below are invalid.
  72. //bool bAnyLinear = bLinear | bNoperspective | bCentroid | bSample;
  73. //if (bNoInterpolation) {
  74. // if (!bAnyLinear) m_Kind = Kind::Constant;
  75. //}
  76. //else if (bAnyLinear) {
  77. // if (bSample) { // warning case: sample overrides centroid.
  78. // if (bNoperspective) m_Kind = Kind::LinearNoperspectiveSample;
  79. // else m_Kind = Kind::LinearSample;
  80. // }
  81. // else {
  82. // if (!bNoperspective && !bCentroid) m_Kind = Kind::Linear;
  83. // else if (!bNoperspective && bCentroid) m_Kind = Kind::LinearCentroid;
  84. // else if ( bNoperspective && !bCentroid) m_Kind = Kind::LinearNoperspective;
  85. // else if ( bNoperspective && bCentroid) m_Kind = Kind::LinearNoperspectiveCentroid;
  86. // }
  87. //}
  88. //else {
  89. // m_Kind = Kind::Undefined;
  90. //}
  91. }
  92. InterpolationMode &InterpolationMode::operator=(const InterpolationMode &o) {
  93. if (this != &o) {
  94. m_Kind = o.m_Kind;
  95. }
  96. return *this;
  97. }
  98. bool InterpolationMode::operator==(const InterpolationMode &o) const {
  99. return m_Kind == o.m_Kind;
  100. }
  101. bool InterpolationMode::IsAnyLinear() const {
  102. return m_Kind < Kind::Invalid && m_Kind != Kind::Undefined && m_Kind != Kind::Constant;
  103. }
  104. bool InterpolationMode::IsAnyNoPerspective() const {
  105. return IsLinearNoperspective() || IsLinearNoperspectiveCentroid() || IsLinearNoperspectiveSample();
  106. }
  107. bool InterpolationMode::IsAnyCentroid() const {
  108. return IsLinearCentroid() || IsLinearNoperspectiveCentroid();
  109. }
  110. bool InterpolationMode::IsAnySample() const {
  111. return IsLinearSample() || IsLinearNoperspectiveSample();
  112. }
  113. const char *InterpolationMode::GetName() const {
  114. switch (m_Kind) {
  115. case Kind::Undefined: return "";
  116. case Kind::Constant: return "nointerpolation";
  117. case Kind::Linear: return "linear";
  118. case Kind::LinearCentroid: return "centroid";
  119. case Kind::LinearNoperspective: return "noperspective";
  120. case Kind::LinearNoperspectiveCentroid: return "noperspective centroid";
  121. case Kind::LinearSample: return "sample";
  122. case Kind::LinearNoperspectiveSample: return "noperspective sample";
  123. default: DXASSERT(false, "invalid interpolation mode"); return "invalid";
  124. }
  125. }
  126. } // namespace hlsl