ParticleOuterSortCS.hlsl 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // RUN: %dxc -E main -T cs_6_0 -O0 %s | FileCheck %s
  2. // CHECK: threadId
  3. // CHECK: bufferLoad
  4. // CHECK: icmp ugt
  5. // CHECK: and
  6. // CHECK: icmp eq
  7. // CHECK: icmp ne
  8. //
  9. // Copyright (c) Microsoft. All rights reserved.
  10. // This code is licensed under the MIT License (MIT).
  11. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  12. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  13. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  14. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  15. //
  16. // Developed by Minigraph
  17. //
  18. // Author: James Stanard
  19. //
  20. #include "ParticleUtility.hlsli"
  21. RWStructuredBuffer<uint> g_SortBuffer : register(u0);
  22. cbuffer CB : register(b0)
  23. {
  24. uint k; // k >= 4096
  25. uint j; // j >= 2048 && j < k
  26. };
  27. [RootSignature(Particle_RootSig)]
  28. [numthreads(1024, 1, 1)]
  29. void main( uint3 DTid : SV_DispatchThreadID )
  30. {
  31. // Form unique index pair from dispatch thread ID
  32. uint Index1 = InsertZeroBit(DTid.x, j);
  33. uint Index2 = Index1 | j;
  34. uint A = g_SortBuffer[Index1];
  35. uint B = g_SortBuffer[Index2];
  36. if ((A > B) != ((Index1 & k) == 0))
  37. {
  38. g_SortBuffer[Index1] = B;
  39. g_SortBuffer[Index2] = A;
  40. }
  41. }