texture2DMS-to-texture2D.txt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. "Texture2DMS < float4 > PassSrg_m_texture0ms : register ( t0 , space0 ) ;"
  2. "Texture2D < float4 > PassSrg_m_texture1 : register ( t1 , space0 ) ;"
  3. "Texture2DMS < float4 > PassSrg_m_texture2ms : register ( t2 , space0 ) ;"
  4. "Texture2DMSArray < float4 > PassSrg_m_textureArray0ms : register ( t3 , space0 ) ;"
  5. "Texture2DArray < float4 > PassSrg_m_textureArray1 : register ( t4 , space0 ) ;"
  6. "float4 PassSrg_Load ( int2 texelLoc , int2 texelLocDelta , int element , int sampleIndex )"
  7. "{"
  8. "float4 color = float4 ( 0 , 0 , 0 , 0 ) ;"
  9. "color += :: PassSrg_m_texture0ms . Load ( texelLoc , sampleIndex ) ;"
  10. "color -= :: PassSrg_m_texture0ms . Load ( texelLoc + texelLocDelta , sampleIndex + sampleIndex ) ;"
  11. "color += :: PassSrg_m_texture0ms . Load ( texelLoc + texelLocDelta , sampleIndex + sampleIndex , int2 ( 0 , 2 ) ) ;"
  12. "color -= :: PassSrg_m_texture1 . Load ( int3 ( texelLoc , 0 ) ) ;"
  13. "color += :: PassSrg_m_texture1 . Load ( int3 ( texelLoc , 1 ) ) ;"
  14. "color -= :: PassSrg_m_texture2ms . Load ( texelLoc - 2 . 0 * texelLocDelta , sampleIndex + 1 , int2 ( 1 , 1 ) ) ;"
  15. "color += :: PassSrg_m_textureArray0ms . Load ( int3 ( texelLoc , element ) , sampleIndex / 2 ) - :: PassSrg_m_textureArray1 . Load ( int4 ( texelLoc , element , 3 ) ) ;"
  16. "return color ;"
  17. "}"
  18. "float2 PassSrg_GetSamplePosition ( int sampleIndex )"
  19. "{"
  20. "return :: PassSrg_m_texture0ms . GetSamplePosition ( 2 * sampleIndex ) + :: PassSrg_m_texture2ms . GetSamplePosition ( sampleIndex ) + :: PassSrg_m_textureArray0ms . GetSamplePosition ( ( sampleIndex + 7 ) / 3 ) ;"
  21. "}"
  22. "void PassSrg_GetDimensions ( out uint width , out uint height , out uint elements , out uint numSamples )"
  23. "{"
  24. "uint tmpWidth ;"
  25. "uint tmpHeight ;"
  26. "uint tmpElements ;"
  27. "uint tmpNumSamples ;"
  28. "width = 0 ;"
  29. "height = 0 ;"
  30. "elements = 0 ;"
  31. "numSamples = 0 ;"
  32. ":: PassSrg_m_texture0ms . GetDimensions ( tmpWidth , tmpHeight , tmpNumSamples ) ;"
  33. "width += tmpWidth ;"
  34. "height += tmpHeight ;"
  35. "numSamples += tmpNumSamples ;"
  36. ":: PassSrg_m_texture1 . GetDimensions ( tmpWidth , tmpHeight ) ;"
  37. "width += tmpWidth ;"
  38. "height += tmpHeight ;"
  39. ":: PassSrg_m_texture2ms . GetDimensions ( tmpWidth , tmpHeight , tmpNumSamples ) ;"
  40. "width += tmpWidth ;"
  41. "height += tmpHeight ;"
  42. "numSamples += tmpNumSamples ;"
  43. ":: PassSrg_m_textureArray0ms . GetDimensions ( tmpWidth , tmpHeight , tmpElements , tmpNumSamples ) ;"
  44. "width += tmpWidth ;"
  45. "height += tmpHeight ;"
  46. "elements += tmpElements ;"
  47. "numSamples += tmpNumSamples ;"
  48. ":: PassSrg_m_textureArray1 . GetDimensions ( tmpWidth , tmpHeight , tmpElements ) ;"
  49. "width += tmpWidth ;"
  50. "height += tmpHeight ;"
  51. "elements += tmpElements ;"
  52. "width /= 5 ;"
  53. "height /= 5 ;"
  54. "elements /= 2 ;"
  55. "numSamples /= 3 ;"
  56. "}"
  57. "float4 Load ( int2 texelLoc , int2 texelLocDelta , int element , int sampleIndex , Texture2DMS < float4 > tex0ms , Texture2D < float4 > tex1 , Texture2DMS < float4 > tex2ms , Texture2DMSArray < float4 > texArray0ms , Texture2DArray < float4 > texArray1 )"
  58. "{"
  59. "float4 color = float4 ( 0 , 0 , 0 , 0 ) ;"
  60. "color += tex0ms . Load ( texelLoc , sampleIndex ) ;"
  61. "color -= tex0ms . Load ( texelLoc + texelLocDelta , sampleIndex + sampleIndex ) ;"
  62. "color += tex0ms . Load ( texelLoc + texelLocDelta , sampleIndex + sampleIndex , int2 ( 0 , 2 ) ) ;"
  63. "color -= tex1 . Load ( int3 ( texelLoc , 0 ) ) ;"
  64. "color += tex1 . Load ( int3 ( texelLoc , 1 ) ) ;"
  65. "color -= tex2ms . Load ( texelLoc - 2 . 0 * texelLocDelta , sampleIndex + 1 , int2 ( 1 , 1 ) ) ;"
  66. "color += texArray0ms . Load ( int3 ( texelLoc , element ) , sampleIndex / 2 ) - texArray1 . Load ( int4 ( texelLoc , element , 3 ) ) ;"
  67. "return color ;"
  68. "}"
  69. "struct VSOutput"
  70. "{"
  71. "float4 m_position : SV_Position ;"
  72. "float2 m_texCoord : TEXCOORD0 ;"
  73. "} ;"
  74. "struct PSOutput"
  75. "{"
  76. "float4 m_color : SV_Target0 ;"
  77. "} ;"
  78. ":: PSOutput PSMain ( :: VSOutput IN , in uint sampleIndex : SV_SampleIndex )"
  79. "{"
  80. "PSOutput OUT ;"
  81. "int2 texelCoord = int2 ( IN . m_position . xy ) ;"
  82. "float4 color1 = :: PassSrg_Load ( texelCoord , int2 ( 0 , 0 ) , 1 , sampleIndex ) ;"
  83. "float4 color2 = Load ( texelCoord , int2 ( 0 , 0 ) , 1 , sampleIndex , :: PassSrg_m_texture0ms , :: PassSrg_m_texture1 , :: PassSrg_m_texture2ms , :: PassSrg_m_textureArray0ms , :: PassSrg_m_textureArray1 ) ;"
  84. "float2 samplePos = :: PassSrg_GetSamplePosition ( sampleIndex ) ;"
  85. "uint width ;"
  86. "uint height ;"
  87. "uint elements ;"
  88. "uint numSamples ;"
  89. ":: PassSrg_GetDimensions ( width , height , elements , numSamples ) ;"
  90. "if ( ( samplePos . x == samplePos . y ) && ( width == height ) && ( elements != numSamples ) ) {"
  91. "OUT . m_color = color1 ;"
  92. "} else {"
  93. "OUT . m_color = color2 ;"
  94. "} return OUT ;"
  95. "}"
  96. ":: PSOutput PSMainCoverage ( :: VSOutput IN , inout uint coverage : SV_Coverage )"
  97. "{"
  98. "PSOutput OUT ;"
  99. "int2 texelCoord = int2 ( IN . m_position . xy ) ;"
  100. "uint width ;"
  101. "uint height ;"
  102. "uint elements ;"
  103. "uint numSamples ;"
  104. ":: PassSrg_GetDimensions ( width , height , elements , numSamples ) ;"
  105. "for ( uint sampleIndex = 0 ;"
  106. "sampleIndex < numSamples ;"
  107. "++ sampleIndex ) {"
  108. "if ( ! ( coverage & ( 1 < < sampleIndex ) ) ) {"
  109. "continue ;"
  110. "} float4 color1 = :: PassSrg_Load ( texelCoord , int2 ( 0 , 0 ) , 1 , sampleIndex ) ;"
  111. "float4 color2 = Load ( texelCoord , int2 ( 0 , 0 ) , 1 , sampleIndex , :: PassSrg_m_texture0ms , :: PassSrg_m_texture1 , :: PassSrg_m_texture2ms , :: PassSrg_m_textureArray0ms , :: PassSrg_m_textureArray1 ) ;"
  112. "float2 samplePos = :: PassSrg_GetSamplePosition ( sampleIndex ) ;"
  113. "if ( ( samplePos . x == samplePos . y ) && ( width == height ) && ( elements != numSamples ) ) {"
  114. "OUT . m_color += color1 ;"
  115. "coverage &= ~ ( 1 < < sampleIndex ) ;"
  116. "} else {"
  117. "OUT . m_color -= color2 ;"
  118. "} } return OUT ;"
  119. "}"
  120. "struct VSOutputWithSampleIndex"
  121. "{"
  122. "float4 m_position : SV_Position ;"
  123. "float2 m_texCoord : TEXCOORD0 ;"
  124. "uint m_sampleIndex : SV_SampleIndex ;"
  125. "} ;"
  126. ":: PSOutput PSMain2 ( :: VSOutputWithSampleIndex IN )"
  127. "{"
  128. "PSOutput OUT ;"
  129. "int2 texelCoord = int2 ( IN . m_position . xy ) ;"
  130. "float4 color1 = :: PassSrg_Load ( texelCoord , int2 ( 0 , 0 ) , 1 , IN . m_sampleIndex ) ;"
  131. "float4 color2 = Load ( texelCoord , int2 ( 0 , 0 ) , 1 , IN . m_sampleIndex , :: PassSrg_m_texture0ms , :: PassSrg_m_texture1 , :: PassSrg_m_texture2ms , :: PassSrg_m_textureArray0ms , :: PassSrg_m_textureArray1 ) ;"
  132. "float2 samplePos = :: PassSrg_GetSamplePosition ( IN . m_sampleIndex ) ;"
  133. "uint width ;"
  134. "uint height ;"
  135. "uint elements ;"
  136. "uint numSamples ;"
  137. ":: PassSrg_GetDimensions ( width , height , elements , numSamples ) ;"
  138. "if ( ( samplePos . x == samplePos . y ) && ( width == height ) && ( elements != numSamples ) ) {"
  139. "OUT . m_color = color1 ;"
  140. "} else {"
  141. "OUT . m_color = color2 ;"
  142. "} return OUT ;"
  143. "}"