Removing tons of debugging and sync code
This commit is contained in:
@@ -228,35 +228,58 @@ uint bit_count(uint depth, uint element)
|
||||
// decodes the position of the i-th one in the bitfield
|
||||
uint decode_bit(uint handle)
|
||||
{
|
||||
uint bitID = 1;
|
||||
for (uint currentDepth = 0; currentDepth < WAVE_TREE_DEPTH; ++currentDepth)
|
||||
//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);
|
||||
|
||||
for(uint i = 0; i < OCBT_NUM_ELEMENTS; ++i)
|
||||
{
|
||||
uint heapValue = get_heap_element(2 * bitID);
|
||||
uint b = handle < heapValue ? 0 : 1;
|
||||
|
||||
bitID = 2 * bitID + b;
|
||||
handle -= heapValue * b;
|
||||
if(get_bit(i) == 1)
|
||||
{
|
||||
if(handle == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
handle--;
|
||||
}
|
||||
}
|
||||
|
||||
return (bitID ^ OCBT_NUM_ELEMENTS);
|
||||
}
|
||||
|
||||
// decodes the position of the i-th zero in the bitfield
|
||||
uint decode_bit_complement(uint handle)
|
||||
{
|
||||
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;
|
||||
//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);
|
||||
for(uint i = 0; i < OCBT_NUM_ELEMENTS; ++i)
|
||||
{
|
||||
if(get_bit(i) == 0)
|
||||
{
|
||||
if(handle == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
handle--;
|
||||
}
|
||||
}
|
||||
|
||||
return (bitID ^ OCBT_NUM_ELEMENTS);
|
||||
}
|
||||
|
||||
void reduce(uint groupIndex)
|
||||
|
||||
@@ -10,48 +10,46 @@ void Reset()
|
||||
ResetBuffers();
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
[numthreads(WORKGROUP_SIZE, 1, 1)]
|
||||
void Classify(uint dispatchID : SV_DispatchThreadID)
|
||||
{
|
||||
if(dispatchID > 0)
|
||||
return;
|
||||
for(uint i = 0; i < pParams.indirectDrawBuffer[9]; ++i)
|
||||
{
|
||||
//if(dispatchID > 0)
|
||||
// return;
|
||||
//for(uint i = 0; i < pParams.indirectDrawBuffer[9]; ++i)
|
||||
//{
|
||||
// This thread doesn't have any work to do, we're done
|
||||
//if (currentID >= pParams.indirectDrawBuffer[9])
|
||||
// return;
|
||||
if (dispatchID >= pParams.indirectDrawBuffer[9])
|
||||
return;
|
||||
|
||||
// Operate the indirection
|
||||
uint currentID = pParams.indexedBisectorBuffer[i];
|
||||
// Operate the indirection
|
||||
uint currentID = pParams.indexedBisectorBuffer[dispatchID];
|
||||
|
||||
// Read the current geometry data
|
||||
BisectorGeometry bis;
|
||||
bis.p[0] = pParams.currentVertexBuffer[3 * currentID].xyz;
|
||||
bis.p[1] = pParams.currentVertexBuffer[3 * currentID + 1].xyz;
|
||||
bis.p[2] = pParams.currentVertexBuffer[3 * currentID + 2].xyz;
|
||||
bis.p[3] = pParams.currentVertexBuffer[3 * pParams.geometry.totalNumElements + currentID].xyz;
|
||||
// Read the current geometry data
|
||||
BisectorGeometry bis;
|
||||
bis.p[0] = pParams.currentVertexBuffer[3 * currentID].xyz;
|
||||
bis.p[1] = pParams.currentVertexBuffer[3 * currentID + 1].xyz;
|
||||
bis.p[2] = pParams.currentVertexBuffer[3 * currentID + 2].xyz;
|
||||
bis.p[3] = pParams.currentVertexBuffer[3 * pParams.geometry.totalNumElements + currentID].xyz;
|
||||
|
||||
// Classify the element
|
||||
ClassifyElement(currentID, bis, pParams.geometry.totalNumElements, pParams.geometry.baseDepth);
|
||||
}
|
||||
// Classify the element
|
||||
ClassifyElement(currentID, bis, pParams.geometry.totalNumElements, pParams.geometry.baseDepth);
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
[numthreads(WORKGROUP_SIZE, 1, 1)]
|
||||
void Split(uint dispatchID : SV_DispatchThreadID)
|
||||
{
|
||||
if(dispatchID > 0)
|
||||
//if(dispatchID > 0)
|
||||
// return;
|
||||
//for(dispatchID = 0; dispatchID < pParams.classificationBuffer[SPLIT_COUNTER]; ++dispatchID)
|
||||
//{
|
||||
if (dispatchID >= pParams.classificationBuffer[SPLIT_COUNTER])
|
||||
return;
|
||||
for(dispatchID = 0; dispatchID < pParams.classificationBuffer[SPLIT_COUNTER]; ++dispatchID)
|
||||
{
|
||||
//if (dispatchID >= pParams.classificationBuffer[SPLIT_COUNTER])
|
||||
// return;
|
||||
|
||||
// Grab the real elementID
|
||||
uint currentID = pParams.classificationBuffer[CLASSIFY_COUNTER_OFFSET + dispatchID];
|
||||
// Grab the real elementID
|
||||
uint currentID = pParams.classificationBuffer[CLASSIFY_COUNTER_OFFSET + dispatchID];
|
||||
|
||||
// Split the element
|
||||
SplitElement(currentID, pParams.geometry.baseDepth);
|
||||
}
|
||||
// Split the element
|
||||
SplitElement(currentID, pParams.geometry.baseDepth);
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
@@ -62,102 +60,102 @@ void PrepareIndirect(uint currentID : SV_DispatchThreadID)
|
||||
pParams.indirectDispatchBuffer[currentID * 3 + 2] = 1;
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
[numthreads(WORKGROUP_SIZE, 1, 1)]
|
||||
void Allocate(uint groupIndex : SV_GroupIndex, uint dispatchID : SV_DispatchThreadID)
|
||||
{
|
||||
if(dispatchID > 0)
|
||||
return;
|
||||
|
||||
for(uint i = 0; i < 64; ++i)
|
||||
{
|
||||
//if(dispatchID > 0)
|
||||
// return;
|
||||
//
|
||||
//for(uint i = 0; i < 64; ++i)
|
||||
//{
|
||||
// Load the CBT to the LDS
|
||||
load_buffer_to_shared_memory(i);
|
||||
}
|
||||
load_buffer_to_shared_memory(groupIndex);
|
||||
|
||||
|
||||
// If this element doesn't need to be processed, we're done
|
||||
//if (dispatchID >= pParams.allocateBuffer[0])
|
||||
// return;
|
||||
for(uint i = 0; i < pParams.allocateBuffer[0]; ++i)
|
||||
{
|
||||
if (dispatchID >= pParams.allocateBuffer[0])
|
||||
return;
|
||||
//for(uint i = 0; i < pParams.allocateBuffer[0]; ++i)
|
||||
//{
|
||||
// Allocate the required bits
|
||||
AllocateElement(pParams.allocateBuffer[1 + i]);
|
||||
}
|
||||
AllocateElement(pParams.allocateBuffer[1 + dispatchID]);
|
||||
//}
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
[numthreads(WORKGROUP_SIZE, 1, 1)]
|
||||
void Bisect(uint groupIndex : SV_GroupIndex, uint dispatchID : SV_DispatchThreadID)
|
||||
{
|
||||
if(dispatchID > 0)
|
||||
return;
|
||||
// If this element doesn't need to be processed, we're done
|
||||
//if (dispatchID >= pParams.allocateBuffer[0])
|
||||
//if(dispatchID > 0)
|
||||
// return;
|
||||
for(uint i = 0; i < pParams.allocateBuffer[0]; ++i)
|
||||
{
|
||||
// If this element doesn't need to be processed, we're done
|
||||
if (dispatchID >= pParams.allocateBuffer[0])
|
||||
return;
|
||||
//for(uint i = 0; i < pParams.allocateBuffer[0]; ++i)
|
||||
//{
|
||||
// Operation the bisection of this element
|
||||
BisectElement(pParams.allocateBuffer[1 + i], i);
|
||||
}
|
||||
BisectElement(pParams.allocateBuffer[1 + dispatchID]);
|
||||
//}
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
[numthreads(WORKGROUP_SIZE, 1, 1)]
|
||||
void PropagateBisect(uint dispatchID : SV_DispatchThreadID)
|
||||
{
|
||||
if(dispatchID > 0)
|
||||
return;
|
||||
// If this element doesn't need to be processed, we're done
|
||||
//if (dispatchID >= pParams.propagateBuffer[0])
|
||||
//if(dispatchID > 0)
|
||||
// return;
|
||||
for(uint i = 0; i < pParams.propagateBuffer[0]; ++i)
|
||||
{
|
||||
PropagateBisectElement(pParams.propagateBuffer[2 + i]);
|
||||
}
|
||||
// If this element doesn't need to be processed, we're done
|
||||
if (dispatchID >= pParams.propagateBuffer[0])
|
||||
return;
|
||||
//for(uint i = 0; i < pParams.propagateBuffer[0]; ++i)
|
||||
//{
|
||||
PropagateBisectElement(pParams.propagateBuffer[2 + dispatchID]);
|
||||
//}
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
[numthreads(WORKGROUP_SIZE, 1, 1)]
|
||||
void PrepareSimplify(uint dispatchID : SV_DispatchThreadID)
|
||||
{
|
||||
if(dispatchID > 0)
|
||||
return;
|
||||
// If this element doesn't need to be processed, we're done
|
||||
//if (dispatchID >= pParams.classificationBuffer[SIMPLIFY_COUNTER])
|
||||
//if(dispatchID > 0)
|
||||
// return;
|
||||
for(uint i = 0; i < pParams.classificationBuffer[SIMPLIFY_COUNTER]; ++i)
|
||||
{
|
||||
// Grab the real elementID
|
||||
uint currentID = pParams.classificationBuffer[CLASSIFY_COUNTER_OFFSET + pParams.geometry.totalNumElements + i];
|
||||
// If this element doesn't need to be processed, we're done
|
||||
if (dispatchID >= pParams.classificationBuffer[SIMPLIFY_COUNTER])
|
||||
return;
|
||||
//for(uint i = 0; i < pParams.classificationBuffer[SIMPLIFY_COUNTER]; ++i)
|
||||
//{
|
||||
// Grab the real elementID
|
||||
uint currentID = pParams.classificationBuffer[CLASSIFY_COUNTER_OFFSET + pParams.geometry.totalNumElements + dispatchID];
|
||||
|
||||
// Simplify an element
|
||||
PrepareSimplifyElement(currentID);
|
||||
}
|
||||
// Simplify an element
|
||||
PrepareSimplifyElement(currentID);
|
||||
//}
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
[numthreads(WORKGROUP_SIZE, 1, 1)]
|
||||
void Simplify(uint dispatchID : SV_DispatchThreadID)
|
||||
{
|
||||
if(dispatchID > 0)
|
||||
return;
|
||||
// This thread doesn't have any work to do, we're done
|
||||
//if (currentID >= pParams.simplifyBuffer[0])
|
||||
//if(dispatchID > 0)
|
||||
// return;
|
||||
for(uint i = 0; i < pParams.simplifyBuffer[0]; ++i)
|
||||
{
|
||||
// Simplify an element
|
||||
SimplifyElement(pParams.simplifyBuffer[1 + i]);
|
||||
}
|
||||
// This thread doesn't have any work to do, we're done
|
||||
if (dispatchID >= pParams.simplifyBuffer[0])
|
||||
return;
|
||||
//for(uint i = 0; i < pParams.simplifyBuffer[0]; ++i)
|
||||
//{
|
||||
// Simplify an element
|
||||
SimplifyElement(pParams.simplifyBuffer[1 + dispatchID]);
|
||||
//}
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
[numthreads(WORKGROUP_SIZE, 1, 1)]
|
||||
void PropagateSimplify(uint dispatchID : SV_DispatchThreadID)
|
||||
{
|
||||
if(dispatchID > 0)
|
||||
return;
|
||||
// If this element doesn't need to be processed, we're done
|
||||
//if (dispatchID >= pParams.propagateBuffer[1])
|
||||
//if(dispatchID > 0)
|
||||
// return;
|
||||
for(uint i = 0; i < pParams.propagateBuffer[1]; ++i)
|
||||
{
|
||||
PropagateElementSimplify(pParams.propagateBuffer[2 + i]);
|
||||
}
|
||||
// If this element doesn't need to be processed, we're done
|
||||
if (dispatchID >= pParams.propagateBuffer[1])
|
||||
return;
|
||||
//for(uint i = 0; i < pParams.propagateBuffer[1]; ++i)
|
||||
//{
|
||||
PropagateElementSimplify(pParams.propagateBuffer[2 + dispatchID]);
|
||||
//}
|
||||
}
|
||||
|
||||
[numthreads(WORKGROUP_SIZE, 1, 1)]
|
||||
@@ -180,20 +178,20 @@ void ReduceSecondPass(uint groupIndex : SV_GroupIndex)
|
||||
reduce_second_pass(groupIndex);
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
[numthreads(WORKGROUP_SIZE, 1, 1)]
|
||||
void BisectorIndexation(uint currentID : SV_DispatchThreadID)
|
||||
{
|
||||
if(currentID > 0)
|
||||
return;
|
||||
// This thread doesn't have any work to do, we're done
|
||||
//if (currentID >= pParams.geometry.totalNumElements)
|
||||
//if(currentID > 0)
|
||||
// return;
|
||||
// This thread doesn't have any work to do, we're done
|
||||
if (currentID >= pParams.geometry.totalNumElements)
|
||||
return;
|
||||
|
||||
for(uint i = 0; i < pParams.geometry.totalNumElements; ++i)
|
||||
{
|
||||
// Indexate this bisector
|
||||
BisectorElementIndexation(i);
|
||||
}
|
||||
//for(uint i = 0; i < pParams.geometry.totalNumElements; ++i)
|
||||
//{
|
||||
// Indexate this bisector
|
||||
BisectorElementIndexation(currentID);
|
||||
//}
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
|
||||
@@ -237,12 +237,6 @@ void ClearBuffer(uint currentID : SV_DispatchThreadID)
|
||||
pParams.lebPositionBuffer[currentID] = float4(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float3 TransformToPlanetCoordinate(float3 posPS)
|
||||
{
|
||||
// Evaluate the planet position
|
||||
return normalize(posPS);
|
||||
}
|
||||
|
||||
[[vk::push_constant]]
|
||||
ConstantBuffer<uint> preRendering;
|
||||
struct Triangle
|
||||
@@ -316,9 +310,9 @@ void EvaluateLEB(uint currentID : SV_DispatchThreadID, uint groupIndex: SV_Group
|
||||
EvaluateElementPosition(cHeapID, 0, pParams.geometry.baseDepth, pParams.currentVertexBuffer, parentTri, childTri);
|
||||
|
||||
// Export the child
|
||||
pParams.lebPositionBuffer[3 * currentID] = float4(TransformToPlanetCoordinate(childTri.p[0]), 1.0f);
|
||||
pParams.lebPositionBuffer[3 * currentID + 1] = float4(TransformToPlanetCoordinate(childTri.p[1]), 1.0f);
|
||||
pParams.lebPositionBuffer[3 * currentID + 2] = float4(TransformToPlanetCoordinate(childTri.p[2]), 1.0f);
|
||||
pParams.lebPositionBuffer[3 * currentID] = float4((childTri.p[0]), 1.0f);
|
||||
pParams.lebPositionBuffer[3 * currentID + 1] = float4((childTri.p[1]), 1.0f);
|
||||
pParams.lebPositionBuffer[3 * currentID + 2] = float4((childTri.p[2]), 1.0f);
|
||||
|
||||
// Export the fourth element
|
||||
if (pParams.geometry.baseDepth < depth)
|
||||
@@ -327,6 +321,6 @@ void EvaluateLEB(uint currentID : SV_DispatchThreadID, uint groupIndex: SV_Group
|
||||
const uint parentOffset = 3 * pParams.geometry.totalNumElements;
|
||||
|
||||
// Transform the coordinate to planet space
|
||||
pParams.lebPositionBuffer[parentOffset + currentID] = float4(TransformToPlanetCoordinate(cHeapID % 2 == 0 ? parentTri.p[0] : parentTri.p[2]), 1.0f);
|
||||
pParams.lebPositionBuffer[parentOffset + currentID] = float4((cHeapID % 2 == 0 ? parentTri.p[0] : parentTri.p[2]), 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ struct DeformationCB
|
||||
|
||||
struct UpdateCB
|
||||
{
|
||||
float4x4 viewProjectionMatrix;
|
||||
float triangleSize;
|
||||
uint32_t maxSubdivisionDepth;
|
||||
float fov;
|
||||
|
||||
@@ -62,7 +62,7 @@ int ClassifyBisector(in BisectorGeometry tri, uint depth)
|
||||
return FRUSTUM_CULLED;
|
||||
|
||||
// Project the points on screen
|
||||
float4x4 viewProjectionMatrix = pParams.update.viewProjectionMatrix;//mul(pViewParams.projectionMatrix, pViewParams.viewMatrix);
|
||||
float4x4 viewProjectionMatrix = mul(pViewParams.projectionMatrix, pViewParams.viewMatrix);
|
||||
float4 p0P = mul(viewProjectionMatrix, float4(tri.p[0], 1.0));
|
||||
p0P.xy = p0P.xy / p0P.w;
|
||||
p0P.xy = (p0P.xy * 0.5 + 0.5);
|
||||
@@ -402,15 +402,11 @@ void evaluate_neighbors(uint currentID, uint bisectorID, out uint resX, out uint
|
||||
}
|
||||
}
|
||||
|
||||
void BisectElement(uint currentID, uint dispatchID)
|
||||
void BisectElement(uint currentID)
|
||||
{
|
||||
DebugStruct debug;
|
||||
// If this bisector is not allocated or not subdivided, stop right away
|
||||
uint64_t baseHeapID = pParams.heapIDBuffer[currentID];
|
||||
BisectorData cBisectorData = pParams.bisectorDataBuffer[currentID];
|
||||
debug.baseHeapID = baseHeapID;
|
||||
debug.subdivision = cBisectorData.subdivisionPattern;
|
||||
debug.propagateLocation = 0;
|
||||
if (baseHeapID == 0 || cBisectorData.subdivisionPattern == NO_SPLIT)
|
||||
return;
|
||||
|
||||
@@ -428,11 +424,6 @@ void BisectElement(uint currentID, uint dispatchID)
|
||||
uint siblingID1 = cBisectorData.indices[1];
|
||||
uint siblingID2 = cBisectorData.indices[2];
|
||||
|
||||
debug.indices[0] = cBisectorData.indices[0];
|
||||
debug.indices[1] = cBisectorData.indices[1];
|
||||
debug.indices[2] = cBisectorData.indices[2];
|
||||
debug.indices[3] = 0;
|
||||
|
||||
// Simple subdivision (along the main axis)
|
||||
if (currentSubdiv == CENTER_SPLIT)
|
||||
{
|
||||
@@ -476,7 +467,6 @@ void BisectElement(uint currentID, uint dispatchID)
|
||||
uint targetLocation = 0;
|
||||
InterlockedAdd(pParams.propagateBuffer[0], 1, targetLocation);
|
||||
pParams.propagateBuffer[2 + targetLocation] = siblingID0;
|
||||
debug.propagateLocation = targetLocation;
|
||||
}
|
||||
else if (currentSubdiv == RIGHT_DOUBLE_SPLIT)
|
||||
{
|
||||
@@ -535,7 +525,6 @@ void BisectElement(uint currentID, uint dispatchID)
|
||||
uint targetLocation = 0;
|
||||
InterlockedAdd(pParams.propagateBuffer[0], 1, targetLocation);
|
||||
pParams.propagateBuffer[2 + targetLocation] = siblingID0;
|
||||
debug.propagateLocation = targetLocation;
|
||||
}
|
||||
else if (currentSubdiv == LEFT_DOUBLE_SPLIT)
|
||||
{
|
||||
@@ -659,8 +648,6 @@ void BisectElement(uint currentID, uint dispatchID)
|
||||
|
||||
// How many bits do we need to raise
|
||||
uint numSiblings = countbits(currentSubdiv);
|
||||
debug.numSiblings = numSiblings;
|
||||
pParams.debugBuffer[dispatchID] = debug;
|
||||
for (uint siblingIdx = 0; siblingIdx < numSiblings; ++siblingIdx)
|
||||
{
|
||||
set_bit_atomic(cBisectorData.indices[siblingIdx], true);
|
||||
|
||||
Reference in New Issue
Block a user