No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StpPreTaa.compute 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #pragma kernel StpPreTaa
  2. #pragma multi_compile _ ENABLE_DEBUG_MODE
  3. #pragma multi_compile _ ENABLE_LARGE_KERNEL
  4. #pragma multi_compile _ UNITY_DEVICE_SUPPORTS_NATIVE_16BIT
  5. #pragma multi_compile _ DISABLE_TEXTURE2D_X_ARRAY
  6. #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
  7. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  8. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  9. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
  10. #define STP_DIL 1
  11. #define STP_SAA 1
  12. #include "Packages/com.unity.render-pipelines.core/Runtime/STP/StpCommon.hlsl"
  13. //
  14. // Input
  15. //
  16. TEXTURE2D_X(_StpIntermediateConvergence);
  17. //
  18. // Intermediate Output
  19. //
  20. RW_TEXTURE2D_X(float, _StpIntermediateWeights);
  21. //
  22. // History Input/Output
  23. //
  24. TEXTURE2D_X(_StpLuma);
  25. RW_TEXTURE2D_X(float, _StpConvergence);
  26. // DIL
  27. #if defined(STP_16BIT)
  28. StpH1 StpDilDitH(StpW2 o) { return StpDitH1(o); }
  29. StpH1 StpDilConH(StpF2 p) { return (StpH1)SAMPLE_TEXTURE2D_X_LOD(_StpIntermediateConvergence, s_linear_clamp_sampler, p, 0).r; }
  30. StpH4 StpDilCon4H(StpF2 p) { return (StpH4)GATHER_RED_TEXTURE2D_X(_StpIntermediateConvergence, s_point_clamp_sampler, p); }
  31. #endif
  32. #if defined(STP_32BIT)
  33. StpMF1 StpDilDitF(StpMU2 o) { return StpDitF1(o); }
  34. StpMF1 StpDilConF(StpF2 p) { return (StpMF1)SAMPLE_TEXTURE2D_X_LOD(_StpIntermediateConvergence, s_linear_clamp_sampler, p, 0).r; }
  35. StpMF4 StpDilCon4F(StpF2 p) { return (StpMF4)GATHER_RED_TEXTURE2D_X(_StpIntermediateConvergence, s_point_clamp_sampler, p); }
  36. #endif
  37. // SAA
  38. #if defined(STP_16BIT)
  39. StpH4 StpSaaLum4H(StpF2 p) { return (StpH4)GATHER_RED_TEXTURE2D_X(_StpLuma, s_point_clamp_sampler, p); }
  40. #endif
  41. #if defined(STP_32BIT)
  42. StpMF4 StpSaaLum4F(StpF2 p) { return (StpMF4)GATHER_RED_TEXTURE2D_X(_StpLuma, s_point_clamp_sampler, p); }
  43. #endif
  44. #define THREADING_BLOCK_SIZE STP_GROUP_SIZE
  45. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Threading.hlsl"
  46. [numthreads(STP_GROUP_SIZE, 1, 1)]
  47. void StpPreTaa(Threading::Group group)
  48. {
  49. UNITY_XR_ASSIGN_VIEW_INDEX(group.groupID.z);
  50. #if defined(STP_16BIT)
  51. StpW1 lane = StpW1_(group.groupIndex);
  52. StpW2 groupPos = ComputeGroupPos(StpW2(group.groupID.xy));
  53. StpW2 pos = groupPos + StpRemapLaneTo8x16H(lane);
  54. StpW2 dilationSize = StpW2(asuint(_StpDilConstants0.zw)); // TODO: 16-bit packed constant?
  55. #else
  56. StpMU1 lane = StpMU1_(group.groupIndex);
  57. StpMU2 groupPos = ComputeGroupPos(StpMU2(group.groupID.xy));
  58. StpMU2 pos = groupPos + StpRemapLaneTo8x16F(lane);
  59. StpMU2 dilationSize = StpMU2(asuint(_StpDilConstants0).zw);
  60. #endif
  61. // The dilation logic only runs for a subset of the input image size
  62. if (all(groupPos < dilationSize))
  63. {
  64. half convergence;
  65. #if defined(STP_16BIT)
  66. StpDilH(
  67. #else
  68. StpDilF(
  69. #endif
  70. convergence,
  71. pos,
  72. asuint(_StpDilConstants0)
  73. );
  74. _StpConvergence[COORD_TEXTURE2D_X(pos)] = convergence;
  75. }
  76. half weights;
  77. #if defined(STP_16BIT)
  78. StpSaaH(
  79. #else
  80. StpSaaF(
  81. #endif
  82. weights,
  83. pos,
  84. // SAA uses the same constants as the pattern matcher
  85. asuint(_StpSetupConstants0)
  86. );
  87. _StpIntermediateWeights[COORD_TEXTURE2D_X(pos)] = weights;
  88. }