32 {
34
36 std::vector<RenderCommand> tempBuffer(n);
37
39 RenderCommand* dst = tempBuffer.data();
40
41 const int bitsPerPass = 8;
42 const int bucketCount = 1 << bitsPerPass;
43 const uint32_t mask = bucketCount - 1;
44 const uint16_t keySizeBits =
sizeof(
m_commands[0].m_SortingKey) * 8;
45
46 for (uint16_t shift = 0; shift < keySizeBits; shift += bitsPerPass)
47 {
48 uint32_t count[bucketCount] = { 0 };
49
50 for (size_t i = 0; i < n; i++)
51 {
52 count[(src[i].m_SortingKey >> shift) & mask]++;
53 }
54
55 for (int i = 1; i < bucketCount; ++i)
56 {
57 count[i] += count[i - 1];
58 }
59
60 for (
long long i = (
long long)
m_commands.size() - 1; i >= 0; --i)
61 {
62 uint32_t bucket = (src[i].m_SortingKey >> shift) & mask;
63 dst[--count[bucket]] = src[i];
64 }
65
66 std::swap(src, dst);
67 }
68
70 {
71 std::copy(tempBuffer.begin(), tempBuffer.end(),
m_commands.begin());
72 }
73
75 }