HzbMaxDepth.ankiprog 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include <AnKi/Shaders/Functions.hlsl>
  6. #pragma anki technique comp
  7. Texture2D<Vec4> g_depthRt : register(t0);
  8. SamplerState g_linearAnyClampSampler : register(s0);
  9. RWTexture2D<Vec4> g_maxDepthStorageTex : register(u0);
  10. #define TILE_SIZE 64
  11. #define THREADGROUP_SIZE_XY 32
  12. #define MIN_POSSIBLE_WAVE_SIZE 8
  13. groupshared U32 s_maxDepth;
  14. [numthreads(THREADGROUP_SIZE_XY, THREADGROUP_SIZE_XY, 1)] void main(UVec2 svGroupThreadId : SV_GROUPTHREADID, UVec2 svGroupId : SV_GROUPID,
  15. U32 svGroupIndex : SV_GROUPINDEX)
  16. {
  17. if(svGroupIndex == 0)
  18. {
  19. s_maxDepth = 0;
  20. }
  21. GroupMemoryBarrierWithGroupSync();
  22. Vec2 depthRtSize;
  23. g_depthRt.GetDimensions(depthRtSize.x, depthRtSize.y);
  24. const Vec2 uv = Vec2(svGroupId * TILE_SIZE + svGroupThreadId * 2u + 1u) / depthRtSize;
  25. const Vec4 depths = g_depthRt.GatherRed(g_linearAnyClampSampler, uv);
  26. const F32 maxDepth = max4(depths);
  27. const U32 maxDepthu = asuint(maxDepth);
  28. InterlockedMax(s_maxDepth, maxDepthu);
  29. GroupMemoryBarrierWithGroupSync();
  30. if(svGroupIndex == 0)
  31. {
  32. g_maxDepthStorageTex[svGroupId] = asfloat(s_maxDepth);
  33. }
  34. }