WaveOnce function
This result returns true for only one lane in the current wave.
Syntax
bool WaveOnce(void);
Parameters
This function has no parameters.
Return value
True for only one lane.
Remarks
This function can be used to identify operations that must happen only once per wave. Driver implementations typically use the first lane in the wave, but this is not apparent to app code.
This function is supported from shader model 6.0, in the following types of shaders:
Vertex | Hull | Domain | Geometry | Pixel | Compute |
---|---|---|---|---|---|
x | x |
Examples
This code implements a compacted write to an ordered stream.
uint doesThisLaneHaveAnAppendItem = (cond) ? 1 : 0;
// compute number of items to append for the whole wave
uint appendCount = WaveAllSum( doesThisLaneHaveAnAppendItem );
// compute number of locations filled before this one
uint laneAppendOffset = WavePrefixSum( doesThisLaneHaveAnAppendItem );
// update the output location for this whole wave
uint appendOffset;
if ( WaveOnce() )
{
// 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
appendOffset = atomicAdd(bufferSize, appendCount);
}
appendOffset = WaveReadFirstLane(appendOffset); // broadcast value
appendOffset += laneAppendOffset; // and add in the offset for this lane
buffer[appendOffset] = myData; // write to the offset location for this lane