40 NvFlowUint tableDimBits = 0llu;
41 NvFlowUint tableDimLessOne = 0llu;
42 NvFlowUint tableDim3 = 1u;
50 NvFlowInt4 locationMin = { 0, 0, 0, 0 };
51 NvFlowInt4 locationMax = { 0, 0, 0, 0 };
59 tableDimLessOne = 0llu;
63 nextIndices.size = 0u;
65 ranges.pushBack(nullRange);
79 ranges.reserve(tableDim3);
80 ranges.size = tableDim3;
82 nextIndices.size = 0u;
83 nextIndices.reserve(locations.size);
84 nextIndices.size = locations.size;
88 for (NvFlowUint64 rangeIdx = 0u; rangeIdx < ranges.size; rangeIdx++)
90 ranges[rangeIdx] = nullRange;
92 for (NvFlowUint64 locationIdx = 0u; locationIdx < locations.size; locationIdx++)
94 NvFlowInt4 location = locations[locationIdx];
95 NvFlowUint64 baseRangeIdx = (location.x & tableDimLessOne) |
96 ((location.y & tableDimLessOne) << tableDimBits) |
97 ((location.z & tableDimLessOne) << (tableDimBits + tableDimBits));
100 nextIndices[locationIdx] = ~0llu;
102 NvFlowUint64 beginIdx = ranges[baseRangeIdx].beginIdx;
103 NvFlowUint64 endIdx = ranges[baseRangeIdx].endIdx;
104 if (beginIdx >= endIdx)
106 ranges[baseRangeIdx].beginIdx = locationIdx;
107 ranges[baseRangeIdx].endIdx = locationIdx + 1u;
109 else if (endIdx == locationIdx)
111 ranges[baseRangeIdx].endIdx = locationIdx + 1u;
112 nextIndices[endIdx - 1u] = locationIdx;
116 NvFlowUint64 prevIdx = endIdx - 1u;
117 NvFlowUint64 currentIdx = nextIndices[prevIdx];
118 while (currentIdx < nextIndices.size)
120 prevIdx = currentIdx;
121 currentIdx = nextIndices[currentIdx];
123 nextIndices[prevIdx] = locationIdx;
128 void compactNonZeroWithLimit(NvFlowUint64 maxLocations)
130 NvFlowUint64 dstIdx = 0u;
131 for (NvFlowUint64 srcIdx = 0u; srcIdx < locations.size && dstIdx < maxLocations; srcIdx++)
135 locations[dstIdx] = locations[srcIdx];
136 masks[dstIdx] = masks[srcIdx];
140 locations.size = dstIdx;
145 tableDimLessOne = 0llu;
147 while (locations.size > tableDim3)
150 tableDimLessOne = (1u << tableDimBits) - 1u;
151 tableDim3 = (1 << (tableDimBits + tableDimBits + tableDimBits));
159 NvFlowArray_copy(tmpLocations, locations);
160 NvFlowArray_copy(tmpMasks, masks);
162 NvFlowUint64 globalOffset = 0u;
163 for (NvFlowUint64 baseRangeIdx = 0u; baseRangeIdx < ranges.size; baseRangeIdx++)
165 NvFlowUint64 beginIdx = ranges[baseRangeIdx].beginIdx;
166 NvFlowUint64 endIdx = ranges[baseRangeIdx].endIdx;
167 for (NvFlowUint64 currentIdx = beginIdx; currentIdx < endIdx; currentIdx++)
169 locations[globalOffset] = tmpLocations[currentIdx];
170 masks[globalOffset] = tmpMasks[currentIdx];
173 if (beginIdx < endIdx)
175 NvFlowUint64 currentIdx = nextIndices[endIdx - 1u];
176 while (currentIdx < nextIndices.size)
178 locations[globalOffset] = tmpLocations[currentIdx];
179 masks[globalOffset] = tmpMasks[currentIdx];
182 currentIdx = nextIndices[currentIdx];
190 NvFlowUint64 find(NvFlowInt4 location)
192 NvFlowUint64 baseRangeIdx = (location.x & tableDimLessOne) |
193 ((location.y & tableDimLessOne) << tableDimBits) |
194 ((location.z & tableDimLessOne) << (tableDimBits + tableDimBits));
196 NvFlowUint64 beginIdx = ranges[baseRangeIdx].beginIdx;
197 NvFlowUint64 endIdx = ranges[baseRangeIdx].endIdx;
198 for (NvFlowUint64 currentIdx = beginIdx; currentIdx < endIdx; currentIdx++)
200 if (location.x == locations[currentIdx].x &&
201 location.y == locations[currentIdx].y &&
202 location.z == locations[currentIdx].z &&
203 location.w == locations[currentIdx].w)
208 if (beginIdx < endIdx)
210 NvFlowUint64 currentIdx = nextIndices[endIdx - 1u];
211 while (currentIdx < nextIndices.size)
213 if (location.x == locations[currentIdx].x &&
214 location.y == locations[currentIdx].y &&
215 location.z == locations[currentIdx].z &&
216 location.w == locations[currentIdx].w)
220 currentIdx = nextIndices[currentIdx];
226 void pushNoResize(NvFlowInt4 location, NvFlowUint mask)
228 NvFlowUint64 baseRangeIdx = (location.x & tableDimLessOne) |
229 ((location.y & tableDimLessOne) << tableDimBits) |
230 ((location.z & tableDimLessOne) << (tableDimBits + tableDimBits));
232 NvFlowUint64 beginIdx = ranges[baseRangeIdx].beginIdx;
233 NvFlowUint64 endIdx = ranges[baseRangeIdx].endIdx;
234 for (NvFlowUint64 currentIdx = beginIdx; currentIdx < endIdx; currentIdx++)
236 if (location.x == locations[currentIdx].x &&
237 location.y == locations[currentIdx].y &&
238 location.z == locations[currentIdx].z &&
239 location.w == locations[currentIdx].w)
241 masks[currentIdx] |= mask;
245 if (beginIdx >= endIdx)
247 locations.pushBack(location);
248 masks.pushBack(mask);
249 nextIndices.pushBack(~0llu);
251 ranges[baseRangeIdx].beginIdx = locations.size - 1u;
252 ranges[baseRangeIdx].endIdx = locations.size;
254 else if (endIdx == locations.size)
256 locations.pushBack(location);
257 masks.pushBack(mask);
258 nextIndices.pushBack(~0llu);
260 ranges[baseRangeIdx].endIdx = locations.size;
261 nextIndices[endIdx - 1u] = locations.size - 1u;
265 NvFlowUint64 prevIdx = endIdx - 1u;
266 NvFlowUint64 currentIdx = nextIndices[prevIdx];
267 while (currentIdx < nextIndices.size)
269 if (location.x == locations[currentIdx].x &&
270 location.y == locations[currentIdx].y &&
271 location.z == locations[currentIdx].z &&
272 location.w == locations[currentIdx].w)
274 masks[currentIdx] |= mask;
277 prevIdx = currentIdx;
278 currentIdx = nextIndices[currentIdx];
281 locations.pushBack(location);
282 masks.pushBack(mask);
283 nextIndices.pushBack(~0llu);
285 nextIndices[prevIdx] = locations.size - 1u;
289 void conditionalGrowTable()
291 if (locations.size > tableDim3)
294 tableDimLessOne = (1u << tableDimBits) - 1u;
295 tableDim3 = (1 << (tableDimBits + tableDimBits + tableDimBits));
301 void push(NvFlowInt4 location, NvFlowUint mask)
303 pushNoResize(location, mask);
304 conditionalGrowTable();
309 locationMin = NvFlowInt4{ 0, 0, 0, 0 };
310 locationMax = NvFlowInt4{ 0, 0, 0, 0 };
311 if (locations.size > 0)
313 locationMin = locations[0];
314 locationMax.x = locations[0].x + 1;
315 locationMax.y = locations[0].y + 1;
316 locationMax.z = locations[0].z + 1;
317 locationMax.w = locations[0].w + 1;
319 for (NvFlowUint64 locationIdx = 1u; locationIdx < locations.size; locationIdx++)
321 NvFlowInt4 location = locations[locationIdx];
323 if (location.x < locationMin.x)
325 locationMin.x = location.x;
327 if (location.y < locationMin.y)
329 locationMin.y = location.y;
331 if (location.z < locationMin.z)
333 locationMin.z = location.z;
335 if (location.w < locationMin.w)
337 locationMin.w = location.w;
341 if (location.x + 1 > locationMax.x)
343 locationMax.x = location.x + 1;
345 if (location.y + 1 > locationMax.y)
347 locationMax.y = location.y + 1;
349 if (location.z + 1 > locationMax.z)
351 locationMax.z = location.z + 1;
353 if (location.w + 1 > locationMax.w)
355 locationMax.w = location.w + 1;