Pinning down the issue
This commit is contained in:
@@ -206,9 +206,143 @@ uint get_heap_element(uint id)
|
||||
}
|
||||
}
|
||||
|
||||
// decodes the position of the i-th one in the bitfield
|
||||
uint decode_bit(uint handle)
|
||||
{
|
||||
#if defined(NAIVE_DECODE)
|
||||
uint bitID = 1;
|
||||
for (uint currentDepth = 0; currentDepth < WAVE_TREE_DEPTH; ++currentDepth)
|
||||
{
|
||||
uint heapValue = get_heap_element(2 * bitID);
|
||||
uint b = handle < heapValue ? 0 : 1;
|
||||
|
||||
bitID = 2 * bitID + b;
|
||||
handle -= heapValue * b;
|
||||
}
|
||||
|
||||
return (bitID ^ OCBT_NUM_ELEMENTS);
|
||||
#else
|
||||
uint currentDepth = 0;
|
||||
uint heapElementID = 1u;
|
||||
for (currentDepth = 0; currentDepth < FIRST_VIRTUAL_LEVEL; ++currentDepth)
|
||||
{
|
||||
// Read the left element
|
||||
uint heapValue = get_heap_element(2u * heapElementID);
|
||||
|
||||
// Does it fall in the right or left subtree?
|
||||
uint b = handle < heapValue ? 0u : 1u;
|
||||
|
||||
// Pick a subtree
|
||||
heapElementID = 2u * heapElementID + b;
|
||||
|
||||
// Move the iterator to exclude the right subtree if required
|
||||
handle -= heapValue * b;
|
||||
}
|
||||
|
||||
// Align with the internal depth
|
||||
currentDepth++;
|
||||
|
||||
// Ok we have our subtree, now we need to pick the right bit
|
||||
uint64_t heapValue = pParams.bitFieldBuffer[heapElementID - OCBT_LAST_LEVEL_SIZE * 2];
|
||||
uint64_t mask = 0xffffffff;
|
||||
uint32_t bitCount = 32;
|
||||
for (; currentDepth < (WAVE_TREE_DEPTH + 1); ++currentDepth)
|
||||
{
|
||||
// Figure out the location of the first bit of this element
|
||||
uint real_heap_id = 2 * heapElementID - 1;
|
||||
uint level_first_element = (1u << currentDepth) - 1;
|
||||
uint id_in_level = real_heap_id - level_first_element;
|
||||
uint first_bit = bitCount * id_in_level;
|
||||
uint local_id = first_bit % 64;
|
||||
uint64_t target_bits = (heapValue >> local_id) & mask;
|
||||
uint heapValue = countbits(uint(target_bits >> 32)) + countbits(uint(target_bits));
|
||||
|
||||
// Does it fall in the right or left subtree?
|
||||
uint b = handle < heapValue ? 0u : 1u;
|
||||
|
||||
// Pick a subtree
|
||||
heapElementID = 2u * heapElementID + b;
|
||||
|
||||
// Move the iterator to exclude the right subtree if required
|
||||
handle -= heapValue * b;
|
||||
|
||||
// Adjust the mask and bitcount
|
||||
bitCount /= 2;
|
||||
mask = mask >> bitCount;
|
||||
}
|
||||
return (heapElementID ^ OCBT_NUM_ELEMENTS);
|
||||
#endif
|
||||
}
|
||||
|
||||
// decodes the position of the i-th zero in the bitfield
|
||||
uint decode_bit_complement(uint handle)
|
||||
{
|
||||
#if defined(NAIVE_DECODE)
|
||||
uint bitID = 1u;
|
||||
uint c = OCBT_NUM_ELEMENTS / 2u;
|
||||
|
||||
while (bitID < OCBT_NUM_ELEMENTS) {
|
||||
uint heapValue = c - get_heap_element(2u * bitID);
|
||||
uint b = handle < heapValue ? 0u : 1u;
|
||||
|
||||
bitID = 2u * bitID + b;
|
||||
handle -= heapValue * b;
|
||||
c /= 2u;
|
||||
}
|
||||
|
||||
return (bitID ^ OCBT_NUM_ELEMENTS);
|
||||
#else
|
||||
uint heapElementID = 1u;
|
||||
uint c = OCBT_NUM_ELEMENTS / 2u;
|
||||
uint currentDepth = 0;
|
||||
|
||||
for (currentDepth = 0; currentDepth < FIRST_VIRTUAL_LEVEL; ++currentDepth)
|
||||
{
|
||||
uint heapValue = c - get_heap_element(2u * heapElementID);
|
||||
uint b = handle < heapValue ? 0u : 1u;
|
||||
|
||||
heapElementID = 2u * heapElementID + b;
|
||||
handle -= heapValue * b;
|
||||
c /= 2u;
|
||||
}
|
||||
|
||||
// Align with the internal depth
|
||||
currentDepth++;
|
||||
|
||||
// Ok we have our subtree, now we need to pick the right bit
|
||||
uint64_t heapValue = pParams.bitFieldBuffer[heapElementID - OCBT_LAST_LEVEL_SIZE * 2];
|
||||
uint64_t mask = 0xffffffff;
|
||||
uint32_t bitCount = 32;
|
||||
for (; currentDepth < (WAVE_TREE_DEPTH + 1); ++currentDepth)
|
||||
{
|
||||
// Figure out the location of the first bit of this element
|
||||
uint real_heap_id = 2 * heapElementID - 1;
|
||||
uint level_first_element = (1u << currentDepth) - 1;
|
||||
uint id_in_level = real_heap_id - level_first_element;
|
||||
uint first_bit = bitCount * id_in_level;
|
||||
uint local_id = first_bit % 64;
|
||||
uint64_t target_bits = (heapValue >> local_id) & mask;
|
||||
uint heapValue = c - countbits(uint(target_bits >> 32)) + countbits(uint(target_bits));;
|
||||
|
||||
uint b = handle < heapValue ? 0u : 1u;
|
||||
|
||||
heapElementID = 2u * heapElementID + b;
|
||||
handle -= heapValue * b;
|
||||
c /= 2u;
|
||||
|
||||
// Adjust the mask and bitcount
|
||||
bitCount /= 2;
|
||||
mask = mask >> bitCount;
|
||||
}
|
||||
|
||||
return (heapElementID ^ OCBT_NUM_ELEMENTS);
|
||||
#endif
|
||||
}
|
||||
|
||||
[numthreads(64, 1, 1)]
|
||||
void GetHeap(uint groupIndex : SV_GroupIndex, uint dispatchID : SV_DispatchThreadID)
|
||||
{
|
||||
load_buffer_to_shared_memory(groupIndex);
|
||||
pParams.classificationBuffer[dispatchID] = get_heap_element(dispatchID);
|
||||
pParams.classificationBuffer[dispatchID] = decode_bit(dispatchID);
|
||||
pParams.classificationBuffer[dispatchID * 2] = decode_bit_complement(dispatchID);
|
||||
}
|
||||
Reference in New Issue
Block a user