Created
October 29, 2016 13:18
-
-
Save reinsteam/15cf9b39b7cfb04690216f2eaa281320 to your computer and use it in GitHub Desktop.
An HLSL for computing prefix sum of 64 values using LDS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint ReadSlotId(uint LaneId, uint mask0, uint mask1) | |
{ | |
return LaneId & (0x20 | mask0) | mask1; | |
} | |
void LdsBarrier() {} | |
groupshared float Scratch[64]; | |
float PrefixSum64(uint LaneId, float x) | |
{ | |
Scratch[LaneId] = x; LdsBarrier(); | |
if (LaneId & 0x01) Scratch[LaneId] += Scratch[ReadSlotId(LaneId, 0x1e, 0x0)]; LdsBarrier(); | |
if (LaneId & 0x02) Scratch[LaneId] += Scratch[ReadSlotId(LaneId, 0x1c, 0x1)]; LdsBarrier(); | |
if (LaneId & 0x04) Scratch[LaneId] += Scratch[ReadSlotId(LaneId, 0x18, 0x3)]; LdsBarrier(); | |
if (LaneId & 0x08) Scratch[LaneId] += Scratch[ReadSlotId(LaneId, 0x10, 0x7)]; LdsBarrier(); | |
if (LaneId & 0x10) Scratch[LaneId] += Scratch[ReadSlotId(LaneId, 0x00, 0xf)]; LdsBarrier(); | |
if (LaneId & 0x20) Scratch[LaneId] += Scratch[31]; LdsBarrier(); | |
return Scratch[LaneId]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment