| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #include <AnKi/Shaders/Functions.hlsl>
- #pragma anki technique comp
- Texture2D<Vec4> g_depthRt : register(t0);
- SamplerState g_linearAnyClampSampler : register(s0);
- RWTexture2D<Vec4> g_maxDepthStorageTex : register(u0);
- #define TILE_SIZE 64
- #define THREADGROUP_SIZE_XY 32
- #define MIN_POSSIBLE_WAVE_SIZE 8
- groupshared U32 s_maxDepth;
- [numthreads(THREADGROUP_SIZE_XY, THREADGROUP_SIZE_XY, 1)] void main(UVec2 svGroupThreadId : SV_GROUPTHREADID, UVec2 svGroupId : SV_GROUPID,
- U32 svGroupIndex : SV_GROUPINDEX)
- {
- if(svGroupIndex == 0)
- {
- s_maxDepth = 0;
- }
- GroupMemoryBarrierWithGroupSync();
- Vec2 depthRtSize;
- g_depthRt.GetDimensions(depthRtSize.x, depthRtSize.y);
- const Vec2 uv = Vec2(svGroupId * TILE_SIZE + svGroupThreadId * 2u + 1u) / depthRtSize;
- const Vec4 depths = g_depthRt.GatherRed(g_linearAnyClampSampler, uv);
- const F32 maxDepth = max4(depths);
- const U32 maxDepthu = asuint(maxDepth);
- InterlockedMax(s_maxDepth, maxDepthu);
- GroupMemoryBarrierWithGroupSync();
- if(svGroupIndex == 0)
- {
- g_maxDepthStorageTex[svGroupId] = asfloat(s_maxDepth);
- }
- }
|