ParticleSortIndirectArgsCS.hlsl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // RUN: %dxc -E main -T cs_6_0 %s | FileCheck %s
  2. // CHECK: flattenedThreadIdInGroup
  3. // CHECK: FirstbitHi
  4. //
  5. // Copyright (c) Microsoft. All rights reserved.
  6. // This code is licensed under the MIT License (MIT).
  7. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  8. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  9. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  10. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  11. //
  12. // Developed by Minigraph
  13. //
  14. // Author: James Stanard
  15. //
  16. #include "ParticleUtility.hlsli"
  17. ByteAddressBuffer g_ActiveParticlesCount : register(t1);
  18. RWByteAddressBuffer g_IndirectArgsBuffer : register(u0);
  19. [RootSignature(Particle_RootSig)]
  20. [numthreads(8, 1, 1)]
  21. void main( uint GI : SV_GroupIndex )
  22. {
  23. uint k = 1 << (GI + 11);
  24. uint VisibleParticles = g_ActiveParticlesCount.Load(4);
  25. uint NextPow2 = (1 << firstbithigh(VisibleParticles)) - 1;
  26. NextPow2 = (VisibleParticles + NextPow2) & ~NextPow2;
  27. NextPow2 = (NextPow2 + 2047) & ~2047;
  28. uint NumElements = k > NextPow2 ? 0 : (VisibleParticles + k - 1) & ~(k - 1);
  29. uint NumGroups = (GI == 0 ? NextPow2 : NumElements) / 2048;
  30. g_IndirectArgsBuffer.Store3(GI * 12, uint3(NumGroups, 1, 1));
  31. }