DepthDownscale.ankiprog 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma anki mutator WAVE_OPERATIONS 0 1
  6. #pragma anki technique vert pixel comp
  7. #if ANKI_COMPUTE_SHADER
  8. # include <AnKi/Shaders/Common.hlsl>
  9. # include <AnKi/Shaders/Include/MiscRendererTypes.h>
  10. ANKI_FAST_CONSTANTS(DepthDownscaleConstants, g_consts)
  11. globallycoherent RWStructuredBuffer<U32> g_spdCounter : register(u0);
  12. RWTexture2D<Vec4> g_dstStorageTextures[kMaxMipsSinglePassDownsamplerCanProduce] : register(u1);
  13. SamplerState u_linearAnyClampSampler : register(s0);
  14. Texture2D g_srcTex : register(t0);
  15. // Include SPD
  16. # define A_GPU 1
  17. # define A_HLSL 1
  18. # include <ThirdParty/FidelityFX/ffx_a.h>
  19. groupshared AU1 s_spdCounter;
  20. groupshared AF1 s_spdIntermediateR[16][16];
  21. AF4 SpdLoadSourceImage(AU2 p, AU1 slice)
  22. {
  23. ANKI_MAYBE_UNUSED(slice);
  24. const AF2 textureCoord = Vec2(p) * g_consts.m_srcTexSizeOverOne + g_consts.m_srcTexSizeOverOne;
  25. return AF4(g_srcTex.SampleLevel(u_linearAnyClampSampler, textureCoord, 0.0).r, 0.0, 0.0, 0.0);
  26. }
  27. AF4 SpdLoad(AU2 p, AU1 slice)
  28. {
  29. ANKI_MAYBE_UNUSED(slice);
  30. return AF4(g_dstStorageTextures[5][p].r, 0.0, 0.0, 0.0);
  31. }
  32. void SpdStore(AU2 p, AF4 value, AU1 mip, AU1 slice)
  33. {
  34. ANKI_MAYBE_UNUSED(slice);
  35. g_dstStorageTextures[mip][p] = Vec4(value.x, 0.0, 0.0, 0.0);
  36. }
  37. void SpdIncreaseAtomicCounter(AU1 slice)
  38. {
  39. ANKI_MAYBE_UNUSED(slice);
  40. InterlockedAdd(g_spdCounter[0], 1u, s_spdCounter);
  41. }
  42. AU1 SpdGetAtomicCounter()
  43. {
  44. return s_spdCounter;
  45. }
  46. void SpdResetAtomicCounter(AU1 slice)
  47. {
  48. ANKI_MAYBE_UNUSED(slice);
  49. g_spdCounter[0] = 0u;
  50. }
  51. AF4 SpdLoadIntermediate(AU1 x, AU1 y)
  52. {
  53. return AF4(s_spdIntermediateR[x][y], 0.0, 0.0, 0.0);
  54. }
  55. void SpdStoreIntermediate(AU1 x, AU1 y, AF4 value)
  56. {
  57. s_spdIntermediateR[x][y] = value.x;
  58. }
  59. AF4 SpdReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3)
  60. {
  61. const F32 avg = (v0.x + v1.x + v2.x + v3.x) / 4.0f;
  62. return AF4(avg, 0.0, 0.0, 0.0);
  63. }
  64. # define SPD_LINEAR_SAMPLER 1
  65. # if WAVE_OPERATIONS == 0
  66. # define SPD_NO_WAVE_OPERATIONS 1
  67. # endif
  68. # include <ThirdParty/FidelityFX/ffx_spd.h>
  69. [numthreads(256, 1, 1)] void main(UVec3 svGroupId : SV_GROUPID, U32 svGroupIndex : SV_GROUPINDEX)
  70. {
  71. const U32 slice = 0u;
  72. const UVec2 offset = UVec2(0, 0);
  73. SpdDownsample(AU2(svGroupId.xy), AU1(svGroupIndex), AU1(g_consts.m_mipmapCount), AU1(g_consts.m_threadgroupCount), slice, offset);
  74. }
  75. #endif // ANKI_COMPUTE_SHADER
  76. #if ANKI_PIXEL_SHADER || ANKI_VERTEX_SHADER
  77. # include <AnKi/Shaders/QuadVert.hlsl>
  78. Texture2D<Vec4> g_inputTex : register(t0);
  79. SamplerState g_linearAnyClampSampler : register(s0);
  80. # if ANKI_PIXEL_SHADER
  81. F32 main(VertOut input) : SV_TARGET0
  82. {
  83. return g_inputTex.SampleLevel(g_linearAnyClampSampler, input.m_uv, 0.0).x;
  84. }
  85. # endif // ANKI_PIXEL_SHADER
  86. #endif // ANKI_PIXEL_SHADER || ANKI_VERTEX_SHADER