ShadowMappingVetVisibility.ankiprog 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. // A very simle compute shader that checks if the light shadows needs rendering or not.
  6. #pragma anki technique comp
  7. #include <AnKi/Shaders/Common.hlsl>
  8. #include <AnKi/Shaders/Include/GpuVisibilityTypes.h>
  9. #include <AnKi/Shaders/Include/GpuSceneTypes.h>
  10. StructuredBuffer<GpuVisibilityHash> g_hash : register(t0);
  11. RWStructuredBuffer<U32> g_mdiDrawCounts : register(u0);
  12. RWStructuredBuffer<GpuSceneLight> g_lights : register(u1);
  13. RWStructuredBuffer<GpuSceneLightVisibleRenderablesHash> g_lightHashes : register(u2);
  14. RWStructuredBuffer<DrawIndirectArgs> g_clearTileIndirectArgs : register(u3);
  15. RWStructuredBuffer<DispatchIndirectArgs> g_dispatchMeshIndirectArgs : register(u4);
  16. RWStructuredBuffer<DrawIndirectArgs> g_drawIndirectArgs : register(u5);
  17. struct Constants
  18. {
  19. U32 m_lightIndex;
  20. U32 m_padding0;
  21. U32 m_padding1;
  22. U32 m_padding2;
  23. };
  24. ANKI_FAST_CONSTANTS(Constants, g_consts)
  25. groupshared U32 s_renderLight;
  26. [numthreads(64, 1, 1)] void main(U32 svGroupIndex : SV_GROUPINDEX)
  27. {
  28. if(svGroupIndex == 0)
  29. {
  30. const GpuSceneLight light = g_lights[g_consts.m_lightIndex];
  31. const U32 crntHash = g_lightHashes[light.m_visibleRenderablesHashIndex].m_hash;
  32. s_renderLight = crntHash != g_hash[0].m_renderablesHash || g_hash[0].m_containsDeformable == 1;
  33. if(s_renderLight)
  34. {
  35. g_lightHashes[light.m_visibleRenderablesHashIndex].m_hash = g_hash[0].m_renderablesHash;
  36. g_clearTileIndirectArgs[0] = (DrawIndirectArgs)0;
  37. g_clearTileIndirectArgs[0].m_vertexCount = 3;
  38. g_clearTileIndirectArgs[0].m_instanceCount = 1;
  39. }
  40. else
  41. {
  42. g_clearTileIndirectArgs[0] = (DrawIndirectArgs)0;
  43. }
  44. }
  45. GroupMemoryBarrierWithGroupSync();
  46. if(s_renderLight == 0)
  47. {
  48. // Nullify indirect args
  49. const U32 mdiCounts = getStructuredBufferElementCount(g_mdiDrawCounts);
  50. ANKI_ASSERT(mdiCounts <= 64);
  51. if(svGroupIndex < mdiCounts)
  52. {
  53. g_mdiDrawCounts[svGroupIndex] = 0u;
  54. }
  55. const U32 argCount = getStructuredBufferElementCount(g_dispatchMeshIndirectArgs);
  56. ANKI_ASSERT(argCount <= 64);
  57. if(svGroupIndex < argCount)
  58. {
  59. g_dispatchMeshIndirectArgs[svGroupIndex].m_threadGroupCountX = 0u;
  60. }
  61. const U32 drawCount = getStructuredBufferElementCount(g_drawIndirectArgs);
  62. ANKI_ASSERT(drawCount <= 64);
  63. if(svGroupIndex < drawCount)
  64. {
  65. g_drawIndirectArgs[svGroupIndex].m_vertexCount = 0;
  66. }
  67. }
  68. }