| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- // A very simle compute shader that checks if the light shadows needs rendering or not.
- #pragma anki technique comp
- #include <AnKi/Shaders/Common.hlsl>
- #include <AnKi/Shaders/Include/GpuVisibilityTypes.h>
- #include <AnKi/Shaders/Include/GpuSceneTypes.h>
- StructuredBuffer<GpuVisibilityHash> g_hash : register(t0);
- RWStructuredBuffer<U32> g_mdiDrawCounts : register(u0);
- RWStructuredBuffer<GpuSceneLight> g_lights : register(u1);
- RWStructuredBuffer<GpuSceneLightVisibleRenderablesHash> g_lightHashes : register(u2);
- RWStructuredBuffer<DrawIndirectArgs> g_clearTileIndirectArgs : register(u3);
- RWStructuredBuffer<DispatchIndirectArgs> g_dispatchMeshIndirectArgs : register(u4);
- RWStructuredBuffer<DrawIndirectArgs> g_drawIndirectArgs : register(u5);
- struct Constants
- {
- U32 m_lightIndex;
- U32 m_padding0;
- U32 m_padding1;
- U32 m_padding2;
- };
- ANKI_FAST_CONSTANTS(Constants, g_consts)
- groupshared U32 s_renderLight;
- [numthreads(64, 1, 1)] void main(U32 svGroupIndex : SV_GROUPINDEX)
- {
- if(svGroupIndex == 0)
- {
- const GpuSceneLight light = g_lights[g_consts.m_lightIndex];
- const U32 crntHash = g_lightHashes[light.m_visibleRenderablesHashIndex].m_hash;
- s_renderLight = crntHash != g_hash[0].m_renderablesHash || g_hash[0].m_containsDeformable == 1;
- if(s_renderLight)
- {
- g_lightHashes[light.m_visibleRenderablesHashIndex].m_hash = g_hash[0].m_renderablesHash;
- g_clearTileIndirectArgs[0] = (DrawIndirectArgs)0;
- g_clearTileIndirectArgs[0].m_vertexCount = 3;
- g_clearTileIndirectArgs[0].m_instanceCount = 1;
- }
- else
- {
- g_clearTileIndirectArgs[0] = (DrawIndirectArgs)0;
- }
- }
- GroupMemoryBarrierWithGroupSync();
- if(s_renderLight == 0)
- {
- // Nullify indirect args
- const U32 mdiCounts = getStructuredBufferElementCount(g_mdiDrawCounts);
- ANKI_ASSERT(mdiCounts <= 64);
- if(svGroupIndex < mdiCounts)
- {
- g_mdiDrawCounts[svGroupIndex] = 0u;
- }
- const U32 argCount = getStructuredBufferElementCount(g_dispatchMeshIndirectArgs);
- ANKI_ASSERT(argCount <= 64);
- if(svGroupIndex < argCount)
- {
- g_dispatchMeshIndirectArgs[svGroupIndex].m_threadGroupCountX = 0u;
- }
- const U32 drawCount = getStructuredBufferElementCount(g_drawIndirectArgs);
- ANKI_ASSERT(drawCount <= 64);
- if(svGroupIndex < drawCount)
- {
- g_drawIndirectArgs[svGroupIndex].m_vertexCount = 0;
- }
- }
- }
|