OIT_CreatePrefixSum_Pass1_CS.hlsl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // RUN: %dxc -E main -T cs_6_0 %s | FileCheck %s
  2. // CHECK: groupId
  3. // CHECK: bufferLoad
  4. // CHECK: bufferStore
  5. //-----------------------------------------------------------------------------
  6. // File: OIT_CS.hlsl
  7. //
  8. // Desc: Compute shaders for used in the Order Independent Transparency sample.
  9. //
  10. // Copyright (c) Microsoft Corporation. All rights reserved.
  11. //-----------------------------------------------------------------------------
  12. // TODO: use structured buffers
  13. RWBuffer<float> deepBufferDepth : register( u0 );
  14. RWBuffer<uint> deepBufferColorUINT : register( u1 );
  15. RWTexture2D<float4> frameBuffer : register( u2 );
  16. RWBuffer<uint> prefixSum : register( u3 );
  17. Texture2D<uint> fragmentCount : register ( t0 );
  18. cbuffer CB : register( b0 )
  19. {
  20. uint g_nFrameWidth : packoffset( c0.x );
  21. uint g_nFrameHeight : packoffset( c0.y );
  22. uint g_nPassSize : packoffset( c0.z );
  23. uint g_nReserved : packoffset( c0.w );
  24. }
  25. #define blocksize 1
  26. #define groupthreads (blocksize*blocksize)
  27. groupshared float accum[groupthreads];
  28. // Second and following passes. Each pass distributes the sum of the first half of the group
  29. // to the second half of the group. There are n/groupsize groups in each pass.
  30. // Each pass increases the group size until it is the size of the buffer.
  31. // The resulting buffer holds the prefix sum of all preceding values in each
  32. // position
  33. [numthreads(1,1,1)]
  34. void main( uint3 nGid : SV_GroupID, uint3 nDTid : SV_DispatchThreadID, uint3 nGTid : SV_GroupThreadID )
  35. {
  36. int nThreadNum = nGid.x;
  37. int nValue = prefixSum[nThreadNum*g_nPassSize + g_nPassSize/2 - 1];
  38. for(int i = nThreadNum*g_nPassSize + g_nPassSize/2; i < nThreadNum*g_nPassSize + g_nPassSize && i < g_nFrameWidth*g_nFrameHeight; i++)
  39. {
  40. prefixSum[i] = prefixSum[i] + nValue;
  41. }
  42. }