From f1316eb2135130622b03acece79ccbdd07e2e906 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Mon, 21 Oct 2024 21:40:48 +0200 Subject: [PATCH] Removing tons of debugging and sync code --- res/shaders/terrain/CBT.slang | 65 +++-- res/shaders/terrain/CBTCompute.slang | 202 +++++++------- res/shaders/terrain/LEB.slang | 14 +- res/shaders/terrain/Parameters.slang | 1 - res/shaders/terrain/update_utils.slang | 17 +- src/Engine/Graphics/CBT/CBT.cpp | 246 ++++++++++-------- src/Engine/Graphics/CBT/CBT.h | 5 +- .../Graphics/RenderPass/TerrainRenderer.cpp | 33 --- 8 files changed, 285 insertions(+), 298 deletions(-) diff --git a/res/shaders/terrain/CBT.slang b/res/shaders/terrain/CBT.slang index 43fceb9..700ad31 100644 --- a/res/shaders/terrain/CBT.slang +++ b/res/shaders/terrain/CBT.slang @@ -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) diff --git a/res/shaders/terrain/CBTCompute.slang b/res/shaders/terrain/CBTCompute.slang index 3faf50e..e6ef82b 100644 --- a/res/shaders/terrain/CBTCompute.slang +++ b/res/shaders/terrain/CBTCompute.slang @@ -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)] diff --git a/res/shaders/terrain/LEB.slang b/res/shaders/terrain/LEB.slang index 8527d80..e629445 100644 --- a/res/shaders/terrain/LEB.slang +++ b/res/shaders/terrain/LEB.slang @@ -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 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); } } diff --git a/res/shaders/terrain/Parameters.slang b/res/shaders/terrain/Parameters.slang index 2c13d9d..b321a66 100644 --- a/res/shaders/terrain/Parameters.slang +++ b/res/shaders/terrain/Parameters.slang @@ -20,7 +20,6 @@ struct DeformationCB struct UpdateCB { - float4x4 viewProjectionMatrix; float triangleSize; uint32_t maxSubdivisionDepth; float fov; diff --git a/res/shaders/terrain/update_utils.slang b/res/shaders/terrain/update_utils.slang index c7ee4a3..b665e4b 100644 --- a/res/shaders/terrain/update_utils.slang +++ b/res/shaders/terrain/update_utils.slang @@ -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); diff --git a/src/Engine/Graphics/CBT/CBT.cpp b/src/Engine/Graphics/CBT/CBT.cpp index f4b5f25..6c7145b 100644 --- a/src/Engine/Graphics/CBT/CBT.cpp +++ b/src/Engine/Graphics/CBT/CBT.cpp @@ -4,16 +4,16 @@ using namespace Seele; Array basePoints = { - //Vector4(0.0f / 3, 0, 0.0f / 3, 1), Vector4(0.0f / 3, 0, 1.0f / 3, 1), Vector4(0.0f / 3, 0, 2.0f / 3, 1), - //Vector4(0.0f / 3, 0, 3.0f / 3, 1), Vector4(1.0f / 3, 0, 0.0f / 3, 1), Vector4(1.0f / 3, 0, 1.0f / 3, 1), - //Vector4(1.0f / 3, 0, 2.0f / 3, 1), Vector4(1.0f / 3, 0, 3.0f / 3, 1), Vector4(2.0f / 3, 0, 0.0f / 3, 1), - //Vector4(2.0f / 3, 0, 1.0f / 3, 1), Vector4(2.0f / 3, 0, 2.0f / 3, 1), Vector4(2.0f / 3, 0, 3.0f / 3, 1), - //Vector4(3.0f / 3, 0, 0.0f / 3, 1), Vector4(3.0f / 3, 0, 1.0f / 3, 1), Vector4(3.0f / 3, 0, 2.0f / 3, 1), - //Vector4(3.0f / 3, 0, 3.0f / 3, 1), - Vector4(0, -0.525731, 0.850651, 1), Vector4(0.850651, 0, 0.525731, 1), Vector4(0.850651, 0, -0.525731, 1), - Vector4(-0.850651, 0, -0.525731, 1), Vector4(-0.850651, 0, 0.525731, 1), Vector4(-0.525731, 0.850651, 0, 1), - Vector4(0.525731, 0.850651, 0, 1), Vector4(0.525731, -0.850651, 0, 1), Vector4(-0.525731, -0.850651, 0, 1), - Vector4(0, -0.525731, -0.850651, 1), Vector4(0, 0.525731, -0.850651, 1), Vector4(0, 0.525731, 0.850651, 1), + Vector4(0.0f / 3, 0, 0.0f / 3, 1), Vector4(0.0f / 3, 0, 1.0f / 3, 1), Vector4(0.0f / 3, 0, 2.0f / 3, 1), + Vector4(0.0f / 3, 0, 3.0f / 3, 1), Vector4(1.0f / 3, 0, 0.0f / 3, 1), Vector4(1.0f / 3, 0, 1.0f / 3, 1), + Vector4(1.0f / 3, 0, 2.0f / 3, 1), Vector4(1.0f / 3, 0, 3.0f / 3, 1), Vector4(2.0f / 3, 0, 0.0f / 3, 1), + Vector4(2.0f / 3, 0, 1.0f / 3, 1), Vector4(2.0f / 3, 0, 2.0f / 3, 1), Vector4(2.0f / 3, 0, 3.0f / 3, 1), + Vector4(3.0f / 3, 0, 0.0f / 3, 1), Vector4(3.0f / 3, 0, 1.0f / 3, 1), Vector4(3.0f / 3, 0, 2.0f / 3, 1), + Vector4(3.0f / 3, 0, 3.0f / 3, 1), + // Vector4(0, -0.525731, 0.850651, 1), Vector4(0.850651, 0, 0.525731, 1), Vector4(0.850651, 0, -0.525731, 1), + // Vector4(-0.850651, 0, -0.525731, 1), Vector4(-0.850651, 0, 0.525731, 1), Vector4(-0.525731, 0.850651, 0, 1), + // Vector4(0.525731, 0.850651, 0, 1), Vector4(0.525731, -0.850651, 0, 1), Vector4(-0.525731, -0.850651, 0, 1), + // Vector4(0, -0.525731, -0.850651, 1), Vector4(0, 0.525731, -0.850651, 1), Vector4(0, 0.525731, 0.850651, 1), }; struct Halfedge { uint32 vertexID; @@ -22,73 +22,73 @@ struct Halfedge { uint32 twinID; }; Array edges = { - //Halfedge{0, 1, 2, 4294967295}, - //Halfedge{1, 2, 0, 3}, - //Halfedge{4, 0, 1, 4294967295}, - //Halfedge{4, 4, 5, 1}, - //Halfedge{1, 5, 3, 8}, - //Halfedge{5, 3, 4, 18}, - //Halfedge{1, 7, 8, 4294967295}, - //Halfedge{2, 8, 6, 9}, - //Halfedge{5, 6, 7, 4}, - //Halfedge{5, 10, 11, 7}, - //Halfedge{2, 11, 9, 14}, - //Halfedge{6, 9, 10, 24}, - //Halfedge{2, 13, 14, 4294967295}, - //Halfedge{3, 14, 12, 15}, - //Halfedge{6, 12, 13, 10}, - //Halfedge{6, 16, 17, 13}, - //Halfedge{3, 17, 15, 4294967295}, - //Halfedge{7, 15, 16, 30}, - //Halfedge{4, 19, 20, 5}, - //Halfedge{5, 20, 18, 21}, - //Halfedge{8, 18, 19, 4294967295}, - //Halfedge{8, 22, 23, 19}, - //Halfedge{5, 23, 21, 26}, - //Halfedge{9, 21, 22, 36}, - //Halfedge{5, 25, 26, 11}, - //Halfedge{6, 26, 24, 27}, - //Halfedge{9, 24, 25, 22}, - //Halfedge{9, 28, 29, 25}, - //Halfedge{6, 29, 27, 32}, - //Halfedge{10, 27, 28, 42}, - //Halfedge{6, 31, 32, 17}, - //Halfedge{7, 32, 30, 33}, - //Halfedge{10, 30, 31, 28}, - //Halfedge{10, 34, 35, 31}, - //Halfedge{7, 35, 33, 4294967295}, - //Halfedge{11, 33, 34, 48}, - //Halfedge{8, 37, 38, 23}, - //Halfedge{9, 38, 36, 39}, - //Halfedge{12, 36, 37, 4294967295}, - //Halfedge{12, 40, 41, 37}, - //Halfedge{9, 41, 39, 44}, - //Halfedge{13, 39, 40, 4294967295}, - //Halfedge{9, 43, 44, 29}, - //Halfedge{10, 44, 42, 45}, - //Halfedge{13, 42, 43, 40}, - //Halfedge{13, 46, 47, 43}, - //Halfedge{10, 47, 45, 50}, - //Halfedge{14, 45, 46, 4294967295}, - //Halfedge{10, 49, 50, 35}, - //Halfedge{11, 50, 48, 51}, - //Halfedge{14, 48, 49, 46}, - //Halfedge{14, 52, 53, 49}, - //Halfedge{11, 53, 51, 4294967295}, - //Halfedge{15, 51, 52, 4294967295}, - - Halfedge{1, 1, 2, 5}, Halfedge{2, 2, 0, 36}, Halfedge{6, 0, 1, 39}, Halfedge{1, 4, 5, 51}, Halfedge{7, 5, 3, 48}, - Halfedge{2, 3, 4, 0}, Halfedge{3, 7, 8, 9}, Halfedge{4, 8, 6, 45}, Halfedge{5, 6, 7, 42}, Halfedge{4, 10, 11, 6}, - Halfedge{3, 11, 9, 56}, Halfedge{8, 9, 10, 57}, Halfedge{6, 13, 14, 15}, Halfedge{5, 14, 12, 47}, Halfedge{11, 12, 13, 40}, - Halfedge{5, 16, 17, 12}, Halfedge{6, 17, 15, 38}, Halfedge{10, 15, 16, 43}, Halfedge{9, 19, 20, 21}, Halfedge{10, 20, 18, 37}, - Halfedge{2, 18, 19, 50}, Halfedge{10, 22, 23, 18}, Halfedge{9, 23, 21, 54}, Halfedge{3, 21, 22, 44}, Halfedge{7, 25, 26, 27}, - Halfedge{8, 26, 24, 55}, Halfedge{9, 24, 25, 49}, Halfedge{8, 28, 29, 24}, Halfedge{7, 29, 27, 53}, Halfedge{0, 27, 28, 58}, - Halfedge{11, 31, 32, 33}, Halfedge{0, 32, 30, 52}, Halfedge{1, 30, 31, 41}, Halfedge{0, 34, 35, 30}, Halfedge{11, 35, 33, 46}, - Halfedge{4, 33, 34, 59}, Halfedge{6, 37, 38, 1}, Halfedge{2, 38, 36, 19}, Halfedge{10, 36, 37, 16}, Halfedge{1, 40, 41, 2}, - Halfedge{6, 41, 39, 14}, Halfedge{11, 39, 40, 32}, Halfedge{3, 43, 44, 8}, Halfedge{5, 44, 42, 17}, Halfedge{10, 42, 43, 23}, - Halfedge{5, 46, 47, 7}, Halfedge{4, 47, 45, 34}, Halfedge{11, 45, 46, 13}, Halfedge{2, 49, 50, 4}, Halfedge{7, 50, 48, 26}, - Halfedge{9, 48, 49, 20}, Halfedge{7, 52, 53, 3}, Halfedge{1, 53, 51, 31}, Halfedge{0, 51, 52, 28}, Halfedge{3, 55, 56, 22}, - Halfedge{9, 56, 54, 25}, Halfedge{8, 54, 55, 10}, Halfedge{4, 58, 59, 11}, Halfedge{8, 59, 57, 29}, Halfedge{0, 57, 58, 35}, + Halfedge{0, 1, 2, 4294967295}, + Halfedge{1, 2, 0, 3}, + Halfedge{4, 0, 1, 4294967295}, + Halfedge{4, 4, 5, 1}, + Halfedge{1, 5, 3, 8}, + Halfedge{5, 3, 4, 18}, + Halfedge{1, 7, 8, 4294967295}, + Halfedge{2, 8, 6, 9}, + Halfedge{5, 6, 7, 4}, + Halfedge{5, 10, 11, 7}, + Halfedge{2, 11, 9, 14}, + Halfedge{6, 9, 10, 24}, + Halfedge{2, 13, 14, 4294967295}, + Halfedge{3, 14, 12, 15}, + Halfedge{6, 12, 13, 10}, + Halfedge{6, 16, 17, 13}, + Halfedge{3, 17, 15, 4294967295}, + Halfedge{7, 15, 16, 30}, + Halfedge{4, 19, 20, 5}, + Halfedge{5, 20, 18, 21}, + Halfedge{8, 18, 19, 4294967295}, + Halfedge{8, 22, 23, 19}, + Halfedge{5, 23, 21, 26}, + Halfedge{9, 21, 22, 36}, + Halfedge{5, 25, 26, 11}, + Halfedge{6, 26, 24, 27}, + Halfedge{9, 24, 25, 22}, + Halfedge{9, 28, 29, 25}, + Halfedge{6, 29, 27, 32}, + Halfedge{10, 27, 28, 42}, + Halfedge{6, 31, 32, 17}, + Halfedge{7, 32, 30, 33}, + Halfedge{10, 30, 31, 28}, + Halfedge{10, 34, 35, 31}, + Halfedge{7, 35, 33, 4294967295}, + Halfedge{11, 33, 34, 48}, + Halfedge{8, 37, 38, 23}, + Halfedge{9, 38, 36, 39}, + Halfedge{12, 36, 37, 4294967295}, + Halfedge{12, 40, 41, 37}, + Halfedge{9, 41, 39, 44}, + Halfedge{13, 39, 40, 4294967295}, + Halfedge{9, 43, 44, 29}, + Halfedge{10, 44, 42, 45}, + Halfedge{13, 42, 43, 40}, + Halfedge{13, 46, 47, 43}, + Halfedge{10, 47, 45, 50}, + Halfedge{14, 45, 46, 4294967295}, + Halfedge{10, 49, 50, 35}, + Halfedge{11, 50, 48, 51}, + Halfedge{14, 48, 49, 46}, + Halfedge{14, 52, 53, 49}, + Halfedge{11, 53, 51, 4294967295}, + Halfedge{15, 51, 52, 4294967295}, + + // Halfedge{1, 1, 2, 5}, Halfedge{2, 2, 0, 36}, Halfedge{6, 0, 1, 39}, Halfedge{1, 4, 5, 51}, Halfedge{7, 5, 3, 48}, + // Halfedge{2, 3, 4, 0}, Halfedge{3, 7, 8, 9}, Halfedge{4, 8, 6, 45}, Halfedge{5, 6, 7, 42}, Halfedge{4, 10, 11, 6}, + // Halfedge{3, 11, 9, 56}, Halfedge{8, 9, 10, 57}, Halfedge{6, 13, 14, 15}, Halfedge{5, 14, 12, 47}, Halfedge{11, 12, 13, 40}, + // Halfedge{5, 16, 17, 12}, Halfedge{6, 17, 15, 38}, Halfedge{10, 15, 16, 43}, Halfedge{9, 19, 20, 21}, Halfedge{10, 20, 18, 37}, + // Halfedge{2, 18, 19, 50}, Halfedge{10, 22, 23, 18}, Halfedge{9, 23, 21, 54}, Halfedge{3, 21, 22, 44}, Halfedge{7, 25, 26, 27}, + // Halfedge{8, 26, 24, 55}, Halfedge{9, 24, 25, 49}, Halfedge{8, 28, 29, 24}, Halfedge{7, 29, 27, 53}, Halfedge{0, 27, 28, 58}, + // Halfedge{11, 31, 32, 33}, Halfedge{0, 32, 30, 52}, Halfedge{1, 30, 31, 41}, Halfedge{0, 34, 35, 30}, Halfedge{11, 35, 33, 46}, + // Halfedge{4, 33, 34, 59}, Halfedge{6, 37, 38, 1}, Halfedge{2, 38, 36, 19}, Halfedge{10, 36, 37, 16}, Halfedge{1, 40, 41, 2}, + // Halfedge{6, 41, 39, 14}, Halfedge{11, 39, 40, 32}, Halfedge{3, 43, 44, 8}, Halfedge{5, 44, 42, 17}, Halfedge{10, 42, 43, 23}, + // Halfedge{5, 46, 47, 7}, Halfedge{4, 47, 45, 34}, Halfedge{11, 45, 46, 13}, Halfedge{2, 49, 50, 4}, Halfedge{7, 50, 48, 26}, + // Halfedge{9, 48, 49, 20}, Halfedge{7, 52, 53, 3}, Halfedge{1, 53, 51, 31}, Halfedge{0, 51, 52, 28}, Halfedge{3, 55, 56, 22}, + // Halfedge{9, 56, 54, 25}, Halfedge{8, 54, 55, 10}, Halfedge{4, 58, 59, 11}, Halfedge{8, 59, 57, 29}, Halfedge{0, 57, 58, 35}, }; uint32_t find_msb_64(uint64_t x) { @@ -414,11 +414,11 @@ void MeshUpdater::evaluateLeb(const BaseMesh& baseMesh, CBTMesh& mesh, Gfx::PDes clearCmd->bindDescriptor(set); clearCmd->dispatch((mesh.totalNumElements * 3 + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE, 1, 1); graphics->executeCommands(std::move(clearCmd)); - mesh.currentVertexBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.lebVertexBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT, + Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); graphics->endDebugRegion(); } - graphics->waitDeviceIdle(); graphics->beginDebugRegion("EvaluateLEB"); Gfx::PDescriptorSet set = layout->allocateDescriptorSet(); set->updateBuffer(GEOMETRY_CB, 0, geometryBuffer); @@ -438,7 +438,7 @@ void MeshUpdater::evaluateLeb(const BaseMesh& baseMesh, CBTMesh& mesh, Gfx::PDes evalCmd->dispatchIndirect(mesh.indirectDispatchBuffer, complete ? 0 : sizeof(uint32) * 6); graphics->executeCommands(std::move(evalCmd)); mesh.lebVertexBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); graphics->endDebugRegion(); } @@ -448,7 +448,6 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: Gfx::PShaderBuffer nextNeighborsBuffer = mesh.neighborsBuffers[nextNeighborsBufferIdx]; resetBuffers(mesh); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("Classify"); { Gfx::PDescriptorSet set = layout->allocateDescriptorSet(); @@ -470,9 +469,10 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: graphics->executeCommands(std::move(classifyCmd)); mesh.updateBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.classificationBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("PrepareIndirect"); { @@ -486,11 +486,9 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: prepareIndirectCmd->dispatch(2, 1, 1); graphics->executeCommands(std::move(prepareIndirectCmd)); indirectBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + Gfx::SE_ACCESS_INDIRECT_COMMAND_READ_BIT, Gfx::SE_PIPELINE_STAGE_DRAW_INDIRECT_BIT); } graphics->endDebugRegion(); - - graphics->waitDeviceIdle(); graphics->beginDebugRegion("Split"); { Gfx::PDescriptorSet set = layout->allocateDescriptorSet(); @@ -509,13 +507,14 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: splitCmd->bindDescriptor({viewParamsSet, set}); splitCmd->dispatchIndirect(indirectBuffer, 0); graphics->executeCommands(std::move(splitCmd)); + memoryBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); mesh.updateBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); mesh.allocateBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("PrepareIndirect"); { @@ -529,10 +528,9 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: prepareIndirectCmd->dispatch(1, 1, 1); graphics->executeCommands(std::move(prepareIndirectCmd)); indirectBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + Gfx::SE_ACCESS_INDIRECT_COMMAND_READ_BIT, Gfx::SE_PIPELINE_STAGE_DRAW_INDIRECT_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("Allocate"); { @@ -551,11 +549,12 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: allocateCmd->bindDescriptor({viewParamsSet, set}); allocateCmd->dispatchIndirect(indirectBuffer, 0); graphics->executeCommands(std::move(allocateCmd)); + memoryBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); mesh.updateBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("Copy"); currentNeighborsBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, @@ -564,7 +563,6 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: nextNeighborsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("Bisect"); { @@ -589,9 +587,14 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: graphics->executeCommands(std::move(bisectCmd)); nextNeighborsBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.heapIDBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.propagateBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.gpuCBT.bufferArray[1]->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("PrepareIndirect"); { @@ -605,10 +608,9 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: prepareIndirectCmd->dispatch(1, 1, 1); graphics->executeCommands(std::move(prepareIndirectCmd)); indirectBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + Gfx::SE_ACCESS_INDIRECT_COMMAND_READ_BIT, Gfx::SE_PIPELINE_STAGE_DRAW_INDIRECT_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("PropagateBisect"); { @@ -627,9 +629,10 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: graphics->executeCommands(std::move(propagateBisectCmd)); mesh.updateBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + nextNeighborsBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("PrepareSimplify"); { @@ -652,7 +655,6 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("PrepareIndirectSimplify"); { @@ -666,10 +668,9 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: prepareIndirectCmd->dispatch(1, 1, 1); graphics->executeCommands(std::move(prepareIndirectCmd)); indirectBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + Gfx::SE_ACCESS_INDIRECT_COMMAND_READ_BIT, Gfx::SE_PIPELINE_STAGE_DRAW_INDIRECT_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("Simplify"); { @@ -692,9 +693,16 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: graphics->executeCommands(std::move(simplifyCmd)); nextNeighborsBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.heapIDBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.updateBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.propagateBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.gpuCBT.bufferArray[1]->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("PrepareIndirectPropagateSimplify"); { @@ -708,10 +716,9 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: prepareIndirectCmd->dispatch(2, 1, 1); graphics->executeCommands(std::move(prepareIndirectCmd)); indirectBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + Gfx::SE_ACCESS_INDIRECT_COMMAND_READ_BIT, Gfx::SE_PIPELINE_STAGE_DRAW_INDIRECT_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("PropagateSimplify"); { @@ -731,9 +738,10 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: graphics->executeCommands(std::move(propagateSimplifyCmd)); nextNeighborsBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.updateBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("Update Tree"); { @@ -767,15 +775,13 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); mesh.currentNeighborsBufferIdx = nextNeighborsBufferIdx; prepareIndirection(mesh, geometryCB); - graphics->waitDeviceIdle(); } -void MeshUpdater::validation(const CBTMesh& mesh, Gfx::PUniformBuffer geometryCB) { +void MeshUpdater::validation(CBTMesh& mesh, Gfx::PUniformBuffer geometryCB) { uint32 numGroups = (mesh.totalNumElements + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE; Gfx::PDescriptorSet set = layout->allocateDescriptorSet(); @@ -797,7 +803,7 @@ void MeshUpdater::validation(const CBTMesh& mesh, Gfx::PUniformBuffer geometryCB graphics->copyBuffer(validationBuffer, validationBufferRB); } -void MeshUpdater::resetBuffers(const CBTMesh& mesh) { +void MeshUpdater::resetBuffers(CBTMesh& mesh) { graphics->beginDebugRegion("ResetBuffers"); Gfx::PDescriptorSet set = layout->allocateDescriptorSet(); set->updateBuffer(CBT_BUFFER0, 0, mesh.gpuCBT.bufferArray[0]); @@ -817,13 +823,21 @@ void MeshUpdater::resetBuffers(const CBTMesh& mesh) { graphics->executeCommands(std::move(resetCmd)); memoryBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.classificationBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.allocateBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.propagateBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.simplificationBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.indirectDrawBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); graphics->endDebugRegion(); } void MeshUpdater::prepareIndirection(CBTMesh& mesh, Gfx::PUniformBuffer geometryCB) { uint32 numGroups = (mesh.totalNumElements + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE; - - graphics->waitDeviceIdle(); graphics->beginDebugRegion("BisectorIndexation"); { Gfx::PDescriptorSet set = layout->allocateDescriptorSet(); @@ -841,11 +855,16 @@ void MeshUpdater::prepareIndirection(CBTMesh& mesh, Gfx::PUniformBuffer geometry bisectorIndexationCmd->bindDescriptor(set); bisectorIndexationCmd->dispatch(numGroups, 1, 1); graphics->executeCommands(std::move(bisectorIndexationCmd)); + mesh.indirectDrawBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.indexedBisectorBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.visibleIndexedBisectorBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + mesh.modifiedIndexedBisectorBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); } - mesh.indirectDrawBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); graphics->endDebugRegion(); - graphics->waitDeviceIdle(); graphics->beginDebugRegion("PrepareBisectorIndirectDispatch"); { Gfx::PDescriptorSet set = layout->allocateDescriptorSet(); @@ -859,10 +878,11 @@ void MeshUpdater::prepareIndirection(CBTMesh& mesh, Gfx::PUniformBuffer geometry prepareBisectorIndirectCmd->dispatch(1, 1, 1); graphics->executeCommands(std::move(prepareBisectorIndirectCmd)); mesh.indirectDispatchBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + Gfx::SE_ACCESS_INDIRECT_COMMAND_READ_BIT, Gfx::SE_PIPELINE_STAGE_DRAW_INDIRECT_BIT); + mesh.indirectDrawBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); } graphics->endDebugRegion(); - graphics->waitDeviceIdle(); } bool MeshUpdater::checkIfValid() { return true; } diff --git a/src/Engine/Graphics/CBT/CBT.h b/src/Engine/Graphics/CBT/CBT.h index 07d6442..ce732ea 100644 --- a/src/Engine/Graphics/CBT/CBT.h +++ b/src/Engine/Graphics/CBT/CBT.h @@ -327,7 +327,6 @@ struct GeometryCB { uint32 totalNumVertices; }; struct UpdateCB { - Matrix4 viewProjectionMatrix; float triangleSize; uint32_t maxSubdivisionDepth; float fov; @@ -436,9 +435,9 @@ struct MeshUpdater { void update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx::PUniformBuffer geometryCB, Gfx::PUniformBuffer updateCB); - void validation(const CBTMesh& mesh, Gfx::PUniformBuffer geometryCB); + void validation(CBTMesh& mesh, Gfx::PUniformBuffer geometryCB); - void resetBuffers(const CBTMesh& mesh); + void resetBuffers(CBTMesh& mesh); void prepareIndirection(CBTMesh& mesh, Gfx::PUniformBuffer geometryCB); diff --git a/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp b/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp index 1c9d95f..4dba548 100644 --- a/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp +++ b/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp @@ -165,7 +165,6 @@ TerrainRenderer::TerrainRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDe { .size = sizeof(Vector4) * plainMesh.totalNumElements * 4, }, - .usage = Gfx::SE_BUFFER_USAGE_INDIRECT_BUFFER_BIT, .name = "CurrentVertexBuffer", }); plainMesh.currentDisplacementBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ @@ -222,7 +221,6 @@ TerrainRenderer::TerrainRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDe geometryBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); UpdateCB updateCB = { - .viewProjectionMatrix = Matrix4(0), .triangleSize = 60.0f, .maxSubdivisionDepth = 63, .fov = 1.22173f, @@ -255,18 +253,10 @@ TerrainRenderer::TerrainRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDe .computeShader = deformCS, .pipelineLayout = meshUpdater.pipelineLayout, }); - graphics->waitDeviceIdle(); - meshUpdater.resetBuffers(plainMesh); - graphics->waitDeviceIdle(); meshUpdater.prepareIndirection(plainMesh, geometryBuffer); - graphics->waitDeviceIdle(); meshUpdater.evaluateLeb(baseMesh, plainMesh, viewParamsSet, geometryBuffer, updateBuffer, lebCache.getLebMatrixBuffer(), true, true); - graphics->waitDeviceIdle(); applyDeformation(viewParamsSet); - graphics->waitDeviceIdle(); - meshUpdater.validation(plainMesh, geometryBuffer); - graphics->waitDeviceIdle(); } TerrainRenderer::~TerrainRenderer() {} @@ -274,32 +264,9 @@ TerrainRenderer::~TerrainRenderer() {} static bool first = true; void TerrainRenderer::beginFrame(Gfx::PDescriptorSet viewParamsSet, const Component::Camera& cam) { - UpdateCB updateCB = { - .viewProjectionMatrix = viewport->getProjectionMatrix() * cam.getViewMatrix(), - .triangleSize = 60.0f, - .maxSubdivisionDepth = 63, - .fov = 1.22173f, - .farPlaneDistance = 1000.0f, - }; - updateBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{ - .sourceData = - { - .size = sizeof(UpdateCB), - .data = (uint8*)&updateCB, - }, - .name = "UpdateCB", - }); - updateBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT, - Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); - graphics->waitDeviceIdle(); meshUpdater.update(plainMesh, viewParamsSet, geometryBuffer, updateBuffer); - graphics->waitDeviceIdle(); meshUpdater.evaluateLeb(baseMesh, plainMesh, viewParamsSet, geometryBuffer, updateBuffer, lebCache.getLebMatrixBuffer(), false, false); - graphics->waitDeviceIdle(); applyDeformation(viewParamsSet); - graphics->waitDeviceIdle(); - meshUpdater.validation(plainMesh, geometryBuffer); - graphics->waitDeviceIdle(); } Gfx::ORenderCommand TerrainRenderer::render(Gfx::PDescriptorSet viewParamsSet) {