Share via


WavePrefixCountBits 函式

傳回所有指定布林值變數的總和,這些變數在所有作用中通道中,索引小於目前通道。

語法

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