// ======================================================================== // Allocate a ShadowSlotID that will be used to store list of lights uint AllocateShadowSlotID(in uint inTileIndex , in uint inTileLightCount ) { // Reserve fixed amount of memory for debuging with predictable location if( DEBUG_FIXED_LIGHTCOUNT > 0 ) { return inTileIndex * RoundUp ( DEBUG_FIXED_LIGHTCOUNT , 3) ; }
// Round up to next multiple becase 3 indices stored per uint inTileLightCount = RoundUp ( inTileLightCount , 3) ; uint tileGrpLightCount = WaveActiveSum ( tileLightCount ) ; uint tileGrpSlotID = 0;
// Single thread allocates space for entire TileGroup if( WaveIsFirstLane () ) { staticconst uint kShadowCounterOffset = 0; rw_SlotCounters . InterlockedAdd ( kShadowCounterOffset , tileGrpLightCount , tileGrpSlotID ) ; }
// Tile get its SlotID by offsetting the starting location of the // Group reserved memory with the sum of previous Tile Slots count uint shadowSlotID = WaveReadLaneFirst ( tileGrpSlotID ) ; shadowSlotID += WavePrefixSum ( inTileLightCount ) ; return shadowSlotID ; }
// ======================================================================== // Allocate a VisibilitySlotID that will be used to store the visibility // of one light at each pixel of a Tile (1 slot = 8x8 pixels (64 bytes )) uint AllocateVisibilitySlotID() { // Single thread allocates space for entire Tile uint slotID ; if( WaveIsFirstLane () ) { staticconst uint kVisibilityCounterOffset = 4; rw_SlotCounters . InterlockedAdd ( kVisibilityCounterOffset , 1 , slotID ) ; }