WavePrefixCountBits function
Returns the sum of all the specified boolean variables set to true across all active lanes with indices smaller than the current lane.
Syntax
uint WavePrefixCountBits(
bool bBit
);
Parameters
-
bBit
-
The specified boolean variables.
Return value
The sum of all the specified Boolean variables set to true across all active lanes with indices smaller than the current lane.
Remarks
This function is supported from shader model 6.0 in all shader stages.
Examples
The following code describes how to implement a compacted write to an ordered stream where the number of elements written per lane is either 1 or 0.
bool bDoesThisLaneHaveAnAppendItem = <expr>;
// compute number of items to append for the whole wave
uint laneAppendOffset = WavePrefixCountBits( bDoesThisLaneHaveAnAppendItem );
uint appendCount = WaveActiveCountBits( bDoesThisLaneHaveAnAppendItem);
// update the output location for this whole wave
uint appendOffset;
if ( WaveIsFirstLane () )
{
// this way, we only issue one atomic for the entire wave, which reduces contention
// and keeps the output data for each lane in this wave together in the output buffer
InterlockedAdd(bufferSize, appendCount, appendOffset);
}
appendOffset = WaveReadLaneFirst( appendOffset ); // broadcast value
appendOffset += laneAppendOffset; // and add in the offset for this lane
buffer[appendOffset] = myData; // write to the offset location for this lane
See also