Nothing works

This commit is contained in:
Dynamitos
2024-10-14 18:14:08 +02:00
parent 98a7e16756
commit 62d6662ad1
14 changed files with 244 additions and 187 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ include (ExternalProject)
add_library(slang SHARED IMPORTED) add_library(slang SHARED IMPORTED)
if(WIN32) if(WIN32)
add_library(slang-glslang SHARED IMPORTED) add_library(slang-glslang SHARED IMPORTED)
set(SLANG_ROOT ${PROJECT_SOURCE_DIR}/../slang/build/Debug/) set(SLANG_ROOT ${PROJECT_SOURCE_DIR}/../slang/build/Release/)
set_target_properties(slang-glslang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}bin/slang-glslang.dll) set_target_properties(slang-glslang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}bin/slang-glslang.dll)
set_target_properties(slang-glslang PROPERTIES IMPORTED_IMPLIB ${SLANG_ROOT}lib/slang.lib) set_target_properties(slang-glslang PROPERTIES IMPORTED_IMPLIB ${SLANG_ROOT}lib/slang.lib)
set_target_properties(slang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}bin/slang.dll) set_target_properties(slang PROPERTIES IMPORTED_LOCATION ${SLANG_ROOT}bin/slang.dll)
+3 -2
View File
@@ -55,7 +55,7 @@ float4 frag(PixelInput input) : SV_Target
[numthreads(64, 1, 1)] [numthreads(64, 1, 1)]
void deform(uint currentID: SV_DispatchThreadID) void deform(uint currentID: SV_DispatchThreadID)
{ {
if(currentID > pParams.indirectDrawBuffer[9] * 4) if(currentID >= pParams.indirectDrawBuffer[9] * 4)
return; return;
uint bisectorID = currentID / 4; uint bisectorID = currentID / 4;
@@ -66,6 +66,7 @@ void deform(uint currentID: SV_DispatchThreadID)
currentID = localVertexID < 3 ? bisectorID * 3 + localVertexID : 3 * pParams.geometry.totalNumElements + bisectorID; currentID = localVertexID < 3 ? bisectorID * 3 + localVertexID : 3 * pParams.geometry.totalNumElements + bisectorID;
float3 positionWS = pParams.lebPositionBuffer[currentID]; float3 positionWS = pParams.lebPositionBuffer[currentID];
float3 positionRWS = positionWS - pViewParams.cameraPosition_WS.xyz;
float3 positionPS = positionWS; float3 positionPS = positionWS;
@@ -73,5 +74,5 @@ void deform(uint currentID: SV_DispatchThreadID)
float2 sampleUV = float2(0, 0); float2 sampleUV = float2(0, 0);
pParams.currentVertexBuffer[currentID] = positionWS; pParams.currentVertexBuffer[currentID] = positionRWS;
} }
+7 -7
View File
@@ -2,13 +2,13 @@
const static int INVALID_POINTER = 4294967295; const static int INVALID_POINTER = 4294967295;
// Possible culling state // Possible culling state
const static int BACK_FACE_CULLED =-3; const static int BACK_FACE_CULLED = -3;
const static int FRUSTUM_CULLED =-2; const static int FRUSTUM_CULLED = -2;
const static int TOO_SMALL =-1; const static int TOO_SMALL = -1;
const static int UNCHANGED_ELEMENT= 0; const static int UNCHANGED_ELEMENT = 0;
const static int BISECT_ELEMENT= 1; const static int BISECT_ELEMENT = 1;
const static int SIMPLIFY_ELEMENT= 2; const static int SIMPLIFY_ELEMENT = 2;
const static int MERGED_ELEMENT= 3; const static int MERGED_ELEMENT = 3;
// Bisector flags // Bisector flags
const static int VISIBLE_BISECTOR = 0x1; const static int VISIBLE_BISECTOR = 0x1;
+38 -45
View File
@@ -1,26 +1,44 @@
import Parameters; import Parameters;
// The maximal size of the LDS is 16kbyte.
#ifndef WORKGROUP_SIZE #ifndef WORKGROUP_SIZE
#define WORKGROUP_SIZE 64 #define WORKGROUP_SIZE 64
#endif #endif
/*
Level 0: 32 bit // [0, 131072] x 1, needs a minimum of 18 bits (rounded up to 32 for alignment and required for atomic operations)
Level 1: 32 bit // [0, 65536] x 2, needs a minimum of 17 bits (rounded up to 32 for alignment and required for atomic operations)
Level 2: 32 bit // [0, 32768] x 4, needs a minimum of 16 bits (bumped to 32 bits for atomic operations)
Level 3: 32 bit // [0, 16384] x 8, needs a minimum of 15 bits (rounded up to 16 for alignment and bumped to 32 bits for atomic operations)
Level 4: 32 bit // [0, 8192] x 16, needs a minimum of 14 bits (rounded up to 16 for alignment and bumped to 32 bits for atomic operations)
Level 5: 32 bit // [0, 4096] x 32, needs a minimum of 13 bits (rounded up to 16 for alignment and bumped to 32 bits for atomic operations)
Level 6: 32 bit // [0, 2048] x 64, needs a minimum of 12 bits (rounded up to 16 for alignment and bumped to 32 bits for atomic operations)
Level 7: 16 bit // [0, 1024] x 128, needs a minimum of 11 bits (rounded up to 16 for alignment)
Level 8: 16 bit // [0, 512] x 256, needs a minimum of 10 bits (rounded up to 16 for alignment)
Level 9: 16 bit // [0, 256] x 512, needs a minimum of 9 bits (rounded up to 16 for alignment)
Level 10: 8 bit // [0, 128] x 1024, needs a minimum of 8 bits
Level 11: Raw 64 bits representation
*/
// Num elements // Num elements
#define OCBT_NUM_ELEMENTS 1048576 #define OCBT_NUM_ELEMENTS 131072
// Tree sizes // Tree sizes
#define OCBT_TREE_SIZE_BITS (32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256 + 16 * 512 + 16 * 1024 + 16* 2048 + 16 * 4096 + 8 * 8192) #define OCBT_TREE_SIZE_BITS (32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256 + 16 * 512 + 8 * 1024)
#define OCBT_TREE_NUM_SLOTS (OCBT_TREE_SIZE_BITS / 32) #define OCBT_TREE_NUM_SLOTS (OCBT_TREE_SIZE_BITS / 32)
#define OCBT_BITFIELD_NUM_SLOTS (OCBT_NUM_ELEMENTS / 64) #define OCBT_BITFIELD_NUM_SLOTS (OCBT_NUM_ELEMENTS / 64)
#define OCBT_LAST_LEVEL_SIZE 8192 #define OCBT_LAST_LEVEL_SIZE 1024
// Tree last level // Tree last level
#define TREE_LAST_LEVEL 13 #define TREE_LAST_LEVEL 10
// First virtual level // First virtual level
#define FIRST_VIRTUAL_LEVEL 14 #define FIRST_VIRTUAL_LEVEL 11
// Leaf level // Leaf level
#define LEAF_LEVEL 20 #define LEAF_LEVEL 17
// per level offset // per level offset
static const uint32_t OCBT_depth_offset[21] = { 0, // Level 0 static const uint32_t OCBT_depth_offset[18] = { 0, // Level 0
32 * 1, // level 1 32 * 1, // level 1
32 * 1 + 32 * 2, // level 2 32 * 1 + 32 * 2, // level 2
32 * 1 + 32 * 2 + 32 * 4, // level 3 32 * 1 + 32 * 2 + 32 * 4, // level 3
@@ -32,20 +50,17 @@ static const uint32_t OCBT_depth_offset[21] = { 0, // Level 0
32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128, // Level 8 32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128, // Level 8
32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256, // Level 9 32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256, // Level 9
32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256 + 16 * 512, // Level 10 32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256 + 16 * 512, // Level 10
32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256 + 16 * 512 + 16 * 1024, // Level 11
32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256 + 16 * 512 + 16 * 1024 + 16 * 2048, // Level 12
32 * 1 + 32 * 2 + 32 * 4 + 32 * 8 + 32 * 16 + 32 * 32 + 32 * 64 + 16 * 128 + 16 * 256 + 16 * 512 + 16 * 1024 + 16 * 2048 + 16 * 4096, // Level 13
0, // Level 12
0, // Level 13
0, // Level 14 0, // Level 14
0, // Level 15 0, // Level 15
0, // Level 16 0, // Level 16
0, // Level 17 0, // Level 17
0, // Level 18 0, // Level 18
0, // Level 19
0, // Level 20
}; };
static const uint64_t OCBT_bit_mask[21] = { 0xffffffff, // Root 17 static const uint64_t OCBT_bit_mask[18] = { 0xffffffff, // Root 17
0xffffffff, // Level 16 0xffffffff, // Level 16
0xffffffff, // level 15 0xffffffff, // level 15
0xffffffff, // level 14 0xffffffff, // level 14
@@ -56,9 +71,6 @@ static const uint64_t OCBT_bit_mask[21] = { 0xffffffff, // Root 17
0xffff, // level 10 0xffff, // level 10
0xffff, // level 9 0xffff, // level 9
0xffff, // level 8 0xffff, // level 8
0xffff, // level 8
0xffff, // level 8
0xffff, // level 8
0xff, // level 8 0xff, // level 8
0xffffffffffffffff, // level 7 0xffffffffffffffff, // level 7
@@ -70,7 +82,7 @@ static const uint64_t OCBT_bit_mask[21] = { 0xffffffff, // Root 17
0x1, // level 1 0x1, // level 1
}; };
static const uint32_t OCBT_bit_count[21] = { 32, // Root 17 static const uint32_t OCBT_bit_count[18] = { 32, // Root 17
32, // Level 16 32, // Level 16
32, // level 15 32, // level 15
32, // level 14 32, // level 14
@@ -81,9 +93,6 @@ static const uint32_t OCBT_bit_count[21] = { 32, // Root 17
16, // level 10 16, // level 10
16, // level 9 16, // level 9
16, // level 8 16, // level 8
16, // level 8
16, // level 8
16, // level 8
8, // level 8 8, // level 8
64, // Level 5 64, // Level 5
@@ -417,11 +426,9 @@ void reduce_first_pass(uint dispatchThreadID, uint groupIndex)
{ {
// Load the lowest level (and only the last level) // Load the lowest level (and only the last level)
const uint level0Offset = OCBT_depth_offset[TREE_LAST_LEVEL] / 32; const uint level0Offset = OCBT_depth_offset[TREE_LAST_LEVEL] / 32;
for (uint e = 0; e < 4; ++e) if (groupIndex % 2 == 0)
{ gs_cbtTree[level0Offset + dispatchThreadID / 2] = pParams.cbtBuffer[level0Offset + dispatchThreadID / 2];
uint target_element = 4 * dispatchThreadID + e;
gs_cbtTree[level0Offset + target_element] = pParams.cbtBuffer[level0Offset + target_element];
}
GroupMemoryBarrierWithGroupSync(); GroupMemoryBarrierWithGroupSync();
// First we do a reduction until each lane has exactly one element to process // First we do a reduction until each lane has exactly one element to process
@@ -444,29 +451,15 @@ void reduce_first_pass(uint dispatchThreadID, uint groupIndex)
GroupMemoryBarrierWithGroupSync(); GroupMemoryBarrierWithGroupSync();
// Load the first reduced level
const uint level2Offset = OCBT_depth_offset[TREE_LAST_LEVEL - 1] / 32; const uint level2Offset = OCBT_depth_offset[TREE_LAST_LEVEL - 1] / 32;
for (uint e = 0; e < 4; ++e)
{
uint target_element = 4 * dispatchThreadID + e;
pParams.cbtBuffer[level2Offset + target_element] = gs_cbtTree[level2Offset + target_element];
}
// Load the first reduced level
const uint level3Offset = OCBT_depth_offset[TREE_LAST_LEVEL - 2] / 32;
for (uint e = 0; e < 2; ++e)
{
uint target_element = 2 * dispatchThreadID + e;
pParams.cbtBuffer[level3Offset + target_element] = gs_cbtTree[level3Offset + target_element];
}
const uint level4Offset = OCBT_depth_offset[TREE_LAST_LEVEL - 3] / 32;
pParams.cbtBuffer[level4Offset + dispatchThreadID] = gs_cbtTree[level4Offset + dispatchThreadID];
const uint level5Offset = OCBT_depth_offset[TREE_LAST_LEVEL - 4] / 32;
if (groupIndex % 2 == 0) if (groupIndex % 2 == 0)
pParams.cbtBuffer[level5Offset + dispatchThreadID / 2] = gs_cbtTree[level5Offset + dispatchThreadID / 2]; pParams.cbtBuffer[level2Offset + dispatchThreadID / 2] = gs_cbtTree[level2Offset + dispatchThreadID / 2];
const uint level3Offset = OCBT_depth_offset[TREE_LAST_LEVEL - 2] / 32;
if (groupIndex % 4 == 0)
pParams.cbtBuffer[level3Offset + dispatchThreadID / 4] = gs_cbtTree[level3Offset + dispatchThreadID / 4];
} }
void reduce_second_pass(uint groupIndex) void reduce_second_pass(uint groupIndex)
{ {
// Load the lowest level (and only the last level) // Load the lowest level (and only the last level)
+36 -27
View File
@@ -16,7 +16,7 @@ struct BisectorGeometry
// global // global
// update // update
int classifyBisector(in BisectorGeometry tri, uint depth) int classifyBisector(in BisectorGeometry tri, uint depth, inout DebugStruct debug)
{ {
float3 triNormal = normalize(cross(tri.p[2] - tri.p[1], tri.p[0] - tri.p[1])); float3 triNormal = normalize(cross(tri.p[2] - tri.p[1], tri.p[0] - tri.p[1]));
float3 triCenter = (tri.p[0] + tri.p[1] + tri.p[2]) / 3.0; float3 triCenter = (tri.p[0] + tri.p[1] + tri.p[2]) / 3.0;
@@ -24,49 +24,49 @@ int classifyBisector(in BisectorGeometry tri, uint depth)
float fDotV = dot(viewDir, pViewParams.cameraForward_WS.xyz); float fDotV = dot(viewDir, pViewParams.cameraForward_WS.xyz);
float vDotN = dot(viewDir, triNormal); float vDotN = dot(viewDir, triNormal);
debug.fDotV = fDotV;
debug.vDotN = vDotN;
if(fDotV < 0.0 && vDotN < -1e-3) if(fDotV < 0.0 && vDotN < -1e-3)
{
debug.area = 420;
return BACK_FACE_CULLED; return BACK_FACE_CULLED;
}
AABB aabb; AABB aabb;
aabb.minCorner = float3(min(min(tri.p[0].x, tri.p[1].x), tri.p[2].x), min(min(tri.p[0].y, tri.p[1].y), tri.p[2].y), min(min(tri.p[0].z, tri.p[1].z), tri.p[2].z)); aabb.minCorner = float3(min(min(tri.p[0].x, tri.p[1].x), tri.p[2].x), min(min(tri.p[0].y, tri.p[1].y), tri.p[2].y), min(min(tri.p[0].z, tri.p[1].z), tri.p[2].z));
aabb.maxCorner = float3(max(max(tri.p[0].x, tri.p[1].x), tri.p[2].x), max(max(tri.p[0].y, tri.p[1].y), tri.p[2].y), max(max(tri.p[0].z, tri.p[1].z), tri.p[2].z)); aabb.maxCorner = float3(max(max(tri.p[0].x, tri.p[1].x), tri.p[2].x), max(max(tri.p[0].y, tri.p[1].y), tri.p[2].y), max(max(tri.p[0].z, tri.p[1].z), tri.p[2].z));
if(aabb.insideFrustum(pViewParams.viewFrustum)) //if(aabb.insideFrustum(pViewParams.viewFrustum))
return FRUSTUM_CULLED; // return FRUSTUM_CULLED;
float4x4 viewProjectionMatrix = mul(pViewParams.projectionMatrix, pViewParams.viewMatrix); float4x4 viewProjectionMatrix = mul(pViewParams.projectionMatrix, pViewParams.viewMatrix);
float4 p0P = mul(pViewParams.viewMatrix, float4(tri.p[0], 1.0)); float4 p0P = clipToScreen(mul(viewProjectionMatrix, float4(tri.p[0], 1.0)));
p0P.xy = p0P.xy / p0P.w;
p0P.xy = (p0P.xy * 0.5 + 0.5);
float4 p1P = mul(viewProjectionMatrix, float4(tri.p[1], 1.0)); float4 p1P = clipToScreen(mul(viewProjectionMatrix, float4(tri.p[1], 1.0)));
p1P.xy = p1P.xy / p1P.w;
p1P.xy = (p1P.xy * 0.5 + 0.5);
float4 p2P = mul(viewProjectionMatrix, float4(tri.p[2], 1.0)); float4 p2P = clipToScreen(mul(viewProjectionMatrix, float4(tri.p[2], 1.0)));
p2P.xy = p2P.xy / p2P.w;
p2P.xy = (p2P.xy * 0.5 + 0.5);
float area = 0.5 * abs(p0P.x * (p2P.y - p1P.y) + p1P.x * (p0P.y - p2P.y) + p2P.x * (p1P.y - p0P.y)); float area = 0.5 * abs(p0P.x * (p1P.y - p2P.y) + p1P.x * (p2P.y - p0P.y) + p2P.x * (p0P.y - p1P.y));
area *= pViewParams.screenDimensions.x * pViewParams.screenDimensions.y;
float areaOverestimation = lerp(2.0, 1.0, pow(vDotN, 0.2)); float areaOverestimation = lerp(2.0, 1.0, pow(vDotN, 0.2));
area *= areaOverestimation; area *= areaOverestimation;
debug.areaP[0] = p0P.xy;
debug.areaP[1] = p1P.xy;
debug.areaP[2] = p2P.xy;
debug.area = area;
if(pParams.update.triangleSize < area && depth < pParams.update.maxSubdivisionDepth) if(pParams.update.triangleSize < area && depth < pParams.update.maxSubdivisionDepth)
{ {
return BISECT_ELEMENT; return BISECT_ELEMENT;
} }
else if((pParams.update.triangleSize * 0.5 > area) || (depth > pParams.update.maxSubdivisionDepth)) else if((pParams.update.triangleSize * 0.5 > area) || (depth > pParams.update.maxSubdivisionDepth))
{ {
float4 p3P = mul(viewProjectionMatrix, float4(tri.p[3], 1.0)); float4 p3P = clipToScreen(mul(viewProjectionMatrix, float4(tri.p[3], 1.0)));
p3P.xy = p3P.xy / p3P.w;
p3P.xy = (p3P.xy * 0.5 + 0.5);
float areaParent = 0.5 * abs(p0P.x * (p2P.y - p3P.y) + p3P.x * (p0P.y - p2P.y) + p2P.x * (p3P.y - p0P.y)); float areaParent = 0.5 * abs(p0P.x * (p3P.y - p2P.y) + p3P.x * (p2P.y - p0P.y) + p2P.x * (p0P.y - p3P.y));
areaParent *= pViewParams.screenDimensions.x * pViewParams.screenDimensions.y;
areaParent *= areaOverestimation; areaParent *= areaOverestimation;
return ((pParams.update.triangleSize >= areaParent ) || (depth > pParams.update.maxSubdivisionDepth)) ? TOO_SMALL : UNCHANGED_ELEMENT; return ((pParams.update.triangleSize >= areaParent ) || (depth > pParams.update.maxSubdivisionDepth)) ? TOO_SMALL : UNCHANGED_ELEMENT;
} }
@@ -136,7 +136,7 @@ void reset()
[numthreads(WORKGROUP_SIZE, 1, 1)] [numthreads(WORKGROUP_SIZE, 1, 1)]
void classify(uint dispatchID : SV_DispatchThreadID) void classify(uint dispatchID : SV_DispatchThreadID)
{ {
if(dispatchID > pParams.indirectDrawBuffer[9]) if(dispatchID >= pParams.indirectDrawBuffer[9])
return; return;
uint currentID = pParams.indexedBisectorBuffer[dispatchID]; uint currentID = pParams.indexedBisectorBuffer[dispatchID];
@@ -155,7 +155,13 @@ void classify(uint dispatchID : SV_DispatchThreadID)
cBisectorData.problematicNeighbor = INVALID_POINTER; cBisectorData.problematicNeighbor = INVALID_POINTER;
cBisectorData.flags = VISIBLE_BISECTOR; cBisectorData.flags = VISIBLE_BISECTOR;
int currentValidity = classifyBisector(bis, depth); DebugStruct debug;
debug.sourceP[0] = float4(bis.p[0], 1);
debug.sourceP[1] = float4(bis.p[1], 1);
debug.sourceP[2] = float4(bis.p[2], 1);
int currentValidity = classifyBisector(bis, depth, debug);
debug.validity = currentValidity;
pParams.debugBuffer[dispatchID] = debug;
if(currentValidity > UNCHANGED_ELEMENT) if(currentValidity > UNCHANGED_ELEMENT)
{ {
uint targetSlot; uint targetSlot;
@@ -1085,7 +1091,7 @@ void leb_DecodeNodeAttributeArray_parent_child(uint64_t heapID, inout float3 chi
} }
} }
void evaluateElementPosition(uint64_t heapID, uint32_t vertexDataOffset, uint minDepth, out Triangle parentTri, out Triangle childTri) void evaluateElementPosition(uint64_t heapID, uint32_t vertexDataOffset, uint minDepth, RWStructuredBuffer<float3> vertexBuffer, out Triangle parentTri, out Triangle childTri)
{ {
// Get the depth of the element // Get the depth of the element
uint depth = heapIDDepth(heapID); uint depth = heapIDDepth(heapID);
@@ -1098,9 +1104,9 @@ void evaluateElementPosition(uint64_t heapID, uint32_t vertexDataOffset, uint mi
uint primitiveID = uint((heapID >> subTreeDepth) - baseHeapID); uint primitiveID = uint((heapID >> subTreeDepth) - baseHeapID);
// Grab the base positions of the element // Grab the base positions of the element
float3 p0 = float3(pParams.currentVertexBuffer[3 * primitiveID + vertexDataOffset]); float3 p0 = float3(vertexBuffer[3 * primitiveID + vertexDataOffset]);
float3 p1 = float3(pParams.currentVertexBuffer[3 * primitiveID + 1 + vertexDataOffset]); float3 p1 = float3(vertexBuffer[3 * primitiveID + 1 + vertexDataOffset]);
float3 p2 = float3(pParams.currentVertexBuffer[3 * primitiveID + 2 + vertexDataOffset]); float3 p2 = float3(vertexBuffer[3 * primitiveID + 2 + vertexDataOffset]);
// Heap ID in the sub triangle // Heap ID in the sub triangle
uint64_t mask = subTreeDepth != 0uL ? 0xFFFFFFFFFFFFFFFFull >> (64ull - subTreeDepth) : 0ull; uint64_t mask = subTreeDepth != 0uL ? 0xFFFFFFFFFFFFFFFFull >> (64ull - subTreeDepth) : 0ull;
@@ -1127,6 +1133,9 @@ void evaluateElementPosition(uint64_t heapID, uint32_t vertexDataOffset, uint mi
childTri.p[2] = float3(childArray[0][2], childArray[1][2], childArray[2][2]); childTri.p[2] = float3(childArray[0][2], childArray[1][2], childArray[2][2]);
} }
layout(push_constant)
ConstantBuffer<uint> preRender;
[numthreads(WORKGROUP_SIZE, 1, 1)] [numthreads(WORKGROUP_SIZE, 1, 1)]
void evaluateLeb(uint currentID : SV_DispatchThreadID, uint groupIndex: SV_GroupIndex) void evaluateLeb(uint currentID : SV_DispatchThreadID, uint groupIndex: SV_GroupIndex)
{ {
@@ -1136,7 +1145,7 @@ void evaluateLeb(uint currentID : SV_DispatchThreadID, uint groupIndex: SV_Group
GroupMemoryBarrierWithGroupSync(); GroupMemoryBarrierWithGroupSync();
uint numBisectors; uint numBisectors;
if(pViewParams.frameIndex == -1) if(preRender == 1)
{ {
numBisectors = pParams.indirectDrawBuffer[9]; numBisectors = pParams.indirectDrawBuffer[9];
} }
@@ -1153,7 +1162,7 @@ void evaluateLeb(uint currentID : SV_DispatchThreadID, uint groupIndex: SV_Group
uint depth = heapIDDepth(cHeapID); uint depth = heapIDDepth(cHeapID);
Triangle parentTri, childTri; Triangle parentTri, childTri;
evaluateElementPosition(cHeapID, 0, pParams.geometry.baseDepth, parentTri, childTri); evaluateElementPosition(cHeapID, 0, pParams.geometry.baseDepth, pParams.currentVertexBuffer, parentTri, childTri);
pParams.lebPositionBuffer[3 * currentID + 0] = childTri.p[0]; pParams.lebPositionBuffer[3 * currentID + 0] = childTri.p[0];
pParams.lebPositionBuffer[3 * currentID + 1] = childTri.p[1]; pParams.lebPositionBuffer[3 * currentID + 1] = childTri.p[1];
+11
View File
@@ -26,6 +26,16 @@ struct UpdateCB
float farPlaneDistance; float farPlaneDistance;
} }
struct DebugStruct
{
float4 sourceP[3];
float2 areaP[3];
float area;
int validity;
float fDotV;
float vDotN;
}
struct ComputeParams struct ComputeParams
{ {
ConstantBuffer<GeometryCB> geometry; ConstantBuffer<GeometryCB> geometry;
@@ -52,5 +62,6 @@ struct ComputeParams
RWStructuredBuffer<uint> modifiedBisectorIndices; RWStructuredBuffer<uint> modifiedBisectorIndices;
RWStructuredBuffer<float3> lebPositionBuffer; RWStructuredBuffer<float3> lebPositionBuffer;
StructuredBuffer<float3x3> lebMatrixCache; StructuredBuffer<float3x3> lebMatrixCache;
RWStructuredBuffer<DebugStruct> debugBuffer;
}; };
ParameterBlock<ComputeParams> pParams; ParameterBlock<ComputeParams> pParams;
+6 -1
View File
@@ -10,6 +10,11 @@ using namespace Seele::Math;
Camera::Camera() : viewMatrix(Matrix4()), cameraPos(Vector()), bNeedsViewBuild(false) { Camera::Camera() : viewMatrix(Matrix4()), cameraPos(Vector()), bNeedsViewBuild(false) {
yaw = -3.1415f / 2; yaw = -3.1415f / 2;
pitch = 0; pitch = 0;
Vector eyePos = Vector(0, 0, -5);
Vector lookAt = Vector(0, 0, 0);
viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0));
cameraPos = eyePos;
cameraForward = Vector(0, 0, 1);
} }
Camera::~Camera() {} Camera::~Camera() {}
@@ -39,7 +44,7 @@ void Camera::moveY(float amount) {
} }
void Camera::buildViewMatrix() { void Camera::buildViewMatrix() {
Vector eyePos = getTransform().getPosition(); Vector eyePos = getTransform().getPosition() + Vector(0, 0, -5);
Vector lookAt = eyePos + getTransform().getForward(); Vector lookAt = eyePos + getTransform().getForward();
viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0)); viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0));
cameraPos = eyePos; cameraPos = eyePos;
+104 -75
View File
@@ -4,12 +4,16 @@
using namespace Seele; using namespace Seele;
Array<Vector4> basePoints = { Array<Vector4> basePoints = {
Vector4(000.0f / 3, 0, 000.0f / 3, 1), Vector4(000.0f / 3, 0, 100.0f / 3, 1), Vector4(000.0f / 3, 0, 200.0f / 3, 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(000.0f / 3, 0, 300.0f / 3, 1), Vector4(100.0f / 3, 0, 000.0f / 3, 1), Vector4(100.0f / 3, 0, 100.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(100.0f / 3, 0, 200.0f / 3, 1), Vector4(100.0f / 3, 0, 300.0f / 3, 1), Vector4(200.0f / 3, 0, 000.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(200.0f / 3, 0, 100.0f / 3, 1), Vector4(200.0f / 3, 0, 200.0f / 3, 1), Vector4(200.0f / 3, 0, 300.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(300.0f / 3, 0, 000.0f / 3, 1), Vector4(300.0f / 3, 0, 100.0f / 3, 1), Vector4(300.0f / 3, 0, 200.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(300.0f / 3, 0, 300.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 { struct Halfedge {
uint32 vertexID; uint32 vertexID;
@@ -18,60 +22,73 @@ struct Halfedge {
uint32 twinID; uint32 twinID;
}; };
Array<Halfedge> edges = { Array<Halfedge> edges = {
Halfedge{0, 1, 2, 4294967295}, //Halfedge{0, 1, 2, 4294967295},
Halfedge{1, 2, 0, 3}, //Halfedge{1, 2, 0, 3},
Halfedge{4, 0, 1, 4294967295}, //Halfedge{4, 0, 1, 4294967295},
Halfedge{4, 4, 5, 1}, //Halfedge{4, 4, 5, 1},
Halfedge{1, 5, 3, 8}, //Halfedge{1, 5, 3, 8},
Halfedge{5, 3, 4, 18}, //Halfedge{5, 3, 4, 18},
Halfedge{1, 7, 8, 4294967295}, //Halfedge{1, 7, 8, 4294967295},
Halfedge{2, 8, 6, 9}, //Halfedge{2, 8, 6, 9},
Halfedge{5, 6, 7, 4}, //Halfedge{5, 6, 7, 4},
Halfedge{5, 10, 11, 7}, //Halfedge{5, 10, 11, 7},
Halfedge{2, 11, 9, 14}, //Halfedge{2, 11, 9, 14},
Halfedge{6, 9, 10, 24}, //Halfedge{6, 9, 10, 24},
Halfedge{2, 13, 14, 4294967295}, //Halfedge{2, 13, 14, 4294967295},
Halfedge{3, 14, 12, 15}, //Halfedge{3, 14, 12, 15},
Halfedge{6, 12, 13, 10}, //Halfedge{6, 12, 13, 10},
Halfedge{6, 16, 17, 13}, //Halfedge{6, 16, 17, 13},
Halfedge{3, 17, 15, 4294967295}, //Halfedge{3, 17, 15, 4294967295},
Halfedge{7, 15, 16, 30}, //Halfedge{7, 15, 16, 30},
Halfedge{4, 19, 20, 5}, //Halfedge{4, 19, 20, 5},
Halfedge{5, 20, 18, 21}, //Halfedge{5, 20, 18, 21},
Halfedge{8, 18, 19, 4294967295}, //Halfedge{8, 18, 19, 4294967295},
Halfedge{8, 22, 23, 19}, //Halfedge{8, 22, 23, 19},
Halfedge{5, 23, 21, 26}, //Halfedge{5, 23, 21, 26},
Halfedge{9, 21, 22, 36}, //Halfedge{9, 21, 22, 36},
Halfedge{5, 25, 26, 11}, //Halfedge{5, 25, 26, 11},
Halfedge{6, 26, 24, 27}, //Halfedge{6, 26, 24, 27},
Halfedge{9, 24, 25, 22}, //Halfedge{9, 24, 25, 22},
Halfedge{9, 28, 29, 25}, //Halfedge{9, 28, 29, 25},
Halfedge{6, 29, 27, 32}, //Halfedge{6, 29, 27, 32},
Halfedge{10, 27, 28, 42}, //Halfedge{10, 27, 28, 42},
Halfedge{6, 31, 32, 17}, //Halfedge{6, 31, 32, 17},
Halfedge{7, 32, 30, 33}, //Halfedge{7, 32, 30, 33},
Halfedge{10, 30, 31, 28}, //Halfedge{10, 30, 31, 28},
Halfedge{10, 34, 35, 31}, //Halfedge{10, 34, 35, 31},
Halfedge{7, 35, 33, 4294967295}, //Halfedge{7, 35, 33, 4294967295},
Halfedge{11, 33, 34, 48}, //Halfedge{11, 33, 34, 48},
Halfedge{8, 37, 38, 23}, //Halfedge{8, 37, 38, 23},
Halfedge{9, 38, 36, 39}, //Halfedge{9, 38, 36, 39},
Halfedge{12, 36, 37, 4294967295}, //Halfedge{12, 36, 37, 4294967295},
Halfedge{12, 40, 41, 37}, //Halfedge{12, 40, 41, 37},
Halfedge{9, 41, 39, 44}, //Halfedge{9, 41, 39, 44},
Halfedge{13, 39, 40, 4294967295}, //Halfedge{13, 39, 40, 4294967295},
Halfedge{9, 43, 44, 29}, //Halfedge{9, 43, 44, 29},
Halfedge{10, 44, 42, 45}, //Halfedge{10, 44, 42, 45},
Halfedge{13, 42, 43, 40}, //Halfedge{13, 42, 43, 40},
Halfedge{13, 46, 47, 43}, //Halfedge{13, 46, 47, 43},
Halfedge{10, 47, 45, 50}, //Halfedge{10, 47, 45, 50},
Halfedge{14, 45, 46, 4294967295}, //Halfedge{14, 45, 46, 4294967295},
Halfedge{10, 49, 50, 35}, //Halfedge{10, 49, 50, 35},
Halfedge{11, 50, 48, 51}, //Halfedge{11, 50, 48, 51},
Halfedge{14, 48, 49, 46}, //Halfedge{14, 48, 49, 46},
Halfedge{14, 52, 53, 49}, //Halfedge{14, 52, 53, 49},
Halfedge{11, 53, 51, 4294967295}, //Halfedge{11, 53, 51, 4294967295},
Halfedge{15, 51, 52, 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) { uint32_t find_msb_64(uint64_t x) {
@@ -133,7 +150,7 @@ Matrix3 splittingMatrix(uint32 bitValue) {
float b = float(bitValue); float b = float(bitValue);
float c = 1.0f - b; float c = 1.0f - b;
return glm::transpose(Matrix3({ return Matrix3({
0.0f, 0.0f,
b, b,
c, c,
@@ -143,7 +160,7 @@ Matrix3 splittingMatrix(uint32 bitValue) {
b, b,
c, c,
0.0f, 0.0f,
})); });
} }
Matrix3 decodeSubdivisionMatrix(uint64 heapID) { Matrix3 decodeSubdivisionMatrix(uint64 heapID) {
@@ -158,8 +175,7 @@ Matrix3 decodeSubdivisionMatrix(uint64 heapID) {
void LebMatrixCache::init(Gfx::PGraphics graphics, uint32 depth) { void LebMatrixCache::init(Gfx::PGraphics graphics, uint32 depth) {
cacheDepth = depth; cacheDepth = depth;
uint32 matrixCount = 2ULL << cacheDepth; uint32 matrixCount = 2ULL << cacheDepth;
struct PaddedMatrix struct PaddedMatrix {
{
Matrix3 m; Matrix3 m;
uint8 pad[12]; uint8 pad[12];
}; };
@@ -209,10 +225,16 @@ void MeshUpdater::init(Gfx::PGraphics gfx, Gfx::PDescriptorLayout viewParamsLayo
layout->addDescriptorBinding(Gfx::DescriptorBinding{20, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); layout->addDescriptorBinding(Gfx::DescriptorBinding{20, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
layout->addDescriptorBinding(Gfx::DescriptorBinding{21, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); layout->addDescriptorBinding(Gfx::DescriptorBinding{21, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
layout->addDescriptorBinding(Gfx::DescriptorBinding{22, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER}); layout->addDescriptorBinding(Gfx::DescriptorBinding{22, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
layout->addDescriptorBinding(Gfx::DescriptorBinding{23, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
layout->create(); layout->create();
pipelineLayout = graphics->createPipelineLayout("ComputeLayout"); pipelineLayout = graphics->createPipelineLayout("ComputeLayout");
pipelineLayout->addDescriptorLayout(viewParamsLayout); pipelineLayout->addDescriptorLayout(viewParamsLayout);
pipelineLayout->addDescriptorLayout(layout); pipelineLayout->addDescriptorLayout(layout);
pipelineLayout->addPushConstants(Gfx::SePushConstantRange{
.stageFlags = Gfx::SE_SHADER_STAGE_COMPUTE_BIT,
.offset = 0,
.size = sizeof(uint32),
});
indirectBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ indirectBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = .sourceData =
{ {
@@ -249,6 +271,13 @@ void MeshUpdater::init(Gfx::PGraphics gfx, Gfx::PDescriptorLayout viewParamsLayo
}, },
.name = "OccupancyBuffer", .name = "OccupancyBuffer",
}); });
debugBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData =
{
.size = 100000,
},
.name = "DebugBuffer",
});
graphics->beginShaderCompilation(ShaderCompilationInfo{ graphics->beginShaderCompilation(ShaderCompilationInfo{
.name = "CBTCompute", .name = "CBTCompute",
@@ -399,6 +428,8 @@ void MeshUpdater::evaluateLeb(const BaseMesh& baseMesh, CBTMesh& mesh, Gfx::PDes
Gfx::OComputeCommand evalCmd = graphics->createComputeCommand("EvalLEB"); Gfx::OComputeCommand evalCmd = graphics->createComputeCommand("EvalLEB");
evalCmd->bindPipeline(lebEvaluate); evalCmd->bindPipeline(lebEvaluate);
evalCmd->bindDescriptor({set, viewParamsSet}); evalCmd->bindDescriptor({set, viewParamsSet});
uint32 val = complete;
evalCmd->pushConstants(Gfx::SE_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(uint32), &val);
evalCmd->dispatchIndirect(mesh.indirectDispatchBuffer, complete ? 0 : sizeof(uint32) * 6); evalCmd->dispatchIndirect(mesh.indirectDispatchBuffer, complete ? 0 : sizeof(uint32) * 6);
graphics->executeCommands(std::move(evalCmd)); graphics->executeCommands(std::move(evalCmd));
mesh.currentVertexBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, mesh.currentVertexBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
@@ -425,6 +456,7 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx::
set->updateBuffer(HEAP_ID_BUFFER, 0, mesh.heapIDBuffer); set->updateBuffer(HEAP_ID_BUFFER, 0, mesh.heapIDBuffer);
set->updateBuffer(BISECTOR_DATA_BUFFER, 0, mesh.updateBuffer); set->updateBuffer(BISECTOR_DATA_BUFFER, 0, mesh.updateBuffer);
set->updateBuffer(CLASSIFICATION_BUFFER, 0, mesh.classificationBuffer); set->updateBuffer(CLASSIFICATION_BUFFER, 0, mesh.classificationBuffer);
set->updateBuffer(DEBUG_BUFFER, 0, debugBuffer);
set->writeChanges(); set->writeChanges();
Gfx::OComputeCommand classifyCmd = graphics->createComputeCommand("Classify"); Gfx::OComputeCommand classifyCmd = graphics->createComputeCommand("Classify");
classifyCmd->bindPipeline(classify); classifyCmd->bindPipeline(classify);
@@ -588,7 +620,7 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx::
Gfx::OComputeCommand prepareSimplifyCmd = graphics->createComputeCommand("PrepareSimplify"); Gfx::OComputeCommand prepareSimplifyCmd = graphics->createComputeCommand("PrepareSimplify");
prepareSimplifyCmd->bindPipeline(prepareSimplify); prepareSimplifyCmd->bindPipeline(prepareSimplify);
prepareSimplifyCmd->bindDescriptor({viewParamsSet, set}); prepareSimplifyCmd->bindDescriptor({viewParamsSet, set});
prepareSimplifyCmd->dispatchIndirect(indirectBuffer, 0); prepareSimplifyCmd->dispatchIndirect(indirectBuffer, 3 * sizeof(uint32_t));
graphics->executeCommands(std::move(prepareSimplifyCmd)); graphics->executeCommands(std::move(prepareSimplifyCmd));
mesh.simplificationBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_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); Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
@@ -653,19 +685,16 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx::
set->updateBuffer(GEOMETRY_CB, 0, geometryCB); set->updateBuffer(GEOMETRY_CB, 0, geometryCB);
set->updateBuffer(UPDATE_CB, 0, updateCB); set->updateBuffer(UPDATE_CB, 0, updateCB);
set->updateBuffer(SIMPLIFICATION_BUFFER, 0, mesh.simplificationBuffer); set->updateBuffer(PROPAGATE_BUFFER, 0, mesh.propagateBuffer);
set->updateBuffer(HEAP_ID_BUFFER, 0, mesh.heapIDBuffer);
set->updateBuffer(BISECTOR_DATA_BUFFER, 0, mesh.updateBuffer); set->updateBuffer(BISECTOR_DATA_BUFFER, 0, mesh.updateBuffer);
set->updateBuffer(NEIGHBOURS_BUFFER, 0, nextNeighborsBuffer); set->updateBuffer(NEIGHBOURS_BUFFER, 0, nextNeighborsBuffer);
set->updateBuffer(HEAP_ID_BUFFER, 0, mesh.heapIDBuffer);
set->updateBuffer(CBT_BUFFER0, 0, mesh.gpuCBT.bufferArray[0]);
set->updateBuffer(CBT_BUFFER1, 0, mesh.gpuCBT.bufferArray[1]);
set->updateBuffer(PROPAGATE_BUFFER, 0, mesh.propagateBuffer);
set->writeChanges(); set->writeChanges();
Gfx::OComputeCommand simplifyCmd = graphics->createComputeCommand("simplify"); Gfx::OComputeCommand propagateSimplifyCmd = graphics->createComputeCommand("PropagateSimplify");
simplifyCmd->bindPipeline(simplify); propagateSimplifyCmd->bindPipeline(propagateSimplify);
simplifyCmd->bindDescriptor({viewParamsSet, set}); propagateSimplifyCmd->bindDescriptor({viewParamsSet, set});
simplifyCmd->dispatchIndirect(indirectBuffer, 0); propagateSimplifyCmd->dispatchIndirect(indirectBuffer, 3 * sizeof(uint32));
graphics->executeCommands(std::move(simplifyCmd)); graphics->executeCommands(std::move(propagateSimplifyCmd));
nextNeighborsBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_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); Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
} }
+3
View File
@@ -7,6 +7,7 @@
namespace Seele { namespace Seele {
constexpr auto GEOMETRY_CB = 0; constexpr auto GEOMETRY_CB = 0;
constexpr auto UPDATE_CB = 1; constexpr auto UPDATE_CB = 1;
constexpr auto CURRENT_VERTEX_BUFFER = 2; constexpr auto CURRENT_VERTEX_BUFFER = 2;
constexpr auto INDEXED_BISECTOR_BUFFER = 3; constexpr auto INDEXED_BISECTOR_BUFFER = 3;
constexpr auto INDIRECT_DRAW_BUFFER = 4; constexpr auto INDIRECT_DRAW_BUFFER = 4;
@@ -28,6 +29,7 @@ constexpr auto VISIBLE_BISECTOR_INDICES = 19;
constexpr auto MODIFIED_BISECTOR_INDICES = 20; constexpr auto MODIFIED_BISECTOR_INDICES = 20;
constexpr auto LEB_POSITION_BUFFER = 21; constexpr auto LEB_POSITION_BUFFER = 21;
constexpr auto LEB_MATRIX_CACHE = 22; constexpr auto LEB_MATRIX_CACHE = 22;
constexpr auto DEBUG_BUFFER = 23;
constexpr uint64 WORKGROUP_SIZE = 64; constexpr uint64 WORKGROUP_SIZE = 64;
template <size_t Power> class CBT { template <size_t Power> class CBT {
@@ -495,6 +497,7 @@ struct MeshUpdater {
// Debug // Debug
Gfx::OComputeShader validateCS; Gfx::OComputeShader validateCS;
Gfx::PComputePipeline validate; Gfx::PComputePipeline validate;
Gfx::OShaderBuffer debugBuffer;
// LEB // LEB
Gfx::OComputeShader lebClearCS; Gfx::OComputeShader lebClearCS;
@@ -12,7 +12,7 @@ TerrainRenderer::TerrainRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDe
: graphics(graphics), scene(scene) { : graphics(graphics), scene(scene) {
meshUpdater.init(graphics, viewParamsLayout); meshUpdater.init(graphics, viewParamsLayout);
lebCache.init(graphics, 5); lebCache.init(graphics, 5);
CBT<21> cbt; CBT<18> cbt;
CPUMesh cpuMesh = generateCPUMesh(cbt.numElements()); CPUMesh cpuMesh = generateCPUMesh(cbt.numElements());
plainMesh.gpuCBT.lastLevelSize = cbt.lastLevelSize(); plainMesh.gpuCBT.lastLevelSize = cbt.lastLevelSize();
for (uint32 i = 0; i < 2; ++i) { for (uint32 i = 0; i < 2; ++i) {
@@ -228,10 +228,6 @@ TerrainRenderer::TerrainRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDe
}); });
updateBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT, 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); Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
meshUpdater.resetBuffers(plainMesh);
meshUpdater.prepareIndirection(plainMesh, geometryBuffer);
meshUpdater.evaluateLeb(baseMesh, plainMesh, viewParamsSet, geometryBuffer, updateBuffer, lebCache.getLebMatrixBuffer(), true, true);
graphics->beginShaderCompilation(ShaderCompilationInfo{ graphics->beginShaderCompilation(ShaderCompilationInfo{
.modules = {"TerrainPass"}, .modules = {"TerrainPass"},
.entryPoints = .entryPoints =
@@ -249,27 +245,20 @@ TerrainRenderer::TerrainRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDe
.computeShader = deformCS, .computeShader = deformCS,
.pipelineLayout = meshUpdater.pipelineLayout, .pipelineLayout = meshUpdater.pipelineLayout,
}); });
meshUpdater.resetBuffers(plainMesh);
meshUpdater.prepareIndirection(plainMesh, geometryBuffer);
meshUpdater.evaluateLeb(baseMesh, plainMesh, viewParamsSet, geometryBuffer, updateBuffer, lebCache.getLebMatrixBuffer(), true, true);
applyDeformation(viewParamsSet);
} }
TerrainRenderer::~TerrainRenderer() {} TerrainRenderer::~TerrainRenderer() {}
static bool first = true;
void TerrainRenderer::beginFrame(Gfx::PDescriptorSet viewParamsSet) { void TerrainRenderer::beginFrame(Gfx::PDescriptorSet viewParamsSet) {
meshUpdater.update(plainMesh, viewParamsSet, geometryBuffer, updateBuffer); meshUpdater.update(plainMesh, viewParamsSet, geometryBuffer, updateBuffer);
meshUpdater.evaluateLeb(baseMesh, plainMesh, viewParamsSet, geometryBuffer, updateBuffer, lebCache.getLebMatrixBuffer(), false, false); meshUpdater.evaluateLeb(baseMesh, plainMesh, viewParamsSet, geometryBuffer, updateBuffer, lebCache.getLebMatrixBuffer(), false, false);
Gfx::PDescriptorSet set = meshUpdater.layout->allocateDescriptorSet(); applyDeformation(viewParamsSet);
set->updateBuffer(GEOMETRY_CB, 0, geometryBuffer);
set->updateBuffer(INDIRECT_DRAW_BUFFER, 0, plainMesh.indirectDrawBuffer);
set->updateBuffer(INDEXED_BISECTOR_BUFFER, 0, plainMesh.indexedBisectorBuffer);
set->updateBuffer(LEB_POSITION_BUFFER, 0, plainMesh.lebVertexBuffer);
set->updateBuffer(CURRENT_VERTEX_BUFFER, 0, plainMesh.currentVertexBuffer);
set->writeChanges();
Gfx::OComputeCommand command = graphics->createComputeCommand("Deform");
command->bindPipeline(deform);
command->bindDescriptor({viewParamsSet, set});
command->dispatchIndirect(plainMesh.indirectDispatchBuffer, 3 * sizeof(uint32));
graphics->executeCommands(std::move(command));
plainMesh.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_VERTEX_SHADER_BIT);
} }
Gfx::ORenderCommand TerrainRenderer::render(Gfx::PDescriptorSet viewParamsSet) { Gfx::ORenderCommand TerrainRenderer::render(Gfx::PDescriptorSet viewParamsSet) {
@@ -300,8 +289,8 @@ void TerrainRenderer::setViewport(Gfx::PViewport _viewport, Gfx::PRenderPass ren
}, },
.rasterizationState = .rasterizationState =
{ {
//.polygonMode = Gfx::SE_POLYGON_MODE_LINE, .polygonMode = Gfx::SE_POLYGON_MODE_LINE,
.cullMode = Gfx::SE_CULL_MODE_BACK_BIT, .cullMode = Gfx::SE_CULL_MODE_NONE,
}, },
.colorBlend = .colorBlend =
{ {
@@ -316,3 +305,20 @@ void TerrainRenderer::setViewport(Gfx::PViewport _viewport, Gfx::PRenderPass ren
}; };
pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo)); pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
} }
void TerrainRenderer::applyDeformation(Gfx::PDescriptorSet viewParamsSet) {
Gfx::PDescriptorSet set = meshUpdater.layout->allocateDescriptorSet();
set->updateBuffer(GEOMETRY_CB, 0, geometryBuffer);
set->updateBuffer(INDIRECT_DRAW_BUFFER, 0, plainMesh.indirectDrawBuffer);
set->updateBuffer(INDEXED_BISECTOR_BUFFER, 0, plainMesh.indexedBisectorBuffer);
set->updateBuffer(LEB_POSITION_BUFFER, 0, plainMesh.lebVertexBuffer);
set->updateBuffer(CURRENT_VERTEX_BUFFER, 0, plainMesh.currentVertexBuffer);
set->writeChanges();
Gfx::OComputeCommand command = graphics->createComputeCommand("Deform");
command->bindPipeline(deform);
command->bindDescriptor({viewParamsSet, set});
command->dispatchIndirect(plainMesh.indirectDispatchBuffer, 3 * sizeof(uint32));
graphics->executeCommands(std::move(command));
plainMesh.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_VERTEX_SHADER_BIT);
}
@@ -13,11 +13,11 @@ class TerrainRenderer {
void setViewport(Gfx::PViewport viewport, Gfx::PRenderPass renderPass); void setViewport(Gfx::PViewport viewport, Gfx::PRenderPass renderPass);
private: private:
void applyDeformation(Gfx::PDescriptorSet viewParamsSet);
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
PScene scene; PScene scene;
Gfx::ODescriptorLayout layout; Gfx::PDescriptorLayout viewParamsLayout;
Gfx::PDescriptorSet set; Gfx::PRenderPass renderPass;
Gfx::OPipelineLayout pipelineLayout;
Gfx::OTaskShader task; Gfx::OTaskShader task;
Gfx::OMeshShader mesh; Gfx::OMeshShader mesh;
Gfx::OVertexInput inp; Gfx::OVertexInput inp;
+1 -1
View File
@@ -88,7 +88,7 @@ DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout)
DescriptorPool::~DescriptorPool() { DescriptorPool::~DescriptorPool() {
for (size_t i = 0; i < maxSets; ++i) { for (size_t i = 0; i < maxSets; ++i) {
if (cachedHandles[i] != nullptr) { if (cachedHandles[i] != nullptr) {
cachedHandles[i] = nullptr; graphics->getDestructionManager()->queueResourceForDestruction(std::move(cachedHandles[i]));
} }
} }
vkDestroyDescriptorPool(graphics->getDevice(), poolHandle, nullptr); vkDestroyDescriptorPool(graphics->getDevice(), poolHandle, nullptr);
+1 -1
View File
@@ -55,7 +55,7 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
.value = .value =
{ {
.kind = slang::CompilerOptionValueKind::Int, .kind = slang::CompilerOptionValueKind::Int,
.intValue0 = SLANG_DEBUG_INFO_LEVEL_STANDARD, .intValue0 = SLANG_DEBUG_INFO_LEVEL_NONE,
}, },
}, },
{ {
+3 -3
View File
@@ -49,19 +49,19 @@ void LightEnvironment::commit() {
lightEnvBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, lightEnvBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_UNIFORM_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR | Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT); Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
directionalLights->rotateBuffer(sizeof(Component::DirectionalLight) * dirs.size()); directionalLights->rotateBuffer(sizeof(Component::DirectionalLight) * dirs.size());
directionalLights->updateContents(0, sizeof(Component::DirectionalLight) * dirs.size(), dirs.data()); directionalLights->updateContents(0, sizeof(Component::DirectionalLight) * dirs.size(), dirs.data());
directionalLights->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, directionalLights->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR | Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT); Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
pointLights->rotateBuffer(sizeof(Component::PointLight) * points.size()); pointLights->rotateBuffer(sizeof(Component::PointLight) * points.size());
pointLights->updateContents(0, sizeof(Component::PointLight) * points.size(), points.data()); pointLights->updateContents(0, sizeof(Component::PointLight) * points.size(), points.data());
pointLights->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, pointLights->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR | Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT); Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
set->updateBuffer(0, 0, lightEnvBuffer); set->updateBuffer(0, 0, lightEnvBuffer);
set->updateBuffer(1, 0, directionalLights); set->updateBuffer(1, 0, directionalLights);
set->updateBuffer(2, 0, pointLights); set->updateBuffer(2, 0, pointLights);