WavePrefixCountBits 函数

返回索引小于当前通道的所有活动通道中所有指定布尔变量设置为 true 的总和。

语法

uint WavePrefixCountBits(
   bool bBit
);

参数

bBit

指定的布尔变量。

返回值

所有指定布尔变量在索引小于当前通道的所有活动通道中设置为 true 的总和。

备注

着色器模型 6.0 在所有着色器阶段都支持此函数。

 

示例

以下代码介绍如何实现对有序流的压缩写入,其中每个通道写入的元素数为 1 或 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

另请参阅

着色器模型 6 概述

着色器型号 6