Skip to content

Commit e1e028b

Browse files
committed
Simplify the loop in histogram
1 parent f53f6c4 commit e1e028b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

include/nbl/builtin/hlsl/sort/counting.hlsl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,18 @@ struct counting
7272
histogram.atomicAdd(tid, sum);
7373

7474
const bool is_last_wg_invocation = tid == (GroupSize - 1);
75+
const uint16_t adjusted_key_bucket_count = KeyBucketCount + (GroupSize - KeyBucketCount % GroupSize);
7576

76-
for (int i = 1; i < buckets_per_thread; i++)
77+
for (tid += GroupSize; tid < adjusted_key_bucket_count; tid += GroupSize)
7778
{
78-
uint32_t prev_bucket_count = GroupSize * i;
79-
8079
if (is_last_wg_invocation) {
81-
sdata.set(prev_bucket_count, sdata.get(prev_bucket_count) + sum);
80+
uint32_t startIndex = tid - tid % GroupSize;
81+
sdata.set(startIndex, sdata.get(startIndex) + sum);
8282
}
8383

84-
uint32_t index = prev_bucket_count + tid;
85-
sum = inclusive_scan(sdata.get(index), sdata);
84+
sum = inclusive_scan(sdata.get(tid), sdata);
8685

87-
histogram.atomicAdd(prev_bucket_count + tid, sum);
86+
histogram.atomicAdd(tid, sum);
8887
}
8988
}
9089

0 commit comments

Comments
 (0)